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
2472 return Defining_Entity (Specification (N));
2475 N_Component_Declaration |
2476 N_Defining_Program_Unit_Name |
2477 N_Discriminant_Specification |
2479 N_Entry_Declaration |
2480 N_Entry_Index_Specification |
2481 N_Exception_Declaration |
2482 N_Exception_Renaming_Declaration |
2483 N_Formal_Object_Declaration |
2484 N_Formal_Package_Declaration |
2485 N_Formal_Type_Declaration |
2486 N_Full_Type_Declaration |
2487 N_Implicit_Label_Declaration |
2488 N_Incomplete_Type_Declaration |
2489 N_Loop_Parameter_Specification |
2490 N_Number_Declaration |
2491 N_Object_Declaration |
2492 N_Object_Renaming_Declaration |
2493 N_Package_Body_Stub |
2494 N_Parameter_Specification |
2495 N_Private_Extension_Declaration |
2496 N_Private_Type_Declaration |
2498 N_Protected_Body_Stub |
2499 N_Protected_Type_Declaration |
2500 N_Single_Protected_Declaration |
2501 N_Single_Task_Declaration |
2502 N_Subtype_Declaration |
2505 N_Task_Type_Declaration
2507 return Defining_Identifier (N);
2510 return Defining_Entity (Proper_Body (N));
2513 N_Function_Instantiation |
2514 N_Function_Specification |
2515 N_Generic_Function_Renaming_Declaration |
2516 N_Generic_Package_Renaming_Declaration |
2517 N_Generic_Procedure_Renaming_Declaration |
2519 N_Package_Instantiation |
2520 N_Package_Renaming_Declaration |
2521 N_Package_Specification |
2522 N_Procedure_Instantiation |
2523 N_Procedure_Specification
2526 Nam : constant Node_Id := Defining_Unit_Name (N);
2529 if Nkind (Nam) in N_Entity then
2532 -- For Error, make up a name and attach to declaration
2533 -- so we can continue semantic analysis
2535 elsif Nam = Error then
2536 Err := Make_Temporary (Sloc (N), 'T');
2537 Set_Defining_Unit_Name (N, Err);
2540 -- If not an entity, get defining identifier
2543 return Defining_Identifier (Nam);
2547 when N_Block_Statement =>
2548 return Entity (Identifier (N));
2551 raise Program_Error;
2554 end Defining_Entity;
2556 --------------------------
2557 -- Denotes_Discriminant --
2558 --------------------------
2560 function Denotes_Discriminant
2562 Check_Concurrent : Boolean := False) return Boolean
2566 if not Is_Entity_Name (N)
2567 or else No (Entity (N))
2574 -- If we are checking for a protected type, the discriminant may have
2575 -- been rewritten as the corresponding discriminal of the original type
2576 -- or of the corresponding concurrent record, depending on whether we
2577 -- are in the spec or body of the protected type.
2579 return Ekind (E) = E_Discriminant
2582 and then Ekind (E) = E_In_Parameter
2583 and then Present (Discriminal_Link (E))
2585 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2587 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2589 end Denotes_Discriminant;
2591 -------------------------
2592 -- Denotes_Same_Object --
2593 -------------------------
2595 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2596 Obj1 : Node_Id := A1;
2597 Obj2 : Node_Id := A2;
2599 procedure Check_Renaming (Obj : in out Node_Id);
2600 -- If an object is a renaming, examine renamed object. If it is a
2601 -- dereference of a variable, or an indexed expression with non-constant
2602 -- indexes, no overlap check can be reported.
2604 --------------------
2605 -- Check_Renaming --
2606 --------------------
2608 procedure Check_Renaming (Obj : in out Node_Id) is
2610 if Is_Entity_Name (Obj)
2611 and then Present (Renamed_Entity (Entity (Obj)))
2613 Obj := Renamed_Entity (Entity (Obj));
2614 if Nkind (Obj) = N_Explicit_Dereference
2615 and then Is_Variable (Prefix (Obj))
2619 elsif Nkind (Obj) = N_Indexed_Component then
2624 Indx := First (Expressions (Obj));
2625 while Present (Indx) loop
2626 if not Is_OK_Static_Expression (Indx) then
2638 -- Start of processing for Denotes_Same_Object
2641 Check_Renaming (Obj1);
2642 Check_Renaming (Obj2);
2650 -- If we have entity names, then must be same entity
2652 if Is_Entity_Name (Obj1) then
2653 if Is_Entity_Name (Obj2) then
2654 return Entity (Obj1) = Entity (Obj2);
2659 -- No match if not same node kind
2661 elsif Nkind (Obj1) /= Nkind (Obj2) then
2664 -- For selected components, must have same prefix and selector
2666 elsif Nkind (Obj1) = N_Selected_Component then
2667 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2669 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2671 -- For explicit dereferences, prefixes must be same
2673 elsif Nkind (Obj1) = N_Explicit_Dereference then
2674 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2676 -- For indexed components, prefixes and all subscripts must be the same
2678 elsif Nkind (Obj1) = N_Indexed_Component then
2679 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2685 Indx1 := First (Expressions (Obj1));
2686 Indx2 := First (Expressions (Obj2));
2687 while Present (Indx1) loop
2689 -- Indexes must denote the same static value or same object
2691 if Is_OK_Static_Expression (Indx1) then
2692 if not Is_OK_Static_Expression (Indx2) then
2695 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2699 elsif not Denotes_Same_Object (Indx1, Indx2) then
2713 -- For slices, prefixes must match and bounds must match
2715 elsif Nkind (Obj1) = N_Slice
2716 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2719 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2722 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2723 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2725 -- Check whether bounds are statically identical. There is no
2726 -- attempt to detect partial overlap of slices.
2728 return Denotes_Same_Object (Lo1, Lo2)
2729 and then Denotes_Same_Object (Hi1, Hi2);
2732 -- Literals will appear as indexes. Isn't this where we should check
2733 -- Known_At_Compile_Time at least if we are generating warnings ???
2735 elsif Nkind (Obj1) = N_Integer_Literal then
2736 return Intval (Obj1) = Intval (Obj2);
2741 end Denotes_Same_Object;
2743 -------------------------
2744 -- Denotes_Same_Prefix --
2745 -------------------------
2747 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2750 if Is_Entity_Name (A1) then
2751 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2752 and then not Is_Access_Type (Etype (A1))
2754 return Denotes_Same_Object (A1, Prefix (A2))
2755 or else Denotes_Same_Prefix (A1, Prefix (A2));
2760 elsif Is_Entity_Name (A2) then
2761 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
2763 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2765 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2768 Root1, Root2 : Node_Id;
2769 Depth1, Depth2 : Int := 0;
2772 Root1 := Prefix (A1);
2773 while not Is_Entity_Name (Root1) loop
2775 (Root1, N_Selected_Component, N_Indexed_Component)
2779 Root1 := Prefix (Root1);
2782 Depth1 := Depth1 + 1;
2785 Root2 := Prefix (A2);
2786 while not Is_Entity_Name (Root2) loop
2788 (Root2, N_Selected_Component, N_Indexed_Component)
2792 Root2 := Prefix (Root2);
2795 Depth2 := Depth2 + 1;
2798 -- If both have the same depth and they do not denote the same
2799 -- object, they are disjoint and not warning is needed.
2801 if Depth1 = Depth2 then
2804 elsif Depth1 > Depth2 then
2805 Root1 := Prefix (A1);
2806 for I in 1 .. Depth1 - Depth2 - 1 loop
2807 Root1 := Prefix (Root1);
2810 return Denotes_Same_Object (Root1, A2);
2813 Root2 := Prefix (A2);
2814 for I in 1 .. Depth2 - Depth1 - 1 loop
2815 Root2 := Prefix (Root2);
2818 return Denotes_Same_Object (A1, Root2);
2825 end Denotes_Same_Prefix;
2827 ----------------------
2828 -- Denotes_Variable --
2829 ----------------------
2831 function Denotes_Variable (N : Node_Id) return Boolean is
2833 return Is_Variable (N) and then Paren_Count (N) = 0;
2834 end Denotes_Variable;
2836 -----------------------------
2837 -- Depends_On_Discriminant --
2838 -----------------------------
2840 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2845 Get_Index_Bounds (N, L, H);
2846 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2847 end Depends_On_Discriminant;
2849 -------------------------
2850 -- Designate_Same_Unit --
2851 -------------------------
2853 function Designate_Same_Unit
2855 Name2 : Node_Id) return Boolean
2857 K1 : constant Node_Kind := Nkind (Name1);
2858 K2 : constant Node_Kind := Nkind (Name2);
2860 function Prefix_Node (N : Node_Id) return Node_Id;
2861 -- Returns the parent unit name node of a defining program unit name
2862 -- or the prefix if N is a selected component or an expanded name.
2864 function Select_Node (N : Node_Id) return Node_Id;
2865 -- Returns the defining identifier node of a defining program unit
2866 -- name or the selector node if N is a selected component or an
2873 function Prefix_Node (N : Node_Id) return Node_Id is
2875 if Nkind (N) = N_Defining_Program_Unit_Name then
2887 function Select_Node (N : Node_Id) return Node_Id is
2889 if Nkind (N) = N_Defining_Program_Unit_Name then
2890 return Defining_Identifier (N);
2893 return Selector_Name (N);
2897 -- Start of processing for Designate_Next_Unit
2900 if (K1 = N_Identifier or else
2901 K1 = N_Defining_Identifier)
2903 (K2 = N_Identifier or else
2904 K2 = N_Defining_Identifier)
2906 return Chars (Name1) = Chars (Name2);
2909 (K1 = N_Expanded_Name or else
2910 K1 = N_Selected_Component or else
2911 K1 = N_Defining_Program_Unit_Name)
2913 (K2 = N_Expanded_Name or else
2914 K2 = N_Selected_Component or else
2915 K2 = N_Defining_Program_Unit_Name)
2918 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2920 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2925 end Designate_Same_Unit;
2927 ------------------------------------------
2928 -- function Dynamic_Accessibility_Level --
2929 ------------------------------------------
2931 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
2933 Loc : constant Source_Ptr := Sloc (Expr);
2935 function Make_Level_Literal (Level : Uint) return Node_Id;
2936 -- Construct an integer literal representing an accessibility level
2937 -- with its type set to Natural.
2939 ------------------------
2940 -- Make_Level_Literal --
2941 ------------------------
2943 function Make_Level_Literal (Level : Uint) return Node_Id is
2944 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
2946 Set_Etype (Result, Standard_Natural);
2948 end Make_Level_Literal;
2950 -- Start of processing for Dynamic_Accessibility_Level
2953 if Is_Entity_Name (Expr) then
2956 if Present (Renamed_Object (E)) then
2957 return Dynamic_Accessibility_Level (Renamed_Object (E));
2960 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
2961 if Present (Extra_Accessibility (E)) then
2962 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
2967 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
2969 case Nkind (Expr) is
2971 -- For access discriminant, the level of the enclosing object
2973 when N_Selected_Component =>
2974 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
2975 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
2976 E_Anonymous_Access_Type
2978 return Make_Level_Literal (Object_Access_Level (Expr));
2981 when N_Attribute_Reference =>
2982 case Get_Attribute_Id (Attribute_Name (Expr)) is
2984 -- For X'Access, the level of the prefix X
2986 when Attribute_Access =>
2987 return Make_Level_Literal
2988 (Object_Access_Level (Prefix (Expr)));
2990 -- Treat the unchecked attributes as library-level
2992 when Attribute_Unchecked_Access |
2993 Attribute_Unrestricted_Access =>
2994 return Make_Level_Literal (Scope_Depth (Standard_Standard));
2996 -- No other access-valued attributes
2999 raise Program_Error;
3004 -- Unimplemented: depends on context. As an actual parameter where
3005 -- formal type is anonymous, use
3006 -- Scope_Depth (Current_Scope) + 1.
3007 -- For other cases, see 3.10.2(14/3) and following. ???
3011 when N_Type_Conversion =>
3012 if not Is_Local_Anonymous_Access (Etype (Expr)) then
3014 -- Handle type conversions introduced for a rename of an
3015 -- Ada 2012 stand-alone object of an anonymous access type.
3017 return Dynamic_Accessibility_Level (Expression (Expr));
3024 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
3025 end Dynamic_Accessibility_Level;
3027 -----------------------------------
3028 -- Effective_Extra_Accessibility --
3029 -----------------------------------
3031 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
3033 if Present (Renamed_Object (Id))
3034 and then Is_Entity_Name (Renamed_Object (Id))
3036 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
3039 return Extra_Accessibility (Id);
3040 end Effective_Extra_Accessibility;
3042 ----------------------------------------------
3043 -- Effectively_Has_Constrained_Partial_View --
3044 ----------------------------------------------
3046 function Effectively_Has_Constrained_Partial_View
3048 Scop : Entity_Id := Current_Scope) return Boolean is
3050 return Has_Constrained_Partial_View (Typ)
3051 or else (In_Generic_Body (Scop)
3052 and then Is_Generic_Type (Base_Type (Typ))
3053 and then Is_Private_Type (Base_Type (Typ))
3054 and then not Is_Tagged_Type (Typ)
3055 and then not (Is_Array_Type (Typ)
3056 and then not Is_Constrained (Typ))
3057 and then Has_Discriminants (Typ));
3058 end Effectively_Has_Constrained_Partial_View;
3060 --------------------------
3061 -- Enclosing_CPP_Parent --
3062 --------------------------
3064 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
3065 Parent_Typ : Entity_Id := Typ;
3068 while not Is_CPP_Class (Parent_Typ)
3069 and then Etype (Parent_Typ) /= Parent_Typ
3071 Parent_Typ := Etype (Parent_Typ);
3073 if Is_Private_Type (Parent_Typ) then
3074 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3078 pragma Assert (Is_CPP_Class (Parent_Typ));
3080 end Enclosing_CPP_Parent;
3082 ----------------------------
3083 -- Enclosing_Generic_Body --
3084 ----------------------------
3086 function Enclosing_Generic_Body
3087 (N : Node_Id) return Node_Id
3095 while Present (P) loop
3096 if Nkind (P) = N_Package_Body
3097 or else Nkind (P) = N_Subprogram_Body
3099 Spec := Corresponding_Spec (P);
3101 if Present (Spec) then
3102 Decl := Unit_Declaration_Node (Spec);
3104 if Nkind (Decl) = N_Generic_Package_Declaration
3105 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3116 end Enclosing_Generic_Body;
3118 ----------------------------
3119 -- Enclosing_Generic_Unit --
3120 ----------------------------
3122 function Enclosing_Generic_Unit
3123 (N : Node_Id) return Node_Id
3131 while Present (P) loop
3132 if Nkind (P) = N_Generic_Package_Declaration
3133 or else Nkind (P) = N_Generic_Subprogram_Declaration
3137 elsif Nkind (P) = N_Package_Body
3138 or else Nkind (P) = N_Subprogram_Body
3140 Spec := Corresponding_Spec (P);
3142 if Present (Spec) then
3143 Decl := Unit_Declaration_Node (Spec);
3145 if Nkind (Decl) = N_Generic_Package_Declaration
3146 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
3157 end Enclosing_Generic_Unit;
3159 -------------------------------
3160 -- Enclosing_Lib_Unit_Entity --
3161 -------------------------------
3163 function Enclosing_Lib_Unit_Entity return Entity_Id is
3164 Unit_Entity : Entity_Id;
3167 -- Look for enclosing library unit entity by following scope links.
3168 -- Equivalent to, but faster than indexing through the scope stack.
3170 Unit_Entity := Current_Scope;
3171 while (Present (Scope (Unit_Entity))
3172 and then Scope (Unit_Entity) /= Standard_Standard)
3173 and not Is_Child_Unit (Unit_Entity)
3175 Unit_Entity := Scope (Unit_Entity);
3179 end Enclosing_Lib_Unit_Entity;
3181 -----------------------------
3182 -- Enclosing_Lib_Unit_Node --
3183 -----------------------------
3185 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
3186 Current_Node : Node_Id;
3190 while Present (Current_Node)
3191 and then Nkind (Current_Node) /= N_Compilation_Unit
3193 Current_Node := Parent (Current_Node);
3196 if Nkind (Current_Node) /= N_Compilation_Unit then
3200 return Current_Node;
3201 end Enclosing_Lib_Unit_Node;
3203 -----------------------
3204 -- Enclosing_Package --
3205 -----------------------
3207 function Enclosing_Package (E : Entity_Id) return Entity_Id is
3208 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3211 if Dynamic_Scope = Standard_Standard then
3212 return Standard_Standard;
3214 elsif Dynamic_Scope = Empty then
3217 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
3220 return Dynamic_Scope;
3223 return Enclosing_Package (Dynamic_Scope);
3225 end Enclosing_Package;
3227 --------------------------
3228 -- Enclosing_Subprogram --
3229 --------------------------
3231 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3232 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3235 if Dynamic_Scope = Standard_Standard then
3238 elsif Dynamic_Scope = Empty then
3241 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3242 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3244 elsif Ekind (Dynamic_Scope) = E_Block
3245 or else Ekind (Dynamic_Scope) = E_Return_Statement
3247 return Enclosing_Subprogram (Dynamic_Scope);
3249 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3250 return Get_Task_Body_Procedure (Dynamic_Scope);
3252 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3253 and then Present (Full_View (Dynamic_Scope))
3254 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3256 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3258 -- No body is generated if the protected operation is eliminated
3260 elsif Convention (Dynamic_Scope) = Convention_Protected
3261 and then not Is_Eliminated (Dynamic_Scope)
3262 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3264 return Protected_Body_Subprogram (Dynamic_Scope);
3267 return Dynamic_Scope;
3269 end Enclosing_Subprogram;
3271 ------------------------
3272 -- Ensure_Freeze_Node --
3273 ------------------------
3275 procedure Ensure_Freeze_Node (E : Entity_Id) is
3279 if No (Freeze_Node (E)) then
3280 FN := Make_Freeze_Entity (Sloc (E));
3281 Set_Has_Delayed_Freeze (E);
3282 Set_Freeze_Node (E, FN);
3283 Set_Access_Types_To_Process (FN, No_Elist);
3284 Set_TSS_Elist (FN, No_Elist);
3287 end Ensure_Freeze_Node;
3293 procedure Enter_Name (Def_Id : Entity_Id) is
3294 C : constant Entity_Id := Current_Entity (Def_Id);
3295 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3296 S : constant Entity_Id := Current_Scope;
3299 Generate_Definition (Def_Id);
3301 -- Add new name to current scope declarations. Check for duplicate
3302 -- declaration, which may or may not be a genuine error.
3306 -- Case of previous entity entered because of a missing declaration
3307 -- or else a bad subtype indication. Best is to use the new entity,
3308 -- and make the previous one invisible.
3310 if Etype (E) = Any_Type then
3311 Set_Is_Immediately_Visible (E, False);
3313 -- Case of renaming declaration constructed for package instances.
3314 -- if there is an explicit declaration with the same identifier,
3315 -- the renaming is not immediately visible any longer, but remains
3316 -- visible through selected component notation.
3318 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3319 and then not Comes_From_Source (E)
3321 Set_Is_Immediately_Visible (E, False);
3323 -- The new entity may be the package renaming, which has the same
3324 -- same name as a generic formal which has been seen already.
3326 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3327 and then not Comes_From_Source (Def_Id)
3329 Set_Is_Immediately_Visible (E, False);
3331 -- For a fat pointer corresponding to a remote access to subprogram,
3332 -- we use the same identifier as the RAS type, so that the proper
3333 -- name appears in the stub. This type is only retrieved through
3334 -- the RAS type and never by visibility, and is not added to the
3335 -- visibility list (see below).
3337 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3338 and then Present (Corresponding_Remote_Type (Def_Id))
3342 -- Case of an implicit operation or derived literal. The new entity
3343 -- hides the implicit one, which is removed from all visibility,
3344 -- i.e. the entity list of its scope, and homonym chain of its name.
3346 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3347 or else Is_Internal (E)
3351 Prev_Vis : Entity_Id;
3352 Decl : constant Node_Id := Parent (E);
3355 -- If E is an implicit declaration, it cannot be the first
3356 -- entity in the scope.
3358 Prev := First_Entity (Current_Scope);
3359 while Present (Prev)
3360 and then Next_Entity (Prev) /= E
3367 -- If E is not on the entity chain of the current scope,
3368 -- it is an implicit declaration in the generic formal
3369 -- part of a generic subprogram. When analyzing the body,
3370 -- the generic formals are visible but not on the entity
3371 -- chain of the subprogram. The new entity will become
3372 -- the visible one in the body.
3375 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3379 Set_Next_Entity (Prev, Next_Entity (E));
3381 if No (Next_Entity (Prev)) then
3382 Set_Last_Entity (Current_Scope, Prev);
3385 if E = Current_Entity (E) then
3389 Prev_Vis := Current_Entity (E);
3390 while Homonym (Prev_Vis) /= E loop
3391 Prev_Vis := Homonym (Prev_Vis);
3395 if Present (Prev_Vis) then
3397 -- Skip E in the visibility chain
3399 Set_Homonym (Prev_Vis, Homonym (E));
3402 Set_Name_Entity_Id (Chars (E), Homonym (E));
3407 -- This section of code could use a comment ???
3409 elsif Present (Etype (E))
3410 and then Is_Concurrent_Type (Etype (E))
3415 -- If the homograph is a protected component renaming, it should not
3416 -- be hiding the current entity. Such renamings are treated as weak
3419 elsif Is_Prival (E) then
3420 Set_Is_Immediately_Visible (E, False);
3422 -- In this case the current entity is a protected component renaming.
3423 -- Perform minimal decoration by setting the scope and return since
3424 -- the prival should not be hiding other visible entities.
3426 elsif Is_Prival (Def_Id) then
3427 Set_Scope (Def_Id, Current_Scope);
3430 -- Analogous to privals, the discriminal generated for an entry index
3431 -- parameter acts as a weak declaration. Perform minimal decoration
3432 -- to avoid bogus errors.
3434 elsif Is_Discriminal (Def_Id)
3435 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3437 Set_Scope (Def_Id, Current_Scope);
3440 -- In the body or private part of an instance, a type extension may
3441 -- introduce a component with the same name as that of an actual. The
3442 -- legality rule is not enforced, but the semantics of the full type
3443 -- with two components of same name are not clear at this point???
3445 elsif In_Instance_Not_Visible then
3448 -- When compiling a package body, some child units may have become
3449 -- visible. They cannot conflict with local entities that hide them.
3451 elsif Is_Child_Unit (E)
3452 and then In_Open_Scopes (Scope (E))
3453 and then not Is_Immediately_Visible (E)
3457 -- Conversely, with front-end inlining we may compile the parent body
3458 -- first, and a child unit subsequently. The context is now the
3459 -- parent spec, and body entities are not visible.
3461 elsif Is_Child_Unit (Def_Id)
3462 and then Is_Package_Body_Entity (E)
3463 and then not In_Package_Body (Current_Scope)
3467 -- Case of genuine duplicate declaration
3470 Error_Msg_Sloc := Sloc (E);
3472 -- If the previous declaration is an incomplete type declaration
3473 -- this may be an attempt to complete it with a private type. The
3474 -- following avoids confusing cascaded errors.
3476 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3477 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3480 ("incomplete type cannot be completed with a private " &
3481 "declaration", Parent (Def_Id));
3482 Set_Is_Immediately_Visible (E, False);
3483 Set_Full_View (E, Def_Id);
3485 -- An inherited component of a record conflicts with a new
3486 -- discriminant. The discriminant is inserted first in the scope,
3487 -- but the error should be posted on it, not on the component.
3489 elsif Ekind (E) = E_Discriminant
3490 and then Present (Scope (Def_Id))
3491 and then Scope (Def_Id) /= Current_Scope
3493 Error_Msg_Sloc := Sloc (Def_Id);
3494 Error_Msg_N ("& conflicts with declaration#", E);
3497 -- If the name of the unit appears in its own context clause, a
3498 -- dummy package with the name has already been created, and the
3499 -- error emitted. Try to continue quietly.
3501 elsif Error_Posted (E)
3502 and then Sloc (E) = No_Location
3503 and then Nkind (Parent (E)) = N_Package_Specification
3504 and then Current_Scope = Standard_Standard
3506 Set_Scope (Def_Id, Current_Scope);
3510 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3512 -- Avoid cascaded messages with duplicate components in
3515 if Ekind_In (E, E_Component, E_Discriminant) then
3520 if Nkind (Parent (Parent (Def_Id))) =
3521 N_Generic_Subprogram_Declaration
3523 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3525 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3528 -- If entity is in standard, then we are in trouble, because it
3529 -- means that we have a library package with a duplicated name.
3530 -- That's hard to recover from, so abort!
3532 if S = Standard_Standard then
3533 raise Unrecoverable_Error;
3535 -- Otherwise we continue with the declaration. Having two
3536 -- identical declarations should not cause us too much trouble!
3544 -- If we fall through, declaration is OK, at least OK enough to continue
3546 -- If Def_Id is a discriminant or a record component we are in the midst
3547 -- of inheriting components in a derived record definition. Preserve
3548 -- their Ekind and Etype.
3550 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3553 -- If a type is already set, leave it alone (happens when a type
3554 -- declaration is reanalyzed following a call to the optimizer).
3556 elsif Present (Etype (Def_Id)) then
3559 -- Otherwise, the kind E_Void insures that premature uses of the entity
3560 -- will be detected. Any_Type insures that no cascaded errors will occur
3563 Set_Ekind (Def_Id, E_Void);
3564 Set_Etype (Def_Id, Any_Type);
3567 -- Inherited discriminants and components in derived record types are
3568 -- immediately visible. Itypes are not.
3570 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3571 or else (No (Corresponding_Remote_Type (Def_Id))
3572 and then not Is_Itype (Def_Id))
3574 Set_Is_Immediately_Visible (Def_Id);
3575 Set_Current_Entity (Def_Id);
3578 Set_Homonym (Def_Id, C);
3579 Append_Entity (Def_Id, S);
3580 Set_Public_Status (Def_Id);
3582 -- Declaring a homonym is not allowed in SPARK ...
3585 and then Restriction_Check_Required (SPARK)
3589 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3590 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3591 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3594 -- ... unless the new declaration is in a subprogram, and the
3595 -- visible declaration is a variable declaration or a parameter
3596 -- specification outside that subprogram.
3598 if Present (Enclosing_Subp)
3599 and then Nkind_In (Parent (C), N_Object_Declaration,
3600 N_Parameter_Specification)
3601 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3605 -- ... or the new declaration is in a package, and the visible
3606 -- declaration occurs outside that package.
3608 elsif Present (Enclosing_Pack)
3609 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3613 -- ... or the new declaration is a component declaration in a
3614 -- record type definition.
3616 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3619 -- Don't issue error for non-source entities
3621 elsif Comes_From_Source (Def_Id)
3622 and then Comes_From_Source (C)
3624 Error_Msg_Sloc := Sloc (C);
3625 Check_SPARK_Restriction
3626 ("redeclaration of identifier &#", Def_Id);
3631 -- Warn if new entity hides an old one
3633 if Warn_On_Hiding and then Present (C)
3635 -- Don't warn for record components since they always have a well
3636 -- defined scope which does not confuse other uses. Note that in
3637 -- some cases, Ekind has not been set yet.
3639 and then Ekind (C) /= E_Component
3640 and then Ekind (C) /= E_Discriminant
3641 and then Nkind (Parent (C)) /= N_Component_Declaration
3642 and then Ekind (Def_Id) /= E_Component
3643 and then Ekind (Def_Id) /= E_Discriminant
3644 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3646 -- Don't warn for one character variables. It is too common to use
3647 -- such variables as locals and will just cause too many false hits.
3649 and then Length_Of_Name (Chars (C)) /= 1
3651 -- Don't warn for non-source entities
3653 and then Comes_From_Source (C)
3654 and then Comes_From_Source (Def_Id)
3656 -- Don't warn unless entity in question is in extended main source
3658 and then In_Extended_Main_Source_Unit (Def_Id)
3660 -- Finally, the hidden entity must be either immediately visible or
3661 -- use visible (i.e. from a used package).
3664 (Is_Immediately_Visible (C)
3666 Is_Potentially_Use_Visible (C))
3668 Error_Msg_Sloc := Sloc (C);
3669 Error_Msg_N ("declaration hides &#?", Def_Id);
3673 --------------------------
3674 -- Explain_Limited_Type --
3675 --------------------------
3677 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3681 -- For array, component type must be limited
3683 if Is_Array_Type (T) then
3684 Error_Msg_Node_2 := T;
3686 ("\component type& of type& is limited", N, Component_Type (T));
3687 Explain_Limited_Type (Component_Type (T), N);
3689 elsif Is_Record_Type (T) then
3691 -- No need for extra messages if explicit limited record
3693 if Is_Limited_Record (Base_Type (T)) then
3697 -- Otherwise find a limited component. Check only components that
3698 -- come from source, or inherited components that appear in the
3699 -- source of the ancestor.
3701 C := First_Component (T);
3702 while Present (C) loop
3703 if Is_Limited_Type (Etype (C))
3705 (Comes_From_Source (C)
3707 (Present (Original_Record_Component (C))
3709 Comes_From_Source (Original_Record_Component (C))))
3711 Error_Msg_Node_2 := T;
3712 Error_Msg_NE ("\component& of type& has limited type", N, C);
3713 Explain_Limited_Type (Etype (C), N);
3720 -- The type may be declared explicitly limited, even if no component
3721 -- of it is limited, in which case we fall out of the loop.
3724 end Explain_Limited_Type;
3730 procedure Find_Actual
3732 Formal : out Entity_Id;
3735 Parnt : constant Node_Id := Parent (N);
3739 if (Nkind (Parnt) = N_Indexed_Component
3741 Nkind (Parnt) = N_Selected_Component)
3742 and then N = Prefix (Parnt)
3744 Find_Actual (Parnt, Formal, Call);
3747 elsif Nkind (Parnt) = N_Parameter_Association
3748 and then N = Explicit_Actual_Parameter (Parnt)
3750 Call := Parent (Parnt);
3752 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3761 -- If we have a call to a subprogram look for the parameter. Note that
3762 -- we exclude overloaded calls, since we don't know enough to be sure
3763 -- of giving the right answer in this case.
3765 if Is_Entity_Name (Name (Call))
3766 and then Present (Entity (Name (Call)))
3767 and then Is_Overloadable (Entity (Name (Call)))
3768 and then not Is_Overloaded (Name (Call))
3770 -- Fall here if we are definitely a parameter
3772 Actual := First_Actual (Call);
3773 Formal := First_Formal (Entity (Name (Call)));
3774 while Present (Formal) and then Present (Actual) loop
3778 Actual := Next_Actual (Actual);
3779 Formal := Next_Formal (Formal);
3784 -- Fall through here if we did not find matching actual
3790 ---------------------------
3791 -- Find_Body_Discriminal --
3792 ---------------------------
3794 function Find_Body_Discriminal
3795 (Spec_Discriminant : Entity_Id) return Entity_Id
3801 -- If expansion is suppressed, then the scope can be the concurrent type
3802 -- itself rather than a corresponding concurrent record type.
3804 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
3805 Tsk := Scope (Spec_Discriminant);
3808 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3810 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3813 -- Find discriminant of original concurrent type, and use its current
3814 -- discriminal, which is the renaming within the task/protected body.
3816 Disc := First_Discriminant (Tsk);
3817 while Present (Disc) loop
3818 if Chars (Disc) = Chars (Spec_Discriminant) then
3819 return Discriminal (Disc);
3822 Next_Discriminant (Disc);
3825 -- That loop should always succeed in finding a matching entry and
3826 -- returning. Fatal error if not.
3828 raise Program_Error;
3829 end Find_Body_Discriminal;
3831 -------------------------------------
3832 -- Find_Corresponding_Discriminant --
3833 -------------------------------------
3835 function Find_Corresponding_Discriminant
3837 Typ : Entity_Id) return Entity_Id
3839 Par_Disc : Entity_Id;
3840 Old_Disc : Entity_Id;
3841 New_Disc : Entity_Id;
3844 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3846 -- The original type may currently be private, and the discriminant
3847 -- only appear on its full view.
3849 if Is_Private_Type (Scope (Par_Disc))
3850 and then not Has_Discriminants (Scope (Par_Disc))
3851 and then Present (Full_View (Scope (Par_Disc)))
3853 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3855 Old_Disc := First_Discriminant (Scope (Par_Disc));
3858 if Is_Class_Wide_Type (Typ) then
3859 New_Disc := First_Discriminant (Root_Type (Typ));
3861 New_Disc := First_Discriminant (Typ);
3864 while Present (Old_Disc) and then Present (New_Disc) loop
3865 if Old_Disc = Par_Disc then
3868 Next_Discriminant (Old_Disc);
3869 Next_Discriminant (New_Disc);
3873 -- Should always find it
3875 raise Program_Error;
3876 end Find_Corresponding_Discriminant;
3878 --------------------------
3879 -- Find_Overlaid_Entity --
3880 --------------------------
3882 procedure Find_Overlaid_Entity
3884 Ent : out Entity_Id;
3890 -- We are looking for one of the two following forms:
3892 -- for X'Address use Y'Address
3896 -- Const : constant Address := expr;
3898 -- for X'Address use Const;
3900 -- In the second case, the expr is either Y'Address, or recursively a
3901 -- constant that eventually references Y'Address.
3906 if Nkind (N) = N_Attribute_Definition_Clause
3907 and then Chars (N) = Name_Address
3909 Expr := Expression (N);
3911 -- This loop checks the form of the expression for Y'Address,
3912 -- using recursion to deal with intermediate constants.
3915 -- Check for Y'Address
3917 if Nkind (Expr) = N_Attribute_Reference
3918 and then Attribute_Name (Expr) = Name_Address
3920 Expr := Prefix (Expr);
3923 -- Check for Const where Const is a constant entity
3925 elsif Is_Entity_Name (Expr)
3926 and then Ekind (Entity (Expr)) = E_Constant
3928 Expr := Constant_Value (Entity (Expr));
3930 -- Anything else does not need checking
3937 -- This loop checks the form of the prefix for an entity, using
3938 -- recursion to deal with intermediate components.
3941 -- Check for Y where Y is an entity
3943 if Is_Entity_Name (Expr) then
3944 Ent := Entity (Expr);
3947 -- Check for components
3950 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
3952 Expr := Prefix (Expr);
3955 -- Anything else does not need checking
3962 end Find_Overlaid_Entity;
3964 -------------------------
3965 -- Find_Parameter_Type --
3966 -------------------------
3968 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3970 if Nkind (Param) /= N_Parameter_Specification then
3973 -- For an access parameter, obtain the type from the formal entity
3974 -- itself, because access to subprogram nodes do not carry a type.
3975 -- Shouldn't we always use the formal entity ???
3977 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3978 return Etype (Defining_Identifier (Param));
3981 return Etype (Parameter_Type (Param));
3983 end Find_Parameter_Type;
3985 -----------------------------
3986 -- Find_Static_Alternative --
3987 -----------------------------
3989 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3990 Expr : constant Node_Id := Expression (N);
3991 Val : constant Uint := Expr_Value (Expr);
3996 Alt := First (Alternatives (N));
3999 if Nkind (Alt) /= N_Pragma then
4000 Choice := First (Discrete_Choices (Alt));
4001 while Present (Choice) loop
4003 -- Others choice, always matches
4005 if Nkind (Choice) = N_Others_Choice then
4008 -- Range, check if value is in the range
4010 elsif Nkind (Choice) = N_Range then
4012 Val >= Expr_Value (Low_Bound (Choice))
4014 Val <= Expr_Value (High_Bound (Choice));
4016 -- Choice is a subtype name. Note that we know it must
4017 -- be a static subtype, since otherwise it would have
4018 -- been diagnosed as illegal.
4020 elsif Is_Entity_Name (Choice)
4021 and then Is_Type (Entity (Choice))
4023 exit Search when Is_In_Range (Expr, Etype (Choice),
4024 Assume_Valid => False);
4026 -- Choice is a subtype indication
4028 elsif Nkind (Choice) = N_Subtype_Indication then
4030 C : constant Node_Id := Constraint (Choice);
4031 R : constant Node_Id := Range_Expression (C);
4035 Val >= Expr_Value (Low_Bound (R))
4037 Val <= Expr_Value (High_Bound (R));
4040 -- Choice is a simple expression
4043 exit Search when Val = Expr_Value (Choice);
4051 pragma Assert (Present (Alt));
4054 -- The above loop *must* terminate by finding a match, since
4055 -- we know the case statement is valid, and the value of the
4056 -- expression is known at compile time. When we fall out of
4057 -- the loop, Alt points to the alternative that we know will
4058 -- be selected at run time.
4061 end Find_Static_Alternative;
4067 function First_Actual (Node : Node_Id) return Node_Id is
4071 if No (Parameter_Associations (Node)) then
4075 N := First (Parameter_Associations (Node));
4077 if Nkind (N) = N_Parameter_Association then
4078 return First_Named_Actual (Node);
4084 -----------------------
4085 -- Gather_Components --
4086 -----------------------
4088 procedure Gather_Components
4090 Comp_List : Node_Id;
4091 Governed_By : List_Id;
4093 Report_Errors : out Boolean)
4097 Discrete_Choice : Node_Id;
4098 Comp_Item : Node_Id;
4100 Discrim : Entity_Id;
4101 Discrim_Name : Node_Id;
4102 Discrim_Value : Node_Id;
4105 Report_Errors := False;
4107 if No (Comp_List) or else Null_Present (Comp_List) then
4110 elsif Present (Component_Items (Comp_List)) then
4111 Comp_Item := First (Component_Items (Comp_List));
4117 while Present (Comp_Item) loop
4119 -- Skip the tag of a tagged record, the interface tags, as well
4120 -- as all items that are not user components (anonymous types,
4121 -- rep clauses, Parent field, controller field).
4123 if Nkind (Comp_Item) = N_Component_Declaration then
4125 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
4127 if not Is_Tag (Comp)
4128 and then Chars (Comp) /= Name_uParent
4130 Append_Elmt (Comp, Into);
4138 if No (Variant_Part (Comp_List)) then
4141 Discrim_Name := Name (Variant_Part (Comp_List));
4142 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
4145 -- Look for the discriminant that governs this variant part.
4146 -- The discriminant *must* be in the Governed_By List
4148 Assoc := First (Governed_By);
4149 Find_Constraint : loop
4150 Discrim := First (Choices (Assoc));
4151 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
4152 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
4154 Chars (Corresponding_Discriminant (Entity (Discrim)))
4155 = Chars (Discrim_Name))
4156 or else Chars (Original_Record_Component (Entity (Discrim)))
4157 = Chars (Discrim_Name);
4159 if No (Next (Assoc)) then
4160 if not Is_Constrained (Typ)
4161 and then Is_Derived_Type (Typ)
4162 and then Present (Stored_Constraint (Typ))
4164 -- If the type is a tagged type with inherited discriminants,
4165 -- use the stored constraint on the parent in order to find
4166 -- the values of discriminants that are otherwise hidden by an
4167 -- explicit constraint. Renamed discriminants are handled in
4170 -- If several parent discriminants are renamed by a single
4171 -- discriminant of the derived type, the call to obtain the
4172 -- Corresponding_Discriminant field only retrieves the last
4173 -- of them. We recover the constraint on the others from the
4174 -- Stored_Constraint as well.
4181 D := First_Discriminant (Etype (Typ));
4182 C := First_Elmt (Stored_Constraint (Typ));
4183 while Present (D) and then Present (C) loop
4184 if Chars (Discrim_Name) = Chars (D) then
4185 if Is_Entity_Name (Node (C))
4186 and then Entity (Node (C)) = Entity (Discrim)
4188 -- D is renamed by Discrim, whose value is given in
4195 Make_Component_Association (Sloc (Typ),
4197 (New_Occurrence_Of (D, Sloc (Typ))),
4198 Duplicate_Subexpr_No_Checks (Node (C)));
4200 exit Find_Constraint;
4203 Next_Discriminant (D);
4210 if No (Next (Assoc)) then
4211 Error_Msg_NE (" missing value for discriminant&",
4212 First (Governed_By), Discrim_Name);
4213 Report_Errors := True;
4218 end loop Find_Constraint;
4220 Discrim_Value := Expression (Assoc);
4222 if not Is_OK_Static_Expression (Discrim_Value) then
4224 ("value for discriminant & must be static!",
4225 Discrim_Value, Discrim);
4226 Why_Not_Static (Discrim_Value);
4227 Report_Errors := True;
4231 Search_For_Discriminant_Value : declare
4237 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4240 Find_Discrete_Value : while Present (Variant) loop
4241 Discrete_Choice := First (Discrete_Choices (Variant));
4242 while Present (Discrete_Choice) loop
4244 exit Find_Discrete_Value when
4245 Nkind (Discrete_Choice) = N_Others_Choice;
4247 Get_Index_Bounds (Discrete_Choice, Low, High);
4249 UI_Low := Expr_Value (Low);
4250 UI_High := Expr_Value (High);
4252 exit Find_Discrete_Value when
4253 UI_Low <= UI_Discrim_Value
4255 UI_High >= UI_Discrim_Value;
4257 Next (Discrete_Choice);
4260 Next_Non_Pragma (Variant);
4261 end loop Find_Discrete_Value;
4262 end Search_For_Discriminant_Value;
4264 if No (Variant) then
4266 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4267 Report_Errors := True;
4271 -- If we have found the corresponding choice, recursively add its
4272 -- components to the Into list.
4274 Gather_Components (Empty,
4275 Component_List (Variant), Governed_By, Into, Report_Errors);
4276 end Gather_Components;
4278 ------------------------
4279 -- Get_Actual_Subtype --
4280 ------------------------
4282 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4283 Typ : constant Entity_Id := Etype (N);
4284 Utyp : Entity_Id := Underlying_Type (Typ);
4293 -- If what we have is an identifier that references a subprogram
4294 -- formal, or a variable or constant object, then we get the actual
4295 -- subtype from the referenced entity if one has been built.
4297 if Nkind (N) = N_Identifier
4299 (Is_Formal (Entity (N))
4300 or else Ekind (Entity (N)) = E_Constant
4301 or else Ekind (Entity (N)) = E_Variable)
4302 and then Present (Actual_Subtype (Entity (N)))
4304 return Actual_Subtype (Entity (N));
4306 -- Actual subtype of unchecked union is always itself. We never need
4307 -- the "real" actual subtype. If we did, we couldn't get it anyway
4308 -- because the discriminant is not available. The restrictions on
4309 -- Unchecked_Union are designed to make sure that this is OK.
4311 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4314 -- Here for the unconstrained case, we must find actual subtype
4315 -- No actual subtype is available, so we must build it on the fly.
4317 -- Checking the type, not the underlying type, for constrainedness
4318 -- seems to be necessary. Maybe all the tests should be on the type???
4320 elsif (not Is_Constrained (Typ))
4321 and then (Is_Array_Type (Utyp)
4322 or else (Is_Record_Type (Utyp)
4323 and then Has_Discriminants (Utyp)))
4324 and then not Has_Unknown_Discriminants (Utyp)
4325 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4327 -- Nothing to do if in spec expression (why not???)
4329 if In_Spec_Expression then
4332 elsif Is_Private_Type (Typ)
4333 and then not Has_Discriminants (Typ)
4335 -- If the type has no discriminants, there is no subtype to
4336 -- build, even if the underlying type is discriminated.
4340 -- Else build the actual subtype
4343 Decl := Build_Actual_Subtype (Typ, N);
4344 Atyp := Defining_Identifier (Decl);
4346 -- If Build_Actual_Subtype generated a new declaration then use it
4350 -- The actual subtype is an Itype, so analyze the declaration,
4351 -- but do not attach it to the tree, to get the type defined.
4353 Set_Parent (Decl, N);
4354 Set_Is_Itype (Atyp);
4355 Analyze (Decl, Suppress => All_Checks);
4356 Set_Associated_Node_For_Itype (Atyp, N);
4357 Set_Has_Delayed_Freeze (Atyp, False);
4359 -- We need to freeze the actual subtype immediately. This is
4360 -- needed, because otherwise this Itype will not get frozen
4361 -- at all, and it is always safe to freeze on creation because
4362 -- any associated types must be frozen at this point.
4364 Freeze_Itype (Atyp, N);
4367 -- Otherwise we did not build a declaration, so return original
4374 -- For all remaining cases, the actual subtype is the same as
4375 -- the nominal type.
4380 end Get_Actual_Subtype;
4382 -------------------------------------
4383 -- Get_Actual_Subtype_If_Available --
4384 -------------------------------------
4386 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4387 Typ : constant Entity_Id := Etype (N);
4390 -- If what we have is an identifier that references a subprogram
4391 -- formal, or a variable or constant object, then we get the actual
4392 -- subtype from the referenced entity if one has been built.
4394 if Nkind (N) = N_Identifier
4396 (Is_Formal (Entity (N))
4397 or else Ekind (Entity (N)) = E_Constant
4398 or else Ekind (Entity (N)) = E_Variable)
4399 and then Present (Actual_Subtype (Entity (N)))
4401 return Actual_Subtype (Entity (N));
4403 -- Otherwise the Etype of N is returned unchanged
4408 end Get_Actual_Subtype_If_Available;
4410 ------------------------
4411 -- Get_Body_From_Stub --
4412 ------------------------
4414 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
4416 return Proper_Body (Unit (Library_Unit (N)));
4417 end Get_Body_From_Stub;
4419 -------------------------------
4420 -- Get_Default_External_Name --
4421 -------------------------------
4423 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4425 Get_Decoded_Name_String (Chars (E));
4427 if Opt.External_Name_Imp_Casing = Uppercase then
4428 Set_Casing (All_Upper_Case);
4430 Set_Casing (All_Lower_Case);
4434 Make_String_Literal (Sloc (E),
4435 Strval => String_From_Name_Buffer);
4436 end Get_Default_External_Name;
4438 --------------------------
4439 -- Get_Enclosing_Object --
4440 --------------------------
4442 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
4444 if Is_Entity_Name (N) then
4448 when N_Indexed_Component |
4450 N_Selected_Component =>
4452 -- If not generating code, a dereference may be left implicit.
4453 -- In thoses cases, return Empty.
4455 if Is_Access_Type (Etype (Prefix (N))) then
4458 return Get_Enclosing_Object (Prefix (N));
4461 when N_Type_Conversion =>
4462 return Get_Enclosing_Object (Expression (N));
4468 end Get_Enclosing_Object;
4470 ---------------------------
4471 -- Get_Enum_Lit_From_Pos --
4472 ---------------------------
4474 function Get_Enum_Lit_From_Pos
4477 Loc : Source_Ptr) return Node_Id
4482 -- In the case where the literal is of type Character, Wide_Character
4483 -- or Wide_Wide_Character or of a type derived from them, there needs
4484 -- to be some special handling since there is no explicit chain of
4485 -- literals to search. Instead, an N_Character_Literal node is created
4486 -- with the appropriate Char_Code and Chars fields.
4488 if Is_Standard_Character_Type (T) then
4489 Set_Character_Literal_Name (UI_To_CC (Pos));
4491 Make_Character_Literal (Loc,
4493 Char_Literal_Value => Pos);
4495 -- For all other cases, we have a complete table of literals, and
4496 -- we simply iterate through the chain of literal until the one
4497 -- with the desired position value is found.
4501 Lit := First_Literal (Base_Type (T));
4502 for J in 1 .. UI_To_Int (Pos) loop
4506 return New_Occurrence_Of (Lit, Loc);
4508 end Get_Enum_Lit_From_Pos;
4510 ---------------------------------------
4511 -- Get_Ensures_From_Test_Case_Pragma --
4512 ---------------------------------------
4514 function Get_Ensures_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4515 Args : constant List_Id := Pragma_Argument_Associations (N);
4519 if List_Length (Args) = 4 then
4520 Res := Pick (Args, 4);
4522 elsif List_Length (Args) = 3 then
4523 Res := Pick (Args, 3);
4525 if Chars (Res) /= Name_Ensures then
4534 end Get_Ensures_From_Test_Case_Pragma;
4536 ------------------------
4537 -- Get_Generic_Entity --
4538 ------------------------
4540 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4541 Ent : constant Entity_Id := Entity (Name (N));
4543 if Present (Renamed_Object (Ent)) then
4544 return Renamed_Object (Ent);
4548 end Get_Generic_Entity;
4550 ----------------------
4551 -- Get_Index_Bounds --
4552 ----------------------
4554 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4555 Kind : constant Node_Kind := Nkind (N);
4559 if Kind = N_Range then
4561 H := High_Bound (N);
4563 elsif Kind = N_Subtype_Indication then
4564 R := Range_Expression (Constraint (N));
4572 L := Low_Bound (Range_Expression (Constraint (N)));
4573 H := High_Bound (Range_Expression (Constraint (N)));
4576 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4577 if Error_Posted (Scalar_Range (Entity (N))) then
4581 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4582 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4585 L := Low_Bound (Scalar_Range (Entity (N)));
4586 H := High_Bound (Scalar_Range (Entity (N)));
4590 -- N is an expression, indicating a range with one value
4595 end Get_Index_Bounds;
4597 ----------------------------------
4598 -- Get_Library_Unit_Name_string --
4599 ----------------------------------
4601 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4602 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4605 Get_Unit_Name_String (Unit_Name_Id);
4607 -- Remove seven last character (" (spec)" or " (body)")
4609 Name_Len := Name_Len - 7;
4610 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4611 end Get_Library_Unit_Name_String;
4613 ------------------------
4614 -- Get_Name_Entity_Id --
4615 ------------------------
4617 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4619 return Entity_Id (Get_Name_Table_Info (Id));
4620 end Get_Name_Entity_Id;
4622 ------------------------------------
4623 -- Get_Name_From_Test_Case_Pragma --
4624 ------------------------------------
4626 function Get_Name_From_Test_Case_Pragma (N : Node_Id) return String_Id is
4627 Arg : constant Node_Id :=
4628 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
4630 return Strval (Expr_Value_S (Arg));
4631 end Get_Name_From_Test_Case_Pragma;
4637 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4639 return Get_Pragma_Id (Pragma_Name (N));
4642 ---------------------------
4643 -- Get_Referenced_Object --
4644 ---------------------------
4646 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4651 while Is_Entity_Name (R)
4652 and then Present (Renamed_Object (Entity (R)))
4654 R := Renamed_Object (Entity (R));
4658 end Get_Referenced_Object;
4660 ------------------------
4661 -- Get_Renamed_Entity --
4662 ------------------------
4664 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4669 while Present (Renamed_Entity (R)) loop
4670 R := Renamed_Entity (R);
4674 end Get_Renamed_Entity;
4676 ----------------------------------------
4677 -- Get_Requires_From_Test_Case_Pragma --
4678 ----------------------------------------
4680 function Get_Requires_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4681 Args : constant List_Id := Pragma_Argument_Associations (N);
4685 if List_Length (Args) >= 3 then
4686 Res := Pick (Args, 3);
4688 if Chars (Res) /= Name_Requires then
4697 end Get_Requires_From_Test_Case_Pragma;
4699 -------------------------
4700 -- Get_Subprogram_Body --
4701 -------------------------
4703 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4707 Decl := Unit_Declaration_Node (E);
4709 if Nkind (Decl) = N_Subprogram_Body then
4712 -- The below comment is bad, because it is possible for
4713 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4715 else -- Nkind (Decl) = N_Subprogram_Declaration
4717 if Present (Corresponding_Body (Decl)) then
4718 return Unit_Declaration_Node (Corresponding_Body (Decl));
4720 -- Imported subprogram case
4726 end Get_Subprogram_Body;
4728 ---------------------------
4729 -- Get_Subprogram_Entity --
4730 ---------------------------
4732 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4737 if Nkind (Nod) = N_Accept_Statement then
4738 Nam := Entry_Direct_Name (Nod);
4740 -- For an entry call, the prefix of the call is a selected component.
4741 -- Need additional code for internal calls ???
4743 elsif Nkind (Nod) = N_Entry_Call_Statement then
4744 if Nkind (Name (Nod)) = N_Selected_Component then
4745 Nam := Entity (Selector_Name (Name (Nod)));
4754 if Nkind (Nam) = N_Explicit_Dereference then
4755 Proc := Etype (Prefix (Nam));
4756 elsif Is_Entity_Name (Nam) then
4757 Proc := Entity (Nam);
4762 if Is_Object (Proc) then
4763 Proc := Etype (Proc);
4766 if Ekind (Proc) = E_Access_Subprogram_Type then
4767 Proc := Directly_Designated_Type (Proc);
4770 if not Is_Subprogram (Proc)
4771 and then Ekind (Proc) /= E_Subprogram_Type
4777 end Get_Subprogram_Entity;
4779 -----------------------------
4780 -- Get_Task_Body_Procedure --
4781 -----------------------------
4783 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4785 -- Note: A task type may be the completion of a private type with
4786 -- discriminants. When performing elaboration checks on a task
4787 -- declaration, the current view of the type may be the private one,
4788 -- and the procedure that holds the body of the task is held in its
4791 -- This is an odd function, why not have Task_Body_Procedure do
4792 -- the following digging???
4794 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4795 end Get_Task_Body_Procedure;
4797 -----------------------
4798 -- Has_Access_Values --
4799 -----------------------
4801 function Has_Access_Values (T : Entity_Id) return Boolean is
4802 Typ : constant Entity_Id := Underlying_Type (T);
4805 -- Case of a private type which is not completed yet. This can only
4806 -- happen in the case of a generic format type appearing directly, or
4807 -- as a component of the type to which this function is being applied
4808 -- at the top level. Return False in this case, since we certainly do
4809 -- not know that the type contains access types.
4814 elsif Is_Access_Type (Typ) then
4817 elsif Is_Array_Type (Typ) then
4818 return Has_Access_Values (Component_Type (Typ));
4820 elsif Is_Record_Type (Typ) then
4825 -- Loop to Check components
4827 Comp := First_Component_Or_Discriminant (Typ);
4828 while Present (Comp) loop
4830 -- Check for access component, tag field does not count, even
4831 -- though it is implemented internally using an access type.
4833 if Has_Access_Values (Etype (Comp))
4834 and then Chars (Comp) /= Name_uTag
4839 Next_Component_Or_Discriminant (Comp);
4848 end Has_Access_Values;
4850 ------------------------------
4851 -- Has_Compatible_Alignment --
4852 ------------------------------
4854 function Has_Compatible_Alignment
4856 Expr : Node_Id) return Alignment_Result
4858 function Has_Compatible_Alignment_Internal
4861 Default : Alignment_Result) return Alignment_Result;
4862 -- This is the internal recursive function that actually does the work.
4863 -- There is one additional parameter, which says what the result should
4864 -- be if no alignment information is found, and there is no definite
4865 -- indication of compatible alignments. At the outer level, this is set
4866 -- to Unknown, but for internal recursive calls in the case where types
4867 -- are known to be correct, it is set to Known_Compatible.
4869 ---------------------------------------
4870 -- Has_Compatible_Alignment_Internal --
4871 ---------------------------------------
4873 function Has_Compatible_Alignment_Internal
4876 Default : Alignment_Result) return Alignment_Result
4878 Result : Alignment_Result := Known_Compatible;
4879 -- Holds the current status of the result. Note that once a value of
4880 -- Known_Incompatible is set, it is sticky and does not get changed
4881 -- to Unknown (the value in Result only gets worse as we go along,
4884 Offs : Uint := No_Uint;
4885 -- Set to a factor of the offset from the base object when Expr is a
4886 -- selected or indexed component, based on Component_Bit_Offset and
4887 -- Component_Size respectively. A negative value is used to represent
4888 -- a value which is not known at compile time.
4890 procedure Check_Prefix;
4891 -- Checks the prefix recursively in the case where the expression
4892 -- is an indexed or selected component.
4894 procedure Set_Result (R : Alignment_Result);
4895 -- If R represents a worse outcome (unknown instead of known
4896 -- compatible, or known incompatible), then set Result to R.
4902 procedure Check_Prefix is
4904 -- The subtlety here is that in doing a recursive call to check
4905 -- the prefix, we have to decide what to do in the case where we
4906 -- don't find any specific indication of an alignment problem.
4908 -- At the outer level, we normally set Unknown as the result in
4909 -- this case, since we can only set Known_Compatible if we really
4910 -- know that the alignment value is OK, but for the recursive
4911 -- call, in the case where the types match, and we have not
4912 -- specified a peculiar alignment for the object, we are only
4913 -- concerned about suspicious rep clauses, the default case does
4914 -- not affect us, since the compiler will, in the absence of such
4915 -- rep clauses, ensure that the alignment is correct.
4917 if Default = Known_Compatible
4919 (Etype (Obj) = Etype (Expr)
4920 and then (Unknown_Alignment (Obj)
4922 Alignment (Obj) = Alignment (Etype (Obj))))
4925 (Has_Compatible_Alignment_Internal
4926 (Obj, Prefix (Expr), Known_Compatible));
4928 -- In all other cases, we need a full check on the prefix
4932 (Has_Compatible_Alignment_Internal
4933 (Obj, Prefix (Expr), Unknown));
4941 procedure Set_Result (R : Alignment_Result) is
4948 -- Start of processing for Has_Compatible_Alignment_Internal
4951 -- If Expr is a selected component, we must make sure there is no
4952 -- potentially troublesome component clause, and that the record is
4955 if Nkind (Expr) = N_Selected_Component then
4957 -- Packed record always generate unknown alignment
4959 if Is_Packed (Etype (Prefix (Expr))) then
4960 Set_Result (Unknown);
4963 -- Check prefix and component offset
4966 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4968 -- If Expr is an indexed component, we must make sure there is no
4969 -- potentially troublesome Component_Size clause and that the array
4970 -- is not bit-packed.
4972 elsif Nkind (Expr) = N_Indexed_Component then
4974 Typ : constant Entity_Id := Etype (Prefix (Expr));
4975 Ind : constant Node_Id := First_Index (Typ);
4978 -- Bit packed array always generates unknown alignment
4980 if Is_Bit_Packed_Array (Typ) then
4981 Set_Result (Unknown);
4984 -- Check prefix and component offset
4987 Offs := Component_Size (Typ);
4989 -- Small optimization: compute the full offset when possible
4992 and then Offs > Uint_0
4993 and then Present (Ind)
4994 and then Nkind (Ind) = N_Range
4995 and then Compile_Time_Known_Value (Low_Bound (Ind))
4996 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4998 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4999 - Expr_Value (Low_Bound ((Ind))));
5004 -- If we have a null offset, the result is entirely determined by
5005 -- the base object and has already been computed recursively.
5007 if Offs = Uint_0 then
5010 -- Case where we know the alignment of the object
5012 elsif Known_Alignment (Obj) then
5014 ObjA : constant Uint := Alignment (Obj);
5015 ExpA : Uint := No_Uint;
5016 SizA : Uint := No_Uint;
5019 -- If alignment of Obj is 1, then we are always OK
5022 Set_Result (Known_Compatible);
5024 -- Alignment of Obj is greater than 1, so we need to check
5027 -- If we have an offset, see if it is compatible
5029 if Offs /= No_Uint and Offs > Uint_0 then
5030 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
5031 Set_Result (Known_Incompatible);
5034 -- See if Expr is an object with known alignment
5036 elsif Is_Entity_Name (Expr)
5037 and then Known_Alignment (Entity (Expr))
5039 ExpA := Alignment (Entity (Expr));
5041 -- Otherwise, we can use the alignment of the type of
5042 -- Expr given that we already checked for
5043 -- discombobulating rep clauses for the cases of indexed
5044 -- and selected components above.
5046 elsif Known_Alignment (Etype (Expr)) then
5047 ExpA := Alignment (Etype (Expr));
5049 -- Otherwise the alignment is unknown
5052 Set_Result (Default);
5055 -- If we got an alignment, see if it is acceptable
5057 if ExpA /= No_Uint and then ExpA < ObjA then
5058 Set_Result (Known_Incompatible);
5061 -- If Expr is not a piece of a larger object, see if size
5062 -- is given. If so, check that it is not too small for the
5063 -- required alignment.
5065 if Offs /= No_Uint then
5068 -- See if Expr is an object with known size
5070 elsif Is_Entity_Name (Expr)
5071 and then Known_Static_Esize (Entity (Expr))
5073 SizA := Esize (Entity (Expr));
5075 -- Otherwise, we check the object size of the Expr type
5077 elsif Known_Static_Esize (Etype (Expr)) then
5078 SizA := Esize (Etype (Expr));
5081 -- If we got a size, see if it is a multiple of the Obj
5082 -- alignment, if not, then the alignment cannot be
5083 -- acceptable, since the size is always a multiple of the
5086 if SizA /= No_Uint then
5087 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
5088 Set_Result (Known_Incompatible);
5094 -- If we do not know required alignment, any non-zero offset is a
5095 -- potential problem (but certainly may be OK, so result is unknown).
5097 elsif Offs /= No_Uint then
5098 Set_Result (Unknown);
5100 -- If we can't find the result by direct comparison of alignment
5101 -- values, then there is still one case that we can determine known
5102 -- result, and that is when we can determine that the types are the
5103 -- same, and no alignments are specified. Then we known that the
5104 -- alignments are compatible, even if we don't know the alignment
5105 -- value in the front end.
5107 elsif Etype (Obj) = Etype (Expr) then
5109 -- Types are the same, but we have to check for possible size
5110 -- and alignments on the Expr object that may make the alignment
5111 -- different, even though the types are the same.
5113 if Is_Entity_Name (Expr) then
5115 -- First check alignment of the Expr object. Any alignment less
5116 -- than Maximum_Alignment is worrisome since this is the case
5117 -- where we do not know the alignment of Obj.
5119 if Known_Alignment (Entity (Expr))
5121 UI_To_Int (Alignment (Entity (Expr))) <
5122 Ttypes.Maximum_Alignment
5124 Set_Result (Unknown);
5126 -- Now check size of Expr object. Any size that is not an
5127 -- even multiple of Maximum_Alignment is also worrisome
5128 -- since it may cause the alignment of the object to be less
5129 -- than the alignment of the type.
5131 elsif Known_Static_Esize (Entity (Expr))
5133 (UI_To_Int (Esize (Entity (Expr))) mod
5134 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
5137 Set_Result (Unknown);
5139 -- Otherwise same type is decisive
5142 Set_Result (Known_Compatible);
5146 -- Another case to deal with is when there is an explicit size or
5147 -- alignment clause when the types are not the same. If so, then the
5148 -- result is Unknown. We don't need to do this test if the Default is
5149 -- Unknown, since that result will be set in any case.
5151 elsif Default /= Unknown
5152 and then (Has_Size_Clause (Etype (Expr))
5154 Has_Alignment_Clause (Etype (Expr)))
5156 Set_Result (Unknown);
5158 -- If no indication found, set default
5161 Set_Result (Default);
5164 -- Return worst result found
5167 end Has_Compatible_Alignment_Internal;
5169 -- Start of processing for Has_Compatible_Alignment
5172 -- If Obj has no specified alignment, then set alignment from the type
5173 -- alignment. Perhaps we should always do this, but for sure we should
5174 -- do it when there is an address clause since we can do more if the
5175 -- alignment is known.
5177 if Unknown_Alignment (Obj) then
5178 Set_Alignment (Obj, Alignment (Etype (Obj)));
5181 -- Now do the internal call that does all the work
5183 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
5184 end Has_Compatible_Alignment;
5186 ----------------------
5187 -- Has_Declarations --
5188 ----------------------
5190 function Has_Declarations (N : Node_Id) return Boolean is
5192 return Nkind_In (Nkind (N), N_Accept_Statement,
5194 N_Compilation_Unit_Aux,
5200 N_Package_Specification);
5201 end Has_Declarations;
5203 -------------------------------------------
5204 -- Has_Discriminant_Dependent_Constraint --
5205 -------------------------------------------
5207 function Has_Discriminant_Dependent_Constraint
5208 (Comp : Entity_Id) return Boolean
5210 Comp_Decl : constant Node_Id := Parent (Comp);
5211 Subt_Indic : constant Node_Id :=
5212 Subtype_Indication (Component_Definition (Comp_Decl));
5217 if Nkind (Subt_Indic) = N_Subtype_Indication then
5218 Constr := Constraint (Subt_Indic);
5220 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
5221 Assn := First (Constraints (Constr));
5222 while Present (Assn) loop
5223 case Nkind (Assn) is
5224 when N_Subtype_Indication |
5228 if Depends_On_Discriminant (Assn) then
5232 when N_Discriminant_Association =>
5233 if Depends_On_Discriminant (Expression (Assn)) then
5248 end Has_Discriminant_Dependent_Constraint;
5250 --------------------
5251 -- Has_Infinities --
5252 --------------------
5254 function Has_Infinities (E : Entity_Id) return Boolean is
5257 Is_Floating_Point_Type (E)
5258 and then Nkind (Scalar_Range (E)) = N_Range
5259 and then Includes_Infinities (Scalar_Range (E));
5262 --------------------
5263 -- Has_Interfaces --
5264 --------------------
5266 function Has_Interfaces
5268 Use_Full_View : Boolean := True) return Boolean
5270 Typ : Entity_Id := Base_Type (T);
5273 -- Handle concurrent types
5275 if Is_Concurrent_Type (Typ) then
5276 Typ := Corresponding_Record_Type (Typ);
5279 if not Present (Typ)
5280 or else not Is_Record_Type (Typ)
5281 or else not Is_Tagged_Type (Typ)
5286 -- Handle private types
5289 and then Present (Full_View (Typ))
5291 Typ := Full_View (Typ);
5294 -- Handle concurrent record types
5296 if Is_Concurrent_Record_Type (Typ)
5297 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
5303 if Is_Interface (Typ)
5305 (Is_Record_Type (Typ)
5306 and then Present (Interfaces (Typ))
5307 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
5312 exit when Etype (Typ) = Typ
5314 -- Handle private types
5316 or else (Present (Full_View (Etype (Typ)))
5317 and then Full_View (Etype (Typ)) = Typ)
5319 -- Protect the frontend against wrong source with cyclic
5322 or else Etype (Typ) = T;
5324 -- Climb to the ancestor type handling private types
5326 if Present (Full_View (Etype (Typ))) then
5327 Typ := Full_View (Etype (Typ));
5336 ------------------------
5337 -- Has_Null_Exclusion --
5338 ------------------------
5340 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5343 when N_Access_Definition |
5344 N_Access_Function_Definition |
5345 N_Access_Procedure_Definition |
5346 N_Access_To_Object_Definition |
5348 N_Derived_Type_Definition |
5349 N_Function_Specification |
5350 N_Subtype_Declaration =>
5351 return Null_Exclusion_Present (N);
5353 when N_Component_Definition |
5354 N_Formal_Object_Declaration |
5355 N_Object_Renaming_Declaration =>
5356 if Present (Subtype_Mark (N)) then
5357 return Null_Exclusion_Present (N);
5358 else pragma Assert (Present (Access_Definition (N)));
5359 return Null_Exclusion_Present (Access_Definition (N));
5362 when N_Discriminant_Specification =>
5363 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5364 return Null_Exclusion_Present (Discriminant_Type (N));
5366 return Null_Exclusion_Present (N);
5369 when N_Object_Declaration =>
5370 if Nkind (Object_Definition (N)) = N_Access_Definition then
5371 return Null_Exclusion_Present (Object_Definition (N));
5373 return Null_Exclusion_Present (N);
5376 when N_Parameter_Specification =>
5377 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5378 return Null_Exclusion_Present (Parameter_Type (N));
5380 return Null_Exclusion_Present (N);
5387 end Has_Null_Exclusion;
5389 ------------------------
5390 -- Has_Null_Extension --
5391 ------------------------
5393 function Has_Null_Extension (T : Entity_Id) return Boolean is
5394 B : constant Entity_Id := Base_Type (T);
5399 if Nkind (Parent (B)) = N_Full_Type_Declaration
5400 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5402 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5404 if Present (Ext) then
5405 if Null_Present (Ext) then
5408 Comps := Component_List (Ext);
5410 -- The null component list is rewritten during analysis to
5411 -- include the parent component. Any other component indicates
5412 -- that the extension was not originally null.
5414 return Null_Present (Comps)
5415 or else No (Next (First (Component_Items (Comps))));
5424 end Has_Null_Extension;
5426 -------------------------------
5427 -- Has_Overriding_Initialize --
5428 -------------------------------
5430 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5431 BT : constant Entity_Id := Base_Type (T);
5435 if Is_Controlled (BT) then
5436 if Is_RTU (Scope (BT), Ada_Finalization) then
5439 elsif Present (Primitive_Operations (BT)) then
5440 P := First_Elmt (Primitive_Operations (BT));
5441 while Present (P) loop
5443 Init : constant Entity_Id := Node (P);
5444 Formal : constant Entity_Id := First_Formal (Init);
5446 if Ekind (Init) = E_Procedure
5447 and then Chars (Init) = Name_Initialize
5448 and then Comes_From_Source (Init)
5449 and then Present (Formal)
5450 and then Etype (Formal) = BT
5451 and then No (Next_Formal (Formal))
5452 and then (Ada_Version < Ada_2012
5453 or else not Null_Present (Parent (Init)))
5463 -- Here if type itself does not have a non-null Initialize operation:
5464 -- check immediate ancestor.
5466 if Is_Derived_Type (BT)
5467 and then Has_Overriding_Initialize (Etype (BT))
5474 end Has_Overriding_Initialize;
5476 --------------------------------------
5477 -- Has_Preelaborable_Initialization --
5478 --------------------------------------
5480 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5483 procedure Check_Components (E : Entity_Id);
5484 -- Check component/discriminant chain, sets Has_PE False if a component
5485 -- or discriminant does not meet the preelaborable initialization rules.
5487 ----------------------
5488 -- Check_Components --
5489 ----------------------
5491 procedure Check_Components (E : Entity_Id) is
5495 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5496 -- Returns True if and only if the expression denoted by N does not
5497 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5499 ---------------------------------
5500 -- Is_Preelaborable_Expression --
5501 ---------------------------------
5503 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5507 Comp_Type : Entity_Id;
5508 Is_Array_Aggr : Boolean;
5511 if Is_Static_Expression (N) then
5514 elsif Nkind (N) = N_Null then
5517 -- Attributes are allowed in general, even if their prefix is a
5518 -- formal type. (It seems that certain attributes known not to be
5519 -- static might not be allowed, but there are no rules to prevent
5522 elsif Nkind (N) = N_Attribute_Reference then
5525 -- The name of a discriminant evaluated within its parent type is
5526 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5527 -- names that denote discriminals as well as discriminants to
5528 -- catch references occurring within init procs.
5530 elsif Is_Entity_Name (N)
5532 (Ekind (Entity (N)) = E_Discriminant
5534 ((Ekind (Entity (N)) = E_Constant
5535 or else Ekind (Entity (N)) = E_In_Parameter)
5536 and then Present (Discriminal_Link (Entity (N)))))
5540 elsif Nkind (N) = N_Qualified_Expression then
5541 return Is_Preelaborable_Expression (Expression (N));
5543 -- For aggregates we have to check that each of the associations
5544 -- is preelaborable.
5546 elsif Nkind (N) = N_Aggregate
5547 or else Nkind (N) = N_Extension_Aggregate
5549 Is_Array_Aggr := Is_Array_Type (Etype (N));
5551 if Is_Array_Aggr then
5552 Comp_Type := Component_Type (Etype (N));
5555 -- Check the ancestor part of extension aggregates, which must
5556 -- be either the name of a type that has preelaborable init or
5557 -- an expression that is preelaborable.
5559 if Nkind (N) = N_Extension_Aggregate then
5561 Anc_Part : constant Node_Id := Ancestor_Part (N);
5564 if Is_Entity_Name (Anc_Part)
5565 and then Is_Type (Entity (Anc_Part))
5567 if not Has_Preelaborable_Initialization
5573 elsif not Is_Preelaborable_Expression (Anc_Part) then
5579 -- Check positional associations
5581 Exp := First (Expressions (N));
5582 while Present (Exp) loop
5583 if not Is_Preelaborable_Expression (Exp) then
5590 -- Check named associations
5592 Assn := First (Component_Associations (N));
5593 while Present (Assn) loop
5594 Choice := First (Choices (Assn));
5595 while Present (Choice) loop
5596 if Is_Array_Aggr then
5597 if Nkind (Choice) = N_Others_Choice then
5600 elsif Nkind (Choice) = N_Range then
5601 if not Is_Static_Range (Choice) then
5605 elsif not Is_Static_Expression (Choice) then
5610 Comp_Type := Etype (Choice);
5616 -- If the association has a <> at this point, then we have
5617 -- to check whether the component's type has preelaborable
5618 -- initialization. Note that this only occurs when the
5619 -- association's corresponding component does not have a
5620 -- default expression, the latter case having already been
5621 -- expanded as an expression for the association.
5623 if Box_Present (Assn) then
5624 if not Has_Preelaborable_Initialization (Comp_Type) then
5628 -- In the expression case we check whether the expression
5629 -- is preelaborable.
5632 not Is_Preelaborable_Expression (Expression (Assn))
5640 -- If we get here then aggregate as a whole is preelaborable
5644 -- All other cases are not preelaborable
5649 end Is_Preelaborable_Expression;
5651 -- Start of processing for Check_Components
5654 -- Loop through entities of record or protected type
5657 while Present (Ent) loop
5659 -- We are interested only in components and discriminants
5666 -- Get default expression if any. If there is no declaration
5667 -- node, it means we have an internal entity. The parent and
5668 -- tag fields are examples of such entities. For such cases,
5669 -- we just test the type of the entity.
5671 if Present (Declaration_Node (Ent)) then
5672 Exp := Expression (Declaration_Node (Ent));
5675 when E_Discriminant =>
5677 -- Note: for a renamed discriminant, the Declaration_Node
5678 -- may point to the one from the ancestor, and have a
5679 -- different expression, so use the proper attribute to
5680 -- retrieve the expression from the derived constraint.
5682 Exp := Discriminant_Default_Value (Ent);
5685 goto Check_Next_Entity;
5688 -- A component has PI if it has no default expression and the
5689 -- component type has PI.
5692 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5697 -- Require the default expression to be preelaborable
5699 elsif not Is_Preelaborable_Expression (Exp) then
5704 <<Check_Next_Entity>>
5707 end Check_Components;
5709 -- Start of processing for Has_Preelaborable_Initialization
5712 -- Immediate return if already marked as known preelaborable init. This
5713 -- covers types for which this function has already been called once
5714 -- and returned True (in which case the result is cached), and also
5715 -- types to which a pragma Preelaborable_Initialization applies.
5717 if Known_To_Have_Preelab_Init (E) then
5721 -- If the type is a subtype representing a generic actual type, then
5722 -- test whether its base type has preelaborable initialization since
5723 -- the subtype representing the actual does not inherit this attribute
5724 -- from the actual or formal. (but maybe it should???)
5726 if Is_Generic_Actual_Type (E) then
5727 return Has_Preelaborable_Initialization (Base_Type (E));
5730 -- All elementary types have preelaborable initialization
5732 if Is_Elementary_Type (E) then
5735 -- Array types have PI if the component type has PI
5737 elsif Is_Array_Type (E) then
5738 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5740 -- A derived type has preelaborable initialization if its parent type
5741 -- has preelaborable initialization and (in the case of a derived record
5742 -- extension) if the non-inherited components all have preelaborable
5743 -- initialization. However, a user-defined controlled type with an
5744 -- overriding Initialize procedure does not have preelaborable
5747 elsif Is_Derived_Type (E) then
5749 -- If the derived type is a private extension then it doesn't have
5750 -- preelaborable initialization.
5752 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5756 -- First check whether ancestor type has preelaborable initialization
5758 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5760 -- If OK, check extension components (if any)
5762 if Has_PE and then Is_Record_Type (E) then
5763 Check_Components (First_Entity (E));
5766 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5767 -- with a user defined Initialize procedure does not have PI.
5770 and then Is_Controlled (E)
5771 and then Has_Overriding_Initialize (E)
5776 -- Private types not derived from a type having preelaborable init and
5777 -- that are not marked with pragma Preelaborable_Initialization do not
5778 -- have preelaborable initialization.
5780 elsif Is_Private_Type (E) then
5783 -- Record type has PI if it is non private and all components have PI
5785 elsif Is_Record_Type (E) then
5787 Check_Components (First_Entity (E));
5789 -- Protected types must not have entries, and components must meet
5790 -- same set of rules as for record components.
5792 elsif Is_Protected_Type (E) then
5793 if Has_Entries (E) then
5797 Check_Components (First_Entity (E));
5798 Check_Components (First_Private_Entity (E));
5801 -- Type System.Address always has preelaborable initialization
5803 elsif Is_RTE (E, RE_Address) then
5806 -- In all other cases, type does not have preelaborable initialization
5812 -- If type has preelaborable initialization, cache result
5815 Set_Known_To_Have_Preelab_Init (E);
5819 end Has_Preelaborable_Initialization;
5821 ---------------------------
5822 -- Has_Private_Component --
5823 ---------------------------
5825 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5826 Btype : Entity_Id := Base_Type (Type_Id);
5827 Component : Entity_Id;
5830 if Error_Posted (Type_Id)
5831 or else Error_Posted (Btype)
5836 if Is_Class_Wide_Type (Btype) then
5837 Btype := Root_Type (Btype);
5840 if Is_Private_Type (Btype) then
5842 UT : constant Entity_Id := Underlying_Type (Btype);
5845 if No (Full_View (Btype)) then
5846 return not Is_Generic_Type (Btype)
5847 and then not Is_Generic_Type (Root_Type (Btype));
5849 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5852 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5856 elsif Is_Array_Type (Btype) then
5857 return Has_Private_Component (Component_Type (Btype));
5859 elsif Is_Record_Type (Btype) then
5860 Component := First_Component (Btype);
5861 while Present (Component) loop
5862 if Has_Private_Component (Etype (Component)) then
5866 Next_Component (Component);
5871 elsif Is_Protected_Type (Btype)
5872 and then Present (Corresponding_Record_Type (Btype))
5874 return Has_Private_Component (Corresponding_Record_Type (Btype));
5879 end Has_Private_Component;
5881 -----------------------------
5882 -- Has_Static_Array_Bounds --
5883 -----------------------------
5885 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5886 Ndims : constant Nat := Number_Dimensions (Typ);
5893 -- Unconstrained types do not have static bounds
5895 if not Is_Constrained (Typ) then
5899 -- First treat string literals specially, as the lower bound and length
5900 -- of string literals are not stored like those of arrays.
5902 -- A string literal always has static bounds
5904 if Ekind (Typ) = E_String_Literal_Subtype then
5908 -- Treat all dimensions in turn
5910 Index := First_Index (Typ);
5911 for Indx in 1 .. Ndims loop
5913 -- In case of an erroneous index which is not a discrete type, return
5914 -- that the type is not static.
5916 if not Is_Discrete_Type (Etype (Index))
5917 or else Etype (Index) = Any_Type
5922 Get_Index_Bounds (Index, Low, High);
5924 if Error_Posted (Low) or else Error_Posted (High) then
5928 if Is_OK_Static_Expression (Low)
5930 Is_OK_Static_Expression (High)
5940 -- If we fall through the loop, all indexes matched
5943 end Has_Static_Array_Bounds;
5949 function Has_Stream (T : Entity_Id) return Boolean is
5956 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5959 elsif Is_Array_Type (T) then
5960 return Has_Stream (Component_Type (T));
5962 elsif Is_Record_Type (T) then
5963 E := First_Component (T);
5964 while Present (E) loop
5965 if Has_Stream (Etype (E)) then
5974 elsif Is_Private_Type (T) then
5975 return Has_Stream (Underlying_Type (T));
5986 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5988 Get_Name_String (Chars (E));
5989 return Name_Buffer (Name_Len) = Suffix;
5996 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
5998 Get_Name_String (Chars (E));
5999 Add_Char_To_Name_Buffer (Suffix);
6007 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
6009 pragma Assert (Has_Suffix (E, Suffix));
6010 Get_Name_String (Chars (E));
6011 Name_Len := Name_Len - 1;
6015 --------------------------
6016 -- Has_Tagged_Component --
6017 --------------------------
6019 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
6023 if Is_Private_Type (Typ)
6024 and then Present (Underlying_Type (Typ))
6026 return Has_Tagged_Component (Underlying_Type (Typ));
6028 elsif Is_Array_Type (Typ) then
6029 return Has_Tagged_Component (Component_Type (Typ));
6031 elsif Is_Tagged_Type (Typ) then
6034 elsif Is_Record_Type (Typ) then
6035 Comp := First_Component (Typ);
6036 while Present (Comp) loop
6037 if Has_Tagged_Component (Etype (Comp)) then
6041 Next_Component (Comp);
6049 end Has_Tagged_Component;
6051 -------------------------
6052 -- Implementation_Kind --
6053 -------------------------
6055 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
6056 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
6058 pragma Assert (Present (Impl_Prag));
6060 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
6061 end Implementation_Kind;
6063 --------------------------
6064 -- Implements_Interface --
6065 --------------------------
6067 function Implements_Interface
6068 (Typ_Ent : Entity_Id;
6069 Iface_Ent : Entity_Id;
6070 Exclude_Parents : Boolean := False) return Boolean
6072 Ifaces_List : Elist_Id;
6074 Iface : Entity_Id := Base_Type (Iface_Ent);
6075 Typ : Entity_Id := Base_Type (Typ_Ent);
6078 if Is_Class_Wide_Type (Typ) then
6079 Typ := Root_Type (Typ);
6082 if not Has_Interfaces (Typ) then
6086 if Is_Class_Wide_Type (Iface) then
6087 Iface := Root_Type (Iface);
6090 Collect_Interfaces (Typ, Ifaces_List);
6092 Elmt := First_Elmt (Ifaces_List);
6093 while Present (Elmt) loop
6094 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
6095 and then Exclude_Parents
6099 elsif Node (Elmt) = Iface then
6107 end Implements_Interface;
6109 ---------------------
6110 -- In_Generic_Body --
6111 ---------------------
6113 function In_Generic_Body (Id : Entity_Id) return Boolean is
6114 S : Entity_Id := Id;
6117 while Present (S) and then S /= Standard_Standard loop
6119 -- Generic package body
6121 if Ekind (S) = E_Generic_Package
6122 and then In_Package_Body (S)
6126 -- Generic subprogram body
6128 elsif Is_Subprogram (S)
6129 and then Nkind (Unit_Declaration_Node (S))
6130 = N_Generic_Subprogram_Declaration
6139 end In_Generic_Body;
6145 function In_Instance return Boolean is
6146 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6152 and then S /= Standard_Standard
6154 if (Ekind (S) = E_Function
6155 or else Ekind (S) = E_Package
6156 or else Ekind (S) = E_Procedure)
6157 and then Is_Generic_Instance (S)
6159 -- A child instance is always compiled in the context of a parent
6160 -- instance. Nevertheless, the actuals are not analyzed in an
6161 -- instance context. We detect this case by examining the current
6162 -- compilation unit, which must be a child instance, and checking
6163 -- that it is not currently on the scope stack.
6165 if Is_Child_Unit (Curr_Unit)
6167 Nkind (Unit (Cunit (Current_Sem_Unit)))
6168 = N_Package_Instantiation
6169 and then not In_Open_Scopes (Curr_Unit)
6183 ----------------------
6184 -- In_Instance_Body --
6185 ----------------------
6187 function In_Instance_Body return Boolean is
6193 and then S /= Standard_Standard
6195 if (Ekind (S) = E_Function
6196 or else Ekind (S) = E_Procedure)
6197 and then Is_Generic_Instance (S)
6201 elsif Ekind (S) = E_Package
6202 and then In_Package_Body (S)
6203 and then Is_Generic_Instance (S)
6212 end In_Instance_Body;
6214 -----------------------------
6215 -- In_Instance_Not_Visible --
6216 -----------------------------
6218 function In_Instance_Not_Visible return Boolean is
6224 and then S /= Standard_Standard
6226 if (Ekind (S) = E_Function
6227 or else Ekind (S) = E_Procedure)
6228 and then Is_Generic_Instance (S)
6232 elsif Ekind (S) = E_Package
6233 and then (In_Package_Body (S) or else In_Private_Part (S))
6234 and then Is_Generic_Instance (S)
6243 end In_Instance_Not_Visible;
6245 ------------------------------
6246 -- In_Instance_Visible_Part --
6247 ------------------------------
6249 function In_Instance_Visible_Part return Boolean is
6255 and then S /= Standard_Standard
6257 if Ekind (S) = E_Package
6258 and then Is_Generic_Instance (S)
6259 and then not In_Package_Body (S)
6260 and then not In_Private_Part (S)
6269 end In_Instance_Visible_Part;
6271 ---------------------
6272 -- In_Package_Body --
6273 ---------------------
6275 function In_Package_Body return Boolean is
6281 and then S /= Standard_Standard
6283 if Ekind (S) = E_Package
6284 and then In_Package_Body (S)
6293 end In_Package_Body;
6295 --------------------------------
6296 -- In_Parameter_Specification --
6297 --------------------------------
6299 function In_Parameter_Specification (N : Node_Id) return Boolean is
6304 while Present (PN) loop
6305 if Nkind (PN) = N_Parameter_Specification then
6313 end In_Parameter_Specification;
6315 --------------------------------------
6316 -- In_Subprogram_Or_Concurrent_Unit --
6317 --------------------------------------
6319 function In_Subprogram_Or_Concurrent_Unit return Boolean is
6324 -- Use scope chain to check successively outer scopes
6330 if K in Subprogram_Kind
6331 or else K in Concurrent_Kind
6332 or else K in Generic_Subprogram_Kind
6336 elsif E = Standard_Standard then
6342 end In_Subprogram_Or_Concurrent_Unit;
6344 ---------------------
6345 -- In_Visible_Part --
6346 ---------------------
6348 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
6351 Is_Package_Or_Generic_Package (Scope_Id)
6352 and then In_Open_Scopes (Scope_Id)
6353 and then not In_Package_Body (Scope_Id)
6354 and then not In_Private_Part (Scope_Id);
6355 end In_Visible_Part;
6357 --------------------------------
6358 -- Incomplete_Or_Private_View --
6359 --------------------------------
6361 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
6362 function Inspect_Decls
6364 Taft : Boolean := False) return Entity_Id;
6365 -- Check whether a declarative region contains the incomplete or private
6372 function Inspect_Decls
6374 Taft : Boolean := False) return Entity_Id
6380 Decl := First (Decls);
6381 while Present (Decl) loop
6385 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6386 Match := Defining_Identifier (Decl);
6390 if Nkind_In (Decl, N_Private_Extension_Declaration,
6391 N_Private_Type_Declaration)
6393 Match := Defining_Identifier (Decl);
6398 and then Present (Full_View (Match))
6399 and then Full_View (Match) = Typ
6414 -- Start of processing for Incomplete_Or_Partial_View
6417 -- Incomplete type case
6419 Prev := Current_Entity_In_Scope (Typ);
6422 and then Is_Incomplete_Type (Prev)
6423 and then Present (Full_View (Prev))
6424 and then Full_View (Prev) = Typ
6429 -- Private or Taft amendment type case
6432 Pkg : constant Entity_Id := Scope (Typ);
6433 Pkg_Decl : Node_Id := Pkg;
6436 if Ekind (Pkg) = E_Package then
6437 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6438 Pkg_Decl := Parent (Pkg_Decl);
6441 -- It is knows that Typ has a private view, look for it in the
6442 -- visible declarations of the enclosing scope. A special case
6443 -- of this is when the two views have been exchanged - the full
6444 -- appears earlier than the private.
6446 if Has_Private_Declaration (Typ) then
6447 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6449 -- Exchanged view case, look in the private declarations
6452 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6457 -- Otherwise if this is the package body, then Typ is a potential
6458 -- Taft amendment type. The incomplete view should be located in
6459 -- the private declarations of the enclosing scope.
6461 elsif In_Package_Body (Pkg) then
6462 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6467 -- The type has no incomplete or private view
6470 end Incomplete_Or_Private_View;
6472 ---------------------------------
6473 -- Insert_Explicit_Dereference --
6474 ---------------------------------
6476 procedure Insert_Explicit_Dereference (N : Node_Id) is
6477 New_Prefix : constant Node_Id := Relocate_Node (N);
6478 Ent : Entity_Id := Empty;
6485 Save_Interps (N, New_Prefix);
6488 Make_Explicit_Dereference (Sloc (Parent (N)),
6489 Prefix => New_Prefix));
6491 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6493 if Is_Overloaded (New_Prefix) then
6495 -- The dereference is also overloaded, and its interpretations are
6496 -- the designated types of the interpretations of the original node.
6498 Set_Etype (N, Any_Type);
6500 Get_First_Interp (New_Prefix, I, It);
6501 while Present (It.Nam) loop
6504 if Is_Access_Type (T) then
6505 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6508 Get_Next_Interp (I, It);
6514 -- Prefix is unambiguous: mark the original prefix (which might
6515 -- Come_From_Source) as a reference, since the new (relocated) one
6516 -- won't be taken into account.
6518 if Is_Entity_Name (New_Prefix) then
6519 Ent := Entity (New_Prefix);
6522 -- For a retrieval of a subcomponent of some composite object,
6523 -- retrieve the ultimate entity if there is one.
6525 elsif Nkind (New_Prefix) = N_Selected_Component
6526 or else Nkind (New_Prefix) = N_Indexed_Component
6528 Pref := Prefix (New_Prefix);
6529 while Present (Pref)
6531 (Nkind (Pref) = N_Selected_Component
6532 or else Nkind (Pref) = N_Indexed_Component)
6534 Pref := Prefix (Pref);
6537 if Present (Pref) and then Is_Entity_Name (Pref) then
6538 Ent := Entity (Pref);
6542 -- Place the reference on the entity node
6544 if Present (Ent) then
6545 Generate_Reference (Ent, Pref);
6548 end Insert_Explicit_Dereference;
6550 ------------------------------------------
6551 -- Inspect_Deferred_Constant_Completion --
6552 ------------------------------------------
6554 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6558 Decl := First (Decls);
6559 while Present (Decl) loop
6561 -- Deferred constant signature
6563 if Nkind (Decl) = N_Object_Declaration
6564 and then Constant_Present (Decl)
6565 and then No (Expression (Decl))
6567 -- No need to check internally generated constants
6569 and then Comes_From_Source (Decl)
6571 -- The constant is not completed. A full object declaration or a
6572 -- pragma Import complete a deferred constant.
6574 and then not Has_Completion (Defining_Identifier (Decl))
6577 ("constant declaration requires initialization expression",
6578 Defining_Identifier (Decl));
6581 Decl := Next (Decl);
6583 end Inspect_Deferred_Constant_Completion;
6585 -----------------------------
6586 -- Is_Actual_Out_Parameter --
6587 -----------------------------
6589 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6593 Find_Actual (N, Formal, Call);
6594 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6595 end Is_Actual_Out_Parameter;
6597 -------------------------
6598 -- Is_Actual_Parameter --
6599 -------------------------
6601 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6602 PK : constant Node_Kind := Nkind (Parent (N));
6606 when N_Parameter_Association =>
6607 return N = Explicit_Actual_Parameter (Parent (N));
6609 when N_Function_Call | N_Procedure_Call_Statement =>
6610 return Is_List_Member (N)
6612 List_Containing (N) = Parameter_Associations (Parent (N));
6617 end Is_Actual_Parameter;
6619 --------------------------------
6620 -- Is_Actual_Tagged_Parameter --
6621 --------------------------------
6623 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6627 Find_Actual (N, Formal, Call);
6628 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6629 end Is_Actual_Tagged_Parameter;
6631 ---------------------
6632 -- Is_Aliased_View --
6633 ---------------------
6635 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6639 if Is_Entity_Name (Obj) then
6646 or else (Present (Renamed_Object (E))
6647 and then Is_Aliased_View (Renamed_Object (E)))))
6649 or else ((Is_Formal (E)
6650 or else Ekind (E) = E_Generic_In_Out_Parameter
6651 or else Ekind (E) = E_Generic_In_Parameter)
6652 and then Is_Tagged_Type (Etype (E)))
6654 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
6656 -- Current instance of type, either directly or as rewritten
6657 -- reference to the current object.
6659 or else (Is_Entity_Name (Original_Node (Obj))
6660 and then Present (Entity (Original_Node (Obj)))
6661 and then Is_Type (Entity (Original_Node (Obj))))
6663 or else (Is_Type (E) and then E = Current_Scope)
6665 or else (Is_Incomplete_Or_Private_Type (E)
6666 and then Full_View (E) = Current_Scope)
6668 -- Ada 2012 AI05-0053: the return object of an extended return
6669 -- statement is aliased if its type is immutably limited.
6671 or else (Is_Return_Object (E)
6672 and then Is_Immutably_Limited_Type (Etype (E)));
6674 elsif Nkind (Obj) = N_Selected_Component then
6675 return Is_Aliased (Entity (Selector_Name (Obj)));
6677 elsif Nkind (Obj) = N_Indexed_Component then
6678 return Has_Aliased_Components (Etype (Prefix (Obj)))
6680 (Is_Access_Type (Etype (Prefix (Obj)))
6681 and then Has_Aliased_Components
6682 (Designated_Type (Etype (Prefix (Obj)))));
6684 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
6685 return Is_Tagged_Type (Etype (Obj))
6686 and then Is_Aliased_View (Expression (Obj));
6688 elsif Nkind (Obj) = N_Explicit_Dereference then
6689 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6694 end Is_Aliased_View;
6696 -------------------------
6697 -- Is_Ancestor_Package --
6698 -------------------------
6700 function Is_Ancestor_Package
6702 E2 : Entity_Id) return Boolean
6709 and then Par /= Standard_Standard
6719 end Is_Ancestor_Package;
6721 ----------------------
6722 -- Is_Atomic_Object --
6723 ----------------------
6725 function Is_Atomic_Object (N : Node_Id) return Boolean is
6727 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6728 -- Determines if given object has atomic components
6730 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6731 -- If prefix is an implicit dereference, examine designated type
6733 ----------------------
6734 -- Is_Atomic_Prefix --
6735 ----------------------
6737 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6739 if Is_Access_Type (Etype (N)) then
6741 Has_Atomic_Components (Designated_Type (Etype (N)));
6743 return Object_Has_Atomic_Components (N);
6745 end Is_Atomic_Prefix;
6747 ----------------------------------
6748 -- Object_Has_Atomic_Components --
6749 ----------------------------------
6751 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6753 if Has_Atomic_Components (Etype (N))
6754 or else Is_Atomic (Etype (N))
6758 elsif Is_Entity_Name (N)
6759 and then (Has_Atomic_Components (Entity (N))
6760 or else Is_Atomic (Entity (N)))
6764 elsif Nkind (N) = N_Indexed_Component
6765 or else Nkind (N) = N_Selected_Component
6767 return Is_Atomic_Prefix (Prefix (N));
6772 end Object_Has_Atomic_Components;
6774 -- Start of processing for Is_Atomic_Object
6777 -- Predicate is not relevant to subprograms
6779 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6782 elsif Is_Atomic (Etype (N))
6783 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6787 elsif Nkind (N) = N_Indexed_Component
6788 or else Nkind (N) = N_Selected_Component
6790 return Is_Atomic_Prefix (Prefix (N));
6795 end Is_Atomic_Object;
6797 -----------------------------
6798 -- Is_Concurrent_Interface --
6799 -----------------------------
6801 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6806 (Is_Protected_Interface (T)
6807 or else Is_Synchronized_Interface (T)
6808 or else Is_Task_Interface (T));
6809 end Is_Concurrent_Interface;
6811 --------------------------------------
6812 -- Is_Controlling_Limited_Procedure --
6813 --------------------------------------
6815 function Is_Controlling_Limited_Procedure
6816 (Proc_Nam : Entity_Id) return Boolean
6818 Param_Typ : Entity_Id := Empty;
6821 if Ekind (Proc_Nam) = E_Procedure
6822 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6824 Param_Typ := Etype (Parameter_Type (First (
6825 Parameter_Specifications (Parent (Proc_Nam)))));
6827 -- In this case where an Itype was created, the procedure call has been
6830 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6831 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6833 Present (Parameter_Associations
6834 (Associated_Node_For_Itype (Proc_Nam)))
6837 Etype (First (Parameter_Associations
6838 (Associated_Node_For_Itype (Proc_Nam))));
6841 if Present (Param_Typ) then
6843 Is_Interface (Param_Typ)
6844 and then Is_Limited_Record (Param_Typ);
6848 end Is_Controlling_Limited_Procedure;
6850 -----------------------------
6851 -- Is_CPP_Constructor_Call --
6852 -----------------------------
6854 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6856 return Nkind (N) = N_Function_Call
6857 and then Is_CPP_Class (Etype (Etype (N)))
6858 and then Is_Constructor (Entity (Name (N)))
6859 and then Is_Imported (Entity (Name (N)));
6860 end Is_CPP_Constructor_Call;
6866 function Is_Delegate (T : Entity_Id) return Boolean is
6867 Desig_Type : Entity_Id;
6870 if VM_Target /= CLI_Target then
6874 -- Access-to-subprograms are delegates in CIL
6876 if Ekind (T) = E_Access_Subprogram_Type then
6880 if Ekind (T) not in Access_Kind then
6882 -- A delegate is a managed pointer. If no designated type is defined
6883 -- it means that it's not a delegate.
6888 Desig_Type := Etype (Directly_Designated_Type (T));
6890 if not Is_Tagged_Type (Desig_Type) then
6894 -- Test if the type is inherited from [mscorlib]System.Delegate
6896 while Etype (Desig_Type) /= Desig_Type loop
6897 if Chars (Scope (Desig_Type)) /= No_Name
6898 and then Is_Imported (Scope (Desig_Type))
6899 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6904 Desig_Type := Etype (Desig_Type);
6910 ----------------------------------------------
6911 -- Is_Dependent_Component_Of_Mutable_Object --
6912 ----------------------------------------------
6914 function Is_Dependent_Component_Of_Mutable_Object
6915 (Object : Node_Id) return Boolean
6918 Prefix_Type : Entity_Id;
6919 P_Aliased : Boolean := False;
6922 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6923 -- Returns True if and only if Comp is declared within a variant part
6925 --------------------------------
6926 -- Is_Declared_Within_Variant --
6927 --------------------------------
6929 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6930 Comp_Decl : constant Node_Id := Parent (Comp);
6931 Comp_List : constant Node_Id := Parent (Comp_Decl);
6933 return Nkind (Parent (Comp_List)) = N_Variant;
6934 end Is_Declared_Within_Variant;
6936 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6939 if Is_Variable (Object) then
6941 if Nkind (Object) = N_Selected_Component then
6942 P := Prefix (Object);
6943 Prefix_Type := Etype (P);
6945 if Is_Entity_Name (P) then
6947 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6948 Prefix_Type := Base_Type (Prefix_Type);
6951 if Is_Aliased (Entity (P)) then
6955 -- A discriminant check on a selected component may be expanded
6956 -- into a dereference when removing side-effects. Recover the
6957 -- original node and its type, which may be unconstrained.
6959 elsif Nkind (P) = N_Explicit_Dereference
6960 and then not (Comes_From_Source (P))
6962 P := Original_Node (P);
6963 Prefix_Type := Etype (P);
6966 -- Check for prefix being an aliased component???
6972 -- A heap object is constrained by its initial value
6974 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6975 -- the dereferenced case, since the access value might denote an
6976 -- unconstrained aliased object, whereas in Ada 95 the designated
6977 -- object is guaranteed to be constrained. A worst-case assumption
6978 -- has to apply in Ada 2005 because we can't tell at compile time
6979 -- whether the object is "constrained by its initial value"
6980 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6981 -- semantic rules -- these rules are acknowledged to need fixing).
6983 if Ada_Version < Ada_2005 then
6984 if Is_Access_Type (Prefix_Type)
6985 or else Nkind (P) = N_Explicit_Dereference
6990 elsif Ada_Version >= Ada_2005 then
6991 if Is_Access_Type (Prefix_Type) then
6993 -- If the access type is pool-specific, and there is no
6994 -- constrained partial view of the designated type, then the
6995 -- designated object is known to be constrained.
6997 if Ekind (Prefix_Type) = E_Access_Type
6998 and then not Effectively_Has_Constrained_Partial_View
6999 (Designated_Type (Prefix_Type))
7003 -- Otherwise (general access type, or there is a constrained
7004 -- partial view of the designated type), we need to check
7005 -- based on the designated type.
7008 Prefix_Type := Designated_Type (Prefix_Type);
7014 Original_Record_Component (Entity (Selector_Name (Object)));
7016 -- As per AI-0017, the renaming is illegal in a generic body, even
7017 -- if the subtype is indefinite.
7019 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
7021 if not Is_Constrained (Prefix_Type)
7022 and then (not Is_Indefinite_Subtype (Prefix_Type)
7024 (Is_Generic_Type (Prefix_Type)
7025 and then Ekind (Current_Scope) = E_Generic_Package
7026 and then In_Package_Body (Current_Scope)))
7028 and then (Is_Declared_Within_Variant (Comp)
7029 or else Has_Discriminant_Dependent_Constraint (Comp))
7030 and then (not P_Aliased or else Ada_Version >= Ada_2005)
7036 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
7040 elsif Nkind (Object) = N_Indexed_Component
7041 or else Nkind (Object) = N_Slice
7043 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
7045 -- A type conversion that Is_Variable is a view conversion:
7046 -- go back to the denoted object.
7048 elsif Nkind (Object) = N_Type_Conversion then
7050 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
7055 end Is_Dependent_Component_Of_Mutable_Object;
7057 ---------------------
7058 -- Is_Dereferenced --
7059 ---------------------
7061 function Is_Dereferenced (N : Node_Id) return Boolean is
7062 P : constant Node_Id := Parent (N);
7065 (Nkind (P) = N_Selected_Component
7067 Nkind (P) = N_Explicit_Dereference
7069 Nkind (P) = N_Indexed_Component
7071 Nkind (P) = N_Slice)
7072 and then Prefix (P) = N;
7073 end Is_Dereferenced;
7075 ----------------------
7076 -- Is_Descendent_Of --
7077 ----------------------
7079 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
7084 pragma Assert (Nkind (T1) in N_Entity);
7085 pragma Assert (Nkind (T2) in N_Entity);
7087 T := Base_Type (T1);
7089 -- Immediate return if the types match
7094 -- Comment needed here ???
7096 elsif Ekind (T) = E_Class_Wide_Type then
7097 return Etype (T) = T2;
7105 -- Done if we found the type we are looking for
7110 -- Done if no more derivations to check
7117 -- Following test catches error cases resulting from prev errors
7119 elsif No (Etyp) then
7122 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
7125 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
7129 T := Base_Type (Etyp);
7132 end Is_Descendent_Of;
7134 ----------------------------
7135 -- Is_Expression_Function --
7136 ----------------------------
7138 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
7139 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7142 return Ekind (Subp) = E_Function
7143 and then Nkind (Decl) = N_Subprogram_Declaration
7145 (Nkind (Original_Node (Decl)) = N_Expression_Function
7147 (Present (Corresponding_Body (Decl))
7149 Nkind (Original_Node
7150 (Unit_Declaration_Node (Corresponding_Body (Decl))))
7151 = N_Expression_Function));
7152 end Is_Expression_Function;
7158 function Is_False (U : Uint) return Boolean is
7163 ---------------------------
7164 -- Is_Fixed_Model_Number --
7165 ---------------------------
7167 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
7168 S : constant Ureal := Small_Value (T);
7169 M : Urealp.Save_Mark;
7173 R := (U = UR_Trunc (U / S) * S);
7176 end Is_Fixed_Model_Number;
7178 -------------------------------
7179 -- Is_Fully_Initialized_Type --
7180 -------------------------------
7182 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
7184 if Is_Scalar_Type (Typ) then
7187 elsif Is_Access_Type (Typ) then
7190 elsif Is_Array_Type (Typ) then
7191 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
7195 -- An interesting case, if we have a constrained type one of whose
7196 -- bounds is known to be null, then there are no elements to be
7197 -- initialized, so all the elements are initialized!
7199 if Is_Constrained (Typ) then
7202 Indx_Typ : Entity_Id;
7206 Indx := First_Index (Typ);
7207 while Present (Indx) loop
7208 if Etype (Indx) = Any_Type then
7211 -- If index is a range, use directly
7213 elsif Nkind (Indx) = N_Range then
7214 Lbd := Low_Bound (Indx);
7215 Hbd := High_Bound (Indx);
7218 Indx_Typ := Etype (Indx);
7220 if Is_Private_Type (Indx_Typ) then
7221 Indx_Typ := Full_View (Indx_Typ);
7224 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
7227 Lbd := Type_Low_Bound (Indx_Typ);
7228 Hbd := Type_High_Bound (Indx_Typ);
7232 if Compile_Time_Known_Value (Lbd)
7233 and then Compile_Time_Known_Value (Hbd)
7235 if Expr_Value (Hbd) < Expr_Value (Lbd) then
7245 -- If no null indexes, then type is not fully initialized
7251 elsif Is_Record_Type (Typ) then
7252 if Has_Discriminants (Typ)
7254 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
7255 and then Is_Fully_Initialized_Variant (Typ)
7260 -- Controlled records are considered to be fully initialized if
7261 -- there is a user defined Initialize routine. This may not be
7262 -- entirely correct, but as the spec notes, we are guessing here
7263 -- what is best from the point of view of issuing warnings.
7265 if Is_Controlled (Typ) then
7267 Utyp : constant Entity_Id := Underlying_Type (Typ);
7270 if Present (Utyp) then
7272 Init : constant Entity_Id :=
7274 (Underlying_Type (Typ), Name_Initialize));
7278 and then Comes_From_Source (Init)
7280 Is_Predefined_File_Name
7281 (File_Name (Get_Source_File_Index (Sloc (Init))))
7285 elsif Has_Null_Extension (Typ)
7287 Is_Fully_Initialized_Type
7288 (Etype (Base_Type (Typ)))
7297 -- Otherwise see if all record components are initialized
7303 Ent := First_Entity (Typ);
7304 while Present (Ent) loop
7305 if Ekind (Ent) = E_Component
7306 and then (No (Parent (Ent))
7307 or else No (Expression (Parent (Ent))))
7308 and then not Is_Fully_Initialized_Type (Etype (Ent))
7310 -- Special VM case for tag components, which need to be
7311 -- defined in this case, but are never initialized as VMs
7312 -- are using other dispatching mechanisms. Ignore this
7313 -- uninitialized case. Note that this applies both to the
7314 -- uTag entry and the main vtable pointer (CPP_Class case).
7316 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
7325 -- No uninitialized components, so type is fully initialized.
7326 -- Note that this catches the case of no components as well.
7330 elsif Is_Concurrent_Type (Typ) then
7333 elsif Is_Private_Type (Typ) then
7335 U : constant Entity_Id := Underlying_Type (Typ);
7341 return Is_Fully_Initialized_Type (U);
7348 end Is_Fully_Initialized_Type;
7350 ----------------------------------
7351 -- Is_Fully_Initialized_Variant --
7352 ----------------------------------
7354 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
7355 Loc : constant Source_Ptr := Sloc (Typ);
7356 Constraints : constant List_Id := New_List;
7357 Components : constant Elist_Id := New_Elmt_List;
7358 Comp_Elmt : Elmt_Id;
7360 Comp_List : Node_Id;
7362 Discr_Val : Node_Id;
7364 Report_Errors : Boolean;
7365 pragma Warnings (Off, Report_Errors);
7368 if Serious_Errors_Detected > 0 then
7372 if Is_Record_Type (Typ)
7373 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7374 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7376 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7378 Discr := First_Discriminant (Typ);
7379 while Present (Discr) loop
7380 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7381 Discr_Val := Expression (Parent (Discr));
7383 if Present (Discr_Val)
7384 and then Is_OK_Static_Expression (Discr_Val)
7386 Append_To (Constraints,
7387 Make_Component_Association (Loc,
7388 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7389 Expression => New_Copy (Discr_Val)));
7397 Next_Discriminant (Discr);
7402 Comp_List => Comp_List,
7403 Governed_By => Constraints,
7405 Report_Errors => Report_Errors);
7407 -- Check that each component present is fully initialized
7409 Comp_Elmt := First_Elmt (Components);
7410 while Present (Comp_Elmt) loop
7411 Comp_Id := Node (Comp_Elmt);
7413 if Ekind (Comp_Id) = E_Component
7414 and then (No (Parent (Comp_Id))
7415 or else No (Expression (Parent (Comp_Id))))
7416 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7421 Next_Elmt (Comp_Elmt);
7426 elsif Is_Private_Type (Typ) then
7428 U : constant Entity_Id := Underlying_Type (Typ);
7434 return Is_Fully_Initialized_Variant (U);
7440 end Is_Fully_Initialized_Variant;
7442 ----------------------------
7443 -- Is_Inherited_Operation --
7444 ----------------------------
7446 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7447 pragma Assert (Is_Overloadable (E));
7448 Kind : constant Node_Kind := Nkind (Parent (E));
7450 return Kind = N_Full_Type_Declaration
7451 or else Kind = N_Private_Extension_Declaration
7452 or else Kind = N_Subtype_Declaration
7453 or else (Ekind (E) = E_Enumeration_Literal
7454 and then Is_Derived_Type (Etype (E)));
7455 end Is_Inherited_Operation;
7457 -------------------------------------
7458 -- Is_Inherited_Operation_For_Type --
7459 -------------------------------------
7461 function Is_Inherited_Operation_For_Type
7463 Typ : Entity_Id) return Boolean
7466 return Is_Inherited_Operation (E)
7467 and then Etype (Parent (E)) = Typ;
7468 end Is_Inherited_Operation_For_Type;
7474 function Is_Iterator (Typ : Entity_Id) return Boolean is
7475 Ifaces_List : Elist_Id;
7476 Iface_Elmt : Elmt_Id;
7480 if Is_Class_Wide_Type (Typ)
7482 (Chars (Etype (Typ)) = Name_Forward_Iterator
7484 Chars (Etype (Typ)) = Name_Reversible_Iterator)
7486 Is_Predefined_File_Name
7487 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
7491 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
7495 Collect_Interfaces (Typ, Ifaces_List);
7497 Iface_Elmt := First_Elmt (Ifaces_List);
7498 while Present (Iface_Elmt) loop
7499 Iface := Node (Iface_Elmt);
7500 if Chars (Iface) = Name_Forward_Iterator
7502 Is_Predefined_File_Name
7503 (Unit_File_Name (Get_Source_Unit (Iface)))
7508 Next_Elmt (Iface_Elmt);
7519 -- We seem to have a lot of overlapping functions that do similar things
7520 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7521 -- purely syntactic, it should be in Sem_Aux I would think???
7523 function Is_LHS (N : Node_Id) return Boolean is
7524 P : constant Node_Id := Parent (N);
7527 if Nkind (P) = N_Assignment_Statement then
7528 return Name (P) = N;
7531 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7533 return N = Prefix (P) and then Is_LHS (P);
7540 -----------------------------
7541 -- Is_Library_Level_Entity --
7542 -----------------------------
7544 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7546 -- The following is a small optimization, and it also properly handles
7547 -- discriminals, which in task bodies might appear in expressions before
7548 -- the corresponding procedure has been created, and which therefore do
7549 -- not have an assigned scope.
7551 if Is_Formal (E) then
7555 -- Normal test is simply that the enclosing dynamic scope is Standard
7557 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7558 end Is_Library_Level_Entity;
7560 --------------------------------
7561 -- Is_Limited_Class_Wide_Type --
7562 --------------------------------
7564 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
7567 Is_Class_Wide_Type (Typ)
7568 and then Is_Limited_Type (Typ);
7569 end Is_Limited_Class_Wide_Type;
7571 ---------------------------------
7572 -- Is_Local_Variable_Reference --
7573 ---------------------------------
7575 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7577 if not Is_Entity_Name (Expr) then
7582 Ent : constant Entity_Id := Entity (Expr);
7583 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7585 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7588 return Present (Sub) and then Sub = Current_Subprogram;
7592 end Is_Local_Variable_Reference;
7594 -------------------------
7595 -- Is_Object_Reference --
7596 -------------------------
7598 function Is_Object_Reference (N : Node_Id) return Boolean is
7600 if Is_Entity_Name (N) then
7601 return Present (Entity (N)) and then Is_Object (Entity (N));
7605 when N_Indexed_Component | N_Slice =>
7607 Is_Object_Reference (Prefix (N))
7608 or else Is_Access_Type (Etype (Prefix (N)));
7610 -- In Ada 95, a function call is a constant object; a procedure
7613 when N_Function_Call =>
7614 return Etype (N) /= Standard_Void_Type;
7616 -- A reference to the stream attribute Input is a function call
7618 when N_Attribute_Reference =>
7619 return Attribute_Name (N) = Name_Input;
7621 when N_Selected_Component =>
7623 Is_Object_Reference (Selector_Name (N))
7625 (Is_Object_Reference (Prefix (N))
7626 or else Is_Access_Type (Etype (Prefix (N))));
7628 when N_Explicit_Dereference =>
7631 -- A view conversion of a tagged object is an object reference
7633 when N_Type_Conversion =>
7634 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7635 and then Is_Tagged_Type (Etype (Expression (N)))
7636 and then Is_Object_Reference (Expression (N));
7638 -- An unchecked type conversion is considered to be an object if
7639 -- the operand is an object (this construction arises only as a
7640 -- result of expansion activities).
7642 when N_Unchecked_Type_Conversion =>
7649 end Is_Object_Reference;
7651 -----------------------------------
7652 -- Is_OK_Variable_For_Out_Formal --
7653 -----------------------------------
7655 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7657 Note_Possible_Modification (AV, Sure => True);
7659 -- We must reject parenthesized variable names. The check for
7660 -- Comes_From_Source is present because there are currently
7661 -- cases where the compiler violates this rule (e.g. passing
7662 -- a task object to its controlled Initialize routine).
7664 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7667 -- A variable is always allowed
7669 elsif Is_Variable (AV) then
7672 -- Unchecked conversions are allowed only if they come from the
7673 -- generated code, which sometimes uses unchecked conversions for out
7674 -- parameters in cases where code generation is unaffected. We tell
7675 -- source unchecked conversions by seeing if they are rewrites of an
7676 -- original Unchecked_Conversion function call, or of an explicit
7677 -- conversion of a function call.
7679 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7680 if Nkind (Original_Node (AV)) = N_Function_Call then
7683 elsif Comes_From_Source (AV)
7684 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7688 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7689 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7695 -- Normal type conversions are allowed if argument is a variable
7697 elsif Nkind (AV) = N_Type_Conversion then
7698 if Is_Variable (Expression (AV))
7699 and then Paren_Count (Expression (AV)) = 0
7701 Note_Possible_Modification (Expression (AV), Sure => True);
7704 -- We also allow a non-parenthesized expression that raises
7705 -- constraint error if it rewrites what used to be a variable
7707 elsif Raises_Constraint_Error (Expression (AV))
7708 and then Paren_Count (Expression (AV)) = 0
7709 and then Is_Variable (Original_Node (Expression (AV)))
7713 -- Type conversion of something other than a variable
7719 -- If this node is rewritten, then test the original form, if that is
7720 -- OK, then we consider the rewritten node OK (for example, if the
7721 -- original node is a conversion, then Is_Variable will not be true
7722 -- but we still want to allow the conversion if it converts a variable).
7724 elsif Original_Node (AV) /= AV then
7726 -- In Ada 2012, the explicit dereference may be a rewritten call to a
7727 -- Reference function.
7729 if Ada_Version >= Ada_2012
7730 and then Nkind (Original_Node (AV)) = N_Function_Call
7732 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
7737 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7740 -- All other non-variables are rejected
7745 end Is_OK_Variable_For_Out_Formal;
7747 -----------------------------------
7748 -- Is_Partially_Initialized_Type --
7749 -----------------------------------
7751 function Is_Partially_Initialized_Type
7753 Include_Implicit : Boolean := True) return Boolean
7756 if Is_Scalar_Type (Typ) then
7759 elsif Is_Access_Type (Typ) then
7760 return Include_Implicit;
7762 elsif Is_Array_Type (Typ) then
7764 -- If component type is partially initialized, so is array type
7766 if Is_Partially_Initialized_Type
7767 (Component_Type (Typ), Include_Implicit)
7771 -- Otherwise we are only partially initialized if we are fully
7772 -- initialized (this is the empty array case, no point in us
7773 -- duplicating that code here).
7776 return Is_Fully_Initialized_Type (Typ);
7779 elsif Is_Record_Type (Typ) then
7781 -- A discriminated type is always partially initialized if in
7784 if Has_Discriminants (Typ) and then Include_Implicit then
7787 -- A tagged type is always partially initialized
7789 elsif Is_Tagged_Type (Typ) then
7792 -- Case of non-discriminated record
7798 Component_Present : Boolean := False;
7799 -- Set True if at least one component is present. If no
7800 -- components are present, then record type is fully
7801 -- initialized (another odd case, like the null array).
7804 -- Loop through components
7806 Ent := First_Entity (Typ);
7807 while Present (Ent) loop
7808 if Ekind (Ent) = E_Component then
7809 Component_Present := True;
7811 -- If a component has an initialization expression then
7812 -- the enclosing record type is partially initialized
7814 if Present (Parent (Ent))
7815 and then Present (Expression (Parent (Ent)))
7819 -- If a component is of a type which is itself partially
7820 -- initialized, then the enclosing record type is also.
7822 elsif Is_Partially_Initialized_Type
7823 (Etype (Ent), Include_Implicit)
7832 -- No initialized components found. If we found any components
7833 -- they were all uninitialized so the result is false.
7835 if Component_Present then
7838 -- But if we found no components, then all the components are
7839 -- initialized so we consider the type to be initialized.
7847 -- Concurrent types are always fully initialized
7849 elsif Is_Concurrent_Type (Typ) then
7852 -- For a private type, go to underlying type. If there is no underlying
7853 -- type then just assume this partially initialized. Not clear if this
7854 -- can happen in a non-error case, but no harm in testing for this.
7856 elsif Is_Private_Type (Typ) then
7858 U : constant Entity_Id := Underlying_Type (Typ);
7863 return Is_Partially_Initialized_Type (U, Include_Implicit);
7867 -- For any other type (are there any?) assume partially initialized
7872 end Is_Partially_Initialized_Type;
7874 ------------------------------------
7875 -- Is_Potentially_Persistent_Type --
7876 ------------------------------------
7878 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7883 -- For private type, test corresponding full type
7885 if Is_Private_Type (T) then
7886 return Is_Potentially_Persistent_Type (Full_View (T));
7888 -- Scalar types are potentially persistent
7890 elsif Is_Scalar_Type (T) then
7893 -- Record type is potentially persistent if not tagged and the types of
7894 -- all it components are potentially persistent, and no component has
7895 -- an initialization expression.
7897 elsif Is_Record_Type (T)
7898 and then not Is_Tagged_Type (T)
7899 and then not Is_Partially_Initialized_Type (T)
7901 Comp := First_Component (T);
7902 while Present (Comp) loop
7903 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7912 -- Array type is potentially persistent if its component type is
7913 -- potentially persistent and if all its constraints are static.
7915 elsif Is_Array_Type (T) then
7916 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7920 Indx := First_Index (T);
7921 while Present (Indx) loop
7922 if not Is_OK_Static_Subtype (Etype (Indx)) then
7931 -- All other types are not potentially persistent
7936 end Is_Potentially_Persistent_Type;
7938 ---------------------------------
7939 -- Is_Protected_Self_Reference --
7940 ---------------------------------
7942 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7944 function In_Access_Definition (N : Node_Id) return Boolean;
7945 -- Returns true if N belongs to an access definition
7947 --------------------------
7948 -- In_Access_Definition --
7949 --------------------------
7951 function In_Access_Definition (N : Node_Id) return Boolean is
7956 while Present (P) loop
7957 if Nkind (P) = N_Access_Definition then
7965 end In_Access_Definition;
7967 -- Start of processing for Is_Protected_Self_Reference
7970 -- Verify that prefix is analyzed and has the proper form. Note that
7971 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
7972 -- which also produce the address of an entity, do not analyze their
7973 -- prefix because they denote entities that are not necessarily visible.
7974 -- Neither of them can apply to a protected type.
7976 return Ada_Version >= Ada_2005
7977 and then Is_Entity_Name (N)
7978 and then Present (Entity (N))
7979 and then Is_Protected_Type (Entity (N))
7980 and then In_Open_Scopes (Entity (N))
7981 and then not In_Access_Definition (N);
7982 end Is_Protected_Self_Reference;
7984 -----------------------------
7985 -- Is_RCI_Pkg_Spec_Or_Body --
7986 -----------------------------
7988 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7990 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7991 -- Return True if the unit of Cunit is an RCI package declaration
7993 ---------------------------
7994 -- Is_RCI_Pkg_Decl_Cunit --
7995 ---------------------------
7997 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7998 The_Unit : constant Node_Id := Unit (Cunit);
8001 if Nkind (The_Unit) /= N_Package_Declaration then
8005 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
8006 end Is_RCI_Pkg_Decl_Cunit;
8008 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
8011 return Is_RCI_Pkg_Decl_Cunit (Cunit)
8013 (Nkind (Unit (Cunit)) = N_Package_Body
8014 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
8015 end Is_RCI_Pkg_Spec_Or_Body;
8017 -----------------------------------------
8018 -- Is_Remote_Access_To_Class_Wide_Type --
8019 -----------------------------------------
8021 function Is_Remote_Access_To_Class_Wide_Type
8022 (E : Entity_Id) return Boolean
8025 -- A remote access to class-wide type is a general access to object type
8026 -- declared in the visible part of a Remote_Types or Remote_Call_
8029 return Ekind (E) = E_General_Access_Type
8030 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
8031 end Is_Remote_Access_To_Class_Wide_Type;
8033 -----------------------------------------
8034 -- Is_Remote_Access_To_Subprogram_Type --
8035 -----------------------------------------
8037 function Is_Remote_Access_To_Subprogram_Type
8038 (E : Entity_Id) return Boolean
8041 return (Ekind (E) = E_Access_Subprogram_Type
8042 or else (Ekind (E) = E_Record_Type
8043 and then Present (Corresponding_Remote_Type (E))))
8044 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
8045 end Is_Remote_Access_To_Subprogram_Type;
8047 --------------------
8048 -- Is_Remote_Call --
8049 --------------------
8051 function Is_Remote_Call (N : Node_Id) return Boolean is
8053 if Nkind (N) /= N_Procedure_Call_Statement
8054 and then Nkind (N) /= N_Function_Call
8056 -- An entry call cannot be remote
8060 elsif Nkind (Name (N)) in N_Has_Entity
8061 and then Is_Remote_Call_Interface (Entity (Name (N)))
8063 -- A subprogram declared in the spec of a RCI package is remote
8067 elsif Nkind (Name (N)) = N_Explicit_Dereference
8068 and then Is_Remote_Access_To_Subprogram_Type
8069 (Etype (Prefix (Name (N))))
8071 -- The dereference of a RAS is a remote call
8075 elsif Present (Controlling_Argument (N))
8076 and then Is_Remote_Access_To_Class_Wide_Type
8077 (Etype (Controlling_Argument (N)))
8079 -- Any primitive operation call with a controlling argument of
8080 -- a RACW type is a remote call.
8085 -- All other calls are local calls
8090 ----------------------
8091 -- Is_Renamed_Entry --
8092 ----------------------
8094 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
8095 Orig_Node : Node_Id := Empty;
8096 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
8098 function Is_Entry (Nam : Node_Id) return Boolean;
8099 -- Determine whether Nam is an entry. Traverse selectors if there are
8100 -- nested selected components.
8106 function Is_Entry (Nam : Node_Id) return Boolean is
8108 if Nkind (Nam) = N_Selected_Component then
8109 return Is_Entry (Selector_Name (Nam));
8112 return Ekind (Entity (Nam)) = E_Entry;
8115 -- Start of processing for Is_Renamed_Entry
8118 if Present (Alias (Proc_Nam)) then
8119 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
8122 -- Look for a rewritten subprogram renaming declaration
8124 if Nkind (Subp_Decl) = N_Subprogram_Declaration
8125 and then Present (Original_Node (Subp_Decl))
8127 Orig_Node := Original_Node (Subp_Decl);
8130 -- The rewritten subprogram is actually an entry
8132 if Present (Orig_Node)
8133 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
8134 and then Is_Entry (Name (Orig_Node))
8140 end Is_Renamed_Entry;
8142 ----------------------------
8143 -- Is_Reversible_Iterator --
8144 ----------------------------
8146 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
8147 Ifaces_List : Elist_Id;
8148 Iface_Elmt : Elmt_Id;
8152 if Is_Class_Wide_Type (Typ)
8153 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
8155 Is_Predefined_File_Name
8156 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
8160 elsif not Is_Tagged_Type (Typ)
8161 or else not Is_Derived_Type (Typ)
8166 Collect_Interfaces (Typ, Ifaces_List);
8168 Iface_Elmt := First_Elmt (Ifaces_List);
8169 while Present (Iface_Elmt) loop
8170 Iface := Node (Iface_Elmt);
8171 if Chars (Iface) = Name_Reversible_Iterator
8173 Is_Predefined_File_Name
8174 (Unit_File_Name (Get_Source_Unit (Iface)))
8179 Next_Elmt (Iface_Elmt);
8184 end Is_Reversible_Iterator;
8186 ----------------------
8187 -- Is_Selector_Name --
8188 ----------------------
8190 function Is_Selector_Name (N : Node_Id) return Boolean is
8192 if not Is_List_Member (N) then
8194 P : constant Node_Id := Parent (N);
8195 K : constant Node_Kind := Nkind (P);
8198 (K = N_Expanded_Name or else
8199 K = N_Generic_Association or else
8200 K = N_Parameter_Association or else
8201 K = N_Selected_Component)
8202 and then Selector_Name (P) = N;
8207 L : constant List_Id := List_Containing (N);
8208 P : constant Node_Id := Parent (L);
8210 return (Nkind (P) = N_Discriminant_Association
8211 and then Selector_Names (P) = L)
8213 (Nkind (P) = N_Component_Association
8214 and then Choices (P) = L);
8217 end Is_Selector_Name;
8219 ----------------------------------
8220 -- Is_SPARK_Initialization_Expr --
8221 ----------------------------------
8223 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
8226 Comp_Assn : Node_Id;
8227 Orig_N : constant Node_Id := Original_Node (N);
8232 if not Comes_From_Source (Orig_N) then
8236 pragma Assert (Nkind (Orig_N) in N_Subexpr);
8238 case Nkind (Orig_N) is
8239 when N_Character_Literal |
8247 if Is_Entity_Name (Orig_N)
8248 and then Present (Entity (Orig_N)) -- needed in some cases
8250 case Ekind (Entity (Orig_N)) is
8252 E_Enumeration_Literal |
8257 if Is_Type (Entity (Orig_N)) then
8265 when N_Qualified_Expression |
8266 N_Type_Conversion =>
8267 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
8270 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8274 N_Membership_Test =>
8275 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
8276 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
8279 N_Extension_Aggregate =>
8280 if Nkind (Orig_N) = N_Extension_Aggregate then
8281 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
8284 Expr := First (Expressions (Orig_N));
8285 while Present (Expr) loop
8286 if not Is_SPARK_Initialization_Expr (Expr) then
8294 Comp_Assn := First (Component_Associations (Orig_N));
8295 while Present (Comp_Assn) loop
8296 Expr := Expression (Comp_Assn);
8297 if Present (Expr) -- needed for box association
8298 and then not Is_SPARK_Initialization_Expr (Expr)
8307 when N_Attribute_Reference =>
8308 if Nkind (Prefix (Orig_N)) in N_Subexpr then
8309 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
8312 Expr := First (Expressions (Orig_N));
8313 while Present (Expr) loop
8314 if not Is_SPARK_Initialization_Expr (Expr) then
8322 -- Selected components might be expanded named not yet resolved, so
8323 -- default on the safe side. (Eg on sparklex.ads)
8325 when N_Selected_Component =>
8334 end Is_SPARK_Initialization_Expr;
8336 -------------------------------
8337 -- Is_SPARK_Object_Reference --
8338 -------------------------------
8340 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
8342 if Is_Entity_Name (N) then
8343 return Present (Entity (N))
8345 (Ekind_In (Entity (N), E_Constant, E_Variable)
8346 or else Ekind (Entity (N)) in Formal_Kind);
8350 when N_Selected_Component =>
8351 return Is_SPARK_Object_Reference (Prefix (N));
8357 end Is_SPARK_Object_Reference;
8363 function Is_Statement (N : Node_Id) return Boolean is
8366 Nkind (N) in N_Statement_Other_Than_Procedure_Call
8367 or else Nkind (N) = N_Procedure_Call_Statement;
8370 --------------------------------------------------
8371 -- Is_Subprogram_Stub_Without_Prior_Declaration --
8372 --------------------------------------------------
8374 function Is_Subprogram_Stub_Without_Prior_Declaration
8375 (N : Node_Id) return Boolean
8378 -- A subprogram stub without prior declaration serves as declaration for
8379 -- the actual subprogram body. As such, it has an attached defining
8380 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
8382 return Nkind (N) = N_Subprogram_Body_Stub
8383 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
8384 end Is_Subprogram_Stub_Without_Prior_Declaration;
8386 ---------------------------------
8387 -- Is_Synchronized_Tagged_Type --
8388 ---------------------------------
8390 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
8391 Kind : constant Entity_Kind := Ekind (Base_Type (E));
8394 -- A task or protected type derived from an interface is a tagged type.
8395 -- Such a tagged type is called a synchronized tagged type, as are
8396 -- synchronized interfaces and private extensions whose declaration
8397 -- includes the reserved word synchronized.
8399 return (Is_Tagged_Type (E)
8400 and then (Kind = E_Task_Type
8401 or else Kind = E_Protected_Type))
8404 and then Is_Synchronized_Interface (E))
8406 (Ekind (E) = E_Record_Type_With_Private
8407 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
8408 and then (Synchronized_Present (Parent (E))
8409 or else Is_Synchronized_Interface (Etype (E))));
8410 end Is_Synchronized_Tagged_Type;
8416 function Is_Transfer (N : Node_Id) return Boolean is
8417 Kind : constant Node_Kind := Nkind (N);
8420 if Kind = N_Simple_Return_Statement
8422 Kind = N_Extended_Return_Statement
8424 Kind = N_Goto_Statement
8426 Kind = N_Raise_Statement
8428 Kind = N_Requeue_Statement
8432 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
8433 and then No (Condition (N))
8437 elsif Kind = N_Procedure_Call_Statement
8438 and then Is_Entity_Name (Name (N))
8439 and then Present (Entity (Name (N)))
8440 and then No_Return (Entity (Name (N)))
8444 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
8456 function Is_True (U : Uint) return Boolean is
8461 -------------------------------
8462 -- Is_Universal_Numeric_Type --
8463 -------------------------------
8465 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
8467 return T = Universal_Integer or else T = Universal_Real;
8468 end Is_Universal_Numeric_Type;
8474 function Is_Value_Type (T : Entity_Id) return Boolean is
8476 return VM_Target = CLI_Target
8477 and then Nkind (T) in N_Has_Chars
8478 and then Chars (T) /= No_Name
8479 and then Get_Name_String (Chars (T)) = "valuetype";
8482 ---------------------
8483 -- Is_VMS_Operator --
8484 ---------------------
8486 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
8488 -- The VMS operators are declared in a child of System that is loaded
8489 -- through pragma Extend_System. In some rare cases a program is run
8490 -- with this extension but without indicating that the target is VMS.
8492 return Ekind (Op) = E_Function
8493 and then Is_Intrinsic_Subprogram (Op)
8495 ((Present_System_Aux
8496 and then Scope (Op) = System_Aux_Id)
8499 and then Scope (Scope (Op)) = RTU_Entity (System)));
8500 end Is_VMS_Operator;
8506 function Is_Variable
8508 Use_Original_Node : Boolean := True) return Boolean
8510 Orig_Node : Node_Id;
8512 function In_Protected_Function (E : Entity_Id) return Boolean;
8513 -- Within a protected function, the private components of the enclosing
8514 -- protected type are constants. A function nested within a (protected)
8515 -- procedure is not itself protected.
8517 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8518 -- Prefixes can involve implicit dereferences, in which case we must
8519 -- test for the case of a reference of a constant access type, which can
8520 -- can never be a variable.
8522 ---------------------------
8523 -- In_Protected_Function --
8524 ---------------------------
8526 function In_Protected_Function (E : Entity_Id) return Boolean is
8527 Prot : constant Entity_Id := Scope (E);
8531 if not Is_Protected_Type (Prot) then
8535 while Present (S) and then S /= Prot loop
8536 if Ekind (S) = E_Function and then Scope (S) = Prot then
8545 end In_Protected_Function;
8547 ------------------------
8548 -- Is_Variable_Prefix --
8549 ------------------------
8551 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8553 if Is_Access_Type (Etype (P)) then
8554 return not Is_Access_Constant (Root_Type (Etype (P)));
8556 -- For the case of an indexed component whose prefix has a packed
8557 -- array type, the prefix has been rewritten into a type conversion.
8558 -- Determine variable-ness from the converted expression.
8560 elsif Nkind (P) = N_Type_Conversion
8561 and then not Comes_From_Source (P)
8562 and then Is_Array_Type (Etype (P))
8563 and then Is_Packed (Etype (P))
8565 return Is_Variable (Expression (P));
8568 return Is_Variable (P);
8570 end Is_Variable_Prefix;
8572 -- Start of processing for Is_Variable
8575 -- Check if we perform the test on the original node since this may be a
8576 -- test of syntactic categories which must not be disturbed by whatever
8577 -- rewriting might have occurred. For example, an aggregate, which is
8578 -- certainly NOT a variable, could be turned into a variable by
8581 if Use_Original_Node then
8582 Orig_Node := Original_Node (N);
8587 -- Definitely OK if Assignment_OK is set. Since this is something that
8588 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8590 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8593 -- Normally we go to the original node, but there is one exception where
8594 -- we use the rewritten node, namely when it is an explicit dereference.
8595 -- The generated code may rewrite a prefix which is an access type with
8596 -- an explicit dereference. The dereference is a variable, even though
8597 -- the original node may not be (since it could be a constant of the
8600 -- In Ada 2005 we have a further case to consider: the prefix may be a
8601 -- function call given in prefix notation. The original node appears to
8602 -- be a selected component, but we need to examine the call.
8604 elsif Nkind (N) = N_Explicit_Dereference
8605 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8606 and then Present (Etype (Orig_Node))
8607 and then Is_Access_Type (Etype (Orig_Node))
8609 -- Note that if the prefix is an explicit dereference that does not
8610 -- come from source, we must check for a rewritten function call in
8611 -- prefixed notation before other forms of rewriting, to prevent a
8615 (Nkind (Orig_Node) = N_Function_Call
8616 and then not Is_Access_Constant (Etype (Prefix (N))))
8618 Is_Variable_Prefix (Original_Node (Prefix (N)));
8620 -- A function call is never a variable
8622 elsif Nkind (N) = N_Function_Call then
8625 -- All remaining checks use the original node
8627 elsif Is_Entity_Name (Orig_Node)
8628 and then Present (Entity (Orig_Node))
8631 E : constant Entity_Id := Entity (Orig_Node);
8632 K : constant Entity_Kind := Ekind (E);
8635 return (K = E_Variable
8636 and then Nkind (Parent (E)) /= N_Exception_Handler)
8637 or else (K = E_Component
8638 and then not In_Protected_Function (E))
8639 or else K = E_Out_Parameter
8640 or else K = E_In_Out_Parameter
8641 or else K = E_Generic_In_Out_Parameter
8643 -- Current instance of type
8645 or else (Is_Type (E) and then In_Open_Scopes (E))
8646 or else (Is_Incomplete_Or_Private_Type (E)
8647 and then In_Open_Scopes (Full_View (E)));
8651 case Nkind (Orig_Node) is
8652 when N_Indexed_Component | N_Slice =>
8653 return Is_Variable_Prefix (Prefix (Orig_Node));
8655 when N_Selected_Component =>
8656 return Is_Variable_Prefix (Prefix (Orig_Node))
8657 and then Is_Variable (Selector_Name (Orig_Node));
8659 -- For an explicit dereference, the type of the prefix cannot
8660 -- be an access to constant or an access to subprogram.
8662 when N_Explicit_Dereference =>
8664 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8666 return Is_Access_Type (Typ)
8667 and then not Is_Access_Constant (Root_Type (Typ))
8668 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8671 -- The type conversion is the case where we do not deal with the
8672 -- context dependent special case of an actual parameter. Thus
8673 -- the type conversion is only considered a variable for the
8674 -- purposes of this routine if the target type is tagged. However,
8675 -- a type conversion is considered to be a variable if it does not
8676 -- come from source (this deals for example with the conversions
8677 -- of expressions to their actual subtypes).
8679 when N_Type_Conversion =>
8680 return Is_Variable (Expression (Orig_Node))
8682 (not Comes_From_Source (Orig_Node)
8684 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8686 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8688 -- GNAT allows an unchecked type conversion as a variable. This
8689 -- only affects the generation of internal expanded code, since
8690 -- calls to instantiations of Unchecked_Conversion are never
8691 -- considered variables (since they are function calls).
8692 -- This is also true for expression actions.
8694 when N_Unchecked_Type_Conversion =>
8695 return Is_Variable (Expression (Orig_Node));
8703 ---------------------------
8704 -- Is_Visibly_Controlled --
8705 ---------------------------
8707 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8708 Root : constant Entity_Id := Root_Type (T);
8710 return Chars (Scope (Root)) = Name_Finalization
8711 and then Chars (Scope (Scope (Root))) = Name_Ada
8712 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8713 end Is_Visibly_Controlled;
8715 ------------------------
8716 -- Is_Volatile_Object --
8717 ------------------------
8719 function Is_Volatile_Object (N : Node_Id) return Boolean is
8721 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8722 -- Determines if given object has volatile components
8724 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8725 -- If prefix is an implicit dereference, examine designated type
8727 ------------------------
8728 -- Is_Volatile_Prefix --
8729 ------------------------
8731 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8732 Typ : constant Entity_Id := Etype (N);
8735 if Is_Access_Type (Typ) then
8737 Dtyp : constant Entity_Id := Designated_Type (Typ);
8740 return Is_Volatile (Dtyp)
8741 or else Has_Volatile_Components (Dtyp);
8745 return Object_Has_Volatile_Components (N);
8747 end Is_Volatile_Prefix;
8749 ------------------------------------
8750 -- Object_Has_Volatile_Components --
8751 ------------------------------------
8753 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8754 Typ : constant Entity_Id := Etype (N);
8757 if Is_Volatile (Typ)
8758 or else Has_Volatile_Components (Typ)
8762 elsif Is_Entity_Name (N)
8763 and then (Has_Volatile_Components (Entity (N))
8764 or else Is_Volatile (Entity (N)))
8768 elsif Nkind (N) = N_Indexed_Component
8769 or else Nkind (N) = N_Selected_Component
8771 return Is_Volatile_Prefix (Prefix (N));
8776 end Object_Has_Volatile_Components;
8778 -- Start of processing for Is_Volatile_Object
8781 if Is_Volatile (Etype (N))
8782 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8786 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
8787 and then Is_Volatile_Prefix (Prefix (N))
8791 elsif Nkind (N) = N_Selected_Component
8792 and then Is_Volatile (Entity (Selector_Name (N)))
8799 end Is_Volatile_Object;
8801 ---------------------------
8802 -- Itype_Has_Declaration --
8803 ---------------------------
8805 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
8807 pragma Assert (Is_Itype (Id));
8808 return Present (Parent (Id))
8809 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
8810 N_Subtype_Declaration)
8811 and then Defining_Entity (Parent (Id)) = Id;
8812 end Itype_Has_Declaration;
8814 -------------------------
8815 -- Kill_Current_Values --
8816 -------------------------
8818 procedure Kill_Current_Values
8820 Last_Assignment_Only : Boolean := False)
8823 -- ??? do we have to worry about clearing cached checks?
8825 if Is_Assignable (Ent) then
8826 Set_Last_Assignment (Ent, Empty);
8829 if Is_Object (Ent) then
8830 if not Last_Assignment_Only then
8832 Set_Current_Value (Ent, Empty);
8834 if not Can_Never_Be_Null (Ent) then
8835 Set_Is_Known_Non_Null (Ent, False);
8838 Set_Is_Known_Null (Ent, False);
8840 -- Reset Is_Known_Valid unless type is always valid, or if we have
8841 -- a loop parameter (loop parameters are always valid, since their
8842 -- bounds are defined by the bounds given in the loop header).
8844 if not Is_Known_Valid (Etype (Ent))
8845 and then Ekind (Ent) /= E_Loop_Parameter
8847 Set_Is_Known_Valid (Ent, False);
8851 end Kill_Current_Values;
8853 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8856 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8857 -- Clear current value for entity E and all entities chained to E
8859 ------------------------------------------
8860 -- Kill_Current_Values_For_Entity_Chain --
8861 ------------------------------------------
8863 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8867 while Present (Ent) loop
8868 Kill_Current_Values (Ent, Last_Assignment_Only);
8871 end Kill_Current_Values_For_Entity_Chain;
8873 -- Start of processing for Kill_Current_Values
8876 -- Kill all saved checks, a special case of killing saved values
8878 if not Last_Assignment_Only then
8882 -- Loop through relevant scopes, which includes the current scope and
8883 -- any parent scopes if the current scope is a block or a package.
8888 -- Clear current values of all entities in current scope
8890 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8892 -- If scope is a package, also clear current values of all private
8893 -- entities in the scope.
8895 if Is_Package_Or_Generic_Package (S)
8896 or else Is_Concurrent_Type (S)
8898 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8901 -- If this is a not a subprogram, deal with parents
8903 if not Is_Subprogram (S) then
8905 exit Scope_Loop when S = Standard_Standard;
8909 end loop Scope_Loop;
8910 end Kill_Current_Values;
8912 --------------------------
8913 -- Kill_Size_Check_Code --
8914 --------------------------
8916 procedure Kill_Size_Check_Code (E : Entity_Id) is
8918 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8919 and then Present (Size_Check_Code (E))
8921 Remove (Size_Check_Code (E));
8922 Set_Size_Check_Code (E, Empty);
8924 end Kill_Size_Check_Code;
8926 --------------------------
8927 -- Known_To_Be_Assigned --
8928 --------------------------
8930 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8931 P : constant Node_Id := Parent (N);
8936 -- Test left side of assignment
8938 when N_Assignment_Statement =>
8939 return N = Name (P);
8941 -- Function call arguments are never lvalues
8943 when N_Function_Call =>
8946 -- Positional parameter for procedure or accept call
8948 when N_Procedure_Call_Statement |
8957 Proc := Get_Subprogram_Entity (P);
8963 -- If we are not a list member, something is strange, so
8964 -- be conservative and return False.
8966 if not Is_List_Member (N) then
8970 -- We are going to find the right formal by stepping forward
8971 -- through the formals, as we step backwards in the actuals.
8973 Form := First_Formal (Proc);
8976 -- If no formal, something is weird, so be conservative
8977 -- and return False.
8988 return Ekind (Form) /= E_In_Parameter;
8991 -- Named parameter for procedure or accept call
8993 when N_Parameter_Association =>
8999 Proc := Get_Subprogram_Entity (Parent (P));
9005 -- Loop through formals to find the one that matches
9007 Form := First_Formal (Proc);
9009 -- If no matching formal, that's peculiar, some kind of
9010 -- previous error, so return False to be conservative.
9016 -- Else test for match
9018 if Chars (Form) = Chars (Selector_Name (P)) then
9019 return Ekind (Form) /= E_In_Parameter;
9026 -- Test for appearing in a conversion that itself appears
9027 -- in an lvalue context, since this should be an lvalue.
9029 when N_Type_Conversion =>
9030 return Known_To_Be_Assigned (P);
9032 -- All other references are definitely not known to be modifications
9038 end Known_To_Be_Assigned;
9040 ---------------------------
9041 -- Last_Source_Statement --
9042 ---------------------------
9044 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
9048 N := Last (Statements (HSS));
9049 while Present (N) loop
9050 exit when Comes_From_Source (N);
9055 end Last_Source_Statement;
9057 ----------------------------------
9058 -- Matching_Static_Array_Bounds --
9059 ----------------------------------
9061 function Matching_Static_Array_Bounds
9063 R_Typ : Node_Id) return Boolean
9065 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
9066 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
9078 if L_Ndims /= R_Ndims then
9082 -- Unconstrained types do not have static bounds
9084 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
9088 -- First treat specially the first dimension, as the lower bound and
9089 -- length of string literals are not stored like those of arrays.
9091 if Ekind (L_Typ) = E_String_Literal_Subtype then
9092 L_Low := String_Literal_Low_Bound (L_Typ);
9093 L_Len := String_Literal_Length (L_Typ);
9095 L_Index := First_Index (L_Typ);
9096 Get_Index_Bounds (L_Index, L_Low, L_High);
9098 if Is_OK_Static_Expression (L_Low)
9099 and then Is_OK_Static_Expression (L_High)
9101 if Expr_Value (L_High) < Expr_Value (L_Low) then
9104 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
9111 if Ekind (R_Typ) = E_String_Literal_Subtype then
9112 R_Low := String_Literal_Low_Bound (R_Typ);
9113 R_Len := String_Literal_Length (R_Typ);
9115 R_Index := First_Index (R_Typ);
9116 Get_Index_Bounds (R_Index, R_Low, R_High);
9118 if Is_OK_Static_Expression (R_Low)
9119 and then Is_OK_Static_Expression (R_High)
9121 if Expr_Value (R_High) < Expr_Value (R_Low) then
9124 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
9131 if Is_OK_Static_Expression (L_Low)
9132 and then Is_OK_Static_Expression (R_Low)
9133 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9134 and then L_Len = R_Len
9141 -- Then treat all other dimensions
9143 for Indx in 2 .. L_Ndims loop
9147 Get_Index_Bounds (L_Index, L_Low, L_High);
9148 Get_Index_Bounds (R_Index, R_Low, R_High);
9150 if Is_OK_Static_Expression (L_Low)
9151 and then Is_OK_Static_Expression (L_High)
9152 and then Is_OK_Static_Expression (R_Low)
9153 and then Is_OK_Static_Expression (R_High)
9154 and then Expr_Value (L_Low) = Expr_Value (R_Low)
9155 and then Expr_Value (L_High) = Expr_Value (R_High)
9163 -- If we fall through the loop, all indexes matched
9166 end Matching_Static_Array_Bounds;
9172 function May_Be_Lvalue (N : Node_Id) return Boolean is
9173 P : constant Node_Id := Parent (N);
9178 -- Test left side of assignment
9180 when N_Assignment_Statement =>
9181 return N = Name (P);
9183 -- Test prefix of component or attribute. Note that the prefix of an
9184 -- explicit or implicit dereference cannot be an l-value.
9186 when N_Attribute_Reference =>
9187 return N = Prefix (P)
9188 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
9190 -- For an expanded name, the name is an lvalue if the expanded name
9191 -- is an lvalue, but the prefix is never an lvalue, since it is just
9192 -- the scope where the name is found.
9194 when N_Expanded_Name =>
9195 if N = Prefix (P) then
9196 return May_Be_Lvalue (P);
9201 -- For a selected component A.B, A is certainly an lvalue if A.B is.
9202 -- B is a little interesting, if we have A.B := 3, there is some
9203 -- discussion as to whether B is an lvalue or not, we choose to say
9204 -- it is. Note however that A is not an lvalue if it is of an access
9205 -- type since this is an implicit dereference.
9207 when N_Selected_Component =>
9209 and then Present (Etype (N))
9210 and then Is_Access_Type (Etype (N))
9214 return May_Be_Lvalue (P);
9217 -- For an indexed component or slice, the index or slice bounds is
9218 -- never an lvalue. The prefix is an lvalue if the indexed component
9219 -- or slice is an lvalue, except if it is an access type, where we
9220 -- have an implicit dereference.
9222 when N_Indexed_Component | N_Slice =>
9224 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
9228 return May_Be_Lvalue (P);
9231 -- Prefix of a reference is an lvalue if the reference is an lvalue
9234 return May_Be_Lvalue (P);
9236 -- Prefix of explicit dereference is never an lvalue
9238 when N_Explicit_Dereference =>
9241 -- Positional parameter for subprogram, entry, or accept call.
9242 -- In older versions of Ada function call arguments are never
9243 -- lvalues. In Ada 2012 functions can have in-out parameters.
9245 when N_Function_Call |
9246 N_Procedure_Call_Statement |
9247 N_Entry_Call_Statement |
9250 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
9254 -- The following mechanism is clumsy and fragile. A single flag
9255 -- set in Resolve_Actuals would be preferable ???
9263 Proc := Get_Subprogram_Entity (P);
9269 -- If we are not a list member, something is strange, so be
9270 -- conservative and return True.
9272 if not Is_List_Member (N) then
9276 -- We are going to find the right formal by stepping forward
9277 -- through the formals, as we step backwards in the actuals.
9279 Form := First_Formal (Proc);
9282 -- If no formal, something is weird, so be conservative and
9294 return Ekind (Form) /= E_In_Parameter;
9297 -- Named parameter for procedure or accept call
9299 when N_Parameter_Association =>
9305 Proc := Get_Subprogram_Entity (Parent (P));
9311 -- Loop through formals to find the one that matches
9313 Form := First_Formal (Proc);
9315 -- If no matching formal, that's peculiar, some kind of
9316 -- previous error, so return True to be conservative.
9322 -- Else test for match
9324 if Chars (Form) = Chars (Selector_Name (P)) then
9325 return Ekind (Form) /= E_In_Parameter;
9332 -- Test for appearing in a conversion that itself appears in an
9333 -- lvalue context, since this should be an lvalue.
9335 when N_Type_Conversion =>
9336 return May_Be_Lvalue (P);
9338 -- Test for appearance in object renaming declaration
9340 when N_Object_Renaming_Declaration =>
9343 -- All other references are definitely not lvalues
9351 -----------------------
9352 -- Mark_Coextensions --
9353 -----------------------
9355 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
9356 Is_Dynamic : Boolean;
9357 -- Indicates whether the context causes nested coextensions to be
9358 -- dynamic or static
9360 function Mark_Allocator (N : Node_Id) return Traverse_Result;
9361 -- Recognize an allocator node and label it as a dynamic coextension
9363 --------------------
9364 -- Mark_Allocator --
9365 --------------------
9367 function Mark_Allocator (N : Node_Id) return Traverse_Result is
9369 if Nkind (N) = N_Allocator then
9371 Set_Is_Dynamic_Coextension (N);
9373 -- If the allocator expression is potentially dynamic, it may
9374 -- be expanded out of order and require dynamic allocation
9375 -- anyway, so we treat the coextension itself as dynamic.
9376 -- Potential optimization ???
9378 elsif Nkind (Expression (N)) = N_Qualified_Expression
9379 and then Nkind (Expression (Expression (N))) = N_Op_Concat
9381 Set_Is_Dynamic_Coextension (N);
9384 Set_Is_Static_Coextension (N);
9391 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
9393 -- Start of processing Mark_Coextensions
9396 case Nkind (Context_Nod) is
9397 when N_Assignment_Statement |
9398 N_Simple_Return_Statement =>
9399 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
9401 when N_Object_Declaration =>
9402 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
9404 -- This routine should not be called for constructs which may not
9405 -- contain coextensions.
9408 raise Program_Error;
9411 Mark_Allocators (Root_Nod);
9412 end Mark_Coextensions;
9414 ----------------------
9415 -- Needs_One_Actual --
9416 ----------------------
9418 function Needs_One_Actual (E : Entity_Id) return Boolean is
9422 if Ada_Version >= Ada_2005
9423 and then Present (First_Formal (E))
9425 Formal := Next_Formal (First_Formal (E));
9426 while Present (Formal) loop
9427 if No (Default_Value (Formal)) then
9431 Next_Formal (Formal);
9439 end Needs_One_Actual;
9441 ------------------------
9442 -- New_Copy_List_Tree --
9443 ------------------------
9445 function New_Copy_List_Tree (List : List_Id) return List_Id is
9450 if List = No_List then
9457 while Present (E) loop
9458 Append (New_Copy_Tree (E), NL);
9464 end New_Copy_List_Tree;
9470 use Atree.Unchecked_Access;
9471 use Atree_Private_Part;
9473 -- Our approach here requires a two pass traversal of the tree. The
9474 -- first pass visits all nodes that eventually will be copied looking
9475 -- for defining Itypes. If any defining Itypes are found, then they are
9476 -- copied, and an entry is added to the replacement map. In the second
9477 -- phase, the tree is copied, using the replacement map to replace any
9478 -- Itype references within the copied tree.
9480 -- The following hash tables are used if the Map supplied has more
9481 -- than hash threshold entries to speed up access to the map. If
9482 -- there are fewer entries, then the map is searched sequentially
9483 -- (because setting up a hash table for only a few entries takes
9484 -- more time than it saves.
9486 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
9487 -- Hash function used for hash operations
9493 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
9495 return Nat (E) mod (NCT_Header_Num'Last + 1);
9502 -- The hash table NCT_Assoc associates old entities in the table
9503 -- with their corresponding new entities (i.e. the pairs of entries
9504 -- presented in the original Map argument are Key-Element pairs).
9506 package NCT_Assoc is new Simple_HTable (
9507 Header_Num => NCT_Header_Num,
9508 Element => Entity_Id,
9509 No_Element => Empty,
9511 Hash => New_Copy_Hash,
9512 Equal => Types."=");
9514 ---------------------
9515 -- NCT_Itype_Assoc --
9516 ---------------------
9518 -- The hash table NCT_Itype_Assoc contains entries only for those
9519 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9520 -- The key is the associated node, and the element is the new node
9521 -- itself (NOT the associated node for the new node).
9523 package NCT_Itype_Assoc is new Simple_HTable (
9524 Header_Num => NCT_Header_Num,
9525 Element => Entity_Id,
9526 No_Element => Empty,
9528 Hash => New_Copy_Hash,
9529 Equal => Types."=");
9531 -- Start of processing for New_Copy_Tree function
9533 function New_Copy_Tree
9535 Map : Elist_Id := No_Elist;
9536 New_Sloc : Source_Ptr := No_Location;
9537 New_Scope : Entity_Id := Empty) return Node_Id
9539 Actual_Map : Elist_Id := Map;
9540 -- This is the actual map for the copy. It is initialized with the
9541 -- given elements, and then enlarged as required for Itypes that are
9542 -- copied during the first phase of the copy operation. The visit
9543 -- procedures add elements to this map as Itypes are encountered.
9544 -- The reason we cannot use Map directly, is that it may well be
9545 -- (and normally is) initialized to No_Elist, and if we have mapped
9546 -- entities, we have to reset it to point to a real Elist.
9548 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9549 -- Called during second phase to map entities into their corresponding
9550 -- copies using Actual_Map. If the argument is not an entity, or is not
9551 -- in Actual_Map, then it is returned unchanged.
9553 procedure Build_NCT_Hash_Tables;
9554 -- Builds hash tables (number of elements >= threshold value)
9556 function Copy_Elist_With_Replacement
9557 (Old_Elist : Elist_Id) return Elist_Id;
9558 -- Called during second phase to copy element list doing replacements
9560 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9561 -- Called during the second phase to process a copied Itype. The actual
9562 -- copy happened during the first phase (so that we could make the entry
9563 -- in the mapping), but we still have to deal with the descendents of
9564 -- the copied Itype and copy them where necessary.
9566 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9567 -- Called during second phase to copy list doing replacements
9569 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9570 -- Called during second phase to copy node doing replacements
9572 procedure Visit_Elist (E : Elist_Id);
9573 -- Called during first phase to visit all elements of an Elist
9575 procedure Visit_Field (F : Union_Id; N : Node_Id);
9576 -- Visit a single field, recursing to call Visit_Node or Visit_List
9577 -- if the field is a syntactic descendent of the current node (i.e.
9578 -- its parent is Node N).
9580 procedure Visit_Itype (Old_Itype : Entity_Id);
9581 -- Called during first phase to visit subsidiary fields of a defining
9582 -- Itype, and also create a copy and make an entry in the replacement
9583 -- map for the new copy.
9585 procedure Visit_List (L : List_Id);
9586 -- Called during first phase to visit all elements of a List
9588 procedure Visit_Node (N : Node_Or_Entity_Id);
9589 -- Called during first phase to visit a node and all its subtrees
9595 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9600 if not Has_Extension (N) or else No (Actual_Map) then
9603 elsif NCT_Hash_Tables_Used then
9604 Ent := NCT_Assoc.Get (Entity_Id (N));
9606 if Present (Ent) then
9612 -- No hash table used, do serial search
9615 E := First_Elmt (Actual_Map);
9616 while Present (E) loop
9617 if Node (E) = N then
9618 return Node (Next_Elmt (E));
9620 E := Next_Elmt (Next_Elmt (E));
9628 ---------------------------
9629 -- Build_NCT_Hash_Tables --
9630 ---------------------------
9632 procedure Build_NCT_Hash_Tables is
9636 if NCT_Hash_Table_Setup then
9638 NCT_Itype_Assoc.Reset;
9641 Elmt := First_Elmt (Actual_Map);
9642 while Present (Elmt) loop
9645 -- Get new entity, and associate old and new
9648 NCT_Assoc.Set (Ent, Node (Elmt));
9650 if Is_Type (Ent) then
9652 Anode : constant Entity_Id :=
9653 Associated_Node_For_Itype (Ent);
9656 if Present (Anode) then
9658 -- Enter a link between the associated node of the
9659 -- old Itype and the new Itype, for updating later
9660 -- when node is copied.
9662 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9670 NCT_Hash_Tables_Used := True;
9671 NCT_Hash_Table_Setup := True;
9672 end Build_NCT_Hash_Tables;
9674 ---------------------------------
9675 -- Copy_Elist_With_Replacement --
9676 ---------------------------------
9678 function Copy_Elist_With_Replacement
9679 (Old_Elist : Elist_Id) return Elist_Id
9682 New_Elist : Elist_Id;
9685 if No (Old_Elist) then
9689 New_Elist := New_Elmt_List;
9691 M := First_Elmt (Old_Elist);
9692 while Present (M) loop
9693 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9699 end Copy_Elist_With_Replacement;
9701 ---------------------------------
9702 -- Copy_Itype_With_Replacement --
9703 ---------------------------------
9705 -- This routine exactly parallels its phase one analog Visit_Itype,
9707 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9709 -- Translate Next_Entity, Scope and Etype fields, in case they
9710 -- reference entities that have been mapped into copies.
9712 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9713 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9715 if Present (New_Scope) then
9716 Set_Scope (New_Itype, New_Scope);
9718 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9721 -- Copy referenced fields
9723 if Is_Discrete_Type (New_Itype) then
9724 Set_Scalar_Range (New_Itype,
9725 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9727 elsif Has_Discriminants (Base_Type (New_Itype)) then
9728 Set_Discriminant_Constraint (New_Itype,
9729 Copy_Elist_With_Replacement
9730 (Discriminant_Constraint (New_Itype)));
9732 elsif Is_Array_Type (New_Itype) then
9733 if Present (First_Index (New_Itype)) then
9734 Set_First_Index (New_Itype,
9735 First (Copy_List_With_Replacement
9736 (List_Containing (First_Index (New_Itype)))));
9739 if Is_Packed (New_Itype) then
9740 Set_Packed_Array_Type (New_Itype,
9741 Copy_Node_With_Replacement
9742 (Packed_Array_Type (New_Itype)));
9745 end Copy_Itype_With_Replacement;
9747 --------------------------------
9748 -- Copy_List_With_Replacement --
9749 --------------------------------
9751 function Copy_List_With_Replacement
9752 (Old_List : List_Id) return List_Id
9758 if Old_List = No_List then
9762 New_List := Empty_List;
9764 E := First (Old_List);
9765 while Present (E) loop
9766 Append (Copy_Node_With_Replacement (E), New_List);
9772 end Copy_List_With_Replacement;
9774 --------------------------------
9775 -- Copy_Node_With_Replacement --
9776 --------------------------------
9778 function Copy_Node_With_Replacement
9779 (Old_Node : Node_Id) return Node_Id
9783 procedure Adjust_Named_Associations
9784 (Old_Node : Node_Id;
9785 New_Node : Node_Id);
9786 -- If a call node has named associations, these are chained through
9787 -- the First_Named_Actual, Next_Named_Actual links. These must be
9788 -- propagated separately to the new parameter list, because these
9789 -- are not syntactic fields.
9791 function Copy_Field_With_Replacement
9792 (Field : Union_Id) return Union_Id;
9793 -- Given Field, which is a field of Old_Node, return a copy of it
9794 -- if it is a syntactic field (i.e. its parent is Node), setting
9795 -- the parent of the copy to poit to New_Node. Otherwise returns
9796 -- the field (possibly mapped if it is an entity).
9798 -------------------------------
9799 -- Adjust_Named_Associations --
9800 -------------------------------
9802 procedure Adjust_Named_Associations
9803 (Old_Node : Node_Id;
9813 Old_E := First (Parameter_Associations (Old_Node));
9814 New_E := First (Parameter_Associations (New_Node));
9815 while Present (Old_E) loop
9816 if Nkind (Old_E) = N_Parameter_Association
9817 and then Present (Next_Named_Actual (Old_E))
9819 if First_Named_Actual (Old_Node)
9820 = Explicit_Actual_Parameter (Old_E)
9822 Set_First_Named_Actual
9823 (New_Node, Explicit_Actual_Parameter (New_E));
9826 -- Now scan parameter list from the beginning,to locate
9827 -- next named actual, which can be out of order.
9829 Old_Next := First (Parameter_Associations (Old_Node));
9830 New_Next := First (Parameter_Associations (New_Node));
9832 while Nkind (Old_Next) /= N_Parameter_Association
9833 or else Explicit_Actual_Parameter (Old_Next)
9834 /= Next_Named_Actual (Old_E)
9840 Set_Next_Named_Actual
9841 (New_E, Explicit_Actual_Parameter (New_Next));
9847 end Adjust_Named_Associations;
9849 ---------------------------------
9850 -- Copy_Field_With_Replacement --
9851 ---------------------------------
9853 function Copy_Field_With_Replacement
9854 (Field : Union_Id) return Union_Id
9857 if Field = Union_Id (Empty) then
9860 elsif Field in Node_Range then
9862 Old_N : constant Node_Id := Node_Id (Field);
9866 -- If syntactic field, as indicated by the parent pointer
9867 -- being set, then copy the referenced node recursively.
9869 if Parent (Old_N) = Old_Node then
9870 New_N := Copy_Node_With_Replacement (Old_N);
9872 if New_N /= Old_N then
9873 Set_Parent (New_N, New_Node);
9876 -- For semantic fields, update possible entity reference
9877 -- from the replacement map.
9880 New_N := Assoc (Old_N);
9883 return Union_Id (New_N);
9886 elsif Field in List_Range then
9888 Old_L : constant List_Id := List_Id (Field);
9892 -- If syntactic field, as indicated by the parent pointer,
9893 -- then recursively copy the entire referenced list.
9895 if Parent (Old_L) = Old_Node then
9896 New_L := Copy_List_With_Replacement (Old_L);
9897 Set_Parent (New_L, New_Node);
9899 -- For semantic list, just returned unchanged
9905 return Union_Id (New_L);
9908 -- Anything other than a list or a node is returned unchanged
9913 end Copy_Field_With_Replacement;
9915 -- Start of processing for Copy_Node_With_Replacement
9918 if Old_Node <= Empty_Or_Error then
9921 elsif Has_Extension (Old_Node) then
9922 return Assoc (Old_Node);
9925 New_Node := New_Copy (Old_Node);
9927 -- If the node we are copying is the associated node of a
9928 -- previously copied Itype, then adjust the associated node
9929 -- of the copy of that Itype accordingly.
9931 if Present (Actual_Map) then
9937 -- Case of hash table used
9939 if NCT_Hash_Tables_Used then
9940 Ent := NCT_Itype_Assoc.Get (Old_Node);
9942 if Present (Ent) then
9943 Set_Associated_Node_For_Itype (Ent, New_Node);
9946 -- Case of no hash table used
9949 E := First_Elmt (Actual_Map);
9950 while Present (E) loop
9951 if Is_Itype (Node (E))
9953 Old_Node = Associated_Node_For_Itype (Node (E))
9955 Set_Associated_Node_For_Itype
9956 (Node (Next_Elmt (E)), New_Node);
9959 E := Next_Elmt (Next_Elmt (E));
9965 -- Recursively copy descendents
9968 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9970 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9972 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9974 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9976 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9978 -- Adjust Sloc of new node if necessary
9980 if New_Sloc /= No_Location then
9981 Set_Sloc (New_Node, New_Sloc);
9983 -- If we adjust the Sloc, then we are essentially making
9984 -- a completely new node, so the Comes_From_Source flag
9985 -- should be reset to the proper default value.
9987 Nodes.Table (New_Node).Comes_From_Source :=
9988 Default_Node.Comes_From_Source;
9991 -- If the node is call and has named associations,
9992 -- set the corresponding links in the copy.
9994 if (Nkind (Old_Node) = N_Function_Call
9995 or else Nkind (Old_Node) = N_Entry_Call_Statement
9997 Nkind (Old_Node) = N_Procedure_Call_Statement)
9998 and then Present (First_Named_Actual (Old_Node))
10000 Adjust_Named_Associations (Old_Node, New_Node);
10003 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
10004 -- The replacement mechanism applies to entities, and is not used
10005 -- here. Eventually we may need a more general graph-copying
10006 -- routine. For now, do a sequential search to find desired node.
10008 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
10009 and then Present (First_Real_Statement (Old_Node))
10012 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
10016 N1 := First (Statements (Old_Node));
10017 N2 := First (Statements (New_Node));
10019 while N1 /= Old_F loop
10024 Set_First_Real_Statement (New_Node, N2);
10029 -- All done, return copied node
10032 end Copy_Node_With_Replacement;
10038 procedure Visit_Elist (E : Elist_Id) is
10041 if Present (E) then
10042 Elmt := First_Elmt (E);
10044 while Elmt /= No_Elmt loop
10045 Visit_Node (Node (Elmt));
10055 procedure Visit_Field (F : Union_Id; N : Node_Id) is
10057 if F = Union_Id (Empty) then
10060 elsif F in Node_Range then
10062 -- Copy node if it is syntactic, i.e. its parent pointer is
10063 -- set to point to the field that referenced it (certain
10064 -- Itypes will also meet this criterion, which is fine, since
10065 -- these are clearly Itypes that do need to be copied, since
10066 -- we are copying their parent.)
10068 if Parent (Node_Id (F)) = N then
10069 Visit_Node (Node_Id (F));
10072 -- Another case, if we are pointing to an Itype, then we want
10073 -- to copy it if its associated node is somewhere in the tree
10076 -- Note: the exclusion of self-referential copies is just an
10077 -- optimization, since the search of the already copied list
10078 -- would catch it, but it is a common case (Etype pointing
10079 -- to itself for an Itype that is a base type).
10081 elsif Has_Extension (Node_Id (F))
10082 and then Is_Itype (Entity_Id (F))
10083 and then Node_Id (F) /= N
10089 P := Associated_Node_For_Itype (Node_Id (F));
10090 while Present (P) loop
10092 Visit_Node (Node_Id (F));
10099 -- An Itype whose parent is not being copied definitely
10100 -- should NOT be copied, since it does not belong in any
10101 -- sense to the copied subtree.
10107 elsif F in List_Range
10108 and then Parent (List_Id (F)) = N
10110 Visit_List (List_Id (F));
10119 procedure Visit_Itype (Old_Itype : Entity_Id) is
10120 New_Itype : Entity_Id;
10125 -- Itypes that describe the designated type of access to subprograms
10126 -- have the structure of subprogram declarations, with signatures,
10127 -- etc. Either we duplicate the signatures completely, or choose to
10128 -- share such itypes, which is fine because their elaboration will
10129 -- have no side effects.
10131 if Ekind (Old_Itype) = E_Subprogram_Type then
10135 New_Itype := New_Copy (Old_Itype);
10137 -- The new Itype has all the attributes of the old one, and
10138 -- we just copy the contents of the entity. However, the back-end
10139 -- needs different names for debugging purposes, so we create a
10140 -- new internal name for it in all cases.
10142 Set_Chars (New_Itype, New_Internal_Name ('T'));
10144 -- If our associated node is an entity that has already been copied,
10145 -- then set the associated node of the copy to point to the right
10146 -- copy. If we have copied an Itype that is itself the associated
10147 -- node of some previously copied Itype, then we set the right
10148 -- pointer in the other direction.
10150 if Present (Actual_Map) then
10152 -- Case of hash tables used
10154 if NCT_Hash_Tables_Used then
10156 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
10158 if Present (Ent) then
10159 Set_Associated_Node_For_Itype (New_Itype, Ent);
10162 Ent := NCT_Itype_Assoc.Get (Old_Itype);
10163 if Present (Ent) then
10164 Set_Associated_Node_For_Itype (Ent, New_Itype);
10166 -- If the hash table has no association for this Itype and
10167 -- its associated node, enter one now.
10170 NCT_Itype_Assoc.Set
10171 (Associated_Node_For_Itype (Old_Itype), New_Itype);
10174 -- Case of hash tables not used
10177 E := First_Elmt (Actual_Map);
10178 while Present (E) loop
10179 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
10180 Set_Associated_Node_For_Itype
10181 (New_Itype, Node (Next_Elmt (E)));
10184 if Is_Type (Node (E))
10186 Old_Itype = Associated_Node_For_Itype (Node (E))
10188 Set_Associated_Node_For_Itype
10189 (Node (Next_Elmt (E)), New_Itype);
10192 E := Next_Elmt (Next_Elmt (E));
10197 if Present (Freeze_Node (New_Itype)) then
10198 Set_Is_Frozen (New_Itype, False);
10199 Set_Freeze_Node (New_Itype, Empty);
10202 -- Add new association to map
10204 if No (Actual_Map) then
10205 Actual_Map := New_Elmt_List;
10208 Append_Elmt (Old_Itype, Actual_Map);
10209 Append_Elmt (New_Itype, Actual_Map);
10211 if NCT_Hash_Tables_Used then
10212 NCT_Assoc.Set (Old_Itype, New_Itype);
10215 NCT_Table_Entries := NCT_Table_Entries + 1;
10217 if NCT_Table_Entries > NCT_Hash_Threshold then
10218 Build_NCT_Hash_Tables;
10222 -- If a record subtype is simply copied, the entity list will be
10223 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
10225 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
10226 Set_Cloned_Subtype (New_Itype, Old_Itype);
10229 -- Visit descendents that eventually get copied
10231 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
10233 if Is_Discrete_Type (Old_Itype) then
10234 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
10236 elsif Has_Discriminants (Base_Type (Old_Itype)) then
10237 -- ??? This should involve call to Visit_Field
10238 Visit_Elist (Discriminant_Constraint (Old_Itype));
10240 elsif Is_Array_Type (Old_Itype) then
10241 if Present (First_Index (Old_Itype)) then
10242 Visit_Field (Union_Id (List_Containing
10243 (First_Index (Old_Itype))),
10247 if Is_Packed (Old_Itype) then
10248 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
10258 procedure Visit_List (L : List_Id) is
10261 if L /= No_List then
10264 while Present (N) loop
10275 procedure Visit_Node (N : Node_Or_Entity_Id) is
10277 -- Start of processing for Visit_Node
10280 -- Handle case of an Itype, which must be copied
10282 if Has_Extension (N)
10283 and then Is_Itype (N)
10285 -- Nothing to do if already in the list. This can happen with an
10286 -- Itype entity that appears more than once in the tree.
10287 -- Note that we do not want to visit descendents in this case.
10289 -- Test for already in list when hash table is used
10291 if NCT_Hash_Tables_Used then
10292 if Present (NCT_Assoc.Get (Entity_Id (N))) then
10296 -- Test for already in list when hash table not used
10302 if Present (Actual_Map) then
10303 E := First_Elmt (Actual_Map);
10304 while Present (E) loop
10305 if Node (E) = N then
10308 E := Next_Elmt (Next_Elmt (E));
10318 -- Visit descendents
10320 Visit_Field (Field1 (N), N);
10321 Visit_Field (Field2 (N), N);
10322 Visit_Field (Field3 (N), N);
10323 Visit_Field (Field4 (N), N);
10324 Visit_Field (Field5 (N), N);
10327 -- Start of processing for New_Copy_Tree
10332 -- See if we should use hash table
10334 if No (Actual_Map) then
10335 NCT_Hash_Tables_Used := False;
10342 NCT_Table_Entries := 0;
10344 Elmt := First_Elmt (Actual_Map);
10345 while Present (Elmt) loop
10346 NCT_Table_Entries := NCT_Table_Entries + 1;
10351 if NCT_Table_Entries > NCT_Hash_Threshold then
10352 Build_NCT_Hash_Tables;
10354 NCT_Hash_Tables_Used := False;
10359 -- Hash table set up if required, now start phase one by visiting
10360 -- top node (we will recursively visit the descendents).
10362 Visit_Node (Source);
10364 -- Now the second phase of the copy can start. First we process
10365 -- all the mapped entities, copying their descendents.
10367 if Present (Actual_Map) then
10370 New_Itype : Entity_Id;
10372 Elmt := First_Elmt (Actual_Map);
10373 while Present (Elmt) loop
10375 New_Itype := Node (Elmt);
10376 Copy_Itype_With_Replacement (New_Itype);
10382 -- Now we can copy the actual tree
10384 return Copy_Node_With_Replacement (Source);
10387 -------------------------
10388 -- New_External_Entity --
10389 -------------------------
10391 function New_External_Entity
10392 (Kind : Entity_Kind;
10393 Scope_Id : Entity_Id;
10394 Sloc_Value : Source_Ptr;
10395 Related_Id : Entity_Id;
10396 Suffix : Character;
10397 Suffix_Index : Nat := 0;
10398 Prefix : Character := ' ') return Entity_Id
10400 N : constant Entity_Id :=
10401 Make_Defining_Identifier (Sloc_Value,
10403 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
10406 Set_Ekind (N, Kind);
10407 Set_Is_Internal (N, True);
10408 Append_Entity (N, Scope_Id);
10409 Set_Public_Status (N);
10411 if Kind in Type_Kind then
10412 Init_Size_Align (N);
10416 end New_External_Entity;
10418 -------------------------
10419 -- New_Internal_Entity --
10420 -------------------------
10422 function New_Internal_Entity
10423 (Kind : Entity_Kind;
10424 Scope_Id : Entity_Id;
10425 Sloc_Value : Source_Ptr;
10426 Id_Char : Character) return Entity_Id
10428 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
10431 Set_Ekind (N, Kind);
10432 Set_Is_Internal (N, True);
10433 Append_Entity (N, Scope_Id);
10435 if Kind in Type_Kind then
10436 Init_Size_Align (N);
10440 end New_Internal_Entity;
10446 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
10450 -- If we are pointing at a positional parameter, it is a member of a
10451 -- node list (the list of parameters), and the next parameter is the
10452 -- next node on the list, unless we hit a parameter association, then
10453 -- we shift to using the chain whose head is the First_Named_Actual in
10454 -- the parent, and then is threaded using the Next_Named_Actual of the
10455 -- Parameter_Association. All this fiddling is because the original node
10456 -- list is in the textual call order, and what we need is the
10457 -- declaration order.
10459 if Is_List_Member (Actual_Id) then
10460 N := Next (Actual_Id);
10462 if Nkind (N) = N_Parameter_Association then
10463 return First_Named_Actual (Parent (Actual_Id));
10469 return Next_Named_Actual (Parent (Actual_Id));
10473 procedure Next_Actual (Actual_Id : in out Node_Id) is
10475 Actual_Id := Next_Actual (Actual_Id);
10478 -----------------------
10479 -- Normalize_Actuals --
10480 -----------------------
10482 -- Chain actuals according to formals of subprogram. If there are no named
10483 -- associations, the chain is simply the list of Parameter Associations,
10484 -- since the order is the same as the declaration order. If there are named
10485 -- associations, then the First_Named_Actual field in the N_Function_Call
10486 -- or N_Procedure_Call_Statement node points to the Parameter_Association
10487 -- node for the parameter that comes first in declaration order. The
10488 -- remaining named parameters are then chained in declaration order using
10489 -- Next_Named_Actual.
10491 -- This routine also verifies that the number of actuals is compatible with
10492 -- the number and default values of formals, but performs no type checking
10493 -- (type checking is done by the caller).
10495 -- If the matching succeeds, Success is set to True and the caller proceeds
10496 -- with type-checking. If the match is unsuccessful, then Success is set to
10497 -- False, and the caller attempts a different interpretation, if there is
10500 -- If the flag Report is on, the call is not overloaded, and a failure to
10501 -- match can be reported here, rather than in the caller.
10503 procedure Normalize_Actuals
10507 Success : out Boolean)
10509 Actuals : constant List_Id := Parameter_Associations (N);
10510 Actual : Node_Id := Empty;
10511 Formal : Entity_Id;
10512 Last : Node_Id := Empty;
10513 First_Named : Node_Id := Empty;
10516 Formals_To_Match : Integer := 0;
10517 Actuals_To_Match : Integer := 0;
10519 procedure Chain (A : Node_Id);
10520 -- Add named actual at the proper place in the list, using the
10521 -- Next_Named_Actual link.
10523 function Reporting return Boolean;
10524 -- Determines if an error is to be reported. To report an error, we
10525 -- need Report to be True, and also we do not report errors caused
10526 -- by calls to init procs that occur within other init procs. Such
10527 -- errors must always be cascaded errors, since if all the types are
10528 -- declared correctly, the compiler will certainly build decent calls!
10534 procedure Chain (A : Node_Id) is
10538 -- Call node points to first actual in list
10540 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10543 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10547 Set_Next_Named_Actual (Last, Empty);
10554 function Reporting return Boolean is
10559 elsif not Within_Init_Proc then
10562 elsif Is_Init_Proc (Entity (Name (N))) then
10570 -- Start of processing for Normalize_Actuals
10573 if Is_Access_Type (S) then
10575 -- The name in the call is a function call that returns an access
10576 -- to subprogram. The designated type has the list of formals.
10578 Formal := First_Formal (Designated_Type (S));
10580 Formal := First_Formal (S);
10583 while Present (Formal) loop
10584 Formals_To_Match := Formals_To_Match + 1;
10585 Next_Formal (Formal);
10588 -- Find if there is a named association, and verify that no positional
10589 -- associations appear after named ones.
10591 if Present (Actuals) then
10592 Actual := First (Actuals);
10595 while Present (Actual)
10596 and then Nkind (Actual) /= N_Parameter_Association
10598 Actuals_To_Match := Actuals_To_Match + 1;
10602 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10604 -- Most common case: positional notation, no defaults
10609 elsif Actuals_To_Match > Formals_To_Match then
10611 -- Too many actuals: will not work
10614 if Is_Entity_Name (Name (N)) then
10615 Error_Msg_N ("too many arguments in call to&", Name (N));
10617 Error_Msg_N ("too many arguments in call", N);
10625 First_Named := Actual;
10627 while Present (Actual) loop
10628 if Nkind (Actual) /= N_Parameter_Association then
10630 ("positional parameters not allowed after named ones", Actual);
10635 Actuals_To_Match := Actuals_To_Match + 1;
10641 if Present (Actuals) then
10642 Actual := First (Actuals);
10645 Formal := First_Formal (S);
10646 while Present (Formal) loop
10648 -- Match the formals in order. If the corresponding actual is
10649 -- positional, nothing to do. Else scan the list of named actuals
10650 -- to find the one with the right name.
10652 if Present (Actual)
10653 and then Nkind (Actual) /= N_Parameter_Association
10656 Actuals_To_Match := Actuals_To_Match - 1;
10657 Formals_To_Match := Formals_To_Match - 1;
10660 -- For named parameters, search the list of actuals to find
10661 -- one that matches the next formal name.
10663 Actual := First_Named;
10665 while Present (Actual) loop
10666 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10669 Actuals_To_Match := Actuals_To_Match - 1;
10670 Formals_To_Match := Formals_To_Match - 1;
10678 if Ekind (Formal) /= E_In_Parameter
10679 or else No (Default_Value (Formal))
10682 if (Comes_From_Source (S)
10683 or else Sloc (S) = Standard_Location)
10684 and then Is_Overloadable (S)
10688 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10690 (Nkind (Parent (N)) = N_Function_Call
10692 Nkind (Parent (N)) = N_Parameter_Association))
10693 and then Ekind (S) /= E_Function
10695 Set_Etype (N, Etype (S));
10697 Error_Msg_Name_1 := Chars (S);
10698 Error_Msg_Sloc := Sloc (S);
10700 ("missing argument for parameter & " &
10701 "in call to % declared #", N, Formal);
10704 elsif Is_Overloadable (S) then
10705 Error_Msg_Name_1 := Chars (S);
10707 -- Point to type derivation that generated the
10710 Error_Msg_Sloc := Sloc (Parent (S));
10713 ("missing argument for parameter & " &
10714 "in call to % (inherited) #", N, Formal);
10718 ("missing argument for parameter &", N, Formal);
10726 Formals_To_Match := Formals_To_Match - 1;
10731 Next_Formal (Formal);
10734 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10741 -- Find some superfluous named actual that did not get
10742 -- attached to the list of associations.
10744 Actual := First (Actuals);
10745 while Present (Actual) loop
10746 if Nkind (Actual) = N_Parameter_Association
10747 and then Actual /= Last
10748 and then No (Next_Named_Actual (Actual))
10750 Error_Msg_N ("unmatched actual & in call",
10751 Selector_Name (Actual));
10762 end Normalize_Actuals;
10764 --------------------------------
10765 -- Note_Possible_Modification --
10766 --------------------------------
10768 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10769 Modification_Comes_From_Source : constant Boolean :=
10770 Comes_From_Source (Parent (N));
10776 -- Loop to find referenced entity, if there is one
10783 if Is_Entity_Name (Exp) then
10784 Ent := Entity (Exp);
10786 -- If the entity is missing, it is an undeclared identifier,
10787 -- and there is nothing to annotate.
10793 elsif Nkind (Exp) = N_Explicit_Dereference then
10795 P : constant Node_Id := Prefix (Exp);
10798 -- In formal verification mode, keep track of all reads and
10799 -- writes through explicit dereferences.
10802 Alfa.Generate_Dereference (N, 'm');
10805 if Nkind (P) = N_Selected_Component
10807 Entry_Formal (Entity (Selector_Name (P))))
10809 -- Case of a reference to an entry formal
10811 Ent := Entry_Formal (Entity (Selector_Name (P)));
10813 elsif Nkind (P) = N_Identifier
10814 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10815 and then Present (Expression (Parent (Entity (P))))
10816 and then Nkind (Expression (Parent (Entity (P))))
10819 -- Case of a reference to a value on which side effects have
10822 Exp := Prefix (Expression (Parent (Entity (P))));
10831 elsif Nkind (Exp) = N_Type_Conversion
10832 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10834 Exp := Expression (Exp);
10837 elsif Nkind (Exp) = N_Slice
10838 or else Nkind (Exp) = N_Indexed_Component
10839 or else Nkind (Exp) = N_Selected_Component
10841 Exp := Prefix (Exp);
10848 -- Now look for entity being referenced
10850 if Present (Ent) then
10851 if Is_Object (Ent) then
10852 if Comes_From_Source (Exp)
10853 or else Modification_Comes_From_Source
10855 -- Give warning if pragma unmodified given and we are
10856 -- sure this is a modification.
10858 if Has_Pragma_Unmodified (Ent) and then Sure then
10859 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10862 Set_Never_Set_In_Source (Ent, False);
10865 Set_Is_True_Constant (Ent, False);
10866 Set_Current_Value (Ent, Empty);
10867 Set_Is_Known_Null (Ent, False);
10869 if not Can_Never_Be_Null (Ent) then
10870 Set_Is_Known_Non_Null (Ent, False);
10873 -- Follow renaming chain
10875 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10876 and then Present (Renamed_Object (Ent))
10878 Exp := Renamed_Object (Ent);
10881 -- The expression may be the renaming of a subcomponent of an
10882 -- array or container. The assignment to the subcomponent is
10883 -- a modification of the container.
10885 elsif Comes_From_Source (Original_Node (Exp))
10886 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
10887 N_Indexed_Component)
10889 Exp := Prefix (Original_Node (Exp));
10893 -- Generate a reference only if the assignment comes from
10894 -- source. This excludes, for example, calls to a dispatching
10895 -- assignment operation when the left-hand side is tagged.
10897 if Modification_Comes_From_Source or else Alfa_Mode then
10898 Generate_Reference (Ent, Exp, 'm');
10900 -- If the target of the assignment is the bound variable
10901 -- in an iterator, indicate that the corresponding array
10902 -- or container is also modified.
10904 if Ada_Version >= Ada_2012
10906 Nkind (Parent (Ent)) = N_Iterator_Specification
10909 Domain : constant Node_Id := Name (Parent (Ent));
10912 -- TBD : in the full version of the construct, the
10913 -- domain of iteration can be given by an expression.
10915 if Is_Entity_Name (Domain) then
10916 Generate_Reference (Entity (Domain), Exp, 'm');
10917 Set_Is_True_Constant (Entity (Domain), False);
10918 Set_Never_Set_In_Source (Entity (Domain), False);
10924 Check_Nested_Access (Ent);
10929 -- If we are sure this is a modification from source, and we know
10930 -- this modifies a constant, then give an appropriate warning.
10932 if Overlays_Constant (Ent)
10933 and then Modification_Comes_From_Source
10937 A : constant Node_Id := Address_Clause (Ent);
10939 if Present (A) then
10941 Exp : constant Node_Id := Expression (A);
10943 if Nkind (Exp) = N_Attribute_Reference
10944 and then Attribute_Name (Exp) = Name_Address
10945 and then Is_Entity_Name (Prefix (Exp))
10947 Error_Msg_Sloc := Sloc (A);
10949 ("constant& may be modified via address clause#?",
10950 N, Entity (Prefix (Exp)));
10960 end Note_Possible_Modification;
10962 -------------------------
10963 -- Object_Access_Level --
10964 -------------------------
10966 function Object_Access_Level (Obj : Node_Id) return Uint is
10969 -- Returns the static accessibility level of the view denoted by Obj. Note
10970 -- that the value returned is the result of a call to Scope_Depth. Only
10971 -- scope depths associated with dynamic scopes can actually be returned.
10972 -- Since only relative levels matter for accessibility checking, the fact
10973 -- that the distance between successive levels of accessibility is not
10974 -- always one is immaterial (invariant: if level(E2) is deeper than
10975 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10977 function Reference_To (Obj : Node_Id) return Node_Id;
10978 -- An explicit dereference is created when removing side-effects from
10979 -- expressions for constraint checking purposes. In this case a local
10980 -- access type is created for it. The correct access level is that of
10981 -- the original source node. We detect this case by noting that the
10982 -- prefix of the dereference is created by an object declaration whose
10983 -- initial expression is a reference.
10989 function Reference_To (Obj : Node_Id) return Node_Id is
10990 Pref : constant Node_Id := Prefix (Obj);
10992 if Is_Entity_Name (Pref)
10993 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10994 and then Present (Expression (Parent (Entity (Pref))))
10995 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10997 return (Prefix (Expression (Parent (Entity (Pref)))));
11003 -- Start of processing for Object_Access_Level
11006 if Nkind (Obj) = N_Defining_Identifier
11007 or else Is_Entity_Name (Obj)
11009 if Nkind (Obj) = N_Defining_Identifier then
11015 if Is_Prival (E) then
11016 E := Prival_Link (E);
11019 -- If E is a type then it denotes a current instance. For this case
11020 -- we add one to the normal accessibility level of the type to ensure
11021 -- that current instances are treated as always being deeper than
11022 -- than the level of any visible named access type (see 3.10.2(21)).
11024 if Is_Type (E) then
11025 return Type_Access_Level (E) + 1;
11027 elsif Present (Renamed_Object (E)) then
11028 return Object_Access_Level (Renamed_Object (E));
11030 -- Similarly, if E is a component of the current instance of a
11031 -- protected type, any instance of it is assumed to be at a deeper
11032 -- level than the type. For a protected object (whose type is an
11033 -- anonymous protected type) its components are at the same level
11034 -- as the type itself.
11036 elsif not Is_Overloadable (E)
11037 and then Ekind (Scope (E)) = E_Protected_Type
11038 and then Comes_From_Source (Scope (E))
11040 return Type_Access_Level (Scope (E)) + 1;
11043 return Scope_Depth (Enclosing_Dynamic_Scope (E));
11046 elsif Nkind (Obj) = N_Selected_Component then
11047 if Is_Access_Type (Etype (Prefix (Obj))) then
11048 return Type_Access_Level (Etype (Prefix (Obj)));
11050 return Object_Access_Level (Prefix (Obj));
11053 elsif Nkind (Obj) = N_Indexed_Component then
11054 if Is_Access_Type (Etype (Prefix (Obj))) then
11055 return Type_Access_Level (Etype (Prefix (Obj)));
11057 return Object_Access_Level (Prefix (Obj));
11060 elsif Nkind (Obj) = N_Explicit_Dereference then
11062 -- If the prefix is a selected access discriminant then we make a
11063 -- recursive call on the prefix, which will in turn check the level
11064 -- of the prefix object of the selected discriminant.
11066 if Nkind (Prefix (Obj)) = N_Selected_Component
11067 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
11069 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
11071 return Object_Access_Level (Prefix (Obj));
11073 elsif not (Comes_From_Source (Obj)) then
11075 Ref : constant Node_Id := Reference_To (Obj);
11077 if Present (Ref) then
11078 return Object_Access_Level (Ref);
11080 return Type_Access_Level (Etype (Prefix (Obj)));
11085 return Type_Access_Level (Etype (Prefix (Obj)));
11088 elsif Nkind (Obj) = N_Type_Conversion
11089 or else Nkind (Obj) = N_Unchecked_Type_Conversion
11091 return Object_Access_Level (Expression (Obj));
11093 elsif Nkind (Obj) = N_Function_Call then
11095 -- Function results are objects, so we get either the access level of
11096 -- the function or, in the case of an indirect call, the level of the
11097 -- access-to-subprogram type. (This code is used for Ada 95, but it
11098 -- looks wrong, because it seems that we should be checking the level
11099 -- of the call itself, even for Ada 95. However, using the Ada 2005
11100 -- version of the code causes regressions in several tests that are
11101 -- compiled with -gnat95. ???)
11103 if Ada_Version < Ada_2005 then
11104 if Is_Entity_Name (Name (Obj)) then
11105 return Subprogram_Access_Level (Entity (Name (Obj)));
11107 return Type_Access_Level (Etype (Prefix (Name (Obj))));
11110 -- For Ada 2005, the level of the result object of a function call is
11111 -- defined to be the level of the call's innermost enclosing master.
11112 -- We determine that by querying the depth of the innermost enclosing
11116 Return_Master_Scope_Depth_Of_Call : declare
11118 function Innermost_Master_Scope_Depth
11119 (N : Node_Id) return Uint;
11120 -- Returns the scope depth of the given node's innermost
11121 -- enclosing dynamic scope (effectively the accessibility
11122 -- level of the innermost enclosing master).
11124 ----------------------------------
11125 -- Innermost_Master_Scope_Depth --
11126 ----------------------------------
11128 function Innermost_Master_Scope_Depth
11129 (N : Node_Id) return Uint
11131 Node_Par : Node_Id := Parent (N);
11134 -- Locate the nearest enclosing node (by traversing Parents)
11135 -- that Defining_Entity can be applied to, and return the
11136 -- depth of that entity's nearest enclosing dynamic scope.
11138 while Present (Node_Par) loop
11139 case Nkind (Node_Par) is
11140 when N_Component_Declaration |
11141 N_Entry_Declaration |
11142 N_Formal_Object_Declaration |
11143 N_Formal_Type_Declaration |
11144 N_Full_Type_Declaration |
11145 N_Incomplete_Type_Declaration |
11146 N_Loop_Parameter_Specification |
11147 N_Object_Declaration |
11148 N_Protected_Type_Declaration |
11149 N_Private_Extension_Declaration |
11150 N_Private_Type_Declaration |
11151 N_Subtype_Declaration |
11152 N_Function_Specification |
11153 N_Procedure_Specification |
11154 N_Task_Type_Declaration |
11156 N_Generic_Instantiation |
11158 N_Implicit_Label_Declaration |
11159 N_Package_Declaration |
11160 N_Single_Task_Declaration |
11161 N_Subprogram_Declaration |
11162 N_Generic_Declaration |
11163 N_Renaming_Declaration |
11164 N_Block_Statement |
11165 N_Formal_Subprogram_Declaration |
11166 N_Abstract_Subprogram_Declaration |
11168 N_Exception_Declaration |
11169 N_Formal_Package_Declaration |
11170 N_Number_Declaration |
11171 N_Package_Specification |
11172 N_Parameter_Specification |
11173 N_Single_Protected_Declaration |
11177 (Nearest_Dynamic_Scope
11178 (Defining_Entity (Node_Par)));
11184 Node_Par := Parent (Node_Par);
11187 pragma Assert (False);
11189 -- Should never reach the following return
11191 return Scope_Depth (Current_Scope) + 1;
11192 end Innermost_Master_Scope_Depth;
11194 -- Start of processing for Return_Master_Scope_Depth_Of_Call
11197 return Innermost_Master_Scope_Depth (Obj);
11198 end Return_Master_Scope_Depth_Of_Call;
11201 -- For convenience we handle qualified expressions, even though
11202 -- they aren't technically object names.
11204 elsif Nkind (Obj) = N_Qualified_Expression then
11205 return Object_Access_Level (Expression (Obj));
11207 -- Otherwise return the scope level of Standard.
11208 -- (If there are cases that fall through
11209 -- to this point they will be treated as
11210 -- having global accessibility for now. ???)
11213 return Scope_Depth (Standard_Standard);
11215 end Object_Access_Level;
11217 --------------------------------------
11218 -- Original_Corresponding_Operation --
11219 --------------------------------------
11221 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
11223 Typ : constant Entity_Id := Find_Dispatching_Type (S);
11226 -- If S is an inherited primitive S2 the original corresponding
11227 -- operation of S is the original corresponding operation of S2
11229 if Present (Alias (S))
11230 and then Find_Dispatching_Type (Alias (S)) /= Typ
11232 return Original_Corresponding_Operation (Alias (S));
11234 -- If S overrides an inherited subprogram S2 the original corresponding
11235 -- operation of S is the original corresponding operation of S2
11237 elsif Present (Overridden_Operation (S)) then
11238 return Original_Corresponding_Operation (Overridden_Operation (S));
11240 -- otherwise it is S itself
11245 end Original_Corresponding_Operation;
11247 -----------------------
11248 -- Private_Component --
11249 -----------------------
11251 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
11252 Ancestor : constant Entity_Id := Base_Type (Type_Id);
11254 function Trace_Components
11256 Check : Boolean) return Entity_Id;
11257 -- Recursive function that does the work, and checks against circular
11258 -- definition for each subcomponent type.
11260 ----------------------
11261 -- Trace_Components --
11262 ----------------------
11264 function Trace_Components
11266 Check : Boolean) return Entity_Id
11268 Btype : constant Entity_Id := Base_Type (T);
11269 Component : Entity_Id;
11271 Candidate : Entity_Id := Empty;
11274 if Check and then Btype = Ancestor then
11275 Error_Msg_N ("circular type definition", Type_Id);
11279 if Is_Private_Type (Btype)
11280 and then not Is_Generic_Type (Btype)
11282 if Present (Full_View (Btype))
11283 and then Is_Record_Type (Full_View (Btype))
11284 and then not Is_Frozen (Btype)
11286 -- To indicate that the ancestor depends on a private type, the
11287 -- current Btype is sufficient. However, to check for circular
11288 -- definition we must recurse on the full view.
11290 Candidate := Trace_Components (Full_View (Btype), True);
11292 if Candidate = Any_Type then
11302 elsif Is_Array_Type (Btype) then
11303 return Trace_Components (Component_Type (Btype), True);
11305 elsif Is_Record_Type (Btype) then
11306 Component := First_Entity (Btype);
11307 while Present (Component)
11308 and then Comes_From_Source (Component)
11310 -- Skip anonymous types generated by constrained components
11312 if not Is_Type (Component) then
11313 P := Trace_Components (Etype (Component), True);
11315 if Present (P) then
11316 if P = Any_Type then
11324 Next_Entity (Component);
11332 end Trace_Components;
11334 -- Start of processing for Private_Component
11337 return Trace_Components (Type_Id, False);
11338 end Private_Component;
11340 ---------------------------
11341 -- Primitive_Names_Match --
11342 ---------------------------
11344 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
11346 function Non_Internal_Name (E : Entity_Id) return Name_Id;
11347 -- Given an internal name, returns the corresponding non-internal name
11349 ------------------------
11350 -- Non_Internal_Name --
11351 ------------------------
11353 function Non_Internal_Name (E : Entity_Id) return Name_Id is
11355 Get_Name_String (Chars (E));
11356 Name_Len := Name_Len - 1;
11358 end Non_Internal_Name;
11360 -- Start of processing for Primitive_Names_Match
11363 pragma Assert (Present (E1) and then Present (E2));
11365 return Chars (E1) = Chars (E2)
11367 (not Is_Internal_Name (Chars (E1))
11368 and then Is_Internal_Name (Chars (E2))
11369 and then Non_Internal_Name (E2) = Chars (E1))
11371 (not Is_Internal_Name (Chars (E2))
11372 and then Is_Internal_Name (Chars (E1))
11373 and then Non_Internal_Name (E1) = Chars (E2))
11375 (Is_Predefined_Dispatching_Operation (E1)
11376 and then Is_Predefined_Dispatching_Operation (E2)
11377 and then Same_TSS (E1, E2))
11379 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
11380 end Primitive_Names_Match;
11382 -----------------------
11383 -- Process_End_Label --
11384 -----------------------
11386 procedure Process_End_Label
11395 Label_Ref : Boolean;
11396 -- Set True if reference to end label itself is required
11399 -- Gets set to the operator symbol or identifier that references the
11400 -- entity Ent. For the child unit case, this is the identifier from the
11401 -- designator. For other cases, this is simply Endl.
11403 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
11404 -- N is an identifier node that appears as a parent unit reference in
11405 -- the case where Ent is a child unit. This procedure generates an
11406 -- appropriate cross-reference entry. E is the corresponding entity.
11408 -------------------------
11409 -- Generate_Parent_Ref --
11410 -------------------------
11412 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
11414 -- If names do not match, something weird, skip reference
11416 if Chars (E) = Chars (N) then
11418 -- Generate the reference. We do NOT consider this as a reference
11419 -- for unreferenced symbol purposes.
11421 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
11423 if Style_Check then
11424 Style.Check_Identifier (N, E);
11427 end Generate_Parent_Ref;
11429 -- Start of processing for Process_End_Label
11432 -- If no node, ignore. This happens in some error situations, and
11433 -- also for some internally generated structures where no end label
11434 -- references are required in any case.
11440 -- Nothing to do if no End_Label, happens for internally generated
11441 -- constructs where we don't want an end label reference anyway. Also
11442 -- nothing to do if Endl is a string literal, which means there was
11443 -- some prior error (bad operator symbol)
11445 Endl := End_Label (N);
11447 if No (Endl) or else Nkind (Endl) = N_String_Literal then
11451 -- Reference node is not in extended main source unit
11453 if not In_Extended_Main_Source_Unit (N) then
11455 -- Generally we do not collect references except for the extended
11456 -- main source unit. The one exception is the 'e' entry for a
11457 -- package spec, where it is useful for a client to have the
11458 -- ending information to define scopes.
11464 Label_Ref := False;
11466 -- For this case, we can ignore any parent references, but we
11467 -- need the package name itself for the 'e' entry.
11469 if Nkind (Endl) = N_Designator then
11470 Endl := Identifier (Endl);
11474 -- Reference is in extended main source unit
11479 -- For designator, generate references for the parent entries
11481 if Nkind (Endl) = N_Designator then
11483 -- Generate references for the prefix if the END line comes from
11484 -- source (otherwise we do not need these references) We climb the
11485 -- scope stack to find the expected entities.
11487 if Comes_From_Source (Endl) then
11488 Nam := Name (Endl);
11489 Scop := Current_Scope;
11490 while Nkind (Nam) = N_Selected_Component loop
11491 Scop := Scope (Scop);
11492 exit when No (Scop);
11493 Generate_Parent_Ref (Selector_Name (Nam), Scop);
11494 Nam := Prefix (Nam);
11497 if Present (Scop) then
11498 Generate_Parent_Ref (Nam, Scope (Scop));
11502 Endl := Identifier (Endl);
11506 -- If the end label is not for the given entity, then either we have
11507 -- some previous error, or this is a generic instantiation for which
11508 -- we do not need to make a cross-reference in this case anyway. In
11509 -- either case we simply ignore the call.
11511 if Chars (Ent) /= Chars (Endl) then
11515 -- If label was really there, then generate a normal reference and then
11516 -- adjust the location in the end label to point past the name (which
11517 -- should almost always be the semicolon).
11519 Loc := Sloc (Endl);
11521 if Comes_From_Source (Endl) then
11523 -- If a label reference is required, then do the style check and
11524 -- generate an l-type cross-reference entry for the label
11527 if Style_Check then
11528 Style.Check_Identifier (Endl, Ent);
11531 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
11534 -- Set the location to point past the label (normally this will
11535 -- mean the semicolon immediately following the label). This is
11536 -- done for the sake of the 'e' or 't' entry generated below.
11538 Get_Decoded_Name_String (Chars (Endl));
11539 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11542 -- In SPARK mode, no missing label is allowed for packages and
11543 -- subprogram bodies. Detect those cases by testing whether
11544 -- Process_End_Label was called for a body (Typ = 't') or a package.
11546 if Restriction_Check_Required (SPARK)
11547 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11549 Error_Msg_Node_1 := Endl;
11550 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11554 -- Now generate the e/t reference
11556 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11558 -- Restore Sloc, in case modified above, since we have an identifier
11559 -- and the normal Sloc should be left set in the tree.
11561 Set_Sloc (Endl, Loc);
11562 end Process_End_Label;
11564 ------------------------------------
11565 -- References_Generic_Formal_Type --
11566 ------------------------------------
11568 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11570 function Process (N : Node_Id) return Traverse_Result;
11571 -- Process one node in search for generic formal type
11577 function Process (N : Node_Id) return Traverse_Result is
11579 if Nkind (N) in N_Has_Entity then
11581 E : constant Entity_Id := Entity (N);
11583 if Present (E) then
11584 if Is_Generic_Type (E) then
11586 elsif Present (Etype (E))
11587 and then Is_Generic_Type (Etype (E))
11598 function Traverse is new Traverse_Func (Process);
11599 -- Traverse tree to look for generic type
11602 if Inside_A_Generic then
11603 return Traverse (N) = Abandon;
11607 end References_Generic_Formal_Type;
11609 --------------------
11610 -- Remove_Homonym --
11611 --------------------
11613 procedure Remove_Homonym (E : Entity_Id) is
11614 Prev : Entity_Id := Empty;
11618 if E = Current_Entity (E) then
11619 if Present (Homonym (E)) then
11620 Set_Current_Entity (Homonym (E));
11622 Set_Name_Entity_Id (Chars (E), Empty);
11625 H := Current_Entity (E);
11626 while Present (H) and then H /= E loop
11631 Set_Homonym (Prev, Homonym (E));
11633 end Remove_Homonym;
11635 ---------------------
11636 -- Rep_To_Pos_Flag --
11637 ---------------------
11639 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11641 return New_Occurrence_Of
11642 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11643 end Rep_To_Pos_Flag;
11645 --------------------
11646 -- Require_Entity --
11647 --------------------
11649 procedure Require_Entity (N : Node_Id) is
11651 if Is_Entity_Name (N) and then No (Entity (N)) then
11652 if Total_Errors_Detected /= 0 then
11653 Set_Entity (N, Any_Id);
11655 raise Program_Error;
11658 end Require_Entity;
11660 ------------------------------
11661 -- Requires_Transient_Scope --
11662 ------------------------------
11664 -- A transient scope is required when variable-sized temporaries are
11665 -- allocated in the primary or secondary stack, or when finalization
11666 -- actions must be generated before the next instruction.
11668 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11669 Typ : constant Entity_Id := Underlying_Type (Id);
11671 -- Start of processing for Requires_Transient_Scope
11674 -- This is a private type which is not completed yet. This can only
11675 -- happen in a default expression (of a formal parameter or of a
11676 -- record component). Do not expand transient scope in this case
11681 -- Do not expand transient scope for non-existent procedure return
11683 elsif Typ = Standard_Void_Type then
11686 -- Elementary types do not require a transient scope
11688 elsif Is_Elementary_Type (Typ) then
11691 -- Generally, indefinite subtypes require a transient scope, since the
11692 -- back end cannot generate temporaries, since this is not a valid type
11693 -- for declaring an object. It might be possible to relax this in the
11694 -- future, e.g. by declaring the maximum possible space for the type.
11696 elsif Is_Indefinite_Subtype (Typ) then
11699 -- Functions returning tagged types may dispatch on result so their
11700 -- returned value is allocated on the secondary stack. Controlled
11701 -- type temporaries need finalization.
11703 elsif Is_Tagged_Type (Typ)
11704 or else Has_Controlled_Component (Typ)
11706 return not Is_Value_Type (Typ);
11710 elsif Is_Record_Type (Typ) then
11714 Comp := First_Entity (Typ);
11715 while Present (Comp) loop
11716 if Ekind (Comp) = E_Component
11717 and then Requires_Transient_Scope (Etype (Comp))
11721 Next_Entity (Comp);
11728 -- String literal types never require transient scope
11730 elsif Ekind (Typ) = E_String_Literal_Subtype then
11733 -- Array type. Note that we already know that this is a constrained
11734 -- array, since unconstrained arrays will fail the indefinite test.
11736 elsif Is_Array_Type (Typ) then
11738 -- If component type requires a transient scope, the array does too
11740 if Requires_Transient_Scope (Component_Type (Typ)) then
11743 -- Otherwise, we only need a transient scope if the size depends on
11744 -- the value of one or more discriminants.
11747 return Size_Depends_On_Discriminant (Typ);
11750 -- All other cases do not require a transient scope
11755 end Requires_Transient_Scope;
11757 --------------------------
11758 -- Reset_Analyzed_Flags --
11759 --------------------------
11761 procedure Reset_Analyzed_Flags (N : Node_Id) is
11763 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11764 -- Function used to reset Analyzed flags in tree. Note that we do
11765 -- not reset Analyzed flags in entities, since there is no need to
11766 -- reanalyze entities, and indeed, it is wrong to do so, since it
11767 -- can result in generating auxiliary stuff more than once.
11769 --------------------
11770 -- Clear_Analyzed --
11771 --------------------
11773 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11775 if not Has_Extension (N) then
11776 Set_Analyzed (N, False);
11780 end Clear_Analyzed;
11782 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11784 -- Start of processing for Reset_Analyzed_Flags
11787 Reset_Analyzed (N);
11788 end Reset_Analyzed_Flags;
11790 ---------------------------
11791 -- Safe_To_Capture_Value --
11792 ---------------------------
11794 function Safe_To_Capture_Value
11797 Cond : Boolean := False) return Boolean
11800 -- The only entities for which we track constant values are variables
11801 -- which are not renamings, constants, out parameters, and in out
11802 -- parameters, so check if we have this case.
11804 -- Note: it may seem odd to track constant values for constants, but in
11805 -- fact this routine is used for other purposes than simply capturing
11806 -- the value. In particular, the setting of Known[_Non]_Null.
11808 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11810 Ekind (Ent) = E_Constant
11812 Ekind (Ent) = E_Out_Parameter
11814 Ekind (Ent) = E_In_Out_Parameter
11818 -- For conditionals, we also allow loop parameters and all formals,
11819 -- including in parameters.
11823 (Ekind (Ent) = E_Loop_Parameter
11825 Ekind (Ent) = E_In_Parameter)
11829 -- For all other cases, not just unsafe, but impossible to capture
11830 -- Current_Value, since the above are the only entities which have
11831 -- Current_Value fields.
11837 -- Skip if volatile or aliased, since funny things might be going on in
11838 -- these cases which we cannot necessarily track. Also skip any variable
11839 -- for which an address clause is given, or whose address is taken. Also
11840 -- never capture value of library level variables (an attempt to do so
11841 -- can occur in the case of package elaboration code).
11843 if Treat_As_Volatile (Ent)
11844 or else Is_Aliased (Ent)
11845 or else Present (Address_Clause (Ent))
11846 or else Address_Taken (Ent)
11847 or else (Is_Library_Level_Entity (Ent)
11848 and then Ekind (Ent) = E_Variable)
11853 -- OK, all above conditions are met. We also require that the scope of
11854 -- the reference be the same as the scope of the entity, not counting
11855 -- packages and blocks and loops.
11858 E_Scope : constant Entity_Id := Scope (Ent);
11859 R_Scope : Entity_Id;
11862 R_Scope := Current_Scope;
11863 while R_Scope /= Standard_Standard loop
11864 exit when R_Scope = E_Scope;
11866 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11869 R_Scope := Scope (R_Scope);
11874 -- We also require that the reference does not appear in a context
11875 -- where it is not sure to be executed (i.e. a conditional context
11876 -- or an exception handler). We skip this if Cond is True, since the
11877 -- capturing of values from conditional tests handles this ok.
11891 while Present (P) loop
11892 if Nkind (P) = N_If_Statement
11893 or else Nkind (P) = N_Case_Statement
11894 or else (Nkind (P) in N_Short_Circuit
11895 and then Desc = Right_Opnd (P))
11896 or else (Nkind (P) = N_Conditional_Expression
11897 and then Desc /= First (Expressions (P)))
11898 or else Nkind (P) = N_Exception_Handler
11899 or else Nkind (P) = N_Selective_Accept
11900 or else Nkind (P) = N_Conditional_Entry_Call
11901 or else Nkind (P) = N_Timed_Entry_Call
11902 or else Nkind (P) = N_Asynchronous_Select
11912 -- OK, looks safe to set value
11915 end Safe_To_Capture_Value;
11921 function Same_Name (N1, N2 : Node_Id) return Boolean is
11922 K1 : constant Node_Kind := Nkind (N1);
11923 K2 : constant Node_Kind := Nkind (N2);
11926 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11927 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11929 return Chars (N1) = Chars (N2);
11931 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11932 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11934 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11935 and then Same_Name (Prefix (N1), Prefix (N2));
11946 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11947 N1 : constant Node_Id := Original_Node (Node1);
11948 N2 : constant Node_Id := Original_Node (Node2);
11949 -- We do the tests on original nodes, since we are most interested
11950 -- in the original source, not any expansion that got in the way.
11952 K1 : constant Node_Kind := Nkind (N1);
11953 K2 : constant Node_Kind := Nkind (N2);
11956 -- First case, both are entities with same entity
11958 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11960 EN1 : constant Entity_Id := Entity (N1);
11961 EN2 : constant Entity_Id := Entity (N2);
11963 if Present (EN1) and then Present (EN2)
11964 and then (Ekind_In (EN1, E_Variable, E_Constant)
11965 or else Is_Formal (EN1))
11973 -- Second case, selected component with same selector, same record
11975 if K1 = N_Selected_Component
11976 and then K2 = N_Selected_Component
11977 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11979 return Same_Object (Prefix (N1), Prefix (N2));
11981 -- Third case, indexed component with same subscripts, same array
11983 elsif K1 = N_Indexed_Component
11984 and then K2 = N_Indexed_Component
11985 and then Same_Object (Prefix (N1), Prefix (N2))
11990 E1 := First (Expressions (N1));
11991 E2 := First (Expressions (N2));
11992 while Present (E1) loop
11993 if not Same_Value (E1, E2) then
12004 -- Fourth case, slice of same array with same bounds
12007 and then K2 = N_Slice
12008 and then Nkind (Discrete_Range (N1)) = N_Range
12009 and then Nkind (Discrete_Range (N2)) = N_Range
12010 and then Same_Value (Low_Bound (Discrete_Range (N1)),
12011 Low_Bound (Discrete_Range (N2)))
12012 and then Same_Value (High_Bound (Discrete_Range (N1)),
12013 High_Bound (Discrete_Range (N2)))
12015 return Same_Name (Prefix (N1), Prefix (N2));
12017 -- All other cases, not clearly the same object
12028 function Same_Type (T1, T2 : Entity_Id) return Boolean is
12033 elsif not Is_Constrained (T1)
12034 and then not Is_Constrained (T2)
12035 and then Base_Type (T1) = Base_Type (T2)
12039 -- For now don't bother with case of identical constraints, to be
12040 -- fiddled with later on perhaps (this is only used for optimization
12041 -- purposes, so it is not critical to do a best possible job)
12052 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
12054 if Compile_Time_Known_Value (Node1)
12055 and then Compile_Time_Known_Value (Node2)
12056 and then Expr_Value (Node1) = Expr_Value (Node2)
12059 elsif Same_Object (Node1, Node2) then
12070 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
12072 if Ada_Version < Ada_2012 then
12075 elsif Is_Entity_Name (N)
12077 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
12079 (Nkind (N) = N_Attribute_Reference
12080 and then Attribute_Name (N) = Name_Access)
12083 -- We are only interested in IN OUT parameters of inner calls
12086 or else Nkind (Parent (N)) = N_Function_Call
12087 or else Nkind (Parent (N)) in N_Op
12089 Actuals_In_Call.Increment_Last;
12090 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
12095 ------------------------
12096 -- Scope_Is_Transient --
12097 ------------------------
12099 function Scope_Is_Transient return Boolean is
12101 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
12102 end Scope_Is_Transient;
12108 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
12113 while Scop /= Standard_Standard loop
12114 Scop := Scope (Scop);
12116 if Scop = Scope2 then
12124 --------------------------
12125 -- Scope_Within_Or_Same --
12126 --------------------------
12128 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
12133 while Scop /= Standard_Standard loop
12134 if Scop = Scope2 then
12137 Scop := Scope (Scop);
12142 end Scope_Within_Or_Same;
12144 --------------------
12145 -- Set_Convention --
12146 --------------------
12148 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
12150 Basic_Set_Convention (E, Val);
12153 and then Is_Access_Subprogram_Type (Base_Type (E))
12154 and then Has_Foreign_Convention (E)
12156 Set_Can_Use_Internal_Rep (E, False);
12158 end Set_Convention;
12160 ------------------------
12161 -- Set_Current_Entity --
12162 ------------------------
12164 -- The given entity is to be set as the currently visible definition of its
12165 -- associated name (i.e. the Node_Id associated with its name). All we have
12166 -- to do is to get the name from the identifier, and then set the
12167 -- associated Node_Id to point to the given entity.
12169 procedure Set_Current_Entity (E : Entity_Id) is
12171 Set_Name_Entity_Id (Chars (E), E);
12172 end Set_Current_Entity;
12174 ---------------------------
12175 -- Set_Debug_Info_Needed --
12176 ---------------------------
12178 procedure Set_Debug_Info_Needed (T : Entity_Id) is
12180 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
12181 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
12182 -- Used to set debug info in a related node if not set already
12184 --------------------------------------
12185 -- Set_Debug_Info_Needed_If_Not_Set --
12186 --------------------------------------
12188 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
12191 and then not Needs_Debug_Info (E)
12193 Set_Debug_Info_Needed (E);
12195 -- For a private type, indicate that the full view also needs
12196 -- debug information.
12199 and then Is_Private_Type (E)
12200 and then Present (Full_View (E))
12202 Set_Debug_Info_Needed (Full_View (E));
12205 end Set_Debug_Info_Needed_If_Not_Set;
12207 -- Start of processing for Set_Debug_Info_Needed
12210 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
12211 -- indicates that Debug_Info_Needed is never required for the entity.
12214 or else Debug_Info_Off (T)
12219 -- Set flag in entity itself. Note that we will go through the following
12220 -- circuitry even if the flag is already set on T. That's intentional,
12221 -- it makes sure that the flag will be set in subsidiary entities.
12223 Set_Needs_Debug_Info (T);
12225 -- Set flag on subsidiary entities if not set already
12227 if Is_Object (T) then
12228 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12230 elsif Is_Type (T) then
12231 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
12233 if Is_Record_Type (T) then
12235 Ent : Entity_Id := First_Entity (T);
12237 while Present (Ent) loop
12238 Set_Debug_Info_Needed_If_Not_Set (Ent);
12243 -- For a class wide subtype, we also need debug information
12244 -- for the equivalent type.
12246 if Ekind (T) = E_Class_Wide_Subtype then
12247 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
12250 elsif Is_Array_Type (T) then
12251 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
12254 Indx : Node_Id := First_Index (T);
12256 while Present (Indx) loop
12257 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
12258 Indx := Next_Index (Indx);
12262 if Is_Packed (T) then
12263 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
12266 elsif Is_Access_Type (T) then
12267 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
12269 elsif Is_Private_Type (T) then
12270 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
12272 elsif Is_Protected_Type (T) then
12273 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
12276 end Set_Debug_Info_Needed;
12278 ---------------------------------
12279 -- Set_Entity_With_Style_Check --
12280 ---------------------------------
12282 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
12283 Val_Actual : Entity_Id;
12287 -- Unconditionally set the entity
12289 Set_Entity (N, Val);
12291 -- Check for No_Implementation_Identifiers
12293 if Restriction_Check_Required (No_Implementation_Identifiers) then
12295 -- We have an implementation defined entity if it is marked as
12296 -- implementation defined, or is defined in a package marked as
12297 -- implementation defined. However, library packages themselves
12298 -- are excluded (we don't want to flag Interfaces itself, just
12299 -- the entities within it).
12301 if (Is_Implementation_Defined (Val)
12302 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
12303 and then Is_Library_Level_Entity (Val)))
12304 or else Is_Implementation_Defined (Scope (Val))
12306 Check_Restriction (No_Implementation_Identifiers, N);
12310 -- Do the style check
12313 and then not Suppress_Style_Checks (Val)
12314 and then not In_Instance
12316 if Nkind (N) = N_Identifier then
12318 elsif Nkind (N) = N_Expanded_Name then
12319 Nod := Selector_Name (N);
12324 -- A special situation arises for derived operations, where we want
12325 -- to do the check against the parent (since the Sloc of the derived
12326 -- operation points to the derived type declaration itself).
12329 while not Comes_From_Source (Val_Actual)
12330 and then Nkind (Val_Actual) in N_Entity
12331 and then (Ekind (Val_Actual) = E_Enumeration_Literal
12332 or else Is_Subprogram (Val_Actual)
12333 or else Is_Generic_Subprogram (Val_Actual))
12334 and then Present (Alias (Val_Actual))
12336 Val_Actual := Alias (Val_Actual);
12339 -- Renaming declarations for generic actuals do not come from source,
12340 -- and have a different name from that of the entity they rename, so
12341 -- there is no style check to perform here.
12343 if Chars (Nod) = Chars (Val_Actual) then
12344 Style.Check_Identifier (Nod, Val_Actual);
12348 Set_Entity (N, Val);
12349 end Set_Entity_With_Style_Check;
12351 ------------------------
12352 -- Set_Name_Entity_Id --
12353 ------------------------
12355 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
12357 Set_Name_Table_Info (Id, Int (Val));
12358 end Set_Name_Entity_Id;
12360 ---------------------
12361 -- Set_Next_Actual --
12362 ---------------------
12364 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
12366 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
12367 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
12369 end Set_Next_Actual;
12371 ----------------------------------
12372 -- Set_Optimize_Alignment_Flags --
12373 ----------------------------------
12375 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
12377 if Optimize_Alignment = 'S' then
12378 Set_Optimize_Alignment_Space (E);
12379 elsif Optimize_Alignment = 'T' then
12380 Set_Optimize_Alignment_Time (E);
12382 end Set_Optimize_Alignment_Flags;
12384 -----------------------
12385 -- Set_Public_Status --
12386 -----------------------
12388 procedure Set_Public_Status (Id : Entity_Id) is
12389 S : constant Entity_Id := Current_Scope;
12391 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
12392 -- Determines if E is defined within handled statement sequence or
12393 -- an if statement, returns True if so, False otherwise.
12395 ----------------------
12396 -- Within_HSS_Or_If --
12397 ----------------------
12399 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
12402 N := Declaration_Node (E);
12409 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
12415 end Within_HSS_Or_If;
12417 -- Start of processing for Set_Public_Status
12420 -- Everything in the scope of Standard is public
12422 if S = Standard_Standard then
12423 Set_Is_Public (Id);
12425 -- Entity is definitely not public if enclosing scope is not public
12427 elsif not Is_Public (S) then
12430 -- An object or function declaration that occurs in a handled sequence
12431 -- of statements or within an if statement is the declaration for a
12432 -- temporary object or local subprogram generated by the expander. It
12433 -- never needs to be made public and furthermore, making it public can
12434 -- cause back end problems.
12436 elsif Nkind_In (Parent (Id), N_Object_Declaration,
12437 N_Function_Specification)
12438 and then Within_HSS_Or_If (Id)
12442 -- Entities in public packages or records are public
12444 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
12445 Set_Is_Public (Id);
12447 -- The bounds of an entry family declaration can generate object
12448 -- declarations that are visible to the back-end, e.g. in the
12449 -- the declaration of a composite type that contains tasks.
12451 elsif Is_Concurrent_Type (S)
12452 and then not Has_Completion (S)
12453 and then Nkind (Parent (Id)) = N_Object_Declaration
12455 Set_Is_Public (Id);
12457 end Set_Public_Status;
12459 -----------------------------
12460 -- Set_Referenced_Modified --
12461 -----------------------------
12463 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
12467 -- Deal with indexed or selected component where prefix is modified
12469 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
12470 Pref := Prefix (N);
12472 -- If prefix is access type, then it is the designated object that is
12473 -- being modified, which means we have no entity to set the flag on.
12475 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
12478 -- Otherwise chase the prefix
12481 Set_Referenced_Modified (Pref, Out_Param);
12484 -- Otherwise see if we have an entity name (only other case to process)
12486 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
12487 Set_Referenced_As_LHS (Entity (N), not Out_Param);
12488 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
12490 end Set_Referenced_Modified;
12492 ----------------------------
12493 -- Set_Scope_Is_Transient --
12494 ----------------------------
12496 procedure Set_Scope_Is_Transient (V : Boolean := True) is
12498 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
12499 end Set_Scope_Is_Transient;
12501 -------------------
12502 -- Set_Size_Info --
12503 -------------------
12505 procedure Set_Size_Info (T1, T2 : Entity_Id) is
12507 -- We copy Esize, but not RM_Size, since in general RM_Size is
12508 -- subtype specific and does not get inherited by all subtypes.
12510 Set_Esize (T1, Esize (T2));
12511 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
12513 if Is_Discrete_Or_Fixed_Point_Type (T1)
12515 Is_Discrete_Or_Fixed_Point_Type (T2)
12517 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
12520 Set_Alignment (T1, Alignment (T2));
12523 --------------------
12524 -- Static_Boolean --
12525 --------------------
12527 function Static_Boolean (N : Node_Id) return Uint is
12529 Analyze_And_Resolve (N, Standard_Boolean);
12532 or else Error_Posted (N)
12533 or else Etype (N) = Any_Type
12538 if Is_Static_Expression (N) then
12539 if not Raises_Constraint_Error (N) then
12540 return Expr_Value (N);
12545 elsif Etype (N) = Any_Type then
12549 Flag_Non_Static_Expr
12550 ("static boolean expression required here", N);
12553 end Static_Boolean;
12555 --------------------
12556 -- Static_Integer --
12557 --------------------
12559 function Static_Integer (N : Node_Id) return Uint is
12561 Analyze_And_Resolve (N, Any_Integer);
12564 or else Error_Posted (N)
12565 or else Etype (N) = Any_Type
12570 if Is_Static_Expression (N) then
12571 if not Raises_Constraint_Error (N) then
12572 return Expr_Value (N);
12577 elsif Etype (N) = Any_Type then
12581 Flag_Non_Static_Expr
12582 ("static integer expression required here", N);
12585 end Static_Integer;
12587 --------------------------
12588 -- Statically_Different --
12589 --------------------------
12591 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12592 R1 : constant Node_Id := Get_Referenced_Object (E1);
12593 R2 : constant Node_Id := Get_Referenced_Object (E2);
12595 return Is_Entity_Name (R1)
12596 and then Is_Entity_Name (R2)
12597 and then Entity (R1) /= Entity (R2)
12598 and then not Is_Formal (Entity (R1))
12599 and then not Is_Formal (Entity (R2));
12600 end Statically_Different;
12602 -----------------------------
12603 -- Subprogram_Access_Level --
12604 -----------------------------
12606 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12608 if Present (Alias (Subp)) then
12609 return Subprogram_Access_Level (Alias (Subp));
12611 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12613 end Subprogram_Access_Level;
12619 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12621 if Debug_Flag_W then
12622 for J in 0 .. Scope_Stack.Last loop
12627 Write_Name (Chars (E));
12628 Write_Str (" from ");
12629 Write_Location (Sloc (N));
12634 -----------------------
12635 -- Transfer_Entities --
12636 -----------------------
12638 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12639 Ent : Entity_Id := First_Entity (From);
12646 if (Last_Entity (To)) = Empty then
12647 Set_First_Entity (To, Ent);
12649 Set_Next_Entity (Last_Entity (To), Ent);
12652 Set_Last_Entity (To, Last_Entity (From));
12654 while Present (Ent) loop
12655 Set_Scope (Ent, To);
12657 if not Is_Public (Ent) then
12658 Set_Public_Status (Ent);
12661 and then Ekind (Ent) = E_Record_Subtype
12664 -- The components of the propagated Itype must be public
12670 Comp := First_Entity (Ent);
12671 while Present (Comp) loop
12672 Set_Is_Public (Comp);
12673 Next_Entity (Comp);
12682 Set_First_Entity (From, Empty);
12683 Set_Last_Entity (From, Empty);
12684 end Transfer_Entities;
12686 -----------------------
12687 -- Type_Access_Level --
12688 -----------------------
12690 function Type_Access_Level (Typ : Entity_Id) return Uint is
12694 Btyp := Base_Type (Typ);
12696 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12697 -- simply use the level where the type is declared. This is true for
12698 -- stand-alone object declarations, and for anonymous access types
12699 -- associated with components the level is the same as that of the
12700 -- enclosing composite type. However, special treatment is needed for
12701 -- the cases of access parameters, return objects of an anonymous access
12702 -- type, and, in Ada 95, access discriminants of limited types.
12704 if Ekind (Btyp) in Access_Kind then
12705 if Ekind (Btyp) = E_Anonymous_Access_Type then
12707 -- If the type is a nonlocal anonymous access type (such as for
12708 -- an access parameter) we treat it as being declared at the
12709 -- library level to ensure that names such as X.all'access don't
12710 -- fail static accessibility checks.
12712 if not Is_Local_Anonymous_Access (Typ) then
12713 return Scope_Depth (Standard_Standard);
12715 -- If this is a return object, the accessibility level is that of
12716 -- the result subtype of the enclosing function. The test here is
12717 -- little complicated, because we have to account for extended
12718 -- return statements that have been rewritten as blocks, in which
12719 -- case we have to find and the Is_Return_Object attribute of the
12720 -- itype's associated object. It would be nice to find a way to
12721 -- simplify this test, but it doesn't seem worthwhile to add a new
12722 -- flag just for purposes of this test. ???
12724 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12727 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12728 N_Object_Declaration
12729 and then Is_Return_Object
12730 (Defining_Identifier
12731 (Associated_Node_For_Itype (Btyp))))
12737 Scop := Scope (Scope (Btyp));
12738 while Present (Scop) loop
12739 exit when Ekind (Scop) = E_Function;
12740 Scop := Scope (Scop);
12743 -- Treat the return object's type as having the level of the
12744 -- function's result subtype (as per RM05-6.5(5.3/2)).
12746 return Type_Access_Level (Etype (Scop));
12751 Btyp := Root_Type (Btyp);
12753 -- The accessibility level of anonymous access types associated with
12754 -- discriminants is that of the current instance of the type, and
12755 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12757 -- AI-402: access discriminants have accessibility based on the
12758 -- object rather than the type in Ada 2005, so the above paragraph
12761 -- ??? Needs completion with rules from AI-416
12763 if Ada_Version <= Ada_95
12764 and then Ekind (Typ) = E_Anonymous_Access_Type
12765 and then Present (Associated_Node_For_Itype (Typ))
12766 and then Nkind (Associated_Node_For_Itype (Typ)) =
12767 N_Discriminant_Specification
12769 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12773 -- Return library level for a generic formal type. This is done because
12774 -- RM(10.3.2) says that "The statically deeper relationship does not
12775 -- apply to ... a descendant of a generic formal type". Rather than
12776 -- checking at each point where a static accessibility check is
12777 -- performed to see if we are dealing with a formal type, this rule is
12778 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
12779 -- return extreme values for a formal type; Deepest_Type_Access_Level
12780 -- returns Int'Last. By calling the appropriate function from among the
12781 -- two, we ensure that the static accessibility check will pass if we
12782 -- happen to run into a formal type. More specifically, we should call
12783 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
12784 -- call occurs as part of a static accessibility check and the error
12785 -- case is the case where the type's level is too shallow (as opposed
12788 if Is_Generic_Type (Root_Type (Btyp)) then
12789 return Scope_Depth (Standard_Standard);
12792 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12793 end Type_Access_Level;
12795 ------------------------------------
12796 -- Type_Without_Stream_Operation --
12797 ------------------------------------
12799 function Type_Without_Stream_Operation
12801 Op : TSS_Name_Type := TSS_Null) return Entity_Id
12803 BT : constant Entity_Id := Base_Type (T);
12804 Op_Missing : Boolean;
12807 if not Restriction_Active (No_Default_Stream_Attributes) then
12811 if Is_Elementary_Type (T) then
12812 if Op = TSS_Null then
12814 No (TSS (BT, TSS_Stream_Read))
12815 or else No (TSS (BT, TSS_Stream_Write));
12818 Op_Missing := No (TSS (BT, Op));
12827 elsif Is_Array_Type (T) then
12828 return Type_Without_Stream_Operation (Component_Type (T), Op);
12830 elsif Is_Record_Type (T) then
12836 Comp := First_Component (T);
12837 while Present (Comp) loop
12838 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
12840 if Present (C_Typ) then
12844 Next_Component (Comp);
12850 elsif Is_Private_Type (T)
12851 and then Present (Full_View (T))
12853 return Type_Without_Stream_Operation (Full_View (T), Op);
12857 end Type_Without_Stream_Operation;
12859 ----------------------------
12860 -- Unique_Defining_Entity --
12861 ----------------------------
12863 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
12865 return Unique_Entity (Defining_Entity (N));
12866 end Unique_Defining_Entity;
12868 -------------------
12869 -- Unique_Entity --
12870 -------------------
12872 function Unique_Entity (E : Entity_Id) return Entity_Id is
12873 U : Entity_Id := E;
12879 if Present (Full_View (E)) then
12880 U := Full_View (E);
12884 if Present (Full_View (E)) then
12885 U := Full_View (E);
12888 when E_Package_Body =>
12891 if Nkind (P) = N_Defining_Program_Unit_Name then
12895 U := Corresponding_Spec (P);
12897 when E_Subprogram_Body =>
12900 if Nkind (P) = N_Defining_Program_Unit_Name then
12906 if Nkind (P) = N_Subprogram_Body_Stub then
12907 if Present (Library_Unit (P)) then
12908 U := Get_Body_From_Stub (P);
12911 U := Corresponding_Spec (P);
12914 when Formal_Kind =>
12915 if Present (Spec_Entity (E)) then
12916 U := Spec_Entity (E);
12930 function Unique_Name (E : Entity_Id) return String is
12932 function Get_Scoped_Name (E : Entity_Id) return String;
12933 -- Return the name of E prefixed by all the names of the scopes to which
12934 -- E belongs, except for Standard.
12936 ---------------------
12937 -- Get_Scoped_Name --
12938 ---------------------
12940 function Get_Scoped_Name (E : Entity_Id) return String is
12941 Name : constant String := Get_Name_String (Chars (E));
12943 if Has_Fully_Qualified_Name (E)
12944 or else Scope (E) = Standard_Standard
12948 return Get_Scoped_Name (Scope (E)) & "__" & Name;
12950 end Get_Scoped_Name;
12952 -- Start of processing for Unique_Name
12955 if E = Standard_Standard then
12956 return Get_Name_String (Name_Standard);
12958 elsif Scope (E) = Standard_Standard
12959 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
12961 return Get_Name_String (Name_Standard) & "__" &
12962 Get_Name_String (Chars (E));
12964 elsif Ekind (E) = E_Enumeration_Literal then
12965 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
12968 return Get_Scoped_Name (E);
12972 --------------------------
12973 -- Unit_Declaration_Node --
12974 --------------------------
12976 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12977 N : Node_Id := Parent (Unit_Id);
12980 -- Predefined operators do not have a full function declaration
12982 if Ekind (Unit_Id) = E_Operator then
12986 -- Isn't there some better way to express the following ???
12988 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12989 and then Nkind (N) /= N_Formal_Package_Declaration
12990 and then Nkind (N) /= N_Function_Instantiation
12991 and then Nkind (N) /= N_Generic_Package_Declaration
12992 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12993 and then Nkind (N) /= N_Package_Declaration
12994 and then Nkind (N) /= N_Package_Body
12995 and then Nkind (N) /= N_Package_Instantiation
12996 and then Nkind (N) /= N_Package_Renaming_Declaration
12997 and then Nkind (N) /= N_Procedure_Instantiation
12998 and then Nkind (N) /= N_Protected_Body
12999 and then Nkind (N) /= N_Subprogram_Declaration
13000 and then Nkind (N) /= N_Subprogram_Body
13001 and then Nkind (N) /= N_Subprogram_Body_Stub
13002 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
13003 and then Nkind (N) /= N_Task_Body
13004 and then Nkind (N) /= N_Task_Type_Declaration
13005 and then Nkind (N) not in N_Formal_Subprogram_Declaration
13006 and then Nkind (N) not in N_Generic_Renaming_Declaration
13010 -- We don't use Assert here, because that causes an infinite loop
13011 -- when assertions are turned off. Better to crash.
13014 raise Program_Error;
13019 end Unit_Declaration_Node;
13021 ---------------------
13022 -- Unit_Is_Visible --
13023 ---------------------
13025 function Unit_Is_Visible (U : Entity_Id) return Boolean is
13026 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
13027 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
13029 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
13030 -- For a child unit, check whether unit appears in a with_clause
13033 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
13034 -- Scan the context clause of one compilation unit looking for a
13035 -- with_clause for the unit in question.
13037 ----------------------------
13038 -- Unit_In_Parent_Context --
13039 ----------------------------
13041 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
13043 if Unit_In_Context (Par_Unit) then
13046 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
13047 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
13052 end Unit_In_Parent_Context;
13054 ---------------------
13055 -- Unit_In_Context --
13056 ---------------------
13058 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
13062 Clause := First (Context_Items (Comp_Unit));
13063 while Present (Clause) loop
13064 if Nkind (Clause) = N_With_Clause then
13065 if Library_Unit (Clause) = U then
13068 -- The with_clause may denote a renaming of the unit we are
13069 -- looking for, eg. Text_IO which renames Ada.Text_IO.
13072 Renamed_Entity (Entity (Name (Clause))) =
13073 Defining_Entity (Unit (U))
13083 end Unit_In_Context;
13085 -- Start of processing for Unit_Is_Visible
13088 -- The currrent unit is directly visible
13093 elsif Unit_In_Context (Curr) then
13096 -- If the current unit is a body, check the context of the spec
13098 elsif Nkind (Unit (Curr)) = N_Package_Body
13100 (Nkind (Unit (Curr)) = N_Subprogram_Body
13101 and then not Acts_As_Spec (Unit (Curr)))
13103 if Unit_In_Context (Library_Unit (Curr)) then
13108 -- If the spec is a child unit, examine the parents
13110 if Is_Child_Unit (Curr_Entity) then
13111 if Nkind (Unit (Curr)) in N_Unit_Body then
13113 Unit_In_Parent_Context
13114 (Parent_Spec (Unit (Library_Unit (Curr))));
13116 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
13122 end Unit_Is_Visible;
13124 ------------------------------
13125 -- Universal_Interpretation --
13126 ------------------------------
13128 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
13129 Index : Interp_Index;
13133 -- The argument may be a formal parameter of an operator or subprogram
13134 -- with multiple interpretations, or else an expression for an actual.
13136 if Nkind (Opnd) = N_Defining_Identifier
13137 or else not Is_Overloaded (Opnd)
13139 if Etype (Opnd) = Universal_Integer
13140 or else Etype (Opnd) = Universal_Real
13142 return Etype (Opnd);
13148 Get_First_Interp (Opnd, Index, It);
13149 while Present (It.Typ) loop
13150 if It.Typ = Universal_Integer
13151 or else It.Typ = Universal_Real
13156 Get_Next_Interp (Index, It);
13161 end Universal_Interpretation;
13167 function Unqualify (Expr : Node_Id) return Node_Id is
13169 -- Recurse to handle unlikely case of multiple levels of qualification
13171 if Nkind (Expr) = N_Qualified_Expression then
13172 return Unqualify (Expression (Expr));
13174 -- Normal case, not a qualified expression
13181 -----------------------
13182 -- Visible_Ancestors --
13183 -----------------------
13185 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
13191 pragma Assert (Is_Record_Type (Typ)
13192 and then Is_Tagged_Type (Typ));
13194 -- Collect all the parents and progenitors of Typ. If the full-view of
13195 -- private parents and progenitors is available then it is used to
13196 -- generate the list of visible ancestors; otherwise their partial
13197 -- view is added to the resulting list.
13202 Use_Full_View => True);
13206 Ifaces_List => List_2,
13207 Exclude_Parents => True,
13208 Use_Full_View => True);
13210 -- Join the two lists. Avoid duplications because an interface may
13211 -- simultaneously be parent and progenitor of a type.
13213 Elmt := First_Elmt (List_2);
13214 while Present (Elmt) loop
13215 Append_Unique_Elmt (Node (Elmt), List_1);
13220 end Visible_Ancestors;
13222 ----------------------
13223 -- Within_Init_Proc --
13224 ----------------------
13226 function Within_Init_Proc return Boolean is
13230 S := Current_Scope;
13231 while not Is_Overloadable (S) loop
13232 if S = Standard_Standard then
13239 return Is_Init_Proc (S);
13240 end Within_Init_Proc;
13246 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
13247 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
13248 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
13250 Matching_Field : Entity_Id;
13251 -- Entity to give a more precise suggestion on how to write a one-
13252 -- element positional aggregate.
13254 function Has_One_Matching_Field return Boolean;
13255 -- Determines if Expec_Type is a record type with a single component or
13256 -- discriminant whose type matches the found type or is one dimensional
13257 -- array whose component type matches the found type.
13259 ----------------------------
13260 -- Has_One_Matching_Field --
13261 ----------------------------
13263 function Has_One_Matching_Field return Boolean is
13267 Matching_Field := Empty;
13269 if Is_Array_Type (Expec_Type)
13270 and then Number_Dimensions (Expec_Type) = 1
13272 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
13274 -- Use type name if available. This excludes multidimensional
13275 -- arrays and anonymous arrays.
13277 if Comes_From_Source (Expec_Type) then
13278 Matching_Field := Expec_Type;
13280 -- For an assignment, use name of target
13282 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
13283 and then Is_Entity_Name (Name (Parent (Expr)))
13285 Matching_Field := Entity (Name (Parent (Expr)));
13290 elsif not Is_Record_Type (Expec_Type) then
13294 E := First_Entity (Expec_Type);
13299 elsif (Ekind (E) /= E_Discriminant
13300 and then Ekind (E) /= E_Component)
13301 or else (Chars (E) = Name_uTag
13302 or else Chars (E) = Name_uParent)
13311 if not Covers (Etype (E), Found_Type) then
13314 elsif Present (Next_Entity (E)) then
13318 Matching_Field := E;
13322 end Has_One_Matching_Field;
13324 -- Start of processing for Wrong_Type
13327 -- Don't output message if either type is Any_Type, or if a message
13328 -- has already been posted for this node. We need to do the latter
13329 -- check explicitly (it is ordinarily done in Errout), because we
13330 -- are using ! to force the output of the error messages.
13332 if Expec_Type = Any_Type
13333 or else Found_Type = Any_Type
13334 or else Error_Posted (Expr)
13338 -- If one of the types is a Taft-Amendment type and the other it its
13339 -- completion, it must be an illegal use of a TAT in the spec, for
13340 -- which an error was already emitted. Avoid cascaded errors.
13342 elsif Is_Incomplete_Type (Expec_Type)
13343 and then Has_Completion_In_Body (Expec_Type)
13344 and then Full_View (Expec_Type) = Etype (Expr)
13348 elsif Is_Incomplete_Type (Etype (Expr))
13349 and then Has_Completion_In_Body (Etype (Expr))
13350 and then Full_View (Etype (Expr)) = Expec_Type
13354 -- In an instance, there is an ongoing problem with completion of
13355 -- type derived from private types. Their structure is what Gigi
13356 -- expects, but the Etype is the parent type rather than the
13357 -- derived private type itself. Do not flag error in this case. The
13358 -- private completion is an entity without a parent, like an Itype.
13359 -- Similarly, full and partial views may be incorrect in the instance.
13360 -- There is no simple way to insure that it is consistent ???
13362 elsif In_Instance then
13363 if Etype (Etype (Expr)) = Etype (Expected_Type)
13365 (Has_Private_Declaration (Expected_Type)
13366 or else Has_Private_Declaration (Etype (Expr)))
13367 and then No (Parent (Expected_Type))
13373 -- An interesting special check. If the expression is parenthesized
13374 -- and its type corresponds to the type of the sole component of the
13375 -- expected record type, or to the component type of the expected one
13376 -- dimensional array type, then assume we have a bad aggregate attempt.
13378 if Nkind (Expr) in N_Subexpr
13379 and then Paren_Count (Expr) /= 0
13380 and then Has_One_Matching_Field
13382 Error_Msg_N ("positional aggregate cannot have one component", Expr);
13383 if Present (Matching_Field) then
13384 if Is_Array_Type (Expec_Type) then
13386 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
13390 ("\write instead `& ='> ...`", Expr, Matching_Field);
13394 -- Another special check, if we are looking for a pool-specific access
13395 -- type and we found an E_Access_Attribute_Type, then we have the case
13396 -- of an Access attribute being used in a context which needs a pool-
13397 -- specific type, which is never allowed. The one extra check we make
13398 -- is that the expected designated type covers the Found_Type.
13400 elsif Is_Access_Type (Expec_Type)
13401 and then Ekind (Found_Type) = E_Access_Attribute_Type
13402 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
13403 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
13405 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
13407 Error_Msg_N -- CODEFIX
13408 ("result must be general access type!", Expr);
13409 Error_Msg_NE -- CODEFIX
13410 ("add ALL to }!", Expr, Expec_Type);
13412 -- Another special check, if the expected type is an integer type,
13413 -- but the expression is of type System.Address, and the parent is
13414 -- an addition or subtraction operation whose left operand is the
13415 -- expression in question and whose right operand is of an integral
13416 -- type, then this is an attempt at address arithmetic, so give
13417 -- appropriate message.
13419 elsif Is_Integer_Type (Expec_Type)
13420 and then Is_RTE (Found_Type, RE_Address)
13421 and then (Nkind (Parent (Expr)) = N_Op_Add
13423 Nkind (Parent (Expr)) = N_Op_Subtract)
13424 and then Expr = Left_Opnd (Parent (Expr))
13425 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
13428 ("address arithmetic not predefined in package System",
13431 ("\possible missing with/use of System.Storage_Elements",
13435 -- If the expected type is an anonymous access type, as for access
13436 -- parameters and discriminants, the error is on the designated types.
13438 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
13439 if Comes_From_Source (Expec_Type) then
13440 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13443 ("expected an access type with designated}",
13444 Expr, Designated_Type (Expec_Type));
13447 if Is_Access_Type (Found_Type)
13448 and then not Comes_From_Source (Found_Type)
13451 ("\\found an access type with designated}!",
13452 Expr, Designated_Type (Found_Type));
13454 if From_With_Type (Found_Type) then
13455 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
13456 Error_Msg_Qual_Level := 99;
13457 Error_Msg_NE -- CODEFIX
13458 ("\\missing `WITH &;", Expr, Scope (Found_Type));
13459 Error_Msg_Qual_Level := 0;
13461 Error_Msg_NE ("found}!", Expr, Found_Type);
13465 -- Normal case of one type found, some other type expected
13468 -- If the names of the two types are the same, see if some number
13469 -- of levels of qualification will help. Don't try more than three
13470 -- levels, and if we get to standard, it's no use (and probably
13471 -- represents an error in the compiler) Also do not bother with
13472 -- internal scope names.
13475 Expec_Scope : Entity_Id;
13476 Found_Scope : Entity_Id;
13479 Expec_Scope := Expec_Type;
13480 Found_Scope := Found_Type;
13482 for Levels in Int range 0 .. 3 loop
13483 if Chars (Expec_Scope) /= Chars (Found_Scope) then
13484 Error_Msg_Qual_Level := Levels;
13488 Expec_Scope := Scope (Expec_Scope);
13489 Found_Scope := Scope (Found_Scope);
13491 exit when Expec_Scope = Standard_Standard
13492 or else Found_Scope = Standard_Standard
13493 or else not Comes_From_Source (Expec_Scope)
13494 or else not Comes_From_Source (Found_Scope);
13498 if Is_Record_Type (Expec_Type)
13499 and then Present (Corresponding_Remote_Type (Expec_Type))
13501 Error_Msg_NE ("expected}!", Expr,
13502 Corresponding_Remote_Type (Expec_Type));
13504 Error_Msg_NE ("expected}!", Expr, Expec_Type);
13507 if Is_Entity_Name (Expr)
13508 and then Is_Package_Or_Generic_Package (Entity (Expr))
13510 Error_Msg_N ("\\found package name!", Expr);
13512 elsif Is_Entity_Name (Expr)
13514 (Ekind (Entity (Expr)) = E_Procedure
13516 Ekind (Entity (Expr)) = E_Generic_Procedure)
13518 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
13520 ("found procedure name, possibly missing Access attribute!",
13524 ("\\found procedure name instead of function!", Expr);
13527 elsif Nkind (Expr) = N_Function_Call
13528 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
13529 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
13530 and then No (Parameter_Associations (Expr))
13533 ("found function name, possibly missing Access attribute!",
13536 -- Catch common error: a prefix or infix operator which is not
13537 -- directly visible because the type isn't.
13539 elsif Nkind (Expr) in N_Op
13540 and then Is_Overloaded (Expr)
13541 and then not Is_Immediately_Visible (Expec_Type)
13542 and then not Is_Potentially_Use_Visible (Expec_Type)
13543 and then not In_Use (Expec_Type)
13544 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
13547 ("operator of the type is not directly visible!", Expr);
13549 elsif Ekind (Found_Type) = E_Void
13550 and then Present (Parent (Found_Type))
13551 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
13553 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
13556 Error_Msg_NE ("\\found}!", Expr, Found_Type);
13559 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
13560 -- of the same modular type, and (M1 and M2) = 0 was intended.
13562 if Expec_Type = Standard_Boolean
13563 and then Is_Modular_Integer_Type (Found_Type)
13564 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
13565 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
13568 Op : constant Node_Id := Right_Opnd (Parent (Expr));
13569 L : constant Node_Id := Left_Opnd (Op);
13570 R : constant Node_Id := Right_Opnd (Op);
13572 -- The case for the message is when the left operand of the
13573 -- comparison is the same modular type, or when it is an
13574 -- integer literal (or other universal integer expression),
13575 -- which would have been typed as the modular type if the
13576 -- parens had been there.
13578 if (Etype (L) = Found_Type
13580 Etype (L) = Universal_Integer)
13581 and then Is_Integer_Type (Etype (R))
13584 ("\\possible missing parens for modular operation", Expr);
13589 -- Reset error message qualification indication
13591 Error_Msg_Qual_Level := 0;