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))));
2440 -- For generic formal type, return Int'Last (infinite).
2441 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
2443 elsif Is_Generic_Type (Root_Type (Typ)) then
2444 return UI_From_Int (Int'Last);
2447 return Type_Access_Level (Typ);
2449 end Deepest_Type_Access_Level;
2451 ---------------------
2452 -- Defining_Entity --
2453 ---------------------
2455 function Defining_Entity (N : Node_Id) return Entity_Id is
2456 K : constant Node_Kind := Nkind (N);
2457 Err : Entity_Id := Empty;
2462 N_Subprogram_Declaration |
2463 N_Abstract_Subprogram_Declaration |
2465 N_Package_Declaration |
2466 N_Subprogram_Renaming_Declaration |
2467 N_Subprogram_Body_Stub |
2468 N_Generic_Subprogram_Declaration |
2469 N_Generic_Package_Declaration |
2470 N_Formal_Subprogram_Declaration |
2471 N_Expression_Function
2473 return Defining_Entity (Specification (N));
2476 N_Component_Declaration |
2477 N_Defining_Program_Unit_Name |
2478 N_Discriminant_Specification |
2480 N_Entry_Declaration |
2481 N_Entry_Index_Specification |
2482 N_Exception_Declaration |
2483 N_Exception_Renaming_Declaration |
2484 N_Formal_Object_Declaration |
2485 N_Formal_Package_Declaration |
2486 N_Formal_Type_Declaration |
2487 N_Full_Type_Declaration |
2488 N_Implicit_Label_Declaration |
2489 N_Incomplete_Type_Declaration |
2490 N_Loop_Parameter_Specification |
2491 N_Number_Declaration |
2492 N_Object_Declaration |
2493 N_Object_Renaming_Declaration |
2494 N_Package_Body_Stub |
2495 N_Parameter_Specification |
2496 N_Private_Extension_Declaration |
2497 N_Private_Type_Declaration |
2499 N_Protected_Body_Stub |
2500 N_Protected_Type_Declaration |
2501 N_Single_Protected_Declaration |
2502 N_Single_Task_Declaration |
2503 N_Subtype_Declaration |
2506 N_Task_Type_Declaration
2508 return Defining_Identifier (N);
2511 return Defining_Entity (Proper_Body (N));
2514 N_Function_Instantiation |
2515 N_Function_Specification |
2516 N_Generic_Function_Renaming_Declaration |
2517 N_Generic_Package_Renaming_Declaration |
2518 N_Generic_Procedure_Renaming_Declaration |
2520 N_Package_Instantiation |
2521 N_Package_Renaming_Declaration |
2522 N_Package_Specification |
2523 N_Procedure_Instantiation |
2524 N_Procedure_Specification
2527 Nam : constant Node_Id := Defining_Unit_Name (N);
2530 if Nkind (Nam) in N_Entity then
2533 -- For Error, make up a name and attach to declaration
2534 -- so we can continue semantic analysis
2536 elsif Nam = Error then
2537 Err := Make_Temporary (Sloc (N), 'T');
2538 Set_Defining_Unit_Name (N, Err);
2541 -- If not an entity, get defining identifier
2544 return Defining_Identifier (Nam);
2548 when N_Block_Statement =>
2549 return Entity (Identifier (N));
2552 raise Program_Error;
2555 end Defining_Entity;
2557 --------------------------
2558 -- Denotes_Discriminant --
2559 --------------------------
2561 function Denotes_Discriminant
2563 Check_Concurrent : Boolean := False) return Boolean
2567 if not Is_Entity_Name (N)
2568 or else No (Entity (N))
2575 -- If we are checking for a protected type, the discriminant may have
2576 -- been rewritten as the corresponding discriminal of the original type
2577 -- or of the corresponding concurrent record, depending on whether we
2578 -- are in the spec or body of the protected type.
2580 return Ekind (E) = E_Discriminant
2583 and then Ekind (E) = E_In_Parameter
2584 and then Present (Discriminal_Link (E))
2586 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2588 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2590 end Denotes_Discriminant;
2592 -------------------------
2593 -- Denotes_Same_Object --
2594 -------------------------
2596 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2597 Obj1 : Node_Id := A1;
2598 Obj2 : Node_Id := A2;
2600 procedure Check_Renaming (Obj : in out Node_Id);
2601 -- If an object is a renaming, examine renamed object. If it is a
2602 -- dereference of a variable, or an indexed expression with non-constant
2603 -- indexes, no overlap check can be reported.
2605 --------------------
2606 -- Check_Renaming --
2607 --------------------
2609 procedure Check_Renaming (Obj : in out Node_Id) is
2611 if Is_Entity_Name (Obj)
2612 and then Present (Renamed_Entity (Entity (Obj)))
2614 Obj := Renamed_Entity (Entity (Obj));
2615 if Nkind (Obj) = N_Explicit_Dereference
2616 and then Is_Variable (Prefix (Obj))
2620 elsif Nkind (Obj) = N_Indexed_Component then
2625 Indx := First (Expressions (Obj));
2626 while Present (Indx) loop
2627 if not Is_OK_Static_Expression (Indx) then
2639 -- Start of processing for Denotes_Same_Object
2642 Check_Renaming (Obj1);
2643 Check_Renaming (Obj2);
2651 -- If we have entity names, then must be same entity
2653 if Is_Entity_Name (Obj1) then
2654 if Is_Entity_Name (Obj2) then
2655 return Entity (Obj1) = Entity (Obj2);
2660 -- No match if not same node kind
2662 elsif Nkind (Obj1) /= Nkind (Obj2) then
2665 -- For selected components, must have same prefix and selector
2667 elsif Nkind (Obj1) = N_Selected_Component then
2668 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2670 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2672 -- For explicit dereferences, prefixes must be same
2674 elsif Nkind (Obj1) = N_Explicit_Dereference then
2675 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2677 -- For indexed components, prefixes and all subscripts must be the same
2679 elsif Nkind (Obj1) = N_Indexed_Component then
2680 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2686 Indx1 := First (Expressions (Obj1));
2687 Indx2 := First (Expressions (Obj2));
2688 while Present (Indx1) loop
2690 -- Indexes must denote the same static value or same object
2692 if Is_OK_Static_Expression (Indx1) then
2693 if not Is_OK_Static_Expression (Indx2) then
2696 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2700 elsif not Denotes_Same_Object (Indx1, Indx2) then
2714 -- For slices, prefixes must match and bounds must match
2716 elsif Nkind (Obj1) = N_Slice
2717 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2720 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2723 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2724 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2726 -- Check whether bounds are statically identical. There is no
2727 -- attempt to detect partial overlap of slices.
2729 return Denotes_Same_Object (Lo1, Lo2)
2730 and then Denotes_Same_Object (Hi1, Hi2);
2733 -- Literals will appear as indexes. Isn't this where we should check
2734 -- Known_At_Compile_Time at least if we are generating warnings ???
2736 elsif Nkind (Obj1) = N_Integer_Literal then
2737 return Intval (Obj1) = Intval (Obj2);
2742 end Denotes_Same_Object;
2744 -------------------------
2745 -- Denotes_Same_Prefix --
2746 -------------------------
2748 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2751 if Is_Entity_Name (A1) then
2752 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2753 and then not Is_Access_Type (Etype (A1))
2755 return Denotes_Same_Object (A1, Prefix (A2))
2756 or else Denotes_Same_Prefix (A1, Prefix (A2));
2761 elsif Is_Entity_Name (A2) then
2762 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
2764 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2766 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2769 Root1, Root2 : Node_Id;
2770 Depth1, Depth2 : Int := 0;
2773 Root1 := Prefix (A1);
2774 while not Is_Entity_Name (Root1) loop
2776 (Root1, N_Selected_Component, N_Indexed_Component)
2780 Root1 := Prefix (Root1);
2783 Depth1 := Depth1 + 1;
2786 Root2 := Prefix (A2);
2787 while not Is_Entity_Name (Root2) loop
2789 (Root2, N_Selected_Component, N_Indexed_Component)
2793 Root2 := Prefix (Root2);
2796 Depth2 := Depth2 + 1;
2799 -- If both have the same depth and they do not denote the same
2800 -- object, they are disjoint and not warning is needed.
2802 if Depth1 = Depth2 then
2805 elsif Depth1 > Depth2 then
2806 Root1 := Prefix (A1);
2807 for I in 1 .. Depth1 - Depth2 - 1 loop
2808 Root1 := Prefix (Root1);
2811 return Denotes_Same_Object (Root1, A2);
2814 Root2 := Prefix (A2);
2815 for I in 1 .. Depth2 - Depth1 - 1 loop
2816 Root2 := Prefix (Root2);
2819 return Denotes_Same_Object (A1, Root2);
2826 end Denotes_Same_Prefix;
2828 ----------------------
2829 -- Denotes_Variable --
2830 ----------------------
2832 function Denotes_Variable (N : Node_Id) return Boolean is
2834 return Is_Variable (N) and then Paren_Count (N) = 0;
2835 end Denotes_Variable;
2837 -----------------------------
2838 -- Depends_On_Discriminant --
2839 -----------------------------
2841 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2846 Get_Index_Bounds (N, L, H);
2847 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2848 end Depends_On_Discriminant;
2850 -------------------------
2851 -- Designate_Same_Unit --
2852 -------------------------
2854 function Designate_Same_Unit
2856 Name2 : Node_Id) return Boolean
2858 K1 : constant Node_Kind := Nkind (Name1);
2859 K2 : constant Node_Kind := Nkind (Name2);
2861 function Prefix_Node (N : Node_Id) return Node_Id;
2862 -- Returns the parent unit name node of a defining program unit name
2863 -- or the prefix if N is a selected component or an expanded name.
2865 function Select_Node (N : Node_Id) return Node_Id;
2866 -- Returns the defining identifier node of a defining program unit
2867 -- name or the selector node if N is a selected component or an
2874 function Prefix_Node (N : Node_Id) return Node_Id is
2876 if Nkind (N) = N_Defining_Program_Unit_Name then
2888 function Select_Node (N : Node_Id) return Node_Id is
2890 if Nkind (N) = N_Defining_Program_Unit_Name then
2891 return Defining_Identifier (N);
2894 return Selector_Name (N);
2898 -- Start of processing for Designate_Next_Unit
2901 if (K1 = N_Identifier or else
2902 K1 = N_Defining_Identifier)
2904 (K2 = N_Identifier or else
2905 K2 = N_Defining_Identifier)
2907 return Chars (Name1) = Chars (Name2);
2910 (K1 = N_Expanded_Name or else
2911 K1 = N_Selected_Component or else
2912 K1 = N_Defining_Program_Unit_Name)
2914 (K2 = N_Expanded_Name or else
2915 K2 = N_Selected_Component or else
2916 K2 = N_Defining_Program_Unit_Name)
2919 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2921 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2926 end Designate_Same_Unit;
2928 ------------------------------------------
2929 -- function Dynamic_Accessibility_Level --
2930 ------------------------------------------
2932 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
2934 Loc : constant Source_Ptr := Sloc (Expr);
2936 function Make_Level_Literal (Level : Uint) return Node_Id;
2937 -- Construct an integer literal representing an accessibility level
2938 -- with its type set to Natural.
2940 ------------------------
2941 -- Make_Level_Literal --
2942 ------------------------
2944 function Make_Level_Literal (Level : Uint) return Node_Id is
2945 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
2947 Set_Etype (Result, Standard_Natural);
2949 end Make_Level_Literal;
2951 -- Start of processing for Dynamic_Accessibility_Level
2954 if Is_Entity_Name (Expr) then
2957 if Present (Renamed_Object (E)) then
2958 return Dynamic_Accessibility_Level (Renamed_Object (E));
2961 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
2962 if Present (Extra_Accessibility (E)) then
2963 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
2968 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
2970 case Nkind (Expr) is
2972 -- For access discriminant, the level of the enclosing object
2974 when N_Selected_Component =>
2975 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
2976 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
2977 E_Anonymous_Access_Type
2979 return Make_Level_Literal (Object_Access_Level (Expr));
2982 when N_Attribute_Reference =>
2983 case Get_Attribute_Id (Attribute_Name (Expr)) is
2985 -- For X'Access, the level of the prefix X
2987 when Attribute_Access =>
2988 return Make_Level_Literal
2989 (Object_Access_Level (Prefix (Expr)));
2991 -- Treat the unchecked attributes as library-level
2993 when Attribute_Unchecked_Access |
2994 Attribute_Unrestricted_Access =>
2995 return Make_Level_Literal (Scope_Depth (Standard_Standard));
2997 -- No other access-valued attributes
3000 raise Program_Error;
3005 -- Unimplemented: depends on context. As an actual parameter where
3006 -- formal type is anonymous, use
3007 -- Scope_Depth (Current_Scope) + 1.
3008 -- For other cases, see 3.10.2(14/3) and following. ???
3012 when N_Type_Conversion =>
3013 if not Is_Local_Anonymous_Access (Etype (Expr)) then
3015 -- Handle type conversions introduced for a rename of an
3016 -- Ada 2012 stand-alone object of an anonymous access type.
3018 return Dynamic_Accessibility_Level (Expression (Expr));
3025 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
3026 end Dynamic_Accessibility_Level;
3028 -----------------------------------
3029 -- Effective_Extra_Accessibility --
3030 -----------------------------------
3032 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
3034 if Present (Renamed_Object (Id))
3035 and then Is_Entity_Name (Renamed_Object (Id))
3037 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
3040 return Extra_Accessibility (Id);
3041 end Effective_Extra_Accessibility;
3043 --------------------------
3044 -- Enclosing_CPP_Parent --
3045 --------------------------
3047 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
3048 Parent_Typ : Entity_Id := Typ;
3051 while not Is_CPP_Class (Parent_Typ)
3052 and then Etype (Parent_Typ) /= Parent_Typ
3054 Parent_Typ := Etype (Parent_Typ);
3056 if Is_Private_Type (Parent_Typ) then
3057 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3061 pragma Assert (Is_CPP_Class (Parent_Typ));
3063 end Enclosing_CPP_Parent;
3065 ----------------------------
3066 -- Enclosing_Generic_Body --
3067 ----------------------------
3069 function Enclosing_Generic_Body
3070 (N : Node_Id) return Node_Id
3078 while Present (P) loop
3079 if Nkind (P) = N_Package_Body
3080 or else Nkind (P) = N_Subprogram_Body
3082 Spec := Corresponding_Spec (P);
3084 if Present (Spec) then
3085 Decl := Unit_Declaration_Node (Spec);
3087 if Nkind (Decl) = N_Generic_Package_Declaration
3088 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3099 end Enclosing_Generic_Body;
3101 ----------------------------
3102 -- Enclosing_Generic_Unit --
3103 ----------------------------
3105 function Enclosing_Generic_Unit
3106 (N : Node_Id) return Node_Id
3114 while Present (P) loop
3115 if Nkind (P) = N_Generic_Package_Declaration
3116 or else Nkind (P) = N_Generic_Subprogram_Declaration
3120 elsif Nkind (P) = N_Package_Body
3121 or else Nkind (P) = N_Subprogram_Body
3123 Spec := Corresponding_Spec (P);
3125 if Present (Spec) then
3126 Decl := Unit_Declaration_Node (Spec);
3128 if Nkind (Decl) = N_Generic_Package_Declaration
3129 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3140 end Enclosing_Generic_Unit;
3142 -------------------------------
3143 -- Enclosing_Lib_Unit_Entity --
3144 -------------------------------
3146 function Enclosing_Lib_Unit_Entity return Entity_Id is
3147 Unit_Entity : Entity_Id;
3150 -- Look for enclosing library unit entity by following scope links.
3151 -- Equivalent to, but faster than indexing through the scope stack.
3153 Unit_Entity := Current_Scope;
3154 while (Present (Scope (Unit_Entity))
3155 and then Scope (Unit_Entity) /= Standard_Standard)
3156 and not Is_Child_Unit (Unit_Entity)
3158 Unit_Entity := Scope (Unit_Entity);
3162 end Enclosing_Lib_Unit_Entity;
3164 -----------------------------
3165 -- Enclosing_Lib_Unit_Node --
3166 -----------------------------
3168 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
3169 Current_Node : Node_Id;
3173 while Present (Current_Node)
3174 and then Nkind (Current_Node) /= N_Compilation_Unit
3176 Current_Node := Parent (Current_Node);
3179 if Nkind (Current_Node) /= N_Compilation_Unit then
3183 return Current_Node;
3184 end Enclosing_Lib_Unit_Node;
3186 -----------------------
3187 -- Enclosing_Package --
3188 -----------------------
3190 function Enclosing_Package (E : Entity_Id) return Entity_Id is
3191 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3194 if Dynamic_Scope = Standard_Standard then
3195 return Standard_Standard;
3197 elsif Dynamic_Scope = Empty then
3200 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
3203 return Dynamic_Scope;
3206 return Enclosing_Package (Dynamic_Scope);
3208 end Enclosing_Package;
3210 --------------------------
3211 -- Enclosing_Subprogram --
3212 --------------------------
3214 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3215 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3218 if Dynamic_Scope = Standard_Standard then
3221 elsif Dynamic_Scope = Empty then
3224 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3225 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3227 elsif Ekind (Dynamic_Scope) = E_Block
3228 or else Ekind (Dynamic_Scope) = E_Return_Statement
3230 return Enclosing_Subprogram (Dynamic_Scope);
3232 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3233 return Get_Task_Body_Procedure (Dynamic_Scope);
3235 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3236 and then Present (Full_View (Dynamic_Scope))
3237 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3239 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3241 -- No body is generated if the protected operation is eliminated
3243 elsif Convention (Dynamic_Scope) = Convention_Protected
3244 and then not Is_Eliminated (Dynamic_Scope)
3245 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3247 return Protected_Body_Subprogram (Dynamic_Scope);
3250 return Dynamic_Scope;
3252 end Enclosing_Subprogram;
3254 ------------------------
3255 -- Ensure_Freeze_Node --
3256 ------------------------
3258 procedure Ensure_Freeze_Node (E : Entity_Id) is
3262 if No (Freeze_Node (E)) then
3263 FN := Make_Freeze_Entity (Sloc (E));
3264 Set_Has_Delayed_Freeze (E);
3265 Set_Freeze_Node (E, FN);
3266 Set_Access_Types_To_Process (FN, No_Elist);
3267 Set_TSS_Elist (FN, No_Elist);
3270 end Ensure_Freeze_Node;
3276 procedure Enter_Name (Def_Id : Entity_Id) is
3277 C : constant Entity_Id := Current_Entity (Def_Id);
3278 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3279 S : constant Entity_Id := Current_Scope;
3282 Generate_Definition (Def_Id);
3284 -- Add new name to current scope declarations. Check for duplicate
3285 -- declaration, which may or may not be a genuine error.
3289 -- Case of previous entity entered because of a missing declaration
3290 -- or else a bad subtype indication. Best is to use the new entity,
3291 -- and make the previous one invisible.
3293 if Etype (E) = Any_Type then
3294 Set_Is_Immediately_Visible (E, False);
3296 -- Case of renaming declaration constructed for package instances.
3297 -- if there is an explicit declaration with the same identifier,
3298 -- the renaming is not immediately visible any longer, but remains
3299 -- visible through selected component notation.
3301 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3302 and then not Comes_From_Source (E)
3304 Set_Is_Immediately_Visible (E, False);
3306 -- The new entity may be the package renaming, which has the same
3307 -- same name as a generic formal which has been seen already.
3309 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3310 and then not Comes_From_Source (Def_Id)
3312 Set_Is_Immediately_Visible (E, False);
3314 -- For a fat pointer corresponding to a remote access to subprogram,
3315 -- we use the same identifier as the RAS type, so that the proper
3316 -- name appears in the stub. This type is only retrieved through
3317 -- the RAS type and never by visibility, and is not added to the
3318 -- visibility list (see below).
3320 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3321 and then Present (Corresponding_Remote_Type (Def_Id))
3325 -- Case of an implicit operation or derived literal. The new entity
3326 -- hides the implicit one, which is removed from all visibility,
3327 -- i.e. the entity list of its scope, and homonym chain of its name.
3329 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3330 or else Is_Internal (E)
3334 Prev_Vis : Entity_Id;
3335 Decl : constant Node_Id := Parent (E);
3338 -- If E is an implicit declaration, it cannot be the first
3339 -- entity in the scope.
3341 Prev := First_Entity (Current_Scope);
3342 while Present (Prev)
3343 and then Next_Entity (Prev) /= E
3350 -- If E is not on the entity chain of the current scope,
3351 -- it is an implicit declaration in the generic formal
3352 -- part of a generic subprogram. When analyzing the body,
3353 -- the generic formals are visible but not on the entity
3354 -- chain of the subprogram. The new entity will become
3355 -- the visible one in the body.
3358 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3362 Set_Next_Entity (Prev, Next_Entity (E));
3364 if No (Next_Entity (Prev)) then
3365 Set_Last_Entity (Current_Scope, Prev);
3368 if E = Current_Entity (E) then
3372 Prev_Vis := Current_Entity (E);
3373 while Homonym (Prev_Vis) /= E loop
3374 Prev_Vis := Homonym (Prev_Vis);
3378 if Present (Prev_Vis) then
3380 -- Skip E in the visibility chain
3382 Set_Homonym (Prev_Vis, Homonym (E));
3385 Set_Name_Entity_Id (Chars (E), Homonym (E));
3390 -- This section of code could use a comment ???
3392 elsif Present (Etype (E))
3393 and then Is_Concurrent_Type (Etype (E))
3398 -- If the homograph is a protected component renaming, it should not
3399 -- be hiding the current entity. Such renamings are treated as weak
3402 elsif Is_Prival (E) then
3403 Set_Is_Immediately_Visible (E, False);
3405 -- In this case the current entity is a protected component renaming.
3406 -- Perform minimal decoration by setting the scope and return since
3407 -- the prival should not be hiding other visible entities.
3409 elsif Is_Prival (Def_Id) then
3410 Set_Scope (Def_Id, Current_Scope);
3413 -- Analogous to privals, the discriminal generated for an entry index
3414 -- parameter acts as a weak declaration. Perform minimal decoration
3415 -- to avoid bogus errors.
3417 elsif Is_Discriminal (Def_Id)
3418 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3420 Set_Scope (Def_Id, Current_Scope);
3423 -- In the body or private part of an instance, a type extension may
3424 -- introduce a component with the same name as that of an actual. The
3425 -- legality rule is not enforced, but the semantics of the full type
3426 -- with two components of same name are not clear at this point???
3428 elsif In_Instance_Not_Visible then
3431 -- When compiling a package body, some child units may have become
3432 -- visible. They cannot conflict with local entities that hide them.
3434 elsif Is_Child_Unit (E)
3435 and then In_Open_Scopes (Scope (E))
3436 and then not Is_Immediately_Visible (E)
3440 -- Conversely, with front-end inlining we may compile the parent body
3441 -- first, and a child unit subsequently. The context is now the
3442 -- parent spec, and body entities are not visible.
3444 elsif Is_Child_Unit (Def_Id)
3445 and then Is_Package_Body_Entity (E)
3446 and then not In_Package_Body (Current_Scope)
3450 -- Case of genuine duplicate declaration
3453 Error_Msg_Sloc := Sloc (E);
3455 -- If the previous declaration is an incomplete type declaration
3456 -- this may be an attempt to complete it with a private type. The
3457 -- following avoids confusing cascaded errors.
3459 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3460 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3463 ("incomplete type cannot be completed with a private " &
3464 "declaration", Parent (Def_Id));
3465 Set_Is_Immediately_Visible (E, False);
3466 Set_Full_View (E, Def_Id);
3468 -- An inherited component of a record conflicts with a new
3469 -- discriminant. The discriminant is inserted first in the scope,
3470 -- but the error should be posted on it, not on the component.
3472 elsif Ekind (E) = E_Discriminant
3473 and then Present (Scope (Def_Id))
3474 and then Scope (Def_Id) /= Current_Scope
3476 Error_Msg_Sloc := Sloc (Def_Id);
3477 Error_Msg_N ("& conflicts with declaration#", E);
3480 -- If the name of the unit appears in its own context clause, a
3481 -- dummy package with the name has already been created, and the
3482 -- error emitted. Try to continue quietly.
3484 elsif Error_Posted (E)
3485 and then Sloc (E) = No_Location
3486 and then Nkind (Parent (E)) = N_Package_Specification
3487 and then Current_Scope = Standard_Standard
3489 Set_Scope (Def_Id, Current_Scope);
3493 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3495 -- Avoid cascaded messages with duplicate components in
3498 if Ekind_In (E, E_Component, E_Discriminant) then
3503 if Nkind (Parent (Parent (Def_Id))) =
3504 N_Generic_Subprogram_Declaration
3506 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3508 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3511 -- If entity is in standard, then we are in trouble, because it
3512 -- means that we have a library package with a duplicated name.
3513 -- That's hard to recover from, so abort!
3515 if S = Standard_Standard then
3516 raise Unrecoverable_Error;
3518 -- Otherwise we continue with the declaration. Having two
3519 -- identical declarations should not cause us too much trouble!
3527 -- If we fall through, declaration is OK, at least OK enough to continue
3529 -- If Def_Id is a discriminant or a record component we are in the midst
3530 -- of inheriting components in a derived record definition. Preserve
3531 -- their Ekind and Etype.
3533 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3536 -- If a type is already set, leave it alone (happens when a type
3537 -- declaration is reanalyzed following a call to the optimizer).
3539 elsif Present (Etype (Def_Id)) then
3542 -- Otherwise, the kind E_Void insures that premature uses of the entity
3543 -- will be detected. Any_Type insures that no cascaded errors will occur
3546 Set_Ekind (Def_Id, E_Void);
3547 Set_Etype (Def_Id, Any_Type);
3550 -- Inherited discriminants and components in derived record types are
3551 -- immediately visible. Itypes are not.
3553 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3554 or else (No (Corresponding_Remote_Type (Def_Id))
3555 and then not Is_Itype (Def_Id))
3557 Set_Is_Immediately_Visible (Def_Id);
3558 Set_Current_Entity (Def_Id);
3561 Set_Homonym (Def_Id, C);
3562 Append_Entity (Def_Id, S);
3563 Set_Public_Status (Def_Id);
3565 -- Declaring a homonym is not allowed in SPARK ...
3568 and then Restriction_Check_Required (SPARK)
3572 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3573 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3574 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3577 -- ... unless the new declaration is in a subprogram, and the
3578 -- visible declaration is a variable declaration or a parameter
3579 -- specification outside that subprogram.
3581 if Present (Enclosing_Subp)
3582 and then Nkind_In (Parent (C), N_Object_Declaration,
3583 N_Parameter_Specification)
3584 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3588 -- ... or the new declaration is in a package, and the visible
3589 -- declaration occurs outside that package.
3591 elsif Present (Enclosing_Pack)
3592 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3596 -- ... or the new declaration is a component declaration in a
3597 -- record type definition.
3599 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3602 -- Don't issue error for non-source entities
3604 elsif Comes_From_Source (Def_Id)
3605 and then Comes_From_Source (C)
3607 Error_Msg_Sloc := Sloc (C);
3608 Check_SPARK_Restriction
3609 ("redeclaration of identifier &#", Def_Id);
3614 -- Warn if new entity hides an old one
3616 if Warn_On_Hiding and then Present (C)
3618 -- Don't warn for record components since they always have a well
3619 -- defined scope which does not confuse other uses. Note that in
3620 -- some cases, Ekind has not been set yet.
3622 and then Ekind (C) /= E_Component
3623 and then Ekind (C) /= E_Discriminant
3624 and then Nkind (Parent (C)) /= N_Component_Declaration
3625 and then Ekind (Def_Id) /= E_Component
3626 and then Ekind (Def_Id) /= E_Discriminant
3627 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3629 -- Don't warn for one character variables. It is too common to use
3630 -- such variables as locals and will just cause too many false hits.
3632 and then Length_Of_Name (Chars (C)) /= 1
3634 -- Don't warn for non-source entities
3636 and then Comes_From_Source (C)
3637 and then Comes_From_Source (Def_Id)
3639 -- Don't warn unless entity in question is in extended main source
3641 and then In_Extended_Main_Source_Unit (Def_Id)
3643 -- Finally, the hidden entity must be either immediately visible or
3644 -- use visible (i.e. from a used package).
3647 (Is_Immediately_Visible (C)
3649 Is_Potentially_Use_Visible (C))
3651 Error_Msg_Sloc := Sloc (C);
3652 Error_Msg_N ("declaration hides &#?", Def_Id);
3656 --------------------------
3657 -- Explain_Limited_Type --
3658 --------------------------
3660 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3664 -- For array, component type must be limited
3666 if Is_Array_Type (T) then
3667 Error_Msg_Node_2 := T;
3669 ("\component type& of type& is limited", N, Component_Type (T));
3670 Explain_Limited_Type (Component_Type (T), N);
3672 elsif Is_Record_Type (T) then
3674 -- No need for extra messages if explicit limited record
3676 if Is_Limited_Record (Base_Type (T)) then
3680 -- Otherwise find a limited component. Check only components that
3681 -- come from source, or inherited components that appear in the
3682 -- source of the ancestor.
3684 C := First_Component (T);
3685 while Present (C) loop
3686 if Is_Limited_Type (Etype (C))
3688 (Comes_From_Source (C)
3690 (Present (Original_Record_Component (C))
3692 Comes_From_Source (Original_Record_Component (C))))
3694 Error_Msg_Node_2 := T;
3695 Error_Msg_NE ("\component& of type& has limited type", N, C);
3696 Explain_Limited_Type (Etype (C), N);
3703 -- The type may be declared explicitly limited, even if no component
3704 -- of it is limited, in which case we fall out of the loop.
3707 end Explain_Limited_Type;
3713 procedure Find_Actual
3715 Formal : out Entity_Id;
3718 Parnt : constant Node_Id := Parent (N);
3722 if (Nkind (Parnt) = N_Indexed_Component
3724 Nkind (Parnt) = N_Selected_Component)
3725 and then N = Prefix (Parnt)
3727 Find_Actual (Parnt, Formal, Call);
3730 elsif Nkind (Parnt) = N_Parameter_Association
3731 and then N = Explicit_Actual_Parameter (Parnt)
3733 Call := Parent (Parnt);
3735 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3744 -- If we have a call to a subprogram look for the parameter. Note that
3745 -- we exclude overloaded calls, since we don't know enough to be sure
3746 -- of giving the right answer in this case.
3748 if Is_Entity_Name (Name (Call))
3749 and then Present (Entity (Name (Call)))
3750 and then Is_Overloadable (Entity (Name (Call)))
3751 and then not Is_Overloaded (Name (Call))
3753 -- Fall here if we are definitely a parameter
3755 Actual := First_Actual (Call);
3756 Formal := First_Formal (Entity (Name (Call)));
3757 while Present (Formal) and then Present (Actual) loop
3761 Actual := Next_Actual (Actual);
3762 Formal := Next_Formal (Formal);
3767 -- Fall through here if we did not find matching actual
3773 ---------------------------
3774 -- Find_Body_Discriminal --
3775 ---------------------------
3777 function Find_Body_Discriminal
3778 (Spec_Discriminant : Entity_Id) return Entity_Id
3784 -- If expansion is suppressed, then the scope can be the concurrent type
3785 -- itself rather than a corresponding concurrent record type.
3787 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
3788 Tsk := Scope (Spec_Discriminant);
3791 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3793 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3796 -- Find discriminant of original concurrent type, and use its current
3797 -- discriminal, which is the renaming within the task/protected body.
3799 Disc := First_Discriminant (Tsk);
3800 while Present (Disc) loop
3801 if Chars (Disc) = Chars (Spec_Discriminant) then
3802 return Discriminal (Disc);
3805 Next_Discriminant (Disc);
3808 -- That loop should always succeed in finding a matching entry and
3809 -- returning. Fatal error if not.
3811 raise Program_Error;
3812 end Find_Body_Discriminal;
3814 -------------------------------------
3815 -- Find_Corresponding_Discriminant --
3816 -------------------------------------
3818 function Find_Corresponding_Discriminant
3820 Typ : Entity_Id) return Entity_Id
3822 Par_Disc : Entity_Id;
3823 Old_Disc : Entity_Id;
3824 New_Disc : Entity_Id;
3827 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3829 -- The original type may currently be private, and the discriminant
3830 -- only appear on its full view.
3832 if Is_Private_Type (Scope (Par_Disc))
3833 and then not Has_Discriminants (Scope (Par_Disc))
3834 and then Present (Full_View (Scope (Par_Disc)))
3836 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3838 Old_Disc := First_Discriminant (Scope (Par_Disc));
3841 if Is_Class_Wide_Type (Typ) then
3842 New_Disc := First_Discriminant (Root_Type (Typ));
3844 New_Disc := First_Discriminant (Typ);
3847 while Present (Old_Disc) and then Present (New_Disc) loop
3848 if Old_Disc = Par_Disc then
3851 Next_Discriminant (Old_Disc);
3852 Next_Discriminant (New_Disc);
3856 -- Should always find it
3858 raise Program_Error;
3859 end Find_Corresponding_Discriminant;
3861 --------------------------
3862 -- Find_Overlaid_Entity --
3863 --------------------------
3865 procedure Find_Overlaid_Entity
3867 Ent : out Entity_Id;
3873 -- We are looking for one of the two following forms:
3875 -- for X'Address use Y'Address
3879 -- Const : constant Address := expr;
3881 -- for X'Address use Const;
3883 -- In the second case, the expr is either Y'Address, or recursively a
3884 -- constant that eventually references Y'Address.
3889 if Nkind (N) = N_Attribute_Definition_Clause
3890 and then Chars (N) = Name_Address
3892 Expr := Expression (N);
3894 -- This loop checks the form of the expression for Y'Address,
3895 -- using recursion to deal with intermediate constants.
3898 -- Check for Y'Address
3900 if Nkind (Expr) = N_Attribute_Reference
3901 and then Attribute_Name (Expr) = Name_Address
3903 Expr := Prefix (Expr);
3906 -- Check for Const where Const is a constant entity
3908 elsif Is_Entity_Name (Expr)
3909 and then Ekind (Entity (Expr)) = E_Constant
3911 Expr := Constant_Value (Entity (Expr));
3913 -- Anything else does not need checking
3920 -- This loop checks the form of the prefix for an entity, using
3921 -- recursion to deal with intermediate components.
3924 -- Check for Y where Y is an entity
3926 if Is_Entity_Name (Expr) then
3927 Ent := Entity (Expr);
3930 -- Check for components
3933 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
3935 Expr := Prefix (Expr);
3938 -- Anything else does not need checking
3945 end Find_Overlaid_Entity;
3947 -------------------------
3948 -- Find_Parameter_Type --
3949 -------------------------
3951 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3953 if Nkind (Param) /= N_Parameter_Specification then
3956 -- For an access parameter, obtain the type from the formal entity
3957 -- itself, because access to subprogram nodes do not carry a type.
3958 -- Shouldn't we always use the formal entity ???
3960 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3961 return Etype (Defining_Identifier (Param));
3964 return Etype (Parameter_Type (Param));
3966 end Find_Parameter_Type;
3968 -----------------------------
3969 -- Find_Static_Alternative --
3970 -----------------------------
3972 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3973 Expr : constant Node_Id := Expression (N);
3974 Val : constant Uint := Expr_Value (Expr);
3979 Alt := First (Alternatives (N));
3982 if Nkind (Alt) /= N_Pragma then
3983 Choice := First (Discrete_Choices (Alt));
3984 while Present (Choice) loop
3986 -- Others choice, always matches
3988 if Nkind (Choice) = N_Others_Choice then
3991 -- Range, check if value is in the range
3993 elsif Nkind (Choice) = N_Range then
3995 Val >= Expr_Value (Low_Bound (Choice))
3997 Val <= Expr_Value (High_Bound (Choice));
3999 -- Choice is a subtype name. Note that we know it must
4000 -- be a static subtype, since otherwise it would have
4001 -- been diagnosed as illegal.
4003 elsif Is_Entity_Name (Choice)
4004 and then Is_Type (Entity (Choice))
4006 exit Search when Is_In_Range (Expr, Etype (Choice),
4007 Assume_Valid => False);
4009 -- Choice is a subtype indication
4011 elsif Nkind (Choice) = N_Subtype_Indication then
4013 C : constant Node_Id := Constraint (Choice);
4014 R : constant Node_Id := Range_Expression (C);
4018 Val >= Expr_Value (Low_Bound (R))
4020 Val <= Expr_Value (High_Bound (R));
4023 -- Choice is a simple expression
4026 exit Search when Val = Expr_Value (Choice);
4034 pragma Assert (Present (Alt));
4037 -- The above loop *must* terminate by finding a match, since
4038 -- we know the case statement is valid, and the value of the
4039 -- expression is known at compile time. When we fall out of
4040 -- the loop, Alt points to the alternative that we know will
4041 -- be selected at run time.
4044 end Find_Static_Alternative;
4050 function First_Actual (Node : Node_Id) return Node_Id is
4054 if No (Parameter_Associations (Node)) then
4058 N := First (Parameter_Associations (Node));
4060 if Nkind (N) = N_Parameter_Association then
4061 return First_Named_Actual (Node);
4067 -----------------------
4068 -- Gather_Components --
4069 -----------------------
4071 procedure Gather_Components
4073 Comp_List : Node_Id;
4074 Governed_By : List_Id;
4076 Report_Errors : out Boolean)
4080 Discrete_Choice : Node_Id;
4081 Comp_Item : Node_Id;
4083 Discrim : Entity_Id;
4084 Discrim_Name : Node_Id;
4085 Discrim_Value : Node_Id;
4088 Report_Errors := False;
4090 if No (Comp_List) or else Null_Present (Comp_List) then
4093 elsif Present (Component_Items (Comp_List)) then
4094 Comp_Item := First (Component_Items (Comp_List));
4100 while Present (Comp_Item) loop
4102 -- Skip the tag of a tagged record, the interface tags, as well
4103 -- as all items that are not user components (anonymous types,
4104 -- rep clauses, Parent field, controller field).
4106 if Nkind (Comp_Item) = N_Component_Declaration then
4108 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
4110 if not Is_Tag (Comp)
4111 and then Chars (Comp) /= Name_uParent
4113 Append_Elmt (Comp, Into);
4121 if No (Variant_Part (Comp_List)) then
4124 Discrim_Name := Name (Variant_Part (Comp_List));
4125 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
4128 -- Look for the discriminant that governs this variant part.
4129 -- The discriminant *must* be in the Governed_By List
4131 Assoc := First (Governed_By);
4132 Find_Constraint : loop
4133 Discrim := First (Choices (Assoc));
4134 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
4135 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
4137 Chars (Corresponding_Discriminant (Entity (Discrim)))
4138 = Chars (Discrim_Name))
4139 or else Chars (Original_Record_Component (Entity (Discrim)))
4140 = Chars (Discrim_Name);
4142 if No (Next (Assoc)) then
4143 if not Is_Constrained (Typ)
4144 and then Is_Derived_Type (Typ)
4145 and then Present (Stored_Constraint (Typ))
4147 -- If the type is a tagged type with inherited discriminants,
4148 -- use the stored constraint on the parent in order to find
4149 -- the values of discriminants that are otherwise hidden by an
4150 -- explicit constraint. Renamed discriminants are handled in
4153 -- If several parent discriminants are renamed by a single
4154 -- discriminant of the derived type, the call to obtain the
4155 -- Corresponding_Discriminant field only retrieves the last
4156 -- of them. We recover the constraint on the others from the
4157 -- Stored_Constraint as well.
4164 D := First_Discriminant (Etype (Typ));
4165 C := First_Elmt (Stored_Constraint (Typ));
4166 while Present (D) and then Present (C) loop
4167 if Chars (Discrim_Name) = Chars (D) then
4168 if Is_Entity_Name (Node (C))
4169 and then Entity (Node (C)) = Entity (Discrim)
4171 -- D is renamed by Discrim, whose value is given in
4178 Make_Component_Association (Sloc (Typ),
4180 (New_Occurrence_Of (D, Sloc (Typ))),
4181 Duplicate_Subexpr_No_Checks (Node (C)));
4183 exit Find_Constraint;
4186 Next_Discriminant (D);
4193 if No (Next (Assoc)) then
4194 Error_Msg_NE (" missing value for discriminant&",
4195 First (Governed_By), Discrim_Name);
4196 Report_Errors := True;
4201 end loop Find_Constraint;
4203 Discrim_Value := Expression (Assoc);
4205 if not Is_OK_Static_Expression (Discrim_Value) then
4207 ("value for discriminant & must be static!",
4208 Discrim_Value, Discrim);
4209 Why_Not_Static (Discrim_Value);
4210 Report_Errors := True;
4214 Search_For_Discriminant_Value : declare
4220 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4223 Find_Discrete_Value : while Present (Variant) loop
4224 Discrete_Choice := First (Discrete_Choices (Variant));
4225 while Present (Discrete_Choice) loop
4227 exit Find_Discrete_Value when
4228 Nkind (Discrete_Choice) = N_Others_Choice;
4230 Get_Index_Bounds (Discrete_Choice, Low, High);
4232 UI_Low := Expr_Value (Low);
4233 UI_High := Expr_Value (High);
4235 exit Find_Discrete_Value when
4236 UI_Low <= UI_Discrim_Value
4238 UI_High >= UI_Discrim_Value;
4240 Next (Discrete_Choice);
4243 Next_Non_Pragma (Variant);
4244 end loop Find_Discrete_Value;
4245 end Search_For_Discriminant_Value;
4247 if No (Variant) then
4249 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4250 Report_Errors := True;
4254 -- If we have found the corresponding choice, recursively add its
4255 -- components to the Into list.
4257 Gather_Components (Empty,
4258 Component_List (Variant), Governed_By, Into, Report_Errors);
4259 end Gather_Components;
4261 ------------------------
4262 -- Get_Actual_Subtype --
4263 ------------------------
4265 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4266 Typ : constant Entity_Id := Etype (N);
4267 Utyp : Entity_Id := Underlying_Type (Typ);
4276 -- If what we have is an identifier that references a subprogram
4277 -- formal, or a variable or constant object, then we get the actual
4278 -- subtype from the referenced entity if one has been built.
4280 if Nkind (N) = N_Identifier
4282 (Is_Formal (Entity (N))
4283 or else Ekind (Entity (N)) = E_Constant
4284 or else Ekind (Entity (N)) = E_Variable)
4285 and then Present (Actual_Subtype (Entity (N)))
4287 return Actual_Subtype (Entity (N));
4289 -- Actual subtype of unchecked union is always itself. We never need
4290 -- the "real" actual subtype. If we did, we couldn't get it anyway
4291 -- because the discriminant is not available. The restrictions on
4292 -- Unchecked_Union are designed to make sure that this is OK.
4294 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4297 -- Here for the unconstrained case, we must find actual subtype
4298 -- No actual subtype is available, so we must build it on the fly.
4300 -- Checking the type, not the underlying type, for constrainedness
4301 -- seems to be necessary. Maybe all the tests should be on the type???
4303 elsif (not Is_Constrained (Typ))
4304 and then (Is_Array_Type (Utyp)
4305 or else (Is_Record_Type (Utyp)
4306 and then Has_Discriminants (Utyp)))
4307 and then not Has_Unknown_Discriminants (Utyp)
4308 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4310 -- Nothing to do if in spec expression (why not???)
4312 if In_Spec_Expression then
4315 elsif Is_Private_Type (Typ)
4316 and then not Has_Discriminants (Typ)
4318 -- If the type has no discriminants, there is no subtype to
4319 -- build, even if the underlying type is discriminated.
4323 -- Else build the actual subtype
4326 Decl := Build_Actual_Subtype (Typ, N);
4327 Atyp := Defining_Identifier (Decl);
4329 -- If Build_Actual_Subtype generated a new declaration then use it
4333 -- The actual subtype is an Itype, so analyze the declaration,
4334 -- but do not attach it to the tree, to get the type defined.
4336 Set_Parent (Decl, N);
4337 Set_Is_Itype (Atyp);
4338 Analyze (Decl, Suppress => All_Checks);
4339 Set_Associated_Node_For_Itype (Atyp, N);
4340 Set_Has_Delayed_Freeze (Atyp, False);
4342 -- We need to freeze the actual subtype immediately. This is
4343 -- needed, because otherwise this Itype will not get frozen
4344 -- at all, and it is always safe to freeze on creation because
4345 -- any associated types must be frozen at this point.
4347 Freeze_Itype (Atyp, N);
4350 -- Otherwise we did not build a declaration, so return original
4357 -- For all remaining cases, the actual subtype is the same as
4358 -- the nominal type.
4363 end Get_Actual_Subtype;
4365 -------------------------------------
4366 -- Get_Actual_Subtype_If_Available --
4367 -------------------------------------
4369 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4370 Typ : constant Entity_Id := Etype (N);
4373 -- If what we have is an identifier that references a subprogram
4374 -- formal, or a variable or constant object, then we get the actual
4375 -- subtype from the referenced entity if one has been built.
4377 if Nkind (N) = N_Identifier
4379 (Is_Formal (Entity (N))
4380 or else Ekind (Entity (N)) = E_Constant
4381 or else Ekind (Entity (N)) = E_Variable)
4382 and then Present (Actual_Subtype (Entity (N)))
4384 return Actual_Subtype (Entity (N));
4386 -- Otherwise the Etype of N is returned unchanged
4391 end Get_Actual_Subtype_If_Available;
4393 ------------------------
4394 -- Get_Body_From_Stub --
4395 ------------------------
4397 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
4399 return Proper_Body (Unit (Library_Unit (N)));
4400 end Get_Body_From_Stub;
4402 -------------------------------
4403 -- Get_Default_External_Name --
4404 -------------------------------
4406 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4408 Get_Decoded_Name_String (Chars (E));
4410 if Opt.External_Name_Imp_Casing = Uppercase then
4411 Set_Casing (All_Upper_Case);
4413 Set_Casing (All_Lower_Case);
4417 Make_String_Literal (Sloc (E),
4418 Strval => String_From_Name_Buffer);
4419 end Get_Default_External_Name;
4421 --------------------------
4422 -- Get_Enclosing_Object --
4423 --------------------------
4425 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
4427 if Is_Entity_Name (N) then
4431 when N_Indexed_Component |
4433 N_Selected_Component =>
4435 -- If not generating code, a dereference may be left implicit.
4436 -- In thoses cases, return Empty.
4438 if Is_Access_Type (Etype (Prefix (N))) then
4441 return Get_Enclosing_Object (Prefix (N));
4444 when N_Type_Conversion =>
4445 return Get_Enclosing_Object (Expression (N));
4451 end Get_Enclosing_Object;
4453 ---------------------------
4454 -- Get_Enum_Lit_From_Pos --
4455 ---------------------------
4457 function Get_Enum_Lit_From_Pos
4460 Loc : Source_Ptr) return Node_Id
4465 -- In the case where the literal is of type Character, Wide_Character
4466 -- or Wide_Wide_Character or of a type derived from them, there needs
4467 -- to be some special handling since there is no explicit chain of
4468 -- literals to search. Instead, an N_Character_Literal node is created
4469 -- with the appropriate Char_Code and Chars fields.
4471 if Is_Standard_Character_Type (T) then
4472 Set_Character_Literal_Name (UI_To_CC (Pos));
4474 Make_Character_Literal (Loc,
4476 Char_Literal_Value => Pos);
4478 -- For all other cases, we have a complete table of literals, and
4479 -- we simply iterate through the chain of literal until the one
4480 -- with the desired position value is found.
4484 Lit := First_Literal (Base_Type (T));
4485 for J in 1 .. UI_To_Int (Pos) loop
4489 return New_Occurrence_Of (Lit, Loc);
4491 end Get_Enum_Lit_From_Pos;
4493 ---------------------------------------
4494 -- Get_Ensures_From_Test_Case_Pragma --
4495 ---------------------------------------
4497 function Get_Ensures_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4498 Args : constant List_Id := Pragma_Argument_Associations (N);
4502 if List_Length (Args) = 4 then
4503 Res := Pick (Args, 4);
4505 elsif List_Length (Args) = 3 then
4506 Res := Pick (Args, 3);
4508 if Chars (Res) /= Name_Ensures then
4517 end Get_Ensures_From_Test_Case_Pragma;
4519 ------------------------
4520 -- Get_Generic_Entity --
4521 ------------------------
4523 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4524 Ent : constant Entity_Id := Entity (Name (N));
4526 if Present (Renamed_Object (Ent)) then
4527 return Renamed_Object (Ent);
4531 end Get_Generic_Entity;
4533 ----------------------
4534 -- Get_Index_Bounds --
4535 ----------------------
4537 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4538 Kind : constant Node_Kind := Nkind (N);
4542 if Kind = N_Range then
4544 H := High_Bound (N);
4546 elsif Kind = N_Subtype_Indication then
4547 R := Range_Expression (Constraint (N));
4555 L := Low_Bound (Range_Expression (Constraint (N)));
4556 H := High_Bound (Range_Expression (Constraint (N)));
4559 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4560 if Error_Posted (Scalar_Range (Entity (N))) then
4564 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4565 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4568 L := Low_Bound (Scalar_Range (Entity (N)));
4569 H := High_Bound (Scalar_Range (Entity (N)));
4573 -- N is an expression, indicating a range with one value
4578 end Get_Index_Bounds;
4580 ----------------------------------
4581 -- Get_Library_Unit_Name_string --
4582 ----------------------------------
4584 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4585 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4588 Get_Unit_Name_String (Unit_Name_Id);
4590 -- Remove seven last character (" (spec)" or " (body)")
4592 Name_Len := Name_Len - 7;
4593 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4594 end Get_Library_Unit_Name_String;
4596 ------------------------
4597 -- Get_Name_Entity_Id --
4598 ------------------------
4600 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4602 return Entity_Id (Get_Name_Table_Info (Id));
4603 end Get_Name_Entity_Id;
4605 ------------------------------------
4606 -- Get_Name_From_Test_Case_Pragma --
4607 ------------------------------------
4609 function Get_Name_From_Test_Case_Pragma (N : Node_Id) return String_Id is
4610 Arg : constant Node_Id :=
4611 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
4613 return Strval (Expr_Value_S (Arg));
4614 end Get_Name_From_Test_Case_Pragma;
4620 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4622 return Get_Pragma_Id (Pragma_Name (N));
4625 ---------------------------
4626 -- Get_Referenced_Object --
4627 ---------------------------
4629 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4634 while Is_Entity_Name (R)
4635 and then Present (Renamed_Object (Entity (R)))
4637 R := Renamed_Object (Entity (R));
4641 end Get_Referenced_Object;
4643 ------------------------
4644 -- Get_Renamed_Entity --
4645 ------------------------
4647 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4652 while Present (Renamed_Entity (R)) loop
4653 R := Renamed_Entity (R);
4657 end Get_Renamed_Entity;
4659 ----------------------------------------
4660 -- Get_Requires_From_Test_Case_Pragma --
4661 ----------------------------------------
4663 function Get_Requires_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4664 Args : constant List_Id := Pragma_Argument_Associations (N);
4668 if List_Length (Args) >= 3 then
4669 Res := Pick (Args, 3);
4671 if Chars (Res) /= Name_Requires then
4680 end Get_Requires_From_Test_Case_Pragma;
4682 -------------------------
4683 -- Get_Subprogram_Body --
4684 -------------------------
4686 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4690 Decl := Unit_Declaration_Node (E);
4692 if Nkind (Decl) = N_Subprogram_Body then
4695 -- The below comment is bad, because it is possible for
4696 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4698 else -- Nkind (Decl) = N_Subprogram_Declaration
4700 if Present (Corresponding_Body (Decl)) then
4701 return Unit_Declaration_Node (Corresponding_Body (Decl));
4703 -- Imported subprogram case
4709 end Get_Subprogram_Body;
4711 ---------------------------
4712 -- Get_Subprogram_Entity --
4713 ---------------------------
4715 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4720 if Nkind (Nod) = N_Accept_Statement then
4721 Nam := Entry_Direct_Name (Nod);
4723 -- For an entry call, the prefix of the call is a selected component.
4724 -- Need additional code for internal calls ???
4726 elsif Nkind (Nod) = N_Entry_Call_Statement then
4727 if Nkind (Name (Nod)) = N_Selected_Component then
4728 Nam := Entity (Selector_Name (Name (Nod)));
4737 if Nkind (Nam) = N_Explicit_Dereference then
4738 Proc := Etype (Prefix (Nam));
4739 elsif Is_Entity_Name (Nam) then
4740 Proc := Entity (Nam);
4745 if Is_Object (Proc) then
4746 Proc := Etype (Proc);
4749 if Ekind (Proc) = E_Access_Subprogram_Type then
4750 Proc := Directly_Designated_Type (Proc);
4753 if not Is_Subprogram (Proc)
4754 and then Ekind (Proc) /= E_Subprogram_Type
4760 end Get_Subprogram_Entity;
4762 -----------------------------
4763 -- Get_Task_Body_Procedure --
4764 -----------------------------
4766 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4768 -- Note: A task type may be the completion of a private type with
4769 -- discriminants. When performing elaboration checks on a task
4770 -- declaration, the current view of the type may be the private one,
4771 -- and the procedure that holds the body of the task is held in its
4774 -- This is an odd function, why not have Task_Body_Procedure do
4775 -- the following digging???
4777 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4778 end Get_Task_Body_Procedure;
4780 -----------------------
4781 -- Has_Access_Values --
4782 -----------------------
4784 function Has_Access_Values (T : Entity_Id) return Boolean is
4785 Typ : constant Entity_Id := Underlying_Type (T);
4788 -- Case of a private type which is not completed yet. This can only
4789 -- happen in the case of a generic format type appearing directly, or
4790 -- as a component of the type to which this function is being applied
4791 -- at the top level. Return False in this case, since we certainly do
4792 -- not know that the type contains access types.
4797 elsif Is_Access_Type (Typ) then
4800 elsif Is_Array_Type (Typ) then
4801 return Has_Access_Values (Component_Type (Typ));
4803 elsif Is_Record_Type (Typ) then
4808 -- Loop to Check components
4810 Comp := First_Component_Or_Discriminant (Typ);
4811 while Present (Comp) loop
4813 -- Check for access component, tag field does not count, even
4814 -- though it is implemented internally using an access type.
4816 if Has_Access_Values (Etype (Comp))
4817 and then Chars (Comp) /= Name_uTag
4822 Next_Component_Or_Discriminant (Comp);
4831 end Has_Access_Values;
4833 ------------------------------
4834 -- Has_Compatible_Alignment --
4835 ------------------------------
4837 function Has_Compatible_Alignment
4839 Expr : Node_Id) return Alignment_Result
4841 function Has_Compatible_Alignment_Internal
4844 Default : Alignment_Result) return Alignment_Result;
4845 -- This is the internal recursive function that actually does the work.
4846 -- There is one additional parameter, which says what the result should
4847 -- be if no alignment information is found, and there is no definite
4848 -- indication of compatible alignments. At the outer level, this is set
4849 -- to Unknown, but for internal recursive calls in the case where types
4850 -- are known to be correct, it is set to Known_Compatible.
4852 ---------------------------------------
4853 -- Has_Compatible_Alignment_Internal --
4854 ---------------------------------------
4856 function Has_Compatible_Alignment_Internal
4859 Default : Alignment_Result) return Alignment_Result
4861 Result : Alignment_Result := Known_Compatible;
4862 -- Holds the current status of the result. Note that once a value of
4863 -- Known_Incompatible is set, it is sticky and does not get changed
4864 -- to Unknown (the value in Result only gets worse as we go along,
4867 Offs : Uint := No_Uint;
4868 -- Set to a factor of the offset from the base object when Expr is a
4869 -- selected or indexed component, based on Component_Bit_Offset and
4870 -- Component_Size respectively. A negative value is used to represent
4871 -- a value which is not known at compile time.
4873 procedure Check_Prefix;
4874 -- Checks the prefix recursively in the case where the expression
4875 -- is an indexed or selected component.
4877 procedure Set_Result (R : Alignment_Result);
4878 -- If R represents a worse outcome (unknown instead of known
4879 -- compatible, or known incompatible), then set Result to R.
4885 procedure Check_Prefix is
4887 -- The subtlety here is that in doing a recursive call to check
4888 -- the prefix, we have to decide what to do in the case where we
4889 -- don't find any specific indication of an alignment problem.
4891 -- At the outer level, we normally set Unknown as the result in
4892 -- this case, since we can only set Known_Compatible if we really
4893 -- know that the alignment value is OK, but for the recursive
4894 -- call, in the case where the types match, and we have not
4895 -- specified a peculiar alignment for the object, we are only
4896 -- concerned about suspicious rep clauses, the default case does
4897 -- not affect us, since the compiler will, in the absence of such
4898 -- rep clauses, ensure that the alignment is correct.
4900 if Default = Known_Compatible
4902 (Etype (Obj) = Etype (Expr)
4903 and then (Unknown_Alignment (Obj)
4905 Alignment (Obj) = Alignment (Etype (Obj))))
4908 (Has_Compatible_Alignment_Internal
4909 (Obj, Prefix (Expr), Known_Compatible));
4911 -- In all other cases, we need a full check on the prefix
4915 (Has_Compatible_Alignment_Internal
4916 (Obj, Prefix (Expr), Unknown));
4924 procedure Set_Result (R : Alignment_Result) is
4931 -- Start of processing for Has_Compatible_Alignment_Internal
4934 -- If Expr is a selected component, we must make sure there is no
4935 -- potentially troublesome component clause, and that the record is
4938 if Nkind (Expr) = N_Selected_Component then
4940 -- Packed record always generate unknown alignment
4942 if Is_Packed (Etype (Prefix (Expr))) then
4943 Set_Result (Unknown);
4946 -- Check prefix and component offset
4949 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4951 -- If Expr is an indexed component, we must make sure there is no
4952 -- potentially troublesome Component_Size clause and that the array
4953 -- is not bit-packed.
4955 elsif Nkind (Expr) = N_Indexed_Component then
4957 Typ : constant Entity_Id := Etype (Prefix (Expr));
4958 Ind : constant Node_Id := First_Index (Typ);
4961 -- Bit packed array always generates unknown alignment
4963 if Is_Bit_Packed_Array (Typ) then
4964 Set_Result (Unknown);
4967 -- Check prefix and component offset
4970 Offs := Component_Size (Typ);
4972 -- Small optimization: compute the full offset when possible
4975 and then Offs > Uint_0
4976 and then Present (Ind)
4977 and then Nkind (Ind) = N_Range
4978 and then Compile_Time_Known_Value (Low_Bound (Ind))
4979 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4981 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4982 - Expr_Value (Low_Bound ((Ind))));
4987 -- If we have a null offset, the result is entirely determined by
4988 -- the base object and has already been computed recursively.
4990 if Offs = Uint_0 then
4993 -- Case where we know the alignment of the object
4995 elsif Known_Alignment (Obj) then
4997 ObjA : constant Uint := Alignment (Obj);
4998 ExpA : Uint := No_Uint;
4999 SizA : Uint := No_Uint;
5002 -- If alignment of Obj is 1, then we are always OK
5005 Set_Result (Known_Compatible);
5007 -- Alignment of Obj is greater than 1, so we need to check
5010 -- If we have an offset, see if it is compatible
5012 if Offs /= No_Uint and Offs > Uint_0 then
5013 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
5014 Set_Result (Known_Incompatible);
5017 -- See if Expr is an object with known alignment
5019 elsif Is_Entity_Name (Expr)
5020 and then Known_Alignment (Entity (Expr))
5022 ExpA := Alignment (Entity (Expr));
5024 -- Otherwise, we can use the alignment of the type of
5025 -- Expr given that we already checked for
5026 -- discombobulating rep clauses for the cases of indexed
5027 -- and selected components above.
5029 elsif Known_Alignment (Etype (Expr)) then
5030 ExpA := Alignment (Etype (Expr));
5032 -- Otherwise the alignment is unknown
5035 Set_Result (Default);
5038 -- If we got an alignment, see if it is acceptable
5040 if ExpA /= No_Uint and then ExpA < ObjA then
5041 Set_Result (Known_Incompatible);
5044 -- If Expr is not a piece of a larger object, see if size
5045 -- is given. If so, check that it is not too small for the
5046 -- required alignment.
5048 if Offs /= No_Uint then
5051 -- See if Expr is an object with known size
5053 elsif Is_Entity_Name (Expr)
5054 and then Known_Static_Esize (Entity (Expr))
5056 SizA := Esize (Entity (Expr));
5058 -- Otherwise, we check the object size of the Expr type
5060 elsif Known_Static_Esize (Etype (Expr)) then
5061 SizA := Esize (Etype (Expr));
5064 -- If we got a size, see if it is a multiple of the Obj
5065 -- alignment, if not, then the alignment cannot be
5066 -- acceptable, since the size is always a multiple of the
5069 if SizA /= No_Uint then
5070 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
5071 Set_Result (Known_Incompatible);
5077 -- If we do not know required alignment, any non-zero offset is a
5078 -- potential problem (but certainly may be OK, so result is unknown).
5080 elsif Offs /= No_Uint then
5081 Set_Result (Unknown);
5083 -- If we can't find the result by direct comparison of alignment
5084 -- values, then there is still one case that we can determine known
5085 -- result, and that is when we can determine that the types are the
5086 -- same, and no alignments are specified. Then we known that the
5087 -- alignments are compatible, even if we don't know the alignment
5088 -- value in the front end.
5090 elsif Etype (Obj) = Etype (Expr) then
5092 -- Types are the same, but we have to check for possible size
5093 -- and alignments on the Expr object that may make the alignment
5094 -- different, even though the types are the same.
5096 if Is_Entity_Name (Expr) then
5098 -- First check alignment of the Expr object. Any alignment less
5099 -- than Maximum_Alignment is worrisome since this is the case
5100 -- where we do not know the alignment of Obj.
5102 if Known_Alignment (Entity (Expr))
5104 UI_To_Int (Alignment (Entity (Expr))) <
5105 Ttypes.Maximum_Alignment
5107 Set_Result (Unknown);
5109 -- Now check size of Expr object. Any size that is not an
5110 -- even multiple of Maximum_Alignment is also worrisome
5111 -- since it may cause the alignment of the object to be less
5112 -- than the alignment of the type.
5114 elsif Known_Static_Esize (Entity (Expr))
5116 (UI_To_Int (Esize (Entity (Expr))) mod
5117 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
5120 Set_Result (Unknown);
5122 -- Otherwise same type is decisive
5125 Set_Result (Known_Compatible);
5129 -- Another case to deal with is when there is an explicit size or
5130 -- alignment clause when the types are not the same. If so, then the
5131 -- result is Unknown. We don't need to do this test if the Default is
5132 -- Unknown, since that result will be set in any case.
5134 elsif Default /= Unknown
5135 and then (Has_Size_Clause (Etype (Expr))
5137 Has_Alignment_Clause (Etype (Expr)))
5139 Set_Result (Unknown);
5141 -- If no indication found, set default
5144 Set_Result (Default);
5147 -- Return worst result found
5150 end Has_Compatible_Alignment_Internal;
5152 -- Start of processing for Has_Compatible_Alignment
5155 -- If Obj has no specified alignment, then set alignment from the type
5156 -- alignment. Perhaps we should always do this, but for sure we should
5157 -- do it when there is an address clause since we can do more if the
5158 -- alignment is known.
5160 if Unknown_Alignment (Obj) then
5161 Set_Alignment (Obj, Alignment (Etype (Obj)));
5164 -- Now do the internal call that does all the work
5166 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
5167 end Has_Compatible_Alignment;
5169 ----------------------
5170 -- Has_Declarations --
5171 ----------------------
5173 function Has_Declarations (N : Node_Id) return Boolean is
5175 return Nkind_In (Nkind (N), N_Accept_Statement,
5177 N_Compilation_Unit_Aux,
5183 N_Package_Specification);
5184 end Has_Declarations;
5186 -------------------------------------------
5187 -- Has_Discriminant_Dependent_Constraint --
5188 -------------------------------------------
5190 function Has_Discriminant_Dependent_Constraint
5191 (Comp : Entity_Id) return Boolean
5193 Comp_Decl : constant Node_Id := Parent (Comp);
5194 Subt_Indic : constant Node_Id :=
5195 Subtype_Indication (Component_Definition (Comp_Decl));
5200 if Nkind (Subt_Indic) = N_Subtype_Indication then
5201 Constr := Constraint (Subt_Indic);
5203 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
5204 Assn := First (Constraints (Constr));
5205 while Present (Assn) loop
5206 case Nkind (Assn) is
5207 when N_Subtype_Indication |
5211 if Depends_On_Discriminant (Assn) then
5215 when N_Discriminant_Association =>
5216 if Depends_On_Discriminant (Expression (Assn)) then
5231 end Has_Discriminant_Dependent_Constraint;
5233 --------------------
5234 -- Has_Infinities --
5235 --------------------
5237 function Has_Infinities (E : Entity_Id) return Boolean is
5240 Is_Floating_Point_Type (E)
5241 and then Nkind (Scalar_Range (E)) = N_Range
5242 and then Includes_Infinities (Scalar_Range (E));
5245 --------------------
5246 -- Has_Interfaces --
5247 --------------------
5249 function Has_Interfaces
5251 Use_Full_View : Boolean := True) return Boolean
5253 Typ : Entity_Id := Base_Type (T);
5256 -- Handle concurrent types
5258 if Is_Concurrent_Type (Typ) then
5259 Typ := Corresponding_Record_Type (Typ);
5262 if not Present (Typ)
5263 or else not Is_Record_Type (Typ)
5264 or else not Is_Tagged_Type (Typ)
5269 -- Handle private types
5272 and then Present (Full_View (Typ))
5274 Typ := Full_View (Typ);
5277 -- Handle concurrent record types
5279 if Is_Concurrent_Record_Type (Typ)
5280 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
5286 if Is_Interface (Typ)
5288 (Is_Record_Type (Typ)
5289 and then Present (Interfaces (Typ))
5290 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
5295 exit when Etype (Typ) = Typ
5297 -- Handle private types
5299 or else (Present (Full_View (Etype (Typ)))
5300 and then Full_View (Etype (Typ)) = Typ)
5302 -- Protect the frontend against wrong source with cyclic
5305 or else Etype (Typ) = T;
5307 -- Climb to the ancestor type handling private types
5309 if Present (Full_View (Etype (Typ))) then
5310 Typ := Full_View (Etype (Typ));
5319 ------------------------
5320 -- Has_Null_Exclusion --
5321 ------------------------
5323 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5326 when N_Access_Definition |
5327 N_Access_Function_Definition |
5328 N_Access_Procedure_Definition |
5329 N_Access_To_Object_Definition |
5331 N_Derived_Type_Definition |
5332 N_Function_Specification |
5333 N_Subtype_Declaration =>
5334 return Null_Exclusion_Present (N);
5336 when N_Component_Definition |
5337 N_Formal_Object_Declaration |
5338 N_Object_Renaming_Declaration =>
5339 if Present (Subtype_Mark (N)) then
5340 return Null_Exclusion_Present (N);
5341 else pragma Assert (Present (Access_Definition (N)));
5342 return Null_Exclusion_Present (Access_Definition (N));
5345 when N_Discriminant_Specification =>
5346 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5347 return Null_Exclusion_Present (Discriminant_Type (N));
5349 return Null_Exclusion_Present (N);
5352 when N_Object_Declaration =>
5353 if Nkind (Object_Definition (N)) = N_Access_Definition then
5354 return Null_Exclusion_Present (Object_Definition (N));
5356 return Null_Exclusion_Present (N);
5359 when N_Parameter_Specification =>
5360 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5361 return Null_Exclusion_Present (Parameter_Type (N));
5363 return Null_Exclusion_Present (N);
5370 end Has_Null_Exclusion;
5372 ------------------------
5373 -- Has_Null_Extension --
5374 ------------------------
5376 function Has_Null_Extension (T : Entity_Id) return Boolean is
5377 B : constant Entity_Id := Base_Type (T);
5382 if Nkind (Parent (B)) = N_Full_Type_Declaration
5383 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5385 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5387 if Present (Ext) then
5388 if Null_Present (Ext) then
5391 Comps := Component_List (Ext);
5393 -- The null component list is rewritten during analysis to
5394 -- include the parent component. Any other component indicates
5395 -- that the extension was not originally null.
5397 return Null_Present (Comps)
5398 or else No (Next (First (Component_Items (Comps))));
5407 end Has_Null_Extension;
5409 -------------------------------
5410 -- Has_Overriding_Initialize --
5411 -------------------------------
5413 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5414 BT : constant Entity_Id := Base_Type (T);
5418 if Is_Controlled (BT) then
5419 if Is_RTU (Scope (BT), Ada_Finalization) then
5422 elsif Present (Primitive_Operations (BT)) then
5423 P := First_Elmt (Primitive_Operations (BT));
5424 while Present (P) loop
5426 Init : constant Entity_Id := Node (P);
5427 Formal : constant Entity_Id := First_Formal (Init);
5429 if Ekind (Init) = E_Procedure
5430 and then Chars (Init) = Name_Initialize
5431 and then Comes_From_Source (Init)
5432 and then Present (Formal)
5433 and then Etype (Formal) = BT
5434 and then No (Next_Formal (Formal))
5435 and then (Ada_Version < Ada_2012
5436 or else not Null_Present (Parent (Init)))
5446 -- Here if type itself does not have a non-null Initialize operation:
5447 -- check immediate ancestor.
5449 if Is_Derived_Type (BT)
5450 and then Has_Overriding_Initialize (Etype (BT))
5457 end Has_Overriding_Initialize;
5459 --------------------------------------
5460 -- Has_Preelaborable_Initialization --
5461 --------------------------------------
5463 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5466 procedure Check_Components (E : Entity_Id);
5467 -- Check component/discriminant chain, sets Has_PE False if a component
5468 -- or discriminant does not meet the preelaborable initialization rules.
5470 ----------------------
5471 -- Check_Components --
5472 ----------------------
5474 procedure Check_Components (E : Entity_Id) is
5478 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5479 -- Returns True if and only if the expression denoted by N does not
5480 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5482 ---------------------------------
5483 -- Is_Preelaborable_Expression --
5484 ---------------------------------
5486 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5490 Comp_Type : Entity_Id;
5491 Is_Array_Aggr : Boolean;
5494 if Is_Static_Expression (N) then
5497 elsif Nkind (N) = N_Null then
5500 -- Attributes are allowed in general, even if their prefix is a
5501 -- formal type. (It seems that certain attributes known not to be
5502 -- static might not be allowed, but there are no rules to prevent
5505 elsif Nkind (N) = N_Attribute_Reference then
5508 -- The name of a discriminant evaluated within its parent type is
5509 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5510 -- names that denote discriminals as well as discriminants to
5511 -- catch references occurring within init procs.
5513 elsif Is_Entity_Name (N)
5515 (Ekind (Entity (N)) = E_Discriminant
5517 ((Ekind (Entity (N)) = E_Constant
5518 or else Ekind (Entity (N)) = E_In_Parameter)
5519 and then Present (Discriminal_Link (Entity (N)))))
5523 elsif Nkind (N) = N_Qualified_Expression then
5524 return Is_Preelaborable_Expression (Expression (N));
5526 -- For aggregates we have to check that each of the associations
5527 -- is preelaborable.
5529 elsif Nkind (N) = N_Aggregate
5530 or else Nkind (N) = N_Extension_Aggregate
5532 Is_Array_Aggr := Is_Array_Type (Etype (N));
5534 if Is_Array_Aggr then
5535 Comp_Type := Component_Type (Etype (N));
5538 -- Check the ancestor part of extension aggregates, which must
5539 -- be either the name of a type that has preelaborable init or
5540 -- an expression that is preelaborable.
5542 if Nkind (N) = N_Extension_Aggregate then
5544 Anc_Part : constant Node_Id := Ancestor_Part (N);
5547 if Is_Entity_Name (Anc_Part)
5548 and then Is_Type (Entity (Anc_Part))
5550 if not Has_Preelaborable_Initialization
5556 elsif not Is_Preelaborable_Expression (Anc_Part) then
5562 -- Check positional associations
5564 Exp := First (Expressions (N));
5565 while Present (Exp) loop
5566 if not Is_Preelaborable_Expression (Exp) then
5573 -- Check named associations
5575 Assn := First (Component_Associations (N));
5576 while Present (Assn) loop
5577 Choice := First (Choices (Assn));
5578 while Present (Choice) loop
5579 if Is_Array_Aggr then
5580 if Nkind (Choice) = N_Others_Choice then
5583 elsif Nkind (Choice) = N_Range then
5584 if not Is_Static_Range (Choice) then
5588 elsif not Is_Static_Expression (Choice) then
5593 Comp_Type := Etype (Choice);
5599 -- If the association has a <> at this point, then we have
5600 -- to check whether the component's type has preelaborable
5601 -- initialization. Note that this only occurs when the
5602 -- association's corresponding component does not have a
5603 -- default expression, the latter case having already been
5604 -- expanded as an expression for the association.
5606 if Box_Present (Assn) then
5607 if not Has_Preelaborable_Initialization (Comp_Type) then
5611 -- In the expression case we check whether the expression
5612 -- is preelaborable.
5615 not Is_Preelaborable_Expression (Expression (Assn))
5623 -- If we get here then aggregate as a whole is preelaborable
5627 -- All other cases are not preelaborable
5632 end Is_Preelaborable_Expression;
5634 -- Start of processing for Check_Components
5637 -- Loop through entities of record or protected type
5640 while Present (Ent) loop
5642 -- We are interested only in components and discriminants
5649 -- Get default expression if any. If there is no declaration
5650 -- node, it means we have an internal entity. The parent and
5651 -- tag fields are examples of such entities. For such cases,
5652 -- we just test the type of the entity.
5654 if Present (Declaration_Node (Ent)) then
5655 Exp := Expression (Declaration_Node (Ent));
5658 when E_Discriminant =>
5660 -- Note: for a renamed discriminant, the Declaration_Node
5661 -- may point to the one from the ancestor, and have a
5662 -- different expression, so use the proper attribute to
5663 -- retrieve the expression from the derived constraint.
5665 Exp := Discriminant_Default_Value (Ent);
5668 goto Check_Next_Entity;
5671 -- A component has PI if it has no default expression and the
5672 -- component type has PI.
5675 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5680 -- Require the default expression to be preelaborable
5682 elsif not Is_Preelaborable_Expression (Exp) then
5687 <<Check_Next_Entity>>
5690 end Check_Components;
5692 -- Start of processing for Has_Preelaborable_Initialization
5695 -- Immediate return if already marked as known preelaborable init. This
5696 -- covers types for which this function has already been called once
5697 -- and returned True (in which case the result is cached), and also
5698 -- types to which a pragma Preelaborable_Initialization applies.
5700 if Known_To_Have_Preelab_Init (E) then
5704 -- If the type is a subtype representing a generic actual type, then
5705 -- test whether its base type has preelaborable initialization since
5706 -- the subtype representing the actual does not inherit this attribute
5707 -- from the actual or formal. (but maybe it should???)
5709 if Is_Generic_Actual_Type (E) then
5710 return Has_Preelaborable_Initialization (Base_Type (E));
5713 -- All elementary types have preelaborable initialization
5715 if Is_Elementary_Type (E) then
5718 -- Array types have PI if the component type has PI
5720 elsif Is_Array_Type (E) then
5721 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5723 -- A derived type has preelaborable initialization if its parent type
5724 -- has preelaborable initialization and (in the case of a derived record
5725 -- extension) if the non-inherited components all have preelaborable
5726 -- initialization. However, a user-defined controlled type with an
5727 -- overriding Initialize procedure does not have preelaborable
5730 elsif Is_Derived_Type (E) then
5732 -- If the derived type is a private extension then it doesn't have
5733 -- preelaborable initialization.
5735 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5739 -- First check whether ancestor type has preelaborable initialization
5741 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5743 -- If OK, check extension components (if any)
5745 if Has_PE and then Is_Record_Type (E) then
5746 Check_Components (First_Entity (E));
5749 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5750 -- with a user defined Initialize procedure does not have PI.
5753 and then Is_Controlled (E)
5754 and then Has_Overriding_Initialize (E)
5759 -- Private types not derived from a type having preelaborable init and
5760 -- that are not marked with pragma Preelaborable_Initialization do not
5761 -- have preelaborable initialization.
5763 elsif Is_Private_Type (E) then
5766 -- Record type has PI if it is non private and all components have PI
5768 elsif Is_Record_Type (E) then
5770 Check_Components (First_Entity (E));
5772 -- Protected types must not have entries, and components must meet
5773 -- same set of rules as for record components.
5775 elsif Is_Protected_Type (E) then
5776 if Has_Entries (E) then
5780 Check_Components (First_Entity (E));
5781 Check_Components (First_Private_Entity (E));
5784 -- Type System.Address always has preelaborable initialization
5786 elsif Is_RTE (E, RE_Address) then
5789 -- In all other cases, type does not have preelaborable initialization
5795 -- If type has preelaborable initialization, cache result
5798 Set_Known_To_Have_Preelab_Init (E);
5802 end Has_Preelaborable_Initialization;
5804 ---------------------------
5805 -- Has_Private_Component --
5806 ---------------------------
5808 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5809 Btype : Entity_Id := Base_Type (Type_Id);
5810 Component : Entity_Id;
5813 if Error_Posted (Type_Id)
5814 or else Error_Posted (Btype)
5819 if Is_Class_Wide_Type (Btype) then
5820 Btype := Root_Type (Btype);
5823 if Is_Private_Type (Btype) then
5825 UT : constant Entity_Id := Underlying_Type (Btype);
5828 if No (Full_View (Btype)) then
5829 return not Is_Generic_Type (Btype)
5830 and then not Is_Generic_Type (Root_Type (Btype));
5832 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5835 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5839 elsif Is_Array_Type (Btype) then
5840 return Has_Private_Component (Component_Type (Btype));
5842 elsif Is_Record_Type (Btype) then
5843 Component := First_Component (Btype);
5844 while Present (Component) loop
5845 if Has_Private_Component (Etype (Component)) then
5849 Next_Component (Component);
5854 elsif Is_Protected_Type (Btype)
5855 and then Present (Corresponding_Record_Type (Btype))
5857 return Has_Private_Component (Corresponding_Record_Type (Btype));
5862 end Has_Private_Component;
5864 -----------------------------
5865 -- Has_Static_Array_Bounds --
5866 -----------------------------
5868 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5869 Ndims : constant Nat := Number_Dimensions (Typ);
5876 -- Unconstrained types do not have static bounds
5878 if not Is_Constrained (Typ) then
5882 -- First treat string literals specially, as the lower bound and length
5883 -- of string literals are not stored like those of arrays.
5885 -- A string literal always has static bounds
5887 if Ekind (Typ) = E_String_Literal_Subtype then
5891 -- Treat all dimensions in turn
5893 Index := First_Index (Typ);
5894 for Indx in 1 .. Ndims loop
5896 -- In case of an erroneous index which is not a discrete type, return
5897 -- that the type is not static.
5899 if not Is_Discrete_Type (Etype (Index))
5900 or else Etype (Index) = Any_Type
5905 Get_Index_Bounds (Index, Low, High);
5907 if Error_Posted (Low) or else Error_Posted (High) then
5911 if Is_OK_Static_Expression (Low)
5913 Is_OK_Static_Expression (High)
5923 -- If we fall through the loop, all indexes matched
5926 end Has_Static_Array_Bounds;
5932 function Has_Stream (T : Entity_Id) return Boolean is
5939 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5942 elsif Is_Array_Type (T) then
5943 return Has_Stream (Component_Type (T));
5945 elsif Is_Record_Type (T) then
5946 E := First_Component (T);
5947 while Present (E) loop
5948 if Has_Stream (Etype (E)) then
5957 elsif Is_Private_Type (T) then
5958 return Has_Stream (Underlying_Type (T));
5969 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5971 Get_Name_String (Chars (E));
5972 return Name_Buffer (Name_Len) = Suffix;
5979 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
5981 Get_Name_String (Chars (E));
5982 Add_Char_To_Name_Buffer (Suffix);
5990 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
5992 pragma Assert (Has_Suffix (E, Suffix));
5993 Get_Name_String (Chars (E));
5994 Name_Len := Name_Len - 1;
5998 --------------------------
5999 -- Has_Tagged_Component --
6000 --------------------------
6002 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
6006 if Is_Private_Type (Typ)
6007 and then Present (Underlying_Type (Typ))
6009 return Has_Tagged_Component (Underlying_Type (Typ));
6011 elsif Is_Array_Type (Typ) then
6012 return Has_Tagged_Component (Component_Type (Typ));
6014 elsif Is_Tagged_Type (Typ) then
6017 elsif Is_Record_Type (Typ) then
6018 Comp := First_Component (Typ);
6019 while Present (Comp) loop
6020 if Has_Tagged_Component (Etype (Comp)) then
6024 Next_Component (Comp);
6032 end Has_Tagged_Component;
6034 -------------------------
6035 -- Implementation_Kind --
6036 -------------------------
6038 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
6039 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
6041 pragma Assert (Present (Impl_Prag));
6043 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
6044 end Implementation_Kind;
6046 --------------------------
6047 -- Implements_Interface --
6048 --------------------------
6050 function Implements_Interface
6051 (Typ_Ent : Entity_Id;
6052 Iface_Ent : Entity_Id;
6053 Exclude_Parents : Boolean := False) return Boolean
6055 Ifaces_List : Elist_Id;
6057 Iface : Entity_Id := Base_Type (Iface_Ent);
6058 Typ : Entity_Id := Base_Type (Typ_Ent);
6061 if Is_Class_Wide_Type (Typ) then
6062 Typ := Root_Type (Typ);
6065 if not Has_Interfaces (Typ) then
6069 if Is_Class_Wide_Type (Iface) then
6070 Iface := Root_Type (Iface);
6073 Collect_Interfaces (Typ, Ifaces_List);
6075 Elmt := First_Elmt (Ifaces_List);
6076 while Present (Elmt) loop
6077 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
6078 and then Exclude_Parents
6082 elsif Node (Elmt) = Iface then
6090 end Implements_Interface;
6096 function In_Instance return Boolean is
6097 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6103 and then S /= Standard_Standard
6105 if (Ekind (S) = E_Function
6106 or else Ekind (S) = E_Package
6107 or else Ekind (S) = E_Procedure)
6108 and then Is_Generic_Instance (S)
6110 -- A child instance is always compiled in the context of a parent
6111 -- instance. Nevertheless, the actuals are not analyzed in an
6112 -- instance context. We detect this case by examining the current
6113 -- compilation unit, which must be a child instance, and checking
6114 -- that it is not currently on the scope stack.
6116 if Is_Child_Unit (Curr_Unit)
6118 Nkind (Unit (Cunit (Current_Sem_Unit)))
6119 = N_Package_Instantiation
6120 and then not In_Open_Scopes (Curr_Unit)
6134 ----------------------
6135 -- In_Instance_Body --
6136 ----------------------
6138 function In_Instance_Body return Boolean is
6144 and then S /= Standard_Standard
6146 if (Ekind (S) = E_Function
6147 or else Ekind (S) = E_Procedure)
6148 and then Is_Generic_Instance (S)
6152 elsif Ekind (S) = E_Package
6153 and then In_Package_Body (S)
6154 and then Is_Generic_Instance (S)
6163 end In_Instance_Body;
6165 -----------------------------
6166 -- In_Instance_Not_Visible --
6167 -----------------------------
6169 function In_Instance_Not_Visible return Boolean is
6175 and then S /= Standard_Standard
6177 if (Ekind (S) = E_Function
6178 or else Ekind (S) = E_Procedure)
6179 and then Is_Generic_Instance (S)
6183 elsif Ekind (S) = E_Package
6184 and then (In_Package_Body (S) or else In_Private_Part (S))
6185 and then Is_Generic_Instance (S)
6194 end In_Instance_Not_Visible;
6196 ------------------------------
6197 -- In_Instance_Visible_Part --
6198 ------------------------------
6200 function In_Instance_Visible_Part return Boolean is
6206 and then S /= Standard_Standard
6208 if Ekind (S) = E_Package
6209 and then Is_Generic_Instance (S)
6210 and then not In_Package_Body (S)
6211 and then not In_Private_Part (S)
6220 end In_Instance_Visible_Part;
6222 ---------------------
6223 -- In_Package_Body --
6224 ---------------------
6226 function In_Package_Body return Boolean is
6232 and then S /= Standard_Standard
6234 if Ekind (S) = E_Package
6235 and then In_Package_Body (S)
6244 end In_Package_Body;
6246 --------------------------------
6247 -- In_Parameter_Specification --
6248 --------------------------------
6250 function In_Parameter_Specification (N : Node_Id) return Boolean is
6255 while Present (PN) loop
6256 if Nkind (PN) = N_Parameter_Specification then
6264 end In_Parameter_Specification;
6266 --------------------------------------
6267 -- In_Subprogram_Or_Concurrent_Unit --
6268 --------------------------------------
6270 function In_Subprogram_Or_Concurrent_Unit return Boolean is
6275 -- Use scope chain to check successively outer scopes
6281 if K in Subprogram_Kind
6282 or else K in Concurrent_Kind
6283 or else K in Generic_Subprogram_Kind
6287 elsif E = Standard_Standard then
6293 end In_Subprogram_Or_Concurrent_Unit;
6295 ---------------------
6296 -- In_Visible_Part --
6297 ---------------------
6299 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
6302 Is_Package_Or_Generic_Package (Scope_Id)
6303 and then In_Open_Scopes (Scope_Id)
6304 and then not In_Package_Body (Scope_Id)
6305 and then not In_Private_Part (Scope_Id);
6306 end In_Visible_Part;
6308 --------------------------------
6309 -- Incomplete_Or_Private_View --
6310 --------------------------------
6312 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
6313 function Inspect_Decls
6315 Taft : Boolean := False) return Entity_Id;
6316 -- Check whether a declarative region contains the incomplete or private
6323 function Inspect_Decls
6325 Taft : Boolean := False) return Entity_Id
6331 Decl := First (Decls);
6332 while Present (Decl) loop
6336 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6337 Match := Defining_Identifier (Decl);
6341 if Nkind_In (Decl, N_Private_Extension_Declaration,
6342 N_Private_Type_Declaration)
6344 Match := Defining_Identifier (Decl);
6349 and then Present (Full_View (Match))
6350 and then Full_View (Match) = Typ
6365 -- Start of processing for Incomplete_Or_Partial_View
6368 -- Incomplete type case
6370 Prev := Current_Entity_In_Scope (Typ);
6373 and then Is_Incomplete_Type (Prev)
6374 and then Present (Full_View (Prev))
6375 and then Full_View (Prev) = Typ
6380 -- Private or Taft amendment type case
6383 Pkg : constant Entity_Id := Scope (Typ);
6384 Pkg_Decl : Node_Id := Pkg;
6387 if Ekind (Pkg) = E_Package then
6388 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6389 Pkg_Decl := Parent (Pkg_Decl);
6392 -- It is knows that Typ has a private view, look for it in the
6393 -- visible declarations of the enclosing scope. A special case
6394 -- of this is when the two views have been exchanged - the full
6395 -- appears earlier than the private.
6397 if Has_Private_Declaration (Typ) then
6398 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6400 -- Exchanged view case, look in the private declarations
6403 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6408 -- Otherwise if this is the package body, then Typ is a potential
6409 -- Taft amendment type. The incomplete view should be located in
6410 -- the private declarations of the enclosing scope.
6412 elsif In_Package_Body (Pkg) then
6413 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6418 -- The type has no incomplete or private view
6421 end Incomplete_Or_Private_View;
6423 ---------------------------------
6424 -- Insert_Explicit_Dereference --
6425 ---------------------------------
6427 procedure Insert_Explicit_Dereference (N : Node_Id) is
6428 New_Prefix : constant Node_Id := Relocate_Node (N);
6429 Ent : Entity_Id := Empty;
6436 Save_Interps (N, New_Prefix);
6439 Make_Explicit_Dereference (Sloc (Parent (N)),
6440 Prefix => New_Prefix));
6442 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6444 if Is_Overloaded (New_Prefix) then
6446 -- The dereference is also overloaded, and its interpretations are
6447 -- the designated types of the interpretations of the original node.
6449 Set_Etype (N, Any_Type);
6451 Get_First_Interp (New_Prefix, I, It);
6452 while Present (It.Nam) loop
6455 if Is_Access_Type (T) then
6456 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6459 Get_Next_Interp (I, It);
6465 -- Prefix is unambiguous: mark the original prefix (which might
6466 -- Come_From_Source) as a reference, since the new (relocated) one
6467 -- won't be taken into account.
6469 if Is_Entity_Name (New_Prefix) then
6470 Ent := Entity (New_Prefix);
6473 -- For a retrieval of a subcomponent of some composite object,
6474 -- retrieve the ultimate entity if there is one.
6476 elsif Nkind (New_Prefix) = N_Selected_Component
6477 or else Nkind (New_Prefix) = N_Indexed_Component
6479 Pref := Prefix (New_Prefix);
6480 while Present (Pref)
6482 (Nkind (Pref) = N_Selected_Component
6483 or else Nkind (Pref) = N_Indexed_Component)
6485 Pref := Prefix (Pref);
6488 if Present (Pref) and then Is_Entity_Name (Pref) then
6489 Ent := Entity (Pref);
6493 -- Place the reference on the entity node
6495 if Present (Ent) then
6496 Generate_Reference (Ent, Pref);
6499 end Insert_Explicit_Dereference;
6501 ------------------------------------------
6502 -- Inspect_Deferred_Constant_Completion --
6503 ------------------------------------------
6505 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6509 Decl := First (Decls);
6510 while Present (Decl) loop
6512 -- Deferred constant signature
6514 if Nkind (Decl) = N_Object_Declaration
6515 and then Constant_Present (Decl)
6516 and then No (Expression (Decl))
6518 -- No need to check internally generated constants
6520 and then Comes_From_Source (Decl)
6522 -- The constant is not completed. A full object declaration or a
6523 -- pragma Import complete a deferred constant.
6525 and then not Has_Completion (Defining_Identifier (Decl))
6528 ("constant declaration requires initialization expression",
6529 Defining_Identifier (Decl));
6532 Decl := Next (Decl);
6534 end Inspect_Deferred_Constant_Completion;
6536 -----------------------------
6537 -- Is_Actual_Out_Parameter --
6538 -----------------------------
6540 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6544 Find_Actual (N, Formal, Call);
6545 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6546 end Is_Actual_Out_Parameter;
6548 -------------------------
6549 -- Is_Actual_Parameter --
6550 -------------------------
6552 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6553 PK : constant Node_Kind := Nkind (Parent (N));
6557 when N_Parameter_Association =>
6558 return N = Explicit_Actual_Parameter (Parent (N));
6560 when N_Function_Call | N_Procedure_Call_Statement =>
6561 return Is_List_Member (N)
6563 List_Containing (N) = Parameter_Associations (Parent (N));
6568 end Is_Actual_Parameter;
6570 --------------------------------
6571 -- Is_Actual_Tagged_Parameter --
6572 --------------------------------
6574 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6578 Find_Actual (N, Formal, Call);
6579 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6580 end Is_Actual_Tagged_Parameter;
6582 ---------------------
6583 -- Is_Aliased_View --
6584 ---------------------
6586 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6590 if Is_Entity_Name (Obj) then
6597 or else (Present (Renamed_Object (E))
6598 and then Is_Aliased_View (Renamed_Object (E)))))
6600 or else ((Is_Formal (E)
6601 or else Ekind (E) = E_Generic_In_Out_Parameter
6602 or else Ekind (E) = E_Generic_In_Parameter)
6603 and then Is_Tagged_Type (Etype (E)))
6605 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
6607 -- Current instance of type, either directly or as rewritten
6608 -- reference to the current object.
6610 or else (Is_Entity_Name (Original_Node (Obj))
6611 and then Present (Entity (Original_Node (Obj)))
6612 and then Is_Type (Entity (Original_Node (Obj))))
6614 or else (Is_Type (E) and then E = Current_Scope)
6616 or else (Is_Incomplete_Or_Private_Type (E)
6617 and then Full_View (E) = Current_Scope)
6619 -- Ada 2012 AI05-0053: the return object of an extended return
6620 -- statement is aliased if its type is immutably limited.
6622 or else (Is_Return_Object (E)
6623 and then Is_Immutably_Limited_Type (Etype (E)));
6625 elsif Nkind (Obj) = N_Selected_Component then
6626 return Is_Aliased (Entity (Selector_Name (Obj)));
6628 elsif Nkind (Obj) = N_Indexed_Component then
6629 return Has_Aliased_Components (Etype (Prefix (Obj)))
6631 (Is_Access_Type (Etype (Prefix (Obj)))
6632 and then Has_Aliased_Components
6633 (Designated_Type (Etype (Prefix (Obj)))));
6635 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
6636 return Is_Tagged_Type (Etype (Obj))
6637 and then Is_Aliased_View (Expression (Obj));
6639 elsif Nkind (Obj) = N_Explicit_Dereference then
6640 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6645 end Is_Aliased_View;
6647 -------------------------
6648 -- Is_Ancestor_Package --
6649 -------------------------
6651 function Is_Ancestor_Package
6653 E2 : Entity_Id) return Boolean
6660 and then Par /= Standard_Standard
6670 end Is_Ancestor_Package;
6672 ----------------------
6673 -- Is_Atomic_Object --
6674 ----------------------
6676 function Is_Atomic_Object (N : Node_Id) return Boolean is
6678 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6679 -- Determines if given object has atomic components
6681 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6682 -- If prefix is an implicit dereference, examine designated type
6684 ----------------------
6685 -- Is_Atomic_Prefix --
6686 ----------------------
6688 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6690 if Is_Access_Type (Etype (N)) then
6692 Has_Atomic_Components (Designated_Type (Etype (N)));
6694 return Object_Has_Atomic_Components (N);
6696 end Is_Atomic_Prefix;
6698 ----------------------------------
6699 -- Object_Has_Atomic_Components --
6700 ----------------------------------
6702 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6704 if Has_Atomic_Components (Etype (N))
6705 or else Is_Atomic (Etype (N))
6709 elsif Is_Entity_Name (N)
6710 and then (Has_Atomic_Components (Entity (N))
6711 or else Is_Atomic (Entity (N)))
6715 elsif Nkind (N) = N_Indexed_Component
6716 or else Nkind (N) = N_Selected_Component
6718 return Is_Atomic_Prefix (Prefix (N));
6723 end Object_Has_Atomic_Components;
6725 -- Start of processing for Is_Atomic_Object
6728 -- Predicate is not relevant to subprograms
6730 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6733 elsif Is_Atomic (Etype (N))
6734 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6738 elsif Nkind (N) = N_Indexed_Component
6739 or else Nkind (N) = N_Selected_Component
6741 return Is_Atomic_Prefix (Prefix (N));
6746 end Is_Atomic_Object;
6748 -----------------------------
6749 -- Is_Concurrent_Interface --
6750 -----------------------------
6752 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6757 (Is_Protected_Interface (T)
6758 or else Is_Synchronized_Interface (T)
6759 or else Is_Task_Interface (T));
6760 end Is_Concurrent_Interface;
6762 --------------------------------------
6763 -- Is_Controlling_Limited_Procedure --
6764 --------------------------------------
6766 function Is_Controlling_Limited_Procedure
6767 (Proc_Nam : Entity_Id) return Boolean
6769 Param_Typ : Entity_Id := Empty;
6772 if Ekind (Proc_Nam) = E_Procedure
6773 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6775 Param_Typ := Etype (Parameter_Type (First (
6776 Parameter_Specifications (Parent (Proc_Nam)))));
6778 -- In this case where an Itype was created, the procedure call has been
6781 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6782 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6784 Present (Parameter_Associations
6785 (Associated_Node_For_Itype (Proc_Nam)))
6788 Etype (First (Parameter_Associations
6789 (Associated_Node_For_Itype (Proc_Nam))));
6792 if Present (Param_Typ) then
6794 Is_Interface (Param_Typ)
6795 and then Is_Limited_Record (Param_Typ);
6799 end Is_Controlling_Limited_Procedure;
6801 -----------------------------
6802 -- Is_CPP_Constructor_Call --
6803 -----------------------------
6805 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6807 return Nkind (N) = N_Function_Call
6808 and then Is_CPP_Class (Etype (Etype (N)))
6809 and then Is_Constructor (Entity (Name (N)))
6810 and then Is_Imported (Entity (Name (N)));
6811 end Is_CPP_Constructor_Call;
6817 function Is_Delegate (T : Entity_Id) return Boolean is
6818 Desig_Type : Entity_Id;
6821 if VM_Target /= CLI_Target then
6825 -- Access-to-subprograms are delegates in CIL
6827 if Ekind (T) = E_Access_Subprogram_Type then
6831 if Ekind (T) not in Access_Kind then
6833 -- A delegate is a managed pointer. If no designated type is defined
6834 -- it means that it's not a delegate.
6839 Desig_Type := Etype (Directly_Designated_Type (T));
6841 if not Is_Tagged_Type (Desig_Type) then
6845 -- Test if the type is inherited from [mscorlib]System.Delegate
6847 while Etype (Desig_Type) /= Desig_Type loop
6848 if Chars (Scope (Desig_Type)) /= No_Name
6849 and then Is_Imported (Scope (Desig_Type))
6850 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6855 Desig_Type := Etype (Desig_Type);
6861 ----------------------------------------------
6862 -- Is_Dependent_Component_Of_Mutable_Object --
6863 ----------------------------------------------
6865 function Is_Dependent_Component_Of_Mutable_Object
6866 (Object : Node_Id) return Boolean
6869 Prefix_Type : Entity_Id;
6870 P_Aliased : Boolean := False;
6873 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6874 -- Returns True if and only if Comp is declared within a variant part
6876 --------------------------------
6877 -- Is_Declared_Within_Variant --
6878 --------------------------------
6880 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6881 Comp_Decl : constant Node_Id := Parent (Comp);
6882 Comp_List : constant Node_Id := Parent (Comp_Decl);
6884 return Nkind (Parent (Comp_List)) = N_Variant;
6885 end Is_Declared_Within_Variant;
6887 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6890 if Is_Variable (Object) then
6892 if Nkind (Object) = N_Selected_Component then
6893 P := Prefix (Object);
6894 Prefix_Type := Etype (P);
6896 if Is_Entity_Name (P) then
6898 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6899 Prefix_Type := Base_Type (Prefix_Type);
6902 if Is_Aliased (Entity (P)) then
6906 -- A discriminant check on a selected component may be expanded
6907 -- into a dereference when removing side-effects. Recover the
6908 -- original node and its type, which may be unconstrained.
6910 elsif Nkind (P) = N_Explicit_Dereference
6911 and then not (Comes_From_Source (P))
6913 P := Original_Node (P);
6914 Prefix_Type := Etype (P);
6917 -- Check for prefix being an aliased component???
6923 -- A heap object is constrained by its initial value
6925 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6926 -- the dereferenced case, since the access value might denote an
6927 -- unconstrained aliased object, whereas in Ada 95 the designated
6928 -- object is guaranteed to be constrained. A worst-case assumption
6929 -- has to apply in Ada 2005 because we can't tell at compile time
6930 -- whether the object is "constrained by its initial value"
6931 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6932 -- semantic rules -- these rules are acknowledged to need fixing).
6934 if Ada_Version < Ada_2005 then
6935 if Is_Access_Type (Prefix_Type)
6936 or else Nkind (P) = N_Explicit_Dereference
6941 elsif Ada_Version >= Ada_2005 then
6942 if Is_Access_Type (Prefix_Type) then
6944 -- If the access type is pool-specific, and there is no
6945 -- constrained partial view of the designated type, then the
6946 -- designated object is known to be constrained.
6948 if Ekind (Prefix_Type) = E_Access_Type
6949 and then not Effectively_Has_Constrained_Partial_View
6950 (Typ => Designated_Type (Prefix_Type),
6951 Scop => Current_Scope)
6955 -- Otherwise (general access type, or there is a constrained
6956 -- partial view of the designated type), we need to check
6957 -- based on the designated type.
6960 Prefix_Type := Designated_Type (Prefix_Type);
6966 Original_Record_Component (Entity (Selector_Name (Object)));
6968 -- As per AI-0017, the renaming is illegal in a generic body, even
6969 -- if the subtype is indefinite.
6971 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6973 if not Is_Constrained (Prefix_Type)
6974 and then (not Is_Indefinite_Subtype (Prefix_Type)
6976 (Is_Generic_Type (Prefix_Type)
6977 and then Ekind (Current_Scope) = E_Generic_Package
6978 and then In_Package_Body (Current_Scope)))
6980 and then (Is_Declared_Within_Variant (Comp)
6981 or else Has_Discriminant_Dependent_Constraint (Comp))
6982 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6988 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6992 elsif Nkind (Object) = N_Indexed_Component
6993 or else Nkind (Object) = N_Slice
6995 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6997 -- A type conversion that Is_Variable is a view conversion:
6998 -- go back to the denoted object.
7000 elsif Nkind (Object) = N_Type_Conversion then
7002 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
7007 end Is_Dependent_Component_Of_Mutable_Object;
7009 ---------------------
7010 -- Is_Dereferenced --
7011 ---------------------
7013 function Is_Dereferenced (N : Node_Id) return Boolean is
7014 P : constant Node_Id := Parent (N);
7017 (Nkind (P) = N_Selected_Component
7019 Nkind (P) = N_Explicit_Dereference
7021 Nkind (P) = N_Indexed_Component
7023 Nkind (P) = N_Slice)
7024 and then Prefix (P) = N;
7025 end Is_Dereferenced;
7027 ----------------------
7028 -- Is_Descendent_Of --
7029 ----------------------
7031 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
7036 pragma Assert (Nkind (T1) in N_Entity);
7037 pragma Assert (Nkind (T2) in N_Entity);
7039 T := Base_Type (T1);
7041 -- Immediate return if the types match
7046 -- Comment needed here ???
7048 elsif Ekind (T) = E_Class_Wide_Type then
7049 return Etype (T) = T2;
7057 -- Done if we found the type we are looking for
7062 -- Done if no more derivations to check
7069 -- Following test catches error cases resulting from prev errors
7071 elsif No (Etyp) then
7074 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
7077 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
7081 T := Base_Type (Etyp);
7084 end Is_Descendent_Of;
7086 ----------------------------
7087 -- Is_Expression_Function --
7088 ----------------------------
7090 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
7091 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7094 return Ekind (Subp) = E_Function
7095 and then Nkind (Decl) = N_Subprogram_Declaration
7097 (Nkind (Original_Node (Decl)) = N_Expression_Function
7099 (Present (Corresponding_Body (Decl))
7101 Nkind (Original_Node
7102 (Unit_Declaration_Node (Corresponding_Body (Decl))))
7103 = N_Expression_Function));
7104 end Is_Expression_Function;
7110 function Is_False (U : Uint) return Boolean is
7115 ---------------------------
7116 -- Is_Fixed_Model_Number --
7117 ---------------------------
7119 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
7120 S : constant Ureal := Small_Value (T);
7121 M : Urealp.Save_Mark;
7125 R := (U = UR_Trunc (U / S) * S);
7128 end Is_Fixed_Model_Number;
7130 -------------------------------
7131 -- Is_Fully_Initialized_Type --
7132 -------------------------------
7134 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
7136 if Is_Scalar_Type (Typ) then
7139 elsif Is_Access_Type (Typ) then
7142 elsif Is_Array_Type (Typ) then
7143 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
7147 -- An interesting case, if we have a constrained type one of whose
7148 -- bounds is known to be null, then there are no elements to be
7149 -- initialized, so all the elements are initialized!
7151 if Is_Constrained (Typ) then
7154 Indx_Typ : Entity_Id;
7158 Indx := First_Index (Typ);
7159 while Present (Indx) loop
7160 if Etype (Indx) = Any_Type then
7163 -- If index is a range, use directly
7165 elsif Nkind (Indx) = N_Range then
7166 Lbd := Low_Bound (Indx);
7167 Hbd := High_Bound (Indx);
7170 Indx_Typ := Etype (Indx);
7172 if Is_Private_Type (Indx_Typ) then
7173 Indx_Typ := Full_View (Indx_Typ);
7176 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
7179 Lbd := Type_Low_Bound (Indx_Typ);
7180 Hbd := Type_High_Bound (Indx_Typ);
7184 if Compile_Time_Known_Value (Lbd)
7185 and then Compile_Time_Known_Value (Hbd)
7187 if Expr_Value (Hbd) < Expr_Value (Lbd) then
7197 -- If no null indexes, then type is not fully initialized
7203 elsif Is_Record_Type (Typ) then
7204 if Has_Discriminants (Typ)
7206 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
7207 and then Is_Fully_Initialized_Variant (Typ)
7212 -- Controlled records are considered to be fully initialized if
7213 -- there is a user defined Initialize routine. This may not be
7214 -- entirely correct, but as the spec notes, we are guessing here
7215 -- what is best from the point of view of issuing warnings.
7217 if Is_Controlled (Typ) then
7219 Utyp : constant Entity_Id := Underlying_Type (Typ);
7222 if Present (Utyp) then
7224 Init : constant Entity_Id :=
7226 (Underlying_Type (Typ), Name_Initialize));
7230 and then Comes_From_Source (Init)
7232 Is_Predefined_File_Name
7233 (File_Name (Get_Source_File_Index (Sloc (Init))))
7237 elsif Has_Null_Extension (Typ)
7239 Is_Fully_Initialized_Type
7240 (Etype (Base_Type (Typ)))
7249 -- Otherwise see if all record components are initialized
7255 Ent := First_Entity (Typ);
7256 while Present (Ent) loop
7257 if Ekind (Ent) = E_Component
7258 and then (No (Parent (Ent))
7259 or else No (Expression (Parent (Ent))))
7260 and then not Is_Fully_Initialized_Type (Etype (Ent))
7262 -- Special VM case for tag components, which need to be
7263 -- defined in this case, but are never initialized as VMs
7264 -- are using other dispatching mechanisms. Ignore this
7265 -- uninitialized case. Note that this applies both to the
7266 -- uTag entry and the main vtable pointer (CPP_Class case).
7268 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
7277 -- No uninitialized components, so type is fully initialized.
7278 -- Note that this catches the case of no components as well.
7282 elsif Is_Concurrent_Type (Typ) then
7285 elsif Is_Private_Type (Typ) then
7287 U : constant Entity_Id := Underlying_Type (Typ);
7293 return Is_Fully_Initialized_Type (U);
7300 end Is_Fully_Initialized_Type;
7302 ----------------------------------
7303 -- Is_Fully_Initialized_Variant --
7304 ----------------------------------
7306 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
7307 Loc : constant Source_Ptr := Sloc (Typ);
7308 Constraints : constant List_Id := New_List;
7309 Components : constant Elist_Id := New_Elmt_List;
7310 Comp_Elmt : Elmt_Id;
7312 Comp_List : Node_Id;
7314 Discr_Val : Node_Id;
7316 Report_Errors : Boolean;
7317 pragma Warnings (Off, Report_Errors);
7320 if Serious_Errors_Detected > 0 then
7324 if Is_Record_Type (Typ)
7325 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7326 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7328 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7330 Discr := First_Discriminant (Typ);
7331 while Present (Discr) loop
7332 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7333 Discr_Val := Expression (Parent (Discr));
7335 if Present (Discr_Val)
7336 and then Is_OK_Static_Expression (Discr_Val)
7338 Append_To (Constraints,
7339 Make_Component_Association (Loc,
7340 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7341 Expression => New_Copy (Discr_Val)));
7349 Next_Discriminant (Discr);
7354 Comp_List => Comp_List,
7355 Governed_By => Constraints,
7357 Report_Errors => Report_Errors);
7359 -- Check that each component present is fully initialized
7361 Comp_Elmt := First_Elmt (Components);
7362 while Present (Comp_Elmt) loop
7363 Comp_Id := Node (Comp_Elmt);
7365 if Ekind (Comp_Id) = E_Component
7366 and then (No (Parent (Comp_Id))
7367 or else No (Expression (Parent (Comp_Id))))
7368 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7373 Next_Elmt (Comp_Elmt);
7378 elsif Is_Private_Type (Typ) then
7380 U : constant Entity_Id := Underlying_Type (Typ);
7386 return Is_Fully_Initialized_Variant (U);
7392 end Is_Fully_Initialized_Variant;
7394 ----------------------------
7395 -- Is_Inherited_Operation --
7396 ----------------------------
7398 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7399 pragma Assert (Is_Overloadable (E));
7400 Kind : constant Node_Kind := Nkind (Parent (E));
7402 return Kind = N_Full_Type_Declaration
7403 or else Kind = N_Private_Extension_Declaration
7404 or else Kind = N_Subtype_Declaration
7405 or else (Ekind (E) = E_Enumeration_Literal
7406 and then Is_Derived_Type (Etype (E)));
7407 end Is_Inherited_Operation;
7409 -------------------------------------
7410 -- Is_Inherited_Operation_For_Type --
7411 -------------------------------------
7413 function Is_Inherited_Operation_For_Type
7415 Typ : Entity_Id) return Boolean
7418 return Is_Inherited_Operation (E)
7419 and then Etype (Parent (E)) = Typ;
7420 end Is_Inherited_Operation_For_Type;
7426 function Is_Iterator (Typ : Entity_Id) return Boolean is
7427 Ifaces_List : Elist_Id;
7428 Iface_Elmt : Elmt_Id;
7432 if Is_Class_Wide_Type (Typ)
7434 (Chars (Etype (Typ)) = Name_Forward_Iterator
7436 Chars (Etype (Typ)) = Name_Reversible_Iterator)
7438 Is_Predefined_File_Name
7439 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
7443 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
7447 Collect_Interfaces (Typ, Ifaces_List);
7449 Iface_Elmt := First_Elmt (Ifaces_List);
7450 while Present (Iface_Elmt) loop
7451 Iface := Node (Iface_Elmt);
7452 if Chars (Iface) = Name_Forward_Iterator
7454 Is_Predefined_File_Name
7455 (Unit_File_Name (Get_Source_Unit (Iface)))
7460 Next_Elmt (Iface_Elmt);
7471 -- We seem to have a lot of overlapping functions that do similar things
7472 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7473 -- purely syntactic, it should be in Sem_Aux I would think???
7475 function Is_LHS (N : Node_Id) return Boolean is
7476 P : constant Node_Id := Parent (N);
7479 if Nkind (P) = N_Assignment_Statement then
7480 return Name (P) = N;
7483 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7485 return N = Prefix (P) and then Is_LHS (P);
7492 -----------------------------
7493 -- Is_Library_Level_Entity --
7494 -----------------------------
7496 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7498 -- The following is a small optimization, and it also properly handles
7499 -- discriminals, which in task bodies might appear in expressions before
7500 -- the corresponding procedure has been created, and which therefore do
7501 -- not have an assigned scope.
7503 if Is_Formal (E) then
7507 -- Normal test is simply that the enclosing dynamic scope is Standard
7509 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7510 end Is_Library_Level_Entity;
7512 --------------------------------
7513 -- Is_Limited_Class_Wide_Type --
7514 --------------------------------
7516 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
7519 Is_Class_Wide_Type (Typ)
7520 and then Is_Limited_Type (Typ);
7521 end Is_Limited_Class_Wide_Type;
7523 ---------------------------------
7524 -- Is_Local_Variable_Reference --
7525 ---------------------------------
7527 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7529 if not Is_Entity_Name (Expr) then
7534 Ent : constant Entity_Id := Entity (Expr);
7535 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7537 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7540 return Present (Sub) and then Sub = Current_Subprogram;
7544 end Is_Local_Variable_Reference;
7546 -------------------------
7547 -- Is_Object_Reference --
7548 -------------------------
7550 function Is_Object_Reference (N : Node_Id) return Boolean is
7552 if Is_Entity_Name (N) then
7553 return Present (Entity (N)) and then Is_Object (Entity (N));
7557 when N_Indexed_Component | N_Slice =>
7559 Is_Object_Reference (Prefix (N))
7560 or else Is_Access_Type (Etype (Prefix (N)));
7562 -- In Ada 95, a function call is a constant object; a procedure
7565 when N_Function_Call =>
7566 return Etype (N) /= Standard_Void_Type;
7568 -- A reference to the stream attribute Input is a function call
7570 when N_Attribute_Reference =>
7571 return Attribute_Name (N) = Name_Input;
7573 when N_Selected_Component =>
7575 Is_Object_Reference (Selector_Name (N))
7577 (Is_Object_Reference (Prefix (N))
7578 or else Is_Access_Type (Etype (Prefix (N))));
7580 when N_Explicit_Dereference =>
7583 -- A view conversion of a tagged object is an object reference
7585 when N_Type_Conversion =>
7586 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7587 and then Is_Tagged_Type (Etype (Expression (N)))
7588 and then Is_Object_Reference (Expression (N));
7590 -- An unchecked type conversion is considered to be an object if
7591 -- the operand is an object (this construction arises only as a
7592 -- result of expansion activities).
7594 when N_Unchecked_Type_Conversion =>
7601 end Is_Object_Reference;
7603 -----------------------------------
7604 -- Is_OK_Variable_For_Out_Formal --
7605 -----------------------------------
7607 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7609 Note_Possible_Modification (AV, Sure => True);
7611 -- We must reject parenthesized variable names. The check for
7612 -- Comes_From_Source is present because there are currently
7613 -- cases where the compiler violates this rule (e.g. passing
7614 -- a task object to its controlled Initialize routine).
7616 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7619 -- A variable is always allowed
7621 elsif Is_Variable (AV) then
7624 -- Unchecked conversions are allowed only if they come from the
7625 -- generated code, which sometimes uses unchecked conversions for out
7626 -- parameters in cases where code generation is unaffected. We tell
7627 -- source unchecked conversions by seeing if they are rewrites of an
7628 -- original Unchecked_Conversion function call, or of an explicit
7629 -- conversion of a function call.
7631 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7632 if Nkind (Original_Node (AV)) = N_Function_Call then
7635 elsif Comes_From_Source (AV)
7636 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7640 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7641 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7647 -- Normal type conversions are allowed if argument is a variable
7649 elsif Nkind (AV) = N_Type_Conversion then
7650 if Is_Variable (Expression (AV))
7651 and then Paren_Count (Expression (AV)) = 0
7653 Note_Possible_Modification (Expression (AV), Sure => True);
7656 -- We also allow a non-parenthesized expression that raises
7657 -- constraint error if it rewrites what used to be a variable
7659 elsif Raises_Constraint_Error (Expression (AV))
7660 and then Paren_Count (Expression (AV)) = 0
7661 and then Is_Variable (Original_Node (Expression (AV)))
7665 -- Type conversion of something other than a variable
7671 -- If this node is rewritten, then test the original form, if that is
7672 -- OK, then we consider the rewritten node OK (for example, if the
7673 -- original node is a conversion, then Is_Variable will not be true
7674 -- but we still want to allow the conversion if it converts a variable).
7676 elsif Original_Node (AV) /= AV then
7678 -- In Ada 2012, the explicit dereference may be a rewritten call to a
7679 -- Reference function.
7681 if Ada_Version >= Ada_2012
7682 and then Nkind (Original_Node (AV)) = N_Function_Call
7684 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
7689 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7692 -- All other non-variables are rejected
7697 end Is_OK_Variable_For_Out_Formal;
7699 -----------------------------------
7700 -- Is_Partially_Initialized_Type --
7701 -----------------------------------
7703 function Is_Partially_Initialized_Type
7705 Include_Implicit : Boolean := True) return Boolean
7708 if Is_Scalar_Type (Typ) then
7711 elsif Is_Access_Type (Typ) then
7712 return Include_Implicit;
7714 elsif Is_Array_Type (Typ) then
7716 -- If component type is partially initialized, so is array type
7718 if Is_Partially_Initialized_Type
7719 (Component_Type (Typ), Include_Implicit)
7723 -- Otherwise we are only partially initialized if we are fully
7724 -- initialized (this is the empty array case, no point in us
7725 -- duplicating that code here).
7728 return Is_Fully_Initialized_Type (Typ);
7731 elsif Is_Record_Type (Typ) then
7733 -- A discriminated type is always partially initialized if in
7736 if Has_Discriminants (Typ) and then Include_Implicit then
7739 -- A tagged type is always partially initialized
7741 elsif Is_Tagged_Type (Typ) then
7744 -- Case of non-discriminated record
7750 Component_Present : Boolean := False;
7751 -- Set True if at least one component is present. If no
7752 -- components are present, then record type is fully
7753 -- initialized (another odd case, like the null array).
7756 -- Loop through components
7758 Ent := First_Entity (Typ);
7759 while Present (Ent) loop
7760 if Ekind (Ent) = E_Component then
7761 Component_Present := True;
7763 -- If a component has an initialization expression then
7764 -- the enclosing record type is partially initialized
7766 if Present (Parent (Ent))
7767 and then Present (Expression (Parent (Ent)))
7771 -- If a component is of a type which is itself partially
7772 -- initialized, then the enclosing record type is also.
7774 elsif Is_Partially_Initialized_Type
7775 (Etype (Ent), Include_Implicit)
7784 -- No initialized components found. If we found any components
7785 -- they were all uninitialized so the result is false.
7787 if Component_Present then
7790 -- But if we found no components, then all the components are
7791 -- initialized so we consider the type to be initialized.
7799 -- Concurrent types are always fully initialized
7801 elsif Is_Concurrent_Type (Typ) then
7804 -- For a private type, go to underlying type. If there is no underlying
7805 -- type then just assume this partially initialized. Not clear if this
7806 -- can happen in a non-error case, but no harm in testing for this.
7808 elsif Is_Private_Type (Typ) then
7810 U : constant Entity_Id := Underlying_Type (Typ);
7815 return Is_Partially_Initialized_Type (U, Include_Implicit);
7819 -- For any other type (are there any?) assume partially initialized
7824 end Is_Partially_Initialized_Type;
7826 ------------------------------------
7827 -- Is_Potentially_Persistent_Type --
7828 ------------------------------------
7830 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7835 -- For private type, test corresponding full type
7837 if Is_Private_Type (T) then
7838 return Is_Potentially_Persistent_Type (Full_View (T));
7840 -- Scalar types are potentially persistent
7842 elsif Is_Scalar_Type (T) then
7845 -- Record type is potentially persistent if not tagged and the types of
7846 -- all it components are potentially persistent, and no component has
7847 -- an initialization expression.
7849 elsif Is_Record_Type (T)
7850 and then not Is_Tagged_Type (T)
7851 and then not Is_Partially_Initialized_Type (T)
7853 Comp := First_Component (T);
7854 while Present (Comp) loop
7855 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7864 -- Array type is potentially persistent if its component type is
7865 -- potentially persistent and if all its constraints are static.
7867 elsif Is_Array_Type (T) then
7868 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7872 Indx := First_Index (T);
7873 while Present (Indx) loop
7874 if not Is_OK_Static_Subtype (Etype (Indx)) then
7883 -- All other types are not potentially persistent
7888 end Is_Potentially_Persistent_Type;
7890 ---------------------------------
7891 -- Is_Protected_Self_Reference --
7892 ---------------------------------
7894 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7896 function In_Access_Definition (N : Node_Id) return Boolean;
7897 -- Returns true if N belongs to an access definition
7899 --------------------------
7900 -- In_Access_Definition --
7901 --------------------------
7903 function In_Access_Definition (N : Node_Id) return Boolean is
7908 while Present (P) loop
7909 if Nkind (P) = N_Access_Definition then
7917 end In_Access_Definition;
7919 -- Start of processing for Is_Protected_Self_Reference
7922 -- Verify that prefix is analyzed and has the proper form. Note that
7923 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
7924 -- which also produce the address of an entity, do not analyze their
7925 -- prefix because they denote entities that are not necessarily visible.
7926 -- Neither of them can apply to a protected type.
7928 return Ada_Version >= Ada_2005
7929 and then Is_Entity_Name (N)
7930 and then Present (Entity (N))
7931 and then Is_Protected_Type (Entity (N))
7932 and then In_Open_Scopes (Entity (N))
7933 and then not In_Access_Definition (N);
7934 end Is_Protected_Self_Reference;
7936 -----------------------------
7937 -- Is_RCI_Pkg_Spec_Or_Body --
7938 -----------------------------
7940 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7942 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7943 -- Return True if the unit of Cunit is an RCI package declaration
7945 ---------------------------
7946 -- Is_RCI_Pkg_Decl_Cunit --
7947 ---------------------------
7949 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7950 The_Unit : constant Node_Id := Unit (Cunit);
7953 if Nkind (The_Unit) /= N_Package_Declaration then
7957 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7958 end Is_RCI_Pkg_Decl_Cunit;
7960 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7963 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7965 (Nkind (Unit (Cunit)) = N_Package_Body
7966 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7967 end Is_RCI_Pkg_Spec_Or_Body;
7969 -----------------------------------------
7970 -- Is_Remote_Access_To_Class_Wide_Type --
7971 -----------------------------------------
7973 function Is_Remote_Access_To_Class_Wide_Type
7974 (E : Entity_Id) return Boolean
7977 -- A remote access to class-wide type is a general access to object type
7978 -- declared in the visible part of a Remote_Types or Remote_Call_
7981 return Ekind (E) = E_General_Access_Type
7982 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7983 end Is_Remote_Access_To_Class_Wide_Type;
7985 -----------------------------------------
7986 -- Is_Remote_Access_To_Subprogram_Type --
7987 -----------------------------------------
7989 function Is_Remote_Access_To_Subprogram_Type
7990 (E : Entity_Id) return Boolean
7993 return (Ekind (E) = E_Access_Subprogram_Type
7994 or else (Ekind (E) = E_Record_Type
7995 and then Present (Corresponding_Remote_Type (E))))
7996 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7997 end Is_Remote_Access_To_Subprogram_Type;
7999 --------------------
8000 -- Is_Remote_Call --
8001 --------------------
8003 function Is_Remote_Call (N : Node_Id) return Boolean is
8005 if Nkind (N) /= N_Procedure_Call_Statement
8006 and then Nkind (N) /= N_Function_Call
8008 -- An entry call cannot be remote
8012 elsif Nkind (Name (N)) in N_Has_Entity
8013 and then Is_Remote_Call_Interface (Entity (Name (N)))
8015 -- A subprogram declared in the spec of a RCI package is remote
8019 elsif Nkind (Name (N)) = N_Explicit_Dereference
8020 and then Is_Remote_Access_To_Subprogram_Type
8021 (Etype (Prefix (Name (N))))
8023 -- The dereference of a RAS is a remote call
8027 elsif Present (Controlling_Argument (N))
8028 and then Is_Remote_Access_To_Class_Wide_Type
8029 (Etype (Controlling_Argument (N)))
8031 -- Any primitive operation call with a controlling argument of
8032 -- a RACW type is a remote call.
8037 -- All other calls are local calls
8042 ----------------------
8043 -- Is_Renamed_Entry --
8044 ----------------------
8046 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
8047 Orig_Node : Node_Id := Empty;
8048 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
8050 function Is_Entry (Nam : Node_Id) return Boolean;
8051 -- Determine whether Nam is an entry. Traverse selectors if there are
8052 -- nested selected components.
8058 function Is_Entry (Nam : Node_Id) return Boolean is
8060 if Nkind (Nam) = N_Selected_Component then
8061 return Is_Entry (Selector_Name (Nam));
8064 return Ekind (Entity (Nam)) = E_Entry;
8067 -- Start of processing for Is_Renamed_Entry
8070 if Present (Alias (Proc_Nam)) then
8071 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
8074 -- Look for a rewritten subprogram renaming declaration
8076 if Nkind (Subp_Decl) = N_Subprogram_Declaration
8077 and then Present (Original_Node (Subp_Decl))
8079 Orig_Node := Original_Node (Subp_Decl);
8082 -- The rewritten subprogram is actually an entry
8084 if Present (Orig_Node)
8085 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
8086 and then Is_Entry (Name (Orig_Node))
8092 end Is_Renamed_Entry;
8094 ----------------------------
8095 -- Is_Reversible_Iterator --
8096 ----------------------------
8098 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
8099 Ifaces_List : Elist_Id;
8100 Iface_Elmt : Elmt_Id;
8104 if Is_Class_Wide_Type (Typ)
8105 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
8107 Is_Predefined_File_Name
8108 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
8112 elsif not Is_Tagged_Type (Typ)
8113 or else not Is_Derived_Type (Typ)
8118 Collect_Interfaces (Typ, Ifaces_List);
8120 Iface_Elmt := First_Elmt (Ifaces_List);
8121 while Present (Iface_Elmt) loop
8122 Iface := Node (Iface_Elmt);
8123 if Chars (Iface) = Name_Reversible_Iterator
8125 Is_Predefined_File_Name
8126 (Unit_File_Name (Get_Source_Unit (Iface)))
8131 Next_Elmt (Iface_Elmt);
8136 end Is_Reversible_Iterator;
8138 ----------------------
8139 -- Is_Selector_Name --
8140 ----------------------
8142 function Is_Selector_Name (N : Node_Id) return Boolean is
8144 if not Is_List_Member (N) then
8146 P : constant Node_Id := Parent (N);
8147 K : constant Node_Kind := Nkind (P);
8150 (K = N_Expanded_Name or else
8151 K = N_Generic_Association or else
8152 K = N_Parameter_Association or else
8153 K = N_Selected_Component)
8154 and then Selector_Name (P) = N;
8159 L : constant List_Id := List_Containing (N);
8160 P : constant Node_Id := Parent (L);
8162 return (Nkind (P) = N_Discriminant_Association
8163 and then Selector_Names (P) = L)
8165 (Nkind (P) = N_Component_Association
8166 and then Choices (P) = L);
8169 end Is_Selector_Name;
8171 ----------------------------------
8172 -- Is_SPARK_Initialization_Expr --
8173 ----------------------------------
8175 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
8178 Comp_Assn : Node_Id;
8179 Orig_N : constant Node_Id := Original_Node (N);
8184 if not Comes_From_Source (Orig_N) then
8188 pragma Assert (Nkind (Orig_N) in N_Subexpr);
8190 case Nkind (Orig_N) is
8191 when N_Character_Literal |
8199 if Is_Entity_Name (Orig_N)
8200 and then Present (Entity (Orig_N)) -- needed in some cases
8202 case Ekind (Entity (Orig_N)) is
8204 E_Enumeration_Literal |
8209 if Is_Type (Entity (Orig_N)) then
8217 when N_Qualified_Expression |
8218 N_Type_Conversion =>
8219 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
8222 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8226 N_Membership_Test =>
8227 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
8228 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8231 N_Extension_Aggregate =>
8232 if Nkind (Orig_N) = N_Extension_Aggregate then
8233 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
8236 Expr := First (Expressions (Orig_N));
8237 while Present (Expr) loop
8238 if not Is_SPARK_Initialization_Expr (Expr) then
8246 Comp_Assn := First (Component_Associations (Orig_N));
8247 while Present (Comp_Assn) loop
8248 Expr := Expression (Comp_Assn);
8249 if Present (Expr) -- needed for box association
8250 and then not Is_SPARK_Initialization_Expr (Expr)
8259 when N_Attribute_Reference =>
8260 if Nkind (Prefix (Orig_N)) in N_Subexpr then
8261 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
8264 Expr := First (Expressions (Orig_N));
8265 while Present (Expr) loop
8266 if not Is_SPARK_Initialization_Expr (Expr) then
8274 -- Selected components might be expanded named not yet resolved, so
8275 -- default on the safe side. (Eg on sparklex.ads)
8277 when N_Selected_Component =>
8286 end Is_SPARK_Initialization_Expr;
8288 -------------------------------
8289 -- Is_SPARK_Object_Reference --
8290 -------------------------------
8292 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
8294 if Is_Entity_Name (N) then
8295 return Present (Entity (N))
8297 (Ekind_In (Entity (N), E_Constant, E_Variable)
8298 or else Ekind (Entity (N)) in Formal_Kind);
8302 when N_Selected_Component =>
8303 return Is_SPARK_Object_Reference (Prefix (N));
8309 end Is_SPARK_Object_Reference;
8315 function Is_Statement (N : Node_Id) return Boolean is
8318 Nkind (N) in N_Statement_Other_Than_Procedure_Call
8319 or else Nkind (N) = N_Procedure_Call_Statement;
8322 --------------------------------------------------
8323 -- Is_Subprogram_Stub_Without_Prior_Declaration --
8324 --------------------------------------------------
8326 function Is_Subprogram_Stub_Without_Prior_Declaration
8327 (N : Node_Id) return Boolean
8330 -- A subprogram stub without prior declaration serves as declaration for
8331 -- the actual subprogram body. As such, it has an attached defining
8332 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
8334 return Nkind (N) = N_Subprogram_Body_Stub
8335 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
8336 end Is_Subprogram_Stub_Without_Prior_Declaration;
8338 ---------------------------------
8339 -- Is_Synchronized_Tagged_Type --
8340 ---------------------------------
8342 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
8343 Kind : constant Entity_Kind := Ekind (Base_Type (E));
8346 -- A task or protected type derived from an interface is a tagged type.
8347 -- Such a tagged type is called a synchronized tagged type, as are
8348 -- synchronized interfaces and private extensions whose declaration
8349 -- includes the reserved word synchronized.
8351 return (Is_Tagged_Type (E)
8352 and then (Kind = E_Task_Type
8353 or else Kind = E_Protected_Type))
8356 and then Is_Synchronized_Interface (E))
8358 (Ekind (E) = E_Record_Type_With_Private
8359 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
8360 and then (Synchronized_Present (Parent (E))
8361 or else Is_Synchronized_Interface (Etype (E))));
8362 end Is_Synchronized_Tagged_Type;
8368 function Is_Transfer (N : Node_Id) return Boolean is
8369 Kind : constant Node_Kind := Nkind (N);
8372 if Kind = N_Simple_Return_Statement
8374 Kind = N_Extended_Return_Statement
8376 Kind = N_Goto_Statement
8378 Kind = N_Raise_Statement
8380 Kind = N_Requeue_Statement
8384 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
8385 and then No (Condition (N))
8389 elsif Kind = N_Procedure_Call_Statement
8390 and then Is_Entity_Name (Name (N))
8391 and then Present (Entity (Name (N)))
8392 and then No_Return (Entity (Name (N)))
8396 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
8408 function Is_True (U : Uint) return Boolean is
8413 -------------------------------
8414 -- Is_Universal_Numeric_Type --
8415 -------------------------------
8417 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
8419 return T = Universal_Integer or else T = Universal_Real;
8420 end Is_Universal_Numeric_Type;
8426 function Is_Value_Type (T : Entity_Id) return Boolean is
8428 return VM_Target = CLI_Target
8429 and then Nkind (T) in N_Has_Chars
8430 and then Chars (T) /= No_Name
8431 and then Get_Name_String (Chars (T)) = "valuetype";
8434 ---------------------
8435 -- Is_VMS_Operator --
8436 ---------------------
8438 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
8440 -- The VMS operators are declared in a child of System that is loaded
8441 -- through pragma Extend_System. In some rare cases a program is run
8442 -- with this extension but without indicating that the target is VMS.
8444 return Ekind (Op) = E_Function
8445 and then Is_Intrinsic_Subprogram (Op)
8447 ((Present_System_Aux
8448 and then Scope (Op) = System_Aux_Id)
8451 and then Scope (Scope (Op)) = RTU_Entity (System)));
8452 end Is_VMS_Operator;
8458 function Is_Variable
8460 Use_Original_Node : Boolean := True) return Boolean
8462 Orig_Node : Node_Id;
8464 function In_Protected_Function (E : Entity_Id) return Boolean;
8465 -- Within a protected function, the private components of the enclosing
8466 -- protected type are constants. A function nested within a (protected)
8467 -- procedure is not itself protected.
8469 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8470 -- Prefixes can involve implicit dereferences, in which case we must
8471 -- test for the case of a reference of a constant access type, which can
8472 -- can never be a variable.
8474 ---------------------------
8475 -- In_Protected_Function --
8476 ---------------------------
8478 function In_Protected_Function (E : Entity_Id) return Boolean is
8479 Prot : constant Entity_Id := Scope (E);
8483 if not Is_Protected_Type (Prot) then
8487 while Present (S) and then S /= Prot loop
8488 if Ekind (S) = E_Function and then Scope (S) = Prot then
8497 end In_Protected_Function;
8499 ------------------------
8500 -- Is_Variable_Prefix --
8501 ------------------------
8503 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8505 if Is_Access_Type (Etype (P)) then
8506 return not Is_Access_Constant (Root_Type (Etype (P)));
8508 -- For the case of an indexed component whose prefix has a packed
8509 -- array type, the prefix has been rewritten into a type conversion.
8510 -- Determine variable-ness from the converted expression.
8512 elsif Nkind (P) = N_Type_Conversion
8513 and then not Comes_From_Source (P)
8514 and then Is_Array_Type (Etype (P))
8515 and then Is_Packed (Etype (P))
8517 return Is_Variable (Expression (P));
8520 return Is_Variable (P);
8522 end Is_Variable_Prefix;
8524 -- Start of processing for Is_Variable
8527 -- Check if we perform the test on the original node since this may be a
8528 -- test of syntactic categories which must not be disturbed by whatever
8529 -- rewriting might have occurred. For example, an aggregate, which is
8530 -- certainly NOT a variable, could be turned into a variable by
8533 if Use_Original_Node then
8534 Orig_Node := Original_Node (N);
8539 -- Definitely OK if Assignment_OK is set. Since this is something that
8540 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8542 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8545 -- Normally we go to the original node, but there is one exception where
8546 -- we use the rewritten node, namely when it is an explicit dereference.
8547 -- The generated code may rewrite a prefix which is an access type with
8548 -- an explicit dereference. The dereference is a variable, even though
8549 -- the original node may not be (since it could be a constant of the
8552 -- In Ada 2005 we have a further case to consider: the prefix may be a
8553 -- function call given in prefix notation. The original node appears to
8554 -- be a selected component, but we need to examine the call.
8556 elsif Nkind (N) = N_Explicit_Dereference
8557 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8558 and then Present (Etype (Orig_Node))
8559 and then Is_Access_Type (Etype (Orig_Node))
8561 -- Note that if the prefix is an explicit dereference that does not
8562 -- come from source, we must check for a rewritten function call in
8563 -- prefixed notation before other forms of rewriting, to prevent a
8567 (Nkind (Orig_Node) = N_Function_Call
8568 and then not Is_Access_Constant (Etype (Prefix (N))))
8570 Is_Variable_Prefix (Original_Node (Prefix (N)));
8572 -- A function call is never a variable
8574 elsif Nkind (N) = N_Function_Call then
8577 -- All remaining checks use the original node
8579 elsif Is_Entity_Name (Orig_Node)
8580 and then Present (Entity (Orig_Node))
8583 E : constant Entity_Id := Entity (Orig_Node);
8584 K : constant Entity_Kind := Ekind (E);
8587 return (K = E_Variable
8588 and then Nkind (Parent (E)) /= N_Exception_Handler)
8589 or else (K = E_Component
8590 and then not In_Protected_Function (E))
8591 or else K = E_Out_Parameter
8592 or else K = E_In_Out_Parameter
8593 or else K = E_Generic_In_Out_Parameter
8595 -- Current instance of type
8597 or else (Is_Type (E) and then In_Open_Scopes (E))
8598 or else (Is_Incomplete_Or_Private_Type (E)
8599 and then In_Open_Scopes (Full_View (E)));
8603 case Nkind (Orig_Node) is
8604 when N_Indexed_Component | N_Slice =>
8605 return Is_Variable_Prefix (Prefix (Orig_Node));
8607 when N_Selected_Component =>
8608 return Is_Variable_Prefix (Prefix (Orig_Node))
8609 and then Is_Variable (Selector_Name (Orig_Node));
8611 -- For an explicit dereference, the type of the prefix cannot
8612 -- be an access to constant or an access to subprogram.
8614 when N_Explicit_Dereference =>
8616 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8618 return Is_Access_Type (Typ)
8619 and then not Is_Access_Constant (Root_Type (Typ))
8620 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8623 -- The type conversion is the case where we do not deal with the
8624 -- context dependent special case of an actual parameter. Thus
8625 -- the type conversion is only considered a variable for the
8626 -- purposes of this routine if the target type is tagged. However,
8627 -- a type conversion is considered to be a variable if it does not
8628 -- come from source (this deals for example with the conversions
8629 -- of expressions to their actual subtypes).
8631 when N_Type_Conversion =>
8632 return Is_Variable (Expression (Orig_Node))
8634 (not Comes_From_Source (Orig_Node)
8636 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8638 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8640 -- GNAT allows an unchecked type conversion as a variable. This
8641 -- only affects the generation of internal expanded code, since
8642 -- calls to instantiations of Unchecked_Conversion are never
8643 -- considered variables (since they are function calls).
8644 -- This is also true for expression actions.
8646 when N_Unchecked_Type_Conversion =>
8647 return Is_Variable (Expression (Orig_Node));
8655 ---------------------------
8656 -- Is_Visibly_Controlled --
8657 ---------------------------
8659 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8660 Root : constant Entity_Id := Root_Type (T);
8662 return Chars (Scope (Root)) = Name_Finalization
8663 and then Chars (Scope (Scope (Root))) = Name_Ada
8664 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8665 end Is_Visibly_Controlled;
8667 ------------------------
8668 -- Is_Volatile_Object --
8669 ------------------------
8671 function Is_Volatile_Object (N : Node_Id) return Boolean is
8673 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8674 -- Determines if given object has volatile components
8676 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8677 -- If prefix is an implicit dereference, examine designated type
8679 ------------------------
8680 -- Is_Volatile_Prefix --
8681 ------------------------
8683 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8684 Typ : constant Entity_Id := Etype (N);
8687 if Is_Access_Type (Typ) then
8689 Dtyp : constant Entity_Id := Designated_Type (Typ);
8692 return Is_Volatile (Dtyp)
8693 or else Has_Volatile_Components (Dtyp);
8697 return Object_Has_Volatile_Components (N);
8699 end Is_Volatile_Prefix;
8701 ------------------------------------
8702 -- Object_Has_Volatile_Components --
8703 ------------------------------------
8705 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8706 Typ : constant Entity_Id := Etype (N);
8709 if Is_Volatile (Typ)
8710 or else Has_Volatile_Components (Typ)
8714 elsif Is_Entity_Name (N)
8715 and then (Has_Volatile_Components (Entity (N))
8716 or else Is_Volatile (Entity (N)))
8720 elsif Nkind (N) = N_Indexed_Component
8721 or else Nkind (N) = N_Selected_Component
8723 return Is_Volatile_Prefix (Prefix (N));
8728 end Object_Has_Volatile_Components;
8730 -- Start of processing for Is_Volatile_Object
8733 if Is_Volatile (Etype (N))
8734 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8738 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
8739 and then Is_Volatile_Prefix (Prefix (N))
8743 elsif Nkind (N) = N_Selected_Component
8744 and then Is_Volatile (Entity (Selector_Name (N)))
8751 end Is_Volatile_Object;
8753 ---------------------------
8754 -- Itype_Has_Declaration --
8755 ---------------------------
8757 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
8759 pragma Assert (Is_Itype (Id));
8760 return Present (Parent (Id))
8761 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
8762 N_Subtype_Declaration)
8763 and then Defining_Entity (Parent (Id)) = Id;
8764 end Itype_Has_Declaration;
8766 -------------------------
8767 -- Kill_Current_Values --
8768 -------------------------
8770 procedure Kill_Current_Values
8772 Last_Assignment_Only : Boolean := False)
8775 -- ??? do we have to worry about clearing cached checks?
8777 if Is_Assignable (Ent) then
8778 Set_Last_Assignment (Ent, Empty);
8781 if Is_Object (Ent) then
8782 if not Last_Assignment_Only then
8784 Set_Current_Value (Ent, Empty);
8786 if not Can_Never_Be_Null (Ent) then
8787 Set_Is_Known_Non_Null (Ent, False);
8790 Set_Is_Known_Null (Ent, False);
8792 -- Reset Is_Known_Valid unless type is always valid, or if we have
8793 -- a loop parameter (loop parameters are always valid, since their
8794 -- bounds are defined by the bounds given in the loop header).
8796 if not Is_Known_Valid (Etype (Ent))
8797 and then Ekind (Ent) /= E_Loop_Parameter
8799 Set_Is_Known_Valid (Ent, False);
8803 end Kill_Current_Values;
8805 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8808 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8809 -- Clear current value for entity E and all entities chained to E
8811 ------------------------------------------
8812 -- Kill_Current_Values_For_Entity_Chain --
8813 ------------------------------------------
8815 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8819 while Present (Ent) loop
8820 Kill_Current_Values (Ent, Last_Assignment_Only);
8823 end Kill_Current_Values_For_Entity_Chain;
8825 -- Start of processing for Kill_Current_Values
8828 -- Kill all saved checks, a special case of killing saved values
8830 if not Last_Assignment_Only then
8834 -- Loop through relevant scopes, which includes the current scope and
8835 -- any parent scopes if the current scope is a block or a package.
8840 -- Clear current values of all entities in current scope
8842 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8844 -- If scope is a package, also clear current values of all private
8845 -- entities in the scope.
8847 if Is_Package_Or_Generic_Package (S)
8848 or else Is_Concurrent_Type (S)
8850 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8853 -- If this is a not a subprogram, deal with parents
8855 if not Is_Subprogram (S) then
8857 exit Scope_Loop when S = Standard_Standard;
8861 end loop Scope_Loop;
8862 end Kill_Current_Values;
8864 --------------------------
8865 -- Kill_Size_Check_Code --
8866 --------------------------
8868 procedure Kill_Size_Check_Code (E : Entity_Id) is
8870 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8871 and then Present (Size_Check_Code (E))
8873 Remove (Size_Check_Code (E));
8874 Set_Size_Check_Code (E, Empty);
8876 end Kill_Size_Check_Code;
8878 --------------------------
8879 -- Known_To_Be_Assigned --
8880 --------------------------
8882 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8883 P : constant Node_Id := Parent (N);
8888 -- Test left side of assignment
8890 when N_Assignment_Statement =>
8891 return N = Name (P);
8893 -- Function call arguments are never lvalues
8895 when N_Function_Call =>
8898 -- Positional parameter for procedure or accept call
8900 when N_Procedure_Call_Statement |
8909 Proc := Get_Subprogram_Entity (P);
8915 -- If we are not a list member, something is strange, so
8916 -- be conservative and return False.
8918 if not Is_List_Member (N) then
8922 -- We are going to find the right formal by stepping forward
8923 -- through the formals, as we step backwards in the actuals.
8925 Form := First_Formal (Proc);
8928 -- If no formal, something is weird, so be conservative
8929 -- and return False.
8940 return Ekind (Form) /= E_In_Parameter;
8943 -- Named parameter for procedure or accept call
8945 when N_Parameter_Association =>
8951 Proc := Get_Subprogram_Entity (Parent (P));
8957 -- Loop through formals to find the one that matches
8959 Form := First_Formal (Proc);
8961 -- If no matching formal, that's peculiar, some kind of
8962 -- previous error, so return False to be conservative.
8968 -- Else test for match
8970 if Chars (Form) = Chars (Selector_Name (P)) then
8971 return Ekind (Form) /= E_In_Parameter;
8978 -- Test for appearing in a conversion that itself appears
8979 -- in an lvalue context, since this should be an lvalue.
8981 when N_Type_Conversion =>
8982 return Known_To_Be_Assigned (P);
8984 -- All other references are definitely not known to be modifications
8990 end Known_To_Be_Assigned;
8992 ---------------------------
8993 -- Last_Source_Statement --
8994 ---------------------------
8996 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
9000 N := Last (Statements (HSS));
9001 while Present (N) loop
9002 exit when Comes_From_Source (N);
9007 end Last_Source_Statement;
9009 ----------------------------------
9010 -- Matching_Static_Array_Bounds --
9011 ----------------------------------
9013 function Matching_Static_Array_Bounds
9015 R_Typ : Node_Id) return Boolean
9017 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
9018 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
9030 if L_Ndims /= R_Ndims then
9034 -- Unconstrained types do not have static bounds
9036 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
9040 -- First treat specially the first dimension, as the lower bound and
9041 -- length of string literals are not stored like those of arrays.
9043 if Ekind (L_Typ) = E_String_Literal_Subtype then
9044 L_Low := String_Literal_Low_Bound (L_Typ);
9045 L_Len := String_Literal_Length (L_Typ);
9047 L_Index := First_Index (L_Typ);
9048 Get_Index_Bounds (L_Index, L_Low, L_High);
9050 if Is_OK_Static_Expression (L_Low)
9051 and then Is_OK_Static_Expression (L_High)
9053 if Expr_Value (L_High) < Expr_Value (L_Low) then
9056 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
9063 if Ekind (R_Typ) = E_String_Literal_Subtype then
9064 R_Low := String_Literal_Low_Bound (R_Typ);
9065 R_Len := String_Literal_Length (R_Typ);
9067 R_Index := First_Index (R_Typ);
9068 Get_Index_Bounds (R_Index, R_Low, R_High);
9070 if Is_OK_Static_Expression (R_Low)
9071 and then Is_OK_Static_Expression (R_High)
9073 if Expr_Value (R_High) < Expr_Value (R_Low) then
9076 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
9083 if Is_OK_Static_Expression (L_Low)
9084 and then Is_OK_Static_Expression (R_Low)
9085 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9086 and then L_Len = R_Len
9093 -- Then treat all other dimensions
9095 for Indx in 2 .. L_Ndims loop
9099 Get_Index_Bounds (L_Index, L_Low, L_High);
9100 Get_Index_Bounds (R_Index, R_Low, R_High);
9102 if Is_OK_Static_Expression (L_Low)
9103 and then Is_OK_Static_Expression (L_High)
9104 and then Is_OK_Static_Expression (R_Low)
9105 and then Is_OK_Static_Expression (R_High)
9106 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9107 and then Expr_Value (L_High) = Expr_Value (R_High)
9115 -- If we fall through the loop, all indexes matched
9118 end Matching_Static_Array_Bounds;
9124 function May_Be_Lvalue (N : Node_Id) return Boolean is
9125 P : constant Node_Id := Parent (N);
9130 -- Test left side of assignment
9132 when N_Assignment_Statement =>
9133 return N = Name (P);
9135 -- Test prefix of component or attribute. Note that the prefix of an
9136 -- explicit or implicit dereference cannot be an l-value.
9138 when N_Attribute_Reference =>
9139 return N = Prefix (P)
9140 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
9142 -- For an expanded name, the name is an lvalue if the expanded name
9143 -- is an lvalue, but the prefix is never an lvalue, since it is just
9144 -- the scope where the name is found.
9146 when N_Expanded_Name =>
9147 if N = Prefix (P) then
9148 return May_Be_Lvalue (P);
9153 -- For a selected component A.B, A is certainly an lvalue if A.B is.
9154 -- B is a little interesting, if we have A.B := 3, there is some
9155 -- discussion as to whether B is an lvalue or not, we choose to say
9156 -- it is. Note however that A is not an lvalue if it is of an access
9157 -- type since this is an implicit dereference.
9159 when N_Selected_Component =>
9161 and then Present (Etype (N))
9162 and then Is_Access_Type (Etype (N))
9166 return May_Be_Lvalue (P);
9169 -- For an indexed component or slice, the index or slice bounds is
9170 -- never an lvalue. The prefix is an lvalue if the indexed component
9171 -- or slice is an lvalue, except if it is an access type, where we
9172 -- have an implicit dereference.
9174 when N_Indexed_Component | N_Slice =>
9176 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
9180 return May_Be_Lvalue (P);
9183 -- Prefix of a reference is an lvalue if the reference is an lvalue
9186 return May_Be_Lvalue (P);
9188 -- Prefix of explicit dereference is never an lvalue
9190 when N_Explicit_Dereference =>
9193 -- Positional parameter for subprogram, entry, or accept call.
9194 -- In older versions of Ada function call arguments are never
9195 -- lvalues. In Ada 2012 functions can have in-out parameters.
9197 when N_Function_Call |
9198 N_Procedure_Call_Statement |
9199 N_Entry_Call_Statement |
9202 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
9206 -- The following mechanism is clumsy and fragile. A single flag
9207 -- set in Resolve_Actuals would be preferable ???
9215 Proc := Get_Subprogram_Entity (P);
9221 -- If we are not a list member, something is strange, so be
9222 -- conservative and return True.
9224 if not Is_List_Member (N) then
9228 -- We are going to find the right formal by stepping forward
9229 -- through the formals, as we step backwards in the actuals.
9231 Form := First_Formal (Proc);
9234 -- If no formal, something is weird, so be conservative and
9246 return Ekind (Form) /= E_In_Parameter;
9249 -- Named parameter for procedure or accept call
9251 when N_Parameter_Association =>
9257 Proc := Get_Subprogram_Entity (Parent (P));
9263 -- Loop through formals to find the one that matches
9265 Form := First_Formal (Proc);
9267 -- If no matching formal, that's peculiar, some kind of
9268 -- previous error, so return True to be conservative.
9274 -- Else test for match
9276 if Chars (Form) = Chars (Selector_Name (P)) then
9277 return Ekind (Form) /= E_In_Parameter;
9284 -- Test for appearing in a conversion that itself appears in an
9285 -- lvalue context, since this should be an lvalue.
9287 when N_Type_Conversion =>
9288 return May_Be_Lvalue (P);
9290 -- Test for appearance in object renaming declaration
9292 when N_Object_Renaming_Declaration =>
9295 -- All other references are definitely not lvalues
9303 -----------------------
9304 -- Mark_Coextensions --
9305 -----------------------
9307 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
9308 Is_Dynamic : Boolean;
9309 -- Indicates whether the context causes nested coextensions to be
9310 -- dynamic or static
9312 function Mark_Allocator (N : Node_Id) return Traverse_Result;
9313 -- Recognize an allocator node and label it as a dynamic coextension
9315 --------------------
9316 -- Mark_Allocator --
9317 --------------------
9319 function Mark_Allocator (N : Node_Id) return Traverse_Result is
9321 if Nkind (N) = N_Allocator then
9323 Set_Is_Dynamic_Coextension (N);
9325 -- If the allocator expression is potentially dynamic, it may
9326 -- be expanded out of order and require dynamic allocation
9327 -- anyway, so we treat the coextension itself as dynamic.
9328 -- Potential optimization ???
9330 elsif Nkind (Expression (N)) = N_Qualified_Expression
9331 and then Nkind (Expression (Expression (N))) = N_Op_Concat
9333 Set_Is_Dynamic_Coextension (N);
9335 Set_Is_Static_Coextension (N);
9342 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
9344 -- Start of processing Mark_Coextensions
9347 case Nkind (Context_Nod) is
9351 when N_Assignment_Statement =>
9352 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
9354 -- An allocator that is a component of a returned aggregate
9357 when N_Simple_Return_Statement =>
9359 Expr : constant Node_Id := Expression (Context_Nod);
9362 Nkind (Expr) = N_Allocator
9364 (Nkind (Expr) = N_Qualified_Expression
9365 and then Nkind (Expression (Expr)) = N_Aggregate);
9368 -- An alloctor within an object declaration in an extended return
9369 -- statement is of necessity dynamic.
9371 when N_Object_Declaration =>
9372 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
9374 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
9376 -- This routine should not be called for constructs which may not
9377 -- contain coextensions.
9380 raise Program_Error;
9383 Mark_Allocators (Root_Nod);
9384 end Mark_Coextensions;
9386 ----------------------
9387 -- Needs_One_Actual --
9388 ----------------------
9390 function Needs_One_Actual (E : Entity_Id) return Boolean is
9394 -- Ada 2005 or later, and formals present
9396 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
9397 Formal := Next_Formal (First_Formal (E));
9398 while Present (Formal) loop
9399 if No (Default_Value (Formal)) then
9403 Next_Formal (Formal);
9408 -- Ada 83/95 or no formals
9413 end Needs_One_Actual;
9415 ------------------------
9416 -- New_Copy_List_Tree --
9417 ------------------------
9419 function New_Copy_List_Tree (List : List_Id) return List_Id is
9424 if List = No_List then
9431 while Present (E) loop
9432 Append (New_Copy_Tree (E), NL);
9438 end New_Copy_List_Tree;
9444 use Atree.Unchecked_Access;
9445 use Atree_Private_Part;
9447 -- Our approach here requires a two pass traversal of the tree. The
9448 -- first pass visits all nodes that eventually will be copied looking
9449 -- for defining Itypes. If any defining Itypes are found, then they are
9450 -- copied, and an entry is added to the replacement map. In the second
9451 -- phase, the tree is copied, using the replacement map to replace any
9452 -- Itype references within the copied tree.
9454 -- The following hash tables are used if the Map supplied has more
9455 -- than hash threshold entries to speed up access to the map. If
9456 -- there are fewer entries, then the map is searched sequentially
9457 -- (because setting up a hash table for only a few entries takes
9458 -- more time than it saves.
9460 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
9461 -- Hash function used for hash operations
9467 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
9469 return Nat (E) mod (NCT_Header_Num'Last + 1);
9476 -- The hash table NCT_Assoc associates old entities in the table
9477 -- with their corresponding new entities (i.e. the pairs of entries
9478 -- presented in the original Map argument are Key-Element pairs).
9480 package NCT_Assoc is new Simple_HTable (
9481 Header_Num => NCT_Header_Num,
9482 Element => Entity_Id,
9483 No_Element => Empty,
9485 Hash => New_Copy_Hash,
9486 Equal => Types."=");
9488 ---------------------
9489 -- NCT_Itype_Assoc --
9490 ---------------------
9492 -- The hash table NCT_Itype_Assoc contains entries only for those
9493 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9494 -- The key is the associated node, and the element is the new node
9495 -- itself (NOT the associated node for the new node).
9497 package NCT_Itype_Assoc is new Simple_HTable (
9498 Header_Num => NCT_Header_Num,
9499 Element => Entity_Id,
9500 No_Element => Empty,
9502 Hash => New_Copy_Hash,
9503 Equal => Types."=");
9505 -- Start of processing for New_Copy_Tree function
9507 function New_Copy_Tree
9509 Map : Elist_Id := No_Elist;
9510 New_Sloc : Source_Ptr := No_Location;
9511 New_Scope : Entity_Id := Empty) return Node_Id
9513 Actual_Map : Elist_Id := Map;
9514 -- This is the actual map for the copy. It is initialized with the
9515 -- given elements, and then enlarged as required for Itypes that are
9516 -- copied during the first phase of the copy operation. The visit
9517 -- procedures add elements to this map as Itypes are encountered.
9518 -- The reason we cannot use Map directly, is that it may well be
9519 -- (and normally is) initialized to No_Elist, and if we have mapped
9520 -- entities, we have to reset it to point to a real Elist.
9522 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9523 -- Called during second phase to map entities into their corresponding
9524 -- copies using Actual_Map. If the argument is not an entity, or is not
9525 -- in Actual_Map, then it is returned unchanged.
9527 procedure Build_NCT_Hash_Tables;
9528 -- Builds hash tables (number of elements >= threshold value)
9530 function Copy_Elist_With_Replacement
9531 (Old_Elist : Elist_Id) return Elist_Id;
9532 -- Called during second phase to copy element list doing replacements
9534 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9535 -- Called during the second phase to process a copied Itype. The actual
9536 -- copy happened during the first phase (so that we could make the entry
9537 -- in the mapping), but we still have to deal with the descendents of
9538 -- the copied Itype and copy them where necessary.
9540 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9541 -- Called during second phase to copy list doing replacements
9543 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9544 -- Called during second phase to copy node doing replacements
9546 procedure Visit_Elist (E : Elist_Id);
9547 -- Called during first phase to visit all elements of an Elist
9549 procedure Visit_Field (F : Union_Id; N : Node_Id);
9550 -- Visit a single field, recursing to call Visit_Node or Visit_List
9551 -- if the field is a syntactic descendent of the current node (i.e.
9552 -- its parent is Node N).
9554 procedure Visit_Itype (Old_Itype : Entity_Id);
9555 -- Called during first phase to visit subsidiary fields of a defining
9556 -- Itype, and also create a copy and make an entry in the replacement
9557 -- map for the new copy.
9559 procedure Visit_List (L : List_Id);
9560 -- Called during first phase to visit all elements of a List
9562 procedure Visit_Node (N : Node_Or_Entity_Id);
9563 -- Called during first phase to visit a node and all its subtrees
9569 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9574 if not Has_Extension (N) or else No (Actual_Map) then
9577 elsif NCT_Hash_Tables_Used then
9578 Ent := NCT_Assoc.Get (Entity_Id (N));
9580 if Present (Ent) then
9586 -- No hash table used, do serial search
9589 E := First_Elmt (Actual_Map);
9590 while Present (E) loop
9591 if Node (E) = N then
9592 return Node (Next_Elmt (E));
9594 E := Next_Elmt (Next_Elmt (E));
9602 ---------------------------
9603 -- Build_NCT_Hash_Tables --
9604 ---------------------------
9606 procedure Build_NCT_Hash_Tables is
9610 if NCT_Hash_Table_Setup then
9612 NCT_Itype_Assoc.Reset;
9615 Elmt := First_Elmt (Actual_Map);
9616 while Present (Elmt) loop
9619 -- Get new entity, and associate old and new
9622 NCT_Assoc.Set (Ent, Node (Elmt));
9624 if Is_Type (Ent) then
9626 Anode : constant Entity_Id :=
9627 Associated_Node_For_Itype (Ent);
9630 if Present (Anode) then
9632 -- Enter a link between the associated node of the
9633 -- old Itype and the new Itype, for updating later
9634 -- when node is copied.
9636 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9644 NCT_Hash_Tables_Used := True;
9645 NCT_Hash_Table_Setup := True;
9646 end Build_NCT_Hash_Tables;
9648 ---------------------------------
9649 -- Copy_Elist_With_Replacement --
9650 ---------------------------------
9652 function Copy_Elist_With_Replacement
9653 (Old_Elist : Elist_Id) return Elist_Id
9656 New_Elist : Elist_Id;
9659 if No (Old_Elist) then
9663 New_Elist := New_Elmt_List;
9665 M := First_Elmt (Old_Elist);
9666 while Present (M) loop
9667 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9673 end Copy_Elist_With_Replacement;
9675 ---------------------------------
9676 -- Copy_Itype_With_Replacement --
9677 ---------------------------------
9679 -- This routine exactly parallels its phase one analog Visit_Itype,
9681 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9683 -- Translate Next_Entity, Scope and Etype fields, in case they
9684 -- reference entities that have been mapped into copies.
9686 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9687 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9689 if Present (New_Scope) then
9690 Set_Scope (New_Itype, New_Scope);
9692 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9695 -- Copy referenced fields
9697 if Is_Discrete_Type (New_Itype) then
9698 Set_Scalar_Range (New_Itype,
9699 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9701 elsif Has_Discriminants (Base_Type (New_Itype)) then
9702 Set_Discriminant_Constraint (New_Itype,
9703 Copy_Elist_With_Replacement
9704 (Discriminant_Constraint (New_Itype)));
9706 elsif Is_Array_Type (New_Itype) then
9707 if Present (First_Index (New_Itype)) then
9708 Set_First_Index (New_Itype,
9709 First (Copy_List_With_Replacement
9710 (List_Containing (First_Index (New_Itype)))));
9713 if Is_Packed (New_Itype) then
9714 Set_Packed_Array_Type (New_Itype,
9715 Copy_Node_With_Replacement
9716 (Packed_Array_Type (New_Itype)));
9719 end Copy_Itype_With_Replacement;
9721 --------------------------------
9722 -- Copy_List_With_Replacement --
9723 --------------------------------
9725 function Copy_List_With_Replacement
9726 (Old_List : List_Id) return List_Id
9732 if Old_List = No_List then
9736 New_List := Empty_List;
9738 E := First (Old_List);
9739 while Present (E) loop
9740 Append (Copy_Node_With_Replacement (E), New_List);
9746 end Copy_List_With_Replacement;
9748 --------------------------------
9749 -- Copy_Node_With_Replacement --
9750 --------------------------------
9752 function Copy_Node_With_Replacement
9753 (Old_Node : Node_Id) return Node_Id
9757 procedure Adjust_Named_Associations
9758 (Old_Node : Node_Id;
9759 New_Node : Node_Id);
9760 -- If a call node has named associations, these are chained through
9761 -- the First_Named_Actual, Next_Named_Actual links. These must be
9762 -- propagated separately to the new parameter list, because these
9763 -- are not syntactic fields.
9765 function Copy_Field_With_Replacement
9766 (Field : Union_Id) return Union_Id;
9767 -- Given Field, which is a field of Old_Node, return a copy of it
9768 -- if it is a syntactic field (i.e. its parent is Node), setting
9769 -- the parent of the copy to poit to New_Node. Otherwise returns
9770 -- the field (possibly mapped if it is an entity).
9772 -------------------------------
9773 -- Adjust_Named_Associations --
9774 -------------------------------
9776 procedure Adjust_Named_Associations
9777 (Old_Node : Node_Id;
9787 Old_E := First (Parameter_Associations (Old_Node));
9788 New_E := First (Parameter_Associations (New_Node));
9789 while Present (Old_E) loop
9790 if Nkind (Old_E) = N_Parameter_Association
9791 and then Present (Next_Named_Actual (Old_E))
9793 if First_Named_Actual (Old_Node)
9794 = Explicit_Actual_Parameter (Old_E)
9796 Set_First_Named_Actual
9797 (New_Node, Explicit_Actual_Parameter (New_E));
9800 -- Now scan parameter list from the beginning,to locate
9801 -- next named actual, which can be out of order.
9803 Old_Next := First (Parameter_Associations (Old_Node));
9804 New_Next := First (Parameter_Associations (New_Node));
9806 while Nkind (Old_Next) /= N_Parameter_Association
9807 or else Explicit_Actual_Parameter (Old_Next)
9808 /= Next_Named_Actual (Old_E)
9814 Set_Next_Named_Actual
9815 (New_E, Explicit_Actual_Parameter (New_Next));
9821 end Adjust_Named_Associations;
9823 ---------------------------------
9824 -- Copy_Field_With_Replacement --
9825 ---------------------------------
9827 function Copy_Field_With_Replacement
9828 (Field : Union_Id) return Union_Id
9831 if Field = Union_Id (Empty) then
9834 elsif Field in Node_Range then
9836 Old_N : constant Node_Id := Node_Id (Field);
9840 -- If syntactic field, as indicated by the parent pointer
9841 -- being set, then copy the referenced node recursively.
9843 if Parent (Old_N) = Old_Node then
9844 New_N := Copy_Node_With_Replacement (Old_N);
9846 if New_N /= Old_N then
9847 Set_Parent (New_N, New_Node);
9850 -- For semantic fields, update possible entity reference
9851 -- from the replacement map.
9854 New_N := Assoc (Old_N);
9857 return Union_Id (New_N);
9860 elsif Field in List_Range then
9862 Old_L : constant List_Id := List_Id (Field);
9866 -- If syntactic field, as indicated by the parent pointer,
9867 -- then recursively copy the entire referenced list.
9869 if Parent (Old_L) = Old_Node then
9870 New_L := Copy_List_With_Replacement (Old_L);
9871 Set_Parent (New_L, New_Node);
9873 -- For semantic list, just returned unchanged
9879 return Union_Id (New_L);
9882 -- Anything other than a list or a node is returned unchanged
9887 end Copy_Field_With_Replacement;
9889 -- Start of processing for Copy_Node_With_Replacement
9892 if Old_Node <= Empty_Or_Error then
9895 elsif Has_Extension (Old_Node) then
9896 return Assoc (Old_Node);
9899 New_Node := New_Copy (Old_Node);
9901 -- If the node we are copying is the associated node of a
9902 -- previously copied Itype, then adjust the associated node
9903 -- of the copy of that Itype accordingly.
9905 if Present (Actual_Map) then
9911 -- Case of hash table used
9913 if NCT_Hash_Tables_Used then
9914 Ent := NCT_Itype_Assoc.Get (Old_Node);
9916 if Present (Ent) then
9917 Set_Associated_Node_For_Itype (Ent, New_Node);
9920 -- Case of no hash table used
9923 E := First_Elmt (Actual_Map);
9924 while Present (E) loop
9925 if Is_Itype (Node (E))
9927 Old_Node = Associated_Node_For_Itype (Node (E))
9929 Set_Associated_Node_For_Itype
9930 (Node (Next_Elmt (E)), New_Node);
9933 E := Next_Elmt (Next_Elmt (E));
9939 -- Recursively copy descendents
9942 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9944 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9946 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9948 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9950 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9952 -- Adjust Sloc of new node if necessary
9954 if New_Sloc /= No_Location then
9955 Set_Sloc (New_Node, New_Sloc);
9957 -- If we adjust the Sloc, then we are essentially making
9958 -- a completely new node, so the Comes_From_Source flag
9959 -- should be reset to the proper default value.
9961 Nodes.Table (New_Node).Comes_From_Source :=
9962 Default_Node.Comes_From_Source;
9965 -- If the node is call and has named associations,
9966 -- set the corresponding links in the copy.
9968 if (Nkind (Old_Node) = N_Function_Call
9969 or else Nkind (Old_Node) = N_Entry_Call_Statement
9971 Nkind (Old_Node) = N_Procedure_Call_Statement)
9972 and then Present (First_Named_Actual (Old_Node))
9974 Adjust_Named_Associations (Old_Node, New_Node);
9977 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9978 -- The replacement mechanism applies to entities, and is not used
9979 -- here. Eventually we may need a more general graph-copying
9980 -- routine. For now, do a sequential search to find desired node.
9982 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9983 and then Present (First_Real_Statement (Old_Node))
9986 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9990 N1 := First (Statements (Old_Node));
9991 N2 := First (Statements (New_Node));
9993 while N1 /= Old_F loop
9998 Set_First_Real_Statement (New_Node, N2);
10003 -- All done, return copied node
10006 end Copy_Node_With_Replacement;
10012 procedure Visit_Elist (E : Elist_Id) is
10015 if Present (E) then
10016 Elmt := First_Elmt (E);
10018 while Elmt /= No_Elmt loop
10019 Visit_Node (Node (Elmt));
10029 procedure Visit_Field (F : Union_Id; N : Node_Id) is
10031 if F = Union_Id (Empty) then
10034 elsif F in Node_Range then
10036 -- Copy node if it is syntactic, i.e. its parent pointer is
10037 -- set to point to the field that referenced it (certain
10038 -- Itypes will also meet this criterion, which is fine, since
10039 -- these are clearly Itypes that do need to be copied, since
10040 -- we are copying their parent.)
10042 if Parent (Node_Id (F)) = N then
10043 Visit_Node (Node_Id (F));
10046 -- Another case, if we are pointing to an Itype, then we want
10047 -- to copy it if its associated node is somewhere in the tree
10050 -- Note: the exclusion of self-referential copies is just an
10051 -- optimization, since the search of the already copied list
10052 -- would catch it, but it is a common case (Etype pointing
10053 -- to itself for an Itype that is a base type).
10055 elsif Has_Extension (Node_Id (F))
10056 and then Is_Itype (Entity_Id (F))
10057 and then Node_Id (F) /= N
10063 P := Associated_Node_For_Itype (Node_Id (F));
10064 while Present (P) loop
10066 Visit_Node (Node_Id (F));
10073 -- An Itype whose parent is not being copied definitely
10074 -- should NOT be copied, since it does not belong in any
10075 -- sense to the copied subtree.
10081 elsif F in List_Range
10082 and then Parent (List_Id (F)) = N
10084 Visit_List (List_Id (F));
10093 procedure Visit_Itype (Old_Itype : Entity_Id) is
10094 New_Itype : Entity_Id;
10099 -- Itypes that describe the designated type of access to subprograms
10100 -- have the structure of subprogram declarations, with signatures,
10101 -- etc. Either we duplicate the signatures completely, or choose to
10102 -- share such itypes, which is fine because their elaboration will
10103 -- have no side effects.
10105 if Ekind (Old_Itype) = E_Subprogram_Type then
10109 New_Itype := New_Copy (Old_Itype);
10111 -- The new Itype has all the attributes of the old one, and
10112 -- we just copy the contents of the entity. However, the back-end
10113 -- needs different names for debugging purposes, so we create a
10114 -- new internal name for it in all cases.
10116 Set_Chars (New_Itype, New_Internal_Name ('T'));
10118 -- If our associated node is an entity that has already been copied,
10119 -- then set the associated node of the copy to point to the right
10120 -- copy. If we have copied an Itype that is itself the associated
10121 -- node of some previously copied Itype, then we set the right
10122 -- pointer in the other direction.
10124 if Present (Actual_Map) then
10126 -- Case of hash tables used
10128 if NCT_Hash_Tables_Used then
10130 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
10132 if Present (Ent) then
10133 Set_Associated_Node_For_Itype (New_Itype, Ent);
10136 Ent := NCT_Itype_Assoc.Get (Old_Itype);
10137 if Present (Ent) then
10138 Set_Associated_Node_For_Itype (Ent, New_Itype);
10140 -- If the hash table has no association for this Itype and
10141 -- its associated node, enter one now.
10144 NCT_Itype_Assoc.Set
10145 (Associated_Node_For_Itype (Old_Itype), New_Itype);
10148 -- Case of hash tables not used
10151 E := First_Elmt (Actual_Map);
10152 while Present (E) loop
10153 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
10154 Set_Associated_Node_For_Itype
10155 (New_Itype, Node (Next_Elmt (E)));
10158 if Is_Type (Node (E))
10160 Old_Itype = Associated_Node_For_Itype (Node (E))
10162 Set_Associated_Node_For_Itype
10163 (Node (Next_Elmt (E)), New_Itype);
10166 E := Next_Elmt (Next_Elmt (E));
10171 if Present (Freeze_Node (New_Itype)) then
10172 Set_Is_Frozen (New_Itype, False);
10173 Set_Freeze_Node (New_Itype, Empty);
10176 -- Add new association to map
10178 if No (Actual_Map) then
10179 Actual_Map := New_Elmt_List;
10182 Append_Elmt (Old_Itype, Actual_Map);
10183 Append_Elmt (New_Itype, Actual_Map);
10185 if NCT_Hash_Tables_Used then
10186 NCT_Assoc.Set (Old_Itype, New_Itype);
10189 NCT_Table_Entries := NCT_Table_Entries + 1;
10191 if NCT_Table_Entries > NCT_Hash_Threshold then
10192 Build_NCT_Hash_Tables;
10196 -- If a record subtype is simply copied, the entity list will be
10197 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
10199 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
10200 Set_Cloned_Subtype (New_Itype, Old_Itype);
10203 -- Visit descendents that eventually get copied
10205 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
10207 if Is_Discrete_Type (Old_Itype) then
10208 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
10210 elsif Has_Discriminants (Base_Type (Old_Itype)) then
10211 -- ??? This should involve call to Visit_Field
10212 Visit_Elist (Discriminant_Constraint (Old_Itype));
10214 elsif Is_Array_Type (Old_Itype) then
10215 if Present (First_Index (Old_Itype)) then
10216 Visit_Field (Union_Id (List_Containing
10217 (First_Index (Old_Itype))),
10221 if Is_Packed (Old_Itype) then
10222 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
10232 procedure Visit_List (L : List_Id) is
10235 if L /= No_List then
10238 while Present (N) loop
10249 procedure Visit_Node (N : Node_Or_Entity_Id) is
10251 -- Start of processing for Visit_Node
10254 -- Handle case of an Itype, which must be copied
10256 if Has_Extension (N)
10257 and then Is_Itype (N)
10259 -- Nothing to do if already in the list. This can happen with an
10260 -- Itype entity that appears more than once in the tree.
10261 -- Note that we do not want to visit descendents in this case.
10263 -- Test for already in list when hash table is used
10265 if NCT_Hash_Tables_Used then
10266 if Present (NCT_Assoc.Get (Entity_Id (N))) then
10270 -- Test for already in list when hash table not used
10276 if Present (Actual_Map) then
10277 E := First_Elmt (Actual_Map);
10278 while Present (E) loop
10279 if Node (E) = N then
10282 E := Next_Elmt (Next_Elmt (E));
10292 -- Visit descendents
10294 Visit_Field (Field1 (N), N);
10295 Visit_Field (Field2 (N), N);
10296 Visit_Field (Field3 (N), N);
10297 Visit_Field (Field4 (N), N);
10298 Visit_Field (Field5 (N), N);
10301 -- Start of processing for New_Copy_Tree
10306 -- See if we should use hash table
10308 if No (Actual_Map) then
10309 NCT_Hash_Tables_Used := False;
10316 NCT_Table_Entries := 0;
10318 Elmt := First_Elmt (Actual_Map);
10319 while Present (Elmt) loop
10320 NCT_Table_Entries := NCT_Table_Entries + 1;
10325 if NCT_Table_Entries > NCT_Hash_Threshold then
10326 Build_NCT_Hash_Tables;
10328 NCT_Hash_Tables_Used := False;
10333 -- Hash table set up if required, now start phase one by visiting
10334 -- top node (we will recursively visit the descendents).
10336 Visit_Node (Source);
10338 -- Now the second phase of the copy can start. First we process
10339 -- all the mapped entities, copying their descendents.
10341 if Present (Actual_Map) then
10344 New_Itype : Entity_Id;
10346 Elmt := First_Elmt (Actual_Map);
10347 while Present (Elmt) loop
10349 New_Itype := Node (Elmt);
10350 Copy_Itype_With_Replacement (New_Itype);
10356 -- Now we can copy the actual tree
10358 return Copy_Node_With_Replacement (Source);
10361 -------------------------
10362 -- New_External_Entity --
10363 -------------------------
10365 function New_External_Entity
10366 (Kind : Entity_Kind;
10367 Scope_Id : Entity_Id;
10368 Sloc_Value : Source_Ptr;
10369 Related_Id : Entity_Id;
10370 Suffix : Character;
10371 Suffix_Index : Nat := 0;
10372 Prefix : Character := ' ') return Entity_Id
10374 N : constant Entity_Id :=
10375 Make_Defining_Identifier (Sloc_Value,
10377 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
10380 Set_Ekind (N, Kind);
10381 Set_Is_Internal (N, True);
10382 Append_Entity (N, Scope_Id);
10383 Set_Public_Status (N);
10385 if Kind in Type_Kind then
10386 Init_Size_Align (N);
10390 end New_External_Entity;
10392 -------------------------
10393 -- New_Internal_Entity --
10394 -------------------------
10396 function New_Internal_Entity
10397 (Kind : Entity_Kind;
10398 Scope_Id : Entity_Id;
10399 Sloc_Value : Source_Ptr;
10400 Id_Char : Character) return Entity_Id
10402 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
10405 Set_Ekind (N, Kind);
10406 Set_Is_Internal (N, True);
10407 Append_Entity (N, Scope_Id);
10409 if Kind in Type_Kind then
10410 Init_Size_Align (N);
10414 end New_Internal_Entity;
10420 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
10424 -- If we are pointing at a positional parameter, it is a member of a
10425 -- node list (the list of parameters), and the next parameter is the
10426 -- next node on the list, unless we hit a parameter association, then
10427 -- we shift to using the chain whose head is the First_Named_Actual in
10428 -- the parent, and then is threaded using the Next_Named_Actual of the
10429 -- Parameter_Association. All this fiddling is because the original node
10430 -- list is in the textual call order, and what we need is the
10431 -- declaration order.
10433 if Is_List_Member (Actual_Id) then
10434 N := Next (Actual_Id);
10436 if Nkind (N) = N_Parameter_Association then
10437 return First_Named_Actual (Parent (Actual_Id));
10443 return Next_Named_Actual (Parent (Actual_Id));
10447 procedure Next_Actual (Actual_Id : in out Node_Id) is
10449 Actual_Id := Next_Actual (Actual_Id);
10452 -----------------------
10453 -- Normalize_Actuals --
10454 -----------------------
10456 -- Chain actuals according to formals of subprogram. If there are no named
10457 -- associations, the chain is simply the list of Parameter Associations,
10458 -- since the order is the same as the declaration order. If there are named
10459 -- associations, then the First_Named_Actual field in the N_Function_Call
10460 -- or N_Procedure_Call_Statement node points to the Parameter_Association
10461 -- node for the parameter that comes first in declaration order. The
10462 -- remaining named parameters are then chained in declaration order using
10463 -- Next_Named_Actual.
10465 -- This routine also verifies that the number of actuals is compatible with
10466 -- the number and default values of formals, but performs no type checking
10467 -- (type checking is done by the caller).
10469 -- If the matching succeeds, Success is set to True and the caller proceeds
10470 -- with type-checking. If the match is unsuccessful, then Success is set to
10471 -- False, and the caller attempts a different interpretation, if there is
10474 -- If the flag Report is on, the call is not overloaded, and a failure to
10475 -- match can be reported here, rather than in the caller.
10477 procedure Normalize_Actuals
10481 Success : out Boolean)
10483 Actuals : constant List_Id := Parameter_Associations (N);
10484 Actual : Node_Id := Empty;
10485 Formal : Entity_Id;
10486 Last : Node_Id := Empty;
10487 First_Named : Node_Id := Empty;
10490 Formals_To_Match : Integer := 0;
10491 Actuals_To_Match : Integer := 0;
10493 procedure Chain (A : Node_Id);
10494 -- Add named actual at the proper place in the list, using the
10495 -- Next_Named_Actual link.
10497 function Reporting return Boolean;
10498 -- Determines if an error is to be reported. To report an error, we
10499 -- need Report to be True, and also we do not report errors caused
10500 -- by calls to init procs that occur within other init procs. Such
10501 -- errors must always be cascaded errors, since if all the types are
10502 -- declared correctly, the compiler will certainly build decent calls!
10508 procedure Chain (A : Node_Id) is
10512 -- Call node points to first actual in list
10514 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10517 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10521 Set_Next_Named_Actual (Last, Empty);
10528 function Reporting return Boolean is
10533 elsif not Within_Init_Proc then
10536 elsif Is_Init_Proc (Entity (Name (N))) then
10544 -- Start of processing for Normalize_Actuals
10547 if Is_Access_Type (S) then
10549 -- The name in the call is a function call that returns an access
10550 -- to subprogram. The designated type has the list of formals.
10552 Formal := First_Formal (Designated_Type (S));
10554 Formal := First_Formal (S);
10557 while Present (Formal) loop
10558 Formals_To_Match := Formals_To_Match + 1;
10559 Next_Formal (Formal);
10562 -- Find if there is a named association, and verify that no positional
10563 -- associations appear after named ones.
10565 if Present (Actuals) then
10566 Actual := First (Actuals);
10569 while Present (Actual)
10570 and then Nkind (Actual) /= N_Parameter_Association
10572 Actuals_To_Match := Actuals_To_Match + 1;
10576 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10578 -- Most common case: positional notation, no defaults
10583 elsif Actuals_To_Match > Formals_To_Match then
10585 -- Too many actuals: will not work
10588 if Is_Entity_Name (Name (N)) then
10589 Error_Msg_N ("too many arguments in call to&", Name (N));
10591 Error_Msg_N ("too many arguments in call", N);
10599 First_Named := Actual;
10601 while Present (Actual) loop
10602 if Nkind (Actual) /= N_Parameter_Association then
10604 ("positional parameters not allowed after named ones", Actual);
10609 Actuals_To_Match := Actuals_To_Match + 1;
10615 if Present (Actuals) then
10616 Actual := First (Actuals);
10619 Formal := First_Formal (S);
10620 while Present (Formal) loop
10622 -- Match the formals in order. If the corresponding actual is
10623 -- positional, nothing to do. Else scan the list of named actuals
10624 -- to find the one with the right name.
10626 if Present (Actual)
10627 and then Nkind (Actual) /= N_Parameter_Association
10630 Actuals_To_Match := Actuals_To_Match - 1;
10631 Formals_To_Match := Formals_To_Match - 1;
10634 -- For named parameters, search the list of actuals to find
10635 -- one that matches the next formal name.
10637 Actual := First_Named;
10639 while Present (Actual) loop
10640 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10643 Actuals_To_Match := Actuals_To_Match - 1;
10644 Formals_To_Match := Formals_To_Match - 1;
10652 if Ekind (Formal) /= E_In_Parameter
10653 or else No (Default_Value (Formal))
10656 if (Comes_From_Source (S)
10657 or else Sloc (S) = Standard_Location)
10658 and then Is_Overloadable (S)
10662 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10664 (Nkind (Parent (N)) = N_Function_Call
10666 Nkind (Parent (N)) = N_Parameter_Association))
10667 and then Ekind (S) /= E_Function
10669 Set_Etype (N, Etype (S));
10671 Error_Msg_Name_1 := Chars (S);
10672 Error_Msg_Sloc := Sloc (S);
10674 ("missing argument for parameter & " &
10675 "in call to % declared #", N, Formal);
10678 elsif Is_Overloadable (S) then
10679 Error_Msg_Name_1 := Chars (S);
10681 -- Point to type derivation that generated the
10684 Error_Msg_Sloc := Sloc (Parent (S));
10687 ("missing argument for parameter & " &
10688 "in call to % (inherited) #", N, Formal);
10692 ("missing argument for parameter &", N, Formal);
10700 Formals_To_Match := Formals_To_Match - 1;
10705 Next_Formal (Formal);
10708 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10715 -- Find some superfluous named actual that did not get
10716 -- attached to the list of associations.
10718 Actual := First (Actuals);
10719 while Present (Actual) loop
10720 if Nkind (Actual) = N_Parameter_Association
10721 and then Actual /= Last
10722 and then No (Next_Named_Actual (Actual))
10724 Error_Msg_N ("unmatched actual & in call",
10725 Selector_Name (Actual));
10736 end Normalize_Actuals;
10738 --------------------------------
10739 -- Note_Possible_Modification --
10740 --------------------------------
10742 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10743 Modification_Comes_From_Source : constant Boolean :=
10744 Comes_From_Source (Parent (N));
10750 -- Loop to find referenced entity, if there is one
10757 if Is_Entity_Name (Exp) then
10758 Ent := Entity (Exp);
10760 -- If the entity is missing, it is an undeclared identifier,
10761 -- and there is nothing to annotate.
10767 elsif Nkind (Exp) = N_Explicit_Dereference then
10769 P : constant Node_Id := Prefix (Exp);
10772 -- In formal verification mode, keep track of all reads and
10773 -- writes through explicit dereferences.
10776 Alfa.Generate_Dereference (N, 'm');
10779 if Nkind (P) = N_Selected_Component
10781 Entry_Formal (Entity (Selector_Name (P))))
10783 -- Case of a reference to an entry formal
10785 Ent := Entry_Formal (Entity (Selector_Name (P)));
10787 elsif Nkind (P) = N_Identifier
10788 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10789 and then Present (Expression (Parent (Entity (P))))
10790 and then Nkind (Expression (Parent (Entity (P))))
10793 -- Case of a reference to a value on which side effects have
10796 Exp := Prefix (Expression (Parent (Entity (P))));
10805 elsif Nkind (Exp) = N_Type_Conversion
10806 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10808 Exp := Expression (Exp);
10811 elsif Nkind (Exp) = N_Slice
10812 or else Nkind (Exp) = N_Indexed_Component
10813 or else Nkind (Exp) = N_Selected_Component
10815 Exp := Prefix (Exp);
10822 -- Now look for entity being referenced
10824 if Present (Ent) then
10825 if Is_Object (Ent) then
10826 if Comes_From_Source (Exp)
10827 or else Modification_Comes_From_Source
10829 -- Give warning if pragma unmodified given and we are
10830 -- sure this is a modification.
10832 if Has_Pragma_Unmodified (Ent) and then Sure then
10833 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10836 Set_Never_Set_In_Source (Ent, False);
10839 Set_Is_True_Constant (Ent, False);
10840 Set_Current_Value (Ent, Empty);
10841 Set_Is_Known_Null (Ent, False);
10843 if not Can_Never_Be_Null (Ent) then
10844 Set_Is_Known_Non_Null (Ent, False);
10847 -- Follow renaming chain
10849 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10850 and then Present (Renamed_Object (Ent))
10852 Exp := Renamed_Object (Ent);
10855 -- The expression may be the renaming of a subcomponent of an
10856 -- array or container. The assignment to the subcomponent is
10857 -- a modification of the container.
10859 elsif Comes_From_Source (Original_Node (Exp))
10860 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
10861 N_Indexed_Component)
10863 Exp := Prefix (Original_Node (Exp));
10867 -- Generate a reference only if the assignment comes from
10868 -- source. This excludes, for example, calls to a dispatching
10869 -- assignment operation when the left-hand side is tagged.
10871 if Modification_Comes_From_Source or else Alfa_Mode then
10872 Generate_Reference (Ent, Exp, 'm');
10874 -- If the target of the assignment is the bound variable
10875 -- in an iterator, indicate that the corresponding array
10876 -- or container is also modified.
10878 if Ada_Version >= Ada_2012
10880 Nkind (Parent (Ent)) = N_Iterator_Specification
10883 Domain : constant Node_Id := Name (Parent (Ent));
10886 -- TBD : in the full version of the construct, the
10887 -- domain of iteration can be given by an expression.
10889 if Is_Entity_Name (Domain) then
10890 Generate_Reference (Entity (Domain), Exp, 'm');
10891 Set_Is_True_Constant (Entity (Domain), False);
10892 Set_Never_Set_In_Source (Entity (Domain), False);
10898 Check_Nested_Access (Ent);
10903 -- If we are sure this is a modification from source, and we know
10904 -- this modifies a constant, then give an appropriate warning.
10906 if Overlays_Constant (Ent)
10907 and then Modification_Comes_From_Source
10911 A : constant Node_Id := Address_Clause (Ent);
10913 if Present (A) then
10915 Exp : constant Node_Id := Expression (A);
10917 if Nkind (Exp) = N_Attribute_Reference
10918 and then Attribute_Name (Exp) = Name_Address
10919 and then Is_Entity_Name (Prefix (Exp))
10921 Error_Msg_Sloc := Sloc (A);
10923 ("constant& may be modified via address clause#?",
10924 N, Entity (Prefix (Exp)));
10934 end Note_Possible_Modification;
10936 -------------------------
10937 -- Object_Access_Level --
10938 -------------------------
10940 function Object_Access_Level (Obj : Node_Id) return Uint is
10943 -- Returns the static accessibility level of the view denoted by Obj. Note
10944 -- that the value returned is the result of a call to Scope_Depth. Only
10945 -- scope depths associated with dynamic scopes can actually be returned.
10946 -- Since only relative levels matter for accessibility checking, the fact
10947 -- that the distance between successive levels of accessibility is not
10948 -- always one is immaterial (invariant: if level(E2) is deeper than
10949 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10951 function Reference_To (Obj : Node_Id) return Node_Id;
10952 -- An explicit dereference is created when removing side-effects from
10953 -- expressions for constraint checking purposes. In this case a local
10954 -- access type is created for it. The correct access level is that of
10955 -- the original source node. We detect this case by noting that the
10956 -- prefix of the dereference is created by an object declaration whose
10957 -- initial expression is a reference.
10963 function Reference_To (Obj : Node_Id) return Node_Id is
10964 Pref : constant Node_Id := Prefix (Obj);
10966 if Is_Entity_Name (Pref)
10967 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10968 and then Present (Expression (Parent (Entity (Pref))))
10969 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10971 return (Prefix (Expression (Parent (Entity (Pref)))));
10977 -- Start of processing for Object_Access_Level
10980 if Nkind (Obj) = N_Defining_Identifier
10981 or else Is_Entity_Name (Obj)
10983 if Nkind (Obj) = N_Defining_Identifier then
10989 if Is_Prival (E) then
10990 E := Prival_Link (E);
10993 -- If E is a type then it denotes a current instance. For this case
10994 -- we add one to the normal accessibility level of the type to ensure
10995 -- that current instances are treated as always being deeper than
10996 -- than the level of any visible named access type (see 3.10.2(21)).
10998 if Is_Type (E) then
10999 return Type_Access_Level (E) + 1;
11001 elsif Present (Renamed_Object (E)) then
11002 return Object_Access_Level (Renamed_Object (E));
11004 -- Similarly, if E is a component of the current instance of a
11005 -- protected type, any instance of it is assumed to be at a deeper
11006 -- level than the type. For a protected object (whose type is an
11007 -- anonymous protected type) its components are at the same level
11008 -- as the type itself.
11010 elsif not Is_Overloadable (E)
11011 and then Ekind (Scope (E)) = E_Protected_Type
11012 and then Comes_From_Source (Scope (E))
11014 return Type_Access_Level (Scope (E)) + 1;
11017 return Scope_Depth (Enclosing_Dynamic_Scope (E));
11020 elsif Nkind (Obj) = N_Selected_Component then
11021 if Is_Access_Type (Etype (Prefix (Obj))) then
11022 return Type_Access_Level (Etype (Prefix (Obj)));
11024 return Object_Access_Level (Prefix (Obj));
11027 elsif Nkind (Obj) = N_Indexed_Component then
11028 if Is_Access_Type (Etype (Prefix (Obj))) then
11029 return Type_Access_Level (Etype (Prefix (Obj)));
11031 return Object_Access_Level (Prefix (Obj));
11034 elsif Nkind (Obj) = N_Explicit_Dereference then
11036 -- If the prefix is a selected access discriminant then we make a
11037 -- recursive call on the prefix, which will in turn check the level
11038 -- of the prefix object of the selected discriminant.
11040 if Nkind (Prefix (Obj)) = N_Selected_Component
11041 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
11043 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
11045 return Object_Access_Level (Prefix (Obj));
11047 elsif not (Comes_From_Source (Obj)) then
11049 Ref : constant Node_Id := Reference_To (Obj);
11051 if Present (Ref) then
11052 return Object_Access_Level (Ref);
11054 return Type_Access_Level (Etype (Prefix (Obj)));
11059 return Type_Access_Level (Etype (Prefix (Obj)));
11062 elsif Nkind (Obj) = N_Type_Conversion
11063 or else Nkind (Obj) = N_Unchecked_Type_Conversion
11065 return Object_Access_Level (Expression (Obj));
11067 elsif Nkind (Obj) = N_Function_Call then
11069 -- Function results are objects, so we get either the access level of
11070 -- the function or, in the case of an indirect call, the level of the
11071 -- access-to-subprogram type. (This code is used for Ada 95, but it
11072 -- looks wrong, because it seems that we should be checking the level
11073 -- of the call itself, even for Ada 95. However, using the Ada 2005
11074 -- version of the code causes regressions in several tests that are
11075 -- compiled with -gnat95. ???)
11077 if Ada_Version < Ada_2005 then
11078 if Is_Entity_Name (Name (Obj)) then
11079 return Subprogram_Access_Level (Entity (Name (Obj)));
11081 return Type_Access_Level (Etype (Prefix (Name (Obj))));
11084 -- For Ada 2005, the level of the result object of a function call is
11085 -- defined to be the level of the call's innermost enclosing master.
11086 -- We determine that by querying the depth of the innermost enclosing
11090 Return_Master_Scope_Depth_Of_Call : declare
11092 function Innermost_Master_Scope_Depth
11093 (N : Node_Id) return Uint;
11094 -- Returns the scope depth of the given node's innermost
11095 -- enclosing dynamic scope (effectively the accessibility
11096 -- level of the innermost enclosing master).
11098 ----------------------------------
11099 -- Innermost_Master_Scope_Depth --
11100 ----------------------------------
11102 function Innermost_Master_Scope_Depth
11103 (N : Node_Id) return Uint
11105 Node_Par : Node_Id := Parent (N);
11108 -- Locate the nearest enclosing node (by traversing Parents)
11109 -- that Defining_Entity can be applied to, and return the
11110 -- depth of that entity's nearest enclosing dynamic scope.
11112 while Present (Node_Par) loop
11113 case Nkind (Node_Par) is
11114 when N_Component_Declaration |
11115 N_Entry_Declaration |
11116 N_Formal_Object_Declaration |
11117 N_Formal_Type_Declaration |
11118 N_Full_Type_Declaration |
11119 N_Incomplete_Type_Declaration |
11120 N_Loop_Parameter_Specification |
11121 N_Object_Declaration |
11122 N_Protected_Type_Declaration |
11123 N_Private_Extension_Declaration |
11124 N_Private_Type_Declaration |
11125 N_Subtype_Declaration |
11126 N_Function_Specification |
11127 N_Procedure_Specification |
11128 N_Task_Type_Declaration |
11130 N_Generic_Instantiation |
11132 N_Implicit_Label_Declaration |
11133 N_Package_Declaration |
11134 N_Single_Task_Declaration |
11135 N_Subprogram_Declaration |
11136 N_Generic_Declaration |
11137 N_Renaming_Declaration |
11138 N_Block_Statement |
11139 N_Formal_Subprogram_Declaration |
11140 N_Abstract_Subprogram_Declaration |
11142 N_Exception_Declaration |
11143 N_Formal_Package_Declaration |
11144 N_Number_Declaration |
11145 N_Package_Specification |
11146 N_Parameter_Specification |
11147 N_Single_Protected_Declaration |
11151 (Nearest_Dynamic_Scope
11152 (Defining_Entity (Node_Par)));
11158 Node_Par := Parent (Node_Par);
11161 pragma Assert (False);
11163 -- Should never reach the following return
11165 return Scope_Depth (Current_Scope) + 1;
11166 end Innermost_Master_Scope_Depth;
11168 -- Start of processing for Return_Master_Scope_Depth_Of_Call
11171 return Innermost_Master_Scope_Depth (Obj);
11172 end Return_Master_Scope_Depth_Of_Call;
11175 -- For convenience we handle qualified expressions, even though
11176 -- they aren't technically object names.
11178 elsif Nkind (Obj) = N_Qualified_Expression then
11179 return Object_Access_Level (Expression (Obj));
11181 -- Otherwise return the scope level of Standard.
11182 -- (If there are cases that fall through
11183 -- to this point they will be treated as
11184 -- having global accessibility for now. ???)
11187 return Scope_Depth (Standard_Standard);
11189 end Object_Access_Level;
11191 --------------------------------------
11192 -- Original_Corresponding_Operation --
11193 --------------------------------------
11195 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
11197 Typ : constant Entity_Id := Find_Dispatching_Type (S);
11200 -- If S is an inherited primitive S2 the original corresponding
11201 -- operation of S is the original corresponding operation of S2
11203 if Present (Alias (S))
11204 and then Find_Dispatching_Type (Alias (S)) /= Typ
11206 return Original_Corresponding_Operation (Alias (S));
11208 -- If S overrides an inherited subprogram S2 the original corresponding
11209 -- operation of S is the original corresponding operation of S2
11211 elsif Present (Overridden_Operation (S)) then
11212 return Original_Corresponding_Operation (Overridden_Operation (S));
11214 -- otherwise it is S itself
11219 end Original_Corresponding_Operation;
11221 -----------------------
11222 -- Private_Component --
11223 -----------------------
11225 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
11226 Ancestor : constant Entity_Id := Base_Type (Type_Id);
11228 function Trace_Components
11230 Check : Boolean) return Entity_Id;
11231 -- Recursive function that does the work, and checks against circular
11232 -- definition for each subcomponent type.
11234 ----------------------
11235 -- Trace_Components --
11236 ----------------------
11238 function Trace_Components
11240 Check : Boolean) return Entity_Id
11242 Btype : constant Entity_Id := Base_Type (T);
11243 Component : Entity_Id;
11245 Candidate : Entity_Id := Empty;
11248 if Check and then Btype = Ancestor then
11249 Error_Msg_N ("circular type definition", Type_Id);
11253 if Is_Private_Type (Btype)
11254 and then not Is_Generic_Type (Btype)
11256 if Present (Full_View (Btype))
11257 and then Is_Record_Type (Full_View (Btype))
11258 and then not Is_Frozen (Btype)
11260 -- To indicate that the ancestor depends on a private type, the
11261 -- current Btype is sufficient. However, to check for circular
11262 -- definition we must recurse on the full view.
11264 Candidate := Trace_Components (Full_View (Btype), True);
11266 if Candidate = Any_Type then
11276 elsif Is_Array_Type (Btype) then
11277 return Trace_Components (Component_Type (Btype), True);
11279 elsif Is_Record_Type (Btype) then
11280 Component := First_Entity (Btype);
11281 while Present (Component)
11282 and then Comes_From_Source (Component)
11284 -- Skip anonymous types generated by constrained components
11286 if not Is_Type (Component) then
11287 P := Trace_Components (Etype (Component), True);
11289 if Present (P) then
11290 if P = Any_Type then
11298 Next_Entity (Component);
11306 end Trace_Components;
11308 -- Start of processing for Private_Component
11311 return Trace_Components (Type_Id, False);
11312 end Private_Component;
11314 ---------------------------
11315 -- Primitive_Names_Match --
11316 ---------------------------
11318 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
11320 function Non_Internal_Name (E : Entity_Id) return Name_Id;
11321 -- Given an internal name, returns the corresponding non-internal name
11323 ------------------------
11324 -- Non_Internal_Name --
11325 ------------------------
11327 function Non_Internal_Name (E : Entity_Id) return Name_Id is
11329 Get_Name_String (Chars (E));
11330 Name_Len := Name_Len - 1;
11332 end Non_Internal_Name;
11334 -- Start of processing for Primitive_Names_Match
11337 pragma Assert (Present (E1) and then Present (E2));
11339 return Chars (E1) = Chars (E2)
11341 (not Is_Internal_Name (Chars (E1))
11342 and then Is_Internal_Name (Chars (E2))
11343 and then Non_Internal_Name (E2) = Chars (E1))
11345 (not Is_Internal_Name (Chars (E2))
11346 and then Is_Internal_Name (Chars (E1))
11347 and then Non_Internal_Name (E1) = Chars (E2))
11349 (Is_Predefined_Dispatching_Operation (E1)
11350 and then Is_Predefined_Dispatching_Operation (E2)
11351 and then Same_TSS (E1, E2))
11353 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
11354 end Primitive_Names_Match;
11356 -----------------------
11357 -- Process_End_Label --
11358 -----------------------
11360 procedure Process_End_Label
11369 Label_Ref : Boolean;
11370 -- Set True if reference to end label itself is required
11373 -- Gets set to the operator symbol or identifier that references the
11374 -- entity Ent. For the child unit case, this is the identifier from the
11375 -- designator. For other cases, this is simply Endl.
11377 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
11378 -- N is an identifier node that appears as a parent unit reference in
11379 -- the case where Ent is a child unit. This procedure generates an
11380 -- appropriate cross-reference entry. E is the corresponding entity.
11382 -------------------------
11383 -- Generate_Parent_Ref --
11384 -------------------------
11386 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
11388 -- If names do not match, something weird, skip reference
11390 if Chars (E) = Chars (N) then
11392 -- Generate the reference. We do NOT consider this as a reference
11393 -- for unreferenced symbol purposes.
11395 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
11397 if Style_Check then
11398 Style.Check_Identifier (N, E);
11401 end Generate_Parent_Ref;
11403 -- Start of processing for Process_End_Label
11406 -- If no node, ignore. This happens in some error situations, and
11407 -- also for some internally generated structures where no end label
11408 -- references are required in any case.
11414 -- Nothing to do if no End_Label, happens for internally generated
11415 -- constructs where we don't want an end label reference anyway. Also
11416 -- nothing to do if Endl is a string literal, which means there was
11417 -- some prior error (bad operator symbol)
11419 Endl := End_Label (N);
11421 if No (Endl) or else Nkind (Endl) = N_String_Literal then
11425 -- Reference node is not in extended main source unit
11427 if not In_Extended_Main_Source_Unit (N) then
11429 -- Generally we do not collect references except for the extended
11430 -- main source unit. The one exception is the 'e' entry for a
11431 -- package spec, where it is useful for a client to have the
11432 -- ending information to define scopes.
11438 Label_Ref := False;
11440 -- For this case, we can ignore any parent references, but we
11441 -- need the package name itself for the 'e' entry.
11443 if Nkind (Endl) = N_Designator then
11444 Endl := Identifier (Endl);
11448 -- Reference is in extended main source unit
11453 -- For designator, generate references for the parent entries
11455 if Nkind (Endl) = N_Designator then
11457 -- Generate references for the prefix if the END line comes from
11458 -- source (otherwise we do not need these references) We climb the
11459 -- scope stack to find the expected entities.
11461 if Comes_From_Source (Endl) then
11462 Nam := Name (Endl);
11463 Scop := Current_Scope;
11464 while Nkind (Nam) = N_Selected_Component loop
11465 Scop := Scope (Scop);
11466 exit when No (Scop);
11467 Generate_Parent_Ref (Selector_Name (Nam), Scop);
11468 Nam := Prefix (Nam);
11471 if Present (Scop) then
11472 Generate_Parent_Ref (Nam, Scope (Scop));
11476 Endl := Identifier (Endl);
11480 -- If the end label is not for the given entity, then either we have
11481 -- some previous error, or this is a generic instantiation for which
11482 -- we do not need to make a cross-reference in this case anyway. In
11483 -- either case we simply ignore the call.
11485 if Chars (Ent) /= Chars (Endl) then
11489 -- If label was really there, then generate a normal reference and then
11490 -- adjust the location in the end label to point past the name (which
11491 -- should almost always be the semicolon).
11493 Loc := Sloc (Endl);
11495 if Comes_From_Source (Endl) then
11497 -- If a label reference is required, then do the style check and
11498 -- generate an l-type cross-reference entry for the label
11501 if Style_Check then
11502 Style.Check_Identifier (Endl, Ent);
11505 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
11508 -- Set the location to point past the label (normally this will
11509 -- mean the semicolon immediately following the label). This is
11510 -- done for the sake of the 'e' or 't' entry generated below.
11512 Get_Decoded_Name_String (Chars (Endl));
11513 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11516 -- In SPARK mode, no missing label is allowed for packages and
11517 -- subprogram bodies. Detect those cases by testing whether
11518 -- Process_End_Label was called for a body (Typ = 't') or a package.
11520 if Restriction_Check_Required (SPARK)
11521 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11523 Error_Msg_Node_1 := Endl;
11524 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11528 -- Now generate the e/t reference
11530 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11532 -- Restore Sloc, in case modified above, since we have an identifier
11533 -- and the normal Sloc should be left set in the tree.
11535 Set_Sloc (Endl, Loc);
11536 end Process_End_Label;
11538 ------------------------------------
11539 -- References_Generic_Formal_Type --
11540 ------------------------------------
11542 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11544 function Process (N : Node_Id) return Traverse_Result;
11545 -- Process one node in search for generic formal type
11551 function Process (N : Node_Id) return Traverse_Result is
11553 if Nkind (N) in N_Has_Entity then
11555 E : constant Entity_Id := Entity (N);
11557 if Present (E) then
11558 if Is_Generic_Type (E) then
11560 elsif Present (Etype (E))
11561 and then Is_Generic_Type (Etype (E))
11572 function Traverse is new Traverse_Func (Process);
11573 -- Traverse tree to look for generic type
11576 if Inside_A_Generic then
11577 return Traverse (N) = Abandon;
11581 end References_Generic_Formal_Type;
11583 --------------------
11584 -- Remove_Homonym --
11585 --------------------
11587 procedure Remove_Homonym (E : Entity_Id) is
11588 Prev : Entity_Id := Empty;
11592 if E = Current_Entity (E) then
11593 if Present (Homonym (E)) then
11594 Set_Current_Entity (Homonym (E));
11596 Set_Name_Entity_Id (Chars (E), Empty);
11599 H := Current_Entity (E);
11600 while Present (H) and then H /= E loop
11605 Set_Homonym (Prev, Homonym (E));
11607 end Remove_Homonym;
11609 ---------------------
11610 -- Rep_To_Pos_Flag --
11611 ---------------------
11613 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11615 return New_Occurrence_Of
11616 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11617 end Rep_To_Pos_Flag;
11619 --------------------
11620 -- Require_Entity --
11621 --------------------
11623 procedure Require_Entity (N : Node_Id) is
11625 if Is_Entity_Name (N) and then No (Entity (N)) then
11626 if Total_Errors_Detected /= 0 then
11627 Set_Entity (N, Any_Id);
11629 raise Program_Error;
11632 end Require_Entity;
11634 ------------------------------
11635 -- Requires_Transient_Scope --
11636 ------------------------------
11638 -- A transient scope is required when variable-sized temporaries are
11639 -- allocated in the primary or secondary stack, or when finalization
11640 -- actions must be generated before the next instruction.
11642 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11643 Typ : constant Entity_Id := Underlying_Type (Id);
11645 -- Start of processing for Requires_Transient_Scope
11648 -- This is a private type which is not completed yet. This can only
11649 -- happen in a default expression (of a formal parameter or of a
11650 -- record component). Do not expand transient scope in this case
11655 -- Do not expand transient scope for non-existent procedure return
11657 elsif Typ = Standard_Void_Type then
11660 -- Elementary types do not require a transient scope
11662 elsif Is_Elementary_Type (Typ) then
11665 -- Generally, indefinite subtypes require a transient scope, since the
11666 -- back end cannot generate temporaries, since this is not a valid type
11667 -- for declaring an object. It might be possible to relax this in the
11668 -- future, e.g. by declaring the maximum possible space for the type.
11670 elsif Is_Indefinite_Subtype (Typ) then
11673 -- Functions returning tagged types may dispatch on result so their
11674 -- returned value is allocated on the secondary stack. Controlled
11675 -- type temporaries need finalization.
11677 elsif Is_Tagged_Type (Typ)
11678 or else Has_Controlled_Component (Typ)
11680 return not Is_Value_Type (Typ);
11684 elsif Is_Record_Type (Typ) then
11688 Comp := First_Entity (Typ);
11689 while Present (Comp) loop
11690 if Ekind (Comp) = E_Component
11691 and then Requires_Transient_Scope (Etype (Comp))
11695 Next_Entity (Comp);
11702 -- String literal types never require transient scope
11704 elsif Ekind (Typ) = E_String_Literal_Subtype then
11707 -- Array type. Note that we already know that this is a constrained
11708 -- array, since unconstrained arrays will fail the indefinite test.
11710 elsif Is_Array_Type (Typ) then
11712 -- If component type requires a transient scope, the array does too
11714 if Requires_Transient_Scope (Component_Type (Typ)) then
11717 -- Otherwise, we only need a transient scope if the size depends on
11718 -- the value of one or more discriminants.
11721 return Size_Depends_On_Discriminant (Typ);
11724 -- All other cases do not require a transient scope
11729 end Requires_Transient_Scope;
11731 --------------------------
11732 -- Reset_Analyzed_Flags --
11733 --------------------------
11735 procedure Reset_Analyzed_Flags (N : Node_Id) is
11737 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11738 -- Function used to reset Analyzed flags in tree. Note that we do
11739 -- not reset Analyzed flags in entities, since there is no need to
11740 -- reanalyze entities, and indeed, it is wrong to do so, since it
11741 -- can result in generating auxiliary stuff more than once.
11743 --------------------
11744 -- Clear_Analyzed --
11745 --------------------
11747 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11749 if not Has_Extension (N) then
11750 Set_Analyzed (N, False);
11754 end Clear_Analyzed;
11756 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11758 -- Start of processing for Reset_Analyzed_Flags
11761 Reset_Analyzed (N);
11762 end Reset_Analyzed_Flags;
11764 ---------------------------
11765 -- Safe_To_Capture_Value --
11766 ---------------------------
11768 function Safe_To_Capture_Value
11771 Cond : Boolean := False) return Boolean
11774 -- The only entities for which we track constant values are variables
11775 -- which are not renamings, constants, out parameters, and in out
11776 -- parameters, so check if we have this case.
11778 -- Note: it may seem odd to track constant values for constants, but in
11779 -- fact this routine is used for other purposes than simply capturing
11780 -- the value. In particular, the setting of Known[_Non]_Null.
11782 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11784 Ekind (Ent) = E_Constant
11786 Ekind (Ent) = E_Out_Parameter
11788 Ekind (Ent) = E_In_Out_Parameter
11792 -- For conditionals, we also allow loop parameters and all formals,
11793 -- including in parameters.
11797 (Ekind (Ent) = E_Loop_Parameter
11799 Ekind (Ent) = E_In_Parameter)
11803 -- For all other cases, not just unsafe, but impossible to capture
11804 -- Current_Value, since the above are the only entities which have
11805 -- Current_Value fields.
11811 -- Skip if volatile or aliased, since funny things might be going on in
11812 -- these cases which we cannot necessarily track. Also skip any variable
11813 -- for which an address clause is given, or whose address is taken. Also
11814 -- never capture value of library level variables (an attempt to do so
11815 -- can occur in the case of package elaboration code).
11817 if Treat_As_Volatile (Ent)
11818 or else Is_Aliased (Ent)
11819 or else Present (Address_Clause (Ent))
11820 or else Address_Taken (Ent)
11821 or else (Is_Library_Level_Entity (Ent)
11822 and then Ekind (Ent) = E_Variable)
11827 -- OK, all above conditions are met. We also require that the scope of
11828 -- the reference be the same as the scope of the entity, not counting
11829 -- packages and blocks and loops.
11832 E_Scope : constant Entity_Id := Scope (Ent);
11833 R_Scope : Entity_Id;
11836 R_Scope := Current_Scope;
11837 while R_Scope /= Standard_Standard loop
11838 exit when R_Scope = E_Scope;
11840 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11843 R_Scope := Scope (R_Scope);
11848 -- We also require that the reference does not appear in a context
11849 -- where it is not sure to be executed (i.e. a conditional context
11850 -- or an exception handler). We skip this if Cond is True, since the
11851 -- capturing of values from conditional tests handles this ok.
11865 while Present (P) loop
11866 if Nkind (P) = N_If_Statement
11867 or else Nkind (P) = N_Case_Statement
11868 or else (Nkind (P) in N_Short_Circuit
11869 and then Desc = Right_Opnd (P))
11870 or else (Nkind (P) = N_Conditional_Expression
11871 and then Desc /= First (Expressions (P)))
11872 or else Nkind (P) = N_Exception_Handler
11873 or else Nkind (P) = N_Selective_Accept
11874 or else Nkind (P) = N_Conditional_Entry_Call
11875 or else Nkind (P) = N_Timed_Entry_Call
11876 or else Nkind (P) = N_Asynchronous_Select
11886 -- OK, looks safe to set value
11889 end Safe_To_Capture_Value;
11895 function Same_Name (N1, N2 : Node_Id) return Boolean is
11896 K1 : constant Node_Kind := Nkind (N1);
11897 K2 : constant Node_Kind := Nkind (N2);
11900 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11901 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11903 return Chars (N1) = Chars (N2);
11905 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11906 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11908 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11909 and then Same_Name (Prefix (N1), Prefix (N2));
11920 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11921 N1 : constant Node_Id := Original_Node (Node1);
11922 N2 : constant Node_Id := Original_Node (Node2);
11923 -- We do the tests on original nodes, since we are most interested
11924 -- in the original source, not any expansion that got in the way.
11926 K1 : constant Node_Kind := Nkind (N1);
11927 K2 : constant Node_Kind := Nkind (N2);
11930 -- First case, both are entities with same entity
11932 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11934 EN1 : constant Entity_Id := Entity (N1);
11935 EN2 : constant Entity_Id := Entity (N2);
11937 if Present (EN1) and then Present (EN2)
11938 and then (Ekind_In (EN1, E_Variable, E_Constant)
11939 or else Is_Formal (EN1))
11947 -- Second case, selected component with same selector, same record
11949 if K1 = N_Selected_Component
11950 and then K2 = N_Selected_Component
11951 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11953 return Same_Object (Prefix (N1), Prefix (N2));
11955 -- Third case, indexed component with same subscripts, same array
11957 elsif K1 = N_Indexed_Component
11958 and then K2 = N_Indexed_Component
11959 and then Same_Object (Prefix (N1), Prefix (N2))
11964 E1 := First (Expressions (N1));
11965 E2 := First (Expressions (N2));
11966 while Present (E1) loop
11967 if not Same_Value (E1, E2) then
11978 -- Fourth case, slice of same array with same bounds
11981 and then K2 = N_Slice
11982 and then Nkind (Discrete_Range (N1)) = N_Range
11983 and then Nkind (Discrete_Range (N2)) = N_Range
11984 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11985 Low_Bound (Discrete_Range (N2)))
11986 and then Same_Value (High_Bound (Discrete_Range (N1)),
11987 High_Bound (Discrete_Range (N2)))
11989 return Same_Name (Prefix (N1), Prefix (N2));
11991 -- All other cases, not clearly the same object
12002 function Same_Type (T1, T2 : Entity_Id) return Boolean is
12007 elsif not Is_Constrained (T1)
12008 and then not Is_Constrained (T2)
12009 and then Base_Type (T1) = Base_Type (T2)
12013 -- For now don't bother with case of identical constraints, to be
12014 -- fiddled with later on perhaps (this is only used for optimization
12015 -- purposes, so it is not critical to do a best possible job)
12026 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
12028 if Compile_Time_Known_Value (Node1)
12029 and then Compile_Time_Known_Value (Node2)
12030 and then Expr_Value (Node1) = Expr_Value (Node2)
12033 elsif Same_Object (Node1, Node2) then
12044 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
12046 if Ada_Version < Ada_2012 then
12049 elsif Is_Entity_Name (N)
12051 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
12053 (Nkind (N) = N_Attribute_Reference
12054 and then Attribute_Name (N) = Name_Access)
12057 -- We are only interested in IN OUT parameters of inner calls
12060 or else Nkind (Parent (N)) = N_Function_Call
12061 or else Nkind (Parent (N)) in N_Op
12063 Actuals_In_Call.Increment_Last;
12064 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
12069 ------------------------
12070 -- Scope_Is_Transient --
12071 ------------------------
12073 function Scope_Is_Transient return Boolean is
12075 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
12076 end Scope_Is_Transient;
12082 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
12087 while Scop /= Standard_Standard loop
12088 Scop := Scope (Scop);
12090 if Scop = Scope2 then
12098 --------------------------
12099 -- Scope_Within_Or_Same --
12100 --------------------------
12102 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
12107 while Scop /= Standard_Standard loop
12108 if Scop = Scope2 then
12111 Scop := Scope (Scop);
12116 end Scope_Within_Or_Same;
12118 --------------------
12119 -- Set_Convention --
12120 --------------------
12122 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
12124 Basic_Set_Convention (E, Val);
12127 and then Is_Access_Subprogram_Type (Base_Type (E))
12128 and then Has_Foreign_Convention (E)
12130 Set_Can_Use_Internal_Rep (E, False);
12132 end Set_Convention;
12134 ------------------------
12135 -- Set_Current_Entity --
12136 ------------------------
12138 -- The given entity is to be set as the currently visible definition of its
12139 -- associated name (i.e. the Node_Id associated with its name). All we have
12140 -- to do is to get the name from the identifier, and then set the
12141 -- associated Node_Id to point to the given entity.
12143 procedure Set_Current_Entity (E : Entity_Id) is
12145 Set_Name_Entity_Id (Chars (E), E);
12146 end Set_Current_Entity;
12148 ---------------------------
12149 -- Set_Debug_Info_Needed --
12150 ---------------------------
12152 procedure Set_Debug_Info_Needed (T : Entity_Id) is
12154 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
12155 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
12156 -- Used to set debug info in a related node if not set already
12158 --------------------------------------
12159 -- Set_Debug_Info_Needed_If_Not_Set --
12160 --------------------------------------
12162 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
12165 and then not Needs_Debug_Info (E)
12167 Set_Debug_Info_Needed (E);
12169 -- For a private type, indicate that the full view also needs
12170 -- debug information.
12173 and then Is_Private_Type (E)
12174 and then Present (Full_View (E))
12176 Set_Debug_Info_Needed (Full_View (E));
12179 end Set_Debug_Info_Needed_If_Not_Set;
12181 -- Start of processing for Set_Debug_Info_Needed
12184 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
12185 -- indicates that Debug_Info_Needed is never required for the entity.
12188 or else Debug_Info_Off (T)
12193 -- Set flag in entity itself. Note that we will go through the following
12194 -- circuitry even if the flag is already set on T. That's intentional,
12195 -- it makes sure that the flag will be set in subsidiary entities.
12197 Set_Needs_Debug_Info (T);
12199 -- Set flag on subsidiary entities if not set already
12201 if Is_Object (T) then
12202 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12204 elsif Is_Type (T) then
12205 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12207 if Is_Record_Type (T) then
12209 Ent : Entity_Id := First_Entity (T);
12211 while Present (Ent) loop
12212 Set_Debug_Info_Needed_If_Not_Set (Ent);
12217 -- For a class wide subtype, we also need debug information
12218 -- for the equivalent type.
12220 if Ekind (T) = E_Class_Wide_Subtype then
12221 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
12224 elsif Is_Array_Type (T) then
12225 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
12228 Indx : Node_Id := First_Index (T);
12230 while Present (Indx) loop
12231 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
12232 Indx := Next_Index (Indx);
12236 -- For a packed array type, we also need debug information for
12237 -- the type used to represent the packed array. Conversely, we
12238 -- also need it for the former if we need it for the latter.
12240 if Is_Packed (T) then
12241 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
12244 if Is_Packed_Array_Type (T) then
12245 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
12248 elsif Is_Access_Type (T) then
12249 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
12251 elsif Is_Private_Type (T) then
12252 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
12254 elsif Is_Protected_Type (T) then
12255 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
12258 end Set_Debug_Info_Needed;
12260 ---------------------------------
12261 -- Set_Entity_With_Style_Check --
12262 ---------------------------------
12264 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
12265 Val_Actual : Entity_Id;
12269 -- Unconditionally set the entity
12271 Set_Entity (N, Val);
12273 -- Check for No_Implementation_Identifiers
12275 if Restriction_Check_Required (No_Implementation_Identifiers) then
12277 -- We have an implementation defined entity if it is marked as
12278 -- implementation defined, or is defined in a package marked as
12279 -- implementation defined. However, library packages themselves
12280 -- are excluded (we don't want to flag Interfaces itself, just
12281 -- the entities within it).
12283 if (Is_Implementation_Defined (Val)
12284 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
12285 and then Is_Library_Level_Entity (Val)))
12286 or else Is_Implementation_Defined (Scope (Val))
12288 Check_Restriction (No_Implementation_Identifiers, N);
12292 -- Do the style check
12295 and then not Suppress_Style_Checks (Val)
12296 and then not In_Instance
12298 if Nkind (N) = N_Identifier then
12300 elsif Nkind (N) = N_Expanded_Name then
12301 Nod := Selector_Name (N);
12306 -- A special situation arises for derived operations, where we want
12307 -- to do the check against the parent (since the Sloc of the derived
12308 -- operation points to the derived type declaration itself).
12311 while not Comes_From_Source (Val_Actual)
12312 and then Nkind (Val_Actual) in N_Entity
12313 and then (Ekind (Val_Actual) = E_Enumeration_Literal
12314 or else Is_Subprogram (Val_Actual)
12315 or else Is_Generic_Subprogram (Val_Actual))
12316 and then Present (Alias (Val_Actual))
12318 Val_Actual := Alias (Val_Actual);
12321 -- Renaming declarations for generic actuals do not come from source,
12322 -- and have a different name from that of the entity they rename, so
12323 -- there is no style check to perform here.
12325 if Chars (Nod) = Chars (Val_Actual) then
12326 Style.Check_Identifier (Nod, Val_Actual);
12330 Set_Entity (N, Val);
12331 end Set_Entity_With_Style_Check;
12333 ------------------------
12334 -- Set_Name_Entity_Id --
12335 ------------------------
12337 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
12339 Set_Name_Table_Info (Id, Int (Val));
12340 end Set_Name_Entity_Id;
12342 ---------------------
12343 -- Set_Next_Actual --
12344 ---------------------
12346 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
12348 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
12349 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
12351 end Set_Next_Actual;
12353 ----------------------------------
12354 -- Set_Optimize_Alignment_Flags --
12355 ----------------------------------
12357 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
12359 if Optimize_Alignment = 'S' then
12360 Set_Optimize_Alignment_Space (E);
12361 elsif Optimize_Alignment = 'T' then
12362 Set_Optimize_Alignment_Time (E);
12364 end Set_Optimize_Alignment_Flags;
12366 -----------------------
12367 -- Set_Public_Status --
12368 -----------------------
12370 procedure Set_Public_Status (Id : Entity_Id) is
12371 S : constant Entity_Id := Current_Scope;
12373 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
12374 -- Determines if E is defined within handled statement sequence or
12375 -- an if statement, returns True if so, False otherwise.
12377 ----------------------
12378 -- Within_HSS_Or_If --
12379 ----------------------
12381 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
12384 N := Declaration_Node (E);
12391 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
12397 end Within_HSS_Or_If;
12399 -- Start of processing for Set_Public_Status
12402 -- Everything in the scope of Standard is public
12404 if S = Standard_Standard then
12405 Set_Is_Public (Id);
12407 -- Entity is definitely not public if enclosing scope is not public
12409 elsif not Is_Public (S) then
12412 -- An object or function declaration that occurs in a handled sequence
12413 -- of statements or within an if statement is the declaration for a
12414 -- temporary object or local subprogram generated by the expander. It
12415 -- never needs to be made public and furthermore, making it public can
12416 -- cause back end problems.
12418 elsif Nkind_In (Parent (Id), N_Object_Declaration,
12419 N_Function_Specification)
12420 and then Within_HSS_Or_If (Id)
12424 -- Entities in public packages or records are public
12426 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
12427 Set_Is_Public (Id);
12429 -- The bounds of an entry family declaration can generate object
12430 -- declarations that are visible to the back-end, e.g. in the
12431 -- the declaration of a composite type that contains tasks.
12433 elsif Is_Concurrent_Type (S)
12434 and then not Has_Completion (S)
12435 and then Nkind (Parent (Id)) = N_Object_Declaration
12437 Set_Is_Public (Id);
12439 end Set_Public_Status;
12441 -----------------------------
12442 -- Set_Referenced_Modified --
12443 -----------------------------
12445 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
12449 -- Deal with indexed or selected component where prefix is modified
12451 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
12452 Pref := Prefix (N);
12454 -- If prefix is access type, then it is the designated object that is
12455 -- being modified, which means we have no entity to set the flag on.
12457 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
12460 -- Otherwise chase the prefix
12463 Set_Referenced_Modified (Pref, Out_Param);
12466 -- Otherwise see if we have an entity name (only other case to process)
12468 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
12469 Set_Referenced_As_LHS (Entity (N), not Out_Param);
12470 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
12472 end Set_Referenced_Modified;
12474 ----------------------------
12475 -- Set_Scope_Is_Transient --
12476 ----------------------------
12478 procedure Set_Scope_Is_Transient (V : Boolean := True) is
12480 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
12481 end Set_Scope_Is_Transient;
12483 -------------------
12484 -- Set_Size_Info --
12485 -------------------
12487 procedure Set_Size_Info (T1, T2 : Entity_Id) is
12489 -- We copy Esize, but not RM_Size, since in general RM_Size is
12490 -- subtype specific and does not get inherited by all subtypes.
12492 Set_Esize (T1, Esize (T2));
12493 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
12495 if Is_Discrete_Or_Fixed_Point_Type (T1)
12497 Is_Discrete_Or_Fixed_Point_Type (T2)
12499 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
12502 Set_Alignment (T1, Alignment (T2));
12505 --------------------
12506 -- Static_Boolean --
12507 --------------------
12509 function Static_Boolean (N : Node_Id) return Uint is
12511 Analyze_And_Resolve (N, Standard_Boolean);
12514 or else Error_Posted (N)
12515 or else Etype (N) = Any_Type
12520 if Is_Static_Expression (N) then
12521 if not Raises_Constraint_Error (N) then
12522 return Expr_Value (N);
12527 elsif Etype (N) = Any_Type then
12531 Flag_Non_Static_Expr
12532 ("static boolean expression required here", N);
12535 end Static_Boolean;
12537 --------------------
12538 -- Static_Integer --
12539 --------------------
12541 function Static_Integer (N : Node_Id) return Uint is
12543 Analyze_And_Resolve (N, Any_Integer);
12546 or else Error_Posted (N)
12547 or else Etype (N) = Any_Type
12552 if Is_Static_Expression (N) then
12553 if not Raises_Constraint_Error (N) then
12554 return Expr_Value (N);
12559 elsif Etype (N) = Any_Type then
12563 Flag_Non_Static_Expr
12564 ("static integer expression required here", N);
12567 end Static_Integer;
12569 --------------------------
12570 -- Statically_Different --
12571 --------------------------
12573 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12574 R1 : constant Node_Id := Get_Referenced_Object (E1);
12575 R2 : constant Node_Id := Get_Referenced_Object (E2);
12577 return Is_Entity_Name (R1)
12578 and then Is_Entity_Name (R2)
12579 and then Entity (R1) /= Entity (R2)
12580 and then not Is_Formal (Entity (R1))
12581 and then not Is_Formal (Entity (R2));
12582 end Statically_Different;
12584 -----------------------------
12585 -- Subprogram_Access_Level --
12586 -----------------------------
12588 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12590 if Present (Alias (Subp)) then
12591 return Subprogram_Access_Level (Alias (Subp));
12593 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12595 end Subprogram_Access_Level;
12601 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12603 if Debug_Flag_W then
12604 for J in 0 .. Scope_Stack.Last loop
12609 Write_Name (Chars (E));
12610 Write_Str (" from ");
12611 Write_Location (Sloc (N));
12616 -----------------------
12617 -- Transfer_Entities --
12618 -----------------------
12620 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12621 Ent : Entity_Id := First_Entity (From);
12628 if (Last_Entity (To)) = Empty then
12629 Set_First_Entity (To, Ent);
12631 Set_Next_Entity (Last_Entity (To), Ent);
12634 Set_Last_Entity (To, Last_Entity (From));
12636 while Present (Ent) loop
12637 Set_Scope (Ent, To);
12639 if not Is_Public (Ent) then
12640 Set_Public_Status (Ent);
12643 and then Ekind (Ent) = E_Record_Subtype
12646 -- The components of the propagated Itype must be public
12652 Comp := First_Entity (Ent);
12653 while Present (Comp) loop
12654 Set_Is_Public (Comp);
12655 Next_Entity (Comp);
12664 Set_First_Entity (From, Empty);
12665 Set_Last_Entity (From, Empty);
12666 end Transfer_Entities;
12668 -----------------------
12669 -- Type_Access_Level --
12670 -----------------------
12672 function Type_Access_Level (Typ : Entity_Id) return Uint is
12676 Btyp := Base_Type (Typ);
12678 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12679 -- simply use the level where the type is declared. This is true for
12680 -- stand-alone object declarations, and for anonymous access types
12681 -- associated with components the level is the same as that of the
12682 -- enclosing composite type. However, special treatment is needed for
12683 -- the cases of access parameters, return objects of an anonymous access
12684 -- type, and, in Ada 95, access discriminants of limited types.
12686 if Ekind (Btyp) in Access_Kind then
12687 if Ekind (Btyp) = E_Anonymous_Access_Type then
12689 -- If the type is a nonlocal anonymous access type (such as for
12690 -- an access parameter) we treat it as being declared at the
12691 -- library level to ensure that names such as X.all'access don't
12692 -- fail static accessibility checks.
12694 if not Is_Local_Anonymous_Access (Typ) then
12695 return Scope_Depth (Standard_Standard);
12697 -- If this is a return object, the accessibility level is that of
12698 -- the result subtype of the enclosing function. The test here is
12699 -- little complicated, because we have to account for extended
12700 -- return statements that have been rewritten as blocks, in which
12701 -- case we have to find and the Is_Return_Object attribute of the
12702 -- itype's associated object. It would be nice to find a way to
12703 -- simplify this test, but it doesn't seem worthwhile to add a new
12704 -- flag just for purposes of this test. ???
12706 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12709 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12710 N_Object_Declaration
12711 and then Is_Return_Object
12712 (Defining_Identifier
12713 (Associated_Node_For_Itype (Btyp))))
12719 Scop := Scope (Scope (Btyp));
12720 while Present (Scop) loop
12721 exit when Ekind (Scop) = E_Function;
12722 Scop := Scope (Scop);
12725 -- Treat the return object's type as having the level of the
12726 -- function's result subtype (as per RM05-6.5(5.3/2)).
12728 return Type_Access_Level (Etype (Scop));
12733 Btyp := Root_Type (Btyp);
12735 -- The accessibility level of anonymous access types associated with
12736 -- discriminants is that of the current instance of the type, and
12737 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12739 -- AI-402: access discriminants have accessibility based on the
12740 -- object rather than the type in Ada 2005, so the above paragraph
12743 -- ??? Needs completion with rules from AI-416
12745 if Ada_Version <= Ada_95
12746 and then Ekind (Typ) = E_Anonymous_Access_Type
12747 and then Present (Associated_Node_For_Itype (Typ))
12748 and then Nkind (Associated_Node_For_Itype (Typ)) =
12749 N_Discriminant_Specification
12751 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12755 -- Return library level for a generic formal type. This is done because
12756 -- RM(10.3.2) says that "The statically deeper relationship does not
12757 -- apply to ... a descendant of a generic formal type". Rather than
12758 -- checking at each point where a static accessibility check is
12759 -- performed to see if we are dealing with a formal type, this rule is
12760 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
12761 -- return extreme values for a formal type; Deepest_Type_Access_Level
12762 -- returns Int'Last. By calling the appropriate function from among the
12763 -- two, we ensure that the static accessibility check will pass if we
12764 -- happen to run into a formal type. More specifically, we should call
12765 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
12766 -- call occurs as part of a static accessibility check and the error
12767 -- case is the case where the type's level is too shallow (as opposed
12770 if Is_Generic_Type (Root_Type (Btyp)) then
12771 return Scope_Depth (Standard_Standard);
12774 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12775 end Type_Access_Level;
12777 ------------------------------------
12778 -- Type_Without_Stream_Operation --
12779 ------------------------------------
12781 function Type_Without_Stream_Operation
12783 Op : TSS_Name_Type := TSS_Null) return Entity_Id
12785 BT : constant Entity_Id := Base_Type (T);
12786 Op_Missing : Boolean;
12789 if not Restriction_Active (No_Default_Stream_Attributes) then
12793 if Is_Elementary_Type (T) then
12794 if Op = TSS_Null then
12796 No (TSS (BT, TSS_Stream_Read))
12797 or else No (TSS (BT, TSS_Stream_Write));
12800 Op_Missing := No (TSS (BT, Op));
12809 elsif Is_Array_Type (T) then
12810 return Type_Without_Stream_Operation (Component_Type (T), Op);
12812 elsif Is_Record_Type (T) then
12818 Comp := First_Component (T);
12819 while Present (Comp) loop
12820 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
12822 if Present (C_Typ) then
12826 Next_Component (Comp);
12832 elsif Is_Private_Type (T)
12833 and then Present (Full_View (T))
12835 return Type_Without_Stream_Operation (Full_View (T), Op);
12839 end Type_Without_Stream_Operation;
12841 ----------------------------
12842 -- Unique_Defining_Entity --
12843 ----------------------------
12845 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
12847 return Unique_Entity (Defining_Entity (N));
12848 end Unique_Defining_Entity;
12850 -------------------
12851 -- Unique_Entity --
12852 -------------------
12854 function Unique_Entity (E : Entity_Id) return Entity_Id is
12855 U : Entity_Id := E;
12861 if Present (Full_View (E)) then
12862 U := Full_View (E);
12866 if Present (Full_View (E)) then
12867 U := Full_View (E);
12870 when E_Package_Body =>
12873 if Nkind (P) = N_Defining_Program_Unit_Name then
12877 U := Corresponding_Spec (P);
12879 when E_Subprogram_Body =>
12882 if Nkind (P) = N_Defining_Program_Unit_Name then
12888 if Nkind (P) = N_Subprogram_Body_Stub then
12889 if Present (Library_Unit (P)) then
12891 -- Get to the function or procedure (generic) entity through
12892 -- the body entity.
12895 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
12898 U := Corresponding_Spec (P);
12901 when Formal_Kind =>
12902 if Present (Spec_Entity (E)) then
12903 U := Spec_Entity (E);
12917 function Unique_Name (E : Entity_Id) return String is
12919 -- Names of E_Subprogram_Body or E_Package_Body entities are not
12920 -- reliable, as they may not include the overloading suffix. Instead,
12921 -- when looking for the name of E or one of its enclosing scope, we get
12922 -- the name of the corresponding Unique_Entity.
12924 function Get_Scoped_Name (E : Entity_Id) return String;
12925 -- Return the name of E prefixed by all the names of the scopes to which
12926 -- E belongs, except for Standard.
12928 ---------------------
12929 -- Get_Scoped_Name --
12930 ---------------------
12932 function Get_Scoped_Name (E : Entity_Id) return String is
12933 Name : constant String := Get_Name_String (Chars (E));
12935 if Has_Fully_Qualified_Name (E)
12936 or else Scope (E) = Standard_Standard
12940 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
12942 end Get_Scoped_Name;
12944 -- Start of processing for Unique_Name
12947 if E = Standard_Standard then
12948 return Get_Name_String (Name_Standard);
12950 elsif Scope (E) = Standard_Standard
12951 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
12953 return Get_Name_String (Name_Standard) & "__" &
12954 Get_Name_String (Chars (E));
12956 elsif Ekind (E) = E_Enumeration_Literal then
12957 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
12960 return Get_Scoped_Name (Unique_Entity (E));
12964 ---------------------
12965 -- Unit_Is_Visible --
12966 ---------------------
12968 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12969 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12970 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12972 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12973 -- For a child unit, check whether unit appears in a with_clause
12976 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12977 -- Scan the context clause of one compilation unit looking for a
12978 -- with_clause for the unit in question.
12980 ----------------------------
12981 -- Unit_In_Parent_Context --
12982 ----------------------------
12984 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12986 if Unit_In_Context (Par_Unit) then
12989 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12990 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12995 end Unit_In_Parent_Context;
12997 ---------------------
12998 -- Unit_In_Context --
12999 ---------------------
13001 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
13005 Clause := First (Context_Items (Comp_Unit));
13006 while Present (Clause) loop
13007 if Nkind (Clause) = N_With_Clause then
13008 if Library_Unit (Clause) = U then
13011 -- The with_clause may denote a renaming of the unit we are
13012 -- looking for, eg. Text_IO which renames Ada.Text_IO.
13015 Renamed_Entity (Entity (Name (Clause))) =
13016 Defining_Entity (Unit (U))
13026 end Unit_In_Context;
13028 -- Start of processing for Unit_Is_Visible
13031 -- The currrent unit is directly visible
13036 elsif Unit_In_Context (Curr) then
13039 -- If the current unit is a body, check the context of the spec
13041 elsif Nkind (Unit (Curr)) = N_Package_Body
13043 (Nkind (Unit (Curr)) = N_Subprogram_Body
13044 and then not Acts_As_Spec (Unit (Curr)))
13046 if Unit_In_Context (Library_Unit (Curr)) then
13051 -- If the spec is a child unit, examine the parents
13053 if Is_Child_Unit (Curr_Entity) then
13054 if Nkind (Unit (Curr)) in N_Unit_Body then
13056 Unit_In_Parent_Context
13057 (Parent_Spec (Unit (Library_Unit (Curr))));
13059 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
13065 end Unit_Is_Visible;
13067 ------------------------------
13068 -- Universal_Interpretation --
13069 ------------------------------
13071 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
13072 Index : Interp_Index;
13076 -- The argument may be a formal parameter of an operator or subprogram
13077 -- with multiple interpretations, or else an expression for an actual.
13079 if Nkind (Opnd) = N_Defining_Identifier
13080 or else not Is_Overloaded (Opnd)
13082 if Etype (Opnd) = Universal_Integer
13083 or else Etype (Opnd) = Universal_Real
13085 return Etype (Opnd);
13091 Get_First_Interp (Opnd, Index, It);
13092 while Present (It.Typ) loop
13093 if It.Typ = Universal_Integer
13094 or else It.Typ = Universal_Real
13099 Get_Next_Interp (Index, It);
13104 end Universal_Interpretation;
13110 function Unqualify (Expr : Node_Id) return Node_Id is
13112 -- Recurse to handle unlikely case of multiple levels of qualification
13114 if Nkind (Expr) = N_Qualified_Expression then
13115 return Unqualify (Expression (Expr));
13117 -- Normal case, not a qualified expression
13124 -----------------------
13125 -- Visible_Ancestors --
13126 -----------------------
13128 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
13134 pragma Assert (Is_Record_Type (Typ)
13135 and then Is_Tagged_Type (Typ));
13137 -- Collect all the parents and progenitors of Typ. If the full-view of
13138 -- private parents and progenitors is available then it is used to
13139 -- generate the list of visible ancestors; otherwise their partial
13140 -- view is added to the resulting list.
13145 Use_Full_View => True);
13149 Ifaces_List => List_2,
13150 Exclude_Parents => True,
13151 Use_Full_View => True);
13153 -- Join the two lists. Avoid duplications because an interface may
13154 -- simultaneously be parent and progenitor of a type.
13156 Elmt := First_Elmt (List_2);
13157 while Present (Elmt) loop
13158 Append_Unique_Elmt (Node (Elmt), List_1);
13163 end Visible_Ancestors;
13165 ----------------------
13166 -- Within_Init_Proc --
13167 ----------------------
13169 function Within_Init_Proc return Boolean is
13173 S := Current_Scope;
13174 while not Is_Overloadable (S) loop
13175 if S = Standard_Standard then
13182 return Is_Init_Proc (S);
13183 end Within_Init_Proc;
13189 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
13190 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
13191 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
13193 Matching_Field : Entity_Id;
13194 -- Entity to give a more precise suggestion on how to write a one-
13195 -- element positional aggregate.
13197 function Has_One_Matching_Field return Boolean;
13198 -- Determines if Expec_Type is a record type with a single component or
13199 -- discriminant whose type matches the found type or is one dimensional
13200 -- array whose component type matches the found type.
13202 ----------------------------
13203 -- Has_One_Matching_Field --
13204 ----------------------------
13206 function Has_One_Matching_Field return Boolean is
13210 Matching_Field := Empty;
13212 if Is_Array_Type (Expec_Type)
13213 and then Number_Dimensions (Expec_Type) = 1
13215 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
13217 -- Use type name if available. This excludes multidimensional
13218 -- arrays and anonymous arrays.
13220 if Comes_From_Source (Expec_Type) then
13221 Matching_Field := Expec_Type;
13223 -- For an assignment, use name of target
13225 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
13226 and then Is_Entity_Name (Name (Parent (Expr)))
13228 Matching_Field := Entity (Name (Parent (Expr)));
13233 elsif not Is_Record_Type (Expec_Type) then
13237 E := First_Entity (Expec_Type);
13242 elsif (Ekind (E) /= E_Discriminant
13243 and then Ekind (E) /= E_Component)
13244 or else (Chars (E) = Name_uTag
13245 or else Chars (E) = Name_uParent)
13254 if not Covers (Etype (E), Found_Type) then
13257 elsif Present (Next_Entity (E)) then
13261 Matching_Field := E;
13265 end Has_One_Matching_Field;
13267 -- Start of processing for Wrong_Type
13270 -- Don't output message if either type is Any_Type, or if a message
13271 -- has already been posted for this node. We need to do the latter
13272 -- check explicitly (it is ordinarily done in Errout), because we
13273 -- are using ! to force the output of the error messages.
13275 if Expec_Type = Any_Type
13276 or else Found_Type = Any_Type
13277 or else Error_Posted (Expr)
13281 -- If one of the types is a Taft-Amendment type and the other it its
13282 -- completion, it must be an illegal use of a TAT in the spec, for
13283 -- which an error was already emitted. Avoid cascaded errors.
13285 elsif Is_Incomplete_Type (Expec_Type)
13286 and then Has_Completion_In_Body (Expec_Type)
13287 and then Full_View (Expec_Type) = Etype (Expr)
13291 elsif Is_Incomplete_Type (Etype (Expr))
13292 and then Has_Completion_In_Body (Etype (Expr))
13293 and then Full_View (Etype (Expr)) = Expec_Type
13297 -- In an instance, there is an ongoing problem with completion of
13298 -- type derived from private types. Their structure is what Gigi
13299 -- expects, but the Etype is the parent type rather than the
13300 -- derived private type itself. Do not flag error in this case. The
13301 -- private completion is an entity without a parent, like an Itype.
13302 -- Similarly, full and partial views may be incorrect in the instance.
13303 -- There is no simple way to insure that it is consistent ???
13305 elsif In_Instance then
13306 if Etype (Etype (Expr)) = Etype (Expected_Type)
13308 (Has_Private_Declaration (Expected_Type)
13309 or else Has_Private_Declaration (Etype (Expr)))
13310 and then No (Parent (Expected_Type))
13316 -- An interesting special check. If the expression is parenthesized
13317 -- and its type corresponds to the type of the sole component of the
13318 -- expected record type, or to the component type of the expected one
13319 -- dimensional array type, then assume we have a bad aggregate attempt.
13321 if Nkind (Expr) in N_Subexpr
13322 and then Paren_Count (Expr) /= 0
13323 and then Has_One_Matching_Field
13325 Error_Msg_N ("positional aggregate cannot have one component", Expr);
13326 if Present (Matching_Field) then
13327 if Is_Array_Type (Expec_Type) then
13329 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
13333 ("\write instead `& ='> ...`", Expr, Matching_Field);
13337 -- Another special check, if we are looking for a pool-specific access
13338 -- type and we found an E_Access_Attribute_Type, then we have the case
13339 -- of an Access attribute being used in a context which needs a pool-
13340 -- specific type, which is never allowed. The one extra check we make
13341 -- is that the expected designated type covers the Found_Type.
13343 elsif Is_Access_Type (Expec_Type)
13344 and then Ekind (Found_Type) = E_Access_Attribute_Type
13345 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
13346 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
13348 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
13350 Error_Msg_N -- CODEFIX
13351 ("result must be general access type!", Expr);
13352 Error_Msg_NE -- CODEFIX
13353 ("add ALL to }!", Expr, Expec_Type);
13355 -- Another special check, if the expected type is an integer type,
13356 -- but the expression is of type System.Address, and the parent is
13357 -- an addition or subtraction operation whose left operand is the
13358 -- expression in question and whose right operand is of an integral
13359 -- type, then this is an attempt at address arithmetic, so give
13360 -- appropriate message.
13362 elsif Is_Integer_Type (Expec_Type)
13363 and then Is_RTE (Found_Type, RE_Address)
13364 and then (Nkind (Parent (Expr)) = N_Op_Add
13366 Nkind (Parent (Expr)) = N_Op_Subtract)
13367 and then Expr = Left_Opnd (Parent (Expr))
13368 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
13371 ("address arithmetic not predefined in package System",
13374 ("\possible missing with/use of System.Storage_Elements",
13378 -- If the expected type is an anonymous access type, as for access
13379 -- parameters and discriminants, the error is on the designated types.
13381 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
13382 if Comes_From_Source (Expec_Type) then
13383 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13386 ("expected an access type with designated}",
13387 Expr, Designated_Type (Expec_Type));
13390 if Is_Access_Type (Found_Type)
13391 and then not Comes_From_Source (Found_Type)
13394 ("\\found an access type with designated}!",
13395 Expr, Designated_Type (Found_Type));
13397 if From_With_Type (Found_Type) then
13398 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
13399 Error_Msg_Qual_Level := 99;
13400 Error_Msg_NE -- CODEFIX
13401 ("\\missing `WITH &;", Expr, Scope (Found_Type));
13402 Error_Msg_Qual_Level := 0;
13404 Error_Msg_NE ("found}!", Expr, Found_Type);
13408 -- Normal case of one type found, some other type expected
13411 -- If the names of the two types are the same, see if some number
13412 -- of levels of qualification will help. Don't try more than three
13413 -- levels, and if we get to standard, it's no use (and probably
13414 -- represents an error in the compiler) Also do not bother with
13415 -- internal scope names.
13418 Expec_Scope : Entity_Id;
13419 Found_Scope : Entity_Id;
13422 Expec_Scope := Expec_Type;
13423 Found_Scope := Found_Type;
13425 for Levels in Int range 0 .. 3 loop
13426 if Chars (Expec_Scope) /= Chars (Found_Scope) then
13427 Error_Msg_Qual_Level := Levels;
13431 Expec_Scope := Scope (Expec_Scope);
13432 Found_Scope := Scope (Found_Scope);
13434 exit when Expec_Scope = Standard_Standard
13435 or else Found_Scope = Standard_Standard
13436 or else not Comes_From_Source (Expec_Scope)
13437 or else not Comes_From_Source (Found_Scope);
13441 if Is_Record_Type (Expec_Type)
13442 and then Present (Corresponding_Remote_Type (Expec_Type))
13444 Error_Msg_NE ("expected}!", Expr,
13445 Corresponding_Remote_Type (Expec_Type));
13447 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13450 if Is_Entity_Name (Expr)
13451 and then Is_Package_Or_Generic_Package (Entity (Expr))
13453 Error_Msg_N ("\\found package name!", Expr);
13455 elsif Is_Entity_Name (Expr)
13457 (Ekind (Entity (Expr)) = E_Procedure
13459 Ekind (Entity (Expr)) = E_Generic_Procedure)
13461 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
13463 ("found procedure name, possibly missing Access attribute!",
13467 ("\\found procedure name instead of function!", Expr);
13470 elsif Nkind (Expr) = N_Function_Call
13471 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
13472 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
13473 and then No (Parameter_Associations (Expr))
13476 ("found function name, possibly missing Access attribute!",
13479 -- Catch common error: a prefix or infix operator which is not
13480 -- directly visible because the type isn't.
13482 elsif Nkind (Expr) in N_Op
13483 and then Is_Overloaded (Expr)
13484 and then not Is_Immediately_Visible (Expec_Type)
13485 and then not Is_Potentially_Use_Visible (Expec_Type)
13486 and then not In_Use (Expec_Type)
13487 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
13490 ("operator of the type is not directly visible!", Expr);
13492 elsif Ekind (Found_Type) = E_Void
13493 and then Present (Parent (Found_Type))
13494 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
13496 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
13499 Error_Msg_NE ("\\found}!", Expr, Found_Type);
13502 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
13503 -- of the same modular type, and (M1 and M2) = 0 was intended.
13505 if Expec_Type = Standard_Boolean
13506 and then Is_Modular_Integer_Type (Found_Type)
13507 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
13508 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
13511 Op : constant Node_Id := Right_Opnd (Parent (Expr));
13512 L : constant Node_Id := Left_Opnd (Op);
13513 R : constant Node_Id := Right_Opnd (Op);
13515 -- The case for the message is when the left operand of the
13516 -- comparison is the same modular type, or when it is an
13517 -- integer literal (or other universal integer expression),
13518 -- which would have been typed as the modular type if the
13519 -- parens had been there.
13521 if (Etype (L) = Found_Type
13523 Etype (L) = Universal_Integer)
13524 and then Is_Integer_Type (Etype (R))
13527 ("\\possible missing parens for modular operation", Expr);
13532 -- Reset error message qualification indication
13534 Error_Msg_Qual_Level := 0;