1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with 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 Rtsfind; use Rtsfind;
44 with Scans; use Scans;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
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;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uname; use Uname;
63 with GNAT.HTable; use GNAT.HTable;
64 package body Sem_Util is
66 ----------------------------------------
67 -- Global_Variables for New_Copy_Tree --
68 ----------------------------------------
70 -- These global variables are used by New_Copy_Tree. See description
71 -- of the body of this subprogram for details. Global variables can be
72 -- safely used by New_Copy_Tree, since there is no case of a recursive
73 -- call from the processing inside New_Copy_Tree.
75 NCT_Hash_Threshhold : constant := 20;
76 -- If there are more than this number of pairs of entries in the
77 -- map, then Hash_Tables_Used will be set, and the hash tables will
78 -- be initialized and used for the searches.
80 NCT_Hash_Tables_Used : Boolean := False;
81 -- Set to True if hash tables are in use
83 NCT_Table_Entries : Nat;
84 -- Count entries in table to see if threshhold is reached
86 NCT_Hash_Table_Setup : Boolean := False;
87 -- Set to True if hash table contains data. We set this True if we
88 -- setup the hash table with data, and leave it set permanently
89 -- from then on, this is a signal that second and subsequent users
90 -- of the hash table must clear the old entries before reuse.
92 subtype NCT_Header_Num is Int range 0 .. 511;
93 -- Defines range of headers in hash tables (512 headers)
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 function Build_Component_Subtype
102 T : Entity_Id) return Node_Id;
103 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
104 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
105 -- Loc is the source location, T is the original subtype.
107 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
108 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
109 -- with discriminants whose default values are static, examine only the
110 -- components in the selected variant to determine whether all of them
113 function Has_Null_Extension (T : Entity_Id) return Boolean;
114 -- T is a derived tagged type. Check whether the type extension is null.
115 -- If the parent type is fully initialized, T can be treated as such.
117 ------------------------------
118 -- Abstract_Interface_List --
119 ------------------------------
121 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
125 if Is_Concurrent_Type (Typ) then
127 -- If we are dealing with a synchronized subtype, go to the base
128 -- type, whose declaration has the interface list.
130 -- Shouldn't this be Declaration_Node???
132 Nod := Parent (Base_Type (Typ));
134 if Nkind (Nod) = N_Full_Type_Declaration then
138 elsif Ekind (Typ) = E_Record_Type_With_Private then
139 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
140 Nod := Type_Definition (Parent (Typ));
142 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
143 if Present (Full_View (Typ)) then
144 Nod := Type_Definition (Parent (Full_View (Typ)));
146 -- If the full-view is not available we cannot do anything else
147 -- here (the source has errors).
153 -- Support for generic formals with interfaces is still missing ???
155 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
160 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
164 elsif Ekind (Typ) = E_Record_Subtype then
165 Nod := Type_Definition (Parent (Etype (Typ)));
167 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
169 -- Recurse, because parent may still be a private extension. Also
170 -- note that the full view of the subtype or the full view of its
171 -- base type may (both) be unavailable.
173 return Abstract_Interface_List (Etype (Typ));
175 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
176 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
177 Nod := Formal_Type_Definition (Parent (Typ));
179 Nod := Type_Definition (Parent (Typ));
183 return Interface_List (Nod);
184 end Abstract_Interface_List;
186 --------------------------------
187 -- Add_Access_Type_To_Process --
188 --------------------------------
190 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
194 Ensure_Freeze_Node (E);
195 L := Access_Types_To_Process (Freeze_Node (E));
199 Set_Access_Types_To_Process (Freeze_Node (E), L);
203 end Add_Access_Type_To_Process;
205 ----------------------------
206 -- Add_Global_Declaration --
207 ----------------------------
209 procedure Add_Global_Declaration (N : Node_Id) is
210 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
213 if No (Declarations (Aux_Node)) then
214 Set_Declarations (Aux_Node, New_List);
217 Append_To (Declarations (Aux_Node), N);
219 end Add_Global_Declaration;
221 -----------------------
222 -- Alignment_In_Bits --
223 -----------------------
225 function Alignment_In_Bits (E : Entity_Id) return Uint is
227 return Alignment (E) * System_Storage_Unit;
228 end Alignment_In_Bits;
230 -----------------------------------------
231 -- Apply_Compile_Time_Constraint_Error --
232 -----------------------------------------
234 procedure Apply_Compile_Time_Constraint_Error
237 Reason : RT_Exception_Code;
238 Ent : Entity_Id := Empty;
239 Typ : Entity_Id := Empty;
240 Loc : Source_Ptr := No_Location;
241 Rep : Boolean := True;
242 Warn : Boolean := False)
244 Stat : constant Boolean := Is_Static_Expression (N);
245 R_Stat : constant Node_Id :=
246 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
257 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
263 -- Now we replace the node by an N_Raise_Constraint_Error node
264 -- This does not need reanalyzing, so set it as analyzed now.
267 Set_Analyzed (N, True);
270 Set_Raises_Constraint_Error (N);
272 -- Now deal with possible local raise handling
274 Possible_Local_Raise (N, Standard_Constraint_Error);
276 -- If the original expression was marked as static, the result is
277 -- still marked as static, but the Raises_Constraint_Error flag is
278 -- always set so that further static evaluation is not attempted.
281 Set_Is_Static_Expression (N);
283 end Apply_Compile_Time_Constraint_Error;
285 --------------------------
286 -- Build_Actual_Subtype --
287 --------------------------
289 function Build_Actual_Subtype
291 N : Node_Or_Entity_Id) return Node_Id
294 -- Normally Sloc (N), but may point to corresponding body in some cases
296 Constraints : List_Id;
302 Disc_Type : Entity_Id;
308 if Nkind (N) = N_Defining_Identifier then
309 Obj := New_Reference_To (N, Loc);
311 -- If this is a formal parameter of a subprogram declaration, and
312 -- we are compiling the body, we want the declaration for the
313 -- actual subtype to carry the source position of the body, to
314 -- prevent anomalies in gdb when stepping through the code.
316 if Is_Formal (N) then
318 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
320 if Nkind (Decl) = N_Subprogram_Declaration
321 and then Present (Corresponding_Body (Decl))
323 Loc := Sloc (Corresponding_Body (Decl));
332 if Is_Array_Type (T) then
333 Constraints := New_List;
334 for J in 1 .. Number_Dimensions (T) loop
336 -- Build an array subtype declaration with the nominal subtype and
337 -- the bounds of the actual. Add the declaration in front of the
338 -- local declarations for the subprogram, for analysis before any
339 -- reference to the formal in the body.
342 Make_Attribute_Reference (Loc,
344 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
345 Attribute_Name => Name_First,
346 Expressions => New_List (
347 Make_Integer_Literal (Loc, J)));
350 Make_Attribute_Reference (Loc,
352 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
353 Attribute_Name => Name_Last,
354 Expressions => New_List (
355 Make_Integer_Literal (Loc, J)));
357 Append (Make_Range (Loc, Lo, Hi), Constraints);
360 -- If the type has unknown discriminants there is no constrained
361 -- subtype to build. This is never called for a formal or for a
362 -- lhs, so returning the type is ok ???
364 elsif Has_Unknown_Discriminants (T) then
368 Constraints := New_List;
370 -- Type T is a generic derived type, inherit the discriminants from
373 if Is_Private_Type (T)
374 and then No (Full_View (T))
376 -- T was flagged as an error if it was declared as a formal
377 -- derived type with known discriminants. In this case there
378 -- is no need to look at the parent type since T already carries
379 -- its own discriminants.
381 and then not Error_Posted (T)
383 Disc_Type := Etype (Base_Type (T));
388 Discr := First_Discriminant (Disc_Type);
389 while Present (Discr) loop
390 Append_To (Constraints,
391 Make_Selected_Component (Loc,
393 Duplicate_Subexpr_No_Checks (Obj),
394 Selector_Name => New_Occurrence_Of (Discr, Loc)));
395 Next_Discriminant (Discr);
400 Make_Defining_Identifier (Loc,
401 Chars => New_Internal_Name ('S'));
402 Set_Is_Internal (Subt);
405 Make_Subtype_Declaration (Loc,
406 Defining_Identifier => Subt,
407 Subtype_Indication =>
408 Make_Subtype_Indication (Loc,
409 Subtype_Mark => New_Reference_To (T, Loc),
411 Make_Index_Or_Discriminant_Constraint (Loc,
412 Constraints => Constraints)));
414 Mark_Rewrite_Insertion (Decl);
416 end Build_Actual_Subtype;
418 ---------------------------------------
419 -- Build_Actual_Subtype_Of_Component --
420 ---------------------------------------
422 function Build_Actual_Subtype_Of_Component
424 N : Node_Id) return Node_Id
426 Loc : constant Source_Ptr := Sloc (N);
427 P : constant Node_Id := Prefix (N);
430 Indx_Type : Entity_Id;
432 Deaccessed_T : Entity_Id;
433 -- This is either a copy of T, or if T is an access type, then it is
434 -- the directly designated type of this access type.
436 function Build_Actual_Array_Constraint return List_Id;
437 -- If one or more of the bounds of the component depends on
438 -- discriminants, build actual constraint using the discriminants
441 function Build_Actual_Record_Constraint return List_Id;
442 -- Similar to previous one, for discriminated components constrained
443 -- by the discriminant of the enclosing object.
445 -----------------------------------
446 -- Build_Actual_Array_Constraint --
447 -----------------------------------
449 function Build_Actual_Array_Constraint return List_Id is
450 Constraints : constant List_Id := New_List;
458 Indx := First_Index (Deaccessed_T);
459 while Present (Indx) loop
460 Old_Lo := Type_Low_Bound (Etype (Indx));
461 Old_Hi := Type_High_Bound (Etype (Indx));
463 if Denotes_Discriminant (Old_Lo) then
465 Make_Selected_Component (Loc,
466 Prefix => New_Copy_Tree (P),
467 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
470 Lo := New_Copy_Tree (Old_Lo);
472 -- The new bound will be reanalyzed in the enclosing
473 -- declaration. For literal bounds that come from a type
474 -- declaration, the type of the context must be imposed, so
475 -- insure that analysis will take place. For non-universal
476 -- types this is not strictly necessary.
478 Set_Analyzed (Lo, False);
481 if Denotes_Discriminant (Old_Hi) then
483 Make_Selected_Component (Loc,
484 Prefix => New_Copy_Tree (P),
485 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
488 Hi := New_Copy_Tree (Old_Hi);
489 Set_Analyzed (Hi, False);
492 Append (Make_Range (Loc, Lo, Hi), Constraints);
497 end Build_Actual_Array_Constraint;
499 ------------------------------------
500 -- Build_Actual_Record_Constraint --
501 ------------------------------------
503 function Build_Actual_Record_Constraint return List_Id is
504 Constraints : constant List_Id := New_List;
509 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
510 while Present (D) loop
511 if Denotes_Discriminant (Node (D)) then
512 D_Val := Make_Selected_Component (Loc,
513 Prefix => New_Copy_Tree (P),
514 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
517 D_Val := New_Copy_Tree (Node (D));
520 Append (D_Val, Constraints);
525 end Build_Actual_Record_Constraint;
527 -- Start of processing for Build_Actual_Subtype_Of_Component
530 -- Why the test for Spec_Expression mode here???
532 if In_Spec_Expression then
535 -- More comments for the rest of this body would be good ???
537 elsif Nkind (N) = N_Explicit_Dereference then
538 if Is_Composite_Type (T)
539 and then not Is_Constrained (T)
540 and then not (Is_Class_Wide_Type (T)
541 and then Is_Constrained (Root_Type (T)))
542 and then not Has_Unknown_Discriminants (T)
544 -- If the type of the dereference is already constrained, it
545 -- is an actual subtype.
547 if Is_Array_Type (Etype (N))
548 and then Is_Constrained (Etype (N))
552 Remove_Side_Effects (P);
553 return Build_Actual_Subtype (T, N);
560 if Ekind (T) = E_Access_Subtype then
561 Deaccessed_T := Designated_Type (T);
566 if Ekind (Deaccessed_T) = E_Array_Subtype then
567 Id := First_Index (Deaccessed_T);
568 while Present (Id) loop
569 Indx_Type := Underlying_Type (Etype (Id));
571 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
573 Denotes_Discriminant (Type_High_Bound (Indx_Type))
575 Remove_Side_Effects (P);
577 Build_Component_Subtype
578 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
584 elsif Is_Composite_Type (Deaccessed_T)
585 and then Has_Discriminants (Deaccessed_T)
586 and then not Has_Unknown_Discriminants (Deaccessed_T)
588 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
589 while Present (D) loop
590 if Denotes_Discriminant (Node (D)) then
591 Remove_Side_Effects (P);
593 Build_Component_Subtype (
594 Build_Actual_Record_Constraint, Loc, Base_Type (T));
601 -- If none of the above, the actual and nominal subtypes are the same
604 end Build_Actual_Subtype_Of_Component;
606 -----------------------------
607 -- Build_Component_Subtype --
608 -----------------------------
610 function Build_Component_Subtype
613 T : Entity_Id) return Node_Id
619 -- Unchecked_Union components do not require component subtypes
621 if Is_Unchecked_Union (T) then
626 Make_Defining_Identifier (Loc,
627 Chars => New_Internal_Name ('S'));
628 Set_Is_Internal (Subt);
631 Make_Subtype_Declaration (Loc,
632 Defining_Identifier => Subt,
633 Subtype_Indication =>
634 Make_Subtype_Indication (Loc,
635 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
637 Make_Index_Or_Discriminant_Constraint (Loc,
640 Mark_Rewrite_Insertion (Decl);
642 end Build_Component_Subtype;
644 ---------------------------
645 -- Build_Default_Subtype --
646 ---------------------------
648 function Build_Default_Subtype
650 N : Node_Id) return Entity_Id
652 Loc : constant Source_Ptr := Sloc (N);
656 if not Has_Discriminants (T) or else Is_Constrained (T) then
660 Disc := First_Discriminant (T);
662 if No (Discriminant_Default_Value (Disc)) then
667 Act : constant Entity_Id :=
668 Make_Defining_Identifier (Loc,
669 Chars => New_Internal_Name ('S'));
671 Constraints : constant List_Id := New_List;
675 while Present (Disc) loop
676 Append_To (Constraints,
677 New_Copy_Tree (Discriminant_Default_Value (Disc)));
678 Next_Discriminant (Disc);
682 Make_Subtype_Declaration (Loc,
683 Defining_Identifier => Act,
684 Subtype_Indication =>
685 Make_Subtype_Indication (Loc,
686 Subtype_Mark => New_Occurrence_Of (T, Loc),
688 Make_Index_Or_Discriminant_Constraint (Loc,
689 Constraints => Constraints)));
691 Insert_Action (N, Decl);
695 end Build_Default_Subtype;
697 --------------------------------------------
698 -- Build_Discriminal_Subtype_Of_Component --
699 --------------------------------------------
701 function Build_Discriminal_Subtype_Of_Component
702 (T : Entity_Id) return Node_Id
704 Loc : constant Source_Ptr := Sloc (T);
708 function Build_Discriminal_Array_Constraint return List_Id;
709 -- If one or more of the bounds of the component depends on
710 -- discriminants, build actual constraint using the discriminants
713 function Build_Discriminal_Record_Constraint return List_Id;
714 -- Similar to previous one, for discriminated components constrained
715 -- by the discriminant of the enclosing object.
717 ----------------------------------------
718 -- Build_Discriminal_Array_Constraint --
719 ----------------------------------------
721 function Build_Discriminal_Array_Constraint return List_Id is
722 Constraints : constant List_Id := New_List;
730 Indx := First_Index (T);
731 while Present (Indx) loop
732 Old_Lo := Type_Low_Bound (Etype (Indx));
733 Old_Hi := Type_High_Bound (Etype (Indx));
735 if Denotes_Discriminant (Old_Lo) then
736 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
739 Lo := New_Copy_Tree (Old_Lo);
742 if Denotes_Discriminant (Old_Hi) then
743 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
746 Hi := New_Copy_Tree (Old_Hi);
749 Append (Make_Range (Loc, Lo, Hi), Constraints);
754 end Build_Discriminal_Array_Constraint;
756 -----------------------------------------
757 -- Build_Discriminal_Record_Constraint --
758 -----------------------------------------
760 function Build_Discriminal_Record_Constraint return List_Id is
761 Constraints : constant List_Id := New_List;
766 D := First_Elmt (Discriminant_Constraint (T));
767 while Present (D) loop
768 if Denotes_Discriminant (Node (D)) then
770 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
773 D_Val := New_Copy_Tree (Node (D));
776 Append (D_Val, Constraints);
781 end Build_Discriminal_Record_Constraint;
783 -- Start of processing for Build_Discriminal_Subtype_Of_Component
786 if Ekind (T) = E_Array_Subtype then
787 Id := First_Index (T);
788 while Present (Id) loop
789 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
790 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
792 return Build_Component_Subtype
793 (Build_Discriminal_Array_Constraint, Loc, T);
799 elsif Ekind (T) = E_Record_Subtype
800 and then Has_Discriminants (T)
801 and then not Has_Unknown_Discriminants (T)
803 D := First_Elmt (Discriminant_Constraint (T));
804 while Present (D) loop
805 if Denotes_Discriminant (Node (D)) then
806 return Build_Component_Subtype
807 (Build_Discriminal_Record_Constraint, Loc, T);
814 -- If none of the above, the actual and nominal subtypes are the same
817 end Build_Discriminal_Subtype_Of_Component;
819 ------------------------------
820 -- Build_Elaboration_Entity --
821 ------------------------------
823 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
824 Loc : constant Source_Ptr := Sloc (N);
826 Elab_Ent : Entity_Id;
828 procedure Set_Package_Name (Ent : Entity_Id);
829 -- Given an entity, sets the fully qualified name of the entity in
830 -- Name_Buffer, with components separated by double underscores. This
831 -- is a recursive routine that climbs the scope chain to Standard.
833 ----------------------
834 -- Set_Package_Name --
835 ----------------------
837 procedure Set_Package_Name (Ent : Entity_Id) is
839 if Scope (Ent) /= Standard_Standard then
840 Set_Package_Name (Scope (Ent));
843 Nam : constant String := Get_Name_String (Chars (Ent));
845 Name_Buffer (Name_Len + 1) := '_';
846 Name_Buffer (Name_Len + 2) := '_';
847 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
848 Name_Len := Name_Len + Nam'Length + 2;
852 Get_Name_String (Chars (Ent));
854 end Set_Package_Name;
856 -- Start of processing for Build_Elaboration_Entity
859 -- Ignore if already constructed
861 if Present (Elaboration_Entity (Spec_Id)) then
865 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
866 -- name with dots replaced by double underscore. We have to manually
867 -- construct this name, since it will be elaborated in the outer scope,
868 -- and thus will not have the unit name automatically prepended.
870 Set_Package_Name (Spec_Id);
874 Name_Buffer (Name_Len + 1) := '_';
875 Name_Buffer (Name_Len + 2) := 'E';
876 Name_Len := Name_Len + 2;
878 -- Create elaboration flag
881 Make_Defining_Identifier (Loc, Chars => Name_Find);
882 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
885 Make_Object_Declaration (Loc,
886 Defining_Identifier => Elab_Ent,
888 New_Occurrence_Of (Standard_Boolean, Loc),
890 New_Occurrence_Of (Standard_False, Loc));
892 Push_Scope (Standard_Standard);
893 Add_Global_Declaration (Decl);
896 -- Reset True_Constant indication, since we will indeed assign a value
897 -- to the variable in the binder main. We also kill the Current_Value
898 -- and Last_Assignment fields for the same reason.
900 Set_Is_True_Constant (Elab_Ent, False);
901 Set_Current_Value (Elab_Ent, Empty);
902 Set_Last_Assignment (Elab_Ent, Empty);
904 -- We do not want any further qualification of the name (if we did
905 -- not do this, we would pick up the name of the generic package
906 -- in the case of a library level generic instantiation).
908 Set_Has_Qualified_Name (Elab_Ent);
909 Set_Has_Fully_Qualified_Name (Elab_Ent);
910 end Build_Elaboration_Entity;
912 -----------------------------------
913 -- Cannot_Raise_Constraint_Error --
914 -----------------------------------
916 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
918 if Compile_Time_Known_Value (Expr) then
921 elsif Do_Range_Check (Expr) then
924 elsif Raises_Constraint_Error (Expr) then
932 when N_Expanded_Name =>
935 when N_Selected_Component =>
936 return not Do_Discriminant_Check (Expr);
938 when N_Attribute_Reference =>
939 if Do_Overflow_Check (Expr) then
942 elsif No (Expressions (Expr)) then
950 N := First (Expressions (Expr));
951 while Present (N) loop
952 if Cannot_Raise_Constraint_Error (N) then
963 when N_Type_Conversion =>
964 if Do_Overflow_Check (Expr)
965 or else Do_Length_Check (Expr)
966 or else Do_Tag_Check (Expr)
971 Cannot_Raise_Constraint_Error (Expression (Expr));
974 when N_Unchecked_Type_Conversion =>
975 return Cannot_Raise_Constraint_Error (Expression (Expr));
978 if Do_Overflow_Check (Expr) then
982 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
989 if Do_Division_Check (Expr)
990 or else Do_Overflow_Check (Expr)
995 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
997 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1016 N_Op_Shift_Right_Arithmetic |
1020 if Do_Overflow_Check (Expr) then
1024 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1026 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1033 end Cannot_Raise_Constraint_Error;
1035 --------------------------
1036 -- Check_Fully_Declared --
1037 --------------------------
1039 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1041 if Ekind (T) = E_Incomplete_Type then
1043 -- Ada 2005 (AI-50217): If the type is available through a limited
1044 -- with_clause, verify that its full view has been analyzed.
1046 if From_With_Type (T)
1047 and then Present (Non_Limited_View (T))
1048 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1050 -- The non-limited view is fully declared
1055 ("premature usage of incomplete}", N, First_Subtype (T));
1058 -- Need comments for these tests ???
1060 elsif Has_Private_Component (T)
1061 and then not Is_Generic_Type (Root_Type (T))
1062 and then not In_Spec_Expression
1064 -- Special case: if T is the anonymous type created for a single
1065 -- task or protected object, use the name of the source object.
1067 if Is_Concurrent_Type (T)
1068 and then not Comes_From_Source (T)
1069 and then Nkind (N) = N_Object_Declaration
1071 Error_Msg_NE ("type of& has incomplete component", N,
1072 Defining_Identifier (N));
1076 ("premature usage of incomplete}", N, First_Subtype (T));
1079 end Check_Fully_Declared;
1081 -------------------------
1082 -- Check_Nested_Access --
1083 -------------------------
1085 procedure Check_Nested_Access (Ent : Entity_Id) is
1086 Scop : constant Entity_Id := Current_Scope;
1087 Current_Subp : Entity_Id;
1088 Enclosing : Entity_Id;
1091 -- Currently only enabled for VM back-ends for efficiency, should we
1092 -- enable it more systematically ???
1094 -- Check for Is_Imported needs commenting below ???
1096 if VM_Target /= No_VM
1097 and then (Ekind (Ent) = E_Variable
1099 Ekind (Ent) = E_Constant
1101 Ekind (Ent) = E_Loop_Parameter)
1102 and then Scope (Ent) /= Empty
1103 and then not Is_Library_Level_Entity (Ent)
1104 and then not Is_Imported (Ent)
1106 if Is_Subprogram (Scop)
1107 or else Is_Generic_Subprogram (Scop)
1108 or else Is_Entry (Scop)
1110 Current_Subp := Scop;
1112 Current_Subp := Current_Subprogram;
1115 Enclosing := Enclosing_Subprogram (Ent);
1117 if Enclosing /= Empty
1118 and then Enclosing /= Current_Subp
1120 Set_Has_Up_Level_Access (Ent, True);
1123 end Check_Nested_Access;
1125 ------------------------------------------
1126 -- Check_Potentially_Blocking_Operation --
1127 ------------------------------------------
1129 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1132 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1133 -- When pragma Detect_Blocking is active, the run time will raise
1134 -- Program_Error. Here we only issue a warning, since we generally
1135 -- support the use of potentially blocking operations in the absence
1138 -- Indirect blocking through a subprogram call cannot be diagnosed
1139 -- statically without interprocedural analysis, so we do not attempt
1142 S := Scope (Current_Scope);
1143 while Present (S) and then S /= Standard_Standard loop
1144 if Is_Protected_Type (S) then
1146 ("potentially blocking operation in protected operation?", N);
1153 end Check_Potentially_Blocking_Operation;
1155 ------------------------------
1156 -- Check_Unprotected_Access --
1157 ------------------------------
1159 procedure Check_Unprotected_Access
1163 Cont_Encl_Typ : Entity_Id;
1164 Pref_Encl_Typ : Entity_Id;
1166 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1167 -- Check whether Obj is a private component of a protected object.
1168 -- Return the protected type where the component resides, Empty
1171 function Is_Public_Operation return Boolean;
1172 -- Verify that the enclosing operation is callable from outside the
1173 -- protected object, to minimize false positives.
1175 ------------------------------
1176 -- Enclosing_Protected_Type --
1177 ------------------------------
1179 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1181 if Is_Entity_Name (Obj) then
1183 Ent : Entity_Id := Entity (Obj);
1186 -- The object can be a renaming of a private component, use
1187 -- the original record component.
1189 if Is_Prival (Ent) then
1190 Ent := Prival_Link (Ent);
1193 if Is_Protected_Type (Scope (Ent)) then
1199 -- For indexed and selected components, recursively check the prefix
1201 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1202 return Enclosing_Protected_Type (Prefix (Obj));
1204 -- The object does not denote a protected component
1209 end Enclosing_Protected_Type;
1211 -------------------------
1212 -- Is_Public_Operation --
1213 -------------------------
1215 function Is_Public_Operation return Boolean is
1222 and then S /= Pref_Encl_Typ
1224 if Scope (S) = Pref_Encl_Typ then
1225 E := First_Entity (Pref_Encl_Typ);
1227 and then E /= First_Private_Entity (Pref_Encl_Typ)
1240 end Is_Public_Operation;
1242 -- Start of processing for Check_Unprotected_Access
1245 if Nkind (Expr) = N_Attribute_Reference
1246 and then Attribute_Name (Expr) = Name_Unchecked_Access
1248 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1249 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1251 -- Check whether we are trying to export a protected component to a
1252 -- context with an equal or lower access level.
1254 if Present (Pref_Encl_Typ)
1255 and then No (Cont_Encl_Typ)
1256 and then Is_Public_Operation
1257 and then Scope_Depth (Pref_Encl_Typ) >=
1258 Object_Access_Level (Context)
1261 ("?possible unprotected access to protected data", Expr);
1264 end Check_Unprotected_Access;
1270 procedure Check_VMS (Construct : Node_Id) is
1272 if not OpenVMS_On_Target then
1274 ("this construct is allowed only in Open'V'M'S", Construct);
1278 ------------------------
1279 -- Collect_Interfaces --
1280 ------------------------
1282 procedure Collect_Interfaces
1284 Ifaces_List : out Elist_Id;
1285 Exclude_Parents : Boolean := False;
1286 Use_Full_View : Boolean := True)
1288 procedure Collect (Typ : Entity_Id);
1289 -- Subsidiary subprogram used to traverse the whole list
1290 -- of directly and indirectly implemented interfaces
1296 procedure Collect (Typ : Entity_Id) is
1297 Ancestor : Entity_Id;
1305 -- Handle private types
1308 and then Is_Private_Type (Typ)
1309 and then Present (Full_View (Typ))
1311 Full_T := Full_View (Typ);
1314 -- Include the ancestor if we are generating the whole list of
1315 -- abstract interfaces.
1317 if Etype (Full_T) /= Typ
1319 -- Protect the frontend against wrong sources. For example:
1322 -- type A is tagged null record;
1323 -- type B is new A with private;
1324 -- type C is new A with private;
1326 -- type B is new C with null record;
1327 -- type C is new B with null record;
1330 and then Etype (Full_T) /= T
1332 Ancestor := Etype (Full_T);
1335 if Is_Interface (Ancestor)
1336 and then not Exclude_Parents
1338 Append_Unique_Elmt (Ancestor, Ifaces_List);
1342 -- Traverse the graph of ancestor interfaces
1344 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1345 Id := First (Abstract_Interface_List (Full_T));
1346 while Present (Id) loop
1347 Iface := Etype (Id);
1349 -- Protect against wrong uses. For example:
1350 -- type I is interface;
1351 -- type O is tagged null record;
1352 -- type Wrong is new I and O with null record; -- ERROR
1354 if Is_Interface (Iface) then
1356 and then Etype (T) /= T
1357 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1362 Append_Unique_Elmt (Iface, Ifaces_List);
1371 -- Start of processing for Collect_Interfaces
1374 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1375 Ifaces_List := New_Elmt_List;
1377 end Collect_Interfaces;
1379 ----------------------------------
1380 -- Collect_Interface_Components --
1381 ----------------------------------
1383 procedure Collect_Interface_Components
1384 (Tagged_Type : Entity_Id;
1385 Components_List : out Elist_Id)
1387 procedure Collect (Typ : Entity_Id);
1388 -- Subsidiary subprogram used to climb to the parents
1394 procedure Collect (Typ : Entity_Id) is
1395 Tag_Comp : Entity_Id;
1396 Parent_Typ : Entity_Id;
1399 -- Handle private types
1401 if Present (Full_View (Etype (Typ))) then
1402 Parent_Typ := Full_View (Etype (Typ));
1404 Parent_Typ := Etype (Typ);
1407 if Parent_Typ /= Typ
1409 -- Protect the frontend against wrong sources. For example:
1412 -- type A is tagged null record;
1413 -- type B is new A with private;
1414 -- type C is new A with private;
1416 -- type B is new C with null record;
1417 -- type C is new B with null record;
1420 and then Parent_Typ /= Tagged_Type
1422 Collect (Parent_Typ);
1425 -- Collect the components containing tags of secondary dispatch
1428 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1429 while Present (Tag_Comp) loop
1430 pragma Assert (Present (Related_Type (Tag_Comp)));
1431 Append_Elmt (Tag_Comp, Components_List);
1433 Tag_Comp := Next_Tag_Component (Tag_Comp);
1437 -- Start of processing for Collect_Interface_Components
1440 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1441 and then Is_Tagged_Type (Tagged_Type));
1443 Components_List := New_Elmt_List;
1444 Collect (Tagged_Type);
1445 end Collect_Interface_Components;
1447 -----------------------------
1448 -- Collect_Interfaces_Info --
1449 -----------------------------
1451 procedure Collect_Interfaces_Info
1453 Ifaces_List : out Elist_Id;
1454 Components_List : out Elist_Id;
1455 Tags_List : out Elist_Id)
1457 Comps_List : Elist_Id;
1458 Comp_Elmt : Elmt_Id;
1459 Comp_Iface : Entity_Id;
1460 Iface_Elmt : Elmt_Id;
1463 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1464 -- Search for the secondary tag associated with the interface type
1465 -- Iface that is implemented by T.
1471 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1475 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1477 and then Ekind (Node (ADT)) = E_Constant
1478 and then Related_Type (Node (ADT)) /= Iface
1480 -- Skip the secondary dispatch tables of Iface
1488 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1492 -- Start of processing for Collect_Interfaces_Info
1495 Collect_Interfaces (T, Ifaces_List);
1496 Collect_Interface_Components (T, Comps_List);
1498 -- Search for the record component and tag associated with each
1499 -- interface type of T.
1501 Components_List := New_Elmt_List;
1502 Tags_List := New_Elmt_List;
1504 Iface_Elmt := First_Elmt (Ifaces_List);
1505 while Present (Iface_Elmt) loop
1506 Iface := Node (Iface_Elmt);
1508 -- Associate the primary tag component and the primary dispatch table
1509 -- with all the interfaces that are parents of T
1511 if Is_Ancestor (Iface, T) then
1512 Append_Elmt (First_Tag_Component (T), Components_List);
1513 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1515 -- Otherwise search for the tag component and secondary dispatch
1519 Comp_Elmt := First_Elmt (Comps_List);
1520 while Present (Comp_Elmt) loop
1521 Comp_Iface := Related_Type (Node (Comp_Elmt));
1523 if Comp_Iface = Iface
1524 or else Is_Ancestor (Iface, Comp_Iface)
1526 Append_Elmt (Node (Comp_Elmt), Components_List);
1527 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1531 Next_Elmt (Comp_Elmt);
1533 pragma Assert (Present (Comp_Elmt));
1536 Next_Elmt (Iface_Elmt);
1538 end Collect_Interfaces_Info;
1540 ----------------------------------
1541 -- Collect_Primitive_Operations --
1542 ----------------------------------
1544 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1545 B_Type : constant Entity_Id := Base_Type (T);
1546 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1547 B_Scope : Entity_Id := Scope (B_Type);
1551 Formal_Derived : Boolean := False;
1555 -- For tagged types, the primitive operations are collected as they
1556 -- are declared, and held in an explicit list which is simply returned.
1558 if Is_Tagged_Type (B_Type) then
1559 return Primitive_Operations (B_Type);
1561 -- An untagged generic type that is a derived type inherits the
1562 -- primitive operations of its parent type. Other formal types only
1563 -- have predefined operators, which are not explicitly represented.
1565 elsif Is_Generic_Type (B_Type) then
1566 if Nkind (B_Decl) = N_Formal_Type_Declaration
1567 and then Nkind (Formal_Type_Definition (B_Decl))
1568 = N_Formal_Derived_Type_Definition
1570 Formal_Derived := True;
1572 return New_Elmt_List;
1576 Op_List := New_Elmt_List;
1578 if B_Scope = Standard_Standard then
1579 if B_Type = Standard_String then
1580 Append_Elmt (Standard_Op_Concat, Op_List);
1582 elsif B_Type = Standard_Wide_String then
1583 Append_Elmt (Standard_Op_Concatw, Op_List);
1589 elsif (Is_Package_Or_Generic_Package (B_Scope)
1591 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1593 or else Is_Derived_Type (B_Type)
1595 -- The primitive operations appear after the base type, except
1596 -- if the derivation happens within the private part of B_Scope
1597 -- and the type is a private type, in which case both the type
1598 -- and some primitive operations may appear before the base
1599 -- type, and the list of candidates starts after the type.
1601 if In_Open_Scopes (B_Scope)
1602 and then Scope (T) = B_Scope
1603 and then In_Private_Part (B_Scope)
1605 Id := Next_Entity (T);
1607 Id := Next_Entity (B_Type);
1610 while Present (Id) loop
1612 -- Note that generic formal subprograms are not
1613 -- considered to be primitive operations and thus
1614 -- are never inherited.
1616 if Is_Overloadable (Id)
1617 and then Nkind (Parent (Parent (Id)))
1618 not in N_Formal_Subprogram_Declaration
1622 if Base_Type (Etype (Id)) = B_Type then
1625 Formal := First_Formal (Id);
1626 while Present (Formal) loop
1627 if Base_Type (Etype (Formal)) = B_Type then
1631 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1633 (Designated_Type (Etype (Formal))) = B_Type
1639 Next_Formal (Formal);
1643 -- For a formal derived type, the only primitives are the
1644 -- ones inherited from the parent type. Operations appearing
1645 -- in the package declaration are not primitive for it.
1648 and then (not Formal_Derived
1649 or else Present (Alias (Id)))
1651 Append_Elmt (Id, Op_List);
1657 -- For a type declared in System, some of its operations
1658 -- may appear in the target-specific extension to System.
1661 and then Chars (B_Scope) = Name_System
1662 and then Scope (B_Scope) = Standard_Standard
1663 and then Present_System_Aux
1665 B_Scope := System_Aux_Id;
1666 Id := First_Entity (System_Aux_Id);
1672 end Collect_Primitive_Operations;
1674 -----------------------------------
1675 -- Compile_Time_Constraint_Error --
1676 -----------------------------------
1678 function Compile_Time_Constraint_Error
1681 Ent : Entity_Id := Empty;
1682 Loc : Source_Ptr := No_Location;
1683 Warn : Boolean := False) return Node_Id
1685 Msgc : String (1 .. Msg'Length + 2);
1686 -- Copy of message, with room for possible ? and ! at end
1696 -- A static constraint error in an instance body is not a fatal error.
1697 -- we choose to inhibit the message altogether, because there is no
1698 -- obvious node (for now) on which to post it. On the other hand the
1699 -- offending node must be replaced with a constraint_error in any case.
1701 -- No messages are generated if we already posted an error on this node
1703 if not Error_Posted (N) then
1704 if Loc /= No_Location then
1710 Msgc (1 .. Msg'Length) := Msg;
1713 -- Message is a warning, even in Ada 95 case
1715 if Msg (Msg'Last) = '?' then
1718 -- In Ada 83, all messages are warnings. In the private part and
1719 -- the body of an instance, constraint_checks are only warnings.
1720 -- We also make this a warning if the Warn parameter is set.
1723 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1729 elsif In_Instance_Not_Visible then
1734 -- Otherwise we have a real error message (Ada 95 static case)
1735 -- and we make this an unconditional message. Note that in the
1736 -- warning case we do not make the message unconditional, it seems
1737 -- quite reasonable to delete messages like this (about exceptions
1738 -- that will be raised) in dead code.
1746 -- Should we generate a warning? The answer is not quite yes. The
1747 -- very annoying exception occurs in the case of a short circuit
1748 -- operator where the left operand is static and decisive. Climb
1749 -- parents to see if that is the case we have here. Conditional
1750 -- expressions with decisive conditions are a similar situation.
1758 -- And then with False as left operand
1760 if Nkind (P) = N_And_Then
1761 and then Compile_Time_Known_Value (Left_Opnd (P))
1762 and then Is_False (Expr_Value (Left_Opnd (P)))
1767 -- OR ELSE with True as left operand
1769 elsif Nkind (P) = N_Or_Else
1770 and then Compile_Time_Known_Value (Left_Opnd (P))
1771 and then Is_True (Expr_Value (Left_Opnd (P)))
1776 -- Conditional expression
1778 elsif Nkind (P) = N_Conditional_Expression then
1780 Cond : constant Node_Id := First (Expressions (P));
1781 Texp : constant Node_Id := Next (Cond);
1782 Fexp : constant Node_Id := Next (Texp);
1785 if Compile_Time_Known_Value (Cond) then
1787 -- Condition is True and we are in the right operand
1789 if Is_True (Expr_Value (Cond))
1790 and then OldP = Fexp
1795 -- Condition is False and we are in the left operand
1797 elsif Is_False (Expr_Value (Cond))
1798 and then OldP = Texp
1806 -- Special case for component association in aggregates, where
1807 -- we want to keep climbing up to the parent aggregate.
1809 elsif Nkind (P) = N_Component_Association
1810 and then Nkind (Parent (P)) = N_Aggregate
1814 -- Keep going if within subexpression
1817 exit when Nkind (P) not in N_Subexpr;
1822 if Present (Ent) then
1823 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1825 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1829 if Inside_Init_Proc then
1831 ("\?& will be raised for objects of this type",
1832 N, Standard_Constraint_Error, Eloc);
1835 ("\?& will be raised at run time",
1836 N, Standard_Constraint_Error, Eloc);
1841 ("\static expression fails Constraint_Check", Eloc);
1842 Set_Error_Posted (N);
1848 end Compile_Time_Constraint_Error;
1850 -----------------------
1851 -- Conditional_Delay --
1852 -----------------------
1854 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1856 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1857 Set_Has_Delayed_Freeze (New_Ent);
1859 end Conditional_Delay;
1861 -------------------------
1862 -- Copy_Parameter_List --
1863 -------------------------
1865 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1866 Loc : constant Source_Ptr := Sloc (Subp_Id);
1871 if No (First_Formal (Subp_Id)) then
1875 Formal := First_Formal (Subp_Id);
1876 while Present (Formal) loop
1878 (Make_Parameter_Specification (Loc,
1879 Defining_Identifier =>
1880 Make_Defining_Identifier (Sloc (Formal),
1881 Chars => Chars (Formal)),
1882 In_Present => In_Present (Parent (Formal)),
1883 Out_Present => Out_Present (Parent (Formal)),
1885 New_Reference_To (Etype (Formal), Loc),
1887 New_Copy_Tree (Expression (Parent (Formal)))),
1890 Next_Formal (Formal);
1895 end Copy_Parameter_List;
1897 --------------------
1898 -- Current_Entity --
1899 --------------------
1901 -- The currently visible definition for a given identifier is the
1902 -- one most chained at the start of the visibility chain, i.e. the
1903 -- one that is referenced by the Node_Id value of the name of the
1904 -- given identifier.
1906 function Current_Entity (N : Node_Id) return Entity_Id is
1908 return Get_Name_Entity_Id (Chars (N));
1911 -----------------------------
1912 -- Current_Entity_In_Scope --
1913 -----------------------------
1915 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1917 CS : constant Entity_Id := Current_Scope;
1919 Transient_Case : constant Boolean := Scope_Is_Transient;
1922 E := Get_Name_Entity_Id (Chars (N));
1924 and then Scope (E) /= CS
1925 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1931 end Current_Entity_In_Scope;
1937 function Current_Scope return Entity_Id is
1939 if Scope_Stack.Last = -1 then
1940 return Standard_Standard;
1943 C : constant Entity_Id :=
1944 Scope_Stack.Table (Scope_Stack.Last).Entity;
1949 return Standard_Standard;
1955 ------------------------
1956 -- Current_Subprogram --
1957 ------------------------
1959 function Current_Subprogram return Entity_Id is
1960 Scop : constant Entity_Id := Current_Scope;
1962 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1965 return Enclosing_Subprogram (Scop);
1967 end Current_Subprogram;
1969 ---------------------
1970 -- Defining_Entity --
1971 ---------------------
1973 function Defining_Entity (N : Node_Id) return Entity_Id is
1974 K : constant Node_Kind := Nkind (N);
1975 Err : Entity_Id := Empty;
1980 N_Subprogram_Declaration |
1981 N_Abstract_Subprogram_Declaration |
1983 N_Package_Declaration |
1984 N_Subprogram_Renaming_Declaration |
1985 N_Subprogram_Body_Stub |
1986 N_Generic_Subprogram_Declaration |
1987 N_Generic_Package_Declaration |
1988 N_Formal_Subprogram_Declaration
1990 return Defining_Entity (Specification (N));
1993 N_Component_Declaration |
1994 N_Defining_Program_Unit_Name |
1995 N_Discriminant_Specification |
1997 N_Entry_Declaration |
1998 N_Entry_Index_Specification |
1999 N_Exception_Declaration |
2000 N_Exception_Renaming_Declaration |
2001 N_Formal_Object_Declaration |
2002 N_Formal_Package_Declaration |
2003 N_Formal_Type_Declaration |
2004 N_Full_Type_Declaration |
2005 N_Implicit_Label_Declaration |
2006 N_Incomplete_Type_Declaration |
2007 N_Loop_Parameter_Specification |
2008 N_Number_Declaration |
2009 N_Object_Declaration |
2010 N_Object_Renaming_Declaration |
2011 N_Package_Body_Stub |
2012 N_Parameter_Specification |
2013 N_Private_Extension_Declaration |
2014 N_Private_Type_Declaration |
2016 N_Protected_Body_Stub |
2017 N_Protected_Type_Declaration |
2018 N_Single_Protected_Declaration |
2019 N_Single_Task_Declaration |
2020 N_Subtype_Declaration |
2023 N_Task_Type_Declaration
2025 return Defining_Identifier (N);
2028 return Defining_Entity (Proper_Body (N));
2031 N_Function_Instantiation |
2032 N_Function_Specification |
2033 N_Generic_Function_Renaming_Declaration |
2034 N_Generic_Package_Renaming_Declaration |
2035 N_Generic_Procedure_Renaming_Declaration |
2037 N_Package_Instantiation |
2038 N_Package_Renaming_Declaration |
2039 N_Package_Specification |
2040 N_Procedure_Instantiation |
2041 N_Procedure_Specification
2044 Nam : constant Node_Id := Defining_Unit_Name (N);
2047 if Nkind (Nam) in N_Entity then
2050 -- For Error, make up a name and attach to declaration
2051 -- so we can continue semantic analysis
2053 elsif Nam = Error then
2055 Make_Defining_Identifier (Sloc (N),
2056 Chars => New_Internal_Name ('T'));
2057 Set_Defining_Unit_Name (N, Err);
2060 -- If not an entity, get defining identifier
2063 return Defining_Identifier (Nam);
2067 when N_Block_Statement =>
2068 return Entity (Identifier (N));
2071 raise Program_Error;
2074 end Defining_Entity;
2076 --------------------------
2077 -- Denotes_Discriminant --
2078 --------------------------
2080 function Denotes_Discriminant
2082 Check_Concurrent : Boolean := False) return Boolean
2086 if not Is_Entity_Name (N)
2087 or else No (Entity (N))
2094 -- If we are checking for a protected type, the discriminant may have
2095 -- been rewritten as the corresponding discriminal of the original type
2096 -- or of the corresponding concurrent record, depending on whether we
2097 -- are in the spec or body of the protected type.
2099 return Ekind (E) = E_Discriminant
2102 and then Ekind (E) = E_In_Parameter
2103 and then Present (Discriminal_Link (E))
2105 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2107 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2109 end Denotes_Discriminant;
2111 ----------------------
2112 -- Denotes_Variable --
2113 ----------------------
2115 function Denotes_Variable (N : Node_Id) return Boolean is
2117 return Is_Variable (N) and then Paren_Count (N) = 0;
2118 end Denotes_Variable;
2120 -----------------------------
2121 -- Depends_On_Discriminant --
2122 -----------------------------
2124 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2129 Get_Index_Bounds (N, L, H);
2130 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2131 end Depends_On_Discriminant;
2133 -------------------------
2134 -- Designate_Same_Unit --
2135 -------------------------
2137 function Designate_Same_Unit
2139 Name2 : Node_Id) return Boolean
2141 K1 : constant Node_Kind := Nkind (Name1);
2142 K2 : constant Node_Kind := Nkind (Name2);
2144 function Prefix_Node (N : Node_Id) return Node_Id;
2145 -- Returns the parent unit name node of a defining program unit name
2146 -- or the prefix if N is a selected component or an expanded name.
2148 function Select_Node (N : Node_Id) return Node_Id;
2149 -- Returns the defining identifier node of a defining program unit
2150 -- name or the selector node if N is a selected component or an
2157 function Prefix_Node (N : Node_Id) return Node_Id is
2159 if Nkind (N) = N_Defining_Program_Unit_Name then
2171 function Select_Node (N : Node_Id) return Node_Id is
2173 if Nkind (N) = N_Defining_Program_Unit_Name then
2174 return Defining_Identifier (N);
2177 return Selector_Name (N);
2181 -- Start of processing for Designate_Next_Unit
2184 if (K1 = N_Identifier or else
2185 K1 = N_Defining_Identifier)
2187 (K2 = N_Identifier or else
2188 K2 = N_Defining_Identifier)
2190 return Chars (Name1) = Chars (Name2);
2193 (K1 = N_Expanded_Name or else
2194 K1 = N_Selected_Component or else
2195 K1 = N_Defining_Program_Unit_Name)
2197 (K2 = N_Expanded_Name or else
2198 K2 = N_Selected_Component or else
2199 K2 = N_Defining_Program_Unit_Name)
2202 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2204 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2209 end Designate_Same_Unit;
2211 ----------------------------
2212 -- Enclosing_Generic_Body --
2213 ----------------------------
2215 function Enclosing_Generic_Body
2216 (N : Node_Id) return Node_Id
2224 while Present (P) loop
2225 if Nkind (P) = N_Package_Body
2226 or else Nkind (P) = N_Subprogram_Body
2228 Spec := Corresponding_Spec (P);
2230 if Present (Spec) then
2231 Decl := Unit_Declaration_Node (Spec);
2233 if Nkind (Decl) = N_Generic_Package_Declaration
2234 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2245 end Enclosing_Generic_Body;
2247 ----------------------------
2248 -- Enclosing_Generic_Unit --
2249 ----------------------------
2251 function Enclosing_Generic_Unit
2252 (N : Node_Id) return Node_Id
2260 while Present (P) loop
2261 if Nkind (P) = N_Generic_Package_Declaration
2262 or else Nkind (P) = N_Generic_Subprogram_Declaration
2266 elsif Nkind (P) = N_Package_Body
2267 or else Nkind (P) = N_Subprogram_Body
2269 Spec := Corresponding_Spec (P);
2271 if Present (Spec) then
2272 Decl := Unit_Declaration_Node (Spec);
2274 if Nkind (Decl) = N_Generic_Package_Declaration
2275 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2286 end Enclosing_Generic_Unit;
2288 -------------------------------
2289 -- Enclosing_Lib_Unit_Entity --
2290 -------------------------------
2292 function Enclosing_Lib_Unit_Entity return Entity_Id is
2293 Unit_Entity : Entity_Id;
2296 -- Look for enclosing library unit entity by following scope links.
2297 -- Equivalent to, but faster than indexing through the scope stack.
2299 Unit_Entity := Current_Scope;
2300 while (Present (Scope (Unit_Entity))
2301 and then Scope (Unit_Entity) /= Standard_Standard)
2302 and not Is_Child_Unit (Unit_Entity)
2304 Unit_Entity := Scope (Unit_Entity);
2308 end Enclosing_Lib_Unit_Entity;
2310 -----------------------------
2311 -- Enclosing_Lib_Unit_Node --
2312 -----------------------------
2314 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2315 Current_Node : Node_Id;
2319 while Present (Current_Node)
2320 and then Nkind (Current_Node) /= N_Compilation_Unit
2322 Current_Node := Parent (Current_Node);
2325 if Nkind (Current_Node) /= N_Compilation_Unit then
2329 return Current_Node;
2330 end Enclosing_Lib_Unit_Node;
2332 --------------------------
2333 -- Enclosing_Subprogram --
2334 --------------------------
2336 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2337 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2340 if Dynamic_Scope = Standard_Standard then
2343 elsif Dynamic_Scope = Empty then
2346 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2347 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2349 elsif Ekind (Dynamic_Scope) = E_Block
2350 or else Ekind (Dynamic_Scope) = E_Return_Statement
2352 return Enclosing_Subprogram (Dynamic_Scope);
2354 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2355 return Get_Task_Body_Procedure (Dynamic_Scope);
2357 elsif Convention (Dynamic_Scope) = Convention_Protected then
2358 return Protected_Body_Subprogram (Dynamic_Scope);
2361 return Dynamic_Scope;
2363 end Enclosing_Subprogram;
2365 ------------------------
2366 -- Ensure_Freeze_Node --
2367 ------------------------
2369 procedure Ensure_Freeze_Node (E : Entity_Id) is
2373 if No (Freeze_Node (E)) then
2374 FN := Make_Freeze_Entity (Sloc (E));
2375 Set_Has_Delayed_Freeze (E);
2376 Set_Freeze_Node (E, FN);
2377 Set_Access_Types_To_Process (FN, No_Elist);
2378 Set_TSS_Elist (FN, No_Elist);
2381 end Ensure_Freeze_Node;
2387 procedure Enter_Name (Def_Id : Entity_Id) is
2388 C : constant Entity_Id := Current_Entity (Def_Id);
2389 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2390 S : constant Entity_Id := Current_Scope;
2393 Generate_Definition (Def_Id);
2395 -- Add new name to current scope declarations. Check for duplicate
2396 -- declaration, which may or may not be a genuine error.
2400 -- Case of previous entity entered because of a missing declaration
2401 -- or else a bad subtype indication. Best is to use the new entity,
2402 -- and make the previous one invisible.
2404 if Etype (E) = Any_Type then
2405 Set_Is_Immediately_Visible (E, False);
2407 -- Case of renaming declaration constructed for package instances.
2408 -- if there is an explicit declaration with the same identifier,
2409 -- the renaming is not immediately visible any longer, but remains
2410 -- visible through selected component notation.
2412 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2413 and then not Comes_From_Source (E)
2415 Set_Is_Immediately_Visible (E, False);
2417 -- The new entity may be the package renaming, which has the same
2418 -- same name as a generic formal which has been seen already.
2420 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2421 and then not Comes_From_Source (Def_Id)
2423 Set_Is_Immediately_Visible (E, False);
2425 -- For a fat pointer corresponding to a remote access to subprogram,
2426 -- we use the same identifier as the RAS type, so that the proper
2427 -- name appears in the stub. This type is only retrieved through
2428 -- the RAS type and never by visibility, and is not added to the
2429 -- visibility list (see below).
2431 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2432 and then Present (Corresponding_Remote_Type (Def_Id))
2436 -- A controller component for a type extension overrides the
2437 -- inherited component.
2439 elsif Chars (E) = Name_uController then
2442 -- Case of an implicit operation or derived literal. The new entity
2443 -- hides the implicit one, which is removed from all visibility,
2444 -- i.e. the entity list of its scope, and homonym chain of its name.
2446 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2447 or else Is_Internal (E)
2451 Prev_Vis : Entity_Id;
2452 Decl : constant Node_Id := Parent (E);
2455 -- If E is an implicit declaration, it cannot be the first
2456 -- entity in the scope.
2458 Prev := First_Entity (Current_Scope);
2459 while Present (Prev)
2460 and then Next_Entity (Prev) /= E
2467 -- If E is not on the entity chain of the current scope,
2468 -- it is an implicit declaration in the generic formal
2469 -- part of a generic subprogram. When analyzing the body,
2470 -- the generic formals are visible but not on the entity
2471 -- chain of the subprogram. The new entity will become
2472 -- the visible one in the body.
2475 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2479 Set_Next_Entity (Prev, Next_Entity (E));
2481 if No (Next_Entity (Prev)) then
2482 Set_Last_Entity (Current_Scope, Prev);
2485 if E = Current_Entity (E) then
2489 Prev_Vis := Current_Entity (E);
2490 while Homonym (Prev_Vis) /= E loop
2491 Prev_Vis := Homonym (Prev_Vis);
2495 if Present (Prev_Vis) then
2497 -- Skip E in the visibility chain
2499 Set_Homonym (Prev_Vis, Homonym (E));
2502 Set_Name_Entity_Id (Chars (E), Homonym (E));
2507 -- This section of code could use a comment ???
2509 elsif Present (Etype (E))
2510 and then Is_Concurrent_Type (Etype (E))
2515 -- If the homograph is a protected component renaming, it should not
2516 -- be hiding the current entity. Such renamings are treated as weak
2519 elsif Is_Prival (E) then
2520 Set_Is_Immediately_Visible (E, False);
2522 -- In this case the current entity is a protected component renaming.
2523 -- Perform minimal decoration by setting the scope and return since
2524 -- the prival should not be hiding other visible entities.
2526 elsif Is_Prival (Def_Id) then
2527 Set_Scope (Def_Id, Current_Scope);
2530 -- Analogous to privals, the discriminal generated for an entry
2531 -- index parameter acts as a weak declaration. Perform minimal
2532 -- decoration to avoid bogus errors.
2534 elsif Is_Discriminal (Def_Id)
2535 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2537 Set_Scope (Def_Id, Current_Scope);
2540 -- In the body or private part of an instance, a type extension
2541 -- may introduce a component with the same name as that of an
2542 -- actual. The legality rule is not enforced, but the semantics
2543 -- of the full type with two components of the same name are not
2544 -- clear at this point ???
2546 elsif In_Instance_Not_Visible then
2549 -- When compiling a package body, some child units may have become
2550 -- visible. They cannot conflict with local entities that hide them.
2552 elsif Is_Child_Unit (E)
2553 and then In_Open_Scopes (Scope (E))
2554 and then not Is_Immediately_Visible (E)
2558 -- Conversely, with front-end inlining we may compile the parent
2559 -- body first, and a child unit subsequently. The context is now
2560 -- the parent spec, and body entities are not visible.
2562 elsif Is_Child_Unit (Def_Id)
2563 and then Is_Package_Body_Entity (E)
2564 and then not In_Package_Body (Current_Scope)
2568 -- Case of genuine duplicate declaration
2571 Error_Msg_Sloc := Sloc (E);
2573 -- If the previous declaration is an incomplete type declaration
2574 -- this may be an attempt to complete it with a private type.
2575 -- The following avoids confusing cascaded errors.
2577 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2578 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2581 ("incomplete type cannot be completed with a private " &
2582 "declaration", Parent (Def_Id));
2583 Set_Is_Immediately_Visible (E, False);
2584 Set_Full_View (E, Def_Id);
2586 -- An inherited component of a record conflicts with a new
2587 -- discriminant. The discriminant is inserted first in the scope,
2588 -- but the error should be posted on it, not on the component.
2590 elsif Ekind (E) = E_Discriminant
2591 and then Present (Scope (Def_Id))
2592 and then Scope (Def_Id) /= Current_Scope
2594 Error_Msg_Sloc := Sloc (Def_Id);
2595 Error_Msg_N ("& conflicts with declaration#", E);
2598 -- If the name of the unit appears in its own context clause,
2599 -- a dummy package with the name has already been created, and
2600 -- the error emitted. Try to continue quietly.
2602 elsif Error_Posted (E)
2603 and then Sloc (E) = No_Location
2604 and then Nkind (Parent (E)) = N_Package_Specification
2605 and then Current_Scope = Standard_Standard
2607 Set_Scope (Def_Id, Current_Scope);
2611 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2613 -- Avoid cascaded messages with duplicate components in
2616 if Ekind (E) = E_Component
2617 or else Ekind (E) = E_Discriminant
2623 if Nkind (Parent (Parent (Def_Id))) =
2624 N_Generic_Subprogram_Declaration
2626 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2628 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2631 -- If entity is in standard, then we are in trouble, because
2632 -- it means that we have a library package with a duplicated
2633 -- name. That's hard to recover from, so abort!
2635 if S = Standard_Standard then
2636 raise Unrecoverable_Error;
2638 -- Otherwise we continue with the declaration. Having two
2639 -- identical declarations should not cause us too much trouble!
2647 -- If we fall through, declaration is OK , or OK enough to continue
2649 -- If Def_Id is a discriminant or a record component we are in the
2650 -- midst of inheriting components in a derived record definition.
2651 -- Preserve their Ekind and Etype.
2653 if Ekind (Def_Id) = E_Discriminant
2654 or else Ekind (Def_Id) = E_Component
2658 -- If a type is already set, leave it alone (happens whey a type
2659 -- declaration is reanalyzed following a call to the optimizer)
2661 elsif Present (Etype (Def_Id)) then
2664 -- Otherwise, the kind E_Void insures that premature uses of the entity
2665 -- will be detected. Any_Type insures that no cascaded errors will occur
2668 Set_Ekind (Def_Id, E_Void);
2669 Set_Etype (Def_Id, Any_Type);
2672 -- Inherited discriminants and components in derived record types are
2673 -- immediately visible. Itypes are not.
2675 if Ekind (Def_Id) = E_Discriminant
2676 or else Ekind (Def_Id) = E_Component
2677 or else (No (Corresponding_Remote_Type (Def_Id))
2678 and then not Is_Itype (Def_Id))
2680 Set_Is_Immediately_Visible (Def_Id);
2681 Set_Current_Entity (Def_Id);
2684 Set_Homonym (Def_Id, C);
2685 Append_Entity (Def_Id, S);
2686 Set_Public_Status (Def_Id);
2688 -- Warn if new entity hides an old one
2690 if Warn_On_Hiding and then Present (C)
2692 -- Don't warn for record components since they always have a well
2693 -- defined scope which does not confuse other uses. Note that in
2694 -- some cases, Ekind has not been set yet.
2696 and then Ekind (C) /= E_Component
2697 and then Ekind (C) /= E_Discriminant
2698 and then Nkind (Parent (C)) /= N_Component_Declaration
2699 and then Ekind (Def_Id) /= E_Component
2700 and then Ekind (Def_Id) /= E_Discriminant
2701 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2703 -- Don't warn for one character variables. It is too common to use
2704 -- such variables as locals and will just cause too many false hits.
2706 and then Length_Of_Name (Chars (C)) /= 1
2708 -- Don't warn for non-source entities
2710 and then Comes_From_Source (C)
2711 and then Comes_From_Source (Def_Id)
2713 -- Don't warn unless entity in question is in extended main source
2715 and then In_Extended_Main_Source_Unit (Def_Id)
2717 -- Finally, the hidden entity must be either immediately visible
2718 -- or use visible (from a used package)
2721 (Is_Immediately_Visible (C)
2723 Is_Potentially_Use_Visible (C))
2725 Error_Msg_Sloc := Sloc (C);
2726 Error_Msg_N ("declaration hides &#?", Def_Id);
2730 --------------------------
2731 -- Explain_Limited_Type --
2732 --------------------------
2734 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2738 -- For array, component type must be limited
2740 if Is_Array_Type (T) then
2741 Error_Msg_Node_2 := T;
2743 ("\component type& of type& is limited", N, Component_Type (T));
2744 Explain_Limited_Type (Component_Type (T), N);
2746 elsif Is_Record_Type (T) then
2748 -- No need for extra messages if explicit limited record
2750 if Is_Limited_Record (Base_Type (T)) then
2754 -- Otherwise find a limited component. Check only components that
2755 -- come from source, or inherited components that appear in the
2756 -- source of the ancestor.
2758 C := First_Component (T);
2759 while Present (C) loop
2760 if Is_Limited_Type (Etype (C))
2762 (Comes_From_Source (C)
2764 (Present (Original_Record_Component (C))
2766 Comes_From_Source (Original_Record_Component (C))))
2768 Error_Msg_Node_2 := T;
2769 Error_Msg_NE ("\component& of type& has limited type", N, C);
2770 Explain_Limited_Type (Etype (C), N);
2777 -- The type may be declared explicitly limited, even if no component
2778 -- of it is limited, in which case we fall out of the loop.
2781 end Explain_Limited_Type;
2787 procedure Find_Actual
2789 Formal : out Entity_Id;
2792 Parnt : constant Node_Id := Parent (N);
2796 if (Nkind (Parnt) = N_Indexed_Component
2798 Nkind (Parnt) = N_Selected_Component)
2799 and then N = Prefix (Parnt)
2801 Find_Actual (Parnt, Formal, Call);
2804 elsif Nkind (Parnt) = N_Parameter_Association
2805 and then N = Explicit_Actual_Parameter (Parnt)
2807 Call := Parent (Parnt);
2809 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2818 -- If we have a call to a subprogram look for the parameter. Note that
2819 -- we exclude overloaded calls, since we don't know enough to be sure
2820 -- of giving the right answer in this case.
2822 if Is_Entity_Name (Name (Call))
2823 and then Present (Entity (Name (Call)))
2824 and then Is_Overloadable (Entity (Name (Call)))
2825 and then not Is_Overloaded (Name (Call))
2827 -- Fall here if we are definitely a parameter
2829 Actual := First_Actual (Call);
2830 Formal := First_Formal (Entity (Name (Call)));
2831 while Present (Formal) and then Present (Actual) loop
2835 Actual := Next_Actual (Actual);
2836 Formal := Next_Formal (Formal);
2841 -- Fall through here if we did not find matching actual
2847 -------------------------------------
2848 -- Find_Corresponding_Discriminant --
2849 -------------------------------------
2851 function Find_Corresponding_Discriminant
2853 Typ : Entity_Id) return Entity_Id
2855 Par_Disc : Entity_Id;
2856 Old_Disc : Entity_Id;
2857 New_Disc : Entity_Id;
2860 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2862 -- The original type may currently be private, and the discriminant
2863 -- only appear on its full view.
2865 if Is_Private_Type (Scope (Par_Disc))
2866 and then not Has_Discriminants (Scope (Par_Disc))
2867 and then Present (Full_View (Scope (Par_Disc)))
2869 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2871 Old_Disc := First_Discriminant (Scope (Par_Disc));
2874 if Is_Class_Wide_Type (Typ) then
2875 New_Disc := First_Discriminant (Root_Type (Typ));
2877 New_Disc := First_Discriminant (Typ);
2880 while Present (Old_Disc) and then Present (New_Disc) loop
2881 if Old_Disc = Par_Disc then
2884 Next_Discriminant (Old_Disc);
2885 Next_Discriminant (New_Disc);
2889 -- Should always find it
2891 raise Program_Error;
2892 end Find_Corresponding_Discriminant;
2894 --------------------------
2895 -- Find_Overlaid_Object --
2896 --------------------------
2898 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2902 -- We are looking for one of the two following forms:
2904 -- for X'Address use Y'Address
2908 -- Const : constant Address := expr;
2910 -- for X'Address use Const;
2912 -- In the second case, the expr is either Y'Address, or recursively a
2913 -- constant that eventually references Y'Address.
2915 if Nkind (N) = N_Attribute_Definition_Clause
2916 and then Chars (N) = Name_Address
2918 -- This loop checks the form of the expression for Y'Address where Y
2919 -- is an object entity name. The first loop checks the original
2920 -- expression in the attribute definition clause. Subsequent loops
2921 -- check referenced constants.
2923 Expr := Expression (N);
2925 -- Check for Y'Address where Y is an object entity
2927 if Nkind (Expr) = N_Attribute_Reference
2928 and then Attribute_Name (Expr) = Name_Address
2929 and then Is_Entity_Name (Prefix (Expr))
2930 and then Is_Object (Entity (Prefix (Expr)))
2932 return Entity (Prefix (Expr));
2934 -- Check for Const where Const is a constant entity
2936 elsif Is_Entity_Name (Expr)
2937 and then Ekind (Entity (Expr)) = E_Constant
2939 Expr := Constant_Value (Entity (Expr));
2941 -- Anything else does not need checking
2950 end Find_Overlaid_Object;
2952 -------------------------
2953 -- Find_Parameter_Type --
2954 -------------------------
2956 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2958 if Nkind (Param) /= N_Parameter_Specification then
2961 -- For an access parameter, obtain the type from the formal entity
2962 -- itself, because access to subprogram nodes do not carry a type.
2963 -- Shouldn't we always use the formal entity ???
2965 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
2966 return Etype (Defining_Identifier (Param));
2969 return Etype (Parameter_Type (Param));
2971 end Find_Parameter_Type;
2973 -----------------------------
2974 -- Find_Static_Alternative --
2975 -----------------------------
2977 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2978 Expr : constant Node_Id := Expression (N);
2979 Val : constant Uint := Expr_Value (Expr);
2984 Alt := First (Alternatives (N));
2987 if Nkind (Alt) /= N_Pragma then
2988 Choice := First (Discrete_Choices (Alt));
2989 while Present (Choice) loop
2991 -- Others choice, always matches
2993 if Nkind (Choice) = N_Others_Choice then
2996 -- Range, check if value is in the range
2998 elsif Nkind (Choice) = N_Range then
3000 Val >= Expr_Value (Low_Bound (Choice))
3002 Val <= Expr_Value (High_Bound (Choice));
3004 -- Choice is a subtype name. Note that we know it must
3005 -- be a static subtype, since otherwise it would have
3006 -- been diagnosed as illegal.
3008 elsif Is_Entity_Name (Choice)
3009 and then Is_Type (Entity (Choice))
3011 exit Search when Is_In_Range (Expr, Etype (Choice),
3012 Assume_Valid => False);
3014 -- Choice is a subtype indication
3016 elsif Nkind (Choice) = N_Subtype_Indication then
3018 C : constant Node_Id := Constraint (Choice);
3019 R : constant Node_Id := Range_Expression (C);
3023 Val >= Expr_Value (Low_Bound (R))
3025 Val <= Expr_Value (High_Bound (R));
3028 -- Choice is a simple expression
3031 exit Search when Val = Expr_Value (Choice);
3039 pragma Assert (Present (Alt));
3042 -- The above loop *must* terminate by finding a match, since
3043 -- we know the case statement is valid, and the value of the
3044 -- expression is known at compile time. When we fall out of
3045 -- the loop, Alt points to the alternative that we know will
3046 -- be selected at run time.
3049 end Find_Static_Alternative;
3055 function First_Actual (Node : Node_Id) return Node_Id is
3059 if No (Parameter_Associations (Node)) then
3063 N := First (Parameter_Associations (Node));
3065 if Nkind (N) = N_Parameter_Association then
3066 return First_Named_Actual (Node);
3072 -------------------------
3073 -- Full_Qualified_Name --
3074 -------------------------
3076 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3078 pragma Warnings (Off, Res);
3080 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3081 -- Compute recursively the qualified name without NUL at the end
3083 ----------------------------------
3084 -- Internal_Full_Qualified_Name --
3085 ----------------------------------
3087 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3088 Ent : Entity_Id := E;
3089 Parent_Name : String_Id := No_String;
3092 -- Deals properly with child units
3094 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3095 Ent := Defining_Identifier (Ent);
3098 -- Compute qualification recursively (only "Standard" has no scope)
3100 if Present (Scope (Scope (Ent))) then
3101 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3104 -- Every entity should have a name except some expanded blocks
3105 -- don't bother about those.
3107 if Chars (Ent) = No_Name then
3111 -- Add a period between Name and qualification
3113 if Parent_Name /= No_String then
3114 Start_String (Parent_Name);
3115 Store_String_Char (Get_Char_Code ('.'));
3121 -- Generates the entity name in upper case
3123 Get_Decoded_Name_String (Chars (Ent));
3125 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3127 end Internal_Full_Qualified_Name;
3129 -- Start of processing for Full_Qualified_Name
3132 Res := Internal_Full_Qualified_Name (E);
3133 Store_String_Char (Get_Char_Code (ASCII.NUL));
3135 end Full_Qualified_Name;
3137 -----------------------
3138 -- Gather_Components --
3139 -----------------------
3141 procedure Gather_Components
3143 Comp_List : Node_Id;
3144 Governed_By : List_Id;
3146 Report_Errors : out Boolean)
3150 Discrete_Choice : Node_Id;
3151 Comp_Item : Node_Id;
3153 Discrim : Entity_Id;
3154 Discrim_Name : Node_Id;
3155 Discrim_Value : Node_Id;
3158 Report_Errors := False;
3160 if No (Comp_List) or else Null_Present (Comp_List) then
3163 elsif Present (Component_Items (Comp_List)) then
3164 Comp_Item := First (Component_Items (Comp_List));
3170 while Present (Comp_Item) loop
3172 -- Skip the tag of a tagged record, the interface tags, as well
3173 -- as all items that are not user components (anonymous types,
3174 -- rep clauses, Parent field, controller field).
3176 if Nkind (Comp_Item) = N_Component_Declaration then
3178 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3180 if not Is_Tag (Comp)
3181 and then Chars (Comp) /= Name_uParent
3182 and then Chars (Comp) /= Name_uController
3184 Append_Elmt (Comp, Into);
3192 if No (Variant_Part (Comp_List)) then
3195 Discrim_Name := Name (Variant_Part (Comp_List));
3196 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3199 -- Look for the discriminant that governs this variant part.
3200 -- The discriminant *must* be in the Governed_By List
3202 Assoc := First (Governed_By);
3203 Find_Constraint : loop
3204 Discrim := First (Choices (Assoc));
3205 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3206 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3208 Chars (Corresponding_Discriminant (Entity (Discrim)))
3209 = Chars (Discrim_Name))
3210 or else Chars (Original_Record_Component (Entity (Discrim)))
3211 = Chars (Discrim_Name);
3213 if No (Next (Assoc)) then
3214 if not Is_Constrained (Typ)
3215 and then Is_Derived_Type (Typ)
3216 and then Present (Stored_Constraint (Typ))
3218 -- If the type is a tagged type with inherited discriminants,
3219 -- use the stored constraint on the parent in order to find
3220 -- the values of discriminants that are otherwise hidden by an
3221 -- explicit constraint. Renamed discriminants are handled in
3224 -- If several parent discriminants are renamed by a single
3225 -- discriminant of the derived type, the call to obtain the
3226 -- Corresponding_Discriminant field only retrieves the last
3227 -- of them. We recover the constraint on the others from the
3228 -- Stored_Constraint as well.
3235 D := First_Discriminant (Etype (Typ));
3236 C := First_Elmt (Stored_Constraint (Typ));
3237 while Present (D) and then Present (C) loop
3238 if Chars (Discrim_Name) = Chars (D) then
3239 if Is_Entity_Name (Node (C))
3240 and then Entity (Node (C)) = Entity (Discrim)
3242 -- D is renamed by Discrim, whose value is given in
3249 Make_Component_Association (Sloc (Typ),
3251 (New_Occurrence_Of (D, Sloc (Typ))),
3252 Duplicate_Subexpr_No_Checks (Node (C)));
3254 exit Find_Constraint;
3257 Next_Discriminant (D);
3264 if No (Next (Assoc)) then
3265 Error_Msg_NE (" missing value for discriminant&",
3266 First (Governed_By), Discrim_Name);
3267 Report_Errors := True;
3272 end loop Find_Constraint;
3274 Discrim_Value := Expression (Assoc);
3276 if not Is_OK_Static_Expression (Discrim_Value) then
3278 ("value for discriminant & must be static!",
3279 Discrim_Value, Discrim);
3280 Why_Not_Static (Discrim_Value);
3281 Report_Errors := True;
3285 Search_For_Discriminant_Value : declare
3291 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3294 Find_Discrete_Value : while Present (Variant) loop
3295 Discrete_Choice := First (Discrete_Choices (Variant));
3296 while Present (Discrete_Choice) loop
3298 exit Find_Discrete_Value when
3299 Nkind (Discrete_Choice) = N_Others_Choice;
3301 Get_Index_Bounds (Discrete_Choice, Low, High);
3303 UI_Low := Expr_Value (Low);
3304 UI_High := Expr_Value (High);
3306 exit Find_Discrete_Value when
3307 UI_Low <= UI_Discrim_Value
3309 UI_High >= UI_Discrim_Value;
3311 Next (Discrete_Choice);
3314 Next_Non_Pragma (Variant);
3315 end loop Find_Discrete_Value;
3316 end Search_For_Discriminant_Value;
3318 if No (Variant) then
3320 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3321 Report_Errors := True;
3325 -- If we have found the corresponding choice, recursively add its
3326 -- components to the Into list.
3328 Gather_Components (Empty,
3329 Component_List (Variant), Governed_By, Into, Report_Errors);
3330 end Gather_Components;
3332 ------------------------
3333 -- Get_Actual_Subtype --
3334 ------------------------
3336 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3337 Typ : constant Entity_Id := Etype (N);
3338 Utyp : Entity_Id := Underlying_Type (Typ);
3347 -- If what we have is an identifier that references a subprogram
3348 -- formal, or a variable or constant object, then we get the actual
3349 -- subtype from the referenced entity if one has been built.
3351 if Nkind (N) = N_Identifier
3353 (Is_Formal (Entity (N))
3354 or else Ekind (Entity (N)) = E_Constant
3355 or else Ekind (Entity (N)) = E_Variable)
3356 and then Present (Actual_Subtype (Entity (N)))
3358 return Actual_Subtype (Entity (N));
3360 -- Actual subtype of unchecked union is always itself. We never need
3361 -- the "real" actual subtype. If we did, we couldn't get it anyway
3362 -- because the discriminant is not available. The restrictions on
3363 -- Unchecked_Union are designed to make sure that this is OK.
3365 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3368 -- Here for the unconstrained case, we must find actual subtype
3369 -- No actual subtype is available, so we must build it on the fly.
3371 -- Checking the type, not the underlying type, for constrainedness
3372 -- seems to be necessary. Maybe all the tests should be on the type???
3374 elsif (not Is_Constrained (Typ))
3375 and then (Is_Array_Type (Utyp)
3376 or else (Is_Record_Type (Utyp)
3377 and then Has_Discriminants (Utyp)))
3378 and then not Has_Unknown_Discriminants (Utyp)
3379 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3381 -- Nothing to do if in spec expression (why not???)
3383 if In_Spec_Expression then
3386 elsif Is_Private_Type (Typ)
3387 and then not Has_Discriminants (Typ)
3389 -- If the type has no discriminants, there is no subtype to
3390 -- build, even if the underlying type is discriminated.
3394 -- Else build the actual subtype
3397 Decl := Build_Actual_Subtype (Typ, N);
3398 Atyp := Defining_Identifier (Decl);
3400 -- If Build_Actual_Subtype generated a new declaration then use it
3404 -- The actual subtype is an Itype, so analyze the declaration,
3405 -- but do not attach it to the tree, to get the type defined.
3407 Set_Parent (Decl, N);
3408 Set_Is_Itype (Atyp);
3409 Analyze (Decl, Suppress => All_Checks);
3410 Set_Associated_Node_For_Itype (Atyp, N);
3411 Set_Has_Delayed_Freeze (Atyp, False);
3413 -- We need to freeze the actual subtype immediately. This is
3414 -- needed, because otherwise this Itype will not get frozen
3415 -- at all, and it is always safe to freeze on creation because
3416 -- any associated types must be frozen at this point.
3418 Freeze_Itype (Atyp, N);
3421 -- Otherwise we did not build a declaration, so return original
3428 -- For all remaining cases, the actual subtype is the same as
3429 -- the nominal type.
3434 end Get_Actual_Subtype;
3436 -------------------------------------
3437 -- Get_Actual_Subtype_If_Available --
3438 -------------------------------------
3440 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3441 Typ : constant Entity_Id := Etype (N);
3444 -- If what we have is an identifier that references a subprogram
3445 -- formal, or a variable or constant object, then we get the actual
3446 -- subtype from the referenced entity if one has been built.
3448 if Nkind (N) = N_Identifier
3450 (Is_Formal (Entity (N))
3451 or else Ekind (Entity (N)) = E_Constant
3452 or else Ekind (Entity (N)) = E_Variable)
3453 and then Present (Actual_Subtype (Entity (N)))
3455 return Actual_Subtype (Entity (N));
3457 -- Otherwise the Etype of N is returned unchanged
3462 end Get_Actual_Subtype_If_Available;
3464 -------------------------------
3465 -- Get_Default_External_Name --
3466 -------------------------------
3468 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3470 Get_Decoded_Name_String (Chars (E));
3472 if Opt.External_Name_Imp_Casing = Uppercase then
3473 Set_Casing (All_Upper_Case);
3475 Set_Casing (All_Lower_Case);
3479 Make_String_Literal (Sloc (E),
3480 Strval => String_From_Name_Buffer);
3481 end Get_Default_External_Name;
3483 ---------------------------
3484 -- Get_Enum_Lit_From_Pos --
3485 ---------------------------
3487 function Get_Enum_Lit_From_Pos
3490 Loc : Source_Ptr) return Node_Id
3495 -- In the case where the literal is of type Character, Wide_Character
3496 -- or Wide_Wide_Character or of a type derived from them, there needs
3497 -- to be some special handling since there is no explicit chain of
3498 -- literals to search. Instead, an N_Character_Literal node is created
3499 -- with the appropriate Char_Code and Chars fields.
3501 if Is_Standard_Character_Type (T) then
3502 Set_Character_Literal_Name (UI_To_CC (Pos));
3504 Make_Character_Literal (Loc,
3506 Char_Literal_Value => Pos);
3508 -- For all other cases, we have a complete table of literals, and
3509 -- we simply iterate through the chain of literal until the one
3510 -- with the desired position value is found.
3514 Lit := First_Literal (Base_Type (T));
3515 for J in 1 .. UI_To_Int (Pos) loop
3519 return New_Occurrence_Of (Lit, Loc);
3521 end Get_Enum_Lit_From_Pos;
3523 ------------------------
3524 -- Get_Generic_Entity --
3525 ------------------------
3527 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3528 Ent : constant Entity_Id := Entity (Name (N));
3530 if Present (Renamed_Object (Ent)) then
3531 return Renamed_Object (Ent);
3535 end Get_Generic_Entity;
3537 ----------------------
3538 -- Get_Index_Bounds --
3539 ----------------------
3541 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3542 Kind : constant Node_Kind := Nkind (N);
3546 if Kind = N_Range then
3548 H := High_Bound (N);
3550 elsif Kind = N_Subtype_Indication then
3551 R := Range_Expression (Constraint (N));
3559 L := Low_Bound (Range_Expression (Constraint (N)));
3560 H := High_Bound (Range_Expression (Constraint (N)));
3563 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3564 if Error_Posted (Scalar_Range (Entity (N))) then
3568 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3569 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3572 L := Low_Bound (Scalar_Range (Entity (N)));
3573 H := High_Bound (Scalar_Range (Entity (N)));
3577 -- N is an expression, indicating a range with one value
3582 end Get_Index_Bounds;
3584 ----------------------------------
3585 -- Get_Library_Unit_Name_string --
3586 ----------------------------------
3588 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3589 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3592 Get_Unit_Name_String (Unit_Name_Id);
3594 -- Remove seven last character (" (spec)" or " (body)")
3596 Name_Len := Name_Len - 7;
3597 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3598 end Get_Library_Unit_Name_String;
3600 ------------------------
3601 -- Get_Name_Entity_Id --
3602 ------------------------
3604 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3606 return Entity_Id (Get_Name_Table_Info (Id));
3607 end Get_Name_Entity_Id;
3613 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3615 return Get_Pragma_Id (Pragma_Name (N));
3618 ---------------------------
3619 -- Get_Referenced_Object --
3620 ---------------------------
3622 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3627 while Is_Entity_Name (R)
3628 and then Present (Renamed_Object (Entity (R)))
3630 R := Renamed_Object (Entity (R));
3634 end Get_Referenced_Object;
3636 ------------------------
3637 -- Get_Renamed_Entity --
3638 ------------------------
3640 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3645 while Present (Renamed_Entity (R)) loop
3646 R := Renamed_Entity (R);
3650 end Get_Renamed_Entity;
3652 -------------------------
3653 -- Get_Subprogram_Body --
3654 -------------------------
3656 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3660 Decl := Unit_Declaration_Node (E);
3662 if Nkind (Decl) = N_Subprogram_Body then
3665 -- The below comment is bad, because it is possible for
3666 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3668 else -- Nkind (Decl) = N_Subprogram_Declaration
3670 if Present (Corresponding_Body (Decl)) then
3671 return Unit_Declaration_Node (Corresponding_Body (Decl));
3673 -- Imported subprogram case
3679 end Get_Subprogram_Body;
3681 ---------------------------
3682 -- Get_Subprogram_Entity --
3683 ---------------------------
3685 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3690 if Nkind (Nod) = N_Accept_Statement then
3691 Nam := Entry_Direct_Name (Nod);
3693 -- For an entry call, the prefix of the call is a selected component.
3694 -- Need additional code for internal calls ???
3696 elsif Nkind (Nod) = N_Entry_Call_Statement then
3697 if Nkind (Name (Nod)) = N_Selected_Component then
3698 Nam := Entity (Selector_Name (Name (Nod)));
3707 if Nkind (Nam) = N_Explicit_Dereference then
3708 Proc := Etype (Prefix (Nam));
3709 elsif Is_Entity_Name (Nam) then
3710 Proc := Entity (Nam);
3715 if Is_Object (Proc) then
3716 Proc := Etype (Proc);
3719 if Ekind (Proc) = E_Access_Subprogram_Type then
3720 Proc := Directly_Designated_Type (Proc);
3723 if not Is_Subprogram (Proc)
3724 and then Ekind (Proc) /= E_Subprogram_Type
3730 end Get_Subprogram_Entity;
3732 -----------------------------
3733 -- Get_Task_Body_Procedure --
3734 -----------------------------
3736 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3738 -- Note: A task type may be the completion of a private type with
3739 -- discriminants. When performing elaboration checks on a task
3740 -- declaration, the current view of the type may be the private one,
3741 -- and the procedure that holds the body of the task is held in its
3744 -- This is an odd function, why not have Task_Body_Procedure do
3745 -- the following digging???
3747 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3748 end Get_Task_Body_Procedure;
3750 -----------------------
3751 -- Has_Access_Values --
3752 -----------------------
3754 function Has_Access_Values (T : Entity_Id) return Boolean is
3755 Typ : constant Entity_Id := Underlying_Type (T);
3758 -- Case of a private type which is not completed yet. This can only
3759 -- happen in the case of a generic format type appearing directly, or
3760 -- as a component of the type to which this function is being applied
3761 -- at the top level. Return False in this case, since we certainly do
3762 -- not know that the type contains access types.
3767 elsif Is_Access_Type (Typ) then
3770 elsif Is_Array_Type (Typ) then
3771 return Has_Access_Values (Component_Type (Typ));
3773 elsif Is_Record_Type (Typ) then
3778 -- Loop to Check components
3780 Comp := First_Component_Or_Discriminant (Typ);
3781 while Present (Comp) loop
3783 -- Check for access component, tag field does not count, even
3784 -- though it is implemented internally using an access type.
3786 if Has_Access_Values (Etype (Comp))
3787 and then Chars (Comp) /= Name_uTag
3792 Next_Component_Or_Discriminant (Comp);
3801 end Has_Access_Values;
3803 ------------------------------
3804 -- Has_Compatible_Alignment --
3805 ------------------------------
3807 function Has_Compatible_Alignment
3809 Expr : Node_Id) return Alignment_Result
3811 function Has_Compatible_Alignment_Internal
3814 Default : Alignment_Result) return Alignment_Result;
3815 -- This is the internal recursive function that actually does the work.
3816 -- There is one additional parameter, which says what the result should
3817 -- be if no alignment information is found, and there is no definite
3818 -- indication of compatible alignments. At the outer level, this is set
3819 -- to Unknown, but for internal recursive calls in the case where types
3820 -- are known to be correct, it is set to Known_Compatible.
3822 ---------------------------------------
3823 -- Has_Compatible_Alignment_Internal --
3824 ---------------------------------------
3826 function Has_Compatible_Alignment_Internal
3829 Default : Alignment_Result) return Alignment_Result
3831 Result : Alignment_Result := Known_Compatible;
3832 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3833 -- Note that once a value of Known_Incompatible is set, it is sticky
3834 -- and does not get changed to Unknown (the value in Result only gets
3835 -- worse as we go along, never better).
3837 procedure Check_Offset (Offs : Uint);
3838 -- Called when Expr is a selected or indexed component with Offs set
3839 -- to resp Component_First_Bit or Component_Size. Checks that if the
3840 -- offset is specified it is compatible with the object alignment
3841 -- requirements. The value in Result is modified accordingly.
3843 procedure Check_Prefix;
3844 -- Checks the prefix recursively in the case where the expression
3845 -- is an indexed or selected component.
3847 procedure Set_Result (R : Alignment_Result);
3848 -- If R represents a worse outcome (unknown instead of known
3849 -- compatible, or known incompatible), then set Result to R.
3855 procedure Check_Offset (Offs : Uint) is
3857 -- Unspecified or zero offset is always OK
3859 if Offs = No_Uint or else Offs = Uint_0 then
3862 -- If we do not know required alignment, any non-zero offset is
3863 -- a potential problem (but certainly may be OK, so result is
3866 elsif Unknown_Alignment (Obj) then
3867 Set_Result (Unknown);
3869 -- If we know the required alignment, see if offset is compatible
3872 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3873 Set_Result (Known_Incompatible);
3882 procedure Check_Prefix is
3884 -- The subtlety here is that in doing a recursive call to check
3885 -- the prefix, we have to decide what to do in the case where we
3886 -- don't find any specific indication of an alignment problem.
3888 -- At the outer level, we normally set Unknown as the result in
3889 -- this case, since we can only set Known_Compatible if we really
3890 -- know that the alignment value is OK, but for the recursive
3891 -- call, in the case where the types match, and we have not
3892 -- specified a peculiar alignment for the object, we are only
3893 -- concerned about suspicious rep clauses, the default case does
3894 -- not affect us, since the compiler will, in the absence of such
3895 -- rep clauses, ensure that the alignment is correct.
3897 if Default = Known_Compatible
3899 (Etype (Obj) = Etype (Expr)
3900 and then (Unknown_Alignment (Obj)
3902 Alignment (Obj) = Alignment (Etype (Obj))))
3905 (Has_Compatible_Alignment_Internal
3906 (Obj, Prefix (Expr), Known_Compatible));
3908 -- In all other cases, we need a full check on the prefix
3912 (Has_Compatible_Alignment_Internal
3913 (Obj, Prefix (Expr), Unknown));
3921 procedure Set_Result (R : Alignment_Result) is
3928 -- Start of processing for Has_Compatible_Alignment_Internal
3931 -- If Expr is a selected component, we must make sure there is no
3932 -- potentially troublesome component clause, and that the record is
3935 if Nkind (Expr) = N_Selected_Component then
3937 -- Packed record always generate unknown alignment
3939 if Is_Packed (Etype (Prefix (Expr))) then
3940 Set_Result (Unknown);
3943 -- Check possible bad component offset and check prefix
3946 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3949 -- If Expr is an indexed component, we must make sure there is no
3950 -- potentially troublesome Component_Size clause and that the array
3951 -- is not bit-packed.
3953 elsif Nkind (Expr) = N_Indexed_Component then
3955 -- Bit packed array always generates unknown alignment
3957 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3958 Set_Result (Unknown);
3961 -- Check possible bad component size and check prefix
3963 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3967 -- Case where we know the alignment of the object
3969 if Known_Alignment (Obj) then
3971 ObjA : constant Uint := Alignment (Obj);
3972 ExpA : Uint := No_Uint;
3973 SizA : Uint := No_Uint;
3976 -- If alignment of Obj is 1, then we are always OK
3979 Set_Result (Known_Compatible);
3981 -- Alignment of Obj is greater than 1, so we need to check
3984 -- See if Expr is an object with known alignment
3986 if Is_Entity_Name (Expr)
3987 and then Known_Alignment (Entity (Expr))
3989 ExpA := Alignment (Entity (Expr));
3991 -- Otherwise, we can use the alignment of the type of
3992 -- Expr given that we already checked for
3993 -- discombobulating rep clauses for the cases of indexed
3994 -- and selected components above.
3996 elsif Known_Alignment (Etype (Expr)) then
3997 ExpA := Alignment (Etype (Expr));
4000 -- If we got an alignment, see if it is acceptable
4002 if ExpA /= No_Uint then
4004 Set_Result (Known_Incompatible);
4007 -- Case of Expr alignment unknown
4010 Set_Result (Default);
4013 -- See if size is given. If so, check that it is not too
4014 -- small for the required alignment.
4015 -- See if Expr is an object with known alignment
4017 if Is_Entity_Name (Expr)
4018 and then Known_Static_Esize (Entity (Expr))
4020 SizA := Esize (Entity (Expr));
4022 -- Otherwise, we check the object size of the Expr type
4024 elsif Known_Static_Esize (Etype (Expr)) then
4025 SizA := Esize (Etype (Expr));
4028 -- If we got a size, see if it is a multiple of the Obj
4029 -- alignment, if not, then the alignment cannot be
4030 -- acceptable, since the size is always a multiple of the
4033 if SizA /= No_Uint then
4034 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4035 Set_Result (Known_Incompatible);
4041 -- If we can't find the result by direct comparison of alignment
4042 -- values, then there is still one case that we can determine known
4043 -- result, and that is when we can determine that the types are the
4044 -- same, and no alignments are specified. Then we known that the
4045 -- alignments are compatible, even if we don't know the alignment
4046 -- value in the front end.
4048 elsif Etype (Obj) = Etype (Expr) then
4050 -- Types are the same, but we have to check for possible size
4051 -- and alignments on the Expr object that may make the alignment
4052 -- different, even though the types are the same.
4054 if Is_Entity_Name (Expr) then
4056 -- First check alignment of the Expr object. Any alignment less
4057 -- than Maximum_Alignment is worrisome since this is the case
4058 -- where we do not know the alignment of Obj.
4060 if Known_Alignment (Entity (Expr))
4062 UI_To_Int (Alignment (Entity (Expr)))
4063 < Ttypes.Maximum_Alignment
4065 Set_Result (Unknown);
4067 -- Now check size of Expr object. Any size that is not an
4068 -- even multiple of Maximum_Alignment is also worrisome
4069 -- since it may cause the alignment of the object to be less
4070 -- than the alignment of the type.
4072 elsif Known_Static_Esize (Entity (Expr))
4074 (UI_To_Int (Esize (Entity (Expr))) mod
4075 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4078 Set_Result (Unknown);
4080 -- Otherwise same type is decisive
4083 Set_Result (Known_Compatible);
4087 -- Another case to deal with is when there is an explicit size or
4088 -- alignment clause when the types are not the same. If so, then the
4089 -- result is Unknown. We don't need to do this test if the Default is
4090 -- Unknown, since that result will be set in any case.
4092 elsif Default /= Unknown
4093 and then (Has_Size_Clause (Etype (Expr))
4095 Has_Alignment_Clause (Etype (Expr)))
4097 Set_Result (Unknown);
4099 -- If no indication found, set default
4102 Set_Result (Default);
4105 -- Return worst result found
4108 end Has_Compatible_Alignment_Internal;
4110 -- Start of processing for Has_Compatible_Alignment
4113 -- If Obj has no specified alignment, then set alignment from the type
4114 -- alignment. Perhaps we should always do this, but for sure we should
4115 -- do it when there is an address clause since we can do more if the
4116 -- alignment is known.
4118 if Unknown_Alignment (Obj) then
4119 Set_Alignment (Obj, Alignment (Etype (Obj)));
4122 -- Now do the internal call that does all the work
4124 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4125 end Has_Compatible_Alignment;
4127 ----------------------
4128 -- Has_Declarations --
4129 ----------------------
4131 function Has_Declarations (N : Node_Id) return Boolean is
4132 K : constant Node_Kind := Nkind (N);
4134 return K = N_Accept_Statement
4135 or else K = N_Block_Statement
4136 or else K = N_Compilation_Unit_Aux
4137 or else K = N_Entry_Body
4138 or else K = N_Package_Body
4139 or else K = N_Protected_Body
4140 or else K = N_Subprogram_Body
4141 or else K = N_Task_Body
4142 or else K = N_Package_Specification;
4143 end Has_Declarations;
4145 -------------------------------------------
4146 -- Has_Discriminant_Dependent_Constraint --
4147 -------------------------------------------
4149 function Has_Discriminant_Dependent_Constraint
4150 (Comp : Entity_Id) return Boolean
4152 Comp_Decl : constant Node_Id := Parent (Comp);
4153 Subt_Indic : constant Node_Id :=
4154 Subtype_Indication (Component_Definition (Comp_Decl));
4159 if Nkind (Subt_Indic) = N_Subtype_Indication then
4160 Constr := Constraint (Subt_Indic);
4162 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4163 Assn := First (Constraints (Constr));
4164 while Present (Assn) loop
4165 case Nkind (Assn) is
4166 when N_Subtype_Indication |
4170 if Depends_On_Discriminant (Assn) then
4174 when N_Discriminant_Association =>
4175 if Depends_On_Discriminant (Expression (Assn)) then
4190 end Has_Discriminant_Dependent_Constraint;
4192 --------------------
4193 -- Has_Infinities --
4194 --------------------
4196 function Has_Infinities (E : Entity_Id) return Boolean is
4199 Is_Floating_Point_Type (E)
4200 and then Nkind (Scalar_Range (E)) = N_Range
4201 and then Includes_Infinities (Scalar_Range (E));
4204 --------------------
4205 -- Has_Interfaces --
4206 --------------------
4208 function Has_Interfaces
4210 Use_Full_View : Boolean := True) return Boolean
4215 -- Handle concurrent types
4217 if Is_Concurrent_Type (T) then
4218 Typ := Corresponding_Record_Type (T);
4223 if not Present (Typ)
4224 or else not Is_Record_Type (Typ)
4225 or else not Is_Tagged_Type (Typ)
4230 -- Handle private types
4233 and then Present (Full_View (Typ))
4235 Typ := Full_View (Typ);
4238 -- Handle concurrent record types
4240 if Is_Concurrent_Record_Type (Typ)
4241 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4247 if Is_Interface (Typ)
4249 (Is_Record_Type (Typ)
4250 and then Present (Interfaces (Typ))
4251 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4256 exit when Etype (Typ) = Typ
4258 -- Handle private types
4260 or else (Present (Full_View (Etype (Typ)))
4261 and then Full_View (Etype (Typ)) = Typ)
4263 -- Protect the frontend against wrong source with cyclic
4266 or else Etype (Typ) = T;
4268 -- Climb to the ancestor type handling private types
4270 if Present (Full_View (Etype (Typ))) then
4271 Typ := Full_View (Etype (Typ));
4280 ------------------------
4281 -- Has_Null_Exclusion --
4282 ------------------------
4284 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4287 when N_Access_Definition |
4288 N_Access_Function_Definition |
4289 N_Access_Procedure_Definition |
4290 N_Access_To_Object_Definition |
4292 N_Derived_Type_Definition |
4293 N_Function_Specification |
4294 N_Subtype_Declaration =>
4295 return Null_Exclusion_Present (N);
4297 when N_Component_Definition |
4298 N_Formal_Object_Declaration |
4299 N_Object_Renaming_Declaration =>
4300 if Present (Subtype_Mark (N)) then
4301 return Null_Exclusion_Present (N);
4302 else pragma Assert (Present (Access_Definition (N)));
4303 return Null_Exclusion_Present (Access_Definition (N));
4306 when N_Discriminant_Specification =>
4307 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4308 return Null_Exclusion_Present (Discriminant_Type (N));
4310 return Null_Exclusion_Present (N);
4313 when N_Object_Declaration =>
4314 if Nkind (Object_Definition (N)) = N_Access_Definition then
4315 return Null_Exclusion_Present (Object_Definition (N));
4317 return Null_Exclusion_Present (N);
4320 when N_Parameter_Specification =>
4321 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4322 return Null_Exclusion_Present (Parameter_Type (N));
4324 return Null_Exclusion_Present (N);
4331 end Has_Null_Exclusion;
4333 ------------------------
4334 -- Has_Null_Extension --
4335 ------------------------
4337 function Has_Null_Extension (T : Entity_Id) return Boolean is
4338 B : constant Entity_Id := Base_Type (T);
4343 if Nkind (Parent (B)) = N_Full_Type_Declaration
4344 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4346 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4348 if Present (Ext) then
4349 if Null_Present (Ext) then
4352 Comps := Component_List (Ext);
4354 -- The null component list is rewritten during analysis to
4355 -- include the parent component. Any other component indicates
4356 -- that the extension was not originally null.
4358 return Null_Present (Comps)
4359 or else No (Next (First (Component_Items (Comps))));
4368 end Has_Null_Extension;
4370 -------------------------------
4371 -- Has_Overriding_Initialize --
4372 -------------------------------
4374 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4375 BT : constant Entity_Id := Base_Type (T);
4380 if Is_Controlled (BT) then
4382 -- For derived types, check immediate ancestor, excluding
4383 -- Controlled itself.
4385 if Is_Derived_Type (BT)
4386 and then not In_Predefined_Unit (Etype (BT))
4387 and then Has_Overriding_Initialize (Etype (BT))
4391 elsif Present (Primitive_Operations (BT)) then
4392 P := First_Elmt (Primitive_Operations (BT));
4393 while Present (P) loop
4394 if Chars (Node (P)) = Name_Initialize
4395 and then Comes_From_Source (Node (P))
4406 elsif Has_Controlled_Component (BT) then
4407 Comp := First_Component (BT);
4408 while Present (Comp) loop
4409 if Has_Overriding_Initialize (Etype (Comp)) then
4413 Next_Component (Comp);
4421 end Has_Overriding_Initialize;
4423 --------------------------------------
4424 -- Has_Preelaborable_Initialization --
4425 --------------------------------------
4427 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4430 procedure Check_Components (E : Entity_Id);
4431 -- Check component/discriminant chain, sets Has_PE False if a component
4432 -- or discriminant does not meet the preelaborable initialization rules.
4434 ----------------------
4435 -- Check_Components --
4436 ----------------------
4438 procedure Check_Components (E : Entity_Id) is
4442 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4443 -- Returns True if and only if the expression denoted by N does not
4444 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4446 ---------------------------------
4447 -- Is_Preelaborable_Expression --
4448 ---------------------------------
4450 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4454 Comp_Type : Entity_Id;
4455 Is_Array_Aggr : Boolean;
4458 if Is_Static_Expression (N) then
4461 elsif Nkind (N) = N_Null then
4464 -- Attributes are allowed in general, even if their prefix is a
4465 -- formal type. (It seems that certain attributes known not to be
4466 -- static might not be allowed, but there are no rules to prevent
4469 elsif Nkind (N) = N_Attribute_Reference then
4472 -- The name of a discriminant evaluated within its parent type is
4473 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4474 -- names that denote discriminals as well as discriminants to
4475 -- catch references occurring within init procs.
4477 elsif Is_Entity_Name (N)
4479 (Ekind (Entity (N)) = E_Discriminant
4481 ((Ekind (Entity (N)) = E_Constant
4482 or else Ekind (Entity (N)) = E_In_Parameter)
4483 and then Present (Discriminal_Link (Entity (N)))))
4487 elsif Nkind (N) = N_Qualified_Expression then
4488 return Is_Preelaborable_Expression (Expression (N));
4490 -- For aggregates we have to check that each of the associations
4491 -- is preelaborable.
4493 elsif Nkind (N) = N_Aggregate
4494 or else Nkind (N) = N_Extension_Aggregate
4496 Is_Array_Aggr := Is_Array_Type (Etype (N));
4498 if Is_Array_Aggr then
4499 Comp_Type := Component_Type (Etype (N));
4502 -- Check the ancestor part of extension aggregates, which must
4503 -- be either the name of a type that has preelaborable init or
4504 -- an expression that is preelaborable.
4506 if Nkind (N) = N_Extension_Aggregate then
4508 Anc_Part : constant Node_Id := Ancestor_Part (N);
4511 if Is_Entity_Name (Anc_Part)
4512 and then Is_Type (Entity (Anc_Part))
4514 if not Has_Preelaborable_Initialization
4520 elsif not Is_Preelaborable_Expression (Anc_Part) then
4526 -- Check positional associations
4528 Exp := First (Expressions (N));
4529 while Present (Exp) loop
4530 if not Is_Preelaborable_Expression (Exp) then
4537 -- Check named associations
4539 Assn := First (Component_Associations (N));
4540 while Present (Assn) loop
4541 Choice := First (Choices (Assn));
4542 while Present (Choice) loop
4543 if Is_Array_Aggr then
4544 if Nkind (Choice) = N_Others_Choice then
4547 elsif Nkind (Choice) = N_Range then
4548 if not Is_Static_Range (Choice) then
4552 elsif not Is_Static_Expression (Choice) then
4557 Comp_Type := Etype (Choice);
4563 -- If the association has a <> at this point, then we have
4564 -- to check whether the component's type has preelaborable
4565 -- initialization. Note that this only occurs when the
4566 -- association's corresponding component does not have a
4567 -- default expression, the latter case having already been
4568 -- expanded as an expression for the association.
4570 if Box_Present (Assn) then
4571 if not Has_Preelaborable_Initialization (Comp_Type) then
4575 -- In the expression case we check whether the expression
4576 -- is preelaborable.
4579 not Is_Preelaborable_Expression (Expression (Assn))
4587 -- If we get here then aggregate as a whole is preelaborable
4591 -- All other cases are not preelaborable
4596 end Is_Preelaborable_Expression;
4598 -- Start of processing for Check_Components
4601 -- Loop through entities of record or protected type
4604 while Present (Ent) loop
4606 -- We are interested only in components and discriminants
4608 if Ekind (Ent) = E_Component
4610 Ekind (Ent) = E_Discriminant
4612 -- Get default expression if any. If there is no declaration
4613 -- node, it means we have an internal entity. The parent and
4614 -- tag fields are examples of such entities. For these cases,
4615 -- we just test the type of the entity.
4617 if Present (Declaration_Node (Ent)) then
4618 Exp := Expression (Declaration_Node (Ent));
4623 -- A component has PI if it has no default expression and the
4624 -- component type has PI.
4627 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4632 -- Require the default expression to be preelaborable
4634 elsif not Is_Preelaborable_Expression (Exp) then
4642 end Check_Components;
4644 -- Start of processing for Has_Preelaborable_Initialization
4647 -- Immediate return if already marked as known preelaborable init. This
4648 -- covers types for which this function has already been called once
4649 -- and returned True (in which case the result is cached), and also
4650 -- types to which a pragma Preelaborable_Initialization applies.
4652 if Known_To_Have_Preelab_Init (E) then
4656 -- If the type is a subtype representing a generic actual type, then
4657 -- test whether its base type has preelaborable initialization since
4658 -- the subtype representing the actual does not inherit this attribute
4659 -- from the actual or formal. (but maybe it should???)
4661 if Is_Generic_Actual_Type (E) then
4662 return Has_Preelaborable_Initialization (Base_Type (E));
4665 -- All elementary types have preelaborable initialization
4667 if Is_Elementary_Type (E) then
4670 -- Array types have PI if the component type has PI
4672 elsif Is_Array_Type (E) then
4673 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4675 -- A derived type has preelaborable initialization if its parent type
4676 -- has preelaborable initialization and (in the case of a derived record
4677 -- extension) if the non-inherited components all have preelaborable
4678 -- initialization. However, a user-defined controlled type with an
4679 -- overriding Initialize procedure does not have preelaborable
4682 elsif Is_Derived_Type (E) then
4684 -- If the derived type is a private extension then it doesn't have
4685 -- preelaborable initialization.
4687 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4691 -- First check whether ancestor type has preelaborable initialization
4693 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4695 -- If OK, check extension components (if any)
4697 if Has_PE and then Is_Record_Type (E) then
4698 Check_Components (First_Entity (E));
4701 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4702 -- with a user defined Initialize procedure does not have PI.
4705 and then Is_Controlled (E)
4706 and then Has_Overriding_Initialize (E)
4711 -- Private types not derived from a type having preelaborable init and
4712 -- that are not marked with pragma Preelaborable_Initialization do not
4713 -- have preelaborable initialization.
4715 elsif Is_Private_Type (E) then
4718 -- Record type has PI if it is non private and all components have PI
4720 elsif Is_Record_Type (E) then
4722 Check_Components (First_Entity (E));
4724 -- Protected types must not have entries, and components must meet
4725 -- same set of rules as for record components.
4727 elsif Is_Protected_Type (E) then
4728 if Has_Entries (E) then
4732 Check_Components (First_Entity (E));
4733 Check_Components (First_Private_Entity (E));
4736 -- Type System.Address always has preelaborable initialization
4738 elsif Is_RTE (E, RE_Address) then
4741 -- In all other cases, type does not have preelaborable initialization
4747 -- If type has preelaborable initialization, cache result
4750 Set_Known_To_Have_Preelab_Init (E);
4754 end Has_Preelaborable_Initialization;
4756 ---------------------------
4757 -- Has_Private_Component --
4758 ---------------------------
4760 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4761 Btype : Entity_Id := Base_Type (Type_Id);
4762 Component : Entity_Id;
4765 if Error_Posted (Type_Id)
4766 or else Error_Posted (Btype)
4771 if Is_Class_Wide_Type (Btype) then
4772 Btype := Root_Type (Btype);
4775 if Is_Private_Type (Btype) then
4777 UT : constant Entity_Id := Underlying_Type (Btype);
4780 if No (Full_View (Btype)) then
4781 return not Is_Generic_Type (Btype)
4782 and then not Is_Generic_Type (Root_Type (Btype));
4784 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4787 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4791 elsif Is_Array_Type (Btype) then
4792 return Has_Private_Component (Component_Type (Btype));
4794 elsif Is_Record_Type (Btype) then
4795 Component := First_Component (Btype);
4796 while Present (Component) loop
4797 if Has_Private_Component (Etype (Component)) then
4801 Next_Component (Component);
4806 elsif Is_Protected_Type (Btype)
4807 and then Present (Corresponding_Record_Type (Btype))
4809 return Has_Private_Component (Corresponding_Record_Type (Btype));
4814 end Has_Private_Component;
4820 function Has_Stream (T : Entity_Id) return Boolean is
4827 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4830 elsif Is_Array_Type (T) then
4831 return Has_Stream (Component_Type (T));
4833 elsif Is_Record_Type (T) then
4834 E := First_Component (T);
4835 while Present (E) loop
4836 if Has_Stream (Etype (E)) then
4845 elsif Is_Private_Type (T) then
4846 return Has_Stream (Underlying_Type (T));
4853 --------------------------
4854 -- Has_Tagged_Component --
4855 --------------------------
4857 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4861 if Is_Private_Type (Typ)
4862 and then Present (Underlying_Type (Typ))
4864 return Has_Tagged_Component (Underlying_Type (Typ));
4866 elsif Is_Array_Type (Typ) then
4867 return Has_Tagged_Component (Component_Type (Typ));
4869 elsif Is_Tagged_Type (Typ) then
4872 elsif Is_Record_Type (Typ) then
4873 Comp := First_Component (Typ);
4874 while Present (Comp) loop
4875 if Has_Tagged_Component (Etype (Comp)) then
4879 Next_Component (Comp);
4887 end Has_Tagged_Component;
4889 --------------------------
4890 -- Implements_Interface --
4891 --------------------------
4893 function Implements_Interface
4894 (Typ_Ent : Entity_Id;
4895 Iface_Ent : Entity_Id;
4896 Exclude_Parents : Boolean := False) return Boolean
4898 Ifaces_List : Elist_Id;
4904 if Is_Class_Wide_Type (Typ_Ent) then
4905 Typ := Etype (Typ_Ent);
4910 if Is_Class_Wide_Type (Iface_Ent) then
4911 Iface := Etype (Iface_Ent);
4916 if not Has_Interfaces (Typ) then
4920 Collect_Interfaces (Typ, Ifaces_List);
4922 Elmt := First_Elmt (Ifaces_List);
4923 while Present (Elmt) loop
4924 if Is_Ancestor (Node (Elmt), Typ)
4925 and then Exclude_Parents
4929 elsif Node (Elmt) = Iface then
4937 end Implements_Interface;
4943 function In_Instance return Boolean is
4944 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4950 and then S /= Standard_Standard
4952 if (Ekind (S) = E_Function
4953 or else Ekind (S) = E_Package
4954 or else Ekind (S) = E_Procedure)
4955 and then Is_Generic_Instance (S)
4957 -- A child instance is always compiled in the context of a parent
4958 -- instance. Nevertheless, the actuals are not analyzed in an
4959 -- instance context. We detect this case by examining the current
4960 -- compilation unit, which must be a child instance, and checking
4961 -- that it is not currently on the scope stack.
4963 if Is_Child_Unit (Curr_Unit)
4965 Nkind (Unit (Cunit (Current_Sem_Unit)))
4966 = N_Package_Instantiation
4967 and then not In_Open_Scopes (Curr_Unit)
4981 ----------------------
4982 -- In_Instance_Body --
4983 ----------------------
4985 function In_Instance_Body return Boolean is
4991 and then S /= Standard_Standard
4993 if (Ekind (S) = E_Function
4994 or else Ekind (S) = E_Procedure)
4995 and then Is_Generic_Instance (S)
4999 elsif Ekind (S) = E_Package
5000 and then In_Package_Body (S)
5001 and then Is_Generic_Instance (S)
5010 end In_Instance_Body;
5012 -----------------------------
5013 -- In_Instance_Not_Visible --
5014 -----------------------------
5016 function In_Instance_Not_Visible return Boolean is
5022 and then S /= Standard_Standard
5024 if (Ekind (S) = E_Function
5025 or else Ekind (S) = E_Procedure)
5026 and then Is_Generic_Instance (S)
5030 elsif Ekind (S) = E_Package
5031 and then (In_Package_Body (S) or else In_Private_Part (S))
5032 and then Is_Generic_Instance (S)
5041 end In_Instance_Not_Visible;
5043 ------------------------------
5044 -- In_Instance_Visible_Part --
5045 ------------------------------
5047 function In_Instance_Visible_Part return Boolean is
5053 and then S /= Standard_Standard
5055 if Ekind (S) = E_Package
5056 and then Is_Generic_Instance (S)
5057 and then not In_Package_Body (S)
5058 and then not In_Private_Part (S)
5067 end In_Instance_Visible_Part;
5069 ---------------------
5070 -- In_Package_Body --
5071 ---------------------
5073 function In_Package_Body return Boolean is
5079 and then S /= Standard_Standard
5081 if Ekind (S) = E_Package
5082 and then In_Package_Body (S)
5091 end In_Package_Body;
5093 --------------------------------
5094 -- In_Parameter_Specification --
5095 --------------------------------
5097 function In_Parameter_Specification (N : Node_Id) return Boolean is
5102 while Present (PN) loop
5103 if Nkind (PN) = N_Parameter_Specification then
5111 end In_Parameter_Specification;
5113 --------------------------------------
5114 -- In_Subprogram_Or_Concurrent_Unit --
5115 --------------------------------------
5117 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5122 -- Use scope chain to check successively outer scopes
5128 if K in Subprogram_Kind
5129 or else K in Concurrent_Kind
5130 or else K in Generic_Subprogram_Kind
5134 elsif E = Standard_Standard then
5140 end In_Subprogram_Or_Concurrent_Unit;
5142 ---------------------
5143 -- In_Visible_Part --
5144 ---------------------
5146 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5149 Is_Package_Or_Generic_Package (Scope_Id)
5150 and then In_Open_Scopes (Scope_Id)
5151 and then not In_Package_Body (Scope_Id)
5152 and then not In_Private_Part (Scope_Id);
5153 end In_Visible_Part;
5155 ---------------------------------
5156 -- Insert_Explicit_Dereference --
5157 ---------------------------------
5159 procedure Insert_Explicit_Dereference (N : Node_Id) is
5160 New_Prefix : constant Node_Id := Relocate_Node (N);
5161 Ent : Entity_Id := Empty;
5168 Save_Interps (N, New_Prefix);
5169 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5171 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5173 if Is_Overloaded (New_Prefix) then
5175 -- The deference is also overloaded, and its interpretations are the
5176 -- designated types of the interpretations of the original node.
5178 Set_Etype (N, Any_Type);
5180 Get_First_Interp (New_Prefix, I, It);
5181 while Present (It.Nam) loop
5184 if Is_Access_Type (T) then
5185 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5188 Get_Next_Interp (I, It);
5194 -- Prefix is unambiguous: mark the original prefix (which might
5195 -- Come_From_Source) as a reference, since the new (relocated) one
5196 -- won't be taken into account.
5198 if Is_Entity_Name (New_Prefix) then
5199 Ent := Entity (New_Prefix);
5201 -- For a retrieval of a subcomponent of some composite object,
5202 -- retrieve the ultimate entity if there is one.
5204 elsif Nkind (New_Prefix) = N_Selected_Component
5205 or else Nkind (New_Prefix) = N_Indexed_Component
5207 Pref := Prefix (New_Prefix);
5208 while Present (Pref)
5210 (Nkind (Pref) = N_Selected_Component
5211 or else Nkind (Pref) = N_Indexed_Component)
5213 Pref := Prefix (Pref);
5216 if Present (Pref) and then Is_Entity_Name (Pref) then
5217 Ent := Entity (Pref);
5221 if Present (Ent) then
5222 Generate_Reference (Ent, New_Prefix);
5225 end Insert_Explicit_Dereference;
5227 ------------------------------------------
5228 -- Inspect_Deferred_Constant_Completion --
5229 ------------------------------------------
5231 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5235 Decl := First (Decls);
5236 while Present (Decl) loop
5238 -- Deferred constant signature
5240 if Nkind (Decl) = N_Object_Declaration
5241 and then Constant_Present (Decl)
5242 and then No (Expression (Decl))
5244 -- No need to check internally generated constants
5246 and then Comes_From_Source (Decl)
5248 -- The constant is not completed. A full object declaration
5249 -- or a pragma Import complete a deferred constant.
5251 and then not Has_Completion (Defining_Identifier (Decl))
5254 ("constant declaration requires initialization expression",
5255 Defining_Identifier (Decl));
5258 Decl := Next (Decl);
5260 end Inspect_Deferred_Constant_Completion;
5266 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5267 pragma Assert (Is_Type (E));
5269 return AAMP_On_Target
5270 and then Is_Floating_Point_Type (E)
5271 and then E = Base_Type (E);
5274 -------------------------
5275 -- Is_Actual_Parameter --
5276 -------------------------
5278 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5279 PK : constant Node_Kind := Nkind (Parent (N));
5283 when N_Parameter_Association =>
5284 return N = Explicit_Actual_Parameter (Parent (N));
5286 when N_Function_Call | N_Procedure_Call_Statement =>
5287 return Is_List_Member (N)
5289 List_Containing (N) = Parameter_Associations (Parent (N));
5294 end Is_Actual_Parameter;
5296 ---------------------
5297 -- Is_Aliased_View --
5298 ---------------------
5300 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5304 if Is_Entity_Name (Obj) then
5312 or else (Present (Renamed_Object (E))
5313 and then Is_Aliased_View (Renamed_Object (E)))))
5315 or else ((Is_Formal (E)
5316 or else Ekind (E) = E_Generic_In_Out_Parameter
5317 or else Ekind (E) = E_Generic_In_Parameter)
5318 and then Is_Tagged_Type (Etype (E)))
5320 or else (Is_Concurrent_Type (E)
5321 and then In_Open_Scopes (E))
5323 -- Current instance of type, either directly or as rewritten
5324 -- reference to the current object.
5326 or else (Is_Entity_Name (Original_Node (Obj))
5327 and then Present (Entity (Original_Node (Obj)))
5328 and then Is_Type (Entity (Original_Node (Obj))))
5330 or else (Is_Type (E) and then E = Current_Scope)
5332 or else (Is_Incomplete_Or_Private_Type (E)
5333 and then Full_View (E) = Current_Scope);
5335 elsif Nkind (Obj) = N_Selected_Component then
5336 return Is_Aliased (Entity (Selector_Name (Obj)));
5338 elsif Nkind (Obj) = N_Indexed_Component then
5339 return Has_Aliased_Components (Etype (Prefix (Obj)))
5341 (Is_Access_Type (Etype (Prefix (Obj)))
5343 Has_Aliased_Components
5344 (Designated_Type (Etype (Prefix (Obj)))));
5346 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5347 or else Nkind (Obj) = N_Type_Conversion
5349 return Is_Tagged_Type (Etype (Obj))
5350 and then Is_Aliased_View (Expression (Obj));
5352 elsif Nkind (Obj) = N_Explicit_Dereference then
5353 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5358 end Is_Aliased_View;
5360 -------------------------
5361 -- Is_Ancestor_Package --
5362 -------------------------
5364 function Is_Ancestor_Package
5366 E2 : Entity_Id) return Boolean
5373 and then Par /= Standard_Standard
5383 end Is_Ancestor_Package;
5385 ----------------------
5386 -- Is_Atomic_Object --
5387 ----------------------
5389 function Is_Atomic_Object (N : Node_Id) return Boolean is
5391 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5392 -- Determines if given object has atomic components
5394 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5395 -- If prefix is an implicit dereference, examine designated type
5397 ----------------------
5398 -- Is_Atomic_Prefix --
5399 ----------------------
5401 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5403 if Is_Access_Type (Etype (N)) then
5405 Has_Atomic_Components (Designated_Type (Etype (N)));
5407 return Object_Has_Atomic_Components (N);
5409 end Is_Atomic_Prefix;
5411 ----------------------------------
5412 -- Object_Has_Atomic_Components --
5413 ----------------------------------
5415 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5417 if Has_Atomic_Components (Etype (N))
5418 or else Is_Atomic (Etype (N))
5422 elsif Is_Entity_Name (N)
5423 and then (Has_Atomic_Components (Entity (N))
5424 or else Is_Atomic (Entity (N)))
5428 elsif Nkind (N) = N_Indexed_Component
5429 or else Nkind (N) = N_Selected_Component
5431 return Is_Atomic_Prefix (Prefix (N));
5436 end Object_Has_Atomic_Components;
5438 -- Start of processing for Is_Atomic_Object
5441 if Is_Atomic (Etype (N))
5442 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5446 elsif Nkind (N) = N_Indexed_Component
5447 or else Nkind (N) = N_Selected_Component
5449 return Is_Atomic_Prefix (Prefix (N));
5454 end Is_Atomic_Object;
5456 -------------------------
5457 -- Is_Coextension_Root --
5458 -------------------------
5460 function Is_Coextension_Root (N : Node_Id) return Boolean is
5463 Nkind (N) = N_Allocator
5464 and then Present (Coextensions (N))
5466 -- Anonymous access discriminants carry a list of all nested
5467 -- controlled coextensions.
5469 and then not Is_Dynamic_Coextension (N)
5470 and then not Is_Static_Coextension (N);
5471 end Is_Coextension_Root;
5473 -----------------------------
5474 -- Is_Concurrent_Interface --
5475 -----------------------------
5477 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5482 (Is_Protected_Interface (T)
5483 or else Is_Synchronized_Interface (T)
5484 or else Is_Task_Interface (T));
5485 end Is_Concurrent_Interface;
5487 --------------------------------------
5488 -- Is_Controlling_Limited_Procedure --
5489 --------------------------------------
5491 function Is_Controlling_Limited_Procedure
5492 (Proc_Nam : Entity_Id) return Boolean
5494 Param_Typ : Entity_Id := Empty;
5497 if Ekind (Proc_Nam) = E_Procedure
5498 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5500 Param_Typ := Etype (Parameter_Type (First (
5501 Parameter_Specifications (Parent (Proc_Nam)))));
5503 -- In this case where an Itype was created, the procedure call has been
5506 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5507 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5509 Present (Parameter_Associations
5510 (Associated_Node_For_Itype (Proc_Nam)))
5513 Etype (First (Parameter_Associations
5514 (Associated_Node_For_Itype (Proc_Nam))));
5517 if Present (Param_Typ) then
5519 Is_Interface (Param_Typ)
5520 and then Is_Limited_Record (Param_Typ);
5524 end Is_Controlling_Limited_Procedure;
5526 -----------------------------
5527 -- Is_CPP_Constructor_Call --
5528 -----------------------------
5530 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5532 return Nkind (N) = N_Function_Call
5533 and then Is_CPP_Class (Etype (Etype (N)))
5534 and then Is_Constructor (Entity (Name (N)))
5535 and then Is_Imported (Entity (Name (N)));
5536 end Is_CPP_Constructor_Call;
5538 ----------------------------------------------
5539 -- Is_Dependent_Component_Of_Mutable_Object --
5540 ----------------------------------------------
5542 function Is_Dependent_Component_Of_Mutable_Object
5543 (Object : Node_Id) return Boolean
5546 Prefix_Type : Entity_Id;
5547 P_Aliased : Boolean := False;
5550 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5551 -- Returns True if and only if Comp is declared within a variant part
5553 --------------------------------
5554 -- Is_Declared_Within_Variant --
5555 --------------------------------
5557 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5558 Comp_Decl : constant Node_Id := Parent (Comp);
5559 Comp_List : constant Node_Id := Parent (Comp_Decl);
5561 return Nkind (Parent (Comp_List)) = N_Variant;
5562 end Is_Declared_Within_Variant;
5564 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5567 if Is_Variable (Object) then
5569 if Nkind (Object) = N_Selected_Component then
5570 P := Prefix (Object);
5571 Prefix_Type := Etype (P);
5573 if Is_Entity_Name (P) then
5575 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5576 Prefix_Type := Base_Type (Prefix_Type);
5579 if Is_Aliased (Entity (P)) then
5583 -- A discriminant check on a selected component may be
5584 -- expanded into a dereference when removing side-effects.
5585 -- Recover the original node and its type, which may be
5588 elsif Nkind (P) = N_Explicit_Dereference
5589 and then not (Comes_From_Source (P))
5591 P := Original_Node (P);
5592 Prefix_Type := Etype (P);
5595 -- Check for prefix being an aliased component ???
5600 -- A heap object is constrained by its initial value
5602 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5603 -- the dereferenced case, since the access value might denote an
5604 -- unconstrained aliased object, whereas in Ada 95 the designated
5605 -- object is guaranteed to be constrained. A worst-case assumption
5606 -- has to apply in Ada 2005 because we can't tell at compile time
5607 -- whether the object is "constrained by its initial value"
5608 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5609 -- semantic rules -- these rules are acknowledged to need fixing).
5611 if Ada_Version < Ada_05 then
5612 if Is_Access_Type (Prefix_Type)
5613 or else Nkind (P) = N_Explicit_Dereference
5618 elsif Ada_Version >= Ada_05 then
5619 if Is_Access_Type (Prefix_Type) then
5621 -- If the access type is pool-specific, and there is no
5622 -- constrained partial view of the designated type, then the
5623 -- designated object is known to be constrained.
5625 if Ekind (Prefix_Type) = E_Access_Type
5626 and then not Has_Constrained_Partial_View
5627 (Designated_Type (Prefix_Type))
5631 -- Otherwise (general access type, or there is a constrained
5632 -- partial view of the designated type), we need to check
5633 -- based on the designated type.
5636 Prefix_Type := Designated_Type (Prefix_Type);
5642 Original_Record_Component (Entity (Selector_Name (Object)));
5644 -- As per AI-0017, the renaming is illegal in a generic body,
5645 -- even if the subtype is indefinite.
5647 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5649 if not Is_Constrained (Prefix_Type)
5650 and then (not Is_Indefinite_Subtype (Prefix_Type)
5652 (Is_Generic_Type (Prefix_Type)
5653 and then Ekind (Current_Scope) = E_Generic_Package
5654 and then In_Package_Body (Current_Scope)))
5656 and then (Is_Declared_Within_Variant (Comp)
5657 or else Has_Discriminant_Dependent_Constraint (Comp))
5658 and then (not P_Aliased or else Ada_Version >= Ada_05)
5664 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5668 elsif Nkind (Object) = N_Indexed_Component
5669 or else Nkind (Object) = N_Slice
5671 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5673 -- A type conversion that Is_Variable is a view conversion:
5674 -- go back to the denoted object.
5676 elsif Nkind (Object) = N_Type_Conversion then
5678 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5683 end Is_Dependent_Component_Of_Mutable_Object;
5685 ---------------------
5686 -- Is_Dereferenced --
5687 ---------------------
5689 function Is_Dereferenced (N : Node_Id) return Boolean is
5690 P : constant Node_Id := Parent (N);
5693 (Nkind (P) = N_Selected_Component
5695 Nkind (P) = N_Explicit_Dereference
5697 Nkind (P) = N_Indexed_Component
5699 Nkind (P) = N_Slice)
5700 and then Prefix (P) = N;
5701 end Is_Dereferenced;
5703 ----------------------
5704 -- Is_Descendent_Of --
5705 ----------------------
5707 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5712 pragma Assert (Nkind (T1) in N_Entity);
5713 pragma Assert (Nkind (T2) in N_Entity);
5715 T := Base_Type (T1);
5717 -- Immediate return if the types match
5722 -- Comment needed here ???
5724 elsif Ekind (T) = E_Class_Wide_Type then
5725 return Etype (T) = T2;
5733 -- Done if we found the type we are looking for
5738 -- Done if no more derivations to check
5745 -- Following test catches error cases resulting from prev errors
5747 elsif No (Etyp) then
5750 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5753 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5757 T := Base_Type (Etyp);
5760 end Is_Descendent_Of;
5766 function Is_False (U : Uint) return Boolean is
5771 ---------------------------
5772 -- Is_Fixed_Model_Number --
5773 ---------------------------
5775 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5776 S : constant Ureal := Small_Value (T);
5777 M : Urealp.Save_Mark;
5781 R := (U = UR_Trunc (U / S) * S);
5784 end Is_Fixed_Model_Number;
5786 -------------------------------
5787 -- Is_Fully_Initialized_Type --
5788 -------------------------------
5790 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5792 if Is_Scalar_Type (Typ) then
5795 elsif Is_Access_Type (Typ) then
5798 elsif Is_Array_Type (Typ) then
5799 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5803 -- An interesting case, if we have a constrained type one of whose
5804 -- bounds is known to be null, then there are no elements to be
5805 -- initialized, so all the elements are initialized!
5807 if Is_Constrained (Typ) then
5810 Indx_Typ : Entity_Id;
5814 Indx := First_Index (Typ);
5815 while Present (Indx) loop
5816 if Etype (Indx) = Any_Type then
5819 -- If index is a range, use directly
5821 elsif Nkind (Indx) = N_Range then
5822 Lbd := Low_Bound (Indx);
5823 Hbd := High_Bound (Indx);
5826 Indx_Typ := Etype (Indx);
5828 if Is_Private_Type (Indx_Typ) then
5829 Indx_Typ := Full_View (Indx_Typ);
5832 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5835 Lbd := Type_Low_Bound (Indx_Typ);
5836 Hbd := Type_High_Bound (Indx_Typ);
5840 if Compile_Time_Known_Value (Lbd)
5841 and then Compile_Time_Known_Value (Hbd)
5843 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5853 -- If no null indexes, then type is not fully initialized
5859 elsif Is_Record_Type (Typ) then
5860 if Has_Discriminants (Typ)
5862 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5863 and then Is_Fully_Initialized_Variant (Typ)
5868 -- Controlled records are considered to be fully initialized if
5869 -- there is a user defined Initialize routine. This may not be
5870 -- entirely correct, but as the spec notes, we are guessing here
5871 -- what is best from the point of view of issuing warnings.
5873 if Is_Controlled (Typ) then
5875 Utyp : constant Entity_Id := Underlying_Type (Typ);
5878 if Present (Utyp) then
5880 Init : constant Entity_Id :=
5882 (Underlying_Type (Typ), Name_Initialize));
5886 and then Comes_From_Source (Init)
5888 Is_Predefined_File_Name
5889 (File_Name (Get_Source_File_Index (Sloc (Init))))
5893 elsif Has_Null_Extension (Typ)
5895 Is_Fully_Initialized_Type
5896 (Etype (Base_Type (Typ)))
5905 -- Otherwise see if all record components are initialized
5911 Ent := First_Entity (Typ);
5912 while Present (Ent) loop
5913 if Chars (Ent) = Name_uController then
5916 elsif Ekind (Ent) = E_Component
5917 and then (No (Parent (Ent))
5918 or else No (Expression (Parent (Ent))))
5919 and then not Is_Fully_Initialized_Type (Etype (Ent))
5921 -- Special VM case for tag components, which need to be
5922 -- defined in this case, but are never initialized as VMs
5923 -- are using other dispatching mechanisms. Ignore this
5924 -- uninitialized case. Note that this applies both to the
5925 -- uTag entry and the main vtable pointer (CPP_Class case).
5927 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
5936 -- No uninitialized components, so type is fully initialized.
5937 -- Note that this catches the case of no components as well.
5941 elsif Is_Concurrent_Type (Typ) then
5944 elsif Is_Private_Type (Typ) then
5946 U : constant Entity_Id := Underlying_Type (Typ);
5952 return Is_Fully_Initialized_Type (U);
5959 end Is_Fully_Initialized_Type;
5961 ----------------------------------
5962 -- Is_Fully_Initialized_Variant --
5963 ----------------------------------
5965 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5966 Loc : constant Source_Ptr := Sloc (Typ);
5967 Constraints : constant List_Id := New_List;
5968 Components : constant Elist_Id := New_Elmt_List;
5969 Comp_Elmt : Elmt_Id;
5971 Comp_List : Node_Id;
5973 Discr_Val : Node_Id;
5975 Report_Errors : Boolean;
5976 pragma Warnings (Off, Report_Errors);
5979 if Serious_Errors_Detected > 0 then
5983 if Is_Record_Type (Typ)
5984 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5985 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5987 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5989 Discr := First_Discriminant (Typ);
5990 while Present (Discr) loop
5991 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5992 Discr_Val := Expression (Parent (Discr));
5994 if Present (Discr_Val)
5995 and then Is_OK_Static_Expression (Discr_Val)
5997 Append_To (Constraints,
5998 Make_Component_Association (Loc,
5999 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6000 Expression => New_Copy (Discr_Val)));
6008 Next_Discriminant (Discr);
6013 Comp_List => Comp_List,
6014 Governed_By => Constraints,
6016 Report_Errors => Report_Errors);
6018 -- Check that each component present is fully initialized
6020 Comp_Elmt := First_Elmt (Components);
6021 while Present (Comp_Elmt) loop
6022 Comp_Id := Node (Comp_Elmt);
6024 if Ekind (Comp_Id) = E_Component
6025 and then (No (Parent (Comp_Id))
6026 or else No (Expression (Parent (Comp_Id))))
6027 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6032 Next_Elmt (Comp_Elmt);
6037 elsif Is_Private_Type (Typ) then
6039 U : constant Entity_Id := Underlying_Type (Typ);
6045 return Is_Fully_Initialized_Variant (U);
6051 end Is_Fully_Initialized_Variant;
6053 ----------------------------
6054 -- Is_Inherited_Operation --
6055 ----------------------------
6057 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6058 Kind : constant Node_Kind := Nkind (Parent (E));
6060 pragma Assert (Is_Overloadable (E));
6061 return Kind = N_Full_Type_Declaration
6062 or else Kind = N_Private_Extension_Declaration
6063 or else Kind = N_Subtype_Declaration
6064 or else (Ekind (E) = E_Enumeration_Literal
6065 and then Is_Derived_Type (Etype (E)));
6066 end Is_Inherited_Operation;
6068 -----------------------------
6069 -- Is_Library_Level_Entity --
6070 -----------------------------
6072 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6074 -- The following is a small optimization, and it also properly handles
6075 -- discriminals, which in task bodies might appear in expressions before
6076 -- the corresponding procedure has been created, and which therefore do
6077 -- not have an assigned scope.
6079 if Ekind (E) in Formal_Kind then
6083 -- Normal test is simply that the enclosing dynamic scope is Standard
6085 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6086 end Is_Library_Level_Entity;
6088 ---------------------------------
6089 -- Is_Local_Variable_Reference --
6090 ---------------------------------
6092 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6094 if not Is_Entity_Name (Expr) then
6099 Ent : constant Entity_Id := Entity (Expr);
6100 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6102 if Ekind (Ent) /= E_Variable
6104 Ekind (Ent) /= E_In_Out_Parameter
6108 return Present (Sub) and then Sub = Current_Subprogram;
6112 end Is_Local_Variable_Reference;
6114 -------------------------
6115 -- Is_Object_Reference --
6116 -------------------------
6118 function Is_Object_Reference (N : Node_Id) return Boolean is
6120 if Is_Entity_Name (N) then
6121 return Present (Entity (N)) and then Is_Object (Entity (N));
6125 when N_Indexed_Component | N_Slice =>
6127 Is_Object_Reference (Prefix (N))
6128 or else Is_Access_Type (Etype (Prefix (N)));
6130 -- In Ada95, a function call is a constant object; a procedure
6133 when N_Function_Call =>
6134 return Etype (N) /= Standard_Void_Type;
6136 -- A reference to the stream attribute Input is a function call
6138 when N_Attribute_Reference =>
6139 return Attribute_Name (N) = Name_Input;
6141 when N_Selected_Component =>
6143 Is_Object_Reference (Selector_Name (N))
6145 (Is_Object_Reference (Prefix (N))
6146 or else Is_Access_Type (Etype (Prefix (N))));
6148 when N_Explicit_Dereference =>
6151 -- A view conversion of a tagged object is an object reference
6153 when N_Type_Conversion =>
6154 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6155 and then Is_Tagged_Type (Etype (Expression (N)))
6156 and then Is_Object_Reference (Expression (N));
6158 -- An unchecked type conversion is considered to be an object if
6159 -- the operand is an object (this construction arises only as a
6160 -- result of expansion activities).
6162 when N_Unchecked_Type_Conversion =>
6169 end Is_Object_Reference;
6171 -----------------------------------
6172 -- Is_OK_Variable_For_Out_Formal --
6173 -----------------------------------
6175 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6177 Note_Possible_Modification (AV, Sure => True);
6179 -- We must reject parenthesized variable names. The check for
6180 -- Comes_From_Source is present because there are currently
6181 -- cases where the compiler violates this rule (e.g. passing
6182 -- a task object to its controlled Initialize routine).
6184 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6187 -- A variable is always allowed
6189 elsif Is_Variable (AV) then
6192 -- Unchecked conversions are allowed only if they come from the
6193 -- generated code, which sometimes uses unchecked conversions for out
6194 -- parameters in cases where code generation is unaffected. We tell
6195 -- source unchecked conversions by seeing if they are rewrites of an
6196 -- original Unchecked_Conversion function call, or of an explicit
6197 -- conversion of a function call.
6199 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6200 if Nkind (Original_Node (AV)) = N_Function_Call then
6203 elsif Comes_From_Source (AV)
6204 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6208 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6209 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6215 -- Normal type conversions are allowed if argument is a variable
6217 elsif Nkind (AV) = N_Type_Conversion then
6218 if Is_Variable (Expression (AV))
6219 and then Paren_Count (Expression (AV)) = 0
6221 Note_Possible_Modification (Expression (AV), Sure => True);
6224 -- We also allow a non-parenthesized expression that raises
6225 -- constraint error if it rewrites what used to be a variable
6227 elsif Raises_Constraint_Error (Expression (AV))
6228 and then Paren_Count (Expression (AV)) = 0
6229 and then Is_Variable (Original_Node (Expression (AV)))
6233 -- Type conversion of something other than a variable
6239 -- If this node is rewritten, then test the original form, if that is
6240 -- OK, then we consider the rewritten node OK (for example, if the
6241 -- original node is a conversion, then Is_Variable will not be true
6242 -- but we still want to allow the conversion if it converts a variable).
6244 elsif Original_Node (AV) /= AV then
6245 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6247 -- All other non-variables are rejected
6252 end Is_OK_Variable_For_Out_Formal;
6254 -----------------------------------
6255 -- Is_Partially_Initialized_Type --
6256 -----------------------------------
6258 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6260 if Is_Scalar_Type (Typ) then
6263 elsif Is_Access_Type (Typ) then
6266 elsif Is_Array_Type (Typ) then
6268 -- If component type is partially initialized, so is array type
6270 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6273 -- Otherwise we are only partially initialized if we are fully
6274 -- initialized (this is the empty array case, no point in us
6275 -- duplicating that code here).
6278 return Is_Fully_Initialized_Type (Typ);
6281 elsif Is_Record_Type (Typ) then
6283 -- A discriminated type is always partially initialized
6285 if Has_Discriminants (Typ) then
6288 -- A tagged type is always partially initialized
6290 elsif Is_Tagged_Type (Typ) then
6293 -- Case of non-discriminated record
6299 Component_Present : Boolean := False;
6300 -- Set True if at least one component is present. If no
6301 -- components are present, then record type is fully
6302 -- initialized (another odd case, like the null array).
6305 -- Loop through components
6307 Ent := First_Entity (Typ);
6308 while Present (Ent) loop
6309 if Ekind (Ent) = E_Component then
6310 Component_Present := True;
6312 -- If a component has an initialization expression then
6313 -- the enclosing record type is partially initialized
6315 if Present (Parent (Ent))
6316 and then Present (Expression (Parent (Ent)))
6320 -- If a component is of a type which is itself partially
6321 -- initialized, then the enclosing record type is also.
6323 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6331 -- No initialized components found. If we found any components
6332 -- they were all uninitialized so the result is false.
6334 if Component_Present then
6337 -- But if we found no components, then all the components are
6338 -- initialized so we consider the type to be initialized.
6346 -- Concurrent types are always fully initialized
6348 elsif Is_Concurrent_Type (Typ) then
6351 -- For a private type, go to underlying type. If there is no underlying
6352 -- type then just assume this partially initialized. Not clear if this
6353 -- can happen in a non-error case, but no harm in testing for this.
6355 elsif Is_Private_Type (Typ) then
6357 U : constant Entity_Id := Underlying_Type (Typ);
6362 return Is_Partially_Initialized_Type (U);
6366 -- For any other type (are there any?) assume partially initialized
6371 end Is_Partially_Initialized_Type;
6373 ------------------------------------
6374 -- Is_Potentially_Persistent_Type --
6375 ------------------------------------
6377 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6382 -- For private type, test corresponding full type
6384 if Is_Private_Type (T) then
6385 return Is_Potentially_Persistent_Type (Full_View (T));
6387 -- Scalar types are potentially persistent
6389 elsif Is_Scalar_Type (T) then
6392 -- Record type is potentially persistent if not tagged and the types of
6393 -- all it components are potentially persistent, and no component has
6394 -- an initialization expression.
6396 elsif Is_Record_Type (T)
6397 and then not Is_Tagged_Type (T)
6398 and then not Is_Partially_Initialized_Type (T)
6400 Comp := First_Component (T);
6401 while Present (Comp) loop
6402 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6411 -- Array type is potentially persistent if its component type is
6412 -- potentially persistent and if all its constraints are static.
6414 elsif Is_Array_Type (T) then
6415 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6419 Indx := First_Index (T);
6420 while Present (Indx) loop
6421 if not Is_OK_Static_Subtype (Etype (Indx)) then
6430 -- All other types are not potentially persistent
6435 end Is_Potentially_Persistent_Type;
6437 ---------------------------------
6438 -- Is_Protected_Self_Reference --
6439 ---------------------------------
6441 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6443 function In_Access_Definition (N : Node_Id) return Boolean;
6444 -- Returns true if N belongs to an access definition
6446 --------------------------
6447 -- In_Access_Definition --
6448 --------------------------
6450 function In_Access_Definition (N : Node_Id) return Boolean is
6455 while Present (P) loop
6456 if Nkind (P) = N_Access_Definition then
6464 end In_Access_Definition;
6466 -- Start of processing for Is_Protected_Self_Reference
6469 -- Verify that prefix is analyzed and has the proper form. Note that
6470 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6471 -- produce the address of an entity, do not analyze their prefix
6472 -- because they denote entities that are not necessarily visible.
6473 -- Neither of them can apply to a protected type.
6475 return Ada_Version >= Ada_05
6476 and then Is_Entity_Name (N)
6477 and then Present (Entity (N))
6478 and then Is_Protected_Type (Entity (N))
6479 and then In_Open_Scopes (Entity (N))
6480 and then not In_Access_Definition (N);
6481 end Is_Protected_Self_Reference;
6483 -----------------------------
6484 -- Is_RCI_Pkg_Spec_Or_Body --
6485 -----------------------------
6487 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6489 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6490 -- Return True if the unit of Cunit is an RCI package declaration
6492 ---------------------------
6493 -- Is_RCI_Pkg_Decl_Cunit --
6494 ---------------------------
6496 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6497 The_Unit : constant Node_Id := Unit (Cunit);
6500 if Nkind (The_Unit) /= N_Package_Declaration then
6504 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6505 end Is_RCI_Pkg_Decl_Cunit;
6507 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6510 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6512 (Nkind (Unit (Cunit)) = N_Package_Body
6513 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6514 end Is_RCI_Pkg_Spec_Or_Body;
6516 -----------------------------------------
6517 -- Is_Remote_Access_To_Class_Wide_Type --
6518 -----------------------------------------
6520 function Is_Remote_Access_To_Class_Wide_Type
6521 (E : Entity_Id) return Boolean
6524 -- A remote access to class-wide type is a general access to object type
6525 -- declared in the visible part of a Remote_Types or Remote_Call_
6528 return Ekind (E) = E_General_Access_Type
6529 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6530 end Is_Remote_Access_To_Class_Wide_Type;
6532 -----------------------------------------
6533 -- Is_Remote_Access_To_Subprogram_Type --
6534 -----------------------------------------
6536 function Is_Remote_Access_To_Subprogram_Type
6537 (E : Entity_Id) return Boolean
6540 return (Ekind (E) = E_Access_Subprogram_Type
6541 or else (Ekind (E) = E_Record_Type
6542 and then Present (Corresponding_Remote_Type (E))))
6543 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6544 end Is_Remote_Access_To_Subprogram_Type;
6546 --------------------
6547 -- Is_Remote_Call --
6548 --------------------
6550 function Is_Remote_Call (N : Node_Id) return Boolean is
6552 if Nkind (N) /= N_Procedure_Call_Statement
6553 and then Nkind (N) /= N_Function_Call
6555 -- An entry call cannot be remote
6559 elsif Nkind (Name (N)) in N_Has_Entity
6560 and then Is_Remote_Call_Interface (Entity (Name (N)))
6562 -- A subprogram declared in the spec of a RCI package is remote
6566 elsif Nkind (Name (N)) = N_Explicit_Dereference
6567 and then Is_Remote_Access_To_Subprogram_Type
6568 (Etype (Prefix (Name (N))))
6570 -- The dereference of a RAS is a remote call
6574 elsif Present (Controlling_Argument (N))
6575 and then Is_Remote_Access_To_Class_Wide_Type
6576 (Etype (Controlling_Argument (N)))
6578 -- Any primitive operation call with a controlling argument of
6579 -- a RACW type is a remote call.
6584 -- All other calls are local calls
6589 ----------------------
6590 -- Is_Renamed_Entry --
6591 ----------------------
6593 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6594 Orig_Node : Node_Id := Empty;
6595 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6597 function Is_Entry (Nam : Node_Id) return Boolean;
6598 -- Determine whether Nam is an entry. Traverse selectors if there are
6599 -- nested selected components.
6605 function Is_Entry (Nam : Node_Id) return Boolean is
6607 if Nkind (Nam) = N_Selected_Component then
6608 return Is_Entry (Selector_Name (Nam));
6611 return Ekind (Entity (Nam)) = E_Entry;
6614 -- Start of processing for Is_Renamed_Entry
6617 if Present (Alias (Proc_Nam)) then
6618 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6621 -- Look for a rewritten subprogram renaming declaration
6623 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6624 and then Present (Original_Node (Subp_Decl))
6626 Orig_Node := Original_Node (Subp_Decl);
6629 -- The rewritten subprogram is actually an entry
6631 if Present (Orig_Node)
6632 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6633 and then Is_Entry (Name (Orig_Node))
6639 end Is_Renamed_Entry;
6641 ----------------------
6642 -- Is_Selector_Name --
6643 ----------------------
6645 function Is_Selector_Name (N : Node_Id) return Boolean is
6647 if not Is_List_Member (N) then
6649 P : constant Node_Id := Parent (N);
6650 K : constant Node_Kind := Nkind (P);
6653 (K = N_Expanded_Name or else
6654 K = N_Generic_Association or else
6655 K = N_Parameter_Association or else
6656 K = N_Selected_Component)
6657 and then Selector_Name (P) = N;
6662 L : constant List_Id := List_Containing (N);
6663 P : constant Node_Id := Parent (L);
6665 return (Nkind (P) = N_Discriminant_Association
6666 and then Selector_Names (P) = L)
6668 (Nkind (P) = N_Component_Association
6669 and then Choices (P) = L);
6672 end Is_Selector_Name;
6678 function Is_Statement (N : Node_Id) return Boolean is
6681 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6682 or else Nkind (N) = N_Procedure_Call_Statement;
6685 ---------------------------------
6686 -- Is_Synchronized_Tagged_Type --
6687 ---------------------------------
6689 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6690 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6693 -- A task or protected type derived from an interface is a tagged type.
6694 -- Such a tagged type is called a synchronized tagged type, as are
6695 -- synchronized interfaces and private extensions whose declaration
6696 -- includes the reserved word synchronized.
6698 return (Is_Tagged_Type (E)
6699 and then (Kind = E_Task_Type
6700 or else Kind = E_Protected_Type))
6703 and then Is_Synchronized_Interface (E))
6705 (Ekind (E) = E_Record_Type_With_Private
6706 and then (Synchronized_Present (Parent (E))
6707 or else Is_Synchronized_Interface (Etype (E))));
6708 end Is_Synchronized_Tagged_Type;
6714 function Is_Transfer (N : Node_Id) return Boolean is
6715 Kind : constant Node_Kind := Nkind (N);
6718 if Kind = N_Simple_Return_Statement
6720 Kind = N_Extended_Return_Statement
6722 Kind = N_Goto_Statement
6724 Kind = N_Raise_Statement
6726 Kind = N_Requeue_Statement
6730 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6731 and then No (Condition (N))
6735 elsif Kind = N_Procedure_Call_Statement
6736 and then Is_Entity_Name (Name (N))
6737 and then Present (Entity (Name (N)))
6738 and then No_Return (Entity (Name (N)))
6742 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6754 function Is_True (U : Uint) return Boolean is
6763 function Is_Value_Type (T : Entity_Id) return Boolean is
6765 return VM_Target = CLI_Target
6766 and then Chars (T) /= No_Name
6767 and then Get_Name_String (Chars (T)) = "valuetype";
6774 function Is_Variable (N : Node_Id) return Boolean is
6776 Orig_Node : constant Node_Id := Original_Node (N);
6777 -- We do the test on the original node, since this is basically a
6778 -- test of syntactic categories, so it must not be disturbed by
6779 -- whatever rewriting might have occurred. For example, an aggregate,
6780 -- which is certainly NOT a variable, could be turned into a variable
6783 function In_Protected_Function (E : Entity_Id) return Boolean;
6784 -- Within a protected function, the private components of the
6785 -- enclosing protected type are constants. A function nested within
6786 -- a (protected) procedure is not itself protected.
6788 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6789 -- Prefixes can involve implicit dereferences, in which case we
6790 -- must test for the case of a reference of a constant access
6791 -- type, which can never be a variable.
6793 ---------------------------
6794 -- In_Protected_Function --
6795 ---------------------------
6797 function In_Protected_Function (E : Entity_Id) return Boolean is
6798 Prot : constant Entity_Id := Scope (E);
6802 if not Is_Protected_Type (Prot) then
6806 while Present (S) and then S /= Prot loop
6807 if Ekind (S) = E_Function
6808 and then Scope (S) = Prot
6818 end In_Protected_Function;
6820 ------------------------
6821 -- Is_Variable_Prefix --
6822 ------------------------
6824 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6826 if Is_Access_Type (Etype (P)) then
6827 return not Is_Access_Constant (Root_Type (Etype (P)));
6829 -- For the case of an indexed component whose prefix has a packed
6830 -- array type, the prefix has been rewritten into a type conversion.
6831 -- Determine variable-ness from the converted expression.
6833 elsif Nkind (P) = N_Type_Conversion
6834 and then not Comes_From_Source (P)
6835 and then Is_Array_Type (Etype (P))
6836 and then Is_Packed (Etype (P))
6838 return Is_Variable (Expression (P));
6841 return Is_Variable (P);
6843 end Is_Variable_Prefix;
6845 -- Start of processing for Is_Variable
6848 -- Definitely OK if Assignment_OK is set. Since this is something that
6849 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6851 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6854 -- Normally we go to the original node, but there is one exception
6855 -- where we use the rewritten node, namely when it is an explicit
6856 -- dereference. The generated code may rewrite a prefix which is an
6857 -- access type with an explicit dereference. The dereference is a
6858 -- variable, even though the original node may not be (since it could
6859 -- be a constant of the access type).
6861 -- In Ada 2005 we have a further case to consider: the prefix may be
6862 -- a function call given in prefix notation. The original node appears
6863 -- to be a selected component, but we need to examine the call.
6865 elsif Nkind (N) = N_Explicit_Dereference
6866 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6867 and then Present (Etype (Orig_Node))
6868 and then Is_Access_Type (Etype (Orig_Node))
6870 -- Note that if the prefix is an explicit dereference that does not
6871 -- come from source, we must check for a rewritten function call in
6872 -- prefixed notation before other forms of rewriting, to prevent a
6876 (Nkind (Orig_Node) = N_Function_Call
6877 and then not Is_Access_Constant (Etype (Prefix (N))))
6879 Is_Variable_Prefix (Original_Node (Prefix (N)));
6881 -- A function call is never a variable
6883 elsif Nkind (N) = N_Function_Call then
6886 -- All remaining checks use the original node
6888 elsif Is_Entity_Name (Orig_Node)
6889 and then Present (Entity (Orig_Node))
6892 E : constant Entity_Id := Entity (Orig_Node);
6893 K : constant Entity_Kind := Ekind (E);
6896 return (K = E_Variable
6897 and then Nkind (Parent (E)) /= N_Exception_Handler)
6898 or else (K = E_Component
6899 and then not In_Protected_Function (E))
6900 or else K = E_Out_Parameter
6901 or else K = E_In_Out_Parameter
6902 or else K = E_Generic_In_Out_Parameter
6904 -- Current instance of type:
6906 or else (Is_Type (E) and then In_Open_Scopes (E))
6907 or else (Is_Incomplete_Or_Private_Type (E)
6908 and then In_Open_Scopes (Full_View (E)));
6912 case Nkind (Orig_Node) is
6913 when N_Indexed_Component | N_Slice =>
6914 return Is_Variable_Prefix (Prefix (Orig_Node));
6916 when N_Selected_Component =>
6917 return Is_Variable_Prefix (Prefix (Orig_Node))
6918 and then Is_Variable (Selector_Name (Orig_Node));
6920 -- For an explicit dereference, the type of the prefix cannot
6921 -- be an access to constant or an access to subprogram.
6923 when N_Explicit_Dereference =>
6925 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6927 return Is_Access_Type (Typ)
6928 and then not Is_Access_Constant (Root_Type (Typ))
6929 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6932 -- The type conversion is the case where we do not deal with the
6933 -- context dependent special case of an actual parameter. Thus
6934 -- the type conversion is only considered a variable for the
6935 -- purposes of this routine if the target type is tagged. However,
6936 -- a type conversion is considered to be a variable if it does not
6937 -- come from source (this deals for example with the conversions
6938 -- of expressions to their actual subtypes).
6940 when N_Type_Conversion =>
6941 return Is_Variable (Expression (Orig_Node))
6943 (not Comes_From_Source (Orig_Node)
6945 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6947 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6949 -- GNAT allows an unchecked type conversion as a variable. This
6950 -- only affects the generation of internal expanded code, since
6951 -- calls to instantiations of Unchecked_Conversion are never
6952 -- considered variables (since they are function calls).
6953 -- This is also true for expression actions.
6955 when N_Unchecked_Type_Conversion =>
6956 return Is_Variable (Expression (Orig_Node));
6964 ------------------------
6965 -- Is_Volatile_Object --
6966 ------------------------
6968 function Is_Volatile_Object (N : Node_Id) return Boolean is
6970 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6971 -- Determines if given object has volatile components
6973 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6974 -- If prefix is an implicit dereference, examine designated type
6976 ------------------------
6977 -- Is_Volatile_Prefix --
6978 ------------------------
6980 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6981 Typ : constant Entity_Id := Etype (N);
6984 if Is_Access_Type (Typ) then
6986 Dtyp : constant Entity_Id := Designated_Type (Typ);
6989 return Is_Volatile (Dtyp)
6990 or else Has_Volatile_Components (Dtyp);
6994 return Object_Has_Volatile_Components (N);
6996 end Is_Volatile_Prefix;
6998 ------------------------------------
6999 -- Object_Has_Volatile_Components --
7000 ------------------------------------
7002 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7003 Typ : constant Entity_Id := Etype (N);
7006 if Is_Volatile (Typ)
7007 or else Has_Volatile_Components (Typ)
7011 elsif Is_Entity_Name (N)
7012 and then (Has_Volatile_Components (Entity (N))
7013 or else Is_Volatile (Entity (N)))
7017 elsif Nkind (N) = N_Indexed_Component
7018 or else Nkind (N) = N_Selected_Component
7020 return Is_Volatile_Prefix (Prefix (N));
7025 end Object_Has_Volatile_Components;
7027 -- Start of processing for Is_Volatile_Object
7030 if Is_Volatile (Etype (N))
7031 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7035 elsif Nkind (N) = N_Indexed_Component
7036 or else Nkind (N) = N_Selected_Component
7038 return Is_Volatile_Prefix (Prefix (N));
7043 end Is_Volatile_Object;
7045 -------------------------
7046 -- Kill_Current_Values --
7047 -------------------------
7049 procedure Kill_Current_Values
7051 Last_Assignment_Only : Boolean := False)
7054 if Is_Assignable (Ent) then
7055 Set_Last_Assignment (Ent, Empty);
7058 if not Last_Assignment_Only and then Is_Object (Ent) then
7060 Set_Current_Value (Ent, Empty);
7062 if not Can_Never_Be_Null (Ent) then
7063 Set_Is_Known_Non_Null (Ent, False);
7066 Set_Is_Known_Null (Ent, False);
7068 end Kill_Current_Values;
7070 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7073 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7074 -- Clear current value for entity E and all entities chained to E
7076 ------------------------------------------
7077 -- Kill_Current_Values_For_Entity_Chain --
7078 ------------------------------------------
7080 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7084 while Present (Ent) loop
7085 Kill_Current_Values (Ent, Last_Assignment_Only);
7088 end Kill_Current_Values_For_Entity_Chain;
7090 -- Start of processing for Kill_Current_Values
7093 -- Kill all saved checks, a special case of killing saved values
7095 if not Last_Assignment_Only then
7099 -- Loop through relevant scopes, which includes the current scope and
7100 -- any parent scopes if the current scope is a block or a package.
7105 -- Clear current values of all entities in current scope
7107 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7109 -- If scope is a package, also clear current values of all
7110 -- private entities in the scope.
7112 if Is_Package_Or_Generic_Package (S)
7113 or else Is_Concurrent_Type (S)
7115 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7118 -- If this is a not a subprogram, deal with parents
7120 if not Is_Subprogram (S) then
7122 exit Scope_Loop when S = Standard_Standard;
7126 end loop Scope_Loop;
7127 end Kill_Current_Values;
7129 --------------------------
7130 -- Kill_Size_Check_Code --
7131 --------------------------
7133 procedure Kill_Size_Check_Code (E : Entity_Id) is
7135 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7136 and then Present (Size_Check_Code (E))
7138 Remove (Size_Check_Code (E));
7139 Set_Size_Check_Code (E, Empty);
7141 end Kill_Size_Check_Code;
7143 --------------------------
7144 -- Known_To_Be_Assigned --
7145 --------------------------
7147 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7148 P : constant Node_Id := Parent (N);
7153 -- Test left side of assignment
7155 when N_Assignment_Statement =>
7156 return N = Name (P);
7158 -- Function call arguments are never lvalues
7160 when N_Function_Call =>
7163 -- Positional parameter for procedure or accept call
7165 when N_Procedure_Call_Statement |
7174 Proc := Get_Subprogram_Entity (P);
7180 -- If we are not a list member, something is strange, so
7181 -- be conservative and return False.
7183 if not Is_List_Member (N) then
7187 -- We are going to find the right formal by stepping forward
7188 -- through the formals, as we step backwards in the actuals.
7190 Form := First_Formal (Proc);
7193 -- If no formal, something is weird, so be conservative
7194 -- and return False.
7205 return Ekind (Form) /= E_In_Parameter;
7208 -- Named parameter for procedure or accept call
7210 when N_Parameter_Association =>
7216 Proc := Get_Subprogram_Entity (Parent (P));
7222 -- Loop through formals to find the one that matches
7224 Form := First_Formal (Proc);
7226 -- If no matching formal, that's peculiar, some kind of
7227 -- previous error, so return False to be conservative.
7233 -- Else test for match
7235 if Chars (Form) = Chars (Selector_Name (P)) then
7236 return Ekind (Form) /= E_In_Parameter;
7243 -- Test for appearing in a conversion that itself appears
7244 -- in an lvalue context, since this should be an lvalue.
7246 when N_Type_Conversion =>
7247 return Known_To_Be_Assigned (P);
7249 -- All other references are definitely not known to be modifications
7255 end Known_To_Be_Assigned;
7261 function May_Be_Lvalue (N : Node_Id) return Boolean is
7262 P : constant Node_Id := Parent (N);
7267 -- Test left side of assignment
7269 when N_Assignment_Statement =>
7270 return N = Name (P);
7272 -- Test prefix of component or attribute. Note that the prefix of an
7273 -- explicit or implicit dereference cannot be an l-value.
7275 when N_Attribute_Reference =>
7276 return N = Prefix (P)
7277 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7279 -- For an expanded name, the name is an lvalue if the expanded name
7280 -- is an lvalue, but the prefix is never an lvalue, since it is just
7281 -- the scope where the name is found.
7283 when N_Expanded_Name =>
7284 if N = Prefix (P) then
7285 return May_Be_Lvalue (P);
7290 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7291 -- B is a little interesting, if we have A.B := 3, there is some
7292 -- discussion as to whether B is an lvalue or not, we choose to say
7293 -- it is. Note however that A is not an lvalue if it is of an access
7294 -- type since this is an implicit dereference.
7296 when N_Selected_Component =>
7298 and then Present (Etype (N))
7299 and then Is_Access_Type (Etype (N))
7303 return May_Be_Lvalue (P);
7306 -- For an indexed component or slice, the index or slice bounds is
7307 -- never an lvalue. The prefix is an lvalue if the indexed component
7308 -- or slice is an lvalue, except if it is an access type, where we
7309 -- have an implicit dereference.
7311 when N_Indexed_Component =>
7313 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7317 return May_Be_Lvalue (P);
7320 -- Prefix of a reference is an lvalue if the reference is an lvalue
7323 return May_Be_Lvalue (P);
7325 -- Prefix of explicit dereference is never an lvalue
7327 when N_Explicit_Dereference =>
7330 -- Function call arguments are never lvalues
7332 when N_Function_Call =>
7335 -- Positional parameter for procedure, entry, or accept call
7337 when N_Procedure_Call_Statement |
7338 N_Entry_Call_Statement |
7347 Proc := Get_Subprogram_Entity (P);
7353 -- If we are not a list member, something is strange, so
7354 -- be conservative and return True.
7356 if not Is_List_Member (N) then
7360 -- We are going to find the right formal by stepping forward
7361 -- through the formals, as we step backwards in the actuals.
7363 Form := First_Formal (Proc);
7366 -- If no formal, something is weird, so be conservative
7378 return Ekind (Form) /= E_In_Parameter;
7381 -- Named parameter for procedure or accept call
7383 when N_Parameter_Association =>
7389 Proc := Get_Subprogram_Entity (Parent (P));
7395 -- Loop through formals to find the one that matches
7397 Form := First_Formal (Proc);
7399 -- If no matching formal, that's peculiar, some kind of
7400 -- previous error, so return True to be conservative.
7406 -- Else test for match
7408 if Chars (Form) = Chars (Selector_Name (P)) then
7409 return Ekind (Form) /= E_In_Parameter;
7416 -- Test for appearing in a conversion that itself appears in an
7417 -- lvalue context, since this should be an lvalue.
7419 when N_Type_Conversion =>
7420 return May_Be_Lvalue (P);
7422 -- Test for appearance in object renaming declaration
7424 when N_Object_Renaming_Declaration =>
7427 -- All other references are definitely not lvalues
7435 -----------------------
7436 -- Mark_Coextensions --
7437 -----------------------
7439 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7440 Is_Dynamic : Boolean;
7441 -- Indicates whether the context causes nested coextensions to be
7442 -- dynamic or static
7444 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7445 -- Recognize an allocator node and label it as a dynamic coextension
7447 --------------------
7448 -- Mark_Allocator --
7449 --------------------
7451 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7453 if Nkind (N) = N_Allocator then
7455 Set_Is_Dynamic_Coextension (N);
7457 Set_Is_Static_Coextension (N);
7464 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7466 -- Start of processing Mark_Coextensions
7469 case Nkind (Context_Nod) is
7470 when N_Assignment_Statement |
7471 N_Simple_Return_Statement =>
7472 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7474 when N_Object_Declaration =>
7475 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7477 -- This routine should not be called for constructs which may not
7478 -- contain coextensions.
7481 raise Program_Error;
7484 Mark_Allocators (Root_Nod);
7485 end Mark_Coextensions;
7487 ----------------------
7488 -- Needs_One_Actual --
7489 ----------------------
7491 function Needs_One_Actual (E : Entity_Id) return Boolean is
7495 if Ada_Version >= Ada_05
7496 and then Present (First_Formal (E))
7498 Formal := Next_Formal (First_Formal (E));
7499 while Present (Formal) loop
7500 if No (Default_Value (Formal)) then
7504 Next_Formal (Formal);
7512 end Needs_One_Actual;
7514 ------------------------
7515 -- New_Copy_List_Tree --
7516 ------------------------
7518 function New_Copy_List_Tree (List : List_Id) return List_Id is
7523 if List = No_List then
7530 while Present (E) loop
7531 Append (New_Copy_Tree (E), NL);
7537 end New_Copy_List_Tree;
7543 use Atree.Unchecked_Access;
7544 use Atree_Private_Part;
7546 -- Our approach here requires a two pass traversal of the tree. The
7547 -- first pass visits all nodes that eventually will be copied looking
7548 -- for defining Itypes. If any defining Itypes are found, then they are
7549 -- copied, and an entry is added to the replacement map. In the second
7550 -- phase, the tree is copied, using the replacement map to replace any
7551 -- Itype references within the copied tree.
7553 -- The following hash tables are used if the Map supplied has more
7554 -- than hash threshhold entries to speed up access to the map. If
7555 -- there are fewer entries, then the map is searched sequentially
7556 -- (because setting up a hash table for only a few entries takes
7557 -- more time than it saves.
7559 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7560 -- Hash function used for hash operations
7566 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7568 return Nat (E) mod (NCT_Header_Num'Last + 1);
7575 -- The hash table NCT_Assoc associates old entities in the table
7576 -- with their corresponding new entities (i.e. the pairs of entries
7577 -- presented in the original Map argument are Key-Element pairs).
7579 package NCT_Assoc is new Simple_HTable (
7580 Header_Num => NCT_Header_Num,
7581 Element => Entity_Id,
7582 No_Element => Empty,
7584 Hash => New_Copy_Hash,
7585 Equal => Types."=");
7587 ---------------------
7588 -- NCT_Itype_Assoc --
7589 ---------------------
7591 -- The hash table NCT_Itype_Assoc contains entries only for those
7592 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7593 -- The key is the associated node, and the element is the new node
7594 -- itself (NOT the associated node for the new node).
7596 package NCT_Itype_Assoc is new Simple_HTable (
7597 Header_Num => NCT_Header_Num,
7598 Element => Entity_Id,
7599 No_Element => Empty,
7601 Hash => New_Copy_Hash,
7602 Equal => Types."=");
7604 -- Start of processing for New_Copy_Tree function
7606 function New_Copy_Tree
7608 Map : Elist_Id := No_Elist;
7609 New_Sloc : Source_Ptr := No_Location;
7610 New_Scope : Entity_Id := Empty) return Node_Id
7612 Actual_Map : Elist_Id := Map;
7613 -- This is the actual map for the copy. It is initialized with the
7614 -- given elements, and then enlarged as required for Itypes that are
7615 -- copied during the first phase of the copy operation. The visit
7616 -- procedures add elements to this map as Itypes are encountered.
7617 -- The reason we cannot use Map directly, is that it may well be
7618 -- (and normally is) initialized to No_Elist, and if we have mapped
7619 -- entities, we have to reset it to point to a real Elist.
7621 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
7622 -- Called during second phase to map entities into their corresponding
7623 -- copies using Actual_Map. If the argument is not an entity, or is not
7624 -- in Actual_Map, then it is returned unchanged.
7626 procedure Build_NCT_Hash_Tables;
7627 -- Builds hash tables (number of elements >= threshold value)
7629 function Copy_Elist_With_Replacement
7630 (Old_Elist : Elist_Id) return Elist_Id;
7631 -- Called during second phase to copy element list doing replacements
7633 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
7634 -- Called during the second phase to process a copied Itype. The actual
7635 -- copy happened during the first phase (so that we could make the entry
7636 -- in the mapping), but we still have to deal with the descendents of
7637 -- the copied Itype and copy them where necessary.
7639 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
7640 -- Called during second phase to copy list doing replacements
7642 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
7643 -- Called during second phase to copy node doing replacements
7645 procedure Visit_Elist (E : Elist_Id);
7646 -- Called during first phase to visit all elements of an Elist
7648 procedure Visit_Field (F : Union_Id; N : Node_Id);
7649 -- Visit a single field, recursing to call Visit_Node or Visit_List
7650 -- if the field is a syntactic descendent of the current node (i.e.
7651 -- its parent is Node N).
7653 procedure Visit_Itype (Old_Itype : Entity_Id);
7654 -- Called during first phase to visit subsidiary fields of a defining
7655 -- Itype, and also create a copy and make an entry in the replacement
7656 -- map for the new copy.
7658 procedure Visit_List (L : List_Id);
7659 -- Called during first phase to visit all elements of a List
7661 procedure Visit_Node (N : Node_Or_Entity_Id);
7662 -- Called during first phase to visit a node and all its subtrees
7668 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
7673 if not Has_Extension (N) or else No (Actual_Map) then
7676 elsif NCT_Hash_Tables_Used then
7677 Ent := NCT_Assoc.Get (Entity_Id (N));
7679 if Present (Ent) then
7685 -- No hash table used, do serial search
7688 E := First_Elmt (Actual_Map);
7689 while Present (E) loop
7690 if Node (E) = N then
7691 return Node (Next_Elmt (E));
7693 E := Next_Elmt (Next_Elmt (E));
7701 ---------------------------
7702 -- Build_NCT_Hash_Tables --
7703 ---------------------------
7705 procedure Build_NCT_Hash_Tables is
7709 if NCT_Hash_Table_Setup then
7711 NCT_Itype_Assoc.Reset;
7714 Elmt := First_Elmt (Actual_Map);
7715 while Present (Elmt) loop
7718 -- Get new entity, and associate old and new
7721 NCT_Assoc.Set (Ent, Node (Elmt));
7723 if Is_Type (Ent) then
7725 Anode : constant Entity_Id :=
7726 Associated_Node_For_Itype (Ent);
7729 if Present (Anode) then
7731 -- Enter a link between the associated node of the
7732 -- old Itype and the new Itype, for updating later
7733 -- when node is copied.
7735 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
7743 NCT_Hash_Tables_Used := True;
7744 NCT_Hash_Table_Setup := True;
7745 end Build_NCT_Hash_Tables;
7747 ---------------------------------
7748 -- Copy_Elist_With_Replacement --
7749 ---------------------------------
7751 function Copy_Elist_With_Replacement
7752 (Old_Elist : Elist_Id) return Elist_Id
7755 New_Elist : Elist_Id;
7758 if No (Old_Elist) then
7762 New_Elist := New_Elmt_List;
7764 M := First_Elmt (Old_Elist);
7765 while Present (M) loop
7766 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
7772 end Copy_Elist_With_Replacement;
7774 ---------------------------------
7775 -- Copy_Itype_With_Replacement --
7776 ---------------------------------
7778 -- This routine exactly parallels its phase one analog Visit_Itype,
7780 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
7782 -- Translate Next_Entity, Scope and Etype fields, in case they
7783 -- reference entities that have been mapped into copies.
7785 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
7786 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
7788 if Present (New_Scope) then
7789 Set_Scope (New_Itype, New_Scope);
7791 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
7794 -- Copy referenced fields
7796 if Is_Discrete_Type (New_Itype) then
7797 Set_Scalar_Range (New_Itype,
7798 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
7800 elsif Has_Discriminants (Base_Type (New_Itype)) then
7801 Set_Discriminant_Constraint (New_Itype,
7802 Copy_Elist_With_Replacement
7803 (Discriminant_Constraint (New_Itype)));
7805 elsif Is_Array_Type (New_Itype) then
7806 if Present (First_Index (New_Itype)) then
7807 Set_First_Index (New_Itype,
7808 First (Copy_List_With_Replacement
7809 (List_Containing (First_Index (New_Itype)))));
7812 if Is_Packed (New_Itype) then
7813 Set_Packed_Array_Type (New_Itype,
7814 Copy_Node_With_Replacement
7815 (Packed_Array_Type (New_Itype)));
7818 end Copy_Itype_With_Replacement;
7820 --------------------------------
7821 -- Copy_List_With_Replacement --
7822 --------------------------------
7824 function Copy_List_With_Replacement
7825 (Old_List : List_Id) return List_Id
7831 if Old_List = No_List then
7835 New_List := Empty_List;
7837 E := First (Old_List);
7838 while Present (E) loop
7839 Append (Copy_Node_With_Replacement (E), New_List);
7845 end Copy_List_With_Replacement;
7847 --------------------------------
7848 -- Copy_Node_With_Replacement --
7849 --------------------------------
7851 function Copy_Node_With_Replacement
7852 (Old_Node : Node_Id) return Node_Id
7856 procedure Adjust_Named_Associations
7857 (Old_Node : Node_Id;
7858 New_Node : Node_Id);
7859 -- If a call node has named associations, these are chained through
7860 -- the First_Named_Actual, Next_Named_Actual links. These must be
7861 -- propagated separately to the new parameter list, because these
7862 -- are not syntactic fields.
7864 function Copy_Field_With_Replacement
7865 (Field : Union_Id) return Union_Id;
7866 -- Given Field, which is a field of Old_Node, return a copy of it
7867 -- if it is a syntactic field (i.e. its parent is Node), setting
7868 -- the parent of the copy to poit to New_Node. Otherwise returns
7869 -- the field (possibly mapped if it is an entity).
7871 -------------------------------
7872 -- Adjust_Named_Associations --
7873 -------------------------------
7875 procedure Adjust_Named_Associations
7876 (Old_Node : Node_Id;
7886 Old_E := First (Parameter_Associations (Old_Node));
7887 New_E := First (Parameter_Associations (New_Node));
7888 while Present (Old_E) loop
7889 if Nkind (Old_E) = N_Parameter_Association
7890 and then Present (Next_Named_Actual (Old_E))
7892 if First_Named_Actual (Old_Node)
7893 = Explicit_Actual_Parameter (Old_E)
7895 Set_First_Named_Actual
7896 (New_Node, Explicit_Actual_Parameter (New_E));
7899 -- Now scan parameter list from the beginning,to locate
7900 -- next named actual, which can be out of order.
7902 Old_Next := First (Parameter_Associations (Old_Node));
7903 New_Next := First (Parameter_Associations (New_Node));
7905 while Nkind (Old_Next) /= N_Parameter_Association
7906 or else Explicit_Actual_Parameter (Old_Next)
7907 /= Next_Named_Actual (Old_E)
7913 Set_Next_Named_Actual
7914 (New_E, Explicit_Actual_Parameter (New_Next));
7920 end Adjust_Named_Associations;
7922 ---------------------------------
7923 -- Copy_Field_With_Replacement --
7924 ---------------------------------
7926 function Copy_Field_With_Replacement
7927 (Field : Union_Id) return Union_Id
7930 if Field = Union_Id (Empty) then
7933 elsif Field in Node_Range then
7935 Old_N : constant Node_Id := Node_Id (Field);
7939 -- If syntactic field, as indicated by the parent pointer
7940 -- being set, then copy the referenced node recursively.
7942 if Parent (Old_N) = Old_Node then
7943 New_N := Copy_Node_With_Replacement (Old_N);
7945 if New_N /= Old_N then
7946 Set_Parent (New_N, New_Node);
7949 -- For semantic fields, update possible entity reference
7950 -- from the replacement map.
7953 New_N := Assoc (Old_N);
7956 return Union_Id (New_N);
7959 elsif Field in List_Range then
7961 Old_L : constant List_Id := List_Id (Field);
7965 -- If syntactic field, as indicated by the parent pointer,
7966 -- then recursively copy the entire referenced list.
7968 if Parent (Old_L) = Old_Node then
7969 New_L := Copy_List_With_Replacement (Old_L);
7970 Set_Parent (New_L, New_Node);
7972 -- For semantic list, just returned unchanged
7978 return Union_Id (New_L);
7981 -- Anything other than a list or a node is returned unchanged
7986 end Copy_Field_With_Replacement;
7988 -- Start of processing for Copy_Node_With_Replacement
7991 if Old_Node <= Empty_Or_Error then
7994 elsif Has_Extension (Old_Node) then
7995 return Assoc (Old_Node);
7998 New_Node := New_Copy (Old_Node);
8000 -- If the node we are copying is the associated node of a
8001 -- previously copied Itype, then adjust the associated node
8002 -- of the copy of that Itype accordingly.
8004 if Present (Actual_Map) then
8010 -- Case of hash table used
8012 if NCT_Hash_Tables_Used then
8013 Ent := NCT_Itype_Assoc.Get (Old_Node);
8015 if Present (Ent) then
8016 Set_Associated_Node_For_Itype (Ent, New_Node);
8019 -- Case of no hash table used
8022 E := First_Elmt (Actual_Map);
8023 while Present (E) loop
8024 if Is_Itype (Node (E))
8026 Old_Node = Associated_Node_For_Itype (Node (E))
8028 Set_Associated_Node_For_Itype
8029 (Node (Next_Elmt (E)), New_Node);
8032 E := Next_Elmt (Next_Elmt (E));
8038 -- Recursively copy descendents
8041 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8043 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8045 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8047 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8049 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8051 -- Adjust Sloc of new node if necessary
8053 if New_Sloc /= No_Location then
8054 Set_Sloc (New_Node, New_Sloc);
8056 -- If we adjust the Sloc, then we are essentially making
8057 -- a completely new node, so the Comes_From_Source flag
8058 -- should be reset to the proper default value.
8060 Nodes.Table (New_Node).Comes_From_Source :=
8061 Default_Node.Comes_From_Source;
8064 -- If the node is call and has named associations,
8065 -- set the corresponding links in the copy.
8067 if (Nkind (Old_Node) = N_Function_Call
8068 or else Nkind (Old_Node) = N_Entry_Call_Statement
8070 Nkind (Old_Node) = N_Procedure_Call_Statement)
8071 and then Present (First_Named_Actual (Old_Node))
8073 Adjust_Named_Associations (Old_Node, New_Node);
8076 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8077 -- The replacement mechanism applies to entities, and is not used
8078 -- here. Eventually we may need a more general graph-copying
8079 -- routine. For now, do a sequential search to find desired node.
8081 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8082 and then Present (First_Real_Statement (Old_Node))
8085 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8089 N1 := First (Statements (Old_Node));
8090 N2 := First (Statements (New_Node));
8092 while N1 /= Old_F loop
8097 Set_First_Real_Statement (New_Node, N2);
8102 -- All done, return copied node
8105 end Copy_Node_With_Replacement;
8111 procedure Visit_Elist (E : Elist_Id) is
8115 Elmt := First_Elmt (E);
8117 while Elmt /= No_Elmt loop
8118 Visit_Node (Node (Elmt));
8128 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8130 if F = Union_Id (Empty) then
8133 elsif F in Node_Range then
8135 -- Copy node if it is syntactic, i.e. its parent pointer is
8136 -- set to point to the field that referenced it (certain
8137 -- Itypes will also meet this criterion, which is fine, since
8138 -- these are clearly Itypes that do need to be copied, since
8139 -- we are copying their parent.)
8141 if Parent (Node_Id (F)) = N then
8142 Visit_Node (Node_Id (F));
8145 -- Another case, if we are pointing to an Itype, then we want
8146 -- to copy it if its associated node is somewhere in the tree
8149 -- Note: the exclusion of self-referential copies is just an
8150 -- optimization, since the search of the already copied list
8151 -- would catch it, but it is a common case (Etype pointing
8152 -- to itself for an Itype that is a base type).
8154 elsif Has_Extension (Node_Id (F))
8155 and then Is_Itype (Entity_Id (F))
8156 and then Node_Id (F) /= N
8162 P := Associated_Node_For_Itype (Node_Id (F));
8163 while Present (P) loop
8165 Visit_Node (Node_Id (F));
8172 -- An Itype whose parent is not being copied definitely
8173 -- should NOT be copied, since it does not belong in any
8174 -- sense to the copied subtree.
8180 elsif F in List_Range
8181 and then Parent (List_Id (F)) = N
8183 Visit_List (List_Id (F));
8192 procedure Visit_Itype (Old_Itype : Entity_Id) is
8193 New_Itype : Entity_Id;
8198 -- Itypes that describe the designated type of access to subprograms
8199 -- have the structure of subprogram declarations, with signatures,
8200 -- etc. Either we duplicate the signatures completely, or choose to
8201 -- share such itypes, which is fine because their elaboration will
8202 -- have no side effects.
8204 if Ekind (Old_Itype) = E_Subprogram_Type then
8208 New_Itype := New_Copy (Old_Itype);
8210 -- The new Itype has all the attributes of the old one, and
8211 -- we just copy the contents of the entity. However, the back-end
8212 -- needs different names for debugging purposes, so we create a
8213 -- new internal name for it in all cases.
8215 Set_Chars (New_Itype, New_Internal_Name ('T'));
8217 -- If our associated node is an entity that has already been copied,
8218 -- then set the associated node of the copy to point to the right
8219 -- copy. If we have copied an Itype that is itself the associated
8220 -- node of some previously copied Itype, then we set the right
8221 -- pointer in the other direction.
8223 if Present (Actual_Map) then
8225 -- Case of hash tables used
8227 if NCT_Hash_Tables_Used then
8229 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8231 if Present (Ent) then
8232 Set_Associated_Node_For_Itype (New_Itype, Ent);
8235 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8236 if Present (Ent) then
8237 Set_Associated_Node_For_Itype (Ent, New_Itype);
8239 -- If the hash table has no association for this Itype and
8240 -- its associated node, enter one now.
8244 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8247 -- Case of hash tables not used
8250 E := First_Elmt (Actual_Map);
8251 while Present (E) loop
8252 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8253 Set_Associated_Node_For_Itype
8254 (New_Itype, Node (Next_Elmt (E)));
8257 if Is_Type (Node (E))
8259 Old_Itype = Associated_Node_For_Itype (Node (E))
8261 Set_Associated_Node_For_Itype
8262 (Node (Next_Elmt (E)), New_Itype);
8265 E := Next_Elmt (Next_Elmt (E));
8270 if Present (Freeze_Node (New_Itype)) then
8271 Set_Is_Frozen (New_Itype, False);
8272 Set_Freeze_Node (New_Itype, Empty);
8275 -- Add new association to map
8277 if No (Actual_Map) then
8278 Actual_Map := New_Elmt_List;
8281 Append_Elmt (Old_Itype, Actual_Map);
8282 Append_Elmt (New_Itype, Actual_Map);
8284 if NCT_Hash_Tables_Used then
8285 NCT_Assoc.Set (Old_Itype, New_Itype);
8288 NCT_Table_Entries := NCT_Table_Entries + 1;
8290 if NCT_Table_Entries > NCT_Hash_Threshhold then
8291 Build_NCT_Hash_Tables;
8295 -- If a record subtype is simply copied, the entity list will be
8296 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8298 if Ekind (Old_Itype) = E_Record_Subtype
8299 or else Ekind (Old_Itype) = E_Class_Wide_Subtype
8301 Set_Cloned_Subtype (New_Itype, Old_Itype);
8304 -- Visit descendents that eventually get copied
8306 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8308 if Is_Discrete_Type (Old_Itype) then
8309 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8311 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8312 -- ??? This should involve call to Visit_Field
8313 Visit_Elist (Discriminant_Constraint (Old_Itype));
8315 elsif Is_Array_Type (Old_Itype) then
8316 if Present (First_Index (Old_Itype)) then
8317 Visit_Field (Union_Id (List_Containing
8318 (First_Index (Old_Itype))),
8322 if Is_Packed (Old_Itype) then
8323 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8333 procedure Visit_List (L : List_Id) is
8336 if L /= No_List then
8339 while Present (N) loop
8350 procedure Visit_Node (N : Node_Or_Entity_Id) is
8352 -- Start of processing for Visit_Node
8355 -- Handle case of an Itype, which must be copied
8357 if Has_Extension (N)
8358 and then Is_Itype (N)
8360 -- Nothing to do if already in the list. This can happen with an
8361 -- Itype entity that appears more than once in the tree.
8362 -- Note that we do not want to visit descendents in this case.
8364 -- Test for already in list when hash table is used
8366 if NCT_Hash_Tables_Used then
8367 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8371 -- Test for already in list when hash table not used
8377 if Present (Actual_Map) then
8378 E := First_Elmt (Actual_Map);
8379 while Present (E) loop
8380 if Node (E) = N then
8383 E := Next_Elmt (Next_Elmt (E));
8393 -- Visit descendents
8395 Visit_Field (Field1 (N), N);
8396 Visit_Field (Field2 (N), N);
8397 Visit_Field (Field3 (N), N);
8398 Visit_Field (Field4 (N), N);
8399 Visit_Field (Field5 (N), N);
8402 -- Start of processing for New_Copy_Tree
8407 -- See if we should use hash table
8409 if No (Actual_Map) then
8410 NCT_Hash_Tables_Used := False;
8417 NCT_Table_Entries := 0;
8419 Elmt := First_Elmt (Actual_Map);
8420 while Present (Elmt) loop
8421 NCT_Table_Entries := NCT_Table_Entries + 1;
8426 if NCT_Table_Entries > NCT_Hash_Threshhold then
8427 Build_NCT_Hash_Tables;
8429 NCT_Hash_Tables_Used := False;
8434 -- Hash table set up if required, now start phase one by visiting
8435 -- top node (we will recursively visit the descendents).
8437 Visit_Node (Source);
8439 -- Now the second phase of the copy can start. First we process
8440 -- all the mapped entities, copying their descendents.
8442 if Present (Actual_Map) then
8445 New_Itype : Entity_Id;
8447 Elmt := First_Elmt (Actual_Map);
8448 while Present (Elmt) loop
8450 New_Itype := Node (Elmt);
8451 Copy_Itype_With_Replacement (New_Itype);
8457 -- Now we can copy the actual tree
8459 return Copy_Node_With_Replacement (Source);
8462 -------------------------
8463 -- New_External_Entity --
8464 -------------------------
8466 function New_External_Entity
8467 (Kind : Entity_Kind;
8468 Scope_Id : Entity_Id;
8469 Sloc_Value : Source_Ptr;
8470 Related_Id : Entity_Id;
8472 Suffix_Index : Nat := 0;
8473 Prefix : Character := ' ') return Entity_Id
8475 N : constant Entity_Id :=
8476 Make_Defining_Identifier (Sloc_Value,
8478 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8481 Set_Ekind (N, Kind);
8482 Set_Is_Internal (N, True);
8483 Append_Entity (N, Scope_Id);
8484 Set_Public_Status (N);
8486 if Kind in Type_Kind then
8487 Init_Size_Align (N);
8491 end New_External_Entity;
8493 -------------------------
8494 -- New_Internal_Entity --
8495 -------------------------
8497 function New_Internal_Entity
8498 (Kind : Entity_Kind;
8499 Scope_Id : Entity_Id;
8500 Sloc_Value : Source_Ptr;
8501 Id_Char : Character) return Entity_Id
8503 N : constant Entity_Id :=
8504 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
8507 Set_Ekind (N, Kind);
8508 Set_Is_Internal (N, True);
8509 Append_Entity (N, Scope_Id);
8511 if Kind in Type_Kind then
8512 Init_Size_Align (N);
8516 end New_Internal_Entity;
8522 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8526 -- If we are pointing at a positional parameter, it is a member of a
8527 -- node list (the list of parameters), and the next parameter is the
8528 -- next node on the list, unless we hit a parameter association, then
8529 -- we shift to using the chain whose head is the First_Named_Actual in
8530 -- the parent, and then is threaded using the Next_Named_Actual of the
8531 -- Parameter_Association. All this fiddling is because the original node
8532 -- list is in the textual call order, and what we need is the
8533 -- declaration order.
8535 if Is_List_Member (Actual_Id) then
8536 N := Next (Actual_Id);
8538 if Nkind (N) = N_Parameter_Association then
8539 return First_Named_Actual (Parent (Actual_Id));
8545 return Next_Named_Actual (Parent (Actual_Id));
8549 procedure Next_Actual (Actual_Id : in out Node_Id) is
8551 Actual_Id := Next_Actual (Actual_Id);
8554 -----------------------
8555 -- Normalize_Actuals --
8556 -----------------------
8558 -- Chain actuals according to formals of subprogram. If there are no named
8559 -- associations, the chain is simply the list of Parameter Associations,
8560 -- since the order is the same as the declaration order. If there are named
8561 -- associations, then the First_Named_Actual field in the N_Function_Call
8562 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8563 -- node for the parameter that comes first in declaration order. The
8564 -- remaining named parameters are then chained in declaration order using
8565 -- Next_Named_Actual.
8567 -- This routine also verifies that the number of actuals is compatible with
8568 -- the number and default values of formals, but performs no type checking
8569 -- (type checking is done by the caller).
8571 -- If the matching succeeds, Success is set to True and the caller proceeds
8572 -- with type-checking. If the match is unsuccessful, then Success is set to
8573 -- False, and the caller attempts a different interpretation, if there is
8576 -- If the flag Report is on, the call is not overloaded, and a failure to
8577 -- match can be reported here, rather than in the caller.
8579 procedure Normalize_Actuals
8583 Success : out Boolean)
8585 Actuals : constant List_Id := Parameter_Associations (N);
8586 Actual : Node_Id := Empty;
8588 Last : Node_Id := Empty;
8589 First_Named : Node_Id := Empty;
8592 Formals_To_Match : Integer := 0;
8593 Actuals_To_Match : Integer := 0;
8595 procedure Chain (A : Node_Id);
8596 -- Add named actual at the proper place in the list, using the
8597 -- Next_Named_Actual link.
8599 function Reporting return Boolean;
8600 -- Determines if an error is to be reported. To report an error, we
8601 -- need Report to be True, and also we do not report errors caused
8602 -- by calls to init procs that occur within other init procs. Such
8603 -- errors must always be cascaded errors, since if all the types are
8604 -- declared correctly, the compiler will certainly build decent calls!
8610 procedure Chain (A : Node_Id) is
8614 -- Call node points to first actual in list
8616 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
8619 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
8623 Set_Next_Named_Actual (Last, Empty);
8630 function Reporting return Boolean is
8635 elsif not Within_Init_Proc then
8638 elsif Is_Init_Proc (Entity (Name (N))) then
8646 -- Start of processing for Normalize_Actuals
8649 if Is_Access_Type (S) then
8651 -- The name in the call is a function call that returns an access
8652 -- to subprogram. The designated type has the list of formals.
8654 Formal := First_Formal (Designated_Type (S));
8656 Formal := First_Formal (S);
8659 while Present (Formal) loop
8660 Formals_To_Match := Formals_To_Match + 1;
8661 Next_Formal (Formal);
8664 -- Find if there is a named association, and verify that no positional
8665 -- associations appear after named ones.
8667 if Present (Actuals) then
8668 Actual := First (Actuals);
8671 while Present (Actual)
8672 and then Nkind (Actual) /= N_Parameter_Association
8674 Actuals_To_Match := Actuals_To_Match + 1;
8678 if No (Actual) and Actuals_To_Match = Formals_To_Match then
8680 -- Most common case: positional notation, no defaults
8685 elsif Actuals_To_Match > Formals_To_Match then
8687 -- Too many actuals: will not work
8690 if Is_Entity_Name (Name (N)) then
8691 Error_Msg_N ("too many arguments in call to&", Name (N));
8693 Error_Msg_N ("too many arguments in call", N);
8701 First_Named := Actual;
8703 while Present (Actual) loop
8704 if Nkind (Actual) /= N_Parameter_Association then
8706 ("positional parameters not allowed after named ones", Actual);
8711 Actuals_To_Match := Actuals_To_Match + 1;
8717 if Present (Actuals) then
8718 Actual := First (Actuals);
8721 Formal := First_Formal (S);
8722 while Present (Formal) loop
8724 -- Match the formals in order. If the corresponding actual is
8725 -- positional, nothing to do. Else scan the list of named actuals
8726 -- to find the one with the right name.
8729 and then Nkind (Actual) /= N_Parameter_Association
8732 Actuals_To_Match := Actuals_To_Match - 1;
8733 Formals_To_Match := Formals_To_Match - 1;
8736 -- For named parameters, search the list of actuals to find
8737 -- one that matches the next formal name.
8739 Actual := First_Named;
8741 while Present (Actual) loop
8742 if Chars (Selector_Name (Actual)) = Chars (Formal) then
8745 Actuals_To_Match := Actuals_To_Match - 1;
8746 Formals_To_Match := Formals_To_Match - 1;
8754 if Ekind (Formal) /= E_In_Parameter
8755 or else No (Default_Value (Formal))
8758 if (Comes_From_Source (S)
8759 or else Sloc (S) = Standard_Location)
8760 and then Is_Overloadable (S)
8764 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8766 (Nkind (Parent (N)) = N_Function_Call
8768 Nkind (Parent (N)) = N_Parameter_Association))
8769 and then Ekind (S) /= E_Function
8771 Set_Etype (N, Etype (S));
8773 Error_Msg_Name_1 := Chars (S);
8774 Error_Msg_Sloc := Sloc (S);
8776 ("missing argument for parameter & " &
8777 "in call to % declared #", N, Formal);
8780 elsif Is_Overloadable (S) then
8781 Error_Msg_Name_1 := Chars (S);
8783 -- Point to type derivation that generated the
8786 Error_Msg_Sloc := Sloc (Parent (S));
8789 ("missing argument for parameter & " &
8790 "in call to % (inherited) #", N, Formal);
8794 ("missing argument for parameter &", N, Formal);
8802 Formals_To_Match := Formals_To_Match - 1;
8807 Next_Formal (Formal);
8810 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8817 -- Find some superfluous named actual that did not get
8818 -- attached to the list of associations.
8820 Actual := First (Actuals);
8821 while Present (Actual) loop
8822 if Nkind (Actual) = N_Parameter_Association
8823 and then Actual /= Last
8824 and then No (Next_Named_Actual (Actual))
8826 Error_Msg_N ("unmatched actual & in call",
8827 Selector_Name (Actual));
8838 end Normalize_Actuals;
8840 --------------------------------
8841 -- Note_Possible_Modification --
8842 --------------------------------
8844 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8845 Modification_Comes_From_Source : constant Boolean :=
8846 Comes_From_Source (Parent (N));
8852 -- Loop to find referenced entity, if there is one
8859 if Is_Entity_Name (Exp) then
8860 Ent := Entity (Exp);
8862 -- If the entity is missing, it is an undeclared identifier,
8863 -- and there is nothing to annotate.
8869 elsif Nkind (Exp) = N_Explicit_Dereference then
8871 P : constant Node_Id := Prefix (Exp);
8874 if Nkind (P) = N_Selected_Component
8876 Entry_Formal (Entity (Selector_Name (P))))
8878 -- Case of a reference to an entry formal
8880 Ent := Entry_Formal (Entity (Selector_Name (P)));
8882 elsif Nkind (P) = N_Identifier
8883 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
8884 and then Present (Expression (Parent (Entity (P))))
8885 and then Nkind (Expression (Parent (Entity (P))))
8888 -- Case of a reference to a value on which side effects have
8891 Exp := Prefix (Expression (Parent (Entity (P))));
8900 elsif Nkind (Exp) = N_Type_Conversion
8901 or else Nkind (Exp) = N_Unchecked_Type_Conversion
8903 Exp := Expression (Exp);
8906 elsif Nkind (Exp) = N_Slice
8907 or else Nkind (Exp) = N_Indexed_Component
8908 or else Nkind (Exp) = N_Selected_Component
8910 Exp := Prefix (Exp);
8917 -- Now look for entity being referenced
8919 if Present (Ent) then
8920 if Is_Object (Ent) then
8921 if Comes_From_Source (Exp)
8922 or else Modification_Comes_From_Source
8924 if Has_Pragma_Unmodified (Ent) then
8925 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
8928 Set_Never_Set_In_Source (Ent, False);
8931 Set_Is_True_Constant (Ent, False);
8932 Set_Current_Value (Ent, Empty);
8933 Set_Is_Known_Null (Ent, False);
8935 if not Can_Never_Be_Null (Ent) then
8936 Set_Is_Known_Non_Null (Ent, False);
8939 -- Follow renaming chain
8941 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
8942 and then Present (Renamed_Object (Ent))
8944 Exp := Renamed_Object (Ent);
8948 -- Generate a reference only if the assignment comes from
8949 -- source. This excludes, for example, calls to a dispatching
8950 -- assignment operation when the left-hand side is tagged.
8952 if Modification_Comes_From_Source then
8953 Generate_Reference (Ent, Exp, 'm');
8956 Check_Nested_Access (Ent);
8961 -- If we are sure this is a modification from source, and we know
8962 -- this modifies a constant, then give an appropriate warning.
8964 if Overlays_Constant (Ent)
8965 and then Modification_Comes_From_Source
8969 A : constant Node_Id := Address_Clause (Ent);
8973 Exp : constant Node_Id := Expression (A);
8975 if Nkind (Exp) = N_Attribute_Reference
8976 and then Attribute_Name (Exp) = Name_Address
8977 and then Is_Entity_Name (Prefix (Exp))
8979 Error_Msg_Sloc := Sloc (A);
8981 ("constant& may be modified via address clause#?",
8982 N, Entity (Prefix (Exp)));
8992 end Note_Possible_Modification;
8994 -------------------------
8995 -- Object_Access_Level --
8996 -------------------------
8998 function Object_Access_Level (Obj : Node_Id) return Uint is
9001 -- Returns the static accessibility level of the view denoted by Obj. Note
9002 -- that the value returned is the result of a call to Scope_Depth. Only
9003 -- scope depths associated with dynamic scopes can actually be returned.
9004 -- Since only relative levels matter for accessibility checking, the fact
9005 -- that the distance between successive levels of accessibility is not
9006 -- always one is immaterial (invariant: if level(E2) is deeper than
9007 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9009 function Reference_To (Obj : Node_Id) return Node_Id;
9010 -- An explicit dereference is created when removing side-effects from
9011 -- expressions for constraint checking purposes. In this case a local
9012 -- access type is created for it. The correct access level is that of
9013 -- the original source node. We detect this case by noting that the
9014 -- prefix of the dereference is created by an object declaration whose
9015 -- initial expression is a reference.
9021 function Reference_To (Obj : Node_Id) return Node_Id is
9022 Pref : constant Node_Id := Prefix (Obj);
9024 if Is_Entity_Name (Pref)
9025 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9026 and then Present (Expression (Parent (Entity (Pref))))
9027 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9029 return (Prefix (Expression (Parent (Entity (Pref)))));
9035 -- Start of processing for Object_Access_Level
9038 if Is_Entity_Name (Obj) then
9041 if Is_Prival (E) then
9042 E := Prival_Link (E);
9045 -- If E is a type then it denotes a current instance. For this case
9046 -- we add one to the normal accessibility level of the type to ensure
9047 -- that current instances are treated as always being deeper than
9048 -- than the level of any visible named access type (see 3.10.2(21)).
9051 return Type_Access_Level (E) + 1;
9053 elsif Present (Renamed_Object (E)) then
9054 return Object_Access_Level (Renamed_Object (E));
9056 -- Similarly, if E is a component of the current instance of a
9057 -- protected type, any instance of it is assumed to be at a deeper
9058 -- level than the type. For a protected object (whose type is an
9059 -- anonymous protected type) its components are at the same level
9060 -- as the type itself.
9062 elsif not Is_Overloadable (E)
9063 and then Ekind (Scope (E)) = E_Protected_Type
9064 and then Comes_From_Source (Scope (E))
9066 return Type_Access_Level (Scope (E)) + 1;
9069 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9072 elsif Nkind (Obj) = N_Selected_Component then
9073 if Is_Access_Type (Etype (Prefix (Obj))) then
9074 return Type_Access_Level (Etype (Prefix (Obj)));
9076 return Object_Access_Level (Prefix (Obj));
9079 elsif Nkind (Obj) = N_Indexed_Component then
9080 if Is_Access_Type (Etype (Prefix (Obj))) then
9081 return Type_Access_Level (Etype (Prefix (Obj)));
9083 return Object_Access_Level (Prefix (Obj));
9086 elsif Nkind (Obj) = N_Explicit_Dereference then
9088 -- If the prefix is a selected access discriminant then we make a
9089 -- recursive call on the prefix, which will in turn check the level
9090 -- of the prefix object of the selected discriminant.
9092 if Nkind (Prefix (Obj)) = N_Selected_Component
9093 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9095 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9097 return Object_Access_Level (Prefix (Obj));
9099 elsif not (Comes_From_Source (Obj)) then
9101 Ref : constant Node_Id := Reference_To (Obj);
9103 if Present (Ref) then
9104 return Object_Access_Level (Ref);
9106 return Type_Access_Level (Etype (Prefix (Obj)));
9111 return Type_Access_Level (Etype (Prefix (Obj)));
9114 elsif Nkind (Obj) = N_Type_Conversion
9115 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9117 return Object_Access_Level (Expression (Obj));
9119 -- Function results are objects, so we get either the access level of
9120 -- the function or, in the case of an indirect call, the level of the
9121 -- access-to-subprogram type.
9123 elsif Nkind (Obj) = N_Function_Call then
9124 if Is_Entity_Name (Name (Obj)) then
9125 return Subprogram_Access_Level (Entity (Name (Obj)));
9127 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9130 -- For convenience we handle qualified expressions, even though
9131 -- they aren't technically object names.
9133 elsif Nkind (Obj) = N_Qualified_Expression then
9134 return Object_Access_Level (Expression (Obj));
9136 -- Otherwise return the scope level of Standard.
9137 -- (If there are cases that fall through
9138 -- to this point they will be treated as
9139 -- having global accessibility for now. ???)
9142 return Scope_Depth (Standard_Standard);
9144 end Object_Access_Level;
9146 -----------------------
9147 -- Private_Component --
9148 -----------------------
9150 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9151 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9153 function Trace_Components
9155 Check : Boolean) return Entity_Id;
9156 -- Recursive function that does the work, and checks against circular
9157 -- definition for each subcomponent type.
9159 ----------------------
9160 -- Trace_Components --
9161 ----------------------
9163 function Trace_Components
9165 Check : Boolean) return Entity_Id
9167 Btype : constant Entity_Id := Base_Type (T);
9168 Component : Entity_Id;
9170 Candidate : Entity_Id := Empty;
9173 if Check and then Btype = Ancestor then
9174 Error_Msg_N ("circular type definition", Type_Id);
9178 if Is_Private_Type (Btype)
9179 and then not Is_Generic_Type (Btype)
9181 if Present (Full_View (Btype))
9182 and then Is_Record_Type (Full_View (Btype))
9183 and then not Is_Frozen (Btype)
9185 -- To indicate that the ancestor depends on a private type, the
9186 -- current Btype is sufficient. However, to check for circular
9187 -- definition we must recurse on the full view.
9189 Candidate := Trace_Components (Full_View (Btype), True);
9191 if Candidate = Any_Type then
9201 elsif Is_Array_Type (Btype) then
9202 return Trace_Components (Component_Type (Btype), True);
9204 elsif Is_Record_Type (Btype) then
9205 Component := First_Entity (Btype);
9206 while Present (Component) loop
9208 -- Skip anonymous types generated by constrained components
9210 if not Is_Type (Component) then
9211 P := Trace_Components (Etype (Component), True);
9214 if P = Any_Type then
9222 Next_Entity (Component);
9230 end Trace_Components;
9232 -- Start of processing for Private_Component
9235 return Trace_Components (Type_Id, False);
9236 end Private_Component;
9238 ---------------------------
9239 -- Primitive_Names_Match --
9240 ---------------------------
9242 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9244 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9245 -- Given an internal name, returns the corresponding non-internal name
9247 ------------------------
9248 -- Non_Internal_Name --
9249 ------------------------
9251 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9253 Get_Name_String (Chars (E));
9254 Name_Len := Name_Len - 1;
9256 end Non_Internal_Name;
9258 -- Start of processing for Primitive_Names_Match
9261 pragma Assert (Present (E1) and then Present (E2));
9263 return Chars (E1) = Chars (E2)
9265 (not Is_Internal_Name (Chars (E1))
9266 and then Is_Internal_Name (Chars (E2))
9267 and then Non_Internal_Name (E2) = Chars (E1))
9269 (not Is_Internal_Name (Chars (E2))
9270 and then Is_Internal_Name (Chars (E1))
9271 and then Non_Internal_Name (E1) = Chars (E2))
9273 (Is_Predefined_Dispatching_Operation (E1)
9274 and then Is_Predefined_Dispatching_Operation (E2)
9275 and then Same_TSS (E1, E2))
9277 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9278 end Primitive_Names_Match;
9280 -----------------------
9281 -- Process_End_Label --
9282 -----------------------
9284 procedure Process_End_Label
9293 Label_Ref : Boolean;
9294 -- Set True if reference to end label itself is required
9297 -- Gets set to the operator symbol or identifier that references the
9298 -- entity Ent. For the child unit case, this is the identifier from the
9299 -- designator. For other cases, this is simply Endl.
9301 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9302 -- N is an identifier node that appears as a parent unit reference in
9303 -- the case where Ent is a child unit. This procedure generates an
9304 -- appropriate cross-reference entry. E is the corresponding entity.
9306 -------------------------
9307 -- Generate_Parent_Ref --
9308 -------------------------
9310 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9312 -- If names do not match, something weird, skip reference
9314 if Chars (E) = Chars (N) then
9316 -- Generate the reference. We do NOT consider this as a reference
9317 -- for unreferenced symbol purposes.
9319 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9322 Style.Check_Identifier (N, E);
9325 end Generate_Parent_Ref;
9327 -- Start of processing for Process_End_Label
9330 -- If no node, ignore. This happens in some error situations, and
9331 -- also for some internally generated structures where no end label
9332 -- references are required in any case.
9338 -- Nothing to do if no End_Label, happens for internally generated
9339 -- constructs where we don't want an end label reference anyway. Also
9340 -- nothing to do if Endl is a string literal, which means there was
9341 -- some prior error (bad operator symbol)
9343 Endl := End_Label (N);
9345 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9349 -- Reference node is not in extended main source unit
9351 if not In_Extended_Main_Source_Unit (N) then
9353 -- Generally we do not collect references except for the extended
9354 -- main source unit. The one exception is the 'e' entry for a
9355 -- package spec, where it is useful for a client to have the
9356 -- ending information to define scopes.
9364 -- For this case, we can ignore any parent references, but we
9365 -- need the package name itself for the 'e' entry.
9367 if Nkind (Endl) = N_Designator then
9368 Endl := Identifier (Endl);
9372 -- Reference is in extended main source unit
9377 -- For designator, generate references for the parent entries
9379 if Nkind (Endl) = N_Designator then
9381 -- Generate references for the prefix if the END line comes from
9382 -- source (otherwise we do not need these references) We climb the
9383 -- scope stack to find the expected entities.
9385 if Comes_From_Source (Endl) then
9387 Scop := Current_Scope;
9388 while Nkind (Nam) = N_Selected_Component loop
9389 Scop := Scope (Scop);
9390 exit when No (Scop);
9391 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9392 Nam := Prefix (Nam);
9395 if Present (Scop) then
9396 Generate_Parent_Ref (Nam, Scope (Scop));
9400 Endl := Identifier (Endl);
9404 -- If the end label is not for the given entity, then either we have
9405 -- some previous error, or this is a generic instantiation for which
9406 -- we do not need to make a cross-reference in this case anyway. In
9407 -- either case we simply ignore the call.
9409 if Chars (Ent) /= Chars (Endl) then
9413 -- If label was really there, then generate a normal reference and then
9414 -- adjust the location in the end label to point past the name (which
9415 -- should almost always be the semicolon).
9419 if Comes_From_Source (Endl) then
9421 -- If a label reference is required, then do the style check and
9422 -- generate an l-type cross-reference entry for the label
9426 Style.Check_Identifier (Endl, Ent);
9429 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9432 -- Set the location to point past the label (normally this will
9433 -- mean the semicolon immediately following the label). This is
9434 -- done for the sake of the 'e' or 't' entry generated below.
9436 Get_Decoded_Name_String (Chars (Endl));
9437 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9440 -- Now generate the e/t reference
9442 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9444 -- Restore Sloc, in case modified above, since we have an identifier
9445 -- and the normal Sloc should be left set in the tree.
9447 Set_Sloc (Endl, Loc);
9448 end Process_End_Label;
9454 -- We do the conversion to get the value of the real string by using
9455 -- the scanner, see Sinput for details on use of the internal source
9456 -- buffer for scanning internal strings.
9458 function Real_Convert (S : String) return Node_Id is
9459 Save_Src : constant Source_Buffer_Ptr := Source;
9463 Source := Internal_Source_Ptr;
9466 for J in S'Range loop
9467 Source (Source_Ptr (J)) := S (J);
9470 Source (S'Length + 1) := EOF;
9472 if Source (Scan_Ptr) = '-' then
9474 Scan_Ptr := Scan_Ptr + 1;
9482 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9489 ------------------------------------
9490 -- References_Generic_Formal_Type --
9491 ------------------------------------
9493 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
9495 function Process (N : Node_Id) return Traverse_Result;
9496 -- Process one node in search for generic formal type
9502 function Process (N : Node_Id) return Traverse_Result is
9504 if Nkind (N) in N_Has_Entity then
9506 E : constant Entity_Id := Entity (N);
9509 if Is_Generic_Type (E) then
9511 elsif Present (Etype (E))
9512 and then Is_Generic_Type (Etype (E))
9523 function Traverse is new Traverse_Func (Process);
9524 -- Traverse tree to look for generic type
9527 if Inside_A_Generic then
9528 return Traverse (N) = Abandon;
9532 end References_Generic_Formal_Type;
9534 --------------------
9535 -- Remove_Homonym --
9536 --------------------
9538 procedure Remove_Homonym (E : Entity_Id) is
9539 Prev : Entity_Id := Empty;
9543 if E = Current_Entity (E) then
9544 if Present (Homonym (E)) then
9545 Set_Current_Entity (Homonym (E));
9547 Set_Name_Entity_Id (Chars (E), Empty);
9550 H := Current_Entity (E);
9551 while Present (H) and then H /= E loop
9556 Set_Homonym (Prev, Homonym (E));
9560 ---------------------
9561 -- Rep_To_Pos_Flag --
9562 ---------------------
9564 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
9566 return New_Occurrence_Of
9567 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
9568 end Rep_To_Pos_Flag;
9570 --------------------
9571 -- Require_Entity --
9572 --------------------
9574 procedure Require_Entity (N : Node_Id) is
9576 if Is_Entity_Name (N) and then No (Entity (N)) then
9577 if Total_Errors_Detected /= 0 then
9578 Set_Entity (N, Any_Id);
9580 raise Program_Error;
9585 ------------------------------
9586 -- Requires_Transient_Scope --
9587 ------------------------------
9589 -- A transient scope is required when variable-sized temporaries are
9590 -- allocated in the primary or secondary stack, or when finalization
9591 -- actions must be generated before the next instruction.
9593 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
9594 Typ : constant Entity_Id := Underlying_Type (Id);
9596 -- Start of processing for Requires_Transient_Scope
9599 -- This is a private type which is not completed yet. This can only
9600 -- happen in a default expression (of a formal parameter or of a
9601 -- record component). Do not expand transient scope in this case
9606 -- Do not expand transient scope for non-existent procedure return
9608 elsif Typ = Standard_Void_Type then
9611 -- Elementary types do not require a transient scope
9613 elsif Is_Elementary_Type (Typ) then
9616 -- Generally, indefinite subtypes require a transient scope, since the
9617 -- back end cannot generate temporaries, since this is not a valid type
9618 -- for declaring an object. It might be possible to relax this in the
9619 -- future, e.g. by declaring the maximum possible space for the type.
9621 elsif Is_Indefinite_Subtype (Typ) then
9624 -- Functions returning tagged types may dispatch on result so their
9625 -- returned value is allocated on the secondary stack. Controlled
9626 -- type temporaries need finalization.
9628 elsif Is_Tagged_Type (Typ)
9629 or else Has_Controlled_Component (Typ)
9631 return not Is_Value_Type (Typ);
9635 elsif Is_Record_Type (Typ) then
9639 Comp := First_Entity (Typ);
9640 while Present (Comp) loop
9641 if Ekind (Comp) = E_Component
9642 and then Requires_Transient_Scope (Etype (Comp))
9653 -- String literal types never require transient scope
9655 elsif Ekind (Typ) = E_String_Literal_Subtype then
9658 -- Array type. Note that we already know that this is a constrained
9659 -- array, since unconstrained arrays will fail the indefinite test.
9661 elsif Is_Array_Type (Typ) then
9663 -- If component type requires a transient scope, the array does too
9665 if Requires_Transient_Scope (Component_Type (Typ)) then
9668 -- Otherwise, we only need a transient scope if the size is not
9669 -- known at compile time.
9672 return not Size_Known_At_Compile_Time (Typ);
9675 -- All other cases do not require a transient scope
9680 end Requires_Transient_Scope;
9682 --------------------------
9683 -- Reset_Analyzed_Flags --
9684 --------------------------
9686 procedure Reset_Analyzed_Flags (N : Node_Id) is
9688 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
9689 -- Function used to reset Analyzed flags in tree. Note that we do
9690 -- not reset Analyzed flags in entities, since there is no need to
9691 -- reanalyze entities, and indeed, it is wrong to do so, since it
9692 -- can result in generating auxiliary stuff more than once.
9694 --------------------
9695 -- Clear_Analyzed --
9696 --------------------
9698 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
9700 if not Has_Extension (N) then
9701 Set_Analyzed (N, False);
9707 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
9709 -- Start of processing for Reset_Analyzed_Flags
9713 end Reset_Analyzed_Flags;
9715 ---------------------------
9716 -- Safe_To_Capture_Value --
9717 ---------------------------
9719 function Safe_To_Capture_Value
9722 Cond : Boolean := False) return Boolean
9725 -- The only entities for which we track constant values are variables
9726 -- which are not renamings, constants, out parameters, and in out
9727 -- parameters, so check if we have this case.
9729 -- Note: it may seem odd to track constant values for constants, but in
9730 -- fact this routine is used for other purposes than simply capturing
9731 -- the value. In particular, the setting of Known[_Non]_Null.
9733 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
9735 Ekind (Ent) = E_Constant
9737 Ekind (Ent) = E_Out_Parameter
9739 Ekind (Ent) = E_In_Out_Parameter
9743 -- For conditionals, we also allow loop parameters and all formals,
9744 -- including in parameters.
9748 (Ekind (Ent) = E_Loop_Parameter
9750 Ekind (Ent) = E_In_Parameter)
9754 -- For all other cases, not just unsafe, but impossible to capture
9755 -- Current_Value, since the above are the only entities which have
9756 -- Current_Value fields.
9762 -- Skip if volatile or aliased, since funny things might be going on in
9763 -- these cases which we cannot necessarily track. Also skip any variable
9764 -- for which an address clause is given, or whose address is taken. Also
9765 -- never capture value of library level variables (an attempt to do so
9766 -- can occur in the case of package elaboration code).
9768 if Treat_As_Volatile (Ent)
9769 or else Is_Aliased (Ent)
9770 or else Present (Address_Clause (Ent))
9771 or else Address_Taken (Ent)
9772 or else (Is_Library_Level_Entity (Ent)
9773 and then Ekind (Ent) = E_Variable)
9778 -- OK, all above conditions are met. We also require that the scope of
9779 -- the reference be the same as the scope of the entity, not counting
9780 -- packages and blocks and loops.
9783 E_Scope : constant Entity_Id := Scope (Ent);
9784 R_Scope : Entity_Id;
9787 R_Scope := Current_Scope;
9788 while R_Scope /= Standard_Standard loop
9789 exit when R_Scope = E_Scope;
9791 if Ekind (R_Scope) /= E_Package
9793 Ekind (R_Scope) /= E_Block
9795 Ekind (R_Scope) /= E_Loop
9799 R_Scope := Scope (R_Scope);
9804 -- We also require that the reference does not appear in a context
9805 -- where it is not sure to be executed (i.e. a conditional context
9806 -- or an exception handler). We skip this if Cond is True, since the
9807 -- capturing of values from conditional tests handles this ok.
9821 while Present (P) loop
9822 if Nkind (P) = N_If_Statement
9823 or else Nkind (P) = N_Case_Statement
9824 or else (Nkind (P) in N_Short_Circuit
9825 and then Desc = Right_Opnd (P))
9826 or else (Nkind (P) = N_Conditional_Expression
9827 and then Desc /= First (Expressions (P)))
9828 or else Nkind (P) = N_Exception_Handler
9829 or else Nkind (P) = N_Selective_Accept
9830 or else Nkind (P) = N_Conditional_Entry_Call
9831 or else Nkind (P) = N_Timed_Entry_Call
9832 or else Nkind (P) = N_Asynchronous_Select
9842 -- OK, looks safe to set value
9845 end Safe_To_Capture_Value;
9851 function Same_Name (N1, N2 : Node_Id) return Boolean is
9852 K1 : constant Node_Kind := Nkind (N1);
9853 K2 : constant Node_Kind := Nkind (N2);
9856 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
9857 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
9859 return Chars (N1) = Chars (N2);
9861 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
9862 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
9864 return Same_Name (Selector_Name (N1), Selector_Name (N2))
9865 and then Same_Name (Prefix (N1), Prefix (N2));
9876 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9877 N1 : constant Node_Id := Original_Node (Node1);
9878 N2 : constant Node_Id := Original_Node (Node2);
9879 -- We do the tests on original nodes, since we are most interested
9880 -- in the original source, not any expansion that got in the way.
9882 K1 : constant Node_Kind := Nkind (N1);
9883 K2 : constant Node_Kind := Nkind (N2);
9886 -- First case, both are entities with same entity
9888 if K1 in N_Has_Entity
9889 and then K2 in N_Has_Entity
9890 and then Present (Entity (N1))
9891 and then Present (Entity (N2))
9892 and then (Ekind (Entity (N1)) = E_Variable
9894 Ekind (Entity (N1)) = E_Constant)
9895 and then Entity (N1) = Entity (N2)
9899 -- Second case, selected component with same selector, same record
9901 elsif K1 = N_Selected_Component
9902 and then K2 = N_Selected_Component
9903 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
9905 return Same_Object (Prefix (N1), Prefix (N2));
9907 -- Third case, indexed component with same subscripts, same array
9909 elsif K1 = N_Indexed_Component
9910 and then K2 = N_Indexed_Component
9911 and then Same_Object (Prefix (N1), Prefix (N2))
9916 E1 := First (Expressions (N1));
9917 E2 := First (Expressions (N2));
9918 while Present (E1) loop
9919 if not Same_Value (E1, E2) then
9930 -- Fourth case, slice of same array with same bounds
9933 and then K2 = N_Slice
9934 and then Nkind (Discrete_Range (N1)) = N_Range
9935 and then Nkind (Discrete_Range (N2)) = N_Range
9936 and then Same_Value (Low_Bound (Discrete_Range (N1)),
9937 Low_Bound (Discrete_Range (N2)))
9938 and then Same_Value (High_Bound (Discrete_Range (N1)),
9939 High_Bound (Discrete_Range (N2)))
9941 return Same_Name (Prefix (N1), Prefix (N2));
9943 -- All other cases, not clearly the same object
9954 function Same_Type (T1, T2 : Entity_Id) return Boolean is
9959 elsif not Is_Constrained (T1)
9960 and then not Is_Constrained (T2)
9961 and then Base_Type (T1) = Base_Type (T2)
9965 -- For now don't bother with case of identical constraints, to be
9966 -- fiddled with later on perhaps (this is only used for optimization
9967 -- purposes, so it is not critical to do a best possible job)
9978 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
9980 if Compile_Time_Known_Value (Node1)
9981 and then Compile_Time_Known_Value (Node2)
9982 and then Expr_Value (Node1) = Expr_Value (Node2)
9985 elsif Same_Object (Node1, Node2) then
9992 ------------------------
9993 -- Scope_Is_Transient --
9994 ------------------------
9996 function Scope_Is_Transient return Boolean is
9998 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
9999 end Scope_Is_Transient;
10005 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10010 while Scop /= Standard_Standard loop
10011 Scop := Scope (Scop);
10013 if Scop = Scope2 then
10021 --------------------------
10022 -- Scope_Within_Or_Same --
10023 --------------------------
10025 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10030 while Scop /= Standard_Standard loop
10031 if Scop = Scope2 then
10034 Scop := Scope (Scop);
10039 end Scope_Within_Or_Same;
10041 --------------------
10042 -- Set_Convention --
10043 --------------------
10045 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10047 Basic_Set_Convention (E, Val);
10050 and then Is_Access_Subprogram_Type (Base_Type (E))
10051 and then Has_Foreign_Convention (E)
10053 Set_Can_Use_Internal_Rep (E, False);
10055 end Set_Convention;
10057 ------------------------
10058 -- Set_Current_Entity --
10059 ------------------------
10061 -- The given entity is to be set as the currently visible definition
10062 -- of its associated name (i.e. the Node_Id associated with its name).
10063 -- All we have to do is to get the name from the identifier, and
10064 -- then set the associated Node_Id to point to the given entity.
10066 procedure Set_Current_Entity (E : Entity_Id) is
10068 Set_Name_Entity_Id (Chars (E), E);
10069 end Set_Current_Entity;
10071 ---------------------------
10072 -- Set_Debug_Info_Needed --
10073 ---------------------------
10075 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10077 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10078 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10079 -- Used to set debug info in a related node if not set already
10081 --------------------------------------
10082 -- Set_Debug_Info_Needed_If_Not_Set --
10083 --------------------------------------
10085 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10088 and then not Needs_Debug_Info (E)
10090 Set_Debug_Info_Needed (E);
10092 -- For a private type, indicate that the full view also needs
10093 -- debug information.
10096 and then Is_Private_Type (E)
10097 and then Present (Full_View (E))
10099 Set_Debug_Info_Needed (Full_View (E));
10102 end Set_Debug_Info_Needed_If_Not_Set;
10104 -- Start of processing for Set_Debug_Info_Needed
10107 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10108 -- indicates that Debug_Info_Needed is never required for the entity.
10111 or else Debug_Info_Off (T)
10116 -- Set flag in entity itself. Note that we will go through the following
10117 -- circuitry even if the flag is already set on T. That's intentional,
10118 -- it makes sure that the flag will be set in subsidiary entities.
10120 Set_Needs_Debug_Info (T);
10122 -- Set flag on subsidiary entities if not set already
10124 if Is_Object (T) then
10125 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10127 elsif Is_Type (T) then
10128 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10130 if Is_Record_Type (T) then
10132 Ent : Entity_Id := First_Entity (T);
10134 while Present (Ent) loop
10135 Set_Debug_Info_Needed_If_Not_Set (Ent);
10140 elsif Is_Array_Type (T) then
10141 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10144 Indx : Node_Id := First_Index (T);
10146 while Present (Indx) loop
10147 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10148 Indx := Next_Index (Indx);
10152 if Is_Packed (T) then
10153 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10156 elsif Is_Access_Type (T) then
10157 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10159 elsif Is_Private_Type (T) then
10160 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10162 elsif Is_Protected_Type (T) then
10163 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10166 end Set_Debug_Info_Needed;
10168 ---------------------------------
10169 -- Set_Entity_With_Style_Check --
10170 ---------------------------------
10172 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10173 Val_Actual : Entity_Id;
10177 Set_Entity (N, Val);
10180 and then not Suppress_Style_Checks (Val)
10181 and then not In_Instance
10183 if Nkind (N) = N_Identifier then
10185 elsif Nkind (N) = N_Expanded_Name then
10186 Nod := Selector_Name (N);
10191 -- A special situation arises for derived operations, where we want
10192 -- to do the check against the parent (since the Sloc of the derived
10193 -- operation points to the derived type declaration itself).
10196 while not Comes_From_Source (Val_Actual)
10197 and then Nkind (Val_Actual) in N_Entity
10198 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10199 or else Is_Subprogram (Val_Actual)
10200 or else Is_Generic_Subprogram (Val_Actual))
10201 and then Present (Alias (Val_Actual))
10203 Val_Actual := Alias (Val_Actual);
10206 -- Renaming declarations for generic actuals do not come from source,
10207 -- and have a different name from that of the entity they rename, so
10208 -- there is no style check to perform here.
10210 if Chars (Nod) = Chars (Val_Actual) then
10211 Style.Check_Identifier (Nod, Val_Actual);
10215 Set_Entity (N, Val);
10216 end Set_Entity_With_Style_Check;
10218 ------------------------
10219 -- Set_Name_Entity_Id --
10220 ------------------------
10222 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10224 Set_Name_Table_Info (Id, Int (Val));
10225 end Set_Name_Entity_Id;
10227 ---------------------
10228 -- Set_Next_Actual --
10229 ---------------------
10231 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10233 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10234 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10236 end Set_Next_Actual;
10238 ----------------------------------
10239 -- Set_Optimize_Alignment_Flags --
10240 ----------------------------------
10242 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10244 if Optimize_Alignment = 'S' then
10245 Set_Optimize_Alignment_Space (E);
10246 elsif Optimize_Alignment = 'T' then
10247 Set_Optimize_Alignment_Time (E);
10249 end Set_Optimize_Alignment_Flags;
10251 -----------------------
10252 -- Set_Public_Status --
10253 -----------------------
10255 procedure Set_Public_Status (Id : Entity_Id) is
10256 S : constant Entity_Id := Current_Scope;
10258 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10259 -- Determines if E is defined within handled statement sequence or
10260 -- an if statement, returns True if so, False otherwise.
10262 ----------------------
10263 -- Within_HSS_Or_If --
10264 ----------------------
10266 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10269 N := Declaration_Node (E);
10276 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10282 end Within_HSS_Or_If;
10284 -- Start of processing for Set_Public_Status
10287 -- Everything in the scope of Standard is public
10289 if S = Standard_Standard then
10290 Set_Is_Public (Id);
10292 -- Entity is definitely not public if enclosing scope is not public
10294 elsif not Is_Public (S) then
10297 -- An object or function declaration that occurs in a handled sequence
10298 -- of statements or within an if statement is the declaration for a
10299 -- temporary object or local subprogram generated by the expander. It
10300 -- never needs to be made public and furthermore, making it public can
10301 -- cause back end problems.
10303 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10304 N_Function_Specification)
10305 and then Within_HSS_Or_If (Id)
10309 -- Entities in public packages or records are public
10311 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10312 Set_Is_Public (Id);
10314 -- The bounds of an entry family declaration can generate object
10315 -- declarations that are visible to the back-end, e.g. in the
10316 -- the declaration of a composite type that contains tasks.
10318 elsif Is_Concurrent_Type (S)
10319 and then not Has_Completion (S)
10320 and then Nkind (Parent (Id)) = N_Object_Declaration
10322 Set_Is_Public (Id);
10324 end Set_Public_Status;
10326 -----------------------------
10327 -- Set_Referenced_Modified --
10328 -----------------------------
10330 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10334 -- Deal with indexed or selected component where prefix is modified
10336 if Nkind (N) = N_Indexed_Component
10338 Nkind (N) = N_Selected_Component
10340 Pref := Prefix (N);
10342 -- If prefix is access type, then it is the designated object that is
10343 -- being modified, which means we have no entity to set the flag on.
10345 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10348 -- Otherwise chase the prefix
10351 Set_Referenced_Modified (Pref, Out_Param);
10354 -- Otherwise see if we have an entity name (only other case to process)
10356 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10357 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10358 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10360 end Set_Referenced_Modified;
10362 ----------------------------
10363 -- Set_Scope_Is_Transient --
10364 ----------------------------
10366 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10368 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10369 end Set_Scope_Is_Transient;
10371 -------------------
10372 -- Set_Size_Info --
10373 -------------------
10375 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10377 -- We copy Esize, but not RM_Size, since in general RM_Size is
10378 -- subtype specific and does not get inherited by all subtypes.
10380 Set_Esize (T1, Esize (T2));
10381 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10383 if Is_Discrete_Or_Fixed_Point_Type (T1)
10385 Is_Discrete_Or_Fixed_Point_Type (T2)
10387 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10390 Set_Alignment (T1, Alignment (T2));
10393 --------------------
10394 -- Static_Integer --
10395 --------------------
10397 function Static_Integer (N : Node_Id) return Uint is
10399 Analyze_And_Resolve (N, Any_Integer);
10402 or else Error_Posted (N)
10403 or else Etype (N) = Any_Type
10408 if Is_Static_Expression (N) then
10409 if not Raises_Constraint_Error (N) then
10410 return Expr_Value (N);
10415 elsif Etype (N) = Any_Type then
10419 Flag_Non_Static_Expr
10420 ("static integer expression required here", N);
10423 end Static_Integer;
10425 --------------------------
10426 -- Statically_Different --
10427 --------------------------
10429 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10430 R1 : constant Node_Id := Get_Referenced_Object (E1);
10431 R2 : constant Node_Id := Get_Referenced_Object (E2);
10433 return Is_Entity_Name (R1)
10434 and then Is_Entity_Name (R2)
10435 and then Entity (R1) /= Entity (R2)
10436 and then not Is_Formal (Entity (R1))
10437 and then not Is_Formal (Entity (R2));
10438 end Statically_Different;
10440 -----------------------------
10441 -- Subprogram_Access_Level --
10442 -----------------------------
10444 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10446 if Present (Alias (Subp)) then
10447 return Subprogram_Access_Level (Alias (Subp));
10449 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10451 end Subprogram_Access_Level;
10457 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10459 if Debug_Flag_W then
10460 for J in 0 .. Scope_Stack.Last loop
10465 Write_Name (Chars (E));
10466 Write_Str (" from ");
10467 Write_Location (Sloc (N));
10472 -----------------------
10473 -- Transfer_Entities --
10474 -----------------------
10476 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10477 Ent : Entity_Id := First_Entity (From);
10484 if (Last_Entity (To)) = Empty then
10485 Set_First_Entity (To, Ent);
10487 Set_Next_Entity (Last_Entity (To), Ent);
10490 Set_Last_Entity (To, Last_Entity (From));
10492 while Present (Ent) loop
10493 Set_Scope (Ent, To);
10495 if not Is_Public (Ent) then
10496 Set_Public_Status (Ent);
10499 and then Ekind (Ent) = E_Record_Subtype
10502 -- The components of the propagated Itype must be public
10508 Comp := First_Entity (Ent);
10509 while Present (Comp) loop
10510 Set_Is_Public (Comp);
10511 Next_Entity (Comp);
10520 Set_First_Entity (From, Empty);
10521 Set_Last_Entity (From, Empty);
10522 end Transfer_Entities;
10524 -----------------------
10525 -- Type_Access_Level --
10526 -----------------------
10528 function Type_Access_Level (Typ : Entity_Id) return Uint is
10532 Btyp := Base_Type (Typ);
10534 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10535 -- simply use the level where the type is declared. This is true for
10536 -- stand-alone object declarations, and for anonymous access types
10537 -- associated with components the level is the same as that of the
10538 -- enclosing composite type. However, special treatment is needed for
10539 -- the cases of access parameters, return objects of an anonymous access
10540 -- type, and, in Ada 95, access discriminants of limited types.
10542 if Ekind (Btyp) in Access_Kind then
10543 if Ekind (Btyp) = E_Anonymous_Access_Type then
10545 -- If the type is a nonlocal anonymous access type (such as for
10546 -- an access parameter) we treat it as being declared at the
10547 -- library level to ensure that names such as X.all'access don't
10548 -- fail static accessibility checks.
10550 if not Is_Local_Anonymous_Access (Typ) then
10551 return Scope_Depth (Standard_Standard);
10553 -- If this is a return object, the accessibility level is that of
10554 -- the result subtype of the enclosing function. The test here is
10555 -- little complicated, because we have to account for extended
10556 -- return statements that have been rewritten as blocks, in which
10557 -- case we have to find and the Is_Return_Object attribute of the
10558 -- itype's associated object. It would be nice to find a way to
10559 -- simplify this test, but it doesn't seem worthwhile to add a new
10560 -- flag just for purposes of this test. ???
10562 elsif Ekind (Scope (Btyp)) = E_Return_Statement
10565 and then Nkind (Associated_Node_For_Itype (Btyp)) =
10566 N_Object_Declaration
10567 and then Is_Return_Object
10568 (Defining_Identifier
10569 (Associated_Node_For_Itype (Btyp))))
10575 Scop := Scope (Scope (Btyp));
10576 while Present (Scop) loop
10577 exit when Ekind (Scop) = E_Function;
10578 Scop := Scope (Scop);
10581 -- Treat the return object's type as having the level of the
10582 -- function's result subtype (as per RM05-6.5(5.3/2)).
10584 return Type_Access_Level (Etype (Scop));
10589 Btyp := Root_Type (Btyp);
10591 -- The accessibility level of anonymous access types associated with
10592 -- discriminants is that of the current instance of the type, and
10593 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10595 -- AI-402: access discriminants have accessibility based on the
10596 -- object rather than the type in Ada 2005, so the above paragraph
10599 -- ??? Needs completion with rules from AI-416
10601 if Ada_Version <= Ada_95
10602 and then Ekind (Typ) = E_Anonymous_Access_Type
10603 and then Present (Associated_Node_For_Itype (Typ))
10604 and then Nkind (Associated_Node_For_Itype (Typ)) =
10605 N_Discriminant_Specification
10607 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
10611 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
10612 end Type_Access_Level;
10614 --------------------
10615 -- Ultimate_Alias --
10616 --------------------
10617 -- To do: add occurrences calling this new subprogram
10619 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
10620 E : Entity_Id := Prim;
10623 while Present (Alias (E)) loop
10628 end Ultimate_Alias;
10630 --------------------------
10631 -- Unit_Declaration_Node --
10632 --------------------------
10634 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
10635 N : Node_Id := Parent (Unit_Id);
10638 -- Predefined operators do not have a full function declaration
10640 if Ekind (Unit_Id) = E_Operator then
10644 -- Isn't there some better way to express the following ???
10646 while Nkind (N) /= N_Abstract_Subprogram_Declaration
10647 and then Nkind (N) /= N_Formal_Package_Declaration
10648 and then Nkind (N) /= N_Function_Instantiation
10649 and then Nkind (N) /= N_Generic_Package_Declaration
10650 and then Nkind (N) /= N_Generic_Subprogram_Declaration
10651 and then Nkind (N) /= N_Package_Declaration
10652 and then Nkind (N) /= N_Package_Body
10653 and then Nkind (N) /= N_Package_Instantiation
10654 and then Nkind (N) /= N_Package_Renaming_Declaration
10655 and then Nkind (N) /= N_Procedure_Instantiation
10656 and then Nkind (N) /= N_Protected_Body
10657 and then Nkind (N) /= N_Subprogram_Declaration
10658 and then Nkind (N) /= N_Subprogram_Body
10659 and then Nkind (N) /= N_Subprogram_Body_Stub
10660 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
10661 and then Nkind (N) /= N_Task_Body
10662 and then Nkind (N) /= N_Task_Type_Declaration
10663 and then Nkind (N) not in N_Formal_Subprogram_Declaration
10664 and then Nkind (N) not in N_Generic_Renaming_Declaration
10667 pragma Assert (Present (N));
10671 end Unit_Declaration_Node;
10673 ------------------------------
10674 -- Universal_Interpretation --
10675 ------------------------------
10677 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
10678 Index : Interp_Index;
10682 -- The argument may be a formal parameter of an operator or subprogram
10683 -- with multiple interpretations, or else an expression for an actual.
10685 if Nkind (Opnd) = N_Defining_Identifier
10686 or else not Is_Overloaded (Opnd)
10688 if Etype (Opnd) = Universal_Integer
10689 or else Etype (Opnd) = Universal_Real
10691 return Etype (Opnd);
10697 Get_First_Interp (Opnd, Index, It);
10698 while Present (It.Typ) loop
10699 if It.Typ = Universal_Integer
10700 or else It.Typ = Universal_Real
10705 Get_Next_Interp (Index, It);
10710 end Universal_Interpretation;
10716 function Unqualify (Expr : Node_Id) return Node_Id is
10718 -- Recurse to handle unlikely case of multiple levels of qualification
10720 if Nkind (Expr) = N_Qualified_Expression then
10721 return Unqualify (Expression (Expr));
10723 -- Normal case, not a qualified expression
10730 ----------------------
10731 -- Within_Init_Proc --
10732 ----------------------
10734 function Within_Init_Proc return Boolean is
10738 S := Current_Scope;
10739 while not Is_Overloadable (S) loop
10740 if S = Standard_Standard then
10747 return Is_Init_Proc (S);
10748 end Within_Init_Proc;
10754 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
10755 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
10756 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
10758 function Has_One_Matching_Field return Boolean;
10759 -- Determines if Expec_Type is a record type with a single component or
10760 -- discriminant whose type matches the found type or is one dimensional
10761 -- array whose component type matches the found type.
10763 ----------------------------
10764 -- Has_One_Matching_Field --
10765 ----------------------------
10767 function Has_One_Matching_Field return Boolean is
10771 if Is_Array_Type (Expec_Type)
10772 and then Number_Dimensions (Expec_Type) = 1
10774 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
10778 elsif not Is_Record_Type (Expec_Type) then
10782 E := First_Entity (Expec_Type);
10787 elsif (Ekind (E) /= E_Discriminant
10788 and then Ekind (E) /= E_Component)
10789 or else (Chars (E) = Name_uTag
10790 or else Chars (E) = Name_uParent)
10799 if not Covers (Etype (E), Found_Type) then
10802 elsif Present (Next_Entity (E)) then
10809 end Has_One_Matching_Field;
10811 -- Start of processing for Wrong_Type
10814 -- Don't output message if either type is Any_Type, or if a message
10815 -- has already been posted for this node. We need to do the latter
10816 -- check explicitly (it is ordinarily done in Errout), because we
10817 -- are using ! to force the output of the error messages.
10819 if Expec_Type = Any_Type
10820 or else Found_Type = Any_Type
10821 or else Error_Posted (Expr)
10825 -- In an instance, there is an ongoing problem with completion of
10826 -- type derived from private types. Their structure is what Gigi
10827 -- expects, but the Etype is the parent type rather than the
10828 -- derived private type itself. Do not flag error in this case. The
10829 -- private completion is an entity without a parent, like an Itype.
10830 -- Similarly, full and partial views may be incorrect in the instance.
10831 -- There is no simple way to insure that it is consistent ???
10833 elsif In_Instance then
10834 if Etype (Etype (Expr)) = Etype (Expected_Type)
10836 (Has_Private_Declaration (Expected_Type)
10837 or else Has_Private_Declaration (Etype (Expr)))
10838 and then No (Parent (Expected_Type))
10844 -- An interesting special check. If the expression is parenthesized
10845 -- and its type corresponds to the type of the sole component of the
10846 -- expected record type, or to the component type of the expected one
10847 -- dimensional array type, then assume we have a bad aggregate attempt.
10849 if Nkind (Expr) in N_Subexpr
10850 and then Paren_Count (Expr) /= 0
10851 and then Has_One_Matching_Field
10853 Error_Msg_N ("positional aggregate cannot have one component", Expr);
10855 -- Another special check, if we are looking for a pool-specific access
10856 -- type and we found an E_Access_Attribute_Type, then we have the case
10857 -- of an Access attribute being used in a context which needs a pool-
10858 -- specific type, which is never allowed. The one extra check we make
10859 -- is that the expected designated type covers the Found_Type.
10861 elsif Is_Access_Type (Expec_Type)
10862 and then Ekind (Found_Type) = E_Access_Attribute_Type
10863 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
10864 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
10866 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
10868 Error_Msg_N ("result must be general access type!", Expr);
10869 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
10871 -- Another special check, if the expected type is an integer type,
10872 -- but the expression is of type System.Address, and the parent is
10873 -- an addition or subtraction operation whose left operand is the
10874 -- expression in question and whose right operand is of an integral
10875 -- type, then this is an attempt at address arithmetic, so give
10876 -- appropriate message.
10878 elsif Is_Integer_Type (Expec_Type)
10879 and then Is_RTE (Found_Type, RE_Address)
10880 and then (Nkind (Parent (Expr)) = N_Op_Add
10882 Nkind (Parent (Expr)) = N_Op_Subtract)
10883 and then Expr = Left_Opnd (Parent (Expr))
10884 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
10887 ("address arithmetic not predefined in package System",
10890 ("\possible missing with/use of System.Storage_Elements",
10894 -- If the expected type is an anonymous access type, as for access
10895 -- parameters and discriminants, the error is on the designated types.
10897 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
10898 if Comes_From_Source (Expec_Type) then
10899 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10902 ("expected an access type with designated}",
10903 Expr, Designated_Type (Expec_Type));
10906 if Is_Access_Type (Found_Type)
10907 and then not Comes_From_Source (Found_Type)
10910 ("\\found an access type with designated}!",
10911 Expr, Designated_Type (Found_Type));
10913 if From_With_Type (Found_Type) then
10914 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
10915 Error_Msg_Qual_Level := 99;
10916 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
10917 Error_Msg_Qual_Level := 0;
10919 Error_Msg_NE ("found}!", Expr, Found_Type);
10923 -- Normal case of one type found, some other type expected
10926 -- If the names of the two types are the same, see if some number
10927 -- of levels of qualification will help. Don't try more than three
10928 -- levels, and if we get to standard, it's no use (and probably
10929 -- represents an error in the compiler) Also do not bother with
10930 -- internal scope names.
10933 Expec_Scope : Entity_Id;
10934 Found_Scope : Entity_Id;
10937 Expec_Scope := Expec_Type;
10938 Found_Scope := Found_Type;
10940 for Levels in Int range 0 .. 3 loop
10941 if Chars (Expec_Scope) /= Chars (Found_Scope) then
10942 Error_Msg_Qual_Level := Levels;
10946 Expec_Scope := Scope (Expec_Scope);
10947 Found_Scope := Scope (Found_Scope);
10949 exit when Expec_Scope = Standard_Standard
10950 or else Found_Scope = Standard_Standard
10951 or else not Comes_From_Source (Expec_Scope)
10952 or else not Comes_From_Source (Found_Scope);
10956 if Is_Record_Type (Expec_Type)
10957 and then Present (Corresponding_Remote_Type (Expec_Type))
10959 Error_Msg_NE ("expected}!", Expr,
10960 Corresponding_Remote_Type (Expec_Type));
10962 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10965 if Is_Entity_Name (Expr)
10966 and then Is_Package_Or_Generic_Package (Entity (Expr))
10968 Error_Msg_N ("\\found package name!", Expr);
10970 elsif Is_Entity_Name (Expr)
10972 (Ekind (Entity (Expr)) = E_Procedure
10974 Ekind (Entity (Expr)) = E_Generic_Procedure)
10976 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
10978 ("found procedure name, possibly missing Access attribute!",
10982 ("\\found procedure name instead of function!", Expr);
10985 elsif Nkind (Expr) = N_Function_Call
10986 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
10987 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
10988 and then No (Parameter_Associations (Expr))
10991 ("found function name, possibly missing Access attribute!",
10994 -- Catch common error: a prefix or infix operator which is not
10995 -- directly visible because the type isn't.
10997 elsif Nkind (Expr) in N_Op
10998 and then Is_Overloaded (Expr)
10999 and then not Is_Immediately_Visible (Expec_Type)
11000 and then not Is_Potentially_Use_Visible (Expec_Type)
11001 and then not In_Use (Expec_Type)
11002 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11005 ("operator of the type is not directly visible!", Expr);
11007 elsif Ekind (Found_Type) = E_Void
11008 and then Present (Parent (Found_Type))
11009 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11011 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11014 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11017 Error_Msg_Qual_Level := 0;