1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Aggr; use Exp_Aggr;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_Ch7; use Exp_Ch7;
35 with Inline; use Inline;
36 with Itypes; use Itypes;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Restrict; use Restrict;
42 with Rident; use Rident;
44 with Sem_Aux; use Sem_Aux;
45 with Sem_Ch8; use Sem_Ch8;
46 with Sem_SCIL; use Sem_SCIL;
47 with Sem_Eval; use Sem_Eval;
48 with Sem_Res; use Sem_Res;
49 with Sem_Type; use Sem_Type;
50 with Sem_Util; use Sem_Util;
51 with Snames; use Snames;
52 with Stand; use Stand;
53 with Stringt; use Stringt;
54 with Targparm; use Targparm;
55 with Tbuild; use Tbuild;
56 with Ttypes; use Ttypes;
57 with Uintp; use Uintp;
58 with Urealp; use Urealp;
59 with Validsw; use Validsw;
61 package body Exp_Util is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Task_Array_Image
71 Dyn : Boolean := False) return Node_Id;
72 -- Build function to generate the image string for a task that is an
73 -- array component, concatenating the images of each index. To avoid
74 -- storage leaks, the string is built with successive slice assignments.
75 -- The flag Dyn indicates whether this is called for the initialization
76 -- procedure of an array of tasks, or for the name of a dynamically
77 -- created task that is assigned to an indexed component.
79 function Build_Task_Image_Function
83 Res : Entity_Id) return Node_Id;
84 -- Common processing for Task_Array_Image and Task_Record_Image.
85 -- Build function body that computes image.
87 procedure Build_Task_Image_Prefix
96 -- Common processing for Task_Array_Image and Task_Record_Image.
97 -- Create local variables and assign prefix of name to result string.
99 function Build_Task_Record_Image
102 Dyn : Boolean := False) return Node_Id;
103 -- Build function to generate the image string for a task that is a
104 -- record component. Concatenate name of variable with that of selector.
105 -- The flag Dyn indicates whether this is called for the initialization
106 -- procedure of record with task components, or for a dynamically
107 -- created task that is assigned to a selected component.
109 function Make_CW_Equivalent_Type
111 E : Node_Id) return Entity_Id;
112 -- T is a class-wide type entity, E is the initial expression node that
113 -- constrains T in case such as: " X: T := E" or "new T'(E)"
114 -- This function returns the entity of the Equivalent type and inserts
115 -- on the fly the necessary declaration such as:
117 -- type anon is record
118 -- _parent : Root_Type (T); constrained with E discriminants (if any)
119 -- Extension : String (1 .. expr to match size of E);
122 -- This record is compatible with any object of the class of T thanks
123 -- to the first field and has the same size as E thanks to the second.
125 function Make_Literal_Range
127 Literal_Typ : Entity_Id) return Node_Id;
128 -- Produce a Range node whose bounds are:
129 -- Low_Bound (Literal_Type) ..
130 -- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
131 -- this is used for expanding declarations like X : String := "sdfgdfg";
133 -- If the index type of the target array is not integer, we generate:
134 -- Low_Bound (Literal_Type) ..
136 -- (Literal_Type'Pos (Low_Bound (Literal_Type))
137 -- + (Length (Literal_Typ) -1))
139 function Make_Non_Empty_Check
141 N : Node_Id) return Node_Id;
142 -- Produce a boolean expression checking that the unidimensional array
143 -- node N is not empty.
145 function New_Class_Wide_Subtype
147 N : Node_Id) return Entity_Id;
148 -- Create an implicit subtype of CW_Typ attached to node N
150 ----------------------
151 -- Adjust_Condition --
152 ----------------------
154 procedure Adjust_Condition (N : Node_Id) is
161 Loc : constant Source_Ptr := Sloc (N);
162 T : constant Entity_Id := Etype (N);
166 -- For now, we simply ignore a call where the argument has no
167 -- type (probably case of unanalyzed condition), or has a type
168 -- that is not Boolean. This is because this is a pretty marginal
169 -- piece of functionality, and violations of these rules are
170 -- likely to be truly marginal (how much code uses Fortran Logical
171 -- as the barrier to a protected entry?) and we do not want to
172 -- blow up existing programs. We can change this to an assertion
173 -- after 3.12a is released ???
175 if No (T) or else not Is_Boolean_Type (T) then
179 -- Apply validity checking if needed
181 if Validity_Checks_On and Validity_Check_Tests then
185 -- Immediate return if standard boolean, the most common case,
186 -- where nothing needs to be done.
188 if Base_Type (T) = Standard_Boolean then
192 -- Case of zero/non-zero semantics or non-standard enumeration
193 -- representation. In each case, we rewrite the node as:
195 -- ityp!(N) /= False'Enum_Rep
197 -- where ityp is an integer type with large enough size to hold
198 -- any value of type T.
200 if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
201 if Esize (T) <= Esize (Standard_Integer) then
202 Ti := Standard_Integer;
204 Ti := Standard_Long_Long_Integer;
209 Left_Opnd => Unchecked_Convert_To (Ti, N),
211 Make_Attribute_Reference (Loc,
212 Attribute_Name => Name_Enum_Rep,
214 New_Occurrence_Of (First_Literal (T), Loc))));
215 Analyze_And_Resolve (N, Standard_Boolean);
218 Rewrite (N, Convert_To (Standard_Boolean, N));
219 Analyze_And_Resolve (N, Standard_Boolean);
222 end Adjust_Condition;
224 ------------------------
225 -- Adjust_Result_Type --
226 ------------------------
228 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
230 -- Ignore call if current type is not Standard.Boolean
232 if Etype (N) /= Standard_Boolean then
236 -- If result is already of correct type, nothing to do. Note that
237 -- this will get the most common case where everything has a type
238 -- of Standard.Boolean.
240 if Base_Type (T) = Standard_Boolean then
245 KP : constant Node_Kind := Nkind (Parent (N));
248 -- If result is to be used as a Condition in the syntax, no need
249 -- to convert it back, since if it was changed to Standard.Boolean
250 -- using Adjust_Condition, that is just fine for this usage.
252 if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
255 -- If result is an operand of another logical operation, no need
256 -- to reset its type, since Standard.Boolean is just fine, and
257 -- such operations always do Adjust_Condition on their operands.
259 elsif KP in N_Op_Boolean
260 or else KP in N_Short_Circuit
261 or else KP = N_Op_Not
265 -- Otherwise we perform a conversion from the current type,
266 -- which must be Standard.Boolean, to the desired type.
270 Rewrite (N, Convert_To (T, N));
271 Analyze_And_Resolve (N, T);
275 end Adjust_Result_Type;
277 --------------------------
278 -- Append_Freeze_Action --
279 --------------------------
281 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
285 Ensure_Freeze_Node (T);
286 Fnode := Freeze_Node (T);
288 if No (Actions (Fnode)) then
289 Set_Actions (Fnode, New_List);
292 Append (N, Actions (Fnode));
293 end Append_Freeze_Action;
295 ---------------------------
296 -- Append_Freeze_Actions --
297 ---------------------------
299 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
300 Fnode : constant Node_Id := Freeze_Node (T);
307 if No (Actions (Fnode)) then
308 Set_Actions (Fnode, L);
311 Append_List (L, Actions (Fnode));
315 end Append_Freeze_Actions;
317 ------------------------
318 -- Build_Runtime_Call --
319 ------------------------
321 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
323 -- If entity is not available, we can skip making the call (this avoids
324 -- junk duplicated error messages in a number of cases).
326 if not RTE_Available (RE) then
327 return Make_Null_Statement (Loc);
330 Make_Procedure_Call_Statement (Loc,
331 Name => New_Reference_To (RTE (RE), Loc));
333 end Build_Runtime_Call;
335 ----------------------------
336 -- Build_Task_Array_Image --
337 ----------------------------
339 -- This function generates the body for a function that constructs the
340 -- image string for a task that is an array component. The function is
341 -- local to the init proc for the array type, and is called for each one
342 -- of the components. The constructed image has the form of an indexed
343 -- component, whose prefix is the outer variable of the array type.
344 -- The n-dimensional array type has known indices Index, Index2...
345 -- Id_Ref is an indexed component form created by the enclosing init proc.
346 -- Its successive indices are Val1, Val2, ... which are the loop variables
347 -- in the loops that call the individual task init proc on each component.
349 -- The generated function has the following structure:
351 -- function F return String is
352 -- Pref : string renames Task_Name;
353 -- T1 : String := Index1'Image (Val1);
355 -- Tn : String := indexn'image (Valn);
356 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
357 -- -- Len includes commas and the end parentheses.
358 -- Res : String (1..Len);
359 -- Pos : Integer := Pref'Length;
362 -- Res (1 .. Pos) := Pref;
366 -- Res (Pos .. Pos + T1'Length - 1) := T1;
367 -- Pos := Pos + T1'Length;
371 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
377 -- Needless to say, multidimensional arrays of tasks are rare enough
378 -- that the bulkiness of this code is not really a concern.
380 function Build_Task_Array_Image
384 Dyn : Boolean := False) return Node_Id
386 Dims : constant Nat := Number_Dimensions (A_Type);
387 -- Number of dimensions for array of tasks
389 Temps : array (1 .. Dims) of Entity_Id;
390 -- Array of temporaries to hold string for each index
396 -- Total length of generated name
399 -- Running index for substring assignments
401 Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
402 -- Name of enclosing variable, prefix of resulting name
405 -- String to hold result
408 -- Value of successive indices
411 -- Expression to compute total size of string
414 -- Entity for name at one index position
416 Decls : constant List_Id := New_List;
417 Stats : constant List_Id := New_List;
420 -- For a dynamic task, the name comes from the target variable.
421 -- For a static one it is a formal of the enclosing init proc.
424 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
426 Make_Object_Declaration (Loc,
427 Defining_Identifier => Pref,
428 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
430 Make_String_Literal (Loc,
431 Strval => String_From_Name_Buffer)));
435 Make_Object_Renaming_Declaration (Loc,
436 Defining_Identifier => Pref,
437 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
438 Name => Make_Identifier (Loc, Name_uTask_Name)));
441 Indx := First_Index (A_Type);
442 Val := First (Expressions (Id_Ref));
444 for J in 1 .. Dims loop
445 T := Make_Temporary (Loc, 'T');
449 Make_Object_Declaration (Loc,
450 Defining_Identifier => T,
451 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
453 Make_Attribute_Reference (Loc,
454 Attribute_Name => Name_Image,
455 Prefix => New_Occurrence_Of (Etype (Indx), Loc),
456 Expressions => New_List (New_Copy_Tree (Val)))));
462 Sum := Make_Integer_Literal (Loc, Dims + 1);
468 Make_Attribute_Reference (Loc,
469 Attribute_Name => Name_Length,
471 New_Occurrence_Of (Pref, Loc),
472 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
474 for J in 1 .. Dims loop
479 Make_Attribute_Reference (Loc,
480 Attribute_Name => Name_Length,
482 New_Occurrence_Of (Temps (J), Loc),
483 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
486 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
488 Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
491 Make_Assignment_Statement (Loc,
492 Name => Make_Indexed_Component (Loc,
493 Prefix => New_Occurrence_Of (Res, Loc),
494 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
496 Make_Character_Literal (Loc,
498 Char_Literal_Value =>
499 UI_From_Int (Character'Pos ('(')))));
502 Make_Assignment_Statement (Loc,
503 Name => New_Occurrence_Of (Pos, Loc),
506 Left_Opnd => New_Occurrence_Of (Pos, Loc),
507 Right_Opnd => Make_Integer_Literal (Loc, 1))));
509 for J in 1 .. Dims loop
512 Make_Assignment_Statement (Loc,
513 Name => Make_Slice (Loc,
514 Prefix => New_Occurrence_Of (Res, Loc),
517 Low_Bound => New_Occurrence_Of (Pos, Loc),
518 High_Bound => Make_Op_Subtract (Loc,
521 Left_Opnd => New_Occurrence_Of (Pos, Loc),
523 Make_Attribute_Reference (Loc,
524 Attribute_Name => Name_Length,
526 New_Occurrence_Of (Temps (J), Loc),
528 New_List (Make_Integer_Literal (Loc, 1)))),
529 Right_Opnd => Make_Integer_Literal (Loc, 1)))),
531 Expression => New_Occurrence_Of (Temps (J), Loc)));
535 Make_Assignment_Statement (Loc,
536 Name => New_Occurrence_Of (Pos, Loc),
539 Left_Opnd => New_Occurrence_Of (Pos, Loc),
541 Make_Attribute_Reference (Loc,
542 Attribute_Name => Name_Length,
543 Prefix => New_Occurrence_Of (Temps (J), Loc),
545 New_List (Make_Integer_Literal (Loc, 1))))));
547 Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
550 Make_Assignment_Statement (Loc,
551 Name => Make_Indexed_Component (Loc,
552 Prefix => New_Occurrence_Of (Res, Loc),
553 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
555 Make_Character_Literal (Loc,
557 Char_Literal_Value =>
558 UI_From_Int (Character'Pos (',')))));
561 Make_Assignment_Statement (Loc,
562 Name => New_Occurrence_Of (Pos, Loc),
565 Left_Opnd => New_Occurrence_Of (Pos, Loc),
566 Right_Opnd => Make_Integer_Literal (Loc, 1))));
570 Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
573 Make_Assignment_Statement (Loc,
574 Name => Make_Indexed_Component (Loc,
575 Prefix => New_Occurrence_Of (Res, Loc),
576 Expressions => New_List (New_Occurrence_Of (Len, Loc))),
578 Make_Character_Literal (Loc,
580 Char_Literal_Value =>
581 UI_From_Int (Character'Pos (')')))));
582 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
583 end Build_Task_Array_Image;
585 ----------------------------
586 -- Build_Task_Image_Decls --
587 ----------------------------
589 function Build_Task_Image_Decls
593 In_Init_Proc : Boolean := False) return List_Id
595 Decls : constant List_Id := New_List;
596 T_Id : Entity_Id := Empty;
598 Expr : Node_Id := Empty;
599 Fun : Node_Id := Empty;
600 Is_Dyn : constant Boolean :=
601 Nkind (Parent (Id_Ref)) = N_Assignment_Statement
603 Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
606 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
607 -- generate a dummy declaration only.
609 if Restriction_Active (No_Implicit_Heap_Allocations)
610 or else Global_Discard_Names
612 T_Id := Make_Temporary (Loc, 'J');
617 Make_Object_Declaration (Loc,
618 Defining_Identifier => T_Id,
619 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
621 Make_String_Literal (Loc,
622 Strval => String_From_Name_Buffer)));
625 if Nkind (Id_Ref) = N_Identifier
626 or else Nkind (Id_Ref) = N_Defining_Identifier
628 -- For a simple variable, the image of the task is built from
629 -- the name of the variable. To avoid possible conflict with
630 -- the anonymous type created for a single protected object,
631 -- add a numeric suffix.
634 Make_Defining_Identifier (Loc,
635 New_External_Name (Chars (Id_Ref), 'T', 1));
637 Get_Name_String (Chars (Id_Ref));
640 Make_String_Literal (Loc,
641 Strval => String_From_Name_Buffer);
643 elsif Nkind (Id_Ref) = N_Selected_Component then
645 Make_Defining_Identifier (Loc,
646 New_External_Name (Chars (Selector_Name (Id_Ref)), 'T'));
647 Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn);
649 elsif Nkind (Id_Ref) = N_Indexed_Component then
651 Make_Defining_Identifier (Loc,
652 New_External_Name (Chars (A_Type), 'N'));
654 Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
658 if Present (Fun) then
660 Expr := Make_Function_Call (Loc,
661 Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
663 if not In_Init_Proc and then VM_Target = No_VM then
664 Set_Uses_Sec_Stack (Defining_Entity (Fun));
668 Decl := Make_Object_Declaration (Loc,
669 Defining_Identifier => T_Id,
670 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
671 Constant_Present => True,
674 Append (Decl, Decls);
676 end Build_Task_Image_Decls;
678 -------------------------------
679 -- Build_Task_Image_Function --
680 -------------------------------
682 function Build_Task_Image_Function
686 Res : Entity_Id) return Node_Id
692 Make_Simple_Return_Statement (Loc,
693 Expression => New_Occurrence_Of (Res, Loc)));
695 Spec := Make_Function_Specification (Loc,
696 Defining_Unit_Name => Make_Temporary (Loc, 'F'),
697 Result_Definition => New_Occurrence_Of (Standard_String, Loc));
699 -- Calls to 'Image use the secondary stack, which must be cleaned
700 -- up after the task name is built.
702 return Make_Subprogram_Body (Loc,
703 Specification => Spec,
704 Declarations => Decls,
705 Handled_Statement_Sequence =>
706 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats));
707 end Build_Task_Image_Function;
709 -----------------------------
710 -- Build_Task_Image_Prefix --
711 -----------------------------
713 procedure Build_Task_Image_Prefix
724 Len := Make_Temporary (Loc, 'L', Sum);
727 Make_Object_Declaration (Loc,
728 Defining_Identifier => Len,
729 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
732 Res := Make_Temporary (Loc, 'R');
735 Make_Object_Declaration (Loc,
736 Defining_Identifier => Res,
738 Make_Subtype_Indication (Loc,
739 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
741 Make_Index_Or_Discriminant_Constraint (Loc,
745 Low_Bound => Make_Integer_Literal (Loc, 1),
746 High_Bound => New_Occurrence_Of (Len, Loc)))))));
748 Pos := Make_Temporary (Loc, 'P');
751 Make_Object_Declaration (Loc,
752 Defining_Identifier => Pos,
753 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
755 -- Pos := Prefix'Length;
758 Make_Assignment_Statement (Loc,
759 Name => New_Occurrence_Of (Pos, Loc),
761 Make_Attribute_Reference (Loc,
762 Attribute_Name => Name_Length,
763 Prefix => New_Occurrence_Of (Prefix, Loc),
764 Expressions => New_List (Make_Integer_Literal (Loc, 1)))));
766 -- Res (1 .. Pos) := Prefix;
769 Make_Assignment_Statement (Loc,
772 Prefix => New_Occurrence_Of (Res, Loc),
775 Low_Bound => Make_Integer_Literal (Loc, 1),
776 High_Bound => New_Occurrence_Of (Pos, Loc))),
778 Expression => New_Occurrence_Of (Prefix, Loc)));
781 Make_Assignment_Statement (Loc,
782 Name => New_Occurrence_Of (Pos, Loc),
785 Left_Opnd => New_Occurrence_Of (Pos, Loc),
786 Right_Opnd => Make_Integer_Literal (Loc, 1))));
787 end Build_Task_Image_Prefix;
789 -----------------------------
790 -- Build_Task_Record_Image --
791 -----------------------------
793 function Build_Task_Record_Image
796 Dyn : Boolean := False) return Node_Id
799 -- Total length of generated name
805 -- String to hold result
807 Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
808 -- Name of enclosing variable, prefix of resulting name
811 -- Expression to compute total size of string
814 -- Entity for selector name
816 Decls : constant List_Id := New_List;
817 Stats : constant List_Id := New_List;
820 -- For a dynamic task, the name comes from the target variable.
821 -- For a static one it is a formal of the enclosing init proc.
824 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
826 Make_Object_Declaration (Loc,
827 Defining_Identifier => Pref,
828 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
830 Make_String_Literal (Loc,
831 Strval => String_From_Name_Buffer)));
835 Make_Object_Renaming_Declaration (Loc,
836 Defining_Identifier => Pref,
837 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
838 Name => Make_Identifier (Loc, Name_uTask_Name)));
841 Sel := Make_Temporary (Loc, 'S');
843 Get_Name_String (Chars (Selector_Name (Id_Ref)));
846 Make_Object_Declaration (Loc,
847 Defining_Identifier => Sel,
848 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
850 Make_String_Literal (Loc,
851 Strval => String_From_Name_Buffer)));
853 Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
859 Make_Attribute_Reference (Loc,
860 Attribute_Name => Name_Length,
862 New_Occurrence_Of (Pref, Loc),
863 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
865 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
867 Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
872 Make_Assignment_Statement (Loc,
873 Name => Make_Indexed_Component (Loc,
874 Prefix => New_Occurrence_Of (Res, Loc),
875 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
877 Make_Character_Literal (Loc,
879 Char_Literal_Value =>
880 UI_From_Int (Character'Pos ('.')))));
883 Make_Assignment_Statement (Loc,
884 Name => New_Occurrence_Of (Pos, Loc),
887 Left_Opnd => New_Occurrence_Of (Pos, Loc),
888 Right_Opnd => Make_Integer_Literal (Loc, 1))));
890 -- Res (Pos .. Len) := Selector;
893 Make_Assignment_Statement (Loc,
894 Name => Make_Slice (Loc,
895 Prefix => New_Occurrence_Of (Res, Loc),
898 Low_Bound => New_Occurrence_Of (Pos, Loc),
899 High_Bound => New_Occurrence_Of (Len, Loc))),
900 Expression => New_Occurrence_Of (Sel, Loc)));
902 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
903 end Build_Task_Record_Image;
905 ----------------------------------
906 -- Component_May_Be_Bit_Aligned --
907 ----------------------------------
909 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
910 UT : constant Entity_Id := Underlying_Type (Etype (Comp));
913 -- If no component clause, then everything is fine, since the back end
914 -- never bit-misaligns by default, even if there is a pragma Packed for
917 if No (Component_Clause (Comp)) then
921 -- It is only array and record types that cause trouble
923 if not Is_Record_Type (UT)
924 and then not Is_Array_Type (UT)
928 -- If we know that we have a small (64 bits or less) record or small
929 -- bit-packed array, then everything is fine, since the back end can
930 -- handle these cases correctly.
932 elsif Esize (Comp) <= 64
933 and then (Is_Record_Type (UT)
934 or else Is_Bit_Packed_Array (UT))
938 -- Otherwise if the component is not byte aligned, we know we have the
939 -- nasty unaligned case.
941 elsif Normalized_First_Bit (Comp) /= Uint_0
942 or else Esize (Comp) mod System_Storage_Unit /= Uint_0
946 -- If we are large and byte aligned, then OK at this level
951 end Component_May_Be_Bit_Aligned;
953 -----------------------------------
954 -- Corresponding_Runtime_Package --
955 -----------------------------------
957 function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id is
958 Pkg_Id : RTU_Id := RTU_Null;
961 pragma Assert (Is_Concurrent_Type (Typ));
963 if Ekind (Typ) in Protected_Kind then
965 or else Has_Interrupt_Handler (Typ)
966 or else (Has_Attach_Handler (Typ)
967 and then not Restricted_Profile)
969 -- A protected type without entries that covers an interface and
970 -- overrides the abstract routines with protected procedures is
971 -- considered equivalent to a protected type with entries in the
972 -- context of dispatching select statements. It is sufficient to
973 -- check for the presence of an interface list in the declaration
974 -- node to recognize this case.
976 or else Present (Interface_List (Parent (Typ)))
979 or else Restriction_Active (No_Entry_Queue) = False
980 or else Number_Entries (Typ) > 1
981 or else (Has_Attach_Handler (Typ)
982 and then not Restricted_Profile)
984 Pkg_Id := System_Tasking_Protected_Objects_Entries;
986 Pkg_Id := System_Tasking_Protected_Objects_Single_Entry;
990 Pkg_Id := System_Tasking_Protected_Objects;
995 end Corresponding_Runtime_Package;
997 -------------------------------
998 -- Convert_To_Actual_Subtype --
999 -------------------------------
1001 procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
1005 Act_ST := Get_Actual_Subtype (Exp);
1007 if Act_ST = Etype (Exp) then
1012 Convert_To (Act_ST, Relocate_Node (Exp)));
1013 Analyze_And_Resolve (Exp, Act_ST);
1015 end Convert_To_Actual_Subtype;
1017 -----------------------------------
1018 -- Current_Sem_Unit_Declarations --
1019 -----------------------------------
1021 function Current_Sem_Unit_Declarations return List_Id is
1022 U : Node_Id := Unit (Cunit (Current_Sem_Unit));
1026 -- If the current unit is a package body, locate the visible
1027 -- declarations of the package spec.
1029 if Nkind (U) = N_Package_Body then
1030 U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
1033 if Nkind (U) = N_Package_Declaration then
1034 U := Specification (U);
1035 Decls := Visible_Declarations (U);
1039 Set_Visible_Declarations (U, Decls);
1043 Decls := Declarations (U);
1047 Set_Declarations (U, Decls);
1052 end Current_Sem_Unit_Declarations;
1054 -----------------------
1055 -- Duplicate_Subexpr --
1056 -----------------------
1058 function Duplicate_Subexpr
1060 Name_Req : Boolean := False) return Node_Id
1063 Remove_Side_Effects (Exp, Name_Req);
1064 return New_Copy_Tree (Exp);
1065 end Duplicate_Subexpr;
1067 ---------------------------------
1068 -- Duplicate_Subexpr_No_Checks --
1069 ---------------------------------
1071 function Duplicate_Subexpr_No_Checks
1073 Name_Req : Boolean := False) return Node_Id
1078 Remove_Side_Effects (Exp, Name_Req);
1079 New_Exp := New_Copy_Tree (Exp);
1080 Remove_Checks (New_Exp);
1082 end Duplicate_Subexpr_No_Checks;
1084 -----------------------------------
1085 -- Duplicate_Subexpr_Move_Checks --
1086 -----------------------------------
1088 function Duplicate_Subexpr_Move_Checks
1090 Name_Req : Boolean := False) return Node_Id
1095 Remove_Side_Effects (Exp, Name_Req);
1096 New_Exp := New_Copy_Tree (Exp);
1097 Remove_Checks (Exp);
1099 end Duplicate_Subexpr_Move_Checks;
1101 --------------------
1102 -- Ensure_Defined --
1103 --------------------
1105 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
1109 -- An itype reference must only be created if this is a local
1110 -- itype, so that gigi can elaborate it on the proper objstack.
1113 and then Scope (Typ) = Current_Scope
1115 IR := Make_Itype_Reference (Sloc (N));
1116 Set_Itype (IR, Typ);
1117 Insert_Action (N, IR);
1121 --------------------
1122 -- Entry_Names_OK --
1123 --------------------
1125 function Entry_Names_OK return Boolean is
1128 not Restricted_Profile
1129 and then not Global_Discard_Names
1130 and then not Restriction_Active (No_Implicit_Heap_Allocations)
1131 and then not Restriction_Active (No_Local_Allocators);
1134 ---------------------
1135 -- Evolve_And_Then --
1136 ---------------------
1138 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
1144 Make_And_Then (Sloc (Cond1),
1146 Right_Opnd => Cond1);
1148 end Evolve_And_Then;
1150 --------------------
1151 -- Evolve_Or_Else --
1152 --------------------
1154 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
1160 Make_Or_Else (Sloc (Cond1),
1162 Right_Opnd => Cond1);
1166 ------------------------------
1167 -- Expand_Subtype_From_Expr --
1168 ------------------------------
1170 -- This function is applicable for both static and dynamic allocation of
1171 -- objects which are constrained by an initial expression. Basically it
1172 -- transforms an unconstrained subtype indication into a constrained one.
1173 -- The expression may also be transformed in certain cases in order to
1174 -- avoid multiple evaluation. In the static allocation case, the general
1179 -- is transformed into
1181 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1183 -- Here are the main cases :
1185 -- <if Expr is a Slice>
1186 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1188 -- <elsif Expr is a String Literal>
1189 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
1191 -- <elsif Expr is Constrained>
1192 -- subtype T is Type_Of_Expr
1195 -- <elsif Expr is an entity_name>
1196 -- Val : T (constraints taken from Expr) := Expr;
1199 -- type Axxx is access all T;
1200 -- Rval : Axxx := Expr'ref;
1201 -- Val : T (constraints taken from Rval) := Rval.all;
1203 -- ??? note: when the Expression is allocated in the secondary stack
1204 -- we could use it directly instead of copying it by declaring
1205 -- Val : T (...) renames Rval.all
1207 procedure Expand_Subtype_From_Expr
1209 Unc_Type : Entity_Id;
1210 Subtype_Indic : Node_Id;
1213 Loc : constant Source_Ptr := Sloc (N);
1214 Exp_Typ : constant Entity_Id := Etype (Exp);
1218 -- In general we cannot build the subtype if expansion is disabled,
1219 -- because internal entities may not have been defined. However, to
1220 -- avoid some cascaded errors, we try to continue when the expression
1221 -- is an array (or string), because it is safe to compute the bounds.
1222 -- It is in fact required to do so even in a generic context, because
1223 -- there may be constants that depend on bounds of string literal.
1225 if not Expander_Active
1226 and then (No (Etype (Exp))
1227 or else Base_Type (Etype (Exp)) /= Standard_String)
1232 if Nkind (Exp) = N_Slice then
1234 Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
1237 Rewrite (Subtype_Indic,
1238 Make_Subtype_Indication (Loc,
1239 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
1241 Make_Index_Or_Discriminant_Constraint (Loc,
1242 Constraints => New_List
1243 (New_Reference_To (Slice_Type, Loc)))));
1245 -- This subtype indication may be used later for constraint checks
1246 -- we better make sure that if a variable was used as a bound of
1247 -- of the original slice, its value is frozen.
1249 Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
1250 Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
1253 elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
1254 Rewrite (Subtype_Indic,
1255 Make_Subtype_Indication (Loc,
1256 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
1258 Make_Index_Or_Discriminant_Constraint (Loc,
1259 Constraints => New_List (
1260 Make_Literal_Range (Loc,
1261 Literal_Typ => Exp_Typ)))));
1263 elsif Is_Constrained (Exp_Typ)
1264 and then not Is_Class_Wide_Type (Unc_Type)
1266 if Is_Itype (Exp_Typ) then
1268 -- Within an initialization procedure, a selected component
1269 -- denotes a component of the enclosing record, and it appears
1270 -- as an actual in a call to its own initialization procedure.
1271 -- If this component depends on the outer discriminant, we must
1272 -- generate the proper actual subtype for it.
1274 if Nkind (Exp) = N_Selected_Component
1275 and then Within_Init_Proc
1278 Decl : constant Node_Id :=
1279 Build_Actual_Subtype_Of_Component (Exp_Typ, Exp);
1281 if Present (Decl) then
1282 Insert_Action (N, Decl);
1283 T := Defining_Identifier (Decl);
1289 -- No need to generate a new one (new what???)
1296 T := Make_Temporary (Loc, 'T');
1299 Make_Subtype_Declaration (Loc,
1300 Defining_Identifier => T,
1301 Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
1303 -- This type is marked as an itype even though it has an
1304 -- explicit declaration because otherwise it can be marked
1305 -- with Is_Generic_Actual_Type and generate spurious errors.
1306 -- (see sem_ch8.Analyze_Package_Renaming and sem_type.covers)
1309 Set_Associated_Node_For_Itype (T, Exp);
1312 Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
1314 -- Nothing needs to be done for private types with unknown discriminants
1315 -- if the underlying type is not an unconstrained composite type or it
1316 -- is an unchecked union.
1318 elsif Is_Private_Type (Unc_Type)
1319 and then Has_Unknown_Discriminants (Unc_Type)
1320 and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
1321 or else Is_Constrained (Underlying_Type (Unc_Type))
1322 or else Is_Unchecked_Union (Underlying_Type (Unc_Type)))
1326 -- Case of derived type with unknown discriminants where the parent type
1327 -- also has unknown discriminants.
1329 elsif Is_Record_Type (Unc_Type)
1330 and then not Is_Class_Wide_Type (Unc_Type)
1331 and then Has_Unknown_Discriminants (Unc_Type)
1332 and then Has_Unknown_Discriminants (Underlying_Type (Unc_Type))
1334 -- Nothing to be done if no underlying record view available
1336 if No (Underlying_Record_View (Unc_Type)) then
1339 -- Otherwise use the Underlying_Record_View to create the proper
1340 -- constrained subtype for an object of a derived type with unknown
1344 Remove_Side_Effects (Exp);
1345 Rewrite (Subtype_Indic,
1346 Make_Subtype_From_Expr (Exp, Underlying_Record_View (Unc_Type)));
1349 -- Renamings of class-wide interface types require no equivalent
1350 -- constrained type declarations because we only need to reference
1351 -- the tag component associated with the interface.
1354 and then Nkind (N) = N_Object_Renaming_Declaration
1355 and then Is_Interface (Unc_Type)
1357 pragma Assert (Is_Class_Wide_Type (Unc_Type));
1360 -- In Ada95, nothing to be done if the type of the expression is
1361 -- limited, because in this case the expression cannot be copied,
1362 -- and its use can only be by reference.
1364 -- In Ada2005, the context can be an object declaration whose expression
1365 -- is a function that returns in place. If the nominal subtype has
1366 -- unknown discriminants, the call still provides constraints on the
1367 -- object, and we have to create an actual subtype from it.
1369 -- If the type is class-wide, the expression is dynamically tagged and
1370 -- we do not create an actual subtype either. Ditto for an interface.
1372 elsif Is_Limited_Type (Exp_Typ)
1374 (Is_Class_Wide_Type (Exp_Typ)
1375 or else Is_Interface (Exp_Typ)
1376 or else not Has_Unknown_Discriminants (Exp_Typ)
1377 or else not Is_Composite_Type (Unc_Type))
1381 -- For limited objects initialized with build in place function calls,
1382 -- nothing to be done; otherwise we prematurely introduce an N_Reference
1383 -- node in the expression initializing the object, which breaks the
1384 -- circuitry that detects and adds the additional arguments to the
1387 elsif Is_Build_In_Place_Function_Call (Exp) then
1391 Remove_Side_Effects (Exp);
1392 Rewrite (Subtype_Indic,
1393 Make_Subtype_From_Expr (Exp, Unc_Type));
1395 end Expand_Subtype_From_Expr;
1397 --------------------
1398 -- Find_Init_Call --
1399 --------------------
1401 function Find_Init_Call
1403 Rep_Clause : Node_Id) return Node_Id
1405 Typ : constant Entity_Id := Etype (Var);
1407 Init_Proc : Entity_Id;
1408 -- Initialization procedure for Typ
1410 function Find_Init_Call_In_List (From : Node_Id) return Node_Id;
1411 -- Look for init call for Var starting at From and scanning the
1412 -- enclosing list until Rep_Clause or the end of the list is reached.
1414 ----------------------------
1415 -- Find_Init_Call_In_List --
1416 ----------------------------
1418 function Find_Init_Call_In_List (From : Node_Id) return Node_Id is
1419 Init_Call : Node_Id;
1423 while Present (Init_Call) and then Init_Call /= Rep_Clause loop
1424 if Nkind (Init_Call) = N_Procedure_Call_Statement
1425 and then Is_Entity_Name (Name (Init_Call))
1426 and then Entity (Name (Init_Call)) = Init_Proc
1434 end Find_Init_Call_In_List;
1436 Init_Call : Node_Id;
1438 -- Start of processing for Find_Init_Call
1441 if not Has_Non_Null_Base_Init_Proc (Typ) then
1442 -- No init proc for the type, so obviously no call to be found
1447 Init_Proc := Base_Init_Proc (Typ);
1449 -- First scan the list containing the declaration of Var
1451 Init_Call := Find_Init_Call_In_List (From => Next (Parent (Var)));
1453 -- If not found, also look on Var's freeze actions list, if any, since
1454 -- the init call may have been moved there (case of an address clause
1455 -- applying to Var).
1457 if No (Init_Call) and then Present (Freeze_Node (Var)) then
1458 Init_Call := Find_Init_Call_In_List
1459 (First (Actions (Freeze_Node (Var))));
1465 ------------------------
1466 -- Find_Interface_ADT --
1467 ------------------------
1469 function Find_Interface_ADT
1471 Iface : Entity_Id) return Elmt_Id
1474 Typ : Entity_Id := T;
1477 pragma Assert (Is_Interface (Iface));
1479 -- Handle private types
1481 if Has_Private_Declaration (Typ)
1482 and then Present (Full_View (Typ))
1484 Typ := Full_View (Typ);
1487 -- Handle access types
1489 if Is_Access_Type (Typ) then
1490 Typ := Designated_Type (Typ);
1493 -- Handle task and protected types implementing interfaces
1495 if Is_Concurrent_Type (Typ) then
1496 Typ := Corresponding_Record_Type (Typ);
1500 (not Is_Class_Wide_Type (Typ)
1501 and then Ekind (Typ) /= E_Incomplete_Type);
1503 if Is_Ancestor (Iface, Typ) then
1504 return First_Elmt (Access_Disp_Table (Typ));
1508 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
1510 and then Present (Related_Type (Node (ADT)))
1511 and then Related_Type (Node (ADT)) /= Iface
1512 and then not Is_Ancestor (Iface, Related_Type (Node (ADT)))
1517 pragma Assert (Present (Related_Type (Node (ADT))));
1520 end Find_Interface_ADT;
1522 ------------------------
1523 -- Find_Interface_Tag --
1524 ------------------------
1526 function Find_Interface_Tag
1528 Iface : Entity_Id) return Entity_Id
1531 Found : Boolean := False;
1532 Typ : Entity_Id := T;
1534 procedure Find_Tag (Typ : Entity_Id);
1535 -- Internal subprogram used to recursively climb to the ancestors
1541 procedure Find_Tag (Typ : Entity_Id) is
1546 -- This routine does not handle the case in which the interface is an
1547 -- ancestor of Typ. That case is handled by the enclosing subprogram.
1549 pragma Assert (Typ /= Iface);
1551 -- Climb to the root type handling private types
1553 if Present (Full_View (Etype (Typ))) then
1554 if Full_View (Etype (Typ)) /= Typ then
1555 Find_Tag (Full_View (Etype (Typ)));
1558 elsif Etype (Typ) /= Typ then
1559 Find_Tag (Etype (Typ));
1562 -- Traverse the list of interfaces implemented by the type
1565 and then Present (Interfaces (Typ))
1566 and then not (Is_Empty_Elmt_List (Interfaces (Typ)))
1568 -- Skip the tag associated with the primary table
1570 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
1571 AI_Tag := Next_Tag_Component (First_Tag_Component (Typ));
1572 pragma Assert (Present (AI_Tag));
1574 AI_Elmt := First_Elmt (Interfaces (Typ));
1575 while Present (AI_Elmt) loop
1576 AI := Node (AI_Elmt);
1578 if AI = Iface or else Is_Ancestor (Iface, AI) then
1583 AI_Tag := Next_Tag_Component (AI_Tag);
1584 Next_Elmt (AI_Elmt);
1589 -- Start of processing for Find_Interface_Tag
1592 pragma Assert (Is_Interface (Iface));
1594 -- Handle access types
1596 if Is_Access_Type (Typ) then
1597 Typ := Designated_Type (Typ);
1600 -- Handle class-wide types
1602 if Is_Class_Wide_Type (Typ) then
1603 Typ := Root_Type (Typ);
1606 -- Handle private types
1608 if Has_Private_Declaration (Typ)
1609 and then Present (Full_View (Typ))
1611 Typ := Full_View (Typ);
1614 -- Handle entities from the limited view
1616 if Ekind (Typ) = E_Incomplete_Type then
1617 pragma Assert (Present (Non_Limited_View (Typ)));
1618 Typ := Non_Limited_View (Typ);
1621 -- Handle task and protected types implementing interfaces
1623 if Is_Concurrent_Type (Typ) then
1624 Typ := Corresponding_Record_Type (Typ);
1627 -- If the interface is an ancestor of the type, then it shared the
1628 -- primary dispatch table.
1630 if Is_Ancestor (Iface, Typ) then
1631 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
1632 return First_Tag_Component (Typ);
1634 -- Otherwise we need to search for its associated tag component
1638 pragma Assert (Found);
1641 end Find_Interface_Tag;
1647 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
1649 Typ : Entity_Id := T;
1653 if Is_Class_Wide_Type (Typ) then
1654 Typ := Root_Type (Typ);
1657 Typ := Underlying_Type (Typ);
1659 -- Loop through primitive operations
1661 Prim := First_Elmt (Primitive_Operations (Typ));
1662 while Present (Prim) loop
1665 -- We can retrieve primitive operations by name if it is an internal
1666 -- name. For equality we must check that both of its operands have
1667 -- the same type, to avoid confusion with user-defined equalities
1668 -- than may have a non-symmetric signature.
1670 exit when Chars (Op) = Name
1673 or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op)));
1677 -- Raise Program_Error if no primitive found
1680 raise Program_Error;
1691 function Find_Prim_Op
1693 Name : TSS_Name_Type) return Entity_Id
1696 Typ : Entity_Id := T;
1699 if Is_Class_Wide_Type (Typ) then
1700 Typ := Root_Type (Typ);
1703 Typ := Underlying_Type (Typ);
1705 Prim := First_Elmt (Primitive_Operations (Typ));
1706 while not Is_TSS (Node (Prim), Name) loop
1709 -- Raise program error if no primitive found
1712 raise Program_Error;
1719 ----------------------------
1720 -- Find_Protection_Object --
1721 ----------------------------
1723 function Find_Protection_Object (Scop : Entity_Id) return Entity_Id is
1728 while Present (S) loop
1729 if (Ekind (S) = E_Entry
1730 or else Ekind (S) = E_Entry_Family
1731 or else Ekind (S) = E_Function
1732 or else Ekind (S) = E_Procedure)
1733 and then Present (Protection_Object (S))
1735 return Protection_Object (S);
1741 -- If we do not find a Protection object in the scope chain, then
1742 -- something has gone wrong, most likely the object was never created.
1744 raise Program_Error;
1745 end Find_Protection_Object;
1747 ----------------------
1748 -- Force_Evaluation --
1749 ----------------------
1751 procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
1753 Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
1754 end Force_Evaluation;
1756 ------------------------
1757 -- Generate_Poll_Call --
1758 ------------------------
1760 procedure Generate_Poll_Call (N : Node_Id) is
1762 -- No poll call if polling not active
1764 if not Polling_Required then
1767 -- Otherwise generate require poll call
1770 Insert_Before_And_Analyze (N,
1771 Make_Procedure_Call_Statement (Sloc (N),
1772 Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
1774 end Generate_Poll_Call;
1776 ---------------------------------
1777 -- Get_Current_Value_Condition --
1778 ---------------------------------
1780 -- Note: the implementation of this procedure is very closely tied to the
1781 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
1782 -- interpret Current_Value fields set by the Set procedure, so the two
1783 -- procedures need to be closely coordinated.
1785 procedure Get_Current_Value_Condition
1790 Loc : constant Source_Ptr := Sloc (Var);
1791 Ent : constant Entity_Id := Entity (Var);
1793 procedure Process_Current_Value_Condition
1796 -- N is an expression which holds either True (S = True) or False (S =
1797 -- False) in the condition. This procedure digs out the expression and
1798 -- if it refers to Ent, sets Op and Val appropriately.
1800 -------------------------------------
1801 -- Process_Current_Value_Condition --
1802 -------------------------------------
1804 procedure Process_Current_Value_Condition
1815 -- Deal with NOT operators, inverting sense
1817 while Nkind (Cond) = N_Op_Not loop
1818 Cond := Right_Opnd (Cond);
1822 -- Deal with AND THEN and AND cases
1824 if Nkind (Cond) = N_And_Then
1825 or else Nkind (Cond) = N_Op_And
1827 -- Don't ever try to invert a condition that is of the form
1828 -- of an AND or AND THEN (since we are not doing sufficiently
1829 -- general processing to allow this).
1831 if Sens = False then
1837 -- Recursively process AND and AND THEN branches
1839 Process_Current_Value_Condition (Left_Opnd (Cond), True);
1841 if Op /= N_Empty then
1845 Process_Current_Value_Condition (Right_Opnd (Cond), True);
1848 -- Case of relational operator
1850 elsif Nkind (Cond) in N_Op_Compare then
1853 -- Invert sense of test if inverted test
1855 if Sens = False then
1857 when N_Op_Eq => Op := N_Op_Ne;
1858 when N_Op_Ne => Op := N_Op_Eq;
1859 when N_Op_Lt => Op := N_Op_Ge;
1860 when N_Op_Gt => Op := N_Op_Le;
1861 when N_Op_Le => Op := N_Op_Gt;
1862 when N_Op_Ge => Op := N_Op_Lt;
1863 when others => raise Program_Error;
1867 -- Case of entity op value
1869 if Is_Entity_Name (Left_Opnd (Cond))
1870 and then Ent = Entity (Left_Opnd (Cond))
1871 and then Compile_Time_Known_Value (Right_Opnd (Cond))
1873 Val := Right_Opnd (Cond);
1875 -- Case of value op entity
1877 elsif Is_Entity_Name (Right_Opnd (Cond))
1878 and then Ent = Entity (Right_Opnd (Cond))
1879 and then Compile_Time_Known_Value (Left_Opnd (Cond))
1881 Val := Left_Opnd (Cond);
1883 -- We are effectively swapping operands
1886 when N_Op_Eq => null;
1887 when N_Op_Ne => null;
1888 when N_Op_Lt => Op := N_Op_Gt;
1889 when N_Op_Gt => Op := N_Op_Lt;
1890 when N_Op_Le => Op := N_Op_Ge;
1891 when N_Op_Ge => Op := N_Op_Le;
1892 when others => raise Program_Error;
1901 -- Case of Boolean variable reference, return as though the
1902 -- reference had said var = True.
1905 if Is_Entity_Name (Cond)
1906 and then Ent = Entity (Cond)
1908 Val := New_Occurrence_Of (Standard_True, Sloc (Cond));
1910 if Sens = False then
1917 end Process_Current_Value_Condition;
1919 -- Start of processing for Get_Current_Value_Condition
1925 -- Immediate return, nothing doing, if this is not an object
1927 if Ekind (Ent) not in Object_Kind then
1931 -- Otherwise examine current value
1934 CV : constant Node_Id := Current_Value (Ent);
1939 -- If statement. Condition is known true in THEN section, known False
1940 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
1942 if Nkind (CV) = N_If_Statement then
1944 -- Before start of IF statement
1946 if Loc < Sloc (CV) then
1949 -- After end of IF statement
1951 elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then
1955 -- At this stage we know that we are within the IF statement, but
1956 -- unfortunately, the tree does not record the SLOC of the ELSE so
1957 -- we cannot use a simple SLOC comparison to distinguish between
1958 -- the then/else statements, so we have to climb the tree.
1965 while Parent (N) /= CV loop
1968 -- If we fall off the top of the tree, then that's odd, but
1969 -- perhaps it could occur in some error situation, and the
1970 -- safest response is simply to assume that the outcome of
1971 -- the condition is unknown. No point in bombing during an
1972 -- attempt to optimize things.
1979 -- Now we have N pointing to a node whose parent is the IF
1980 -- statement in question, so now we can tell if we are within
1981 -- the THEN statements.
1983 if Is_List_Member (N)
1984 and then List_Containing (N) = Then_Statements (CV)
1988 -- If the variable reference does not come from source, we
1989 -- cannot reliably tell whether it appears in the else part.
1990 -- In particular, if it appears in generated code for a node
1991 -- that requires finalization, it may be attached to a list
1992 -- that has not been yet inserted into the code. For now,
1993 -- treat it as unknown.
1995 elsif not Comes_From_Source (N) then
1998 -- Otherwise we must be in ELSIF or ELSE part
2005 -- ELSIF part. Condition is known true within the referenced
2006 -- ELSIF, known False in any subsequent ELSIF or ELSE part, and
2007 -- unknown before the ELSE part or after the IF statement.
2009 elsif Nkind (CV) = N_Elsif_Part then
2011 -- if the Elsif_Part had condition_actions, the elsif has been
2012 -- rewritten as a nested if, and the original elsif_part is
2013 -- detached from the tree, so there is no way to obtain useful
2014 -- information on the current value of the variable.
2015 -- Can this be improved ???
2017 if No (Parent (CV)) then
2023 -- Before start of ELSIF part
2025 if Loc < Sloc (CV) then
2028 -- After end of IF statement
2030 elsif Loc >= Sloc (Stm) +
2031 Text_Ptr (UI_To_Int (End_Span (Stm)))
2036 -- Again we lack the SLOC of the ELSE, so we need to climb the
2037 -- tree to see if we are within the ELSIF part in question.
2044 while Parent (N) /= Stm loop
2047 -- If we fall off the top of the tree, then that's odd, but
2048 -- perhaps it could occur in some error situation, and the
2049 -- safest response is simply to assume that the outcome of
2050 -- the condition is unknown. No point in bombing during an
2051 -- attempt to optimize things.
2058 -- Now we have N pointing to a node whose parent is the IF
2059 -- statement in question, so see if is the ELSIF part we want.
2060 -- the THEN statements.
2065 -- Otherwise we must be in subsequent ELSIF or ELSE part
2072 -- Iteration scheme of while loop. The condition is known to be
2073 -- true within the body of the loop.
2075 elsif Nkind (CV) = N_Iteration_Scheme then
2077 Loop_Stmt : constant Node_Id := Parent (CV);
2080 -- Before start of body of loop
2082 if Loc < Sloc (Loop_Stmt) then
2085 -- After end of LOOP statement
2087 elsif Loc >= Sloc (End_Label (Loop_Stmt)) then
2090 -- We are within the body of the loop
2097 -- All other cases of Current_Value settings
2103 -- If we fall through here, then we have a reportable condition, Sens
2104 -- is True if the condition is true and False if it needs inverting.
2106 Process_Current_Value_Condition (Condition (CV), Sens);
2108 end Get_Current_Value_Condition;
2110 ---------------------------------
2111 -- Has_Controlled_Coextensions --
2112 ---------------------------------
2114 function Has_Controlled_Coextensions (Typ : Entity_Id) return Boolean is
2119 -- Only consider record types
2121 if not Ekind_In (Typ, E_Record_Type, E_Record_Subtype) then
2125 if Has_Discriminants (Typ) then
2126 Discr := First_Discriminant (Typ);
2127 while Present (Discr) loop
2128 D_Typ := Etype (Discr);
2130 if Ekind (D_Typ) = E_Anonymous_Access_Type
2132 (Is_Controlled (Designated_Type (D_Typ))
2134 Is_Concurrent_Type (Designated_Type (D_Typ)))
2139 Next_Discriminant (Discr);
2144 end Has_Controlled_Coextensions;
2146 ------------------------
2147 -- Has_Address_Clause --
2148 ------------------------
2150 -- Should this function check the private part in a package ???
2152 function Has_Following_Address_Clause (D : Node_Id) return Boolean is
2153 Id : constant Entity_Id := Defining_Identifier (D);
2158 while Present (Decl) loop
2159 if Nkind (Decl) = N_At_Clause
2160 and then Chars (Identifier (Decl)) = Chars (Id)
2164 elsif Nkind (Decl) = N_Attribute_Definition_Clause
2165 and then Chars (Decl) = Name_Address
2166 and then Chars (Name (Decl)) = Chars (Id)
2175 end Has_Following_Address_Clause;
2177 --------------------
2178 -- Homonym_Number --
2179 --------------------
2181 function Homonym_Number (Subp : Entity_Id) return Nat is
2187 Hom := Homonym (Subp);
2188 while Present (Hom) loop
2189 if Scope (Hom) = Scope (Subp) then
2193 Hom := Homonym (Hom);
2199 ------------------------------
2200 -- In_Unconditional_Context --
2201 ------------------------------
2203 function In_Unconditional_Context (Node : Node_Id) return Boolean is
2208 while Present (P) loop
2210 when N_Subprogram_Body =>
2213 when N_If_Statement =>
2216 when N_Loop_Statement =>
2219 when N_Case_Statement =>
2228 end In_Unconditional_Context;
2234 procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
2236 if Present (Ins_Action) then
2237 Insert_Actions (Assoc_Node, New_List (Ins_Action));
2241 -- Version with check(s) suppressed
2243 procedure Insert_Action
2244 (Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
2247 Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
2250 --------------------
2251 -- Insert_Actions --
2252 --------------------
2254 procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
2258 Wrapped_Node : Node_Id := Empty;
2261 if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
2265 -- Ignore insert of actions from inside default expression (or other
2266 -- similar "spec expression") in the special spec-expression analyze
2267 -- mode. Any insertions at this point have no relevance, since we are
2268 -- only doing the analyze to freeze the types of any static expressions.
2269 -- See section "Handling of Default Expressions" in the spec of package
2270 -- Sem for further details.
2272 if In_Spec_Expression then
2276 -- If the action derives from stuff inside a record, then the actions
2277 -- are attached to the current scope, to be inserted and analyzed on
2278 -- exit from the scope. The reason for this is that we may also
2279 -- be generating freeze actions at the same time, and they must
2280 -- eventually be elaborated in the correct order.
2282 if Is_Record_Type (Current_Scope)
2283 and then not Is_Frozen (Current_Scope)
2285 if No (Scope_Stack.Table
2286 (Scope_Stack.Last).Pending_Freeze_Actions)
2288 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
2293 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
2299 -- We now intend to climb up the tree to find the right point to
2300 -- insert the actions. We start at Assoc_Node, unless this node is
2301 -- a subexpression in which case we start with its parent. We do this
2302 -- for two reasons. First it speeds things up. Second, if Assoc_Node
2303 -- is itself one of the special nodes like N_And_Then, then we assume
2304 -- that an initial request to insert actions for such a node does not
2305 -- expect the actions to get deposited in the node for later handling
2306 -- when the node is expanded, since clearly the node is being dealt
2307 -- with by the caller. Note that in the subexpression case, N is
2308 -- always the child we came from.
2310 -- N_Raise_xxx_Error is an annoying special case, it is a statement
2311 -- if it has type Standard_Void_Type, and a subexpression otherwise.
2312 -- otherwise. Procedure attribute references are also statements.
2314 if Nkind (Assoc_Node) in N_Subexpr
2315 and then (Nkind (Assoc_Node) in N_Raise_xxx_Error
2316 or else Etype (Assoc_Node) /= Standard_Void_Type)
2317 and then (Nkind (Assoc_Node) /= N_Attribute_Reference
2319 not Is_Procedure_Attribute_Name
2320 (Attribute_Name (Assoc_Node)))
2322 P := Assoc_Node; -- ??? does not agree with above!
2323 N := Parent (Assoc_Node);
2325 -- Non-subexpression case. Note that N is initially Empty in this
2326 -- case (N is only guaranteed Non-Empty in the subexpr case).
2333 -- Capture root of the transient scope
2335 if Scope_Is_Transient then
2336 Wrapped_Node := Node_To_Be_Wrapped;
2340 pragma Assert (Present (P));
2344 -- Case of right operand of AND THEN or OR ELSE. Put the actions
2345 -- in the Actions field of the right operand. They will be moved
2346 -- out further when the AND THEN or OR ELSE operator is expanded.
2347 -- Nothing special needs to be done for the left operand since
2348 -- in that case the actions are executed unconditionally.
2350 when N_Short_Circuit =>
2351 if N = Right_Opnd (P) then
2353 -- We are now going to either append the actions to the
2354 -- actions field of the short-circuit operation. We will
2355 -- also analyze the actions now.
2357 -- This analysis is really too early, the proper thing would
2358 -- be to just park them there now, and only analyze them if
2359 -- we find we really need them, and to it at the proper
2360 -- final insertion point. However attempting to this proved
2361 -- tricky, so for now we just kill current values before and
2362 -- after the analyze call to make sure we avoid peculiar
2363 -- optimizations from this out of order insertion.
2365 Kill_Current_Values;
2367 if Present (Actions (P)) then
2368 Insert_List_After_And_Analyze
2369 (Last (Actions (P)), Ins_Actions);
2371 Set_Actions (P, Ins_Actions);
2372 Analyze_List (Actions (P));
2375 Kill_Current_Values;
2380 -- Then or Else operand of conditional expression. Add actions to
2381 -- Then_Actions or Else_Actions field as appropriate. The actions
2382 -- will be moved further out when the conditional is expanded.
2384 when N_Conditional_Expression =>
2386 ThenX : constant Node_Id := Next (First (Expressions (P)));
2387 ElseX : constant Node_Id := Next (ThenX);
2390 -- Actions belong to the then expression, temporarily
2391 -- place them as Then_Actions of the conditional expr.
2392 -- They will be moved to the proper place later when
2393 -- the conditional expression is expanded.
2396 if Present (Then_Actions (P)) then
2397 Insert_List_After_And_Analyze
2398 (Last (Then_Actions (P)), Ins_Actions);
2400 Set_Then_Actions (P, Ins_Actions);
2401 Analyze_List (Then_Actions (P));
2406 -- Actions belong to the else expression, temporarily
2407 -- place them as Else_Actions of the conditional expr.
2408 -- They will be moved to the proper place later when
2409 -- the conditional expression is expanded.
2411 elsif N = ElseX then
2412 if Present (Else_Actions (P)) then
2413 Insert_List_After_And_Analyze
2414 (Last (Else_Actions (P)), Ins_Actions);
2416 Set_Else_Actions (P, Ins_Actions);
2417 Analyze_List (Else_Actions (P));
2422 -- Actions belong to the condition. In this case they are
2423 -- unconditionally executed, and so we can continue the
2424 -- search for the proper insert point.
2431 -- Alternative of case expression, we place the action in
2432 -- the Actions field of the case expression alternative, this
2433 -- will be handled when the case expression is expanded.
2435 when N_Case_Expression_Alternative =>
2436 if Present (Actions (P)) then
2437 Insert_List_After_And_Analyze
2438 (Last (Actions (P)), Ins_Actions);
2440 Set_Actions (P, Ins_Actions);
2441 Analyze_List (Then_Actions (P));
2446 -- Case of appearing within an Expressions_With_Actions node. We
2447 -- prepend the actions to the list of actions already there.
2449 when N_Expression_With_Actions =>
2450 Prepend_List (Ins_Actions, Actions (P));
2453 -- Case of appearing in the condition of a while expression or
2454 -- elsif. We insert the actions into the Condition_Actions field.
2455 -- They will be moved further out when the while loop or elsif
2458 when N_Iteration_Scheme |
2461 if N = Condition (P) then
2462 if Present (Condition_Actions (P)) then
2463 Insert_List_After_And_Analyze
2464 (Last (Condition_Actions (P)), Ins_Actions);
2466 Set_Condition_Actions (P, Ins_Actions);
2468 -- Set the parent of the insert actions explicitly.
2469 -- This is not a syntactic field, but we need the
2470 -- parent field set, in particular so that freeze
2471 -- can understand that it is dealing with condition
2472 -- actions, and properly insert the freezing actions.
2474 Set_Parent (Ins_Actions, P);
2475 Analyze_List (Condition_Actions (P));
2481 -- Statements, declarations, pragmas, representation clauses
2486 N_Procedure_Call_Statement |
2487 N_Statement_Other_Than_Procedure_Call |
2493 -- Representation_Clause
2496 N_Attribute_Definition_Clause |
2497 N_Enumeration_Representation_Clause |
2498 N_Record_Representation_Clause |
2502 N_Abstract_Subprogram_Declaration |
2504 N_Exception_Declaration |
2505 N_Exception_Renaming_Declaration |
2506 N_Formal_Abstract_Subprogram_Declaration |
2507 N_Formal_Concrete_Subprogram_Declaration |
2508 N_Formal_Object_Declaration |
2509 N_Formal_Type_Declaration |
2510 N_Full_Type_Declaration |
2511 N_Function_Instantiation |
2512 N_Generic_Function_Renaming_Declaration |
2513 N_Generic_Package_Declaration |
2514 N_Generic_Package_Renaming_Declaration |
2515 N_Generic_Procedure_Renaming_Declaration |
2516 N_Generic_Subprogram_Declaration |
2517 N_Implicit_Label_Declaration |
2518 N_Incomplete_Type_Declaration |
2519 N_Number_Declaration |
2520 N_Object_Declaration |
2521 N_Object_Renaming_Declaration |
2523 N_Package_Body_Stub |
2524 N_Package_Declaration |
2525 N_Package_Instantiation |
2526 N_Package_Renaming_Declaration |
2527 N_Private_Extension_Declaration |
2528 N_Private_Type_Declaration |
2529 N_Procedure_Instantiation |
2531 N_Protected_Body_Stub |
2532 N_Protected_Type_Declaration |
2533 N_Single_Task_Declaration |
2535 N_Subprogram_Body_Stub |
2536 N_Subprogram_Declaration |
2537 N_Subprogram_Renaming_Declaration |
2538 N_Subtype_Declaration |
2541 N_Task_Type_Declaration |
2543 -- Freeze entity behaves like a declaration or statement
2547 -- Do not insert here if the item is not a list member (this
2548 -- happens for example with a triggering statement, and the
2549 -- proper approach is to insert before the entire select).
2551 if not Is_List_Member (P) then
2554 -- Do not insert if parent of P is an N_Component_Association
2555 -- node (i.e. we are in the context of an N_Aggregate or
2556 -- N_Extension_Aggregate node. In this case we want to insert
2557 -- before the entire aggregate.
2559 elsif Nkind (Parent (P)) = N_Component_Association then
2562 -- Do not insert if the parent of P is either an N_Variant
2563 -- node or an N_Record_Definition node, meaning in either
2564 -- case that P is a member of a component list, and that
2565 -- therefore the actions should be inserted outside the
2566 -- complete record declaration.
2568 elsif Nkind (Parent (P)) = N_Variant
2569 or else Nkind (Parent (P)) = N_Record_Definition
2573 -- Do not insert freeze nodes within the loop generated for
2574 -- an aggregate, because they may be elaborated too late for
2575 -- subsequent use in the back end: within a package spec the
2576 -- loop is part of the elaboration procedure and is only
2577 -- elaborated during the second pass.
2578 -- If the loop comes from source, or the entity is local to
2579 -- the loop itself it must remain within.
2581 elsif Nkind (Parent (P)) = N_Loop_Statement
2582 and then not Comes_From_Source (Parent (P))
2583 and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
2585 Scope (Entity (First (Ins_Actions))) /= Current_Scope
2589 -- Otherwise we can go ahead and do the insertion
2591 elsif P = Wrapped_Node then
2592 Store_Before_Actions_In_Scope (Ins_Actions);
2596 Insert_List_Before_And_Analyze (P, Ins_Actions);
2600 -- A special case, N_Raise_xxx_Error can act either as a
2601 -- statement or a subexpression. We tell the difference
2602 -- by looking at the Etype. It is set to Standard_Void_Type
2603 -- in the statement case.
2606 N_Raise_xxx_Error =>
2607 if Etype (P) = Standard_Void_Type then
2608 if P = Wrapped_Node then
2609 Store_Before_Actions_In_Scope (Ins_Actions);
2611 Insert_List_Before_And_Analyze (P, Ins_Actions);
2616 -- In the subexpression case, keep climbing
2622 -- If a component association appears within a loop created for
2623 -- an array aggregate, attach the actions to the association so
2624 -- they can be subsequently inserted within the loop. For other
2625 -- component associations insert outside of the aggregate. For
2626 -- an association that will generate a loop, its Loop_Actions
2627 -- attribute is already initialized (see exp_aggr.adb).
2629 -- The list of loop_actions can in turn generate additional ones,
2630 -- that are inserted before the associated node. If the associated
2631 -- node is outside the aggregate, the new actions are collected
2632 -- at the end of the loop actions, to respect the order in which
2633 -- they are to be elaborated.
2636 N_Component_Association =>
2637 if Nkind (Parent (P)) = N_Aggregate
2638 and then Present (Loop_Actions (P))
2640 if Is_Empty_List (Loop_Actions (P)) then
2641 Set_Loop_Actions (P, Ins_Actions);
2642 Analyze_List (Ins_Actions);
2649 -- Check whether these actions were generated
2650 -- by a declaration that is part of the loop_
2651 -- actions for the component_association.
2654 while Present (Decl) loop
2655 exit when Parent (Decl) = P
2656 and then Is_List_Member (Decl)
2658 List_Containing (Decl) = Loop_Actions (P);
2659 Decl := Parent (Decl);
2662 if Present (Decl) then
2663 Insert_List_Before_And_Analyze
2664 (Decl, Ins_Actions);
2666 Insert_List_After_And_Analyze
2667 (Last (Loop_Actions (P)), Ins_Actions);
2678 -- Another special case, an attribute denoting a procedure call
2681 N_Attribute_Reference =>
2682 if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
2683 if P = Wrapped_Node then
2684 Store_Before_Actions_In_Scope (Ins_Actions);
2686 Insert_List_Before_And_Analyze (P, Ins_Actions);
2691 -- In the subexpression case, keep climbing
2697 -- For all other node types, keep climbing tree
2701 N_Accept_Alternative |
2702 N_Access_Definition |
2703 N_Access_Function_Definition |
2704 N_Access_Procedure_Definition |
2705 N_Access_To_Object_Definition |
2709 N_Case_Statement_Alternative |
2710 N_Character_Literal |
2711 N_Compilation_Unit |
2712 N_Compilation_Unit_Aux |
2713 N_Component_Clause |
2714 N_Component_Declaration |
2715 N_Component_Definition |
2717 N_Constrained_Array_Definition |
2718 N_Decimal_Fixed_Point_Definition |
2719 N_Defining_Character_Literal |
2720 N_Defining_Identifier |
2721 N_Defining_Operator_Symbol |
2722 N_Defining_Program_Unit_Name |
2723 N_Delay_Alternative |
2724 N_Delta_Constraint |
2725 N_Derived_Type_Definition |
2727 N_Digits_Constraint |
2728 N_Discriminant_Association |
2729 N_Discriminant_Specification |
2731 N_Entry_Body_Formal_Part |
2732 N_Entry_Call_Alternative |
2733 N_Entry_Declaration |
2734 N_Entry_Index_Specification |
2735 N_Enumeration_Type_Definition |
2737 N_Exception_Handler |
2739 N_Explicit_Dereference |
2740 N_Extension_Aggregate |
2741 N_Floating_Point_Definition |
2742 N_Formal_Decimal_Fixed_Point_Definition |
2743 N_Formal_Derived_Type_Definition |
2744 N_Formal_Discrete_Type_Definition |
2745 N_Formal_Floating_Point_Definition |
2746 N_Formal_Modular_Type_Definition |
2747 N_Formal_Ordinary_Fixed_Point_Definition |
2748 N_Formal_Package_Declaration |
2749 N_Formal_Private_Type_Definition |
2750 N_Formal_Signed_Integer_Type_Definition |
2752 N_Function_Specification |
2753 N_Generic_Association |
2754 N_Handled_Sequence_Of_Statements |
2757 N_Index_Or_Discriminant_Constraint |
2758 N_Indexed_Component |
2762 N_Loop_Parameter_Specification |
2764 N_Modular_Type_Definition |
2790 N_Op_Shift_Right_Arithmetic |
2794 N_Ordinary_Fixed_Point_Definition |
2796 N_Package_Specification |
2797 N_Parameter_Association |
2798 N_Parameter_Specification |
2799 N_Pop_Constraint_Error_Label |
2800 N_Pop_Program_Error_Label |
2801 N_Pop_Storage_Error_Label |
2802 N_Pragma_Argument_Association |
2803 N_Procedure_Specification |
2804 N_Protected_Definition |
2805 N_Push_Constraint_Error_Label |
2806 N_Push_Program_Error_Label |
2807 N_Push_Storage_Error_Label |
2808 N_Qualified_Expression |
2810 N_Range_Constraint |
2812 N_Real_Range_Specification |
2813 N_Record_Definition |
2815 N_SCIL_Dispatch_Table_Object_Init |
2816 N_SCIL_Dispatch_Table_Tag_Init |
2817 N_SCIL_Dispatching_Call |
2818 N_SCIL_Membership_Test |
2820 N_Selected_Component |
2821 N_Signed_Integer_Type_Definition |
2822 N_Single_Protected_Declaration |
2826 N_Subtype_Indication |
2829 N_Terminate_Alternative |
2830 N_Triggering_Alternative |
2832 N_Unchecked_Expression |
2833 N_Unchecked_Type_Conversion |
2834 N_Unconstrained_Array_Definition |
2837 N_Use_Package_Clause |
2841 N_Validate_Unchecked_Conversion |
2848 -- Make sure that inserted actions stay in the transient scope
2850 if P = Wrapped_Node then
2851 Store_Before_Actions_In_Scope (Ins_Actions);
2855 -- If we fall through above tests, keep climbing tree
2859 if Nkind (Parent (N)) = N_Subunit then
2861 -- This is the proper body corresponding to a stub. Insertion
2862 -- must be done at the point of the stub, which is in the decla-
2863 -- rative part of the parent unit.
2865 P := Corresponding_Stub (Parent (N));
2873 -- Version with check(s) suppressed
2875 procedure Insert_Actions
2876 (Assoc_Node : Node_Id;
2877 Ins_Actions : List_Id;
2878 Suppress : Check_Id)
2881 if Suppress = All_Checks then
2883 Svg : constant Suppress_Array := Scope_Suppress;
2885 Scope_Suppress := (others => True);
2886 Insert_Actions (Assoc_Node, Ins_Actions);
2887 Scope_Suppress := Svg;
2892 Svg : constant Boolean := Scope_Suppress (Suppress);
2894 Scope_Suppress (Suppress) := True;
2895 Insert_Actions (Assoc_Node, Ins_Actions);
2896 Scope_Suppress (Suppress) := Svg;
2901 --------------------------
2902 -- Insert_Actions_After --
2903 --------------------------
2905 procedure Insert_Actions_After
2906 (Assoc_Node : Node_Id;
2907 Ins_Actions : List_Id)
2910 if Scope_Is_Transient
2911 and then Assoc_Node = Node_To_Be_Wrapped
2913 Store_After_Actions_In_Scope (Ins_Actions);
2915 Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
2917 end Insert_Actions_After;
2919 ---------------------------------
2920 -- Insert_Library_Level_Action --
2921 ---------------------------------
2923 procedure Insert_Library_Level_Action (N : Node_Id) is
2924 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
2927 Push_Scope (Cunit_Entity (Main_Unit));
2928 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
2930 if No (Actions (Aux)) then
2931 Set_Actions (Aux, New_List (N));
2933 Append (N, Actions (Aux));
2938 end Insert_Library_Level_Action;
2940 ----------------------------------
2941 -- Insert_Library_Level_Actions --
2942 ----------------------------------
2944 procedure Insert_Library_Level_Actions (L : List_Id) is
2945 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
2948 if Is_Non_Empty_List (L) then
2949 Push_Scope (Cunit_Entity (Main_Unit));
2950 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
2952 if No (Actions (Aux)) then
2953 Set_Actions (Aux, L);
2956 Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
2961 end Insert_Library_Level_Actions;
2963 ----------------------
2964 -- Inside_Init_Proc --
2965 ----------------------
2967 function Inside_Init_Proc return Boolean is
2973 and then S /= Standard_Standard
2975 if Is_Init_Proc (S) then
2983 end Inside_Init_Proc;
2985 ----------------------------
2986 -- Is_All_Null_Statements --
2987 ----------------------------
2989 function Is_All_Null_Statements (L : List_Id) return Boolean is
2994 while Present (Stm) loop
2995 if Nkind (Stm) /= N_Null_Statement then
3003 end Is_All_Null_Statements;
3005 ---------------------------------
3006 -- Is_Fully_Repped_Tagged_Type --
3007 ---------------------------------
3009 function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean is
3010 U : constant Entity_Id := Underlying_Type (T);
3014 if No (U) or else not Is_Tagged_Type (U) then
3016 elsif Has_Discriminants (U) then
3018 elsif not Has_Specified_Layout (U) then
3022 -- Here we have a tagged type, see if it has any unlayed out fields
3023 -- other than a possible tag and parent fields. If so, we return False.
3025 Comp := First_Component (U);
3026 while Present (Comp) loop
3027 if not Is_Tag (Comp)
3028 and then Chars (Comp) /= Name_uParent
3029 and then No (Component_Clause (Comp))
3033 Next_Component (Comp);
3037 -- All components are layed out
3040 end Is_Fully_Repped_Tagged_Type;
3042 ----------------------------------
3043 -- Is_Library_Level_Tagged_Type --
3044 ----------------------------------
3046 function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean is
3048 return Is_Tagged_Type (Typ)
3049 and then Is_Library_Level_Entity (Typ);
3050 end Is_Library_Level_Tagged_Type;
3052 ----------------------------------
3053 -- Is_Possibly_Unaligned_Object --
3054 ----------------------------------
3056 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
3057 T : constant Entity_Id := Etype (N);
3060 -- If renamed object, apply test to underlying object
3062 if Is_Entity_Name (N)
3063 and then Is_Object (Entity (N))
3064 and then Present (Renamed_Object (Entity (N)))
3066 return Is_Possibly_Unaligned_Object (Renamed_Object (Entity (N)));
3069 -- Tagged and controlled types and aliased types are always aligned,
3070 -- as are concurrent types.
3073 or else Has_Controlled_Component (T)
3074 or else Is_Concurrent_Type (T)
3075 or else Is_Tagged_Type (T)
3076 or else Is_Controlled (T)
3081 -- If this is an element of a packed array, may be unaligned
3083 if Is_Ref_To_Bit_Packed_Array (N) then
3087 -- Case of component reference
3089 if Nkind (N) = N_Selected_Component then
3091 P : constant Node_Id := Prefix (N);
3092 C : constant Entity_Id := Entity (Selector_Name (N));
3097 -- If component reference is for an array with non-static bounds,
3098 -- then it is always aligned: we can only process unaligned
3099 -- arrays with static bounds (more accurately bounds known at
3102 if Is_Array_Type (T)
3103 and then not Compile_Time_Known_Bounds (T)
3108 -- If component is aliased, it is definitely properly aligned
3110 if Is_Aliased (C) then
3114 -- If component is for a type implemented as a scalar, and the
3115 -- record is packed, and the component is other than the first
3116 -- component of the record, then the component may be unaligned.
3118 if Is_Packed (Etype (P))
3119 and then Represented_As_Scalar (Etype (C))
3120 and then First_Entity (Scope (C)) /= C
3125 -- Compute maximum possible alignment for T
3127 -- If alignment is known, then that settles things
3129 if Known_Alignment (T) then
3130 M := UI_To_Int (Alignment (T));
3132 -- If alignment is not known, tentatively set max alignment
3135 M := Ttypes.Maximum_Alignment;
3137 -- We can reduce this if the Esize is known since the default
3138 -- alignment will never be more than the smallest power of 2
3139 -- that does not exceed this Esize value.
3141 if Known_Esize (T) then
3142 S := UI_To_Int (Esize (T));
3144 while (M / 2) >= S loop
3150 -- If the component reference is for a record that has a specified
3151 -- alignment, and we either know it is too small, or cannot tell,
3152 -- then the component may be unaligned
3154 if Known_Alignment (Etype (P))
3155 and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
3156 and then M > Alignment (Etype (P))
3161 -- Case of component clause present which may specify an
3162 -- unaligned position.
3164 if Present (Component_Clause (C)) then
3166 -- Otherwise we can do a test to make sure that the actual
3167 -- start position in the record, and the length, are both
3168 -- consistent with the required alignment. If not, we know
3169 -- that we are unaligned.
3172 Align_In_Bits : constant Nat := M * System_Storage_Unit;
3174 if Component_Bit_Offset (C) mod Align_In_Bits /= 0
3175 or else Esize (C) mod Align_In_Bits /= 0
3182 -- Otherwise, for a component reference, test prefix
3184 return Is_Possibly_Unaligned_Object (P);
3187 -- If not a component reference, must be aligned
3192 end Is_Possibly_Unaligned_Object;
3194 ---------------------------------
3195 -- Is_Possibly_Unaligned_Slice --
3196 ---------------------------------
3198 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean is
3200 -- Go to renamed object
3202 if Is_Entity_Name (N)
3203 and then Is_Object (Entity (N))
3204 and then Present (Renamed_Object (Entity (N)))
3206 return Is_Possibly_Unaligned_Slice (Renamed_Object (Entity (N)));
3209 -- The reference must be a slice
3211 if Nkind (N) /= N_Slice then
3215 -- Always assume the worst for a nested record component with a
3216 -- component clause, which gigi/gcc does not appear to handle well.
3217 -- It is not clear why this special test is needed at all ???
3219 if Nkind (Prefix (N)) = N_Selected_Component
3220 and then Nkind (Prefix (Prefix (N))) = N_Selected_Component
3222 Present (Component_Clause (Entity (Selector_Name (Prefix (N)))))
3227 -- We only need to worry if the target has strict alignment
3229 if not Target_Strict_Alignment then
3233 -- If it is a slice, then look at the array type being sliced
3236 Sarr : constant Node_Id := Prefix (N);
3237 -- Prefix of the slice, i.e. the array being sliced
3239 Styp : constant Entity_Id := Etype (Prefix (N));
3240 -- Type of the array being sliced
3246 -- The problems arise if the array object that is being sliced
3247 -- is a component of a record or array, and we cannot guarantee
3248 -- the alignment of the array within its containing object.
3250 -- To investigate this, we look at successive prefixes to see
3251 -- if we have a worrisome indexed or selected component.
3255 -- Case of array is part of an indexed component reference
3257 if Nkind (Pref) = N_Indexed_Component then
3258 Ptyp := Etype (Prefix (Pref));
3260 -- The only problematic case is when the array is packed,
3261 -- in which case we really know nothing about the alignment
3262 -- of individual components.
3264 if Is_Bit_Packed_Array (Ptyp) then
3268 -- Case of array is part of a selected component reference
3270 elsif Nkind (Pref) = N_Selected_Component then
3271 Ptyp := Etype (Prefix (Pref));
3273 -- We are definitely in trouble if the record in question
3274 -- has an alignment, and either we know this alignment is
3275 -- inconsistent with the alignment of the slice, or we
3276 -- don't know what the alignment of the slice should be.
3278 if Known_Alignment (Ptyp)
3279 and then (Unknown_Alignment (Styp)
3280 or else Alignment (Styp) > Alignment (Ptyp))
3285 -- We are in potential trouble if the record type is packed.
3286 -- We could special case when we know that the array is the
3287 -- first component, but that's not such a simple case ???
3289 if Is_Packed (Ptyp) then
3293 -- We are in trouble if there is a component clause, and
3294 -- either we do not know the alignment of the slice, or
3295 -- the alignment of the slice is inconsistent with the
3296 -- bit position specified by the component clause.
3299 Field : constant Entity_Id := Entity (Selector_Name (Pref));
3301 if Present (Component_Clause (Field))
3303 (Unknown_Alignment (Styp)
3305 (Component_Bit_Offset (Field) mod
3306 (System_Storage_Unit * Alignment (Styp))) /= 0)
3312 -- For cases other than selected or indexed components we
3313 -- know we are OK, since no issues arise over alignment.
3319 -- We processed an indexed component or selected component
3320 -- reference that looked safe, so keep checking prefixes.
3322 Pref := Prefix (Pref);
3325 end Is_Possibly_Unaligned_Slice;
3327 --------------------------------
3328 -- Is_Ref_To_Bit_Packed_Array --
3329 --------------------------------
3331 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean is
3336 if Is_Entity_Name (N)
3337 and then Is_Object (Entity (N))
3338 and then Present (Renamed_Object (Entity (N)))
3340 return Is_Ref_To_Bit_Packed_Array (Renamed_Object (Entity (N)));
3343 if Nkind (N) = N_Indexed_Component
3345 Nkind (N) = N_Selected_Component
3347 if Is_Bit_Packed_Array (Etype (Prefix (N))) then
3350 Result := Is_Ref_To_Bit_Packed_Array (Prefix (N));
3353 if Result and then Nkind (N) = N_Indexed_Component then
3354 Expr := First (Expressions (N));
3355 while Present (Expr) loop
3356 Force_Evaluation (Expr);
3366 end Is_Ref_To_Bit_Packed_Array;
3368 --------------------------------
3369 -- Is_Ref_To_Bit_Packed_Slice --
3370 --------------------------------
3372 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean is
3374 if Nkind (N) = N_Type_Conversion then
3375 return Is_Ref_To_Bit_Packed_Slice (Expression (N));
3377 elsif Is_Entity_Name (N)
3378 and then Is_Object (Entity (N))
3379 and then Present (Renamed_Object (Entity (N)))
3381 return Is_Ref_To_Bit_Packed_Slice (Renamed_Object (Entity (N)));
3383 elsif Nkind (N) = N_Slice
3384 and then Is_Bit_Packed_Array (Etype (Prefix (N)))
3388 elsif Nkind (N) = N_Indexed_Component
3390 Nkind (N) = N_Selected_Component
3392 return Is_Ref_To_Bit_Packed_Slice (Prefix (N));
3397 end Is_Ref_To_Bit_Packed_Slice;
3399 -----------------------
3400 -- Is_Renamed_Object --
3401 -----------------------
3403 function Is_Renamed_Object (N : Node_Id) return Boolean is
3404 Pnod : constant Node_Id := Parent (N);
3405 Kind : constant Node_Kind := Nkind (Pnod);
3407 if Kind = N_Object_Renaming_Declaration then
3409 elsif Nkind_In (Kind, N_Indexed_Component, N_Selected_Component) then
3410 return Is_Renamed_Object (Pnod);
3414 end Is_Renamed_Object;
3416 ----------------------------
3417 -- Is_Untagged_Derivation --
3418 ----------------------------
3420 function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
3422 return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
3424 (Is_Private_Type (T) and then Present (Full_View (T))
3425 and then not Is_Tagged_Type (Full_View (T))
3426 and then Is_Derived_Type (Full_View (T))
3427 and then Etype (Full_View (T)) /= T);
3428 end Is_Untagged_Derivation;
3430 ---------------------------
3431 -- Is_Volatile_Reference --
3432 ---------------------------
3434 function Is_Volatile_Reference (N : Node_Id) return Boolean is
3436 if Nkind (N) in N_Has_Etype
3437 and then Present (Etype (N))
3438 and then Treat_As_Volatile (Etype (N))
3442 elsif Is_Entity_Name (N) then
3443 return Treat_As_Volatile (Entity (N));
3445 elsif Nkind (N) = N_Slice then
3446 return Is_Volatile_Reference (Prefix (N));
3448 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
3449 if (Is_Entity_Name (Prefix (N))
3450 and then Has_Volatile_Components (Entity (Prefix (N))))
3451 or else (Present (Etype (Prefix (N)))
3452 and then Has_Volatile_Components (Etype (Prefix (N))))
3456 return Is_Volatile_Reference (Prefix (N));
3462 end Is_Volatile_Reference;
3464 --------------------
3465 -- Kill_Dead_Code --
3466 --------------------
3468 procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False) is
3469 W : Boolean := Warn;
3470 -- Set False if warnings suppressed
3474 Remove_Warning_Messages (N);
3476 -- Generate warning if appropriate
3480 -- We suppress the warning if this code is under control of an
3481 -- if statement, whose condition is a simple identifier, and
3482 -- either we are in an instance, or warnings off is set for this
3483 -- identifier. The reason for killing it in the instance case is
3484 -- that it is common and reasonable for code to be deleted in
3485 -- instances for various reasons.
3487 if Nkind (Parent (N)) = N_If_Statement then
3489 C : constant Node_Id := Condition (Parent (N));
3491 if Nkind (C) = N_Identifier
3494 or else (Present (Entity (C))
3495 and then Has_Warnings_Off (Entity (C))))
3502 -- Generate warning if not suppressed
3506 ("?this code can never be executed and has been deleted!", N);
3510 -- Recurse into block statements and bodies to process declarations
3513 if Nkind (N) = N_Block_Statement
3514 or else Nkind (N) = N_Subprogram_Body
3515 or else Nkind (N) = N_Package_Body
3517 Kill_Dead_Code (Declarations (N), False);
3518 Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
3520 if Nkind (N) = N_Subprogram_Body then
3521 Set_Is_Eliminated (Defining_Entity (N));
3524 elsif Nkind (N) = N_Package_Declaration then
3525 Kill_Dead_Code (Visible_Declarations (Specification (N)));
3526 Kill_Dead_Code (Private_Declarations (Specification (N)));
3528 -- ??? After this point, Delete_Tree has been called on all
3529 -- declarations in Specification (N), so references to
3530 -- entities therein look suspicious.
3533 E : Entity_Id := First_Entity (Defining_Entity (N));
3535 while Present (E) loop
3536 if Ekind (E) = E_Operator then
3537 Set_Is_Eliminated (E);
3544 -- Recurse into composite statement to kill individual statements,
3545 -- in particular instantiations.
3547 elsif Nkind (N) = N_If_Statement then
3548 Kill_Dead_Code (Then_Statements (N));
3549 Kill_Dead_Code (Elsif_Parts (N));
3550 Kill_Dead_Code (Else_Statements (N));
3552 elsif Nkind (N) = N_Loop_Statement then
3553 Kill_Dead_Code (Statements (N));
3555 elsif Nkind (N) = N_Case_Statement then
3559 Alt := First (Alternatives (N));
3560 while Present (Alt) loop
3561 Kill_Dead_Code (Statements (Alt));
3566 elsif Nkind (N) = N_Case_Statement_Alternative then
3567 Kill_Dead_Code (Statements (N));
3569 -- Deal with dead instances caused by deleting instantiations
3571 elsif Nkind (N) in N_Generic_Instantiation then
3572 Remove_Dead_Instance (N);
3577 -- Case where argument is a list of nodes to be killed
3579 procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False) is
3584 if Is_Non_Empty_List (L) then
3586 while Present (N) loop
3587 Kill_Dead_Code (N, W);
3594 ------------------------
3595 -- Known_Non_Negative --
3596 ------------------------
3598 function Known_Non_Negative (Opnd : Node_Id) return Boolean is
3600 if Is_OK_Static_Expression (Opnd)
3601 and then Expr_Value (Opnd) >= 0
3607 Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
3611 Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
3614 end Known_Non_Negative;
3616 --------------------
3617 -- Known_Non_Null --
3618 --------------------
3620 function Known_Non_Null (N : Node_Id) return Boolean is
3622 -- Checks for case where N is an entity reference
3624 if Is_Entity_Name (N) and then Present (Entity (N)) then
3626 E : constant Entity_Id := Entity (N);
3631 -- First check if we are in decisive conditional
3633 Get_Current_Value_Condition (N, Op, Val);
3635 if Known_Null (Val) then
3636 if Op = N_Op_Eq then
3638 elsif Op = N_Op_Ne then
3643 -- If OK to do replacement, test Is_Known_Non_Null flag
3645 if OK_To_Do_Constant_Replacement (E) then
3646 return Is_Known_Non_Null (E);
3648 -- Otherwise if not safe to do replacement, then say so
3655 -- True if access attribute
3657 elsif Nkind (N) = N_Attribute_Reference
3658 and then (Attribute_Name (N) = Name_Access
3660 Attribute_Name (N) = Name_Unchecked_Access
3662 Attribute_Name (N) = Name_Unrestricted_Access)
3666 -- True if allocator
3668 elsif Nkind (N) = N_Allocator then
3671 -- For a conversion, true if expression is known non-null
3673 elsif Nkind (N) = N_Type_Conversion then
3674 return Known_Non_Null (Expression (N));
3676 -- Above are all cases where the value could be determined to be
3677 -- non-null. In all other cases, we don't know, so return False.
3688 function Known_Null (N : Node_Id) return Boolean is
3690 -- Checks for case where N is an entity reference
3692 if Is_Entity_Name (N) and then Present (Entity (N)) then
3694 E : constant Entity_Id := Entity (N);
3699 -- Constant null value is for sure null
3701 if Ekind (E) = E_Constant
3702 and then Known_Null (Constant_Value (E))
3707 -- First check if we are in decisive conditional
3709 Get_Current_Value_Condition (N, Op, Val);
3711 if Known_Null (Val) then
3712 if Op = N_Op_Eq then
3714 elsif Op = N_Op_Ne then
3719 -- If OK to do replacement, test Is_Known_Null flag
3721 if OK_To_Do_Constant_Replacement (E) then
3722 return Is_Known_Null (E);
3724 -- Otherwise if not safe to do replacement, then say so
3731 -- True if explicit reference to null
3733 elsif Nkind (N) = N_Null then
3736 -- For a conversion, true if expression is known null
3738 elsif Nkind (N) = N_Type_Conversion then
3739 return Known_Null (Expression (N));
3741 -- Above are all cases where the value could be determined to be null.
3742 -- In all other cases, we don't know, so return False.
3749 -----------------------------
3750 -- Make_CW_Equivalent_Type --
3751 -----------------------------
3753 -- Create a record type used as an equivalent of any member of the class
3754 -- which takes its size from exp.
3756 -- Generate the following code:
3758 -- type Equiv_T is record
3759 -- _parent : T (List of discriminant constraints taken from Exp);
3760 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
3763 -- ??? Note that this type does not guarantee same alignment as all
3766 function Make_CW_Equivalent_Type
3768 E : Node_Id) return Entity_Id
3770 Loc : constant Source_Ptr := Sloc (E);
3771 Root_Typ : constant Entity_Id := Root_Type (T);
3772 List_Def : constant List_Id := Empty_List;
3773 Comp_List : constant List_Id := New_List;
3774 Equiv_Type : Entity_Id;
3775 Range_Type : Entity_Id;
3776 Str_Type : Entity_Id;
3777 Constr_Root : Entity_Id;
3781 -- If the root type is already constrained, there are no discriminants
3782 -- in the expression.
3784 if not Has_Discriminants (Root_Typ)
3785 or else Is_Constrained (Root_Typ)
3787 Constr_Root := Root_Typ;
3789 Constr_Root := Make_Temporary (Loc, 'R');
3791 -- subtype cstr__n is T (List of discr constraints taken from Exp)
3793 Append_To (List_Def,
3794 Make_Subtype_Declaration (Loc,
3795 Defining_Identifier => Constr_Root,
3796 Subtype_Indication => Make_Subtype_From_Expr (E, Root_Typ)));
3799 -- Generate the range subtype declaration
3801 Range_Type := Make_Temporary (Loc, 'G');
3803 if not Is_Interface (Root_Typ) then
3805 -- subtype rg__xx is
3806 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
3809 Make_Op_Subtract (Loc,
3811 Make_Attribute_Reference (Loc,
3813 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
3814 Attribute_Name => Name_Size),
3816 Make_Attribute_Reference (Loc,
3817 Prefix => New_Reference_To (Constr_Root, Loc),
3818 Attribute_Name => Name_Object_Size));
3820 -- subtype rg__xx is
3821 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
3824 Make_Attribute_Reference (Loc,
3826 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
3827 Attribute_Name => Name_Size);
3830 Set_Paren_Count (Sizexpr, 1);
3832 Append_To (List_Def,
3833 Make_Subtype_Declaration (Loc,
3834 Defining_Identifier => Range_Type,
3835 Subtype_Indication =>
3836 Make_Subtype_Indication (Loc,
3837 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
3838 Constraint => Make_Range_Constraint (Loc,
3841 Low_Bound => Make_Integer_Literal (Loc, 1),
3843 Make_Op_Divide (Loc,
3844 Left_Opnd => Sizexpr,
3845 Right_Opnd => Make_Integer_Literal (Loc,
3846 Intval => System_Storage_Unit)))))));
3848 -- subtype str__nn is Storage_Array (rg__x);
3850 Str_Type := Make_Temporary (Loc, 'S');
3851 Append_To (List_Def,
3852 Make_Subtype_Declaration (Loc,
3853 Defining_Identifier => Str_Type,
3854 Subtype_Indication =>
3855 Make_Subtype_Indication (Loc,
3856 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
3858 Make_Index_Or_Discriminant_Constraint (Loc,
3860 New_List (New_Reference_To (Range_Type, Loc))))));
3862 -- type Equiv_T is record
3863 -- [ _parent : Tnn; ]
3867 Equiv_Type := Make_Temporary (Loc, 'T');
3868 Set_Ekind (Equiv_Type, E_Record_Type);
3869 Set_Parent_Subtype (Equiv_Type, Constr_Root);
3871 -- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
3872 -- treatment for this type. In particular, even though _parent's type
3873 -- is a controlled type or contains controlled components, we do not
3874 -- want to set Has_Controlled_Component on it to avoid making it gain
3875 -- an unwanted _controller component.
3877 Set_Is_Class_Wide_Equivalent_Type (Equiv_Type);
3879 if not Is_Interface (Root_Typ) then
3880 Append_To (Comp_List,
3881 Make_Component_Declaration (Loc,
3882 Defining_Identifier =>
3883 Make_Defining_Identifier (Loc, Name_uParent),
3884 Component_Definition =>
3885 Make_Component_Definition (Loc,
3886 Aliased_Present => False,
3887 Subtype_Indication => New_Reference_To (Constr_Root, Loc))));
3890 Append_To (Comp_List,
3891 Make_Component_Declaration (Loc,
3892 Defining_Identifier => Make_Temporary (Loc, 'C'),
3893 Component_Definition =>
3894 Make_Component_Definition (Loc,
3895 Aliased_Present => False,
3896 Subtype_Indication => New_Reference_To (Str_Type, Loc))));
3898 Append_To (List_Def,
3899 Make_Full_Type_Declaration (Loc,
3900 Defining_Identifier => Equiv_Type,
3902 Make_Record_Definition (Loc,
3904 Make_Component_List (Loc,
3905 Component_Items => Comp_List,
3906 Variant_Part => Empty))));
3908 -- Suppress all checks during the analysis of the expanded code
3909 -- to avoid the generation of spurious warnings under ZFP run-time.
3911 Insert_Actions (E, List_Def, Suppress => All_Checks);
3913 end Make_CW_Equivalent_Type;
3915 ------------------------
3916 -- Make_Literal_Range --
3917 ------------------------
3919 function Make_Literal_Range
3921 Literal_Typ : Entity_Id) return Node_Id
3923 Lo : constant Node_Id :=
3924 New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
3925 Index : constant Entity_Id := Etype (Lo);
3928 Length_Expr : constant Node_Id :=
3929 Make_Op_Subtract (Loc,
3931 Make_Integer_Literal (Loc,
3932 Intval => String_Literal_Length (Literal_Typ)),
3934 Make_Integer_Literal (Loc, 1));
3937 Set_Analyzed (Lo, False);
3939 if Is_Integer_Type (Index) then
3942 Left_Opnd => New_Copy_Tree (Lo),
3943 Right_Opnd => Length_Expr);
3946 Make_Attribute_Reference (Loc,
3947 Attribute_Name => Name_Val,
3948 Prefix => New_Occurrence_Of (Index, Loc),
3949 Expressions => New_List (
3952 Make_Attribute_Reference (Loc,
3953 Attribute_Name => Name_Pos,
3954 Prefix => New_Occurrence_Of (Index, Loc),
3955 Expressions => New_List (New_Copy_Tree (Lo))),
3956 Right_Opnd => Length_Expr)));
3963 end Make_Literal_Range;
3965 --------------------------
3966 -- Make_Non_Empty_Check --
3967 --------------------------
3969 function Make_Non_Empty_Check
3971 N : Node_Id) return Node_Id
3977 Make_Attribute_Reference (Loc,
3978 Attribute_Name => Name_Length,
3979 Prefix => Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
3981 Make_Integer_Literal (Loc, 0));
3982 end Make_Non_Empty_Check;
3984 ----------------------------
3985 -- Make_Subtype_From_Expr --
3986 ----------------------------
3988 -- 1. If Expr is an unconstrained array expression, creates
3989 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
3991 -- 2. If Expr is a unconstrained discriminated type expression, creates
3992 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
3994 -- 3. If Expr is class-wide, creates an implicit class wide subtype
3996 function Make_Subtype_From_Expr
3998 Unc_Typ : Entity_Id) return Node_Id
4000 Loc : constant Source_Ptr := Sloc (E);
4001 List_Constr : constant List_Id := New_List;
4004 Full_Subtyp : Entity_Id;
4005 Priv_Subtyp : Entity_Id;
4010 if Is_Private_Type (Unc_Typ)
4011 and then Has_Unknown_Discriminants (Unc_Typ)
4013 -- Prepare the subtype completion, Go to base type to
4014 -- find underlying type, because the type may be a generic
4015 -- actual or an explicit subtype.
4017 Utyp := Underlying_Type (Base_Type (Unc_Typ));
4018 Full_Subtyp := Make_Temporary (Loc, 'C');
4020 Unchecked_Convert_To (Utyp, Duplicate_Subexpr_No_Checks (E));
4021 Set_Parent (Full_Exp, Parent (E));
4023 Priv_Subtyp := Make_Temporary (Loc, 'P');
4026 Make_Subtype_Declaration (Loc,
4027 Defining_Identifier => Full_Subtyp,
4028 Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
4030 -- Define the dummy private subtype
4032 Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
4033 Set_Etype (Priv_Subtyp, Base_Type (Unc_Typ));
4034 Set_Scope (Priv_Subtyp, Full_Subtyp);
4035 Set_Is_Constrained (Priv_Subtyp);
4036 Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
4037 Set_Is_Itype (Priv_Subtyp);
4038 Set_Associated_Node_For_Itype (Priv_Subtyp, E);
4040 if Is_Tagged_Type (Priv_Subtyp) then
4042 (Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
4043 Set_Primitive_Operations (Priv_Subtyp,
4044 Primitive_Operations (Unc_Typ));
4047 Set_Full_View (Priv_Subtyp, Full_Subtyp);
4049 return New_Reference_To (Priv_Subtyp, Loc);
4051 elsif Is_Array_Type (Unc_Typ) then
4052 for J in 1 .. Number_Dimensions (Unc_Typ) loop
4053 Append_To (List_Constr,
4056 Make_Attribute_Reference (Loc,
4057 Prefix => Duplicate_Subexpr_No_Checks (E),
4058 Attribute_Name => Name_First,
4059 Expressions => New_List (
4060 Make_Integer_Literal (Loc, J))),
4063 Make_Attribute_Reference (Loc,
4064 Prefix => Duplicate_Subexpr_No_Checks (E),
4065 Attribute_Name => Name_Last,
4066 Expressions => New_List (
4067 Make_Integer_Literal (Loc, J)))));
4070 elsif Is_Class_Wide_Type (Unc_Typ) then
4072 CW_Subtype : Entity_Id;
4073 EQ_Typ : Entity_Id := Empty;
4076 -- A class-wide equivalent type is not needed when VM_Target
4077 -- because the VM back-ends handle the class-wide object
4078 -- initialization itself (and doesn't need or want the
4079 -- additional intermediate type to handle the assignment).
4081 if Expander_Active and then Tagged_Type_Expansion then
4083 -- If this is the class_wide type of a completion that is
4084 -- a record subtype, set the type of the class_wide type
4085 -- to be the full base type, for use in the expanded code
4086 -- for the equivalent type. Should this be done earlier when
4087 -- the completion is analyzed ???
4089 if Is_Private_Type (Etype (Unc_Typ))
4091 Ekind (Full_View (Etype (Unc_Typ))) = E_Record_Subtype
4093 Set_Etype (Unc_Typ, Base_Type (Full_View (Etype (Unc_Typ))));
4096 EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
4099 CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
4100 Set_Equivalent_Type (CW_Subtype, EQ_Typ);
4101 Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
4103 return New_Occurrence_Of (CW_Subtype, Loc);
4106 -- Indefinite record type with discriminants
4109 D := First_Discriminant (Unc_Typ);
4110 while Present (D) loop
4111 Append_To (List_Constr,
4112 Make_Selected_Component (Loc,
4113 Prefix => Duplicate_Subexpr_No_Checks (E),
4114 Selector_Name => New_Reference_To (D, Loc)));
4116 Next_Discriminant (D);
4121 Make_Subtype_Indication (Loc,
4122 Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
4124 Make_Index_Or_Discriminant_Constraint (Loc,
4125 Constraints => List_Constr));
4126 end Make_Subtype_From_Expr;
4128 -----------------------------
4129 -- May_Generate_Large_Temp --
4130 -----------------------------
4132 -- At the current time, the only types that we return False for (i.e.
4133 -- where we decide we know they cannot generate large temps) are ones
4134 -- where we know the size is 256 bits or less at compile time, and we
4135 -- are still not doing a thorough job on arrays and records ???
4137 function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
4139 if not Size_Known_At_Compile_Time (Typ) then
4142 elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
4145 elsif Is_Array_Type (Typ)
4146 and then Present (Packed_Array_Type (Typ))
4148 return May_Generate_Large_Temp (Packed_Array_Type (Typ));
4150 -- We could do more here to find other small types ???
4155 end May_Generate_Large_Temp;
4157 ----------------------------
4158 -- New_Class_Wide_Subtype --
4159 ----------------------------
4161 function New_Class_Wide_Subtype
4162 (CW_Typ : Entity_Id;
4163 N : Node_Id) return Entity_Id
4165 Res : constant Entity_Id := Create_Itype (E_Void, N);
4166 Res_Name : constant Name_Id := Chars (Res);
4167 Res_Scope : constant Entity_Id := Scope (Res);
4170 Copy_Node (CW_Typ, Res);
4171 Set_Comes_From_Source (Res, False);
4172 Set_Sloc (Res, Sloc (N));
4174 Set_Associated_Node_For_Itype (Res, N);
4175 Set_Is_Public (Res, False); -- By default, may be changed below.
4176 Set_Public_Status (Res);
4177 Set_Chars (Res, Res_Name);
4178 Set_Scope (Res, Res_Scope);
4179 Set_Ekind (Res, E_Class_Wide_Subtype);
4180 Set_Next_Entity (Res, Empty);
4181 Set_Etype (Res, Base_Type (CW_Typ));
4182 Set_Is_Frozen (Res, False);
4183 Set_Freeze_Node (Res, Empty);
4185 end New_Class_Wide_Subtype;
4187 --------------------------------
4188 -- Non_Limited_Designated_Type --
4189 ---------------------------------
4191 function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id is
4192 Desig : constant Entity_Id := Designated_Type (T);
4194 if Ekind (Desig) = E_Incomplete_Type
4195 and then Present (Non_Limited_View (Desig))
4197 return Non_Limited_View (Desig);
4201 end Non_Limited_Designated_Type;
4203 -----------------------------------
4204 -- OK_To_Do_Constant_Replacement --
4205 -----------------------------------
4207 function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean is
4208 ES : constant Entity_Id := Scope (E);
4212 -- Do not replace statically allocated objects, because they may be
4213 -- modified outside the current scope.
4215 if Is_Statically_Allocated (E) then
4218 -- Do not replace aliased or volatile objects, since we don't know what
4219 -- else might change the value.
4221 elsif Is_Aliased (E) or else Treat_As_Volatile (E) then
4224 -- Debug flag -gnatdM disconnects this optimization
4226 elsif Debug_Flag_MM then
4229 -- Otherwise check scopes
4232 CS := Current_Scope;
4235 -- If we are in right scope, replacement is safe
4240 -- Packages do not affect the determination of safety
4242 elsif Ekind (CS) = E_Package then
4243 exit when CS = Standard_Standard;
4246 -- Blocks do not affect the determination of safety
4248 elsif Ekind (CS) = E_Block then
4251 -- Loops do not affect the determination of safety. Note that we
4252 -- kill all current values on entry to a loop, so we are just
4253 -- talking about processing within a loop here.
4255 elsif Ekind (CS) = E_Loop then
4258 -- Otherwise, the reference is dubious, and we cannot be sure that
4259 -- it is safe to do the replacement.
4268 end OK_To_Do_Constant_Replacement;
4270 ------------------------------------
4271 -- Possible_Bit_Aligned_Component --
4272 ------------------------------------
4274 function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean is
4278 -- Case of indexed component
4280 when N_Indexed_Component =>
4282 P : constant Node_Id := Prefix (N);
4283 Ptyp : constant Entity_Id := Etype (P);
4286 -- If we know the component size and it is less than 64, then
4287 -- we are definitely OK. The back end always does assignment of
4288 -- misaligned small objects correctly.
4290 if Known_Static_Component_Size (Ptyp)
4291 and then Component_Size (Ptyp) <= 64
4295 -- Otherwise, we need to test the prefix, to see if we are
4296 -- indexing from a possibly unaligned component.
4299 return Possible_Bit_Aligned_Component (P);
4303 -- Case of selected component
4305 when N_Selected_Component =>
4307 P : constant Node_Id := Prefix (N);
4308 Comp : constant Entity_Id := Entity (Selector_Name (N));
4311 -- If there is no component clause, then we are in the clear
4312 -- since the back end will never misalign a large component
4313 -- unless it is forced to do so. In the clear means we need
4314 -- only the recursive test on the prefix.
4316 if Component_May_Be_Bit_Aligned (Comp) then
4319 return Possible_Bit_Aligned_Component (P);
4323 -- For a slice, test the prefix, if that is possibly misaligned,
4324 -- then for sure the slice is!
4327 return Possible_Bit_Aligned_Component (Prefix (N));
4329 -- If we have none of the above, it means that we have fallen off the
4330 -- top testing prefixes recursively, and we now have a stand alone
4331 -- object, where we don't have a problem.
4337 end Possible_Bit_Aligned_Component;
4339 -------------------------
4340 -- Remove_Side_Effects --
4341 -------------------------
4343 procedure Remove_Side_Effects
4345 Name_Req : Boolean := False;
4346 Variable_Ref : Boolean := False)
4348 Loc : constant Source_Ptr := Sloc (Exp);
4349 Exp_Type : constant Entity_Id := Etype (Exp);
4350 Svg_Suppress : constant Suppress_Array := Scope_Suppress;
4352 Ref_Type : Entity_Id;
4354 Ptr_Typ_Decl : Node_Id;
4358 function Side_Effect_Free (N : Node_Id) return Boolean;
4359 -- Determines if the tree N represents an expression that is known not
4360 -- to have side effects, and for which no processing is required.
4362 function Side_Effect_Free (L : List_Id) return Boolean;
4363 -- Determines if all elements of the list L are side effect free
4365 function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
4366 -- The argument N is a construct where the Prefix is dereferenced if it
4367 -- is an access type and the result is a variable. The call returns True
4368 -- if the construct is side effect free (not considering side effects in
4369 -- other than the prefix which are to be tested by the caller).
4371 function Within_In_Parameter (N : Node_Id) return Boolean;
4372 -- Determines if N is a subcomponent of a composite in-parameter. If so,
4373 -- N is not side-effect free when the actual is global and modifiable
4374 -- indirectly from within a subprogram, because it may be passed by
4375 -- reference. The front-end must be conservative here and assume that
4376 -- this may happen with any array or record type. On the other hand, we
4377 -- cannot create temporaries for all expressions for which this
4378 -- condition is true, for various reasons that might require clearing up
4379 -- ??? For example, discriminant references that appear out of place, or
4380 -- spurious type errors with class-wide expressions. As a result, we
4381 -- limit the transformation to loop bounds, which is so far the only
4382 -- case that requires it.
4384 -----------------------------
4385 -- Safe_Prefixed_Reference --
4386 -----------------------------
4388 function Safe_Prefixed_Reference (N : Node_Id) return Boolean is
4390 -- If prefix is not side effect free, definitely not safe
4392 if not Side_Effect_Free (Prefix (N)) then
4395 -- If the prefix is of an access type that is not access-to-constant,
4396 -- then this construct is a variable reference, which means it is to
4397 -- be considered to have side effects if Variable_Ref is set True
4398 -- Exception is an access to an entity that is a constant or an
4399 -- in-parameter which does not come from source, and is the result
4400 -- of a previous removal of side-effects.
4402 elsif Is_Access_Type (Etype (Prefix (N)))
4403 and then not Is_Access_Constant (Etype (Prefix (N)))
4404 and then Variable_Ref
4406 if not Is_Entity_Name (Prefix (N)) then
4409 return Ekind (Entity (Prefix (N))) = E_Constant
4410 or else Ekind (Entity (Prefix (N))) = E_In_Parameter;
4413 -- The following test is the simplest way of solving a complex
4414 -- problem uncovered by BB08-010: Side effect on loop bound that
4415 -- is a subcomponent of a global variable:
4416 -- If a loop bound is a subcomponent of a global variable, a
4417 -- modification of that variable within the loop may incorrectly
4418 -- affect the execution of the loop.
4421 (Nkind (Parent (Parent (N))) /= N_Loop_Parameter_Specification
4422 or else not Within_In_Parameter (Prefix (N)))
4426 -- All other cases are side effect free
4431 end Safe_Prefixed_Reference;
4433 ----------------------
4434 -- Side_Effect_Free --
4435 ----------------------
4437 function Side_Effect_Free (N : Node_Id) return Boolean is
4439 -- Note on checks that could raise Constraint_Error. Strictly, if
4440 -- we take advantage of 11.6, these checks do not count as side
4441 -- effects. However, we would just as soon consider that they are
4442 -- side effects, since the backend CSE does not work very well on
4443 -- expressions which can raise Constraint_Error. On the other
4444 -- hand, if we do not consider them to be side effect free, then
4445 -- we get some awkward expansions in -gnato mode, resulting in
4446 -- code insertions at a point where we do not have a clear model
4447 -- for performing the insertions.
4449 -- Special handling for entity names
4451 if Is_Entity_Name (N) then
4453 -- If the entity is a constant, it is definitely side effect
4454 -- free. Note that the test of Is_Variable (N) below might
4455 -- be expected to catch this case, but it does not, because
4456 -- this test goes to the original tree, and we may have
4457 -- already rewritten a variable node with a constant as
4458 -- a result of an earlier Force_Evaluation call.
4460 if Ekind_In (Entity (N), E_Constant, E_In_Parameter) then
4463 -- Functions are not side effect free
4465 elsif Ekind (Entity (N)) = E_Function then
4468 -- Variables are considered to be a side effect if Variable_Ref
4469 -- is set or if we have a volatile reference and Name_Req is off.
4470 -- If Name_Req is True then we can't help returning a name which
4471 -- effectively allows multiple references in any case.
4473 elsif Is_Variable (N) then
4474 return not Variable_Ref
4475 and then (not Is_Volatile_Reference (N) or else Name_Req);
4477 -- Any other entity (e.g. a subtype name) is definitely side
4484 -- A value known at compile time is always side effect free
4486 elsif Compile_Time_Known_Value (N) then
4489 -- A variable renaming is not side-effect free, because the
4490 -- renaming will function like a macro in the front-end in
4491 -- some cases, and an assignment can modify the component
4492 -- designated by N, so we need to create a temporary for it.
4494 elsif Is_Entity_Name (Original_Node (N))
4495 and then Is_Renaming_Of_Object (Entity (Original_Node (N)))
4496 and then Ekind (Entity (Original_Node (N))) /= E_Constant
4501 -- For other than entity names and compile time known values,
4502 -- check the node kind for special processing.
4506 -- An attribute reference is side effect free if its expressions
4507 -- are side effect free and its prefix is side effect free or
4508 -- is an entity reference.
4510 -- Is this right? what about x'first where x is a variable???
4512 when N_Attribute_Reference =>
4513 return Side_Effect_Free (Expressions (N))
4514 and then Attribute_Name (N) /= Name_Input
4515 and then (Is_Entity_Name (Prefix (N))
4516 or else Side_Effect_Free (Prefix (N)));
4518 -- A binary operator is side effect free if and both operands
4519 -- are side effect free. For this purpose binary operators
4520 -- include membership tests and short circuit forms
4522 when N_Binary_Op | N_Membership_Test | N_Short_Circuit =>
4523 return Side_Effect_Free (Left_Opnd (N))
4525 Side_Effect_Free (Right_Opnd (N));
4527 -- An explicit dereference is side effect free only if it is
4528 -- a side effect free prefixed reference.
4530 when N_Explicit_Dereference =>
4531 return Safe_Prefixed_Reference (N);
4533 -- A call to _rep_to_pos is side effect free, since we generate
4534 -- this pure function call ourselves. Moreover it is critically
4535 -- important to make this exception, since otherwise we can
4536 -- have discriminants in array components which don't look
4537 -- side effect free in the case of an array whose index type
4538 -- is an enumeration type with an enumeration rep clause.
4540 -- All other function calls are not side effect free
4542 when N_Function_Call =>
4543 return Nkind (Name (N)) = N_Identifier
4544 and then Is_TSS (Name (N), TSS_Rep_To_Pos)
4546 Side_Effect_Free (First (Parameter_Associations (N)));
4548 -- An indexed component is side effect free if it is a side
4549 -- effect free prefixed reference and all the indexing
4550 -- expressions are side effect free.
4552 when N_Indexed_Component =>
4553 return Side_Effect_Free (Expressions (N))
4554 and then Safe_Prefixed_Reference (N);
4556 -- A type qualification is side effect free if the expression
4557 -- is side effect free.
4559 when N_Qualified_Expression =>
4560 return Side_Effect_Free (Expression (N));
4562 -- A selected component is side effect free only if it is a
4563 -- side effect free prefixed reference. If it designates a
4564 -- component with a rep. clause it must be treated has having
4565 -- a potential side effect, because it may be modified through
4566 -- a renaming, and a subsequent use of the renaming as a macro
4567 -- will yield the wrong value. This complex interaction between
4568 -- renaming and removing side effects is a reminder that the
4569 -- latter has become a headache to maintain, and that it should
4570 -- be removed in favor of the gcc mechanism to capture values ???
4572 when N_Selected_Component =>
4573 if Nkind (Parent (N)) = N_Explicit_Dereference
4574 and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
4578 return Safe_Prefixed_Reference (N);
4581 -- A range is side effect free if the bounds are side effect free
4584 return Side_Effect_Free (Low_Bound (N))
4585 and then Side_Effect_Free (High_Bound (N));
4587 -- A slice is side effect free if it is a side effect free
4588 -- prefixed reference and the bounds are side effect free.
4591 return Side_Effect_Free (Discrete_Range (N))
4592 and then Safe_Prefixed_Reference (N);
4594 -- A type conversion is side effect free if the expression to be
4595 -- converted is side effect free.
4597 when N_Type_Conversion =>
4598 return Side_Effect_Free (Expression (N));
4600 -- A unary operator is side effect free if the operand
4601 -- is side effect free.
4604 return Side_Effect_Free (Right_Opnd (N));
4606 -- An unchecked type conversion is side effect free only if it
4607 -- is safe and its argument is side effect free.
4609 when N_Unchecked_Type_Conversion =>
4610 return Safe_Unchecked_Type_Conversion (N)
4611 and then Side_Effect_Free (Expression (N));
4613 -- An unchecked expression is side effect free if its expression
4614 -- is side effect free.
4616 when N_Unchecked_Expression =>
4617 return Side_Effect_Free (Expression (N));
4619 -- A literal is side effect free
4621 when N_Character_Literal |
4627 -- We consider that anything else has side effects. This is a bit
4628 -- crude, but we are pretty close for most common cases, and we
4629 -- are certainly correct (i.e. we never return True when the
4630 -- answer should be False).
4635 end Side_Effect_Free;
4637 -- A list is side effect free if all elements of the list are
4638 -- side effect free.
4640 function Side_Effect_Free (L : List_Id) return Boolean is
4644 if L = No_List or else L = Error_List then
4649 while Present (N) loop
4650 if not Side_Effect_Free (N) then
4659 end Side_Effect_Free;
4661 -------------------------
4662 -- Within_In_Parameter --
4663 -------------------------
4665 function Within_In_Parameter (N : Node_Id) return Boolean is
4667 if not Comes_From_Source (N) then
4670 elsif Is_Entity_Name (N) then
4671 return Ekind (Entity (N)) = E_In_Parameter;
4673 elsif Nkind (N) = N_Indexed_Component
4674 or else Nkind (N) = N_Selected_Component
4676 return Within_In_Parameter (Prefix (N));
4681 end Within_In_Parameter;
4683 -- Start of processing for Remove_Side_Effects
4686 -- If we are side effect free already or expansion is disabled,
4687 -- there is nothing to do.
4689 if Side_Effect_Free (Exp) or else not Expander_Active then
4693 -- All this must not have any checks
4695 Scope_Suppress := (others => True);
4697 -- If it is a scalar type and we need to capture the value, just make
4698 -- a copy. Likewise for a function call, an attribute reference, an
4699 -- allocator, or an operator. And if we have a volatile reference and
4700 -- Name_Req is not set (see comments above for Side_Effect_Free).
4702 if Is_Elementary_Type (Exp_Type)
4703 and then (Variable_Ref
4704 or else Nkind (Exp) = N_Function_Call
4705 or else Nkind (Exp) = N_Attribute_Reference
4706 or else Nkind (Exp) = N_Allocator
4707 or else Nkind (Exp) in N_Op
4708 or else (not Name_Req and then Is_Volatile_Reference (Exp)))
4710 Def_Id := Make_Temporary (Loc, 'R', Exp);
4711 Set_Etype (Def_Id, Exp_Type);
4712 Res := New_Reference_To (Def_Id, Loc);
4715 Make_Object_Declaration (Loc,
4716 Defining_Identifier => Def_Id,
4717 Object_Definition => New_Reference_To (Exp_Type, Loc),
4718 Constant_Present => True,
4719 Expression => Relocate_Node (Exp));
4721 -- Check if the previous node relocation requires readjustment of
4722 -- some SCIL Dispatching node.
4725 and then Nkind (Exp) = N_Function_Call
4727 Adjust_SCIL_Node (Exp, Expression (E));
4730 Set_Assignment_OK (E);
4731 Insert_Action (Exp, E);
4733 -- If the expression has the form v.all then we can just capture
4734 -- the pointer, and then do an explicit dereference on the result.
4736 elsif Nkind (Exp) = N_Explicit_Dereference then
4737 Def_Id := Make_Temporary (Loc, 'R', Exp);
4739 Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
4742 Make_Object_Declaration (Loc,
4743 Defining_Identifier => Def_Id,
4744 Object_Definition =>
4745 New_Reference_To (Etype (Prefix (Exp)), Loc),
4746 Constant_Present => True,
4747 Expression => Relocate_Node (Prefix (Exp))));
4749 -- Similar processing for an unchecked conversion of an expression
4750 -- of the form v.all, where we want the same kind of treatment.
4752 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
4753 and then Nkind (Expression (Exp)) = N_Explicit_Dereference
4755 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
4756 Scope_Suppress := Svg_Suppress;
4759 -- If this is a type conversion, leave the type conversion and remove
4760 -- the side effects in the expression. This is important in several
4761 -- circumstances: for change of representations, and also when this is
4762 -- a view conversion to a smaller object, where gigi can end up creating
4763 -- its own temporary of the wrong size.
4765 elsif Nkind (Exp) = N_Type_Conversion then
4766 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
4767 Scope_Suppress := Svg_Suppress;
4770 -- If this is an unchecked conversion that Gigi can't handle, make
4771 -- a copy or a use a renaming to capture the value.
4773 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
4774 and then not Safe_Unchecked_Type_Conversion (Exp)
4776 if CW_Or_Has_Controlled_Part (Exp_Type) then
4778 -- Use a renaming to capture the expression, rather than create
4779 -- a controlled temporary.
4781 Def_Id := Make_Temporary (Loc, 'R', Exp);
4782 Res := New_Reference_To (Def_Id, Loc);
4785 Make_Object_Renaming_Declaration (Loc,
4786 Defining_Identifier => Def_Id,
4787 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
4788 Name => Relocate_Node (Exp)));
4791 Def_Id := Make_Temporary (Loc, 'R', Exp);
4792 Set_Etype (Def_Id, Exp_Type);
4793 Res := New_Reference_To (Def_Id, Loc);
4796 Make_Object_Declaration (Loc,
4797 Defining_Identifier => Def_Id,
4798 Object_Definition => New_Reference_To (Exp_Type, Loc),
4799 Constant_Present => not Is_Variable (Exp),
4800 Expression => Relocate_Node (Exp));
4802 Set_Assignment_OK (E);
4803 Insert_Action (Exp, E);
4806 -- For expressions that denote objects, we can use a renaming scheme.
4807 -- We skip using this if we have a volatile reference and we do not
4808 -- have Name_Req set true (see comments above for Side_Effect_Free).
4810 elsif Is_Object_Reference (Exp)
4811 and then Nkind (Exp) /= N_Function_Call
4812 and then (Name_Req or else not Is_Volatile_Reference (Exp))
4814 Def_Id := Make_Temporary (Loc, 'R', Exp);
4816 if Nkind (Exp) = N_Selected_Component
4817 and then Nkind (Prefix (Exp)) = N_Function_Call
4818 and then Is_Array_Type (Exp_Type)
4820 -- Avoid generating a variable-sized temporary, by generating
4821 -- the renaming declaration just for the function call. The
4822 -- transformation could be refined to apply only when the array
4823 -- component is constrained by a discriminant???
4826 Make_Selected_Component (Loc,
4827 Prefix => New_Occurrence_Of (Def_Id, Loc),
4828 Selector_Name => Selector_Name (Exp));
4831 Make_Object_Renaming_Declaration (Loc,
4832 Defining_Identifier => Def_Id,
4834 New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
4835 Name => Relocate_Node (Prefix (Exp))));
4838 Res := New_Reference_To (Def_Id, Loc);
4841 Make_Object_Renaming_Declaration (Loc,
4842 Defining_Identifier => Def_Id,
4843 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
4844 Name => Relocate_Node (Exp)));
4847 -- If this is a packed reference, or a selected component with a
4848 -- non-standard representation, a reference to the temporary will
4849 -- be replaced by a copy of the original expression (see
4850 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
4851 -- elaborated by gigi, and is of course not to be replaced in-line
4852 -- by the expression it renames, which would defeat the purpose of
4853 -- removing the side-effect.
4855 if (Nkind (Exp) = N_Selected_Component
4856 or else Nkind (Exp) = N_Indexed_Component)
4857 and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
4861 Set_Is_Renaming_Of_Object (Def_Id, False);
4864 -- Otherwise we generate a reference to the value
4867 -- Special processing for function calls that return a limited type.
4868 -- We need to build a declaration that will enable build-in-place
4869 -- expansion of the call. This is not done if the context is already
4870 -- an object declaration, to prevent infinite recursion.
4872 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
4873 -- to accommodate functions returning limited objects by reference.
4875 if Nkind (Exp) = N_Function_Call
4876 and then Is_Inherently_Limited_Type (Etype (Exp))
4877 and then Nkind (Parent (Exp)) /= N_Object_Declaration
4878 and then Ada_Version >= Ada_05
4881 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', Exp);
4886 Make_Object_Declaration (Loc,
4887 Defining_Identifier => Obj,
4888 Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
4889 Expression => Relocate_Node (Exp));
4891 -- Check if the previous node relocation requires readjustment
4892 -- of some SCIL Dispatching node.
4895 and then Nkind (Exp) = N_Function_Call
4897 Adjust_SCIL_Node (Exp, Expression (Decl));
4900 Insert_Action (Exp, Decl);
4901 Set_Etype (Obj, Exp_Type);
4902 Rewrite (Exp, New_Occurrence_Of (Obj, Loc));
4907 Ref_Type := Make_Temporary (Loc, 'A');
4910 Make_Full_Type_Declaration (Loc,
4911 Defining_Identifier => Ref_Type,
4913 Make_Access_To_Object_Definition (Loc,
4914 All_Present => True,
4915 Subtype_Indication =>
4916 New_Reference_To (Exp_Type, Loc)));
4919 Insert_Action (Exp, Ptr_Typ_Decl);
4921 Def_Id := Make_Temporary (Loc, 'R', Exp);
4922 Set_Etype (Def_Id, Exp_Type);
4925 Make_Explicit_Dereference (Loc,
4926 Prefix => New_Reference_To (Def_Id, Loc));
4928 if Nkind (E) = N_Explicit_Dereference then
4929 New_Exp := Relocate_Node (Prefix (E));
4931 E := Relocate_Node (E);
4932 New_Exp := Make_Reference (Loc, E);
4935 if Is_Delayed_Aggregate (E) then
4937 -- The expansion of nested aggregates is delayed until the
4938 -- enclosing aggregate is expanded. As aggregates are often
4939 -- qualified, the predicate applies to qualified expressions
4940 -- as well, indicating that the enclosing aggregate has not
4941 -- been expanded yet. At this point the aggregate is part of
4942 -- a stand-alone declaration, and must be fully expanded.
4944 if Nkind (E) = N_Qualified_Expression then
4945 Set_Expansion_Delayed (Expression (E), False);
4946 Set_Analyzed (Expression (E), False);
4948 Set_Expansion_Delayed (E, False);
4951 Set_Analyzed (E, False);
4955 Make_Object_Declaration (Loc,
4956 Defining_Identifier => Def_Id,
4957 Object_Definition => New_Reference_To (Ref_Type, Loc),
4958 Expression => New_Exp));
4960 -- Check if the previous node relocation requires readjustment
4961 -- of some SCIL Dispatching node.
4964 and then Nkind (Exp) = N_Function_Call
4966 Adjust_SCIL_Node (Exp, Prefix (New_Exp));
4970 -- Preserve the Assignment_OK flag in all copies, since at least
4971 -- one copy may be used in a context where this flag must be set
4972 -- (otherwise why would the flag be set in the first place).
4974 Set_Assignment_OK (Res, Assignment_OK (Exp));
4976 -- Finally rewrite the original expression and we are done
4979 Analyze_And_Resolve (Exp, Exp_Type);
4980 Scope_Suppress := Svg_Suppress;
4981 end Remove_Side_Effects;
4983 ---------------------------
4984 -- Represented_As_Scalar --
4985 ---------------------------
4987 function Represented_As_Scalar (T : Entity_Id) return Boolean is
4988 UT : constant Entity_Id := Underlying_Type (T);
4990 return Is_Scalar_Type (UT)
4991 or else (Is_Bit_Packed_Array (UT)
4992 and then Is_Scalar_Type (Packed_Array_Type (UT)));
4993 end Represented_As_Scalar;
4995 ------------------------------------
4996 -- Safe_Unchecked_Type_Conversion --
4997 ------------------------------------
4999 -- Note: this function knows quite a bit about the exact requirements
5000 -- of Gigi with respect to unchecked type conversions, and its code
5001 -- must be coordinated with any changes in Gigi in this area.
5003 -- The above requirements should be documented in Sinfo ???
5005 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
5010 Pexp : constant Node_Id := Parent (Exp);
5013 -- If the expression is the RHS of an assignment or object declaration
5014 -- we are always OK because there will always be a target.
5016 -- Object renaming declarations, (generated for view conversions of
5017 -- actuals in inlined calls), like object declarations, provide an
5018 -- explicit type, and are safe as well.
5020 if (Nkind (Pexp) = N_Assignment_Statement
5021 and then Expression (Pexp) = Exp)
5022 or else Nkind (Pexp) = N_Object_Declaration
5023 or else Nkind (Pexp) = N_Object_Renaming_Declaration
5027 -- If the expression is the prefix of an N_Selected_Component
5028 -- we should also be OK because GCC knows to look inside the
5029 -- conversion except if the type is discriminated. We assume
5030 -- that we are OK anyway if the type is not set yet or if it is
5031 -- controlled since we can't afford to introduce a temporary in
5034 elsif Nkind (Pexp) = N_Selected_Component
5035 and then Prefix (Pexp) = Exp
5037 if No (Etype (Pexp)) then
5041 not Has_Discriminants (Etype (Pexp))
5042 or else Is_Constrained (Etype (Pexp));
5046 -- Set the output type, this comes from Etype if it is set, otherwise
5047 -- we take it from the subtype mark, which we assume was already
5050 if Present (Etype (Exp)) then
5051 Otyp := Etype (Exp);
5053 Otyp := Entity (Subtype_Mark (Exp));
5056 -- The input type always comes from the expression, and we assume
5057 -- this is indeed always analyzed, so we can simply get the Etype.
5059 Ityp := Etype (Expression (Exp));
5061 -- Initialize alignments to unknown so far
5066 -- Replace a concurrent type by its corresponding record type
5067 -- and each type by its underlying type and do the tests on those.
5068 -- The original type may be a private type whose completion is a
5069 -- concurrent type, so find the underlying type first.
5071 if Present (Underlying_Type (Otyp)) then
5072 Otyp := Underlying_Type (Otyp);
5075 if Present (Underlying_Type (Ityp)) then
5076 Ityp := Underlying_Type (Ityp);
5079 if Is_Concurrent_Type (Otyp) then
5080 Otyp := Corresponding_Record_Type (Otyp);
5083 if Is_Concurrent_Type (Ityp) then
5084 Ityp := Corresponding_Record_Type (Ityp);
5087 -- If the base types are the same, we know there is no problem since
5088 -- this conversion will be a noop.
5090 if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
5093 -- Same if this is an upwards conversion of an untagged type, and there
5094 -- are no constraints involved (could be more general???)
5096 elsif Etype (Ityp) = Otyp
5097 and then not Is_Tagged_Type (Ityp)
5098 and then not Has_Discriminants (Ityp)
5099 and then No (First_Rep_Item (Base_Type (Ityp)))
5103 -- If the expression has an access type (object or subprogram) we
5104 -- assume that the conversion is safe, because the size of the target
5105 -- is safe, even if it is a record (which might be treated as having
5106 -- unknown size at this point).
5108 elsif Is_Access_Type (Ityp) then
5111 -- If the size of output type is known at compile time, there is
5112 -- never a problem. Note that unconstrained records are considered
5113 -- to be of known size, but we can't consider them that way here,
5114 -- because we are talking about the actual size of the object.
5116 -- We also make sure that in addition to the size being known, we do
5117 -- not have a case which might generate an embarrassingly large temp
5118 -- in stack checking mode.
5120 elsif Size_Known_At_Compile_Time (Otyp)
5122 (not Stack_Checking_Enabled
5123 or else not May_Generate_Large_Temp (Otyp))
5124 and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
5128 -- If either type is tagged, then we know the alignment is OK so
5129 -- Gigi will be able to use pointer punning.
5131 elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
5134 -- If either type is a limited record type, we cannot do a copy, so
5135 -- say safe since there's nothing else we can do.
5137 elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
5140 -- Conversions to and from packed array types are always ignored and
5143 elsif Is_Packed_Array_Type (Otyp)
5144 or else Is_Packed_Array_Type (Ityp)
5149 -- The only other cases known to be safe is if the input type's
5150 -- alignment is known to be at least the maximum alignment for the
5151 -- target or if both alignments are known and the output type's
5152 -- alignment is no stricter than the input's. We can use the alignment
5153 -- of the component type of an array if a type is an unpacked
5156 if Present (Alignment_Clause (Otyp)) then
5157 Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
5159 elsif Is_Array_Type (Otyp)
5160 and then Present (Alignment_Clause (Component_Type (Otyp)))
5162 Oalign := Expr_Value (Expression (Alignment_Clause
5163 (Component_Type (Otyp))));
5166 if Present (Alignment_Clause (Ityp)) then
5167 Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
5169 elsif Is_Array_Type (Ityp)
5170 and then Present (Alignment_Clause (Component_Type (Ityp)))
5172 Ialign := Expr_Value (Expression (Alignment_Clause
5173 (Component_Type (Ityp))));
5176 if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
5179 elsif Ialign /= No_Uint and then Oalign /= No_Uint
5180 and then Ialign <= Oalign
5184 -- Otherwise, Gigi cannot handle this and we must make a temporary
5189 end Safe_Unchecked_Type_Conversion;
5191 ---------------------------------
5192 -- Set_Current_Value_Condition --
5193 ---------------------------------
5195 -- Note: the implementation of this procedure is very closely tied to the
5196 -- implementation of Get_Current_Value_Condition. Here we set required
5197 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
5198 -- them, so they must have a consistent view.
5200 procedure Set_Current_Value_Condition (Cnode : Node_Id) is
5202 procedure Set_Entity_Current_Value (N : Node_Id);
5203 -- If N is an entity reference, where the entity is of an appropriate
5204 -- kind, then set the current value of this entity to Cnode, unless
5205 -- there is already a definite value set there.
5207 procedure Set_Expression_Current_Value (N : Node_Id);
5208 -- If N is of an appropriate form, sets an appropriate entry in current
5209 -- value fields of relevant entities. Multiple entities can be affected
5210 -- in the case of an AND or AND THEN.
5212 ------------------------------
5213 -- Set_Entity_Current_Value --
5214 ------------------------------
5216 procedure Set_Entity_Current_Value (N : Node_Id) is
5218 if Is_Entity_Name (N) then
5220 Ent : constant Entity_Id := Entity (N);
5223 -- Don't capture if not safe to do so
5225 if not Safe_To_Capture_Value (N, Ent, Cond => True) then
5229 -- Here we have a case where the Current_Value field may
5230 -- need to be set. We set it if it is not already set to a
5231 -- compile time expression value.
5233 -- Note that this represents a decision that one condition
5234 -- blots out another previous one. That's certainly right
5235 -- if they occur at the same level. If the second one is
5236 -- nested, then the decision is neither right nor wrong (it
5237 -- would be equally OK to leave the outer one in place, or
5238 -- take the new inner one. Really we should record both, but
5239 -- our data structures are not that elaborate.
5241 if Nkind (Current_Value (Ent)) not in N_Subexpr then
5242 Set_Current_Value (Ent, Cnode);
5246 end Set_Entity_Current_Value;
5248 ----------------------------------
5249 -- Set_Expression_Current_Value --
5250 ----------------------------------
5252 procedure Set_Expression_Current_Value (N : Node_Id) is
5258 -- Loop to deal with (ignore for now) any NOT operators present. The
5259 -- presence of NOT operators will be handled properly when we call
5260 -- Get_Current_Value_Condition.
5262 while Nkind (Cond) = N_Op_Not loop
5263 Cond := Right_Opnd (Cond);
5266 -- For an AND or AND THEN, recursively process operands
5268 if Nkind (Cond) = N_Op_And or else Nkind (Cond) = N_And_Then then
5269 Set_Expression_Current_Value (Left_Opnd (Cond));
5270 Set_Expression_Current_Value (Right_Opnd (Cond));
5274 -- Check possible relational operator
5276 if Nkind (Cond) in N_Op_Compare then
5277 if Compile_Time_Known_Value (Right_Opnd (Cond)) then
5278 Set_Entity_Current_Value (Left_Opnd (Cond));
5279 elsif Compile_Time_Known_Value (Left_Opnd (Cond)) then
5280 Set_Entity_Current_Value (Right_Opnd (Cond));
5283 -- Check possible boolean variable reference
5286 Set_Entity_Current_Value (Cond);
5288 end Set_Expression_Current_Value;
5290 -- Start of processing for Set_Current_Value_Condition
5293 Set_Expression_Current_Value (Condition (Cnode));
5294 end Set_Current_Value_Condition;
5296 --------------------------
5297 -- Set_Elaboration_Flag --
5298 --------------------------
5300 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
5301 Loc : constant Source_Ptr := Sloc (N);
5302 Ent : constant Entity_Id := Elaboration_Entity (Spec_Id);
5306 if Present (Ent) then
5308 -- Nothing to do if at the compilation unit level, because in this
5309 -- case the flag is set by the binder generated elaboration routine.
5311 if Nkind (Parent (N)) = N_Compilation_Unit then
5314 -- Here we do need to generate an assignment statement
5317 Check_Restriction (No_Elaboration_Code, N);
5319 Make_Assignment_Statement (Loc,
5320 Name => New_Occurrence_Of (Ent, Loc),
5321 Expression => New_Occurrence_Of (Standard_True, Loc));
5323 if Nkind (Parent (N)) = N_Subunit then
5324 Insert_After (Corresponding_Stub (Parent (N)), Asn);
5326 Insert_After (N, Asn);
5331 -- Kill current value indication. This is necessary because the
5332 -- tests of this flag are inserted out of sequence and must not
5333 -- pick up bogus indications of the wrong constant value.
5335 Set_Current_Value (Ent, Empty);
5338 end Set_Elaboration_Flag;
5340 ----------------------------
5341 -- Set_Renamed_Subprogram --
5342 ----------------------------
5344 procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id) is
5346 -- If input node is an identifier, we can just reset it
5348 if Nkind (N) = N_Identifier then
5349 Set_Chars (N, Chars (E));
5352 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
5356 CS : constant Boolean := Comes_From_Source (N);
5358 Rewrite (N, Make_Identifier (Sloc (N), Chars => Chars (E)));
5360 Set_Comes_From_Source (N, CS);
5361 Set_Analyzed (N, True);
5364 end Set_Renamed_Subprogram;
5366 ----------------------------------
5367 -- Silly_Boolean_Array_Not_Test --
5368 ----------------------------------
5370 -- This procedure implements an odd and silly test. We explicitly check
5371 -- for the case where the 'First of the component type is equal to the
5372 -- 'Last of this component type, and if this is the case, we make sure
5373 -- that constraint error is raised. The reason is that the NOT is bound
5374 -- to cause CE in this case, and we will not otherwise catch it.
5376 -- No such check is required for AND and OR, since for both these cases
5377 -- False op False = False, and True op True = True. For the XOR case,
5378 -- see Silly_Boolean_Array_Xor_Test.
5380 -- Believe it or not, this was reported as a bug. Note that nearly
5381 -- always, the test will evaluate statically to False, so the code will
5382 -- be statically removed, and no extra overhead caused.
5384 procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id) is
5385 Loc : constant Source_Ptr := Sloc (N);
5386 CT : constant Entity_Id := Component_Type (T);
5389 -- The check we install is
5391 -- constraint_error when
5392 -- component_type'first = component_type'last
5393 -- and then array_type'Length /= 0)
5395 -- We need the last guard because we don't want to raise CE for empty
5396 -- arrays since no out of range values result. (Empty arrays with a
5397 -- component type of True .. True -- very useful -- even the ACATS
5398 -- does not test that marginal case!)
5401 Make_Raise_Constraint_Error (Loc,
5407 Make_Attribute_Reference (Loc,
5408 Prefix => New_Occurrence_Of (CT, Loc),
5409 Attribute_Name => Name_First),
5412 Make_Attribute_Reference (Loc,
5413 Prefix => New_Occurrence_Of (CT, Loc),
5414 Attribute_Name => Name_Last)),
5416 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
5417 Reason => CE_Range_Check_Failed));
5418 end Silly_Boolean_Array_Not_Test;
5420 ----------------------------------
5421 -- Silly_Boolean_Array_Xor_Test --
5422 ----------------------------------
5424 -- This procedure implements an odd and silly test. We explicitly check
5425 -- for the XOR case where the component type is True .. True, since this
5426 -- will raise constraint error. A special check is required since CE
5427 -- will not be generated otherwise (cf Expand_Packed_Not).
5429 -- No such check is required for AND and OR, since for both these cases
5430 -- False op False = False, and True op True = True, and no check is
5431 -- required for the case of False .. False, since False xor False = False.
5432 -- See also Silly_Boolean_Array_Not_Test
5434 procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is
5435 Loc : constant Source_Ptr := Sloc (N);
5436 CT : constant Entity_Id := Component_Type (T);
5439 -- The check we install is
5441 -- constraint_error when
5442 -- Boolean (component_type'First)
5443 -- and then Boolean (component_type'Last)
5444 -- and then array_type'Length /= 0)
5446 -- We need the last guard because we don't want to raise CE for empty
5447 -- arrays since no out of range values result (Empty arrays with a
5448 -- component type of True .. True -- very useful -- even the ACATS
5449 -- does not test that marginal case!).
5452 Make_Raise_Constraint_Error (Loc,
5458 Convert_To (Standard_Boolean,
5459 Make_Attribute_Reference (Loc,
5460 Prefix => New_Occurrence_Of (CT, Loc),
5461 Attribute_Name => Name_First)),
5464 Convert_To (Standard_Boolean,
5465 Make_Attribute_Reference (Loc,
5466 Prefix => New_Occurrence_Of (CT, Loc),
5467 Attribute_Name => Name_Last))),
5469 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
5470 Reason => CE_Range_Check_Failed));
5471 end Silly_Boolean_Array_Xor_Test;
5473 --------------------------
5474 -- Target_Has_Fixed_Ops --
5475 --------------------------
5477 Integer_Sized_Small : Ureal;
5478 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this
5479 -- function is called (we don't want to compute it more than once!)
5481 Long_Integer_Sized_Small : Ureal;
5482 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this
5483 -- function is called (we don't want to compute it more than once)
5485 First_Time_For_THFO : Boolean := True;
5486 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
5488 function Target_Has_Fixed_Ops
5489 (Left_Typ : Entity_Id;
5490 Right_Typ : Entity_Id;
5491 Result_Typ : Entity_Id) return Boolean
5493 function Is_Fractional_Type (Typ : Entity_Id) return Boolean;
5494 -- Return True if the given type is a fixed-point type with a small
5495 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
5496 -- an absolute value less than 1.0. This is currently limited
5497 -- to fixed-point types that map to Integer or Long_Integer.
5499 ------------------------
5500 -- Is_Fractional_Type --
5501 ------------------------
5503 function Is_Fractional_Type (Typ : Entity_Id) return Boolean is
5505 if Esize (Typ) = Standard_Integer_Size then
5506 return Small_Value (Typ) = Integer_Sized_Small;
5508 elsif Esize (Typ) = Standard_Long_Integer_Size then
5509 return Small_Value (Typ) = Long_Integer_Sized_Small;
5514 end Is_Fractional_Type;
5516 -- Start of processing for Target_Has_Fixed_Ops
5519 -- Return False if Fractional_Fixed_Ops_On_Target is false
5521 if not Fractional_Fixed_Ops_On_Target then
5525 -- Here the target has Fractional_Fixed_Ops, if first time, compute
5526 -- standard constants used by Is_Fractional_Type.
5528 if First_Time_For_THFO then
5529 First_Time_For_THFO := False;
5531 Integer_Sized_Small :=
5534 Den => UI_From_Int (Standard_Integer_Size - 1),
5537 Long_Integer_Sized_Small :=
5540 Den => UI_From_Int (Standard_Long_Integer_Size - 1),
5544 -- Return True if target supports fixed-by-fixed multiply/divide
5545 -- for fractional fixed-point types (see Is_Fractional_Type) and
5546 -- the operand and result types are equivalent fractional types.
5548 return Is_Fractional_Type (Base_Type (Left_Typ))
5549 and then Is_Fractional_Type (Base_Type (Right_Typ))
5550 and then Is_Fractional_Type (Base_Type (Result_Typ))
5551 and then Esize (Left_Typ) = Esize (Right_Typ)
5552 and then Esize (Left_Typ) = Esize (Result_Typ);
5553 end Target_Has_Fixed_Ops;
5555 ------------------------------------------
5556 -- Type_May_Have_Bit_Aligned_Components --
5557 ------------------------------------------
5559 function Type_May_Have_Bit_Aligned_Components
5560 (Typ : Entity_Id) return Boolean
5563 -- Array type, check component type
5565 if Is_Array_Type (Typ) then
5567 Type_May_Have_Bit_Aligned_Components (Component_Type (Typ));
5569 -- Record type, check components
5571 elsif Is_Record_Type (Typ) then
5576 E := First_Component_Or_Discriminant (Typ);
5577 while Present (E) loop
5578 if Component_May_Be_Bit_Aligned (E)
5579 or else Type_May_Have_Bit_Aligned_Components (Etype (E))
5584 Next_Component_Or_Discriminant (E);
5590 -- Type other than array or record is always OK
5595 end Type_May_Have_Bit_Aligned_Components;
5597 ----------------------------
5598 -- Wrap_Cleanup_Procedure --
5599 ----------------------------
5601 procedure Wrap_Cleanup_Procedure (N : Node_Id) is
5602 Loc : constant Source_Ptr := Sloc (N);
5603 Stseq : constant Node_Id := Handled_Statement_Sequence (N);
5604 Stmts : constant List_Id := Statements (Stseq);
5607 if Abort_Allowed then
5608 Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
5609 Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
5611 end Wrap_Cleanup_Procedure;