1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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_Object
(E
: Node_Id
) return Node_Id
;
416 -- Given an arbitrary expression of an allocator, try to find an object
417 -- reference in it, otherwise return the original expression.
419 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean;
420 -- Determine whether subprogram Subp denotes a custom allocate or
427 function Find_Object
(E
: Node_Id
) return Node_Id
is
431 pragma Assert
(Is_Allocate
);
435 if Nkind
(Expr
) = N_Explicit_Dereference
then
436 Expr
:= Prefix
(Expr
);
438 elsif Nkind
(Expr
) = N_Qualified_Expression
then
439 Expr
:= Expression
(Expr
);
441 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
443 -- When interface class-wide types are involved in allocation,
444 -- the expander introduces several levels of address arithmetic
445 -- to perform dispatch table displacement. In this scenario the
446 -- object appears as:
448 -- Tag_Ptr (Base_Address (<object>'Address))
450 -- Detect this case and utilize the whole expression as the
451 -- "object" since it now points to the proper dispatch table.
453 if Is_RTE
(Etype
(Expr
), RE_Tag_Ptr
) then
456 -- Continue to strip the object
459 Expr
:= Expression
(Expr
);
470 ---------------------------------
471 -- Is_Allocate_Deallocate_Proc --
472 ---------------------------------
474 function Is_Allocate_Deallocate_Proc
(Subp
: Entity_Id
) return Boolean is
476 -- Look for a subprogram body with only one statement which is a
477 -- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
479 if Ekind
(Subp
) = E_Procedure
480 and then Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Body
483 HSS
: constant Node_Id
:=
484 Handled_Statement_Sequence
(Parent
(Parent
(Subp
)));
488 if Present
(Statements
(HSS
))
489 and then Nkind
(First
(Statements
(HSS
))) =
490 N_Procedure_Call_Statement
492 Proc
:= Entity
(Name
(First
(Statements
(HSS
))));
495 Is_RTE
(Proc
, RE_Allocate_Any_Controlled
)
496 or else Is_RTE
(Proc
, RE_Deallocate_Any_Controlled
);
502 end Is_Allocate_Deallocate_Proc
;
504 -- Start of processing for Build_Allocate_Deallocate_Proc
507 -- Obtain the attributes of the allocation / deallocation
509 if Nkind
(N
) = N_Free_Statement
then
510 Expr
:= Expression
(N
);
511 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
512 Proc_To_Call
:= Procedure_To_Call
(N
);
515 if Nkind
(N
) = N_Object_Declaration
then
516 Expr
:= Expression
(N
);
521 -- In certain cases an allocator with a qualified expression may
522 -- be relocated and used as the initialization expression of a
526 -- Obj : Ptr_Typ := new Desig_Typ'(...);
529 -- Tmp : Ptr_Typ := new Desig_Typ'(...);
530 -- Obj : Ptr_Typ := Tmp;
532 -- Since the allocator is always marked as analyzed to avoid infinite
533 -- expansion, it will never be processed by this routine given that
534 -- the designated type needs finalization actions. Detect this case
535 -- and complete the expansion of the allocator.
537 if Nkind
(Expr
) = N_Identifier
538 and then Nkind
(Parent
(Entity
(Expr
))) = N_Object_Declaration
539 and then Nkind
(Expression
(Parent
(Entity
(Expr
)))) = N_Allocator
541 Build_Allocate_Deallocate_Proc
(Parent
(Entity
(Expr
)), True);
545 -- The allocator may have been rewritten into something else in which
546 -- case the expansion performed by this routine does not apply.
548 if Nkind
(Expr
) /= N_Allocator
then
552 Ptr_Typ
:= Base_Type
(Etype
(Expr
));
553 Proc_To_Call
:= Procedure_To_Call
(Expr
);
556 Pool_Id
:= Associated_Storage_Pool
(Ptr_Typ
);
557 Desig_Typ
:= Available_View
(Designated_Type
(Ptr_Typ
));
559 -- Handle concurrent types
561 if Is_Concurrent_Type
(Desig_Typ
)
562 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
564 Desig_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
567 -- Do not process allocations / deallocations without a pool
572 -- Do not process allocations on / deallocations from the secondary
575 elsif Is_RTE
(Pool_Id
, RE_SS_Pool
) then
578 -- Do not replicate the machinery if the allocator / free has already
579 -- been expanded and has a custom Allocate / Deallocate.
581 elsif Present
(Proc_To_Call
)
582 and then Is_Allocate_Deallocate_Proc
(Proc_To_Call
)
587 if Needs_Finalization
(Desig_Typ
) then
589 -- Certain run-time configurations and targets do not provide support
590 -- for controlled types.
592 if Restriction_Active
(No_Finalization
) then
595 -- Do nothing if the access type may never allocate / deallocate
598 elsif No_Pool_Assigned
(Ptr_Typ
) then
601 -- Access-to-controlled types are not supported on .NET/JVM since
602 -- these targets cannot support pools and address arithmetic.
604 elsif VM_Target
/= No_VM
then
608 -- The allocation / deallocation of a controlled object must be
609 -- chained on / detached from a finalization master.
611 pragma Assert
(Present
(Finalization_Master
(Ptr_Typ
)));
613 -- The only other kind of allocation / deallocation supported by this
614 -- routine is on / from a subpool.
616 elsif Nkind
(Expr
) = N_Allocator
617 and then No
(Subpool_Handle_Name
(Expr
))
623 Loc
: constant Source_Ptr
:= Sloc
(N
);
624 Addr_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
625 Alig_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
626 Proc_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
627 Size_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
630 Fin_Addr_Id
: Entity_Id
;
631 Fin_Mas_Act
: Node_Id
;
632 Fin_Mas_Id
: Entity_Id
;
633 Proc_To_Call
: Entity_Id
;
634 Subpool
: Node_Id
:= Empty
;
637 -- Step 1: Construct all the actuals for the call to library routine
638 -- Allocate_Any_Controlled / Deallocate_Any_Controlled.
642 Actuals
:= New_List
(New_Occurrence_Of
(Pool_Id
, Loc
));
648 if Nkind
(Expr
) = N_Allocator
then
649 Subpool
:= Subpool_Handle_Name
(Expr
);
652 -- If a subpool is present it can be an arbitrary name, so make
653 -- the actual by copying the tree.
655 if Present
(Subpool
) then
656 Append_To
(Actuals
, New_Copy_Tree
(Subpool
, New_Sloc
=> Loc
));
658 Append_To
(Actuals
, Make_Null
(Loc
));
661 -- c) Finalization master
663 if Needs_Finalization
(Desig_Typ
) then
664 Fin_Mas_Id
:= Finalization_Master
(Ptr_Typ
);
665 Fin_Mas_Act
:= New_Occurrence_Of
(Fin_Mas_Id
, Loc
);
667 -- Handle the case where the master is actually a pointer to a
668 -- master. This case arises in build-in-place functions.
670 if Is_Access_Type
(Etype
(Fin_Mas_Id
)) then
671 Append_To
(Actuals
, Fin_Mas_Act
);
674 Make_Attribute_Reference
(Loc
,
675 Prefix
=> Fin_Mas_Act
,
676 Attribute_Name
=> Name_Unrestricted_Access
));
679 Append_To
(Actuals
, Make_Null
(Loc
));
682 -- d) Finalize_Address
684 -- Primitive Finalize_Address is never generated in CodePeer mode
685 -- since it contains an Unchecked_Conversion.
687 if Needs_Finalization
(Desig_Typ
) and then not CodePeer_Mode
then
688 Fin_Addr_Id
:= Finalize_Address
(Desig_Typ
);
689 pragma Assert
(Present
(Fin_Addr_Id
));
692 Make_Attribute_Reference
(Loc
,
693 Prefix
=> New_Occurrence_Of
(Fin_Addr_Id
, Loc
),
694 Attribute_Name
=> Name_Unrestricted_Access
));
696 Append_To
(Actuals
, Make_Null
(Loc
));
704 Append_To
(Actuals
, New_Occurrence_Of
(Addr_Id
, Loc
));
705 Append_To
(Actuals
, New_Occurrence_Of
(Size_Id
, Loc
));
707 if Is_Allocate
or else not Is_Class_Wide_Type
(Desig_Typ
) then
708 Append_To
(Actuals
, New_Occurrence_Of
(Alig_Id
, Loc
));
710 -- For deallocation of class-wide types we obtain the value of
711 -- alignment from the Type Specific Record of the deallocated object.
712 -- This is needed because the frontend expansion of class-wide types
713 -- into equivalent types confuses the backend.
719 -- ... because 'Alignment applied to class-wide types is expanded
720 -- into the code that reads the value of alignment from the TSD
721 -- (see Expand_N_Attribute_Reference)
724 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
725 Make_Attribute_Reference
(Loc
,
727 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Expr
)),
728 Attribute_Name
=> Name_Alignment
)));
733 if Needs_Finalization
(Desig_Typ
) then
735 Flag_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F');
742 Temp
:= Find_Object
(Expression
(Expr
));
747 -- Processing for allocations where the expression is a subtype
751 and then Is_Entity_Name
(Temp
)
752 and then Is_Type
(Entity
(Temp
))
757 (Needs_Finalization
(Entity
(Temp
))), Loc
);
759 -- The allocation / deallocation of a class-wide object relies
760 -- on a runtime check to determine whether the object is truly
761 -- controlled or not. Depending on this check, the finalization
762 -- machinery will request or reclaim extra storage reserved for
765 elsif Is_Class_Wide_Type
(Desig_Typ
) then
767 -- Detect a special case where interface class-wide types
768 -- are involved as the object appears as:
770 -- Tag_Ptr (Base_Address (<object>'Address))
772 -- The expression already yields the proper tag, generate:
776 if Is_RTE
(Etype
(Temp
), RE_Tag_Ptr
) then
778 Make_Explicit_Dereference
(Loc
,
779 Prefix
=> Relocate_Node
(Temp
));
781 -- In the default case, obtain the tag of the object about
782 -- to be allocated / deallocated. Generate:
788 Make_Attribute_Reference
(Loc
,
789 Prefix
=> Relocate_Node
(Temp
),
790 Attribute_Name
=> Name_Tag
);
794 -- Needs_Finalization (<Param>)
797 Make_Function_Call
(Loc
,
799 New_Occurrence_Of
(RTE
(RE_Needs_Finalization
), Loc
),
800 Parameter_Associations
=> New_List
(Param
));
802 -- Processing for generic actuals
804 elsif Is_Generic_Actual_Type
(Desig_Typ
) then
806 New_Occurrence_Of
(Boolean_Literals
807 (Needs_Finalization
(Base_Type
(Desig_Typ
))), Loc
);
809 -- The object does not require any specialized checks, it is
810 -- known to be controlled.
813 Flag_Expr
:= New_Occurrence_Of
(Standard_True
, Loc
);
816 -- Create the temporary which represents the finalization state
817 -- of the expression. Generate:
819 -- F : constant Boolean := <Flag_Expr>;
822 Make_Object_Declaration
(Loc
,
823 Defining_Identifier
=> Flag_Id
,
824 Constant_Present
=> True,
826 New_Occurrence_Of
(Standard_Boolean
, Loc
),
827 Expression
=> Flag_Expr
));
829 Append_To
(Actuals
, New_Occurrence_Of
(Flag_Id
, Loc
));
832 -- The object is not controlled
835 Append_To
(Actuals
, New_Occurrence_Of
(Standard_False
, Loc
));
842 New_Occurrence_Of
(Boolean_Literals
(Present
(Subpool
)), Loc
));
845 -- Step 2: Build a wrapper Allocate / Deallocate which internally
846 -- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
848 -- Select the proper routine to call
851 Proc_To_Call
:= RTE
(RE_Allocate_Any_Controlled
);
853 Proc_To_Call
:= RTE
(RE_Deallocate_Any_Controlled
);
856 -- Create a custom Allocate / Deallocate routine which has identical
857 -- profile to that of System.Storage_Pools.
860 Make_Subprogram_Body
(Loc
,
865 Make_Procedure_Specification
(Loc
,
866 Defining_Unit_Name
=> Proc_Id
,
867 Parameter_Specifications
=> New_List
(
869 -- P : Root_Storage_Pool
871 Make_Parameter_Specification
(Loc
,
872 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
874 New_Occurrence_Of
(RTE
(RE_Root_Storage_Pool
), Loc
)),
878 Make_Parameter_Specification
(Loc
,
879 Defining_Identifier
=> Addr_Id
,
880 Out_Present
=> Is_Allocate
,
882 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
886 Make_Parameter_Specification
(Loc
,
887 Defining_Identifier
=> Size_Id
,
889 New_Occurrence_Of
(RTE
(RE_Storage_Count
), Loc
)),
893 Make_Parameter_Specification
(Loc
,
894 Defining_Identifier
=> Alig_Id
,
896 New_Occurrence_Of
(RTE
(RE_Storage_Count
), Loc
)))),
898 Declarations
=> No_List
,
900 Handled_Statement_Sequence
=>
901 Make_Handled_Sequence_Of_Statements
(Loc
,
902 Statements
=> New_List
(
903 Make_Procedure_Call_Statement
(Loc
,
904 Name
=> New_Occurrence_Of
(Proc_To_Call
, Loc
),
905 Parameter_Associations
=> Actuals
)))));
907 -- The newly generated Allocate / Deallocate becomes the default
908 -- procedure to call when the back end processes the allocation /
912 Set_Procedure_To_Call
(Expr
, Proc_Id
);
914 Set_Procedure_To_Call
(N
, Proc_Id
);
917 end Build_Allocate_Deallocate_Proc
;
919 ------------------------
920 -- Build_Runtime_Call --
921 ------------------------
923 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
is
925 -- If entity is not available, we can skip making the call (this avoids
926 -- junk duplicated error messages in a number of cases).
928 if not RTE_Available
(RE
) then
929 return Make_Null_Statement
(Loc
);
932 Make_Procedure_Call_Statement
(Loc
,
933 Name
=> New_Occurrence_Of
(RTE
(RE
), Loc
));
935 end Build_Runtime_Call
;
937 ------------------------
938 -- Build_SS_Mark_Call --
939 ------------------------
941 function Build_SS_Mark_Call
943 Mark
: Entity_Id
) return Node_Id
947 -- Mark : constant Mark_Id := SS_Mark;
950 Make_Object_Declaration
(Loc
,
951 Defining_Identifier
=> Mark
,
952 Constant_Present
=> True,
954 New_Occurrence_Of
(RTE
(RE_Mark_Id
), Loc
),
956 Make_Function_Call
(Loc
,
957 Name
=> New_Occurrence_Of
(RTE
(RE_SS_Mark
), Loc
)));
958 end Build_SS_Mark_Call
;
960 ---------------------------
961 -- Build_SS_Release_Call --
962 ---------------------------
964 function Build_SS_Release_Call
966 Mark
: Entity_Id
) return Node_Id
970 -- SS_Release (Mark);
973 Make_Procedure_Call_Statement
(Loc
,
975 New_Occurrence_Of
(RTE
(RE_SS_Release
), Loc
),
976 Parameter_Associations
=> New_List
(
977 New_Occurrence_Of
(Mark
, Loc
)));
978 end Build_SS_Release_Call
;
980 ----------------------------
981 -- Build_Task_Array_Image --
982 ----------------------------
984 -- This function generates the body for a function that constructs the
985 -- image string for a task that is an array component. The function is
986 -- local to the init proc for the array type, and is called for each one
987 -- of the components. The constructed image has the form of an indexed
988 -- component, whose prefix is the outer variable of the array type.
989 -- The n-dimensional array type has known indexes Index, Index2...
991 -- Id_Ref is an indexed component form created by the enclosing init proc.
992 -- Its successive indexes are Val1, Val2, ... which are the loop variables
993 -- in the loops that call the individual task init proc on each component.
995 -- The generated function has the following structure:
997 -- function F return String is
998 -- Pref : string renames Task_Name;
999 -- T1 : String := Index1'Image (Val1);
1001 -- Tn : String := indexn'image (Valn);
1002 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
1003 -- -- Len includes commas and the end parentheses.
1004 -- Res : String (1..Len);
1005 -- Pos : Integer := Pref'Length;
1008 -- Res (1 .. Pos) := Pref;
1010 -- Res (Pos) := '(';
1012 -- Res (Pos .. Pos + T1'Length - 1) := T1;
1013 -- Pos := Pos + T1'Length;
1014 -- Res (Pos) := '.';
1017 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
1018 -- Res (Len) := ')';
1023 -- Needless to say, multidimensional arrays of tasks are rare enough that
1024 -- the bulkiness of this code is not really a concern.
1026 function Build_Task_Array_Image
1030 Dyn
: Boolean := False) return Node_Id
1032 Dims
: constant Nat
:= Number_Dimensions
(A_Type
);
1033 -- Number of dimensions for array of tasks
1035 Temps
: array (1 .. Dims
) of Entity_Id
;
1036 -- Array of temporaries to hold string for each index
1042 -- Total length of generated name
1045 -- Running index for substring assignments
1047 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1048 -- Name of enclosing variable, prefix of resulting name
1051 -- String to hold result
1054 -- Value of successive indexes
1057 -- Expression to compute total size of string
1060 -- Entity for name at one index position
1062 Decls
: constant List_Id
:= New_List
;
1063 Stats
: constant List_Id
:= New_List
;
1066 -- For a dynamic task, the name comes from the target variable. For a
1067 -- static one it is a formal of the enclosing init proc.
1070 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1072 Make_Object_Declaration
(Loc
,
1073 Defining_Identifier
=> Pref
,
1074 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1076 Make_String_Literal
(Loc
,
1077 Strval
=> String_From_Name_Buffer
)));
1081 Make_Object_Renaming_Declaration
(Loc
,
1082 Defining_Identifier
=> Pref
,
1083 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1084 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1087 Indx
:= First_Index
(A_Type
);
1088 Val
:= First
(Expressions
(Id_Ref
));
1090 for J
in 1 .. Dims
loop
1091 T
:= Make_Temporary
(Loc
, 'T');
1095 Make_Object_Declaration
(Loc
,
1096 Defining_Identifier
=> T
,
1097 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1099 Make_Attribute_Reference
(Loc
,
1100 Attribute_Name
=> Name_Image
,
1101 Prefix
=> New_Occurrence_Of
(Etype
(Indx
), Loc
),
1102 Expressions
=> New_List
(New_Copy_Tree
(Val
)))));
1108 Sum
:= Make_Integer_Literal
(Loc
, Dims
+ 1);
1114 Make_Attribute_Reference
(Loc
,
1115 Attribute_Name
=> Name_Length
,
1116 Prefix
=> New_Occurrence_Of
(Pref
, Loc
),
1117 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1119 for J
in 1 .. Dims
loop
1124 Make_Attribute_Reference
(Loc
,
1125 Attribute_Name
=> Name_Length
,
1127 New_Occurrence_Of
(Temps
(J
), Loc
),
1128 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1131 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1133 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('(')));
1136 Make_Assignment_Statement
(Loc
,
1138 Make_Indexed_Component
(Loc
,
1139 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1140 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1142 Make_Character_Literal
(Loc
,
1144 Char_Literal_Value
=> UI_From_Int
(Character'Pos ('(')))));
1147 Make_Assignment_Statement
(Loc
,
1148 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1151 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1152 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1154 for J
in 1 .. Dims
loop
1157 Make_Assignment_Statement
(Loc
,
1160 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1163 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1165 Make_Op_Subtract
(Loc
,
1168 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1170 Make_Attribute_Reference
(Loc
,
1171 Attribute_Name
=> Name_Length
,
1173 New_Occurrence_Of
(Temps
(J
), Loc
),
1175 New_List
(Make_Integer_Literal
(Loc
, 1)))),
1176 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))),
1178 Expression
=> New_Occurrence_Of
(Temps
(J
), Loc
)));
1182 Make_Assignment_Statement
(Loc
,
1183 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1186 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1188 Make_Attribute_Reference
(Loc
,
1189 Attribute_Name
=> Name_Length
,
1190 Prefix
=> New_Occurrence_Of
(Temps
(J
), Loc
),
1192 New_List
(Make_Integer_Literal
(Loc
, 1))))));
1194 Set_Character_Literal_Name
(Char_Code
(Character'Pos (',')));
1197 Make_Assignment_Statement
(Loc
,
1198 Name
=> Make_Indexed_Component
(Loc
,
1199 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1200 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1202 Make_Character_Literal
(Loc
,
1204 Char_Literal_Value
=> UI_From_Int
(Character'Pos (',')))));
1207 Make_Assignment_Statement
(Loc
,
1208 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1211 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1212 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1216 Set_Character_Literal_Name
(Char_Code
(Character'Pos (')')));
1219 Make_Assignment_Statement
(Loc
,
1221 Make_Indexed_Component
(Loc
,
1222 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1223 Expressions
=> New_List
(New_Occurrence_Of
(Len
, Loc
))),
1225 Make_Character_Literal
(Loc
,
1227 Char_Literal_Value
=> UI_From_Int
(Character'Pos (')')))));
1228 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1229 end Build_Task_Array_Image
;
1231 ----------------------------
1232 -- Build_Task_Image_Decls --
1233 ----------------------------
1235 function Build_Task_Image_Decls
1239 In_Init_Proc
: Boolean := False) return List_Id
1241 Decls
: constant List_Id
:= New_List
;
1242 T_Id
: Entity_Id
:= Empty
;
1244 Expr
: Node_Id
:= Empty
;
1245 Fun
: Node_Id
:= Empty
;
1246 Is_Dyn
: constant Boolean :=
1247 Nkind
(Parent
(Id_Ref
)) = N_Assignment_Statement
1249 Nkind
(Expression
(Parent
(Id_Ref
))) = N_Allocator
;
1252 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
1253 -- generate a dummy declaration only.
1255 if Restriction_Active
(No_Implicit_Heap_Allocations
)
1256 or else Global_Discard_Names
1258 T_Id
:= Make_Temporary
(Loc
, 'J');
1263 Make_Object_Declaration
(Loc
,
1264 Defining_Identifier
=> T_Id
,
1265 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1267 Make_String_Literal
(Loc
,
1268 Strval
=> String_From_Name_Buffer
)));
1271 if Nkind
(Id_Ref
) = N_Identifier
1272 or else Nkind
(Id_Ref
) = N_Defining_Identifier
1274 -- For a simple variable, the image of the task is built from
1275 -- the name of the variable. To avoid possible conflict with the
1276 -- anonymous type created for a single protected object, add a
1280 Make_Defining_Identifier
(Loc
,
1281 New_External_Name
(Chars
(Id_Ref
), 'T', 1));
1283 Get_Name_String
(Chars
(Id_Ref
));
1286 Make_String_Literal
(Loc
,
1287 Strval
=> String_From_Name_Buffer
);
1289 elsif Nkind
(Id_Ref
) = N_Selected_Component
then
1291 Make_Defining_Identifier
(Loc
,
1292 New_External_Name
(Chars
(Selector_Name
(Id_Ref
)), 'T'));
1293 Fun
:= Build_Task_Record_Image
(Loc
, Id_Ref
, Is_Dyn
);
1295 elsif Nkind
(Id_Ref
) = N_Indexed_Component
then
1297 Make_Defining_Identifier
(Loc
,
1298 New_External_Name
(Chars
(A_Type
), 'N'));
1300 Fun
:= Build_Task_Array_Image
(Loc
, Id_Ref
, A_Type
, Is_Dyn
);
1304 if Present
(Fun
) then
1305 Append
(Fun
, Decls
);
1306 Expr
:= Make_Function_Call
(Loc
,
1307 Name
=> New_Occurrence_Of
(Defining_Entity
(Fun
), Loc
));
1309 if not In_Init_Proc
and then VM_Target
= No_VM
then
1310 Set_Uses_Sec_Stack
(Defining_Entity
(Fun
));
1314 Decl
:= Make_Object_Declaration
(Loc
,
1315 Defining_Identifier
=> T_Id
,
1316 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1317 Constant_Present
=> True,
1318 Expression
=> Expr
);
1320 Append
(Decl
, Decls
);
1322 end Build_Task_Image_Decls
;
1324 -------------------------------
1325 -- Build_Task_Image_Function --
1326 -------------------------------
1328 function Build_Task_Image_Function
1332 Res
: Entity_Id
) return Node_Id
1338 Make_Simple_Return_Statement
(Loc
,
1339 Expression
=> New_Occurrence_Of
(Res
, Loc
)));
1341 Spec
:= Make_Function_Specification
(Loc
,
1342 Defining_Unit_Name
=> Make_Temporary
(Loc
, 'F'),
1343 Result_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
));
1345 -- Calls to 'Image use the secondary stack, which must be cleaned up
1346 -- after the task name is built.
1348 return Make_Subprogram_Body
(Loc
,
1349 Specification
=> Spec
,
1350 Declarations
=> Decls
,
1351 Handled_Statement_Sequence
=>
1352 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
));
1353 end Build_Task_Image_Function
;
1355 -----------------------------
1356 -- Build_Task_Image_Prefix --
1357 -----------------------------
1359 procedure Build_Task_Image_Prefix
1361 Len
: out Entity_Id
;
1362 Res
: out Entity_Id
;
1363 Pos
: out Entity_Id
;
1370 Len
:= Make_Temporary
(Loc
, 'L', Sum
);
1373 Make_Object_Declaration
(Loc
,
1374 Defining_Identifier
=> Len
,
1375 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1376 Expression
=> Sum
));
1378 Res
:= Make_Temporary
(Loc
, 'R');
1381 Make_Object_Declaration
(Loc
,
1382 Defining_Identifier
=> Res
,
1383 Object_Definition
=>
1384 Make_Subtype_Indication
(Loc
,
1385 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1387 Make_Index_Or_Discriminant_Constraint
(Loc
,
1391 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1392 High_Bound
=> New_Occurrence_Of
(Len
, Loc
)))))));
1394 -- Indicate that the result is an internal temporary, so it does not
1395 -- receive a bogus initialization when declaration is expanded. This
1396 -- is both efficient, and prevents anomalies in the handling of
1397 -- dynamic objects on the secondary stack.
1399 Set_Is_Internal
(Res
);
1400 Pos
:= Make_Temporary
(Loc
, 'P');
1403 Make_Object_Declaration
(Loc
,
1404 Defining_Identifier
=> Pos
,
1405 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
1407 -- Pos := Prefix'Length;
1410 Make_Assignment_Statement
(Loc
,
1411 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1413 Make_Attribute_Reference
(Loc
,
1414 Attribute_Name
=> Name_Length
,
1415 Prefix
=> New_Occurrence_Of
(Prefix
, Loc
),
1416 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1)))));
1418 -- Res (1 .. Pos) := Prefix;
1421 Make_Assignment_Statement
(Loc
,
1424 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1427 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1428 High_Bound
=> New_Occurrence_Of
(Pos
, Loc
))),
1430 Expression
=> New_Occurrence_Of
(Prefix
, Loc
)));
1433 Make_Assignment_Statement
(Loc
,
1434 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1437 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1438 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1439 end Build_Task_Image_Prefix
;
1441 -----------------------------
1442 -- Build_Task_Record_Image --
1443 -----------------------------
1445 function Build_Task_Record_Image
1448 Dyn
: Boolean := False) return Node_Id
1451 -- Total length of generated name
1454 -- Index into result
1457 -- String to hold result
1459 Pref
: constant Entity_Id
:= Make_Temporary
(Loc
, 'P');
1460 -- Name of enclosing variable, prefix of resulting name
1463 -- Expression to compute total size of string
1466 -- Entity for selector name
1468 Decls
: constant List_Id
:= New_List
;
1469 Stats
: constant List_Id
:= New_List
;
1472 -- For a dynamic task, the name comes from the target variable. For a
1473 -- static one it is a formal of the enclosing init proc.
1476 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
1478 Make_Object_Declaration
(Loc
,
1479 Defining_Identifier
=> Pref
,
1480 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1482 Make_String_Literal
(Loc
,
1483 Strval
=> String_From_Name_Buffer
)));
1487 Make_Object_Renaming_Declaration
(Loc
,
1488 Defining_Identifier
=> Pref
,
1489 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
1490 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
1493 Sel
:= Make_Temporary
(Loc
, 'S');
1495 Get_Name_String
(Chars
(Selector_Name
(Id_Ref
)));
1498 Make_Object_Declaration
(Loc
,
1499 Defining_Identifier
=> Sel
,
1500 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
1502 Make_String_Literal
(Loc
,
1503 Strval
=> String_From_Name_Buffer
)));
1505 Sum
:= Make_Integer_Literal
(Loc
, Nat
(Name_Len
+ 1));
1511 Make_Attribute_Reference
(Loc
,
1512 Attribute_Name
=> Name_Length
,
1514 New_Occurrence_Of
(Pref
, Loc
),
1515 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
1517 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
1519 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('.')));
1521 -- Res (Pos) := '.';
1524 Make_Assignment_Statement
(Loc
,
1525 Name
=> Make_Indexed_Component
(Loc
,
1526 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1527 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
1529 Make_Character_Literal
(Loc
,
1531 Char_Literal_Value
=>
1532 UI_From_Int
(Character'Pos ('.')))));
1535 Make_Assignment_Statement
(Loc
,
1536 Name
=> New_Occurrence_Of
(Pos
, Loc
),
1539 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
1540 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
1542 -- Res (Pos .. Len) := Selector;
1545 Make_Assignment_Statement
(Loc
,
1546 Name
=> Make_Slice
(Loc
,
1547 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
1550 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
1551 High_Bound
=> New_Occurrence_Of
(Len
, Loc
))),
1552 Expression
=> New_Occurrence_Of
(Sel
, Loc
)));
1554 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
1555 end Build_Task_Record_Image
;
1557 -----------------------------
1558 -- Check_Float_Op_Overflow --
1559 -----------------------------
1561 procedure Check_Float_Op_Overflow
(N
: Node_Id
) is
1563 -- Return if no check needed
1565 if not Is_Floating_Point_Type
(Etype
(N
))
1566 or else not (Do_Overflow_Check
(N
) and then Check_Float_Overflow
)
1568 -- In CodePeer_Mode, rely on the overflow check flag being set instead
1569 -- and do not expand the code for float overflow checking.
1571 or else CodePeer_Mode
1576 -- Otherwise we replace the expression by
1578 -- do Tnn : constant ftype := expression;
1579 -- constraint_error when not Tnn'Valid;
1583 Loc
: constant Source_Ptr
:= Sloc
(N
);
1584 Tnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T', N
);
1585 Typ
: constant Entity_Id
:= Etype
(N
);
1588 -- Turn off the Do_Overflow_Check flag, since we are doing that work
1589 -- right here. We also set the node as analyzed to prevent infinite
1590 -- recursion from repeating the operation in the expansion.
1592 Set_Do_Overflow_Check
(N
, False);
1593 Set_Analyzed
(N
, True);
1595 -- Do the rewrite to include the check
1598 Make_Expression_With_Actions
(Loc
,
1599 Actions
=> New_List
(
1600 Make_Object_Declaration
(Loc
,
1601 Defining_Identifier
=> Tnn
,
1602 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1603 Constant_Present
=> True,
1604 Expression
=> Relocate_Node
(N
)),
1605 Make_Raise_Constraint_Error
(Loc
,
1609 Make_Attribute_Reference
(Loc
,
1610 Prefix
=> New_Occurrence_Of
(Tnn
, Loc
),
1611 Attribute_Name
=> Name_Valid
)),
1612 Reason
=> CE_Overflow_Check_Failed
)),
1613 Expression
=> New_Occurrence_Of
(Tnn
, Loc
)));
1615 Analyze_And_Resolve
(N
, Typ
);
1617 end Check_Float_Op_Overflow
;
1619 ----------------------------------
1620 -- Component_May_Be_Bit_Aligned --
1621 ----------------------------------
1623 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean is
1627 -- If no component clause, then everything is fine, since the back end
1628 -- never bit-misaligns by default, even if there is a pragma Packed for
1631 if No
(Comp
) or else No
(Component_Clause
(Comp
)) then
1635 UT
:= Underlying_Type
(Etype
(Comp
));
1637 -- It is only array and record types that cause trouble
1639 if not Is_Record_Type
(UT
) and then not Is_Array_Type
(UT
) then
1642 -- If we know that we have a small (64 bits or less) record or small
1643 -- bit-packed array, then everything is fine, since the back end can
1644 -- handle these cases correctly.
1646 elsif Esize
(Comp
) <= 64
1647 and then (Is_Record_Type
(UT
) or else Is_Bit_Packed_Array
(UT
))
1651 -- Otherwise if the component is not byte aligned, we know we have the
1652 -- nasty unaligned case.
1654 elsif Normalized_First_Bit
(Comp
) /= Uint_0
1655 or else Esize
(Comp
) mod System_Storage_Unit
/= Uint_0
1659 -- If we are large and byte aligned, then OK at this level
1664 end Component_May_Be_Bit_Aligned
;
1666 ----------------------------------------
1667 -- Containing_Package_With_Ext_Axioms --
1668 ----------------------------------------
1670 function Containing_Package_With_Ext_Axioms
1671 (E
: Entity_Id
) return Entity_Id
1676 if Ekind
(E
) = E_Package
then
1677 if Nkind
(Parent
(E
)) = N_Defining_Program_Unit_Name
then
1678 Decl
:= Parent
(Parent
(E
));
1684 -- E is the package or generic package which is externally axiomatized
1686 if Ekind_In
(E
, E_Package
, E_Generic_Package
)
1687 and then Has_Annotate_Pragma_For_External_Axiomatization
(E
)
1692 -- If E's scope is axiomatized, E is axiomatized.
1695 First_Ax_Parent_Scope
: Entity_Id
:= Empty
;
1698 if Present
(Scope
(E
)) then
1699 First_Ax_Parent_Scope
:=
1700 Containing_Package_With_Ext_Axioms
(Scope
(E
));
1703 if Present
(First_Ax_Parent_Scope
) then
1704 return First_Ax_Parent_Scope
;
1707 -- otherwise, if E is a package instance, it is axiomatized if the
1708 -- corresponding generic package is axiomatized.
1710 if Ekind
(E
) = E_Package
1711 and then Present
(Generic_Parent
(Decl
))
1714 Containing_Package_With_Ext_Axioms
(Generic_Parent
(Decl
));
1719 end Containing_Package_With_Ext_Axioms
;
1721 -------------------------------
1722 -- Convert_To_Actual_Subtype --
1723 -------------------------------
1725 procedure Convert_To_Actual_Subtype
(Exp
: Entity_Id
) is
1729 Act_ST
:= Get_Actual_Subtype
(Exp
);
1731 if Act_ST
= Etype
(Exp
) then
1734 Rewrite
(Exp
, Convert_To
(Act_ST
, Relocate_Node
(Exp
)));
1735 Analyze_And_Resolve
(Exp
, Act_ST
);
1737 end Convert_To_Actual_Subtype
;
1739 -----------------------------------
1740 -- Corresponding_Runtime_Package --
1741 -----------------------------------
1743 function Corresponding_Runtime_Package
(Typ
: Entity_Id
) return RTU_Id
is
1744 Pkg_Id
: RTU_Id
:= RTU_Null
;
1747 pragma Assert
(Is_Concurrent_Type
(Typ
));
1749 if Ekind
(Typ
) in Protected_Kind
then
1750 if Has_Entries
(Typ
)
1752 -- A protected type without entries that covers an interface and
1753 -- overrides the abstract routines with protected procedures is
1754 -- considered equivalent to a protected type with entries in the
1755 -- context of dispatching select statements. It is sufficient to
1756 -- check for the presence of an interface list in the declaration
1757 -- node to recognize this case.
1759 or else Present
(Interface_List
(Parent
(Typ
)))
1761 -- Protected types with interrupt handlers (when not using a
1762 -- restricted profile) are also considered equivalent to
1763 -- protected types with entries. The types which are used
1764 -- (Static_Interrupt_Protection and Dynamic_Interrupt_Protection)
1765 -- are derived from Protection_Entries.
1767 or else (Has_Attach_Handler
(Typ
) and then not Restricted_Profile
)
1768 or else Has_Interrupt_Handler
(Typ
)
1771 or else Restriction_Active
(No_Entry_Queue
) = False
1772 or else Restriction_Active
(No_Select_Statements
) = False
1773 or else Number_Entries
(Typ
) > 1
1774 or else (Has_Attach_Handler
(Typ
)
1775 and then not Restricted_Profile
)
1777 Pkg_Id
:= System_Tasking_Protected_Objects_Entries
;
1779 Pkg_Id
:= System_Tasking_Protected_Objects_Single_Entry
;
1783 Pkg_Id
:= System_Tasking_Protected_Objects
;
1788 end Corresponding_Runtime_Package
;
1790 -----------------------------------
1791 -- Current_Sem_Unit_Declarations --
1792 -----------------------------------
1794 function Current_Sem_Unit_Declarations
return List_Id
is
1795 U
: Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
1799 -- If the current unit is a package body, locate the visible
1800 -- declarations of the package spec.
1802 if Nkind
(U
) = N_Package_Body
then
1803 U
:= Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
1806 if Nkind
(U
) = N_Package_Declaration
then
1807 U
:= Specification
(U
);
1808 Decls
:= Visible_Declarations
(U
);
1812 Set_Visible_Declarations
(U
, Decls
);
1816 Decls
:= Declarations
(U
);
1820 Set_Declarations
(U
, Decls
);
1825 end Current_Sem_Unit_Declarations
;
1827 -----------------------
1828 -- Duplicate_Subexpr --
1829 -----------------------
1831 function Duplicate_Subexpr
1833 Name_Req
: Boolean := False;
1834 Renaming_Req
: Boolean := False) return Node_Id
1837 Remove_Side_Effects
(Exp
, Name_Req
, Renaming_Req
);
1838 return New_Copy_Tree
(Exp
);
1839 end Duplicate_Subexpr
;
1841 ---------------------------------
1842 -- Duplicate_Subexpr_No_Checks --
1843 ---------------------------------
1845 function Duplicate_Subexpr_No_Checks
1847 Name_Req
: Boolean := False;
1848 Renaming_Req
: Boolean := False;
1849 Related_Id
: Entity_Id
:= Empty
;
1850 Is_Low_Bound
: Boolean := False;
1851 Is_High_Bound
: Boolean := False) return Node_Id
1858 Name_Req
=> Name_Req
,
1859 Renaming_Req
=> Renaming_Req
,
1860 Related_Id
=> Related_Id
,
1861 Is_Low_Bound
=> Is_Low_Bound
,
1862 Is_High_Bound
=> Is_High_Bound
);
1864 New_Exp
:= New_Copy_Tree
(Exp
);
1865 Remove_Checks
(New_Exp
);
1867 end Duplicate_Subexpr_No_Checks
;
1869 -----------------------------------
1870 -- Duplicate_Subexpr_Move_Checks --
1871 -----------------------------------
1873 function Duplicate_Subexpr_Move_Checks
1875 Name_Req
: Boolean := False;
1876 Renaming_Req
: Boolean := False) return Node_Id
1881 Remove_Side_Effects
(Exp
, Name_Req
, Renaming_Req
);
1882 New_Exp
:= New_Copy_Tree
(Exp
);
1883 Remove_Checks
(Exp
);
1885 end Duplicate_Subexpr_Move_Checks
;
1887 --------------------
1888 -- Ensure_Defined --
1889 --------------------
1891 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
) is
1895 -- An itype reference must only be created if this is a local itype, so
1896 -- that gigi can elaborate it on the proper objstack.
1898 if Is_Itype
(Typ
) and then Scope
(Typ
) = Current_Scope
then
1899 IR
:= Make_Itype_Reference
(Sloc
(N
));
1900 Set_Itype
(IR
, Typ
);
1901 Insert_Action
(N
, IR
);
1905 --------------------
1906 -- Entry_Names_OK --
1907 --------------------
1909 function Entry_Names_OK
return Boolean is
1912 not Restricted_Profile
1913 and then not Global_Discard_Names
1914 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
1915 and then not Restriction_Active
(No_Local_Allocators
);
1922 procedure Evaluate_Name
(Nam
: Node_Id
) is
1923 K
: constant Node_Kind
:= Nkind
(Nam
);
1926 -- For an explicit dereference, we simply force the evaluation of the
1927 -- name expression. The dereference provides a value that is the address
1928 -- for the renamed object, and it is precisely this value that we want
1931 if K
= N_Explicit_Dereference
then
1932 Force_Evaluation
(Prefix
(Nam
));
1934 -- For a selected component, we simply evaluate the prefix
1936 elsif K
= N_Selected_Component
then
1937 Evaluate_Name
(Prefix
(Nam
));
1939 -- For an indexed component, or an attribute reference, we evaluate the
1940 -- prefix, which is itself a name, recursively, and then force the
1941 -- evaluation of all the subscripts (or attribute expressions).
1943 elsif Nkind_In
(K
, N_Indexed_Component
, N_Attribute_Reference
) then
1944 Evaluate_Name
(Prefix
(Nam
));
1950 E
:= First
(Expressions
(Nam
));
1951 while Present
(E
) loop
1952 Force_Evaluation
(E
);
1954 if Original_Node
(E
) /= E
then
1955 Set_Do_Range_Check
(E
, Do_Range_Check
(Original_Node
(E
)));
1962 -- For a slice, we evaluate the prefix, as for the indexed component
1963 -- case and then, if there is a range present, either directly or as the
1964 -- constraint of a discrete subtype indication, we evaluate the two
1965 -- bounds of this range.
1967 elsif K
= N_Slice
then
1968 Evaluate_Name
(Prefix
(Nam
));
1969 Evaluate_Slice_Bounds
(Nam
);
1971 -- For a type conversion, the expression of the conversion must be the
1972 -- name of an object, and we simply need to evaluate this name.
1974 elsif K
= N_Type_Conversion
then
1975 Evaluate_Name
(Expression
(Nam
));
1977 -- For a function call, we evaluate the call
1979 elsif K
= N_Function_Call
then
1980 Force_Evaluation
(Nam
);
1982 -- The remaining cases are direct name, operator symbol and character
1983 -- literal. In all these cases, we do nothing, since we want to
1984 -- reevaluate each time the renamed object is used.
1991 ---------------------------
1992 -- Evaluate_Slice_Bounds --
1993 ---------------------------
1995 procedure Evaluate_Slice_Bounds
(Slice
: Node_Id
) is
1996 DR
: constant Node_Id
:= Discrete_Range
(Slice
);
2001 if Nkind
(DR
) = N_Range
then
2002 Force_Evaluation
(Low_Bound
(DR
));
2003 Force_Evaluation
(High_Bound
(DR
));
2005 elsif Nkind
(DR
) = N_Subtype_Indication
then
2006 Constr
:= Constraint
(DR
);
2008 if Nkind
(Constr
) = N_Range_Constraint
then
2009 Rexpr
:= Range_Expression
(Constr
);
2011 Force_Evaluation
(Low_Bound
(Rexpr
));
2012 Force_Evaluation
(High_Bound
(Rexpr
));
2015 end Evaluate_Slice_Bounds
;
2017 ---------------------
2018 -- Evolve_And_Then --
2019 ---------------------
2021 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
2027 Make_And_Then
(Sloc
(Cond1
),
2029 Right_Opnd
=> Cond1
);
2031 end Evolve_And_Then
;
2033 --------------------
2034 -- Evolve_Or_Else --
2035 --------------------
2037 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
2043 Make_Or_Else
(Sloc
(Cond1
),
2045 Right_Opnd
=> Cond1
);
2049 -----------------------------------------
2050 -- Expand_Static_Predicates_In_Choices --
2051 -----------------------------------------
2053 procedure Expand_Static_Predicates_In_Choices
(N
: Node_Id
) is
2054 pragma Assert
(Nkind_In
(N
, N_Case_Statement_Alternative
, N_Variant
));
2056 Choices
: constant List_Id
:= Discrete_Choices
(N
);
2064 Choice
:= First
(Choices
);
2065 while Present
(Choice
) loop
2066 Next_C
:= Next
(Choice
);
2068 -- Check for name of subtype with static predicate
2070 if Is_Entity_Name
(Choice
)
2071 and then Is_Type
(Entity
(Choice
))
2072 and then Has_Predicates
(Entity
(Choice
))
2074 -- Loop through entries in predicate list, converting to choices
2075 -- and inserting in the list before the current choice. Note that
2076 -- if the list is empty, corresponding to a False predicate, then
2077 -- no choices are inserted.
2079 P
:= First
(Static_Discrete_Predicate
(Entity
(Choice
)));
2080 while Present
(P
) loop
2082 -- If low bound and high bounds are equal, copy simple choice
2084 if Expr_Value
(Low_Bound
(P
)) = Expr_Value
(High_Bound
(P
)) then
2085 C
:= New_Copy
(Low_Bound
(P
));
2087 -- Otherwise copy a range
2093 -- Change Sloc to referencing choice (rather than the Sloc of
2094 -- the predicate declaration element itself).
2096 Set_Sloc
(C
, Sloc
(Choice
));
2097 Insert_Before
(Choice
, C
);
2101 -- Delete the predicated entry
2106 -- Move to next choice to check
2110 end Expand_Static_Predicates_In_Choices
;
2112 ------------------------------
2113 -- Expand_Subtype_From_Expr --
2114 ------------------------------
2116 -- This function is applicable for both static and dynamic allocation of
2117 -- objects which are constrained by an initial expression. Basically it
2118 -- transforms an unconstrained subtype indication into a constrained one.
2120 -- The expression may also be transformed in certain cases in order to
2121 -- avoid multiple evaluation. In the static allocation case, the general
2126 -- is transformed into
2128 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
2130 -- Here are the main cases :
2132 -- <if Expr is a Slice>
2133 -- Val : T ([Index_Subtype (Expr)]) := Expr;
2135 -- <elsif Expr is a String Literal>
2136 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
2138 -- <elsif Expr is Constrained>
2139 -- subtype T is Type_Of_Expr
2142 -- <elsif Expr is an entity_name>
2143 -- Val : T (constraints taken from Expr) := Expr;
2146 -- type Axxx is access all T;
2147 -- Rval : Axxx := Expr'ref;
2148 -- Val : T (constraints taken from Rval) := Rval.all;
2150 -- ??? note: when the Expression is allocated in the secondary stack
2151 -- we could use it directly instead of copying it by declaring
2152 -- Val : T (...) renames Rval.all
2154 procedure Expand_Subtype_From_Expr
2156 Unc_Type
: Entity_Id
;
2157 Subtype_Indic
: Node_Id
;
2160 Loc
: constant Source_Ptr
:= Sloc
(N
);
2161 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
2165 -- In general we cannot build the subtype if expansion is disabled,
2166 -- because internal entities may not have been defined. However, to
2167 -- avoid some cascaded errors, we try to continue when the expression is
2168 -- an array (or string), because it is safe to compute the bounds. It is
2169 -- in fact required to do so even in a generic context, because there
2170 -- may be constants that depend on the bounds of a string literal, both
2171 -- standard string types and more generally arrays of characters.
2173 -- In GNATprove mode, these extra subtypes are not needed
2175 if GNATprove_Mode
then
2179 if not Expander_Active
2180 and then (No
(Etype
(Exp
)) or else not Is_String_Type
(Etype
(Exp
)))
2185 if Nkind
(Exp
) = N_Slice
then
2187 Slice_Type
: constant Entity_Id
:= Etype
(First_Index
(Exp_Typ
));
2190 Rewrite
(Subtype_Indic
,
2191 Make_Subtype_Indication
(Loc
,
2192 Subtype_Mark
=> New_Occurrence_Of
(Unc_Type
, Loc
),
2194 Make_Index_Or_Discriminant_Constraint
(Loc
,
2195 Constraints
=> New_List
2196 (New_Occurrence_Of
(Slice_Type
, Loc
)))));
2198 -- This subtype indication may be used later for constraint checks
2199 -- we better make sure that if a variable was used as a bound of
2200 -- of the original slice, its value is frozen.
2202 Evaluate_Slice_Bounds
(Exp
);
2205 elsif Ekind
(Exp_Typ
) = E_String_Literal_Subtype
then
2206 Rewrite
(Subtype_Indic
,
2207 Make_Subtype_Indication
(Loc
,
2208 Subtype_Mark
=> New_Occurrence_Of
(Unc_Type
, Loc
),
2210 Make_Index_Or_Discriminant_Constraint
(Loc
,
2211 Constraints
=> New_List
(
2212 Make_Literal_Range
(Loc
,
2213 Literal_Typ
=> Exp_Typ
)))));
2215 -- If the type of the expression is an internally generated type it
2216 -- may not be necessary to create a new subtype. However there are two
2217 -- exceptions: references to the current instances, and aliased array
2218 -- object declarations for which the backend needs to create a template.
2220 elsif Is_Constrained
(Exp_Typ
)
2221 and then not Is_Class_Wide_Type
(Unc_Type
)
2223 (Nkind
(N
) /= N_Object_Declaration
2224 or else not Is_Entity_Name
(Expression
(N
))
2225 or else not Comes_From_Source
(Entity
(Expression
(N
)))
2226 or else not Is_Array_Type
(Exp_Typ
)
2227 or else not Aliased_Present
(N
))
2229 if Is_Itype
(Exp_Typ
) then
2231 -- Within an initialization procedure, a selected component
2232 -- denotes a component of the enclosing record, and it appears as
2233 -- an actual in a call to its own initialization procedure. If
2234 -- this component depends on the outer discriminant, we must
2235 -- generate the proper actual subtype for it.
2237 if Nkind
(Exp
) = N_Selected_Component
2238 and then Within_Init_Proc
2241 Decl
: constant Node_Id
:=
2242 Build_Actual_Subtype_Of_Component
(Exp_Typ
, Exp
);
2244 if Present
(Decl
) then
2245 Insert_Action
(N
, Decl
);
2246 T
:= Defining_Identifier
(Decl
);
2252 -- No need to generate a new subtype
2259 T
:= Make_Temporary
(Loc
, 'T');
2262 Make_Subtype_Declaration
(Loc
,
2263 Defining_Identifier
=> T
,
2264 Subtype_Indication
=> New_Occurrence_Of
(Exp_Typ
, Loc
)));
2266 -- This type is marked as an itype even though it has an explicit
2267 -- declaration since otherwise Is_Generic_Actual_Type can get
2268 -- set, resulting in the generation of spurious errors. (See
2269 -- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
2272 Set_Associated_Node_For_Itype
(T
, Exp
);
2275 Rewrite
(Subtype_Indic
, New_Occurrence_Of
(T
, Loc
));
2277 -- Nothing needs to be done for private types with unknown discriminants
2278 -- if the underlying type is not an unconstrained composite type or it
2279 -- is an unchecked union.
2281 elsif Is_Private_Type
(Unc_Type
)
2282 and then Has_Unknown_Discriminants
(Unc_Type
)
2283 and then (not Is_Composite_Type
(Underlying_Type
(Unc_Type
))
2284 or else Is_Constrained
(Underlying_Type
(Unc_Type
))
2285 or else Is_Unchecked_Union
(Underlying_Type
(Unc_Type
)))
2289 -- Case of derived type with unknown discriminants where the parent type
2290 -- also has unknown discriminants.
2292 elsif Is_Record_Type
(Unc_Type
)
2293 and then not Is_Class_Wide_Type
(Unc_Type
)
2294 and then Has_Unknown_Discriminants
(Unc_Type
)
2295 and then Has_Unknown_Discriminants
(Underlying_Type
(Unc_Type
))
2297 -- Nothing to be done if no underlying record view available
2299 if No
(Underlying_Record_View
(Unc_Type
)) then
2302 -- Otherwise use the Underlying_Record_View to create the proper
2303 -- constrained subtype for an object of a derived type with unknown
2307 Remove_Side_Effects
(Exp
);
2308 Rewrite
(Subtype_Indic
,
2309 Make_Subtype_From_Expr
(Exp
, Underlying_Record_View
(Unc_Type
)));
2312 -- Renamings of class-wide interface types require no equivalent
2313 -- constrained type declarations because we only need to reference
2314 -- the tag component associated with the interface. The same is
2315 -- presumably true for class-wide types in general, so this test
2316 -- is broadened to include all class-wide renamings, which also
2317 -- avoids cases of unbounded recursion in Remove_Side_Effects.
2318 -- (Is this really correct, or are there some cases of class-wide
2319 -- renamings that require action in this procedure???)
2322 and then Nkind
(N
) = N_Object_Renaming_Declaration
2323 and then Is_Class_Wide_Type
(Unc_Type
)
2327 -- In Ada 95 nothing to be done if the type of the expression is limited
2328 -- because in this case the expression cannot be copied, and its use can
2329 -- only be by reference.
2331 -- In Ada 2005 the context can be an object declaration whose expression
2332 -- is a function that returns in place. If the nominal subtype has
2333 -- unknown discriminants, the call still provides constraints on the
2334 -- object, and we have to create an actual subtype from it.
2336 -- If the type is class-wide, the expression is dynamically tagged and
2337 -- we do not create an actual subtype either. Ditto for an interface.
2338 -- For now this applies only if the type is immutably limited, and the
2339 -- function being called is build-in-place. This will have to be revised
2340 -- when build-in-place functions are generalized to other types.
2342 elsif Is_Limited_View
(Exp_Typ
)
2344 (Is_Class_Wide_Type
(Exp_Typ
)
2345 or else Is_Interface
(Exp_Typ
)
2346 or else not Has_Unknown_Discriminants
(Exp_Typ
)
2347 or else not Is_Composite_Type
(Unc_Type
))
2351 -- For limited objects initialized with build in place function calls,
2352 -- nothing to be done; otherwise we prematurely introduce an N_Reference
2353 -- node in the expression initializing the object, which breaks the
2354 -- circuitry that detects and adds the additional arguments to the
2357 elsif Is_Build_In_Place_Function_Call
(Exp
) then
2361 Remove_Side_Effects
(Exp
);
2362 Rewrite
(Subtype_Indic
,
2363 Make_Subtype_From_Expr
(Exp
, Unc_Type
));
2365 end Expand_Subtype_From_Expr
;
2367 ----------------------
2368 -- Finalize_Address --
2369 ----------------------
2371 function Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
is
2372 Utyp
: Entity_Id
:= Typ
;
2375 -- Handle protected class-wide or task class-wide types
2377 if Is_Class_Wide_Type
(Utyp
) then
2378 if Is_Concurrent_Type
(Root_Type
(Utyp
)) then
2379 Utyp
:= Root_Type
(Utyp
);
2381 elsif Is_Private_Type
(Root_Type
(Utyp
))
2382 and then Present
(Full_View
(Root_Type
(Utyp
)))
2383 and then Is_Concurrent_Type
(Full_View
(Root_Type
(Utyp
)))
2385 Utyp
:= Full_View
(Root_Type
(Utyp
));
2389 -- Handle private types
2391 if Is_Private_Type
(Utyp
) and then Present
(Full_View
(Utyp
)) then
2392 Utyp
:= Full_View
(Utyp
);
2395 -- Handle protected and task types
2397 if Is_Concurrent_Type
(Utyp
)
2398 and then Present
(Corresponding_Record_Type
(Utyp
))
2400 Utyp
:= Corresponding_Record_Type
(Utyp
);
2403 Utyp
:= Underlying_Type
(Base_Type
(Utyp
));
2405 -- Deal with untagged derivation of private views. If the parent is
2406 -- now known to be protected, the finalization routine is the one
2407 -- defined on the corresponding record of the ancestor (corresponding
2408 -- records do not automatically inherit operations, but maybe they
2411 if Is_Untagged_Derivation
(Typ
) then
2412 if Is_Protected_Type
(Typ
) then
2413 Utyp
:= Corresponding_Record_Type
(Root_Type
(Base_Type
(Typ
)));
2416 Utyp
:= Underlying_Type
(Root_Type
(Base_Type
(Typ
)));
2418 if Is_Protected_Type
(Utyp
) then
2419 Utyp
:= Corresponding_Record_Type
(Utyp
);
2424 -- If the underlying_type is a subtype, we are dealing with the
2425 -- completion of a private type. We need to access the base type and
2426 -- generate a conversion to it.
2428 if Utyp
/= Base_Type
(Utyp
) then
2429 pragma Assert
(Is_Private_Type
(Typ
));
2431 Utyp
:= Base_Type
(Utyp
);
2434 -- When dealing with an internally built full view for a type with
2435 -- unknown discriminants, use the original record type.
2437 if Is_Underlying_Record_View
(Utyp
) then
2438 Utyp
:= Etype
(Utyp
);
2441 return TSS
(Utyp
, TSS_Finalize_Address
);
2442 end Finalize_Address
;
2444 ------------------------
2445 -- Find_Interface_ADT --
2446 ------------------------
2448 function Find_Interface_ADT
2450 Iface
: Entity_Id
) return Elmt_Id
2453 Typ
: Entity_Id
:= T
;
2456 pragma Assert
(Is_Interface
(Iface
));
2458 -- Handle private types
2460 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2461 Typ
:= Full_View
(Typ
);
2464 -- Handle access types
2466 if Is_Access_Type
(Typ
) then
2467 Typ
:= Designated_Type
(Typ
);
2470 -- Handle task and protected types implementing interfaces
2472 if Is_Concurrent_Type
(Typ
) then
2473 Typ
:= Corresponding_Record_Type
(Typ
);
2477 (not Is_Class_Wide_Type
(Typ
)
2478 and then Ekind
(Typ
) /= E_Incomplete_Type
);
2480 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2481 return First_Elmt
(Access_Disp_Table
(Typ
));
2484 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
2486 and then Present
(Related_Type
(Node
(ADT
)))
2487 and then Related_Type
(Node
(ADT
)) /= Iface
2488 and then not Is_Ancestor
(Iface
, Related_Type
(Node
(ADT
)),
2489 Use_Full_View
=> True)
2494 pragma Assert
(Present
(Related_Type
(Node
(ADT
))));
2497 end Find_Interface_ADT
;
2499 ------------------------
2500 -- Find_Interface_Tag --
2501 ------------------------
2503 function Find_Interface_Tag
2505 Iface
: Entity_Id
) return Entity_Id
2508 Found
: Boolean := False;
2509 Typ
: Entity_Id
:= T
;
2511 procedure Find_Tag
(Typ
: Entity_Id
);
2512 -- Internal subprogram used to recursively climb to the ancestors
2518 procedure Find_Tag
(Typ
: Entity_Id
) is
2523 -- This routine does not handle the case in which the interface is an
2524 -- ancestor of Typ. That case is handled by the enclosing subprogram.
2526 pragma Assert
(Typ
/= Iface
);
2528 -- Climb to the root type handling private types
2530 if Present
(Full_View
(Etype
(Typ
))) then
2531 if Full_View
(Etype
(Typ
)) /= Typ
then
2532 Find_Tag
(Full_View
(Etype
(Typ
)));
2535 elsif Etype
(Typ
) /= Typ
then
2536 Find_Tag
(Etype
(Typ
));
2539 -- Traverse the list of interfaces implemented by the type
2542 and then Present
(Interfaces
(Typ
))
2543 and then not (Is_Empty_Elmt_List
(Interfaces
(Typ
)))
2545 -- Skip the tag associated with the primary table
2547 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2548 AI_Tag
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2549 pragma Assert
(Present
(AI_Tag
));
2551 AI_Elmt
:= First_Elmt
(Interfaces
(Typ
));
2552 while Present
(AI_Elmt
) loop
2553 AI
:= Node
(AI_Elmt
);
2556 or else Is_Ancestor
(Iface
, AI
, Use_Full_View
=> True)
2562 AI_Tag
:= Next_Tag_Component
(AI_Tag
);
2563 Next_Elmt
(AI_Elmt
);
2568 -- Start of processing for Find_Interface_Tag
2571 pragma Assert
(Is_Interface
(Iface
));
2573 -- Handle access types
2575 if Is_Access_Type
(Typ
) then
2576 Typ
:= Designated_Type
(Typ
);
2579 -- Handle class-wide types
2581 if Is_Class_Wide_Type
(Typ
) then
2582 Typ
:= Root_Type
(Typ
);
2585 -- Handle private types
2587 if Has_Private_Declaration
(Typ
) and then Present
(Full_View
(Typ
)) then
2588 Typ
:= Full_View
(Typ
);
2591 -- Handle entities from the limited view
2593 if Ekind
(Typ
) = E_Incomplete_Type
then
2594 pragma Assert
(Present
(Non_Limited_View
(Typ
)));
2595 Typ
:= Non_Limited_View
(Typ
);
2598 -- Handle task and protected types implementing interfaces
2600 if Is_Concurrent_Type
(Typ
) then
2601 Typ
:= Corresponding_Record_Type
(Typ
);
2604 -- If the interface is an ancestor of the type, then it shared the
2605 -- primary dispatch table.
2607 if Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
2608 pragma Assert
(Etype
(First_Tag_Component
(Typ
)) = RTE
(RE_Tag
));
2609 return First_Tag_Component
(Typ
);
2611 -- Otherwise we need to search for its associated tag component
2615 pragma Assert
(Found
);
2618 end Find_Interface_Tag
;
2624 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
is
2626 Typ
: Entity_Id
:= T
;
2630 if Is_Class_Wide_Type
(Typ
) then
2631 Typ
:= Root_Type
(Typ
);
2634 Typ
:= Underlying_Type
(Typ
);
2636 -- Loop through primitive operations
2638 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
2639 while Present
(Prim
) loop
2642 -- We can retrieve primitive operations by name if it is an internal
2643 -- name. For equality we must check that both of its operands have
2644 -- the same type, to avoid confusion with user-defined equalities
2645 -- than may have a non-symmetric signature.
2647 exit when Chars
(Op
) = Name
2650 or else Etype
(First_Formal
(Op
)) = Etype
(Last_Formal
(Op
)));
2654 -- Raise Program_Error if no primitive found
2657 raise Program_Error
;
2668 function Find_Prim_Op
2670 Name
: TSS_Name_Type
) return Entity_Id
2672 Inher_Op
: Entity_Id
:= Empty
;
2673 Own_Op
: Entity_Id
:= Empty
;
2674 Prim_Elmt
: Elmt_Id
;
2675 Prim_Id
: Entity_Id
;
2676 Typ
: Entity_Id
:= T
;
2679 if Is_Class_Wide_Type
(Typ
) then
2680 Typ
:= Root_Type
(Typ
);
2683 Typ
:= Underlying_Type
(Typ
);
2685 -- This search is based on the assertion that the dispatching version
2686 -- of the TSS routine always precedes the real primitive.
2688 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
2689 while Present
(Prim_Elmt
) loop
2690 Prim_Id
:= Node
(Prim_Elmt
);
2692 if Is_TSS
(Prim_Id
, Name
) then
2693 if Present
(Alias
(Prim_Id
)) then
2694 Inher_Op
:= Prim_Id
;
2700 Next_Elmt
(Prim_Elmt
);
2703 if Present
(Own_Op
) then
2705 elsif Present
(Inher_Op
) then
2708 raise Program_Error
;
2712 ----------------------------
2713 -- Find_Protection_Object --
2714 ----------------------------
2716 function Find_Protection_Object
(Scop
: Entity_Id
) return Entity_Id
is
2721 while Present
(S
) loop
2722 if Ekind_In
(S
, E_Entry
, E_Entry_Family
, E_Function
, E_Procedure
)
2723 and then Present
(Protection_Object
(S
))
2725 return Protection_Object
(S
);
2731 -- If we do not find a Protection object in the scope chain, then
2732 -- something has gone wrong, most likely the object was never created.
2734 raise Program_Error
;
2735 end Find_Protection_Object
;
2737 --------------------------
2738 -- Find_Protection_Type --
2739 --------------------------
2741 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
is
2743 Typ
: Entity_Id
:= Conc_Typ
;
2746 if Is_Concurrent_Type
(Typ
) then
2747 Typ
:= Corresponding_Record_Type
(Typ
);
2750 -- Since restriction violations are not considered serious errors, the
2751 -- expander remains active, but may leave the corresponding record type
2752 -- malformed. In such cases, component _object is not available so do
2755 if not Analyzed
(Typ
) then
2759 Comp
:= First_Component
(Typ
);
2760 while Present
(Comp
) loop
2761 if Chars
(Comp
) = Name_uObject
then
2762 return Base_Type
(Etype
(Comp
));
2765 Next_Component
(Comp
);
2768 -- The corresponding record of a protected type should always have an
2771 raise Program_Error
;
2772 end Find_Protection_Type
;
2774 -----------------------
2775 -- Find_Hook_Context --
2776 -----------------------
2778 function Find_Hook_Context
(N
: Node_Id
) return Node_Id
is
2782 Wrapped_Node
: Node_Id
;
2783 -- Note: if we are in a transient scope, we want to reuse it as
2784 -- the context for actions insertion, if possible. But if N is itself
2785 -- part of the stored actions for the current transient scope,
2786 -- then we need to insert at the appropriate (inner) location in
2787 -- the not as an action on Node_To_Be_Wrapped.
2789 In_Cond_Expr
: constant Boolean := Within_Case_Or_If_Expression
(N
);
2792 -- When the node is inside a case/if expression, the lifetime of any
2793 -- temporary controlled object is extended. Find a suitable insertion
2794 -- node by locating the topmost case or if expressions.
2796 if In_Cond_Expr
then
2799 while Present
(Par
) loop
2800 if Nkind_In
(Original_Node
(Par
), N_Case_Expression
,
2805 -- Prevent the search from going too far
2807 elsif Is_Body_Or_Package_Declaration
(Par
) then
2811 Par
:= Parent
(Par
);
2814 -- The topmost case or if expression is now recovered, but it may
2815 -- still not be the correct place to add generated code. Climb to
2816 -- find a parent that is part of a declarative or statement list,
2817 -- and is not a list of actuals in a call.
2820 while Present
(Par
) loop
2821 if Is_List_Member
(Par
)
2822 and then not Nkind_In
(Par
, N_Component_Association
,
2823 N_Discriminant_Association
,
2824 N_Parameter_Association
,
2825 N_Pragma_Argument_Association
)
2826 and then not Nkind_In
2827 (Parent
(Par
), N_Function_Call
,
2828 N_Procedure_Call_Statement
,
2829 N_Entry_Call_Statement
)
2834 -- Prevent the search from going too far
2836 elsif Is_Body_Or_Package_Declaration
(Par
) then
2840 Par
:= Parent
(Par
);
2847 while Present
(Par
) loop
2849 -- Keep climbing past various operators
2851 if Nkind
(Parent
(Par
)) in N_Op
2852 or else Nkind_In
(Parent
(Par
), N_And_Then
, N_Or_Else
)
2854 Par
:= Parent
(Par
);
2862 -- The node may be located in a pragma in which case return the
2865 -- pragma Precondition (... and then Ctrl_Func_Call ...);
2867 -- Similar case occurs when the node is related to an object
2868 -- declaration or assignment:
2870 -- Obj [: Some_Typ] := ... and then Ctrl_Func_Call ...;
2872 -- Another case to consider is when the node is part of a return
2875 -- return ... and then Ctrl_Func_Call ...;
2877 -- Another case is when the node acts as a formal in a procedure
2880 -- Proc (... and then Ctrl_Func_Call ...);
2882 if Scope_Is_Transient
then
2883 Wrapped_Node
:= Node_To_Be_Wrapped
;
2885 Wrapped_Node
:= Empty
;
2888 while Present
(Par
) loop
2889 if Par
= Wrapped_Node
2890 or else Nkind_In
(Par
, N_Assignment_Statement
,
2891 N_Object_Declaration
,
2893 N_Procedure_Call_Statement
,
2894 N_Simple_Return_Statement
)
2898 -- Prevent the search from going too far
2900 elsif Is_Body_Or_Package_Declaration
(Par
) then
2904 Par
:= Parent
(Par
);
2907 -- Return the topmost short circuit operator
2911 end Find_Hook_Context
;
2913 ------------------------------
2914 -- Following_Address_Clause --
2915 ------------------------------
2917 function Following_Address_Clause
(D
: Node_Id
) return Node_Id
is
2918 Id
: constant Entity_Id
:= Defining_Identifier
(D
);
2922 function Check_Decls
(D
: Node_Id
) return Node_Id
;
2923 -- This internal function differs from the main function in that it
2924 -- gets called to deal with a following package private part, and
2925 -- it checks declarations starting with D (the main function checks
2926 -- declarations following D). If D is Empty, then Empty is returned.
2932 function Check_Decls
(D
: Node_Id
) return Node_Id
is
2937 while Present
(Decl
) loop
2938 if Nkind
(Decl
) = N_At_Clause
2939 and then Chars
(Identifier
(Decl
)) = Chars
(Id
)
2943 elsif Nkind
(Decl
) = N_Attribute_Definition_Clause
2944 and then Chars
(Decl
) = Name_Address
2945 and then Chars
(Name
(Decl
)) = Chars
(Id
)
2953 -- Otherwise not found, return Empty
2958 -- Start of processing for Following_Address_Clause
2961 -- If parser detected no address clause for the identifier in question,
2962 -- then the answer is a quick NO, without the need for a search.
2964 if not Get_Name_Table_Boolean1
(Chars
(Id
)) then
2968 -- Otherwise search current declarative unit
2970 Result
:= Check_Decls
(Next
(D
));
2972 if Present
(Result
) then
2976 -- Check for possible package private part following
2980 if Nkind
(Par
) = N_Package_Specification
2981 and then Visible_Declarations
(Par
) = List_Containing
(D
)
2982 and then Present
(Private_Declarations
(Par
))
2984 -- Private part present, check declarations there
2986 return Check_Decls
(First
(Private_Declarations
(Par
)));
2989 -- No private part, clause not found, return Empty
2993 end Following_Address_Clause
;
2995 ----------------------
2996 -- Force_Evaluation --
2997 ----------------------
2999 procedure Force_Evaluation
3001 Name_Req
: Boolean := False;
3002 Related_Id
: Entity_Id
:= Empty
;
3003 Is_Low_Bound
: Boolean := False;
3004 Is_High_Bound
: Boolean := False)
3009 Name_Req
=> Name_Req
,
3010 Variable_Ref
=> True,
3011 Renaming_Req
=> False,
3012 Related_Id
=> Related_Id
,
3013 Is_Low_Bound
=> Is_Low_Bound
,
3014 Is_High_Bound
=> Is_High_Bound
);
3015 end Force_Evaluation
;
3017 ---------------------------------
3018 -- Fully_Qualified_Name_String --
3019 ---------------------------------
3021 function Fully_Qualified_Name_String
3023 Append_NUL
: Boolean := True) return String_Id
3025 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
);
3026 -- Compute recursively the qualified name without NUL at the end, adding
3027 -- it to the currently started string being generated
3029 ----------------------------------
3030 -- Internal_Full_Qualified_Name --
3031 ----------------------------------
3033 procedure Internal_Full_Qualified_Name
(E
: Entity_Id
) is
3037 -- Deal properly with child units
3039 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
3040 Ent
:= Defining_Identifier
(E
);
3045 -- Compute qualification recursively (only "Standard" has no scope)
3047 if Present
(Scope
(Scope
(Ent
))) then
3048 Internal_Full_Qualified_Name
(Scope
(Ent
));
3049 Store_String_Char
(Get_Char_Code
('.'));
3052 -- Every entity should have a name except some expanded blocks
3053 -- don't bother about those.
3055 if Chars
(Ent
) = No_Name
then
3059 -- Generates the entity name in upper case
3061 Get_Decoded_Name_String
(Chars
(Ent
));
3063 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3065 end Internal_Full_Qualified_Name
;
3067 -- Start of processing for Full_Qualified_Name
3071 Internal_Full_Qualified_Name
(E
);
3074 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
3078 end Fully_Qualified_Name_String
;
3080 ------------------------
3081 -- Generate_Poll_Call --
3082 ------------------------
3084 procedure Generate_Poll_Call
(N
: Node_Id
) is
3086 -- No poll call if polling not active
3088 if not Polling_Required
then
3091 -- Otherwise generate require poll call
3094 Insert_Before_And_Analyze
(N
,
3095 Make_Procedure_Call_Statement
(Sloc
(N
),
3096 Name
=> New_Occurrence_Of
(RTE
(RE_Poll
), Sloc
(N
))));
3098 end Generate_Poll_Call
;
3100 ---------------------------------
3101 -- Get_Current_Value_Condition --
3102 ---------------------------------
3104 -- Note: the implementation of this procedure is very closely tied to the
3105 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
3106 -- interpret Current_Value fields set by the Set procedure, so the two
3107 -- procedures need to be closely coordinated.
3109 procedure Get_Current_Value_Condition
3114 Loc
: constant Source_Ptr
:= Sloc
(Var
);
3115 Ent
: constant Entity_Id
:= Entity
(Var
);
3117 procedure Process_Current_Value_Condition
3120 -- N is an expression which holds either True (S = True) or False (S =
3121 -- False) in the condition. This procedure digs out the expression and
3122 -- if it refers to Ent, sets Op and Val appropriately.
3124 -------------------------------------
3125 -- Process_Current_Value_Condition --
3126 -------------------------------------
3128 procedure Process_Current_Value_Condition
3133 Prev_Cond
: Node_Id
;
3143 -- Deal with NOT operators, inverting sense
3145 while Nkind
(Cond
) = N_Op_Not
loop
3146 Cond
:= Right_Opnd
(Cond
);
3150 -- Deal with conversions, qualifications, and expressions with
3153 while Nkind_In
(Cond
,
3155 N_Qualified_Expression
,
3156 N_Expression_With_Actions
)
3158 Cond
:= Expression
(Cond
);
3161 exit when Cond
= Prev_Cond
;
3164 -- Deal with AND THEN and AND cases
3166 if Nkind_In
(Cond
, N_And_Then
, N_Op_And
) then
3168 -- Don't ever try to invert a condition that is of the form of an
3169 -- AND or AND THEN (since we are not doing sufficiently general
3170 -- processing to allow this).
3172 if Sens
= False then
3178 -- Recursively process AND and AND THEN branches
3180 Process_Current_Value_Condition
(Left_Opnd
(Cond
), True);
3182 if Op
/= N_Empty
then
3186 Process_Current_Value_Condition
(Right_Opnd
(Cond
), True);
3189 -- Case of relational operator
3191 elsif Nkind
(Cond
) in N_Op_Compare
then
3194 -- Invert sense of test if inverted test
3196 if Sens
= False then
3198 when N_Op_Eq
=> Op
:= N_Op_Ne
;
3199 when N_Op_Ne
=> Op
:= N_Op_Eq
;
3200 when N_Op_Lt
=> Op
:= N_Op_Ge
;
3201 when N_Op_Gt
=> Op
:= N_Op_Le
;
3202 when N_Op_Le
=> Op
:= N_Op_Gt
;
3203 when N_Op_Ge
=> Op
:= N_Op_Lt
;
3204 when others => raise Program_Error
;
3208 -- Case of entity op value
3210 if Is_Entity_Name
(Left_Opnd
(Cond
))
3211 and then Ent
= Entity
(Left_Opnd
(Cond
))
3212 and then Compile_Time_Known_Value
(Right_Opnd
(Cond
))
3214 Val
:= Right_Opnd
(Cond
);
3216 -- Case of value op entity
3218 elsif Is_Entity_Name
(Right_Opnd
(Cond
))
3219 and then Ent
= Entity
(Right_Opnd
(Cond
))
3220 and then Compile_Time_Known_Value
(Left_Opnd
(Cond
))
3222 Val
:= Left_Opnd
(Cond
);
3224 -- We are effectively swapping operands
3227 when N_Op_Eq
=> null;
3228 when N_Op_Ne
=> null;
3229 when N_Op_Lt
=> Op
:= N_Op_Gt
;
3230 when N_Op_Gt
=> Op
:= N_Op_Lt
;
3231 when N_Op_Le
=> Op
:= N_Op_Ge
;
3232 when N_Op_Ge
=> Op
:= N_Op_Le
;
3233 when others => raise Program_Error
;
3242 elsif Nkind_In
(Cond
,
3244 N_Qualified_Expression
,
3245 N_Expression_With_Actions
)
3247 Cond
:= Expression
(Cond
);
3249 -- Case of Boolean variable reference, return as though the
3250 -- reference had said var = True.
3253 if Is_Entity_Name
(Cond
) and then Ent
= Entity
(Cond
) then
3254 Val
:= New_Occurrence_Of
(Standard_True
, Sloc
(Cond
));
3256 if Sens
= False then
3263 end Process_Current_Value_Condition
;
3265 -- Start of processing for Get_Current_Value_Condition
3271 -- Immediate return, nothing doing, if this is not an object
3273 if Ekind
(Ent
) not in Object_Kind
then
3277 -- Otherwise examine current value
3280 CV
: constant Node_Id
:= Current_Value
(Ent
);
3285 -- If statement. Condition is known true in THEN section, known False
3286 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
3288 if Nkind
(CV
) = N_If_Statement
then
3290 -- Before start of IF statement
3292 if Loc
< Sloc
(CV
) then
3295 -- After end of IF statement
3297 elsif Loc
>= Sloc
(CV
) + Text_Ptr
(UI_To_Int
(End_Span
(CV
))) then
3301 -- At this stage we know that we are within the IF statement, but
3302 -- unfortunately, the tree does not record the SLOC of the ELSE so
3303 -- we cannot use a simple SLOC comparison to distinguish between
3304 -- the then/else statements, so we have to climb the tree.
3311 while Parent
(N
) /= CV
loop
3314 -- If we fall off the top of the tree, then that's odd, but
3315 -- perhaps it could occur in some error situation, and the
3316 -- safest response is simply to assume that the outcome of
3317 -- the condition is unknown. No point in bombing during an
3318 -- attempt to optimize things.
3325 -- Now we have N pointing to a node whose parent is the IF
3326 -- statement in question, so now we can tell if we are within
3327 -- the THEN statements.
3329 if Is_List_Member
(N
)
3330 and then List_Containing
(N
) = Then_Statements
(CV
)
3334 -- If the variable reference does not come from source, we
3335 -- cannot reliably tell whether it appears in the else part.
3336 -- In particular, if it appears in generated code for a node
3337 -- that requires finalization, it may be attached to a list
3338 -- that has not been yet inserted into the code. For now,
3339 -- treat it as unknown.
3341 elsif not Comes_From_Source
(N
) then
3344 -- Otherwise we must be in ELSIF or ELSE part
3351 -- ELSIF part. Condition is known true within the referenced
3352 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
3353 -- and unknown before the ELSE part or after the IF statement.
3355 elsif Nkind
(CV
) = N_Elsif_Part
then
3357 -- if the Elsif_Part had condition_actions, the elsif has been
3358 -- rewritten as a nested if, and the original elsif_part is
3359 -- detached from the tree, so there is no way to obtain useful
3360 -- information on the current value of the variable.
3361 -- Can this be improved ???
3363 if No
(Parent
(CV
)) then
3369 -- If the tree has been otherwise rewritten there is nothing
3370 -- else to be done either.
3372 if Nkind
(Stm
) /= N_If_Statement
then
3376 -- Before start of ELSIF part
3378 if Loc
< Sloc
(CV
) then
3381 -- After end of IF statement
3383 elsif Loc
>= Sloc
(Stm
) +
3384 Text_Ptr
(UI_To_Int
(End_Span
(Stm
)))
3389 -- Again we lack the SLOC of the ELSE, so we need to climb the
3390 -- tree to see if we are within the ELSIF part in question.
3397 while Parent
(N
) /= Stm
loop
3400 -- If we fall off the top of the tree, then that's odd, but
3401 -- perhaps it could occur in some error situation, and the
3402 -- safest response is simply to assume that the outcome of
3403 -- the condition is unknown. No point in bombing during an
3404 -- attempt to optimize things.
3411 -- Now we have N pointing to a node whose parent is the IF
3412 -- statement in question, so see if is the ELSIF part we want.
3413 -- the THEN statements.
3418 -- Otherwise we must be in subsequent ELSIF or ELSE part
3425 -- Iteration scheme of while loop. The condition is known to be
3426 -- true within the body of the loop.
3428 elsif Nkind
(CV
) = N_Iteration_Scheme
then
3430 Loop_Stmt
: constant Node_Id
:= Parent
(CV
);
3433 -- Before start of body of loop
3435 if Loc
< Sloc
(Loop_Stmt
) then
3438 -- After end of LOOP statement
3440 elsif Loc
>= Sloc
(End_Label
(Loop_Stmt
)) then
3443 -- We are within the body of the loop
3450 -- All other cases of Current_Value settings
3456 -- If we fall through here, then we have a reportable condition, Sens
3457 -- is True if the condition is true and False if it needs inverting.
3459 Process_Current_Value_Condition
(Condition
(CV
), Sens
);
3461 end Get_Current_Value_Condition
;
3463 ---------------------
3464 -- Get_Stream_Size --
3465 ---------------------
3467 function Get_Stream_Size
(E
: Entity_Id
) return Uint
is
3469 -- If we have a Stream_Size clause for this type use it
3471 if Has_Stream_Size_Clause
(E
) then
3472 return Static_Integer
(Expression
(Stream_Size_Clause
(E
)));
3474 -- Otherwise the Stream_Size if the size of the type
3479 end Get_Stream_Size
;
3481 ---------------------------
3482 -- Has_Access_Constraint --
3483 ---------------------------
3485 function Has_Access_Constraint
(E
: Entity_Id
) return Boolean is
3487 T
: constant Entity_Id
:= Etype
(E
);
3490 if Has_Per_Object_Constraint
(E
) and then Has_Discriminants
(T
) then
3491 Disc
:= First_Discriminant
(T
);
3492 while Present
(Disc
) loop
3493 if Is_Access_Type
(Etype
(Disc
)) then
3497 Next_Discriminant
(Disc
);
3504 end Has_Access_Constraint
;
3506 -----------------------------------------------------
3507 -- Has_Annotate_Pragma_For_External_Axiomatization --
3508 -----------------------------------------------------
3510 function Has_Annotate_Pragma_For_External_Axiomatization
3511 (E
: Entity_Id
) return Boolean
3513 function Is_Annotate_Pragma_For_External_Axiomatization
3514 (N
: Node_Id
) return Boolean;
3515 -- Returns whether N is
3516 -- pragma Annotate (GNATprove, External_Axiomatization);
3518 ----------------------------------------------------
3519 -- Is_Annotate_Pragma_For_External_Axiomatization --
3520 ----------------------------------------------------
3522 -- The general form of pragma Annotate is
3524 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
3525 -- ARG ::= NAME | EXPRESSION
3527 -- The first two arguments are by convention intended to refer to an
3528 -- external tool and a tool-specific function. These arguments are
3531 -- The following is used to annotate a package specification which
3532 -- GNATprove should treat specially, because the axiomatization of
3533 -- this unit is given by the user instead of being automatically
3536 -- pragma Annotate (GNATprove, External_Axiomatization);
3538 function Is_Annotate_Pragma_For_External_Axiomatization
3539 (N
: Node_Id
) return Boolean
3541 Name_GNATprove
: constant String :=
3543 Name_External_Axiomatization
: constant String :=
3544 "external_axiomatization";
3548 if Nkind
(N
) = N_Pragma
3549 and then Get_Pragma_Id
(Pragma_Name
(N
)) = Pragma_Annotate
3550 and then List_Length
(Pragma_Argument_Associations
(N
)) = 2
3553 Arg1
: constant Node_Id
:=
3554 First
(Pragma_Argument_Associations
(N
));
3555 Arg2
: constant Node_Id
:= Next
(Arg1
);
3560 -- Fill in Name_Buffer with Name_GNATprove first, and then with
3561 -- Name_External_Axiomatization so that Name_Find returns the
3562 -- corresponding name. This takes care of all possible casings.
3565 Add_Str_To_Name_Buffer
(Name_GNATprove
);
3569 Add_Str_To_Name_Buffer
(Name_External_Axiomatization
);
3572 return Chars
(Get_Pragma_Arg
(Arg1
)) = Nam1
3574 Chars
(Get_Pragma_Arg
(Arg2
)) = Nam2
;
3580 end Is_Annotate_Pragma_For_External_Axiomatization
;
3585 Vis_Decls
: List_Id
;
3588 -- Start of processing for Has_Annotate_Pragma_For_External_Axiomatization
3591 if Nkind
(Parent
(E
)) = N_Defining_Program_Unit_Name
then
3592 Decl
:= Parent
(Parent
(E
));
3597 Vis_Decls
:= Visible_Declarations
(Decl
);
3599 N
:= First
(Vis_Decls
);
3600 while Present
(N
) loop
3602 -- Skip declarations generated by the frontend. Skip all pragmas
3603 -- that are not the desired Annotate pragma. Stop the search on
3604 -- the first non-pragma source declaration.
3606 if Comes_From_Source
(N
) then
3607 if Nkind
(N
) = N_Pragma
then
3608 if Is_Annotate_Pragma_For_External_Axiomatization
(N
) then
3620 end Has_Annotate_Pragma_For_External_Axiomatization
;
3622 --------------------
3623 -- Homonym_Number --
3624 --------------------
3626 function Homonym_Number
(Subp
: Entity_Id
) return Nat
is
3632 Hom
:= Homonym
(Subp
);
3633 while Present
(Hom
) loop
3634 if Scope
(Hom
) = Scope
(Subp
) then
3638 Hom
:= Homonym
(Hom
);
3644 -----------------------------------
3645 -- In_Library_Level_Package_Body --
3646 -----------------------------------
3648 function In_Library_Level_Package_Body
(Id
: Entity_Id
) return Boolean is
3650 -- First determine whether the entity appears at the library level, then
3651 -- look at the containing unit.
3653 if Is_Library_Level_Entity
(Id
) then
3655 Container
: constant Node_Id
:= Cunit
(Get_Source_Unit
(Id
));
3658 return Nkind
(Unit
(Container
)) = N_Package_Body
;
3663 end In_Library_Level_Package_Body
;
3665 ------------------------------
3666 -- In_Unconditional_Context --
3667 ------------------------------
3669 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean is
3674 while Present
(P
) loop
3676 when N_Subprogram_Body
=>
3679 when N_If_Statement
=>
3682 when N_Loop_Statement
=>
3685 when N_Case_Statement
=>
3694 end In_Unconditional_Context
;
3700 procedure Insert_Action
(Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
) is
3702 if Present
(Ins_Action
) then
3703 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
));
3707 -- Version with check(s) suppressed
3709 procedure Insert_Action
3710 (Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
; Suppress
: Check_Id
)
3713 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
), Suppress
);
3716 -------------------------
3717 -- Insert_Action_After --
3718 -------------------------
3720 procedure Insert_Action_After
3721 (Assoc_Node
: Node_Id
;
3722 Ins_Action
: Node_Id
)
3725 Insert_Actions_After
(Assoc_Node
, New_List
(Ins_Action
));
3726 end Insert_Action_After
;
3728 --------------------
3729 -- Insert_Actions --
3730 --------------------
3732 procedure Insert_Actions
(Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
) is
3736 Wrapped_Node
: Node_Id
:= Empty
;
3739 if No
(Ins_Actions
) or else Is_Empty_List
(Ins_Actions
) then
3743 -- Ignore insert of actions from inside default expression (or other
3744 -- similar "spec expression") in the special spec-expression analyze
3745 -- mode. Any insertions at this point have no relevance, since we are
3746 -- only doing the analyze to freeze the types of any static expressions.
3747 -- See section "Handling of Default Expressions" in the spec of package
3748 -- Sem for further details.
3750 if In_Spec_Expression
then
3754 -- If the action derives from stuff inside a record, then the actions
3755 -- are attached to the current scope, to be inserted and analyzed on
3756 -- exit from the scope. The reason for this is that we may also be
3757 -- generating freeze actions at the same time, and they must eventually
3758 -- be elaborated in the correct order.
3760 if Is_Record_Type
(Current_Scope
)
3761 and then not Is_Frozen
(Current_Scope
)
3763 if No
(Scope_Stack
.Table
3764 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
3766 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:=
3771 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
);
3777 -- We now intend to climb up the tree to find the right point to
3778 -- insert the actions. We start at Assoc_Node, unless this node is a
3779 -- subexpression in which case we start with its parent. We do this for
3780 -- two reasons. First it speeds things up. Second, if Assoc_Node is
3781 -- itself one of the special nodes like N_And_Then, then we assume that
3782 -- an initial request to insert actions for such a node does not expect
3783 -- the actions to get deposited in the node for later handling when the
3784 -- node is expanded, since clearly the node is being dealt with by the
3785 -- caller. Note that in the subexpression case, N is always the child we
3788 -- N_Raise_xxx_Error is an annoying special case, it is a statement if
3789 -- it has type Standard_Void_Type, and a subexpression otherwise.
3790 -- otherwise. Procedure calls, and similarly procedure attribute
3791 -- references, are also statements.
3793 if Nkind
(Assoc_Node
) in N_Subexpr
3794 and then (Nkind
(Assoc_Node
) not in N_Raise_xxx_Error
3795 or else Etype
(Assoc_Node
) /= Standard_Void_Type
)
3796 and then Nkind
(Assoc_Node
) /= N_Procedure_Call_Statement
3797 and then (Nkind
(Assoc_Node
) /= N_Attribute_Reference
3798 or else not Is_Procedure_Attribute_Name
3799 (Attribute_Name
(Assoc_Node
)))
3802 P
:= Parent
(Assoc_Node
);
3804 -- Non-subexpression case. Note that N is initially Empty in this case
3805 -- (N is only guaranteed Non-Empty in the subexpr case).
3812 -- Capture root of the transient scope
3814 if Scope_Is_Transient
then
3815 Wrapped_Node
:= Node_To_Be_Wrapped
;
3819 pragma Assert
(Present
(P
));
3821 -- Make sure that inserted actions stay in the transient scope
3823 if Present
(Wrapped_Node
) and then N
= Wrapped_Node
then
3824 Store_Before_Actions_In_Scope
(Ins_Actions
);
3830 -- Case of right operand of AND THEN or OR ELSE. Put the actions
3831 -- in the Actions field of the right operand. They will be moved
3832 -- out further when the AND THEN or OR ELSE operator is expanded.
3833 -- Nothing special needs to be done for the left operand since
3834 -- in that case the actions are executed unconditionally.
3836 when N_Short_Circuit
=>
3837 if N
= Right_Opnd
(P
) then
3839 -- We are now going to either append the actions to the
3840 -- actions field of the short-circuit operation. We will
3841 -- also analyze the actions now.
3843 -- This analysis is really too early, the proper thing would
3844 -- be to just park them there now, and only analyze them if
3845 -- we find we really need them, and to it at the proper
3846 -- final insertion point. However attempting to this proved
3847 -- tricky, so for now we just kill current values before and
3848 -- after the analyze call to make sure we avoid peculiar
3849 -- optimizations from this out of order insertion.
3851 Kill_Current_Values
;
3853 -- If P has already been expanded, we can't park new actions
3854 -- on it, so we need to expand them immediately, introducing
3855 -- an Expression_With_Actions. N can't be an expression
3856 -- with actions, or else then the actions would have been
3857 -- inserted at an inner level.
3859 if Analyzed
(P
) then
3860 pragma Assert
(Nkind
(N
) /= N_Expression_With_Actions
);
3862 Make_Expression_With_Actions
(Sloc
(N
),
3863 Actions
=> Ins_Actions
,
3864 Expression
=> Relocate_Node
(N
)));
3865 Analyze_And_Resolve
(N
);
3867 elsif Present
(Actions
(P
)) then
3868 Insert_List_After_And_Analyze
3869 (Last
(Actions
(P
)), Ins_Actions
);
3871 Set_Actions
(P
, Ins_Actions
);
3872 Analyze_List
(Actions
(P
));
3875 Kill_Current_Values
;
3880 -- Then or Else dependent expression of an if expression. Add
3881 -- actions to Then_Actions or Else_Actions field as appropriate.
3882 -- The actions will be moved further out when the if is expanded.
3884 when N_If_Expression
=>
3886 ThenX
: constant Node_Id
:= Next
(First
(Expressions
(P
)));
3887 ElseX
: constant Node_Id
:= Next
(ThenX
);
3890 -- If the enclosing expression is already analyzed, as
3891 -- is the case for nested elaboration checks, insert the
3892 -- conditional further out.
3894 if Analyzed
(P
) then
3897 -- Actions belong to the then expression, temporarily place
3898 -- them as Then_Actions of the if expression. They will be
3899 -- moved to the proper place later when the if expression
3902 elsif N
= ThenX
then
3903 if Present
(Then_Actions
(P
)) then
3904 Insert_List_After_And_Analyze
3905 (Last
(Then_Actions
(P
)), Ins_Actions
);
3907 Set_Then_Actions
(P
, Ins_Actions
);
3908 Analyze_List
(Then_Actions
(P
));
3913 -- Actions belong to the else expression, temporarily place
3914 -- them as Else_Actions of the if expression. They will be
3915 -- moved to the proper place later when the if expression
3918 elsif N
= ElseX
then
3919 if Present
(Else_Actions
(P
)) then
3920 Insert_List_After_And_Analyze
3921 (Last
(Else_Actions
(P
)), Ins_Actions
);
3923 Set_Else_Actions
(P
, Ins_Actions
);
3924 Analyze_List
(Else_Actions
(P
));
3929 -- Actions belong to the condition. In this case they are
3930 -- unconditionally executed, and so we can continue the
3931 -- search for the proper insert point.
3938 -- Alternative of case expression, we place the action in the
3939 -- Actions field of the case expression alternative, this will
3940 -- be handled when the case expression is expanded.
3942 when N_Case_Expression_Alternative
=>
3943 if Present
(Actions
(P
)) then
3944 Insert_List_After_And_Analyze
3945 (Last
(Actions
(P
)), Ins_Actions
);
3947 Set_Actions
(P
, Ins_Actions
);
3948 Analyze_List
(Actions
(P
));
3953 -- Case of appearing within an Expressions_With_Actions node. When
3954 -- the new actions come from the expression of the expression with
3955 -- actions, they must be added to the existing actions. The other
3956 -- alternative is when the new actions are related to one of the
3957 -- existing actions of the expression with actions, and should
3958 -- never reach here: if actions are inserted on a statement
3959 -- within the Actions of an expression with actions, or on some
3960 -- sub-expression of such a statement, then the outermost proper
3961 -- insertion point is right before the statement, and we should
3962 -- never climb up as far as the N_Expression_With_Actions itself.
3964 when N_Expression_With_Actions
=>
3965 if N
= Expression
(P
) then
3966 if Is_Empty_List
(Actions
(P
)) then
3967 Append_List_To
(Actions
(P
), Ins_Actions
);
3968 Analyze_List
(Actions
(P
));
3970 Insert_List_After_And_Analyze
3971 (Last
(Actions
(P
)), Ins_Actions
);
3977 raise Program_Error
;
3980 -- Case of appearing in the condition of a while expression or
3981 -- elsif. We insert the actions into the Condition_Actions field.
3982 -- They will be moved further out when the while loop or elsif
3985 when N_Iteration_Scheme |
3988 if N
= Condition
(P
) then
3989 if Present
(Condition_Actions
(P
)) then
3990 Insert_List_After_And_Analyze
3991 (Last
(Condition_Actions
(P
)), Ins_Actions
);
3993 Set_Condition_Actions
(P
, Ins_Actions
);
3995 -- Set the parent of the insert actions explicitly. This
3996 -- is not a syntactic field, but we need the parent field
3997 -- set, in particular so that freeze can understand that
3998 -- it is dealing with condition actions, and properly
3999 -- insert the freezing actions.
4001 Set_Parent
(Ins_Actions
, P
);
4002 Analyze_List
(Condition_Actions
(P
));
4008 -- Statements, declarations, pragmas, representation clauses
4013 N_Procedure_Call_Statement |
4014 N_Statement_Other_Than_Procedure_Call |
4020 -- Representation_Clause
4023 N_Attribute_Definition_Clause |
4024 N_Enumeration_Representation_Clause |
4025 N_Record_Representation_Clause |
4029 N_Abstract_Subprogram_Declaration |
4031 N_Exception_Declaration |
4032 N_Exception_Renaming_Declaration |
4033 N_Expression_Function |
4034 N_Formal_Abstract_Subprogram_Declaration |
4035 N_Formal_Concrete_Subprogram_Declaration |
4036 N_Formal_Object_Declaration |
4037 N_Formal_Type_Declaration |
4038 N_Full_Type_Declaration |
4039 N_Function_Instantiation |
4040 N_Generic_Function_Renaming_Declaration |
4041 N_Generic_Package_Declaration |
4042 N_Generic_Package_Renaming_Declaration |
4043 N_Generic_Procedure_Renaming_Declaration |
4044 N_Generic_Subprogram_Declaration |
4045 N_Implicit_Label_Declaration |
4046 N_Incomplete_Type_Declaration |
4047 N_Number_Declaration |
4048 N_Object_Declaration |
4049 N_Object_Renaming_Declaration |
4051 N_Package_Body_Stub |
4052 N_Package_Declaration |
4053 N_Package_Instantiation |
4054 N_Package_Renaming_Declaration |
4055 N_Private_Extension_Declaration |
4056 N_Private_Type_Declaration |
4057 N_Procedure_Instantiation |
4059 N_Protected_Body_Stub |
4060 N_Protected_Type_Declaration |
4061 N_Single_Task_Declaration |
4063 N_Subprogram_Body_Stub |
4064 N_Subprogram_Declaration |
4065 N_Subprogram_Renaming_Declaration |
4066 N_Subtype_Declaration |
4069 N_Task_Type_Declaration |
4071 -- Use clauses can appear in lists of declarations
4073 N_Use_Package_Clause |
4076 -- Freeze entity behaves like a declaration or statement
4079 N_Freeze_Generic_Entity
4081 -- Do not insert here if the item is not a list member (this
4082 -- happens for example with a triggering statement, and the
4083 -- proper approach is to insert before the entire select).
4085 if not Is_List_Member
(P
) then
4088 -- Do not insert if parent of P is an N_Component_Association
4089 -- node (i.e. we are in the context of an N_Aggregate or
4090 -- N_Extension_Aggregate node. In this case we want to insert
4091 -- before the entire aggregate.
4093 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
4096 -- Do not insert if the parent of P is either an N_Variant node
4097 -- or an N_Record_Definition node, meaning in either case that
4098 -- P is a member of a component list, and that therefore the
4099 -- actions should be inserted outside the complete record
4102 elsif Nkind_In
(Parent
(P
), N_Variant
, N_Record_Definition
) then
4105 -- Do not insert freeze nodes within the loop generated for
4106 -- an aggregate, because they may be elaborated too late for
4107 -- subsequent use in the back end: within a package spec the
4108 -- loop is part of the elaboration procedure and is only
4109 -- elaborated during the second pass.
4111 -- If the loop comes from source, or the entity is local to the
4112 -- loop itself it must remain within.
4114 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
4115 and then not Comes_From_Source
(Parent
(P
))
4116 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
4118 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
4122 -- Otherwise we can go ahead and do the insertion
4124 elsif P
= Wrapped_Node
then
4125 Store_Before_Actions_In_Scope
(Ins_Actions
);
4129 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4133 -- A special case, N_Raise_xxx_Error can act either as a statement
4134 -- or a subexpression. We tell the difference by looking at the
4135 -- Etype. It is set to Standard_Void_Type in the statement case.
4138 N_Raise_xxx_Error
=>
4139 if Etype
(P
) = Standard_Void_Type
then
4140 if P
= Wrapped_Node
then
4141 Store_Before_Actions_In_Scope
(Ins_Actions
);
4143 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4148 -- In the subexpression case, keep climbing
4154 -- If a component association appears within a loop created for
4155 -- an array aggregate, attach the actions to the association so
4156 -- they can be subsequently inserted within the loop. For other
4157 -- component associations insert outside of the aggregate. For
4158 -- an association that will generate a loop, its Loop_Actions
4159 -- attribute is already initialized (see exp_aggr.adb).
4161 -- The list of loop_actions can in turn generate additional ones,
4162 -- that are inserted before the associated node. If the associated
4163 -- node is outside the aggregate, the new actions are collected
4164 -- at the end of the loop actions, to respect the order in which
4165 -- they are to be elaborated.
4168 N_Component_Association
=>
4169 if Nkind
(Parent
(P
)) = N_Aggregate
4170 and then Present
(Loop_Actions
(P
))
4172 if Is_Empty_List
(Loop_Actions
(P
)) then
4173 Set_Loop_Actions
(P
, Ins_Actions
);
4174 Analyze_List
(Ins_Actions
);
4181 -- Check whether these actions were generated by a
4182 -- declaration that is part of the loop_ actions
4183 -- for the component_association.
4186 while Present
(Decl
) loop
4187 exit when Parent
(Decl
) = P
4188 and then Is_List_Member
(Decl
)
4190 List_Containing
(Decl
) = Loop_Actions
(P
);
4191 Decl
:= Parent
(Decl
);
4194 if Present
(Decl
) then
4195 Insert_List_Before_And_Analyze
4196 (Decl
, Ins_Actions
);
4198 Insert_List_After_And_Analyze
4199 (Last
(Loop_Actions
(P
)), Ins_Actions
);
4210 -- Another special case, an attribute denoting a procedure call
4213 N_Attribute_Reference
=>
4214 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
4215 if P
= Wrapped_Node
then
4216 Store_Before_Actions_In_Scope
(Ins_Actions
);
4218 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
4223 -- In the subexpression case, keep climbing
4229 -- A contract node should not belong to the tree
4232 raise Program_Error
;
4234 -- For all other node types, keep climbing tree
4238 N_Accept_Alternative |
4239 N_Access_Definition |
4240 N_Access_Function_Definition |
4241 N_Access_Procedure_Definition |
4242 N_Access_To_Object_Definition |
4245 N_Aspect_Specification |
4247 N_Case_Statement_Alternative |
4248 N_Character_Literal |
4249 N_Compilation_Unit |
4250 N_Compilation_Unit_Aux |
4251 N_Component_Clause |
4252 N_Component_Declaration |
4253 N_Component_Definition |
4255 N_Constrained_Array_Definition |
4256 N_Decimal_Fixed_Point_Definition |
4257 N_Defining_Character_Literal |
4258 N_Defining_Identifier |
4259 N_Defining_Operator_Symbol |
4260 N_Defining_Program_Unit_Name |
4261 N_Delay_Alternative |
4262 N_Delta_Constraint |
4263 N_Derived_Type_Definition |
4265 N_Digits_Constraint |
4266 N_Discriminant_Association |
4267 N_Discriminant_Specification |
4269 N_Entry_Body_Formal_Part |
4270 N_Entry_Call_Alternative |
4271 N_Entry_Declaration |
4272 N_Entry_Index_Specification |
4273 N_Enumeration_Type_Definition |
4275 N_Exception_Handler |
4277 N_Explicit_Dereference |
4278 N_Extension_Aggregate |
4279 N_Floating_Point_Definition |
4280 N_Formal_Decimal_Fixed_Point_Definition |
4281 N_Formal_Derived_Type_Definition |
4282 N_Formal_Discrete_Type_Definition |
4283 N_Formal_Floating_Point_Definition |
4284 N_Formal_Modular_Type_Definition |
4285 N_Formal_Ordinary_Fixed_Point_Definition |
4286 N_Formal_Package_Declaration |
4287 N_Formal_Private_Type_Definition |
4288 N_Formal_Incomplete_Type_Definition |
4289 N_Formal_Signed_Integer_Type_Definition |
4291 N_Function_Specification |
4292 N_Generic_Association |
4293 N_Handled_Sequence_Of_Statements |
4296 N_Index_Or_Discriminant_Constraint |
4297 N_Indexed_Component |
4299 N_Iterator_Specification |
4302 N_Loop_Parameter_Specification |
4304 N_Modular_Type_Definition |
4330 N_Op_Shift_Right_Arithmetic |
4334 N_Ordinary_Fixed_Point_Definition |
4336 N_Package_Specification |
4337 N_Parameter_Association |
4338 N_Parameter_Specification |
4339 N_Pop_Constraint_Error_Label |
4340 N_Pop_Program_Error_Label |
4341 N_Pop_Storage_Error_Label |
4342 N_Pragma_Argument_Association |
4343 N_Procedure_Specification |
4344 N_Protected_Definition |
4345 N_Push_Constraint_Error_Label |
4346 N_Push_Program_Error_Label |
4347 N_Push_Storage_Error_Label |
4348 N_Qualified_Expression |
4349 N_Quantified_Expression |
4350 N_Raise_Expression |
4352 N_Range_Constraint |
4354 N_Real_Range_Specification |
4355 N_Record_Definition |
4357 N_SCIL_Dispatch_Table_Tag_Init |
4358 N_SCIL_Dispatching_Call |
4359 N_SCIL_Membership_Test |
4360 N_Selected_Component |
4361 N_Signed_Integer_Type_Definition |
4362 N_Single_Protected_Declaration |
4365 N_Subtype_Indication |
4368 N_Terminate_Alternative |
4369 N_Triggering_Alternative |
4371 N_Unchecked_Expression |
4372 N_Unchecked_Type_Conversion |
4373 N_Unconstrained_Array_Definition |
4378 N_Validate_Unchecked_Conversion |
4385 -- If we fall through above tests, keep climbing tree
4389 if Nkind
(Parent
(N
)) = N_Subunit
then
4391 -- This is the proper body corresponding to a stub. Insertion must
4392 -- be done at the point of the stub, which is in the declarative
4393 -- part of the parent unit.
4395 P
:= Corresponding_Stub
(Parent
(N
));
4403 -- Version with check(s) suppressed
4405 procedure Insert_Actions
4406 (Assoc_Node
: Node_Id
;
4407 Ins_Actions
: List_Id
;
4408 Suppress
: Check_Id
)
4411 if Suppress
= All_Checks
then
4413 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
4415 Scope_Suppress
.Suppress
:= (others => True);
4416 Insert_Actions
(Assoc_Node
, Ins_Actions
);
4417 Scope_Suppress
.Suppress
:= Sva
;
4422 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
4424 Scope_Suppress
.Suppress
(Suppress
) := True;
4425 Insert_Actions
(Assoc_Node
, Ins_Actions
);
4426 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
4431 --------------------------
4432 -- Insert_Actions_After --
4433 --------------------------
4435 procedure Insert_Actions_After
4436 (Assoc_Node
: Node_Id
;
4437 Ins_Actions
: List_Id
)
4440 if Scope_Is_Transient
and then Assoc_Node
= Node_To_Be_Wrapped
then
4441 Store_After_Actions_In_Scope
(Ins_Actions
);
4443 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
4445 end Insert_Actions_After
;
4447 ------------------------
4448 -- Insert_Declaration --
4449 ------------------------
4451 procedure Insert_Declaration
(N
: Node_Id
; Decl
: Node_Id
) is
4455 pragma Assert
(Nkind
(N
) in N_Subexpr
);
4457 -- Climb until we find a procedure or a package
4461 pragma Assert
(Present
(Parent
(P
)));
4464 if Is_List_Member
(P
) then
4465 exit when Nkind_In
(Parent
(P
), N_Package_Specification
,
4468 -- Special handling for handled sequence of statements, we must
4469 -- insert in the statements not the exception handlers!
4471 if Nkind
(Parent
(P
)) = N_Handled_Sequence_Of_Statements
then
4472 P
:= First
(Statements
(Parent
(P
)));
4478 -- Now do the insertion
4480 Insert_Before
(P
, Decl
);
4482 end Insert_Declaration
;
4484 ---------------------------------
4485 -- Insert_Library_Level_Action --
4486 ---------------------------------
4488 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
4489 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
4492 Push_Scope
(Cunit_Entity
(Main_Unit
));
4493 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
4495 if No
(Actions
(Aux
)) then
4496 Set_Actions
(Aux
, New_List
(N
));
4498 Append
(N
, Actions
(Aux
));
4503 end Insert_Library_Level_Action
;
4505 ----------------------------------
4506 -- Insert_Library_Level_Actions --
4507 ----------------------------------
4509 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
4510 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
4513 if Is_Non_Empty_List
(L
) then
4514 Push_Scope
(Cunit_Entity
(Main_Unit
));
4515 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
4517 if No
(Actions
(Aux
)) then
4518 Set_Actions
(Aux
, L
);
4521 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
4526 end Insert_Library_Level_Actions
;
4528 ----------------------
4529 -- Inside_Init_Proc --
4530 ----------------------
4532 function Inside_Init_Proc
return Boolean is
4537 while Present
(S
) and then S
/= Standard_Standard
loop
4538 if Is_Init_Proc
(S
) then
4546 end Inside_Init_Proc
;
4548 ----------------------------
4549 -- Is_All_Null_Statements --
4550 ----------------------------
4552 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
4557 while Present
(Stm
) loop
4558 if Nkind
(Stm
) /= N_Null_Statement
then
4566 end Is_All_Null_Statements
;
4568 --------------------------------------------------
4569 -- Is_Displacement_Of_Object_Or_Function_Result --
4570 --------------------------------------------------
4572 function Is_Displacement_Of_Object_Or_Function_Result
4573 (Obj_Id
: Entity_Id
) return Boolean
4575 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean;
4576 -- Determine if particular node denotes a controlled function call. The
4577 -- call may have been heavily expanded.
4579 function Is_Displace_Call
(N
: Node_Id
) return Boolean;
4580 -- Determine whether a particular node is a call to Ada.Tags.Displace.
4581 -- The call might be nested within other actions such as conversions.
4583 function Is_Source_Object
(N
: Node_Id
) return Boolean;
4584 -- Determine whether a particular node denotes a source object
4586 ---------------------------------
4587 -- Is_Controlled_Function_Call --
4588 ---------------------------------
4590 function Is_Controlled_Function_Call
(N
: Node_Id
) return Boolean is
4591 Expr
: Node_Id
:= Original_Node
(N
);
4594 if Nkind
(Expr
) = N_Function_Call
then
4595 Expr
:= Name
(Expr
);
4597 -- When a function call appears in Object.Operation format, the
4598 -- original representation has two possible forms depending on the
4599 -- availability of actual parameters:
4601 -- Obj.Func_Call N_Selected_Component
4602 -- Obj.Func_Call (Param) N_Indexed_Component
4605 if Nkind
(Expr
) = N_Indexed_Component
then
4606 Expr
:= Prefix
(Expr
);
4609 if Nkind
(Expr
) = N_Selected_Component
then
4610 Expr
:= Selector_Name
(Expr
);
4615 Nkind_In
(Expr
, N_Expanded_Name
, N_Identifier
)
4616 and then Ekind
(Entity
(Expr
)) = E_Function
4617 and then Needs_Finalization
(Etype
(Entity
(Expr
)));
4618 end Is_Controlled_Function_Call
;
4620 ----------------------
4621 -- Is_Displace_Call --
4622 ----------------------
4624 function Is_Displace_Call
(N
: Node_Id
) return Boolean is
4625 Call
: Node_Id
:= N
;
4628 -- Strip various actions which may precede a call to Displace
4631 if Nkind
(Call
) = N_Explicit_Dereference
then
4632 Call
:= Prefix
(Call
);
4634 elsif Nkind_In
(Call
, N_Type_Conversion
,
4635 N_Unchecked_Type_Conversion
)
4637 Call
:= Expression
(Call
);
4646 and then Nkind
(Call
) = N_Function_Call
4647 and then Is_RTE
(Entity
(Name
(Call
)), RE_Displace
);
4648 end Is_Displace_Call
;
4650 ----------------------
4651 -- Is_Source_Object --
4652 ----------------------
4654 function Is_Source_Object
(N
: Node_Id
) return Boolean is
4658 and then Nkind
(N
) in N_Has_Entity
4659 and then Is_Object
(Entity
(N
))
4660 and then Comes_From_Source
(N
);
4661 end Is_Source_Object
;
4665 Decl
: constant Node_Id
:= Parent
(Obj_Id
);
4666 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4667 Orig_Decl
: constant Node_Id
:= Original_Node
(Decl
);
4669 -- Start of processing for Is_Displacement_Of_Object_Or_Function_Result
4674 -- Obj : CW_Type := Function_Call (...);
4678 -- Tmp : ... := Function_Call (...)'reference;
4679 -- Obj : CW_Type renames (... Ada.Tags.Displace (Tmp));
4681 -- where the return type of the function and the class-wide type require
4682 -- dispatch table pointer displacement.
4686 -- Obj : CW_Type := Src_Obj;
4690 -- Obj : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
4692 -- where the type of the source object and the class-wide type require
4693 -- dispatch table pointer displacement.
4696 Nkind
(Decl
) = N_Object_Renaming_Declaration
4697 and then Nkind
(Orig_Decl
) = N_Object_Declaration
4698 and then Comes_From_Source
(Orig_Decl
)
4699 and then Is_Class_Wide_Type
(Obj_Typ
)
4700 and then Is_Displace_Call
(Renamed_Object
(Obj_Id
))
4702 (Is_Controlled_Function_Call
(Expression
(Orig_Decl
))
4703 or else Is_Source_Object
(Expression
(Orig_Decl
)));
4704 end Is_Displacement_Of_Object_Or_Function_Result
;
4706 ------------------------------
4707 -- Is_Finalizable_Transient --
4708 ------------------------------
4710 function Is_Finalizable_Transient
4712 Rel_Node
: Node_Id
) return Boolean
4714 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
4715 Obj_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Obj_Id
));
4716 Desig
: Entity_Id
:= Obj_Typ
;
4718 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean;
4719 -- Determine whether transient object Trans_Id is initialized either
4720 -- by a function call which returns an access type or simply renames
4723 function Initialized_By_Aliased_BIP_Func_Call
4724 (Trans_Id
: Entity_Id
) return Boolean;
4725 -- Determine whether transient object Trans_Id is initialized by a
4726 -- build-in-place function call where the BIPalloc parameter is of
4727 -- value 1 and BIPaccess is not null. This case creates an aliasing
4728 -- between the returned value and the value denoted by BIPaccess.
4731 (Trans_Id
: Entity_Id
;
4732 First_Stmt
: Node_Id
) return Boolean;
4733 -- Determine whether transient object Trans_Id has been renamed or
4734 -- aliased through 'reference in the statement list starting from
4737 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean;
4738 -- Determine whether transient object Trans_Id is allocated on the heap
4740 function Is_Iterated_Container
4741 (Trans_Id
: Entity_Id
;
4742 First_Stmt
: Node_Id
) return Boolean;
4743 -- Determine whether transient object Trans_Id denotes a container which
4744 -- is in the process of being iterated in the statement list starting
4747 ---------------------------
4748 -- Initialized_By_Access --
4749 ---------------------------
4751 function Initialized_By_Access
(Trans_Id
: Entity_Id
) return Boolean is
4752 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4757 and then Nkind
(Expr
) /= N_Reference
4758 and then Is_Access_Type
(Etype
(Expr
));
4759 end Initialized_By_Access
;
4761 ------------------------------------------
4762 -- Initialized_By_Aliased_BIP_Func_Call --
4763 ------------------------------------------
4765 function Initialized_By_Aliased_BIP_Func_Call
4766 (Trans_Id
: Entity_Id
) return Boolean
4768 Call
: Node_Id
:= Expression
(Parent
(Trans_Id
));
4771 -- Build-in-place calls usually appear in 'reference format
4773 if Nkind
(Call
) = N_Reference
then
4774 Call
:= Prefix
(Call
);
4777 if Is_Build_In_Place_Function_Call
(Call
) then
4779 Access_Nam
: Name_Id
:= No_Name
;
4780 Access_OK
: Boolean := False;
4782 Alloc_Nam
: Name_Id
:= No_Name
;
4783 Alloc_OK
: Boolean := False;
4785 Func_Id
: Entity_Id
;
4789 -- Examine all parameter associations of the function call
4791 Param
:= First
(Parameter_Associations
(Call
));
4792 while Present
(Param
) loop
4793 if Nkind
(Param
) = N_Parameter_Association
4794 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
4796 Actual
:= Explicit_Actual_Parameter
(Param
);
4797 Formal
:= Selector_Name
(Param
);
4799 -- Construct the names of formals BIPaccess and BIPalloc
4800 -- using the function name retrieved from an arbitrary
4803 if Access_Nam
= No_Name
4804 and then Alloc_Nam
= No_Name
4805 and then Present
(Entity
(Formal
))
4807 Func_Id
:= Scope
(Entity
(Formal
));
4810 New_External_Name
(Chars
(Func_Id
),
4811 BIP_Formal_Suffix
(BIP_Object_Access
));
4814 New_External_Name
(Chars
(Func_Id
),
4815 BIP_Formal_Suffix
(BIP_Alloc_Form
));
4818 -- A match for BIPaccess => Temp has been found
4820 if Chars
(Formal
) = Access_Nam
4821 and then Nkind
(Actual
) /= N_Null
4826 -- A match for BIPalloc => 1 has been found
4828 if Chars
(Formal
) = Alloc_Nam
4829 and then Nkind
(Actual
) = N_Integer_Literal
4830 and then Intval
(Actual
) = Uint_1
4839 return Access_OK
and Alloc_OK
;
4844 end Initialized_By_Aliased_BIP_Func_Call
;
4851 (Trans_Id
: Entity_Id
;
4852 First_Stmt
: Node_Id
) return Boolean
4854 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
;
4855 -- Given an object renaming declaration, retrieve the entity of the
4856 -- renamed name. Return Empty if the renamed name is anything other
4857 -- than a variable or a constant.
4859 -------------------------
4860 -- Find_Renamed_Object --
4861 -------------------------
4863 function Find_Renamed_Object
(Ren_Decl
: Node_Id
) return Entity_Id
is
4864 Ren_Obj
: Node_Id
:= Empty
;
4866 function Find_Object
(N
: Node_Id
) return Traverse_Result
;
4867 -- Try to detect an object which is either a constant or a
4874 function Find_Object
(N
: Node_Id
) return Traverse_Result
is
4876 -- Stop the search once a constant or a variable has been
4879 if Nkind
(N
) = N_Identifier
4880 and then Present
(Entity
(N
))
4881 and then Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
4883 Ren_Obj
:= Entity
(N
);
4890 procedure Search
is new Traverse_Proc
(Find_Object
);
4894 Typ
: constant Entity_Id
:= Etype
(Defining_Identifier
(Ren_Decl
));
4896 -- Start of processing for Find_Renamed_Object
4899 -- Actions related to dispatching calls may appear as renamings of
4900 -- tags. Do not process this type of renaming because it does not
4901 -- use the actual value of the object.
4903 if not Is_RTE
(Typ
, RE_Tag_Ptr
) then
4904 Search
(Name
(Ren_Decl
));
4908 end Find_Renamed_Object
;
4913 Ren_Obj
: Entity_Id
;
4916 -- Start of processing for Is_Aliased
4920 while Present
(Stmt
) loop
4921 if Nkind
(Stmt
) = N_Object_Declaration
then
4922 Expr
:= Expression
(Stmt
);
4925 and then Nkind
(Expr
) = N_Reference
4926 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4927 and then Entity
(Prefix
(Expr
)) = Trans_Id
4932 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
then
4933 Ren_Obj
:= Find_Renamed_Object
(Stmt
);
4935 if Present
(Ren_Obj
) and then Ren_Obj
= Trans_Id
then
4950 function Is_Allocated
(Trans_Id
: Entity_Id
) return Boolean is
4951 Expr
: constant Node_Id
:= Expression
(Parent
(Trans_Id
));
4954 Is_Access_Type
(Etype
(Trans_Id
))
4955 and then Present
(Expr
)
4956 and then Nkind
(Expr
) = N_Allocator
;
4959 ---------------------------
4960 -- Is_Iterated_Container --
4961 ---------------------------
4963 function Is_Iterated_Container
4964 (Trans_Id
: Entity_Id
;
4965 First_Stmt
: Node_Id
) return Boolean
4975 -- It is not possible to iterate over containers in non-Ada 2012 code
4977 if Ada_Version
< Ada_2012
then
4981 Typ
:= Etype
(Trans_Id
);
4983 -- Handle access type created for secondary stack use
4985 if Is_Access_Type
(Typ
) then
4986 Typ
:= Designated_Type
(Typ
);
4989 -- Look for aspect Default_Iterator. It may be part of a type
4990 -- declaration for a container, or inherited from a base type
4993 Aspect
:= Find_Value_Of_Aspect
(Typ
, Aspect_Default_Iterator
);
4995 if Present
(Aspect
) then
4996 Iter
:= Entity
(Aspect
);
4998 -- Examine the statements following the container object and
4999 -- look for a call to the default iterate routine where the
5000 -- first parameter is the transient. Such a call appears as:
5002 -- It : Access_To_CW_Iterator :=
5003 -- Iterate (Tran_Id.all, ...)'reference;
5006 while Present
(Stmt
) loop
5008 -- Detect an object declaration which is initialized by a
5009 -- secondary stack function call.
5011 if Nkind
(Stmt
) = N_Object_Declaration
5012 and then Present
(Expression
(Stmt
))
5013 and then Nkind
(Expression
(Stmt
)) = N_Reference
5014 and then Nkind
(Prefix
(Expression
(Stmt
))) = N_Function_Call
5016 Call
:= Prefix
(Expression
(Stmt
));
5018 -- The call must invoke the default iterate routine of
5019 -- the container and the transient object must appear as
5020 -- the first actual parameter. Skip any calls whose names
5021 -- are not entities.
5023 if Is_Entity_Name
(Name
(Call
))
5024 and then Entity
(Name
(Call
)) = Iter
5025 and then Present
(Parameter_Associations
(Call
))
5027 Param
:= First
(Parameter_Associations
(Call
));
5029 if Nkind
(Param
) = N_Explicit_Dereference
5030 and then Entity
(Prefix
(Param
)) = Trans_Id
5042 end Is_Iterated_Container
;
5044 -- Start of processing for Is_Finalizable_Transient
5047 -- Handle access types
5049 if Is_Access_Type
(Desig
) then
5050 Desig
:= Available_View
(Designated_Type
(Desig
));
5054 Ekind_In
(Obj_Id
, E_Constant
, E_Variable
)
5055 and then Needs_Finalization
(Desig
)
5056 and then Requires_Transient_Scope
(Desig
)
5057 and then Nkind
(Rel_Node
) /= N_Simple_Return_Statement
5059 -- Do not consider renamed or 'reference-d transient objects because
5060 -- the act of renaming extends the object's lifetime.
5062 and then not Is_Aliased
(Obj_Id
, Decl
)
5064 -- Do not consider transient objects allocated on the heap since
5065 -- they are attached to a finalization master.
5067 and then not Is_Allocated
(Obj_Id
)
5069 -- If the transient object is a pointer, check that it is not
5070 -- initialized by a function which returns a pointer or acts as a
5071 -- renaming of another pointer.
5074 (not Is_Access_Type
(Obj_Typ
)
5075 or else not Initialized_By_Access
(Obj_Id
))
5077 -- Do not consider transient objects which act as indirect aliases
5078 -- of build-in-place function results.
5080 and then not Initialized_By_Aliased_BIP_Func_Call
(Obj_Id
)
5082 -- Do not consider conversions of tags to class-wide types
5084 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
5086 -- Do not consider containers in the context of iterator loops. Such
5087 -- transient objects must exist for as long as the loop is around,
5088 -- otherwise any operation carried out by the iterator will fail.
5090 and then not Is_Iterated_Container
(Obj_Id
, Decl
);
5091 end Is_Finalizable_Transient
;
5093 ---------------------------------
5094 -- Is_Fully_Repped_Tagged_Type --
5095 ---------------------------------
5097 function Is_Fully_Repped_Tagged_Type
(T
: Entity_Id
) return Boolean is
5098 U
: constant Entity_Id
:= Underlying_Type
(T
);
5102 if No
(U
) or else not Is_Tagged_Type
(U
) then
5104 elsif Has_Discriminants
(U
) then
5106 elsif not Has_Specified_Layout
(U
) then
5110 -- Here we have a tagged type, see if it has any unlayed out fields
5111 -- other than a possible tag and parent fields. If so, we return False.
5113 Comp
:= First_Component
(U
);
5114 while Present
(Comp
) loop
5115 if not Is_Tag
(Comp
)
5116 and then Chars
(Comp
) /= Name_uParent
5117 and then No
(Component_Clause
(Comp
))
5121 Next_Component
(Comp
);
5125 -- All components are layed out
5128 end Is_Fully_Repped_Tagged_Type
;
5130 ----------------------------------
5131 -- Is_Library_Level_Tagged_Type --
5132 ----------------------------------
5134 function Is_Library_Level_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
5136 return Is_Tagged_Type
(Typ
) and then Is_Library_Level_Entity
(Typ
);
5137 end Is_Library_Level_Tagged_Type
;
5139 --------------------------
5140 -- Is_Non_BIP_Func_Call --
5141 --------------------------
5143 function Is_Non_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
5145 -- The expected call is of the format
5147 -- Func_Call'reference
5150 Nkind
(Expr
) = N_Reference
5151 and then Nkind
(Prefix
(Expr
)) = N_Function_Call
5152 and then not Is_Build_In_Place_Function_Call
(Prefix
(Expr
));
5153 end Is_Non_BIP_Func_Call
;
5155 ------------------------------------
5156 -- Is_Object_Access_BIP_Func_Call --
5157 ------------------------------------
5159 function Is_Object_Access_BIP_Func_Call
5161 Obj_Id
: Entity_Id
) return Boolean
5163 Access_Nam
: Name_Id
:= No_Name
;
5170 -- Build-in-place calls usually appear in 'reference format. Note that
5171 -- the accessibility check machinery may add an extra 'reference due to
5172 -- side effect removal.
5175 while Nkind
(Call
) = N_Reference
loop
5176 Call
:= Prefix
(Call
);
5179 if Nkind_In
(Call
, N_Qualified_Expression
,
5180 N_Unchecked_Type_Conversion
)
5182 Call
:= Expression
(Call
);
5185 if Is_Build_In_Place_Function_Call
(Call
) then
5187 -- Examine all parameter associations of the function call
5189 Param
:= First
(Parameter_Associations
(Call
));
5190 while Present
(Param
) loop
5191 if Nkind
(Param
) = N_Parameter_Association
5192 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
5194 Formal
:= Selector_Name
(Param
);
5195 Actual
:= Explicit_Actual_Parameter
(Param
);
5197 -- Construct the name of formal BIPaccess. It is much easier to
5198 -- extract the name of the function using an arbitrary formal's
5199 -- scope rather than the Name field of Call.
5201 if Access_Nam
= No_Name
and then Present
(Entity
(Formal
)) then
5204 (Chars
(Scope
(Entity
(Formal
))),
5205 BIP_Formal_Suffix
(BIP_Object_Access
));
5208 -- A match for BIPaccess => Obj_Id'Unrestricted_Access has been
5211 if Chars
(Formal
) = Access_Nam
5212 and then Nkind
(Actual
) = N_Attribute_Reference
5213 and then Attribute_Name
(Actual
) = Name_Unrestricted_Access
5214 and then Nkind
(Prefix
(Actual
)) = N_Identifier
5215 and then Entity
(Prefix
(Actual
)) = Obj_Id
5226 end Is_Object_Access_BIP_Func_Call
;
5228 ----------------------------------
5229 -- Is_Possibly_Unaligned_Object --
5230 ----------------------------------
5232 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean is
5233 T
: constant Entity_Id
:= Etype
(N
);
5236 -- Objects are never unaligned on VMs
5238 if VM_Target
/= No_VM
then
5242 -- If renamed object, apply test to underlying object
5244 if Is_Entity_Name
(N
)
5245 and then Is_Object
(Entity
(N
))
5246 and then Present
(Renamed_Object
(Entity
(N
)))
5248 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(N
)));
5251 -- Tagged and controlled types and aliased types are always aligned, as
5252 -- are concurrent types.
5255 or else Has_Controlled_Component
(T
)
5256 or else Is_Concurrent_Type
(T
)
5257 or else Is_Tagged_Type
(T
)
5258 or else Is_Controlled
(T
)
5263 -- If this is an element of a packed array, may be unaligned
5265 if Is_Ref_To_Bit_Packed_Array
(N
) then
5269 -- Case of indexed component reference: test whether prefix is unaligned
5271 if Nkind
(N
) = N_Indexed_Component
then
5272 return Is_Possibly_Unaligned_Object
(Prefix
(N
));
5274 -- Case of selected component reference
5276 elsif Nkind
(N
) = N_Selected_Component
then
5278 P
: constant Node_Id
:= Prefix
(N
);
5279 C
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
5284 -- If component reference is for an array with non-static bounds,
5285 -- then it is always aligned: we can only process unaligned arrays
5286 -- with static bounds (more precisely compile time known bounds).
5288 if Is_Array_Type
(T
)
5289 and then not Compile_Time_Known_Bounds
(T
)
5294 -- If component is aliased, it is definitely properly aligned
5296 if Is_Aliased
(C
) then
5300 -- If component is for a type implemented as a scalar, and the
5301 -- record is packed, and the component is other than the first
5302 -- component of the record, then the component may be unaligned.
5304 if Is_Packed
(Etype
(P
))
5305 and then Represented_As_Scalar
(Etype
(C
))
5306 and then First_Entity
(Scope
(C
)) /= C
5311 -- Compute maximum possible alignment for T
5313 -- If alignment is known, then that settles things
5315 if Known_Alignment
(T
) then
5316 M
:= UI_To_Int
(Alignment
(T
));
5318 -- If alignment is not known, tentatively set max alignment
5321 M
:= Ttypes
.Maximum_Alignment
;
5323 -- We can reduce this if the Esize is known since the default
5324 -- alignment will never be more than the smallest power of 2
5325 -- that does not exceed this Esize value.
5327 if Known_Esize
(T
) then
5328 S
:= UI_To_Int
(Esize
(T
));
5330 while (M
/ 2) >= S
loop
5336 -- The following code is historical, it used to be present but it
5337 -- is too cautious, because the front-end does not know the proper
5338 -- default alignments for the target. Also, if the alignment is
5339 -- not known, the front end can't know in any case. If a copy is
5340 -- needed, the back-end will take care of it. This whole section
5341 -- including this comment can be removed later ???
5343 -- If the component reference is for a record that has a specified
5344 -- alignment, and we either know it is too small, or cannot tell,
5345 -- then the component may be unaligned.
5347 -- What is the following commented out code ???
5349 -- if Known_Alignment (Etype (P))
5350 -- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
5351 -- and then M > Alignment (Etype (P))
5356 -- Case of component clause present which may specify an
5357 -- unaligned position.
5359 if Present
(Component_Clause
(C
)) then
5361 -- Otherwise we can do a test to make sure that the actual
5362 -- start position in the record, and the length, are both
5363 -- consistent with the required alignment. If not, we know
5364 -- that we are unaligned.
5367 Align_In_Bits
: constant Nat
:= M
* System_Storage_Unit
;
5369 if Component_Bit_Offset
(C
) mod Align_In_Bits
/= 0
5370 or else Esize
(C
) mod Align_In_Bits
/= 0
5377 -- Otherwise, for a component reference, test prefix
5379 return Is_Possibly_Unaligned_Object
(P
);
5382 -- If not a component reference, must be aligned
5387 end Is_Possibly_Unaligned_Object
;
5389 ---------------------------------
5390 -- Is_Possibly_Unaligned_Slice --
5391 ---------------------------------
5393 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean is
5395 -- Go to renamed object
5397 if Is_Entity_Name
(N
)
5398 and then Is_Object
(Entity
(N
))
5399 and then Present
(Renamed_Object
(Entity
(N
)))
5401 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(N
)));
5404 -- The reference must be a slice
5406 if Nkind
(N
) /= N_Slice
then
5410 -- We only need to worry if the target has strict alignment
5412 if not Target_Strict_Alignment
then
5416 -- If it is a slice, then look at the array type being sliced
5419 Sarr
: constant Node_Id
:= Prefix
(N
);
5420 -- Prefix of the slice, i.e. the array being sliced
5422 Styp
: constant Entity_Id
:= Etype
(Prefix
(N
));
5423 -- Type of the array being sliced
5429 -- The problems arise if the array object that is being sliced
5430 -- is a component of a record or array, and we cannot guarantee
5431 -- the alignment of the array within its containing object.
5433 -- To investigate this, we look at successive prefixes to see
5434 -- if we have a worrisome indexed or selected component.
5438 -- Case of array is part of an indexed component reference
5440 if Nkind
(Pref
) = N_Indexed_Component
then
5441 Ptyp
:= Etype
(Prefix
(Pref
));
5443 -- The only problematic case is when the array is packed, in
5444 -- which case we really know nothing about the alignment of
5445 -- individual components.
5447 if Is_Bit_Packed_Array
(Ptyp
) then
5451 -- Case of array is part of a selected component reference
5453 elsif Nkind
(Pref
) = N_Selected_Component
then
5454 Ptyp
:= Etype
(Prefix
(Pref
));
5456 -- We are definitely in trouble if the record in question
5457 -- has an alignment, and either we know this alignment is
5458 -- inconsistent with the alignment of the slice, or we don't
5459 -- know what the alignment of the slice should be.
5461 if Known_Alignment
(Ptyp
)
5462 and then (Unknown_Alignment
(Styp
)
5463 or else Alignment
(Styp
) > Alignment
(Ptyp
))
5468 -- We are in potential trouble if the record type is packed.
5469 -- We could special case when we know that the array is the
5470 -- first component, but that's not such a simple case ???
5472 if Is_Packed
(Ptyp
) then
5476 -- We are in trouble if there is a component clause, and
5477 -- either we do not know the alignment of the slice, or
5478 -- the alignment of the slice is inconsistent with the
5479 -- bit position specified by the component clause.
5482 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
5484 if Present
(Component_Clause
(Field
))
5486 (Unknown_Alignment
(Styp
)
5488 (Component_Bit_Offset
(Field
) mod
5489 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
5495 -- For cases other than selected or indexed components we know we
5496 -- are OK, since no issues arise over alignment.
5502 -- We processed an indexed component or selected component
5503 -- reference that looked safe, so keep checking prefixes.
5505 Pref
:= Prefix
(Pref
);
5508 end Is_Possibly_Unaligned_Slice
;
5510 -------------------------------
5511 -- Is_Related_To_Func_Return --
5512 -------------------------------
5514 function Is_Related_To_Func_Return
(Id
: Entity_Id
) return Boolean is
5515 Expr
: constant Node_Id
:= Related_Expression
(Id
);
5519 and then Nkind
(Expr
) = N_Explicit_Dereference
5520 and then Nkind
(Parent
(Expr
)) = N_Simple_Return_Statement
;
5521 end Is_Related_To_Func_Return
;
5523 --------------------------------
5524 -- Is_Ref_To_Bit_Packed_Array --
5525 --------------------------------
5527 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean is
5532 if Is_Entity_Name
(N
)
5533 and then Is_Object
(Entity
(N
))
5534 and then Present
(Renamed_Object
(Entity
(N
)))
5536 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(N
)));
5539 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5540 if Is_Bit_Packed_Array
(Etype
(Prefix
(N
))) then
5543 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(N
));
5546 if Result
and then Nkind
(N
) = N_Indexed_Component
then
5547 Expr
:= First
(Expressions
(N
));
5548 while Present
(Expr
) loop
5549 Force_Evaluation
(Expr
);
5559 end Is_Ref_To_Bit_Packed_Array
;
5561 --------------------------------
5562 -- Is_Ref_To_Bit_Packed_Slice --
5563 --------------------------------
5565 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean is
5567 if Nkind
(N
) = N_Type_Conversion
then
5568 return Is_Ref_To_Bit_Packed_Slice
(Expression
(N
));
5570 elsif Is_Entity_Name
(N
)
5571 and then Is_Object
(Entity
(N
))
5572 and then Present
(Renamed_Object
(Entity
(N
)))
5574 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(N
)));
5576 elsif Nkind
(N
) = N_Slice
5577 and then Is_Bit_Packed_Array
(Etype
(Prefix
(N
)))
5581 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5582 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(N
));
5587 end Is_Ref_To_Bit_Packed_Slice
;
5589 -----------------------
5590 -- Is_Renamed_Object --
5591 -----------------------
5593 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
5594 Pnod
: constant Node_Id
:= Parent
(N
);
5595 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
5597 if Kind
= N_Object_Renaming_Declaration
then
5599 elsif Nkind_In
(Kind
, N_Indexed_Component
, N_Selected_Component
) then
5600 return Is_Renamed_Object
(Pnod
);
5604 end Is_Renamed_Object
;
5606 --------------------------------------
5607 -- Is_Secondary_Stack_BIP_Func_Call --
5608 --------------------------------------
5610 function Is_Secondary_Stack_BIP_Func_Call
(Expr
: Node_Id
) return Boolean is
5611 Alloc_Nam
: Name_Id
:= No_Name
;
5613 Call
: Node_Id
:= Expr
;
5618 -- Build-in-place calls usually appear in 'reference format. Note that
5619 -- the accessibility check machinery may add an extra 'reference due to
5620 -- side effect removal.
5622 while Nkind
(Call
) = N_Reference
loop
5623 Call
:= Prefix
(Call
);
5626 if Nkind_In
(Call
, N_Qualified_Expression
,
5627 N_Unchecked_Type_Conversion
)
5629 Call
:= Expression
(Call
);
5632 if Is_Build_In_Place_Function_Call
(Call
) then
5634 -- Examine all parameter associations of the function call
5636 Param
:= First
(Parameter_Associations
(Call
));
5637 while Present
(Param
) loop
5638 if Nkind
(Param
) = N_Parameter_Association
5639 and then Nkind
(Selector_Name
(Param
)) = N_Identifier
5641 Formal
:= Selector_Name
(Param
);
5642 Actual
:= Explicit_Actual_Parameter
(Param
);
5644 -- Construct the name of formal BIPalloc. It is much easier to
5645 -- extract the name of the function using an arbitrary formal's
5646 -- scope rather than the Name field of Call.
5648 if Alloc_Nam
= No_Name
and then Present
(Entity
(Formal
)) then
5651 (Chars
(Scope
(Entity
(Formal
))),
5652 BIP_Formal_Suffix
(BIP_Alloc_Form
));
5655 -- A match for BIPalloc => 2 has been found
5657 if Chars
(Formal
) = Alloc_Nam
5658 and then Nkind
(Actual
) = N_Integer_Literal
5659 and then Intval
(Actual
) = Uint_2
5670 end Is_Secondary_Stack_BIP_Func_Call
;
5672 -------------------------------------
5673 -- Is_Tag_To_Class_Wide_Conversion --
5674 -------------------------------------
5676 function Is_Tag_To_Class_Wide_Conversion
5677 (Obj_Id
: Entity_Id
) return Boolean
5679 Expr
: constant Node_Id
:= Expression
(Parent
(Obj_Id
));
5683 Is_Class_Wide_Type
(Etype
(Obj_Id
))
5684 and then Present
(Expr
)
5685 and then Nkind
(Expr
) = N_Unchecked_Type_Conversion
5686 and then Etype
(Expression
(Expr
)) = RTE
(RE_Tag
);
5687 end Is_Tag_To_Class_Wide_Conversion
;
5689 ----------------------------
5690 -- Is_Untagged_Derivation --
5691 ----------------------------
5693 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
5695 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
5697 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
5698 and then not Is_Tagged_Type
(Full_View
(T
))
5699 and then Is_Derived_Type
(Full_View
(T
))
5700 and then Etype
(Full_View
(T
)) /= T
);
5701 end Is_Untagged_Derivation
;
5703 ---------------------------
5704 -- Is_Volatile_Reference --
5705 ---------------------------
5707 function Is_Volatile_Reference
(N
: Node_Id
) return Boolean is
5709 -- Only source references are to be treated as volatile, internally
5710 -- generated stuff cannot have volatile external effects.
5712 if not Comes_From_Source
(N
) then
5715 -- Never true for reference to a type
5717 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
5720 -- Never true for a compile time known constant
5722 elsif Compile_Time_Known_Value
(N
) then
5725 -- True if object reference with volatile type
5727 elsif Is_Volatile_Object
(N
) then
5730 -- True if reference to volatile entity
5732 elsif Is_Entity_Name
(N
) then
5733 return Treat_As_Volatile
(Entity
(N
));
5735 -- True for slice of volatile array
5737 elsif Nkind
(N
) = N_Slice
then
5738 return Is_Volatile_Reference
(Prefix
(N
));
5740 -- True if volatile component
5742 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
5743 if (Is_Entity_Name
(Prefix
(N
))
5744 and then Has_Volatile_Components
(Entity
(Prefix
(N
))))
5745 or else (Present
(Etype
(Prefix
(N
)))
5746 and then Has_Volatile_Components
(Etype
(Prefix
(N
))))
5750 return Is_Volatile_Reference
(Prefix
(N
));
5758 end Is_Volatile_Reference
;
5760 --------------------------
5761 -- Is_VM_By_Copy_Actual --
5762 --------------------------
5764 function Is_VM_By_Copy_Actual
(N
: Node_Id
) return Boolean is
5766 return VM_Target
/= No_VM
5767 and then (Nkind
(N
) = N_Slice
5769 (Nkind
(N
) = N_Identifier
5770 and then Present
(Renamed_Object
(Entity
(N
)))
5771 and then Nkind
(Renamed_Object
(Entity
(N
))) =
5773 end Is_VM_By_Copy_Actual
;
5775 --------------------
5776 -- Kill_Dead_Code --
5777 --------------------
5779 procedure Kill_Dead_Code
(N
: Node_Id
; Warn
: Boolean := False) is
5780 W
: Boolean := Warn
;
5781 -- Set False if warnings suppressed
5785 Remove_Warning_Messages
(N
);
5787 -- Generate warning if appropriate
5791 -- We suppress the warning if this code is under control of an
5792 -- if statement, whose condition is a simple identifier, and
5793 -- either we are in an instance, or warnings off is set for this
5794 -- identifier. The reason for killing it in the instance case is
5795 -- that it is common and reasonable for code to be deleted in
5796 -- instances for various reasons.
5798 -- Could we use Is_Statically_Unevaluated here???
5800 if Nkind
(Parent
(N
)) = N_If_Statement
then
5802 C
: constant Node_Id
:= Condition
(Parent
(N
));
5804 if Nkind
(C
) = N_Identifier
5807 or else (Present
(Entity
(C
))
5808 and then Has_Warnings_Off
(Entity
(C
))))
5815 -- Generate warning if not suppressed
5819 ("?t?this code can never be executed and has been deleted!",
5824 -- Recurse into block statements and bodies to process declarations
5827 if Nkind
(N
) = N_Block_Statement
5828 or else Nkind
(N
) = N_Subprogram_Body
5829 or else Nkind
(N
) = N_Package_Body
5831 Kill_Dead_Code
(Declarations
(N
), False);
5832 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
5834 if Nkind
(N
) = N_Subprogram_Body
then
5835 Set_Is_Eliminated
(Defining_Entity
(N
));
5838 elsif Nkind
(N
) = N_Package_Declaration
then
5839 Kill_Dead_Code
(Visible_Declarations
(Specification
(N
)));
5840 Kill_Dead_Code
(Private_Declarations
(Specification
(N
)));
5842 -- ??? After this point, Delete_Tree has been called on all
5843 -- declarations in Specification (N), so references to entities
5844 -- therein look suspicious.
5847 E
: Entity_Id
:= First_Entity
(Defining_Entity
(N
));
5850 while Present
(E
) loop
5851 if Ekind
(E
) = E_Operator
then
5852 Set_Is_Eliminated
(E
);
5859 -- Recurse into composite statement to kill individual statements in
5860 -- particular instantiations.
5862 elsif Nkind
(N
) = N_If_Statement
then
5863 Kill_Dead_Code
(Then_Statements
(N
));
5864 Kill_Dead_Code
(Elsif_Parts
(N
));
5865 Kill_Dead_Code
(Else_Statements
(N
));
5867 elsif Nkind
(N
) = N_Loop_Statement
then
5868 Kill_Dead_Code
(Statements
(N
));
5870 elsif Nkind
(N
) = N_Case_Statement
then
5874 Alt
:= First
(Alternatives
(N
));
5875 while Present
(Alt
) loop
5876 Kill_Dead_Code
(Statements
(Alt
));
5881 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
5882 Kill_Dead_Code
(Statements
(N
));
5884 -- Deal with dead instances caused by deleting instantiations
5886 elsif Nkind
(N
) in N_Generic_Instantiation
then
5887 Remove_Dead_Instance
(N
);
5892 -- Case where argument is a list of nodes to be killed
5894 procedure Kill_Dead_Code
(L
: List_Id
; Warn
: Boolean := False) is
5901 if Is_Non_Empty_List
(L
) then
5903 while Present
(N
) loop
5904 Kill_Dead_Code
(N
, W
);
5911 ------------------------
5912 -- Known_Non_Negative --
5913 ------------------------
5915 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
5917 if Is_OK_Static_Expression
(Opnd
) and then Expr_Value
(Opnd
) >= 0 then
5922 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
5925 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
5928 end Known_Non_Negative
;
5930 --------------------
5931 -- Known_Non_Null --
5932 --------------------
5934 function Known_Non_Null
(N
: Node_Id
) return Boolean is
5936 -- Checks for case where N is an entity reference
5938 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5940 E
: constant Entity_Id
:= Entity
(N
);
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_Non_Null flag
5959 if OK_To_Do_Constant_Replacement
(E
) then
5960 return Is_Known_Non_Null
(E
);
5962 -- Otherwise if not safe to do replacement, then say so
5969 -- True if access attribute
5971 elsif Nkind
(N
) = N_Attribute_Reference
5972 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
5973 Name_Unchecked_Access
,
5974 Name_Unrestricted_Access
)
5978 -- True if allocator
5980 elsif Nkind
(N
) = N_Allocator
then
5983 -- For a conversion, true if expression is known non-null
5985 elsif Nkind
(N
) = N_Type_Conversion
then
5986 return Known_Non_Null
(Expression
(N
));
5988 -- Above are all cases where the value could be determined to be
5989 -- non-null. In all other cases, we don't know, so return False.
6000 function Known_Null
(N
: Node_Id
) return Boolean is
6002 -- Checks for case where N is an entity reference
6004 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
6006 E
: constant Entity_Id
:= Entity
(N
);
6011 -- Constant null value is for sure null
6013 if Ekind
(E
) = E_Constant
6014 and then Known_Null
(Constant_Value
(E
))
6019 -- First check if we are in decisive conditional
6021 Get_Current_Value_Condition
(N
, Op
, Val
);
6023 if Known_Null
(Val
) then
6024 if Op
= N_Op_Eq
then
6026 elsif Op
= N_Op_Ne
then
6031 -- If OK to do replacement, test Is_Known_Null flag
6033 if OK_To_Do_Constant_Replacement
(E
) then
6034 return Is_Known_Null
(E
);
6036 -- Otherwise if not safe to do replacement, then say so
6043 -- True if explicit reference to null
6045 elsif Nkind
(N
) = N_Null
then
6048 -- For a conversion, true if expression is known null
6050 elsif Nkind
(N
) = N_Type_Conversion
then
6051 return Known_Null
(Expression
(N
));
6053 -- Above are all cases where the value could be determined to be null.
6054 -- In all other cases, we don't know, so return False.
6061 -----------------------------
6062 -- Make_CW_Equivalent_Type --
6063 -----------------------------
6065 -- Create a record type used as an equivalent of any member of the class
6066 -- which takes its size from exp.
6068 -- Generate the following code:
6070 -- type Equiv_T is record
6071 -- _parent : T (List of discriminant constraints taken from Exp);
6072 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
6075 -- ??? Note that this type does not guarantee same alignment as all
6078 function Make_CW_Equivalent_Type
6080 E
: Node_Id
) return Entity_Id
6082 Loc
: constant Source_Ptr
:= Sloc
(E
);
6083 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
6084 List_Def
: constant List_Id
:= Empty_List
;
6085 Comp_List
: constant List_Id
:= New_List
;
6086 Equiv_Type
: Entity_Id
;
6087 Range_Type
: Entity_Id
;
6088 Str_Type
: Entity_Id
;
6089 Constr_Root
: Entity_Id
;
6093 -- If the root type is already constrained, there are no discriminants
6094 -- in the expression.
6096 if not Has_Discriminants
(Root_Typ
)
6097 or else Is_Constrained
(Root_Typ
)
6099 Constr_Root
:= Root_Typ
;
6101 -- At this point in the expansion, non-limited view of the type
6102 -- must be available, otherwise the error will be reported later.
6104 if From_Limited_With
(Constr_Root
)
6105 and then Present
(Non_Limited_View
(Constr_Root
))
6107 Constr_Root
:= Non_Limited_View
(Constr_Root
);
6111 Constr_Root
:= Make_Temporary
(Loc
, 'R');
6113 -- subtype cstr__n is T (List of discr constraints taken from Exp)
6115 Append_To
(List_Def
,
6116 Make_Subtype_Declaration
(Loc
,
6117 Defining_Identifier
=> Constr_Root
,
6118 Subtype_Indication
=> Make_Subtype_From_Expr
(E
, Root_Typ
)));
6121 -- Generate the range subtype declaration
6123 Range_Type
:= Make_Temporary
(Loc
, 'G');
6125 if not Is_Interface
(Root_Typ
) then
6127 -- subtype rg__xx is
6128 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
6131 Make_Op_Subtract
(Loc
,
6133 Make_Attribute_Reference
(Loc
,
6135 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
6136 Attribute_Name
=> Name_Size
),
6138 Make_Attribute_Reference
(Loc
,
6139 Prefix
=> New_Occurrence_Of
(Constr_Root
, Loc
),
6140 Attribute_Name
=> Name_Object_Size
));
6142 -- subtype rg__xx is
6143 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
6146 Make_Attribute_Reference
(Loc
,
6148 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
6149 Attribute_Name
=> Name_Size
);
6152 Set_Paren_Count
(Sizexpr
, 1);
6154 Append_To
(List_Def
,
6155 Make_Subtype_Declaration
(Loc
,
6156 Defining_Identifier
=> Range_Type
,
6157 Subtype_Indication
=>
6158 Make_Subtype_Indication
(Loc
,
6159 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
6160 Constraint
=> Make_Range_Constraint
(Loc
,
6163 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6165 Make_Op_Divide
(Loc
,
6166 Left_Opnd
=> Sizexpr
,
6167 Right_Opnd
=> Make_Integer_Literal
(Loc
,
6168 Intval
=> System_Storage_Unit
)))))));
6170 -- subtype str__nn is Storage_Array (rg__x);
6172 Str_Type
:= Make_Temporary
(Loc
, 'S');
6173 Append_To
(List_Def
,
6174 Make_Subtype_Declaration
(Loc
,
6175 Defining_Identifier
=> Str_Type
,
6176 Subtype_Indication
=>
6177 Make_Subtype_Indication
(Loc
,
6178 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
6180 Make_Index_Or_Discriminant_Constraint
(Loc
,
6182 New_List
(New_Occurrence_Of
(Range_Type
, Loc
))))));
6184 -- type Equiv_T is record
6185 -- [ _parent : Tnn; ]
6189 Equiv_Type
:= Make_Temporary
(Loc
, 'T');
6190 Set_Ekind
(Equiv_Type
, E_Record_Type
);
6191 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
6193 -- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
6194 -- treatment for this type. In particular, even though _parent's type
6195 -- is a controlled type or contains controlled components, we do not
6196 -- want to set Has_Controlled_Component on it to avoid making it gain
6197 -- an unwanted _controller component.
6199 Set_Is_Class_Wide_Equivalent_Type
(Equiv_Type
);
6201 -- A class-wide equivalent type does not require initialization
6203 Set_Suppress_Initialization
(Equiv_Type
);
6205 if not Is_Interface
(Root_Typ
) then
6206 Append_To
(Comp_List
,
6207 Make_Component_Declaration
(Loc
,
6208 Defining_Identifier
=>
6209 Make_Defining_Identifier
(Loc
, Name_uParent
),
6210 Component_Definition
=>
6211 Make_Component_Definition
(Loc
,
6212 Aliased_Present
=> False,
6213 Subtype_Indication
=> New_Occurrence_Of
(Constr_Root
, Loc
))));
6216 Append_To
(Comp_List
,
6217 Make_Component_Declaration
(Loc
,
6218 Defining_Identifier
=> Make_Temporary
(Loc
, 'C'),
6219 Component_Definition
=>
6220 Make_Component_Definition
(Loc
,
6221 Aliased_Present
=> False,
6222 Subtype_Indication
=> New_Occurrence_Of
(Str_Type
, Loc
))));
6224 Append_To
(List_Def
,
6225 Make_Full_Type_Declaration
(Loc
,
6226 Defining_Identifier
=> Equiv_Type
,
6228 Make_Record_Definition
(Loc
,
6230 Make_Component_List
(Loc
,
6231 Component_Items
=> Comp_List
,
6232 Variant_Part
=> Empty
))));
6234 -- Suppress all checks during the analysis of the expanded code to avoid
6235 -- the generation of spurious warnings under ZFP run-time.
6237 Insert_Actions
(E
, List_Def
, Suppress
=> All_Checks
);
6239 end Make_CW_Equivalent_Type
;
6241 -------------------------
6242 -- Make_Invariant_Call --
6243 -------------------------
6245 function Make_Invariant_Call
(Expr
: Node_Id
) return Node_Id
is
6246 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6250 Typ
:= Etype
(Expr
);
6252 -- Subtypes may be subject to invariants coming from their respective
6253 -- base types. The subtype may be fully or partially private.
6255 if Ekind_In
(Typ
, E_Array_Subtype
,
6258 E_Record_Subtype_With_Private
)
6260 Typ
:= Base_Type
(Typ
);
6264 (Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)));
6267 Make_Procedure_Call_Statement
(Loc
,
6269 New_Occurrence_Of
(Invariant_Procedure
(Typ
), Loc
),
6270 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6271 end Make_Invariant_Call
;
6273 ------------------------
6274 -- Make_Literal_Range --
6275 ------------------------
6277 function Make_Literal_Range
6279 Literal_Typ
: Entity_Id
) return Node_Id
6281 Lo
: constant Node_Id
:=
6282 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
6283 Index
: constant Entity_Id
:= Etype
(Lo
);
6286 Length_Expr
: constant Node_Id
:=
6287 Make_Op_Subtract
(Loc
,
6289 Make_Integer_Literal
(Loc
,
6290 Intval
=> String_Literal_Length
(Literal_Typ
)),
6292 Make_Integer_Literal
(Loc
, 1));
6295 Set_Analyzed
(Lo
, False);
6297 if Is_Integer_Type
(Index
) then
6300 Left_Opnd
=> New_Copy_Tree
(Lo
),
6301 Right_Opnd
=> Length_Expr
);
6304 Make_Attribute_Reference
(Loc
,
6305 Attribute_Name
=> Name_Val
,
6306 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
6307 Expressions
=> New_List
(
6310 Make_Attribute_Reference
(Loc
,
6311 Attribute_Name
=> Name_Pos
,
6312 Prefix
=> New_Occurrence_Of
(Index
, Loc
),
6313 Expressions
=> New_List
(New_Copy_Tree
(Lo
))),
6314 Right_Opnd
=> Length_Expr
)));
6321 end Make_Literal_Range
;
6323 --------------------------
6324 -- Make_Non_Empty_Check --
6325 --------------------------
6327 function Make_Non_Empty_Check
6329 N
: Node_Id
) return Node_Id
6335 Make_Attribute_Reference
(Loc
,
6336 Attribute_Name
=> Name_Length
,
6337 Prefix
=> Duplicate_Subexpr_No_Checks
(N
, Name_Req
=> True)),
6339 Make_Integer_Literal
(Loc
, 0));
6340 end Make_Non_Empty_Check
;
6342 -------------------------
6343 -- Make_Predicate_Call --
6344 -------------------------
6346 function Make_Predicate_Call
6349 Mem
: Boolean := False) return Node_Id
6351 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6354 pragma Assert
(Present
(Predicate_Function
(Typ
)));
6356 -- Call special membership version if requested and available
6360 PFM
: constant Entity_Id
:= Predicate_Function_M
(Typ
);
6362 if Present
(PFM
) then
6364 Make_Function_Call
(Loc
,
6365 Name
=> New_Occurrence_Of
(PFM
, Loc
),
6366 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6371 -- Case of calling normal predicate function
6374 Make_Function_Call
(Loc
,
6376 New_Occurrence_Of
(Predicate_Function
(Typ
), Loc
),
6377 Parameter_Associations
=> New_List
(Relocate_Node
(Expr
)));
6378 end Make_Predicate_Call
;
6380 --------------------------
6381 -- Make_Predicate_Check --
6382 --------------------------
6384 function Make_Predicate_Check
6386 Expr
: Node_Id
) return Node_Id
6388 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6392 -- If predicate checks are suppressed, then return a null statement.
6393 -- For this call, we check only the scope setting. If the caller wants
6394 -- to check a specific entity's setting, they must do it manually.
6396 if Predicate_Checks_Suppressed
(Empty
) then
6397 return Make_Null_Statement
(Loc
);
6400 -- Do not generate a check within an internal subprogram (stream
6401 -- functions and the like, including including predicate functions).
6403 if Within_Internal_Subprogram
then
6404 return Make_Null_Statement
(Loc
);
6407 -- Compute proper name to use, we need to get this right so that the
6408 -- right set of check policies apply to the Check pragma we are making.
6410 if Has_Dynamic_Predicate_Aspect
(Typ
) then
6411 Nam
:= Name_Dynamic_Predicate
;
6412 elsif Has_Static_Predicate_Aspect
(Typ
) then
6413 Nam
:= Name_Static_Predicate
;
6415 Nam
:= Name_Predicate
;
6420 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Check
),
6421 Pragma_Argument_Associations
=> New_List
(
6422 Make_Pragma_Argument_Association
(Loc
,
6423 Expression
=> Make_Identifier
(Loc
, Nam
)),
6424 Make_Pragma_Argument_Association
(Loc
,
6425 Expression
=> Make_Predicate_Call
(Typ
, Expr
))));
6426 end Make_Predicate_Check
;
6428 ----------------------------
6429 -- Make_Subtype_From_Expr --
6430 ----------------------------
6432 -- 1. If Expr is an unconstrained array expression, creates
6433 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
6435 -- 2. If Expr is a unconstrained discriminated type expression, creates
6436 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
6438 -- 3. If Expr is class-wide, creates an implicit class-wide subtype
6440 function Make_Subtype_From_Expr
6442 Unc_Typ
: Entity_Id
) return Node_Id
6444 List_Constr
: constant List_Id
:= New_List
;
6445 Loc
: constant Source_Ptr
:= Sloc
(E
);
6448 Full_Subtyp
: Entity_Id
;
6449 High_Bound
: Entity_Id
;
6450 Index_Typ
: Entity_Id
;
6451 Low_Bound
: Entity_Id
;
6452 Priv_Subtyp
: Entity_Id
;
6456 if Is_Private_Type
(Unc_Typ
)
6457 and then Has_Unknown_Discriminants
(Unc_Typ
)
6459 -- Prepare the subtype completion. Use the base type to find the
6460 -- underlying type because the type may be a generic actual or an
6461 -- explicit subtype.
6463 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
6464 Full_Subtyp
:= Make_Temporary
(Loc
, 'C');
6466 Unchecked_Convert_To
(Utyp
, Duplicate_Subexpr_No_Checks
(E
));
6467 Set_Parent
(Full_Exp
, Parent
(E
));
6469 Priv_Subtyp
:= Make_Temporary
(Loc
, 'P');
6472 Make_Subtype_Declaration
(Loc
,
6473 Defining_Identifier
=> Full_Subtyp
,
6474 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
6476 -- Define the dummy private subtype
6478 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
6479 Set_Etype
(Priv_Subtyp
, Base_Type
(Unc_Typ
));
6480 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
6481 Set_Is_Constrained
(Priv_Subtyp
);
6482 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
6483 Set_Is_Itype
(Priv_Subtyp
);
6484 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
6486 if Is_Tagged_Type
(Priv_Subtyp
) then
6488 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
6489 Set_Direct_Primitive_Operations
(Priv_Subtyp
,
6490 Direct_Primitive_Operations
(Unc_Typ
));
6493 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
6495 return New_Occurrence_Of
(Priv_Subtyp
, Loc
);
6497 elsif Is_Array_Type
(Unc_Typ
) then
6498 Index_Typ
:= First_Index
(Unc_Typ
);
6499 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
6501 -- Capture the bounds of each index constraint in case the context
6502 -- is an object declaration of an unconstrained type initialized
6503 -- by a function call:
6505 -- Obj : Unconstr_Typ := Func_Call;
6507 -- This scenario requires secondary scope management and the index
6508 -- constraint cannot depend on the temporary used to capture the
6509 -- result of the function call.
6512 -- Temp : Unconstr_Typ_Ptr := Func_Call'reference;
6513 -- subtype S is Unconstr_Typ (Temp.all'First .. Temp.all'Last);
6514 -- Obj : S := Temp.all;
6515 -- SS_Release; -- Temp is gone at this point, bounds of S are
6519 -- Low_Bound : constant Base_Type (Index_Typ) := E'First (J);
6521 Low_Bound
:= Make_Temporary
(Loc
, 'B');
6523 Make_Object_Declaration
(Loc
,
6524 Defining_Identifier
=> Low_Bound
,
6525 Object_Definition
=>
6526 New_Occurrence_Of
(Base_Type
(Etype
(Index_Typ
)), Loc
),
6527 Constant_Present
=> True,
6529 Make_Attribute_Reference
(Loc
,
6530 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6531 Attribute_Name
=> Name_First
,
6532 Expressions
=> New_List
(
6533 Make_Integer_Literal
(Loc
, J
)))));
6536 -- High_Bound : constant Base_Type (Index_Typ) := E'Last (J);
6538 High_Bound
:= Make_Temporary
(Loc
, 'B');
6540 Make_Object_Declaration
(Loc
,
6541 Defining_Identifier
=> High_Bound
,
6542 Object_Definition
=>
6543 New_Occurrence_Of
(Base_Type
(Etype
(Index_Typ
)), Loc
),
6544 Constant_Present
=> True,
6546 Make_Attribute_Reference
(Loc
,
6547 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6548 Attribute_Name
=> Name_Last
,
6549 Expressions
=> New_List
(
6550 Make_Integer_Literal
(Loc
, J
)))));
6552 Append_To
(List_Constr
,
6554 Low_Bound
=> New_Occurrence_Of
(Low_Bound
, Loc
),
6555 High_Bound
=> New_Occurrence_Of
(High_Bound
, Loc
)));
6557 Index_Typ
:= Next_Index
(Index_Typ
);
6560 elsif Is_Class_Wide_Type
(Unc_Typ
) then
6562 CW_Subtype
: Entity_Id
;
6563 EQ_Typ
: Entity_Id
:= Empty
;
6566 -- A class-wide equivalent type is not needed when VM_Target
6567 -- because the VM back-ends handle the class-wide object
6568 -- initialization itself (and doesn't need or want the
6569 -- additional intermediate type to handle the assignment).
6571 if Expander_Active
and then Tagged_Type_Expansion
then
6573 -- If this is the class-wide type of a completion that is a
6574 -- record subtype, set the type of the class-wide type to be
6575 -- the full base type, for use in the expanded code for the
6576 -- equivalent type. Should this be done earlier when the
6577 -- completion is analyzed ???
6579 if Is_Private_Type
(Etype
(Unc_Typ
))
6581 Ekind
(Full_View
(Etype
(Unc_Typ
))) = E_Record_Subtype
6583 Set_Etype
(Unc_Typ
, Base_Type
(Full_View
(Etype
(Unc_Typ
))));
6586 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
6589 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
6590 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
6591 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
6593 return New_Occurrence_Of
(CW_Subtype
, Loc
);
6596 -- Indefinite record type with discriminants
6599 D
:= First_Discriminant
(Unc_Typ
);
6600 while Present
(D
) loop
6601 Append_To
(List_Constr
,
6602 Make_Selected_Component
(Loc
,
6603 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
6604 Selector_Name
=> New_Occurrence_Of
(D
, Loc
)));
6606 Next_Discriminant
(D
);
6611 Make_Subtype_Indication
(Loc
,
6612 Subtype_Mark
=> New_Occurrence_Of
(Unc_Typ
, Loc
),
6614 Make_Index_Or_Discriminant_Constraint
(Loc
,
6615 Constraints
=> List_Constr
));
6616 end Make_Subtype_From_Expr
;
6618 ----------------------------
6619 -- Matching_Standard_Type --
6620 ----------------------------
6622 function Matching_Standard_Type
(Typ
: Entity_Id
) return Entity_Id
is
6623 pragma Assert
(Is_Scalar_Type
(Typ
));
6624 Siz
: constant Uint
:= Esize
(Typ
);
6627 -- Floating-point cases
6629 if Is_Floating_Point_Type
(Typ
) then
6630 if Siz
<= Esize
(Standard_Short_Float
) then
6631 return Standard_Short_Float
;
6632 elsif Siz
<= Esize
(Standard_Float
) then
6633 return Standard_Float
;
6634 elsif Siz
<= Esize
(Standard_Long_Float
) then
6635 return Standard_Long_Float
;
6636 elsif Siz
<= Esize
(Standard_Long_Long_Float
) then
6637 return Standard_Long_Long_Float
;
6639 raise Program_Error
;
6642 -- Integer cases (includes fixed-point types)
6644 -- Unsigned integer cases (includes normal enumeration types)
6646 elsif Is_Unsigned_Type
(Typ
) then
6647 if Siz
<= Esize
(Standard_Short_Short_Unsigned
) then
6648 return Standard_Short_Short_Unsigned
;
6649 elsif Siz
<= Esize
(Standard_Short_Unsigned
) then
6650 return Standard_Short_Unsigned
;
6651 elsif Siz
<= Esize
(Standard_Unsigned
) then
6652 return Standard_Unsigned
;
6653 elsif Siz
<= Esize
(Standard_Long_Unsigned
) then
6654 return Standard_Long_Unsigned
;
6655 elsif Siz
<= Esize
(Standard_Long_Long_Unsigned
) then
6656 return Standard_Long_Long_Unsigned
;
6658 raise Program_Error
;
6661 -- Signed integer cases
6664 if Siz
<= Esize
(Standard_Short_Short_Integer
) then
6665 return Standard_Short_Short_Integer
;
6666 elsif Siz
<= Esize
(Standard_Short_Integer
) then
6667 return Standard_Short_Integer
;
6668 elsif Siz
<= Esize
(Standard_Integer
) then
6669 return Standard_Integer
;
6670 elsif Siz
<= Esize
(Standard_Long_Integer
) then
6671 return Standard_Long_Integer
;
6672 elsif Siz
<= Esize
(Standard_Long_Long_Integer
) then
6673 return Standard_Long_Long_Integer
;
6675 raise Program_Error
;
6678 end Matching_Standard_Type
;
6680 -----------------------------
6681 -- May_Generate_Large_Temp --
6682 -----------------------------
6684 -- At the current time, the only types that we return False for (i.e. where
6685 -- we decide we know they cannot generate large temps) are ones where we
6686 -- know the size is 256 bits or less at compile time, and we are still not
6687 -- doing a thorough job on arrays and records ???
6689 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
6691 if not Size_Known_At_Compile_Time
(Typ
) then
6694 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
6697 elsif Is_Array_Type
(Typ
)
6698 and then Present
(Packed_Array_Impl_Type
(Typ
))
6700 return May_Generate_Large_Temp
(Packed_Array_Impl_Type
(Typ
));
6702 -- We could do more here to find other small types ???
6707 end May_Generate_Large_Temp
;
6709 ------------------------
6710 -- Needs_Finalization --
6711 ------------------------
6713 function Needs_Finalization
(T
: Entity_Id
) return Boolean is
6714 function Has_Some_Controlled_Component
(Rec
: Entity_Id
) return Boolean;
6715 -- If type is not frozen yet, check explicitly among its components,
6716 -- because the Has_Controlled_Component flag is not necessarily set.
6718 -----------------------------------
6719 -- Has_Some_Controlled_Component --
6720 -----------------------------------
6722 function Has_Some_Controlled_Component
6723 (Rec
: Entity_Id
) return Boolean
6728 if Has_Controlled_Component
(Rec
) then
6731 elsif not Is_Frozen
(Rec
) then
6732 if Is_Record_Type
(Rec
) then
6733 Comp
:= First_Entity
(Rec
);
6735 while Present
(Comp
) loop
6736 if not Is_Type
(Comp
)
6737 and then Needs_Finalization
(Etype
(Comp
))
6747 elsif Is_Array_Type
(Rec
) then
6748 return Needs_Finalization
(Component_Type
(Rec
));
6751 return Has_Controlled_Component
(Rec
);
6756 end Has_Some_Controlled_Component
;
6758 -- Start of processing for Needs_Finalization
6761 -- Certain run-time configurations and targets do not provide support
6762 -- for controlled types.
6764 if Restriction_Active
(No_Finalization
) then
6767 -- C++, CIL and Java types are not considered controlled. It is assumed
6768 -- that the non-Ada side will handle their clean up.
6770 elsif Convention
(T
) = Convention_CIL
6771 or else Convention
(T
) = Convention_CPP
6772 or else Convention
(T
) = Convention_Java
6777 -- Class-wide types are treated as controlled because derivations
6778 -- from the root type can introduce controlled components.
6781 Is_Class_Wide_Type
(T
)
6782 or else Is_Controlled
(T
)
6783 or else Has_Controlled_Component
(T
)
6784 or else Has_Some_Controlled_Component
(T
)
6786 (Is_Concurrent_Type
(T
)
6787 and then Present
(Corresponding_Record_Type
(T
))
6788 and then Needs_Finalization
(Corresponding_Record_Type
(T
)));
6790 end Needs_Finalization
;
6792 ----------------------------
6793 -- Needs_Constant_Address --
6794 ----------------------------
6796 function Needs_Constant_Address
6798 Typ
: Entity_Id
) return Boolean
6802 -- If we have no initialization of any kind, then we don't need to place
6803 -- any restrictions on the address clause, because the object will be
6804 -- elaborated after the address clause is evaluated. This happens if the
6805 -- declaration has no initial expression, or the type has no implicit
6806 -- initialization, or the object is imported.
6808 -- The same holds for all initialized scalar types and all access types.
6809 -- Packed bit arrays of size up to 64 are represented using a modular
6810 -- type with an initialization (to zero) and can be processed like other
6811 -- initialized scalar types.
6813 -- If the type is controlled, code to attach the object to a
6814 -- finalization chain is generated at the point of declaration, and
6815 -- therefore the elaboration of the object cannot be delayed: the
6816 -- address expression must be a constant.
6818 if No
(Expression
(Decl
))
6819 and then not Needs_Finalization
(Typ
)
6821 (not Has_Non_Null_Base_Init_Proc
(Typ
)
6822 or else Is_Imported
(Defining_Identifier
(Decl
)))
6826 elsif (Present
(Expression
(Decl
)) and then Is_Scalar_Type
(Typ
))
6827 or else Is_Access_Type
(Typ
)
6829 (Is_Bit_Packed_Array
(Typ
)
6830 and then Is_Modular_Integer_Type
(Packed_Array_Impl_Type
(Typ
)))
6836 -- Otherwise, we require the address clause to be constant because
6837 -- the call to the initialization procedure (or the attach code) has
6838 -- to happen at the point of the declaration.
6840 -- Actually the IP call has been moved to the freeze actions anyway,
6841 -- so maybe we can relax this restriction???
6845 end Needs_Constant_Address
;
6847 ----------------------------
6848 -- New_Class_Wide_Subtype --
6849 ----------------------------
6851 function New_Class_Wide_Subtype
6852 (CW_Typ
: Entity_Id
;
6853 N
: Node_Id
) return Entity_Id
6855 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
6856 Res_Name
: constant Name_Id
:= Chars
(Res
);
6857 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
6860 Copy_Node
(CW_Typ
, Res
);
6861 Set_Comes_From_Source
(Res
, False);
6862 Set_Sloc
(Res
, Sloc
(N
));
6864 Set_Associated_Node_For_Itype
(Res
, N
);
6865 Set_Is_Public
(Res
, False); -- By default, may be changed below.
6866 Set_Public_Status
(Res
);
6867 Set_Chars
(Res
, Res_Name
);
6868 Set_Scope
(Res
, Res_Scope
);
6869 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
6870 Set_Next_Entity
(Res
, Empty
);
6871 Set_Etype
(Res
, Base_Type
(CW_Typ
));
6872 Set_Is_Frozen
(Res
, False);
6873 Set_Freeze_Node
(Res
, Empty
);
6875 end New_Class_Wide_Subtype
;
6877 --------------------------------
6878 -- Non_Limited_Designated_Type --
6879 ---------------------------------
6881 function Non_Limited_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
6882 Desig
: constant Entity_Id
:= Designated_Type
(T
);
6884 if Has_Non_Limited_View
(Desig
) then
6885 return Non_Limited_View
(Desig
);
6889 end Non_Limited_Designated_Type
;
6891 -----------------------------------
6892 -- OK_To_Do_Constant_Replacement --
6893 -----------------------------------
6895 function OK_To_Do_Constant_Replacement
(E
: Entity_Id
) return Boolean is
6896 ES
: constant Entity_Id
:= Scope
(E
);
6900 -- Do not replace statically allocated objects, because they may be
6901 -- modified outside the current scope.
6903 if Is_Statically_Allocated
(E
) then
6906 -- Do not replace aliased or volatile objects, since we don't know what
6907 -- else might change the value.
6909 elsif Is_Aliased
(E
) or else Treat_As_Volatile
(E
) then
6912 -- Debug flag -gnatdM disconnects this optimization
6914 elsif Debug_Flag_MM
then
6917 -- Otherwise check scopes
6920 CS
:= Current_Scope
;
6923 -- If we are in right scope, replacement is safe
6928 -- Packages do not affect the determination of safety
6930 elsif Ekind
(CS
) = E_Package
then
6931 exit when CS
= Standard_Standard
;
6934 -- Blocks do not affect the determination of safety
6936 elsif Ekind
(CS
) = E_Block
then
6939 -- Loops do not affect the determination of safety. Note that we
6940 -- kill all current values on entry to a loop, so we are just
6941 -- talking about processing within a loop here.
6943 elsif Ekind
(CS
) = E_Loop
then
6946 -- Otherwise, the reference is dubious, and we cannot be sure that
6947 -- it is safe to do the replacement.
6956 end OK_To_Do_Constant_Replacement
;
6958 ------------------------------------
6959 -- Possible_Bit_Aligned_Component --
6960 ------------------------------------
6962 function Possible_Bit_Aligned_Component
(N
: Node_Id
) return Boolean is
6964 -- Do not process an unanalyzed node because it is not yet decorated and
6965 -- most checks performed below will fail.
6967 if not Analyzed
(N
) then
6973 -- Case of indexed component
6975 when N_Indexed_Component
=>
6977 P
: constant Node_Id
:= Prefix
(N
);
6978 Ptyp
: constant Entity_Id
:= Etype
(P
);
6981 -- If we know the component size and it is less than 64, then
6982 -- we are definitely OK. The back end always does assignment of
6983 -- misaligned small objects correctly.
6985 if Known_Static_Component_Size
(Ptyp
)
6986 and then Component_Size
(Ptyp
) <= 64
6990 -- Otherwise, we need to test the prefix, to see if we are
6991 -- indexing from a possibly unaligned component.
6994 return Possible_Bit_Aligned_Component
(P
);
6998 -- Case of selected component
7000 when N_Selected_Component
=>
7002 P
: constant Node_Id
:= Prefix
(N
);
7003 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
7006 -- If there is no component clause, then we are in the clear
7007 -- since the back end will never misalign a large component
7008 -- unless it is forced to do so. In the clear means we need
7009 -- only the recursive test on the prefix.
7011 if Component_May_Be_Bit_Aligned
(Comp
) then
7014 return Possible_Bit_Aligned_Component
(P
);
7018 -- For a slice, test the prefix, if that is possibly misaligned,
7019 -- then for sure the slice is.
7022 return Possible_Bit_Aligned_Component
(Prefix
(N
));
7024 -- For an unchecked conversion, check whether the expression may
7027 when N_Unchecked_Type_Conversion
=>
7028 return Possible_Bit_Aligned_Component
(Expression
(N
));
7030 -- If we have none of the above, it means that we have fallen off the
7031 -- top testing prefixes recursively, and we now have a stand alone
7032 -- object, where we don't have a problem, unless this is a renaming,
7033 -- in which case we need to look into the renamed object.
7036 if Is_Entity_Name
(N
)
7037 and then Present
(Renamed_Object
(Entity
(N
)))
7040 Possible_Bit_Aligned_Component
(Renamed_Object
(Entity
(N
)));
7046 end Possible_Bit_Aligned_Component
;
7048 -----------------------------------------------
7049 -- Process_Statements_For_Controlled_Objects --
7050 -----------------------------------------------
7052 procedure Process_Statements_For_Controlled_Objects
(N
: Node_Id
) is
7053 Loc
: constant Source_Ptr
:= Sloc
(N
);
7055 function Are_Wrapped
(L
: List_Id
) return Boolean;
7056 -- Determine whether list L contains only one statement which is a block
7058 function Wrap_Statements_In_Block
7060 Scop
: Entity_Id
:= Current_Scope
) return Node_Id
;
7061 -- Given a list of statements L, wrap it in a block statement and return
7062 -- the generated node. Scop is either the current scope or the scope of
7063 -- the context (if applicable).
7069 function Are_Wrapped
(L
: List_Id
) return Boolean is
7070 Stmt
: constant Node_Id
:= First
(L
);
7074 and then No
(Next
(Stmt
))
7075 and then Nkind
(Stmt
) = N_Block_Statement
;
7078 ------------------------------
7079 -- Wrap_Statements_In_Block --
7080 ------------------------------
7082 function Wrap_Statements_In_Block
7084 Scop
: Entity_Id
:= Current_Scope
) return Node_Id
7086 Block_Id
: Entity_Id
;
7087 Block_Nod
: Node_Id
;
7088 Iter_Loop
: Entity_Id
;
7092 Make_Block_Statement
(Loc
,
7093 Declarations
=> No_List
,
7094 Handled_Statement_Sequence
=>
7095 Make_Handled_Sequence_Of_Statements
(Loc
,
7098 -- Create a label for the block in case the block needs to manage the
7099 -- secondary stack. A label allows for flag Uses_Sec_Stack to be set.
7101 Add_Block_Identifier
(Block_Nod
, Block_Id
);
7103 -- When wrapping the statements of an iterator loop, check whether
7104 -- the loop requires secondary stack management and if so, propagate
7105 -- the appropriate flags to the block. This ensures that the cursor
7106 -- is properly cleaned up at each iteration of the loop.
7108 Iter_Loop
:= Find_Enclosing_Iterator_Loop
(Scop
);
7110 if Present
(Iter_Loop
) then
7111 Set_Uses_Sec_Stack
(Block_Id
, Uses_Sec_Stack
(Iter_Loop
));
7113 -- Secondary stack reclamation is suppressed when the associated
7114 -- iterator loop contains a return statement which uses the stack.
7116 Set_Sec_Stack_Needed_For_Return
7117 (Block_Id
, Sec_Stack_Needed_For_Return
(Iter_Loop
));
7121 end Wrap_Statements_In_Block
;
7127 -- Start of processing for Process_Statements_For_Controlled_Objects
7130 -- Whenever a non-handled statement list is wrapped in a block, the
7131 -- block must be explicitly analyzed to redecorate all entities in the
7132 -- list and ensure that a finalizer is properly built.
7137 N_Conditional_Entry_Call |
7138 N_Selective_Accept
=>
7140 -- Check the "then statements" for elsif parts and if statements
7142 if Nkind_In
(N
, N_Elsif_Part
, N_If_Statement
)
7143 and then not Is_Empty_List
(Then_Statements
(N
))
7144 and then not Are_Wrapped
(Then_Statements
(N
))
7145 and then Requires_Cleanup_Actions
7146 (Then_Statements
(N
), False, False)
7148 Block
:= Wrap_Statements_In_Block
(Then_Statements
(N
));
7149 Set_Then_Statements
(N
, New_List
(Block
));
7154 -- Check the "else statements" for conditional entry calls, if
7155 -- statements and selective accepts.
7157 if Nkind_In
(N
, N_Conditional_Entry_Call
,
7160 and then not Is_Empty_List
(Else_Statements
(N
))
7161 and then not Are_Wrapped
(Else_Statements
(N
))
7162 and then Requires_Cleanup_Actions
7163 (Else_Statements
(N
), False, False)
7165 Block
:= Wrap_Statements_In_Block
(Else_Statements
(N
));
7166 Set_Else_Statements
(N
, New_List
(Block
));
7171 when N_Abortable_Part |
7172 N_Accept_Alternative |
7173 N_Case_Statement_Alternative |
7174 N_Delay_Alternative |
7175 N_Entry_Call_Alternative |
7176 N_Exception_Handler |
7178 N_Triggering_Alternative
=>
7180 if not Is_Empty_List
(Statements
(N
))
7181 and then not Are_Wrapped
(Statements
(N
))
7182 and then Requires_Cleanup_Actions
(Statements
(N
), False, False)
7184 if Nkind
(N
) = N_Loop_Statement
7185 and then Present
(Identifier
(N
))
7188 Wrap_Statements_In_Block
7189 (L
=> Statements
(N
),
7190 Scop
=> Entity
(Identifier
(N
)));
7192 Block
:= Wrap_Statements_In_Block
(Statements
(N
));
7195 Set_Statements
(N
, New_List
(Block
));
7202 end Process_Statements_For_Controlled_Objects
;
7208 function Power_Of_Two
(N
: Node_Id
) return Nat
is
7209 Typ
: constant Entity_Id
:= Etype
(N
);
7210 pragma Assert
(Is_Integer_Type
(Typ
));
7212 Siz
: constant Nat
:= UI_To_Int
(Esize
(Typ
));
7216 if not Compile_Time_Known_Value
(N
) then
7220 Val
:= Expr_Value
(N
);
7221 for J
in 1 .. Siz
- 1 loop
7222 if Val
= Uint_2
** J
then
7231 ----------------------
7232 -- Remove_Init_Call --
7233 ----------------------
7235 function Remove_Init_Call
7237 Rep_Clause
: Node_Id
) return Node_Id
7239 Par
: constant Node_Id
:= Parent
(Var
);
7240 Typ
: constant Entity_Id
:= Etype
(Var
);
7242 Init_Proc
: Entity_Id
;
7243 -- Initialization procedure for Typ
7245 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
;
7246 -- Look for init call for Var starting at From and scanning the
7247 -- enclosing list until Rep_Clause or the end of the list is reached.
7249 ----------------------------
7250 -- Find_Init_Call_In_List --
7251 ----------------------------
7253 function Find_Init_Call_In_List
(From
: Node_Id
) return Node_Id
is
7254 Init_Call
: Node_Id
;
7258 while Present
(Init_Call
) and then Init_Call
/= Rep_Clause
loop
7259 if Nkind
(Init_Call
) = N_Procedure_Call_Statement
7260 and then Is_Entity_Name
(Name
(Init_Call
))
7261 and then Entity
(Name
(Init_Call
)) = Init_Proc
7270 end Find_Init_Call_In_List
;
7272 Init_Call
: Node_Id
;
7274 -- Start of processing for Find_Init_Call
7277 if Present
(Initialization_Statements
(Var
)) then
7278 Init_Call
:= Initialization_Statements
(Var
);
7279 Set_Initialization_Statements
(Var
, Empty
);
7281 elsif not Has_Non_Null_Base_Init_Proc
(Typ
) then
7283 -- No init proc for the type, so obviously no call to be found
7288 -- We might be able to handle other cases below by just properly
7289 -- setting Initialization_Statements at the point where the init proc
7290 -- call is generated???
7292 Init_Proc
:= Base_Init_Proc
(Typ
);
7294 -- First scan the list containing the declaration of Var
7296 Init_Call
:= Find_Init_Call_In_List
(From
=> Next
(Par
));
7298 -- If not found, also look on Var's freeze actions list, if any,
7299 -- since the init call may have been moved there (case of an address
7300 -- clause applying to Var).
7302 if No
(Init_Call
) and then Present
(Freeze_Node
(Var
)) then
7304 Find_Init_Call_In_List
(First
(Actions
(Freeze_Node
(Var
))));
7307 -- If the initialization call has actuals that use the secondary
7308 -- stack, the call may have been wrapped into a temporary block, in
7309 -- which case the block itself has to be removed.
7311 if No
(Init_Call
) and then Nkind
(Next
(Par
)) = N_Block_Statement
then
7313 Blk
: constant Node_Id
:= Next
(Par
);
7316 (Find_Init_Call_In_List
7317 (First
(Statements
(Handled_Statement_Sequence
(Blk
)))))
7325 if Present
(Init_Call
) then
7329 end Remove_Init_Call
;
7331 -------------------------
7332 -- Remove_Side_Effects --
7333 -------------------------
7335 procedure Remove_Side_Effects
7337 Name_Req
: Boolean := False;
7338 Renaming_Req
: Boolean := False;
7339 Variable_Ref
: Boolean := False;
7340 Related_Id
: Entity_Id
:= Empty
;
7341 Is_Low_Bound
: Boolean := False;
7342 Is_High_Bound
: Boolean := False)
7344 function Build_Temporary
7347 Related_Nod
: Node_Id
:= Empty
) return Entity_Id
;
7348 -- Create an external symbol of the form xxx_FIRST/_LAST if Related_Nod
7349 -- is present (xxx is taken from the Chars field of Related_Nod),
7350 -- otherwise it generates an internal temporary.
7352 ---------------------
7353 -- Build_Temporary --
7354 ---------------------
7356 function Build_Temporary
7359 Related_Nod
: Node_Id
:= Empty
) return Entity_Id
7364 -- The context requires an external symbol
7366 if Present
(Related_Id
) then
7367 if Is_Low_Bound
then
7368 Temp_Nam
:= New_External_Name
(Chars
(Related_Id
), "_FIRST");
7369 else pragma Assert
(Is_High_Bound
);
7370 Temp_Nam
:= New_External_Name
(Chars
(Related_Id
), "_LAST");
7373 return Make_Defining_Identifier
(Loc
, Temp_Nam
);
7375 -- Otherwise generate an internal temporary
7378 return Make_Temporary
(Loc
, Id
, Related_Nod
);
7380 end Build_Temporary
;
7384 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
7385 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
7386 Svg_Suppress
: constant Suppress_Record
:= Scope_Suppress
;
7390 Ptr_Typ_Decl
: Node_Id
;
7391 Ref_Type
: Entity_Id
;
7394 -- Start of processing for Remove_Side_Effects
7397 -- Handle cases in which there is nothing to do. In GNATprove mode,
7398 -- removal of side effects is useful for the light expansion of
7399 -- renamings. This removal should only occur when not inside a
7400 -- generic and not doing a pre-analysis.
7402 if not Expander_Active
7403 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
7408 -- Cannot generate temporaries if the invocation to remove side effects
7409 -- was issued too early and the type of the expression is not resolved
7410 -- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
7411 -- Remove_Side_Effects).
7413 if No
(Exp_Type
) or else Ekind
(Exp_Type
) = E_Access_Attribute_Type
then
7416 -- No action needed for side-effect free expressions
7418 elsif Side_Effect_Free
(Exp
, Name_Req
, Variable_Ref
) then
7422 -- The remaining procesaing is done with all checks suppressed
7424 -- Note: from now on, don't use return statements, instead do a goto
7425 -- Leave, to ensure that we properly restore Scope_Suppress.Suppress.
7427 Scope_Suppress
.Suppress
:= (others => True);
7429 -- If it is a scalar type and we need to capture the value, just make
7430 -- a copy. Likewise for a function call, an attribute reference, a
7431 -- conditional expression, an allocator, or an operator. And if we have
7432 -- a volatile reference and Name_Req is not set (see comments for
7433 -- Side_Effect_Free).
7435 if Is_Elementary_Type
(Exp_Type
)
7437 -- Note: this test is rather mysterious??? Why can't we just test ONLY
7438 -- Is_Elementary_Type and be done with it. If we try that approach, we
7439 -- get some failures (infinite recursions) from the Duplicate_Subexpr
7440 -- call at the end of Checks.Apply_Predicate_Check. To be
7443 and then (Variable_Ref
7444 or else Nkind_In
(Exp
, N_Attribute_Reference
,
7449 or else Nkind
(Exp
) in N_Op
7450 or else (not Name_Req
7451 and then Is_Volatile_Reference
(Exp
)))
7453 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7454 Set_Etype
(Def_Id
, Exp_Type
);
7455 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7457 -- If the expression is a packed reference, it must be reanalyzed and
7458 -- expanded, depending on context. This is the case for actuals where
7459 -- a constraint check may capture the actual before expansion of the
7460 -- call is complete.
7462 if Nkind
(Exp
) = N_Indexed_Component
7463 and then Is_Packed
(Etype
(Prefix
(Exp
)))
7465 Set_Analyzed
(Exp
, False);
7466 Set_Analyzed
(Prefix
(Exp
), False);
7470 -- Rnn : Exp_Type renames Expr;
7472 if Renaming_Req
then
7474 Make_Object_Renaming_Declaration
(Loc
,
7475 Defining_Identifier
=> Def_Id
,
7476 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7477 Name
=> Relocate_Node
(Exp
));
7480 -- Rnn : constant Exp_Type := Expr;
7484 Make_Object_Declaration
(Loc
,
7485 Defining_Identifier
=> Def_Id
,
7486 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7487 Constant_Present
=> True,
7488 Expression
=> Relocate_Node
(Exp
));
7490 Set_Assignment_OK
(E
);
7493 Insert_Action
(Exp
, E
);
7495 -- If the expression has the form v.all then we can just capture the
7496 -- pointer, and then do an explicit dereference on the result, but
7497 -- this is not right if this is a volatile reference.
7499 elsif Nkind
(Exp
) = N_Explicit_Dereference
7500 and then not Is_Volatile_Reference
(Exp
)
7502 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7504 Make_Explicit_Dereference
(Loc
, New_Occurrence_Of
(Def_Id
, Loc
));
7507 Make_Object_Declaration
(Loc
,
7508 Defining_Identifier
=> Def_Id
,
7509 Object_Definition
=>
7510 New_Occurrence_Of
(Etype
(Prefix
(Exp
)), Loc
),
7511 Constant_Present
=> True,
7512 Expression
=> Relocate_Node
(Prefix
(Exp
))));
7514 -- Similar processing for an unchecked conversion of an expression of
7515 -- the form v.all, where we want the same kind of treatment.
7517 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
7518 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
7520 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
7523 -- If this is a type conversion, leave the type conversion and remove
7524 -- the side effects in the expression. This is important in several
7525 -- circumstances: for change of representations, and also when this is a
7526 -- view conversion to a smaller object, where gigi can end up creating
7527 -- its own temporary of the wrong size.
7529 elsif Nkind
(Exp
) = N_Type_Conversion
then
7530 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
7533 -- If this is an unchecked conversion that Gigi can't handle, make
7534 -- a copy or a use a renaming to capture the value.
7536 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
7537 and then not Safe_Unchecked_Type_Conversion
(Exp
)
7539 if CW_Or_Has_Controlled_Part
(Exp_Type
) then
7541 -- Use a renaming to capture the expression, rather than create
7542 -- a controlled temporary.
7544 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7545 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7548 Make_Object_Renaming_Declaration
(Loc
,
7549 Defining_Identifier
=> Def_Id
,
7550 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7551 Name
=> Relocate_Node
(Exp
)));
7554 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7555 Set_Etype
(Def_Id
, Exp_Type
);
7556 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7559 Make_Object_Declaration
(Loc
,
7560 Defining_Identifier
=> Def_Id
,
7561 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7562 Constant_Present
=> not Is_Variable
(Exp
),
7563 Expression
=> Relocate_Node
(Exp
));
7565 Set_Assignment_OK
(E
);
7566 Insert_Action
(Exp
, E
);
7569 -- For expressions that denote objects, we can use a renaming scheme.
7570 -- This is needed for correctness in the case of a volatile object of
7571 -- a non-volatile type because the Make_Reference call of the "default"
7572 -- approach would generate an illegal access value (an access value
7573 -- cannot designate such an object - see Analyze_Reference).
7575 elsif Is_Object_Reference
(Exp
)
7576 and then Nkind
(Exp
) /= N_Function_Call
7578 -- In Ada 2012 a qualified expression is an object, but for purposes
7579 -- of removing side effects it still need to be transformed into a
7580 -- separate declaration, particularly in the case of an aggregate.
7582 and then Nkind
(Exp
) /= N_Qualified_Expression
7584 -- We skip using this scheme if we have an object of a volatile
7585 -- type and we do not have Name_Req set true (see comments for
7586 -- Side_Effect_Free).
7588 and then (Name_Req
or else not Treat_As_Volatile
(Exp_Type
))
7590 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7592 if Nkind
(Exp
) = N_Selected_Component
7593 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
7594 and then Is_Array_Type
(Exp_Type
)
7596 -- Avoid generating a variable-sized temporary, by generating
7597 -- the renaming declaration just for the function call. The
7598 -- transformation could be refined to apply only when the array
7599 -- component is constrained by a discriminant???
7602 Make_Selected_Component
(Loc
,
7603 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
7604 Selector_Name
=> Selector_Name
(Exp
));
7607 Make_Object_Renaming_Declaration
(Loc
,
7608 Defining_Identifier
=> Def_Id
,
7610 New_Occurrence_Of
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
7611 Name
=> Relocate_Node
(Prefix
(Exp
))));
7614 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7617 Make_Object_Renaming_Declaration
(Loc
,
7618 Defining_Identifier
=> Def_Id
,
7619 Subtype_Mark
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7620 Name
=> Relocate_Node
(Exp
)));
7623 -- If this is a packed reference, or a selected component with
7624 -- a non-standard representation, a reference to the temporary
7625 -- will be replaced by a copy of the original expression (see
7626 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
7627 -- elaborated by gigi, and is of course not to be replaced in-line
7628 -- by the expression it renames, which would defeat the purpose of
7629 -- removing the side-effect.
7631 if Nkind_In
(Exp
, N_Selected_Component
, N_Indexed_Component
)
7632 and then Has_Non_Standard_Rep
(Etype
(Prefix
(Exp
)))
7636 Set_Is_Renaming_Of_Object
(Def_Id
, False);
7639 -- Otherwise we generate a reference to the value
7642 -- An expression which is in SPARK mode is considered side effect
7643 -- free if the resulting value is captured by a variable or a
7647 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
7652 -- Special processing for function calls that return a limited type.
7653 -- We need to build a declaration that will enable build-in-place
7654 -- expansion of the call. This is not done if the context is already
7655 -- an object declaration, to prevent infinite recursion.
7657 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
7658 -- to accommodate functions returning limited objects by reference.
7660 if Ada_Version
>= Ada_2005
7661 and then Nkind
(Exp
) = N_Function_Call
7662 and then Is_Limited_View
(Etype
(Exp
))
7663 and then Nkind
(Parent
(Exp
)) /= N_Object_Declaration
7666 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', Exp
);
7671 Make_Object_Declaration
(Loc
,
7672 Defining_Identifier
=> Obj
,
7673 Object_Definition
=> New_Occurrence_Of
(Exp_Type
, Loc
),
7674 Expression
=> Relocate_Node
(Exp
));
7676 Insert_Action
(Exp
, Decl
);
7677 Set_Etype
(Obj
, Exp_Type
);
7678 Rewrite
(Exp
, New_Occurrence_Of
(Obj
, Loc
));
7683 Def_Id
:= Build_Temporary
(Loc
, 'R', Exp
);
7685 -- The regular expansion of functions with side effects involves the
7686 -- generation of an access type to capture the return value found on
7687 -- the secondary stack. Since SPARK (and why) cannot process access
7688 -- types, use a different approach which ignores the secondary stack
7689 -- and "copies" the returned object.
7691 if GNATprove_Mode
then
7692 Res
:= New_Occurrence_Of
(Def_Id
, Loc
);
7693 Ref_Type
:= Exp_Type
;
7695 -- Regular expansion utilizing an access type and 'reference
7699 Make_Explicit_Dereference
(Loc
,
7700 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
));
7703 -- type Ann is access all <Exp_Type>;
7705 Ref_Type
:= Make_Temporary
(Loc
, 'A');
7708 Make_Full_Type_Declaration
(Loc
,
7709 Defining_Identifier
=> Ref_Type
,
7711 Make_Access_To_Object_Definition
(Loc
,
7712 All_Present
=> True,
7713 Subtype_Indication
=>
7714 New_Occurrence_Of
(Exp_Type
, Loc
)));
7716 Insert_Action
(Exp
, Ptr_Typ_Decl
);
7720 if Nkind
(E
) = N_Explicit_Dereference
then
7721 New_Exp
:= Relocate_Node
(Prefix
(E
));
7724 E
:= Relocate_Node
(E
);
7726 -- Do not generate a 'reference in SPARK mode since the access
7727 -- type is not created in the first place.
7729 if GNATprove_Mode
then
7732 -- Otherwise generate reference, marking the value as non-null
7733 -- since we know it cannot be null and we don't want a check.
7736 New_Exp
:= Make_Reference
(Loc
, E
);
7737 Set_Is_Known_Non_Null
(Def_Id
);
7741 if Is_Delayed_Aggregate
(E
) then
7743 -- The expansion of nested aggregates is delayed until the
7744 -- enclosing aggregate is expanded. As aggregates are often
7745 -- qualified, the predicate applies to qualified expressions as
7746 -- well, indicating that the enclosing aggregate has not been
7747 -- expanded yet. At this point the aggregate is part of a
7748 -- stand-alone declaration, and must be fully expanded.
7750 if Nkind
(E
) = N_Qualified_Expression
then
7751 Set_Expansion_Delayed
(Expression
(E
), False);
7752 Set_Analyzed
(Expression
(E
), False);
7754 Set_Expansion_Delayed
(E
, False);
7757 Set_Analyzed
(E
, False);
7761 Make_Object_Declaration
(Loc
,
7762 Defining_Identifier
=> Def_Id
,
7763 Object_Definition
=> New_Occurrence_Of
(Ref_Type
, Loc
),
7764 Constant_Present
=> True,
7765 Expression
=> New_Exp
));
7768 -- Preserve the Assignment_OK flag in all copies, since at least one
7769 -- copy may be used in a context where this flag must be set (otherwise
7770 -- why would the flag be set in the first place).
7772 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
7774 -- Finally rewrite the original expression and we are done
7777 Analyze_And_Resolve
(Exp
, Exp_Type
);
7780 Scope_Suppress
:= Svg_Suppress
;
7781 end Remove_Side_Effects
;
7783 ---------------------------
7784 -- Represented_As_Scalar --
7785 ---------------------------
7787 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean is
7788 UT
: constant Entity_Id
:= Underlying_Type
(T
);
7790 return Is_Scalar_Type
(UT
)
7791 or else (Is_Bit_Packed_Array
(UT
)
7792 and then Is_Scalar_Type
(Packed_Array_Impl_Type
(UT
)));
7793 end Represented_As_Scalar
;
7795 ------------------------------
7796 -- Requires_Cleanup_Actions --
7797 ------------------------------
7799 function Requires_Cleanup_Actions
7801 Lib_Level
: Boolean) return Boolean
7803 At_Lib_Level
: constant Boolean :=
7805 and then Nkind_In
(N
, N_Package_Body
,
7806 N_Package_Specification
);
7807 -- N is at the library level if the top-most context is a package and
7808 -- the path taken to reach N does not inlcude non-package constructs.
7812 when N_Accept_Statement |
7820 Requires_Cleanup_Actions
(Declarations
(N
), At_Lib_Level
, True)
7822 (Present
(Handled_Statement_Sequence
(N
))
7824 Requires_Cleanup_Actions
7825 (Statements
(Handled_Statement_Sequence
(N
)),
7826 At_Lib_Level
, True));
7828 when N_Package_Specification
=>
7830 Requires_Cleanup_Actions
7831 (Visible_Declarations
(N
), At_Lib_Level
, True)
7833 Requires_Cleanup_Actions
7834 (Private_Declarations
(N
), At_Lib_Level
, True);
7839 end Requires_Cleanup_Actions
;
7841 ------------------------------
7842 -- Requires_Cleanup_Actions --
7843 ------------------------------
7845 function Requires_Cleanup_Actions
7847 Lib_Level
: Boolean;
7848 Nested_Constructs
: Boolean) return Boolean
7853 Obj_Typ
: Entity_Id
;
7854 Pack_Id
: Entity_Id
;
7859 or else Is_Empty_List
(L
)
7865 while Present
(Decl
) loop
7867 -- Library-level tagged types
7869 if Nkind
(Decl
) = N_Full_Type_Declaration
then
7870 Typ
:= Defining_Identifier
(Decl
);
7872 -- Ignored Ghost types do not need any cleanup actions because
7873 -- they will not appear in the final tree.
7875 if Is_Ignored_Ghost_Entity
(Typ
) then
7878 elsif Is_Tagged_Type
(Typ
)
7879 and then Is_Library_Level_Entity
(Typ
)
7880 and then Convention
(Typ
) = Convention_Ada
7881 and then Present
(Access_Disp_Table
(Typ
))
7882 and then RTE_Available
(RE_Unregister_Tag
)
7883 and then not Is_Abstract_Type
(Typ
)
7884 and then not No_Run_Time_Mode
7889 -- Regular object declarations
7891 elsif Nkind
(Decl
) = N_Object_Declaration
then
7892 Obj_Id
:= Defining_Identifier
(Decl
);
7893 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7894 Expr
:= Expression
(Decl
);
7896 -- Bypass any form of processing for objects which have their
7897 -- finalization disabled. This applies only to objects at the
7900 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7903 -- Transient variables are treated separately in order to minimize
7904 -- the size of the generated code. See Exp_Ch7.Process_Transient_
7907 elsif Is_Processed_Transient
(Obj_Id
) then
7910 -- Ignored Ghost objects do not need any cleanup actions because
7911 -- they will not appear in the final tree.
7913 elsif Is_Ignored_Ghost_Entity
(Obj_Id
) then
7916 -- The object is of the form:
7917 -- Obj : Typ [:= Expr];
7919 -- Do not process the incomplete view of a deferred constant. Do
7920 -- not consider tag-to-class-wide conversions.
7922 elsif not Is_Imported
(Obj_Id
)
7923 and then Needs_Finalization
(Obj_Typ
)
7924 and then not (Ekind
(Obj_Id
) = E_Constant
7925 and then not Has_Completion
(Obj_Id
))
7926 and then not Is_Tag_To_Class_Wide_Conversion
(Obj_Id
)
7930 -- The object is of the form:
7931 -- Obj : Access_Typ := Non_BIP_Function_Call'reference;
7933 -- Obj : Access_Typ :=
7934 -- BIP_Function_Call (BIPalloc => 2, ...)'reference;
7936 elsif Is_Access_Type
(Obj_Typ
)
7937 and then Needs_Finalization
7938 (Available_View
(Designated_Type
(Obj_Typ
)))
7939 and then Present
(Expr
)
7941 (Is_Secondary_Stack_BIP_Func_Call
(Expr
)
7943 (Is_Non_BIP_Func_Call
(Expr
)
7944 and then not Is_Related_To_Func_Return
(Obj_Id
)))
7948 -- Processing for "hook" objects generated for controlled
7949 -- transients declared inside an Expression_With_Actions.
7951 elsif Is_Access_Type
(Obj_Typ
)
7952 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7953 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7954 N_Object_Declaration
7958 -- Processing for intermediate results of if expressions where
7959 -- one of the alternatives uses a controlled function call.
7961 elsif Is_Access_Type
(Obj_Typ
)
7962 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
7963 and then Nkind
(Status_Flag_Or_Transient_Decl
(Obj_Id
)) =
7964 N_Defining_Identifier
7965 and then Present
(Expr
)
7966 and then Nkind
(Expr
) = N_Null
7970 -- Simple protected objects which use type System.Tasking.
7971 -- Protected_Objects.Protection to manage their locks should be
7972 -- treated as controlled since they require manual cleanup.
7974 elsif Ekind
(Obj_Id
) = E_Variable
7975 and then (Is_Simple_Protected_Type
(Obj_Typ
)
7976 or else Has_Simple_Protected_Object
(Obj_Typ
))
7981 -- Specific cases of object renamings
7983 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
7984 Obj_Id
:= Defining_Identifier
(Decl
);
7985 Obj_Typ
:= Base_Type
(Etype
(Obj_Id
));
7987 -- Bypass any form of processing for objects which have their
7988 -- finalization disabled. This applies only to objects at the
7991 if Lib_Level
and then Finalize_Storage_Only
(Obj_Typ
) then
7994 -- Ignored Ghost object renamings do not need any cleanup actions
7995 -- because they will not appear in the final tree.
7997 elsif Is_Ignored_Ghost_Entity
(Obj_Id
) then
8000 -- Return object of a build-in-place function. This case is
8001 -- recognized and marked by the expansion of an extended return
8002 -- statement (see Expand_N_Extended_Return_Statement).
8004 elsif Needs_Finalization
(Obj_Typ
)
8005 and then Is_Return_Object
(Obj_Id
)
8006 and then Present
(Status_Flag_Or_Transient_Decl
(Obj_Id
))
8010 -- Detect a case where a source object has been initialized by
8011 -- a controlled function call or another object which was later
8012 -- rewritten as a class-wide conversion of Ada.Tags.Displace.
8014 -- Obj1 : CW_Type := Src_Obj;
8015 -- Obj2 : CW_Type := Function_Call (...);
8017 -- Obj1 : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
8018 -- Tmp : ... := Function_Call (...)'reference;
8019 -- Obj2 : CW_Type renames (... Ada.Tags.Displace (Tmp));
8021 elsif Is_Displacement_Of_Object_Or_Function_Result
(Obj_Id
) then
8025 -- Inspect the freeze node of an access-to-controlled type and look
8026 -- for a delayed finalization master. This case arises when the
8027 -- freeze actions are inserted at a later time than the expansion of
8028 -- the context. Since Build_Finalizer is never called on a single
8029 -- construct twice, the master will be ultimately left out and never
8030 -- finalized. This is also needed for freeze actions of designated
8031 -- types themselves, since in some cases the finalization master is
8032 -- associated with a designated type's freeze node rather than that
8033 -- of the access type (see handling for freeze actions in
8034 -- Build_Finalization_Master).
8036 elsif Nkind
(Decl
) = N_Freeze_Entity
8037 and then Present
(Actions
(Decl
))
8039 Typ
:= Entity
(Decl
);
8041 -- Freeze nodes for ignored Ghost types do not need cleanup
8042 -- actions because they will never appear in the final tree.
8044 if Is_Ignored_Ghost_Entity
(Typ
) then
8047 elsif ((Is_Access_Type
(Typ
)
8048 and then not Is_Access_Subprogram_Type
(Typ
)
8049 and then Needs_Finalization
8050 (Available_View
(Designated_Type
(Typ
))))
8051 or else (Is_Type
(Typ
) and then Needs_Finalization
(Typ
)))
8052 and then Requires_Cleanup_Actions
8053 (Actions
(Decl
), Lib_Level
, Nested_Constructs
)
8058 -- Nested package declarations
8060 elsif Nested_Constructs
8061 and then Nkind
(Decl
) = N_Package_Declaration
8063 Pack_Id
:= Defining_Entity
(Decl
);
8065 -- Do not inspect an ignored Ghost package because all code found
8066 -- within will not appear in the final tree.
8068 if Is_Ignored_Ghost_Entity
(Pack_Id
) then
8071 elsif Ekind
(Pack_Id
) /= E_Generic_Package
8072 and then Requires_Cleanup_Actions
8073 (Specification
(Decl
), Lib_Level
)
8078 -- Nested package bodies
8080 elsif Nested_Constructs
and then Nkind
(Decl
) = N_Package_Body
then
8082 -- Do not inspect an ignored Ghost package body because all code
8083 -- found within will not appear in the final tree.
8085 if Is_Ignored_Ghost_Entity
(Defining_Entity
(Decl
)) then
8088 elsif Ekind
(Corresponding_Spec
(Decl
)) /= E_Generic_Package
8089 and then Requires_Cleanup_Actions
(Decl
, Lib_Level
)
8094 elsif Nkind
(Decl
) = N_Block_Statement
8097 -- Handle a rare case caused by a controlled transient variable
8098 -- created as part of a record init proc. The variable is wrapped
8099 -- in a block, but the block is not associated with a transient
8104 -- Handle the case where the original context has been wrapped in
8105 -- a block to avoid interference between exception handlers and
8106 -- At_End handlers. Treat the block as transparent and process its
8109 or else Is_Finalization_Wrapper
(Decl
))
8111 if Requires_Cleanup_Actions
(Decl
, Lib_Level
) then
8120 end Requires_Cleanup_Actions
;
8122 ------------------------------------
8123 -- Safe_Unchecked_Type_Conversion --
8124 ------------------------------------
8126 -- Note: this function knows quite a bit about the exact requirements of
8127 -- Gigi with respect to unchecked type conversions, and its code must be
8128 -- coordinated with any changes in Gigi in this area.
8130 -- The above requirements should be documented in Sinfo ???
8132 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
8137 Pexp
: constant Node_Id
:= Parent
(Exp
);
8140 -- If the expression is the RHS of an assignment or object declaration
8141 -- we are always OK because there will always be a target.
8143 -- Object renaming declarations, (generated for view conversions of
8144 -- actuals in inlined calls), like object declarations, provide an
8145 -- explicit type, and are safe as well.
8147 if (Nkind
(Pexp
) = N_Assignment_Statement
8148 and then Expression
(Pexp
) = Exp
)
8149 or else Nkind_In
(Pexp
, N_Object_Declaration
,
8150 N_Object_Renaming_Declaration
)
8154 -- If the expression is the prefix of an N_Selected_Component we should
8155 -- also be OK because GCC knows to look inside the conversion except if
8156 -- the type is discriminated. We assume that we are OK anyway if the
8157 -- type is not set yet or if it is controlled since we can't afford to
8158 -- introduce a temporary in this case.
8160 elsif Nkind
(Pexp
) = N_Selected_Component
8161 and then Prefix
(Pexp
) = Exp
8163 if No
(Etype
(Pexp
)) then
8167 not Has_Discriminants
(Etype
(Pexp
))
8168 or else Is_Constrained
(Etype
(Pexp
));
8172 -- Set the output type, this comes from Etype if it is set, otherwise we
8173 -- take it from the subtype mark, which we assume was already fully
8176 if Present
(Etype
(Exp
)) then
8177 Otyp
:= Etype
(Exp
);
8179 Otyp
:= Entity
(Subtype_Mark
(Exp
));
8182 -- The input type always comes from the expression, and we assume this
8183 -- is indeed always analyzed, so we can simply get the Etype.
8185 Ityp
:= Etype
(Expression
(Exp
));
8187 -- Initialize alignments to unknown so far
8192 -- Replace a concurrent type by its corresponding record type and each
8193 -- type by its underlying type and do the tests on those. The original
8194 -- type may be a private type whose completion is a concurrent type, so
8195 -- find the underlying type first.
8197 if Present
(Underlying_Type
(Otyp
)) then
8198 Otyp
:= Underlying_Type
(Otyp
);
8201 if Present
(Underlying_Type
(Ityp
)) then
8202 Ityp
:= Underlying_Type
(Ityp
);
8205 if Is_Concurrent_Type
(Otyp
) then
8206 Otyp
:= Corresponding_Record_Type
(Otyp
);
8209 if Is_Concurrent_Type
(Ityp
) then
8210 Ityp
:= Corresponding_Record_Type
(Ityp
);
8213 -- If the base types are the same, we know there is no problem since
8214 -- this conversion will be a noop.
8216 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
8219 -- Same if this is an upwards conversion of an untagged type, and there
8220 -- are no constraints involved (could be more general???)
8222 elsif Etype
(Ityp
) = Otyp
8223 and then not Is_Tagged_Type
(Ityp
)
8224 and then not Has_Discriminants
(Ityp
)
8225 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
8229 -- If the expression has an access type (object or subprogram) we assume
8230 -- that the conversion is safe, because the size of the target is safe,
8231 -- even if it is a record (which might be treated as having unknown size
8234 elsif Is_Access_Type
(Ityp
) then
8237 -- If the size of output type is known at compile time, there is never
8238 -- a problem. Note that unconstrained records are considered to be of
8239 -- known size, but we can't consider them that way here, because we are
8240 -- talking about the actual size of the object.
8242 -- We also make sure that in addition to the size being known, we do not
8243 -- have a case which might generate an embarrassingly large temp in
8244 -- stack checking mode.
8246 elsif Size_Known_At_Compile_Time
(Otyp
)
8248 (not Stack_Checking_Enabled
8249 or else not May_Generate_Large_Temp
(Otyp
))
8250 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
8254 -- If either type is tagged, then we know the alignment is OK so Gigi
8255 -- will be able to use pointer punning.
8257 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
8260 -- If either type is a limited record type, we cannot do a copy, so say
8261 -- safe since there's nothing else we can do.
8263 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
8266 -- Conversions to and from packed array types are always ignored and
8269 elsif Is_Packed_Array_Impl_Type
(Otyp
)
8270 or else Is_Packed_Array_Impl_Type
(Ityp
)
8275 -- The only other cases known to be safe is if the input type's
8276 -- alignment is known to be at least the maximum alignment for the
8277 -- target or if both alignments are known and the output type's
8278 -- alignment is no stricter than the input's. We can use the component
8279 -- type alignement for an array if a type is an unpacked array type.
8281 if Present
(Alignment_Clause
(Otyp
)) then
8282 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
8284 elsif Is_Array_Type
(Otyp
)
8285 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
8287 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
8288 (Component_Type
(Otyp
))));
8291 if Present
(Alignment_Clause
(Ityp
)) then
8292 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
8294 elsif Is_Array_Type
(Ityp
)
8295 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
8297 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
8298 (Component_Type
(Ityp
))));
8301 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
8304 elsif Ialign
/= No_Uint
8305 and then Oalign
/= No_Uint
8306 and then Ialign
<= Oalign
8310 -- Otherwise, Gigi cannot handle this and we must make a temporary
8315 end Safe_Unchecked_Type_Conversion
;
8317 ---------------------------------
8318 -- Set_Current_Value_Condition --
8319 ---------------------------------
8321 -- Note: the implementation of this procedure is very closely tied to the
8322 -- implementation of Get_Current_Value_Condition. Here we set required
8323 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
8324 -- them, so they must have a consistent view.
8326 procedure Set_Current_Value_Condition
(Cnode
: Node_Id
) is
8328 procedure Set_Entity_Current_Value
(N
: Node_Id
);
8329 -- If N is an entity reference, where the entity is of an appropriate
8330 -- kind, then set the current value of this entity to Cnode, unless
8331 -- there is already a definite value set there.
8333 procedure Set_Expression_Current_Value
(N
: Node_Id
);
8334 -- If N is of an appropriate form, sets an appropriate entry in current
8335 -- value fields of relevant entities. Multiple entities can be affected
8336 -- in the case of an AND or AND THEN.
8338 ------------------------------
8339 -- Set_Entity_Current_Value --
8340 ------------------------------
8342 procedure Set_Entity_Current_Value
(N
: Node_Id
) is
8344 if Is_Entity_Name
(N
) then
8346 Ent
: constant Entity_Id
:= Entity
(N
);
8349 -- Don't capture if not safe to do so
8351 if not Safe_To_Capture_Value
(N
, Ent
, Cond
=> True) then
8355 -- Here we have a case where the Current_Value field may need
8356 -- to be set. We set it if it is not already set to a compile
8357 -- time expression value.
8359 -- Note that this represents a decision that one condition
8360 -- blots out another previous one. That's certainly right if
8361 -- they occur at the same level. If the second one is nested,
8362 -- then the decision is neither right nor wrong (it would be
8363 -- equally OK to leave the outer one in place, or take the new
8364 -- inner one. Really we should record both, but our data
8365 -- structures are not that elaborate.
8367 if Nkind
(Current_Value
(Ent
)) not in N_Subexpr
then
8368 Set_Current_Value
(Ent
, Cnode
);
8372 end Set_Entity_Current_Value
;
8374 ----------------------------------
8375 -- Set_Expression_Current_Value --
8376 ----------------------------------
8378 procedure Set_Expression_Current_Value
(N
: Node_Id
) is
8384 -- Loop to deal with (ignore for now) any NOT operators present. The
8385 -- presence of NOT operators will be handled properly when we call
8386 -- Get_Current_Value_Condition.
8388 while Nkind
(Cond
) = N_Op_Not
loop
8389 Cond
:= Right_Opnd
(Cond
);
8392 -- For an AND or AND THEN, recursively process operands
8394 if Nkind
(Cond
) = N_Op_And
or else Nkind
(Cond
) = N_And_Then
then
8395 Set_Expression_Current_Value
(Left_Opnd
(Cond
));
8396 Set_Expression_Current_Value
(Right_Opnd
(Cond
));
8400 -- Check possible relational operator
8402 if Nkind
(Cond
) in N_Op_Compare
then
8403 if Compile_Time_Known_Value
(Right_Opnd
(Cond
)) then
8404 Set_Entity_Current_Value
(Left_Opnd
(Cond
));
8405 elsif Compile_Time_Known_Value
(Left_Opnd
(Cond
)) then
8406 Set_Entity_Current_Value
(Right_Opnd
(Cond
));
8409 elsif Nkind_In
(Cond
,
8411 N_Qualified_Expression
,
8412 N_Expression_With_Actions
)
8414 Set_Expression_Current_Value
(Expression
(Cond
));
8416 -- Check possible boolean variable reference
8419 Set_Entity_Current_Value
(Cond
);
8421 end Set_Expression_Current_Value
;
8423 -- Start of processing for Set_Current_Value_Condition
8426 Set_Expression_Current_Value
(Condition
(Cnode
));
8427 end Set_Current_Value_Condition
;
8429 --------------------------
8430 -- Set_Elaboration_Flag --
8431 --------------------------
8433 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
8434 Loc
: constant Source_Ptr
:= Sloc
(N
);
8435 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
8439 if Present
(Ent
) then
8441 -- Nothing to do if at the compilation unit level, because in this
8442 -- case the flag is set by the binder generated elaboration routine.
8444 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
8447 -- Here we do need to generate an assignment statement
8450 Check_Restriction
(No_Elaboration_Code
, N
);
8452 Make_Assignment_Statement
(Loc
,
8453 Name
=> New_Occurrence_Of
(Ent
, Loc
),
8454 Expression
=> Make_Integer_Literal
(Loc
, Uint_1
));
8456 if Nkind
(Parent
(N
)) = N_Subunit
then
8457 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
8459 Insert_After
(N
, Asn
);
8464 -- Kill current value indication. This is necessary because the
8465 -- tests of this flag are inserted out of sequence and must not
8466 -- pick up bogus indications of the wrong constant value.
8468 Set_Current_Value
(Ent
, Empty
);
8470 -- If the subprogram is in the current declarative part and
8471 -- 'access has been applied to it, generate an elaboration
8472 -- check at the beginning of the declarations of the body.
8474 if Nkind
(N
) = N_Subprogram_Body
8475 and then Address_Taken
(Spec_Id
)
8477 Ekind_In
(Scope
(Spec_Id
), E_Block
, E_Procedure
, E_Function
)
8480 Loc
: constant Source_Ptr
:= Sloc
(N
);
8481 Decls
: constant List_Id
:= Declarations
(N
);
8485 -- No need to generate this check if first entry in the
8486 -- declaration list is a raise of Program_Error now.
8489 and then Nkind
(First
(Decls
)) = N_Raise_Program_Error
8494 -- Otherwise generate the check
8497 Make_Raise_Program_Error
(Loc
,
8500 Left_Opnd
=> New_Occurrence_Of
(Ent
, Loc
),
8501 Right_Opnd
=> Make_Integer_Literal
(Loc
, Uint_0
)),
8502 Reason
=> PE_Access_Before_Elaboration
);
8505 Set_Declarations
(N
, New_List
(Chk
));
8507 Prepend
(Chk
, Decls
);
8515 end Set_Elaboration_Flag
;
8517 ----------------------------
8518 -- Set_Renamed_Subprogram --
8519 ----------------------------
8521 procedure Set_Renamed_Subprogram
(N
: Node_Id
; E
: Entity_Id
) is
8523 -- If input node is an identifier, we can just reset it
8525 if Nkind
(N
) = N_Identifier
then
8526 Set_Chars
(N
, Chars
(E
));
8529 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
8533 CS
: constant Boolean := Comes_From_Source
(N
);
8535 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
(E
)));
8537 Set_Comes_From_Source
(N
, CS
);
8538 Set_Analyzed
(N
, True);
8541 end Set_Renamed_Subprogram
;
8543 ----------------------
8544 -- Side_Effect_Free --
8545 ----------------------
8547 function Side_Effect_Free
8549 Name_Req
: Boolean := False;
8550 Variable_Ref
: Boolean := False) return Boolean
8552 Typ
: constant Entity_Id
:= Etype
(N
);
8553 -- Result type of the expression
8555 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
8556 -- The argument N is a construct where the Prefix is dereferenced if it
8557 -- is an access type and the result is a variable. The call returns True
8558 -- if the construct is side effect free (not considering side effects in
8559 -- other than the prefix which are to be tested by the caller).
8561 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
8562 -- Determines if N is a subcomponent of a composite in-parameter. If so,
8563 -- N is not side-effect free when the actual is global and modifiable
8564 -- indirectly from within a subprogram, because it may be passed by
8565 -- reference. The front-end must be conservative here and assume that
8566 -- this may happen with any array or record type. On the other hand, we
8567 -- cannot create temporaries for all expressions for which this
8568 -- condition is true, for various reasons that might require clearing up
8569 -- ??? For example, discriminant references that appear out of place, or
8570 -- spurious type errors with class-wide expressions. As a result, we
8571 -- limit the transformation to loop bounds, which is so far the only
8572 -- case that requires it.
8574 -----------------------------
8575 -- Safe_Prefixed_Reference --
8576 -----------------------------
8578 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
8580 -- If prefix is not side effect free, definitely not safe
8582 if not Side_Effect_Free
(Prefix
(N
), Name_Req
, Variable_Ref
) then
8585 -- If the prefix is of an access type that is not access-to-constant,
8586 -- then this construct is a variable reference, which means it is to
8587 -- be considered to have side effects if Variable_Ref is set True.
8589 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
8590 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
8591 and then Variable_Ref
8593 -- Exception is a prefix that is the result of a previous removal
8596 return Is_Entity_Name
(Prefix
(N
))
8597 and then not Comes_From_Source
(Prefix
(N
))
8598 and then Ekind
(Entity
(Prefix
(N
))) = E_Constant
8599 and then Is_Internal_Name
(Chars
(Entity
(Prefix
(N
))));
8601 -- If the prefix is an explicit dereference then this construct is a
8602 -- variable reference, which means it is to be considered to have
8603 -- side effects if Variable_Ref is True.
8605 -- We do NOT exclude dereferences of access-to-constant types because
8606 -- we handle them as constant view of variables.
8608 elsif Nkind
(Prefix
(N
)) = N_Explicit_Dereference
8609 and then Variable_Ref
8613 -- Note: The following test is the simplest way of solving a complex
8614 -- problem uncovered by the following test (Side effect on loop bound
8615 -- that is a subcomponent of a global variable:
8617 -- with Text_Io; use Text_Io;
8618 -- procedure Tloop is
8621 -- V : Natural := 4;
8622 -- S : String (1..5) := (others => 'a');
8629 -- with procedure Action;
8630 -- procedure Loop_G (Arg : X; Msg : String)
8632 -- procedure Loop_G (Arg : X; Msg : String) is
8634 -- Put_Line ("begin loop_g " & Msg & " will loop till: "
8635 -- & Natural'Image (Arg.V));
8636 -- for Index in 1 .. Arg.V loop
8638 -- (Natural'Image (Index) & " " & Arg.S (Index));
8639 -- if Index > 2 then
8643 -- Put_Line ("end loop_g " & Msg);
8646 -- procedure Loop1 is new Loop_G (Modi);
8647 -- procedure Modi is
8650 -- Loop1 (X1, "from modi");
8654 -- Loop1 (X1, "initial");
8657 -- The output of the above program should be:
8659 -- begin loop_g initial will loop till: 4
8663 -- begin loop_g from modi will loop till: 1
8665 -- end loop_g from modi
8667 -- begin loop_g from modi will loop till: 1
8669 -- end loop_g from modi
8670 -- end loop_g initial
8672 -- If a loop bound is a subcomponent of a global variable, a
8673 -- modification of that variable within the loop may incorrectly
8674 -- affect the execution of the loop.
8676 elsif Nkind
(Parent
(Parent
(N
))) = N_Loop_Parameter_Specification
8677 and then Within_In_Parameter
(Prefix
(N
))
8678 and then Variable_Ref
8682 -- All other cases are side effect free
8687 end Safe_Prefixed_Reference
;
8689 -------------------------
8690 -- Within_In_Parameter --
8691 -------------------------
8693 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
8695 if not Comes_From_Source
(N
) then
8698 elsif Is_Entity_Name
(N
) then
8699 return Ekind
(Entity
(N
)) = E_In_Parameter
;
8701 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
8702 return Within_In_Parameter
(Prefix
(N
));
8707 end Within_In_Parameter
;
8709 -- Start of processing for Side_Effect_Free
8712 -- If volatile reference, always consider it to have side effects
8714 if Is_Volatile_Reference
(N
) then
8718 -- Note on checks that could raise Constraint_Error. Strictly, if we
8719 -- take advantage of 11.6, these checks do not count as side effects.
8720 -- However, we would prefer to consider that they are side effects,
8721 -- since the backend CSE does not work very well on expressions which
8722 -- can raise Constraint_Error. On the other hand if we don't consider
8723 -- them to be side effect free, then we get some awkward expansions
8724 -- in -gnato mode, resulting in code insertions at a point where we
8725 -- do not have a clear model for performing the insertions.
8727 -- Special handling for entity names
8729 if Is_Entity_Name
(N
) then
8731 -- A type reference is always side effect free
8733 if Is_Type
(Entity
(N
)) then
8736 -- Variables are considered to be a side effect if Variable_Ref
8737 -- is set or if we have a volatile reference and Name_Req is off.
8738 -- If Name_Req is True then we can't help returning a name which
8739 -- effectively allows multiple references in any case.
8741 elsif Is_Variable
(N
, Use_Original_Node
=> False) then
8742 return not Variable_Ref
8743 and then (not Is_Volatile_Reference
(N
) or else Name_Req
);
8745 -- Any other entity (e.g. a subtype name) is definitely side
8752 -- A value known at compile time is always side effect free
8754 elsif Compile_Time_Known_Value
(N
) then
8757 -- A variable renaming is not side-effect free, because the renaming
8758 -- will function like a macro in the front-end in some cases, and an
8759 -- assignment can modify the component designated by N, so we need to
8760 -- create a temporary for it.
8762 -- The guard testing for Entity being present is needed at least in
8763 -- the case of rewritten predicate expressions, and may well also be
8764 -- appropriate elsewhere. Obviously we can't go testing the entity
8765 -- field if it does not exist, so it's reasonable to say that this is
8766 -- not the renaming case if it does not exist.
8768 elsif Is_Entity_Name
(Original_Node
(N
))
8769 and then Present
(Entity
(Original_Node
(N
)))
8770 and then Is_Renaming_Of_Object
(Entity
(Original_Node
(N
)))
8771 and then Ekind
(Entity
(Original_Node
(N
))) /= E_Constant
8774 RO
: constant Node_Id
:=
8775 Renamed_Object
(Entity
(Original_Node
(N
)));
8778 -- If the renamed object is an indexed component, or an
8779 -- explicit dereference, then the designated object could
8780 -- be modified by an assignment.
8782 if Nkind_In
(RO
, N_Indexed_Component
,
8783 N_Explicit_Dereference
)
8787 -- A selected component must have a safe prefix
8789 elsif Nkind
(RO
) = N_Selected_Component
then
8790 return Safe_Prefixed_Reference
(RO
);
8792 -- In all other cases, designated object cannot be changed so
8793 -- we are side effect free.
8800 -- Remove_Side_Effects generates an object renaming declaration to
8801 -- capture the expression of a class-wide expression. In VM targets
8802 -- the frontend performs no expansion for dispatching calls to
8803 -- class- wide types since they are handled by the VM. Hence, we must
8804 -- locate here if this node corresponds to a previous invocation of
8805 -- Remove_Side_Effects to avoid a never ending loop in the frontend.
8807 elsif VM_Target
/= No_VM
8808 and then not Comes_From_Source
(N
)
8809 and then Nkind
(Parent
(N
)) = N_Object_Renaming_Declaration
8810 and then Is_Class_Wide_Type
(Typ
)
8815 -- For other than entity names and compile time known values,
8816 -- check the node kind for special processing.
8820 -- An attribute reference is side effect free if its expressions
8821 -- are side effect free and its prefix is side effect free or
8822 -- is an entity reference.
8824 -- Is this right? what about x'first where x is a variable???
8826 when N_Attribute_Reference
=>
8827 return Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
)
8828 and then Attribute_Name
(N
) /= Name_Input
8829 and then (Is_Entity_Name
(Prefix
(N
))
8830 or else Side_Effect_Free
8831 (Prefix
(N
), Name_Req
, Variable_Ref
));
8833 -- A binary operator is side effect free if and both operands are
8834 -- side effect free. For this purpose binary operators include
8835 -- membership tests and short circuit forms.
8837 when N_Binary_Op | N_Membership_Test | N_Short_Circuit
=>
8838 return Side_Effect_Free
(Left_Opnd
(N
), Name_Req
, Variable_Ref
)
8840 Side_Effect_Free
(Right_Opnd
(N
), Name_Req
, Variable_Ref
);
8842 -- An explicit dereference is side effect free only if it is
8843 -- a side effect free prefixed reference.
8845 when N_Explicit_Dereference
=>
8846 return Safe_Prefixed_Reference
(N
);
8848 -- An expression with action is side effect free if its expression
8849 -- is side effect free and it has no actions.
8851 when N_Expression_With_Actions
=>
8852 return Is_Empty_List
(Actions
(N
))
8854 Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8856 -- A call to _rep_to_pos is side effect free, since we generate
8857 -- this pure function call ourselves. Moreover it is critically
8858 -- important to make this exception, since otherwise we can have
8859 -- discriminants in array components which don't look side effect
8860 -- free in the case of an array whose index type is an enumeration
8861 -- type with an enumeration rep clause.
8863 -- All other function calls are not side effect free
8865 when N_Function_Call
=>
8866 return Nkind
(Name
(N
)) = N_Identifier
8867 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
8870 (First
(Parameter_Associations
(N
)), Name_Req
, Variable_Ref
);
8872 -- An IF expression is side effect free if it's of a scalar type, and
8873 -- all its components are all side effect free (conditions and then
8874 -- actions and else actions). We restrict to scalar types, since it
8875 -- is annoying to deal with things like (if A then B else C)'First
8876 -- where the type involved is a string type.
8878 when N_If_Expression
=>
8879 return Is_Scalar_Type
(Typ
)
8881 Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
);
8883 -- An indexed component is side effect free if it is a side
8884 -- effect free prefixed reference and all the indexing
8885 -- expressions are side effect free.
8887 when N_Indexed_Component
=>
8888 return Side_Effect_Free
(Expressions
(N
), Name_Req
, Variable_Ref
)
8889 and then Safe_Prefixed_Reference
(N
);
8891 -- A type qualification is side effect free if the expression
8892 -- is side effect free.
8894 when N_Qualified_Expression
=>
8895 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8897 -- A selected component is side effect free only if it is a side
8898 -- effect free prefixed reference. If it designates a component
8899 -- with a rep. clause it must be treated has having a potential
8900 -- side effect, because it may be modified through a renaming, and
8901 -- a subsequent use of the renaming as a macro will yield the
8902 -- wrong value. This complex interaction between renaming and
8903 -- removing side effects is a reminder that the latter has become
8904 -- a headache to maintain, and that it should be removed in favor
8905 -- of the gcc mechanism to capture values ???
8907 when N_Selected_Component
=>
8908 if Nkind
(Parent
(N
)) = N_Explicit_Dereference
8909 and then Has_Non_Standard_Rep
(Designated_Type
(Typ
))
8913 return Safe_Prefixed_Reference
(N
);
8916 -- A range is side effect free if the bounds are side effect free
8919 return Side_Effect_Free
(Low_Bound
(N
), Name_Req
, Variable_Ref
)
8921 Side_Effect_Free
(High_Bound
(N
), Name_Req
, Variable_Ref
);
8923 -- A slice is side effect free if it is a side effect free
8924 -- prefixed reference and the bounds are side effect free.
8927 return Side_Effect_Free
8928 (Discrete_Range
(N
), Name_Req
, Variable_Ref
)
8929 and then Safe_Prefixed_Reference
(N
);
8931 -- A type conversion is side effect free if the expression to be
8932 -- converted is side effect free.
8934 when N_Type_Conversion
=>
8935 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8937 -- A unary operator is side effect free if the operand
8938 -- is side effect free.
8941 return Side_Effect_Free
(Right_Opnd
(N
), Name_Req
, Variable_Ref
);
8943 -- An unchecked type conversion is side effect free only if it
8944 -- is safe and its argument is side effect free.
8946 when N_Unchecked_Type_Conversion
=>
8947 return Safe_Unchecked_Type_Conversion
(N
)
8949 Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8951 -- An unchecked expression is side effect free if its expression
8952 -- is side effect free.
8954 when N_Unchecked_Expression
=>
8955 return Side_Effect_Free
(Expression
(N
), Name_Req
, Variable_Ref
);
8957 -- A literal is side effect free
8959 when N_Character_Literal |
8965 -- We consider that anything else has side effects. This is a bit
8966 -- crude, but we are pretty close for most common cases, and we
8967 -- are certainly correct (i.e. we never return True when the
8968 -- answer should be False).
8973 end Side_Effect_Free
;
8975 -- A list is side effect free if all elements of the list are side
8978 function Side_Effect_Free
8980 Name_Req
: Boolean := False;
8981 Variable_Ref
: Boolean := False) return Boolean
8986 if L
= No_List
or else L
= Error_List
then
8991 while Present
(N
) loop
8992 if not Side_Effect_Free
(N
, Name_Req
, Variable_Ref
) then
9001 end Side_Effect_Free
;
9003 ----------------------------------
9004 -- Silly_Boolean_Array_Not_Test --
9005 ----------------------------------
9007 -- This procedure implements an odd and silly test. We explicitly check
9008 -- for the case where the 'First of the component type is equal to the
9009 -- 'Last of this component type, and if this is the case, we make sure
9010 -- that constraint error is raised. The reason is that the NOT is bound
9011 -- to cause CE in this case, and we will not otherwise catch it.
9013 -- No such check is required for AND and OR, since for both these cases
9014 -- False op False = False, and True op True = True. For the XOR case,
9015 -- see Silly_Boolean_Array_Xor_Test.
9017 -- Believe it or not, this was reported as a bug. Note that nearly always,
9018 -- the test will evaluate statically to False, so the code will be
9019 -- statically removed, and no extra overhead caused.
9021 procedure Silly_Boolean_Array_Not_Test
(N
: Node_Id
; T
: Entity_Id
) is
9022 Loc
: constant Source_Ptr
:= Sloc
(N
);
9023 CT
: constant Entity_Id
:= Component_Type
(T
);
9026 -- The check we install is
9028 -- constraint_error when
9029 -- component_type'first = component_type'last
9030 -- and then array_type'Length /= 0)
9032 -- We need the last guard because we don't want to raise CE for empty
9033 -- arrays since no out of range values result. (Empty arrays with a
9034 -- component type of True .. True -- very useful -- even the ACATS
9035 -- does not test that marginal case).
9038 Make_Raise_Constraint_Error
(Loc
,
9044 Make_Attribute_Reference
(Loc
,
9045 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
9046 Attribute_Name
=> Name_First
),
9049 Make_Attribute_Reference
(Loc
,
9050 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
9051 Attribute_Name
=> Name_Last
)),
9053 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
9054 Reason
=> CE_Range_Check_Failed
));
9055 end Silly_Boolean_Array_Not_Test
;
9057 ----------------------------------
9058 -- Silly_Boolean_Array_Xor_Test --
9059 ----------------------------------
9061 -- This procedure implements an odd and silly test. We explicitly check
9062 -- for the XOR case where the component type is True .. True, since this
9063 -- will raise constraint error. A special check is required since CE
9064 -- will not be generated otherwise (cf Expand_Packed_Not).
9066 -- No such check is required for AND and OR, since for both these cases
9067 -- False op False = False, and True op True = True, and no check is
9068 -- required for the case of False .. False, since False xor False = False.
9069 -- See also Silly_Boolean_Array_Not_Test
9071 procedure Silly_Boolean_Array_Xor_Test
(N
: Node_Id
; T
: Entity_Id
) is
9072 Loc
: constant Source_Ptr
:= Sloc
(N
);
9073 CT
: constant Entity_Id
:= Component_Type
(T
);
9076 -- The check we install is
9078 -- constraint_error when
9079 -- Boolean (component_type'First)
9080 -- and then Boolean (component_type'Last)
9081 -- and then array_type'Length /= 0)
9083 -- We need the last guard because we don't want to raise CE for empty
9084 -- arrays since no out of range values result (Empty arrays with a
9085 -- component type of True .. True -- very useful -- even the ACATS
9086 -- does not test that marginal case).
9089 Make_Raise_Constraint_Error
(Loc
,
9095 Convert_To
(Standard_Boolean
,
9096 Make_Attribute_Reference
(Loc
,
9097 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
9098 Attribute_Name
=> Name_First
)),
9101 Convert_To
(Standard_Boolean
,
9102 Make_Attribute_Reference
(Loc
,
9103 Prefix
=> New_Occurrence_Of
(CT
, Loc
),
9104 Attribute_Name
=> Name_Last
))),
9106 Right_Opnd
=> Make_Non_Empty_Check
(Loc
, Right_Opnd
(N
))),
9107 Reason
=> CE_Range_Check_Failed
));
9108 end Silly_Boolean_Array_Xor_Test
;
9110 --------------------------
9111 -- Target_Has_Fixed_Ops --
9112 --------------------------
9114 Integer_Sized_Small
: Ureal
;
9115 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
9116 -- called (we don't want to compute it more than once).
9118 Long_Integer_Sized_Small
: Ureal
;
9119 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
9120 -- is called (we don't want to compute it more than once)
9122 First_Time_For_THFO
: Boolean := True;
9123 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
9125 function Target_Has_Fixed_Ops
9126 (Left_Typ
: Entity_Id
;
9127 Right_Typ
: Entity_Id
;
9128 Result_Typ
: Entity_Id
) return Boolean
9130 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
9131 -- Return True if the given type is a fixed-point type with a small
9132 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
9133 -- an absolute value less than 1.0. This is currently limited to
9134 -- fixed-point types that map to Integer or Long_Integer.
9136 ------------------------
9137 -- Is_Fractional_Type --
9138 ------------------------
9140 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
9142 if Esize
(Typ
) = Standard_Integer_Size
then
9143 return Small_Value
(Typ
) = Integer_Sized_Small
;
9145 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
9146 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
9151 end Is_Fractional_Type
;
9153 -- Start of processing for Target_Has_Fixed_Ops
9156 -- Return False if Fractional_Fixed_Ops_On_Target is false
9158 if not Fractional_Fixed_Ops_On_Target
then
9162 -- Here the target has Fractional_Fixed_Ops, if first time, compute
9163 -- standard constants used by Is_Fractional_Type.
9165 if First_Time_For_THFO
then
9166 First_Time_For_THFO
:= False;
9168 Integer_Sized_Small
:=
9171 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
9174 Long_Integer_Sized_Small
:=
9177 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
9181 -- Return True if target supports fixed-by-fixed multiply/divide for
9182 -- fractional fixed-point types (see Is_Fractional_Type) and the operand
9183 -- and result types are equivalent fractional types.
9185 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
9186 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
9187 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
9188 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
9189 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
9190 end Target_Has_Fixed_Ops
;
9192 ------------------------------------------
9193 -- Type_May_Have_Bit_Aligned_Components --
9194 ------------------------------------------
9196 function Type_May_Have_Bit_Aligned_Components
9197 (Typ
: Entity_Id
) return Boolean
9200 -- Array type, check component type
9202 if Is_Array_Type
(Typ
) then
9204 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
9206 -- Record type, check components
9208 elsif Is_Record_Type
(Typ
) then
9213 E
:= First_Component_Or_Discriminant
(Typ
);
9214 while Present
(E
) loop
9215 if Component_May_Be_Bit_Aligned
(E
)
9216 or else Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
9221 Next_Component_Or_Discriminant
(E
);
9227 -- Type other than array or record is always OK
9232 end Type_May_Have_Bit_Aligned_Components
;
9234 ----------------------------------
9235 -- Within_Case_Or_If_Expression --
9236 ----------------------------------
9238 function Within_Case_Or_If_Expression
(N
: Node_Id
) return Boolean is
9242 -- Locate an enclosing case or if expression. Note that these constructs
9243 -- can be expanded into Expression_With_Actions, hence the test of the
9247 while Present
(Par
) loop
9248 if Nkind_In
(Original_Node
(Par
), N_Case_Expression
,
9253 -- Prevent the search from going too far
9255 elsif Is_Body_Or_Package_Declaration
(Par
) then
9259 Par
:= Parent
(Par
);
9263 end Within_Case_Or_If_Expression
;
9265 --------------------------------
9266 -- Within_Internal_Subprogram --
9267 --------------------------------
9269 function Within_Internal_Subprogram
return Boolean is
9274 while Present
(S
) and then not Is_Subprogram
(S
) loop
9279 and then Get_TSS_Name
(S
) /= TSS_Null
9280 and then not Is_Predicate_Function
(S
);
9281 end Within_Internal_Subprogram
;
9283 ----------------------------
9284 -- Wrap_Cleanup_Procedure --
9285 ----------------------------
9287 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
9288 Loc
: constant Source_Ptr
:= Sloc
(N
);
9289 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
9290 Stmts
: constant List_Id
:= Statements
(Stseq
);
9292 if Abort_Allowed
then
9293 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
9294 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
9296 end Wrap_Cleanup_Procedure
;