1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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 Char_Code
(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 Char_Code
(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 Char_Code
(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 Char_Code
(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_Object_Declaration |
1837 N_Formal_Subprogram_Declaration |
1838 N_Formal_Type_Declaration |
1839 N_Full_Type_Declaration |
1840 N_Function_Instantiation |
1841 N_Generic_Function_Renaming_Declaration |
1842 N_Generic_Package_Declaration |
1843 N_Generic_Package_Renaming_Declaration |
1844 N_Generic_Procedure_Renaming_Declaration |
1845 N_Generic_Subprogram_Declaration |
1846 N_Implicit_Label_Declaration |
1847 N_Incomplete_Type_Declaration |
1848 N_Number_Declaration |
1849 N_Object_Declaration |
1850 N_Object_Renaming_Declaration |
1852 N_Package_Body_Stub |
1853 N_Package_Declaration |
1854 N_Package_Instantiation |
1855 N_Package_Renaming_Declaration |
1856 N_Private_Extension_Declaration |
1857 N_Private_Type_Declaration |
1858 N_Procedure_Instantiation |
1859 N_Protected_Body_Stub |
1860 N_Protected_Type_Declaration |
1861 N_Single_Task_Declaration |
1863 N_Subprogram_Body_Stub |
1864 N_Subprogram_Declaration |
1865 N_Subprogram_Renaming_Declaration |
1866 N_Subtype_Declaration |
1869 N_Task_Type_Declaration |
1871 -- Freeze entity behaves like a declaration or statement
1875 -- Do not insert here if the item is not a list member (this
1876 -- happens for example with a triggering statement, and the
1877 -- proper approach is to insert before the entire select).
1879 if not Is_List_Member
(P
) then
1882 -- Do not insert if parent of P is an N_Component_Association
1883 -- node (i.e. we are in the context of an N_Aggregate node.
1884 -- In this case we want to insert before the entire aggregate.
1886 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
1889 -- Do not insert if the parent of P is either an N_Variant
1890 -- node or an N_Record_Definition node, meaning in either
1891 -- case that P is a member of a component list, and that
1892 -- therefore the actions should be inserted outside the
1893 -- complete record declaration.
1895 elsif Nkind
(Parent
(P
)) = N_Variant
1896 or else Nkind
(Parent
(P
)) = N_Record_Definition
1900 -- Do not insert freeze nodes within the loop generated for
1901 -- an aggregate, because they may be elaborated too late for
1902 -- subsequent use in the back end: within a package spec the
1903 -- loop is part of the elaboration procedure and is only
1904 -- elaborated during the second pass.
1905 -- If the loop comes from source, or the entity is local to
1906 -- the loop itself it must remain within.
1908 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
1909 and then not Comes_From_Source
(Parent
(P
))
1910 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
1912 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
1916 -- Otherwise we can go ahead and do the insertion
1918 elsif P
= Wrapped_Node
then
1919 Store_Before_Actions_In_Scope
(Ins_Actions
);
1923 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1927 -- A special case, N_Raise_xxx_Error can act either as a
1928 -- statement or a subexpression. We tell the difference
1929 -- by looking at the Etype. It is set to Standard_Void_Type
1930 -- in the statement case.
1933 N_Raise_xxx_Error
=>
1934 if Etype
(P
) = Standard_Void_Type
then
1935 if P
= Wrapped_Node
then
1936 Store_Before_Actions_In_Scope
(Ins_Actions
);
1938 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1943 -- In the subexpression case, keep climbing
1949 -- If a component association appears within a loop created for
1950 -- an array aggregate, attach the actions to the association so
1951 -- they can be subsequently inserted within the loop. For other
1952 -- component associations insert outside of the aggregate. For
1953 -- an association that will generate a loop, its Loop_Actions
1954 -- attribute is already initialized (see exp_aggr.adb).
1956 -- The list of loop_actions can in turn generate additional ones,
1957 -- that are inserted before the associated node. If the associated
1958 -- node is outside the aggregate, the new actions are collected
1959 -- at the end of the loop actions, to respect the order in which
1960 -- they are to be elaborated.
1963 N_Component_Association
=>
1964 if Nkind
(Parent
(P
)) = N_Aggregate
1965 and then Present
(Loop_Actions
(P
))
1967 if Is_Empty_List
(Loop_Actions
(P
)) then
1968 Set_Loop_Actions
(P
, Ins_Actions
);
1969 Analyze_List
(Ins_Actions
);
1976 -- Check whether these actions were generated
1977 -- by a declaration that is part of the loop_
1978 -- actions for the component_association.
1981 while Present
(Decl
) loop
1982 exit when Parent
(Decl
) = P
1983 and then Is_List_Member
(Decl
)
1985 List_Containing
(Decl
) = Loop_Actions
(P
);
1986 Decl
:= Parent
(Decl
);
1989 if Present
(Decl
) then
1990 Insert_List_Before_And_Analyze
1991 (Decl
, Ins_Actions
);
1993 Insert_List_After_And_Analyze
1994 (Last
(Loop_Actions
(P
)), Ins_Actions
);
2005 -- Another special case, an attribute denoting a procedure call
2008 N_Attribute_Reference
=>
2009 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
2010 if P
= Wrapped_Node
then
2011 Store_Before_Actions_In_Scope
(Ins_Actions
);
2013 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
2018 -- In the subexpression case, keep climbing
2024 -- For all other node types, keep climbing tree
2028 N_Accept_Alternative |
2029 N_Access_Definition |
2030 N_Access_Function_Definition |
2031 N_Access_Procedure_Definition |
2032 N_Access_To_Object_Definition |
2035 N_Case_Statement_Alternative |
2036 N_Character_Literal |
2037 N_Compilation_Unit |
2038 N_Compilation_Unit_Aux |
2039 N_Component_Clause |
2040 N_Component_Declaration |
2041 N_Component_Definition |
2043 N_Constrained_Array_Definition |
2044 N_Decimal_Fixed_Point_Definition |
2045 N_Defining_Character_Literal |
2046 N_Defining_Identifier |
2047 N_Defining_Operator_Symbol |
2048 N_Defining_Program_Unit_Name |
2049 N_Delay_Alternative |
2050 N_Delta_Constraint |
2051 N_Derived_Type_Definition |
2053 N_Digits_Constraint |
2054 N_Discriminant_Association |
2055 N_Discriminant_Specification |
2057 N_Entry_Body_Formal_Part |
2058 N_Entry_Call_Alternative |
2059 N_Entry_Declaration |
2060 N_Entry_Index_Specification |
2061 N_Enumeration_Type_Definition |
2063 N_Exception_Handler |
2065 N_Explicit_Dereference |
2066 N_Extension_Aggregate |
2067 N_Floating_Point_Definition |
2068 N_Formal_Decimal_Fixed_Point_Definition |
2069 N_Formal_Derived_Type_Definition |
2070 N_Formal_Discrete_Type_Definition |
2071 N_Formal_Floating_Point_Definition |
2072 N_Formal_Modular_Type_Definition |
2073 N_Formal_Ordinary_Fixed_Point_Definition |
2074 N_Formal_Package_Declaration |
2075 N_Formal_Private_Type_Definition |
2076 N_Formal_Signed_Integer_Type_Definition |
2078 N_Function_Specification |
2079 N_Generic_Association |
2080 N_Handled_Sequence_Of_Statements |
2083 N_Index_Or_Discriminant_Constraint |
2084 N_Indexed_Component |
2088 N_Loop_Parameter_Specification |
2090 N_Modular_Type_Definition |
2116 N_Op_Shift_Right_Arithmetic |
2120 N_Ordinary_Fixed_Point_Definition |
2122 N_Package_Specification |
2123 N_Parameter_Association |
2124 N_Parameter_Specification |
2125 N_Pragma_Argument_Association |
2126 N_Procedure_Specification |
2128 N_Protected_Definition |
2129 N_Qualified_Expression |
2131 N_Range_Constraint |
2133 N_Real_Range_Specification |
2134 N_Record_Definition |
2136 N_Selected_Component |
2137 N_Signed_Integer_Type_Definition |
2138 N_Single_Protected_Declaration |
2142 N_Subtype_Indication |
2145 N_Terminate_Alternative |
2146 N_Triggering_Alternative |
2148 N_Unchecked_Expression |
2149 N_Unchecked_Type_Conversion |
2150 N_Unconstrained_Array_Definition |
2153 N_Use_Package_Clause |
2157 N_Validate_Unchecked_Conversion |
2165 -- Make sure that inserted actions stay in the transient scope
2167 if P
= Wrapped_Node
then
2168 Store_Before_Actions_In_Scope
(Ins_Actions
);
2172 -- If we fall through above tests, keep climbing tree
2176 if Nkind
(Parent
(N
)) = N_Subunit
then
2178 -- This is the proper body corresponding to a stub. Insertion
2179 -- must be done at the point of the stub, which is in the decla-
2180 -- tive part of the parent unit.
2182 P
:= Corresponding_Stub
(Parent
(N
));
2191 -- Version with check(s) suppressed
2193 procedure Insert_Actions
2194 (Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
; Suppress
: Check_Id
)
2197 if Suppress
= All_Checks
then
2199 Svg
: constant Suppress_Array
:= Scope_Suppress
;
2202 Scope_Suppress
:= (others => True);
2203 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2204 Scope_Suppress
:= Svg
;
2209 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
2212 Scope_Suppress
(Suppress
) := True;
2213 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2214 Scope_Suppress
(Suppress
) := Svg
;
2219 --------------------------
2220 -- Insert_Actions_After --
2221 --------------------------
2223 procedure Insert_Actions_After
2224 (Assoc_Node
: Node_Id
;
2225 Ins_Actions
: List_Id
)
2228 if Scope_Is_Transient
2229 and then Assoc_Node
= Node_To_Be_Wrapped
2231 Store_After_Actions_In_Scope
(Ins_Actions
);
2233 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
2235 end Insert_Actions_After
;
2237 ---------------------------------
2238 -- Insert_Library_Level_Action --
2239 ---------------------------------
2241 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
2242 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2245 New_Scope
(Cunit_Entity
(Main_Unit
));
2247 if No
(Actions
(Aux
)) then
2248 Set_Actions
(Aux
, New_List
(N
));
2250 Append
(N
, Actions
(Aux
));
2255 end Insert_Library_Level_Action
;
2257 ----------------------------------
2258 -- Insert_Library_Level_Actions --
2259 ----------------------------------
2261 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
2262 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2265 if Is_Non_Empty_List
(L
) then
2266 New_Scope
(Cunit_Entity
(Main_Unit
));
2268 if No
(Actions
(Aux
)) then
2269 Set_Actions
(Aux
, L
);
2272 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
2277 end Insert_Library_Level_Actions
;
2279 ----------------------
2280 -- Inside_Init_Proc --
2281 ----------------------
2283 function Inside_Init_Proc
return Boolean is
2289 and then S
/= Standard_Standard
2291 if Is_Init_Proc
(S
) then
2299 end Inside_Init_Proc
;
2301 ----------------------------
2302 -- Is_All_Null_Statements --
2303 ----------------------------
2305 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
2310 while Present
(Stm
) loop
2311 if Nkind
(Stm
) /= N_Null_Statement
then
2319 end Is_All_Null_Statements
;
2321 ----------------------------------
2322 -- Is_Possibly_Unaligned_Object --
2323 ----------------------------------
2325 function Is_Possibly_Unaligned_Object
(P
: Node_Id
) return Boolean is
2327 -- If target does not have strict alignment, result is always
2328 -- False, since correctness of code does no depend on alignment.
2330 if not Target_Strict_Alignment
then
2334 -- If renamed object, apply test to underlying object
2336 if Is_Entity_Name
(P
)
2337 and then Is_Object
(Entity
(P
))
2338 and then Present
(Renamed_Object
(Entity
(P
)))
2340 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(P
)));
2343 -- If this is an element of a packed array, may be unaligned
2345 if Is_Ref_To_Bit_Packed_Array
(P
) then
2349 -- Case of component reference
2351 if Nkind
(P
) = N_Selected_Component
then
2353 -- If component reference is for a record that is bit packed
2354 -- or has a specified alignment (that might be too small) or
2355 -- the component reference has a component clause, then the
2356 -- object may be unaligned.
2358 if Is_Packed
(Etype
(Prefix
(P
)))
2359 or else Known_Alignment
(Etype
(Prefix
(P
)))
2360 or else Present
(Component_Clause
(Entity
(Selector_Name
(P
))))
2364 -- Otherwise, for a component reference, test prefix
2367 return Is_Possibly_Unaligned_Object
(Prefix
(P
));
2370 -- If not a component reference, must be aligned
2375 end Is_Possibly_Unaligned_Object
;
2377 ---------------------------------
2378 -- Is_Possibly_Unaligned_Slice --
2379 ---------------------------------
2381 function Is_Possibly_Unaligned_Slice
(P
: Node_Id
) return Boolean is
2383 -- ??? GCC3 will eventually handle strings with arbitrary alignments,
2384 -- but for now the following check must be disabled.
2386 -- if get_gcc_version >= 3 then
2390 -- For renaming case, go to renamed object
2392 if Is_Entity_Name
(P
)
2393 and then Is_Object
(Entity
(P
))
2394 and then Present
(Renamed_Object
(Entity
(P
)))
2396 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(P
)));
2399 -- The reference must be a slice
2401 if Nkind
(P
) /= N_Slice
then
2405 -- Always assume the worst for a nested record component with a
2406 -- component clause, which gigi/gcc does not appear to handle well.
2407 -- It is not clear why this special test is needed at all ???
2409 if Nkind
(Prefix
(P
)) = N_Selected_Component
2410 and then Nkind
(Prefix
(Prefix
(P
))) = N_Selected_Component
2412 Present
(Component_Clause
(Entity
(Selector_Name
(Prefix
(P
)))))
2417 -- We only need to worry if the target has strict alignment
2419 if not Target_Strict_Alignment
then
2423 -- If it is a slice, then look at the array type being sliced
2426 Sarr
: constant Node_Id
:= Prefix
(P
);
2427 -- Prefix of the slice, i.e. the array being sliced
2429 Styp
: constant Entity_Id
:= Etype
(Prefix
(P
));
2430 -- Type of the array being sliced
2436 -- The problems arise if the array object that is being sliced
2437 -- is a component of a record or array, and we cannot guarantee
2438 -- the alignment of the array within its containing object.
2440 -- To investigate this, we look at successive prefixes to see
2441 -- if we have a worrisome indexed or selected component.
2445 -- Case of array is part of an indexed component reference
2447 if Nkind
(Pref
) = N_Indexed_Component
then
2448 Ptyp
:= Etype
(Prefix
(Pref
));
2450 -- The only problematic case is when the array is packed,
2451 -- in which case we really know nothing about the alignment
2452 -- of individual components.
2454 if Is_Bit_Packed_Array
(Ptyp
) then
2458 -- Case of array is part of a selected component reference
2460 elsif Nkind
(Pref
) = N_Selected_Component
then
2461 Ptyp
:= Etype
(Prefix
(Pref
));
2463 -- We are definitely in trouble if the record in question
2464 -- has an alignment, and either we know this alignment is
2465 -- inconsistent with the alignment of the slice, or we
2466 -- don't know what the alignment of the slice should be.
2468 if Known_Alignment
(Ptyp
)
2469 and then (Unknown_Alignment
(Styp
)
2470 or else Alignment
(Styp
) > Alignment
(Ptyp
))
2475 -- We are in potential trouble if the record type is packed.
2476 -- We could special case when we know that the array is the
2477 -- first component, but that's not such a simple case ???
2479 if Is_Packed
(Ptyp
) then
2483 -- We are in trouble if there is a component clause, and
2484 -- either we do not know the alignment of the slice, or
2485 -- the alignment of the slice is inconsistent with the
2486 -- bit position specified by the component clause.
2489 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2491 if Present
(Component_Clause
(Field
))
2493 (Unknown_Alignment
(Styp
)
2495 (Component_Bit_Offset
(Field
) mod
2496 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
2502 -- For cases other than selected or indexed components we
2503 -- know we are OK, since no issues arise over alignment.
2509 -- We processed an indexed component or selected component
2510 -- reference that looked safe, so keep checking prefixes.
2512 Pref
:= Prefix
(Pref
);
2515 end Is_Possibly_Unaligned_Slice
;
2517 --------------------------------
2518 -- Is_Ref_To_Bit_Packed_Array --
2519 --------------------------------
2521 function Is_Ref_To_Bit_Packed_Array
(P
: Node_Id
) return Boolean is
2526 if Is_Entity_Name
(P
)
2527 and then Is_Object
(Entity
(P
))
2528 and then Present
(Renamed_Object
(Entity
(P
)))
2530 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(P
)));
2533 if Nkind
(P
) = N_Indexed_Component
2535 Nkind
(P
) = N_Selected_Component
2537 if Is_Bit_Packed_Array
(Etype
(Prefix
(P
))) then
2540 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(P
));
2543 if Result
and then Nkind
(P
) = N_Indexed_Component
then
2544 Expr
:= First
(Expressions
(P
));
2545 while Present
(Expr
) loop
2546 Force_Evaluation
(Expr
);
2556 end Is_Ref_To_Bit_Packed_Array
;
2558 --------------------------------
2559 -- Is_Ref_To_Bit_Packed_Slice --
2560 --------------------------------
2562 function Is_Ref_To_Bit_Packed_Slice
(P
: Node_Id
) return Boolean is
2564 if Is_Entity_Name
(P
)
2565 and then Is_Object
(Entity
(P
))
2566 and then Present
(Renamed_Object
(Entity
(P
)))
2568 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(P
)));
2571 if Nkind
(P
) = N_Slice
2572 and then Is_Bit_Packed_Array
(Etype
(Prefix
(P
)))
2576 elsif Nkind
(P
) = N_Indexed_Component
2578 Nkind
(P
) = N_Selected_Component
2580 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(P
));
2585 end Is_Ref_To_Bit_Packed_Slice
;
2587 -----------------------
2588 -- Is_Renamed_Object --
2589 -----------------------
2591 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
2592 Pnod
: constant Node_Id
:= Parent
(N
);
2593 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
2596 if Kind
= N_Object_Renaming_Declaration
then
2599 elsif Kind
= N_Indexed_Component
2600 or else Kind
= N_Selected_Component
2602 return Is_Renamed_Object
(Pnod
);
2607 end Is_Renamed_Object
;
2609 ----------------------------
2610 -- Is_Untagged_Derivation --
2611 ----------------------------
2613 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
2615 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
2617 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
2618 and then not Is_Tagged_Type
(Full_View
(T
))
2619 and then Is_Derived_Type
(Full_View
(T
))
2620 and then Etype
(Full_View
(T
)) /= T
);
2622 end Is_Untagged_Derivation
;
2624 --------------------
2625 -- Kill_Dead_Code --
2626 --------------------
2628 procedure Kill_Dead_Code
(N
: Node_Id
) is
2631 Remove_Handler_Entries
(N
);
2632 Remove_Warning_Messages
(N
);
2634 -- Recurse into block statements and bodies to process declarations
2637 if Nkind
(N
) = N_Block_Statement
2638 or else Nkind
(N
) = N_Subprogram_Body
2639 or else Nkind
(N
) = N_Package_Body
2641 Kill_Dead_Code
(Declarations
(N
));
2642 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
2644 if Nkind
(N
) = N_Subprogram_Body
then
2645 Set_Is_Eliminated
(Defining_Entity
(N
));
2648 -- Recurse into composite statement to kill individual statements,
2649 -- in particular instantiations.
2651 elsif Nkind
(N
) = N_If_Statement
then
2652 Kill_Dead_Code
(Then_Statements
(N
));
2653 Kill_Dead_Code
(Elsif_Parts
(N
));
2654 Kill_Dead_Code
(Else_Statements
(N
));
2656 elsif Nkind
(N
) = N_Loop_Statement
then
2657 Kill_Dead_Code
(Statements
(N
));
2659 elsif Nkind
(N
) = N_Case_Statement
then
2663 Alt
:= First
(Alternatives
(N
));
2664 while Present
(Alt
) loop
2665 Kill_Dead_Code
(Statements
(Alt
));
2670 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
2671 Kill_Dead_Code
(Statements
(N
));
2673 -- Deal with dead instances caused by deleting instantiations
2675 elsif Nkind
(N
) in N_Generic_Instantiation
then
2676 Remove_Dead_Instance
(N
);
2683 -- Case where argument is a list of nodes to be killed
2685 procedure Kill_Dead_Code
(L
: List_Id
) is
2689 if Is_Non_Empty_List
(L
) then
2691 N
:= Remove_Head
(L
);
2698 ------------------------
2699 -- Known_Non_Negative --
2700 ------------------------
2702 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
2704 if Is_OK_Static_Expression
(Opnd
)
2705 and then Expr_Value
(Opnd
) >= 0
2711 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
2715 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
2718 end Known_Non_Negative
;
2720 --------------------
2721 -- Known_Non_Null --
2722 --------------------
2724 function Known_Non_Null
(N
: Node_Id
) return Boolean is
2726 pragma Assert
(Is_Access_Type
(Underlying_Type
(Etype
(N
))));
2728 -- Case of entity for which Is_Known_Non_Null is True
2730 if Is_Entity_Name
(N
) and then Is_Known_Non_Null
(Entity
(N
)) then
2732 -- If the entity is aliased or volatile, then we decide that
2733 -- we don't know it is really non-null even if the sequential
2734 -- flow indicates that it is, since such variables can be
2735 -- changed without us noticing.
2737 if Is_Aliased
(Entity
(N
))
2738 or else Treat_As_Volatile
(Entity
(N
))
2742 -- For all other cases, the flag is decisive
2748 -- True if access attribute
2750 elsif Nkind
(N
) = N_Attribute_Reference
2751 and then (Attribute_Name
(N
) = Name_Access
2753 Attribute_Name
(N
) = Name_Unchecked_Access
2755 Attribute_Name
(N
) = Name_Unrestricted_Access
)
2759 -- True if allocator
2761 elsif Nkind
(N
) = N_Allocator
then
2764 -- For a conversion, true if expression is known non-null
2766 elsif Nkind
(N
) = N_Type_Conversion
then
2767 return Known_Non_Null
(Expression
(N
));
2769 -- One more case is when Current_Value references a condition
2770 -- that ensures a non-null value.
2772 elsif Is_Entity_Name
(N
) then
2778 Get_Current_Value_Condition
(N
, Op
, Val
);
2779 return Op
= N_Op_Ne
and then Nkind
(Val
) = N_Null
;
2782 -- Above are all cases where the value could be determined to be
2783 -- non-null. In all other cases, we don't know, so return False.
2790 -----------------------------
2791 -- Make_CW_Equivalent_Type --
2792 -----------------------------
2794 -- Create a record type used as an equivalent of any member
2795 -- of the class which takes its size from exp.
2797 -- Generate the following code:
2799 -- type Equiv_T is record
2800 -- _parent : T (List of discriminant constaints taken from Exp);
2801 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
2804 -- ??? Note that this type does not guarantee same alignment as all
2807 function Make_CW_Equivalent_Type
2809 E
: Node_Id
) return Entity_Id
2811 Loc
: constant Source_Ptr
:= Sloc
(E
);
2812 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
2813 List_Def
: constant List_Id
:= Empty_List
;
2814 Equiv_Type
: Entity_Id
;
2815 Range_Type
: Entity_Id
;
2816 Str_Type
: Entity_Id
;
2817 Constr_Root
: Entity_Id
;
2821 if not Has_Discriminants
(Root_Typ
) then
2822 Constr_Root
:= Root_Typ
;
2825 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2827 -- subtype cstr__n is T (List of discr constraints taken from Exp)
2829 Append_To
(List_Def
,
2830 Make_Subtype_Declaration
(Loc
,
2831 Defining_Identifier
=> Constr_Root
,
2832 Subtype_Indication
=>
2833 Make_Subtype_From_Expr
(E
, Root_Typ
)));
2836 -- subtype rg__xx is Storage_Offset range
2837 -- (Expr'size - typ'size) / Storage_Unit
2839 Range_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('G'));
2842 Make_Op_Subtract
(Loc
,
2844 Make_Attribute_Reference
(Loc
,
2846 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
2847 Attribute_Name
=> Name_Size
),
2849 Make_Attribute_Reference
(Loc
,
2850 Prefix
=> New_Reference_To
(Constr_Root
, Loc
),
2851 Attribute_Name
=> Name_Object_Size
));
2853 Set_Paren_Count
(Sizexpr
, 1);
2855 Append_To
(List_Def
,
2856 Make_Subtype_Declaration
(Loc
,
2857 Defining_Identifier
=> Range_Type
,
2858 Subtype_Indication
=>
2859 Make_Subtype_Indication
(Loc
,
2860 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
2861 Constraint
=> Make_Range_Constraint
(Loc
,
2864 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
2866 Make_Op_Divide
(Loc
,
2867 Left_Opnd
=> Sizexpr
,
2868 Right_Opnd
=> Make_Integer_Literal
(Loc
,
2869 Intval
=> System_Storage_Unit
)))))));
2871 -- subtype str__nn is Storage_Array (rg__x);
2873 Str_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
2874 Append_To
(List_Def
,
2875 Make_Subtype_Declaration
(Loc
,
2876 Defining_Identifier
=> Str_Type
,
2877 Subtype_Indication
=>
2878 Make_Subtype_Indication
(Loc
,
2879 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Array
), Loc
),
2881 Make_Index_Or_Discriminant_Constraint
(Loc
,
2883 New_List
(New_Reference_To
(Range_Type
, Loc
))))));
2885 -- type Equiv_T is record
2890 Equiv_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
2892 -- When the target requires front-end layout, it's necessary to allow
2893 -- the equivalent type to be frozen so that layout can occur (when the
2894 -- associated class-wide subtype is frozen, the equivalent type will
2895 -- be frozen, see freeze.adb). For other targets, Gigi wants to have
2896 -- the equivalent type marked as frozen and deals with this type itself.
2897 -- In the Gigi case this will also avoid the generation of an init
2898 -- procedure for the type.
2900 if not Frontend_Layout_On_Target
then
2901 Set_Is_Frozen
(Equiv_Type
);
2904 Set_Ekind
(Equiv_Type
, E_Record_Type
);
2905 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
2907 Append_To
(List_Def
,
2908 Make_Full_Type_Declaration
(Loc
,
2909 Defining_Identifier
=> Equiv_Type
,
2912 Make_Record_Definition
(Loc
,
2913 Component_List
=> Make_Component_List
(Loc
,
2914 Component_Items
=> New_List
(
2915 Make_Component_Declaration
(Loc
,
2916 Defining_Identifier
=>
2917 Make_Defining_Identifier
(Loc
, Name_uParent
),
2918 Component_Definition
=>
2919 Make_Component_Definition
(Loc
,
2920 Aliased_Present
=> False,
2921 Subtype_Indication
=>
2922 New_Reference_To
(Constr_Root
, Loc
))),
2924 Make_Component_Declaration
(Loc
,
2925 Defining_Identifier
=>
2926 Make_Defining_Identifier
(Loc
,
2927 Chars
=> New_Internal_Name
('C')),
2928 Component_Definition
=>
2929 Make_Component_Definition
(Loc
,
2930 Aliased_Present
=> False,
2931 Subtype_Indication
=>
2932 New_Reference_To
(Str_Type
, Loc
)))),
2934 Variant_Part
=> Empty
))));
2936 Insert_Actions
(E
, List_Def
);
2938 end Make_CW_Equivalent_Type
;
2940 ------------------------
2941 -- Make_Literal_Range --
2942 ------------------------
2944 function Make_Literal_Range
2946 Literal_Typ
: Entity_Id
) return Node_Id
2948 Lo
: constant Node_Id
:=
2949 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
2952 Set_Analyzed
(Lo
, False);
2959 Make_Op_Subtract
(Loc
,
2962 Left_Opnd
=> New_Copy_Tree
(Lo
),
2964 Make_Integer_Literal
(Loc
,
2965 String_Literal_Length
(Literal_Typ
))),
2966 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
2967 end Make_Literal_Range
;
2969 ----------------------------
2970 -- Make_Subtype_From_Expr --
2971 ----------------------------
2973 -- 1. If Expr is an uncontrained array expression, creates
2974 -- Unc_Type(Expr'first(1)..Expr'Last(1),..., Expr'first(n)..Expr'last(n))
2976 -- 2. If Expr is a unconstrained discriminated type expression, creates
2977 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
2979 -- 3. If Expr is class-wide, creates an implicit class wide subtype
2981 function Make_Subtype_From_Expr
2983 Unc_Typ
: Entity_Id
) return Node_Id
2985 Loc
: constant Source_Ptr
:= Sloc
(E
);
2986 List_Constr
: constant List_Id
:= New_List
;
2989 Full_Subtyp
: Entity_Id
;
2990 Priv_Subtyp
: Entity_Id
;
2995 if Is_Private_Type
(Unc_Typ
)
2996 and then Has_Unknown_Discriminants
(Unc_Typ
)
2998 -- Prepare the subtype completion, Go to base type to
2999 -- find underlying type.
3001 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
3002 Full_Subtyp
:= Make_Defining_Identifier
(Loc
,
3003 New_Internal_Name
('C'));
3005 Unchecked_Convert_To
3006 (Utyp
, Duplicate_Subexpr_No_Checks
(E
));
3007 Set_Parent
(Full_Exp
, Parent
(E
));
3010 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
3013 Make_Subtype_Declaration
(Loc
,
3014 Defining_Identifier
=> Full_Subtyp
,
3015 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
3017 -- Define the dummy private subtype
3019 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
3020 Set_Etype
(Priv_Subtyp
, Unc_Typ
);
3021 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
3022 Set_Is_Constrained
(Priv_Subtyp
);
3023 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
3024 Set_Is_Itype
(Priv_Subtyp
);
3025 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
3027 if Is_Tagged_Type
(Priv_Subtyp
) then
3029 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
3030 Set_Primitive_Operations
(Priv_Subtyp
,
3031 Primitive_Operations
(Unc_Typ
));
3034 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
3036 return New_Reference_To
(Priv_Subtyp
, Loc
);
3038 elsif Is_Array_Type
(Unc_Typ
) then
3039 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
3040 Append_To
(List_Constr
,
3043 Make_Attribute_Reference
(Loc
,
3044 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3045 Attribute_Name
=> Name_First
,
3046 Expressions
=> New_List
(
3047 Make_Integer_Literal
(Loc
, J
))),
3050 Make_Attribute_Reference
(Loc
,
3051 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3052 Attribute_Name
=> Name_Last
,
3053 Expressions
=> New_List
(
3054 Make_Integer_Literal
(Loc
, J
)))));
3057 elsif Is_Class_Wide_Type
(Unc_Typ
) then
3059 CW_Subtype
: Entity_Id
;
3060 EQ_Typ
: Entity_Id
:= Empty
;
3063 -- A class-wide equivalent type is not needed when Java_VM
3064 -- because the JVM back end handles the class-wide object
3065 -- initialization itself (and doesn't need or want the
3066 -- additional intermediate type to handle the assignment).
3068 if Expander_Active
and then not Java_VM
then
3069 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
3072 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
3073 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
3075 if Present
(EQ_Typ
) then
3076 Set_Is_Class_Wide_Equivalent_Type
(EQ_Typ
);
3079 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
3081 return New_Occurrence_Of
(CW_Subtype
, Loc
);
3084 -- Comment needed (what case is this ???)
3087 D
:= First_Discriminant
(Unc_Typ
);
3088 while Present
(D
) loop
3089 Append_To
(List_Constr
,
3090 Make_Selected_Component
(Loc
,
3091 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3092 Selector_Name
=> New_Reference_To
(D
, Loc
)));
3094 Next_Discriminant
(D
);
3099 Make_Subtype_Indication
(Loc
,
3100 Subtype_Mark
=> New_Reference_To
(Unc_Typ
, Loc
),
3102 Make_Index_Or_Discriminant_Constraint
(Loc
,
3103 Constraints
=> List_Constr
));
3104 end Make_Subtype_From_Expr
;
3106 -----------------------------
3107 -- May_Generate_Large_Temp --
3108 -----------------------------
3110 -- At the current time, the only types that we return False for (i.e.
3111 -- where we decide we know they cannot generate large temps) are ones
3112 -- where we know the size is 128 bits or less at compile time, and we
3113 -- are still not doing a thorough job on arrays and records ???
3115 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
3117 if not Size_Known_At_Compile_Time
(Typ
) then
3120 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
3123 elsif Is_Array_Type
(Typ
)
3124 and then Present
(Packed_Array_Type
(Typ
))
3126 return May_Generate_Large_Temp
(Packed_Array_Type
(Typ
));
3128 -- We could do more here to find other small types ???
3133 end May_Generate_Large_Temp
;
3135 ----------------------------
3136 -- New_Class_Wide_Subtype --
3137 ----------------------------
3139 function New_Class_Wide_Subtype
3140 (CW_Typ
: Entity_Id
;
3141 N
: Node_Id
) return Entity_Id
3143 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
3144 Res_Name
: constant Name_Id
:= Chars
(Res
);
3145 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
3148 Copy_Node
(CW_Typ
, Res
);
3149 Set_Sloc
(Res
, Sloc
(N
));
3151 Set_Associated_Node_For_Itype
(Res
, N
);
3152 Set_Is_Public
(Res
, False); -- By default, may be changed below.
3153 Set_Public_Status
(Res
);
3154 Set_Chars
(Res
, Res_Name
);
3155 Set_Scope
(Res
, Res_Scope
);
3156 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
3157 Set_Next_Entity
(Res
, Empty
);
3158 Set_Etype
(Res
, Base_Type
(CW_Typ
));
3160 -- For targets where front-end layout is required, reset the Is_Frozen
3161 -- status of the subtype to False (it can be implicitly set to true
3162 -- from the copy of the class-wide type). For other targets, Gigi
3163 -- doesn't want the class-wide subtype to go through the freezing
3164 -- process (though it's unclear why that causes problems and it would
3165 -- be nice to allow freezing to occur normally for all targets ???).
3167 if Frontend_Layout_On_Target
then
3168 Set_Is_Frozen
(Res
, False);
3171 Set_Freeze_Node
(Res
, Empty
);
3173 end New_Class_Wide_Subtype
;
3175 -------------------------
3176 -- Remove_Side_Effects --
3177 -------------------------
3179 procedure Remove_Side_Effects
3181 Name_Req
: Boolean := False;
3182 Variable_Ref
: Boolean := False)
3184 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
3185 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
3186 Svg_Suppress
: constant Suppress_Array
:= Scope_Suppress
;
3188 Ref_Type
: Entity_Id
;
3190 Ptr_Typ_Decl
: Node_Id
;
3194 function Side_Effect_Free
(N
: Node_Id
) return Boolean;
3195 -- Determines if the tree N represents an expession that is known
3196 -- not to have side effects, and for which no processing is required.
3198 function Side_Effect_Free
(L
: List_Id
) return Boolean;
3199 -- Determines if all elements of the list L are side effect free
3201 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
3202 -- The argument N is a construct where the Prefix is dereferenced
3203 -- if it is a an access type and the result is a variable. The call
3204 -- returns True if the construct is side effect free (not considering
3205 -- side effects in other than the prefix which are to be tested by the
3208 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
3209 -- Determines if N is a subcomponent of a composite in-parameter.
3210 -- If so, N is not side-effect free when the actual is global and
3211 -- modifiable indirectly from within a subprogram, because it may
3212 -- be passed by reference. The front-end must be conservative here
3213 -- and assume that this may happen with any array or record type.
3214 -- On the other hand, we cannot create temporaries for all expressions
3215 -- for which this condition is true, for various reasons that might
3216 -- require clearing up ??? For example, descriminant references that
3217 -- appear out of place, or spurious type errors with class-wide
3218 -- expressions. As a result, we limit the transformation to loop
3219 -- bounds, which is so far the only case that requires it.
3221 -----------------------------
3222 -- Safe_Prefixed_Reference --
3223 -----------------------------
3225 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
3227 -- If prefix is not side effect free, definitely not safe
3229 if not Side_Effect_Free
(Prefix
(N
)) then
3232 -- If the prefix is of an access type that is not access-to-constant,
3233 -- then this construct is a variable reference, which means it is to
3234 -- be considered to have side effects if Variable_Ref is set True
3235 -- Exception is an access to an entity that is a constant or an
3236 -- in-parameter which does not come from source, and is the result
3237 -- of a previous removal of side-effects.
3239 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
3240 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
3241 and then Variable_Ref
3243 if not Is_Entity_Name
(Prefix
(N
)) then
3246 return Ekind
(Entity
(Prefix
(N
))) = E_Constant
3247 or else Ekind
(Entity
(Prefix
(N
))) = E_In_Parameter
;
3250 -- The following test is the simplest way of solving a complex
3251 -- problem uncovered by BB08-010: Side effect on loop bound that
3252 -- is a subcomponent of a global variable:
3253 -- If a loop bound is a subcomponent of a global variable, a
3254 -- modification of that variable within the loop may incorrectly
3255 -- affect the execution of the loop.
3258 (Nkind
(Parent
(Parent
(N
))) /= N_Loop_Parameter_Specification
3259 or else not Within_In_Parameter
(Prefix
(N
)))
3263 -- All other cases are side effect free
3268 end Safe_Prefixed_Reference
;
3270 ----------------------
3271 -- Side_Effect_Free --
3272 ----------------------
3274 function Side_Effect_Free
(N
: Node_Id
) return Boolean is
3276 -- Note on checks that could raise Constraint_Error. Strictly, if
3277 -- we take advantage of 11.6, these checks do not count as side
3278 -- effects. However, we would just as soon consider that they are
3279 -- side effects, since the backend CSE does not work very well on
3280 -- expressions which can raise Constraint_Error. On the other
3281 -- hand, if we do not consider them to be side effect free, then
3282 -- we get some awkward expansions in -gnato mode, resulting in
3283 -- code insertions at a point where we do not have a clear model
3284 -- for performing the insertions. See 4908-002/comment for details.
3286 -- Special handling for entity names
3288 if Is_Entity_Name
(N
) then
3290 -- If the entity is a constant, it is definitely side effect
3291 -- free. Note that the test of Is_Variable (N) below might
3292 -- be expected to catch this case, but it does not, because
3293 -- this test goes to the original tree, and we may have
3294 -- already rewritten a variable node with a constant as
3295 -- a result of an earlier Force_Evaluation call.
3297 if Ekind
(Entity
(N
)) = E_Constant
3298 or else Ekind
(Entity
(N
)) = E_In_Parameter
3302 -- Functions are not side effect free
3304 elsif Ekind
(Entity
(N
)) = E_Function
then
3307 -- Variables are considered to be a side effect if Variable_Ref
3308 -- is set or if we have a volatile variable and Name_Req is off.
3309 -- If Name_Req is True then we can't help returning a name which
3310 -- effectively allows multiple references in any case.
3312 elsif Is_Variable
(N
) then
3313 return not Variable_Ref
3314 and then (not Treat_As_Volatile
(Entity
(N
))
3317 -- Any other entity (e.g. a subtype name) is definitely side
3324 -- A value known at compile time is always side effect free
3326 elsif Compile_Time_Known_Value
(N
) then
3330 -- For other than entity names and compile time known values,
3331 -- check the node kind for special processing.
3335 -- An attribute reference is side effect free if its expressions
3336 -- are side effect free and its prefix is side effect free or
3337 -- is an entity reference.
3339 -- Is this right? what about x'first where x is a variable???
3341 when N_Attribute_Reference
=>
3342 return Side_Effect_Free
(Expressions
(N
))
3343 and then (Is_Entity_Name
(Prefix
(N
))
3344 or else Side_Effect_Free
(Prefix
(N
)));
3346 -- A binary operator is side effect free if and both operands
3347 -- are side effect free. For this purpose binary operators
3348 -- include membership tests and short circuit forms
3355 return Side_Effect_Free
(Left_Opnd
(N
))
3356 and then Side_Effect_Free
(Right_Opnd
(N
));
3358 -- An explicit dereference is side effect free only if it is
3359 -- a side effect free prefixed reference.
3361 when N_Explicit_Dereference
=>
3362 return Safe_Prefixed_Reference
(N
);
3364 -- A call to _rep_to_pos is side effect free, since we generate
3365 -- this pure function call ourselves. Moreover it is critically
3366 -- important to make this exception, since otherwise we can
3367 -- have discriminants in array components which don't look
3368 -- side effect free in the case of an array whose index type
3369 -- is an enumeration type with an enumeration rep clause.
3371 -- All other function calls are not side effect free
3373 when N_Function_Call
=>
3374 return Nkind
(Name
(N
)) = N_Identifier
3375 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
3377 Side_Effect_Free
(First
(Parameter_Associations
(N
)));
3379 -- An indexed component is side effect free if it is a side
3380 -- effect free prefixed reference and all the indexing
3381 -- expressions are side effect free.
3383 when N_Indexed_Component
=>
3384 return Side_Effect_Free
(Expressions
(N
))
3385 and then Safe_Prefixed_Reference
(N
);
3387 -- A type qualification is side effect free if the expression
3388 -- is side effect free.
3390 when N_Qualified_Expression
=>
3391 return Side_Effect_Free
(Expression
(N
));
3393 -- A selected component is side effect free only if it is a
3394 -- side effect free prefixed reference.
3396 when N_Selected_Component
=>
3397 return Safe_Prefixed_Reference
(N
);
3399 -- A range is side effect free if the bounds are side effect free
3402 return Side_Effect_Free
(Low_Bound
(N
))
3403 and then Side_Effect_Free
(High_Bound
(N
));
3405 -- A slice is side effect free if it is a side effect free
3406 -- prefixed reference and the bounds are side effect free.
3409 return Side_Effect_Free
(Discrete_Range
(N
))
3410 and then Safe_Prefixed_Reference
(N
);
3412 -- A type conversion is side effect free if the expression
3413 -- to be converted is side effect free.
3415 when N_Type_Conversion
=>
3416 return Side_Effect_Free
(Expression
(N
));
3418 -- A unary operator is side effect free if the operand
3419 -- is side effect free.
3422 return Side_Effect_Free
(Right_Opnd
(N
));
3424 -- An unchecked type conversion is side effect free only if it
3425 -- is safe and its argument is side effect free.
3427 when N_Unchecked_Type_Conversion
=>
3428 return Safe_Unchecked_Type_Conversion
(N
)
3429 and then Side_Effect_Free
(Expression
(N
));
3431 -- An unchecked expression is side effect free if its expression
3432 -- is side effect free.
3434 when N_Unchecked_Expression
=>
3435 return Side_Effect_Free
(Expression
(N
));
3437 -- A literal is side effect free
3439 when N_Character_Literal |
3445 -- We consider that anything else has side effects. This is a bit
3446 -- crude, but we are pretty close for most common cases, and we
3447 -- are certainly correct (i.e. we never return True when the
3448 -- answer should be False).
3453 end Side_Effect_Free
;
3455 -- A list is side effect free if all elements of the list are
3456 -- side effect free.
3458 function Side_Effect_Free
(L
: List_Id
) return Boolean is
3462 if L
= No_List
or else L
= Error_List
then
3467 while Present
(N
) loop
3468 if not Side_Effect_Free
(N
) then
3477 end Side_Effect_Free
;
3479 -------------------------
3480 -- Within_In_Parameter --
3481 -------------------------
3483 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
3485 if not Comes_From_Source
(N
) then
3488 elsif Is_Entity_Name
(N
) then
3490 Ekind
(Entity
(N
)) = E_In_Parameter
;
3492 elsif Nkind
(N
) = N_Indexed_Component
3493 or else Nkind
(N
) = N_Selected_Component
3495 return Within_In_Parameter
(Prefix
(N
));
3500 end Within_In_Parameter
;
3502 -- Start of processing for Remove_Side_Effects
3505 -- If we are side effect free already or expansion is disabled,
3506 -- there is nothing to do.
3508 if Side_Effect_Free
(Exp
) or else not Expander_Active
then
3512 -- All this must not have any checks
3514 Scope_Suppress
:= (others => True);
3516 -- If the expression has the form v.all then we can just capture
3517 -- the pointer, and then do an explicit dereference on the result.
3519 if Nkind
(Exp
) = N_Explicit_Dereference
then
3521 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3523 Make_Explicit_Dereference
(Loc
, New_Reference_To
(Def_Id
, Loc
));
3526 Make_Object_Declaration
(Loc
,
3527 Defining_Identifier
=> Def_Id
,
3528 Object_Definition
=>
3529 New_Reference_To
(Etype
(Prefix
(Exp
)), Loc
),
3530 Constant_Present
=> True,
3531 Expression
=> Relocate_Node
(Prefix
(Exp
))));
3533 -- Similar processing for an unchecked conversion of an expression
3534 -- of the form v.all, where we want the same kind of treatment.
3536 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3537 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
3539 Remove_Side_Effects
(Expression
(Exp
), Variable_Ref
);
3540 Scope_Suppress
:= Svg_Suppress
;
3543 -- If this is a type conversion, leave the type conversion and remove
3544 -- the side effects in the expression. This is important in several
3545 -- circumstances: for change of representations, and also when this
3546 -- is a view conversion to a smaller object, where gigi can end up
3547 -- its own temporary of the wrong size.
3549 -- ??? this transformation is inhibited for elementary types that are
3550 -- not involved in a change of representation because it causes
3551 -- regressions that are not fully understood yet.
3553 elsif Nkind
(Exp
) = N_Type_Conversion
3554 and then (not Is_Elementary_Type
(Underlying_Type
(Exp_Type
))
3555 or else Nkind
(Parent
(Exp
)) = N_Assignment_Statement
)
3557 Remove_Side_Effects
(Expression
(Exp
), Variable_Ref
);
3558 Scope_Suppress
:= Svg_Suppress
;
3561 -- For expressions that denote objects, we can use a renaming scheme.
3562 -- We skip using this if we have a volatile variable and we do not
3563 -- have Nam_Req set true (see comments above for Side_Effect_Free).
3564 -- We also skip this scheme for class-wide expressions in order to
3565 -- avoid recursive expansion (see Expand_N_Object_Renaming_Declaration)
3566 -- If the object is a function call, we need to create a temporary and
3569 -- Note that we could use ordinary object declarations in the case of
3570 -- expressions not appearing as lvalues. That is left as a possible
3571 -- optimization in the future but we prefer to generate renamings
3572 -- right now, since we may indeed be transforming an lvalue.
3574 elsif Is_Object_Reference
(Exp
)
3575 and then Nkind
(Exp
) /= N_Function_Call
3576 and then not Variable_Ref
3578 or else not Is_Entity_Name
(Exp
)
3579 or else not Treat_As_Volatile
(Entity
(Exp
)))
3580 and then not Is_Class_Wide_Type
(Exp_Type
)
3582 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3584 if Nkind
(Exp
) = N_Selected_Component
3585 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
3586 and then Is_Array_Type
(Etype
(Exp
))
3588 -- Avoid generating a variable-sized temporary, by generating
3589 -- the renaming declaration just for the function call. The
3590 -- transformation could be refined to apply only when the array
3591 -- component is constrained by a discriminant???
3594 Make_Selected_Component
(Loc
,
3595 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
3596 Selector_Name
=> Selector_Name
(Exp
));
3599 Make_Object_Renaming_Declaration
(Loc
,
3600 Defining_Identifier
=> Def_Id
,
3602 New_Reference_To
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
3603 Name
=> Relocate_Node
(Prefix
(Exp
))));
3605 -- The temporary must be elaborated by gigi, and is of course
3606 -- not to be replaced in-line by the expression it renames,
3607 -- which would defeat the purpose of removing the side-effect.
3609 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3612 Res
:= New_Reference_To
(Def_Id
, Loc
);
3615 Make_Object_Renaming_Declaration
(Loc
,
3616 Defining_Identifier
=> Def_Id
,
3617 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3618 Name
=> Relocate_Node
(Exp
)));
3620 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3623 -- If it is a scalar type, just make a copy
3625 elsif Is_Elementary_Type
(Exp_Type
) then
3626 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3627 Set_Etype
(Def_Id
, Exp_Type
);
3628 Res
:= New_Reference_To
(Def_Id
, Loc
);
3631 Make_Object_Declaration
(Loc
,
3632 Defining_Identifier
=> Def_Id
,
3633 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3634 Constant_Present
=> True,
3635 Expression
=> Relocate_Node
(Exp
));
3637 Set_Assignment_OK
(E
);
3638 Insert_Action
(Exp
, E
);
3640 -- Always use a renaming for an unchecked conversion
3641 -- If this is an unchecked conversion that Gigi can't handle, make
3642 -- a copy or a use a renaming to capture the value.
3644 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3645 and then not Safe_Unchecked_Type_Conversion
(Exp
)
3647 if Controlled_Type
(Etype
(Exp
)) then
3649 -- Use a renaming to capture the expression, rather than create
3650 -- a controlled temporary.
3652 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3653 Res
:= New_Reference_To
(Def_Id
, Loc
);
3656 Make_Object_Renaming_Declaration
(Loc
,
3657 Defining_Identifier
=> Def_Id
,
3658 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3659 Name
=> Relocate_Node
(Exp
)));
3662 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3663 Set_Etype
(Def_Id
, Exp_Type
);
3664 Res
:= New_Reference_To
(Def_Id
, Loc
);
3667 Make_Object_Declaration
(Loc
,
3668 Defining_Identifier
=> Def_Id
,
3669 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3670 Constant_Present
=> not Is_Variable
(Exp
),
3671 Expression
=> Relocate_Node
(Exp
));
3673 Set_Assignment_OK
(E
);
3674 Insert_Action
(Exp
, E
);
3677 -- Otherwise we generate a reference to the value
3680 Ref_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3683 Make_Full_Type_Declaration
(Loc
,
3684 Defining_Identifier
=> Ref_Type
,
3686 Make_Access_To_Object_Definition
(Loc
,
3687 All_Present
=> True,
3688 Subtype_Indication
=>
3689 New_Reference_To
(Exp_Type
, Loc
)));
3692 Insert_Action
(Exp
, Ptr_Typ_Decl
);
3694 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3695 Set_Etype
(Def_Id
, Exp_Type
);
3698 Make_Explicit_Dereference
(Loc
,
3699 Prefix
=> New_Reference_To
(Def_Id
, Loc
));
3701 if Nkind
(E
) = N_Explicit_Dereference
then
3702 New_Exp
:= Relocate_Node
(Prefix
(E
));
3704 E
:= Relocate_Node
(E
);
3705 New_Exp
:= Make_Reference
(Loc
, E
);
3708 if Nkind
(E
) = N_Aggregate
and then Expansion_Delayed
(E
) then
3709 Set_Expansion_Delayed
(E
, False);
3710 Set_Analyzed
(E
, False);
3714 Make_Object_Declaration
(Loc
,
3715 Defining_Identifier
=> Def_Id
,
3716 Object_Definition
=> New_Reference_To
(Ref_Type
, Loc
),
3717 Expression
=> New_Exp
));
3720 -- Preserve the Assignment_OK flag in all copies, since at least
3721 -- one copy may be used in a context where this flag must be set
3722 -- (otherwise why would the flag be set in the first place).
3724 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
3726 -- Finally rewrite the original expression and we are done
3729 Analyze_And_Resolve
(Exp
, Exp_Type
);
3730 Scope_Suppress
:= Svg_Suppress
;
3731 end Remove_Side_Effects
;
3733 ------------------------------------
3734 -- Safe_Unchecked_Type_Conversion --
3735 ------------------------------------
3737 -- Note: this function knows quite a bit about the exact requirements
3738 -- of Gigi with respect to unchecked type conversions, and its code
3739 -- must be coordinated with any changes in Gigi in this area.
3741 -- The above requirements should be documented in Sinfo ???
3743 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
3748 Pexp
: constant Node_Id
:= Parent
(Exp
);
3751 -- If the expression is the RHS of an assignment or object declaration
3752 -- we are always OK because there will always be a target.
3754 -- Object renaming declarations, (generated for view conversions of
3755 -- actuals in inlined calls), like object declarations, provide an
3756 -- explicit type, and are safe as well.
3758 if (Nkind
(Pexp
) = N_Assignment_Statement
3759 and then Expression
(Pexp
) = Exp
)
3760 or else Nkind
(Pexp
) = N_Object_Declaration
3761 or else Nkind
(Pexp
) = N_Object_Renaming_Declaration
3765 -- If the expression is the prefix of an N_Selected_Component
3766 -- we should also be OK because GCC knows to look inside the
3767 -- conversion except if the type is discriminated. We assume
3768 -- that we are OK anyway if the type is not set yet or if it is
3769 -- controlled since we can't afford to introduce a temporary in
3772 elsif Nkind
(Pexp
) = N_Selected_Component
3773 and then Prefix
(Pexp
) = Exp
3775 if No
(Etype
(Pexp
)) then
3779 not Has_Discriminants
(Etype
(Pexp
))
3780 or else Is_Constrained
(Etype
(Pexp
));
3784 -- Set the output type, this comes from Etype if it is set, otherwise
3785 -- we take it from the subtype mark, which we assume was already
3788 if Present
(Etype
(Exp
)) then
3789 Otyp
:= Etype
(Exp
);
3791 Otyp
:= Entity
(Subtype_Mark
(Exp
));
3794 -- The input type always comes from the expression, and we assume
3795 -- this is indeed always analyzed, so we can simply get the Etype.
3797 Ityp
:= Etype
(Expression
(Exp
));
3799 -- Initialize alignments to unknown so far
3804 -- Replace a concurrent type by its corresponding record type
3805 -- and each type by its underlying type and do the tests on those.
3806 -- The original type may be a private type whose completion is a
3807 -- concurrent type, so find the underlying type first.
3809 if Present
(Underlying_Type
(Otyp
)) then
3810 Otyp
:= Underlying_Type
(Otyp
);
3813 if Present
(Underlying_Type
(Ityp
)) then
3814 Ityp
:= Underlying_Type
(Ityp
);
3817 if Is_Concurrent_Type
(Otyp
) then
3818 Otyp
:= Corresponding_Record_Type
(Otyp
);
3821 if Is_Concurrent_Type
(Ityp
) then
3822 Ityp
:= Corresponding_Record_Type
(Ityp
);
3825 -- If the base types are the same, we know there is no problem since
3826 -- this conversion will be a noop.
3828 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
3831 -- Same if this is an upwards conversion of an untagged type, and there
3832 -- are no constraints involved (could be more general???)
3834 elsif Etype
(Ityp
) = Otyp
3835 and then not Is_Tagged_Type
(Ityp
)
3836 and then not Has_Discriminants
(Ityp
)
3837 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
3841 -- If the size of output type is known at compile time, there is
3842 -- never a problem. Note that unconstrained records are considered
3843 -- to be of known size, but we can't consider them that way here,
3844 -- because we are talking about the actual size of the object.
3846 -- We also make sure that in addition to the size being known, we do
3847 -- not have a case which might generate an embarrassingly large temp
3848 -- in stack checking mode.
3850 elsif Size_Known_At_Compile_Time
(Otyp
)
3852 (not Stack_Checking_Enabled
3853 or else not May_Generate_Large_Temp
(Otyp
))
3854 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
3858 -- If either type is tagged, then we know the alignment is OK so
3859 -- Gigi will be able to use pointer punning.
3861 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
3864 -- If either type is a limited record type, we cannot do a copy, so
3865 -- say safe since there's nothing else we can do.
3867 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
3870 -- Conversions to and from packed array types are always ignored and
3873 elsif Is_Packed_Array_Type
(Otyp
)
3874 or else Is_Packed_Array_Type
(Ityp
)
3879 -- The only other cases known to be safe is if the input type's
3880 -- alignment is known to be at least the maximum alignment for the
3881 -- target or if both alignments are known and the output type's
3882 -- alignment is no stricter than the input's. We can use the alignment
3883 -- of the component type of an array if a type is an unpacked
3886 if Present
(Alignment_Clause
(Otyp
)) then
3887 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
3889 elsif Is_Array_Type
(Otyp
)
3890 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
3892 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
3893 (Component_Type
(Otyp
))));
3896 if Present
(Alignment_Clause
(Ityp
)) then
3897 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
3899 elsif Is_Array_Type
(Ityp
)
3900 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
3902 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
3903 (Component_Type
(Ityp
))));
3906 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
3909 elsif Ialign
/= No_Uint
and then Oalign
/= No_Uint
3910 and then Ialign
<= Oalign
3914 -- Otherwise, Gigi cannot handle this and we must make a temporary
3920 end Safe_Unchecked_Type_Conversion
;
3922 --------------------------
3923 -- Set_Elaboration_Flag --
3924 --------------------------
3926 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
3927 Loc
: constant Source_Ptr
:= Sloc
(N
);
3928 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
3932 if Present
(Ent
) then
3934 -- Nothing to do if at the compilation unit level, because in this
3935 -- case the flag is set by the binder generated elaboration routine.
3937 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3940 -- Here we do need to generate an assignment statement
3943 Check_Restriction
(No_Elaboration_Code
, N
);
3945 Make_Assignment_Statement
(Loc
,
3946 Name
=> New_Occurrence_Of
(Ent
, Loc
),
3947 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
));
3949 if Nkind
(Parent
(N
)) = N_Subunit
then
3950 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
3952 Insert_After
(N
, Asn
);
3957 -- Kill current value indication. This is necessary because
3958 -- the tests of this flag are inserted out of sequence and must
3959 -- not pick up bogus indications of the wrong constant value.
3961 Set_Current_Value
(Ent
, Empty
);
3964 end Set_Elaboration_Flag
;
3966 --------------------------
3967 -- Target_Has_Fixed_Ops --
3968 --------------------------
3970 Integer_Sized_Small
: Ureal
;
3971 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this
3972 -- function is called (we don't want to compute it more than once!)
3974 Long_Integer_Sized_Small
: Ureal
;
3975 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this
3976 -- functoin is called (we don't want to compute it more than once)
3978 First_Time_For_THFO
: Boolean := True;
3979 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
3981 function Target_Has_Fixed_Ops
3982 (Left_Typ
: Entity_Id
;
3983 Right_Typ
: Entity_Id
;
3984 Result_Typ
: Entity_Id
) return Boolean
3986 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
3987 -- Return True if the given type is a fixed-point type with a small
3988 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
3989 -- an absolute value less than 1.0. This is currently limited
3990 -- to fixed-point types that map to Integer or Long_Integer.
3992 ------------------------
3993 -- Is_Fractional_Type --
3994 ------------------------
3996 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
3998 if Esize
(Typ
) = Standard_Integer_Size
then
3999 return Small_Value
(Typ
) = Integer_Sized_Small
;
4001 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
4002 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
4007 end Is_Fractional_Type
;
4009 -- Start of processing for Target_Has_Fixed_Ops
4012 -- Return False if Fractional_Fixed_Ops_On_Target is false
4014 if not Fractional_Fixed_Ops_On_Target
then
4018 -- Here the target has Fractional_Fixed_Ops, if first time, compute
4019 -- standard constants used by Is_Fractional_Type.
4021 if First_Time_For_THFO
then
4022 First_Time_For_THFO
:= False;
4024 Integer_Sized_Small
:=
4027 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
4030 Long_Integer_Sized_Small
:=
4033 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
4037 -- Return True if target supports fixed-by-fixed multiply/divide
4038 -- for fractional fixed-point types (see Is_Fractional_Type) and
4039 -- the operand and result types are equivalent fractional types.
4041 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
4042 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
4043 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
4044 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
4045 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
4046 end Target_Has_Fixed_Ops
;
4048 ------------------------------------------
4049 -- Type_May_Have_Bit_Aligned_Components --
4050 ------------------------------------------
4052 function Type_May_Have_Bit_Aligned_Components
4053 (Typ
: Entity_Id
) return Boolean
4056 -- Array type, check component type
4058 if Is_Array_Type
(Typ
) then
4060 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
4062 -- Record type, check components
4064 elsif Is_Record_Type
(Typ
) then
4069 E
:= First_Entity
(Typ
);
4070 while Present
(E
) loop
4071 if Ekind
(E
) = E_Component
4072 or else Ekind
(E
) = E_Discriminant
4074 if Component_May_Be_Bit_Aligned
(E
)
4076 Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
4088 -- Type other than array or record is always OK
4093 end Type_May_Have_Bit_Aligned_Components
;
4095 ----------------------------
4096 -- Wrap_Cleanup_Procedure --
4097 ----------------------------
4099 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
4100 Loc
: constant Source_Ptr
:= Sloc
(N
);
4101 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4102 Stmts
: constant List_Id
:= Statements
(Stseq
);
4105 if Abort_Allowed
then
4106 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
4107 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4109 end Wrap_Cleanup_Procedure
;