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_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Restrict; use Restrict;
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 -- Bad_Predicated_Subtype_Use --
338 --------------------------------
340 procedure Bad_Predicated_Subtype_Use
346 if Has_Predicates (Typ) then
347 if Is_Generic_Actual_Type (Typ) then
348 Error_Msg_FE (Msg & '?', N, Typ);
349 Error_Msg_F ("\Program_Error will be raised at run time?", N);
351 Make_Raise_Program_Error (Sloc (N),
352 Reason => PE_Bad_Predicated_Generic_Type));
355 Error_Msg_FE (Msg, N, Typ);
358 end Bad_Predicated_Subtype_Use;
360 --------------------------
361 -- Build_Actual_Subtype --
362 --------------------------
364 function Build_Actual_Subtype
366 N : Node_Or_Entity_Id) return Node_Id
369 -- Normally Sloc (N), but may point to corresponding body in some cases
371 Constraints : List_Id;
377 Disc_Type : Entity_Id;
383 if Nkind (N) = N_Defining_Identifier then
384 Obj := New_Reference_To (N, Loc);
386 -- If this is a formal parameter of a subprogram declaration, and
387 -- we are compiling the body, we want the declaration for the
388 -- actual subtype to carry the source position of the body, to
389 -- prevent anomalies in gdb when stepping through the code.
391 if Is_Formal (N) then
393 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
395 if Nkind (Decl) = N_Subprogram_Declaration
396 and then Present (Corresponding_Body (Decl))
398 Loc := Sloc (Corresponding_Body (Decl));
407 if Is_Array_Type (T) then
408 Constraints := New_List;
409 for J in 1 .. Number_Dimensions (T) loop
411 -- Build an array subtype declaration with the nominal subtype and
412 -- the bounds of the actual. Add the declaration in front of the
413 -- local declarations for the subprogram, for analysis before any
414 -- reference to the formal in the body.
417 Make_Attribute_Reference (Loc,
419 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
420 Attribute_Name => Name_First,
421 Expressions => New_List (
422 Make_Integer_Literal (Loc, J)));
425 Make_Attribute_Reference (Loc,
427 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
428 Attribute_Name => Name_Last,
429 Expressions => New_List (
430 Make_Integer_Literal (Loc, J)));
432 Append (Make_Range (Loc, Lo, Hi), Constraints);
435 -- If the type has unknown discriminants there is no constrained
436 -- subtype to build. This is never called for a formal or for a
437 -- lhs, so returning the type is ok ???
439 elsif Has_Unknown_Discriminants (T) then
443 Constraints := New_List;
445 -- Type T is a generic derived type, inherit the discriminants from
448 if Is_Private_Type (T)
449 and then No (Full_View (T))
451 -- T was flagged as an error if it was declared as a formal
452 -- derived type with known discriminants. In this case there
453 -- is no need to look at the parent type since T already carries
454 -- its own discriminants.
456 and then not Error_Posted (T)
458 Disc_Type := Etype (Base_Type (T));
463 Discr := First_Discriminant (Disc_Type);
464 while Present (Discr) loop
465 Append_To (Constraints,
466 Make_Selected_Component (Loc,
468 Duplicate_Subexpr_No_Checks (Obj),
469 Selector_Name => New_Occurrence_Of (Discr, Loc)));
470 Next_Discriminant (Discr);
474 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
475 Set_Is_Internal (Subt);
478 Make_Subtype_Declaration (Loc,
479 Defining_Identifier => Subt,
480 Subtype_Indication =>
481 Make_Subtype_Indication (Loc,
482 Subtype_Mark => New_Reference_To (T, Loc),
484 Make_Index_Or_Discriminant_Constraint (Loc,
485 Constraints => Constraints)));
487 Mark_Rewrite_Insertion (Decl);
489 end Build_Actual_Subtype;
491 ---------------------------------------
492 -- Build_Actual_Subtype_Of_Component --
493 ---------------------------------------
495 function Build_Actual_Subtype_Of_Component
497 N : Node_Id) return Node_Id
499 Loc : constant Source_Ptr := Sloc (N);
500 P : constant Node_Id := Prefix (N);
503 Indx_Type : Entity_Id;
505 Deaccessed_T : Entity_Id;
506 -- This is either a copy of T, or if T is an access type, then it is
507 -- the directly designated type of this access type.
509 function Build_Actual_Array_Constraint return List_Id;
510 -- If one or more of the bounds of the component depends on
511 -- discriminants, build actual constraint using the discriminants
514 function Build_Actual_Record_Constraint return List_Id;
515 -- Similar to previous one, for discriminated components constrained
516 -- by the discriminant of the enclosing object.
518 -----------------------------------
519 -- Build_Actual_Array_Constraint --
520 -----------------------------------
522 function Build_Actual_Array_Constraint return List_Id is
523 Constraints : constant List_Id := New_List;
531 Indx := First_Index (Deaccessed_T);
532 while Present (Indx) loop
533 Old_Lo := Type_Low_Bound (Etype (Indx));
534 Old_Hi := Type_High_Bound (Etype (Indx));
536 if Denotes_Discriminant (Old_Lo) then
538 Make_Selected_Component (Loc,
539 Prefix => New_Copy_Tree (P),
540 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
543 Lo := New_Copy_Tree (Old_Lo);
545 -- The new bound will be reanalyzed in the enclosing
546 -- declaration. For literal bounds that come from a type
547 -- declaration, the type of the context must be imposed, so
548 -- insure that analysis will take place. For non-universal
549 -- types this is not strictly necessary.
551 Set_Analyzed (Lo, False);
554 if Denotes_Discriminant (Old_Hi) then
556 Make_Selected_Component (Loc,
557 Prefix => New_Copy_Tree (P),
558 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
561 Hi := New_Copy_Tree (Old_Hi);
562 Set_Analyzed (Hi, False);
565 Append (Make_Range (Loc, Lo, Hi), Constraints);
570 end Build_Actual_Array_Constraint;
572 ------------------------------------
573 -- Build_Actual_Record_Constraint --
574 ------------------------------------
576 function Build_Actual_Record_Constraint return List_Id is
577 Constraints : constant List_Id := New_List;
582 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
583 while Present (D) loop
584 if Denotes_Discriminant (Node (D)) then
585 D_Val := Make_Selected_Component (Loc,
586 Prefix => New_Copy_Tree (P),
587 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
590 D_Val := New_Copy_Tree (Node (D));
593 Append (D_Val, Constraints);
598 end Build_Actual_Record_Constraint;
600 -- Start of processing for Build_Actual_Subtype_Of_Component
603 -- Why the test for Spec_Expression mode here???
605 if In_Spec_Expression then
608 -- More comments for the rest of this body would be good ???
610 elsif Nkind (N) = N_Explicit_Dereference then
611 if Is_Composite_Type (T)
612 and then not Is_Constrained (T)
613 and then not (Is_Class_Wide_Type (T)
614 and then Is_Constrained (Root_Type (T)))
615 and then not Has_Unknown_Discriminants (T)
617 -- If the type of the dereference is already constrained, it is an
620 if Is_Array_Type (Etype (N))
621 and then Is_Constrained (Etype (N))
625 Remove_Side_Effects (P);
626 return Build_Actual_Subtype (T, N);
633 if Ekind (T) = E_Access_Subtype then
634 Deaccessed_T := Designated_Type (T);
639 if Ekind (Deaccessed_T) = E_Array_Subtype then
640 Id := First_Index (Deaccessed_T);
641 while Present (Id) loop
642 Indx_Type := Underlying_Type (Etype (Id));
644 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
646 Denotes_Discriminant (Type_High_Bound (Indx_Type))
648 Remove_Side_Effects (P);
650 Build_Component_Subtype
651 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
657 elsif Is_Composite_Type (Deaccessed_T)
658 and then Has_Discriminants (Deaccessed_T)
659 and then not Has_Unknown_Discriminants (Deaccessed_T)
661 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
662 while Present (D) loop
663 if Denotes_Discriminant (Node (D)) then
664 Remove_Side_Effects (P);
666 Build_Component_Subtype (
667 Build_Actual_Record_Constraint, Loc, Base_Type (T));
674 -- If none of the above, the actual and nominal subtypes are the same
677 end Build_Actual_Subtype_Of_Component;
679 -----------------------------
680 -- Build_Component_Subtype --
681 -----------------------------
683 function Build_Component_Subtype
686 T : Entity_Id) return Node_Id
692 -- Unchecked_Union components do not require component subtypes
694 if Is_Unchecked_Union (T) then
698 Subt := Make_Temporary (Loc, 'S');
699 Set_Is_Internal (Subt);
702 Make_Subtype_Declaration (Loc,
703 Defining_Identifier => Subt,
704 Subtype_Indication =>
705 Make_Subtype_Indication (Loc,
706 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
708 Make_Index_Or_Discriminant_Constraint (Loc,
711 Mark_Rewrite_Insertion (Decl);
713 end Build_Component_Subtype;
715 ---------------------------
716 -- Build_Default_Subtype --
717 ---------------------------
719 function Build_Default_Subtype
721 N : Node_Id) return Entity_Id
723 Loc : constant Source_Ptr := Sloc (N);
727 if not Has_Discriminants (T) or else Is_Constrained (T) then
731 Disc := First_Discriminant (T);
733 if No (Discriminant_Default_Value (Disc)) then
738 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
739 Constraints : constant List_Id := New_List;
743 while Present (Disc) loop
744 Append_To (Constraints,
745 New_Copy_Tree (Discriminant_Default_Value (Disc)));
746 Next_Discriminant (Disc);
750 Make_Subtype_Declaration (Loc,
751 Defining_Identifier => Act,
752 Subtype_Indication =>
753 Make_Subtype_Indication (Loc,
754 Subtype_Mark => New_Occurrence_Of (T, Loc),
756 Make_Index_Or_Discriminant_Constraint (Loc,
757 Constraints => Constraints)));
759 Insert_Action (N, Decl);
763 end Build_Default_Subtype;
765 --------------------------------------------
766 -- Build_Discriminal_Subtype_Of_Component --
767 --------------------------------------------
769 function Build_Discriminal_Subtype_Of_Component
770 (T : Entity_Id) return Node_Id
772 Loc : constant Source_Ptr := Sloc (T);
776 function Build_Discriminal_Array_Constraint return List_Id;
777 -- If one or more of the bounds of the component depends on
778 -- discriminants, build actual constraint using the discriminants
781 function Build_Discriminal_Record_Constraint return List_Id;
782 -- Similar to previous one, for discriminated components constrained
783 -- by the discriminant of the enclosing object.
785 ----------------------------------------
786 -- Build_Discriminal_Array_Constraint --
787 ----------------------------------------
789 function Build_Discriminal_Array_Constraint return List_Id is
790 Constraints : constant List_Id := New_List;
798 Indx := First_Index (T);
799 while Present (Indx) loop
800 Old_Lo := Type_Low_Bound (Etype (Indx));
801 Old_Hi := Type_High_Bound (Etype (Indx));
803 if Denotes_Discriminant (Old_Lo) then
804 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
807 Lo := New_Copy_Tree (Old_Lo);
810 if Denotes_Discriminant (Old_Hi) then
811 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
814 Hi := New_Copy_Tree (Old_Hi);
817 Append (Make_Range (Loc, Lo, Hi), Constraints);
822 end Build_Discriminal_Array_Constraint;
824 -----------------------------------------
825 -- Build_Discriminal_Record_Constraint --
826 -----------------------------------------
828 function Build_Discriminal_Record_Constraint return List_Id is
829 Constraints : constant List_Id := New_List;
834 D := First_Elmt (Discriminant_Constraint (T));
835 while Present (D) loop
836 if Denotes_Discriminant (Node (D)) then
838 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
841 D_Val := New_Copy_Tree (Node (D));
844 Append (D_Val, Constraints);
849 end Build_Discriminal_Record_Constraint;
851 -- Start of processing for Build_Discriminal_Subtype_Of_Component
854 if Ekind (T) = E_Array_Subtype then
855 Id := First_Index (T);
856 while Present (Id) loop
857 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
858 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
860 return Build_Component_Subtype
861 (Build_Discriminal_Array_Constraint, Loc, T);
867 elsif Ekind (T) = E_Record_Subtype
868 and then Has_Discriminants (T)
869 and then not Has_Unknown_Discriminants (T)
871 D := First_Elmt (Discriminant_Constraint (T));
872 while Present (D) loop
873 if Denotes_Discriminant (Node (D)) then
874 return Build_Component_Subtype
875 (Build_Discriminal_Record_Constraint, Loc, T);
882 -- If none of the above, the actual and nominal subtypes are the same
885 end Build_Discriminal_Subtype_Of_Component;
887 ------------------------------
888 -- Build_Elaboration_Entity --
889 ------------------------------
891 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
892 Loc : constant Source_Ptr := Sloc (N);
894 Elab_Ent : Entity_Id;
896 procedure Set_Package_Name (Ent : Entity_Id);
897 -- Given an entity, sets the fully qualified name of the entity in
898 -- Name_Buffer, with components separated by double underscores. This
899 -- is a recursive routine that climbs the scope chain to Standard.
901 ----------------------
902 -- Set_Package_Name --
903 ----------------------
905 procedure Set_Package_Name (Ent : Entity_Id) is
907 if Scope (Ent) /= Standard_Standard then
908 Set_Package_Name (Scope (Ent));
911 Nam : constant String := Get_Name_String (Chars (Ent));
913 Name_Buffer (Name_Len + 1) := '_';
914 Name_Buffer (Name_Len + 2) := '_';
915 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
916 Name_Len := Name_Len + Nam'Length + 2;
920 Get_Name_String (Chars (Ent));
922 end Set_Package_Name;
924 -- Start of processing for Build_Elaboration_Entity
927 -- Ignore if already constructed
929 if Present (Elaboration_Entity (Spec_Id)) then
933 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
934 -- name with dots replaced by double underscore. We have to manually
935 -- construct this name, since it will be elaborated in the outer scope,
936 -- and thus will not have the unit name automatically prepended.
938 Set_Package_Name (Spec_Id);
942 Name_Buffer (Name_Len + 1) := '_';
943 Name_Buffer (Name_Len + 2) := 'E';
944 Name_Len := Name_Len + 2;
946 -- Create elaboration flag
949 Make_Defining_Identifier (Loc, Chars => Name_Find);
950 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
953 Make_Object_Declaration (Loc,
954 Defining_Identifier => Elab_Ent,
956 New_Occurrence_Of (Standard_Boolean, Loc),
958 New_Occurrence_Of (Standard_False, Loc));
960 Push_Scope (Standard_Standard);
961 Add_Global_Declaration (Decl);
964 -- Reset True_Constant indication, since we will indeed assign a value
965 -- to the variable in the binder main. We also kill the Current_Value
966 -- and Last_Assignment fields for the same reason.
968 Set_Is_True_Constant (Elab_Ent, False);
969 Set_Current_Value (Elab_Ent, Empty);
970 Set_Last_Assignment (Elab_Ent, Empty);
972 -- We do not want any further qualification of the name (if we did
973 -- not do this, we would pick up the name of the generic package
974 -- in the case of a library level generic instantiation).
976 Set_Has_Qualified_Name (Elab_Ent);
977 Set_Has_Fully_Qualified_Name (Elab_Ent);
978 end Build_Elaboration_Entity;
980 -----------------------------------
981 -- Cannot_Raise_Constraint_Error --
982 -----------------------------------
984 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
986 if Compile_Time_Known_Value (Expr) then
989 elsif Do_Range_Check (Expr) then
992 elsif Raises_Constraint_Error (Expr) then
1000 when N_Expanded_Name =>
1003 when N_Selected_Component =>
1004 return not Do_Discriminant_Check (Expr);
1006 when N_Attribute_Reference =>
1007 if Do_Overflow_Check (Expr) then
1010 elsif No (Expressions (Expr)) then
1018 N := First (Expressions (Expr));
1019 while Present (N) loop
1020 if Cannot_Raise_Constraint_Error (N) then
1031 when N_Type_Conversion =>
1032 if Do_Overflow_Check (Expr)
1033 or else Do_Length_Check (Expr)
1034 or else Do_Tag_Check (Expr)
1039 Cannot_Raise_Constraint_Error (Expression (Expr));
1042 when N_Unchecked_Type_Conversion =>
1043 return Cannot_Raise_Constraint_Error (Expression (Expr));
1046 if Do_Overflow_Check (Expr) then
1050 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1057 if Do_Division_Check (Expr)
1058 or else Do_Overflow_Check (Expr)
1063 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1065 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1084 N_Op_Shift_Right_Arithmetic |
1088 if Do_Overflow_Check (Expr) then
1092 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1094 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1101 end Cannot_Raise_Constraint_Error;
1103 -----------------------------------------
1104 -- Check_Dynamically_Tagged_Expression --
1105 -----------------------------------------
1107 procedure Check_Dynamically_Tagged_Expression
1110 Related_Nod : Node_Id)
1113 pragma Assert (Is_Tagged_Type (Typ));
1115 -- In order to avoid spurious errors when analyzing the expanded code,
1116 -- this check is done only for nodes that come from source and for
1117 -- actuals of generic instantiations.
1119 if (Comes_From_Source (Related_Nod)
1120 or else In_Generic_Actual (Expr))
1121 and then (Is_Class_Wide_Type (Etype (Expr))
1122 or else Is_Dynamically_Tagged (Expr))
1123 and then Is_Tagged_Type (Typ)
1124 and then not Is_Class_Wide_Type (Typ)
1126 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1128 end Check_Dynamically_Tagged_Expression;
1130 --------------------------
1131 -- Check_Fully_Declared --
1132 --------------------------
1134 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1136 if Ekind (T) = E_Incomplete_Type then
1138 -- Ada 2005 (AI-50217): If the type is available through a limited
1139 -- with_clause, verify that its full view has been analyzed.
1141 if From_With_Type (T)
1142 and then Present (Non_Limited_View (T))
1143 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1145 -- The non-limited view is fully declared
1150 ("premature usage of incomplete}", N, First_Subtype (T));
1153 -- Need comments for these tests ???
1155 elsif Has_Private_Component (T)
1156 and then not Is_Generic_Type (Root_Type (T))
1157 and then not In_Spec_Expression
1159 -- Special case: if T is the anonymous type created for a single
1160 -- task or protected object, use the name of the source object.
1162 if Is_Concurrent_Type (T)
1163 and then not Comes_From_Source (T)
1164 and then Nkind (N) = N_Object_Declaration
1166 Error_Msg_NE ("type of& has incomplete component", N,
1167 Defining_Identifier (N));
1171 ("premature usage of incomplete}", N, First_Subtype (T));
1174 end Check_Fully_Declared;
1176 -------------------------
1177 -- Check_Nested_Access --
1178 -------------------------
1180 procedure Check_Nested_Access (Ent : Entity_Id) is
1181 Scop : constant Entity_Id := Current_Scope;
1182 Current_Subp : Entity_Id;
1183 Enclosing : Entity_Id;
1186 -- Currently only enabled for VM back-ends for efficiency, should we
1187 -- enable it more systematically ???
1189 -- Check for Is_Imported needs commenting below ???
1191 if VM_Target /= No_VM
1192 and then (Ekind (Ent) = E_Variable
1194 Ekind (Ent) = E_Constant
1196 Ekind (Ent) = E_Loop_Parameter)
1197 and then Scope (Ent) /= Empty
1198 and then not Is_Library_Level_Entity (Ent)
1199 and then not Is_Imported (Ent)
1201 if Is_Subprogram (Scop)
1202 or else Is_Generic_Subprogram (Scop)
1203 or else Is_Entry (Scop)
1205 Current_Subp := Scop;
1207 Current_Subp := Current_Subprogram;
1210 Enclosing := Enclosing_Subprogram (Ent);
1212 if Enclosing /= Empty
1213 and then Enclosing /= Current_Subp
1215 Set_Has_Up_Level_Access (Ent, True);
1218 end Check_Nested_Access;
1220 ----------------------------
1221 -- Check_Order_Dependence --
1222 ----------------------------
1224 procedure Check_Order_Dependence is
1229 if Ada_Version < Ada_2012 then
1233 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1234 -- calls within a construct have been collected. If one of them is
1235 -- writable and overlaps with another one, evaluation of the enclosing
1236 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1237 -- treated as a warning for now.
1239 for J in 1 .. Actuals_In_Call.Last loop
1240 if Actuals_In_Call.Table (J).Is_Writable then
1241 Act1 := Actuals_In_Call.Table (J).Act;
1243 if Nkind (Act1) = N_Attribute_Reference then
1244 Act1 := Prefix (Act1);
1247 for K in 1 .. Actuals_In_Call.Last loop
1249 Act2 := Actuals_In_Call.Table (K).Act;
1251 if Nkind (Act2) = N_Attribute_Reference then
1252 Act2 := Prefix (Act2);
1255 if Actuals_In_Call.Table (K).Is_Writable
1262 elsif Denotes_Same_Object (Act1, Act2)
1263 and then Parent (Act1) /= Parent (Act2)
1266 ("result may differ if evaluated "
1267 & "after other actual in expression?", Act1);
1274 -- Remove checked actuals from table
1276 Actuals_In_Call.Set_Last (0);
1277 end Check_Order_Dependence;
1279 ------------------------------------------
1280 -- Check_Potentially_Blocking_Operation --
1281 ------------------------------------------
1283 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1287 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1288 -- When pragma Detect_Blocking is active, the run time will raise
1289 -- Program_Error. Here we only issue a warning, since we generally
1290 -- support the use of potentially blocking operations in the absence
1293 -- Indirect blocking through a subprogram call cannot be diagnosed
1294 -- statically without interprocedural analysis, so we do not attempt
1297 S := Scope (Current_Scope);
1298 while Present (S) and then S /= Standard_Standard loop
1299 if Is_Protected_Type (S) then
1301 ("potentially blocking operation in protected operation?", N);
1307 end Check_Potentially_Blocking_Operation;
1309 ------------------------------
1310 -- Check_Unprotected_Access --
1311 ------------------------------
1313 procedure Check_Unprotected_Access
1317 Cont_Encl_Typ : Entity_Id;
1318 Pref_Encl_Typ : Entity_Id;
1320 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1321 -- Check whether Obj is a private component of a protected object.
1322 -- Return the protected type where the component resides, Empty
1325 function Is_Public_Operation return Boolean;
1326 -- Verify that the enclosing operation is callable from outside the
1327 -- protected object, to minimize false positives.
1329 ------------------------------
1330 -- Enclosing_Protected_Type --
1331 ------------------------------
1333 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1335 if Is_Entity_Name (Obj) then
1337 Ent : Entity_Id := Entity (Obj);
1340 -- The object can be a renaming of a private component, use
1341 -- the original record component.
1343 if Is_Prival (Ent) then
1344 Ent := Prival_Link (Ent);
1347 if Is_Protected_Type (Scope (Ent)) then
1353 -- For indexed and selected components, recursively check the prefix
1355 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1356 return Enclosing_Protected_Type (Prefix (Obj));
1358 -- The object does not denote a protected component
1363 end Enclosing_Protected_Type;
1365 -------------------------
1366 -- Is_Public_Operation --
1367 -------------------------
1369 function Is_Public_Operation return Boolean is
1376 and then S /= Pref_Encl_Typ
1378 if Scope (S) = Pref_Encl_Typ then
1379 E := First_Entity (Pref_Encl_Typ);
1381 and then E /= First_Private_Entity (Pref_Encl_Typ)
1394 end Is_Public_Operation;
1396 -- Start of processing for Check_Unprotected_Access
1399 if Nkind (Expr) = N_Attribute_Reference
1400 and then Attribute_Name (Expr) = Name_Unchecked_Access
1402 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1403 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1405 -- Check whether we are trying to export a protected component to a
1406 -- context with an equal or lower access level.
1408 if Present (Pref_Encl_Typ)
1409 and then No (Cont_Encl_Typ)
1410 and then Is_Public_Operation
1411 and then Scope_Depth (Pref_Encl_Typ) >=
1412 Object_Access_Level (Context)
1415 ("?possible unprotected access to protected data", Expr);
1418 end Check_Unprotected_Access;
1424 procedure Check_VMS (Construct : Node_Id) is
1426 if not OpenVMS_On_Target then
1428 ("this construct is allowed only in Open'V'M'S", Construct);
1432 ------------------------
1433 -- Collect_Interfaces --
1434 ------------------------
1436 procedure Collect_Interfaces
1438 Ifaces_List : out Elist_Id;
1439 Exclude_Parents : Boolean := False;
1440 Use_Full_View : Boolean := True)
1442 procedure Collect (Typ : Entity_Id);
1443 -- Subsidiary subprogram used to traverse the whole list
1444 -- of directly and indirectly implemented interfaces
1450 procedure Collect (Typ : Entity_Id) is
1451 Ancestor : Entity_Id;
1459 -- Handle private types
1462 and then Is_Private_Type (Typ)
1463 and then Present (Full_View (Typ))
1465 Full_T := Full_View (Typ);
1468 -- Include the ancestor if we are generating the whole list of
1469 -- abstract interfaces.
1471 if Etype (Full_T) /= Typ
1473 -- Protect the frontend against wrong sources. For example:
1476 -- type A is tagged null record;
1477 -- type B is new A with private;
1478 -- type C is new A with private;
1480 -- type B is new C with null record;
1481 -- type C is new B with null record;
1484 and then Etype (Full_T) /= T
1486 Ancestor := Etype (Full_T);
1489 if Is_Interface (Ancestor)
1490 and then not Exclude_Parents
1492 Append_Unique_Elmt (Ancestor, Ifaces_List);
1496 -- Traverse the graph of ancestor interfaces
1498 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1499 Id := First (Abstract_Interface_List (Full_T));
1500 while Present (Id) loop
1501 Iface := Etype (Id);
1503 -- Protect against wrong uses. For example:
1504 -- type I is interface;
1505 -- type O is tagged null record;
1506 -- type Wrong is new I and O with null record; -- ERROR
1508 if Is_Interface (Iface) then
1510 and then Etype (T) /= T
1511 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1516 Append_Unique_Elmt (Iface, Ifaces_List);
1525 -- Start of processing for Collect_Interfaces
1528 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1529 Ifaces_List := New_Elmt_List;
1531 end Collect_Interfaces;
1533 ----------------------------------
1534 -- Collect_Interface_Components --
1535 ----------------------------------
1537 procedure Collect_Interface_Components
1538 (Tagged_Type : Entity_Id;
1539 Components_List : out Elist_Id)
1541 procedure Collect (Typ : Entity_Id);
1542 -- Subsidiary subprogram used to climb to the parents
1548 procedure Collect (Typ : Entity_Id) is
1549 Tag_Comp : Entity_Id;
1550 Parent_Typ : Entity_Id;
1553 -- Handle private types
1555 if Present (Full_View (Etype (Typ))) then
1556 Parent_Typ := Full_View (Etype (Typ));
1558 Parent_Typ := Etype (Typ);
1561 if Parent_Typ /= Typ
1563 -- Protect the frontend against wrong sources. For example:
1566 -- type A is tagged null record;
1567 -- type B is new A with private;
1568 -- type C is new A with private;
1570 -- type B is new C with null record;
1571 -- type C is new B with null record;
1574 and then Parent_Typ /= Tagged_Type
1576 Collect (Parent_Typ);
1579 -- Collect the components containing tags of secondary dispatch
1582 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1583 while Present (Tag_Comp) loop
1584 pragma Assert (Present (Related_Type (Tag_Comp)));
1585 Append_Elmt (Tag_Comp, Components_List);
1587 Tag_Comp := Next_Tag_Component (Tag_Comp);
1591 -- Start of processing for Collect_Interface_Components
1594 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1595 and then Is_Tagged_Type (Tagged_Type));
1597 Components_List := New_Elmt_List;
1598 Collect (Tagged_Type);
1599 end Collect_Interface_Components;
1601 -----------------------------
1602 -- Collect_Interfaces_Info --
1603 -----------------------------
1605 procedure Collect_Interfaces_Info
1607 Ifaces_List : out Elist_Id;
1608 Components_List : out Elist_Id;
1609 Tags_List : out Elist_Id)
1611 Comps_List : Elist_Id;
1612 Comp_Elmt : Elmt_Id;
1613 Comp_Iface : Entity_Id;
1614 Iface_Elmt : Elmt_Id;
1617 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1618 -- Search for the secondary tag associated with the interface type
1619 -- Iface that is implemented by T.
1625 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1628 if not Is_CPP_Class (T) then
1629 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1631 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1635 and then Is_Tag (Node (ADT))
1636 and then Related_Type (Node (ADT)) /= Iface
1638 -- Skip secondary dispatch table referencing thunks to user
1639 -- defined primitives covered by this interface.
1641 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1644 -- Skip secondary dispatch tables of Ada types
1646 if not Is_CPP_Class (T) then
1648 -- Skip secondary dispatch table referencing thunks to
1649 -- predefined primitives.
1651 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1654 -- Skip secondary dispatch table referencing user-defined
1655 -- primitives covered by this interface.
1657 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1660 -- Skip secondary dispatch table referencing predefined
1663 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1668 pragma Assert (Is_Tag (Node (ADT)));
1672 -- Start of processing for Collect_Interfaces_Info
1675 Collect_Interfaces (T, Ifaces_List);
1676 Collect_Interface_Components (T, Comps_List);
1678 -- Search for the record component and tag associated with each
1679 -- interface type of T.
1681 Components_List := New_Elmt_List;
1682 Tags_List := New_Elmt_List;
1684 Iface_Elmt := First_Elmt (Ifaces_List);
1685 while Present (Iface_Elmt) loop
1686 Iface := Node (Iface_Elmt);
1688 -- Associate the primary tag component and the primary dispatch table
1689 -- with all the interfaces that are parents of T
1691 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1692 Append_Elmt (First_Tag_Component (T), Components_List);
1693 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1695 -- Otherwise search for the tag component and secondary dispatch
1699 Comp_Elmt := First_Elmt (Comps_List);
1700 while Present (Comp_Elmt) loop
1701 Comp_Iface := Related_Type (Node (Comp_Elmt));
1703 if Comp_Iface = Iface
1704 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1706 Append_Elmt (Node (Comp_Elmt), Components_List);
1707 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1711 Next_Elmt (Comp_Elmt);
1713 pragma Assert (Present (Comp_Elmt));
1716 Next_Elmt (Iface_Elmt);
1718 end Collect_Interfaces_Info;
1720 ---------------------
1721 -- Collect_Parents --
1722 ---------------------
1724 procedure Collect_Parents
1726 List : out Elist_Id;
1727 Use_Full_View : Boolean := True)
1729 Current_Typ : Entity_Id := T;
1730 Parent_Typ : Entity_Id;
1733 List := New_Elmt_List;
1735 -- No action if the if the type has no parents
1737 if T = Etype (T) then
1742 Parent_Typ := Etype (Current_Typ);
1744 if Is_Private_Type (Parent_Typ)
1745 and then Present (Full_View (Parent_Typ))
1746 and then Use_Full_View
1748 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1751 Append_Elmt (Parent_Typ, List);
1753 exit when Parent_Typ = Current_Typ;
1754 Current_Typ := Parent_Typ;
1756 end Collect_Parents;
1758 ----------------------------------
1759 -- Collect_Primitive_Operations --
1760 ----------------------------------
1762 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1763 B_Type : constant Entity_Id := Base_Type (T);
1764 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1765 B_Scope : Entity_Id := Scope (B_Type);
1769 Formal_Derived : Boolean := False;
1772 function Match (E : Entity_Id) return Boolean;
1773 -- True if E's base type is B_Type, or E is of an anonymous access type
1774 -- and the base type of its designated type is B_Type.
1780 function Match (E : Entity_Id) return Boolean is
1781 Etyp : Entity_Id := Etype (E);
1784 if Ekind (Etyp) = E_Anonymous_Access_Type then
1785 Etyp := Designated_Type (Etyp);
1788 return Base_Type (Etyp) = B_Type;
1791 -- Start of processing for Collect_Primitive_Operations
1794 -- For tagged types, the primitive operations are collected as they
1795 -- are declared, and held in an explicit list which is simply returned.
1797 if Is_Tagged_Type (B_Type) then
1798 return Primitive_Operations (B_Type);
1800 -- An untagged generic type that is a derived type inherits the
1801 -- primitive operations of its parent type. Other formal types only
1802 -- have predefined operators, which are not explicitly represented.
1804 elsif Is_Generic_Type (B_Type) then
1805 if Nkind (B_Decl) = N_Formal_Type_Declaration
1806 and then Nkind (Formal_Type_Definition (B_Decl))
1807 = N_Formal_Derived_Type_Definition
1809 Formal_Derived := True;
1811 return New_Elmt_List;
1815 Op_List := New_Elmt_List;
1817 if B_Scope = Standard_Standard then
1818 if B_Type = Standard_String then
1819 Append_Elmt (Standard_Op_Concat, Op_List);
1821 elsif B_Type = Standard_Wide_String then
1822 Append_Elmt (Standard_Op_Concatw, Op_List);
1828 elsif (Is_Package_Or_Generic_Package (B_Scope)
1830 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1832 or else Is_Derived_Type (B_Type)
1834 -- The primitive operations appear after the base type, except
1835 -- if the derivation happens within the private part of B_Scope
1836 -- and the type is a private type, in which case both the type
1837 -- and some primitive operations may appear before the base
1838 -- type, and the list of candidates starts after the type.
1840 if In_Open_Scopes (B_Scope)
1841 and then Scope (T) = B_Scope
1842 and then In_Private_Part (B_Scope)
1844 Id := Next_Entity (T);
1846 Id := Next_Entity (B_Type);
1849 while Present (Id) loop
1851 -- Note that generic formal subprograms are not
1852 -- considered to be primitive operations and thus
1853 -- are never inherited.
1855 if Is_Overloadable (Id)
1856 and then Nkind (Parent (Parent (Id)))
1857 not in N_Formal_Subprogram_Declaration
1865 Formal := First_Formal (Id);
1866 while Present (Formal) loop
1867 if Match (Formal) then
1872 Next_Formal (Formal);
1876 -- For a formal derived type, the only primitives are the
1877 -- ones inherited from the parent type. Operations appearing
1878 -- in the package declaration are not primitive for it.
1881 and then (not Formal_Derived
1882 or else Present (Alias (Id)))
1884 -- In the special case of an equality operator aliased to
1885 -- an overriding dispatching equality belonging to the same
1886 -- type, we don't include it in the list of primitives.
1887 -- This avoids inheriting multiple equality operators when
1888 -- deriving from untagged private types whose full type is
1889 -- tagged, which can otherwise cause ambiguities. Note that
1890 -- this should only happen for this kind of untagged parent
1891 -- type, since normally dispatching operations are inherited
1892 -- using the type's Primitive_Operations list.
1894 if Chars (Id) = Name_Op_Eq
1895 and then Is_Dispatching_Operation (Id)
1896 and then Present (Alias (Id))
1897 and then Present (Overridden_Operation (Alias (Id)))
1898 and then Base_Type (Etype (First_Entity (Id))) =
1899 Base_Type (Etype (First_Entity (Alias (Id))))
1903 -- Include the subprogram in the list of primitives
1906 Append_Elmt (Id, Op_List);
1913 -- For a type declared in System, some of its operations may
1914 -- appear in the target-specific extension to System.
1917 and then B_Scope = RTU_Entity (System)
1918 and then Present_System_Aux
1920 B_Scope := System_Aux_Id;
1921 Id := First_Entity (System_Aux_Id);
1927 end Collect_Primitive_Operations;
1929 -----------------------------------
1930 -- Compile_Time_Constraint_Error --
1931 -----------------------------------
1933 function Compile_Time_Constraint_Error
1936 Ent : Entity_Id := Empty;
1937 Loc : Source_Ptr := No_Location;
1938 Warn : Boolean := False) return Node_Id
1940 Msgc : String (1 .. Msg'Length + 2);
1941 -- Copy of message, with room for possible ? and ! at end
1951 -- A static constraint error in an instance body is not a fatal error.
1952 -- we choose to inhibit the message altogether, because there is no
1953 -- obvious node (for now) on which to post it. On the other hand the
1954 -- offending node must be replaced with a constraint_error in any case.
1956 -- No messages are generated if we already posted an error on this node
1958 if not Error_Posted (N) then
1959 if Loc /= No_Location then
1965 Msgc (1 .. Msg'Length) := Msg;
1968 -- Message is a warning, even in Ada 95 case
1970 if Msg (Msg'Last) = '?' then
1973 -- In Ada 83, all messages are warnings. In the private part and
1974 -- the body of an instance, constraint_checks are only warnings.
1975 -- We also make this a warning if the Warn parameter is set.
1978 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1984 elsif In_Instance_Not_Visible then
1989 -- Otherwise we have a real error message (Ada 95 static case)
1990 -- and we make this an unconditional message. Note that in the
1991 -- warning case we do not make the message unconditional, it seems
1992 -- quite reasonable to delete messages like this (about exceptions
1993 -- that will be raised) in dead code.
2001 -- Should we generate a warning? The answer is not quite yes. The
2002 -- very annoying exception occurs in the case of a short circuit
2003 -- operator where the left operand is static and decisive. Climb
2004 -- parents to see if that is the case we have here. Conditional
2005 -- expressions with decisive conditions are a similar situation.
2013 -- And then with False as left operand
2015 if Nkind (P) = N_And_Then
2016 and then Compile_Time_Known_Value (Left_Opnd (P))
2017 and then Is_False (Expr_Value (Left_Opnd (P)))
2022 -- OR ELSE with True as left operand
2024 elsif Nkind (P) = N_Or_Else
2025 and then Compile_Time_Known_Value (Left_Opnd (P))
2026 and then Is_True (Expr_Value (Left_Opnd (P)))
2031 -- Conditional expression
2033 elsif Nkind (P) = N_Conditional_Expression then
2035 Cond : constant Node_Id := First (Expressions (P));
2036 Texp : constant Node_Id := Next (Cond);
2037 Fexp : constant Node_Id := Next (Texp);
2040 if Compile_Time_Known_Value (Cond) then
2042 -- Condition is True and we are in the right operand
2044 if Is_True (Expr_Value (Cond))
2045 and then OldP = Fexp
2050 -- Condition is False and we are in the left operand
2052 elsif Is_False (Expr_Value (Cond))
2053 and then OldP = Texp
2061 -- Special case for component association in aggregates, where
2062 -- we want to keep climbing up to the parent aggregate.
2064 elsif Nkind (P) = N_Component_Association
2065 and then Nkind (Parent (P)) = N_Aggregate
2069 -- Keep going if within subexpression
2072 exit when Nkind (P) not in N_Subexpr;
2077 if Present (Ent) then
2078 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2080 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2084 if Inside_Init_Proc then
2086 ("\?& will be raised for objects of this type",
2087 N, Standard_Constraint_Error, Eloc);
2090 ("\?& will be raised at run time",
2091 N, Standard_Constraint_Error, Eloc);
2096 ("\static expression fails Constraint_Check", Eloc);
2097 Set_Error_Posted (N);
2103 end Compile_Time_Constraint_Error;
2105 -----------------------
2106 -- Conditional_Delay --
2107 -----------------------
2109 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2111 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2112 Set_Has_Delayed_Freeze (New_Ent);
2114 end Conditional_Delay;
2116 -------------------------
2117 -- Copy_Parameter_List --
2118 -------------------------
2120 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2121 Loc : constant Source_Ptr := Sloc (Subp_Id);
2126 if No (First_Formal (Subp_Id)) then
2130 Formal := First_Formal (Subp_Id);
2131 while Present (Formal) loop
2133 (Make_Parameter_Specification (Loc,
2134 Defining_Identifier =>
2135 Make_Defining_Identifier (Sloc (Formal),
2136 Chars => Chars (Formal)),
2137 In_Present => In_Present (Parent (Formal)),
2138 Out_Present => Out_Present (Parent (Formal)),
2140 New_Reference_To (Etype (Formal), Loc),
2142 New_Copy_Tree (Expression (Parent (Formal)))),
2145 Next_Formal (Formal);
2150 end Copy_Parameter_List;
2152 --------------------
2153 -- Current_Entity --
2154 --------------------
2156 -- The currently visible definition for a given identifier is the
2157 -- one most chained at the start of the visibility chain, i.e. the
2158 -- one that is referenced by the Node_Id value of the name of the
2159 -- given identifier.
2161 function Current_Entity (N : Node_Id) return Entity_Id is
2163 return Get_Name_Entity_Id (Chars (N));
2166 -----------------------------
2167 -- Current_Entity_In_Scope --
2168 -----------------------------
2170 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2172 CS : constant Entity_Id := Current_Scope;
2174 Transient_Case : constant Boolean := Scope_Is_Transient;
2177 E := Get_Name_Entity_Id (Chars (N));
2179 and then Scope (E) /= CS
2180 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2186 end Current_Entity_In_Scope;
2192 function Current_Scope return Entity_Id is
2194 if Scope_Stack.Last = -1 then
2195 return Standard_Standard;
2198 C : constant Entity_Id :=
2199 Scope_Stack.Table (Scope_Stack.Last).Entity;
2204 return Standard_Standard;
2210 ------------------------
2211 -- Current_Subprogram --
2212 ------------------------
2214 function Current_Subprogram return Entity_Id is
2215 Scop : constant Entity_Id := Current_Scope;
2217 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2220 return Enclosing_Subprogram (Scop);
2222 end Current_Subprogram;
2224 ---------------------
2225 -- Defining_Entity --
2226 ---------------------
2228 function Defining_Entity (N : Node_Id) return Entity_Id is
2229 K : constant Node_Kind := Nkind (N);
2230 Err : Entity_Id := Empty;
2235 N_Subprogram_Declaration |
2236 N_Abstract_Subprogram_Declaration |
2238 N_Package_Declaration |
2239 N_Subprogram_Renaming_Declaration |
2240 N_Subprogram_Body_Stub |
2241 N_Generic_Subprogram_Declaration |
2242 N_Generic_Package_Declaration |
2243 N_Formal_Subprogram_Declaration
2245 return Defining_Entity (Specification (N));
2248 N_Component_Declaration |
2249 N_Defining_Program_Unit_Name |
2250 N_Discriminant_Specification |
2252 N_Entry_Declaration |
2253 N_Entry_Index_Specification |
2254 N_Exception_Declaration |
2255 N_Exception_Renaming_Declaration |
2256 N_Formal_Object_Declaration |
2257 N_Formal_Package_Declaration |
2258 N_Formal_Type_Declaration |
2259 N_Full_Type_Declaration |
2260 N_Implicit_Label_Declaration |
2261 N_Incomplete_Type_Declaration |
2262 N_Loop_Parameter_Specification |
2263 N_Number_Declaration |
2264 N_Object_Declaration |
2265 N_Object_Renaming_Declaration |
2266 N_Package_Body_Stub |
2267 N_Parameter_Specification |
2268 N_Private_Extension_Declaration |
2269 N_Private_Type_Declaration |
2271 N_Protected_Body_Stub |
2272 N_Protected_Type_Declaration |
2273 N_Single_Protected_Declaration |
2274 N_Single_Task_Declaration |
2275 N_Subtype_Declaration |
2278 N_Task_Type_Declaration
2280 return Defining_Identifier (N);
2283 return Defining_Entity (Proper_Body (N));
2286 N_Function_Instantiation |
2287 N_Function_Specification |
2288 N_Generic_Function_Renaming_Declaration |
2289 N_Generic_Package_Renaming_Declaration |
2290 N_Generic_Procedure_Renaming_Declaration |
2292 N_Package_Instantiation |
2293 N_Package_Renaming_Declaration |
2294 N_Package_Specification |
2295 N_Procedure_Instantiation |
2296 N_Procedure_Specification
2299 Nam : constant Node_Id := Defining_Unit_Name (N);
2302 if Nkind (Nam) in N_Entity then
2305 -- For Error, make up a name and attach to declaration
2306 -- so we can continue semantic analysis
2308 elsif Nam = Error then
2309 Err := Make_Temporary (Sloc (N), 'T');
2310 Set_Defining_Unit_Name (N, Err);
2313 -- If not an entity, get defining identifier
2316 return Defining_Identifier (Nam);
2320 when N_Block_Statement =>
2321 return Entity (Identifier (N));
2324 raise Program_Error;
2327 end Defining_Entity;
2329 --------------------------
2330 -- Denotes_Discriminant --
2331 --------------------------
2333 function Denotes_Discriminant
2335 Check_Concurrent : Boolean := False) return Boolean
2339 if not Is_Entity_Name (N)
2340 or else No (Entity (N))
2347 -- If we are checking for a protected type, the discriminant may have
2348 -- been rewritten as the corresponding discriminal of the original type
2349 -- or of the corresponding concurrent record, depending on whether we
2350 -- are in the spec or body of the protected type.
2352 return Ekind (E) = E_Discriminant
2355 and then Ekind (E) = E_In_Parameter
2356 and then Present (Discriminal_Link (E))
2358 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2360 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2362 end Denotes_Discriminant;
2364 -------------------------
2365 -- Denotes_Same_Object --
2366 -------------------------
2368 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2369 Obj1 : Node_Id := A1;
2370 Obj2 : Node_Id := A2;
2372 procedure Check_Renaming (Obj : in out Node_Id);
2373 -- If an object is a renaming, examine renamed object. If it is a
2374 -- dereference of a variable, or an indexed expression with non-constant
2375 -- indexes, no overlap check can be reported.
2377 --------------------
2378 -- Check_Renaming --
2379 --------------------
2381 procedure Check_Renaming (Obj : in out Node_Id) is
2383 if Is_Entity_Name (Obj)
2384 and then Present (Renamed_Entity (Entity (Obj)))
2386 Obj := Renamed_Entity (Entity (Obj));
2387 if Nkind (Obj) = N_Explicit_Dereference
2388 and then Is_Variable (Prefix (Obj))
2392 elsif Nkind (Obj) = N_Indexed_Component then
2397 Indx := First (Expressions (Obj));
2398 while Present (Indx) loop
2399 if not Is_OK_Static_Expression (Indx) then
2411 -- Start of processing for Denotes_Same_Object
2414 Check_Renaming (Obj1);
2415 Check_Renaming (Obj2);
2423 -- If we have entity names, then must be same entity
2425 if Is_Entity_Name (Obj1) then
2426 if Is_Entity_Name (Obj2) then
2427 return Entity (Obj1) = Entity (Obj2);
2432 -- No match if not same node kind
2434 elsif Nkind (Obj1) /= Nkind (Obj2) then
2437 -- For selected components, must have same prefix and selector
2439 elsif Nkind (Obj1) = N_Selected_Component then
2440 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2442 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2444 -- For explicit dereferences, prefixes must be same
2446 elsif Nkind (Obj1) = N_Explicit_Dereference then
2447 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2449 -- For indexed components, prefixes and all subscripts must be the same
2451 elsif Nkind (Obj1) = N_Indexed_Component then
2452 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2458 Indx1 := First (Expressions (Obj1));
2459 Indx2 := First (Expressions (Obj2));
2460 while Present (Indx1) loop
2462 -- Indexes must denote the same static value or same object
2464 if Is_OK_Static_Expression (Indx1) then
2465 if not Is_OK_Static_Expression (Indx2) then
2468 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2472 elsif not Denotes_Same_Object (Indx1, Indx2) then
2486 -- For slices, prefixes must match and bounds must match
2488 elsif Nkind (Obj1) = N_Slice
2489 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2492 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2495 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2496 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2498 -- Check whether bounds are statically identical. There is no
2499 -- attempt to detect partial overlap of slices.
2501 return Denotes_Same_Object (Lo1, Lo2)
2502 and then Denotes_Same_Object (Hi1, Hi2);
2505 -- Literals will appear as indexes. Isn't this where we should check
2506 -- Known_At_Compile_Time at least if we are generating warnings ???
2508 elsif Nkind (Obj1) = N_Integer_Literal then
2509 return Intval (Obj1) = Intval (Obj2);
2514 end Denotes_Same_Object;
2516 -------------------------
2517 -- Denotes_Same_Prefix --
2518 -------------------------
2520 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2523 if Is_Entity_Name (A1) then
2524 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2525 and then not Is_Access_Type (Etype (A1))
2527 return Denotes_Same_Object (A1, Prefix (A2))
2528 or else Denotes_Same_Prefix (A1, Prefix (A2));
2533 elsif Is_Entity_Name (A2) then
2534 return Denotes_Same_Prefix (A2, A1);
2536 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2538 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2541 Root1, Root2 : Node_Id;
2542 Depth1, Depth2 : Int := 0;
2545 Root1 := Prefix (A1);
2546 while not Is_Entity_Name (Root1) loop
2548 (Root1, N_Selected_Component, N_Indexed_Component)
2552 Root1 := Prefix (Root1);
2555 Depth1 := Depth1 + 1;
2558 Root2 := Prefix (A2);
2559 while not Is_Entity_Name (Root2) loop
2561 (Root2, N_Selected_Component, N_Indexed_Component)
2565 Root2 := Prefix (Root2);
2568 Depth2 := Depth2 + 1;
2571 -- If both have the same depth and they do not denote the same
2572 -- object, they are disjoint and not warning is needed.
2574 if Depth1 = Depth2 then
2577 elsif Depth1 > Depth2 then
2578 Root1 := Prefix (A1);
2579 for I in 1 .. Depth1 - Depth2 - 1 loop
2580 Root1 := Prefix (Root1);
2583 return Denotes_Same_Object (Root1, A2);
2586 Root2 := Prefix (A2);
2587 for I in 1 .. Depth2 - Depth1 - 1 loop
2588 Root2 := Prefix (Root2);
2591 return Denotes_Same_Object (A1, Root2);
2598 end Denotes_Same_Prefix;
2600 ----------------------
2601 -- Denotes_Variable --
2602 ----------------------
2604 function Denotes_Variable (N : Node_Id) return Boolean is
2606 return Is_Variable (N) and then Paren_Count (N) = 0;
2607 end Denotes_Variable;
2609 -----------------------------
2610 -- Depends_On_Discriminant --
2611 -----------------------------
2613 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2618 Get_Index_Bounds (N, L, H);
2619 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2620 end Depends_On_Discriminant;
2622 -------------------------
2623 -- Designate_Same_Unit --
2624 -------------------------
2626 function Designate_Same_Unit
2628 Name2 : Node_Id) return Boolean
2630 K1 : constant Node_Kind := Nkind (Name1);
2631 K2 : constant Node_Kind := Nkind (Name2);
2633 function Prefix_Node (N : Node_Id) return Node_Id;
2634 -- Returns the parent unit name node of a defining program unit name
2635 -- or the prefix if N is a selected component or an expanded name.
2637 function Select_Node (N : Node_Id) return Node_Id;
2638 -- Returns the defining identifier node of a defining program unit
2639 -- name or the selector node if N is a selected component or an
2646 function Prefix_Node (N : Node_Id) return Node_Id is
2648 if Nkind (N) = N_Defining_Program_Unit_Name then
2660 function Select_Node (N : Node_Id) return Node_Id is
2662 if Nkind (N) = N_Defining_Program_Unit_Name then
2663 return Defining_Identifier (N);
2666 return Selector_Name (N);
2670 -- Start of processing for Designate_Next_Unit
2673 if (K1 = N_Identifier or else
2674 K1 = N_Defining_Identifier)
2676 (K2 = N_Identifier or else
2677 K2 = N_Defining_Identifier)
2679 return Chars (Name1) = Chars (Name2);
2682 (K1 = N_Expanded_Name or else
2683 K1 = N_Selected_Component or else
2684 K1 = N_Defining_Program_Unit_Name)
2686 (K2 = N_Expanded_Name or else
2687 K2 = N_Selected_Component or else
2688 K2 = N_Defining_Program_Unit_Name)
2691 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2693 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2698 end Designate_Same_Unit;
2700 --------------------------
2701 -- Enclosing_CPP_Parent --
2702 --------------------------
2704 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2705 Parent_Typ : Entity_Id := Typ;
2708 while not Is_CPP_Class (Parent_Typ)
2709 and then Etype (Parent_Typ) /= Parent_Typ
2711 Parent_Typ := Etype (Parent_Typ);
2713 if Is_Private_Type (Parent_Typ) then
2714 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2718 pragma Assert (Is_CPP_Class (Parent_Typ));
2720 end Enclosing_CPP_Parent;
2722 ----------------------------
2723 -- Enclosing_Generic_Body --
2724 ----------------------------
2726 function Enclosing_Generic_Body
2727 (N : Node_Id) return Node_Id
2735 while Present (P) loop
2736 if Nkind (P) = N_Package_Body
2737 or else Nkind (P) = N_Subprogram_Body
2739 Spec := Corresponding_Spec (P);
2741 if Present (Spec) then
2742 Decl := Unit_Declaration_Node (Spec);
2744 if Nkind (Decl) = N_Generic_Package_Declaration
2745 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2756 end Enclosing_Generic_Body;
2758 ----------------------------
2759 -- Enclosing_Generic_Unit --
2760 ----------------------------
2762 function Enclosing_Generic_Unit
2763 (N : Node_Id) return Node_Id
2771 while Present (P) loop
2772 if Nkind (P) = N_Generic_Package_Declaration
2773 or else Nkind (P) = N_Generic_Subprogram_Declaration
2777 elsif Nkind (P) = N_Package_Body
2778 or else Nkind (P) = N_Subprogram_Body
2780 Spec := Corresponding_Spec (P);
2782 if Present (Spec) then
2783 Decl := Unit_Declaration_Node (Spec);
2785 if Nkind (Decl) = N_Generic_Package_Declaration
2786 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2797 end Enclosing_Generic_Unit;
2799 -------------------------------
2800 -- Enclosing_Lib_Unit_Entity --
2801 -------------------------------
2803 function Enclosing_Lib_Unit_Entity return Entity_Id is
2804 Unit_Entity : Entity_Id;
2807 -- Look for enclosing library unit entity by following scope links.
2808 -- Equivalent to, but faster than indexing through the scope stack.
2810 Unit_Entity := Current_Scope;
2811 while (Present (Scope (Unit_Entity))
2812 and then Scope (Unit_Entity) /= Standard_Standard)
2813 and not Is_Child_Unit (Unit_Entity)
2815 Unit_Entity := Scope (Unit_Entity);
2819 end Enclosing_Lib_Unit_Entity;
2821 -----------------------------
2822 -- Enclosing_Lib_Unit_Node --
2823 -----------------------------
2825 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2826 Current_Node : Node_Id;
2830 while Present (Current_Node)
2831 and then Nkind (Current_Node) /= N_Compilation_Unit
2833 Current_Node := Parent (Current_Node);
2836 if Nkind (Current_Node) /= N_Compilation_Unit then
2840 return Current_Node;
2841 end Enclosing_Lib_Unit_Node;
2843 --------------------------
2844 -- Enclosing_Subprogram --
2845 --------------------------
2847 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2848 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2851 if Dynamic_Scope = Standard_Standard then
2854 elsif Dynamic_Scope = Empty then
2857 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2858 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2860 elsif Ekind (Dynamic_Scope) = E_Block
2861 or else Ekind (Dynamic_Scope) = E_Return_Statement
2863 return Enclosing_Subprogram (Dynamic_Scope);
2865 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2866 return Get_Task_Body_Procedure (Dynamic_Scope);
2868 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2869 and then Present (Full_View (Dynamic_Scope))
2870 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2872 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2874 -- No body is generated if the protected operation is eliminated
2876 elsif Convention (Dynamic_Scope) = Convention_Protected
2877 and then not Is_Eliminated (Dynamic_Scope)
2878 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2880 return Protected_Body_Subprogram (Dynamic_Scope);
2883 return Dynamic_Scope;
2885 end Enclosing_Subprogram;
2887 ------------------------
2888 -- Ensure_Freeze_Node --
2889 ------------------------
2891 procedure Ensure_Freeze_Node (E : Entity_Id) is
2895 if No (Freeze_Node (E)) then
2896 FN := Make_Freeze_Entity (Sloc (E));
2897 Set_Has_Delayed_Freeze (E);
2898 Set_Freeze_Node (E, FN);
2899 Set_Access_Types_To_Process (FN, No_Elist);
2900 Set_TSS_Elist (FN, No_Elist);
2903 end Ensure_Freeze_Node;
2909 procedure Enter_Name (Def_Id : Entity_Id) is
2910 C : constant Entity_Id := Current_Entity (Def_Id);
2911 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2912 S : constant Entity_Id := Current_Scope;
2915 Generate_Definition (Def_Id);
2917 -- Add new name to current scope declarations. Check for duplicate
2918 -- declaration, which may or may not be a genuine error.
2922 -- Case of previous entity entered because of a missing declaration
2923 -- or else a bad subtype indication. Best is to use the new entity,
2924 -- and make the previous one invisible.
2926 if Etype (E) = Any_Type then
2927 Set_Is_Immediately_Visible (E, False);
2929 -- Case of renaming declaration constructed for package instances.
2930 -- if there is an explicit declaration with the same identifier,
2931 -- the renaming is not immediately visible any longer, but remains
2932 -- visible through selected component notation.
2934 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2935 and then not Comes_From_Source (E)
2937 Set_Is_Immediately_Visible (E, False);
2939 -- The new entity may be the package renaming, which has the same
2940 -- same name as a generic formal which has been seen already.
2942 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2943 and then not Comes_From_Source (Def_Id)
2945 Set_Is_Immediately_Visible (E, False);
2947 -- For a fat pointer corresponding to a remote access to subprogram,
2948 -- we use the same identifier as the RAS type, so that the proper
2949 -- name appears in the stub. This type is only retrieved through
2950 -- the RAS type and never by visibility, and is not added to the
2951 -- visibility list (see below).
2953 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2954 and then Present (Corresponding_Remote_Type (Def_Id))
2958 -- A controller component for a type extension overrides the
2959 -- inherited component.
2961 elsif Chars (E) = Name_uController then
2964 -- Case of an implicit operation or derived literal. The new entity
2965 -- hides the implicit one, which is removed from all visibility,
2966 -- i.e. the entity list of its scope, and homonym chain of its name.
2968 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2969 or else Is_Internal (E)
2973 Prev_Vis : Entity_Id;
2974 Decl : constant Node_Id := Parent (E);
2977 -- If E is an implicit declaration, it cannot be the first
2978 -- entity in the scope.
2980 Prev := First_Entity (Current_Scope);
2981 while Present (Prev)
2982 and then Next_Entity (Prev) /= E
2989 -- If E is not on the entity chain of the current scope,
2990 -- it is an implicit declaration in the generic formal
2991 -- part of a generic subprogram. When analyzing the body,
2992 -- the generic formals are visible but not on the entity
2993 -- chain of the subprogram. The new entity will become
2994 -- the visible one in the body.
2997 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3001 Set_Next_Entity (Prev, Next_Entity (E));
3003 if No (Next_Entity (Prev)) then
3004 Set_Last_Entity (Current_Scope, Prev);
3007 if E = Current_Entity (E) then
3011 Prev_Vis := Current_Entity (E);
3012 while Homonym (Prev_Vis) /= E loop
3013 Prev_Vis := Homonym (Prev_Vis);
3017 if Present (Prev_Vis) then
3019 -- Skip E in the visibility chain
3021 Set_Homonym (Prev_Vis, Homonym (E));
3024 Set_Name_Entity_Id (Chars (E), Homonym (E));
3029 -- This section of code could use a comment ???
3031 elsif Present (Etype (E))
3032 and then Is_Concurrent_Type (Etype (E))
3037 -- If the homograph is a protected component renaming, it should not
3038 -- be hiding the current entity. Such renamings are treated as weak
3041 elsif Is_Prival (E) then
3042 Set_Is_Immediately_Visible (E, False);
3044 -- In this case the current entity is a protected component renaming.
3045 -- Perform minimal decoration by setting the scope and return since
3046 -- the prival should not be hiding other visible entities.
3048 elsif Is_Prival (Def_Id) then
3049 Set_Scope (Def_Id, Current_Scope);
3052 -- Analogous to privals, the discriminal generated for an entry index
3053 -- parameter acts as a weak declaration. Perform minimal decoration
3054 -- to avoid bogus errors.
3056 elsif Is_Discriminal (Def_Id)
3057 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3059 Set_Scope (Def_Id, Current_Scope);
3062 -- In the body or private part of an instance, a type extension may
3063 -- introduce a component with the same name as that of an actual. The
3064 -- legality rule is not enforced, but the semantics of the full type
3065 -- with two components of same name are not clear at this point???
3067 elsif In_Instance_Not_Visible then
3070 -- When compiling a package body, some child units may have become
3071 -- visible. They cannot conflict with local entities that hide them.
3073 elsif Is_Child_Unit (E)
3074 and then In_Open_Scopes (Scope (E))
3075 and then not Is_Immediately_Visible (E)
3079 -- Conversely, with front-end inlining we may compile the parent body
3080 -- first, and a child unit subsequently. The context is now the
3081 -- parent spec, and body entities are not visible.
3083 elsif Is_Child_Unit (Def_Id)
3084 and then Is_Package_Body_Entity (E)
3085 and then not In_Package_Body (Current_Scope)
3089 -- Case of genuine duplicate declaration
3092 Error_Msg_Sloc := Sloc (E);
3094 -- If the previous declaration is an incomplete type declaration
3095 -- this may be an attempt to complete it with a private type. The
3096 -- following avoids confusing cascaded errors.
3098 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3099 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3102 ("incomplete type cannot be completed with a private " &
3103 "declaration", Parent (Def_Id));
3104 Set_Is_Immediately_Visible (E, False);
3105 Set_Full_View (E, Def_Id);
3107 -- An inherited component of a record conflicts with a new
3108 -- discriminant. The discriminant is inserted first in the scope,
3109 -- but the error should be posted on it, not on the component.
3111 elsif Ekind (E) = E_Discriminant
3112 and then Present (Scope (Def_Id))
3113 and then Scope (Def_Id) /= Current_Scope
3115 Error_Msg_Sloc := Sloc (Def_Id);
3116 Error_Msg_N ("& conflicts with declaration#", E);
3119 -- If the name of the unit appears in its own context clause, a
3120 -- dummy package with the name has already been created, and the
3121 -- error emitted. Try to continue quietly.
3123 elsif Error_Posted (E)
3124 and then Sloc (E) = No_Location
3125 and then Nkind (Parent (E)) = N_Package_Specification
3126 and then Current_Scope = Standard_Standard
3128 Set_Scope (Def_Id, Current_Scope);
3132 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3134 -- Avoid cascaded messages with duplicate components in
3137 if Ekind_In (E, E_Component, E_Discriminant) then
3142 if Nkind (Parent (Parent (Def_Id))) =
3143 N_Generic_Subprogram_Declaration
3145 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3147 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3150 -- If entity is in standard, then we are in trouble, because it
3151 -- means that we have a library package with a duplicated name.
3152 -- That's hard to recover from, so abort!
3154 if S = Standard_Standard then
3155 raise Unrecoverable_Error;
3157 -- Otherwise we continue with the declaration. Having two
3158 -- identical declarations should not cause us too much trouble!
3166 -- If we fall through, declaration is OK, at least OK enough to continue
3168 -- If Def_Id is a discriminant or a record component we are in the midst
3169 -- of inheriting components in a derived record definition. Preserve
3170 -- their Ekind and Etype.
3172 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3175 -- If a type is already set, leave it alone (happens when a type
3176 -- declaration is reanalyzed following a call to the optimizer).
3178 elsif Present (Etype (Def_Id)) then
3181 -- Otherwise, the kind E_Void insures that premature uses of the entity
3182 -- will be detected. Any_Type insures that no cascaded errors will occur
3185 Set_Ekind (Def_Id, E_Void);
3186 Set_Etype (Def_Id, Any_Type);
3189 -- Inherited discriminants and components in derived record types are
3190 -- immediately visible. Itypes are not.
3192 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3193 or else (No (Corresponding_Remote_Type (Def_Id))
3194 and then not Is_Itype (Def_Id))
3196 Set_Is_Immediately_Visible (Def_Id);
3197 Set_Current_Entity (Def_Id);
3200 Set_Homonym (Def_Id, C);
3201 Append_Entity (Def_Id, S);
3202 Set_Public_Status (Def_Id);
3204 -- Declaring a homonym is not allowed in SPARK or ALFA ...
3208 -- ... unless the new declaration is in a subprogram, and the visible
3209 -- declaration is a variable declaration or a parameter specification
3210 -- outside that subprogram.
3213 (Nkind_In (Parent (Parent (Def_Id)), N_Subprogram_Body,
3214 N_Function_Specification,
3215 N_Procedure_Specification)
3217 Nkind_In (Parent (C), N_Object_Declaration,
3218 N_Parameter_Specification))
3220 -- ... or the new declaration is in a package, and the visible
3221 -- declaration occurs outside that package.
3224 Nkind_In (Parent (Parent (Def_Id)), N_Package_Specification,
3227 -- ... or the new declaration is a component declaration in a record
3230 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3232 -- Don't issue error for non-source entities
3234 and then Comes_From_Source (Def_Id)
3235 and then Comes_From_Source (C)
3237 Error_Msg_Sloc := Sloc (C);
3238 Check_Formal_Restriction ("redeclaration of identifier &#", Def_Id);
3241 -- Warn if new entity hides an old one
3243 if Warn_On_Hiding and then Present (C)
3245 -- Don't warn for record components since they always have a well
3246 -- defined scope which does not confuse other uses. Note that in
3247 -- some cases, Ekind has not been set yet.
3249 and then Ekind (C) /= E_Component
3250 and then Ekind (C) /= E_Discriminant
3251 and then Nkind (Parent (C)) /= N_Component_Declaration
3252 and then Ekind (Def_Id) /= E_Component
3253 and then Ekind (Def_Id) /= E_Discriminant
3254 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3256 -- Don't warn for one character variables. It is too common to use
3257 -- such variables as locals and will just cause too many false hits.
3259 and then Length_Of_Name (Chars (C)) /= 1
3261 -- Don't warn for non-source entities
3263 and then Comes_From_Source (C)
3264 and then Comes_From_Source (Def_Id)
3266 -- Don't warn unless entity in question is in extended main source
3268 and then In_Extended_Main_Source_Unit (Def_Id)
3270 -- Finally, the hidden entity must be either immediately visible or
3271 -- use visible (i.e. from a used package).
3274 (Is_Immediately_Visible (C)
3276 Is_Potentially_Use_Visible (C))
3278 Error_Msg_Sloc := Sloc (C);
3279 Error_Msg_N ("declaration hides &#?", Def_Id);
3283 --------------------------
3284 -- Explain_Limited_Type --
3285 --------------------------
3287 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3291 -- For array, component type must be limited
3293 if Is_Array_Type (T) then
3294 Error_Msg_Node_2 := T;
3296 ("\component type& of type& is limited", N, Component_Type (T));
3297 Explain_Limited_Type (Component_Type (T), N);
3299 elsif Is_Record_Type (T) then
3301 -- No need for extra messages if explicit limited record
3303 if Is_Limited_Record (Base_Type (T)) then
3307 -- Otherwise find a limited component. Check only components that
3308 -- come from source, or inherited components that appear in the
3309 -- source of the ancestor.
3311 C := First_Component (T);
3312 while Present (C) loop
3313 if Is_Limited_Type (Etype (C))
3315 (Comes_From_Source (C)
3317 (Present (Original_Record_Component (C))
3319 Comes_From_Source (Original_Record_Component (C))))
3321 Error_Msg_Node_2 := T;
3322 Error_Msg_NE ("\component& of type& has limited type", N, C);
3323 Explain_Limited_Type (Etype (C), N);
3330 -- The type may be declared explicitly limited, even if no component
3331 -- of it is limited, in which case we fall out of the loop.
3334 end Explain_Limited_Type;
3340 procedure Find_Actual
3342 Formal : out Entity_Id;
3345 Parnt : constant Node_Id := Parent (N);
3349 if (Nkind (Parnt) = N_Indexed_Component
3351 Nkind (Parnt) = N_Selected_Component)
3352 and then N = Prefix (Parnt)
3354 Find_Actual (Parnt, Formal, Call);
3357 elsif Nkind (Parnt) = N_Parameter_Association
3358 and then N = Explicit_Actual_Parameter (Parnt)
3360 Call := Parent (Parnt);
3362 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3371 -- If we have a call to a subprogram look for the parameter. Note that
3372 -- we exclude overloaded calls, since we don't know enough to be sure
3373 -- of giving the right answer in this case.
3375 if Is_Entity_Name (Name (Call))
3376 and then Present (Entity (Name (Call)))
3377 and then Is_Overloadable (Entity (Name (Call)))
3378 and then not Is_Overloaded (Name (Call))
3380 -- Fall here if we are definitely a parameter
3382 Actual := First_Actual (Call);
3383 Formal := First_Formal (Entity (Name (Call)));
3384 while Present (Formal) and then Present (Actual) loop
3388 Actual := Next_Actual (Actual);
3389 Formal := Next_Formal (Formal);
3394 -- Fall through here if we did not find matching actual
3400 ---------------------------
3401 -- Find_Body_Discriminal --
3402 ---------------------------
3404 function Find_Body_Discriminal
3405 (Spec_Discriminant : Entity_Id) return Entity_Id
3407 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3409 Tsk : constant Entity_Id :=
3410 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3414 -- Find discriminant of original concurrent type, and use its current
3415 -- discriminal, which is the renaming within the task/protected body.
3417 Disc := First_Discriminant (Tsk);
3418 while Present (Disc) loop
3419 if Chars (Disc) = Chars (Spec_Discriminant) then
3420 return Discriminal (Disc);
3423 Next_Discriminant (Disc);
3426 -- That loop should always succeed in finding a matching entry and
3427 -- returning. Fatal error if not.
3429 raise Program_Error;
3430 end Find_Body_Discriminal;
3432 -------------------------------------
3433 -- Find_Corresponding_Discriminant --
3434 -------------------------------------
3436 function Find_Corresponding_Discriminant
3438 Typ : Entity_Id) return Entity_Id
3440 Par_Disc : Entity_Id;
3441 Old_Disc : Entity_Id;
3442 New_Disc : Entity_Id;
3445 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3447 -- The original type may currently be private, and the discriminant
3448 -- only appear on its full view.
3450 if Is_Private_Type (Scope (Par_Disc))
3451 and then not Has_Discriminants (Scope (Par_Disc))
3452 and then Present (Full_View (Scope (Par_Disc)))
3454 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3456 Old_Disc := First_Discriminant (Scope (Par_Disc));
3459 if Is_Class_Wide_Type (Typ) then
3460 New_Disc := First_Discriminant (Root_Type (Typ));
3462 New_Disc := First_Discriminant (Typ);
3465 while Present (Old_Disc) and then Present (New_Disc) loop
3466 if Old_Disc = Par_Disc then
3469 Next_Discriminant (Old_Disc);
3470 Next_Discriminant (New_Disc);
3474 -- Should always find it
3476 raise Program_Error;
3477 end Find_Corresponding_Discriminant;
3479 --------------------------
3480 -- Find_Overlaid_Entity --
3481 --------------------------
3483 procedure Find_Overlaid_Entity
3485 Ent : out Entity_Id;
3491 -- We are looking for one of the two following forms:
3493 -- for X'Address use Y'Address
3497 -- Const : constant Address := expr;
3499 -- for X'Address use Const;
3501 -- In the second case, the expr is either Y'Address, or recursively a
3502 -- constant that eventually references Y'Address.
3507 if Nkind (N) = N_Attribute_Definition_Clause
3508 and then Chars (N) = Name_Address
3510 Expr := Expression (N);
3512 -- This loop checks the form of the expression for Y'Address,
3513 -- using recursion to deal with intermediate constants.
3516 -- Check for Y'Address
3518 if Nkind (Expr) = N_Attribute_Reference
3519 and then Attribute_Name (Expr) = Name_Address
3521 Expr := Prefix (Expr);
3524 -- Check for Const where Const is a constant entity
3526 elsif Is_Entity_Name (Expr)
3527 and then Ekind (Entity (Expr)) = E_Constant
3529 Expr := Constant_Value (Entity (Expr));
3531 -- Anything else does not need checking
3538 -- This loop checks the form of the prefix for an entity,
3539 -- using recursion to deal with intermediate components.
3542 -- Check for Y where Y is an entity
3544 if Is_Entity_Name (Expr) then
3545 Ent := Entity (Expr);
3548 -- Check for components
3551 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3553 Expr := Prefix (Expr);
3556 -- Anything else does not need checking
3563 end Find_Overlaid_Entity;
3565 -------------------------
3566 -- Find_Parameter_Type --
3567 -------------------------
3569 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3571 if Nkind (Param) /= N_Parameter_Specification then
3574 -- For an access parameter, obtain the type from the formal entity
3575 -- itself, because access to subprogram nodes do not carry a type.
3576 -- Shouldn't we always use the formal entity ???
3578 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3579 return Etype (Defining_Identifier (Param));
3582 return Etype (Parameter_Type (Param));
3584 end Find_Parameter_Type;
3586 -----------------------------
3587 -- Find_Static_Alternative --
3588 -----------------------------
3590 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3591 Expr : constant Node_Id := Expression (N);
3592 Val : constant Uint := Expr_Value (Expr);
3597 Alt := First (Alternatives (N));
3600 if Nkind (Alt) /= N_Pragma then
3601 Choice := First (Discrete_Choices (Alt));
3602 while Present (Choice) loop
3604 -- Others choice, always matches
3606 if Nkind (Choice) = N_Others_Choice then
3609 -- Range, check if value is in the range
3611 elsif Nkind (Choice) = N_Range then
3613 Val >= Expr_Value (Low_Bound (Choice))
3615 Val <= Expr_Value (High_Bound (Choice));
3617 -- Choice is a subtype name. Note that we know it must
3618 -- be a static subtype, since otherwise it would have
3619 -- been diagnosed as illegal.
3621 elsif Is_Entity_Name (Choice)
3622 and then Is_Type (Entity (Choice))
3624 exit Search when Is_In_Range (Expr, Etype (Choice),
3625 Assume_Valid => False);
3627 -- Choice is a subtype indication
3629 elsif Nkind (Choice) = N_Subtype_Indication then
3631 C : constant Node_Id := Constraint (Choice);
3632 R : constant Node_Id := Range_Expression (C);
3636 Val >= Expr_Value (Low_Bound (R))
3638 Val <= Expr_Value (High_Bound (R));
3641 -- Choice is a simple expression
3644 exit Search when Val = Expr_Value (Choice);
3652 pragma Assert (Present (Alt));
3655 -- The above loop *must* terminate by finding a match, since
3656 -- we know the case statement is valid, and the value of the
3657 -- expression is known at compile time. When we fall out of
3658 -- the loop, Alt points to the alternative that we know will
3659 -- be selected at run time.
3662 end Find_Static_Alternative;
3668 function First_Actual (Node : Node_Id) return Node_Id is
3672 if No (Parameter_Associations (Node)) then
3676 N := First (Parameter_Associations (Node));
3678 if Nkind (N) = N_Parameter_Association then
3679 return First_Named_Actual (Node);
3685 -----------------------
3686 -- Gather_Components --
3687 -----------------------
3689 procedure Gather_Components
3691 Comp_List : Node_Id;
3692 Governed_By : List_Id;
3694 Report_Errors : out Boolean)
3698 Discrete_Choice : Node_Id;
3699 Comp_Item : Node_Id;
3701 Discrim : Entity_Id;
3702 Discrim_Name : Node_Id;
3703 Discrim_Value : Node_Id;
3706 Report_Errors := False;
3708 if No (Comp_List) or else Null_Present (Comp_List) then
3711 elsif Present (Component_Items (Comp_List)) then
3712 Comp_Item := First (Component_Items (Comp_List));
3718 while Present (Comp_Item) loop
3720 -- Skip the tag of a tagged record, the interface tags, as well
3721 -- as all items that are not user components (anonymous types,
3722 -- rep clauses, Parent field, controller field).
3724 if Nkind (Comp_Item) = N_Component_Declaration then
3726 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3728 if not Is_Tag (Comp)
3729 and then Chars (Comp) /= Name_uParent
3730 and then Chars (Comp) /= Name_uController
3732 Append_Elmt (Comp, Into);
3740 if No (Variant_Part (Comp_List)) then
3743 Discrim_Name := Name (Variant_Part (Comp_List));
3744 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3747 -- Look for the discriminant that governs this variant part.
3748 -- The discriminant *must* be in the Governed_By List
3750 Assoc := First (Governed_By);
3751 Find_Constraint : loop
3752 Discrim := First (Choices (Assoc));
3753 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3754 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3756 Chars (Corresponding_Discriminant (Entity (Discrim)))
3757 = Chars (Discrim_Name))
3758 or else Chars (Original_Record_Component (Entity (Discrim)))
3759 = Chars (Discrim_Name);
3761 if No (Next (Assoc)) then
3762 if not Is_Constrained (Typ)
3763 and then Is_Derived_Type (Typ)
3764 and then Present (Stored_Constraint (Typ))
3766 -- If the type is a tagged type with inherited discriminants,
3767 -- use the stored constraint on the parent in order to find
3768 -- the values of discriminants that are otherwise hidden by an
3769 -- explicit constraint. Renamed discriminants are handled in
3772 -- If several parent discriminants are renamed by a single
3773 -- discriminant of the derived type, the call to obtain the
3774 -- Corresponding_Discriminant field only retrieves the last
3775 -- of them. We recover the constraint on the others from the
3776 -- Stored_Constraint as well.
3783 D := First_Discriminant (Etype (Typ));
3784 C := First_Elmt (Stored_Constraint (Typ));
3785 while Present (D) and then Present (C) loop
3786 if Chars (Discrim_Name) = Chars (D) then
3787 if Is_Entity_Name (Node (C))
3788 and then Entity (Node (C)) = Entity (Discrim)
3790 -- D is renamed by Discrim, whose value is given in
3797 Make_Component_Association (Sloc (Typ),
3799 (New_Occurrence_Of (D, Sloc (Typ))),
3800 Duplicate_Subexpr_No_Checks (Node (C)));
3802 exit Find_Constraint;
3805 Next_Discriminant (D);
3812 if No (Next (Assoc)) then
3813 Error_Msg_NE (" missing value for discriminant&",
3814 First (Governed_By), Discrim_Name);
3815 Report_Errors := True;
3820 end loop Find_Constraint;
3822 Discrim_Value := Expression (Assoc);
3824 if not Is_OK_Static_Expression (Discrim_Value) then
3826 ("value for discriminant & must be static!",
3827 Discrim_Value, Discrim);
3828 Why_Not_Static (Discrim_Value);
3829 Report_Errors := True;
3833 Search_For_Discriminant_Value : declare
3839 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3842 Find_Discrete_Value : while Present (Variant) loop
3843 Discrete_Choice := First (Discrete_Choices (Variant));
3844 while Present (Discrete_Choice) loop
3846 exit Find_Discrete_Value when
3847 Nkind (Discrete_Choice) = N_Others_Choice;
3849 Get_Index_Bounds (Discrete_Choice, Low, High);
3851 UI_Low := Expr_Value (Low);
3852 UI_High := Expr_Value (High);
3854 exit Find_Discrete_Value when
3855 UI_Low <= UI_Discrim_Value
3857 UI_High >= UI_Discrim_Value;
3859 Next (Discrete_Choice);
3862 Next_Non_Pragma (Variant);
3863 end loop Find_Discrete_Value;
3864 end Search_For_Discriminant_Value;
3866 if No (Variant) then
3868 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3869 Report_Errors := True;
3873 -- If we have found the corresponding choice, recursively add its
3874 -- components to the Into list.
3876 Gather_Components (Empty,
3877 Component_List (Variant), Governed_By, Into, Report_Errors);
3878 end Gather_Components;
3880 ------------------------
3881 -- Get_Actual_Subtype --
3882 ------------------------
3884 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3885 Typ : constant Entity_Id := Etype (N);
3886 Utyp : Entity_Id := Underlying_Type (Typ);
3895 -- If what we have is an identifier that references a subprogram
3896 -- formal, or a variable or constant object, then we get the actual
3897 -- subtype from the referenced entity if one has been built.
3899 if Nkind (N) = N_Identifier
3901 (Is_Formal (Entity (N))
3902 or else Ekind (Entity (N)) = E_Constant
3903 or else Ekind (Entity (N)) = E_Variable)
3904 and then Present (Actual_Subtype (Entity (N)))
3906 return Actual_Subtype (Entity (N));
3908 -- Actual subtype of unchecked union is always itself. We never need
3909 -- the "real" actual subtype. If we did, we couldn't get it anyway
3910 -- because the discriminant is not available. The restrictions on
3911 -- Unchecked_Union are designed to make sure that this is OK.
3913 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3916 -- Here for the unconstrained case, we must find actual subtype
3917 -- No actual subtype is available, so we must build it on the fly.
3919 -- Checking the type, not the underlying type, for constrainedness
3920 -- seems to be necessary. Maybe all the tests should be on the type???
3922 elsif (not Is_Constrained (Typ))
3923 and then (Is_Array_Type (Utyp)
3924 or else (Is_Record_Type (Utyp)
3925 and then Has_Discriminants (Utyp)))
3926 and then not Has_Unknown_Discriminants (Utyp)
3927 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3929 -- Nothing to do if in spec expression (why not???)
3931 if In_Spec_Expression then
3934 elsif Is_Private_Type (Typ)
3935 and then not Has_Discriminants (Typ)
3937 -- If the type has no discriminants, there is no subtype to
3938 -- build, even if the underlying type is discriminated.
3942 -- Else build the actual subtype
3945 Decl := Build_Actual_Subtype (Typ, N);
3946 Atyp := Defining_Identifier (Decl);
3948 -- If Build_Actual_Subtype generated a new declaration then use it
3952 -- The actual subtype is an Itype, so analyze the declaration,
3953 -- but do not attach it to the tree, to get the type defined.
3955 Set_Parent (Decl, N);
3956 Set_Is_Itype (Atyp);
3957 Analyze (Decl, Suppress => All_Checks);
3958 Set_Associated_Node_For_Itype (Atyp, N);
3959 Set_Has_Delayed_Freeze (Atyp, False);
3961 -- We need to freeze the actual subtype immediately. This is
3962 -- needed, because otherwise this Itype will not get frozen
3963 -- at all, and it is always safe to freeze on creation because
3964 -- any associated types must be frozen at this point.
3966 Freeze_Itype (Atyp, N);
3969 -- Otherwise we did not build a declaration, so return original
3976 -- For all remaining cases, the actual subtype is the same as
3977 -- the nominal type.
3982 end Get_Actual_Subtype;
3984 -------------------------------------
3985 -- Get_Actual_Subtype_If_Available --
3986 -------------------------------------
3988 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3989 Typ : constant Entity_Id := Etype (N);
3992 -- If what we have is an identifier that references a subprogram
3993 -- formal, or a variable or constant object, then we get the actual
3994 -- subtype from the referenced entity if one has been built.
3996 if Nkind (N) = N_Identifier
3998 (Is_Formal (Entity (N))
3999 or else Ekind (Entity (N)) = E_Constant
4000 or else Ekind (Entity (N)) = E_Variable)
4001 and then Present (Actual_Subtype (Entity (N)))
4003 return Actual_Subtype (Entity (N));
4005 -- Otherwise the Etype of N is returned unchanged
4010 end Get_Actual_Subtype_If_Available;
4012 -------------------------------
4013 -- Get_Default_External_Name --
4014 -------------------------------
4016 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4018 Get_Decoded_Name_String (Chars (E));
4020 if Opt.External_Name_Imp_Casing = Uppercase then
4021 Set_Casing (All_Upper_Case);
4023 Set_Casing (All_Lower_Case);
4027 Make_String_Literal (Sloc (E),
4028 Strval => String_From_Name_Buffer);
4029 end Get_Default_External_Name;
4031 ---------------------------
4032 -- Get_Enum_Lit_From_Pos --
4033 ---------------------------
4035 function Get_Enum_Lit_From_Pos
4038 Loc : Source_Ptr) return Node_Id
4043 -- In the case where the literal is of type Character, Wide_Character
4044 -- or Wide_Wide_Character or of a type derived from them, there needs
4045 -- to be some special handling since there is no explicit chain of
4046 -- literals to search. Instead, an N_Character_Literal node is created
4047 -- with the appropriate Char_Code and Chars fields.
4049 if Is_Standard_Character_Type (T) then
4050 Set_Character_Literal_Name (UI_To_CC (Pos));
4052 Make_Character_Literal (Loc,
4054 Char_Literal_Value => Pos);
4056 -- For all other cases, we have a complete table of literals, and
4057 -- we simply iterate through the chain of literal until the one
4058 -- with the desired position value is found.
4062 Lit := First_Literal (Base_Type (T));
4063 for J in 1 .. UI_To_Int (Pos) loop
4067 return New_Occurrence_Of (Lit, Loc);
4069 end Get_Enum_Lit_From_Pos;
4071 ------------------------
4072 -- Get_Generic_Entity --
4073 ------------------------
4075 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4076 Ent : constant Entity_Id := Entity (Name (N));
4078 if Present (Renamed_Object (Ent)) then
4079 return Renamed_Object (Ent);
4083 end Get_Generic_Entity;
4085 ----------------------
4086 -- Get_Index_Bounds --
4087 ----------------------
4089 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4090 Kind : constant Node_Kind := Nkind (N);
4094 if Kind = N_Range then
4096 H := High_Bound (N);
4098 elsif Kind = N_Subtype_Indication then
4099 R := Range_Expression (Constraint (N));
4107 L := Low_Bound (Range_Expression (Constraint (N)));
4108 H := High_Bound (Range_Expression (Constraint (N)));
4111 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4112 if Error_Posted (Scalar_Range (Entity (N))) then
4116 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4117 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4120 L := Low_Bound (Scalar_Range (Entity (N)));
4121 H := High_Bound (Scalar_Range (Entity (N)));
4125 -- N is an expression, indicating a range with one value
4130 end Get_Index_Bounds;
4132 ----------------------------------
4133 -- Get_Library_Unit_Name_string --
4134 ----------------------------------
4136 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4137 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4140 Get_Unit_Name_String (Unit_Name_Id);
4142 -- Remove seven last character (" (spec)" or " (body)")
4144 Name_Len := Name_Len - 7;
4145 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4146 end Get_Library_Unit_Name_String;
4148 ------------------------
4149 -- Get_Name_Entity_Id --
4150 ------------------------
4152 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4154 return Entity_Id (Get_Name_Table_Info (Id));
4155 end Get_Name_Entity_Id;
4161 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4163 return Get_Pragma_Id (Pragma_Name (N));
4166 ---------------------------
4167 -- Get_Referenced_Object --
4168 ---------------------------
4170 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4175 while Is_Entity_Name (R)
4176 and then Present (Renamed_Object (Entity (R)))
4178 R := Renamed_Object (Entity (R));
4182 end Get_Referenced_Object;
4184 ------------------------
4185 -- Get_Renamed_Entity --
4186 ------------------------
4188 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4193 while Present (Renamed_Entity (R)) loop
4194 R := Renamed_Entity (R);
4198 end Get_Renamed_Entity;
4200 -------------------------
4201 -- Get_Subprogram_Body --
4202 -------------------------
4204 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4208 Decl := Unit_Declaration_Node (E);
4210 if Nkind (Decl) = N_Subprogram_Body then
4213 -- The below comment is bad, because it is possible for
4214 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4216 else -- Nkind (Decl) = N_Subprogram_Declaration
4218 if Present (Corresponding_Body (Decl)) then
4219 return Unit_Declaration_Node (Corresponding_Body (Decl));
4221 -- Imported subprogram case
4227 end Get_Subprogram_Body;
4229 ---------------------------
4230 -- Get_Subprogram_Entity --
4231 ---------------------------
4233 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4238 if Nkind (Nod) = N_Accept_Statement then
4239 Nam := Entry_Direct_Name (Nod);
4241 -- For an entry call, the prefix of the call is a selected component.
4242 -- Need additional code for internal calls ???
4244 elsif Nkind (Nod) = N_Entry_Call_Statement then
4245 if Nkind (Name (Nod)) = N_Selected_Component then
4246 Nam := Entity (Selector_Name (Name (Nod)));
4255 if Nkind (Nam) = N_Explicit_Dereference then
4256 Proc := Etype (Prefix (Nam));
4257 elsif Is_Entity_Name (Nam) then
4258 Proc := Entity (Nam);
4263 if Is_Object (Proc) then
4264 Proc := Etype (Proc);
4267 if Ekind (Proc) = E_Access_Subprogram_Type then
4268 Proc := Directly_Designated_Type (Proc);
4271 if not Is_Subprogram (Proc)
4272 and then Ekind (Proc) /= E_Subprogram_Type
4278 end Get_Subprogram_Entity;
4280 -----------------------------
4281 -- Get_Task_Body_Procedure --
4282 -----------------------------
4284 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4286 -- Note: A task type may be the completion of a private type with
4287 -- discriminants. When performing elaboration checks on a task
4288 -- declaration, the current view of the type may be the private one,
4289 -- and the procedure that holds the body of the task is held in its
4292 -- This is an odd function, why not have Task_Body_Procedure do
4293 -- the following digging???
4295 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4296 end Get_Task_Body_Procedure;
4298 -----------------------
4299 -- Has_Access_Values --
4300 -----------------------
4302 function Has_Access_Values (T : Entity_Id) return Boolean is
4303 Typ : constant Entity_Id := Underlying_Type (T);
4306 -- Case of a private type which is not completed yet. This can only
4307 -- happen in the case of a generic format type appearing directly, or
4308 -- as a component of the type to which this function is being applied
4309 -- at the top level. Return False in this case, since we certainly do
4310 -- not know that the type contains access types.
4315 elsif Is_Access_Type (Typ) then
4318 elsif Is_Array_Type (Typ) then
4319 return Has_Access_Values (Component_Type (Typ));
4321 elsif Is_Record_Type (Typ) then
4326 -- Loop to Check components
4328 Comp := First_Component_Or_Discriminant (Typ);
4329 while Present (Comp) loop
4331 -- Check for access component, tag field does not count, even
4332 -- though it is implemented internally using an access type.
4334 if Has_Access_Values (Etype (Comp))
4335 and then Chars (Comp) /= Name_uTag
4340 Next_Component_Or_Discriminant (Comp);
4349 end Has_Access_Values;
4351 ------------------------------
4352 -- Has_Compatible_Alignment --
4353 ------------------------------
4355 function Has_Compatible_Alignment
4357 Expr : Node_Id) return Alignment_Result
4359 function Has_Compatible_Alignment_Internal
4362 Default : Alignment_Result) return Alignment_Result;
4363 -- This is the internal recursive function that actually does the work.
4364 -- There is one additional parameter, which says what the result should
4365 -- be if no alignment information is found, and there is no definite
4366 -- indication of compatible alignments. At the outer level, this is set
4367 -- to Unknown, but for internal recursive calls in the case where types
4368 -- are known to be correct, it is set to Known_Compatible.
4370 ---------------------------------------
4371 -- Has_Compatible_Alignment_Internal --
4372 ---------------------------------------
4374 function Has_Compatible_Alignment_Internal
4377 Default : Alignment_Result) return Alignment_Result
4379 Result : Alignment_Result := Known_Compatible;
4380 -- Holds the current status of the result. Note that once a value of
4381 -- Known_Incompatible is set, it is sticky and does not get changed
4382 -- to Unknown (the value in Result only gets worse as we go along,
4385 Offs : Uint := No_Uint;
4386 -- Set to a factor of the offset from the base object when Expr is a
4387 -- selected or indexed component, based on Component_Bit_Offset and
4388 -- Component_Size respectively. A negative value is used to represent
4389 -- a value which is not known at compile time.
4391 procedure Check_Prefix;
4392 -- Checks the prefix recursively in the case where the expression
4393 -- is an indexed or selected component.
4395 procedure Set_Result (R : Alignment_Result);
4396 -- If R represents a worse outcome (unknown instead of known
4397 -- compatible, or known incompatible), then set Result to R.
4403 procedure Check_Prefix is
4405 -- The subtlety here is that in doing a recursive call to check
4406 -- the prefix, we have to decide what to do in the case where we
4407 -- don't find any specific indication of an alignment problem.
4409 -- At the outer level, we normally set Unknown as the result in
4410 -- this case, since we can only set Known_Compatible if we really
4411 -- know that the alignment value is OK, but for the recursive
4412 -- call, in the case where the types match, and we have not
4413 -- specified a peculiar alignment for the object, we are only
4414 -- concerned about suspicious rep clauses, the default case does
4415 -- not affect us, since the compiler will, in the absence of such
4416 -- rep clauses, ensure that the alignment is correct.
4418 if Default = Known_Compatible
4420 (Etype (Obj) = Etype (Expr)
4421 and then (Unknown_Alignment (Obj)
4423 Alignment (Obj) = Alignment (Etype (Obj))))
4426 (Has_Compatible_Alignment_Internal
4427 (Obj, Prefix (Expr), Known_Compatible));
4429 -- In all other cases, we need a full check on the prefix
4433 (Has_Compatible_Alignment_Internal
4434 (Obj, Prefix (Expr), Unknown));
4442 procedure Set_Result (R : Alignment_Result) is
4449 -- Start of processing for Has_Compatible_Alignment_Internal
4452 -- If Expr is a selected component, we must make sure there is no
4453 -- potentially troublesome component clause, and that the record is
4456 if Nkind (Expr) = N_Selected_Component then
4458 -- Packed record always generate unknown alignment
4460 if Is_Packed (Etype (Prefix (Expr))) then
4461 Set_Result (Unknown);
4464 -- Check prefix and component offset
4467 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4469 -- If Expr is an indexed component, we must make sure there is no
4470 -- potentially troublesome Component_Size clause and that the array
4471 -- is not bit-packed.
4473 elsif Nkind (Expr) = N_Indexed_Component then
4475 Typ : constant Entity_Id := Etype (Prefix (Expr));
4476 Ind : constant Node_Id := First_Index (Typ);
4479 -- Bit packed array always generates unknown alignment
4481 if Is_Bit_Packed_Array (Typ) then
4482 Set_Result (Unknown);
4485 -- Check prefix and component offset
4488 Offs := Component_Size (Typ);
4490 -- Small optimization: compute the full offset when possible
4493 and then Offs > Uint_0
4494 and then Present (Ind)
4495 and then Nkind (Ind) = N_Range
4496 and then Compile_Time_Known_Value (Low_Bound (Ind))
4497 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4499 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4500 - Expr_Value (Low_Bound ((Ind))));
4505 -- If we have a null offset, the result is entirely determined by
4506 -- the base object and has already been computed recursively.
4508 if Offs = Uint_0 then
4511 -- Case where we know the alignment of the object
4513 elsif Known_Alignment (Obj) then
4515 ObjA : constant Uint := Alignment (Obj);
4516 ExpA : Uint := No_Uint;
4517 SizA : Uint := No_Uint;
4520 -- If alignment of Obj is 1, then we are always OK
4523 Set_Result (Known_Compatible);
4525 -- Alignment of Obj is greater than 1, so we need to check
4528 -- If we have an offset, see if it is compatible
4530 if Offs /= No_Uint and Offs > Uint_0 then
4531 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4532 Set_Result (Known_Incompatible);
4535 -- See if Expr is an object with known alignment
4537 elsif Is_Entity_Name (Expr)
4538 and then Known_Alignment (Entity (Expr))
4540 ExpA := Alignment (Entity (Expr));
4542 -- Otherwise, we can use the alignment of the type of
4543 -- Expr given that we already checked for
4544 -- discombobulating rep clauses for the cases of indexed
4545 -- and selected components above.
4547 elsif Known_Alignment (Etype (Expr)) then
4548 ExpA := Alignment (Etype (Expr));
4550 -- Otherwise the alignment is unknown
4553 Set_Result (Default);
4556 -- If we got an alignment, see if it is acceptable
4558 if ExpA /= No_Uint and then ExpA < ObjA then
4559 Set_Result (Known_Incompatible);
4562 -- If Expr is not a piece of a larger object, see if size
4563 -- is given. If so, check that it is not too small for the
4564 -- required alignment.
4566 if Offs /= No_Uint then
4569 -- See if Expr is an object with known size
4571 elsif Is_Entity_Name (Expr)
4572 and then Known_Static_Esize (Entity (Expr))
4574 SizA := Esize (Entity (Expr));
4576 -- Otherwise, we check the object size of the Expr type
4578 elsif Known_Static_Esize (Etype (Expr)) then
4579 SizA := Esize (Etype (Expr));
4582 -- If we got a size, see if it is a multiple of the Obj
4583 -- alignment, if not, then the alignment cannot be
4584 -- acceptable, since the size is always a multiple of the
4587 if SizA /= No_Uint then
4588 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4589 Set_Result (Known_Incompatible);
4595 -- If we do not know required alignment, any non-zero offset is a
4596 -- potential problem (but certainly may be OK, so result is unknown).
4598 elsif Offs /= No_Uint then
4599 Set_Result (Unknown);
4601 -- If we can't find the result by direct comparison of alignment
4602 -- values, then there is still one case that we can determine known
4603 -- result, and that is when we can determine that the types are the
4604 -- same, and no alignments are specified. Then we known that the
4605 -- alignments are compatible, even if we don't know the alignment
4606 -- value in the front end.
4608 elsif Etype (Obj) = Etype (Expr) then
4610 -- Types are the same, but we have to check for possible size
4611 -- and alignments on the Expr object that may make the alignment
4612 -- different, even though the types are the same.
4614 if Is_Entity_Name (Expr) then
4616 -- First check alignment of the Expr object. Any alignment less
4617 -- than Maximum_Alignment is worrisome since this is the case
4618 -- where we do not know the alignment of Obj.
4620 if Known_Alignment (Entity (Expr))
4622 UI_To_Int (Alignment (Entity (Expr))) <
4623 Ttypes.Maximum_Alignment
4625 Set_Result (Unknown);
4627 -- Now check size of Expr object. Any size that is not an
4628 -- even multiple of Maximum_Alignment is also worrisome
4629 -- since it may cause the alignment of the object to be less
4630 -- than the alignment of the type.
4632 elsif Known_Static_Esize (Entity (Expr))
4634 (UI_To_Int (Esize (Entity (Expr))) mod
4635 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4638 Set_Result (Unknown);
4640 -- Otherwise same type is decisive
4643 Set_Result (Known_Compatible);
4647 -- Another case to deal with is when there is an explicit size or
4648 -- alignment clause when the types are not the same. If so, then the
4649 -- result is Unknown. We don't need to do this test if the Default is
4650 -- Unknown, since that result will be set in any case.
4652 elsif Default /= Unknown
4653 and then (Has_Size_Clause (Etype (Expr))
4655 Has_Alignment_Clause (Etype (Expr)))
4657 Set_Result (Unknown);
4659 -- If no indication found, set default
4662 Set_Result (Default);
4665 -- Return worst result found
4668 end Has_Compatible_Alignment_Internal;
4670 -- Start of processing for Has_Compatible_Alignment
4673 -- If Obj has no specified alignment, then set alignment from the type
4674 -- alignment. Perhaps we should always do this, but for sure we should
4675 -- do it when there is an address clause since we can do more if the
4676 -- alignment is known.
4678 if Unknown_Alignment (Obj) then
4679 Set_Alignment (Obj, Alignment (Etype (Obj)));
4682 -- Now do the internal call that does all the work
4684 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4685 end Has_Compatible_Alignment;
4687 ----------------------
4688 -- Has_Declarations --
4689 ----------------------
4691 function Has_Declarations (N : Node_Id) return Boolean is
4693 return Nkind_In (Nkind (N), N_Accept_Statement,
4695 N_Compilation_Unit_Aux,
4701 N_Package_Specification);
4702 end Has_Declarations;
4704 -------------------------------------------
4705 -- Has_Discriminant_Dependent_Constraint --
4706 -------------------------------------------
4708 function Has_Discriminant_Dependent_Constraint
4709 (Comp : Entity_Id) return Boolean
4711 Comp_Decl : constant Node_Id := Parent (Comp);
4712 Subt_Indic : constant Node_Id :=
4713 Subtype_Indication (Component_Definition (Comp_Decl));
4718 if Nkind (Subt_Indic) = N_Subtype_Indication then
4719 Constr := Constraint (Subt_Indic);
4721 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4722 Assn := First (Constraints (Constr));
4723 while Present (Assn) loop
4724 case Nkind (Assn) is
4725 when N_Subtype_Indication |
4729 if Depends_On_Discriminant (Assn) then
4733 when N_Discriminant_Association =>
4734 if Depends_On_Discriminant (Expression (Assn)) then
4749 end Has_Discriminant_Dependent_Constraint;
4751 --------------------
4752 -- Has_Infinities --
4753 --------------------
4755 function Has_Infinities (E : Entity_Id) return Boolean is
4758 Is_Floating_Point_Type (E)
4759 and then Nkind (Scalar_Range (E)) = N_Range
4760 and then Includes_Infinities (Scalar_Range (E));
4763 --------------------
4764 -- Has_Interfaces --
4765 --------------------
4767 function Has_Interfaces
4769 Use_Full_View : Boolean := True) return Boolean
4771 Typ : Entity_Id := Base_Type (T);
4774 -- Handle concurrent types
4776 if Is_Concurrent_Type (Typ) then
4777 Typ := Corresponding_Record_Type (Typ);
4780 if not Present (Typ)
4781 or else not Is_Record_Type (Typ)
4782 or else not Is_Tagged_Type (Typ)
4787 -- Handle private types
4790 and then Present (Full_View (Typ))
4792 Typ := Full_View (Typ);
4795 -- Handle concurrent record types
4797 if Is_Concurrent_Record_Type (Typ)
4798 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4804 if Is_Interface (Typ)
4806 (Is_Record_Type (Typ)
4807 and then Present (Interfaces (Typ))
4808 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4813 exit when Etype (Typ) = Typ
4815 -- Handle private types
4817 or else (Present (Full_View (Etype (Typ)))
4818 and then Full_View (Etype (Typ)) = Typ)
4820 -- Protect the frontend against wrong source with cyclic
4823 or else Etype (Typ) = T;
4825 -- Climb to the ancestor type handling private types
4827 if Present (Full_View (Etype (Typ))) then
4828 Typ := Full_View (Etype (Typ));
4837 ------------------------
4838 -- Has_Null_Exclusion --
4839 ------------------------
4841 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4844 when N_Access_Definition |
4845 N_Access_Function_Definition |
4846 N_Access_Procedure_Definition |
4847 N_Access_To_Object_Definition |
4849 N_Derived_Type_Definition |
4850 N_Function_Specification |
4851 N_Subtype_Declaration =>
4852 return Null_Exclusion_Present (N);
4854 when N_Component_Definition |
4855 N_Formal_Object_Declaration |
4856 N_Object_Renaming_Declaration =>
4857 if Present (Subtype_Mark (N)) then
4858 return Null_Exclusion_Present (N);
4859 else pragma Assert (Present (Access_Definition (N)));
4860 return Null_Exclusion_Present (Access_Definition (N));
4863 when N_Discriminant_Specification =>
4864 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4865 return Null_Exclusion_Present (Discriminant_Type (N));
4867 return Null_Exclusion_Present (N);
4870 when N_Object_Declaration =>
4871 if Nkind (Object_Definition (N)) = N_Access_Definition then
4872 return Null_Exclusion_Present (Object_Definition (N));
4874 return Null_Exclusion_Present (N);
4877 when N_Parameter_Specification =>
4878 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4879 return Null_Exclusion_Present (Parameter_Type (N));
4881 return Null_Exclusion_Present (N);
4888 end Has_Null_Exclusion;
4890 ------------------------
4891 -- Has_Null_Extension --
4892 ------------------------
4894 function Has_Null_Extension (T : Entity_Id) return Boolean is
4895 B : constant Entity_Id := Base_Type (T);
4900 if Nkind (Parent (B)) = N_Full_Type_Declaration
4901 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4903 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4905 if Present (Ext) then
4906 if Null_Present (Ext) then
4909 Comps := Component_List (Ext);
4911 -- The null component list is rewritten during analysis to
4912 -- include the parent component. Any other component indicates
4913 -- that the extension was not originally null.
4915 return Null_Present (Comps)
4916 or else No (Next (First (Component_Items (Comps))));
4925 end Has_Null_Extension;
4927 -------------------------------
4928 -- Has_Overriding_Initialize --
4929 -------------------------------
4931 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4932 BT : constant Entity_Id := Base_Type (T);
4936 if Is_Controlled (BT) then
4937 if Is_RTU (Scope (BT), Ada_Finalization) then
4940 elsif Present (Primitive_Operations (BT)) then
4941 P := First_Elmt (Primitive_Operations (BT));
4942 while Present (P) loop
4944 Init : constant Entity_Id := Node (P);
4945 Formal : constant Entity_Id := First_Formal (Init);
4947 if Ekind (Init) = E_Procedure
4948 and then Chars (Init) = Name_Initialize
4949 and then Comes_From_Source (Init)
4950 and then Present (Formal)
4951 and then Etype (Formal) = BT
4952 and then No (Next_Formal (Formal))
4953 and then (Ada_Version < Ada_2012
4954 or else not Null_Present (Parent (Init)))
4964 -- Here if type itself does not have a non-null Initialize operation:
4965 -- check immediate ancestor.
4967 if Is_Derived_Type (BT)
4968 and then Has_Overriding_Initialize (Etype (BT))
4975 end Has_Overriding_Initialize;
4977 --------------------------------------
4978 -- Has_Preelaborable_Initialization --
4979 --------------------------------------
4981 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4984 procedure Check_Components (E : Entity_Id);
4985 -- Check component/discriminant chain, sets Has_PE False if a component
4986 -- or discriminant does not meet the preelaborable initialization rules.
4988 ----------------------
4989 -- Check_Components --
4990 ----------------------
4992 procedure Check_Components (E : Entity_Id) is
4996 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4997 -- Returns True if and only if the expression denoted by N does not
4998 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5000 ---------------------------------
5001 -- Is_Preelaborable_Expression --
5002 ---------------------------------
5004 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5008 Comp_Type : Entity_Id;
5009 Is_Array_Aggr : Boolean;
5012 if Is_Static_Expression (N) then
5015 elsif Nkind (N) = N_Null then
5018 -- Attributes are allowed in general, even if their prefix is a
5019 -- formal type. (It seems that certain attributes known not to be
5020 -- static might not be allowed, but there are no rules to prevent
5023 elsif Nkind (N) = N_Attribute_Reference then
5026 -- The name of a discriminant evaluated within its parent type is
5027 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5028 -- names that denote discriminals as well as discriminants to
5029 -- catch references occurring within init procs.
5031 elsif Is_Entity_Name (N)
5033 (Ekind (Entity (N)) = E_Discriminant
5035 ((Ekind (Entity (N)) = E_Constant
5036 or else Ekind (Entity (N)) = E_In_Parameter)
5037 and then Present (Discriminal_Link (Entity (N)))))
5041 elsif Nkind (N) = N_Qualified_Expression then
5042 return Is_Preelaborable_Expression (Expression (N));
5044 -- For aggregates we have to check that each of the associations
5045 -- is preelaborable.
5047 elsif Nkind (N) = N_Aggregate
5048 or else Nkind (N) = N_Extension_Aggregate
5050 Is_Array_Aggr := Is_Array_Type (Etype (N));
5052 if Is_Array_Aggr then
5053 Comp_Type := Component_Type (Etype (N));
5056 -- Check the ancestor part of extension aggregates, which must
5057 -- be either the name of a type that has preelaborable init or
5058 -- an expression that is preelaborable.
5060 if Nkind (N) = N_Extension_Aggregate then
5062 Anc_Part : constant Node_Id := Ancestor_Part (N);
5065 if Is_Entity_Name (Anc_Part)
5066 and then Is_Type (Entity (Anc_Part))
5068 if not Has_Preelaborable_Initialization
5074 elsif not Is_Preelaborable_Expression (Anc_Part) then
5080 -- Check positional associations
5082 Exp := First (Expressions (N));
5083 while Present (Exp) loop
5084 if not Is_Preelaborable_Expression (Exp) then
5091 -- Check named associations
5093 Assn := First (Component_Associations (N));
5094 while Present (Assn) loop
5095 Choice := First (Choices (Assn));
5096 while Present (Choice) loop
5097 if Is_Array_Aggr then
5098 if Nkind (Choice) = N_Others_Choice then
5101 elsif Nkind (Choice) = N_Range then
5102 if not Is_Static_Range (Choice) then
5106 elsif not Is_Static_Expression (Choice) then
5111 Comp_Type := Etype (Choice);
5117 -- If the association has a <> at this point, then we have
5118 -- to check whether the component's type has preelaborable
5119 -- initialization. Note that this only occurs when the
5120 -- association's corresponding component does not have a
5121 -- default expression, the latter case having already been
5122 -- expanded as an expression for the association.
5124 if Box_Present (Assn) then
5125 if not Has_Preelaborable_Initialization (Comp_Type) then
5129 -- In the expression case we check whether the expression
5130 -- is preelaborable.
5133 not Is_Preelaborable_Expression (Expression (Assn))
5141 -- If we get here then aggregate as a whole is preelaborable
5145 -- All other cases are not preelaborable
5150 end Is_Preelaborable_Expression;
5152 -- Start of processing for Check_Components
5155 -- Loop through entities of record or protected type
5158 while Present (Ent) loop
5160 -- We are interested only in components and discriminants
5167 -- Get default expression if any. If there is no declaration
5168 -- node, it means we have an internal entity. The parent and
5169 -- tag fields are examples of such entities. For such cases,
5170 -- we just test the type of the entity.
5172 if Present (Declaration_Node (Ent)) then
5173 Exp := Expression (Declaration_Node (Ent));
5176 when E_Discriminant =>
5178 -- Note: for a renamed discriminant, the Declaration_Node
5179 -- may point to the one from the ancestor, and have a
5180 -- different expression, so use the proper attribute to
5181 -- retrieve the expression from the derived constraint.
5183 Exp := Discriminant_Default_Value (Ent);
5186 goto Check_Next_Entity;
5189 -- A component has PI if it has no default expression and the
5190 -- component type has PI.
5193 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5198 -- Require the default expression to be preelaborable
5200 elsif not Is_Preelaborable_Expression (Exp) then
5205 <<Check_Next_Entity>>
5208 end Check_Components;
5210 -- Start of processing for Has_Preelaborable_Initialization
5213 -- Immediate return if already marked as known preelaborable init. This
5214 -- covers types for which this function has already been called once
5215 -- and returned True (in which case the result is cached), and also
5216 -- types to which a pragma Preelaborable_Initialization applies.
5218 if Known_To_Have_Preelab_Init (E) then
5222 -- If the type is a subtype representing a generic actual type, then
5223 -- test whether its base type has preelaborable initialization since
5224 -- the subtype representing the actual does not inherit this attribute
5225 -- from the actual or formal. (but maybe it should???)
5227 if Is_Generic_Actual_Type (E) then
5228 return Has_Preelaborable_Initialization (Base_Type (E));
5231 -- All elementary types have preelaborable initialization
5233 if Is_Elementary_Type (E) then
5236 -- Array types have PI if the component type has PI
5238 elsif Is_Array_Type (E) then
5239 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5241 -- A derived type has preelaborable initialization if its parent type
5242 -- has preelaborable initialization and (in the case of a derived record
5243 -- extension) if the non-inherited components all have preelaborable
5244 -- initialization. However, a user-defined controlled type with an
5245 -- overriding Initialize procedure does not have preelaborable
5248 elsif Is_Derived_Type (E) then
5250 -- If the derived type is a private extension then it doesn't have
5251 -- preelaborable initialization.
5253 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5257 -- First check whether ancestor type has preelaborable initialization
5259 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5261 -- If OK, check extension components (if any)
5263 if Has_PE and then Is_Record_Type (E) then
5264 Check_Components (First_Entity (E));
5267 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5268 -- with a user defined Initialize procedure does not have PI.
5271 and then Is_Controlled (E)
5272 and then Has_Overriding_Initialize (E)
5277 -- Private types not derived from a type having preelaborable init and
5278 -- that are not marked with pragma Preelaborable_Initialization do not
5279 -- have preelaborable initialization.
5281 elsif Is_Private_Type (E) then
5284 -- Record type has PI if it is non private and all components have PI
5286 elsif Is_Record_Type (E) then
5288 Check_Components (First_Entity (E));
5290 -- Protected types must not have entries, and components must meet
5291 -- same set of rules as for record components.
5293 elsif Is_Protected_Type (E) then
5294 if Has_Entries (E) then
5298 Check_Components (First_Entity (E));
5299 Check_Components (First_Private_Entity (E));
5302 -- Type System.Address always has preelaborable initialization
5304 elsif Is_RTE (E, RE_Address) then
5307 -- In all other cases, type does not have preelaborable initialization
5313 -- If type has preelaborable initialization, cache result
5316 Set_Known_To_Have_Preelab_Init (E);
5320 end Has_Preelaborable_Initialization;
5322 ---------------------------
5323 -- Has_Private_Component --
5324 ---------------------------
5326 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5327 Btype : Entity_Id := Base_Type (Type_Id);
5328 Component : Entity_Id;
5331 if Error_Posted (Type_Id)
5332 or else Error_Posted (Btype)
5337 if Is_Class_Wide_Type (Btype) then
5338 Btype := Root_Type (Btype);
5341 if Is_Private_Type (Btype) then
5343 UT : constant Entity_Id := Underlying_Type (Btype);
5346 if No (Full_View (Btype)) then
5347 return not Is_Generic_Type (Btype)
5348 and then not Is_Generic_Type (Root_Type (Btype));
5350 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5353 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5357 elsif Is_Array_Type (Btype) then
5358 return Has_Private_Component (Component_Type (Btype));
5360 elsif Is_Record_Type (Btype) then
5361 Component := First_Component (Btype);
5362 while Present (Component) loop
5363 if Has_Private_Component (Etype (Component)) then
5367 Next_Component (Component);
5372 elsif Is_Protected_Type (Btype)
5373 and then Present (Corresponding_Record_Type (Btype))
5375 return Has_Private_Component (Corresponding_Record_Type (Btype));
5380 end Has_Private_Component;
5386 function Has_Stream (T : Entity_Id) return Boolean is
5393 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5396 elsif Is_Array_Type (T) then
5397 return Has_Stream (Component_Type (T));
5399 elsif Is_Record_Type (T) then
5400 E := First_Component (T);
5401 while Present (E) loop
5402 if Has_Stream (Etype (E)) then
5411 elsif Is_Private_Type (T) then
5412 return Has_Stream (Underlying_Type (T));
5423 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5425 Get_Name_String (Chars (E));
5426 return Name_Buffer (Name_Len) = Suffix;
5429 --------------------------
5430 -- Has_Tagged_Component --
5431 --------------------------
5433 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5437 if Is_Private_Type (Typ)
5438 and then Present (Underlying_Type (Typ))
5440 return Has_Tagged_Component (Underlying_Type (Typ));
5442 elsif Is_Array_Type (Typ) then
5443 return Has_Tagged_Component (Component_Type (Typ));
5445 elsif Is_Tagged_Type (Typ) then
5448 elsif Is_Record_Type (Typ) then
5449 Comp := First_Component (Typ);
5450 while Present (Comp) loop
5451 if Has_Tagged_Component (Etype (Comp)) then
5455 Next_Component (Comp);
5463 end Has_Tagged_Component;
5465 -------------------------
5466 -- Implementation_Kind --
5467 -------------------------
5469 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5470 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5472 pragma Assert (Present (Impl_Prag));
5474 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5475 end Implementation_Kind;
5477 --------------------------
5478 -- Implements_Interface --
5479 --------------------------
5481 function Implements_Interface
5482 (Typ_Ent : Entity_Id;
5483 Iface_Ent : Entity_Id;
5484 Exclude_Parents : Boolean := False) return Boolean
5486 Ifaces_List : Elist_Id;
5488 Iface : Entity_Id := Base_Type (Iface_Ent);
5489 Typ : Entity_Id := Base_Type (Typ_Ent);
5492 if Is_Class_Wide_Type (Typ) then
5493 Typ := Root_Type (Typ);
5496 if not Has_Interfaces (Typ) then
5500 if Is_Class_Wide_Type (Iface) then
5501 Iface := Root_Type (Iface);
5504 Collect_Interfaces (Typ, Ifaces_List);
5506 Elmt := First_Elmt (Ifaces_List);
5507 while Present (Elmt) loop
5508 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5509 and then Exclude_Parents
5513 elsif Node (Elmt) = Iface then
5521 end Implements_Interface;
5527 function In_Instance return Boolean is
5528 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5534 and then S /= Standard_Standard
5536 if (Ekind (S) = E_Function
5537 or else Ekind (S) = E_Package
5538 or else Ekind (S) = E_Procedure)
5539 and then Is_Generic_Instance (S)
5541 -- A child instance is always compiled in the context of a parent
5542 -- instance. Nevertheless, the actuals are not analyzed in an
5543 -- instance context. We detect this case by examining the current
5544 -- compilation unit, which must be a child instance, and checking
5545 -- that it is not currently on the scope stack.
5547 if Is_Child_Unit (Curr_Unit)
5549 Nkind (Unit (Cunit (Current_Sem_Unit)))
5550 = N_Package_Instantiation
5551 and then not In_Open_Scopes (Curr_Unit)
5565 ----------------------
5566 -- In_Instance_Body --
5567 ----------------------
5569 function In_Instance_Body return Boolean is
5575 and then S /= Standard_Standard
5577 if (Ekind (S) = E_Function
5578 or else Ekind (S) = E_Procedure)
5579 and then Is_Generic_Instance (S)
5583 elsif Ekind (S) = E_Package
5584 and then In_Package_Body (S)
5585 and then Is_Generic_Instance (S)
5594 end In_Instance_Body;
5596 -----------------------------
5597 -- In_Instance_Not_Visible --
5598 -----------------------------
5600 function In_Instance_Not_Visible return Boolean is
5606 and then S /= Standard_Standard
5608 if (Ekind (S) = E_Function
5609 or else Ekind (S) = E_Procedure)
5610 and then Is_Generic_Instance (S)
5614 elsif Ekind (S) = E_Package
5615 and then (In_Package_Body (S) or else In_Private_Part (S))
5616 and then Is_Generic_Instance (S)
5625 end In_Instance_Not_Visible;
5627 ------------------------------
5628 -- In_Instance_Visible_Part --
5629 ------------------------------
5631 function In_Instance_Visible_Part return Boolean is
5637 and then S /= Standard_Standard
5639 if Ekind (S) = E_Package
5640 and then Is_Generic_Instance (S)
5641 and then not In_Package_Body (S)
5642 and then not In_Private_Part (S)
5651 end In_Instance_Visible_Part;
5653 ---------------------
5654 -- In_Package_Body --
5655 ---------------------
5657 function In_Package_Body return Boolean is
5663 and then S /= Standard_Standard
5665 if Ekind (S) = E_Package
5666 and then In_Package_Body (S)
5675 end In_Package_Body;
5677 --------------------------------
5678 -- In_Parameter_Specification --
5679 --------------------------------
5681 function In_Parameter_Specification (N : Node_Id) return Boolean is
5686 while Present (PN) loop
5687 if Nkind (PN) = N_Parameter_Specification then
5695 end In_Parameter_Specification;
5697 --------------------------------------
5698 -- In_Subprogram_Or_Concurrent_Unit --
5699 --------------------------------------
5701 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5706 -- Use scope chain to check successively outer scopes
5712 if K in Subprogram_Kind
5713 or else K in Concurrent_Kind
5714 or else K in Generic_Subprogram_Kind
5718 elsif E = Standard_Standard then
5724 end In_Subprogram_Or_Concurrent_Unit;
5726 ---------------------
5727 -- In_Visible_Part --
5728 ---------------------
5730 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5733 Is_Package_Or_Generic_Package (Scope_Id)
5734 and then In_Open_Scopes (Scope_Id)
5735 and then not In_Package_Body (Scope_Id)
5736 and then not In_Private_Part (Scope_Id);
5737 end In_Visible_Part;
5739 ---------------------------------
5740 -- Insert_Explicit_Dereference --
5741 ---------------------------------
5743 procedure Insert_Explicit_Dereference (N : Node_Id) is
5744 New_Prefix : constant Node_Id := Relocate_Node (N);
5745 Ent : Entity_Id := Empty;
5752 Save_Interps (N, New_Prefix);
5755 Make_Explicit_Dereference (Sloc (Parent (N)),
5756 Prefix => New_Prefix));
5758 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5760 if Is_Overloaded (New_Prefix) then
5762 -- The dereference is also overloaded, and its interpretations are
5763 -- the designated types of the interpretations of the original node.
5765 Set_Etype (N, Any_Type);
5767 Get_First_Interp (New_Prefix, I, It);
5768 while Present (It.Nam) loop
5771 if Is_Access_Type (T) then
5772 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5775 Get_Next_Interp (I, It);
5781 -- Prefix is unambiguous: mark the original prefix (which might
5782 -- Come_From_Source) as a reference, since the new (relocated) one
5783 -- won't be taken into account.
5785 if Is_Entity_Name (New_Prefix) then
5786 Ent := Entity (New_Prefix);
5789 -- For a retrieval of a subcomponent of some composite object,
5790 -- retrieve the ultimate entity if there is one.
5792 elsif Nkind (New_Prefix) = N_Selected_Component
5793 or else Nkind (New_Prefix) = N_Indexed_Component
5795 Pref := Prefix (New_Prefix);
5796 while Present (Pref)
5798 (Nkind (Pref) = N_Selected_Component
5799 or else Nkind (Pref) = N_Indexed_Component)
5801 Pref := Prefix (Pref);
5804 if Present (Pref) and then Is_Entity_Name (Pref) then
5805 Ent := Entity (Pref);
5809 -- Place the reference on the entity node
5811 if Present (Ent) then
5812 Generate_Reference (Ent, Pref);
5815 end Insert_Explicit_Dereference;
5817 ------------------------------------------
5818 -- Inspect_Deferred_Constant_Completion --
5819 ------------------------------------------
5821 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5825 Decl := First (Decls);
5826 while Present (Decl) loop
5828 -- Deferred constant signature
5830 if Nkind (Decl) = N_Object_Declaration
5831 and then Constant_Present (Decl)
5832 and then No (Expression (Decl))
5834 -- No need to check internally generated constants
5836 and then Comes_From_Source (Decl)
5838 -- The constant is not completed. A full object declaration or a
5839 -- pragma Import complete a deferred constant.
5841 and then not Has_Completion (Defining_Identifier (Decl))
5844 ("constant declaration requires initialization expression",
5845 Defining_Identifier (Decl));
5848 Decl := Next (Decl);
5850 end Inspect_Deferred_Constant_Completion;
5852 -----------------------------
5853 -- Is_Actual_Out_Parameter --
5854 -----------------------------
5856 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5860 Find_Actual (N, Formal, Call);
5861 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5862 end Is_Actual_Out_Parameter;
5864 -------------------------
5865 -- Is_Actual_Parameter --
5866 -------------------------
5868 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5869 PK : constant Node_Kind := Nkind (Parent (N));
5873 when N_Parameter_Association =>
5874 return N = Explicit_Actual_Parameter (Parent (N));
5876 when N_Function_Call | N_Procedure_Call_Statement =>
5877 return Is_List_Member (N)
5879 List_Containing (N) = Parameter_Associations (Parent (N));
5884 end Is_Actual_Parameter;
5886 ---------------------
5887 -- Is_Aliased_View --
5888 ---------------------
5890 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5894 if Is_Entity_Name (Obj) then
5902 or else (Present (Renamed_Object (E))
5903 and then Is_Aliased_View (Renamed_Object (E)))))
5905 or else ((Is_Formal (E)
5906 or else Ekind (E) = E_Generic_In_Out_Parameter
5907 or else Ekind (E) = E_Generic_In_Parameter)
5908 and then Is_Tagged_Type (Etype (E)))
5910 or else (Is_Concurrent_Type (E)
5911 and then In_Open_Scopes (E))
5913 -- Current instance of type, either directly or as rewritten
5914 -- reference to the current object.
5916 or else (Is_Entity_Name (Original_Node (Obj))
5917 and then Present (Entity (Original_Node (Obj)))
5918 and then Is_Type (Entity (Original_Node (Obj))))
5920 or else (Is_Type (E) and then E = Current_Scope)
5922 or else (Is_Incomplete_Or_Private_Type (E)
5923 and then Full_View (E) = Current_Scope);
5925 elsif Nkind (Obj) = N_Selected_Component then
5926 return Is_Aliased (Entity (Selector_Name (Obj)));
5928 elsif Nkind (Obj) = N_Indexed_Component then
5929 return Has_Aliased_Components (Etype (Prefix (Obj)))
5931 (Is_Access_Type (Etype (Prefix (Obj)))
5933 Has_Aliased_Components
5934 (Designated_Type (Etype (Prefix (Obj)))));
5936 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5937 or else Nkind (Obj) = N_Type_Conversion
5939 return Is_Tagged_Type (Etype (Obj))
5940 and then Is_Aliased_View (Expression (Obj));
5942 elsif Nkind (Obj) = N_Explicit_Dereference then
5943 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5948 end Is_Aliased_View;
5950 -------------------------
5951 -- Is_Ancestor_Package --
5952 -------------------------
5954 function Is_Ancestor_Package
5956 E2 : Entity_Id) return Boolean
5963 and then Par /= Standard_Standard
5973 end Is_Ancestor_Package;
5975 ----------------------
5976 -- Is_Atomic_Object --
5977 ----------------------
5979 function Is_Atomic_Object (N : Node_Id) return Boolean is
5981 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5982 -- Determines if given object has atomic components
5984 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5985 -- If prefix is an implicit dereference, examine designated type
5987 ----------------------
5988 -- Is_Atomic_Prefix --
5989 ----------------------
5991 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5993 if Is_Access_Type (Etype (N)) then
5995 Has_Atomic_Components (Designated_Type (Etype (N)));
5997 return Object_Has_Atomic_Components (N);
5999 end Is_Atomic_Prefix;
6001 ----------------------------------
6002 -- Object_Has_Atomic_Components --
6003 ----------------------------------
6005 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6007 if Has_Atomic_Components (Etype (N))
6008 or else Is_Atomic (Etype (N))
6012 elsif Is_Entity_Name (N)
6013 and then (Has_Atomic_Components (Entity (N))
6014 or else Is_Atomic (Entity (N)))
6018 elsif Nkind (N) = N_Indexed_Component
6019 or else Nkind (N) = N_Selected_Component
6021 return Is_Atomic_Prefix (Prefix (N));
6026 end Object_Has_Atomic_Components;
6028 -- Start of processing for Is_Atomic_Object
6031 -- Predicate is not relevant to subprograms
6033 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6036 elsif Is_Atomic (Etype (N))
6037 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6041 elsif Nkind (N) = N_Indexed_Component
6042 or else Nkind (N) = N_Selected_Component
6044 return Is_Atomic_Prefix (Prefix (N));
6049 end Is_Atomic_Object;
6051 -------------------------
6052 -- Is_Coextension_Root --
6053 -------------------------
6055 function Is_Coextension_Root (N : Node_Id) return Boolean is
6058 Nkind (N) = N_Allocator
6059 and then Present (Coextensions (N))
6061 -- Anonymous access discriminants carry a list of all nested
6062 -- controlled coextensions.
6064 and then not Is_Dynamic_Coextension (N)
6065 and then not Is_Static_Coextension (N);
6066 end Is_Coextension_Root;
6068 -----------------------------
6069 -- Is_Concurrent_Interface --
6070 -----------------------------
6072 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6077 (Is_Protected_Interface (T)
6078 or else Is_Synchronized_Interface (T)
6079 or else Is_Task_Interface (T));
6080 end Is_Concurrent_Interface;
6082 --------------------------------------
6083 -- Is_Controlling_Limited_Procedure --
6084 --------------------------------------
6086 function Is_Controlling_Limited_Procedure
6087 (Proc_Nam : Entity_Id) return Boolean
6089 Param_Typ : Entity_Id := Empty;
6092 if Ekind (Proc_Nam) = E_Procedure
6093 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6095 Param_Typ := Etype (Parameter_Type (First (
6096 Parameter_Specifications (Parent (Proc_Nam)))));
6098 -- In this case where an Itype was created, the procedure call has been
6101 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6102 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6104 Present (Parameter_Associations
6105 (Associated_Node_For_Itype (Proc_Nam)))
6108 Etype (First (Parameter_Associations
6109 (Associated_Node_For_Itype (Proc_Nam))));
6112 if Present (Param_Typ) then
6114 Is_Interface (Param_Typ)
6115 and then Is_Limited_Record (Param_Typ);
6119 end Is_Controlling_Limited_Procedure;
6121 -----------------------------
6122 -- Is_CPP_Constructor_Call --
6123 -----------------------------
6125 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6127 return Nkind (N) = N_Function_Call
6128 and then Is_CPP_Class (Etype (Etype (N)))
6129 and then Is_Constructor (Entity (Name (N)))
6130 and then Is_Imported (Entity (Name (N)));
6131 end Is_CPP_Constructor_Call;
6137 function Is_Delegate (T : Entity_Id) return Boolean is
6138 Desig_Type : Entity_Id;
6141 if VM_Target /= CLI_Target then
6145 -- Access-to-subprograms are delegates in CIL
6147 if Ekind (T) = E_Access_Subprogram_Type then
6151 if Ekind (T) not in Access_Kind then
6153 -- A delegate is a managed pointer. If no designated type is defined
6154 -- it means that it's not a delegate.
6159 Desig_Type := Etype (Directly_Designated_Type (T));
6161 if not Is_Tagged_Type (Desig_Type) then
6165 -- Test if the type is inherited from [mscorlib]System.Delegate
6167 while Etype (Desig_Type) /= Desig_Type loop
6168 if Chars (Scope (Desig_Type)) /= No_Name
6169 and then Is_Imported (Scope (Desig_Type))
6170 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6175 Desig_Type := Etype (Desig_Type);
6181 ----------------------------------------------
6182 -- Is_Dependent_Component_Of_Mutable_Object --
6183 ----------------------------------------------
6185 function Is_Dependent_Component_Of_Mutable_Object
6186 (Object : Node_Id) return Boolean
6189 Prefix_Type : Entity_Id;
6190 P_Aliased : Boolean := False;
6193 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6194 -- Returns True if and only if Comp is declared within a variant part
6196 --------------------------------
6197 -- Is_Declared_Within_Variant --
6198 --------------------------------
6200 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6201 Comp_Decl : constant Node_Id := Parent (Comp);
6202 Comp_List : constant Node_Id := Parent (Comp_Decl);
6204 return Nkind (Parent (Comp_List)) = N_Variant;
6205 end Is_Declared_Within_Variant;
6207 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6210 if Is_Variable (Object) then
6212 if Nkind (Object) = N_Selected_Component then
6213 P := Prefix (Object);
6214 Prefix_Type := Etype (P);
6216 if Is_Entity_Name (P) then
6218 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6219 Prefix_Type := Base_Type (Prefix_Type);
6222 if Is_Aliased (Entity (P)) then
6226 -- A discriminant check on a selected component may be expanded
6227 -- into a dereference when removing side-effects. Recover the
6228 -- original node and its type, which may be unconstrained.
6230 elsif Nkind (P) = N_Explicit_Dereference
6231 and then not (Comes_From_Source (P))
6233 P := Original_Node (P);
6234 Prefix_Type := Etype (P);
6237 -- Check for prefix being an aliased component???
6243 -- A heap object is constrained by its initial value
6245 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6246 -- the dereferenced case, since the access value might denote an
6247 -- unconstrained aliased object, whereas in Ada 95 the designated
6248 -- object is guaranteed to be constrained. A worst-case assumption
6249 -- has to apply in Ada 2005 because we can't tell at compile time
6250 -- whether the object is "constrained by its initial value"
6251 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6252 -- semantic rules -- these rules are acknowledged to need fixing).
6254 if Ada_Version < Ada_2005 then
6255 if Is_Access_Type (Prefix_Type)
6256 or else Nkind (P) = N_Explicit_Dereference
6261 elsif Ada_Version >= Ada_2005 then
6262 if Is_Access_Type (Prefix_Type) then
6264 -- If the access type is pool-specific, and there is no
6265 -- constrained partial view of the designated type, then the
6266 -- designated object is known to be constrained.
6268 if Ekind (Prefix_Type) = E_Access_Type
6269 and then not Has_Constrained_Partial_View
6270 (Designated_Type (Prefix_Type))
6274 -- Otherwise (general access type, or there is a constrained
6275 -- partial view of the designated type), we need to check
6276 -- based on the designated type.
6279 Prefix_Type := Designated_Type (Prefix_Type);
6285 Original_Record_Component (Entity (Selector_Name (Object)));
6287 -- As per AI-0017, the renaming is illegal in a generic body, even
6288 -- if the subtype is indefinite.
6290 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6292 if not Is_Constrained (Prefix_Type)
6293 and then (not Is_Indefinite_Subtype (Prefix_Type)
6295 (Is_Generic_Type (Prefix_Type)
6296 and then Ekind (Current_Scope) = E_Generic_Package
6297 and then In_Package_Body (Current_Scope)))
6299 and then (Is_Declared_Within_Variant (Comp)
6300 or else Has_Discriminant_Dependent_Constraint (Comp))
6301 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6307 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6311 elsif Nkind (Object) = N_Indexed_Component
6312 or else Nkind (Object) = N_Slice
6314 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6316 -- A type conversion that Is_Variable is a view conversion:
6317 -- go back to the denoted object.
6319 elsif Nkind (Object) = N_Type_Conversion then
6321 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6326 end Is_Dependent_Component_Of_Mutable_Object;
6328 ---------------------
6329 -- Is_Dereferenced --
6330 ---------------------
6332 function Is_Dereferenced (N : Node_Id) return Boolean is
6333 P : constant Node_Id := Parent (N);
6336 (Nkind (P) = N_Selected_Component
6338 Nkind (P) = N_Explicit_Dereference
6340 Nkind (P) = N_Indexed_Component
6342 Nkind (P) = N_Slice)
6343 and then Prefix (P) = N;
6344 end Is_Dereferenced;
6346 ----------------------
6347 -- Is_Descendent_Of --
6348 ----------------------
6350 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6355 pragma Assert (Nkind (T1) in N_Entity);
6356 pragma Assert (Nkind (T2) in N_Entity);
6358 T := Base_Type (T1);
6360 -- Immediate return if the types match
6365 -- Comment needed here ???
6367 elsif Ekind (T) = E_Class_Wide_Type then
6368 return Etype (T) = T2;
6376 -- Done if we found the type we are looking for
6381 -- Done if no more derivations to check
6388 -- Following test catches error cases resulting from prev errors
6390 elsif No (Etyp) then
6393 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6396 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6400 T := Base_Type (Etyp);
6403 end Is_Descendent_Of;
6409 function Is_False (U : Uint) return Boolean is
6414 ---------------------------
6415 -- Is_Fixed_Model_Number --
6416 ---------------------------
6418 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6419 S : constant Ureal := Small_Value (T);
6420 M : Urealp.Save_Mark;
6424 R := (U = UR_Trunc (U / S) * S);
6427 end Is_Fixed_Model_Number;
6429 -------------------------------
6430 -- Is_Fully_Initialized_Type --
6431 -------------------------------
6433 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6435 if Is_Scalar_Type (Typ) then
6438 elsif Is_Access_Type (Typ) then
6441 elsif Is_Array_Type (Typ) then
6442 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6446 -- An interesting case, if we have a constrained type one of whose
6447 -- bounds is known to be null, then there are no elements to be
6448 -- initialized, so all the elements are initialized!
6450 if Is_Constrained (Typ) then
6453 Indx_Typ : Entity_Id;
6457 Indx := First_Index (Typ);
6458 while Present (Indx) loop
6459 if Etype (Indx) = Any_Type then
6462 -- If index is a range, use directly
6464 elsif Nkind (Indx) = N_Range then
6465 Lbd := Low_Bound (Indx);
6466 Hbd := High_Bound (Indx);
6469 Indx_Typ := Etype (Indx);
6471 if Is_Private_Type (Indx_Typ) then
6472 Indx_Typ := Full_View (Indx_Typ);
6475 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6478 Lbd := Type_Low_Bound (Indx_Typ);
6479 Hbd := Type_High_Bound (Indx_Typ);
6483 if Compile_Time_Known_Value (Lbd)
6484 and then Compile_Time_Known_Value (Hbd)
6486 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6496 -- If no null indexes, then type is not fully initialized
6502 elsif Is_Record_Type (Typ) then
6503 if Has_Discriminants (Typ)
6505 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6506 and then Is_Fully_Initialized_Variant (Typ)
6511 -- Controlled records are considered to be fully initialized if
6512 -- there is a user defined Initialize routine. This may not be
6513 -- entirely correct, but as the spec notes, we are guessing here
6514 -- what is best from the point of view of issuing warnings.
6516 if Is_Controlled (Typ) then
6518 Utyp : constant Entity_Id := Underlying_Type (Typ);
6521 if Present (Utyp) then
6523 Init : constant Entity_Id :=
6525 (Underlying_Type (Typ), Name_Initialize));
6529 and then Comes_From_Source (Init)
6531 Is_Predefined_File_Name
6532 (File_Name (Get_Source_File_Index (Sloc (Init))))
6536 elsif Has_Null_Extension (Typ)
6538 Is_Fully_Initialized_Type
6539 (Etype (Base_Type (Typ)))
6548 -- Otherwise see if all record components are initialized
6554 Ent := First_Entity (Typ);
6555 while Present (Ent) loop
6556 if Chars (Ent) = Name_uController then
6559 elsif Ekind (Ent) = E_Component
6560 and then (No (Parent (Ent))
6561 or else No (Expression (Parent (Ent))))
6562 and then not Is_Fully_Initialized_Type (Etype (Ent))
6564 -- Special VM case for tag components, which need to be
6565 -- defined in this case, but are never initialized as VMs
6566 -- are using other dispatching mechanisms. Ignore this
6567 -- uninitialized case. Note that this applies both to the
6568 -- uTag entry and the main vtable pointer (CPP_Class case).
6570 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6579 -- No uninitialized components, so type is fully initialized.
6580 -- Note that this catches the case of no components as well.
6584 elsif Is_Concurrent_Type (Typ) then
6587 elsif Is_Private_Type (Typ) then
6589 U : constant Entity_Id := Underlying_Type (Typ);
6595 return Is_Fully_Initialized_Type (U);
6602 end Is_Fully_Initialized_Type;
6604 ----------------------------------
6605 -- Is_Fully_Initialized_Variant --
6606 ----------------------------------
6608 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6609 Loc : constant Source_Ptr := Sloc (Typ);
6610 Constraints : constant List_Id := New_List;
6611 Components : constant Elist_Id := New_Elmt_List;
6612 Comp_Elmt : Elmt_Id;
6614 Comp_List : Node_Id;
6616 Discr_Val : Node_Id;
6618 Report_Errors : Boolean;
6619 pragma Warnings (Off, Report_Errors);
6622 if Serious_Errors_Detected > 0 then
6626 if Is_Record_Type (Typ)
6627 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6628 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6630 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6632 Discr := First_Discriminant (Typ);
6633 while Present (Discr) loop
6634 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6635 Discr_Val := Expression (Parent (Discr));
6637 if Present (Discr_Val)
6638 and then Is_OK_Static_Expression (Discr_Val)
6640 Append_To (Constraints,
6641 Make_Component_Association (Loc,
6642 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6643 Expression => New_Copy (Discr_Val)));
6651 Next_Discriminant (Discr);
6656 Comp_List => Comp_List,
6657 Governed_By => Constraints,
6659 Report_Errors => Report_Errors);
6661 -- Check that each component present is fully initialized
6663 Comp_Elmt := First_Elmt (Components);
6664 while Present (Comp_Elmt) loop
6665 Comp_Id := Node (Comp_Elmt);
6667 if Ekind (Comp_Id) = E_Component
6668 and then (No (Parent (Comp_Id))
6669 or else No (Expression (Parent (Comp_Id))))
6670 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6675 Next_Elmt (Comp_Elmt);
6680 elsif Is_Private_Type (Typ) then
6682 U : constant Entity_Id := Underlying_Type (Typ);
6688 return Is_Fully_Initialized_Variant (U);
6694 end Is_Fully_Initialized_Variant;
6700 -- We seem to have a lot of overlapping functions that do similar things
6701 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6702 -- purely syntactic, it should be in Sem_Aux I would think???
6704 function Is_LHS (N : Node_Id) return Boolean is
6705 P : constant Node_Id := Parent (N);
6708 if Nkind (P) = N_Assignment_Statement then
6709 return Name (P) = N;
6712 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6714 return N = Prefix (P) and then Is_LHS (P);
6721 ----------------------------
6722 -- Is_Inherited_Operation --
6723 ----------------------------
6725 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6726 Kind : constant Node_Kind := Nkind (Parent (E));
6728 pragma Assert (Is_Overloadable (E));
6729 return Kind = N_Full_Type_Declaration
6730 or else Kind = N_Private_Extension_Declaration
6731 or else Kind = N_Subtype_Declaration
6732 or else (Ekind (E) = E_Enumeration_Literal
6733 and then Is_Derived_Type (Etype (E)));
6734 end Is_Inherited_Operation;
6736 -----------------------------
6737 -- Is_Library_Level_Entity --
6738 -----------------------------
6740 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6742 -- The following is a small optimization, and it also properly handles
6743 -- discriminals, which in task bodies might appear in expressions before
6744 -- the corresponding procedure has been created, and which therefore do
6745 -- not have an assigned scope.
6747 if Is_Formal (E) then
6751 -- Normal test is simply that the enclosing dynamic scope is Standard
6753 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6754 end Is_Library_Level_Entity;
6756 ---------------------------------
6757 -- Is_Local_Variable_Reference --
6758 ---------------------------------
6760 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6762 if not Is_Entity_Name (Expr) then
6767 Ent : constant Entity_Id := Entity (Expr);
6768 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6770 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6773 return Present (Sub) and then Sub = Current_Subprogram;
6777 end Is_Local_Variable_Reference;
6779 -------------------------
6780 -- Is_Object_Reference --
6781 -------------------------
6783 function Is_Object_Reference (N : Node_Id) return Boolean is
6785 if Is_Entity_Name (N) then
6786 return Present (Entity (N)) and then Is_Object (Entity (N));
6790 when N_Indexed_Component | N_Slice =>
6792 Is_Object_Reference (Prefix (N))
6793 or else Is_Access_Type (Etype (Prefix (N)));
6795 -- In Ada95, a function call is a constant object; a procedure
6798 when N_Function_Call =>
6799 return Etype (N) /= Standard_Void_Type;
6801 -- A reference to the stream attribute Input is a function call
6803 when N_Attribute_Reference =>
6804 return Attribute_Name (N) = Name_Input;
6806 when N_Selected_Component =>
6808 Is_Object_Reference (Selector_Name (N))
6810 (Is_Object_Reference (Prefix (N))
6811 or else Is_Access_Type (Etype (Prefix (N))));
6813 when N_Explicit_Dereference =>
6816 -- A view conversion of a tagged object is an object reference
6818 when N_Type_Conversion =>
6819 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6820 and then Is_Tagged_Type (Etype (Expression (N)))
6821 and then Is_Object_Reference (Expression (N));
6823 -- An unchecked type conversion is considered to be an object if
6824 -- the operand is an object (this construction arises only as a
6825 -- result of expansion activities).
6827 when N_Unchecked_Type_Conversion =>
6834 end Is_Object_Reference;
6836 -----------------------------------
6837 -- Is_OK_Variable_For_Out_Formal --
6838 -----------------------------------
6840 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6842 Note_Possible_Modification (AV, Sure => True);
6844 -- We must reject parenthesized variable names. The check for
6845 -- Comes_From_Source is present because there are currently
6846 -- cases where the compiler violates this rule (e.g. passing
6847 -- a task object to its controlled Initialize routine).
6849 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6852 -- A variable is always allowed
6854 elsif Is_Variable (AV) then
6857 -- Unchecked conversions are allowed only if they come from the
6858 -- generated code, which sometimes uses unchecked conversions for out
6859 -- parameters in cases where code generation is unaffected. We tell
6860 -- source unchecked conversions by seeing if they are rewrites of an
6861 -- original Unchecked_Conversion function call, or of an explicit
6862 -- conversion of a function call.
6864 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6865 if Nkind (Original_Node (AV)) = N_Function_Call then
6868 elsif Comes_From_Source (AV)
6869 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6873 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6874 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6880 -- Normal type conversions are allowed if argument is a variable
6882 elsif Nkind (AV) = N_Type_Conversion then
6883 if Is_Variable (Expression (AV))
6884 and then Paren_Count (Expression (AV)) = 0
6886 Note_Possible_Modification (Expression (AV), Sure => True);
6889 -- We also allow a non-parenthesized expression that raises
6890 -- constraint error if it rewrites what used to be a variable
6892 elsif Raises_Constraint_Error (Expression (AV))
6893 and then Paren_Count (Expression (AV)) = 0
6894 and then Is_Variable (Original_Node (Expression (AV)))
6898 -- Type conversion of something other than a variable
6904 -- If this node is rewritten, then test the original form, if that is
6905 -- OK, then we consider the rewritten node OK (for example, if the
6906 -- original node is a conversion, then Is_Variable will not be true
6907 -- but we still want to allow the conversion if it converts a variable).
6909 elsif Original_Node (AV) /= AV then
6910 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6912 -- All other non-variables are rejected
6917 end Is_OK_Variable_For_Out_Formal;
6919 -----------------------------------
6920 -- Is_Partially_Initialized_Type --
6921 -----------------------------------
6923 function Is_Partially_Initialized_Type
6925 Include_Implicit : Boolean := True) return Boolean
6928 if Is_Scalar_Type (Typ) then
6931 elsif Is_Access_Type (Typ) then
6932 return Include_Implicit;
6934 elsif Is_Array_Type (Typ) then
6936 -- If component type is partially initialized, so is array type
6938 if Is_Partially_Initialized_Type
6939 (Component_Type (Typ), Include_Implicit)
6943 -- Otherwise we are only partially initialized if we are fully
6944 -- initialized (this is the empty array case, no point in us
6945 -- duplicating that code here).
6948 return Is_Fully_Initialized_Type (Typ);
6951 elsif Is_Record_Type (Typ) then
6953 -- A discriminated type is always partially initialized if in
6956 if Has_Discriminants (Typ) and then Include_Implicit then
6959 -- A tagged type is always partially initialized
6961 elsif Is_Tagged_Type (Typ) then
6964 -- Case of non-discriminated record
6970 Component_Present : Boolean := False;
6971 -- Set True if at least one component is present. If no
6972 -- components are present, then record type is fully
6973 -- initialized (another odd case, like the null array).
6976 -- Loop through components
6978 Ent := First_Entity (Typ);
6979 while Present (Ent) loop
6980 if Ekind (Ent) = E_Component then
6981 Component_Present := True;
6983 -- If a component has an initialization expression then
6984 -- the enclosing record type is partially initialized
6986 if Present (Parent (Ent))
6987 and then Present (Expression (Parent (Ent)))
6991 -- If a component is of a type which is itself partially
6992 -- initialized, then the enclosing record type is also.
6994 elsif Is_Partially_Initialized_Type
6995 (Etype (Ent), Include_Implicit)
7004 -- No initialized components found. If we found any components
7005 -- they were all uninitialized so the result is false.
7007 if Component_Present then
7010 -- But if we found no components, then all the components are
7011 -- initialized so we consider the type to be initialized.
7019 -- Concurrent types are always fully initialized
7021 elsif Is_Concurrent_Type (Typ) then
7024 -- For a private type, go to underlying type. If there is no underlying
7025 -- type then just assume this partially initialized. Not clear if this
7026 -- can happen in a non-error case, but no harm in testing for this.
7028 elsif Is_Private_Type (Typ) then
7030 U : constant Entity_Id := Underlying_Type (Typ);
7035 return Is_Partially_Initialized_Type (U, Include_Implicit);
7039 -- For any other type (are there any?) assume partially initialized
7044 end Is_Partially_Initialized_Type;
7046 ------------------------------------
7047 -- Is_Potentially_Persistent_Type --
7048 ------------------------------------
7050 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7055 -- For private type, test corresponding full type
7057 if Is_Private_Type (T) then
7058 return Is_Potentially_Persistent_Type (Full_View (T));
7060 -- Scalar types are potentially persistent
7062 elsif Is_Scalar_Type (T) then
7065 -- Record type is potentially persistent if not tagged and the types of
7066 -- all it components are potentially persistent, and no component has
7067 -- an initialization expression.
7069 elsif Is_Record_Type (T)
7070 and then not Is_Tagged_Type (T)
7071 and then not Is_Partially_Initialized_Type (T)
7073 Comp := First_Component (T);
7074 while Present (Comp) loop
7075 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7084 -- Array type is potentially persistent if its component type is
7085 -- potentially persistent and if all its constraints are static.
7087 elsif Is_Array_Type (T) then
7088 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7092 Indx := First_Index (T);
7093 while Present (Indx) loop
7094 if not Is_OK_Static_Subtype (Etype (Indx)) then
7103 -- All other types are not potentially persistent
7108 end Is_Potentially_Persistent_Type;
7110 ---------------------------------
7111 -- Is_Protected_Self_Reference --
7112 ---------------------------------
7114 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7116 function In_Access_Definition (N : Node_Id) return Boolean;
7117 -- Returns true if N belongs to an access definition
7119 --------------------------
7120 -- In_Access_Definition --
7121 --------------------------
7123 function In_Access_Definition (N : Node_Id) return Boolean is
7128 while Present (P) loop
7129 if Nkind (P) = N_Access_Definition then
7137 end In_Access_Definition;
7139 -- Start of processing for Is_Protected_Self_Reference
7142 -- Verify that prefix is analyzed and has the proper form. Note that
7143 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7144 -- produce the address of an entity, do not analyze their prefix
7145 -- because they denote entities that are not necessarily visible.
7146 -- Neither of them can apply to a protected type.
7148 return Ada_Version >= Ada_2005
7149 and then Is_Entity_Name (N)
7150 and then Present (Entity (N))
7151 and then Is_Protected_Type (Entity (N))
7152 and then In_Open_Scopes (Entity (N))
7153 and then not In_Access_Definition (N);
7154 end Is_Protected_Self_Reference;
7156 -----------------------------
7157 -- Is_RCI_Pkg_Spec_Or_Body --
7158 -----------------------------
7160 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7162 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7163 -- Return True if the unit of Cunit is an RCI package declaration
7165 ---------------------------
7166 -- Is_RCI_Pkg_Decl_Cunit --
7167 ---------------------------
7169 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7170 The_Unit : constant Node_Id := Unit (Cunit);
7173 if Nkind (The_Unit) /= N_Package_Declaration then
7177 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7178 end Is_RCI_Pkg_Decl_Cunit;
7180 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7183 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7185 (Nkind (Unit (Cunit)) = N_Package_Body
7186 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7187 end Is_RCI_Pkg_Spec_Or_Body;
7189 -----------------------------------------
7190 -- Is_Remote_Access_To_Class_Wide_Type --
7191 -----------------------------------------
7193 function Is_Remote_Access_To_Class_Wide_Type
7194 (E : Entity_Id) return Boolean
7197 -- A remote access to class-wide type is a general access to object type
7198 -- declared in the visible part of a Remote_Types or Remote_Call_
7201 return Ekind (E) = E_General_Access_Type
7202 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7203 end Is_Remote_Access_To_Class_Wide_Type;
7205 -----------------------------------------
7206 -- Is_Remote_Access_To_Subprogram_Type --
7207 -----------------------------------------
7209 function Is_Remote_Access_To_Subprogram_Type
7210 (E : Entity_Id) return Boolean
7213 return (Ekind (E) = E_Access_Subprogram_Type
7214 or else (Ekind (E) = E_Record_Type
7215 and then Present (Corresponding_Remote_Type (E))))
7216 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7217 end Is_Remote_Access_To_Subprogram_Type;
7219 --------------------
7220 -- Is_Remote_Call --
7221 --------------------
7223 function Is_Remote_Call (N : Node_Id) return Boolean is
7225 if Nkind (N) /= N_Procedure_Call_Statement
7226 and then Nkind (N) /= N_Function_Call
7228 -- An entry call cannot be remote
7232 elsif Nkind (Name (N)) in N_Has_Entity
7233 and then Is_Remote_Call_Interface (Entity (Name (N)))
7235 -- A subprogram declared in the spec of a RCI package is remote
7239 elsif Nkind (Name (N)) = N_Explicit_Dereference
7240 and then Is_Remote_Access_To_Subprogram_Type
7241 (Etype (Prefix (Name (N))))
7243 -- The dereference of a RAS is a remote call
7247 elsif Present (Controlling_Argument (N))
7248 and then Is_Remote_Access_To_Class_Wide_Type
7249 (Etype (Controlling_Argument (N)))
7251 -- Any primitive operation call with a controlling argument of
7252 -- a RACW type is a remote call.
7257 -- All other calls are local calls
7262 ----------------------
7263 -- Is_Renamed_Entry --
7264 ----------------------
7266 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7267 Orig_Node : Node_Id := Empty;
7268 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7270 function Is_Entry (Nam : Node_Id) return Boolean;
7271 -- Determine whether Nam is an entry. Traverse selectors if there are
7272 -- nested selected components.
7278 function Is_Entry (Nam : Node_Id) return Boolean is
7280 if Nkind (Nam) = N_Selected_Component then
7281 return Is_Entry (Selector_Name (Nam));
7284 return Ekind (Entity (Nam)) = E_Entry;
7287 -- Start of processing for Is_Renamed_Entry
7290 if Present (Alias (Proc_Nam)) then
7291 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7294 -- Look for a rewritten subprogram renaming declaration
7296 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7297 and then Present (Original_Node (Subp_Decl))
7299 Orig_Node := Original_Node (Subp_Decl);
7302 -- The rewritten subprogram is actually an entry
7304 if Present (Orig_Node)
7305 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7306 and then Is_Entry (Name (Orig_Node))
7312 end Is_Renamed_Entry;
7314 ----------------------
7315 -- Is_Selector_Name --
7316 ----------------------
7318 function Is_Selector_Name (N : Node_Id) return Boolean is
7320 if not Is_List_Member (N) then
7322 P : constant Node_Id := Parent (N);
7323 K : constant Node_Kind := Nkind (P);
7326 (K = N_Expanded_Name or else
7327 K = N_Generic_Association or else
7328 K = N_Parameter_Association or else
7329 K = N_Selected_Component)
7330 and then Selector_Name (P) = N;
7335 L : constant List_Id := List_Containing (N);
7336 P : constant Node_Id := Parent (L);
7338 return (Nkind (P) = N_Discriminant_Association
7339 and then Selector_Names (P) = L)
7341 (Nkind (P) = N_Component_Association
7342 and then Choices (P) = L);
7345 end Is_Selector_Name;
7351 function Is_Statement (N : Node_Id) return Boolean is
7354 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7355 or else Nkind (N) = N_Procedure_Call_Statement;
7358 ---------------------------------
7359 -- Is_Synchronized_Tagged_Type --
7360 ---------------------------------
7362 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7363 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7366 -- A task or protected type derived from an interface is a tagged type.
7367 -- Such a tagged type is called a synchronized tagged type, as are
7368 -- synchronized interfaces and private extensions whose declaration
7369 -- includes the reserved word synchronized.
7371 return (Is_Tagged_Type (E)
7372 and then (Kind = E_Task_Type
7373 or else Kind = E_Protected_Type))
7376 and then Is_Synchronized_Interface (E))
7378 (Ekind (E) = E_Record_Type_With_Private
7379 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7380 and then (Synchronized_Present (Parent (E))
7381 or else Is_Synchronized_Interface (Etype (E))));
7382 end Is_Synchronized_Tagged_Type;
7388 function Is_Transfer (N : Node_Id) return Boolean is
7389 Kind : constant Node_Kind := Nkind (N);
7392 if Kind = N_Simple_Return_Statement
7394 Kind = N_Extended_Return_Statement
7396 Kind = N_Goto_Statement
7398 Kind = N_Raise_Statement
7400 Kind = N_Requeue_Statement
7404 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7405 and then No (Condition (N))
7409 elsif Kind = N_Procedure_Call_Statement
7410 and then Is_Entity_Name (Name (N))
7411 and then Present (Entity (Name (N)))
7412 and then No_Return (Entity (Name (N)))
7416 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7428 function Is_True (U : Uint) return Boolean is
7433 -------------------------------
7434 -- Is_Universal_Numeric_Type --
7435 -------------------------------
7437 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7439 return T = Universal_Integer or else T = Universal_Real;
7440 end Is_Universal_Numeric_Type;
7446 function Is_Value_Type (T : Entity_Id) return Boolean is
7448 return VM_Target = CLI_Target
7449 and then Nkind (T) in N_Has_Chars
7450 and then Chars (T) /= No_Name
7451 and then Get_Name_String (Chars (T)) = "valuetype";
7454 ---------------------
7455 -- Is_VMS_Operator --
7456 ---------------------
7458 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7460 -- The VMS operators are declared in a child of System that is loaded
7461 -- through pragma Extend_System. In some rare cases a program is run
7462 -- with this extension but without indicating that the target is VMS.
7464 return Ekind (Op) = E_Function
7465 and then Is_Intrinsic_Subprogram (Op)
7467 ((Present_System_Aux
7468 and then Scope (Op) = System_Aux_Id)
7471 and then Scope (Scope (Op)) = RTU_Entity (System)));
7472 end Is_VMS_Operator;
7478 function Is_Variable (N : Node_Id) return Boolean is
7480 Orig_Node : constant Node_Id := Original_Node (N);
7481 -- We do the test on the original node, since this is basically a test
7482 -- of syntactic categories, so it must not be disturbed by whatever
7483 -- rewriting might have occurred. For example, an aggregate, which is
7484 -- certainly NOT a variable, could be turned into a variable by
7487 function In_Protected_Function (E : Entity_Id) return Boolean;
7488 -- Within a protected function, the private components of the enclosing
7489 -- protected type are constants. A function nested within a (protected)
7490 -- procedure is not itself protected.
7492 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7493 -- Prefixes can involve implicit dereferences, in which case we must
7494 -- test for the case of a reference of a constant access type, which can
7495 -- can never be a variable.
7497 ---------------------------
7498 -- In_Protected_Function --
7499 ---------------------------
7501 function In_Protected_Function (E : Entity_Id) return Boolean is
7502 Prot : constant Entity_Id := Scope (E);
7506 if not Is_Protected_Type (Prot) then
7510 while Present (S) and then S /= Prot loop
7511 if Ekind (S) = E_Function and then Scope (S) = Prot then
7520 end In_Protected_Function;
7522 ------------------------
7523 -- Is_Variable_Prefix --
7524 ------------------------
7526 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7528 if Is_Access_Type (Etype (P)) then
7529 return not Is_Access_Constant (Root_Type (Etype (P)));
7531 -- For the case of an indexed component whose prefix has a packed
7532 -- array type, the prefix has been rewritten into a type conversion.
7533 -- Determine variable-ness from the converted expression.
7535 elsif Nkind (P) = N_Type_Conversion
7536 and then not Comes_From_Source (P)
7537 and then Is_Array_Type (Etype (P))
7538 and then Is_Packed (Etype (P))
7540 return Is_Variable (Expression (P));
7543 return Is_Variable (P);
7545 end Is_Variable_Prefix;
7547 -- Start of processing for Is_Variable
7550 -- Definitely OK if Assignment_OK is set. Since this is something that
7551 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7553 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7556 -- Normally we go to the original node, but there is one exception where
7557 -- we use the rewritten node, namely when it is an explicit dereference.
7558 -- The generated code may rewrite a prefix which is an access type with
7559 -- an explicit dereference. The dereference is a variable, even though
7560 -- the original node may not be (since it could be a constant of the
7563 -- In Ada 2005 we have a further case to consider: the prefix may be a
7564 -- function call given in prefix notation. The original node appears to
7565 -- be a selected component, but we need to examine the call.
7567 elsif Nkind (N) = N_Explicit_Dereference
7568 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7569 and then Present (Etype (Orig_Node))
7570 and then Is_Access_Type (Etype (Orig_Node))
7572 -- Note that if the prefix is an explicit dereference that does not
7573 -- come from source, we must check for a rewritten function call in
7574 -- prefixed notation before other forms of rewriting, to prevent a
7578 (Nkind (Orig_Node) = N_Function_Call
7579 and then not Is_Access_Constant (Etype (Prefix (N))))
7581 Is_Variable_Prefix (Original_Node (Prefix (N)));
7583 -- A function call is never a variable
7585 elsif Nkind (N) = N_Function_Call then
7588 -- All remaining checks use the original node
7590 elsif Is_Entity_Name (Orig_Node)
7591 and then Present (Entity (Orig_Node))
7594 E : constant Entity_Id := Entity (Orig_Node);
7595 K : constant Entity_Kind := Ekind (E);
7598 return (K = E_Variable
7599 and then Nkind (Parent (E)) /= N_Exception_Handler)
7600 or else (K = E_Component
7601 and then not In_Protected_Function (E))
7602 or else K = E_Out_Parameter
7603 or else K = E_In_Out_Parameter
7604 or else K = E_Generic_In_Out_Parameter
7606 -- Current instance of type:
7608 or else (Is_Type (E) and then In_Open_Scopes (E))
7609 or else (Is_Incomplete_Or_Private_Type (E)
7610 and then In_Open_Scopes (Full_View (E)));
7614 case Nkind (Orig_Node) is
7615 when N_Indexed_Component | N_Slice =>
7616 return Is_Variable_Prefix (Prefix (Orig_Node));
7618 when N_Selected_Component =>
7619 return Is_Variable_Prefix (Prefix (Orig_Node))
7620 and then Is_Variable (Selector_Name (Orig_Node));
7622 -- For an explicit dereference, the type of the prefix cannot
7623 -- be an access to constant or an access to subprogram.
7625 when N_Explicit_Dereference =>
7627 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7629 return Is_Access_Type (Typ)
7630 and then not Is_Access_Constant (Root_Type (Typ))
7631 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7634 -- The type conversion is the case where we do not deal with the
7635 -- context dependent special case of an actual parameter. Thus
7636 -- the type conversion is only considered a variable for the
7637 -- purposes of this routine if the target type is tagged. However,
7638 -- a type conversion is considered to be a variable if it does not
7639 -- come from source (this deals for example with the conversions
7640 -- of expressions to their actual subtypes).
7642 when N_Type_Conversion =>
7643 return Is_Variable (Expression (Orig_Node))
7645 (not Comes_From_Source (Orig_Node)
7647 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7649 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7651 -- GNAT allows an unchecked type conversion as a variable. This
7652 -- only affects the generation of internal expanded code, since
7653 -- calls to instantiations of Unchecked_Conversion are never
7654 -- considered variables (since they are function calls).
7655 -- This is also true for expression actions.
7657 when N_Unchecked_Type_Conversion =>
7658 return Is_Variable (Expression (Orig_Node));
7666 ---------------------------
7667 -- Is_Visibly_Controlled --
7668 ---------------------------
7670 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7671 Root : constant Entity_Id := Root_Type (T);
7673 return Chars (Scope (Root)) = Name_Finalization
7674 and then Chars (Scope (Scope (Root))) = Name_Ada
7675 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7676 end Is_Visibly_Controlled;
7678 ------------------------
7679 -- Is_Volatile_Object --
7680 ------------------------
7682 function Is_Volatile_Object (N : Node_Id) return Boolean is
7684 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7685 -- Determines if given object has volatile components
7687 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7688 -- If prefix is an implicit dereference, examine designated type
7690 ------------------------
7691 -- Is_Volatile_Prefix --
7692 ------------------------
7694 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7695 Typ : constant Entity_Id := Etype (N);
7698 if Is_Access_Type (Typ) then
7700 Dtyp : constant Entity_Id := Designated_Type (Typ);
7703 return Is_Volatile (Dtyp)
7704 or else Has_Volatile_Components (Dtyp);
7708 return Object_Has_Volatile_Components (N);
7710 end Is_Volatile_Prefix;
7712 ------------------------------------
7713 -- Object_Has_Volatile_Components --
7714 ------------------------------------
7716 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7717 Typ : constant Entity_Id := Etype (N);
7720 if Is_Volatile (Typ)
7721 or else Has_Volatile_Components (Typ)
7725 elsif Is_Entity_Name (N)
7726 and then (Has_Volatile_Components (Entity (N))
7727 or else Is_Volatile (Entity (N)))
7731 elsif Nkind (N) = N_Indexed_Component
7732 or else Nkind (N) = N_Selected_Component
7734 return Is_Volatile_Prefix (Prefix (N));
7739 end Object_Has_Volatile_Components;
7741 -- Start of processing for Is_Volatile_Object
7744 if Is_Volatile (Etype (N))
7745 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7749 elsif Nkind (N) = N_Indexed_Component
7750 or else Nkind (N) = N_Selected_Component
7752 return Is_Volatile_Prefix (Prefix (N));
7757 end Is_Volatile_Object;
7759 -------------------------
7760 -- Kill_Current_Values --
7761 -------------------------
7763 procedure Kill_Current_Values
7765 Last_Assignment_Only : Boolean := False)
7768 -- ??? do we have to worry about clearing cached checks?
7770 if Is_Assignable (Ent) then
7771 Set_Last_Assignment (Ent, Empty);
7774 if Is_Object (Ent) then
7775 if not Last_Assignment_Only then
7777 Set_Current_Value (Ent, Empty);
7779 if not Can_Never_Be_Null (Ent) then
7780 Set_Is_Known_Non_Null (Ent, False);
7783 Set_Is_Known_Null (Ent, False);
7785 -- Reset Is_Known_Valid unless type is always valid, or if we have
7786 -- a loop parameter (loop parameters are always valid, since their
7787 -- bounds are defined by the bounds given in the loop header).
7789 if not Is_Known_Valid (Etype (Ent))
7790 and then Ekind (Ent) /= E_Loop_Parameter
7792 Set_Is_Known_Valid (Ent, False);
7796 end Kill_Current_Values;
7798 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7801 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7802 -- Clear current value for entity E and all entities chained to E
7804 ------------------------------------------
7805 -- Kill_Current_Values_For_Entity_Chain --
7806 ------------------------------------------
7808 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7812 while Present (Ent) loop
7813 Kill_Current_Values (Ent, Last_Assignment_Only);
7816 end Kill_Current_Values_For_Entity_Chain;
7818 -- Start of processing for Kill_Current_Values
7821 -- Kill all saved checks, a special case of killing saved values
7823 if not Last_Assignment_Only then
7827 -- Loop through relevant scopes, which includes the current scope and
7828 -- any parent scopes if the current scope is a block or a package.
7833 -- Clear current values of all entities in current scope
7835 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7837 -- If scope is a package, also clear current values of all
7838 -- private entities in the scope.
7840 if Is_Package_Or_Generic_Package (S)
7841 or else Is_Concurrent_Type (S)
7843 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7846 -- If this is a not a subprogram, deal with parents
7848 if not Is_Subprogram (S) then
7850 exit Scope_Loop when S = Standard_Standard;
7854 end loop Scope_Loop;
7855 end Kill_Current_Values;
7857 --------------------------
7858 -- Kill_Size_Check_Code --
7859 --------------------------
7861 procedure Kill_Size_Check_Code (E : Entity_Id) is
7863 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7864 and then Present (Size_Check_Code (E))
7866 Remove (Size_Check_Code (E));
7867 Set_Size_Check_Code (E, Empty);
7869 end Kill_Size_Check_Code;
7871 --------------------------
7872 -- Known_To_Be_Assigned --
7873 --------------------------
7875 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7876 P : constant Node_Id := Parent (N);
7881 -- Test left side of assignment
7883 when N_Assignment_Statement =>
7884 return N = Name (P);
7886 -- Function call arguments are never lvalues
7888 when N_Function_Call =>
7891 -- Positional parameter for procedure or accept call
7893 when N_Procedure_Call_Statement |
7902 Proc := Get_Subprogram_Entity (P);
7908 -- If we are not a list member, something is strange, so
7909 -- be conservative and return False.
7911 if not Is_List_Member (N) then
7915 -- We are going to find the right formal by stepping forward
7916 -- through the formals, as we step backwards in the actuals.
7918 Form := First_Formal (Proc);
7921 -- If no formal, something is weird, so be conservative
7922 -- and return False.
7933 return Ekind (Form) /= E_In_Parameter;
7936 -- Named parameter for procedure or accept call
7938 when N_Parameter_Association =>
7944 Proc := Get_Subprogram_Entity (Parent (P));
7950 -- Loop through formals to find the one that matches
7952 Form := First_Formal (Proc);
7954 -- If no matching formal, that's peculiar, some kind of
7955 -- previous error, so return False to be conservative.
7961 -- Else test for match
7963 if Chars (Form) = Chars (Selector_Name (P)) then
7964 return Ekind (Form) /= E_In_Parameter;
7971 -- Test for appearing in a conversion that itself appears
7972 -- in an lvalue context, since this should be an lvalue.
7974 when N_Type_Conversion =>
7975 return Known_To_Be_Assigned (P);
7977 -- All other references are definitely not known to be modifications
7983 end Known_To_Be_Assigned;
7985 ---------------------------
7986 -- Last_Source_Statement --
7987 ---------------------------
7989 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
7993 N := Last (Statements (HSS));
7994 while Present (N) loop
7995 exit when Comes_From_Source (N);
8000 end Last_Source_Statement;
8002 ----------------------------------
8003 -- Matching_Static_Array_Bounds --
8004 ----------------------------------
8006 function Matching_Static_Array_Bounds
8008 R_Typ : Node_Id) return Boolean
8010 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8011 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8023 if L_Ndims /= R_Ndims then
8027 -- Unconstrained types do not have static bounds
8029 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8033 -- First treat specially the first dimension, as the lower bound and
8034 -- length of string literals are not stored like those of arrays.
8036 if Ekind (L_Typ) = E_String_Literal_Subtype then
8037 L_Low := String_Literal_Low_Bound (L_Typ);
8038 L_Len := String_Literal_Length (L_Typ);
8040 L_Index := First_Index (L_Typ);
8041 Get_Index_Bounds (L_Index, L_Low, L_High);
8043 if Is_OK_Static_Expression (L_Low)
8044 and then Is_OK_Static_Expression (L_High)
8046 if Expr_Value (L_High) < Expr_Value (L_Low) then
8049 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8056 if Ekind (R_Typ) = E_String_Literal_Subtype then
8057 R_Low := String_Literal_Low_Bound (R_Typ);
8058 R_Len := String_Literal_Length (R_Typ);
8060 R_Index := First_Index (R_Typ);
8061 Get_Index_Bounds (R_Index, R_Low, R_High);
8063 if Is_OK_Static_Expression (R_Low)
8064 and then Is_OK_Static_Expression (R_High)
8066 if Expr_Value (R_High) < Expr_Value (R_Low) then
8069 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8076 if Is_OK_Static_Expression (L_Low)
8077 and then Is_OK_Static_Expression (R_Low)
8078 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8079 and then L_Len = R_Len
8086 -- Then treat all other dimensions
8088 for Indx in 2 .. L_Ndims loop
8092 Get_Index_Bounds (L_Index, L_Low, L_High);
8093 Get_Index_Bounds (R_Index, R_Low, R_High);
8095 if Is_OK_Static_Expression (L_Low)
8096 and then Is_OK_Static_Expression (L_High)
8097 and then Is_OK_Static_Expression (R_Low)
8098 and then Is_OK_Static_Expression (R_High)
8099 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8100 and then Expr_Value (L_High) = Expr_Value (R_High)
8108 -- If we fall through the loop, all indexes matched
8111 end Matching_Static_Array_Bounds;
8117 function May_Be_Lvalue (N : Node_Id) return Boolean is
8118 P : constant Node_Id := Parent (N);
8123 -- Test left side of assignment
8125 when N_Assignment_Statement =>
8126 return N = Name (P);
8128 -- Test prefix of component or attribute. Note that the prefix of an
8129 -- explicit or implicit dereference cannot be an l-value.
8131 when N_Attribute_Reference =>
8132 return N = Prefix (P)
8133 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8135 -- For an expanded name, the name is an lvalue if the expanded name
8136 -- is an lvalue, but the prefix is never an lvalue, since it is just
8137 -- the scope where the name is found.
8139 when N_Expanded_Name =>
8140 if N = Prefix (P) then
8141 return May_Be_Lvalue (P);
8146 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8147 -- B is a little interesting, if we have A.B := 3, there is some
8148 -- discussion as to whether B is an lvalue or not, we choose to say
8149 -- it is. Note however that A is not an lvalue if it is of an access
8150 -- type since this is an implicit dereference.
8152 when N_Selected_Component =>
8154 and then Present (Etype (N))
8155 and then Is_Access_Type (Etype (N))
8159 return May_Be_Lvalue (P);
8162 -- For an indexed component or slice, the index or slice bounds is
8163 -- never an lvalue. The prefix is an lvalue if the indexed component
8164 -- or slice is an lvalue, except if it is an access type, where we
8165 -- have an implicit dereference.
8167 when N_Indexed_Component =>
8169 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8173 return May_Be_Lvalue (P);
8176 -- Prefix of a reference is an lvalue if the reference is an lvalue
8179 return May_Be_Lvalue (P);
8181 -- Prefix of explicit dereference is never an lvalue
8183 when N_Explicit_Dereference =>
8186 -- Positional parameter for subprogram, entry, or accept call.
8187 -- In older versions of Ada function call arguments are never
8188 -- lvalues. In Ada 2012 functions can have in-out parameters.
8190 when N_Function_Call |
8191 N_Procedure_Call_Statement |
8192 N_Entry_Call_Statement |
8195 if Nkind (P) = N_Function_Call
8196 and then Ada_Version < Ada_2012
8201 -- The following mechanism is clumsy and fragile. A single
8202 -- flag set in Resolve_Actuals would be preferable ???
8210 Proc := Get_Subprogram_Entity (P);
8216 -- If we are not a list member, something is strange, so
8217 -- be conservative and return True.
8219 if not Is_List_Member (N) then
8223 -- We are going to find the right formal by stepping forward
8224 -- through the formals, as we step backwards in the actuals.
8226 Form := First_Formal (Proc);
8229 -- If no formal, something is weird, so be conservative
8241 return Ekind (Form) /= E_In_Parameter;
8244 -- Named parameter for procedure or accept call
8246 when N_Parameter_Association =>
8252 Proc := Get_Subprogram_Entity (Parent (P));
8258 -- Loop through formals to find the one that matches
8260 Form := First_Formal (Proc);
8262 -- If no matching formal, that's peculiar, some kind of
8263 -- previous error, so return True to be conservative.
8269 -- Else test for match
8271 if Chars (Form) = Chars (Selector_Name (P)) then
8272 return Ekind (Form) /= E_In_Parameter;
8279 -- Test for appearing in a conversion that itself appears in an
8280 -- lvalue context, since this should be an lvalue.
8282 when N_Type_Conversion =>
8283 return May_Be_Lvalue (P);
8285 -- Test for appearance in object renaming declaration
8287 when N_Object_Renaming_Declaration =>
8290 -- All other references are definitely not lvalues
8298 -----------------------
8299 -- Mark_Coextensions --
8300 -----------------------
8302 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8303 Is_Dynamic : Boolean;
8304 -- Indicates whether the context causes nested coextensions to be
8305 -- dynamic or static
8307 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8308 -- Recognize an allocator node and label it as a dynamic coextension
8310 --------------------
8311 -- Mark_Allocator --
8312 --------------------
8314 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8316 if Nkind (N) = N_Allocator then
8318 Set_Is_Dynamic_Coextension (N);
8320 -- If the allocator expression is potentially dynamic, it may
8321 -- be expanded out of order and require dynamic allocation
8322 -- anyway, so we treat the coextension itself as dynamic.
8323 -- Potential optimization ???
8325 elsif Nkind (Expression (N)) = N_Qualified_Expression
8326 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8328 Set_Is_Dynamic_Coextension (N);
8331 Set_Is_Static_Coextension (N);
8338 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8340 -- Start of processing Mark_Coextensions
8343 case Nkind (Context_Nod) is
8344 when N_Assignment_Statement |
8345 N_Simple_Return_Statement =>
8346 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8348 when N_Object_Declaration =>
8349 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8351 -- This routine should not be called for constructs which may not
8352 -- contain coextensions.
8355 raise Program_Error;
8358 Mark_Allocators (Root_Nod);
8359 end Mark_Coextensions;
8361 ----------------------
8362 -- Needs_One_Actual --
8363 ----------------------
8365 function Needs_One_Actual (E : Entity_Id) return Boolean is
8369 if Ada_Version >= Ada_2005
8370 and then Present (First_Formal (E))
8372 Formal := Next_Formal (First_Formal (E));
8373 while Present (Formal) loop
8374 if No (Default_Value (Formal)) then
8378 Next_Formal (Formal);
8386 end Needs_One_Actual;
8388 ------------------------
8389 -- New_Copy_List_Tree --
8390 ------------------------
8392 function New_Copy_List_Tree (List : List_Id) return List_Id is
8397 if List = No_List then
8404 while Present (E) loop
8405 Append (New_Copy_Tree (E), NL);
8411 end New_Copy_List_Tree;
8417 use Atree.Unchecked_Access;
8418 use Atree_Private_Part;
8420 -- Our approach here requires a two pass traversal of the tree. The
8421 -- first pass visits all nodes that eventually will be copied looking
8422 -- for defining Itypes. If any defining Itypes are found, then they are
8423 -- copied, and an entry is added to the replacement map. In the second
8424 -- phase, the tree is copied, using the replacement map to replace any
8425 -- Itype references within the copied tree.
8427 -- The following hash tables are used if the Map supplied has more
8428 -- than hash threshold entries to speed up access to the map. If
8429 -- there are fewer entries, then the map is searched sequentially
8430 -- (because setting up a hash table for only a few entries takes
8431 -- more time than it saves.
8433 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8434 -- Hash function used for hash operations
8440 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8442 return Nat (E) mod (NCT_Header_Num'Last + 1);
8449 -- The hash table NCT_Assoc associates old entities in the table
8450 -- with their corresponding new entities (i.e. the pairs of entries
8451 -- presented in the original Map argument are Key-Element pairs).
8453 package NCT_Assoc is new Simple_HTable (
8454 Header_Num => NCT_Header_Num,
8455 Element => Entity_Id,
8456 No_Element => Empty,
8458 Hash => New_Copy_Hash,
8459 Equal => Types."=");
8461 ---------------------
8462 -- NCT_Itype_Assoc --
8463 ---------------------
8465 -- The hash table NCT_Itype_Assoc contains entries only for those
8466 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8467 -- The key is the associated node, and the element is the new node
8468 -- itself (NOT the associated node for the new node).
8470 package NCT_Itype_Assoc is new Simple_HTable (
8471 Header_Num => NCT_Header_Num,
8472 Element => Entity_Id,
8473 No_Element => Empty,
8475 Hash => New_Copy_Hash,
8476 Equal => Types."=");
8478 -- Start of processing for New_Copy_Tree function
8480 function New_Copy_Tree
8482 Map : Elist_Id := No_Elist;
8483 New_Sloc : Source_Ptr := No_Location;
8484 New_Scope : Entity_Id := Empty) return Node_Id
8486 Actual_Map : Elist_Id := Map;
8487 -- This is the actual map for the copy. It is initialized with the
8488 -- given elements, and then enlarged as required for Itypes that are
8489 -- copied during the first phase of the copy operation. The visit
8490 -- procedures add elements to this map as Itypes are encountered.
8491 -- The reason we cannot use Map directly, is that it may well be
8492 -- (and normally is) initialized to No_Elist, and if we have mapped
8493 -- entities, we have to reset it to point to a real Elist.
8495 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8496 -- Called during second phase to map entities into their corresponding
8497 -- copies using Actual_Map. If the argument is not an entity, or is not
8498 -- in Actual_Map, then it is returned unchanged.
8500 procedure Build_NCT_Hash_Tables;
8501 -- Builds hash tables (number of elements >= threshold value)
8503 function Copy_Elist_With_Replacement
8504 (Old_Elist : Elist_Id) return Elist_Id;
8505 -- Called during second phase to copy element list doing replacements
8507 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8508 -- Called during the second phase to process a copied Itype. The actual
8509 -- copy happened during the first phase (so that we could make the entry
8510 -- in the mapping), but we still have to deal with the descendents of
8511 -- the copied Itype and copy them where necessary.
8513 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8514 -- Called during second phase to copy list doing replacements
8516 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8517 -- Called during second phase to copy node doing replacements
8519 procedure Visit_Elist (E : Elist_Id);
8520 -- Called during first phase to visit all elements of an Elist
8522 procedure Visit_Field (F : Union_Id; N : Node_Id);
8523 -- Visit a single field, recursing to call Visit_Node or Visit_List
8524 -- if the field is a syntactic descendent of the current node (i.e.
8525 -- its parent is Node N).
8527 procedure Visit_Itype (Old_Itype : Entity_Id);
8528 -- Called during first phase to visit subsidiary fields of a defining
8529 -- Itype, and also create a copy and make an entry in the replacement
8530 -- map for the new copy.
8532 procedure Visit_List (L : List_Id);
8533 -- Called during first phase to visit all elements of a List
8535 procedure Visit_Node (N : Node_Or_Entity_Id);
8536 -- Called during first phase to visit a node and all its subtrees
8542 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8547 if not Has_Extension (N) or else No (Actual_Map) then
8550 elsif NCT_Hash_Tables_Used then
8551 Ent := NCT_Assoc.Get (Entity_Id (N));
8553 if Present (Ent) then
8559 -- No hash table used, do serial search
8562 E := First_Elmt (Actual_Map);
8563 while Present (E) loop
8564 if Node (E) = N then
8565 return Node (Next_Elmt (E));
8567 E := Next_Elmt (Next_Elmt (E));
8575 ---------------------------
8576 -- Build_NCT_Hash_Tables --
8577 ---------------------------
8579 procedure Build_NCT_Hash_Tables is
8583 if NCT_Hash_Table_Setup then
8585 NCT_Itype_Assoc.Reset;
8588 Elmt := First_Elmt (Actual_Map);
8589 while Present (Elmt) loop
8592 -- Get new entity, and associate old and new
8595 NCT_Assoc.Set (Ent, Node (Elmt));
8597 if Is_Type (Ent) then
8599 Anode : constant Entity_Id :=
8600 Associated_Node_For_Itype (Ent);
8603 if Present (Anode) then
8605 -- Enter a link between the associated node of the
8606 -- old Itype and the new Itype, for updating later
8607 -- when node is copied.
8609 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8617 NCT_Hash_Tables_Used := True;
8618 NCT_Hash_Table_Setup := True;
8619 end Build_NCT_Hash_Tables;
8621 ---------------------------------
8622 -- Copy_Elist_With_Replacement --
8623 ---------------------------------
8625 function Copy_Elist_With_Replacement
8626 (Old_Elist : Elist_Id) return Elist_Id
8629 New_Elist : Elist_Id;
8632 if No (Old_Elist) then
8636 New_Elist := New_Elmt_List;
8638 M := First_Elmt (Old_Elist);
8639 while Present (M) loop
8640 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8646 end Copy_Elist_With_Replacement;
8648 ---------------------------------
8649 -- Copy_Itype_With_Replacement --
8650 ---------------------------------
8652 -- This routine exactly parallels its phase one analog Visit_Itype,
8654 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8656 -- Translate Next_Entity, Scope and Etype fields, in case they
8657 -- reference entities that have been mapped into copies.
8659 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8660 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8662 if Present (New_Scope) then
8663 Set_Scope (New_Itype, New_Scope);
8665 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8668 -- Copy referenced fields
8670 if Is_Discrete_Type (New_Itype) then
8671 Set_Scalar_Range (New_Itype,
8672 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8674 elsif Has_Discriminants (Base_Type (New_Itype)) then
8675 Set_Discriminant_Constraint (New_Itype,
8676 Copy_Elist_With_Replacement
8677 (Discriminant_Constraint (New_Itype)));
8679 elsif Is_Array_Type (New_Itype) then
8680 if Present (First_Index (New_Itype)) then
8681 Set_First_Index (New_Itype,
8682 First (Copy_List_With_Replacement
8683 (List_Containing (First_Index (New_Itype)))));
8686 if Is_Packed (New_Itype) then
8687 Set_Packed_Array_Type (New_Itype,
8688 Copy_Node_With_Replacement
8689 (Packed_Array_Type (New_Itype)));
8692 end Copy_Itype_With_Replacement;
8694 --------------------------------
8695 -- Copy_List_With_Replacement --
8696 --------------------------------
8698 function Copy_List_With_Replacement
8699 (Old_List : List_Id) return List_Id
8705 if Old_List = No_List then
8709 New_List := Empty_List;
8711 E := First (Old_List);
8712 while Present (E) loop
8713 Append (Copy_Node_With_Replacement (E), New_List);
8719 end Copy_List_With_Replacement;
8721 --------------------------------
8722 -- Copy_Node_With_Replacement --
8723 --------------------------------
8725 function Copy_Node_With_Replacement
8726 (Old_Node : Node_Id) return Node_Id
8730 procedure Adjust_Named_Associations
8731 (Old_Node : Node_Id;
8732 New_Node : Node_Id);
8733 -- If a call node has named associations, these are chained through
8734 -- the First_Named_Actual, Next_Named_Actual links. These must be
8735 -- propagated separately to the new parameter list, because these
8736 -- are not syntactic fields.
8738 function Copy_Field_With_Replacement
8739 (Field : Union_Id) return Union_Id;
8740 -- Given Field, which is a field of Old_Node, return a copy of it
8741 -- if it is a syntactic field (i.e. its parent is Node), setting
8742 -- the parent of the copy to poit to New_Node. Otherwise returns
8743 -- the field (possibly mapped if it is an entity).
8745 -------------------------------
8746 -- Adjust_Named_Associations --
8747 -------------------------------
8749 procedure Adjust_Named_Associations
8750 (Old_Node : Node_Id;
8760 Old_E := First (Parameter_Associations (Old_Node));
8761 New_E := First (Parameter_Associations (New_Node));
8762 while Present (Old_E) loop
8763 if Nkind (Old_E) = N_Parameter_Association
8764 and then Present (Next_Named_Actual (Old_E))
8766 if First_Named_Actual (Old_Node)
8767 = Explicit_Actual_Parameter (Old_E)
8769 Set_First_Named_Actual
8770 (New_Node, Explicit_Actual_Parameter (New_E));
8773 -- Now scan parameter list from the beginning,to locate
8774 -- next named actual, which can be out of order.
8776 Old_Next := First (Parameter_Associations (Old_Node));
8777 New_Next := First (Parameter_Associations (New_Node));
8779 while Nkind (Old_Next) /= N_Parameter_Association
8780 or else Explicit_Actual_Parameter (Old_Next)
8781 /= Next_Named_Actual (Old_E)
8787 Set_Next_Named_Actual
8788 (New_E, Explicit_Actual_Parameter (New_Next));
8794 end Adjust_Named_Associations;
8796 ---------------------------------
8797 -- Copy_Field_With_Replacement --
8798 ---------------------------------
8800 function Copy_Field_With_Replacement
8801 (Field : Union_Id) return Union_Id
8804 if Field = Union_Id (Empty) then
8807 elsif Field in Node_Range then
8809 Old_N : constant Node_Id := Node_Id (Field);
8813 -- If syntactic field, as indicated by the parent pointer
8814 -- being set, then copy the referenced node recursively.
8816 if Parent (Old_N) = Old_Node then
8817 New_N := Copy_Node_With_Replacement (Old_N);
8819 if New_N /= Old_N then
8820 Set_Parent (New_N, New_Node);
8823 -- For semantic fields, update possible entity reference
8824 -- from the replacement map.
8827 New_N := Assoc (Old_N);
8830 return Union_Id (New_N);
8833 elsif Field in List_Range then
8835 Old_L : constant List_Id := List_Id (Field);
8839 -- If syntactic field, as indicated by the parent pointer,
8840 -- then recursively copy the entire referenced list.
8842 if Parent (Old_L) = Old_Node then
8843 New_L := Copy_List_With_Replacement (Old_L);
8844 Set_Parent (New_L, New_Node);
8846 -- For semantic list, just returned unchanged
8852 return Union_Id (New_L);
8855 -- Anything other than a list or a node is returned unchanged
8860 end Copy_Field_With_Replacement;
8862 -- Start of processing for Copy_Node_With_Replacement
8865 if Old_Node <= Empty_Or_Error then
8868 elsif Has_Extension (Old_Node) then
8869 return Assoc (Old_Node);
8872 New_Node := New_Copy (Old_Node);
8874 -- If the node we are copying is the associated node of a
8875 -- previously copied Itype, then adjust the associated node
8876 -- of the copy of that Itype accordingly.
8878 if Present (Actual_Map) then
8884 -- Case of hash table used
8886 if NCT_Hash_Tables_Used then
8887 Ent := NCT_Itype_Assoc.Get (Old_Node);
8889 if Present (Ent) then
8890 Set_Associated_Node_For_Itype (Ent, New_Node);
8893 -- Case of no hash table used
8896 E := First_Elmt (Actual_Map);
8897 while Present (E) loop
8898 if Is_Itype (Node (E))
8900 Old_Node = Associated_Node_For_Itype (Node (E))
8902 Set_Associated_Node_For_Itype
8903 (Node (Next_Elmt (E)), New_Node);
8906 E := Next_Elmt (Next_Elmt (E));
8912 -- Recursively copy descendents
8915 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8917 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8919 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8921 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8923 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8925 -- Adjust Sloc of new node if necessary
8927 if New_Sloc /= No_Location then
8928 Set_Sloc (New_Node, New_Sloc);
8930 -- If we adjust the Sloc, then we are essentially making
8931 -- a completely new node, so the Comes_From_Source flag
8932 -- should be reset to the proper default value.
8934 Nodes.Table (New_Node).Comes_From_Source :=
8935 Default_Node.Comes_From_Source;
8938 -- If the node is call and has named associations,
8939 -- set the corresponding links in the copy.
8941 if (Nkind (Old_Node) = N_Function_Call
8942 or else Nkind (Old_Node) = N_Entry_Call_Statement
8944 Nkind (Old_Node) = N_Procedure_Call_Statement)
8945 and then Present (First_Named_Actual (Old_Node))
8947 Adjust_Named_Associations (Old_Node, New_Node);
8950 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8951 -- The replacement mechanism applies to entities, and is not used
8952 -- here. Eventually we may need a more general graph-copying
8953 -- routine. For now, do a sequential search to find desired node.
8955 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8956 and then Present (First_Real_Statement (Old_Node))
8959 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8963 N1 := First (Statements (Old_Node));
8964 N2 := First (Statements (New_Node));
8966 while N1 /= Old_F loop
8971 Set_First_Real_Statement (New_Node, N2);
8976 -- All done, return copied node
8979 end Copy_Node_With_Replacement;
8985 procedure Visit_Elist (E : Elist_Id) is
8989 Elmt := First_Elmt (E);
8991 while Elmt /= No_Elmt loop
8992 Visit_Node (Node (Elmt));
9002 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9004 if F = Union_Id (Empty) then
9007 elsif F in Node_Range then
9009 -- Copy node if it is syntactic, i.e. its parent pointer is
9010 -- set to point to the field that referenced it (certain
9011 -- Itypes will also meet this criterion, which is fine, since
9012 -- these are clearly Itypes that do need to be copied, since
9013 -- we are copying their parent.)
9015 if Parent (Node_Id (F)) = N then
9016 Visit_Node (Node_Id (F));
9019 -- Another case, if we are pointing to an Itype, then we want
9020 -- to copy it if its associated node is somewhere in the tree
9023 -- Note: the exclusion of self-referential copies is just an
9024 -- optimization, since the search of the already copied list
9025 -- would catch it, but it is a common case (Etype pointing
9026 -- to itself for an Itype that is a base type).
9028 elsif Has_Extension (Node_Id (F))
9029 and then Is_Itype (Entity_Id (F))
9030 and then Node_Id (F) /= N
9036 P := Associated_Node_For_Itype (Node_Id (F));
9037 while Present (P) loop
9039 Visit_Node (Node_Id (F));
9046 -- An Itype whose parent is not being copied definitely
9047 -- should NOT be copied, since it does not belong in any
9048 -- sense to the copied subtree.
9054 elsif F in List_Range
9055 and then Parent (List_Id (F)) = N
9057 Visit_List (List_Id (F));
9066 procedure Visit_Itype (Old_Itype : Entity_Id) is
9067 New_Itype : Entity_Id;
9072 -- Itypes that describe the designated type of access to subprograms
9073 -- have the structure of subprogram declarations, with signatures,
9074 -- etc. Either we duplicate the signatures completely, or choose to
9075 -- share such itypes, which is fine because their elaboration will
9076 -- have no side effects.
9078 if Ekind (Old_Itype) = E_Subprogram_Type then
9082 New_Itype := New_Copy (Old_Itype);
9084 -- The new Itype has all the attributes of the old one, and
9085 -- we just copy the contents of the entity. However, the back-end
9086 -- needs different names for debugging purposes, so we create a
9087 -- new internal name for it in all cases.
9089 Set_Chars (New_Itype, New_Internal_Name ('T'));
9091 -- If our associated node is an entity that has already been copied,
9092 -- then set the associated node of the copy to point to the right
9093 -- copy. If we have copied an Itype that is itself the associated
9094 -- node of some previously copied Itype, then we set the right
9095 -- pointer in the other direction.
9097 if Present (Actual_Map) then
9099 -- Case of hash tables used
9101 if NCT_Hash_Tables_Used then
9103 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9105 if Present (Ent) then
9106 Set_Associated_Node_For_Itype (New_Itype, Ent);
9109 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9110 if Present (Ent) then
9111 Set_Associated_Node_For_Itype (Ent, New_Itype);
9113 -- If the hash table has no association for this Itype and
9114 -- its associated node, enter one now.
9118 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9121 -- Case of hash tables not used
9124 E := First_Elmt (Actual_Map);
9125 while Present (E) loop
9126 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9127 Set_Associated_Node_For_Itype
9128 (New_Itype, Node (Next_Elmt (E)));
9131 if Is_Type (Node (E))
9133 Old_Itype = Associated_Node_For_Itype (Node (E))
9135 Set_Associated_Node_For_Itype
9136 (Node (Next_Elmt (E)), New_Itype);
9139 E := Next_Elmt (Next_Elmt (E));
9144 if Present (Freeze_Node (New_Itype)) then
9145 Set_Is_Frozen (New_Itype, False);
9146 Set_Freeze_Node (New_Itype, Empty);
9149 -- Add new association to map
9151 if No (Actual_Map) then
9152 Actual_Map := New_Elmt_List;
9155 Append_Elmt (Old_Itype, Actual_Map);
9156 Append_Elmt (New_Itype, Actual_Map);
9158 if NCT_Hash_Tables_Used then
9159 NCT_Assoc.Set (Old_Itype, New_Itype);
9162 NCT_Table_Entries := NCT_Table_Entries + 1;
9164 if NCT_Table_Entries > NCT_Hash_Threshold then
9165 Build_NCT_Hash_Tables;
9169 -- If a record subtype is simply copied, the entity list will be
9170 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9172 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9173 Set_Cloned_Subtype (New_Itype, Old_Itype);
9176 -- Visit descendents that eventually get copied
9178 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9180 if Is_Discrete_Type (Old_Itype) then
9181 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9183 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9184 -- ??? This should involve call to Visit_Field
9185 Visit_Elist (Discriminant_Constraint (Old_Itype));
9187 elsif Is_Array_Type (Old_Itype) then
9188 if Present (First_Index (Old_Itype)) then
9189 Visit_Field (Union_Id (List_Containing
9190 (First_Index (Old_Itype))),
9194 if Is_Packed (Old_Itype) then
9195 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9205 procedure Visit_List (L : List_Id) is
9208 if L /= No_List then
9211 while Present (N) loop
9222 procedure Visit_Node (N : Node_Or_Entity_Id) is
9224 -- Start of processing for Visit_Node
9227 -- Handle case of an Itype, which must be copied
9229 if Has_Extension (N)
9230 and then Is_Itype (N)
9232 -- Nothing to do if already in the list. This can happen with an
9233 -- Itype entity that appears more than once in the tree.
9234 -- Note that we do not want to visit descendents in this case.
9236 -- Test for already in list when hash table is used
9238 if NCT_Hash_Tables_Used then
9239 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9243 -- Test for already in list when hash table not used
9249 if Present (Actual_Map) then
9250 E := First_Elmt (Actual_Map);
9251 while Present (E) loop
9252 if Node (E) = N then
9255 E := Next_Elmt (Next_Elmt (E));
9265 -- Visit descendents
9267 Visit_Field (Field1 (N), N);
9268 Visit_Field (Field2 (N), N);
9269 Visit_Field (Field3 (N), N);
9270 Visit_Field (Field4 (N), N);
9271 Visit_Field (Field5 (N), N);
9274 -- Start of processing for New_Copy_Tree
9279 -- See if we should use hash table
9281 if No (Actual_Map) then
9282 NCT_Hash_Tables_Used := False;
9289 NCT_Table_Entries := 0;
9291 Elmt := First_Elmt (Actual_Map);
9292 while Present (Elmt) loop
9293 NCT_Table_Entries := NCT_Table_Entries + 1;
9298 if NCT_Table_Entries > NCT_Hash_Threshold then
9299 Build_NCT_Hash_Tables;
9301 NCT_Hash_Tables_Used := False;
9306 -- Hash table set up if required, now start phase one by visiting
9307 -- top node (we will recursively visit the descendents).
9309 Visit_Node (Source);
9311 -- Now the second phase of the copy can start. First we process
9312 -- all the mapped entities, copying their descendents.
9314 if Present (Actual_Map) then
9317 New_Itype : Entity_Id;
9319 Elmt := First_Elmt (Actual_Map);
9320 while Present (Elmt) loop
9322 New_Itype := Node (Elmt);
9323 Copy_Itype_With_Replacement (New_Itype);
9329 -- Now we can copy the actual tree
9331 return Copy_Node_With_Replacement (Source);
9334 -------------------------
9335 -- New_External_Entity --
9336 -------------------------
9338 function New_External_Entity
9339 (Kind : Entity_Kind;
9340 Scope_Id : Entity_Id;
9341 Sloc_Value : Source_Ptr;
9342 Related_Id : Entity_Id;
9344 Suffix_Index : Nat := 0;
9345 Prefix : Character := ' ') return Entity_Id
9347 N : constant Entity_Id :=
9348 Make_Defining_Identifier (Sloc_Value,
9350 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9353 Set_Ekind (N, Kind);
9354 Set_Is_Internal (N, True);
9355 Append_Entity (N, Scope_Id);
9356 Set_Public_Status (N);
9358 if Kind in Type_Kind then
9359 Init_Size_Align (N);
9363 end New_External_Entity;
9365 -------------------------
9366 -- New_Internal_Entity --
9367 -------------------------
9369 function New_Internal_Entity
9370 (Kind : Entity_Kind;
9371 Scope_Id : Entity_Id;
9372 Sloc_Value : Source_Ptr;
9373 Id_Char : Character) return Entity_Id
9375 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9378 Set_Ekind (N, Kind);
9379 Set_Is_Internal (N, True);
9380 Append_Entity (N, Scope_Id);
9382 if Kind in Type_Kind then
9383 Init_Size_Align (N);
9387 end New_Internal_Entity;
9393 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9397 -- If we are pointing at a positional parameter, it is a member of a
9398 -- node list (the list of parameters), and the next parameter is the
9399 -- next node on the list, unless we hit a parameter association, then
9400 -- we shift to using the chain whose head is the First_Named_Actual in
9401 -- the parent, and then is threaded using the Next_Named_Actual of the
9402 -- Parameter_Association. All this fiddling is because the original node
9403 -- list is in the textual call order, and what we need is the
9404 -- declaration order.
9406 if Is_List_Member (Actual_Id) then
9407 N := Next (Actual_Id);
9409 if Nkind (N) = N_Parameter_Association then
9410 return First_Named_Actual (Parent (Actual_Id));
9416 return Next_Named_Actual (Parent (Actual_Id));
9420 procedure Next_Actual (Actual_Id : in out Node_Id) is
9422 Actual_Id := Next_Actual (Actual_Id);
9425 -----------------------
9426 -- Normalize_Actuals --
9427 -----------------------
9429 -- Chain actuals according to formals of subprogram. If there are no named
9430 -- associations, the chain is simply the list of Parameter Associations,
9431 -- since the order is the same as the declaration order. If there are named
9432 -- associations, then the First_Named_Actual field in the N_Function_Call
9433 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9434 -- node for the parameter that comes first in declaration order. The
9435 -- remaining named parameters are then chained in declaration order using
9436 -- Next_Named_Actual.
9438 -- This routine also verifies that the number of actuals is compatible with
9439 -- the number and default values of formals, but performs no type checking
9440 -- (type checking is done by the caller).
9442 -- If the matching succeeds, Success is set to True and the caller proceeds
9443 -- with type-checking. If the match is unsuccessful, then Success is set to
9444 -- False, and the caller attempts a different interpretation, if there is
9447 -- If the flag Report is on, the call is not overloaded, and a failure to
9448 -- match can be reported here, rather than in the caller.
9450 procedure Normalize_Actuals
9454 Success : out Boolean)
9456 Actuals : constant List_Id := Parameter_Associations (N);
9457 Actual : Node_Id := Empty;
9459 Last : Node_Id := Empty;
9460 First_Named : Node_Id := Empty;
9463 Formals_To_Match : Integer := 0;
9464 Actuals_To_Match : Integer := 0;
9466 procedure Chain (A : Node_Id);
9467 -- Add named actual at the proper place in the list, using the
9468 -- Next_Named_Actual link.
9470 function Reporting return Boolean;
9471 -- Determines if an error is to be reported. To report an error, we
9472 -- need Report to be True, and also we do not report errors caused
9473 -- by calls to init procs that occur within other init procs. Such
9474 -- errors must always be cascaded errors, since if all the types are
9475 -- declared correctly, the compiler will certainly build decent calls!
9481 procedure Chain (A : Node_Id) is
9485 -- Call node points to first actual in list
9487 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9490 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9494 Set_Next_Named_Actual (Last, Empty);
9501 function Reporting return Boolean is
9506 elsif not Within_Init_Proc then
9509 elsif Is_Init_Proc (Entity (Name (N))) then
9517 -- Start of processing for Normalize_Actuals
9520 if Is_Access_Type (S) then
9522 -- The name in the call is a function call that returns an access
9523 -- to subprogram. The designated type has the list of formals.
9525 Formal := First_Formal (Designated_Type (S));
9527 Formal := First_Formal (S);
9530 while Present (Formal) loop
9531 Formals_To_Match := Formals_To_Match + 1;
9532 Next_Formal (Formal);
9535 -- Find if there is a named association, and verify that no positional
9536 -- associations appear after named ones.
9538 if Present (Actuals) then
9539 Actual := First (Actuals);
9542 while Present (Actual)
9543 and then Nkind (Actual) /= N_Parameter_Association
9545 Actuals_To_Match := Actuals_To_Match + 1;
9549 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9551 -- Most common case: positional notation, no defaults
9556 elsif Actuals_To_Match > Formals_To_Match then
9558 -- Too many actuals: will not work
9561 if Is_Entity_Name (Name (N)) then
9562 Error_Msg_N ("too many arguments in call to&", Name (N));
9564 Error_Msg_N ("too many arguments in call", N);
9572 First_Named := Actual;
9574 while Present (Actual) loop
9575 if Nkind (Actual) /= N_Parameter_Association then
9577 ("positional parameters not allowed after named ones", Actual);
9582 Actuals_To_Match := Actuals_To_Match + 1;
9588 if Present (Actuals) then
9589 Actual := First (Actuals);
9592 Formal := First_Formal (S);
9593 while Present (Formal) loop
9595 -- Match the formals in order. If the corresponding actual is
9596 -- positional, nothing to do. Else scan the list of named actuals
9597 -- to find the one with the right name.
9600 and then Nkind (Actual) /= N_Parameter_Association
9603 Actuals_To_Match := Actuals_To_Match - 1;
9604 Formals_To_Match := Formals_To_Match - 1;
9607 -- For named parameters, search the list of actuals to find
9608 -- one that matches the next formal name.
9610 Actual := First_Named;
9612 while Present (Actual) loop
9613 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9616 Actuals_To_Match := Actuals_To_Match - 1;
9617 Formals_To_Match := Formals_To_Match - 1;
9625 if Ekind (Formal) /= E_In_Parameter
9626 or else No (Default_Value (Formal))
9629 if (Comes_From_Source (S)
9630 or else Sloc (S) = Standard_Location)
9631 and then Is_Overloadable (S)
9635 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9637 (Nkind (Parent (N)) = N_Function_Call
9639 Nkind (Parent (N)) = N_Parameter_Association))
9640 and then Ekind (S) /= E_Function
9642 Set_Etype (N, Etype (S));
9644 Error_Msg_Name_1 := Chars (S);
9645 Error_Msg_Sloc := Sloc (S);
9647 ("missing argument for parameter & " &
9648 "in call to % declared #", N, Formal);
9651 elsif Is_Overloadable (S) then
9652 Error_Msg_Name_1 := Chars (S);
9654 -- Point to type derivation that generated the
9657 Error_Msg_Sloc := Sloc (Parent (S));
9660 ("missing argument for parameter & " &
9661 "in call to % (inherited) #", N, Formal);
9665 ("missing argument for parameter &", N, Formal);
9673 Formals_To_Match := Formals_To_Match - 1;
9678 Next_Formal (Formal);
9681 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9688 -- Find some superfluous named actual that did not get
9689 -- attached to the list of associations.
9691 Actual := First (Actuals);
9692 while Present (Actual) loop
9693 if Nkind (Actual) = N_Parameter_Association
9694 and then Actual /= Last
9695 and then No (Next_Named_Actual (Actual))
9697 Error_Msg_N ("unmatched actual & in call",
9698 Selector_Name (Actual));
9709 end Normalize_Actuals;
9711 --------------------------------
9712 -- Note_Possible_Modification --
9713 --------------------------------
9715 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9716 Modification_Comes_From_Source : constant Boolean :=
9717 Comes_From_Source (Parent (N));
9723 -- Loop to find referenced entity, if there is one
9730 if Is_Entity_Name (Exp) then
9731 Ent := Entity (Exp);
9733 -- If the entity is missing, it is an undeclared identifier,
9734 -- and there is nothing to annotate.
9740 elsif Nkind (Exp) = N_Explicit_Dereference then
9742 P : constant Node_Id := Prefix (Exp);
9745 if Nkind (P) = N_Selected_Component
9747 Entry_Formal (Entity (Selector_Name (P))))
9749 -- Case of a reference to an entry formal
9751 Ent := Entry_Formal (Entity (Selector_Name (P)));
9753 elsif Nkind (P) = N_Identifier
9754 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9755 and then Present (Expression (Parent (Entity (P))))
9756 and then Nkind (Expression (Parent (Entity (P))))
9759 -- Case of a reference to a value on which side effects have
9762 Exp := Prefix (Expression (Parent (Entity (P))));
9771 elsif Nkind (Exp) = N_Type_Conversion
9772 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9774 Exp := Expression (Exp);
9777 elsif Nkind (Exp) = N_Slice
9778 or else Nkind (Exp) = N_Indexed_Component
9779 or else Nkind (Exp) = N_Selected_Component
9781 Exp := Prefix (Exp);
9788 -- Now look for entity being referenced
9790 if Present (Ent) then
9791 if Is_Object (Ent) then
9792 if Comes_From_Source (Exp)
9793 or else Modification_Comes_From_Source
9795 -- Give warning if pragma unmodified given and we are
9796 -- sure this is a modification.
9798 if Has_Pragma_Unmodified (Ent) and then Sure then
9799 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9802 Set_Never_Set_In_Source (Ent, False);
9805 Set_Is_True_Constant (Ent, False);
9806 Set_Current_Value (Ent, Empty);
9807 Set_Is_Known_Null (Ent, False);
9809 if not Can_Never_Be_Null (Ent) then
9810 Set_Is_Known_Non_Null (Ent, False);
9813 -- Follow renaming chain
9815 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9816 and then Present (Renamed_Object (Ent))
9818 Exp := Renamed_Object (Ent);
9822 -- Generate a reference only if the assignment comes from
9823 -- source. This excludes, for example, calls to a dispatching
9824 -- assignment operation when the left-hand side is tagged.
9826 if Modification_Comes_From_Source then
9827 Generate_Reference (Ent, Exp, 'm');
9829 -- If the target of the assignment is the bound variable
9830 -- in an iterator, indicate that the corresponding array
9831 -- or container is also modified.
9833 if Ada_Version >= Ada_2012
9835 Nkind (Parent (Ent)) = N_Iterator_Specification
9838 Domain : constant Node_Id := Name (Parent (Ent));
9841 -- TBD : in the full version of the construct, the
9842 -- domain of iteration can be given by an expression.
9844 if Is_Entity_Name (Domain) then
9845 Generate_Reference (Entity (Domain), Exp, 'm');
9846 Set_Is_True_Constant (Entity (Domain), False);
9847 Set_Never_Set_In_Source (Entity (Domain), False);
9853 Check_Nested_Access (Ent);
9858 -- If we are sure this is a modification from source, and we know
9859 -- this modifies a constant, then give an appropriate warning.
9861 if Overlays_Constant (Ent)
9862 and then Modification_Comes_From_Source
9866 A : constant Node_Id := Address_Clause (Ent);
9870 Exp : constant Node_Id := Expression (A);
9872 if Nkind (Exp) = N_Attribute_Reference
9873 and then Attribute_Name (Exp) = Name_Address
9874 and then Is_Entity_Name (Prefix (Exp))
9876 Error_Msg_Sloc := Sloc (A);
9878 ("constant& may be modified via address clause#?",
9879 N, Entity (Prefix (Exp)));
9889 end Note_Possible_Modification;
9891 -------------------------
9892 -- Object_Access_Level --
9893 -------------------------
9895 function Object_Access_Level (Obj : Node_Id) return Uint is
9898 -- Returns the static accessibility level of the view denoted by Obj. Note
9899 -- that the value returned is the result of a call to Scope_Depth. Only
9900 -- scope depths associated with dynamic scopes can actually be returned.
9901 -- Since only relative levels matter for accessibility checking, the fact
9902 -- that the distance between successive levels of accessibility is not
9903 -- always one is immaterial (invariant: if level(E2) is deeper than
9904 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9906 function Reference_To (Obj : Node_Id) return Node_Id;
9907 -- An explicit dereference is created when removing side-effects from
9908 -- expressions for constraint checking purposes. In this case a local
9909 -- access type is created for it. The correct access level is that of
9910 -- the original source node. We detect this case by noting that the
9911 -- prefix of the dereference is created by an object declaration whose
9912 -- initial expression is a reference.
9918 function Reference_To (Obj : Node_Id) return Node_Id is
9919 Pref : constant Node_Id := Prefix (Obj);
9921 if Is_Entity_Name (Pref)
9922 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9923 and then Present (Expression (Parent (Entity (Pref))))
9924 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9926 return (Prefix (Expression (Parent (Entity (Pref)))));
9932 -- Start of processing for Object_Access_Level
9935 if Is_Entity_Name (Obj) then
9938 if Is_Prival (E) then
9939 E := Prival_Link (E);
9942 -- If E is a type then it denotes a current instance. For this case
9943 -- we add one to the normal accessibility level of the type to ensure
9944 -- that current instances are treated as always being deeper than
9945 -- than the level of any visible named access type (see 3.10.2(21)).
9948 return Type_Access_Level (E) + 1;
9950 elsif Present (Renamed_Object (E)) then
9951 return Object_Access_Level (Renamed_Object (E));
9953 -- Similarly, if E is a component of the current instance of a
9954 -- protected type, any instance of it is assumed to be at a deeper
9955 -- level than the type. For a protected object (whose type is an
9956 -- anonymous protected type) its components are at the same level
9957 -- as the type itself.
9959 elsif not Is_Overloadable (E)
9960 and then Ekind (Scope (E)) = E_Protected_Type
9961 and then Comes_From_Source (Scope (E))
9963 return Type_Access_Level (Scope (E)) + 1;
9966 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9969 elsif Nkind (Obj) = N_Selected_Component then
9970 if Is_Access_Type (Etype (Prefix (Obj))) then
9971 return Type_Access_Level (Etype (Prefix (Obj)));
9973 return Object_Access_Level (Prefix (Obj));
9976 elsif Nkind (Obj) = N_Indexed_Component then
9977 if Is_Access_Type (Etype (Prefix (Obj))) then
9978 return Type_Access_Level (Etype (Prefix (Obj)));
9980 return Object_Access_Level (Prefix (Obj));
9983 elsif Nkind (Obj) = N_Explicit_Dereference then
9985 -- If the prefix is a selected access discriminant then we make a
9986 -- recursive call on the prefix, which will in turn check the level
9987 -- of the prefix object of the selected discriminant.
9989 if Nkind (Prefix (Obj)) = N_Selected_Component
9990 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9992 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9994 return Object_Access_Level (Prefix (Obj));
9996 elsif not (Comes_From_Source (Obj)) then
9998 Ref : constant Node_Id := Reference_To (Obj);
10000 if Present (Ref) then
10001 return Object_Access_Level (Ref);
10003 return Type_Access_Level (Etype (Prefix (Obj)));
10008 return Type_Access_Level (Etype (Prefix (Obj)));
10011 elsif Nkind (Obj) = N_Type_Conversion
10012 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10014 return Object_Access_Level (Expression (Obj));
10016 elsif Nkind (Obj) = N_Function_Call then
10018 -- Function results are objects, so we get either the access level of
10019 -- the function or, in the case of an indirect call, the level of the
10020 -- access-to-subprogram type. (This code is used for Ada 95, but it
10021 -- looks wrong, because it seems that we should be checking the level
10022 -- of the call itself, even for Ada 95. However, using the Ada 2005
10023 -- version of the code causes regressions in several tests that are
10024 -- compiled with -gnat95. ???)
10026 if Ada_Version < Ada_2005 then
10027 if Is_Entity_Name (Name (Obj)) then
10028 return Subprogram_Access_Level (Entity (Name (Obj)));
10030 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10033 -- For Ada 2005, the level of the result object of a function call is
10034 -- defined to be the level of the call's innermost enclosing master.
10035 -- We determine that by querying the depth of the innermost enclosing
10039 Return_Master_Scope_Depth_Of_Call : declare
10041 function Innermost_Master_Scope_Depth
10042 (N : Node_Id) return Uint;
10043 -- Returns the scope depth of the given node's innermost
10044 -- enclosing dynamic scope (effectively the accessibility
10045 -- level of the innermost enclosing master).
10047 ----------------------------------
10048 -- Innermost_Master_Scope_Depth --
10049 ----------------------------------
10051 function Innermost_Master_Scope_Depth
10052 (N : Node_Id) return Uint
10054 Node_Par : Node_Id := Parent (N);
10057 -- Locate the nearest enclosing node (by traversing Parents)
10058 -- that Defining_Entity can be applied to, and return the
10059 -- depth of that entity's nearest enclosing dynamic scope.
10061 while Present (Node_Par) loop
10062 case Nkind (Node_Par) is
10063 when N_Component_Declaration |
10064 N_Entry_Declaration |
10065 N_Formal_Object_Declaration |
10066 N_Formal_Type_Declaration |
10067 N_Full_Type_Declaration |
10068 N_Incomplete_Type_Declaration |
10069 N_Loop_Parameter_Specification |
10070 N_Object_Declaration |
10071 N_Protected_Type_Declaration |
10072 N_Private_Extension_Declaration |
10073 N_Private_Type_Declaration |
10074 N_Subtype_Declaration |
10075 N_Function_Specification |
10076 N_Procedure_Specification |
10077 N_Task_Type_Declaration |
10079 N_Generic_Instantiation |
10081 N_Implicit_Label_Declaration |
10082 N_Package_Declaration |
10083 N_Single_Task_Declaration |
10084 N_Subprogram_Declaration |
10085 N_Generic_Declaration |
10086 N_Renaming_Declaration |
10087 N_Block_Statement |
10088 N_Formal_Subprogram_Declaration |
10089 N_Abstract_Subprogram_Declaration |
10091 N_Exception_Declaration |
10092 N_Formal_Package_Declaration |
10093 N_Number_Declaration |
10094 N_Package_Specification |
10095 N_Parameter_Specification |
10096 N_Single_Protected_Declaration |
10100 (Nearest_Dynamic_Scope
10101 (Defining_Entity (Node_Par)));
10107 Node_Par := Parent (Node_Par);
10110 pragma Assert (False);
10112 -- Should never reach the following return
10114 return Scope_Depth (Current_Scope) + 1;
10115 end Innermost_Master_Scope_Depth;
10117 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10120 return Innermost_Master_Scope_Depth (Obj);
10121 end Return_Master_Scope_Depth_Of_Call;
10124 -- For convenience we handle qualified expressions, even though
10125 -- they aren't technically object names.
10127 elsif Nkind (Obj) = N_Qualified_Expression then
10128 return Object_Access_Level (Expression (Obj));
10130 -- Otherwise return the scope level of Standard.
10131 -- (If there are cases that fall through
10132 -- to this point they will be treated as
10133 -- having global accessibility for now. ???)
10136 return Scope_Depth (Standard_Standard);
10138 end Object_Access_Level;
10140 --------------------------------------
10141 -- Original_Corresponding_Operation --
10142 --------------------------------------
10144 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10146 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10149 -- If S is an inherited primitive S2 the original corresponding
10150 -- operation of S is the original corresponding operation of S2
10152 if Present (Alias (S))
10153 and then Find_Dispatching_Type (Alias (S)) /= Typ
10155 return Original_Corresponding_Operation (Alias (S));
10157 -- If S overrides an inherited subprogram S2 the original corresponding
10158 -- operation of S is the original corresponding operation of S2
10160 elsif Present (Overridden_Operation (S)) then
10161 return Original_Corresponding_Operation (Overridden_Operation (S));
10163 -- otherwise it is S itself
10168 end Original_Corresponding_Operation;
10170 -----------------------
10171 -- Private_Component --
10172 -----------------------
10174 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10175 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10177 function Trace_Components
10179 Check : Boolean) return Entity_Id;
10180 -- Recursive function that does the work, and checks against circular
10181 -- definition for each subcomponent type.
10183 ----------------------
10184 -- Trace_Components --
10185 ----------------------
10187 function Trace_Components
10189 Check : Boolean) return Entity_Id
10191 Btype : constant Entity_Id := Base_Type (T);
10192 Component : Entity_Id;
10194 Candidate : Entity_Id := Empty;
10197 if Check and then Btype = Ancestor then
10198 Error_Msg_N ("circular type definition", Type_Id);
10202 if Is_Private_Type (Btype)
10203 and then not Is_Generic_Type (Btype)
10205 if Present (Full_View (Btype))
10206 and then Is_Record_Type (Full_View (Btype))
10207 and then not Is_Frozen (Btype)
10209 -- To indicate that the ancestor depends on a private type, the
10210 -- current Btype is sufficient. However, to check for circular
10211 -- definition we must recurse on the full view.
10213 Candidate := Trace_Components (Full_View (Btype), True);
10215 if Candidate = Any_Type then
10225 elsif Is_Array_Type (Btype) then
10226 return Trace_Components (Component_Type (Btype), True);
10228 elsif Is_Record_Type (Btype) then
10229 Component := First_Entity (Btype);
10230 while Present (Component) loop
10232 -- Skip anonymous types generated by constrained components
10234 if not Is_Type (Component) then
10235 P := Trace_Components (Etype (Component), True);
10237 if Present (P) then
10238 if P = Any_Type then
10246 Next_Entity (Component);
10254 end Trace_Components;
10256 -- Start of processing for Private_Component
10259 return Trace_Components (Type_Id, False);
10260 end Private_Component;
10262 ---------------------------
10263 -- Primitive_Names_Match --
10264 ---------------------------
10266 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10268 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10269 -- Given an internal name, returns the corresponding non-internal name
10271 ------------------------
10272 -- Non_Internal_Name --
10273 ------------------------
10275 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10277 Get_Name_String (Chars (E));
10278 Name_Len := Name_Len - 1;
10280 end Non_Internal_Name;
10282 -- Start of processing for Primitive_Names_Match
10285 pragma Assert (Present (E1) and then Present (E2));
10287 return Chars (E1) = Chars (E2)
10289 (not Is_Internal_Name (Chars (E1))
10290 and then Is_Internal_Name (Chars (E2))
10291 and then Non_Internal_Name (E2) = Chars (E1))
10293 (not Is_Internal_Name (Chars (E2))
10294 and then Is_Internal_Name (Chars (E1))
10295 and then Non_Internal_Name (E1) = Chars (E2))
10297 (Is_Predefined_Dispatching_Operation (E1)
10298 and then Is_Predefined_Dispatching_Operation (E2)
10299 and then Same_TSS (E1, E2))
10301 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10302 end Primitive_Names_Match;
10304 -----------------------
10305 -- Process_End_Label --
10306 -----------------------
10308 procedure Process_End_Label
10317 Label_Ref : Boolean;
10318 -- Set True if reference to end label itself is required
10321 -- Gets set to the operator symbol or identifier that references the
10322 -- entity Ent. For the child unit case, this is the identifier from the
10323 -- designator. For other cases, this is simply Endl.
10325 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10326 -- N is an identifier node that appears as a parent unit reference in
10327 -- the case where Ent is a child unit. This procedure generates an
10328 -- appropriate cross-reference entry. E is the corresponding entity.
10330 -------------------------
10331 -- Generate_Parent_Ref --
10332 -------------------------
10334 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10336 -- If names do not match, something weird, skip reference
10338 if Chars (E) = Chars (N) then
10340 -- Generate the reference. We do NOT consider this as a reference
10341 -- for unreferenced symbol purposes.
10343 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10345 if Style_Check then
10346 Style.Check_Identifier (N, E);
10349 end Generate_Parent_Ref;
10351 -- Start of processing for Process_End_Label
10354 -- If no node, ignore. This happens in some error situations, and
10355 -- also for some internally generated structures where no end label
10356 -- references are required in any case.
10362 -- Nothing to do if no End_Label, happens for internally generated
10363 -- constructs where we don't want an end label reference anyway. Also
10364 -- nothing to do if Endl is a string literal, which means there was
10365 -- some prior error (bad operator symbol)
10367 Endl := End_Label (N);
10369 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10373 -- Reference node is not in extended main source unit
10375 if not In_Extended_Main_Source_Unit (N) then
10377 -- Generally we do not collect references except for the extended
10378 -- main source unit. The one exception is the 'e' entry for a
10379 -- package spec, where it is useful for a client to have the
10380 -- ending information to define scopes.
10386 Label_Ref := False;
10388 -- For this case, we can ignore any parent references, but we
10389 -- need the package name itself for the 'e' entry.
10391 if Nkind (Endl) = N_Designator then
10392 Endl := Identifier (Endl);
10396 -- Reference is in extended main source unit
10401 -- For designator, generate references for the parent entries
10403 if Nkind (Endl) = N_Designator then
10405 -- Generate references for the prefix if the END line comes from
10406 -- source (otherwise we do not need these references) We climb the
10407 -- scope stack to find the expected entities.
10409 if Comes_From_Source (Endl) then
10410 Nam := Name (Endl);
10411 Scop := Current_Scope;
10412 while Nkind (Nam) = N_Selected_Component loop
10413 Scop := Scope (Scop);
10414 exit when No (Scop);
10415 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10416 Nam := Prefix (Nam);
10419 if Present (Scop) then
10420 Generate_Parent_Ref (Nam, Scope (Scop));
10424 Endl := Identifier (Endl);
10428 -- If the end label is not for the given entity, then either we have
10429 -- some previous error, or this is a generic instantiation for which
10430 -- we do not need to make a cross-reference in this case anyway. In
10431 -- either case we simply ignore the call.
10433 if Chars (Ent) /= Chars (Endl) then
10437 -- If label was really there, then generate a normal reference and then
10438 -- adjust the location in the end label to point past the name (which
10439 -- should almost always be the semicolon).
10441 Loc := Sloc (Endl);
10443 if Comes_From_Source (Endl) then
10445 -- If a label reference is required, then do the style check and
10446 -- generate an l-type cross-reference entry for the label
10449 if Style_Check then
10450 Style.Check_Identifier (Endl, Ent);
10453 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10456 -- Set the location to point past the label (normally this will
10457 -- mean the semicolon immediately following the label). This is
10458 -- done for the sake of the 'e' or 't' entry generated below.
10460 Get_Decoded_Name_String (Chars (Endl));
10461 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10464 -- Now generate the e/t reference
10466 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10468 -- Restore Sloc, in case modified above, since we have an identifier
10469 -- and the normal Sloc should be left set in the tree.
10471 Set_Sloc (Endl, Loc);
10472 end Process_End_Label;
10474 ------------------------------------
10475 -- References_Generic_Formal_Type --
10476 ------------------------------------
10478 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10480 function Process (N : Node_Id) return Traverse_Result;
10481 -- Process one node in search for generic formal type
10487 function Process (N : Node_Id) return Traverse_Result is
10489 if Nkind (N) in N_Has_Entity then
10491 E : constant Entity_Id := Entity (N);
10493 if Present (E) then
10494 if Is_Generic_Type (E) then
10496 elsif Present (Etype (E))
10497 and then Is_Generic_Type (Etype (E))
10508 function Traverse is new Traverse_Func (Process);
10509 -- Traverse tree to look for generic type
10512 if Inside_A_Generic then
10513 return Traverse (N) = Abandon;
10517 end References_Generic_Formal_Type;
10519 --------------------
10520 -- Remove_Homonym --
10521 --------------------
10523 procedure Remove_Homonym (E : Entity_Id) is
10524 Prev : Entity_Id := Empty;
10528 if E = Current_Entity (E) then
10529 if Present (Homonym (E)) then
10530 Set_Current_Entity (Homonym (E));
10532 Set_Name_Entity_Id (Chars (E), Empty);
10535 H := Current_Entity (E);
10536 while Present (H) and then H /= E loop
10541 Set_Homonym (Prev, Homonym (E));
10543 end Remove_Homonym;
10545 ---------------------
10546 -- Rep_To_Pos_Flag --
10547 ---------------------
10549 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10551 return New_Occurrence_Of
10552 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10553 end Rep_To_Pos_Flag;
10555 --------------------
10556 -- Require_Entity --
10557 --------------------
10559 procedure Require_Entity (N : Node_Id) is
10561 if Is_Entity_Name (N) and then No (Entity (N)) then
10562 if Total_Errors_Detected /= 0 then
10563 Set_Entity (N, Any_Id);
10565 raise Program_Error;
10568 end Require_Entity;
10570 ------------------------------
10571 -- Requires_Transient_Scope --
10572 ------------------------------
10574 -- A transient scope is required when variable-sized temporaries are
10575 -- allocated in the primary or secondary stack, or when finalization
10576 -- actions must be generated before the next instruction.
10578 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10579 Typ : constant Entity_Id := Underlying_Type (Id);
10581 -- Start of processing for Requires_Transient_Scope
10584 -- This is a private type which is not completed yet. This can only
10585 -- happen in a default expression (of a formal parameter or of a
10586 -- record component). Do not expand transient scope in this case
10591 -- Do not expand transient scope for non-existent procedure return
10593 elsif Typ = Standard_Void_Type then
10596 -- Elementary types do not require a transient scope
10598 elsif Is_Elementary_Type (Typ) then
10601 -- Generally, indefinite subtypes require a transient scope, since the
10602 -- back end cannot generate temporaries, since this is not a valid type
10603 -- for declaring an object. It might be possible to relax this in the
10604 -- future, e.g. by declaring the maximum possible space for the type.
10606 elsif Is_Indefinite_Subtype (Typ) then
10609 -- Functions returning tagged types may dispatch on result so their
10610 -- returned value is allocated on the secondary stack. Controlled
10611 -- type temporaries need finalization.
10613 elsif Is_Tagged_Type (Typ)
10614 or else Has_Controlled_Component (Typ)
10616 return not Is_Value_Type (Typ);
10620 elsif Is_Record_Type (Typ) then
10624 Comp := First_Entity (Typ);
10625 while Present (Comp) loop
10626 if Ekind (Comp) = E_Component
10627 and then Requires_Transient_Scope (Etype (Comp))
10631 Next_Entity (Comp);
10638 -- String literal types never require transient scope
10640 elsif Ekind (Typ) = E_String_Literal_Subtype then
10643 -- Array type. Note that we already know that this is a constrained
10644 -- array, since unconstrained arrays will fail the indefinite test.
10646 elsif Is_Array_Type (Typ) then
10648 -- If component type requires a transient scope, the array does too
10650 if Requires_Transient_Scope (Component_Type (Typ)) then
10653 -- Otherwise, we only need a transient scope if the size depends on
10654 -- the value of one or more discriminants.
10657 return Size_Depends_On_Discriminant (Typ);
10660 -- All other cases do not require a transient scope
10665 end Requires_Transient_Scope;
10667 --------------------------
10668 -- Reset_Analyzed_Flags --
10669 --------------------------
10671 procedure Reset_Analyzed_Flags (N : Node_Id) is
10673 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10674 -- Function used to reset Analyzed flags in tree. Note that we do
10675 -- not reset Analyzed flags in entities, since there is no need to
10676 -- reanalyze entities, and indeed, it is wrong to do so, since it
10677 -- can result in generating auxiliary stuff more than once.
10679 --------------------
10680 -- Clear_Analyzed --
10681 --------------------
10683 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10685 if not Has_Extension (N) then
10686 Set_Analyzed (N, False);
10690 end Clear_Analyzed;
10692 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10694 -- Start of processing for Reset_Analyzed_Flags
10697 Reset_Analyzed (N);
10698 end Reset_Analyzed_Flags;
10700 ---------------------------
10701 -- Safe_To_Capture_Value --
10702 ---------------------------
10704 function Safe_To_Capture_Value
10707 Cond : Boolean := False) return Boolean
10710 -- The only entities for which we track constant values are variables
10711 -- which are not renamings, constants, out parameters, and in out
10712 -- parameters, so check if we have this case.
10714 -- Note: it may seem odd to track constant values for constants, but in
10715 -- fact this routine is used for other purposes than simply capturing
10716 -- the value. In particular, the setting of Known[_Non]_Null.
10718 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10720 Ekind (Ent) = E_Constant
10722 Ekind (Ent) = E_Out_Parameter
10724 Ekind (Ent) = E_In_Out_Parameter
10728 -- For conditionals, we also allow loop parameters and all formals,
10729 -- including in parameters.
10733 (Ekind (Ent) = E_Loop_Parameter
10735 Ekind (Ent) = E_In_Parameter)
10739 -- For all other cases, not just unsafe, but impossible to capture
10740 -- Current_Value, since the above are the only entities which have
10741 -- Current_Value fields.
10747 -- Skip if volatile or aliased, since funny things might be going on in
10748 -- these cases which we cannot necessarily track. Also skip any variable
10749 -- for which an address clause is given, or whose address is taken. Also
10750 -- never capture value of library level variables (an attempt to do so
10751 -- can occur in the case of package elaboration code).
10753 if Treat_As_Volatile (Ent)
10754 or else Is_Aliased (Ent)
10755 or else Present (Address_Clause (Ent))
10756 or else Address_Taken (Ent)
10757 or else (Is_Library_Level_Entity (Ent)
10758 and then Ekind (Ent) = E_Variable)
10763 -- OK, all above conditions are met. We also require that the scope of
10764 -- the reference be the same as the scope of the entity, not counting
10765 -- packages and blocks and loops.
10768 E_Scope : constant Entity_Id := Scope (Ent);
10769 R_Scope : Entity_Id;
10772 R_Scope := Current_Scope;
10773 while R_Scope /= Standard_Standard loop
10774 exit when R_Scope = E_Scope;
10776 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10779 R_Scope := Scope (R_Scope);
10784 -- We also require that the reference does not appear in a context
10785 -- where it is not sure to be executed (i.e. a conditional context
10786 -- or an exception handler). We skip this if Cond is True, since the
10787 -- capturing of values from conditional tests handles this ok.
10801 while Present (P) loop
10802 if Nkind (P) = N_If_Statement
10803 or else Nkind (P) = N_Case_Statement
10804 or else (Nkind (P) in N_Short_Circuit
10805 and then Desc = Right_Opnd (P))
10806 or else (Nkind (P) = N_Conditional_Expression
10807 and then Desc /= First (Expressions (P)))
10808 or else Nkind (P) = N_Exception_Handler
10809 or else Nkind (P) = N_Selective_Accept
10810 or else Nkind (P) = N_Conditional_Entry_Call
10811 or else Nkind (P) = N_Timed_Entry_Call
10812 or else Nkind (P) = N_Asynchronous_Select
10822 -- OK, looks safe to set value
10825 end Safe_To_Capture_Value;
10831 function Same_Name (N1, N2 : Node_Id) return Boolean is
10832 K1 : constant Node_Kind := Nkind (N1);
10833 K2 : constant Node_Kind := Nkind (N2);
10836 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10837 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10839 return Chars (N1) = Chars (N2);
10841 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10842 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10844 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10845 and then Same_Name (Prefix (N1), Prefix (N2));
10856 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10857 N1 : constant Node_Id := Original_Node (Node1);
10858 N2 : constant Node_Id := Original_Node (Node2);
10859 -- We do the tests on original nodes, since we are most interested
10860 -- in the original source, not any expansion that got in the way.
10862 K1 : constant Node_Kind := Nkind (N1);
10863 K2 : constant Node_Kind := Nkind (N2);
10866 -- First case, both are entities with same entity
10868 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
10870 EN1 : constant Entity_Id := Entity (N1);
10871 EN2 : constant Entity_Id := Entity (N2);
10873 if Present (EN1) and then Present (EN2)
10874 and then (Ekind_In (EN1, E_Variable, E_Constant)
10875 or else Is_Formal (EN1))
10883 -- Second case, selected component with same selector, same record
10885 if K1 = N_Selected_Component
10886 and then K2 = N_Selected_Component
10887 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10889 return Same_Object (Prefix (N1), Prefix (N2));
10891 -- Third case, indexed component with same subscripts, same array
10893 elsif K1 = N_Indexed_Component
10894 and then K2 = N_Indexed_Component
10895 and then Same_Object (Prefix (N1), Prefix (N2))
10900 E1 := First (Expressions (N1));
10901 E2 := First (Expressions (N2));
10902 while Present (E1) loop
10903 if not Same_Value (E1, E2) then
10914 -- Fourth case, slice of same array with same bounds
10917 and then K2 = N_Slice
10918 and then Nkind (Discrete_Range (N1)) = N_Range
10919 and then Nkind (Discrete_Range (N2)) = N_Range
10920 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10921 Low_Bound (Discrete_Range (N2)))
10922 and then Same_Value (High_Bound (Discrete_Range (N1)),
10923 High_Bound (Discrete_Range (N2)))
10925 return Same_Name (Prefix (N1), Prefix (N2));
10927 -- All other cases, not clearly the same object
10938 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10943 elsif not Is_Constrained (T1)
10944 and then not Is_Constrained (T2)
10945 and then Base_Type (T1) = Base_Type (T2)
10949 -- For now don't bother with case of identical constraints, to be
10950 -- fiddled with later on perhaps (this is only used for optimization
10951 -- purposes, so it is not critical to do a best possible job)
10962 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10964 if Compile_Time_Known_Value (Node1)
10965 and then Compile_Time_Known_Value (Node2)
10966 and then Expr_Value (Node1) = Expr_Value (Node2)
10969 elsif Same_Object (Node1, Node2) then
10980 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
10982 if Ada_Version < Ada_2012 then
10985 elsif Is_Entity_Name (N)
10987 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
10989 (Nkind (N) = N_Attribute_Reference
10990 and then Attribute_Name (N) = Name_Access)
10993 -- We are only interested in IN OUT parameters of inner calls
10996 or else Nkind (Parent (N)) = N_Function_Call
10997 or else Nkind (Parent (N)) in N_Op
10999 Actuals_In_Call.Increment_Last;
11000 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11005 ------------------------
11006 -- Scope_Is_Transient --
11007 ------------------------
11009 function Scope_Is_Transient return Boolean is
11011 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11012 end Scope_Is_Transient;
11018 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11023 while Scop /= Standard_Standard loop
11024 Scop := Scope (Scop);
11026 if Scop = Scope2 then
11034 --------------------------
11035 -- Scope_Within_Or_Same --
11036 --------------------------
11038 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11043 while Scop /= Standard_Standard loop
11044 if Scop = Scope2 then
11047 Scop := Scope (Scop);
11052 end Scope_Within_Or_Same;
11054 --------------------
11055 -- Set_Convention --
11056 --------------------
11058 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11060 Basic_Set_Convention (E, Val);
11063 and then Is_Access_Subprogram_Type (Base_Type (E))
11064 and then Has_Foreign_Convention (E)
11066 Set_Can_Use_Internal_Rep (E, False);
11068 end Set_Convention;
11070 ------------------------
11071 -- Set_Current_Entity --
11072 ------------------------
11074 -- The given entity is to be set as the currently visible definition
11075 -- of its associated name (i.e. the Node_Id associated with its name).
11076 -- All we have to do is to get the name from the identifier, and
11077 -- then set the associated Node_Id to point to the given entity.
11079 procedure Set_Current_Entity (E : Entity_Id) is
11081 Set_Name_Entity_Id (Chars (E), E);
11082 end Set_Current_Entity;
11084 ---------------------------
11085 -- Set_Debug_Info_Needed --
11086 ---------------------------
11088 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11090 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11091 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11092 -- Used to set debug info in a related node if not set already
11094 --------------------------------------
11095 -- Set_Debug_Info_Needed_If_Not_Set --
11096 --------------------------------------
11098 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11101 and then not Needs_Debug_Info (E)
11103 Set_Debug_Info_Needed (E);
11105 -- For a private type, indicate that the full view also needs
11106 -- debug information.
11109 and then Is_Private_Type (E)
11110 and then Present (Full_View (E))
11112 Set_Debug_Info_Needed (Full_View (E));
11115 end Set_Debug_Info_Needed_If_Not_Set;
11117 -- Start of processing for Set_Debug_Info_Needed
11120 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11121 -- indicates that Debug_Info_Needed is never required for the entity.
11124 or else Debug_Info_Off (T)
11129 -- Set flag in entity itself. Note that we will go through the following
11130 -- circuitry even if the flag is already set on T. That's intentional,
11131 -- it makes sure that the flag will be set in subsidiary entities.
11133 Set_Needs_Debug_Info (T);
11135 -- Set flag on subsidiary entities if not set already
11137 if Is_Object (T) then
11138 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11140 elsif Is_Type (T) then
11141 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11143 if Is_Record_Type (T) then
11145 Ent : Entity_Id := First_Entity (T);
11147 while Present (Ent) loop
11148 Set_Debug_Info_Needed_If_Not_Set (Ent);
11153 -- For a class wide subtype, we also need debug information
11154 -- for the equivalent type.
11156 if Ekind (T) = E_Class_Wide_Subtype then
11157 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11160 elsif Is_Array_Type (T) then
11161 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11164 Indx : Node_Id := First_Index (T);
11166 while Present (Indx) loop
11167 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11168 Indx := Next_Index (Indx);
11172 if Is_Packed (T) then
11173 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11176 elsif Is_Access_Type (T) then
11177 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11179 elsif Is_Private_Type (T) then
11180 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11182 elsif Is_Protected_Type (T) then
11183 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11186 end Set_Debug_Info_Needed;
11188 ---------------------------------
11189 -- Set_Entity_With_Style_Check --
11190 ---------------------------------
11192 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11193 Val_Actual : Entity_Id;
11197 Set_Entity (N, Val);
11200 and then not Suppress_Style_Checks (Val)
11201 and then not In_Instance
11203 if Nkind (N) = N_Identifier then
11205 elsif Nkind (N) = N_Expanded_Name then
11206 Nod := Selector_Name (N);
11211 -- A special situation arises for derived operations, where we want
11212 -- to do the check against the parent (since the Sloc of the derived
11213 -- operation points to the derived type declaration itself).
11216 while not Comes_From_Source (Val_Actual)
11217 and then Nkind (Val_Actual) in N_Entity
11218 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11219 or else Is_Subprogram (Val_Actual)
11220 or else Is_Generic_Subprogram (Val_Actual))
11221 and then Present (Alias (Val_Actual))
11223 Val_Actual := Alias (Val_Actual);
11226 -- Renaming declarations for generic actuals do not come from source,
11227 -- and have a different name from that of the entity they rename, so
11228 -- there is no style check to perform here.
11230 if Chars (Nod) = Chars (Val_Actual) then
11231 Style.Check_Identifier (Nod, Val_Actual);
11235 Set_Entity (N, Val);
11236 end Set_Entity_With_Style_Check;
11238 ------------------------
11239 -- Set_Name_Entity_Id --
11240 ------------------------
11242 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11244 Set_Name_Table_Info (Id, Int (Val));
11245 end Set_Name_Entity_Id;
11247 ---------------------
11248 -- Set_Next_Actual --
11249 ---------------------
11251 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11253 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11254 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11256 end Set_Next_Actual;
11258 ----------------------------------
11259 -- Set_Optimize_Alignment_Flags --
11260 ----------------------------------
11262 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11264 if Optimize_Alignment = 'S' then
11265 Set_Optimize_Alignment_Space (E);
11266 elsif Optimize_Alignment = 'T' then
11267 Set_Optimize_Alignment_Time (E);
11269 end Set_Optimize_Alignment_Flags;
11271 -----------------------
11272 -- Set_Public_Status --
11273 -----------------------
11275 procedure Set_Public_Status (Id : Entity_Id) is
11276 S : constant Entity_Id := Current_Scope;
11278 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11279 -- Determines if E is defined within handled statement sequence or
11280 -- an if statement, returns True if so, False otherwise.
11282 ----------------------
11283 -- Within_HSS_Or_If --
11284 ----------------------
11286 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11289 N := Declaration_Node (E);
11296 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11302 end Within_HSS_Or_If;
11304 -- Start of processing for Set_Public_Status
11307 -- Everything in the scope of Standard is public
11309 if S = Standard_Standard then
11310 Set_Is_Public (Id);
11312 -- Entity is definitely not public if enclosing scope is not public
11314 elsif not Is_Public (S) then
11317 -- An object or function declaration that occurs in a handled sequence
11318 -- of statements or within an if statement is the declaration for a
11319 -- temporary object or local subprogram generated by the expander. It
11320 -- never needs to be made public and furthermore, making it public can
11321 -- cause back end problems.
11323 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11324 N_Function_Specification)
11325 and then Within_HSS_Or_If (Id)
11329 -- Entities in public packages or records are public
11331 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11332 Set_Is_Public (Id);
11334 -- The bounds of an entry family declaration can generate object
11335 -- declarations that are visible to the back-end, e.g. in the
11336 -- the declaration of a composite type that contains tasks.
11338 elsif Is_Concurrent_Type (S)
11339 and then not Has_Completion (S)
11340 and then Nkind (Parent (Id)) = N_Object_Declaration
11342 Set_Is_Public (Id);
11344 end Set_Public_Status;
11346 -----------------------------
11347 -- Set_Referenced_Modified --
11348 -----------------------------
11350 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11354 -- Deal with indexed or selected component where prefix is modified
11356 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11357 Pref := Prefix (N);
11359 -- If prefix is access type, then it is the designated object that is
11360 -- being modified, which means we have no entity to set the flag on.
11362 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11365 -- Otherwise chase the prefix
11368 Set_Referenced_Modified (Pref, Out_Param);
11371 -- Otherwise see if we have an entity name (only other case to process)
11373 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11374 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11375 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11377 end Set_Referenced_Modified;
11379 ----------------------------
11380 -- Set_Scope_Is_Transient --
11381 ----------------------------
11383 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11385 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11386 end Set_Scope_Is_Transient;
11388 -------------------
11389 -- Set_Size_Info --
11390 -------------------
11392 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11394 -- We copy Esize, but not RM_Size, since in general RM_Size is
11395 -- subtype specific and does not get inherited by all subtypes.
11397 Set_Esize (T1, Esize (T2));
11398 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11400 if Is_Discrete_Or_Fixed_Point_Type (T1)
11402 Is_Discrete_Or_Fixed_Point_Type (T2)
11404 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11407 Set_Alignment (T1, Alignment (T2));
11410 --------------------
11411 -- Static_Boolean --
11412 --------------------
11414 function Static_Boolean (N : Node_Id) return Uint is
11416 Analyze_And_Resolve (N, Standard_Boolean);
11419 or else Error_Posted (N)
11420 or else Etype (N) = Any_Type
11425 if Is_Static_Expression (N) then
11426 if not Raises_Constraint_Error (N) then
11427 return Expr_Value (N);
11432 elsif Etype (N) = Any_Type then
11436 Flag_Non_Static_Expr
11437 ("static boolean expression required here", N);
11440 end Static_Boolean;
11442 --------------------
11443 -- Static_Integer --
11444 --------------------
11446 function Static_Integer (N : Node_Id) return Uint is
11448 Analyze_And_Resolve (N, Any_Integer);
11451 or else Error_Posted (N)
11452 or else Etype (N) = Any_Type
11457 if Is_Static_Expression (N) then
11458 if not Raises_Constraint_Error (N) then
11459 return Expr_Value (N);
11464 elsif Etype (N) = Any_Type then
11468 Flag_Non_Static_Expr
11469 ("static integer expression required here", N);
11472 end Static_Integer;
11474 --------------------------
11475 -- Statically_Different --
11476 --------------------------
11478 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11479 R1 : constant Node_Id := Get_Referenced_Object (E1);
11480 R2 : constant Node_Id := Get_Referenced_Object (E2);
11482 return Is_Entity_Name (R1)
11483 and then Is_Entity_Name (R2)
11484 and then Entity (R1) /= Entity (R2)
11485 and then not Is_Formal (Entity (R1))
11486 and then not Is_Formal (Entity (R2));
11487 end Statically_Different;
11489 -----------------------------
11490 -- Subprogram_Access_Level --
11491 -----------------------------
11493 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11495 if Present (Alias (Subp)) then
11496 return Subprogram_Access_Level (Alias (Subp));
11498 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11500 end Subprogram_Access_Level;
11506 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11508 if Debug_Flag_W then
11509 for J in 0 .. Scope_Stack.Last loop
11514 Write_Name (Chars (E));
11515 Write_Str (" from ");
11516 Write_Location (Sloc (N));
11521 -----------------------
11522 -- Transfer_Entities --
11523 -----------------------
11525 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11526 Ent : Entity_Id := First_Entity (From);
11533 if (Last_Entity (To)) = Empty then
11534 Set_First_Entity (To, Ent);
11536 Set_Next_Entity (Last_Entity (To), Ent);
11539 Set_Last_Entity (To, Last_Entity (From));
11541 while Present (Ent) loop
11542 Set_Scope (Ent, To);
11544 if not Is_Public (Ent) then
11545 Set_Public_Status (Ent);
11548 and then Ekind (Ent) = E_Record_Subtype
11551 -- The components of the propagated Itype must be public
11557 Comp := First_Entity (Ent);
11558 while Present (Comp) loop
11559 Set_Is_Public (Comp);
11560 Next_Entity (Comp);
11569 Set_First_Entity (From, Empty);
11570 Set_Last_Entity (From, Empty);
11571 end Transfer_Entities;
11573 -----------------------
11574 -- Type_Access_Level --
11575 -----------------------
11577 function Type_Access_Level (Typ : Entity_Id) return Uint is
11581 Btyp := Base_Type (Typ);
11583 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11584 -- simply use the level where the type is declared. This is true for
11585 -- stand-alone object declarations, and for anonymous access types
11586 -- associated with components the level is the same as that of the
11587 -- enclosing composite type. However, special treatment is needed for
11588 -- the cases of access parameters, return objects of an anonymous access
11589 -- type, and, in Ada 95, access discriminants of limited types.
11591 if Ekind (Btyp) in Access_Kind then
11592 if Ekind (Btyp) = E_Anonymous_Access_Type then
11594 -- If the type is a nonlocal anonymous access type (such as for
11595 -- an access parameter) we treat it as being declared at the
11596 -- library level to ensure that names such as X.all'access don't
11597 -- fail static accessibility checks.
11599 if not Is_Local_Anonymous_Access (Typ) then
11600 return Scope_Depth (Standard_Standard);
11602 -- If this is a return object, the accessibility level is that of
11603 -- the result subtype of the enclosing function. The test here is
11604 -- little complicated, because we have to account for extended
11605 -- return statements that have been rewritten as blocks, in which
11606 -- case we have to find and the Is_Return_Object attribute of the
11607 -- itype's associated object. It would be nice to find a way to
11608 -- simplify this test, but it doesn't seem worthwhile to add a new
11609 -- flag just for purposes of this test. ???
11611 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11614 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11615 N_Object_Declaration
11616 and then Is_Return_Object
11617 (Defining_Identifier
11618 (Associated_Node_For_Itype (Btyp))))
11624 Scop := Scope (Scope (Btyp));
11625 while Present (Scop) loop
11626 exit when Ekind (Scop) = E_Function;
11627 Scop := Scope (Scop);
11630 -- Treat the return object's type as having the level of the
11631 -- function's result subtype (as per RM05-6.5(5.3/2)).
11633 return Type_Access_Level (Etype (Scop));
11638 Btyp := Root_Type (Btyp);
11640 -- The accessibility level of anonymous access types associated with
11641 -- discriminants is that of the current instance of the type, and
11642 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11644 -- AI-402: access discriminants have accessibility based on the
11645 -- object rather than the type in Ada 2005, so the above paragraph
11648 -- ??? Needs completion with rules from AI-416
11650 if Ada_Version <= Ada_95
11651 and then Ekind (Typ) = E_Anonymous_Access_Type
11652 and then Present (Associated_Node_For_Itype (Typ))
11653 and then Nkind (Associated_Node_For_Itype (Typ)) =
11654 N_Discriminant_Specification
11656 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11660 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11661 end Type_Access_Level;
11663 --------------------------
11664 -- Unit_Declaration_Node --
11665 --------------------------
11667 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11668 N : Node_Id := Parent (Unit_Id);
11671 -- Predefined operators do not have a full function declaration
11673 if Ekind (Unit_Id) = E_Operator then
11677 -- Isn't there some better way to express the following ???
11679 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11680 and then Nkind (N) /= N_Formal_Package_Declaration
11681 and then Nkind (N) /= N_Function_Instantiation
11682 and then Nkind (N) /= N_Generic_Package_Declaration
11683 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11684 and then Nkind (N) /= N_Package_Declaration
11685 and then Nkind (N) /= N_Package_Body
11686 and then Nkind (N) /= N_Package_Instantiation
11687 and then Nkind (N) /= N_Package_Renaming_Declaration
11688 and then Nkind (N) /= N_Procedure_Instantiation
11689 and then Nkind (N) /= N_Protected_Body
11690 and then Nkind (N) /= N_Subprogram_Declaration
11691 and then Nkind (N) /= N_Subprogram_Body
11692 and then Nkind (N) /= N_Subprogram_Body_Stub
11693 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11694 and then Nkind (N) /= N_Task_Body
11695 and then Nkind (N) /= N_Task_Type_Declaration
11696 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11697 and then Nkind (N) not in N_Generic_Renaming_Declaration
11700 pragma Assert (Present (N));
11704 end Unit_Declaration_Node;
11706 ---------------------
11707 -- Unit_Is_Visible --
11708 ---------------------
11710 function Unit_Is_Visible (U : Entity_Id) return Boolean is
11711 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
11712 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11714 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
11715 -- For a child unit, check whether unit appears in a with_clause
11718 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
11719 -- Scan the context clause of one compilation unit looking for a
11720 -- with_clause for the unit in question.
11722 ----------------------------
11723 -- Unit_In_Parent_Context --
11724 ----------------------------
11726 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
11728 if Unit_In_Context (Par_Unit) then
11731 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
11732 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
11737 end Unit_In_Parent_Context;
11739 ---------------------
11740 -- Unit_In_Context --
11741 ---------------------
11743 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
11747 Clause := First (Context_Items (Comp_Unit));
11748 while Present (Clause) loop
11749 if Nkind (Clause) = N_With_Clause then
11750 if Library_Unit (Clause) = U then
11753 -- The with_clause may denote a renaming of the unit we are
11754 -- looking for, eg. Text_IO which renames Ada.Text_IO.
11757 Renamed_Entity (Entity (Name (Clause))) =
11758 Defining_Entity (Unit (U))
11768 end Unit_In_Context;
11770 -- Start of processing for Unit_Is_Visible
11773 -- The currrent unit is directly visible.
11778 elsif Unit_In_Context (Curr) then
11781 -- If the current unit is a body, check the context of the spec.
11783 elsif Nkind (Unit (Curr)) = N_Package_Body
11785 (Nkind (Unit (Curr)) = N_Subprogram_Body
11786 and then not Acts_As_Spec (Unit (Curr)))
11788 if Unit_In_Context (Library_Unit (Curr)) then
11793 -- If the spec is a child unit, examine the parents.
11795 if Is_Child_Unit (Curr_Entity) then
11796 if Nkind (Unit (Curr)) in N_Unit_Body then
11798 Unit_In_Parent_Context
11799 (Parent_Spec (Unit (Library_Unit (Curr))));
11801 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
11807 end Unit_Is_Visible;
11809 ------------------------------
11810 -- Universal_Interpretation --
11811 ------------------------------
11813 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11814 Index : Interp_Index;
11818 -- The argument may be a formal parameter of an operator or subprogram
11819 -- with multiple interpretations, or else an expression for an actual.
11821 if Nkind (Opnd) = N_Defining_Identifier
11822 or else not Is_Overloaded (Opnd)
11824 if Etype (Opnd) = Universal_Integer
11825 or else Etype (Opnd) = Universal_Real
11827 return Etype (Opnd);
11833 Get_First_Interp (Opnd, Index, It);
11834 while Present (It.Typ) loop
11835 if It.Typ = Universal_Integer
11836 or else It.Typ = Universal_Real
11841 Get_Next_Interp (Index, It);
11846 end Universal_Interpretation;
11852 function Unqualify (Expr : Node_Id) return Node_Id is
11854 -- Recurse to handle unlikely case of multiple levels of qualification
11856 if Nkind (Expr) = N_Qualified_Expression then
11857 return Unqualify (Expression (Expr));
11859 -- Normal case, not a qualified expression
11866 -----------------------
11867 -- Visible_Ancestors --
11868 -----------------------
11870 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
11876 pragma Assert (Is_Record_Type (Typ)
11877 and then Is_Tagged_Type (Typ));
11879 -- Collect all the parents and progenitors of Typ. If the full-view of
11880 -- private parents and progenitors is available then it is used to
11881 -- generate the list of visible ancestors; otherwise their partial
11882 -- view is added to the resulting list.
11887 Use_Full_View => True);
11891 Ifaces_List => List_2,
11892 Exclude_Parents => True,
11893 Use_Full_View => True);
11895 -- Join the two lists. Avoid duplications because an interface may
11896 -- simultaneously be parent and progenitor of a type.
11898 Elmt := First_Elmt (List_2);
11899 while Present (Elmt) loop
11900 Append_Unique_Elmt (Node (Elmt), List_1);
11905 end Visible_Ancestors;
11907 ----------------------
11908 -- Within_Init_Proc --
11909 ----------------------
11911 function Within_Init_Proc return Boolean is
11915 S := Current_Scope;
11916 while not Is_Overloadable (S) loop
11917 if S = Standard_Standard then
11924 return Is_Init_Proc (S);
11925 end Within_Init_Proc;
11931 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11932 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11933 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11935 function Has_One_Matching_Field return Boolean;
11936 -- Determines if Expec_Type is a record type with a single component or
11937 -- discriminant whose type matches the found type or is one dimensional
11938 -- array whose component type matches the found type.
11940 ----------------------------
11941 -- Has_One_Matching_Field --
11942 ----------------------------
11944 function Has_One_Matching_Field return Boolean is
11948 if Is_Array_Type (Expec_Type)
11949 and then Number_Dimensions (Expec_Type) = 1
11951 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11955 elsif not Is_Record_Type (Expec_Type) then
11959 E := First_Entity (Expec_Type);
11964 elsif (Ekind (E) /= E_Discriminant
11965 and then Ekind (E) /= E_Component)
11966 or else (Chars (E) = Name_uTag
11967 or else Chars (E) = Name_uParent)
11976 if not Covers (Etype (E), Found_Type) then
11979 elsif Present (Next_Entity (E)) then
11986 end Has_One_Matching_Field;
11988 -- Start of processing for Wrong_Type
11991 -- Don't output message if either type is Any_Type, or if a message
11992 -- has already been posted for this node. We need to do the latter
11993 -- check explicitly (it is ordinarily done in Errout), because we
11994 -- are using ! to force the output of the error messages.
11996 if Expec_Type = Any_Type
11997 or else Found_Type = Any_Type
11998 or else Error_Posted (Expr)
12002 -- In an instance, there is an ongoing problem with completion of
12003 -- type derived from private types. Their structure is what Gigi
12004 -- expects, but the Etype is the parent type rather than the
12005 -- derived private type itself. Do not flag error in this case. The
12006 -- private completion is an entity without a parent, like an Itype.
12007 -- Similarly, full and partial views may be incorrect in the instance.
12008 -- There is no simple way to insure that it is consistent ???
12010 elsif In_Instance then
12011 if Etype (Etype (Expr)) = Etype (Expected_Type)
12013 (Has_Private_Declaration (Expected_Type)
12014 or else Has_Private_Declaration (Etype (Expr)))
12015 and then No (Parent (Expected_Type))
12021 -- An interesting special check. If the expression is parenthesized
12022 -- and its type corresponds to the type of the sole component of the
12023 -- expected record type, or to the component type of the expected one
12024 -- dimensional array type, then assume we have a bad aggregate attempt.
12026 if Nkind (Expr) in N_Subexpr
12027 and then Paren_Count (Expr) /= 0
12028 and then Has_One_Matching_Field
12030 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12032 -- Another special check, if we are looking for a pool-specific access
12033 -- type and we found an E_Access_Attribute_Type, then we have the case
12034 -- of an Access attribute being used in a context which needs a pool-
12035 -- specific type, which is never allowed. The one extra check we make
12036 -- is that the expected designated type covers the Found_Type.
12038 elsif Is_Access_Type (Expec_Type)
12039 and then Ekind (Found_Type) = E_Access_Attribute_Type
12040 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12041 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12043 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12045 Error_Msg_N -- CODEFIX
12046 ("result must be general access type!", Expr);
12047 Error_Msg_NE -- CODEFIX
12048 ("add ALL to }!", Expr, Expec_Type);
12050 -- Another special check, if the expected type is an integer type,
12051 -- but the expression is of type System.Address, and the parent is
12052 -- an addition or subtraction operation whose left operand is the
12053 -- expression in question and whose right operand is of an integral
12054 -- type, then this is an attempt at address arithmetic, so give
12055 -- appropriate message.
12057 elsif Is_Integer_Type (Expec_Type)
12058 and then Is_RTE (Found_Type, RE_Address)
12059 and then (Nkind (Parent (Expr)) = N_Op_Add
12061 Nkind (Parent (Expr)) = N_Op_Subtract)
12062 and then Expr = Left_Opnd (Parent (Expr))
12063 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12066 ("address arithmetic not predefined in package System",
12069 ("\possible missing with/use of System.Storage_Elements",
12073 -- If the expected type is an anonymous access type, as for access
12074 -- parameters and discriminants, the error is on the designated types.
12076 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12077 if Comes_From_Source (Expec_Type) then
12078 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12081 ("expected an access type with designated}",
12082 Expr, Designated_Type (Expec_Type));
12085 if Is_Access_Type (Found_Type)
12086 and then not Comes_From_Source (Found_Type)
12089 ("\\found an access type with designated}!",
12090 Expr, Designated_Type (Found_Type));
12092 if From_With_Type (Found_Type) then
12093 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12094 Error_Msg_Qual_Level := 99;
12095 Error_Msg_NE -- CODEFIX
12096 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12097 Error_Msg_Qual_Level := 0;
12099 Error_Msg_NE ("found}!", Expr, Found_Type);
12103 -- Normal case of one type found, some other type expected
12106 -- If the names of the two types are the same, see if some number
12107 -- of levels of qualification will help. Don't try more than three
12108 -- levels, and if we get to standard, it's no use (and probably
12109 -- represents an error in the compiler) Also do not bother with
12110 -- internal scope names.
12113 Expec_Scope : Entity_Id;
12114 Found_Scope : Entity_Id;
12117 Expec_Scope := Expec_Type;
12118 Found_Scope := Found_Type;
12120 for Levels in Int range 0 .. 3 loop
12121 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12122 Error_Msg_Qual_Level := Levels;
12126 Expec_Scope := Scope (Expec_Scope);
12127 Found_Scope := Scope (Found_Scope);
12129 exit when Expec_Scope = Standard_Standard
12130 or else Found_Scope = Standard_Standard
12131 or else not Comes_From_Source (Expec_Scope)
12132 or else not Comes_From_Source (Found_Scope);
12136 if Is_Record_Type (Expec_Type)
12137 and then Present (Corresponding_Remote_Type (Expec_Type))
12139 Error_Msg_NE ("expected}!", Expr,
12140 Corresponding_Remote_Type (Expec_Type));
12142 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12145 if Is_Entity_Name (Expr)
12146 and then Is_Package_Or_Generic_Package (Entity (Expr))
12148 Error_Msg_N ("\\found package name!", Expr);
12150 elsif Is_Entity_Name (Expr)
12152 (Ekind (Entity (Expr)) = E_Procedure
12154 Ekind (Entity (Expr)) = E_Generic_Procedure)
12156 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12158 ("found procedure name, possibly missing Access attribute!",
12162 ("\\found procedure name instead of function!", Expr);
12165 elsif Nkind (Expr) = N_Function_Call
12166 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12167 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12168 and then No (Parameter_Associations (Expr))
12171 ("found function name, possibly missing Access attribute!",
12174 -- Catch common error: a prefix or infix operator which is not
12175 -- directly visible because the type isn't.
12177 elsif Nkind (Expr) in N_Op
12178 and then Is_Overloaded (Expr)
12179 and then not Is_Immediately_Visible (Expec_Type)
12180 and then not Is_Potentially_Use_Visible (Expec_Type)
12181 and then not In_Use (Expec_Type)
12182 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12185 ("operator of the type is not directly visible!", Expr);
12187 elsif Ekind (Found_Type) = E_Void
12188 and then Present (Parent (Found_Type))
12189 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12191 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12194 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12197 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12198 -- of the same modular type, and (M1 and M2) = 0 was intended.
12200 if Expec_Type = Standard_Boolean
12201 and then Is_Modular_Integer_Type (Found_Type)
12202 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12203 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12206 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12207 L : constant Node_Id := Left_Opnd (Op);
12208 R : constant Node_Id := Right_Opnd (Op);
12210 -- The case for the message is when the left operand of the
12211 -- comparison is the same modular type, or when it is an
12212 -- integer literal (or other universal integer expression),
12213 -- which would have been typed as the modular type if the
12214 -- parens had been there.
12216 if (Etype (L) = Found_Type
12218 Etype (L) = Universal_Integer)
12219 and then Is_Integer_Type (Etype (R))
12222 ("\\possible missing parens for modular operation", Expr);
12227 -- Reset error message qualification indication
12229 Error_Msg_Qual_Level := 0;