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_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Type; use Sem_Type;
54 with Sinfo; use Sinfo;
55 with Sinput; use Sinput;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
59 with Targparm; use Targparm;
60 with Tbuild; use Tbuild;
61 with Ttypes; use Ttypes;
62 with Uname; use Uname;
64 with GNAT.HTable; use GNAT.HTable;
65 package body Sem_Util is
67 ----------------------------------------
68 -- Global_Variables for New_Copy_Tree --
69 ----------------------------------------
71 -- These global variables are used by New_Copy_Tree. See description
72 -- of the body of this subprogram for details. Global variables can be
73 -- safely used by New_Copy_Tree, since there is no case of a recursive
74 -- call from the processing inside New_Copy_Tree.
76 NCT_Hash_Threshhold : constant := 20;
77 -- If there are more than this number of pairs of entries in the
78 -- map, then Hash_Tables_Used will be set, and the hash tables will
79 -- be initialized and used for the searches.
81 NCT_Hash_Tables_Used : Boolean := False;
82 -- Set to True if hash tables are in use
84 NCT_Table_Entries : Nat;
85 -- Count entries in table to see if threshhold is reached
87 NCT_Hash_Table_Setup : Boolean := False;
88 -- Set to True if hash table contains data. We set this True if we
89 -- setup the hash table with data, and leave it set permanently
90 -- from then on, this is a signal that second and subsequent users
91 -- of the hash table must clear the old entries before reuse.
93 subtype NCT_Header_Num is Int range 0 .. 511;
94 -- Defines range of headers in hash tables (512 headers)
96 -----------------------
97 -- Local Subprograms --
98 -----------------------
100 function Build_Component_Subtype
103 T : Entity_Id) return Node_Id;
104 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
105 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
106 -- Loc is the source location, T is the original subtype.
108 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
109 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
110 -- with discriminants whose default values are static, examine only the
111 -- components in the selected variant to determine whether all of them
114 function Has_Null_Extension (T : Entity_Id) return Boolean;
115 -- T is a derived tagged type. Check whether the type extension is null.
116 -- If the parent type is fully initialized, T can be treated as such.
118 ------------------------------
119 -- Abstract_Interface_List --
120 ------------------------------
122 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
126 if Is_Concurrent_Type (Typ) then
128 -- If we are dealing with a synchronized subtype, go to the base
129 -- type, whose declaration has the interface list.
131 -- Shouldn't this be Declaration_Node???
133 Nod := Parent (Base_Type (Typ));
135 if Nkind (Nod) = N_Full_Type_Declaration then
139 elsif Ekind (Typ) = E_Record_Type_With_Private then
140 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
141 Nod := Type_Definition (Parent (Typ));
143 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
144 if Present (Full_View (Typ)) then
145 Nod := Type_Definition (Parent (Full_View (Typ)));
147 -- If the full-view is not available we cannot do anything else
148 -- here (the source has errors).
154 -- Support for generic formals with interfaces is still missing ???
156 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
161 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
165 elsif Ekind (Typ) = E_Record_Subtype then
166 Nod := Type_Definition (Parent (Etype (Typ)));
168 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
170 -- Recurse, because parent may still be a private extension. Also
171 -- note that the full view of the subtype or the full view of its
172 -- base type may (both) be unavailable.
174 return Abstract_Interface_List (Etype (Typ));
176 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
177 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
178 Nod := Formal_Type_Definition (Parent (Typ));
180 Nod := Type_Definition (Parent (Typ));
184 return Interface_List (Nod);
185 end Abstract_Interface_List;
187 --------------------------------
188 -- Add_Access_Type_To_Process --
189 --------------------------------
191 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
195 Ensure_Freeze_Node (E);
196 L := Access_Types_To_Process (Freeze_Node (E));
200 Set_Access_Types_To_Process (Freeze_Node (E), L);
204 end Add_Access_Type_To_Process;
206 ----------------------------
207 -- Add_Global_Declaration --
208 ----------------------------
210 procedure Add_Global_Declaration (N : Node_Id) is
211 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
214 if No (Declarations (Aux_Node)) then
215 Set_Declarations (Aux_Node, New_List);
218 Append_To (Declarations (Aux_Node), N);
220 end Add_Global_Declaration;
222 -----------------------
223 -- Alignment_In_Bits --
224 -----------------------
226 function Alignment_In_Bits (E : Entity_Id) return Uint is
228 return Alignment (E) * System_Storage_Unit;
229 end Alignment_In_Bits;
231 -----------------------------------------
232 -- Apply_Compile_Time_Constraint_Error --
233 -----------------------------------------
235 procedure Apply_Compile_Time_Constraint_Error
238 Reason : RT_Exception_Code;
239 Ent : Entity_Id := Empty;
240 Typ : Entity_Id := Empty;
241 Loc : Source_Ptr := No_Location;
242 Rep : Boolean := True;
243 Warn : Boolean := False)
245 Stat : constant Boolean := Is_Static_Expression (N);
246 R_Stat : constant Node_Id :=
247 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
258 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
264 -- Now we replace the node by an N_Raise_Constraint_Error node
265 -- This does not need reanalyzing, so set it as analyzed now.
268 Set_Analyzed (N, True);
271 Set_Raises_Constraint_Error (N);
273 -- Now deal with possible local raise handling
275 Possible_Local_Raise (N, Standard_Constraint_Error);
277 -- If the original expression was marked as static, the result is
278 -- still marked as static, but the Raises_Constraint_Error flag is
279 -- always set so that further static evaluation is not attempted.
282 Set_Is_Static_Expression (N);
284 end Apply_Compile_Time_Constraint_Error;
286 --------------------------
287 -- Build_Actual_Subtype --
288 --------------------------
290 function Build_Actual_Subtype
292 N : Node_Or_Entity_Id) return Node_Id
295 -- Normally Sloc (N), but may point to corresponding body in some cases
297 Constraints : List_Id;
303 Disc_Type : Entity_Id;
309 if Nkind (N) = N_Defining_Identifier then
310 Obj := New_Reference_To (N, Loc);
312 -- If this is a formal parameter of a subprogram declaration, and
313 -- we are compiling the body, we want the declaration for the
314 -- actual subtype to carry the source position of the body, to
315 -- prevent anomalies in gdb when stepping through the code.
317 if Is_Formal (N) then
319 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
321 if Nkind (Decl) = N_Subprogram_Declaration
322 and then Present (Corresponding_Body (Decl))
324 Loc := Sloc (Corresponding_Body (Decl));
333 if Is_Array_Type (T) then
334 Constraints := New_List;
335 for J in 1 .. Number_Dimensions (T) loop
337 -- Build an array subtype declaration with the nominal subtype and
338 -- the bounds of the actual. Add the declaration in front of the
339 -- local declarations for the subprogram, for analysis before any
340 -- reference to the formal in the body.
343 Make_Attribute_Reference (Loc,
345 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
346 Attribute_Name => Name_First,
347 Expressions => New_List (
348 Make_Integer_Literal (Loc, J)));
351 Make_Attribute_Reference (Loc,
353 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
354 Attribute_Name => Name_Last,
355 Expressions => New_List (
356 Make_Integer_Literal (Loc, J)));
358 Append (Make_Range (Loc, Lo, Hi), Constraints);
361 -- If the type has unknown discriminants there is no constrained
362 -- subtype to build. This is never called for a formal or for a
363 -- lhs, so returning the type is ok ???
365 elsif Has_Unknown_Discriminants (T) then
369 Constraints := New_List;
371 -- Type T is a generic derived type, inherit the discriminants from
374 if Is_Private_Type (T)
375 and then No (Full_View (T))
377 -- T was flagged as an error if it was declared as a formal
378 -- derived type with known discriminants. In this case there
379 -- is no need to look at the parent type since T already carries
380 -- its own discriminants.
382 and then not Error_Posted (T)
384 Disc_Type := Etype (Base_Type (T));
389 Discr := First_Discriminant (Disc_Type);
390 while Present (Discr) loop
391 Append_To (Constraints,
392 Make_Selected_Component (Loc,
394 Duplicate_Subexpr_No_Checks (Obj),
395 Selector_Name => New_Occurrence_Of (Discr, Loc)));
396 Next_Discriminant (Discr);
401 Make_Defining_Identifier (Loc,
402 Chars => New_Internal_Name ('S'));
403 Set_Is_Internal (Subt);
406 Make_Subtype_Declaration (Loc,
407 Defining_Identifier => Subt,
408 Subtype_Indication =>
409 Make_Subtype_Indication (Loc,
410 Subtype_Mark => New_Reference_To (T, Loc),
412 Make_Index_Or_Discriminant_Constraint (Loc,
413 Constraints => Constraints)));
415 Mark_Rewrite_Insertion (Decl);
417 end Build_Actual_Subtype;
419 ---------------------------------------
420 -- Build_Actual_Subtype_Of_Component --
421 ---------------------------------------
423 function Build_Actual_Subtype_Of_Component
425 N : Node_Id) return Node_Id
427 Loc : constant Source_Ptr := Sloc (N);
428 P : constant Node_Id := Prefix (N);
431 Indx_Type : Entity_Id;
433 Deaccessed_T : Entity_Id;
434 -- This is either a copy of T, or if T is an access type, then it is
435 -- the directly designated type of this access type.
437 function Build_Actual_Array_Constraint return List_Id;
438 -- If one or more of the bounds of the component depends on
439 -- discriminants, build actual constraint using the discriminants
442 function Build_Actual_Record_Constraint return List_Id;
443 -- Similar to previous one, for discriminated components constrained
444 -- by the discriminant of the enclosing object.
446 -----------------------------------
447 -- Build_Actual_Array_Constraint --
448 -----------------------------------
450 function Build_Actual_Array_Constraint return List_Id is
451 Constraints : constant List_Id := New_List;
459 Indx := First_Index (Deaccessed_T);
460 while Present (Indx) loop
461 Old_Lo := Type_Low_Bound (Etype (Indx));
462 Old_Hi := Type_High_Bound (Etype (Indx));
464 if Denotes_Discriminant (Old_Lo) then
466 Make_Selected_Component (Loc,
467 Prefix => New_Copy_Tree (P),
468 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
471 Lo := New_Copy_Tree (Old_Lo);
473 -- The new bound will be reanalyzed in the enclosing
474 -- declaration. For literal bounds that come from a type
475 -- declaration, the type of the context must be imposed, so
476 -- insure that analysis will take place. For non-universal
477 -- types this is not strictly necessary.
479 Set_Analyzed (Lo, False);
482 if Denotes_Discriminant (Old_Hi) then
484 Make_Selected_Component (Loc,
485 Prefix => New_Copy_Tree (P),
486 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
489 Hi := New_Copy_Tree (Old_Hi);
490 Set_Analyzed (Hi, False);
493 Append (Make_Range (Loc, Lo, Hi), Constraints);
498 end Build_Actual_Array_Constraint;
500 ------------------------------------
501 -- Build_Actual_Record_Constraint --
502 ------------------------------------
504 function Build_Actual_Record_Constraint return List_Id is
505 Constraints : constant List_Id := New_List;
510 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
511 while Present (D) loop
512 if Denotes_Discriminant (Node (D)) then
513 D_Val := Make_Selected_Component (Loc,
514 Prefix => New_Copy_Tree (P),
515 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
518 D_Val := New_Copy_Tree (Node (D));
521 Append (D_Val, Constraints);
526 end Build_Actual_Record_Constraint;
528 -- Start of processing for Build_Actual_Subtype_Of_Component
531 -- Why the test for Spec_Expression mode here???
533 if In_Spec_Expression then
536 -- More comments for the rest of this body would be good ???
538 elsif Nkind (N) = N_Explicit_Dereference then
539 if Is_Composite_Type (T)
540 and then not Is_Constrained (T)
541 and then not (Is_Class_Wide_Type (T)
542 and then Is_Constrained (Root_Type (T)))
543 and then not Has_Unknown_Discriminants (T)
545 -- If the type of the dereference is already constrained, it
546 -- is an actual subtype.
548 if Is_Array_Type (Etype (N))
549 and then Is_Constrained (Etype (N))
553 Remove_Side_Effects (P);
554 return Build_Actual_Subtype (T, N);
561 if Ekind (T) = E_Access_Subtype then
562 Deaccessed_T := Designated_Type (T);
567 if Ekind (Deaccessed_T) = E_Array_Subtype then
568 Id := First_Index (Deaccessed_T);
569 while Present (Id) loop
570 Indx_Type := Underlying_Type (Etype (Id));
572 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
574 Denotes_Discriminant (Type_High_Bound (Indx_Type))
576 Remove_Side_Effects (P);
578 Build_Component_Subtype
579 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
585 elsif Is_Composite_Type (Deaccessed_T)
586 and then Has_Discriminants (Deaccessed_T)
587 and then not Has_Unknown_Discriminants (Deaccessed_T)
589 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
590 while Present (D) loop
591 if Denotes_Discriminant (Node (D)) then
592 Remove_Side_Effects (P);
594 Build_Component_Subtype (
595 Build_Actual_Record_Constraint, Loc, Base_Type (T));
602 -- If none of the above, the actual and nominal subtypes are the same
605 end Build_Actual_Subtype_Of_Component;
607 -----------------------------
608 -- Build_Component_Subtype --
609 -----------------------------
611 function Build_Component_Subtype
614 T : Entity_Id) return Node_Id
620 -- Unchecked_Union components do not require component subtypes
622 if Is_Unchecked_Union (T) then
627 Make_Defining_Identifier (Loc,
628 Chars => New_Internal_Name ('S'));
629 Set_Is_Internal (Subt);
632 Make_Subtype_Declaration (Loc,
633 Defining_Identifier => Subt,
634 Subtype_Indication =>
635 Make_Subtype_Indication (Loc,
636 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
638 Make_Index_Or_Discriminant_Constraint (Loc,
641 Mark_Rewrite_Insertion (Decl);
643 end Build_Component_Subtype;
645 ---------------------------
646 -- Build_Default_Subtype --
647 ---------------------------
649 function Build_Default_Subtype
651 N : Node_Id) return Entity_Id
653 Loc : constant Source_Ptr := Sloc (N);
657 if not Has_Discriminants (T) or else Is_Constrained (T) then
661 Disc := First_Discriminant (T);
663 if No (Discriminant_Default_Value (Disc)) then
668 Act : constant Entity_Id :=
669 Make_Defining_Identifier (Loc,
670 Chars => New_Internal_Name ('S'));
672 Constraints : constant List_Id := New_List;
676 while Present (Disc) loop
677 Append_To (Constraints,
678 New_Copy_Tree (Discriminant_Default_Value (Disc)));
679 Next_Discriminant (Disc);
683 Make_Subtype_Declaration (Loc,
684 Defining_Identifier => Act,
685 Subtype_Indication =>
686 Make_Subtype_Indication (Loc,
687 Subtype_Mark => New_Occurrence_Of (T, Loc),
689 Make_Index_Or_Discriminant_Constraint (Loc,
690 Constraints => Constraints)));
692 Insert_Action (N, Decl);
696 end Build_Default_Subtype;
698 --------------------------------------------
699 -- Build_Discriminal_Subtype_Of_Component --
700 --------------------------------------------
702 function Build_Discriminal_Subtype_Of_Component
703 (T : Entity_Id) return Node_Id
705 Loc : constant Source_Ptr := Sloc (T);
709 function Build_Discriminal_Array_Constraint return List_Id;
710 -- If one or more of the bounds of the component depends on
711 -- discriminants, build actual constraint using the discriminants
714 function Build_Discriminal_Record_Constraint return List_Id;
715 -- Similar to previous one, for discriminated components constrained
716 -- by the discriminant of the enclosing object.
718 ----------------------------------------
719 -- Build_Discriminal_Array_Constraint --
720 ----------------------------------------
722 function Build_Discriminal_Array_Constraint return List_Id is
723 Constraints : constant List_Id := New_List;
731 Indx := First_Index (T);
732 while Present (Indx) loop
733 Old_Lo := Type_Low_Bound (Etype (Indx));
734 Old_Hi := Type_High_Bound (Etype (Indx));
736 if Denotes_Discriminant (Old_Lo) then
737 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
740 Lo := New_Copy_Tree (Old_Lo);
743 if Denotes_Discriminant (Old_Hi) then
744 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
747 Hi := New_Copy_Tree (Old_Hi);
750 Append (Make_Range (Loc, Lo, Hi), Constraints);
755 end Build_Discriminal_Array_Constraint;
757 -----------------------------------------
758 -- Build_Discriminal_Record_Constraint --
759 -----------------------------------------
761 function Build_Discriminal_Record_Constraint return List_Id is
762 Constraints : constant List_Id := New_List;
767 D := First_Elmt (Discriminant_Constraint (T));
768 while Present (D) loop
769 if Denotes_Discriminant (Node (D)) then
771 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
774 D_Val := New_Copy_Tree (Node (D));
777 Append (D_Val, Constraints);
782 end Build_Discriminal_Record_Constraint;
784 -- Start of processing for Build_Discriminal_Subtype_Of_Component
787 if Ekind (T) = E_Array_Subtype then
788 Id := First_Index (T);
789 while Present (Id) loop
790 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
791 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
793 return Build_Component_Subtype
794 (Build_Discriminal_Array_Constraint, Loc, T);
800 elsif Ekind (T) = E_Record_Subtype
801 and then Has_Discriminants (T)
802 and then not Has_Unknown_Discriminants (T)
804 D := First_Elmt (Discriminant_Constraint (T));
805 while Present (D) loop
806 if Denotes_Discriminant (Node (D)) then
807 return Build_Component_Subtype
808 (Build_Discriminal_Record_Constraint, Loc, T);
815 -- If none of the above, the actual and nominal subtypes are the same
818 end Build_Discriminal_Subtype_Of_Component;
820 ------------------------------
821 -- Build_Elaboration_Entity --
822 ------------------------------
824 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
825 Loc : constant Source_Ptr := Sloc (N);
827 Elab_Ent : Entity_Id;
829 procedure Set_Package_Name (Ent : Entity_Id);
830 -- Given an entity, sets the fully qualified name of the entity in
831 -- Name_Buffer, with components separated by double underscores. This
832 -- is a recursive routine that climbs the scope chain to Standard.
834 ----------------------
835 -- Set_Package_Name --
836 ----------------------
838 procedure Set_Package_Name (Ent : Entity_Id) is
840 if Scope (Ent) /= Standard_Standard then
841 Set_Package_Name (Scope (Ent));
844 Nam : constant String := Get_Name_String (Chars (Ent));
846 Name_Buffer (Name_Len + 1) := '_';
847 Name_Buffer (Name_Len + 2) := '_';
848 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
849 Name_Len := Name_Len + Nam'Length + 2;
853 Get_Name_String (Chars (Ent));
855 end Set_Package_Name;
857 -- Start of processing for Build_Elaboration_Entity
860 -- Ignore if already constructed
862 if Present (Elaboration_Entity (Spec_Id)) then
866 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
867 -- name with dots replaced by double underscore. We have to manually
868 -- construct this name, since it will be elaborated in the outer scope,
869 -- and thus will not have the unit name automatically prepended.
871 Set_Package_Name (Spec_Id);
875 Name_Buffer (Name_Len + 1) := '_';
876 Name_Buffer (Name_Len + 2) := 'E';
877 Name_Len := Name_Len + 2;
879 -- Create elaboration flag
882 Make_Defining_Identifier (Loc, Chars => Name_Find);
883 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
886 Make_Object_Declaration (Loc,
887 Defining_Identifier => Elab_Ent,
889 New_Occurrence_Of (Standard_Boolean, Loc),
891 New_Occurrence_Of (Standard_False, Loc));
893 Push_Scope (Standard_Standard);
894 Add_Global_Declaration (Decl);
897 -- Reset True_Constant indication, since we will indeed assign a value
898 -- to the variable in the binder main. We also kill the Current_Value
899 -- and Last_Assignment fields for the same reason.
901 Set_Is_True_Constant (Elab_Ent, False);
902 Set_Current_Value (Elab_Ent, Empty);
903 Set_Last_Assignment (Elab_Ent, Empty);
905 -- We do not want any further qualification of the name (if we did
906 -- not do this, we would pick up the name of the generic package
907 -- in the case of a library level generic instantiation).
909 Set_Has_Qualified_Name (Elab_Ent);
910 Set_Has_Fully_Qualified_Name (Elab_Ent);
911 end Build_Elaboration_Entity;
913 -----------------------------------
914 -- Cannot_Raise_Constraint_Error --
915 -----------------------------------
917 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
919 if Compile_Time_Known_Value (Expr) then
922 elsif Do_Range_Check (Expr) then
925 elsif Raises_Constraint_Error (Expr) then
933 when N_Expanded_Name =>
936 when N_Selected_Component =>
937 return not Do_Discriminant_Check (Expr);
939 when N_Attribute_Reference =>
940 if Do_Overflow_Check (Expr) then
943 elsif No (Expressions (Expr)) then
951 N := First (Expressions (Expr));
952 while Present (N) loop
953 if Cannot_Raise_Constraint_Error (N) then
964 when N_Type_Conversion =>
965 if Do_Overflow_Check (Expr)
966 or else Do_Length_Check (Expr)
967 or else Do_Tag_Check (Expr)
972 Cannot_Raise_Constraint_Error (Expression (Expr));
975 when N_Unchecked_Type_Conversion =>
976 return Cannot_Raise_Constraint_Error (Expression (Expr));
979 if Do_Overflow_Check (Expr) then
983 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
990 if Do_Division_Check (Expr)
991 or else Do_Overflow_Check (Expr)
996 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
998 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1017 N_Op_Shift_Right_Arithmetic |
1021 if Do_Overflow_Check (Expr) then
1025 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1027 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1034 end Cannot_Raise_Constraint_Error;
1036 -----------------------------------------
1037 -- Check_Dynamically_Tagged_Expression --
1038 -----------------------------------------
1040 procedure Check_Dynamically_Tagged_Expression
1043 Related_Nod : Node_Id)
1046 pragma Assert (Is_Tagged_Type (Typ));
1048 -- In order to avoid spurious errors when analyzing the expanded code,
1049 -- this check is done only for nodes that come from source and for
1050 -- actuals of generic instantiations.
1052 if (Comes_From_Source (Related_Nod)
1053 or else In_Generic_Actual (Expr))
1054 and then (Is_Class_Wide_Type (Etype (Expr))
1055 or else Is_Dynamically_Tagged (Expr))
1056 and then Is_Tagged_Type (Typ)
1057 and then not Is_Class_Wide_Type (Typ)
1059 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1061 end Check_Dynamically_Tagged_Expression;
1063 --------------------------
1064 -- Check_Fully_Declared --
1065 --------------------------
1067 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1069 if Ekind (T) = E_Incomplete_Type then
1071 -- Ada 2005 (AI-50217): If the type is available through a limited
1072 -- with_clause, verify that its full view has been analyzed.
1074 if From_With_Type (T)
1075 and then Present (Non_Limited_View (T))
1076 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1078 -- The non-limited view is fully declared
1083 ("premature usage of incomplete}", N, First_Subtype (T));
1086 -- Need comments for these tests ???
1088 elsif Has_Private_Component (T)
1089 and then not Is_Generic_Type (Root_Type (T))
1090 and then not In_Spec_Expression
1092 -- Special case: if T is the anonymous type created for a single
1093 -- task or protected object, use the name of the source object.
1095 if Is_Concurrent_Type (T)
1096 and then not Comes_From_Source (T)
1097 and then Nkind (N) = N_Object_Declaration
1099 Error_Msg_NE ("type of& has incomplete component", N,
1100 Defining_Identifier (N));
1104 ("premature usage of incomplete}", N, First_Subtype (T));
1107 end Check_Fully_Declared;
1109 -------------------------
1110 -- Check_Nested_Access --
1111 -------------------------
1113 procedure Check_Nested_Access (Ent : Entity_Id) is
1114 Scop : constant Entity_Id := Current_Scope;
1115 Current_Subp : Entity_Id;
1116 Enclosing : Entity_Id;
1119 -- Currently only enabled for VM back-ends for efficiency, should we
1120 -- enable it more systematically ???
1122 -- Check for Is_Imported needs commenting below ???
1124 if VM_Target /= No_VM
1125 and then (Ekind (Ent) = E_Variable
1127 Ekind (Ent) = E_Constant
1129 Ekind (Ent) = E_Loop_Parameter)
1130 and then Scope (Ent) /= Empty
1131 and then not Is_Library_Level_Entity (Ent)
1132 and then not Is_Imported (Ent)
1134 if Is_Subprogram (Scop)
1135 or else Is_Generic_Subprogram (Scop)
1136 or else Is_Entry (Scop)
1138 Current_Subp := Scop;
1140 Current_Subp := Current_Subprogram;
1143 Enclosing := Enclosing_Subprogram (Ent);
1145 if Enclosing /= Empty
1146 and then Enclosing /= Current_Subp
1148 Set_Has_Up_Level_Access (Ent, True);
1151 end Check_Nested_Access;
1153 ------------------------------------------
1154 -- Check_Potentially_Blocking_Operation --
1155 ------------------------------------------
1157 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1160 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1161 -- When pragma Detect_Blocking is active, the run time will raise
1162 -- Program_Error. Here we only issue a warning, since we generally
1163 -- support the use of potentially blocking operations in the absence
1166 -- Indirect blocking through a subprogram call cannot be diagnosed
1167 -- statically without interprocedural analysis, so we do not attempt
1170 S := Scope (Current_Scope);
1171 while Present (S) and then S /= Standard_Standard loop
1172 if Is_Protected_Type (S) then
1174 ("potentially blocking operation in protected operation?", N);
1181 end Check_Potentially_Blocking_Operation;
1183 ------------------------------
1184 -- Check_Unprotected_Access --
1185 ------------------------------
1187 procedure Check_Unprotected_Access
1191 Cont_Encl_Typ : Entity_Id;
1192 Pref_Encl_Typ : Entity_Id;
1194 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1195 -- Check whether Obj is a private component of a protected object.
1196 -- Return the protected type where the component resides, Empty
1199 function Is_Public_Operation return Boolean;
1200 -- Verify that the enclosing operation is callable from outside the
1201 -- protected object, to minimize false positives.
1203 ------------------------------
1204 -- Enclosing_Protected_Type --
1205 ------------------------------
1207 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1209 if Is_Entity_Name (Obj) then
1211 Ent : Entity_Id := Entity (Obj);
1214 -- The object can be a renaming of a private component, use
1215 -- the original record component.
1217 if Is_Prival (Ent) then
1218 Ent := Prival_Link (Ent);
1221 if Is_Protected_Type (Scope (Ent)) then
1227 -- For indexed and selected components, recursively check the prefix
1229 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1230 return Enclosing_Protected_Type (Prefix (Obj));
1232 -- The object does not denote a protected component
1237 end Enclosing_Protected_Type;
1239 -------------------------
1240 -- Is_Public_Operation --
1241 -------------------------
1243 function Is_Public_Operation return Boolean is
1250 and then S /= Pref_Encl_Typ
1252 if Scope (S) = Pref_Encl_Typ then
1253 E := First_Entity (Pref_Encl_Typ);
1255 and then E /= First_Private_Entity (Pref_Encl_Typ)
1268 end Is_Public_Operation;
1270 -- Start of processing for Check_Unprotected_Access
1273 if Nkind (Expr) = N_Attribute_Reference
1274 and then Attribute_Name (Expr) = Name_Unchecked_Access
1276 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1277 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1279 -- Check whether we are trying to export a protected component to a
1280 -- context with an equal or lower access level.
1282 if Present (Pref_Encl_Typ)
1283 and then No (Cont_Encl_Typ)
1284 and then Is_Public_Operation
1285 and then Scope_Depth (Pref_Encl_Typ) >=
1286 Object_Access_Level (Context)
1289 ("?possible unprotected access to protected data", Expr);
1292 end Check_Unprotected_Access;
1298 procedure Check_VMS (Construct : Node_Id) is
1300 if not OpenVMS_On_Target then
1302 ("this construct is allowed only in Open'V'M'S", Construct);
1306 ------------------------
1307 -- Collect_Interfaces --
1308 ------------------------
1310 procedure Collect_Interfaces
1312 Ifaces_List : out Elist_Id;
1313 Exclude_Parents : Boolean := False;
1314 Use_Full_View : Boolean := True)
1316 procedure Collect (Typ : Entity_Id);
1317 -- Subsidiary subprogram used to traverse the whole list
1318 -- of directly and indirectly implemented interfaces
1324 procedure Collect (Typ : Entity_Id) is
1325 Ancestor : Entity_Id;
1333 -- Handle private types
1336 and then Is_Private_Type (Typ)
1337 and then Present (Full_View (Typ))
1339 Full_T := Full_View (Typ);
1342 -- Include the ancestor if we are generating the whole list of
1343 -- abstract interfaces.
1345 if Etype (Full_T) /= Typ
1347 -- Protect the frontend against wrong sources. For example:
1350 -- type A is tagged null record;
1351 -- type B is new A with private;
1352 -- type C is new A with private;
1354 -- type B is new C with null record;
1355 -- type C is new B with null record;
1358 and then Etype (Full_T) /= T
1360 Ancestor := Etype (Full_T);
1363 if Is_Interface (Ancestor)
1364 and then not Exclude_Parents
1366 Append_Unique_Elmt (Ancestor, Ifaces_List);
1370 -- Traverse the graph of ancestor interfaces
1372 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1373 Id := First (Abstract_Interface_List (Full_T));
1374 while Present (Id) loop
1375 Iface := Etype (Id);
1377 -- Protect against wrong uses. For example:
1378 -- type I is interface;
1379 -- type O is tagged null record;
1380 -- type Wrong is new I and O with null record; -- ERROR
1382 if Is_Interface (Iface) then
1384 and then Etype (T) /= T
1385 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1390 Append_Unique_Elmt (Iface, Ifaces_List);
1399 -- Start of processing for Collect_Interfaces
1402 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1403 Ifaces_List := New_Elmt_List;
1405 end Collect_Interfaces;
1407 ----------------------------------
1408 -- Collect_Interface_Components --
1409 ----------------------------------
1411 procedure Collect_Interface_Components
1412 (Tagged_Type : Entity_Id;
1413 Components_List : out Elist_Id)
1415 procedure Collect (Typ : Entity_Id);
1416 -- Subsidiary subprogram used to climb to the parents
1422 procedure Collect (Typ : Entity_Id) is
1423 Tag_Comp : Entity_Id;
1424 Parent_Typ : Entity_Id;
1427 -- Handle private types
1429 if Present (Full_View (Etype (Typ))) then
1430 Parent_Typ := Full_View (Etype (Typ));
1432 Parent_Typ := Etype (Typ);
1435 if Parent_Typ /= Typ
1437 -- Protect the frontend against wrong sources. For example:
1440 -- type A is tagged null record;
1441 -- type B is new A with private;
1442 -- type C is new A with private;
1444 -- type B is new C with null record;
1445 -- type C is new B with null record;
1448 and then Parent_Typ /= Tagged_Type
1450 Collect (Parent_Typ);
1453 -- Collect the components containing tags of secondary dispatch
1456 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1457 while Present (Tag_Comp) loop
1458 pragma Assert (Present (Related_Type (Tag_Comp)));
1459 Append_Elmt (Tag_Comp, Components_List);
1461 Tag_Comp := Next_Tag_Component (Tag_Comp);
1465 -- Start of processing for Collect_Interface_Components
1468 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1469 and then Is_Tagged_Type (Tagged_Type));
1471 Components_List := New_Elmt_List;
1472 Collect (Tagged_Type);
1473 end Collect_Interface_Components;
1475 -----------------------------
1476 -- Collect_Interfaces_Info --
1477 -----------------------------
1479 procedure Collect_Interfaces_Info
1481 Ifaces_List : out Elist_Id;
1482 Components_List : out Elist_Id;
1483 Tags_List : out Elist_Id)
1485 Comps_List : Elist_Id;
1486 Comp_Elmt : Elmt_Id;
1487 Comp_Iface : Entity_Id;
1488 Iface_Elmt : Elmt_Id;
1491 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1492 -- Search for the secondary tag associated with the interface type
1493 -- Iface that is implemented by T.
1499 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1503 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1505 and then Ekind (Node (ADT)) = E_Constant
1506 and then Related_Type (Node (ADT)) /= Iface
1508 -- Skip the secondary dispatch tables of Iface
1516 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1520 -- Start of processing for Collect_Interfaces_Info
1523 Collect_Interfaces (T, Ifaces_List);
1524 Collect_Interface_Components (T, Comps_List);
1526 -- Search for the record component and tag associated with each
1527 -- interface type of T.
1529 Components_List := New_Elmt_List;
1530 Tags_List := New_Elmt_List;
1532 Iface_Elmt := First_Elmt (Ifaces_List);
1533 while Present (Iface_Elmt) loop
1534 Iface := Node (Iface_Elmt);
1536 -- Associate the primary tag component and the primary dispatch table
1537 -- with all the interfaces that are parents of T
1539 if Is_Ancestor (Iface, T) then
1540 Append_Elmt (First_Tag_Component (T), Components_List);
1541 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1543 -- Otherwise search for the tag component and secondary dispatch
1547 Comp_Elmt := First_Elmt (Comps_List);
1548 while Present (Comp_Elmt) loop
1549 Comp_Iface := Related_Type (Node (Comp_Elmt));
1551 if Comp_Iface = Iface
1552 or else Is_Ancestor (Iface, Comp_Iface)
1554 Append_Elmt (Node (Comp_Elmt), Components_List);
1555 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1559 Next_Elmt (Comp_Elmt);
1561 pragma Assert (Present (Comp_Elmt));
1564 Next_Elmt (Iface_Elmt);
1566 end Collect_Interfaces_Info;
1568 ----------------------------------
1569 -- Collect_Primitive_Operations --
1570 ----------------------------------
1572 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1573 B_Type : constant Entity_Id := Base_Type (T);
1574 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1575 B_Scope : Entity_Id := Scope (B_Type);
1579 Formal_Derived : Boolean := False;
1583 -- For tagged types, the primitive operations are collected as they
1584 -- are declared, and held in an explicit list which is simply returned.
1586 if Is_Tagged_Type (B_Type) then
1587 return Primitive_Operations (B_Type);
1589 -- An untagged generic type that is a derived type inherits the
1590 -- primitive operations of its parent type. Other formal types only
1591 -- have predefined operators, which are not explicitly represented.
1593 elsif Is_Generic_Type (B_Type) then
1594 if Nkind (B_Decl) = N_Formal_Type_Declaration
1595 and then Nkind (Formal_Type_Definition (B_Decl))
1596 = N_Formal_Derived_Type_Definition
1598 Formal_Derived := True;
1600 return New_Elmt_List;
1604 Op_List := New_Elmt_List;
1606 if B_Scope = Standard_Standard then
1607 if B_Type = Standard_String then
1608 Append_Elmt (Standard_Op_Concat, Op_List);
1610 elsif B_Type = Standard_Wide_String then
1611 Append_Elmt (Standard_Op_Concatw, Op_List);
1617 elsif (Is_Package_Or_Generic_Package (B_Scope)
1619 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1621 or else Is_Derived_Type (B_Type)
1623 -- The primitive operations appear after the base type, except
1624 -- if the derivation happens within the private part of B_Scope
1625 -- and the type is a private type, in which case both the type
1626 -- and some primitive operations may appear before the base
1627 -- type, and the list of candidates starts after the type.
1629 if In_Open_Scopes (B_Scope)
1630 and then Scope (T) = B_Scope
1631 and then In_Private_Part (B_Scope)
1633 Id := Next_Entity (T);
1635 Id := Next_Entity (B_Type);
1638 while Present (Id) loop
1640 -- Note that generic formal subprograms are not
1641 -- considered to be primitive operations and thus
1642 -- are never inherited.
1644 if Is_Overloadable (Id)
1645 and then Nkind (Parent (Parent (Id)))
1646 not in N_Formal_Subprogram_Declaration
1650 if Base_Type (Etype (Id)) = B_Type then
1653 Formal := First_Formal (Id);
1654 while Present (Formal) loop
1655 if Base_Type (Etype (Formal)) = B_Type then
1659 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1661 (Designated_Type (Etype (Formal))) = B_Type
1667 Next_Formal (Formal);
1671 -- For a formal derived type, the only primitives are the
1672 -- ones inherited from the parent type. Operations appearing
1673 -- in the package declaration are not primitive for it.
1676 and then (not Formal_Derived
1677 or else Present (Alias (Id)))
1679 Append_Elmt (Id, Op_List);
1685 -- For a type declared in System, some of its operations
1686 -- may appear in the target-specific extension to System.
1689 and then Chars (B_Scope) = Name_System
1690 and then Scope (B_Scope) = Standard_Standard
1691 and then Present_System_Aux
1693 B_Scope := System_Aux_Id;
1694 Id := First_Entity (System_Aux_Id);
1700 end Collect_Primitive_Operations;
1702 -----------------------------------
1703 -- Compile_Time_Constraint_Error --
1704 -----------------------------------
1706 function Compile_Time_Constraint_Error
1709 Ent : Entity_Id := Empty;
1710 Loc : Source_Ptr := No_Location;
1711 Warn : Boolean := False) return Node_Id
1713 Msgc : String (1 .. Msg'Length + 2);
1714 -- Copy of message, with room for possible ? and ! at end
1724 -- A static constraint error in an instance body is not a fatal error.
1725 -- we choose to inhibit the message altogether, because there is no
1726 -- obvious node (for now) on which to post it. On the other hand the
1727 -- offending node must be replaced with a constraint_error in any case.
1729 -- No messages are generated if we already posted an error on this node
1731 if not Error_Posted (N) then
1732 if Loc /= No_Location then
1738 Msgc (1 .. Msg'Length) := Msg;
1741 -- Message is a warning, even in Ada 95 case
1743 if Msg (Msg'Last) = '?' then
1746 -- In Ada 83, all messages are warnings. In the private part and
1747 -- the body of an instance, constraint_checks are only warnings.
1748 -- We also make this a warning if the Warn parameter is set.
1751 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1757 elsif In_Instance_Not_Visible then
1762 -- Otherwise we have a real error message (Ada 95 static case)
1763 -- and we make this an unconditional message. Note that in the
1764 -- warning case we do not make the message unconditional, it seems
1765 -- quite reasonable to delete messages like this (about exceptions
1766 -- that will be raised) in dead code.
1774 -- Should we generate a warning? The answer is not quite yes. The
1775 -- very annoying exception occurs in the case of a short circuit
1776 -- operator where the left operand is static and decisive. Climb
1777 -- parents to see if that is the case we have here. Conditional
1778 -- expressions with decisive conditions are a similar situation.
1786 -- And then with False as left operand
1788 if Nkind (P) = N_And_Then
1789 and then Compile_Time_Known_Value (Left_Opnd (P))
1790 and then Is_False (Expr_Value (Left_Opnd (P)))
1795 -- OR ELSE with True as left operand
1797 elsif Nkind (P) = N_Or_Else
1798 and then Compile_Time_Known_Value (Left_Opnd (P))
1799 and then Is_True (Expr_Value (Left_Opnd (P)))
1804 -- Conditional expression
1806 elsif Nkind (P) = N_Conditional_Expression then
1808 Cond : constant Node_Id := First (Expressions (P));
1809 Texp : constant Node_Id := Next (Cond);
1810 Fexp : constant Node_Id := Next (Texp);
1813 if Compile_Time_Known_Value (Cond) then
1815 -- Condition is True and we are in the right operand
1817 if Is_True (Expr_Value (Cond))
1818 and then OldP = Fexp
1823 -- Condition is False and we are in the left operand
1825 elsif Is_False (Expr_Value (Cond))
1826 and then OldP = Texp
1834 -- Special case for component association in aggregates, where
1835 -- we want to keep climbing up to the parent aggregate.
1837 elsif Nkind (P) = N_Component_Association
1838 and then Nkind (Parent (P)) = N_Aggregate
1842 -- Keep going if within subexpression
1845 exit when Nkind (P) not in N_Subexpr;
1850 if Present (Ent) then
1851 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1853 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1857 if Inside_Init_Proc then
1859 ("\?& will be raised for objects of this type",
1860 N, Standard_Constraint_Error, Eloc);
1863 ("\?& will be raised at run time",
1864 N, Standard_Constraint_Error, Eloc);
1869 ("\static expression fails Constraint_Check", Eloc);
1870 Set_Error_Posted (N);
1876 end Compile_Time_Constraint_Error;
1878 -----------------------
1879 -- Conditional_Delay --
1880 -----------------------
1882 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1884 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1885 Set_Has_Delayed_Freeze (New_Ent);
1887 end Conditional_Delay;
1889 -------------------------
1890 -- Copy_Parameter_List --
1891 -------------------------
1893 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1894 Loc : constant Source_Ptr := Sloc (Subp_Id);
1899 if No (First_Formal (Subp_Id)) then
1903 Formal := First_Formal (Subp_Id);
1904 while Present (Formal) loop
1906 (Make_Parameter_Specification (Loc,
1907 Defining_Identifier =>
1908 Make_Defining_Identifier (Sloc (Formal),
1909 Chars => Chars (Formal)),
1910 In_Present => In_Present (Parent (Formal)),
1911 Out_Present => Out_Present (Parent (Formal)),
1913 New_Reference_To (Etype (Formal), Loc),
1915 New_Copy_Tree (Expression (Parent (Formal)))),
1918 Next_Formal (Formal);
1923 end Copy_Parameter_List;
1925 --------------------
1926 -- Current_Entity --
1927 --------------------
1929 -- The currently visible definition for a given identifier is the
1930 -- one most chained at the start of the visibility chain, i.e. the
1931 -- one that is referenced by the Node_Id value of the name of the
1932 -- given identifier.
1934 function Current_Entity (N : Node_Id) return Entity_Id is
1936 return Get_Name_Entity_Id (Chars (N));
1939 -----------------------------
1940 -- Current_Entity_In_Scope --
1941 -----------------------------
1943 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1945 CS : constant Entity_Id := Current_Scope;
1947 Transient_Case : constant Boolean := Scope_Is_Transient;
1950 E := Get_Name_Entity_Id (Chars (N));
1952 and then Scope (E) /= CS
1953 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1959 end Current_Entity_In_Scope;
1965 function Current_Scope return Entity_Id is
1967 if Scope_Stack.Last = -1 then
1968 return Standard_Standard;
1971 C : constant Entity_Id :=
1972 Scope_Stack.Table (Scope_Stack.Last).Entity;
1977 return Standard_Standard;
1983 ------------------------
1984 -- Current_Subprogram --
1985 ------------------------
1987 function Current_Subprogram return Entity_Id is
1988 Scop : constant Entity_Id := Current_Scope;
1990 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1993 return Enclosing_Subprogram (Scop);
1995 end Current_Subprogram;
1997 ---------------------
1998 -- Defining_Entity --
1999 ---------------------
2001 function Defining_Entity (N : Node_Id) return Entity_Id is
2002 K : constant Node_Kind := Nkind (N);
2003 Err : Entity_Id := Empty;
2008 N_Subprogram_Declaration |
2009 N_Abstract_Subprogram_Declaration |
2011 N_Package_Declaration |
2012 N_Subprogram_Renaming_Declaration |
2013 N_Subprogram_Body_Stub |
2014 N_Generic_Subprogram_Declaration |
2015 N_Generic_Package_Declaration |
2016 N_Formal_Subprogram_Declaration
2018 return Defining_Entity (Specification (N));
2021 N_Component_Declaration |
2022 N_Defining_Program_Unit_Name |
2023 N_Discriminant_Specification |
2025 N_Entry_Declaration |
2026 N_Entry_Index_Specification |
2027 N_Exception_Declaration |
2028 N_Exception_Renaming_Declaration |
2029 N_Formal_Object_Declaration |
2030 N_Formal_Package_Declaration |
2031 N_Formal_Type_Declaration |
2032 N_Full_Type_Declaration |
2033 N_Implicit_Label_Declaration |
2034 N_Incomplete_Type_Declaration |
2035 N_Loop_Parameter_Specification |
2036 N_Number_Declaration |
2037 N_Object_Declaration |
2038 N_Object_Renaming_Declaration |
2039 N_Package_Body_Stub |
2040 N_Parameter_Specification |
2041 N_Private_Extension_Declaration |
2042 N_Private_Type_Declaration |
2044 N_Protected_Body_Stub |
2045 N_Protected_Type_Declaration |
2046 N_Single_Protected_Declaration |
2047 N_Single_Task_Declaration |
2048 N_Subtype_Declaration |
2051 N_Task_Type_Declaration
2053 return Defining_Identifier (N);
2056 return Defining_Entity (Proper_Body (N));
2059 N_Function_Instantiation |
2060 N_Function_Specification |
2061 N_Generic_Function_Renaming_Declaration |
2062 N_Generic_Package_Renaming_Declaration |
2063 N_Generic_Procedure_Renaming_Declaration |
2065 N_Package_Instantiation |
2066 N_Package_Renaming_Declaration |
2067 N_Package_Specification |
2068 N_Procedure_Instantiation |
2069 N_Procedure_Specification
2072 Nam : constant Node_Id := Defining_Unit_Name (N);
2075 if Nkind (Nam) in N_Entity then
2078 -- For Error, make up a name and attach to declaration
2079 -- so we can continue semantic analysis
2081 elsif Nam = Error then
2083 Make_Defining_Identifier (Sloc (N),
2084 Chars => New_Internal_Name ('T'));
2085 Set_Defining_Unit_Name (N, Err);
2088 -- If not an entity, get defining identifier
2091 return Defining_Identifier (Nam);
2095 when N_Block_Statement =>
2096 return Entity (Identifier (N));
2099 raise Program_Error;
2102 end Defining_Entity;
2104 --------------------------
2105 -- Denotes_Discriminant --
2106 --------------------------
2108 function Denotes_Discriminant
2110 Check_Concurrent : Boolean := False) return Boolean
2114 if not Is_Entity_Name (N)
2115 or else No (Entity (N))
2122 -- If we are checking for a protected type, the discriminant may have
2123 -- been rewritten as the corresponding discriminal of the original type
2124 -- or of the corresponding concurrent record, depending on whether we
2125 -- are in the spec or body of the protected type.
2127 return Ekind (E) = E_Discriminant
2130 and then Ekind (E) = E_In_Parameter
2131 and then Present (Discriminal_Link (E))
2133 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2135 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2137 end Denotes_Discriminant;
2139 ----------------------
2140 -- Denotes_Variable --
2141 ----------------------
2143 function Denotes_Variable (N : Node_Id) return Boolean is
2145 return Is_Variable (N) and then Paren_Count (N) = 0;
2146 end Denotes_Variable;
2148 -----------------------------
2149 -- Depends_On_Discriminant --
2150 -----------------------------
2152 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2157 Get_Index_Bounds (N, L, H);
2158 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2159 end Depends_On_Discriminant;
2161 -------------------------
2162 -- Designate_Same_Unit --
2163 -------------------------
2165 function Designate_Same_Unit
2167 Name2 : Node_Id) return Boolean
2169 K1 : constant Node_Kind := Nkind (Name1);
2170 K2 : constant Node_Kind := Nkind (Name2);
2172 function Prefix_Node (N : Node_Id) return Node_Id;
2173 -- Returns the parent unit name node of a defining program unit name
2174 -- or the prefix if N is a selected component or an expanded name.
2176 function Select_Node (N : Node_Id) return Node_Id;
2177 -- Returns the defining identifier node of a defining program unit
2178 -- name or the selector node if N is a selected component or an
2185 function Prefix_Node (N : Node_Id) return Node_Id is
2187 if Nkind (N) = N_Defining_Program_Unit_Name then
2199 function Select_Node (N : Node_Id) return Node_Id is
2201 if Nkind (N) = N_Defining_Program_Unit_Name then
2202 return Defining_Identifier (N);
2205 return Selector_Name (N);
2209 -- Start of processing for Designate_Next_Unit
2212 if (K1 = N_Identifier or else
2213 K1 = N_Defining_Identifier)
2215 (K2 = N_Identifier or else
2216 K2 = N_Defining_Identifier)
2218 return Chars (Name1) = Chars (Name2);
2221 (K1 = N_Expanded_Name or else
2222 K1 = N_Selected_Component or else
2223 K1 = N_Defining_Program_Unit_Name)
2225 (K2 = N_Expanded_Name or else
2226 K2 = N_Selected_Component or else
2227 K2 = N_Defining_Program_Unit_Name)
2230 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2232 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2237 end Designate_Same_Unit;
2239 ----------------------------
2240 -- Enclosing_Generic_Body --
2241 ----------------------------
2243 function Enclosing_Generic_Body
2244 (N : Node_Id) return Node_Id
2252 while Present (P) loop
2253 if Nkind (P) = N_Package_Body
2254 or else Nkind (P) = N_Subprogram_Body
2256 Spec := Corresponding_Spec (P);
2258 if Present (Spec) then
2259 Decl := Unit_Declaration_Node (Spec);
2261 if Nkind (Decl) = N_Generic_Package_Declaration
2262 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2273 end Enclosing_Generic_Body;
2275 ----------------------------
2276 -- Enclosing_Generic_Unit --
2277 ----------------------------
2279 function Enclosing_Generic_Unit
2280 (N : Node_Id) return Node_Id
2288 while Present (P) loop
2289 if Nkind (P) = N_Generic_Package_Declaration
2290 or else Nkind (P) = N_Generic_Subprogram_Declaration
2294 elsif Nkind (P) = N_Package_Body
2295 or else Nkind (P) = N_Subprogram_Body
2297 Spec := Corresponding_Spec (P);
2299 if Present (Spec) then
2300 Decl := Unit_Declaration_Node (Spec);
2302 if Nkind (Decl) = N_Generic_Package_Declaration
2303 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2314 end Enclosing_Generic_Unit;
2316 -------------------------------
2317 -- Enclosing_Lib_Unit_Entity --
2318 -------------------------------
2320 function Enclosing_Lib_Unit_Entity return Entity_Id is
2321 Unit_Entity : Entity_Id;
2324 -- Look for enclosing library unit entity by following scope links.
2325 -- Equivalent to, but faster than indexing through the scope stack.
2327 Unit_Entity := Current_Scope;
2328 while (Present (Scope (Unit_Entity))
2329 and then Scope (Unit_Entity) /= Standard_Standard)
2330 and not Is_Child_Unit (Unit_Entity)
2332 Unit_Entity := Scope (Unit_Entity);
2336 end Enclosing_Lib_Unit_Entity;
2338 -----------------------------
2339 -- Enclosing_Lib_Unit_Node --
2340 -----------------------------
2342 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2343 Current_Node : Node_Id;
2347 while Present (Current_Node)
2348 and then Nkind (Current_Node) /= N_Compilation_Unit
2350 Current_Node := Parent (Current_Node);
2353 if Nkind (Current_Node) /= N_Compilation_Unit then
2357 return Current_Node;
2358 end Enclosing_Lib_Unit_Node;
2360 --------------------------
2361 -- Enclosing_Subprogram --
2362 --------------------------
2364 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2365 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2368 if Dynamic_Scope = Standard_Standard then
2371 elsif Dynamic_Scope = Empty then
2374 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2375 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2377 elsif Ekind (Dynamic_Scope) = E_Block
2378 or else Ekind (Dynamic_Scope) = E_Return_Statement
2380 return Enclosing_Subprogram (Dynamic_Scope);
2382 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2383 return Get_Task_Body_Procedure (Dynamic_Scope);
2385 elsif Convention (Dynamic_Scope) = Convention_Protected then
2386 return Protected_Body_Subprogram (Dynamic_Scope);
2389 return Dynamic_Scope;
2391 end Enclosing_Subprogram;
2393 ------------------------
2394 -- Ensure_Freeze_Node --
2395 ------------------------
2397 procedure Ensure_Freeze_Node (E : Entity_Id) is
2401 if No (Freeze_Node (E)) then
2402 FN := Make_Freeze_Entity (Sloc (E));
2403 Set_Has_Delayed_Freeze (E);
2404 Set_Freeze_Node (E, FN);
2405 Set_Access_Types_To_Process (FN, No_Elist);
2406 Set_TSS_Elist (FN, No_Elist);
2409 end Ensure_Freeze_Node;
2415 procedure Enter_Name (Def_Id : Entity_Id) is
2416 C : constant Entity_Id := Current_Entity (Def_Id);
2417 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2418 S : constant Entity_Id := Current_Scope;
2421 Generate_Definition (Def_Id);
2423 -- Add new name to current scope declarations. Check for duplicate
2424 -- declaration, which may or may not be a genuine error.
2428 -- Case of previous entity entered because of a missing declaration
2429 -- or else a bad subtype indication. Best is to use the new entity,
2430 -- and make the previous one invisible.
2432 if Etype (E) = Any_Type then
2433 Set_Is_Immediately_Visible (E, False);
2435 -- Case of renaming declaration constructed for package instances.
2436 -- if there is an explicit declaration with the same identifier,
2437 -- the renaming is not immediately visible any longer, but remains
2438 -- visible through selected component notation.
2440 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2441 and then not Comes_From_Source (E)
2443 Set_Is_Immediately_Visible (E, False);
2445 -- The new entity may be the package renaming, which has the same
2446 -- same name as a generic formal which has been seen already.
2448 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2449 and then not Comes_From_Source (Def_Id)
2451 Set_Is_Immediately_Visible (E, False);
2453 -- For a fat pointer corresponding to a remote access to subprogram,
2454 -- we use the same identifier as the RAS type, so that the proper
2455 -- name appears in the stub. This type is only retrieved through
2456 -- the RAS type and never by visibility, and is not added to the
2457 -- visibility list (see below).
2459 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2460 and then Present (Corresponding_Remote_Type (Def_Id))
2464 -- A controller component for a type extension overrides the
2465 -- inherited component.
2467 elsif Chars (E) = Name_uController then
2470 -- Case of an implicit operation or derived literal. The new entity
2471 -- hides the implicit one, which is removed from all visibility,
2472 -- i.e. the entity list of its scope, and homonym chain of its name.
2474 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2475 or else Is_Internal (E)
2479 Prev_Vis : Entity_Id;
2480 Decl : constant Node_Id := Parent (E);
2483 -- If E is an implicit declaration, it cannot be the first
2484 -- entity in the scope.
2486 Prev := First_Entity (Current_Scope);
2487 while Present (Prev)
2488 and then Next_Entity (Prev) /= E
2495 -- If E is not on the entity chain of the current scope,
2496 -- it is an implicit declaration in the generic formal
2497 -- part of a generic subprogram. When analyzing the body,
2498 -- the generic formals are visible but not on the entity
2499 -- chain of the subprogram. The new entity will become
2500 -- the visible one in the body.
2503 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2507 Set_Next_Entity (Prev, Next_Entity (E));
2509 if No (Next_Entity (Prev)) then
2510 Set_Last_Entity (Current_Scope, Prev);
2513 if E = Current_Entity (E) then
2517 Prev_Vis := Current_Entity (E);
2518 while Homonym (Prev_Vis) /= E loop
2519 Prev_Vis := Homonym (Prev_Vis);
2523 if Present (Prev_Vis) then
2525 -- Skip E in the visibility chain
2527 Set_Homonym (Prev_Vis, Homonym (E));
2530 Set_Name_Entity_Id (Chars (E), Homonym (E));
2535 -- This section of code could use a comment ???
2537 elsif Present (Etype (E))
2538 and then Is_Concurrent_Type (Etype (E))
2543 -- If the homograph is a protected component renaming, it should not
2544 -- be hiding the current entity. Such renamings are treated as weak
2547 elsif Is_Prival (E) then
2548 Set_Is_Immediately_Visible (E, False);
2550 -- In this case the current entity is a protected component renaming.
2551 -- Perform minimal decoration by setting the scope and return since
2552 -- the prival should not be hiding other visible entities.
2554 elsif Is_Prival (Def_Id) then
2555 Set_Scope (Def_Id, Current_Scope);
2558 -- Analogous to privals, the discriminal generated for an entry
2559 -- index parameter acts as a weak declaration. Perform minimal
2560 -- decoration to avoid bogus errors.
2562 elsif Is_Discriminal (Def_Id)
2563 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2565 Set_Scope (Def_Id, Current_Scope);
2568 -- In the body or private part of an instance, a type extension
2569 -- may introduce a component with the same name as that of an
2570 -- actual. The legality rule is not enforced, but the semantics
2571 -- of the full type with two components of the same name are not
2572 -- clear at this point ???
2574 elsif In_Instance_Not_Visible then
2577 -- When compiling a package body, some child units may have become
2578 -- visible. They cannot conflict with local entities that hide them.
2580 elsif Is_Child_Unit (E)
2581 and then In_Open_Scopes (Scope (E))
2582 and then not Is_Immediately_Visible (E)
2586 -- Conversely, with front-end inlining we may compile the parent
2587 -- body first, and a child unit subsequently. The context is now
2588 -- the parent spec, and body entities are not visible.
2590 elsif Is_Child_Unit (Def_Id)
2591 and then Is_Package_Body_Entity (E)
2592 and then not In_Package_Body (Current_Scope)
2596 -- Case of genuine duplicate declaration
2599 Error_Msg_Sloc := Sloc (E);
2601 -- If the previous declaration is an incomplete type declaration
2602 -- this may be an attempt to complete it with a private type.
2603 -- The following avoids confusing cascaded errors.
2605 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2606 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2609 ("incomplete type cannot be completed with a private " &
2610 "declaration", Parent (Def_Id));
2611 Set_Is_Immediately_Visible (E, False);
2612 Set_Full_View (E, Def_Id);
2614 -- An inherited component of a record conflicts with a new
2615 -- discriminant. The discriminant is inserted first in the scope,
2616 -- but the error should be posted on it, not on the component.
2618 elsif Ekind (E) = E_Discriminant
2619 and then Present (Scope (Def_Id))
2620 and then Scope (Def_Id) /= Current_Scope
2622 Error_Msg_Sloc := Sloc (Def_Id);
2623 Error_Msg_N ("& conflicts with declaration#", E);
2626 -- If the name of the unit appears in its own context clause,
2627 -- a dummy package with the name has already been created, and
2628 -- the error emitted. Try to continue quietly.
2630 elsif Error_Posted (E)
2631 and then Sloc (E) = No_Location
2632 and then Nkind (Parent (E)) = N_Package_Specification
2633 and then Current_Scope = Standard_Standard
2635 Set_Scope (Def_Id, Current_Scope);
2639 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2641 -- Avoid cascaded messages with duplicate components in
2644 if Ekind (E) = E_Component
2645 or else Ekind (E) = E_Discriminant
2651 if Nkind (Parent (Parent (Def_Id))) =
2652 N_Generic_Subprogram_Declaration
2654 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2656 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2659 -- If entity is in standard, then we are in trouble, because
2660 -- it means that we have a library package with a duplicated
2661 -- name. That's hard to recover from, so abort!
2663 if S = Standard_Standard then
2664 raise Unrecoverable_Error;
2666 -- Otherwise we continue with the declaration. Having two
2667 -- identical declarations should not cause us too much trouble!
2675 -- If we fall through, declaration is OK , or OK enough to continue
2677 -- If Def_Id is a discriminant or a record component we are in the
2678 -- midst of inheriting components in a derived record definition.
2679 -- Preserve their Ekind and Etype.
2681 if Ekind (Def_Id) = E_Discriminant
2682 or else Ekind (Def_Id) = E_Component
2686 -- If a type is already set, leave it alone (happens whey a type
2687 -- declaration is reanalyzed following a call to the optimizer)
2689 elsif Present (Etype (Def_Id)) then
2692 -- Otherwise, the kind E_Void insures that premature uses of the entity
2693 -- will be detected. Any_Type insures that no cascaded errors will occur
2696 Set_Ekind (Def_Id, E_Void);
2697 Set_Etype (Def_Id, Any_Type);
2700 -- Inherited discriminants and components in derived record types are
2701 -- immediately visible. Itypes are not.
2703 if Ekind (Def_Id) = E_Discriminant
2704 or else Ekind (Def_Id) = E_Component
2705 or else (No (Corresponding_Remote_Type (Def_Id))
2706 and then not Is_Itype (Def_Id))
2708 Set_Is_Immediately_Visible (Def_Id);
2709 Set_Current_Entity (Def_Id);
2712 Set_Homonym (Def_Id, C);
2713 Append_Entity (Def_Id, S);
2714 Set_Public_Status (Def_Id);
2716 -- Warn if new entity hides an old one
2718 if Warn_On_Hiding and then Present (C)
2720 -- Don't warn for record components since they always have a well
2721 -- defined scope which does not confuse other uses. Note that in
2722 -- some cases, Ekind has not been set yet.
2724 and then Ekind (C) /= E_Component
2725 and then Ekind (C) /= E_Discriminant
2726 and then Nkind (Parent (C)) /= N_Component_Declaration
2727 and then Ekind (Def_Id) /= E_Component
2728 and then Ekind (Def_Id) /= E_Discriminant
2729 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2731 -- Don't warn for one character variables. It is too common to use
2732 -- such variables as locals and will just cause too many false hits.
2734 and then Length_Of_Name (Chars (C)) /= 1
2736 -- Don't warn for non-source entities
2738 and then Comes_From_Source (C)
2739 and then Comes_From_Source (Def_Id)
2741 -- Don't warn unless entity in question is in extended main source
2743 and then In_Extended_Main_Source_Unit (Def_Id)
2745 -- Finally, the hidden entity must be either immediately visible
2746 -- or use visible (from a used package)
2749 (Is_Immediately_Visible (C)
2751 Is_Potentially_Use_Visible (C))
2753 Error_Msg_Sloc := Sloc (C);
2754 Error_Msg_N ("declaration hides &#?", Def_Id);
2758 --------------------------
2759 -- Explain_Limited_Type --
2760 --------------------------
2762 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2766 -- For array, component type must be limited
2768 if Is_Array_Type (T) then
2769 Error_Msg_Node_2 := T;
2771 ("\component type& of type& is limited", N, Component_Type (T));
2772 Explain_Limited_Type (Component_Type (T), N);
2774 elsif Is_Record_Type (T) then
2776 -- No need for extra messages if explicit limited record
2778 if Is_Limited_Record (Base_Type (T)) then
2782 -- Otherwise find a limited component. Check only components that
2783 -- come from source, or inherited components that appear in the
2784 -- source of the ancestor.
2786 C := First_Component (T);
2787 while Present (C) loop
2788 if Is_Limited_Type (Etype (C))
2790 (Comes_From_Source (C)
2792 (Present (Original_Record_Component (C))
2794 Comes_From_Source (Original_Record_Component (C))))
2796 Error_Msg_Node_2 := T;
2797 Error_Msg_NE ("\component& of type& has limited type", N, C);
2798 Explain_Limited_Type (Etype (C), N);
2805 -- The type may be declared explicitly limited, even if no component
2806 -- of it is limited, in which case we fall out of the loop.
2809 end Explain_Limited_Type;
2815 procedure Find_Actual
2817 Formal : out Entity_Id;
2820 Parnt : constant Node_Id := Parent (N);
2824 if (Nkind (Parnt) = N_Indexed_Component
2826 Nkind (Parnt) = N_Selected_Component)
2827 and then N = Prefix (Parnt)
2829 Find_Actual (Parnt, Formal, Call);
2832 elsif Nkind (Parnt) = N_Parameter_Association
2833 and then N = Explicit_Actual_Parameter (Parnt)
2835 Call := Parent (Parnt);
2837 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2846 -- If we have a call to a subprogram look for the parameter. Note that
2847 -- we exclude overloaded calls, since we don't know enough to be sure
2848 -- of giving the right answer in this case.
2850 if Is_Entity_Name (Name (Call))
2851 and then Present (Entity (Name (Call)))
2852 and then Is_Overloadable (Entity (Name (Call)))
2853 and then not Is_Overloaded (Name (Call))
2855 -- Fall here if we are definitely a parameter
2857 Actual := First_Actual (Call);
2858 Formal := First_Formal (Entity (Name (Call)));
2859 while Present (Formal) and then Present (Actual) loop
2863 Actual := Next_Actual (Actual);
2864 Formal := Next_Formal (Formal);
2869 -- Fall through here if we did not find matching actual
2875 -------------------------------------
2876 -- Find_Corresponding_Discriminant --
2877 -------------------------------------
2879 function Find_Corresponding_Discriminant
2881 Typ : Entity_Id) return Entity_Id
2883 Par_Disc : Entity_Id;
2884 Old_Disc : Entity_Id;
2885 New_Disc : Entity_Id;
2888 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2890 -- The original type may currently be private, and the discriminant
2891 -- only appear on its full view.
2893 if Is_Private_Type (Scope (Par_Disc))
2894 and then not Has_Discriminants (Scope (Par_Disc))
2895 and then Present (Full_View (Scope (Par_Disc)))
2897 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2899 Old_Disc := First_Discriminant (Scope (Par_Disc));
2902 if Is_Class_Wide_Type (Typ) then
2903 New_Disc := First_Discriminant (Root_Type (Typ));
2905 New_Disc := First_Discriminant (Typ);
2908 while Present (Old_Disc) and then Present (New_Disc) loop
2909 if Old_Disc = Par_Disc then
2912 Next_Discriminant (Old_Disc);
2913 Next_Discriminant (New_Disc);
2917 -- Should always find it
2919 raise Program_Error;
2920 end Find_Corresponding_Discriminant;
2922 --------------------------
2923 -- Find_Overlaid_Entity --
2924 --------------------------
2926 procedure Find_Overlaid_Entity
2928 Ent : out Entity_Id;
2934 -- We are looking for one of the two following forms:
2936 -- for X'Address use Y'Address
2940 -- Const : constant Address := expr;
2942 -- for X'Address use Const;
2944 -- In the second case, the expr is either Y'Address, or recursively a
2945 -- constant that eventually references Y'Address.
2950 if Nkind (N) = N_Attribute_Definition_Clause
2951 and then Chars (N) = Name_Address
2953 Expr := Expression (N);
2955 -- This loop checks the form of the expression for Y'Address,
2956 -- using recursion to deal with intermediate constants.
2959 -- Check for Y'Address
2961 if Nkind (Expr) = N_Attribute_Reference
2962 and then Attribute_Name (Expr) = Name_Address
2964 Expr := Prefix (Expr);
2967 -- Check for Const where Const is a constant entity
2969 elsif Is_Entity_Name (Expr)
2970 and then Ekind (Entity (Expr)) = E_Constant
2972 Expr := Constant_Value (Entity (Expr));
2974 -- Anything else does not need checking
2981 -- This loop checks the form of the prefix for an entity,
2982 -- using recursion to deal with intermediate components.
2985 -- Check for Y where Y is an entity
2987 if Is_Entity_Name (Expr) then
2988 Ent := Entity (Expr);
2991 -- Check for components
2994 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
2996 Expr := Prefix (Expr);
2999 -- Anything else does not need checking
3006 end Find_Overlaid_Entity;
3008 -------------------------
3009 -- Find_Parameter_Type --
3010 -------------------------
3012 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3014 if Nkind (Param) /= N_Parameter_Specification then
3017 -- For an access parameter, obtain the type from the formal entity
3018 -- itself, because access to subprogram nodes do not carry a type.
3019 -- Shouldn't we always use the formal entity ???
3021 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3022 return Etype (Defining_Identifier (Param));
3025 return Etype (Parameter_Type (Param));
3027 end Find_Parameter_Type;
3029 -----------------------------
3030 -- Find_Static_Alternative --
3031 -----------------------------
3033 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3034 Expr : constant Node_Id := Expression (N);
3035 Val : constant Uint := Expr_Value (Expr);
3040 Alt := First (Alternatives (N));
3043 if Nkind (Alt) /= N_Pragma then
3044 Choice := First (Discrete_Choices (Alt));
3045 while Present (Choice) loop
3047 -- Others choice, always matches
3049 if Nkind (Choice) = N_Others_Choice then
3052 -- Range, check if value is in the range
3054 elsif Nkind (Choice) = N_Range then
3056 Val >= Expr_Value (Low_Bound (Choice))
3058 Val <= Expr_Value (High_Bound (Choice));
3060 -- Choice is a subtype name. Note that we know it must
3061 -- be a static subtype, since otherwise it would have
3062 -- been diagnosed as illegal.
3064 elsif Is_Entity_Name (Choice)
3065 and then Is_Type (Entity (Choice))
3067 exit Search when Is_In_Range (Expr, Etype (Choice),
3068 Assume_Valid => False);
3070 -- Choice is a subtype indication
3072 elsif Nkind (Choice) = N_Subtype_Indication then
3074 C : constant Node_Id := Constraint (Choice);
3075 R : constant Node_Id := Range_Expression (C);
3079 Val >= Expr_Value (Low_Bound (R))
3081 Val <= Expr_Value (High_Bound (R));
3084 -- Choice is a simple expression
3087 exit Search when Val = Expr_Value (Choice);
3095 pragma Assert (Present (Alt));
3098 -- The above loop *must* terminate by finding a match, since
3099 -- we know the case statement is valid, and the value of the
3100 -- expression is known at compile time. When we fall out of
3101 -- the loop, Alt points to the alternative that we know will
3102 -- be selected at run time.
3105 end Find_Static_Alternative;
3111 function First_Actual (Node : Node_Id) return Node_Id is
3115 if No (Parameter_Associations (Node)) then
3119 N := First (Parameter_Associations (Node));
3121 if Nkind (N) = N_Parameter_Association then
3122 return First_Named_Actual (Node);
3128 -------------------------
3129 -- Full_Qualified_Name --
3130 -------------------------
3132 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3134 pragma Warnings (Off, Res);
3136 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3137 -- Compute recursively the qualified name without NUL at the end
3139 ----------------------------------
3140 -- Internal_Full_Qualified_Name --
3141 ----------------------------------
3143 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3144 Ent : Entity_Id := E;
3145 Parent_Name : String_Id := No_String;
3148 -- Deals properly with child units
3150 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3151 Ent := Defining_Identifier (Ent);
3154 -- Compute qualification recursively (only "Standard" has no scope)
3156 if Present (Scope (Scope (Ent))) then
3157 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3160 -- Every entity should have a name except some expanded blocks
3161 -- don't bother about those.
3163 if Chars (Ent) = No_Name then
3167 -- Add a period between Name and qualification
3169 if Parent_Name /= No_String then
3170 Start_String (Parent_Name);
3171 Store_String_Char (Get_Char_Code ('.'));
3177 -- Generates the entity name in upper case
3179 Get_Decoded_Name_String (Chars (Ent));
3181 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3183 end Internal_Full_Qualified_Name;
3185 -- Start of processing for Full_Qualified_Name
3188 Res := Internal_Full_Qualified_Name (E);
3189 Store_String_Char (Get_Char_Code (ASCII.NUL));
3191 end Full_Qualified_Name;
3193 -----------------------
3194 -- Gather_Components --
3195 -----------------------
3197 procedure Gather_Components
3199 Comp_List : Node_Id;
3200 Governed_By : List_Id;
3202 Report_Errors : out Boolean)
3206 Discrete_Choice : Node_Id;
3207 Comp_Item : Node_Id;
3209 Discrim : Entity_Id;
3210 Discrim_Name : Node_Id;
3211 Discrim_Value : Node_Id;
3214 Report_Errors := False;
3216 if No (Comp_List) or else Null_Present (Comp_List) then
3219 elsif Present (Component_Items (Comp_List)) then
3220 Comp_Item := First (Component_Items (Comp_List));
3226 while Present (Comp_Item) loop
3228 -- Skip the tag of a tagged record, the interface tags, as well
3229 -- as all items that are not user components (anonymous types,
3230 -- rep clauses, Parent field, controller field).
3232 if Nkind (Comp_Item) = N_Component_Declaration then
3234 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3236 if not Is_Tag (Comp)
3237 and then Chars (Comp) /= Name_uParent
3238 and then Chars (Comp) /= Name_uController
3240 Append_Elmt (Comp, Into);
3248 if No (Variant_Part (Comp_List)) then
3251 Discrim_Name := Name (Variant_Part (Comp_List));
3252 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3255 -- Look for the discriminant that governs this variant part.
3256 -- The discriminant *must* be in the Governed_By List
3258 Assoc := First (Governed_By);
3259 Find_Constraint : loop
3260 Discrim := First (Choices (Assoc));
3261 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3262 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3264 Chars (Corresponding_Discriminant (Entity (Discrim)))
3265 = Chars (Discrim_Name))
3266 or else Chars (Original_Record_Component (Entity (Discrim)))
3267 = Chars (Discrim_Name);
3269 if No (Next (Assoc)) then
3270 if not Is_Constrained (Typ)
3271 and then Is_Derived_Type (Typ)
3272 and then Present (Stored_Constraint (Typ))
3274 -- If the type is a tagged type with inherited discriminants,
3275 -- use the stored constraint on the parent in order to find
3276 -- the values of discriminants that are otherwise hidden by an
3277 -- explicit constraint. Renamed discriminants are handled in
3280 -- If several parent discriminants are renamed by a single
3281 -- discriminant of the derived type, the call to obtain the
3282 -- Corresponding_Discriminant field only retrieves the last
3283 -- of them. We recover the constraint on the others from the
3284 -- Stored_Constraint as well.
3291 D := First_Discriminant (Etype (Typ));
3292 C := First_Elmt (Stored_Constraint (Typ));
3293 while Present (D) and then Present (C) loop
3294 if Chars (Discrim_Name) = Chars (D) then
3295 if Is_Entity_Name (Node (C))
3296 and then Entity (Node (C)) = Entity (Discrim)
3298 -- D is renamed by Discrim, whose value is given in
3305 Make_Component_Association (Sloc (Typ),
3307 (New_Occurrence_Of (D, Sloc (Typ))),
3308 Duplicate_Subexpr_No_Checks (Node (C)));
3310 exit Find_Constraint;
3313 Next_Discriminant (D);
3320 if No (Next (Assoc)) then
3321 Error_Msg_NE (" missing value for discriminant&",
3322 First (Governed_By), Discrim_Name);
3323 Report_Errors := True;
3328 end loop Find_Constraint;
3330 Discrim_Value := Expression (Assoc);
3332 if not Is_OK_Static_Expression (Discrim_Value) then
3334 ("value for discriminant & must be static!",
3335 Discrim_Value, Discrim);
3336 Why_Not_Static (Discrim_Value);
3337 Report_Errors := True;
3341 Search_For_Discriminant_Value : declare
3347 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3350 Find_Discrete_Value : while Present (Variant) loop
3351 Discrete_Choice := First (Discrete_Choices (Variant));
3352 while Present (Discrete_Choice) loop
3354 exit Find_Discrete_Value when
3355 Nkind (Discrete_Choice) = N_Others_Choice;
3357 Get_Index_Bounds (Discrete_Choice, Low, High);
3359 UI_Low := Expr_Value (Low);
3360 UI_High := Expr_Value (High);
3362 exit Find_Discrete_Value when
3363 UI_Low <= UI_Discrim_Value
3365 UI_High >= UI_Discrim_Value;
3367 Next (Discrete_Choice);
3370 Next_Non_Pragma (Variant);
3371 end loop Find_Discrete_Value;
3372 end Search_For_Discriminant_Value;
3374 if No (Variant) then
3376 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3377 Report_Errors := True;
3381 -- If we have found the corresponding choice, recursively add its
3382 -- components to the Into list.
3384 Gather_Components (Empty,
3385 Component_List (Variant), Governed_By, Into, Report_Errors);
3386 end Gather_Components;
3388 ------------------------
3389 -- Get_Actual_Subtype --
3390 ------------------------
3392 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3393 Typ : constant Entity_Id := Etype (N);
3394 Utyp : Entity_Id := Underlying_Type (Typ);
3403 -- If what we have is an identifier that references a subprogram
3404 -- formal, or a variable or constant object, then we get the actual
3405 -- subtype from the referenced entity if one has been built.
3407 if Nkind (N) = N_Identifier
3409 (Is_Formal (Entity (N))
3410 or else Ekind (Entity (N)) = E_Constant
3411 or else Ekind (Entity (N)) = E_Variable)
3412 and then Present (Actual_Subtype (Entity (N)))
3414 return Actual_Subtype (Entity (N));
3416 -- Actual subtype of unchecked union is always itself. We never need
3417 -- the "real" actual subtype. If we did, we couldn't get it anyway
3418 -- because the discriminant is not available. The restrictions on
3419 -- Unchecked_Union are designed to make sure that this is OK.
3421 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3424 -- Here for the unconstrained case, we must find actual subtype
3425 -- No actual subtype is available, so we must build it on the fly.
3427 -- Checking the type, not the underlying type, for constrainedness
3428 -- seems to be necessary. Maybe all the tests should be on the type???
3430 elsif (not Is_Constrained (Typ))
3431 and then (Is_Array_Type (Utyp)
3432 or else (Is_Record_Type (Utyp)
3433 and then Has_Discriminants (Utyp)))
3434 and then not Has_Unknown_Discriminants (Utyp)
3435 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3437 -- Nothing to do if in spec expression (why not???)
3439 if In_Spec_Expression then
3442 elsif Is_Private_Type (Typ)
3443 and then not Has_Discriminants (Typ)
3445 -- If the type has no discriminants, there is no subtype to
3446 -- build, even if the underlying type is discriminated.
3450 -- Else build the actual subtype
3453 Decl := Build_Actual_Subtype (Typ, N);
3454 Atyp := Defining_Identifier (Decl);
3456 -- If Build_Actual_Subtype generated a new declaration then use it
3460 -- The actual subtype is an Itype, so analyze the declaration,
3461 -- but do not attach it to the tree, to get the type defined.
3463 Set_Parent (Decl, N);
3464 Set_Is_Itype (Atyp);
3465 Analyze (Decl, Suppress => All_Checks);
3466 Set_Associated_Node_For_Itype (Atyp, N);
3467 Set_Has_Delayed_Freeze (Atyp, False);
3469 -- We need to freeze the actual subtype immediately. This is
3470 -- needed, because otherwise this Itype will not get frozen
3471 -- at all, and it is always safe to freeze on creation because
3472 -- any associated types must be frozen at this point.
3474 Freeze_Itype (Atyp, N);
3477 -- Otherwise we did not build a declaration, so return original
3484 -- For all remaining cases, the actual subtype is the same as
3485 -- the nominal type.
3490 end Get_Actual_Subtype;
3492 -------------------------------------
3493 -- Get_Actual_Subtype_If_Available --
3494 -------------------------------------
3496 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3497 Typ : constant Entity_Id := Etype (N);
3500 -- If what we have is an identifier that references a subprogram
3501 -- formal, or a variable or constant object, then we get the actual
3502 -- subtype from the referenced entity if one has been built.
3504 if Nkind (N) = N_Identifier
3506 (Is_Formal (Entity (N))
3507 or else Ekind (Entity (N)) = E_Constant
3508 or else Ekind (Entity (N)) = E_Variable)
3509 and then Present (Actual_Subtype (Entity (N)))
3511 return Actual_Subtype (Entity (N));
3513 -- Otherwise the Etype of N is returned unchanged
3518 end Get_Actual_Subtype_If_Available;
3520 -------------------------------
3521 -- Get_Default_External_Name --
3522 -------------------------------
3524 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3526 Get_Decoded_Name_String (Chars (E));
3528 if Opt.External_Name_Imp_Casing = Uppercase then
3529 Set_Casing (All_Upper_Case);
3531 Set_Casing (All_Lower_Case);
3535 Make_String_Literal (Sloc (E),
3536 Strval => String_From_Name_Buffer);
3537 end Get_Default_External_Name;
3539 ---------------------------
3540 -- Get_Enum_Lit_From_Pos --
3541 ---------------------------
3543 function Get_Enum_Lit_From_Pos
3546 Loc : Source_Ptr) return Node_Id
3551 -- In the case where the literal is of type Character, Wide_Character
3552 -- or Wide_Wide_Character or of a type derived from them, there needs
3553 -- to be some special handling since there is no explicit chain of
3554 -- literals to search. Instead, an N_Character_Literal node is created
3555 -- with the appropriate Char_Code and Chars fields.
3557 if Is_Standard_Character_Type (T) then
3558 Set_Character_Literal_Name (UI_To_CC (Pos));
3560 Make_Character_Literal (Loc,
3562 Char_Literal_Value => Pos);
3564 -- For all other cases, we have a complete table of literals, and
3565 -- we simply iterate through the chain of literal until the one
3566 -- with the desired position value is found.
3570 Lit := First_Literal (Base_Type (T));
3571 for J in 1 .. UI_To_Int (Pos) loop
3575 return New_Occurrence_Of (Lit, Loc);
3577 end Get_Enum_Lit_From_Pos;
3579 ------------------------
3580 -- Get_Generic_Entity --
3581 ------------------------
3583 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3584 Ent : constant Entity_Id := Entity (Name (N));
3586 if Present (Renamed_Object (Ent)) then
3587 return Renamed_Object (Ent);
3591 end Get_Generic_Entity;
3593 ----------------------
3594 -- Get_Index_Bounds --
3595 ----------------------
3597 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3598 Kind : constant Node_Kind := Nkind (N);
3602 if Kind = N_Range then
3604 H := High_Bound (N);
3606 elsif Kind = N_Subtype_Indication then
3607 R := Range_Expression (Constraint (N));
3615 L := Low_Bound (Range_Expression (Constraint (N)));
3616 H := High_Bound (Range_Expression (Constraint (N)));
3619 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3620 if Error_Posted (Scalar_Range (Entity (N))) then
3624 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3625 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3628 L := Low_Bound (Scalar_Range (Entity (N)));
3629 H := High_Bound (Scalar_Range (Entity (N)));
3633 -- N is an expression, indicating a range with one value
3638 end Get_Index_Bounds;
3640 ----------------------------------
3641 -- Get_Library_Unit_Name_string --
3642 ----------------------------------
3644 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3645 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3648 Get_Unit_Name_String (Unit_Name_Id);
3650 -- Remove seven last character (" (spec)" or " (body)")
3652 Name_Len := Name_Len - 7;
3653 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3654 end Get_Library_Unit_Name_String;
3656 ------------------------
3657 -- Get_Name_Entity_Id --
3658 ------------------------
3660 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3662 return Entity_Id (Get_Name_Table_Info (Id));
3663 end Get_Name_Entity_Id;
3669 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3671 return Get_Pragma_Id (Pragma_Name (N));
3674 ---------------------------
3675 -- Get_Referenced_Object --
3676 ---------------------------
3678 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3683 while Is_Entity_Name (R)
3684 and then Present (Renamed_Object (Entity (R)))
3686 R := Renamed_Object (Entity (R));
3690 end Get_Referenced_Object;
3692 ------------------------
3693 -- Get_Renamed_Entity --
3694 ------------------------
3696 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3701 while Present (Renamed_Entity (R)) loop
3702 R := Renamed_Entity (R);
3706 end Get_Renamed_Entity;
3708 -------------------------
3709 -- Get_Subprogram_Body --
3710 -------------------------
3712 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3716 Decl := Unit_Declaration_Node (E);
3718 if Nkind (Decl) = N_Subprogram_Body then
3721 -- The below comment is bad, because it is possible for
3722 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3724 else -- Nkind (Decl) = N_Subprogram_Declaration
3726 if Present (Corresponding_Body (Decl)) then
3727 return Unit_Declaration_Node (Corresponding_Body (Decl));
3729 -- Imported subprogram case
3735 end Get_Subprogram_Body;
3737 ---------------------------
3738 -- Get_Subprogram_Entity --
3739 ---------------------------
3741 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3746 if Nkind (Nod) = N_Accept_Statement then
3747 Nam := Entry_Direct_Name (Nod);
3749 -- For an entry call, the prefix of the call is a selected component.
3750 -- Need additional code for internal calls ???
3752 elsif Nkind (Nod) = N_Entry_Call_Statement then
3753 if Nkind (Name (Nod)) = N_Selected_Component then
3754 Nam := Entity (Selector_Name (Name (Nod)));
3763 if Nkind (Nam) = N_Explicit_Dereference then
3764 Proc := Etype (Prefix (Nam));
3765 elsif Is_Entity_Name (Nam) then
3766 Proc := Entity (Nam);
3771 if Is_Object (Proc) then
3772 Proc := Etype (Proc);
3775 if Ekind (Proc) = E_Access_Subprogram_Type then
3776 Proc := Directly_Designated_Type (Proc);
3779 if not Is_Subprogram (Proc)
3780 and then Ekind (Proc) /= E_Subprogram_Type
3786 end Get_Subprogram_Entity;
3788 -----------------------------
3789 -- Get_Task_Body_Procedure --
3790 -----------------------------
3792 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3794 -- Note: A task type may be the completion of a private type with
3795 -- discriminants. When performing elaboration checks on a task
3796 -- declaration, the current view of the type may be the private one,
3797 -- and the procedure that holds the body of the task is held in its
3800 -- This is an odd function, why not have Task_Body_Procedure do
3801 -- the following digging???
3803 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3804 end Get_Task_Body_Procedure;
3806 -----------------------
3807 -- Has_Access_Values --
3808 -----------------------
3810 function Has_Access_Values (T : Entity_Id) return Boolean is
3811 Typ : constant Entity_Id := Underlying_Type (T);
3814 -- Case of a private type which is not completed yet. This can only
3815 -- happen in the case of a generic format type appearing directly, or
3816 -- as a component of the type to which this function is being applied
3817 -- at the top level. Return False in this case, since we certainly do
3818 -- not know that the type contains access types.
3823 elsif Is_Access_Type (Typ) then
3826 elsif Is_Array_Type (Typ) then
3827 return Has_Access_Values (Component_Type (Typ));
3829 elsif Is_Record_Type (Typ) then
3834 -- Loop to Check components
3836 Comp := First_Component_Or_Discriminant (Typ);
3837 while Present (Comp) loop
3839 -- Check for access component, tag field does not count, even
3840 -- though it is implemented internally using an access type.
3842 if Has_Access_Values (Etype (Comp))
3843 and then Chars (Comp) /= Name_uTag
3848 Next_Component_Or_Discriminant (Comp);
3857 end Has_Access_Values;
3859 ------------------------------
3860 -- Has_Compatible_Alignment --
3861 ------------------------------
3863 function Has_Compatible_Alignment
3865 Expr : Node_Id) return Alignment_Result
3867 function Has_Compatible_Alignment_Internal
3870 Default : Alignment_Result) return Alignment_Result;
3871 -- This is the internal recursive function that actually does the work.
3872 -- There is one additional parameter, which says what the result should
3873 -- be if no alignment information is found, and there is no definite
3874 -- indication of compatible alignments. At the outer level, this is set
3875 -- to Unknown, but for internal recursive calls in the case where types
3876 -- are known to be correct, it is set to Known_Compatible.
3878 ---------------------------------------
3879 -- Has_Compatible_Alignment_Internal --
3880 ---------------------------------------
3882 function Has_Compatible_Alignment_Internal
3885 Default : Alignment_Result) return Alignment_Result
3887 Result : Alignment_Result := Known_Compatible;
3888 -- Holds the current status of the result. Note that once a value of
3889 -- Known_Incompatible is set, it is sticky and does not get changed
3890 -- to Unknown (the value in Result only gets worse as we go along,
3893 Offs : Uint := No_Uint;
3894 -- Set to a factor of the offset from the base object when Expr is a
3895 -- selected or indexed component, based on Component_Bit_Offset and
3896 -- Component_Size respectively. A negative value is used to represent
3897 -- a value which is not known at compile time.
3899 procedure Check_Prefix;
3900 -- Checks the prefix recursively in the case where the expression
3901 -- is an indexed or selected component.
3903 procedure Set_Result (R : Alignment_Result);
3904 -- If R represents a worse outcome (unknown instead of known
3905 -- compatible, or known incompatible), then set Result to R.
3911 procedure Check_Prefix is
3913 -- The subtlety here is that in doing a recursive call to check
3914 -- the prefix, we have to decide what to do in the case where we
3915 -- don't find any specific indication of an alignment problem.
3917 -- At the outer level, we normally set Unknown as the result in
3918 -- this case, since we can only set Known_Compatible if we really
3919 -- know that the alignment value is OK, but for the recursive
3920 -- call, in the case where the types match, and we have not
3921 -- specified a peculiar alignment for the object, we are only
3922 -- concerned about suspicious rep clauses, the default case does
3923 -- not affect us, since the compiler will, in the absence of such
3924 -- rep clauses, ensure that the alignment is correct.
3926 if Default = Known_Compatible
3928 (Etype (Obj) = Etype (Expr)
3929 and then (Unknown_Alignment (Obj)
3931 Alignment (Obj) = Alignment (Etype (Obj))))
3934 (Has_Compatible_Alignment_Internal
3935 (Obj, Prefix (Expr), Known_Compatible));
3937 -- In all other cases, we need a full check on the prefix
3941 (Has_Compatible_Alignment_Internal
3942 (Obj, Prefix (Expr), Unknown));
3950 procedure Set_Result (R : Alignment_Result) is
3957 -- Start of processing for Has_Compatible_Alignment_Internal
3960 -- If Expr is a selected component, we must make sure there is no
3961 -- potentially troublesome component clause, and that the record is
3964 if Nkind (Expr) = N_Selected_Component then
3966 -- Packed record always generate unknown alignment
3968 if Is_Packed (Etype (Prefix (Expr))) then
3969 Set_Result (Unknown);
3972 -- Check prefix and component offset
3975 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
3977 -- If Expr is an indexed component, we must make sure there is no
3978 -- potentially troublesome Component_Size clause and that the array
3979 -- is not bit-packed.
3981 elsif Nkind (Expr) = N_Indexed_Component then
3983 Typ : constant Entity_Id := Etype (Prefix (Expr));
3984 Ind : constant Node_Id := First_Index (Typ);
3987 -- Bit packed array always generates unknown alignment
3989 if Is_Bit_Packed_Array (Typ) then
3990 Set_Result (Unknown);
3993 -- Check prefix and component offset
3996 Offs := Component_Size (Typ);
3998 -- Small optimization: compute the full offset when possible
4001 and then Offs > Uint_0
4002 and then Present (Ind)
4003 and then Nkind (Ind) = N_Range
4004 and then Compile_Time_Known_Value (Low_Bound (Ind))
4005 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4007 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4008 - Expr_Value (Low_Bound ((Ind))));
4013 -- If we have a null offset, the result is entirely determined by
4014 -- the base object and has already been computed recursively.
4016 if Offs = Uint_0 then
4019 -- Case where we know the alignment of the object
4021 elsif Known_Alignment (Obj) then
4023 ObjA : constant Uint := Alignment (Obj);
4024 ExpA : Uint := No_Uint;
4025 SizA : Uint := No_Uint;
4028 -- If alignment of Obj is 1, then we are always OK
4031 Set_Result (Known_Compatible);
4033 -- Alignment of Obj is greater than 1, so we need to check
4036 -- If we have an offset, see if it is compatible
4038 if Offs /= No_Uint and Offs > Uint_0 then
4039 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4040 Set_Result (Known_Incompatible);
4043 -- See if Expr is an object with known alignment
4045 elsif Is_Entity_Name (Expr)
4046 and then Known_Alignment (Entity (Expr))
4048 ExpA := Alignment (Entity (Expr));
4050 -- Otherwise, we can use the alignment of the type of
4051 -- Expr given that we already checked for
4052 -- discombobulating rep clauses for the cases of indexed
4053 -- and selected components above.
4055 elsif Known_Alignment (Etype (Expr)) then
4056 ExpA := Alignment (Etype (Expr));
4058 -- Otherwise the alignment is unknown
4061 Set_Result (Default);
4064 -- If we got an alignment, see if it is acceptable
4066 if ExpA /= No_Uint and then ExpA < ObjA then
4067 Set_Result (Known_Incompatible);
4070 -- If Expr is not a piece of a larger object, see if size
4071 -- is given. If so, check that it is not too small for the
4072 -- required alignment.
4074 if Offs /= No_Uint then
4077 -- See if Expr is an object with known size
4079 elsif Is_Entity_Name (Expr)
4080 and then Known_Static_Esize (Entity (Expr))
4082 SizA := Esize (Entity (Expr));
4084 -- Otherwise, we check the object size of the Expr type
4086 elsif Known_Static_Esize (Etype (Expr)) then
4087 SizA := Esize (Etype (Expr));
4090 -- If we got a size, see if it is a multiple of the Obj
4091 -- alignment, if not, then the alignment cannot be
4092 -- acceptable, since the size is always a multiple of the
4095 if SizA /= No_Uint then
4096 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4097 Set_Result (Known_Incompatible);
4103 -- If we do not know required alignment, any non-zero offset is a
4104 -- potential problem (but certainly may be OK, so result is unknown).
4106 elsif Offs /= No_Uint then
4107 Set_Result (Unknown);
4109 -- If we can't find the result by direct comparison of alignment
4110 -- values, then there is still one case that we can determine known
4111 -- result, and that is when we can determine that the types are the
4112 -- same, and no alignments are specified. Then we known that the
4113 -- alignments are compatible, even if we don't know the alignment
4114 -- value in the front end.
4116 elsif Etype (Obj) = Etype (Expr) then
4118 -- Types are the same, but we have to check for possible size
4119 -- and alignments on the Expr object that may make the alignment
4120 -- different, even though the types are the same.
4122 if Is_Entity_Name (Expr) then
4124 -- First check alignment of the Expr object. Any alignment less
4125 -- than Maximum_Alignment is worrisome since this is the case
4126 -- where we do not know the alignment of Obj.
4128 if Known_Alignment (Entity (Expr))
4130 UI_To_Int (Alignment (Entity (Expr))) <
4131 Ttypes.Maximum_Alignment
4133 Set_Result (Unknown);
4135 -- Now check size of Expr object. Any size that is not an
4136 -- even multiple of Maximum_Alignment is also worrisome
4137 -- since it may cause the alignment of the object to be less
4138 -- than the alignment of the type.
4140 elsif Known_Static_Esize (Entity (Expr))
4142 (UI_To_Int (Esize (Entity (Expr))) mod
4143 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4146 Set_Result (Unknown);
4148 -- Otherwise same type is decisive
4151 Set_Result (Known_Compatible);
4155 -- Another case to deal with is when there is an explicit size or
4156 -- alignment clause when the types are not the same. If so, then the
4157 -- result is Unknown. We don't need to do this test if the Default is
4158 -- Unknown, since that result will be set in any case.
4160 elsif Default /= Unknown
4161 and then (Has_Size_Clause (Etype (Expr))
4163 Has_Alignment_Clause (Etype (Expr)))
4165 Set_Result (Unknown);
4167 -- If no indication found, set default
4170 Set_Result (Default);
4173 -- Return worst result found
4176 end Has_Compatible_Alignment_Internal;
4178 -- Start of processing for Has_Compatible_Alignment
4181 -- If Obj has no specified alignment, then set alignment from the type
4182 -- alignment. Perhaps we should always do this, but for sure we should
4183 -- do it when there is an address clause since we can do more if the
4184 -- alignment is known.
4186 if Unknown_Alignment (Obj) then
4187 Set_Alignment (Obj, Alignment (Etype (Obj)));
4190 -- Now do the internal call that does all the work
4192 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4193 end Has_Compatible_Alignment;
4195 ----------------------
4196 -- Has_Declarations --
4197 ----------------------
4199 function Has_Declarations (N : Node_Id) return Boolean is
4201 return Nkind_In (Nkind (N), N_Accept_Statement,
4203 N_Compilation_Unit_Aux,
4209 N_Package_Specification);
4210 end Has_Declarations;
4212 -------------------------------------------
4213 -- Has_Discriminant_Dependent_Constraint --
4214 -------------------------------------------
4216 function Has_Discriminant_Dependent_Constraint
4217 (Comp : Entity_Id) return Boolean
4219 Comp_Decl : constant Node_Id := Parent (Comp);
4220 Subt_Indic : constant Node_Id :=
4221 Subtype_Indication (Component_Definition (Comp_Decl));
4226 if Nkind (Subt_Indic) = N_Subtype_Indication then
4227 Constr := Constraint (Subt_Indic);
4229 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4230 Assn := First (Constraints (Constr));
4231 while Present (Assn) loop
4232 case Nkind (Assn) is
4233 when N_Subtype_Indication |
4237 if Depends_On_Discriminant (Assn) then
4241 when N_Discriminant_Association =>
4242 if Depends_On_Discriminant (Expression (Assn)) then
4257 end Has_Discriminant_Dependent_Constraint;
4259 --------------------
4260 -- Has_Infinities --
4261 --------------------
4263 function Has_Infinities (E : Entity_Id) return Boolean is
4266 Is_Floating_Point_Type (E)
4267 and then Nkind (Scalar_Range (E)) = N_Range
4268 and then Includes_Infinities (Scalar_Range (E));
4271 --------------------
4272 -- Has_Interfaces --
4273 --------------------
4275 function Has_Interfaces
4277 Use_Full_View : Boolean := True) return Boolean
4282 -- Handle concurrent types
4284 if Is_Concurrent_Type (T) then
4285 Typ := Corresponding_Record_Type (T);
4290 if not Present (Typ)
4291 or else not Is_Record_Type (Typ)
4292 or else not Is_Tagged_Type (Typ)
4297 -- Handle private types
4300 and then Present (Full_View (Typ))
4302 Typ := Full_View (Typ);
4305 -- Handle concurrent record types
4307 if Is_Concurrent_Record_Type (Typ)
4308 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4314 if Is_Interface (Typ)
4316 (Is_Record_Type (Typ)
4317 and then Present (Interfaces (Typ))
4318 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4323 exit when Etype (Typ) = Typ
4325 -- Handle private types
4327 or else (Present (Full_View (Etype (Typ)))
4328 and then Full_View (Etype (Typ)) = Typ)
4330 -- Protect the frontend against wrong source with cyclic
4333 or else Etype (Typ) = T;
4335 -- Climb to the ancestor type handling private types
4337 if Present (Full_View (Etype (Typ))) then
4338 Typ := Full_View (Etype (Typ));
4347 ------------------------
4348 -- Has_Null_Exclusion --
4349 ------------------------
4351 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4354 when N_Access_Definition |
4355 N_Access_Function_Definition |
4356 N_Access_Procedure_Definition |
4357 N_Access_To_Object_Definition |
4359 N_Derived_Type_Definition |
4360 N_Function_Specification |
4361 N_Subtype_Declaration =>
4362 return Null_Exclusion_Present (N);
4364 when N_Component_Definition |
4365 N_Formal_Object_Declaration |
4366 N_Object_Renaming_Declaration =>
4367 if Present (Subtype_Mark (N)) then
4368 return Null_Exclusion_Present (N);
4369 else pragma Assert (Present (Access_Definition (N)));
4370 return Null_Exclusion_Present (Access_Definition (N));
4373 when N_Discriminant_Specification =>
4374 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4375 return Null_Exclusion_Present (Discriminant_Type (N));
4377 return Null_Exclusion_Present (N);
4380 when N_Object_Declaration =>
4381 if Nkind (Object_Definition (N)) = N_Access_Definition then
4382 return Null_Exclusion_Present (Object_Definition (N));
4384 return Null_Exclusion_Present (N);
4387 when N_Parameter_Specification =>
4388 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4389 return Null_Exclusion_Present (Parameter_Type (N));
4391 return Null_Exclusion_Present (N);
4398 end Has_Null_Exclusion;
4400 ------------------------
4401 -- Has_Null_Extension --
4402 ------------------------
4404 function Has_Null_Extension (T : Entity_Id) return Boolean is
4405 B : constant Entity_Id := Base_Type (T);
4410 if Nkind (Parent (B)) = N_Full_Type_Declaration
4411 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4413 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4415 if Present (Ext) then
4416 if Null_Present (Ext) then
4419 Comps := Component_List (Ext);
4421 -- The null component list is rewritten during analysis to
4422 -- include the parent component. Any other component indicates
4423 -- that the extension was not originally null.
4425 return Null_Present (Comps)
4426 or else No (Next (First (Component_Items (Comps))));
4435 end Has_Null_Extension;
4437 -------------------------------
4438 -- Has_Overriding_Initialize --
4439 -------------------------------
4441 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4442 BT : constant Entity_Id := Base_Type (T);
4447 if Is_Controlled (BT) then
4449 -- For derived types, check immediate ancestor, excluding
4450 -- Controlled itself.
4452 if Is_Derived_Type (BT)
4453 and then not In_Predefined_Unit (Etype (BT))
4454 and then Has_Overriding_Initialize (Etype (BT))
4458 elsif Present (Primitive_Operations (BT)) then
4459 P := First_Elmt (Primitive_Operations (BT));
4460 while Present (P) loop
4461 if Chars (Node (P)) = Name_Initialize
4462 and then Comes_From_Source (Node (P))
4473 elsif Has_Controlled_Component (BT) then
4474 Comp := First_Component (BT);
4475 while Present (Comp) loop
4476 if Has_Overriding_Initialize (Etype (Comp)) then
4480 Next_Component (Comp);
4488 end Has_Overriding_Initialize;
4490 --------------------------------------
4491 -- Has_Preelaborable_Initialization --
4492 --------------------------------------
4494 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4497 procedure Check_Components (E : Entity_Id);
4498 -- Check component/discriminant chain, sets Has_PE False if a component
4499 -- or discriminant does not meet the preelaborable initialization rules.
4501 ----------------------
4502 -- Check_Components --
4503 ----------------------
4505 procedure Check_Components (E : Entity_Id) is
4509 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4510 -- Returns True if and only if the expression denoted by N does not
4511 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4513 ---------------------------------
4514 -- Is_Preelaborable_Expression --
4515 ---------------------------------
4517 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4521 Comp_Type : Entity_Id;
4522 Is_Array_Aggr : Boolean;
4525 if Is_Static_Expression (N) then
4528 elsif Nkind (N) = N_Null then
4531 -- Attributes are allowed in general, even if their prefix is a
4532 -- formal type. (It seems that certain attributes known not to be
4533 -- static might not be allowed, but there are no rules to prevent
4536 elsif Nkind (N) = N_Attribute_Reference then
4539 -- The name of a discriminant evaluated within its parent type is
4540 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4541 -- names that denote discriminals as well as discriminants to
4542 -- catch references occurring within init procs.
4544 elsif Is_Entity_Name (N)
4546 (Ekind (Entity (N)) = E_Discriminant
4548 ((Ekind (Entity (N)) = E_Constant
4549 or else Ekind (Entity (N)) = E_In_Parameter)
4550 and then Present (Discriminal_Link (Entity (N)))))
4554 elsif Nkind (N) = N_Qualified_Expression then
4555 return Is_Preelaborable_Expression (Expression (N));
4557 -- For aggregates we have to check that each of the associations
4558 -- is preelaborable.
4560 elsif Nkind (N) = N_Aggregate
4561 or else Nkind (N) = N_Extension_Aggregate
4563 Is_Array_Aggr := Is_Array_Type (Etype (N));
4565 if Is_Array_Aggr then
4566 Comp_Type := Component_Type (Etype (N));
4569 -- Check the ancestor part of extension aggregates, which must
4570 -- be either the name of a type that has preelaborable init or
4571 -- an expression that is preelaborable.
4573 if Nkind (N) = N_Extension_Aggregate then
4575 Anc_Part : constant Node_Id := Ancestor_Part (N);
4578 if Is_Entity_Name (Anc_Part)
4579 and then Is_Type (Entity (Anc_Part))
4581 if not Has_Preelaborable_Initialization
4587 elsif not Is_Preelaborable_Expression (Anc_Part) then
4593 -- Check positional associations
4595 Exp := First (Expressions (N));
4596 while Present (Exp) loop
4597 if not Is_Preelaborable_Expression (Exp) then
4604 -- Check named associations
4606 Assn := First (Component_Associations (N));
4607 while Present (Assn) loop
4608 Choice := First (Choices (Assn));
4609 while Present (Choice) loop
4610 if Is_Array_Aggr then
4611 if Nkind (Choice) = N_Others_Choice then
4614 elsif Nkind (Choice) = N_Range then
4615 if not Is_Static_Range (Choice) then
4619 elsif not Is_Static_Expression (Choice) then
4624 Comp_Type := Etype (Choice);
4630 -- If the association has a <> at this point, then we have
4631 -- to check whether the component's type has preelaborable
4632 -- initialization. Note that this only occurs when the
4633 -- association's corresponding component does not have a
4634 -- default expression, the latter case having already been
4635 -- expanded as an expression for the association.
4637 if Box_Present (Assn) then
4638 if not Has_Preelaborable_Initialization (Comp_Type) then
4642 -- In the expression case we check whether the expression
4643 -- is preelaborable.
4646 not Is_Preelaborable_Expression (Expression (Assn))
4654 -- If we get here then aggregate as a whole is preelaborable
4658 -- All other cases are not preelaborable
4663 end Is_Preelaborable_Expression;
4665 -- Start of processing for Check_Components
4668 -- Loop through entities of record or protected type
4671 while Present (Ent) loop
4673 -- We are interested only in components and discriminants
4675 if Ekind (Ent) = E_Component
4677 Ekind (Ent) = E_Discriminant
4679 -- Get default expression if any. If there is no declaration
4680 -- node, it means we have an internal entity. The parent and
4681 -- tag fields are examples of such entities. For these cases,
4682 -- we just test the type of the entity.
4684 if Present (Declaration_Node (Ent)) then
4685 Exp := Expression (Declaration_Node (Ent));
4690 -- A component has PI if it has no default expression and the
4691 -- component type has PI.
4694 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4699 -- Require the default expression to be preelaborable
4701 elsif not Is_Preelaborable_Expression (Exp) then
4709 end Check_Components;
4711 -- Start of processing for Has_Preelaborable_Initialization
4714 -- Immediate return if already marked as known preelaborable init. This
4715 -- covers types for which this function has already been called once
4716 -- and returned True (in which case the result is cached), and also
4717 -- types to which a pragma Preelaborable_Initialization applies.
4719 if Known_To_Have_Preelab_Init (E) then
4723 -- If the type is a subtype representing a generic actual type, then
4724 -- test whether its base type has preelaborable initialization since
4725 -- the subtype representing the actual does not inherit this attribute
4726 -- from the actual or formal. (but maybe it should???)
4728 if Is_Generic_Actual_Type (E) then
4729 return Has_Preelaborable_Initialization (Base_Type (E));
4732 -- All elementary types have preelaborable initialization
4734 if Is_Elementary_Type (E) then
4737 -- Array types have PI if the component type has PI
4739 elsif Is_Array_Type (E) then
4740 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4742 -- A derived type has preelaborable initialization if its parent type
4743 -- has preelaborable initialization and (in the case of a derived record
4744 -- extension) if the non-inherited components all have preelaborable
4745 -- initialization. However, a user-defined controlled type with an
4746 -- overriding Initialize procedure does not have preelaborable
4749 elsif Is_Derived_Type (E) then
4751 -- If the derived type is a private extension then it doesn't have
4752 -- preelaborable initialization.
4754 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4758 -- First check whether ancestor type has preelaborable initialization
4760 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4762 -- If OK, check extension components (if any)
4764 if Has_PE and then Is_Record_Type (E) then
4765 Check_Components (First_Entity (E));
4768 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4769 -- with a user defined Initialize procedure does not have PI.
4772 and then Is_Controlled (E)
4773 and then Has_Overriding_Initialize (E)
4778 -- Private types not derived from a type having preelaborable init and
4779 -- that are not marked with pragma Preelaborable_Initialization do not
4780 -- have preelaborable initialization.
4782 elsif Is_Private_Type (E) then
4785 -- Record type has PI if it is non private and all components have PI
4787 elsif Is_Record_Type (E) then
4789 Check_Components (First_Entity (E));
4791 -- Protected types must not have entries, and components must meet
4792 -- same set of rules as for record components.
4794 elsif Is_Protected_Type (E) then
4795 if Has_Entries (E) then
4799 Check_Components (First_Entity (E));
4800 Check_Components (First_Private_Entity (E));
4803 -- Type System.Address always has preelaborable initialization
4805 elsif Is_RTE (E, RE_Address) then
4808 -- In all other cases, type does not have preelaborable initialization
4814 -- If type has preelaborable initialization, cache result
4817 Set_Known_To_Have_Preelab_Init (E);
4821 end Has_Preelaborable_Initialization;
4823 ---------------------------
4824 -- Has_Private_Component --
4825 ---------------------------
4827 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4828 Btype : Entity_Id := Base_Type (Type_Id);
4829 Component : Entity_Id;
4832 if Error_Posted (Type_Id)
4833 or else Error_Posted (Btype)
4838 if Is_Class_Wide_Type (Btype) then
4839 Btype := Root_Type (Btype);
4842 if Is_Private_Type (Btype) then
4844 UT : constant Entity_Id := Underlying_Type (Btype);
4847 if No (Full_View (Btype)) then
4848 return not Is_Generic_Type (Btype)
4849 and then not Is_Generic_Type (Root_Type (Btype));
4851 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4854 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4858 elsif Is_Array_Type (Btype) then
4859 return Has_Private_Component (Component_Type (Btype));
4861 elsif Is_Record_Type (Btype) then
4862 Component := First_Component (Btype);
4863 while Present (Component) loop
4864 if Has_Private_Component (Etype (Component)) then
4868 Next_Component (Component);
4873 elsif Is_Protected_Type (Btype)
4874 and then Present (Corresponding_Record_Type (Btype))
4876 return Has_Private_Component (Corresponding_Record_Type (Btype));
4881 end Has_Private_Component;
4887 function Has_Stream (T : Entity_Id) return Boolean is
4894 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4897 elsif Is_Array_Type (T) then
4898 return Has_Stream (Component_Type (T));
4900 elsif Is_Record_Type (T) then
4901 E := First_Component (T);
4902 while Present (E) loop
4903 if Has_Stream (Etype (E)) then
4912 elsif Is_Private_Type (T) then
4913 return Has_Stream (Underlying_Type (T));
4920 --------------------------
4921 -- Has_Tagged_Component --
4922 --------------------------
4924 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4928 if Is_Private_Type (Typ)
4929 and then Present (Underlying_Type (Typ))
4931 return Has_Tagged_Component (Underlying_Type (Typ));
4933 elsif Is_Array_Type (Typ) then
4934 return Has_Tagged_Component (Component_Type (Typ));
4936 elsif Is_Tagged_Type (Typ) then
4939 elsif Is_Record_Type (Typ) then
4940 Comp := First_Component (Typ);
4941 while Present (Comp) loop
4942 if Has_Tagged_Component (Etype (Comp)) then
4946 Next_Component (Comp);
4954 end Has_Tagged_Component;
4956 --------------------------
4957 -- Implements_Interface --
4958 --------------------------
4960 function Implements_Interface
4961 (Typ_Ent : Entity_Id;
4962 Iface_Ent : Entity_Id;
4963 Exclude_Parents : Boolean := False) return Boolean
4965 Ifaces_List : Elist_Id;
4967 Iface : Entity_Id := Base_Type (Iface_Ent);
4968 Typ : Entity_Id := Base_Type (Typ_Ent);
4971 if Is_Class_Wide_Type (Typ) then
4972 Typ := Root_Type (Typ);
4975 if not Has_Interfaces (Typ) then
4979 if Is_Class_Wide_Type (Iface) then
4980 Iface := Root_Type (Iface);
4983 Collect_Interfaces (Typ, Ifaces_List);
4985 Elmt := First_Elmt (Ifaces_List);
4986 while Present (Elmt) loop
4987 if Is_Ancestor (Node (Elmt), Typ)
4988 and then Exclude_Parents
4992 elsif Node (Elmt) = Iface then
5000 end Implements_Interface;
5006 function In_Instance return Boolean is
5007 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5013 and then S /= Standard_Standard
5015 if (Ekind (S) = E_Function
5016 or else Ekind (S) = E_Package
5017 or else Ekind (S) = E_Procedure)
5018 and then Is_Generic_Instance (S)
5020 -- A child instance is always compiled in the context of a parent
5021 -- instance. Nevertheless, the actuals are not analyzed in an
5022 -- instance context. We detect this case by examining the current
5023 -- compilation unit, which must be a child instance, and checking
5024 -- that it is not currently on the scope stack.
5026 if Is_Child_Unit (Curr_Unit)
5028 Nkind (Unit (Cunit (Current_Sem_Unit)))
5029 = N_Package_Instantiation
5030 and then not In_Open_Scopes (Curr_Unit)
5044 ----------------------
5045 -- In_Instance_Body --
5046 ----------------------
5048 function In_Instance_Body return Boolean is
5054 and then S /= Standard_Standard
5056 if (Ekind (S) = E_Function
5057 or else Ekind (S) = E_Procedure)
5058 and then Is_Generic_Instance (S)
5062 elsif Ekind (S) = E_Package
5063 and then In_Package_Body (S)
5064 and then Is_Generic_Instance (S)
5073 end In_Instance_Body;
5075 -----------------------------
5076 -- In_Instance_Not_Visible --
5077 -----------------------------
5079 function In_Instance_Not_Visible return Boolean is
5085 and then S /= Standard_Standard
5087 if (Ekind (S) = E_Function
5088 or else Ekind (S) = E_Procedure)
5089 and then Is_Generic_Instance (S)
5093 elsif Ekind (S) = E_Package
5094 and then (In_Package_Body (S) or else In_Private_Part (S))
5095 and then Is_Generic_Instance (S)
5104 end In_Instance_Not_Visible;
5106 ------------------------------
5107 -- In_Instance_Visible_Part --
5108 ------------------------------
5110 function In_Instance_Visible_Part return Boolean is
5116 and then S /= Standard_Standard
5118 if Ekind (S) = E_Package
5119 and then Is_Generic_Instance (S)
5120 and then not In_Package_Body (S)
5121 and then not In_Private_Part (S)
5130 end In_Instance_Visible_Part;
5132 ---------------------
5133 -- In_Package_Body --
5134 ---------------------
5136 function In_Package_Body return Boolean is
5142 and then S /= Standard_Standard
5144 if Ekind (S) = E_Package
5145 and then In_Package_Body (S)
5154 end In_Package_Body;
5156 --------------------------------
5157 -- In_Parameter_Specification --
5158 --------------------------------
5160 function In_Parameter_Specification (N : Node_Id) return Boolean is
5165 while Present (PN) loop
5166 if Nkind (PN) = N_Parameter_Specification then
5174 end In_Parameter_Specification;
5176 --------------------------------------
5177 -- In_Subprogram_Or_Concurrent_Unit --
5178 --------------------------------------
5180 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5185 -- Use scope chain to check successively outer scopes
5191 if K in Subprogram_Kind
5192 or else K in Concurrent_Kind
5193 or else K in Generic_Subprogram_Kind
5197 elsif E = Standard_Standard then
5203 end In_Subprogram_Or_Concurrent_Unit;
5205 ---------------------
5206 -- In_Visible_Part --
5207 ---------------------
5209 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5212 Is_Package_Or_Generic_Package (Scope_Id)
5213 and then In_Open_Scopes (Scope_Id)
5214 and then not In_Package_Body (Scope_Id)
5215 and then not In_Private_Part (Scope_Id);
5216 end In_Visible_Part;
5218 ---------------------------------
5219 -- Insert_Explicit_Dereference --
5220 ---------------------------------
5222 procedure Insert_Explicit_Dereference (N : Node_Id) is
5223 New_Prefix : constant Node_Id := Relocate_Node (N);
5224 Ent : Entity_Id := Empty;
5231 Save_Interps (N, New_Prefix);
5232 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5234 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5236 if Is_Overloaded (New_Prefix) then
5238 -- The deference is also overloaded, and its interpretations are the
5239 -- designated types of the interpretations of the original node.
5241 Set_Etype (N, Any_Type);
5243 Get_First_Interp (New_Prefix, I, It);
5244 while Present (It.Nam) loop
5247 if Is_Access_Type (T) then
5248 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5251 Get_Next_Interp (I, It);
5257 -- Prefix is unambiguous: mark the original prefix (which might
5258 -- Come_From_Source) as a reference, since the new (relocated) one
5259 -- won't be taken into account.
5261 if Is_Entity_Name (New_Prefix) then
5262 Ent := Entity (New_Prefix);
5264 -- For a retrieval of a subcomponent of some composite object,
5265 -- retrieve the ultimate entity if there is one.
5267 elsif Nkind (New_Prefix) = N_Selected_Component
5268 or else Nkind (New_Prefix) = N_Indexed_Component
5270 Pref := Prefix (New_Prefix);
5271 while Present (Pref)
5273 (Nkind (Pref) = N_Selected_Component
5274 or else Nkind (Pref) = N_Indexed_Component)
5276 Pref := Prefix (Pref);
5279 if Present (Pref) and then Is_Entity_Name (Pref) then
5280 Ent := Entity (Pref);
5284 if Present (Ent) then
5285 Generate_Reference (Ent, New_Prefix);
5288 end Insert_Explicit_Dereference;
5290 ------------------------------------------
5291 -- Inspect_Deferred_Constant_Completion --
5292 ------------------------------------------
5294 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5298 Decl := First (Decls);
5299 while Present (Decl) loop
5301 -- Deferred constant signature
5303 if Nkind (Decl) = N_Object_Declaration
5304 and then Constant_Present (Decl)
5305 and then No (Expression (Decl))
5307 -- No need to check internally generated constants
5309 and then Comes_From_Source (Decl)
5311 -- The constant is not completed. A full object declaration
5312 -- or a pragma Import complete a deferred constant.
5314 and then not Has_Completion (Defining_Identifier (Decl))
5317 ("constant declaration requires initialization expression",
5318 Defining_Identifier (Decl));
5321 Decl := Next (Decl);
5323 end Inspect_Deferred_Constant_Completion;
5329 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5330 pragma Assert (Is_Type (E));
5332 return AAMP_On_Target
5333 and then Is_Floating_Point_Type (E)
5334 and then E = Base_Type (E);
5337 -------------------------
5338 -- Is_Actual_Parameter --
5339 -------------------------
5341 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5342 PK : constant Node_Kind := Nkind (Parent (N));
5346 when N_Parameter_Association =>
5347 return N = Explicit_Actual_Parameter (Parent (N));
5349 when N_Function_Call | N_Procedure_Call_Statement =>
5350 return Is_List_Member (N)
5352 List_Containing (N) = Parameter_Associations (Parent (N));
5357 end Is_Actual_Parameter;
5359 ---------------------
5360 -- Is_Aliased_View --
5361 ---------------------
5363 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5367 if Is_Entity_Name (Obj) then
5375 or else (Present (Renamed_Object (E))
5376 and then Is_Aliased_View (Renamed_Object (E)))))
5378 or else ((Is_Formal (E)
5379 or else Ekind (E) = E_Generic_In_Out_Parameter
5380 or else Ekind (E) = E_Generic_In_Parameter)
5381 and then Is_Tagged_Type (Etype (E)))
5383 or else (Is_Concurrent_Type (E)
5384 and then In_Open_Scopes (E))
5386 -- Current instance of type, either directly or as rewritten
5387 -- reference to the current object.
5389 or else (Is_Entity_Name (Original_Node (Obj))
5390 and then Present (Entity (Original_Node (Obj)))
5391 and then Is_Type (Entity (Original_Node (Obj))))
5393 or else (Is_Type (E) and then E = Current_Scope)
5395 or else (Is_Incomplete_Or_Private_Type (E)
5396 and then Full_View (E) = Current_Scope);
5398 elsif Nkind (Obj) = N_Selected_Component then
5399 return Is_Aliased (Entity (Selector_Name (Obj)));
5401 elsif Nkind (Obj) = N_Indexed_Component then
5402 return Has_Aliased_Components (Etype (Prefix (Obj)))
5404 (Is_Access_Type (Etype (Prefix (Obj)))
5406 Has_Aliased_Components
5407 (Designated_Type (Etype (Prefix (Obj)))));
5409 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5410 or else Nkind (Obj) = N_Type_Conversion
5412 return Is_Tagged_Type (Etype (Obj))
5413 and then Is_Aliased_View (Expression (Obj));
5415 elsif Nkind (Obj) = N_Explicit_Dereference then
5416 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5421 end Is_Aliased_View;
5423 -------------------------
5424 -- Is_Ancestor_Package --
5425 -------------------------
5427 function Is_Ancestor_Package
5429 E2 : Entity_Id) return Boolean
5436 and then Par /= Standard_Standard
5446 end Is_Ancestor_Package;
5448 ----------------------
5449 -- Is_Atomic_Object --
5450 ----------------------
5452 function Is_Atomic_Object (N : Node_Id) return Boolean is
5454 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5455 -- Determines if given object has atomic components
5457 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5458 -- If prefix is an implicit dereference, examine designated type
5460 ----------------------
5461 -- Is_Atomic_Prefix --
5462 ----------------------
5464 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5466 if Is_Access_Type (Etype (N)) then
5468 Has_Atomic_Components (Designated_Type (Etype (N)));
5470 return Object_Has_Atomic_Components (N);
5472 end Is_Atomic_Prefix;
5474 ----------------------------------
5475 -- Object_Has_Atomic_Components --
5476 ----------------------------------
5478 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5480 if Has_Atomic_Components (Etype (N))
5481 or else Is_Atomic (Etype (N))
5485 elsif Is_Entity_Name (N)
5486 and then (Has_Atomic_Components (Entity (N))
5487 or else Is_Atomic (Entity (N)))
5491 elsif Nkind (N) = N_Indexed_Component
5492 or else Nkind (N) = N_Selected_Component
5494 return Is_Atomic_Prefix (Prefix (N));
5499 end Object_Has_Atomic_Components;
5501 -- Start of processing for Is_Atomic_Object
5504 if Is_Atomic (Etype (N))
5505 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5509 elsif Nkind (N) = N_Indexed_Component
5510 or else Nkind (N) = N_Selected_Component
5512 return Is_Atomic_Prefix (Prefix (N));
5517 end Is_Atomic_Object;
5519 -------------------------
5520 -- Is_Coextension_Root --
5521 -------------------------
5523 function Is_Coextension_Root (N : Node_Id) return Boolean is
5526 Nkind (N) = N_Allocator
5527 and then Present (Coextensions (N))
5529 -- Anonymous access discriminants carry a list of all nested
5530 -- controlled coextensions.
5532 and then not Is_Dynamic_Coextension (N)
5533 and then not Is_Static_Coextension (N);
5534 end Is_Coextension_Root;
5536 -----------------------------
5537 -- Is_Concurrent_Interface --
5538 -----------------------------
5540 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5545 (Is_Protected_Interface (T)
5546 or else Is_Synchronized_Interface (T)
5547 or else Is_Task_Interface (T));
5548 end Is_Concurrent_Interface;
5550 --------------------------------------
5551 -- Is_Controlling_Limited_Procedure --
5552 --------------------------------------
5554 function Is_Controlling_Limited_Procedure
5555 (Proc_Nam : Entity_Id) return Boolean
5557 Param_Typ : Entity_Id := Empty;
5560 if Ekind (Proc_Nam) = E_Procedure
5561 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5563 Param_Typ := Etype (Parameter_Type (First (
5564 Parameter_Specifications (Parent (Proc_Nam)))));
5566 -- In this case where an Itype was created, the procedure call has been
5569 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5570 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5572 Present (Parameter_Associations
5573 (Associated_Node_For_Itype (Proc_Nam)))
5576 Etype (First (Parameter_Associations
5577 (Associated_Node_For_Itype (Proc_Nam))));
5580 if Present (Param_Typ) then
5582 Is_Interface (Param_Typ)
5583 and then Is_Limited_Record (Param_Typ);
5587 end Is_Controlling_Limited_Procedure;
5589 -----------------------------
5590 -- Is_CPP_Constructor_Call --
5591 -----------------------------
5593 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5595 return Nkind (N) = N_Function_Call
5596 and then Is_CPP_Class (Etype (Etype (N)))
5597 and then Is_Constructor (Entity (Name (N)))
5598 and then Is_Imported (Entity (Name (N)));
5599 end Is_CPP_Constructor_Call;
5601 ----------------------------------------------
5602 -- Is_Dependent_Component_Of_Mutable_Object --
5603 ----------------------------------------------
5605 function Is_Dependent_Component_Of_Mutable_Object
5606 (Object : Node_Id) return Boolean
5609 Prefix_Type : Entity_Id;
5610 P_Aliased : Boolean := False;
5613 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5614 -- Returns True if and only if Comp is declared within a variant part
5616 --------------------------------
5617 -- Is_Declared_Within_Variant --
5618 --------------------------------
5620 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5621 Comp_Decl : constant Node_Id := Parent (Comp);
5622 Comp_List : constant Node_Id := Parent (Comp_Decl);
5624 return Nkind (Parent (Comp_List)) = N_Variant;
5625 end Is_Declared_Within_Variant;
5627 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5630 if Is_Variable (Object) then
5632 if Nkind (Object) = N_Selected_Component then
5633 P := Prefix (Object);
5634 Prefix_Type := Etype (P);
5636 if Is_Entity_Name (P) then
5638 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5639 Prefix_Type := Base_Type (Prefix_Type);
5642 if Is_Aliased (Entity (P)) then
5646 -- A discriminant check on a selected component may be
5647 -- expanded into a dereference when removing side-effects.
5648 -- Recover the original node and its type, which may be
5651 elsif Nkind (P) = N_Explicit_Dereference
5652 and then not (Comes_From_Source (P))
5654 P := Original_Node (P);
5655 Prefix_Type := Etype (P);
5658 -- Check for prefix being an aliased component ???
5663 -- A heap object is constrained by its initial value
5665 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5666 -- the dereferenced case, since the access value might denote an
5667 -- unconstrained aliased object, whereas in Ada 95 the designated
5668 -- object is guaranteed to be constrained. A worst-case assumption
5669 -- has to apply in Ada 2005 because we can't tell at compile time
5670 -- whether the object is "constrained by its initial value"
5671 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5672 -- semantic rules -- these rules are acknowledged to need fixing).
5674 if Ada_Version < Ada_05 then
5675 if Is_Access_Type (Prefix_Type)
5676 or else Nkind (P) = N_Explicit_Dereference
5681 elsif Ada_Version >= Ada_05 then
5682 if Is_Access_Type (Prefix_Type) then
5684 -- If the access type is pool-specific, and there is no
5685 -- constrained partial view of the designated type, then the
5686 -- designated object is known to be constrained.
5688 if Ekind (Prefix_Type) = E_Access_Type
5689 and then not Has_Constrained_Partial_View
5690 (Designated_Type (Prefix_Type))
5694 -- Otherwise (general access type, or there is a constrained
5695 -- partial view of the designated type), we need to check
5696 -- based on the designated type.
5699 Prefix_Type := Designated_Type (Prefix_Type);
5705 Original_Record_Component (Entity (Selector_Name (Object)));
5707 -- As per AI-0017, the renaming is illegal in a generic body,
5708 -- even if the subtype is indefinite.
5710 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5712 if not Is_Constrained (Prefix_Type)
5713 and then (not Is_Indefinite_Subtype (Prefix_Type)
5715 (Is_Generic_Type (Prefix_Type)
5716 and then Ekind (Current_Scope) = E_Generic_Package
5717 and then In_Package_Body (Current_Scope)))
5719 and then (Is_Declared_Within_Variant (Comp)
5720 or else Has_Discriminant_Dependent_Constraint (Comp))
5721 and then (not P_Aliased or else Ada_Version >= Ada_05)
5727 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5731 elsif Nkind (Object) = N_Indexed_Component
5732 or else Nkind (Object) = N_Slice
5734 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5736 -- A type conversion that Is_Variable is a view conversion:
5737 -- go back to the denoted object.
5739 elsif Nkind (Object) = N_Type_Conversion then
5741 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5746 end Is_Dependent_Component_Of_Mutable_Object;
5748 ---------------------
5749 -- Is_Dereferenced --
5750 ---------------------
5752 function Is_Dereferenced (N : Node_Id) return Boolean is
5753 P : constant Node_Id := Parent (N);
5756 (Nkind (P) = N_Selected_Component
5758 Nkind (P) = N_Explicit_Dereference
5760 Nkind (P) = N_Indexed_Component
5762 Nkind (P) = N_Slice)
5763 and then Prefix (P) = N;
5764 end Is_Dereferenced;
5766 ----------------------
5767 -- Is_Descendent_Of --
5768 ----------------------
5770 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5775 pragma Assert (Nkind (T1) in N_Entity);
5776 pragma Assert (Nkind (T2) in N_Entity);
5778 T := Base_Type (T1);
5780 -- Immediate return if the types match
5785 -- Comment needed here ???
5787 elsif Ekind (T) = E_Class_Wide_Type then
5788 return Etype (T) = T2;
5796 -- Done if we found the type we are looking for
5801 -- Done if no more derivations to check
5808 -- Following test catches error cases resulting from prev errors
5810 elsif No (Etyp) then
5813 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5816 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5820 T := Base_Type (Etyp);
5823 end Is_Descendent_Of;
5829 function Is_False (U : Uint) return Boolean is
5834 ---------------------------
5835 -- Is_Fixed_Model_Number --
5836 ---------------------------
5838 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5839 S : constant Ureal := Small_Value (T);
5840 M : Urealp.Save_Mark;
5844 R := (U = UR_Trunc (U / S) * S);
5847 end Is_Fixed_Model_Number;
5849 -------------------------------
5850 -- Is_Fully_Initialized_Type --
5851 -------------------------------
5853 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5855 if Is_Scalar_Type (Typ) then
5858 elsif Is_Access_Type (Typ) then
5861 elsif Is_Array_Type (Typ) then
5862 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5866 -- An interesting case, if we have a constrained type one of whose
5867 -- bounds is known to be null, then there are no elements to be
5868 -- initialized, so all the elements are initialized!
5870 if Is_Constrained (Typ) then
5873 Indx_Typ : Entity_Id;
5877 Indx := First_Index (Typ);
5878 while Present (Indx) loop
5879 if Etype (Indx) = Any_Type then
5882 -- If index is a range, use directly
5884 elsif Nkind (Indx) = N_Range then
5885 Lbd := Low_Bound (Indx);
5886 Hbd := High_Bound (Indx);
5889 Indx_Typ := Etype (Indx);
5891 if Is_Private_Type (Indx_Typ) then
5892 Indx_Typ := Full_View (Indx_Typ);
5895 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5898 Lbd := Type_Low_Bound (Indx_Typ);
5899 Hbd := Type_High_Bound (Indx_Typ);
5903 if Compile_Time_Known_Value (Lbd)
5904 and then Compile_Time_Known_Value (Hbd)
5906 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5916 -- If no null indexes, then type is not fully initialized
5922 elsif Is_Record_Type (Typ) then
5923 if Has_Discriminants (Typ)
5925 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5926 and then Is_Fully_Initialized_Variant (Typ)
5931 -- Controlled records are considered to be fully initialized if
5932 -- there is a user defined Initialize routine. This may not be
5933 -- entirely correct, but as the spec notes, we are guessing here
5934 -- what is best from the point of view of issuing warnings.
5936 if Is_Controlled (Typ) then
5938 Utyp : constant Entity_Id := Underlying_Type (Typ);
5941 if Present (Utyp) then
5943 Init : constant Entity_Id :=
5945 (Underlying_Type (Typ), Name_Initialize));
5949 and then Comes_From_Source (Init)
5951 Is_Predefined_File_Name
5952 (File_Name (Get_Source_File_Index (Sloc (Init))))
5956 elsif Has_Null_Extension (Typ)
5958 Is_Fully_Initialized_Type
5959 (Etype (Base_Type (Typ)))
5968 -- Otherwise see if all record components are initialized
5974 Ent := First_Entity (Typ);
5975 while Present (Ent) loop
5976 if Chars (Ent) = Name_uController then
5979 elsif Ekind (Ent) = E_Component
5980 and then (No (Parent (Ent))
5981 or else No (Expression (Parent (Ent))))
5982 and then not Is_Fully_Initialized_Type (Etype (Ent))
5984 -- Special VM case for tag components, which need to be
5985 -- defined in this case, but are never initialized as VMs
5986 -- are using other dispatching mechanisms. Ignore this
5987 -- uninitialized case. Note that this applies both to the
5988 -- uTag entry and the main vtable pointer (CPP_Class case).
5990 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
5999 -- No uninitialized components, so type is fully initialized.
6000 -- Note that this catches the case of no components as well.
6004 elsif Is_Concurrent_Type (Typ) then
6007 elsif Is_Private_Type (Typ) then
6009 U : constant Entity_Id := Underlying_Type (Typ);
6015 return Is_Fully_Initialized_Type (U);
6022 end Is_Fully_Initialized_Type;
6024 ----------------------------------
6025 -- Is_Fully_Initialized_Variant --
6026 ----------------------------------
6028 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6029 Loc : constant Source_Ptr := Sloc (Typ);
6030 Constraints : constant List_Id := New_List;
6031 Components : constant Elist_Id := New_Elmt_List;
6032 Comp_Elmt : Elmt_Id;
6034 Comp_List : Node_Id;
6036 Discr_Val : Node_Id;
6038 Report_Errors : Boolean;
6039 pragma Warnings (Off, Report_Errors);
6042 if Serious_Errors_Detected > 0 then
6046 if Is_Record_Type (Typ)
6047 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6048 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6050 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6052 Discr := First_Discriminant (Typ);
6053 while Present (Discr) loop
6054 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6055 Discr_Val := Expression (Parent (Discr));
6057 if Present (Discr_Val)
6058 and then Is_OK_Static_Expression (Discr_Val)
6060 Append_To (Constraints,
6061 Make_Component_Association (Loc,
6062 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6063 Expression => New_Copy (Discr_Val)));
6071 Next_Discriminant (Discr);
6076 Comp_List => Comp_List,
6077 Governed_By => Constraints,
6079 Report_Errors => Report_Errors);
6081 -- Check that each component present is fully initialized
6083 Comp_Elmt := First_Elmt (Components);
6084 while Present (Comp_Elmt) loop
6085 Comp_Id := Node (Comp_Elmt);
6087 if Ekind (Comp_Id) = E_Component
6088 and then (No (Parent (Comp_Id))
6089 or else No (Expression (Parent (Comp_Id))))
6090 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6095 Next_Elmt (Comp_Elmt);
6100 elsif Is_Private_Type (Typ) then
6102 U : constant Entity_Id := Underlying_Type (Typ);
6108 return Is_Fully_Initialized_Variant (U);
6114 end Is_Fully_Initialized_Variant;
6116 ----------------------------
6117 -- Is_Inherited_Operation --
6118 ----------------------------
6120 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6121 Kind : constant Node_Kind := Nkind (Parent (E));
6123 pragma Assert (Is_Overloadable (E));
6124 return Kind = N_Full_Type_Declaration
6125 or else Kind = N_Private_Extension_Declaration
6126 or else Kind = N_Subtype_Declaration
6127 or else (Ekind (E) = E_Enumeration_Literal
6128 and then Is_Derived_Type (Etype (E)));
6129 end Is_Inherited_Operation;
6131 -----------------------------
6132 -- Is_Library_Level_Entity --
6133 -----------------------------
6135 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6137 -- The following is a small optimization, and it also properly handles
6138 -- discriminals, which in task bodies might appear in expressions before
6139 -- the corresponding procedure has been created, and which therefore do
6140 -- not have an assigned scope.
6142 if Ekind (E) in Formal_Kind then
6146 -- Normal test is simply that the enclosing dynamic scope is Standard
6148 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6149 end Is_Library_Level_Entity;
6151 ---------------------------------
6152 -- Is_Local_Variable_Reference --
6153 ---------------------------------
6155 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6157 if not Is_Entity_Name (Expr) then
6162 Ent : constant Entity_Id := Entity (Expr);
6163 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6165 if Ekind (Ent) /= E_Variable
6167 Ekind (Ent) /= E_In_Out_Parameter
6171 return Present (Sub) and then Sub = Current_Subprogram;
6175 end Is_Local_Variable_Reference;
6177 -------------------------
6178 -- Is_Object_Reference --
6179 -------------------------
6181 function Is_Object_Reference (N : Node_Id) return Boolean is
6183 if Is_Entity_Name (N) then
6184 return Present (Entity (N)) and then Is_Object (Entity (N));
6188 when N_Indexed_Component | N_Slice =>
6190 Is_Object_Reference (Prefix (N))
6191 or else Is_Access_Type (Etype (Prefix (N)));
6193 -- In Ada95, a function call is a constant object; a procedure
6196 when N_Function_Call =>
6197 return Etype (N) /= Standard_Void_Type;
6199 -- A reference to the stream attribute Input is a function call
6201 when N_Attribute_Reference =>
6202 return Attribute_Name (N) = Name_Input;
6204 when N_Selected_Component =>
6206 Is_Object_Reference (Selector_Name (N))
6208 (Is_Object_Reference (Prefix (N))
6209 or else Is_Access_Type (Etype (Prefix (N))));
6211 when N_Explicit_Dereference =>
6214 -- A view conversion of a tagged object is an object reference
6216 when N_Type_Conversion =>
6217 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6218 and then Is_Tagged_Type (Etype (Expression (N)))
6219 and then Is_Object_Reference (Expression (N));
6221 -- An unchecked type conversion is considered to be an object if
6222 -- the operand is an object (this construction arises only as a
6223 -- result of expansion activities).
6225 when N_Unchecked_Type_Conversion =>
6232 end Is_Object_Reference;
6234 -----------------------------------
6235 -- Is_OK_Variable_For_Out_Formal --
6236 -----------------------------------
6238 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6240 Note_Possible_Modification (AV, Sure => True);
6242 -- We must reject parenthesized variable names. The check for
6243 -- Comes_From_Source is present because there are currently
6244 -- cases where the compiler violates this rule (e.g. passing
6245 -- a task object to its controlled Initialize routine).
6247 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6250 -- A variable is always allowed
6252 elsif Is_Variable (AV) then
6255 -- Unchecked conversions are allowed only if they come from the
6256 -- generated code, which sometimes uses unchecked conversions for out
6257 -- parameters in cases where code generation is unaffected. We tell
6258 -- source unchecked conversions by seeing if they are rewrites of an
6259 -- original Unchecked_Conversion function call, or of an explicit
6260 -- conversion of a function call.
6262 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6263 if Nkind (Original_Node (AV)) = N_Function_Call then
6266 elsif Comes_From_Source (AV)
6267 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6271 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6272 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6278 -- Normal type conversions are allowed if argument is a variable
6280 elsif Nkind (AV) = N_Type_Conversion then
6281 if Is_Variable (Expression (AV))
6282 and then Paren_Count (Expression (AV)) = 0
6284 Note_Possible_Modification (Expression (AV), Sure => True);
6287 -- We also allow a non-parenthesized expression that raises
6288 -- constraint error if it rewrites what used to be a variable
6290 elsif Raises_Constraint_Error (Expression (AV))
6291 and then Paren_Count (Expression (AV)) = 0
6292 and then Is_Variable (Original_Node (Expression (AV)))
6296 -- Type conversion of something other than a variable
6302 -- If this node is rewritten, then test the original form, if that is
6303 -- OK, then we consider the rewritten node OK (for example, if the
6304 -- original node is a conversion, then Is_Variable will not be true
6305 -- but we still want to allow the conversion if it converts a variable).
6307 elsif Original_Node (AV) /= AV then
6308 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6310 -- All other non-variables are rejected
6315 end Is_OK_Variable_For_Out_Formal;
6317 -----------------------------------
6318 -- Is_Partially_Initialized_Type --
6319 -----------------------------------
6321 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6323 if Is_Scalar_Type (Typ) then
6326 elsif Is_Access_Type (Typ) then
6329 elsif Is_Array_Type (Typ) then
6331 -- If component type is partially initialized, so is array type
6333 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6336 -- Otherwise we are only partially initialized if we are fully
6337 -- initialized (this is the empty array case, no point in us
6338 -- duplicating that code here).
6341 return Is_Fully_Initialized_Type (Typ);
6344 elsif Is_Record_Type (Typ) then
6346 -- A discriminated type is always partially initialized
6348 if Has_Discriminants (Typ) then
6351 -- A tagged type is always partially initialized
6353 elsif Is_Tagged_Type (Typ) then
6356 -- Case of non-discriminated record
6362 Component_Present : Boolean := False;
6363 -- Set True if at least one component is present. If no
6364 -- components are present, then record type is fully
6365 -- initialized (another odd case, like the null array).
6368 -- Loop through components
6370 Ent := First_Entity (Typ);
6371 while Present (Ent) loop
6372 if Ekind (Ent) = E_Component then
6373 Component_Present := True;
6375 -- If a component has an initialization expression then
6376 -- the enclosing record type is partially initialized
6378 if Present (Parent (Ent))
6379 and then Present (Expression (Parent (Ent)))
6383 -- If a component is of a type which is itself partially
6384 -- initialized, then the enclosing record type is also.
6386 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6394 -- No initialized components found. If we found any components
6395 -- they were all uninitialized so the result is false.
6397 if Component_Present then
6400 -- But if we found no components, then all the components are
6401 -- initialized so we consider the type to be initialized.
6409 -- Concurrent types are always fully initialized
6411 elsif Is_Concurrent_Type (Typ) then
6414 -- For a private type, go to underlying type. If there is no underlying
6415 -- type then just assume this partially initialized. Not clear if this
6416 -- can happen in a non-error case, but no harm in testing for this.
6418 elsif Is_Private_Type (Typ) then
6420 U : constant Entity_Id := Underlying_Type (Typ);
6425 return Is_Partially_Initialized_Type (U);
6429 -- For any other type (are there any?) assume partially initialized
6434 end Is_Partially_Initialized_Type;
6436 ------------------------------------
6437 -- Is_Potentially_Persistent_Type --
6438 ------------------------------------
6440 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6445 -- For private type, test corresponding full type
6447 if Is_Private_Type (T) then
6448 return Is_Potentially_Persistent_Type (Full_View (T));
6450 -- Scalar types are potentially persistent
6452 elsif Is_Scalar_Type (T) then
6455 -- Record type is potentially persistent if not tagged and the types of
6456 -- all it components are potentially persistent, and no component has
6457 -- an initialization expression.
6459 elsif Is_Record_Type (T)
6460 and then not Is_Tagged_Type (T)
6461 and then not Is_Partially_Initialized_Type (T)
6463 Comp := First_Component (T);
6464 while Present (Comp) loop
6465 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6474 -- Array type is potentially persistent if its component type is
6475 -- potentially persistent and if all its constraints are static.
6477 elsif Is_Array_Type (T) then
6478 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6482 Indx := First_Index (T);
6483 while Present (Indx) loop
6484 if not Is_OK_Static_Subtype (Etype (Indx)) then
6493 -- All other types are not potentially persistent
6498 end Is_Potentially_Persistent_Type;
6500 ---------------------------------
6501 -- Is_Protected_Self_Reference --
6502 ---------------------------------
6504 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6506 function In_Access_Definition (N : Node_Id) return Boolean;
6507 -- Returns true if N belongs to an access definition
6509 --------------------------
6510 -- In_Access_Definition --
6511 --------------------------
6513 function In_Access_Definition (N : Node_Id) return Boolean is
6518 while Present (P) loop
6519 if Nkind (P) = N_Access_Definition then
6527 end In_Access_Definition;
6529 -- Start of processing for Is_Protected_Self_Reference
6532 -- Verify that prefix is analyzed and has the proper form. Note that
6533 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6534 -- produce the address of an entity, do not analyze their prefix
6535 -- because they denote entities that are not necessarily visible.
6536 -- Neither of them can apply to a protected type.
6538 return Ada_Version >= Ada_05
6539 and then Is_Entity_Name (N)
6540 and then Present (Entity (N))
6541 and then Is_Protected_Type (Entity (N))
6542 and then In_Open_Scopes (Entity (N))
6543 and then not In_Access_Definition (N);
6544 end Is_Protected_Self_Reference;
6546 -----------------------------
6547 -- Is_RCI_Pkg_Spec_Or_Body --
6548 -----------------------------
6550 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6552 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6553 -- Return True if the unit of Cunit is an RCI package declaration
6555 ---------------------------
6556 -- Is_RCI_Pkg_Decl_Cunit --
6557 ---------------------------
6559 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6560 The_Unit : constant Node_Id := Unit (Cunit);
6563 if Nkind (The_Unit) /= N_Package_Declaration then
6567 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6568 end Is_RCI_Pkg_Decl_Cunit;
6570 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6573 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6575 (Nkind (Unit (Cunit)) = N_Package_Body
6576 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6577 end Is_RCI_Pkg_Spec_Or_Body;
6579 -----------------------------------------
6580 -- Is_Remote_Access_To_Class_Wide_Type --
6581 -----------------------------------------
6583 function Is_Remote_Access_To_Class_Wide_Type
6584 (E : Entity_Id) return Boolean
6587 -- A remote access to class-wide type is a general access to object type
6588 -- declared in the visible part of a Remote_Types or Remote_Call_
6591 return Ekind (E) = E_General_Access_Type
6592 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6593 end Is_Remote_Access_To_Class_Wide_Type;
6595 -----------------------------------------
6596 -- Is_Remote_Access_To_Subprogram_Type --
6597 -----------------------------------------
6599 function Is_Remote_Access_To_Subprogram_Type
6600 (E : Entity_Id) return Boolean
6603 return (Ekind (E) = E_Access_Subprogram_Type
6604 or else (Ekind (E) = E_Record_Type
6605 and then Present (Corresponding_Remote_Type (E))))
6606 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6607 end Is_Remote_Access_To_Subprogram_Type;
6609 --------------------
6610 -- Is_Remote_Call --
6611 --------------------
6613 function Is_Remote_Call (N : Node_Id) return Boolean is
6615 if Nkind (N) /= N_Procedure_Call_Statement
6616 and then Nkind (N) /= N_Function_Call
6618 -- An entry call cannot be remote
6622 elsif Nkind (Name (N)) in N_Has_Entity
6623 and then Is_Remote_Call_Interface (Entity (Name (N)))
6625 -- A subprogram declared in the spec of a RCI package is remote
6629 elsif Nkind (Name (N)) = N_Explicit_Dereference
6630 and then Is_Remote_Access_To_Subprogram_Type
6631 (Etype (Prefix (Name (N))))
6633 -- The dereference of a RAS is a remote call
6637 elsif Present (Controlling_Argument (N))
6638 and then Is_Remote_Access_To_Class_Wide_Type
6639 (Etype (Controlling_Argument (N)))
6641 -- Any primitive operation call with a controlling argument of
6642 -- a RACW type is a remote call.
6647 -- All other calls are local calls
6652 ----------------------
6653 -- Is_Renamed_Entry --
6654 ----------------------
6656 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6657 Orig_Node : Node_Id := Empty;
6658 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6660 function Is_Entry (Nam : Node_Id) return Boolean;
6661 -- Determine whether Nam is an entry. Traverse selectors if there are
6662 -- nested selected components.
6668 function Is_Entry (Nam : Node_Id) return Boolean is
6670 if Nkind (Nam) = N_Selected_Component then
6671 return Is_Entry (Selector_Name (Nam));
6674 return Ekind (Entity (Nam)) = E_Entry;
6677 -- Start of processing for Is_Renamed_Entry
6680 if Present (Alias (Proc_Nam)) then
6681 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6684 -- Look for a rewritten subprogram renaming declaration
6686 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6687 and then Present (Original_Node (Subp_Decl))
6689 Orig_Node := Original_Node (Subp_Decl);
6692 -- The rewritten subprogram is actually an entry
6694 if Present (Orig_Node)
6695 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6696 and then Is_Entry (Name (Orig_Node))
6702 end Is_Renamed_Entry;
6704 ----------------------
6705 -- Is_Selector_Name --
6706 ----------------------
6708 function Is_Selector_Name (N : Node_Id) return Boolean is
6710 if not Is_List_Member (N) then
6712 P : constant Node_Id := Parent (N);
6713 K : constant Node_Kind := Nkind (P);
6716 (K = N_Expanded_Name or else
6717 K = N_Generic_Association or else
6718 K = N_Parameter_Association or else
6719 K = N_Selected_Component)
6720 and then Selector_Name (P) = N;
6725 L : constant List_Id := List_Containing (N);
6726 P : constant Node_Id := Parent (L);
6728 return (Nkind (P) = N_Discriminant_Association
6729 and then Selector_Names (P) = L)
6731 (Nkind (P) = N_Component_Association
6732 and then Choices (P) = L);
6735 end Is_Selector_Name;
6741 function Is_Statement (N : Node_Id) return Boolean is
6744 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6745 or else Nkind (N) = N_Procedure_Call_Statement;
6748 ---------------------------------
6749 -- Is_Synchronized_Tagged_Type --
6750 ---------------------------------
6752 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6753 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6756 -- A task or protected type derived from an interface is a tagged type.
6757 -- Such a tagged type is called a synchronized tagged type, as are
6758 -- synchronized interfaces and private extensions whose declaration
6759 -- includes the reserved word synchronized.
6761 return (Is_Tagged_Type (E)
6762 and then (Kind = E_Task_Type
6763 or else Kind = E_Protected_Type))
6766 and then Is_Synchronized_Interface (E))
6768 (Ekind (E) = E_Record_Type_With_Private
6769 and then (Synchronized_Present (Parent (E))
6770 or else Is_Synchronized_Interface (Etype (E))));
6771 end Is_Synchronized_Tagged_Type;
6777 function Is_Transfer (N : Node_Id) return Boolean is
6778 Kind : constant Node_Kind := Nkind (N);
6781 if Kind = N_Simple_Return_Statement
6783 Kind = N_Extended_Return_Statement
6785 Kind = N_Goto_Statement
6787 Kind = N_Raise_Statement
6789 Kind = N_Requeue_Statement
6793 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6794 and then No (Condition (N))
6798 elsif Kind = N_Procedure_Call_Statement
6799 and then Is_Entity_Name (Name (N))
6800 and then Present (Entity (Name (N)))
6801 and then No_Return (Entity (Name (N)))
6805 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6817 function Is_True (U : Uint) return Boolean is
6826 function Is_Value_Type (T : Entity_Id) return Boolean is
6828 return VM_Target = CLI_Target
6829 and then Chars (T) /= No_Name
6830 and then Get_Name_String (Chars (T)) = "valuetype";
6837 function Is_Variable (N : Node_Id) return Boolean is
6839 Orig_Node : constant Node_Id := Original_Node (N);
6840 -- We do the test on the original node, since this is basically a
6841 -- test of syntactic categories, so it must not be disturbed by
6842 -- whatever rewriting might have occurred. For example, an aggregate,
6843 -- which is certainly NOT a variable, could be turned into a variable
6846 function In_Protected_Function (E : Entity_Id) return Boolean;
6847 -- Within a protected function, the private components of the
6848 -- enclosing protected type are constants. A function nested within
6849 -- a (protected) procedure is not itself protected.
6851 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6852 -- Prefixes can involve implicit dereferences, in which case we
6853 -- must test for the case of a reference of a constant access
6854 -- type, which can never be a variable.
6856 ---------------------------
6857 -- In_Protected_Function --
6858 ---------------------------
6860 function In_Protected_Function (E : Entity_Id) return Boolean is
6861 Prot : constant Entity_Id := Scope (E);
6865 if not Is_Protected_Type (Prot) then
6869 while Present (S) and then S /= Prot loop
6870 if Ekind (S) = E_Function
6871 and then Scope (S) = Prot
6881 end In_Protected_Function;
6883 ------------------------
6884 -- Is_Variable_Prefix --
6885 ------------------------
6887 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6889 if Is_Access_Type (Etype (P)) then
6890 return not Is_Access_Constant (Root_Type (Etype (P)));
6892 -- For the case of an indexed component whose prefix has a packed
6893 -- array type, the prefix has been rewritten into a type conversion.
6894 -- Determine variable-ness from the converted expression.
6896 elsif Nkind (P) = N_Type_Conversion
6897 and then not Comes_From_Source (P)
6898 and then Is_Array_Type (Etype (P))
6899 and then Is_Packed (Etype (P))
6901 return Is_Variable (Expression (P));
6904 return Is_Variable (P);
6906 end Is_Variable_Prefix;
6908 -- Start of processing for Is_Variable
6911 -- Definitely OK if Assignment_OK is set. Since this is something that
6912 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6914 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6917 -- Normally we go to the original node, but there is one exception
6918 -- where we use the rewritten node, namely when it is an explicit
6919 -- dereference. The generated code may rewrite a prefix which is an
6920 -- access type with an explicit dereference. The dereference is a
6921 -- variable, even though the original node may not be (since it could
6922 -- be a constant of the access type).
6924 -- In Ada 2005 we have a further case to consider: the prefix may be
6925 -- a function call given in prefix notation. The original node appears
6926 -- to be a selected component, but we need to examine the call.
6928 elsif Nkind (N) = N_Explicit_Dereference
6929 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6930 and then Present (Etype (Orig_Node))
6931 and then Is_Access_Type (Etype (Orig_Node))
6933 -- Note that if the prefix is an explicit dereference that does not
6934 -- come from source, we must check for a rewritten function call in
6935 -- prefixed notation before other forms of rewriting, to prevent a
6939 (Nkind (Orig_Node) = N_Function_Call
6940 and then not Is_Access_Constant (Etype (Prefix (N))))
6942 Is_Variable_Prefix (Original_Node (Prefix (N)));
6944 -- A function call is never a variable
6946 elsif Nkind (N) = N_Function_Call then
6949 -- All remaining checks use the original node
6951 elsif Is_Entity_Name (Orig_Node)
6952 and then Present (Entity (Orig_Node))
6955 E : constant Entity_Id := Entity (Orig_Node);
6956 K : constant Entity_Kind := Ekind (E);
6959 return (K = E_Variable
6960 and then Nkind (Parent (E)) /= N_Exception_Handler)
6961 or else (K = E_Component
6962 and then not In_Protected_Function (E))
6963 or else K = E_Out_Parameter
6964 or else K = E_In_Out_Parameter
6965 or else K = E_Generic_In_Out_Parameter
6967 -- Current instance of type:
6969 or else (Is_Type (E) and then In_Open_Scopes (E))
6970 or else (Is_Incomplete_Or_Private_Type (E)
6971 and then In_Open_Scopes (Full_View (E)));
6975 case Nkind (Orig_Node) is
6976 when N_Indexed_Component | N_Slice =>
6977 return Is_Variable_Prefix (Prefix (Orig_Node));
6979 when N_Selected_Component =>
6980 return Is_Variable_Prefix (Prefix (Orig_Node))
6981 and then Is_Variable (Selector_Name (Orig_Node));
6983 -- For an explicit dereference, the type of the prefix cannot
6984 -- be an access to constant or an access to subprogram.
6986 when N_Explicit_Dereference =>
6988 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6990 return Is_Access_Type (Typ)
6991 and then not Is_Access_Constant (Root_Type (Typ))
6992 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6995 -- The type conversion is the case where we do not deal with the
6996 -- context dependent special case of an actual parameter. Thus
6997 -- the type conversion is only considered a variable for the
6998 -- purposes of this routine if the target type is tagged. However,
6999 -- a type conversion is considered to be a variable if it does not
7000 -- come from source (this deals for example with the conversions
7001 -- of expressions to their actual subtypes).
7003 when N_Type_Conversion =>
7004 return Is_Variable (Expression (Orig_Node))
7006 (not Comes_From_Source (Orig_Node)
7008 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7010 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7012 -- GNAT allows an unchecked type conversion as a variable. This
7013 -- only affects the generation of internal expanded code, since
7014 -- calls to instantiations of Unchecked_Conversion are never
7015 -- considered variables (since they are function calls).
7016 -- This is also true for expression actions.
7018 when N_Unchecked_Type_Conversion =>
7019 return Is_Variable (Expression (Orig_Node));
7027 ------------------------
7028 -- Is_Volatile_Object --
7029 ------------------------
7031 function Is_Volatile_Object (N : Node_Id) return Boolean is
7033 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7034 -- Determines if given object has volatile components
7036 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7037 -- If prefix is an implicit dereference, examine designated type
7039 ------------------------
7040 -- Is_Volatile_Prefix --
7041 ------------------------
7043 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7044 Typ : constant Entity_Id := Etype (N);
7047 if Is_Access_Type (Typ) then
7049 Dtyp : constant Entity_Id := Designated_Type (Typ);
7052 return Is_Volatile (Dtyp)
7053 or else Has_Volatile_Components (Dtyp);
7057 return Object_Has_Volatile_Components (N);
7059 end Is_Volatile_Prefix;
7061 ------------------------------------
7062 -- Object_Has_Volatile_Components --
7063 ------------------------------------
7065 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7066 Typ : constant Entity_Id := Etype (N);
7069 if Is_Volatile (Typ)
7070 or else Has_Volatile_Components (Typ)
7074 elsif Is_Entity_Name (N)
7075 and then (Has_Volatile_Components (Entity (N))
7076 or else Is_Volatile (Entity (N)))
7080 elsif Nkind (N) = N_Indexed_Component
7081 or else Nkind (N) = N_Selected_Component
7083 return Is_Volatile_Prefix (Prefix (N));
7088 end Object_Has_Volatile_Components;
7090 -- Start of processing for Is_Volatile_Object
7093 if Is_Volatile (Etype (N))
7094 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7098 elsif Nkind (N) = N_Indexed_Component
7099 or else Nkind (N) = N_Selected_Component
7101 return Is_Volatile_Prefix (Prefix (N));
7106 end Is_Volatile_Object;
7108 -------------------------
7109 -- Kill_Current_Values --
7110 -------------------------
7112 procedure Kill_Current_Values
7114 Last_Assignment_Only : Boolean := False)
7117 if Is_Assignable (Ent) then
7118 Set_Last_Assignment (Ent, Empty);
7121 if not Last_Assignment_Only and then Is_Object (Ent) then
7123 Set_Current_Value (Ent, Empty);
7125 if not Can_Never_Be_Null (Ent) then
7126 Set_Is_Known_Non_Null (Ent, False);
7129 Set_Is_Known_Null (Ent, False);
7131 end Kill_Current_Values;
7133 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7136 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7137 -- Clear current value for entity E and all entities chained to E
7139 ------------------------------------------
7140 -- Kill_Current_Values_For_Entity_Chain --
7141 ------------------------------------------
7143 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7147 while Present (Ent) loop
7148 Kill_Current_Values (Ent, Last_Assignment_Only);
7151 end Kill_Current_Values_For_Entity_Chain;
7153 -- Start of processing for Kill_Current_Values
7156 -- Kill all saved checks, a special case of killing saved values
7158 if not Last_Assignment_Only then
7162 -- Loop through relevant scopes, which includes the current scope and
7163 -- any parent scopes if the current scope is a block or a package.
7168 -- Clear current values of all entities in current scope
7170 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7172 -- If scope is a package, also clear current values of all
7173 -- private entities in the scope.
7175 if Is_Package_Or_Generic_Package (S)
7176 or else Is_Concurrent_Type (S)
7178 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7181 -- If this is a not a subprogram, deal with parents
7183 if not Is_Subprogram (S) then
7185 exit Scope_Loop when S = Standard_Standard;
7189 end loop Scope_Loop;
7190 end Kill_Current_Values;
7192 --------------------------
7193 -- Kill_Size_Check_Code --
7194 --------------------------
7196 procedure Kill_Size_Check_Code (E : Entity_Id) is
7198 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7199 and then Present (Size_Check_Code (E))
7201 Remove (Size_Check_Code (E));
7202 Set_Size_Check_Code (E, Empty);
7204 end Kill_Size_Check_Code;
7206 --------------------------
7207 -- Known_To_Be_Assigned --
7208 --------------------------
7210 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7211 P : constant Node_Id := Parent (N);
7216 -- Test left side of assignment
7218 when N_Assignment_Statement =>
7219 return N = Name (P);
7221 -- Function call arguments are never lvalues
7223 when N_Function_Call =>
7226 -- Positional parameter for procedure or accept call
7228 when N_Procedure_Call_Statement |
7237 Proc := Get_Subprogram_Entity (P);
7243 -- If we are not a list member, something is strange, so
7244 -- be conservative and return False.
7246 if not Is_List_Member (N) then
7250 -- We are going to find the right formal by stepping forward
7251 -- through the formals, as we step backwards in the actuals.
7253 Form := First_Formal (Proc);
7256 -- If no formal, something is weird, so be conservative
7257 -- and return False.
7268 return Ekind (Form) /= E_In_Parameter;
7271 -- Named parameter for procedure or accept call
7273 when N_Parameter_Association =>
7279 Proc := Get_Subprogram_Entity (Parent (P));
7285 -- Loop through formals to find the one that matches
7287 Form := First_Formal (Proc);
7289 -- If no matching formal, that's peculiar, some kind of
7290 -- previous error, so return False to be conservative.
7296 -- Else test for match
7298 if Chars (Form) = Chars (Selector_Name (P)) then
7299 return Ekind (Form) /= E_In_Parameter;
7306 -- Test for appearing in a conversion that itself appears
7307 -- in an lvalue context, since this should be an lvalue.
7309 when N_Type_Conversion =>
7310 return Known_To_Be_Assigned (P);
7312 -- All other references are definitely not known to be modifications
7318 end Known_To_Be_Assigned;
7324 function May_Be_Lvalue (N : Node_Id) return Boolean is
7325 P : constant Node_Id := Parent (N);
7330 -- Test left side of assignment
7332 when N_Assignment_Statement =>
7333 return N = Name (P);
7335 -- Test prefix of component or attribute. Note that the prefix of an
7336 -- explicit or implicit dereference cannot be an l-value.
7338 when N_Attribute_Reference =>
7339 return N = Prefix (P)
7340 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7342 -- For an expanded name, the name is an lvalue if the expanded name
7343 -- is an lvalue, but the prefix is never an lvalue, since it is just
7344 -- the scope where the name is found.
7346 when N_Expanded_Name =>
7347 if N = Prefix (P) then
7348 return May_Be_Lvalue (P);
7353 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7354 -- B is a little interesting, if we have A.B := 3, there is some
7355 -- discussion as to whether B is an lvalue or not, we choose to say
7356 -- it is. Note however that A is not an lvalue if it is of an access
7357 -- type since this is an implicit dereference.
7359 when N_Selected_Component =>
7361 and then Present (Etype (N))
7362 and then Is_Access_Type (Etype (N))
7366 return May_Be_Lvalue (P);
7369 -- For an indexed component or slice, the index or slice bounds is
7370 -- never an lvalue. The prefix is an lvalue if the indexed component
7371 -- or slice is an lvalue, except if it is an access type, where we
7372 -- have an implicit dereference.
7374 when N_Indexed_Component =>
7376 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7380 return May_Be_Lvalue (P);
7383 -- Prefix of a reference is an lvalue if the reference is an lvalue
7386 return May_Be_Lvalue (P);
7388 -- Prefix of explicit dereference is never an lvalue
7390 when N_Explicit_Dereference =>
7393 -- Function call arguments are never lvalues
7395 when N_Function_Call =>
7398 -- Positional parameter for procedure, entry, or accept call
7400 when N_Procedure_Call_Statement |
7401 N_Entry_Call_Statement |
7410 Proc := Get_Subprogram_Entity (P);
7416 -- If we are not a list member, something is strange, so
7417 -- be conservative and return True.
7419 if not Is_List_Member (N) then
7423 -- We are going to find the right formal by stepping forward
7424 -- through the formals, as we step backwards in the actuals.
7426 Form := First_Formal (Proc);
7429 -- If no formal, something is weird, so be conservative
7441 return Ekind (Form) /= E_In_Parameter;
7444 -- Named parameter for procedure or accept call
7446 when N_Parameter_Association =>
7452 Proc := Get_Subprogram_Entity (Parent (P));
7458 -- Loop through formals to find the one that matches
7460 Form := First_Formal (Proc);
7462 -- If no matching formal, that's peculiar, some kind of
7463 -- previous error, so return True to be conservative.
7469 -- Else test for match
7471 if Chars (Form) = Chars (Selector_Name (P)) then
7472 return Ekind (Form) /= E_In_Parameter;
7479 -- Test for appearing in a conversion that itself appears in an
7480 -- lvalue context, since this should be an lvalue.
7482 when N_Type_Conversion =>
7483 return May_Be_Lvalue (P);
7485 -- Test for appearance in object renaming declaration
7487 when N_Object_Renaming_Declaration =>
7490 -- All other references are definitely not lvalues
7498 -----------------------
7499 -- Mark_Coextensions --
7500 -----------------------
7502 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7503 Is_Dynamic : Boolean;
7504 -- Indicates whether the context causes nested coextensions to be
7505 -- dynamic or static
7507 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7508 -- Recognize an allocator node and label it as a dynamic coextension
7510 --------------------
7511 -- Mark_Allocator --
7512 --------------------
7514 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7516 if Nkind (N) = N_Allocator then
7518 Set_Is_Dynamic_Coextension (N);
7520 Set_Is_Static_Coextension (N);
7527 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7529 -- Start of processing Mark_Coextensions
7532 case Nkind (Context_Nod) is
7533 when N_Assignment_Statement |
7534 N_Simple_Return_Statement =>
7535 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7537 when N_Object_Declaration =>
7538 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7540 -- This routine should not be called for constructs which may not
7541 -- contain coextensions.
7544 raise Program_Error;
7547 Mark_Allocators (Root_Nod);
7548 end Mark_Coextensions;
7550 ----------------------
7551 -- Needs_One_Actual --
7552 ----------------------
7554 function Needs_One_Actual (E : Entity_Id) return Boolean is
7558 if Ada_Version >= Ada_05
7559 and then Present (First_Formal (E))
7561 Formal := Next_Formal (First_Formal (E));
7562 while Present (Formal) loop
7563 if No (Default_Value (Formal)) then
7567 Next_Formal (Formal);
7575 end Needs_One_Actual;
7577 ------------------------
7578 -- New_Copy_List_Tree --
7579 ------------------------
7581 function New_Copy_List_Tree (List : List_Id) return List_Id is
7586 if List = No_List then
7593 while Present (E) loop
7594 Append (New_Copy_Tree (E), NL);
7600 end New_Copy_List_Tree;
7606 use Atree.Unchecked_Access;
7607 use Atree_Private_Part;
7609 -- Our approach here requires a two pass traversal of the tree. The
7610 -- first pass visits all nodes that eventually will be copied looking
7611 -- for defining Itypes. If any defining Itypes are found, then they are
7612 -- copied, and an entry is added to the replacement map. In the second
7613 -- phase, the tree is copied, using the replacement map to replace any
7614 -- Itype references within the copied tree.
7616 -- The following hash tables are used if the Map supplied has more
7617 -- than hash threshhold entries to speed up access to the map. If
7618 -- there are fewer entries, then the map is searched sequentially
7619 -- (because setting up a hash table for only a few entries takes
7620 -- more time than it saves.
7622 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7623 -- Hash function used for hash operations
7629 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7631 return Nat (E) mod (NCT_Header_Num'Last + 1);
7638 -- The hash table NCT_Assoc associates old entities in the table
7639 -- with their corresponding new entities (i.e. the pairs of entries
7640 -- presented in the original Map argument are Key-Element pairs).
7642 package NCT_Assoc is new Simple_HTable (
7643 Header_Num => NCT_Header_Num,
7644 Element => Entity_Id,
7645 No_Element => Empty,
7647 Hash => New_Copy_Hash,
7648 Equal => Types."=");
7650 ---------------------
7651 -- NCT_Itype_Assoc --
7652 ---------------------
7654 -- The hash table NCT_Itype_Assoc contains entries only for those
7655 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7656 -- The key is the associated node, and the element is the new node
7657 -- itself (NOT the associated node for the new node).
7659 package NCT_Itype_Assoc is new Simple_HTable (
7660 Header_Num => NCT_Header_Num,
7661 Element => Entity_Id,
7662 No_Element => Empty,
7664 Hash => New_Copy_Hash,
7665 Equal => Types."=");
7667 -- Start of processing for New_Copy_Tree function
7669 function New_Copy_Tree
7671 Map : Elist_Id := No_Elist;
7672 New_Sloc : Source_Ptr := No_Location;
7673 New_Scope : Entity_Id := Empty) return Node_Id
7675 Actual_Map : Elist_Id := Map;
7676 -- This is the actual map for the copy. It is initialized with the
7677 -- given elements, and then enlarged as required for Itypes that are
7678 -- copied during the first phase of the copy operation. The visit
7679 -- procedures add elements to this map as Itypes are encountered.
7680 -- The reason we cannot use Map directly, is that it may well be
7681 -- (and normally is) initialized to No_Elist, and if we have mapped
7682 -- entities, we have to reset it to point to a real Elist.
7684 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
7685 -- Called during second phase to map entities into their corresponding
7686 -- copies using Actual_Map. If the argument is not an entity, or is not
7687 -- in Actual_Map, then it is returned unchanged.
7689 procedure Build_NCT_Hash_Tables;
7690 -- Builds hash tables (number of elements >= threshold value)
7692 function Copy_Elist_With_Replacement
7693 (Old_Elist : Elist_Id) return Elist_Id;
7694 -- Called during second phase to copy element list doing replacements
7696 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
7697 -- Called during the second phase to process a copied Itype. The actual
7698 -- copy happened during the first phase (so that we could make the entry
7699 -- in the mapping), but we still have to deal with the descendents of
7700 -- the copied Itype and copy them where necessary.
7702 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
7703 -- Called during second phase to copy list doing replacements
7705 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
7706 -- Called during second phase to copy node doing replacements
7708 procedure Visit_Elist (E : Elist_Id);
7709 -- Called during first phase to visit all elements of an Elist
7711 procedure Visit_Field (F : Union_Id; N : Node_Id);
7712 -- Visit a single field, recursing to call Visit_Node or Visit_List
7713 -- if the field is a syntactic descendent of the current node (i.e.
7714 -- its parent is Node N).
7716 procedure Visit_Itype (Old_Itype : Entity_Id);
7717 -- Called during first phase to visit subsidiary fields of a defining
7718 -- Itype, and also create a copy and make an entry in the replacement
7719 -- map for the new copy.
7721 procedure Visit_List (L : List_Id);
7722 -- Called during first phase to visit all elements of a List
7724 procedure Visit_Node (N : Node_Or_Entity_Id);
7725 -- Called during first phase to visit a node and all its subtrees
7731 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
7736 if not Has_Extension (N) or else No (Actual_Map) then
7739 elsif NCT_Hash_Tables_Used then
7740 Ent := NCT_Assoc.Get (Entity_Id (N));
7742 if Present (Ent) then
7748 -- No hash table used, do serial search
7751 E := First_Elmt (Actual_Map);
7752 while Present (E) loop
7753 if Node (E) = N then
7754 return Node (Next_Elmt (E));
7756 E := Next_Elmt (Next_Elmt (E));
7764 ---------------------------
7765 -- Build_NCT_Hash_Tables --
7766 ---------------------------
7768 procedure Build_NCT_Hash_Tables is
7772 if NCT_Hash_Table_Setup then
7774 NCT_Itype_Assoc.Reset;
7777 Elmt := First_Elmt (Actual_Map);
7778 while Present (Elmt) loop
7781 -- Get new entity, and associate old and new
7784 NCT_Assoc.Set (Ent, Node (Elmt));
7786 if Is_Type (Ent) then
7788 Anode : constant Entity_Id :=
7789 Associated_Node_For_Itype (Ent);
7792 if Present (Anode) then
7794 -- Enter a link between the associated node of the
7795 -- old Itype and the new Itype, for updating later
7796 -- when node is copied.
7798 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
7806 NCT_Hash_Tables_Used := True;
7807 NCT_Hash_Table_Setup := True;
7808 end Build_NCT_Hash_Tables;
7810 ---------------------------------
7811 -- Copy_Elist_With_Replacement --
7812 ---------------------------------
7814 function Copy_Elist_With_Replacement
7815 (Old_Elist : Elist_Id) return Elist_Id
7818 New_Elist : Elist_Id;
7821 if No (Old_Elist) then
7825 New_Elist := New_Elmt_List;
7827 M := First_Elmt (Old_Elist);
7828 while Present (M) loop
7829 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
7835 end Copy_Elist_With_Replacement;
7837 ---------------------------------
7838 -- Copy_Itype_With_Replacement --
7839 ---------------------------------
7841 -- This routine exactly parallels its phase one analog Visit_Itype,
7843 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
7845 -- Translate Next_Entity, Scope and Etype fields, in case they
7846 -- reference entities that have been mapped into copies.
7848 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
7849 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
7851 if Present (New_Scope) then
7852 Set_Scope (New_Itype, New_Scope);
7854 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
7857 -- Copy referenced fields
7859 if Is_Discrete_Type (New_Itype) then
7860 Set_Scalar_Range (New_Itype,
7861 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
7863 elsif Has_Discriminants (Base_Type (New_Itype)) then
7864 Set_Discriminant_Constraint (New_Itype,
7865 Copy_Elist_With_Replacement
7866 (Discriminant_Constraint (New_Itype)));
7868 elsif Is_Array_Type (New_Itype) then
7869 if Present (First_Index (New_Itype)) then
7870 Set_First_Index (New_Itype,
7871 First (Copy_List_With_Replacement
7872 (List_Containing (First_Index (New_Itype)))));
7875 if Is_Packed (New_Itype) then
7876 Set_Packed_Array_Type (New_Itype,
7877 Copy_Node_With_Replacement
7878 (Packed_Array_Type (New_Itype)));
7881 end Copy_Itype_With_Replacement;
7883 --------------------------------
7884 -- Copy_List_With_Replacement --
7885 --------------------------------
7887 function Copy_List_With_Replacement
7888 (Old_List : List_Id) return List_Id
7894 if Old_List = No_List then
7898 New_List := Empty_List;
7900 E := First (Old_List);
7901 while Present (E) loop
7902 Append (Copy_Node_With_Replacement (E), New_List);
7908 end Copy_List_With_Replacement;
7910 --------------------------------
7911 -- Copy_Node_With_Replacement --
7912 --------------------------------
7914 function Copy_Node_With_Replacement
7915 (Old_Node : Node_Id) return Node_Id
7919 procedure Adjust_Named_Associations
7920 (Old_Node : Node_Id;
7921 New_Node : Node_Id);
7922 -- If a call node has named associations, these are chained through
7923 -- the First_Named_Actual, Next_Named_Actual links. These must be
7924 -- propagated separately to the new parameter list, because these
7925 -- are not syntactic fields.
7927 function Copy_Field_With_Replacement
7928 (Field : Union_Id) return Union_Id;
7929 -- Given Field, which is a field of Old_Node, return a copy of it
7930 -- if it is a syntactic field (i.e. its parent is Node), setting
7931 -- the parent of the copy to poit to New_Node. Otherwise returns
7932 -- the field (possibly mapped if it is an entity).
7934 -------------------------------
7935 -- Adjust_Named_Associations --
7936 -------------------------------
7938 procedure Adjust_Named_Associations
7939 (Old_Node : Node_Id;
7949 Old_E := First (Parameter_Associations (Old_Node));
7950 New_E := First (Parameter_Associations (New_Node));
7951 while Present (Old_E) loop
7952 if Nkind (Old_E) = N_Parameter_Association
7953 and then Present (Next_Named_Actual (Old_E))
7955 if First_Named_Actual (Old_Node)
7956 = Explicit_Actual_Parameter (Old_E)
7958 Set_First_Named_Actual
7959 (New_Node, Explicit_Actual_Parameter (New_E));
7962 -- Now scan parameter list from the beginning,to locate
7963 -- next named actual, which can be out of order.
7965 Old_Next := First (Parameter_Associations (Old_Node));
7966 New_Next := First (Parameter_Associations (New_Node));
7968 while Nkind (Old_Next) /= N_Parameter_Association
7969 or else Explicit_Actual_Parameter (Old_Next)
7970 /= Next_Named_Actual (Old_E)
7976 Set_Next_Named_Actual
7977 (New_E, Explicit_Actual_Parameter (New_Next));
7983 end Adjust_Named_Associations;
7985 ---------------------------------
7986 -- Copy_Field_With_Replacement --
7987 ---------------------------------
7989 function Copy_Field_With_Replacement
7990 (Field : Union_Id) return Union_Id
7993 if Field = Union_Id (Empty) then
7996 elsif Field in Node_Range then
7998 Old_N : constant Node_Id := Node_Id (Field);
8002 -- If syntactic field, as indicated by the parent pointer
8003 -- being set, then copy the referenced node recursively.
8005 if Parent (Old_N) = Old_Node then
8006 New_N := Copy_Node_With_Replacement (Old_N);
8008 if New_N /= Old_N then
8009 Set_Parent (New_N, New_Node);
8012 -- For semantic fields, update possible entity reference
8013 -- from the replacement map.
8016 New_N := Assoc (Old_N);
8019 return Union_Id (New_N);
8022 elsif Field in List_Range then
8024 Old_L : constant List_Id := List_Id (Field);
8028 -- If syntactic field, as indicated by the parent pointer,
8029 -- then recursively copy the entire referenced list.
8031 if Parent (Old_L) = Old_Node then
8032 New_L := Copy_List_With_Replacement (Old_L);
8033 Set_Parent (New_L, New_Node);
8035 -- For semantic list, just returned unchanged
8041 return Union_Id (New_L);
8044 -- Anything other than a list or a node is returned unchanged
8049 end Copy_Field_With_Replacement;
8051 -- Start of processing for Copy_Node_With_Replacement
8054 if Old_Node <= Empty_Or_Error then
8057 elsif Has_Extension (Old_Node) then
8058 return Assoc (Old_Node);
8061 New_Node := New_Copy (Old_Node);
8063 -- If the node we are copying is the associated node of a
8064 -- previously copied Itype, then adjust the associated node
8065 -- of the copy of that Itype accordingly.
8067 if Present (Actual_Map) then
8073 -- Case of hash table used
8075 if NCT_Hash_Tables_Used then
8076 Ent := NCT_Itype_Assoc.Get (Old_Node);
8078 if Present (Ent) then
8079 Set_Associated_Node_For_Itype (Ent, New_Node);
8082 -- Case of no hash table used
8085 E := First_Elmt (Actual_Map);
8086 while Present (E) loop
8087 if Is_Itype (Node (E))
8089 Old_Node = Associated_Node_For_Itype (Node (E))
8091 Set_Associated_Node_For_Itype
8092 (Node (Next_Elmt (E)), New_Node);
8095 E := Next_Elmt (Next_Elmt (E));
8101 -- Recursively copy descendents
8104 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8106 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8108 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8110 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8112 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8114 -- Adjust Sloc of new node if necessary
8116 if New_Sloc /= No_Location then
8117 Set_Sloc (New_Node, New_Sloc);
8119 -- If we adjust the Sloc, then we are essentially making
8120 -- a completely new node, so the Comes_From_Source flag
8121 -- should be reset to the proper default value.
8123 Nodes.Table (New_Node).Comes_From_Source :=
8124 Default_Node.Comes_From_Source;
8127 -- If the node is call and has named associations,
8128 -- set the corresponding links in the copy.
8130 if (Nkind (Old_Node) = N_Function_Call
8131 or else Nkind (Old_Node) = N_Entry_Call_Statement
8133 Nkind (Old_Node) = N_Procedure_Call_Statement)
8134 and then Present (First_Named_Actual (Old_Node))
8136 Adjust_Named_Associations (Old_Node, New_Node);
8139 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8140 -- The replacement mechanism applies to entities, and is not used
8141 -- here. Eventually we may need a more general graph-copying
8142 -- routine. For now, do a sequential search to find desired node.
8144 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8145 and then Present (First_Real_Statement (Old_Node))
8148 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8152 N1 := First (Statements (Old_Node));
8153 N2 := First (Statements (New_Node));
8155 while N1 /= Old_F loop
8160 Set_First_Real_Statement (New_Node, N2);
8165 -- All done, return copied node
8168 end Copy_Node_With_Replacement;
8174 procedure Visit_Elist (E : Elist_Id) is
8178 Elmt := First_Elmt (E);
8180 while Elmt /= No_Elmt loop
8181 Visit_Node (Node (Elmt));
8191 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8193 if F = Union_Id (Empty) then
8196 elsif F in Node_Range then
8198 -- Copy node if it is syntactic, i.e. its parent pointer is
8199 -- set to point to the field that referenced it (certain
8200 -- Itypes will also meet this criterion, which is fine, since
8201 -- these are clearly Itypes that do need to be copied, since
8202 -- we are copying their parent.)
8204 if Parent (Node_Id (F)) = N then
8205 Visit_Node (Node_Id (F));
8208 -- Another case, if we are pointing to an Itype, then we want
8209 -- to copy it if its associated node is somewhere in the tree
8212 -- Note: the exclusion of self-referential copies is just an
8213 -- optimization, since the search of the already copied list
8214 -- would catch it, but it is a common case (Etype pointing
8215 -- to itself for an Itype that is a base type).
8217 elsif Has_Extension (Node_Id (F))
8218 and then Is_Itype (Entity_Id (F))
8219 and then Node_Id (F) /= N
8225 P := Associated_Node_For_Itype (Node_Id (F));
8226 while Present (P) loop
8228 Visit_Node (Node_Id (F));
8235 -- An Itype whose parent is not being copied definitely
8236 -- should NOT be copied, since it does not belong in any
8237 -- sense to the copied subtree.
8243 elsif F in List_Range
8244 and then Parent (List_Id (F)) = N
8246 Visit_List (List_Id (F));
8255 procedure Visit_Itype (Old_Itype : Entity_Id) is
8256 New_Itype : Entity_Id;
8261 -- Itypes that describe the designated type of access to subprograms
8262 -- have the structure of subprogram declarations, with signatures,
8263 -- etc. Either we duplicate the signatures completely, or choose to
8264 -- share such itypes, which is fine because their elaboration will
8265 -- have no side effects.
8267 if Ekind (Old_Itype) = E_Subprogram_Type then
8271 New_Itype := New_Copy (Old_Itype);
8273 -- The new Itype has all the attributes of the old one, and
8274 -- we just copy the contents of the entity. However, the back-end
8275 -- needs different names for debugging purposes, so we create a
8276 -- new internal name for it in all cases.
8278 Set_Chars (New_Itype, New_Internal_Name ('T'));
8280 -- If our associated node is an entity that has already been copied,
8281 -- then set the associated node of the copy to point to the right
8282 -- copy. If we have copied an Itype that is itself the associated
8283 -- node of some previously copied Itype, then we set the right
8284 -- pointer in the other direction.
8286 if Present (Actual_Map) then
8288 -- Case of hash tables used
8290 if NCT_Hash_Tables_Used then
8292 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8294 if Present (Ent) then
8295 Set_Associated_Node_For_Itype (New_Itype, Ent);
8298 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8299 if Present (Ent) then
8300 Set_Associated_Node_For_Itype (Ent, New_Itype);
8302 -- If the hash table has no association for this Itype and
8303 -- its associated node, enter one now.
8307 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8310 -- Case of hash tables not used
8313 E := First_Elmt (Actual_Map);
8314 while Present (E) loop
8315 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8316 Set_Associated_Node_For_Itype
8317 (New_Itype, Node (Next_Elmt (E)));
8320 if Is_Type (Node (E))
8322 Old_Itype = Associated_Node_For_Itype (Node (E))
8324 Set_Associated_Node_For_Itype
8325 (Node (Next_Elmt (E)), New_Itype);
8328 E := Next_Elmt (Next_Elmt (E));
8333 if Present (Freeze_Node (New_Itype)) then
8334 Set_Is_Frozen (New_Itype, False);
8335 Set_Freeze_Node (New_Itype, Empty);
8338 -- Add new association to map
8340 if No (Actual_Map) then
8341 Actual_Map := New_Elmt_List;
8344 Append_Elmt (Old_Itype, Actual_Map);
8345 Append_Elmt (New_Itype, Actual_Map);
8347 if NCT_Hash_Tables_Used then
8348 NCT_Assoc.Set (Old_Itype, New_Itype);
8351 NCT_Table_Entries := NCT_Table_Entries + 1;
8353 if NCT_Table_Entries > NCT_Hash_Threshhold then
8354 Build_NCT_Hash_Tables;
8358 -- If a record subtype is simply copied, the entity list will be
8359 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8361 if Ekind (Old_Itype) = E_Record_Subtype
8362 or else Ekind (Old_Itype) = E_Class_Wide_Subtype
8364 Set_Cloned_Subtype (New_Itype, Old_Itype);
8367 -- Visit descendents that eventually get copied
8369 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8371 if Is_Discrete_Type (Old_Itype) then
8372 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8374 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8375 -- ??? This should involve call to Visit_Field
8376 Visit_Elist (Discriminant_Constraint (Old_Itype));
8378 elsif Is_Array_Type (Old_Itype) then
8379 if Present (First_Index (Old_Itype)) then
8380 Visit_Field (Union_Id (List_Containing
8381 (First_Index (Old_Itype))),
8385 if Is_Packed (Old_Itype) then
8386 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8396 procedure Visit_List (L : List_Id) is
8399 if L /= No_List then
8402 while Present (N) loop
8413 procedure Visit_Node (N : Node_Or_Entity_Id) is
8415 -- Start of processing for Visit_Node
8418 -- Handle case of an Itype, which must be copied
8420 if Has_Extension (N)
8421 and then Is_Itype (N)
8423 -- Nothing to do if already in the list. This can happen with an
8424 -- Itype entity that appears more than once in the tree.
8425 -- Note that we do not want to visit descendents in this case.
8427 -- Test for already in list when hash table is used
8429 if NCT_Hash_Tables_Used then
8430 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8434 -- Test for already in list when hash table not used
8440 if Present (Actual_Map) then
8441 E := First_Elmt (Actual_Map);
8442 while Present (E) loop
8443 if Node (E) = N then
8446 E := Next_Elmt (Next_Elmt (E));
8456 -- Visit descendents
8458 Visit_Field (Field1 (N), N);
8459 Visit_Field (Field2 (N), N);
8460 Visit_Field (Field3 (N), N);
8461 Visit_Field (Field4 (N), N);
8462 Visit_Field (Field5 (N), N);
8465 -- Start of processing for New_Copy_Tree
8470 -- See if we should use hash table
8472 if No (Actual_Map) then
8473 NCT_Hash_Tables_Used := False;
8480 NCT_Table_Entries := 0;
8482 Elmt := First_Elmt (Actual_Map);
8483 while Present (Elmt) loop
8484 NCT_Table_Entries := NCT_Table_Entries + 1;
8489 if NCT_Table_Entries > NCT_Hash_Threshhold then
8490 Build_NCT_Hash_Tables;
8492 NCT_Hash_Tables_Used := False;
8497 -- Hash table set up if required, now start phase one by visiting
8498 -- top node (we will recursively visit the descendents).
8500 Visit_Node (Source);
8502 -- Now the second phase of the copy can start. First we process
8503 -- all the mapped entities, copying their descendents.
8505 if Present (Actual_Map) then
8508 New_Itype : Entity_Id;
8510 Elmt := First_Elmt (Actual_Map);
8511 while Present (Elmt) loop
8513 New_Itype := Node (Elmt);
8514 Copy_Itype_With_Replacement (New_Itype);
8520 -- Now we can copy the actual tree
8522 return Copy_Node_With_Replacement (Source);
8525 -------------------------
8526 -- New_External_Entity --
8527 -------------------------
8529 function New_External_Entity
8530 (Kind : Entity_Kind;
8531 Scope_Id : Entity_Id;
8532 Sloc_Value : Source_Ptr;
8533 Related_Id : Entity_Id;
8535 Suffix_Index : Nat := 0;
8536 Prefix : Character := ' ') return Entity_Id
8538 N : constant Entity_Id :=
8539 Make_Defining_Identifier (Sloc_Value,
8541 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8544 Set_Ekind (N, Kind);
8545 Set_Is_Internal (N, True);
8546 Append_Entity (N, Scope_Id);
8547 Set_Public_Status (N);
8549 if Kind in Type_Kind then
8550 Init_Size_Align (N);
8554 end New_External_Entity;
8556 -------------------------
8557 -- New_Internal_Entity --
8558 -------------------------
8560 function New_Internal_Entity
8561 (Kind : Entity_Kind;
8562 Scope_Id : Entity_Id;
8563 Sloc_Value : Source_Ptr;
8564 Id_Char : Character) return Entity_Id
8566 N : constant Entity_Id :=
8567 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
8570 Set_Ekind (N, Kind);
8571 Set_Is_Internal (N, True);
8572 Append_Entity (N, Scope_Id);
8574 if Kind in Type_Kind then
8575 Init_Size_Align (N);
8579 end New_Internal_Entity;
8585 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8589 -- If we are pointing at a positional parameter, it is a member of a
8590 -- node list (the list of parameters), and the next parameter is the
8591 -- next node on the list, unless we hit a parameter association, then
8592 -- we shift to using the chain whose head is the First_Named_Actual in
8593 -- the parent, and then is threaded using the Next_Named_Actual of the
8594 -- Parameter_Association. All this fiddling is because the original node
8595 -- list is in the textual call order, and what we need is the
8596 -- declaration order.
8598 if Is_List_Member (Actual_Id) then
8599 N := Next (Actual_Id);
8601 if Nkind (N) = N_Parameter_Association then
8602 return First_Named_Actual (Parent (Actual_Id));
8608 return Next_Named_Actual (Parent (Actual_Id));
8612 procedure Next_Actual (Actual_Id : in out Node_Id) is
8614 Actual_Id := Next_Actual (Actual_Id);
8617 -----------------------
8618 -- Normalize_Actuals --
8619 -----------------------
8621 -- Chain actuals according to formals of subprogram. If there are no named
8622 -- associations, the chain is simply the list of Parameter Associations,
8623 -- since the order is the same as the declaration order. If there are named
8624 -- associations, then the First_Named_Actual field in the N_Function_Call
8625 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8626 -- node for the parameter that comes first in declaration order. The
8627 -- remaining named parameters are then chained in declaration order using
8628 -- Next_Named_Actual.
8630 -- This routine also verifies that the number of actuals is compatible with
8631 -- the number and default values of formals, but performs no type checking
8632 -- (type checking is done by the caller).
8634 -- If the matching succeeds, Success is set to True and the caller proceeds
8635 -- with type-checking. If the match is unsuccessful, then Success is set to
8636 -- False, and the caller attempts a different interpretation, if there is
8639 -- If the flag Report is on, the call is not overloaded, and a failure to
8640 -- match can be reported here, rather than in the caller.
8642 procedure Normalize_Actuals
8646 Success : out Boolean)
8648 Actuals : constant List_Id := Parameter_Associations (N);
8649 Actual : Node_Id := Empty;
8651 Last : Node_Id := Empty;
8652 First_Named : Node_Id := Empty;
8655 Formals_To_Match : Integer := 0;
8656 Actuals_To_Match : Integer := 0;
8658 procedure Chain (A : Node_Id);
8659 -- Add named actual at the proper place in the list, using the
8660 -- Next_Named_Actual link.
8662 function Reporting return Boolean;
8663 -- Determines if an error is to be reported. To report an error, we
8664 -- need Report to be True, and also we do not report errors caused
8665 -- by calls to init procs that occur within other init procs. Such
8666 -- errors must always be cascaded errors, since if all the types are
8667 -- declared correctly, the compiler will certainly build decent calls!
8673 procedure Chain (A : Node_Id) is
8677 -- Call node points to first actual in list
8679 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
8682 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
8686 Set_Next_Named_Actual (Last, Empty);
8693 function Reporting return Boolean is
8698 elsif not Within_Init_Proc then
8701 elsif Is_Init_Proc (Entity (Name (N))) then
8709 -- Start of processing for Normalize_Actuals
8712 if Is_Access_Type (S) then
8714 -- The name in the call is a function call that returns an access
8715 -- to subprogram. The designated type has the list of formals.
8717 Formal := First_Formal (Designated_Type (S));
8719 Formal := First_Formal (S);
8722 while Present (Formal) loop
8723 Formals_To_Match := Formals_To_Match + 1;
8724 Next_Formal (Formal);
8727 -- Find if there is a named association, and verify that no positional
8728 -- associations appear after named ones.
8730 if Present (Actuals) then
8731 Actual := First (Actuals);
8734 while Present (Actual)
8735 and then Nkind (Actual) /= N_Parameter_Association
8737 Actuals_To_Match := Actuals_To_Match + 1;
8741 if No (Actual) and Actuals_To_Match = Formals_To_Match then
8743 -- Most common case: positional notation, no defaults
8748 elsif Actuals_To_Match > Formals_To_Match then
8750 -- Too many actuals: will not work
8753 if Is_Entity_Name (Name (N)) then
8754 Error_Msg_N ("too many arguments in call to&", Name (N));
8756 Error_Msg_N ("too many arguments in call", N);
8764 First_Named := Actual;
8766 while Present (Actual) loop
8767 if Nkind (Actual) /= N_Parameter_Association then
8769 ("positional parameters not allowed after named ones", Actual);
8774 Actuals_To_Match := Actuals_To_Match + 1;
8780 if Present (Actuals) then
8781 Actual := First (Actuals);
8784 Formal := First_Formal (S);
8785 while Present (Formal) loop
8787 -- Match the formals in order. If the corresponding actual is
8788 -- positional, nothing to do. Else scan the list of named actuals
8789 -- to find the one with the right name.
8792 and then Nkind (Actual) /= N_Parameter_Association
8795 Actuals_To_Match := Actuals_To_Match - 1;
8796 Formals_To_Match := Formals_To_Match - 1;
8799 -- For named parameters, search the list of actuals to find
8800 -- one that matches the next formal name.
8802 Actual := First_Named;
8804 while Present (Actual) loop
8805 if Chars (Selector_Name (Actual)) = Chars (Formal) then
8808 Actuals_To_Match := Actuals_To_Match - 1;
8809 Formals_To_Match := Formals_To_Match - 1;
8817 if Ekind (Formal) /= E_In_Parameter
8818 or else No (Default_Value (Formal))
8821 if (Comes_From_Source (S)
8822 or else Sloc (S) = Standard_Location)
8823 and then Is_Overloadable (S)
8827 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8829 (Nkind (Parent (N)) = N_Function_Call
8831 Nkind (Parent (N)) = N_Parameter_Association))
8832 and then Ekind (S) /= E_Function
8834 Set_Etype (N, Etype (S));
8836 Error_Msg_Name_1 := Chars (S);
8837 Error_Msg_Sloc := Sloc (S);
8839 ("missing argument for parameter & " &
8840 "in call to % declared #", N, Formal);
8843 elsif Is_Overloadable (S) then
8844 Error_Msg_Name_1 := Chars (S);
8846 -- Point to type derivation that generated the
8849 Error_Msg_Sloc := Sloc (Parent (S));
8852 ("missing argument for parameter & " &
8853 "in call to % (inherited) #", N, Formal);
8857 ("missing argument for parameter &", N, Formal);
8865 Formals_To_Match := Formals_To_Match - 1;
8870 Next_Formal (Formal);
8873 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8880 -- Find some superfluous named actual that did not get
8881 -- attached to the list of associations.
8883 Actual := First (Actuals);
8884 while Present (Actual) loop
8885 if Nkind (Actual) = N_Parameter_Association
8886 and then Actual /= Last
8887 and then No (Next_Named_Actual (Actual))
8889 Error_Msg_N ("unmatched actual & in call",
8890 Selector_Name (Actual));
8901 end Normalize_Actuals;
8903 --------------------------------
8904 -- Note_Possible_Modification --
8905 --------------------------------
8907 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8908 Modification_Comes_From_Source : constant Boolean :=
8909 Comes_From_Source (Parent (N));
8915 -- Loop to find referenced entity, if there is one
8922 if Is_Entity_Name (Exp) then
8923 Ent := Entity (Exp);
8925 -- If the entity is missing, it is an undeclared identifier,
8926 -- and there is nothing to annotate.
8932 elsif Nkind (Exp) = N_Explicit_Dereference then
8934 P : constant Node_Id := Prefix (Exp);
8937 if Nkind (P) = N_Selected_Component
8939 Entry_Formal (Entity (Selector_Name (P))))
8941 -- Case of a reference to an entry formal
8943 Ent := Entry_Formal (Entity (Selector_Name (P)));
8945 elsif Nkind (P) = N_Identifier
8946 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
8947 and then Present (Expression (Parent (Entity (P))))
8948 and then Nkind (Expression (Parent (Entity (P))))
8951 -- Case of a reference to a value on which side effects have
8954 Exp := Prefix (Expression (Parent (Entity (P))));
8963 elsif Nkind (Exp) = N_Type_Conversion
8964 or else Nkind (Exp) = N_Unchecked_Type_Conversion
8966 Exp := Expression (Exp);
8969 elsif Nkind (Exp) = N_Slice
8970 or else Nkind (Exp) = N_Indexed_Component
8971 or else Nkind (Exp) = N_Selected_Component
8973 Exp := Prefix (Exp);
8980 -- Now look for entity being referenced
8982 if Present (Ent) then
8983 if Is_Object (Ent) then
8984 if Comes_From_Source (Exp)
8985 or else Modification_Comes_From_Source
8987 if Has_Pragma_Unmodified (Ent) then
8988 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
8991 Set_Never_Set_In_Source (Ent, False);
8994 Set_Is_True_Constant (Ent, False);
8995 Set_Current_Value (Ent, Empty);
8996 Set_Is_Known_Null (Ent, False);
8998 if not Can_Never_Be_Null (Ent) then
8999 Set_Is_Known_Non_Null (Ent, False);
9002 -- Follow renaming chain
9004 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9005 and then Present (Renamed_Object (Ent))
9007 Exp := Renamed_Object (Ent);
9011 -- Generate a reference only if the assignment comes from
9012 -- source. This excludes, for example, calls to a dispatching
9013 -- assignment operation when the left-hand side is tagged.
9015 if Modification_Comes_From_Source then
9016 Generate_Reference (Ent, Exp, 'm');
9019 Check_Nested_Access (Ent);
9024 -- If we are sure this is a modification from source, and we know
9025 -- this modifies a constant, then give an appropriate warning.
9027 if Overlays_Constant (Ent)
9028 and then Modification_Comes_From_Source
9032 A : constant Node_Id := Address_Clause (Ent);
9036 Exp : constant Node_Id := Expression (A);
9038 if Nkind (Exp) = N_Attribute_Reference
9039 and then Attribute_Name (Exp) = Name_Address
9040 and then Is_Entity_Name (Prefix (Exp))
9042 Error_Msg_Sloc := Sloc (A);
9044 ("constant& may be modified via address clause#?",
9045 N, Entity (Prefix (Exp)));
9055 end Note_Possible_Modification;
9057 -------------------------
9058 -- Object_Access_Level --
9059 -------------------------
9061 function Object_Access_Level (Obj : Node_Id) return Uint is
9064 -- Returns the static accessibility level of the view denoted by Obj. Note
9065 -- that the value returned is the result of a call to Scope_Depth. Only
9066 -- scope depths associated with dynamic scopes can actually be returned.
9067 -- Since only relative levels matter for accessibility checking, the fact
9068 -- that the distance between successive levels of accessibility is not
9069 -- always one is immaterial (invariant: if level(E2) is deeper than
9070 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9072 function Reference_To (Obj : Node_Id) return Node_Id;
9073 -- An explicit dereference is created when removing side-effects from
9074 -- expressions for constraint checking purposes. In this case a local
9075 -- access type is created for it. The correct access level is that of
9076 -- the original source node. We detect this case by noting that the
9077 -- prefix of the dereference is created by an object declaration whose
9078 -- initial expression is a reference.
9084 function Reference_To (Obj : Node_Id) return Node_Id is
9085 Pref : constant Node_Id := Prefix (Obj);
9087 if Is_Entity_Name (Pref)
9088 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9089 and then Present (Expression (Parent (Entity (Pref))))
9090 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9092 return (Prefix (Expression (Parent (Entity (Pref)))));
9098 -- Start of processing for Object_Access_Level
9101 if Is_Entity_Name (Obj) then
9104 if Is_Prival (E) then
9105 E := Prival_Link (E);
9108 -- If E is a type then it denotes a current instance. For this case
9109 -- we add one to the normal accessibility level of the type to ensure
9110 -- that current instances are treated as always being deeper than
9111 -- than the level of any visible named access type (see 3.10.2(21)).
9114 return Type_Access_Level (E) + 1;
9116 elsif Present (Renamed_Object (E)) then
9117 return Object_Access_Level (Renamed_Object (E));
9119 -- Similarly, if E is a component of the current instance of a
9120 -- protected type, any instance of it is assumed to be at a deeper
9121 -- level than the type. For a protected object (whose type is an
9122 -- anonymous protected type) its components are at the same level
9123 -- as the type itself.
9125 elsif not Is_Overloadable (E)
9126 and then Ekind (Scope (E)) = E_Protected_Type
9127 and then Comes_From_Source (Scope (E))
9129 return Type_Access_Level (Scope (E)) + 1;
9132 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9135 elsif Nkind (Obj) = N_Selected_Component then
9136 if Is_Access_Type (Etype (Prefix (Obj))) then
9137 return Type_Access_Level (Etype (Prefix (Obj)));
9139 return Object_Access_Level (Prefix (Obj));
9142 elsif Nkind (Obj) = N_Indexed_Component then
9143 if Is_Access_Type (Etype (Prefix (Obj))) then
9144 return Type_Access_Level (Etype (Prefix (Obj)));
9146 return Object_Access_Level (Prefix (Obj));
9149 elsif Nkind (Obj) = N_Explicit_Dereference then
9151 -- If the prefix is a selected access discriminant then we make a
9152 -- recursive call on the prefix, which will in turn check the level
9153 -- of the prefix object of the selected discriminant.
9155 if Nkind (Prefix (Obj)) = N_Selected_Component
9156 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9158 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9160 return Object_Access_Level (Prefix (Obj));
9162 elsif not (Comes_From_Source (Obj)) then
9164 Ref : constant Node_Id := Reference_To (Obj);
9166 if Present (Ref) then
9167 return Object_Access_Level (Ref);
9169 return Type_Access_Level (Etype (Prefix (Obj)));
9174 return Type_Access_Level (Etype (Prefix (Obj)));
9177 elsif Nkind (Obj) = N_Type_Conversion
9178 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9180 return Object_Access_Level (Expression (Obj));
9182 -- Function results are objects, so we get either the access level of
9183 -- the function or, in the case of an indirect call, the level of the
9184 -- access-to-subprogram type.
9186 elsif Nkind (Obj) = N_Function_Call then
9187 if Is_Entity_Name (Name (Obj)) then
9188 return Subprogram_Access_Level (Entity (Name (Obj)));
9190 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9193 -- For convenience we handle qualified expressions, even though
9194 -- they aren't technically object names.
9196 elsif Nkind (Obj) = N_Qualified_Expression then
9197 return Object_Access_Level (Expression (Obj));
9199 -- Otherwise return the scope level of Standard.
9200 -- (If there are cases that fall through
9201 -- to this point they will be treated as
9202 -- having global accessibility for now. ???)
9205 return Scope_Depth (Standard_Standard);
9207 end Object_Access_Level;
9209 -----------------------
9210 -- Private_Component --
9211 -----------------------
9213 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9214 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9216 function Trace_Components
9218 Check : Boolean) return Entity_Id;
9219 -- Recursive function that does the work, and checks against circular
9220 -- definition for each subcomponent type.
9222 ----------------------
9223 -- Trace_Components --
9224 ----------------------
9226 function Trace_Components
9228 Check : Boolean) return Entity_Id
9230 Btype : constant Entity_Id := Base_Type (T);
9231 Component : Entity_Id;
9233 Candidate : Entity_Id := Empty;
9236 if Check and then Btype = Ancestor then
9237 Error_Msg_N ("circular type definition", Type_Id);
9241 if Is_Private_Type (Btype)
9242 and then not Is_Generic_Type (Btype)
9244 if Present (Full_View (Btype))
9245 and then Is_Record_Type (Full_View (Btype))
9246 and then not Is_Frozen (Btype)
9248 -- To indicate that the ancestor depends on a private type, the
9249 -- current Btype is sufficient. However, to check for circular
9250 -- definition we must recurse on the full view.
9252 Candidate := Trace_Components (Full_View (Btype), True);
9254 if Candidate = Any_Type then
9264 elsif Is_Array_Type (Btype) then
9265 return Trace_Components (Component_Type (Btype), True);
9267 elsif Is_Record_Type (Btype) then
9268 Component := First_Entity (Btype);
9269 while Present (Component) loop
9271 -- Skip anonymous types generated by constrained components
9273 if not Is_Type (Component) then
9274 P := Trace_Components (Etype (Component), True);
9277 if P = Any_Type then
9285 Next_Entity (Component);
9293 end Trace_Components;
9295 -- Start of processing for Private_Component
9298 return Trace_Components (Type_Id, False);
9299 end Private_Component;
9301 ---------------------------
9302 -- Primitive_Names_Match --
9303 ---------------------------
9305 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9307 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9308 -- Given an internal name, returns the corresponding non-internal name
9310 ------------------------
9311 -- Non_Internal_Name --
9312 ------------------------
9314 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9316 Get_Name_String (Chars (E));
9317 Name_Len := Name_Len - 1;
9319 end Non_Internal_Name;
9321 -- Start of processing for Primitive_Names_Match
9324 pragma Assert (Present (E1) and then Present (E2));
9326 return Chars (E1) = Chars (E2)
9328 (not Is_Internal_Name (Chars (E1))
9329 and then Is_Internal_Name (Chars (E2))
9330 and then Non_Internal_Name (E2) = Chars (E1))
9332 (not Is_Internal_Name (Chars (E2))
9333 and then Is_Internal_Name (Chars (E1))
9334 and then Non_Internal_Name (E1) = Chars (E2))
9336 (Is_Predefined_Dispatching_Operation (E1)
9337 and then Is_Predefined_Dispatching_Operation (E2)
9338 and then Same_TSS (E1, E2))
9340 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9341 end Primitive_Names_Match;
9343 -----------------------
9344 -- Process_End_Label --
9345 -----------------------
9347 procedure Process_End_Label
9356 Label_Ref : Boolean;
9357 -- Set True if reference to end label itself is required
9360 -- Gets set to the operator symbol or identifier that references the
9361 -- entity Ent. For the child unit case, this is the identifier from the
9362 -- designator. For other cases, this is simply Endl.
9364 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9365 -- N is an identifier node that appears as a parent unit reference in
9366 -- the case where Ent is a child unit. This procedure generates an
9367 -- appropriate cross-reference entry. E is the corresponding entity.
9369 -------------------------
9370 -- Generate_Parent_Ref --
9371 -------------------------
9373 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9375 -- If names do not match, something weird, skip reference
9377 if Chars (E) = Chars (N) then
9379 -- Generate the reference. We do NOT consider this as a reference
9380 -- for unreferenced symbol purposes.
9382 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9385 Style.Check_Identifier (N, E);
9388 end Generate_Parent_Ref;
9390 -- Start of processing for Process_End_Label
9393 -- If no node, ignore. This happens in some error situations, and
9394 -- also for some internally generated structures where no end label
9395 -- references are required in any case.
9401 -- Nothing to do if no End_Label, happens for internally generated
9402 -- constructs where we don't want an end label reference anyway. Also
9403 -- nothing to do if Endl is a string literal, which means there was
9404 -- some prior error (bad operator symbol)
9406 Endl := End_Label (N);
9408 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9412 -- Reference node is not in extended main source unit
9414 if not In_Extended_Main_Source_Unit (N) then
9416 -- Generally we do not collect references except for the extended
9417 -- main source unit. The one exception is the 'e' entry for a
9418 -- package spec, where it is useful for a client to have the
9419 -- ending information to define scopes.
9427 -- For this case, we can ignore any parent references, but we
9428 -- need the package name itself for the 'e' entry.
9430 if Nkind (Endl) = N_Designator then
9431 Endl := Identifier (Endl);
9435 -- Reference is in extended main source unit
9440 -- For designator, generate references for the parent entries
9442 if Nkind (Endl) = N_Designator then
9444 -- Generate references for the prefix if the END line comes from
9445 -- source (otherwise we do not need these references) We climb the
9446 -- scope stack to find the expected entities.
9448 if Comes_From_Source (Endl) then
9450 Scop := Current_Scope;
9451 while Nkind (Nam) = N_Selected_Component loop
9452 Scop := Scope (Scop);
9453 exit when No (Scop);
9454 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9455 Nam := Prefix (Nam);
9458 if Present (Scop) then
9459 Generate_Parent_Ref (Nam, Scope (Scop));
9463 Endl := Identifier (Endl);
9467 -- If the end label is not for the given entity, then either we have
9468 -- some previous error, or this is a generic instantiation for which
9469 -- we do not need to make a cross-reference in this case anyway. In
9470 -- either case we simply ignore the call.
9472 if Chars (Ent) /= Chars (Endl) then
9476 -- If label was really there, then generate a normal reference and then
9477 -- adjust the location in the end label to point past the name (which
9478 -- should almost always be the semicolon).
9482 if Comes_From_Source (Endl) then
9484 -- If a label reference is required, then do the style check and
9485 -- generate an l-type cross-reference entry for the label
9489 Style.Check_Identifier (Endl, Ent);
9492 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9495 -- Set the location to point past the label (normally this will
9496 -- mean the semicolon immediately following the label). This is
9497 -- done for the sake of the 'e' or 't' entry generated below.
9499 Get_Decoded_Name_String (Chars (Endl));
9500 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9503 -- Now generate the e/t reference
9505 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9507 -- Restore Sloc, in case modified above, since we have an identifier
9508 -- and the normal Sloc should be left set in the tree.
9510 Set_Sloc (Endl, Loc);
9511 end Process_End_Label;
9517 -- We do the conversion to get the value of the real string by using
9518 -- the scanner, see Sinput for details on use of the internal source
9519 -- buffer for scanning internal strings.
9521 function Real_Convert (S : String) return Node_Id is
9522 Save_Src : constant Source_Buffer_Ptr := Source;
9526 Source := Internal_Source_Ptr;
9529 for J in S'Range loop
9530 Source (Source_Ptr (J)) := S (J);
9533 Source (S'Length + 1) := EOF;
9535 if Source (Scan_Ptr) = '-' then
9537 Scan_Ptr := Scan_Ptr + 1;
9545 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9552 ------------------------------------
9553 -- References_Generic_Formal_Type --
9554 ------------------------------------
9556 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
9558 function Process (N : Node_Id) return Traverse_Result;
9559 -- Process one node in search for generic formal type
9565 function Process (N : Node_Id) return Traverse_Result is
9567 if Nkind (N) in N_Has_Entity then
9569 E : constant Entity_Id := Entity (N);
9572 if Is_Generic_Type (E) then
9574 elsif Present (Etype (E))
9575 and then Is_Generic_Type (Etype (E))
9586 function Traverse is new Traverse_Func (Process);
9587 -- Traverse tree to look for generic type
9590 if Inside_A_Generic then
9591 return Traverse (N) = Abandon;
9595 end References_Generic_Formal_Type;
9597 --------------------
9598 -- Remove_Homonym --
9599 --------------------
9601 procedure Remove_Homonym (E : Entity_Id) is
9602 Prev : Entity_Id := Empty;
9606 if E = Current_Entity (E) then
9607 if Present (Homonym (E)) then
9608 Set_Current_Entity (Homonym (E));
9610 Set_Name_Entity_Id (Chars (E), Empty);
9613 H := Current_Entity (E);
9614 while Present (H) and then H /= E loop
9619 Set_Homonym (Prev, Homonym (E));
9623 ---------------------
9624 -- Rep_To_Pos_Flag --
9625 ---------------------
9627 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
9629 return New_Occurrence_Of
9630 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
9631 end Rep_To_Pos_Flag;
9633 --------------------
9634 -- Require_Entity --
9635 --------------------
9637 procedure Require_Entity (N : Node_Id) is
9639 if Is_Entity_Name (N) and then No (Entity (N)) then
9640 if Total_Errors_Detected /= 0 then
9641 Set_Entity (N, Any_Id);
9643 raise Program_Error;
9648 ------------------------------
9649 -- Requires_Transient_Scope --
9650 ------------------------------
9652 -- A transient scope is required when variable-sized temporaries are
9653 -- allocated in the primary or secondary stack, or when finalization
9654 -- actions must be generated before the next instruction.
9656 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
9657 Typ : constant Entity_Id := Underlying_Type (Id);
9659 -- Start of processing for Requires_Transient_Scope
9662 -- This is a private type which is not completed yet. This can only
9663 -- happen in a default expression (of a formal parameter or of a
9664 -- record component). Do not expand transient scope in this case
9669 -- Do not expand transient scope for non-existent procedure return
9671 elsif Typ = Standard_Void_Type then
9674 -- Elementary types do not require a transient scope
9676 elsif Is_Elementary_Type (Typ) then
9679 -- Generally, indefinite subtypes require a transient scope, since the
9680 -- back end cannot generate temporaries, since this is not a valid type
9681 -- for declaring an object. It might be possible to relax this in the
9682 -- future, e.g. by declaring the maximum possible space for the type.
9684 elsif Is_Indefinite_Subtype (Typ) then
9687 -- Functions returning tagged types may dispatch on result so their
9688 -- returned value is allocated on the secondary stack. Controlled
9689 -- type temporaries need finalization.
9691 elsif Is_Tagged_Type (Typ)
9692 or else Has_Controlled_Component (Typ)
9694 return not Is_Value_Type (Typ);
9698 elsif Is_Record_Type (Typ) then
9702 Comp := First_Entity (Typ);
9703 while Present (Comp) loop
9704 if Ekind (Comp) = E_Component
9705 and then Requires_Transient_Scope (Etype (Comp))
9716 -- String literal types never require transient scope
9718 elsif Ekind (Typ) = E_String_Literal_Subtype then
9721 -- Array type. Note that we already know that this is a constrained
9722 -- array, since unconstrained arrays will fail the indefinite test.
9724 elsif Is_Array_Type (Typ) then
9726 -- If component type requires a transient scope, the array does too
9728 if Requires_Transient_Scope (Component_Type (Typ)) then
9731 -- Otherwise, we only need a transient scope if the size is not
9732 -- known at compile time.
9735 return not Size_Known_At_Compile_Time (Typ);
9738 -- All other cases do not require a transient scope
9743 end Requires_Transient_Scope;
9745 --------------------------
9746 -- Reset_Analyzed_Flags --
9747 --------------------------
9749 procedure Reset_Analyzed_Flags (N : Node_Id) is
9751 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
9752 -- Function used to reset Analyzed flags in tree. Note that we do
9753 -- not reset Analyzed flags in entities, since there is no need to
9754 -- reanalyze entities, and indeed, it is wrong to do so, since it
9755 -- can result in generating auxiliary stuff more than once.
9757 --------------------
9758 -- Clear_Analyzed --
9759 --------------------
9761 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
9763 if not Has_Extension (N) then
9764 Set_Analyzed (N, False);
9770 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
9772 -- Start of processing for Reset_Analyzed_Flags
9776 end Reset_Analyzed_Flags;
9778 ---------------------------
9779 -- Safe_To_Capture_Value --
9780 ---------------------------
9782 function Safe_To_Capture_Value
9785 Cond : Boolean := False) return Boolean
9788 -- The only entities for which we track constant values are variables
9789 -- which are not renamings, constants, out parameters, and in out
9790 -- parameters, so check if we have this case.
9792 -- Note: it may seem odd to track constant values for constants, but in
9793 -- fact this routine is used for other purposes than simply capturing
9794 -- the value. In particular, the setting of Known[_Non]_Null.
9796 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
9798 Ekind (Ent) = E_Constant
9800 Ekind (Ent) = E_Out_Parameter
9802 Ekind (Ent) = E_In_Out_Parameter
9806 -- For conditionals, we also allow loop parameters and all formals,
9807 -- including in parameters.
9811 (Ekind (Ent) = E_Loop_Parameter
9813 Ekind (Ent) = E_In_Parameter)
9817 -- For all other cases, not just unsafe, but impossible to capture
9818 -- Current_Value, since the above are the only entities which have
9819 -- Current_Value fields.
9825 -- Skip if volatile or aliased, since funny things might be going on in
9826 -- these cases which we cannot necessarily track. Also skip any variable
9827 -- for which an address clause is given, or whose address is taken. Also
9828 -- never capture value of library level variables (an attempt to do so
9829 -- can occur in the case of package elaboration code).
9831 if Treat_As_Volatile (Ent)
9832 or else Is_Aliased (Ent)
9833 or else Present (Address_Clause (Ent))
9834 or else Address_Taken (Ent)
9835 or else (Is_Library_Level_Entity (Ent)
9836 and then Ekind (Ent) = E_Variable)
9841 -- OK, all above conditions are met. We also require that the scope of
9842 -- the reference be the same as the scope of the entity, not counting
9843 -- packages and blocks and loops.
9846 E_Scope : constant Entity_Id := Scope (Ent);
9847 R_Scope : Entity_Id;
9850 R_Scope := Current_Scope;
9851 while R_Scope /= Standard_Standard loop
9852 exit when R_Scope = E_Scope;
9854 if Ekind (R_Scope) /= E_Package
9856 Ekind (R_Scope) /= E_Block
9858 Ekind (R_Scope) /= E_Loop
9862 R_Scope := Scope (R_Scope);
9867 -- We also require that the reference does not appear in a context
9868 -- where it is not sure to be executed (i.e. a conditional context
9869 -- or an exception handler). We skip this if Cond is True, since the
9870 -- capturing of values from conditional tests handles this ok.
9884 while Present (P) loop
9885 if Nkind (P) = N_If_Statement
9886 or else Nkind (P) = N_Case_Statement
9887 or else (Nkind (P) in N_Short_Circuit
9888 and then Desc = Right_Opnd (P))
9889 or else (Nkind (P) = N_Conditional_Expression
9890 and then Desc /= First (Expressions (P)))
9891 or else Nkind (P) = N_Exception_Handler
9892 or else Nkind (P) = N_Selective_Accept
9893 or else Nkind (P) = N_Conditional_Entry_Call
9894 or else Nkind (P) = N_Timed_Entry_Call
9895 or else Nkind (P) = N_Asynchronous_Select
9905 -- OK, looks safe to set value
9908 end Safe_To_Capture_Value;
9914 function Same_Name (N1, N2 : Node_Id) return Boolean is
9915 K1 : constant Node_Kind := Nkind (N1);
9916 K2 : constant Node_Kind := Nkind (N2);
9919 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
9920 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
9922 return Chars (N1) = Chars (N2);
9924 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
9925 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
9927 return Same_Name (Selector_Name (N1), Selector_Name (N2))
9928 and then Same_Name (Prefix (N1), Prefix (N2));
9939 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9940 N1 : constant Node_Id := Original_Node (Node1);
9941 N2 : constant Node_Id := Original_Node (Node2);
9942 -- We do the tests on original nodes, since we are most interested
9943 -- in the original source, not any expansion that got in the way.
9945 K1 : constant Node_Kind := Nkind (N1);
9946 K2 : constant Node_Kind := Nkind (N2);
9949 -- First case, both are entities with same entity
9951 if K1 in N_Has_Entity
9952 and then K2 in N_Has_Entity
9953 and then Present (Entity (N1))
9954 and then Present (Entity (N2))
9955 and then (Ekind (Entity (N1)) = E_Variable
9957 Ekind (Entity (N1)) = E_Constant)
9958 and then Entity (N1) = Entity (N2)
9962 -- Second case, selected component with same selector, same record
9964 elsif K1 = N_Selected_Component
9965 and then K2 = N_Selected_Component
9966 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
9968 return Same_Object (Prefix (N1), Prefix (N2));
9970 -- Third case, indexed component with same subscripts, same array
9972 elsif K1 = N_Indexed_Component
9973 and then K2 = N_Indexed_Component
9974 and then Same_Object (Prefix (N1), Prefix (N2))
9979 E1 := First (Expressions (N1));
9980 E2 := First (Expressions (N2));
9981 while Present (E1) loop
9982 if not Same_Value (E1, E2) then
9993 -- Fourth case, slice of same array with same bounds
9996 and then K2 = N_Slice
9997 and then Nkind (Discrete_Range (N1)) = N_Range
9998 and then Nkind (Discrete_Range (N2)) = N_Range
9999 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10000 Low_Bound (Discrete_Range (N2)))
10001 and then Same_Value (High_Bound (Discrete_Range (N1)),
10002 High_Bound (Discrete_Range (N2)))
10004 return Same_Name (Prefix (N1), Prefix (N2));
10006 -- All other cases, not clearly the same object
10017 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10022 elsif not Is_Constrained (T1)
10023 and then not Is_Constrained (T2)
10024 and then Base_Type (T1) = Base_Type (T2)
10028 -- For now don't bother with case of identical constraints, to be
10029 -- fiddled with later on perhaps (this is only used for optimization
10030 -- purposes, so it is not critical to do a best possible job)
10041 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10043 if Compile_Time_Known_Value (Node1)
10044 and then Compile_Time_Known_Value (Node2)
10045 and then Expr_Value (Node1) = Expr_Value (Node2)
10048 elsif Same_Object (Node1, Node2) then
10055 ------------------------
10056 -- Scope_Is_Transient --
10057 ------------------------
10059 function Scope_Is_Transient return Boolean is
10061 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10062 end Scope_Is_Transient;
10068 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10073 while Scop /= Standard_Standard loop
10074 Scop := Scope (Scop);
10076 if Scop = Scope2 then
10084 --------------------------
10085 -- Scope_Within_Or_Same --
10086 --------------------------
10088 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10093 while Scop /= Standard_Standard loop
10094 if Scop = Scope2 then
10097 Scop := Scope (Scop);
10102 end Scope_Within_Or_Same;
10104 --------------------
10105 -- Set_Convention --
10106 --------------------
10108 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10110 Basic_Set_Convention (E, Val);
10113 and then Is_Access_Subprogram_Type (Base_Type (E))
10114 and then Has_Foreign_Convention (E)
10116 Set_Can_Use_Internal_Rep (E, False);
10118 end Set_Convention;
10120 ------------------------
10121 -- Set_Current_Entity --
10122 ------------------------
10124 -- The given entity is to be set as the currently visible definition
10125 -- of its associated name (i.e. the Node_Id associated with its name).
10126 -- All we have to do is to get the name from the identifier, and
10127 -- then set the associated Node_Id to point to the given entity.
10129 procedure Set_Current_Entity (E : Entity_Id) is
10131 Set_Name_Entity_Id (Chars (E), E);
10132 end Set_Current_Entity;
10134 ---------------------------
10135 -- Set_Debug_Info_Needed --
10136 ---------------------------
10138 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10140 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10141 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10142 -- Used to set debug info in a related node if not set already
10144 --------------------------------------
10145 -- Set_Debug_Info_Needed_If_Not_Set --
10146 --------------------------------------
10148 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10151 and then not Needs_Debug_Info (E)
10153 Set_Debug_Info_Needed (E);
10155 -- For a private type, indicate that the full view also needs
10156 -- debug information.
10159 and then Is_Private_Type (E)
10160 and then Present (Full_View (E))
10162 Set_Debug_Info_Needed (Full_View (E));
10165 end Set_Debug_Info_Needed_If_Not_Set;
10167 -- Start of processing for Set_Debug_Info_Needed
10170 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10171 -- indicates that Debug_Info_Needed is never required for the entity.
10174 or else Debug_Info_Off (T)
10179 -- Set flag in entity itself. Note that we will go through the following
10180 -- circuitry even if the flag is already set on T. That's intentional,
10181 -- it makes sure that the flag will be set in subsidiary entities.
10183 Set_Needs_Debug_Info (T);
10185 -- Set flag on subsidiary entities if not set already
10187 if Is_Object (T) then
10188 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10190 elsif Is_Type (T) then
10191 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10193 if Is_Record_Type (T) then
10195 Ent : Entity_Id := First_Entity (T);
10197 while Present (Ent) loop
10198 Set_Debug_Info_Needed_If_Not_Set (Ent);
10203 elsif Is_Array_Type (T) then
10204 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10207 Indx : Node_Id := First_Index (T);
10209 while Present (Indx) loop
10210 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10211 Indx := Next_Index (Indx);
10215 if Is_Packed (T) then
10216 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10219 elsif Is_Access_Type (T) then
10220 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10222 elsif Is_Private_Type (T) then
10223 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10225 elsif Is_Protected_Type (T) then
10226 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10229 end Set_Debug_Info_Needed;
10231 ---------------------------------
10232 -- Set_Entity_With_Style_Check --
10233 ---------------------------------
10235 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10236 Val_Actual : Entity_Id;
10240 Set_Entity (N, Val);
10243 and then not Suppress_Style_Checks (Val)
10244 and then not In_Instance
10246 if Nkind (N) = N_Identifier then
10248 elsif Nkind (N) = N_Expanded_Name then
10249 Nod := Selector_Name (N);
10254 -- A special situation arises for derived operations, where we want
10255 -- to do the check against the parent (since the Sloc of the derived
10256 -- operation points to the derived type declaration itself).
10259 while not Comes_From_Source (Val_Actual)
10260 and then Nkind (Val_Actual) in N_Entity
10261 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10262 or else Is_Subprogram (Val_Actual)
10263 or else Is_Generic_Subprogram (Val_Actual))
10264 and then Present (Alias (Val_Actual))
10266 Val_Actual := Alias (Val_Actual);
10269 -- Renaming declarations for generic actuals do not come from source,
10270 -- and have a different name from that of the entity they rename, so
10271 -- there is no style check to perform here.
10273 if Chars (Nod) = Chars (Val_Actual) then
10274 Style.Check_Identifier (Nod, Val_Actual);
10278 Set_Entity (N, Val);
10279 end Set_Entity_With_Style_Check;
10281 ------------------------
10282 -- Set_Name_Entity_Id --
10283 ------------------------
10285 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10287 Set_Name_Table_Info (Id, Int (Val));
10288 end Set_Name_Entity_Id;
10290 ---------------------
10291 -- Set_Next_Actual --
10292 ---------------------
10294 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10296 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10297 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10299 end Set_Next_Actual;
10301 ----------------------------------
10302 -- Set_Optimize_Alignment_Flags --
10303 ----------------------------------
10305 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10307 if Optimize_Alignment = 'S' then
10308 Set_Optimize_Alignment_Space (E);
10309 elsif Optimize_Alignment = 'T' then
10310 Set_Optimize_Alignment_Time (E);
10312 end Set_Optimize_Alignment_Flags;
10314 -----------------------
10315 -- Set_Public_Status --
10316 -----------------------
10318 procedure Set_Public_Status (Id : Entity_Id) is
10319 S : constant Entity_Id := Current_Scope;
10321 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10322 -- Determines if E is defined within handled statement sequence or
10323 -- an if statement, returns True if so, False otherwise.
10325 ----------------------
10326 -- Within_HSS_Or_If --
10327 ----------------------
10329 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10332 N := Declaration_Node (E);
10339 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10345 end Within_HSS_Or_If;
10347 -- Start of processing for Set_Public_Status
10350 -- Everything in the scope of Standard is public
10352 if S = Standard_Standard then
10353 Set_Is_Public (Id);
10355 -- Entity is definitely not public if enclosing scope is not public
10357 elsif not Is_Public (S) then
10360 -- An object or function declaration that occurs in a handled sequence
10361 -- of statements or within an if statement is the declaration for a
10362 -- temporary object or local subprogram generated by the expander. It
10363 -- never needs to be made public and furthermore, making it public can
10364 -- cause back end problems.
10366 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10367 N_Function_Specification)
10368 and then Within_HSS_Or_If (Id)
10372 -- Entities in public packages or records are public
10374 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10375 Set_Is_Public (Id);
10377 -- The bounds of an entry family declaration can generate object
10378 -- declarations that are visible to the back-end, e.g. in the
10379 -- the declaration of a composite type that contains tasks.
10381 elsif Is_Concurrent_Type (S)
10382 and then not Has_Completion (S)
10383 and then Nkind (Parent (Id)) = N_Object_Declaration
10385 Set_Is_Public (Id);
10387 end Set_Public_Status;
10389 -----------------------------
10390 -- Set_Referenced_Modified --
10391 -----------------------------
10393 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10397 -- Deal with indexed or selected component where prefix is modified
10399 if Nkind (N) = N_Indexed_Component
10401 Nkind (N) = N_Selected_Component
10403 Pref := Prefix (N);
10405 -- If prefix is access type, then it is the designated object that is
10406 -- being modified, which means we have no entity to set the flag on.
10408 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10411 -- Otherwise chase the prefix
10414 Set_Referenced_Modified (Pref, Out_Param);
10417 -- Otherwise see if we have an entity name (only other case to process)
10419 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10420 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10421 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10423 end Set_Referenced_Modified;
10425 ----------------------------
10426 -- Set_Scope_Is_Transient --
10427 ----------------------------
10429 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10431 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10432 end Set_Scope_Is_Transient;
10434 -------------------
10435 -- Set_Size_Info --
10436 -------------------
10438 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10440 -- We copy Esize, but not RM_Size, since in general RM_Size is
10441 -- subtype specific and does not get inherited by all subtypes.
10443 Set_Esize (T1, Esize (T2));
10444 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10446 if Is_Discrete_Or_Fixed_Point_Type (T1)
10448 Is_Discrete_Or_Fixed_Point_Type (T2)
10450 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10453 Set_Alignment (T1, Alignment (T2));
10456 --------------------
10457 -- Static_Integer --
10458 --------------------
10460 function Static_Integer (N : Node_Id) return Uint is
10462 Analyze_And_Resolve (N, Any_Integer);
10465 or else Error_Posted (N)
10466 or else Etype (N) = Any_Type
10471 if Is_Static_Expression (N) then
10472 if not Raises_Constraint_Error (N) then
10473 return Expr_Value (N);
10478 elsif Etype (N) = Any_Type then
10482 Flag_Non_Static_Expr
10483 ("static integer expression required here", N);
10486 end Static_Integer;
10488 --------------------------
10489 -- Statically_Different --
10490 --------------------------
10492 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10493 R1 : constant Node_Id := Get_Referenced_Object (E1);
10494 R2 : constant Node_Id := Get_Referenced_Object (E2);
10496 return Is_Entity_Name (R1)
10497 and then Is_Entity_Name (R2)
10498 and then Entity (R1) /= Entity (R2)
10499 and then not Is_Formal (Entity (R1))
10500 and then not Is_Formal (Entity (R2));
10501 end Statically_Different;
10503 -----------------------------
10504 -- Subprogram_Access_Level --
10505 -----------------------------
10507 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10509 if Present (Alias (Subp)) then
10510 return Subprogram_Access_Level (Alias (Subp));
10512 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10514 end Subprogram_Access_Level;
10520 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10522 if Debug_Flag_W then
10523 for J in 0 .. Scope_Stack.Last loop
10528 Write_Name (Chars (E));
10529 Write_Str (" from ");
10530 Write_Location (Sloc (N));
10535 -----------------------
10536 -- Transfer_Entities --
10537 -----------------------
10539 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10540 Ent : Entity_Id := First_Entity (From);
10547 if (Last_Entity (To)) = Empty then
10548 Set_First_Entity (To, Ent);
10550 Set_Next_Entity (Last_Entity (To), Ent);
10553 Set_Last_Entity (To, Last_Entity (From));
10555 while Present (Ent) loop
10556 Set_Scope (Ent, To);
10558 if not Is_Public (Ent) then
10559 Set_Public_Status (Ent);
10562 and then Ekind (Ent) = E_Record_Subtype
10565 -- The components of the propagated Itype must be public
10571 Comp := First_Entity (Ent);
10572 while Present (Comp) loop
10573 Set_Is_Public (Comp);
10574 Next_Entity (Comp);
10583 Set_First_Entity (From, Empty);
10584 Set_Last_Entity (From, Empty);
10585 end Transfer_Entities;
10587 -----------------------
10588 -- Type_Access_Level --
10589 -----------------------
10591 function Type_Access_Level (Typ : Entity_Id) return Uint is
10595 Btyp := Base_Type (Typ);
10597 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10598 -- simply use the level where the type is declared. This is true for
10599 -- stand-alone object declarations, and for anonymous access types
10600 -- associated with components the level is the same as that of the
10601 -- enclosing composite type. However, special treatment is needed for
10602 -- the cases of access parameters, return objects of an anonymous access
10603 -- type, and, in Ada 95, access discriminants of limited types.
10605 if Ekind (Btyp) in Access_Kind then
10606 if Ekind (Btyp) = E_Anonymous_Access_Type then
10608 -- If the type is a nonlocal anonymous access type (such as for
10609 -- an access parameter) we treat it as being declared at the
10610 -- library level to ensure that names such as X.all'access don't
10611 -- fail static accessibility checks.
10613 if not Is_Local_Anonymous_Access (Typ) then
10614 return Scope_Depth (Standard_Standard);
10616 -- If this is a return object, the accessibility level is that of
10617 -- the result subtype of the enclosing function. The test here is
10618 -- little complicated, because we have to account for extended
10619 -- return statements that have been rewritten as blocks, in which
10620 -- case we have to find and the Is_Return_Object attribute of the
10621 -- itype's associated object. It would be nice to find a way to
10622 -- simplify this test, but it doesn't seem worthwhile to add a new
10623 -- flag just for purposes of this test. ???
10625 elsif Ekind (Scope (Btyp)) = E_Return_Statement
10628 and then Nkind (Associated_Node_For_Itype (Btyp)) =
10629 N_Object_Declaration
10630 and then Is_Return_Object
10631 (Defining_Identifier
10632 (Associated_Node_For_Itype (Btyp))))
10638 Scop := Scope (Scope (Btyp));
10639 while Present (Scop) loop
10640 exit when Ekind (Scop) = E_Function;
10641 Scop := Scope (Scop);
10644 -- Treat the return object's type as having the level of the
10645 -- function's result subtype (as per RM05-6.5(5.3/2)).
10647 return Type_Access_Level (Etype (Scop));
10652 Btyp := Root_Type (Btyp);
10654 -- The accessibility level of anonymous access types associated with
10655 -- discriminants is that of the current instance of the type, and
10656 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10658 -- AI-402: access discriminants have accessibility based on the
10659 -- object rather than the type in Ada 2005, so the above paragraph
10662 -- ??? Needs completion with rules from AI-416
10664 if Ada_Version <= Ada_95
10665 and then Ekind (Typ) = E_Anonymous_Access_Type
10666 and then Present (Associated_Node_For_Itype (Typ))
10667 and then Nkind (Associated_Node_For_Itype (Typ)) =
10668 N_Discriminant_Specification
10670 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
10674 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
10675 end Type_Access_Level;
10677 --------------------
10678 -- Ultimate_Alias --
10679 --------------------
10680 -- To do: add occurrences calling this new subprogram
10682 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
10683 E : Entity_Id := Prim;
10686 while Present (Alias (E)) loop
10691 end Ultimate_Alias;
10693 --------------------------
10694 -- Unit_Declaration_Node --
10695 --------------------------
10697 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
10698 N : Node_Id := Parent (Unit_Id);
10701 -- Predefined operators do not have a full function declaration
10703 if Ekind (Unit_Id) = E_Operator then
10707 -- Isn't there some better way to express the following ???
10709 while Nkind (N) /= N_Abstract_Subprogram_Declaration
10710 and then Nkind (N) /= N_Formal_Package_Declaration
10711 and then Nkind (N) /= N_Function_Instantiation
10712 and then Nkind (N) /= N_Generic_Package_Declaration
10713 and then Nkind (N) /= N_Generic_Subprogram_Declaration
10714 and then Nkind (N) /= N_Package_Declaration
10715 and then Nkind (N) /= N_Package_Body
10716 and then Nkind (N) /= N_Package_Instantiation
10717 and then Nkind (N) /= N_Package_Renaming_Declaration
10718 and then Nkind (N) /= N_Procedure_Instantiation
10719 and then Nkind (N) /= N_Protected_Body
10720 and then Nkind (N) /= N_Subprogram_Declaration
10721 and then Nkind (N) /= N_Subprogram_Body
10722 and then Nkind (N) /= N_Subprogram_Body_Stub
10723 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
10724 and then Nkind (N) /= N_Task_Body
10725 and then Nkind (N) /= N_Task_Type_Declaration
10726 and then Nkind (N) not in N_Formal_Subprogram_Declaration
10727 and then Nkind (N) not in N_Generic_Renaming_Declaration
10730 pragma Assert (Present (N));
10734 end Unit_Declaration_Node;
10736 ------------------------------
10737 -- Universal_Interpretation --
10738 ------------------------------
10740 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
10741 Index : Interp_Index;
10745 -- The argument may be a formal parameter of an operator or subprogram
10746 -- with multiple interpretations, or else an expression for an actual.
10748 if Nkind (Opnd) = N_Defining_Identifier
10749 or else not Is_Overloaded (Opnd)
10751 if Etype (Opnd) = Universal_Integer
10752 or else Etype (Opnd) = Universal_Real
10754 return Etype (Opnd);
10760 Get_First_Interp (Opnd, Index, It);
10761 while Present (It.Typ) loop
10762 if It.Typ = Universal_Integer
10763 or else It.Typ = Universal_Real
10768 Get_Next_Interp (Index, It);
10773 end Universal_Interpretation;
10779 function Unqualify (Expr : Node_Id) return Node_Id is
10781 -- Recurse to handle unlikely case of multiple levels of qualification
10783 if Nkind (Expr) = N_Qualified_Expression then
10784 return Unqualify (Expression (Expr));
10786 -- Normal case, not a qualified expression
10793 ----------------------
10794 -- Within_Init_Proc --
10795 ----------------------
10797 function Within_Init_Proc return Boolean is
10801 S := Current_Scope;
10802 while not Is_Overloadable (S) loop
10803 if S = Standard_Standard then
10810 return Is_Init_Proc (S);
10811 end Within_Init_Proc;
10817 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
10818 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
10819 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
10821 function Has_One_Matching_Field return Boolean;
10822 -- Determines if Expec_Type is a record type with a single component or
10823 -- discriminant whose type matches the found type or is one dimensional
10824 -- array whose component type matches the found type.
10826 ----------------------------
10827 -- Has_One_Matching_Field --
10828 ----------------------------
10830 function Has_One_Matching_Field return Boolean is
10834 if Is_Array_Type (Expec_Type)
10835 and then Number_Dimensions (Expec_Type) = 1
10837 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
10841 elsif not Is_Record_Type (Expec_Type) then
10845 E := First_Entity (Expec_Type);
10850 elsif (Ekind (E) /= E_Discriminant
10851 and then Ekind (E) /= E_Component)
10852 or else (Chars (E) = Name_uTag
10853 or else Chars (E) = Name_uParent)
10862 if not Covers (Etype (E), Found_Type) then
10865 elsif Present (Next_Entity (E)) then
10872 end Has_One_Matching_Field;
10874 -- Start of processing for Wrong_Type
10877 -- Don't output message if either type is Any_Type, or if a message
10878 -- has already been posted for this node. We need to do the latter
10879 -- check explicitly (it is ordinarily done in Errout), because we
10880 -- are using ! to force the output of the error messages.
10882 if Expec_Type = Any_Type
10883 or else Found_Type = Any_Type
10884 or else Error_Posted (Expr)
10888 -- In an instance, there is an ongoing problem with completion of
10889 -- type derived from private types. Their structure is what Gigi
10890 -- expects, but the Etype is the parent type rather than the
10891 -- derived private type itself. Do not flag error in this case. The
10892 -- private completion is an entity without a parent, like an Itype.
10893 -- Similarly, full and partial views may be incorrect in the instance.
10894 -- There is no simple way to insure that it is consistent ???
10896 elsif In_Instance then
10897 if Etype (Etype (Expr)) = Etype (Expected_Type)
10899 (Has_Private_Declaration (Expected_Type)
10900 or else Has_Private_Declaration (Etype (Expr)))
10901 and then No (Parent (Expected_Type))
10907 -- An interesting special check. If the expression is parenthesized
10908 -- and its type corresponds to the type of the sole component of the
10909 -- expected record type, or to the component type of the expected one
10910 -- dimensional array type, then assume we have a bad aggregate attempt.
10912 if Nkind (Expr) in N_Subexpr
10913 and then Paren_Count (Expr) /= 0
10914 and then Has_One_Matching_Field
10916 Error_Msg_N ("positional aggregate cannot have one component", Expr);
10918 -- Another special check, if we are looking for a pool-specific access
10919 -- type and we found an E_Access_Attribute_Type, then we have the case
10920 -- of an Access attribute being used in a context which needs a pool-
10921 -- specific type, which is never allowed. The one extra check we make
10922 -- is that the expected designated type covers the Found_Type.
10924 elsif Is_Access_Type (Expec_Type)
10925 and then Ekind (Found_Type) = E_Access_Attribute_Type
10926 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
10927 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
10929 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
10931 Error_Msg_N ("result must be general access type!", Expr);
10932 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
10934 -- Another special check, if the expected type is an integer type,
10935 -- but the expression is of type System.Address, and the parent is
10936 -- an addition or subtraction operation whose left operand is the
10937 -- expression in question and whose right operand is of an integral
10938 -- type, then this is an attempt at address arithmetic, so give
10939 -- appropriate message.
10941 elsif Is_Integer_Type (Expec_Type)
10942 and then Is_RTE (Found_Type, RE_Address)
10943 and then (Nkind (Parent (Expr)) = N_Op_Add
10945 Nkind (Parent (Expr)) = N_Op_Subtract)
10946 and then Expr = Left_Opnd (Parent (Expr))
10947 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
10950 ("address arithmetic not predefined in package System",
10953 ("\possible missing with/use of System.Storage_Elements",
10957 -- If the expected type is an anonymous access type, as for access
10958 -- parameters and discriminants, the error is on the designated types.
10960 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
10961 if Comes_From_Source (Expec_Type) then
10962 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10965 ("expected an access type with designated}",
10966 Expr, Designated_Type (Expec_Type));
10969 if Is_Access_Type (Found_Type)
10970 and then not Comes_From_Source (Found_Type)
10973 ("\\found an access type with designated}!",
10974 Expr, Designated_Type (Found_Type));
10976 if From_With_Type (Found_Type) then
10977 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
10978 Error_Msg_Qual_Level := 99;
10979 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
10980 Error_Msg_Qual_Level := 0;
10982 Error_Msg_NE ("found}!", Expr, Found_Type);
10986 -- Normal case of one type found, some other type expected
10989 -- If the names of the two types are the same, see if some number
10990 -- of levels of qualification will help. Don't try more than three
10991 -- levels, and if we get to standard, it's no use (and probably
10992 -- represents an error in the compiler) Also do not bother with
10993 -- internal scope names.
10996 Expec_Scope : Entity_Id;
10997 Found_Scope : Entity_Id;
11000 Expec_Scope := Expec_Type;
11001 Found_Scope := Found_Type;
11003 for Levels in Int range 0 .. 3 loop
11004 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11005 Error_Msg_Qual_Level := Levels;
11009 Expec_Scope := Scope (Expec_Scope);
11010 Found_Scope := Scope (Found_Scope);
11012 exit when Expec_Scope = Standard_Standard
11013 or else Found_Scope = Standard_Standard
11014 or else not Comes_From_Source (Expec_Scope)
11015 or else not Comes_From_Source (Found_Scope);
11019 if Is_Record_Type (Expec_Type)
11020 and then Present (Corresponding_Remote_Type (Expec_Type))
11022 Error_Msg_NE ("expected}!", Expr,
11023 Corresponding_Remote_Type (Expec_Type));
11025 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11028 if Is_Entity_Name (Expr)
11029 and then Is_Package_Or_Generic_Package (Entity (Expr))
11031 Error_Msg_N ("\\found package name!", Expr);
11033 elsif Is_Entity_Name (Expr)
11035 (Ekind (Entity (Expr)) = E_Procedure
11037 Ekind (Entity (Expr)) = E_Generic_Procedure)
11039 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11041 ("found procedure name, possibly missing Access attribute!",
11045 ("\\found procedure name instead of function!", Expr);
11048 elsif Nkind (Expr) = N_Function_Call
11049 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11050 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11051 and then No (Parameter_Associations (Expr))
11054 ("found function name, possibly missing Access attribute!",
11057 -- Catch common error: a prefix or infix operator which is not
11058 -- directly visible because the type isn't.
11060 elsif Nkind (Expr) in N_Op
11061 and then Is_Overloaded (Expr)
11062 and then not Is_Immediately_Visible (Expec_Type)
11063 and then not Is_Potentially_Use_Visible (Expec_Type)
11064 and then not In_Use (Expec_Type)
11065 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11068 ("operator of the type is not directly visible!", Expr);
11070 elsif Ekind (Found_Type) = E_Void
11071 and then Present (Parent (Found_Type))
11072 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11074 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11077 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11080 Error_Msg_Qual_Level := 0;