1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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_Eval; use Sem_Eval;
47 with Sem_Res; use Sem_Res;
48 with Sem_Type; use Sem_Type;
49 with Sem_Util; use Sem_Util;
50 with Snames; use Snames;
51 with Stand; use Stand;
52 with Stringt; use Stringt;
53 with Targparm; use Targparm;
54 with Tbuild; use Tbuild;
55 with Ttypes; use Ttypes;
56 with Uintp; use Uintp;
57 with Urealp; use Urealp;
58 with Validsw; use Validsw;
60 package body Exp_Util is
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 function Build_Task_Array_Image
70 Dyn : Boolean := False) return Node_Id;
71 -- Build function to generate the image string for a task that is an
72 -- array component, concatenating the images of each index. To avoid
73 -- storage leaks, the string is built with successive slice assignments.
74 -- The flag Dyn indicates whether this is called for the initialization
75 -- procedure of an array of tasks, or for the name of a dynamically
76 -- created task that is assigned to an indexed component.
78 function Build_Task_Image_Function
82 Res : Entity_Id) return Node_Id;
83 -- Common processing for Task_Array_Image and Task_Record_Image.
84 -- Build function body that computes image.
86 procedure Build_Task_Image_Prefix
95 -- Common processing for Task_Array_Image and Task_Record_Image.
96 -- Create local variables and assign prefix of name to result string.
98 function Build_Task_Record_Image
101 Dyn : Boolean := False) return Node_Id;
102 -- Build function to generate the image string for a task that is a
103 -- record component. Concatenate name of variable with that of selector.
104 -- The flag Dyn indicates whether this is called for the initialization
105 -- procedure of record with task components, or for a dynamically
106 -- created task that is assigned to a selected component.
108 function Make_CW_Equivalent_Type
110 E : Node_Id) return Entity_Id;
111 -- T is a class-wide type entity, E is the initial expression node that
112 -- constrains T in case such as: " X: T := E" or "new T'(E)"
113 -- This function returns the entity of the Equivalent type and inserts
114 -- on the fly the necessary declaration such as:
116 -- type anon is record
117 -- _parent : Root_Type (T); constrained with E discriminants (if any)
118 -- Extension : String (1 .. expr to match size of E);
121 -- This record is compatible with any object of the class of T thanks
122 -- to the first field and has the same size as E thanks to the second.
124 function Make_Literal_Range
126 Literal_Typ : Entity_Id) return Node_Id;
127 -- Produce a Range node whose bounds are:
128 -- Low_Bound (Literal_Type) ..
129 -- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
130 -- this is used for expanding declarations like X : String := "sdfgdfg";
132 -- If the index type of the target array is not integer, we generate:
133 -- Low_Bound (Literal_Type) ..
135 -- (Literal_Type'Pos (Low_Bound (Literal_Type))
136 -- + (Length (Literal_Typ) -1))
138 function Make_Non_Empty_Check
140 N : Node_Id) return Node_Id;
141 -- Produce a boolean expression checking that the unidimensional array
142 -- node N is not empty.
144 function New_Class_Wide_Subtype
146 N : Node_Id) return Entity_Id;
147 -- Create an implicit subtype of CW_Typ attached to node N
149 ----------------------
150 -- Adjust_Condition --
151 ----------------------
153 procedure Adjust_Condition (N : Node_Id) is
160 Loc : constant Source_Ptr := Sloc (N);
161 T : constant Entity_Id := Etype (N);
165 -- For now, we simply ignore a call where the argument has no
166 -- type (probably case of unanalyzed condition), or has a type
167 -- that is not Boolean. This is because this is a pretty marginal
168 -- piece of functionality, and violations of these rules are
169 -- likely to be truly marginal (how much code uses Fortran Logical
170 -- as the barrier to a protected entry?) and we do not want to
171 -- blow up existing programs. We can change this to an assertion
172 -- after 3.12a is released ???
174 if No (T) or else not Is_Boolean_Type (T) then
178 -- Apply validity checking if needed
180 if Validity_Checks_On and Validity_Check_Tests then
184 -- Immediate return if standard boolean, the most common case,
185 -- where nothing needs to be done.
187 if Base_Type (T) = Standard_Boolean then
191 -- Case of zero/non-zero semantics or non-standard enumeration
192 -- representation. In each case, we rewrite the node as:
194 -- ityp!(N) /= False'Enum_Rep
196 -- where ityp is an integer type with large enough size to hold
197 -- any value of type T.
199 if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
200 if Esize (T) <= Esize (Standard_Integer) then
201 Ti := Standard_Integer;
203 Ti := Standard_Long_Long_Integer;
208 Left_Opnd => Unchecked_Convert_To (Ti, N),
210 Make_Attribute_Reference (Loc,
211 Attribute_Name => Name_Enum_Rep,
213 New_Occurrence_Of (First_Literal (T), Loc))));
214 Analyze_And_Resolve (N, Standard_Boolean);
217 Rewrite (N, Convert_To (Standard_Boolean, N));
218 Analyze_And_Resolve (N, Standard_Boolean);
221 end Adjust_Condition;
223 ------------------------
224 -- Adjust_Result_Type --
225 ------------------------
227 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
229 -- Ignore call if current type is not Standard.Boolean
231 if Etype (N) /= Standard_Boolean then
235 -- If result is already of correct type, nothing to do. Note that
236 -- this will get the most common case where everything has a type
237 -- of Standard.Boolean.
239 if Base_Type (T) = Standard_Boolean then
244 KP : constant Node_Kind := Nkind (Parent (N));
247 -- If result is to be used as a Condition in the syntax, no need
248 -- to convert it back, since if it was changed to Standard.Boolean
249 -- using Adjust_Condition, that is just fine for this usage.
251 if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
254 -- If result is an operand of another logical operation, no need
255 -- to reset its type, since Standard.Boolean is just fine, and
256 -- such operations always do Adjust_Condition on their operands.
258 elsif KP in N_Op_Boolean
259 or else KP in N_Short_Circuit
260 or else KP = N_Op_Not
264 -- Otherwise we perform a conversion from the current type,
265 -- which must be Standard.Boolean, to the desired type.
269 Rewrite (N, Convert_To (T, N));
270 Analyze_And_Resolve (N, T);
274 end Adjust_Result_Type;
276 --------------------------
277 -- Append_Freeze_Action --
278 --------------------------
280 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
284 Ensure_Freeze_Node (T);
285 Fnode := Freeze_Node (T);
287 if No (Actions (Fnode)) then
288 Set_Actions (Fnode, New_List);
291 Append (N, Actions (Fnode));
292 end Append_Freeze_Action;
294 ---------------------------
295 -- Append_Freeze_Actions --
296 ---------------------------
298 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
299 Fnode : constant Node_Id := Freeze_Node (T);
306 if No (Actions (Fnode)) then
307 Set_Actions (Fnode, L);
310 Append_List (L, Actions (Fnode));
314 end Append_Freeze_Actions;
316 ------------------------
317 -- Build_Runtime_Call --
318 ------------------------
320 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
322 -- If entity is not available, we can skip making the call (this avoids
323 -- junk duplicated error messages in a number of cases).
325 if not RTE_Available (RE) then
326 return Make_Null_Statement (Loc);
329 Make_Procedure_Call_Statement (Loc,
330 Name => New_Reference_To (RTE (RE), Loc));
332 end Build_Runtime_Call;
334 ----------------------------
335 -- Build_Task_Array_Image --
336 ----------------------------
338 -- This function generates the body for a function that constructs the
339 -- image string for a task that is an array component. The function is
340 -- local to the init proc for the array type, and is called for each one
341 -- of the components. The constructed image has the form of an indexed
342 -- component, whose prefix is the outer variable of the array type.
343 -- The n-dimensional array type has known indices Index, Index2...
344 -- Id_Ref is an indexed component form created by the enclosing init proc.
345 -- Its successive indices are Val1, Val2, ... which are the loop variables
346 -- in the loops that call the individual task init proc on each component.
348 -- The generated function has the following structure:
350 -- function F return String is
351 -- Pref : string renames Task_Name;
352 -- T1 : String := Index1'Image (Val1);
354 -- Tn : String := indexn'image (Valn);
355 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
356 -- -- Len includes commas and the end parentheses.
357 -- Res : String (1..Len);
358 -- Pos : Integer := Pref'Length;
361 -- Res (1 .. Pos) := Pref;
365 -- Res (Pos .. Pos + T1'Length - 1) := T1;
366 -- Pos := Pos + T1'Length;
370 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
376 -- Needless to say, multidimensional arrays of tasks are rare enough
377 -- that the bulkiness of this code is not really a concern.
379 function Build_Task_Array_Image
383 Dyn : Boolean := False) return Node_Id
385 Dims : constant Nat := Number_Dimensions (A_Type);
386 -- Number of dimensions for array of tasks
388 Temps : array (1 .. Dims) of Entity_Id;
389 -- Array of temporaries to hold string for each index
395 -- Total length of generated name
398 -- Running index for substring assignments
401 -- Name of enclosing variable, prefix of resulting name
404 -- String to hold result
407 -- Value of successive indices
410 -- Expression to compute total size of string
413 -- Entity for name at one index position
415 Decls : constant List_Id := New_List;
416 Stats : constant List_Id := New_List;
419 Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
421 -- For a dynamic task, the name comes from the target variable.
422 -- For a static one it is a formal of the enclosing init proc.
425 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
427 Make_Object_Declaration (Loc,
428 Defining_Identifier => Pref,
429 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
431 Make_String_Literal (Loc,
432 Strval => String_From_Name_Buffer)));
436 Make_Object_Renaming_Declaration (Loc,
437 Defining_Identifier => Pref,
438 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
439 Name => Make_Identifier (Loc, Name_uTask_Name)));
442 Indx := First_Index (A_Type);
443 Val := First (Expressions (Id_Ref));
445 for J in 1 .. Dims loop
446 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
450 Make_Object_Declaration (Loc,
451 Defining_Identifier => T,
452 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
454 Make_Attribute_Reference (Loc,
455 Attribute_Name => Name_Image,
457 New_Occurrence_Of (Etype (Indx), Loc),
458 Expressions => New_List (
459 New_Copy_Tree (Val)))));
465 Sum := Make_Integer_Literal (Loc, Dims + 1);
471 Make_Attribute_Reference (Loc,
472 Attribute_Name => Name_Length,
474 New_Occurrence_Of (Pref, Loc),
475 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
477 for J in 1 .. Dims loop
482 Make_Attribute_Reference (Loc,
483 Attribute_Name => Name_Length,
485 New_Occurrence_Of (Temps (J), Loc),
486 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
489 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
491 Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
494 Make_Assignment_Statement (Loc,
495 Name => Make_Indexed_Component (Loc,
496 Prefix => New_Occurrence_Of (Res, Loc),
497 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
499 Make_Character_Literal (Loc,
501 Char_Literal_Value =>
502 UI_From_Int (Character'Pos ('(')))));
505 Make_Assignment_Statement (Loc,
506 Name => New_Occurrence_Of (Pos, Loc),
509 Left_Opnd => New_Occurrence_Of (Pos, Loc),
510 Right_Opnd => Make_Integer_Literal (Loc, 1))));
512 for J in 1 .. Dims loop
515 Make_Assignment_Statement (Loc,
516 Name => Make_Slice (Loc,
517 Prefix => New_Occurrence_Of (Res, Loc),
520 Low_Bound => New_Occurrence_Of (Pos, Loc),
521 High_Bound => Make_Op_Subtract (Loc,
524 Left_Opnd => New_Occurrence_Of (Pos, Loc),
526 Make_Attribute_Reference (Loc,
527 Attribute_Name => Name_Length,
529 New_Occurrence_Of (Temps (J), Loc),
531 New_List (Make_Integer_Literal (Loc, 1)))),
532 Right_Opnd => Make_Integer_Literal (Loc, 1)))),
534 Expression => New_Occurrence_Of (Temps (J), Loc)));
538 Make_Assignment_Statement (Loc,
539 Name => New_Occurrence_Of (Pos, Loc),
542 Left_Opnd => New_Occurrence_Of (Pos, Loc),
544 Make_Attribute_Reference (Loc,
545 Attribute_Name => Name_Length,
546 Prefix => New_Occurrence_Of (Temps (J), Loc),
548 New_List (Make_Integer_Literal (Loc, 1))))));
550 Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
553 Make_Assignment_Statement (Loc,
554 Name => Make_Indexed_Component (Loc,
555 Prefix => New_Occurrence_Of (Res, Loc),
556 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
558 Make_Character_Literal (Loc,
560 Char_Literal_Value =>
561 UI_From_Int (Character'Pos (',')))));
564 Make_Assignment_Statement (Loc,
565 Name => New_Occurrence_Of (Pos, Loc),
568 Left_Opnd => New_Occurrence_Of (Pos, Loc),
569 Right_Opnd => Make_Integer_Literal (Loc, 1))));
573 Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
576 Make_Assignment_Statement (Loc,
577 Name => Make_Indexed_Component (Loc,
578 Prefix => New_Occurrence_Of (Res, Loc),
579 Expressions => New_List (New_Occurrence_Of (Len, Loc))),
581 Make_Character_Literal (Loc,
583 Char_Literal_Value =>
584 UI_From_Int (Character'Pos (')')))));
585 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
586 end Build_Task_Array_Image;
588 ----------------------------
589 -- Build_Task_Image_Decls --
590 ----------------------------
592 function Build_Task_Image_Decls
596 In_Init_Proc : Boolean := False) return List_Id
598 Decls : constant List_Id := New_List;
599 T_Id : Entity_Id := Empty;
601 Expr : Node_Id := Empty;
602 Fun : Node_Id := Empty;
603 Is_Dyn : constant Boolean :=
604 Nkind (Parent (Id_Ref)) = N_Assignment_Statement
606 Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
609 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
610 -- generate a dummy declaration only.
612 if Restriction_Active (No_Implicit_Heap_Allocations)
613 or else Global_Discard_Names
615 T_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
620 Make_Object_Declaration (Loc,
621 Defining_Identifier => T_Id,
622 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
624 Make_String_Literal (Loc,
625 Strval => String_From_Name_Buffer)));
628 if Nkind (Id_Ref) = N_Identifier
629 or else Nkind (Id_Ref) = N_Defining_Identifier
631 -- For a simple variable, the image of the task is built from
632 -- the name of the variable. To avoid possible conflict with
633 -- the anonymous type created for a single protected object,
634 -- add a numeric suffix.
637 Make_Defining_Identifier (Loc,
638 New_External_Name (Chars (Id_Ref), 'T', 1));
640 Get_Name_String (Chars (Id_Ref));
643 Make_String_Literal (Loc,
644 Strval => String_From_Name_Buffer);
646 elsif Nkind (Id_Ref) = N_Selected_Component then
648 Make_Defining_Identifier (Loc,
649 New_External_Name (Chars (Selector_Name (Id_Ref)), 'T'));
650 Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn);
652 elsif Nkind (Id_Ref) = N_Indexed_Component then
654 Make_Defining_Identifier (Loc,
655 New_External_Name (Chars (A_Type), 'N'));
657 Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
661 if Present (Fun) then
663 Expr := Make_Function_Call (Loc,
664 Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
666 if not In_Init_Proc and then VM_Target = No_VM then
667 Set_Uses_Sec_Stack (Defining_Entity (Fun));
671 Decl := Make_Object_Declaration (Loc,
672 Defining_Identifier => T_Id,
673 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
674 Constant_Present => True,
677 Append (Decl, Decls);
679 end Build_Task_Image_Decls;
681 -------------------------------
682 -- Build_Task_Image_Function --
683 -------------------------------
685 function Build_Task_Image_Function
689 Res : Entity_Id) return Node_Id
695 Make_Simple_Return_Statement (Loc,
696 Expression => New_Occurrence_Of (Res, Loc)));
698 Spec := Make_Function_Specification (Loc,
699 Defining_Unit_Name =>
700 Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
701 Result_Definition => New_Occurrence_Of (Standard_String, Loc));
703 -- Calls to 'Image use the secondary stack, which must be cleaned
704 -- up after the task name is built.
706 return Make_Subprogram_Body (Loc,
707 Specification => Spec,
708 Declarations => Decls,
709 Handled_Statement_Sequence =>
710 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats));
711 end Build_Task_Image_Function;
713 -----------------------------
714 -- Build_Task_Image_Prefix --
715 -----------------------------
717 procedure Build_Task_Image_Prefix
728 Len := Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
731 Make_Object_Declaration (Loc,
732 Defining_Identifier => Len,
733 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
736 Res := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
739 Make_Object_Declaration (Loc,
740 Defining_Identifier => Res,
742 Make_Subtype_Indication (Loc,
743 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
745 Make_Index_Or_Discriminant_Constraint (Loc,
749 Low_Bound => Make_Integer_Literal (Loc, 1),
750 High_Bound => New_Occurrence_Of (Len, Loc)))))));
752 Pos := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
755 Make_Object_Declaration (Loc,
756 Defining_Identifier => Pos,
757 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
759 -- Pos := Prefix'Length;
762 Make_Assignment_Statement (Loc,
763 Name => New_Occurrence_Of (Pos, Loc),
765 Make_Attribute_Reference (Loc,
766 Attribute_Name => Name_Length,
767 Prefix => New_Occurrence_Of (Prefix, Loc),
769 New_List (Make_Integer_Literal (Loc, 1)))));
771 -- Res (1 .. Pos) := Prefix;
774 Make_Assignment_Statement (Loc,
775 Name => Make_Slice (Loc,
776 Prefix => New_Occurrence_Of (Res, Loc),
779 Low_Bound => Make_Integer_Literal (Loc, 1),
780 High_Bound => New_Occurrence_Of (Pos, Loc))),
782 Expression => New_Occurrence_Of (Prefix, Loc)));
785 Make_Assignment_Statement (Loc,
786 Name => New_Occurrence_Of (Pos, Loc),
789 Left_Opnd => New_Occurrence_Of (Pos, Loc),
790 Right_Opnd => Make_Integer_Literal (Loc, 1))));
791 end Build_Task_Image_Prefix;
793 -----------------------------
794 -- Build_Task_Record_Image --
795 -----------------------------
797 function Build_Task_Record_Image
800 Dyn : Boolean := False) return Node_Id
803 -- Total length of generated name
809 -- String to hold result
812 -- Name of enclosing variable, prefix of resulting name
815 -- Expression to compute total size of string
818 -- Entity for selector name
820 Decls : constant List_Id := New_List;
821 Stats : constant List_Id := New_List;
824 Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
826 -- For a dynamic task, the name comes from the target variable.
827 -- For a static one it is a formal of the enclosing init proc.
830 Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
832 Make_Object_Declaration (Loc,
833 Defining_Identifier => Pref,
834 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
836 Make_String_Literal (Loc,
837 Strval => String_From_Name_Buffer)));
841 Make_Object_Renaming_Declaration (Loc,
842 Defining_Identifier => Pref,
843 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
844 Name => Make_Identifier (Loc, Name_uTask_Name)));
847 Sel := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
849 Get_Name_String (Chars (Selector_Name (Id_Ref)));
852 Make_Object_Declaration (Loc,
853 Defining_Identifier => Sel,
854 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
856 Make_String_Literal (Loc,
857 Strval => String_From_Name_Buffer)));
859 Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
865 Make_Attribute_Reference (Loc,
866 Attribute_Name => Name_Length,
868 New_Occurrence_Of (Pref, Loc),
869 Expressions => New_List (Make_Integer_Literal (Loc, 1))));
871 Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
873 Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
878 Make_Assignment_Statement (Loc,
879 Name => Make_Indexed_Component (Loc,
880 Prefix => New_Occurrence_Of (Res, Loc),
881 Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
883 Make_Character_Literal (Loc,
885 Char_Literal_Value =>
886 UI_From_Int (Character'Pos ('.')))));
889 Make_Assignment_Statement (Loc,
890 Name => New_Occurrence_Of (Pos, Loc),
893 Left_Opnd => New_Occurrence_Of (Pos, Loc),
894 Right_Opnd => Make_Integer_Literal (Loc, 1))));
896 -- Res (Pos .. Len) := Selector;
899 Make_Assignment_Statement (Loc,
900 Name => Make_Slice (Loc,
901 Prefix => New_Occurrence_Of (Res, Loc),
904 Low_Bound => New_Occurrence_Of (Pos, Loc),
905 High_Bound => New_Occurrence_Of (Len, Loc))),
906 Expression => New_Occurrence_Of (Sel, Loc)));
908 return Build_Task_Image_Function (Loc, Decls, Stats, Res);
909 end Build_Task_Record_Image;
911 ----------------------------------
912 -- Component_May_Be_Bit_Aligned --
913 ----------------------------------
915 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
917 -- If no component clause, then everything is fine, since the back end
918 -- never bit-misaligns by default, even if there is a pragma Packed for
921 if No (Component_Clause (Comp)) then
925 -- It is only array and record types that cause trouble
927 if not Is_Record_Type (Etype (Comp))
928 and then not Is_Array_Type (Etype (Comp))
932 -- If we know that we have a small (64 bits or less) record
933 -- or bit-packed array, then everything is fine, since the
934 -- back end can handle these cases correctly.
936 elsif Esize (Comp) <= 64
937 and then (Is_Record_Type (Etype (Comp))
938 or else Is_Bit_Packed_Array (Etype (Comp)))
942 -- Otherwise if the component is not byte aligned, we know we have the
943 -- nasty unaligned case.
945 elsif Normalized_First_Bit (Comp) /= Uint_0
946 or else Esize (Comp) mod System_Storage_Unit /= Uint_0
950 -- If we are large and byte aligned, then OK at this level
955 end Component_May_Be_Bit_Aligned;
957 -----------------------------------
958 -- Corresponding_Runtime_Package --
959 -----------------------------------
961 function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id is
962 Pkg_Id : RTU_Id := RTU_Null;
965 pragma Assert (Is_Concurrent_Type (Typ));
967 if Ekind (Typ) in Protected_Kind then
969 or else Has_Interrupt_Handler (Typ)
970 or else (Has_Attach_Handler (Typ)
971 and then not Restricted_Profile)
973 -- A protected type without entries that covers an interface and
974 -- overrides the abstract routines with protected procedures is
975 -- considered equivalent to a protected type with entries in the
976 -- context of dispatching select statements. It is sufficient to
977 -- check for the presence of an interface list in the declaration
978 -- node to recognize this case.
980 or else Present (Interface_List (Parent (Typ)))
983 or else Restriction_Active (No_Entry_Queue) = False
984 or else Number_Entries (Typ) > 1
985 or else (Has_Attach_Handler (Typ)
986 and then not Restricted_Profile)
988 Pkg_Id := System_Tasking_Protected_Objects_Entries;
990 Pkg_Id := System_Tasking_Protected_Objects_Single_Entry;
994 Pkg_Id := System_Tasking_Protected_Objects;
999 end Corresponding_Runtime_Package;
1001 -------------------------------
1002 -- Convert_To_Actual_Subtype --
1003 -------------------------------
1005 procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
1009 Act_ST := Get_Actual_Subtype (Exp);
1011 if Act_ST = Etype (Exp) then
1016 Convert_To (Act_ST, Relocate_Node (Exp)));
1017 Analyze_And_Resolve (Exp, Act_ST);
1019 end Convert_To_Actual_Subtype;
1021 -----------------------------------
1022 -- Current_Sem_Unit_Declarations --
1023 -----------------------------------
1025 function Current_Sem_Unit_Declarations return List_Id is
1026 U : Node_Id := Unit (Cunit (Current_Sem_Unit));
1030 -- If the current unit is a package body, locate the visible
1031 -- declarations of the package spec.
1033 if Nkind (U) = N_Package_Body then
1034 U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
1037 if Nkind (U) = N_Package_Declaration then
1038 U := Specification (U);
1039 Decls := Visible_Declarations (U);
1043 Set_Visible_Declarations (U, Decls);
1047 Decls := Declarations (U);
1051 Set_Declarations (U, Decls);
1056 end Current_Sem_Unit_Declarations;
1058 -----------------------
1059 -- Duplicate_Subexpr --
1060 -----------------------
1062 function Duplicate_Subexpr
1064 Name_Req : Boolean := False) return Node_Id
1067 Remove_Side_Effects (Exp, Name_Req);
1068 return New_Copy_Tree (Exp);
1069 end Duplicate_Subexpr;
1071 ---------------------------------
1072 -- Duplicate_Subexpr_No_Checks --
1073 ---------------------------------
1075 function Duplicate_Subexpr_No_Checks
1077 Name_Req : Boolean := False) return Node_Id
1082 Remove_Side_Effects (Exp, Name_Req);
1083 New_Exp := New_Copy_Tree (Exp);
1084 Remove_Checks (New_Exp);
1086 end Duplicate_Subexpr_No_Checks;
1088 -----------------------------------
1089 -- Duplicate_Subexpr_Move_Checks --
1090 -----------------------------------
1092 function Duplicate_Subexpr_Move_Checks
1094 Name_Req : Boolean := False) return Node_Id
1099 Remove_Side_Effects (Exp, Name_Req);
1100 New_Exp := New_Copy_Tree (Exp);
1101 Remove_Checks (Exp);
1103 end Duplicate_Subexpr_Move_Checks;
1105 --------------------
1106 -- Ensure_Defined --
1107 --------------------
1109 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
1113 -- An itype reference must only be created if this is a local
1114 -- itype, so that gigi can elaborate it on the proper objstack.
1117 and then Scope (Typ) = Current_Scope
1119 IR := Make_Itype_Reference (Sloc (N));
1120 Set_Itype (IR, Typ);
1121 Insert_Action (N, IR);
1125 --------------------
1126 -- Entry_Names_OK --
1127 --------------------
1129 function Entry_Names_OK return Boolean is
1132 not Restricted_Profile
1133 and then not Global_Discard_Names
1134 and then not Restriction_Active (No_Implicit_Heap_Allocations)
1135 and then not Restriction_Active (No_Local_Allocators);
1138 ---------------------
1139 -- Evolve_And_Then --
1140 ---------------------
1142 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
1148 Make_And_Then (Sloc (Cond1),
1150 Right_Opnd => Cond1);
1152 end Evolve_And_Then;
1154 --------------------
1155 -- Evolve_Or_Else --
1156 --------------------
1158 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
1164 Make_Or_Else (Sloc (Cond1),
1166 Right_Opnd => Cond1);
1170 ------------------------------
1171 -- Expand_Subtype_From_Expr --
1172 ------------------------------
1174 -- This function is applicable for both static and dynamic allocation of
1175 -- objects which are constrained by an initial expression. Basically it
1176 -- transforms an unconstrained subtype indication into a constrained one.
1177 -- The expression may also be transformed in certain cases in order to
1178 -- avoid multiple evaluation. In the static allocation case, the general
1183 -- is transformed into
1185 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1187 -- Here are the main cases :
1189 -- <if Expr is a Slice>
1190 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1192 -- <elsif Expr is a String Literal>
1193 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
1195 -- <elsif Expr is Constrained>
1196 -- subtype T is Type_Of_Expr
1199 -- <elsif Expr is an entity_name>
1200 -- Val : T (constraints taken from Expr) := Expr;
1203 -- type Axxx is access all T;
1204 -- Rval : Axxx := Expr'ref;
1205 -- Val : T (constraints taken from Rval) := Rval.all;
1207 -- ??? note: when the Expression is allocated in the secondary stack
1208 -- we could use it directly instead of copying it by declaring
1209 -- Val : T (...) renames Rval.all
1211 procedure Expand_Subtype_From_Expr
1213 Unc_Type : Entity_Id;
1214 Subtype_Indic : Node_Id;
1217 Loc : constant Source_Ptr := Sloc (N);
1218 Exp_Typ : constant Entity_Id := Etype (Exp);
1222 -- In general we cannot build the subtype if expansion is disabled,
1223 -- because internal entities may not have been defined. However, to
1224 -- avoid some cascaded errors, we try to continue when the expression
1225 -- is an array (or string), because it is safe to compute the bounds.
1226 -- It is in fact required to do so even in a generic context, because
1227 -- there may be constants that depend on bounds of string literal.
1229 if not Expander_Active
1230 and then (No (Etype (Exp))
1231 or else Base_Type (Etype (Exp)) /= Standard_String)
1236 if Nkind (Exp) = N_Slice then
1238 Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
1241 Rewrite (Subtype_Indic,
1242 Make_Subtype_Indication (Loc,
1243 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
1245 Make_Index_Or_Discriminant_Constraint (Loc,
1246 Constraints => New_List
1247 (New_Reference_To (Slice_Type, Loc)))));
1249 -- This subtype indication may be used later for constraint checks
1250 -- we better make sure that if a variable was used as a bound of
1251 -- of the original slice, its value is frozen.
1253 Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
1254 Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
1257 elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
1258 Rewrite (Subtype_Indic,
1259 Make_Subtype_Indication (Loc,
1260 Subtype_Mark => New_Reference_To (Unc_Type, Loc),
1262 Make_Index_Or_Discriminant_Constraint (Loc,
1263 Constraints => New_List (
1264 Make_Literal_Range (Loc,
1265 Literal_Typ => Exp_Typ)))));
1267 elsif Is_Constrained (Exp_Typ)
1268 and then not Is_Class_Wide_Type (Unc_Type)
1270 if Is_Itype (Exp_Typ) then
1272 -- Within an initialization procedure, a selected component
1273 -- denotes a component of the enclosing record, and it appears
1274 -- as an actual in a call to its own initialization procedure.
1275 -- If this component depends on the outer discriminant, we must
1276 -- generate the proper actual subtype for it.
1278 if Nkind (Exp) = N_Selected_Component
1279 and then Within_Init_Proc
1282 Decl : constant Node_Id :=
1283 Build_Actual_Subtype_Of_Component (Exp_Typ, Exp);
1285 if Present (Decl) then
1286 Insert_Action (N, Decl);
1287 T := Defining_Identifier (Decl);
1293 -- No need to generate a new one (new what???)
1301 Make_Defining_Identifier (Loc,
1302 Chars => New_Internal_Name ('T'));
1305 Make_Subtype_Declaration (Loc,
1306 Defining_Identifier => T,
1307 Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
1309 -- This type is marked as an itype even though it has an
1310 -- explicit declaration because otherwise it can be marked
1311 -- with Is_Generic_Actual_Type and generate spurious errors.
1312 -- (see sem_ch8.Analyze_Package_Renaming and sem_type.covers)
1315 Set_Associated_Node_For_Itype (T, Exp);
1318 Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
1320 -- nothing needs to be done for private types with unknown discriminants
1321 -- if the underlying type is not an unconstrained composite type.
1323 elsif Is_Private_Type (Unc_Type)
1324 and then Has_Unknown_Discriminants (Unc_Type)
1325 and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
1326 or else Is_Constrained (Underlying_Type (Unc_Type)))
1330 -- Case of derived type with unknown discriminants where the parent type
1331 -- also has unknown discriminants.
1333 elsif Is_Record_Type (Unc_Type)
1334 and then not Is_Class_Wide_Type (Unc_Type)
1335 and then Has_Unknown_Discriminants (Unc_Type)
1336 and then Has_Unknown_Discriminants (Underlying_Type (Unc_Type))
1338 -- Nothing to be done if no underlying record view available
1340 if No (Underlying_Record_View (Unc_Type)) then
1343 -- Otherwise use the Underlying_Record_View to create the proper
1344 -- constrained subtype for an object of a derived type with unknown
1348 Remove_Side_Effects (Exp);
1349 Rewrite (Subtype_Indic,
1350 Make_Subtype_From_Expr (Exp, Underlying_Record_View (Unc_Type)));
1353 -- Renamings of class-wide interface types require no equivalent
1354 -- constrained type declarations because we only need to reference
1355 -- the tag component associated with the interface.
1358 and then Nkind (N) = N_Object_Renaming_Declaration
1359 and then Is_Interface (Unc_Type)
1361 pragma Assert (Is_Class_Wide_Type (Unc_Type));
1364 -- In Ada95, nothing to be done if the type of the expression is
1365 -- limited, because in this case the expression cannot be copied,
1366 -- and its use can only be by reference.
1368 -- In Ada2005, the context can be an object declaration whose expression
1369 -- is a function that returns in place. If the nominal subtype has
1370 -- unknown discriminants, the call still provides constraints on the
1371 -- object, and we have to create an actual subtype from it.
1373 -- If the type is class-wide, the expression is dynamically tagged and
1374 -- we do not create an actual subtype either. Ditto for an interface.
1376 elsif Is_Limited_Type (Exp_Typ)
1378 (Is_Class_Wide_Type (Exp_Typ)
1379 or else Is_Interface (Exp_Typ)
1380 or else not Has_Unknown_Discriminants (Exp_Typ)
1381 or else not Is_Composite_Type (Unc_Type))
1385 -- For limited objects initialized with build in place function calls,
1386 -- nothing to be done; otherwise we prematurely introduce an N_Reference
1387 -- node in the expression initializing the object, which breaks the
1388 -- circuitry that detects and adds the additional arguments to the
1391 elsif Is_Build_In_Place_Function_Call (Exp) then
1395 Remove_Side_Effects (Exp);
1396 Rewrite (Subtype_Indic,
1397 Make_Subtype_From_Expr (Exp, Unc_Type));
1399 end Expand_Subtype_From_Expr;
1401 --------------------
1402 -- Find_Init_Call --
1403 --------------------
1405 function Find_Init_Call
1407 Rep_Clause : Node_Id) return Node_Id
1409 Typ : constant Entity_Id := Etype (Var);
1411 Init_Proc : Entity_Id;
1412 -- Initialization procedure for Typ
1414 function Find_Init_Call_In_List (From : Node_Id) return Node_Id;
1415 -- Look for init call for Var starting at From and scanning the
1416 -- enclosing list until Rep_Clause or the end of the list is reached.
1418 ----------------------------
1419 -- Find_Init_Call_In_List --
1420 ----------------------------
1422 function Find_Init_Call_In_List (From : Node_Id) return Node_Id is
1423 Init_Call : Node_Id;
1427 while Present (Init_Call) and then Init_Call /= Rep_Clause loop
1428 if Nkind (Init_Call) = N_Procedure_Call_Statement
1429 and then Is_Entity_Name (Name (Init_Call))
1430 and then Entity (Name (Init_Call)) = Init_Proc
1438 end Find_Init_Call_In_List;
1440 Init_Call : Node_Id;
1442 -- Start of processing for Find_Init_Call
1445 if not Has_Non_Null_Base_Init_Proc (Typ) then
1446 -- No init proc for the type, so obviously no call to be found
1451 Init_Proc := Base_Init_Proc (Typ);
1453 -- First scan the list containing the declaration of Var
1455 Init_Call := Find_Init_Call_In_List (From => Next (Parent (Var)));
1457 -- If not found, also look on Var's freeze actions list, if any, since
1458 -- the init call may have been moved there (case of an address clause
1459 -- applying to Var).
1461 if No (Init_Call) and then Present (Freeze_Node (Var)) then
1462 Init_Call := Find_Init_Call_In_List
1463 (First (Actions (Freeze_Node (Var))));
1469 ------------------------
1470 -- Find_Interface_ADT --
1471 ------------------------
1473 function Find_Interface_ADT
1475 Iface : Entity_Id) return Elmt_Id
1478 Typ : Entity_Id := T;
1481 pragma Assert (Is_Interface (Iface));
1483 -- Handle private types
1485 if Has_Private_Declaration (Typ)
1486 and then Present (Full_View (Typ))
1488 Typ := Full_View (Typ);
1491 -- Handle access types
1493 if Is_Access_Type (Typ) then
1494 Typ := Directly_Designated_Type (Typ);
1497 -- Handle task and protected types implementing interfaces
1499 if Is_Concurrent_Type (Typ) then
1500 Typ := Corresponding_Record_Type (Typ);
1504 (not Is_Class_Wide_Type (Typ)
1505 and then Ekind (Typ) /= E_Incomplete_Type);
1507 if Is_Ancestor (Iface, Typ) then
1508 return First_Elmt (Access_Disp_Table (Typ));
1512 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
1514 and then Present (Related_Type (Node (ADT)))
1515 and then Related_Type (Node (ADT)) /= Iface
1516 and then not Is_Ancestor (Iface, Related_Type (Node (ADT)))
1521 pragma Assert (Present (Related_Type (Node (ADT))));
1524 end Find_Interface_ADT;
1526 ------------------------
1527 -- Find_Interface_Tag --
1528 ------------------------
1530 function Find_Interface_Tag
1532 Iface : Entity_Id) return Entity_Id
1535 Found : Boolean := False;
1536 Typ : Entity_Id := T;
1538 procedure Find_Tag (Typ : Entity_Id);
1539 -- Internal subprogram used to recursively climb to the ancestors
1545 procedure Find_Tag (Typ : Entity_Id) is
1550 -- This routine does not handle the case in which the interface is an
1551 -- ancestor of Typ. That case is handled by the enclosing subprogram.
1553 pragma Assert (Typ /= Iface);
1555 -- Climb to the root type handling private types
1557 if Present (Full_View (Etype (Typ))) then
1558 if Full_View (Etype (Typ)) /= Typ then
1559 Find_Tag (Full_View (Etype (Typ)));
1562 elsif Etype (Typ) /= Typ then
1563 Find_Tag (Etype (Typ));
1566 -- Traverse the list of interfaces implemented by the type
1569 and then Present (Interfaces (Typ))
1570 and then not (Is_Empty_Elmt_List (Interfaces (Typ)))
1572 -- Skip the tag associated with the primary table
1574 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
1575 AI_Tag := Next_Tag_Component (First_Tag_Component (Typ));
1576 pragma Assert (Present (AI_Tag));
1578 AI_Elmt := First_Elmt (Interfaces (Typ));
1579 while Present (AI_Elmt) loop
1580 AI := Node (AI_Elmt);
1582 if AI = Iface or else Is_Ancestor (Iface, AI) then
1587 AI_Tag := Next_Tag_Component (AI_Tag);
1588 Next_Elmt (AI_Elmt);
1593 -- Start of processing for Find_Interface_Tag
1596 pragma Assert (Is_Interface (Iface));
1598 -- Handle access types
1600 if Is_Access_Type (Typ) then
1601 Typ := Directly_Designated_Type (Typ);
1604 -- Handle class-wide types
1606 if Is_Class_Wide_Type (Typ) then
1607 Typ := Root_Type (Typ);
1610 -- Handle private types
1612 if Has_Private_Declaration (Typ)
1613 and then Present (Full_View (Typ))
1615 Typ := Full_View (Typ);
1618 -- Handle entities from the limited view
1620 if Ekind (Typ) = E_Incomplete_Type then
1621 pragma Assert (Present (Non_Limited_View (Typ)));
1622 Typ := Non_Limited_View (Typ);
1625 -- Handle task and protected types implementing interfaces
1627 if Is_Concurrent_Type (Typ) then
1628 Typ := Corresponding_Record_Type (Typ);
1631 -- If the interface is an ancestor of the type, then it shared the
1632 -- primary dispatch table.
1634 if Is_Ancestor (Iface, Typ) then
1635 pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
1636 return First_Tag_Component (Typ);
1638 -- Otherwise we need to search for its associated tag component
1642 pragma Assert (Found);
1645 end Find_Interface_Tag;
1651 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
1653 Typ : Entity_Id := T;
1657 if Is_Class_Wide_Type (Typ) then
1658 Typ := Root_Type (Typ);
1661 Typ := Underlying_Type (Typ);
1663 -- Loop through primitive operations
1665 Prim := First_Elmt (Primitive_Operations (Typ));
1666 while Present (Prim) loop
1669 -- We can retrieve primitive operations by name if it is an internal
1670 -- name. For equality we must check that both of its operands have
1671 -- the same type, to avoid confusion with user-defined equalities
1672 -- than may have a non-symmetric signature.
1674 exit when Chars (Op) = Name
1677 or else Etype (First_Entity (Op)) = Etype (Last_Entity (Op)));
1681 -- Raise Program_Error if no primitive found
1684 raise Program_Error;
1695 function Find_Prim_Op
1697 Name : TSS_Name_Type) return Entity_Id
1700 Typ : Entity_Id := T;
1703 if Is_Class_Wide_Type (Typ) then
1704 Typ := Root_Type (Typ);
1707 Typ := Underlying_Type (Typ);
1709 Prim := First_Elmt (Primitive_Operations (Typ));
1710 while not Is_TSS (Node (Prim), Name) loop
1713 -- Raise program error if no primitive found
1716 raise Program_Error;
1723 ----------------------------
1724 -- Find_Protection_Object --
1725 ----------------------------
1727 function Find_Protection_Object (Scop : Entity_Id) return Entity_Id is
1732 while Present (S) loop
1733 if (Ekind (S) = E_Entry
1734 or else Ekind (S) = E_Entry_Family
1735 or else Ekind (S) = E_Function
1736 or else Ekind (S) = E_Procedure)
1737 and then Present (Protection_Object (S))
1739 return Protection_Object (S);
1745 -- If we do not find a Protection object in the scope chain, then
1746 -- something has gone wrong, most likely the object was never created.
1748 raise Program_Error;
1749 end Find_Protection_Object;
1751 ----------------------
1752 -- Force_Evaluation --
1753 ----------------------
1755 procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
1757 Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
1758 end Force_Evaluation;
1760 ------------------------
1761 -- Generate_Poll_Call --
1762 ------------------------
1764 procedure Generate_Poll_Call (N : Node_Id) is
1766 -- No poll call if polling not active
1768 if not Polling_Required then
1771 -- Otherwise generate require poll call
1774 Insert_Before_And_Analyze (N,
1775 Make_Procedure_Call_Statement (Sloc (N),
1776 Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
1778 end Generate_Poll_Call;
1780 ---------------------------------
1781 -- Get_Current_Value_Condition --
1782 ---------------------------------
1784 -- Note: the implementation of this procedure is very closely tied to the
1785 -- implementation of Set_Current_Value_Condition. In the Get procedure, we
1786 -- interpret Current_Value fields set by the Set procedure, so the two
1787 -- procedures need to be closely coordinated.
1789 procedure Get_Current_Value_Condition
1794 Loc : constant Source_Ptr := Sloc (Var);
1795 Ent : constant Entity_Id := Entity (Var);
1797 procedure Process_Current_Value_Condition
1800 -- N is an expression which holds either True (S = True) or False (S =
1801 -- False) in the condition. This procedure digs out the expression and
1802 -- if it refers to Ent, sets Op and Val appropriately.
1804 -------------------------------------
1805 -- Process_Current_Value_Condition --
1806 -------------------------------------
1808 procedure Process_Current_Value_Condition
1819 -- Deal with NOT operators, inverting sense
1821 while Nkind (Cond) = N_Op_Not loop
1822 Cond := Right_Opnd (Cond);
1826 -- Deal with AND THEN and AND cases
1828 if Nkind (Cond) = N_And_Then
1829 or else Nkind (Cond) = N_Op_And
1831 -- Don't ever try to invert a condition that is of the form
1832 -- of an AND or AND THEN (since we are not doing sufficiently
1833 -- general processing to allow this).
1835 if Sens = False then
1841 -- Recursively process AND and AND THEN branches
1843 Process_Current_Value_Condition (Left_Opnd (Cond), True);
1845 if Op /= N_Empty then
1849 Process_Current_Value_Condition (Right_Opnd (Cond), True);
1852 -- Case of relational operator
1854 elsif Nkind (Cond) in N_Op_Compare then
1857 -- Invert sense of test if inverted test
1859 if Sens = False then
1861 when N_Op_Eq => Op := N_Op_Ne;
1862 when N_Op_Ne => Op := N_Op_Eq;
1863 when N_Op_Lt => Op := N_Op_Ge;
1864 when N_Op_Gt => Op := N_Op_Le;
1865 when N_Op_Le => Op := N_Op_Gt;
1866 when N_Op_Ge => Op := N_Op_Lt;
1867 when others => raise Program_Error;
1871 -- Case of entity op value
1873 if Is_Entity_Name (Left_Opnd (Cond))
1874 and then Ent = Entity (Left_Opnd (Cond))
1875 and then Compile_Time_Known_Value (Right_Opnd (Cond))
1877 Val := Right_Opnd (Cond);
1879 -- Case of value op entity
1881 elsif Is_Entity_Name (Right_Opnd (Cond))
1882 and then Ent = Entity (Right_Opnd (Cond))
1883 and then Compile_Time_Known_Value (Left_Opnd (Cond))
1885 Val := Left_Opnd (Cond);
1887 -- We are effectively swapping operands
1890 when N_Op_Eq => null;
1891 when N_Op_Ne => null;
1892 when N_Op_Lt => Op := N_Op_Gt;
1893 when N_Op_Gt => Op := N_Op_Lt;
1894 when N_Op_Le => Op := N_Op_Ge;
1895 when N_Op_Ge => Op := N_Op_Le;
1896 when others => raise Program_Error;
1905 -- Case of Boolean variable reference, return as though the
1906 -- reference had said var = True.
1909 if Is_Entity_Name (Cond)
1910 and then Ent = Entity (Cond)
1912 Val := New_Occurrence_Of (Standard_True, Sloc (Cond));
1914 if Sens = False then
1921 end Process_Current_Value_Condition;
1923 -- Start of processing for Get_Current_Value_Condition
1929 -- Immediate return, nothing doing, if this is not an object
1931 if Ekind (Ent) not in Object_Kind then
1935 -- Otherwise examine current value
1938 CV : constant Node_Id := Current_Value (Ent);
1943 -- If statement. Condition is known true in THEN section, known False
1944 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
1946 if Nkind (CV) = N_If_Statement then
1948 -- Before start of IF statement
1950 if Loc < Sloc (CV) then
1953 -- After end of IF statement
1955 elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then
1959 -- At this stage we know that we are within the IF statement, but
1960 -- unfortunately, the tree does not record the SLOC of the ELSE so
1961 -- we cannot use a simple SLOC comparison to distinguish between
1962 -- the then/else statements, so we have to climb the tree.
1969 while Parent (N) /= CV loop
1972 -- If we fall off the top of the tree, then that's odd, but
1973 -- perhaps it could occur in some error situation, and the
1974 -- safest response is simply to assume that the outcome of
1975 -- the condition is unknown. No point in bombing during an
1976 -- attempt to optimize things.
1983 -- Now we have N pointing to a node whose parent is the IF
1984 -- statement in question, so now we can tell if we are within
1985 -- the THEN statements.
1987 if Is_List_Member (N)
1988 and then List_Containing (N) = Then_Statements (CV)
1992 -- If the variable reference does not come from source, we
1993 -- cannot reliably tell whether it appears in the else part.
1994 -- In particular, if it appears in generated code for a node
1995 -- that requires finalization, it may be attached to a list
1996 -- that has not been yet inserted into the code. For now,
1997 -- treat it as unknown.
1999 elsif not Comes_From_Source (N) then
2002 -- Otherwise we must be in ELSIF or ELSE part
2009 -- ELSIF part. Condition is known true within the referenced
2010 -- ELSIF, known False in any subsequent ELSIF or ELSE part, and
2011 -- unknown before the ELSE part or after the IF statement.
2013 elsif Nkind (CV) = N_Elsif_Part then
2016 -- Before start of ELSIF part
2018 if Loc < Sloc (CV) then
2021 -- After end of IF statement
2023 elsif Loc >= Sloc (Stm) +
2024 Text_Ptr (UI_To_Int (End_Span (Stm)))
2029 -- Again we lack the SLOC of the ELSE, so we need to climb the
2030 -- tree to see if we are within the ELSIF part in question.
2037 while Parent (N) /= Stm loop
2040 -- If we fall off the top of the tree, then that's odd, but
2041 -- perhaps it could occur in some error situation, and the
2042 -- safest response is simply to assume that the outcome of
2043 -- the condition is unknown. No point in bombing during an
2044 -- attempt to optimize things.
2051 -- Now we have N pointing to a node whose parent is the IF
2052 -- statement in question, so see if is the ELSIF part we want.
2053 -- the THEN statements.
2058 -- Otherwise we must be in subsequent ELSIF or ELSE part
2065 -- Iteration scheme of while loop. The condition is known to be
2066 -- true within the body of the loop.
2068 elsif Nkind (CV) = N_Iteration_Scheme then
2070 Loop_Stmt : constant Node_Id := Parent (CV);
2073 -- Before start of body of loop
2075 if Loc < Sloc (Loop_Stmt) then
2078 -- After end of LOOP statement
2080 elsif Loc >= Sloc (End_Label (Loop_Stmt)) then
2083 -- We are within the body of the loop
2090 -- All other cases of Current_Value settings
2096 -- If we fall through here, then we have a reportable condition, Sens
2097 -- is True if the condition is true and False if it needs inverting.
2099 Process_Current_Value_Condition (Condition (CV), Sens);
2101 end Get_Current_Value_Condition;
2103 ---------------------------------
2104 -- Has_Controlled_Coextensions --
2105 ---------------------------------
2107 function Has_Controlled_Coextensions (Typ : Entity_Id) return Boolean is
2112 -- Only consider record types
2114 if Ekind (Typ) /= E_Record_Type
2115 and then Ekind (Typ) /= E_Record_Subtype
2120 if Has_Discriminants (Typ) then
2121 Discr := First_Discriminant (Typ);
2122 while Present (Discr) loop
2123 D_Typ := Etype (Discr);
2125 if Ekind (D_Typ) = E_Anonymous_Access_Type
2127 (Is_Controlled (Directly_Designated_Type (D_Typ))
2129 Is_Concurrent_Type (Directly_Designated_Type (D_Typ)))
2134 Next_Discriminant (Discr);
2139 end Has_Controlled_Coextensions;
2141 --------------------
2142 -- Homonym_Number --
2143 --------------------
2145 function Homonym_Number (Subp : Entity_Id) return Nat is
2151 Hom := Homonym (Subp);
2152 while Present (Hom) loop
2153 if Scope (Hom) = Scope (Subp) then
2157 Hom := Homonym (Hom);
2163 ------------------------------
2164 -- In_Unconditional_Context --
2165 ------------------------------
2167 function In_Unconditional_Context (Node : Node_Id) return Boolean is
2172 while Present (P) loop
2174 when N_Subprogram_Body =>
2177 when N_If_Statement =>
2180 when N_Loop_Statement =>
2183 when N_Case_Statement =>
2192 end In_Unconditional_Context;
2198 procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
2200 if Present (Ins_Action) then
2201 Insert_Actions (Assoc_Node, New_List (Ins_Action));
2205 -- Version with check(s) suppressed
2207 procedure Insert_Action
2208 (Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
2211 Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
2214 --------------------
2215 -- Insert_Actions --
2216 --------------------
2218 procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
2222 Wrapped_Node : Node_Id := Empty;
2225 if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
2229 -- Ignore insert of actions from inside default expression (or other
2230 -- similar "spec expression") in the special spec-expression analyze
2231 -- mode. Any insertions at this point have no relevance, since we are
2232 -- only doing the analyze to freeze the types of any static expressions.
2233 -- See section "Handling of Default Expressions" in the spec of package
2234 -- Sem for further details.
2236 if In_Spec_Expression then
2240 -- If the action derives from stuff inside a record, then the actions
2241 -- are attached to the current scope, to be inserted and analyzed on
2242 -- exit from the scope. The reason for this is that we may also
2243 -- be generating freeze actions at the same time, and they must
2244 -- eventually be elaborated in the correct order.
2246 if Is_Record_Type (Current_Scope)
2247 and then not Is_Frozen (Current_Scope)
2249 if No (Scope_Stack.Table
2250 (Scope_Stack.Last).Pending_Freeze_Actions)
2252 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
2257 Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
2263 -- We now intend to climb up the tree to find the right point to
2264 -- insert the actions. We start at Assoc_Node, unless this node is
2265 -- a subexpression in which case we start with its parent. We do this
2266 -- for two reasons. First it speeds things up. Second, if Assoc_Node
2267 -- is itself one of the special nodes like N_And_Then, then we assume
2268 -- that an initial request to insert actions for such a node does not
2269 -- expect the actions to get deposited in the node for later handling
2270 -- when the node is expanded, since clearly the node is being dealt
2271 -- with by the caller. Note that in the subexpression case, N is
2272 -- always the child we came from.
2274 -- N_Raise_xxx_Error is an annoying special case, it is a statement
2275 -- if it has type Standard_Void_Type, and a subexpression otherwise.
2276 -- otherwise. Procedure attribute references are also statements.
2278 if Nkind (Assoc_Node) in N_Subexpr
2279 and then (Nkind (Assoc_Node) in N_Raise_xxx_Error
2280 or else Etype (Assoc_Node) /= Standard_Void_Type)
2281 and then (Nkind (Assoc_Node) /= N_Attribute_Reference
2283 not Is_Procedure_Attribute_Name
2284 (Attribute_Name (Assoc_Node)))
2286 P := Assoc_Node; -- ??? does not agree with above!
2287 N := Parent (Assoc_Node);
2289 -- Non-subexpression case. Note that N is initially Empty in this
2290 -- case (N is only guaranteed Non-Empty in the subexpr case).
2297 -- Capture root of the transient scope
2299 if Scope_Is_Transient then
2300 Wrapped_Node := Node_To_Be_Wrapped;
2304 pragma Assert (Present (P));
2308 -- Case of right operand of AND THEN or OR ELSE. Put the actions
2309 -- in the Actions field of the right operand. They will be moved
2310 -- out further when the AND THEN or OR ELSE operator is expanded.
2311 -- Nothing special needs to be done for the left operand since
2312 -- in that case the actions are executed unconditionally.
2314 when N_Short_Circuit =>
2315 if N = Right_Opnd (P) then
2317 -- We are now going to either append the actions to the
2318 -- actions field of the short-circuit operation. We will
2319 -- also analyze the actions now.
2321 -- This analysis is really too early, the proper thing would
2322 -- be to just park them there now, and only analyze them if
2323 -- we find we really need them, and to it at the proper
2324 -- final insertion point. However attempting to this proved
2325 -- tricky, so for now we just kill current values before and
2326 -- after the analyze call to make sure we avoid peculiar
2327 -- optimizations from this out of order insertion.
2329 Kill_Current_Values;
2331 if Present (Actions (P)) then
2332 Insert_List_After_And_Analyze
2333 (Last (Actions (P)), Ins_Actions);
2335 Set_Actions (P, Ins_Actions);
2336 Analyze_List (Actions (P));
2339 Kill_Current_Values;
2344 -- Then or Else operand of conditional expression. Add actions to
2345 -- Then_Actions or Else_Actions field as appropriate. The actions
2346 -- will be moved further out when the conditional is expanded.
2348 when N_Conditional_Expression =>
2350 ThenX : constant Node_Id := Next (First (Expressions (P)));
2351 ElseX : constant Node_Id := Next (ThenX);
2354 -- Actions belong to the then expression, temporarily
2355 -- place them as Then_Actions of the conditional expr.
2356 -- They will be moved to the proper place later when
2357 -- the conditional expression is expanded.
2360 if Present (Then_Actions (P)) then
2361 Insert_List_After_And_Analyze
2362 (Last (Then_Actions (P)), Ins_Actions);
2364 Set_Then_Actions (P, Ins_Actions);
2365 Analyze_List (Then_Actions (P));
2370 -- Actions belong to the else expression, temporarily
2371 -- place them as Else_Actions of the conditional expr.
2372 -- They will be moved to the proper place later when
2373 -- the conditional expression is expanded.
2375 elsif N = ElseX then
2376 if Present (Else_Actions (P)) then
2377 Insert_List_After_And_Analyze
2378 (Last (Else_Actions (P)), Ins_Actions);
2380 Set_Else_Actions (P, Ins_Actions);
2381 Analyze_List (Else_Actions (P));
2386 -- Actions belong to the condition. In this case they are
2387 -- unconditionally executed, and so we can continue the
2388 -- search for the proper insert point.
2395 -- Case of appearing in the condition of a while expression or
2396 -- elsif. We insert the actions into the Condition_Actions field.
2397 -- They will be moved further out when the while loop or elsif
2400 when N_Iteration_Scheme |
2403 if N = Condition (P) then
2404 if Present (Condition_Actions (P)) then
2405 Insert_List_After_And_Analyze
2406 (Last (Condition_Actions (P)), Ins_Actions);
2408 Set_Condition_Actions (P, Ins_Actions);
2410 -- Set the parent of the insert actions explicitly.
2411 -- This is not a syntactic field, but we need the
2412 -- parent field set, in particular so that freeze
2413 -- can understand that it is dealing with condition
2414 -- actions, and properly insert the freezing actions.
2416 Set_Parent (Ins_Actions, P);
2417 Analyze_List (Condition_Actions (P));
2423 -- Statements, declarations, pragmas, representation clauses
2428 N_Procedure_Call_Statement |
2429 N_Statement_Other_Than_Procedure_Call |
2435 -- Representation_Clause
2438 N_Attribute_Definition_Clause |
2439 N_Enumeration_Representation_Clause |
2440 N_Record_Representation_Clause |
2444 N_Abstract_Subprogram_Declaration |
2446 N_Exception_Declaration |
2447 N_Exception_Renaming_Declaration |
2448 N_Formal_Abstract_Subprogram_Declaration |
2449 N_Formal_Concrete_Subprogram_Declaration |
2450 N_Formal_Object_Declaration |
2451 N_Formal_Type_Declaration |
2452 N_Full_Type_Declaration |
2453 N_Function_Instantiation |
2454 N_Generic_Function_Renaming_Declaration |
2455 N_Generic_Package_Declaration |
2456 N_Generic_Package_Renaming_Declaration |
2457 N_Generic_Procedure_Renaming_Declaration |
2458 N_Generic_Subprogram_Declaration |
2459 N_Implicit_Label_Declaration |
2460 N_Incomplete_Type_Declaration |
2461 N_Number_Declaration |
2462 N_Object_Declaration |
2463 N_Object_Renaming_Declaration |
2465 N_Package_Body_Stub |
2466 N_Package_Declaration |
2467 N_Package_Instantiation |
2468 N_Package_Renaming_Declaration |
2469 N_Private_Extension_Declaration |
2470 N_Private_Type_Declaration |
2471 N_Procedure_Instantiation |
2473 N_Protected_Body_Stub |
2474 N_Protected_Type_Declaration |
2475 N_Single_Task_Declaration |
2477 N_Subprogram_Body_Stub |
2478 N_Subprogram_Declaration |
2479 N_Subprogram_Renaming_Declaration |
2480 N_Subtype_Declaration |
2483 N_Task_Type_Declaration |
2485 -- Freeze entity behaves like a declaration or statement
2489 -- Do not insert here if the item is not a list member (this
2490 -- happens for example with a triggering statement, and the
2491 -- proper approach is to insert before the entire select).
2493 if not Is_List_Member (P) then
2496 -- Do not insert if parent of P is an N_Component_Association
2497 -- node (i.e. we are in the context of an N_Aggregate or
2498 -- N_Extension_Aggregate node. In this case we want to insert
2499 -- before the entire aggregate.
2501 elsif Nkind (Parent (P)) = N_Component_Association then
2504 -- Do not insert if the parent of P is either an N_Variant
2505 -- node or an N_Record_Definition node, meaning in either
2506 -- case that P is a member of a component list, and that
2507 -- therefore the actions should be inserted outside the
2508 -- complete record declaration.
2510 elsif Nkind (Parent (P)) = N_Variant
2511 or else Nkind (Parent (P)) = N_Record_Definition
2515 -- Do not insert freeze nodes within the loop generated for
2516 -- an aggregate, because they may be elaborated too late for
2517 -- subsequent use in the back end: within a package spec the
2518 -- loop is part of the elaboration procedure and is only
2519 -- elaborated during the second pass.
2520 -- If the loop comes from source, or the entity is local to
2521 -- the loop itself it must remain within.
2523 elsif Nkind (Parent (P)) = N_Loop_Statement
2524 and then not Comes_From_Source (Parent (P))
2525 and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
2527 Scope (Entity (First (Ins_Actions))) /= Current_Scope
2531 -- Otherwise we can go ahead and do the insertion
2533 elsif P = Wrapped_Node then
2534 Store_Before_Actions_In_Scope (Ins_Actions);
2538 Insert_List_Before_And_Analyze (P, Ins_Actions);
2542 -- A special case, N_Raise_xxx_Error can act either as a
2543 -- statement or a subexpression. We tell the difference
2544 -- by looking at the Etype. It is set to Standard_Void_Type
2545 -- in the statement case.
2548 N_Raise_xxx_Error =>
2549 if Etype (P) = Standard_Void_Type then
2550 if P = Wrapped_Node then
2551 Store_Before_Actions_In_Scope (Ins_Actions);
2553 Insert_List_Before_And_Analyze (P, Ins_Actions);
2558 -- In the subexpression case, keep climbing
2564 -- If a component association appears within a loop created for
2565 -- an array aggregate, attach the actions to the association so
2566 -- they can be subsequently inserted within the loop. For other
2567 -- component associations insert outside of the aggregate. For
2568 -- an association that will generate a loop, its Loop_Actions
2569 -- attribute is already initialized (see exp_aggr.adb).
2571 -- The list of loop_actions can in turn generate additional ones,
2572 -- that are inserted before the associated node. If the associated
2573 -- node is outside the aggregate, the new actions are collected
2574 -- at the end of the loop actions, to respect the order in which
2575 -- they are to be elaborated.
2578 N_Component_Association =>
2579 if Nkind (Parent (P)) = N_Aggregate
2580 and then Present (Loop_Actions (P))
2582 if Is_Empty_List (Loop_Actions (P)) then
2583 Set_Loop_Actions (P, Ins_Actions);
2584 Analyze_List (Ins_Actions);
2591 -- Check whether these actions were generated
2592 -- by a declaration that is part of the loop_
2593 -- actions for the component_association.
2596 while Present (Decl) loop
2597 exit when Parent (Decl) = P
2598 and then Is_List_Member (Decl)
2600 List_Containing (Decl) = Loop_Actions (P);
2601 Decl := Parent (Decl);
2604 if Present (Decl) then
2605 Insert_List_Before_And_Analyze
2606 (Decl, Ins_Actions);
2608 Insert_List_After_And_Analyze
2609 (Last (Loop_Actions (P)), Ins_Actions);
2620 -- Another special case, an attribute denoting a procedure call
2623 N_Attribute_Reference =>
2624 if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
2625 if P = Wrapped_Node then
2626 Store_Before_Actions_In_Scope (Ins_Actions);
2628 Insert_List_Before_And_Analyze (P, Ins_Actions);
2633 -- In the subexpression case, keep climbing
2639 -- For all other node types, keep climbing tree
2643 N_Accept_Alternative |
2644 N_Access_Definition |
2645 N_Access_Function_Definition |
2646 N_Access_Procedure_Definition |
2647 N_Access_To_Object_Definition |
2650 N_Case_Statement_Alternative |
2651 N_Character_Literal |
2652 N_Compilation_Unit |
2653 N_Compilation_Unit_Aux |
2654 N_Component_Clause |
2655 N_Component_Declaration |
2656 N_Component_Definition |
2658 N_Constrained_Array_Definition |
2659 N_Decimal_Fixed_Point_Definition |
2660 N_Defining_Character_Literal |
2661 N_Defining_Identifier |
2662 N_Defining_Operator_Symbol |
2663 N_Defining_Program_Unit_Name |
2664 N_Delay_Alternative |
2665 N_Delta_Constraint |
2666 N_Derived_Type_Definition |
2668 N_Digits_Constraint |
2669 N_Discriminant_Association |
2670 N_Discriminant_Specification |
2672 N_Entry_Body_Formal_Part |
2673 N_Entry_Call_Alternative |
2674 N_Entry_Declaration |
2675 N_Entry_Index_Specification |
2676 N_Enumeration_Type_Definition |
2678 N_Exception_Handler |
2680 N_Explicit_Dereference |
2681 N_Extension_Aggregate |
2682 N_Floating_Point_Definition |
2683 N_Formal_Decimal_Fixed_Point_Definition |
2684 N_Formal_Derived_Type_Definition |
2685 N_Formal_Discrete_Type_Definition |
2686 N_Formal_Floating_Point_Definition |
2687 N_Formal_Modular_Type_Definition |
2688 N_Formal_Ordinary_Fixed_Point_Definition |
2689 N_Formal_Package_Declaration |
2690 N_Formal_Private_Type_Definition |
2691 N_Formal_Signed_Integer_Type_Definition |
2693 N_Function_Specification |
2694 N_Generic_Association |
2695 N_Handled_Sequence_Of_Statements |
2698 N_Index_Or_Discriminant_Constraint |
2699 N_Indexed_Component |
2703 N_Loop_Parameter_Specification |
2705 N_Modular_Type_Definition |
2731 N_Op_Shift_Right_Arithmetic |
2735 N_Ordinary_Fixed_Point_Definition |
2737 N_Package_Specification |
2738 N_Parameter_Association |
2739 N_Parameter_Specification |
2740 N_Pop_Constraint_Error_Label |
2741 N_Pop_Program_Error_Label |
2742 N_Pop_Storage_Error_Label |
2743 N_Pragma_Argument_Association |
2744 N_Procedure_Specification |
2745 N_Protected_Definition |
2746 N_Push_Constraint_Error_Label |
2747 N_Push_Program_Error_Label |
2748 N_Push_Storage_Error_Label |
2749 N_Qualified_Expression |
2751 N_Range_Constraint |
2753 N_Real_Range_Specification |
2754 N_Record_Definition |
2756 N_Selected_Component |
2757 N_Signed_Integer_Type_Definition |
2758 N_Single_Protected_Declaration |
2762 N_Subtype_Indication |
2765 N_Terminate_Alternative |
2766 N_Triggering_Alternative |
2768 N_Unchecked_Expression |
2769 N_Unchecked_Type_Conversion |
2770 N_Unconstrained_Array_Definition |
2773 N_Use_Package_Clause |
2777 N_Validate_Unchecked_Conversion |
2784 -- Make sure that inserted actions stay in the transient scope
2786 if P = Wrapped_Node then
2787 Store_Before_Actions_In_Scope (Ins_Actions);
2791 -- If we fall through above tests, keep climbing tree
2795 if Nkind (Parent (N)) = N_Subunit then
2797 -- This is the proper body corresponding to a stub. Insertion
2798 -- must be done at the point of the stub, which is in the decla-
2799 -- rative part of the parent unit.
2801 P := Corresponding_Stub (Parent (N));
2809 -- Version with check(s) suppressed
2811 procedure Insert_Actions
2812 (Assoc_Node : Node_Id;
2813 Ins_Actions : List_Id;
2814 Suppress : Check_Id)
2817 if Suppress = All_Checks then
2819 Svg : constant Suppress_Array := Scope_Suppress;
2821 Scope_Suppress := (others => True);
2822 Insert_Actions (Assoc_Node, Ins_Actions);
2823 Scope_Suppress := Svg;
2828 Svg : constant Boolean := Scope_Suppress (Suppress);
2830 Scope_Suppress (Suppress) := True;
2831 Insert_Actions (Assoc_Node, Ins_Actions);
2832 Scope_Suppress (Suppress) := Svg;
2837 --------------------------
2838 -- Insert_Actions_After --
2839 --------------------------
2841 procedure Insert_Actions_After
2842 (Assoc_Node : Node_Id;
2843 Ins_Actions : List_Id)
2846 if Scope_Is_Transient
2847 and then Assoc_Node = Node_To_Be_Wrapped
2849 Store_After_Actions_In_Scope (Ins_Actions);
2851 Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
2853 end Insert_Actions_After;
2855 ---------------------------------
2856 -- Insert_Library_Level_Action --
2857 ---------------------------------
2859 procedure Insert_Library_Level_Action (N : Node_Id) is
2860 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
2863 Push_Scope (Cunit_Entity (Main_Unit));
2864 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
2866 if No (Actions (Aux)) then
2867 Set_Actions (Aux, New_List (N));
2869 Append (N, Actions (Aux));
2874 end Insert_Library_Level_Action;
2876 ----------------------------------
2877 -- Insert_Library_Level_Actions --
2878 ----------------------------------
2880 procedure Insert_Library_Level_Actions (L : List_Id) is
2881 Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
2884 if Is_Non_Empty_List (L) then
2885 Push_Scope (Cunit_Entity (Main_Unit));
2886 -- ??? should this be Current_Sem_Unit instead of Main_Unit?
2888 if No (Actions (Aux)) then
2889 Set_Actions (Aux, L);
2892 Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
2897 end Insert_Library_Level_Actions;
2899 ----------------------
2900 -- Inside_Init_Proc --
2901 ----------------------
2903 function Inside_Init_Proc return Boolean is
2909 and then S /= Standard_Standard
2911 if Is_Init_Proc (S) then
2919 end Inside_Init_Proc;
2921 ----------------------------
2922 -- Is_All_Null_Statements --
2923 ----------------------------
2925 function Is_All_Null_Statements (L : List_Id) return Boolean is
2930 while Present (Stm) loop
2931 if Nkind (Stm) /= N_Null_Statement then
2939 end Is_All_Null_Statements;
2941 ----------------------------------
2942 -- Is_Library_Level_Tagged_Type --
2943 ----------------------------------
2945 function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean is
2947 return Is_Tagged_Type (Typ)
2948 and then Is_Library_Level_Entity (Typ);
2949 end Is_Library_Level_Tagged_Type;
2951 ----------------------------------
2952 -- Is_Possibly_Unaligned_Object --
2953 ----------------------------------
2955 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
2956 T : constant Entity_Id := Etype (N);
2959 -- If renamed object, apply test to underlying object
2961 if Is_Entity_Name (N)
2962 and then Is_Object (Entity (N))
2963 and then Present (Renamed_Object (Entity (N)))
2965 return Is_Possibly_Unaligned_Object (Renamed_Object (Entity (N)));
2968 -- Tagged and controlled types and aliased types are always aligned,
2969 -- as are concurrent types.
2972 or else Has_Controlled_Component (T)
2973 or else Is_Concurrent_Type (T)
2974 or else Is_Tagged_Type (T)
2975 or else Is_Controlled (T)
2980 -- If this is an element of a packed array, may be unaligned
2982 if Is_Ref_To_Bit_Packed_Array (N) then
2986 -- Case of component reference
2988 if Nkind (N) = N_Selected_Component then
2990 P : constant Node_Id := Prefix (N);
2991 C : constant Entity_Id := Entity (Selector_Name (N));
2996 -- If component reference is for an array with non-static bounds,
2997 -- then it is always aligned: we can only process unaligned
2998 -- arrays with static bounds (more accurately bounds known at
3001 if Is_Array_Type (T)
3002 and then not Compile_Time_Known_Bounds (T)
3007 -- If component is aliased, it is definitely properly aligned
3009 if Is_Aliased (C) then
3013 -- If component is for a type implemented as a scalar, and the
3014 -- record is packed, and the component is other than the first
3015 -- component of the record, then the component may be unaligned.
3017 if Is_Packed (Etype (P))
3018 and then Represented_As_Scalar (Etype (C))
3019 and then First_Entity (Scope (C)) /= C
3024 -- Compute maximum possible alignment for T
3026 -- If alignment is known, then that settles things
3028 if Known_Alignment (T) then
3029 M := UI_To_Int (Alignment (T));
3031 -- If alignment is not known, tentatively set max alignment
3034 M := Ttypes.Maximum_Alignment;
3036 -- We can reduce this if the Esize is known since the default
3037 -- alignment will never be more than the smallest power of 2
3038 -- that does not exceed this Esize value.
3040 if Known_Esize (T) then
3041 S := UI_To_Int (Esize (T));
3043 while (M / 2) >= S loop
3049 -- If the component reference is for a record that has a specified
3050 -- alignment, and we either know it is too small, or cannot tell,
3051 -- then the component may be unaligned
3053 if Known_Alignment (Etype (P))
3054 and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
3055 and then M > Alignment (Etype (P))
3060 -- Case of component clause present which may specify an
3061 -- unaligned position.
3063 if Present (Component_Clause (C)) then
3065 -- Otherwise we can do a test to make sure that the actual
3066 -- start position in the record, and the length, are both
3067 -- consistent with the required alignment. If not, we know
3068 -- that we are unaligned.
3071 Align_In_Bits : constant Nat := M * System_Storage_Unit;
3073 if Component_Bit_Offset (C) mod Align_In_Bits /= 0
3074 or else Esize (C) mod Align_In_Bits /= 0
3081 -- Otherwise, for a component reference, test prefix
3083 return Is_Possibly_Unaligned_Object (P);
3086 -- If not a component reference, must be aligned
3091 end Is_Possibly_Unaligned_Object;
3093 ---------------------------------
3094 -- Is_Possibly_Unaligned_Slice --
3095 ---------------------------------
3097 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean is
3099 -- Go to renamed object
3101 if Is_Entity_Name (N)
3102 and then Is_Object (Entity (N))
3103 and then Present (Renamed_Object (Entity (N)))
3105 return Is_Possibly_Unaligned_Slice (Renamed_Object (Entity (N)));
3108 -- The reference must be a slice
3110 if Nkind (N) /= N_Slice then
3114 -- Always assume the worst for a nested record component with a
3115 -- component clause, which gigi/gcc does not appear to handle well.
3116 -- It is not clear why this special test is needed at all ???
3118 if Nkind (Prefix (N)) = N_Selected_Component
3119 and then Nkind (Prefix (Prefix (N))) = N_Selected_Component
3121 Present (Component_Clause (Entity (Selector_Name (Prefix (N)))))
3126 -- We only need to worry if the target has strict alignment
3128 if not Target_Strict_Alignment then
3132 -- If it is a slice, then look at the array type being sliced
3135 Sarr : constant Node_Id := Prefix (N);
3136 -- Prefix of the slice, i.e. the array being sliced
3138 Styp : constant Entity_Id := Etype (Prefix (N));
3139 -- Type of the array being sliced
3145 -- The problems arise if the array object that is being sliced
3146 -- is a component of a record or array, and we cannot guarantee
3147 -- the alignment of the array within its containing object.
3149 -- To investigate this, we look at successive prefixes to see
3150 -- if we have a worrisome indexed or selected component.
3154 -- Case of array is part of an indexed component reference
3156 if Nkind (Pref) = N_Indexed_Component then
3157 Ptyp := Etype (Prefix (Pref));
3159 -- The only problematic case is when the array is packed,
3160 -- in which case we really know nothing about the alignment
3161 -- of individual components.
3163 if Is_Bit_Packed_Array (Ptyp) then
3167 -- Case of array is part of a selected component reference
3169 elsif Nkind (Pref) = N_Selected_Component then
3170 Ptyp := Etype (Prefix (Pref));
3172 -- We are definitely in trouble if the record in question
3173 -- has an alignment, and either we know this alignment is
3174 -- inconsistent with the alignment of the slice, or we
3175 -- don't know what the alignment of the slice should be.
3177 if Known_Alignment (Ptyp)
3178 and then (Unknown_Alignment (Styp)
3179 or else Alignment (Styp) > Alignment (Ptyp))
3184 -- We are in potential trouble if the record type is packed.
3185 -- We could special case when we know that the array is the
3186 -- first component, but that's not such a simple case ???
3188 if Is_Packed (Ptyp) then
3192 -- We are in trouble if there is a component clause, and
3193 -- either we do not know the alignment of the slice, or
3194 -- the alignment of the slice is inconsistent with the
3195 -- bit position specified by the component clause.
3198 Field : constant Entity_Id := Entity (Selector_Name (Pref));
3200 if Present (Component_Clause (Field))
3202 (Unknown_Alignment (Styp)
3204 (Component_Bit_Offset (Field) mod
3205 (System_Storage_Unit * Alignment (Styp))) /= 0)
3211 -- For cases other than selected or indexed components we
3212 -- know we are OK, since no issues arise over alignment.
3218 -- We processed an indexed component or selected component
3219 -- reference that looked safe, so keep checking prefixes.
3221 Pref := Prefix (Pref);
3224 end Is_Possibly_Unaligned_Slice;
3226 --------------------------------
3227 -- Is_Ref_To_Bit_Packed_Array --
3228 --------------------------------
3230 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean is
3235 if Is_Entity_Name (N)
3236 and then Is_Object (Entity (N))
3237 and then Present (Renamed_Object (Entity (N)))
3239 return Is_Ref_To_Bit_Packed_Array (Renamed_Object (Entity (N)));
3242 if Nkind (N) = N_Indexed_Component
3244 Nkind (N) = N_Selected_Component
3246 if Is_Bit_Packed_Array (Etype (Prefix (N))) then
3249 Result := Is_Ref_To_Bit_Packed_Array (Prefix (N));
3252 if Result and then Nkind (N) = N_Indexed_Component then
3253 Expr := First (Expressions (N));
3254 while Present (Expr) loop
3255 Force_Evaluation (Expr);
3265 end Is_Ref_To_Bit_Packed_Array;
3267 --------------------------------
3268 -- Is_Ref_To_Bit_Packed_Slice --
3269 --------------------------------
3271 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean is
3273 if Nkind (N) = N_Type_Conversion then
3274 return Is_Ref_To_Bit_Packed_Slice (Expression (N));
3276 elsif Is_Entity_Name (N)
3277 and then Is_Object (Entity (N))
3278 and then Present (Renamed_Object (Entity (N)))
3280 return Is_Ref_To_Bit_Packed_Slice (Renamed_Object (Entity (N)));
3282 elsif Nkind (N) = N_Slice
3283 and then Is_Bit_Packed_Array (Etype (Prefix (N)))
3287 elsif Nkind (N) = N_Indexed_Component
3289 Nkind (N) = N_Selected_Component
3291 return Is_Ref_To_Bit_Packed_Slice (Prefix (N));
3296 end Is_Ref_To_Bit_Packed_Slice;
3298 -----------------------
3299 -- Is_Renamed_Object --
3300 -----------------------
3302 function Is_Renamed_Object (N : Node_Id) return Boolean is
3303 Pnod : constant Node_Id := Parent (N);
3304 Kind : constant Node_Kind := Nkind (Pnod);
3307 if Kind = N_Object_Renaming_Declaration then
3310 elsif Kind = N_Indexed_Component
3311 or else Kind = N_Selected_Component
3313 return Is_Renamed_Object (Pnod);
3318 end Is_Renamed_Object;
3320 ----------------------------
3321 -- Is_Untagged_Derivation --
3322 ----------------------------
3324 function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
3326 return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
3328 (Is_Private_Type (T) and then Present (Full_View (T))
3329 and then not Is_Tagged_Type (Full_View (T))
3330 and then Is_Derived_Type (Full_View (T))
3331 and then Etype (Full_View (T)) /= T);
3332 end Is_Untagged_Derivation;
3334 ---------------------------
3335 -- Is_Volatile_Reference --
3336 ---------------------------
3338 function Is_Volatile_Reference (N : Node_Id) return Boolean is
3340 if Nkind (N) in N_Has_Etype
3341 and then Present (Etype (N))
3342 and then Treat_As_Volatile (Etype (N))
3346 elsif Is_Entity_Name (N) then
3347 return Treat_As_Volatile (Entity (N));
3349 elsif Nkind (N) = N_Slice then
3350 return Is_Volatile_Reference (Prefix (N));
3352 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
3353 if (Is_Entity_Name (Prefix (N))
3354 and then Has_Volatile_Components (Entity (Prefix (N))))
3355 or else (Present (Etype (Prefix (N)))
3356 and then Has_Volatile_Components (Etype (Prefix (N))))
3360 return Is_Volatile_Reference (Prefix (N));
3366 end Is_Volatile_Reference;
3368 --------------------
3369 -- Kill_Dead_Code --
3370 --------------------
3372 procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False) is
3375 Remove_Warning_Messages (N);
3379 ("?this code can never be executed and has been deleted!", N);
3382 -- Recurse into block statements and bodies to process declarations
3385 if Nkind (N) = N_Block_Statement
3386 or else Nkind (N) = N_Subprogram_Body
3387 or else Nkind (N) = N_Package_Body
3389 Kill_Dead_Code (Declarations (N), False);
3390 Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
3392 if Nkind (N) = N_Subprogram_Body then
3393 Set_Is_Eliminated (Defining_Entity (N));
3396 elsif Nkind (N) = N_Package_Declaration then
3397 Kill_Dead_Code (Visible_Declarations (Specification (N)));
3398 Kill_Dead_Code (Private_Declarations (Specification (N)));
3400 -- ??? After this point, Delete_Tree has been called on all
3401 -- declarations in Specification (N), so references to
3402 -- entities therein look suspicious.
3405 E : Entity_Id := First_Entity (Defining_Entity (N));
3407 while Present (E) loop
3408 if Ekind (E) = E_Operator then
3409 Set_Is_Eliminated (E);
3416 -- Recurse into composite statement to kill individual statements,
3417 -- in particular instantiations.
3419 elsif Nkind (N) = N_If_Statement then
3420 Kill_Dead_Code (Then_Statements (N));
3421 Kill_Dead_Code (Elsif_Parts (N));
3422 Kill_Dead_Code (Else_Statements (N));
3424 elsif Nkind (N) = N_Loop_Statement then
3425 Kill_Dead_Code (Statements (N));
3427 elsif Nkind (N) = N_Case_Statement then
3431 Alt := First (Alternatives (N));
3432 while Present (Alt) loop
3433 Kill_Dead_Code (Statements (Alt));
3438 elsif Nkind (N) = N_Case_Statement_Alternative then
3439 Kill_Dead_Code (Statements (N));
3441 -- Deal with dead instances caused by deleting instantiations
3443 elsif Nkind (N) in N_Generic_Instantiation then
3444 Remove_Dead_Instance (N);
3449 -- Case where argument is a list of nodes to be killed
3451 procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False) is
3456 if Is_Non_Empty_List (L) then
3458 while Present (N) loop
3459 Kill_Dead_Code (N, W);
3466 ------------------------
3467 -- Known_Non_Negative --
3468 ------------------------
3470 function Known_Non_Negative (Opnd : Node_Id) return Boolean is
3472 if Is_OK_Static_Expression (Opnd)
3473 and then Expr_Value (Opnd) >= 0
3479 Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
3483 Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
3486 end Known_Non_Negative;
3488 --------------------
3489 -- Known_Non_Null --
3490 --------------------
3492 function Known_Non_Null (N : Node_Id) return Boolean is
3494 -- Checks for case where N is an entity reference
3496 if Is_Entity_Name (N) and then Present (Entity (N)) then
3498 E : constant Entity_Id := Entity (N);
3503 -- First check if we are in decisive conditional
3505 Get_Current_Value_Condition (N, Op, Val);
3507 if Known_Null (Val) then
3508 if Op = N_Op_Eq then
3510 elsif Op = N_Op_Ne then
3515 -- If OK to do replacement, test Is_Known_Non_Null flag
3517 if OK_To_Do_Constant_Replacement (E) then
3518 return Is_Known_Non_Null (E);
3520 -- Otherwise if not safe to do replacement, then say so
3527 -- True if access attribute
3529 elsif Nkind (N) = N_Attribute_Reference
3530 and then (Attribute_Name (N) = Name_Access
3532 Attribute_Name (N) = Name_Unchecked_Access
3534 Attribute_Name (N) = Name_Unrestricted_Access)
3538 -- True if allocator
3540 elsif Nkind (N) = N_Allocator then
3543 -- For a conversion, true if expression is known non-null
3545 elsif Nkind (N) = N_Type_Conversion then
3546 return Known_Non_Null (Expression (N));
3548 -- Above are all cases where the value could be determined to be
3549 -- non-null. In all other cases, we don't know, so return False.
3560 function Known_Null (N : Node_Id) return Boolean is
3562 -- Checks for case where N is an entity reference
3564 if Is_Entity_Name (N) and then Present (Entity (N)) then
3566 E : constant Entity_Id := Entity (N);
3571 -- Constant null value is for sure null
3573 if Ekind (E) = E_Constant
3574 and then Known_Null (Constant_Value (E))
3579 -- First check if we are in decisive conditional
3581 Get_Current_Value_Condition (N, Op, Val);
3583 if Known_Null (Val) then
3584 if Op = N_Op_Eq then
3586 elsif Op = N_Op_Ne then
3591 -- If OK to do replacement, test Is_Known_Null flag
3593 if OK_To_Do_Constant_Replacement (E) then
3594 return Is_Known_Null (E);
3596 -- Otherwise if not safe to do replacement, then say so
3603 -- True if explicit reference to null
3605 elsif Nkind (N) = N_Null then
3608 -- For a conversion, true if expression is known null
3610 elsif Nkind (N) = N_Type_Conversion then
3611 return Known_Null (Expression (N));
3613 -- Above are all cases where the value could be determined to be null.
3614 -- In all other cases, we don't know, so return False.
3621 -----------------------------
3622 -- Make_CW_Equivalent_Type --
3623 -----------------------------
3625 -- Create a record type used as an equivalent of any member
3626 -- of the class which takes its size from exp.
3628 -- Generate the following code:
3630 -- type Equiv_T is record
3631 -- _parent : T (List of discriminant constraints taken from Exp);
3632 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
3635 -- ??? Note that this type does not guarantee same alignment as all
3638 function Make_CW_Equivalent_Type
3640 E : Node_Id) return Entity_Id
3642 Loc : constant Source_Ptr := Sloc (E);
3643 Root_Typ : constant Entity_Id := Root_Type (T);
3644 List_Def : constant List_Id := Empty_List;
3645 Comp_List : constant List_Id := New_List;
3646 Equiv_Type : Entity_Id;
3647 Range_Type : Entity_Id;
3648 Str_Type : Entity_Id;
3649 Constr_Root : Entity_Id;
3653 if not Has_Discriminants (Root_Typ) then
3654 Constr_Root := Root_Typ;
3657 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
3659 -- subtype cstr__n is T (List of discr constraints taken from Exp)
3661 Append_To (List_Def,
3662 Make_Subtype_Declaration (Loc,
3663 Defining_Identifier => Constr_Root,
3664 Subtype_Indication =>
3665 Make_Subtype_From_Expr (E, Root_Typ)));
3668 -- Generate the range subtype declaration
3670 Range_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('G'));
3672 if not Is_Interface (Root_Typ) then
3673 -- subtype rg__xx is
3674 -- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
3677 Make_Op_Subtract (Loc,
3679 Make_Attribute_Reference (Loc,
3681 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
3682 Attribute_Name => Name_Size),
3684 Make_Attribute_Reference (Loc,
3685 Prefix => New_Reference_To (Constr_Root, Loc),
3686 Attribute_Name => Name_Object_Size));
3688 -- subtype rg__xx is
3689 -- Storage_Offset range 1 .. Expr'size / Storage_Unit
3692 Make_Attribute_Reference (Loc,
3694 OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
3695 Attribute_Name => Name_Size);
3698 Set_Paren_Count (Sizexpr, 1);
3700 Append_To (List_Def,
3701 Make_Subtype_Declaration (Loc,
3702 Defining_Identifier => Range_Type,
3703 Subtype_Indication =>
3704 Make_Subtype_Indication (Loc,
3705 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
3706 Constraint => Make_Range_Constraint (Loc,
3709 Low_Bound => Make_Integer_Literal (Loc, 1),
3711 Make_Op_Divide (Loc,
3712 Left_Opnd => Sizexpr,
3713 Right_Opnd => Make_Integer_Literal (Loc,
3714 Intval => System_Storage_Unit)))))));
3716 -- subtype str__nn is Storage_Array (rg__x);
3718 Str_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3719 Append_To (List_Def,
3720 Make_Subtype_Declaration (Loc,
3721 Defining_Identifier => Str_Type,
3722 Subtype_Indication =>
3723 Make_Subtype_Indication (Loc,
3724 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
3726 Make_Index_Or_Discriminant_Constraint (Loc,
3728 New_List (New_Reference_To (Range_Type, Loc))))));
3730 -- type Equiv_T is record
3731 -- [ _parent : Tnn; ]
3735 Equiv_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
3737 -- When the target requires front-end layout, it's necessary to allow
3738 -- the equivalent type to be frozen so that layout can occur (when the
3739 -- associated class-wide subtype is frozen, the equivalent type will
3740 -- be frozen, see freeze.adb). For other targets, Gigi wants to have
3741 -- the equivalent type marked as frozen and deals with this type itself.
3742 -- In the Gigi case this will also avoid the generation of an init
3743 -- procedure for the type.
3745 if not Frontend_Layout_On_Target then
3746 Set_Is_Frozen (Equiv_Type);
3749 Set_Ekind (Equiv_Type, E_Record_Type);
3750 Set_Parent_Subtype (Equiv_Type, Constr_Root);
3752 if not Is_Interface (Root_Typ) then
3753 Append_To (Comp_List,
3754 Make_Component_Declaration (Loc,
3755 Defining_Identifier =>
3756 Make_Defining_Identifier (Loc, Name_uParent),
3757 Component_Definition =>
3758 Make_Component_Definition (Loc,
3759 Aliased_Present => False,
3760 Subtype_Indication => New_Reference_To (Constr_Root, Loc))));
3763 Append_To (Comp_List,
3764 Make_Component_Declaration (Loc,
3765 Defining_Identifier =>
3766 Make_Defining_Identifier (Loc,
3767 Chars => New_Internal_Name ('C')),
3768 Component_Definition =>
3769 Make_Component_Definition (Loc,
3770 Aliased_Present => False,
3771 Subtype_Indication => New_Reference_To (Str_Type, Loc))));
3773 Append_To (List_Def,
3774 Make_Full_Type_Declaration (Loc,
3775 Defining_Identifier => Equiv_Type,
3777 Make_Record_Definition (Loc,
3779 Make_Component_List (Loc,
3780 Component_Items => Comp_List,
3781 Variant_Part => Empty))));
3783 -- Suppress all checks during the analysis of the expanded code
3784 -- to avoid the generation of spurious warnings under ZFP run-time.
3786 Insert_Actions (E, List_Def, Suppress => All_Checks);
3788 end Make_CW_Equivalent_Type;
3790 ------------------------
3791 -- Make_Literal_Range --
3792 ------------------------
3794 function Make_Literal_Range
3796 Literal_Typ : Entity_Id) return Node_Id
3798 Lo : constant Node_Id :=
3799 New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
3800 Index : constant Entity_Id := Etype (Lo);
3803 Length_Expr : constant Node_Id :=
3804 Make_Op_Subtract (Loc,
3806 Make_Integer_Literal (Loc,
3807 Intval => String_Literal_Length (Literal_Typ)),
3809 Make_Integer_Literal (Loc, 1));
3812 Set_Analyzed (Lo, False);
3814 if Is_Integer_Type (Index) then
3817 Left_Opnd => New_Copy_Tree (Lo),
3818 Right_Opnd => Length_Expr);
3821 Make_Attribute_Reference (Loc,
3822 Attribute_Name => Name_Val,
3823 Prefix => New_Occurrence_Of (Index, Loc),
3824 Expressions => New_List (
3827 Make_Attribute_Reference (Loc,
3828 Attribute_Name => Name_Pos,
3829 Prefix => New_Occurrence_Of (Index, Loc),
3830 Expressions => New_List (New_Copy_Tree (Lo))),
3831 Right_Opnd => Length_Expr)));
3838 end Make_Literal_Range;
3840 --------------------------
3841 -- Make_Non_Empty_Check --
3842 --------------------------
3844 function Make_Non_Empty_Check
3846 N : Node_Id) return Node_Id
3852 Make_Attribute_Reference (Loc,
3853 Attribute_Name => Name_Length,
3854 Prefix => Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
3856 Make_Integer_Literal (Loc, 0));
3857 end Make_Non_Empty_Check;
3859 ----------------------------
3860 -- Make_Subtype_From_Expr --
3861 ----------------------------
3863 -- 1. If Expr is an unconstrained array expression, creates
3864 -- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
3866 -- 2. If Expr is a unconstrained discriminated type expression, creates
3867 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
3869 -- 3. If Expr is class-wide, creates an implicit class wide subtype
3871 function Make_Subtype_From_Expr
3873 Unc_Typ : Entity_Id) return Node_Id
3875 Loc : constant Source_Ptr := Sloc (E);
3876 List_Constr : constant List_Id := New_List;
3879 Full_Subtyp : Entity_Id;
3880 Priv_Subtyp : Entity_Id;
3885 if Is_Private_Type (Unc_Typ)
3886 and then Has_Unknown_Discriminants (Unc_Typ)
3888 -- Prepare the subtype completion, Go to base type to
3889 -- find underlying type, because the type may be a generic
3890 -- actual or an explicit subtype.
3892 Utyp := Underlying_Type (Base_Type (Unc_Typ));
3893 Full_Subtyp := Make_Defining_Identifier (Loc,
3894 New_Internal_Name ('C'));
3896 Unchecked_Convert_To
3897 (Utyp, Duplicate_Subexpr_No_Checks (E));
3898 Set_Parent (Full_Exp, Parent (E));
3901 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
3904 Make_Subtype_Declaration (Loc,
3905 Defining_Identifier => Full_Subtyp,
3906 Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
3908 -- Define the dummy private subtype
3910 Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
3911 Set_Etype (Priv_Subtyp, Base_Type (Unc_Typ));
3912 Set_Scope (Priv_Subtyp, Full_Subtyp);
3913 Set_Is_Constrained (Priv_Subtyp);
3914 Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
3915 Set_Is_Itype (Priv_Subtyp);
3916 Set_Associated_Node_For_Itype (Priv_Subtyp, E);
3918 if Is_Tagged_Type (Priv_Subtyp) then
3920 (Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
3921 Set_Primitive_Operations (Priv_Subtyp,
3922 Primitive_Operations (Unc_Typ));
3925 Set_Full_View (Priv_Subtyp, Full_Subtyp);
3927 return New_Reference_To (Priv_Subtyp, Loc);
3929 elsif Is_Array_Type (Unc_Typ) then
3930 for J in 1 .. Number_Dimensions (Unc_Typ) loop
3931 Append_To (List_Constr,
3934 Make_Attribute_Reference (Loc,
3935 Prefix => Duplicate_Subexpr_No_Checks (E),
3936 Attribute_Name => Name_First,
3937 Expressions => New_List (
3938 Make_Integer_Literal (Loc, J))),
3941 Make_Attribute_Reference (Loc,
3942 Prefix => Duplicate_Subexpr_No_Checks (E),
3943 Attribute_Name => Name_Last,
3944 Expressions => New_List (
3945 Make_Integer_Literal (Loc, J)))));
3948 elsif Is_Class_Wide_Type (Unc_Typ) then
3950 CW_Subtype : Entity_Id;
3951 EQ_Typ : Entity_Id := Empty;
3954 -- A class-wide equivalent type is not needed when VM_Target
3955 -- because the VM back-ends handle the class-wide object
3956 -- initialization itself (and doesn't need or want the
3957 -- additional intermediate type to handle the assignment).
3959 if Expander_Active and then Tagged_Type_Expansion then
3960 EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
3963 CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
3964 Set_Equivalent_Type (CW_Subtype, EQ_Typ);
3966 if Present (EQ_Typ) then
3967 Set_Is_Class_Wide_Equivalent_Type (EQ_Typ);
3970 Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
3972 return New_Occurrence_Of (CW_Subtype, Loc);
3975 -- Indefinite record type with discriminants
3978 D := First_Discriminant (Unc_Typ);
3979 while Present (D) loop
3980 Append_To (List_Constr,
3981 Make_Selected_Component (Loc,
3982 Prefix => Duplicate_Subexpr_No_Checks (E),
3983 Selector_Name => New_Reference_To (D, Loc)));
3985 Next_Discriminant (D);
3990 Make_Subtype_Indication (Loc,
3991 Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
3993 Make_Index_Or_Discriminant_Constraint (Loc,
3994 Constraints => List_Constr));
3995 end Make_Subtype_From_Expr;
3997 -----------------------------
3998 -- May_Generate_Large_Temp --
3999 -----------------------------
4001 -- At the current time, the only types that we return False for (i.e.
4002 -- where we decide we know they cannot generate large temps) are ones
4003 -- where we know the size is 256 bits or less at compile time, and we
4004 -- are still not doing a thorough job on arrays and records ???
4006 function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
4008 if not Size_Known_At_Compile_Time (Typ) then
4011 elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
4014 elsif Is_Array_Type (Typ)
4015 and then Present (Packed_Array_Type (Typ))
4017 return May_Generate_Large_Temp (Packed_Array_Type (Typ));
4019 -- We could do more here to find other small types ???
4024 end May_Generate_Large_Temp;
4026 ----------------------------
4027 -- New_Class_Wide_Subtype --
4028 ----------------------------
4030 function New_Class_Wide_Subtype
4031 (CW_Typ : Entity_Id;
4032 N : Node_Id) return Entity_Id
4034 Res : constant Entity_Id := Create_Itype (E_Void, N);
4035 Res_Name : constant Name_Id := Chars (Res);
4036 Res_Scope : constant Entity_Id := Scope (Res);
4039 Copy_Node (CW_Typ, Res);
4040 Set_Comes_From_Source (Res, False);
4041 Set_Sloc (Res, Sloc (N));
4043 Set_Associated_Node_For_Itype (Res, N);
4044 Set_Is_Public (Res, False); -- By default, may be changed below.
4045 Set_Public_Status (Res);
4046 Set_Chars (Res, Res_Name);
4047 Set_Scope (Res, Res_Scope);
4048 Set_Ekind (Res, E_Class_Wide_Subtype);
4049 Set_Next_Entity (Res, Empty);
4050 Set_Etype (Res, Base_Type (CW_Typ));
4052 -- For targets where front-end layout is required, reset the Is_Frozen
4053 -- status of the subtype to False (it can be implicitly set to true
4054 -- from the copy of the class-wide type). For other targets, Gigi
4055 -- doesn't want the class-wide subtype to go through the freezing
4056 -- process (though it's unclear why that causes problems and it would
4057 -- be nice to allow freezing to occur normally for all targets ???).
4059 if Frontend_Layout_On_Target then
4060 Set_Is_Frozen (Res, False);
4063 Set_Freeze_Node (Res, Empty);
4065 end New_Class_Wide_Subtype;
4067 --------------------------------
4068 -- Non_Limited_Designated_Type --
4069 ---------------------------------
4071 function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id is
4072 Desig : constant Entity_Id := Designated_Type (T);
4074 if Ekind (Desig) = E_Incomplete_Type
4075 and then Present (Non_Limited_View (Desig))
4077 return Non_Limited_View (Desig);
4081 end Non_Limited_Designated_Type;
4083 -----------------------------------
4084 -- OK_To_Do_Constant_Replacement --
4085 -----------------------------------
4087 function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean is
4088 ES : constant Entity_Id := Scope (E);
4092 -- Do not replace statically allocated objects, because they may be
4093 -- modified outside the current scope.
4095 if Is_Statically_Allocated (E) then
4098 -- Do not replace aliased or volatile objects, since we don't know what
4099 -- else might change the value.
4101 elsif Is_Aliased (E) or else Treat_As_Volatile (E) then
4104 -- Debug flag -gnatdM disconnects this optimization
4106 elsif Debug_Flag_MM then
4109 -- Otherwise check scopes
4112 CS := Current_Scope;
4115 -- If we are in right scope, replacement is safe
4120 -- Packages do not affect the determination of safety
4122 elsif Ekind (CS) = E_Package then
4123 exit when CS = Standard_Standard;
4126 -- Blocks do not affect the determination of safety
4128 elsif Ekind (CS) = E_Block then
4131 -- Loops do not affect the determination of safety. Note that we
4132 -- kill all current values on entry to a loop, so we are just
4133 -- talking about processing within a loop here.
4135 elsif Ekind (CS) = E_Loop then
4138 -- Otherwise, the reference is dubious, and we cannot be sure that
4139 -- it is safe to do the replacement.
4148 end OK_To_Do_Constant_Replacement;
4150 ------------------------------------
4151 -- Possible_Bit_Aligned_Component --
4152 ------------------------------------
4154 function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean is
4158 -- Case of indexed component
4160 when N_Indexed_Component =>
4162 P : constant Node_Id := Prefix (N);
4163 Ptyp : constant Entity_Id := Etype (P);
4166 -- If we know the component size and it is less than 64, then
4167 -- we are definitely OK. The back end always does assignment of
4168 -- misaligned small objects correctly.
4170 if Known_Static_Component_Size (Ptyp)
4171 and then Component_Size (Ptyp) <= 64
4175 -- Otherwise, we need to test the prefix, to see if we are
4176 -- indexing from a possibly unaligned component.
4179 return Possible_Bit_Aligned_Component (P);
4183 -- Case of selected component
4185 when N_Selected_Component =>
4187 P : constant Node_Id := Prefix (N);
4188 Comp : constant Entity_Id := Entity (Selector_Name (N));
4191 -- If there is no component clause, then we are in the clear
4192 -- since the back end will never misalign a large component
4193 -- unless it is forced to do so. In the clear means we need
4194 -- only the recursive test on the prefix.
4196 if Component_May_Be_Bit_Aligned (Comp) then
4199 return Possible_Bit_Aligned_Component (P);
4203 -- For a slice, test the prefix, if that is possibly misaligned,
4204 -- then for sure the slice is!
4207 return Possible_Bit_Aligned_Component (Prefix (N));
4209 -- If we have none of the above, it means that we have fallen off the
4210 -- top testing prefixes recursively, and we now have a stand alone
4211 -- object, where we don't have a problem.
4217 end Possible_Bit_Aligned_Component;
4219 -------------------------
4220 -- Remove_Side_Effects --
4221 -------------------------
4223 procedure Remove_Side_Effects
4225 Name_Req : Boolean := False;
4226 Variable_Ref : Boolean := False)
4228 Loc : constant Source_Ptr := Sloc (Exp);
4229 Exp_Type : constant Entity_Id := Etype (Exp);
4230 Svg_Suppress : constant Suppress_Array := Scope_Suppress;
4232 Ref_Type : Entity_Id;
4234 Ptr_Typ_Decl : Node_Id;
4238 function Side_Effect_Free (N : Node_Id) return Boolean;
4239 -- Determines if the tree N represents an expression that is known not
4240 -- to have side effects, and for which no processing is required.
4242 function Side_Effect_Free (L : List_Id) return Boolean;
4243 -- Determines if all elements of the list L are side effect free
4245 function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
4246 -- The argument N is a construct where the Prefix is dereferenced if it
4247 -- is an access type and the result is a variable. The call returns True
4248 -- if the construct is side effect free (not considering side effects in
4249 -- other than the prefix which are to be tested by the caller).
4251 function Within_In_Parameter (N : Node_Id) return Boolean;
4252 -- Determines if N is a subcomponent of a composite in-parameter. If so,
4253 -- N is not side-effect free when the actual is global and modifiable
4254 -- indirectly from within a subprogram, because it may be passed by
4255 -- reference. The front-end must be conservative here and assume that
4256 -- this may happen with any array or record type. On the other hand, we
4257 -- cannot create temporaries for all expressions for which this
4258 -- condition is true, for various reasons that might require clearing up
4259 -- ??? For example, discriminant references that appear out of place, or
4260 -- spurious type errors with class-wide expressions. As a result, we
4261 -- limit the transformation to loop bounds, which is so far the only
4262 -- case that requires it.
4264 -----------------------------
4265 -- Safe_Prefixed_Reference --
4266 -----------------------------
4268 function Safe_Prefixed_Reference (N : Node_Id) return Boolean is
4270 -- If prefix is not side effect free, definitely not safe
4272 if not Side_Effect_Free (Prefix (N)) then
4275 -- If the prefix is of an access type that is not access-to-constant,
4276 -- then this construct is a variable reference, which means it is to
4277 -- be considered to have side effects if Variable_Ref is set True
4278 -- Exception is an access to an entity that is a constant or an
4279 -- in-parameter which does not come from source, and is the result
4280 -- of a previous removal of side-effects.
4282 elsif Is_Access_Type (Etype (Prefix (N)))
4283 and then not Is_Access_Constant (Etype (Prefix (N)))
4284 and then Variable_Ref
4286 if not Is_Entity_Name (Prefix (N)) then
4289 return Ekind (Entity (Prefix (N))) = E_Constant
4290 or else Ekind (Entity (Prefix (N))) = E_In_Parameter;
4293 -- The following test is the simplest way of solving a complex
4294 -- problem uncovered by BB08-010: Side effect on loop bound that
4295 -- is a subcomponent of a global variable:
4296 -- If a loop bound is a subcomponent of a global variable, a
4297 -- modification of that variable within the loop may incorrectly
4298 -- affect the execution of the loop.
4301 (Nkind (Parent (Parent (N))) /= N_Loop_Parameter_Specification
4302 or else not Within_In_Parameter (Prefix (N)))
4306 -- All other cases are side effect free
4311 end Safe_Prefixed_Reference;
4313 ----------------------
4314 -- Side_Effect_Free --
4315 ----------------------
4317 function Side_Effect_Free (N : Node_Id) return Boolean is
4319 -- Note on checks that could raise Constraint_Error. Strictly, if
4320 -- we take advantage of 11.6, these checks do not count as side
4321 -- effects. However, we would just as soon consider that they are
4322 -- side effects, since the backend CSE does not work very well on
4323 -- expressions which can raise Constraint_Error. On the other
4324 -- hand, if we do not consider them to be side effect free, then
4325 -- we get some awkward expansions in -gnato mode, resulting in
4326 -- code insertions at a point where we do not have a clear model
4327 -- for performing the insertions.
4329 -- Special handling for entity names
4331 if Is_Entity_Name (N) then
4333 -- If the entity is a constant, it is definitely side effect
4334 -- free. Note that the test of Is_Variable (N) below might
4335 -- be expected to catch this case, but it does not, because
4336 -- this test goes to the original tree, and we may have
4337 -- already rewritten a variable node with a constant as
4338 -- a result of an earlier Force_Evaluation call.
4340 if Ekind (Entity (N)) = E_Constant
4341 or else Ekind (Entity (N)) = E_In_Parameter
4345 -- Functions are not side effect free
4347 elsif Ekind (Entity (N)) = E_Function then
4350 -- Variables are considered to be a side effect if Variable_Ref
4351 -- is set or if we have a volatile reference and Name_Req is off.
4352 -- If Name_Req is True then we can't help returning a name which
4353 -- effectively allows multiple references in any case.
4355 elsif Is_Variable (N) then
4356 return not Variable_Ref
4357 and then (not Is_Volatile_Reference (N) or else Name_Req);
4359 -- Any other entity (e.g. a subtype name) is definitely side
4366 -- A value known at compile time is always side effect free
4368 elsif Compile_Time_Known_Value (N) then
4371 -- A variable renaming is not side-effect free, because the
4372 -- renaming will function like a macro in the front-end in
4373 -- some cases, and an assignment can modify the component
4374 -- designated by N, so we need to create a temporary for it.
4376 elsif Is_Entity_Name (Original_Node (N))
4377 and then Is_Renaming_Of_Object (Entity (Original_Node (N)))
4378 and then Ekind (Entity (Original_Node (N))) /= E_Constant
4383 -- For other than entity names and compile time known values,
4384 -- check the node kind for special processing.
4388 -- An attribute reference is side effect free if its expressions
4389 -- are side effect free and its prefix is side effect free or
4390 -- is an entity reference.
4392 -- Is this right? what about x'first where x is a variable???
4394 when N_Attribute_Reference =>
4395 return Side_Effect_Free (Expressions (N))
4396 and then Attribute_Name (N) /= Name_Input
4397 and then (Is_Entity_Name (Prefix (N))
4398 or else Side_Effect_Free (Prefix (N)));
4400 -- A binary operator is side effect free if and both operands
4401 -- are side effect free. For this purpose binary operators
4402 -- include membership tests and short circuit forms
4404 when N_Binary_Op | N_Membership_Test | N_Short_Circuit =>
4405 return Side_Effect_Free (Left_Opnd (N))
4407 Side_Effect_Free (Right_Opnd (N));
4409 -- An explicit dereference is side effect free only if it is
4410 -- a side effect free prefixed reference.
4412 when N_Explicit_Dereference =>
4413 return Safe_Prefixed_Reference (N);
4415 -- A call to _rep_to_pos is side effect free, since we generate
4416 -- this pure function call ourselves. Moreover it is critically
4417 -- important to make this exception, since otherwise we can
4418 -- have discriminants in array components which don't look
4419 -- side effect free in the case of an array whose index type
4420 -- is an enumeration type with an enumeration rep clause.
4422 -- All other function calls are not side effect free
4424 when N_Function_Call =>
4425 return Nkind (Name (N)) = N_Identifier
4426 and then Is_TSS (Name (N), TSS_Rep_To_Pos)
4428 Side_Effect_Free (First (Parameter_Associations (N)));
4430 -- An indexed component is side effect free if it is a side
4431 -- effect free prefixed reference and all the indexing
4432 -- expressions are side effect free.
4434 when N_Indexed_Component =>
4435 return Side_Effect_Free (Expressions (N))
4436 and then Safe_Prefixed_Reference (N);
4438 -- A type qualification is side effect free if the expression
4439 -- is side effect free.
4441 when N_Qualified_Expression =>
4442 return Side_Effect_Free (Expression (N));
4444 -- A selected component is side effect free only if it is a
4445 -- side effect free prefixed reference. If it designates a
4446 -- component with a rep. clause it must be treated has having
4447 -- a potential side effect, because it may be modified through
4448 -- a renaming, and a subsequent use of the renaming as a macro
4449 -- will yield the wrong value. This complex interaction between
4450 -- renaming and removing side effects is a reminder that the
4451 -- latter has become a headache to maintain, and that it should
4452 -- be removed in favor of the gcc mechanism to capture values ???
4454 when N_Selected_Component =>
4455 if Nkind (Parent (N)) = N_Explicit_Dereference
4456 and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
4460 return Safe_Prefixed_Reference (N);
4463 -- A range is side effect free if the bounds are side effect free
4466 return Side_Effect_Free (Low_Bound (N))
4467 and then Side_Effect_Free (High_Bound (N));
4469 -- A slice is side effect free if it is a side effect free
4470 -- prefixed reference and the bounds are side effect free.
4473 return Side_Effect_Free (Discrete_Range (N))
4474 and then Safe_Prefixed_Reference (N);
4476 -- A type conversion is side effect free if the expression to be
4477 -- converted is side effect free.
4479 when N_Type_Conversion =>
4480 return Side_Effect_Free (Expression (N));
4482 -- A unary operator is side effect free if the operand
4483 -- is side effect free.
4486 return Side_Effect_Free (Right_Opnd (N));
4488 -- An unchecked type conversion is side effect free only if it
4489 -- is safe and its argument is side effect free.
4491 when N_Unchecked_Type_Conversion =>
4492 return Safe_Unchecked_Type_Conversion (N)
4493 and then Side_Effect_Free (Expression (N));
4495 -- An unchecked expression is side effect free if its expression
4496 -- is side effect free.
4498 when N_Unchecked_Expression =>
4499 return Side_Effect_Free (Expression (N));
4501 -- A literal is side effect free
4503 when N_Character_Literal |
4509 -- We consider that anything else has side effects. This is a bit
4510 -- crude, but we are pretty close for most common cases, and we
4511 -- are certainly correct (i.e. we never return True when the
4512 -- answer should be False).
4517 end Side_Effect_Free;
4519 -- A list is side effect free if all elements of the list are
4520 -- side effect free.
4522 function Side_Effect_Free (L : List_Id) return Boolean is
4526 if L = No_List or else L = Error_List then
4531 while Present (N) loop
4532 if not Side_Effect_Free (N) then
4541 end Side_Effect_Free;
4543 -------------------------
4544 -- Within_In_Parameter --
4545 -------------------------
4547 function Within_In_Parameter (N : Node_Id) return Boolean is
4549 if not Comes_From_Source (N) then
4552 elsif Is_Entity_Name (N) then
4553 return Ekind (Entity (N)) = E_In_Parameter;
4555 elsif Nkind (N) = N_Indexed_Component
4556 or else Nkind (N) = N_Selected_Component
4558 return Within_In_Parameter (Prefix (N));
4563 end Within_In_Parameter;
4565 -- Start of processing for Remove_Side_Effects
4568 -- If we are side effect free already or expansion is disabled,
4569 -- there is nothing to do.
4571 if Side_Effect_Free (Exp) or else not Expander_Active then
4575 -- All this must not have any checks
4577 Scope_Suppress := (others => True);
4579 -- If it is a scalar type and we need to capture the value, just make
4580 -- a copy. Likewise for a function call, an attribute reference or an
4581 -- operator. And if we have a volatile reference and Name_Req is not
4582 -- set (see comments above for Side_Effect_Free).
4584 if Is_Elementary_Type (Exp_Type)
4585 and then (Variable_Ref
4586 or else Nkind (Exp) = N_Function_Call
4587 or else Nkind (Exp) = N_Attribute_Reference
4588 or else Nkind (Exp) in N_Op
4589 or else (not Name_Req and then Is_Volatile_Reference (Exp)))
4591 Def_Id := Make_Temporary (Loc, 'R', Exp);
4592 Set_Etype (Def_Id, Exp_Type);
4593 Res := New_Reference_To (Def_Id, Loc);
4596 Make_Object_Declaration (Loc,
4597 Defining_Identifier => Def_Id,
4598 Object_Definition => New_Reference_To (Exp_Type, Loc),
4599 Constant_Present => True,
4600 Expression => Relocate_Node (Exp));
4602 Set_Assignment_OK (E);
4603 Insert_Action (Exp, E);
4605 -- If the expression has the form v.all then we can just capture
4606 -- the pointer, and then do an explicit dereference on the result.
4608 elsif Nkind (Exp) = N_Explicit_Dereference then
4609 Def_Id := Make_Temporary (Loc, 'R', Exp);
4611 Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
4614 Make_Object_Declaration (Loc,
4615 Defining_Identifier => Def_Id,
4616 Object_Definition =>
4617 New_Reference_To (Etype (Prefix (Exp)), Loc),
4618 Constant_Present => True,
4619 Expression => Relocate_Node (Prefix (Exp))));
4621 -- Similar processing for an unchecked conversion of an expression
4622 -- of the form v.all, where we want the same kind of treatment.
4624 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
4625 and then Nkind (Expression (Exp)) = N_Explicit_Dereference
4627 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
4628 Scope_Suppress := Svg_Suppress;
4631 -- If this is a type conversion, leave the type conversion and remove
4632 -- the side effects in the expression. This is important in several
4633 -- circumstances: for change of representations, and also when this is
4634 -- a view conversion to a smaller object, where gigi can end up creating
4635 -- its own temporary of the wrong size.
4637 elsif Nkind (Exp) = N_Type_Conversion then
4638 Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
4639 Scope_Suppress := Svg_Suppress;
4642 -- If this is an unchecked conversion that Gigi can't handle, make
4643 -- a copy or a use a renaming to capture the value.
4645 elsif Nkind (Exp) = N_Unchecked_Type_Conversion
4646 and then not Safe_Unchecked_Type_Conversion (Exp)
4648 if CW_Or_Has_Controlled_Part (Exp_Type) then
4650 -- Use a renaming to capture the expression, rather than create
4651 -- a controlled temporary.
4653 Def_Id := Make_Temporary (Loc, 'R', Exp);
4654 Res := New_Reference_To (Def_Id, Loc);
4657 Make_Object_Renaming_Declaration (Loc,
4658 Defining_Identifier => Def_Id,
4659 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
4660 Name => Relocate_Node (Exp)));
4663 Def_Id := Make_Temporary (Loc, 'R', Exp);
4664 Set_Etype (Def_Id, Exp_Type);
4665 Res := New_Reference_To (Def_Id, Loc);
4668 Make_Object_Declaration (Loc,
4669 Defining_Identifier => Def_Id,
4670 Object_Definition => New_Reference_To (Exp_Type, Loc),
4671 Constant_Present => not Is_Variable (Exp),
4672 Expression => Relocate_Node (Exp));
4674 Set_Assignment_OK (E);
4675 Insert_Action (Exp, E);
4678 -- For expressions that denote objects, we can use a renaming scheme.
4679 -- We skip using this if we have a volatile reference and we do not
4680 -- have Name_Req set true (see comments above for Side_Effect_Free).
4682 elsif Is_Object_Reference (Exp)
4683 and then Nkind (Exp) /= N_Function_Call
4684 and then (Name_Req or else not Is_Volatile_Reference (Exp))
4686 Def_Id := Make_Temporary (Loc, 'R', Exp);
4688 if Nkind (Exp) = N_Selected_Component
4689 and then Nkind (Prefix (Exp)) = N_Function_Call
4690 and then Is_Array_Type (Exp_Type)
4692 -- Avoid generating a variable-sized temporary, by generating
4693 -- the renaming declaration just for the function call. The
4694 -- transformation could be refined to apply only when the array
4695 -- component is constrained by a discriminant???
4698 Make_Selected_Component (Loc,
4699 Prefix => New_Occurrence_Of (Def_Id, Loc),
4700 Selector_Name => Selector_Name (Exp));
4703 Make_Object_Renaming_Declaration (Loc,
4704 Defining_Identifier => Def_Id,
4706 New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
4707 Name => Relocate_Node (Prefix (Exp))));
4710 Res := New_Reference_To (Def_Id, Loc);
4713 Make_Object_Renaming_Declaration (Loc,
4714 Defining_Identifier => Def_Id,
4715 Subtype_Mark => New_Reference_To (Exp_Type, Loc),
4716 Name => Relocate_Node (Exp)));
4719 -- If this is a packed reference, or a selected component with a
4720 -- non-standard representation, a reference to the temporary will
4721 -- be replaced by a copy of the original expression (see
4722 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
4723 -- elaborated by gigi, and is of course not to be replaced in-line
4724 -- by the expression it renames, which would defeat the purpose of
4725 -- removing the side-effect.
4727 if (Nkind (Exp) = N_Selected_Component
4728 or else Nkind (Exp) = N_Indexed_Component)
4729 and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
4733 Set_Is_Renaming_Of_Object (Def_Id, False);
4736 -- Otherwise we generate a reference to the value
4739 -- Special processing for function calls that return a limited type.
4740 -- We need to build a declaration that will enable build-in-place
4741 -- expansion of the call. This is not done if the context is already
4742 -- an object declaration, to prevent infinite recursion.
4744 -- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
4745 -- to accommodate functions returning limited objects by reference.
4747 if Nkind (Exp) = N_Function_Call
4748 and then Is_Inherently_Limited_Type (Etype (Exp))
4749 and then Nkind (Parent (Exp)) /= N_Object_Declaration
4750 and then Ada_Version >= Ada_05
4753 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', Exp);
4758 Make_Object_Declaration (Loc,
4759 Defining_Identifier => Obj,
4760 Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
4761 Expression => Relocate_Node (Exp));
4762 Insert_Action (Exp, Decl);
4763 Set_Etype (Obj, Exp_Type);
4764 Rewrite (Exp, New_Occurrence_Of (Obj, Loc));
4769 Ref_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4772 Make_Full_Type_Declaration (Loc,
4773 Defining_Identifier => Ref_Type,
4775 Make_Access_To_Object_Definition (Loc,
4776 All_Present => True,
4777 Subtype_Indication =>
4778 New_Reference_To (Exp_Type, Loc)));
4781 Insert_Action (Exp, Ptr_Typ_Decl);
4783 Def_Id := Make_Temporary (Loc, 'R', Exp);
4784 Set_Etype (Def_Id, Exp_Type);
4787 Make_Explicit_Dereference (Loc,
4788 Prefix => New_Reference_To (Def_Id, Loc));
4790 if Nkind (E) = N_Explicit_Dereference then
4791 New_Exp := Relocate_Node (Prefix (E));
4793 E := Relocate_Node (E);
4794 New_Exp := Make_Reference (Loc, E);
4797 if Is_Delayed_Aggregate (E) then
4799 -- The expansion of nested aggregates is delayed until the
4800 -- enclosing aggregate is expanded. As aggregates are often
4801 -- qualified, the predicate applies to qualified expressions
4802 -- as well, indicating that the enclosing aggregate has not
4803 -- been expanded yet. At this point the aggregate is part of
4804 -- a stand-alone declaration, and must be fully expanded.
4806 if Nkind (E) = N_Qualified_Expression then
4807 Set_Expansion_Delayed (Expression (E), False);
4808 Set_Analyzed (Expression (E), False);
4810 Set_Expansion_Delayed (E, False);
4813 Set_Analyzed (E, False);
4817 Make_Object_Declaration (Loc,
4818 Defining_Identifier => Def_Id,
4819 Object_Definition => New_Reference_To (Ref_Type, Loc),
4820 Expression => New_Exp));
4823 -- Preserve the Assignment_OK flag in all copies, since at least
4824 -- one copy may be used in a context where this flag must be set
4825 -- (otherwise why would the flag be set in the first place).
4827 Set_Assignment_OK (Res, Assignment_OK (Exp));
4829 -- Finally rewrite the original expression and we are done
4832 Analyze_And_Resolve (Exp, Exp_Type);
4833 Scope_Suppress := Svg_Suppress;
4834 end Remove_Side_Effects;
4836 ---------------------------
4837 -- Represented_As_Scalar --
4838 ---------------------------
4840 function Represented_As_Scalar (T : Entity_Id) return Boolean is
4841 UT : constant Entity_Id := Underlying_Type (T);
4843 return Is_Scalar_Type (UT)
4844 or else (Is_Bit_Packed_Array (UT)
4845 and then Is_Scalar_Type (Packed_Array_Type (UT)));
4846 end Represented_As_Scalar;
4848 ------------------------------------
4849 -- Safe_Unchecked_Type_Conversion --
4850 ------------------------------------
4852 -- Note: this function knows quite a bit about the exact requirements
4853 -- of Gigi with respect to unchecked type conversions, and its code
4854 -- must be coordinated with any changes in Gigi in this area.
4856 -- The above requirements should be documented in Sinfo ???
4858 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
4863 Pexp : constant Node_Id := Parent (Exp);
4866 -- If the expression is the RHS of an assignment or object declaration
4867 -- we are always OK because there will always be a target.
4869 -- Object renaming declarations, (generated for view conversions of
4870 -- actuals in inlined calls), like object declarations, provide an
4871 -- explicit type, and are safe as well.
4873 if (Nkind (Pexp) = N_Assignment_Statement
4874 and then Expression (Pexp) = Exp)
4875 or else Nkind (Pexp) = N_Object_Declaration
4876 or else Nkind (Pexp) = N_Object_Renaming_Declaration
4880 -- If the expression is the prefix of an N_Selected_Component
4881 -- we should also be OK because GCC knows to look inside the
4882 -- conversion except if the type is discriminated. We assume
4883 -- that we are OK anyway if the type is not set yet or if it is
4884 -- controlled since we can't afford to introduce a temporary in
4887 elsif Nkind (Pexp) = N_Selected_Component
4888 and then Prefix (Pexp) = Exp
4890 if No (Etype (Pexp)) then
4894 not Has_Discriminants (Etype (Pexp))
4895 or else Is_Constrained (Etype (Pexp));
4899 -- Set the output type, this comes from Etype if it is set, otherwise
4900 -- we take it from the subtype mark, which we assume was already
4903 if Present (Etype (Exp)) then
4904 Otyp := Etype (Exp);
4906 Otyp := Entity (Subtype_Mark (Exp));
4909 -- The input type always comes from the expression, and we assume
4910 -- this is indeed always analyzed, so we can simply get the Etype.
4912 Ityp := Etype (Expression (Exp));
4914 -- Initialize alignments to unknown so far
4919 -- Replace a concurrent type by its corresponding record type
4920 -- and each type by its underlying type and do the tests on those.
4921 -- The original type may be a private type whose completion is a
4922 -- concurrent type, so find the underlying type first.
4924 if Present (Underlying_Type (Otyp)) then
4925 Otyp := Underlying_Type (Otyp);
4928 if Present (Underlying_Type (Ityp)) then
4929 Ityp := Underlying_Type (Ityp);
4932 if Is_Concurrent_Type (Otyp) then
4933 Otyp := Corresponding_Record_Type (Otyp);
4936 if Is_Concurrent_Type (Ityp) then
4937 Ityp := Corresponding_Record_Type (Ityp);
4940 -- If the base types are the same, we know there is no problem since
4941 -- this conversion will be a noop.
4943 if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
4946 -- Same if this is an upwards conversion of an untagged type, and there
4947 -- are no constraints involved (could be more general???)
4949 elsif Etype (Ityp) = Otyp
4950 and then not Is_Tagged_Type (Ityp)
4951 and then not Has_Discriminants (Ityp)
4952 and then No (First_Rep_Item (Base_Type (Ityp)))
4956 -- If the expression has an access type (object or subprogram) we
4957 -- assume that the conversion is safe, because the size of the target
4958 -- is safe, even if it is a record (which might be treated as having
4959 -- unknown size at this point).
4961 elsif Is_Access_Type (Ityp) then
4964 -- If the size of output type is known at compile time, there is
4965 -- never a problem. Note that unconstrained records are considered
4966 -- to be of known size, but we can't consider them that way here,
4967 -- because we are talking about the actual size of the object.
4969 -- We also make sure that in addition to the size being known, we do
4970 -- not have a case which might generate an embarrassingly large temp
4971 -- in stack checking mode.
4973 elsif Size_Known_At_Compile_Time (Otyp)
4975 (not Stack_Checking_Enabled
4976 or else not May_Generate_Large_Temp (Otyp))
4977 and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
4981 -- If either type is tagged, then we know the alignment is OK so
4982 -- Gigi will be able to use pointer punning.
4984 elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
4987 -- If either type is a limited record type, we cannot do a copy, so
4988 -- say safe since there's nothing else we can do.
4990 elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
4993 -- Conversions to and from packed array types are always ignored and
4996 elsif Is_Packed_Array_Type (Otyp)
4997 or else Is_Packed_Array_Type (Ityp)
5002 -- The only other cases known to be safe is if the input type's
5003 -- alignment is known to be at least the maximum alignment for the
5004 -- target or if both alignments are known and the output type's
5005 -- alignment is no stricter than the input's. We can use the alignment
5006 -- of the component type of an array if a type is an unpacked
5009 if Present (Alignment_Clause (Otyp)) then
5010 Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
5012 elsif Is_Array_Type (Otyp)
5013 and then Present (Alignment_Clause (Component_Type (Otyp)))
5015 Oalign := Expr_Value (Expression (Alignment_Clause
5016 (Component_Type (Otyp))));
5019 if Present (Alignment_Clause (Ityp)) then
5020 Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
5022 elsif Is_Array_Type (Ityp)
5023 and then Present (Alignment_Clause (Component_Type (Ityp)))
5025 Ialign := Expr_Value (Expression (Alignment_Clause
5026 (Component_Type (Ityp))));
5029 if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
5032 elsif Ialign /= No_Uint and then Oalign /= No_Uint
5033 and then Ialign <= Oalign
5037 -- Otherwise, Gigi cannot handle this and we must make a temporary
5042 end Safe_Unchecked_Type_Conversion;
5044 ---------------------------------
5045 -- Set_Current_Value_Condition --
5046 ---------------------------------
5048 -- Note: the implementation of this procedure is very closely tied to the
5049 -- implementation of Get_Current_Value_Condition. Here we set required
5050 -- Current_Value fields, and in Get_Current_Value_Condition, we interpret
5051 -- them, so they must have a consistent view.
5053 procedure Set_Current_Value_Condition (Cnode : Node_Id) is
5055 procedure Set_Entity_Current_Value (N : Node_Id);
5056 -- If N is an entity reference, where the entity is of an appropriate
5057 -- kind, then set the current value of this entity to Cnode, unless
5058 -- there is already a definite value set there.
5060 procedure Set_Expression_Current_Value (N : Node_Id);
5061 -- If N is of an appropriate form, sets an appropriate entry in current
5062 -- value fields of relevant entities. Multiple entities can be affected
5063 -- in the case of an AND or AND THEN.
5065 ------------------------------
5066 -- Set_Entity_Current_Value --
5067 ------------------------------
5069 procedure Set_Entity_Current_Value (N : Node_Id) is
5071 if Is_Entity_Name (N) then
5073 Ent : constant Entity_Id := Entity (N);
5076 -- Don't capture if not safe to do so
5078 if not Safe_To_Capture_Value (N, Ent, Cond => True) then
5082 -- Here we have a case where the Current_Value field may
5083 -- need to be set. We set it if it is not already set to a
5084 -- compile time expression value.
5086 -- Note that this represents a decision that one condition
5087 -- blots out another previous one. That's certainly right
5088 -- if they occur at the same level. If the second one is
5089 -- nested, then the decision is neither right nor wrong (it
5090 -- would be equally OK to leave the outer one in place, or
5091 -- take the new inner one. Really we should record both, but
5092 -- our data structures are not that elaborate.
5094 if Nkind (Current_Value (Ent)) not in N_Subexpr then
5095 Set_Current_Value (Ent, Cnode);
5099 end Set_Entity_Current_Value;
5101 ----------------------------------
5102 -- Set_Expression_Current_Value --
5103 ----------------------------------
5105 procedure Set_Expression_Current_Value (N : Node_Id) is
5111 -- Loop to deal with (ignore for now) any NOT operators present. The
5112 -- presence of NOT operators will be handled properly when we call
5113 -- Get_Current_Value_Condition.
5115 while Nkind (Cond) = N_Op_Not loop
5116 Cond := Right_Opnd (Cond);
5119 -- For an AND or AND THEN, recursively process operands
5121 if Nkind (Cond) = N_Op_And or else Nkind (Cond) = N_And_Then then
5122 Set_Expression_Current_Value (Left_Opnd (Cond));
5123 Set_Expression_Current_Value (Right_Opnd (Cond));
5127 -- Check possible relational operator
5129 if Nkind (Cond) in N_Op_Compare then
5130 if Compile_Time_Known_Value (Right_Opnd (Cond)) then
5131 Set_Entity_Current_Value (Left_Opnd (Cond));
5132 elsif Compile_Time_Known_Value (Left_Opnd (Cond)) then
5133 Set_Entity_Current_Value (Right_Opnd (Cond));
5136 -- Check possible boolean variable reference
5139 Set_Entity_Current_Value (Cond);
5141 end Set_Expression_Current_Value;
5143 -- Start of processing for Set_Current_Value_Condition
5146 Set_Expression_Current_Value (Condition (Cnode));
5147 end Set_Current_Value_Condition;
5149 --------------------------
5150 -- Set_Elaboration_Flag --
5151 --------------------------
5153 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
5154 Loc : constant Source_Ptr := Sloc (N);
5155 Ent : constant Entity_Id := Elaboration_Entity (Spec_Id);
5159 if Present (Ent) then
5161 -- Nothing to do if at the compilation unit level, because in this
5162 -- case the flag is set by the binder generated elaboration routine.
5164 if Nkind (Parent (N)) = N_Compilation_Unit then
5167 -- Here we do need to generate an assignment statement
5170 Check_Restriction (No_Elaboration_Code, N);
5172 Make_Assignment_Statement (Loc,
5173 Name => New_Occurrence_Of (Ent, Loc),
5174 Expression => New_Occurrence_Of (Standard_True, Loc));
5176 if Nkind (Parent (N)) = N_Subunit then
5177 Insert_After (Corresponding_Stub (Parent (N)), Asn);
5179 Insert_After (N, Asn);
5184 -- Kill current value indication. This is necessary because the
5185 -- tests of this flag are inserted out of sequence and must not
5186 -- pick up bogus indications of the wrong constant value.
5188 Set_Current_Value (Ent, Empty);
5191 end Set_Elaboration_Flag;
5193 ----------------------------
5194 -- Set_Renamed_Subprogram --
5195 ----------------------------
5197 procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id) is
5199 -- If input node is an identifier, we can just reset it
5201 if Nkind (N) = N_Identifier then
5202 Set_Chars (N, Chars (E));
5205 -- Otherwise we have to do a rewrite, preserving Comes_From_Source
5209 CS : constant Boolean := Comes_From_Source (N);
5211 Rewrite (N, Make_Identifier (Sloc (N), Chars => Chars (E)));
5213 Set_Comes_From_Source (N, CS);
5214 Set_Analyzed (N, True);
5217 end Set_Renamed_Subprogram;
5219 ----------------------------------
5220 -- Silly_Boolean_Array_Not_Test --
5221 ----------------------------------
5223 -- This procedure implements an odd and silly test. We explicitly check
5224 -- for the case where the 'First of the component type is equal to the
5225 -- 'Last of this component type, and if this is the case, we make sure
5226 -- that constraint error is raised. The reason is that the NOT is bound
5227 -- to cause CE in this case, and we will not otherwise catch it.
5229 -- No such check is required for AND and OR, since for both these cases
5230 -- False op False = False, and True op True = True. For the XOR case,
5231 -- see Silly_Boolean_Array_Xor_Test.
5233 -- Believe it or not, this was reported as a bug. Note that nearly
5234 -- always, the test will evaluate statically to False, so the code will
5235 -- be statically removed, and no extra overhead caused.
5237 procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id) is
5238 Loc : constant Source_Ptr := Sloc (N);
5239 CT : constant Entity_Id := Component_Type (T);
5242 -- The check we install is
5244 -- constraint_error when
5245 -- component_type'first = component_type'last
5246 -- and then array_type'Length /= 0)
5248 -- We need the last guard because we don't want to raise CE for empty
5249 -- arrays since no out of range values result. (Empty arrays with a
5250 -- component type of True .. True -- very useful -- even the ACATS
5251 -- does not test that marginal case!)
5254 Make_Raise_Constraint_Error (Loc,
5260 Make_Attribute_Reference (Loc,
5261 Prefix => New_Occurrence_Of (CT, Loc),
5262 Attribute_Name => Name_First),
5265 Make_Attribute_Reference (Loc,
5266 Prefix => New_Occurrence_Of (CT, Loc),
5267 Attribute_Name => Name_Last)),
5269 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
5270 Reason => CE_Range_Check_Failed));
5271 end Silly_Boolean_Array_Not_Test;
5273 ----------------------------------
5274 -- Silly_Boolean_Array_Xor_Test --
5275 ----------------------------------
5277 -- This procedure implements an odd and silly test. We explicitly check
5278 -- for the XOR case where the component type is True .. True, since this
5279 -- will raise constraint error. A special check is required since CE
5280 -- will not be generated otherwise (cf Expand_Packed_Not).
5282 -- No such check is required for AND and OR, since for both these cases
5283 -- False op False = False, and True op True = True, and no check is
5284 -- required for the case of False .. False, since False xor False = False.
5285 -- See also Silly_Boolean_Array_Not_Test
5287 procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is
5288 Loc : constant Source_Ptr := Sloc (N);
5289 CT : constant Entity_Id := Component_Type (T);
5292 -- The check we install is
5294 -- constraint_error when
5295 -- Boolean (component_type'First)
5296 -- and then Boolean (component_type'Last)
5297 -- and then array_type'Length /= 0)
5299 -- We need the last guard because we don't want to raise CE for empty
5300 -- arrays since no out of range values result (Empty arrays with a
5301 -- component type of True .. True -- very useful -- even the ACATS
5302 -- does not test that marginal case!).
5305 Make_Raise_Constraint_Error (Loc,
5311 Convert_To (Standard_Boolean,
5312 Make_Attribute_Reference (Loc,
5313 Prefix => New_Occurrence_Of (CT, Loc),
5314 Attribute_Name => Name_First)),
5317 Convert_To (Standard_Boolean,
5318 Make_Attribute_Reference (Loc,
5319 Prefix => New_Occurrence_Of (CT, Loc),
5320 Attribute_Name => Name_Last))),
5322 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
5323 Reason => CE_Range_Check_Failed));
5324 end Silly_Boolean_Array_Xor_Test;
5326 --------------------------
5327 -- Target_Has_Fixed_Ops --
5328 --------------------------
5330 Integer_Sized_Small : Ureal;
5331 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this
5332 -- function is called (we don't want to compute it more than once!)
5334 Long_Integer_Sized_Small : Ureal;
5335 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this
5336 -- function is called (we don't want to compute it more than once)
5338 First_Time_For_THFO : Boolean := True;
5339 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
5341 function Target_Has_Fixed_Ops
5342 (Left_Typ : Entity_Id;
5343 Right_Typ : Entity_Id;
5344 Result_Typ : Entity_Id) return Boolean
5346 function Is_Fractional_Type (Typ : Entity_Id) return Boolean;
5347 -- Return True if the given type is a fixed-point type with a small
5348 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
5349 -- an absolute value less than 1.0. This is currently limited
5350 -- to fixed-point types that map to Integer or Long_Integer.
5352 ------------------------
5353 -- Is_Fractional_Type --
5354 ------------------------
5356 function Is_Fractional_Type (Typ : Entity_Id) return Boolean is
5358 if Esize (Typ) = Standard_Integer_Size then
5359 return Small_Value (Typ) = Integer_Sized_Small;
5361 elsif Esize (Typ) = Standard_Long_Integer_Size then
5362 return Small_Value (Typ) = Long_Integer_Sized_Small;
5367 end Is_Fractional_Type;
5369 -- Start of processing for Target_Has_Fixed_Ops
5372 -- Return False if Fractional_Fixed_Ops_On_Target is false
5374 if not Fractional_Fixed_Ops_On_Target then
5378 -- Here the target has Fractional_Fixed_Ops, if first time, compute
5379 -- standard constants used by Is_Fractional_Type.
5381 if First_Time_For_THFO then
5382 First_Time_For_THFO := False;
5384 Integer_Sized_Small :=
5387 Den => UI_From_Int (Standard_Integer_Size - 1),
5390 Long_Integer_Sized_Small :=
5393 Den => UI_From_Int (Standard_Long_Integer_Size - 1),
5397 -- Return True if target supports fixed-by-fixed multiply/divide
5398 -- for fractional fixed-point types (see Is_Fractional_Type) and
5399 -- the operand and result types are equivalent fractional types.
5401 return Is_Fractional_Type (Base_Type (Left_Typ))
5402 and then Is_Fractional_Type (Base_Type (Right_Typ))
5403 and then Is_Fractional_Type (Base_Type (Result_Typ))
5404 and then Esize (Left_Typ) = Esize (Right_Typ)
5405 and then Esize (Left_Typ) = Esize (Result_Typ);
5406 end Target_Has_Fixed_Ops;
5408 ------------------------------------------
5409 -- Type_May_Have_Bit_Aligned_Components --
5410 ------------------------------------------
5412 function Type_May_Have_Bit_Aligned_Components
5413 (Typ : Entity_Id) return Boolean
5416 -- Array type, check component type
5418 if Is_Array_Type (Typ) then
5420 Type_May_Have_Bit_Aligned_Components (Component_Type (Typ));
5422 -- Record type, check components
5424 elsif Is_Record_Type (Typ) then
5429 E := First_Component_Or_Discriminant (Typ);
5430 while Present (E) loop
5431 if Component_May_Be_Bit_Aligned (E)
5432 or else Type_May_Have_Bit_Aligned_Components (Etype (E))
5437 Next_Component_Or_Discriminant (E);
5443 -- Type other than array or record is always OK
5448 end Type_May_Have_Bit_Aligned_Components;
5450 ----------------------------
5451 -- Wrap_Cleanup_Procedure --
5452 ----------------------------
5454 procedure Wrap_Cleanup_Procedure (N : Node_Id) is
5455 Loc : constant Source_Ptr := Sloc (N);
5456 Stseq : constant Node_Id := Handled_Statement_Sequence (N);
5457 Stmts : constant List_Id := Statements (Stseq);
5460 if Abort_Allowed then
5461 Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
5462 Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
5464 end Wrap_Cleanup_Procedure;