1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Rtsfind; use Rtsfind;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Attr; use Sem_Attr;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Disp; use Sem_Disp;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Type; use Sem_Type;
53 with Sinfo; use Sinfo;
54 with Sinput; use Sinput;
55 with Stand; use Stand;
57 with Stringt; use Stringt;
59 with Targparm; use Targparm;
60 with Tbuild; use Tbuild;
61 with Ttypes; use Ttypes;
62 with Uname; use Uname;
64 with GNAT.HTable; use GNAT.HTable;
66 package body Sem_Util is
68 ----------------------------------------
69 -- Global_Variables for New_Copy_Tree --
70 ----------------------------------------
72 -- These global variables are used by New_Copy_Tree. See description
73 -- of the body of this subprogram for details. Global variables can be
74 -- safely used by New_Copy_Tree, since there is no case of a recursive
75 -- call from the processing inside New_Copy_Tree.
77 NCT_Hash_Threshold : constant := 20;
78 -- If there are more than this number of pairs of entries in the
79 -- map, then Hash_Tables_Used will be set, and the hash tables will
80 -- be initialized and used for the searches.
82 NCT_Hash_Tables_Used : Boolean := False;
83 -- Set to True if hash tables are in use
85 NCT_Table_Entries : Nat;
86 -- Count entries in table to see if threshold is reached
88 NCT_Hash_Table_Setup : Boolean := False;
89 -- Set to True if hash table contains data. We set this True if we
90 -- setup the hash table with data, and leave it set permanently
91 -- from then on, this is a signal that second and subsequent users
92 -- of the hash table must clear the old entries before reuse.
94 subtype NCT_Header_Num is Int range 0 .. 511;
95 -- Defines range of headers in hash tables (512 headers)
97 ----------------------------------
98 -- Order Dependence (AI05-0144) --
99 ----------------------------------
101 -- Each actual in a call is entered into the table below. A flag indicates
102 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
103 -- (procedure call, condition, assignment) examines all the actuals for a
104 -- possible order dependence. The table is reset after each such check.
105 -- The actuals to be checked in a call to Check_Order_Dependence are at
106 -- positions 1 .. Last.
108 type Actual_Name is record
110 Is_Writable : Boolean;
113 package Actuals_In_Call is new Table.Table (
114 Table_Component_Type => Actual_Name,
115 Table_Index_Type => Int,
116 Table_Low_Bound => 0,
118 Table_Increment => 100,
119 Table_Name => "Actuals");
121 -----------------------
122 -- Local Subprograms --
123 -----------------------
125 function Build_Component_Subtype
128 T : Entity_Id) return Node_Id;
129 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
130 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
131 -- Loc is the source location, T is the original subtype.
133 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
134 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
135 -- with discriminants whose default values are static, examine only the
136 -- components in the selected variant to determine whether all of them
139 function Has_Null_Extension (T : Entity_Id) return Boolean;
140 -- T is a derived tagged type. Check whether the type extension is null.
141 -- If the parent type is fully initialized, T can be treated as such.
143 ------------------------------
144 -- Abstract_Interface_List --
145 ------------------------------
147 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
151 if Is_Concurrent_Type (Typ) then
153 -- If we are dealing with a synchronized subtype, go to the base
154 -- type, whose declaration has the interface list.
156 -- Shouldn't this be Declaration_Node???
158 Nod := Parent (Base_Type (Typ));
160 if Nkind (Nod) = N_Full_Type_Declaration then
164 elsif Ekind (Typ) = E_Record_Type_With_Private then
165 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
166 Nod := Type_Definition (Parent (Typ));
168 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
169 if Present (Full_View (Typ))
170 and then Nkind (Parent (Full_View (Typ)))
171 = N_Full_Type_Declaration
173 Nod := Type_Definition (Parent (Full_View (Typ)));
175 -- If the full-view is not available we cannot do anything else
176 -- here (the source has errors).
182 -- Support for generic formals with interfaces is still missing ???
184 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
189 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
193 elsif Ekind (Typ) = E_Record_Subtype then
194 Nod := Type_Definition (Parent (Etype (Typ)));
196 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
198 -- Recurse, because parent may still be a private extension. Also
199 -- note that the full view of the subtype or the full view of its
200 -- base type may (both) be unavailable.
202 return Abstract_Interface_List (Etype (Typ));
204 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
205 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
206 Nod := Formal_Type_Definition (Parent (Typ));
208 Nod := Type_Definition (Parent (Typ));
212 return Interface_List (Nod);
213 end Abstract_Interface_List;
215 --------------------------------
216 -- Add_Access_Type_To_Process --
217 --------------------------------
219 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
223 Ensure_Freeze_Node (E);
224 L := Access_Types_To_Process (Freeze_Node (E));
228 Set_Access_Types_To_Process (Freeze_Node (E), L);
232 end Add_Access_Type_To_Process;
234 ----------------------------
235 -- Add_Global_Declaration --
236 ----------------------------
238 procedure Add_Global_Declaration (N : Node_Id) is
239 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
242 if No (Declarations (Aux_Node)) then
243 Set_Declarations (Aux_Node, New_List);
246 Append_To (Declarations (Aux_Node), N);
248 end Add_Global_Declaration;
254 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
256 function Addressable (V : Uint) return Boolean is
258 return V = Uint_8 or else
264 function Addressable (V : Int) return Boolean is
272 -----------------------
273 -- Alignment_In_Bits --
274 -----------------------
276 function Alignment_In_Bits (E : Entity_Id) return Uint is
278 return Alignment (E) * System_Storage_Unit;
279 end Alignment_In_Bits;
281 -----------------------------------------
282 -- Apply_Compile_Time_Constraint_Error --
283 -----------------------------------------
285 procedure Apply_Compile_Time_Constraint_Error
288 Reason : RT_Exception_Code;
289 Ent : Entity_Id := Empty;
290 Typ : Entity_Id := Empty;
291 Loc : Source_Ptr := No_Location;
292 Rep : Boolean := True;
293 Warn : Boolean := False)
295 Stat : constant Boolean := Is_Static_Expression (N);
296 R_Stat : constant Node_Id :=
297 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
308 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
314 -- Now we replace the node by an N_Raise_Constraint_Error node
315 -- This does not need reanalyzing, so set it as analyzed now.
318 Set_Analyzed (N, True);
321 Set_Raises_Constraint_Error (N);
323 -- Now deal with possible local raise handling
325 Possible_Local_Raise (N, Standard_Constraint_Error);
327 -- If the original expression was marked as static, the result is
328 -- still marked as static, but the Raises_Constraint_Error flag is
329 -- always set so that further static evaluation is not attempted.
332 Set_Is_Static_Expression (N);
334 end Apply_Compile_Time_Constraint_Error;
336 --------------------------------------
337 -- Available_Full_View_Of_Component --
338 --------------------------------------
340 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
341 ST : constant Entity_Id := Scope (T);
342 SCT : constant Entity_Id := Scope (Component_Type (T));
344 return In_Open_Scopes (ST)
345 and then In_Open_Scopes (SCT)
346 and then Scope_Depth (ST) >= Scope_Depth (SCT);
347 end Available_Full_View_Of_Component;
349 --------------------------------
350 -- Bad_Predicated_Subtype_Use --
351 --------------------------------
353 procedure Bad_Predicated_Subtype_Use
359 if Has_Predicates (Typ) then
360 if Is_Generic_Actual_Type (Typ) then
361 Error_Msg_FE (Msg & '?', N, Typ);
362 Error_Msg_F ("\Program_Error will be raised at run time?", N);
364 Make_Raise_Program_Error (Sloc (N),
365 Reason => PE_Bad_Predicated_Generic_Type));
368 Error_Msg_FE (Msg, N, Typ);
371 end Bad_Predicated_Subtype_Use;
373 --------------------------
374 -- Build_Actual_Subtype --
375 --------------------------
377 function Build_Actual_Subtype
379 N : Node_Or_Entity_Id) return Node_Id
382 -- Normally Sloc (N), but may point to corresponding body in some cases
384 Constraints : List_Id;
390 Disc_Type : Entity_Id;
396 if Nkind (N) = N_Defining_Identifier then
397 Obj := New_Reference_To (N, Loc);
399 -- If this is a formal parameter of a subprogram declaration, and
400 -- we are compiling the body, we want the declaration for the
401 -- actual subtype to carry the source position of the body, to
402 -- prevent anomalies in gdb when stepping through the code.
404 if Is_Formal (N) then
406 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
408 if Nkind (Decl) = N_Subprogram_Declaration
409 and then Present (Corresponding_Body (Decl))
411 Loc := Sloc (Corresponding_Body (Decl));
420 if Is_Array_Type (T) then
421 Constraints := New_List;
422 for J in 1 .. Number_Dimensions (T) loop
424 -- Build an array subtype declaration with the nominal subtype and
425 -- the bounds of the actual. Add the declaration in front of the
426 -- local declarations for the subprogram, for analysis before any
427 -- reference to the formal in the body.
430 Make_Attribute_Reference (Loc,
432 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
433 Attribute_Name => Name_First,
434 Expressions => New_List (
435 Make_Integer_Literal (Loc, J)));
438 Make_Attribute_Reference (Loc,
440 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
441 Attribute_Name => Name_Last,
442 Expressions => New_List (
443 Make_Integer_Literal (Loc, J)));
445 Append (Make_Range (Loc, Lo, Hi), Constraints);
448 -- If the type has unknown discriminants there is no constrained
449 -- subtype to build. This is never called for a formal or for a
450 -- lhs, so returning the type is ok ???
452 elsif Has_Unknown_Discriminants (T) then
456 Constraints := New_List;
458 -- Type T is a generic derived type, inherit the discriminants from
461 if Is_Private_Type (T)
462 and then No (Full_View (T))
464 -- T was flagged as an error if it was declared as a formal
465 -- derived type with known discriminants. In this case there
466 -- is no need to look at the parent type since T already carries
467 -- its own discriminants.
469 and then not Error_Posted (T)
471 Disc_Type := Etype (Base_Type (T));
476 Discr := First_Discriminant (Disc_Type);
477 while Present (Discr) loop
478 Append_To (Constraints,
479 Make_Selected_Component (Loc,
481 Duplicate_Subexpr_No_Checks (Obj),
482 Selector_Name => New_Occurrence_Of (Discr, Loc)));
483 Next_Discriminant (Discr);
487 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
488 Set_Is_Internal (Subt);
491 Make_Subtype_Declaration (Loc,
492 Defining_Identifier => Subt,
493 Subtype_Indication =>
494 Make_Subtype_Indication (Loc,
495 Subtype_Mark => New_Reference_To (T, Loc),
497 Make_Index_Or_Discriminant_Constraint (Loc,
498 Constraints => Constraints)));
500 Mark_Rewrite_Insertion (Decl);
502 end Build_Actual_Subtype;
504 ---------------------------------------
505 -- Build_Actual_Subtype_Of_Component --
506 ---------------------------------------
508 function Build_Actual_Subtype_Of_Component
510 N : Node_Id) return Node_Id
512 Loc : constant Source_Ptr := Sloc (N);
513 P : constant Node_Id := Prefix (N);
516 Index_Typ : Entity_Id;
518 Desig_Typ : Entity_Id;
519 -- This is either a copy of T, or if T is an access type, then it is
520 -- the directly designated type of this access type.
522 function Build_Actual_Array_Constraint return List_Id;
523 -- If one or more of the bounds of the component depends on
524 -- discriminants, build actual constraint using the discriminants
527 function Build_Actual_Record_Constraint return List_Id;
528 -- Similar to previous one, for discriminated components constrained
529 -- by the discriminant of the enclosing object.
531 -----------------------------------
532 -- Build_Actual_Array_Constraint --
533 -----------------------------------
535 function Build_Actual_Array_Constraint return List_Id is
536 Constraints : constant List_Id := New_List;
544 Indx := First_Index (Desig_Typ);
545 while Present (Indx) loop
546 Old_Lo := Type_Low_Bound (Etype (Indx));
547 Old_Hi := Type_High_Bound (Etype (Indx));
549 if Denotes_Discriminant (Old_Lo) then
551 Make_Selected_Component (Loc,
552 Prefix => New_Copy_Tree (P),
553 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
556 Lo := New_Copy_Tree (Old_Lo);
558 -- The new bound will be reanalyzed in the enclosing
559 -- declaration. For literal bounds that come from a type
560 -- declaration, the type of the context must be imposed, so
561 -- insure that analysis will take place. For non-universal
562 -- types this is not strictly necessary.
564 Set_Analyzed (Lo, False);
567 if Denotes_Discriminant (Old_Hi) then
569 Make_Selected_Component (Loc,
570 Prefix => New_Copy_Tree (P),
571 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
574 Hi := New_Copy_Tree (Old_Hi);
575 Set_Analyzed (Hi, False);
578 Append (Make_Range (Loc, Lo, Hi), Constraints);
583 end Build_Actual_Array_Constraint;
585 ------------------------------------
586 -- Build_Actual_Record_Constraint --
587 ------------------------------------
589 function Build_Actual_Record_Constraint return List_Id is
590 Constraints : constant List_Id := New_List;
595 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
596 while Present (D) loop
597 if Denotes_Discriminant (Node (D)) then
598 D_Val := Make_Selected_Component (Loc,
599 Prefix => New_Copy_Tree (P),
600 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
603 D_Val := New_Copy_Tree (Node (D));
606 Append (D_Val, Constraints);
611 end Build_Actual_Record_Constraint;
613 -- Start of processing for Build_Actual_Subtype_Of_Component
616 -- Why the test for Spec_Expression mode here???
618 if In_Spec_Expression then
621 -- More comments for the rest of this body would be good ???
623 elsif Nkind (N) = N_Explicit_Dereference then
624 if Is_Composite_Type (T)
625 and then not Is_Constrained (T)
626 and then not (Is_Class_Wide_Type (T)
627 and then Is_Constrained (Root_Type (T)))
628 and then not Has_Unknown_Discriminants (T)
630 -- If the type of the dereference is already constrained, it is an
633 if Is_Array_Type (Etype (N))
634 and then Is_Constrained (Etype (N))
638 Remove_Side_Effects (P);
639 return Build_Actual_Subtype (T, N);
646 if Ekind (T) = E_Access_Subtype then
647 Desig_Typ := Designated_Type (T);
652 if Ekind (Desig_Typ) = E_Array_Subtype then
653 Id := First_Index (Desig_Typ);
654 while Present (Id) loop
655 Index_Typ := Underlying_Type (Etype (Id));
657 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
659 Denotes_Discriminant (Type_High_Bound (Index_Typ))
661 Remove_Side_Effects (P);
663 Build_Component_Subtype
664 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
670 elsif Is_Composite_Type (Desig_Typ)
671 and then Has_Discriminants (Desig_Typ)
672 and then not Has_Unknown_Discriminants (Desig_Typ)
674 if Is_Private_Type (Desig_Typ)
675 and then No (Discriminant_Constraint (Desig_Typ))
677 Desig_Typ := Full_View (Desig_Typ);
680 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
681 while Present (D) loop
682 if Denotes_Discriminant (Node (D)) then
683 Remove_Side_Effects (P);
685 Build_Component_Subtype (
686 Build_Actual_Record_Constraint, Loc, Base_Type (T));
693 -- If none of the above, the actual and nominal subtypes are the same
696 end Build_Actual_Subtype_Of_Component;
698 -----------------------------
699 -- Build_Component_Subtype --
700 -----------------------------
702 function Build_Component_Subtype
705 T : Entity_Id) return Node_Id
711 -- Unchecked_Union components do not require component subtypes
713 if Is_Unchecked_Union (T) then
717 Subt := Make_Temporary (Loc, 'S');
718 Set_Is_Internal (Subt);
721 Make_Subtype_Declaration (Loc,
722 Defining_Identifier => Subt,
723 Subtype_Indication =>
724 Make_Subtype_Indication (Loc,
725 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
727 Make_Index_Or_Discriminant_Constraint (Loc,
730 Mark_Rewrite_Insertion (Decl);
732 end Build_Component_Subtype;
734 ---------------------------
735 -- Build_Default_Subtype --
736 ---------------------------
738 function Build_Default_Subtype
740 N : Node_Id) return Entity_Id
742 Loc : constant Source_Ptr := Sloc (N);
746 if not Has_Discriminants (T) or else Is_Constrained (T) then
750 Disc := First_Discriminant (T);
752 if No (Discriminant_Default_Value (Disc)) then
757 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
758 Constraints : constant List_Id := New_List;
762 while Present (Disc) loop
763 Append_To (Constraints,
764 New_Copy_Tree (Discriminant_Default_Value (Disc)));
765 Next_Discriminant (Disc);
769 Make_Subtype_Declaration (Loc,
770 Defining_Identifier => Act,
771 Subtype_Indication =>
772 Make_Subtype_Indication (Loc,
773 Subtype_Mark => New_Occurrence_Of (T, Loc),
775 Make_Index_Or_Discriminant_Constraint (Loc,
776 Constraints => Constraints)));
778 Insert_Action (N, Decl);
782 end Build_Default_Subtype;
784 --------------------------------------------
785 -- Build_Discriminal_Subtype_Of_Component --
786 --------------------------------------------
788 function Build_Discriminal_Subtype_Of_Component
789 (T : Entity_Id) return Node_Id
791 Loc : constant Source_Ptr := Sloc (T);
795 function Build_Discriminal_Array_Constraint return List_Id;
796 -- If one or more of the bounds of the component depends on
797 -- discriminants, build actual constraint using the discriminants
800 function Build_Discriminal_Record_Constraint return List_Id;
801 -- Similar to previous one, for discriminated components constrained
802 -- by the discriminant of the enclosing object.
804 ----------------------------------------
805 -- Build_Discriminal_Array_Constraint --
806 ----------------------------------------
808 function Build_Discriminal_Array_Constraint return List_Id is
809 Constraints : constant List_Id := New_List;
817 Indx := First_Index (T);
818 while Present (Indx) loop
819 Old_Lo := Type_Low_Bound (Etype (Indx));
820 Old_Hi := Type_High_Bound (Etype (Indx));
822 if Denotes_Discriminant (Old_Lo) then
823 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
826 Lo := New_Copy_Tree (Old_Lo);
829 if Denotes_Discriminant (Old_Hi) then
830 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
833 Hi := New_Copy_Tree (Old_Hi);
836 Append (Make_Range (Loc, Lo, Hi), Constraints);
841 end Build_Discriminal_Array_Constraint;
843 -----------------------------------------
844 -- Build_Discriminal_Record_Constraint --
845 -----------------------------------------
847 function Build_Discriminal_Record_Constraint return List_Id is
848 Constraints : constant List_Id := New_List;
853 D := First_Elmt (Discriminant_Constraint (T));
854 while Present (D) loop
855 if Denotes_Discriminant (Node (D)) then
857 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
860 D_Val := New_Copy_Tree (Node (D));
863 Append (D_Val, Constraints);
868 end Build_Discriminal_Record_Constraint;
870 -- Start of processing for Build_Discriminal_Subtype_Of_Component
873 if Ekind (T) = E_Array_Subtype then
874 Id := First_Index (T);
875 while Present (Id) loop
876 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
877 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
879 return Build_Component_Subtype
880 (Build_Discriminal_Array_Constraint, Loc, T);
886 elsif Ekind (T) = E_Record_Subtype
887 and then Has_Discriminants (T)
888 and then not Has_Unknown_Discriminants (T)
890 D := First_Elmt (Discriminant_Constraint (T));
891 while Present (D) loop
892 if Denotes_Discriminant (Node (D)) then
893 return Build_Component_Subtype
894 (Build_Discriminal_Record_Constraint, Loc, T);
901 -- If none of the above, the actual and nominal subtypes are the same
904 end Build_Discriminal_Subtype_Of_Component;
906 ------------------------------
907 -- Build_Elaboration_Entity --
908 ------------------------------
910 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
911 Loc : constant Source_Ptr := Sloc (N);
913 Elab_Ent : Entity_Id;
915 procedure Set_Package_Name (Ent : Entity_Id);
916 -- Given an entity, sets the fully qualified name of the entity in
917 -- Name_Buffer, with components separated by double underscores. This
918 -- is a recursive routine that climbs the scope chain to Standard.
920 ----------------------
921 -- Set_Package_Name --
922 ----------------------
924 procedure Set_Package_Name (Ent : Entity_Id) is
926 if Scope (Ent) /= Standard_Standard then
927 Set_Package_Name (Scope (Ent));
930 Nam : constant String := Get_Name_String (Chars (Ent));
932 Name_Buffer (Name_Len + 1) := '_';
933 Name_Buffer (Name_Len + 2) := '_';
934 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
935 Name_Len := Name_Len + Nam'Length + 2;
939 Get_Name_String (Chars (Ent));
941 end Set_Package_Name;
943 -- Start of processing for Build_Elaboration_Entity
946 -- Ignore if already constructed
948 if Present (Elaboration_Entity (Spec_Id)) then
952 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
953 -- name with dots replaced by double underscore. We have to manually
954 -- construct this name, since it will be elaborated in the outer scope,
955 -- and thus will not have the unit name automatically prepended.
957 Set_Package_Name (Spec_Id);
961 Name_Buffer (Name_Len + 1) := '_';
962 Name_Buffer (Name_Len + 2) := 'E';
963 Name_Len := Name_Len + 2;
965 -- Create elaboration counter
967 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
968 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
971 Make_Object_Declaration (Loc,
972 Defining_Identifier => Elab_Ent,
974 New_Occurrence_Of (Standard_Short_Integer, Loc),
975 Expression => Make_Integer_Literal (Loc, Uint_0));
977 Push_Scope (Standard_Standard);
978 Add_Global_Declaration (Decl);
981 -- Reset True_Constant indication, since we will indeed assign a value
982 -- to the variable in the binder main. We also kill the Current_Value
983 -- and Last_Assignment fields for the same reason.
985 Set_Is_True_Constant (Elab_Ent, False);
986 Set_Current_Value (Elab_Ent, Empty);
987 Set_Last_Assignment (Elab_Ent, Empty);
989 -- We do not want any further qualification of the name (if we did
990 -- not do this, we would pick up the name of the generic package
991 -- in the case of a library level generic instantiation).
993 Set_Has_Qualified_Name (Elab_Ent);
994 Set_Has_Fully_Qualified_Name (Elab_Ent);
995 end Build_Elaboration_Entity;
997 --------------------------------
998 -- Build_Explicit_Dereference --
999 --------------------------------
1001 procedure Build_Explicit_Dereference
1005 Loc : constant Source_Ptr := Sloc (Expr);
1007 Set_Is_Overloaded (Expr, False);
1009 Make_Explicit_Dereference (Loc,
1011 Make_Selected_Component (Loc,
1012 Prefix => Relocate_Node (Expr),
1013 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1014 Set_Etype (Prefix (Expr), Etype (Disc));
1015 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1016 end Build_Explicit_Dereference;
1018 -----------------------------------
1019 -- Cannot_Raise_Constraint_Error --
1020 -----------------------------------
1022 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1024 if Compile_Time_Known_Value (Expr) then
1027 elsif Do_Range_Check (Expr) then
1030 elsif Raises_Constraint_Error (Expr) then
1034 case Nkind (Expr) is
1035 when N_Identifier =>
1038 when N_Expanded_Name =>
1041 when N_Selected_Component =>
1042 return not Do_Discriminant_Check (Expr);
1044 when N_Attribute_Reference =>
1045 if Do_Overflow_Check (Expr) then
1048 elsif No (Expressions (Expr)) then
1056 N := First (Expressions (Expr));
1057 while Present (N) loop
1058 if Cannot_Raise_Constraint_Error (N) then
1069 when N_Type_Conversion =>
1070 if Do_Overflow_Check (Expr)
1071 or else Do_Length_Check (Expr)
1072 or else Do_Tag_Check (Expr)
1077 Cannot_Raise_Constraint_Error (Expression (Expr));
1080 when N_Unchecked_Type_Conversion =>
1081 return Cannot_Raise_Constraint_Error (Expression (Expr));
1084 if Do_Overflow_Check (Expr) then
1088 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1095 if Do_Division_Check (Expr)
1096 or else Do_Overflow_Check (Expr)
1101 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1103 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1122 N_Op_Shift_Right_Arithmetic |
1126 if Do_Overflow_Check (Expr) then
1130 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1132 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1139 end Cannot_Raise_Constraint_Error;
1141 --------------------------------
1142 -- Check_Implicit_Dereference --
1143 --------------------------------
1145 procedure Check_Implicit_Dereference (Nam : Node_Id; Typ : Entity_Id)
1151 if Ada_Version < Ada_2012
1152 or else not Has_Implicit_Dereference (Base_Type (Typ))
1156 elsif not Comes_From_Source (Nam) then
1159 elsif Is_Entity_Name (Nam)
1160 and then Is_Type (Entity (Nam))
1165 Disc := First_Discriminant (Typ);
1166 while Present (Disc) loop
1167 if Has_Implicit_Dereference (Disc) then
1168 Desig := Designated_Type (Etype (Disc));
1169 Add_One_Interp (Nam, Disc, Desig);
1173 Next_Discriminant (Disc);
1176 end Check_Implicit_Dereference;
1178 ---------------------------------------
1179 -- Check_Later_Vs_Basic_Declarations --
1180 ---------------------------------------
1182 procedure Check_Later_Vs_Basic_Declarations
1184 During_Parsing : Boolean)
1186 Body_Sloc : Source_Ptr;
1189 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1190 -- Return whether Decl is considered as a declarative item.
1191 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1192 -- When During_Parsing is False, the semantics of SPARK is followed.
1194 -------------------------------
1195 -- Is_Later_Declarative_Item --
1196 -------------------------------
1198 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1200 if Nkind (Decl) in N_Later_Decl_Item then
1203 elsif Nkind (Decl) = N_Pragma then
1206 elsif During_Parsing then
1209 -- In SPARK, a package declaration is not considered as a later
1210 -- declarative item.
1212 elsif Nkind (Decl) = N_Package_Declaration then
1215 -- In SPARK, a renaming is considered as a later declarative item
1217 elsif Nkind (Decl) in N_Renaming_Declaration then
1223 end Is_Later_Declarative_Item;
1225 -- Start of Check_Later_Vs_Basic_Declarations
1228 Decl := First (Decls);
1230 -- Loop through sequence of basic declarative items
1232 Outer : while Present (Decl) loop
1233 if Nkind (Decl) /= N_Subprogram_Body
1234 and then Nkind (Decl) /= N_Package_Body
1235 and then Nkind (Decl) /= N_Task_Body
1236 and then Nkind (Decl) not in N_Body_Stub
1240 -- Once a body is encountered, we only allow later declarative
1241 -- items. The inner loop checks the rest of the list.
1244 Body_Sloc := Sloc (Decl);
1246 Inner : while Present (Decl) loop
1247 if not Is_Later_Declarative_Item (Decl) then
1248 if During_Parsing then
1249 if Ada_Version = Ada_83 then
1250 Error_Msg_Sloc := Body_Sloc;
1252 ("(Ada 83) decl cannot appear after body#", Decl);
1255 Error_Msg_Sloc := Body_Sloc;
1256 Check_SPARK_Restriction
1257 ("decl cannot appear after body#", Decl);
1265 end Check_Later_Vs_Basic_Declarations;
1267 -----------------------------------------
1268 -- Check_Dynamically_Tagged_Expression --
1269 -----------------------------------------
1271 procedure Check_Dynamically_Tagged_Expression
1274 Related_Nod : Node_Id)
1277 pragma Assert (Is_Tagged_Type (Typ));
1279 -- In order to avoid spurious errors when analyzing the expanded code,
1280 -- this check is done only for nodes that come from source and for
1281 -- actuals of generic instantiations.
1283 if (Comes_From_Source (Related_Nod)
1284 or else In_Generic_Actual (Expr))
1285 and then (Is_Class_Wide_Type (Etype (Expr))
1286 or else Is_Dynamically_Tagged (Expr))
1287 and then Is_Tagged_Type (Typ)
1288 and then not Is_Class_Wide_Type (Typ)
1290 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1292 end Check_Dynamically_Tagged_Expression;
1294 --------------------------
1295 -- Check_Fully_Declared --
1296 --------------------------
1298 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1300 if Ekind (T) = E_Incomplete_Type then
1302 -- Ada 2005 (AI-50217): If the type is available through a limited
1303 -- with_clause, verify that its full view has been analyzed.
1305 if From_With_Type (T)
1306 and then Present (Non_Limited_View (T))
1307 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1309 -- The non-limited view is fully declared
1314 ("premature usage of incomplete}", N, First_Subtype (T));
1317 -- Need comments for these tests ???
1319 elsif Has_Private_Component (T)
1320 and then not Is_Generic_Type (Root_Type (T))
1321 and then not In_Spec_Expression
1323 -- Special case: if T is the anonymous type created for a single
1324 -- task or protected object, use the name of the source object.
1326 if Is_Concurrent_Type (T)
1327 and then not Comes_From_Source (T)
1328 and then Nkind (N) = N_Object_Declaration
1330 Error_Msg_NE ("type of& has incomplete component", N,
1331 Defining_Identifier (N));
1335 ("premature usage of incomplete}", N, First_Subtype (T));
1338 end Check_Fully_Declared;
1340 -------------------------
1341 -- Check_Nested_Access --
1342 -------------------------
1344 procedure Check_Nested_Access (Ent : Entity_Id) is
1345 Scop : constant Entity_Id := Current_Scope;
1346 Current_Subp : Entity_Id;
1347 Enclosing : Entity_Id;
1350 -- Currently only enabled for VM back-ends for efficiency, should we
1351 -- enable it more systematically ???
1353 -- Check for Is_Imported needs commenting below ???
1355 if VM_Target /= No_VM
1356 and then (Ekind (Ent) = E_Variable
1358 Ekind (Ent) = E_Constant
1360 Ekind (Ent) = E_Loop_Parameter)
1361 and then Scope (Ent) /= Empty
1362 and then not Is_Library_Level_Entity (Ent)
1363 and then not Is_Imported (Ent)
1365 if Is_Subprogram (Scop)
1366 or else Is_Generic_Subprogram (Scop)
1367 or else Is_Entry (Scop)
1369 Current_Subp := Scop;
1371 Current_Subp := Current_Subprogram;
1374 Enclosing := Enclosing_Subprogram (Ent);
1376 if Enclosing /= Empty
1377 and then Enclosing /= Current_Subp
1379 Set_Has_Up_Level_Access (Ent, True);
1382 end Check_Nested_Access;
1384 ----------------------------
1385 -- Check_Order_Dependence --
1386 ----------------------------
1388 procedure Check_Order_Dependence is
1393 if Ada_Version < Ada_2012 then
1397 -- Ada 2012 AI05-0144-2: Dangerous order dependence. Actuals in nested
1398 -- calls within a construct have been collected. If one of them is
1399 -- writable and overlaps with another one, evaluation of the enclosing
1400 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1401 -- treated as a warning for now.
1403 for J in 1 .. Actuals_In_Call.Last loop
1404 if Actuals_In_Call.Table (J).Is_Writable then
1405 Act1 := Actuals_In_Call.Table (J).Act;
1407 if Nkind (Act1) = N_Attribute_Reference then
1408 Act1 := Prefix (Act1);
1411 for K in 1 .. Actuals_In_Call.Last loop
1413 Act2 := Actuals_In_Call.Table (K).Act;
1415 if Nkind (Act2) = N_Attribute_Reference then
1416 Act2 := Prefix (Act2);
1419 if Actuals_In_Call.Table (K).Is_Writable
1426 elsif Denotes_Same_Object (Act1, Act2)
1427 and then Parent (Act1) /= Parent (Act2)
1430 ("result may differ if evaluated "
1431 & "after other actual in expression?", Act1);
1438 -- Remove checked actuals from table
1440 Actuals_In_Call.Set_Last (0);
1441 end Check_Order_Dependence;
1443 ------------------------------------------
1444 -- Check_Potentially_Blocking_Operation --
1445 ------------------------------------------
1447 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1451 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1452 -- When pragma Detect_Blocking is active, the run time will raise
1453 -- Program_Error. Here we only issue a warning, since we generally
1454 -- support the use of potentially blocking operations in the absence
1457 -- Indirect blocking through a subprogram call cannot be diagnosed
1458 -- statically without interprocedural analysis, so we do not attempt
1461 S := Scope (Current_Scope);
1462 while Present (S) and then S /= Standard_Standard loop
1463 if Is_Protected_Type (S) then
1465 ("potentially blocking operation in protected operation?", N);
1471 end Check_Potentially_Blocking_Operation;
1473 ------------------------------
1474 -- Check_Unprotected_Access --
1475 ------------------------------
1477 procedure Check_Unprotected_Access
1481 Cont_Encl_Typ : Entity_Id;
1482 Pref_Encl_Typ : Entity_Id;
1484 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1485 -- Check whether Obj is a private component of a protected object.
1486 -- Return the protected type where the component resides, Empty
1489 function Is_Public_Operation return Boolean;
1490 -- Verify that the enclosing operation is callable from outside the
1491 -- protected object, to minimize false positives.
1493 ------------------------------
1494 -- Enclosing_Protected_Type --
1495 ------------------------------
1497 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1499 if Is_Entity_Name (Obj) then
1501 Ent : Entity_Id := Entity (Obj);
1504 -- The object can be a renaming of a private component, use
1505 -- the original record component.
1507 if Is_Prival (Ent) then
1508 Ent := Prival_Link (Ent);
1511 if Is_Protected_Type (Scope (Ent)) then
1517 -- For indexed and selected components, recursively check the prefix
1519 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1520 return Enclosing_Protected_Type (Prefix (Obj));
1522 -- The object does not denote a protected component
1527 end Enclosing_Protected_Type;
1529 -------------------------
1530 -- Is_Public_Operation --
1531 -------------------------
1533 function Is_Public_Operation return Boolean is
1540 and then S /= Pref_Encl_Typ
1542 if Scope (S) = Pref_Encl_Typ then
1543 E := First_Entity (Pref_Encl_Typ);
1545 and then E /= First_Private_Entity (Pref_Encl_Typ)
1558 end Is_Public_Operation;
1560 -- Start of processing for Check_Unprotected_Access
1563 if Nkind (Expr) = N_Attribute_Reference
1564 and then Attribute_Name (Expr) = Name_Unchecked_Access
1566 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1567 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1569 -- Check whether we are trying to export a protected component to a
1570 -- context with an equal or lower access level.
1572 if Present (Pref_Encl_Typ)
1573 and then No (Cont_Encl_Typ)
1574 and then Is_Public_Operation
1575 and then Scope_Depth (Pref_Encl_Typ) >=
1576 Object_Access_Level (Context)
1579 ("?possible unprotected access to protected data", Expr);
1582 end Check_Unprotected_Access;
1588 procedure Check_VMS (Construct : Node_Id) is
1590 if not OpenVMS_On_Target then
1592 ("this construct is allowed only in Open'V'M'S", Construct);
1596 ------------------------
1597 -- Collect_Interfaces --
1598 ------------------------
1600 procedure Collect_Interfaces
1602 Ifaces_List : out Elist_Id;
1603 Exclude_Parents : Boolean := False;
1604 Use_Full_View : Boolean := True)
1606 procedure Collect (Typ : Entity_Id);
1607 -- Subsidiary subprogram used to traverse the whole list
1608 -- of directly and indirectly implemented interfaces
1614 procedure Collect (Typ : Entity_Id) is
1615 Ancestor : Entity_Id;
1623 -- Handle private types
1626 and then Is_Private_Type (Typ)
1627 and then Present (Full_View (Typ))
1629 Full_T := Full_View (Typ);
1632 -- Include the ancestor if we are generating the whole list of
1633 -- abstract interfaces.
1635 if Etype (Full_T) /= Typ
1637 -- Protect the frontend against wrong sources. For example:
1640 -- type A is tagged null record;
1641 -- type B is new A with private;
1642 -- type C is new A with private;
1644 -- type B is new C with null record;
1645 -- type C is new B with null record;
1648 and then Etype (Full_T) /= T
1650 Ancestor := Etype (Full_T);
1653 if Is_Interface (Ancestor)
1654 and then not Exclude_Parents
1656 Append_Unique_Elmt (Ancestor, Ifaces_List);
1660 -- Traverse the graph of ancestor interfaces
1662 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1663 Id := First (Abstract_Interface_List (Full_T));
1664 while Present (Id) loop
1665 Iface := Etype (Id);
1667 -- Protect against wrong uses. For example:
1668 -- type I is interface;
1669 -- type O is tagged null record;
1670 -- type Wrong is new I and O with null record; -- ERROR
1672 if Is_Interface (Iface) then
1674 and then Etype (T) /= T
1675 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1680 Append_Unique_Elmt (Iface, Ifaces_List);
1689 -- Start of processing for Collect_Interfaces
1692 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1693 Ifaces_List := New_Elmt_List;
1695 end Collect_Interfaces;
1697 ----------------------------------
1698 -- Collect_Interface_Components --
1699 ----------------------------------
1701 procedure Collect_Interface_Components
1702 (Tagged_Type : Entity_Id;
1703 Components_List : out Elist_Id)
1705 procedure Collect (Typ : Entity_Id);
1706 -- Subsidiary subprogram used to climb to the parents
1712 procedure Collect (Typ : Entity_Id) is
1713 Tag_Comp : Entity_Id;
1714 Parent_Typ : Entity_Id;
1717 -- Handle private types
1719 if Present (Full_View (Etype (Typ))) then
1720 Parent_Typ := Full_View (Etype (Typ));
1722 Parent_Typ := Etype (Typ);
1725 if Parent_Typ /= Typ
1727 -- Protect the frontend against wrong sources. For example:
1730 -- type A is tagged null record;
1731 -- type B is new A with private;
1732 -- type C is new A with private;
1734 -- type B is new C with null record;
1735 -- type C is new B with null record;
1738 and then Parent_Typ /= Tagged_Type
1740 Collect (Parent_Typ);
1743 -- Collect the components containing tags of secondary dispatch
1746 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1747 while Present (Tag_Comp) loop
1748 pragma Assert (Present (Related_Type (Tag_Comp)));
1749 Append_Elmt (Tag_Comp, Components_List);
1751 Tag_Comp := Next_Tag_Component (Tag_Comp);
1755 -- Start of processing for Collect_Interface_Components
1758 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1759 and then Is_Tagged_Type (Tagged_Type));
1761 Components_List := New_Elmt_List;
1762 Collect (Tagged_Type);
1763 end Collect_Interface_Components;
1765 -----------------------------
1766 -- Collect_Interfaces_Info --
1767 -----------------------------
1769 procedure Collect_Interfaces_Info
1771 Ifaces_List : out Elist_Id;
1772 Components_List : out Elist_Id;
1773 Tags_List : out Elist_Id)
1775 Comps_List : Elist_Id;
1776 Comp_Elmt : Elmt_Id;
1777 Comp_Iface : Entity_Id;
1778 Iface_Elmt : Elmt_Id;
1781 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1782 -- Search for the secondary tag associated with the interface type
1783 -- Iface that is implemented by T.
1789 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1792 if not Is_CPP_Class (T) then
1793 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1795 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1799 and then Is_Tag (Node (ADT))
1800 and then Related_Type (Node (ADT)) /= Iface
1802 -- Skip secondary dispatch table referencing thunks to user
1803 -- defined primitives covered by this interface.
1805 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1808 -- Skip secondary dispatch tables of Ada types
1810 if not Is_CPP_Class (T) then
1812 -- Skip secondary dispatch table referencing thunks to
1813 -- predefined primitives.
1815 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1818 -- Skip secondary dispatch table referencing user-defined
1819 -- primitives covered by this interface.
1821 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1824 -- Skip secondary dispatch table referencing predefined
1827 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1832 pragma Assert (Is_Tag (Node (ADT)));
1836 -- Start of processing for Collect_Interfaces_Info
1839 Collect_Interfaces (T, Ifaces_List);
1840 Collect_Interface_Components (T, Comps_List);
1842 -- Search for the record component and tag associated with each
1843 -- interface type of T.
1845 Components_List := New_Elmt_List;
1846 Tags_List := New_Elmt_List;
1848 Iface_Elmt := First_Elmt (Ifaces_List);
1849 while Present (Iface_Elmt) loop
1850 Iface := Node (Iface_Elmt);
1852 -- Associate the primary tag component and the primary dispatch table
1853 -- with all the interfaces that are parents of T
1855 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1856 Append_Elmt (First_Tag_Component (T), Components_List);
1857 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1859 -- Otherwise search for the tag component and secondary dispatch
1863 Comp_Elmt := First_Elmt (Comps_List);
1864 while Present (Comp_Elmt) loop
1865 Comp_Iface := Related_Type (Node (Comp_Elmt));
1867 if Comp_Iface = Iface
1868 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1870 Append_Elmt (Node (Comp_Elmt), Components_List);
1871 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1875 Next_Elmt (Comp_Elmt);
1877 pragma Assert (Present (Comp_Elmt));
1880 Next_Elmt (Iface_Elmt);
1882 end Collect_Interfaces_Info;
1884 ---------------------
1885 -- Collect_Parents --
1886 ---------------------
1888 procedure Collect_Parents
1890 List : out Elist_Id;
1891 Use_Full_View : Boolean := True)
1893 Current_Typ : Entity_Id := T;
1894 Parent_Typ : Entity_Id;
1897 List := New_Elmt_List;
1899 -- No action if the if the type has no parents
1901 if T = Etype (T) then
1906 Parent_Typ := Etype (Current_Typ);
1908 if Is_Private_Type (Parent_Typ)
1909 and then Present (Full_View (Parent_Typ))
1910 and then Use_Full_View
1912 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1915 Append_Elmt (Parent_Typ, List);
1917 exit when Parent_Typ = Current_Typ;
1918 Current_Typ := Parent_Typ;
1920 end Collect_Parents;
1922 ----------------------------------
1923 -- Collect_Primitive_Operations --
1924 ----------------------------------
1926 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1927 B_Type : constant Entity_Id := Base_Type (T);
1928 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1929 B_Scope : Entity_Id := Scope (B_Type);
1933 Formal_Derived : Boolean := False;
1936 function Match (E : Entity_Id) return Boolean;
1937 -- True if E's base type is B_Type, or E is of an anonymous access type
1938 -- and the base type of its designated type is B_Type.
1944 function Match (E : Entity_Id) return Boolean is
1945 Etyp : Entity_Id := Etype (E);
1948 if Ekind (Etyp) = E_Anonymous_Access_Type then
1949 Etyp := Designated_Type (Etyp);
1952 return Base_Type (Etyp) = B_Type;
1955 -- Start of processing for Collect_Primitive_Operations
1958 -- For tagged types, the primitive operations are collected as they
1959 -- are declared, and held in an explicit list which is simply returned.
1961 if Is_Tagged_Type (B_Type) then
1962 return Primitive_Operations (B_Type);
1964 -- An untagged generic type that is a derived type inherits the
1965 -- primitive operations of its parent type. Other formal types only
1966 -- have predefined operators, which are not explicitly represented.
1968 elsif Is_Generic_Type (B_Type) then
1969 if Nkind (B_Decl) = N_Formal_Type_Declaration
1970 and then Nkind (Formal_Type_Definition (B_Decl))
1971 = N_Formal_Derived_Type_Definition
1973 Formal_Derived := True;
1975 return New_Elmt_List;
1979 Op_List := New_Elmt_List;
1981 if B_Scope = Standard_Standard then
1982 if B_Type = Standard_String then
1983 Append_Elmt (Standard_Op_Concat, Op_List);
1985 elsif B_Type = Standard_Wide_String then
1986 Append_Elmt (Standard_Op_Concatw, Op_List);
1992 elsif (Is_Package_Or_Generic_Package (B_Scope)
1994 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1996 or else Is_Derived_Type (B_Type)
1998 -- The primitive operations appear after the base type, except
1999 -- if the derivation happens within the private part of B_Scope
2000 -- and the type is a private type, in which case both the type
2001 -- and some primitive operations may appear before the base
2002 -- type, and the list of candidates starts after the type.
2004 if In_Open_Scopes (B_Scope)
2005 and then Scope (T) = B_Scope
2006 and then In_Private_Part (B_Scope)
2008 Id := Next_Entity (T);
2010 Id := Next_Entity (B_Type);
2013 while Present (Id) loop
2015 -- Note that generic formal subprograms are not
2016 -- considered to be primitive operations and thus
2017 -- are never inherited.
2019 if Is_Overloadable (Id)
2020 and then Nkind (Parent (Parent (Id)))
2021 not in N_Formal_Subprogram_Declaration
2029 Formal := First_Formal (Id);
2030 while Present (Formal) loop
2031 if Match (Formal) then
2036 Next_Formal (Formal);
2040 -- For a formal derived type, the only primitives are the
2041 -- ones inherited from the parent type. Operations appearing
2042 -- in the package declaration are not primitive for it.
2045 and then (not Formal_Derived
2046 or else Present (Alias (Id)))
2048 -- In the special case of an equality operator aliased to
2049 -- an overriding dispatching equality belonging to the same
2050 -- type, we don't include it in the list of primitives.
2051 -- This avoids inheriting multiple equality operators when
2052 -- deriving from untagged private types whose full type is
2053 -- tagged, which can otherwise cause ambiguities. Note that
2054 -- this should only happen for this kind of untagged parent
2055 -- type, since normally dispatching operations are inherited
2056 -- using the type's Primitive_Operations list.
2058 if Chars (Id) = Name_Op_Eq
2059 and then Is_Dispatching_Operation (Id)
2060 and then Present (Alias (Id))
2061 and then Present (Overridden_Operation (Alias (Id)))
2062 and then Base_Type (Etype (First_Entity (Id))) =
2063 Base_Type (Etype (First_Entity (Alias (Id))))
2067 -- Include the subprogram in the list of primitives
2070 Append_Elmt (Id, Op_List);
2077 -- For a type declared in System, some of its operations may
2078 -- appear in the target-specific extension to System.
2081 and then B_Scope = RTU_Entity (System)
2082 and then Present_System_Aux
2084 B_Scope := System_Aux_Id;
2085 Id := First_Entity (System_Aux_Id);
2091 end Collect_Primitive_Operations;
2093 -----------------------------------
2094 -- Compile_Time_Constraint_Error --
2095 -----------------------------------
2097 function Compile_Time_Constraint_Error
2100 Ent : Entity_Id := Empty;
2101 Loc : Source_Ptr := No_Location;
2102 Warn : Boolean := False) return Node_Id
2104 Msgc : String (1 .. Msg'Length + 2);
2105 -- Copy of message, with room for possible ? and ! at end
2115 -- A static constraint error in an instance body is not a fatal error.
2116 -- we choose to inhibit the message altogether, because there is no
2117 -- obvious node (for now) on which to post it. On the other hand the
2118 -- offending node must be replaced with a constraint_error in any case.
2120 -- No messages are generated if we already posted an error on this node
2122 if not Error_Posted (N) then
2123 if Loc /= No_Location then
2129 Msgc (1 .. Msg'Length) := Msg;
2132 -- Message is a warning, even in Ada 95 case
2134 if Msg (Msg'Last) = '?' then
2137 -- In Ada 83, all messages are warnings. In the private part and
2138 -- the body of an instance, constraint_checks are only warnings.
2139 -- We also make this a warning if the Warn parameter is set.
2142 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2148 elsif In_Instance_Not_Visible then
2153 -- Otherwise we have a real error message (Ada 95 static case)
2154 -- and we make this an unconditional message. Note that in the
2155 -- warning case we do not make the message unconditional, it seems
2156 -- quite reasonable to delete messages like this (about exceptions
2157 -- that will be raised) in dead code.
2165 -- Should we generate a warning? The answer is not quite yes. The
2166 -- very annoying exception occurs in the case of a short circuit
2167 -- operator where the left operand is static and decisive. Climb
2168 -- parents to see if that is the case we have here. Conditional
2169 -- expressions with decisive conditions are a similar situation.
2177 -- And then with False as left operand
2179 if Nkind (P) = N_And_Then
2180 and then Compile_Time_Known_Value (Left_Opnd (P))
2181 and then Is_False (Expr_Value (Left_Opnd (P)))
2186 -- OR ELSE with True as left operand
2188 elsif Nkind (P) = N_Or_Else
2189 and then Compile_Time_Known_Value (Left_Opnd (P))
2190 and then Is_True (Expr_Value (Left_Opnd (P)))
2195 -- Conditional expression
2197 elsif Nkind (P) = N_Conditional_Expression then
2199 Cond : constant Node_Id := First (Expressions (P));
2200 Texp : constant Node_Id := Next (Cond);
2201 Fexp : constant Node_Id := Next (Texp);
2204 if Compile_Time_Known_Value (Cond) then
2206 -- Condition is True and we are in the right operand
2208 if Is_True (Expr_Value (Cond))
2209 and then OldP = Fexp
2214 -- Condition is False and we are in the left operand
2216 elsif Is_False (Expr_Value (Cond))
2217 and then OldP = Texp
2225 -- Special case for component association in aggregates, where
2226 -- we want to keep climbing up to the parent aggregate.
2228 elsif Nkind (P) = N_Component_Association
2229 and then Nkind (Parent (P)) = N_Aggregate
2233 -- Keep going if within subexpression
2236 exit when Nkind (P) not in N_Subexpr;
2241 if Present (Ent) then
2242 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2244 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2248 if Inside_Init_Proc then
2250 ("\?& will be raised for objects of this type",
2251 N, Standard_Constraint_Error, Eloc);
2254 ("\?& will be raised at run time",
2255 N, Standard_Constraint_Error, Eloc);
2260 ("\static expression fails Constraint_Check", Eloc);
2261 Set_Error_Posted (N);
2267 end Compile_Time_Constraint_Error;
2269 -----------------------
2270 -- Conditional_Delay --
2271 -----------------------
2273 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2275 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2276 Set_Has_Delayed_Freeze (New_Ent);
2278 end Conditional_Delay;
2280 -------------------------
2281 -- Copy_Component_List --
2282 -------------------------
2284 function Copy_Component_List
2286 Loc : Source_Ptr) return List_Id
2289 Comps : constant List_Id := New_List;
2292 Comp := First_Component (Underlying_Type (R_Typ));
2293 while Present (Comp) loop
2294 if Comes_From_Source (Comp) then
2296 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
2299 Make_Component_Declaration (Loc,
2300 Defining_Identifier =>
2301 Make_Defining_Identifier (Loc, Chars (Comp)),
2302 Component_Definition =>
2304 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
2308 Next_Component (Comp);
2312 end Copy_Component_List;
2314 -------------------------
2315 -- Copy_Parameter_List --
2316 -------------------------
2318 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2319 Loc : constant Source_Ptr := Sloc (Subp_Id);
2324 if No (First_Formal (Subp_Id)) then
2328 Formal := First_Formal (Subp_Id);
2329 while Present (Formal) loop
2331 (Make_Parameter_Specification (Loc,
2332 Defining_Identifier =>
2333 Make_Defining_Identifier (Sloc (Formal),
2334 Chars => Chars (Formal)),
2335 In_Present => In_Present (Parent (Formal)),
2336 Out_Present => Out_Present (Parent (Formal)),
2338 New_Reference_To (Etype (Formal), Loc),
2340 New_Copy_Tree (Expression (Parent (Formal)))),
2343 Next_Formal (Formal);
2348 end Copy_Parameter_List;
2350 --------------------
2351 -- Current_Entity --
2352 --------------------
2354 -- The currently visible definition for a given identifier is the
2355 -- one most chained at the start of the visibility chain, i.e. the
2356 -- one that is referenced by the Node_Id value of the name of the
2357 -- given identifier.
2359 function Current_Entity (N : Node_Id) return Entity_Id is
2361 return Get_Name_Entity_Id (Chars (N));
2364 -----------------------------
2365 -- Current_Entity_In_Scope --
2366 -----------------------------
2368 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2370 CS : constant Entity_Id := Current_Scope;
2372 Transient_Case : constant Boolean := Scope_Is_Transient;
2375 E := Get_Name_Entity_Id (Chars (N));
2377 and then Scope (E) /= CS
2378 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2384 end Current_Entity_In_Scope;
2390 function Current_Scope return Entity_Id is
2392 if Scope_Stack.Last = -1 then
2393 return Standard_Standard;
2396 C : constant Entity_Id :=
2397 Scope_Stack.Table (Scope_Stack.Last).Entity;
2402 return Standard_Standard;
2408 ------------------------
2409 -- Current_Subprogram --
2410 ------------------------
2412 function Current_Subprogram return Entity_Id is
2413 Scop : constant Entity_Id := Current_Scope;
2415 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2418 return Enclosing_Subprogram (Scop);
2420 end Current_Subprogram;
2422 ----------------------------------
2423 -- Deepest_Type_Access_Level --
2424 ----------------------------------
2426 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
2428 if Ekind (Typ) = E_Anonymous_Access_Type
2429 and then not Is_Local_Anonymous_Access (Typ)
2430 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
2432 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
2436 Scope_Depth (Enclosing_Dynamic_Scope
2437 (Defining_Identifier
2438 (Associated_Node_For_Itype (Typ))));
2441 return Type_Access_Level (Typ);
2443 end Deepest_Type_Access_Level;
2445 ---------------------
2446 -- Defining_Entity --
2447 ---------------------
2449 function Defining_Entity (N : Node_Id) return Entity_Id is
2450 K : constant Node_Kind := Nkind (N);
2451 Err : Entity_Id := Empty;
2456 N_Subprogram_Declaration |
2457 N_Abstract_Subprogram_Declaration |
2459 N_Package_Declaration |
2460 N_Subprogram_Renaming_Declaration |
2461 N_Subprogram_Body_Stub |
2462 N_Generic_Subprogram_Declaration |
2463 N_Generic_Package_Declaration |
2464 N_Formal_Subprogram_Declaration
2466 return Defining_Entity (Specification (N));
2469 N_Component_Declaration |
2470 N_Defining_Program_Unit_Name |
2471 N_Discriminant_Specification |
2473 N_Entry_Declaration |
2474 N_Entry_Index_Specification |
2475 N_Exception_Declaration |
2476 N_Exception_Renaming_Declaration |
2477 N_Formal_Object_Declaration |
2478 N_Formal_Package_Declaration |
2479 N_Formal_Type_Declaration |
2480 N_Full_Type_Declaration |
2481 N_Implicit_Label_Declaration |
2482 N_Incomplete_Type_Declaration |
2483 N_Loop_Parameter_Specification |
2484 N_Number_Declaration |
2485 N_Object_Declaration |
2486 N_Object_Renaming_Declaration |
2487 N_Package_Body_Stub |
2488 N_Parameter_Specification |
2489 N_Private_Extension_Declaration |
2490 N_Private_Type_Declaration |
2492 N_Protected_Body_Stub |
2493 N_Protected_Type_Declaration |
2494 N_Single_Protected_Declaration |
2495 N_Single_Task_Declaration |
2496 N_Subtype_Declaration |
2499 N_Task_Type_Declaration
2501 return Defining_Identifier (N);
2504 return Defining_Entity (Proper_Body (N));
2507 N_Function_Instantiation |
2508 N_Function_Specification |
2509 N_Generic_Function_Renaming_Declaration |
2510 N_Generic_Package_Renaming_Declaration |
2511 N_Generic_Procedure_Renaming_Declaration |
2513 N_Package_Instantiation |
2514 N_Package_Renaming_Declaration |
2515 N_Package_Specification |
2516 N_Procedure_Instantiation |
2517 N_Procedure_Specification
2520 Nam : constant Node_Id := Defining_Unit_Name (N);
2523 if Nkind (Nam) in N_Entity then
2526 -- For Error, make up a name and attach to declaration
2527 -- so we can continue semantic analysis
2529 elsif Nam = Error then
2530 Err := Make_Temporary (Sloc (N), 'T');
2531 Set_Defining_Unit_Name (N, Err);
2534 -- If not an entity, get defining identifier
2537 return Defining_Identifier (Nam);
2541 when N_Block_Statement =>
2542 return Entity (Identifier (N));
2545 raise Program_Error;
2548 end Defining_Entity;
2550 --------------------------
2551 -- Denotes_Discriminant --
2552 --------------------------
2554 function Denotes_Discriminant
2556 Check_Concurrent : Boolean := False) return Boolean
2560 if not Is_Entity_Name (N)
2561 or else No (Entity (N))
2568 -- If we are checking for a protected type, the discriminant may have
2569 -- been rewritten as the corresponding discriminal of the original type
2570 -- or of the corresponding concurrent record, depending on whether we
2571 -- are in the spec or body of the protected type.
2573 return Ekind (E) = E_Discriminant
2576 and then Ekind (E) = E_In_Parameter
2577 and then Present (Discriminal_Link (E))
2579 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2581 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2583 end Denotes_Discriminant;
2585 -------------------------
2586 -- Denotes_Same_Object --
2587 -------------------------
2589 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2590 Obj1 : Node_Id := A1;
2591 Obj2 : Node_Id := A2;
2593 procedure Check_Renaming (Obj : in out Node_Id);
2594 -- If an object is a renaming, examine renamed object. If it is a
2595 -- dereference of a variable, or an indexed expression with non-constant
2596 -- indexes, no overlap check can be reported.
2598 --------------------
2599 -- Check_Renaming --
2600 --------------------
2602 procedure Check_Renaming (Obj : in out Node_Id) is
2604 if Is_Entity_Name (Obj)
2605 and then Present (Renamed_Entity (Entity (Obj)))
2607 Obj := Renamed_Entity (Entity (Obj));
2608 if Nkind (Obj) = N_Explicit_Dereference
2609 and then Is_Variable (Prefix (Obj))
2613 elsif Nkind (Obj) = N_Indexed_Component then
2618 Indx := First (Expressions (Obj));
2619 while Present (Indx) loop
2620 if not Is_OK_Static_Expression (Indx) then
2632 -- Start of processing for Denotes_Same_Object
2635 Check_Renaming (Obj1);
2636 Check_Renaming (Obj2);
2644 -- If we have entity names, then must be same entity
2646 if Is_Entity_Name (Obj1) then
2647 if Is_Entity_Name (Obj2) then
2648 return Entity (Obj1) = Entity (Obj2);
2653 -- No match if not same node kind
2655 elsif Nkind (Obj1) /= Nkind (Obj2) then
2658 -- For selected components, must have same prefix and selector
2660 elsif Nkind (Obj1) = N_Selected_Component then
2661 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2663 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2665 -- For explicit dereferences, prefixes must be same
2667 elsif Nkind (Obj1) = N_Explicit_Dereference then
2668 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2670 -- For indexed components, prefixes and all subscripts must be the same
2672 elsif Nkind (Obj1) = N_Indexed_Component then
2673 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2679 Indx1 := First (Expressions (Obj1));
2680 Indx2 := First (Expressions (Obj2));
2681 while Present (Indx1) loop
2683 -- Indexes must denote the same static value or same object
2685 if Is_OK_Static_Expression (Indx1) then
2686 if not Is_OK_Static_Expression (Indx2) then
2689 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2693 elsif not Denotes_Same_Object (Indx1, Indx2) then
2707 -- For slices, prefixes must match and bounds must match
2709 elsif Nkind (Obj1) = N_Slice
2710 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2713 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2716 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2717 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2719 -- Check whether bounds are statically identical. There is no
2720 -- attempt to detect partial overlap of slices.
2722 return Denotes_Same_Object (Lo1, Lo2)
2723 and then Denotes_Same_Object (Hi1, Hi2);
2726 -- Literals will appear as indexes. Isn't this where we should check
2727 -- Known_At_Compile_Time at least if we are generating warnings ???
2729 elsif Nkind (Obj1) = N_Integer_Literal then
2730 return Intval (Obj1) = Intval (Obj2);
2735 end Denotes_Same_Object;
2737 -------------------------
2738 -- Denotes_Same_Prefix --
2739 -------------------------
2741 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2744 if Is_Entity_Name (A1) then
2745 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2746 and then not Is_Access_Type (Etype (A1))
2748 return Denotes_Same_Object (A1, Prefix (A2))
2749 or else Denotes_Same_Prefix (A1, Prefix (A2));
2754 elsif Is_Entity_Name (A2) then
2755 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
2757 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2759 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2762 Root1, Root2 : Node_Id;
2763 Depth1, Depth2 : Int := 0;
2766 Root1 := Prefix (A1);
2767 while not Is_Entity_Name (Root1) loop
2769 (Root1, N_Selected_Component, N_Indexed_Component)
2773 Root1 := Prefix (Root1);
2776 Depth1 := Depth1 + 1;
2779 Root2 := Prefix (A2);
2780 while not Is_Entity_Name (Root2) loop
2782 (Root2, N_Selected_Component, N_Indexed_Component)
2786 Root2 := Prefix (Root2);
2789 Depth2 := Depth2 + 1;
2792 -- If both have the same depth and they do not denote the same
2793 -- object, they are disjoint and not warning is needed.
2795 if Depth1 = Depth2 then
2798 elsif Depth1 > Depth2 then
2799 Root1 := Prefix (A1);
2800 for I in 1 .. Depth1 - Depth2 - 1 loop
2801 Root1 := Prefix (Root1);
2804 return Denotes_Same_Object (Root1, A2);
2807 Root2 := Prefix (A2);
2808 for I in 1 .. Depth2 - Depth1 - 1 loop
2809 Root2 := Prefix (Root2);
2812 return Denotes_Same_Object (A1, Root2);
2819 end Denotes_Same_Prefix;
2821 ----------------------
2822 -- Denotes_Variable --
2823 ----------------------
2825 function Denotes_Variable (N : Node_Id) return Boolean is
2827 return Is_Variable (N) and then Paren_Count (N) = 0;
2828 end Denotes_Variable;
2830 -----------------------------
2831 -- Depends_On_Discriminant --
2832 -----------------------------
2834 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2839 Get_Index_Bounds (N, L, H);
2840 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2841 end Depends_On_Discriminant;
2843 -------------------------
2844 -- Designate_Same_Unit --
2845 -------------------------
2847 function Designate_Same_Unit
2849 Name2 : Node_Id) return Boolean
2851 K1 : constant Node_Kind := Nkind (Name1);
2852 K2 : constant Node_Kind := Nkind (Name2);
2854 function Prefix_Node (N : Node_Id) return Node_Id;
2855 -- Returns the parent unit name node of a defining program unit name
2856 -- or the prefix if N is a selected component or an expanded name.
2858 function Select_Node (N : Node_Id) return Node_Id;
2859 -- Returns the defining identifier node of a defining program unit
2860 -- name or the selector node if N is a selected component or an
2867 function Prefix_Node (N : Node_Id) return Node_Id is
2869 if Nkind (N) = N_Defining_Program_Unit_Name then
2881 function Select_Node (N : Node_Id) return Node_Id is
2883 if Nkind (N) = N_Defining_Program_Unit_Name then
2884 return Defining_Identifier (N);
2887 return Selector_Name (N);
2891 -- Start of processing for Designate_Next_Unit
2894 if (K1 = N_Identifier or else
2895 K1 = N_Defining_Identifier)
2897 (K2 = N_Identifier or else
2898 K2 = N_Defining_Identifier)
2900 return Chars (Name1) = Chars (Name2);
2903 (K1 = N_Expanded_Name or else
2904 K1 = N_Selected_Component or else
2905 K1 = N_Defining_Program_Unit_Name)
2907 (K2 = N_Expanded_Name or else
2908 K2 = N_Selected_Component or else
2909 K2 = N_Defining_Program_Unit_Name)
2912 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2914 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2919 end Designate_Same_Unit;
2921 ------------------------------------------
2922 -- function Dynamic_Accessibility_Level --
2923 ------------------------------------------
2925 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
2927 Loc : constant Source_Ptr := Sloc (Expr);
2929 function Make_Level_Literal (Level : Uint) return Node_Id;
2930 -- Construct an integer literal representing an accessibility level
2931 -- with its type set to Natural.
2933 ------------------------
2934 -- Make_Level_Literal --
2935 ------------------------
2937 function Make_Level_Literal (Level : Uint) return Node_Id is
2938 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
2940 Set_Etype (Result, Standard_Natural);
2942 end Make_Level_Literal;
2944 -- Start of processing for Dynamic_Accessibility_Level
2947 if Is_Entity_Name (Expr) then
2950 if Present (Renamed_Object (E)) then
2951 return Dynamic_Accessibility_Level (Renamed_Object (E));
2954 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
2955 if Present (Extra_Accessibility (E)) then
2956 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
2961 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
2963 case Nkind (Expr) is
2965 -- For access discriminant, the level of the enclosing object
2967 when N_Selected_Component =>
2968 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
2969 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
2970 E_Anonymous_Access_Type
2972 return Make_Level_Literal (Object_Access_Level (Expr));
2975 when N_Attribute_Reference =>
2976 case Get_Attribute_Id (Attribute_Name (Expr)) is
2978 -- For X'Access, the level of the prefix X
2980 when Attribute_Access =>
2981 return Make_Level_Literal
2982 (Object_Access_Level (Prefix (Expr)));
2984 -- Treat the unchecked attributes as library-level
2986 when Attribute_Unchecked_Access |
2987 Attribute_Unrestricted_Access =>
2988 return Make_Level_Literal (Scope_Depth (Standard_Standard));
2990 -- No other access-valued attributes
2993 raise Program_Error;
2998 -- Unimplemented: depends on context. As an actual parameter where
2999 -- formal type is anonymous, use
3000 -- Scope_Depth (Current_Scope) + 1.
3001 -- For other cases, see 3.10.2(14/3) and following. ???
3005 when N_Type_Conversion =>
3006 if not Is_Local_Anonymous_Access (Etype (Expr)) then
3008 -- Handle type conversions introduced for a rename of an
3009 -- Ada 2012 stand-alone object of an anonymous access type.
3011 return Dynamic_Accessibility_Level (Expression (Expr));
3018 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
3019 end Dynamic_Accessibility_Level;
3021 -----------------------------------
3022 -- Effective_Extra_Accessibility --
3023 -----------------------------------
3025 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
3027 if Present (Renamed_Object (Id))
3028 and then Is_Entity_Name (Renamed_Object (Id))
3030 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
3033 return Extra_Accessibility (Id);
3034 end Effective_Extra_Accessibility;
3036 --------------------------
3037 -- Enclosing_CPP_Parent --
3038 --------------------------
3040 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
3041 Parent_Typ : Entity_Id := Typ;
3044 while not Is_CPP_Class (Parent_Typ)
3045 and then Etype (Parent_Typ) /= Parent_Typ
3047 Parent_Typ := Etype (Parent_Typ);
3049 if Is_Private_Type (Parent_Typ) then
3050 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3054 pragma Assert (Is_CPP_Class (Parent_Typ));
3056 end Enclosing_CPP_Parent;
3058 ----------------------------
3059 -- Enclosing_Generic_Body --
3060 ----------------------------
3062 function Enclosing_Generic_Body
3063 (N : Node_Id) return Node_Id
3071 while Present (P) loop
3072 if Nkind (P) = N_Package_Body
3073 or else Nkind (P) = N_Subprogram_Body
3075 Spec := Corresponding_Spec (P);
3077 if Present (Spec) then
3078 Decl := Unit_Declaration_Node (Spec);
3080 if Nkind (Decl) = N_Generic_Package_Declaration
3081 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3092 end Enclosing_Generic_Body;
3094 ----------------------------
3095 -- Enclosing_Generic_Unit --
3096 ----------------------------
3098 function Enclosing_Generic_Unit
3099 (N : Node_Id) return Node_Id
3107 while Present (P) loop
3108 if Nkind (P) = N_Generic_Package_Declaration
3109 or else Nkind (P) = N_Generic_Subprogram_Declaration
3113 elsif Nkind (P) = N_Package_Body
3114 or else Nkind (P) = N_Subprogram_Body
3116 Spec := Corresponding_Spec (P);
3118 if Present (Spec) then
3119 Decl := Unit_Declaration_Node (Spec);
3121 if Nkind (Decl) = N_Generic_Package_Declaration
3122 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3133 end Enclosing_Generic_Unit;
3135 -------------------------------
3136 -- Enclosing_Lib_Unit_Entity --
3137 -------------------------------
3139 function Enclosing_Lib_Unit_Entity return Entity_Id is
3140 Unit_Entity : Entity_Id;
3143 -- Look for enclosing library unit entity by following scope links.
3144 -- Equivalent to, but faster than indexing through the scope stack.
3146 Unit_Entity := Current_Scope;
3147 while (Present (Scope (Unit_Entity))
3148 and then Scope (Unit_Entity) /= Standard_Standard)
3149 and not Is_Child_Unit (Unit_Entity)
3151 Unit_Entity := Scope (Unit_Entity);
3155 end Enclosing_Lib_Unit_Entity;
3157 -----------------------------
3158 -- Enclosing_Lib_Unit_Node --
3159 -----------------------------
3161 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
3162 Current_Node : Node_Id;
3166 while Present (Current_Node)
3167 and then Nkind (Current_Node) /= N_Compilation_Unit
3169 Current_Node := Parent (Current_Node);
3172 if Nkind (Current_Node) /= N_Compilation_Unit then
3176 return Current_Node;
3177 end Enclosing_Lib_Unit_Node;
3179 -----------------------
3180 -- Enclosing_Package --
3181 -----------------------
3183 function Enclosing_Package (E : Entity_Id) return Entity_Id is
3184 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3187 if Dynamic_Scope = Standard_Standard then
3188 return Standard_Standard;
3190 elsif Dynamic_Scope = Empty then
3193 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
3196 return Dynamic_Scope;
3199 return Enclosing_Package (Dynamic_Scope);
3201 end Enclosing_Package;
3203 --------------------------
3204 -- Enclosing_Subprogram --
3205 --------------------------
3207 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3208 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3211 if Dynamic_Scope = Standard_Standard then
3214 elsif Dynamic_Scope = Empty then
3217 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3218 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3220 elsif Ekind (Dynamic_Scope) = E_Block
3221 or else Ekind (Dynamic_Scope) = E_Return_Statement
3223 return Enclosing_Subprogram (Dynamic_Scope);
3225 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3226 return Get_Task_Body_Procedure (Dynamic_Scope);
3228 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3229 and then Present (Full_View (Dynamic_Scope))
3230 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3232 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3234 -- No body is generated if the protected operation is eliminated
3236 elsif Convention (Dynamic_Scope) = Convention_Protected
3237 and then not Is_Eliminated (Dynamic_Scope)
3238 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3240 return Protected_Body_Subprogram (Dynamic_Scope);
3243 return Dynamic_Scope;
3245 end Enclosing_Subprogram;
3247 ------------------------
3248 -- Ensure_Freeze_Node --
3249 ------------------------
3251 procedure Ensure_Freeze_Node (E : Entity_Id) is
3255 if No (Freeze_Node (E)) then
3256 FN := Make_Freeze_Entity (Sloc (E));
3257 Set_Has_Delayed_Freeze (E);
3258 Set_Freeze_Node (E, FN);
3259 Set_Access_Types_To_Process (FN, No_Elist);
3260 Set_TSS_Elist (FN, No_Elist);
3263 end Ensure_Freeze_Node;
3269 procedure Enter_Name (Def_Id : Entity_Id) is
3270 C : constant Entity_Id := Current_Entity (Def_Id);
3271 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3272 S : constant Entity_Id := Current_Scope;
3275 Generate_Definition (Def_Id);
3277 -- Add new name to current scope declarations. Check for duplicate
3278 -- declaration, which may or may not be a genuine error.
3282 -- Case of previous entity entered because of a missing declaration
3283 -- or else a bad subtype indication. Best is to use the new entity,
3284 -- and make the previous one invisible.
3286 if Etype (E) = Any_Type then
3287 Set_Is_Immediately_Visible (E, False);
3289 -- Case of renaming declaration constructed for package instances.
3290 -- if there is an explicit declaration with the same identifier,
3291 -- the renaming is not immediately visible any longer, but remains
3292 -- visible through selected component notation.
3294 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3295 and then not Comes_From_Source (E)
3297 Set_Is_Immediately_Visible (E, False);
3299 -- The new entity may be the package renaming, which has the same
3300 -- same name as a generic formal which has been seen already.
3302 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3303 and then not Comes_From_Source (Def_Id)
3305 Set_Is_Immediately_Visible (E, False);
3307 -- For a fat pointer corresponding to a remote access to subprogram,
3308 -- we use the same identifier as the RAS type, so that the proper
3309 -- name appears in the stub. This type is only retrieved through
3310 -- the RAS type and never by visibility, and is not added to the
3311 -- visibility list (see below).
3313 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3314 and then Present (Corresponding_Remote_Type (Def_Id))
3318 -- Case of an implicit operation or derived literal. The new entity
3319 -- hides the implicit one, which is removed from all visibility,
3320 -- i.e. the entity list of its scope, and homonym chain of its name.
3322 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3323 or else Is_Internal (E)
3327 Prev_Vis : Entity_Id;
3328 Decl : constant Node_Id := Parent (E);
3331 -- If E is an implicit declaration, it cannot be the first
3332 -- entity in the scope.
3334 Prev := First_Entity (Current_Scope);
3335 while Present (Prev)
3336 and then Next_Entity (Prev) /= E
3343 -- If E is not on the entity chain of the current scope,
3344 -- it is an implicit declaration in the generic formal
3345 -- part of a generic subprogram. When analyzing the body,
3346 -- the generic formals are visible but not on the entity
3347 -- chain of the subprogram. The new entity will become
3348 -- the visible one in the body.
3351 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3355 Set_Next_Entity (Prev, Next_Entity (E));
3357 if No (Next_Entity (Prev)) then
3358 Set_Last_Entity (Current_Scope, Prev);
3361 if E = Current_Entity (E) then
3365 Prev_Vis := Current_Entity (E);
3366 while Homonym (Prev_Vis) /= E loop
3367 Prev_Vis := Homonym (Prev_Vis);
3371 if Present (Prev_Vis) then
3373 -- Skip E in the visibility chain
3375 Set_Homonym (Prev_Vis, Homonym (E));
3378 Set_Name_Entity_Id (Chars (E), Homonym (E));
3383 -- This section of code could use a comment ???
3385 elsif Present (Etype (E))
3386 and then Is_Concurrent_Type (Etype (E))
3391 -- If the homograph is a protected component renaming, it should not
3392 -- be hiding the current entity. Such renamings are treated as weak
3395 elsif Is_Prival (E) then
3396 Set_Is_Immediately_Visible (E, False);
3398 -- In this case the current entity is a protected component renaming.
3399 -- Perform minimal decoration by setting the scope and return since
3400 -- the prival should not be hiding other visible entities.
3402 elsif Is_Prival (Def_Id) then
3403 Set_Scope (Def_Id, Current_Scope);
3406 -- Analogous to privals, the discriminal generated for an entry index
3407 -- parameter acts as a weak declaration. Perform minimal decoration
3408 -- to avoid bogus errors.
3410 elsif Is_Discriminal (Def_Id)
3411 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3413 Set_Scope (Def_Id, Current_Scope);
3416 -- In the body or private part of an instance, a type extension may
3417 -- introduce a component with the same name as that of an actual. The
3418 -- legality rule is not enforced, but the semantics of the full type
3419 -- with two components of same name are not clear at this point???
3421 elsif In_Instance_Not_Visible then
3424 -- When compiling a package body, some child units may have become
3425 -- visible. They cannot conflict with local entities that hide them.
3427 elsif Is_Child_Unit (E)
3428 and then In_Open_Scopes (Scope (E))
3429 and then not Is_Immediately_Visible (E)
3433 -- Conversely, with front-end inlining we may compile the parent body
3434 -- first, and a child unit subsequently. The context is now the
3435 -- parent spec, and body entities are not visible.
3437 elsif Is_Child_Unit (Def_Id)
3438 and then Is_Package_Body_Entity (E)
3439 and then not In_Package_Body (Current_Scope)
3443 -- Case of genuine duplicate declaration
3446 Error_Msg_Sloc := Sloc (E);
3448 -- If the previous declaration is an incomplete type declaration
3449 -- this may be an attempt to complete it with a private type. The
3450 -- following avoids confusing cascaded errors.
3452 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3453 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3456 ("incomplete type cannot be completed with a private " &
3457 "declaration", Parent (Def_Id));
3458 Set_Is_Immediately_Visible (E, False);
3459 Set_Full_View (E, Def_Id);
3461 -- An inherited component of a record conflicts with a new
3462 -- discriminant. The discriminant is inserted first in the scope,
3463 -- but the error should be posted on it, not on the component.
3465 elsif Ekind (E) = E_Discriminant
3466 and then Present (Scope (Def_Id))
3467 and then Scope (Def_Id) /= Current_Scope
3469 Error_Msg_Sloc := Sloc (Def_Id);
3470 Error_Msg_N ("& conflicts with declaration#", E);
3473 -- If the name of the unit appears in its own context clause, a
3474 -- dummy package with the name has already been created, and the
3475 -- error emitted. Try to continue quietly.
3477 elsif Error_Posted (E)
3478 and then Sloc (E) = No_Location
3479 and then Nkind (Parent (E)) = N_Package_Specification
3480 and then Current_Scope = Standard_Standard
3482 Set_Scope (Def_Id, Current_Scope);
3486 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3488 -- Avoid cascaded messages with duplicate components in
3491 if Ekind_In (E, E_Component, E_Discriminant) then
3496 if Nkind (Parent (Parent (Def_Id))) =
3497 N_Generic_Subprogram_Declaration
3499 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3501 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3504 -- If entity is in standard, then we are in trouble, because it
3505 -- means that we have a library package with a duplicated name.
3506 -- That's hard to recover from, so abort!
3508 if S = Standard_Standard then
3509 raise Unrecoverable_Error;
3511 -- Otherwise we continue with the declaration. Having two
3512 -- identical declarations should not cause us too much trouble!
3520 -- If we fall through, declaration is OK, at least OK enough to continue
3522 -- If Def_Id is a discriminant or a record component we are in the midst
3523 -- of inheriting components in a derived record definition. Preserve
3524 -- their Ekind and Etype.
3526 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3529 -- If a type is already set, leave it alone (happens when a type
3530 -- declaration is reanalyzed following a call to the optimizer).
3532 elsif Present (Etype (Def_Id)) then
3535 -- Otherwise, the kind E_Void insures that premature uses of the entity
3536 -- will be detected. Any_Type insures that no cascaded errors will occur
3539 Set_Ekind (Def_Id, E_Void);
3540 Set_Etype (Def_Id, Any_Type);
3543 -- Inherited discriminants and components in derived record types are
3544 -- immediately visible. Itypes are not.
3546 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3547 or else (No (Corresponding_Remote_Type (Def_Id))
3548 and then not Is_Itype (Def_Id))
3550 Set_Is_Immediately_Visible (Def_Id);
3551 Set_Current_Entity (Def_Id);
3554 Set_Homonym (Def_Id, C);
3555 Append_Entity (Def_Id, S);
3556 Set_Public_Status (Def_Id);
3558 -- Declaring a homonym is not allowed in SPARK ...
3561 and then Restriction_Check_Required (SPARK)
3565 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3566 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3567 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3570 -- ... unless the new declaration is in a subprogram, and the
3571 -- visible declaration is a variable declaration or a parameter
3572 -- specification outside that subprogram.
3574 if Present (Enclosing_Subp)
3575 and then Nkind_In (Parent (C), N_Object_Declaration,
3576 N_Parameter_Specification)
3577 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3581 -- ... or the new declaration is in a package, and the visible
3582 -- declaration occurs outside that package.
3584 elsif Present (Enclosing_Pack)
3585 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3589 -- ... or the new declaration is a component declaration in a
3590 -- record type definition.
3592 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3595 -- Don't issue error for non-source entities
3597 elsif Comes_From_Source (Def_Id)
3598 and then Comes_From_Source (C)
3600 Error_Msg_Sloc := Sloc (C);
3601 Check_SPARK_Restriction
3602 ("redeclaration of identifier &#", Def_Id);
3607 -- Warn if new entity hides an old one
3609 if Warn_On_Hiding and then Present (C)
3611 -- Don't warn for record components since they always have a well
3612 -- defined scope which does not confuse other uses. Note that in
3613 -- some cases, Ekind has not been set yet.
3615 and then Ekind (C) /= E_Component
3616 and then Ekind (C) /= E_Discriminant
3617 and then Nkind (Parent (C)) /= N_Component_Declaration
3618 and then Ekind (Def_Id) /= E_Component
3619 and then Ekind (Def_Id) /= E_Discriminant
3620 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3622 -- Don't warn for one character variables. It is too common to use
3623 -- such variables as locals and will just cause too many false hits.
3625 and then Length_Of_Name (Chars (C)) /= 1
3627 -- Don't warn for non-source entities
3629 and then Comes_From_Source (C)
3630 and then Comes_From_Source (Def_Id)
3632 -- Don't warn unless entity in question is in extended main source
3634 and then In_Extended_Main_Source_Unit (Def_Id)
3636 -- Finally, the hidden entity must be either immediately visible or
3637 -- use visible (i.e. from a used package).
3640 (Is_Immediately_Visible (C)
3642 Is_Potentially_Use_Visible (C))
3644 Error_Msg_Sloc := Sloc (C);
3645 Error_Msg_N ("declaration hides &#?", Def_Id);
3649 --------------------------
3650 -- Explain_Limited_Type --
3651 --------------------------
3653 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3657 -- For array, component type must be limited
3659 if Is_Array_Type (T) then
3660 Error_Msg_Node_2 := T;
3662 ("\component type& of type& is limited", N, Component_Type (T));
3663 Explain_Limited_Type (Component_Type (T), N);
3665 elsif Is_Record_Type (T) then
3667 -- No need for extra messages if explicit limited record
3669 if Is_Limited_Record (Base_Type (T)) then
3673 -- Otherwise find a limited component. Check only components that
3674 -- come from source, or inherited components that appear in the
3675 -- source of the ancestor.
3677 C := First_Component (T);
3678 while Present (C) loop
3679 if Is_Limited_Type (Etype (C))
3681 (Comes_From_Source (C)
3683 (Present (Original_Record_Component (C))
3685 Comes_From_Source (Original_Record_Component (C))))
3687 Error_Msg_Node_2 := T;
3688 Error_Msg_NE ("\component& of type& has limited type", N, C);
3689 Explain_Limited_Type (Etype (C), N);
3696 -- The type may be declared explicitly limited, even if no component
3697 -- of it is limited, in which case we fall out of the loop.
3700 end Explain_Limited_Type;
3706 procedure Find_Actual
3708 Formal : out Entity_Id;
3711 Parnt : constant Node_Id := Parent (N);
3715 if (Nkind (Parnt) = N_Indexed_Component
3717 Nkind (Parnt) = N_Selected_Component)
3718 and then N = Prefix (Parnt)
3720 Find_Actual (Parnt, Formal, Call);
3723 elsif Nkind (Parnt) = N_Parameter_Association
3724 and then N = Explicit_Actual_Parameter (Parnt)
3726 Call := Parent (Parnt);
3728 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3737 -- If we have a call to a subprogram look for the parameter. Note that
3738 -- we exclude overloaded calls, since we don't know enough to be sure
3739 -- of giving the right answer in this case.
3741 if Is_Entity_Name (Name (Call))
3742 and then Present (Entity (Name (Call)))
3743 and then Is_Overloadable (Entity (Name (Call)))
3744 and then not Is_Overloaded (Name (Call))
3746 -- Fall here if we are definitely a parameter
3748 Actual := First_Actual (Call);
3749 Formal := First_Formal (Entity (Name (Call)));
3750 while Present (Formal) and then Present (Actual) loop
3754 Actual := Next_Actual (Actual);
3755 Formal := Next_Formal (Formal);
3760 -- Fall through here if we did not find matching actual
3766 ---------------------------
3767 -- Find_Body_Discriminal --
3768 ---------------------------
3770 function Find_Body_Discriminal
3771 (Spec_Discriminant : Entity_Id) return Entity_Id
3777 -- If expansion is suppressed, then the scope can be the concurrent type
3778 -- itself rather than a corresponding concurrent record type.
3780 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
3781 Tsk := Scope (Spec_Discriminant);
3784 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3786 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3789 -- Find discriminant of original concurrent type, and use its current
3790 -- discriminal, which is the renaming within the task/protected body.
3792 Disc := First_Discriminant (Tsk);
3793 while Present (Disc) loop
3794 if Chars (Disc) = Chars (Spec_Discriminant) then
3795 return Discriminal (Disc);
3798 Next_Discriminant (Disc);
3801 -- That loop should always succeed in finding a matching entry and
3802 -- returning. Fatal error if not.
3804 raise Program_Error;
3805 end Find_Body_Discriminal;
3807 -------------------------------------
3808 -- Find_Corresponding_Discriminant --
3809 -------------------------------------
3811 function Find_Corresponding_Discriminant
3813 Typ : Entity_Id) return Entity_Id
3815 Par_Disc : Entity_Id;
3816 Old_Disc : Entity_Id;
3817 New_Disc : Entity_Id;
3820 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3822 -- The original type may currently be private, and the discriminant
3823 -- only appear on its full view.
3825 if Is_Private_Type (Scope (Par_Disc))
3826 and then not Has_Discriminants (Scope (Par_Disc))
3827 and then Present (Full_View (Scope (Par_Disc)))
3829 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3831 Old_Disc := First_Discriminant (Scope (Par_Disc));
3834 if Is_Class_Wide_Type (Typ) then
3835 New_Disc := First_Discriminant (Root_Type (Typ));
3837 New_Disc := First_Discriminant (Typ);
3840 while Present (Old_Disc) and then Present (New_Disc) loop
3841 if Old_Disc = Par_Disc then
3844 Next_Discriminant (Old_Disc);
3845 Next_Discriminant (New_Disc);
3849 -- Should always find it
3851 raise Program_Error;
3852 end Find_Corresponding_Discriminant;
3854 --------------------------
3855 -- Find_Overlaid_Entity --
3856 --------------------------
3858 procedure Find_Overlaid_Entity
3860 Ent : out Entity_Id;
3866 -- We are looking for one of the two following forms:
3868 -- for X'Address use Y'Address
3872 -- Const : constant Address := expr;
3874 -- for X'Address use Const;
3876 -- In the second case, the expr is either Y'Address, or recursively a
3877 -- constant that eventually references Y'Address.
3882 if Nkind (N) = N_Attribute_Definition_Clause
3883 and then Chars (N) = Name_Address
3885 Expr := Expression (N);
3887 -- This loop checks the form of the expression for Y'Address,
3888 -- using recursion to deal with intermediate constants.
3891 -- Check for Y'Address
3893 if Nkind (Expr) = N_Attribute_Reference
3894 and then Attribute_Name (Expr) = Name_Address
3896 Expr := Prefix (Expr);
3899 -- Check for Const where Const is a constant entity
3901 elsif Is_Entity_Name (Expr)
3902 and then Ekind (Entity (Expr)) = E_Constant
3904 Expr := Constant_Value (Entity (Expr));
3906 -- Anything else does not need checking
3913 -- This loop checks the form of the prefix for an entity, using
3914 -- recursion to deal with intermediate components.
3917 -- Check for Y where Y is an entity
3919 if Is_Entity_Name (Expr) then
3920 Ent := Entity (Expr);
3923 -- Check for components
3926 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
3928 Expr := Prefix (Expr);
3931 -- Anything else does not need checking
3938 end Find_Overlaid_Entity;
3940 -------------------------
3941 -- Find_Parameter_Type --
3942 -------------------------
3944 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3946 if Nkind (Param) /= N_Parameter_Specification then
3949 -- For an access parameter, obtain the type from the formal entity
3950 -- itself, because access to subprogram nodes do not carry a type.
3951 -- Shouldn't we always use the formal entity ???
3953 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3954 return Etype (Defining_Identifier (Param));
3957 return Etype (Parameter_Type (Param));
3959 end Find_Parameter_Type;
3961 -----------------------------
3962 -- Find_Static_Alternative --
3963 -----------------------------
3965 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3966 Expr : constant Node_Id := Expression (N);
3967 Val : constant Uint := Expr_Value (Expr);
3972 Alt := First (Alternatives (N));
3975 if Nkind (Alt) /= N_Pragma then
3976 Choice := First (Discrete_Choices (Alt));
3977 while Present (Choice) loop
3979 -- Others choice, always matches
3981 if Nkind (Choice) = N_Others_Choice then
3984 -- Range, check if value is in the range
3986 elsif Nkind (Choice) = N_Range then
3988 Val >= Expr_Value (Low_Bound (Choice))
3990 Val <= Expr_Value (High_Bound (Choice));
3992 -- Choice is a subtype name. Note that we know it must
3993 -- be a static subtype, since otherwise it would have
3994 -- been diagnosed as illegal.
3996 elsif Is_Entity_Name (Choice)
3997 and then Is_Type (Entity (Choice))
3999 exit Search when Is_In_Range (Expr, Etype (Choice),
4000 Assume_Valid => False);
4002 -- Choice is a subtype indication
4004 elsif Nkind (Choice) = N_Subtype_Indication then
4006 C : constant Node_Id := Constraint (Choice);
4007 R : constant Node_Id := Range_Expression (C);
4011 Val >= Expr_Value (Low_Bound (R))
4013 Val <= Expr_Value (High_Bound (R));
4016 -- Choice is a simple expression
4019 exit Search when Val = Expr_Value (Choice);
4027 pragma Assert (Present (Alt));
4030 -- The above loop *must* terminate by finding a match, since
4031 -- we know the case statement is valid, and the value of the
4032 -- expression is known at compile time. When we fall out of
4033 -- the loop, Alt points to the alternative that we know will
4034 -- be selected at run time.
4037 end Find_Static_Alternative;
4043 function First_Actual (Node : Node_Id) return Node_Id is
4047 if No (Parameter_Associations (Node)) then
4051 N := First (Parameter_Associations (Node));
4053 if Nkind (N) = N_Parameter_Association then
4054 return First_Named_Actual (Node);
4060 -----------------------
4061 -- Gather_Components --
4062 -----------------------
4064 procedure Gather_Components
4066 Comp_List : Node_Id;
4067 Governed_By : List_Id;
4069 Report_Errors : out Boolean)
4073 Discrete_Choice : Node_Id;
4074 Comp_Item : Node_Id;
4076 Discrim : Entity_Id;
4077 Discrim_Name : Node_Id;
4078 Discrim_Value : Node_Id;
4081 Report_Errors := False;
4083 if No (Comp_List) or else Null_Present (Comp_List) then
4086 elsif Present (Component_Items (Comp_List)) then
4087 Comp_Item := First (Component_Items (Comp_List));
4093 while Present (Comp_Item) loop
4095 -- Skip the tag of a tagged record, the interface tags, as well
4096 -- as all items that are not user components (anonymous types,
4097 -- rep clauses, Parent field, controller field).
4099 if Nkind (Comp_Item) = N_Component_Declaration then
4101 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
4103 if not Is_Tag (Comp)
4104 and then Chars (Comp) /= Name_uParent
4106 Append_Elmt (Comp, Into);
4114 if No (Variant_Part (Comp_List)) then
4117 Discrim_Name := Name (Variant_Part (Comp_List));
4118 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
4121 -- Look for the discriminant that governs this variant part.
4122 -- The discriminant *must* be in the Governed_By List
4124 Assoc := First (Governed_By);
4125 Find_Constraint : loop
4126 Discrim := First (Choices (Assoc));
4127 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
4128 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
4130 Chars (Corresponding_Discriminant (Entity (Discrim)))
4131 = Chars (Discrim_Name))
4132 or else Chars (Original_Record_Component (Entity (Discrim)))
4133 = Chars (Discrim_Name);
4135 if No (Next (Assoc)) then
4136 if not Is_Constrained (Typ)
4137 and then Is_Derived_Type (Typ)
4138 and then Present (Stored_Constraint (Typ))
4140 -- If the type is a tagged type with inherited discriminants,
4141 -- use the stored constraint on the parent in order to find
4142 -- the values of discriminants that are otherwise hidden by an
4143 -- explicit constraint. Renamed discriminants are handled in
4146 -- If several parent discriminants are renamed by a single
4147 -- discriminant of the derived type, the call to obtain the
4148 -- Corresponding_Discriminant field only retrieves the last
4149 -- of them. We recover the constraint on the others from the
4150 -- Stored_Constraint as well.
4157 D := First_Discriminant (Etype (Typ));
4158 C := First_Elmt (Stored_Constraint (Typ));
4159 while Present (D) and then Present (C) loop
4160 if Chars (Discrim_Name) = Chars (D) then
4161 if Is_Entity_Name (Node (C))
4162 and then Entity (Node (C)) = Entity (Discrim)
4164 -- D is renamed by Discrim, whose value is given in
4171 Make_Component_Association (Sloc (Typ),
4173 (New_Occurrence_Of (D, Sloc (Typ))),
4174 Duplicate_Subexpr_No_Checks (Node (C)));
4176 exit Find_Constraint;
4179 Next_Discriminant (D);
4186 if No (Next (Assoc)) then
4187 Error_Msg_NE (" missing value for discriminant&",
4188 First (Governed_By), Discrim_Name);
4189 Report_Errors := True;
4194 end loop Find_Constraint;
4196 Discrim_Value := Expression (Assoc);
4198 if not Is_OK_Static_Expression (Discrim_Value) then
4200 ("value for discriminant & must be static!",
4201 Discrim_Value, Discrim);
4202 Why_Not_Static (Discrim_Value);
4203 Report_Errors := True;
4207 Search_For_Discriminant_Value : declare
4213 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4216 Find_Discrete_Value : while Present (Variant) loop
4217 Discrete_Choice := First (Discrete_Choices (Variant));
4218 while Present (Discrete_Choice) loop
4220 exit Find_Discrete_Value when
4221 Nkind (Discrete_Choice) = N_Others_Choice;
4223 Get_Index_Bounds (Discrete_Choice, Low, High);
4225 UI_Low := Expr_Value (Low);
4226 UI_High := Expr_Value (High);
4228 exit Find_Discrete_Value when
4229 UI_Low <= UI_Discrim_Value
4231 UI_High >= UI_Discrim_Value;
4233 Next (Discrete_Choice);
4236 Next_Non_Pragma (Variant);
4237 end loop Find_Discrete_Value;
4238 end Search_For_Discriminant_Value;
4240 if No (Variant) then
4242 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4243 Report_Errors := True;
4247 -- If we have found the corresponding choice, recursively add its
4248 -- components to the Into list.
4250 Gather_Components (Empty,
4251 Component_List (Variant), Governed_By, Into, Report_Errors);
4252 end Gather_Components;
4254 ------------------------
4255 -- Get_Actual_Subtype --
4256 ------------------------
4258 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4259 Typ : constant Entity_Id := Etype (N);
4260 Utyp : Entity_Id := Underlying_Type (Typ);
4269 -- If what we have is an identifier that references a subprogram
4270 -- formal, or a variable or constant object, then we get the actual
4271 -- subtype from the referenced entity if one has been built.
4273 if Nkind (N) = N_Identifier
4275 (Is_Formal (Entity (N))
4276 or else Ekind (Entity (N)) = E_Constant
4277 or else Ekind (Entity (N)) = E_Variable)
4278 and then Present (Actual_Subtype (Entity (N)))
4280 return Actual_Subtype (Entity (N));
4282 -- Actual subtype of unchecked union is always itself. We never need
4283 -- the "real" actual subtype. If we did, we couldn't get it anyway
4284 -- because the discriminant is not available. The restrictions on
4285 -- Unchecked_Union are designed to make sure that this is OK.
4287 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4290 -- Here for the unconstrained case, we must find actual subtype
4291 -- No actual subtype is available, so we must build it on the fly.
4293 -- Checking the type, not the underlying type, for constrainedness
4294 -- seems to be necessary. Maybe all the tests should be on the type???
4296 elsif (not Is_Constrained (Typ))
4297 and then (Is_Array_Type (Utyp)
4298 or else (Is_Record_Type (Utyp)
4299 and then Has_Discriminants (Utyp)))
4300 and then not Has_Unknown_Discriminants (Utyp)
4301 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4303 -- Nothing to do if in spec expression (why not???)
4305 if In_Spec_Expression then
4308 elsif Is_Private_Type (Typ)
4309 and then not Has_Discriminants (Typ)
4311 -- If the type has no discriminants, there is no subtype to
4312 -- build, even if the underlying type is discriminated.
4316 -- Else build the actual subtype
4319 Decl := Build_Actual_Subtype (Typ, N);
4320 Atyp := Defining_Identifier (Decl);
4322 -- If Build_Actual_Subtype generated a new declaration then use it
4326 -- The actual subtype is an Itype, so analyze the declaration,
4327 -- but do not attach it to the tree, to get the type defined.
4329 Set_Parent (Decl, N);
4330 Set_Is_Itype (Atyp);
4331 Analyze (Decl, Suppress => All_Checks);
4332 Set_Associated_Node_For_Itype (Atyp, N);
4333 Set_Has_Delayed_Freeze (Atyp, False);
4335 -- We need to freeze the actual subtype immediately. This is
4336 -- needed, because otherwise this Itype will not get frozen
4337 -- at all, and it is always safe to freeze on creation because
4338 -- any associated types must be frozen at this point.
4340 Freeze_Itype (Atyp, N);
4343 -- Otherwise we did not build a declaration, so return original
4350 -- For all remaining cases, the actual subtype is the same as
4351 -- the nominal type.
4356 end Get_Actual_Subtype;
4358 -------------------------------------
4359 -- Get_Actual_Subtype_If_Available --
4360 -------------------------------------
4362 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4363 Typ : constant Entity_Id := Etype (N);
4366 -- If what we have is an identifier that references a subprogram
4367 -- formal, or a variable or constant object, then we get the actual
4368 -- subtype from the referenced entity if one has been built.
4370 if Nkind (N) = N_Identifier
4372 (Is_Formal (Entity (N))
4373 or else Ekind (Entity (N)) = E_Constant
4374 or else Ekind (Entity (N)) = E_Variable)
4375 and then Present (Actual_Subtype (Entity (N)))
4377 return Actual_Subtype (Entity (N));
4379 -- Otherwise the Etype of N is returned unchanged
4384 end Get_Actual_Subtype_If_Available;
4386 ------------------------
4387 -- Get_Body_From_Stub --
4388 ------------------------
4390 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
4392 return Proper_Body (Unit (Library_Unit (N)));
4393 end Get_Body_From_Stub;
4395 -------------------------------
4396 -- Get_Default_External_Name --
4397 -------------------------------
4399 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4401 Get_Decoded_Name_String (Chars (E));
4403 if Opt.External_Name_Imp_Casing = Uppercase then
4404 Set_Casing (All_Upper_Case);
4406 Set_Casing (All_Lower_Case);
4410 Make_String_Literal (Sloc (E),
4411 Strval => String_From_Name_Buffer);
4412 end Get_Default_External_Name;
4414 --------------------------
4415 -- Get_Enclosing_Object --
4416 --------------------------
4418 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
4420 if Is_Entity_Name (N) then
4424 when N_Indexed_Component |
4426 N_Selected_Component =>
4428 -- If not generating code, a dereference may be left implicit.
4429 -- In thoses cases, return Empty.
4431 if Is_Access_Type (Etype (Prefix (N))) then
4434 return Get_Enclosing_Object (Prefix (N));
4437 when N_Type_Conversion =>
4438 return Get_Enclosing_Object (Expression (N));
4444 end Get_Enclosing_Object;
4446 ---------------------------
4447 -- Get_Enum_Lit_From_Pos --
4448 ---------------------------
4450 function Get_Enum_Lit_From_Pos
4453 Loc : Source_Ptr) return Node_Id
4458 -- In the case where the literal is of type Character, Wide_Character
4459 -- or Wide_Wide_Character or of a type derived from them, there needs
4460 -- to be some special handling since there is no explicit chain of
4461 -- literals to search. Instead, an N_Character_Literal node is created
4462 -- with the appropriate Char_Code and Chars fields.
4464 if Is_Standard_Character_Type (T) then
4465 Set_Character_Literal_Name (UI_To_CC (Pos));
4467 Make_Character_Literal (Loc,
4469 Char_Literal_Value => Pos);
4471 -- For all other cases, we have a complete table of literals, and
4472 -- we simply iterate through the chain of literal until the one
4473 -- with the desired position value is found.
4477 Lit := First_Literal (Base_Type (T));
4478 for J in 1 .. UI_To_Int (Pos) loop
4482 return New_Occurrence_Of (Lit, Loc);
4484 end Get_Enum_Lit_From_Pos;
4486 ---------------------------------------
4487 -- Get_Ensures_From_Test_Case_Pragma --
4488 ---------------------------------------
4490 function Get_Ensures_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4491 Args : constant List_Id := Pragma_Argument_Associations (N);
4495 if List_Length (Args) = 4 then
4496 Res := Pick (Args, 4);
4498 elsif List_Length (Args) = 3 then
4499 Res := Pick (Args, 3);
4501 if Chars (Res) /= Name_Ensures then
4510 end Get_Ensures_From_Test_Case_Pragma;
4512 ------------------------
4513 -- Get_Generic_Entity --
4514 ------------------------
4516 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4517 Ent : constant Entity_Id := Entity (Name (N));
4519 if Present (Renamed_Object (Ent)) then
4520 return Renamed_Object (Ent);
4524 end Get_Generic_Entity;
4526 ----------------------
4527 -- Get_Index_Bounds --
4528 ----------------------
4530 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4531 Kind : constant Node_Kind := Nkind (N);
4535 if Kind = N_Range then
4537 H := High_Bound (N);
4539 elsif Kind = N_Subtype_Indication then
4540 R := Range_Expression (Constraint (N));
4548 L := Low_Bound (Range_Expression (Constraint (N)));
4549 H := High_Bound (Range_Expression (Constraint (N)));
4552 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4553 if Error_Posted (Scalar_Range (Entity (N))) then
4557 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4558 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4561 L := Low_Bound (Scalar_Range (Entity (N)));
4562 H := High_Bound (Scalar_Range (Entity (N)));
4566 -- N is an expression, indicating a range with one value
4571 end Get_Index_Bounds;
4573 ----------------------------------
4574 -- Get_Library_Unit_Name_string --
4575 ----------------------------------
4577 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4578 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4581 Get_Unit_Name_String (Unit_Name_Id);
4583 -- Remove seven last character (" (spec)" or " (body)")
4585 Name_Len := Name_Len - 7;
4586 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4587 end Get_Library_Unit_Name_String;
4589 ------------------------
4590 -- Get_Name_Entity_Id --
4591 ------------------------
4593 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4595 return Entity_Id (Get_Name_Table_Info (Id));
4596 end Get_Name_Entity_Id;
4598 ------------------------------------
4599 -- Get_Name_From_Test_Case_Pragma --
4600 ------------------------------------
4602 function Get_Name_From_Test_Case_Pragma (N : Node_Id) return String_Id is
4603 Arg : constant Node_Id :=
4604 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
4606 return Strval (Expr_Value_S (Arg));
4607 end Get_Name_From_Test_Case_Pragma;
4613 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4615 return Get_Pragma_Id (Pragma_Name (N));
4618 ---------------------------
4619 -- Get_Referenced_Object --
4620 ---------------------------
4622 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4627 while Is_Entity_Name (R)
4628 and then Present (Renamed_Object (Entity (R)))
4630 R := Renamed_Object (Entity (R));
4634 end Get_Referenced_Object;
4636 ------------------------
4637 -- Get_Renamed_Entity --
4638 ------------------------
4640 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4645 while Present (Renamed_Entity (R)) loop
4646 R := Renamed_Entity (R);
4650 end Get_Renamed_Entity;
4652 ----------------------------------------
4653 -- Get_Requires_From_Test_Case_Pragma --
4654 ----------------------------------------
4656 function Get_Requires_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4657 Args : constant List_Id := Pragma_Argument_Associations (N);
4661 if List_Length (Args) >= 3 then
4662 Res := Pick (Args, 3);
4664 if Chars (Res) /= Name_Requires then
4673 end Get_Requires_From_Test_Case_Pragma;
4675 -------------------------
4676 -- Get_Subprogram_Body --
4677 -------------------------
4679 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4683 Decl := Unit_Declaration_Node (E);
4685 if Nkind (Decl) = N_Subprogram_Body then
4688 -- The below comment is bad, because it is possible for
4689 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4691 else -- Nkind (Decl) = N_Subprogram_Declaration
4693 if Present (Corresponding_Body (Decl)) then
4694 return Unit_Declaration_Node (Corresponding_Body (Decl));
4696 -- Imported subprogram case
4702 end Get_Subprogram_Body;
4704 ---------------------------
4705 -- Get_Subprogram_Entity --
4706 ---------------------------
4708 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4713 if Nkind (Nod) = N_Accept_Statement then
4714 Nam := Entry_Direct_Name (Nod);
4716 -- For an entry call, the prefix of the call is a selected component.
4717 -- Need additional code for internal calls ???
4719 elsif Nkind (Nod) = N_Entry_Call_Statement then
4720 if Nkind (Name (Nod)) = N_Selected_Component then
4721 Nam := Entity (Selector_Name (Name (Nod)));
4730 if Nkind (Nam) = N_Explicit_Dereference then
4731 Proc := Etype (Prefix (Nam));
4732 elsif Is_Entity_Name (Nam) then
4733 Proc := Entity (Nam);
4738 if Is_Object (Proc) then
4739 Proc := Etype (Proc);
4742 if Ekind (Proc) = E_Access_Subprogram_Type then
4743 Proc := Directly_Designated_Type (Proc);
4746 if not Is_Subprogram (Proc)
4747 and then Ekind (Proc) /= E_Subprogram_Type
4753 end Get_Subprogram_Entity;
4755 -----------------------------
4756 -- Get_Task_Body_Procedure --
4757 -----------------------------
4759 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4761 -- Note: A task type may be the completion of a private type with
4762 -- discriminants. When performing elaboration checks on a task
4763 -- declaration, the current view of the type may be the private one,
4764 -- and the procedure that holds the body of the task is held in its
4767 -- This is an odd function, why not have Task_Body_Procedure do
4768 -- the following digging???
4770 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4771 end Get_Task_Body_Procedure;
4773 -----------------------
4774 -- Has_Access_Values --
4775 -----------------------
4777 function Has_Access_Values (T : Entity_Id) return Boolean is
4778 Typ : constant Entity_Id := Underlying_Type (T);
4781 -- Case of a private type which is not completed yet. This can only
4782 -- happen in the case of a generic format type appearing directly, or
4783 -- as a component of the type to which this function is being applied
4784 -- at the top level. Return False in this case, since we certainly do
4785 -- not know that the type contains access types.
4790 elsif Is_Access_Type (Typ) then
4793 elsif Is_Array_Type (Typ) then
4794 return Has_Access_Values (Component_Type (Typ));
4796 elsif Is_Record_Type (Typ) then
4801 -- Loop to Check components
4803 Comp := First_Component_Or_Discriminant (Typ);
4804 while Present (Comp) loop
4806 -- Check for access component, tag field does not count, even
4807 -- though it is implemented internally using an access type.
4809 if Has_Access_Values (Etype (Comp))
4810 and then Chars (Comp) /= Name_uTag
4815 Next_Component_Or_Discriminant (Comp);
4824 end Has_Access_Values;
4826 ------------------------------
4827 -- Has_Compatible_Alignment --
4828 ------------------------------
4830 function Has_Compatible_Alignment
4832 Expr : Node_Id) return Alignment_Result
4834 function Has_Compatible_Alignment_Internal
4837 Default : Alignment_Result) return Alignment_Result;
4838 -- This is the internal recursive function that actually does the work.
4839 -- There is one additional parameter, which says what the result should
4840 -- be if no alignment information is found, and there is no definite
4841 -- indication of compatible alignments. At the outer level, this is set
4842 -- to Unknown, but for internal recursive calls in the case where types
4843 -- are known to be correct, it is set to Known_Compatible.
4845 ---------------------------------------
4846 -- Has_Compatible_Alignment_Internal --
4847 ---------------------------------------
4849 function Has_Compatible_Alignment_Internal
4852 Default : Alignment_Result) return Alignment_Result
4854 Result : Alignment_Result := Known_Compatible;
4855 -- Holds the current status of the result. Note that once a value of
4856 -- Known_Incompatible is set, it is sticky and does not get changed
4857 -- to Unknown (the value in Result only gets worse as we go along,
4860 Offs : Uint := No_Uint;
4861 -- Set to a factor of the offset from the base object when Expr is a
4862 -- selected or indexed component, based on Component_Bit_Offset and
4863 -- Component_Size respectively. A negative value is used to represent
4864 -- a value which is not known at compile time.
4866 procedure Check_Prefix;
4867 -- Checks the prefix recursively in the case where the expression
4868 -- is an indexed or selected component.
4870 procedure Set_Result (R : Alignment_Result);
4871 -- If R represents a worse outcome (unknown instead of known
4872 -- compatible, or known incompatible), then set Result to R.
4878 procedure Check_Prefix is
4880 -- The subtlety here is that in doing a recursive call to check
4881 -- the prefix, we have to decide what to do in the case where we
4882 -- don't find any specific indication of an alignment problem.
4884 -- At the outer level, we normally set Unknown as the result in
4885 -- this case, since we can only set Known_Compatible if we really
4886 -- know that the alignment value is OK, but for the recursive
4887 -- call, in the case where the types match, and we have not
4888 -- specified a peculiar alignment for the object, we are only
4889 -- concerned about suspicious rep clauses, the default case does
4890 -- not affect us, since the compiler will, in the absence of such
4891 -- rep clauses, ensure that the alignment is correct.
4893 if Default = Known_Compatible
4895 (Etype (Obj) = Etype (Expr)
4896 and then (Unknown_Alignment (Obj)
4898 Alignment (Obj) = Alignment (Etype (Obj))))
4901 (Has_Compatible_Alignment_Internal
4902 (Obj, Prefix (Expr), Known_Compatible));
4904 -- In all other cases, we need a full check on the prefix
4908 (Has_Compatible_Alignment_Internal
4909 (Obj, Prefix (Expr), Unknown));
4917 procedure Set_Result (R : Alignment_Result) is
4924 -- Start of processing for Has_Compatible_Alignment_Internal
4927 -- If Expr is a selected component, we must make sure there is no
4928 -- potentially troublesome component clause, and that the record is
4931 if Nkind (Expr) = N_Selected_Component then
4933 -- Packed record always generate unknown alignment
4935 if Is_Packed (Etype (Prefix (Expr))) then
4936 Set_Result (Unknown);
4939 -- Check prefix and component offset
4942 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4944 -- If Expr is an indexed component, we must make sure there is no
4945 -- potentially troublesome Component_Size clause and that the array
4946 -- is not bit-packed.
4948 elsif Nkind (Expr) = N_Indexed_Component then
4950 Typ : constant Entity_Id := Etype (Prefix (Expr));
4951 Ind : constant Node_Id := First_Index (Typ);
4954 -- Bit packed array always generates unknown alignment
4956 if Is_Bit_Packed_Array (Typ) then
4957 Set_Result (Unknown);
4960 -- Check prefix and component offset
4963 Offs := Component_Size (Typ);
4965 -- Small optimization: compute the full offset when possible
4968 and then Offs > Uint_0
4969 and then Present (Ind)
4970 and then Nkind (Ind) = N_Range
4971 and then Compile_Time_Known_Value (Low_Bound (Ind))
4972 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4974 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4975 - Expr_Value (Low_Bound ((Ind))));
4980 -- If we have a null offset, the result is entirely determined by
4981 -- the base object and has already been computed recursively.
4983 if Offs = Uint_0 then
4986 -- Case where we know the alignment of the object
4988 elsif Known_Alignment (Obj) then
4990 ObjA : constant Uint := Alignment (Obj);
4991 ExpA : Uint := No_Uint;
4992 SizA : Uint := No_Uint;
4995 -- If alignment of Obj is 1, then we are always OK
4998 Set_Result (Known_Compatible);
5000 -- Alignment of Obj is greater than 1, so we need to check
5003 -- If we have an offset, see if it is compatible
5005 if Offs /= No_Uint and Offs > Uint_0 then
5006 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
5007 Set_Result (Known_Incompatible);
5010 -- See if Expr is an object with known alignment
5012 elsif Is_Entity_Name (Expr)
5013 and then Known_Alignment (Entity (Expr))
5015 ExpA := Alignment (Entity (Expr));
5017 -- Otherwise, we can use the alignment of the type of
5018 -- Expr given that we already checked for
5019 -- discombobulating rep clauses for the cases of indexed
5020 -- and selected components above.
5022 elsif Known_Alignment (Etype (Expr)) then
5023 ExpA := Alignment (Etype (Expr));
5025 -- Otherwise the alignment is unknown
5028 Set_Result (Default);
5031 -- If we got an alignment, see if it is acceptable
5033 if ExpA /= No_Uint and then ExpA < ObjA then
5034 Set_Result (Known_Incompatible);
5037 -- If Expr is not a piece of a larger object, see if size
5038 -- is given. If so, check that it is not too small for the
5039 -- required alignment.
5041 if Offs /= No_Uint then
5044 -- See if Expr is an object with known size
5046 elsif Is_Entity_Name (Expr)
5047 and then Known_Static_Esize (Entity (Expr))
5049 SizA := Esize (Entity (Expr));
5051 -- Otherwise, we check the object size of the Expr type
5053 elsif Known_Static_Esize (Etype (Expr)) then
5054 SizA := Esize (Etype (Expr));
5057 -- If we got a size, see if it is a multiple of the Obj
5058 -- alignment, if not, then the alignment cannot be
5059 -- acceptable, since the size is always a multiple of the
5062 if SizA /= No_Uint then
5063 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
5064 Set_Result (Known_Incompatible);
5070 -- If we do not know required alignment, any non-zero offset is a
5071 -- potential problem (but certainly may be OK, so result is unknown).
5073 elsif Offs /= No_Uint then
5074 Set_Result (Unknown);
5076 -- If we can't find the result by direct comparison of alignment
5077 -- values, then there is still one case that we can determine known
5078 -- result, and that is when we can determine that the types are the
5079 -- same, and no alignments are specified. Then we known that the
5080 -- alignments are compatible, even if we don't know the alignment
5081 -- value in the front end.
5083 elsif Etype (Obj) = Etype (Expr) then
5085 -- Types are the same, but we have to check for possible size
5086 -- and alignments on the Expr object that may make the alignment
5087 -- different, even though the types are the same.
5089 if Is_Entity_Name (Expr) then
5091 -- First check alignment of the Expr object. Any alignment less
5092 -- than Maximum_Alignment is worrisome since this is the case
5093 -- where we do not know the alignment of Obj.
5095 if Known_Alignment (Entity (Expr))
5097 UI_To_Int (Alignment (Entity (Expr))) <
5098 Ttypes.Maximum_Alignment
5100 Set_Result (Unknown);
5102 -- Now check size of Expr object. Any size that is not an
5103 -- even multiple of Maximum_Alignment is also worrisome
5104 -- since it may cause the alignment of the object to be less
5105 -- than the alignment of the type.
5107 elsif Known_Static_Esize (Entity (Expr))
5109 (UI_To_Int (Esize (Entity (Expr))) mod
5110 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
5113 Set_Result (Unknown);
5115 -- Otherwise same type is decisive
5118 Set_Result (Known_Compatible);
5122 -- Another case to deal with is when there is an explicit size or
5123 -- alignment clause when the types are not the same. If so, then the
5124 -- result is Unknown. We don't need to do this test if the Default is
5125 -- Unknown, since that result will be set in any case.
5127 elsif Default /= Unknown
5128 and then (Has_Size_Clause (Etype (Expr))
5130 Has_Alignment_Clause (Etype (Expr)))
5132 Set_Result (Unknown);
5134 -- If no indication found, set default
5137 Set_Result (Default);
5140 -- Return worst result found
5143 end Has_Compatible_Alignment_Internal;
5145 -- Start of processing for Has_Compatible_Alignment
5148 -- If Obj has no specified alignment, then set alignment from the type
5149 -- alignment. Perhaps we should always do this, but for sure we should
5150 -- do it when there is an address clause since we can do more if the
5151 -- alignment is known.
5153 if Unknown_Alignment (Obj) then
5154 Set_Alignment (Obj, Alignment (Etype (Obj)));
5157 -- Now do the internal call that does all the work
5159 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
5160 end Has_Compatible_Alignment;
5162 ----------------------
5163 -- Has_Declarations --
5164 ----------------------
5166 function Has_Declarations (N : Node_Id) return Boolean is
5168 return Nkind_In (Nkind (N), N_Accept_Statement,
5170 N_Compilation_Unit_Aux,
5176 N_Package_Specification);
5177 end Has_Declarations;
5179 -------------------------------------------
5180 -- Has_Discriminant_Dependent_Constraint --
5181 -------------------------------------------
5183 function Has_Discriminant_Dependent_Constraint
5184 (Comp : Entity_Id) return Boolean
5186 Comp_Decl : constant Node_Id := Parent (Comp);
5187 Subt_Indic : constant Node_Id :=
5188 Subtype_Indication (Component_Definition (Comp_Decl));
5193 if Nkind (Subt_Indic) = N_Subtype_Indication then
5194 Constr := Constraint (Subt_Indic);
5196 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
5197 Assn := First (Constraints (Constr));
5198 while Present (Assn) loop
5199 case Nkind (Assn) is
5200 when N_Subtype_Indication |
5204 if Depends_On_Discriminant (Assn) then
5208 when N_Discriminant_Association =>
5209 if Depends_On_Discriminant (Expression (Assn)) then
5224 end Has_Discriminant_Dependent_Constraint;
5226 --------------------
5227 -- Has_Infinities --
5228 --------------------
5230 function Has_Infinities (E : Entity_Id) return Boolean is
5233 Is_Floating_Point_Type (E)
5234 and then Nkind (Scalar_Range (E)) = N_Range
5235 and then Includes_Infinities (Scalar_Range (E));
5238 --------------------
5239 -- Has_Interfaces --
5240 --------------------
5242 function Has_Interfaces
5244 Use_Full_View : Boolean := True) return Boolean
5246 Typ : Entity_Id := Base_Type (T);
5249 -- Handle concurrent types
5251 if Is_Concurrent_Type (Typ) then
5252 Typ := Corresponding_Record_Type (Typ);
5255 if not Present (Typ)
5256 or else not Is_Record_Type (Typ)
5257 or else not Is_Tagged_Type (Typ)
5262 -- Handle private types
5265 and then Present (Full_View (Typ))
5267 Typ := Full_View (Typ);
5270 -- Handle concurrent record types
5272 if Is_Concurrent_Record_Type (Typ)
5273 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
5279 if Is_Interface (Typ)
5281 (Is_Record_Type (Typ)
5282 and then Present (Interfaces (Typ))
5283 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
5288 exit when Etype (Typ) = Typ
5290 -- Handle private types
5292 or else (Present (Full_View (Etype (Typ)))
5293 and then Full_View (Etype (Typ)) = Typ)
5295 -- Protect the frontend against wrong source with cyclic
5298 or else Etype (Typ) = T;
5300 -- Climb to the ancestor type handling private types
5302 if Present (Full_View (Etype (Typ))) then
5303 Typ := Full_View (Etype (Typ));
5312 ------------------------
5313 -- Has_Null_Exclusion --
5314 ------------------------
5316 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5319 when N_Access_Definition |
5320 N_Access_Function_Definition |
5321 N_Access_Procedure_Definition |
5322 N_Access_To_Object_Definition |
5324 N_Derived_Type_Definition |
5325 N_Function_Specification |
5326 N_Subtype_Declaration =>
5327 return Null_Exclusion_Present (N);
5329 when N_Component_Definition |
5330 N_Formal_Object_Declaration |
5331 N_Object_Renaming_Declaration =>
5332 if Present (Subtype_Mark (N)) then
5333 return Null_Exclusion_Present (N);
5334 else pragma Assert (Present (Access_Definition (N)));
5335 return Null_Exclusion_Present (Access_Definition (N));
5338 when N_Discriminant_Specification =>
5339 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5340 return Null_Exclusion_Present (Discriminant_Type (N));
5342 return Null_Exclusion_Present (N);
5345 when N_Object_Declaration =>
5346 if Nkind (Object_Definition (N)) = N_Access_Definition then
5347 return Null_Exclusion_Present (Object_Definition (N));
5349 return Null_Exclusion_Present (N);
5352 when N_Parameter_Specification =>
5353 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5354 return Null_Exclusion_Present (Parameter_Type (N));
5356 return Null_Exclusion_Present (N);
5363 end Has_Null_Exclusion;
5365 ------------------------
5366 -- Has_Null_Extension --
5367 ------------------------
5369 function Has_Null_Extension (T : Entity_Id) return Boolean is
5370 B : constant Entity_Id := Base_Type (T);
5375 if Nkind (Parent (B)) = N_Full_Type_Declaration
5376 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5378 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5380 if Present (Ext) then
5381 if Null_Present (Ext) then
5384 Comps := Component_List (Ext);
5386 -- The null component list is rewritten during analysis to
5387 -- include the parent component. Any other component indicates
5388 -- that the extension was not originally null.
5390 return Null_Present (Comps)
5391 or else No (Next (First (Component_Items (Comps))));
5400 end Has_Null_Extension;
5402 -------------------------------
5403 -- Has_Overriding_Initialize --
5404 -------------------------------
5406 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5407 BT : constant Entity_Id := Base_Type (T);
5411 if Is_Controlled (BT) then
5412 if Is_RTU (Scope (BT), Ada_Finalization) then
5415 elsif Present (Primitive_Operations (BT)) then
5416 P := First_Elmt (Primitive_Operations (BT));
5417 while Present (P) loop
5419 Init : constant Entity_Id := Node (P);
5420 Formal : constant Entity_Id := First_Formal (Init);
5422 if Ekind (Init) = E_Procedure
5423 and then Chars (Init) = Name_Initialize
5424 and then Comes_From_Source (Init)
5425 and then Present (Formal)
5426 and then Etype (Formal) = BT
5427 and then No (Next_Formal (Formal))
5428 and then (Ada_Version < Ada_2012
5429 or else not Null_Present (Parent (Init)))
5439 -- Here if type itself does not have a non-null Initialize operation:
5440 -- check immediate ancestor.
5442 if Is_Derived_Type (BT)
5443 and then Has_Overriding_Initialize (Etype (BT))
5450 end Has_Overriding_Initialize;
5452 --------------------------------------
5453 -- Has_Preelaborable_Initialization --
5454 --------------------------------------
5456 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5459 procedure Check_Components (E : Entity_Id);
5460 -- Check component/discriminant chain, sets Has_PE False if a component
5461 -- or discriminant does not meet the preelaborable initialization rules.
5463 ----------------------
5464 -- Check_Components --
5465 ----------------------
5467 procedure Check_Components (E : Entity_Id) is
5471 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5472 -- Returns True if and only if the expression denoted by N does not
5473 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5475 ---------------------------------
5476 -- Is_Preelaborable_Expression --
5477 ---------------------------------
5479 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5483 Comp_Type : Entity_Id;
5484 Is_Array_Aggr : Boolean;
5487 if Is_Static_Expression (N) then
5490 elsif Nkind (N) = N_Null then
5493 -- Attributes are allowed in general, even if their prefix is a
5494 -- formal type. (It seems that certain attributes known not to be
5495 -- static might not be allowed, but there are no rules to prevent
5498 elsif Nkind (N) = N_Attribute_Reference then
5501 -- The name of a discriminant evaluated within its parent type is
5502 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5503 -- names that denote discriminals as well as discriminants to
5504 -- catch references occurring within init procs.
5506 elsif Is_Entity_Name (N)
5508 (Ekind (Entity (N)) = E_Discriminant
5510 ((Ekind (Entity (N)) = E_Constant
5511 or else Ekind (Entity (N)) = E_In_Parameter)
5512 and then Present (Discriminal_Link (Entity (N)))))
5516 elsif Nkind (N) = N_Qualified_Expression then
5517 return Is_Preelaborable_Expression (Expression (N));
5519 -- For aggregates we have to check that each of the associations
5520 -- is preelaborable.
5522 elsif Nkind (N) = N_Aggregate
5523 or else Nkind (N) = N_Extension_Aggregate
5525 Is_Array_Aggr := Is_Array_Type (Etype (N));
5527 if Is_Array_Aggr then
5528 Comp_Type := Component_Type (Etype (N));
5531 -- Check the ancestor part of extension aggregates, which must
5532 -- be either the name of a type that has preelaborable init or
5533 -- an expression that is preelaborable.
5535 if Nkind (N) = N_Extension_Aggregate then
5537 Anc_Part : constant Node_Id := Ancestor_Part (N);
5540 if Is_Entity_Name (Anc_Part)
5541 and then Is_Type (Entity (Anc_Part))
5543 if not Has_Preelaborable_Initialization
5549 elsif not Is_Preelaborable_Expression (Anc_Part) then
5555 -- Check positional associations
5557 Exp := First (Expressions (N));
5558 while Present (Exp) loop
5559 if not Is_Preelaborable_Expression (Exp) then
5566 -- Check named associations
5568 Assn := First (Component_Associations (N));
5569 while Present (Assn) loop
5570 Choice := First (Choices (Assn));
5571 while Present (Choice) loop
5572 if Is_Array_Aggr then
5573 if Nkind (Choice) = N_Others_Choice then
5576 elsif Nkind (Choice) = N_Range then
5577 if not Is_Static_Range (Choice) then
5581 elsif not Is_Static_Expression (Choice) then
5586 Comp_Type := Etype (Choice);
5592 -- If the association has a <> at this point, then we have
5593 -- to check whether the component's type has preelaborable
5594 -- initialization. Note that this only occurs when the
5595 -- association's corresponding component does not have a
5596 -- default expression, the latter case having already been
5597 -- expanded as an expression for the association.
5599 if Box_Present (Assn) then
5600 if not Has_Preelaborable_Initialization (Comp_Type) then
5604 -- In the expression case we check whether the expression
5605 -- is preelaborable.
5608 not Is_Preelaborable_Expression (Expression (Assn))
5616 -- If we get here then aggregate as a whole is preelaborable
5620 -- All other cases are not preelaborable
5625 end Is_Preelaborable_Expression;
5627 -- Start of processing for Check_Components
5630 -- Loop through entities of record or protected type
5633 while Present (Ent) loop
5635 -- We are interested only in components and discriminants
5642 -- Get default expression if any. If there is no declaration
5643 -- node, it means we have an internal entity. The parent and
5644 -- tag fields are examples of such entities. For such cases,
5645 -- we just test the type of the entity.
5647 if Present (Declaration_Node (Ent)) then
5648 Exp := Expression (Declaration_Node (Ent));
5651 when E_Discriminant =>
5653 -- Note: for a renamed discriminant, the Declaration_Node
5654 -- may point to the one from the ancestor, and have a
5655 -- different expression, so use the proper attribute to
5656 -- retrieve the expression from the derived constraint.
5658 Exp := Discriminant_Default_Value (Ent);
5661 goto Check_Next_Entity;
5664 -- A component has PI if it has no default expression and the
5665 -- component type has PI.
5668 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5673 -- Require the default expression to be preelaborable
5675 elsif not Is_Preelaborable_Expression (Exp) then
5680 <<Check_Next_Entity>>
5683 end Check_Components;
5685 -- Start of processing for Has_Preelaborable_Initialization
5688 -- Immediate return if already marked as known preelaborable init. This
5689 -- covers types for which this function has already been called once
5690 -- and returned True (in which case the result is cached), and also
5691 -- types to which a pragma Preelaborable_Initialization applies.
5693 if Known_To_Have_Preelab_Init (E) then
5697 -- If the type is a subtype representing a generic actual type, then
5698 -- test whether its base type has preelaborable initialization since
5699 -- the subtype representing the actual does not inherit this attribute
5700 -- from the actual or formal. (but maybe it should???)
5702 if Is_Generic_Actual_Type (E) then
5703 return Has_Preelaborable_Initialization (Base_Type (E));
5706 -- All elementary types have preelaborable initialization
5708 if Is_Elementary_Type (E) then
5711 -- Array types have PI if the component type has PI
5713 elsif Is_Array_Type (E) then
5714 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5716 -- A derived type has preelaborable initialization if its parent type
5717 -- has preelaborable initialization and (in the case of a derived record
5718 -- extension) if the non-inherited components all have preelaborable
5719 -- initialization. However, a user-defined controlled type with an
5720 -- overriding Initialize procedure does not have preelaborable
5723 elsif Is_Derived_Type (E) then
5725 -- If the derived type is a private extension then it doesn't have
5726 -- preelaborable initialization.
5728 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5732 -- First check whether ancestor type has preelaborable initialization
5734 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5736 -- If OK, check extension components (if any)
5738 if Has_PE and then Is_Record_Type (E) then
5739 Check_Components (First_Entity (E));
5742 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5743 -- with a user defined Initialize procedure does not have PI.
5746 and then Is_Controlled (E)
5747 and then Has_Overriding_Initialize (E)
5752 -- Private types not derived from a type having preelaborable init and
5753 -- that are not marked with pragma Preelaborable_Initialization do not
5754 -- have preelaborable initialization.
5756 elsif Is_Private_Type (E) then
5759 -- Record type has PI if it is non private and all components have PI
5761 elsif Is_Record_Type (E) then
5763 Check_Components (First_Entity (E));
5765 -- Protected types must not have entries, and components must meet
5766 -- same set of rules as for record components.
5768 elsif Is_Protected_Type (E) then
5769 if Has_Entries (E) then
5773 Check_Components (First_Entity (E));
5774 Check_Components (First_Private_Entity (E));
5777 -- Type System.Address always has preelaborable initialization
5779 elsif Is_RTE (E, RE_Address) then
5782 -- In all other cases, type does not have preelaborable initialization
5788 -- If type has preelaborable initialization, cache result
5791 Set_Known_To_Have_Preelab_Init (E);
5795 end Has_Preelaborable_Initialization;
5797 ---------------------------
5798 -- Has_Private_Component --
5799 ---------------------------
5801 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5802 Btype : Entity_Id := Base_Type (Type_Id);
5803 Component : Entity_Id;
5806 if Error_Posted (Type_Id)
5807 or else Error_Posted (Btype)
5812 if Is_Class_Wide_Type (Btype) then
5813 Btype := Root_Type (Btype);
5816 if Is_Private_Type (Btype) then
5818 UT : constant Entity_Id := Underlying_Type (Btype);
5821 if No (Full_View (Btype)) then
5822 return not Is_Generic_Type (Btype)
5823 and then not Is_Generic_Type (Root_Type (Btype));
5825 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5828 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5832 elsif Is_Array_Type (Btype) then
5833 return Has_Private_Component (Component_Type (Btype));
5835 elsif Is_Record_Type (Btype) then
5836 Component := First_Component (Btype);
5837 while Present (Component) loop
5838 if Has_Private_Component (Etype (Component)) then
5842 Next_Component (Component);
5847 elsif Is_Protected_Type (Btype)
5848 and then Present (Corresponding_Record_Type (Btype))
5850 return Has_Private_Component (Corresponding_Record_Type (Btype));
5855 end Has_Private_Component;
5857 -----------------------------
5858 -- Has_Static_Array_Bounds --
5859 -----------------------------
5861 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5862 Ndims : constant Nat := Number_Dimensions (Typ);
5869 -- Unconstrained types do not have static bounds
5871 if not Is_Constrained (Typ) then
5875 -- First treat string literals specially, as the lower bound and length
5876 -- of string literals are not stored like those of arrays.
5878 -- A string literal always has static bounds
5880 if Ekind (Typ) = E_String_Literal_Subtype then
5884 -- Treat all dimensions in turn
5886 Index := First_Index (Typ);
5887 for Indx in 1 .. Ndims loop
5889 -- In case of an erroneous index which is not a discrete type, return
5890 -- that the type is not static.
5892 if not Is_Discrete_Type (Etype (Index))
5893 or else Etype (Index) = Any_Type
5898 Get_Index_Bounds (Index, Low, High);
5900 if Error_Posted (Low) or else Error_Posted (High) then
5904 if Is_OK_Static_Expression (Low)
5906 Is_OK_Static_Expression (High)
5916 -- If we fall through the loop, all indexes matched
5919 end Has_Static_Array_Bounds;
5925 function Has_Stream (T : Entity_Id) return Boolean is
5932 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5935 elsif Is_Array_Type (T) then
5936 return Has_Stream (Component_Type (T));
5938 elsif Is_Record_Type (T) then
5939 E := First_Component (T);
5940 while Present (E) loop
5941 if Has_Stream (Etype (E)) then
5950 elsif Is_Private_Type (T) then
5951 return Has_Stream (Underlying_Type (T));
5962 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5964 Get_Name_String (Chars (E));
5965 return Name_Buffer (Name_Len) = Suffix;
5972 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
5974 Get_Name_String (Chars (E));
5975 Add_Char_To_Name_Buffer (Suffix);
5983 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
5985 pragma Assert (Has_Suffix (E, Suffix));
5986 Get_Name_String (Chars (E));
5987 Name_Len := Name_Len - 1;
5991 --------------------------
5992 -- Has_Tagged_Component --
5993 --------------------------
5995 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5999 if Is_Private_Type (Typ)
6000 and then Present (Underlying_Type (Typ))
6002 return Has_Tagged_Component (Underlying_Type (Typ));
6004 elsif Is_Array_Type (Typ) then
6005 return Has_Tagged_Component (Component_Type (Typ));
6007 elsif Is_Tagged_Type (Typ) then
6010 elsif Is_Record_Type (Typ) then
6011 Comp := First_Component (Typ);
6012 while Present (Comp) loop
6013 if Has_Tagged_Component (Etype (Comp)) then
6017 Next_Component (Comp);
6025 end Has_Tagged_Component;
6027 -------------------------
6028 -- Implementation_Kind --
6029 -------------------------
6031 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
6032 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
6034 pragma Assert (Present (Impl_Prag));
6036 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
6037 end Implementation_Kind;
6039 --------------------------
6040 -- Implements_Interface --
6041 --------------------------
6043 function Implements_Interface
6044 (Typ_Ent : Entity_Id;
6045 Iface_Ent : Entity_Id;
6046 Exclude_Parents : Boolean := False) return Boolean
6048 Ifaces_List : Elist_Id;
6050 Iface : Entity_Id := Base_Type (Iface_Ent);
6051 Typ : Entity_Id := Base_Type (Typ_Ent);
6054 if Is_Class_Wide_Type (Typ) then
6055 Typ := Root_Type (Typ);
6058 if not Has_Interfaces (Typ) then
6062 if Is_Class_Wide_Type (Iface) then
6063 Iface := Root_Type (Iface);
6066 Collect_Interfaces (Typ, Ifaces_List);
6068 Elmt := First_Elmt (Ifaces_List);
6069 while Present (Elmt) loop
6070 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
6071 and then Exclude_Parents
6075 elsif Node (Elmt) = Iface then
6083 end Implements_Interface;
6089 function In_Instance return Boolean is
6090 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6096 and then S /= Standard_Standard
6098 if (Ekind (S) = E_Function
6099 or else Ekind (S) = E_Package
6100 or else Ekind (S) = E_Procedure)
6101 and then Is_Generic_Instance (S)
6103 -- A child instance is always compiled in the context of a parent
6104 -- instance. Nevertheless, the actuals are not analyzed in an
6105 -- instance context. We detect this case by examining the current
6106 -- compilation unit, which must be a child instance, and checking
6107 -- that it is not currently on the scope stack.
6109 if Is_Child_Unit (Curr_Unit)
6111 Nkind (Unit (Cunit (Current_Sem_Unit)))
6112 = N_Package_Instantiation
6113 and then not In_Open_Scopes (Curr_Unit)
6127 ----------------------
6128 -- In_Instance_Body --
6129 ----------------------
6131 function In_Instance_Body return Boolean is
6137 and then S /= Standard_Standard
6139 if (Ekind (S) = E_Function
6140 or else Ekind (S) = E_Procedure)
6141 and then Is_Generic_Instance (S)
6145 elsif Ekind (S) = E_Package
6146 and then In_Package_Body (S)
6147 and then Is_Generic_Instance (S)
6156 end In_Instance_Body;
6158 -----------------------------
6159 -- In_Instance_Not_Visible --
6160 -----------------------------
6162 function In_Instance_Not_Visible return Boolean is
6168 and then S /= Standard_Standard
6170 if (Ekind (S) = E_Function
6171 or else Ekind (S) = E_Procedure)
6172 and then Is_Generic_Instance (S)
6176 elsif Ekind (S) = E_Package
6177 and then (In_Package_Body (S) or else In_Private_Part (S))
6178 and then Is_Generic_Instance (S)
6187 end In_Instance_Not_Visible;
6189 ------------------------------
6190 -- In_Instance_Visible_Part --
6191 ------------------------------
6193 function In_Instance_Visible_Part return Boolean is
6199 and then S /= Standard_Standard
6201 if Ekind (S) = E_Package
6202 and then Is_Generic_Instance (S)
6203 and then not In_Package_Body (S)
6204 and then not In_Private_Part (S)
6213 end In_Instance_Visible_Part;
6215 ---------------------
6216 -- In_Package_Body --
6217 ---------------------
6219 function In_Package_Body return Boolean is
6225 and then S /= Standard_Standard
6227 if Ekind (S) = E_Package
6228 and then In_Package_Body (S)
6237 end In_Package_Body;
6239 --------------------------------
6240 -- In_Parameter_Specification --
6241 --------------------------------
6243 function In_Parameter_Specification (N : Node_Id) return Boolean is
6248 while Present (PN) loop
6249 if Nkind (PN) = N_Parameter_Specification then
6257 end In_Parameter_Specification;
6259 --------------------------------------
6260 -- In_Subprogram_Or_Concurrent_Unit --
6261 --------------------------------------
6263 function In_Subprogram_Or_Concurrent_Unit return Boolean is
6268 -- Use scope chain to check successively outer scopes
6274 if K in Subprogram_Kind
6275 or else K in Concurrent_Kind
6276 or else K in Generic_Subprogram_Kind
6280 elsif E = Standard_Standard then
6286 end In_Subprogram_Or_Concurrent_Unit;
6288 ---------------------
6289 -- In_Visible_Part --
6290 ---------------------
6292 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
6295 Is_Package_Or_Generic_Package (Scope_Id)
6296 and then In_Open_Scopes (Scope_Id)
6297 and then not In_Package_Body (Scope_Id)
6298 and then not In_Private_Part (Scope_Id);
6299 end In_Visible_Part;
6301 --------------------------------
6302 -- Incomplete_Or_Private_View --
6303 --------------------------------
6305 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
6306 function Inspect_Decls
6308 Taft : Boolean := False) return Entity_Id;
6309 -- Check whether a declarative region contains the incomplete or private
6316 function Inspect_Decls
6318 Taft : Boolean := False) return Entity_Id
6324 Decl := First (Decls);
6325 while Present (Decl) loop
6329 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6330 Match := Defining_Identifier (Decl);
6334 if Nkind_In (Decl, N_Private_Extension_Declaration,
6335 N_Private_Type_Declaration)
6337 Match := Defining_Identifier (Decl);
6342 and then Present (Full_View (Match))
6343 and then Full_View (Match) = Typ
6358 -- Start of processing for Incomplete_Or_Partial_View
6361 -- Incomplete type case
6363 Prev := Current_Entity_In_Scope (Typ);
6366 and then Is_Incomplete_Type (Prev)
6367 and then Present (Full_View (Prev))
6368 and then Full_View (Prev) = Typ
6373 -- Private or Taft amendment type case
6376 Pkg : constant Entity_Id := Scope (Typ);
6377 Pkg_Decl : Node_Id := Pkg;
6380 if Ekind (Pkg) = E_Package then
6381 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6382 Pkg_Decl := Parent (Pkg_Decl);
6385 -- It is knows that Typ has a private view, look for it in the
6386 -- visible declarations of the enclosing scope. A special case
6387 -- of this is when the two views have been exchanged - the full
6388 -- appears earlier than the private.
6390 if Has_Private_Declaration (Typ) then
6391 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6393 -- Exchanged view case, look in the private declarations
6396 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6401 -- Otherwise if this is the package body, then Typ is a potential
6402 -- Taft amendment type. The incomplete view should be located in
6403 -- the private declarations of the enclosing scope.
6405 elsif In_Package_Body (Pkg) then
6406 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6411 -- The type has no incomplete or private view
6414 end Incomplete_Or_Private_View;
6416 ---------------------------------
6417 -- Insert_Explicit_Dereference --
6418 ---------------------------------
6420 procedure Insert_Explicit_Dereference (N : Node_Id) is
6421 New_Prefix : constant Node_Id := Relocate_Node (N);
6422 Ent : Entity_Id := Empty;
6429 Save_Interps (N, New_Prefix);
6432 Make_Explicit_Dereference (Sloc (Parent (N)),
6433 Prefix => New_Prefix));
6435 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6437 if Is_Overloaded (New_Prefix) then
6439 -- The dereference is also overloaded, and its interpretations are
6440 -- the designated types of the interpretations of the original node.
6442 Set_Etype (N, Any_Type);
6444 Get_First_Interp (New_Prefix, I, It);
6445 while Present (It.Nam) loop
6448 if Is_Access_Type (T) then
6449 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6452 Get_Next_Interp (I, It);
6458 -- Prefix is unambiguous: mark the original prefix (which might
6459 -- Come_From_Source) as a reference, since the new (relocated) one
6460 -- won't be taken into account.
6462 if Is_Entity_Name (New_Prefix) then
6463 Ent := Entity (New_Prefix);
6466 -- For a retrieval of a subcomponent of some composite object,
6467 -- retrieve the ultimate entity if there is one.
6469 elsif Nkind (New_Prefix) = N_Selected_Component
6470 or else Nkind (New_Prefix) = N_Indexed_Component
6472 Pref := Prefix (New_Prefix);
6473 while Present (Pref)
6475 (Nkind (Pref) = N_Selected_Component
6476 or else Nkind (Pref) = N_Indexed_Component)
6478 Pref := Prefix (Pref);
6481 if Present (Pref) and then Is_Entity_Name (Pref) then
6482 Ent := Entity (Pref);
6486 -- Place the reference on the entity node
6488 if Present (Ent) then
6489 Generate_Reference (Ent, Pref);
6492 end Insert_Explicit_Dereference;
6494 ------------------------------------------
6495 -- Inspect_Deferred_Constant_Completion --
6496 ------------------------------------------
6498 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6502 Decl := First (Decls);
6503 while Present (Decl) loop
6505 -- Deferred constant signature
6507 if Nkind (Decl) = N_Object_Declaration
6508 and then Constant_Present (Decl)
6509 and then No (Expression (Decl))
6511 -- No need to check internally generated constants
6513 and then Comes_From_Source (Decl)
6515 -- The constant is not completed. A full object declaration or a
6516 -- pragma Import complete a deferred constant.
6518 and then not Has_Completion (Defining_Identifier (Decl))
6521 ("constant declaration requires initialization expression",
6522 Defining_Identifier (Decl));
6525 Decl := Next (Decl);
6527 end Inspect_Deferred_Constant_Completion;
6529 -----------------------------
6530 -- Is_Actual_Out_Parameter --
6531 -----------------------------
6533 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6537 Find_Actual (N, Formal, Call);
6538 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6539 end Is_Actual_Out_Parameter;
6541 -------------------------
6542 -- Is_Actual_Parameter --
6543 -------------------------
6545 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6546 PK : constant Node_Kind := Nkind (Parent (N));
6550 when N_Parameter_Association =>
6551 return N = Explicit_Actual_Parameter (Parent (N));
6553 when N_Function_Call | N_Procedure_Call_Statement =>
6554 return Is_List_Member (N)
6556 List_Containing (N) = Parameter_Associations (Parent (N));
6561 end Is_Actual_Parameter;
6563 --------------------------------
6564 -- Is_Actual_Tagged_Parameter --
6565 --------------------------------
6567 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6571 Find_Actual (N, Formal, Call);
6572 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6573 end Is_Actual_Tagged_Parameter;
6575 ---------------------
6576 -- Is_Aliased_View --
6577 ---------------------
6579 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6583 if Is_Entity_Name (Obj) then
6586 if Is_Object (E) and then not Is_Aliased (E) then
6587 Check_Restriction (No_Implicit_Aliasing, Obj);
6594 or else (Present (Renamed_Object (E))
6595 and then Is_Aliased_View (Renamed_Object (E)))))
6597 or else ((Is_Formal (E)
6598 or else Ekind (E) = E_Generic_In_Out_Parameter
6599 or else Ekind (E) = E_Generic_In_Parameter)
6600 and then Is_Tagged_Type (Etype (E)))
6602 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
6604 -- Current instance of type, either directly or as rewritten
6605 -- reference to the current object.
6607 or else (Is_Entity_Name (Original_Node (Obj))
6608 and then Present (Entity (Original_Node (Obj)))
6609 and then Is_Type (Entity (Original_Node (Obj))))
6611 or else (Is_Type (E) and then E = Current_Scope)
6613 or else (Is_Incomplete_Or_Private_Type (E)
6614 and then Full_View (E) = Current_Scope)
6616 -- Ada 2012 AI05-0053: the return object of an extended return
6617 -- statement is aliased if its type is immutably limited.
6619 or else (Is_Return_Object (E)
6620 and then Is_Immutably_Limited_Type (Etype (E)));
6622 elsif Nkind (Obj) = N_Selected_Component then
6623 return Is_Aliased (Entity (Selector_Name (Obj)));
6625 elsif Nkind (Obj) = N_Indexed_Component then
6626 return Has_Aliased_Components (Etype (Prefix (Obj)))
6628 (Is_Access_Type (Etype (Prefix (Obj)))
6629 and then Has_Aliased_Components
6630 (Designated_Type (Etype (Prefix (Obj)))));
6632 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
6633 return Is_Tagged_Type (Etype (Obj))
6634 and then Is_Aliased_View (Expression (Obj));
6636 elsif Nkind (Obj) = N_Explicit_Dereference then
6637 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6642 end Is_Aliased_View;
6644 -------------------------
6645 -- Is_Ancestor_Package --
6646 -------------------------
6648 function Is_Ancestor_Package
6650 E2 : Entity_Id) return Boolean
6657 and then Par /= Standard_Standard
6667 end Is_Ancestor_Package;
6669 ----------------------
6670 -- Is_Atomic_Object --
6671 ----------------------
6673 function Is_Atomic_Object (N : Node_Id) return Boolean is
6675 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6676 -- Determines if given object has atomic components
6678 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6679 -- If prefix is an implicit dereference, examine designated type
6681 ----------------------
6682 -- Is_Atomic_Prefix --
6683 ----------------------
6685 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6687 if Is_Access_Type (Etype (N)) then
6689 Has_Atomic_Components (Designated_Type (Etype (N)));
6691 return Object_Has_Atomic_Components (N);
6693 end Is_Atomic_Prefix;
6695 ----------------------------------
6696 -- Object_Has_Atomic_Components --
6697 ----------------------------------
6699 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6701 if Has_Atomic_Components (Etype (N))
6702 or else Is_Atomic (Etype (N))
6706 elsif Is_Entity_Name (N)
6707 and then (Has_Atomic_Components (Entity (N))
6708 or else Is_Atomic (Entity (N)))
6712 elsif Nkind (N) = N_Indexed_Component
6713 or else Nkind (N) = N_Selected_Component
6715 return Is_Atomic_Prefix (Prefix (N));
6720 end Object_Has_Atomic_Components;
6722 -- Start of processing for Is_Atomic_Object
6725 -- Predicate is not relevant to subprograms
6727 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6730 elsif Is_Atomic (Etype (N))
6731 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6735 elsif Nkind (N) = N_Indexed_Component
6736 or else Nkind (N) = N_Selected_Component
6738 return Is_Atomic_Prefix (Prefix (N));
6743 end Is_Atomic_Object;
6745 -----------------------------
6746 -- Is_Concurrent_Interface --
6747 -----------------------------
6749 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6754 (Is_Protected_Interface (T)
6755 or else Is_Synchronized_Interface (T)
6756 or else Is_Task_Interface (T));
6757 end Is_Concurrent_Interface;
6759 --------------------------------------
6760 -- Is_Controlling_Limited_Procedure --
6761 --------------------------------------
6763 function Is_Controlling_Limited_Procedure
6764 (Proc_Nam : Entity_Id) return Boolean
6766 Param_Typ : Entity_Id := Empty;
6769 if Ekind (Proc_Nam) = E_Procedure
6770 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6772 Param_Typ := Etype (Parameter_Type (First (
6773 Parameter_Specifications (Parent (Proc_Nam)))));
6775 -- In this case where an Itype was created, the procedure call has been
6778 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6779 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6781 Present (Parameter_Associations
6782 (Associated_Node_For_Itype (Proc_Nam)))
6785 Etype (First (Parameter_Associations
6786 (Associated_Node_For_Itype (Proc_Nam))));
6789 if Present (Param_Typ) then
6791 Is_Interface (Param_Typ)
6792 and then Is_Limited_Record (Param_Typ);
6796 end Is_Controlling_Limited_Procedure;
6798 -----------------------------
6799 -- Is_CPP_Constructor_Call --
6800 -----------------------------
6802 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6804 return Nkind (N) = N_Function_Call
6805 and then Is_CPP_Class (Etype (Etype (N)))
6806 and then Is_Constructor (Entity (Name (N)))
6807 and then Is_Imported (Entity (Name (N)));
6808 end Is_CPP_Constructor_Call;
6814 function Is_Delegate (T : Entity_Id) return Boolean is
6815 Desig_Type : Entity_Id;
6818 if VM_Target /= CLI_Target then
6822 -- Access-to-subprograms are delegates in CIL
6824 if Ekind (T) = E_Access_Subprogram_Type then
6828 if Ekind (T) not in Access_Kind then
6830 -- A delegate is a managed pointer. If no designated type is defined
6831 -- it means that it's not a delegate.
6836 Desig_Type := Etype (Directly_Designated_Type (T));
6838 if not Is_Tagged_Type (Desig_Type) then
6842 -- Test if the type is inherited from [mscorlib]System.Delegate
6844 while Etype (Desig_Type) /= Desig_Type loop
6845 if Chars (Scope (Desig_Type)) /= No_Name
6846 and then Is_Imported (Scope (Desig_Type))
6847 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6852 Desig_Type := Etype (Desig_Type);
6858 ----------------------------------------------
6859 -- Is_Dependent_Component_Of_Mutable_Object --
6860 ----------------------------------------------
6862 function Is_Dependent_Component_Of_Mutable_Object
6863 (Object : Node_Id) return Boolean
6866 Prefix_Type : Entity_Id;
6867 P_Aliased : Boolean := False;
6870 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6871 -- Returns True if and only if Comp is declared within a variant part
6873 --------------------------------
6874 -- Is_Declared_Within_Variant --
6875 --------------------------------
6877 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6878 Comp_Decl : constant Node_Id := Parent (Comp);
6879 Comp_List : constant Node_Id := Parent (Comp_Decl);
6881 return Nkind (Parent (Comp_List)) = N_Variant;
6882 end Is_Declared_Within_Variant;
6884 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6887 if Is_Variable (Object) then
6889 if Nkind (Object) = N_Selected_Component then
6890 P := Prefix (Object);
6891 Prefix_Type := Etype (P);
6893 if Is_Entity_Name (P) then
6895 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6896 Prefix_Type := Base_Type (Prefix_Type);
6899 if Is_Aliased (Entity (P)) then
6903 -- A discriminant check on a selected component may be expanded
6904 -- into a dereference when removing side-effects. Recover the
6905 -- original node and its type, which may be unconstrained.
6907 elsif Nkind (P) = N_Explicit_Dereference
6908 and then not (Comes_From_Source (P))
6910 P := Original_Node (P);
6911 Prefix_Type := Etype (P);
6914 -- Check for prefix being an aliased component???
6920 -- A heap object is constrained by its initial value
6922 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6923 -- the dereferenced case, since the access value might denote an
6924 -- unconstrained aliased object, whereas in Ada 95 the designated
6925 -- object is guaranteed to be constrained. A worst-case assumption
6926 -- has to apply in Ada 2005 because we can't tell at compile time
6927 -- whether the object is "constrained by its initial value"
6928 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6929 -- semantic rules -- these rules are acknowledged to need fixing).
6931 if Ada_Version < Ada_2005 then
6932 if Is_Access_Type (Prefix_Type)
6933 or else Nkind (P) = N_Explicit_Dereference
6938 elsif Ada_Version >= Ada_2005 then
6939 if Is_Access_Type (Prefix_Type) then
6941 -- If the access type is pool-specific, and there is no
6942 -- constrained partial view of the designated type, then the
6943 -- designated object is known to be constrained.
6945 if Ekind (Prefix_Type) = E_Access_Type
6946 and then not Has_Constrained_Partial_View
6947 (Designated_Type (Prefix_Type))
6951 -- Otherwise (general access type, or there is a constrained
6952 -- partial view of the designated type), we need to check
6953 -- based on the designated type.
6956 Prefix_Type := Designated_Type (Prefix_Type);
6962 Original_Record_Component (Entity (Selector_Name (Object)));
6964 -- As per AI-0017, the renaming is illegal in a generic body, even
6965 -- if the subtype is indefinite.
6967 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6969 if not Is_Constrained (Prefix_Type)
6970 and then (not Is_Indefinite_Subtype (Prefix_Type)
6972 (Is_Generic_Type (Prefix_Type)
6973 and then Ekind (Current_Scope) = E_Generic_Package
6974 and then In_Package_Body (Current_Scope)))
6976 and then (Is_Declared_Within_Variant (Comp)
6977 or else Has_Discriminant_Dependent_Constraint (Comp))
6978 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6984 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6988 elsif Nkind (Object) = N_Indexed_Component
6989 or else Nkind (Object) = N_Slice
6991 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6993 -- A type conversion that Is_Variable is a view conversion:
6994 -- go back to the denoted object.
6996 elsif Nkind (Object) = N_Type_Conversion then
6998 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
7003 end Is_Dependent_Component_Of_Mutable_Object;
7005 ---------------------
7006 -- Is_Dereferenced --
7007 ---------------------
7009 function Is_Dereferenced (N : Node_Id) return Boolean is
7010 P : constant Node_Id := Parent (N);
7013 (Nkind (P) = N_Selected_Component
7015 Nkind (P) = N_Explicit_Dereference
7017 Nkind (P) = N_Indexed_Component
7019 Nkind (P) = N_Slice)
7020 and then Prefix (P) = N;
7021 end Is_Dereferenced;
7023 ----------------------
7024 -- Is_Descendent_Of --
7025 ----------------------
7027 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
7032 pragma Assert (Nkind (T1) in N_Entity);
7033 pragma Assert (Nkind (T2) in N_Entity);
7035 T := Base_Type (T1);
7037 -- Immediate return if the types match
7042 -- Comment needed here ???
7044 elsif Ekind (T) = E_Class_Wide_Type then
7045 return Etype (T) = T2;
7053 -- Done if we found the type we are looking for
7058 -- Done if no more derivations to check
7065 -- Following test catches error cases resulting from prev errors
7067 elsif No (Etyp) then
7070 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
7073 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
7077 T := Base_Type (Etyp);
7080 end Is_Descendent_Of;
7082 ----------------------------
7083 -- Is_Expression_Function --
7084 ----------------------------
7086 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
7087 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7090 return Ekind (Subp) = E_Function
7091 and then Nkind (Decl) = N_Subprogram_Declaration
7093 (Nkind (Original_Node (Decl)) = N_Expression_Function
7095 (Present (Corresponding_Body (Decl))
7097 Nkind (Original_Node
7098 (Unit_Declaration_Node (Corresponding_Body (Decl))))
7099 = N_Expression_Function));
7100 end Is_Expression_Function;
7106 function Is_False (U : Uint) return Boolean is
7111 ---------------------------
7112 -- Is_Fixed_Model_Number --
7113 ---------------------------
7115 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
7116 S : constant Ureal := Small_Value (T);
7117 M : Urealp.Save_Mark;
7121 R := (U = UR_Trunc (U / S) * S);
7124 end Is_Fixed_Model_Number;
7126 -------------------------------
7127 -- Is_Fully_Initialized_Type --
7128 -------------------------------
7130 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
7132 if Is_Scalar_Type (Typ) then
7135 elsif Is_Access_Type (Typ) then
7138 elsif Is_Array_Type (Typ) then
7139 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
7143 -- An interesting case, if we have a constrained type one of whose
7144 -- bounds is known to be null, then there are no elements to be
7145 -- initialized, so all the elements are initialized!
7147 if Is_Constrained (Typ) then
7150 Indx_Typ : Entity_Id;
7154 Indx := First_Index (Typ);
7155 while Present (Indx) loop
7156 if Etype (Indx) = Any_Type then
7159 -- If index is a range, use directly
7161 elsif Nkind (Indx) = N_Range then
7162 Lbd := Low_Bound (Indx);
7163 Hbd := High_Bound (Indx);
7166 Indx_Typ := Etype (Indx);
7168 if Is_Private_Type (Indx_Typ) then
7169 Indx_Typ := Full_View (Indx_Typ);
7172 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
7175 Lbd := Type_Low_Bound (Indx_Typ);
7176 Hbd := Type_High_Bound (Indx_Typ);
7180 if Compile_Time_Known_Value (Lbd)
7181 and then Compile_Time_Known_Value (Hbd)
7183 if Expr_Value (Hbd) < Expr_Value (Lbd) then
7193 -- If no null indexes, then type is not fully initialized
7199 elsif Is_Record_Type (Typ) then
7200 if Has_Discriminants (Typ)
7202 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
7203 and then Is_Fully_Initialized_Variant (Typ)
7208 -- Controlled records are considered to be fully initialized if
7209 -- there is a user defined Initialize routine. This may not be
7210 -- entirely correct, but as the spec notes, we are guessing here
7211 -- what is best from the point of view of issuing warnings.
7213 if Is_Controlled (Typ) then
7215 Utyp : constant Entity_Id := Underlying_Type (Typ);
7218 if Present (Utyp) then
7220 Init : constant Entity_Id :=
7222 (Underlying_Type (Typ), Name_Initialize));
7226 and then Comes_From_Source (Init)
7228 Is_Predefined_File_Name
7229 (File_Name (Get_Source_File_Index (Sloc (Init))))
7233 elsif Has_Null_Extension (Typ)
7235 Is_Fully_Initialized_Type
7236 (Etype (Base_Type (Typ)))
7245 -- Otherwise see if all record components are initialized
7251 Ent := First_Entity (Typ);
7252 while Present (Ent) loop
7253 if Ekind (Ent) = E_Component
7254 and then (No (Parent (Ent))
7255 or else No (Expression (Parent (Ent))))
7256 and then not Is_Fully_Initialized_Type (Etype (Ent))
7258 -- Special VM case for tag components, which need to be
7259 -- defined in this case, but are never initialized as VMs
7260 -- are using other dispatching mechanisms. Ignore this
7261 -- uninitialized case. Note that this applies both to the
7262 -- uTag entry and the main vtable pointer (CPP_Class case).
7264 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
7273 -- No uninitialized components, so type is fully initialized.
7274 -- Note that this catches the case of no components as well.
7278 elsif Is_Concurrent_Type (Typ) then
7281 elsif Is_Private_Type (Typ) then
7283 U : constant Entity_Id := Underlying_Type (Typ);
7289 return Is_Fully_Initialized_Type (U);
7296 end Is_Fully_Initialized_Type;
7298 ----------------------------------
7299 -- Is_Fully_Initialized_Variant --
7300 ----------------------------------
7302 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
7303 Loc : constant Source_Ptr := Sloc (Typ);
7304 Constraints : constant List_Id := New_List;
7305 Components : constant Elist_Id := New_Elmt_List;
7306 Comp_Elmt : Elmt_Id;
7308 Comp_List : Node_Id;
7310 Discr_Val : Node_Id;
7312 Report_Errors : Boolean;
7313 pragma Warnings (Off, Report_Errors);
7316 if Serious_Errors_Detected > 0 then
7320 if Is_Record_Type (Typ)
7321 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7322 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7324 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7326 Discr := First_Discriminant (Typ);
7327 while Present (Discr) loop
7328 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7329 Discr_Val := Expression (Parent (Discr));
7331 if Present (Discr_Val)
7332 and then Is_OK_Static_Expression (Discr_Val)
7334 Append_To (Constraints,
7335 Make_Component_Association (Loc,
7336 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7337 Expression => New_Copy (Discr_Val)));
7345 Next_Discriminant (Discr);
7350 Comp_List => Comp_List,
7351 Governed_By => Constraints,
7353 Report_Errors => Report_Errors);
7355 -- Check that each component present is fully initialized
7357 Comp_Elmt := First_Elmt (Components);
7358 while Present (Comp_Elmt) loop
7359 Comp_Id := Node (Comp_Elmt);
7361 if Ekind (Comp_Id) = E_Component
7362 and then (No (Parent (Comp_Id))
7363 or else No (Expression (Parent (Comp_Id))))
7364 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7369 Next_Elmt (Comp_Elmt);
7374 elsif Is_Private_Type (Typ) then
7376 U : constant Entity_Id := Underlying_Type (Typ);
7382 return Is_Fully_Initialized_Variant (U);
7388 end Is_Fully_Initialized_Variant;
7390 ----------------------------
7391 -- Is_Inherited_Operation --
7392 ----------------------------
7394 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7395 pragma Assert (Is_Overloadable (E));
7396 Kind : constant Node_Kind := Nkind (Parent (E));
7398 return Kind = N_Full_Type_Declaration
7399 or else Kind = N_Private_Extension_Declaration
7400 or else Kind = N_Subtype_Declaration
7401 or else (Ekind (E) = E_Enumeration_Literal
7402 and then Is_Derived_Type (Etype (E)));
7403 end Is_Inherited_Operation;
7405 -------------------------------------
7406 -- Is_Inherited_Operation_For_Type --
7407 -------------------------------------
7409 function Is_Inherited_Operation_For_Type
7411 Typ : Entity_Id) return Boolean
7414 return Is_Inherited_Operation (E)
7415 and then Etype (Parent (E)) = Typ;
7416 end Is_Inherited_Operation_For_Type;
7422 function Is_Iterator (Typ : Entity_Id) return Boolean is
7423 Ifaces_List : Elist_Id;
7424 Iface_Elmt : Elmt_Id;
7428 if Is_Class_Wide_Type (Typ)
7430 (Chars (Etype (Typ)) = Name_Forward_Iterator
7432 Chars (Etype (Typ)) = Name_Reversible_Iterator)
7434 Is_Predefined_File_Name
7435 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
7439 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
7443 Collect_Interfaces (Typ, Ifaces_List);
7445 Iface_Elmt := First_Elmt (Ifaces_List);
7446 while Present (Iface_Elmt) loop
7447 Iface := Node (Iface_Elmt);
7448 if Chars (Iface) = Name_Forward_Iterator
7450 Is_Predefined_File_Name
7451 (Unit_File_Name (Get_Source_Unit (Iface)))
7456 Next_Elmt (Iface_Elmt);
7467 -- We seem to have a lot of overlapping functions that do similar things
7468 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7469 -- purely syntactic, it should be in Sem_Aux I would think???
7471 function Is_LHS (N : Node_Id) return Boolean is
7472 P : constant Node_Id := Parent (N);
7475 if Nkind (P) = N_Assignment_Statement then
7476 return Name (P) = N;
7479 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7481 return N = Prefix (P) and then Is_LHS (P);
7488 -----------------------------
7489 -- Is_Library_Level_Entity --
7490 -----------------------------
7492 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7494 -- The following is a small optimization, and it also properly handles
7495 -- discriminals, which in task bodies might appear in expressions before
7496 -- the corresponding procedure has been created, and which therefore do
7497 -- not have an assigned scope.
7499 if Is_Formal (E) then
7503 -- Normal test is simply that the enclosing dynamic scope is Standard
7505 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7506 end Is_Library_Level_Entity;
7508 --------------------------------
7509 -- Is_Limited_Class_Wide_Type --
7510 --------------------------------
7512 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
7515 Is_Class_Wide_Type (Typ)
7516 and then Is_Limited_Type (Typ);
7517 end Is_Limited_Class_Wide_Type;
7519 ---------------------------------
7520 -- Is_Local_Variable_Reference --
7521 ---------------------------------
7523 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7525 if not Is_Entity_Name (Expr) then
7530 Ent : constant Entity_Id := Entity (Expr);
7531 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7533 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7536 return Present (Sub) and then Sub = Current_Subprogram;
7540 end Is_Local_Variable_Reference;
7542 -------------------------
7543 -- Is_Object_Reference --
7544 -------------------------
7546 function Is_Object_Reference (N : Node_Id) return Boolean is
7548 if Is_Entity_Name (N) then
7549 return Present (Entity (N)) and then Is_Object (Entity (N));
7553 when N_Indexed_Component | N_Slice =>
7555 Is_Object_Reference (Prefix (N))
7556 or else Is_Access_Type (Etype (Prefix (N)));
7558 -- In Ada 95, a function call is a constant object; a procedure
7561 when N_Function_Call =>
7562 return Etype (N) /= Standard_Void_Type;
7564 -- A reference to the stream attribute Input is a function call
7566 when N_Attribute_Reference =>
7567 return Attribute_Name (N) = Name_Input;
7569 when N_Selected_Component =>
7571 Is_Object_Reference (Selector_Name (N))
7573 (Is_Object_Reference (Prefix (N))
7574 or else Is_Access_Type (Etype (Prefix (N))));
7576 when N_Explicit_Dereference =>
7579 -- A view conversion of a tagged object is an object reference
7581 when N_Type_Conversion =>
7582 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7583 and then Is_Tagged_Type (Etype (Expression (N)))
7584 and then Is_Object_Reference (Expression (N));
7586 -- An unchecked type conversion is considered to be an object if
7587 -- the operand is an object (this construction arises only as a
7588 -- result of expansion activities).
7590 when N_Unchecked_Type_Conversion =>
7597 end Is_Object_Reference;
7599 -----------------------------------
7600 -- Is_OK_Variable_For_Out_Formal --
7601 -----------------------------------
7603 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7605 Note_Possible_Modification (AV, Sure => True);
7607 -- We must reject parenthesized variable names. The check for
7608 -- Comes_From_Source is present because there are currently
7609 -- cases where the compiler violates this rule (e.g. passing
7610 -- a task object to its controlled Initialize routine).
7612 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7615 -- A variable is always allowed
7617 elsif Is_Variable (AV) then
7620 -- Unchecked conversions are allowed only if they come from the
7621 -- generated code, which sometimes uses unchecked conversions for out
7622 -- parameters in cases where code generation is unaffected. We tell
7623 -- source unchecked conversions by seeing if they are rewrites of an
7624 -- original Unchecked_Conversion function call, or of an explicit
7625 -- conversion of a function call.
7627 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7628 if Nkind (Original_Node (AV)) = N_Function_Call then
7631 elsif Comes_From_Source (AV)
7632 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7636 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7637 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7643 -- Normal type conversions are allowed if argument is a variable
7645 elsif Nkind (AV) = N_Type_Conversion then
7646 if Is_Variable (Expression (AV))
7647 and then Paren_Count (Expression (AV)) = 0
7649 Note_Possible_Modification (Expression (AV), Sure => True);
7652 -- We also allow a non-parenthesized expression that raises
7653 -- constraint error if it rewrites what used to be a variable
7655 elsif Raises_Constraint_Error (Expression (AV))
7656 and then Paren_Count (Expression (AV)) = 0
7657 and then Is_Variable (Original_Node (Expression (AV)))
7661 -- Type conversion of something other than a variable
7667 -- If this node is rewritten, then test the original form, if that is
7668 -- OK, then we consider the rewritten node OK (for example, if the
7669 -- original node is a conversion, then Is_Variable will not be true
7670 -- but we still want to allow the conversion if it converts a variable).
7672 elsif Original_Node (AV) /= AV then
7674 -- In Ada 2012, the explicit dereference may be a rewritten call to a
7675 -- Reference function.
7677 if Ada_Version >= Ada_2012
7678 and then Nkind (Original_Node (AV)) = N_Function_Call
7680 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
7685 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7688 -- All other non-variables are rejected
7693 end Is_OK_Variable_For_Out_Formal;
7695 -----------------------------------
7696 -- Is_Partially_Initialized_Type --
7697 -----------------------------------
7699 function Is_Partially_Initialized_Type
7701 Include_Implicit : Boolean := True) return Boolean
7704 if Is_Scalar_Type (Typ) then
7707 elsif Is_Access_Type (Typ) then
7708 return Include_Implicit;
7710 elsif Is_Array_Type (Typ) then
7712 -- If component type is partially initialized, so is array type
7714 if Is_Partially_Initialized_Type
7715 (Component_Type (Typ), Include_Implicit)
7719 -- Otherwise we are only partially initialized if we are fully
7720 -- initialized (this is the empty array case, no point in us
7721 -- duplicating that code here).
7724 return Is_Fully_Initialized_Type (Typ);
7727 elsif Is_Record_Type (Typ) then
7729 -- A discriminated type is always partially initialized if in
7732 if Has_Discriminants (Typ) and then Include_Implicit then
7735 -- A tagged type is always partially initialized
7737 elsif Is_Tagged_Type (Typ) then
7740 -- Case of non-discriminated record
7746 Component_Present : Boolean := False;
7747 -- Set True if at least one component is present. If no
7748 -- components are present, then record type is fully
7749 -- initialized (another odd case, like the null array).
7752 -- Loop through components
7754 Ent := First_Entity (Typ);
7755 while Present (Ent) loop
7756 if Ekind (Ent) = E_Component then
7757 Component_Present := True;
7759 -- If a component has an initialization expression then
7760 -- the enclosing record type is partially initialized
7762 if Present (Parent (Ent))
7763 and then Present (Expression (Parent (Ent)))
7767 -- If a component is of a type which is itself partially
7768 -- initialized, then the enclosing record type is also.
7770 elsif Is_Partially_Initialized_Type
7771 (Etype (Ent), Include_Implicit)
7780 -- No initialized components found. If we found any components
7781 -- they were all uninitialized so the result is false.
7783 if Component_Present then
7786 -- But if we found no components, then all the components are
7787 -- initialized so we consider the type to be initialized.
7795 -- Concurrent types are always fully initialized
7797 elsif Is_Concurrent_Type (Typ) then
7800 -- For a private type, go to underlying type. If there is no underlying
7801 -- type then just assume this partially initialized. Not clear if this
7802 -- can happen in a non-error case, but no harm in testing for this.
7804 elsif Is_Private_Type (Typ) then
7806 U : constant Entity_Id := Underlying_Type (Typ);
7811 return Is_Partially_Initialized_Type (U, Include_Implicit);
7815 -- For any other type (are there any?) assume partially initialized
7820 end Is_Partially_Initialized_Type;
7822 ------------------------------------
7823 -- Is_Potentially_Persistent_Type --
7824 ------------------------------------
7826 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7831 -- For private type, test corresponding full type
7833 if Is_Private_Type (T) then
7834 return Is_Potentially_Persistent_Type (Full_View (T));
7836 -- Scalar types are potentially persistent
7838 elsif Is_Scalar_Type (T) then
7841 -- Record type is potentially persistent if not tagged and the types of
7842 -- all it components are potentially persistent, and no component has
7843 -- an initialization expression.
7845 elsif Is_Record_Type (T)
7846 and then not Is_Tagged_Type (T)
7847 and then not Is_Partially_Initialized_Type (T)
7849 Comp := First_Component (T);
7850 while Present (Comp) loop
7851 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7860 -- Array type is potentially persistent if its component type is
7861 -- potentially persistent and if all its constraints are static.
7863 elsif Is_Array_Type (T) then
7864 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7868 Indx := First_Index (T);
7869 while Present (Indx) loop
7870 if not Is_OK_Static_Subtype (Etype (Indx)) then
7879 -- All other types are not potentially persistent
7884 end Is_Potentially_Persistent_Type;
7886 ---------------------------------
7887 -- Is_Protected_Self_Reference --
7888 ---------------------------------
7890 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7892 function In_Access_Definition (N : Node_Id) return Boolean;
7893 -- Returns true if N belongs to an access definition
7895 --------------------------
7896 -- In_Access_Definition --
7897 --------------------------
7899 function In_Access_Definition (N : Node_Id) return Boolean is
7904 while Present (P) loop
7905 if Nkind (P) = N_Access_Definition then
7913 end In_Access_Definition;
7915 -- Start of processing for Is_Protected_Self_Reference
7918 -- Verify that prefix is analyzed and has the proper form. Note that
7919 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
7920 -- which also produce the address of an entity, do not analyze their
7921 -- prefix because they denote entities that are not necessarily visible.
7922 -- Neither of them can apply to a protected type.
7924 return Ada_Version >= Ada_2005
7925 and then Is_Entity_Name (N)
7926 and then Present (Entity (N))
7927 and then Is_Protected_Type (Entity (N))
7928 and then In_Open_Scopes (Entity (N))
7929 and then not In_Access_Definition (N);
7930 end Is_Protected_Self_Reference;
7932 -----------------------------
7933 -- Is_RCI_Pkg_Spec_Or_Body --
7934 -----------------------------
7936 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7938 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7939 -- Return True if the unit of Cunit is an RCI package declaration
7941 ---------------------------
7942 -- Is_RCI_Pkg_Decl_Cunit --
7943 ---------------------------
7945 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7946 The_Unit : constant Node_Id := Unit (Cunit);
7949 if Nkind (The_Unit) /= N_Package_Declaration then
7953 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7954 end Is_RCI_Pkg_Decl_Cunit;
7956 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7959 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7961 (Nkind (Unit (Cunit)) = N_Package_Body
7962 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7963 end Is_RCI_Pkg_Spec_Or_Body;
7965 -----------------------------------------
7966 -- Is_Remote_Access_To_Class_Wide_Type --
7967 -----------------------------------------
7969 function Is_Remote_Access_To_Class_Wide_Type
7970 (E : Entity_Id) return Boolean
7973 -- A remote access to class-wide type is a general access to object type
7974 -- declared in the visible part of a Remote_Types or Remote_Call_
7977 return Ekind (E) = E_General_Access_Type
7978 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7979 end Is_Remote_Access_To_Class_Wide_Type;
7981 -----------------------------------------
7982 -- Is_Remote_Access_To_Subprogram_Type --
7983 -----------------------------------------
7985 function Is_Remote_Access_To_Subprogram_Type
7986 (E : Entity_Id) return Boolean
7989 return (Ekind (E) = E_Access_Subprogram_Type
7990 or else (Ekind (E) = E_Record_Type
7991 and then Present (Corresponding_Remote_Type (E))))
7992 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7993 end Is_Remote_Access_To_Subprogram_Type;
7995 --------------------
7996 -- Is_Remote_Call --
7997 --------------------
7999 function Is_Remote_Call (N : Node_Id) return Boolean is
8001 if Nkind (N) /= N_Procedure_Call_Statement
8002 and then Nkind (N) /= N_Function_Call
8004 -- An entry call cannot be remote
8008 elsif Nkind (Name (N)) in N_Has_Entity
8009 and then Is_Remote_Call_Interface (Entity (Name (N)))
8011 -- A subprogram declared in the spec of a RCI package is remote
8015 elsif Nkind (Name (N)) = N_Explicit_Dereference
8016 and then Is_Remote_Access_To_Subprogram_Type
8017 (Etype (Prefix (Name (N))))
8019 -- The dereference of a RAS is a remote call
8023 elsif Present (Controlling_Argument (N))
8024 and then Is_Remote_Access_To_Class_Wide_Type
8025 (Etype (Controlling_Argument (N)))
8027 -- Any primitive operation call with a controlling argument of
8028 -- a RACW type is a remote call.
8033 -- All other calls are local calls
8038 ----------------------
8039 -- Is_Renamed_Entry --
8040 ----------------------
8042 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
8043 Orig_Node : Node_Id := Empty;
8044 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
8046 function Is_Entry (Nam : Node_Id) return Boolean;
8047 -- Determine whether Nam is an entry. Traverse selectors if there are
8048 -- nested selected components.
8054 function Is_Entry (Nam : Node_Id) return Boolean is
8056 if Nkind (Nam) = N_Selected_Component then
8057 return Is_Entry (Selector_Name (Nam));
8060 return Ekind (Entity (Nam)) = E_Entry;
8063 -- Start of processing for Is_Renamed_Entry
8066 if Present (Alias (Proc_Nam)) then
8067 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
8070 -- Look for a rewritten subprogram renaming declaration
8072 if Nkind (Subp_Decl) = N_Subprogram_Declaration
8073 and then Present (Original_Node (Subp_Decl))
8075 Orig_Node := Original_Node (Subp_Decl);
8078 -- The rewritten subprogram is actually an entry
8080 if Present (Orig_Node)
8081 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
8082 and then Is_Entry (Name (Orig_Node))
8088 end Is_Renamed_Entry;
8090 ----------------------------
8091 -- Is_Reversible_Iterator --
8092 ----------------------------
8094 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
8095 Ifaces_List : Elist_Id;
8096 Iface_Elmt : Elmt_Id;
8100 if Is_Class_Wide_Type (Typ)
8101 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
8103 Is_Predefined_File_Name
8104 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
8108 elsif not Is_Tagged_Type (Typ)
8109 or else not Is_Derived_Type (Typ)
8114 Collect_Interfaces (Typ, Ifaces_List);
8116 Iface_Elmt := First_Elmt (Ifaces_List);
8117 while Present (Iface_Elmt) loop
8118 Iface := Node (Iface_Elmt);
8119 if Chars (Iface) = Name_Reversible_Iterator
8121 Is_Predefined_File_Name
8122 (Unit_File_Name (Get_Source_Unit (Iface)))
8127 Next_Elmt (Iface_Elmt);
8132 end Is_Reversible_Iterator;
8134 ----------------------
8135 -- Is_Selector_Name --
8136 ----------------------
8138 function Is_Selector_Name (N : Node_Id) return Boolean is
8140 if not Is_List_Member (N) then
8142 P : constant Node_Id := Parent (N);
8143 K : constant Node_Kind := Nkind (P);
8146 (K = N_Expanded_Name or else
8147 K = N_Generic_Association or else
8148 K = N_Parameter_Association or else
8149 K = N_Selected_Component)
8150 and then Selector_Name (P) = N;
8155 L : constant List_Id := List_Containing (N);
8156 P : constant Node_Id := Parent (L);
8158 return (Nkind (P) = N_Discriminant_Association
8159 and then Selector_Names (P) = L)
8161 (Nkind (P) = N_Component_Association
8162 and then Choices (P) = L);
8165 end Is_Selector_Name;
8167 ----------------------------------
8168 -- Is_SPARK_Initialization_Expr --
8169 ----------------------------------
8171 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
8174 Comp_Assn : Node_Id;
8175 Orig_N : constant Node_Id := Original_Node (N);
8180 if not Comes_From_Source (Orig_N) then
8184 pragma Assert (Nkind (Orig_N) in N_Subexpr);
8186 case Nkind (Orig_N) is
8187 when N_Character_Literal |
8195 if Is_Entity_Name (Orig_N)
8196 and then Present (Entity (Orig_N)) -- needed in some cases
8198 case Ekind (Entity (Orig_N)) is
8200 E_Enumeration_Literal |
8205 if Is_Type (Entity (Orig_N)) then
8213 when N_Qualified_Expression |
8214 N_Type_Conversion =>
8215 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
8218 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8222 N_Membership_Test =>
8223 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
8224 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8227 N_Extension_Aggregate =>
8228 if Nkind (Orig_N) = N_Extension_Aggregate then
8229 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
8232 Expr := First (Expressions (Orig_N));
8233 while Present (Expr) loop
8234 if not Is_SPARK_Initialization_Expr (Expr) then
8242 Comp_Assn := First (Component_Associations (Orig_N));
8243 while Present (Comp_Assn) loop
8244 Expr := Expression (Comp_Assn);
8245 if Present (Expr) -- needed for box association
8246 and then not Is_SPARK_Initialization_Expr (Expr)
8255 when N_Attribute_Reference =>
8256 if Nkind (Prefix (Orig_N)) in N_Subexpr then
8257 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
8260 Expr := First (Expressions (Orig_N));
8261 while Present (Expr) loop
8262 if not Is_SPARK_Initialization_Expr (Expr) then
8270 -- Selected components might be expanded named not yet resolved, so
8271 -- default on the safe side. (Eg on sparklex.ads)
8273 when N_Selected_Component =>
8282 end Is_SPARK_Initialization_Expr;
8284 -------------------------------
8285 -- Is_SPARK_Object_Reference --
8286 -------------------------------
8288 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
8290 if Is_Entity_Name (N) then
8291 return Present (Entity (N))
8293 (Ekind_In (Entity (N), E_Constant, E_Variable)
8294 or else Ekind (Entity (N)) in Formal_Kind);
8298 when N_Selected_Component =>
8299 return Is_SPARK_Object_Reference (Prefix (N));
8305 end Is_SPARK_Object_Reference;
8311 function Is_Statement (N : Node_Id) return Boolean is
8314 Nkind (N) in N_Statement_Other_Than_Procedure_Call
8315 or else Nkind (N) = N_Procedure_Call_Statement;
8318 --------------------------------------------------
8319 -- Is_Subprogram_Stub_Without_Prior_Declaration --
8320 --------------------------------------------------
8322 function Is_Subprogram_Stub_Without_Prior_Declaration
8323 (N : Node_Id) return Boolean
8326 -- A subprogram stub without prior declaration serves as declaration for
8327 -- the actual subprogram body. As such, it has an attached defining
8328 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
8330 return Nkind (N) = N_Subprogram_Body_Stub
8331 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
8332 end Is_Subprogram_Stub_Without_Prior_Declaration;
8334 ---------------------------------
8335 -- Is_Synchronized_Tagged_Type --
8336 ---------------------------------
8338 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
8339 Kind : constant Entity_Kind := Ekind (Base_Type (E));
8342 -- A task or protected type derived from an interface is a tagged type.
8343 -- Such a tagged type is called a synchronized tagged type, as are
8344 -- synchronized interfaces and private extensions whose declaration
8345 -- includes the reserved word synchronized.
8347 return (Is_Tagged_Type (E)
8348 and then (Kind = E_Task_Type
8349 or else Kind = E_Protected_Type))
8352 and then Is_Synchronized_Interface (E))
8354 (Ekind (E) = E_Record_Type_With_Private
8355 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
8356 and then (Synchronized_Present (Parent (E))
8357 or else Is_Synchronized_Interface (Etype (E))));
8358 end Is_Synchronized_Tagged_Type;
8364 function Is_Transfer (N : Node_Id) return Boolean is
8365 Kind : constant Node_Kind := Nkind (N);
8368 if Kind = N_Simple_Return_Statement
8370 Kind = N_Extended_Return_Statement
8372 Kind = N_Goto_Statement
8374 Kind = N_Raise_Statement
8376 Kind = N_Requeue_Statement
8380 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
8381 and then No (Condition (N))
8385 elsif Kind = N_Procedure_Call_Statement
8386 and then Is_Entity_Name (Name (N))
8387 and then Present (Entity (Name (N)))
8388 and then No_Return (Entity (Name (N)))
8392 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
8404 function Is_True (U : Uint) return Boolean is
8409 -------------------------------
8410 -- Is_Universal_Numeric_Type --
8411 -------------------------------
8413 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
8415 return T = Universal_Integer or else T = Universal_Real;
8416 end Is_Universal_Numeric_Type;
8422 function Is_Value_Type (T : Entity_Id) return Boolean is
8424 return VM_Target = CLI_Target
8425 and then Nkind (T) in N_Has_Chars
8426 and then Chars (T) /= No_Name
8427 and then Get_Name_String (Chars (T)) = "valuetype";
8430 ---------------------
8431 -- Is_VMS_Operator --
8432 ---------------------
8434 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
8436 -- The VMS operators are declared in a child of System that is loaded
8437 -- through pragma Extend_System. In some rare cases a program is run
8438 -- with this extension but without indicating that the target is VMS.
8440 return Ekind (Op) = E_Function
8441 and then Is_Intrinsic_Subprogram (Op)
8443 ((Present_System_Aux
8444 and then Scope (Op) = System_Aux_Id)
8447 and then Scope (Scope (Op)) = RTU_Entity (System)));
8448 end Is_VMS_Operator;
8454 function Is_Variable
8456 Use_Original_Node : Boolean := True) return Boolean
8458 Orig_Node : Node_Id;
8460 function In_Protected_Function (E : Entity_Id) return Boolean;
8461 -- Within a protected function, the private components of the enclosing
8462 -- protected type are constants. A function nested within a (protected)
8463 -- procedure is not itself protected.
8465 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8466 -- Prefixes can involve implicit dereferences, in which case we must
8467 -- test for the case of a reference of a constant access type, which can
8468 -- can never be a variable.
8470 ---------------------------
8471 -- In_Protected_Function --
8472 ---------------------------
8474 function In_Protected_Function (E : Entity_Id) return Boolean is
8475 Prot : constant Entity_Id := Scope (E);
8479 if not Is_Protected_Type (Prot) then
8483 while Present (S) and then S /= Prot loop
8484 if Ekind (S) = E_Function and then Scope (S) = Prot then
8493 end In_Protected_Function;
8495 ------------------------
8496 -- Is_Variable_Prefix --
8497 ------------------------
8499 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8501 if Is_Access_Type (Etype (P)) then
8502 return not Is_Access_Constant (Root_Type (Etype (P)));
8504 -- For the case of an indexed component whose prefix has a packed
8505 -- array type, the prefix has been rewritten into a type conversion.
8506 -- Determine variable-ness from the converted expression.
8508 elsif Nkind (P) = N_Type_Conversion
8509 and then not Comes_From_Source (P)
8510 and then Is_Array_Type (Etype (P))
8511 and then Is_Packed (Etype (P))
8513 return Is_Variable (Expression (P));
8516 return Is_Variable (P);
8518 end Is_Variable_Prefix;
8520 -- Start of processing for Is_Variable
8523 -- Check if we perform the test on the original node since this may be a
8524 -- test of syntactic categories which must not be disturbed by whatever
8525 -- rewriting might have occurred. For example, an aggregate, which is
8526 -- certainly NOT a variable, could be turned into a variable by
8529 if Use_Original_Node then
8530 Orig_Node := Original_Node (N);
8535 -- Definitely OK if Assignment_OK is set. Since this is something that
8536 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8538 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8541 -- Normally we go to the original node, but there is one exception where
8542 -- we use the rewritten node, namely when it is an explicit dereference.
8543 -- The generated code may rewrite a prefix which is an access type with
8544 -- an explicit dereference. The dereference is a variable, even though
8545 -- the original node may not be (since it could be a constant of the
8548 -- In Ada 2005 we have a further case to consider: the prefix may be a
8549 -- function call given in prefix notation. The original node appears to
8550 -- be a selected component, but we need to examine the call.
8552 elsif Nkind (N) = N_Explicit_Dereference
8553 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8554 and then Present (Etype (Orig_Node))
8555 and then Is_Access_Type (Etype (Orig_Node))
8557 -- Note that if the prefix is an explicit dereference that does not
8558 -- come from source, we must check for a rewritten function call in
8559 -- prefixed notation before other forms of rewriting, to prevent a
8563 (Nkind (Orig_Node) = N_Function_Call
8564 and then not Is_Access_Constant (Etype (Prefix (N))))
8566 Is_Variable_Prefix (Original_Node (Prefix (N)));
8568 -- A function call is never a variable
8570 elsif Nkind (N) = N_Function_Call then
8573 -- All remaining checks use the original node
8575 elsif Is_Entity_Name (Orig_Node)
8576 and then Present (Entity (Orig_Node))
8579 E : constant Entity_Id := Entity (Orig_Node);
8580 K : constant Entity_Kind := Ekind (E);
8583 return (K = E_Variable
8584 and then Nkind (Parent (E)) /= N_Exception_Handler)
8585 or else (K = E_Component
8586 and then not In_Protected_Function (E))
8587 or else K = E_Out_Parameter
8588 or else K = E_In_Out_Parameter
8589 or else K = E_Generic_In_Out_Parameter
8591 -- Current instance of type
8593 or else (Is_Type (E) and then In_Open_Scopes (E))
8594 or else (Is_Incomplete_Or_Private_Type (E)
8595 and then In_Open_Scopes (Full_View (E)));
8599 case Nkind (Orig_Node) is
8600 when N_Indexed_Component | N_Slice =>
8601 return Is_Variable_Prefix (Prefix (Orig_Node));
8603 when N_Selected_Component =>
8604 return Is_Variable_Prefix (Prefix (Orig_Node))
8605 and then Is_Variable (Selector_Name (Orig_Node));
8607 -- For an explicit dereference, the type of the prefix cannot
8608 -- be an access to constant or an access to subprogram.
8610 when N_Explicit_Dereference =>
8612 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8614 return Is_Access_Type (Typ)
8615 and then not Is_Access_Constant (Root_Type (Typ))
8616 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8619 -- The type conversion is the case where we do not deal with the
8620 -- context dependent special case of an actual parameter. Thus
8621 -- the type conversion is only considered a variable for the
8622 -- purposes of this routine if the target type is tagged. However,
8623 -- a type conversion is considered to be a variable if it does not
8624 -- come from source (this deals for example with the conversions
8625 -- of expressions to their actual subtypes).
8627 when N_Type_Conversion =>
8628 return Is_Variable (Expression (Orig_Node))
8630 (not Comes_From_Source (Orig_Node)
8632 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8634 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8636 -- GNAT allows an unchecked type conversion as a variable. This
8637 -- only affects the generation of internal expanded code, since
8638 -- calls to instantiations of Unchecked_Conversion are never
8639 -- considered variables (since they are function calls).
8640 -- This is also true for expression actions.
8642 when N_Unchecked_Type_Conversion =>
8643 return Is_Variable (Expression (Orig_Node));
8651 ---------------------------
8652 -- Is_Visibly_Controlled --
8653 ---------------------------
8655 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8656 Root : constant Entity_Id := Root_Type (T);
8658 return Chars (Scope (Root)) = Name_Finalization
8659 and then Chars (Scope (Scope (Root))) = Name_Ada
8660 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8661 end Is_Visibly_Controlled;
8663 ------------------------
8664 -- Is_Volatile_Object --
8665 ------------------------
8667 function Is_Volatile_Object (N : Node_Id) return Boolean is
8669 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8670 -- Determines if given object has volatile components
8672 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8673 -- If prefix is an implicit dereference, examine designated type
8675 ------------------------
8676 -- Is_Volatile_Prefix --
8677 ------------------------
8679 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8680 Typ : constant Entity_Id := Etype (N);
8683 if Is_Access_Type (Typ) then
8685 Dtyp : constant Entity_Id := Designated_Type (Typ);
8688 return Is_Volatile (Dtyp)
8689 or else Has_Volatile_Components (Dtyp);
8693 return Object_Has_Volatile_Components (N);
8695 end Is_Volatile_Prefix;
8697 ------------------------------------
8698 -- Object_Has_Volatile_Components --
8699 ------------------------------------
8701 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8702 Typ : constant Entity_Id := Etype (N);
8705 if Is_Volatile (Typ)
8706 or else Has_Volatile_Components (Typ)
8710 elsif Is_Entity_Name (N)
8711 and then (Has_Volatile_Components (Entity (N))
8712 or else Is_Volatile (Entity (N)))
8716 elsif Nkind (N) = N_Indexed_Component
8717 or else Nkind (N) = N_Selected_Component
8719 return Is_Volatile_Prefix (Prefix (N));
8724 end Object_Has_Volatile_Components;
8726 -- Start of processing for Is_Volatile_Object
8729 if Is_Volatile (Etype (N))
8730 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8734 elsif Nkind (N) = N_Indexed_Component
8735 or else Nkind (N) = N_Selected_Component
8737 return Is_Volatile_Prefix (Prefix (N));
8742 end Is_Volatile_Object;
8744 ---------------------------
8745 -- Itype_Has_Declaration --
8746 ---------------------------
8748 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
8750 pragma Assert (Is_Itype (Id));
8751 return Present (Parent (Id))
8752 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
8753 N_Subtype_Declaration)
8754 and then Defining_Entity (Parent (Id)) = Id;
8755 end Itype_Has_Declaration;
8757 -------------------------
8758 -- Kill_Current_Values --
8759 -------------------------
8761 procedure Kill_Current_Values
8763 Last_Assignment_Only : Boolean := False)
8766 -- ??? do we have to worry about clearing cached checks?
8768 if Is_Assignable (Ent) then
8769 Set_Last_Assignment (Ent, Empty);
8772 if Is_Object (Ent) then
8773 if not Last_Assignment_Only then
8775 Set_Current_Value (Ent, Empty);
8777 if not Can_Never_Be_Null (Ent) then
8778 Set_Is_Known_Non_Null (Ent, False);
8781 Set_Is_Known_Null (Ent, False);
8783 -- Reset Is_Known_Valid unless type is always valid, or if we have
8784 -- a loop parameter (loop parameters are always valid, since their
8785 -- bounds are defined by the bounds given in the loop header).
8787 if not Is_Known_Valid (Etype (Ent))
8788 and then Ekind (Ent) /= E_Loop_Parameter
8790 Set_Is_Known_Valid (Ent, False);
8794 end Kill_Current_Values;
8796 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8799 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8800 -- Clear current value for entity E and all entities chained to E
8802 ------------------------------------------
8803 -- Kill_Current_Values_For_Entity_Chain --
8804 ------------------------------------------
8806 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8810 while Present (Ent) loop
8811 Kill_Current_Values (Ent, Last_Assignment_Only);
8814 end Kill_Current_Values_For_Entity_Chain;
8816 -- Start of processing for Kill_Current_Values
8819 -- Kill all saved checks, a special case of killing saved values
8821 if not Last_Assignment_Only then
8825 -- Loop through relevant scopes, which includes the current scope and
8826 -- any parent scopes if the current scope is a block or a package.
8831 -- Clear current values of all entities in current scope
8833 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8835 -- If scope is a package, also clear current values of all private
8836 -- entities in the scope.
8838 if Is_Package_Or_Generic_Package (S)
8839 or else Is_Concurrent_Type (S)
8841 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8844 -- If this is a not a subprogram, deal with parents
8846 if not Is_Subprogram (S) then
8848 exit Scope_Loop when S = Standard_Standard;
8852 end loop Scope_Loop;
8853 end Kill_Current_Values;
8855 --------------------------
8856 -- Kill_Size_Check_Code --
8857 --------------------------
8859 procedure Kill_Size_Check_Code (E : Entity_Id) is
8861 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8862 and then Present (Size_Check_Code (E))
8864 Remove (Size_Check_Code (E));
8865 Set_Size_Check_Code (E, Empty);
8867 end Kill_Size_Check_Code;
8869 --------------------------
8870 -- Known_To_Be_Assigned --
8871 --------------------------
8873 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8874 P : constant Node_Id := Parent (N);
8879 -- Test left side of assignment
8881 when N_Assignment_Statement =>
8882 return N = Name (P);
8884 -- Function call arguments are never lvalues
8886 when N_Function_Call =>
8889 -- Positional parameter for procedure or accept call
8891 when N_Procedure_Call_Statement |
8900 Proc := Get_Subprogram_Entity (P);
8906 -- If we are not a list member, something is strange, so
8907 -- be conservative and return False.
8909 if not Is_List_Member (N) then
8913 -- We are going to find the right formal by stepping forward
8914 -- through the formals, as we step backwards in the actuals.
8916 Form := First_Formal (Proc);
8919 -- If no formal, something is weird, so be conservative
8920 -- and return False.
8931 return Ekind (Form) /= E_In_Parameter;
8934 -- Named parameter for procedure or accept call
8936 when N_Parameter_Association =>
8942 Proc := Get_Subprogram_Entity (Parent (P));
8948 -- Loop through formals to find the one that matches
8950 Form := First_Formal (Proc);
8952 -- If no matching formal, that's peculiar, some kind of
8953 -- previous error, so return False to be conservative.
8959 -- Else test for match
8961 if Chars (Form) = Chars (Selector_Name (P)) then
8962 return Ekind (Form) /= E_In_Parameter;
8969 -- Test for appearing in a conversion that itself appears
8970 -- in an lvalue context, since this should be an lvalue.
8972 when N_Type_Conversion =>
8973 return Known_To_Be_Assigned (P);
8975 -- All other references are definitely not known to be modifications
8981 end Known_To_Be_Assigned;
8983 ---------------------------
8984 -- Last_Source_Statement --
8985 ---------------------------
8987 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8991 N := Last (Statements (HSS));
8992 while Present (N) loop
8993 exit when Comes_From_Source (N);
8998 end Last_Source_Statement;
9000 ----------------------------------
9001 -- Matching_Static_Array_Bounds --
9002 ----------------------------------
9004 function Matching_Static_Array_Bounds
9006 R_Typ : Node_Id) return Boolean
9008 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
9009 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
9021 if L_Ndims /= R_Ndims then
9025 -- Unconstrained types do not have static bounds
9027 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
9031 -- First treat specially the first dimension, as the lower bound and
9032 -- length of string literals are not stored like those of arrays.
9034 if Ekind (L_Typ) = E_String_Literal_Subtype then
9035 L_Low := String_Literal_Low_Bound (L_Typ);
9036 L_Len := String_Literal_Length (L_Typ);
9038 L_Index := First_Index (L_Typ);
9039 Get_Index_Bounds (L_Index, L_Low, L_High);
9041 if Is_OK_Static_Expression (L_Low)
9042 and then Is_OK_Static_Expression (L_High)
9044 if Expr_Value (L_High) < Expr_Value (L_Low) then
9047 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
9054 if Ekind (R_Typ) = E_String_Literal_Subtype then
9055 R_Low := String_Literal_Low_Bound (R_Typ);
9056 R_Len := String_Literal_Length (R_Typ);
9058 R_Index := First_Index (R_Typ);
9059 Get_Index_Bounds (R_Index, R_Low, R_High);
9061 if Is_OK_Static_Expression (R_Low)
9062 and then Is_OK_Static_Expression (R_High)
9064 if Expr_Value (R_High) < Expr_Value (R_Low) then
9067 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
9074 if Is_OK_Static_Expression (L_Low)
9075 and then Is_OK_Static_Expression (R_Low)
9076 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9077 and then L_Len = R_Len
9084 -- Then treat all other dimensions
9086 for Indx in 2 .. L_Ndims loop
9090 Get_Index_Bounds (L_Index, L_Low, L_High);
9091 Get_Index_Bounds (R_Index, R_Low, R_High);
9093 if Is_OK_Static_Expression (L_Low)
9094 and then Is_OK_Static_Expression (L_High)
9095 and then Is_OK_Static_Expression (R_Low)
9096 and then Is_OK_Static_Expression (R_High)
9097 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9098 and then Expr_Value (L_High) = Expr_Value (R_High)
9106 -- If we fall through the loop, all indexes matched
9109 end Matching_Static_Array_Bounds;
9115 function May_Be_Lvalue (N : Node_Id) return Boolean is
9116 P : constant Node_Id := Parent (N);
9121 -- Test left side of assignment
9123 when N_Assignment_Statement =>
9124 return N = Name (P);
9126 -- Test prefix of component or attribute. Note that the prefix of an
9127 -- explicit or implicit dereference cannot be an l-value.
9129 when N_Attribute_Reference =>
9130 return N = Prefix (P)
9131 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
9133 -- For an expanded name, the name is an lvalue if the expanded name
9134 -- is an lvalue, but the prefix is never an lvalue, since it is just
9135 -- the scope where the name is found.
9137 when N_Expanded_Name =>
9138 if N = Prefix (P) then
9139 return May_Be_Lvalue (P);
9144 -- For a selected component A.B, A is certainly an lvalue if A.B is.
9145 -- B is a little interesting, if we have A.B := 3, there is some
9146 -- discussion as to whether B is an lvalue or not, we choose to say
9147 -- it is. Note however that A is not an lvalue if it is of an access
9148 -- type since this is an implicit dereference.
9150 when N_Selected_Component =>
9152 and then Present (Etype (N))
9153 and then Is_Access_Type (Etype (N))
9157 return May_Be_Lvalue (P);
9160 -- For an indexed component or slice, the index or slice bounds is
9161 -- never an lvalue. The prefix is an lvalue if the indexed component
9162 -- or slice is an lvalue, except if it is an access type, where we
9163 -- have an implicit dereference.
9165 when N_Indexed_Component | N_Slice =>
9167 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
9171 return May_Be_Lvalue (P);
9174 -- Prefix of a reference is an lvalue if the reference is an lvalue
9177 return May_Be_Lvalue (P);
9179 -- Prefix of explicit dereference is never an lvalue
9181 when N_Explicit_Dereference =>
9184 -- Positional parameter for subprogram, entry, or accept call.
9185 -- In older versions of Ada function call arguments are never
9186 -- lvalues. In Ada 2012 functions can have in-out parameters.
9188 when N_Function_Call |
9189 N_Procedure_Call_Statement |
9190 N_Entry_Call_Statement |
9193 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
9197 -- The following mechanism is clumsy and fragile. A single flag
9198 -- set in Resolve_Actuals would be preferable ???
9206 Proc := Get_Subprogram_Entity (P);
9212 -- If we are not a list member, something is strange, so be
9213 -- conservative and return True.
9215 if not Is_List_Member (N) then
9219 -- We are going to find the right formal by stepping forward
9220 -- through the formals, as we step backwards in the actuals.
9222 Form := First_Formal (Proc);
9225 -- If no formal, something is weird, so be conservative and
9237 return Ekind (Form) /= E_In_Parameter;
9240 -- Named parameter for procedure or accept call
9242 when N_Parameter_Association =>
9248 Proc := Get_Subprogram_Entity (Parent (P));
9254 -- Loop through formals to find the one that matches
9256 Form := First_Formal (Proc);
9258 -- If no matching formal, that's peculiar, some kind of
9259 -- previous error, so return True to be conservative.
9265 -- Else test for match
9267 if Chars (Form) = Chars (Selector_Name (P)) then
9268 return Ekind (Form) /= E_In_Parameter;
9275 -- Test for appearing in a conversion that itself appears in an
9276 -- lvalue context, since this should be an lvalue.
9278 when N_Type_Conversion =>
9279 return May_Be_Lvalue (P);
9281 -- Test for appearance in object renaming declaration
9283 when N_Object_Renaming_Declaration =>
9286 -- All other references are definitely not lvalues
9294 -----------------------
9295 -- Mark_Coextensions --
9296 -----------------------
9298 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
9299 Is_Dynamic : Boolean;
9300 -- Indicates whether the context causes nested coextensions to be
9301 -- dynamic or static
9303 function Mark_Allocator (N : Node_Id) return Traverse_Result;
9304 -- Recognize an allocator node and label it as a dynamic coextension
9306 --------------------
9307 -- Mark_Allocator --
9308 --------------------
9310 function Mark_Allocator (N : Node_Id) return Traverse_Result is
9312 if Nkind (N) = N_Allocator then
9314 Set_Is_Dynamic_Coextension (N);
9316 -- If the allocator expression is potentially dynamic, it may
9317 -- be expanded out of order and require dynamic allocation
9318 -- anyway, so we treat the coextension itself as dynamic.
9319 -- Potential optimization ???
9321 elsif Nkind (Expression (N)) = N_Qualified_Expression
9322 and then Nkind (Expression (Expression (N))) = N_Op_Concat
9324 Set_Is_Dynamic_Coextension (N);
9327 Set_Is_Static_Coextension (N);
9334 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
9336 -- Start of processing Mark_Coextensions
9339 case Nkind (Context_Nod) is
9340 when N_Assignment_Statement |
9341 N_Simple_Return_Statement =>
9342 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
9344 when N_Object_Declaration =>
9345 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
9347 -- This routine should not be called for constructs which may not
9348 -- contain coextensions.
9351 raise Program_Error;
9354 Mark_Allocators (Root_Nod);
9355 end Mark_Coextensions;
9357 ----------------------
9358 -- Needs_One_Actual --
9359 ----------------------
9361 function Needs_One_Actual (E : Entity_Id) return Boolean is
9365 if Ada_Version >= Ada_2005
9366 and then Present (First_Formal (E))
9368 Formal := Next_Formal (First_Formal (E));
9369 while Present (Formal) loop
9370 if No (Default_Value (Formal)) then
9374 Next_Formal (Formal);
9382 end Needs_One_Actual;
9384 ------------------------
9385 -- New_Copy_List_Tree --
9386 ------------------------
9388 function New_Copy_List_Tree (List : List_Id) return List_Id is
9393 if List = No_List then
9400 while Present (E) loop
9401 Append (New_Copy_Tree (E), NL);
9407 end New_Copy_List_Tree;
9413 use Atree.Unchecked_Access;
9414 use Atree_Private_Part;
9416 -- Our approach here requires a two pass traversal of the tree. The
9417 -- first pass visits all nodes that eventually will be copied looking
9418 -- for defining Itypes. If any defining Itypes are found, then they are
9419 -- copied, and an entry is added to the replacement map. In the second
9420 -- phase, the tree is copied, using the replacement map to replace any
9421 -- Itype references within the copied tree.
9423 -- The following hash tables are used if the Map supplied has more
9424 -- than hash threshold entries to speed up access to the map. If
9425 -- there are fewer entries, then the map is searched sequentially
9426 -- (because setting up a hash table for only a few entries takes
9427 -- more time than it saves.
9429 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
9430 -- Hash function used for hash operations
9436 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
9438 return Nat (E) mod (NCT_Header_Num'Last + 1);
9445 -- The hash table NCT_Assoc associates old entities in the table
9446 -- with their corresponding new entities (i.e. the pairs of entries
9447 -- presented in the original Map argument are Key-Element pairs).
9449 package NCT_Assoc is new Simple_HTable (
9450 Header_Num => NCT_Header_Num,
9451 Element => Entity_Id,
9452 No_Element => Empty,
9454 Hash => New_Copy_Hash,
9455 Equal => Types."=");
9457 ---------------------
9458 -- NCT_Itype_Assoc --
9459 ---------------------
9461 -- The hash table NCT_Itype_Assoc contains entries only for those
9462 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9463 -- The key is the associated node, and the element is the new node
9464 -- itself (NOT the associated node for the new node).
9466 package NCT_Itype_Assoc is new Simple_HTable (
9467 Header_Num => NCT_Header_Num,
9468 Element => Entity_Id,
9469 No_Element => Empty,
9471 Hash => New_Copy_Hash,
9472 Equal => Types."=");
9474 -- Start of processing for New_Copy_Tree function
9476 function New_Copy_Tree
9478 Map : Elist_Id := No_Elist;
9479 New_Sloc : Source_Ptr := No_Location;
9480 New_Scope : Entity_Id := Empty) return Node_Id
9482 Actual_Map : Elist_Id := Map;
9483 -- This is the actual map for the copy. It is initialized with the
9484 -- given elements, and then enlarged as required for Itypes that are
9485 -- copied during the first phase of the copy operation. The visit
9486 -- procedures add elements to this map as Itypes are encountered.
9487 -- The reason we cannot use Map directly, is that it may well be
9488 -- (and normally is) initialized to No_Elist, and if we have mapped
9489 -- entities, we have to reset it to point to a real Elist.
9491 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9492 -- Called during second phase to map entities into their corresponding
9493 -- copies using Actual_Map. If the argument is not an entity, or is not
9494 -- in Actual_Map, then it is returned unchanged.
9496 procedure Build_NCT_Hash_Tables;
9497 -- Builds hash tables (number of elements >= threshold value)
9499 function Copy_Elist_With_Replacement
9500 (Old_Elist : Elist_Id) return Elist_Id;
9501 -- Called during second phase to copy element list doing replacements
9503 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9504 -- Called during the second phase to process a copied Itype. The actual
9505 -- copy happened during the first phase (so that we could make the entry
9506 -- in the mapping), but we still have to deal with the descendents of
9507 -- the copied Itype and copy them where necessary.
9509 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9510 -- Called during second phase to copy list doing replacements
9512 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9513 -- Called during second phase to copy node doing replacements
9515 procedure Visit_Elist (E : Elist_Id);
9516 -- Called during first phase to visit all elements of an Elist
9518 procedure Visit_Field (F : Union_Id; N : Node_Id);
9519 -- Visit a single field, recursing to call Visit_Node or Visit_List
9520 -- if the field is a syntactic descendent of the current node (i.e.
9521 -- its parent is Node N).
9523 procedure Visit_Itype (Old_Itype : Entity_Id);
9524 -- Called during first phase to visit subsidiary fields of a defining
9525 -- Itype, and also create a copy and make an entry in the replacement
9526 -- map for the new copy.
9528 procedure Visit_List (L : List_Id);
9529 -- Called during first phase to visit all elements of a List
9531 procedure Visit_Node (N : Node_Or_Entity_Id);
9532 -- Called during first phase to visit a node and all its subtrees
9538 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9543 if not Has_Extension (N) or else No (Actual_Map) then
9546 elsif NCT_Hash_Tables_Used then
9547 Ent := NCT_Assoc.Get (Entity_Id (N));
9549 if Present (Ent) then
9555 -- No hash table used, do serial search
9558 E := First_Elmt (Actual_Map);
9559 while Present (E) loop
9560 if Node (E) = N then
9561 return Node (Next_Elmt (E));
9563 E := Next_Elmt (Next_Elmt (E));
9571 ---------------------------
9572 -- Build_NCT_Hash_Tables --
9573 ---------------------------
9575 procedure Build_NCT_Hash_Tables is
9579 if NCT_Hash_Table_Setup then
9581 NCT_Itype_Assoc.Reset;
9584 Elmt := First_Elmt (Actual_Map);
9585 while Present (Elmt) loop
9588 -- Get new entity, and associate old and new
9591 NCT_Assoc.Set (Ent, Node (Elmt));
9593 if Is_Type (Ent) then
9595 Anode : constant Entity_Id :=
9596 Associated_Node_For_Itype (Ent);
9599 if Present (Anode) then
9601 -- Enter a link between the associated node of the
9602 -- old Itype and the new Itype, for updating later
9603 -- when node is copied.
9605 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9613 NCT_Hash_Tables_Used := True;
9614 NCT_Hash_Table_Setup := True;
9615 end Build_NCT_Hash_Tables;
9617 ---------------------------------
9618 -- Copy_Elist_With_Replacement --
9619 ---------------------------------
9621 function Copy_Elist_With_Replacement
9622 (Old_Elist : Elist_Id) return Elist_Id
9625 New_Elist : Elist_Id;
9628 if No (Old_Elist) then
9632 New_Elist := New_Elmt_List;
9634 M := First_Elmt (Old_Elist);
9635 while Present (M) loop
9636 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9642 end Copy_Elist_With_Replacement;
9644 ---------------------------------
9645 -- Copy_Itype_With_Replacement --
9646 ---------------------------------
9648 -- This routine exactly parallels its phase one analog Visit_Itype,
9650 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9652 -- Translate Next_Entity, Scope and Etype fields, in case they
9653 -- reference entities that have been mapped into copies.
9655 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9656 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9658 if Present (New_Scope) then
9659 Set_Scope (New_Itype, New_Scope);
9661 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9664 -- Copy referenced fields
9666 if Is_Discrete_Type (New_Itype) then
9667 Set_Scalar_Range (New_Itype,
9668 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9670 elsif Has_Discriminants (Base_Type (New_Itype)) then
9671 Set_Discriminant_Constraint (New_Itype,
9672 Copy_Elist_With_Replacement
9673 (Discriminant_Constraint (New_Itype)));
9675 elsif Is_Array_Type (New_Itype) then
9676 if Present (First_Index (New_Itype)) then
9677 Set_First_Index (New_Itype,
9678 First (Copy_List_With_Replacement
9679 (List_Containing (First_Index (New_Itype)))));
9682 if Is_Packed (New_Itype) then
9683 Set_Packed_Array_Type (New_Itype,
9684 Copy_Node_With_Replacement
9685 (Packed_Array_Type (New_Itype)));
9688 end Copy_Itype_With_Replacement;
9690 --------------------------------
9691 -- Copy_List_With_Replacement --
9692 --------------------------------
9694 function Copy_List_With_Replacement
9695 (Old_List : List_Id) return List_Id
9701 if Old_List = No_List then
9705 New_List := Empty_List;
9707 E := First (Old_List);
9708 while Present (E) loop
9709 Append (Copy_Node_With_Replacement (E), New_List);
9715 end Copy_List_With_Replacement;
9717 --------------------------------
9718 -- Copy_Node_With_Replacement --
9719 --------------------------------
9721 function Copy_Node_With_Replacement
9722 (Old_Node : Node_Id) return Node_Id
9726 procedure Adjust_Named_Associations
9727 (Old_Node : Node_Id;
9728 New_Node : Node_Id);
9729 -- If a call node has named associations, these are chained through
9730 -- the First_Named_Actual, Next_Named_Actual links. These must be
9731 -- propagated separately to the new parameter list, because these
9732 -- are not syntactic fields.
9734 function Copy_Field_With_Replacement
9735 (Field : Union_Id) return Union_Id;
9736 -- Given Field, which is a field of Old_Node, return a copy of it
9737 -- if it is a syntactic field (i.e. its parent is Node), setting
9738 -- the parent of the copy to poit to New_Node. Otherwise returns
9739 -- the field (possibly mapped if it is an entity).
9741 -------------------------------
9742 -- Adjust_Named_Associations --
9743 -------------------------------
9745 procedure Adjust_Named_Associations
9746 (Old_Node : Node_Id;
9756 Old_E := First (Parameter_Associations (Old_Node));
9757 New_E := First (Parameter_Associations (New_Node));
9758 while Present (Old_E) loop
9759 if Nkind (Old_E) = N_Parameter_Association
9760 and then Present (Next_Named_Actual (Old_E))
9762 if First_Named_Actual (Old_Node)
9763 = Explicit_Actual_Parameter (Old_E)
9765 Set_First_Named_Actual
9766 (New_Node, Explicit_Actual_Parameter (New_E));
9769 -- Now scan parameter list from the beginning,to locate
9770 -- next named actual, which can be out of order.
9772 Old_Next := First (Parameter_Associations (Old_Node));
9773 New_Next := First (Parameter_Associations (New_Node));
9775 while Nkind (Old_Next) /= N_Parameter_Association
9776 or else Explicit_Actual_Parameter (Old_Next)
9777 /= Next_Named_Actual (Old_E)
9783 Set_Next_Named_Actual
9784 (New_E, Explicit_Actual_Parameter (New_Next));
9790 end Adjust_Named_Associations;
9792 ---------------------------------
9793 -- Copy_Field_With_Replacement --
9794 ---------------------------------
9796 function Copy_Field_With_Replacement
9797 (Field : Union_Id) return Union_Id
9800 if Field = Union_Id (Empty) then
9803 elsif Field in Node_Range then
9805 Old_N : constant Node_Id := Node_Id (Field);
9809 -- If syntactic field, as indicated by the parent pointer
9810 -- being set, then copy the referenced node recursively.
9812 if Parent (Old_N) = Old_Node then
9813 New_N := Copy_Node_With_Replacement (Old_N);
9815 if New_N /= Old_N then
9816 Set_Parent (New_N, New_Node);
9819 -- For semantic fields, update possible entity reference
9820 -- from the replacement map.
9823 New_N := Assoc (Old_N);
9826 return Union_Id (New_N);
9829 elsif Field in List_Range then
9831 Old_L : constant List_Id := List_Id (Field);
9835 -- If syntactic field, as indicated by the parent pointer,
9836 -- then recursively copy the entire referenced list.
9838 if Parent (Old_L) = Old_Node then
9839 New_L := Copy_List_With_Replacement (Old_L);
9840 Set_Parent (New_L, New_Node);
9842 -- For semantic list, just returned unchanged
9848 return Union_Id (New_L);
9851 -- Anything other than a list or a node is returned unchanged
9856 end Copy_Field_With_Replacement;
9858 -- Start of processing for Copy_Node_With_Replacement
9861 if Old_Node <= Empty_Or_Error then
9864 elsif Has_Extension (Old_Node) then
9865 return Assoc (Old_Node);
9868 New_Node := New_Copy (Old_Node);
9870 -- If the node we are copying is the associated node of a
9871 -- previously copied Itype, then adjust the associated node
9872 -- of the copy of that Itype accordingly.
9874 if Present (Actual_Map) then
9880 -- Case of hash table used
9882 if NCT_Hash_Tables_Used then
9883 Ent := NCT_Itype_Assoc.Get (Old_Node);
9885 if Present (Ent) then
9886 Set_Associated_Node_For_Itype (Ent, New_Node);
9889 -- Case of no hash table used
9892 E := First_Elmt (Actual_Map);
9893 while Present (E) loop
9894 if Is_Itype (Node (E))
9896 Old_Node = Associated_Node_For_Itype (Node (E))
9898 Set_Associated_Node_For_Itype
9899 (Node (Next_Elmt (E)), New_Node);
9902 E := Next_Elmt (Next_Elmt (E));
9908 -- Recursively copy descendents
9911 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9913 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9915 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9917 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9919 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9921 -- Adjust Sloc of new node if necessary
9923 if New_Sloc /= No_Location then
9924 Set_Sloc (New_Node, New_Sloc);
9926 -- If we adjust the Sloc, then we are essentially making
9927 -- a completely new node, so the Comes_From_Source flag
9928 -- should be reset to the proper default value.
9930 Nodes.Table (New_Node).Comes_From_Source :=
9931 Default_Node.Comes_From_Source;
9934 -- If the node is call and has named associations,
9935 -- set the corresponding links in the copy.
9937 if (Nkind (Old_Node) = N_Function_Call
9938 or else Nkind (Old_Node) = N_Entry_Call_Statement
9940 Nkind (Old_Node) = N_Procedure_Call_Statement)
9941 and then Present (First_Named_Actual (Old_Node))
9943 Adjust_Named_Associations (Old_Node, New_Node);
9946 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9947 -- The replacement mechanism applies to entities, and is not used
9948 -- here. Eventually we may need a more general graph-copying
9949 -- routine. For now, do a sequential search to find desired node.
9951 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9952 and then Present (First_Real_Statement (Old_Node))
9955 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9959 N1 := First (Statements (Old_Node));
9960 N2 := First (Statements (New_Node));
9962 while N1 /= Old_F loop
9967 Set_First_Real_Statement (New_Node, N2);
9972 -- All done, return copied node
9975 end Copy_Node_With_Replacement;
9981 procedure Visit_Elist (E : Elist_Id) is
9985 Elmt := First_Elmt (E);
9987 while Elmt /= No_Elmt loop
9988 Visit_Node (Node (Elmt));
9998 procedure Visit_Field (F : Union_Id; N : Node_Id) is
10000 if F = Union_Id (Empty) then
10003 elsif F in Node_Range then
10005 -- Copy node if it is syntactic, i.e. its parent pointer is
10006 -- set to point to the field that referenced it (certain
10007 -- Itypes will also meet this criterion, which is fine, since
10008 -- these are clearly Itypes that do need to be copied, since
10009 -- we are copying their parent.)
10011 if Parent (Node_Id (F)) = N then
10012 Visit_Node (Node_Id (F));
10015 -- Another case, if we are pointing to an Itype, then we want
10016 -- to copy it if its associated node is somewhere in the tree
10019 -- Note: the exclusion of self-referential copies is just an
10020 -- optimization, since the search of the already copied list
10021 -- would catch it, but it is a common case (Etype pointing
10022 -- to itself for an Itype that is a base type).
10024 elsif Has_Extension (Node_Id (F))
10025 and then Is_Itype (Entity_Id (F))
10026 and then Node_Id (F) /= N
10032 P := Associated_Node_For_Itype (Node_Id (F));
10033 while Present (P) loop
10035 Visit_Node (Node_Id (F));
10042 -- An Itype whose parent is not being copied definitely
10043 -- should NOT be copied, since it does not belong in any
10044 -- sense to the copied subtree.
10050 elsif F in List_Range
10051 and then Parent (List_Id (F)) = N
10053 Visit_List (List_Id (F));
10062 procedure Visit_Itype (Old_Itype : Entity_Id) is
10063 New_Itype : Entity_Id;
10068 -- Itypes that describe the designated type of access to subprograms
10069 -- have the structure of subprogram declarations, with signatures,
10070 -- etc. Either we duplicate the signatures completely, or choose to
10071 -- share such itypes, which is fine because their elaboration will
10072 -- have no side effects.
10074 if Ekind (Old_Itype) = E_Subprogram_Type then
10078 New_Itype := New_Copy (Old_Itype);
10080 -- The new Itype has all the attributes of the old one, and
10081 -- we just copy the contents of the entity. However, the back-end
10082 -- needs different names for debugging purposes, so we create a
10083 -- new internal name for it in all cases.
10085 Set_Chars (New_Itype, New_Internal_Name ('T'));
10087 -- If our associated node is an entity that has already been copied,
10088 -- then set the associated node of the copy to point to the right
10089 -- copy. If we have copied an Itype that is itself the associated
10090 -- node of some previously copied Itype, then we set the right
10091 -- pointer in the other direction.
10093 if Present (Actual_Map) then
10095 -- Case of hash tables used
10097 if NCT_Hash_Tables_Used then
10099 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
10101 if Present (Ent) then
10102 Set_Associated_Node_For_Itype (New_Itype, Ent);
10105 Ent := NCT_Itype_Assoc.Get (Old_Itype);
10106 if Present (Ent) then
10107 Set_Associated_Node_For_Itype (Ent, New_Itype);
10109 -- If the hash table has no association for this Itype and
10110 -- its associated node, enter one now.
10113 NCT_Itype_Assoc.Set
10114 (Associated_Node_For_Itype (Old_Itype), New_Itype);
10117 -- Case of hash tables not used
10120 E := First_Elmt (Actual_Map);
10121 while Present (E) loop
10122 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
10123 Set_Associated_Node_For_Itype
10124 (New_Itype, Node (Next_Elmt (E)));
10127 if Is_Type (Node (E))
10129 Old_Itype = Associated_Node_For_Itype (Node (E))
10131 Set_Associated_Node_For_Itype
10132 (Node (Next_Elmt (E)), New_Itype);
10135 E := Next_Elmt (Next_Elmt (E));
10140 if Present (Freeze_Node (New_Itype)) then
10141 Set_Is_Frozen (New_Itype, False);
10142 Set_Freeze_Node (New_Itype, Empty);
10145 -- Add new association to map
10147 if No (Actual_Map) then
10148 Actual_Map := New_Elmt_List;
10151 Append_Elmt (Old_Itype, Actual_Map);
10152 Append_Elmt (New_Itype, Actual_Map);
10154 if NCT_Hash_Tables_Used then
10155 NCT_Assoc.Set (Old_Itype, New_Itype);
10158 NCT_Table_Entries := NCT_Table_Entries + 1;
10160 if NCT_Table_Entries > NCT_Hash_Threshold then
10161 Build_NCT_Hash_Tables;
10165 -- If a record subtype is simply copied, the entity list will be
10166 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
10168 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
10169 Set_Cloned_Subtype (New_Itype, Old_Itype);
10172 -- Visit descendents that eventually get copied
10174 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
10176 if Is_Discrete_Type (Old_Itype) then
10177 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
10179 elsif Has_Discriminants (Base_Type (Old_Itype)) then
10180 -- ??? This should involve call to Visit_Field
10181 Visit_Elist (Discriminant_Constraint (Old_Itype));
10183 elsif Is_Array_Type (Old_Itype) then
10184 if Present (First_Index (Old_Itype)) then
10185 Visit_Field (Union_Id (List_Containing
10186 (First_Index (Old_Itype))),
10190 if Is_Packed (Old_Itype) then
10191 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
10201 procedure Visit_List (L : List_Id) is
10204 if L /= No_List then
10207 while Present (N) loop
10218 procedure Visit_Node (N : Node_Or_Entity_Id) is
10220 -- Start of processing for Visit_Node
10223 -- Handle case of an Itype, which must be copied
10225 if Has_Extension (N)
10226 and then Is_Itype (N)
10228 -- Nothing to do if already in the list. This can happen with an
10229 -- Itype entity that appears more than once in the tree.
10230 -- Note that we do not want to visit descendents in this case.
10232 -- Test for already in list when hash table is used
10234 if NCT_Hash_Tables_Used then
10235 if Present (NCT_Assoc.Get (Entity_Id (N))) then
10239 -- Test for already in list when hash table not used
10245 if Present (Actual_Map) then
10246 E := First_Elmt (Actual_Map);
10247 while Present (E) loop
10248 if Node (E) = N then
10251 E := Next_Elmt (Next_Elmt (E));
10261 -- Visit descendents
10263 Visit_Field (Field1 (N), N);
10264 Visit_Field (Field2 (N), N);
10265 Visit_Field (Field3 (N), N);
10266 Visit_Field (Field4 (N), N);
10267 Visit_Field (Field5 (N), N);
10270 -- Start of processing for New_Copy_Tree
10275 -- See if we should use hash table
10277 if No (Actual_Map) then
10278 NCT_Hash_Tables_Used := False;
10285 NCT_Table_Entries := 0;
10287 Elmt := First_Elmt (Actual_Map);
10288 while Present (Elmt) loop
10289 NCT_Table_Entries := NCT_Table_Entries + 1;
10294 if NCT_Table_Entries > NCT_Hash_Threshold then
10295 Build_NCT_Hash_Tables;
10297 NCT_Hash_Tables_Used := False;
10302 -- Hash table set up if required, now start phase one by visiting
10303 -- top node (we will recursively visit the descendents).
10305 Visit_Node (Source);
10307 -- Now the second phase of the copy can start. First we process
10308 -- all the mapped entities, copying their descendents.
10310 if Present (Actual_Map) then
10313 New_Itype : Entity_Id;
10315 Elmt := First_Elmt (Actual_Map);
10316 while Present (Elmt) loop
10318 New_Itype := Node (Elmt);
10319 Copy_Itype_With_Replacement (New_Itype);
10325 -- Now we can copy the actual tree
10327 return Copy_Node_With_Replacement (Source);
10330 -------------------------
10331 -- New_External_Entity --
10332 -------------------------
10334 function New_External_Entity
10335 (Kind : Entity_Kind;
10336 Scope_Id : Entity_Id;
10337 Sloc_Value : Source_Ptr;
10338 Related_Id : Entity_Id;
10339 Suffix : Character;
10340 Suffix_Index : Nat := 0;
10341 Prefix : Character := ' ') return Entity_Id
10343 N : constant Entity_Id :=
10344 Make_Defining_Identifier (Sloc_Value,
10346 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
10349 Set_Ekind (N, Kind);
10350 Set_Is_Internal (N, True);
10351 Append_Entity (N, Scope_Id);
10352 Set_Public_Status (N);
10354 if Kind in Type_Kind then
10355 Init_Size_Align (N);
10359 end New_External_Entity;
10361 -------------------------
10362 -- New_Internal_Entity --
10363 -------------------------
10365 function New_Internal_Entity
10366 (Kind : Entity_Kind;
10367 Scope_Id : Entity_Id;
10368 Sloc_Value : Source_Ptr;
10369 Id_Char : Character) return Entity_Id
10371 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
10374 Set_Ekind (N, Kind);
10375 Set_Is_Internal (N, True);
10376 Append_Entity (N, Scope_Id);
10378 if Kind in Type_Kind then
10379 Init_Size_Align (N);
10383 end New_Internal_Entity;
10389 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
10393 -- If we are pointing at a positional parameter, it is a member of a
10394 -- node list (the list of parameters), and the next parameter is the
10395 -- next node on the list, unless we hit a parameter association, then
10396 -- we shift to using the chain whose head is the First_Named_Actual in
10397 -- the parent, and then is threaded using the Next_Named_Actual of the
10398 -- Parameter_Association. All this fiddling is because the original node
10399 -- list is in the textual call order, and what we need is the
10400 -- declaration order.
10402 if Is_List_Member (Actual_Id) then
10403 N := Next (Actual_Id);
10405 if Nkind (N) = N_Parameter_Association then
10406 return First_Named_Actual (Parent (Actual_Id));
10412 return Next_Named_Actual (Parent (Actual_Id));
10416 procedure Next_Actual (Actual_Id : in out Node_Id) is
10418 Actual_Id := Next_Actual (Actual_Id);
10421 -----------------------
10422 -- Normalize_Actuals --
10423 -----------------------
10425 -- Chain actuals according to formals of subprogram. If there are no named
10426 -- associations, the chain is simply the list of Parameter Associations,
10427 -- since the order is the same as the declaration order. If there are named
10428 -- associations, then the First_Named_Actual field in the N_Function_Call
10429 -- or N_Procedure_Call_Statement node points to the Parameter_Association
10430 -- node for the parameter that comes first in declaration order. The
10431 -- remaining named parameters are then chained in declaration order using
10432 -- Next_Named_Actual.
10434 -- This routine also verifies that the number of actuals is compatible with
10435 -- the number and default values of formals, but performs no type checking
10436 -- (type checking is done by the caller).
10438 -- If the matching succeeds, Success is set to True and the caller proceeds
10439 -- with type-checking. If the match is unsuccessful, then Success is set to
10440 -- False, and the caller attempts a different interpretation, if there is
10443 -- If the flag Report is on, the call is not overloaded, and a failure to
10444 -- match can be reported here, rather than in the caller.
10446 procedure Normalize_Actuals
10450 Success : out Boolean)
10452 Actuals : constant List_Id := Parameter_Associations (N);
10453 Actual : Node_Id := Empty;
10454 Formal : Entity_Id;
10455 Last : Node_Id := Empty;
10456 First_Named : Node_Id := Empty;
10459 Formals_To_Match : Integer := 0;
10460 Actuals_To_Match : Integer := 0;
10462 procedure Chain (A : Node_Id);
10463 -- Add named actual at the proper place in the list, using the
10464 -- Next_Named_Actual link.
10466 function Reporting return Boolean;
10467 -- Determines if an error is to be reported. To report an error, we
10468 -- need Report to be True, and also we do not report errors caused
10469 -- by calls to init procs that occur within other init procs. Such
10470 -- errors must always be cascaded errors, since if all the types are
10471 -- declared correctly, the compiler will certainly build decent calls!
10477 procedure Chain (A : Node_Id) is
10481 -- Call node points to first actual in list
10483 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10486 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10490 Set_Next_Named_Actual (Last, Empty);
10497 function Reporting return Boolean is
10502 elsif not Within_Init_Proc then
10505 elsif Is_Init_Proc (Entity (Name (N))) then
10513 -- Start of processing for Normalize_Actuals
10516 if Is_Access_Type (S) then
10518 -- The name in the call is a function call that returns an access
10519 -- to subprogram. The designated type has the list of formals.
10521 Formal := First_Formal (Designated_Type (S));
10523 Formal := First_Formal (S);
10526 while Present (Formal) loop
10527 Formals_To_Match := Formals_To_Match + 1;
10528 Next_Formal (Formal);
10531 -- Find if there is a named association, and verify that no positional
10532 -- associations appear after named ones.
10534 if Present (Actuals) then
10535 Actual := First (Actuals);
10538 while Present (Actual)
10539 and then Nkind (Actual) /= N_Parameter_Association
10541 Actuals_To_Match := Actuals_To_Match + 1;
10545 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10547 -- Most common case: positional notation, no defaults
10552 elsif Actuals_To_Match > Formals_To_Match then
10554 -- Too many actuals: will not work
10557 if Is_Entity_Name (Name (N)) then
10558 Error_Msg_N ("too many arguments in call to&", Name (N));
10560 Error_Msg_N ("too many arguments in call", N);
10568 First_Named := Actual;
10570 while Present (Actual) loop
10571 if Nkind (Actual) /= N_Parameter_Association then
10573 ("positional parameters not allowed after named ones", Actual);
10578 Actuals_To_Match := Actuals_To_Match + 1;
10584 if Present (Actuals) then
10585 Actual := First (Actuals);
10588 Formal := First_Formal (S);
10589 while Present (Formal) loop
10591 -- Match the formals in order. If the corresponding actual is
10592 -- positional, nothing to do. Else scan the list of named actuals
10593 -- to find the one with the right name.
10595 if Present (Actual)
10596 and then Nkind (Actual) /= N_Parameter_Association
10599 Actuals_To_Match := Actuals_To_Match - 1;
10600 Formals_To_Match := Formals_To_Match - 1;
10603 -- For named parameters, search the list of actuals to find
10604 -- one that matches the next formal name.
10606 Actual := First_Named;
10608 while Present (Actual) loop
10609 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10612 Actuals_To_Match := Actuals_To_Match - 1;
10613 Formals_To_Match := Formals_To_Match - 1;
10621 if Ekind (Formal) /= E_In_Parameter
10622 or else No (Default_Value (Formal))
10625 if (Comes_From_Source (S)
10626 or else Sloc (S) = Standard_Location)
10627 and then Is_Overloadable (S)
10631 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10633 (Nkind (Parent (N)) = N_Function_Call
10635 Nkind (Parent (N)) = N_Parameter_Association))
10636 and then Ekind (S) /= E_Function
10638 Set_Etype (N, Etype (S));
10640 Error_Msg_Name_1 := Chars (S);
10641 Error_Msg_Sloc := Sloc (S);
10643 ("missing argument for parameter & " &
10644 "in call to % declared #", N, Formal);
10647 elsif Is_Overloadable (S) then
10648 Error_Msg_Name_1 := Chars (S);
10650 -- Point to type derivation that generated the
10653 Error_Msg_Sloc := Sloc (Parent (S));
10656 ("missing argument for parameter & " &
10657 "in call to % (inherited) #", N, Formal);
10661 ("missing argument for parameter &", N, Formal);
10669 Formals_To_Match := Formals_To_Match - 1;
10674 Next_Formal (Formal);
10677 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10684 -- Find some superfluous named actual that did not get
10685 -- attached to the list of associations.
10687 Actual := First (Actuals);
10688 while Present (Actual) loop
10689 if Nkind (Actual) = N_Parameter_Association
10690 and then Actual /= Last
10691 and then No (Next_Named_Actual (Actual))
10693 Error_Msg_N ("unmatched actual & in call",
10694 Selector_Name (Actual));
10705 end Normalize_Actuals;
10707 --------------------------------
10708 -- Note_Possible_Modification --
10709 --------------------------------
10711 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10712 Modification_Comes_From_Source : constant Boolean :=
10713 Comes_From_Source (Parent (N));
10719 -- Loop to find referenced entity, if there is one
10726 if Is_Entity_Name (Exp) then
10727 Ent := Entity (Exp);
10729 -- If the entity is missing, it is an undeclared identifier,
10730 -- and there is nothing to annotate.
10736 elsif Nkind (Exp) = N_Explicit_Dereference then
10738 P : constant Node_Id := Prefix (Exp);
10741 -- In formal verification mode, keep track of all reads and
10742 -- writes through explicit dereferences.
10745 Alfa.Generate_Dereference (N, 'm');
10748 if Nkind (P) = N_Selected_Component
10750 Entry_Formal (Entity (Selector_Name (P))))
10752 -- Case of a reference to an entry formal
10754 Ent := Entry_Formal (Entity (Selector_Name (P)));
10756 elsif Nkind (P) = N_Identifier
10757 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10758 and then Present (Expression (Parent (Entity (P))))
10759 and then Nkind (Expression (Parent (Entity (P))))
10762 -- Case of a reference to a value on which side effects have
10765 Exp := Prefix (Expression (Parent (Entity (P))));
10774 elsif Nkind (Exp) = N_Type_Conversion
10775 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10777 Exp := Expression (Exp);
10780 elsif Nkind (Exp) = N_Slice
10781 or else Nkind (Exp) = N_Indexed_Component
10782 or else Nkind (Exp) = N_Selected_Component
10784 Exp := Prefix (Exp);
10791 -- Now look for entity being referenced
10793 if Present (Ent) then
10794 if Is_Object (Ent) then
10795 if Comes_From_Source (Exp)
10796 or else Modification_Comes_From_Source
10798 -- Give warning if pragma unmodified given and we are
10799 -- sure this is a modification.
10801 if Has_Pragma_Unmodified (Ent) and then Sure then
10802 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10805 Set_Never_Set_In_Source (Ent, False);
10808 Set_Is_True_Constant (Ent, False);
10809 Set_Current_Value (Ent, Empty);
10810 Set_Is_Known_Null (Ent, False);
10812 if not Can_Never_Be_Null (Ent) then
10813 Set_Is_Known_Non_Null (Ent, False);
10816 -- Follow renaming chain
10818 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10819 and then Present (Renamed_Object (Ent))
10821 Exp := Renamed_Object (Ent);
10824 -- The expression may be the renaming of a subcomponent of an
10825 -- array or container. The assignment to the subcomponent is
10826 -- a modification of the container.
10828 elsif Comes_From_Source (Original_Node (Exp))
10829 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
10830 N_Indexed_Component)
10832 Exp := Prefix (Original_Node (Exp));
10836 -- Generate a reference only if the assignment comes from
10837 -- source. This excludes, for example, calls to a dispatching
10838 -- assignment operation when the left-hand side is tagged.
10840 if Modification_Comes_From_Source then
10841 Generate_Reference (Ent, Exp, 'm');
10843 -- If the target of the assignment is the bound variable
10844 -- in an iterator, indicate that the corresponding array
10845 -- or container is also modified.
10847 if Ada_Version >= Ada_2012
10849 Nkind (Parent (Ent)) = N_Iterator_Specification
10852 Domain : constant Node_Id := Name (Parent (Ent));
10855 -- TBD : in the full version of the construct, the
10856 -- domain of iteration can be given by an expression.
10858 if Is_Entity_Name (Domain) then
10859 Generate_Reference (Entity (Domain), Exp, 'm');
10860 Set_Is_True_Constant (Entity (Domain), False);
10861 Set_Never_Set_In_Source (Entity (Domain), False);
10867 Check_Nested_Access (Ent);
10872 -- If we are sure this is a modification from source, and we know
10873 -- this modifies a constant, then give an appropriate warning.
10875 if Overlays_Constant (Ent)
10876 and then Modification_Comes_From_Source
10880 A : constant Node_Id := Address_Clause (Ent);
10882 if Present (A) then
10884 Exp : constant Node_Id := Expression (A);
10886 if Nkind (Exp) = N_Attribute_Reference
10887 and then Attribute_Name (Exp) = Name_Address
10888 and then Is_Entity_Name (Prefix (Exp))
10890 Error_Msg_Sloc := Sloc (A);
10892 ("constant& may be modified via address clause#?",
10893 N, Entity (Prefix (Exp)));
10903 end Note_Possible_Modification;
10905 -------------------------
10906 -- Object_Access_Level --
10907 -------------------------
10909 function Object_Access_Level (Obj : Node_Id) return Uint is
10912 -- Returns the static accessibility level of the view denoted by Obj. Note
10913 -- that the value returned is the result of a call to Scope_Depth. Only
10914 -- scope depths associated with dynamic scopes can actually be returned.
10915 -- Since only relative levels matter for accessibility checking, the fact
10916 -- that the distance between successive levels of accessibility is not
10917 -- always one is immaterial (invariant: if level(E2) is deeper than
10918 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10920 function Reference_To (Obj : Node_Id) return Node_Id;
10921 -- An explicit dereference is created when removing side-effects from
10922 -- expressions for constraint checking purposes. In this case a local
10923 -- access type is created for it. The correct access level is that of
10924 -- the original source node. We detect this case by noting that the
10925 -- prefix of the dereference is created by an object declaration whose
10926 -- initial expression is a reference.
10932 function Reference_To (Obj : Node_Id) return Node_Id is
10933 Pref : constant Node_Id := Prefix (Obj);
10935 if Is_Entity_Name (Pref)
10936 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10937 and then Present (Expression (Parent (Entity (Pref))))
10938 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10940 return (Prefix (Expression (Parent (Entity (Pref)))));
10946 -- Start of processing for Object_Access_Level
10949 if Nkind (Obj) = N_Defining_Identifier
10950 or else Is_Entity_Name (Obj)
10952 if Nkind (Obj) = N_Defining_Identifier then
10958 if Is_Prival (E) then
10959 E := Prival_Link (E);
10962 -- If E is a type then it denotes a current instance. For this case
10963 -- we add one to the normal accessibility level of the type to ensure
10964 -- that current instances are treated as always being deeper than
10965 -- than the level of any visible named access type (see 3.10.2(21)).
10967 if Is_Type (E) then
10968 return Type_Access_Level (E) + 1;
10970 elsif Present (Renamed_Object (E)) then
10971 return Object_Access_Level (Renamed_Object (E));
10973 -- Similarly, if E is a component of the current instance of a
10974 -- protected type, any instance of it is assumed to be at a deeper
10975 -- level than the type. For a protected object (whose type is an
10976 -- anonymous protected type) its components are at the same level
10977 -- as the type itself.
10979 elsif not Is_Overloadable (E)
10980 and then Ekind (Scope (E)) = E_Protected_Type
10981 and then Comes_From_Source (Scope (E))
10983 return Type_Access_Level (Scope (E)) + 1;
10986 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10989 elsif Nkind (Obj) = N_Selected_Component then
10990 if Is_Access_Type (Etype (Prefix (Obj))) then
10991 return Type_Access_Level (Etype (Prefix (Obj)));
10993 return Object_Access_Level (Prefix (Obj));
10996 elsif Nkind (Obj) = N_Indexed_Component then
10997 if Is_Access_Type (Etype (Prefix (Obj))) then
10998 return Type_Access_Level (Etype (Prefix (Obj)));
11000 return Object_Access_Level (Prefix (Obj));
11003 elsif Nkind (Obj) = N_Explicit_Dereference then
11005 -- If the prefix is a selected access discriminant then we make a
11006 -- recursive call on the prefix, which will in turn check the level
11007 -- of the prefix object of the selected discriminant.
11009 if Nkind (Prefix (Obj)) = N_Selected_Component
11010 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
11012 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
11014 return Object_Access_Level (Prefix (Obj));
11016 elsif not (Comes_From_Source (Obj)) then
11018 Ref : constant Node_Id := Reference_To (Obj);
11020 if Present (Ref) then
11021 return Object_Access_Level (Ref);
11023 return Type_Access_Level (Etype (Prefix (Obj)));
11028 return Type_Access_Level (Etype (Prefix (Obj)));
11031 elsif Nkind (Obj) = N_Type_Conversion
11032 or else Nkind (Obj) = N_Unchecked_Type_Conversion
11034 return Object_Access_Level (Expression (Obj));
11036 elsif Nkind (Obj) = N_Function_Call then
11038 -- Function results are objects, so we get either the access level of
11039 -- the function or, in the case of an indirect call, the level of the
11040 -- access-to-subprogram type. (This code is used for Ada 95, but it
11041 -- looks wrong, because it seems that we should be checking the level
11042 -- of the call itself, even for Ada 95. However, using the Ada 2005
11043 -- version of the code causes regressions in several tests that are
11044 -- compiled with -gnat95. ???)
11046 if Ada_Version < Ada_2005 then
11047 if Is_Entity_Name (Name (Obj)) then
11048 return Subprogram_Access_Level (Entity (Name (Obj)));
11050 return Type_Access_Level (Etype (Prefix (Name (Obj))));
11053 -- For Ada 2005, the level of the result object of a function call is
11054 -- defined to be the level of the call's innermost enclosing master.
11055 -- We determine that by querying the depth of the innermost enclosing
11059 Return_Master_Scope_Depth_Of_Call : declare
11061 function Innermost_Master_Scope_Depth
11062 (N : Node_Id) return Uint;
11063 -- Returns the scope depth of the given node's innermost
11064 -- enclosing dynamic scope (effectively the accessibility
11065 -- level of the innermost enclosing master).
11067 ----------------------------------
11068 -- Innermost_Master_Scope_Depth --
11069 ----------------------------------
11071 function Innermost_Master_Scope_Depth
11072 (N : Node_Id) return Uint
11074 Node_Par : Node_Id := Parent (N);
11077 -- Locate the nearest enclosing node (by traversing Parents)
11078 -- that Defining_Entity can be applied to, and return the
11079 -- depth of that entity's nearest enclosing dynamic scope.
11081 while Present (Node_Par) loop
11082 case Nkind (Node_Par) is
11083 when N_Component_Declaration |
11084 N_Entry_Declaration |
11085 N_Formal_Object_Declaration |
11086 N_Formal_Type_Declaration |
11087 N_Full_Type_Declaration |
11088 N_Incomplete_Type_Declaration |
11089 N_Loop_Parameter_Specification |
11090 N_Object_Declaration |
11091 N_Protected_Type_Declaration |
11092 N_Private_Extension_Declaration |
11093 N_Private_Type_Declaration |
11094 N_Subtype_Declaration |
11095 N_Function_Specification |
11096 N_Procedure_Specification |
11097 N_Task_Type_Declaration |
11099 N_Generic_Instantiation |
11101 N_Implicit_Label_Declaration |
11102 N_Package_Declaration |
11103 N_Single_Task_Declaration |
11104 N_Subprogram_Declaration |
11105 N_Generic_Declaration |
11106 N_Renaming_Declaration |
11107 N_Block_Statement |
11108 N_Formal_Subprogram_Declaration |
11109 N_Abstract_Subprogram_Declaration |
11111 N_Exception_Declaration |
11112 N_Formal_Package_Declaration |
11113 N_Number_Declaration |
11114 N_Package_Specification |
11115 N_Parameter_Specification |
11116 N_Single_Protected_Declaration |
11120 (Nearest_Dynamic_Scope
11121 (Defining_Entity (Node_Par)));
11127 Node_Par := Parent (Node_Par);
11130 pragma Assert (False);
11132 -- Should never reach the following return
11134 return Scope_Depth (Current_Scope) + 1;
11135 end Innermost_Master_Scope_Depth;
11137 -- Start of processing for Return_Master_Scope_Depth_Of_Call
11140 return Innermost_Master_Scope_Depth (Obj);
11141 end Return_Master_Scope_Depth_Of_Call;
11144 -- For convenience we handle qualified expressions, even though
11145 -- they aren't technically object names.
11147 elsif Nkind (Obj) = N_Qualified_Expression then
11148 return Object_Access_Level (Expression (Obj));
11150 -- Otherwise return the scope level of Standard.
11151 -- (If there are cases that fall through
11152 -- to this point they will be treated as
11153 -- having global accessibility for now. ???)
11156 return Scope_Depth (Standard_Standard);
11158 end Object_Access_Level;
11160 --------------------------------------
11161 -- Original_Corresponding_Operation --
11162 --------------------------------------
11164 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
11166 Typ : constant Entity_Id := Find_Dispatching_Type (S);
11169 -- If S is an inherited primitive S2 the original corresponding
11170 -- operation of S is the original corresponding operation of S2
11172 if Present (Alias (S))
11173 and then Find_Dispatching_Type (Alias (S)) /= Typ
11175 return Original_Corresponding_Operation (Alias (S));
11177 -- If S overrides an inherited subprogram S2 the original corresponding
11178 -- operation of S is the original corresponding operation of S2
11180 elsif Present (Overridden_Operation (S)) then
11181 return Original_Corresponding_Operation (Overridden_Operation (S));
11183 -- otherwise it is S itself
11188 end Original_Corresponding_Operation;
11190 -----------------------
11191 -- Private_Component --
11192 -----------------------
11194 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
11195 Ancestor : constant Entity_Id := Base_Type (Type_Id);
11197 function Trace_Components
11199 Check : Boolean) return Entity_Id;
11200 -- Recursive function that does the work, and checks against circular
11201 -- definition for each subcomponent type.
11203 ----------------------
11204 -- Trace_Components --
11205 ----------------------
11207 function Trace_Components
11209 Check : Boolean) return Entity_Id
11211 Btype : constant Entity_Id := Base_Type (T);
11212 Component : Entity_Id;
11214 Candidate : Entity_Id := Empty;
11217 if Check and then Btype = Ancestor then
11218 Error_Msg_N ("circular type definition", Type_Id);
11222 if Is_Private_Type (Btype)
11223 and then not Is_Generic_Type (Btype)
11225 if Present (Full_View (Btype))
11226 and then Is_Record_Type (Full_View (Btype))
11227 and then not Is_Frozen (Btype)
11229 -- To indicate that the ancestor depends on a private type, the
11230 -- current Btype is sufficient. However, to check for circular
11231 -- definition we must recurse on the full view.
11233 Candidate := Trace_Components (Full_View (Btype), True);
11235 if Candidate = Any_Type then
11245 elsif Is_Array_Type (Btype) then
11246 return Trace_Components (Component_Type (Btype), True);
11248 elsif Is_Record_Type (Btype) then
11249 Component := First_Entity (Btype);
11250 while Present (Component)
11251 and then Comes_From_Source (Component)
11253 -- Skip anonymous types generated by constrained components
11255 if not Is_Type (Component) then
11256 P := Trace_Components (Etype (Component), True);
11258 if Present (P) then
11259 if P = Any_Type then
11267 Next_Entity (Component);
11275 end Trace_Components;
11277 -- Start of processing for Private_Component
11280 return Trace_Components (Type_Id, False);
11281 end Private_Component;
11283 ---------------------------
11284 -- Primitive_Names_Match --
11285 ---------------------------
11287 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
11289 function Non_Internal_Name (E : Entity_Id) return Name_Id;
11290 -- Given an internal name, returns the corresponding non-internal name
11292 ------------------------
11293 -- Non_Internal_Name --
11294 ------------------------
11296 function Non_Internal_Name (E : Entity_Id) return Name_Id is
11298 Get_Name_String (Chars (E));
11299 Name_Len := Name_Len - 1;
11301 end Non_Internal_Name;
11303 -- Start of processing for Primitive_Names_Match
11306 pragma Assert (Present (E1) and then Present (E2));
11308 return Chars (E1) = Chars (E2)
11310 (not Is_Internal_Name (Chars (E1))
11311 and then Is_Internal_Name (Chars (E2))
11312 and then Non_Internal_Name (E2) = Chars (E1))
11314 (not Is_Internal_Name (Chars (E2))
11315 and then Is_Internal_Name (Chars (E1))
11316 and then Non_Internal_Name (E1) = Chars (E2))
11318 (Is_Predefined_Dispatching_Operation (E1)
11319 and then Is_Predefined_Dispatching_Operation (E2)
11320 and then Same_TSS (E1, E2))
11322 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
11323 end Primitive_Names_Match;
11325 -----------------------
11326 -- Process_End_Label --
11327 -----------------------
11329 procedure Process_End_Label
11338 Label_Ref : Boolean;
11339 -- Set True if reference to end label itself is required
11342 -- Gets set to the operator symbol or identifier that references the
11343 -- entity Ent. For the child unit case, this is the identifier from the
11344 -- designator. For other cases, this is simply Endl.
11346 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
11347 -- N is an identifier node that appears as a parent unit reference in
11348 -- the case where Ent is a child unit. This procedure generates an
11349 -- appropriate cross-reference entry. E is the corresponding entity.
11351 -------------------------
11352 -- Generate_Parent_Ref --
11353 -------------------------
11355 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
11357 -- If names do not match, something weird, skip reference
11359 if Chars (E) = Chars (N) then
11361 -- Generate the reference. We do NOT consider this as a reference
11362 -- for unreferenced symbol purposes.
11364 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
11366 if Style_Check then
11367 Style.Check_Identifier (N, E);
11370 end Generate_Parent_Ref;
11372 -- Start of processing for Process_End_Label
11375 -- If no node, ignore. This happens in some error situations, and
11376 -- also for some internally generated structures where no end label
11377 -- references are required in any case.
11383 -- Nothing to do if no End_Label, happens for internally generated
11384 -- constructs where we don't want an end label reference anyway. Also
11385 -- nothing to do if Endl is a string literal, which means there was
11386 -- some prior error (bad operator symbol)
11388 Endl := End_Label (N);
11390 if No (Endl) or else Nkind (Endl) = N_String_Literal then
11394 -- Reference node is not in extended main source unit
11396 if not In_Extended_Main_Source_Unit (N) then
11398 -- Generally we do not collect references except for the extended
11399 -- main source unit. The one exception is the 'e' entry for a
11400 -- package spec, where it is useful for a client to have the
11401 -- ending information to define scopes.
11407 Label_Ref := False;
11409 -- For this case, we can ignore any parent references, but we
11410 -- need the package name itself for the 'e' entry.
11412 if Nkind (Endl) = N_Designator then
11413 Endl := Identifier (Endl);
11417 -- Reference is in extended main source unit
11422 -- For designator, generate references for the parent entries
11424 if Nkind (Endl) = N_Designator then
11426 -- Generate references for the prefix if the END line comes from
11427 -- source (otherwise we do not need these references) We climb the
11428 -- scope stack to find the expected entities.
11430 if Comes_From_Source (Endl) then
11431 Nam := Name (Endl);
11432 Scop := Current_Scope;
11433 while Nkind (Nam) = N_Selected_Component loop
11434 Scop := Scope (Scop);
11435 exit when No (Scop);
11436 Generate_Parent_Ref (Selector_Name (Nam), Scop);
11437 Nam := Prefix (Nam);
11440 if Present (Scop) then
11441 Generate_Parent_Ref (Nam, Scope (Scop));
11445 Endl := Identifier (Endl);
11449 -- If the end label is not for the given entity, then either we have
11450 -- some previous error, or this is a generic instantiation for which
11451 -- we do not need to make a cross-reference in this case anyway. In
11452 -- either case we simply ignore the call.
11454 if Chars (Ent) /= Chars (Endl) then
11458 -- If label was really there, then generate a normal reference and then
11459 -- adjust the location in the end label to point past the name (which
11460 -- should almost always be the semicolon).
11462 Loc := Sloc (Endl);
11464 if Comes_From_Source (Endl) then
11466 -- If a label reference is required, then do the style check and
11467 -- generate an l-type cross-reference entry for the label
11470 if Style_Check then
11471 Style.Check_Identifier (Endl, Ent);
11474 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
11477 -- Set the location to point past the label (normally this will
11478 -- mean the semicolon immediately following the label). This is
11479 -- done for the sake of the 'e' or 't' entry generated below.
11481 Get_Decoded_Name_String (Chars (Endl));
11482 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11485 -- In SPARK mode, no missing label is allowed for packages and
11486 -- subprogram bodies. Detect those cases by testing whether
11487 -- Process_End_Label was called for a body (Typ = 't') or a package.
11489 if Restriction_Check_Required (SPARK)
11490 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11492 Error_Msg_Node_1 := Endl;
11493 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11497 -- Now generate the e/t reference
11499 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11501 -- Restore Sloc, in case modified above, since we have an identifier
11502 -- and the normal Sloc should be left set in the tree.
11504 Set_Sloc (Endl, Loc);
11505 end Process_End_Label;
11507 ------------------------------------
11508 -- References_Generic_Formal_Type --
11509 ------------------------------------
11511 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11513 function Process (N : Node_Id) return Traverse_Result;
11514 -- Process one node in search for generic formal type
11520 function Process (N : Node_Id) return Traverse_Result is
11522 if Nkind (N) in N_Has_Entity then
11524 E : constant Entity_Id := Entity (N);
11526 if Present (E) then
11527 if Is_Generic_Type (E) then
11529 elsif Present (Etype (E))
11530 and then Is_Generic_Type (Etype (E))
11541 function Traverse is new Traverse_Func (Process);
11542 -- Traverse tree to look for generic type
11545 if Inside_A_Generic then
11546 return Traverse (N) = Abandon;
11550 end References_Generic_Formal_Type;
11552 --------------------
11553 -- Remove_Homonym --
11554 --------------------
11556 procedure Remove_Homonym (E : Entity_Id) is
11557 Prev : Entity_Id := Empty;
11561 if E = Current_Entity (E) then
11562 if Present (Homonym (E)) then
11563 Set_Current_Entity (Homonym (E));
11565 Set_Name_Entity_Id (Chars (E), Empty);
11568 H := Current_Entity (E);
11569 while Present (H) and then H /= E loop
11574 Set_Homonym (Prev, Homonym (E));
11576 end Remove_Homonym;
11578 ---------------------
11579 -- Rep_To_Pos_Flag --
11580 ---------------------
11582 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11584 return New_Occurrence_Of
11585 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11586 end Rep_To_Pos_Flag;
11588 --------------------
11589 -- Require_Entity --
11590 --------------------
11592 procedure Require_Entity (N : Node_Id) is
11594 if Is_Entity_Name (N) and then No (Entity (N)) then
11595 if Total_Errors_Detected /= 0 then
11596 Set_Entity (N, Any_Id);
11598 raise Program_Error;
11601 end Require_Entity;
11603 ------------------------------
11604 -- Requires_Transient_Scope --
11605 ------------------------------
11607 -- A transient scope is required when variable-sized temporaries are
11608 -- allocated in the primary or secondary stack, or when finalization
11609 -- actions must be generated before the next instruction.
11611 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11612 Typ : constant Entity_Id := Underlying_Type (Id);
11614 -- Start of processing for Requires_Transient_Scope
11617 -- This is a private type which is not completed yet. This can only
11618 -- happen in a default expression (of a formal parameter or of a
11619 -- record component). Do not expand transient scope in this case
11624 -- Do not expand transient scope for non-existent procedure return
11626 elsif Typ = Standard_Void_Type then
11629 -- Elementary types do not require a transient scope
11631 elsif Is_Elementary_Type (Typ) then
11634 -- Generally, indefinite subtypes require a transient scope, since the
11635 -- back end cannot generate temporaries, since this is not a valid type
11636 -- for declaring an object. It might be possible to relax this in the
11637 -- future, e.g. by declaring the maximum possible space for the type.
11639 elsif Is_Indefinite_Subtype (Typ) then
11642 -- Functions returning tagged types may dispatch on result so their
11643 -- returned value is allocated on the secondary stack. Controlled
11644 -- type temporaries need finalization.
11646 elsif Is_Tagged_Type (Typ)
11647 or else Has_Controlled_Component (Typ)
11649 return not Is_Value_Type (Typ);
11653 elsif Is_Record_Type (Typ) then
11657 Comp := First_Entity (Typ);
11658 while Present (Comp) loop
11659 if Ekind (Comp) = E_Component
11660 and then Requires_Transient_Scope (Etype (Comp))
11664 Next_Entity (Comp);
11671 -- String literal types never require transient scope
11673 elsif Ekind (Typ) = E_String_Literal_Subtype then
11676 -- Array type. Note that we already know that this is a constrained
11677 -- array, since unconstrained arrays will fail the indefinite test.
11679 elsif Is_Array_Type (Typ) then
11681 -- If component type requires a transient scope, the array does too
11683 if Requires_Transient_Scope (Component_Type (Typ)) then
11686 -- Otherwise, we only need a transient scope if the size depends on
11687 -- the value of one or more discriminants.
11690 return Size_Depends_On_Discriminant (Typ);
11693 -- All other cases do not require a transient scope
11698 end Requires_Transient_Scope;
11700 --------------------------
11701 -- Reset_Analyzed_Flags --
11702 --------------------------
11704 procedure Reset_Analyzed_Flags (N : Node_Id) is
11706 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11707 -- Function used to reset Analyzed flags in tree. Note that we do
11708 -- not reset Analyzed flags in entities, since there is no need to
11709 -- reanalyze entities, and indeed, it is wrong to do so, since it
11710 -- can result in generating auxiliary stuff more than once.
11712 --------------------
11713 -- Clear_Analyzed --
11714 --------------------
11716 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11718 if not Has_Extension (N) then
11719 Set_Analyzed (N, False);
11723 end Clear_Analyzed;
11725 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11727 -- Start of processing for Reset_Analyzed_Flags
11730 Reset_Analyzed (N);
11731 end Reset_Analyzed_Flags;
11733 ---------------------------
11734 -- Safe_To_Capture_Value --
11735 ---------------------------
11737 function Safe_To_Capture_Value
11740 Cond : Boolean := False) return Boolean
11743 -- The only entities for which we track constant values are variables
11744 -- which are not renamings, constants, out parameters, and in out
11745 -- parameters, so check if we have this case.
11747 -- Note: it may seem odd to track constant values for constants, but in
11748 -- fact this routine is used for other purposes than simply capturing
11749 -- the value. In particular, the setting of Known[_Non]_Null.
11751 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11753 Ekind (Ent) = E_Constant
11755 Ekind (Ent) = E_Out_Parameter
11757 Ekind (Ent) = E_In_Out_Parameter
11761 -- For conditionals, we also allow loop parameters and all formals,
11762 -- including in parameters.
11766 (Ekind (Ent) = E_Loop_Parameter
11768 Ekind (Ent) = E_In_Parameter)
11772 -- For all other cases, not just unsafe, but impossible to capture
11773 -- Current_Value, since the above are the only entities which have
11774 -- Current_Value fields.
11780 -- Skip if volatile or aliased, since funny things might be going on in
11781 -- these cases which we cannot necessarily track. Also skip any variable
11782 -- for which an address clause is given, or whose address is taken. Also
11783 -- never capture value of library level variables (an attempt to do so
11784 -- can occur in the case of package elaboration code).
11786 if Treat_As_Volatile (Ent)
11787 or else Is_Aliased (Ent)
11788 or else Present (Address_Clause (Ent))
11789 or else Address_Taken (Ent)
11790 or else (Is_Library_Level_Entity (Ent)
11791 and then Ekind (Ent) = E_Variable)
11796 -- OK, all above conditions are met. We also require that the scope of
11797 -- the reference be the same as the scope of the entity, not counting
11798 -- packages and blocks and loops.
11801 E_Scope : constant Entity_Id := Scope (Ent);
11802 R_Scope : Entity_Id;
11805 R_Scope := Current_Scope;
11806 while R_Scope /= Standard_Standard loop
11807 exit when R_Scope = E_Scope;
11809 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11812 R_Scope := Scope (R_Scope);
11817 -- We also require that the reference does not appear in a context
11818 -- where it is not sure to be executed (i.e. a conditional context
11819 -- or an exception handler). We skip this if Cond is True, since the
11820 -- capturing of values from conditional tests handles this ok.
11834 while Present (P) loop
11835 if Nkind (P) = N_If_Statement
11836 or else Nkind (P) = N_Case_Statement
11837 or else (Nkind (P) in N_Short_Circuit
11838 and then Desc = Right_Opnd (P))
11839 or else (Nkind (P) = N_Conditional_Expression
11840 and then Desc /= First (Expressions (P)))
11841 or else Nkind (P) = N_Exception_Handler
11842 or else Nkind (P) = N_Selective_Accept
11843 or else Nkind (P) = N_Conditional_Entry_Call
11844 or else Nkind (P) = N_Timed_Entry_Call
11845 or else Nkind (P) = N_Asynchronous_Select
11855 -- OK, looks safe to set value
11858 end Safe_To_Capture_Value;
11864 function Same_Name (N1, N2 : Node_Id) return Boolean is
11865 K1 : constant Node_Kind := Nkind (N1);
11866 K2 : constant Node_Kind := Nkind (N2);
11869 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11870 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11872 return Chars (N1) = Chars (N2);
11874 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11875 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11877 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11878 and then Same_Name (Prefix (N1), Prefix (N2));
11889 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11890 N1 : constant Node_Id := Original_Node (Node1);
11891 N2 : constant Node_Id := Original_Node (Node2);
11892 -- We do the tests on original nodes, since we are most interested
11893 -- in the original source, not any expansion that got in the way.
11895 K1 : constant Node_Kind := Nkind (N1);
11896 K2 : constant Node_Kind := Nkind (N2);
11899 -- First case, both are entities with same entity
11901 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11903 EN1 : constant Entity_Id := Entity (N1);
11904 EN2 : constant Entity_Id := Entity (N2);
11906 if Present (EN1) and then Present (EN2)
11907 and then (Ekind_In (EN1, E_Variable, E_Constant)
11908 or else Is_Formal (EN1))
11916 -- Second case, selected component with same selector, same record
11918 if K1 = N_Selected_Component
11919 and then K2 = N_Selected_Component
11920 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11922 return Same_Object (Prefix (N1), Prefix (N2));
11924 -- Third case, indexed component with same subscripts, same array
11926 elsif K1 = N_Indexed_Component
11927 and then K2 = N_Indexed_Component
11928 and then Same_Object (Prefix (N1), Prefix (N2))
11933 E1 := First (Expressions (N1));
11934 E2 := First (Expressions (N2));
11935 while Present (E1) loop
11936 if not Same_Value (E1, E2) then
11947 -- Fourth case, slice of same array with same bounds
11950 and then K2 = N_Slice
11951 and then Nkind (Discrete_Range (N1)) = N_Range
11952 and then Nkind (Discrete_Range (N2)) = N_Range
11953 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11954 Low_Bound (Discrete_Range (N2)))
11955 and then Same_Value (High_Bound (Discrete_Range (N1)),
11956 High_Bound (Discrete_Range (N2)))
11958 return Same_Name (Prefix (N1), Prefix (N2));
11960 -- All other cases, not clearly the same object
11971 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11976 elsif not Is_Constrained (T1)
11977 and then not Is_Constrained (T2)
11978 and then Base_Type (T1) = Base_Type (T2)
11982 -- For now don't bother with case of identical constraints, to be
11983 -- fiddled with later on perhaps (this is only used for optimization
11984 -- purposes, so it is not critical to do a best possible job)
11995 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11997 if Compile_Time_Known_Value (Node1)
11998 and then Compile_Time_Known_Value (Node2)
11999 and then Expr_Value (Node1) = Expr_Value (Node2)
12002 elsif Same_Object (Node1, Node2) then
12013 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
12015 if Ada_Version < Ada_2012 then
12018 elsif Is_Entity_Name (N)
12020 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
12022 (Nkind (N) = N_Attribute_Reference
12023 and then Attribute_Name (N) = Name_Access)
12026 -- We are only interested in IN OUT parameters of inner calls
12029 or else Nkind (Parent (N)) = N_Function_Call
12030 or else Nkind (Parent (N)) in N_Op
12032 Actuals_In_Call.Increment_Last;
12033 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
12038 ------------------------
12039 -- Scope_Is_Transient --
12040 ------------------------
12042 function Scope_Is_Transient return Boolean is
12044 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
12045 end Scope_Is_Transient;
12051 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
12056 while Scop /= Standard_Standard loop
12057 Scop := Scope (Scop);
12059 if Scop = Scope2 then
12067 --------------------------
12068 -- Scope_Within_Or_Same --
12069 --------------------------
12071 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
12076 while Scop /= Standard_Standard loop
12077 if Scop = Scope2 then
12080 Scop := Scope (Scop);
12085 end Scope_Within_Or_Same;
12087 --------------------
12088 -- Set_Convention --
12089 --------------------
12091 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
12093 Basic_Set_Convention (E, Val);
12096 and then Is_Access_Subprogram_Type (Base_Type (E))
12097 and then Has_Foreign_Convention (E)
12099 Set_Can_Use_Internal_Rep (E, False);
12101 end Set_Convention;
12103 ------------------------
12104 -- Set_Current_Entity --
12105 ------------------------
12107 -- The given entity is to be set as the currently visible definition of its
12108 -- associated name (i.e. the Node_Id associated with its name). All we have
12109 -- to do is to get the name from the identifier, and then set the
12110 -- associated Node_Id to point to the given entity.
12112 procedure Set_Current_Entity (E : Entity_Id) is
12114 Set_Name_Entity_Id (Chars (E), E);
12115 end Set_Current_Entity;
12117 ---------------------------
12118 -- Set_Debug_Info_Needed --
12119 ---------------------------
12121 procedure Set_Debug_Info_Needed (T : Entity_Id) is
12123 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
12124 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
12125 -- Used to set debug info in a related node if not set already
12127 --------------------------------------
12128 -- Set_Debug_Info_Needed_If_Not_Set --
12129 --------------------------------------
12131 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
12134 and then not Needs_Debug_Info (E)
12136 Set_Debug_Info_Needed (E);
12138 -- For a private type, indicate that the full view also needs
12139 -- debug information.
12142 and then Is_Private_Type (E)
12143 and then Present (Full_View (E))
12145 Set_Debug_Info_Needed (Full_View (E));
12148 end Set_Debug_Info_Needed_If_Not_Set;
12150 -- Start of processing for Set_Debug_Info_Needed
12153 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
12154 -- indicates that Debug_Info_Needed is never required for the entity.
12157 or else Debug_Info_Off (T)
12162 -- Set flag in entity itself. Note that we will go through the following
12163 -- circuitry even if the flag is already set on T. That's intentional,
12164 -- it makes sure that the flag will be set in subsidiary entities.
12166 Set_Needs_Debug_Info (T);
12168 -- Set flag on subsidiary entities if not set already
12170 if Is_Object (T) then
12171 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12173 elsif Is_Type (T) then
12174 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12176 if Is_Record_Type (T) then
12178 Ent : Entity_Id := First_Entity (T);
12180 while Present (Ent) loop
12181 Set_Debug_Info_Needed_If_Not_Set (Ent);
12186 -- For a class wide subtype, we also need debug information
12187 -- for the equivalent type.
12189 if Ekind (T) = E_Class_Wide_Subtype then
12190 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
12193 elsif Is_Array_Type (T) then
12194 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
12197 Indx : Node_Id := First_Index (T);
12199 while Present (Indx) loop
12200 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
12201 Indx := Next_Index (Indx);
12205 if Is_Packed (T) then
12206 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
12209 elsif Is_Access_Type (T) then
12210 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
12212 elsif Is_Private_Type (T) then
12213 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
12215 elsif Is_Protected_Type (T) then
12216 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
12219 end Set_Debug_Info_Needed;
12221 ---------------------------------
12222 -- Set_Entity_With_Style_Check --
12223 ---------------------------------
12225 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
12226 Val_Actual : Entity_Id;
12230 -- Unconditionally set the entity
12232 Set_Entity (N, Val);
12234 -- Check for No_Implementation_Identifiers
12236 if Restriction_Check_Required (No_Implementation_Identifiers) then
12238 -- We have an implementation defined entity if it is marked as
12239 -- implementation defined, or is defined in a package marked as
12240 -- implementation defined. However, library packages themselves
12241 -- are excluded (we don't want to flag Interfaces itself, just
12242 -- the entities within it).
12244 if (Is_Implementation_Defined (Val)
12245 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
12246 and then Is_Library_Level_Entity (Val)))
12247 or else Is_Implementation_Defined (Scope (Val))
12249 Check_Restriction (No_Implementation_Identifiers, N);
12253 -- Do the style check
12256 and then not Suppress_Style_Checks (Val)
12257 and then not In_Instance
12259 if Nkind (N) = N_Identifier then
12261 elsif Nkind (N) = N_Expanded_Name then
12262 Nod := Selector_Name (N);
12267 -- A special situation arises for derived operations, where we want
12268 -- to do the check against the parent (since the Sloc of the derived
12269 -- operation points to the derived type declaration itself).
12272 while not Comes_From_Source (Val_Actual)
12273 and then Nkind (Val_Actual) in N_Entity
12274 and then (Ekind (Val_Actual) = E_Enumeration_Literal
12275 or else Is_Subprogram (Val_Actual)
12276 or else Is_Generic_Subprogram (Val_Actual))
12277 and then Present (Alias (Val_Actual))
12279 Val_Actual := Alias (Val_Actual);
12282 -- Renaming declarations for generic actuals do not come from source,
12283 -- and have a different name from that of the entity they rename, so
12284 -- there is no style check to perform here.
12286 if Chars (Nod) = Chars (Val_Actual) then
12287 Style.Check_Identifier (Nod, Val_Actual);
12291 Set_Entity (N, Val);
12292 end Set_Entity_With_Style_Check;
12294 ------------------------
12295 -- Set_Name_Entity_Id --
12296 ------------------------
12298 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
12300 Set_Name_Table_Info (Id, Int (Val));
12301 end Set_Name_Entity_Id;
12303 ---------------------
12304 -- Set_Next_Actual --
12305 ---------------------
12307 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
12309 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
12310 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
12312 end Set_Next_Actual;
12314 ----------------------------------
12315 -- Set_Optimize_Alignment_Flags --
12316 ----------------------------------
12318 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
12320 if Optimize_Alignment = 'S' then
12321 Set_Optimize_Alignment_Space (E);
12322 elsif Optimize_Alignment = 'T' then
12323 Set_Optimize_Alignment_Time (E);
12325 end Set_Optimize_Alignment_Flags;
12327 -----------------------
12328 -- Set_Public_Status --
12329 -----------------------
12331 procedure Set_Public_Status (Id : Entity_Id) is
12332 S : constant Entity_Id := Current_Scope;
12334 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
12335 -- Determines if E is defined within handled statement sequence or
12336 -- an if statement, returns True if so, False otherwise.
12338 ----------------------
12339 -- Within_HSS_Or_If --
12340 ----------------------
12342 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
12345 N := Declaration_Node (E);
12352 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
12358 end Within_HSS_Or_If;
12360 -- Start of processing for Set_Public_Status
12363 -- Everything in the scope of Standard is public
12365 if S = Standard_Standard then
12366 Set_Is_Public (Id);
12368 -- Entity is definitely not public if enclosing scope is not public
12370 elsif not Is_Public (S) then
12373 -- An object or function declaration that occurs in a handled sequence
12374 -- of statements or within an if statement is the declaration for a
12375 -- temporary object or local subprogram generated by the expander. It
12376 -- never needs to be made public and furthermore, making it public can
12377 -- cause back end problems.
12379 elsif Nkind_In (Parent (Id), N_Object_Declaration,
12380 N_Function_Specification)
12381 and then Within_HSS_Or_If (Id)
12385 -- Entities in public packages or records are public
12387 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
12388 Set_Is_Public (Id);
12390 -- The bounds of an entry family declaration can generate object
12391 -- declarations that are visible to the back-end, e.g. in the
12392 -- the declaration of a composite type that contains tasks.
12394 elsif Is_Concurrent_Type (S)
12395 and then not Has_Completion (S)
12396 and then Nkind (Parent (Id)) = N_Object_Declaration
12398 Set_Is_Public (Id);
12400 end Set_Public_Status;
12402 -----------------------------
12403 -- Set_Referenced_Modified --
12404 -----------------------------
12406 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
12410 -- Deal with indexed or selected component where prefix is modified
12412 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
12413 Pref := Prefix (N);
12415 -- If prefix is access type, then it is the designated object that is
12416 -- being modified, which means we have no entity to set the flag on.
12418 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
12421 -- Otherwise chase the prefix
12424 Set_Referenced_Modified (Pref, Out_Param);
12427 -- Otherwise see if we have an entity name (only other case to process)
12429 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
12430 Set_Referenced_As_LHS (Entity (N), not Out_Param);
12431 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
12433 end Set_Referenced_Modified;
12435 ----------------------------
12436 -- Set_Scope_Is_Transient --
12437 ----------------------------
12439 procedure Set_Scope_Is_Transient (V : Boolean := True) is
12441 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
12442 end Set_Scope_Is_Transient;
12444 -------------------
12445 -- Set_Size_Info --
12446 -------------------
12448 procedure Set_Size_Info (T1, T2 : Entity_Id) is
12450 -- We copy Esize, but not RM_Size, since in general RM_Size is
12451 -- subtype specific and does not get inherited by all subtypes.
12453 Set_Esize (T1, Esize (T2));
12454 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
12456 if Is_Discrete_Or_Fixed_Point_Type (T1)
12458 Is_Discrete_Or_Fixed_Point_Type (T2)
12460 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
12463 Set_Alignment (T1, Alignment (T2));
12466 --------------------
12467 -- Static_Boolean --
12468 --------------------
12470 function Static_Boolean (N : Node_Id) return Uint is
12472 Analyze_And_Resolve (N, Standard_Boolean);
12475 or else Error_Posted (N)
12476 or else Etype (N) = Any_Type
12481 if Is_Static_Expression (N) then
12482 if not Raises_Constraint_Error (N) then
12483 return Expr_Value (N);
12488 elsif Etype (N) = Any_Type then
12492 Flag_Non_Static_Expr
12493 ("static boolean expression required here", N);
12496 end Static_Boolean;
12498 --------------------
12499 -- Static_Integer --
12500 --------------------
12502 function Static_Integer (N : Node_Id) return Uint is
12504 Analyze_And_Resolve (N, Any_Integer);
12507 or else Error_Posted (N)
12508 or else Etype (N) = Any_Type
12513 if Is_Static_Expression (N) then
12514 if not Raises_Constraint_Error (N) then
12515 return Expr_Value (N);
12520 elsif Etype (N) = Any_Type then
12524 Flag_Non_Static_Expr
12525 ("static integer expression required here", N);
12528 end Static_Integer;
12530 --------------------------
12531 -- Statically_Different --
12532 --------------------------
12534 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12535 R1 : constant Node_Id := Get_Referenced_Object (E1);
12536 R2 : constant Node_Id := Get_Referenced_Object (E2);
12538 return Is_Entity_Name (R1)
12539 and then Is_Entity_Name (R2)
12540 and then Entity (R1) /= Entity (R2)
12541 and then not Is_Formal (Entity (R1))
12542 and then not Is_Formal (Entity (R2));
12543 end Statically_Different;
12545 -----------------------------
12546 -- Subprogram_Access_Level --
12547 -----------------------------
12549 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12551 if Present (Alias (Subp)) then
12552 return Subprogram_Access_Level (Alias (Subp));
12554 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12556 end Subprogram_Access_Level;
12562 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12564 if Debug_Flag_W then
12565 for J in 0 .. Scope_Stack.Last loop
12570 Write_Name (Chars (E));
12571 Write_Str (" from ");
12572 Write_Location (Sloc (N));
12577 -----------------------
12578 -- Transfer_Entities --
12579 -----------------------
12581 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12582 Ent : Entity_Id := First_Entity (From);
12589 if (Last_Entity (To)) = Empty then
12590 Set_First_Entity (To, Ent);
12592 Set_Next_Entity (Last_Entity (To), Ent);
12595 Set_Last_Entity (To, Last_Entity (From));
12597 while Present (Ent) loop
12598 Set_Scope (Ent, To);
12600 if not Is_Public (Ent) then
12601 Set_Public_Status (Ent);
12604 and then Ekind (Ent) = E_Record_Subtype
12607 -- The components of the propagated Itype must be public
12613 Comp := First_Entity (Ent);
12614 while Present (Comp) loop
12615 Set_Is_Public (Comp);
12616 Next_Entity (Comp);
12625 Set_First_Entity (From, Empty);
12626 Set_Last_Entity (From, Empty);
12627 end Transfer_Entities;
12629 -----------------------
12630 -- Type_Access_Level --
12631 -----------------------
12633 function Type_Access_Level (Typ : Entity_Id) return Uint is
12637 Btyp := Base_Type (Typ);
12639 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12640 -- simply use the level where the type is declared. This is true for
12641 -- stand-alone object declarations, and for anonymous access types
12642 -- associated with components the level is the same as that of the
12643 -- enclosing composite type. However, special treatment is needed for
12644 -- the cases of access parameters, return objects of an anonymous access
12645 -- type, and, in Ada 95, access discriminants of limited types.
12647 if Ekind (Btyp) in Access_Kind then
12648 if Ekind (Btyp) = E_Anonymous_Access_Type then
12650 -- If the type is a nonlocal anonymous access type (such as for
12651 -- an access parameter) we treat it as being declared at the
12652 -- library level to ensure that names such as X.all'access don't
12653 -- fail static accessibility checks.
12655 if not Is_Local_Anonymous_Access (Typ) then
12656 return Scope_Depth (Standard_Standard);
12658 -- If this is a return object, the accessibility level is that of
12659 -- the result subtype of the enclosing function. The test here is
12660 -- little complicated, because we have to account for extended
12661 -- return statements that have been rewritten as blocks, in which
12662 -- case we have to find and the Is_Return_Object attribute of the
12663 -- itype's associated object. It would be nice to find a way to
12664 -- simplify this test, but it doesn't seem worthwhile to add a new
12665 -- flag just for purposes of this test. ???
12667 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12670 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12671 N_Object_Declaration
12672 and then Is_Return_Object
12673 (Defining_Identifier
12674 (Associated_Node_For_Itype (Btyp))))
12680 Scop := Scope (Scope (Btyp));
12681 while Present (Scop) loop
12682 exit when Ekind (Scop) = E_Function;
12683 Scop := Scope (Scop);
12686 -- Treat the return object's type as having the level of the
12687 -- function's result subtype (as per RM05-6.5(5.3/2)).
12689 return Type_Access_Level (Etype (Scop));
12694 Btyp := Root_Type (Btyp);
12696 -- The accessibility level of anonymous access types associated with
12697 -- discriminants is that of the current instance of the type, and
12698 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12700 -- AI-402: access discriminants have accessibility based on the
12701 -- object rather than the type in Ada 2005, so the above paragraph
12704 -- ??? Needs completion with rules from AI-416
12706 if Ada_Version <= Ada_95
12707 and then Ekind (Typ) = E_Anonymous_Access_Type
12708 and then Present (Associated_Node_For_Itype (Typ))
12709 and then Nkind (Associated_Node_For_Itype (Typ)) =
12710 N_Discriminant_Specification
12712 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12716 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12717 end Type_Access_Level;
12719 ------------------------------------
12720 -- Type_Without_Stream_Operation --
12721 ------------------------------------
12723 function Type_Without_Stream_Operation
12725 Op : TSS_Name_Type := TSS_Null) return Entity_Id
12727 BT : constant Entity_Id := Base_Type (T);
12728 Op_Missing : Boolean;
12731 if not Restriction_Active (No_Default_Stream_Attributes) then
12735 if Is_Elementary_Type (T) then
12736 if Op = TSS_Null then
12738 No (TSS (BT, TSS_Stream_Read))
12739 or else No (TSS (BT, TSS_Stream_Write));
12742 Op_Missing := No (TSS (BT, Op));
12751 elsif Is_Array_Type (T) then
12752 return Type_Without_Stream_Operation (Component_Type (T), Op);
12754 elsif Is_Record_Type (T) then
12760 Comp := First_Component (T);
12761 while Present (Comp) loop
12762 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
12764 if Present (C_Typ) then
12768 Next_Component (Comp);
12774 elsif Is_Private_Type (T)
12775 and then Present (Full_View (T))
12777 return Type_Without_Stream_Operation (Full_View (T), Op);
12781 end Type_Without_Stream_Operation;
12783 ----------------------------
12784 -- Unique_Defining_Entity --
12785 ----------------------------
12787 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
12789 return Unique_Entity (Defining_Entity (N));
12790 end Unique_Defining_Entity;
12792 -------------------
12793 -- Unique_Entity --
12794 -------------------
12796 function Unique_Entity (E : Entity_Id) return Entity_Id is
12797 U : Entity_Id := E;
12803 if Present (Full_View (E)) then
12804 U := Full_View (E);
12808 if Present (Full_View (E)) then
12809 U := Full_View (E);
12812 when E_Package_Body =>
12815 if Nkind (P) = N_Defining_Program_Unit_Name then
12819 U := Corresponding_Spec (P);
12821 when E_Subprogram_Body =>
12824 if Nkind (P) = N_Defining_Program_Unit_Name then
12830 if Nkind (P) = N_Subprogram_Body_Stub then
12831 if Present (Library_Unit (P)) then
12832 U := Get_Body_From_Stub (P);
12835 U := Corresponding_Spec (P);
12849 function Unique_Name (E : Entity_Id) return String is
12851 function Get_Scoped_Name (E : Entity_Id) return String;
12852 -- Return the name of E prefixed by all the names of the scopes to which
12853 -- E belongs, except for Standard.
12855 ---------------------
12856 -- Get_Scoped_Name --
12857 ---------------------
12859 function Get_Scoped_Name (E : Entity_Id) return String is
12860 Name : constant String := Get_Name_String (Chars (E));
12862 if Has_Fully_Qualified_Name (E)
12863 or else Scope (E) = Standard_Standard
12867 return Get_Scoped_Name (Scope (E)) & "__" & Name;
12869 end Get_Scoped_Name;
12871 -- Start of processing for Unique_Name
12874 if E = Standard_Standard then
12875 return Get_Name_String (Name_Standard);
12877 elsif Scope (E) = Standard_Standard
12878 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
12880 return Get_Name_String (Name_Standard) & "__" &
12881 Get_Name_String (Chars (E));
12883 elsif Ekind (E) = E_Enumeration_Literal then
12884 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
12887 return Get_Scoped_Name (E);
12891 --------------------------
12892 -- Unit_Declaration_Node --
12893 --------------------------
12895 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12896 N : Node_Id := Parent (Unit_Id);
12899 -- Predefined operators do not have a full function declaration
12901 if Ekind (Unit_Id) = E_Operator then
12905 -- Isn't there some better way to express the following ???
12907 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12908 and then Nkind (N) /= N_Formal_Package_Declaration
12909 and then Nkind (N) /= N_Function_Instantiation
12910 and then Nkind (N) /= N_Generic_Package_Declaration
12911 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12912 and then Nkind (N) /= N_Package_Declaration
12913 and then Nkind (N) /= N_Package_Body
12914 and then Nkind (N) /= N_Package_Instantiation
12915 and then Nkind (N) /= N_Package_Renaming_Declaration
12916 and then Nkind (N) /= N_Procedure_Instantiation
12917 and then Nkind (N) /= N_Protected_Body
12918 and then Nkind (N) /= N_Subprogram_Declaration
12919 and then Nkind (N) /= N_Subprogram_Body
12920 and then Nkind (N) /= N_Subprogram_Body_Stub
12921 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12922 and then Nkind (N) /= N_Task_Body
12923 and then Nkind (N) /= N_Task_Type_Declaration
12924 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12925 and then Nkind (N) not in N_Generic_Renaming_Declaration
12929 -- We don't use Assert here, because that causes an infinite loop
12930 -- when assertions are turned off. Better to crash.
12933 raise Program_Error;
12938 end Unit_Declaration_Node;
12940 ---------------------
12941 -- Unit_Is_Visible --
12942 ---------------------
12944 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12945 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12946 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12948 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12949 -- For a child unit, check whether unit appears in a with_clause
12952 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12953 -- Scan the context clause of one compilation unit looking for a
12954 -- with_clause for the unit in question.
12956 ----------------------------
12957 -- Unit_In_Parent_Context --
12958 ----------------------------
12960 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12962 if Unit_In_Context (Par_Unit) then
12965 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12966 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12971 end Unit_In_Parent_Context;
12973 ---------------------
12974 -- Unit_In_Context --
12975 ---------------------
12977 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12981 Clause := First (Context_Items (Comp_Unit));
12982 while Present (Clause) loop
12983 if Nkind (Clause) = N_With_Clause then
12984 if Library_Unit (Clause) = U then
12987 -- The with_clause may denote a renaming of the unit we are
12988 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12991 Renamed_Entity (Entity (Name (Clause))) =
12992 Defining_Entity (Unit (U))
13002 end Unit_In_Context;
13004 -- Start of processing for Unit_Is_Visible
13007 -- The currrent unit is directly visible
13012 elsif Unit_In_Context (Curr) then
13015 -- If the current unit is a body, check the context of the spec
13017 elsif Nkind (Unit (Curr)) = N_Package_Body
13019 (Nkind (Unit (Curr)) = N_Subprogram_Body
13020 and then not Acts_As_Spec (Unit (Curr)))
13022 if Unit_In_Context (Library_Unit (Curr)) then
13027 -- If the spec is a child unit, examine the parents
13029 if Is_Child_Unit (Curr_Entity) then
13030 if Nkind (Unit (Curr)) in N_Unit_Body then
13032 Unit_In_Parent_Context
13033 (Parent_Spec (Unit (Library_Unit (Curr))));
13035 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
13041 end Unit_Is_Visible;
13043 ------------------------------
13044 -- Universal_Interpretation --
13045 ------------------------------
13047 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
13048 Index : Interp_Index;
13052 -- The argument may be a formal parameter of an operator or subprogram
13053 -- with multiple interpretations, or else an expression for an actual.
13055 if Nkind (Opnd) = N_Defining_Identifier
13056 or else not Is_Overloaded (Opnd)
13058 if Etype (Opnd) = Universal_Integer
13059 or else Etype (Opnd) = Universal_Real
13061 return Etype (Opnd);
13067 Get_First_Interp (Opnd, Index, It);
13068 while Present (It.Typ) loop
13069 if It.Typ = Universal_Integer
13070 or else It.Typ = Universal_Real
13075 Get_Next_Interp (Index, It);
13080 end Universal_Interpretation;
13086 function Unqualify (Expr : Node_Id) return Node_Id is
13088 -- Recurse to handle unlikely case of multiple levels of qualification
13090 if Nkind (Expr) = N_Qualified_Expression then
13091 return Unqualify (Expression (Expr));
13093 -- Normal case, not a qualified expression
13100 -----------------------
13101 -- Visible_Ancestors --
13102 -----------------------
13104 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
13110 pragma Assert (Is_Record_Type (Typ)
13111 and then Is_Tagged_Type (Typ));
13113 -- Collect all the parents and progenitors of Typ. If the full-view of
13114 -- private parents and progenitors is available then it is used to
13115 -- generate the list of visible ancestors; otherwise their partial
13116 -- view is added to the resulting list.
13121 Use_Full_View => True);
13125 Ifaces_List => List_2,
13126 Exclude_Parents => True,
13127 Use_Full_View => True);
13129 -- Join the two lists. Avoid duplications because an interface may
13130 -- simultaneously be parent and progenitor of a type.
13132 Elmt := First_Elmt (List_2);
13133 while Present (Elmt) loop
13134 Append_Unique_Elmt (Node (Elmt), List_1);
13139 end Visible_Ancestors;
13141 ----------------------
13142 -- Within_Init_Proc --
13143 ----------------------
13145 function Within_Init_Proc return Boolean is
13149 S := Current_Scope;
13150 while not Is_Overloadable (S) loop
13151 if S = Standard_Standard then
13158 return Is_Init_Proc (S);
13159 end Within_Init_Proc;
13165 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
13166 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
13167 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
13169 Matching_Field : Entity_Id;
13170 -- Entity to give a more precise suggestion on how to write a one-
13171 -- element positional aggregate.
13173 function Has_One_Matching_Field return Boolean;
13174 -- Determines if Expec_Type is a record type with a single component or
13175 -- discriminant whose type matches the found type or is one dimensional
13176 -- array whose component type matches the found type.
13178 ----------------------------
13179 -- Has_One_Matching_Field --
13180 ----------------------------
13182 function Has_One_Matching_Field return Boolean is
13186 Matching_Field := Empty;
13188 if Is_Array_Type (Expec_Type)
13189 and then Number_Dimensions (Expec_Type) = 1
13191 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
13193 -- Use type name if available. This excludes multidimensional
13194 -- arrays and anonymous arrays.
13196 if Comes_From_Source (Expec_Type) then
13197 Matching_Field := Expec_Type;
13199 -- For an assignment, use name of target
13201 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
13202 and then Is_Entity_Name (Name (Parent (Expr)))
13204 Matching_Field := Entity (Name (Parent (Expr)));
13209 elsif not Is_Record_Type (Expec_Type) then
13213 E := First_Entity (Expec_Type);
13218 elsif (Ekind (E) /= E_Discriminant
13219 and then Ekind (E) /= E_Component)
13220 or else (Chars (E) = Name_uTag
13221 or else Chars (E) = Name_uParent)
13230 if not Covers (Etype (E), Found_Type) then
13233 elsif Present (Next_Entity (E)) then
13237 Matching_Field := E;
13241 end Has_One_Matching_Field;
13243 -- Start of processing for Wrong_Type
13246 -- Don't output message if either type is Any_Type, or if a message
13247 -- has already been posted for this node. We need to do the latter
13248 -- check explicitly (it is ordinarily done in Errout), because we
13249 -- are using ! to force the output of the error messages.
13251 if Expec_Type = Any_Type
13252 or else Found_Type = Any_Type
13253 or else Error_Posted (Expr)
13257 -- If one of the types is a Taft-Amendment type and the other it its
13258 -- completion, it must be an illegal use of a TAT in the spec, for
13259 -- which an error was already emitted. Avoid cascaded errors.
13261 elsif Is_Incomplete_Type (Expec_Type)
13262 and then Has_Completion_In_Body (Expec_Type)
13263 and then Full_View (Expec_Type) = Etype (Expr)
13267 elsif Is_Incomplete_Type (Etype (Expr))
13268 and then Has_Completion_In_Body (Etype (Expr))
13269 and then Full_View (Etype (Expr)) = Expec_Type
13273 -- In an instance, there is an ongoing problem with completion of
13274 -- type derived from private types. Their structure is what Gigi
13275 -- expects, but the Etype is the parent type rather than the
13276 -- derived private type itself. Do not flag error in this case. The
13277 -- private completion is an entity without a parent, like an Itype.
13278 -- Similarly, full and partial views may be incorrect in the instance.
13279 -- There is no simple way to insure that it is consistent ???
13281 elsif In_Instance then
13282 if Etype (Etype (Expr)) = Etype (Expected_Type)
13284 (Has_Private_Declaration (Expected_Type)
13285 or else Has_Private_Declaration (Etype (Expr)))
13286 and then No (Parent (Expected_Type))
13292 -- An interesting special check. If the expression is parenthesized
13293 -- and its type corresponds to the type of the sole component of the
13294 -- expected record type, or to the component type of the expected one
13295 -- dimensional array type, then assume we have a bad aggregate attempt.
13297 if Nkind (Expr) in N_Subexpr
13298 and then Paren_Count (Expr) /= 0
13299 and then Has_One_Matching_Field
13301 Error_Msg_N ("positional aggregate cannot have one component", Expr);
13302 if Present (Matching_Field) then
13303 if Is_Array_Type (Expec_Type) then
13305 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
13309 ("\write instead `& ='> ...`", Expr, Matching_Field);
13313 -- Another special check, if we are looking for a pool-specific access
13314 -- type and we found an E_Access_Attribute_Type, then we have the case
13315 -- of an Access attribute being used in a context which needs a pool-
13316 -- specific type, which is never allowed. The one extra check we make
13317 -- is that the expected designated type covers the Found_Type.
13319 elsif Is_Access_Type (Expec_Type)
13320 and then Ekind (Found_Type) = E_Access_Attribute_Type
13321 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
13322 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
13324 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
13326 Error_Msg_N -- CODEFIX
13327 ("result must be general access type!", Expr);
13328 Error_Msg_NE -- CODEFIX
13329 ("add ALL to }!", Expr, Expec_Type);
13331 -- Another special check, if the expected type is an integer type,
13332 -- but the expression is of type System.Address, and the parent is
13333 -- an addition or subtraction operation whose left operand is the
13334 -- expression in question and whose right operand is of an integral
13335 -- type, then this is an attempt at address arithmetic, so give
13336 -- appropriate message.
13338 elsif Is_Integer_Type (Expec_Type)
13339 and then Is_RTE (Found_Type, RE_Address)
13340 and then (Nkind (Parent (Expr)) = N_Op_Add
13342 Nkind (Parent (Expr)) = N_Op_Subtract)
13343 and then Expr = Left_Opnd (Parent (Expr))
13344 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
13347 ("address arithmetic not predefined in package System",
13350 ("\possible missing with/use of System.Storage_Elements",
13354 -- If the expected type is an anonymous access type, as for access
13355 -- parameters and discriminants, the error is on the designated types.
13357 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
13358 if Comes_From_Source (Expec_Type) then
13359 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13362 ("expected an access type with designated}",
13363 Expr, Designated_Type (Expec_Type));
13366 if Is_Access_Type (Found_Type)
13367 and then not Comes_From_Source (Found_Type)
13370 ("\\found an access type with designated}!",
13371 Expr, Designated_Type (Found_Type));
13373 if From_With_Type (Found_Type) then
13374 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
13375 Error_Msg_Qual_Level := 99;
13376 Error_Msg_NE -- CODEFIX
13377 ("\\missing `WITH &;", Expr, Scope (Found_Type));
13378 Error_Msg_Qual_Level := 0;
13380 Error_Msg_NE ("found}!", Expr, Found_Type);
13384 -- Normal case of one type found, some other type expected
13387 -- If the names of the two types are the same, see if some number
13388 -- of levels of qualification will help. Don't try more than three
13389 -- levels, and if we get to standard, it's no use (and probably
13390 -- represents an error in the compiler) Also do not bother with
13391 -- internal scope names.
13394 Expec_Scope : Entity_Id;
13395 Found_Scope : Entity_Id;
13398 Expec_Scope := Expec_Type;
13399 Found_Scope := Found_Type;
13401 for Levels in Int range 0 .. 3 loop
13402 if Chars (Expec_Scope) /= Chars (Found_Scope) then
13403 Error_Msg_Qual_Level := Levels;
13407 Expec_Scope := Scope (Expec_Scope);
13408 Found_Scope := Scope (Found_Scope);
13410 exit when Expec_Scope = Standard_Standard
13411 or else Found_Scope = Standard_Standard
13412 or else not Comes_From_Source (Expec_Scope)
13413 or else not Comes_From_Source (Found_Scope);
13417 if Is_Record_Type (Expec_Type)
13418 and then Present (Corresponding_Remote_Type (Expec_Type))
13420 Error_Msg_NE ("expected}!", Expr,
13421 Corresponding_Remote_Type (Expec_Type));
13423 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13426 if Is_Entity_Name (Expr)
13427 and then Is_Package_Or_Generic_Package (Entity (Expr))
13429 Error_Msg_N ("\\found package name!", Expr);
13431 elsif Is_Entity_Name (Expr)
13433 (Ekind (Entity (Expr)) = E_Procedure
13435 Ekind (Entity (Expr)) = E_Generic_Procedure)
13437 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
13439 ("found procedure name, possibly missing Access attribute!",
13443 ("\\found procedure name instead of function!", Expr);
13446 elsif Nkind (Expr) = N_Function_Call
13447 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
13448 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
13449 and then No (Parameter_Associations (Expr))
13452 ("found function name, possibly missing Access attribute!",
13455 -- Catch common error: a prefix or infix operator which is not
13456 -- directly visible because the type isn't.
13458 elsif Nkind (Expr) in N_Op
13459 and then Is_Overloaded (Expr)
13460 and then not Is_Immediately_Visible (Expec_Type)
13461 and then not Is_Potentially_Use_Visible (Expec_Type)
13462 and then not In_Use (Expec_Type)
13463 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
13466 ("operator of the type is not directly visible!", Expr);
13468 elsif Ekind (Found_Type) = E_Void
13469 and then Present (Parent (Found_Type))
13470 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
13472 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
13475 Error_Msg_NE ("\\found}!", Expr, Found_Type);
13478 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
13479 -- of the same modular type, and (M1 and M2) = 0 was intended.
13481 if Expec_Type = Standard_Boolean
13482 and then Is_Modular_Integer_Type (Found_Type)
13483 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
13484 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
13487 Op : constant Node_Id := Right_Opnd (Parent (Expr));
13488 L : constant Node_Id := Left_Opnd (Op);
13489 R : constant Node_Id := Right_Opnd (Op);
13491 -- The case for the message is when the left operand of the
13492 -- comparison is the same modular type, or when it is an
13493 -- integer literal (or other universal integer expression),
13494 -- which would have been typed as the modular type if the
13495 -- parens had been there.
13497 if (Etype (L) = Found_Type
13499 Etype (L) = Universal_Integer)
13500 and then Is_Integer_Type (Etype (R))
13503 ("\\possible missing parens for modular operation", Expr);
13508 -- Reset error message qualification indication
13510 Error_Msg_Qual_Level := 0;