1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 procedure Evaluate_Slice_Bounds
(Slice
: Node_Id
);
110 -- Force evaluation of bounds of a slice, which may be given by a range
111 -- or by a subtype indication with or without a constraint.
113 function Make_CW_Equivalent_Type
115 E
: Node_Id
) return Entity_Id
;
116 -- T is a class-wide type entity, E is the initial expression node that
117 -- constrains T in case such as: " X: T := E" or "new T'(E)". This function
118 -- returns the entity of the Equivalent type and inserts on the fly the
119 -- necessary declaration such as:
121 -- type anon is record
122 -- _parent : Root_Type (T); constrained with E discriminants (if any)
123 -- Extension : String (1 .. expr to match size of E);
126 -- This record is compatible with any object of the class of T thanks to
127 -- the first field and has the same size as E thanks to the second.
129 function Make_Literal_Range
131 Literal_Typ
: Entity_Id
) return Node_Id
;
132 -- Produce a Range node whose bounds are:
133 -- Low_Bound (Literal_Type) ..
134 -- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
135 -- this is used for expanding declarations like X : String := "sdfgdfg";
137 -- If the index type of the target array is not integer, we generate:
138 -- Low_Bound (Literal_Type) ..
140 -- (Literal_Type'Pos (Low_Bound (Literal_Type))
141 -- + (Length (Literal_Typ) -1))
143 function Make_Non_Empty_Check
145 N
: Node_Id
) return Node_Id
;
146 -- Produce a boolean expression checking that the unidimensional array
147 -- node N is not empty.
149 function New_Class_Wide_Subtype
151 N
: Node_Id
) return Entity_Id
;
152 -- Create an implicit subtype of CW_Typ attached to node N
154 function Requires_Cleanup_Actions
157 Nested_Constructs
: Boolean) return Boolean;
158 -- Given a list L, determine whether it contains one of the following:
160 -- 1) controlled objects
161 -- 2) library-level tagged types
163 -- Lib_Level is True when the list comes from a construct at the library
164 -- level, and False otherwise. Nested_Constructs is True when any nested
165 -- packages declared in L must be processed, and False otherwise.
167 -------------------------------------
168 -- Activate_Atomic_Synchronization --
169 -------------------------------------
171 procedure Activate_Atomic_Synchronization
(N
: Node_Id
) is
175 case Nkind
(Parent
(N
)) is
177 -- Check for cases of appearing in the prefix of a construct where
178 -- we don't need atomic synchronization for this kind of usage.
181 -- Nothing to do if we are the prefix of an attribute, since we
182 -- do not want an atomic sync operation for things like 'Size.
184 N_Attribute_Reference |
186 -- The N_Reference node is like an attribute
190 -- Nothing to do for a reference to a component (or components)
191 -- of a composite object. Only reads and updates of the object
192 -- as a whole require atomic synchronization (RM C.6 (15)).
194 N_Indexed_Component |
195 N_Selected_Component |
198 -- For all the above cases, nothing to do if we are the prefix
200 if Prefix
(Parent
(N
)) = N
then
207 -- Go ahead and set the flag
209 Set_Atomic_Sync_Required
(N
);
211 -- Generate info message if requested
213 if Warn_On_Atomic_Synchronization
then
218 when N_Selected_Component | N_Expanded_Name
=>
219 Msg_Node
:= Selector_Name
(N
);
221 when N_Explicit_Dereference | N_Indexed_Component
=>
225 pragma Assert
(False);
229 if Present
(Msg_Node
) then
231 ("info: atomic synchronization set for &?N?", Msg_Node
);
234 ("info: atomic synchronization set?N?", N
);
237 end Activate_Atomic_Synchronization
;
239 ----------------------
240 -- Adjust_Condition --
241 ----------------------
243 procedure Adjust_Condition
(N
: Node_Id
) is
250 Loc
: constant Source_Ptr
:= Sloc
(N
);
251 T
: constant Entity_Id
:= Etype
(N
);
255 -- Defend against a call where the argument has no type, or has a
256 -- type that is not Boolean. This can occur because of prior errors.
258 if No
(T
) or else not Is_Boolean_Type
(T
) then
262 -- Apply validity checking if needed
264 if Validity_Checks_On
and Validity_Check_Tests
then
268 -- Immediate return if standard boolean, the most common case,
269 -- where nothing needs to be done.
271 if Base_Type
(T
) = Standard_Boolean
then
275 -- Case of zero/non-zero semantics or non-standard enumeration
276 -- representation. In each case, we rewrite the node as:
278 -- ityp!(N) /= False'Enum_Rep
280 -- where ityp is an integer type with large enough size to hold any
283 if Nonzero_Is_True
(T
) or else Has_Non_Standard_Rep
(T
) then
284 if Esize
(T
) <= Esize
(Standard_Integer
) then
285 Ti
:= Standard_Integer
;
287 Ti
:= Standard_Long_Long_Integer
;
292 Left_Opnd
=> Unchecked_Convert_To
(Ti
, N
),
294 Make_Attribute_Reference
(Loc
,
295 Attribute_Name
=> Name_Enum_Rep
,
297 New_Occurrence_Of
(First_Literal
(T
), Loc
))));
298 Analyze_And_Resolve
(N
, Standard_Boolean
);
301 Rewrite
(N
, Convert_To
(Standard_Boolean
, N
));
302 Analyze_And_Resolve
(N
, Standard_Boolean
);
305 end Adjust_Condition
;
307 ------------------------
308 -- Adjust_Result_Type --
309 ------------------------
311 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
) is
313 -- Ignore call if current type is not Standard.Boolean
315 if Etype
(N
) /= Standard_Boolean
then
319 -- If result is already of correct type, nothing to do. Note that
320 -- this will get the most common case where everything has a type
321 -- of Standard.Boolean.
323 if Base_Type
(T
) = Standard_Boolean
then
328 KP
: constant Node_Kind
:= Nkind
(Parent
(N
));
331 -- If result is to be used as a Condition in the syntax, no need
332 -- to convert it back, since if it was changed to Standard.Boolean
333 -- using Adjust_Condition, that is just fine for this usage.
335 if KP
in N_Raise_xxx_Error
or else KP
in N_Has_Condition
then
338 -- If result is an operand of another logical operation, no need
339 -- to reset its type, since Standard.Boolean is just fine, and
340 -- such operations always do Adjust_Condition on their operands.
342 elsif KP
in N_Op_Boolean
343 or else KP
in N_Short_Circuit
344 or else KP
= N_Op_Not
348 -- Otherwise we perform a conversion from the current type, which
349 -- must be Standard.Boolean, to the desired type.
353 Rewrite
(N
, Convert_To
(T
, N
));
354 Analyze_And_Resolve
(N
, T
);
358 end Adjust_Result_Type
;
360 --------------------------
361 -- Append_Freeze_Action --
362 --------------------------
364 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
) is
368 Ensure_Freeze_Node
(T
);
369 Fnode
:= Freeze_Node
(T
);
371 if No
(Actions
(Fnode
)) then
372 Set_Actions
(Fnode
, New_List
(N
));
374 Append
(N
, Actions
(Fnode
));
377 end Append_Freeze_Action
;
379 ---------------------------
380 -- Append_Freeze_Actions --
381 ---------------------------
383 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
) is
391 Ensure_Freeze_Node
(T
);
392 Fnode
:= Freeze_Node
(T
);
394 if No
(Actions
(Fnode
)) then
395 Set_Actions
(Fnode
, L
);
397 Append_List
(L
, Actions
(Fnode
));
399 end Append_Freeze_Actions
;
401 ------------------------------------
402 -- Build_Allocate_Deallocate_Proc --
403 ------------------------------------
405 procedure Build_Allocate_Deallocate_Proc
407 Is_Allocate
: Boolean)
409 Desig_Typ
: Entity_Id
;
412 Proc_To_Call
: Node_Id
:= Empty
;
415 function Find_Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
;
416 -- Locate TSS primitive Finalize_Address in type Typ
418 function Find_Object
(E
: Node_Id
) return Node_Id
;
419 -- Given an arbitrary expression of an allocator, try to find an object
420 -- reference in it, otherwise return the original expression.
422 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean;
423 -- Determine whether subprogram Subp denotes a custom allocate or
426 ---------------------------
427 -- Find_Finalize_Address --
428 ---------------------------
430 function Find_Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
is
431 Utyp
: Entity_Id
:= Typ
;
434 -- Handle protected class-wide or task class-wide types
436 if Is_Class_Wide_Type
(Utyp
) then
437 if Is_Concurrent_Type
(Root_Type
(Utyp
)) then
438 Utyp
:= Root_Type
(Utyp
);
440 elsif Is_Private_Type
(Root_Type
(Utyp
))
441 and then Present
(Full_View
(Root_Type
(Utyp
)))
442 and then Is_Concurrent_Type
(Full_View
(Root_Type
(Utyp
)))
444 Utyp
:= Full_View
(Root_Type
(Utyp
));
448 -- Handle private types
450 if Is_Private_Type
(Utyp
) and then Present
(Full_View
(Utyp
)) then
451 Utyp
:= Full_View
(Utyp
);
454 -- Handle protected and task types
456 if Is_Concurrent_Type
(Utyp
)
457 and then Present
(Corresponding_Record_Type
(Utyp
))
459 Utyp
:= Corresponding_Record_Type
(Utyp
);
462 Utyp
:= Underlying_Type
(Base_Type
(Utyp
));
464 -- Deal with untagged derivation of private views. If the parent is
465 -- now known to be protected, the finalization routine is the one
466 -- defined on the corresponding record of the ancestor (corresponding
467 -- records do not automatically inherit operations, but maybe they
470 if Is_Untagged_Derivation
(Typ
) then
471 if Is_Protected_Type
(Typ
) then
472 Utyp
:= Corresponding_Record_Type
(Root_Type
(Base_Type
(Typ
)));
474 Utyp
:= Underlying_Type
(Root_Type
(Base_Type
(Typ
)));
476 if Is_Protected_Type
(Utyp
) then
477 Utyp
:= Corresponding_Record_Type
(Utyp
);
482 -- If the underlying_type is a subtype, we are dealing with the
483 -- completion of a private type. We need to access the base type and
484 -- generate a conversion to it.
486 if Utyp
/= Base_Type
(Utyp
) then
487 pragma Assert
(Is_Private_Type
(Typ
));
489 Utyp
:= Base_Type
(Utyp
);
492 -- When dealing with an internally built full view for a type with
493 -- unknown discriminants, use the original record type.
495 if Is_Underlying_Record_View
(Utyp
) then
496 Utyp
:= Etype
(Utyp
);
499 return TSS
(Utyp
, TSS_Finalize_Address
);
500 end Find_Finalize_Address
;
506 function Find_Object
(E
: Node_Id
) return Node_Id
is
510 pragma Assert
(Is_Allocate
);
514 if Nkind
(Expr
) = N_Explicit_Dereference
then
515 Expr
:= Prefix
(Expr
);
517 elsif Nkind
(Expr
) = N_Qualified_Expression
then
518 Expr
:= Expression
(Expr
);
520 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
522 -- When interface class-wide types are involved in allocation,
523 -- the expander introduces several levels of address arithmetic
524 -- to perform dispatch table displacement. In this scenario the
525 -- object appears as:
527 -- Tag_Ptr (Base_Address (<object>'Address))
529 -- Detect this case and utilize the whole expression as the
530 -- "object" since it now points to the proper dispatch table.
532 if Is_RTE
(Etype
(Expr
), RE_Tag_Ptr
) then
535 -- Continue to strip the object
538 Expr
:= Expression
(Expr
);
549 ---------------------------------
550 -- Is_Allocate_Deallocate_Proc --
551 ---------------------------------
553 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean is
555 -- Look for a subprogram body with only one statement which is a
556 -- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
558 if Ekind
(Subp
) = E_Procedure
559 and then Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Body
562 HSS
: constant Node_Id
:=
563 Handled_Statement_Sequence
(Parent
(Parent
(Subp
)));
567 if Present
(Statements
(HSS
))
568 and then Nkind
(First
(Statements
(HSS
))) =
569 N_Procedure_Call_Statement
571 Proc
:= Entity
(Name
(First
(Statements
(HSS
))));
574 Is_RTE
(Proc
, RE_Allocate_Any_Controlled
)
575 or else Is_RTE
(Proc
, RE_Deallocate_Any_Controlled
);
581 end Is_Allocate_Deallocate_Proc
;
583 -- Start of processing for Build_Allocate_Deallocate_Proc
586 -- Obtain the attributes of the allocation / deallocation
588 if Nkind
(N
) = N_Free_Statement
then
589 Expr
:= Expression
(N
);
590 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
591 Proc_To_Call
:= Procedure_To_Call
(N
);
594 if Nkind
(N
) = N_Object_Declaration
then
595 Expr
:= Expression
(N
);
600 -- In certain cases an allocator with a qualified expression may
601 -- be relocated and used as the initialization expression of a
605 -- Obj : Ptr_Typ := new Desig_Typ'(...);
608 -- Tmp : Ptr_Typ := new Desig_Typ'(...);
609 -- Obj : Ptr_Typ := Tmp;
611 -- Since the allocator is always marked as analyzed to avoid infinite
612 -- expansion, it will never be processed by this routine given that
613 -- the designated type needs finalization actions. Detect this case
614 -- and complete the expansion of the allocator.
616 if Nkind
(Expr
) = N_Identifier
617 and then Nkind
(Parent
(Entity
(Expr
))) = N_Object_Declaration
618 and then Nkind
(Expression
(Parent
(Entity
(Expr
)))) = N_Allocator
620 Build_Allocate_Deallocate_Proc
(Parent
(Entity
(Expr
)), True);
624 -- The allocator may have been rewritten into something else in which
625 -- case the expansion performed by this routine does not apply.
627 if Nkind
(Expr
) /= N_Allocator
then
631 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
632 Proc_To_Call
:= Procedure_To_Call
(Expr
);
635 Pool_Id
:= Associated_Storage_Pool
(Ptr_Typ
);
636 Desig_Typ
:= Available_View
(Designated_Type
(Ptr_Typ
));
638 -- Handle concurrent types
640 if Is_Concurrent_Type
(Desig_Typ
)
641 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
643 Desig_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
646 -- Do not process allocations / deallocations without a pool
651 -- Do not process allocations on / deallocations from the secondary
654 elsif Is_RTE
(Pool_Id
, RE_SS_Pool
) then
657 -- Do not replicate the machinery if the allocator / free has already
658 -- been expanded and has a custom Allocate / Deallocate.
660 elsif Present
(Proc_To_Call
)
661 and then Is_Allocate_Deallocate_Proc
(Proc_To_Call
)
666 if Needs_Finalization
(Desig_Typ
) then
668 -- Certain run-time configurations and targets do not provide support
669 -- for controlled types.
671 if Restriction_Active
(No_Finalization
) then
674 -- Do nothing if the access type may never allocate / deallocate
677 elsif No_Pool_Assigned
(Ptr_Typ
) then
680 -- Access-to-controlled types are not supported on .NET/JVM since
681 -- these targets cannot support pools and address arithmetic.
683 elsif VM_Target
/= No_VM
then
687 -- The allocation / deallocation of a controlled object must be
688 -- chained on / detached from a finalization master.
690 pragma Assert
(Present
(Finalization_Master
(Ptr_Typ
)));
692 -- The only other kind of allocation / deallocation supported by this
693 -- routine is on / from a subpool.
695 elsif Nkind
(Expr
) = N_Allocator
696 and then No
(Subpool_Handle_Name
(Expr
))
702 Loc
: constant Source_Ptr
:= Sloc
(N
);
703 Addr_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
704 Alig_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
705 Proc_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
706 Size_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
709 Fin_Addr_Id
: Entity_Id
;
710 Fin_Mas_Act
: Node_Id
;
711 Fin_Mas_Id
: Entity_Id
;
712 Proc_To_Call
: Entity_Id
;
713 Subpool
: Node_Id
:= Empty
;
716 -- Step 1: Construct all the actuals for the call to library routine
717 -- Allocate_Any_Controlled / Deallocate_Any_Controlled.
721 Actuals
:= New_List
(New_Occurrence_Of
(Pool_Id
, Loc
));
727 if Nkind
(Expr
) = N_Allocator
then
728 Subpool
:= Subpool_Handle_Name
(Expr
);
731 -- If a subpool is present it can be an arbitrary name, so make
732 -- the actual by copying the tree.
734 if Present
(Subpool
) then
735 Append_To
(Actuals
, New_Copy_Tree
(Subpool
, New_Sloc
=> Loc
));
737 Append_To
(Actuals
, Make_Null
(Loc
));
740 -- c) Finalization master
742 if Needs_Finalization
(Desig_Typ
) then
743 Fin_Mas_Id
:= Finalization_Master
(Ptr_Typ
);
744 Fin_Mas_Act
:= New_Occurrence_Of
(Fin_Mas_Id
, Loc
);
746 -- Handle the case where the master is actually a pointer to a
747 -- master. This case arises in build-in-place functions.
749 if Is_Access_Type
(Etype
(Fin_Mas_Id
)) then
750 Append_To
(Actuals
, Fin_Mas_Act
);
753 Make_Attribute_Reference
(Loc
,
754 Prefix
=> Fin_Mas_Act
,
755 Attribute_Name
=> Name_Unrestricted_Access
));
758 Append_To
(Actuals
, Make_Null
(Loc
));
761 -- d) Finalize_Address
763 -- Primitive Finalize_Address is never generated in CodePeer mode
764 -- since it contains an Unchecked_Conversion.
766 if Needs_Finalization
(Desig_Typ
) and then not CodePeer_Mode
then
767 Fin_Addr_Id
:= Find_Finalize_Address
(Desig_Typ
);
768 pragma Assert
(Present
(Fin_Addr_Id
));
771 Make_Attribute_Reference
(Loc
,
772 Prefix
=> New_Occurrence_Of
(Fin_Addr_Id
, Loc
),
773 Attribute_Name
=> Name_Unrestricted_Access
));
775 Append_To
(Actuals
, Make_Null
(Loc
));
783 Append_To
(Actuals
, New_Occurrence_Of
(Addr_Id
, Loc
));
784 Append_To
(Actuals
, New_Occurrence_Of
(Size_Id
, Loc
));
786 if Is_Allocate
or else not Is_Class_Wide_Type
(Desig_Typ
) then
787 Append_To
(Actuals
, New_Occurrence_Of
(Alig_Id
, Loc
));
789 -- For deallocation of class-wide types we obtain the value of
790 -- alignment from the Type Specific Record of the deallocated object.
791 -- This is needed because the frontend expansion of class-wide types
792 -- into equivalent types confuses the backend.
798 -- ... because 'Alignment applied to class-wide types is expanded
799 -- into the code that reads the value of alignment from the TSD
800 -- (see Expand_N_Attribute_Reference)
803 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
804 Make_Attribute_Reference
(Loc
,
806 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Expr
)),
807 Attribute_Name
=> Name_Alignment
)));
812 if Needs_Finalization
(Desig_Typ
) then
814 Flag_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F');
821 Temp
:= Find_Object
(Expression
(Expr
));
826 -- Processing for allocations where the expression is a subtype
830 and then Is_Entity_Name
(Temp
)
831 and then Is_Type
(Entity
(Temp
))
836 (Needs_Finalization
(Entity
(Temp
))), Loc
);
838 -- The allocation / deallocation of a class-wide object relies
839 -- on a runtime check to determine whether the object is truly
840 -- controlled or not. Depending on this check, the finalization
841 -- machinery will request or reclaim extra storage reserved for
844 elsif Is_Class_Wide_Type
(Desig_Typ
) then
846 -- Detect a special case where interface class-wide types
847 -- are involved as the object appears as:
849 -- Tag_Ptr (Base_Address (<object>'Address))
851 -- The expression already yields the proper tag, generate:
855 if Is_RTE
(Etype
(Temp
), RE_Tag_Ptr
) then
857 Make_Explicit_Dereference
(Loc
,
858 Prefix
=> Relocate_Node
(Temp
));
860 -- In the default case, obtain the tag of the object about
861 -- to be allocated / deallocated. Generate:
867 Make_Attribute_Reference
(Loc
,
868 Prefix
=> Relocate_Node
(Temp
),
869 Attribute_Name
=> Name_Tag
);
873 -- Needs_Finalization (<Param>)
876 Make_Function_Call
(Loc
,
878 New_Occurrence_Of
(RTE
(RE_Needs_Finalization
), Loc
),
879 Parameter_Associations
=> New_List
(Param
));
881 -- Processing for generic actuals
883 elsif Is_Generic_Actual_Type
(Desig_Typ
) then
885 New_Occurrence_Of
(Boolean_Literals
886 (Needs_Finalization
(Base_Type
(Desig_Typ
))), Loc
);
888 -- The object does not require any specialized checks, it is
889 -- known to be controlled.
892 Flag_Expr
:= New_Occurrence_Of
(Standard_True
, Loc
);
895 -- Create the temporary which represents the finalization state
896 -- of the expression. Generate:
898 -- F : constant Boolean := <Flag_Expr>;
901 Make_Object_Declaration
(Loc
,
902 Defining_Identifier
=> Flag_Id
,
903 Constant_Present
=> True,
905 New_Occurrence_Of
(Standard_Boolean
, Loc
),
906 Expression
=> Flag_Expr
));
908 Append_To
(Actuals
, New_Occurrence_Of
(Flag_Id
, Loc
));
911 -- The object is not controlled
914 Append_To
(Actuals
, New_Occurrence_Of
(Standard_False
, Loc
));
921 New_Occurrence_Of
(Boolean_Literals
(Present
(Subpool
)), Loc
));
924 -- Step 2: Build a wrapper Allocate / Deallocate which internally
925 -- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
927 -- Select the proper routine to call
930 Proc_To_Call
:= RTE
(RE_Allocate_Any_Controlled
);
932 Proc_To_Call
:= RTE
(RE_Deallocate_Any_Controlled
);
935 -- Create a custom Allocate / Deallocate routine which has identical
936 -- profile to that of System.Storage_Pools.
939 Make_Subprogram_Body
(Loc
,
944 Make_Procedure_Specification
(Loc
,
945 Defining_Unit_Name
=> Proc_Id
,
946 Parameter_Specifications
=> New_List
(
948 -- P : Root_Storage_Pool
950 Make_Parameter_Specification
(Loc
,
951 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
953 New_Occurrence_Of
(RTE
(RE_Root_Storage_Pool
), Loc
)),
957 Make_Parameter_Specification
(Loc
,
958 Defining_Identifier
=> Addr_Id
,
959 Out_Present
=> Is_Allocate
,
961 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
965 Make_Parameter_Specification
(Loc
,
966 Defining_Identifier
=> Size_Id
,
968 New_Occurrence_Of
(RTE
(RE_Storage_Count
), Loc
)),
972 Make_Parameter_Specification
(Loc
,
973 Defining_Identifier
=> Alig_Id
,
975 New_Occurrence_Of
(RTE
(RE_Storage_Count
), Loc
)))),
977 Declarations
=> No_List
,
979 Handled_Statement_Sequence
=>
980 Make_Handled_Sequence_Of_Statements
(Loc
,
981 Statements
=> New_List
(
982 Make_Procedure_Call_Statement
(Loc
,
983 Name
=> New_Occurrence_Of
(Proc_To_Call
, Loc
),
984 Parameter_Associations
=> Actuals
)))));
986 -- The newly generated Allocate / Deallocate becomes the default
987 -- procedure to call when the back end processes the allocation /
991 Set_Procedure_To_Call
(Expr
, Proc_Id
);
993 Set_Procedure_To_Call
(N
, Proc_Id
);
996 end Build_Allocate_Deallocate_Proc
;
998 ------------------------
999 -- Build_Runtime_Call --
1000 ------------------------
1002 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
is
1004 -- If entity is not available, we can skip making the call (this avoids
1005 -- junk duplicated error messages in a number of cases).
1007 if not RTE_Available
(RE
) then
1008 return Make_Null_Statement
(Loc
);
1011 Make_Procedure_Call_Statement
(Loc
,
1012 Name
=> New_Occurrence_Of
(RTE
(RE
), Loc
));
1014 end Build_Runtime_Call
;
1016 ------------------------
1017 -- Build_SS_Mark_Call --
1018 ------------------------
1020 function Build_SS_Mark_Call
1022 Mark
: Entity_Id
) return Node_Id
1026 -- Mark : constant Mark_Id := SS_Mark;
1029 Make_Object_Declaration
(Loc
,
1030 Defining_Identifier
=> Mark
,
1031 Constant_Present
=> True,
1032 Object_Definition
=>
1033 New_Occurrence_Of
(RTE
(RE_Mark_Id
), Loc
),
1035 Make_Function_Call
(Loc
,
1036 Name
=> New_Occurrence_Of
(RTE
(RE_SS_Mark
), Loc
)));
1037 end Build_SS_Mark_Call
;
1039 ---------------------------
1040 -- Build_SS_Release_Call --
1041 ---------------------------
1043 function Build_SS_Release_Call
1045 Mark
: Entity_Id
) return Node_Id
1049 -- SS_Release (Mark);
1052 Make_Procedure_Call_Statement
(Loc
,
1054 New_Occurrence_Of
(RTE
(RE_SS_Release
), Loc
),
1055 Parameter_Associations
=> New_List
(
1056 New_Occurrence_Of
(Mark
, Loc
)));
1057 end Build_SS_Release_Call
;
1059 ----------------------------
1060 -- Build_Task_Array_Image --
1061 ----------------------------
1063 -- This function generates the body for a function that constructs the
1064 -- image string for a task that is an array component. The function is
1065 -- local to the init proc for the array type, and is called for each one
1066 -- of the components. The constructed image has the form of an indexed
1067 -- component, whose prefix is the outer variable of the array type.
1068 -- The n-dimensional array type has known indexes Index, Index2...
1070 -- Id_Ref is an indexed component form created by the enclosing init proc.
1071 -- Its successive indexes are Val1, Val2, ... which are the loop variables
1072 -- in the loops that call the individual task init proc on each component.
1074 -- The generated function has the following structure:
1076 -- function F return String is
1077 -- Pref : string renames Task_Name;
1078 -- T1 : String := Index1'Image (Val1);
1080 -- Tn : String := indexn'image (Valn);
1081 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
1082 -- -- Len includes commas and the end parentheses.
1083 -- Res : String (1..Len);
1084 -- Pos : Integer := Pref'Length;
1087 -- Res (1 .. Pos) := Pref;
1089 -- Res (Pos) := '(';
1091 -- Res (Pos .. Pos + T1'Length - 1) := T1;
1092 -- Pos := Pos + T1'Length;
1093 -- Res (Pos) := '.';
1096 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
1097 -- Res (Len) := ')';
1102 -- Needless to say, multidimensional arrays of tasks are rare enough that
1103 -- the bulkiness of this code is not really a concern.
1105 function Build_Task_Array_Image
1109 Dyn
: Boolean := False) return Node_Id
1111 Dims
: constant Nat
:= Number_Dimensions
(A_Type
);
1112 -- Number of dimensions for array of tasks
1114 Temps
: array (1 .. Dims
) of Entity_Id
;
1115 -- Array of temporaries to hold string for each index
1121 -- Total length of generated name
1124 -- Running index for substring assignments
1126 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1127 -- Name of enclosing variable, prefix of resulting name
1130 -- String to hold result
1133 -- Value of successive indexes
1136 -- Expression to compute total size of string
1139 -- Entity for name at one index position
1141 Decls
: constant List_Id
:= New_List
;
1142 Stats
: constant List_Id
:= New_List
;
1145 -- For a dynamic task, the name comes from the target variable. For a
1146 -- static one it is a formal of the enclosing init proc.
1149 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1151 Make_Object_Declaration
(Loc
,
1152 Defining_Identifier
=> Pref
,
1153 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1155 Make_String_Literal
(Loc
,
1156 Strval
=> String_From_Name_Buffer
)));
1160 Make_Object_Renaming_Declaration
(Loc
,
1161 Defining_Identifier
=> Pref
,
1162 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1163 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1166 Indx
:= First_Index
(A_Type
);
1167 Val
:= First
(Expressions
(Id_Ref
));
1169 for J
in 1 .. Dims
loop
1170 T
:= Make_Temporary
(Loc
, 'T');
1174 Make_Object_Declaration
(Loc
,
1175 Defining_Identifier
=> T
,
1176 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1178 Make_Attribute_Reference
(Loc
,
1179 Attribute_Name
=> Name_Image
,
1180 Prefix
=> New_Occurrence_Of
(Etype
(Indx
), Loc
),
1181 Expressions
=> New_List
(New_Copy_Tree
(Val
)))));
1187 Sum
:= Make_Integer_Literal
(Loc
, Dims
+ 1);
1193 Make_Attribute_Reference
(Loc
,
1194 Attribute_Name
=> Name_Length
,
1195 Prefix
=> New_Occurrence_Of
(Pref
, Loc
),
1196 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1198 for J
in 1 .. Dims
loop
1203 Make_Attribute_Reference
(Loc
,
1204 Attribute_Name
=> Name_Length
,
1206 New_Occurrence_Of
(Temps
(J
), Loc
),
1207 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1210 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1212 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('(')));
1215 Make_Assignment_Statement
(Loc
,
1217 Make_Indexed_Component
(Loc
,
1218 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1219 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1221 Make_Character_Literal
(Loc
,
1223 Char_Literal_Value
=> UI_From_Int
(Character'Pos ('(')))));
1226 Make_Assignment_Statement
(Loc
,
1227 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1230 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1231 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1233 for J
in 1 .. Dims
loop
1236 Make_Assignment_Statement
(Loc
,
1239 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1242 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1244 Make_Op_Subtract
(Loc
,
1247 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1249 Make_Attribute_Reference
(Loc
,
1250 Attribute_Name
=> Name_Length
,
1252 New_Occurrence_Of
(Temps
(J
), Loc
),
1254 New_List
(Make_Integer_Literal
(Loc
, 1)))),
1255 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))),
1257 Expression
=> New_Occurrence_Of
(Temps
(J
), Loc
)));
1261 Make_Assignment_Statement
(Loc
,
1262 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1265 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1267 Make_Attribute_Reference
(Loc
,
1268 Attribute_Name
=> Name_Length
,
1269 Prefix
=> New_Occurrence_Of
(Temps
(J
), Loc
),
1271 New_List
(Make_Integer_Literal
(Loc
, 1))))));
1273 Set_Character_Literal_Name
(Char_Code
(Character'Pos (',')));
1276 Make_Assignment_Statement
(Loc
,
1277 Name
=> Make_Indexed_Component
(Loc
,
1278 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1279 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1281 Make_Character_Literal
(Loc
,
1283 Char_Literal_Value
=> UI_From_Int
(Character'Pos (',')))));
1286 Make_Assignment_Statement
(Loc
,
1287 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1290 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1291 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1295 Set_Character_Literal_Name
(Char_Code
(Character'Pos (')')));
1298 Make_Assignment_Statement
(Loc
,
1300 Make_Indexed_Component
(Loc
,
1301 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1302 Expressions
=> New_List
(New_Occurrence_Of
(Len
, Loc
))),
1304 Make_Character_Literal
(Loc
,
1306 Char_Literal_Value
=> UI_From_Int
(Character'Pos (')')))));
1307 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1308 end Build_Task_Array_Image
;
1310 ----------------------------
1311 -- Build_Task_Image_Decls --
1312 ----------------------------
1314 function Build_Task_Image_Decls
1318 In_Init_Proc
: Boolean := False) return List_Id
1320 Decls
: constant List_Id
:= New_List
;
1321 T_Id
: Entity_Id
:= Empty
;
1323 Expr
: Node_Id
:= Empty
;
1324 Fun
: Node_Id
:= Empty
;
1325 Is_Dyn
: constant Boolean :=
1326 Nkind
(Parent
(Id_Ref
)) = N_Assignment_Statement
1328 Nkind
(Expression
(Parent
(Id_Ref
))) = N_Allocator
;
1331 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
1332 -- generate a dummy declaration only.
1334 if Restriction_Active
(No_Implicit_Heap_Allocations
)
1335 or else Global_Discard_Names
1337 T_Id
:= Make_Temporary
(Loc
, 'J');
1342 Make_Object_Declaration
(Loc
,
1343 Defining_Identifier
=> T_Id
,
1344 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1346 Make_String_Literal
(Loc
,
1347 Strval
=> String_From_Name_Buffer
)));
1350 if Nkind
(Id_Ref
) = N_Identifier
1351 or else Nkind
(Id_Ref
) = N_Defining_Identifier
1353 -- For a simple variable, the image of the task is built from
1354 -- the name of the variable. To avoid possible conflict with the
1355 -- anonymous type created for a single protected object, add a
1359 Make_Defining_Identifier
(Loc
,
1360 New_External_Name
(Chars
(Id_Ref
), 'T', 1));
1362 Get_Name_String
(Chars
(Id_Ref
));
1365 Make_String_Literal
(Loc
,
1366 Strval
=> String_From_Name_Buffer
);
1368 elsif Nkind
(Id_Ref
) = N_Selected_Component
then
1370 Make_Defining_Identifier
(Loc
,
1371 New_External_Name
(Chars
(Selector_Name
(Id_Ref
)), 'T'));
1372 Fun
:= Build_Task_Record_Image
(Loc
, Id_Ref
, Is_Dyn
);
1374 elsif Nkind
(Id_Ref
) = N_Indexed_Component
then
1376 Make_Defining_Identifier
(Loc
,
1377 New_External_Name
(Chars
(A_Type
), 'N'));
1379 Fun
:= Build_Task_Array_Image
(Loc
, Id_Ref
, A_Type
, Is_Dyn
);
1383 if Present
(Fun
) then
1384 Append
(Fun
, Decls
);
1385 Expr
:= Make_Function_Call
(Loc
,
1386 Name
=> New_Occurrence_Of
(Defining_Entity
(Fun
), Loc
));
1388 if not In_Init_Proc
and then VM_Target
= No_VM
then
1389 Set_Uses_Sec_Stack
(Defining_Entity
(Fun
));
1393 Decl
:= Make_Object_Declaration
(Loc
,
1394 Defining_Identifier
=> T_Id
,
1395 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1396 Constant_Present
=> True,
1397 Expression
=> Expr
);
1399 Append
(Decl
, Decls
);
1401 end Build_Task_Image_Decls
;
1403 -------------------------------
1404 -- Build_Task_Image_Function --
1405 -------------------------------
1407 function Build_Task_Image_Function
1411 Res
: Entity_Id
) return Node_Id
1417 Make_Simple_Return_Statement
(Loc
,
1418 Expression
=> New_Occurrence_Of
(Res
, Loc
)));
1420 Spec
:= Make_Function_Specification
(Loc
,
1421 Defining_Unit_Name
=> Make_Temporary
(Loc
, 'F'),
1422 Result_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
));
1424 -- Calls to 'Image use the secondary stack, which must be cleaned up
1425 -- after the task name is built.
1427 return Make_Subprogram_Body
(Loc
,
1428 Specification
=> Spec
,
1429 Declarations
=> Decls
,
1430 Handled_Statement_Sequence
=>
1431 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
));
1432 end Build_Task_Image_Function
;
1434 -----------------------------
1435 -- Build_Task_Image_Prefix --
1436 -----------------------------
1438 procedure Build_Task_Image_Prefix
1440 Len
: out Entity_Id
;
1441 Res
: out Entity_Id
;
1442 Pos
: out Entity_Id
;
1449 Len
:= Make_Temporary
(Loc
, 'L', Sum
);
1452 Make_Object_Declaration
(Loc
,
1453 Defining_Identifier
=> Len
,
1454 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1455 Expression
=> Sum
));
1457 Res
:= Make_Temporary
(Loc
, 'R');
1460 Make_Object_Declaration
(Loc
,
1461 Defining_Identifier
=> Res
,
1462 Object_Definition
=>
1463 Make_Subtype_Indication
(Loc
,
1464 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1466 Make_Index_Or_Discriminant_Constraint
(Loc
,
1470 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1471 High_Bound
=> New_Occurrence_Of
(Len
, Loc
)))))));
1473 -- Indicate that the result is an internal temporary, so it does not
1474 -- receive a bogus initialization when declaration is expanded. This
1475 -- is both efficient, and prevents anomalies in the handling of
1476 -- dynamic objects on the secondary stack.
1478 Set_Is_Internal
(Res
);
1479 Pos
:= Make_Temporary
(Loc
, 'P');
1482 Make_Object_Declaration
(Loc
,
1483 Defining_Identifier
=> Pos
,
1484 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
1486 -- Pos := Prefix'Length;
1489 Make_Assignment_Statement
(Loc
,
1490 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1492 Make_Attribute_Reference
(Loc
,
1493 Attribute_Name
=> Name_Length
,
1494 Prefix
=> New_Occurrence_Of
(Prefix
, Loc
),
1495 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1)))));
1497 -- Res (1 .. Pos) := Prefix;
1500 Make_Assignment_Statement
(Loc
,
1503 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1506 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1507 High_Bound
=> New_Occurrence_Of
(Pos
, Loc
))),
1509 Expression
=> New_Occurrence_Of
(Prefix
, Loc
)));
1512 Make_Assignment_Statement
(Loc
,
1513 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1516 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1517 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1518 end Build_Task_Image_Prefix
;
1520 -----------------------------
1521 -- Build_Task_Record_Image --
1522 -----------------------------
1524 function Build_Task_Record_Image
1527 Dyn
: Boolean := False) return Node_Id
1530 -- Total length of generated name
1533 -- Index into result
1536 -- String to hold result
1538 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1539 -- Name of enclosing variable, prefix of resulting name
1542 -- Expression to compute total size of string
1545 -- Entity for selector name
1547 Decls
: constant List_Id
:= New_List
;
1548 Stats
: constant List_Id
:= New_List
;
1551 -- For a dynamic task, the name comes from the target variable. For a
1552 -- static one it is a formal of the enclosing init proc.
1555 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1557 Make_Object_Declaration
(Loc
,
1558 Defining_Identifier
=> Pref
,
1559 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1561 Make_String_Literal
(Loc
,
1562 Strval
=> String_From_Name_Buffer
)));
1566 Make_Object_Renaming_Declaration
(Loc
,
1567 Defining_Identifier
=> Pref
,
1568 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1569 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1572 Sel
:= Make_Temporary
(Loc
, 'S');
1574 Get_Name_String
(Chars
(Selector_Name
(Id_Ref
)));
1577 Make_Object_Declaration
(Loc
,
1578 Defining_Identifier
=> Sel
,
1579 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1581 Make_String_Literal
(Loc
,
1582 Strval
=> String_From_Name_Buffer
)));
1584 Sum
:= Make_Integer_Literal
(Loc
, Nat
(Name_Len
+ 1));
1590 Make_Attribute_Reference
(Loc
,
1591 Attribute_Name
=> Name_Length
,
1593 New_Occurrence_Of
(Pref
, Loc
),
1594 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1596 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1598 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('.')));
1600 -- Res (Pos) := '.';
1603 Make_Assignment_Statement
(Loc
,
1604 Name
=> Make_Indexed_Component
(Loc
,
1605 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1606 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1608 Make_Character_Literal
(Loc
,
1610 Char_Literal_Value
=>
1611 UI_From_Int
(Character'Pos ('.')))));
1614 Make_Assignment_Statement
(Loc
,
1615 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1618 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1619 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1621 -- Res (Pos .. Len) := Selector;
1624 Make_Assignment_Statement
(Loc
,
1625 Name
=> Make_Slice
(Loc
,
1626 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1629 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1630 High_Bound
=> New_Occurrence_Of
(Len
, Loc
))),
1631 Expression
=> New_Occurrence_Of
(Sel
, Loc
)));
1633 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1634 end Build_Task_Record_Image
;
1636 -----------------------------
1637 -- Check_Float_Op_Overflow --
1638 -----------------------------
1640 procedure Check_Float_Op_Overflow
(N
: Node_Id
) is
1642 -- Return if no check needed
1644 if not Is_Floating_Point_Type
(Etype
(N
))
1645 or else not (Do_Overflow_Check
(N
) and then Check_Float_Overflow
)
1647 -- In CodePeer_Mode, rely on the overflow check flag being set instead
1648 -- and do not expand the code for float overflow checking.
1650 or else CodePeer_Mode
1655 -- Otherwise we replace the expression by
1657 -- do Tnn : constant ftype := expression;
1658 -- constraint_error when not Tnn'Valid;
1662 Loc
: constant Source_Ptr
:= Sloc
(N
);
1663 Tnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T', N
);
1664 Typ
: constant Entity_Id
:= Etype
(N
);
1667 -- Turn off the Do_Overflow_Check flag, since we are doing that work
1668 -- right here. We also set the node as analyzed to prevent infinite
1669 -- recursion from repeating the operation in the expansion.
1671 Set_Do_Overflow_Check
(N
, False);
1672 Set_Analyzed
(N
, True);
1674 -- Do the rewrite to include the check
1677 Make_Expression_With_Actions
(Loc
,
1678 Actions
=> New_List
(
1679 Make_Object_Declaration
(Loc
,
1680 Defining_Identifier
=> Tnn
,
1681 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1682 Constant_Present
=> True,
1683 Expression
=> Relocate_Node
(N
)),
1684 Make_Raise_Constraint_Error
(Loc
,
1688 Make_Attribute_Reference
(Loc
,
1689 Prefix
=> New_Occurrence_Of
(Tnn
, Loc
),
1690 Attribute_Name
=> Name_Valid
)),
1691 Reason
=> CE_Overflow_Check_Failed
)),
1692 Expression
=> New_Occurrence_Of
(Tnn
, Loc
)));
1694 Analyze_And_Resolve
(N
, Typ
);
1696 end Check_Float_Op_Overflow
;
1698 ----------------------------------
1699 -- Component_May_Be_Bit_Aligned --
1700 ----------------------------------
1702 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean is
1706 -- If no component clause, then everything is fine, since the back end
1707 -- never bit-misaligns by default, even if there is a pragma Packed for
1710 if No
(Comp
) or else No
(Component_Clause
(Comp
)) then
1714 UT
:= Underlying_Type
(Etype
(Comp
));
1716 -- It is only array and record types that cause trouble
1718 if not Is_Record_Type
(UT
) and then not Is_Array_Type
(UT
) then
1721 -- If we know that we have a small (64 bits or less) record or small
1722 -- bit-packed array, then everything is fine, since the back end can
1723 -- handle these cases correctly.
1725 elsif Esize
(Comp
) <= 64
1726 and then (Is_Record_Type
(UT
) or else Is_Bit_Packed_Array
(UT
))
1730 -- Otherwise if the component is not byte aligned, we know we have the
1731 -- nasty unaligned case.
1733 elsif Normalized_First_Bit
(Comp
) /= Uint_0
1734 or else Esize
(Comp
) mod System_Storage_Unit
/= Uint_0
1738 -- If we are large and byte aligned, then OK at this level
1743 end Component_May_Be_Bit_Aligned
;
1745 ----------------------------------------
1746 -- Containing_Package_With_Ext_Axioms --
1747 ----------------------------------------
1749 function Containing_Package_With_Ext_Axioms
1750 (E
: Entity_Id
) return Entity_Id
1755 if Ekind
(E
) = E_Package
then
1756 if Nkind
(Parent
(E
)) = N_Defining_Program_Unit_Name
then
1757 Decl
:= Parent
(Parent
(E
));
1763 -- E is the package or generic package which is externally axiomatized
1765 if Ekind_In
(E
, E_Package
, E_Generic_Package
)
1766 and then Has_Annotate_Pragma_For_External_Axiomatization
(E
)
1771 -- If E's scope is axiomatized, E is axiomatized.
1774 First_Ax_Parent_Scope
: Entity_Id
:= Empty
;
1777 if Present
(Scope
(E
)) then
1778 First_Ax_Parent_Scope
:=
1779 Containing_Package_With_Ext_Axioms
(Scope
(E
));
1782 if Present
(First_Ax_Parent_Scope
) then
1783 return First_Ax_Parent_Scope
;
1786 -- otherwise, if E is a package instance, it is axiomatized if the
1787 -- corresponding generic package is axiomatized.
1789 if Ekind
(E
) = E_Package
1790 and then Present
(Generic_Parent
(Decl
))
1793 Containing_Package_With_Ext_Axioms
(Generic_Parent
(Decl
));
1798 end Containing_Package_With_Ext_Axioms
;
1800 -------------------------------
1801 -- Convert_To_Actual_Subtype --
1802 -------------------------------
1804 procedure Convert_To_Actual_Subtype
(Exp
: Entity_Id
) is
1808 Act_ST
:= Get_Actual_Subtype
(Exp
);
1810 if Act_ST
= Etype
(Exp
) then
1813 Rewrite
(Exp
, Convert_To
(Act_ST
, Relocate_Node
(Exp
)));
1814 Analyze_And_Resolve
(Exp
, Act_ST
);
1816 end Convert_To_Actual_Subtype
;
1818 -----------------------------------
1819 -- Corresponding_Runtime_Package --
1820 -----------------------------------
1822 function Corresponding_Runtime_Package
(Typ
: Entity_Id
) return RTU_Id
is
1823 Pkg_Id
: RTU_Id
:= RTU_Null
;
1826 pragma Assert
(Is_Concurrent_Type
(Typ
));
1828 if Ekind
(Typ
) in Protected_Kind
then
1829 if Has_Entries
(Typ
)
1831 -- A protected type without entries that covers an interface and
1832 -- overrides the abstract routines with protected procedures is
1833 -- considered equivalent to a protected type with entries in the
1834 -- context of dispatching select statements. It is sufficient to
1835 -- check for the presence of an interface list in the declaration
1836 -- node to recognize this case.
1838 or else Present
(Interface_List
(Parent
(Typ
)))
1840 -- Protected types with interrupt handlers (when not using a
1841 -- restricted profile) are also considered equivalent to
1842 -- protected types with entries. The types which are used
1843 -- (Static_Interrupt_Protection and Dynamic_Interrupt_Protection)
1844 -- are derived from Protection_Entries.
1846 or else (Has_Attach_Handler
(Typ
) and then not Restricted_Profile
)
1847 or else Has_Interrupt_Handler
(Typ
)
1850 or else Restriction_Active
(No_Entry_Queue
) = False
1851 or else Restriction_Active
(No_Select_Statements
) = False
1852 or else Number_Entries
(Typ
) > 1
1853 or else (Has_Attach_Handler
(Typ
)
1854 and then not Restricted_Profile
)
1856 Pkg_Id
:= System_Tasking_Protected_Objects_Entries
;
1858 Pkg_Id
:= System_Tasking_Protected_Objects_Single_Entry
;
1862 Pkg_Id
:= System_Tasking_Protected_Objects
;
1867 end Corresponding_Runtime_Package
;
1869 -----------------------------------
1870 -- Current_Sem_Unit_Declarations --
1871 -----------------------------------
1873 function Current_Sem_Unit_Declarations
return List_Id
is
1874 U
: Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
1878 -- If the current unit is a package body, locate the visible
1879 -- declarations of the package spec.
1881 if Nkind
(U
) = N_Package_Body
then
1882 U
:= Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
1885 if Nkind
(U
) = N_Package_Declaration
then
1886 U
:= Specification
(U
);
1887 Decls
:= Visible_Declarations
(U
);
1891 Set_Visible_Declarations
(U
, Decls
);
1895 Decls
:= Declarations
(U
);
1899 Set_Declarations
(U
, Decls
);
1904 end Current_Sem_Unit_Declarations
;
1906 -----------------------
1907 -- Duplicate_Subexpr --
1908 -----------------------
1910 function Duplicate_Subexpr
1912 Name_Req
: Boolean := False;
1913 Renaming_Req
: Boolean := False) return Node_Id
1916 Remove_Side_Effects
(Exp
, Name_Req
, Renaming_Req
);
1917 return New_Copy_Tree
(Exp
);
1918 end Duplicate_Subexpr
;
1920 ---------------------------------
1921 -- Duplicate_Subexpr_No_Checks --
1922 ---------------------------------
1924 function Duplicate_Subexpr_No_Checks
1926 Name_Req
: Boolean := False;
1927 Renaming_Req
: Boolean := False;
1928 Related_Id
: Entity_Id
:= Empty
;
1929 Is_Low_Bound
: Boolean := False;
1930 Is_High_Bound
: Boolean := False) return Node_Id
1937 Name_Req
=> Name_Req
,
1938 Renaming_Req
=> Renaming_Req
,
1939 Related_Id
=> Related_Id
,
1940 Is_Low_Bound
=> Is_Low_Bound
,
1941 Is_High_Bound
=> Is_High_Bound
);
1943 New_Exp
:= New_Copy_Tree
(Exp
);
1944 Remove_Checks
(New_Exp
);
1946 end Duplicate_Subexpr_No_Checks
;
1948 -----------------------------------
1949 -- Duplicate_Subexpr_Move_Checks --
1950 -----------------------------------
1952 function Duplicate_Subexpr_Move_Checks
1954 Name_Req
: Boolean := False;
1955 Renaming_Req
: Boolean := False) return Node_Id
1960 Remove_Side_Effects
(Exp
, Name_Req
, Renaming_Req
);
1961 New_Exp
:= New_Copy_Tree
(Exp
);
1962 Remove_Checks
(Exp
);
1964 end Duplicate_Subexpr_Move_Checks
;
1966 --------------------
1967 -- Ensure_Defined --
1968 --------------------
1970 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
) is
1974 -- An itype reference must only be created if this is a local itype, so
1975 -- that gigi can elaborate it on the proper objstack.
1977 if Is_Itype
(Typ
) and then Scope
(Typ
) = Current_Scope
then
1978 IR
:= Make_Itype_Reference
(Sloc
(N
));
1979 Set_Itype
(IR
, Typ
);
1980 Insert_Action
(N
, IR
);
1984 --------------------
1985 -- Entry_Names_OK --
1986 --------------------
1988 function Entry_Names_OK
return Boolean is
1991 not Restricted_Profile
1992 and then not Global_Discard_Names
1993 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
1994 and then not Restriction_Active
(No_Local_Allocators
);
2001 procedure Evaluate_Name
(Nam
: Node_Id
) is
2002 K
: constant Node_Kind
:= Nkind
(Nam
);
2005 -- For an explicit dereference, we simply force the evaluation of the
2006 -- name expression. The dereference provides a value that is the address
2007 -- for the renamed object, and it is precisely this value that we want
2010 if K
= N_Explicit_Dereference
then
2011 Force_Evaluation
(Prefix
(Nam
));
2013 -- For a selected component, we simply evaluate the prefix
2015 elsif K
= N_Selected_Component
then
2016 Evaluate_Name
(Prefix
(Nam
));
2018 -- For an indexed component, or an attribute reference, we evaluate the
2019 -- prefix, which is itself a name, recursively, and then force the
2020 -- evaluation of all the subscripts (or attribute expressions).
2022 elsif Nkind_In
(K
, N_Indexed_Component
, N_Attribute_Reference
) then
2023 Evaluate_Name
(Prefix
(Nam
));
2029 E
:= First
(Expressions
(Nam
));
2030 while Present
(E
) loop
2031 Force_Evaluation
(E
);
2033 if Original_Node
(E
) /= E
then
2034 Set_Do_Range_Check
(E
, Do_Range_Check
(Original_Node
(E
)));
2041 -- For a slice, we evaluate the prefix, as for the indexed component
2042 -- case and then, if there is a range present, either directly or as the
2043 -- constraint of a discrete subtype indication, we evaluate the two
2044 -- bounds of this range.
2046 elsif K
= N_Slice
then
2047 Evaluate_Name
(Prefix
(Nam
));
2048 Evaluate_Slice_Bounds
(Nam
);
2050 -- For a type conversion, the expression of the conversion must be the
2051 -- name of an object, and we simply need to evaluate this name.
2053 elsif K
= N_Type_Conversion
then
2054 Evaluate_Name
(Expression
(Nam
));
2056 -- For a function call, we evaluate the call
2058 elsif K
= N_Function_Call
then
2059 Force_Evaluation
(Nam
);
2061 -- The remaining cases are direct name, operator symbol and character
2062 -- literal. In all these cases, we do nothing, since we want to
2063 -- reevaluate each time the renamed object is used.
2070 ---------------------------
2071 -- Evaluate_Slice_Bounds --
2072 ---------------------------
2074 procedure Evaluate_Slice_Bounds
(Slice
: Node_Id
) is
2075 DR
: constant Node_Id
:= Discrete_Range
(Slice
);
2080 if Nkind
(DR
) = N_Range
then
2081 Force_Evaluation
(Low_Bound
(DR
));
2082 Force_Evaluation
(High_Bound
(DR
));
2084 elsif Nkind
(DR
) = N_Subtype_Indication
then
2085 Constr
:= Constraint
(DR
);
2087 if Nkind
(Constr
) = N_Range_Constraint
then
2088 Rexpr
:= Range_Expression
(Constr
);
2090 Force_Evaluation
(Low_Bound
(Rexpr
));
2091 Force_Evaluation
(High_Bound
(Rexpr
));
2094 end Evaluate_Slice_Bounds
;
2096 ---------------------
2097 -- Evolve_And_Then --
2098 ---------------------
2100 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
2106 Make_And_Then
(Sloc
(Cond1
),
2108 Right_Opnd
=> Cond1
);
2110 end Evolve_And_Then
;
2112 --------------------
2113 -- Evolve_Or_Else --
2114 --------------------
2116 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
2122 Make_Or_Else
(Sloc
(Cond1
),
2124 Right_Opnd
=> Cond1
);
2128 -----------------------------------------
2129 -- Expand_Static_Predicates_In_Choices --
2130 -----------------------------------------
2132 procedure Expand_Static_Predicates_In_Choices
(N
: Node_Id
) is
2133 pragma Assert
(Nkind_In
(N
, N_Case_Statement_Alternative
, N_Variant
));
2135 Choices
: constant List_Id
:= Discrete_Choices
(N
);
2143 Choice
:= First
(Choices
);
2144 while Present
(Choice
) loop
2145 Next_C
:= Next
(Choice
);
2147 -- Check for name of subtype with static predicate
2149 if Is_Entity_Name
(Choice
)
2150 and then Is_Type
(Entity
(Choice
))
2151 and then Has_Predicates
(Entity
(Choice
))
2153 -- Loop through entries in predicate list, converting to choices
2154 -- and inserting in the list before the current choice. Note that
2155 -- if the list is empty, corresponding to a False predicate, then
2156 -- no choices are inserted.
2158 P
:= First
(Static_Discrete_Predicate
(Entity
(Choice
)));
2159 while Present
(P
) loop
2161 -- If low bound and high bounds are equal, copy simple choice
2163 if Expr_Value
(Low_Bound
(P
)) = Expr_Value
(High_Bound
(P
)) then
2164 C
:= New_Copy
(Low_Bound
(P
));
2166 -- Otherwise copy a range
2172 -- Change Sloc to referencing choice (rather than the Sloc of
2173 -- the predicate declaration element itself).
2175 Set_Sloc
(C
, Sloc
(Choice
));
2176 Insert_Before
(Choice
, C
);
2180 -- Delete the predicated entry
2185 -- Move to next choice to check
2189 end Expand_Static_Predicates_In_Choices
;
2191 ------------------------------
2192 -- Expand_Subtype_From_Expr --
2193 ------------------------------
2195 -- This function is applicable for both static and dynamic allocation of
2196 -- objects which are constrained by an initial expression. Basically it
2197 -- transforms an unconstrained subtype indication into a constrained one.
2199 -- The expression may also be transformed in certain cases in order to
2200 -- avoid multiple evaluation. In the static allocation case, the general
2205 -- is transformed into
2207 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
2209 -- Here are the main cases :
2211 -- <if Expr is a Slice>
2212 -- Val : T ([Index_Subtype (Expr)]) := Expr;
2214 -- <elsif Expr is a String Literal>
2215 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
2217 -- <elsif Expr is Constrained>
2218 -- subtype T is Type_Of_Expr
2221 -- <elsif Expr is an entity_name>
2222 -- Val : T (constraints taken from Expr) := Expr;
2225 -- type Axxx is access all T;
2226 -- Rval : Axxx := Expr'ref;
2227 -- Val : T (constraints taken from Rval) := Rval.all;
2229 -- ??? note: when the Expression is allocated in the secondary stack
2230 -- we could use it directly instead of copying it by declaring
2231 -- Val : T (...) renames Rval.all
2233 procedure Expand_Subtype_From_Expr
2235 Unc_Type
: Entity_Id
;
2236 Subtype_Indic
: Node_Id
;
2239 Loc
: constant Source_Ptr
:= Sloc
(N
);
2240 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
2244 -- In general we cannot build the subtype if expansion is disabled,
2245 -- because internal entities may not have been defined. However, to
2246 -- avoid some cascaded errors, we try to continue when the expression is
2247 -- an array (or string), because it is safe to compute the bounds. It is
2248 -- in fact required to do so even in a generic context, because there
2249 -- may be constants that depend on the bounds of a string literal, both
2250 -- standard string types and more generally arrays of characters.
2252 -- In GNATprove mode, these extra subtypes are not needed
2254 if GNATprove_Mode
then
2258 if not Expander_Active
2259 and then (No
(Etype
(Exp
)) or else not Is_String_Type
(Etype
(Exp
)))
2264 if Nkind
(Exp
) = N_Slice
then
2266 Slice_Type
: constant Entity_Id
:= Etype
(First_Index
(Exp_Typ
));
2269 Rewrite
(Subtype_Indic
,
2270 Make_Subtype_Indication
(Loc
,
2271 Subtype_Mark
=> New_Occurrence_Of
(Unc_Type
, Loc
),
2273 Make_Index_Or_Discriminant_Constraint
(Loc
,
2274 Constraints
=> New_List
2275 (New_Occurrence_Of
(Slice_Type
, Loc
)))));
2277 -- This subtype indication may be used later for constraint checks
2278 -- we better make sure that if a variable was used as a bound of
2279 -- of the original slice, its value is frozen.
2281 Evaluate_Slice_Bounds
(Exp
);
2284 elsif Ekind
(Exp_Typ
) = E_String_Literal_Subtype
then
2285 Rewrite
(Subtype_Indic
,
2286 Make_Subtype_Indication
(Loc
,
2287 Subtype_Mark
=> New_Occurrence_Of
(Unc_Type
, Loc
),
2289 Make_Index_Or_Discriminant_Constraint
(Loc
,
2290 Constraints
=> New_List
(
2291 Make_Literal_Range
(Loc
,
2292 Literal_Typ
=> Exp_Typ
)))));
2294 -- If the type of the expression is an internally generated type it
2295 -- may not be necessary to create a new subtype. However there are two
2296 -- exceptions: references to the current instances, and aliased array
2297 -- object declarations for which the backend needs to create a template.
2299 elsif Is_Constrained
(Exp_Typ
)
2300 and then not Is_Class_Wide_Type
(Unc_Type
)
2302 (Nkind
(N
) /= N_Object_Declaration
2303 or else not Is_Entity_Name
(Expression
(N
))
2304 or else not Comes_From_Source
(Entity
(Expression
(N
)))
2305 or else not Is_Array_Type
(Exp_Typ
)
2306 or else not Aliased_Present
(N
))
2308 if Is_Itype
(Exp_Typ
) then
2310 -- Within an initialization procedure, a selected component
2311 -- denotes a component of the enclosing record, and it appears as
2312 -- an actual in a call to its own initialization procedure. If
2313 -- this component depends on the outer discriminant, we must
2314 -- generate the proper actual subtype for it.
2316 if Nkind
(Exp
) = N_Selected_Component
2317 and then Within_Init_Proc
2320 Decl
: constant Node_Id
:=
2321 Build_Actual_Subtype_Of_Component
(Exp_Typ
, Exp
);
2323 if Present
(Decl
) then
2324 Insert_Action
(N
, Decl
);
2325 T
:= Defining_Identifier
(Decl
);
2331 -- No need to generate a new subtype
2338 T
:= Make_Temporary
(Loc
, 'T');
2341 Make_Subtype_Declaration
(Loc
,
2342 Defining_Identifier
=> T
,
2343 Subtype_Indication
=> New_Occurrence_Of
(Exp_Typ
, Loc
)));
2345 -- This type is marked as an itype even though it has an explicit
2346 -- declaration since otherwise Is_Generic_Actual_Type can get
2347 -- set, resulting in the generation of spurious errors. (See
2348 -- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
2351 Set_Associated_Node_For_Itype
(T
, Exp
);
2354 Rewrite
(Subtype_Indic
, New_Occurrence_Of
(T
, Loc
));
2356 -- Nothing needs to be done for private types with unknown discriminants
2357 -- if the underlying type is not an unconstrained composite type or it
2358 -- is an unchecked union.
2360 elsif Is_Private_Type
(Unc_Type
)
2361 and then Has_Unknown_Discriminants
(Unc_Type
)
2362 and then (not Is_Composite_Type
(Underlying_Type
(Unc_Type
))
2363 or else Is_Constrained
(Underlying_Type
(Unc_Type
))
2364 or else Is_Unchecked_Union
(Underlying_Type
(Unc_Type
)))
2368 -- Case of derived type with unknown discriminants where the parent type
2369 -- also has unknown discriminants.
2371 elsif Is_Record_Type
(Unc_Type
)
2372 and then not Is_Class_Wide_Type
(Unc_Type
)
2373 and then Has_Unknown_Discriminants
(Unc_Type
)
2374 and then Has_Unknown_Discriminants
(Underlying_Type
(Unc_Type
))
2376 -- Nothing to be done if no underlying record view available
2378 if No
(Underlying_Record_View
(Unc_Type
)) then
2381 -- Otherwise use the Underlying_Record_View to create the proper
2382 -- constrained subtype for an object of a derived type with unknown
2386 Remove_Side_Effects
(Exp
);
2387 Rewrite
(Subtype_Indic
,
2388 Make_Subtype_From_Expr
(Exp
, Underlying_Record_View
(Unc_Type
)));
2391 -- Renamings of class-wide interface types require no equivalent
2392 -- constrained type declarations because we only need to reference
2393 -- the tag component associated with the interface. The same is
2394 -- presumably true for class-wide types in general, so this test
2395 -- is broadened to include all class-wide renamings, which also
2396 -- avoids cases of unbounded recursion in Remove_Side_Effects.
2397 -- (Is this really correct, or are there some cases of class-wide
2398 -- renamings that require action in this procedure???)
2401 and then Nkind
(N
) = N_Object_Renaming_Declaration
2402 and then Is_Class_Wide_Type
(Unc_Type
)
2406 -- In Ada 95 nothing to be done if the type of the expression is limited
2407 -- because in this case the expression cannot be copied, and its use can
2408 -- only be by reference.
2410 -- In Ada 2005 the context can be an object declaration whose expression
2411 -- is a function that returns in place. If the nominal subtype has
2412 -- unknown discriminants, the call still provides constraints on the
2413 -- object, and we have to create an actual subtype from it.
2415 -- If the type is class-wide, the expression is dynamically tagged and
2416 -- we do not create an actual subtype either. Ditto for an interface.
2417 -- For now this applies only if the type is immutably limited, and the
2418 -- function being called is build-in-place. This will have to be revised
2419 -- when build-in-place functions are generalized to other types.
2421 elsif Is_Limited_View
(Exp_Typ
)
2423 (Is_Class_Wide_Type
(Exp_Typ
)
2424 or else Is_Interface
(Exp_Typ
)
2425 or else not Has_Unknown_Discriminants
(Exp_Typ
)
2426 or else not Is_Composite_Type
(Unc_Type
))
2430 -- For limited objects initialized with build in place function calls,
2431 -- nothing to be done; otherwise we prematurely introduce an N_Reference
2432 -- node in the expression initializing the object, which breaks the
2433 -- circuitry that detects and adds the additional arguments to the
2436 elsif Is_Build_In_Place_Function_Call
(Exp
) then
2440 Remove_Side_Effects
(Exp
);
2441 Rewrite
(Subtype_Indic
,
2442 Make_Subtype_From_Expr
(Exp
, Unc_Type
));
2444 end Expand_Subtype_From_Expr
;
2446 ------------------------
2447 -- Find_Interface_ADT --
2448 ------------------------
2450 function Find_Interface_ADT
2452 Iface
: Entity_Id
) return Elmt_Id
2455 Typ
: Entity_Id
:= T
;
2458 pragma Assert
(Is_Interface
(Iface
));
2460 -- Handle private types
2462 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2463 Typ
:= Full_View
(Typ
);
2466 -- Handle access types
2468 if Is_Access_Type
(Typ
) then
2469 Typ
:= Designated_Type
(Typ
);
2472 -- Handle task and protected types implementing interfaces
2474 if Is_Concurrent_Type
(Typ
) then
2475 Typ
:= Corresponding_Record_Type
(Typ
);
2479 (not Is_Class_Wide_Type
(Typ
)
2480 and then Ekind
(Typ
) /= E_Incomplete_Type
);
2482 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2483 return First_Elmt
(Access_Disp_Table
(Typ
));
2486 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
2488 and then Present
(Related_Type
(Node
(ADT
)))
2489 and then Related_Type
(Node
(ADT
)) /= Iface
2490 and then not Is_Ancestor
(Iface
, Related_Type
(Node
(ADT
)),
2491 Use_Full_View
=> True)
2496 pragma Assert
(Present
(Related_Type
(Node
(ADT
))));
2499 end Find_Interface_ADT
;
2501 ------------------------
2502 -- Find_Interface_Tag --
2503 ------------------------
2505 function Find_Interface_Tag
2507 Iface
: Entity_Id
) return Entity_Id
2510 Found
: Boolean := False;
2511 Typ
: Entity_Id
:= T
;
2513 procedure Find_Tag
(Typ
: Entity_Id
);
2514 -- Internal subprogram used to recursively climb to the ancestors
2520 procedure Find_Tag
(Typ
: Entity_Id
) is
2525 -- This routine does not handle the case in which the interface is an
2526 -- ancestor of Typ. That case is handled by the enclosing subprogram.
2528 pragma Assert
(Typ
/= Iface
);
2530 -- Climb to the root type handling private types
2532 if Present
(Full_View
(Etype
(Typ
))) then
2533 if Full_View
(Etype
(Typ
)) /= Typ
then
2534 Find_Tag
(Full_View
(Etype
(Typ
)));
2537 elsif Etype
(Typ
) /= Typ
then
2538 Find_Tag
(Etype
(Typ
));
2541 -- Traverse the list of interfaces implemented by the type
2544 and then Present
(Interfaces
(Typ
))
2545 and then not (Is_Empty_Elmt_List
(Interfaces
(Typ
)))
2547 -- Skip the tag associated with the primary table
2549 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2550 AI_Tag
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2551 pragma Assert
(Present
(AI_Tag
));
2553 AI_Elmt
:= First_Elmt
(Interfaces
(Typ
));
2554 while Present
(AI_Elmt
) loop
2555 AI
:= Node
(AI_Elmt
);
2558 or else Is_Ancestor
(Iface
, AI
, Use_Full_View
=> True)
2564 AI_Tag
:= Next_Tag_Component
(AI_Tag
);
2565 Next_Elmt
(AI_Elmt
);
2570 -- Start of processing for Find_Interface_Tag
2573 pragma Assert
(Is_Interface
(Iface
));
2575 -- Handle access types
2577 if Is_Access_Type
(Typ
) then
2578 Typ
:= Designated_Type
(Typ
);
2581 -- Handle class-wide types
2583 if Is_Class_Wide_Type
(Typ
) then
2584 Typ
:= Root_Type
(Typ
);
2587 -- Handle private types
2589 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2590 Typ
:= Full_View
(Typ
);
2593 -- Handle entities from the limited view
2595 if Ekind
(Typ
) = E_Incomplete_Type
then
2596 pragma Assert
(Present
(Non_Limited_View
(Typ
)));
2597 Typ
:= Non_Limited_View
(Typ
);
2600 -- Handle task and protected types implementing interfaces
2602 if Is_Concurrent_Type
(Typ
) then
2603 Typ
:= Corresponding_Record_Type
(Typ
);
2606 -- If the interface is an ancestor of the type, then it shared the
2607 -- primary dispatch table.
2609 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2610 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2611 return First_Tag_Component
(Typ
);
2613 -- Otherwise we need to search for its associated tag component
2617 pragma Assert
(Found
);
2620 end Find_Interface_Tag
;
2626 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
is
2628 Typ
: Entity_Id
:= T
;
2632 if Is_Class_Wide_Type
(Typ
) then
2633 Typ
:= Root_Type
(Typ
);
2636 Typ
:= Underlying_Type
(Typ
);
2638 -- Loop through primitive operations
2640 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
2641 while Present
(Prim
) loop
2644 -- We can retrieve primitive operations by name if it is an internal
2645 -- name. For equality we must check that both of its operands have
2646 -- the same type, to avoid confusion with user-defined equalities
2647 -- than may have a non-symmetric signature.
2649 exit when Chars
(Op
) = Name
2652 or else Etype
(First_Formal
(Op
)) = Etype
(Last_Formal
(Op
)));
2656 -- Raise Program_Error if no primitive found
2659 raise Program_Error
;
2670 function Find_Prim_Op
2672 Name
: TSS_Name_Type
) return Entity_Id
2674 Inher_Op
: Entity_Id
:= Empty
;
2675 Own_Op
: Entity_Id
:= Empty
;
2676 Prim_Elmt
: Elmt_Id
;
2677 Prim_Id
: Entity_Id
;
2678 Typ
: Entity_Id
:= T
;
2681 if Is_Class_Wide_Type
(Typ
) then
2682 Typ
:= Root_Type
(Typ
);
2685 Typ
:= Underlying_Type
(Typ
);
2687 -- This search is based on the assertion that the dispatching version
2688 -- of the TSS routine always precedes the real primitive.
2690 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
2691 while Present
(Prim_Elmt
) loop
2692 Prim_Id
:= Node
(Prim_Elmt
);
2694 if Is_TSS
(Prim_Id
, Name
) then
2695 if Present
(Alias
(Prim_Id
)) then
2696 Inher_Op
:= Prim_Id
;
2702 Next_Elmt
(Prim_Elmt
);
2705 if Present
(Own_Op
) then
2707 elsif Present
(Inher_Op
) then
2710 raise Program_Error
;
2714 ----------------------------
2715 -- Find_Protection_Object --
2716 ----------------------------
2718 function Find_Protection_Object
(Scop
: Entity_Id
) return Entity_Id
is
2723 while Present
(S
) loop
2724 if Ekind_In
(S
, E_Entry
, E_Entry_Family
, E_Function
, E_Procedure
)
2725 and then Present
(Protection_Object
(S
))
2727 return Protection_Object
(S
);
2733 -- If we do not find a Protection object in the scope chain, then
2734 -- something has gone wrong, most likely the object was never created.
2736 raise Program_Error
;
2737 end Find_Protection_Object
;
2739 --------------------------
2740 -- Find_Protection_Type --
2741 --------------------------
2743 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
is
2745 Typ
: Entity_Id
:= Conc_Typ
;
2748 if Is_Concurrent_Type
(Typ
) then
2749 Typ
:= Corresponding_Record_Type
(Typ
);
2752 -- Since restriction violations are not considered serious errors, the
2753 -- expander remains active, but may leave the corresponding record type
2754 -- malformed. In such cases, component _object is not available so do
2757 if not Analyzed
(Typ
) then
2761 Comp
:= First_Component
(Typ
);
2762 while Present
(Comp
) loop
2763 if Chars
(Comp
) = Name_uObject
then
2764 return Base_Type
(Etype
(Comp
));
2767 Next_Component
(Comp
);
2770 -- The corresponding record of a protected type should always have an
2773 raise Program_Error
;
2774 end Find_Protection_Type
;
2776 -----------------------
2777 -- Find_Hook_Context --
2778 -----------------------
2780 function Find_Hook_Context
(N
: Node_Id
) return Node_Id
is
2784 Wrapped_Node
: Node_Id
;
2785 -- Note: if we are in a transient scope, we want to reuse it as
2786 -- the context for actions insertion, if possible. But if N is itself
2787 -- part of the stored actions for the current transient scope,
2788 -- then we need to insert at the appropriate (inner) location in
2789 -- the not as an action on Node_To_Be_Wrapped.
2791 In_Cond_Expr
: constant Boolean := Within_Case_Or_If_Expression
(N
);
2794 -- When the node is inside a case/if expression, the lifetime of any
2795 -- temporary controlled object is extended. Find a suitable insertion
2796 -- node by locating the topmost case or if expressions.
2798 if In_Cond_Expr
then
2801 while Present
(Par
) loop
2802 if Nkind_In
(Original_Node
(Par
), N_Case_Expression
,
2807 -- Prevent the search from going too far
2809 elsif Is_Body_Or_Package_Declaration
(Par
) then
2813 Par
:= Parent
(Par
);
2816 -- The topmost case or if expression is now recovered, but it may
2817 -- still not be the correct place to add generated code. Climb to
2818 -- find a parent that is part of a declarative or statement list,
2819 -- and is not a list of actuals in a call.
2822 while Present
(Par
) loop
2823 if Is_List_Member
(Par
)
2824 and then not Nkind_In
(Par
, N_Component_Association
,
2825 N_Discriminant_Association
,
2826 N_Parameter_Association
,
2827 N_Pragma_Argument_Association
)
2828 and then not Nkind_In
2829 (Parent
(Par
), N_Function_Call
,
2830 N_Procedure_Call_Statement
,
2831 N_Entry_Call_Statement
)
2836 -- Prevent the search from going too far
2838 elsif Is_Body_Or_Package_Declaration
(Par
) then
2842 Par
:= Parent
(Par
);
2849 while Present
(Par
) loop
2851 -- Keep climbing past various operators
2853 if Nkind
(Parent
(Par
)) in N_Op
2854 or else Nkind_In
(Parent
(Par
), N_And_Then
, N_Or_Else
)
2856 Par
:= Parent
(Par
);
2864 -- The node may be located in a pragma in which case return the
2867 -- pragma Precondition (... and then Ctrl_Func_Call ...);
2869 -- Similar case occurs when the node is related to an object
2870 -- declaration or assignment:
2872 -- Obj [: Some_Typ] := ... and then Ctrl_Func_Call ...;
2874 -- Another case to consider is when the node is part of a return
2877 -- return ... and then Ctrl_Func_Call ...;
2879 -- Another case is when the node acts as a formal in a procedure
2882 -- Proc (... and then Ctrl_Func_Call ...);
2884 if Scope_Is_Transient
then
2885 Wrapped_Node
:= Node_To_Be_Wrapped
;
2887 Wrapped_Node
:= Empty
;
2890 while Present
(Par
) loop
2891 if Par
= Wrapped_Node
2892 or else Nkind_In
(Par
, N_Assignment_Statement
,
2893 N_Object_Declaration
,
2895 N_Procedure_Call_Statement
,
2896 N_Simple_Return_Statement
)
2900 -- Prevent the search from going too far
2902 elsif Is_Body_Or_Package_Declaration
(Par
) then
2906 Par
:= Parent
(Par
);
2909 -- Return the topmost short circuit operator
2913 end Find_Hook_Context
;
2915 ------------------------------
2916 -- Following_Address_Clause --
2917 ------------------------------
2919 -- Should this function check the private part in a package ???
2921 function Following_Address_Clause
(D
: Node_Id
) return Node_Id
is
2922 Id
: constant Entity_Id
:= Defining_Identifier
(D
);
2927 while Present
(Decl
) loop
2928 if Nkind
(Decl
) = N_At_Clause
2929 and then Chars
(Identifier
(Decl
)) = Chars
(Id
)
2933 elsif Nkind
(Decl
) = N_Attribute_Definition_Clause
2934 and then Chars
(Decl
) = Name_Address
2935 and then Chars
(Name
(Decl
)) = Chars
(Id
)
2944 end Following_Address_Clause
;
2946 ----------------------
2947 -- Force_Evaluation --
2948 ----------------------
2950 procedure Force_Evaluation
(Exp
: Node_Id
; Name_Req
: Boolean := False) is
2952 Remove_Side_Effects
(Exp
, Name_Req
, Variable_Ref
=> True);
2953 end Force_Evaluation
;
2955 ---------------------------------
2956 -- Fully_Qualified_Name_String --
2957 ---------------------------------
2959 function Fully_Qualified_Name_String
2961 Append_NUL
: Boolean := True) return String_Id
2963 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
);
2964 -- Compute recursively the qualified name without NUL at the end, adding
2965 -- it to the currently started string being generated
2967 ----------------------------------
2968 -- Internal_Full_Qualified_Name --
2969 ----------------------------------
2971 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
) is
2975 -- Deal properly with child units
2977 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
2978 Ent
:= Defining_Identifier
(E
);
2983 -- Compute qualification recursively (only "Standard" has no scope)
2985 if Present
(Scope
(Scope
(Ent
))) then
2986 Internal_Full_Qualified_Name
(Scope
(Ent
));
2987 Store_String_Char
(Get_Char_Code
('.'));
2990 -- Every entity should have a name except some expanded blocks
2991 -- don't bother about those.
2993 if Chars
(Ent
) = No_Name
then
2997 -- Generates the entity name in upper case
2999 Get_Decoded_Name_String
(Chars
(Ent
));
3001 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3003 end Internal_Full_Qualified_Name
;
3005 -- Start of processing for Full_Qualified_Name
3009 Internal_Full_Qualified_Name
(E
);
3012 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
3016 end Fully_Qualified_Name_String
;
3018 ------------------------
3019 -- Generate_Poll_Call --
3020 ------------------------
3022 procedure Generate_Poll_Call
(N
: Node_Id
) is
3024 -- No poll call if polling not active
3026 if not Polling_Required
then
3029 -- Otherwise generate require poll call
3032 Insert_Before_And_Analyze
(N
,
3033 Make_Procedure_Call_Statement
(Sloc
(N
),
3034 Name
=> New_Occurrence_Of
(RTE
(RE_Poll
), Sloc
(N
))));
3036 end Generate_Poll_Call
;
3038 ---------------------------------
3039 -- Get_Current_Value_Condition --
3040 ---------------------------------
3042 -- Note: the implementation of this procedure is very closely tied to the
3043 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
3044 -- interpret Current_Value fields set by the Set procedure, so the two
3045 -- procedures need to be closely coordinated.
3047 procedure Get_Current_Value_Condition
3052 Loc
: constant Source_Ptr
:= Sloc
(Var
);
3053 Ent
: constant Entity_Id
:= Entity
(Var
);
3055 procedure Process_Current_Value_Condition
3058 -- N is an expression which holds either True (S = True) or False (S =
3059 -- False) in the condition. This procedure digs out the expression and
3060 -- if it refers to Ent, sets Op and Val appropriately.
3062 -------------------------------------
3063 -- Process_Current_Value_Condition --
3064 -------------------------------------
3066 procedure Process_Current_Value_Condition
3071 Prev_Cond
: Node_Id
;
3081 -- Deal with NOT operators, inverting sense
3083 while Nkind
(Cond
) = N_Op_Not
loop
3084 Cond
:= Right_Opnd
(Cond
);
3088 -- Deal with conversions, qualifications, and expressions with
3091 while Nkind_In
(Cond
,
3093 N_Qualified_Expression
,
3094 N_Expression_With_Actions
)
3096 Cond
:= Expression
(Cond
);
3099 exit when Cond
= Prev_Cond
;
3102 -- Deal with AND THEN and AND cases
3104 if Nkind_In
(Cond
, N_And_Then
, N_Op_And
) then
3106 -- Don't ever try to invert a condition that is of the form of an
3107 -- AND or AND THEN (since we are not doing sufficiently general
3108 -- processing to allow this).
3110 if Sens
= False then
3116 -- Recursively process AND and AND THEN branches
3118 Process_Current_Value_Condition
(Left_Opnd
(Cond
), True);
3120 if Op
/= N_Empty
then
3124 Process_Current_Value_Condition
(Right_Opnd
(Cond
), True);
3127 -- Case of relational operator
3129 elsif Nkind
(Cond
) in N_Op_Compare
then
3132 -- Invert sense of test if inverted test
3134 if Sens
= False then
3136 when N_Op_Eq
=> Op
:= N_Op_Ne
;
3137 when N_Op_Ne
=> Op
:= N_Op_Eq
;
3138 when N_Op_Lt
=> Op
:= N_Op_Ge
;
3139 when N_Op_Gt
=> Op
:= N_Op_Le
;
3140 when N_Op_Le
=> Op
:= N_Op_Gt
;
3141 when N_Op_Ge
=> Op
:= N_Op_Lt
;
3142 when others => raise Program_Error
;
3146 -- Case of entity op value
3148 if Is_Entity_Name
(Left_Opnd
(Cond
))
3149 and then Ent
= Entity
(Left_Opnd
(Cond
))
3150 and then Compile_Time_Known_Value
(Right_Opnd
(Cond
))
3152 Val
:= Right_Opnd
(Cond
);
3154 -- Case of value op entity
3156 elsif Is_Entity_Name
(Right_Opnd
(Cond
))
3157 and then Ent
= Entity
(Right_Opnd
(Cond
))
3158 and then Compile_Time_Known_Value
(Left_Opnd
(Cond
))
3160 Val
:= Left_Opnd
(Cond
);
3162 -- We are effectively swapping operands
3165 when N_Op_Eq
=> null;
3166 when N_Op_Ne
=> null;
3167 when N_Op_Lt
=> Op
:= N_Op_Gt
;
3168 when N_Op_Gt
=> Op
:= N_Op_Lt
;
3169 when N_Op_Le
=> Op
:= N_Op_Ge
;
3170 when N_Op_Ge
=> Op
:= N_Op_Le
;
3171 when others => raise Program_Error
;
3180 elsif Nkind_In
(Cond
,
3182 N_Qualified_Expression
,
3183 N_Expression_With_Actions
)
3185 Cond
:= Expression
(Cond
);
3187 -- Case of Boolean variable reference, return as though the
3188 -- reference had said var = True.
3191 if Is_Entity_Name
(Cond
) and then Ent
= Entity
(Cond
) then
3192 Val
:= New_Occurrence_Of
(Standard_True
, Sloc
(Cond
));
3194 if Sens
= False then
3201 end Process_Current_Value_Condition
;
3203 -- Start of processing for Get_Current_Value_Condition
3209 -- Immediate return, nothing doing, if this is not an object
3211 if Ekind
(Ent
) not in Object_Kind
then
3215 -- Otherwise examine current value
3218 CV
: constant Node_Id
:= Current_Value
(Ent
);
3223 -- If statement. Condition is known true in THEN section, known False
3224 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
3226 if Nkind
(CV
) = N_If_Statement
then
3228 -- Before start of IF statement
3230 if Loc
< Sloc
(CV
) then
3233 -- After end of IF statement
3235 elsif Loc
>= Sloc
(CV
) + Text_Ptr
(UI_To_Int
(End_Span
(CV
))) then
3239 -- At this stage we know that we are within the IF statement, but
3240 -- unfortunately, the tree does not record the SLOC of the ELSE so
3241 -- we cannot use a simple SLOC comparison to distinguish between
3242 -- the then/else statements, so we have to climb the tree.
3249 while Parent
(N
) /= CV
loop
3252 -- If we fall off the top of the tree, then that's odd, but
3253 -- perhaps it could occur in some error situation, and the
3254 -- safest response is simply to assume that the outcome of
3255 -- the condition is unknown. No point in bombing during an
3256 -- attempt to optimize things.
3263 -- Now we have N pointing to a node whose parent is the IF
3264 -- statement in question, so now we can tell if we are within
3265 -- the THEN statements.
3267 if Is_List_Member
(N
)
3268 and then List_Containing
(N
) = Then_Statements
(CV
)
3272 -- If the variable reference does not come from source, we
3273 -- cannot reliably tell whether it appears in the else part.
3274 -- In particular, if it appears in generated code for a node
3275 -- that requires finalization, it may be attached to a list
3276 -- that has not been yet inserted into the code. For now,
3277 -- treat it as unknown.
3279 elsif not Comes_From_Source
(N
) then
3282 -- Otherwise we must be in ELSIF or ELSE part
3289 -- ELSIF part. Condition is known true within the referenced
3290 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
3291 -- and unknown before the ELSE part or after the IF statement.
3293 elsif Nkind
(CV
) = N_Elsif_Part
then
3295 -- if the Elsif_Part had condition_actions, the elsif has been
3296 -- rewritten as a nested if, and the original elsif_part is
3297 -- detached from the tree, so there is no way to obtain useful
3298 -- information on the current value of the variable.
3299 -- Can this be improved ???
3301 if No
(Parent
(CV
)) then
3307 -- Before start of ELSIF part
3309 if Loc
< Sloc
(CV
) then
3312 -- After end of IF statement
3314 elsif Loc
>= Sloc
(Stm
) +
3315 Text_Ptr
(UI_To_Int
(End_Span
(Stm
)))
3320 -- Again we lack the SLOC of the ELSE, so we need to climb the
3321 -- tree to see if we are within the ELSIF part in question.
3328 while Parent
(N
) /= Stm
loop
3331 -- If we fall off the top of the tree, then that's odd, but
3332 -- perhaps it could occur in some error situation, and the
3333 -- safest response is simply to assume that the outcome of
3334 -- the condition is unknown. No point in bombing during an
3335 -- attempt to optimize things.
3342 -- Now we have N pointing to a node whose parent is the IF
3343 -- statement in question, so see if is the ELSIF part we want.
3344 -- the THEN statements.
3349 -- Otherwise we must be in subsequent ELSIF or ELSE part
3356 -- Iteration scheme of while loop. The condition is known to be
3357 -- true within the body of the loop.
3359 elsif Nkind
(CV
) = N_Iteration_Scheme
then
3361 Loop_Stmt
: constant Node_Id
:= Parent
(CV
);
3364 -- Before start of body of loop
3366 if Loc
< Sloc
(Loop_Stmt
) then
3369 -- After end of LOOP statement
3371 elsif Loc
>= Sloc
(End_Label
(Loop_Stmt
)) then
3374 -- We are within the body of the loop
3381 -- All other cases of Current_Value settings
3387 -- If we fall through here, then we have a reportable condition, Sens
3388 -- is True if the condition is true and False if it needs inverting.
3390 Process_Current_Value_Condition
(Condition
(CV
), Sens
);
3392 end Get_Current_Value_Condition
;
3394 ---------------------
3395 -- Get_Stream_Size --
3396 ---------------------
3398 function Get_Stream_Size
(E
: Entity_Id
) return Uint
is
3400 -- If we have a Stream_Size clause for this type use it
3402 if Has_Stream_Size_Clause
(E
) then
3403 return Static_Integer
(Expression
(Stream_Size_Clause
(E
)));
3405 -- Otherwise the Stream_Size if the size of the type
3410 end Get_Stream_Size
;
3412 ---------------------------
3413 -- Has_Access_Constraint --
3414 ---------------------------
3416 function Has_Access_Constraint
(E
: Entity_Id
) return Boolean is
3418 T
: constant Entity_Id
:= Etype
(E
);
3421 if Has_Per_Object_Constraint
(E
) and then Has_Discriminants
(T
) then
3422 Disc
:= First_Discriminant
(T
);
3423 while Present
(Disc
) loop
3424 if Is_Access_Type
(Etype
(Disc
)) then
3428 Next_Discriminant
(Disc
);
3435 end Has_Access_Constraint
;
3437 -----------------------------------------------------
3438 -- Has_Annotate_Pragma_For_External_Axiomatization --
3439 -----------------------------------------------------
3441 function Has_Annotate_Pragma_For_External_Axiomatization
3442 (E
: Entity_Id
) return Boolean
3444 function Is_Annotate_Pragma_For_External_Axiomatization
3445 (N
: Node_Id
) return Boolean;
3446 -- Returns whether N is
3447 -- pragma Annotate (GNATprove, External_Axiomatization);
3449 ----------------------------------------------------
3450 -- Is_Annotate_Pragma_For_External_Axiomatization --
3451 ----------------------------------------------------
3453 -- The general form of pragma Annotate is
3455 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
3456 -- ARG ::= NAME | EXPRESSION
3458 -- The first two arguments are by convention intended to refer to an
3459 -- external tool and a tool-specific function. These arguments are
3462 -- The following is used to annotate a package specification which
3463 -- GNATprove should treat specially, because the axiomatization of
3464 -- this unit is given by the user instead of being automatically
3467 -- pragma Annotate (GNATprove, External_Axiomatization);
3469 function Is_Annotate_Pragma_For_External_Axiomatization
3470 (N
: Node_Id
) return Boolean
3472 Name_GNATprove
: constant String :=
3474 Name_External_Axiomatization
: constant String :=
3475 "external_axiomatization";
3479 if Nkind
(N
) = N_Pragma
3480 and then Get_Pragma_Id
(Pragma_Name
(N
)) = Pragma_Annotate
3481 and then List_Length
(Pragma_Argument_Associations
(N
)) = 2
3484 Arg1
: constant Node_Id
:=
3485 First
(Pragma_Argument_Associations
(N
));
3486 Arg2
: constant Node_Id
:= Next
(Arg1
);
3491 -- Fill in Name_Buffer with Name_GNATprove first, and then with
3492 -- Name_External_Axiomatization so that Name_Find returns the
3493 -- corresponding name. This takes care of all possible casings.
3496 Add_Str_To_Name_Buffer
(Name_GNATprove
);
3500 Add_Str_To_Name_Buffer
(Name_External_Axiomatization
);
3503 return Chars
(Get_Pragma_Arg
(Arg1
)) = Nam1
3505 Chars
(Get_Pragma_Arg
(Arg2
)) = Nam2
;
3511 end Is_Annotate_Pragma_For_External_Axiomatization
;
3516 Vis_Decls
: List_Id
;
3519 -- Start of processing for Has_Annotate_Pragma_For_External_Axiomatization
3522 if Nkind
(Parent
(E
)) = N_Defining_Program_Unit_Name
then
3523 Decl
:= Parent
(Parent
(E
));
3528 Vis_Decls
:= Visible_Declarations
(Decl
);
3530 N
:= First
(Vis_Decls
);
3531 while Present
(N
) loop
3533 -- Skip declarations generated by the frontend. Skip all pragmas
3534 -- that are not the desired Annotate pragma. Stop the search on
3535 -- the first non-pragma source declaration.
3537 if Comes_From_Source
(N
) then
3538 if Nkind
(N
) = N_Pragma
then
3539 if Is_Annotate_Pragma_For_External_Axiomatization
(N
) then
3551 end Has_Annotate_Pragma_For_External_Axiomatization
;
3553 --------------------
3554 -- Homonym_Number --
3555 --------------------
3557 function Homonym_Number
(Subp
: Entity_Id
) return Nat
is
3563 Hom
:= Homonym
(Subp
);
3564 while Present
(Hom
) loop
3565 if Scope
(Hom
) = Scope
(Subp
) then
3569 Hom
:= Homonym
(Hom
);
3575 -----------------------------------
3576 -- In_Library_Level_Package_Body --
3577 -----------------------------------
3579 function In_Library_Level_Package_Body
(Id
: Entity_Id
) return Boolean is
3581 -- First determine whether the entity appears at the library level, then
3582 -- look at the containing unit.
3584 if Is_Library_Level_Entity
(Id
) then
3586 Container
: constant Node_Id
:= Cunit
(Get_Source_Unit
(Id
));
3589 return Nkind
(Unit
(Container
)) = N_Package_Body
;
3594 end In_Library_Level_Package_Body
;
3596 ------------------------------
3597 -- In_Unconditional_Context --
3598 ------------------------------
3600 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean is
3605 while Present
(P
) loop
3607 when N_Subprogram_Body
=>
3610 when N_If_Statement
=>
3613 when N_Loop_Statement
=>
3616 when N_Case_Statement
=>
3625 end In_Unconditional_Context
;
3631 procedure Insert_Action
(Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
) is
3633 if Present
(Ins_Action
) then
3634 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
));
3638 -- Version with check(s) suppressed
3640 procedure Insert_Action
3641 (Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
; Suppress
: Check_Id
)
3644 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
), Suppress
);
3647 -------------------------
3648 -- Insert_Action_After --
3649 -------------------------
3651 procedure Insert_Action_After
3652 (Assoc_Node
: Node_Id
;
3653 Ins_Action
: Node_Id
)
3656 Insert_Actions_After
(Assoc_Node
, New_List
(Ins_Action
));
3657 end Insert_Action_After
;
3659 --------------------
3660 -- Insert_Actions --
3661 --------------------
3663 procedure Insert_Actions
(Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
) is
3667 Wrapped_Node
: Node_Id
:= Empty
;
3670 if No
(Ins_Actions
) or else Is_Empty_List
(Ins_Actions
) then
3674 -- Ignore insert of actions from inside default expression (or other
3675 -- similar "spec expression") in the special spec-expression analyze
3676 -- mode. Any insertions at this point have no relevance, since we are
3677 -- only doing the analyze to freeze the types of any static expressions.
3678 -- See section "Handling of Default Expressions" in the spec of package
3679 -- Sem for further details.
3681 if In_Spec_Expression
then
3685 -- If the action derives from stuff inside a record, then the actions
3686 -- are attached to the current scope, to be inserted and analyzed on
3687 -- exit from the scope. The reason for this is that we may also be
3688 -- generating freeze actions at the same time, and they must eventually
3689 -- be elaborated in the correct order.
3691 if Is_Record_Type
(Current_Scope
)
3692 and then not Is_Frozen
(Current_Scope
)
3694 if No
(Scope_Stack
.Table
3695 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
3697 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:=
3702 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
);
3708 -- We now intend to climb up the tree to find the right point to
3709 -- insert the actions. We start at Assoc_Node, unless this node is a
3710 -- subexpression in which case we start with its parent. We do this for
3711 -- two reasons. First it speeds things up. Second, if Assoc_Node is
3712 -- itself one of the special nodes like N_And_Then, then we assume that
3713 -- an initial request to insert actions for such a node does not expect
3714 -- the actions to get deposited in the node for later handling when the
3715 -- node is expanded, since clearly the node is being dealt with by the
3716 -- caller. Note that in the subexpression case, N is always the child we
3719 -- N_Raise_xxx_Error is an annoying special case, it is a statement if
3720 -- it has type Standard_Void_Type, and a subexpression otherwise.
3721 -- otherwise. Procedure calls, and similarly procedure attribute
3722 -- references, are also statements.
3724 if Nkind
(Assoc_Node
) in N_Subexpr
3725 and then (Nkind
(Assoc_Node
) not in N_Raise_xxx_Error
3726 or else Etype
(Assoc_Node
) /= Standard_Void_Type
)
3727 and then Nkind
(Assoc_Node
) /= N_Procedure_Call_Statement
3728 and then (Nkind
(Assoc_Node
) /= N_Attribute_Reference
3729 or else not Is_Procedure_Attribute_Name
3730 (Attribute_Name
(Assoc_Node
)))
3733 P
:= Parent
(Assoc_Node
);
3735 -- Non-subexpression case. Note that N is initially Empty in this case
3736 -- (N is only guaranteed Non-Empty in the subexpr case).
3743 -- Capture root of the transient scope
3745 if Scope_Is_Transient
then
3746 Wrapped_Node
:= Node_To_Be_Wrapped
;
3750 pragma Assert
(Present
(P
));
3752 -- Make sure that inserted actions stay in the transient scope
3754 if Present
(Wrapped_Node
) and then N
= Wrapped_Node
then
3755 Store_Before_Actions_In_Scope
(Ins_Actions
);
3761 -- Case of right operand of AND THEN or OR ELSE. Put the actions
3762 -- in the Actions field of the right operand. They will be moved
3763 -- out further when the AND THEN or OR ELSE operator is expanded.
3764 -- Nothing special needs to be done for the left operand since
3765 -- in that case the actions are executed unconditionally.
3767 when N_Short_Circuit
=>
3768 if N
= Right_Opnd
(P
) then
3770 -- We are now going to either append the actions to the
3771 -- actions field of the short-circuit operation. We will
3772 -- also analyze the actions now.
3774 -- This analysis is really too early, the proper thing would
3775 -- be to just park them there now, and only analyze them if
3776 -- we find we really need them, and to it at the proper
3777 -- final insertion point. However attempting to this proved
3778 -- tricky, so for now we just kill current values before and
3779 -- after the analyze call to make sure we avoid peculiar
3780 -- optimizations from this out of order insertion.
3782 Kill_Current_Values
;
3784 -- If P has already been expanded, we can't park new actions
3785 -- on it, so we need to expand them immediately, introducing
3786 -- an Expression_With_Actions. N can't be an expression
3787 -- with actions, or else then the actions would have been
3788 -- inserted at an inner level.
3790 if Analyzed
(P
) then
3791 pragma Assert
(Nkind
(N
) /= N_Expression_With_Actions
);
3793 Make_Expression_With_Actions
(Sloc
(N
),
3794 Actions
=> Ins_Actions
,
3795 Expression
=> Relocate_Node
(N
)));
3796 Analyze_And_Resolve
(N
);
3798 elsif Present
(Actions
(P
)) then
3799 Insert_List_After_And_Analyze
3800 (Last
(Actions
(P
)), Ins_Actions
);
3802 Set_Actions
(P
, Ins_Actions
);
3803 Analyze_List
(Actions
(P
));
3806 Kill_Current_Values
;
3811 -- Then or Else dependent expression of an if expression. Add
3812 -- actions to Then_Actions or Else_Actions field as appropriate.
3813 -- The actions will be moved further out when the if is expanded.
3815 when N_If_Expression
=>
3817 ThenX
: constant Node_Id
:= Next
(First
(Expressions
(P
)));
3818 ElseX
: constant Node_Id
:= Next
(ThenX
);
3821 -- If the enclosing expression is already analyzed, as
3822 -- is the case for nested elaboration checks, insert the
3823 -- conditional further out.
3825 if Analyzed
(P
) then
3828 -- Actions belong to the then expression, temporarily place
3829 -- them as Then_Actions of the if expression. They will be
3830 -- moved to the proper place later when the if expression
3833 elsif N
= ThenX
then
3834 if Present
(Then_Actions
(P
)) then
3835 Insert_List_After_And_Analyze
3836 (Last
(Then_Actions
(P
)), Ins_Actions
);
3838 Set_Then_Actions
(P
, Ins_Actions
);
3839 Analyze_List
(Then_Actions
(P
));
3844 -- Actions belong to the else expression, temporarily place
3845 -- them as Else_Actions of the if expression. They will be
3846 -- moved to the proper place later when the if expression
3849 elsif N
= ElseX
then
3850 if Present
(Else_Actions
(P
)) then
3851 Insert_List_After_And_Analyze
3852 (Last
(Else_Actions
(P
)), Ins_Actions
);
3854 Set_Else_Actions
(P
, Ins_Actions
);
3855 Analyze_List
(Else_Actions
(P
));
3860 -- Actions belong to the condition. In this case they are
3861 -- unconditionally executed, and so we can continue the
3862 -- search for the proper insert point.
3869 -- Alternative of case expression, we place the action in the
3870 -- Actions field of the case expression alternative, this will
3871 -- be handled when the case expression is expanded.
3873 when N_Case_Expression_Alternative
=>
3874 if Present
(Actions
(P
)) then
3875 Insert_List_After_And_Analyze
3876 (Last
(Actions
(P
)), Ins_Actions
);
3878 Set_Actions
(P
, Ins_Actions
);
3879 Analyze_List
(Actions
(P
));
3884 -- Case of appearing within an Expressions_With_Actions node. When
3885 -- the new actions come from the expression of the expression with
3886 -- actions, they must be added to the existing actions. The other
3887 -- alternative is when the new actions are related to one of the
3888 -- existing actions of the expression with actions, and should
3889 -- never reach here: if actions are inserted on a statement
3890 -- within the Actions of an expression with actions, or on some
3891 -- sub-expression of such a statement, then the outermost proper
3892 -- insertion point is right before the statement, and we should
3893 -- never climb up as far as the N_Expression_With_Actions itself.
3895 when N_Expression_With_Actions
=>
3896 if N
= Expression
(P
) then
3897 if Is_Empty_List
(Actions
(P
)) then
3898 Append_List_To
(Actions
(P
), Ins_Actions
);
3899 Analyze_List
(Actions
(P
));
3901 Insert_List_After_And_Analyze
3902 (Last
(Actions
(P
)), Ins_Actions
);
3908 raise Program_Error
;
3911 -- Case of appearing in the condition of a while expression or
3912 -- elsif. We insert the actions into the Condition_Actions field.
3913 -- They will be moved further out when the while loop or elsif
3916 when N_Iteration_Scheme |
3919 if N
= Condition
(P
) then
3920 if Present
(Condition_Actions
(P
)) then
3921 Insert_List_After_And_Analyze
3922 (Last
(Condition_Actions
(P
)), Ins_Actions
);
3924 Set_Condition_Actions
(P
, Ins_Actions
);
3926 -- Set the parent of the insert actions explicitly. This
3927 -- is not a syntactic field, but we need the parent field
3928 -- set, in particular so that freeze can understand that
3929 -- it is dealing with condition actions, and properly
3930 -- insert the freezing actions.
3932 Set_Parent
(Ins_Actions
, P
);
3933 Analyze_List
(Condition_Actions
(P
));
3939 -- Statements, declarations, pragmas, representation clauses
3944 N_Procedure_Call_Statement |
3945 N_Statement_Other_Than_Procedure_Call |
3951 -- Representation_Clause
3954 N_Attribute_Definition_Clause |
3955 N_Enumeration_Representation_Clause |
3956 N_Record_Representation_Clause |
3960 N_Abstract_Subprogram_Declaration |
3962 N_Exception_Declaration |
3963 N_Exception_Renaming_Declaration |
3964 N_Expression_Function |
3965 N_Formal_Abstract_Subprogram_Declaration |
3966 N_Formal_Concrete_Subprogram_Declaration |
3967 N_Formal_Object_Declaration |
3968 N_Formal_Type_Declaration |
3969 N_Full_Type_Declaration |
3970 N_Function_Instantiation |
3971 N_Generic_Function_Renaming_Declaration |
3972 N_Generic_Package_Declaration |
3973 N_Generic_Package_Renaming_Declaration |
3974 N_Generic_Procedure_Renaming_Declaration |
3975 N_Generic_Subprogram_Declaration |
3976 N_Implicit_Label_Declaration |
3977 N_Incomplete_Type_Declaration |
3978 N_Number_Declaration |
3979 N_Object_Declaration |
3980 N_Object_Renaming_Declaration |
3982 N_Package_Body_Stub |
3983 N_Package_Declaration |
3984 N_Package_Instantiation |
3985 N_Package_Renaming_Declaration |
3986 N_Private_Extension_Declaration |
3987 N_Private_Type_Declaration |
3988 N_Procedure_Instantiation |
3990 N_Protected_Body_Stub |
3991 N_Protected_Type_Declaration |
3992 N_Single_Task_Declaration |
3994 N_Subprogram_Body_Stub |
3995 N_Subprogram_Declaration |
3996 N_Subprogram_Renaming_Declaration |
3997 N_Subtype_Declaration |
4000 N_Task_Type_Declaration |
4002 -- Use clauses can appear in lists of declarations
4004 N_Use_Package_Clause |
4007 -- Freeze entity behaves like a declaration or statement
4010 N_Freeze_Generic_Entity
4012 -- Do not insert here if the item is not a list member (this
4013 -- happens for example with a triggering statement, and the
4014 -- proper approach is to insert before the entire select).
4016 if not Is_List_Member
(P
) then
4019 -- Do not insert if parent of P is an N_Component_Association
4020 -- node (i.e. we are in the context of an N_Aggregate or
4021 -- N_Extension_Aggregate node. In this case we want to insert
4022 -- before the entire aggregate.
4024 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
4027 -- Do not insert if the parent of P is either an N_Variant node
4028 -- or an N_Record_Definition node, meaning in either case that
4029 -- P is a member of a component list, and that therefore the
4030 -- actions should be inserted outside the complete record
4033 elsif Nkind_In
(Parent
(P
), N_Variant
, N_Record_Definition
) then
4036 -- Do not insert freeze nodes within the loop generated for
4037 -- an aggregate, because they may be elaborated too late for
4038 -- subsequent use in the back end: within a package spec the
4039 -- loop is part of the elaboration procedure and is only
4040 -- elaborated during the second pass.
4042 -- If the loop comes from source, or the entity is local to the
4043 -- loop itself it must remain within.
4045 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
4046 and then not Comes_From_Source
(Parent
(P
))
4047 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
4049 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
4053 -- Otherwise we can go ahead and do the insertion
4055 elsif P
= Wrapped_Node
then
4056 Store_Before_Actions_In_Scope
(Ins_Actions
);
4060 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4064 -- A special case, N_Raise_xxx_Error can act either as a statement
4065 -- or a subexpression. We tell the difference by looking at the
4066 -- Etype. It is set to Standard_Void_Type in the statement case.
4069 N_Raise_xxx_Error
=>
4070 if Etype
(P
) = Standard_Void_Type
then
4071 if P
= Wrapped_Node
then
4072 Store_Before_Actions_In_Scope
(Ins_Actions
);
4074 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4079 -- In the subexpression case, keep climbing
4085 -- If a component association appears within a loop created for
4086 -- an array aggregate, attach the actions to the association so
4087 -- they can be subsequently inserted within the loop. For other
4088 -- component associations insert outside of the aggregate. For
4089 -- an association that will generate a loop, its Loop_Actions
4090 -- attribute is already initialized (see exp_aggr.adb).
4092 -- The list of loop_actions can in turn generate additional ones,
4093 -- that are inserted before the associated node. If the associated
4094 -- node is outside the aggregate, the new actions are collected
4095 -- at the end of the loop actions, to respect the order in which
4096 -- they are to be elaborated.
4099 N_Component_Association
=>
4100 if Nkind
(Parent
(P
)) = N_Aggregate
4101 and then Present
(Loop_Actions
(P
))
4103 if Is_Empty_List
(Loop_Actions
(P
)) then
4104 Set_Loop_Actions
(P
, Ins_Actions
);
4105 Analyze_List
(Ins_Actions
);
4112 -- Check whether these actions were generated by a
4113 -- declaration that is part of the loop_ actions
4114 -- for the component_association.
4117 while Present
(Decl
) loop
4118 exit when Parent
(Decl
) = P
4119 and then Is_List_Member
(Decl
)
4121 List_Containing
(Decl
) = Loop_Actions
(P
);
4122 Decl
:= Parent
(Decl
);
4125 if Present
(Decl
) then
4126 Insert_List_Before_And_Analyze
4127 (Decl
, Ins_Actions
);
4129 Insert_List_After_And_Analyze
4130 (Last
(Loop_Actions
(P
)), Ins_Actions
);
4141 -- Another special case, an attribute denoting a procedure call
4144 N_Attribute_Reference
=>
4145 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
4146 if P
= Wrapped_Node
then
4147 Store_Before_Actions_In_Scope
(Ins_Actions
);
4149 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4154 -- In the subexpression case, keep climbing
4160 -- A contract node should not belong to the tree
4163 raise Program_Error
;
4165 -- For all other node types, keep climbing tree
4169 N_Accept_Alternative |
4170 N_Access_Definition |
4171 N_Access_Function_Definition |
4172 N_Access_Procedure_Definition |
4173 N_Access_To_Object_Definition |
4176 N_Aspect_Specification |
4178 N_Case_Statement_Alternative |
4179 N_Character_Literal |
4180 N_Compilation_Unit |
4181 N_Compilation_Unit_Aux |
4182 N_Component_Clause |
4183 N_Component_Declaration |
4184 N_Component_Definition |
4186 N_Constrained_Array_Definition |
4187 N_Decimal_Fixed_Point_Definition |
4188 N_Defining_Character_Literal |
4189 N_Defining_Identifier |
4190 N_Defining_Operator_Symbol |
4191 N_Defining_Program_Unit_Name |
4192 N_Delay_Alternative |
4193 N_Delta_Constraint |
4194 N_Derived_Type_Definition |
4196 N_Digits_Constraint |
4197 N_Discriminant_Association |
4198 N_Discriminant_Specification |
4200 N_Entry_Body_Formal_Part |
4201 N_Entry_Call_Alternative |
4202 N_Entry_Declaration |
4203 N_Entry_Index_Specification |
4204 N_Enumeration_Type_Definition |
4206 N_Exception_Handler |
4208 N_Explicit_Dereference |
4209 N_Extension_Aggregate |
4210 N_Floating_Point_Definition |
4211 N_Formal_Decimal_Fixed_Point_Definition |
4212 N_Formal_Derived_Type_Definition |
4213 N_Formal_Discrete_Type_Definition |
4214 N_Formal_Floating_Point_Definition |
4215 N_Formal_Modular_Type_Definition |
4216 N_Formal_Ordinary_Fixed_Point_Definition |
4217 N_Formal_Package_Declaration |
4218 N_Formal_Private_Type_Definition |
4219 N_Formal_Incomplete_Type_Definition |
4220 N_Formal_Signed_Integer_Type_Definition |
4222 N_Function_Specification |
4223 N_Generic_Association |
4224 N_Handled_Sequence_Of_Statements |
4227 N_Index_Or_Discriminant_Constraint |
4228 N_Indexed_Component |
4230 N_Iterator_Specification |
4233 N_Loop_Parameter_Specification |
4235 N_Modular_Type_Definition |
4261 N_Op_Shift_Right_Arithmetic |
4265 N_Ordinary_Fixed_Point_Definition |
4267 N_Package_Specification |
4268 N_Parameter_Association |
4269 N_Parameter_Specification |
4270 N_Pop_Constraint_Error_Label |
4271 N_Pop_Program_Error_Label |
4272 N_Pop_Storage_Error_Label |
4273 N_Pragma_Argument_Association |
4274 N_Procedure_Specification |
4275 N_Protected_Definition |
4276 N_Push_Constraint_Error_Label |
4277 N_Push_Program_Error_Label |
4278 N_Push_Storage_Error_Label |
4279 N_Qualified_Expression |
4280 N_Quantified_Expression |
4281 N_Raise_Expression |
4283 N_Range_Constraint |
4285 N_Real_Range_Specification |
4286 N_Record_Definition |
4288 N_SCIL_Dispatch_Table_Tag_Init |
4289 N_SCIL_Dispatching_Call |
4290 N_SCIL_Membership_Test |
4291 N_Selected_Component |
4292 N_Signed_Integer_Type_Definition |
4293 N_Single_Protected_Declaration |
4296 N_Subtype_Indication |
4299 N_Terminate_Alternative |
4300 N_Triggering_Alternative |
4302 N_Unchecked_Expression |
4303 N_Unchecked_Type_Conversion |
4304 N_Unconstrained_Array_Definition |
4309 N_Validate_Unchecked_Conversion |
4316 -- If we fall through above tests, keep climbing tree
4320 if Nkind
(Parent
(N
)) = N_Subunit
then
4322 -- This is the proper body corresponding to a stub. Insertion must
4323 -- be done at the point of the stub, which is in the declarative
4324 -- part of the parent unit.
4326 P
:= Corresponding_Stub
(Parent
(N
));
4334 -- Version with check(s) suppressed
4336 procedure Insert_Actions
4337 (Assoc_Node
: Node_Id
;
4338 Ins_Actions
: List_Id
;
4339 Suppress
: Check_Id
)
4342 if Suppress
= All_Checks
then
4344 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
4346 Scope_Suppress
.Suppress
:= (others => True);
4347 Insert_Actions
(Assoc_Node
, Ins_Actions
);
4348 Scope_Suppress
.Suppress
:= Sva
;
4353 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
4355 Scope_Suppress
.Suppress
(Suppress
) := True;
4356 Insert_Actions
(Assoc_Node
, Ins_Actions
);
4357 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
4362 --------------------------
4363 -- Insert_Actions_After --
4364 --------------------------
4366 procedure Insert_Actions_After
4367 (Assoc_Node
: Node_Id
;
4368 Ins_Actions
: List_Id
)
4371 if Scope_Is_Transient
and then Assoc_Node
= Node_To_Be_Wrapped
then
4372 Store_After_Actions_In_Scope
(Ins_Actions
);
4374 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
4376 end Insert_Actions_After
;
4378 ------------------------
4379 -- Insert_Declaration --
4380 ------------------------
4382 procedure Insert_Declaration
(N
: Node_Id
; Decl
: Node_Id
) is
4386 pragma Assert
(Nkind
(N
) in N_Subexpr
);
4388 -- Climb until we find a procedure or a package
4392 pragma Assert
(Present
(Parent
(P
)));
4395 if Is_List_Member
(P
) then
4396 exit when Nkind_In
(Parent
(P
), N_Package_Specification
,
4399 -- Special handling for handled sequence of statements, we must
4400 -- insert in the statements not the exception handlers!
4402 if Nkind
(Parent
(P
)) = N_Handled_Sequence_Of_Statements
then
4403 P
:= First
(Statements
(Parent
(P
)));
4409 -- Now do the insertion
4411 Insert_Before
(P
, Decl
);
4413 end Insert_Declaration
;
4415 ---------------------------------
4416 -- Insert_Library_Level_Action --
4417 ---------------------------------
4419 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
4420 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
4423 Push_Scope
(Cunit_Entity
(Main_Unit
));
4424 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
4426 if No
(Actions
(Aux
)) then
4427 Set_Actions
(Aux
, New_List
(N
));
4429 Append
(N
, Actions
(Aux
));
4434 end Insert_Library_Level_Action
;
4436 ----------------------------------
4437 -- Insert_Library_Level_Actions --
4438 ----------------------------------
4440 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
4441 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
4444 if Is_Non_Empty_List
(L
) then
4445 Push_Scope
(Cunit_Entity
(Main_Unit
));
4446 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
4448 if No
(Actions
(Aux
)) then
4449 Set_Actions
(Aux
, L
);
4452 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
4457 end Insert_Library_Level_Actions
;
4459 ----------------------
4460 -- Inside_Init_Proc --
4461 ----------------------
4463 function Inside_Init_Proc
return Boolean is
4468 while Present
(S
) and then S
/= Standard_Standard
loop
4469 if Is_Init_Proc
(S
) then
4477 end Inside_Init_Proc
;
4479 ----------------------------
4480 -- Is_All_Null_Statements --
4481 ----------------------------
4483 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
4488 while Present
(Stm
) loop
4489 if Nkind
(Stm
) /= N_Null_Statement
then
4497 end Is_All_Null_Statements
;
4499 --------------------------------------------------
4500 -- Is_Displacement_Of_Object_Or_Function_Result --
4501 --------------------------------------------------
4503 function Is_Displacement_Of_Object_Or_Function_Result
4504 (Obj_Id
: Entity_Id
) return Boolean
4506 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean;
4507 -- Determine if particular node denotes a controlled function call. The
4508 -- call may have been heavily expanded.
4510 function Is_Displace_Call
(N
: Node_Id
) return Boolean;
4511 -- Determine whether a particular node is a call to Ada.Tags.Displace.
4512 -- The call might be nested within other actions such as conversions.
4514 function Is_Source_Object
(N
: Node_Id
) return Boolean;
4515 -- Determine whether a particular node denotes a source object
4517 ---------------------------------
4518 -- Is_Controlled_Function_Call --
4519 ---------------------------------
4521 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean is
4522 Expr
: Node_Id
:= Original_Node
(N
);
4525 if Nkind
(Expr
) = N_Function_Call
then
4526 Expr
:= Name
(Expr
);
4528 -- When a function call appears in Object.Operation format, the
4529 -- original representation has two possible forms depending on the
4530 -- availability of actual parameters:
4532 -- Obj.Func_Call N_Selected_Component
4533 -- Obj.Func_Call (Param) N_Indexed_Component
4536 if Nkind
(Expr
) = N_Indexed_Component
then
4537 Expr
:= Prefix
(Expr
);
4540 if Nkind
(Expr
) = N_Selected_Component
then
4541 Expr
:= Selector_Name
(Expr
);
4546 Nkind_In
(Expr
, N_Expanded_Name
, N_Identifier
)
4547 and then Ekind
(Entity
(Expr
)) = E_Function
4548 and then Needs_Finalization
(Etype
(Entity
(Expr
)));
4549 end Is_Controlled_Function_Call
;
4551 ----------------------
4552 -- Is_Displace_Call --
4553 ----------------------
4555 function Is_Displace_Call
(N
: Node_Id
) return Boolean is
4556 Call
: Node_Id
:= N
;
4559 -- Strip various actions which may precede a call to Displace
4562 if Nkind
(Call
) = N_Explicit_Dereference
then
4563 Call
:= Prefix
(Call
);
4565 elsif Nkind_In
(Call
, N_Type_Conversion
,
4566 N_Unchecked_Type_Conversion
)
4568 Call
:= Expression
(Call
);
4577 and then Nkind
(Call
) = N_Function_Call
4578 and then Is_RTE
(Entity
(Name
(Call
)), RE_Displace
);
4579 end Is_Displace_Call
;
4581 ----------------------
4582 -- Is_Source_Object --
4583 ----------------------
4585 function Is_Source_Object
(N
: Node_Id
) return Boolean is
4589 and then Nkind
(N
) in N_Has_Entity
4590 and then Is_Object
(Entity
(N
))
4591 and then Comes_From_Source
(N
);
4592 end Is_Source_Object
;
4596 Decl
: constant Node_Id
:= Parent
(Obj_Id
);
4597 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4598 Orig_Decl
: constant Node_Id
:= Original_Node
(Decl
);
4600 -- Start of processing for Is_Displacement_Of_Object_Or_Function_Result
4605 -- Obj : CW_Type := Function_Call (...);
4609 -- Tmp : ... := Function_Call (...)'reference;
4610 -- Obj : CW_Type renames (... Ada.Tags.Displace (Tmp));
4612 -- where the return type of the function and the class-wide type require
4613 -- dispatch table pointer displacement.
4617 -- Obj : CW_Type := Src_Obj;
4621 -- Obj : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
4623 -- where the type of the source object and the class-wide type require
4624 -- dispatch table pointer displacement.
4627 Nkind
(Decl
) = N_Object_Renaming_Declaration
4628 and then Nkind
(Orig_Decl
) = N_Object_Declaration
4629 and then Comes_From_Source
(Orig_Decl
)
4630 and then Is_Class_Wide_Type
(Obj_Typ
)
4631 and then Is_Displace_Call
(Renamed_Object
(Obj_Id
))
4633 (Is_Controlled_Function_Call
(Expression
(Orig_Decl
))
4634 or else Is_Source_Object
(Expression
(Orig_Decl
)));
4635 end Is_Displacement_Of_Object_Or_Function_Result
;
4637 ------------------------------
4638 -- Is_Finalizable_Transient --
4639 ------------------------------
4641 function Is_Finalizable_Transient
4643 Rel_Node
: Node_Id
) return Boolean
4645 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
4646 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4647 Desig
: Entity_Id
:= Obj_Typ
;
4649 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean;
4650 -- Determine whether transient object Trans_Id is initialized either
4651 -- by a function call which returns an access type or simply renames
4654 function Initialized_By_Aliased_BIP_Func_Call
4655 (Trans_Id
: Entity_Id
) return Boolean;
4656 -- Determine whether transient object Trans_Id is initialized by a
4657 -- build-in-place function call where the BIPalloc parameter is of
4658 -- value 1 and BIPaccess is not null. This case creates an aliasing
4659 -- between the returned value and the value denoted by BIPaccess.
4662 (Trans_Id
: Entity_Id
;
4663 First_Stmt
: Node_Id
) return Boolean;
4664 -- Determine whether transient object Trans_Id has been renamed or
4665 -- aliased through 'reference in the statement list starting from
4668 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean;
4669 -- Determine whether transient object Trans_Id is allocated on the heap
4671 function Is_Iterated_Container
4672 (Trans_Id
: Entity_Id
;
4673 First_Stmt
: Node_Id
) return Boolean;
4674 -- Determine whether transient object Trans_Id denotes a container which
4675 -- is in the process of being iterated in the statement list starting
4678 ---------------------------
4679 -- Initialized_By_Access --
4680 ---------------------------
4682 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean is
4683 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4688 and then Nkind
(Expr
) /= N_Reference
4689 and then Is_Access_Type
(Etype
(Expr
));
4690 end Initialized_By_Access
;
4692 ------------------------------------------
4693 -- Initialized_By_Aliased_BIP_Func_Call --
4694 ------------------------------------------
4696 function Initialized_By_Aliased_BIP_Func_Call
4697 (Trans_Id
: Entity_Id
) return Boolean
4699 Call
: Node_Id
:= Expression
(Parent
(Trans_Id
));
4702 -- Build-in-place calls usually appear in 'reference format
4704 if Nkind
(Call
) = N_Reference
then
4705 Call
:= Prefix
(Call
);
4708 if Is_Build_In_Place_Function_Call
(Call
) then
4710 Access_Nam
: Name_Id
:= No_Name
;
4711 Access_OK
: Boolean := False;
4713 Alloc_Nam
: Name_Id
:= No_Name
;
4714 Alloc_OK
: Boolean := False;
4716 Func_Id
: Entity_Id
;
4720 -- Examine all parameter associations of the function call
4722 Param
:= First
(Parameter_Associations
(Call
));
4723 while Present
(Param
) loop
4724 if Nkind
(Param
) = N_Parameter_Association
4725 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
4727 Actual
:= Explicit_Actual_Parameter
(Param
);
4728 Formal
:= Selector_Name
(Param
);
4730 -- Construct the names of formals BIPaccess and BIPalloc
4731 -- using the function name retrieved from an arbitrary
4734 if Access_Nam
= No_Name
4735 and then Alloc_Nam
= No_Name
4736 and then Present
(Entity
(Formal
))
4738 Func_Id
:= Scope
(Entity
(Formal
));
4741 New_External_Name
(Chars
(Func_Id
),
4742 BIP_Formal_Suffix
(BIP_Object_Access
));
4745 New_External_Name
(Chars
(Func_Id
),
4746 BIP_Formal_Suffix
(BIP_Alloc_Form
));
4749 -- A match for BIPaccess => Temp has been found
4751 if Chars
(Formal
) = Access_Nam
4752 and then Nkind
(Actual
) /= N_Null
4757 -- A match for BIPalloc => 1 has been found
4759 if Chars
(Formal
) = Alloc_Nam
4760 and then Nkind
(Actual
) = N_Integer_Literal
4761 and then Intval
(Actual
) = Uint_1
4770 return Access_OK
and Alloc_OK
;
4775 end Initialized_By_Aliased_BIP_Func_Call
;
4782 (Trans_Id
: Entity_Id
;
4783 First_Stmt
: Node_Id
) return Boolean
4785 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
;
4786 -- Given an object renaming declaration, retrieve the entity of the
4787 -- renamed name. Return Empty if the renamed name is anything other
4788 -- than a variable or a constant.
4790 -------------------------
4791 -- Find_Renamed_Object --
4792 -------------------------
4794 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
is
4795 Ren_Obj
: Node_Id
:= Empty
;
4797 function Find_Object
(N
: Node_Id
) return Traverse_Result
;
4798 -- Try to detect an object which is either a constant or a
4805 function Find_Object
(N
: Node_Id
) return Traverse_Result
is
4807 -- Stop the search once a constant or a variable has been
4810 if Nkind
(N
) = N_Identifier
4811 and then Present
(Entity
(N
))
4812 and then Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
4814 Ren_Obj
:= Entity
(N
);
4821 procedure Search
is new Traverse_Proc
(Find_Object
);
4825 Typ
: constant Entity_Id
:= Etype
(Defining_Identifier
(Ren_Decl
));
4827 -- Start of processing for Find_Renamed_Object
4830 -- Actions related to dispatching calls may appear as renamings of
4831 -- tags. Do not process this type of renaming because it does not
4832 -- use the actual value of the object.
4834 if not Is_RTE
(Typ
, RE_Tag_Ptr
) then
4835 Search
(Name
(Ren_Decl
));
4839 end Find_Renamed_Object
;
4844 Ren_Obj
: Entity_Id
;
4847 -- Start of processing for Is_Aliased
4851 while Present
(Stmt
) loop
4852 if Nkind
(Stmt
) = N_Object_Declaration
then
4853 Expr
:= Expression
(Stmt
);
4856 and then Nkind
(Expr
) = N_Reference
4857 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4858 and then Entity
(Prefix
(Expr
)) = Trans_Id
4863 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
then
4864 Ren_Obj
:= Find_Renamed_Object
(Stmt
);
4866 if Present
(Ren_Obj
) and then Ren_Obj
= Trans_Id
then
4881 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean is
4882 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4885 Is_Access_Type
(Etype
(Trans_Id
))
4886 and then Present
(Expr
)
4887 and then Nkind
(Expr
) = N_Allocator
;
4890 ---------------------------
4891 -- Is_Iterated_Container --
4892 ---------------------------
4894 function Is_Iterated_Container
4895 (Trans_Id
: Entity_Id
;
4896 First_Stmt
: Node_Id
) return Boolean
4906 -- It is not possible to iterate over containers in non-Ada 2012 code
4908 if Ada_Version
< Ada_2012
then
4912 Typ
:= Etype
(Trans_Id
);
4914 -- Handle access type created for secondary stack use
4916 if Is_Access_Type
(Typ
) then
4917 Typ
:= Designated_Type
(Typ
);
4920 -- Look for aspect Default_Iterator. It may be part of a type
4921 -- declaration for a container, or inherited from a base type
4924 Aspect
:= Find_Value_Of_Aspect
(Typ
, Aspect_Default_Iterator
);
4926 if Present
(Aspect
) then
4927 Iter
:= Entity
(Aspect
);
4929 -- Examine the statements following the container object and
4930 -- look for a call to the default iterate routine where the
4931 -- first parameter is the transient. Such a call appears as:
4933 -- It : Access_To_CW_Iterator :=
4934 -- Iterate (Tran_Id.all, ...)'reference;
4937 while Present
(Stmt
) loop
4939 -- Detect an object declaration which is initialized by a
4940 -- secondary stack function call.
4942 if Nkind
(Stmt
) = N_Object_Declaration
4943 and then Present
(Expression
(Stmt
))
4944 and then Nkind
(Expression
(Stmt
)) = N_Reference
4945 and then Nkind
(Prefix
(Expression
(Stmt
))) = N_Function_Call
4947 Call
:= Prefix
(Expression
(Stmt
));
4949 -- The call must invoke the default iterate routine of
4950 -- the container and the transient object must appear as
4951 -- the first actual parameter. Skip any calls whose names
4952 -- are not entities.
4954 if Is_Entity_Name
(Name
(Call
))
4955 and then Entity
(Name
(Call
)) = Iter
4956 and then Present
(Parameter_Associations
(Call
))
4958 Param
:= First
(Parameter_Associations
(Call
));
4960 if Nkind
(Param
) = N_Explicit_Dereference
4961 and then Entity
(Prefix
(Param
)) = Trans_Id
4973 end Is_Iterated_Container
;
4975 -- Start of processing for Is_Finalizable_Transient
4978 -- Handle access types
4980 if Is_Access_Type
(Desig
) then
4981 Desig
:= Available_View
(Designated_Type
(Desig
));
4985 Ekind_In
(Obj_Id
, E_Constant
, E_Variable
)
4986 and then Needs_Finalization
(Desig
)
4987 and then Requires_Transient_Scope
(Desig
)
4988 and then Nkind
(Rel_Node
) /= N_Simple_Return_Statement
4990 -- Do not consider renamed or 'reference-d transient objects because
4991 -- the act of renaming extends the object's lifetime.
4993 and then not Is_Aliased
(Obj_Id
, Decl
)
4995 -- Do not consider transient objects allocated on the heap since
4996 -- they are attached to a finalization master.
4998 and then not Is_Allocated
(Obj_Id
)
5000 -- If the transient object is a pointer, check that it is not
5001 -- initialized by a function which returns a pointer or acts as a
5002 -- renaming of another pointer.
5005 (not Is_Access_Type
(Obj_Typ
)
5006 or else not Initialized_By_Access
(Obj_Id
))
5008 -- Do not consider transient objects which act as indirect aliases
5009 -- of build-in-place function results.
5011 and then not Initialized_By_Aliased_BIP_Func_Call
(Obj_Id
)
5013 -- Do not consider conversions of tags to class-wide types
5015 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
5017 -- Do not consider containers in the context of iterator loops. Such
5018 -- transient objects must exist for as long as the loop is around,
5019 -- otherwise any operation carried out by the iterator will fail.
5021 and then not Is_Iterated_Container
(Obj_Id
, Decl
);
5022 end Is_Finalizable_Transient
;
5024 ---------------------------------
5025 -- Is_Fully_Repped_Tagged_Type --
5026 ---------------------------------
5028 function Is_Fully_Repped_Tagged_Type
(T
: Entity_Id
) return Boolean is
5029 U
: constant Entity_Id
:= Underlying_Type
(T
);
5033 if No
(U
) or else not Is_Tagged_Type
(U
) then
5035 elsif Has_Discriminants
(U
) then
5037 elsif not Has_Specified_Layout
(U
) then
5041 -- Here we have a tagged type, see if it has any unlayed out fields
5042 -- other than a possible tag and parent fields. If so, we return False.
5044 Comp
:= First_Component
(U
);
5045 while Present
(Comp
) loop
5046 if not Is_Tag
(Comp
)
5047 and then Chars
(Comp
) /= Name_uParent
5048 and then No
(Component_Clause
(Comp
))
5052 Next_Component
(Comp
);
5056 -- All components are layed out
5059 end Is_Fully_Repped_Tagged_Type
;
5061 ----------------------------------
5062 -- Is_Library_Level_Tagged_Type --
5063 ----------------------------------
5065 function Is_Library_Level_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
5067 return Is_Tagged_Type
(Typ
) and then Is_Library_Level_Entity
(Typ
);
5068 end Is_Library_Level_Tagged_Type
;
5070 --------------------------
5071 -- Is_Non_BIP_Func_Call --
5072 --------------------------
5074 function Is_Non_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
5076 -- The expected call is of the format
5078 -- Func_Call'reference
5081 Nkind
(Expr
) = N_Reference
5082 and then Nkind
(Prefix
(Expr
)) = N_Function_Call
5083 and then not Is_Build_In_Place_Function_Call
(Prefix
(Expr
));
5084 end Is_Non_BIP_Func_Call
;
5086 ------------------------------------
5087 -- Is_Object_Access_BIP_Func_Call --
5088 ------------------------------------
5090 function Is_Object_Access_BIP_Func_Call
5092 Obj_Id
: Entity_Id
) return Boolean
5094 Access_Nam
: Name_Id
:= No_Name
;
5101 -- Build-in-place calls usually appear in 'reference format. Note that
5102 -- the accessibility check machinery may add an extra 'reference due to
5103 -- side effect removal.
5106 while Nkind
(Call
) = N_Reference
loop
5107 Call
:= Prefix
(Call
);
5110 if Nkind_In
(Call
, N_Qualified_Expression
,
5111 N_Unchecked_Type_Conversion
)
5113 Call
:= Expression
(Call
);
5116 if Is_Build_In_Place_Function_Call
(Call
) then
5118 -- Examine all parameter associations of the function call
5120 Param
:= First
(Parameter_Associations
(Call
));
5121 while Present
(Param
) loop
5122 if Nkind
(Param
) = N_Parameter_Association
5123 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
5125 Formal
:= Selector_Name
(Param
);
5126 Actual
:= Explicit_Actual_Parameter
(Param
);
5128 -- Construct the name of formal BIPaccess. It is much easier to
5129 -- extract the name of the function using an arbitrary formal's
5130 -- scope rather than the Name field of Call.
5132 if Access_Nam
= No_Name
and then Present
(Entity
(Formal
)) then
5135 (Chars
(Scope
(Entity
(Formal
))),
5136 BIP_Formal_Suffix
(BIP_Object_Access
));
5139 -- A match for BIPaccess => Obj_Id'Unrestricted_Access has been
5142 if Chars
(Formal
) = Access_Nam
5143 and then Nkind
(Actual
) = N_Attribute_Reference
5144 and then Attribute_Name
(Actual
) = Name_Unrestricted_Access
5145 and then Nkind
(Prefix
(Actual
)) = N_Identifier
5146 and then Entity
(Prefix
(Actual
)) = Obj_Id
5157 end Is_Object_Access_BIP_Func_Call
;
5159 ----------------------------------
5160 -- Is_Possibly_Unaligned_Object --
5161 ----------------------------------
5163 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean is
5164 T
: constant Entity_Id
:= Etype
(N
);
5167 -- Objects are never unaligned on VMs
5169 if VM_Target
/= No_VM
then
5173 -- If renamed object, apply test to underlying object
5175 if Is_Entity_Name
(N
)
5176 and then Is_Object
(Entity
(N
))
5177 and then Present
(Renamed_Object
(Entity
(N
)))
5179 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(N
)));
5182 -- Tagged and controlled types and aliased types are always aligned, as
5183 -- are concurrent types.
5186 or else Has_Controlled_Component
(T
)
5187 or else Is_Concurrent_Type
(T
)
5188 or else Is_Tagged_Type
(T
)
5189 or else Is_Controlled
(T
)
5194 -- If this is an element of a packed array, may be unaligned
5196 if Is_Ref_To_Bit_Packed_Array
(N
) then
5200 -- Case of indexed component reference: test whether prefix is unaligned
5202 if Nkind
(N
) = N_Indexed_Component
then
5203 return Is_Possibly_Unaligned_Object
(Prefix
(N
));
5205 -- Case of selected component reference
5207 elsif Nkind
(N
) = N_Selected_Component
then
5209 P
: constant Node_Id
:= Prefix
(N
);
5210 C
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
5215 -- If component reference is for an array with non-static bounds,
5216 -- then it is always aligned: we can only process unaligned arrays
5217 -- with static bounds (more precisely compile time known bounds).
5219 if Is_Array_Type
(T
)
5220 and then not Compile_Time_Known_Bounds
(T
)
5225 -- If component is aliased, it is definitely properly aligned
5227 if Is_Aliased
(C
) then
5231 -- If component is for a type implemented as a scalar, and the
5232 -- record is packed, and the component is other than the first
5233 -- component of the record, then the component may be unaligned.
5235 if Is_Packed
(Etype
(P
))
5236 and then Represented_As_Scalar
(Etype
(C
))
5237 and then First_Entity
(Scope
(C
)) /= C
5242 -- Compute maximum possible alignment for T
5244 -- If alignment is known, then that settles things
5246 if Known_Alignment
(T
) then
5247 M
:= UI_To_Int
(Alignment
(T
));
5249 -- If alignment is not known, tentatively set max alignment
5252 M
:= Ttypes
.Maximum_Alignment
;
5254 -- We can reduce this if the Esize is known since the default
5255 -- alignment will never be more than the smallest power of 2
5256 -- that does not exceed this Esize value.
5258 if Known_Esize
(T
) then
5259 S
:= UI_To_Int
(Esize
(T
));
5261 while (M
/ 2) >= S
loop
5267 -- The following code is historical, it used to be present but it
5268 -- is too cautious, because the front-end does not know the proper
5269 -- default alignments for the target. Also, if the alignment is
5270 -- not known, the front end can't know in any case. If a copy is
5271 -- needed, the back-end will take care of it. This whole section
5272 -- including this comment can be removed later ???
5274 -- If the component reference is for a record that has a specified
5275 -- alignment, and we either know it is too small, or cannot tell,
5276 -- then the component may be unaligned.
5278 -- What is the following commented out code ???
5280 -- if Known_Alignment (Etype (P))
5281 -- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
5282 -- and then M > Alignment (Etype (P))
5287 -- Case of component clause present which may specify an
5288 -- unaligned position.
5290 if Present
(Component_Clause
(C
)) then
5292 -- Otherwise we can do a test to make sure that the actual
5293 -- start position in the record, and the length, are both
5294 -- consistent with the required alignment. If not, we know
5295 -- that we are unaligned.
5298 Align_In_Bits
: constant Nat
:= M
* System_Storage_Unit
;
5300 if Component_Bit_Offset
(C
) mod Align_In_Bits
/= 0
5301 or else Esize
(C
) mod Align_In_Bits
/= 0
5308 -- Otherwise, for a component reference, test prefix
5310 return Is_Possibly_Unaligned_Object
(P
);
5313 -- If not a component reference, must be aligned
5318 end Is_Possibly_Unaligned_Object
;
5320 ---------------------------------
5321 -- Is_Possibly_Unaligned_Slice --
5322 ---------------------------------
5324 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean is
5326 -- Go to renamed object
5328 if Is_Entity_Name
(N
)
5329 and then Is_Object
(Entity
(N
))
5330 and then Present
(Renamed_Object
(Entity
(N
)))
5332 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(N
)));
5335 -- The reference must be a slice
5337 if Nkind
(N
) /= N_Slice
then
5341 -- We only need to worry if the target has strict alignment
5343 if not Target_Strict_Alignment
then
5347 -- If it is a slice, then look at the array type being sliced
5350 Sarr
: constant Node_Id
:= Prefix
(N
);
5351 -- Prefix of the slice, i.e. the array being sliced
5353 Styp
: constant Entity_Id
:= Etype
(Prefix
(N
));
5354 -- Type of the array being sliced
5360 -- The problems arise if the array object that is being sliced
5361 -- is a component of a record or array, and we cannot guarantee
5362 -- the alignment of the array within its containing object.
5364 -- To investigate this, we look at successive prefixes to see
5365 -- if we have a worrisome indexed or selected component.
5369 -- Case of array is part of an indexed component reference
5371 if Nkind
(Pref
) = N_Indexed_Component
then
5372 Ptyp
:= Etype
(Prefix
(Pref
));
5374 -- The only problematic case is when the array is packed, in
5375 -- which case we really know nothing about the alignment of
5376 -- individual components.
5378 if Is_Bit_Packed_Array
(Ptyp
) then
5382 -- Case of array is part of a selected component reference
5384 elsif Nkind
(Pref
) = N_Selected_Component
then
5385 Ptyp
:= Etype
(Prefix
(Pref
));
5387 -- We are definitely in trouble if the record in question
5388 -- has an alignment, and either we know this alignment is
5389 -- inconsistent with the alignment of the slice, or we don't
5390 -- know what the alignment of the slice should be.
5392 if Known_Alignment
(Ptyp
)
5393 and then (Unknown_Alignment
(Styp
)
5394 or else Alignment
(Styp
) > Alignment
(Ptyp
))
5399 -- We are in potential trouble if the record type is packed.
5400 -- We could special case when we know that the array is the
5401 -- first component, but that's not such a simple case ???
5403 if Is_Packed
(Ptyp
) then
5407 -- We are in trouble if there is a component clause, and
5408 -- either we do not know the alignment of the slice, or
5409 -- the alignment of the slice is inconsistent with the
5410 -- bit position specified by the component clause.
5413 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
5415 if Present
(Component_Clause
(Field
))
5417 (Unknown_Alignment
(Styp
)
5419 (Component_Bit_Offset
(Field
) mod
5420 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
5426 -- For cases other than selected or indexed components we know we
5427 -- are OK, since no issues arise over alignment.
5433 -- We processed an indexed component or selected component
5434 -- reference that looked safe, so keep checking prefixes.
5436 Pref
:= Prefix
(Pref
);
5439 end Is_Possibly_Unaligned_Slice
;
5441 -------------------------------
5442 -- Is_Related_To_Func_Return --
5443 -------------------------------
5445 function Is_Related_To_Func_Return
(Id
: Entity_Id
) return Boolean is
5446 Expr
: constant Node_Id
:= Related_Expression
(Id
);
5450 and then Nkind
(Expr
) = N_Explicit_Dereference
5451 and then Nkind
(Parent
(Expr
)) = N_Simple_Return_Statement
;
5452 end Is_Related_To_Func_Return
;
5454 --------------------------------
5455 -- Is_Ref_To_Bit_Packed_Array --
5456 --------------------------------
5458 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean is
5463 if Is_Entity_Name
(N
)
5464 and then Is_Object
(Entity
(N
))
5465 and then Present
(Renamed_Object
(Entity
(N
)))
5467 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(N
)));
5470 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5471 if Is_Bit_Packed_Array
(Etype
(Prefix
(N
))) then
5474 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(N
));
5477 if Result
and then Nkind
(N
) = N_Indexed_Component
then
5478 Expr
:= First
(Expressions
(N
));
5479 while Present
(Expr
) loop
5480 Force_Evaluation
(Expr
);
5490 end Is_Ref_To_Bit_Packed_Array
;
5492 --------------------------------
5493 -- Is_Ref_To_Bit_Packed_Slice --
5494 --------------------------------
5496 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean is
5498 if Nkind
(N
) = N_Type_Conversion
then
5499 return Is_Ref_To_Bit_Packed_Slice
(Expression
(N
));
5501 elsif Is_Entity_Name
(N
)
5502 and then Is_Object
(Entity
(N
))
5503 and then Present
(Renamed_Object
(Entity
(N
)))
5505 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(N
)));
5507 elsif Nkind
(N
) = N_Slice
5508 and then Is_Bit_Packed_Array
(Etype
(Prefix
(N
)))
5512 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5513 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(N
));
5518 end Is_Ref_To_Bit_Packed_Slice
;
5520 -----------------------
5521 -- Is_Renamed_Object --
5522 -----------------------
5524 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
5525 Pnod
: constant Node_Id
:= Parent
(N
);
5526 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
5528 if Kind
= N_Object_Renaming_Declaration
then
5530 elsif Nkind_In
(Kind
, N_Indexed_Component
, N_Selected_Component
) then
5531 return Is_Renamed_Object
(Pnod
);
5535 end Is_Renamed_Object
;
5537 --------------------------------------
5538 -- Is_Secondary_Stack_BIP_Func_Call --
5539 --------------------------------------
5541 function Is_Secondary_Stack_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
5542 Alloc_Nam
: Name_Id
:= No_Name
;
5544 Call
: Node_Id
:= Expr
;
5549 -- Build-in-place calls usually appear in 'reference format. Note that
5550 -- the accessibility check machinery may add an extra 'reference due to
5551 -- side effect removal.
5553 while Nkind
(Call
) = N_Reference
loop
5554 Call
:= Prefix
(Call
);
5557 if Nkind_In
(Call
, N_Qualified_Expression
,
5558 N_Unchecked_Type_Conversion
)
5560 Call
:= Expression
(Call
);
5563 if Is_Build_In_Place_Function_Call
(Call
) then
5565 -- Examine all parameter associations of the function call
5567 Param
:= First
(Parameter_Associations
(Call
));
5568 while Present
(Param
) loop
5569 if Nkind
(Param
) = N_Parameter_Association
5570 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
5572 Formal
:= Selector_Name
(Param
);
5573 Actual
:= Explicit_Actual_Parameter
(Param
);
5575 -- Construct the name of formal BIPalloc. It is much easier to
5576 -- extract the name of the function using an arbitrary formal's
5577 -- scope rather than the Name field of Call.
5579 if Alloc_Nam
= No_Name
and then Present
(Entity
(Formal
)) then
5582 (Chars
(Scope
(Entity
(Formal
))),
5583 BIP_Formal_Suffix
(BIP_Alloc_Form
));
5586 -- A match for BIPalloc => 2 has been found
5588 if Chars
(Formal
) = Alloc_Nam
5589 and then Nkind
(Actual
) = N_Integer_Literal
5590 and then Intval
(Actual
) = Uint_2
5601 end Is_Secondary_Stack_BIP_Func_Call
;
5603 -------------------------------------
5604 -- Is_Tag_To_Class_Wide_Conversion --
5605 -------------------------------------
5607 function Is_Tag_To_Class_Wide_Conversion
5608 (Obj_Id
: Entity_Id
) return Boolean
5610 Expr
: constant Node_Id
:= Expression
(Parent
(Obj_Id
));
5614 Is_Class_Wide_Type
(Etype
(Obj_Id
))
5615 and then Present
(Expr
)
5616 and then Nkind
(Expr
) = N_Unchecked_Type_Conversion
5617 and then Etype
(Expression
(Expr
)) = RTE
(RE_Tag
);
5618 end Is_Tag_To_Class_Wide_Conversion
;
5620 ----------------------------
5621 -- Is_Untagged_Derivation --
5622 ----------------------------
5624 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
5626 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
5628 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
5629 and then not Is_Tagged_Type
(Full_View
(T
))
5630 and then Is_Derived_Type
(Full_View
(T
))
5631 and then Etype
(Full_View
(T
)) /= T
);
5632 end Is_Untagged_Derivation
;
5634 ---------------------------
5635 -- Is_Volatile_Reference --
5636 ---------------------------
5638 function Is_Volatile_Reference
(N
: Node_Id
) return Boolean is
5640 -- Only source references are to be treated as volatile, internally
5641 -- generated stuff cannot have volatile external effects.
5643 if not Comes_From_Source
(N
) then
5646 -- Never true for reference to a type
5648 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
5651 -- True if object reference with volatile type
5653 elsif Is_Volatile_Object
(N
) then
5656 -- True if reference to volatile entity
5658 elsif Is_Entity_Name
(N
) then
5659 return Treat_As_Volatile
(Entity
(N
));
5661 -- True for slice of volatile array
5663 elsif Nkind
(N
) = N_Slice
then
5664 return Is_Volatile_Reference
(Prefix
(N
));
5666 -- True if volatile component
5668 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5669 if (Is_Entity_Name
(Prefix
(N
))
5670 and then Has_Volatile_Components
(Entity
(Prefix
(N
))))
5671 or else (Present
(Etype
(Prefix
(N
)))
5672 and then Has_Volatile_Components
(Etype
(Prefix
(N
))))
5676 return Is_Volatile_Reference
(Prefix
(N
));
5684 end Is_Volatile_Reference
;
5686 --------------------------
5687 -- Is_VM_By_Copy_Actual --
5688 --------------------------
5690 function Is_VM_By_Copy_Actual
(N
: Node_Id
) return Boolean is
5692 return VM_Target
/= No_VM
5693 and then (Nkind
(N
) = N_Slice
5695 (Nkind
(N
) = N_Identifier
5696 and then Present
(Renamed_Object
(Entity
(N
)))
5697 and then Nkind
(Renamed_Object
(Entity
(N
))) =
5699 end Is_VM_By_Copy_Actual
;
5701 --------------------
5702 -- Kill_Dead_Code --
5703 --------------------
5705 procedure Kill_Dead_Code
(N
: Node_Id
; Warn
: Boolean := False) is
5706 W
: Boolean := Warn
;
5707 -- Set False if warnings suppressed
5711 Remove_Warning_Messages
(N
);
5713 -- Generate warning if appropriate
5717 -- We suppress the warning if this code is under control of an
5718 -- if statement, whose condition is a simple identifier, and
5719 -- either we are in an instance, or warnings off is set for this
5720 -- identifier. The reason for killing it in the instance case is
5721 -- that it is common and reasonable for code to be deleted in
5722 -- instances for various reasons.
5724 -- Could we use Is_Statically_Unevaluated here???
5726 if Nkind
(Parent
(N
)) = N_If_Statement
then
5728 C
: constant Node_Id
:= Condition
(Parent
(N
));
5730 if Nkind
(C
) = N_Identifier
5733 or else (Present
(Entity
(C
))
5734 and then Has_Warnings_Off
(Entity
(C
))))
5741 -- Generate warning if not suppressed
5745 ("?t?this code can never be executed and has been deleted!",
5750 -- Recurse into block statements and bodies to process declarations
5753 if Nkind
(N
) = N_Block_Statement
5754 or else Nkind
(N
) = N_Subprogram_Body
5755 or else Nkind
(N
) = N_Package_Body
5757 Kill_Dead_Code
(Declarations
(N
), False);
5758 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
5760 if Nkind
(N
) = N_Subprogram_Body
then
5761 Set_Is_Eliminated
(Defining_Entity
(N
));
5764 elsif Nkind
(N
) = N_Package_Declaration
then
5765 Kill_Dead_Code
(Visible_Declarations
(Specification
(N
)));
5766 Kill_Dead_Code
(Private_Declarations
(Specification
(N
)));
5768 -- ??? After this point, Delete_Tree has been called on all
5769 -- declarations in Specification (N), so references to entities
5770 -- therein look suspicious.
5773 E
: Entity_Id
:= First_Entity
(Defining_Entity
(N
));
5776 while Present
(E
) loop
5777 if Ekind
(E
) = E_Operator
then
5778 Set_Is_Eliminated
(E
);
5785 -- Recurse into composite statement to kill individual statements in
5786 -- particular instantiations.
5788 elsif Nkind
(N
) = N_If_Statement
then
5789 Kill_Dead_Code
(Then_Statements
(N
));
5790 Kill_Dead_Code
(Elsif_Parts
(N
));
5791 Kill_Dead_Code
(Else_Statements
(N
));
5793 elsif Nkind
(N
) = N_Loop_Statement
then
5794 Kill_Dead_Code
(Statements
(N
));
5796 elsif Nkind
(N
) = N_Case_Statement
then
5800 Alt
:= First
(Alternatives
(N
));
5801 while Present
(Alt
) loop
5802 Kill_Dead_Code
(Statements
(Alt
));
5807 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
5808 Kill_Dead_Code
(Statements
(N
));
5810 -- Deal with dead instances caused by deleting instantiations
5812 elsif Nkind
(N
) in N_Generic_Instantiation
then
5813 Remove_Dead_Instance
(N
);
5818 -- Case where argument is a list of nodes to be killed
5820 procedure Kill_Dead_Code
(L
: List_Id
; Warn
: Boolean := False) is
5827 if Is_Non_Empty_List
(L
) then
5829 while Present
(N
) loop
5830 Kill_Dead_Code
(N
, W
);
5837 ------------------------
5838 -- Known_Non_Negative --
5839 ------------------------
5841 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
5843 if Is_OK_Static_Expression
(Opnd
) and then Expr_Value
(Opnd
) >= 0 then
5848 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
5851 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
5854 end Known_Non_Negative
;
5856 --------------------
5857 -- Known_Non_Null --
5858 --------------------
5860 function Known_Non_Null
(N
: Node_Id
) return Boolean is
5862 -- Checks for case where N is an entity reference
5864 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5866 E
: constant Entity_Id
:= Entity
(N
);
5871 -- First check if we are in decisive conditional
5873 Get_Current_Value_Condition
(N
, Op
, Val
);
5875 if Known_Null
(Val
) then
5876 if Op
= N_Op_Eq
then
5878 elsif Op
= N_Op_Ne
then
5883 -- If OK to do replacement, test Is_Known_Non_Null flag
5885 if OK_To_Do_Constant_Replacement
(E
) then
5886 return Is_Known_Non_Null
(E
);
5888 -- Otherwise if not safe to do replacement, then say so
5895 -- True if access attribute
5897 elsif Nkind
(N
) = N_Attribute_Reference
5898 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
5899 Name_Unchecked_Access
,
5900 Name_Unrestricted_Access
)
5904 -- True if allocator
5906 elsif Nkind
(N
) = N_Allocator
then
5909 -- For a conversion, true if expression is known non-null
5911 elsif Nkind
(N
) = N_Type_Conversion
then
5912 return Known_Non_Null
(Expression
(N
));
5914 -- Above are all cases where the value could be determined to be
5915 -- non-null. In all other cases, we don't know, so return False.
5926 function Known_Null
(N
: Node_Id
) return Boolean is
5928 -- Checks for case where N is an entity reference
5930 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5932 E
: constant Entity_Id
:= Entity
(N
);
5937 -- Constant null value is for sure null
5939 if Ekind
(E
) = E_Constant
5940 and then Known_Null
(Constant_Value
(E
))
5945 -- First check if we are in decisive conditional
5947 Get_Current_Value_Condition
(N
, Op
, Val
);
5949 if Known_Null
(Val
) then
5950 if Op
= N_Op_Eq
then
5952 elsif Op
= N_Op_Ne
then
5957 -- If OK to do replacement, test Is_Known_Null flag
5959 if OK_To_Do_Constant_Replacement
(E
) then
5960 return Is_Known_Null
(E
);
5962 -- Otherwise if not safe to do replacement, then say so
5969 -- True if explicit reference to null
5971 elsif Nkind
(N
) = N_Null
then
5974 -- For a conversion, true if expression is known null
5976 elsif Nkind
(N
) = N_Type_Conversion
then
5977 return Known_Null
(Expression
(N
));
5979 -- Above are all cases where the value could be determined to be null.
5980 -- In all other cases, we don't know, so return False.
5987 -----------------------------
5988 -- Make_CW_Equivalent_Type --
5989 -----------------------------
5991 -- Create a record type used as an equivalent of any member of the class
5992 -- which takes its size from exp.
5994 -- Generate the following code:
5996 -- type Equiv_T is record
5997 -- _parent : T (List of discriminant constraints taken from Exp);
5998 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
6001 -- ??? Note that this type does not guarantee same alignment as all
6004 function Make_CW_Equivalent_Type
6006 E
: Node_Id
) return Entity_Id
6008 Loc
: constant Source_Ptr
:= Sloc
(E
);
6009 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
6010 List_Def
: constant List_Id
:= Empty_List
;
6011 Comp_List
: constant List_Id
:= New_List
;
6012 Equiv_Type
: Entity_Id
;
6013 Range_Type
: Entity_Id
;
6014 Str_Type
: Entity_Id
;
6015 Constr_Root
: Entity_Id
;
6019 -- If the root type is already constrained, there are no discriminants
6020 -- in the expression.
6022 if not Has_Discriminants
(Root_Typ
)
6023 or else Is_Constrained
(Root_Typ
)
6025 Constr_Root
:= Root_Typ
;
6027 Constr_Root
:= Make_Temporary
(Loc
, 'R');
6029 -- subtype cstr__n is T (List of discr constraints taken from Exp)
6031 Append_To
(List_Def
,
6032 Make_Subtype_Declaration
(Loc
,
6033 Defining_Identifier
=> Constr_Root
,
6034 Subtype_Indication
=> Make_Subtype_From_Expr
(E
, Root_Typ
)));
6037 -- Generate the range subtype declaration
6039 Range_Type
:= Make_Temporary
(Loc
, 'G');
6041 if not Is_Interface
(Root_Typ
) then
6043 -- subtype rg__xx is
6044 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
6047 Make_Op_Subtract
(Loc
,
6049 Make_Attribute_Reference
(Loc
,
6051 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
6052 Attribute_Name
=> Name_Size
),
6054 Make_Attribute_Reference
(Loc
,
6055 Prefix
=> New_Occurrence_Of
(Constr_Root
, Loc
),
6056 Attribute_Name
=> Name_Object_Size
));
6058 -- subtype rg__xx is
6059 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
6062 Make_Attribute_Reference
(Loc
,
6064 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
6065 Attribute_Name
=> Name_Size
);
6068 Set_Paren_Count
(Sizexpr
, 1);
6070 Append_To
(List_Def
,
6071 Make_Subtype_Declaration
(Loc
,
6072 Defining_Identifier
=> Range_Type
,
6073 Subtype_Indication
=>
6074 Make_Subtype_Indication
(Loc
,
6075 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
6076 Constraint
=> Make_Range_Constraint
(Loc
,
6079 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6081 Make_Op_Divide
(Loc
,
6082 Left_Opnd
=> Sizexpr
,
6083 Right_Opnd
=> Make_Integer_Literal
(Loc
,
6084 Intval
=> System_Storage_Unit
)))))));
6086 -- subtype str__nn is Storage_Array (rg__x);
6088 Str_Type
:= Make_Temporary
(Loc
, 'S');
6089 Append_To
(List_Def
,
6090 Make_Subtype_Declaration
(Loc
,
6091 Defining_Identifier
=> Str_Type
,
6092 Subtype_Indication
=>
6093 Make_Subtype_Indication
(Loc
,
6094 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
6096 Make_Index_Or_Discriminant_Constraint
(Loc
,
6098 New_List
(New_Occurrence_Of
(Range_Type
, Loc
))))));
6100 -- type Equiv_T is record
6101 -- [ _parent : Tnn; ]
6105 Equiv_Type
:= Make_Temporary
(Loc
, 'T');
6106 Set_Ekind
(Equiv_Type
, E_Record_Type
);
6107 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
6109 -- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
6110 -- treatment for this type. In particular, even though _parent's type
6111 -- is a controlled type or contains controlled components, we do not
6112 -- want to set Has_Controlled_Component on it to avoid making it gain
6113 -- an unwanted _controller component.
6115 Set_Is_Class_Wide_Equivalent_Type
(Equiv_Type
);
6117 -- A class-wide equivalent type does not require initialization
6119 Set_Suppress_Initialization
(Equiv_Type
);
6121 if not Is_Interface
(Root_Typ
) then
6122 Append_To
(Comp_List
,
6123 Make_Component_Declaration
(Loc
,
6124 Defining_Identifier
=>
6125 Make_Defining_Identifier
(Loc
, Name_uParent
),
6126 Component_Definition
=>
6127 Make_Component_Definition
(Loc
,
6128 Aliased_Present
=> False,
6129 Subtype_Indication
=> New_Occurrence_Of
(Constr_Root
, Loc
))));
6132 Append_To
(Comp_List
,
6133 Make_Component_Declaration
(Loc
,
6134 Defining_Identifier
=> Make_Temporary
(Loc
, 'C'),
6135 Component_Definition
=>
6136 Make_Component_Definition
(Loc
,
6137 Aliased_Present
=> False,
6138 Subtype_Indication
=> New_Occurrence_Of
(Str_Type
, Loc
))));
6140 Append_To
(List_Def
,
6141 Make_Full_Type_Declaration
(Loc
,
6142 Defining_Identifier
=> Equiv_Type
,
6144 Make_Record_Definition
(Loc
,
6146 Make_Component_List
(Loc
,
6147 Component_Items
=> Comp_List
,
6148 Variant_Part
=> Empty
))));
6150 -- Suppress all checks during the analysis of the expanded code to avoid
6151 -- the generation of spurious warnings under ZFP run-time.
6153 Insert_Actions
(E
, List_Def
, Suppress
=> All_Checks
);
6155 end Make_CW_Equivalent_Type
;
6157 -------------------------
6158 -- Make_Invariant_Call --
6159 -------------------------
6161 function Make_Invariant_Call
(Expr
: Node_Id
) return Node_Id
is
6162 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6166 Typ
:= Etype
(Expr
);
6168 -- Subtypes may be subject to invariants coming from their respective
6169 -- base types. The subtype may be fully or partially private.
6171 if Ekind_In
(Typ
, E_Array_Subtype
,
6174 E_Record_Subtype_With_Private
)
6176 Typ
:= Base_Type
(Typ
);
6180 (Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)));
6183 Make_Procedure_Call_Statement
(Loc
,
6185 New_Occurrence_Of
(Invariant_Procedure
(Typ
), Loc
),
6186 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6187 end Make_Invariant_Call
;
6189 ------------------------
6190 -- Make_Literal_Range --
6191 ------------------------
6193 function Make_Literal_Range
6195 Literal_Typ
: Entity_Id
) return Node_Id
6197 Lo
: constant Node_Id
:=
6198 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
6199 Index
: constant Entity_Id
:= Etype
(Lo
);
6202 Length_Expr
: constant Node_Id
:=
6203 Make_Op_Subtract
(Loc
,
6205 Make_Integer_Literal
(Loc
,
6206 Intval
=> String_Literal_Length
(Literal_Typ
)),
6208 Make_Integer_Literal
(Loc
, 1));
6211 Set_Analyzed
(Lo
, False);
6213 if Is_Integer_Type
(Index
) then
6216 Left_Opnd
=> New_Copy_Tree
(Lo
),
6217 Right_Opnd
=> Length_Expr
);
6220 Make_Attribute_Reference
(Loc
,
6221 Attribute_Name
=> Name_Val
,
6222 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
6223 Expressions
=> New_List
(
6226 Make_Attribute_Reference
(Loc
,
6227 Attribute_Name
=> Name_Pos
,
6228 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
6229 Expressions
=> New_List
(New_Copy_Tree
(Lo
))),
6230 Right_Opnd
=> Length_Expr
)));
6237 end Make_Literal_Range
;
6239 --------------------------
6240 -- Make_Non_Empty_Check --
6241 --------------------------
6243 function Make_Non_Empty_Check
6245 N
: Node_Id
) return Node_Id
6251 Make_Attribute_Reference
(Loc
,
6252 Attribute_Name
=> Name_Length
,
6253 Prefix
=> Duplicate_Subexpr_No_Checks
(N
, Name_Req
=> True)),
6255 Make_Integer_Literal
(Loc
, 0));
6256 end Make_Non_Empty_Check
;
6258 -------------------------
6259 -- Make_Predicate_Call --
6260 -------------------------
6262 function Make_Predicate_Call
6265 Mem
: Boolean := False) return Node_Id
6267 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6270 pragma Assert
(Present
(Predicate_Function
(Typ
)));
6272 -- Call special membership version if requested and available
6276 PFM
: constant Entity_Id
:= Predicate_Function_M
(Typ
);
6278 if Present
(PFM
) then
6280 Make_Function_Call
(Loc
,
6281 Name
=> New_Occurrence_Of
(PFM
, Loc
),
6282 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6287 -- Case of calling normal predicate function
6290 Make_Function_Call
(Loc
,
6292 New_Occurrence_Of
(Predicate_Function
(Typ
), Loc
),
6293 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6294 end Make_Predicate_Call
;
6296 --------------------------
6297 -- Make_Predicate_Check --
6298 --------------------------
6300 function Make_Predicate_Check
6302 Expr
: Node_Id
) return Node_Id
6304 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6308 -- If predicate checks are suppressed, then return a null statement.
6309 -- For this call, we check only the scope setting. If the caller wants
6310 -- to check a specific entity's setting, they must do it manually.
6312 if Predicate_Checks_Suppressed
(Empty
) then
6313 return Make_Null_Statement
(Loc
);
6316 -- Do not generate a check within an internal subprogram (stream
6317 -- functions and the like, including including predicate functions).
6319 if Within_Internal_Subprogram
then
6320 return Make_Null_Statement
(Loc
);
6323 -- Compute proper name to use, we need to get this right so that the
6324 -- right set of check policies apply to the Check pragma we are making.
6326 if Has_Dynamic_Predicate_Aspect
(Typ
) then
6327 Nam
:= Name_Dynamic_Predicate
;
6328 elsif Has_Static_Predicate_Aspect
(Typ
) then
6329 Nam
:= Name_Static_Predicate
;
6331 Nam
:= Name_Predicate
;
6336 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Check
),
6337 Pragma_Argument_Associations
=> New_List
(
6338 Make_Pragma_Argument_Association
(Loc
,
6339 Expression
=> Make_Identifier
(Loc
, Nam
)),
6340 Make_Pragma_Argument_Association
(Loc
,
6341 Expression
=> Make_Predicate_Call
(Typ
, Expr
))));
6342 end Make_Predicate_Check
;
6344 ----------------------------
6345 -- Make_Subtype_From_Expr --
6346 ----------------------------
6348 -- 1. If Expr is an unconstrained array expression, creates
6349 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
6351 -- 2. If Expr is a unconstrained discriminated type expression, creates
6352 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
6354 -- 3. If Expr is class-wide, creates an implicit class-wide subtype
6356 function Make_Subtype_From_Expr
6358 Unc_Typ
: Entity_Id
) return Node_Id
6360 Loc
: constant Source_Ptr
:= Sloc
(E
);
6361 List_Constr
: constant List_Id
:= New_List
;
6364 Full_Subtyp
: Entity_Id
;
6365 Priv_Subtyp
: Entity_Id
;
6370 if Is_Private_Type
(Unc_Typ
)
6371 and then Has_Unknown_Discriminants
(Unc_Typ
)
6373 -- Prepare the subtype completion, Go to base type to
6374 -- find underlying type, because the type may be a generic
6375 -- actual or an explicit subtype.
6377 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
6378 Full_Subtyp
:= Make_Temporary
(Loc
, 'C');
6380 Unchecked_Convert_To
(Utyp
, Duplicate_Subexpr_No_Checks
(E
));
6381 Set_Parent
(Full_Exp
, Parent
(E
));
6383 Priv_Subtyp
:= Make_Temporary
(Loc
, 'P');
6386 Make_Subtype_Declaration
(Loc
,
6387 Defining_Identifier
=> Full_Subtyp
,
6388 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
6390 -- Define the dummy private subtype
6392 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
6393 Set_Etype
(Priv_Subtyp
, Base_Type
(Unc_Typ
));
6394 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
6395 Set_Is_Constrained
(Priv_Subtyp
);
6396 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
6397 Set_Is_Itype
(Priv_Subtyp
);
6398 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
6400 if Is_Tagged_Type
(Priv_Subtyp
) then
6402 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
6403 Set_Direct_Primitive_Operations
(Priv_Subtyp
,
6404 Direct_Primitive_Operations
(Unc_Typ
));
6407 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
6409 return New_Occurrence_Of
(Priv_Subtyp
, Loc
);
6411 elsif Is_Array_Type
(Unc_Typ
) then
6412 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
6413 Append_To
(List_Constr
,
6416 Make_Attribute_Reference
(Loc
,
6417 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6418 Attribute_Name
=> Name_First
,
6419 Expressions
=> New_List
(
6420 Make_Integer_Literal
(Loc
, J
))),
6423 Make_Attribute_Reference
(Loc
,
6424 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6425 Attribute_Name
=> Name_Last
,
6426 Expressions
=> New_List
(
6427 Make_Integer_Literal
(Loc
, J
)))));
6430 elsif Is_Class_Wide_Type
(Unc_Typ
) then
6432 CW_Subtype
: Entity_Id
;
6433 EQ_Typ
: Entity_Id
:= Empty
;
6436 -- A class-wide equivalent type is not needed when VM_Target
6437 -- because the VM back-ends handle the class-wide object
6438 -- initialization itself (and doesn't need or want the
6439 -- additional intermediate type to handle the assignment).
6441 if Expander_Active
and then Tagged_Type_Expansion
then
6443 -- If this is the class-wide type of a completion that is a
6444 -- record subtype, set the type of the class-wide type to be
6445 -- the full base type, for use in the expanded code for the
6446 -- equivalent type. Should this be done earlier when the
6447 -- completion is analyzed ???
6449 if Is_Private_Type
(Etype
(Unc_Typ
))
6451 Ekind
(Full_View
(Etype
(Unc_Typ
))) = E_Record_Subtype
6453 Set_Etype
(Unc_Typ
, Base_Type
(Full_View
(Etype
(Unc_Typ
))));
6456 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
6459 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
6460 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
6461 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
6463 return New_Occurrence_Of
(CW_Subtype
, Loc
);
6466 -- Indefinite record type with discriminants
6469 D
:= First_Discriminant
(Unc_Typ
);
6470 while Present
(D
) loop
6471 Append_To
(List_Constr
,
6472 Make_Selected_Component
(Loc
,
6473 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6474 Selector_Name
=> New_Occurrence_Of
(D
, Loc
)));
6476 Next_Discriminant
(D
);
6481 Make_Subtype_Indication
(Loc
,
6482 Subtype_Mark
=> New_Occurrence_Of
(Unc_Typ
, Loc
),
6484 Make_Index_Or_Discriminant_Constraint
(Loc
,
6485 Constraints
=> List_Constr
));
6486 end Make_Subtype_From_Expr
;
6488 ----------------------------
6489 -- Matching_Standard_Type --
6490 ----------------------------
6492 function Matching_Standard_Type
(Typ
: Entity_Id
) return Entity_Id
is
6493 pragma Assert
(Is_Scalar_Type
(Typ
));
6494 Siz
: constant Uint
:= Esize
(Typ
);
6497 -- Floating-point cases
6499 if Is_Floating_Point_Type
(Typ
) then
6500 if Siz
<= Esize
(Standard_Short_Float
) then
6501 return Standard_Short_Float
;
6502 elsif Siz
<= Esize
(Standard_Float
) then
6503 return Standard_Float
;
6504 elsif Siz
<= Esize
(Standard_Long_Float
) then
6505 return Standard_Long_Float
;
6506 elsif Siz
<= Esize
(Standard_Long_Long_Float
) then
6507 return Standard_Long_Long_Float
;
6509 raise Program_Error
;
6512 -- Integer cases (includes fixed-point types)
6514 -- Unsigned integer cases (includes normal enumeration types)
6516 elsif Is_Unsigned_Type
(Typ
) then
6517 if Siz
<= Esize
(Standard_Short_Short_Unsigned
) then
6518 return Standard_Short_Short_Unsigned
;
6519 elsif Siz
<= Esize
(Standard_Short_Unsigned
) then
6520 return Standard_Short_Unsigned
;
6521 elsif Siz
<= Esize
(Standard_Unsigned
) then
6522 return Standard_Unsigned
;
6523 elsif Siz
<= Esize
(Standard_Long_Unsigned
) then
6524 return Standard_Long_Unsigned
;
6525 elsif Siz
<= Esize
(Standard_Long_Long_Unsigned
) then
6526 return Standard_Long_Long_Unsigned
;
6528 raise Program_Error
;
6531 -- Signed integer cases
6534 if Siz
<= Esize
(Standard_Short_Short_Integer
) then
6535 return Standard_Short_Short_Integer
;
6536 elsif Siz
<= Esize
(Standard_Short_Integer
) then
6537 return Standard_Short_Integer
;
6538 elsif Siz
<= Esize
(Standard_Integer
) then
6539 return Standard_Integer
;
6540 elsif Siz
<= Esize
(Standard_Long_Integer
) then
6541 return Standard_Long_Integer
;
6542 elsif Siz
<= Esize
(Standard_Long_Long_Integer
) then
6543 return Standard_Long_Long_Integer
;
6545 raise Program_Error
;
6548 end Matching_Standard_Type
;
6550 -----------------------------
6551 -- May_Generate_Large_Temp --
6552 -----------------------------
6554 -- At the current time, the only types that we return False for (i.e. where
6555 -- we decide we know they cannot generate large temps) are ones where we
6556 -- know the size is 256 bits or less at compile time, and we are still not
6557 -- doing a thorough job on arrays and records ???
6559 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
6561 if not Size_Known_At_Compile_Time
(Typ
) then
6564 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
6567 elsif Is_Array_Type
(Typ
)
6568 and then Present
(Packed_Array_Impl_Type
(Typ
))
6570 return May_Generate_Large_Temp
(Packed_Array_Impl_Type
(Typ
));
6572 -- We could do more here to find other small types ???
6577 end May_Generate_Large_Temp
;
6579 ------------------------
6580 -- Needs_Finalization --
6581 ------------------------
6583 function Needs_Finalization
(T
: Entity_Id
) return Boolean is
6584 function Has_Some_Controlled_Component
(Rec
: Entity_Id
) return Boolean;
6585 -- If type is not frozen yet, check explicitly among its components,
6586 -- because the Has_Controlled_Component flag is not necessarily set.
6588 -----------------------------------
6589 -- Has_Some_Controlled_Component --
6590 -----------------------------------
6592 function Has_Some_Controlled_Component
6593 (Rec
: Entity_Id
) return Boolean
6598 if Has_Controlled_Component
(Rec
) then
6601 elsif not Is_Frozen
(Rec
) then
6602 if Is_Record_Type
(Rec
) then
6603 Comp
:= First_Entity
(Rec
);
6605 while Present
(Comp
) loop
6606 if not Is_Type
(Comp
)
6607 and then Needs_Finalization
(Etype
(Comp
))
6617 elsif Is_Array_Type
(Rec
) then
6618 return Needs_Finalization
(Component_Type
(Rec
));
6621 return Has_Controlled_Component
(Rec
);
6626 end Has_Some_Controlled_Component
;
6628 -- Start of processing for Needs_Finalization
6631 -- Certain run-time configurations and targets do not provide support
6632 -- for controlled types.
6634 if Restriction_Active
(No_Finalization
) then
6637 -- C++, CIL and Java types are not considered controlled. It is assumed
6638 -- that the non-Ada side will handle their clean up.
6640 elsif Convention
(T
) = Convention_CIL
6641 or else Convention
(T
) = Convention_CPP
6642 or else Convention
(T
) = Convention_Java
6647 -- Class-wide types are treated as controlled because derivations
6648 -- from the root type can introduce controlled components.
6651 Is_Class_Wide_Type
(T
)
6652 or else Is_Controlled
(T
)
6653 or else Has_Controlled_Component
(T
)
6654 or else Has_Some_Controlled_Component
(T
)
6656 (Is_Concurrent_Type
(T
)
6657 and then Present
(Corresponding_Record_Type
(T
))
6658 and then Needs_Finalization
(Corresponding_Record_Type
(T
)));
6660 end Needs_Finalization
;
6662 ----------------------------
6663 -- Needs_Constant_Address --
6664 ----------------------------
6666 function Needs_Constant_Address
6668 Typ
: Entity_Id
) return Boolean
6672 -- If we have no initialization of any kind, then we don't need to place
6673 -- any restrictions on the address clause, because the object will be
6674 -- elaborated after the address clause is evaluated. This happens if the
6675 -- declaration has no initial expression, or the type has no implicit
6676 -- initialization, or the object is imported.
6678 -- The same holds for all initialized scalar types and all access types.
6679 -- Packed bit arrays of size up to 64 are represented using a modular
6680 -- type with an initialization (to zero) and can be processed like other
6681 -- initialized scalar types.
6683 -- If the type is controlled, code to attach the object to a
6684 -- finalization chain is generated at the point of declaration, and
6685 -- therefore the elaboration of the object cannot be delayed: the
6686 -- address expression must be a constant.
6688 if No
(Expression
(Decl
))
6689 and then not Needs_Finalization
(Typ
)
6691 (not Has_Non_Null_Base_Init_Proc
(Typ
)
6692 or else Is_Imported
(Defining_Identifier
(Decl
)))
6696 elsif (Present
(Expression
(Decl
)) and then Is_Scalar_Type
(Typ
))
6697 or else Is_Access_Type
(Typ
)
6699 (Is_Bit_Packed_Array
(Typ
)
6700 and then Is_Modular_Integer_Type
(Packed_Array_Impl_Type
(Typ
)))
6706 -- Otherwise, we require the address clause to be constant because
6707 -- the call to the initialization procedure (or the attach code) has
6708 -- to happen at the point of the declaration.
6710 -- Actually the IP call has been moved to the freeze actions anyway,
6711 -- so maybe we can relax this restriction???
6715 end Needs_Constant_Address
;
6717 ----------------------------
6718 -- New_Class_Wide_Subtype --
6719 ----------------------------
6721 function New_Class_Wide_Subtype
6722 (CW_Typ
: Entity_Id
;
6723 N
: Node_Id
) return Entity_Id
6725 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
6726 Res_Name
: constant Name_Id
:= Chars
(Res
);
6727 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
6730 Copy_Node
(CW_Typ
, Res
);
6731 Set_Comes_From_Source
(Res
, False);
6732 Set_Sloc
(Res
, Sloc
(N
));
6734 Set_Associated_Node_For_Itype
(Res
, N
);
6735 Set_Is_Public
(Res
, False); -- By default, may be changed below.
6736 Set_Public_Status
(Res
);
6737 Set_Chars
(Res
, Res_Name
);
6738 Set_Scope
(Res
, Res_Scope
);
6739 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
6740 Set_Next_Entity
(Res
, Empty
);
6741 Set_Etype
(Res
, Base_Type
(CW_Typ
));
6742 Set_Is_Frozen
(Res
, False);
6743 Set_Freeze_Node
(Res
, Empty
);
6745 end New_Class_Wide_Subtype
;
6747 --------------------------------
6748 -- Non_Limited_Designated_Type --
6749 ---------------------------------
6751 function Non_Limited_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
6752 Desig
: constant Entity_Id
:= Designated_Type
(T
);
6754 if Ekind
(Desig
) = E_Incomplete_Type
6755 and then Present
(Non_Limited_View
(Desig
))
6757 return Non_Limited_View
(Desig
);
6761 end Non_Limited_Designated_Type
;
6763 -----------------------------------
6764 -- OK_To_Do_Constant_Replacement --
6765 -----------------------------------
6767 function OK_To_Do_Constant_Replacement
(E
: Entity_Id
) return Boolean is
6768 ES
: constant Entity_Id
:= Scope
(E
);
6772 -- Do not replace statically allocated objects, because they may be
6773 -- modified outside the current scope.
6775 if Is_Statically_Allocated
(E
) then
6778 -- Do not replace aliased or volatile objects, since we don't know what
6779 -- else might change the value.
6781 elsif Is_Aliased
(E
) or else Treat_As_Volatile
(E
) then
6784 -- Debug flag -gnatdM disconnects this optimization
6786 elsif Debug_Flag_MM
then
6789 -- Otherwise check scopes
6792 CS
:= Current_Scope
;
6795 -- If we are in right scope, replacement is safe
6800 -- Packages do not affect the determination of safety
6802 elsif Ekind
(CS
) = E_Package
then
6803 exit when CS
= Standard_Standard
;
6806 -- Blocks do not affect the determination of safety
6808 elsif Ekind
(CS
) = E_Block
then
6811 -- Loops do not affect the determination of safety. Note that we
6812 -- kill all current values on entry to a loop, so we are just
6813 -- talking about processing within a loop here.
6815 elsif Ekind
(CS
) = E_Loop
then
6818 -- Otherwise, the reference is dubious, and we cannot be sure that
6819 -- it is safe to do the replacement.
6828 end OK_To_Do_Constant_Replacement
;
6830 ------------------------------------
6831 -- Possible_Bit_Aligned_Component --
6832 ------------------------------------
6834 function Possible_Bit_Aligned_Component
(N
: Node_Id
) return Boolean is
6838 -- Case of indexed component
6840 when N_Indexed_Component
=>
6842 P
: constant Node_Id
:= Prefix
(N
);
6843 Ptyp
: constant Entity_Id
:= Etype
(P
);
6846 -- If we know the component size and it is less than 64, then
6847 -- we are definitely OK. The back end always does assignment of
6848 -- misaligned small objects correctly.
6850 if Known_Static_Component_Size
(Ptyp
)
6851 and then Component_Size
(Ptyp
) <= 64
6855 -- Otherwise, we need to test the prefix, to see if we are
6856 -- indexing from a possibly unaligned component.
6859 return Possible_Bit_Aligned_Component
(P
);
6863 -- Case of selected component
6865 when N_Selected_Component
=>
6867 P
: constant Node_Id
:= Prefix
(N
);
6868 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
6871 -- If there is no component clause, then we are in the clear
6872 -- since the back end will never misalign a large component
6873 -- unless it is forced to do so. In the clear means we need
6874 -- only the recursive test on the prefix.
6876 if Component_May_Be_Bit_Aligned
(Comp
) then
6879 return Possible_Bit_Aligned_Component
(P
);
6883 -- For a slice, test the prefix, if that is possibly misaligned,
6884 -- then for sure the slice is.
6887 return Possible_Bit_Aligned_Component
(Prefix
(N
));
6889 -- For an unchecked conversion, check whether the expression may
6892 when N_Unchecked_Type_Conversion
=>
6893 return Possible_Bit_Aligned_Component
(Expression
(N
));
6895 -- If we have none of the above, it means that we have fallen off the
6896 -- top testing prefixes recursively, and we now have a stand alone
6897 -- object, where we don't have a problem, unless this is a renaming,
6898 -- in which case we need to look into the renamed object.
6901 if Is_Entity_Name
(N
)
6902 and then Present
(Renamed_Object
(Entity
(N
)))
6905 Possible_Bit_Aligned_Component
(Renamed_Object
(Entity
(N
)));
6911 end Possible_Bit_Aligned_Component
;
6913 -----------------------------------------------
6914 -- Process_Statements_For_Controlled_Objects --
6915 -----------------------------------------------
6917 procedure Process_Statements_For_Controlled_Objects
(N
: Node_Id
) is
6918 Loc
: constant Source_Ptr
:= Sloc
(N
);
6920 function Are_Wrapped
(L
: List_Id
) return Boolean;
6921 -- Determine whether list L contains only one statement which is a block
6923 function Wrap_Statements_In_Block
6925 Scop
: Entity_Id
:= Current_Scope
) return Node_Id
;
6926 -- Given a list of statements L, wrap it in a block statement and return
6927 -- the generated node. Scop is either the current scope or the scope of
6928 -- the context (if applicable).
6934 function Are_Wrapped
(L
: List_Id
) return Boolean is
6935 Stmt
: constant Node_Id
:= First
(L
);
6939 and then No
(Next
(Stmt
))
6940 and then Nkind
(Stmt
) = N_Block_Statement
;
6943 ------------------------------
6944 -- Wrap_Statements_In_Block --
6945 ------------------------------
6947 function Wrap_Statements_In_Block
6949 Scop
: Entity_Id
:= Current_Scope
) return Node_Id
6951 Block_Id
: Entity_Id
;
6952 Block_Nod
: Node_Id
;
6953 Iter_Loop
: Entity_Id
;
6957 Make_Block_Statement
(Loc
,
6958 Declarations
=> No_List
,
6959 Handled_Statement_Sequence
=>
6960 Make_Handled_Sequence_Of_Statements
(Loc
,
6963 -- Create a label for the block in case the block needs to manage the
6964 -- secondary stack. A label allows for flag Uses_Sec_Stack to be set.
6966 Add_Block_Identifier
(Block_Nod
, Block_Id
);
6968 -- When wrapping the statements of an iterator loop, check whether
6969 -- the loop requires secondary stack management and if so, propagate
6970 -- the appropriate flags to the block. This ensures that the cursor
6971 -- is properly cleaned up at each iteration of the loop.
6973 Iter_Loop
:= Find_Enclosing_Iterator_Loop
(Scop
);
6975 if Present
(Iter_Loop
) then
6976 Set_Uses_Sec_Stack
(Block_Id
, Uses_Sec_Stack
(Iter_Loop
));
6978 -- Secondary stack reclamation is suppressed when the associated
6979 -- iterator loop contains a return statement which uses the stack.
6981 Set_Sec_Stack_Needed_For_Return
6982 (Block_Id
, Sec_Stack_Needed_For_Return
(Iter_Loop
));
6986 end Wrap_Statements_In_Block
;
6992 -- Start of processing for Process_Statements_For_Controlled_Objects
6995 -- Whenever a non-handled statement list is wrapped in a block, the
6996 -- block must be explicitly analyzed to redecorate all entities in the
6997 -- list and ensure that a finalizer is properly built.
7002 N_Conditional_Entry_Call |
7003 N_Selective_Accept
=>
7005 -- Check the "then statements" for elsif parts and if statements
7007 if Nkind_In
(N
, N_Elsif_Part
, N_If_Statement
)
7008 and then not Is_Empty_List
(Then_Statements
(N
))
7009 and then not Are_Wrapped
(Then_Statements
(N
))
7010 and then Requires_Cleanup_Actions
7011 (Then_Statements
(N
), False, False)
7013 Block
:= Wrap_Statements_In_Block
(Then_Statements
(N
));
7014 Set_Then_Statements
(N
, New_List
(Block
));
7019 -- Check the "else statements" for conditional entry calls, if
7020 -- statements and selective accepts.
7022 if Nkind_In
(N
, N_Conditional_Entry_Call
,
7025 and then not Is_Empty_List
(Else_Statements
(N
))
7026 and then not Are_Wrapped
(Else_Statements
(N
))
7027 and then Requires_Cleanup_Actions
7028 (Else_Statements
(N
), False, False)
7030 Block
:= Wrap_Statements_In_Block
(Else_Statements
(N
));
7031 Set_Else_Statements
(N
, New_List
(Block
));
7036 when N_Abortable_Part |
7037 N_Accept_Alternative |
7038 N_Case_Statement_Alternative |
7039 N_Delay_Alternative |
7040 N_Entry_Call_Alternative |
7041 N_Exception_Handler |
7043 N_Triggering_Alternative
=>
7045 if not Is_Empty_List
(Statements
(N
))
7046 and then not Are_Wrapped
(Statements
(N
))
7047 and then Requires_Cleanup_Actions
(Statements
(N
), False, False)
7049 if Nkind
(N
) = N_Loop_Statement
7050 and then Present
(Identifier
(N
))
7053 Wrap_Statements_In_Block
7054 (L
=> Statements
(N
),
7055 Scop
=> Entity
(Identifier
(N
)));
7057 Block
:= Wrap_Statements_In_Block
(Statements
(N
));
7060 Set_Statements
(N
, New_List
(Block
));
7067 end Process_Statements_For_Controlled_Objects
;
7073 function Power_Of_Two
(N
: Node_Id
) return Nat
is
7074 Typ
: constant Entity_Id
:= Etype
(N
);
7075 pragma Assert
(Is_Integer_Type
(Typ
));
7077 Siz
: constant Nat
:= UI_To_Int
(Esize
(Typ
));
7081 if not Compile_Time_Known_Value
(N
) then
7085 Val
:= Expr_Value
(N
);
7086 for J
in 1 .. Siz
- 1 loop
7087 if Val
= Uint_2
** J
then
7096 ----------------------
7097 -- Remove_Init_Call --
7098 ----------------------
7100 function Remove_Init_Call
7102 Rep_Clause
: Node_Id
) return Node_Id
7104 Par
: constant Node_Id
:= Parent
(Var
);
7105 Typ
: constant Entity_Id
:= Etype
(Var
);
7107 Init_Proc
: Entity_Id
;
7108 -- Initialization procedure for Typ
7110 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
;
7111 -- Look for init call for Var starting at From and scanning the
7112 -- enclosing list until Rep_Clause or the end of the list is reached.
7114 ----------------------------
7115 -- Find_Init_Call_In_List --
7116 ----------------------------
7118 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
is
7119 Init_Call
: Node_Id
;
7123 while Present
(Init_Call
) and then Init_Call
/= Rep_Clause
loop
7124 if Nkind
(Init_Call
) = N_Procedure_Call_Statement
7125 and then Is_Entity_Name
(Name
(Init_Call
))
7126 and then Entity
(Name
(Init_Call
)) = Init_Proc
7135 end Find_Init_Call_In_List
;
7137 Init_Call
: Node_Id
;
7139 -- Start of processing for Find_Init_Call
7142 if Present
(Initialization_Statements
(Var
)) then
7143 Init_Call
:= Initialization_Statements
(Var
);
7144 Set_Initialization_Statements
(Var
, Empty
);
7146 elsif not Has_Non_Null_Base_Init_Proc
(Typ
) then
7148 -- No init proc for the type, so obviously no call to be found
7153 -- We might be able to handle other cases below by just properly
7154 -- setting Initialization_Statements at the point where the init proc
7155 -- call is generated???
7157 Init_Proc
:= Base_Init_Proc
(Typ
);
7159 -- First scan the list containing the declaration of Var
7161 Init_Call
:= Find_Init_Call_In_List
(From
=> Next
(Par
));
7163 -- If not found, also look on Var's freeze actions list, if any,
7164 -- since the init call may have been moved there (case of an address
7165 -- clause applying to Var).
7167 if No
(Init_Call
) and then Present
(Freeze_Node
(Var
)) then
7169 Find_Init_Call_In_List
(First
(Actions
(Freeze_Node
(Var
))));
7172 -- If the initialization call has actuals that use the secondary
7173 -- stack, the call may have been wrapped into a temporary block, in
7174 -- which case the block itself has to be removed.
7176 if No
(Init_Call
) and then Nkind
(Next
(Par
)) = N_Block_Statement
then
7178 Blk
: constant Node_Id
:= Next
(Par
);
7181 (Find_Init_Call_In_List
7182 (First
(Statements
(Handled_Statement_Sequence
(Blk
)))))
7190 if Present
(Init_Call
) then
7194 end Remove_Init_Call
;
7196 -------------------------
7197 -- Remove_Side_Effects --
7198 -------------------------
7200 procedure Remove_Side_Effects
7202 Name_Req
: Boolean := False;
7203 Renaming_Req
: Boolean := False;
7204 Variable_Ref
: Boolean := False;
7205 Related_Id
: Entity_Id
:= Empty
;
7206 Is_Low_Bound
: Boolean := False;
7207 Is_High_Bound
: Boolean := False)
7209 function Build_Temporary
7212 Related_Nod
: Node_Id
:= Empty
) return Entity_Id
;
7213 -- Create an external symbol of the form xxx_FIRST/_LAST if Related_Id
7214 -- is present, otherwise it generates an internal temporary.
7216 ---------------------
7217 -- Build_Temporary --
7218 ---------------------
7220 function Build_Temporary
7223 Related_Nod
: Node_Id
:= Empty
) return Entity_Id
7228 -- The context requires an external symbol
7230 if Present
(Related_Id
) then
7231 if Is_Low_Bound
then
7232 Temp_Nam
:= New_External_Name
(Chars
(Related_Id
), "_FIRST");
7233 else pragma Assert
(Is_High_Bound
);
7234 Temp_Nam
:= New_External_Name
(Chars
(Related_Id
), "_LAST");
7237 return Make_Defining_Identifier
(Loc
, Temp_Nam
);
7239 -- Otherwise generate an internal temporary
7242 return Make_Temporary
(Loc
, Id
, Related_Nod
);
7244 end Build_Temporary
;
7248 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
7249 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
7250 Svg_Suppress
: constant Suppress_Record
:= Scope_Suppress
;
7254 Ptr_Typ_Decl
: Node_Id
;
7255 Ref_Type
: Entity_Id
;
7258 -- Start of processing for Remove_Side_Effects
7261 -- Handle cases in which there is nothing to do. In GNATprove mode,
7262 -- removal of side effects is useful for the light expansion of
7263 -- renamings. This removal should only occur when not inside a
7264 -- generic and not doing a pre-analysis.
7266 if not Expander_Active
7267 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
7272 -- Cannot generate temporaries if the invocation to remove side effects
7273 -- was issued too early and the type of the expression is not resolved
7274 -- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
7275 -- Remove_Side_Effects).
7277 if No
(Exp_Type
) or else Ekind
(Exp_Type
) = E_Access_Attribute_Type
then
7280 -- No action needed for side-effect free expressions
7282 elsif Side_Effect_Free
(Exp
, Name_Req
, Variable_Ref
) then
7286 -- The remaining procesaing is done with all checks suppressed
7288 -- Note: from now on, don't use return statements, instead do a goto
7289 -- Leave, to ensure that we properly restore Scope_Suppress.Suppress.
7291 Scope_Suppress
.Suppress
:= (others => True);
7293 -- If it is a scalar type and we need to capture the value, just make
7294 -- a copy. Likewise for a function call, an attribute reference, a
7295 -- conditional expression, an allocator, or an operator. And if we have
7296 -- a volatile reference and Name_Req is not set (see comments for
7297 -- Side_Effect_Free).
7299 if Is_Elementary_Type
(Exp_Type
)
7301 -- Note: this test is rather mysterious??? Why can't we just test ONLY
7302 -- Is_Elementary_Type and be done with it. If we try that approach, we
7303 -- get some failures (infinite recursions) from the Duplicate_Subexpr
7304 -- call at the end of Checks.Apply_Predicate_Check. To be
7307 and then (Variable_Ref
7308 or else Nkind_In
(Exp
, N_Attribute_Reference
,
7313 or else Nkind
(Exp
) in N_Op
7314 or else (not Name_Req
7315 and then Is_Volatile_Reference
(Exp
)))
7317 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7318 Set_Etype
(Def_Id
, Exp_Type
);
7319 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7321 -- If the expression is a packed reference, it must be reanalyzed and
7322 -- expanded, depending on context. This is the case for actuals where
7323 -- a constraint check may capture the actual before expansion of the
7324 -- call is complete.
7326 if Nkind
(Exp
) = N_Indexed_Component
7327 and then Is_Packed
(Etype
(Prefix
(Exp
)))
7329 Set_Analyzed
(Exp
, False);
7330 Set_Analyzed
(Prefix
(Exp
), False);
7334 -- Rnn : Exp_Type renames Expr;
7336 if Renaming_Req
then
7338 Make_Object_Renaming_Declaration
(Loc
,
7339 Defining_Identifier
=> Def_Id
,
7340 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7341 Name
=> Relocate_Node
(Exp
));
7344 -- Rnn : constant Exp_Type := Expr;
7348 Make_Object_Declaration
(Loc
,
7349 Defining_Identifier
=> Def_Id
,
7350 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7351 Constant_Present
=> True,
7352 Expression
=> Relocate_Node
(Exp
));
7354 Set_Assignment_OK
(E
);
7357 Insert_Action
(Exp
, E
);
7359 -- If the expression has the form v.all then we can just capture the
7360 -- pointer, and then do an explicit dereference on the result, but
7361 -- this is not right if this is a volatile reference.
7363 elsif Nkind
(Exp
) = N_Explicit_Dereference
7364 and then not Is_Volatile_Reference
(Exp
)
7366 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7368 Make_Explicit_Dereference
(Loc
, New_Occurrence_Of
(Def_Id
, Loc
));
7371 Make_Object_Declaration
(Loc
,
7372 Defining_Identifier
=> Def_Id
,
7373 Object_Definition
=>
7374 New_Occurrence_Of
(Etype
(Prefix
(Exp
)), Loc
),
7375 Constant_Present
=> True,
7376 Expression
=> Relocate_Node
(Prefix
(Exp
))));
7378 -- Similar processing for an unchecked conversion of an expression of
7379 -- the form v.all, where we want the same kind of treatment.
7381 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
7382 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
7384 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
7387 -- If this is a type conversion, leave the type conversion and remove
7388 -- the side effects in the expression. This is important in several
7389 -- circumstances: for change of representations, and also when this is a
7390 -- view conversion to a smaller object, where gigi can end up creating
7391 -- its own temporary of the wrong size.
7393 elsif Nkind
(Exp
) = N_Type_Conversion
then
7394 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
7397 -- If this is an unchecked conversion that Gigi can't handle, make
7398 -- a copy or a use a renaming to capture the value.
7400 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
7401 and then not Safe_Unchecked_Type_Conversion
(Exp
)
7403 if CW_Or_Has_Controlled_Part
(Exp_Type
) then
7405 -- Use a renaming to capture the expression, rather than create
7406 -- a controlled temporary.
7408 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7409 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7412 Make_Object_Renaming_Declaration
(Loc
,
7413 Defining_Identifier
=> Def_Id
,
7414 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7415 Name
=> Relocate_Node
(Exp
)));
7418 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7419 Set_Etype
(Def_Id
, Exp_Type
);
7420 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7423 Make_Object_Declaration
(Loc
,
7424 Defining_Identifier
=> Def_Id
,
7425 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7426 Constant_Present
=> not Is_Variable
(Exp
),
7427 Expression
=> Relocate_Node
(Exp
));
7429 Set_Assignment_OK
(E
);
7430 Insert_Action
(Exp
, E
);
7433 -- For expressions that denote objects, we can use a renaming scheme.
7434 -- This is needed for correctness in the case of a volatile object of
7435 -- a non-volatile type because the Make_Reference call of the "default"
7436 -- approach would generate an illegal access value (an access value
7437 -- cannot designate such an object - see Analyze_Reference).
7439 elsif Is_Object_Reference
(Exp
)
7440 and then Nkind
(Exp
) /= N_Function_Call
7442 -- In Ada 2012 a qualified expression is an object, but for purposes
7443 -- of removing side effects it still need to be transformed into a
7444 -- separate declaration, particularly in the case of an aggregate.
7446 and then Nkind
(Exp
) /= N_Qualified_Expression
7448 -- We skip using this scheme if we have an object of a volatile
7449 -- type and we do not have Name_Req set true (see comments for
7450 -- Side_Effect_Free).
7452 and then (Name_Req
or else not Treat_As_Volatile
(Exp_Type
))
7454 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7456 if Nkind
(Exp
) = N_Selected_Component
7457 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
7458 and then Is_Array_Type
(Exp_Type
)
7460 -- Avoid generating a variable-sized temporary, by generating
7461 -- the renaming declaration just for the function call. The
7462 -- transformation could be refined to apply only when the array
7463 -- component is constrained by a discriminant???
7466 Make_Selected_Component
(Loc
,
7467 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
7468 Selector_Name
=> Selector_Name
(Exp
));
7471 Make_Object_Renaming_Declaration
(Loc
,
7472 Defining_Identifier
=> Def_Id
,
7474 New_Occurrence_Of
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
7475 Name
=> Relocate_Node
(Prefix
(Exp
))));
7478 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7481 Make_Object_Renaming_Declaration
(Loc
,
7482 Defining_Identifier
=> Def_Id
,
7483 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7484 Name
=> Relocate_Node
(Exp
)));
7487 -- If this is a packed reference, or a selected component with
7488 -- a non-standard representation, a reference to the temporary
7489 -- will be replaced by a copy of the original expression (see
7490 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
7491 -- elaborated by gigi, and is of course not to be replaced in-line
7492 -- by the expression it renames, which would defeat the purpose of
7493 -- removing the side-effect.
7495 if Nkind_In
(Exp
, N_Selected_Component
, N_Indexed_Component
)
7496 and then Has_Non_Standard_Rep
(Etype
(Prefix
(Exp
)))
7500 Set_Is_Renaming_Of_Object
(Def_Id
, False);
7503 -- Otherwise we generate a reference to the value
7506 -- An expression which is in SPARK mode is considered side effect
7507 -- free if the resulting value is captured by a variable or a
7511 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
7516 -- Special processing for function calls that return a limited type.
7517 -- We need to build a declaration that will enable build-in-place
7518 -- expansion of the call. This is not done if the context is already
7519 -- an object declaration, to prevent infinite recursion.
7521 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
7522 -- to accommodate functions returning limited objects by reference.
7524 if Ada_Version
>= Ada_2005
7525 and then Nkind
(Exp
) = N_Function_Call
7526 and then Is_Limited_View
(Etype
(Exp
))
7527 and then Nkind
(Parent
(Exp
)) /= N_Object_Declaration
7530 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', Exp
);
7535 Make_Object_Declaration
(Loc
,
7536 Defining_Identifier
=> Obj
,
7537 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7538 Expression
=> Relocate_Node
(Exp
));
7540 Insert_Action
(Exp
, Decl
);
7541 Set_Etype
(Obj
, Exp_Type
);
7542 Rewrite
(Exp
, New_Occurrence_Of
(Obj
, Loc
));
7547 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7549 -- The regular expansion of functions with side effects involves the
7550 -- generation of an access type to capture the return value found on
7551 -- the secondary stack. Since SPARK (and why) cannot process access
7552 -- types, use a different approach which ignores the secondary stack
7553 -- and "copies" the returned object.
7555 if GNATprove_Mode
then
7556 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7557 Ref_Type
:= Exp_Type
;
7559 -- Regular expansion utilizing an access type and 'reference
7563 Make_Explicit_Dereference
(Loc
,
7564 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
));
7567 -- type Ann is access all <Exp_Type>;
7569 Ref_Type
:= Make_Temporary
(Loc
, 'A');
7572 Make_Full_Type_Declaration
(Loc
,
7573 Defining_Identifier
=> Ref_Type
,
7575 Make_Access_To_Object_Definition
(Loc
,
7576 All_Present
=> True,
7577 Subtype_Indication
=>
7578 New_Occurrence_Of
(Exp_Type
, Loc
)));
7580 Insert_Action
(Exp
, Ptr_Typ_Decl
);
7584 if Nkind
(E
) = N_Explicit_Dereference
then
7585 New_Exp
:= Relocate_Node
(Prefix
(E
));
7588 E
:= Relocate_Node
(E
);
7590 -- Do not generate a 'reference in SPARK mode since the access
7591 -- type is not created in the first place.
7593 if GNATprove_Mode
then
7596 -- Otherwise generate reference, marking the value as non-null
7597 -- since we know it cannot be null and we don't want a check.
7600 New_Exp
:= Make_Reference
(Loc
, E
);
7601 Set_Is_Known_Non_Null
(Def_Id
);
7605 if Is_Delayed_Aggregate
(E
) then
7607 -- The expansion of nested aggregates is delayed until the
7608 -- enclosing aggregate is expanded. As aggregates are often
7609 -- qualified, the predicate applies to qualified expressions as
7610 -- well, indicating that the enclosing aggregate has not been
7611 -- expanded yet. At this point the aggregate is part of a
7612 -- stand-alone declaration, and must be fully expanded.
7614 if Nkind
(E
) = N_Qualified_Expression
then
7615 Set_Expansion_Delayed
(Expression
(E
), False);
7616 Set_Analyzed
(Expression
(E
), False);
7618 Set_Expansion_Delayed
(E
, False);
7621 Set_Analyzed
(E
, False);
7625 Make_Object_Declaration
(Loc
,
7626 Defining_Identifier
=> Def_Id
,
7627 Object_Definition
=> New_Occurrence_Of
(Ref_Type
, Loc
),
7628 Constant_Present
=> True,
7629 Expression
=> New_Exp
));
7632 -- Preserve the Assignment_OK flag in all copies, since at least one
7633 -- copy may be used in a context where this flag must be set (otherwise
7634 -- why would the flag be set in the first place).
7636 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
7638 -- Finally rewrite the original expression and we are done
7641 Analyze_And_Resolve
(Exp
, Exp_Type
);
7644 Scope_Suppress
:= Svg_Suppress
;
7645 end Remove_Side_Effects
;
7647 ---------------------------
7648 -- Represented_As_Scalar --
7649 ---------------------------
7651 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean is
7652 UT
: constant Entity_Id
:= Underlying_Type
(T
);
7654 return Is_Scalar_Type
(UT
)
7655 or else (Is_Bit_Packed_Array
(UT
)
7656 and then Is_Scalar_Type
(Packed_Array_Impl_Type
(UT
)));
7657 end Represented_As_Scalar
;
7659 ------------------------------
7660 -- Requires_Cleanup_Actions --
7661 ------------------------------
7663 function Requires_Cleanup_Actions
7665 Lib_Level
: Boolean) return Boolean
7667 At_Lib_Level
: constant Boolean :=
7669 and then Nkind_In
(N
, N_Package_Body
,
7670 N_Package_Specification
);
7671 -- N is at the library level if the top-most context is a package and
7672 -- the path taken to reach N does not inlcude non-package constructs.
7676 when N_Accept_Statement |
7684 Requires_Cleanup_Actions
(Declarations
(N
), At_Lib_Level
, True)
7686 (Present
(Handled_Statement_Sequence
(N
))
7688 Requires_Cleanup_Actions
7689 (Statements
(Handled_Statement_Sequence
(N
)),
7690 At_Lib_Level
, True));
7692 when N_Package_Specification
=>
7694 Requires_Cleanup_Actions
7695 (Visible_Declarations
(N
), At_Lib_Level
, True)
7697 Requires_Cleanup_Actions
7698 (Private_Declarations
(N
), At_Lib_Level
, True);
7703 end Requires_Cleanup_Actions
;
7705 ------------------------------
7706 -- Requires_Cleanup_Actions --
7707 ------------------------------
7709 function Requires_Cleanup_Actions
7711 Lib_Level
: Boolean;
7712 Nested_Constructs
: Boolean) return Boolean
7717 Obj_Typ
: Entity_Id
;
7718 Pack_Id
: Entity_Id
;
7723 or else Is_Empty_List
(L
)
7729 while Present
(Decl
) loop
7731 -- Library-level tagged types
7733 if Nkind
(Decl
) = N_Full_Type_Declaration
then
7734 Typ
:= Defining_Identifier
(Decl
);
7736 if Is_Tagged_Type
(Typ
)
7737 and then Is_Library_Level_Entity
(Typ
)
7738 and then Convention
(Typ
) = Convention_Ada
7739 and then Present
(Access_Disp_Table
(Typ
))
7740 and then RTE_Available
(RE_Unregister_Tag
)
7741 and then not No_Run_Time_Mode
7742 and then not Is_Abstract_Type
(Typ
)
7747 -- Regular object declarations
7749 elsif Nkind
(Decl
) = N_Object_Declaration
then
7750 Obj_Id
:= Defining_Identifier
(Decl
);
7751 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7752 Expr
:= Expression
(Decl
);
7754 -- Bypass any form of processing for objects which have their
7755 -- finalization disabled. This applies only to objects at the
7758 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7761 -- Transient variables are treated separately in order to minimize
7762 -- the size of the generated code. See Exp_Ch7.Process_Transient_
7765 elsif Is_Processed_Transient
(Obj_Id
) then
7768 -- The object is of the form:
7769 -- Obj : Typ [:= Expr];
7771 -- Do not process the incomplete view of a deferred constant. Do
7772 -- not consider tag-to-class-wide conversions.
7774 elsif not Is_Imported
(Obj_Id
)
7775 and then Needs_Finalization
(Obj_Typ
)
7776 and then not (Ekind
(Obj_Id
) = E_Constant
7777 and then not Has_Completion
(Obj_Id
))
7778 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
7782 -- The object is of the form:
7783 -- Obj : Access_Typ := Non_BIP_Function_Call'reference;
7785 -- Obj : Access_Typ :=
7786 -- BIP_Function_Call (BIPalloc => 2, ...)'reference;
7788 elsif Is_Access_Type
(Obj_Typ
)
7789 and then Needs_Finalization
7790 (Available_View
(Designated_Type
(Obj_Typ
)))
7791 and then Present
(Expr
)
7793 (Is_Secondary_Stack_BIP_Func_Call
(Expr
)
7795 (Is_Non_BIP_Func_Call
(Expr
)
7796 and then not Is_Related_To_Func_Return
(Obj_Id
)))
7800 -- Processing for "hook" objects generated for controlled
7801 -- transients declared inside an Expression_With_Actions.
7803 elsif Is_Access_Type
(Obj_Typ
)
7804 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7805 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7806 N_Object_Declaration
7810 -- Processing for intermediate results of if expressions where
7811 -- one of the alternatives uses a controlled function call.
7813 elsif Is_Access_Type
(Obj_Typ
)
7814 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7815 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7816 N_Defining_Identifier
7817 and then Present
(Expr
)
7818 and then Nkind
(Expr
) = N_Null
7822 -- Simple protected objects which use type System.Tasking.
7823 -- Protected_Objects.Protection to manage their locks should be
7824 -- treated as controlled since they require manual cleanup.
7826 elsif Ekind
(Obj_Id
) = E_Variable
7827 and then (Is_Simple_Protected_Type
(Obj_Typ
)
7828 or else Has_Simple_Protected_Object
(Obj_Typ
))
7833 -- Specific cases of object renamings
7835 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
7836 Obj_Id
:= Defining_Identifier
(Decl
);
7837 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7839 -- Bypass any form of processing for objects which have their
7840 -- finalization disabled. This applies only to objects at the
7843 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7846 -- Return object of a build-in-place function. This case is
7847 -- recognized and marked by the expansion of an extended return
7848 -- statement (see Expand_N_Extended_Return_Statement).
7850 elsif Needs_Finalization
(Obj_Typ
)
7851 and then Is_Return_Object
(Obj_Id
)
7852 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7856 -- Detect a case where a source object has been initialized by
7857 -- a controlled function call or another object which was later
7858 -- rewritten as a class-wide conversion of Ada.Tags.Displace.
7860 -- Obj1 : CW_Type := Src_Obj;
7861 -- Obj2 : CW_Type := Function_Call (...);
7863 -- Obj1 : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
7864 -- Tmp : ... := Function_Call (...)'reference;
7865 -- Obj2 : CW_Type renames (... Ada.Tags.Displace (Tmp));
7867 elsif Is_Displacement_Of_Object_Or_Function_Result
(Obj_Id
) then
7871 -- Inspect the freeze node of an access-to-controlled type and look
7872 -- for a delayed finalization master. This case arises when the
7873 -- freeze actions are inserted at a later time than the expansion of
7874 -- the context. Since Build_Finalizer is never called on a single
7875 -- construct twice, the master will be ultimately left out and never
7876 -- finalized. This is also needed for freeze actions of designated
7877 -- types themselves, since in some cases the finalization master is
7878 -- associated with a designated type's freeze node rather than that
7879 -- of the access type (see handling for freeze actions in
7880 -- Build_Finalization_Master).
7882 elsif Nkind
(Decl
) = N_Freeze_Entity
7883 and then Present
(Actions
(Decl
))
7885 Typ
:= Entity
(Decl
);
7887 if ((Is_Access_Type
(Typ
)
7888 and then not Is_Access_Subprogram_Type
(Typ
)
7889 and then Needs_Finalization
7890 (Available_View
(Designated_Type
(Typ
))))
7891 or else (Is_Type
(Typ
) and then Needs_Finalization
(Typ
)))
7892 and then Requires_Cleanup_Actions
7893 (Actions
(Decl
), Lib_Level
, Nested_Constructs
)
7898 -- Nested package declarations
7900 elsif Nested_Constructs
7901 and then Nkind
(Decl
) = N_Package_Declaration
7903 Pack_Id
:= Defining_Unit_Name
(Specification
(Decl
));
7905 if Nkind
(Pack_Id
) = N_Defining_Program_Unit_Name
then
7906 Pack_Id
:= Defining_Identifier
(Pack_Id
);
7909 if Ekind
(Pack_Id
) /= E_Generic_Package
7911 Requires_Cleanup_Actions
(Specification
(Decl
), Lib_Level
)
7916 -- Nested package bodies
7918 elsif Nested_Constructs
and then Nkind
(Decl
) = N_Package_Body
then
7919 Pack_Id
:= Corresponding_Spec
(Decl
);
7921 if Ekind
(Pack_Id
) /= E_Generic_Package
7922 and then Requires_Cleanup_Actions
(Decl
, Lib_Level
)
7932 end Requires_Cleanup_Actions
;
7934 ------------------------------------
7935 -- Safe_Unchecked_Type_Conversion --
7936 ------------------------------------
7938 -- Note: this function knows quite a bit about the exact requirements of
7939 -- Gigi with respect to unchecked type conversions, and its code must be
7940 -- coordinated with any changes in Gigi in this area.
7942 -- The above requirements should be documented in Sinfo ???
7944 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
7949 Pexp
: constant Node_Id
:= Parent
(Exp
);
7952 -- If the expression is the RHS of an assignment or object declaration
7953 -- we are always OK because there will always be a target.
7955 -- Object renaming declarations, (generated for view conversions of
7956 -- actuals in inlined calls), like object declarations, provide an
7957 -- explicit type, and are safe as well.
7959 if (Nkind
(Pexp
) = N_Assignment_Statement
7960 and then Expression
(Pexp
) = Exp
)
7961 or else Nkind_In
(Pexp
, N_Object_Declaration
,
7962 N_Object_Renaming_Declaration
)
7966 -- If the expression is the prefix of an N_Selected_Component we should
7967 -- also be OK because GCC knows to look inside the conversion except if
7968 -- the type is discriminated. We assume that we are OK anyway if the
7969 -- type is not set yet or if it is controlled since we can't afford to
7970 -- introduce a temporary in this case.
7972 elsif Nkind
(Pexp
) = N_Selected_Component
7973 and then Prefix
(Pexp
) = Exp
7975 if No
(Etype
(Pexp
)) then
7979 not Has_Discriminants
(Etype
(Pexp
))
7980 or else Is_Constrained
(Etype
(Pexp
));
7984 -- Set the output type, this comes from Etype if it is set, otherwise we
7985 -- take it from the subtype mark, which we assume was already fully
7988 if Present
(Etype
(Exp
)) then
7989 Otyp
:= Etype
(Exp
);
7991 Otyp
:= Entity
(Subtype_Mark
(Exp
));
7994 -- The input type always comes from the expression, and we assume
7995 -- this is indeed always analyzed, so we can simply get the Etype.
7997 Ityp
:= Etype
(Expression
(Exp
));
7999 -- Initialize alignments to unknown so far
8004 -- Replace a concurrent type by its corresponding record type and each
8005 -- type by its underlying type and do the tests on those. The original
8006 -- type may be a private type whose completion is a concurrent type, so
8007 -- find the underlying type first.
8009 if Present
(Underlying_Type
(Otyp
)) then
8010 Otyp
:= Underlying_Type
(Otyp
);
8013 if Present
(Underlying_Type
(Ityp
)) then
8014 Ityp
:= Underlying_Type
(Ityp
);
8017 if Is_Concurrent_Type
(Otyp
) then
8018 Otyp
:= Corresponding_Record_Type
(Otyp
);
8021 if Is_Concurrent_Type
(Ityp
) then
8022 Ityp
:= Corresponding_Record_Type
(Ityp
);
8025 -- If the base types are the same, we know there is no problem since
8026 -- this conversion will be a noop.
8028 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
8031 -- Same if this is an upwards conversion of an untagged type, and there
8032 -- are no constraints involved (could be more general???)
8034 elsif Etype
(Ityp
) = Otyp
8035 and then not Is_Tagged_Type
(Ityp
)
8036 and then not Has_Discriminants
(Ityp
)
8037 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
8041 -- If the expression has an access type (object or subprogram) we assume
8042 -- that the conversion is safe, because the size of the target is safe,
8043 -- even if it is a record (which might be treated as having unknown size
8046 elsif Is_Access_Type
(Ityp
) then
8049 -- If the size of output type is known at compile time, there is never
8050 -- a problem. Note that unconstrained records are considered to be of
8051 -- known size, but we can't consider them that way here, because we are
8052 -- talking about the actual size of the object.
8054 -- We also make sure that in addition to the size being known, we do not
8055 -- have a case which might generate an embarrassingly large temp in
8056 -- stack checking mode.
8058 elsif Size_Known_At_Compile_Time
(Otyp
)
8060 (not Stack_Checking_Enabled
8061 or else not May_Generate_Large_Temp
(Otyp
))
8062 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
8066 -- If either type is tagged, then we know the alignment is OK so
8067 -- Gigi will be able to use pointer punning.
8069 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
8072 -- If either type is a limited record type, we cannot do a copy, so say
8073 -- safe since there's nothing else we can do.
8075 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
8078 -- Conversions to and from packed array types are always ignored and
8081 elsif Is_Packed_Array_Impl_Type
(Otyp
)
8082 or else Is_Packed_Array_Impl_Type
(Ityp
)
8087 -- The only other cases known to be safe is if the input type's
8088 -- alignment is known to be at least the maximum alignment for the
8089 -- target or if both alignments are known and the output type's
8090 -- alignment is no stricter than the input's. We can use the component
8091 -- type alignement for an array if a type is an unpacked array type.
8093 if Present
(Alignment_Clause
(Otyp
)) then
8094 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
8096 elsif Is_Array_Type
(Otyp
)
8097 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
8099 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
8100 (Component_Type
(Otyp
))));
8103 if Present
(Alignment_Clause
(Ityp
)) then
8104 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
8106 elsif Is_Array_Type
(Ityp
)
8107 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
8109 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
8110 (Component_Type
(Ityp
))));
8113 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
8116 elsif Ialign
/= No_Uint
8117 and then Oalign
/= No_Uint
8118 and then Ialign
<= Oalign
8122 -- Otherwise, Gigi cannot handle this and we must make a temporary
8127 end Safe_Unchecked_Type_Conversion
;
8129 ---------------------------------
8130 -- Set_Current_Value_Condition --
8131 ---------------------------------
8133 -- Note: the implementation of this procedure is very closely tied to the
8134 -- implementation of Get_Current_Value_Condition. Here we set required
8135 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
8136 -- them, so they must have a consistent view.
8138 procedure Set_Current_Value_Condition
(Cnode
: Node_Id
) is
8140 procedure Set_Entity_Current_Value
(N
: Node_Id
);
8141 -- If N is an entity reference, where the entity is of an appropriate
8142 -- kind, then set the current value of this entity to Cnode, unless
8143 -- there is already a definite value set there.
8145 procedure Set_Expression_Current_Value
(N
: Node_Id
);
8146 -- If N is of an appropriate form, sets an appropriate entry in current
8147 -- value fields of relevant entities. Multiple entities can be affected
8148 -- in the case of an AND or AND THEN.
8150 ------------------------------
8151 -- Set_Entity_Current_Value --
8152 ------------------------------
8154 procedure Set_Entity_Current_Value
(N
: Node_Id
) is
8156 if Is_Entity_Name
(N
) then
8158 Ent
: constant Entity_Id
:= Entity
(N
);
8161 -- Don't capture if not safe to do so
8163 if not Safe_To_Capture_Value
(N
, Ent
, Cond
=> True) then
8167 -- Here we have a case where the Current_Value field may need
8168 -- to be set. We set it if it is not already set to a compile
8169 -- time expression value.
8171 -- Note that this represents a decision that one condition
8172 -- blots out another previous one. That's certainly right if
8173 -- they occur at the same level. If the second one is nested,
8174 -- then the decision is neither right nor wrong (it would be
8175 -- equally OK to leave the outer one in place, or take the new
8176 -- inner one. Really we should record both, but our data
8177 -- structures are not that elaborate.
8179 if Nkind
(Current_Value
(Ent
)) not in N_Subexpr
then
8180 Set_Current_Value
(Ent
, Cnode
);
8184 end Set_Entity_Current_Value
;
8186 ----------------------------------
8187 -- Set_Expression_Current_Value --
8188 ----------------------------------
8190 procedure Set_Expression_Current_Value
(N
: Node_Id
) is
8196 -- Loop to deal with (ignore for now) any NOT operators present. The
8197 -- presence of NOT operators will be handled properly when we call
8198 -- Get_Current_Value_Condition.
8200 while Nkind
(Cond
) = N_Op_Not
loop
8201 Cond
:= Right_Opnd
(Cond
);
8204 -- For an AND or AND THEN, recursively process operands
8206 if Nkind
(Cond
) = N_Op_And
or else Nkind
(Cond
) = N_And_Then
then
8207 Set_Expression_Current_Value
(Left_Opnd
(Cond
));
8208 Set_Expression_Current_Value
(Right_Opnd
(Cond
));
8212 -- Check possible relational operator
8214 if Nkind
(Cond
) in N_Op_Compare
then
8215 if Compile_Time_Known_Value
(Right_Opnd
(Cond
)) then
8216 Set_Entity_Current_Value
(Left_Opnd
(Cond
));
8217 elsif Compile_Time_Known_Value
(Left_Opnd
(Cond
)) then
8218 Set_Entity_Current_Value
(Right_Opnd
(Cond
));
8221 elsif Nkind_In
(Cond
,
8223 N_Qualified_Expression
,
8224 N_Expression_With_Actions
)
8226 Set_Expression_Current_Value
(Expression
(Cond
));
8228 -- Check possible boolean variable reference
8231 Set_Entity_Current_Value
(Cond
);
8233 end Set_Expression_Current_Value
;
8235 -- Start of processing for Set_Current_Value_Condition
8238 Set_Expression_Current_Value
(Condition
(Cnode
));
8239 end Set_Current_Value_Condition
;
8241 --------------------------
8242 -- Set_Elaboration_Flag --
8243 --------------------------
8245 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
8246 Loc
: constant Source_Ptr
:= Sloc
(N
);
8247 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
8251 if Present
(Ent
) then
8253 -- Nothing to do if at the compilation unit level, because in this
8254 -- case the flag is set by the binder generated elaboration routine.
8256 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
8259 -- Here we do need to generate an assignment statement
8262 Check_Restriction
(No_Elaboration_Code
, N
);
8264 Make_Assignment_Statement
(Loc
,
8265 Name
=> New_Occurrence_Of
(Ent
, Loc
),
8266 Expression
=> Make_Integer_Literal
(Loc
, Uint_1
));
8268 if Nkind
(Parent
(N
)) = N_Subunit
then
8269 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
8271 Insert_After
(N
, Asn
);
8276 -- Kill current value indication. This is necessary because the
8277 -- tests of this flag are inserted out of sequence and must not
8278 -- pick up bogus indications of the wrong constant value.
8280 Set_Current_Value
(Ent
, Empty
);
8282 -- If the subprogram is in the current declarative part and
8283 -- 'access has been applied to it, generate an elaboration
8284 -- check at the beginning of the declarations of the body.
8286 if Nkind
(N
) = N_Subprogram_Body
8287 and then Address_Taken
(Spec_Id
)
8289 Ekind_In
(Scope
(Spec_Id
), E_Block
, E_Procedure
, E_Function
)
8292 Loc
: constant Source_Ptr
:= Sloc
(N
);
8293 Decls
: constant List_Id
:= Declarations
(N
);
8297 -- No need to generate this check if first entry in the
8298 -- declaration list is a raise of Program_Error now.
8301 and then Nkind
(First
(Decls
)) = N_Raise_Program_Error
8306 -- Otherwise generate the check
8309 Make_Raise_Program_Error
(Loc
,
8312 Left_Opnd
=> New_Occurrence_Of
(Ent
, Loc
),
8313 Right_Opnd
=> Make_Integer_Literal
(Loc
, Uint_0
)),
8314 Reason
=> PE_Access_Before_Elaboration
);
8317 Set_Declarations
(N
, New_List
(Chk
));
8319 Prepend
(Chk
, Decls
);
8327 end Set_Elaboration_Flag
;
8329 ----------------------------
8330 -- Set_Renamed_Subprogram --
8331 ----------------------------
8333 procedure Set_Renamed_Subprogram
(N
: Node_Id
; E
: Entity_Id
) is
8335 -- If input node is an identifier, we can just reset it
8337 if Nkind
(N
) = N_Identifier
then
8338 Set_Chars
(N
, Chars
(E
));
8341 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
8345 CS
: constant Boolean := Comes_From_Source
(N
);
8347 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
(E
)));
8349 Set_Comes_From_Source
(N
, CS
);
8350 Set_Analyzed
(N
, True);
8353 end Set_Renamed_Subprogram
;
8355 ----------------------
8356 -- Side_Effect_Free --
8357 ----------------------
8359 function Side_Effect_Free
8361 Name_Req
: Boolean := False;
8362 Variable_Ref
: Boolean := False) return Boolean
8364 Typ
: constant Entity_Id
:= Etype
(N
);
8365 -- Result type of the expression
8367 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
8368 -- The argument N is a construct where the Prefix is dereferenced if it
8369 -- is an access type and the result is a variable. The call returns True
8370 -- if the construct is side effect free (not considering side effects in
8371 -- other than the prefix which are to be tested by the caller).
8373 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
8374 -- Determines if N is a subcomponent of a composite in-parameter. If so,
8375 -- N is not side-effect free when the actual is global and modifiable
8376 -- indirectly from within a subprogram, because it may be passed by
8377 -- reference. The front-end must be conservative here and assume that
8378 -- this may happen with any array or record type. On the other hand, we
8379 -- cannot create temporaries for all expressions for which this
8380 -- condition is true, for various reasons that might require clearing up
8381 -- ??? For example, discriminant references that appear out of place, or
8382 -- spurious type errors with class-wide expressions. As a result, we
8383 -- limit the transformation to loop bounds, which is so far the only
8384 -- case that requires it.
8386 -----------------------------
8387 -- Safe_Prefixed_Reference --
8388 -----------------------------
8390 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
8392 -- If prefix is not side effect free, definitely not safe
8394 if not Side_Effect_Free
(Prefix
(N
), Name_Req
, Variable_Ref
) then
8397 -- If the prefix is of an access type that is not access-to-constant,
8398 -- then this construct is a variable reference, which means it is to
8399 -- be considered to have side effects if Variable_Ref is set True.
8401 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
8402 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
8403 and then Variable_Ref
8405 -- Exception is a prefix that is the result of a previous removal
8408 return Is_Entity_Name
(Prefix
(N
))
8409 and then not Comes_From_Source
(Prefix
(N
))
8410 and then Ekind
(Entity
(Prefix
(N
))) = E_Constant
8411 and then Is_Internal_Name
(Chars
(Entity
(Prefix
(N
))));
8413 -- If the prefix is an explicit dereference then this construct is a
8414 -- variable reference, which means it is to be considered to have
8415 -- side effects if Variable_Ref is True.
8417 -- We do NOT exclude dereferences of access-to-constant types because
8418 -- we handle them as constant view of variables.
8420 elsif Nkind
(Prefix
(N
)) = N_Explicit_Dereference
8421 and then Variable_Ref
8425 -- Note: The following test is the simplest way of solving a complex
8426 -- problem uncovered by the following test (Side effect on loop bound
8427 -- that is a subcomponent of a global variable:
8429 -- with Text_Io; use Text_Io;
8430 -- procedure Tloop is
8433 -- V : Natural := 4;
8434 -- S : String (1..5) := (others => 'a');
8441 -- with procedure Action;
8442 -- procedure Loop_G (Arg : X; Msg : String)
8444 -- procedure Loop_G (Arg : X; Msg : String) is
8446 -- Put_Line ("begin loop_g " & Msg & " will loop till: "
8447 -- & Natural'Image (Arg.V));
8448 -- for Index in 1 .. Arg.V loop
8450 -- (Natural'Image (Index) & " " & Arg.S (Index));
8451 -- if Index > 2 then
8455 -- Put_Line ("end loop_g " & Msg);
8458 -- procedure Loop1 is new Loop_G (Modi);
8459 -- procedure Modi is
8462 -- Loop1 (X1, "from modi");
8466 -- Loop1 (X1, "initial");
8469 -- The output of the above program should be:
8471 -- begin loop_g initial will loop till: 4
8475 -- begin loop_g from modi will loop till: 1
8477 -- end loop_g from modi
8479 -- begin loop_g from modi will loop till: 1
8481 -- end loop_g from modi
8482 -- end loop_g initial
8484 -- If a loop bound is a subcomponent of a global variable, a
8485 -- modification of that variable within the loop may incorrectly
8486 -- affect the execution of the loop.
8488 elsif Nkind
(Parent
(Parent
(N
))) = N_Loop_Parameter_Specification
8489 and then Within_In_Parameter
(Prefix
(N
))
8490 and then Variable_Ref
8494 -- All other cases are side effect free
8499 end Safe_Prefixed_Reference
;
8501 -------------------------
8502 -- Within_In_Parameter --
8503 -------------------------
8505 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
8507 if not Comes_From_Source
(N
) then
8510 elsif Is_Entity_Name
(N
) then
8511 return Ekind
(Entity
(N
)) = E_In_Parameter
;
8513 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
8514 return Within_In_Parameter
(Prefix
(N
));
8519 end Within_In_Parameter
;
8521 -- Start of processing for Side_Effect_Free
8524 -- If volatile reference, always consider it to have side effects
8526 if Is_Volatile_Reference
(N
) then
8530 -- Note on checks that could raise Constraint_Error. Strictly, if we
8531 -- take advantage of 11.6, these checks do not count as side effects.
8532 -- However, we would prefer to consider that they are side effects,
8533 -- since the backend CSE does not work very well on expressions which
8534 -- can raise Constraint_Error. On the other hand if we don't consider
8535 -- them to be side effect free, then we get some awkward expansions
8536 -- in -gnato mode, resulting in code insertions at a point where we
8537 -- do not have a clear model for performing the insertions.
8539 -- Special handling for entity names
8541 if Is_Entity_Name
(N
) then
8543 -- A type reference is always side effect free
8545 if Is_Type
(Entity
(N
)) then
8548 -- Variables are considered to be a side effect if Variable_Ref
8549 -- is set or if we have a volatile reference and Name_Req is off.
8550 -- If Name_Req is True then we can't help returning a name which
8551 -- effectively allows multiple references in any case.
8553 elsif Is_Variable
(N
, Use_Original_Node
=> False) then
8554 return not Variable_Ref
8555 and then (not Is_Volatile_Reference
(N
) or else Name_Req
);
8557 -- Any other entity (e.g. a subtype name) is definitely side
8564 -- A value known at compile time is always side effect free
8566 elsif Compile_Time_Known_Value
(N
) then
8569 -- A variable renaming is not side-effect free, because the renaming
8570 -- will function like a macro in the front-end in some cases, and an
8571 -- assignment can modify the component designated by N, so we need to
8572 -- create a temporary for it.
8574 -- The guard testing for Entity being present is needed at least in
8575 -- the case of rewritten predicate expressions, and may well also be
8576 -- appropriate elsewhere. Obviously we can't go testing the entity
8577 -- field if it does not exist, so it's reasonable to say that this is
8578 -- not the renaming case if it does not exist.
8580 elsif Is_Entity_Name
(Original_Node
(N
))
8581 and then Present
(Entity
(Original_Node
(N
)))
8582 and then Is_Renaming_Of_Object
(Entity
(Original_Node
(N
)))
8583 and then Ekind
(Entity
(Original_Node
(N
))) /= E_Constant
8586 RO
: constant Node_Id
:=
8587 Renamed_Object
(Entity
(Original_Node
(N
)));
8590 -- If the renamed object is an indexed component, or an
8591 -- explicit dereference, then the designated object could
8592 -- be modified by an assignment.
8594 if Nkind_In
(RO
, N_Indexed_Component
,
8595 N_Explicit_Dereference
)
8599 -- A selected component must have a safe prefix
8601 elsif Nkind
(RO
) = N_Selected_Component
then
8602 return Safe_Prefixed_Reference
(RO
);
8604 -- In all other cases, designated object cannot be changed so
8605 -- we are side effect free.
8612 -- Remove_Side_Effects generates an object renaming declaration to
8613 -- capture the expression of a class-wide expression. In VM targets
8614 -- the frontend performs no expansion for dispatching calls to
8615 -- class- wide types since they are handled by the VM. Hence, we must
8616 -- locate here if this node corresponds to a previous invocation of
8617 -- Remove_Side_Effects to avoid a never ending loop in the frontend.
8619 elsif VM_Target
/= No_VM
8620 and then not Comes_From_Source
(N
)
8621 and then Nkind
(Parent
(N
)) = N_Object_Renaming_Declaration
8622 and then Is_Class_Wide_Type
(Typ
)
8627 -- For other than entity names and compile time known values,
8628 -- check the node kind for special processing.
8632 -- An attribute reference is side effect free if its expressions
8633 -- are side effect free and its prefix is side effect free or
8634 -- is an entity reference.
8636 -- Is this right? what about x'first where x is a variable???
8638 when N_Attribute_Reference
=>
8639 return Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
)
8640 and then Attribute_Name
(N
) /= Name_Input
8641 and then (Is_Entity_Name
(Prefix
(N
))
8642 or else Side_Effect_Free
8643 (Prefix
(N
), Name_Req
, Variable_Ref
));
8645 -- A binary operator is side effect free if and both operands are
8646 -- side effect free. For this purpose binary operators include
8647 -- membership tests and short circuit forms.
8649 when N_Binary_Op | N_Membership_Test | N_Short_Circuit
=>
8650 return Side_Effect_Free
(Left_Opnd
(N
), Name_Req
, Variable_Ref
)
8652 Side_Effect_Free
(Right_Opnd
(N
), Name_Req
, Variable_Ref
);
8654 -- An explicit dereference is side effect free only if it is
8655 -- a side effect free prefixed reference.
8657 when N_Explicit_Dereference
=>
8658 return Safe_Prefixed_Reference
(N
);
8660 -- An expression with action is side effect free if its expression
8661 -- is side effect free and it has no actions.
8663 when N_Expression_With_Actions
=>
8664 return Is_Empty_List
(Actions
(N
))
8666 Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8668 -- A call to _rep_to_pos is side effect free, since we generate
8669 -- this pure function call ourselves. Moreover it is critically
8670 -- important to make this exception, since otherwise we can have
8671 -- discriminants in array components which don't look side effect
8672 -- free in the case of an array whose index type is an enumeration
8673 -- type with an enumeration rep clause.
8675 -- All other function calls are not side effect free
8677 when N_Function_Call
=>
8678 return Nkind
(Name
(N
)) = N_Identifier
8679 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
8682 (First
(Parameter_Associations
(N
)), Name_Req
, Variable_Ref
);
8684 -- An IF expression is side effect free if it's of a scalar type, and
8685 -- all its components are all side effect free (conditions and then
8686 -- actions and else actions). We restrict to scalar types, since it
8687 -- is annoying to deal with things like (if A then B else C)'First
8688 -- where the type involved is a string type.
8690 when N_If_Expression
=>
8691 return Is_Scalar_Type
(Typ
)
8693 Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
);
8695 -- An indexed component is side effect free if it is a side
8696 -- effect free prefixed reference and all the indexing
8697 -- expressions are side effect free.
8699 when N_Indexed_Component
=>
8700 return Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
)
8701 and then Safe_Prefixed_Reference
(N
);
8703 -- A type qualification is side effect free if the expression
8704 -- is side effect free.
8706 when N_Qualified_Expression
=>
8707 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8709 -- A selected component is side effect free only if it is a side
8710 -- effect free prefixed reference. If it designates a component
8711 -- with a rep. clause it must be treated has having a potential
8712 -- side effect, because it may be modified through a renaming, and
8713 -- a subsequent use of the renaming as a macro will yield the
8714 -- wrong value. This complex interaction between renaming and
8715 -- removing side effects is a reminder that the latter has become
8716 -- a headache to maintain, and that it should be removed in favor
8717 -- of the gcc mechanism to capture values ???
8719 when N_Selected_Component
=>
8720 if Nkind
(Parent
(N
)) = N_Explicit_Dereference
8721 and then Has_Non_Standard_Rep
(Designated_Type
(Typ
))
8725 return Safe_Prefixed_Reference
(N
);
8728 -- A range is side effect free if the bounds are side effect free
8731 return Side_Effect_Free
(Low_Bound
(N
), Name_Req
, Variable_Ref
)
8733 Side_Effect_Free
(High_Bound
(N
), Name_Req
, Variable_Ref
);
8735 -- A slice is side effect free if it is a side effect free
8736 -- prefixed reference and the bounds are side effect free.
8739 return Side_Effect_Free
8740 (Discrete_Range
(N
), Name_Req
, Variable_Ref
)
8741 and then Safe_Prefixed_Reference
(N
);
8743 -- A type conversion is side effect free if the expression to be
8744 -- converted is side effect free.
8746 when N_Type_Conversion
=>
8747 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8749 -- A unary operator is side effect free if the operand
8750 -- is side effect free.
8753 return Side_Effect_Free
(Right_Opnd
(N
), Name_Req
, Variable_Ref
);
8755 -- An unchecked type conversion is side effect free only if it
8756 -- is safe and its argument is side effect free.
8758 when N_Unchecked_Type_Conversion
=>
8759 return Safe_Unchecked_Type_Conversion
(N
)
8761 Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8763 -- An unchecked expression is side effect free if its expression
8764 -- is side effect free.
8766 when N_Unchecked_Expression
=>
8767 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8769 -- A literal is side effect free
8771 when N_Character_Literal |
8777 -- We consider that anything else has side effects. This is a bit
8778 -- crude, but we are pretty close for most common cases, and we
8779 -- are certainly correct (i.e. we never return True when the
8780 -- answer should be False).
8785 end Side_Effect_Free
;
8787 -- A list is side effect free if all elements of the list are side
8790 function Side_Effect_Free
8792 Name_Req
: Boolean := False;
8793 Variable_Ref
: Boolean := False) return Boolean
8798 if L
= No_List
or else L
= Error_List
then
8803 while Present
(N
) loop
8804 if not Side_Effect_Free
(N
, Name_Req
, Variable_Ref
) then
8813 end Side_Effect_Free
;
8815 ----------------------------------
8816 -- Silly_Boolean_Array_Not_Test --
8817 ----------------------------------
8819 -- This procedure implements an odd and silly test. We explicitly check
8820 -- for the case where the 'First of the component type is equal to the
8821 -- 'Last of this component type, and if this is the case, we make sure
8822 -- that constraint error is raised. The reason is that the NOT is bound
8823 -- to cause CE in this case, and we will not otherwise catch it.
8825 -- No such check is required for AND and OR, since for both these cases
8826 -- False op False = False, and True op True = True. For the XOR case,
8827 -- see Silly_Boolean_Array_Xor_Test.
8829 -- Believe it or not, this was reported as a bug. Note that nearly always,
8830 -- the test will evaluate statically to False, so the code will be
8831 -- statically removed, and no extra overhead caused.
8833 procedure Silly_Boolean_Array_Not_Test
(N
: Node_Id
; T
: Entity_Id
) is
8834 Loc
: constant Source_Ptr
:= Sloc
(N
);
8835 CT
: constant Entity_Id
:= Component_Type
(T
);
8838 -- The check we install is
8840 -- constraint_error when
8841 -- component_type'first = component_type'last
8842 -- and then array_type'Length /= 0)
8844 -- We need the last guard because we don't want to raise CE for empty
8845 -- arrays since no out of range values result. (Empty arrays with a
8846 -- component type of True .. True -- very useful -- even the ACATS
8847 -- does not test that marginal case).
8850 Make_Raise_Constraint_Error
(Loc
,
8856 Make_Attribute_Reference
(Loc
,
8857 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
8858 Attribute_Name
=> Name_First
),
8861 Make_Attribute_Reference
(Loc
,
8862 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
8863 Attribute_Name
=> Name_Last
)),
8865 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
8866 Reason
=> CE_Range_Check_Failed
));
8867 end Silly_Boolean_Array_Not_Test
;
8869 ----------------------------------
8870 -- Silly_Boolean_Array_Xor_Test --
8871 ----------------------------------
8873 -- This procedure implements an odd and silly test. We explicitly check
8874 -- for the XOR case where the component type is True .. True, since this
8875 -- will raise constraint error. A special check is required since CE
8876 -- will not be generated otherwise (cf Expand_Packed_Not).
8878 -- No such check is required for AND and OR, since for both these cases
8879 -- False op False = False, and True op True = True, and no check is
8880 -- required for the case of False .. False, since False xor False = False.
8881 -- See also Silly_Boolean_Array_Not_Test
8883 procedure Silly_Boolean_Array_Xor_Test
(N
: Node_Id
; T
: Entity_Id
) is
8884 Loc
: constant Source_Ptr
:= Sloc
(N
);
8885 CT
: constant Entity_Id
:= Component_Type
(T
);
8888 -- The check we install is
8890 -- constraint_error when
8891 -- Boolean (component_type'First)
8892 -- and then Boolean (component_type'Last)
8893 -- and then array_type'Length /= 0)
8895 -- We need the last guard because we don't want to raise CE for empty
8896 -- arrays since no out of range values result (Empty arrays with a
8897 -- component type of True .. True -- very useful -- even the ACATS
8898 -- does not test that marginal case).
8901 Make_Raise_Constraint_Error
(Loc
,
8907 Convert_To
(Standard_Boolean
,
8908 Make_Attribute_Reference
(Loc
,
8909 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
8910 Attribute_Name
=> Name_First
)),
8913 Convert_To
(Standard_Boolean
,
8914 Make_Attribute_Reference
(Loc
,
8915 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
8916 Attribute_Name
=> Name_Last
))),
8918 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
8919 Reason
=> CE_Range_Check_Failed
));
8920 end Silly_Boolean_Array_Xor_Test
;
8922 --------------------------
8923 -- Target_Has_Fixed_Ops --
8924 --------------------------
8926 Integer_Sized_Small
: Ureal
;
8927 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
8928 -- called (we don't want to compute it more than once).
8930 Long_Integer_Sized_Small
: Ureal
;
8931 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
8932 -- is called (we don't want to compute it more than once)
8934 First_Time_For_THFO
: Boolean := True;
8935 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
8937 function Target_Has_Fixed_Ops
8938 (Left_Typ
: Entity_Id
;
8939 Right_Typ
: Entity_Id
;
8940 Result_Typ
: Entity_Id
) return Boolean
8942 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
8943 -- Return True if the given type is a fixed-point type with a small
8944 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
8945 -- an absolute value less than 1.0. This is currently limited to
8946 -- fixed-point types that map to Integer or Long_Integer.
8948 ------------------------
8949 -- Is_Fractional_Type --
8950 ------------------------
8952 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
8954 if Esize
(Typ
) = Standard_Integer_Size
then
8955 return Small_Value
(Typ
) = Integer_Sized_Small
;
8957 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
8958 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
8963 end Is_Fractional_Type
;
8965 -- Start of processing for Target_Has_Fixed_Ops
8968 -- Return False if Fractional_Fixed_Ops_On_Target is false
8970 if not Fractional_Fixed_Ops_On_Target
then
8974 -- Here the target has Fractional_Fixed_Ops, if first time, compute
8975 -- standard constants used by Is_Fractional_Type.
8977 if First_Time_For_THFO
then
8978 First_Time_For_THFO
:= False;
8980 Integer_Sized_Small
:=
8983 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
8986 Long_Integer_Sized_Small
:=
8989 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
8993 -- Return True if target supports fixed-by-fixed multiply/divide for
8994 -- fractional fixed-point types (see Is_Fractional_Type) and the operand
8995 -- and result types are equivalent fractional types.
8997 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
8998 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
8999 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
9000 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
9001 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
9002 end Target_Has_Fixed_Ops
;
9004 ------------------------------------------
9005 -- Type_May_Have_Bit_Aligned_Components --
9006 ------------------------------------------
9008 function Type_May_Have_Bit_Aligned_Components
9009 (Typ
: Entity_Id
) return Boolean
9012 -- Array type, check component type
9014 if Is_Array_Type
(Typ
) then
9016 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
9018 -- Record type, check components
9020 elsif Is_Record_Type
(Typ
) then
9025 E
:= First_Component_Or_Discriminant
(Typ
);
9026 while Present
(E
) loop
9027 if Component_May_Be_Bit_Aligned
(E
)
9028 or else Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
9033 Next_Component_Or_Discriminant
(E
);
9039 -- Type other than array or record is always OK
9044 end Type_May_Have_Bit_Aligned_Components
;
9046 ----------------------------------
9047 -- Within_Case_Or_If_Expression --
9048 ----------------------------------
9050 function Within_Case_Or_If_Expression
(N
: Node_Id
) return Boolean is
9054 -- Locate an enclosing case or if expression. Note that these constructs
9055 -- can be expanded into Expression_With_Actions, hence the test of the
9059 while Present
(Par
) loop
9060 if Nkind_In
(Original_Node
(Par
), N_Case_Expression
,
9065 -- Prevent the search from going too far
9067 elsif Is_Body_Or_Package_Declaration
(Par
) then
9071 Par
:= Parent
(Par
);
9075 end Within_Case_Or_If_Expression
;
9077 --------------------------------
9078 -- Within_Internal_Subprogram --
9079 --------------------------------
9081 function Within_Internal_Subprogram
return Boolean is
9086 while Present
(S
) and then not Is_Subprogram
(S
) loop
9091 and then Get_TSS_Name
(S
) /= TSS_Null
9092 and then not Is_Predicate_Function
(S
);
9093 end Within_Internal_Subprogram
;
9095 ----------------------------
9096 -- Wrap_Cleanup_Procedure --
9097 ----------------------------
9099 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
9100 Loc
: constant Source_Ptr
:= Sloc
(N
);
9101 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
9102 Stmts
: constant List_Id
:= Statements
(Stseq
);
9104 if Abort_Allowed
then
9105 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
9106 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
9108 end Wrap_Cleanup_Procedure
;