1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Exp_Aggr
; use Exp_Aggr
;
35 with Exp_Ch6
; use Exp_Ch6
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Inline
; use Inline
;
38 with Itypes
; use Itypes
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Res
; use Sem_Res
;
50 with Sem_Type
; use Sem_Type
;
51 with Sem_Util
; use Sem_Util
;
52 with Snames
; use Snames
;
53 with Stand
; use Stand
;
54 with Stringt
; use Stringt
;
55 with Targparm
; use Targparm
;
56 with Tbuild
; use Tbuild
;
57 with Ttypes
; use Ttypes
;
58 with 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 array
73 -- component, concatenating the images of each index. To avoid storage
74 -- leaks, the string is built with successive slice assignments. The flag
75 -- Dyn indicates whether this is called for the initialization procedure of
76 -- an array of tasks, or for the name of a dynamically created task that is
77 -- 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. Build
85 -- function body that computes image.
87 procedure Build_Task_Image_Prefix
96 -- Common processing for Task_Array_Image and Task_Record_Image. Create
97 -- 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 record
104 -- component. Concatenate name of variable with that of selector. The flag
105 -- Dyn indicates whether this is called for the initialization procedure of
106 -- record with task components, or for a dynamically created task that is
107 -- 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)". This function
114 -- returns the entity of the Equivalent type and inserts on the fly the
115 -- 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 to
123 -- 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 -- If the index type of the target array is not integer, we generate:
134 -- Low_Bound (Literal_Type) ..
136 -- (Literal_Type'Pos (Low_Bound (Literal_Type))
137 -- + (Length (Literal_Typ) -1))
139 function Make_Non_Empty_Check
141 N
: Node_Id
) return Node_Id
;
142 -- Produce a boolean expression checking that the unidimensional array
143 -- node N is not empty.
145 function New_Class_Wide_Subtype
147 N
: Node_Id
) return Entity_Id
;
148 -- Create an implicit subtype of CW_Typ attached to node N
150 function Requires_Cleanup_Actions
153 Nested_Constructs
: Boolean) return Boolean;
154 -- Given a list L, determine whether it contains one of the following:
156 -- 1) controlled objects
157 -- 2) library-level tagged types
159 -- Lib_Level is True when the list comes from a construct at the library
160 -- level, and False otherwise. Nested_Constructs is True when any nested
161 -- packages declared in L must be processed, and False otherwise.
163 -------------------------------------
164 -- Activate_Atomic_Synchronization --
165 -------------------------------------
167 procedure Activate_Atomic_Synchronization
(N
: Node_Id
) is
171 case Nkind
(Parent
(N
)) is
173 -- Check for cases of appearing in the prefix of a construct where
174 -- we don't need atomic synchronization for this kind of usage.
177 -- Nothing to do if we are the prefix of an attribute, since we
178 -- do not want an atomic sync operation for things like 'Size.
180 N_Attribute_Reference |
182 -- The N_Reference node is like an attribute
186 -- Nothing to do for a reference to a component (or components)
187 -- of a composite object. Only reads and updates of the object
188 -- as a whole require atomic synchronization (RM C.6 (15)).
190 N_Indexed_Component |
191 N_Selected_Component |
194 -- For all the above cases, nothing to do if we are the prefix
196 if Prefix
(Parent
(N
)) = N
then
203 -- Go ahead and set the flag
205 Set_Atomic_Sync_Required
(N
);
207 -- Generate info message if requested
209 if Warn_On_Atomic_Synchronization
then
214 when N_Selected_Component | N_Expanded_Name
=>
215 Msg_Node
:= Selector_Name
(N
);
217 when N_Explicit_Dereference | N_Indexed_Component
=>
221 pragma Assert
(False);
225 if Present
(Msg_Node
) then
227 ("?N?info: atomic synchronization set for &", Msg_Node
);
230 ("?N?info: atomic synchronization set", N
);
233 end Activate_Atomic_Synchronization
;
235 ----------------------
236 -- Adjust_Condition --
237 ----------------------
239 procedure Adjust_Condition
(N
: Node_Id
) is
246 Loc
: constant Source_Ptr
:= Sloc
(N
);
247 T
: constant Entity_Id
:= Etype
(N
);
251 -- Defend against a call where the argument has no type, or has a
252 -- type that is not Boolean. This can occur because of prior errors.
254 if No
(T
) or else not Is_Boolean_Type
(T
) then
258 -- Apply validity checking if needed
260 if Validity_Checks_On
and Validity_Check_Tests
then
264 -- Immediate return if standard boolean, the most common case,
265 -- where nothing needs to be done.
267 if Base_Type
(T
) = Standard_Boolean
then
271 -- Case of zero/non-zero semantics or non-standard enumeration
272 -- representation. In each case, we rewrite the node as:
274 -- ityp!(N) /= False'Enum_Rep
276 -- where ityp is an integer type with large enough size to hold any
279 if Nonzero_Is_True
(T
) or else Has_Non_Standard_Rep
(T
) then
280 if Esize
(T
) <= Esize
(Standard_Integer
) then
281 Ti
:= Standard_Integer
;
283 Ti
:= Standard_Long_Long_Integer
;
288 Left_Opnd
=> Unchecked_Convert_To
(Ti
, N
),
290 Make_Attribute_Reference
(Loc
,
291 Attribute_Name
=> Name_Enum_Rep
,
293 New_Occurrence_Of
(First_Literal
(T
), Loc
))));
294 Analyze_And_Resolve
(N
, Standard_Boolean
);
297 Rewrite
(N
, Convert_To
(Standard_Boolean
, N
));
298 Analyze_And_Resolve
(N
, Standard_Boolean
);
301 end Adjust_Condition
;
303 ------------------------
304 -- Adjust_Result_Type --
305 ------------------------
307 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
) is
309 -- Ignore call if current type is not Standard.Boolean
311 if Etype
(N
) /= Standard_Boolean
then
315 -- If result is already of correct type, nothing to do. Note that
316 -- this will get the most common case where everything has a type
317 -- of Standard.Boolean.
319 if Base_Type
(T
) = Standard_Boolean
then
324 KP
: constant Node_Kind
:= Nkind
(Parent
(N
));
327 -- If result is to be used as a Condition in the syntax, no need
328 -- to convert it back, since if it was changed to Standard.Boolean
329 -- using Adjust_Condition, that is just fine for this usage.
331 if KP
in N_Raise_xxx_Error
or else KP
in N_Has_Condition
then
334 -- If result is an operand of another logical operation, no need
335 -- to reset its type, since Standard.Boolean is just fine, and
336 -- such operations always do Adjust_Condition on their operands.
338 elsif KP
in N_Op_Boolean
339 or else KP
in N_Short_Circuit
340 or else KP
= N_Op_Not
344 -- Otherwise we perform a conversion from the current type, which
345 -- must be Standard.Boolean, to the desired type.
349 Rewrite
(N
, Convert_To
(T
, N
));
350 Analyze_And_Resolve
(N
, T
);
354 end Adjust_Result_Type
;
356 --------------------------
357 -- Append_Freeze_Action --
358 --------------------------
360 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
) is
364 Ensure_Freeze_Node
(T
);
365 Fnode
:= Freeze_Node
(T
);
367 if No
(Actions
(Fnode
)) then
368 Set_Actions
(Fnode
, New_List
(N
));
370 Append
(N
, Actions
(Fnode
));
373 end Append_Freeze_Action
;
375 ---------------------------
376 -- Append_Freeze_Actions --
377 ---------------------------
379 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
) is
387 Ensure_Freeze_Node
(T
);
388 Fnode
:= Freeze_Node
(T
);
390 if No
(Actions
(Fnode
)) then
391 Set_Actions
(Fnode
, L
);
393 Append_List
(L
, Actions
(Fnode
));
395 end Append_Freeze_Actions
;
397 ------------------------------------
398 -- Build_Allocate_Deallocate_Proc --
399 ------------------------------------
401 procedure Build_Allocate_Deallocate_Proc
403 Is_Allocate
: Boolean)
405 Desig_Typ
: Entity_Id
;
408 Proc_To_Call
: Node_Id
:= Empty
;
411 function Find_Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
;
412 -- Locate TSS primitive Finalize_Address in type Typ
414 function Find_Object
(E
: Node_Id
) return Node_Id
;
415 -- Given an arbitrary expression of an allocator, try to find an object
416 -- reference in it, otherwise return the original expression.
418 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean;
419 -- Determine whether subprogram Subp denotes a custom allocate or
422 ---------------------------
423 -- Find_Finalize_Address --
424 ---------------------------
426 function Find_Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
is
427 Utyp
: Entity_Id
:= Typ
;
430 -- Handle protected class-wide or task class-wide types
432 if Is_Class_Wide_Type
(Utyp
) then
433 if Is_Concurrent_Type
(Root_Type
(Utyp
)) then
434 Utyp
:= Root_Type
(Utyp
);
436 elsif Is_Private_Type
(Root_Type
(Utyp
))
437 and then Present
(Full_View
(Root_Type
(Utyp
)))
438 and then Is_Concurrent_Type
(Full_View
(Root_Type
(Utyp
)))
440 Utyp
:= Full_View
(Root_Type
(Utyp
));
444 -- Handle private types
446 if Is_Private_Type
(Utyp
) and then Present
(Full_View
(Utyp
)) then
447 Utyp
:= Full_View
(Utyp
);
450 -- Handle protected and task types
452 if Is_Concurrent_Type
(Utyp
)
453 and then Present
(Corresponding_Record_Type
(Utyp
))
455 Utyp
:= Corresponding_Record_Type
(Utyp
);
458 Utyp
:= Underlying_Type
(Base_Type
(Utyp
));
460 -- Deal with non-tagged derivation of private views. If the parent is
461 -- now known to be protected, the finalization routine is the one
462 -- defined on the corresponding record of the ancestor (corresponding
463 -- records do not automatically inherit operations, but maybe they
466 if Is_Untagged_Derivation
(Typ
) then
467 if Is_Protected_Type
(Typ
) then
468 Utyp
:= Corresponding_Record_Type
(Root_Type
(Base_Type
(Typ
)));
470 Utyp
:= Underlying_Type
(Root_Type
(Base_Type
(Typ
)));
472 if Is_Protected_Type
(Utyp
) then
473 Utyp
:= Corresponding_Record_Type
(Utyp
);
478 -- If the underlying_type is a subtype, we are dealing with the
479 -- completion of a private type. We need to access the base type and
480 -- generate a conversion to it.
482 if Utyp
/= Base_Type
(Utyp
) then
483 pragma Assert
(Is_Private_Type
(Typ
));
485 Utyp
:= Base_Type
(Utyp
);
488 -- When dealing with an internally built full view for a type with
489 -- unknown discriminants, use the original record type.
491 if Is_Underlying_Record_View
(Utyp
) then
492 Utyp
:= Etype
(Utyp
);
495 return TSS
(Utyp
, TSS_Finalize_Address
);
496 end Find_Finalize_Address
;
502 function Find_Object
(E
: Node_Id
) return Node_Id
is
506 pragma Assert
(Is_Allocate
);
510 if Nkind_In
(Expr
, N_Qualified_Expression
,
511 N_Unchecked_Type_Conversion
)
513 Expr
:= Expression
(Expr
);
515 elsif Nkind
(Expr
) = N_Explicit_Dereference
then
516 Expr
:= Prefix
(Expr
);
526 ---------------------------------
527 -- Is_Allocate_Deallocate_Proc --
528 ---------------------------------
530 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean is
532 -- Look for a subprogram body with only one statement which is a
533 -- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
535 if Ekind
(Subp
) = E_Procedure
536 and then Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Body
539 HSS
: constant Node_Id
:=
540 Handled_Statement_Sequence
(Parent
(Parent
(Subp
)));
544 if Present
(Statements
(HSS
))
545 and then Nkind
(First
(Statements
(HSS
))) =
546 N_Procedure_Call_Statement
548 Proc
:= Entity
(Name
(First
(Statements
(HSS
))));
551 Is_RTE
(Proc
, RE_Allocate_Any_Controlled
)
552 or else Is_RTE
(Proc
, RE_Deallocate_Any_Controlled
);
558 end Is_Allocate_Deallocate_Proc
;
560 -- Start of processing for Build_Allocate_Deallocate_Proc
563 -- Obtain the attributes of the allocation / deallocation
565 if Nkind
(N
) = N_Free_Statement
then
566 Expr
:= Expression
(N
);
567 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
568 Proc_To_Call
:= Procedure_To_Call
(N
);
571 if Nkind
(N
) = N_Object_Declaration
then
572 Expr
:= Expression
(N
);
577 -- In certain cases an allocator with a qualified expression may
578 -- be relocated and used as the initialization expression of a
582 -- Obj : Ptr_Typ := new Desig_Typ'(...);
585 -- Tmp : Ptr_Typ := new Desig_Typ'(...);
586 -- Obj : Ptr_Typ := Tmp;
588 -- Since the allocator is always marked as analyzed to avoid infinite
589 -- expansion, it will never be processed by this routine given that
590 -- the designated type needs finalization actions. Detect this case
591 -- and complete the expansion of the allocator.
593 if Nkind
(Expr
) = N_Identifier
594 and then Nkind
(Parent
(Entity
(Expr
))) = N_Object_Declaration
595 and then Nkind
(Expression
(Parent
(Entity
(Expr
)))) = N_Allocator
597 Build_Allocate_Deallocate_Proc
(Parent
(Entity
(Expr
)), True);
601 -- The allocator may have been rewritten into something else in which
602 -- case the expansion performed by this routine does not apply.
604 if Nkind
(Expr
) /= N_Allocator
then
608 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
609 Proc_To_Call
:= Procedure_To_Call
(Expr
);
612 Pool_Id
:= Associated_Storage_Pool
(Ptr_Typ
);
613 Desig_Typ
:= Available_View
(Designated_Type
(Ptr_Typ
));
615 -- Handle concurrent types
617 if Is_Concurrent_Type
(Desig_Typ
)
618 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
620 Desig_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
623 -- Do not process allocations / deallocations without a pool
628 -- Do not process allocations on / deallocations from the secondary
631 elsif Is_RTE
(Pool_Id
, RE_SS_Pool
) then
634 -- Do not replicate the machinery if the allocator / free has already
635 -- been expanded and has a custom Allocate / Deallocate.
637 elsif Present
(Proc_To_Call
)
638 and then Is_Allocate_Deallocate_Proc
(Proc_To_Call
)
643 if Needs_Finalization
(Desig_Typ
) then
645 -- Certain run-time configurations and targets do not provide support
646 -- for controlled types.
648 if Restriction_Active
(No_Finalization
) then
651 -- Do nothing if the access type may never allocate / deallocate
654 elsif No_Pool_Assigned
(Ptr_Typ
) then
657 -- Access-to-controlled types are not supported on .NET/JVM since
658 -- these targets cannot support pools and address arithmetic.
660 elsif VM_Target
/= No_VM
then
664 -- The allocation / deallocation of a controlled object must be
665 -- chained on / detached from a finalization master.
667 pragma Assert
(Present
(Finalization_Master
(Ptr_Typ
)));
669 -- The only other kind of allocation / deallocation supported by this
670 -- routine is on / from a subpool.
672 elsif Nkind
(Expr
) = N_Allocator
673 and then No
(Subpool_Handle_Name
(Expr
))
679 Loc
: constant Source_Ptr
:= Sloc
(N
);
680 Addr_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
681 Alig_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
682 Proc_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
683 Size_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
686 Fin_Addr_Id
: Entity_Id
;
687 Fin_Mas_Act
: Node_Id
;
688 Fin_Mas_Id
: Entity_Id
;
689 Proc_To_Call
: Entity_Id
;
690 Subpool
: Node_Id
:= Empty
;
693 -- Step 1: Construct all the actuals for the call to library routine
694 -- Allocate_Any_Controlled / Deallocate_Any_Controlled.
698 Actuals
:= New_List
(New_Reference_To
(Pool_Id
, Loc
));
704 if Nkind
(Expr
) = N_Allocator
then
705 Subpool
:= Subpool_Handle_Name
(Expr
);
708 -- If a subpool is present it can be an arbitrary name, so make
709 -- the actual by copying the tree.
711 if Present
(Subpool
) then
712 Append_To
(Actuals
, New_Copy_Tree
(Subpool
, New_Sloc
=> Loc
));
714 Append_To
(Actuals
, Make_Null
(Loc
));
717 -- c) Finalization master
719 if Needs_Finalization
(Desig_Typ
) then
720 Fin_Mas_Id
:= Finalization_Master
(Ptr_Typ
);
721 Fin_Mas_Act
:= New_Reference_To
(Fin_Mas_Id
, Loc
);
723 -- Handle the case where the master is actually a pointer to a
724 -- master. This case arises in build-in-place functions.
726 if Is_Access_Type
(Etype
(Fin_Mas_Id
)) then
727 Append_To
(Actuals
, Fin_Mas_Act
);
730 Make_Attribute_Reference
(Loc
,
731 Prefix
=> Fin_Mas_Act
,
732 Attribute_Name
=> Name_Unrestricted_Access
));
735 Append_To
(Actuals
, Make_Null
(Loc
));
738 -- d) Finalize_Address
740 -- Primitive Finalize_Address is never generated in CodePeer mode
741 -- since it contains an Unchecked_Conversion.
743 if Needs_Finalization
(Desig_Typ
) and then not CodePeer_Mode
then
744 Fin_Addr_Id
:= Find_Finalize_Address
(Desig_Typ
);
745 pragma Assert
(Present
(Fin_Addr_Id
));
748 Make_Attribute_Reference
(Loc
,
749 Prefix
=> New_Reference_To
(Fin_Addr_Id
, Loc
),
750 Attribute_Name
=> Name_Unrestricted_Access
));
752 Append_To
(Actuals
, Make_Null
(Loc
));
760 Append_To
(Actuals
, New_Reference_To
(Addr_Id
, Loc
));
761 Append_To
(Actuals
, New_Reference_To
(Size_Id
, Loc
));
763 if Is_Allocate
or else not Is_Class_Wide_Type
(Desig_Typ
) then
764 Append_To
(Actuals
, New_Reference_To
(Alig_Id
, Loc
));
766 -- For deallocation of class wide types we obtain the value of
767 -- alignment from the Type Specific Record of the deallocated object.
768 -- This is needed because the frontend expansion of class-wide types
769 -- into equivalent types confuses the backend.
775 -- ... because 'Alignment applied to class-wide types is expanded
776 -- into the code that reads the value of alignment from the TSD
777 -- (see Expand_N_Attribute_Reference)
780 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
781 Make_Attribute_Reference
(Loc
,
783 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Expr
)),
784 Attribute_Name
=> Name_Alignment
)));
789 -- Generate a run-time check to determine whether a class-wide object
790 -- is truly controlled.
792 if Needs_Finalization
(Desig_Typ
) then
793 if Is_Class_Wide_Type
(Desig_Typ
)
794 or else Is_Generic_Actual_Type
(Desig_Typ
)
797 Flag_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F');
804 Temp
:= Find_Object
(Expression
(Expr
));
809 -- Processing for generic actuals
811 if Is_Generic_Actual_Type
(Desig_Typ
) then
813 New_Reference_To
(Boolean_Literals
814 (Needs_Finalization
(Base_Type
(Desig_Typ
))), Loc
);
816 -- Processing for subtype indications
818 elsif Nkind
(Temp
) in N_Has_Entity
819 and then Is_Type
(Entity
(Temp
))
822 New_Reference_To
(Boolean_Literals
823 (Needs_Finalization
(Entity
(Temp
))), Loc
);
825 -- Generate a runtime check to test the controlled state of
826 -- an object for the purposes of allocation / deallocation.
829 -- The following case arises when allocating through an
830 -- interface class-wide type, generate:
834 if Is_RTE
(Etype
(Temp
), RE_Tag_Ptr
) then
836 Make_Explicit_Dereference
(Loc
,
838 Relocate_Node
(Temp
));
845 Make_Attribute_Reference
(Loc
,
847 Relocate_Node
(Temp
),
848 Attribute_Name
=> Name_Tag
);
852 -- Needs_Finalization (<Param>)
855 Make_Function_Call
(Loc
,
857 New_Reference_To
(RTE
(RE_Needs_Finalization
), Loc
),
858 Parameter_Associations
=> New_List
(Param
));
861 -- Create the temporary which represents the finalization
862 -- state of the expression. Generate:
864 -- F : constant Boolean := <Flag_Expr>;
867 Make_Object_Declaration
(Loc
,
868 Defining_Identifier
=> Flag_Id
,
869 Constant_Present
=> True,
871 New_Reference_To
(Standard_Boolean
, Loc
),
872 Expression
=> Flag_Expr
));
874 -- The flag acts as the last actual
876 Append_To
(Actuals
, New_Reference_To
(Flag_Id
, Loc
));
879 -- The object is statically known to be controlled
882 Append_To
(Actuals
, New_Reference_To
(Standard_True
, Loc
));
886 Append_To
(Actuals
, New_Reference_To
(Standard_False
, Loc
));
893 New_Reference_To
(Boolean_Literals
(Present
(Subpool
)), Loc
));
896 -- Step 2: Build a wrapper Allocate / Deallocate which internally
897 -- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
899 -- Select the proper routine to call
902 Proc_To_Call
:= RTE
(RE_Allocate_Any_Controlled
);
904 Proc_To_Call
:= RTE
(RE_Deallocate_Any_Controlled
);
907 -- Create a custom Allocate / Deallocate routine which has identical
908 -- profile to that of System.Storage_Pools.
911 Make_Subprogram_Body
(Loc
,
916 Make_Procedure_Specification
(Loc
,
917 Defining_Unit_Name
=> Proc_Id
,
918 Parameter_Specifications
=> New_List
(
920 -- P : Root_Storage_Pool
922 Make_Parameter_Specification
(Loc
,
923 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
925 New_Reference_To
(RTE
(RE_Root_Storage_Pool
), Loc
)),
929 Make_Parameter_Specification
(Loc
,
930 Defining_Identifier
=> Addr_Id
,
931 Out_Present
=> Is_Allocate
,
933 New_Reference_To
(RTE
(RE_Address
), Loc
)),
937 Make_Parameter_Specification
(Loc
,
938 Defining_Identifier
=> Size_Id
,
940 New_Reference_To
(RTE
(RE_Storage_Count
), Loc
)),
944 Make_Parameter_Specification
(Loc
,
945 Defining_Identifier
=> Alig_Id
,
947 New_Reference_To
(RTE
(RE_Storage_Count
), Loc
)))),
949 Declarations
=> No_List
,
951 Handled_Statement_Sequence
=>
952 Make_Handled_Sequence_Of_Statements
(Loc
,
953 Statements
=> New_List
(
954 Make_Procedure_Call_Statement
(Loc
,
955 Name
=> New_Reference_To
(Proc_To_Call
, Loc
),
956 Parameter_Associations
=> Actuals
)))));
958 -- The newly generated Allocate / Deallocate becomes the default
959 -- procedure to call when the back end processes the allocation /
963 Set_Procedure_To_Call
(Expr
, Proc_Id
);
965 Set_Procedure_To_Call
(N
, Proc_Id
);
968 end Build_Allocate_Deallocate_Proc
;
970 ------------------------
971 -- Build_Runtime_Call --
972 ------------------------
974 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
is
976 -- If entity is not available, we can skip making the call (this avoids
977 -- junk duplicated error messages in a number of cases).
979 if not RTE_Available
(RE
) then
980 return Make_Null_Statement
(Loc
);
983 Make_Procedure_Call_Statement
(Loc
,
984 Name
=> New_Reference_To
(RTE
(RE
), Loc
));
986 end Build_Runtime_Call
;
988 ----------------------------
989 -- Build_Task_Array_Image --
990 ----------------------------
992 -- This function generates the body for a function that constructs the
993 -- image string for a task that is an array component. The function is
994 -- local to the init proc for the array type, and is called for each one
995 -- of the components. The constructed image has the form of an indexed
996 -- component, whose prefix is the outer variable of the array type.
997 -- The n-dimensional array type has known indexes Index, Index2...
999 -- Id_Ref is an indexed component form created by the enclosing init proc.
1000 -- Its successive indexes are Val1, Val2, ... which are the loop variables
1001 -- in the loops that call the individual task init proc on each component.
1003 -- The generated function has the following structure:
1005 -- function F return String is
1006 -- Pref : string renames Task_Name;
1007 -- T1 : String := Index1'Image (Val1);
1009 -- Tn : String := indexn'image (Valn);
1010 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
1011 -- -- Len includes commas and the end parentheses.
1012 -- Res : String (1..Len);
1013 -- Pos : Integer := Pref'Length;
1016 -- Res (1 .. Pos) := Pref;
1018 -- Res (Pos) := '(';
1020 -- Res (Pos .. Pos + T1'Length - 1) := T1;
1021 -- Pos := Pos + T1'Length;
1022 -- Res (Pos) := '.';
1025 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
1026 -- Res (Len) := ')';
1031 -- Needless to say, multidimensional arrays of tasks are rare enough that
1032 -- the bulkiness of this code is not really a concern.
1034 function Build_Task_Array_Image
1038 Dyn
: Boolean := False) return Node_Id
1040 Dims
: constant Nat
:= Number_Dimensions
(A_Type
);
1041 -- Number of dimensions for array of tasks
1043 Temps
: array (1 .. Dims
) of Entity_Id
;
1044 -- Array of temporaries to hold string for each index
1050 -- Total length of generated name
1053 -- Running index for substring assignments
1055 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1056 -- Name of enclosing variable, prefix of resulting name
1059 -- String to hold result
1062 -- Value of successive indexes
1065 -- Expression to compute total size of string
1068 -- Entity for name at one index position
1070 Decls
: constant List_Id
:= New_List
;
1071 Stats
: constant List_Id
:= New_List
;
1074 -- For a dynamic task, the name comes from the target variable. For a
1075 -- static one it is a formal of the enclosing init proc.
1078 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1080 Make_Object_Declaration
(Loc
,
1081 Defining_Identifier
=> Pref
,
1082 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1084 Make_String_Literal
(Loc
,
1085 Strval
=> String_From_Name_Buffer
)));
1089 Make_Object_Renaming_Declaration
(Loc
,
1090 Defining_Identifier
=> Pref
,
1091 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1092 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1095 Indx
:= First_Index
(A_Type
);
1096 Val
:= First
(Expressions
(Id_Ref
));
1098 for J
in 1 .. Dims
loop
1099 T
:= Make_Temporary
(Loc
, 'T');
1103 Make_Object_Declaration
(Loc
,
1104 Defining_Identifier
=> T
,
1105 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1107 Make_Attribute_Reference
(Loc
,
1108 Attribute_Name
=> Name_Image
,
1109 Prefix
=> New_Occurrence_Of
(Etype
(Indx
), Loc
),
1110 Expressions
=> New_List
(New_Copy_Tree
(Val
)))));
1116 Sum
:= Make_Integer_Literal
(Loc
, Dims
+ 1);
1122 Make_Attribute_Reference
(Loc
,
1123 Attribute_Name
=> Name_Length
,
1124 Prefix
=> New_Occurrence_Of
(Pref
, Loc
),
1125 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1127 for J
in 1 .. Dims
loop
1132 Make_Attribute_Reference
(Loc
,
1133 Attribute_Name
=> Name_Length
,
1135 New_Occurrence_Of
(Temps
(J
), Loc
),
1136 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1139 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1141 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('(')));
1144 Make_Assignment_Statement
(Loc
,
1146 Make_Indexed_Component
(Loc
,
1147 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1148 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1150 Make_Character_Literal
(Loc
,
1152 Char_Literal_Value
=> UI_From_Int
(Character'Pos ('(')))));
1155 Make_Assignment_Statement
(Loc
,
1156 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1159 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1160 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1162 for J
in 1 .. Dims
loop
1165 Make_Assignment_Statement
(Loc
,
1168 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1171 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1173 Make_Op_Subtract
(Loc
,
1176 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1178 Make_Attribute_Reference
(Loc
,
1179 Attribute_Name
=> Name_Length
,
1181 New_Occurrence_Of
(Temps
(J
), Loc
),
1183 New_List
(Make_Integer_Literal
(Loc
, 1)))),
1184 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))),
1186 Expression
=> New_Occurrence_Of
(Temps
(J
), Loc
)));
1190 Make_Assignment_Statement
(Loc
,
1191 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1194 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1196 Make_Attribute_Reference
(Loc
,
1197 Attribute_Name
=> Name_Length
,
1198 Prefix
=> New_Occurrence_Of
(Temps
(J
), Loc
),
1200 New_List
(Make_Integer_Literal
(Loc
, 1))))));
1202 Set_Character_Literal_Name
(Char_Code
(Character'Pos (',')));
1205 Make_Assignment_Statement
(Loc
,
1206 Name
=> Make_Indexed_Component
(Loc
,
1207 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1208 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1210 Make_Character_Literal
(Loc
,
1212 Char_Literal_Value
=> UI_From_Int
(Character'Pos (',')))));
1215 Make_Assignment_Statement
(Loc
,
1216 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1219 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1220 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1224 Set_Character_Literal_Name
(Char_Code
(Character'Pos (')')));
1227 Make_Assignment_Statement
(Loc
,
1229 Make_Indexed_Component
(Loc
,
1230 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1231 Expressions
=> New_List
(New_Occurrence_Of
(Len
, Loc
))),
1233 Make_Character_Literal
(Loc
,
1235 Char_Literal_Value
=> UI_From_Int
(Character'Pos (')')))));
1236 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1237 end Build_Task_Array_Image
;
1239 ----------------------------
1240 -- Build_Task_Image_Decls --
1241 ----------------------------
1243 function Build_Task_Image_Decls
1247 In_Init_Proc
: Boolean := False) return List_Id
1249 Decls
: constant List_Id
:= New_List
;
1250 T_Id
: Entity_Id
:= Empty
;
1252 Expr
: Node_Id
:= Empty
;
1253 Fun
: Node_Id
:= Empty
;
1254 Is_Dyn
: constant Boolean :=
1255 Nkind
(Parent
(Id_Ref
)) = N_Assignment_Statement
1257 Nkind
(Expression
(Parent
(Id_Ref
))) = N_Allocator
;
1260 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
1261 -- generate a dummy declaration only.
1263 if Restriction_Active
(No_Implicit_Heap_Allocations
)
1264 or else Global_Discard_Names
1266 T_Id
:= Make_Temporary
(Loc
, 'J');
1271 Make_Object_Declaration
(Loc
,
1272 Defining_Identifier
=> T_Id
,
1273 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1275 Make_String_Literal
(Loc
,
1276 Strval
=> String_From_Name_Buffer
)));
1279 if Nkind
(Id_Ref
) = N_Identifier
1280 or else Nkind
(Id_Ref
) = N_Defining_Identifier
1282 -- For a simple variable, the image of the task is built from
1283 -- the name of the variable. To avoid possible conflict with the
1284 -- anonymous type created for a single protected object, add a
1288 Make_Defining_Identifier
(Loc
,
1289 New_External_Name
(Chars
(Id_Ref
), 'T', 1));
1291 Get_Name_String
(Chars
(Id_Ref
));
1294 Make_String_Literal
(Loc
,
1295 Strval
=> String_From_Name_Buffer
);
1297 elsif Nkind
(Id_Ref
) = N_Selected_Component
then
1299 Make_Defining_Identifier
(Loc
,
1300 New_External_Name
(Chars
(Selector_Name
(Id_Ref
)), 'T'));
1301 Fun
:= Build_Task_Record_Image
(Loc
, Id_Ref
, Is_Dyn
);
1303 elsif Nkind
(Id_Ref
) = N_Indexed_Component
then
1305 Make_Defining_Identifier
(Loc
,
1306 New_External_Name
(Chars
(A_Type
), 'N'));
1308 Fun
:= Build_Task_Array_Image
(Loc
, Id_Ref
, A_Type
, Is_Dyn
);
1312 if Present
(Fun
) then
1313 Append
(Fun
, Decls
);
1314 Expr
:= Make_Function_Call
(Loc
,
1315 Name
=> New_Occurrence_Of
(Defining_Entity
(Fun
), Loc
));
1317 if not In_Init_Proc
and then VM_Target
= No_VM
then
1318 Set_Uses_Sec_Stack
(Defining_Entity
(Fun
));
1322 Decl
:= Make_Object_Declaration
(Loc
,
1323 Defining_Identifier
=> T_Id
,
1324 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1325 Constant_Present
=> True,
1326 Expression
=> Expr
);
1328 Append
(Decl
, Decls
);
1330 end Build_Task_Image_Decls
;
1332 -------------------------------
1333 -- Build_Task_Image_Function --
1334 -------------------------------
1336 function Build_Task_Image_Function
1340 Res
: Entity_Id
) return Node_Id
1346 Make_Simple_Return_Statement
(Loc
,
1347 Expression
=> New_Occurrence_Of
(Res
, Loc
)));
1349 Spec
:= Make_Function_Specification
(Loc
,
1350 Defining_Unit_Name
=> Make_Temporary
(Loc
, 'F'),
1351 Result_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
));
1353 -- Calls to 'Image use the secondary stack, which must be cleaned up
1354 -- after the task name is built.
1356 return Make_Subprogram_Body
(Loc
,
1357 Specification
=> Spec
,
1358 Declarations
=> Decls
,
1359 Handled_Statement_Sequence
=>
1360 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
));
1361 end Build_Task_Image_Function
;
1363 -----------------------------
1364 -- Build_Task_Image_Prefix --
1365 -----------------------------
1367 procedure Build_Task_Image_Prefix
1369 Len
: out Entity_Id
;
1370 Res
: out Entity_Id
;
1371 Pos
: out Entity_Id
;
1378 Len
:= Make_Temporary
(Loc
, 'L', Sum
);
1381 Make_Object_Declaration
(Loc
,
1382 Defining_Identifier
=> Len
,
1383 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1384 Expression
=> Sum
));
1386 Res
:= Make_Temporary
(Loc
, 'R');
1389 Make_Object_Declaration
(Loc
,
1390 Defining_Identifier
=> Res
,
1391 Object_Definition
=>
1392 Make_Subtype_Indication
(Loc
,
1393 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1395 Make_Index_Or_Discriminant_Constraint
(Loc
,
1399 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1400 High_Bound
=> New_Occurrence_Of
(Len
, Loc
)))))));
1402 Pos
:= Make_Temporary
(Loc
, 'P');
1405 Make_Object_Declaration
(Loc
,
1406 Defining_Identifier
=> Pos
,
1407 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
1409 -- Pos := Prefix'Length;
1412 Make_Assignment_Statement
(Loc
,
1413 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1415 Make_Attribute_Reference
(Loc
,
1416 Attribute_Name
=> Name_Length
,
1417 Prefix
=> New_Occurrence_Of
(Prefix
, Loc
),
1418 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1)))));
1420 -- Res (1 .. Pos) := Prefix;
1423 Make_Assignment_Statement
(Loc
,
1426 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1429 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1430 High_Bound
=> New_Occurrence_Of
(Pos
, Loc
))),
1432 Expression
=> New_Occurrence_Of
(Prefix
, Loc
)));
1435 Make_Assignment_Statement
(Loc
,
1436 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1439 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1440 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1441 end Build_Task_Image_Prefix
;
1443 -----------------------------
1444 -- Build_Task_Record_Image --
1445 -----------------------------
1447 function Build_Task_Record_Image
1450 Dyn
: Boolean := False) return Node_Id
1453 -- Total length of generated name
1456 -- Index into result
1459 -- String to hold result
1461 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1462 -- Name of enclosing variable, prefix of resulting name
1465 -- Expression to compute total size of string
1468 -- Entity for selector name
1470 Decls
: constant List_Id
:= New_List
;
1471 Stats
: constant List_Id
:= New_List
;
1474 -- For a dynamic task, the name comes from the target variable. For a
1475 -- static one it is a formal of the enclosing init proc.
1478 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1480 Make_Object_Declaration
(Loc
,
1481 Defining_Identifier
=> Pref
,
1482 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1484 Make_String_Literal
(Loc
,
1485 Strval
=> String_From_Name_Buffer
)));
1489 Make_Object_Renaming_Declaration
(Loc
,
1490 Defining_Identifier
=> Pref
,
1491 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1492 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1495 Sel
:= Make_Temporary
(Loc
, 'S');
1497 Get_Name_String
(Chars
(Selector_Name
(Id_Ref
)));
1500 Make_Object_Declaration
(Loc
,
1501 Defining_Identifier
=> Sel
,
1502 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1504 Make_String_Literal
(Loc
,
1505 Strval
=> String_From_Name_Buffer
)));
1507 Sum
:= Make_Integer_Literal
(Loc
, Nat
(Name_Len
+ 1));
1513 Make_Attribute_Reference
(Loc
,
1514 Attribute_Name
=> Name_Length
,
1516 New_Occurrence_Of
(Pref
, Loc
),
1517 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1519 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1521 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('.')));
1523 -- Res (Pos) := '.';
1526 Make_Assignment_Statement
(Loc
,
1527 Name
=> Make_Indexed_Component
(Loc
,
1528 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1529 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1531 Make_Character_Literal
(Loc
,
1533 Char_Literal_Value
=>
1534 UI_From_Int
(Character'Pos ('.')))));
1537 Make_Assignment_Statement
(Loc
,
1538 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1541 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1542 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1544 -- Res (Pos .. Len) := Selector;
1547 Make_Assignment_Statement
(Loc
,
1548 Name
=> Make_Slice
(Loc
,
1549 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1552 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1553 High_Bound
=> New_Occurrence_Of
(Len
, Loc
))),
1554 Expression
=> New_Occurrence_Of
(Sel
, Loc
)));
1556 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1557 end Build_Task_Record_Image
;
1559 ----------------------------------
1560 -- Component_May_Be_Bit_Aligned --
1561 ----------------------------------
1563 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean is
1567 -- If no component clause, then everything is fine, since the back end
1568 -- never bit-misaligns by default, even if there is a pragma Packed for
1571 if No
(Comp
) or else No
(Component_Clause
(Comp
)) then
1575 UT
:= Underlying_Type
(Etype
(Comp
));
1577 -- It is only array and record types that cause trouble
1579 if not Is_Record_Type
(UT
) and then not Is_Array_Type
(UT
) then
1582 -- If we know that we have a small (64 bits or less) record or small
1583 -- bit-packed array, then everything is fine, since the back end can
1584 -- handle these cases correctly.
1586 elsif Esize
(Comp
) <= 64
1587 and then (Is_Record_Type
(UT
) or else Is_Bit_Packed_Array
(UT
))
1591 -- Otherwise if the component is not byte aligned, we know we have the
1592 -- nasty unaligned case.
1594 elsif Normalized_First_Bit
(Comp
) /= Uint_0
1595 or else Esize
(Comp
) mod System_Storage_Unit
/= Uint_0
1599 -- If we are large and byte aligned, then OK at this level
1604 end Component_May_Be_Bit_Aligned
;
1606 -----------------------------------
1607 -- Corresponding_Runtime_Package --
1608 -----------------------------------
1610 function Corresponding_Runtime_Package
(Typ
: Entity_Id
) return RTU_Id
is
1611 Pkg_Id
: RTU_Id
:= RTU_Null
;
1614 pragma Assert
(Is_Concurrent_Type
(Typ
));
1616 if Ekind
(Typ
) in Protected_Kind
then
1617 if Has_Entries
(Typ
)
1619 -- A protected type without entries that covers an interface and
1620 -- overrides the abstract routines with protected procedures is
1621 -- considered equivalent to a protected type with entries in the
1622 -- context of dispatching select statements. It is sufficient to
1623 -- check for the presence of an interface list in the declaration
1624 -- node to recognize this case.
1626 or else Present
(Interface_List
(Parent
(Typ
)))
1628 -- Protected types with interrupt handlers (when not using a
1629 -- restricted profile) are also considered equivalent to
1630 -- protected types with entries. The types which are used
1631 -- (Static_Interrupt_Protection and Dynamic_Interrupt_Protection)
1632 -- are derived from Protection_Entries.
1634 or else (Has_Attach_Handler
(Typ
) and then not Restricted_Profile
)
1635 or else Has_Interrupt_Handler
(Typ
)
1638 or else Restriction_Active
(No_Entry_Queue
) = False
1639 or else Number_Entries
(Typ
) > 1
1640 or else (Has_Attach_Handler
(Typ
)
1641 and then not Restricted_Profile
)
1643 Pkg_Id
:= System_Tasking_Protected_Objects_Entries
;
1645 Pkg_Id
:= System_Tasking_Protected_Objects_Single_Entry
;
1649 Pkg_Id
:= System_Tasking_Protected_Objects
;
1654 end Corresponding_Runtime_Package
;
1656 -------------------------------
1657 -- Convert_To_Actual_Subtype --
1658 -------------------------------
1660 procedure Convert_To_Actual_Subtype
(Exp
: Entity_Id
) is
1664 Act_ST
:= Get_Actual_Subtype
(Exp
);
1666 if Act_ST
= Etype
(Exp
) then
1669 Rewrite
(Exp
, Convert_To
(Act_ST
, Relocate_Node
(Exp
)));
1670 Analyze_And_Resolve
(Exp
, Act_ST
);
1672 end Convert_To_Actual_Subtype
;
1674 -----------------------------------
1675 -- Current_Sem_Unit_Declarations --
1676 -----------------------------------
1678 function Current_Sem_Unit_Declarations
return List_Id
is
1679 U
: Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
1683 -- If the current unit is a package body, locate the visible
1684 -- declarations of the package spec.
1686 if Nkind
(U
) = N_Package_Body
then
1687 U
:= Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
1690 if Nkind
(U
) = N_Package_Declaration
then
1691 U
:= Specification
(U
);
1692 Decls
:= Visible_Declarations
(U
);
1696 Set_Visible_Declarations
(U
, Decls
);
1700 Decls
:= Declarations
(U
);
1704 Set_Declarations
(U
, Decls
);
1709 end Current_Sem_Unit_Declarations
;
1711 -----------------------
1712 -- Duplicate_Subexpr --
1713 -----------------------
1715 function Duplicate_Subexpr
1717 Name_Req
: Boolean := False) return Node_Id
1720 Remove_Side_Effects
(Exp
, Name_Req
);
1721 return New_Copy_Tree
(Exp
);
1722 end Duplicate_Subexpr
;
1724 ---------------------------------
1725 -- Duplicate_Subexpr_No_Checks --
1726 ---------------------------------
1728 function Duplicate_Subexpr_No_Checks
1730 Name_Req
: Boolean := False) return Node_Id
1734 Remove_Side_Effects
(Exp
, Name_Req
);
1735 New_Exp
:= New_Copy_Tree
(Exp
);
1736 Remove_Checks
(New_Exp
);
1738 end Duplicate_Subexpr_No_Checks
;
1740 -----------------------------------
1741 -- Duplicate_Subexpr_Move_Checks --
1742 -----------------------------------
1744 function Duplicate_Subexpr_Move_Checks
1746 Name_Req
: Boolean := False) return Node_Id
1750 Remove_Side_Effects
(Exp
, Name_Req
);
1751 New_Exp
:= New_Copy_Tree
(Exp
);
1752 Remove_Checks
(Exp
);
1754 end Duplicate_Subexpr_Move_Checks
;
1756 --------------------
1757 -- Ensure_Defined --
1758 --------------------
1760 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
) is
1764 -- An itype reference must only be created if this is a local itype, so
1765 -- that gigi can elaborate it on the proper objstack.
1767 if Is_Itype
(Typ
) and then Scope
(Typ
) = Current_Scope
then
1768 IR
:= Make_Itype_Reference
(Sloc
(N
));
1769 Set_Itype
(IR
, Typ
);
1770 Insert_Action
(N
, IR
);
1774 --------------------
1775 -- Entry_Names_OK --
1776 --------------------
1778 function Entry_Names_OK
return Boolean is
1781 not Restricted_Profile
1782 and then not Global_Discard_Names
1783 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
1784 and then not Restriction_Active
(No_Local_Allocators
);
1791 procedure Evaluate_Name
(Nam
: Node_Id
) is
1792 K
: constant Node_Kind
:= Nkind
(Nam
);
1795 -- For an explicit dereference, we simply force the evaluation of the
1796 -- name expression. The dereference provides a value that is the address
1797 -- for the renamed object, and it is precisely this value that we want
1800 if K
= N_Explicit_Dereference
then
1801 Force_Evaluation
(Prefix
(Nam
));
1803 -- For a selected component, we simply evaluate the prefix
1805 elsif K
= N_Selected_Component
then
1806 Evaluate_Name
(Prefix
(Nam
));
1808 -- For an indexed component, or an attribute reference, we evaluate the
1809 -- prefix, which is itself a name, recursively, and then force the
1810 -- evaluation of all the subscripts (or attribute expressions).
1812 elsif Nkind_In
(K
, N_Indexed_Component
, N_Attribute_Reference
) then
1813 Evaluate_Name
(Prefix
(Nam
));
1819 E
:= First
(Expressions
(Nam
));
1820 while Present
(E
) loop
1821 Force_Evaluation
(E
);
1823 if Original_Node
(E
) /= E
then
1824 Set_Do_Range_Check
(E
, Do_Range_Check
(Original_Node
(E
)));
1831 -- For a slice, we evaluate the prefix, as for the indexed component
1832 -- case and then, if there is a range present, either directly or as the
1833 -- constraint of a discrete subtype indication, we evaluate the two
1834 -- bounds of this range.
1836 elsif K
= N_Slice
then
1837 Evaluate_Name
(Prefix
(Nam
));
1840 DR
: constant Node_Id
:= Discrete_Range
(Nam
);
1845 if Nkind
(DR
) = N_Range
then
1846 Force_Evaluation
(Low_Bound
(DR
));
1847 Force_Evaluation
(High_Bound
(DR
));
1849 elsif Nkind
(DR
) = N_Subtype_Indication
then
1850 Constr
:= Constraint
(DR
);
1852 if Nkind
(Constr
) = N_Range_Constraint
then
1853 Rexpr
:= Range_Expression
(Constr
);
1855 Force_Evaluation
(Low_Bound
(Rexpr
));
1856 Force_Evaluation
(High_Bound
(Rexpr
));
1861 -- For a type conversion, the expression of the conversion must be the
1862 -- name of an object, and we simply need to evaluate this name.
1864 elsif K
= N_Type_Conversion
then
1865 Evaluate_Name
(Expression
(Nam
));
1867 -- For a function call, we evaluate the call
1869 elsif K
= N_Function_Call
then
1870 Force_Evaluation
(Nam
);
1872 -- The remaining cases are direct name, operator symbol and character
1873 -- literal. In all these cases, we do nothing, since we want to
1874 -- reevaluate each time the renamed object is used.
1881 ---------------------
1882 -- Evolve_And_Then --
1883 ---------------------
1885 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1891 Make_And_Then
(Sloc
(Cond1
),
1893 Right_Opnd
=> Cond1
);
1895 end Evolve_And_Then
;
1897 --------------------
1898 -- Evolve_Or_Else --
1899 --------------------
1901 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1907 Make_Or_Else
(Sloc
(Cond1
),
1909 Right_Opnd
=> Cond1
);
1913 -----------------------------------------
1914 -- Expand_Static_Predicates_In_Choices --
1915 -----------------------------------------
1917 procedure Expand_Static_Predicates_In_Choices
(N
: Node_Id
) is
1918 pragma Assert
(Nkind_In
(N
, N_Case_Statement_Alternative
, N_Variant
));
1920 Choices
: constant List_Id
:= Discrete_Choices
(N
);
1928 Choice
:= First
(Choices
);
1929 while Present
(Choice
) loop
1930 Next_C
:= Next
(Choice
);
1932 -- Check for name of subtype with static predicate
1934 if Is_Entity_Name
(Choice
)
1935 and then Is_Type
(Entity
(Choice
))
1936 and then Has_Predicates
(Entity
(Choice
))
1938 -- Loop through entries in predicate list, converting to choices
1939 -- and inserting in the list before the current choice. Note that
1940 -- if the list is empty, corresponding to a False predicate, then
1941 -- no choices are inserted.
1943 P
:= First
(Static_Predicate
(Entity
(Choice
)));
1944 while Present
(P
) loop
1946 -- If low bound and high bounds are equal, copy simple choice
1948 if Expr_Value
(Low_Bound
(P
)) = Expr_Value
(High_Bound
(P
)) then
1949 C
:= New_Copy
(Low_Bound
(P
));
1951 -- Otherwise copy a range
1957 -- Change Sloc to referencing choice (rather than the Sloc of
1958 -- the predicate declaration element itself).
1960 Set_Sloc
(C
, Sloc
(Choice
));
1961 Insert_Before
(Choice
, C
);
1965 -- Delete the predicated entry
1970 -- Move to next choice to check
1974 end Expand_Static_Predicates_In_Choices
;
1976 ------------------------------
1977 -- Expand_Subtype_From_Expr --
1978 ------------------------------
1980 -- This function is applicable for both static and dynamic allocation of
1981 -- objects which are constrained by an initial expression. Basically it
1982 -- transforms an unconstrained subtype indication into a constrained one.
1984 -- The expression may also be transformed in certain cases in order to
1985 -- avoid multiple evaluation. In the static allocation case, the general
1990 -- is transformed into
1992 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1994 -- Here are the main cases :
1996 -- <if Expr is a Slice>
1997 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1999 -- <elsif Expr is a String Literal>
2000 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
2002 -- <elsif Expr is Constrained>
2003 -- subtype T is Type_Of_Expr
2006 -- <elsif Expr is an entity_name>
2007 -- Val : T (constraints taken from Expr) := Expr;
2010 -- type Axxx is access all T;
2011 -- Rval : Axxx := Expr'ref;
2012 -- Val : T (constraints taken from Rval) := Rval.all;
2014 -- ??? note: when the Expression is allocated in the secondary stack
2015 -- we could use it directly instead of copying it by declaring
2016 -- Val : T (...) renames Rval.all
2018 procedure Expand_Subtype_From_Expr
2020 Unc_Type
: Entity_Id
;
2021 Subtype_Indic
: Node_Id
;
2024 Loc
: constant Source_Ptr
:= Sloc
(N
);
2025 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
2029 -- In general we cannot build the subtype if expansion is disabled,
2030 -- because internal entities may not have been defined. However, to
2031 -- avoid some cascaded errors, we try to continue when the expression is
2032 -- an array (or string), because it is safe to compute the bounds. It is
2033 -- in fact required to do so even in a generic context, because there
2034 -- may be constants that depend on the bounds of a string literal, both
2035 -- standard string types and more generally arrays of characters.
2037 if not Expander_Active
2038 and then (No
(Etype
(Exp
)) or else not Is_String_Type
(Etype
(Exp
)))
2043 if Nkind
(Exp
) = N_Slice
then
2045 Slice_Type
: constant Entity_Id
:= Etype
(First_Index
(Exp_Typ
));
2048 Rewrite
(Subtype_Indic
,
2049 Make_Subtype_Indication
(Loc
,
2050 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
2052 Make_Index_Or_Discriminant_Constraint
(Loc
,
2053 Constraints
=> New_List
2054 (New_Reference_To
(Slice_Type
, Loc
)))));
2056 -- This subtype indication may be used later for constraint checks
2057 -- we better make sure that if a variable was used as a bound of
2058 -- of the original slice, its value is frozen.
2060 Force_Evaluation
(Low_Bound
(Scalar_Range
(Slice_Type
)));
2061 Force_Evaluation
(High_Bound
(Scalar_Range
(Slice_Type
)));
2064 elsif Ekind
(Exp_Typ
) = E_String_Literal_Subtype
then
2065 Rewrite
(Subtype_Indic
,
2066 Make_Subtype_Indication
(Loc
,
2067 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
2069 Make_Index_Or_Discriminant_Constraint
(Loc
,
2070 Constraints
=> New_List
(
2071 Make_Literal_Range
(Loc
,
2072 Literal_Typ
=> Exp_Typ
)))));
2074 -- If the type of the expression is an internally generated type it
2075 -- may not be necessary to create a new subtype. However there are two
2076 -- exceptions: references to the current instances, and aliased array
2077 -- object declarations for which the backend needs to create a template.
2079 elsif Is_Constrained
(Exp_Typ
)
2080 and then not Is_Class_Wide_Type
(Unc_Type
)
2082 (Nkind
(N
) /= N_Object_Declaration
2083 or else not Is_Entity_Name
(Expression
(N
))
2084 or else not Comes_From_Source
(Entity
(Expression
(N
)))
2085 or else not Is_Array_Type
(Exp_Typ
)
2086 or else not Aliased_Present
(N
))
2088 if Is_Itype
(Exp_Typ
) then
2090 -- Within an initialization procedure, a selected component
2091 -- denotes a component of the enclosing record, and it appears as
2092 -- an actual in a call to its own initialization procedure. If
2093 -- this component depends on the outer discriminant, we must
2094 -- generate the proper actual subtype for it.
2096 if Nkind
(Exp
) = N_Selected_Component
2097 and then Within_Init_Proc
2100 Decl
: constant Node_Id
:=
2101 Build_Actual_Subtype_Of_Component
(Exp_Typ
, Exp
);
2103 if Present
(Decl
) then
2104 Insert_Action
(N
, Decl
);
2105 T
:= Defining_Identifier
(Decl
);
2111 -- No need to generate a new subtype
2118 T
:= Make_Temporary
(Loc
, 'T');
2121 Make_Subtype_Declaration
(Loc
,
2122 Defining_Identifier
=> T
,
2123 Subtype_Indication
=> New_Reference_To
(Exp_Typ
, Loc
)));
2125 -- This type is marked as an itype even though it has an explicit
2126 -- declaration since otherwise Is_Generic_Actual_Type can get
2127 -- set, resulting in the generation of spurious errors. (See
2128 -- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
2131 Set_Associated_Node_For_Itype
(T
, Exp
);
2134 Rewrite
(Subtype_Indic
, New_Reference_To
(T
, Loc
));
2136 -- Nothing needs to be done for private types with unknown discriminants
2137 -- if the underlying type is not an unconstrained composite type or it
2138 -- is an unchecked union.
2140 elsif Is_Private_Type
(Unc_Type
)
2141 and then Has_Unknown_Discriminants
(Unc_Type
)
2142 and then (not Is_Composite_Type
(Underlying_Type
(Unc_Type
))
2143 or else Is_Constrained
(Underlying_Type
(Unc_Type
))
2144 or else Is_Unchecked_Union
(Underlying_Type
(Unc_Type
)))
2148 -- Case of derived type with unknown discriminants where the parent type
2149 -- also has unknown discriminants.
2151 elsif Is_Record_Type
(Unc_Type
)
2152 and then not Is_Class_Wide_Type
(Unc_Type
)
2153 and then Has_Unknown_Discriminants
(Unc_Type
)
2154 and then Has_Unknown_Discriminants
(Underlying_Type
(Unc_Type
))
2156 -- Nothing to be done if no underlying record view available
2158 if No
(Underlying_Record_View
(Unc_Type
)) then
2161 -- Otherwise use the Underlying_Record_View to create the proper
2162 -- constrained subtype for an object of a derived type with unknown
2166 Remove_Side_Effects
(Exp
);
2167 Rewrite
(Subtype_Indic
,
2168 Make_Subtype_From_Expr
(Exp
, Underlying_Record_View
(Unc_Type
)));
2171 -- Renamings of class-wide interface types require no equivalent
2172 -- constrained type declarations because we only need to reference
2173 -- the tag component associated with the interface. The same is
2174 -- presumably true for class-wide types in general, so this test
2175 -- is broadened to include all class-wide renamings, which also
2176 -- avoids cases of unbounded recursion in Remove_Side_Effects.
2177 -- (Is this really correct, or are there some cases of class-wide
2178 -- renamings that require action in this procedure???)
2181 and then Nkind
(N
) = N_Object_Renaming_Declaration
2182 and then Is_Class_Wide_Type
(Unc_Type
)
2186 -- In Ada 95 nothing to be done if the type of the expression is limited
2187 -- because in this case the expression cannot be copied, and its use can
2188 -- only be by reference.
2190 -- In Ada 2005 the context can be an object declaration whose expression
2191 -- is a function that returns in place. If the nominal subtype has
2192 -- unknown discriminants, the call still provides constraints on the
2193 -- object, and we have to create an actual subtype from it.
2195 -- If the type is class-wide, the expression is dynamically tagged and
2196 -- we do not create an actual subtype either. Ditto for an interface.
2197 -- For now this applies only if the type is immutably limited, and the
2198 -- function being called is build-in-place. This will have to be revised
2199 -- when build-in-place functions are generalized to other types.
2201 elsif Is_Limited_View
(Exp_Typ
)
2203 (Is_Class_Wide_Type
(Exp_Typ
)
2204 or else Is_Interface
(Exp_Typ
)
2205 or else not Has_Unknown_Discriminants
(Exp_Typ
)
2206 or else not Is_Composite_Type
(Unc_Type
))
2210 -- For limited objects initialized with build in place function calls,
2211 -- nothing to be done; otherwise we prematurely introduce an N_Reference
2212 -- node in the expression initializing the object, which breaks the
2213 -- circuitry that detects and adds the additional arguments to the
2216 elsif Is_Build_In_Place_Function_Call
(Exp
) then
2220 Remove_Side_Effects
(Exp
);
2221 Rewrite
(Subtype_Indic
,
2222 Make_Subtype_From_Expr
(Exp
, Unc_Type
));
2224 end Expand_Subtype_From_Expr
;
2226 ------------------------
2227 -- Find_Interface_ADT --
2228 ------------------------
2230 function Find_Interface_ADT
2232 Iface
: Entity_Id
) return Elmt_Id
2235 Typ
: Entity_Id
:= T
;
2238 pragma Assert
(Is_Interface
(Iface
));
2240 -- Handle private types
2242 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2243 Typ
:= Full_View
(Typ
);
2246 -- Handle access types
2248 if Is_Access_Type
(Typ
) then
2249 Typ
:= Designated_Type
(Typ
);
2252 -- Handle task and protected types implementing interfaces
2254 if Is_Concurrent_Type
(Typ
) then
2255 Typ
:= Corresponding_Record_Type
(Typ
);
2259 (not Is_Class_Wide_Type
(Typ
)
2260 and then Ekind
(Typ
) /= E_Incomplete_Type
);
2262 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2263 return First_Elmt
(Access_Disp_Table
(Typ
));
2266 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
2268 and then Present
(Related_Type
(Node
(ADT
)))
2269 and then Related_Type
(Node
(ADT
)) /= Iface
2270 and then not Is_Ancestor
(Iface
, Related_Type
(Node
(ADT
)),
2271 Use_Full_View
=> True)
2276 pragma Assert
(Present
(Related_Type
(Node
(ADT
))));
2279 end Find_Interface_ADT
;
2281 ------------------------
2282 -- Find_Interface_Tag --
2283 ------------------------
2285 function Find_Interface_Tag
2287 Iface
: Entity_Id
) return Entity_Id
2290 Found
: Boolean := False;
2291 Typ
: Entity_Id
:= T
;
2293 procedure Find_Tag
(Typ
: Entity_Id
);
2294 -- Internal subprogram used to recursively climb to the ancestors
2300 procedure Find_Tag
(Typ
: Entity_Id
) is
2305 -- This routine does not handle the case in which the interface is an
2306 -- ancestor of Typ. That case is handled by the enclosing subprogram.
2308 pragma Assert
(Typ
/= Iface
);
2310 -- Climb to the root type handling private types
2312 if Present
(Full_View
(Etype
(Typ
))) then
2313 if Full_View
(Etype
(Typ
)) /= Typ
then
2314 Find_Tag
(Full_View
(Etype
(Typ
)));
2317 elsif Etype
(Typ
) /= Typ
then
2318 Find_Tag
(Etype
(Typ
));
2321 -- Traverse the list of interfaces implemented by the type
2324 and then Present
(Interfaces
(Typ
))
2325 and then not (Is_Empty_Elmt_List
(Interfaces
(Typ
)))
2327 -- Skip the tag associated with the primary table
2329 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2330 AI_Tag
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2331 pragma Assert
(Present
(AI_Tag
));
2333 AI_Elmt
:= First_Elmt
(Interfaces
(Typ
));
2334 while Present
(AI_Elmt
) loop
2335 AI
:= Node
(AI_Elmt
);
2338 or else Is_Ancestor
(Iface
, AI
, Use_Full_View
=> True)
2344 AI_Tag
:= Next_Tag_Component
(AI_Tag
);
2345 Next_Elmt
(AI_Elmt
);
2350 -- Start of processing for Find_Interface_Tag
2353 pragma Assert
(Is_Interface
(Iface
));
2355 -- Handle access types
2357 if Is_Access_Type
(Typ
) then
2358 Typ
:= Designated_Type
(Typ
);
2361 -- Handle class-wide types
2363 if Is_Class_Wide_Type
(Typ
) then
2364 Typ
:= Root_Type
(Typ
);
2367 -- Handle private types
2369 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2370 Typ
:= Full_View
(Typ
);
2373 -- Handle entities from the limited view
2375 if Ekind
(Typ
) = E_Incomplete_Type
then
2376 pragma Assert
(Present
(Non_Limited_View
(Typ
)));
2377 Typ
:= Non_Limited_View
(Typ
);
2380 -- Handle task and protected types implementing interfaces
2382 if Is_Concurrent_Type
(Typ
) then
2383 Typ
:= Corresponding_Record_Type
(Typ
);
2386 -- If the interface is an ancestor of the type, then it shared the
2387 -- primary dispatch table.
2389 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2390 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2391 return First_Tag_Component
(Typ
);
2393 -- Otherwise we need to search for its associated tag component
2397 pragma Assert
(Found
);
2400 end Find_Interface_Tag
;
2406 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
is
2408 Typ
: Entity_Id
:= T
;
2412 if Is_Class_Wide_Type
(Typ
) then
2413 Typ
:= Root_Type
(Typ
);
2416 Typ
:= Underlying_Type
(Typ
);
2418 -- Loop through primitive operations
2420 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
2421 while Present
(Prim
) loop
2424 -- We can retrieve primitive operations by name if it is an internal
2425 -- name. For equality we must check that both of its operands have
2426 -- the same type, to avoid confusion with user-defined equalities
2427 -- than may have a non-symmetric signature.
2429 exit when Chars
(Op
) = Name
2432 or else Etype
(First_Formal
(Op
)) = Etype
(Last_Formal
(Op
)));
2436 -- Raise Program_Error if no primitive found
2439 raise Program_Error
;
2450 function Find_Prim_Op
2452 Name
: TSS_Name_Type
) return Entity_Id
2454 Inher_Op
: Entity_Id
:= Empty
;
2455 Own_Op
: Entity_Id
:= Empty
;
2456 Prim_Elmt
: Elmt_Id
;
2457 Prim_Id
: Entity_Id
;
2458 Typ
: Entity_Id
:= T
;
2461 if Is_Class_Wide_Type
(Typ
) then
2462 Typ
:= Root_Type
(Typ
);
2465 Typ
:= Underlying_Type
(Typ
);
2467 -- This search is based on the assertion that the dispatching version
2468 -- of the TSS routine always precedes the real primitive.
2470 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
2471 while Present
(Prim_Elmt
) loop
2472 Prim_Id
:= Node
(Prim_Elmt
);
2474 if Is_TSS
(Prim_Id
, Name
) then
2475 if Present
(Alias
(Prim_Id
)) then
2476 Inher_Op
:= Prim_Id
;
2482 Next_Elmt
(Prim_Elmt
);
2485 if Present
(Own_Op
) then
2487 elsif Present
(Inher_Op
) then
2490 raise Program_Error
;
2494 ----------------------------
2495 -- Find_Protection_Object --
2496 ----------------------------
2498 function Find_Protection_Object
(Scop
: Entity_Id
) return Entity_Id
is
2503 while Present
(S
) loop
2504 if Ekind_In
(S
, E_Entry
, E_Entry_Family
, E_Function
, E_Procedure
)
2505 and then Present
(Protection_Object
(S
))
2507 return Protection_Object
(S
);
2513 -- If we do not find a Protection object in the scope chain, then
2514 -- something has gone wrong, most likely the object was never created.
2516 raise Program_Error
;
2517 end Find_Protection_Object
;
2519 --------------------------
2520 -- Find_Protection_Type --
2521 --------------------------
2523 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
is
2525 Typ
: Entity_Id
:= Conc_Typ
;
2528 if Is_Concurrent_Type
(Typ
) then
2529 Typ
:= Corresponding_Record_Type
(Typ
);
2532 -- Since restriction violations are not considered serious errors, the
2533 -- expander remains active, but may leave the corresponding record type
2534 -- malformed. In such cases, component _object is not available so do
2537 if not Analyzed
(Typ
) then
2541 Comp
:= First_Component
(Typ
);
2542 while Present
(Comp
) loop
2543 if Chars
(Comp
) = Name_uObject
then
2544 return Base_Type
(Etype
(Comp
));
2547 Next_Component
(Comp
);
2550 -- The corresponding record of a protected type should always have an
2553 raise Program_Error
;
2554 end Find_Protection_Type
;
2556 ----------------------
2557 -- Force_Evaluation --
2558 ----------------------
2560 procedure Force_Evaluation
(Exp
: Node_Id
; Name_Req
: Boolean := False) is
2562 Remove_Side_Effects
(Exp
, Name_Req
, Variable_Ref
=> True);
2563 end Force_Evaluation
;
2565 ---------------------------------
2566 -- Fully_Qualified_Name_String --
2567 ---------------------------------
2569 function Fully_Qualified_Name_String
2571 Append_NUL
: Boolean := True) return String_Id
2573 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
);
2574 -- Compute recursively the qualified name without NUL at the end, adding
2575 -- it to the currently started string being generated
2577 ----------------------------------
2578 -- Internal_Full_Qualified_Name --
2579 ----------------------------------
2581 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
) is
2585 -- Deal properly with child units
2587 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
2588 Ent
:= Defining_Identifier
(E
);
2593 -- Compute qualification recursively (only "Standard" has no scope)
2595 if Present
(Scope
(Scope
(Ent
))) then
2596 Internal_Full_Qualified_Name
(Scope
(Ent
));
2597 Store_String_Char
(Get_Char_Code
('.'));
2600 -- Every entity should have a name except some expanded blocks
2601 -- don't bother about those.
2603 if Chars
(Ent
) = No_Name
then
2607 -- Generates the entity name in upper case
2609 Get_Decoded_Name_String
(Chars
(Ent
));
2611 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
2613 end Internal_Full_Qualified_Name
;
2615 -- Start of processing for Full_Qualified_Name
2619 Internal_Full_Qualified_Name
(E
);
2622 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
2626 end Fully_Qualified_Name_String
;
2628 ------------------------
2629 -- Generate_Poll_Call --
2630 ------------------------
2632 procedure Generate_Poll_Call
(N
: Node_Id
) is
2634 -- No poll call if polling not active
2636 if not Polling_Required
then
2639 -- Otherwise generate require poll call
2642 Insert_Before_And_Analyze
(N
,
2643 Make_Procedure_Call_Statement
(Sloc
(N
),
2644 Name
=> New_Occurrence_Of
(RTE
(RE_Poll
), Sloc
(N
))));
2646 end Generate_Poll_Call
;
2648 ---------------------------------
2649 -- Get_Current_Value_Condition --
2650 ---------------------------------
2652 -- Note: the implementation of this procedure is very closely tied to the
2653 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
2654 -- interpret Current_Value fields set by the Set procedure, so the two
2655 -- procedures need to be closely coordinated.
2657 procedure Get_Current_Value_Condition
2662 Loc
: constant Source_Ptr
:= Sloc
(Var
);
2663 Ent
: constant Entity_Id
:= Entity
(Var
);
2665 procedure Process_Current_Value_Condition
2668 -- N is an expression which holds either True (S = True) or False (S =
2669 -- False) in the condition. This procedure digs out the expression and
2670 -- if it refers to Ent, sets Op and Val appropriately.
2672 -------------------------------------
2673 -- Process_Current_Value_Condition --
2674 -------------------------------------
2676 procedure Process_Current_Value_Condition
2681 Prev_Cond
: Node_Id
;
2691 -- Deal with NOT operators, inverting sense
2693 while Nkind
(Cond
) = N_Op_Not
loop
2694 Cond
:= Right_Opnd
(Cond
);
2698 -- Deal with conversions, qualifications, and expressions with
2701 while Nkind_In
(Cond
,
2703 N_Qualified_Expression
,
2704 N_Expression_With_Actions
)
2706 Cond
:= Expression
(Cond
);
2709 exit when Cond
= Prev_Cond
;
2712 -- Deal with AND THEN and AND cases
2714 if Nkind_In
(Cond
, N_And_Then
, N_Op_And
) then
2716 -- Don't ever try to invert a condition that is of the form of an
2717 -- AND or AND THEN (since we are not doing sufficiently general
2718 -- processing to allow this).
2720 if Sens
= False then
2726 -- Recursively process AND and AND THEN branches
2728 Process_Current_Value_Condition
(Left_Opnd
(Cond
), True);
2730 if Op
/= N_Empty
then
2734 Process_Current_Value_Condition
(Right_Opnd
(Cond
), True);
2737 -- Case of relational operator
2739 elsif Nkind
(Cond
) in N_Op_Compare
then
2742 -- Invert sense of test if inverted test
2744 if Sens
= False then
2746 when N_Op_Eq
=> Op
:= N_Op_Ne
;
2747 when N_Op_Ne
=> Op
:= N_Op_Eq
;
2748 when N_Op_Lt
=> Op
:= N_Op_Ge
;
2749 when N_Op_Gt
=> Op
:= N_Op_Le
;
2750 when N_Op_Le
=> Op
:= N_Op_Gt
;
2751 when N_Op_Ge
=> Op
:= N_Op_Lt
;
2752 when others => raise Program_Error
;
2756 -- Case of entity op value
2758 if Is_Entity_Name
(Left_Opnd
(Cond
))
2759 and then Ent
= Entity
(Left_Opnd
(Cond
))
2760 and then Compile_Time_Known_Value
(Right_Opnd
(Cond
))
2762 Val
:= Right_Opnd
(Cond
);
2764 -- Case of value op entity
2766 elsif Is_Entity_Name
(Right_Opnd
(Cond
))
2767 and then Ent
= Entity
(Right_Opnd
(Cond
))
2768 and then Compile_Time_Known_Value
(Left_Opnd
(Cond
))
2770 Val
:= Left_Opnd
(Cond
);
2772 -- We are effectively swapping operands
2775 when N_Op_Eq
=> null;
2776 when N_Op_Ne
=> null;
2777 when N_Op_Lt
=> Op
:= N_Op_Gt
;
2778 when N_Op_Gt
=> Op
:= N_Op_Lt
;
2779 when N_Op_Le
=> Op
:= N_Op_Ge
;
2780 when N_Op_Ge
=> Op
:= N_Op_Le
;
2781 when others => raise Program_Error
;
2790 elsif Nkind_In
(Cond
,
2792 N_Qualified_Expression
,
2793 N_Expression_With_Actions
)
2795 Cond
:= Expression
(Cond
);
2797 -- Case of Boolean variable reference, return as though the
2798 -- reference had said var = True.
2801 if Is_Entity_Name
(Cond
) and then Ent
= Entity
(Cond
) then
2802 Val
:= New_Occurrence_Of
(Standard_True
, Sloc
(Cond
));
2804 if Sens
= False then
2811 end Process_Current_Value_Condition
;
2813 -- Start of processing for Get_Current_Value_Condition
2819 -- Immediate return, nothing doing, if this is not an object
2821 if Ekind
(Ent
) not in Object_Kind
then
2825 -- Otherwise examine current value
2828 CV
: constant Node_Id
:= Current_Value
(Ent
);
2833 -- If statement. Condition is known true in THEN section, known False
2834 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
2836 if Nkind
(CV
) = N_If_Statement
then
2838 -- Before start of IF statement
2840 if Loc
< Sloc
(CV
) then
2843 -- After end of IF statement
2845 elsif Loc
>= Sloc
(CV
) + Text_Ptr
(UI_To_Int
(End_Span
(CV
))) then
2849 -- At this stage we know that we are within the IF statement, but
2850 -- unfortunately, the tree does not record the SLOC of the ELSE so
2851 -- we cannot use a simple SLOC comparison to distinguish between
2852 -- the then/else statements, so we have to climb the tree.
2859 while Parent
(N
) /= CV
loop
2862 -- If we fall off the top of the tree, then that's odd, but
2863 -- perhaps it could occur in some error situation, and the
2864 -- safest response is simply to assume that the outcome of
2865 -- the condition is unknown. No point in bombing during an
2866 -- attempt to optimize things.
2873 -- Now we have N pointing to a node whose parent is the IF
2874 -- statement in question, so now we can tell if we are within
2875 -- the THEN statements.
2877 if Is_List_Member
(N
)
2878 and then List_Containing
(N
) = Then_Statements
(CV
)
2882 -- If the variable reference does not come from source, we
2883 -- cannot reliably tell whether it appears in the else part.
2884 -- In particular, if it appears in generated code for a node
2885 -- that requires finalization, it may be attached to a list
2886 -- that has not been yet inserted into the code. For now,
2887 -- treat it as unknown.
2889 elsif not Comes_From_Source
(N
) then
2892 -- Otherwise we must be in ELSIF or ELSE part
2899 -- ELSIF part. Condition is known true within the referenced
2900 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
2901 -- and unknown before the ELSE part or after the IF statement.
2903 elsif Nkind
(CV
) = N_Elsif_Part
then
2905 -- if the Elsif_Part had condition_actions, the elsif has been
2906 -- rewritten as a nested if, and the original elsif_part is
2907 -- detached from the tree, so there is no way to obtain useful
2908 -- information on the current value of the variable.
2909 -- Can this be improved ???
2911 if No
(Parent
(CV
)) then
2917 -- Before start of ELSIF part
2919 if Loc
< Sloc
(CV
) then
2922 -- After end of IF statement
2924 elsif Loc
>= Sloc
(Stm
) +
2925 Text_Ptr
(UI_To_Int
(End_Span
(Stm
)))
2930 -- Again we lack the SLOC of the ELSE, so we need to climb the
2931 -- tree to see if we are within the ELSIF part in question.
2938 while Parent
(N
) /= Stm
loop
2941 -- If we fall off the top of the tree, then that's odd, but
2942 -- perhaps it could occur in some error situation, and the
2943 -- safest response is simply to assume that the outcome of
2944 -- the condition is unknown. No point in bombing during an
2945 -- attempt to optimize things.
2952 -- Now we have N pointing to a node whose parent is the IF
2953 -- statement in question, so see if is the ELSIF part we want.
2954 -- the THEN statements.
2959 -- Otherwise we must be in subsequent ELSIF or ELSE part
2966 -- Iteration scheme of while loop. The condition is known to be
2967 -- true within the body of the loop.
2969 elsif Nkind
(CV
) = N_Iteration_Scheme
then
2971 Loop_Stmt
: constant Node_Id
:= Parent
(CV
);
2974 -- Before start of body of loop
2976 if Loc
< Sloc
(Loop_Stmt
) then
2979 -- After end of LOOP statement
2981 elsif Loc
>= Sloc
(End_Label
(Loop_Stmt
)) then
2984 -- We are within the body of the loop
2991 -- All other cases of Current_Value settings
2997 -- If we fall through here, then we have a reportable condition, Sens
2998 -- is True if the condition is true and False if it needs inverting.
3000 Process_Current_Value_Condition
(Condition
(CV
), Sens
);
3002 end Get_Current_Value_Condition
;
3004 ---------------------
3005 -- Get_Stream_Size --
3006 ---------------------
3008 function Get_Stream_Size
(E
: Entity_Id
) return Uint
is
3010 -- If we have a Stream_Size clause for this type use it
3012 if Has_Stream_Size_Clause
(E
) then
3013 return Static_Integer
(Expression
(Stream_Size_Clause
(E
)));
3015 -- Otherwise the Stream_Size if the size of the type
3020 end Get_Stream_Size
;
3022 ---------------------------
3023 -- Has_Access_Constraint --
3024 ---------------------------
3026 function Has_Access_Constraint
(E
: Entity_Id
) return Boolean is
3028 T
: constant Entity_Id
:= Etype
(E
);
3031 if Has_Per_Object_Constraint
(E
) and then Has_Discriminants
(T
) then
3032 Disc
:= First_Discriminant
(T
);
3033 while Present
(Disc
) loop
3034 if Is_Access_Type
(Etype
(Disc
)) then
3038 Next_Discriminant
(Disc
);
3045 end Has_Access_Constraint
;
3047 ----------------------------------
3048 -- Has_Following_Address_Clause --
3049 ----------------------------------
3051 -- Should this function check the private part in a package ???
3053 function Has_Following_Address_Clause
(D
: Node_Id
) return Boolean is
3054 Id
: constant Entity_Id
:= Defining_Identifier
(D
);
3059 while Present
(Decl
) loop
3060 if Nkind
(Decl
) = N_At_Clause
3061 and then Chars
(Identifier
(Decl
)) = Chars
(Id
)
3065 elsif Nkind
(Decl
) = N_Attribute_Definition_Clause
3066 and then Chars
(Decl
) = Name_Address
3067 and then Chars
(Name
(Decl
)) = Chars
(Id
)
3076 end Has_Following_Address_Clause
;
3078 --------------------
3079 -- Homonym_Number --
3080 --------------------
3082 function Homonym_Number
(Subp
: Entity_Id
) return Nat
is
3088 Hom
:= Homonym
(Subp
);
3089 while Present
(Hom
) loop
3090 if Scope
(Hom
) = Scope
(Subp
) then
3094 Hom
:= Homonym
(Hom
);
3100 -----------------------------------
3101 -- In_Library_Level_Package_Body --
3102 -----------------------------------
3104 function In_Library_Level_Package_Body
(Id
: Entity_Id
) return Boolean is
3106 -- First determine whether the entity appears at the library level, then
3107 -- look at the containing unit.
3109 if Is_Library_Level_Entity
(Id
) then
3111 Container
: constant Node_Id
:= Cunit
(Get_Source_Unit
(Id
));
3114 return Nkind
(Unit
(Container
)) = N_Package_Body
;
3119 end In_Library_Level_Package_Body
;
3121 ------------------------------
3122 -- In_Unconditional_Context --
3123 ------------------------------
3125 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean is
3130 while Present
(P
) loop
3132 when N_Subprogram_Body
=>
3135 when N_If_Statement
=>
3138 when N_Loop_Statement
=>
3141 when N_Case_Statement
=>
3150 end In_Unconditional_Context
;
3156 procedure Insert_Action
(Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
) is
3158 if Present
(Ins_Action
) then
3159 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
));
3163 -- Version with check(s) suppressed
3165 procedure Insert_Action
3166 (Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
; Suppress
: Check_Id
)
3169 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
), Suppress
);
3172 -------------------------
3173 -- Insert_Action_After --
3174 -------------------------
3176 procedure Insert_Action_After
3177 (Assoc_Node
: Node_Id
;
3178 Ins_Action
: Node_Id
)
3181 Insert_Actions_After
(Assoc_Node
, New_List
(Ins_Action
));
3182 end Insert_Action_After
;
3184 --------------------
3185 -- Insert_Actions --
3186 --------------------
3188 procedure Insert_Actions
(Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
) is
3192 Wrapped_Node
: Node_Id
:= Empty
;
3195 if No
(Ins_Actions
) or else Is_Empty_List
(Ins_Actions
) then
3199 -- Ignore insert of actions from inside default expression (or other
3200 -- similar "spec expression") in the special spec-expression analyze
3201 -- mode. Any insertions at this point have no relevance, since we are
3202 -- only doing the analyze to freeze the types of any static expressions.
3203 -- See section "Handling of Default Expressions" in the spec of package
3204 -- Sem for further details.
3206 if In_Spec_Expression
then
3210 -- If the action derives from stuff inside a record, then the actions
3211 -- are attached to the current scope, to be inserted and analyzed on
3212 -- exit from the scope. The reason for this is that we may also be
3213 -- generating freeze actions at the same time, and they must eventually
3214 -- be elaborated in the correct order.
3216 if Is_Record_Type
(Current_Scope
)
3217 and then not Is_Frozen
(Current_Scope
)
3219 if No
(Scope_Stack
.Table
3220 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
3222 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:=
3227 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
);
3233 -- We now intend to climb up the tree to find the right point to
3234 -- insert the actions. We start at Assoc_Node, unless this node is a
3235 -- subexpression in which case we start with its parent. We do this for
3236 -- two reasons. First it speeds things up. Second, if Assoc_Node is
3237 -- itself one of the special nodes like N_And_Then, then we assume that
3238 -- an initial request to insert actions for such a node does not expect
3239 -- the actions to get deposited in the node for later handling when the
3240 -- node is expanded, since clearly the node is being dealt with by the
3241 -- caller. Note that in the subexpression case, N is always the child we
3244 -- N_Raise_xxx_Error is an annoying special case, it is a statement if
3245 -- it has type Standard_Void_Type, and a subexpression otherwise.
3246 -- otherwise. Procedure calls, and similarly procedure attribute
3247 -- references, are also statements.
3249 if Nkind
(Assoc_Node
) in N_Subexpr
3250 and then (Nkind
(Assoc_Node
) not in N_Raise_xxx_Error
3251 or else Etype
(Assoc_Node
) /= Standard_Void_Type
)
3252 and then Nkind
(Assoc_Node
) /= N_Procedure_Call_Statement
3253 and then (Nkind
(Assoc_Node
) /= N_Attribute_Reference
3255 not Is_Procedure_Attribute_Name
3256 (Attribute_Name
(Assoc_Node
)))
3259 P
:= Parent
(Assoc_Node
);
3261 -- Non-subexpression case. Note that N is initially Empty in this case
3262 -- (N is only guaranteed Non-Empty in the subexpr case).
3269 -- Capture root of the transient scope
3271 if Scope_Is_Transient
then
3272 Wrapped_Node
:= Node_To_Be_Wrapped
;
3276 pragma Assert
(Present
(P
));
3278 -- Make sure that inserted actions stay in the transient scope
3280 if Present
(Wrapped_Node
) and then N
= Wrapped_Node
then
3281 Store_Before_Actions_In_Scope
(Ins_Actions
);
3287 -- Case of right operand of AND THEN or OR ELSE. Put the actions
3288 -- in the Actions field of the right operand. They will be moved
3289 -- out further when the AND THEN or OR ELSE operator is expanded.
3290 -- Nothing special needs to be done for the left operand since
3291 -- in that case the actions are executed unconditionally.
3293 when N_Short_Circuit
=>
3294 if N
= Right_Opnd
(P
) then
3296 -- We are now going to either append the actions to the
3297 -- actions field of the short-circuit operation. We will
3298 -- also analyze the actions now.
3300 -- This analysis is really too early, the proper thing would
3301 -- be to just park them there now, and only analyze them if
3302 -- we find we really need them, and to it at the proper
3303 -- final insertion point. However attempting to this proved
3304 -- tricky, so for now we just kill current values before and
3305 -- after the analyze call to make sure we avoid peculiar
3306 -- optimizations from this out of order insertion.
3308 Kill_Current_Values
;
3310 if Present
(Actions
(P
)) then
3311 Insert_List_After_And_Analyze
3312 (Last
(Actions
(P
)), Ins_Actions
);
3314 Set_Actions
(P
, Ins_Actions
);
3315 Analyze_List
(Actions
(P
));
3318 Kill_Current_Values
;
3323 -- Then or Else dependent expression of an if expression. Add
3324 -- actions to Then_Actions or Else_Actions field as appropriate.
3325 -- The actions will be moved further out when the if is expanded.
3327 when N_If_Expression
=>
3329 ThenX
: constant Node_Id
:= Next
(First
(Expressions
(P
)));
3330 ElseX
: constant Node_Id
:= Next
(ThenX
);
3333 -- If the enclosing expression is already analyzed, as
3334 -- is the case for nested elaboration checks, insert the
3335 -- conditional further out.
3337 if Analyzed
(P
) then
3340 -- Actions belong to the then expression, temporarily place
3341 -- them as Then_Actions of the if expression. They will be
3342 -- moved to the proper place later when the if expression
3345 elsif N
= ThenX
then
3346 if Present
(Then_Actions
(P
)) then
3347 Insert_List_After_And_Analyze
3348 (Last
(Then_Actions
(P
)), Ins_Actions
);
3350 Set_Then_Actions
(P
, Ins_Actions
);
3351 Analyze_List
(Then_Actions
(P
));
3356 -- Actions belong to the else expression, temporarily place
3357 -- them as Else_Actions of the if expression. They will be
3358 -- moved to the proper place later when the if expression
3361 elsif N
= ElseX
then
3362 if Present
(Else_Actions
(P
)) then
3363 Insert_List_After_And_Analyze
3364 (Last
(Else_Actions
(P
)), Ins_Actions
);
3366 Set_Else_Actions
(P
, Ins_Actions
);
3367 Analyze_List
(Else_Actions
(P
));
3372 -- Actions belong to the condition. In this case they are
3373 -- unconditionally executed, and so we can continue the
3374 -- search for the proper insert point.
3381 -- Alternative of case expression, we place the action in the
3382 -- Actions field of the case expression alternative, this will
3383 -- be handled when the case expression is expanded.
3385 when N_Case_Expression_Alternative
=>
3386 if Present
(Actions
(P
)) then
3387 Insert_List_After_And_Analyze
3388 (Last
(Actions
(P
)), Ins_Actions
);
3390 Set_Actions
(P
, Ins_Actions
);
3391 Analyze_List
(Actions
(P
));
3396 -- Case of appearing within an Expressions_With_Actions node. When
3397 -- the new actions come from the expression of the expression with
3398 -- actions, they must be added to the existing actions. The other
3399 -- alternative is when the new actions are related to one of the
3400 -- existing actions of the expression with actions. In that case
3401 -- they must be inserted further up the tree.
3403 when N_Expression_With_Actions
=>
3404 if N
= Expression
(P
) then
3405 if Is_Empty_List
(Actions
(P
)) then
3406 Append_List_To
(Actions
(P
), Ins_Actions
);
3407 Analyze_List
(Actions
(P
));
3409 Insert_List_After_And_Analyze
3410 (Last
(Actions
(P
)), Ins_Actions
);
3415 -- Case of appearing in the condition of a while expression or
3416 -- elsif. We insert the actions into the Condition_Actions field.
3417 -- They will be moved further out when the while loop or elsif
3420 when N_Iteration_Scheme |
3423 if N
= Condition
(P
) then
3424 if Present
(Condition_Actions
(P
)) then
3425 Insert_List_After_And_Analyze
3426 (Last
(Condition_Actions
(P
)), Ins_Actions
);
3428 Set_Condition_Actions
(P
, Ins_Actions
);
3430 -- Set the parent of the insert actions explicitly. This
3431 -- is not a syntactic field, but we need the parent field
3432 -- set, in particular so that freeze can understand that
3433 -- it is dealing with condition actions, and properly
3434 -- insert the freezing actions.
3436 Set_Parent
(Ins_Actions
, P
);
3437 Analyze_List
(Condition_Actions
(P
));
3443 -- Statements, declarations, pragmas, representation clauses
3448 N_Procedure_Call_Statement |
3449 N_Statement_Other_Than_Procedure_Call |
3455 -- Representation_Clause
3458 N_Attribute_Definition_Clause |
3459 N_Enumeration_Representation_Clause |
3460 N_Record_Representation_Clause |
3464 N_Abstract_Subprogram_Declaration |
3466 N_Exception_Declaration |
3467 N_Exception_Renaming_Declaration |
3468 N_Expression_Function |
3469 N_Formal_Abstract_Subprogram_Declaration |
3470 N_Formal_Concrete_Subprogram_Declaration |
3471 N_Formal_Object_Declaration |
3472 N_Formal_Type_Declaration |
3473 N_Full_Type_Declaration |
3474 N_Function_Instantiation |
3475 N_Generic_Function_Renaming_Declaration |
3476 N_Generic_Package_Declaration |
3477 N_Generic_Package_Renaming_Declaration |
3478 N_Generic_Procedure_Renaming_Declaration |
3479 N_Generic_Subprogram_Declaration |
3480 N_Implicit_Label_Declaration |
3481 N_Incomplete_Type_Declaration |
3482 N_Number_Declaration |
3483 N_Object_Declaration |
3484 N_Object_Renaming_Declaration |
3486 N_Package_Body_Stub |
3487 N_Package_Declaration |
3488 N_Package_Instantiation |
3489 N_Package_Renaming_Declaration |
3490 N_Private_Extension_Declaration |
3491 N_Private_Type_Declaration |
3492 N_Procedure_Instantiation |
3494 N_Protected_Body_Stub |
3495 N_Protected_Type_Declaration |
3496 N_Single_Task_Declaration |
3498 N_Subprogram_Body_Stub |
3499 N_Subprogram_Declaration |
3500 N_Subprogram_Renaming_Declaration |
3501 N_Subtype_Declaration |
3504 N_Task_Type_Declaration |
3506 -- Use clauses can appear in lists of declarations
3508 N_Use_Package_Clause |
3511 -- Freeze entity behaves like a declaration or statement
3514 N_Freeze_Generic_Entity
3516 -- Do not insert here if the item is not a list member (this
3517 -- happens for example with a triggering statement, and the
3518 -- proper approach is to insert before the entire select).
3520 if not Is_List_Member
(P
) then
3523 -- Do not insert if parent of P is an N_Component_Association
3524 -- node (i.e. we are in the context of an N_Aggregate or
3525 -- N_Extension_Aggregate node. In this case we want to insert
3526 -- before the entire aggregate.
3528 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
3531 -- Do not insert if the parent of P is either an N_Variant node
3532 -- or an N_Record_Definition node, meaning in either case that
3533 -- P is a member of a component list, and that therefore the
3534 -- actions should be inserted outside the complete record
3537 elsif Nkind_In
(Parent
(P
), N_Variant
, N_Record_Definition
) then
3540 -- Do not insert freeze nodes within the loop generated for
3541 -- an aggregate, because they may be elaborated too late for
3542 -- subsequent use in the back end: within a package spec the
3543 -- loop is part of the elaboration procedure and is only
3544 -- elaborated during the second pass.
3546 -- If the loop comes from source, or the entity is local to the
3547 -- loop itself it must remain within.
3549 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
3550 and then not Comes_From_Source
(Parent
(P
))
3551 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
3553 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
3557 -- Otherwise we can go ahead and do the insertion
3559 elsif P
= Wrapped_Node
then
3560 Store_Before_Actions_In_Scope
(Ins_Actions
);
3564 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
3568 -- A special case, N_Raise_xxx_Error can act either as a statement
3569 -- or a subexpression. We tell the difference by looking at the
3570 -- Etype. It is set to Standard_Void_Type in the statement case.
3573 N_Raise_xxx_Error
=>
3574 if Etype
(P
) = Standard_Void_Type
then
3575 if P
= Wrapped_Node
then
3576 Store_Before_Actions_In_Scope
(Ins_Actions
);
3578 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
3583 -- In the subexpression case, keep climbing
3589 -- If a component association appears within a loop created for
3590 -- an array aggregate, attach the actions to the association so
3591 -- they can be subsequently inserted within the loop. For other
3592 -- component associations insert outside of the aggregate. For
3593 -- an association that will generate a loop, its Loop_Actions
3594 -- attribute is already initialized (see exp_aggr.adb).
3596 -- The list of loop_actions can in turn generate additional ones,
3597 -- that are inserted before the associated node. If the associated
3598 -- node is outside the aggregate, the new actions are collected
3599 -- at the end of the loop actions, to respect the order in which
3600 -- they are to be elaborated.
3603 N_Component_Association
=>
3604 if Nkind
(Parent
(P
)) = N_Aggregate
3605 and then Present
(Loop_Actions
(P
))
3607 if Is_Empty_List
(Loop_Actions
(P
)) then
3608 Set_Loop_Actions
(P
, Ins_Actions
);
3609 Analyze_List
(Ins_Actions
);
3616 -- Check whether these actions were generated by a
3617 -- declaration that is part of the loop_ actions
3618 -- for the component_association.
3621 while Present
(Decl
) loop
3622 exit when Parent
(Decl
) = P
3623 and then Is_List_Member
(Decl
)
3625 List_Containing
(Decl
) = Loop_Actions
(P
);
3626 Decl
:= Parent
(Decl
);
3629 if Present
(Decl
) then
3630 Insert_List_Before_And_Analyze
3631 (Decl
, Ins_Actions
);
3633 Insert_List_After_And_Analyze
3634 (Last
(Loop_Actions
(P
)), Ins_Actions
);
3645 -- Another special case, an attribute denoting a procedure call
3648 N_Attribute_Reference
=>
3649 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
3650 if P
= Wrapped_Node
then
3651 Store_Before_Actions_In_Scope
(Ins_Actions
);
3653 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
3658 -- In the subexpression case, keep climbing
3664 -- A contract node should not belong to the tree
3667 raise Program_Error
;
3669 -- For all other node types, keep climbing tree
3673 N_Accept_Alternative |
3674 N_Access_Definition |
3675 N_Access_Function_Definition |
3676 N_Access_Procedure_Definition |
3677 N_Access_To_Object_Definition |
3680 N_Aspect_Specification |
3682 N_Case_Statement_Alternative |
3683 N_Character_Literal |
3684 N_Compilation_Unit |
3685 N_Compilation_Unit_Aux |
3686 N_Component_Clause |
3687 N_Component_Declaration |
3688 N_Component_Definition |
3690 N_Constrained_Array_Definition |
3691 N_Decimal_Fixed_Point_Definition |
3692 N_Defining_Character_Literal |
3693 N_Defining_Identifier |
3694 N_Defining_Operator_Symbol |
3695 N_Defining_Program_Unit_Name |
3696 N_Delay_Alternative |
3697 N_Delta_Constraint |
3698 N_Derived_Type_Definition |
3700 N_Digits_Constraint |
3701 N_Discriminant_Association |
3702 N_Discriminant_Specification |
3704 N_Entry_Body_Formal_Part |
3705 N_Entry_Call_Alternative |
3706 N_Entry_Declaration |
3707 N_Entry_Index_Specification |
3708 N_Enumeration_Type_Definition |
3710 N_Exception_Handler |
3712 N_Explicit_Dereference |
3713 N_Extension_Aggregate |
3714 N_Floating_Point_Definition |
3715 N_Formal_Decimal_Fixed_Point_Definition |
3716 N_Formal_Derived_Type_Definition |
3717 N_Formal_Discrete_Type_Definition |
3718 N_Formal_Floating_Point_Definition |
3719 N_Formal_Modular_Type_Definition |
3720 N_Formal_Ordinary_Fixed_Point_Definition |
3721 N_Formal_Package_Declaration |
3722 N_Formal_Private_Type_Definition |
3723 N_Formal_Incomplete_Type_Definition |
3724 N_Formal_Signed_Integer_Type_Definition |
3726 N_Function_Specification |
3727 N_Generic_Association |
3728 N_Handled_Sequence_Of_Statements |
3731 N_Index_Or_Discriminant_Constraint |
3732 N_Indexed_Component |
3734 N_Iterator_Specification |
3737 N_Loop_Parameter_Specification |
3739 N_Modular_Type_Definition |
3765 N_Op_Shift_Right_Arithmetic |
3769 N_Ordinary_Fixed_Point_Definition |
3771 N_Package_Specification |
3772 N_Parameter_Association |
3773 N_Parameter_Specification |
3774 N_Pop_Constraint_Error_Label |
3775 N_Pop_Program_Error_Label |
3776 N_Pop_Storage_Error_Label |
3777 N_Pragma_Argument_Association |
3778 N_Procedure_Specification |
3779 N_Protected_Definition |
3780 N_Push_Constraint_Error_Label |
3781 N_Push_Program_Error_Label |
3782 N_Push_Storage_Error_Label |
3783 N_Qualified_Expression |
3784 N_Quantified_Expression |
3785 N_Raise_Expression |
3787 N_Range_Constraint |
3789 N_Real_Range_Specification |
3790 N_Record_Definition |
3792 N_SCIL_Dispatch_Table_Tag_Init |
3793 N_SCIL_Dispatching_Call |
3794 N_SCIL_Membership_Test |
3795 N_Selected_Component |
3796 N_Signed_Integer_Type_Definition |
3797 N_Single_Protected_Declaration |
3801 N_Subtype_Indication |
3804 N_Terminate_Alternative |
3805 N_Triggering_Alternative |
3807 N_Unchecked_Expression |
3808 N_Unchecked_Type_Conversion |
3809 N_Unconstrained_Array_Definition |
3814 N_Validate_Unchecked_Conversion |
3821 -- If we fall through above tests, keep climbing tree
3825 if Nkind
(Parent
(N
)) = N_Subunit
then
3827 -- This is the proper body corresponding to a stub. Insertion must
3828 -- be done at the point of the stub, which is in the declarative
3829 -- part of the parent unit.
3831 P
:= Corresponding_Stub
(Parent
(N
));
3839 -- Version with check(s) suppressed
3841 procedure Insert_Actions
3842 (Assoc_Node
: Node_Id
;
3843 Ins_Actions
: List_Id
;
3844 Suppress
: Check_Id
)
3847 if Suppress
= All_Checks
then
3849 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
3851 Scope_Suppress
.Suppress
:= (others => True);
3852 Insert_Actions
(Assoc_Node
, Ins_Actions
);
3853 Scope_Suppress
.Suppress
:= Sva
;
3858 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
3860 Scope_Suppress
.Suppress
(Suppress
) := True;
3861 Insert_Actions
(Assoc_Node
, Ins_Actions
);
3862 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
3867 --------------------------
3868 -- Insert_Actions_After --
3869 --------------------------
3871 procedure Insert_Actions_After
3872 (Assoc_Node
: Node_Id
;
3873 Ins_Actions
: List_Id
)
3876 if Scope_Is_Transient
and then Assoc_Node
= Node_To_Be_Wrapped
then
3877 Store_After_Actions_In_Scope
(Ins_Actions
);
3879 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
3881 end Insert_Actions_After
;
3883 ---------------------------------
3884 -- Insert_Library_Level_Action --
3885 ---------------------------------
3887 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
3888 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
3891 Push_Scope
(Cunit_Entity
(Main_Unit
));
3892 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
3894 if No
(Actions
(Aux
)) then
3895 Set_Actions
(Aux
, New_List
(N
));
3897 Append
(N
, Actions
(Aux
));
3902 end Insert_Library_Level_Action
;
3904 ----------------------------------
3905 -- Insert_Library_Level_Actions --
3906 ----------------------------------
3908 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
3909 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
3912 if Is_Non_Empty_List
(L
) then
3913 Push_Scope
(Cunit_Entity
(Main_Unit
));
3914 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
3916 if No
(Actions
(Aux
)) then
3917 Set_Actions
(Aux
, L
);
3920 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
3925 end Insert_Library_Level_Actions
;
3927 ----------------------
3928 -- Inside_Init_Proc --
3929 ----------------------
3931 function Inside_Init_Proc
return Boolean is
3936 while Present
(S
) and then S
/= Standard_Standard
loop
3937 if Is_Init_Proc
(S
) then
3945 end Inside_Init_Proc
;
3947 ----------------------------
3948 -- Is_All_Null_Statements --
3949 ----------------------------
3951 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
3956 while Present
(Stm
) loop
3957 if Nkind
(Stm
) /= N_Null_Statement
then
3965 end Is_All_Null_Statements
;
3967 --------------------------------------------------
3968 -- Is_Displacement_Of_Object_Or_Function_Result --
3969 --------------------------------------------------
3971 function Is_Displacement_Of_Object_Or_Function_Result
3972 (Obj_Id
: Entity_Id
) return Boolean
3974 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean;
3975 -- Determine if particular node denotes a controlled function call
3977 function Is_Displace_Call
(N
: Node_Id
) return Boolean;
3978 -- Determine whether a particular node is a call to Ada.Tags.Displace.
3979 -- The call might be nested within other actions such as conversions.
3981 function Is_Source_Object
(N
: Node_Id
) return Boolean;
3982 -- Determine whether a particular node denotes a source object
3984 ---------------------------------
3985 -- Is_Controlled_Function_Call --
3986 ---------------------------------
3988 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean is
3989 Expr
: Node_Id
:= Original_Node
(N
);
3992 if Nkind
(Expr
) = N_Function_Call
then
3993 Expr
:= Name
(Expr
);
3996 -- The function call may appear in object.operation format
3998 if Nkind
(Expr
) = N_Selected_Component
then
3999 Expr
:= Selector_Name
(Expr
);
4003 Nkind_In
(Expr
, N_Expanded_Name
, N_Identifier
)
4004 and then Ekind
(Entity
(Expr
)) = E_Function
4005 and then Needs_Finalization
(Etype
(Entity
(Expr
)));
4006 end Is_Controlled_Function_Call
;
4008 ----------------------
4009 -- Is_Displace_Call --
4010 ----------------------
4012 function Is_Displace_Call
(N
: Node_Id
) return Boolean is
4013 Call
: Node_Id
:= N
;
4016 -- Strip various actions which may precede a call to Displace
4019 if Nkind
(Call
) = N_Explicit_Dereference
then
4020 Call
:= Prefix
(Call
);
4022 elsif Nkind_In
(Call
, N_Type_Conversion
,
4023 N_Unchecked_Type_Conversion
)
4025 Call
:= Expression
(Call
);
4034 and then Nkind
(Call
) = N_Function_Call
4035 and then Is_RTE
(Entity
(Name
(Call
)), RE_Displace
);
4036 end Is_Displace_Call
;
4038 ----------------------
4039 -- Is_Source_Object --
4040 ----------------------
4042 function Is_Source_Object
(N
: Node_Id
) return Boolean is
4046 and then Nkind
(N
) in N_Has_Entity
4047 and then Is_Object
(Entity
(N
))
4048 and then Comes_From_Source
(N
);
4049 end Is_Source_Object
;
4053 Decl
: constant Node_Id
:= Parent
(Obj_Id
);
4054 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4055 Orig_Decl
: constant Node_Id
:= Original_Node
(Decl
);
4057 -- Start of processing for Is_Displacement_Of_Object_Or_Function_Result
4062 -- Obj : CW_Type := Function_Call (...);
4066 -- Tmp : ... := Function_Call (...)'reference;
4067 -- Obj : CW_Type renames (... Ada.Tags.Displace (Tmp));
4069 -- where the return type of the function and the class-wide type require
4070 -- dispatch table pointer displacement.
4074 -- Obj : CW_Type := Src_Obj;
4078 -- Obj : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
4080 -- where the type of the source object and the class-wide type require
4081 -- dispatch table pointer displacement.
4084 Nkind
(Decl
) = N_Object_Renaming_Declaration
4085 and then Nkind
(Orig_Decl
) = N_Object_Declaration
4086 and then Comes_From_Source
(Orig_Decl
)
4087 and then Is_Class_Wide_Type
(Obj_Typ
)
4088 and then Is_Displace_Call
(Renamed_Object
(Obj_Id
))
4090 (Is_Controlled_Function_Call
(Expression
(Orig_Decl
))
4091 or else Is_Source_Object
(Expression
(Orig_Decl
)));
4092 end Is_Displacement_Of_Object_Or_Function_Result
;
4094 ------------------------------
4095 -- Is_Finalizable_Transient --
4096 ------------------------------
4098 function Is_Finalizable_Transient
4100 Rel_Node
: Node_Id
) return Boolean
4102 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
4103 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4104 Desig
: Entity_Id
:= Obj_Typ
;
4106 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean;
4107 -- Determine whether transient object Trans_Id is initialized either
4108 -- by a function call which returns an access type or simply renames
4111 function Initialized_By_Aliased_BIP_Func_Call
4112 (Trans_Id
: Entity_Id
) return Boolean;
4113 -- Determine whether transient object Trans_Id is initialized by a
4114 -- build-in-place function call where the BIPalloc parameter is of
4115 -- value 1 and BIPaccess is not null. This case creates an aliasing
4116 -- between the returned value and the value denoted by BIPaccess.
4119 (Trans_Id
: Entity_Id
;
4120 First_Stmt
: Node_Id
) return Boolean;
4121 -- Determine whether transient object Trans_Id has been renamed or
4122 -- aliased through 'reference in the statement list starting from
4125 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean;
4126 -- Determine whether transient object Trans_Id is allocated on the heap
4128 function Is_Iterated_Container
4129 (Trans_Id
: Entity_Id
;
4130 First_Stmt
: Node_Id
) return Boolean;
4131 -- Determine whether transient object Trans_Id denotes a container which
4132 -- is in the process of being iterated in the statement list starting
4135 ---------------------------
4136 -- Initialized_By_Access --
4137 ---------------------------
4139 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean is
4140 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4145 and then Nkind
(Expr
) /= N_Reference
4146 and then Is_Access_Type
(Etype
(Expr
));
4147 end Initialized_By_Access
;
4149 ------------------------------------------
4150 -- Initialized_By_Aliased_BIP_Func_Call --
4151 ------------------------------------------
4153 function Initialized_By_Aliased_BIP_Func_Call
4154 (Trans_Id
: Entity_Id
) return Boolean
4156 Call
: Node_Id
:= Expression
(Parent
(Trans_Id
));
4159 -- Build-in-place calls usually appear in 'reference format
4161 if Nkind
(Call
) = N_Reference
then
4162 Call
:= Prefix
(Call
);
4165 if Is_Build_In_Place_Function_Call
(Call
) then
4167 Access_Nam
: Name_Id
:= No_Name
;
4168 Access_OK
: Boolean := False;
4170 Alloc_Nam
: Name_Id
:= No_Name
;
4171 Alloc_OK
: Boolean := False;
4173 Func_Id
: Entity_Id
;
4177 -- Examine all parameter associations of the function call
4179 Param
:= First
(Parameter_Associations
(Call
));
4180 while Present
(Param
) loop
4181 if Nkind
(Param
) = N_Parameter_Association
4182 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
4184 Actual
:= Explicit_Actual_Parameter
(Param
);
4185 Formal
:= Selector_Name
(Param
);
4187 -- Construct the names of formals BIPaccess and BIPalloc
4188 -- using the function name retrieved from an arbitrary
4191 if Access_Nam
= No_Name
4192 and then Alloc_Nam
= No_Name
4193 and then Present
(Entity
(Formal
))
4195 Func_Id
:= Scope
(Entity
(Formal
));
4198 New_External_Name
(Chars
(Func_Id
),
4199 BIP_Formal_Suffix
(BIP_Object_Access
));
4202 New_External_Name
(Chars
(Func_Id
),
4203 BIP_Formal_Suffix
(BIP_Alloc_Form
));
4206 -- A match for BIPaccess => Temp has been found
4208 if Chars
(Formal
) = Access_Nam
4209 and then Nkind
(Actual
) /= N_Null
4214 -- A match for BIPalloc => 1 has been found
4216 if Chars
(Formal
) = Alloc_Nam
4217 and then Nkind
(Actual
) = N_Integer_Literal
4218 and then Intval
(Actual
) = Uint_1
4227 return Access_OK
and Alloc_OK
;
4232 end Initialized_By_Aliased_BIP_Func_Call
;
4239 (Trans_Id
: Entity_Id
;
4240 First_Stmt
: Node_Id
) return Boolean
4242 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
;
4243 -- Given an object renaming declaration, retrieve the entity of the
4244 -- renamed name. Return Empty if the renamed name is anything other
4245 -- than a variable or a constant.
4247 -------------------------
4248 -- Find_Renamed_Object --
4249 -------------------------
4251 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
is
4252 Ren_Obj
: Node_Id
:= Empty
;
4254 function Find_Object
(N
: Node_Id
) return Traverse_Result
;
4255 -- Try to detect an object which is either a constant or a
4262 function Find_Object
(N
: Node_Id
) return Traverse_Result
is
4264 -- Stop the search once a constant or a variable has been
4267 if Nkind
(N
) = N_Identifier
4268 and then Present
(Entity
(N
))
4269 and then Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
4271 Ren_Obj
:= Entity
(N
);
4278 procedure Search
is new Traverse_Proc
(Find_Object
);
4282 Typ
: constant Entity_Id
:= Etype
(Defining_Identifier
(Ren_Decl
));
4284 -- Start of processing for Find_Renamed_Object
4287 -- Actions related to dispatching calls may appear as renamings of
4288 -- tags. Do not process this type of renaming because it does not
4289 -- use the actual value of the object.
4291 if not Is_RTE
(Typ
, RE_Tag_Ptr
) then
4292 Search
(Name
(Ren_Decl
));
4296 end Find_Renamed_Object
;
4301 Ren_Obj
: Entity_Id
;
4304 -- Start of processing for Is_Aliased
4308 while Present
(Stmt
) loop
4309 if Nkind
(Stmt
) = N_Object_Declaration
then
4310 Expr
:= Expression
(Stmt
);
4313 and then Nkind
(Expr
) = N_Reference
4314 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4315 and then Entity
(Prefix
(Expr
)) = Trans_Id
4320 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
then
4321 Ren_Obj
:= Find_Renamed_Object
(Stmt
);
4323 if Present
(Ren_Obj
) and then Ren_Obj
= Trans_Id
then
4338 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean is
4339 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4342 Is_Access_Type
(Etype
(Trans_Id
))
4343 and then Present
(Expr
)
4344 and then Nkind
(Expr
) = N_Allocator
;
4347 ---------------------------
4348 -- Is_Iterated_Container --
4349 ---------------------------
4351 function Is_Iterated_Container
4352 (Trans_Id
: Entity_Id
;
4353 First_Stmt
: Node_Id
) return Boolean
4363 -- It is not possible to iterate over containers in non-Ada 2012 code
4365 if Ada_Version
< Ada_2012
then
4369 Typ
:= Etype
(Trans_Id
);
4371 -- Handle access type created for secondary stack use
4373 if Is_Access_Type
(Typ
) then
4374 Typ
:= Designated_Type
(Typ
);
4377 -- Look for aspect Default_Iterator
4379 if Has_Aspects
(Parent
(Typ
)) then
4380 Aspect
:= Find_Value_Of_Aspect
(Typ
, Aspect_Default_Iterator
);
4382 if Present
(Aspect
) then
4383 Iter
:= Entity
(Aspect
);
4385 -- Examine the statements following the container object and
4386 -- look for a call to the default iterate routine where the
4387 -- first parameter is the transient. Such a call appears as:
4389 -- It : Access_To_CW_Iterator :=
4390 -- Iterate (Tran_Id.all, ...)'reference;
4393 while Present
(Stmt
) loop
4395 -- Detect an object declaration which is initialized by a
4396 -- secondary stack function call.
4398 if Nkind
(Stmt
) = N_Object_Declaration
4399 and then Present
(Expression
(Stmt
))
4400 and then Nkind
(Expression
(Stmt
)) = N_Reference
4401 and then Nkind
(Prefix
(Expression
(Stmt
))) =
4404 Call
:= Prefix
(Expression
(Stmt
));
4406 -- The call must invoke the default iterate routine of
4407 -- the container and the transient object must appear as
4408 -- the first actual parameter. Skip any calls whose names
4409 -- are not entities.
4411 if Is_Entity_Name
(Name
(Call
))
4412 and then Entity
(Name
(Call
)) = Iter
4413 and then Present
(Parameter_Associations
(Call
))
4415 Param
:= First
(Parameter_Associations
(Call
));
4417 if Nkind
(Param
) = N_Explicit_Dereference
4418 and then Entity
(Prefix
(Param
)) = Trans_Id
4431 end Is_Iterated_Container
;
4433 -- Start of processing for Is_Finalizable_Transient
4436 -- Handle access types
4438 if Is_Access_Type
(Desig
) then
4439 Desig
:= Available_View
(Designated_Type
(Desig
));
4443 Ekind_In
(Obj_Id
, E_Constant
, E_Variable
)
4444 and then Needs_Finalization
(Desig
)
4445 and then Requires_Transient_Scope
(Desig
)
4446 and then Nkind
(Rel_Node
) /= N_Simple_Return_Statement
4448 -- Do not consider renamed or 'reference-d transient objects because
4449 -- the act of renaming extends the object's lifetime.
4451 and then not Is_Aliased
(Obj_Id
, Decl
)
4453 -- Do not consider transient objects allocated on the heap since
4454 -- they are attached to a finalization master.
4456 and then not Is_Allocated
(Obj_Id
)
4458 -- If the transient object is a pointer, check that it is not
4459 -- initialized by a function which returns a pointer or acts as a
4460 -- renaming of another pointer.
4463 (not Is_Access_Type
(Obj_Typ
)
4464 or else not Initialized_By_Access
(Obj_Id
))
4466 -- Do not consider transient objects which act as indirect aliases
4467 -- of build-in-place function results.
4469 and then not Initialized_By_Aliased_BIP_Func_Call
(Obj_Id
)
4471 -- Do not consider conversions of tags to class-wide types
4473 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
4475 -- Do not consider containers in the context of iterator loops. Such
4476 -- transient objects must exist for as long as the loop is around,
4477 -- otherwise any operation carried out by the iterator will fail.
4479 and then not Is_Iterated_Container
(Obj_Id
, Decl
);
4480 end Is_Finalizable_Transient
;
4482 ---------------------------------
4483 -- Is_Fully_Repped_Tagged_Type --
4484 ---------------------------------
4486 function Is_Fully_Repped_Tagged_Type
(T
: Entity_Id
) return Boolean is
4487 U
: constant Entity_Id
:= Underlying_Type
(T
);
4491 if No
(U
) or else not Is_Tagged_Type
(U
) then
4493 elsif Has_Discriminants
(U
) then
4495 elsif not Has_Specified_Layout
(U
) then
4499 -- Here we have a tagged type, see if it has any unlayed out fields
4500 -- other than a possible tag and parent fields. If so, we return False.
4502 Comp
:= First_Component
(U
);
4503 while Present
(Comp
) loop
4504 if not Is_Tag
(Comp
)
4505 and then Chars
(Comp
) /= Name_uParent
4506 and then No
(Component_Clause
(Comp
))
4510 Next_Component
(Comp
);
4514 -- All components are layed out
4517 end Is_Fully_Repped_Tagged_Type
;
4519 ----------------------------------
4520 -- Is_Library_Level_Tagged_Type --
4521 ----------------------------------
4523 function Is_Library_Level_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
4525 return Is_Tagged_Type
(Typ
) and then Is_Library_Level_Entity
(Typ
);
4526 end Is_Library_Level_Tagged_Type
;
4528 --------------------------
4529 -- Is_Non_BIP_Func_Call --
4530 --------------------------
4532 function Is_Non_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
4534 -- The expected call is of the format
4536 -- Func_Call'reference
4539 Nkind
(Expr
) = N_Reference
4540 and then Nkind
(Prefix
(Expr
)) = N_Function_Call
4541 and then not Is_Build_In_Place_Function_Call
(Prefix
(Expr
));
4542 end Is_Non_BIP_Func_Call
;
4544 ----------------------------------
4545 -- Is_Possibly_Unaligned_Object --
4546 ----------------------------------
4548 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean is
4549 T
: constant Entity_Id
:= Etype
(N
);
4552 -- If renamed object, apply test to underlying object
4554 if Is_Entity_Name
(N
)
4555 and then Is_Object
(Entity
(N
))
4556 and then Present
(Renamed_Object
(Entity
(N
)))
4558 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(N
)));
4561 -- Tagged and controlled types and aliased types are always aligned, as
4562 -- are concurrent types.
4565 or else Has_Controlled_Component
(T
)
4566 or else Is_Concurrent_Type
(T
)
4567 or else Is_Tagged_Type
(T
)
4568 or else Is_Controlled
(T
)
4573 -- If this is an element of a packed array, may be unaligned
4575 if Is_Ref_To_Bit_Packed_Array
(N
) then
4579 -- Case of indexed component reference: test whether prefix is unaligned
4581 if Nkind
(N
) = N_Indexed_Component
then
4582 return Is_Possibly_Unaligned_Object
(Prefix
(N
));
4584 -- Case of selected component reference
4586 elsif Nkind
(N
) = N_Selected_Component
then
4588 P
: constant Node_Id
:= Prefix
(N
);
4589 C
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
4594 -- If component reference is for an array with non-static bounds,
4595 -- then it is always aligned: we can only process unaligned arrays
4596 -- with static bounds (more precisely compile time known bounds).
4598 if Is_Array_Type
(T
)
4599 and then not Compile_Time_Known_Bounds
(T
)
4604 -- If component is aliased, it is definitely properly aligned
4606 if Is_Aliased
(C
) then
4610 -- If component is for a type implemented as a scalar, and the
4611 -- record is packed, and the component is other than the first
4612 -- component of the record, then the component may be unaligned.
4614 if Is_Packed
(Etype
(P
))
4615 and then Represented_As_Scalar
(Etype
(C
))
4616 and then First_Entity
(Scope
(C
)) /= C
4621 -- Compute maximum possible alignment for T
4623 -- If alignment is known, then that settles things
4625 if Known_Alignment
(T
) then
4626 M
:= UI_To_Int
(Alignment
(T
));
4628 -- If alignment is not known, tentatively set max alignment
4631 M
:= Ttypes
.Maximum_Alignment
;
4633 -- We can reduce this if the Esize is known since the default
4634 -- alignment will never be more than the smallest power of 2
4635 -- that does not exceed this Esize value.
4637 if Known_Esize
(T
) then
4638 S
:= UI_To_Int
(Esize
(T
));
4640 while (M
/ 2) >= S
loop
4646 -- The following code is historical, it used to be present but it
4647 -- is too cautious, because the front-end does not know the proper
4648 -- default alignments for the target. Also, if the alignment is
4649 -- not known, the front end can't know in any case! If a copy is
4650 -- needed, the back-end will take care of it. This whole section
4651 -- including this comment can be removed later ???
4653 -- If the component reference is for a record that has a specified
4654 -- alignment, and we either know it is too small, or cannot tell,
4655 -- then the component may be unaligned.
4657 -- What is the following commented out code ???
4659 -- if Known_Alignment (Etype (P))
4660 -- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
4661 -- and then M > Alignment (Etype (P))
4666 -- Case of component clause present which may specify an
4667 -- unaligned position.
4669 if Present
(Component_Clause
(C
)) then
4671 -- Otherwise we can do a test to make sure that the actual
4672 -- start position in the record, and the length, are both
4673 -- consistent with the required alignment. If not, we know
4674 -- that we are unaligned.
4677 Align_In_Bits
: constant Nat
:= M
* System_Storage_Unit
;
4679 if Component_Bit_Offset
(C
) mod Align_In_Bits
/= 0
4680 or else Esize
(C
) mod Align_In_Bits
/= 0
4687 -- Otherwise, for a component reference, test prefix
4689 return Is_Possibly_Unaligned_Object
(P
);
4692 -- If not a component reference, must be aligned
4697 end Is_Possibly_Unaligned_Object
;
4699 ---------------------------------
4700 -- Is_Possibly_Unaligned_Slice --
4701 ---------------------------------
4703 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean is
4705 -- Go to renamed object
4707 if Is_Entity_Name
(N
)
4708 and then Is_Object
(Entity
(N
))
4709 and then Present
(Renamed_Object
(Entity
(N
)))
4711 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(N
)));
4714 -- The reference must be a slice
4716 if Nkind
(N
) /= N_Slice
then
4720 -- Always assume the worst for a nested record component with a
4721 -- component clause, which gigi/gcc does not appear to handle well.
4722 -- It is not clear why this special test is needed at all ???
4724 if Nkind
(Prefix
(N
)) = N_Selected_Component
4725 and then Nkind
(Prefix
(Prefix
(N
))) = N_Selected_Component
4727 Present
(Component_Clause
(Entity
(Selector_Name
(Prefix
(N
)))))
4732 -- We only need to worry if the target has strict alignment
4734 if not Target_Strict_Alignment
then
4738 -- If it is a slice, then look at the array type being sliced
4741 Sarr
: constant Node_Id
:= Prefix
(N
);
4742 -- Prefix of the slice, i.e. the array being sliced
4744 Styp
: constant Entity_Id
:= Etype
(Prefix
(N
));
4745 -- Type of the array being sliced
4751 -- The problems arise if the array object that is being sliced
4752 -- is a component of a record or array, and we cannot guarantee
4753 -- the alignment of the array within its containing object.
4755 -- To investigate this, we look at successive prefixes to see
4756 -- if we have a worrisome indexed or selected component.
4760 -- Case of array is part of an indexed component reference
4762 if Nkind
(Pref
) = N_Indexed_Component
then
4763 Ptyp
:= Etype
(Prefix
(Pref
));
4765 -- The only problematic case is when the array is packed, in
4766 -- which case we really know nothing about the alignment of
4767 -- individual components.
4769 if Is_Bit_Packed_Array
(Ptyp
) then
4773 -- Case of array is part of a selected component reference
4775 elsif Nkind
(Pref
) = N_Selected_Component
then
4776 Ptyp
:= Etype
(Prefix
(Pref
));
4778 -- We are definitely in trouble if the record in question
4779 -- has an alignment, and either we know this alignment is
4780 -- inconsistent with the alignment of the slice, or we don't
4781 -- know what the alignment of the slice should be.
4783 if Known_Alignment
(Ptyp
)
4784 and then (Unknown_Alignment
(Styp
)
4785 or else Alignment
(Styp
) > Alignment
(Ptyp
))
4790 -- We are in potential trouble if the record type is packed.
4791 -- We could special case when we know that the array is the
4792 -- first component, but that's not such a simple case ???
4794 if Is_Packed
(Ptyp
) then
4798 -- We are in trouble if there is a component clause, and
4799 -- either we do not know the alignment of the slice, or
4800 -- the alignment of the slice is inconsistent with the
4801 -- bit position specified by the component clause.
4804 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
4806 if Present
(Component_Clause
(Field
))
4808 (Unknown_Alignment
(Styp
)
4810 (Component_Bit_Offset
(Field
) mod
4811 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
4817 -- For cases other than selected or indexed components we know we
4818 -- are OK, since no issues arise over alignment.
4824 -- We processed an indexed component or selected component
4825 -- reference that looked safe, so keep checking prefixes.
4827 Pref
:= Prefix
(Pref
);
4830 end Is_Possibly_Unaligned_Slice
;
4832 -------------------------------
4833 -- Is_Related_To_Func_Return --
4834 -------------------------------
4836 function Is_Related_To_Func_Return
(Id
: Entity_Id
) return Boolean is
4837 Expr
: constant Node_Id
:= Related_Expression
(Id
);
4841 and then Nkind
(Expr
) = N_Explicit_Dereference
4842 and then Nkind
(Parent
(Expr
)) = N_Simple_Return_Statement
;
4843 end Is_Related_To_Func_Return
;
4845 --------------------------------
4846 -- Is_Ref_To_Bit_Packed_Array --
4847 --------------------------------
4849 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean is
4854 if Is_Entity_Name
(N
)
4855 and then Is_Object
(Entity
(N
))
4856 and then Present
(Renamed_Object
(Entity
(N
)))
4858 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(N
)));
4861 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
4862 if Is_Bit_Packed_Array
(Etype
(Prefix
(N
))) then
4865 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(N
));
4868 if Result
and then Nkind
(N
) = N_Indexed_Component
then
4869 Expr
:= First
(Expressions
(N
));
4870 while Present
(Expr
) loop
4871 Force_Evaluation
(Expr
);
4881 end Is_Ref_To_Bit_Packed_Array
;
4883 --------------------------------
4884 -- Is_Ref_To_Bit_Packed_Slice --
4885 --------------------------------
4887 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean is
4889 if Nkind
(N
) = N_Type_Conversion
then
4890 return Is_Ref_To_Bit_Packed_Slice
(Expression
(N
));
4892 elsif Is_Entity_Name
(N
)
4893 and then Is_Object
(Entity
(N
))
4894 and then Present
(Renamed_Object
(Entity
(N
)))
4896 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(N
)));
4898 elsif Nkind
(N
) = N_Slice
4899 and then Is_Bit_Packed_Array
(Etype
(Prefix
(N
)))
4903 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
4904 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(N
));
4909 end Is_Ref_To_Bit_Packed_Slice
;
4911 -----------------------
4912 -- Is_Renamed_Object --
4913 -----------------------
4915 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
4916 Pnod
: constant Node_Id
:= Parent
(N
);
4917 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
4919 if Kind
= N_Object_Renaming_Declaration
then
4921 elsif Nkind_In
(Kind
, N_Indexed_Component
, N_Selected_Component
) then
4922 return Is_Renamed_Object
(Pnod
);
4926 end Is_Renamed_Object
;
4928 --------------------------------------
4929 -- Is_Secondary_Stack_BIP_Func_Call --
4930 --------------------------------------
4932 function Is_Secondary_Stack_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
4933 Call
: Node_Id
:= Expr
;
4936 -- Build-in-place calls usually appear in 'reference format. Note that
4937 -- the accessibility check machinery may add an extra 'reference due to
4938 -- side effect removal.
4940 while Nkind
(Call
) = N_Reference
loop
4941 Call
:= Prefix
(Call
);
4944 if Nkind_In
(Call
, N_Qualified_Expression
,
4945 N_Unchecked_Type_Conversion
)
4947 Call
:= Expression
(Call
);
4950 if Is_Build_In_Place_Function_Call
(Call
) then
4952 Access_Nam
: Name_Id
:= No_Name
;
4958 -- Examine all parameter associations of the function call
4960 Param
:= First
(Parameter_Associations
(Call
));
4961 while Present
(Param
) loop
4962 if Nkind
(Param
) = N_Parameter_Association
4963 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
4965 Formal
:= Selector_Name
(Param
);
4966 Actual
:= Explicit_Actual_Parameter
(Param
);
4968 -- Construct the name of formal BIPalloc. It is much easier
4969 -- to extract the name of the function using an arbitrary
4970 -- formal's scope rather than the Name field of Call.
4972 if Access_Nam
= No_Name
4973 and then Present
(Entity
(Formal
))
4977 (Chars
(Scope
(Entity
(Formal
))),
4978 BIP_Formal_Suffix
(BIP_Alloc_Form
));
4981 -- A match for BIPalloc => 2 has been found
4983 if Chars
(Formal
) = Access_Nam
4984 and then Nkind
(Actual
) = N_Integer_Literal
4985 and then Intval
(Actual
) = Uint_2
4997 end Is_Secondary_Stack_BIP_Func_Call
;
4999 -------------------------------------
5000 -- Is_Tag_To_Class_Wide_Conversion --
5001 -------------------------------------
5003 function Is_Tag_To_Class_Wide_Conversion
5004 (Obj_Id
: Entity_Id
) return Boolean
5006 Expr
: constant Node_Id
:= Expression
(Parent
(Obj_Id
));
5010 Is_Class_Wide_Type
(Etype
(Obj_Id
))
5011 and then Present
(Expr
)
5012 and then Nkind
(Expr
) = N_Unchecked_Type_Conversion
5013 and then Etype
(Expression
(Expr
)) = RTE
(RE_Tag
);
5014 end Is_Tag_To_Class_Wide_Conversion
;
5016 ----------------------------
5017 -- Is_Untagged_Derivation --
5018 ----------------------------
5020 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
5022 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
5024 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
5025 and then not Is_Tagged_Type
(Full_View
(T
))
5026 and then Is_Derived_Type
(Full_View
(T
))
5027 and then Etype
(Full_View
(T
)) /= T
);
5028 end Is_Untagged_Derivation
;
5030 ---------------------------
5031 -- Is_Volatile_Reference --
5032 ---------------------------
5034 function Is_Volatile_Reference
(N
: Node_Id
) return Boolean is
5036 if Nkind
(N
) in N_Has_Etype
5037 and then Present
(Etype
(N
))
5038 and then Treat_As_Volatile
(Etype
(N
))
5042 elsif Is_Entity_Name
(N
) then
5043 return Treat_As_Volatile
(Entity
(N
));
5045 elsif Nkind
(N
) = N_Slice
then
5046 return Is_Volatile_Reference
(Prefix
(N
));
5048 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5049 if (Is_Entity_Name
(Prefix
(N
))
5050 and then Has_Volatile_Components
(Entity
(Prefix
(N
))))
5051 or else (Present
(Etype
(Prefix
(N
)))
5052 and then Has_Volatile_Components
(Etype
(Prefix
(N
))))
5056 return Is_Volatile_Reference
(Prefix
(N
));
5062 end Is_Volatile_Reference
;
5064 --------------------------
5065 -- Is_VM_By_Copy_Actual --
5066 --------------------------
5068 function Is_VM_By_Copy_Actual
(N
: Node_Id
) return Boolean is
5070 return VM_Target
/= No_VM
5071 and then (Nkind
(N
) = N_Slice
5073 (Nkind
(N
) = N_Identifier
5074 and then Present
(Renamed_Object
(Entity
(N
)))
5075 and then Nkind
(Renamed_Object
(Entity
(N
))) =
5077 end Is_VM_By_Copy_Actual
;
5079 --------------------
5080 -- Kill_Dead_Code --
5081 --------------------
5083 procedure Kill_Dead_Code
(N
: Node_Id
; Warn
: Boolean := False) is
5084 W
: Boolean := Warn
;
5085 -- Set False if warnings suppressed
5089 Remove_Warning_Messages
(N
);
5091 -- Generate warning if appropriate
5095 -- We suppress the warning if this code is under control of an
5096 -- if statement, whose condition is a simple identifier, and
5097 -- either we are in an instance, or warnings off is set for this
5098 -- identifier. The reason for killing it in the instance case is
5099 -- that it is common and reasonable for code to be deleted in
5100 -- instances for various reasons.
5102 if Nkind
(Parent
(N
)) = N_If_Statement
then
5104 C
: constant Node_Id
:= Condition
(Parent
(N
));
5106 if Nkind
(C
) = N_Identifier
5109 or else (Present
(Entity
(C
))
5110 and then Has_Warnings_Off
(Entity
(C
))))
5117 -- Generate warning if not suppressed
5121 ("?t?this code can never be executed and has been deleted!",
5126 -- Recurse into block statements and bodies to process declarations
5129 if Nkind
(N
) = N_Block_Statement
5130 or else Nkind
(N
) = N_Subprogram_Body
5131 or else Nkind
(N
) = N_Package_Body
5133 Kill_Dead_Code
(Declarations
(N
), False);
5134 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
5136 if Nkind
(N
) = N_Subprogram_Body
then
5137 Set_Is_Eliminated
(Defining_Entity
(N
));
5140 elsif Nkind
(N
) = N_Package_Declaration
then
5141 Kill_Dead_Code
(Visible_Declarations
(Specification
(N
)));
5142 Kill_Dead_Code
(Private_Declarations
(Specification
(N
)));
5144 -- ??? After this point, Delete_Tree has been called on all
5145 -- declarations in Specification (N), so references to entities
5146 -- therein look suspicious.
5149 E
: Entity_Id
:= First_Entity
(Defining_Entity
(N
));
5151 while Present
(E
) loop
5152 if Ekind
(E
) = E_Operator
then
5153 Set_Is_Eliminated
(E
);
5160 -- Recurse into composite statement to kill individual statements in
5161 -- particular instantiations.
5163 elsif Nkind
(N
) = N_If_Statement
then
5164 Kill_Dead_Code
(Then_Statements
(N
));
5165 Kill_Dead_Code
(Elsif_Parts
(N
));
5166 Kill_Dead_Code
(Else_Statements
(N
));
5168 elsif Nkind
(N
) = N_Loop_Statement
then
5169 Kill_Dead_Code
(Statements
(N
));
5171 elsif Nkind
(N
) = N_Case_Statement
then
5175 Alt
:= First
(Alternatives
(N
));
5176 while Present
(Alt
) loop
5177 Kill_Dead_Code
(Statements
(Alt
));
5182 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
5183 Kill_Dead_Code
(Statements
(N
));
5185 -- Deal with dead instances caused by deleting instantiations
5187 elsif Nkind
(N
) in N_Generic_Instantiation
then
5188 Remove_Dead_Instance
(N
);
5193 -- Case where argument is a list of nodes to be killed
5195 procedure Kill_Dead_Code
(L
: List_Id
; Warn
: Boolean := False) is
5200 if Is_Non_Empty_List
(L
) then
5202 while Present
(N
) loop
5203 Kill_Dead_Code
(N
, W
);
5210 ------------------------
5211 -- Known_Non_Negative --
5212 ------------------------
5214 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
5216 if Is_OK_Static_Expression
(Opnd
) and then Expr_Value
(Opnd
) >= 0 then
5221 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
5224 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
5227 end Known_Non_Negative
;
5229 --------------------
5230 -- Known_Non_Null --
5231 --------------------
5233 function Known_Non_Null
(N
: Node_Id
) return Boolean is
5235 -- Checks for case where N is an entity reference
5237 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5239 E
: constant Entity_Id
:= Entity
(N
);
5244 -- First check if we are in decisive conditional
5246 Get_Current_Value_Condition
(N
, Op
, Val
);
5248 if Known_Null
(Val
) then
5249 if Op
= N_Op_Eq
then
5251 elsif Op
= N_Op_Ne
then
5256 -- If OK to do replacement, test Is_Known_Non_Null flag
5258 if OK_To_Do_Constant_Replacement
(E
) then
5259 return Is_Known_Non_Null
(E
);
5261 -- Otherwise if not safe to do replacement, then say so
5268 -- True if access attribute
5270 elsif Nkind
(N
) = N_Attribute_Reference
5271 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
5272 Name_Unchecked_Access
,
5273 Name_Unrestricted_Access
)
5277 -- True if allocator
5279 elsif Nkind
(N
) = N_Allocator
then
5282 -- For a conversion, true if expression is known non-null
5284 elsif Nkind
(N
) = N_Type_Conversion
then
5285 return Known_Non_Null
(Expression
(N
));
5287 -- Above are all cases where the value could be determined to be
5288 -- non-null. In all other cases, we don't know, so return False.
5299 function Known_Null
(N
: Node_Id
) return Boolean is
5301 -- Checks for case where N is an entity reference
5303 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5305 E
: constant Entity_Id
:= Entity
(N
);
5310 -- Constant null value is for sure null
5312 if Ekind
(E
) = E_Constant
5313 and then Known_Null
(Constant_Value
(E
))
5318 -- First check if we are in decisive conditional
5320 Get_Current_Value_Condition
(N
, Op
, Val
);
5322 if Known_Null
(Val
) then
5323 if Op
= N_Op_Eq
then
5325 elsif Op
= N_Op_Ne
then
5330 -- If OK to do replacement, test Is_Known_Null flag
5332 if OK_To_Do_Constant_Replacement
(E
) then
5333 return Is_Known_Null
(E
);
5335 -- Otherwise if not safe to do replacement, then say so
5342 -- True if explicit reference to null
5344 elsif Nkind
(N
) = N_Null
then
5347 -- For a conversion, true if expression is known null
5349 elsif Nkind
(N
) = N_Type_Conversion
then
5350 return Known_Null
(Expression
(N
));
5352 -- Above are all cases where the value could be determined to be null.
5353 -- In all other cases, we don't know, so return False.
5360 -----------------------------
5361 -- Make_CW_Equivalent_Type --
5362 -----------------------------
5364 -- Create a record type used as an equivalent of any member of the class
5365 -- which takes its size from exp.
5367 -- Generate the following code:
5369 -- type Equiv_T is record
5370 -- _parent : T (List of discriminant constraints taken from Exp);
5371 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
5374 -- ??? Note that this type does not guarantee same alignment as all
5377 function Make_CW_Equivalent_Type
5379 E
: Node_Id
) return Entity_Id
5381 Loc
: constant Source_Ptr
:= Sloc
(E
);
5382 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
5383 List_Def
: constant List_Id
:= Empty_List
;
5384 Comp_List
: constant List_Id
:= New_List
;
5385 Equiv_Type
: Entity_Id
;
5386 Range_Type
: Entity_Id
;
5387 Str_Type
: Entity_Id
;
5388 Constr_Root
: Entity_Id
;
5392 -- If the root type is already constrained, there are no discriminants
5393 -- in the expression.
5395 if not Has_Discriminants
(Root_Typ
)
5396 or else Is_Constrained
(Root_Typ
)
5398 Constr_Root
:= Root_Typ
;
5400 Constr_Root
:= Make_Temporary
(Loc
, 'R');
5402 -- subtype cstr__n is T (List of discr constraints taken from Exp)
5404 Append_To
(List_Def
,
5405 Make_Subtype_Declaration
(Loc
,
5406 Defining_Identifier
=> Constr_Root
,
5407 Subtype_Indication
=> Make_Subtype_From_Expr
(E
, Root_Typ
)));
5410 -- Generate the range subtype declaration
5412 Range_Type
:= Make_Temporary
(Loc
, 'G');
5414 if not Is_Interface
(Root_Typ
) then
5416 -- subtype rg__xx is
5417 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
5420 Make_Op_Subtract
(Loc
,
5422 Make_Attribute_Reference
(Loc
,
5424 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
5425 Attribute_Name
=> Name_Size
),
5427 Make_Attribute_Reference
(Loc
,
5428 Prefix
=> New_Reference_To
(Constr_Root
, Loc
),
5429 Attribute_Name
=> Name_Object_Size
));
5431 -- subtype rg__xx is
5432 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
5435 Make_Attribute_Reference
(Loc
,
5437 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
5438 Attribute_Name
=> Name_Size
);
5441 Set_Paren_Count
(Sizexpr
, 1);
5443 Append_To
(List_Def
,
5444 Make_Subtype_Declaration
(Loc
,
5445 Defining_Identifier
=> Range_Type
,
5446 Subtype_Indication
=>
5447 Make_Subtype_Indication
(Loc
,
5448 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
5449 Constraint
=> Make_Range_Constraint
(Loc
,
5452 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
5454 Make_Op_Divide
(Loc
,
5455 Left_Opnd
=> Sizexpr
,
5456 Right_Opnd
=> Make_Integer_Literal
(Loc
,
5457 Intval
=> System_Storage_Unit
)))))));
5459 -- subtype str__nn is Storage_Array (rg__x);
5461 Str_Type
:= Make_Temporary
(Loc
, 'S');
5462 Append_To
(List_Def
,
5463 Make_Subtype_Declaration
(Loc
,
5464 Defining_Identifier
=> Str_Type
,
5465 Subtype_Indication
=>
5466 Make_Subtype_Indication
(Loc
,
5467 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Array
), Loc
),
5469 Make_Index_Or_Discriminant_Constraint
(Loc
,
5471 New_List
(New_Reference_To
(Range_Type
, Loc
))))));
5473 -- type Equiv_T is record
5474 -- [ _parent : Tnn; ]
5478 Equiv_Type
:= Make_Temporary
(Loc
, 'T');
5479 Set_Ekind
(Equiv_Type
, E_Record_Type
);
5480 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
5482 -- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
5483 -- treatment for this type. In particular, even though _parent's type
5484 -- is a controlled type or contains controlled components, we do not
5485 -- want to set Has_Controlled_Component on it to avoid making it gain
5486 -- an unwanted _controller component.
5488 Set_Is_Class_Wide_Equivalent_Type
(Equiv_Type
);
5490 if not Is_Interface
(Root_Typ
) then
5491 Append_To
(Comp_List
,
5492 Make_Component_Declaration
(Loc
,
5493 Defining_Identifier
=>
5494 Make_Defining_Identifier
(Loc
, Name_uParent
),
5495 Component_Definition
=>
5496 Make_Component_Definition
(Loc
,
5497 Aliased_Present
=> False,
5498 Subtype_Indication
=> New_Reference_To
(Constr_Root
, Loc
))));
5501 Append_To
(Comp_List
,
5502 Make_Component_Declaration
(Loc
,
5503 Defining_Identifier
=> Make_Temporary
(Loc
, 'C'),
5504 Component_Definition
=>
5505 Make_Component_Definition
(Loc
,
5506 Aliased_Present
=> False,
5507 Subtype_Indication
=> New_Reference_To
(Str_Type
, Loc
))));
5509 Append_To
(List_Def
,
5510 Make_Full_Type_Declaration
(Loc
,
5511 Defining_Identifier
=> Equiv_Type
,
5513 Make_Record_Definition
(Loc
,
5515 Make_Component_List
(Loc
,
5516 Component_Items
=> Comp_List
,
5517 Variant_Part
=> Empty
))));
5519 -- Suppress all checks during the analysis of the expanded code to avoid
5520 -- the generation of spurious warnings under ZFP run-time.
5522 Insert_Actions
(E
, List_Def
, Suppress
=> All_Checks
);
5524 end Make_CW_Equivalent_Type
;
5526 -------------------------
5527 -- Make_Invariant_Call --
5528 -------------------------
5530 function Make_Invariant_Call
(Expr
: Node_Id
) return Node_Id
is
5531 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5535 Typ
:= Etype
(Expr
);
5537 -- Subtypes may be subject to invariants coming from their respective
5540 if Ekind_In
(Typ
, E_Array_Subtype
,
5544 Typ
:= Base_Type
(Typ
);
5548 (Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)));
5551 Make_Procedure_Call_Statement
(Loc
,
5553 New_Occurrence_Of
(Invariant_Procedure
(Typ
), Loc
),
5554 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
5555 end Make_Invariant_Call
;
5557 ------------------------
5558 -- Make_Literal_Range --
5559 ------------------------
5561 function Make_Literal_Range
5563 Literal_Typ
: Entity_Id
) return Node_Id
5565 Lo
: constant Node_Id
:=
5566 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
5567 Index
: constant Entity_Id
:= Etype
(Lo
);
5570 Length_Expr
: constant Node_Id
:=
5571 Make_Op_Subtract
(Loc
,
5573 Make_Integer_Literal
(Loc
,
5574 Intval
=> String_Literal_Length
(Literal_Typ
)),
5576 Make_Integer_Literal
(Loc
, 1));
5579 Set_Analyzed
(Lo
, False);
5581 if Is_Integer_Type
(Index
) then
5584 Left_Opnd
=> New_Copy_Tree
(Lo
),
5585 Right_Opnd
=> Length_Expr
);
5588 Make_Attribute_Reference
(Loc
,
5589 Attribute_Name
=> Name_Val
,
5590 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
5591 Expressions
=> New_List
(
5594 Make_Attribute_Reference
(Loc
,
5595 Attribute_Name
=> Name_Pos
,
5596 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
5597 Expressions
=> New_List
(New_Copy_Tree
(Lo
))),
5598 Right_Opnd
=> Length_Expr
)));
5605 end Make_Literal_Range
;
5607 --------------------------
5608 -- Make_Non_Empty_Check --
5609 --------------------------
5611 function Make_Non_Empty_Check
5613 N
: Node_Id
) return Node_Id
5619 Make_Attribute_Reference
(Loc
,
5620 Attribute_Name
=> Name_Length
,
5621 Prefix
=> Duplicate_Subexpr_No_Checks
(N
, Name_Req
=> True)),
5623 Make_Integer_Literal
(Loc
, 0));
5624 end Make_Non_Empty_Check
;
5626 -------------------------
5627 -- Make_Predicate_Call --
5628 -------------------------
5630 function Make_Predicate_Call
5633 Mem
: Boolean := False) return Node_Id
5635 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5638 pragma Assert
(Present
(Predicate_Function
(Typ
)));
5640 -- Call special membership version if requested and available
5644 PFM
: constant Entity_Id
:= Predicate_Function_M
(Typ
);
5646 if Present
(PFM
) then
5648 Make_Function_Call
(Loc
,
5649 Name
=> New_Occurrence_Of
(PFM
, Loc
),
5650 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
5655 -- Case of calling normal predicate function
5658 Make_Function_Call
(Loc
,
5660 New_Occurrence_Of
(Predicate_Function
(Typ
), Loc
),
5661 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
5662 end Make_Predicate_Call
;
5664 --------------------------
5665 -- Make_Predicate_Check --
5666 --------------------------
5668 function Make_Predicate_Check
5670 Expr
: Node_Id
) return Node_Id
5672 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5676 -- If predicate checks are suppressed, then return a null statement.
5677 -- For this call, we check only the scope setting. If the caller wants
5678 -- to check a specific entity's setting, they must do it manually.
5680 if Predicate_Checks_Suppressed
(Empty
) then
5681 return Make_Null_Statement
(Loc
);
5684 -- Compute proper name to use, we need to get this right so that the
5685 -- right set of check policies apply to the Check pragma we are making.
5687 if Has_Dynamic_Predicate_Aspect
(Typ
) then
5688 Nam
:= Name_Dynamic_Predicate
;
5689 elsif Has_Static_Predicate_Aspect
(Typ
) then
5690 Nam
:= Name_Static_Predicate
;
5692 Nam
:= Name_Predicate
;
5697 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Check
),
5698 Pragma_Argument_Associations
=> New_List
(
5699 Make_Pragma_Argument_Association
(Loc
,
5700 Expression
=> Make_Identifier
(Loc
, Nam
)),
5701 Make_Pragma_Argument_Association
(Loc
,
5702 Expression
=> Make_Predicate_Call
(Typ
, Expr
))));
5703 end Make_Predicate_Check
;
5705 ----------------------------
5706 -- Make_Subtype_From_Expr --
5707 ----------------------------
5709 -- 1. If Expr is an unconstrained array expression, creates
5710 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
5712 -- 2. If Expr is a unconstrained discriminated type expression, creates
5713 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
5715 -- 3. If Expr is class-wide, creates an implicit class wide subtype
5717 function Make_Subtype_From_Expr
5719 Unc_Typ
: Entity_Id
) return Node_Id
5721 Loc
: constant Source_Ptr
:= Sloc
(E
);
5722 List_Constr
: constant List_Id
:= New_List
;
5725 Full_Subtyp
: Entity_Id
;
5726 Priv_Subtyp
: Entity_Id
;
5731 if Is_Private_Type
(Unc_Typ
)
5732 and then Has_Unknown_Discriminants
(Unc_Typ
)
5734 -- Prepare the subtype completion, Go to base type to
5735 -- find underlying type, because the type may be a generic
5736 -- actual or an explicit subtype.
5738 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
5739 Full_Subtyp
:= Make_Temporary
(Loc
, 'C');
5741 Unchecked_Convert_To
(Utyp
, Duplicate_Subexpr_No_Checks
(E
));
5742 Set_Parent
(Full_Exp
, Parent
(E
));
5744 Priv_Subtyp
:= Make_Temporary
(Loc
, 'P');
5747 Make_Subtype_Declaration
(Loc
,
5748 Defining_Identifier
=> Full_Subtyp
,
5749 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
5751 -- Define the dummy private subtype
5753 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
5754 Set_Etype
(Priv_Subtyp
, Base_Type
(Unc_Typ
));
5755 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
5756 Set_Is_Constrained
(Priv_Subtyp
);
5757 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
5758 Set_Is_Itype
(Priv_Subtyp
);
5759 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
5761 if Is_Tagged_Type
(Priv_Subtyp
) then
5763 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
5764 Set_Direct_Primitive_Operations
(Priv_Subtyp
,
5765 Direct_Primitive_Operations
(Unc_Typ
));
5768 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
5770 return New_Reference_To
(Priv_Subtyp
, Loc
);
5772 elsif Is_Array_Type
(Unc_Typ
) then
5773 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
5774 Append_To
(List_Constr
,
5777 Make_Attribute_Reference
(Loc
,
5778 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
5779 Attribute_Name
=> Name_First
,
5780 Expressions
=> New_List
(
5781 Make_Integer_Literal
(Loc
, J
))),
5784 Make_Attribute_Reference
(Loc
,
5785 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
5786 Attribute_Name
=> Name_Last
,
5787 Expressions
=> New_List
(
5788 Make_Integer_Literal
(Loc
, J
)))));
5791 elsif Is_Class_Wide_Type
(Unc_Typ
) then
5793 CW_Subtype
: Entity_Id
;
5794 EQ_Typ
: Entity_Id
:= Empty
;
5797 -- A class-wide equivalent type is not needed when VM_Target
5798 -- because the VM back-ends handle the class-wide object
5799 -- initialization itself (and doesn't need or want the
5800 -- additional intermediate type to handle the assignment).
5802 if Expander_Active
and then Tagged_Type_Expansion
then
5804 -- If this is the class_wide type of a completion that is a
5805 -- record subtype, set the type of the class_wide type to be
5806 -- the full base type, for use in the expanded code for the
5807 -- equivalent type. Should this be done earlier when the
5808 -- completion is analyzed ???
5810 if Is_Private_Type
(Etype
(Unc_Typ
))
5812 Ekind
(Full_View
(Etype
(Unc_Typ
))) = E_Record_Subtype
5814 Set_Etype
(Unc_Typ
, Base_Type
(Full_View
(Etype
(Unc_Typ
))));
5817 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
5820 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
5821 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
5822 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
5824 return New_Occurrence_Of
(CW_Subtype
, Loc
);
5827 -- Indefinite record type with discriminants
5830 D
:= First_Discriminant
(Unc_Typ
);
5831 while Present
(D
) loop
5832 Append_To
(List_Constr
,
5833 Make_Selected_Component
(Loc
,
5834 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
5835 Selector_Name
=> New_Reference_To
(D
, Loc
)));
5837 Next_Discriminant
(D
);
5842 Make_Subtype_Indication
(Loc
,
5843 Subtype_Mark
=> New_Reference_To
(Unc_Typ
, Loc
),
5845 Make_Index_Or_Discriminant_Constraint
(Loc
,
5846 Constraints
=> List_Constr
));
5847 end Make_Subtype_From_Expr
;
5849 -----------------------------
5850 -- May_Generate_Large_Temp --
5851 -----------------------------
5853 -- At the current time, the only types that we return False for (i.e. where
5854 -- we decide we know they cannot generate large temps) are ones where we
5855 -- know the size is 256 bits or less at compile time, and we are still not
5856 -- doing a thorough job on arrays and records ???
5858 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
5860 if not Size_Known_At_Compile_Time
(Typ
) then
5863 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
5866 elsif Is_Array_Type
(Typ
) and then Present
(Packed_Array_Type
(Typ
)) then
5867 return May_Generate_Large_Temp
(Packed_Array_Type
(Typ
));
5869 -- We could do more here to find other small types ???
5874 end May_Generate_Large_Temp
;
5876 ------------------------
5877 -- Needs_Finalization --
5878 ------------------------
5880 function Needs_Finalization
(T
: Entity_Id
) return Boolean is
5881 function Has_Some_Controlled_Component
(Rec
: Entity_Id
) return Boolean;
5882 -- If type is not frozen yet, check explicitly among its components,
5883 -- because the Has_Controlled_Component flag is not necessarily set.
5885 -----------------------------------
5886 -- Has_Some_Controlled_Component --
5887 -----------------------------------
5889 function Has_Some_Controlled_Component
5890 (Rec
: Entity_Id
) return Boolean
5895 if Has_Controlled_Component
(Rec
) then
5898 elsif not Is_Frozen
(Rec
) then
5899 if Is_Record_Type
(Rec
) then
5900 Comp
:= First_Entity
(Rec
);
5902 while Present
(Comp
) loop
5903 if not Is_Type
(Comp
)
5904 and then Needs_Finalization
(Etype
(Comp
))
5914 elsif Is_Array_Type
(Rec
) then
5915 return Needs_Finalization
(Component_Type
(Rec
));
5918 return Has_Controlled_Component
(Rec
);
5923 end Has_Some_Controlled_Component
;
5925 -- Start of processing for Needs_Finalization
5928 -- Certain run-time configurations and targets do not provide support
5929 -- for controlled types.
5931 if Restriction_Active
(No_Finalization
) then
5934 -- C, C++, CIL and Java types are not considered controlled. It is
5935 -- assumed that the non-Ada side will handle their clean up.
5937 elsif Convention
(T
) = Convention_C
5938 or else Convention
(T
) = Convention_CIL
5939 or else Convention
(T
) = Convention_CPP
5940 or else Convention
(T
) = Convention_Java
5945 -- Class-wide types are treated as controlled because derivations
5946 -- from the root type can introduce controlled components.
5949 Is_Class_Wide_Type
(T
)
5950 or else Is_Controlled
(T
)
5951 or else Has_Controlled_Component
(T
)
5952 or else Has_Some_Controlled_Component
(T
)
5954 (Is_Concurrent_Type
(T
)
5955 and then Present
(Corresponding_Record_Type
(T
))
5956 and then Needs_Finalization
(Corresponding_Record_Type
(T
)));
5958 end Needs_Finalization
;
5960 ----------------------------
5961 -- Needs_Constant_Address --
5962 ----------------------------
5964 function Needs_Constant_Address
5966 Typ
: Entity_Id
) return Boolean
5970 -- If we have no initialization of any kind, then we don't need to place
5971 -- any restrictions on the address clause, because the object will be
5972 -- elaborated after the address clause is evaluated. This happens if the
5973 -- declaration has no initial expression, or the type has no implicit
5974 -- initialization, or the object is imported.
5976 -- The same holds for all initialized scalar types and all access types.
5977 -- Packed bit arrays of size up to 64 are represented using a modular
5978 -- type with an initialization (to zero) and can be processed like other
5979 -- initialized scalar types.
5981 -- If the type is controlled, code to attach the object to a
5982 -- finalization chain is generated at the point of declaration, and
5983 -- therefore the elaboration of the object cannot be delayed: the
5984 -- address expression must be a constant.
5986 if No
(Expression
(Decl
))
5987 and then not Needs_Finalization
(Typ
)
5989 (not Has_Non_Null_Base_Init_Proc
(Typ
)
5990 or else Is_Imported
(Defining_Identifier
(Decl
)))
5994 elsif (Present
(Expression
(Decl
)) and then Is_Scalar_Type
(Typ
))
5995 or else Is_Access_Type
(Typ
)
5997 (Is_Bit_Packed_Array
(Typ
)
5998 and then Is_Modular_Integer_Type
(Packed_Array_Type
(Typ
)))
6004 -- Otherwise, we require the address clause to be constant because
6005 -- the call to the initialization procedure (or the attach code) has
6006 -- to happen at the point of the declaration.
6008 -- Actually the IP call has been moved to the freeze actions anyway,
6009 -- so maybe we can relax this restriction???
6013 end Needs_Constant_Address
;
6015 ----------------------------
6016 -- New_Class_Wide_Subtype --
6017 ----------------------------
6019 function New_Class_Wide_Subtype
6020 (CW_Typ
: Entity_Id
;
6021 N
: Node_Id
) return Entity_Id
6023 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
6024 Res_Name
: constant Name_Id
:= Chars
(Res
);
6025 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
6028 Copy_Node
(CW_Typ
, Res
);
6029 Set_Comes_From_Source
(Res
, False);
6030 Set_Sloc
(Res
, Sloc
(N
));
6032 Set_Associated_Node_For_Itype
(Res
, N
);
6033 Set_Is_Public
(Res
, False); -- By default, may be changed below.
6034 Set_Public_Status
(Res
);
6035 Set_Chars
(Res
, Res_Name
);
6036 Set_Scope
(Res
, Res_Scope
);
6037 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
6038 Set_Next_Entity
(Res
, Empty
);
6039 Set_Etype
(Res
, Base_Type
(CW_Typ
));
6040 Set_Is_Frozen
(Res
, False);
6041 Set_Freeze_Node
(Res
, Empty
);
6043 end New_Class_Wide_Subtype
;
6045 --------------------------------
6046 -- Non_Limited_Designated_Type --
6047 ---------------------------------
6049 function Non_Limited_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
6050 Desig
: constant Entity_Id
:= Designated_Type
(T
);
6052 if Ekind
(Desig
) = E_Incomplete_Type
6053 and then Present
(Non_Limited_View
(Desig
))
6055 return Non_Limited_View
(Desig
);
6059 end Non_Limited_Designated_Type
;
6061 -----------------------------------
6062 -- OK_To_Do_Constant_Replacement --
6063 -----------------------------------
6065 function OK_To_Do_Constant_Replacement
(E
: Entity_Id
) return Boolean is
6066 ES
: constant Entity_Id
:= Scope
(E
);
6070 -- Do not replace statically allocated objects, because they may be
6071 -- modified outside the current scope.
6073 if Is_Statically_Allocated
(E
) then
6076 -- Do not replace aliased or volatile objects, since we don't know what
6077 -- else might change the value.
6079 elsif Is_Aliased
(E
) or else Treat_As_Volatile
(E
) then
6082 -- Debug flag -gnatdM disconnects this optimization
6084 elsif Debug_Flag_MM
then
6087 -- Otherwise check scopes
6090 CS
:= Current_Scope
;
6093 -- If we are in right scope, replacement is safe
6098 -- Packages do not affect the determination of safety
6100 elsif Ekind
(CS
) = E_Package
then
6101 exit when CS
= Standard_Standard
;
6104 -- Blocks do not affect the determination of safety
6106 elsif Ekind
(CS
) = E_Block
then
6109 -- Loops do not affect the determination of safety. Note that we
6110 -- kill all current values on entry to a loop, so we are just
6111 -- talking about processing within a loop here.
6113 elsif Ekind
(CS
) = E_Loop
then
6116 -- Otherwise, the reference is dubious, and we cannot be sure that
6117 -- it is safe to do the replacement.
6126 end OK_To_Do_Constant_Replacement
;
6128 ------------------------------------
6129 -- Possible_Bit_Aligned_Component --
6130 ------------------------------------
6132 function Possible_Bit_Aligned_Component
(N
: Node_Id
) return Boolean is
6136 -- Case of indexed component
6138 when N_Indexed_Component
=>
6140 P
: constant Node_Id
:= Prefix
(N
);
6141 Ptyp
: constant Entity_Id
:= Etype
(P
);
6144 -- If we know the component size and it is less than 64, then
6145 -- we are definitely OK. The back end always does assignment of
6146 -- misaligned small objects correctly.
6148 if Known_Static_Component_Size
(Ptyp
)
6149 and then Component_Size
(Ptyp
) <= 64
6153 -- Otherwise, we need to test the prefix, to see if we are
6154 -- indexing from a possibly unaligned component.
6157 return Possible_Bit_Aligned_Component
(P
);
6161 -- Case of selected component
6163 when N_Selected_Component
=>
6165 P
: constant Node_Id
:= Prefix
(N
);
6166 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
6169 -- If there is no component clause, then we are in the clear
6170 -- since the back end will never misalign a large component
6171 -- unless it is forced to do so. In the clear means we need
6172 -- only the recursive test on the prefix.
6174 if Component_May_Be_Bit_Aligned
(Comp
) then
6177 return Possible_Bit_Aligned_Component
(P
);
6181 -- For a slice, test the prefix, if that is possibly misaligned,
6182 -- then for sure the slice is!
6185 return Possible_Bit_Aligned_Component
(Prefix
(N
));
6187 -- For an unchecked conversion, check whether the expression may
6190 when N_Unchecked_Type_Conversion
=>
6191 return Possible_Bit_Aligned_Component
(Expression
(N
));
6193 -- If we have none of the above, it means that we have fallen off the
6194 -- top testing prefixes recursively, and we now have a stand alone
6195 -- object, where we don't have a problem.
6201 end Possible_Bit_Aligned_Component
;
6203 -----------------------------------------------
6204 -- Process_Statements_For_Controlled_Objects --
6205 -----------------------------------------------
6207 procedure Process_Statements_For_Controlled_Objects
(N
: Node_Id
) is
6208 Loc
: constant Source_Ptr
:= Sloc
(N
);
6210 function Are_Wrapped
(L
: List_Id
) return Boolean;
6211 -- Determine whether list L contains only one statement which is a block
6213 function Wrap_Statements_In_Block
(L
: List_Id
) return Node_Id
;
6214 -- Given a list of statements L, wrap it in a block statement and return
6215 -- the generated node.
6221 function Are_Wrapped
(L
: List_Id
) return Boolean is
6222 Stmt
: constant Node_Id
:= First
(L
);
6226 and then No
(Next
(Stmt
))
6227 and then Nkind
(Stmt
) = N_Block_Statement
;
6230 ------------------------------
6231 -- Wrap_Statements_In_Block --
6232 ------------------------------
6234 function Wrap_Statements_In_Block
(L
: List_Id
) return Node_Id
is
6237 Make_Block_Statement
(Loc
,
6238 Declarations
=> No_List
,
6239 Handled_Statement_Sequence
=>
6240 Make_Handled_Sequence_Of_Statements
(Loc
,
6242 end Wrap_Statements_In_Block
;
6248 -- Start of processing for Process_Statements_For_Controlled_Objects
6251 -- Whenever a non-handled statement list is wrapped in a block, the
6252 -- block must be explicitly analyzed to redecorate all entities in the
6253 -- list and ensure that a finalizer is properly built.
6258 N_Conditional_Entry_Call |
6259 N_Selective_Accept
=>
6261 -- Check the "then statements" for elsif parts and if statements
6263 if Nkind_In
(N
, N_Elsif_Part
, N_If_Statement
)
6264 and then not Is_Empty_List
(Then_Statements
(N
))
6265 and then not Are_Wrapped
(Then_Statements
(N
))
6266 and then Requires_Cleanup_Actions
6267 (Then_Statements
(N
), False, False)
6269 Block
:= Wrap_Statements_In_Block
(Then_Statements
(N
));
6270 Set_Then_Statements
(N
, New_List
(Block
));
6275 -- Check the "else statements" for conditional entry calls, if
6276 -- statements and selective accepts.
6278 if Nkind_In
(N
, N_Conditional_Entry_Call
,
6281 and then not Is_Empty_List
(Else_Statements
(N
))
6282 and then not Are_Wrapped
(Else_Statements
(N
))
6283 and then Requires_Cleanup_Actions
6284 (Else_Statements
(N
), False, False)
6286 Block
:= Wrap_Statements_In_Block
(Else_Statements
(N
));
6287 Set_Else_Statements
(N
, New_List
(Block
));
6292 when N_Abortable_Part |
6293 N_Accept_Alternative |
6294 N_Case_Statement_Alternative |
6295 N_Delay_Alternative |
6296 N_Entry_Call_Alternative |
6297 N_Exception_Handler |
6299 N_Triggering_Alternative
=>
6301 if not Is_Empty_List
(Statements
(N
))
6302 and then not Are_Wrapped
(Statements
(N
))
6303 and then Requires_Cleanup_Actions
(Statements
(N
), False, False)
6305 Block
:= Wrap_Statements_In_Block
(Statements
(N
));
6306 Set_Statements
(N
, New_List
(Block
));
6314 end Process_Statements_For_Controlled_Objects
;
6316 ----------------------
6317 -- Remove_Init_Call --
6318 ----------------------
6320 function Remove_Init_Call
6322 Rep_Clause
: Node_Id
) return Node_Id
6324 Par
: constant Node_Id
:= Parent
(Var
);
6325 Typ
: constant Entity_Id
:= Etype
(Var
);
6327 Init_Proc
: Entity_Id
;
6328 -- Initialization procedure for Typ
6330 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
;
6331 -- Look for init call for Var starting at From and scanning the
6332 -- enclosing list until Rep_Clause or the end of the list is reached.
6334 ----------------------------
6335 -- Find_Init_Call_In_List --
6336 ----------------------------
6338 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
is
6339 Init_Call
: Node_Id
;
6343 while Present
(Init_Call
) and then Init_Call
/= Rep_Clause
loop
6344 if Nkind
(Init_Call
) = N_Procedure_Call_Statement
6345 and then Is_Entity_Name
(Name
(Init_Call
))
6346 and then Entity
(Name
(Init_Call
)) = Init_Proc
6355 end Find_Init_Call_In_List
;
6357 Init_Call
: Node_Id
;
6359 -- Start of processing for Find_Init_Call
6362 if Present
(Initialization_Statements
(Var
)) then
6363 Init_Call
:= Initialization_Statements
(Var
);
6364 Set_Initialization_Statements
(Var
, Empty
);
6366 elsif not Has_Non_Null_Base_Init_Proc
(Typ
) then
6368 -- No init proc for the type, so obviously no call to be found
6373 -- We might be able to handle other cases below by just properly
6374 -- setting Initialization_Statements at the point where the init proc
6375 -- call is generated???
6377 Init_Proc
:= Base_Init_Proc
(Typ
);
6379 -- First scan the list containing the declaration of Var
6381 Init_Call
:= Find_Init_Call_In_List
(From
=> Next
(Par
));
6383 -- If not found, also look on Var's freeze actions list, if any,
6384 -- since the init call may have been moved there (case of an address
6385 -- clause applying to Var).
6387 if No
(Init_Call
) and then Present
(Freeze_Node
(Var
)) then
6389 Find_Init_Call_In_List
(First
(Actions
(Freeze_Node
(Var
))));
6392 -- If the initialization call has actuals that use the secondary
6393 -- stack, the call may have been wrapped into a temporary block, in
6394 -- which case the block itself has to be removed.
6396 if No
(Init_Call
) and then Nkind
(Next
(Par
)) = N_Block_Statement
then
6398 Blk
: constant Node_Id
:= Next
(Par
);
6401 (Find_Init_Call_In_List
6402 (First
(Statements
(Handled_Statement_Sequence
(Blk
)))))
6410 if Present
(Init_Call
) then
6414 end Remove_Init_Call
;
6416 -------------------------
6417 -- Remove_Side_Effects --
6418 -------------------------
6420 procedure Remove_Side_Effects
6422 Name_Req
: Boolean := False;
6423 Variable_Ref
: Boolean := False)
6425 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
6426 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
6427 Svg_Suppress
: constant Suppress_Record
:= Scope_Suppress
;
6431 Ptr_Typ_Decl
: Node_Id
;
6432 Ref_Type
: Entity_Id
;
6435 function Side_Effect_Free
(N
: Node_Id
) return Boolean;
6436 -- Determines if the tree N represents an expression that is known not
6437 -- to have side effects, and for which no processing is required.
6439 function Side_Effect_Free
(L
: List_Id
) return Boolean;
6440 -- Determines if all elements of the list L are side effect free
6442 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
6443 -- The argument N is a construct where the Prefix is dereferenced if it
6444 -- is an access type and the result is a variable. The call returns True
6445 -- if the construct is side effect free (not considering side effects in
6446 -- other than the prefix which are to be tested by the caller).
6448 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
6449 -- Determines if N is a subcomponent of a composite in-parameter. If so,
6450 -- N is not side-effect free when the actual is global and modifiable
6451 -- indirectly from within a subprogram, because it may be passed by
6452 -- reference. The front-end must be conservative here and assume that
6453 -- this may happen with any array or record type. On the other hand, we
6454 -- cannot create temporaries for all expressions for which this
6455 -- condition is true, for various reasons that might require clearing up
6456 -- ??? For example, discriminant references that appear out of place, or
6457 -- spurious type errors with class-wide expressions. As a result, we
6458 -- limit the transformation to loop bounds, which is so far the only
6459 -- case that requires it.
6461 -----------------------------
6462 -- Safe_Prefixed_Reference --
6463 -----------------------------
6465 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
6467 -- If prefix is not side effect free, definitely not safe
6469 if not Side_Effect_Free
(Prefix
(N
)) then
6472 -- If the prefix is of an access type that is not access-to-constant,
6473 -- then this construct is a variable reference, which means it is to
6474 -- be considered to have side effects if Variable_Ref is set True.
6476 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
6477 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
6478 and then Variable_Ref
6480 -- Exception is a prefix that is the result of a previous removal
6483 return Is_Entity_Name
(Prefix
(N
))
6484 and then not Comes_From_Source
(Prefix
(N
))
6485 and then Ekind
(Entity
(Prefix
(N
))) = E_Constant
6486 and then Is_Internal_Name
(Chars
(Entity
(Prefix
(N
))));
6488 -- If the prefix is an explicit dereference then this construct is a
6489 -- variable reference, which means it is to be considered to have
6490 -- side effects if Variable_Ref is True.
6492 -- We do NOT exclude dereferences of access-to-constant types because
6493 -- we handle them as constant view of variables.
6495 elsif Nkind
(Prefix
(N
)) = N_Explicit_Dereference
6496 and then Variable_Ref
6500 -- Note: The following test is the simplest way of solving a complex
6501 -- problem uncovered by the following test (Side effect on loop bound
6502 -- that is a subcomponent of a global variable:
6504 -- with Text_Io; use Text_Io;
6505 -- procedure Tloop is
6508 -- V : Natural := 4;
6509 -- S : String (1..5) := (others => 'a');
6516 -- with procedure Action;
6517 -- procedure Loop_G (Arg : X; Msg : String)
6519 -- procedure Loop_G (Arg : X; Msg : String) is
6521 -- Put_Line ("begin loop_g " & Msg & " will loop till: "
6522 -- & Natural'Image (Arg.V));
6523 -- for Index in 1 .. Arg.V loop
6525 -- (Natural'Image (Index) & " " & Arg.S (Index));
6526 -- if Index > 2 then
6530 -- Put_Line ("end loop_g " & Msg);
6533 -- procedure Loop1 is new Loop_G (Modi);
6534 -- procedure Modi is
6537 -- Loop1 (X1, "from modi");
6541 -- Loop1 (X1, "initial");
6544 -- The output of the above program should be:
6546 -- begin loop_g initial will loop till: 4
6550 -- begin loop_g from modi will loop till: 1
6552 -- end loop_g from modi
6554 -- begin loop_g from modi will loop till: 1
6556 -- end loop_g from modi
6557 -- end loop_g initial
6559 -- If a loop bound is a subcomponent of a global variable, a
6560 -- modification of that variable within the loop may incorrectly
6561 -- affect the execution of the loop.
6563 elsif Nkind
(Parent
(Parent
(N
))) = N_Loop_Parameter_Specification
6564 and then Within_In_Parameter
(Prefix
(N
))
6565 and then Variable_Ref
6569 -- All other cases are side effect free
6574 end Safe_Prefixed_Reference
;
6576 ----------------------
6577 -- Side_Effect_Free --
6578 ----------------------
6580 function Side_Effect_Free
(N
: Node_Id
) return Boolean is
6582 -- Note on checks that could raise Constraint_Error. Strictly, if we
6583 -- take advantage of 11.6, these checks do not count as side effects.
6584 -- However, we would prefer to consider that they are side effects,
6585 -- since the backend CSE does not work very well on expressions which
6586 -- can raise Constraint_Error. On the other hand if we don't consider
6587 -- them to be side effect free, then we get some awkward expansions
6588 -- in -gnato mode, resulting in code insertions at a point where we
6589 -- do not have a clear model for performing the insertions.
6591 -- Special handling for entity names
6593 if Is_Entity_Name
(N
) then
6595 -- Variables are considered to be a side effect if Variable_Ref
6596 -- is set or if we have a volatile reference and Name_Req is off.
6597 -- If Name_Req is True then we can't help returning a name which
6598 -- effectively allows multiple references in any case.
6600 if Is_Variable
(N
, Use_Original_Node
=> False) then
6601 return not Variable_Ref
6602 and then (not Is_Volatile_Reference
(N
) or else Name_Req
);
6604 -- Any other entity (e.g. a subtype name) is definitely side
6611 -- A value known at compile time is always side effect free
6613 elsif Compile_Time_Known_Value
(N
) then
6616 -- A variable renaming is not side-effect free, because the renaming
6617 -- will function like a macro in the front-end in some cases, and an
6618 -- assignment can modify the component designated by N, so we need to
6619 -- create a temporary for it.
6621 -- The guard testing for Entity being present is needed at least in
6622 -- the case of rewritten predicate expressions, and may well also be
6623 -- appropriate elsewhere. Obviously we can't go testing the entity
6624 -- field if it does not exist, so it's reasonable to say that this is
6625 -- not the renaming case if it does not exist.
6627 elsif Is_Entity_Name
(Original_Node
(N
))
6628 and then Present
(Entity
(Original_Node
(N
)))
6629 and then Is_Renaming_Of_Object
(Entity
(Original_Node
(N
)))
6630 and then Ekind
(Entity
(Original_Node
(N
))) /= E_Constant
6633 RO
: constant Node_Id
:=
6634 Renamed_Object
(Entity
(Original_Node
(N
)));
6637 -- If the renamed object is an indexed component, or an
6638 -- explicit dereference, then the designated object could
6639 -- be modified by an assignment.
6641 if Nkind_In
(RO
, N_Indexed_Component
,
6642 N_Explicit_Dereference
)
6646 -- A selected component must have a safe prefix
6648 elsif Nkind
(RO
) = N_Selected_Component
then
6649 return Safe_Prefixed_Reference
(RO
);
6651 -- In all other cases, designated object cannot be changed so
6652 -- we are side effect free.
6659 -- Remove_Side_Effects generates an object renaming declaration to
6660 -- capture the expression of a class-wide expression. In VM targets
6661 -- the frontend performs no expansion for dispatching calls to
6662 -- class- wide types since they are handled by the VM. Hence, we must
6663 -- locate here if this node corresponds to a previous invocation of
6664 -- Remove_Side_Effects to avoid a never ending loop in the frontend.
6666 elsif VM_Target
/= No_VM
6667 and then not Comes_From_Source
(N
)
6668 and then Nkind
(Parent
(N
)) = N_Object_Renaming_Declaration
6669 and then Is_Class_Wide_Type
(Etype
(N
))
6674 -- For other than entity names and compile time known values,
6675 -- check the node kind for special processing.
6679 -- An attribute reference is side effect free if its expressions
6680 -- are side effect free and its prefix is side effect free or
6681 -- is an entity reference.
6683 -- Is this right? what about x'first where x is a variable???
6685 when N_Attribute_Reference
=>
6686 return Side_Effect_Free
(Expressions
(N
))
6687 and then Attribute_Name
(N
) /= Name_Input
6688 and then (Is_Entity_Name
(Prefix
(N
))
6689 or else Side_Effect_Free
(Prefix
(N
)));
6691 -- A binary operator is side effect free if and both operands are
6692 -- side effect free. For this purpose binary operators include
6693 -- membership tests and short circuit forms.
6695 when N_Binary_Op | N_Membership_Test | N_Short_Circuit
=>
6696 return Side_Effect_Free
(Left_Opnd
(N
))
6698 Side_Effect_Free
(Right_Opnd
(N
));
6700 -- An explicit dereference is side effect free only if it is
6701 -- a side effect free prefixed reference.
6703 when N_Explicit_Dereference
=>
6704 return Safe_Prefixed_Reference
(N
);
6706 -- An expression with action is side effect free if its expression
6707 -- is side effect free and it has no actions.
6709 when N_Expression_With_Actions
=>
6710 return Is_Empty_List
(Actions
(N
))
6712 Side_Effect_Free
(Expression
(N
));
6714 -- A call to _rep_to_pos is side effect free, since we generate
6715 -- this pure function call ourselves. Moreover it is critically
6716 -- important to make this exception, since otherwise we can have
6717 -- discriminants in array components which don't look side effect
6718 -- free in the case of an array whose index type is an enumeration
6719 -- type with an enumeration rep clause.
6721 -- All other function calls are not side effect free
6723 when N_Function_Call
=>
6724 return Nkind
(Name
(N
)) = N_Identifier
6725 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
6727 Side_Effect_Free
(First
(Parameter_Associations
(N
)));
6729 -- An indexed component is side effect free if it is a side
6730 -- effect free prefixed reference and all the indexing
6731 -- expressions are side effect free.
6733 when N_Indexed_Component
=>
6734 return Side_Effect_Free
(Expressions
(N
))
6735 and then Safe_Prefixed_Reference
(N
);
6737 -- A type qualification is side effect free if the expression
6738 -- is side effect free.
6740 when N_Qualified_Expression
=>
6741 return Side_Effect_Free
(Expression
(N
));
6743 -- A selected component is side effect free only if it is a side
6744 -- effect free prefixed reference. If it designates a component
6745 -- with a rep. clause it must be treated has having a potential
6746 -- side effect, because it may be modified through a renaming, and
6747 -- a subsequent use of the renaming as a macro will yield the
6748 -- wrong value. This complex interaction between renaming and
6749 -- removing side effects is a reminder that the latter has become
6750 -- a headache to maintain, and that it should be removed in favor
6751 -- of the gcc mechanism to capture values ???
6753 when N_Selected_Component
=>
6754 if Nkind
(Parent
(N
)) = N_Explicit_Dereference
6755 and then Has_Non_Standard_Rep
(Designated_Type
(Etype
(N
)))
6759 return Safe_Prefixed_Reference
(N
);
6762 -- A range is side effect free if the bounds are side effect free
6765 return Side_Effect_Free
(Low_Bound
(N
))
6766 and then Side_Effect_Free
(High_Bound
(N
));
6768 -- A slice is side effect free if it is a side effect free
6769 -- prefixed reference and the bounds are side effect free.
6772 return Side_Effect_Free
(Discrete_Range
(N
))
6773 and then Safe_Prefixed_Reference
(N
);
6775 -- A type conversion is side effect free if the expression to be
6776 -- converted is side effect free.
6778 when N_Type_Conversion
=>
6779 return Side_Effect_Free
(Expression
(N
));
6781 -- A unary operator is side effect free if the operand
6782 -- is side effect free.
6785 return Side_Effect_Free
(Right_Opnd
(N
));
6787 -- An unchecked type conversion is side effect free only if it
6788 -- is safe and its argument is side effect free.
6790 when N_Unchecked_Type_Conversion
=>
6791 return Safe_Unchecked_Type_Conversion
(N
)
6792 and then Side_Effect_Free
(Expression
(N
));
6794 -- An unchecked expression is side effect free if its expression
6795 -- is side effect free.
6797 when N_Unchecked_Expression
=>
6798 return Side_Effect_Free
(Expression
(N
));
6800 -- A literal is side effect free
6802 when N_Character_Literal |
6808 -- We consider that anything else has side effects. This is a bit
6809 -- crude, but we are pretty close for most common cases, and we
6810 -- are certainly correct (i.e. we never return True when the
6811 -- answer should be False).
6816 end Side_Effect_Free
;
6818 -- A list is side effect free if all elements of the list are side
6821 function Side_Effect_Free
(L
: List_Id
) return Boolean is
6825 if L
= No_List
or else L
= Error_List
then
6830 while Present
(N
) loop
6831 if not Side_Effect_Free
(N
) then
6840 end Side_Effect_Free
;
6842 -------------------------
6843 -- Within_In_Parameter --
6844 -------------------------
6846 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
6848 if not Comes_From_Source
(N
) then
6851 elsif Is_Entity_Name
(N
) then
6852 return Ekind
(Entity
(N
)) = E_In_Parameter
;
6854 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
6855 return Within_In_Parameter
(Prefix
(N
));
6860 end Within_In_Parameter
;
6862 -- Start of processing for Remove_Side_Effects
6865 -- Handle cases in which there is nothing to do
6867 if not Expander_Active
then
6871 -- Cannot generate temporaries if the invocation to remove side effects
6872 -- was issued too early and the type of the expression is not resolved
6873 -- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
6874 -- Remove_Side_Effects).
6877 or else Ekind
(Exp_Type
) = E_Access_Attribute_Type
6881 -- No action needed for side-effect free expressions
6883 elsif Side_Effect_Free
(Exp
) then
6887 -- The remaining procesaing is done with all checks suppressed
6889 -- Note: from now on, don't use return statements, instead do a goto
6890 -- Leave, to ensure that we properly restore Scope_Suppress.Suppress.
6892 Scope_Suppress
.Suppress
:= (others => True);
6894 -- If it is a scalar type and we need to capture the value, just make
6895 -- a copy. Likewise for a function call, an attribute reference, an
6896 -- allocator, or an operator. And if we have a volatile reference and
6897 -- Name_Req is not set (see comments above for Side_Effect_Free).
6899 if Is_Elementary_Type
(Exp_Type
)
6900 and then (Variable_Ref
6901 or else Nkind_In
(Exp
, N_Function_Call
,
6902 N_Attribute_Reference
,
6904 or else Nkind
(Exp
) in N_Op
6905 or else (not Name_Req
and then Is_Volatile_Reference
(Exp
)))
6907 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
6908 Set_Etype
(Def_Id
, Exp_Type
);
6909 Res
:= New_Reference_To
(Def_Id
, Loc
);
6911 -- If the expression is a packed reference, it must be reanalyzed and
6912 -- expanded, depending on context. This is the case for actuals where
6913 -- a constraint check may capture the actual before expansion of the
6914 -- call is complete.
6916 if Nkind
(Exp
) = N_Indexed_Component
6917 and then Is_Packed
(Etype
(Prefix
(Exp
)))
6919 Set_Analyzed
(Exp
, False);
6920 Set_Analyzed
(Prefix
(Exp
), False);
6924 Make_Object_Declaration
(Loc
,
6925 Defining_Identifier
=> Def_Id
,
6926 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
6927 Constant_Present
=> True,
6928 Expression
=> Relocate_Node
(Exp
));
6930 Set_Assignment_OK
(E
);
6931 Insert_Action
(Exp
, E
);
6933 -- If the expression has the form v.all then we can just capture the
6934 -- pointer, and then do an explicit dereference on the result.
6936 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
6937 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
6939 Make_Explicit_Dereference
(Loc
, New_Reference_To
(Def_Id
, Loc
));
6942 Make_Object_Declaration
(Loc
,
6943 Defining_Identifier
=> Def_Id
,
6944 Object_Definition
=>
6945 New_Reference_To
(Etype
(Prefix
(Exp
)), Loc
),
6946 Constant_Present
=> True,
6947 Expression
=> Relocate_Node
(Prefix
(Exp
))));
6949 -- Similar processing for an unchecked conversion of an expression of
6950 -- the form v.all, where we want the same kind of treatment.
6952 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
6953 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
6955 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
6958 -- If this is a type conversion, leave the type conversion and remove
6959 -- the side effects in the expression. This is important in several
6960 -- circumstances: for change of representations, and also when this is a
6961 -- view conversion to a smaller object, where gigi can end up creating
6962 -- its own temporary of the wrong size.
6964 elsif Nkind
(Exp
) = N_Type_Conversion
then
6965 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
6968 -- If this is an unchecked conversion that Gigi can't handle, make
6969 -- a copy or a use a renaming to capture the value.
6971 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
6972 and then not Safe_Unchecked_Type_Conversion
(Exp
)
6974 if CW_Or_Has_Controlled_Part
(Exp_Type
) then
6976 -- Use a renaming to capture the expression, rather than create
6977 -- a controlled temporary.
6979 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
6980 Res
:= New_Reference_To
(Def_Id
, Loc
);
6983 Make_Object_Renaming_Declaration
(Loc
,
6984 Defining_Identifier
=> Def_Id
,
6985 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
6986 Name
=> Relocate_Node
(Exp
)));
6989 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
6990 Set_Etype
(Def_Id
, Exp_Type
);
6991 Res
:= New_Reference_To
(Def_Id
, Loc
);
6994 Make_Object_Declaration
(Loc
,
6995 Defining_Identifier
=> Def_Id
,
6996 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
6997 Constant_Present
=> not Is_Variable
(Exp
),
6998 Expression
=> Relocate_Node
(Exp
));
7000 Set_Assignment_OK
(E
);
7001 Insert_Action
(Exp
, E
);
7004 -- For expressions that denote objects, we can use a renaming scheme.
7005 -- This is needed for correctness in the case of a volatile object of
7006 -- a non-volatile type because the Make_Reference call of the "default"
7007 -- approach would generate an illegal access value (an access value
7008 -- cannot designate such an object - see Analyze_Reference). We skip
7009 -- using this scheme if we have an object of a volatile type and we do
7010 -- not have Name_Req set true (see comments above for Side_Effect_Free).
7012 -- In Ada 2012 a qualified expression is an object, but for purposes of
7013 -- removing side effects it still need to be transformed into a separate
7014 -- declaration, particularly if the expression is an aggregate.
7016 elsif Is_Object_Reference
(Exp
)
7017 and then Nkind
(Exp
) /= N_Function_Call
7018 and then Nkind
(Exp
) /= N_Qualified_Expression
7019 and then (Name_Req
or else not Treat_As_Volatile
(Exp_Type
))
7021 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
7023 if Nkind
(Exp
) = N_Selected_Component
7024 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
7025 and then Is_Array_Type
(Exp_Type
)
7027 -- Avoid generating a variable-sized temporary, by generating
7028 -- the renaming declaration just for the function call. The
7029 -- transformation could be refined to apply only when the array
7030 -- component is constrained by a discriminant???
7033 Make_Selected_Component
(Loc
,
7034 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
7035 Selector_Name
=> Selector_Name
(Exp
));
7038 Make_Object_Renaming_Declaration
(Loc
,
7039 Defining_Identifier
=> Def_Id
,
7041 New_Reference_To
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
7042 Name
=> Relocate_Node
(Prefix
(Exp
))));
7045 Res
:= New_Reference_To
(Def_Id
, Loc
);
7048 Make_Object_Renaming_Declaration
(Loc
,
7049 Defining_Identifier
=> Def_Id
,
7050 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
7051 Name
=> Relocate_Node
(Exp
)));
7054 -- If this is a packed reference, or a selected component with
7055 -- a non-standard representation, a reference to the temporary
7056 -- will be replaced by a copy of the original expression (see
7057 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
7058 -- elaborated by gigi, and is of course not to be replaced in-line
7059 -- by the expression it renames, which would defeat the purpose of
7060 -- removing the side-effect.
7062 if Nkind_In
(Exp
, N_Selected_Component
, N_Indexed_Component
)
7063 and then Has_Non_Standard_Rep
(Etype
(Prefix
(Exp
)))
7067 Set_Is_Renaming_Of_Object
(Def_Id
, False);
7070 -- Otherwise we generate a reference to the value
7073 -- An expression which is in SPARK mode is considered side effect
7074 -- free if the resulting value is captured by a variable or a
7078 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
7083 -- Special processing for function calls that return a limited type.
7084 -- We need to build a declaration that will enable build-in-place
7085 -- expansion of the call. This is not done if the context is already
7086 -- an object declaration, to prevent infinite recursion.
7088 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
7089 -- to accommodate functions returning limited objects by reference.
7091 if Ada_Version
>= Ada_2005
7092 and then Nkind
(Exp
) = N_Function_Call
7093 and then Is_Limited_View
(Etype
(Exp
))
7094 and then Nkind
(Parent
(Exp
)) /= N_Object_Declaration
7097 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', Exp
);
7102 Make_Object_Declaration
(Loc
,
7103 Defining_Identifier
=> Obj
,
7104 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7105 Expression
=> Relocate_Node
(Exp
));
7107 Insert_Action
(Exp
, Decl
);
7108 Set_Etype
(Obj
, Exp_Type
);
7109 Rewrite
(Exp
, New_Occurrence_Of
(Obj
, Loc
));
7114 Def_Id
:= Make_Temporary
(Loc
, 'R', Exp
);
7116 -- The regular expansion of functions with side effects involves the
7117 -- generation of an access type to capture the return value found on
7118 -- the secondary stack. Since SPARK (and why) cannot process access
7119 -- types, use a different approach which ignores the secondary stack
7120 -- and "copies" the returned object.
7123 Res
:= New_Reference_To
(Def_Id
, Loc
);
7124 Ref_Type
:= Exp_Type
;
7126 -- Regular expansion utilizing an access type and 'reference
7130 Make_Explicit_Dereference
(Loc
,
7131 Prefix
=> New_Reference_To
(Def_Id
, Loc
));
7134 -- type Ann is access all <Exp_Type>;
7136 Ref_Type
:= Make_Temporary
(Loc
, 'A');
7139 Make_Full_Type_Declaration
(Loc
,
7140 Defining_Identifier
=> Ref_Type
,
7142 Make_Access_To_Object_Definition
(Loc
,
7143 All_Present
=> True,
7144 Subtype_Indication
=>
7145 New_Reference_To
(Exp_Type
, Loc
)));
7147 Insert_Action
(Exp
, Ptr_Typ_Decl
);
7151 if Nkind
(E
) = N_Explicit_Dereference
then
7152 New_Exp
:= Relocate_Node
(Prefix
(E
));
7154 E
:= Relocate_Node
(E
);
7156 -- Do not generate a 'reference in SPARK mode since the access
7157 -- type is not created in the first place.
7162 -- Otherwise generate reference, marking the value as non-null
7163 -- since we know it cannot be null and we don't want a check.
7166 New_Exp
:= Make_Reference
(Loc
, E
);
7167 Set_Is_Known_Non_Null
(Def_Id
);
7171 if Is_Delayed_Aggregate
(E
) then
7173 -- The expansion of nested aggregates is delayed until the
7174 -- enclosing aggregate is expanded. As aggregates are often
7175 -- qualified, the predicate applies to qualified expressions as
7176 -- well, indicating that the enclosing aggregate has not been
7177 -- expanded yet. At this point the aggregate is part of a
7178 -- stand-alone declaration, and must be fully expanded.
7180 if Nkind
(E
) = N_Qualified_Expression
then
7181 Set_Expansion_Delayed
(Expression
(E
), False);
7182 Set_Analyzed
(Expression
(E
), False);
7184 Set_Expansion_Delayed
(E
, False);
7187 Set_Analyzed
(E
, False);
7191 Make_Object_Declaration
(Loc
,
7192 Defining_Identifier
=> Def_Id
,
7193 Object_Definition
=> New_Reference_To
(Ref_Type
, Loc
),
7194 Constant_Present
=> True,
7195 Expression
=> New_Exp
));
7198 -- Preserve the Assignment_OK flag in all copies, since at least one
7199 -- copy may be used in a context where this flag must be set (otherwise
7200 -- why would the flag be set in the first place).
7202 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
7204 -- Finally rewrite the original expression and we are done
7207 Analyze_And_Resolve
(Exp
, Exp_Type
);
7210 Scope_Suppress
:= Svg_Suppress
;
7211 end Remove_Side_Effects
;
7213 ---------------------------
7214 -- Represented_As_Scalar --
7215 ---------------------------
7217 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean is
7218 UT
: constant Entity_Id
:= Underlying_Type
(T
);
7220 return Is_Scalar_Type
(UT
)
7221 or else (Is_Bit_Packed_Array
(UT
)
7222 and then Is_Scalar_Type
(Packed_Array_Type
(UT
)));
7223 end Represented_As_Scalar
;
7225 ------------------------------
7226 -- Requires_Cleanup_Actions --
7227 ------------------------------
7229 function Requires_Cleanup_Actions
7231 Lib_Level
: Boolean) return Boolean
7233 At_Lib_Level
: constant Boolean :=
7235 and then Nkind_In
(N
, N_Package_Body
,
7236 N_Package_Specification
);
7237 -- N is at the library level if the top-most context is a package and
7238 -- the path taken to reach N does not inlcude non-package constructs.
7242 when N_Accept_Statement |
7250 Requires_Cleanup_Actions
(Declarations
(N
), At_Lib_Level
, True)
7252 (Present
(Handled_Statement_Sequence
(N
))
7254 Requires_Cleanup_Actions
7255 (Statements
(Handled_Statement_Sequence
(N
)),
7256 At_Lib_Level
, True));
7258 when N_Package_Specification
=>
7260 Requires_Cleanup_Actions
7261 (Visible_Declarations
(N
), At_Lib_Level
, True)
7263 Requires_Cleanup_Actions
7264 (Private_Declarations
(N
), At_Lib_Level
, True);
7269 end Requires_Cleanup_Actions
;
7271 ------------------------------
7272 -- Requires_Cleanup_Actions --
7273 ------------------------------
7275 function Requires_Cleanup_Actions
7277 Lib_Level
: Boolean;
7278 Nested_Constructs
: Boolean) return Boolean
7283 Obj_Typ
: Entity_Id
;
7284 Pack_Id
: Entity_Id
;
7289 or else Is_Empty_List
(L
)
7295 while Present
(Decl
) loop
7297 -- Library-level tagged types
7299 if Nkind
(Decl
) = N_Full_Type_Declaration
then
7300 Typ
:= Defining_Identifier
(Decl
);
7302 if Is_Tagged_Type
(Typ
)
7303 and then Is_Library_Level_Entity
(Typ
)
7304 and then Convention
(Typ
) = Convention_Ada
7305 and then Present
(Access_Disp_Table
(Typ
))
7306 and then RTE_Available
(RE_Unregister_Tag
)
7307 and then not No_Run_Time_Mode
7308 and then not Is_Abstract_Type
(Typ
)
7313 -- Regular object declarations
7315 elsif Nkind
(Decl
) = N_Object_Declaration
then
7316 Obj_Id
:= Defining_Identifier
(Decl
);
7317 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7318 Expr
:= Expression
(Decl
);
7320 -- Bypass any form of processing for objects which have their
7321 -- finalization disabled. This applies only to objects at the
7324 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7327 -- Transient variables are treated separately in order to minimize
7328 -- the size of the generated code. See Exp_Ch7.Process_Transient_
7331 elsif Is_Processed_Transient
(Obj_Id
) then
7334 -- The object is of the form:
7335 -- Obj : Typ [:= Expr];
7337 -- Do not process the incomplete view of a deferred constant. Do
7338 -- not consider tag-to-class-wide conversions.
7340 elsif not Is_Imported
(Obj_Id
)
7341 and then Needs_Finalization
(Obj_Typ
)
7342 and then not (Ekind
(Obj_Id
) = E_Constant
7343 and then not Has_Completion
(Obj_Id
))
7344 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
7348 -- The object is of the form:
7349 -- Obj : Access_Typ := Non_BIP_Function_Call'reference;
7351 -- Obj : Access_Typ :=
7352 -- BIP_Function_Call (BIPalloc => 2, ...)'reference;
7354 elsif Is_Access_Type
(Obj_Typ
)
7355 and then Needs_Finalization
7356 (Available_View
(Designated_Type
(Obj_Typ
)))
7357 and then Present
(Expr
)
7359 (Is_Secondary_Stack_BIP_Func_Call
(Expr
)
7361 (Is_Non_BIP_Func_Call
(Expr
)
7362 and then not Is_Related_To_Func_Return
(Obj_Id
)))
7366 -- Processing for "hook" objects generated for controlled
7367 -- transients declared inside an Expression_With_Actions.
7369 elsif Is_Access_Type
(Obj_Typ
)
7370 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7371 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7372 N_Object_Declaration
7373 and then Is_Finalizable_Transient
7374 (Status_Flag_Or_Transient_Decl
(Obj_Id
), Decl
)
7378 -- Processing for intermediate results of if expressions where
7379 -- one of the alternatives uses a controlled function call.
7381 elsif Is_Access_Type
(Obj_Typ
)
7382 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7383 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7384 N_Defining_Identifier
7385 and then Present
(Expr
)
7386 and then Nkind
(Expr
) = N_Null
7390 -- Simple protected objects which use type System.Tasking.
7391 -- Protected_Objects.Protection to manage their locks should be
7392 -- treated as controlled since they require manual cleanup.
7394 elsif Ekind
(Obj_Id
) = E_Variable
7396 (Is_Simple_Protected_Type
(Obj_Typ
)
7397 or else Has_Simple_Protected_Object
(Obj_Typ
))
7402 -- Specific cases of object renamings
7404 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
7405 Obj_Id
:= Defining_Identifier
(Decl
);
7406 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7408 -- Bypass any form of processing for objects which have their
7409 -- finalization disabled. This applies only to objects at the
7412 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7415 -- Return object of a build-in-place function. This case is
7416 -- recognized and marked by the expansion of an extended return
7417 -- statement (see Expand_N_Extended_Return_Statement).
7419 elsif Needs_Finalization
(Obj_Typ
)
7420 and then Is_Return_Object
(Obj_Id
)
7421 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7425 -- Detect a case where a source object has been initialized by
7426 -- a controlled function call or another object which was later
7427 -- rewritten as a class-wide conversion of Ada.Tags.Displace.
7429 -- Obj1 : CW_Type := Src_Obj;
7430 -- Obj2 : CW_Type := Function_Call (...);
7432 -- Obj1 : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
7433 -- Tmp : ... := Function_Call (...)'reference;
7434 -- Obj2 : CW_Type renames (... Ada.Tags.Displace (Tmp));
7436 elsif Is_Displacement_Of_Object_Or_Function_Result
(Obj_Id
) then
7440 -- Inspect the freeze node of an access-to-controlled type and look
7441 -- for a delayed finalization master. This case arises when the
7442 -- freeze actions are inserted at a later time than the expansion of
7443 -- the context. Since Build_Finalizer is never called on a single
7444 -- construct twice, the master will be ultimately left out and never
7445 -- finalized. This is also needed for freeze actions of designated
7446 -- types themselves, since in some cases the finalization master is
7447 -- associated with a designated type's freeze node rather than that
7448 -- of the access type (see handling for freeze actions in
7449 -- Build_Finalization_Master).
7451 elsif Nkind
(Decl
) = N_Freeze_Entity
7452 and then Present
(Actions
(Decl
))
7454 Typ
:= Entity
(Decl
);
7456 if ((Is_Access_Type
(Typ
)
7457 and then not Is_Access_Subprogram_Type
(Typ
)
7458 and then Needs_Finalization
7459 (Available_View
(Designated_Type
(Typ
))))
7462 and then Needs_Finalization
(Typ
)))
7463 and then Requires_Cleanup_Actions
7464 (Actions
(Decl
), Lib_Level
, Nested_Constructs
)
7469 -- Nested package declarations
7471 elsif Nested_Constructs
7472 and then Nkind
(Decl
) = N_Package_Declaration
7474 Pack_Id
:= Defining_Unit_Name
(Specification
(Decl
));
7476 if Nkind
(Pack_Id
) = N_Defining_Program_Unit_Name
then
7477 Pack_Id
:= Defining_Identifier
(Pack_Id
);
7480 if Ekind
(Pack_Id
) /= E_Generic_Package
7482 Requires_Cleanup_Actions
(Specification
(Decl
), Lib_Level
)
7487 -- Nested package bodies
7489 elsif Nested_Constructs
and then Nkind
(Decl
) = N_Package_Body
then
7490 Pack_Id
:= Corresponding_Spec
(Decl
);
7492 if Ekind
(Pack_Id
) /= E_Generic_Package
7493 and then Requires_Cleanup_Actions
(Decl
, Lib_Level
)
7503 end Requires_Cleanup_Actions
;
7505 ------------------------------------
7506 -- Safe_Unchecked_Type_Conversion --
7507 ------------------------------------
7509 -- Note: this function knows quite a bit about the exact requirements of
7510 -- Gigi with respect to unchecked type conversions, and its code must be
7511 -- coordinated with any changes in Gigi in this area.
7513 -- The above requirements should be documented in Sinfo ???
7515 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
7520 Pexp
: constant Node_Id
:= Parent
(Exp
);
7523 -- If the expression is the RHS of an assignment or object declaration
7524 -- we are always OK because there will always be a target.
7526 -- Object renaming declarations, (generated for view conversions of
7527 -- actuals in inlined calls), like object declarations, provide an
7528 -- explicit type, and are safe as well.
7530 if (Nkind
(Pexp
) = N_Assignment_Statement
7531 and then Expression
(Pexp
) = Exp
)
7532 or else Nkind_In
(Pexp
, N_Object_Declaration
,
7533 N_Object_Renaming_Declaration
)
7537 -- If the expression is the prefix of an N_Selected_Component we should
7538 -- also be OK because GCC knows to look inside the conversion except if
7539 -- the type is discriminated. We assume that we are OK anyway if the
7540 -- type is not set yet or if it is controlled since we can't afford to
7541 -- introduce a temporary in this case.
7543 elsif Nkind
(Pexp
) = N_Selected_Component
7544 and then Prefix
(Pexp
) = Exp
7546 if No
(Etype
(Pexp
)) then
7550 not Has_Discriminants
(Etype
(Pexp
))
7551 or else Is_Constrained
(Etype
(Pexp
));
7555 -- Set the output type, this comes from Etype if it is set, otherwise we
7556 -- take it from the subtype mark, which we assume was already fully
7559 if Present
(Etype
(Exp
)) then
7560 Otyp
:= Etype
(Exp
);
7562 Otyp
:= Entity
(Subtype_Mark
(Exp
));
7565 -- The input type always comes from the expression, and we assume
7566 -- this is indeed always analyzed, so we can simply get the Etype.
7568 Ityp
:= Etype
(Expression
(Exp
));
7570 -- Initialize alignments to unknown so far
7575 -- Replace a concurrent type by its corresponding record type and each
7576 -- type by its underlying type and do the tests on those. The original
7577 -- type may be a private type whose completion is a concurrent type, so
7578 -- find the underlying type first.
7580 if Present
(Underlying_Type
(Otyp
)) then
7581 Otyp
:= Underlying_Type
(Otyp
);
7584 if Present
(Underlying_Type
(Ityp
)) then
7585 Ityp
:= Underlying_Type
(Ityp
);
7588 if Is_Concurrent_Type
(Otyp
) then
7589 Otyp
:= Corresponding_Record_Type
(Otyp
);
7592 if Is_Concurrent_Type
(Ityp
) then
7593 Ityp
:= Corresponding_Record_Type
(Ityp
);
7596 -- If the base types are the same, we know there is no problem since
7597 -- this conversion will be a noop.
7599 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
7602 -- Same if this is an upwards conversion of an untagged type, and there
7603 -- are no constraints involved (could be more general???)
7605 elsif Etype
(Ityp
) = Otyp
7606 and then not Is_Tagged_Type
(Ityp
)
7607 and then not Has_Discriminants
(Ityp
)
7608 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
7612 -- If the expression has an access type (object or subprogram) we assume
7613 -- that the conversion is safe, because the size of the target is safe,
7614 -- even if it is a record (which might be treated as having unknown size
7617 elsif Is_Access_Type
(Ityp
) then
7620 -- If the size of output type is known at compile time, there is never
7621 -- a problem. Note that unconstrained records are considered to be of
7622 -- known size, but we can't consider them that way here, because we are
7623 -- talking about the actual size of the object.
7625 -- We also make sure that in addition to the size being known, we do not
7626 -- have a case which might generate an embarrassingly large temp in
7627 -- stack checking mode.
7629 elsif Size_Known_At_Compile_Time
(Otyp
)
7631 (not Stack_Checking_Enabled
7632 or else not May_Generate_Large_Temp
(Otyp
))
7633 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
7637 -- If either type is tagged, then we know the alignment is OK so
7638 -- Gigi will be able to use pointer punning.
7640 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
7643 -- If either type is a limited record type, we cannot do a copy, so say
7644 -- safe since there's nothing else we can do.
7646 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
7649 -- Conversions to and from packed array types are always ignored and
7652 elsif Is_Packed_Array_Type
(Otyp
)
7653 or else Is_Packed_Array_Type
(Ityp
)
7658 -- The only other cases known to be safe is if the input type's
7659 -- alignment is known to be at least the maximum alignment for the
7660 -- target or if both alignments are known and the output type's
7661 -- alignment is no stricter than the input's. We can use the component
7662 -- type alignement for an array if a type is an unpacked array type.
7664 if Present
(Alignment_Clause
(Otyp
)) then
7665 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
7667 elsif Is_Array_Type
(Otyp
)
7668 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
7670 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
7671 (Component_Type
(Otyp
))));
7674 if Present
(Alignment_Clause
(Ityp
)) then
7675 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
7677 elsif Is_Array_Type
(Ityp
)
7678 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
7680 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
7681 (Component_Type
(Ityp
))));
7684 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
7687 elsif Ialign
/= No_Uint
and then Oalign
/= No_Uint
7688 and then Ialign
<= Oalign
7692 -- Otherwise, Gigi cannot handle this and we must make a temporary
7697 end Safe_Unchecked_Type_Conversion
;
7699 ---------------------------------
7700 -- Set_Current_Value_Condition --
7701 ---------------------------------
7703 -- Note: the implementation of this procedure is very closely tied to the
7704 -- implementation of Get_Current_Value_Condition. Here we set required
7705 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
7706 -- them, so they must have a consistent view.
7708 procedure Set_Current_Value_Condition
(Cnode
: Node_Id
) is
7710 procedure Set_Entity_Current_Value
(N
: Node_Id
);
7711 -- If N is an entity reference, where the entity is of an appropriate
7712 -- kind, then set the current value of this entity to Cnode, unless
7713 -- there is already a definite value set there.
7715 procedure Set_Expression_Current_Value
(N
: Node_Id
);
7716 -- If N is of an appropriate form, sets an appropriate entry in current
7717 -- value fields of relevant entities. Multiple entities can be affected
7718 -- in the case of an AND or AND THEN.
7720 ------------------------------
7721 -- Set_Entity_Current_Value --
7722 ------------------------------
7724 procedure Set_Entity_Current_Value
(N
: Node_Id
) is
7726 if Is_Entity_Name
(N
) then
7728 Ent
: constant Entity_Id
:= Entity
(N
);
7731 -- Don't capture if not safe to do so
7733 if not Safe_To_Capture_Value
(N
, Ent
, Cond
=> True) then
7737 -- Here we have a case where the Current_Value field may need
7738 -- to be set. We set it if it is not already set to a compile
7739 -- time expression value.
7741 -- Note that this represents a decision that one condition
7742 -- blots out another previous one. That's certainly right if
7743 -- they occur at the same level. If the second one is nested,
7744 -- then the decision is neither right nor wrong (it would be
7745 -- equally OK to leave the outer one in place, or take the new
7746 -- inner one. Really we should record both, but our data
7747 -- structures are not that elaborate.
7749 if Nkind
(Current_Value
(Ent
)) not in N_Subexpr
then
7750 Set_Current_Value
(Ent
, Cnode
);
7754 end Set_Entity_Current_Value
;
7756 ----------------------------------
7757 -- Set_Expression_Current_Value --
7758 ----------------------------------
7760 procedure Set_Expression_Current_Value
(N
: Node_Id
) is
7766 -- Loop to deal with (ignore for now) any NOT operators present. The
7767 -- presence of NOT operators will be handled properly when we call
7768 -- Get_Current_Value_Condition.
7770 while Nkind
(Cond
) = N_Op_Not
loop
7771 Cond
:= Right_Opnd
(Cond
);
7774 -- For an AND or AND THEN, recursively process operands
7776 if Nkind
(Cond
) = N_Op_And
or else Nkind
(Cond
) = N_And_Then
then
7777 Set_Expression_Current_Value
(Left_Opnd
(Cond
));
7778 Set_Expression_Current_Value
(Right_Opnd
(Cond
));
7782 -- Check possible relational operator
7784 if Nkind
(Cond
) in N_Op_Compare
then
7785 if Compile_Time_Known_Value
(Right_Opnd
(Cond
)) then
7786 Set_Entity_Current_Value
(Left_Opnd
(Cond
));
7787 elsif Compile_Time_Known_Value
(Left_Opnd
(Cond
)) then
7788 Set_Entity_Current_Value
(Right_Opnd
(Cond
));
7791 elsif Nkind_In
(Cond
,
7793 N_Qualified_Expression
,
7794 N_Expression_With_Actions
)
7796 Set_Expression_Current_Value
(Expression
(Cond
));
7798 -- Check possible boolean variable reference
7801 Set_Entity_Current_Value
(Cond
);
7803 end Set_Expression_Current_Value
;
7805 -- Start of processing for Set_Current_Value_Condition
7808 Set_Expression_Current_Value
(Condition
(Cnode
));
7809 end Set_Current_Value_Condition
;
7811 --------------------------
7812 -- Set_Elaboration_Flag --
7813 --------------------------
7815 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
7816 Loc
: constant Source_Ptr
:= Sloc
(N
);
7817 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
7821 if Present
(Ent
) then
7823 -- Nothing to do if at the compilation unit level, because in this
7824 -- case the flag is set by the binder generated elaboration routine.
7826 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
7829 -- Here we do need to generate an assignment statement
7832 Check_Restriction
(No_Elaboration_Code
, N
);
7834 Make_Assignment_Statement
(Loc
,
7835 Name
=> New_Occurrence_Of
(Ent
, Loc
),
7836 Expression
=> Make_Integer_Literal
(Loc
, Uint_1
));
7838 if Nkind
(Parent
(N
)) = N_Subunit
then
7839 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
7841 Insert_After
(N
, Asn
);
7846 -- Kill current value indication. This is necessary because the
7847 -- tests of this flag are inserted out of sequence and must not
7848 -- pick up bogus indications of the wrong constant value.
7850 Set_Current_Value
(Ent
, Empty
);
7853 end Set_Elaboration_Flag
;
7855 ----------------------------
7856 -- Set_Renamed_Subprogram --
7857 ----------------------------
7859 procedure Set_Renamed_Subprogram
(N
: Node_Id
; E
: Entity_Id
) is
7861 -- If input node is an identifier, we can just reset it
7863 if Nkind
(N
) = N_Identifier
then
7864 Set_Chars
(N
, Chars
(E
));
7867 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
7871 CS
: constant Boolean := Comes_From_Source
(N
);
7873 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
(E
)));
7875 Set_Comes_From_Source
(N
, CS
);
7876 Set_Analyzed
(N
, True);
7879 end Set_Renamed_Subprogram
;
7881 ----------------------------------
7882 -- Silly_Boolean_Array_Not_Test --
7883 ----------------------------------
7885 -- This procedure implements an odd and silly test. We explicitly check
7886 -- for the case where the 'First of the component type is equal to the
7887 -- 'Last of this component type, and if this is the case, we make sure
7888 -- that constraint error is raised. The reason is that the NOT is bound
7889 -- to cause CE in this case, and we will not otherwise catch it.
7891 -- No such check is required for AND and OR, since for both these cases
7892 -- False op False = False, and True op True = True. For the XOR case,
7893 -- see Silly_Boolean_Array_Xor_Test.
7895 -- Believe it or not, this was reported as a bug. Note that nearly always,
7896 -- the test will evaluate statically to False, so the code will be
7897 -- statically removed, and no extra overhead caused.
7899 procedure Silly_Boolean_Array_Not_Test
(N
: Node_Id
; T
: Entity_Id
) is
7900 Loc
: constant Source_Ptr
:= Sloc
(N
);
7901 CT
: constant Entity_Id
:= Component_Type
(T
);
7904 -- The check we install is
7906 -- constraint_error when
7907 -- component_type'first = component_type'last
7908 -- and then array_type'Length /= 0)
7910 -- We need the last guard because we don't want to raise CE for empty
7911 -- arrays since no out of range values result. (Empty arrays with a
7912 -- component type of True .. True -- very useful -- even the ACATS
7913 -- does not test that marginal case!)
7916 Make_Raise_Constraint_Error
(Loc
,
7922 Make_Attribute_Reference
(Loc
,
7923 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
7924 Attribute_Name
=> Name_First
),
7927 Make_Attribute_Reference
(Loc
,
7928 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
7929 Attribute_Name
=> Name_Last
)),
7931 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
7932 Reason
=> CE_Range_Check_Failed
));
7933 end Silly_Boolean_Array_Not_Test
;
7935 ----------------------------------
7936 -- Silly_Boolean_Array_Xor_Test --
7937 ----------------------------------
7939 -- This procedure implements an odd and silly test. We explicitly check
7940 -- for the XOR case where the component type is True .. True, since this
7941 -- will raise constraint error. A special check is required since CE
7942 -- will not be generated otherwise (cf Expand_Packed_Not).
7944 -- No such check is required for AND and OR, since for both these cases
7945 -- False op False = False, and True op True = True, and no check is
7946 -- required for the case of False .. False, since False xor False = False.
7947 -- See also Silly_Boolean_Array_Not_Test
7949 procedure Silly_Boolean_Array_Xor_Test
(N
: Node_Id
; T
: Entity_Id
) is
7950 Loc
: constant Source_Ptr
:= Sloc
(N
);
7951 CT
: constant Entity_Id
:= Component_Type
(T
);
7954 -- The check we install is
7956 -- constraint_error when
7957 -- Boolean (component_type'First)
7958 -- and then Boolean (component_type'Last)
7959 -- and then array_type'Length /= 0)
7961 -- We need the last guard because we don't want to raise CE for empty
7962 -- arrays since no out of range values result (Empty arrays with a
7963 -- component type of True .. True -- very useful -- even the ACATS
7964 -- does not test that marginal case!).
7967 Make_Raise_Constraint_Error
(Loc
,
7973 Convert_To
(Standard_Boolean
,
7974 Make_Attribute_Reference
(Loc
,
7975 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
7976 Attribute_Name
=> Name_First
)),
7979 Convert_To
(Standard_Boolean
,
7980 Make_Attribute_Reference
(Loc
,
7981 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
7982 Attribute_Name
=> Name_Last
))),
7984 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
7985 Reason
=> CE_Range_Check_Failed
));
7986 end Silly_Boolean_Array_Xor_Test
;
7988 --------------------------
7989 -- Target_Has_Fixed_Ops --
7990 --------------------------
7992 Integer_Sized_Small
: Ureal
;
7993 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
7994 -- called (we don't want to compute it more than once!)
7996 Long_Integer_Sized_Small
: Ureal
;
7997 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
7998 -- is called (we don't want to compute it more than once)
8000 First_Time_For_THFO
: Boolean := True;
8001 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
8003 function Target_Has_Fixed_Ops
8004 (Left_Typ
: Entity_Id
;
8005 Right_Typ
: Entity_Id
;
8006 Result_Typ
: Entity_Id
) return Boolean
8008 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
8009 -- Return True if the given type is a fixed-point type with a small
8010 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
8011 -- an absolute value less than 1.0. This is currently limited to
8012 -- fixed-point types that map to Integer or Long_Integer.
8014 ------------------------
8015 -- Is_Fractional_Type --
8016 ------------------------
8018 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
8020 if Esize
(Typ
) = Standard_Integer_Size
then
8021 return Small_Value
(Typ
) = Integer_Sized_Small
;
8023 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
8024 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
8029 end Is_Fractional_Type
;
8031 -- Start of processing for Target_Has_Fixed_Ops
8034 -- Return False if Fractional_Fixed_Ops_On_Target is false
8036 if not Fractional_Fixed_Ops_On_Target
then
8040 -- Here the target has Fractional_Fixed_Ops, if first time, compute
8041 -- standard constants used by Is_Fractional_Type.
8043 if First_Time_For_THFO
then
8044 First_Time_For_THFO
:= False;
8046 Integer_Sized_Small
:=
8049 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
8052 Long_Integer_Sized_Small
:=
8055 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
8059 -- Return True if target supports fixed-by-fixed multiply/divide for
8060 -- fractional fixed-point types (see Is_Fractional_Type) and the operand
8061 -- and result types are equivalent fractional types.
8063 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
8064 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
8065 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
8066 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
8067 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
8068 end Target_Has_Fixed_Ops
;
8070 ------------------------------------------
8071 -- Type_May_Have_Bit_Aligned_Components --
8072 ------------------------------------------
8074 function Type_May_Have_Bit_Aligned_Components
8075 (Typ
: Entity_Id
) return Boolean
8078 -- Array type, check component type
8080 if Is_Array_Type
(Typ
) then
8082 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
8084 -- Record type, check components
8086 elsif Is_Record_Type
(Typ
) then
8091 E
:= First_Component_Or_Discriminant
(Typ
);
8092 while Present
(E
) loop
8093 if Component_May_Be_Bit_Aligned
(E
)
8094 or else Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
8099 Next_Component_Or_Discriminant
(E
);
8105 -- Type other than array or record is always OK
8110 end Type_May_Have_Bit_Aligned_Components
;
8112 ----------------------------------
8113 -- Within_Case_Or_If_Expression --
8114 ----------------------------------
8116 function Within_Case_Or_If_Expression
(N
: Node_Id
) return Boolean is
8120 -- Locate an enclosing case or if expression. Note that these constructs
8121 -- can be expanded into Expression_With_Actions, hence the test of the
8125 while Present
(Par
) loop
8126 if Nkind_In
(Original_Node
(Par
), N_Case_Expression
,
8131 -- Prevent the search from going too far
8133 elsif Is_Body_Or_Package_Declaration
(Par
) then
8137 Par
:= Parent
(Par
);
8141 end Within_Case_Or_If_Expression
;
8143 ----------------------------
8144 -- Wrap_Cleanup_Procedure --
8145 ----------------------------
8147 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
8148 Loc
: constant Source_Ptr
:= Sloc
(N
);
8149 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
8150 Stmts
: constant List_Id
:= Statements
(Stseq
);
8153 if Abort_Allowed
then
8154 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
8155 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
8157 end Wrap_Cleanup_Procedure
;