1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Exp_Aggr; use Exp_Aggr;
35 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7;
37 with Inline; use Inline;
38 with Itypes; use Itypes;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Prag; use Sem_Prag;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sem_Util; use Sem_Util;
53 with Snames; use Snames;
54 with Stand; use Stand;
55 with Stringt; use Stringt;
56 with Targparm; use Targparm;
57 with Tbuild; use Tbuild;
58 with Ttypes; use Ttypes;
59 with Urealp; use Urealp;
60 with Validsw; use Validsw;
62 package body Exp_Util is
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 function Build_Task_Array_Image
72 Dyn : Boolean := False) return Node_Id;
73 -- Build function to generate the image string for a task that is an array
74 -- component, concatenating the images of each index. To avoid storage
75 -- leaks, the string is built with successive slice assignments. The flag
76 -- Dyn indicates whether this is called for the initialization procedure of
77 -- an array of tasks, or for the name of a dynamically created task that is
78 -- assigned to an indexed component.
80 function Build_Task_Image_Function
84 Res : Entity_Id) return Node_Id;
85 -- Common processing for Task_Array_Image and Task_Record_Image. Build
86 -- function body that computes image.
88 procedure Build_Task_Image_Prefix
97 -- Common processing for Task_Array_Image and Task_Record_Image. Create
98 -- local variables and assign prefix of name to result string.
100 function Build_Task_Record_Image
103 Dyn : Boolean := False) return Node_Id;
104 -- Build function to generate the image string for a task that is a record
105 -- component. Concatenate name of variable with that of selector. The flag
106 -- Dyn indicates whether this is called for the initialization procedure of
107 -- record with task components, or for a dynamically created task that is
108 -- assigned to a selected component.
110 function Make_CW_Equivalent_Type
112 E : Node_Id) return Entity_Id;
113 -- T is a class-wide type entity, E is the initial expression node that
114 -- constrains T in case such as: " X: T := E" or "new T'(E)". This function
115 -- returns the entity of the Equivalent type and inserts on the fly the
116 -- necessary declaration such as:
118 -- type anon is record
119 -- _parent : Root_Type (T); constrained with E discriminants (if any)
120 -- Extension : String (1 .. expr to match size of E);
123 -- This record is compatible with any object of the class of T thanks to
124 -- the first field and has the same size as E thanks to the second.
126 function Make_Literal_Range
128 Literal_Typ : Entity_Id) return Node_Id;
129 -- Produce a Range node whose bounds are:
130 -- Low_Bound (Literal_Type) ..
131 -- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
132 -- this is used for expanding declarations like X : String := "sdfgdfg";
134 -- If the index type of the target array is not integer, we generate:
135 -- Low_Bound (Literal_Type) ..
137 -- (Literal_Type'Pos (Low_Bound (Literal_Type))
138 -- + (Length (Literal_Typ) -1))
140 function Make_Non_Empty_Check
142 N : Node_Id) return Node_Id;
143 -- Produce a boolean expression checking that the unidimensional array
144 -- node N is not empty.
146 function New_Class_Wide_Subtype
148 N : Node_Id) return Entity_Id;
149 -- Create an implicit subtype of CW_Typ attached to node N
151 function Requires_Cleanup_Actions
154 Nested_Constructs : Boolean) return Boolean;
155 -- Given a list L, determine whether it contains one of the following:
157 -- 1) controlled objects
158 -- 2) library-level tagged types
160 -- Lib_Level is True when the list comes from a construct at the library
161 -- level, and False otherwise. Nested_Constructs is True when any nested
162 -- packages declared in L must be processed, and False otherwise.
164 -------------------------------------
165 -- Activate_Atomic_Synchronization --
166 -------------------------------------
168 procedure Activate_Atomic_Synchronization (N : Node_Id) is
172 case Nkind (Parent (N)) is
174 -- Check for cases of appearing in the prefix of a construct where
175 -- we don't need atomic synchronization for this kind of usage.
178 -- Nothing to do if we are the prefix of an attribute, since we
179 -- do not want an atomic sync operation for things like 'Size.
181 N_Attribute_Reference |
183 -- The N_Reference node is like an attribute
187 -- Nothing to do for a reference to a component (or components)
188 -- of a composite object. Only reads and updates of the object
189 -- as a whole require atomic synchronization (RM C.6 (15)).
191 N_Indexed_Component |
192 N_Selected_Component |
195 -- For all the above cases, nothing to do if we are the prefix
197 if Prefix (Parent (N)) = N then
204 -- Go ahead and set the flag
206 Set_Atomic_Sync_Required (N);
208 -- Generate info message if requested
210 if Warn_On_Atomic_Synchronization then
215 when N_Selected_Component | N_Expanded_Name =>
216 Msg_Node := Selector_Name (N);
218 when N_Explicit_Dereference | N_Indexed_Component =>
222 pragma Assert (False);
226 if Present (Msg_Node) then
228 ("?N?info: atomic synchronization set for &", Msg_Node);
231 ("?N?info: atomic synchronization set", N);
234 end Activate_Atomic_Synchronization;
236 ----------------------
237 -- Adjust_Condition --
238 ----------------------
240 procedure Adjust_Condition (N : Node_Id) is
247 Loc : constant Source_Ptr := Sloc (N);
248 T : constant Entity_Id := Etype (N);
252 -- Defend against a call where the argument has no type, or has a
253 -- type that is not Boolean. This can occur because of prior errors.
255 if No (T) or else not Is_Boolean_Type (T) then
259 -- Apply validity checking if needed
261 if Validity_Checks_On and Validity_Check_Tests then
265 -- Immediate return if standard boolean, the most common case,
266 -- where nothing needs to be done.
268 if Base_Type (T) = Standard_Boolean then
272 -- Case of zero/non-zero semantics or non-standard enumeration
273 -- representation. In each case, we rewrite the node as:
275 -- ityp!(N) /= False'Enum_Rep
277 -- where ityp is an integer type with large enough size to hold any
280 if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
281 if Esize (T) <= Esize (Standard_Integer) then
282 Ti := Standard_Integer;
284 Ti := Standard_Long_Long_Integer;
289 Left_Opnd => Unchecked_Convert_To (Ti, N),
291 Make_Attribute_Reference (Loc,
292 Attribute_Name => Name_Enum_Rep,
294 New_Occurrence_Of (First_Literal (T), Loc))));
295 Analyze_And_Resolve (N, Standard_Boolean);
298 Rewrite (N, Convert_To (Standard_Boolean, N));
299 Analyze_And_Resolve (N, Standard_Boolean);
302 end Adjust_Condition;
304 ------------------------
305 -- Adjust_Result_Type --
306 ------------------------
308 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
310 -- Ignore call if current type is not Standard.Boolean
312 if Etype (N) /= Standard_Boolean then
316 -- If result is already of correct type, nothing to do. Note that
317 -- this will get the most common case where everything has a type
318 -- of Standard.Boolean.
320 if Base_Type (T) = Standard_Boolean then
325 KP : constant Node_Kind := Nkind (Parent (N));
328 -- If result is to be used as a Condition in the syntax, no need
329 -- to convert it back, since if it was changed to Standard.Boolean
330 -- using Adjust_Condition, that is just fine for this usage.
332 if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
335 -- If result is an operand of another logical operation, no need
336 -- to reset its type, since Standard.Boolean is just fine, and
337 -- such operations always do Adjust_Condition on their operands.
339 elsif KP in N_Op_Boolean
340 or else KP in N_Short_Circuit
341 or else KP = N_Op_Not
345 -- Otherwise we perform a conversion from the current type, which
346 -- must be Standard.Boolean, to the desired type.
350 Rewrite (N, Convert_To (T, N));
351 Analyze_And_Resolve (N, T);
355 end Adjust_Result_Type;
357 --------------------------
358 -- Append_Freeze_Action --
359 --------------------------
361 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
365 Ensure_Freeze_Node (T);
366 Fnode := Freeze_Node (T);
368 if No (Actions (Fnode)) then
369 Set_Actions (Fnode, New_List (N));
371 Append (N, Actions (Fnode));
374 end Append_Freeze_Action;
376 ---------------------------
377 -- Append_Freeze_Actions --
378 ---------------------------
380 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
388 Ensure_Freeze_Node (T);
389 Fnode := Freeze_Node (T);
391 if No (Actions (Fnode)) then
392 Set_Actions (Fnode, L);
394 Append_List (L, Actions (Fnode));
396 end Append_Freeze_Actions;
398 ------------------------------------
399 -- Build_Allocate_Deallocate_Proc --
400 ------------------------------------
402 procedure Build_Allocate_Deallocate_Proc
404 Is_Allocate : Boolean)
406 Desig_Typ : Entity_Id;
409 Proc_To_Call : Node_Id := Empty;
412 function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id;
413 -- Locate TSS primitive Finalize_Address in type Typ
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
423 ---------------------------
424 -- Find_Finalize_Address --
425 ---------------------------
427 function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id is
428 Utyp : Entity_Id := Typ;
431 -- Handle protected class-wide or task class-wide types
433 if Is_Class_Wide_Type (Utyp) then
434 if Is_Concurrent_Type (Root_Type (Utyp)) then
435 Utyp := Root_Type (Utyp);
437 elsif Is_Private_Type (Root_Type (Utyp))
438 and then Present (Full_View (Root_Type (Utyp)))
439 and then Is_Concurrent_Type (Full_View (Root_Type (Utyp)))
441 Utyp := Full_View (Root_Type (Utyp));
445 -- Handle private types
447 if Is_Private_Type (Utyp) and then Present (Full_View (Utyp)) then
448 Utyp := Full_View (Utyp);
451 -- Handle protected and task types
453 if Is_Concurrent_Type (Utyp)
454 and then Present (Corresponding_Record_Type (Utyp))
456 Utyp := Corresponding_Record_Type (Utyp);
459 Utyp := Underlying_Type (Base_Type (Utyp));
461 -- Deal with non-tagged derivation of private views. If the parent is
462 -- now known to be protected, the finalization routine is the one
463 -- defined on the corresponding record of the ancestor (corresponding
464 -- records do not automatically inherit operations, but maybe they
467 if Is_Untagged_Derivation (Typ) then
468 if Is_Protected_Type (Typ) then
469 Utyp := Corresponding_Record_Type (Root_Type (Base_Type (Typ)));
471 Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
473 if Is_Protected_Type (Utyp) then
474 Utyp := Corresponding_Record_Type (Utyp);
479 -- If the underlying_type is a subtype, we are dealing with the
480 -- completion of a private type. We need to access the base type and
481 -- generate a conversion to it.
483 if Utyp /= Base_Type (Utyp) then
484 pragma Assert (Is_Private_Type (Typ));
486 Utyp := Base_Type (Utyp);
489 -- When dealing with an internally built full view for a type with
490 -- unknown discriminants, use the original record type.
492 if Is_Underlying_Record_View (Utyp) then
493 Utyp := Etype (Utyp);
496 return TSS (Utyp, TSS_Finalize_Address);
497 end Find_Finalize_Address;
503 function Find_Object (E : Node_Id) return Node_Id is
507 pragma Assert (Is_Allocate);
511 if Nkind_In (Expr, N_Qualified_Expression,
512 N_Unchecked_Type_Conversion)
514 Expr := Expression (Expr);
516 elsif Nkind (Expr) = N_Explicit_Dereference then
517 Expr := Prefix (Expr);
527 ---------------------------------
528 -- Is_Allocate_Deallocate_Proc --
529 ---------------------------------
531 function Is_Allocate_Deallocate_Proc (Subp : Entity_Id) return Boolean is
533 -- Look for a subprogram body with only one statement which is a
534 -- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
536 if Ekind (Subp) = E_Procedure
537 and then Nkind (Parent (Parent (Subp))) = N_Subprogram_Body
540 HSS : constant Node_Id :=
541 Handled_Statement_Sequence (Parent (Parent (Subp)));
545 if Present (Statements (HSS))
546 and then Nkind (First (Statements (HSS))) =
547 N_Procedure_Call_Statement
549 Proc := Entity (Name (First (Statements (HSS))));
552 Is_RTE (Proc, RE_Allocate_Any_Controlled)
553 or else Is_RTE (Proc, RE_Deallocate_Any_Controlled);
559 end Is_Allocate_Deallocate_Proc;
561 -- Start of processing for Build_Allocate_Deallocate_Proc
564 -- Do not perform this expansion in Alfa mode because it is not
571 -- Obtain the attributes of the allocation / deallocation
573 if Nkind (N) = N_Free_Statement then
574 Expr := Expression (N);
575 Ptr_Typ := Base_Type (Etype (Expr));
576 Proc_To_Call := Procedure_To_Call (N);
579 if Nkind (N) = N_Object_Declaration then
580 Expr := Expression (N);
585 -- In certain cases an allocator with a qualified expression may
586 -- be relocated and used as the initialization expression of a
590 -- Obj : Ptr_Typ := new Desig_Typ'(...);
593 -- Tmp : Ptr_Typ := new Desig_Typ'(...);
594 -- Obj : Ptr_Typ := Tmp;
596 -- Since the allocator is always marked as analyzed to avoid infinite
597 -- expansion, it will never be processed by this routine given that
598 -- the designated type needs finalization actions. Detect this case
599 -- and complete the expansion of the allocator.
601 if Nkind (Expr) = N_Identifier
602 and then Nkind (Parent (Entity (Expr))) = N_Object_Declaration
603 and then Nkind (Expression (Parent (Entity (Expr)))) = N_Allocator
605 Build_Allocate_Deallocate_Proc (Parent (Entity (Expr)), True);
609 -- The allocator may have been rewritten into something else in which
610 -- case the expansion performed by this routine does not apply.
612 if Nkind (Expr) /= N_Allocator then
616 Ptr_Typ := Base_Type (Etype (Expr));
617 Proc_To_Call := Procedure_To_Call (Expr);
620 Pool_Id := Associated_Storage_Pool (Ptr_Typ);
621 Desig_Typ := Available_View (Designated_Type (Ptr_Typ));
623 -- Handle concurrent types
625 if Is_Concurrent_Type (Desig_Typ)
626 and then Present (Corresponding_Record_Type (Desig_Typ))
628 Desig_Typ := Corresponding_Record_Type (Desig_Typ);
631 -- Do not process allocations / deallocations without a pool
636 -- Do not process allocations on / deallocations from the secondary
639 elsif Is_RTE (Pool_Id, RE_SS_Pool) then
642 -- Do not replicate the machinery if the allocator / free has already
643 -- been expanded and has a custom Allocate / Deallocate.
645 elsif Present (Proc_To_Call)
646 and then Is_Allocate_Deallocate_Proc (Proc_To_Call)
651 if Needs_Finalization (Desig_Typ) then
653 -- Certain run-time configurations and targets do not provide support
654 -- for controlled types.
656 if Restriction_Active (No_Finalization) then
659 -- Do nothing if the access type may never allocate / deallocate
662 elsif No_Pool_Assigned (Ptr_Typ) then
665 -- Access-to-controlled types are not supported on .NET/JVM since
666 -- these targets cannot support pools and address arithmetic.
668 elsif VM_Target /= No_VM then
672 -- The allocation / deallocation of a controlled object must be
673 -- chained on / detached from a finalization master.
675 pragma Assert (Present (Finalization_Master (Ptr_Typ)));
677 -- The only other kind of allocation / deallocation supported by this
678 -- routine is on / from a subpool.
680 elsif Nkind (Expr) = N_Allocator
681 and then No (Subpool_Handle_Name (Expr))
687 Loc : constant Source_Ptr := Sloc (N);
688 Addr_Id : constant Entity_Id := Make_Temporary (Loc, 'A');
689 Alig_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
690 Proc_Id : constant Entity_Id := Make_Temporary (Loc, 'P');
691 Size_Id : constant Entity_Id := Make_Temporary (Loc, 'S');
694 Fin_Addr_Id : Entity_Id;
695 Fin_Mas_Act : Node_Id;
696 Fin_Mas_Id : Entity_Id;
697 Proc_To_Call : Entity_Id;
698 Subpool : Node_Id := Empty;
701 -- Step 1: Construct all the actuals for the call to library routine
702 -- Allocate_Any_Controlled / Deallocate_Any_Controlled.
706 Actuals := New_List (New_Reference_To (Pool_Id, Loc));
712 if Nkind (Expr) = N_Allocator then
713 Subpool := Subpool_Handle_Name (Expr);
716 -- If a subpool is present it can be an arbitrary name, so make
717 -- the actual by copying the tree.
719 if Present (Subpool) then
720 Append_To (Actuals, New_Copy_Tree (Subpool, New_Sloc => Loc));
722 Append_To (Actuals, Make_Null (Loc));
725 -- c) Finalization master
727 if Needs_Finalization (Desig_Typ) then
728 Fin_Mas_Id := Finalization_Master (Ptr_Typ);
729 Fin_Mas_Act := New_Reference_To (Fin_Mas_Id, Loc);
731 -- Handle the case where the master is actually a pointer to a
732 -- master. This case arises in build-in-place functions.
734 if Is_Access_Type (Etype (Fin_Mas_Id)) then
735 Append_To (Actuals, Fin_Mas_Act);
738 Make_Attribute_Reference (Loc,
739 Prefix => Fin_Mas_Act,
740 Attribute_Name => Name_Unrestricted_Access));
743 Append_To (Actuals, Make_Null (Loc));
746 -- d) Finalize_Address
748 -- Primitive Finalize_Address is never generated in CodePeer mode
749 -- since it contains an Unchecked_Conversion.
751 if Needs_Finalization (Desig_Typ) and then not CodePeer_Mode then
752 Fin_Addr_Id := Find_Finalize_Address (Desig_Typ);
753 pragma Assert (Present (Fin_Addr_Id));
756 Make_Attribute_Reference (Loc,
757 Prefix => New_Reference_To (Fin_Addr_Id, Loc),
758 Attribute_Name => Name_Unrestricted_Access));
760 Append_To (Actuals, Make_Null (Loc));
768 Append_To (Actuals, New_Reference_To (Addr_Id, Loc));
769 Append_To (Actuals, New_Reference_To (Size_Id, Loc));
771 if Is_Allocate or else not Is_Class_Wide_Type (Desig_Typ) then
772 Append_To (Actuals, New_Reference_To (Alig_Id, Loc));
774 -- For deallocation of class wide types we obtain the value of
775 -- alignment from the Type Specific Record of the deallocated object.
776 -- This is needed because the frontend expansion of class-wide types
777 -- into equivalent types confuses the backend.
783 -- ... because 'Alignment applied to class-wide types is expanded
784 -- into the code that reads the value of alignment from the TSD
785 -- (see Expand_N_Attribute_Reference)
788 Unchecked_Convert_To (RTE (RE_Storage_Offset),
789 Make_Attribute_Reference (Loc,
791 Make_Explicit_Dereference (Loc, Relocate_Node (Expr)),
792 Attribute_Name => Name_Alignment)));
797 -- Generate a run-time check to determine whether a class-wide object
798 -- is truly controlled.
800 if Needs_Finalization (Desig_Typ) then
801 if Is_Class_Wide_Type (Desig_Typ)
802 or else Is_Generic_Actual_Type (Desig_Typ)
805 Flag_Id : constant Entity_Id := Make_Temporary (Loc, 'F');
812 Temp := Find_Object (Expression (Expr));
817 -- Processing for generic actuals
819 if Is_Generic_Actual_Type (Desig_Typ) then
821 New_Reference_To (Boolean_Literals
822 (Needs_Finalization (Base_Type (Desig_Typ))), Loc);
824 -- Processing for subtype indications
826 elsif Nkind (Temp) in N_Has_Entity
827 and then Is_Type (Entity (Temp))
830 New_Reference_To (Boolean_Literals
831 (Needs_Finalization (Entity (Temp))), Loc);
833 -- Generate a runtime check to test the controlled state of
834 -- an object for the purposes of allocation / deallocation.
837 -- The following case arises when allocating through an
838 -- interface class-wide type, generate:
842 if Is_RTE (Etype (Temp), RE_Tag_Ptr) then
844 Make_Explicit_Dereference (Loc,
846 Relocate_Node (Temp));
853 Make_Attribute_Reference (Loc,
855 Relocate_Node (Temp),
856 Attribute_Name => Name_Tag);
860 -- Needs_Finalization (<Param>)
863 Make_Function_Call (Loc,
865 New_Reference_To (RTE (RE_Needs_Finalization), Loc),
866 Parameter_Associations => New_List (Param));
869 -- Create the temporary which represents the finalization
870 -- state of the expression. Generate:
872 -- F : constant Boolean := <Flag_Expr>;
875 Make_Object_Declaration (Loc,
876 Defining_Identifier => Flag_Id,
877 Constant_Present => True,
879 New_Reference_To (Standard_Boolean, Loc),
880 Expression => Flag_Expr));
882 -- The flag acts as the last actual
884 Append_To (Actuals, New_Reference_To (Flag_Id, Loc));
887 -- The object is statically known to be controlled
890 Append_To (Actuals, New_Reference_To (Standard_True, Loc));
894 Append_To (Actuals, New_Reference_To (Standard_False, Loc));
901 New_Reference_To (Boolean_Literals (Present (Subpool)), Loc));
904 -- Step 2: Build a wrapper Allocate / Deallocate which internally
905 -- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
907 -- Select the proper routine to call
910 Proc_To_Call := RTE (RE_Allocate_Any_Controlled);
912 Proc_To_Call := RTE (RE_Deallocate_Any_Controlled);
915 -- Create a custom Allocate / Deallocate routine which has identical
916 -- profile to that of System.Storage_Pools.
919 Make_Subprogram_Body (Loc,
924 Make_Procedure_Specification (Loc,
925 Defining_Unit_Name => Proc_Id,
926 Parameter_Specifications => New_List (
928 -- P : Root_Storage_Pool
930 Make_Parameter_Specification (Loc,
931 Defining_Identifier => Make_Temporary (Loc, 'P'),
933 New_Reference_To (RTE (RE_Root_Storage_Pool), Loc)),
937 Make_Parameter_Specification (Loc,
938 Defining_Identifier => Addr_Id,
939 Out_Present => Is_Allocate,
941 New_Reference_To (RTE (RE_Address), Loc)),
945 Make_Parameter_Specification (Loc,
946 Defining_Identifier => Size_Id,
948 New_Reference_To (RTE (RE_Storage_Count), Loc)),
952 Make_Parameter_Specification (Loc,
953 Defining_Identifier => Alig_Id,
955 New_Reference_To (RTE (RE_Storage_Count), Loc)))),
957 Declarations => No_List,
959 Handled_Statement_Sequence =>
960 Make_Handled_Sequence_Of_Statements (Loc,
961 Statements => New_List (
962 Make_Procedure_Call_Statement (Loc,
963 Name => New_Reference_To (Proc_To_Call, Loc),
964 Parameter_Associations => Actuals)))));
966 -- The newly generated Allocate / Deallocate becomes the default
967 -- procedure to call when the back end processes the allocation /
971 Set_Procedure_To_Call (Expr, Proc_Id);
973 Set_Procedure_To_Call (N, Proc_Id);
976 end Build_Allocate_Deallocate_Proc;
978 ------------------------
979 -- Build_Runtime_Call --
980 ------------------------
982 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
984 -- If entity is not available, we can skip making the call (this avoids
985 -- junk duplicated error messages in a number of cases).
987 if not RTE_Available (RE) then
988 return Make_Null_Statement (Loc);
991 Make_Procedure_Call_Statement (Loc,
992 Name => New_Reference_To (RTE (RE), Loc));
994 end Build_Runtime_Call;
996 ----------------------------
997 -- Build_Task_Array_Image --
998 ----------------------------
1000 -- This function generates the body for a function that constructs the
1001 -- image string for a task that is an array component. The function is
1002 -- local to the init proc for the array type, and is called for each one
1003 -- of the components. The constructed image has the form of an indexed
1004 -- component, whose prefix is the outer variable of the array type.
1005 -- The n-dimensional array type has known indexes Index, Index2...
1007 -- Id_Ref is an indexed component form created by the enclosing init proc.
1008 -- Its successive indexes are Val1, Val2, ... which are the loop variables
1009 -- in the loops that call the individual task init proc on each component.
1011 -- The generated function has the following structure:
1013 -- function F return String is
1014 -- Pref : string renames Task_Name;
1015 -- T1 : String := Index1'Image (Val1);
1017 -- Tn : String := indexn'image (Valn);
1018 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
1019 -- -- Len includes commas and the end parentheses.
1020 -- Res : String (1..Len);
1021 -- Pos : Integer := Pref'Length;
1024 -- Res (1 .. Pos) := Pref;
1026 -- Res (Pos) := '(';
1028 -- Res (Pos .. Pos + T1'Length - 1) := T1;
1029 -- Pos := Pos + T1'Length;
1030 -- Res (Pos) := '.';
1033 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
1034 -- Res (Len) := ')';
1039 -- Needless to say, multidimensional arrays of tasks are rare enough that
1040 -- the bulkiness of this code is not really a concern.
1042 function Build_Task_Array_Image
1046 Dyn : Boolean := False) return Node_Id
1048 Dims : constant Nat := Number_Dimensions (A_Type);
1049 -- Number of dimensions for array of tasks
1051 Temps : array (1 .. Dims) of Entity_Id;
1052 -- Array of temporaries to hold string for each index
1058 -- Total length of generated name
1061 -- Running index for substring assignments
1063 Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
1064 -- Name of enclosing variable, prefix of resulting name
1067 -- String to hold result
1070 -- Value of successive indexes
1073 -- Expression to compute total size of string
1076 -- Entity for name at one index position
1078 Decls : constant List_Id := New_List;
1079 Stats : constant List_Id := New_List;
1082 -- For a dynamic task, the name comes from the target variable. For a
1083 -- static one it is a formal of the enclosing init proc.
1086 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
1088 Make_Object_Declaration (Loc,
1089 Defining_Identifier => Pref,
1090 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1092 Make_String_Literal (Loc,
1093 Strval => String_From_Name_Buffer)));
1097 Make_Object_Renaming_Declaration (Loc,
1098 Defining_Identifier => Pref,
1099 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
1100 Name => Make_Identifier (Loc, Name_uTask_Name)));
1103 Indx := First_Index (A_Type);
1104 Val := First (Expressions (Id_Ref));
1106 for J in 1 .. Dims loop
1107 T := Make_Temporary (Loc, 'T');
1111 Make_Object_Declaration (Loc,
1112 Defining_Identifier => T,
1113 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1115 Make_Attribute_Reference (Loc,
1116 Attribute_Name => Name_Image,
1117 Prefix => New_Occurrence_Of (Etype (Indx), Loc),
1118 Expressions => New_List (New_Copy_Tree (Val)))));
1124 Sum := Make_Integer_Literal (Loc, Dims + 1);
1130 Make_Attribute_Reference (Loc,
1131 Attribute_Name => Name_Length,
1132 Prefix => New_Occurrence_Of (Pref, Loc),
1133 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
1135 for J in 1 .. Dims loop
1140 Make_Attribute_Reference (Loc,
1141 Attribute_Name => Name_Length,
1143 New_Occurrence_Of (Temps (J), Loc),
1144 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
1147 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
1149 Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
1152 Make_Assignment_Statement (Loc,
1154 Make_Indexed_Component (Loc,
1155 Prefix => New_Occurrence_Of (Res, Loc),
1156 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
1158 Make_Character_Literal (Loc,
1160 Char_Literal_Value => UI_From_Int (Character'Pos ('(')))));
1163 Make_Assignment_Statement (Loc,
1164 Name => New_Occurrence_Of (Pos, Loc),
1167 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1168 Right_Opnd => Make_Integer_Literal (Loc, 1))));
1170 for J in 1 .. Dims loop
1173 Make_Assignment_Statement (Loc,
1176 Prefix => New_Occurrence_Of (Res, Loc),
1179 Low_Bound => New_Occurrence_Of (Pos, Loc),
1181 Make_Op_Subtract (Loc,
1184 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1186 Make_Attribute_Reference (Loc,
1187 Attribute_Name => Name_Length,
1189 New_Occurrence_Of (Temps (J), Loc),
1191 New_List (Make_Integer_Literal (Loc, 1)))),
1192 Right_Opnd => Make_Integer_Literal (Loc, 1)))),
1194 Expression => New_Occurrence_Of (Temps (J), Loc)));
1198 Make_Assignment_Statement (Loc,
1199 Name => New_Occurrence_Of (Pos, Loc),
1202 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1204 Make_Attribute_Reference (Loc,
1205 Attribute_Name => Name_Length,
1206 Prefix => New_Occurrence_Of (Temps (J), Loc),
1208 New_List (Make_Integer_Literal (Loc, 1))))));
1210 Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
1213 Make_Assignment_Statement (Loc,
1214 Name => Make_Indexed_Component (Loc,
1215 Prefix => New_Occurrence_Of (Res, Loc),
1216 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
1218 Make_Character_Literal (Loc,
1220 Char_Literal_Value => UI_From_Int (Character'Pos (',')))));
1223 Make_Assignment_Statement (Loc,
1224 Name => New_Occurrence_Of (Pos, Loc),
1227 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1228 Right_Opnd => Make_Integer_Literal (Loc, 1))));
1232 Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
1235 Make_Assignment_Statement (Loc,
1237 Make_Indexed_Component (Loc,
1238 Prefix => New_Occurrence_Of (Res, Loc),
1239 Expressions => New_List (New_Occurrence_Of (Len, Loc))),
1241 Make_Character_Literal (Loc,
1243 Char_Literal_Value => UI_From_Int (Character'Pos (')')))));
1244 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
1245 end Build_Task_Array_Image;
1247 ----------------------------
1248 -- Build_Task_Image_Decls --
1249 ----------------------------
1251 function Build_Task_Image_Decls
1255 In_Init_Proc : Boolean := False) return List_Id
1257 Decls : constant List_Id := New_List;
1258 T_Id : Entity_Id := Empty;
1260 Expr : Node_Id := Empty;
1261 Fun : Node_Id := Empty;
1262 Is_Dyn : constant Boolean :=
1263 Nkind (Parent (Id_Ref)) = N_Assignment_Statement
1265 Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
1268 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
1269 -- generate a dummy declaration only.
1271 if Restriction_Active (No_Implicit_Heap_Allocations)
1272 or else Global_Discard_Names
1274 T_Id := Make_Temporary (Loc, 'J');
1279 Make_Object_Declaration (Loc,
1280 Defining_Identifier => T_Id,
1281 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1283 Make_String_Literal (Loc,
1284 Strval => String_From_Name_Buffer)));
1287 if Nkind (Id_Ref) = N_Identifier
1288 or else Nkind (Id_Ref) = N_Defining_Identifier
1290 -- For a simple variable, the image of the task is built from
1291 -- the name of the variable. To avoid possible conflict with the
1292 -- anonymous type created for a single protected object, add a
1296 Make_Defining_Identifier (Loc,
1297 New_External_Name (Chars (Id_Ref), 'T', 1));
1299 Get_Name_String (Chars (Id_Ref));
1302 Make_String_Literal (Loc,
1303 Strval => String_From_Name_Buffer);
1305 elsif Nkind (Id_Ref) = N_Selected_Component then
1307 Make_Defining_Identifier (Loc,
1308 New_External_Name (Chars (Selector_Name (Id_Ref)), 'T'));
1309 Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn);
1311 elsif Nkind (Id_Ref) = N_Indexed_Component then
1313 Make_Defining_Identifier (Loc,
1314 New_External_Name (Chars (A_Type), 'N'));
1316 Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
1320 if Present (Fun) then
1321 Append (Fun, Decls);
1322 Expr := Make_Function_Call (Loc,
1323 Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
1325 if not In_Init_Proc and then VM_Target = No_VM then
1326 Set_Uses_Sec_Stack (Defining_Entity (Fun));
1330 Decl := Make_Object_Declaration (Loc,
1331 Defining_Identifier => T_Id,
1332 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1333 Constant_Present => True,
1334 Expression => Expr);
1336 Append (Decl, Decls);
1338 end Build_Task_Image_Decls;
1340 -------------------------------
1341 -- Build_Task_Image_Function --
1342 -------------------------------
1344 function Build_Task_Image_Function
1348 Res : Entity_Id) return Node_Id
1354 Make_Simple_Return_Statement (Loc,
1355 Expression => New_Occurrence_Of (Res, Loc)));
1357 Spec := Make_Function_Specification (Loc,
1358 Defining_Unit_Name => Make_Temporary (Loc, 'F'),
1359 Result_Definition => New_Occurrence_Of (Standard_String, Loc));
1361 -- Calls to 'Image use the secondary stack, which must be cleaned up
1362 -- after the task name is built.
1364 return Make_Subprogram_Body (Loc,
1365 Specification => Spec,
1366 Declarations => Decls,
1367 Handled_Statement_Sequence =>
1368 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats));
1369 end Build_Task_Image_Function;
1371 -----------------------------
1372 -- Build_Task_Image_Prefix --
1373 -----------------------------
1375 procedure Build_Task_Image_Prefix
1377 Len : out Entity_Id;
1378 Res : out Entity_Id;
1379 Pos : out Entity_Id;
1386 Len := Make_Temporary (Loc, 'L', Sum);
1389 Make_Object_Declaration (Loc,
1390 Defining_Identifier => Len,
1391 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
1392 Expression => Sum));
1394 Res := Make_Temporary (Loc, 'R');
1397 Make_Object_Declaration (Loc,
1398 Defining_Identifier => Res,
1399 Object_Definition =>
1400 Make_Subtype_Indication (Loc,
1401 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
1403 Make_Index_Or_Discriminant_Constraint (Loc,
1407 Low_Bound => Make_Integer_Literal (Loc, 1),
1408 High_Bound => New_Occurrence_Of (Len, Loc)))))));
1410 Pos := Make_Temporary (Loc, 'P');
1413 Make_Object_Declaration (Loc,
1414 Defining_Identifier => Pos,
1415 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
1417 -- Pos := Prefix'Length;
1420 Make_Assignment_Statement (Loc,
1421 Name => New_Occurrence_Of (Pos, Loc),
1423 Make_Attribute_Reference (Loc,
1424 Attribute_Name => Name_Length,
1425 Prefix => New_Occurrence_Of (Prefix, Loc),
1426 Expressions => New_List (Make_Integer_Literal (Loc, 1)))));
1428 -- Res (1 .. Pos) := Prefix;
1431 Make_Assignment_Statement (Loc,
1434 Prefix => New_Occurrence_Of (Res, Loc),
1437 Low_Bound => Make_Integer_Literal (Loc, 1),
1438 High_Bound => New_Occurrence_Of (Pos, Loc))),
1440 Expression => New_Occurrence_Of (Prefix, Loc)));
1443 Make_Assignment_Statement (Loc,
1444 Name => New_Occurrence_Of (Pos, Loc),
1447 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1448 Right_Opnd => Make_Integer_Literal (Loc, 1))));
1449 end Build_Task_Image_Prefix;
1451 -----------------------------
1452 -- Build_Task_Record_Image --
1453 -----------------------------
1455 function Build_Task_Record_Image
1458 Dyn : Boolean := False) return Node_Id
1461 -- Total length of generated name
1464 -- Index into result
1467 -- String to hold result
1469 Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
1470 -- Name of enclosing variable, prefix of resulting name
1473 -- Expression to compute total size of string
1476 -- Entity for selector name
1478 Decls : constant List_Id := New_List;
1479 Stats : constant List_Id := New_List;
1482 -- For a dynamic task, the name comes from the target variable. For a
1483 -- static one it is a formal of the enclosing init proc.
1486 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
1488 Make_Object_Declaration (Loc,
1489 Defining_Identifier => Pref,
1490 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1492 Make_String_Literal (Loc,
1493 Strval => String_From_Name_Buffer)));
1497 Make_Object_Renaming_Declaration (Loc,
1498 Defining_Identifier => Pref,
1499 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
1500 Name => Make_Identifier (Loc, Name_uTask_Name)));
1503 Sel := Make_Temporary (Loc, 'S');
1505 Get_Name_String (Chars (Selector_Name (Id_Ref)));
1508 Make_Object_Declaration (Loc,
1509 Defining_Identifier => Sel,
1510 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1512 Make_String_Literal (Loc,
1513 Strval => String_From_Name_Buffer)));
1515 Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
1521 Make_Attribute_Reference (Loc,
1522 Attribute_Name => Name_Length,
1524 New_Occurrence_Of (Pref, Loc),
1525 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
1527 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
1529 Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
1531 -- Res (Pos) := '.';
1534 Make_Assignment_Statement (Loc,
1535 Name => Make_Indexed_Component (Loc,
1536 Prefix => New_Occurrence_Of (Res, Loc),
1537 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
1539 Make_Character_Literal (Loc,
1541 Char_Literal_Value =>
1542 UI_From_Int (Character'Pos ('.')))));
1545 Make_Assignment_Statement (Loc,
1546 Name => New_Occurrence_Of (Pos, Loc),
1549 Left_Opnd => New_Occurrence_Of (Pos, Loc),
1550 Right_Opnd => Make_Integer_Literal (Loc, 1))));
1552 -- Res (Pos .. Len) := Selector;
1555 Make_Assignment_Statement (Loc,
1556 Name => Make_Slice (Loc,
1557 Prefix => New_Occurrence_Of (Res, Loc),
1560 Low_Bound => New_Occurrence_Of (Pos, Loc),
1561 High_Bound => New_Occurrence_Of (Len, Loc))),
1562 Expression => New_Occurrence_Of (Sel, Loc)));
1564 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
1565 end Build_Task_Record_Image;
1567 ----------------------------------
1568 -- Component_May_Be_Bit_Aligned --
1569 ----------------------------------
1571 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
1575 -- If no component clause, then everything is fine, since the back end
1576 -- never bit-misaligns by default, even if there is a pragma Packed for
1579 if No (Comp) or else No (Component_Clause (Comp)) then
1583 UT := Underlying_Type (Etype (Comp));
1585 -- It is only array and record types that cause trouble
1587 if not Is_Record_Type (UT) and then not Is_Array_Type (UT) then
1590 -- If we know that we have a small (64 bits or less) record or small
1591 -- bit-packed array, then everything is fine, since the back end can
1592 -- handle these cases correctly.
1594 elsif Esize (Comp) <= 64
1595 and then (Is_Record_Type (UT) or else Is_Bit_Packed_Array (UT))
1599 -- Otherwise if the component is not byte aligned, we know we have the
1600 -- nasty unaligned case.
1602 elsif Normalized_First_Bit (Comp) /= Uint_0
1603 or else Esize (Comp) mod System_Storage_Unit /= Uint_0
1607 -- If we are large and byte aligned, then OK at this level
1612 end Component_May_Be_Bit_Aligned;
1614 -----------------------------------
1615 -- Corresponding_Runtime_Package --
1616 -----------------------------------
1618 function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id is
1619 Pkg_Id : RTU_Id := RTU_Null;
1622 pragma Assert (Is_Concurrent_Type (Typ));
1624 if Ekind (Typ) in Protected_Kind then
1625 if Has_Entries (Typ)
1627 -- A protected type without entries that covers an interface and
1628 -- overrides the abstract routines with protected procedures is
1629 -- considered equivalent to a protected type with entries in the
1630 -- context of dispatching select statements. It is sufficient to
1631 -- check for the presence of an interface list in the declaration
1632 -- node to recognize this case.
1634 or else Present (Interface_List (Parent (Typ)))
1636 (((Has_Attach_Handler (Typ) and then not Restricted_Profile)
1637 or else Has_Interrupt_Handler (Typ))
1638 and then not Restriction_Active (No_Dynamic_Attachment))
1641 or else Restriction_Active (No_Entry_Queue) = False
1642 or else Number_Entries (Typ) > 1
1643 or else (Has_Attach_Handler (Typ)
1644 and then not Restricted_Profile)
1646 Pkg_Id := System_Tasking_Protected_Objects_Entries;
1648 Pkg_Id := System_Tasking_Protected_Objects_Single_Entry;
1652 Pkg_Id := System_Tasking_Protected_Objects;
1657 end Corresponding_Runtime_Package;
1659 -------------------------------
1660 -- Convert_To_Actual_Subtype --
1661 -------------------------------
1663 procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
1667 Act_ST := Get_Actual_Subtype (Exp);
1669 if Act_ST = Etype (Exp) then
1672 Rewrite (Exp, Convert_To (Act_ST, Relocate_Node (Exp)));
1673 Analyze_And_Resolve (Exp, Act_ST);
1675 end Convert_To_Actual_Subtype;
1677 -----------------------------------
1678 -- Current_Sem_Unit_Declarations --
1679 -----------------------------------
1681 function Current_Sem_Unit_Declarations return List_Id is
1682 U : Node_Id := Unit (Cunit (Current_Sem_Unit));
1686 -- If the current unit is a package body, locate the visible
1687 -- declarations of the package spec.
1689 if Nkind (U) = N_Package_Body then
1690 U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
1693 if Nkind (U) = N_Package_Declaration then
1694 U := Specification (U);
1695 Decls := Visible_Declarations (U);
1699 Set_Visible_Declarations (U, Decls);
1703 Decls := Declarations (U);
1707 Set_Declarations (U, Decls);
1712 end Current_Sem_Unit_Declarations;
1714 -----------------------
1715 -- Duplicate_Subexpr --
1716 -----------------------
1718 function Duplicate_Subexpr
1720 Name_Req : Boolean := False) return Node_Id
1723 Remove_Side_Effects (Exp, Name_Req);
1724 return New_Copy_Tree (Exp);
1725 end Duplicate_Subexpr;
1727 ---------------------------------
1728 -- Duplicate_Subexpr_No_Checks --
1729 ---------------------------------
1731 function Duplicate_Subexpr_No_Checks
1733 Name_Req : Boolean := False) return Node_Id
1737 Remove_Side_Effects (Exp, Name_Req);
1738 New_Exp := New_Copy_Tree (Exp);
1739 Remove_Checks (New_Exp);
1741 end Duplicate_Subexpr_No_Checks;
1743 -----------------------------------
1744 -- Duplicate_Subexpr_Move_Checks --
1745 -----------------------------------
1747 function Duplicate_Subexpr_Move_Checks
1749 Name_Req : Boolean := False) return Node_Id
1753 Remove_Side_Effects (Exp, Name_Req);
1754 New_Exp := New_Copy_Tree (Exp);
1755 Remove_Checks (Exp);
1757 end Duplicate_Subexpr_Move_Checks;
1759 --------------------
1760 -- Ensure_Defined --
1761 --------------------
1763 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
1767 -- An itype reference must only be created if this is a local itype, so
1768 -- that gigi can elaborate it on the proper objstack.
1770 if Is_Itype (Typ) and then Scope (Typ) = Current_Scope then
1771 IR := Make_Itype_Reference (Sloc (N));
1772 Set_Itype (IR, Typ);
1773 Insert_Action (N, IR);
1777 --------------------
1778 -- Entry_Names_OK --
1779 --------------------
1781 function Entry_Names_OK return Boolean is
1784 not Restricted_Profile
1785 and then not Global_Discard_Names
1786 and then not Restriction_Active (No_Implicit_Heap_Allocations)
1787 and then not Restriction_Active (No_Local_Allocators);
1794 procedure Evaluate_Name (Nam : Node_Id) is
1795 K : constant Node_Kind := Nkind (Nam);
1798 -- For an explicit dereference, we simply force the evaluation of the
1799 -- name expression. The dereference provides a value that is the address
1800 -- for the renamed object, and it is precisely this value that we want
1803 if K = N_Explicit_Dereference then
1804 Force_Evaluation (Prefix (Nam));
1806 -- For a selected component, we simply evaluate the prefix
1808 elsif K = N_Selected_Component then
1809 Evaluate_Name (Prefix (Nam));
1811 -- For an indexed component, or an attribute reference, we evaluate the
1812 -- prefix, which is itself a name, recursively, and then force the
1813 -- evaluation of all the subscripts (or attribute expressions).
1815 elsif Nkind_In (K, N_Indexed_Component, N_Attribute_Reference) then
1816 Evaluate_Name (Prefix (Nam));
1822 E := First (Expressions (Nam));
1823 while Present (E) loop
1824 Force_Evaluation (E);
1826 if Original_Node (E) /= E then
1827 Set_Do_Range_Check (E, Do_Range_Check (Original_Node (E)));
1834 -- For a slice, we evaluate the prefix, as for the indexed component
1835 -- case and then, if there is a range present, either directly or as the
1836 -- constraint of a discrete subtype indication, we evaluate the two
1837 -- bounds of this range.
1839 elsif K = N_Slice then
1840 Evaluate_Name (Prefix (Nam));
1843 DR : constant Node_Id := Discrete_Range (Nam);
1848 if Nkind (DR) = N_Range then
1849 Force_Evaluation (Low_Bound (DR));
1850 Force_Evaluation (High_Bound (DR));
1852 elsif Nkind (DR) = N_Subtype_Indication then
1853 Constr := Constraint (DR);
1855 if Nkind (Constr) = N_Range_Constraint then
1856 Rexpr := Range_Expression (Constr);
1858 Force_Evaluation (Low_Bound (Rexpr));
1859 Force_Evaluation (High_Bound (Rexpr));
1864 -- For a type conversion, the expression of the conversion must be the
1865 -- name of an object, and we simply need to evaluate this name.
1867 elsif K = N_Type_Conversion then
1868 Evaluate_Name (Expression (Nam));
1870 -- For a function call, we evaluate the call
1872 elsif K = N_Function_Call then
1873 Force_Evaluation (Nam);
1875 -- The remaining cases are direct name, operator symbol and character
1876 -- literal. In all these cases, we do nothing, since we want to
1877 -- reevaluate each time the renamed object is used.
1884 ---------------------
1885 -- Evolve_And_Then --
1886 ---------------------
1888 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
1894 Make_And_Then (Sloc (Cond1),
1896 Right_Opnd => Cond1);
1898 end Evolve_And_Then;
1900 --------------------
1901 -- Evolve_Or_Else --
1902 --------------------
1904 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
1910 Make_Or_Else (Sloc (Cond1),
1912 Right_Opnd => Cond1);
1916 ------------------------------
1917 -- Expand_Subtype_From_Expr --
1918 ------------------------------
1920 -- This function is applicable for both static and dynamic allocation of
1921 -- objects which are constrained by an initial expression. Basically it
1922 -- transforms an unconstrained subtype indication into a constrained one.
1924 -- The expression may also be transformed in certain cases in order to
1925 -- avoid multiple evaluation. In the static allocation case, the general
1930 -- is transformed into
1932 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1934 -- Here are the main cases :
1936 -- <if Expr is a Slice>
1937 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1939 -- <elsif Expr is a String Literal>
1940 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
1942 -- <elsif Expr is Constrained>
1943 -- subtype T is Type_Of_Expr
1946 -- <elsif Expr is an entity_name>
1947 -- Val : T (constraints taken from Expr) := Expr;
1950 -- type Axxx is access all T;
1951 -- Rval : Axxx := Expr'ref;
1952 -- Val : T (constraints taken from Rval) := Rval.all;
1954 -- ??? note: when the Expression is allocated in the secondary stack
1955 -- we could use it directly instead of copying it by declaring
1956 -- Val : T (...) renames Rval.all
1958 procedure Expand_Subtype_From_Expr
1960 Unc_Type : Entity_Id;
1961 Subtype_Indic : Node_Id;
1964 Loc : constant Source_Ptr := Sloc (N);
1965 Exp_Typ : constant Entity_Id := Etype (Exp);
1969 -- In general we cannot build the subtype if expansion is disabled,
1970 -- because internal entities may not have been defined. However, to
1971 -- avoid some cascaded errors, we try to continue when the expression is
1972 -- an array (or string), because it is safe to compute the bounds. It is
1973 -- in fact required to do so even in a generic context, because there
1974 -- may be constants that depend on the bounds of a string literal, both
1975 -- standard string types and more generally arrays of characters.
1977 if not Expander_Active
1978 and then (No (Etype (Exp)) or else not Is_String_Type (Etype (Exp)))
1983 if Nkind (Exp) = N_Slice then
1985 Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
1988 Rewrite (Subtype_Indic,
1989 Make_Subtype_Indication (Loc,
1990 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
1992 Make_Index_Or_Discriminant_Constraint (Loc,
1993 Constraints => New_List
1994 (New_Reference_To (Slice_Type, Loc)))));
1996 -- This subtype indication may be used later for constraint checks
1997 -- we better make sure that if a variable was used as a bound of
1998 -- of the original slice, its value is frozen.
2000 Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
2001 Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
2004 elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
2005 Rewrite (Subtype_Indic,
2006 Make_Subtype_Indication (Loc,
2007 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
2009 Make_Index_Or_Discriminant_Constraint (Loc,
2010 Constraints => New_List (
2011 Make_Literal_Range (Loc,
2012 Literal_Typ => Exp_Typ)))));
2014 elsif Is_Constrained (Exp_Typ)
2015 and then not Is_Class_Wide_Type (Unc_Type)
2017 if Is_Itype (Exp_Typ) then
2019 -- Within an initialization procedure, a selected component
2020 -- denotes a component of the enclosing record, and it appears as
2021 -- an actual in a call to its own initialization procedure. If
2022 -- this component depends on the outer discriminant, we must
2023 -- generate the proper actual subtype for it.
2025 if Nkind (Exp) = N_Selected_Component
2026 and then Within_Init_Proc
2029 Decl : constant Node_Id :=
2030 Build_Actual_Subtype_Of_Component (Exp_Typ, Exp);
2032 if Present (Decl) then
2033 Insert_Action (N, Decl);
2034 T := Defining_Identifier (Decl);
2040 -- No need to generate a new one (new what???)
2047 T := Make_Temporary (Loc, 'T');
2050 Make_Subtype_Declaration (Loc,
2051 Defining_Identifier => T,
2052 Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
2054 -- This type is marked as an itype even though it has an explicit
2055 -- declaration since otherwise Is_Generic_Actual_Type can get
2056 -- set, resulting in the generation of spurious errors. (See
2057 -- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
2060 Set_Associated_Node_For_Itype (T, Exp);
2063 Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
2065 -- Nothing needs to be done for private types with unknown discriminants
2066 -- if the underlying type is not an unconstrained composite type or it
2067 -- is an unchecked union.
2069 elsif Is_Private_Type (Unc_Type)
2070 and then Has_Unknown_Discriminants (Unc_Type)
2071 and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
2072 or else Is_Constrained (Underlying_Type (Unc_Type))
2073 or else Is_Unchecked_Union (Underlying_Type (Unc_Type)))
2077 -- Case of derived type with unknown discriminants where the parent type
2078 -- also has unknown discriminants.
2080 elsif Is_Record_Type (Unc_Type)
2081 and then not Is_Class_Wide_Type (Unc_Type)
2082 and then Has_Unknown_Discriminants (Unc_Type)
2083 and then Has_Unknown_Discriminants (Underlying_Type (Unc_Type))
2085 -- Nothing to be done if no underlying record view available
2087 if No (Underlying_Record_View (Unc_Type)) then
2090 -- Otherwise use the Underlying_Record_View to create the proper
2091 -- constrained subtype for an object of a derived type with unknown
2095 Remove_Side_Effects (Exp);
2096 Rewrite (Subtype_Indic,
2097 Make_Subtype_From_Expr (Exp, Underlying_Record_View (Unc_Type)));
2100 -- Renamings of class-wide interface types require no equivalent
2101 -- constrained type declarations because we only need to reference
2102 -- the tag component associated with the interface. The same is
2103 -- presumably true for class-wide types in general, so this test
2104 -- is broadened to include all class-wide renamings, which also
2105 -- avoids cases of unbounded recursion in Remove_Side_Effects.
2106 -- (Is this really correct, or are there some cases of class-wide
2107 -- renamings that require action in this procedure???)
2110 and then Nkind (N) = N_Object_Renaming_Declaration
2111 and then Is_Class_Wide_Type (Unc_Type)
2115 -- In Ada 95 nothing to be done if the type of the expression is limited
2116 -- because in this case the expression cannot be copied, and its use can
2117 -- only be by reference.
2119 -- In Ada 2005 the context can be an object declaration whose expression
2120 -- is a function that returns in place. If the nominal subtype has
2121 -- unknown discriminants, the call still provides constraints on the
2122 -- object, and we have to create an actual subtype from it.
2124 -- If the type is class-wide, the expression is dynamically tagged and
2125 -- we do not create an actual subtype either. Ditto for an interface.
2126 -- For now this applies only if the type is immutably limited, and the
2127 -- function being called is build-in-place. This will have to be revised
2128 -- when build-in-place functions are generalized to other types.
2130 elsif Is_Immutably_Limited_Type (Exp_Typ)
2132 (Is_Class_Wide_Type (Exp_Typ)
2133 or else Is_Interface (Exp_Typ)
2134 or else not Has_Unknown_Discriminants (Exp_Typ)
2135 or else not Is_Composite_Type (Unc_Type))
2139 -- For limited objects initialized with build in place function calls,
2140 -- nothing to be done; otherwise we prematurely introduce an N_Reference
2141 -- node in the expression initializing the object, which breaks the
2142 -- circuitry that detects and adds the additional arguments to the
2145 elsif Is_Build_In_Place_Function_Call (Exp) then
2149 Remove_Side_Effects (Exp);
2150 Rewrite (Subtype_Indic,
2151 Make_Subtype_From_Expr (Exp, Unc_Type));
2153 end Expand_Subtype_From_Expr;
2155 ------------------------
2156 -- Find_Interface_ADT --
2157 ------------------------
2159 function Find_Interface_ADT
2161 Iface : Entity_Id) return Elmt_Id
2164 Typ : Entity_Id := T;
2167 pragma Assert (Is_Interface (Iface));
2169 -- Handle private types
2171 if Has_Private_Declaration (Typ) and then Present (Full_View (Typ)) then
2172 Typ := Full_View (Typ);
2175 -- Handle access types
2177 if Is_Access_Type (Typ) then
2178 Typ := Designated_Type (Typ);
2181 -- Handle task and protected types implementing interfaces
2183 if Is_Concurrent_Type (Typ) then
2184 Typ := Corresponding_Record_Type (Typ);
2188 (not Is_Class_Wide_Type (Typ)
2189 and then Ekind (Typ) /= E_Incomplete_Type);
2191 if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
2192 return First_Elmt (Access_Disp_Table (Typ));
2196 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
2198 and then Present (Related_Type (Node (ADT)))
2199 and then Related_Type (Node (ADT)) /= Iface
2200 and then not Is_Ancestor (Iface, Related_Type (Node (ADT)),
2201 Use_Full_View => True)
2206 pragma Assert (Present (Related_Type (Node (ADT))));
2209 end Find_Interface_ADT;
2211 ------------------------
2212 -- Find_Interface_Tag --
2213 ------------------------
2215 function Find_Interface_Tag
2217 Iface : Entity_Id) return Entity_Id
2220 Found : Boolean := False;
2221 Typ : Entity_Id := T;
2223 procedure Find_Tag (Typ : Entity_Id);
2224 -- Internal subprogram used to recursively climb to the ancestors
2230 procedure Find_Tag (Typ : Entity_Id) is
2235 -- This routine does not handle the case in which the interface is an
2236 -- ancestor of Typ. That case is handled by the enclosing subprogram.
2238 pragma Assert (Typ /= Iface);
2240 -- Climb to the root type handling private types
2242 if Present (Full_View (Etype (Typ))) then
2243 if Full_View (Etype (Typ)) /= Typ then
2244 Find_Tag (Full_View (Etype (Typ)));
2247 elsif Etype (Typ) /= Typ then
2248 Find_Tag (Etype (Typ));
2251 -- Traverse the list of interfaces implemented by the type
2254 and then Present (Interfaces (Typ))
2255 and then not (Is_Empty_Elmt_List (Interfaces (Typ)))
2257 -- Skip the tag associated with the primary table
2259 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
2260 AI_Tag := Next_Tag_Component (First_Tag_Component (Typ));
2261 pragma Assert (Present (AI_Tag));
2263 AI_Elmt := First_Elmt (Interfaces (Typ));
2264 while Present (AI_Elmt) loop
2265 AI := Node (AI_Elmt);
2268 or else Is_Ancestor (Iface, AI, Use_Full_View => True)
2274 AI_Tag := Next_Tag_Component (AI_Tag);
2275 Next_Elmt (AI_Elmt);
2280 -- Start of processing for Find_Interface_Tag
2283 pragma Assert (Is_Interface (Iface));
2285 -- Handle access types
2287 if Is_Access_Type (Typ) then
2288 Typ := Designated_Type (Typ);
2291 -- Handle class-wide types
2293 if Is_Class_Wide_Type (Typ) then
2294 Typ := Root_Type (Typ);
2297 -- Handle private types
2299 if Has_Private_Declaration (Typ) and then Present (Full_View (Typ)) then
2300 Typ := Full_View (Typ);
2303 -- Handle entities from the limited view
2305 if Ekind (Typ) = E_Incomplete_Type then
2306 pragma Assert (Present (Non_Limited_View (Typ)));
2307 Typ := Non_Limited_View (Typ);
2310 -- Handle task and protected types implementing interfaces
2312 if Is_Concurrent_Type (Typ) then
2313 Typ := Corresponding_Record_Type (Typ);
2316 -- If the interface is an ancestor of the type, then it shared the
2317 -- primary dispatch table.
2319 if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
2320 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
2321 return First_Tag_Component (Typ);
2323 -- Otherwise we need to search for its associated tag component
2327 pragma Assert (Found);
2330 end Find_Interface_Tag;
2336 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
2338 Typ : Entity_Id := T;
2342 if Is_Class_Wide_Type (Typ) then
2343 Typ := Root_Type (Typ);
2346 Typ := Underlying_Type (Typ);
2348 -- Loop through primitive operations
2350 Prim := First_Elmt (Primitive_Operations (Typ));
2351 while Present (Prim) loop
2354 -- We can retrieve primitive operations by name if it is an internal
2355 -- name. For equality we must check that both of its operands have
2356 -- the same type, to avoid confusion with user-defined equalities
2357 -- than may have a non-symmetric signature.
2359 exit when Chars (Op) = Name
2362 or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op)));
2366 -- Raise Program_Error if no primitive found
2369 raise Program_Error;
2380 function Find_Prim_Op
2382 Name : TSS_Name_Type) return Entity_Id
2384 Inher_Op : Entity_Id := Empty;
2385 Own_Op : Entity_Id := Empty;
2386 Prim_Elmt : Elmt_Id;
2387 Prim_Id : Entity_Id;
2388 Typ : Entity_Id := T;
2391 if Is_Class_Wide_Type (Typ) then
2392 Typ := Root_Type (Typ);
2395 Typ := Underlying_Type (Typ);
2397 -- This search is based on the assertion that the dispatching version
2398 -- of the TSS routine always precedes the real primitive.
2400 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
2401 while Present (Prim_Elmt) loop
2402 Prim_Id := Node (Prim_Elmt);
2404 if Is_TSS (Prim_Id, Name) then
2405 if Present (Alias (Prim_Id)) then
2406 Inher_Op := Prim_Id;
2412 Next_Elmt (Prim_Elmt);
2415 if Present (Own_Op) then
2417 elsif Present (Inher_Op) then
2420 raise Program_Error;
2424 ----------------------------
2425 -- Find_Protection_Object --
2426 ----------------------------
2428 function Find_Protection_Object (Scop : Entity_Id) return Entity_Id is
2433 while Present (S) loop
2434 if Ekind_In (S, E_Entry, E_Entry_Family, E_Function, E_Procedure)
2435 and then Present (Protection_Object (S))
2437 return Protection_Object (S);
2443 -- If we do not find a Protection object in the scope chain, then
2444 -- something has gone wrong, most likely the object was never created.
2446 raise Program_Error;
2447 end Find_Protection_Object;
2449 --------------------------
2450 -- Find_Protection_Type --
2451 --------------------------
2453 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
2455 Typ : Entity_Id := Conc_Typ;
2458 if Is_Concurrent_Type (Typ) then
2459 Typ := Corresponding_Record_Type (Typ);
2462 -- Since restriction violations are not considered serious errors, the
2463 -- expander remains active, but may leave the corresponding record type
2464 -- malformed. In such cases, component _object is not available so do
2467 if not Analyzed (Typ) then
2471 Comp := First_Component (Typ);
2472 while Present (Comp) loop
2473 if Chars (Comp) = Name_uObject then
2474 return Base_Type (Etype (Comp));
2477 Next_Component (Comp);
2480 -- The corresponding record of a protected type should always have an
2483 raise Program_Error;
2484 end Find_Protection_Type;
2486 ----------------------
2487 -- Force_Evaluation --
2488 ----------------------
2490 procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
2492 Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
2493 end Force_Evaluation;
2495 ---------------------------------
2496 -- Fully_Qualified_Name_String --
2497 ---------------------------------
2499 function Fully_Qualified_Name_String (E : Entity_Id) return String_Id is
2500 procedure Internal_Full_Qualified_Name (E : Entity_Id);
2501 -- Compute recursively the qualified name without NUL at the end, adding
2502 -- it to the currently started string being generated
2504 ----------------------------------
2505 -- Internal_Full_Qualified_Name --
2506 ----------------------------------
2508 procedure Internal_Full_Qualified_Name (E : Entity_Id) is
2512 -- Deal properly with child units
2514 if Nkind (E) = N_Defining_Program_Unit_Name then
2515 Ent := Defining_Identifier (E);
2520 -- Compute qualification recursively (only "Standard" has no scope)
2522 if Present (Scope (Scope (Ent))) then
2523 Internal_Full_Qualified_Name (Scope (Ent));
2524 Store_String_Char (Get_Char_Code ('.'));
2527 -- Every entity should have a name except some expanded blocks
2528 -- don't bother about those.
2530 if Chars (Ent) = No_Name then
2534 -- Generates the entity name in upper case
2536 Get_Decoded_Name_String (Chars (Ent));
2538 Store_String_Chars (Name_Buffer (1 .. Name_Len));
2540 end Internal_Full_Qualified_Name;
2542 -- Start of processing for Full_Qualified_Name
2546 Internal_Full_Qualified_Name (E);
2547 Store_String_Char (Get_Char_Code (ASCII.NUL));
2549 end Fully_Qualified_Name_String;
2551 ------------------------
2552 -- Generate_Poll_Call --
2553 ------------------------
2555 procedure Generate_Poll_Call (N : Node_Id) is
2557 -- No poll call if polling not active
2559 if not Polling_Required then
2562 -- Otherwise generate require poll call
2565 Insert_Before_And_Analyze (N,
2566 Make_Procedure_Call_Statement (Sloc (N),
2567 Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
2569 end Generate_Poll_Call;
2571 ---------------------------------
2572 -- Get_Current_Value_Condition --
2573 ---------------------------------
2575 -- Note: the implementation of this procedure is very closely tied to the
2576 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
2577 -- interpret Current_Value fields set by the Set procedure, so the two
2578 -- procedures need to be closely coordinated.
2580 procedure Get_Current_Value_Condition
2585 Loc : constant Source_Ptr := Sloc (Var);
2586 Ent : constant Entity_Id := Entity (Var);
2588 procedure Process_Current_Value_Condition
2591 -- N is an expression which holds either True (S = True) or False (S =
2592 -- False) in the condition. This procedure digs out the expression and
2593 -- if it refers to Ent, sets Op and Val appropriately.
2595 -------------------------------------
2596 -- Process_Current_Value_Condition --
2597 -------------------------------------
2599 procedure Process_Current_Value_Condition
2610 -- Deal with NOT operators, inverting sense
2612 while Nkind (Cond) = N_Op_Not loop
2613 Cond := Right_Opnd (Cond);
2617 -- Deal with AND THEN and AND cases
2619 if Nkind_In (Cond, N_And_Then, N_Op_And) then
2621 -- Don't ever try to invert a condition that is of the form of an
2622 -- AND or AND THEN (since we are not doing sufficiently general
2623 -- processing to allow this).
2625 if Sens = False then
2631 -- Recursively process AND and AND THEN branches
2633 Process_Current_Value_Condition (Left_Opnd (Cond), True);
2635 if Op /= N_Empty then
2639 Process_Current_Value_Condition (Right_Opnd (Cond), True);
2642 -- Case of relational operator
2644 elsif Nkind (Cond) in N_Op_Compare then
2647 -- Invert sense of test if inverted test
2649 if Sens = False then
2651 when N_Op_Eq => Op := N_Op_Ne;
2652 when N_Op_Ne => Op := N_Op_Eq;
2653 when N_Op_Lt => Op := N_Op_Ge;
2654 when N_Op_Gt => Op := N_Op_Le;
2655 when N_Op_Le => Op := N_Op_Gt;
2656 when N_Op_Ge => Op := N_Op_Lt;
2657 when others => raise Program_Error;
2661 -- Case of entity op value
2663 if Is_Entity_Name (Left_Opnd (Cond))
2664 and then Ent = Entity (Left_Opnd (Cond))
2665 and then Compile_Time_Known_Value (Right_Opnd (Cond))
2667 Val := Right_Opnd (Cond);
2669 -- Case of value op entity
2671 elsif Is_Entity_Name (Right_Opnd (Cond))
2672 and then Ent = Entity (Right_Opnd (Cond))
2673 and then Compile_Time_Known_Value (Left_Opnd (Cond))
2675 Val := Left_Opnd (Cond);
2677 -- We are effectively swapping operands
2680 when N_Op_Eq => null;
2681 when N_Op_Ne => null;
2682 when N_Op_Lt => Op := N_Op_Gt;
2683 when N_Op_Gt => Op := N_Op_Lt;
2684 when N_Op_Le => Op := N_Op_Ge;
2685 when N_Op_Ge => Op := N_Op_Le;
2686 when others => raise Program_Error;
2695 -- Case of Boolean variable reference, return as though the
2696 -- reference had said var = True.
2699 if Is_Entity_Name (Cond) and then Ent = Entity (Cond) then
2700 Val := New_Occurrence_Of (Standard_True, Sloc (Cond));
2702 if Sens = False then
2709 end Process_Current_Value_Condition;
2711 -- Start of processing for Get_Current_Value_Condition
2717 -- Immediate return, nothing doing, if this is not an object
2719 if Ekind (Ent) not in Object_Kind then
2723 -- Otherwise examine current value
2726 CV : constant Node_Id := Current_Value (Ent);
2731 -- If statement. Condition is known true in THEN section, known False
2732 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
2734 if Nkind (CV) = N_If_Statement then
2736 -- Before start of IF statement
2738 if Loc < Sloc (CV) then
2741 -- After end of IF statement
2743 elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then
2747 -- At this stage we know that we are within the IF statement, but
2748 -- unfortunately, the tree does not record the SLOC of the ELSE so
2749 -- we cannot use a simple SLOC comparison to distinguish between
2750 -- the then/else statements, so we have to climb the tree.
2757 while Parent (N) /= CV loop
2760 -- If we fall off the top of the tree, then that's odd, but
2761 -- perhaps it could occur in some error situation, and the
2762 -- safest response is simply to assume that the outcome of
2763 -- the condition is unknown. No point in bombing during an
2764 -- attempt to optimize things.
2771 -- Now we have N pointing to a node whose parent is the IF
2772 -- statement in question, so now we can tell if we are within
2773 -- the THEN statements.
2775 if Is_List_Member (N)
2776 and then List_Containing (N) = Then_Statements (CV)
2780 -- If the variable reference does not come from source, we
2781 -- cannot reliably tell whether it appears in the else part.
2782 -- In particular, if it appears in generated code for a node
2783 -- that requires finalization, it may be attached to a list
2784 -- that has not been yet inserted into the code. For now,
2785 -- treat it as unknown.
2787 elsif not Comes_From_Source (N) then
2790 -- Otherwise we must be in ELSIF or ELSE part
2797 -- ELSIF part. Condition is known true within the referenced
2798 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
2799 -- and unknown before the ELSE part or after the IF statement.
2801 elsif Nkind (CV) = N_Elsif_Part then
2803 -- if the Elsif_Part had condition_actions, the elsif has been
2804 -- rewritten as a nested if, and the original elsif_part is
2805 -- detached from the tree, so there is no way to obtain useful
2806 -- information on the current value of the variable.
2807 -- Can this be improved ???
2809 if No (Parent (CV)) then
2815 -- Before start of ELSIF part
2817 if Loc < Sloc (CV) then
2820 -- After end of IF statement
2822 elsif Loc >= Sloc (Stm) +
2823 Text_Ptr (UI_To_Int (End_Span (Stm)))
2828 -- Again we lack the SLOC of the ELSE, so we need to climb the
2829 -- tree to see if we are within the ELSIF part in question.
2836 while Parent (N) /= Stm loop
2839 -- If we fall off the top of the tree, then that's odd, but
2840 -- perhaps it could occur in some error situation, and the
2841 -- safest response is simply to assume that the outcome of
2842 -- the condition is unknown. No point in bombing during an
2843 -- attempt to optimize things.
2850 -- Now we have N pointing to a node whose parent is the IF
2851 -- statement in question, so see if is the ELSIF part we want.
2852 -- the THEN statements.
2857 -- Otherwise we must be in subsequent ELSIF or ELSE part
2864 -- Iteration scheme of while loop. The condition is known to be
2865 -- true within the body of the loop.
2867 elsif Nkind (CV) = N_Iteration_Scheme then
2869 Loop_Stmt : constant Node_Id := Parent (CV);
2872 -- Before start of body of loop
2874 if Loc < Sloc (Loop_Stmt) then
2877 -- After end of LOOP statement
2879 elsif Loc >= Sloc (End_Label (Loop_Stmt)) then
2882 -- We are within the body of the loop
2889 -- All other cases of Current_Value settings
2895 -- If we fall through here, then we have a reportable condition, Sens
2896 -- is True if the condition is true and False if it needs inverting.
2898 Process_Current_Value_Condition (Condition (CV), Sens);
2900 end Get_Current_Value_Condition;
2902 ---------------------
2903 -- Get_Stream_Size --
2904 ---------------------
2906 function Get_Stream_Size (E : Entity_Id) return Uint is
2908 -- If we have a Stream_Size clause for this type use it
2910 if Has_Stream_Size_Clause (E) then
2911 return Static_Integer (Expression (Stream_Size_Clause (E)));
2913 -- Otherwise the Stream_Size if the size of the type
2918 end Get_Stream_Size;
2920 ---------------------------
2921 -- Has_Access_Constraint --
2922 ---------------------------
2924 function Has_Access_Constraint (E : Entity_Id) return Boolean is
2926 T : constant Entity_Id := Etype (E);
2929 if Has_Per_Object_Constraint (E) and then Has_Discriminants (T) then
2930 Disc := First_Discriminant (T);
2931 while Present (Disc) loop
2932 if Is_Access_Type (Etype (Disc)) then
2936 Next_Discriminant (Disc);
2943 end Has_Access_Constraint;
2945 ----------------------------------
2946 -- Has_Following_Address_Clause --
2947 ----------------------------------
2949 -- Should this function check the private part in a package ???
2951 function Has_Following_Address_Clause (D : Node_Id) return Boolean is
2952 Id : constant Entity_Id := Defining_Identifier (D);
2957 while Present (Decl) loop
2958 if Nkind (Decl) = N_At_Clause
2959 and then Chars (Identifier (Decl)) = Chars (Id)
2963 elsif Nkind (Decl) = N_Attribute_Definition_Clause
2964 and then Chars (Decl) = Name_Address
2965 and then Chars (Name (Decl)) = Chars (Id)
2974 end Has_Following_Address_Clause;
2976 --------------------
2977 -- Homonym_Number --
2978 --------------------
2980 function Homonym_Number (Subp : Entity_Id) return Nat is
2986 Hom := Homonym (Subp);
2987 while Present (Hom) loop
2988 if Scope (Hom) = Scope (Subp) then
2992 Hom := Homonym (Hom);
2998 -----------------------------------
2999 -- In_Library_Level_Package_Body --
3000 -----------------------------------
3002 function In_Library_Level_Package_Body (Id : Entity_Id) return Boolean is
3004 -- First determine whether the entity appears at the library level, then
3005 -- look at the containing unit.
3007 if Is_Library_Level_Entity (Id) then
3009 Container : constant Node_Id := Cunit (Get_Source_Unit (Id));
3012 return Nkind (Unit (Container)) = N_Package_Body;
3017 end In_Library_Level_Package_Body;
3019 ------------------------------
3020 -- In_Unconditional_Context --
3021 ------------------------------
3023 function In_Unconditional_Context (Node : Node_Id) return Boolean is
3028 while Present (P) loop
3030 when N_Subprogram_Body =>
3033 when N_If_Statement =>
3036 when N_Loop_Statement =>
3039 when N_Case_Statement =>
3048 end In_Unconditional_Context;
3054 procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
3056 if Present (Ins_Action) then
3057 Insert_Actions (Assoc_Node, New_List (Ins_Action));
3061 -- Version with check(s) suppressed
3063 procedure Insert_Action
3064 (Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
3067 Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
3070 -------------------------
3071 -- Insert_Action_After --
3072 -------------------------
3074 procedure Insert_Action_After
3075 (Assoc_Node : Node_Id;
3076 Ins_Action : Node_Id)
3079 Insert_Actions_After (Assoc_Node, New_List (Ins_Action));
3080 end Insert_Action_After;
3082 --------------------
3083 -- Insert_Actions --
3084 --------------------
3086 procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
3090 Wrapped_Node : Node_Id := Empty;
3093 if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
3097 -- Ignore insert of actions from inside default expression (or other
3098 -- similar "spec expression") in the special spec-expression analyze
3099 -- mode. Any insertions at this point have no relevance, since we are
3100 -- only doing the analyze to freeze the types of any static expressions.
3101 -- See section "Handling of Default Expressions" in the spec of package
3102 -- Sem for further details.
3104 if In_Spec_Expression then
3108 -- If the action derives from stuff inside a record, then the actions
3109 -- are attached to the current scope, to be inserted and analyzed on
3110 -- exit from the scope. The reason for this is that we may also be
3111 -- generating freeze actions at the same time, and they must eventually
3112 -- be elaborated in the correct order.
3114 if Is_Record_Type (Current_Scope)
3115 and then not Is_Frozen (Current_Scope)
3117 if No (Scope_Stack.Table
3118 (Scope_Stack.Last).Pending_Freeze_Actions)
3120 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
3125 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
3131 -- We now intend to climb up the tree to find the right point to
3132 -- insert the actions. We start at Assoc_Node, unless this node is a
3133 -- subexpression in which case we start with its parent. We do this for
3134 -- two reasons. First it speeds things up. Second, if Assoc_Node is
3135 -- itself one of the special nodes like N_And_Then, then we assume that
3136 -- an initial request to insert actions for such a node does not expect
3137 -- the actions to get deposited in the node for later handling when the
3138 -- node is expanded, since clearly the node is being dealt with by the
3139 -- caller. Note that in the subexpression case, N is always the child we
3142 -- N_Raise_xxx_Error is an annoying special case, it is a statement if
3143 -- it has type Standard_Void_Type, and a subexpression otherwise.
3144 -- otherwise. Procedure calls, and similarly procedure attribute
3145 -- references, are also statements.
3147 if Nkind (Assoc_Node) in N_Subexpr
3148 and then (Nkind (Assoc_Node) not in N_Raise_xxx_Error
3149 or else Etype (Assoc_Node) /= Standard_Void_Type)
3150 and then Nkind (Assoc_Node) /= N_Procedure_Call_Statement
3151 and then (Nkind (Assoc_Node) /= N_Attribute_Reference
3153 not Is_Procedure_Attribute_Name
3154 (Attribute_Name (Assoc_Node)))
3157 P := Parent (Assoc_Node);
3159 -- Non-subexpression case. Note that N is initially Empty in this case
3160 -- (N is only guaranteed Non-Empty in the subexpr case).
3167 -- Capture root of the transient scope
3169 if Scope_Is_Transient then
3170 Wrapped_Node := Node_To_Be_Wrapped;
3174 pragma Assert (Present (P));
3176 -- Make sure that inserted actions stay in the transient scope
3178 if Present (Wrapped_Node) and then N = Wrapped_Node then
3179 Store_Before_Actions_In_Scope (Ins_Actions);
3185 -- Case of right operand of AND THEN or OR ELSE. Put the actions
3186 -- in the Actions field of the right operand. They will be moved
3187 -- out further when the AND THEN or OR ELSE operator is expanded.
3188 -- Nothing special needs to be done for the left operand since
3189 -- in that case the actions are executed unconditionally.
3191 when N_Short_Circuit =>
3192 if N = Right_Opnd (P) then
3194 -- We are now going to either append the actions to the
3195 -- actions field of the short-circuit operation. We will
3196 -- also analyze the actions now.
3198 -- This analysis is really too early, the proper thing would
3199 -- be to just park them there now, and only analyze them if
3200 -- we find we really need them, and to it at the proper
3201 -- final insertion point. However attempting to this proved
3202 -- tricky, so for now we just kill current values before and
3203 -- after the analyze call to make sure we avoid peculiar
3204 -- optimizations from this out of order insertion.
3206 Kill_Current_Values;
3208 if Present (Actions (P)) then
3209 Insert_List_After_And_Analyze
3210 (Last (Actions (P)), Ins_Actions);
3212 Set_Actions (P, Ins_Actions);
3213 Analyze_List (Actions (P));
3216 Kill_Current_Values;
3221 -- Then or Else dependent expression of an if expression. Add
3222 -- actions to Then_Actions or Else_Actions field as appropriate.
3223 -- The actions will be moved further out when the if is expanded.
3225 when N_If_Expression =>
3227 ThenX : constant Node_Id := Next (First (Expressions (P)));
3228 ElseX : constant Node_Id := Next (ThenX);
3231 -- If the enclosing expression is already analyzed, as
3232 -- is the case for nested elaboration checks, insert the
3233 -- conditional further out.
3235 if Analyzed (P) then
3238 -- Actions belong to the then expression, temporarily place
3239 -- them as Then_Actions of the if expression. They will be
3240 -- moved to the proper place later when the if expression
3243 elsif N = ThenX then
3244 if Present (Then_Actions (P)) then
3245 Insert_List_After_And_Analyze
3246 (Last (Then_Actions (P)), Ins_Actions);
3248 Set_Then_Actions (P, Ins_Actions);
3249 Analyze_List (Then_Actions (P));
3254 -- Actions belong to the else expression, temporarily place
3255 -- them as Else_Actions of the if expression. They will be
3256 -- moved to the proper place later when the if expression
3259 elsif N = ElseX then
3260 if Present (Else_Actions (P)) then
3261 Insert_List_After_And_Analyze
3262 (Last (Else_Actions (P)), Ins_Actions);
3264 Set_Else_Actions (P, Ins_Actions);
3265 Analyze_List (Else_Actions (P));
3270 -- Actions belong to the condition. In this case they are
3271 -- unconditionally executed, and so we can continue the
3272 -- search for the proper insert point.
3279 -- Alternative of case expression, we place the action in the
3280 -- Actions field of the case expression alternative, this will
3281 -- be handled when the case expression is expanded.
3283 when N_Case_Expression_Alternative =>
3284 if Present (Actions (P)) then
3285 Insert_List_After_And_Analyze
3286 (Last (Actions (P)), Ins_Actions);
3288 Set_Actions (P, Ins_Actions);
3289 Analyze_List (Actions (P));
3294 -- Case of appearing within an Expressions_With_Actions node. When
3295 -- the new actions come from the expression of the expression with
3296 -- actions, they must be added to the existing actions. The other
3297 -- alternative is when the new actions are related to one of the
3298 -- existing actions of the expression with actions. In that case
3299 -- they must be inserted further up the tree.
3301 when N_Expression_With_Actions =>
3302 if N = Expression (P) then
3303 Insert_List_After_And_Analyze
3304 (Last (Actions (P)), Ins_Actions);
3308 -- Case of appearing in the condition of a while expression or
3309 -- elsif. We insert the actions into the Condition_Actions field.
3310 -- They will be moved further out when the while loop or elsif
3313 when N_Iteration_Scheme |
3316 if N = Condition (P) then
3317 if Present (Condition_Actions (P)) then
3318 Insert_List_After_And_Analyze
3319 (Last (Condition_Actions (P)), Ins_Actions);
3321 Set_Condition_Actions (P, Ins_Actions);
3323 -- Set the parent of the insert actions explicitly. This
3324 -- is not a syntactic field, but we need the parent field
3325 -- set, in particular so that freeze can understand that
3326 -- it is dealing with condition actions, and properly
3327 -- insert the freezing actions.
3329 Set_Parent (Ins_Actions, P);
3330 Analyze_List (Condition_Actions (P));
3336 -- Statements, declarations, pragmas, representation clauses
3341 N_Procedure_Call_Statement |
3342 N_Statement_Other_Than_Procedure_Call |
3348 -- Representation_Clause
3351 N_Attribute_Definition_Clause |
3352 N_Enumeration_Representation_Clause |
3353 N_Record_Representation_Clause |
3357 N_Abstract_Subprogram_Declaration |
3359 N_Exception_Declaration |
3360 N_Exception_Renaming_Declaration |
3361 N_Expression_Function |
3362 N_Formal_Abstract_Subprogram_Declaration |
3363 N_Formal_Concrete_Subprogram_Declaration |
3364 N_Formal_Object_Declaration |
3365 N_Formal_Type_Declaration |
3366 N_Full_Type_Declaration |
3367 N_Function_Instantiation |
3368 N_Generic_Function_Renaming_Declaration |
3369 N_Generic_Package_Declaration |
3370 N_Generic_Package_Renaming_Declaration |
3371 N_Generic_Procedure_Renaming_Declaration |
3372 N_Generic_Subprogram_Declaration |
3373 N_Implicit_Label_Declaration |
3374 N_Incomplete_Type_Declaration |
3375 N_Number_Declaration |
3376 N_Object_Declaration |
3377 N_Object_Renaming_Declaration |
3379 N_Package_Body_Stub |
3380 N_Package_Declaration |
3381 N_Package_Instantiation |
3382 N_Package_Renaming_Declaration |
3383 N_Private_Extension_Declaration |
3384 N_Private_Type_Declaration |
3385 N_Procedure_Instantiation |
3387 N_Protected_Body_Stub |
3388 N_Protected_Type_Declaration |
3389 N_Single_Task_Declaration |
3391 N_Subprogram_Body_Stub |
3392 N_Subprogram_Declaration |
3393 N_Subprogram_Renaming_Declaration |
3394 N_Subtype_Declaration |
3397 N_Task_Type_Declaration |
3399 -- Use clauses can appear in lists of declarations
3401 N_Use_Package_Clause |
3404 -- Freeze entity behaves like a declaration or statement
3408 -- Do not insert here if the item is not a list member (this
3409 -- happens for example with a triggering statement, and the
3410 -- proper approach is to insert before the entire select).
3412 if not Is_List_Member (P) then
3415 -- Do not insert if parent of P is an N_Component_Association
3416 -- node (i.e. we are in the context of an N_Aggregate or
3417 -- N_Extension_Aggregate node. In this case we want to insert
3418 -- before the entire aggregate.
3420 elsif Nkind (Parent (P)) = N_Component_Association then
3423 -- Do not insert if the parent of P is either an N_Variant node
3424 -- or an N_Record_Definition node, meaning in either case that
3425 -- P is a member of a component list, and that therefore the
3426 -- actions should be inserted outside the complete record
3429 elsif Nkind_In (Parent (P), N_Variant, N_Record_Definition) then
3432 -- Do not insert freeze nodes within the loop generated for
3433 -- an aggregate, because they may be elaborated too late for
3434 -- subsequent use in the back end: within a package spec the
3435 -- loop is part of the elaboration procedure and is only
3436 -- elaborated during the second pass.
3438 -- If the loop comes from source, or the entity is local to the
3439 -- loop itself it must remain within.
3441 elsif Nkind (Parent (P)) = N_Loop_Statement
3442 and then not Comes_From_Source (Parent (P))
3443 and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
3445 Scope (Entity (First (Ins_Actions))) /= Current_Scope
3449 -- Otherwise we can go ahead and do the insertion
3451 elsif P = Wrapped_Node then
3452 Store_Before_Actions_In_Scope (Ins_Actions);
3456 Insert_List_Before_And_Analyze (P, Ins_Actions);
3460 -- A special case, N_Raise_xxx_Error can act either as a statement
3461 -- or a subexpression. We tell the difference by looking at the
3462 -- Etype. It is set to Standard_Void_Type in the statement case.
3465 N_Raise_xxx_Error =>
3466 if Etype (P) = Standard_Void_Type then
3467 if P = Wrapped_Node then
3468 Store_Before_Actions_In_Scope (Ins_Actions);
3470 Insert_List_Before_And_Analyze (P, Ins_Actions);
3475 -- In the subexpression case, keep climbing
3481 -- If a component association appears within a loop created for
3482 -- an array aggregate, attach the actions to the association so
3483 -- they can be subsequently inserted within the loop. For other
3484 -- component associations insert outside of the aggregate. For
3485 -- an association that will generate a loop, its Loop_Actions
3486 -- attribute is already initialized (see exp_aggr.adb).
3488 -- The list of loop_actions can in turn generate additional ones,
3489 -- that are inserted before the associated node. If the associated
3490 -- node is outside the aggregate, the new actions are collected
3491 -- at the end of the loop actions, to respect the order in which
3492 -- they are to be elaborated.
3495 N_Component_Association =>
3496 if Nkind (Parent (P)) = N_Aggregate
3497 and then Present (Loop_Actions (P))
3499 if Is_Empty_List (Loop_Actions (P)) then
3500 Set_Loop_Actions (P, Ins_Actions);
3501 Analyze_List (Ins_Actions);
3508 -- Check whether these actions were generated by a
3509 -- declaration that is part of the loop_ actions
3510 -- for the component_association.
3513 while Present (Decl) loop
3514 exit when Parent (Decl) = P
3515 and then Is_List_Member (Decl)
3517 List_Containing (Decl) = Loop_Actions (P);
3518 Decl := Parent (Decl);
3521 if Present (Decl) then
3522 Insert_List_Before_And_Analyze
3523 (Decl, Ins_Actions);
3525 Insert_List_After_And_Analyze
3526 (Last (Loop_Actions (P)), Ins_Actions);
3537 -- Another special case, an attribute denoting a procedure call
3540 N_Attribute_Reference =>
3541 if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
3542 if P = Wrapped_Node then
3543 Store_Before_Actions_In_Scope (Ins_Actions);
3545 Insert_List_Before_And_Analyze (P, Ins_Actions);
3550 -- In the subexpression case, keep climbing
3556 -- A contract node should not belong to the tree
3559 raise Program_Error;
3561 -- For all other node types, keep climbing tree
3565 N_Accept_Alternative |
3566 N_Access_Definition |
3567 N_Access_Function_Definition |
3568 N_Access_Procedure_Definition |
3569 N_Access_To_Object_Definition |
3572 N_Aspect_Specification |
3574 N_Case_Statement_Alternative |
3575 N_Character_Literal |
3576 N_Compilation_Unit |
3577 N_Compilation_Unit_Aux |
3578 N_Component_Clause |
3579 N_Component_Declaration |
3580 N_Component_Definition |
3582 N_Constrained_Array_Definition |
3583 N_Decimal_Fixed_Point_Definition |
3584 N_Defining_Character_Literal |
3585 N_Defining_Identifier |
3586 N_Defining_Operator_Symbol |
3587 N_Defining_Program_Unit_Name |
3588 N_Delay_Alternative |
3589 N_Delta_Constraint |
3590 N_Derived_Type_Definition |
3592 N_Digits_Constraint |
3593 N_Discriminant_Association |
3594 N_Discriminant_Specification |
3596 N_Entry_Body_Formal_Part |
3597 N_Entry_Call_Alternative |
3598 N_Entry_Declaration |
3599 N_Entry_Index_Specification |
3600 N_Enumeration_Type_Definition |
3602 N_Exception_Handler |
3604 N_Explicit_Dereference |
3605 N_Extension_Aggregate |
3606 N_Floating_Point_Definition |
3607 N_Formal_Decimal_Fixed_Point_Definition |
3608 N_Formal_Derived_Type_Definition |
3609 N_Formal_Discrete_Type_Definition |
3610 N_Formal_Floating_Point_Definition |
3611 N_Formal_Modular_Type_Definition |
3612 N_Formal_Ordinary_Fixed_Point_Definition |
3613 N_Formal_Package_Declaration |
3614 N_Formal_Private_Type_Definition |
3615 N_Formal_Incomplete_Type_Definition |
3616 N_Formal_Signed_Integer_Type_Definition |
3618 N_Function_Specification |
3619 N_Generic_Association |
3620 N_Handled_Sequence_Of_Statements |
3623 N_Index_Or_Discriminant_Constraint |
3624 N_Indexed_Component |
3626 N_Iterator_Specification |
3629 N_Loop_Parameter_Specification |
3631 N_Modular_Type_Definition |
3657 N_Op_Shift_Right_Arithmetic |
3661 N_Ordinary_Fixed_Point_Definition |
3663 N_Package_Specification |
3664 N_Parameter_Association |
3665 N_Parameter_Specification |
3666 N_Pop_Constraint_Error_Label |
3667 N_Pop_Program_Error_Label |
3668 N_Pop_Storage_Error_Label |
3669 N_Pragma_Argument_Association |
3670 N_Procedure_Specification |
3671 N_Protected_Definition |
3672 N_Push_Constraint_Error_Label |
3673 N_Push_Program_Error_Label |
3674 N_Push_Storage_Error_Label |
3675 N_Qualified_Expression |
3676 N_Quantified_Expression |
3677 N_Raise_Expression |
3679 N_Range_Constraint |
3681 N_Real_Range_Specification |
3682 N_Record_Definition |
3684 N_SCIL_Dispatch_Table_Tag_Init |
3685 N_SCIL_Dispatching_Call |
3686 N_SCIL_Membership_Test |
3687 N_Selected_Component |
3688 N_Signed_Integer_Type_Definition |
3689 N_Single_Protected_Declaration |
3693 N_Subtype_Indication |
3696 N_Terminate_Alternative |
3697 N_Triggering_Alternative |
3699 N_Unchecked_Expression |
3700 N_Unchecked_Type_Conversion |
3701 N_Unconstrained_Array_Definition |
3706 N_Validate_Unchecked_Conversion |
3713 -- If we fall through above tests, keep climbing tree
3717 if Nkind (Parent (N)) = N_Subunit then
3719 -- This is the proper body corresponding to a stub. Insertion must
3720 -- be done at the point of the stub, which is in the declarative
3721 -- part of the parent unit.
3723 P := Corresponding_Stub (Parent (N));
3731 -- Version with check(s) suppressed
3733 procedure Insert_Actions
3734 (Assoc_Node : Node_Id;
3735 Ins_Actions : List_Id;
3736 Suppress : Check_Id)
3739 if Suppress = All_Checks then
3741 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
3743 Scope_Suppress.Suppress := (others => True);
3744 Insert_Actions (Assoc_Node, Ins_Actions);
3745 Scope_Suppress.Suppress := Sva;
3750 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
3752 Scope_Suppress.Suppress (Suppress) := True;
3753 Insert_Actions (Assoc_Node, Ins_Actions);
3754 Scope_Suppress.Suppress (Suppress) := Svg;
3759 --------------------------
3760 -- Insert_Actions_After --
3761 --------------------------
3763 procedure Insert_Actions_After
3764 (Assoc_Node : Node_Id;
3765 Ins_Actions : List_Id)
3768 if Scope_Is_Transient and then Assoc_Node = Node_To_Be_Wrapped then
3769 Store_After_Actions_In_Scope (Ins_Actions);
3771 Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
3773 end Insert_Actions_After;
3775 ---------------------------------
3776 -- Insert_Library_Level_Action --
3777 ---------------------------------
3779 procedure Insert_Library_Level_Action (N : Node_Id) is
3780 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
3783 Push_Scope (Cunit_Entity (Main_Unit));
3784 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
3786 if No (Actions (Aux)) then
3787 Set_Actions (Aux, New_List (N));
3789 Append (N, Actions (Aux));
3794 end Insert_Library_Level_Action;
3796 ----------------------------------
3797 -- Insert_Library_Level_Actions --
3798 ----------------------------------
3800 procedure Insert_Library_Level_Actions (L : List_Id) is
3801 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
3804 if Is_Non_Empty_List (L) then
3805 Push_Scope (Cunit_Entity (Main_Unit));
3806 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
3808 if No (Actions (Aux)) then
3809 Set_Actions (Aux, L);
3812 Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
3817 end Insert_Library_Level_Actions;
3819 ----------------------
3820 -- Inside_Init_Proc --
3821 ----------------------
3823 function Inside_Init_Proc return Boolean is
3828 while Present (S) and then S /= Standard_Standard loop
3829 if Is_Init_Proc (S) then
3837 end Inside_Init_Proc;
3839 ----------------------------
3840 -- Is_All_Null_Statements --
3841 ----------------------------
3843 function Is_All_Null_Statements (L : List_Id) return Boolean is
3848 while Present (Stm) loop
3849 if Nkind (Stm) /= N_Null_Statement then
3857 end Is_All_Null_Statements;
3859 --------------------------------------------------
3860 -- Is_Displacement_Of_Object_Or_Function_Result --
3861 --------------------------------------------------
3863 function Is_Displacement_Of_Object_Or_Function_Result
3864 (Obj_Id : Entity_Id) return Boolean
3866 function Is_Controlled_Function_Call (N : Node_Id) return Boolean;
3867 -- Determine if particular node denotes a controlled function call
3869 function Is_Displace_Call (N : Node_Id) return Boolean;
3870 -- Determine whether a particular node is a call to Ada.Tags.Displace.
3871 -- The call might be nested within other actions such as conversions.
3873 function Is_Source_Object (N : Node_Id) return Boolean;
3874 -- Determine whether a particular node denotes a source object
3876 ---------------------------------
3877 -- Is_Controlled_Function_Call --
3878 ---------------------------------
3880 function Is_Controlled_Function_Call (N : Node_Id) return Boolean is
3881 Expr : Node_Id := Original_Node (N);
3884 if Nkind (Expr) = N_Function_Call then
3885 Expr := Name (Expr);
3888 -- The function call may appear in object.operation format
3890 if Nkind (Expr) = N_Selected_Component then
3891 Expr := Selector_Name (Expr);
3895 Nkind_In (Expr, N_Expanded_Name, N_Identifier)
3896 and then Ekind (Entity (Expr)) = E_Function
3897 and then Needs_Finalization (Etype (Entity (Expr)));
3898 end Is_Controlled_Function_Call;
3900 ----------------------
3901 -- Is_Displace_Call --
3902 ----------------------
3904 function Is_Displace_Call (N : Node_Id) return Boolean is
3905 Call : Node_Id := N;
3908 -- Strip various actions which may precede a call to Displace
3911 if Nkind (Call) = N_Explicit_Dereference then
3912 Call := Prefix (Call);
3914 elsif Nkind_In (Call, N_Type_Conversion,
3915 N_Unchecked_Type_Conversion)
3917 Call := Expression (Call);
3926 and then Nkind (Call) = N_Function_Call
3927 and then Is_RTE (Entity (Name (Call)), RE_Displace);
3928 end Is_Displace_Call;
3930 ----------------------
3931 -- Is_Source_Object --
3932 ----------------------
3934 function Is_Source_Object (N : Node_Id) return Boolean is
3938 and then Nkind (N) in N_Has_Entity
3939 and then Is_Object (Entity (N))
3940 and then Comes_From_Source (N);
3941 end Is_Source_Object;
3945 Decl : constant Node_Id := Parent (Obj_Id);
3946 Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
3947 Orig_Decl : constant Node_Id := Original_Node (Decl);
3949 -- Start of processing for Is_Displacement_Of_Object_Or_Function_Result
3954 -- Obj : CW_Type := Function_Call (...);
3958 -- Tmp : ... := Function_Call (...)'reference;
3959 -- Obj : CW_Type renames (... Ada.Tags.Displace (Tmp));
3961 -- where the return type of the function and the class-wide type require
3962 -- dispatch table pointer displacement.
3966 -- Obj : CW_Type := Src_Obj;
3970 -- Obj : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
3972 -- where the type of the source object and the class-wide type require
3973 -- dispatch table pointer displacement.
3976 Nkind (Decl) = N_Object_Renaming_Declaration
3977 and then Nkind (Orig_Decl) = N_Object_Declaration
3978 and then Comes_From_Source (Orig_Decl)
3979 and then Is_Class_Wide_Type (Obj_Typ)
3980 and then Is_Displace_Call (Renamed_Object (Obj_Id))
3982 (Is_Controlled_Function_Call (Expression (Orig_Decl))
3983 or else Is_Source_Object (Expression (Orig_Decl)));
3984 end Is_Displacement_Of_Object_Or_Function_Result;
3986 ------------------------------
3987 -- Is_Finalizable_Transient --
3988 ------------------------------
3990 function Is_Finalizable_Transient
3992 Rel_Node : Node_Id) return Boolean
3994 Obj_Id : constant Entity_Id := Defining_Identifier (Decl);
3995 Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
3996 Desig : Entity_Id := Obj_Typ;
3998 function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean;
3999 -- Determine whether transient object Trans_Id is initialized either
4000 -- by a function call which returns an access type or simply renames
4003 function Initialized_By_Aliased_BIP_Func_Call
4004 (Trans_Id : Entity_Id) return Boolean;
4005 -- Determine whether transient object Trans_Id is initialized by a
4006 -- build-in-place function call where the BIPalloc parameter is of
4007 -- value 1 and BIPaccess is not null. This case creates an aliasing
4008 -- between the returned value and the value denoted by BIPaccess.
4011 (Trans_Id : Entity_Id;
4012 First_Stmt : Node_Id) return Boolean;
4013 -- Determine whether transient object Trans_Id has been renamed or
4014 -- aliased through 'reference in the statement list starting from
4017 function Is_Allocated (Trans_Id : Entity_Id) return Boolean;
4018 -- Determine whether transient object Trans_Id is allocated on the heap
4020 function Is_Iterated_Container
4021 (Trans_Id : Entity_Id;
4022 First_Stmt : Node_Id) return Boolean;
4023 -- Determine whether transient object Trans_Id denotes a container which
4024 -- is in the process of being iterated in the statement list starting
4027 ---------------------------
4028 -- Initialized_By_Access --
4029 ---------------------------
4031 function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean is
4032 Expr : constant Node_Id := Expression (Parent (Trans_Id));
4037 and then Nkind (Expr) /= N_Reference
4038 and then Is_Access_Type (Etype (Expr));
4039 end Initialized_By_Access;
4041 ------------------------------------------
4042 -- Initialized_By_Aliased_BIP_Func_Call --
4043 ------------------------------------------
4045 function Initialized_By_Aliased_BIP_Func_Call
4046 (Trans_Id : Entity_Id) return Boolean
4048 Call : Node_Id := Expression (Parent (Trans_Id));
4051 -- Build-in-place calls usually appear in 'reference format
4053 if Nkind (Call) = N_Reference then
4054 Call := Prefix (Call);
4057 if Is_Build_In_Place_Function_Call (Call) then
4059 Access_Nam : Name_Id := No_Name;
4060 Access_OK : Boolean := False;
4062 Alloc_Nam : Name_Id := No_Name;
4063 Alloc_OK : Boolean := False;
4065 Func_Id : Entity_Id;
4069 -- Examine all parameter associations of the function call
4071 Param := First (Parameter_Associations (Call));
4072 while Present (Param) loop
4073 if Nkind (Param) = N_Parameter_Association
4074 and then Nkind (Selector_Name (Param)) = N_Identifier
4076 Actual := Explicit_Actual_Parameter (Param);
4077 Formal := Selector_Name (Param);
4079 -- Construct the names of formals BIPaccess and BIPalloc
4080 -- using the function name retrieved from an arbitrary
4083 if Access_Nam = No_Name
4084 and then Alloc_Nam = No_Name
4085 and then Present (Entity (Formal))
4087 Func_Id := Scope (Entity (Formal));
4090 New_External_Name (Chars (Func_Id),
4091 BIP_Formal_Suffix (BIP_Object_Access));
4094 New_External_Name (Chars (Func_Id),
4095 BIP_Formal_Suffix (BIP_Alloc_Form));
4098 -- A match for BIPaccess => Temp has been found
4100 if Chars (Formal) = Access_Nam
4101 and then Nkind (Actual) /= N_Null
4106 -- A match for BIPalloc => 1 has been found
4108 if Chars (Formal) = Alloc_Nam
4109 and then Nkind (Actual) = N_Integer_Literal
4110 and then Intval (Actual) = Uint_1
4119 return Access_OK and Alloc_OK;
4124 end Initialized_By_Aliased_BIP_Func_Call;
4131 (Trans_Id : Entity_Id;
4132 First_Stmt : Node_Id) return Boolean
4134 function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id;
4135 -- Given an object renaming declaration, retrieve the entity of the
4136 -- renamed name. Return Empty if the renamed name is anything other
4137 -- than a variable or a constant.
4139 -------------------------
4140 -- Find_Renamed_Object --
4141 -------------------------
4143 function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id is
4144 Ren_Obj : Node_Id := Empty;
4146 function Find_Object (N : Node_Id) return Traverse_Result;
4147 -- Try to detect an object which is either a constant or a
4154 function Find_Object (N : Node_Id) return Traverse_Result is
4156 -- Stop the search once a constant or a variable has been
4159 if Nkind (N) = N_Identifier
4160 and then Present (Entity (N))
4161 and then Ekind_In (Entity (N), E_Constant, E_Variable)
4163 Ren_Obj := Entity (N);
4170 procedure Search is new Traverse_Proc (Find_Object);
4174 Typ : constant Entity_Id := Etype (Defining_Identifier (Ren_Decl));
4176 -- Start of processing for Find_Renamed_Object
4179 -- Actions related to dispatching calls may appear as renamings of
4180 -- tags. Do not process this type of renaming because it does not
4181 -- use the actual value of the object.
4183 if not Is_RTE (Typ, RE_Tag_Ptr) then
4184 Search (Name (Ren_Decl));
4188 end Find_Renamed_Object;
4193 Ren_Obj : Entity_Id;
4196 -- Start of processing for Is_Aliased
4200 while Present (Stmt) loop
4201 if Nkind (Stmt) = N_Object_Declaration then
4202 Expr := Expression (Stmt);
4205 and then Nkind (Expr) = N_Reference
4206 and then Nkind (Prefix (Expr)) = N_Identifier
4207 and then Entity (Prefix (Expr)) = Trans_Id
4212 elsif Nkind (Stmt) = N_Object_Renaming_Declaration then
4213 Ren_Obj := Find_Renamed_Object (Stmt);
4215 if Present (Ren_Obj) and then Ren_Obj = Trans_Id then
4230 function Is_Allocated (Trans_Id : Entity_Id) return Boolean is
4231 Expr : constant Node_Id := Expression (Parent (Trans_Id));
4234 Is_Access_Type (Etype (Trans_Id))
4235 and then Present (Expr)
4236 and then Nkind (Expr) = N_Allocator;
4239 ---------------------------
4240 -- Is_Iterated_Container --
4241 ---------------------------
4243 function Is_Iterated_Container
4244 (Trans_Id : Entity_Id;
4245 First_Stmt : Node_Id) return Boolean
4255 -- It is not possible to iterate over containers in non-Ada 2012 code
4257 if Ada_Version < Ada_2012 then
4261 Typ := Etype (Trans_Id);
4263 -- Handle access type created for secondary stack use
4265 if Is_Access_Type (Typ) then
4266 Typ := Designated_Type (Typ);
4269 -- Look for aspect Default_Iterator
4271 if Has_Aspects (Parent (Typ)) then
4272 Aspect := Find_Aspect (Typ, Aspect_Default_Iterator);
4274 if Present (Aspect) then
4275 Iter := Entity (Aspect);
4277 -- Examine the statements following the container object and
4278 -- look for a call to the default iterate routine where the
4279 -- first parameter is the transient. Such a call appears as:
4281 -- It : Access_To_CW_Iterator :=
4282 -- Iterate (Tran_Id.all, ...)'reference;
4285 while Present (Stmt) loop
4287 -- Detect an object declaration which is initialized by a
4288 -- secondary stack function call.
4290 if Nkind (Stmt) = N_Object_Declaration
4291 and then Present (Expression (Stmt))
4292 and then Nkind (Expression (Stmt)) = N_Reference
4293 and then Nkind (Prefix (Expression (Stmt))) =
4296 Call := Prefix (Expression (Stmt));
4298 -- The call must invoke the default iterate routine of
4299 -- the container and the transient object must appear as
4300 -- the first actual parameter. Skip any calls whose names
4301 -- are not entities.
4303 if Is_Entity_Name (Name (Call))
4304 and then Entity (Name (Call)) = Iter
4305 and then Present (Parameter_Associations (Call))
4307 Param := First (Parameter_Associations (Call));
4309 if Nkind (Param) = N_Explicit_Dereference
4310 and then Entity (Prefix (Param)) = Trans_Id
4323 end Is_Iterated_Container;
4325 -- Start of processing for Is_Finalizable_Transient
4328 -- Handle access types
4330 if Is_Access_Type (Desig) then
4331 Desig := Available_View (Designated_Type (Desig));
4335 Ekind_In (Obj_Id, E_Constant, E_Variable)
4336 and then Needs_Finalization (Desig)
4337 and then Requires_Transient_Scope (Desig)
4338 and then Nkind (Rel_Node) /= N_Simple_Return_Statement
4340 -- Do not consider renamed or 'reference-d transient objects because
4341 -- the act of renaming extends the object's lifetime.
4343 and then not Is_Aliased (Obj_Id, Decl)
4345 -- Do not consider transient objects allocated on the heap since
4346 -- they are attached to a finalization master.
4348 and then not Is_Allocated (Obj_Id)
4350 -- If the transient object is a pointer, check that it is not
4351 -- initialized by a function which returns a pointer or acts as a
4352 -- renaming of another pointer.
4355 (not Is_Access_Type (Obj_Typ)
4356 or else not Initialized_By_Access (Obj_Id))
4358 -- Do not consider transient objects which act as indirect aliases
4359 -- of build-in-place function results.
4361 and then not Initialized_By_Aliased_BIP_Func_Call (Obj_Id)
4363 -- Do not consider conversions of tags to class-wide types
4365 and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
4367 -- Do not consider containers in the context of iterator loops. Such
4368 -- transient objects must exist for as long as the loop is around,
4369 -- otherwise any operation carried out by the iterator will fail.
4371 and then not Is_Iterated_Container (Obj_Id, Decl);
4372 end Is_Finalizable_Transient;
4374 ---------------------------------
4375 -- Is_Fully_Repped_Tagged_Type --
4376 ---------------------------------
4378 function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean is
4379 U : constant Entity_Id := Underlying_Type (T);
4383 if No (U) or else not Is_Tagged_Type (U) then
4385 elsif Has_Discriminants (U) then
4387 elsif not Has_Specified_Layout (U) then
4391 -- Here we have a tagged type, see if it has any unlayed out fields
4392 -- other than a possible tag and parent fields. If so, we return False.
4394 Comp := First_Component (U);
4395 while Present (Comp) loop
4396 if not Is_Tag (Comp)
4397 and then Chars (Comp) /= Name_uParent
4398 and then No (Component_Clause (Comp))
4402 Next_Component (Comp);
4406 -- All components are layed out
4409 end Is_Fully_Repped_Tagged_Type;
4411 ----------------------------------
4412 -- Is_Library_Level_Tagged_Type --
4413 ----------------------------------
4415 function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean is
4417 return Is_Tagged_Type (Typ) and then Is_Library_Level_Entity (Typ);
4418 end Is_Library_Level_Tagged_Type;
4420 --------------------------
4421 -- Is_Non_BIP_Func_Call --
4422 --------------------------
4424 function Is_Non_BIP_Func_Call (Expr : Node_Id) return Boolean is
4426 -- The expected call is of the format
4428 -- Func_Call'reference
4431 Nkind (Expr) = N_Reference
4432 and then Nkind (Prefix (Expr)) = N_Function_Call
4433 and then not Is_Build_In_Place_Function_Call (Prefix (Expr));
4434 end Is_Non_BIP_Func_Call;
4436 ----------------------------------
4437 -- Is_Possibly_Unaligned_Object --
4438 ----------------------------------
4440 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
4441 T : constant Entity_Id := Etype (N);
4444 -- If renamed object, apply test to underlying object
4446 if Is_Entity_Name (N)
4447 and then Is_Object (Entity (N))
4448 and then Present (Renamed_Object (Entity (N)))
4450 return Is_Possibly_Unaligned_Object (Renamed_Object (Entity (N)));
4453 -- Tagged and controlled types and aliased types are always aligned, as
4454 -- are concurrent types.
4457 or else Has_Controlled_Component (T)
4458 or else Is_Concurrent_Type (T)
4459 or else Is_Tagged_Type (T)
4460 or else Is_Controlled (T)
4465 -- If this is an element of a packed array, may be unaligned
4467 if Is_Ref_To_Bit_Packed_Array (N) then
4471 -- Case of indexed component reference: test whether prefix is unaligned
4473 if Nkind (N) = N_Indexed_Component then
4474 return Is_Possibly_Unaligned_Object (Prefix (N));
4476 -- Case of selected component reference
4478 elsif Nkind (N) = N_Selected_Component then
4480 P : constant Node_Id := Prefix (N);
4481 C : constant Entity_Id := Entity (Selector_Name (N));
4486 -- If component reference is for an array with non-static bounds,
4487 -- then it is always aligned: we can only process unaligned arrays
4488 -- with static bounds (more precisely compile time known bounds).
4490 if Is_Array_Type (T)
4491 and then not Compile_Time_Known_Bounds (T)
4496 -- If component is aliased, it is definitely properly aligned
4498 if Is_Aliased (C) then
4502 -- If component is for a type implemented as a scalar, and the
4503 -- record is packed, and the component is other than the first
4504 -- component of the record, then the component may be unaligned.
4506 if Is_Packed (Etype (P))
4507 and then Represented_As_Scalar (Etype (C))
4508 and then First_Entity (Scope (C)) /= C
4513 -- Compute maximum possible alignment for T
4515 -- If alignment is known, then that settles things
4517 if Known_Alignment (T) then
4518 M := UI_To_Int (Alignment (T));
4520 -- If alignment is not known, tentatively set max alignment
4523 M := Ttypes.Maximum_Alignment;
4525 -- We can reduce this if the Esize is known since the default
4526 -- alignment will never be more than the smallest power of 2
4527 -- that does not exceed this Esize value.
4529 if Known_Esize (T) then
4530 S := UI_To_Int (Esize (T));
4532 while (M / 2) >= S loop
4538 -- The following code is historical, it used to be present but it
4539 -- is too cautious, because the front-end does not know the proper
4540 -- default alignments for the target. Also, if the alignment is
4541 -- not known, the front end can't know in any case! If a copy is
4542 -- needed, the back-end will take care of it. This whole section
4543 -- including this comment can be removed later ???
4545 -- If the component reference is for a record that has a specified
4546 -- alignment, and we either know it is too small, or cannot tell,
4547 -- then the component may be unaligned.
4549 -- What is the following commented out code ???
4551 -- if Known_Alignment (Etype (P))
4552 -- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
4553 -- and then M > Alignment (Etype (P))
4558 -- Case of component clause present which may specify an
4559 -- unaligned position.
4561 if Present (Component_Clause (C)) then
4563 -- Otherwise we can do a test to make sure that the actual
4564 -- start position in the record, and the length, are both
4565 -- consistent with the required alignment. If not, we know
4566 -- that we are unaligned.
4569 Align_In_Bits : constant Nat := M * System_Storage_Unit;
4571 if Component_Bit_Offset (C) mod Align_In_Bits /= 0
4572 or else Esize (C) mod Align_In_Bits /= 0
4579 -- Otherwise, for a component reference, test prefix
4581 return Is_Possibly_Unaligned_Object (P);
4584 -- If not a component reference, must be aligned
4589 end Is_Possibly_Unaligned_Object;
4591 ---------------------------------
4592 -- Is_Possibly_Unaligned_Slice --
4593 ---------------------------------
4595 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean is
4597 -- Go to renamed object
4599 if Is_Entity_Name (N)
4600 and then Is_Object (Entity (N))
4601 and then Present (Renamed_Object (Entity (N)))
4603 return Is_Possibly_Unaligned_Slice (Renamed_Object (Entity (N)));
4606 -- The reference must be a slice
4608 if Nkind (N) /= N_Slice then
4612 -- Always assume the worst for a nested record component with a
4613 -- component clause, which gigi/gcc does not appear to handle well.
4614 -- It is not clear why this special test is needed at all ???
4616 if Nkind (Prefix (N)) = N_Selected_Component
4617 and then Nkind (Prefix (Prefix (N))) = N_Selected_Component
4619 Present (Component_Clause (Entity (Selector_Name (Prefix (N)))))
4624 -- We only need to worry if the target has strict alignment
4626 if not Target_Strict_Alignment then
4630 -- If it is a slice, then look at the array type being sliced
4633 Sarr : constant Node_Id := Prefix (N);
4634 -- Prefix of the slice, i.e. the array being sliced
4636 Styp : constant Entity_Id := Etype (Prefix (N));
4637 -- Type of the array being sliced
4643 -- The problems arise if the array object that is being sliced
4644 -- is a component of a record or array, and we cannot guarantee
4645 -- the alignment of the array within its containing object.
4647 -- To investigate this, we look at successive prefixes to see
4648 -- if we have a worrisome indexed or selected component.
4652 -- Case of array is part of an indexed component reference
4654 if Nkind (Pref) = N_Indexed_Component then
4655 Ptyp := Etype (Prefix (Pref));
4657 -- The only problematic case is when the array is packed, in
4658 -- which case we really know nothing about the alignment of
4659 -- individual components.
4661 if Is_Bit_Packed_Array (Ptyp) then
4665 -- Case of array is part of a selected component reference
4667 elsif Nkind (Pref) = N_Selected_Component then
4668 Ptyp := Etype (Prefix (Pref));
4670 -- We are definitely in trouble if the record in question
4671 -- has an alignment, and either we know this alignment is
4672 -- inconsistent with the alignment of the slice, or we don't
4673 -- know what the alignment of the slice should be.
4675 if Known_Alignment (Ptyp)
4676 and then (Unknown_Alignment (Styp)
4677 or else Alignment (Styp) > Alignment (Ptyp))
4682 -- We are in potential trouble if the record type is packed.
4683 -- We could special case when we know that the array is the
4684 -- first component, but that's not such a simple case ???
4686 if Is_Packed (Ptyp) then
4690 -- We are in trouble if there is a component clause, and
4691 -- either we do not know the alignment of the slice, or
4692 -- the alignment of the slice is inconsistent with the
4693 -- bit position specified by the component clause.
4696 Field : constant Entity_Id := Entity (Selector_Name (Pref));
4698 if Present (Component_Clause (Field))
4700 (Unknown_Alignment (Styp)
4702 (Component_Bit_Offset (Field) mod
4703 (System_Storage_Unit * Alignment (Styp))) /= 0)
4709 -- For cases other than selected or indexed components we know we
4710 -- are OK, since no issues arise over alignment.
4716 -- We processed an indexed component or selected component
4717 -- reference that looked safe, so keep checking prefixes.
4719 Pref := Prefix (Pref);
4722 end Is_Possibly_Unaligned_Slice;
4724 -------------------------------
4725 -- Is_Related_To_Func_Return --
4726 -------------------------------
4728 function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean is
4729 Expr : constant Node_Id := Related_Expression (Id);
4733 and then Nkind (Expr) = N_Explicit_Dereference
4734 and then Nkind (Parent (Expr)) = N_Simple_Return_Statement;
4735 end Is_Related_To_Func_Return;
4737 --------------------------------
4738 -- Is_Ref_To_Bit_Packed_Array --
4739 --------------------------------
4741 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean is
4746 if Is_Entity_Name (N)
4747 and then Is_Object (Entity (N))
4748 and then Present (Renamed_Object (Entity (N)))
4750 return Is_Ref_To_Bit_Packed_Array (Renamed_Object (Entity (N)));
4753 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
4754 if Is_Bit_Packed_Array (Etype (Prefix (N))) then
4757 Result := Is_Ref_To_Bit_Packed_Array (Prefix (N));
4760 if Result and then Nkind (N) = N_Indexed_Component then
4761 Expr := First (Expressions (N));
4762 while Present (Expr) loop
4763 Force_Evaluation (Expr);
4773 end Is_Ref_To_Bit_Packed_Array;
4775 --------------------------------
4776 -- Is_Ref_To_Bit_Packed_Slice --
4777 --------------------------------
4779 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean is
4781 if Nkind (N) = N_Type_Conversion then
4782 return Is_Ref_To_Bit_Packed_Slice (Expression (N));
4784 elsif Is_Entity_Name (N)
4785 and then Is_Object (Entity (N))
4786 and then Present (Renamed_Object (Entity (N)))
4788 return Is_Ref_To_Bit_Packed_Slice (Renamed_Object (Entity (N)));
4790 elsif Nkind (N) = N_Slice
4791 and then Is_Bit_Packed_Array (Etype (Prefix (N)))
4795 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
4796 return Is_Ref_To_Bit_Packed_Slice (Prefix (N));
4801 end Is_Ref_To_Bit_Packed_Slice;
4803 -----------------------
4804 -- Is_Renamed_Object --
4805 -----------------------
4807 function Is_Renamed_Object (N : Node_Id) return Boolean is
4808 Pnod : constant Node_Id := Parent (N);
4809 Kind : constant Node_Kind := Nkind (Pnod);
4811 if Kind = N_Object_Renaming_Declaration then
4813 elsif Nkind_In (Kind, N_Indexed_Component, N_Selected_Component) then
4814 return Is_Renamed_Object (Pnod);
4818 end Is_Renamed_Object;
4820 --------------------------------------
4821 -- Is_Secondary_Stack_BIP_Func_Call --
4822 --------------------------------------
4824 function Is_Secondary_Stack_BIP_Func_Call (Expr : Node_Id) return Boolean is
4825 Call : Node_Id := Expr;
4828 -- Build-in-place calls usually appear in 'reference format. Note that
4829 -- the accessibility check machinery may add an extra 'reference due to
4830 -- side effect removal.
4832 while Nkind (Call) = N_Reference loop
4833 Call := Prefix (Call);
4836 if Nkind_In (Call, N_Qualified_Expression,
4837 N_Unchecked_Type_Conversion)
4839 Call := Expression (Call);
4842 if Is_Build_In_Place_Function_Call (Call) then
4844 Access_Nam : Name_Id := No_Name;
4850 -- Examine all parameter associations of the function call
4852 Param := First (Parameter_Associations (Call));
4853 while Present (Param) loop
4854 if Nkind (Param) = N_Parameter_Association
4855 and then Nkind (Selector_Name (Param)) = N_Identifier
4857 Formal := Selector_Name (Param);
4858 Actual := Explicit_Actual_Parameter (Param);
4860 -- Construct the name of formal BIPalloc. It is much easier
4861 -- to extract the name of the function using an arbitrary
4862 -- formal's scope rather than the Name field of Call.
4864 if Access_Nam = No_Name
4865 and then Present (Entity (Formal))
4869 (Chars (Scope (Entity (Formal))),
4870 BIP_Formal_Suffix (BIP_Alloc_Form));
4873 -- A match for BIPalloc => 2 has been found
4875 if Chars (Formal) = Access_Nam
4876 and then Nkind (Actual) = N_Integer_Literal
4877 and then Intval (Actual) = Uint_2
4889 end Is_Secondary_Stack_BIP_Func_Call;
4891 -------------------------------------
4892 -- Is_Tag_To_Class_Wide_Conversion --
4893 -------------------------------------
4895 function Is_Tag_To_Class_Wide_Conversion
4896 (Obj_Id : Entity_Id) return Boolean
4898 Expr : constant Node_Id := Expression (Parent (Obj_Id));
4902 Is_Class_Wide_Type (Etype (Obj_Id))
4903 and then Present (Expr)
4904 and then Nkind (Expr) = N_Unchecked_Type_Conversion
4905 and then Etype (Expression (Expr)) = RTE (RE_Tag);
4906 end Is_Tag_To_Class_Wide_Conversion;
4908 ----------------------------
4909 -- Is_Untagged_Derivation --
4910 ----------------------------
4912 function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
4914 return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
4916 (Is_Private_Type (T) and then Present (Full_View (T))
4917 and then not Is_Tagged_Type (Full_View (T))
4918 and then Is_Derived_Type (Full_View (T))
4919 and then Etype (Full_View (T)) /= T);
4920 end Is_Untagged_Derivation;
4922 ---------------------------
4923 -- Is_Volatile_Reference --
4924 ---------------------------
4926 function Is_Volatile_Reference (N : Node_Id) return Boolean is
4928 if Nkind (N) in N_Has_Etype
4929 and then Present (Etype (N))
4930 and then Treat_As_Volatile (Etype (N))
4934 elsif Is_Entity_Name (N) then
4935 return Treat_As_Volatile (Entity (N));
4937 elsif Nkind (N) = N_Slice then
4938 return Is_Volatile_Reference (Prefix (N));
4940 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
4941 if (Is_Entity_Name (Prefix (N))
4942 and then Has_Volatile_Components (Entity (Prefix (N))))
4943 or else (Present (Etype (Prefix (N)))
4944 and then Has_Volatile_Components (Etype (Prefix (N))))
4948 return Is_Volatile_Reference (Prefix (N));
4954 end Is_Volatile_Reference;
4956 --------------------------
4957 -- Is_VM_By_Copy_Actual --
4958 --------------------------
4960 function Is_VM_By_Copy_Actual (N : Node_Id) return Boolean is
4962 return VM_Target /= No_VM
4963 and then (Nkind (N) = N_Slice
4965 (Nkind (N) = N_Identifier
4966 and then Present (Renamed_Object (Entity (N)))
4967 and then Nkind (Renamed_Object (Entity (N))) =
4969 end Is_VM_By_Copy_Actual;
4971 --------------------
4972 -- Kill_Dead_Code --
4973 --------------------
4975 procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False) is
4976 W : Boolean := Warn;
4977 -- Set False if warnings suppressed
4981 Remove_Warning_Messages (N);
4983 -- Generate warning if appropriate
4987 -- We suppress the warning if this code is under control of an
4988 -- if statement, whose condition is a simple identifier, and
4989 -- either we are in an instance, or warnings off is set for this
4990 -- identifier. The reason for killing it in the instance case is
4991 -- that it is common and reasonable for code to be deleted in
4992 -- instances for various reasons.
4994 if Nkind (Parent (N)) = N_If_Statement then
4996 C : constant Node_Id := Condition (Parent (N));
4998 if Nkind (C) = N_Identifier
5001 or else (Present (Entity (C))
5002 and then Has_Warnings_Off (Entity (C))))
5009 -- Generate warning if not suppressed
5013 ("?t?this code can never be executed and has been deleted!",
5018 -- Recurse into block statements and bodies to process declarations
5021 if Nkind (N) = N_Block_Statement
5022 or else Nkind (N) = N_Subprogram_Body
5023 or else Nkind (N) = N_Package_Body
5025 Kill_Dead_Code (Declarations (N), False);
5026 Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
5028 if Nkind (N) = N_Subprogram_Body then
5029 Set_Is_Eliminated (Defining_Entity (N));
5032 elsif Nkind (N) = N_Package_Declaration then
5033 Kill_Dead_Code (Visible_Declarations (Specification (N)));
5034 Kill_Dead_Code (Private_Declarations (Specification (N)));
5036 -- ??? After this point, Delete_Tree has been called on all
5037 -- declarations in Specification (N), so references to entities
5038 -- therein look suspicious.
5041 E : Entity_Id := First_Entity (Defining_Entity (N));
5043 while Present (E) loop
5044 if Ekind (E) = E_Operator then
5045 Set_Is_Eliminated (E);
5052 -- Recurse into composite statement to kill individual statements in
5053 -- particular instantiations.
5055 elsif Nkind (N) = N_If_Statement then
5056 Kill_Dead_Code (Then_Statements (N));
5057 Kill_Dead_Code (Elsif_Parts (N));
5058 Kill_Dead_Code (Else_Statements (N));
5060 elsif Nkind (N) = N_Loop_Statement then
5061 Kill_Dead_Code (Statements (N));
5063 elsif Nkind (N) = N_Case_Statement then
5067 Alt := First (Alternatives (N));
5068 while Present (Alt) loop
5069 Kill_Dead_Code (Statements (Alt));
5074 elsif Nkind (N) = N_Case_Statement_Alternative then
5075 Kill_Dead_Code (Statements (N));
5077 -- Deal with dead instances caused by deleting instantiations
5079 elsif Nkind (N) in N_Generic_Instantiation then
5080 Remove_Dead_Instance (N);
5085 -- Case where argument is a list of nodes to be killed
5087 procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False) is
5092 if Is_Non_Empty_List (L) then
5094 while Present (N) loop
5095 Kill_Dead_Code (N, W);
5102 ------------------------
5103 -- Known_Non_Negative --
5104 ------------------------
5106 function Known_Non_Negative (Opnd : Node_Id) return Boolean is
5108 if Is_OK_Static_Expression (Opnd) and then Expr_Value (Opnd) >= 0 then
5113 Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
5116 Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
5119 end Known_Non_Negative;
5121 --------------------
5122 -- Known_Non_Null --
5123 --------------------
5125 function Known_Non_Null (N : Node_Id) return Boolean is
5127 -- Checks for case where N is an entity reference
5129 if Is_Entity_Name (N) and then Present (Entity (N)) then
5131 E : constant Entity_Id := Entity (N);
5136 -- First check if we are in decisive conditional
5138 Get_Current_Value_Condition (N, Op, Val);
5140 if Known_Null (Val) then
5141 if Op = N_Op_Eq then
5143 elsif Op = N_Op_Ne then
5148 -- If OK to do replacement, test Is_Known_Non_Null flag
5150 if OK_To_Do_Constant_Replacement (E) then
5151 return Is_Known_Non_Null (E);
5153 -- Otherwise if not safe to do replacement, then say so
5160 -- True if access attribute
5162 elsif Nkind (N) = N_Attribute_Reference
5163 and then (Attribute_Name (N) = Name_Access
5165 Attribute_Name (N) = Name_Unchecked_Access
5167 Attribute_Name (N) = Name_Unrestricted_Access)
5171 -- True if allocator
5173 elsif Nkind (N) = N_Allocator then
5176 -- For a conversion, true if expression is known non-null
5178 elsif Nkind (N) = N_Type_Conversion then
5179 return Known_Non_Null (Expression (N));
5181 -- Above are all cases where the value could be determined to be
5182 -- non-null. In all other cases, we don't know, so return False.
5193 function Known_Null (N : Node_Id) return Boolean is
5195 -- Checks for case where N is an entity reference
5197 if Is_Entity_Name (N) and then Present (Entity (N)) then
5199 E : constant Entity_Id := Entity (N);
5204 -- Constant null value is for sure null
5206 if Ekind (E) = E_Constant
5207 and then Known_Null (Constant_Value (E))
5212 -- First check if we are in decisive conditional
5214 Get_Current_Value_Condition (N, Op, Val);
5216 if Known_Null (Val) then
5217 if Op = N_Op_Eq then
5219 elsif Op = N_Op_Ne then
5224 -- If OK to do replacement, test Is_Known_Null flag
5226 if OK_To_Do_Constant_Replacement (E) then
5227 return Is_Known_Null (E);
5229 -- Otherwise if not safe to do replacement, then say so
5236 -- True if explicit reference to null
5238 elsif Nkind (N) = N_Null then
5241 -- For a conversion, true if expression is known null
5243 elsif Nkind (N) = N_Type_Conversion then
5244 return Known_Null (Expression (N));
5246 -- Above are all cases where the value could be determined to be null.
5247 -- In all other cases, we don't know, so return False.
5254 -----------------------------
5255 -- Make_CW_Equivalent_Type --
5256 -----------------------------
5258 -- Create a record type used as an equivalent of any member of the class
5259 -- which takes its size from exp.
5261 -- Generate the following code:
5263 -- type Equiv_T is record
5264 -- _parent : T (List of discriminant constraints taken from Exp);
5265 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
5268 -- ??? Note that this type does not guarantee same alignment as all
5271 function Make_CW_Equivalent_Type
5273 E : Node_Id) return Entity_Id
5275 Loc : constant Source_Ptr := Sloc (E);
5276 Root_Typ : constant Entity_Id := Root_Type (T);
5277 List_Def : constant List_Id := Empty_List;
5278 Comp_List : constant List_Id := New_List;
5279 Equiv_Type : Entity_Id;
5280 Range_Type : Entity_Id;
5281 Str_Type : Entity_Id;
5282 Constr_Root : Entity_Id;
5286 -- If the root type is already constrained, there are no discriminants
5287 -- in the expression.
5289 if not Has_Discriminants (Root_Typ)
5290 or else Is_Constrained (Root_Typ)
5292 Constr_Root := Root_Typ;
5294 Constr_Root := Make_Temporary (Loc, 'R');
5296 -- subtype cstr__n is T (List of discr constraints taken from Exp)
5298 Append_To (List_Def,
5299 Make_Subtype_Declaration (Loc,
5300 Defining_Identifier => Constr_Root,
5301 Subtype_Indication => Make_Subtype_From_Expr (E, Root_Typ)));
5304 -- Generate the range subtype declaration
5306 Range_Type := Make_Temporary (Loc, 'G');
5308 if not Is_Interface (Root_Typ) then
5310 -- subtype rg__xx is
5311 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
5314 Make_Op_Subtract (Loc,
5316 Make_Attribute_Reference (Loc,
5318 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
5319 Attribute_Name => Name_Size),
5321 Make_Attribute_Reference (Loc,
5322 Prefix => New_Reference_To (Constr_Root, Loc),
5323 Attribute_Name => Name_Object_Size));
5325 -- subtype rg__xx is
5326 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
5329 Make_Attribute_Reference (Loc,
5331 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
5332 Attribute_Name => Name_Size);
5335 Set_Paren_Count (Sizexpr, 1);
5337 Append_To (List_Def,
5338 Make_Subtype_Declaration (Loc,
5339 Defining_Identifier => Range_Type,
5340 Subtype_Indication =>
5341 Make_Subtype_Indication (Loc,
5342 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
5343 Constraint => Make_Range_Constraint (Loc,
5346 Low_Bound => Make_Integer_Literal (Loc, 1),
5348 Make_Op_Divide (Loc,
5349 Left_Opnd => Sizexpr,
5350 Right_Opnd => Make_Integer_Literal (Loc,
5351 Intval => System_Storage_Unit)))))));
5353 -- subtype str__nn is Storage_Array (rg__x);
5355 Str_Type := Make_Temporary (Loc, 'S');
5356 Append_To (List_Def,
5357 Make_Subtype_Declaration (Loc,
5358 Defining_Identifier => Str_Type,
5359 Subtype_Indication =>
5360 Make_Subtype_Indication (Loc,
5361 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
5363 Make_Index_Or_Discriminant_Constraint (Loc,
5365 New_List (New_Reference_To (Range_Type, Loc))))));
5367 -- type Equiv_T is record
5368 -- [ _parent : Tnn; ]
5372 Equiv_Type := Make_Temporary (Loc, 'T');
5373 Set_Ekind (Equiv_Type, E_Record_Type);
5374 Set_Parent_Subtype (Equiv_Type, Constr_Root);
5376 -- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
5377 -- treatment for this type. In particular, even though _parent's type
5378 -- is a controlled type or contains controlled components, we do not
5379 -- want to set Has_Controlled_Component on it to avoid making it gain
5380 -- an unwanted _controller component.
5382 Set_Is_Class_Wide_Equivalent_Type (Equiv_Type);
5384 if not Is_Interface (Root_Typ) then
5385 Append_To (Comp_List,
5386 Make_Component_Declaration (Loc,
5387 Defining_Identifier =>
5388 Make_Defining_Identifier (Loc, Name_uParent),
5389 Component_Definition =>
5390 Make_Component_Definition (Loc,
5391 Aliased_Present => False,
5392 Subtype_Indication => New_Reference_To (Constr_Root, Loc))));
5395 Append_To (Comp_List,
5396 Make_Component_Declaration (Loc,
5397 Defining_Identifier => Make_Temporary (Loc, 'C'),
5398 Component_Definition =>
5399 Make_Component_Definition (Loc,
5400 Aliased_Present => False,
5401 Subtype_Indication => New_Reference_To (Str_Type, Loc))));
5403 Append_To (List_Def,
5404 Make_Full_Type_Declaration (Loc,
5405 Defining_Identifier => Equiv_Type,
5407 Make_Record_Definition (Loc,
5409 Make_Component_List (Loc,
5410 Component_Items => Comp_List,
5411 Variant_Part => Empty))));
5413 -- Suppress all checks during the analysis of the expanded code to avoid
5414 -- the generation of spurious warnings under ZFP run-time.
5416 Insert_Actions (E, List_Def, Suppress => All_Checks);
5418 end Make_CW_Equivalent_Type;
5420 -------------------------
5421 -- Make_Invariant_Call --
5422 -------------------------
5424 function Make_Invariant_Call (Expr : Node_Id) return Node_Id is
5425 Loc : constant Source_Ptr := Sloc (Expr);
5426 Typ : constant Entity_Id := Etype (Expr);
5430 (Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)));
5432 if Check_Enabled (Name_Invariant)
5434 Check_Enabled (Name_Assertion)
5437 Make_Procedure_Call_Statement (Loc,
5439 New_Occurrence_Of (Invariant_Procedure (Typ), Loc),
5440 Parameter_Associations => New_List (Relocate_Node (Expr)));
5444 Make_Null_Statement (Loc);
5446 end Make_Invariant_Call;
5448 ------------------------
5449 -- Make_Literal_Range --
5450 ------------------------
5452 function Make_Literal_Range
5454 Literal_Typ : Entity_Id) return Node_Id
5456 Lo : constant Node_Id :=
5457 New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
5458 Index : constant Entity_Id := Etype (Lo);
5461 Length_Expr : constant Node_Id :=
5462 Make_Op_Subtract (Loc,
5464 Make_Integer_Literal (Loc,
5465 Intval => String_Literal_Length (Literal_Typ)),
5467 Make_Integer_Literal (Loc, 1));
5470 Set_Analyzed (Lo, False);
5472 if Is_Integer_Type (Index) then
5475 Left_Opnd => New_Copy_Tree (Lo),
5476 Right_Opnd => Length_Expr);
5479 Make_Attribute_Reference (Loc,
5480 Attribute_Name => Name_Val,
5481 Prefix => New_Occurrence_Of (Index, Loc),
5482 Expressions => New_List (
5485 Make_Attribute_Reference (Loc,
5486 Attribute_Name => Name_Pos,
5487 Prefix => New_Occurrence_Of (Index, Loc),
5488 Expressions => New_List (New_Copy_Tree (Lo))),
5489 Right_Opnd => Length_Expr)));
5496 end Make_Literal_Range;
5498 --------------------------
5499 -- Make_Non_Empty_Check --
5500 --------------------------
5502 function Make_Non_Empty_Check
5504 N : Node_Id) return Node_Id
5510 Make_Attribute_Reference (Loc,
5511 Attribute_Name => Name_Length,
5512 Prefix => Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
5514 Make_Integer_Literal (Loc, 0));
5515 end Make_Non_Empty_Check;
5517 -------------------------
5518 -- Make_Predicate_Call --
5519 -------------------------
5521 function Make_Predicate_Call
5524 Mem : Boolean := False) return Node_Id
5526 Loc : constant Source_Ptr := Sloc (Expr);
5529 pragma Assert (Present (Predicate_Function (Typ)));
5531 -- Call special membership version if requested and available
5535 PFM : constant Entity_Id := Predicate_Function_M (Typ);
5537 if Present (PFM) then
5539 Make_Function_Call (Loc,
5540 Name => New_Occurrence_Of (PFM, Loc),
5541 Parameter_Associations => New_List (Relocate_Node (Expr)));
5546 -- Case of calling normal predicate function
5549 Make_Function_Call (Loc,
5551 New_Occurrence_Of (Predicate_Function (Typ), Loc),
5552 Parameter_Associations => New_List (Relocate_Node (Expr)));
5553 end Make_Predicate_Call;
5555 --------------------------
5556 -- Make_Predicate_Check --
5557 --------------------------
5559 function Make_Predicate_Check
5561 Expr : Node_Id) return Node_Id
5563 Loc : constant Source_Ptr := Sloc (Expr);
5568 Pragma_Identifier => Make_Identifier (Loc, Name_Check),
5569 Pragma_Argument_Associations => New_List (
5570 Make_Pragma_Argument_Association (Loc,
5571 Expression => Make_Identifier (Loc, Name_Predicate)),
5572 Make_Pragma_Argument_Association (Loc,
5573 Expression => Make_Predicate_Call (Typ, Expr))));
5574 end Make_Predicate_Check;
5576 ----------------------------
5577 -- Make_Subtype_From_Expr --
5578 ----------------------------
5580 -- 1. If Expr is an unconstrained array expression, creates
5581 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
5583 -- 2. If Expr is a unconstrained discriminated type expression, creates
5584 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
5586 -- 3. If Expr is class-wide, creates an implicit class wide subtype
5588 function Make_Subtype_From_Expr
5590 Unc_Typ : Entity_Id) return Node_Id
5592 Loc : constant Source_Ptr := Sloc (E);
5593 List_Constr : constant List_Id := New_List;
5596 Full_Subtyp : Entity_Id;
5597 Priv_Subtyp : Entity_Id;
5602 if Is_Private_Type (Unc_Typ)
5603 and then Has_Unknown_Discriminants (Unc_Typ)
5605 -- Prepare the subtype completion, Go to base type to
5606 -- find underlying type, because the type may be a generic
5607 -- actual or an explicit subtype.
5609 Utyp := Underlying_Type (Base_Type (Unc_Typ));
5610 Full_Subtyp := Make_Temporary (Loc, 'C');
5612 Unchecked_Convert_To (Utyp, Duplicate_Subexpr_No_Checks (E));
5613 Set_Parent (Full_Exp, Parent (E));
5615 Priv_Subtyp := Make_Temporary (Loc, 'P');
5618 Make_Subtype_Declaration (Loc,
5619 Defining_Identifier => Full_Subtyp,
5620 Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
5622 -- Define the dummy private subtype
5624 Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
5625 Set_Etype (Priv_Subtyp, Base_Type (Unc_Typ));
5626 Set_Scope (Priv_Subtyp, Full_Subtyp);
5627 Set_Is_Constrained (Priv_Subtyp);
5628 Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
5629 Set_Is_Itype (Priv_Subtyp);
5630 Set_Associated_Node_For_Itype (Priv_Subtyp, E);
5632 if Is_Tagged_Type (Priv_Subtyp) then
5634 (Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
5635 Set_Direct_Primitive_Operations (Priv_Subtyp,
5636 Direct_Primitive_Operations (Unc_Typ));
5639 Set_Full_View (Priv_Subtyp, Full_Subtyp);
5641 return New_Reference_To (Priv_Subtyp, Loc);
5643 elsif Is_Array_Type (Unc_Typ) then
5644 for J in 1 .. Number_Dimensions (Unc_Typ) loop
5645 Append_To (List_Constr,
5648 Make_Attribute_Reference (Loc,
5649 Prefix => Duplicate_Subexpr_No_Checks (E),
5650 Attribute_Name => Name_First,
5651 Expressions => New_List (
5652 Make_Integer_Literal (Loc, J))),
5655 Make_Attribute_Reference (Loc,
5656 Prefix => Duplicate_Subexpr_No_Checks (E),
5657 Attribute_Name => Name_Last,
5658 Expressions => New_List (
5659 Make_Integer_Literal (Loc, J)))));
5662 elsif Is_Class_Wide_Type (Unc_Typ) then
5664 CW_Subtype : Entity_Id;
5665 EQ_Typ : Entity_Id := Empty;
5668 -- A class-wide equivalent type is not needed when VM_Target
5669 -- because the VM back-ends handle the class-wide object
5670 -- initialization itself (and doesn't need or want the
5671 -- additional intermediate type to handle the assignment).
5673 if Expander_Active and then Tagged_Type_Expansion then
5675 -- If this is the class_wide type of a completion that is a
5676 -- record subtype, set the type of the class_wide type to be
5677 -- the full base type, for use in the expanded code for the
5678 -- equivalent type. Should this be done earlier when the
5679 -- completion is analyzed ???
5681 if Is_Private_Type (Etype (Unc_Typ))
5683 Ekind (Full_View (Etype (Unc_Typ))) = E_Record_Subtype
5685 Set_Etype (Unc_Typ, Base_Type (Full_View (Etype (Unc_Typ))));
5688 EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
5691 CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
5692 Set_Equivalent_Type (CW_Subtype, EQ_Typ);
5693 Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
5695 return New_Occurrence_Of (CW_Subtype, Loc);
5698 -- Indefinite record type with discriminants
5701 D := First_Discriminant (Unc_Typ);
5702 while Present (D) loop
5703 Append_To (List_Constr,
5704 Make_Selected_Component (Loc,
5705 Prefix => Duplicate_Subexpr_No_Checks (E),
5706 Selector_Name => New_Reference_To (D, Loc)));
5708 Next_Discriminant (D);
5713 Make_Subtype_Indication (Loc,
5714 Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
5716 Make_Index_Or_Discriminant_Constraint (Loc,
5717 Constraints => List_Constr));
5718 end Make_Subtype_From_Expr;
5720 -----------------------------
5721 -- May_Generate_Large_Temp --
5722 -----------------------------
5724 -- At the current time, the only types that we return False for (i.e. where
5725 -- we decide we know they cannot generate large temps) are ones where we
5726 -- know the size is 256 bits or less at compile time, and we are still not
5727 -- doing a thorough job on arrays and records ???
5729 function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
5731 if not Size_Known_At_Compile_Time (Typ) then
5734 elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
5737 elsif Is_Array_Type (Typ) and then Present (Packed_Array_Type (Typ)) then
5738 return May_Generate_Large_Temp (Packed_Array_Type (Typ));
5740 -- We could do more here to find other small types ???
5745 end May_Generate_Large_Temp;
5747 ------------------------
5748 -- Needs_Finalization --
5749 ------------------------
5751 function Needs_Finalization (T : Entity_Id) return Boolean is
5752 function Has_Some_Controlled_Component (Rec : Entity_Id) return Boolean;
5753 -- If type is not frozen yet, check explicitly among its components,
5754 -- because the Has_Controlled_Component flag is not necessarily set.
5756 -----------------------------------
5757 -- Has_Some_Controlled_Component --
5758 -----------------------------------
5760 function Has_Some_Controlled_Component
5761 (Rec : Entity_Id) return Boolean
5766 if Has_Controlled_Component (Rec) then
5769 elsif not Is_Frozen (Rec) then
5770 if Is_Record_Type (Rec) then
5771 Comp := First_Entity (Rec);
5773 while Present (Comp) loop
5774 if not Is_Type (Comp)
5775 and then Needs_Finalization (Etype (Comp))
5785 elsif Is_Array_Type (Rec) then
5786 return Needs_Finalization (Component_Type (Rec));
5789 return Has_Controlled_Component (Rec);
5794 end Has_Some_Controlled_Component;
5796 -- Start of processing for Needs_Finalization
5799 -- Certain run-time configurations and targets do not provide support
5800 -- for controlled types.
5802 if Restriction_Active (No_Finalization) then
5805 -- C, C++, CIL and Java types are not considered controlled. It is
5806 -- assumed that the non-Ada side will handle their clean up.
5808 elsif Convention (T) = Convention_C
5809 or else Convention (T) = Convention_CIL
5810 or else Convention (T) = Convention_CPP
5811 or else Convention (T) = Convention_Java
5816 -- Class-wide types are treated as controlled because derivations
5817 -- from the root type can introduce controlled components.
5820 Is_Class_Wide_Type (T)
5821 or else Is_Controlled (T)
5822 or else Has_Controlled_Component (T)
5823 or else Has_Some_Controlled_Component (T)
5825 (Is_Concurrent_Type (T)
5826 and then Present (Corresponding_Record_Type (T))
5827 and then Needs_Finalization (Corresponding_Record_Type (T)));
5829 end Needs_Finalization;
5831 ----------------------------
5832 -- Needs_Constant_Address --
5833 ----------------------------
5835 function Needs_Constant_Address
5837 Typ : Entity_Id) return Boolean
5841 -- If we have no initialization of any kind, then we don't need to place
5842 -- any restrictions on the address clause, because the object will be
5843 -- elaborated after the address clause is evaluated. This happens if the
5844 -- declaration has no initial expression, or the type has no implicit
5845 -- initialization, or the object is imported.
5847 -- The same holds for all initialized scalar types and all access types.
5848 -- Packed bit arrays of size up to 64 are represented using a modular
5849 -- type with an initialization (to zero) and can be processed like other
5850 -- initialized scalar types.
5852 -- If the type is controlled, code to attach the object to a
5853 -- finalization chain is generated at the point of declaration, and
5854 -- therefore the elaboration of the object cannot be delayed: the
5855 -- address expression must be a constant.
5857 if No (Expression (Decl))
5858 and then not Needs_Finalization (Typ)
5860 (not Has_Non_Null_Base_Init_Proc (Typ)
5861 or else Is_Imported (Defining_Identifier (Decl)))
5865 elsif (Present (Expression (Decl)) and then Is_Scalar_Type (Typ))
5866 or else Is_Access_Type (Typ)
5868 (Is_Bit_Packed_Array (Typ)
5869 and then Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
5875 -- Otherwise, we require the address clause to be constant because
5876 -- the call to the initialization procedure (or the attach code) has
5877 -- to happen at the point of the declaration.
5879 -- Actually the IP call has been moved to the freeze actions anyway,
5880 -- so maybe we can relax this restriction???
5884 end Needs_Constant_Address;
5886 ----------------------------
5887 -- New_Class_Wide_Subtype --
5888 ----------------------------
5890 function New_Class_Wide_Subtype
5891 (CW_Typ : Entity_Id;
5892 N : Node_Id) return Entity_Id
5894 Res : constant Entity_Id := Create_Itype (E_Void, N);
5895 Res_Name : constant Name_Id := Chars (Res);
5896 Res_Scope : constant Entity_Id := Scope (Res);
5899 Copy_Node (CW_Typ, Res);
5900 Set_Comes_From_Source (Res, False);
5901 Set_Sloc (Res, Sloc (N));
5903 Set_Associated_Node_For_Itype (Res, N);
5904 Set_Is_Public (Res, False); -- By default, may be changed below.
5905 Set_Public_Status (Res);
5906 Set_Chars (Res, Res_Name);
5907 Set_Scope (Res, Res_Scope);
5908 Set_Ekind (Res, E_Class_Wide_Subtype);
5909 Set_Next_Entity (Res, Empty);
5910 Set_Etype (Res, Base_Type (CW_Typ));
5911 Set_Is_Frozen (Res, False);
5912 Set_Freeze_Node (Res, Empty);
5914 end New_Class_Wide_Subtype;
5916 --------------------------------
5917 -- Non_Limited_Designated_Type --
5918 ---------------------------------
5920 function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id is
5921 Desig : constant Entity_Id := Designated_Type (T);
5923 if Ekind (Desig) = E_Incomplete_Type
5924 and then Present (Non_Limited_View (Desig))
5926 return Non_Limited_View (Desig);
5930 end Non_Limited_Designated_Type;
5932 -----------------------------------
5933 -- OK_To_Do_Constant_Replacement --
5934 -----------------------------------
5936 function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean is
5937 ES : constant Entity_Id := Scope (E);
5941 -- Do not replace statically allocated objects, because they may be
5942 -- modified outside the current scope.
5944 if Is_Statically_Allocated (E) then
5947 -- Do not replace aliased or volatile objects, since we don't know what
5948 -- else might change the value.
5950 elsif Is_Aliased (E) or else Treat_As_Volatile (E) then
5953 -- Debug flag -gnatdM disconnects this optimization
5955 elsif Debug_Flag_MM then
5958 -- Otherwise check scopes
5961 CS := Current_Scope;
5964 -- If we are in right scope, replacement is safe
5969 -- Packages do not affect the determination of safety
5971 elsif Ekind (CS) = E_Package then
5972 exit when CS = Standard_Standard;
5975 -- Blocks do not affect the determination of safety
5977 elsif Ekind (CS) = E_Block then
5980 -- Loops do not affect the determination of safety. Note that we
5981 -- kill all current values on entry to a loop, so we are just
5982 -- talking about processing within a loop here.
5984 elsif Ekind (CS) = E_Loop then
5987 -- Otherwise, the reference is dubious, and we cannot be sure that
5988 -- it is safe to do the replacement.
5997 end OK_To_Do_Constant_Replacement;
5999 ------------------------------------
6000 -- Possible_Bit_Aligned_Component --
6001 ------------------------------------
6003 function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean is
6007 -- Case of indexed component
6009 when N_Indexed_Component =>
6011 P : constant Node_Id := Prefix (N);
6012 Ptyp : constant Entity_Id := Etype (P);
6015 -- If we know the component size and it is less than 64, then
6016 -- we are definitely OK. The back end always does assignment of
6017 -- misaligned small objects correctly.
6019 if Known_Static_Component_Size (Ptyp)
6020 and then Component_Size (Ptyp) <= 64
6024 -- Otherwise, we need to test the prefix, to see if we are
6025 -- indexing from a possibly unaligned component.
6028 return Possible_Bit_Aligned_Component (P);
6032 -- Case of selected component
6034 when N_Selected_Component =>
6036 P : constant Node_Id := Prefix (N);
6037 Comp : constant Entity_Id := Entity (Selector_Name (N));
6040 -- If there is no component clause, then we are in the clear
6041 -- since the back end will never misalign a large component
6042 -- unless it is forced to do so. In the clear means we need
6043 -- only the recursive test on the prefix.
6045 if Component_May_Be_Bit_Aligned (Comp) then
6048 return Possible_Bit_Aligned_Component (P);
6052 -- For a slice, test the prefix, if that is possibly misaligned,
6053 -- then for sure the slice is!
6056 return Possible_Bit_Aligned_Component (Prefix (N));
6058 -- For an unchecked conversion, check whether the expression may
6061 when N_Unchecked_Type_Conversion =>
6062 return Possible_Bit_Aligned_Component (Expression (N));
6064 -- If we have none of the above, it means that we have fallen off the
6065 -- top testing prefixes recursively, and we now have a stand alone
6066 -- object, where we don't have a problem.
6072 end Possible_Bit_Aligned_Component;
6074 -----------------------------------------------
6075 -- Process_Statements_For_Controlled_Objects --
6076 -----------------------------------------------
6078 procedure Process_Statements_For_Controlled_Objects (N : Node_Id) is
6079 Loc : constant Source_Ptr := Sloc (N);
6081 function Are_Wrapped (L : List_Id) return Boolean;
6082 -- Determine whether list L contains only one statement which is a block
6084 function Wrap_Statements_In_Block (L : List_Id) return Node_Id;
6085 -- Given a list of statements L, wrap it in a block statement and return
6086 -- the generated node.
6092 function Are_Wrapped (L : List_Id) return Boolean is
6093 Stmt : constant Node_Id := First (L);
6097 and then No (Next (Stmt))
6098 and then Nkind (Stmt) = N_Block_Statement;
6101 ------------------------------
6102 -- Wrap_Statements_In_Block --
6103 ------------------------------
6105 function Wrap_Statements_In_Block (L : List_Id) return Node_Id is
6108 Make_Block_Statement (Loc,
6109 Declarations => No_List,
6110 Handled_Statement_Sequence =>
6111 Make_Handled_Sequence_Of_Statements (Loc,
6113 end Wrap_Statements_In_Block;
6119 -- Start of processing for Process_Statements_For_Controlled_Objects
6122 -- Whenever a non-handled statement list is wrapped in a block, the
6123 -- block must be explicitly analyzed to redecorate all entities in the
6124 -- list and ensure that a finalizer is properly built.
6129 N_Conditional_Entry_Call |
6130 N_Selective_Accept =>
6132 -- Check the "then statements" for elsif parts and if statements
6134 if Nkind_In (N, N_Elsif_Part, N_If_Statement)
6135 and then not Is_Empty_List (Then_Statements (N))
6136 and then not Are_Wrapped (Then_Statements (N))
6137 and then Requires_Cleanup_Actions
6138 (Then_Statements (N), False, False)
6140 Block := Wrap_Statements_In_Block (Then_Statements (N));
6141 Set_Then_Statements (N, New_List (Block));
6146 -- Check the "else statements" for conditional entry calls, if
6147 -- statements and selective accepts.
6149 if Nkind_In (N, N_Conditional_Entry_Call,
6152 and then not Is_Empty_List (Else_Statements (N))
6153 and then not Are_Wrapped (Else_Statements (N))
6154 and then Requires_Cleanup_Actions
6155 (Else_Statements (N), False, False)
6157 Block := Wrap_Statements_In_Block (Else_Statements (N));
6158 Set_Else_Statements (N, New_List (Block));
6163 when N_Abortable_Part |
6164 N_Accept_Alternative |
6165 N_Case_Statement_Alternative |
6166 N_Delay_Alternative |
6167 N_Entry_Call_Alternative |
6168 N_Exception_Handler |
6170 N_Triggering_Alternative =>
6172 if not Is_Empty_List (Statements (N))
6173 and then not Are_Wrapped (Statements (N))
6174 and then Requires_Cleanup_Actions (Statements (N), False, False)
6176 Block := Wrap_Statements_In_Block (Statements (N));
6177 Set_Statements (N, New_List (Block));
6185 end Process_Statements_For_Controlled_Objects;
6187 ----------------------
6188 -- Remove_Init_Call --
6189 ----------------------
6191 function Remove_Init_Call
6193 Rep_Clause : Node_Id) return Node_Id
6195 Par : constant Node_Id := Parent (Var);
6196 Typ : constant Entity_Id := Etype (Var);
6198 Init_Proc : Entity_Id;
6199 -- Initialization procedure for Typ
6201 function Find_Init_Call_In_List (From : Node_Id) return Node_Id;
6202 -- Look for init call for Var starting at From and scanning the
6203 -- enclosing list until Rep_Clause or the end of the list is reached.
6205 ----------------------------
6206 -- Find_Init_Call_In_List --
6207 ----------------------------
6209 function Find_Init_Call_In_List (From : Node_Id) return Node_Id is
6210 Init_Call : Node_Id;
6214 while Present (Init_Call) and then Init_Call /= Rep_Clause loop
6215 if Nkind (Init_Call) = N_Procedure_Call_Statement
6216 and then Is_Entity_Name (Name (Init_Call))
6217 and then Entity (Name (Init_Call)) = Init_Proc
6226 end Find_Init_Call_In_List;
6228 Init_Call : Node_Id;
6230 -- Start of processing for Find_Init_Call
6233 if Present (Initialization_Statements (Var)) then
6234 Init_Call := Initialization_Statements (Var);
6235 Set_Initialization_Statements (Var, Empty);
6237 elsif not Has_Non_Null_Base_Init_Proc (Typ) then
6239 -- No init proc for the type, so obviously no call to be found
6244 -- We might be able to handle other cases below by just properly
6245 -- setting Initialization_Statements at the point where the init proc
6246 -- call is generated???
6248 Init_Proc := Base_Init_Proc (Typ);
6250 -- First scan the list containing the declaration of Var
6252 Init_Call := Find_Init_Call_In_List (From => Next (Par));
6254 -- If not found, also look on Var's freeze actions list, if any,
6255 -- since the init call may have been moved there (case of an address
6256 -- clause applying to Var).
6258 if No (Init_Call) and then Present (Freeze_Node (Var)) then
6260 Find_Init_Call_In_List (First (Actions (Freeze_Node (Var))));
6263 -- If the initialization call has actuals that use the secondary
6264 -- stack, the call may have been wrapped into a temporary block, in
6265 -- which case the block itself has to be removed.
6267 if No (Init_Call) and then Nkind (Next (Par)) = N_Block_Statement then
6269 Blk : constant Node_Id := Next (Par);
6272 (Find_Init_Call_In_List
6273 (First (Statements (Handled_Statement_Sequence (Blk)))))
6281 if Present (Init_Call) then
6285 end Remove_Init_Call;
6287 -------------------------
6288 -- Remove_Side_Effects --
6289 -------------------------
6291 procedure Remove_Side_Effects
6293 Name_Req : Boolean := False;
6294 Variable_Ref : Boolean := False)
6296 Loc : constant Source_Ptr := Sloc (Exp);
6297 Exp_Type : constant Entity_Id := Etype (Exp);
6298 Svg_Suppress : constant Suppress_Record := Scope_Suppress;
6302 Ptr_Typ_Decl : Node_Id;
6303 Ref_Type : Entity_Id;
6306 function Side_Effect_Free (N : Node_Id) return Boolean;
6307 -- Determines if the tree N represents an expression that is known not
6308 -- to have side effects, and for which no processing is required.
6310 function Side_Effect_Free (L : List_Id) return Boolean;
6311 -- Determines if all elements of the list L are side effect free
6313 function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
6314 -- The argument N is a construct where the Prefix is dereferenced if it
6315 -- is an access type and the result is a variable. The call returns True
6316 -- if the construct is side effect free (not considering side effects in
6317 -- other than the prefix which are to be tested by the caller).
6319 function Within_In_Parameter (N : Node_Id) return Boolean;
6320 -- Determines if N is a subcomponent of a composite in-parameter. If so,
6321 -- N is not side-effect free when the actual is global and modifiable
6322 -- indirectly from within a subprogram, because it may be passed by
6323 -- reference. The front-end must be conservative here and assume that
6324 -- this may happen with any array or record type. On the other hand, we
6325 -- cannot create temporaries for all expressions for which this
6326 -- condition is true, for various reasons that might require clearing up
6327 -- ??? For example, discriminant references that appear out of place, or
6328 -- spurious type errors with class-wide expressions. As a result, we
6329 -- limit the transformation to loop bounds, which is so far the only
6330 -- case that requires it.
6332 -----------------------------
6333 -- Safe_Prefixed_Reference --
6334 -----------------------------
6336 function Safe_Prefixed_Reference (N : Node_Id) return Boolean is
6338 -- If prefix is not side effect free, definitely not safe
6340 if not Side_Effect_Free (Prefix (N)) then
6343 -- If the prefix is of an access type that is not access-to-constant,
6344 -- then this construct is a variable reference, which means it is to
6345 -- be considered to have side effects if Variable_Ref is set True.
6347 elsif Is_Access_Type (Etype (Prefix (N)))
6348 and then not Is_Access_Constant (Etype (Prefix (N)))
6349 and then Variable_Ref
6351 -- Exception is a prefix that is the result of a previous removal
6354 return Is_Entity_Name (Prefix (N))
6355 and then not Comes_From_Source (Prefix (N))
6356 and then Ekind (Entity (Prefix (N))) = E_Constant
6357 and then Is_Internal_Name (Chars (Entity (Prefix (N))));
6359 -- If the prefix is an explicit dereference then this construct is a
6360 -- variable reference, which means it is to be considered to have
6361 -- side effects if Variable_Ref is True.
6363 -- We do NOT exclude dereferences of access-to-constant types because
6364 -- we handle them as constant view of variables.
6366 elsif Nkind (Prefix (N)) = N_Explicit_Dereference
6367 and then Variable_Ref
6371 -- Note: The following test is the simplest way of solving a complex
6372 -- problem uncovered by the following test (Side effect on loop bound
6373 -- that is a subcomponent of a global variable:
6375 -- with Text_Io; use Text_Io;
6376 -- procedure Tloop is
6379 -- V : Natural := 4;
6380 -- S : String (1..5) := (others => 'a');
6387 -- with procedure Action;
6388 -- procedure Loop_G (Arg : X; Msg : String)
6390 -- procedure Loop_G (Arg : X; Msg : String) is
6392 -- Put_Line ("begin loop_g " & Msg & " will loop till: "
6393 -- & Natural'Image (Arg.V));
6394 -- for Index in 1 .. Arg.V loop
6396 -- (Natural'Image (Index) & " " & Arg.S (Index));
6397 -- if Index > 2 then
6401 -- Put_Line ("end loop_g " & Msg);
6404 -- procedure Loop1 is new Loop_G (Modi);
6405 -- procedure Modi is
6408 -- Loop1 (X1, "from modi");
6412 -- Loop1 (X1, "initial");
6415 -- The output of the above program should be:
6417 -- begin loop_g initial will loop till: 4
6421 -- begin loop_g from modi will loop till: 1
6423 -- end loop_g from modi
6425 -- begin loop_g from modi will loop till: 1
6427 -- end loop_g from modi
6428 -- end loop_g initial
6430 -- If a loop bound is a subcomponent of a global variable, a
6431 -- modification of that variable within the loop may incorrectly
6432 -- affect the execution of the loop.
6434 elsif Nkind (Parent (Parent (N))) = N_Loop_Parameter_Specification
6435 and then Within_In_Parameter (Prefix (N))
6436 and then Variable_Ref
6440 -- All other cases are side effect free
6445 end Safe_Prefixed_Reference;
6447 ----------------------
6448 -- Side_Effect_Free --
6449 ----------------------
6451 function Side_Effect_Free (N : Node_Id) return Boolean is
6453 -- Note on checks that could raise Constraint_Error. Strictly, if we
6454 -- take advantage of 11.6, these checks do not count as side effects.
6455 -- However, we would prefer to consider that they are side effects,
6456 -- since the backend CSE does not work very well on expressions which
6457 -- can raise Constraint_Error. On the other hand if we don't consider
6458 -- them to be side effect free, then we get some awkward expansions
6459 -- in -gnato mode, resulting in code insertions at a point where we
6460 -- do not have a clear model for performing the insertions.
6462 -- Special handling for entity names
6464 if Is_Entity_Name (N) then
6466 -- Variables are considered to be a side effect if Variable_Ref
6467 -- is set or if we have a volatile reference and Name_Req is off.
6468 -- If Name_Req is True then we can't help returning a name which
6469 -- effectively allows multiple references in any case.
6471 if Is_Variable (N, Use_Original_Node => False) then
6472 return not Variable_Ref
6473 and then (not Is_Volatile_Reference (N) or else Name_Req);
6475 -- Any other entity (e.g. a subtype name) is definitely side
6482 -- A value known at compile time is always side effect free
6484 elsif Compile_Time_Known_Value (N) then
6487 -- A variable renaming is not side-effect free, because the renaming
6488 -- will function like a macro in the front-end in some cases, and an
6489 -- assignment can modify the component designated by N, so we need to
6490 -- create a temporary for it.
6492 -- The guard testing for Entity being present is needed at least in
6493 -- the case of rewritten predicate expressions, and may well also be
6494 -- appropriate elsewhere. Obviously we can't go testing the entity
6495 -- field if it does not exist, so it's reasonable to say that this is
6496 -- not the renaming case if it does not exist.
6498 elsif Is_Entity_Name (Original_Node (N))
6499 and then Present (Entity (Original_Node (N)))
6500 and then Is_Renaming_Of_Object (Entity (Original_Node (N)))
6501 and then Ekind (Entity (Original_Node (N))) /= E_Constant
6504 RO : constant Node_Id :=
6505 Renamed_Object (Entity (Original_Node (N)));
6508 -- If the renamed object is an indexed component, or an
6509 -- explicit dereference, then the designated object could
6510 -- be modified by an assignment.
6512 if Nkind_In (RO, N_Indexed_Component,
6513 N_Explicit_Dereference)
6517 -- A selected component must have a safe prefix
6519 elsif Nkind (RO) = N_Selected_Component then
6520 return Safe_Prefixed_Reference (RO);
6522 -- In all other cases, designated object cannot be changed so
6523 -- we are side effect free.
6530 -- Remove_Side_Effects generates an object renaming declaration to
6531 -- capture the expression of a class-wide expression. In VM targets
6532 -- the frontend performs no expansion for dispatching calls to
6533 -- class- wide types since they are handled by the VM. Hence, we must
6534 -- locate here if this node corresponds to a previous invocation of
6535 -- Remove_Side_Effects to avoid a never ending loop in the frontend.
6537 elsif VM_Target /= No_VM
6538 and then not Comes_From_Source (N)
6539 and then Nkind (Parent (N)) = N_Object_Renaming_Declaration
6540 and then Is_Class_Wide_Type (Etype (N))
6545 -- For other than entity names and compile time known values,
6546 -- check the node kind for special processing.
6550 -- An attribute reference is side effect free if its expressions
6551 -- are side effect free and its prefix is side effect free or
6552 -- is an entity reference.
6554 -- Is this right? what about x'first where x is a variable???
6556 when N_Attribute_Reference =>
6557 return Side_Effect_Free (Expressions (N))
6558 and then Attribute_Name (N) /= Name_Input
6559 and then (Is_Entity_Name (Prefix (N))
6560 or else Side_Effect_Free (Prefix (N)));
6562 -- A binary operator is side effect free if and both operands are
6563 -- side effect free. For this purpose binary operators include
6564 -- membership tests and short circuit forms.
6566 when N_Binary_Op | N_Membership_Test | N_Short_Circuit =>
6567 return Side_Effect_Free (Left_Opnd (N))
6569 Side_Effect_Free (Right_Opnd (N));
6571 -- An explicit dereference is side effect free only if it is
6572 -- a side effect free prefixed reference.
6574 when N_Explicit_Dereference =>
6575 return Safe_Prefixed_Reference (N);
6577 -- A call to _rep_to_pos is side effect free, since we generate
6578 -- this pure function call ourselves. Moreover it is critically
6579 -- important to make this exception, since otherwise we can have
6580 -- discriminants in array components which don't look side effect
6581 -- free in the case of an array whose index type is an enumeration
6582 -- type with an enumeration rep clause.
6584 -- All other function calls are not side effect free
6586 when N_Function_Call =>
6587 return Nkind (Name (N)) = N_Identifier
6588 and then Is_TSS (Name (N), TSS_Rep_To_Pos)
6590 Side_Effect_Free (First (Parameter_Associations (N)));
6592 -- An indexed component is side effect free if it is a side
6593 -- effect free prefixed reference and all the indexing
6594 -- expressions are side effect free.
6596 when N_Indexed_Component =>
6597 return Side_Effect_Free (Expressions (N))
6598 and then Safe_Prefixed_Reference (N);
6600 -- A type qualification is side effect free if the expression
6601 -- is side effect free.
6603 when N_Qualified_Expression =>
6604 return Side_Effect_Free (Expression (N));
6606 -- A selected component is side effect free only if it is a side
6607 -- effect free prefixed reference. If it designates a component
6608 -- with a rep. clause it must be treated has having a potential
6609 -- side effect, because it may be modified through a renaming, and
6610 -- a subsequent use of the renaming as a macro will yield the
6611 -- wrong value. This complex interaction between renaming and
6612 -- removing side effects is a reminder that the latter has become
6613 -- a headache to maintain, and that it should be removed in favor
6614 -- of the gcc mechanism to capture values ???
6616 when N_Selected_Component =>
6617 if Nkind (Parent (N)) = N_Explicit_Dereference
6618 and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
6622 return Safe_Prefixed_Reference (N);
6625 -- A range is side effect free if the bounds are side effect free
6628 return Side_Effect_Free (Low_Bound (N))
6629 and then Side_Effect_Free (High_Bound (N));
6631 -- A slice is side effect free if it is a side effect free
6632 -- prefixed reference and the bounds are side effect free.
6635 return Side_Effect_Free (Discrete_Range (N))
6636 and then Safe_Prefixed_Reference (N);
6638 -- A type conversion is side effect free if the expression to be
6639 -- converted is side effect free.
6641 when N_Type_Conversion =>
6642 return Side_Effect_Free (Expression (N));
6644 -- A unary operator is side effect free if the operand
6645 -- is side effect free.
6648 return Side_Effect_Free (Right_Opnd (N));
6650 -- An unchecked type conversion is side effect free only if it
6651 -- is safe and its argument is side effect free.
6653 when N_Unchecked_Type_Conversion =>
6654 return Safe_Unchecked_Type_Conversion (N)
6655 and then Side_Effect_Free (Expression (N));
6657 -- An unchecked expression is side effect free if its expression
6658 -- is side effect free.
6660 when N_Unchecked_Expression =>
6661 return Side_Effect_Free (Expression (N));
6663 -- A literal is side effect free
6665 when N_Character_Literal |
6671 -- We consider that anything else has side effects. This is a bit
6672 -- crude, but we are pretty close for most common cases, and we
6673 -- are certainly correct (i.e. we never return True when the
6674 -- answer should be False).
6679 end Side_Effect_Free;
6681 -- A list is side effect free if all elements of the list are side
6684 function Side_Effect_Free (L : List_Id) return Boolean is
6688 if L = No_List or else L = Error_List then
6693 while Present (N) loop
6694 if not Side_Effect_Free (N) then
6703 end Side_Effect_Free;
6705 -------------------------
6706 -- Within_In_Parameter --
6707 -------------------------
6709 function Within_In_Parameter (N : Node_Id) return Boolean is
6711 if not Comes_From_Source (N) then
6714 elsif Is_Entity_Name (N) then
6715 return Ekind (Entity (N)) = E_In_Parameter;
6717 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
6718 return Within_In_Parameter (Prefix (N));
6723 end Within_In_Parameter;
6725 -- Start of processing for Remove_Side_Effects
6728 -- Handle cases in which there is nothing to do
6730 if not Expander_Active then
6734 -- Cannot generate temporaries if the invocation to remove side effects
6735 -- was issued too early and the type of the expression is not resolved
6736 -- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
6737 -- Remove_Side_Effects).
6740 or else Ekind (Exp_Type) = E_Access_Attribute_Type
6744 -- No action needed for side-effect free expressions
6746 elsif Side_Effect_Free (Exp) then
6750 -- The remaining procesaing is done with all checks suppressed
6752 -- Note: from now on, don't use return statements, instead do a goto
6753 -- Leave, to ensure that we properly restore Scope_Suppress.Suppress.
6755 Scope_Suppress.Suppress := (others => True);
6757 -- If it is a scalar type and we need to capture the value, just make
6758 -- a copy. Likewise for a function call, an attribute reference, an
6759 -- allocator, or an operator. And if we have a volatile reference and
6760 -- Name_Req is not set (see comments above for Side_Effect_Free).
6762 if Is_Elementary_Type (Exp_Type)
6763 and then (Variable_Ref
6764 or else Nkind_In (Exp, N_Function_Call,
6765 N_Attribute_Reference,
6767 or else Nkind (Exp) in N_Op
6768 or else (not Name_Req and then Is_Volatile_Reference (Exp)))
6770 Def_Id := Make_Temporary (Loc, 'R', Exp);
6771 Set_Etype (Def_Id, Exp_Type);
6772 Res := New_Reference_To (Def_Id, Loc);
6774 -- If the expression is a packed reference, it must be reanalyzed and
6775 -- expanded, depending on context. This is the case for actuals where
6776 -- a constraint check may capture the actual before expansion of the
6777 -- call is complete.
6779 if Nkind (Exp) = N_Indexed_Component
6780 and then Is_Packed (Etype (Prefix (Exp)))
6782 Set_Analyzed (Exp, False);
6783 Set_Analyzed (Prefix (Exp), False);
6787 Make_Object_Declaration (Loc,
6788 Defining_Identifier => Def_Id,
6789 Object_Definition => New_Reference_To (Exp_Type, Loc),
6790 Constant_Present => True,
6791 Expression => Relocate_Node (Exp));
6793 Set_Assignment_OK (E);
6794 Insert_Action (Exp, E);
6796 -- If the expression has the form v.all then we can just capture the
6797 -- pointer, and then do an explicit dereference on the result.
6799 elsif Nkind (Exp) = N_Explicit_Dereference then
6800 Def_Id := Make_Temporary (Loc, 'R', Exp);
6802 Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
6805 Make_Object_Declaration (Loc,
6806 Defining_Identifier => Def_Id,
6807 Object_Definition =>
6808 New_Reference_To (Etype (Prefix (Exp)), Loc),
6809 Constant_Present => True,
6810 Expression => Relocate_Node (Prefix (Exp))));
6812 -- Similar processing for an unchecked conversion of an expression of
6813 -- the form v.all, where we want the same kind of treatment.
6815 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
6816 and then Nkind (Expression (Exp)) = N_Explicit_Dereference
6818 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
6821 -- If this is a type conversion, leave the type conversion and remove
6822 -- the side effects in the expression. This is important in several
6823 -- circumstances: for change of representations, and also when this is a
6824 -- view conversion to a smaller object, where gigi can end up creating
6825 -- its own temporary of the wrong size.
6827 elsif Nkind (Exp) = N_Type_Conversion then
6828 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
6831 -- If this is an unchecked conversion that Gigi can't handle, make
6832 -- a copy or a use a renaming to capture the value.
6834 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
6835 and then not Safe_Unchecked_Type_Conversion (Exp)
6837 if CW_Or_Has_Controlled_Part (Exp_Type) then
6839 -- Use a renaming to capture the expression, rather than create
6840 -- a controlled temporary.
6842 Def_Id := Make_Temporary (Loc, 'R', Exp);
6843 Res := New_Reference_To (Def_Id, Loc);
6846 Make_Object_Renaming_Declaration (Loc,
6847 Defining_Identifier => Def_Id,
6848 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
6849 Name => Relocate_Node (Exp)));
6852 Def_Id := Make_Temporary (Loc, 'R', Exp);
6853 Set_Etype (Def_Id, Exp_Type);
6854 Res := New_Reference_To (Def_Id, Loc);
6857 Make_Object_Declaration (Loc,
6858 Defining_Identifier => Def_Id,
6859 Object_Definition => New_Reference_To (Exp_Type, Loc),
6860 Constant_Present => not Is_Variable (Exp),
6861 Expression => Relocate_Node (Exp));
6863 Set_Assignment_OK (E);
6864 Insert_Action (Exp, E);
6867 -- For expressions that denote objects, we can use a renaming scheme.
6868 -- This is needed for correctness in the case of a volatile object of
6869 -- a non-volatile type because the Make_Reference call of the "default"
6870 -- approach would generate an illegal access value (an access value
6871 -- cannot designate such an object - see Analyze_Reference). We skip
6872 -- using this scheme if we have an object of a volatile type and we do
6873 -- not have Name_Req set true (see comments above for Side_Effect_Free).
6875 -- In Ada 2012 a qualified expression is an object, but for purposes of
6876 -- removing side effects it still need to be transformed into a separate
6877 -- declaration, particularly if the expression is an aggregate.
6879 elsif Is_Object_Reference (Exp)
6880 and then Nkind (Exp) /= N_Function_Call
6881 and then Nkind (Exp) /= N_Qualified_Expression
6882 and then (Name_Req or else not Treat_As_Volatile (Exp_Type))
6884 Def_Id := Make_Temporary (Loc, 'R', Exp);
6886 if Nkind (Exp) = N_Selected_Component
6887 and then Nkind (Prefix (Exp)) = N_Function_Call
6888 and then Is_Array_Type (Exp_Type)
6890 -- Avoid generating a variable-sized temporary, by generating
6891 -- the renaming declaration just for the function call. The
6892 -- transformation could be refined to apply only when the array
6893 -- component is constrained by a discriminant???
6896 Make_Selected_Component (Loc,
6897 Prefix => New_Occurrence_Of (Def_Id, Loc),
6898 Selector_Name => Selector_Name (Exp));
6901 Make_Object_Renaming_Declaration (Loc,
6902 Defining_Identifier => Def_Id,
6904 New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
6905 Name => Relocate_Node (Prefix (Exp))));
6908 Res := New_Reference_To (Def_Id, Loc);
6911 Make_Object_Renaming_Declaration (Loc,
6912 Defining_Identifier => Def_Id,
6913 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
6914 Name => Relocate_Node (Exp)));
6917 -- If this is a packed reference, or a selected component with
6918 -- a non-standard representation, a reference to the temporary
6919 -- will be replaced by a copy of the original expression (see
6920 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
6921 -- elaborated by gigi, and is of course not to be replaced in-line
6922 -- by the expression it renames, which would defeat the purpose of
6923 -- removing the side-effect.
6925 if Nkind_In (Exp, N_Selected_Component, N_Indexed_Component)
6926 and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
6930 Set_Is_Renaming_Of_Object (Def_Id, False);
6933 -- Otherwise we generate a reference to the value
6936 -- An expression which is in Alfa mode is considered side effect free
6937 -- if the resulting value is captured by a variable or a constant.
6939 if Alfa_Mode and then Nkind (Parent (Exp)) = N_Object_Declaration then
6943 -- Special processing for function calls that return a limited type.
6944 -- We need to build a declaration that will enable build-in-place
6945 -- expansion of the call. This is not done if the context is already
6946 -- an object declaration, to prevent infinite recursion.
6948 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
6949 -- to accommodate functions returning limited objects by reference.
6951 if Ada_Version >= Ada_2005
6952 and then Nkind (Exp) = N_Function_Call
6953 and then Is_Immutably_Limited_Type (Etype (Exp))
6954 and then Nkind (Parent (Exp)) /= N_Object_Declaration
6957 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', Exp);
6962 Make_Object_Declaration (Loc,
6963 Defining_Identifier => Obj,
6964 Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
6965 Expression => Relocate_Node (Exp));
6967 Insert_Action (Exp, Decl);
6968 Set_Etype (Obj, Exp_Type);
6969 Rewrite (Exp, New_Occurrence_Of (Obj, Loc));
6974 Def_Id := Make_Temporary (Loc, 'R', Exp);
6975 Set_Etype (Def_Id, Exp_Type);
6977 -- The regular expansion of functions with side effects involves the
6978 -- generation of an access type to capture the return value found on
6979 -- the secondary stack. Since Alfa (and why) cannot process access
6980 -- types, use a different approach which ignores the secondary stack
6981 -- and "copies" the returned object.
6984 Res := New_Reference_To (Def_Id, Loc);
6985 Ref_Type := Exp_Type;
6987 -- Regular expansion utilizing an access type and 'reference
6991 Make_Explicit_Dereference (Loc,
6992 Prefix => New_Reference_To (Def_Id, Loc));
6995 -- type Ann is access all <Exp_Type>;
6997 Ref_Type := Make_Temporary (Loc, 'A');
7000 Make_Full_Type_Declaration (Loc,
7001 Defining_Identifier => Ref_Type,
7003 Make_Access_To_Object_Definition (Loc,
7004 All_Present => True,
7005 Subtype_Indication =>
7006 New_Reference_To (Exp_Type, Loc)));
7008 Insert_Action (Exp, Ptr_Typ_Decl);
7012 if Nkind (E) = N_Explicit_Dereference then
7013 New_Exp := Relocate_Node (Prefix (E));
7015 E := Relocate_Node (E);
7017 -- Do not generate a 'reference in Alfa mode since the access type
7018 -- is not created in the first place.
7023 -- Otherwise generate reference, marking the value as non-null
7024 -- since we know it cannot be null and we don't want a check.
7027 New_Exp := Make_Reference (Loc, E);
7028 Set_Is_Known_Non_Null (Def_Id);
7032 if Is_Delayed_Aggregate (E) then
7034 -- The expansion of nested aggregates is delayed until the
7035 -- enclosing aggregate is expanded. As aggregates are often
7036 -- qualified, the predicate applies to qualified expressions as
7037 -- well, indicating that the enclosing aggregate has not been
7038 -- expanded yet. At this point the aggregate is part of a
7039 -- stand-alone declaration, and must be fully expanded.
7041 if Nkind (E) = N_Qualified_Expression then
7042 Set_Expansion_Delayed (Expression (E), False);
7043 Set_Analyzed (Expression (E), False);
7045 Set_Expansion_Delayed (E, False);
7048 Set_Analyzed (E, False);
7052 Make_Object_Declaration (Loc,
7053 Defining_Identifier => Def_Id,
7054 Object_Definition => New_Reference_To (Ref_Type, Loc),
7055 Constant_Present => True,
7056 Expression => New_Exp));
7059 -- Preserve the Assignment_OK flag in all copies, since at least one
7060 -- copy may be used in a context where this flag must be set (otherwise
7061 -- why would the flag be set in the first place).
7063 Set_Assignment_OK (Res, Assignment_OK (Exp));
7065 -- Finally rewrite the original expression and we are done
7068 Analyze_And_Resolve (Exp, Exp_Type);
7071 Scope_Suppress := Svg_Suppress;
7072 end Remove_Side_Effects;
7074 ---------------------------
7075 -- Represented_As_Scalar --
7076 ---------------------------
7078 function Represented_As_Scalar (T : Entity_Id) return Boolean is
7079 UT : constant Entity_Id := Underlying_Type (T);
7081 return Is_Scalar_Type (UT)
7082 or else (Is_Bit_Packed_Array (UT)
7083 and then Is_Scalar_Type (Packed_Array_Type (UT)));
7084 end Represented_As_Scalar;
7086 ------------------------------
7087 -- Requires_Cleanup_Actions --
7088 ------------------------------
7090 function Requires_Cleanup_Actions
7092 Lib_Level : Boolean) return Boolean
7094 At_Lib_Level : constant Boolean :=
7096 and then Nkind_In (N, N_Package_Body,
7097 N_Package_Specification);
7098 -- N is at the library level if the top-most context is a package and
7099 -- the path taken to reach N does not inlcude non-package constructs.
7103 when N_Accept_Statement |
7111 Requires_Cleanup_Actions (Declarations (N), At_Lib_Level, True)
7113 (Present (Handled_Statement_Sequence (N))
7115 Requires_Cleanup_Actions
7116 (Statements (Handled_Statement_Sequence (N)),
7117 At_Lib_Level, True));
7119 when N_Package_Specification =>
7121 Requires_Cleanup_Actions
7122 (Visible_Declarations (N), At_Lib_Level, True)
7124 Requires_Cleanup_Actions
7125 (Private_Declarations (N), At_Lib_Level, True);
7130 end Requires_Cleanup_Actions;
7132 ------------------------------
7133 -- Requires_Cleanup_Actions --
7134 ------------------------------
7136 function Requires_Cleanup_Actions
7138 Lib_Level : Boolean;
7139 Nested_Constructs : Boolean) return Boolean
7144 Obj_Typ : Entity_Id;
7145 Pack_Id : Entity_Id;
7150 or else Is_Empty_List (L)
7156 while Present (Decl) loop
7158 -- Library-level tagged types
7160 if Nkind (Decl) = N_Full_Type_Declaration then
7161 Typ := Defining_Identifier (Decl);
7163 if Is_Tagged_Type (Typ)
7164 and then Is_Library_Level_Entity (Typ)
7165 and then Convention (Typ) = Convention_Ada
7166 and then Present (Access_Disp_Table (Typ))
7167 and then RTE_Available (RE_Unregister_Tag)
7168 and then not No_Run_Time_Mode
7169 and then not Is_Abstract_Type (Typ)
7174 -- Regular object declarations
7176 elsif Nkind (Decl) = N_Object_Declaration then
7177 Obj_Id := Defining_Identifier (Decl);
7178 Obj_Typ := Base_Type (Etype (Obj_Id));
7179 Expr := Expression (Decl);
7181 -- Bypass any form of processing for objects which have their
7182 -- finalization disabled. This applies only to objects at the
7185 if Lib_Level and then Finalize_Storage_Only (Obj_Typ) then
7188 -- Transient variables are treated separately in order to minimize
7189 -- the size of the generated code. See Exp_Ch7.Process_Transient_
7192 elsif Is_Processed_Transient (Obj_Id) then
7195 -- The object is of the form:
7196 -- Obj : Typ [:= Expr];
7198 -- Do not process the incomplete view of a deferred constant. Do
7199 -- not consider tag-to-class-wide conversions.
7201 elsif not Is_Imported (Obj_Id)
7202 and then Needs_Finalization (Obj_Typ)
7203 and then not (Ekind (Obj_Id) = E_Constant
7204 and then not Has_Completion (Obj_Id))
7205 and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
7209 -- The object is of the form:
7210 -- Obj : Access_Typ := Non_BIP_Function_Call'reference;
7212 -- Obj : Access_Typ :=
7213 -- BIP_Function_Call (BIPalloc => 2, ...)'reference;
7215 elsif Is_Access_Type (Obj_Typ)
7216 and then Needs_Finalization
7217 (Available_View (Designated_Type (Obj_Typ)))
7218 and then Present (Expr)
7220 (Is_Secondary_Stack_BIP_Func_Call (Expr)
7222 (Is_Non_BIP_Func_Call (Expr)
7223 and then not Is_Related_To_Func_Return (Obj_Id)))
7227 -- Processing for "hook" objects generated for controlled
7228 -- transients declared inside an Expression_With_Actions.
7230 elsif Is_Access_Type (Obj_Typ)
7231 and then Present (Status_Flag_Or_Transient_Decl (Obj_Id))
7232 and then Nkind (Status_Flag_Or_Transient_Decl (Obj_Id)) =
7233 N_Object_Declaration
7234 and then Is_Finalizable_Transient
7235 (Status_Flag_Or_Transient_Decl (Obj_Id), Decl)
7239 -- Processing for intermediate results of if expressions where
7240 -- one of the alternatives uses a controlled function call.
7242 elsif Is_Access_Type (Obj_Typ)
7243 and then Present (Status_Flag_Or_Transient_Decl (Obj_Id))
7244 and then Nkind (Status_Flag_Or_Transient_Decl (Obj_Id)) =
7245 N_Defining_Identifier
7246 and then Present (Expr)
7247 and then Nkind (Expr) = N_Null
7251 -- Simple protected objects which use type System.Tasking.
7252 -- Protected_Objects.Protection to manage their locks should be
7253 -- treated as controlled since they require manual cleanup.
7255 elsif Ekind (Obj_Id) = E_Variable
7257 (Is_Simple_Protected_Type (Obj_Typ)
7258 or else Has_Simple_Protected_Object (Obj_Typ))
7263 -- Specific cases of object renamings
7265 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
7266 Obj_Id := Defining_Identifier (Decl);
7267 Obj_Typ := Base_Type (Etype (Obj_Id));
7269 -- Bypass any form of processing for objects which have their
7270 -- finalization disabled. This applies only to objects at the
7273 if Lib_Level and then Finalize_Storage_Only (Obj_Typ) then
7276 -- Return object of a build-in-place function. This case is
7277 -- recognized and marked by the expansion of an extended return
7278 -- statement (see Expand_N_Extended_Return_Statement).
7280 elsif Needs_Finalization (Obj_Typ)
7281 and then Is_Return_Object (Obj_Id)
7282 and then Present (Status_Flag_Or_Transient_Decl (Obj_Id))
7286 -- Detect a case where a source object has been initialized by
7287 -- a controlled function call or another object which was later
7288 -- rewritten as a class-wide conversion of Ada.Tags.Displace.
7290 -- Obj1 : CW_Type := Src_Obj;
7291 -- Obj2 : CW_Type := Function_Call (...);
7293 -- Obj1 : CW_Type renames (... Ada.Tags.Displace (Src_Obj));
7294 -- Tmp : ... := Function_Call (...)'reference;
7295 -- Obj2 : CW_Type renames (... Ada.Tags.Displace (Tmp));
7297 elsif Is_Displacement_Of_Object_Or_Function_Result (Obj_Id) then
7301 -- Inspect the freeze node of an access-to-controlled type and look
7302 -- for a delayed finalization master. This case arises when the
7303 -- freeze actions are inserted at a later time than the expansion of
7304 -- the context. Since Build_Finalizer is never called on a single
7305 -- construct twice, the master will be ultimately left out and never
7306 -- finalized. This is also needed for freeze actions of designated
7307 -- types themselves, since in some cases the finalization master is
7308 -- associated with a designated type's freeze node rather than that
7309 -- of the access type (see handling for freeze actions in
7310 -- Build_Finalization_Master).
7312 elsif Nkind (Decl) = N_Freeze_Entity
7313 and then Present (Actions (Decl))
7315 Typ := Entity (Decl);
7317 if ((Is_Access_Type (Typ)
7318 and then not Is_Access_Subprogram_Type (Typ)
7319 and then Needs_Finalization
7320 (Available_View (Designated_Type (Typ))))
7323 and then Needs_Finalization (Typ)))
7324 and then Requires_Cleanup_Actions
7325 (Actions (Decl), Lib_Level, Nested_Constructs)
7330 -- Nested package declarations
7332 elsif Nested_Constructs
7333 and then Nkind (Decl) = N_Package_Declaration
7335 Pack_Id := Defining_Unit_Name (Specification (Decl));
7337 if Nkind (Pack_Id) = N_Defining_Program_Unit_Name then
7338 Pack_Id := Defining_Identifier (Pack_Id);
7341 if Ekind (Pack_Id) /= E_Generic_Package
7343 Requires_Cleanup_Actions (Specification (Decl), Lib_Level)
7348 -- Nested package bodies
7350 elsif Nested_Constructs and then Nkind (Decl) = N_Package_Body then
7351 Pack_Id := Corresponding_Spec (Decl);
7353 if Ekind (Pack_Id) /= E_Generic_Package
7354 and then Requires_Cleanup_Actions (Decl, Lib_Level)
7364 end Requires_Cleanup_Actions;
7366 ------------------------------------
7367 -- Safe_Unchecked_Type_Conversion --
7368 ------------------------------------
7370 -- Note: this function knows quite a bit about the exact requirements of
7371 -- Gigi with respect to unchecked type conversions, and its code must be
7372 -- coordinated with any changes in Gigi in this area.
7374 -- The above requirements should be documented in Sinfo ???
7376 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
7381 Pexp : constant Node_Id := Parent (Exp);
7384 -- If the expression is the RHS of an assignment or object declaration
7385 -- we are always OK because there will always be a target.
7387 -- Object renaming declarations, (generated for view conversions of
7388 -- actuals in inlined calls), like object declarations, provide an
7389 -- explicit type, and are safe as well.
7391 if (Nkind (Pexp) = N_Assignment_Statement
7392 and then Expression (Pexp) = Exp)
7393 or else Nkind_In (Pexp, N_Object_Declaration,
7394 N_Object_Renaming_Declaration)
7398 -- If the expression is the prefix of an N_Selected_Component we should
7399 -- also be OK because GCC knows to look inside the conversion except if
7400 -- the type is discriminated. We assume that we are OK anyway if the
7401 -- type is not set yet or if it is controlled since we can't afford to
7402 -- introduce a temporary in this case.
7404 elsif Nkind (Pexp) = N_Selected_Component
7405 and then Prefix (Pexp) = Exp
7407 if No (Etype (Pexp)) then
7411 not Has_Discriminants (Etype (Pexp))
7412 or else Is_Constrained (Etype (Pexp));
7416 -- Set the output type, this comes from Etype if it is set, otherwise we
7417 -- take it from the subtype mark, which we assume was already fully
7420 if Present (Etype (Exp)) then
7421 Otyp := Etype (Exp);
7423 Otyp := Entity (Subtype_Mark (Exp));
7426 -- The input type always comes from the expression, and we assume
7427 -- this is indeed always analyzed, so we can simply get the Etype.
7429 Ityp := Etype (Expression (Exp));
7431 -- Initialize alignments to unknown so far
7436 -- Replace a concurrent type by its corresponding record type and each
7437 -- type by its underlying type and do the tests on those. The original
7438 -- type may be a private type whose completion is a concurrent type, so
7439 -- find the underlying type first.
7441 if Present (Underlying_Type (Otyp)) then
7442 Otyp := Underlying_Type (Otyp);
7445 if Present (Underlying_Type (Ityp)) then
7446 Ityp := Underlying_Type (Ityp);
7449 if Is_Concurrent_Type (Otyp) then
7450 Otyp := Corresponding_Record_Type (Otyp);
7453 if Is_Concurrent_Type (Ityp) then
7454 Ityp := Corresponding_Record_Type (Ityp);
7457 -- If the base types are the same, we know there is no problem since
7458 -- this conversion will be a noop.
7460 if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
7463 -- Same if this is an upwards conversion of an untagged type, and there
7464 -- are no constraints involved (could be more general???)
7466 elsif Etype (Ityp) = Otyp
7467 and then not Is_Tagged_Type (Ityp)
7468 and then not Has_Discriminants (Ityp)
7469 and then No (First_Rep_Item (Base_Type (Ityp)))
7473 -- If the expression has an access type (object or subprogram) we assume
7474 -- that the conversion is safe, because the size of the target is safe,
7475 -- even if it is a record (which might be treated as having unknown size
7478 elsif Is_Access_Type (Ityp) then
7481 -- If the size of output type is known at compile time, there is never
7482 -- a problem. Note that unconstrained records are considered to be of
7483 -- known size, but we can't consider them that way here, because we are
7484 -- talking about the actual size of the object.
7486 -- We also make sure that in addition to the size being known, we do not
7487 -- have a case which might generate an embarrassingly large temp in
7488 -- stack checking mode.
7490 elsif Size_Known_At_Compile_Time (Otyp)
7492 (not Stack_Checking_Enabled
7493 or else not May_Generate_Large_Temp (Otyp))
7494 and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
7498 -- If either type is tagged, then we know the alignment is OK so
7499 -- Gigi will be able to use pointer punning.
7501 elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
7504 -- If either type is a limited record type, we cannot do a copy, so say
7505 -- safe since there's nothing else we can do.
7507 elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
7510 -- Conversions to and from packed array types are always ignored and
7513 elsif Is_Packed_Array_Type (Otyp)
7514 or else Is_Packed_Array_Type (Ityp)
7519 -- The only other cases known to be safe is if the input type's
7520 -- alignment is known to be at least the maximum alignment for the
7521 -- target or if both alignments are known and the output type's
7522 -- alignment is no stricter than the input's. We can use the component
7523 -- type alignement for an array if a type is an unpacked array type.
7525 if Present (Alignment_Clause (Otyp)) then
7526 Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
7528 elsif Is_Array_Type (Otyp)
7529 and then Present (Alignment_Clause (Component_Type (Otyp)))
7531 Oalign := Expr_Value (Expression (Alignment_Clause
7532 (Component_Type (Otyp))));
7535 if Present (Alignment_Clause (Ityp)) then
7536 Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
7538 elsif Is_Array_Type (Ityp)
7539 and then Present (Alignment_Clause (Component_Type (Ityp)))
7541 Ialign := Expr_Value (Expression (Alignment_Clause
7542 (Component_Type (Ityp))));
7545 if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
7548 elsif Ialign /= No_Uint and then Oalign /= No_Uint
7549 and then Ialign <= Oalign
7553 -- Otherwise, Gigi cannot handle this and we must make a temporary
7558 end Safe_Unchecked_Type_Conversion;
7560 ---------------------------------
7561 -- Set_Current_Value_Condition --
7562 ---------------------------------
7564 -- Note: the implementation of this procedure is very closely tied to the
7565 -- implementation of Get_Current_Value_Condition. Here we set required
7566 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
7567 -- them, so they must have a consistent view.
7569 procedure Set_Current_Value_Condition (Cnode : Node_Id) is
7571 procedure Set_Entity_Current_Value (N : Node_Id);
7572 -- If N is an entity reference, where the entity is of an appropriate
7573 -- kind, then set the current value of this entity to Cnode, unless
7574 -- there is already a definite value set there.
7576 procedure Set_Expression_Current_Value (N : Node_Id);
7577 -- If N is of an appropriate form, sets an appropriate entry in current
7578 -- value fields of relevant entities. Multiple entities can be affected
7579 -- in the case of an AND or AND THEN.
7581 ------------------------------
7582 -- Set_Entity_Current_Value --
7583 ------------------------------
7585 procedure Set_Entity_Current_Value (N : Node_Id) is
7587 if Is_Entity_Name (N) then
7589 Ent : constant Entity_Id := Entity (N);
7592 -- Don't capture if not safe to do so
7594 if not Safe_To_Capture_Value (N, Ent, Cond => True) then
7598 -- Here we have a case where the Current_Value field may need
7599 -- to be set. We set it if it is not already set to a compile
7600 -- time expression value.
7602 -- Note that this represents a decision that one condition
7603 -- blots out another previous one. That's certainly right if
7604 -- they occur at the same level. If the second one is nested,
7605 -- then the decision is neither right nor wrong (it would be
7606 -- equally OK to leave the outer one in place, or take the new
7607 -- inner one. Really we should record both, but our data
7608 -- structures are not that elaborate.
7610 if Nkind (Current_Value (Ent)) not in N_Subexpr then
7611 Set_Current_Value (Ent, Cnode);
7615 end Set_Entity_Current_Value;
7617 ----------------------------------
7618 -- Set_Expression_Current_Value --
7619 ----------------------------------
7621 procedure Set_Expression_Current_Value (N : Node_Id) is
7627 -- Loop to deal with (ignore for now) any NOT operators present. The
7628 -- presence of NOT operators will be handled properly when we call
7629 -- Get_Current_Value_Condition.
7631 while Nkind (Cond) = N_Op_Not loop
7632 Cond := Right_Opnd (Cond);
7635 -- For an AND or AND THEN, recursively process operands
7637 if Nkind (Cond) = N_Op_And or else Nkind (Cond) = N_And_Then then
7638 Set_Expression_Current_Value (Left_Opnd (Cond));
7639 Set_Expression_Current_Value (Right_Opnd (Cond));
7643 -- Check possible relational operator
7645 if Nkind (Cond) in N_Op_Compare then
7646 if Compile_Time_Known_Value (Right_Opnd (Cond)) then
7647 Set_Entity_Current_Value (Left_Opnd (Cond));
7648 elsif Compile_Time_Known_Value (Left_Opnd (Cond)) then
7649 Set_Entity_Current_Value (Right_Opnd (Cond));
7652 -- Check possible boolean variable reference
7655 Set_Entity_Current_Value (Cond);
7657 end Set_Expression_Current_Value;
7659 -- Start of processing for Set_Current_Value_Condition
7662 Set_Expression_Current_Value (Condition (Cnode));
7663 end Set_Current_Value_Condition;
7665 --------------------------
7666 -- Set_Elaboration_Flag --
7667 --------------------------
7669 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
7670 Loc : constant Source_Ptr := Sloc (N);
7671 Ent : constant Entity_Id := Elaboration_Entity (Spec_Id);
7675 if Present (Ent) then
7677 -- Nothing to do if at the compilation unit level, because in this
7678 -- case the flag is set by the binder generated elaboration routine.
7680 if Nkind (Parent (N)) = N_Compilation_Unit then
7683 -- Here we do need to generate an assignment statement
7686 Check_Restriction (No_Elaboration_Code, N);
7688 Make_Assignment_Statement (Loc,
7689 Name => New_Occurrence_Of (Ent, Loc),
7690 Expression => Make_Integer_Literal (Loc, Uint_1));
7692 if Nkind (Parent (N)) = N_Subunit then
7693 Insert_After (Corresponding_Stub (Parent (N)), Asn);
7695 Insert_After (N, Asn);
7700 -- Kill current value indication. This is necessary because the
7701 -- tests of this flag are inserted out of sequence and must not
7702 -- pick up bogus indications of the wrong constant value.
7704 Set_Current_Value (Ent, Empty);
7707 end Set_Elaboration_Flag;
7709 ----------------------------
7710 -- Set_Renamed_Subprogram --
7711 ----------------------------
7713 procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id) is
7715 -- If input node is an identifier, we can just reset it
7717 if Nkind (N) = N_Identifier then
7718 Set_Chars (N, Chars (E));
7721 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
7725 CS : constant Boolean := Comes_From_Source (N);
7727 Rewrite (N, Make_Identifier (Sloc (N), Chars (E)));
7729 Set_Comes_From_Source (N, CS);
7730 Set_Analyzed (N, True);
7733 end Set_Renamed_Subprogram;
7735 ----------------------------------
7736 -- Silly_Boolean_Array_Not_Test --
7737 ----------------------------------
7739 -- This procedure implements an odd and silly test. We explicitly check
7740 -- for the case where the 'First of the component type is equal to the
7741 -- 'Last of this component type, and if this is the case, we make sure
7742 -- that constraint error is raised. The reason is that the NOT is bound
7743 -- to cause CE in this case, and we will not otherwise catch it.
7745 -- No such check is required for AND and OR, since for both these cases
7746 -- False op False = False, and True op True = True. For the XOR case,
7747 -- see Silly_Boolean_Array_Xor_Test.
7749 -- Believe it or not, this was reported as a bug. Note that nearly always,
7750 -- the test will evaluate statically to False, so the code will be
7751 -- statically removed, and no extra overhead caused.
7753 procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id) is
7754 Loc : constant Source_Ptr := Sloc (N);
7755 CT : constant Entity_Id := Component_Type (T);
7758 -- The check we install is
7760 -- constraint_error when
7761 -- component_type'first = component_type'last
7762 -- and then array_type'Length /= 0)
7764 -- We need the last guard because we don't want to raise CE for empty
7765 -- arrays since no out of range values result. (Empty arrays with a
7766 -- component type of True .. True -- very useful -- even the ACATS
7767 -- does not test that marginal case!)
7770 Make_Raise_Constraint_Error (Loc,
7776 Make_Attribute_Reference (Loc,
7777 Prefix => New_Occurrence_Of (CT, Loc),
7778 Attribute_Name => Name_First),
7781 Make_Attribute_Reference (Loc,
7782 Prefix => New_Occurrence_Of (CT, Loc),
7783 Attribute_Name => Name_Last)),
7785 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
7786 Reason => CE_Range_Check_Failed));
7787 end Silly_Boolean_Array_Not_Test;
7789 ----------------------------------
7790 -- Silly_Boolean_Array_Xor_Test --
7791 ----------------------------------
7793 -- This procedure implements an odd and silly test. We explicitly check
7794 -- for the XOR case where the component type is True .. True, since this
7795 -- will raise constraint error. A special check is required since CE
7796 -- will not be generated otherwise (cf Expand_Packed_Not).
7798 -- No such check is required for AND and OR, since for both these cases
7799 -- False op False = False, and True op True = True, and no check is
7800 -- required for the case of False .. False, since False xor False = False.
7801 -- See also Silly_Boolean_Array_Not_Test
7803 procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is
7804 Loc : constant Source_Ptr := Sloc (N);
7805 CT : constant Entity_Id := Component_Type (T);
7808 -- The check we install is
7810 -- constraint_error when
7811 -- Boolean (component_type'First)
7812 -- and then Boolean (component_type'Last)
7813 -- and then array_type'Length /= 0)
7815 -- We need the last guard because we don't want to raise CE for empty
7816 -- arrays since no out of range values result (Empty arrays with a
7817 -- component type of True .. True -- very useful -- even the ACATS
7818 -- does not test that marginal case!).
7821 Make_Raise_Constraint_Error (Loc,
7827 Convert_To (Standard_Boolean,
7828 Make_Attribute_Reference (Loc,
7829 Prefix => New_Occurrence_Of (CT, Loc),
7830 Attribute_Name => Name_First)),
7833 Convert_To (Standard_Boolean,
7834 Make_Attribute_Reference (Loc,
7835 Prefix => New_Occurrence_Of (CT, Loc),
7836 Attribute_Name => Name_Last))),
7838 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
7839 Reason => CE_Range_Check_Failed));
7840 end Silly_Boolean_Array_Xor_Test;
7842 --------------------------
7843 -- Target_Has_Fixed_Ops --
7844 --------------------------
7846 Integer_Sized_Small : Ureal;
7847 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
7848 -- called (we don't want to compute it more than once!)
7850 Long_Integer_Sized_Small : Ureal;
7851 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
7852 -- is called (we don't want to compute it more than once)
7854 First_Time_For_THFO : Boolean := True;
7855 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
7857 function Target_Has_Fixed_Ops
7858 (Left_Typ : Entity_Id;
7859 Right_Typ : Entity_Id;
7860 Result_Typ : Entity_Id) return Boolean
7862 function Is_Fractional_Type (Typ : Entity_Id) return Boolean;
7863 -- Return True if the given type is a fixed-point type with a small
7864 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
7865 -- an absolute value less than 1.0. This is currently limited to
7866 -- fixed-point types that map to Integer or Long_Integer.
7868 ------------------------
7869 -- Is_Fractional_Type --
7870 ------------------------
7872 function Is_Fractional_Type (Typ : Entity_Id) return Boolean is
7874 if Esize (Typ) = Standard_Integer_Size then
7875 return Small_Value (Typ) = Integer_Sized_Small;
7877 elsif Esize (Typ) = Standard_Long_Integer_Size then
7878 return Small_Value (Typ) = Long_Integer_Sized_Small;
7883 end Is_Fractional_Type;
7885 -- Start of processing for Target_Has_Fixed_Ops
7888 -- Return False if Fractional_Fixed_Ops_On_Target is false
7890 if not Fractional_Fixed_Ops_On_Target then
7894 -- Here the target has Fractional_Fixed_Ops, if first time, compute
7895 -- standard constants used by Is_Fractional_Type.
7897 if First_Time_For_THFO then
7898 First_Time_For_THFO := False;
7900 Integer_Sized_Small :=
7903 Den => UI_From_Int (Standard_Integer_Size - 1),
7906 Long_Integer_Sized_Small :=
7909 Den => UI_From_Int (Standard_Long_Integer_Size - 1),
7913 -- Return True if target supports fixed-by-fixed multiply/divide for
7914 -- fractional fixed-point types (see Is_Fractional_Type) and the operand
7915 -- and result types are equivalent fractional types.
7917 return Is_Fractional_Type (Base_Type (Left_Typ))
7918 and then Is_Fractional_Type (Base_Type (Right_Typ))
7919 and then Is_Fractional_Type (Base_Type (Result_Typ))
7920 and then Esize (Left_Typ) = Esize (Right_Typ)
7921 and then Esize (Left_Typ) = Esize (Result_Typ);
7922 end Target_Has_Fixed_Ops;
7924 ------------------------------------------
7925 -- Type_May_Have_Bit_Aligned_Components --
7926 ------------------------------------------
7928 function Type_May_Have_Bit_Aligned_Components
7929 (Typ : Entity_Id) return Boolean
7932 -- Array type, check component type
7934 if Is_Array_Type (Typ) then
7936 Type_May_Have_Bit_Aligned_Components (Component_Type (Typ));
7938 -- Record type, check components
7940 elsif Is_Record_Type (Typ) then
7945 E := First_Component_Or_Discriminant (Typ);
7946 while Present (E) loop
7947 if Component_May_Be_Bit_Aligned (E)
7948 or else Type_May_Have_Bit_Aligned_Components (Etype (E))
7953 Next_Component_Or_Discriminant (E);
7959 -- Type other than array or record is always OK
7964 end Type_May_Have_Bit_Aligned_Components;
7966 ----------------------------------
7967 -- Within_Case_Or_If_Expression --
7968 ----------------------------------
7970 function Within_Case_Or_If_Expression (N : Node_Id) return Boolean is
7974 -- Locate an enclosing case or if expression. Note: these constructs can
7975 -- get expanded into Expression_With_Actions, hence the need to test
7976 -- using the original node.
7979 while Present (Par) loop
7980 if Nkind_In (Original_Node (Par), N_Case_Expression,
7985 -- Prevent the search from going too far
7987 elsif Nkind_In (Par, N_Entry_Body,
7989 N_Package_Declaration,
7997 Par := Parent (Par);
8001 end Within_Case_Or_If_Expression;
8003 ----------------------------
8004 -- Wrap_Cleanup_Procedure --
8005 ----------------------------
8007 procedure Wrap_Cleanup_Procedure (N : Node_Id) is
8008 Loc : constant Source_Ptr := Sloc (N);
8009 Stseq : constant Node_Id := Handled_Statement_Sequence (N);
8010 Stmts : constant List_Id := Statements (Stseq);
8013 if Abort_Allowed then
8014 Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
8015 Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
8017 end Wrap_Cleanup_Procedure;