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_SCIL; use Sem_SCIL;
54 with Sem_Type; use Sem_Type;
55 with Sinfo; use Sinfo;
56 with Sinput; use Sinput;
57 with Stand; use Stand;
59 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
66 package body Sem_Util is
68 ----------------------------------------
69 -- Global_Variables for New_Copy_Tree --
70 ----------------------------------------
72 -- These global variables are used by New_Copy_Tree. See description
73 -- of the body of this subprogram for details. Global variables can be
74 -- safely used by New_Copy_Tree, since there is no case of a recursive
75 -- call from the processing inside New_Copy_Tree.
77 NCT_Hash_Threshhold : constant := 20;
78 -- If there are more than this number of pairs of entries in the
79 -- map, then Hash_Tables_Used will be set, and the hash tables will
80 -- be initialized and used for the searches.
82 NCT_Hash_Tables_Used : Boolean := False;
83 -- Set to True if hash tables are in use
85 NCT_Table_Entries : Nat;
86 -- Count entries in table to see if threshhold is reached
88 NCT_Hash_Table_Setup : Boolean := False;
89 -- Set to True if hash table contains data. We set this True if we
90 -- setup the hash table with data, and leave it set permanently
91 -- from then on, this is a signal that second and subsequent users
92 -- of the hash table must clear the old entries before reuse.
94 subtype NCT_Header_Num is Int range 0 .. 511;
95 -- Defines range of headers in hash tables (512 headers)
97 -----------------------
98 -- Local Subprograms --
99 -----------------------
101 function Build_Component_Subtype
104 T : Entity_Id) return Node_Id;
105 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
106 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
107 -- Loc is the source location, T is the original subtype.
109 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
110 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
111 -- with discriminants whose default values are static, examine only the
112 -- components in the selected variant to determine whether all of them
115 function Has_Null_Extension (T : Entity_Id) return Boolean;
116 -- T is a derived tagged type. Check whether the type extension is null.
117 -- If the parent type is fully initialized, T can be treated as such.
119 ------------------------------
120 -- Abstract_Interface_List --
121 ------------------------------
123 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
127 if Is_Concurrent_Type (Typ) then
129 -- If we are dealing with a synchronized subtype, go to the base
130 -- type, whose declaration has the interface list.
132 -- Shouldn't this be Declaration_Node???
134 Nod := Parent (Base_Type (Typ));
136 if Nkind (Nod) = N_Full_Type_Declaration then
140 elsif Ekind (Typ) = E_Record_Type_With_Private then
141 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
142 Nod := Type_Definition (Parent (Typ));
144 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
145 if Present (Full_View (Typ)) then
146 Nod := Type_Definition (Parent (Full_View (Typ)));
148 -- If the full-view is not available we cannot do anything else
149 -- here (the source has errors).
155 -- Support for generic formals with interfaces is still missing ???
157 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
162 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
166 elsif Ekind (Typ) = E_Record_Subtype then
167 Nod := Type_Definition (Parent (Etype (Typ)));
169 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
171 -- Recurse, because parent may still be a private extension. Also
172 -- note that the full view of the subtype or the full view of its
173 -- base type may (both) be unavailable.
175 return Abstract_Interface_List (Etype (Typ));
177 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
178 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
179 Nod := Formal_Type_Definition (Parent (Typ));
181 Nod := Type_Definition (Parent (Typ));
185 return Interface_List (Nod);
186 end Abstract_Interface_List;
188 --------------------------------
189 -- Add_Access_Type_To_Process --
190 --------------------------------
192 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
196 Ensure_Freeze_Node (E);
197 L := Access_Types_To_Process (Freeze_Node (E));
201 Set_Access_Types_To_Process (Freeze_Node (E), L);
205 end Add_Access_Type_To_Process;
207 ----------------------------
208 -- Add_Global_Declaration --
209 ----------------------------
211 procedure Add_Global_Declaration (N : Node_Id) is
212 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
215 if No (Declarations (Aux_Node)) then
216 Set_Declarations (Aux_Node, New_List);
219 Append_To (Declarations (Aux_Node), N);
221 end Add_Global_Declaration;
223 -----------------------
224 -- Alignment_In_Bits --
225 -----------------------
227 function Alignment_In_Bits (E : Entity_Id) return Uint is
229 return Alignment (E) * System_Storage_Unit;
230 end Alignment_In_Bits;
232 -----------------------------------------
233 -- Apply_Compile_Time_Constraint_Error --
234 -----------------------------------------
236 procedure Apply_Compile_Time_Constraint_Error
239 Reason : RT_Exception_Code;
240 Ent : Entity_Id := Empty;
241 Typ : Entity_Id := Empty;
242 Loc : Source_Ptr := No_Location;
243 Rep : Boolean := True;
244 Warn : Boolean := False)
246 Stat : constant Boolean := Is_Static_Expression (N);
247 R_Stat : constant Node_Id :=
248 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
259 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
265 -- Now we replace the node by an N_Raise_Constraint_Error node
266 -- This does not need reanalyzing, so set it as analyzed now.
269 Set_Analyzed (N, True);
272 Set_Raises_Constraint_Error (N);
274 -- Now deal with possible local raise handling
276 Possible_Local_Raise (N, Standard_Constraint_Error);
278 -- If the original expression was marked as static, the result is
279 -- still marked as static, but the Raises_Constraint_Error flag is
280 -- always set so that further static evaluation is not attempted.
283 Set_Is_Static_Expression (N);
285 end Apply_Compile_Time_Constraint_Error;
287 --------------------------
288 -- Build_Actual_Subtype --
289 --------------------------
291 function Build_Actual_Subtype
293 N : Node_Or_Entity_Id) return Node_Id
296 -- Normally Sloc (N), but may point to corresponding body in some cases
298 Constraints : List_Id;
304 Disc_Type : Entity_Id;
310 if Nkind (N) = N_Defining_Identifier then
311 Obj := New_Reference_To (N, Loc);
313 -- If this is a formal parameter of a subprogram declaration, and
314 -- we are compiling the body, we want the declaration for the
315 -- actual subtype to carry the source position of the body, to
316 -- prevent anomalies in gdb when stepping through the code.
318 if Is_Formal (N) then
320 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
322 if Nkind (Decl) = N_Subprogram_Declaration
323 and then Present (Corresponding_Body (Decl))
325 Loc := Sloc (Corresponding_Body (Decl));
334 if Is_Array_Type (T) then
335 Constraints := New_List;
336 for J in 1 .. Number_Dimensions (T) loop
338 -- Build an array subtype declaration with the nominal subtype and
339 -- the bounds of the actual. Add the declaration in front of the
340 -- local declarations for the subprogram, for analysis before any
341 -- reference to the formal in the body.
344 Make_Attribute_Reference (Loc,
346 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
347 Attribute_Name => Name_First,
348 Expressions => New_List (
349 Make_Integer_Literal (Loc, J)));
352 Make_Attribute_Reference (Loc,
354 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
355 Attribute_Name => Name_Last,
356 Expressions => New_List (
357 Make_Integer_Literal (Loc, J)));
359 Append (Make_Range (Loc, Lo, Hi), Constraints);
362 -- If the type has unknown discriminants there is no constrained
363 -- subtype to build. This is never called for a formal or for a
364 -- lhs, so returning the type is ok ???
366 elsif Has_Unknown_Discriminants (T) then
370 Constraints := New_List;
372 -- Type T is a generic derived type, inherit the discriminants from
375 if Is_Private_Type (T)
376 and then No (Full_View (T))
378 -- T was flagged as an error if it was declared as a formal
379 -- derived type with known discriminants. In this case there
380 -- is no need to look at the parent type since T already carries
381 -- its own discriminants.
383 and then not Error_Posted (T)
385 Disc_Type := Etype (Base_Type (T));
390 Discr := First_Discriminant (Disc_Type);
391 while Present (Discr) loop
392 Append_To (Constraints,
393 Make_Selected_Component (Loc,
395 Duplicate_Subexpr_No_Checks (Obj),
396 Selector_Name => New_Occurrence_Of (Discr, Loc)));
397 Next_Discriminant (Discr);
401 Subt := Make_Temporary (Loc, 'S');
402 Set_Is_Internal (Subt);
405 Make_Subtype_Declaration (Loc,
406 Defining_Identifier => Subt,
407 Subtype_Indication =>
408 Make_Subtype_Indication (Loc,
409 Subtype_Mark => New_Reference_To (T, Loc),
411 Make_Index_Or_Discriminant_Constraint (Loc,
412 Constraints => Constraints)));
414 Mark_Rewrite_Insertion (Decl);
416 end Build_Actual_Subtype;
418 ---------------------------------------
419 -- Build_Actual_Subtype_Of_Component --
420 ---------------------------------------
422 function Build_Actual_Subtype_Of_Component
424 N : Node_Id) return Node_Id
426 Loc : constant Source_Ptr := Sloc (N);
427 P : constant Node_Id := Prefix (N);
430 Indx_Type : Entity_Id;
432 Deaccessed_T : Entity_Id;
433 -- This is either a copy of T, or if T is an access type, then it is
434 -- the directly designated type of this access type.
436 function Build_Actual_Array_Constraint return List_Id;
437 -- If one or more of the bounds of the component depends on
438 -- discriminants, build actual constraint using the discriminants
441 function Build_Actual_Record_Constraint return List_Id;
442 -- Similar to previous one, for discriminated components constrained
443 -- by the discriminant of the enclosing object.
445 -----------------------------------
446 -- Build_Actual_Array_Constraint --
447 -----------------------------------
449 function Build_Actual_Array_Constraint return List_Id is
450 Constraints : constant List_Id := New_List;
458 Indx := First_Index (Deaccessed_T);
459 while Present (Indx) loop
460 Old_Lo := Type_Low_Bound (Etype (Indx));
461 Old_Hi := Type_High_Bound (Etype (Indx));
463 if Denotes_Discriminant (Old_Lo) then
465 Make_Selected_Component (Loc,
466 Prefix => New_Copy_Tree (P),
467 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
470 Lo := New_Copy_Tree (Old_Lo);
472 -- The new bound will be reanalyzed in the enclosing
473 -- declaration. For literal bounds that come from a type
474 -- declaration, the type of the context must be imposed, so
475 -- insure that analysis will take place. For non-universal
476 -- types this is not strictly necessary.
478 Set_Analyzed (Lo, False);
481 if Denotes_Discriminant (Old_Hi) then
483 Make_Selected_Component (Loc,
484 Prefix => New_Copy_Tree (P),
485 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
488 Hi := New_Copy_Tree (Old_Hi);
489 Set_Analyzed (Hi, False);
492 Append (Make_Range (Loc, Lo, Hi), Constraints);
497 end Build_Actual_Array_Constraint;
499 ------------------------------------
500 -- Build_Actual_Record_Constraint --
501 ------------------------------------
503 function Build_Actual_Record_Constraint return List_Id is
504 Constraints : constant List_Id := New_List;
509 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
510 while Present (D) loop
511 if Denotes_Discriminant (Node (D)) then
512 D_Val := Make_Selected_Component (Loc,
513 Prefix => New_Copy_Tree (P),
514 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
517 D_Val := New_Copy_Tree (Node (D));
520 Append (D_Val, Constraints);
525 end Build_Actual_Record_Constraint;
527 -- Start of processing for Build_Actual_Subtype_Of_Component
530 -- Why the test for Spec_Expression mode here???
532 if In_Spec_Expression then
535 -- More comments for the rest of this body would be good ???
537 elsif Nkind (N) = N_Explicit_Dereference then
538 if Is_Composite_Type (T)
539 and then not Is_Constrained (T)
540 and then not (Is_Class_Wide_Type (T)
541 and then Is_Constrained (Root_Type (T)))
542 and then not Has_Unknown_Discriminants (T)
544 -- If the type of the dereference is already constrained, it is an
547 if Is_Array_Type (Etype (N))
548 and then Is_Constrained (Etype (N))
552 Remove_Side_Effects (P);
553 return Build_Actual_Subtype (T, N);
560 if Ekind (T) = E_Access_Subtype then
561 Deaccessed_T := Designated_Type (T);
566 if Ekind (Deaccessed_T) = E_Array_Subtype then
567 Id := First_Index (Deaccessed_T);
568 while Present (Id) loop
569 Indx_Type := Underlying_Type (Etype (Id));
571 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
573 Denotes_Discriminant (Type_High_Bound (Indx_Type))
575 Remove_Side_Effects (P);
577 Build_Component_Subtype
578 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
584 elsif Is_Composite_Type (Deaccessed_T)
585 and then Has_Discriminants (Deaccessed_T)
586 and then not Has_Unknown_Discriminants (Deaccessed_T)
588 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
589 while Present (D) loop
590 if Denotes_Discriminant (Node (D)) then
591 Remove_Side_Effects (P);
593 Build_Component_Subtype (
594 Build_Actual_Record_Constraint, Loc, Base_Type (T));
601 -- If none of the above, the actual and nominal subtypes are the same
604 end Build_Actual_Subtype_Of_Component;
606 -----------------------------
607 -- Build_Component_Subtype --
608 -----------------------------
610 function Build_Component_Subtype
613 T : Entity_Id) return Node_Id
619 -- Unchecked_Union components do not require component subtypes
621 if Is_Unchecked_Union (T) then
625 Subt := Make_Temporary (Loc, 'S');
626 Set_Is_Internal (Subt);
629 Make_Subtype_Declaration (Loc,
630 Defining_Identifier => Subt,
631 Subtype_Indication =>
632 Make_Subtype_Indication (Loc,
633 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
635 Make_Index_Or_Discriminant_Constraint (Loc,
638 Mark_Rewrite_Insertion (Decl);
640 end Build_Component_Subtype;
642 ---------------------------
643 -- Build_Default_Subtype --
644 ---------------------------
646 function Build_Default_Subtype
648 N : Node_Id) return Entity_Id
650 Loc : constant Source_Ptr := Sloc (N);
654 if not Has_Discriminants (T) or else Is_Constrained (T) then
658 Disc := First_Discriminant (T);
660 if No (Discriminant_Default_Value (Disc)) then
665 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
666 Constraints : constant List_Id := New_List;
670 while Present (Disc) loop
671 Append_To (Constraints,
672 New_Copy_Tree (Discriminant_Default_Value (Disc)));
673 Next_Discriminant (Disc);
677 Make_Subtype_Declaration (Loc,
678 Defining_Identifier => Act,
679 Subtype_Indication =>
680 Make_Subtype_Indication (Loc,
681 Subtype_Mark => New_Occurrence_Of (T, Loc),
683 Make_Index_Or_Discriminant_Constraint (Loc,
684 Constraints => Constraints)));
686 Insert_Action (N, Decl);
690 end Build_Default_Subtype;
692 --------------------------------------------
693 -- Build_Discriminal_Subtype_Of_Component --
694 --------------------------------------------
696 function Build_Discriminal_Subtype_Of_Component
697 (T : Entity_Id) return Node_Id
699 Loc : constant Source_Ptr := Sloc (T);
703 function Build_Discriminal_Array_Constraint return List_Id;
704 -- If one or more of the bounds of the component depends on
705 -- discriminants, build actual constraint using the discriminants
708 function Build_Discriminal_Record_Constraint return List_Id;
709 -- Similar to previous one, for discriminated components constrained
710 -- by the discriminant of the enclosing object.
712 ----------------------------------------
713 -- Build_Discriminal_Array_Constraint --
714 ----------------------------------------
716 function Build_Discriminal_Array_Constraint return List_Id is
717 Constraints : constant List_Id := New_List;
725 Indx := First_Index (T);
726 while Present (Indx) loop
727 Old_Lo := Type_Low_Bound (Etype (Indx));
728 Old_Hi := Type_High_Bound (Etype (Indx));
730 if Denotes_Discriminant (Old_Lo) then
731 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
734 Lo := New_Copy_Tree (Old_Lo);
737 if Denotes_Discriminant (Old_Hi) then
738 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
741 Hi := New_Copy_Tree (Old_Hi);
744 Append (Make_Range (Loc, Lo, Hi), Constraints);
749 end Build_Discriminal_Array_Constraint;
751 -----------------------------------------
752 -- Build_Discriminal_Record_Constraint --
753 -----------------------------------------
755 function Build_Discriminal_Record_Constraint return List_Id is
756 Constraints : constant List_Id := New_List;
761 D := First_Elmt (Discriminant_Constraint (T));
762 while Present (D) loop
763 if Denotes_Discriminant (Node (D)) then
765 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
768 D_Val := New_Copy_Tree (Node (D));
771 Append (D_Val, Constraints);
776 end Build_Discriminal_Record_Constraint;
778 -- Start of processing for Build_Discriminal_Subtype_Of_Component
781 if Ekind (T) = E_Array_Subtype then
782 Id := First_Index (T);
783 while Present (Id) loop
784 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
785 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
787 return Build_Component_Subtype
788 (Build_Discriminal_Array_Constraint, Loc, T);
794 elsif Ekind (T) = E_Record_Subtype
795 and then Has_Discriminants (T)
796 and then not Has_Unknown_Discriminants (T)
798 D := First_Elmt (Discriminant_Constraint (T));
799 while Present (D) loop
800 if Denotes_Discriminant (Node (D)) then
801 return Build_Component_Subtype
802 (Build_Discriminal_Record_Constraint, Loc, T);
809 -- If none of the above, the actual and nominal subtypes are the same
812 end Build_Discriminal_Subtype_Of_Component;
814 ------------------------------
815 -- Build_Elaboration_Entity --
816 ------------------------------
818 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
819 Loc : constant Source_Ptr := Sloc (N);
821 Elab_Ent : Entity_Id;
823 procedure Set_Package_Name (Ent : Entity_Id);
824 -- Given an entity, sets the fully qualified name of the entity in
825 -- Name_Buffer, with components separated by double underscores. This
826 -- is a recursive routine that climbs the scope chain to Standard.
828 ----------------------
829 -- Set_Package_Name --
830 ----------------------
832 procedure Set_Package_Name (Ent : Entity_Id) is
834 if Scope (Ent) /= Standard_Standard then
835 Set_Package_Name (Scope (Ent));
838 Nam : constant String := Get_Name_String (Chars (Ent));
840 Name_Buffer (Name_Len + 1) := '_';
841 Name_Buffer (Name_Len + 2) := '_';
842 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
843 Name_Len := Name_Len + Nam'Length + 2;
847 Get_Name_String (Chars (Ent));
849 end Set_Package_Name;
851 -- Start of processing for Build_Elaboration_Entity
854 -- Ignore if already constructed
856 if Present (Elaboration_Entity (Spec_Id)) then
860 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
861 -- name with dots replaced by double underscore. We have to manually
862 -- construct this name, since it will be elaborated in the outer scope,
863 -- and thus will not have the unit name automatically prepended.
865 Set_Package_Name (Spec_Id);
869 Name_Buffer (Name_Len + 1) := '_';
870 Name_Buffer (Name_Len + 2) := 'E';
871 Name_Len := Name_Len + 2;
873 -- Create elaboration flag
876 Make_Defining_Identifier (Loc, Chars => Name_Find);
877 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
880 Make_Object_Declaration (Loc,
881 Defining_Identifier => Elab_Ent,
883 New_Occurrence_Of (Standard_Boolean, Loc),
885 New_Occurrence_Of (Standard_False, Loc));
887 Push_Scope (Standard_Standard);
888 Add_Global_Declaration (Decl);
891 -- Reset True_Constant indication, since we will indeed assign a value
892 -- to the variable in the binder main. We also kill the Current_Value
893 -- and Last_Assignment fields for the same reason.
895 Set_Is_True_Constant (Elab_Ent, False);
896 Set_Current_Value (Elab_Ent, Empty);
897 Set_Last_Assignment (Elab_Ent, Empty);
899 -- We do not want any further qualification of the name (if we did
900 -- not do this, we would pick up the name of the generic package
901 -- in the case of a library level generic instantiation).
903 Set_Has_Qualified_Name (Elab_Ent);
904 Set_Has_Fully_Qualified_Name (Elab_Ent);
905 end Build_Elaboration_Entity;
907 -----------------------------------
908 -- Cannot_Raise_Constraint_Error --
909 -----------------------------------
911 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
913 if Compile_Time_Known_Value (Expr) then
916 elsif Do_Range_Check (Expr) then
919 elsif Raises_Constraint_Error (Expr) then
927 when N_Expanded_Name =>
930 when N_Selected_Component =>
931 return not Do_Discriminant_Check (Expr);
933 when N_Attribute_Reference =>
934 if Do_Overflow_Check (Expr) then
937 elsif No (Expressions (Expr)) then
945 N := First (Expressions (Expr));
946 while Present (N) loop
947 if Cannot_Raise_Constraint_Error (N) then
958 when N_Type_Conversion =>
959 if Do_Overflow_Check (Expr)
960 or else Do_Length_Check (Expr)
961 or else Do_Tag_Check (Expr)
966 Cannot_Raise_Constraint_Error (Expression (Expr));
969 when N_Unchecked_Type_Conversion =>
970 return Cannot_Raise_Constraint_Error (Expression (Expr));
973 if Do_Overflow_Check (Expr) then
977 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
984 if Do_Division_Check (Expr)
985 or else Do_Overflow_Check (Expr)
990 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
992 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1011 N_Op_Shift_Right_Arithmetic |
1015 if Do_Overflow_Check (Expr) then
1019 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1021 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1028 end Cannot_Raise_Constraint_Error;
1030 -----------------------------------------
1031 -- Check_Dynamically_Tagged_Expression --
1032 -----------------------------------------
1034 procedure Check_Dynamically_Tagged_Expression
1037 Related_Nod : Node_Id)
1040 pragma Assert (Is_Tagged_Type (Typ));
1042 -- In order to avoid spurious errors when analyzing the expanded code,
1043 -- this check is done only for nodes that come from source and for
1044 -- actuals of generic instantiations.
1046 if (Comes_From_Source (Related_Nod)
1047 or else In_Generic_Actual (Expr))
1048 and then (Is_Class_Wide_Type (Etype (Expr))
1049 or else Is_Dynamically_Tagged (Expr))
1050 and then Is_Tagged_Type (Typ)
1051 and then not Is_Class_Wide_Type (Typ)
1053 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1055 end Check_Dynamically_Tagged_Expression;
1057 --------------------------
1058 -- Check_Fully_Declared --
1059 --------------------------
1061 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1063 if Ekind (T) = E_Incomplete_Type then
1065 -- Ada 2005 (AI-50217): If the type is available through a limited
1066 -- with_clause, verify that its full view has been analyzed.
1068 if From_With_Type (T)
1069 and then Present (Non_Limited_View (T))
1070 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1072 -- The non-limited view is fully declared
1077 ("premature usage of incomplete}", N, First_Subtype (T));
1080 -- Need comments for these tests ???
1082 elsif Has_Private_Component (T)
1083 and then not Is_Generic_Type (Root_Type (T))
1084 and then not In_Spec_Expression
1086 -- Special case: if T is the anonymous type created for a single
1087 -- task or protected object, use the name of the source object.
1089 if Is_Concurrent_Type (T)
1090 and then not Comes_From_Source (T)
1091 and then Nkind (N) = N_Object_Declaration
1093 Error_Msg_NE ("type of& has incomplete component", N,
1094 Defining_Identifier (N));
1098 ("premature usage of incomplete}", N, First_Subtype (T));
1101 end Check_Fully_Declared;
1103 -------------------------
1104 -- Check_Nested_Access --
1105 -------------------------
1107 procedure Check_Nested_Access (Ent : Entity_Id) is
1108 Scop : constant Entity_Id := Current_Scope;
1109 Current_Subp : Entity_Id;
1110 Enclosing : Entity_Id;
1113 -- Currently only enabled for VM back-ends for efficiency, should we
1114 -- enable it more systematically ???
1116 -- Check for Is_Imported needs commenting below ???
1118 if VM_Target /= No_VM
1119 and then (Ekind (Ent) = E_Variable
1121 Ekind (Ent) = E_Constant
1123 Ekind (Ent) = E_Loop_Parameter)
1124 and then Scope (Ent) /= Empty
1125 and then not Is_Library_Level_Entity (Ent)
1126 and then not Is_Imported (Ent)
1128 if Is_Subprogram (Scop)
1129 or else Is_Generic_Subprogram (Scop)
1130 or else Is_Entry (Scop)
1132 Current_Subp := Scop;
1134 Current_Subp := Current_Subprogram;
1137 Enclosing := Enclosing_Subprogram (Ent);
1139 if Enclosing /= Empty
1140 and then Enclosing /= Current_Subp
1142 Set_Has_Up_Level_Access (Ent, True);
1145 end Check_Nested_Access;
1147 ------------------------------------------
1148 -- Check_Potentially_Blocking_Operation --
1149 ------------------------------------------
1151 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1154 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1155 -- When pragma Detect_Blocking is active, the run time will raise
1156 -- Program_Error. Here we only issue a warning, since we generally
1157 -- support the use of potentially blocking operations in the absence
1160 -- Indirect blocking through a subprogram call cannot be diagnosed
1161 -- statically without interprocedural analysis, so we do not attempt
1164 S := Scope (Current_Scope);
1165 while Present (S) and then S /= Standard_Standard loop
1166 if Is_Protected_Type (S) then
1168 ("potentially blocking operation in protected operation?", N);
1175 end Check_Potentially_Blocking_Operation;
1177 ------------------------------
1178 -- Check_Unprotected_Access --
1179 ------------------------------
1181 procedure Check_Unprotected_Access
1185 Cont_Encl_Typ : Entity_Id;
1186 Pref_Encl_Typ : Entity_Id;
1188 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1189 -- Check whether Obj is a private component of a protected object.
1190 -- Return the protected type where the component resides, Empty
1193 function Is_Public_Operation return Boolean;
1194 -- Verify that the enclosing operation is callable from outside the
1195 -- protected object, to minimize false positives.
1197 ------------------------------
1198 -- Enclosing_Protected_Type --
1199 ------------------------------
1201 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1203 if Is_Entity_Name (Obj) then
1205 Ent : Entity_Id := Entity (Obj);
1208 -- The object can be a renaming of a private component, use
1209 -- the original record component.
1211 if Is_Prival (Ent) then
1212 Ent := Prival_Link (Ent);
1215 if Is_Protected_Type (Scope (Ent)) then
1221 -- For indexed and selected components, recursively check the prefix
1223 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1224 return Enclosing_Protected_Type (Prefix (Obj));
1226 -- The object does not denote a protected component
1231 end Enclosing_Protected_Type;
1233 -------------------------
1234 -- Is_Public_Operation --
1235 -------------------------
1237 function Is_Public_Operation return Boolean is
1244 and then S /= Pref_Encl_Typ
1246 if Scope (S) = Pref_Encl_Typ then
1247 E := First_Entity (Pref_Encl_Typ);
1249 and then E /= First_Private_Entity (Pref_Encl_Typ)
1262 end Is_Public_Operation;
1264 -- Start of processing for Check_Unprotected_Access
1267 if Nkind (Expr) = N_Attribute_Reference
1268 and then Attribute_Name (Expr) = Name_Unchecked_Access
1270 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1271 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1273 -- Check whether we are trying to export a protected component to a
1274 -- context with an equal or lower access level.
1276 if Present (Pref_Encl_Typ)
1277 and then No (Cont_Encl_Typ)
1278 and then Is_Public_Operation
1279 and then Scope_Depth (Pref_Encl_Typ) >=
1280 Object_Access_Level (Context)
1283 ("?possible unprotected access to protected data", Expr);
1286 end Check_Unprotected_Access;
1292 procedure Check_VMS (Construct : Node_Id) is
1294 if not OpenVMS_On_Target then
1296 ("this construct is allowed only in Open'V'M'S", Construct);
1300 ------------------------
1301 -- Collect_Interfaces --
1302 ------------------------
1304 procedure Collect_Interfaces
1306 Ifaces_List : out Elist_Id;
1307 Exclude_Parents : Boolean := False;
1308 Use_Full_View : Boolean := True)
1310 procedure Collect (Typ : Entity_Id);
1311 -- Subsidiary subprogram used to traverse the whole list
1312 -- of directly and indirectly implemented interfaces
1318 procedure Collect (Typ : Entity_Id) is
1319 Ancestor : Entity_Id;
1327 -- Handle private types
1330 and then Is_Private_Type (Typ)
1331 and then Present (Full_View (Typ))
1333 Full_T := Full_View (Typ);
1336 -- Include the ancestor if we are generating the whole list of
1337 -- abstract interfaces.
1339 if Etype (Full_T) /= Typ
1341 -- Protect the frontend against wrong sources. For example:
1344 -- type A is tagged null record;
1345 -- type B is new A with private;
1346 -- type C is new A with private;
1348 -- type B is new C with null record;
1349 -- type C is new B with null record;
1352 and then Etype (Full_T) /= T
1354 Ancestor := Etype (Full_T);
1357 if Is_Interface (Ancestor)
1358 and then not Exclude_Parents
1360 Append_Unique_Elmt (Ancestor, Ifaces_List);
1364 -- Traverse the graph of ancestor interfaces
1366 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1367 Id := First (Abstract_Interface_List (Full_T));
1368 while Present (Id) loop
1369 Iface := Etype (Id);
1371 -- Protect against wrong uses. For example:
1372 -- type I is interface;
1373 -- type O is tagged null record;
1374 -- type Wrong is new I and O with null record; -- ERROR
1376 if Is_Interface (Iface) then
1378 and then Etype (T) /= T
1379 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1384 Append_Unique_Elmt (Iface, Ifaces_List);
1393 -- Start of processing for Collect_Interfaces
1396 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1397 Ifaces_List := New_Elmt_List;
1399 end Collect_Interfaces;
1401 ----------------------------------
1402 -- Collect_Interface_Components --
1403 ----------------------------------
1405 procedure Collect_Interface_Components
1406 (Tagged_Type : Entity_Id;
1407 Components_List : out Elist_Id)
1409 procedure Collect (Typ : Entity_Id);
1410 -- Subsidiary subprogram used to climb to the parents
1416 procedure Collect (Typ : Entity_Id) is
1417 Tag_Comp : Entity_Id;
1418 Parent_Typ : Entity_Id;
1421 -- Handle private types
1423 if Present (Full_View (Etype (Typ))) then
1424 Parent_Typ := Full_View (Etype (Typ));
1426 Parent_Typ := Etype (Typ);
1429 if Parent_Typ /= Typ
1431 -- Protect the frontend against wrong sources. For example:
1434 -- type A is tagged null record;
1435 -- type B is new A with private;
1436 -- type C is new A with private;
1438 -- type B is new C with null record;
1439 -- type C is new B with null record;
1442 and then Parent_Typ /= Tagged_Type
1444 Collect (Parent_Typ);
1447 -- Collect the components containing tags of secondary dispatch
1450 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1451 while Present (Tag_Comp) loop
1452 pragma Assert (Present (Related_Type (Tag_Comp)));
1453 Append_Elmt (Tag_Comp, Components_List);
1455 Tag_Comp := Next_Tag_Component (Tag_Comp);
1459 -- Start of processing for Collect_Interface_Components
1462 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1463 and then Is_Tagged_Type (Tagged_Type));
1465 Components_List := New_Elmt_List;
1466 Collect (Tagged_Type);
1467 end Collect_Interface_Components;
1469 -----------------------------
1470 -- Collect_Interfaces_Info --
1471 -----------------------------
1473 procedure Collect_Interfaces_Info
1475 Ifaces_List : out Elist_Id;
1476 Components_List : out Elist_Id;
1477 Tags_List : out Elist_Id)
1479 Comps_List : Elist_Id;
1480 Comp_Elmt : Elmt_Id;
1481 Comp_Iface : Entity_Id;
1482 Iface_Elmt : Elmt_Id;
1485 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1486 -- Search for the secondary tag associated with the interface type
1487 -- Iface that is implemented by T.
1493 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1497 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1499 and then Ekind (Node (ADT)) = E_Constant
1500 and then Related_Type (Node (ADT)) /= Iface
1502 -- Skip the secondary dispatch tables of Iface
1510 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1514 -- Start of processing for Collect_Interfaces_Info
1517 Collect_Interfaces (T, Ifaces_List);
1518 Collect_Interface_Components (T, Comps_List);
1520 -- Search for the record component and tag associated with each
1521 -- interface type of T.
1523 Components_List := New_Elmt_List;
1524 Tags_List := New_Elmt_List;
1526 Iface_Elmt := First_Elmt (Ifaces_List);
1527 while Present (Iface_Elmt) loop
1528 Iface := Node (Iface_Elmt);
1530 -- Associate the primary tag component and the primary dispatch table
1531 -- with all the interfaces that are parents of T
1533 if Is_Ancestor (Iface, T) then
1534 Append_Elmt (First_Tag_Component (T), Components_List);
1535 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1537 -- Otherwise search for the tag component and secondary dispatch
1541 Comp_Elmt := First_Elmt (Comps_List);
1542 while Present (Comp_Elmt) loop
1543 Comp_Iface := Related_Type (Node (Comp_Elmt));
1545 if Comp_Iface = Iface
1546 or else Is_Ancestor (Iface, Comp_Iface)
1548 Append_Elmt (Node (Comp_Elmt), Components_List);
1549 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1553 Next_Elmt (Comp_Elmt);
1555 pragma Assert (Present (Comp_Elmt));
1558 Next_Elmt (Iface_Elmt);
1560 end Collect_Interfaces_Info;
1562 ----------------------------------
1563 -- Collect_Primitive_Operations --
1564 ----------------------------------
1566 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1567 B_Type : constant Entity_Id := Base_Type (T);
1568 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1569 B_Scope : Entity_Id := Scope (B_Type);
1573 Formal_Derived : Boolean := False;
1577 -- For tagged types, the primitive operations are collected as they
1578 -- are declared, and held in an explicit list which is simply returned.
1580 if Is_Tagged_Type (B_Type) then
1581 return Primitive_Operations (B_Type);
1583 -- An untagged generic type that is a derived type inherits the
1584 -- primitive operations of its parent type. Other formal types only
1585 -- have predefined operators, which are not explicitly represented.
1587 elsif Is_Generic_Type (B_Type) then
1588 if Nkind (B_Decl) = N_Formal_Type_Declaration
1589 and then Nkind (Formal_Type_Definition (B_Decl))
1590 = N_Formal_Derived_Type_Definition
1592 Formal_Derived := True;
1594 return New_Elmt_List;
1598 Op_List := New_Elmt_List;
1600 if B_Scope = Standard_Standard then
1601 if B_Type = Standard_String then
1602 Append_Elmt (Standard_Op_Concat, Op_List);
1604 elsif B_Type = Standard_Wide_String then
1605 Append_Elmt (Standard_Op_Concatw, Op_List);
1611 elsif (Is_Package_Or_Generic_Package (B_Scope)
1613 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1615 or else Is_Derived_Type (B_Type)
1617 -- The primitive operations appear after the base type, except
1618 -- if the derivation happens within the private part of B_Scope
1619 -- and the type is a private type, in which case both the type
1620 -- and some primitive operations may appear before the base
1621 -- type, and the list of candidates starts after the type.
1623 if In_Open_Scopes (B_Scope)
1624 and then Scope (T) = B_Scope
1625 and then In_Private_Part (B_Scope)
1627 Id := Next_Entity (T);
1629 Id := Next_Entity (B_Type);
1632 while Present (Id) loop
1634 -- Note that generic formal subprograms are not
1635 -- considered to be primitive operations and thus
1636 -- are never inherited.
1638 if Is_Overloadable (Id)
1639 and then Nkind (Parent (Parent (Id)))
1640 not in N_Formal_Subprogram_Declaration
1644 if Base_Type (Etype (Id)) = B_Type then
1647 Formal := First_Formal (Id);
1648 while Present (Formal) loop
1649 if Base_Type (Etype (Formal)) = B_Type then
1653 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1655 (Designated_Type (Etype (Formal))) = B_Type
1661 Next_Formal (Formal);
1665 -- For a formal derived type, the only primitives are the
1666 -- ones inherited from the parent type. Operations appearing
1667 -- in the package declaration are not primitive for it.
1670 and then (not Formal_Derived
1671 or else Present (Alias (Id)))
1673 -- In the special case of an equality operator aliased to
1674 -- an overriding dispatching equality belonging to the same
1675 -- type, we don't include it in the list of primitives.
1676 -- This avoids inheriting multiple equality operators when
1677 -- deriving from untagged private types whose full type is
1678 -- tagged, which can otherwise cause ambiguities. Note that
1679 -- this should only happen for this kind of untagged parent
1680 -- type, since normally dispatching operations are inherited
1681 -- using the type's Primitive_Operations list.
1683 if Chars (Id) = Name_Op_Eq
1684 and then Is_Dispatching_Operation (Id)
1685 and then Present (Alias (Id))
1686 and then Is_Overriding_Operation (Alias (Id))
1687 and then Base_Type (Etype (First_Entity (Id))) =
1688 Base_Type (Etype (First_Entity (Alias (Id))))
1692 -- Include the subprogram in the list of primitives
1695 Append_Elmt (Id, Op_List);
1702 -- For a type declared in System, some of its operations
1703 -- may appear in the target-specific extension to System.
1706 and then Chars (B_Scope) = Name_System
1707 and then Scope (B_Scope) = Standard_Standard
1708 and then Present_System_Aux
1710 B_Scope := System_Aux_Id;
1711 Id := First_Entity (System_Aux_Id);
1717 end Collect_Primitive_Operations;
1719 -----------------------------------
1720 -- Compile_Time_Constraint_Error --
1721 -----------------------------------
1723 function Compile_Time_Constraint_Error
1726 Ent : Entity_Id := Empty;
1727 Loc : Source_Ptr := No_Location;
1728 Warn : Boolean := False) return Node_Id
1730 Msgc : String (1 .. Msg'Length + 2);
1731 -- Copy of message, with room for possible ? and ! at end
1741 -- A static constraint error in an instance body is not a fatal error.
1742 -- we choose to inhibit the message altogether, because there is no
1743 -- obvious node (for now) on which to post it. On the other hand the
1744 -- offending node must be replaced with a constraint_error in any case.
1746 -- No messages are generated if we already posted an error on this node
1748 if not Error_Posted (N) then
1749 if Loc /= No_Location then
1755 Msgc (1 .. Msg'Length) := Msg;
1758 -- Message is a warning, even in Ada 95 case
1760 if Msg (Msg'Last) = '?' then
1763 -- In Ada 83, all messages are warnings. In the private part and
1764 -- the body of an instance, constraint_checks are only warnings.
1765 -- We also make this a warning if the Warn parameter is set.
1768 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1774 elsif In_Instance_Not_Visible then
1779 -- Otherwise we have a real error message (Ada 95 static case)
1780 -- and we make this an unconditional message. Note that in the
1781 -- warning case we do not make the message unconditional, it seems
1782 -- quite reasonable to delete messages like this (about exceptions
1783 -- that will be raised) in dead code.
1791 -- Should we generate a warning? The answer is not quite yes. The
1792 -- very annoying exception occurs in the case of a short circuit
1793 -- operator where the left operand is static and decisive. Climb
1794 -- parents to see if that is the case we have here. Conditional
1795 -- expressions with decisive conditions are a similar situation.
1803 -- And then with False as left operand
1805 if Nkind (P) = N_And_Then
1806 and then Compile_Time_Known_Value (Left_Opnd (P))
1807 and then Is_False (Expr_Value (Left_Opnd (P)))
1812 -- OR ELSE with True as left operand
1814 elsif Nkind (P) = N_Or_Else
1815 and then Compile_Time_Known_Value (Left_Opnd (P))
1816 and then Is_True (Expr_Value (Left_Opnd (P)))
1821 -- Conditional expression
1823 elsif Nkind (P) = N_Conditional_Expression then
1825 Cond : constant Node_Id := First (Expressions (P));
1826 Texp : constant Node_Id := Next (Cond);
1827 Fexp : constant Node_Id := Next (Texp);
1830 if Compile_Time_Known_Value (Cond) then
1832 -- Condition is True and we are in the right operand
1834 if Is_True (Expr_Value (Cond))
1835 and then OldP = Fexp
1840 -- Condition is False and we are in the left operand
1842 elsif Is_False (Expr_Value (Cond))
1843 and then OldP = Texp
1851 -- Special case for component association in aggregates, where
1852 -- we want to keep climbing up to the parent aggregate.
1854 elsif Nkind (P) = N_Component_Association
1855 and then Nkind (Parent (P)) = N_Aggregate
1859 -- Keep going if within subexpression
1862 exit when Nkind (P) not in N_Subexpr;
1867 if Present (Ent) then
1868 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1870 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1874 if Inside_Init_Proc then
1876 ("\?& will be raised for objects of this type",
1877 N, Standard_Constraint_Error, Eloc);
1880 ("\?& will be raised at run time",
1881 N, Standard_Constraint_Error, Eloc);
1886 ("\static expression fails Constraint_Check", Eloc);
1887 Set_Error_Posted (N);
1893 end Compile_Time_Constraint_Error;
1895 -----------------------
1896 -- Conditional_Delay --
1897 -----------------------
1899 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1901 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1902 Set_Has_Delayed_Freeze (New_Ent);
1904 end Conditional_Delay;
1906 -------------------------
1907 -- Copy_Parameter_List --
1908 -------------------------
1910 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1911 Loc : constant Source_Ptr := Sloc (Subp_Id);
1916 if No (First_Formal (Subp_Id)) then
1920 Formal := First_Formal (Subp_Id);
1921 while Present (Formal) loop
1923 (Make_Parameter_Specification (Loc,
1924 Defining_Identifier =>
1925 Make_Defining_Identifier (Sloc (Formal),
1926 Chars => Chars (Formal)),
1927 In_Present => In_Present (Parent (Formal)),
1928 Out_Present => Out_Present (Parent (Formal)),
1930 New_Reference_To (Etype (Formal), Loc),
1932 New_Copy_Tree (Expression (Parent (Formal)))),
1935 Next_Formal (Formal);
1940 end Copy_Parameter_List;
1942 --------------------
1943 -- Current_Entity --
1944 --------------------
1946 -- The currently visible definition for a given identifier is the
1947 -- one most chained at the start of the visibility chain, i.e. the
1948 -- one that is referenced by the Node_Id value of the name of the
1949 -- given identifier.
1951 function Current_Entity (N : Node_Id) return Entity_Id is
1953 return Get_Name_Entity_Id (Chars (N));
1956 -----------------------------
1957 -- Current_Entity_In_Scope --
1958 -----------------------------
1960 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1962 CS : constant Entity_Id := Current_Scope;
1964 Transient_Case : constant Boolean := Scope_Is_Transient;
1967 E := Get_Name_Entity_Id (Chars (N));
1969 and then Scope (E) /= CS
1970 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1976 end Current_Entity_In_Scope;
1982 function Current_Scope return Entity_Id is
1984 if Scope_Stack.Last = -1 then
1985 return Standard_Standard;
1988 C : constant Entity_Id :=
1989 Scope_Stack.Table (Scope_Stack.Last).Entity;
1994 return Standard_Standard;
2000 ------------------------
2001 -- Current_Subprogram --
2002 ------------------------
2004 function Current_Subprogram return Entity_Id is
2005 Scop : constant Entity_Id := Current_Scope;
2007 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2010 return Enclosing_Subprogram (Scop);
2012 end Current_Subprogram;
2014 ---------------------
2015 -- Defining_Entity --
2016 ---------------------
2018 function Defining_Entity (N : Node_Id) return Entity_Id is
2019 K : constant Node_Kind := Nkind (N);
2020 Err : Entity_Id := Empty;
2025 N_Subprogram_Declaration |
2026 N_Abstract_Subprogram_Declaration |
2028 N_Package_Declaration |
2029 N_Subprogram_Renaming_Declaration |
2030 N_Subprogram_Body_Stub |
2031 N_Generic_Subprogram_Declaration |
2032 N_Generic_Package_Declaration |
2033 N_Formal_Subprogram_Declaration
2035 return Defining_Entity (Specification (N));
2038 N_Component_Declaration |
2039 N_Defining_Program_Unit_Name |
2040 N_Discriminant_Specification |
2042 N_Entry_Declaration |
2043 N_Entry_Index_Specification |
2044 N_Exception_Declaration |
2045 N_Exception_Renaming_Declaration |
2046 N_Formal_Object_Declaration |
2047 N_Formal_Package_Declaration |
2048 N_Formal_Type_Declaration |
2049 N_Full_Type_Declaration |
2050 N_Implicit_Label_Declaration |
2051 N_Incomplete_Type_Declaration |
2052 N_Loop_Parameter_Specification |
2053 N_Number_Declaration |
2054 N_Object_Declaration |
2055 N_Object_Renaming_Declaration |
2056 N_Package_Body_Stub |
2057 N_Parameter_Specification |
2058 N_Private_Extension_Declaration |
2059 N_Private_Type_Declaration |
2061 N_Protected_Body_Stub |
2062 N_Protected_Type_Declaration |
2063 N_Single_Protected_Declaration |
2064 N_Single_Task_Declaration |
2065 N_Subtype_Declaration |
2068 N_Task_Type_Declaration
2070 return Defining_Identifier (N);
2073 return Defining_Entity (Proper_Body (N));
2076 N_Function_Instantiation |
2077 N_Function_Specification |
2078 N_Generic_Function_Renaming_Declaration |
2079 N_Generic_Package_Renaming_Declaration |
2080 N_Generic_Procedure_Renaming_Declaration |
2082 N_Package_Instantiation |
2083 N_Package_Renaming_Declaration |
2084 N_Package_Specification |
2085 N_Procedure_Instantiation |
2086 N_Procedure_Specification
2089 Nam : constant Node_Id := Defining_Unit_Name (N);
2092 if Nkind (Nam) in N_Entity then
2095 -- For Error, make up a name and attach to declaration
2096 -- so we can continue semantic analysis
2098 elsif Nam = Error then
2099 Err := Make_Temporary (Sloc (N), 'T');
2100 Set_Defining_Unit_Name (N, Err);
2103 -- If not an entity, get defining identifier
2106 return Defining_Identifier (Nam);
2110 when N_Block_Statement =>
2111 return Entity (Identifier (N));
2114 raise Program_Error;
2117 end Defining_Entity;
2119 --------------------------
2120 -- Denotes_Discriminant --
2121 --------------------------
2123 function Denotes_Discriminant
2125 Check_Concurrent : Boolean := False) return Boolean
2129 if not Is_Entity_Name (N)
2130 or else No (Entity (N))
2137 -- If we are checking for a protected type, the discriminant may have
2138 -- been rewritten as the corresponding discriminal of the original type
2139 -- or of the corresponding concurrent record, depending on whether we
2140 -- are in the spec or body of the protected type.
2142 return Ekind (E) = E_Discriminant
2145 and then Ekind (E) = E_In_Parameter
2146 and then Present (Discriminal_Link (E))
2148 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2150 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2152 end Denotes_Discriminant;
2154 -------------------------
2155 -- Denotes_Same_Object --
2156 -------------------------
2158 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2160 -- If we have entity names, then must be same entity
2162 if Is_Entity_Name (A1) then
2163 if Is_Entity_Name (A2) then
2164 return Entity (A1) = Entity (A2);
2169 -- No match if not same node kind
2171 elsif Nkind (A1) /= Nkind (A2) then
2174 -- For selected components, must have same prefix and selector
2176 elsif Nkind (A1) = N_Selected_Component then
2177 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
2179 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
2181 -- For explicit dereferences, prefixes must be same
2183 elsif Nkind (A1) = N_Explicit_Dereference then
2184 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
2186 -- For indexed components, prefixes and all subscripts must be the same
2188 elsif Nkind (A1) = N_Indexed_Component then
2189 if Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
2195 Indx1 := First (Expressions (A1));
2196 Indx2 := First (Expressions (A2));
2197 while Present (Indx1) loop
2199 -- Shouldn't we be checking that values are the same???
2201 if not Denotes_Same_Object (Indx1, Indx2) then
2215 -- For slices, prefixes must match and bounds must match
2217 elsif Nkind (A1) = N_Slice
2218 and then Denotes_Same_Object (Prefix (A1), Prefix (A2))
2221 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2224 Get_Index_Bounds (Etype (A1), Lo1, Hi1);
2225 Get_Index_Bounds (Etype (A2), Lo2, Hi2);
2227 -- Check whether bounds are statically identical. There is no
2228 -- attempt to detect partial overlap of slices.
2230 -- What about an array and a slice of an array???
2232 return Denotes_Same_Object (Lo1, Lo2)
2233 and then Denotes_Same_Object (Hi1, Hi2);
2236 -- Literals will appear as indices. Isn't this where we should check
2237 -- Known_At_Compile_Time at least if we are generating warnings ???
2239 elsif Nkind (A1) = N_Integer_Literal then
2240 return Intval (A1) = Intval (A2);
2245 end Denotes_Same_Object;
2247 -------------------------
2248 -- Denotes_Same_Prefix --
2249 -------------------------
2251 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2254 if Is_Entity_Name (A1) then
2255 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component) then
2256 return Denotes_Same_Object (A1, Prefix (A2))
2257 or else Denotes_Same_Prefix (A1, Prefix (A2));
2262 elsif Is_Entity_Name (A2) then
2263 return Denotes_Same_Prefix (A2, A1);
2265 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2267 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2270 Root1, Root2 : Node_Id;
2271 Depth1, Depth2 : Int := 0;
2274 Root1 := Prefix (A1);
2275 while not Is_Entity_Name (Root1) loop
2277 (Root1, N_Selected_Component, N_Indexed_Component)
2281 Root1 := Prefix (Root1);
2284 Depth1 := Depth1 + 1;
2287 Root2 := Prefix (A2);
2288 while not Is_Entity_Name (Root2) loop
2290 (Root2, N_Selected_Component, N_Indexed_Component)
2294 Root2 := Prefix (Root2);
2297 Depth2 := Depth2 + 1;
2300 -- If both have the same depth and they do not denote the same
2301 -- object, they are disjoint and not warning is needed.
2303 if Depth1 = Depth2 then
2306 elsif Depth1 > Depth2 then
2307 Root1 := Prefix (A1);
2308 for I in 1 .. Depth1 - Depth2 - 1 loop
2309 Root1 := Prefix (Root1);
2312 return Denotes_Same_Object (Root1, A2);
2315 Root2 := Prefix (A2);
2316 for I in 1 .. Depth2 - Depth1 - 1 loop
2317 Root2 := Prefix (Root2);
2320 return Denotes_Same_Object (A1, Root2);
2327 end Denotes_Same_Prefix;
2329 ----------------------
2330 -- Denotes_Variable --
2331 ----------------------
2333 function Denotes_Variable (N : Node_Id) return Boolean is
2335 return Is_Variable (N) and then Paren_Count (N) = 0;
2336 end Denotes_Variable;
2338 -----------------------------
2339 -- Depends_On_Discriminant --
2340 -----------------------------
2342 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2347 Get_Index_Bounds (N, L, H);
2348 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2349 end Depends_On_Discriminant;
2351 -------------------------
2352 -- Designate_Same_Unit --
2353 -------------------------
2355 function Designate_Same_Unit
2357 Name2 : Node_Id) return Boolean
2359 K1 : constant Node_Kind := Nkind (Name1);
2360 K2 : constant Node_Kind := Nkind (Name2);
2362 function Prefix_Node (N : Node_Id) return Node_Id;
2363 -- Returns the parent unit name node of a defining program unit name
2364 -- or the prefix if N is a selected component or an expanded name.
2366 function Select_Node (N : Node_Id) return Node_Id;
2367 -- Returns the defining identifier node of a defining program unit
2368 -- name or the selector node if N is a selected component or an
2375 function Prefix_Node (N : Node_Id) return Node_Id is
2377 if Nkind (N) = N_Defining_Program_Unit_Name then
2389 function Select_Node (N : Node_Id) return Node_Id is
2391 if Nkind (N) = N_Defining_Program_Unit_Name then
2392 return Defining_Identifier (N);
2395 return Selector_Name (N);
2399 -- Start of processing for Designate_Next_Unit
2402 if (K1 = N_Identifier or else
2403 K1 = N_Defining_Identifier)
2405 (K2 = N_Identifier or else
2406 K2 = N_Defining_Identifier)
2408 return Chars (Name1) = Chars (Name2);
2411 (K1 = N_Expanded_Name or else
2412 K1 = N_Selected_Component or else
2413 K1 = N_Defining_Program_Unit_Name)
2415 (K2 = N_Expanded_Name or else
2416 K2 = N_Selected_Component or else
2417 K2 = N_Defining_Program_Unit_Name)
2420 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2422 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2427 end Designate_Same_Unit;
2429 ----------------------------
2430 -- Enclosing_Generic_Body --
2431 ----------------------------
2433 function Enclosing_Generic_Body
2434 (N : Node_Id) return Node_Id
2442 while Present (P) loop
2443 if Nkind (P) = N_Package_Body
2444 or else Nkind (P) = N_Subprogram_Body
2446 Spec := Corresponding_Spec (P);
2448 if Present (Spec) then
2449 Decl := Unit_Declaration_Node (Spec);
2451 if Nkind (Decl) = N_Generic_Package_Declaration
2452 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2463 end Enclosing_Generic_Body;
2465 ----------------------------
2466 -- Enclosing_Generic_Unit --
2467 ----------------------------
2469 function Enclosing_Generic_Unit
2470 (N : Node_Id) return Node_Id
2478 while Present (P) loop
2479 if Nkind (P) = N_Generic_Package_Declaration
2480 or else Nkind (P) = N_Generic_Subprogram_Declaration
2484 elsif Nkind (P) = N_Package_Body
2485 or else Nkind (P) = N_Subprogram_Body
2487 Spec := Corresponding_Spec (P);
2489 if Present (Spec) then
2490 Decl := Unit_Declaration_Node (Spec);
2492 if Nkind (Decl) = N_Generic_Package_Declaration
2493 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2504 end Enclosing_Generic_Unit;
2506 -------------------------------
2507 -- Enclosing_Lib_Unit_Entity --
2508 -------------------------------
2510 function Enclosing_Lib_Unit_Entity return Entity_Id is
2511 Unit_Entity : Entity_Id;
2514 -- Look for enclosing library unit entity by following scope links.
2515 -- Equivalent to, but faster than indexing through the scope stack.
2517 Unit_Entity := Current_Scope;
2518 while (Present (Scope (Unit_Entity))
2519 and then Scope (Unit_Entity) /= Standard_Standard)
2520 and not Is_Child_Unit (Unit_Entity)
2522 Unit_Entity := Scope (Unit_Entity);
2526 end Enclosing_Lib_Unit_Entity;
2528 -----------------------------
2529 -- Enclosing_Lib_Unit_Node --
2530 -----------------------------
2532 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2533 Current_Node : Node_Id;
2537 while Present (Current_Node)
2538 and then Nkind (Current_Node) /= N_Compilation_Unit
2540 Current_Node := Parent (Current_Node);
2543 if Nkind (Current_Node) /= N_Compilation_Unit then
2547 return Current_Node;
2548 end Enclosing_Lib_Unit_Node;
2550 --------------------------
2551 -- Enclosing_Subprogram --
2552 --------------------------
2554 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2555 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2558 if Dynamic_Scope = Standard_Standard then
2561 elsif Dynamic_Scope = Empty then
2564 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2565 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2567 elsif Ekind (Dynamic_Scope) = E_Block
2568 or else Ekind (Dynamic_Scope) = E_Return_Statement
2570 return Enclosing_Subprogram (Dynamic_Scope);
2572 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2573 return Get_Task_Body_Procedure (Dynamic_Scope);
2575 -- No body is generated if the protected operation is eliminated
2577 elsif Convention (Dynamic_Scope) = Convention_Protected
2578 and then not Is_Eliminated (Dynamic_Scope)
2579 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2581 return Protected_Body_Subprogram (Dynamic_Scope);
2584 return Dynamic_Scope;
2586 end Enclosing_Subprogram;
2588 ------------------------
2589 -- Ensure_Freeze_Node --
2590 ------------------------
2592 procedure Ensure_Freeze_Node (E : Entity_Id) is
2596 if No (Freeze_Node (E)) then
2597 FN := Make_Freeze_Entity (Sloc (E));
2598 Set_Has_Delayed_Freeze (E);
2599 Set_Freeze_Node (E, FN);
2600 Set_Access_Types_To_Process (FN, No_Elist);
2601 Set_TSS_Elist (FN, No_Elist);
2604 end Ensure_Freeze_Node;
2610 procedure Enter_Name (Def_Id : Entity_Id) is
2611 C : constant Entity_Id := Current_Entity (Def_Id);
2612 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2613 S : constant Entity_Id := Current_Scope;
2616 Generate_Definition (Def_Id);
2618 -- Add new name to current scope declarations. Check for duplicate
2619 -- declaration, which may or may not be a genuine error.
2623 -- Case of previous entity entered because of a missing declaration
2624 -- or else a bad subtype indication. Best is to use the new entity,
2625 -- and make the previous one invisible.
2627 if Etype (E) = Any_Type then
2628 Set_Is_Immediately_Visible (E, False);
2630 -- Case of renaming declaration constructed for package instances.
2631 -- if there is an explicit declaration with the same identifier,
2632 -- the renaming is not immediately visible any longer, but remains
2633 -- visible through selected component notation.
2635 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2636 and then not Comes_From_Source (E)
2638 Set_Is_Immediately_Visible (E, False);
2640 -- The new entity may be the package renaming, which has the same
2641 -- same name as a generic formal which has been seen already.
2643 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2644 and then not Comes_From_Source (Def_Id)
2646 Set_Is_Immediately_Visible (E, False);
2648 -- For a fat pointer corresponding to a remote access to subprogram,
2649 -- we use the same identifier as the RAS type, so that the proper
2650 -- name appears in the stub. This type is only retrieved through
2651 -- the RAS type and never by visibility, and is not added to the
2652 -- visibility list (see below).
2654 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2655 and then Present (Corresponding_Remote_Type (Def_Id))
2659 -- A controller component for a type extension overrides the
2660 -- inherited component.
2662 elsif Chars (E) = Name_uController then
2665 -- Case of an implicit operation or derived literal. The new entity
2666 -- hides the implicit one, which is removed from all visibility,
2667 -- i.e. the entity list of its scope, and homonym chain of its name.
2669 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2670 or else Is_Internal (E)
2674 Prev_Vis : Entity_Id;
2675 Decl : constant Node_Id := Parent (E);
2678 -- If E is an implicit declaration, it cannot be the first
2679 -- entity in the scope.
2681 Prev := First_Entity (Current_Scope);
2682 while Present (Prev)
2683 and then Next_Entity (Prev) /= E
2690 -- If E is not on the entity chain of the current scope,
2691 -- it is an implicit declaration in the generic formal
2692 -- part of a generic subprogram. When analyzing the body,
2693 -- the generic formals are visible but not on the entity
2694 -- chain of the subprogram. The new entity will become
2695 -- the visible one in the body.
2698 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2702 Set_Next_Entity (Prev, Next_Entity (E));
2704 if No (Next_Entity (Prev)) then
2705 Set_Last_Entity (Current_Scope, Prev);
2708 if E = Current_Entity (E) then
2712 Prev_Vis := Current_Entity (E);
2713 while Homonym (Prev_Vis) /= E loop
2714 Prev_Vis := Homonym (Prev_Vis);
2718 if Present (Prev_Vis) then
2720 -- Skip E in the visibility chain
2722 Set_Homonym (Prev_Vis, Homonym (E));
2725 Set_Name_Entity_Id (Chars (E), Homonym (E));
2730 -- This section of code could use a comment ???
2732 elsif Present (Etype (E))
2733 and then Is_Concurrent_Type (Etype (E))
2738 -- If the homograph is a protected component renaming, it should not
2739 -- be hiding the current entity. Such renamings are treated as weak
2742 elsif Is_Prival (E) then
2743 Set_Is_Immediately_Visible (E, False);
2745 -- In this case the current entity is a protected component renaming.
2746 -- Perform minimal decoration by setting the scope and return since
2747 -- the prival should not be hiding other visible entities.
2749 elsif Is_Prival (Def_Id) then
2750 Set_Scope (Def_Id, Current_Scope);
2753 -- Analogous to privals, the discriminal generated for an entry
2754 -- index parameter acts as a weak declaration. Perform minimal
2755 -- decoration to avoid bogus errors.
2757 elsif Is_Discriminal (Def_Id)
2758 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2760 Set_Scope (Def_Id, Current_Scope);
2763 -- In the body or private part of an instance, a type extension
2764 -- may introduce a component with the same name as that of an
2765 -- actual. The legality rule is not enforced, but the semantics
2766 -- of the full type with two components of the same name are not
2767 -- clear at this point ???
2769 elsif In_Instance_Not_Visible then
2772 -- When compiling a package body, some child units may have become
2773 -- visible. They cannot conflict with local entities that hide them.
2775 elsif Is_Child_Unit (E)
2776 and then In_Open_Scopes (Scope (E))
2777 and then not Is_Immediately_Visible (E)
2781 -- Conversely, with front-end inlining we may compile the parent
2782 -- body first, and a child unit subsequently. The context is now
2783 -- the parent spec, and body entities are not visible.
2785 elsif Is_Child_Unit (Def_Id)
2786 and then Is_Package_Body_Entity (E)
2787 and then not In_Package_Body (Current_Scope)
2791 -- Case of genuine duplicate declaration
2794 Error_Msg_Sloc := Sloc (E);
2796 -- If the previous declaration is an incomplete type declaration
2797 -- this may be an attempt to complete it with a private type.
2798 -- The following avoids confusing cascaded errors.
2800 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2801 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2804 ("incomplete type cannot be completed with a private " &
2805 "declaration", Parent (Def_Id));
2806 Set_Is_Immediately_Visible (E, False);
2807 Set_Full_View (E, Def_Id);
2809 -- An inherited component of a record conflicts with a new
2810 -- discriminant. The discriminant is inserted first in the scope,
2811 -- but the error should be posted on it, not on the component.
2813 elsif Ekind (E) = E_Discriminant
2814 and then Present (Scope (Def_Id))
2815 and then Scope (Def_Id) /= Current_Scope
2817 Error_Msg_Sloc := Sloc (Def_Id);
2818 Error_Msg_N ("& conflicts with declaration#", E);
2821 -- If the name of the unit appears in its own context clause,
2822 -- a dummy package with the name has already been created, and
2823 -- the error emitted. Try to continue quietly.
2825 elsif Error_Posted (E)
2826 and then Sloc (E) = No_Location
2827 and then Nkind (Parent (E)) = N_Package_Specification
2828 and then Current_Scope = Standard_Standard
2830 Set_Scope (Def_Id, Current_Scope);
2834 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2836 -- Avoid cascaded messages with duplicate components in
2839 if Ekind_In (E, E_Component, E_Discriminant) then
2844 if Nkind (Parent (Parent (Def_Id))) =
2845 N_Generic_Subprogram_Declaration
2847 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2849 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2852 -- If entity is in standard, then we are in trouble, because
2853 -- it means that we have a library package with a duplicated
2854 -- name. That's hard to recover from, so abort!
2856 if S = Standard_Standard then
2857 raise Unrecoverable_Error;
2859 -- Otherwise we continue with the declaration. Having two
2860 -- identical declarations should not cause us too much trouble!
2868 -- If we fall through, declaration is OK , or OK enough to continue
2870 -- If Def_Id is a discriminant or a record component we are in the
2871 -- midst of inheriting components in a derived record definition.
2872 -- Preserve their Ekind and Etype.
2874 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
2877 -- If a type is already set, leave it alone (happens whey a type
2878 -- declaration is reanalyzed following a call to the optimizer)
2880 elsif Present (Etype (Def_Id)) then
2883 -- Otherwise, the kind E_Void insures that premature uses of the entity
2884 -- will be detected. Any_Type insures that no cascaded errors will occur
2887 Set_Ekind (Def_Id, E_Void);
2888 Set_Etype (Def_Id, Any_Type);
2891 -- Inherited discriminants and components in derived record types are
2892 -- immediately visible. Itypes are not.
2894 if Ekind_In (Def_Id, E_Discriminant, E_Component)
2895 or else (No (Corresponding_Remote_Type (Def_Id))
2896 and then not Is_Itype (Def_Id))
2898 Set_Is_Immediately_Visible (Def_Id);
2899 Set_Current_Entity (Def_Id);
2902 Set_Homonym (Def_Id, C);
2903 Append_Entity (Def_Id, S);
2904 Set_Public_Status (Def_Id);
2906 -- Warn if new entity hides an old one
2908 if Warn_On_Hiding and then Present (C)
2910 -- Don't warn for record components since they always have a well
2911 -- defined scope which does not confuse other uses. Note that in
2912 -- some cases, Ekind has not been set yet.
2914 and then Ekind (C) /= E_Component
2915 and then Ekind (C) /= E_Discriminant
2916 and then Nkind (Parent (C)) /= N_Component_Declaration
2917 and then Ekind (Def_Id) /= E_Component
2918 and then Ekind (Def_Id) /= E_Discriminant
2919 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2921 -- Don't warn for one character variables. It is too common to use
2922 -- such variables as locals and will just cause too many false hits.
2924 and then Length_Of_Name (Chars (C)) /= 1
2926 -- Don't warn for non-source entities
2928 and then Comes_From_Source (C)
2929 and then Comes_From_Source (Def_Id)
2931 -- Don't warn unless entity in question is in extended main source
2933 and then In_Extended_Main_Source_Unit (Def_Id)
2935 -- Finally, the hidden entity must be either immediately visible
2936 -- or use visible (from a used package)
2939 (Is_Immediately_Visible (C)
2941 Is_Potentially_Use_Visible (C))
2943 Error_Msg_Sloc := Sloc (C);
2944 Error_Msg_N ("declaration hides &#?", Def_Id);
2948 --------------------------
2949 -- Explain_Limited_Type --
2950 --------------------------
2952 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2956 -- For array, component type must be limited
2958 if Is_Array_Type (T) then
2959 Error_Msg_Node_2 := T;
2961 ("\component type& of type& is limited", N, Component_Type (T));
2962 Explain_Limited_Type (Component_Type (T), N);
2964 elsif Is_Record_Type (T) then
2966 -- No need for extra messages if explicit limited record
2968 if Is_Limited_Record (Base_Type (T)) then
2972 -- Otherwise find a limited component. Check only components that
2973 -- come from source, or inherited components that appear in the
2974 -- source of the ancestor.
2976 C := First_Component (T);
2977 while Present (C) loop
2978 if Is_Limited_Type (Etype (C))
2980 (Comes_From_Source (C)
2982 (Present (Original_Record_Component (C))
2984 Comes_From_Source (Original_Record_Component (C))))
2986 Error_Msg_Node_2 := T;
2987 Error_Msg_NE ("\component& of type& has limited type", N, C);
2988 Explain_Limited_Type (Etype (C), N);
2995 -- The type may be declared explicitly limited, even if no component
2996 -- of it is limited, in which case we fall out of the loop.
2999 end Explain_Limited_Type;
3005 procedure Find_Actual
3007 Formal : out Entity_Id;
3010 Parnt : constant Node_Id := Parent (N);
3014 if (Nkind (Parnt) = N_Indexed_Component
3016 Nkind (Parnt) = N_Selected_Component)
3017 and then N = Prefix (Parnt)
3019 Find_Actual (Parnt, Formal, Call);
3022 elsif Nkind (Parnt) = N_Parameter_Association
3023 and then N = Explicit_Actual_Parameter (Parnt)
3025 Call := Parent (Parnt);
3027 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3036 -- If we have a call to a subprogram look for the parameter. Note that
3037 -- we exclude overloaded calls, since we don't know enough to be sure
3038 -- of giving the right answer in this case.
3040 if Is_Entity_Name (Name (Call))
3041 and then Present (Entity (Name (Call)))
3042 and then Is_Overloadable (Entity (Name (Call)))
3043 and then not Is_Overloaded (Name (Call))
3045 -- Fall here if we are definitely a parameter
3047 Actual := First_Actual (Call);
3048 Formal := First_Formal (Entity (Name (Call)));
3049 while Present (Formal) and then Present (Actual) loop
3053 Actual := Next_Actual (Actual);
3054 Formal := Next_Formal (Formal);
3059 -- Fall through here if we did not find matching actual
3065 -------------------------------------
3066 -- Find_Corresponding_Discriminant --
3067 -------------------------------------
3069 function Find_Corresponding_Discriminant
3071 Typ : Entity_Id) return Entity_Id
3073 Par_Disc : Entity_Id;
3074 Old_Disc : Entity_Id;
3075 New_Disc : Entity_Id;
3078 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3080 -- The original type may currently be private, and the discriminant
3081 -- only appear on its full view.
3083 if Is_Private_Type (Scope (Par_Disc))
3084 and then not Has_Discriminants (Scope (Par_Disc))
3085 and then Present (Full_View (Scope (Par_Disc)))
3087 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3089 Old_Disc := First_Discriminant (Scope (Par_Disc));
3092 if Is_Class_Wide_Type (Typ) then
3093 New_Disc := First_Discriminant (Root_Type (Typ));
3095 New_Disc := First_Discriminant (Typ);
3098 while Present (Old_Disc) and then Present (New_Disc) loop
3099 if Old_Disc = Par_Disc then
3102 Next_Discriminant (Old_Disc);
3103 Next_Discriminant (New_Disc);
3107 -- Should always find it
3109 raise Program_Error;
3110 end Find_Corresponding_Discriminant;
3112 --------------------------
3113 -- Find_Overlaid_Entity --
3114 --------------------------
3116 procedure Find_Overlaid_Entity
3118 Ent : out Entity_Id;
3124 -- We are looking for one of the two following forms:
3126 -- for X'Address use Y'Address
3130 -- Const : constant Address := expr;
3132 -- for X'Address use Const;
3134 -- In the second case, the expr is either Y'Address, or recursively a
3135 -- constant that eventually references Y'Address.
3140 if Nkind (N) = N_Attribute_Definition_Clause
3141 and then Chars (N) = Name_Address
3143 Expr := Expression (N);
3145 -- This loop checks the form of the expression for Y'Address,
3146 -- using recursion to deal with intermediate constants.
3149 -- Check for Y'Address
3151 if Nkind (Expr) = N_Attribute_Reference
3152 and then Attribute_Name (Expr) = Name_Address
3154 Expr := Prefix (Expr);
3157 -- Check for Const where Const is a constant entity
3159 elsif Is_Entity_Name (Expr)
3160 and then Ekind (Entity (Expr)) = E_Constant
3162 Expr := Constant_Value (Entity (Expr));
3164 -- Anything else does not need checking
3171 -- This loop checks the form of the prefix for an entity,
3172 -- using recursion to deal with intermediate components.
3175 -- Check for Y where Y is an entity
3177 if Is_Entity_Name (Expr) then
3178 Ent := Entity (Expr);
3181 -- Check for components
3184 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3186 Expr := Prefix (Expr);
3189 -- Anything else does not need checking
3196 end Find_Overlaid_Entity;
3198 -------------------------
3199 -- Find_Parameter_Type --
3200 -------------------------
3202 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3204 if Nkind (Param) /= N_Parameter_Specification then
3207 -- For an access parameter, obtain the type from the formal entity
3208 -- itself, because access to subprogram nodes do not carry a type.
3209 -- Shouldn't we always use the formal entity ???
3211 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3212 return Etype (Defining_Identifier (Param));
3215 return Etype (Parameter_Type (Param));
3217 end Find_Parameter_Type;
3219 -----------------------------
3220 -- Find_Static_Alternative --
3221 -----------------------------
3223 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3224 Expr : constant Node_Id := Expression (N);
3225 Val : constant Uint := Expr_Value (Expr);
3230 Alt := First (Alternatives (N));
3233 if Nkind (Alt) /= N_Pragma then
3234 Choice := First (Discrete_Choices (Alt));
3235 while Present (Choice) loop
3237 -- Others choice, always matches
3239 if Nkind (Choice) = N_Others_Choice then
3242 -- Range, check if value is in the range
3244 elsif Nkind (Choice) = N_Range then
3246 Val >= Expr_Value (Low_Bound (Choice))
3248 Val <= Expr_Value (High_Bound (Choice));
3250 -- Choice is a subtype name. Note that we know it must
3251 -- be a static subtype, since otherwise it would have
3252 -- been diagnosed as illegal.
3254 elsif Is_Entity_Name (Choice)
3255 and then Is_Type (Entity (Choice))
3257 exit Search when Is_In_Range (Expr, Etype (Choice),
3258 Assume_Valid => False);
3260 -- Choice is a subtype indication
3262 elsif Nkind (Choice) = N_Subtype_Indication then
3264 C : constant Node_Id := Constraint (Choice);
3265 R : constant Node_Id := Range_Expression (C);
3269 Val >= Expr_Value (Low_Bound (R))
3271 Val <= Expr_Value (High_Bound (R));
3274 -- Choice is a simple expression
3277 exit Search when Val = Expr_Value (Choice);
3285 pragma Assert (Present (Alt));
3288 -- The above loop *must* terminate by finding a match, since
3289 -- we know the case statement is valid, and the value of the
3290 -- expression is known at compile time. When we fall out of
3291 -- the loop, Alt points to the alternative that we know will
3292 -- be selected at run time.
3295 end Find_Static_Alternative;
3301 function First_Actual (Node : Node_Id) return Node_Id is
3305 if No (Parameter_Associations (Node)) then
3309 N := First (Parameter_Associations (Node));
3311 if Nkind (N) = N_Parameter_Association then
3312 return First_Named_Actual (Node);
3318 -------------------------
3319 -- Full_Qualified_Name --
3320 -------------------------
3322 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3324 pragma Warnings (Off, Res);
3326 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3327 -- Compute recursively the qualified name without NUL at the end
3329 ----------------------------------
3330 -- Internal_Full_Qualified_Name --
3331 ----------------------------------
3333 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3334 Ent : Entity_Id := E;
3335 Parent_Name : String_Id := No_String;
3338 -- Deals properly with child units
3340 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3341 Ent := Defining_Identifier (Ent);
3344 -- Compute qualification recursively (only "Standard" has no scope)
3346 if Present (Scope (Scope (Ent))) then
3347 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3350 -- Every entity should have a name except some expanded blocks
3351 -- don't bother about those.
3353 if Chars (Ent) = No_Name then
3357 -- Add a period between Name and qualification
3359 if Parent_Name /= No_String then
3360 Start_String (Parent_Name);
3361 Store_String_Char (Get_Char_Code ('.'));
3367 -- Generates the entity name in upper case
3369 Get_Decoded_Name_String (Chars (Ent));
3371 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3373 end Internal_Full_Qualified_Name;
3375 -- Start of processing for Full_Qualified_Name
3378 Res := Internal_Full_Qualified_Name (E);
3379 Store_String_Char (Get_Char_Code (ASCII.NUL));
3381 end Full_Qualified_Name;
3383 -----------------------
3384 -- Gather_Components --
3385 -----------------------
3387 procedure Gather_Components
3389 Comp_List : Node_Id;
3390 Governed_By : List_Id;
3392 Report_Errors : out Boolean)
3396 Discrete_Choice : Node_Id;
3397 Comp_Item : Node_Id;
3399 Discrim : Entity_Id;
3400 Discrim_Name : Node_Id;
3401 Discrim_Value : Node_Id;
3404 Report_Errors := False;
3406 if No (Comp_List) or else Null_Present (Comp_List) then
3409 elsif Present (Component_Items (Comp_List)) then
3410 Comp_Item := First (Component_Items (Comp_List));
3416 while Present (Comp_Item) loop
3418 -- Skip the tag of a tagged record, the interface tags, as well
3419 -- as all items that are not user components (anonymous types,
3420 -- rep clauses, Parent field, controller field).
3422 if Nkind (Comp_Item) = N_Component_Declaration then
3424 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3426 if not Is_Tag (Comp)
3427 and then Chars (Comp) /= Name_uParent
3428 and then Chars (Comp) /= Name_uController
3430 Append_Elmt (Comp, Into);
3438 if No (Variant_Part (Comp_List)) then
3441 Discrim_Name := Name (Variant_Part (Comp_List));
3442 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3445 -- Look for the discriminant that governs this variant part.
3446 -- The discriminant *must* be in the Governed_By List
3448 Assoc := First (Governed_By);
3449 Find_Constraint : loop
3450 Discrim := First (Choices (Assoc));
3451 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3452 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3454 Chars (Corresponding_Discriminant (Entity (Discrim)))
3455 = Chars (Discrim_Name))
3456 or else Chars (Original_Record_Component (Entity (Discrim)))
3457 = Chars (Discrim_Name);
3459 if No (Next (Assoc)) then
3460 if not Is_Constrained (Typ)
3461 and then Is_Derived_Type (Typ)
3462 and then Present (Stored_Constraint (Typ))
3464 -- If the type is a tagged type with inherited discriminants,
3465 -- use the stored constraint on the parent in order to find
3466 -- the values of discriminants that are otherwise hidden by an
3467 -- explicit constraint. Renamed discriminants are handled in
3470 -- If several parent discriminants are renamed by a single
3471 -- discriminant of the derived type, the call to obtain the
3472 -- Corresponding_Discriminant field only retrieves the last
3473 -- of them. We recover the constraint on the others from the
3474 -- Stored_Constraint as well.
3481 D := First_Discriminant (Etype (Typ));
3482 C := First_Elmt (Stored_Constraint (Typ));
3483 while Present (D) and then Present (C) loop
3484 if Chars (Discrim_Name) = Chars (D) then
3485 if Is_Entity_Name (Node (C))
3486 and then Entity (Node (C)) = Entity (Discrim)
3488 -- D is renamed by Discrim, whose value is given in
3495 Make_Component_Association (Sloc (Typ),
3497 (New_Occurrence_Of (D, Sloc (Typ))),
3498 Duplicate_Subexpr_No_Checks (Node (C)));
3500 exit Find_Constraint;
3503 Next_Discriminant (D);
3510 if No (Next (Assoc)) then
3511 Error_Msg_NE (" missing value for discriminant&",
3512 First (Governed_By), Discrim_Name);
3513 Report_Errors := True;
3518 end loop Find_Constraint;
3520 Discrim_Value := Expression (Assoc);
3522 if not Is_OK_Static_Expression (Discrim_Value) then
3524 ("value for discriminant & must be static!",
3525 Discrim_Value, Discrim);
3526 Why_Not_Static (Discrim_Value);
3527 Report_Errors := True;
3531 Search_For_Discriminant_Value : declare
3537 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3540 Find_Discrete_Value : while Present (Variant) loop
3541 Discrete_Choice := First (Discrete_Choices (Variant));
3542 while Present (Discrete_Choice) loop
3544 exit Find_Discrete_Value when
3545 Nkind (Discrete_Choice) = N_Others_Choice;
3547 Get_Index_Bounds (Discrete_Choice, Low, High);
3549 UI_Low := Expr_Value (Low);
3550 UI_High := Expr_Value (High);
3552 exit Find_Discrete_Value when
3553 UI_Low <= UI_Discrim_Value
3555 UI_High >= UI_Discrim_Value;
3557 Next (Discrete_Choice);
3560 Next_Non_Pragma (Variant);
3561 end loop Find_Discrete_Value;
3562 end Search_For_Discriminant_Value;
3564 if No (Variant) then
3566 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3567 Report_Errors := True;
3571 -- If we have found the corresponding choice, recursively add its
3572 -- components to the Into list.
3574 Gather_Components (Empty,
3575 Component_List (Variant), Governed_By, Into, Report_Errors);
3576 end Gather_Components;
3578 ------------------------
3579 -- Get_Actual_Subtype --
3580 ------------------------
3582 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3583 Typ : constant Entity_Id := Etype (N);
3584 Utyp : Entity_Id := Underlying_Type (Typ);
3593 -- If what we have is an identifier that references a subprogram
3594 -- formal, or a variable or constant object, then we get the actual
3595 -- subtype from the referenced entity if one has been built.
3597 if Nkind (N) = N_Identifier
3599 (Is_Formal (Entity (N))
3600 or else Ekind (Entity (N)) = E_Constant
3601 or else Ekind (Entity (N)) = E_Variable)
3602 and then Present (Actual_Subtype (Entity (N)))
3604 return Actual_Subtype (Entity (N));
3606 -- Actual subtype of unchecked union is always itself. We never need
3607 -- the "real" actual subtype. If we did, we couldn't get it anyway
3608 -- because the discriminant is not available. The restrictions on
3609 -- Unchecked_Union are designed to make sure that this is OK.
3611 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3614 -- Here for the unconstrained case, we must find actual subtype
3615 -- No actual subtype is available, so we must build it on the fly.
3617 -- Checking the type, not the underlying type, for constrainedness
3618 -- seems to be necessary. Maybe all the tests should be on the type???
3620 elsif (not Is_Constrained (Typ))
3621 and then (Is_Array_Type (Utyp)
3622 or else (Is_Record_Type (Utyp)
3623 and then Has_Discriminants (Utyp)))
3624 and then not Has_Unknown_Discriminants (Utyp)
3625 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3627 -- Nothing to do if in spec expression (why not???)
3629 if In_Spec_Expression then
3632 elsif Is_Private_Type (Typ)
3633 and then not Has_Discriminants (Typ)
3635 -- If the type has no discriminants, there is no subtype to
3636 -- build, even if the underlying type is discriminated.
3640 -- Else build the actual subtype
3643 Decl := Build_Actual_Subtype (Typ, N);
3644 Atyp := Defining_Identifier (Decl);
3646 -- If Build_Actual_Subtype generated a new declaration then use it
3650 -- The actual subtype is an Itype, so analyze the declaration,
3651 -- but do not attach it to the tree, to get the type defined.
3653 Set_Parent (Decl, N);
3654 Set_Is_Itype (Atyp);
3655 Analyze (Decl, Suppress => All_Checks);
3656 Set_Associated_Node_For_Itype (Atyp, N);
3657 Set_Has_Delayed_Freeze (Atyp, False);
3659 -- We need to freeze the actual subtype immediately. This is
3660 -- needed, because otherwise this Itype will not get frozen
3661 -- at all, and it is always safe to freeze on creation because
3662 -- any associated types must be frozen at this point.
3664 Freeze_Itype (Atyp, N);
3667 -- Otherwise we did not build a declaration, so return original
3674 -- For all remaining cases, the actual subtype is the same as
3675 -- the nominal type.
3680 end Get_Actual_Subtype;
3682 -------------------------------------
3683 -- Get_Actual_Subtype_If_Available --
3684 -------------------------------------
3686 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3687 Typ : constant Entity_Id := Etype (N);
3690 -- If what we have is an identifier that references a subprogram
3691 -- formal, or a variable or constant object, then we get the actual
3692 -- subtype from the referenced entity if one has been built.
3694 if Nkind (N) = N_Identifier
3696 (Is_Formal (Entity (N))
3697 or else Ekind (Entity (N)) = E_Constant
3698 or else Ekind (Entity (N)) = E_Variable)
3699 and then Present (Actual_Subtype (Entity (N)))
3701 return Actual_Subtype (Entity (N));
3703 -- Otherwise the Etype of N is returned unchanged
3708 end Get_Actual_Subtype_If_Available;
3710 -------------------------------
3711 -- Get_Default_External_Name --
3712 -------------------------------
3714 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3716 Get_Decoded_Name_String (Chars (E));
3718 if Opt.External_Name_Imp_Casing = Uppercase then
3719 Set_Casing (All_Upper_Case);
3721 Set_Casing (All_Lower_Case);
3725 Make_String_Literal (Sloc (E),
3726 Strval => String_From_Name_Buffer);
3727 end Get_Default_External_Name;
3729 ---------------------------
3730 -- Get_Enum_Lit_From_Pos --
3731 ---------------------------
3733 function Get_Enum_Lit_From_Pos
3736 Loc : Source_Ptr) return Node_Id
3741 -- In the case where the literal is of type Character, Wide_Character
3742 -- or Wide_Wide_Character or of a type derived from them, there needs
3743 -- to be some special handling since there is no explicit chain of
3744 -- literals to search. Instead, an N_Character_Literal node is created
3745 -- with the appropriate Char_Code and Chars fields.
3747 if Is_Standard_Character_Type (T) then
3748 Set_Character_Literal_Name (UI_To_CC (Pos));
3750 Make_Character_Literal (Loc,
3752 Char_Literal_Value => Pos);
3754 -- For all other cases, we have a complete table of literals, and
3755 -- we simply iterate through the chain of literal until the one
3756 -- with the desired position value is found.
3760 Lit := First_Literal (Base_Type (T));
3761 for J in 1 .. UI_To_Int (Pos) loop
3765 return New_Occurrence_Of (Lit, Loc);
3767 end Get_Enum_Lit_From_Pos;
3769 ------------------------
3770 -- Get_Generic_Entity --
3771 ------------------------
3773 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3774 Ent : constant Entity_Id := Entity (Name (N));
3776 if Present (Renamed_Object (Ent)) then
3777 return Renamed_Object (Ent);
3781 end Get_Generic_Entity;
3783 ----------------------
3784 -- Get_Index_Bounds --
3785 ----------------------
3787 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3788 Kind : constant Node_Kind := Nkind (N);
3792 if Kind = N_Range then
3794 H := High_Bound (N);
3796 elsif Kind = N_Subtype_Indication then
3797 R := Range_Expression (Constraint (N));
3805 L := Low_Bound (Range_Expression (Constraint (N)));
3806 H := High_Bound (Range_Expression (Constraint (N)));
3809 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3810 if Error_Posted (Scalar_Range (Entity (N))) then
3814 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3815 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3818 L := Low_Bound (Scalar_Range (Entity (N)));
3819 H := High_Bound (Scalar_Range (Entity (N)));
3823 -- N is an expression, indicating a range with one value
3828 end Get_Index_Bounds;
3830 ----------------------------------
3831 -- Get_Library_Unit_Name_string --
3832 ----------------------------------
3834 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3835 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3838 Get_Unit_Name_String (Unit_Name_Id);
3840 -- Remove seven last character (" (spec)" or " (body)")
3842 Name_Len := Name_Len - 7;
3843 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3844 end Get_Library_Unit_Name_String;
3846 ------------------------
3847 -- Get_Name_Entity_Id --
3848 ------------------------
3850 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3852 return Entity_Id (Get_Name_Table_Info (Id));
3853 end Get_Name_Entity_Id;
3859 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3861 return Get_Pragma_Id (Pragma_Name (N));
3864 ---------------------------
3865 -- Get_Referenced_Object --
3866 ---------------------------
3868 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3873 while Is_Entity_Name (R)
3874 and then Present (Renamed_Object (Entity (R)))
3876 R := Renamed_Object (Entity (R));
3880 end Get_Referenced_Object;
3882 ------------------------
3883 -- Get_Renamed_Entity --
3884 ------------------------
3886 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3891 while Present (Renamed_Entity (R)) loop
3892 R := Renamed_Entity (R);
3896 end Get_Renamed_Entity;
3898 -------------------------
3899 -- Get_Subprogram_Body --
3900 -------------------------
3902 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3906 Decl := Unit_Declaration_Node (E);
3908 if Nkind (Decl) = N_Subprogram_Body then
3911 -- The below comment is bad, because it is possible for
3912 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3914 else -- Nkind (Decl) = N_Subprogram_Declaration
3916 if Present (Corresponding_Body (Decl)) then
3917 return Unit_Declaration_Node (Corresponding_Body (Decl));
3919 -- Imported subprogram case
3925 end Get_Subprogram_Body;
3927 ---------------------------
3928 -- Get_Subprogram_Entity --
3929 ---------------------------
3931 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3936 if Nkind (Nod) = N_Accept_Statement then
3937 Nam := Entry_Direct_Name (Nod);
3939 -- For an entry call, the prefix of the call is a selected component.
3940 -- Need additional code for internal calls ???
3942 elsif Nkind (Nod) = N_Entry_Call_Statement then
3943 if Nkind (Name (Nod)) = N_Selected_Component then
3944 Nam := Entity (Selector_Name (Name (Nod)));
3953 if Nkind (Nam) = N_Explicit_Dereference then
3954 Proc := Etype (Prefix (Nam));
3955 elsif Is_Entity_Name (Nam) then
3956 Proc := Entity (Nam);
3961 if Is_Object (Proc) then
3962 Proc := Etype (Proc);
3965 if Ekind (Proc) = E_Access_Subprogram_Type then
3966 Proc := Directly_Designated_Type (Proc);
3969 if not Is_Subprogram (Proc)
3970 and then Ekind (Proc) /= E_Subprogram_Type
3976 end Get_Subprogram_Entity;
3978 -----------------------------
3979 -- Get_Task_Body_Procedure --
3980 -----------------------------
3982 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3984 -- Note: A task type may be the completion of a private type with
3985 -- discriminants. When performing elaboration checks on a task
3986 -- declaration, the current view of the type may be the private one,
3987 -- and the procedure that holds the body of the task is held in its
3990 -- This is an odd function, why not have Task_Body_Procedure do
3991 -- the following digging???
3993 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3994 end Get_Task_Body_Procedure;
3996 -----------------------
3997 -- Has_Access_Values --
3998 -----------------------
4000 function Has_Access_Values (T : Entity_Id) return Boolean is
4001 Typ : constant Entity_Id := Underlying_Type (T);
4004 -- Case of a private type which is not completed yet. This can only
4005 -- happen in the case of a generic format type appearing directly, or
4006 -- as a component of the type to which this function is being applied
4007 -- at the top level. Return False in this case, since we certainly do
4008 -- not know that the type contains access types.
4013 elsif Is_Access_Type (Typ) then
4016 elsif Is_Array_Type (Typ) then
4017 return Has_Access_Values (Component_Type (Typ));
4019 elsif Is_Record_Type (Typ) then
4024 -- Loop to Check components
4026 Comp := First_Component_Or_Discriminant (Typ);
4027 while Present (Comp) loop
4029 -- Check for access component, tag field does not count, even
4030 -- though it is implemented internally using an access type.
4032 if Has_Access_Values (Etype (Comp))
4033 and then Chars (Comp) /= Name_uTag
4038 Next_Component_Or_Discriminant (Comp);
4047 end Has_Access_Values;
4049 ------------------------------
4050 -- Has_Compatible_Alignment --
4051 ------------------------------
4053 function Has_Compatible_Alignment
4055 Expr : Node_Id) return Alignment_Result
4057 function Has_Compatible_Alignment_Internal
4060 Default : Alignment_Result) return Alignment_Result;
4061 -- This is the internal recursive function that actually does the work.
4062 -- There is one additional parameter, which says what the result should
4063 -- be if no alignment information is found, and there is no definite
4064 -- indication of compatible alignments. At the outer level, this is set
4065 -- to Unknown, but for internal recursive calls in the case where types
4066 -- are known to be correct, it is set to Known_Compatible.
4068 ---------------------------------------
4069 -- Has_Compatible_Alignment_Internal --
4070 ---------------------------------------
4072 function Has_Compatible_Alignment_Internal
4075 Default : Alignment_Result) return Alignment_Result
4077 Result : Alignment_Result := Known_Compatible;
4078 -- Holds the current status of the result. Note that once a value of
4079 -- Known_Incompatible is set, it is sticky and does not get changed
4080 -- to Unknown (the value in Result only gets worse as we go along,
4083 Offs : Uint := No_Uint;
4084 -- Set to a factor of the offset from the base object when Expr is a
4085 -- selected or indexed component, based on Component_Bit_Offset and
4086 -- Component_Size respectively. A negative value is used to represent
4087 -- a value which is not known at compile time.
4089 procedure Check_Prefix;
4090 -- Checks the prefix recursively in the case where the expression
4091 -- is an indexed or selected component.
4093 procedure Set_Result (R : Alignment_Result);
4094 -- If R represents a worse outcome (unknown instead of known
4095 -- compatible, or known incompatible), then set Result to R.
4101 procedure Check_Prefix is
4103 -- The subtlety here is that in doing a recursive call to check
4104 -- the prefix, we have to decide what to do in the case where we
4105 -- don't find any specific indication of an alignment problem.
4107 -- At the outer level, we normally set Unknown as the result in
4108 -- this case, since we can only set Known_Compatible if we really
4109 -- know that the alignment value is OK, but for the recursive
4110 -- call, in the case where the types match, and we have not
4111 -- specified a peculiar alignment for the object, we are only
4112 -- concerned about suspicious rep clauses, the default case does
4113 -- not affect us, since the compiler will, in the absence of such
4114 -- rep clauses, ensure that the alignment is correct.
4116 if Default = Known_Compatible
4118 (Etype (Obj) = Etype (Expr)
4119 and then (Unknown_Alignment (Obj)
4121 Alignment (Obj) = Alignment (Etype (Obj))))
4124 (Has_Compatible_Alignment_Internal
4125 (Obj, Prefix (Expr), Known_Compatible));
4127 -- In all other cases, we need a full check on the prefix
4131 (Has_Compatible_Alignment_Internal
4132 (Obj, Prefix (Expr), Unknown));
4140 procedure Set_Result (R : Alignment_Result) is
4147 -- Start of processing for Has_Compatible_Alignment_Internal
4150 -- If Expr is a selected component, we must make sure there is no
4151 -- potentially troublesome component clause, and that the record is
4154 if Nkind (Expr) = N_Selected_Component then
4156 -- Packed record always generate unknown alignment
4158 if Is_Packed (Etype (Prefix (Expr))) then
4159 Set_Result (Unknown);
4162 -- Check prefix and component offset
4165 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4167 -- If Expr is an indexed component, we must make sure there is no
4168 -- potentially troublesome Component_Size clause and that the array
4169 -- is not bit-packed.
4171 elsif Nkind (Expr) = N_Indexed_Component then
4173 Typ : constant Entity_Id := Etype (Prefix (Expr));
4174 Ind : constant Node_Id := First_Index (Typ);
4177 -- Bit packed array always generates unknown alignment
4179 if Is_Bit_Packed_Array (Typ) then
4180 Set_Result (Unknown);
4183 -- Check prefix and component offset
4186 Offs := Component_Size (Typ);
4188 -- Small optimization: compute the full offset when possible
4191 and then Offs > Uint_0
4192 and then Present (Ind)
4193 and then Nkind (Ind) = N_Range
4194 and then Compile_Time_Known_Value (Low_Bound (Ind))
4195 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4197 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4198 - Expr_Value (Low_Bound ((Ind))));
4203 -- If we have a null offset, the result is entirely determined by
4204 -- the base object and has already been computed recursively.
4206 if Offs = Uint_0 then
4209 -- Case where we know the alignment of the object
4211 elsif Known_Alignment (Obj) then
4213 ObjA : constant Uint := Alignment (Obj);
4214 ExpA : Uint := No_Uint;
4215 SizA : Uint := No_Uint;
4218 -- If alignment of Obj is 1, then we are always OK
4221 Set_Result (Known_Compatible);
4223 -- Alignment of Obj is greater than 1, so we need to check
4226 -- If we have an offset, see if it is compatible
4228 if Offs /= No_Uint and Offs > Uint_0 then
4229 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4230 Set_Result (Known_Incompatible);
4233 -- See if Expr is an object with known alignment
4235 elsif Is_Entity_Name (Expr)
4236 and then Known_Alignment (Entity (Expr))
4238 ExpA := Alignment (Entity (Expr));
4240 -- Otherwise, we can use the alignment of the type of
4241 -- Expr given that we already checked for
4242 -- discombobulating rep clauses for the cases of indexed
4243 -- and selected components above.
4245 elsif Known_Alignment (Etype (Expr)) then
4246 ExpA := Alignment (Etype (Expr));
4248 -- Otherwise the alignment is unknown
4251 Set_Result (Default);
4254 -- If we got an alignment, see if it is acceptable
4256 if ExpA /= No_Uint and then ExpA < ObjA then
4257 Set_Result (Known_Incompatible);
4260 -- If Expr is not a piece of a larger object, see if size
4261 -- is given. If so, check that it is not too small for the
4262 -- required alignment.
4264 if Offs /= No_Uint then
4267 -- See if Expr is an object with known size
4269 elsif Is_Entity_Name (Expr)
4270 and then Known_Static_Esize (Entity (Expr))
4272 SizA := Esize (Entity (Expr));
4274 -- Otherwise, we check the object size of the Expr type
4276 elsif Known_Static_Esize (Etype (Expr)) then
4277 SizA := Esize (Etype (Expr));
4280 -- If we got a size, see if it is a multiple of the Obj
4281 -- alignment, if not, then the alignment cannot be
4282 -- acceptable, since the size is always a multiple of the
4285 if SizA /= No_Uint then
4286 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4287 Set_Result (Known_Incompatible);
4293 -- If we do not know required alignment, any non-zero offset is a
4294 -- potential problem (but certainly may be OK, so result is unknown).
4296 elsif Offs /= No_Uint then
4297 Set_Result (Unknown);
4299 -- If we can't find the result by direct comparison of alignment
4300 -- values, then there is still one case that we can determine known
4301 -- result, and that is when we can determine that the types are the
4302 -- same, and no alignments are specified. Then we known that the
4303 -- alignments are compatible, even if we don't know the alignment
4304 -- value in the front end.
4306 elsif Etype (Obj) = Etype (Expr) then
4308 -- Types are the same, but we have to check for possible size
4309 -- and alignments on the Expr object that may make the alignment
4310 -- different, even though the types are the same.
4312 if Is_Entity_Name (Expr) then
4314 -- First check alignment of the Expr object. Any alignment less
4315 -- than Maximum_Alignment is worrisome since this is the case
4316 -- where we do not know the alignment of Obj.
4318 if Known_Alignment (Entity (Expr))
4320 UI_To_Int (Alignment (Entity (Expr))) <
4321 Ttypes.Maximum_Alignment
4323 Set_Result (Unknown);
4325 -- Now check size of Expr object. Any size that is not an
4326 -- even multiple of Maximum_Alignment is also worrisome
4327 -- since it may cause the alignment of the object to be less
4328 -- than the alignment of the type.
4330 elsif Known_Static_Esize (Entity (Expr))
4332 (UI_To_Int (Esize (Entity (Expr))) mod
4333 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4336 Set_Result (Unknown);
4338 -- Otherwise same type is decisive
4341 Set_Result (Known_Compatible);
4345 -- Another case to deal with is when there is an explicit size or
4346 -- alignment clause when the types are not the same. If so, then the
4347 -- result is Unknown. We don't need to do this test if the Default is
4348 -- Unknown, since that result will be set in any case.
4350 elsif Default /= Unknown
4351 and then (Has_Size_Clause (Etype (Expr))
4353 Has_Alignment_Clause (Etype (Expr)))
4355 Set_Result (Unknown);
4357 -- If no indication found, set default
4360 Set_Result (Default);
4363 -- Return worst result found
4366 end Has_Compatible_Alignment_Internal;
4368 -- Start of processing for Has_Compatible_Alignment
4371 -- If Obj has no specified alignment, then set alignment from the type
4372 -- alignment. Perhaps we should always do this, but for sure we should
4373 -- do it when there is an address clause since we can do more if the
4374 -- alignment is known.
4376 if Unknown_Alignment (Obj) then
4377 Set_Alignment (Obj, Alignment (Etype (Obj)));
4380 -- Now do the internal call that does all the work
4382 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4383 end Has_Compatible_Alignment;
4385 ----------------------
4386 -- Has_Declarations --
4387 ----------------------
4389 function Has_Declarations (N : Node_Id) return Boolean is
4391 return Nkind_In (Nkind (N), N_Accept_Statement,
4393 N_Compilation_Unit_Aux,
4399 N_Package_Specification);
4400 end Has_Declarations;
4402 -------------------------------------------
4403 -- Has_Discriminant_Dependent_Constraint --
4404 -------------------------------------------
4406 function Has_Discriminant_Dependent_Constraint
4407 (Comp : Entity_Id) return Boolean
4409 Comp_Decl : constant Node_Id := Parent (Comp);
4410 Subt_Indic : constant Node_Id :=
4411 Subtype_Indication (Component_Definition (Comp_Decl));
4416 if Nkind (Subt_Indic) = N_Subtype_Indication then
4417 Constr := Constraint (Subt_Indic);
4419 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4420 Assn := First (Constraints (Constr));
4421 while Present (Assn) loop
4422 case Nkind (Assn) is
4423 when N_Subtype_Indication |
4427 if Depends_On_Discriminant (Assn) then
4431 when N_Discriminant_Association =>
4432 if Depends_On_Discriminant (Expression (Assn)) then
4447 end Has_Discriminant_Dependent_Constraint;
4449 --------------------
4450 -- Has_Infinities --
4451 --------------------
4453 function Has_Infinities (E : Entity_Id) return Boolean is
4456 Is_Floating_Point_Type (E)
4457 and then Nkind (Scalar_Range (E)) = N_Range
4458 and then Includes_Infinities (Scalar_Range (E));
4461 --------------------
4462 -- Has_Interfaces --
4463 --------------------
4465 function Has_Interfaces
4467 Use_Full_View : Boolean := True) return Boolean
4472 -- Handle concurrent types
4474 if Is_Concurrent_Type (T) then
4475 Typ := Corresponding_Record_Type (T);
4480 if not Present (Typ)
4481 or else not Is_Record_Type (Typ)
4482 or else not Is_Tagged_Type (Typ)
4487 -- Handle private types
4490 and then Present (Full_View (Typ))
4492 Typ := Full_View (Typ);
4495 -- Handle concurrent record types
4497 if Is_Concurrent_Record_Type (Typ)
4498 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4504 if Is_Interface (Typ)
4506 (Is_Record_Type (Typ)
4507 and then Present (Interfaces (Typ))
4508 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4513 exit when Etype (Typ) = Typ
4515 -- Handle private types
4517 or else (Present (Full_View (Etype (Typ)))
4518 and then Full_View (Etype (Typ)) = Typ)
4520 -- Protect the frontend against wrong source with cyclic
4523 or else Etype (Typ) = T;
4525 -- Climb to the ancestor type handling private types
4527 if Present (Full_View (Etype (Typ))) then
4528 Typ := Full_View (Etype (Typ));
4537 ------------------------
4538 -- Has_Null_Exclusion --
4539 ------------------------
4541 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4544 when N_Access_Definition |
4545 N_Access_Function_Definition |
4546 N_Access_Procedure_Definition |
4547 N_Access_To_Object_Definition |
4549 N_Derived_Type_Definition |
4550 N_Function_Specification |
4551 N_Subtype_Declaration =>
4552 return Null_Exclusion_Present (N);
4554 when N_Component_Definition |
4555 N_Formal_Object_Declaration |
4556 N_Object_Renaming_Declaration =>
4557 if Present (Subtype_Mark (N)) then
4558 return Null_Exclusion_Present (N);
4559 else pragma Assert (Present (Access_Definition (N)));
4560 return Null_Exclusion_Present (Access_Definition (N));
4563 when N_Discriminant_Specification =>
4564 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4565 return Null_Exclusion_Present (Discriminant_Type (N));
4567 return Null_Exclusion_Present (N);
4570 when N_Object_Declaration =>
4571 if Nkind (Object_Definition (N)) = N_Access_Definition then
4572 return Null_Exclusion_Present (Object_Definition (N));
4574 return Null_Exclusion_Present (N);
4577 when N_Parameter_Specification =>
4578 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4579 return Null_Exclusion_Present (Parameter_Type (N));
4581 return Null_Exclusion_Present (N);
4588 end Has_Null_Exclusion;
4590 ------------------------
4591 -- Has_Null_Extension --
4592 ------------------------
4594 function Has_Null_Extension (T : Entity_Id) return Boolean is
4595 B : constant Entity_Id := Base_Type (T);
4600 if Nkind (Parent (B)) = N_Full_Type_Declaration
4601 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4603 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4605 if Present (Ext) then
4606 if Null_Present (Ext) then
4609 Comps := Component_List (Ext);
4611 -- The null component list is rewritten during analysis to
4612 -- include the parent component. Any other component indicates
4613 -- that the extension was not originally null.
4615 return Null_Present (Comps)
4616 or else No (Next (First (Component_Items (Comps))));
4625 end Has_Null_Extension;
4627 -------------------------------
4628 -- Has_Overriding_Initialize --
4629 -------------------------------
4631 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4632 BT : constant Entity_Id := Base_Type (T);
4637 if Is_Controlled (BT) then
4639 -- For derived types, check immediate ancestor, excluding
4640 -- Controlled itself.
4642 if Is_Derived_Type (BT)
4643 and then not In_Predefined_Unit (Etype (BT))
4644 and then Has_Overriding_Initialize (Etype (BT))
4648 elsif Present (Primitive_Operations (BT)) then
4649 P := First_Elmt (Primitive_Operations (BT));
4650 while Present (P) loop
4651 if Chars (Node (P)) = Name_Initialize
4652 and then Comes_From_Source (Node (P))
4663 elsif Has_Controlled_Component (BT) then
4664 Comp := First_Component (BT);
4665 while Present (Comp) loop
4666 if Has_Overriding_Initialize (Etype (Comp)) then
4670 Next_Component (Comp);
4678 end Has_Overriding_Initialize;
4680 --------------------------------------
4681 -- Has_Preelaborable_Initialization --
4682 --------------------------------------
4684 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4687 procedure Check_Components (E : Entity_Id);
4688 -- Check component/discriminant chain, sets Has_PE False if a component
4689 -- or discriminant does not meet the preelaborable initialization rules.
4691 ----------------------
4692 -- Check_Components --
4693 ----------------------
4695 procedure Check_Components (E : Entity_Id) is
4699 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4700 -- Returns True if and only if the expression denoted by N does not
4701 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4703 ---------------------------------
4704 -- Is_Preelaborable_Expression --
4705 ---------------------------------
4707 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4711 Comp_Type : Entity_Id;
4712 Is_Array_Aggr : Boolean;
4715 if Is_Static_Expression (N) then
4718 elsif Nkind (N) = N_Null then
4721 -- Attributes are allowed in general, even if their prefix is a
4722 -- formal type. (It seems that certain attributes known not to be
4723 -- static might not be allowed, but there are no rules to prevent
4726 elsif Nkind (N) = N_Attribute_Reference then
4729 -- The name of a discriminant evaluated within its parent type is
4730 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4731 -- names that denote discriminals as well as discriminants to
4732 -- catch references occurring within init procs.
4734 elsif Is_Entity_Name (N)
4736 (Ekind (Entity (N)) = E_Discriminant
4738 ((Ekind (Entity (N)) = E_Constant
4739 or else Ekind (Entity (N)) = E_In_Parameter)
4740 and then Present (Discriminal_Link (Entity (N)))))
4744 elsif Nkind (N) = N_Qualified_Expression then
4745 return Is_Preelaborable_Expression (Expression (N));
4747 -- For aggregates we have to check that each of the associations
4748 -- is preelaborable.
4750 elsif Nkind (N) = N_Aggregate
4751 or else Nkind (N) = N_Extension_Aggregate
4753 Is_Array_Aggr := Is_Array_Type (Etype (N));
4755 if Is_Array_Aggr then
4756 Comp_Type := Component_Type (Etype (N));
4759 -- Check the ancestor part of extension aggregates, which must
4760 -- be either the name of a type that has preelaborable init or
4761 -- an expression that is preelaborable.
4763 if Nkind (N) = N_Extension_Aggregate then
4765 Anc_Part : constant Node_Id := Ancestor_Part (N);
4768 if Is_Entity_Name (Anc_Part)
4769 and then Is_Type (Entity (Anc_Part))
4771 if not Has_Preelaborable_Initialization
4777 elsif not Is_Preelaborable_Expression (Anc_Part) then
4783 -- Check positional associations
4785 Exp := First (Expressions (N));
4786 while Present (Exp) loop
4787 if not Is_Preelaborable_Expression (Exp) then
4794 -- Check named associations
4796 Assn := First (Component_Associations (N));
4797 while Present (Assn) loop
4798 Choice := First (Choices (Assn));
4799 while Present (Choice) loop
4800 if Is_Array_Aggr then
4801 if Nkind (Choice) = N_Others_Choice then
4804 elsif Nkind (Choice) = N_Range then
4805 if not Is_Static_Range (Choice) then
4809 elsif not Is_Static_Expression (Choice) then
4814 Comp_Type := Etype (Choice);
4820 -- If the association has a <> at this point, then we have
4821 -- to check whether the component's type has preelaborable
4822 -- initialization. Note that this only occurs when the
4823 -- association's corresponding component does not have a
4824 -- default expression, the latter case having already been
4825 -- expanded as an expression for the association.
4827 if Box_Present (Assn) then
4828 if not Has_Preelaborable_Initialization (Comp_Type) then
4832 -- In the expression case we check whether the expression
4833 -- is preelaborable.
4836 not Is_Preelaborable_Expression (Expression (Assn))
4844 -- If we get here then aggregate as a whole is preelaborable
4848 -- All other cases are not preelaborable
4853 end Is_Preelaborable_Expression;
4855 -- Start of processing for Check_Components
4858 -- Loop through entities of record or protected type
4861 while Present (Ent) loop
4863 -- We are interested only in components and discriminants
4865 if Ekind_In (Ent, E_Component, E_Discriminant) then
4867 -- Get default expression if any. If there is no declaration
4868 -- node, it means we have an internal entity. The parent and
4869 -- tag fields are examples of such entities. For these cases,
4870 -- we just test the type of the entity.
4872 if Present (Declaration_Node (Ent)) then
4873 Exp := Expression (Declaration_Node (Ent));
4878 -- A component has PI if it has no default expression and the
4879 -- component type has PI.
4882 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4887 -- Require the default expression to be preelaborable
4889 elsif not Is_Preelaborable_Expression (Exp) then
4897 end Check_Components;
4899 -- Start of processing for Has_Preelaborable_Initialization
4902 -- Immediate return if already marked as known preelaborable init. This
4903 -- covers types for which this function has already been called once
4904 -- and returned True (in which case the result is cached), and also
4905 -- types to which a pragma Preelaborable_Initialization applies.
4907 if Known_To_Have_Preelab_Init (E) then
4911 -- If the type is a subtype representing a generic actual type, then
4912 -- test whether its base type has preelaborable initialization since
4913 -- the subtype representing the actual does not inherit this attribute
4914 -- from the actual or formal. (but maybe it should???)
4916 if Is_Generic_Actual_Type (E) then
4917 return Has_Preelaborable_Initialization (Base_Type (E));
4920 -- All elementary types have preelaborable initialization
4922 if Is_Elementary_Type (E) then
4925 -- Array types have PI if the component type has PI
4927 elsif Is_Array_Type (E) then
4928 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4930 -- A derived type has preelaborable initialization if its parent type
4931 -- has preelaborable initialization and (in the case of a derived record
4932 -- extension) if the non-inherited components all have preelaborable
4933 -- initialization. However, a user-defined controlled type with an
4934 -- overriding Initialize procedure does not have preelaborable
4937 elsif Is_Derived_Type (E) then
4939 -- If the derived type is a private extension then it doesn't have
4940 -- preelaborable initialization.
4942 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4946 -- First check whether ancestor type has preelaborable initialization
4948 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4950 -- If OK, check extension components (if any)
4952 if Has_PE and then Is_Record_Type (E) then
4953 Check_Components (First_Entity (E));
4956 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4957 -- with a user defined Initialize procedure does not have PI.
4960 and then Is_Controlled (E)
4961 and then Has_Overriding_Initialize (E)
4966 -- Private types not derived from a type having preelaborable init and
4967 -- that are not marked with pragma Preelaborable_Initialization do not
4968 -- have preelaborable initialization.
4970 elsif Is_Private_Type (E) then
4973 -- Record type has PI if it is non private and all components have PI
4975 elsif Is_Record_Type (E) then
4977 Check_Components (First_Entity (E));
4979 -- Protected types must not have entries, and components must meet
4980 -- same set of rules as for record components.
4982 elsif Is_Protected_Type (E) then
4983 if Has_Entries (E) then
4987 Check_Components (First_Entity (E));
4988 Check_Components (First_Private_Entity (E));
4991 -- Type System.Address always has preelaborable initialization
4993 elsif Is_RTE (E, RE_Address) then
4996 -- In all other cases, type does not have preelaborable initialization
5002 -- If type has preelaborable initialization, cache result
5005 Set_Known_To_Have_Preelab_Init (E);
5009 end Has_Preelaborable_Initialization;
5011 ---------------------------
5012 -- Has_Private_Component --
5013 ---------------------------
5015 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5016 Btype : Entity_Id := Base_Type (Type_Id);
5017 Component : Entity_Id;
5020 if Error_Posted (Type_Id)
5021 or else Error_Posted (Btype)
5026 if Is_Class_Wide_Type (Btype) then
5027 Btype := Root_Type (Btype);
5030 if Is_Private_Type (Btype) then
5032 UT : constant Entity_Id := Underlying_Type (Btype);
5035 if No (Full_View (Btype)) then
5036 return not Is_Generic_Type (Btype)
5037 and then not Is_Generic_Type (Root_Type (Btype));
5039 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5042 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5046 elsif Is_Array_Type (Btype) then
5047 return Has_Private_Component (Component_Type (Btype));
5049 elsif Is_Record_Type (Btype) then
5050 Component := First_Component (Btype);
5051 while Present (Component) loop
5052 if Has_Private_Component (Etype (Component)) then
5056 Next_Component (Component);
5061 elsif Is_Protected_Type (Btype)
5062 and then Present (Corresponding_Record_Type (Btype))
5064 return Has_Private_Component (Corresponding_Record_Type (Btype));
5069 end Has_Private_Component;
5075 function Has_Stream (T : Entity_Id) return Boolean is
5082 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5085 elsif Is_Array_Type (T) then
5086 return Has_Stream (Component_Type (T));
5088 elsif Is_Record_Type (T) then
5089 E := First_Component (T);
5090 while Present (E) loop
5091 if Has_Stream (Etype (E)) then
5100 elsif Is_Private_Type (T) then
5101 return Has_Stream (Underlying_Type (T));
5108 --------------------------
5109 -- Has_Tagged_Component --
5110 --------------------------
5112 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5116 if Is_Private_Type (Typ)
5117 and then Present (Underlying_Type (Typ))
5119 return Has_Tagged_Component (Underlying_Type (Typ));
5121 elsif Is_Array_Type (Typ) then
5122 return Has_Tagged_Component (Component_Type (Typ));
5124 elsif Is_Tagged_Type (Typ) then
5127 elsif Is_Record_Type (Typ) then
5128 Comp := First_Component (Typ);
5129 while Present (Comp) loop
5130 if Has_Tagged_Component (Etype (Comp)) then
5134 Next_Component (Comp);
5142 end Has_Tagged_Component;
5144 --------------------------
5145 -- Implements_Interface --
5146 --------------------------
5148 function Implements_Interface
5149 (Typ_Ent : Entity_Id;
5150 Iface_Ent : Entity_Id;
5151 Exclude_Parents : Boolean := False) return Boolean
5153 Ifaces_List : Elist_Id;
5155 Iface : Entity_Id := Base_Type (Iface_Ent);
5156 Typ : Entity_Id := Base_Type (Typ_Ent);
5159 if Is_Class_Wide_Type (Typ) then
5160 Typ := Root_Type (Typ);
5163 if not Has_Interfaces (Typ) then
5167 if Is_Class_Wide_Type (Iface) then
5168 Iface := Root_Type (Iface);
5171 Collect_Interfaces (Typ, Ifaces_List);
5173 Elmt := First_Elmt (Ifaces_List);
5174 while Present (Elmt) loop
5175 if Is_Ancestor (Node (Elmt), Typ)
5176 and then Exclude_Parents
5180 elsif Node (Elmt) = Iface then
5188 end Implements_Interface;
5194 function In_Instance return Boolean is
5195 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5201 and then S /= Standard_Standard
5203 if (Ekind (S) = E_Function
5204 or else Ekind (S) = E_Package
5205 or else Ekind (S) = E_Procedure)
5206 and then Is_Generic_Instance (S)
5208 -- A child instance is always compiled in the context of a parent
5209 -- instance. Nevertheless, the actuals are not analyzed in an
5210 -- instance context. We detect this case by examining the current
5211 -- compilation unit, which must be a child instance, and checking
5212 -- that it is not currently on the scope stack.
5214 if Is_Child_Unit (Curr_Unit)
5216 Nkind (Unit (Cunit (Current_Sem_Unit)))
5217 = N_Package_Instantiation
5218 and then not In_Open_Scopes (Curr_Unit)
5232 ----------------------
5233 -- In_Instance_Body --
5234 ----------------------
5236 function In_Instance_Body return Boolean is
5242 and then S /= Standard_Standard
5244 if (Ekind (S) = E_Function
5245 or else Ekind (S) = E_Procedure)
5246 and then Is_Generic_Instance (S)
5250 elsif Ekind (S) = E_Package
5251 and then In_Package_Body (S)
5252 and then Is_Generic_Instance (S)
5261 end In_Instance_Body;
5263 -----------------------------
5264 -- In_Instance_Not_Visible --
5265 -----------------------------
5267 function In_Instance_Not_Visible return Boolean is
5273 and then S /= Standard_Standard
5275 if (Ekind (S) = E_Function
5276 or else Ekind (S) = E_Procedure)
5277 and then Is_Generic_Instance (S)
5281 elsif Ekind (S) = E_Package
5282 and then (In_Package_Body (S) or else In_Private_Part (S))
5283 and then Is_Generic_Instance (S)
5292 end In_Instance_Not_Visible;
5294 ------------------------------
5295 -- In_Instance_Visible_Part --
5296 ------------------------------
5298 function In_Instance_Visible_Part return Boolean is
5304 and then S /= Standard_Standard
5306 if Ekind (S) = E_Package
5307 and then Is_Generic_Instance (S)
5308 and then not In_Package_Body (S)
5309 and then not In_Private_Part (S)
5318 end In_Instance_Visible_Part;
5320 ---------------------
5321 -- In_Package_Body --
5322 ---------------------
5324 function In_Package_Body return Boolean is
5330 and then S /= Standard_Standard
5332 if Ekind (S) = E_Package
5333 and then In_Package_Body (S)
5342 end In_Package_Body;
5344 --------------------------------
5345 -- In_Parameter_Specification --
5346 --------------------------------
5348 function In_Parameter_Specification (N : Node_Id) return Boolean is
5353 while Present (PN) loop
5354 if Nkind (PN) = N_Parameter_Specification then
5362 end In_Parameter_Specification;
5364 --------------------------------------
5365 -- In_Subprogram_Or_Concurrent_Unit --
5366 --------------------------------------
5368 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5373 -- Use scope chain to check successively outer scopes
5379 if K in Subprogram_Kind
5380 or else K in Concurrent_Kind
5381 or else K in Generic_Subprogram_Kind
5385 elsif E = Standard_Standard then
5391 end In_Subprogram_Or_Concurrent_Unit;
5393 ---------------------
5394 -- In_Visible_Part --
5395 ---------------------
5397 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5400 Is_Package_Or_Generic_Package (Scope_Id)
5401 and then In_Open_Scopes (Scope_Id)
5402 and then not In_Package_Body (Scope_Id)
5403 and then not In_Private_Part (Scope_Id);
5404 end In_Visible_Part;
5406 ---------------------------------
5407 -- Insert_Explicit_Dereference --
5408 ---------------------------------
5410 procedure Insert_Explicit_Dereference (N : Node_Id) is
5411 New_Prefix : constant Node_Id := Relocate_Node (N);
5412 Ent : Entity_Id := Empty;
5419 Save_Interps (N, New_Prefix);
5421 -- Check if the node relocation requires readjustment of some SCIL
5422 -- dispatching node.
5425 and then Nkind (N) = N_Function_Call
5427 Adjust_SCIL_Node (N, New_Prefix);
5430 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5432 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5434 if Is_Overloaded (New_Prefix) then
5436 -- The dereference is also overloaded, and its interpretations are
5437 -- the designated types of the interpretations of the original node.
5439 Set_Etype (N, Any_Type);
5441 Get_First_Interp (New_Prefix, I, It);
5442 while Present (It.Nam) loop
5445 if Is_Access_Type (T) then
5446 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5449 Get_Next_Interp (I, It);
5455 -- Prefix is unambiguous: mark the original prefix (which might
5456 -- Come_From_Source) as a reference, since the new (relocated) one
5457 -- won't be taken into account.
5459 if Is_Entity_Name (New_Prefix) then
5460 Ent := Entity (New_Prefix);
5462 -- For a retrieval of a subcomponent of some composite object,
5463 -- retrieve the ultimate entity if there is one.
5465 elsif Nkind (New_Prefix) = N_Selected_Component
5466 or else Nkind (New_Prefix) = N_Indexed_Component
5468 Pref := Prefix (New_Prefix);
5469 while Present (Pref)
5471 (Nkind (Pref) = N_Selected_Component
5472 or else Nkind (Pref) = N_Indexed_Component)
5474 Pref := Prefix (Pref);
5477 if Present (Pref) and then Is_Entity_Name (Pref) then
5478 Ent := Entity (Pref);
5482 if Present (Ent) then
5483 Generate_Reference (Ent, New_Prefix);
5486 end Insert_Explicit_Dereference;
5488 ------------------------------------------
5489 -- Inspect_Deferred_Constant_Completion --
5490 ------------------------------------------
5492 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5496 Decl := First (Decls);
5497 while Present (Decl) loop
5499 -- Deferred constant signature
5501 if Nkind (Decl) = N_Object_Declaration
5502 and then Constant_Present (Decl)
5503 and then No (Expression (Decl))
5505 -- No need to check internally generated constants
5507 and then Comes_From_Source (Decl)
5509 -- The constant is not completed. A full object declaration
5510 -- or a pragma Import complete a deferred constant.
5512 and then not Has_Completion (Defining_Identifier (Decl))
5515 ("constant declaration requires initialization expression",
5516 Defining_Identifier (Decl));
5519 Decl := Next (Decl);
5521 end Inspect_Deferred_Constant_Completion;
5527 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5528 pragma Assert (Is_Type (E));
5530 return AAMP_On_Target
5531 and then Is_Floating_Point_Type (E)
5532 and then E = Base_Type (E);
5535 -----------------------------
5536 -- Is_Actual_Out_Parameter --
5537 -----------------------------
5539 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5543 Find_Actual (N, Formal, Call);
5544 return Present (Formal)
5545 and then Ekind (Formal) = E_Out_Parameter;
5546 end Is_Actual_Out_Parameter;
5548 -------------------------
5549 -- Is_Actual_Parameter --
5550 -------------------------
5552 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5553 PK : constant Node_Kind := Nkind (Parent (N));
5557 when N_Parameter_Association =>
5558 return N = Explicit_Actual_Parameter (Parent (N));
5560 when N_Function_Call | N_Procedure_Call_Statement =>
5561 return Is_List_Member (N)
5563 List_Containing (N) = Parameter_Associations (Parent (N));
5568 end Is_Actual_Parameter;
5570 ---------------------
5571 -- Is_Aliased_View --
5572 ---------------------
5574 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5578 if Is_Entity_Name (Obj) then
5586 or else (Present (Renamed_Object (E))
5587 and then Is_Aliased_View (Renamed_Object (E)))))
5589 or else ((Is_Formal (E)
5590 or else Ekind (E) = E_Generic_In_Out_Parameter
5591 or else Ekind (E) = E_Generic_In_Parameter)
5592 and then Is_Tagged_Type (Etype (E)))
5594 or else (Is_Concurrent_Type (E)
5595 and then In_Open_Scopes (E))
5597 -- Current instance of type, either directly or as rewritten
5598 -- reference to the current object.
5600 or else (Is_Entity_Name (Original_Node (Obj))
5601 and then Present (Entity (Original_Node (Obj)))
5602 and then Is_Type (Entity (Original_Node (Obj))))
5604 or else (Is_Type (E) and then E = Current_Scope)
5606 or else (Is_Incomplete_Or_Private_Type (E)
5607 and then Full_View (E) = Current_Scope);
5609 elsif Nkind (Obj) = N_Selected_Component then
5610 return Is_Aliased (Entity (Selector_Name (Obj)));
5612 elsif Nkind (Obj) = N_Indexed_Component then
5613 return Has_Aliased_Components (Etype (Prefix (Obj)))
5615 (Is_Access_Type (Etype (Prefix (Obj)))
5617 Has_Aliased_Components
5618 (Designated_Type (Etype (Prefix (Obj)))));
5620 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5621 or else Nkind (Obj) = N_Type_Conversion
5623 return Is_Tagged_Type (Etype (Obj))
5624 and then Is_Aliased_View (Expression (Obj));
5626 elsif Nkind (Obj) = N_Explicit_Dereference then
5627 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5632 end Is_Aliased_View;
5634 -------------------------
5635 -- Is_Ancestor_Package --
5636 -------------------------
5638 function Is_Ancestor_Package
5640 E2 : Entity_Id) return Boolean
5647 and then Par /= Standard_Standard
5657 end Is_Ancestor_Package;
5659 ----------------------
5660 -- Is_Atomic_Object --
5661 ----------------------
5663 function Is_Atomic_Object (N : Node_Id) return Boolean is
5665 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5666 -- Determines if given object has atomic components
5668 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5669 -- If prefix is an implicit dereference, examine designated type
5671 ----------------------
5672 -- Is_Atomic_Prefix --
5673 ----------------------
5675 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5677 if Is_Access_Type (Etype (N)) then
5679 Has_Atomic_Components (Designated_Type (Etype (N)));
5681 return Object_Has_Atomic_Components (N);
5683 end Is_Atomic_Prefix;
5685 ----------------------------------
5686 -- Object_Has_Atomic_Components --
5687 ----------------------------------
5689 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5691 if Has_Atomic_Components (Etype (N))
5692 or else Is_Atomic (Etype (N))
5696 elsif Is_Entity_Name (N)
5697 and then (Has_Atomic_Components (Entity (N))
5698 or else Is_Atomic (Entity (N)))
5702 elsif Nkind (N) = N_Indexed_Component
5703 or else Nkind (N) = N_Selected_Component
5705 return Is_Atomic_Prefix (Prefix (N));
5710 end Object_Has_Atomic_Components;
5712 -- Start of processing for Is_Atomic_Object
5715 if Is_Atomic (Etype (N))
5716 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5720 elsif Nkind (N) = N_Indexed_Component
5721 or else Nkind (N) = N_Selected_Component
5723 return Is_Atomic_Prefix (Prefix (N));
5728 end Is_Atomic_Object;
5730 -------------------------
5731 -- Is_Coextension_Root --
5732 -------------------------
5734 function Is_Coextension_Root (N : Node_Id) return Boolean is
5737 Nkind (N) = N_Allocator
5738 and then Present (Coextensions (N))
5740 -- Anonymous access discriminants carry a list of all nested
5741 -- controlled coextensions.
5743 and then not Is_Dynamic_Coextension (N)
5744 and then not Is_Static_Coextension (N);
5745 end Is_Coextension_Root;
5747 -----------------------------
5748 -- Is_Concurrent_Interface --
5749 -----------------------------
5751 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5756 (Is_Protected_Interface (T)
5757 or else Is_Synchronized_Interface (T)
5758 or else Is_Task_Interface (T));
5759 end Is_Concurrent_Interface;
5761 --------------------------------------
5762 -- Is_Controlling_Limited_Procedure --
5763 --------------------------------------
5765 function Is_Controlling_Limited_Procedure
5766 (Proc_Nam : Entity_Id) return Boolean
5768 Param_Typ : Entity_Id := Empty;
5771 if Ekind (Proc_Nam) = E_Procedure
5772 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5774 Param_Typ := Etype (Parameter_Type (First (
5775 Parameter_Specifications (Parent (Proc_Nam)))));
5777 -- In this case where an Itype was created, the procedure call has been
5780 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5781 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5783 Present (Parameter_Associations
5784 (Associated_Node_For_Itype (Proc_Nam)))
5787 Etype (First (Parameter_Associations
5788 (Associated_Node_For_Itype (Proc_Nam))));
5791 if Present (Param_Typ) then
5793 Is_Interface (Param_Typ)
5794 and then Is_Limited_Record (Param_Typ);
5798 end Is_Controlling_Limited_Procedure;
5800 -----------------------------
5801 -- Is_CPP_Constructor_Call --
5802 -----------------------------
5804 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5806 return Nkind (N) = N_Function_Call
5807 and then Is_CPP_Class (Etype (Etype (N)))
5808 and then Is_Constructor (Entity (Name (N)))
5809 and then Is_Imported (Entity (Name (N)));
5810 end Is_CPP_Constructor_Call;
5812 ----------------------------------------------
5813 -- Is_Dependent_Component_Of_Mutable_Object --
5814 ----------------------------------------------
5816 function Is_Dependent_Component_Of_Mutable_Object
5817 (Object : Node_Id) return Boolean
5820 Prefix_Type : Entity_Id;
5821 P_Aliased : Boolean := False;
5824 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5825 -- Returns True if and only if Comp is declared within a variant part
5827 --------------------------------
5828 -- Is_Declared_Within_Variant --
5829 --------------------------------
5831 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5832 Comp_Decl : constant Node_Id := Parent (Comp);
5833 Comp_List : constant Node_Id := Parent (Comp_Decl);
5835 return Nkind (Parent (Comp_List)) = N_Variant;
5836 end Is_Declared_Within_Variant;
5838 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5841 if Is_Variable (Object) then
5843 if Nkind (Object) = N_Selected_Component then
5844 P := Prefix (Object);
5845 Prefix_Type := Etype (P);
5847 if Is_Entity_Name (P) then
5849 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5850 Prefix_Type := Base_Type (Prefix_Type);
5853 if Is_Aliased (Entity (P)) then
5857 -- A discriminant check on a selected component may be
5858 -- expanded into a dereference when removing side-effects.
5859 -- Recover the original node and its type, which may be
5862 elsif Nkind (P) = N_Explicit_Dereference
5863 and then not (Comes_From_Source (P))
5865 P := Original_Node (P);
5866 Prefix_Type := Etype (P);
5869 -- Check for prefix being an aliased component ???
5874 -- A heap object is constrained by its initial value
5876 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5877 -- the dereferenced case, since the access value might denote an
5878 -- unconstrained aliased object, whereas in Ada 95 the designated
5879 -- object is guaranteed to be constrained. A worst-case assumption
5880 -- has to apply in Ada 2005 because we can't tell at compile time
5881 -- whether the object is "constrained by its initial value"
5882 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5883 -- semantic rules -- these rules are acknowledged to need fixing).
5885 if Ada_Version < Ada_05 then
5886 if Is_Access_Type (Prefix_Type)
5887 or else Nkind (P) = N_Explicit_Dereference
5892 elsif Ada_Version >= Ada_05 then
5893 if Is_Access_Type (Prefix_Type) then
5895 -- If the access type is pool-specific, and there is no
5896 -- constrained partial view of the designated type, then the
5897 -- designated object is known to be constrained.
5899 if Ekind (Prefix_Type) = E_Access_Type
5900 and then not Has_Constrained_Partial_View
5901 (Designated_Type (Prefix_Type))
5905 -- Otherwise (general access type, or there is a constrained
5906 -- partial view of the designated type), we need to check
5907 -- based on the designated type.
5910 Prefix_Type := Designated_Type (Prefix_Type);
5916 Original_Record_Component (Entity (Selector_Name (Object)));
5918 -- As per AI-0017, the renaming is illegal in a generic body,
5919 -- even if the subtype is indefinite.
5921 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5923 if not Is_Constrained (Prefix_Type)
5924 and then (not Is_Indefinite_Subtype (Prefix_Type)
5926 (Is_Generic_Type (Prefix_Type)
5927 and then Ekind (Current_Scope) = E_Generic_Package
5928 and then In_Package_Body (Current_Scope)))
5930 and then (Is_Declared_Within_Variant (Comp)
5931 or else Has_Discriminant_Dependent_Constraint (Comp))
5932 and then (not P_Aliased or else Ada_Version >= Ada_05)
5938 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5942 elsif Nkind (Object) = N_Indexed_Component
5943 or else Nkind (Object) = N_Slice
5945 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5947 -- A type conversion that Is_Variable is a view conversion:
5948 -- go back to the denoted object.
5950 elsif Nkind (Object) = N_Type_Conversion then
5952 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5957 end Is_Dependent_Component_Of_Mutable_Object;
5959 ---------------------
5960 -- Is_Dereferenced --
5961 ---------------------
5963 function Is_Dereferenced (N : Node_Id) return Boolean is
5964 P : constant Node_Id := Parent (N);
5967 (Nkind (P) = N_Selected_Component
5969 Nkind (P) = N_Explicit_Dereference
5971 Nkind (P) = N_Indexed_Component
5973 Nkind (P) = N_Slice)
5974 and then Prefix (P) = N;
5975 end Is_Dereferenced;
5977 ----------------------
5978 -- Is_Descendent_Of --
5979 ----------------------
5981 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5986 pragma Assert (Nkind (T1) in N_Entity);
5987 pragma Assert (Nkind (T2) in N_Entity);
5989 T := Base_Type (T1);
5991 -- Immediate return if the types match
5996 -- Comment needed here ???
5998 elsif Ekind (T) = E_Class_Wide_Type then
5999 return Etype (T) = T2;
6007 -- Done if we found the type we are looking for
6012 -- Done if no more derivations to check
6019 -- Following test catches error cases resulting from prev errors
6021 elsif No (Etyp) then
6024 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6027 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6031 T := Base_Type (Etyp);
6034 end Is_Descendent_Of;
6040 function Is_False (U : Uint) return Boolean is
6045 ---------------------------
6046 -- Is_Fixed_Model_Number --
6047 ---------------------------
6049 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6050 S : constant Ureal := Small_Value (T);
6051 M : Urealp.Save_Mark;
6055 R := (U = UR_Trunc (U / S) * S);
6058 end Is_Fixed_Model_Number;
6060 -------------------------------
6061 -- Is_Fully_Initialized_Type --
6062 -------------------------------
6064 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6066 if Is_Scalar_Type (Typ) then
6069 elsif Is_Access_Type (Typ) then
6072 elsif Is_Array_Type (Typ) then
6073 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6077 -- An interesting case, if we have a constrained type one of whose
6078 -- bounds is known to be null, then there are no elements to be
6079 -- initialized, so all the elements are initialized!
6081 if Is_Constrained (Typ) then
6084 Indx_Typ : Entity_Id;
6088 Indx := First_Index (Typ);
6089 while Present (Indx) loop
6090 if Etype (Indx) = Any_Type then
6093 -- If index is a range, use directly
6095 elsif Nkind (Indx) = N_Range then
6096 Lbd := Low_Bound (Indx);
6097 Hbd := High_Bound (Indx);
6100 Indx_Typ := Etype (Indx);
6102 if Is_Private_Type (Indx_Typ) then
6103 Indx_Typ := Full_View (Indx_Typ);
6106 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6109 Lbd := Type_Low_Bound (Indx_Typ);
6110 Hbd := Type_High_Bound (Indx_Typ);
6114 if Compile_Time_Known_Value (Lbd)
6115 and then Compile_Time_Known_Value (Hbd)
6117 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6127 -- If no null indexes, then type is not fully initialized
6133 elsif Is_Record_Type (Typ) then
6134 if Has_Discriminants (Typ)
6136 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6137 and then Is_Fully_Initialized_Variant (Typ)
6142 -- Controlled records are considered to be fully initialized if
6143 -- there is a user defined Initialize routine. This may not be
6144 -- entirely correct, but as the spec notes, we are guessing here
6145 -- what is best from the point of view of issuing warnings.
6147 if Is_Controlled (Typ) then
6149 Utyp : constant Entity_Id := Underlying_Type (Typ);
6152 if Present (Utyp) then
6154 Init : constant Entity_Id :=
6156 (Underlying_Type (Typ), Name_Initialize));
6160 and then Comes_From_Source (Init)
6162 Is_Predefined_File_Name
6163 (File_Name (Get_Source_File_Index (Sloc (Init))))
6167 elsif Has_Null_Extension (Typ)
6169 Is_Fully_Initialized_Type
6170 (Etype (Base_Type (Typ)))
6179 -- Otherwise see if all record components are initialized
6185 Ent := First_Entity (Typ);
6186 while Present (Ent) loop
6187 if Chars (Ent) = Name_uController then
6190 elsif Ekind (Ent) = E_Component
6191 and then (No (Parent (Ent))
6192 or else No (Expression (Parent (Ent))))
6193 and then not Is_Fully_Initialized_Type (Etype (Ent))
6195 -- Special VM case for tag components, which need to be
6196 -- defined in this case, but are never initialized as VMs
6197 -- are using other dispatching mechanisms. Ignore this
6198 -- uninitialized case. Note that this applies both to the
6199 -- uTag entry and the main vtable pointer (CPP_Class case).
6201 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6210 -- No uninitialized components, so type is fully initialized.
6211 -- Note that this catches the case of no components as well.
6215 elsif Is_Concurrent_Type (Typ) then
6218 elsif Is_Private_Type (Typ) then
6220 U : constant Entity_Id := Underlying_Type (Typ);
6226 return Is_Fully_Initialized_Type (U);
6233 end Is_Fully_Initialized_Type;
6235 ----------------------------------
6236 -- Is_Fully_Initialized_Variant --
6237 ----------------------------------
6239 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6240 Loc : constant Source_Ptr := Sloc (Typ);
6241 Constraints : constant List_Id := New_List;
6242 Components : constant Elist_Id := New_Elmt_List;
6243 Comp_Elmt : Elmt_Id;
6245 Comp_List : Node_Id;
6247 Discr_Val : Node_Id;
6249 Report_Errors : Boolean;
6250 pragma Warnings (Off, Report_Errors);
6253 if Serious_Errors_Detected > 0 then
6257 if Is_Record_Type (Typ)
6258 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6259 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6261 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6263 Discr := First_Discriminant (Typ);
6264 while Present (Discr) loop
6265 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6266 Discr_Val := Expression (Parent (Discr));
6268 if Present (Discr_Val)
6269 and then Is_OK_Static_Expression (Discr_Val)
6271 Append_To (Constraints,
6272 Make_Component_Association (Loc,
6273 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6274 Expression => New_Copy (Discr_Val)));
6282 Next_Discriminant (Discr);
6287 Comp_List => Comp_List,
6288 Governed_By => Constraints,
6290 Report_Errors => Report_Errors);
6292 -- Check that each component present is fully initialized
6294 Comp_Elmt := First_Elmt (Components);
6295 while Present (Comp_Elmt) loop
6296 Comp_Id := Node (Comp_Elmt);
6298 if Ekind (Comp_Id) = E_Component
6299 and then (No (Parent (Comp_Id))
6300 or else No (Expression (Parent (Comp_Id))))
6301 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6306 Next_Elmt (Comp_Elmt);
6311 elsif Is_Private_Type (Typ) then
6313 U : constant Entity_Id := Underlying_Type (Typ);
6319 return Is_Fully_Initialized_Variant (U);
6325 end Is_Fully_Initialized_Variant;
6331 -- We seem to have a lot of overlapping functions that do similar things
6332 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6333 -- purely syntactic, it should be in Sem_Aux I would think???
6335 function Is_LHS (N : Node_Id) return Boolean is
6336 P : constant Node_Id := Parent (N);
6338 return Nkind (P) = N_Assignment_Statement
6339 and then Name (P) = N;
6342 ----------------------------
6343 -- Is_Inherited_Operation --
6344 ----------------------------
6346 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6347 Kind : constant Node_Kind := Nkind (Parent (E));
6349 pragma Assert (Is_Overloadable (E));
6350 return Kind = N_Full_Type_Declaration
6351 or else Kind = N_Private_Extension_Declaration
6352 or else Kind = N_Subtype_Declaration
6353 or else (Ekind (E) = E_Enumeration_Literal
6354 and then Is_Derived_Type (Etype (E)));
6355 end Is_Inherited_Operation;
6357 -----------------------------
6358 -- Is_Library_Level_Entity --
6359 -----------------------------
6361 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6363 -- The following is a small optimization, and it also properly handles
6364 -- discriminals, which in task bodies might appear in expressions before
6365 -- the corresponding procedure has been created, and which therefore do
6366 -- not have an assigned scope.
6368 if Ekind (E) in Formal_Kind then
6372 -- Normal test is simply that the enclosing dynamic scope is Standard
6374 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6375 end Is_Library_Level_Entity;
6377 ---------------------------------
6378 -- Is_Local_Variable_Reference --
6379 ---------------------------------
6381 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6383 if not Is_Entity_Name (Expr) then
6388 Ent : constant Entity_Id := Entity (Expr);
6389 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6391 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6394 return Present (Sub) and then Sub = Current_Subprogram;
6398 end Is_Local_Variable_Reference;
6400 -------------------------
6401 -- Is_Object_Reference --
6402 -------------------------
6404 function Is_Object_Reference (N : Node_Id) return Boolean is
6406 if Is_Entity_Name (N) then
6407 return Present (Entity (N)) and then Is_Object (Entity (N));
6411 when N_Indexed_Component | N_Slice =>
6413 Is_Object_Reference (Prefix (N))
6414 or else Is_Access_Type (Etype (Prefix (N)));
6416 -- In Ada95, a function call is a constant object; a procedure
6419 when N_Function_Call =>
6420 return Etype (N) /= Standard_Void_Type;
6422 -- A reference to the stream attribute Input is a function call
6424 when N_Attribute_Reference =>
6425 return Attribute_Name (N) = Name_Input;
6427 when N_Selected_Component =>
6429 Is_Object_Reference (Selector_Name (N))
6431 (Is_Object_Reference (Prefix (N))
6432 or else Is_Access_Type (Etype (Prefix (N))));
6434 when N_Explicit_Dereference =>
6437 -- A view conversion of a tagged object is an object reference
6439 when N_Type_Conversion =>
6440 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6441 and then Is_Tagged_Type (Etype (Expression (N)))
6442 and then Is_Object_Reference (Expression (N));
6444 -- An unchecked type conversion is considered to be an object if
6445 -- the operand is an object (this construction arises only as a
6446 -- result of expansion activities).
6448 when N_Unchecked_Type_Conversion =>
6455 end Is_Object_Reference;
6457 -----------------------------------
6458 -- Is_OK_Variable_For_Out_Formal --
6459 -----------------------------------
6461 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6463 Note_Possible_Modification (AV, Sure => True);
6465 -- We must reject parenthesized variable names. The check for
6466 -- Comes_From_Source is present because there are currently
6467 -- cases where the compiler violates this rule (e.g. passing
6468 -- a task object to its controlled Initialize routine).
6470 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6473 -- A variable is always allowed
6475 elsif Is_Variable (AV) then
6478 -- Unchecked conversions are allowed only if they come from the
6479 -- generated code, which sometimes uses unchecked conversions for out
6480 -- parameters in cases where code generation is unaffected. We tell
6481 -- source unchecked conversions by seeing if they are rewrites of an
6482 -- original Unchecked_Conversion function call, or of an explicit
6483 -- conversion of a function call.
6485 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6486 if Nkind (Original_Node (AV)) = N_Function_Call then
6489 elsif Comes_From_Source (AV)
6490 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6494 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6495 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6501 -- Normal type conversions are allowed if argument is a variable
6503 elsif Nkind (AV) = N_Type_Conversion then
6504 if Is_Variable (Expression (AV))
6505 and then Paren_Count (Expression (AV)) = 0
6507 Note_Possible_Modification (Expression (AV), Sure => True);
6510 -- We also allow a non-parenthesized expression that raises
6511 -- constraint error if it rewrites what used to be a variable
6513 elsif Raises_Constraint_Error (Expression (AV))
6514 and then Paren_Count (Expression (AV)) = 0
6515 and then Is_Variable (Original_Node (Expression (AV)))
6519 -- Type conversion of something other than a variable
6525 -- If this node is rewritten, then test the original form, if that is
6526 -- OK, then we consider the rewritten node OK (for example, if the
6527 -- original node is a conversion, then Is_Variable will not be true
6528 -- but we still want to allow the conversion if it converts a variable).
6530 elsif Original_Node (AV) /= AV then
6531 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6533 -- All other non-variables are rejected
6538 end Is_OK_Variable_For_Out_Formal;
6540 -----------------------------------
6541 -- Is_Partially_Initialized_Type --
6542 -----------------------------------
6544 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6546 if Is_Scalar_Type (Typ) then
6549 elsif Is_Access_Type (Typ) then
6552 elsif Is_Array_Type (Typ) then
6554 -- If component type is partially initialized, so is array type
6556 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6559 -- Otherwise we are only partially initialized if we are fully
6560 -- initialized (this is the empty array case, no point in us
6561 -- duplicating that code here).
6564 return Is_Fully_Initialized_Type (Typ);
6567 elsif Is_Record_Type (Typ) then
6569 -- A discriminated type is always partially initialized
6571 if Has_Discriminants (Typ) then
6574 -- A tagged type is always partially initialized
6576 elsif Is_Tagged_Type (Typ) then
6579 -- Case of non-discriminated record
6585 Component_Present : Boolean := False;
6586 -- Set True if at least one component is present. If no
6587 -- components are present, then record type is fully
6588 -- initialized (another odd case, like the null array).
6591 -- Loop through components
6593 Ent := First_Entity (Typ);
6594 while Present (Ent) loop
6595 if Ekind (Ent) = E_Component then
6596 Component_Present := True;
6598 -- If a component has an initialization expression then
6599 -- the enclosing record type is partially initialized
6601 if Present (Parent (Ent))
6602 and then Present (Expression (Parent (Ent)))
6606 -- If a component is of a type which is itself partially
6607 -- initialized, then the enclosing record type is also.
6609 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6617 -- No initialized components found. If we found any components
6618 -- they were all uninitialized so the result is false.
6620 if Component_Present then
6623 -- But if we found no components, then all the components are
6624 -- initialized so we consider the type to be initialized.
6632 -- Concurrent types are always fully initialized
6634 elsif Is_Concurrent_Type (Typ) then
6637 -- For a private type, go to underlying type. If there is no underlying
6638 -- type then just assume this partially initialized. Not clear if this
6639 -- can happen in a non-error case, but no harm in testing for this.
6641 elsif Is_Private_Type (Typ) then
6643 U : constant Entity_Id := Underlying_Type (Typ);
6648 return Is_Partially_Initialized_Type (U);
6652 -- For any other type (are there any?) assume partially initialized
6657 end Is_Partially_Initialized_Type;
6659 ------------------------------------
6660 -- Is_Potentially_Persistent_Type --
6661 ------------------------------------
6663 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6668 -- For private type, test corresponding full type
6670 if Is_Private_Type (T) then
6671 return Is_Potentially_Persistent_Type (Full_View (T));
6673 -- Scalar types are potentially persistent
6675 elsif Is_Scalar_Type (T) then
6678 -- Record type is potentially persistent if not tagged and the types of
6679 -- all it components are potentially persistent, and no component has
6680 -- an initialization expression.
6682 elsif Is_Record_Type (T)
6683 and then not Is_Tagged_Type (T)
6684 and then not Is_Partially_Initialized_Type (T)
6686 Comp := First_Component (T);
6687 while Present (Comp) loop
6688 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6697 -- Array type is potentially persistent if its component type is
6698 -- potentially persistent and if all its constraints are static.
6700 elsif Is_Array_Type (T) then
6701 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6705 Indx := First_Index (T);
6706 while Present (Indx) loop
6707 if not Is_OK_Static_Subtype (Etype (Indx)) then
6716 -- All other types are not potentially persistent
6721 end Is_Potentially_Persistent_Type;
6723 ---------------------------------
6724 -- Is_Protected_Self_Reference --
6725 ---------------------------------
6727 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6729 function In_Access_Definition (N : Node_Id) return Boolean;
6730 -- Returns true if N belongs to an access definition
6732 --------------------------
6733 -- In_Access_Definition --
6734 --------------------------
6736 function In_Access_Definition (N : Node_Id) return Boolean is
6741 while Present (P) loop
6742 if Nkind (P) = N_Access_Definition then
6750 end In_Access_Definition;
6752 -- Start of processing for Is_Protected_Self_Reference
6755 -- Verify that prefix is analyzed and has the proper form. Note that
6756 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6757 -- produce the address of an entity, do not analyze their prefix
6758 -- because they denote entities that are not necessarily visible.
6759 -- Neither of them can apply to a protected type.
6761 return Ada_Version >= Ada_05
6762 and then Is_Entity_Name (N)
6763 and then Present (Entity (N))
6764 and then Is_Protected_Type (Entity (N))
6765 and then In_Open_Scopes (Entity (N))
6766 and then not In_Access_Definition (N);
6767 end Is_Protected_Self_Reference;
6769 -----------------------------
6770 -- Is_RCI_Pkg_Spec_Or_Body --
6771 -----------------------------
6773 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6775 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6776 -- Return True if the unit of Cunit is an RCI package declaration
6778 ---------------------------
6779 -- Is_RCI_Pkg_Decl_Cunit --
6780 ---------------------------
6782 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6783 The_Unit : constant Node_Id := Unit (Cunit);
6786 if Nkind (The_Unit) /= N_Package_Declaration then
6790 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6791 end Is_RCI_Pkg_Decl_Cunit;
6793 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6796 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6798 (Nkind (Unit (Cunit)) = N_Package_Body
6799 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6800 end Is_RCI_Pkg_Spec_Or_Body;
6802 -----------------------------------------
6803 -- Is_Remote_Access_To_Class_Wide_Type --
6804 -----------------------------------------
6806 function Is_Remote_Access_To_Class_Wide_Type
6807 (E : Entity_Id) return Boolean
6810 -- A remote access to class-wide type is a general access to object type
6811 -- declared in the visible part of a Remote_Types or Remote_Call_
6814 return Ekind (E) = E_General_Access_Type
6815 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6816 end Is_Remote_Access_To_Class_Wide_Type;
6818 -----------------------------------------
6819 -- Is_Remote_Access_To_Subprogram_Type --
6820 -----------------------------------------
6822 function Is_Remote_Access_To_Subprogram_Type
6823 (E : Entity_Id) return Boolean
6826 return (Ekind (E) = E_Access_Subprogram_Type
6827 or else (Ekind (E) = E_Record_Type
6828 and then Present (Corresponding_Remote_Type (E))))
6829 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6830 end Is_Remote_Access_To_Subprogram_Type;
6832 --------------------
6833 -- Is_Remote_Call --
6834 --------------------
6836 function Is_Remote_Call (N : Node_Id) return Boolean is
6838 if Nkind (N) /= N_Procedure_Call_Statement
6839 and then Nkind (N) /= N_Function_Call
6841 -- An entry call cannot be remote
6845 elsif Nkind (Name (N)) in N_Has_Entity
6846 and then Is_Remote_Call_Interface (Entity (Name (N)))
6848 -- A subprogram declared in the spec of a RCI package is remote
6852 elsif Nkind (Name (N)) = N_Explicit_Dereference
6853 and then Is_Remote_Access_To_Subprogram_Type
6854 (Etype (Prefix (Name (N))))
6856 -- The dereference of a RAS is a remote call
6860 elsif Present (Controlling_Argument (N))
6861 and then Is_Remote_Access_To_Class_Wide_Type
6862 (Etype (Controlling_Argument (N)))
6864 -- Any primitive operation call with a controlling argument of
6865 -- a RACW type is a remote call.
6870 -- All other calls are local calls
6875 ----------------------
6876 -- Is_Renamed_Entry --
6877 ----------------------
6879 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6880 Orig_Node : Node_Id := Empty;
6881 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6883 function Is_Entry (Nam : Node_Id) return Boolean;
6884 -- Determine whether Nam is an entry. Traverse selectors if there are
6885 -- nested selected components.
6891 function Is_Entry (Nam : Node_Id) return Boolean is
6893 if Nkind (Nam) = N_Selected_Component then
6894 return Is_Entry (Selector_Name (Nam));
6897 return Ekind (Entity (Nam)) = E_Entry;
6900 -- Start of processing for Is_Renamed_Entry
6903 if Present (Alias (Proc_Nam)) then
6904 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6907 -- Look for a rewritten subprogram renaming declaration
6909 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6910 and then Present (Original_Node (Subp_Decl))
6912 Orig_Node := Original_Node (Subp_Decl);
6915 -- The rewritten subprogram is actually an entry
6917 if Present (Orig_Node)
6918 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6919 and then Is_Entry (Name (Orig_Node))
6925 end Is_Renamed_Entry;
6927 ----------------------
6928 -- Is_Selector_Name --
6929 ----------------------
6931 function Is_Selector_Name (N : Node_Id) return Boolean is
6933 if not Is_List_Member (N) then
6935 P : constant Node_Id := Parent (N);
6936 K : constant Node_Kind := Nkind (P);
6939 (K = N_Expanded_Name or else
6940 K = N_Generic_Association or else
6941 K = N_Parameter_Association or else
6942 K = N_Selected_Component)
6943 and then Selector_Name (P) = N;
6948 L : constant List_Id := List_Containing (N);
6949 P : constant Node_Id := Parent (L);
6951 return (Nkind (P) = N_Discriminant_Association
6952 and then Selector_Names (P) = L)
6954 (Nkind (P) = N_Component_Association
6955 and then Choices (P) = L);
6958 end Is_Selector_Name;
6964 function Is_Statement (N : Node_Id) return Boolean is
6967 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6968 or else Nkind (N) = N_Procedure_Call_Statement;
6971 ---------------------------------
6972 -- Is_Synchronized_Tagged_Type --
6973 ---------------------------------
6975 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6976 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6979 -- A task or protected type derived from an interface is a tagged type.
6980 -- Such a tagged type is called a synchronized tagged type, as are
6981 -- synchronized interfaces and private extensions whose declaration
6982 -- includes the reserved word synchronized.
6984 return (Is_Tagged_Type (E)
6985 and then (Kind = E_Task_Type
6986 or else Kind = E_Protected_Type))
6989 and then Is_Synchronized_Interface (E))
6991 (Ekind (E) = E_Record_Type_With_Private
6992 and then (Synchronized_Present (Parent (E))
6993 or else Is_Synchronized_Interface (Etype (E))));
6994 end Is_Synchronized_Tagged_Type;
7000 function Is_Transfer (N : Node_Id) return Boolean is
7001 Kind : constant Node_Kind := Nkind (N);
7004 if Kind = N_Simple_Return_Statement
7006 Kind = N_Extended_Return_Statement
7008 Kind = N_Goto_Statement
7010 Kind = N_Raise_Statement
7012 Kind = N_Requeue_Statement
7016 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7017 and then No (Condition (N))
7021 elsif Kind = N_Procedure_Call_Statement
7022 and then Is_Entity_Name (Name (N))
7023 and then Present (Entity (Name (N)))
7024 and then No_Return (Entity (Name (N)))
7028 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7040 function Is_True (U : Uint) return Boolean is
7049 function Is_Value_Type (T : Entity_Id) return Boolean is
7051 return VM_Target = CLI_Target
7052 and then Nkind (T) in N_Has_Chars
7053 and then Chars (T) /= No_Name
7054 and then Get_Name_String (Chars (T)) = "valuetype";
7057 ---------------------
7058 -- Is_VMS_Operator --
7059 ---------------------
7061 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7063 return Ekind (Op) = E_Function
7064 and then Is_Intrinsic_Subprogram (Op)
7065 and then Chars (Scope (Scope (Op))) = Name_System
7066 and then OpenVMS_On_Target;
7067 end Is_VMS_Operator;
7073 function Is_Delegate (T : Entity_Id) return Boolean is
7074 Desig_Type : Entity_Id;
7077 if VM_Target /= CLI_Target then
7081 -- Access-to-subprograms are delegates in CIL
7083 if Ekind (T) = E_Access_Subprogram_Type then
7087 if Ekind (T) not in Access_Kind then
7089 -- A delegate is a managed pointer. If no designated type is defined
7090 -- it means that it's not a delegate.
7095 Desig_Type := Etype (Directly_Designated_Type (T));
7097 if not Is_Tagged_Type (Desig_Type) then
7101 -- Test if the type is inherited from [mscorlib]System.Delegate
7103 while Etype (Desig_Type) /= Desig_Type loop
7104 if Chars (Scope (Desig_Type)) /= No_Name
7105 and then Is_Imported (Scope (Desig_Type))
7106 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
7111 Desig_Type := Etype (Desig_Type);
7121 function Is_Variable (N : Node_Id) return Boolean is
7123 Orig_Node : constant Node_Id := Original_Node (N);
7124 -- We do the test on the original node, since this is basically a test
7125 -- of syntactic categories, so it must not be disturbed by whatever
7126 -- rewriting might have occurred. For example, an aggregate, which is
7127 -- certainly NOT a variable, could be turned into a variable by
7130 function In_Protected_Function (E : Entity_Id) return Boolean;
7131 -- Within a protected function, the private components of the
7132 -- enclosing protected type are constants. A function nested within
7133 -- a (protected) procedure is not itself protected.
7135 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7136 -- Prefixes can involve implicit dereferences, in which case we
7137 -- must test for the case of a reference of a constant access
7138 -- type, which can never be a variable.
7140 ---------------------------
7141 -- In_Protected_Function --
7142 ---------------------------
7144 function In_Protected_Function (E : Entity_Id) return Boolean is
7145 Prot : constant Entity_Id := Scope (E);
7149 if not Is_Protected_Type (Prot) then
7153 while Present (S) and then S /= Prot loop
7154 if Ekind (S) = E_Function
7155 and then Scope (S) = Prot
7165 end In_Protected_Function;
7167 ------------------------
7168 -- Is_Variable_Prefix --
7169 ------------------------
7171 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7173 if Is_Access_Type (Etype (P)) then
7174 return not Is_Access_Constant (Root_Type (Etype (P)));
7176 -- For the case of an indexed component whose prefix has a packed
7177 -- array type, the prefix has been rewritten into a type conversion.
7178 -- Determine variable-ness from the converted expression.
7180 elsif Nkind (P) = N_Type_Conversion
7181 and then not Comes_From_Source (P)
7182 and then Is_Array_Type (Etype (P))
7183 and then Is_Packed (Etype (P))
7185 return Is_Variable (Expression (P));
7188 return Is_Variable (P);
7190 end Is_Variable_Prefix;
7192 -- Start of processing for Is_Variable
7195 -- Definitely OK if Assignment_OK is set. Since this is something that
7196 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7198 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7201 -- Normally we go to the original node, but there is one exception
7202 -- where we use the rewritten node, namely when it is an explicit
7203 -- dereference. The generated code may rewrite a prefix which is an
7204 -- access type with an explicit dereference. The dereference is a
7205 -- variable, even though the original node may not be (since it could
7206 -- be a constant of the access type).
7208 -- In Ada 2005 we have a further case to consider: the prefix may be
7209 -- a function call given in prefix notation. The original node appears
7210 -- to be a selected component, but we need to examine the call.
7212 elsif Nkind (N) = N_Explicit_Dereference
7213 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7214 and then Present (Etype (Orig_Node))
7215 and then Is_Access_Type (Etype (Orig_Node))
7217 -- Note that if the prefix is an explicit dereference that does not
7218 -- come from source, we must check for a rewritten function call in
7219 -- prefixed notation before other forms of rewriting, to prevent a
7223 (Nkind (Orig_Node) = N_Function_Call
7224 and then not Is_Access_Constant (Etype (Prefix (N))))
7226 Is_Variable_Prefix (Original_Node (Prefix (N)));
7228 -- A function call is never a variable
7230 elsif Nkind (N) = N_Function_Call then
7233 -- All remaining checks use the original node
7235 elsif Is_Entity_Name (Orig_Node)
7236 and then Present (Entity (Orig_Node))
7239 E : constant Entity_Id := Entity (Orig_Node);
7240 K : constant Entity_Kind := Ekind (E);
7243 return (K = E_Variable
7244 and then Nkind (Parent (E)) /= N_Exception_Handler)
7245 or else (K = E_Component
7246 and then not In_Protected_Function (E))
7247 or else K = E_Out_Parameter
7248 or else K = E_In_Out_Parameter
7249 or else K = E_Generic_In_Out_Parameter
7251 -- Current instance of type:
7253 or else (Is_Type (E) and then In_Open_Scopes (E))
7254 or else (Is_Incomplete_Or_Private_Type (E)
7255 and then In_Open_Scopes (Full_View (E)));
7259 case Nkind (Orig_Node) is
7260 when N_Indexed_Component | N_Slice =>
7261 return Is_Variable_Prefix (Prefix (Orig_Node));
7263 when N_Selected_Component =>
7264 return Is_Variable_Prefix (Prefix (Orig_Node))
7265 and then Is_Variable (Selector_Name (Orig_Node));
7267 -- For an explicit dereference, the type of the prefix cannot
7268 -- be an access to constant or an access to subprogram.
7270 when N_Explicit_Dereference =>
7272 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7274 return Is_Access_Type (Typ)
7275 and then not Is_Access_Constant (Root_Type (Typ))
7276 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7279 -- The type conversion is the case where we do not deal with the
7280 -- context dependent special case of an actual parameter. Thus
7281 -- the type conversion is only considered a variable for the
7282 -- purposes of this routine if the target type is tagged. However,
7283 -- a type conversion is considered to be a variable if it does not
7284 -- come from source (this deals for example with the conversions
7285 -- of expressions to their actual subtypes).
7287 when N_Type_Conversion =>
7288 return Is_Variable (Expression (Orig_Node))
7290 (not Comes_From_Source (Orig_Node)
7292 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7294 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7296 -- GNAT allows an unchecked type conversion as a variable. This
7297 -- only affects the generation of internal expanded code, since
7298 -- calls to instantiations of Unchecked_Conversion are never
7299 -- considered variables (since they are function calls).
7300 -- This is also true for expression actions.
7302 when N_Unchecked_Type_Conversion =>
7303 return Is_Variable (Expression (Orig_Node));
7311 ---------------------------
7312 -- Is_Visibly_Controlled --
7313 ---------------------------
7315 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7316 Root : constant Entity_Id := Root_Type (T);
7318 return Chars (Scope (Root)) = Name_Finalization
7319 and then Chars (Scope (Scope (Root))) = Name_Ada
7320 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7321 end Is_Visibly_Controlled;
7323 ------------------------
7324 -- Is_Volatile_Object --
7325 ------------------------
7327 function Is_Volatile_Object (N : Node_Id) return Boolean is
7329 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7330 -- Determines if given object has volatile components
7332 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7333 -- If prefix is an implicit dereference, examine designated type
7335 ------------------------
7336 -- Is_Volatile_Prefix --
7337 ------------------------
7339 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7340 Typ : constant Entity_Id := Etype (N);
7343 if Is_Access_Type (Typ) then
7345 Dtyp : constant Entity_Id := Designated_Type (Typ);
7348 return Is_Volatile (Dtyp)
7349 or else Has_Volatile_Components (Dtyp);
7353 return Object_Has_Volatile_Components (N);
7355 end Is_Volatile_Prefix;
7357 ------------------------------------
7358 -- Object_Has_Volatile_Components --
7359 ------------------------------------
7361 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7362 Typ : constant Entity_Id := Etype (N);
7365 if Is_Volatile (Typ)
7366 or else Has_Volatile_Components (Typ)
7370 elsif Is_Entity_Name (N)
7371 and then (Has_Volatile_Components (Entity (N))
7372 or else Is_Volatile (Entity (N)))
7376 elsif Nkind (N) = N_Indexed_Component
7377 or else Nkind (N) = N_Selected_Component
7379 return Is_Volatile_Prefix (Prefix (N));
7384 end Object_Has_Volatile_Components;
7386 -- Start of processing for Is_Volatile_Object
7389 if Is_Volatile (Etype (N))
7390 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7394 elsif Nkind (N) = N_Indexed_Component
7395 or else Nkind (N) = N_Selected_Component
7397 return Is_Volatile_Prefix (Prefix (N));
7402 end Is_Volatile_Object;
7404 -------------------------
7405 -- Kill_Current_Values --
7406 -------------------------
7408 procedure Kill_Current_Values
7410 Last_Assignment_Only : Boolean := False)
7413 -- ??? do we have to worry about clearing cached checks?
7415 if Is_Assignable (Ent) then
7416 Set_Last_Assignment (Ent, Empty);
7419 if Is_Object (Ent) then
7420 if not Last_Assignment_Only then
7422 Set_Current_Value (Ent, Empty);
7424 if not Can_Never_Be_Null (Ent) then
7425 Set_Is_Known_Non_Null (Ent, False);
7428 Set_Is_Known_Null (Ent, False);
7430 -- Reset Is_Known_Valid unless type is always valid, or if we have
7431 -- a loop parameter (loop parameters are always valid, since their
7432 -- bounds are defined by the bounds given in the loop header).
7434 if not Is_Known_Valid (Etype (Ent))
7435 and then Ekind (Ent) /= E_Loop_Parameter
7437 Set_Is_Known_Valid (Ent, False);
7441 end Kill_Current_Values;
7443 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7446 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7447 -- Clear current value for entity E and all entities chained to E
7449 ------------------------------------------
7450 -- Kill_Current_Values_For_Entity_Chain --
7451 ------------------------------------------
7453 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7457 while Present (Ent) loop
7458 Kill_Current_Values (Ent, Last_Assignment_Only);
7461 end Kill_Current_Values_For_Entity_Chain;
7463 -- Start of processing for Kill_Current_Values
7466 -- Kill all saved checks, a special case of killing saved values
7468 if not Last_Assignment_Only then
7472 -- Loop through relevant scopes, which includes the current scope and
7473 -- any parent scopes if the current scope is a block or a package.
7478 -- Clear current values of all entities in current scope
7480 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7482 -- If scope is a package, also clear current values of all
7483 -- private entities in the scope.
7485 if Is_Package_Or_Generic_Package (S)
7486 or else Is_Concurrent_Type (S)
7488 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7491 -- If this is a not a subprogram, deal with parents
7493 if not Is_Subprogram (S) then
7495 exit Scope_Loop when S = Standard_Standard;
7499 end loop Scope_Loop;
7500 end Kill_Current_Values;
7502 --------------------------
7503 -- Kill_Size_Check_Code --
7504 --------------------------
7506 procedure Kill_Size_Check_Code (E : Entity_Id) is
7508 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7509 and then Present (Size_Check_Code (E))
7511 Remove (Size_Check_Code (E));
7512 Set_Size_Check_Code (E, Empty);
7514 end Kill_Size_Check_Code;
7516 --------------------------
7517 -- Known_To_Be_Assigned --
7518 --------------------------
7520 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7521 P : constant Node_Id := Parent (N);
7526 -- Test left side of assignment
7528 when N_Assignment_Statement =>
7529 return N = Name (P);
7531 -- Function call arguments are never lvalues
7533 when N_Function_Call =>
7536 -- Positional parameter for procedure or accept call
7538 when N_Procedure_Call_Statement |
7547 Proc := Get_Subprogram_Entity (P);
7553 -- If we are not a list member, something is strange, so
7554 -- be conservative and return False.
7556 if not Is_List_Member (N) then
7560 -- We are going to find the right formal by stepping forward
7561 -- through the formals, as we step backwards in the actuals.
7563 Form := First_Formal (Proc);
7566 -- If no formal, something is weird, so be conservative
7567 -- and return False.
7578 return Ekind (Form) /= E_In_Parameter;
7581 -- Named parameter for procedure or accept call
7583 when N_Parameter_Association =>
7589 Proc := Get_Subprogram_Entity (Parent (P));
7595 -- Loop through formals to find the one that matches
7597 Form := First_Formal (Proc);
7599 -- If no matching formal, that's peculiar, some kind of
7600 -- previous error, so return False to be conservative.
7606 -- Else test for match
7608 if Chars (Form) = Chars (Selector_Name (P)) then
7609 return Ekind (Form) /= E_In_Parameter;
7616 -- Test for appearing in a conversion that itself appears
7617 -- in an lvalue context, since this should be an lvalue.
7619 when N_Type_Conversion =>
7620 return Known_To_Be_Assigned (P);
7622 -- All other references are definitely not known to be modifications
7628 end Known_To_Be_Assigned;
7634 function May_Be_Lvalue (N : Node_Id) return Boolean is
7635 P : constant Node_Id := Parent (N);
7640 -- Test left side of assignment
7642 when N_Assignment_Statement =>
7643 return N = Name (P);
7645 -- Test prefix of component or attribute. Note that the prefix of an
7646 -- explicit or implicit dereference cannot be an l-value.
7648 when N_Attribute_Reference =>
7649 return N = Prefix (P)
7650 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7652 -- For an expanded name, the name is an lvalue if the expanded name
7653 -- is an lvalue, but the prefix is never an lvalue, since it is just
7654 -- the scope where the name is found.
7656 when N_Expanded_Name =>
7657 if N = Prefix (P) then
7658 return May_Be_Lvalue (P);
7663 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7664 -- B is a little interesting, if we have A.B := 3, there is some
7665 -- discussion as to whether B is an lvalue or not, we choose to say
7666 -- it is. Note however that A is not an lvalue if it is of an access
7667 -- type since this is an implicit dereference.
7669 when N_Selected_Component =>
7671 and then Present (Etype (N))
7672 and then Is_Access_Type (Etype (N))
7676 return May_Be_Lvalue (P);
7679 -- For an indexed component or slice, the index or slice bounds is
7680 -- never an lvalue. The prefix is an lvalue if the indexed component
7681 -- or slice is an lvalue, except if it is an access type, where we
7682 -- have an implicit dereference.
7684 when N_Indexed_Component =>
7686 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7690 return May_Be_Lvalue (P);
7693 -- Prefix of a reference is an lvalue if the reference is an lvalue
7696 return May_Be_Lvalue (P);
7698 -- Prefix of explicit dereference is never an lvalue
7700 when N_Explicit_Dereference =>
7703 -- Function call arguments are never lvalues
7705 when N_Function_Call =>
7708 -- Positional parameter for procedure, entry, or accept call
7710 when N_Procedure_Call_Statement |
7711 N_Entry_Call_Statement |
7720 Proc := Get_Subprogram_Entity (P);
7726 -- If we are not a list member, something is strange, so
7727 -- be conservative and return True.
7729 if not Is_List_Member (N) then
7733 -- We are going to find the right formal by stepping forward
7734 -- through the formals, as we step backwards in the actuals.
7736 Form := First_Formal (Proc);
7739 -- If no formal, something is weird, so be conservative
7751 return Ekind (Form) /= E_In_Parameter;
7754 -- Named parameter for procedure or accept call
7756 when N_Parameter_Association =>
7762 Proc := Get_Subprogram_Entity (Parent (P));
7768 -- Loop through formals to find the one that matches
7770 Form := First_Formal (Proc);
7772 -- If no matching formal, that's peculiar, some kind of
7773 -- previous error, so return True to be conservative.
7779 -- Else test for match
7781 if Chars (Form) = Chars (Selector_Name (P)) then
7782 return Ekind (Form) /= E_In_Parameter;
7789 -- Test for appearing in a conversion that itself appears in an
7790 -- lvalue context, since this should be an lvalue.
7792 when N_Type_Conversion =>
7793 return May_Be_Lvalue (P);
7795 -- Test for appearance in object renaming declaration
7797 when N_Object_Renaming_Declaration =>
7800 -- All other references are definitely not lvalues
7808 -----------------------
7809 -- Mark_Coextensions --
7810 -----------------------
7812 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7813 Is_Dynamic : Boolean;
7814 -- Indicates whether the context causes nested coextensions to be
7815 -- dynamic or static
7817 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7818 -- Recognize an allocator node and label it as a dynamic coextension
7820 --------------------
7821 -- Mark_Allocator --
7822 --------------------
7824 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7826 if Nkind (N) = N_Allocator then
7828 Set_Is_Dynamic_Coextension (N);
7830 Set_Is_Static_Coextension (N);
7837 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7839 -- Start of processing Mark_Coextensions
7842 case Nkind (Context_Nod) is
7843 when N_Assignment_Statement |
7844 N_Simple_Return_Statement =>
7845 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7847 when N_Object_Declaration =>
7848 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7850 -- This routine should not be called for constructs which may not
7851 -- contain coextensions.
7854 raise Program_Error;
7857 Mark_Allocators (Root_Nod);
7858 end Mark_Coextensions;
7860 ----------------------
7861 -- Needs_One_Actual --
7862 ----------------------
7864 function Needs_One_Actual (E : Entity_Id) return Boolean is
7868 if Ada_Version >= Ada_05
7869 and then Present (First_Formal (E))
7871 Formal := Next_Formal (First_Formal (E));
7872 while Present (Formal) loop
7873 if No (Default_Value (Formal)) then
7877 Next_Formal (Formal);
7885 end Needs_One_Actual;
7887 ------------------------
7888 -- New_Copy_List_Tree --
7889 ------------------------
7891 function New_Copy_List_Tree (List : List_Id) return List_Id is
7896 if List = No_List then
7903 while Present (E) loop
7904 Append (New_Copy_Tree (E), NL);
7910 end New_Copy_List_Tree;
7916 use Atree.Unchecked_Access;
7917 use Atree_Private_Part;
7919 -- Our approach here requires a two pass traversal of the tree. The
7920 -- first pass visits all nodes that eventually will be copied looking
7921 -- for defining Itypes. If any defining Itypes are found, then they are
7922 -- copied, and an entry is added to the replacement map. In the second
7923 -- phase, the tree is copied, using the replacement map to replace any
7924 -- Itype references within the copied tree.
7926 -- The following hash tables are used if the Map supplied has more
7927 -- than hash threshhold entries to speed up access to the map. If
7928 -- there are fewer entries, then the map is searched sequentially
7929 -- (because setting up a hash table for only a few entries takes
7930 -- more time than it saves.
7932 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7933 -- Hash function used for hash operations
7939 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7941 return Nat (E) mod (NCT_Header_Num'Last + 1);
7948 -- The hash table NCT_Assoc associates old entities in the table
7949 -- with their corresponding new entities (i.e. the pairs of entries
7950 -- presented in the original Map argument are Key-Element pairs).
7952 package NCT_Assoc is new Simple_HTable (
7953 Header_Num => NCT_Header_Num,
7954 Element => Entity_Id,
7955 No_Element => Empty,
7957 Hash => New_Copy_Hash,
7958 Equal => Types."=");
7960 ---------------------
7961 -- NCT_Itype_Assoc --
7962 ---------------------
7964 -- The hash table NCT_Itype_Assoc contains entries only for those
7965 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7966 -- The key is the associated node, and the element is the new node
7967 -- itself (NOT the associated node for the new node).
7969 package NCT_Itype_Assoc is new Simple_HTable (
7970 Header_Num => NCT_Header_Num,
7971 Element => Entity_Id,
7972 No_Element => Empty,
7974 Hash => New_Copy_Hash,
7975 Equal => Types."=");
7977 -- Start of processing for New_Copy_Tree function
7979 function New_Copy_Tree
7981 Map : Elist_Id := No_Elist;
7982 New_Sloc : Source_Ptr := No_Location;
7983 New_Scope : Entity_Id := Empty) return Node_Id
7985 Actual_Map : Elist_Id := Map;
7986 -- This is the actual map for the copy. It is initialized with the
7987 -- given elements, and then enlarged as required for Itypes that are
7988 -- copied during the first phase of the copy operation. The visit
7989 -- procedures add elements to this map as Itypes are encountered.
7990 -- The reason we cannot use Map directly, is that it may well be
7991 -- (and normally is) initialized to No_Elist, and if we have mapped
7992 -- entities, we have to reset it to point to a real Elist.
7994 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
7995 -- Called during second phase to map entities into their corresponding
7996 -- copies using Actual_Map. If the argument is not an entity, or is not
7997 -- in Actual_Map, then it is returned unchanged.
7999 procedure Build_NCT_Hash_Tables;
8000 -- Builds hash tables (number of elements >= threshold value)
8002 function Copy_Elist_With_Replacement
8003 (Old_Elist : Elist_Id) return Elist_Id;
8004 -- Called during second phase to copy element list doing replacements
8006 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8007 -- Called during the second phase to process a copied Itype. The actual
8008 -- copy happened during the first phase (so that we could make the entry
8009 -- in the mapping), but we still have to deal with the descendents of
8010 -- the copied Itype and copy them where necessary.
8012 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8013 -- Called during second phase to copy list doing replacements
8015 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8016 -- Called during second phase to copy node doing replacements
8018 procedure Visit_Elist (E : Elist_Id);
8019 -- Called during first phase to visit all elements of an Elist
8021 procedure Visit_Field (F : Union_Id; N : Node_Id);
8022 -- Visit a single field, recursing to call Visit_Node or Visit_List
8023 -- if the field is a syntactic descendent of the current node (i.e.
8024 -- its parent is Node N).
8026 procedure Visit_Itype (Old_Itype : Entity_Id);
8027 -- Called during first phase to visit subsidiary fields of a defining
8028 -- Itype, and also create a copy and make an entry in the replacement
8029 -- map for the new copy.
8031 procedure Visit_List (L : List_Id);
8032 -- Called during first phase to visit all elements of a List
8034 procedure Visit_Node (N : Node_Or_Entity_Id);
8035 -- Called during first phase to visit a node and all its subtrees
8041 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8046 if not Has_Extension (N) or else No (Actual_Map) then
8049 elsif NCT_Hash_Tables_Used then
8050 Ent := NCT_Assoc.Get (Entity_Id (N));
8052 if Present (Ent) then
8058 -- No hash table used, do serial search
8061 E := First_Elmt (Actual_Map);
8062 while Present (E) loop
8063 if Node (E) = N then
8064 return Node (Next_Elmt (E));
8066 E := Next_Elmt (Next_Elmt (E));
8074 ---------------------------
8075 -- Build_NCT_Hash_Tables --
8076 ---------------------------
8078 procedure Build_NCT_Hash_Tables is
8082 if NCT_Hash_Table_Setup then
8084 NCT_Itype_Assoc.Reset;
8087 Elmt := First_Elmt (Actual_Map);
8088 while Present (Elmt) loop
8091 -- Get new entity, and associate old and new
8094 NCT_Assoc.Set (Ent, Node (Elmt));
8096 if Is_Type (Ent) then
8098 Anode : constant Entity_Id :=
8099 Associated_Node_For_Itype (Ent);
8102 if Present (Anode) then
8104 -- Enter a link between the associated node of the
8105 -- old Itype and the new Itype, for updating later
8106 -- when node is copied.
8108 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8116 NCT_Hash_Tables_Used := True;
8117 NCT_Hash_Table_Setup := True;
8118 end Build_NCT_Hash_Tables;
8120 ---------------------------------
8121 -- Copy_Elist_With_Replacement --
8122 ---------------------------------
8124 function Copy_Elist_With_Replacement
8125 (Old_Elist : Elist_Id) return Elist_Id
8128 New_Elist : Elist_Id;
8131 if No (Old_Elist) then
8135 New_Elist := New_Elmt_List;
8137 M := First_Elmt (Old_Elist);
8138 while Present (M) loop
8139 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8145 end Copy_Elist_With_Replacement;
8147 ---------------------------------
8148 -- Copy_Itype_With_Replacement --
8149 ---------------------------------
8151 -- This routine exactly parallels its phase one analog Visit_Itype,
8153 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8155 -- Translate Next_Entity, Scope and Etype fields, in case they
8156 -- reference entities that have been mapped into copies.
8158 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8159 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8161 if Present (New_Scope) then
8162 Set_Scope (New_Itype, New_Scope);
8164 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8167 -- Copy referenced fields
8169 if Is_Discrete_Type (New_Itype) then
8170 Set_Scalar_Range (New_Itype,
8171 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8173 elsif Has_Discriminants (Base_Type (New_Itype)) then
8174 Set_Discriminant_Constraint (New_Itype,
8175 Copy_Elist_With_Replacement
8176 (Discriminant_Constraint (New_Itype)));
8178 elsif Is_Array_Type (New_Itype) then
8179 if Present (First_Index (New_Itype)) then
8180 Set_First_Index (New_Itype,
8181 First (Copy_List_With_Replacement
8182 (List_Containing (First_Index (New_Itype)))));
8185 if Is_Packed (New_Itype) then
8186 Set_Packed_Array_Type (New_Itype,
8187 Copy_Node_With_Replacement
8188 (Packed_Array_Type (New_Itype)));
8191 end Copy_Itype_With_Replacement;
8193 --------------------------------
8194 -- Copy_List_With_Replacement --
8195 --------------------------------
8197 function Copy_List_With_Replacement
8198 (Old_List : List_Id) return List_Id
8204 if Old_List = No_List then
8208 New_List := Empty_List;
8210 E := First (Old_List);
8211 while Present (E) loop
8212 Append (Copy_Node_With_Replacement (E), New_List);
8218 end Copy_List_With_Replacement;
8220 --------------------------------
8221 -- Copy_Node_With_Replacement --
8222 --------------------------------
8224 function Copy_Node_With_Replacement
8225 (Old_Node : Node_Id) return Node_Id
8229 procedure Adjust_Named_Associations
8230 (Old_Node : Node_Id;
8231 New_Node : Node_Id);
8232 -- If a call node has named associations, these are chained through
8233 -- the First_Named_Actual, Next_Named_Actual links. These must be
8234 -- propagated separately to the new parameter list, because these
8235 -- are not syntactic fields.
8237 function Copy_Field_With_Replacement
8238 (Field : Union_Id) return Union_Id;
8239 -- Given Field, which is a field of Old_Node, return a copy of it
8240 -- if it is a syntactic field (i.e. its parent is Node), setting
8241 -- the parent of the copy to poit to New_Node. Otherwise returns
8242 -- the field (possibly mapped if it is an entity).
8244 -------------------------------
8245 -- Adjust_Named_Associations --
8246 -------------------------------
8248 procedure Adjust_Named_Associations
8249 (Old_Node : Node_Id;
8259 Old_E := First (Parameter_Associations (Old_Node));
8260 New_E := First (Parameter_Associations (New_Node));
8261 while Present (Old_E) loop
8262 if Nkind (Old_E) = N_Parameter_Association
8263 and then Present (Next_Named_Actual (Old_E))
8265 if First_Named_Actual (Old_Node)
8266 = Explicit_Actual_Parameter (Old_E)
8268 Set_First_Named_Actual
8269 (New_Node, Explicit_Actual_Parameter (New_E));
8272 -- Now scan parameter list from the beginning,to locate
8273 -- next named actual, which can be out of order.
8275 Old_Next := First (Parameter_Associations (Old_Node));
8276 New_Next := First (Parameter_Associations (New_Node));
8278 while Nkind (Old_Next) /= N_Parameter_Association
8279 or else Explicit_Actual_Parameter (Old_Next)
8280 /= Next_Named_Actual (Old_E)
8286 Set_Next_Named_Actual
8287 (New_E, Explicit_Actual_Parameter (New_Next));
8293 end Adjust_Named_Associations;
8295 ---------------------------------
8296 -- Copy_Field_With_Replacement --
8297 ---------------------------------
8299 function Copy_Field_With_Replacement
8300 (Field : Union_Id) return Union_Id
8303 if Field = Union_Id (Empty) then
8306 elsif Field in Node_Range then
8308 Old_N : constant Node_Id := Node_Id (Field);
8312 -- If syntactic field, as indicated by the parent pointer
8313 -- being set, then copy the referenced node recursively.
8315 if Parent (Old_N) = Old_Node then
8316 New_N := Copy_Node_With_Replacement (Old_N);
8318 if New_N /= Old_N then
8319 Set_Parent (New_N, New_Node);
8322 -- For semantic fields, update possible entity reference
8323 -- from the replacement map.
8326 New_N := Assoc (Old_N);
8329 return Union_Id (New_N);
8332 elsif Field in List_Range then
8334 Old_L : constant List_Id := List_Id (Field);
8338 -- If syntactic field, as indicated by the parent pointer,
8339 -- then recursively copy the entire referenced list.
8341 if Parent (Old_L) = Old_Node then
8342 New_L := Copy_List_With_Replacement (Old_L);
8343 Set_Parent (New_L, New_Node);
8345 -- For semantic list, just returned unchanged
8351 return Union_Id (New_L);
8354 -- Anything other than a list or a node is returned unchanged
8359 end Copy_Field_With_Replacement;
8361 -- Start of processing for Copy_Node_With_Replacement
8364 if Old_Node <= Empty_Or_Error then
8367 elsif Has_Extension (Old_Node) then
8368 return Assoc (Old_Node);
8371 New_Node := New_Copy (Old_Node);
8373 -- If the node we are copying is the associated node of a
8374 -- previously copied Itype, then adjust the associated node
8375 -- of the copy of that Itype accordingly.
8377 if Present (Actual_Map) then
8383 -- Case of hash table used
8385 if NCT_Hash_Tables_Used then
8386 Ent := NCT_Itype_Assoc.Get (Old_Node);
8388 if Present (Ent) then
8389 Set_Associated_Node_For_Itype (Ent, New_Node);
8392 -- Case of no hash table used
8395 E := First_Elmt (Actual_Map);
8396 while Present (E) loop
8397 if Is_Itype (Node (E))
8399 Old_Node = Associated_Node_For_Itype (Node (E))
8401 Set_Associated_Node_For_Itype
8402 (Node (Next_Elmt (E)), New_Node);
8405 E := Next_Elmt (Next_Elmt (E));
8411 -- Recursively copy descendents
8414 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8416 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8418 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8420 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8422 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8424 -- Adjust Sloc of new node if necessary
8426 if New_Sloc /= No_Location then
8427 Set_Sloc (New_Node, New_Sloc);
8429 -- If we adjust the Sloc, then we are essentially making
8430 -- a completely new node, so the Comes_From_Source flag
8431 -- should be reset to the proper default value.
8433 Nodes.Table (New_Node).Comes_From_Source :=
8434 Default_Node.Comes_From_Source;
8437 -- If the node is call and has named associations,
8438 -- set the corresponding links in the copy.
8440 if (Nkind (Old_Node) = N_Function_Call
8441 or else Nkind (Old_Node) = N_Entry_Call_Statement
8443 Nkind (Old_Node) = N_Procedure_Call_Statement)
8444 and then Present (First_Named_Actual (Old_Node))
8446 Adjust_Named_Associations (Old_Node, New_Node);
8449 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8450 -- The replacement mechanism applies to entities, and is not used
8451 -- here. Eventually we may need a more general graph-copying
8452 -- routine. For now, do a sequential search to find desired node.
8454 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8455 and then Present (First_Real_Statement (Old_Node))
8458 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8462 N1 := First (Statements (Old_Node));
8463 N2 := First (Statements (New_Node));
8465 while N1 /= Old_F loop
8470 Set_First_Real_Statement (New_Node, N2);
8475 -- All done, return copied node
8478 end Copy_Node_With_Replacement;
8484 procedure Visit_Elist (E : Elist_Id) is
8488 Elmt := First_Elmt (E);
8490 while Elmt /= No_Elmt loop
8491 Visit_Node (Node (Elmt));
8501 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8503 if F = Union_Id (Empty) then
8506 elsif F in Node_Range then
8508 -- Copy node if it is syntactic, i.e. its parent pointer is
8509 -- set to point to the field that referenced it (certain
8510 -- Itypes will also meet this criterion, which is fine, since
8511 -- these are clearly Itypes that do need to be copied, since
8512 -- we are copying their parent.)
8514 if Parent (Node_Id (F)) = N then
8515 Visit_Node (Node_Id (F));
8518 -- Another case, if we are pointing to an Itype, then we want
8519 -- to copy it if its associated node is somewhere in the tree
8522 -- Note: the exclusion of self-referential copies is just an
8523 -- optimization, since the search of the already copied list
8524 -- would catch it, but it is a common case (Etype pointing
8525 -- to itself for an Itype that is a base type).
8527 elsif Has_Extension (Node_Id (F))
8528 and then Is_Itype (Entity_Id (F))
8529 and then Node_Id (F) /= N
8535 P := Associated_Node_For_Itype (Node_Id (F));
8536 while Present (P) loop
8538 Visit_Node (Node_Id (F));
8545 -- An Itype whose parent is not being copied definitely
8546 -- should NOT be copied, since it does not belong in any
8547 -- sense to the copied subtree.
8553 elsif F in List_Range
8554 and then Parent (List_Id (F)) = N
8556 Visit_List (List_Id (F));
8565 procedure Visit_Itype (Old_Itype : Entity_Id) is
8566 New_Itype : Entity_Id;
8571 -- Itypes that describe the designated type of access to subprograms
8572 -- have the structure of subprogram declarations, with signatures,
8573 -- etc. Either we duplicate the signatures completely, or choose to
8574 -- share such itypes, which is fine because their elaboration will
8575 -- have no side effects.
8577 if Ekind (Old_Itype) = E_Subprogram_Type then
8581 New_Itype := New_Copy (Old_Itype);
8583 -- The new Itype has all the attributes of the old one, and
8584 -- we just copy the contents of the entity. However, the back-end
8585 -- needs different names for debugging purposes, so we create a
8586 -- new internal name for it in all cases.
8588 Set_Chars (New_Itype, New_Internal_Name ('T'));
8590 -- If our associated node is an entity that has already been copied,
8591 -- then set the associated node of the copy to point to the right
8592 -- copy. If we have copied an Itype that is itself the associated
8593 -- node of some previously copied Itype, then we set the right
8594 -- pointer in the other direction.
8596 if Present (Actual_Map) then
8598 -- Case of hash tables used
8600 if NCT_Hash_Tables_Used then
8602 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8604 if Present (Ent) then
8605 Set_Associated_Node_For_Itype (New_Itype, Ent);
8608 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8609 if Present (Ent) then
8610 Set_Associated_Node_For_Itype (Ent, New_Itype);
8612 -- If the hash table has no association for this Itype and
8613 -- its associated node, enter one now.
8617 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8620 -- Case of hash tables not used
8623 E := First_Elmt (Actual_Map);
8624 while Present (E) loop
8625 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8626 Set_Associated_Node_For_Itype
8627 (New_Itype, Node (Next_Elmt (E)));
8630 if Is_Type (Node (E))
8632 Old_Itype = Associated_Node_For_Itype (Node (E))
8634 Set_Associated_Node_For_Itype
8635 (Node (Next_Elmt (E)), New_Itype);
8638 E := Next_Elmt (Next_Elmt (E));
8643 if Present (Freeze_Node (New_Itype)) then
8644 Set_Is_Frozen (New_Itype, False);
8645 Set_Freeze_Node (New_Itype, Empty);
8648 -- Add new association to map
8650 if No (Actual_Map) then
8651 Actual_Map := New_Elmt_List;
8654 Append_Elmt (Old_Itype, Actual_Map);
8655 Append_Elmt (New_Itype, Actual_Map);
8657 if NCT_Hash_Tables_Used then
8658 NCT_Assoc.Set (Old_Itype, New_Itype);
8661 NCT_Table_Entries := NCT_Table_Entries + 1;
8663 if NCT_Table_Entries > NCT_Hash_Threshhold then
8664 Build_NCT_Hash_Tables;
8668 -- If a record subtype is simply copied, the entity list will be
8669 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8671 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
8672 Set_Cloned_Subtype (New_Itype, Old_Itype);
8675 -- Visit descendents that eventually get copied
8677 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8679 if Is_Discrete_Type (Old_Itype) then
8680 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8682 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8683 -- ??? This should involve call to Visit_Field
8684 Visit_Elist (Discriminant_Constraint (Old_Itype));
8686 elsif Is_Array_Type (Old_Itype) then
8687 if Present (First_Index (Old_Itype)) then
8688 Visit_Field (Union_Id (List_Containing
8689 (First_Index (Old_Itype))),
8693 if Is_Packed (Old_Itype) then
8694 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8704 procedure Visit_List (L : List_Id) is
8707 if L /= No_List then
8710 while Present (N) loop
8721 procedure Visit_Node (N : Node_Or_Entity_Id) is
8723 -- Start of processing for Visit_Node
8726 -- Handle case of an Itype, which must be copied
8728 if Has_Extension (N)
8729 and then Is_Itype (N)
8731 -- Nothing to do if already in the list. This can happen with an
8732 -- Itype entity that appears more than once in the tree.
8733 -- Note that we do not want to visit descendents in this case.
8735 -- Test for already in list when hash table is used
8737 if NCT_Hash_Tables_Used then
8738 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8742 -- Test for already in list when hash table not used
8748 if Present (Actual_Map) then
8749 E := First_Elmt (Actual_Map);
8750 while Present (E) loop
8751 if Node (E) = N then
8754 E := Next_Elmt (Next_Elmt (E));
8764 -- Visit descendents
8766 Visit_Field (Field1 (N), N);
8767 Visit_Field (Field2 (N), N);
8768 Visit_Field (Field3 (N), N);
8769 Visit_Field (Field4 (N), N);
8770 Visit_Field (Field5 (N), N);
8773 -- Start of processing for New_Copy_Tree
8778 -- See if we should use hash table
8780 if No (Actual_Map) then
8781 NCT_Hash_Tables_Used := False;
8788 NCT_Table_Entries := 0;
8790 Elmt := First_Elmt (Actual_Map);
8791 while Present (Elmt) loop
8792 NCT_Table_Entries := NCT_Table_Entries + 1;
8797 if NCT_Table_Entries > NCT_Hash_Threshhold then
8798 Build_NCT_Hash_Tables;
8800 NCT_Hash_Tables_Used := False;
8805 -- Hash table set up if required, now start phase one by visiting
8806 -- top node (we will recursively visit the descendents).
8808 Visit_Node (Source);
8810 -- Now the second phase of the copy can start. First we process
8811 -- all the mapped entities, copying their descendents.
8813 if Present (Actual_Map) then
8816 New_Itype : Entity_Id;
8818 Elmt := First_Elmt (Actual_Map);
8819 while Present (Elmt) loop
8821 New_Itype := Node (Elmt);
8822 Copy_Itype_With_Replacement (New_Itype);
8828 -- Now we can copy the actual tree
8830 return Copy_Node_With_Replacement (Source);
8833 -------------------------
8834 -- New_External_Entity --
8835 -------------------------
8837 function New_External_Entity
8838 (Kind : Entity_Kind;
8839 Scope_Id : Entity_Id;
8840 Sloc_Value : Source_Ptr;
8841 Related_Id : Entity_Id;
8843 Suffix_Index : Nat := 0;
8844 Prefix : Character := ' ') return Entity_Id
8846 N : constant Entity_Id :=
8847 Make_Defining_Identifier (Sloc_Value,
8849 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8852 Set_Ekind (N, Kind);
8853 Set_Is_Internal (N, True);
8854 Append_Entity (N, Scope_Id);
8855 Set_Public_Status (N);
8857 if Kind in Type_Kind then
8858 Init_Size_Align (N);
8862 end New_External_Entity;
8864 -------------------------
8865 -- New_Internal_Entity --
8866 -------------------------
8868 function New_Internal_Entity
8869 (Kind : Entity_Kind;
8870 Scope_Id : Entity_Id;
8871 Sloc_Value : Source_Ptr;
8872 Id_Char : Character) return Entity_Id
8874 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
8877 Set_Ekind (N, Kind);
8878 Set_Is_Internal (N, True);
8879 Append_Entity (N, Scope_Id);
8881 if Kind in Type_Kind then
8882 Init_Size_Align (N);
8886 end New_Internal_Entity;
8892 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8896 -- If we are pointing at a positional parameter, it is a member of a
8897 -- node list (the list of parameters), and the next parameter is the
8898 -- next node on the list, unless we hit a parameter association, then
8899 -- we shift to using the chain whose head is the First_Named_Actual in
8900 -- the parent, and then is threaded using the Next_Named_Actual of the
8901 -- Parameter_Association. All this fiddling is because the original node
8902 -- list is in the textual call order, and what we need is the
8903 -- declaration order.
8905 if Is_List_Member (Actual_Id) then
8906 N := Next (Actual_Id);
8908 if Nkind (N) = N_Parameter_Association then
8909 return First_Named_Actual (Parent (Actual_Id));
8915 return Next_Named_Actual (Parent (Actual_Id));
8919 procedure Next_Actual (Actual_Id : in out Node_Id) is
8921 Actual_Id := Next_Actual (Actual_Id);
8924 -----------------------
8925 -- Normalize_Actuals --
8926 -----------------------
8928 -- Chain actuals according to formals of subprogram. If there are no named
8929 -- associations, the chain is simply the list of Parameter Associations,
8930 -- since the order is the same as the declaration order. If there are named
8931 -- associations, then the First_Named_Actual field in the N_Function_Call
8932 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8933 -- node for the parameter that comes first in declaration order. The
8934 -- remaining named parameters are then chained in declaration order using
8935 -- Next_Named_Actual.
8937 -- This routine also verifies that the number of actuals is compatible with
8938 -- the number and default values of formals, but performs no type checking
8939 -- (type checking is done by the caller).
8941 -- If the matching succeeds, Success is set to True and the caller proceeds
8942 -- with type-checking. If the match is unsuccessful, then Success is set to
8943 -- False, and the caller attempts a different interpretation, if there is
8946 -- If the flag Report is on, the call is not overloaded, and a failure to
8947 -- match can be reported here, rather than in the caller.
8949 procedure Normalize_Actuals
8953 Success : out Boolean)
8955 Actuals : constant List_Id := Parameter_Associations (N);
8956 Actual : Node_Id := Empty;
8958 Last : Node_Id := Empty;
8959 First_Named : Node_Id := Empty;
8962 Formals_To_Match : Integer := 0;
8963 Actuals_To_Match : Integer := 0;
8965 procedure Chain (A : Node_Id);
8966 -- Add named actual at the proper place in the list, using the
8967 -- Next_Named_Actual link.
8969 function Reporting return Boolean;
8970 -- Determines if an error is to be reported. To report an error, we
8971 -- need Report to be True, and also we do not report errors caused
8972 -- by calls to init procs that occur within other init procs. Such
8973 -- errors must always be cascaded errors, since if all the types are
8974 -- declared correctly, the compiler will certainly build decent calls!
8980 procedure Chain (A : Node_Id) is
8984 -- Call node points to first actual in list
8986 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
8989 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
8993 Set_Next_Named_Actual (Last, Empty);
9000 function Reporting return Boolean is
9005 elsif not Within_Init_Proc then
9008 elsif Is_Init_Proc (Entity (Name (N))) then
9016 -- Start of processing for Normalize_Actuals
9019 if Is_Access_Type (S) then
9021 -- The name in the call is a function call that returns an access
9022 -- to subprogram. The designated type has the list of formals.
9024 Formal := First_Formal (Designated_Type (S));
9026 Formal := First_Formal (S);
9029 while Present (Formal) loop
9030 Formals_To_Match := Formals_To_Match + 1;
9031 Next_Formal (Formal);
9034 -- Find if there is a named association, and verify that no positional
9035 -- associations appear after named ones.
9037 if Present (Actuals) then
9038 Actual := First (Actuals);
9041 while Present (Actual)
9042 and then Nkind (Actual) /= N_Parameter_Association
9044 Actuals_To_Match := Actuals_To_Match + 1;
9048 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9050 -- Most common case: positional notation, no defaults
9055 elsif Actuals_To_Match > Formals_To_Match then
9057 -- Too many actuals: will not work
9060 if Is_Entity_Name (Name (N)) then
9061 Error_Msg_N ("too many arguments in call to&", Name (N));
9063 Error_Msg_N ("too many arguments in call", N);
9071 First_Named := Actual;
9073 while Present (Actual) loop
9074 if Nkind (Actual) /= N_Parameter_Association then
9076 ("positional parameters not allowed after named ones", Actual);
9081 Actuals_To_Match := Actuals_To_Match + 1;
9087 if Present (Actuals) then
9088 Actual := First (Actuals);
9091 Formal := First_Formal (S);
9092 while Present (Formal) loop
9094 -- Match the formals in order. If the corresponding actual is
9095 -- positional, nothing to do. Else scan the list of named actuals
9096 -- to find the one with the right name.
9099 and then Nkind (Actual) /= N_Parameter_Association
9102 Actuals_To_Match := Actuals_To_Match - 1;
9103 Formals_To_Match := Formals_To_Match - 1;
9106 -- For named parameters, search the list of actuals to find
9107 -- one that matches the next formal name.
9109 Actual := First_Named;
9111 while Present (Actual) loop
9112 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9115 Actuals_To_Match := Actuals_To_Match - 1;
9116 Formals_To_Match := Formals_To_Match - 1;
9124 if Ekind (Formal) /= E_In_Parameter
9125 or else No (Default_Value (Formal))
9128 if (Comes_From_Source (S)
9129 or else Sloc (S) = Standard_Location)
9130 and then Is_Overloadable (S)
9134 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9136 (Nkind (Parent (N)) = N_Function_Call
9138 Nkind (Parent (N)) = N_Parameter_Association))
9139 and then Ekind (S) /= E_Function
9141 Set_Etype (N, Etype (S));
9143 Error_Msg_Name_1 := Chars (S);
9144 Error_Msg_Sloc := Sloc (S);
9146 ("missing argument for parameter & " &
9147 "in call to % declared #", N, Formal);
9150 elsif Is_Overloadable (S) then
9151 Error_Msg_Name_1 := Chars (S);
9153 -- Point to type derivation that generated the
9156 Error_Msg_Sloc := Sloc (Parent (S));
9159 ("missing argument for parameter & " &
9160 "in call to % (inherited) #", N, Formal);
9164 ("missing argument for parameter &", N, Formal);
9172 Formals_To_Match := Formals_To_Match - 1;
9177 Next_Formal (Formal);
9180 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9187 -- Find some superfluous named actual that did not get
9188 -- attached to the list of associations.
9190 Actual := First (Actuals);
9191 while Present (Actual) loop
9192 if Nkind (Actual) = N_Parameter_Association
9193 and then Actual /= Last
9194 and then No (Next_Named_Actual (Actual))
9196 Error_Msg_N ("unmatched actual & in call",
9197 Selector_Name (Actual));
9208 end Normalize_Actuals;
9210 --------------------------------
9211 -- Note_Possible_Modification --
9212 --------------------------------
9214 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9215 Modification_Comes_From_Source : constant Boolean :=
9216 Comes_From_Source (Parent (N));
9222 -- Loop to find referenced entity, if there is one
9229 if Is_Entity_Name (Exp) then
9230 Ent := Entity (Exp);
9232 -- If the entity is missing, it is an undeclared identifier,
9233 -- and there is nothing to annotate.
9239 elsif Nkind (Exp) = N_Explicit_Dereference then
9241 P : constant Node_Id := Prefix (Exp);
9244 if Nkind (P) = N_Selected_Component
9246 Entry_Formal (Entity (Selector_Name (P))))
9248 -- Case of a reference to an entry formal
9250 Ent := Entry_Formal (Entity (Selector_Name (P)));
9252 elsif Nkind (P) = N_Identifier
9253 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9254 and then Present (Expression (Parent (Entity (P))))
9255 and then Nkind (Expression (Parent (Entity (P))))
9258 -- Case of a reference to a value on which side effects have
9261 Exp := Prefix (Expression (Parent (Entity (P))));
9270 elsif Nkind (Exp) = N_Type_Conversion
9271 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9273 Exp := Expression (Exp);
9276 elsif Nkind (Exp) = N_Slice
9277 or else Nkind (Exp) = N_Indexed_Component
9278 or else Nkind (Exp) = N_Selected_Component
9280 Exp := Prefix (Exp);
9287 -- Now look for entity being referenced
9289 if Present (Ent) then
9290 if Is_Object (Ent) then
9291 if Comes_From_Source (Exp)
9292 or else Modification_Comes_From_Source
9294 if Has_Pragma_Unmodified (Ent) then
9295 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9298 Set_Never_Set_In_Source (Ent, False);
9301 Set_Is_True_Constant (Ent, False);
9302 Set_Current_Value (Ent, Empty);
9303 Set_Is_Known_Null (Ent, False);
9305 if not Can_Never_Be_Null (Ent) then
9306 Set_Is_Known_Non_Null (Ent, False);
9309 -- Follow renaming chain
9311 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9312 and then Present (Renamed_Object (Ent))
9314 Exp := Renamed_Object (Ent);
9318 -- Generate a reference only if the assignment comes from
9319 -- source. This excludes, for example, calls to a dispatching
9320 -- assignment operation when the left-hand side is tagged.
9322 if Modification_Comes_From_Source then
9323 Generate_Reference (Ent, Exp, 'm');
9326 Check_Nested_Access (Ent);
9331 -- If we are sure this is a modification from source, and we know
9332 -- this modifies a constant, then give an appropriate warning.
9334 if Overlays_Constant (Ent)
9335 and then Modification_Comes_From_Source
9339 A : constant Node_Id := Address_Clause (Ent);
9343 Exp : constant Node_Id := Expression (A);
9345 if Nkind (Exp) = N_Attribute_Reference
9346 and then Attribute_Name (Exp) = Name_Address
9347 and then Is_Entity_Name (Prefix (Exp))
9349 Error_Msg_Sloc := Sloc (A);
9351 ("constant& may be modified via address clause#?",
9352 N, Entity (Prefix (Exp)));
9362 end Note_Possible_Modification;
9364 -------------------------
9365 -- Object_Access_Level --
9366 -------------------------
9368 function Object_Access_Level (Obj : Node_Id) return Uint is
9371 -- Returns the static accessibility level of the view denoted by Obj. Note
9372 -- that the value returned is the result of a call to Scope_Depth. Only
9373 -- scope depths associated with dynamic scopes can actually be returned.
9374 -- Since only relative levels matter for accessibility checking, the fact
9375 -- that the distance between successive levels of accessibility is not
9376 -- always one is immaterial (invariant: if level(E2) is deeper than
9377 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9379 function Reference_To (Obj : Node_Id) return Node_Id;
9380 -- An explicit dereference is created when removing side-effects from
9381 -- expressions for constraint checking purposes. In this case a local
9382 -- access type is created for it. The correct access level is that of
9383 -- the original source node. We detect this case by noting that the
9384 -- prefix of the dereference is created by an object declaration whose
9385 -- initial expression is a reference.
9391 function Reference_To (Obj : Node_Id) return Node_Id is
9392 Pref : constant Node_Id := Prefix (Obj);
9394 if Is_Entity_Name (Pref)
9395 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9396 and then Present (Expression (Parent (Entity (Pref))))
9397 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9399 return (Prefix (Expression (Parent (Entity (Pref)))));
9405 -- Start of processing for Object_Access_Level
9408 if Is_Entity_Name (Obj) then
9411 if Is_Prival (E) then
9412 E := Prival_Link (E);
9415 -- If E is a type then it denotes a current instance. For this case
9416 -- we add one to the normal accessibility level of the type to ensure
9417 -- that current instances are treated as always being deeper than
9418 -- than the level of any visible named access type (see 3.10.2(21)).
9421 return Type_Access_Level (E) + 1;
9423 elsif Present (Renamed_Object (E)) then
9424 return Object_Access_Level (Renamed_Object (E));
9426 -- Similarly, if E is a component of the current instance of a
9427 -- protected type, any instance of it is assumed to be at a deeper
9428 -- level than the type. For a protected object (whose type is an
9429 -- anonymous protected type) its components are at the same level
9430 -- as the type itself.
9432 elsif not Is_Overloadable (E)
9433 and then Ekind (Scope (E)) = E_Protected_Type
9434 and then Comes_From_Source (Scope (E))
9436 return Type_Access_Level (Scope (E)) + 1;
9439 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9442 elsif Nkind (Obj) = N_Selected_Component then
9443 if Is_Access_Type (Etype (Prefix (Obj))) then
9444 return Type_Access_Level (Etype (Prefix (Obj)));
9446 return Object_Access_Level (Prefix (Obj));
9449 elsif Nkind (Obj) = N_Indexed_Component then
9450 if Is_Access_Type (Etype (Prefix (Obj))) then
9451 return Type_Access_Level (Etype (Prefix (Obj)));
9453 return Object_Access_Level (Prefix (Obj));
9456 elsif Nkind (Obj) = N_Explicit_Dereference then
9458 -- If the prefix is a selected access discriminant then we make a
9459 -- recursive call on the prefix, which will in turn check the level
9460 -- of the prefix object of the selected discriminant.
9462 if Nkind (Prefix (Obj)) = N_Selected_Component
9463 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9465 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9467 return Object_Access_Level (Prefix (Obj));
9469 elsif not (Comes_From_Source (Obj)) then
9471 Ref : constant Node_Id := Reference_To (Obj);
9473 if Present (Ref) then
9474 return Object_Access_Level (Ref);
9476 return Type_Access_Level (Etype (Prefix (Obj)));
9481 return Type_Access_Level (Etype (Prefix (Obj)));
9484 elsif Nkind (Obj) = N_Type_Conversion
9485 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9487 return Object_Access_Level (Expression (Obj));
9489 -- Function results are objects, so we get either the access level of
9490 -- the function or, in the case of an indirect call, the level of the
9491 -- access-to-subprogram type.
9493 elsif Nkind (Obj) = N_Function_Call then
9494 if Is_Entity_Name (Name (Obj)) then
9495 return Subprogram_Access_Level (Entity (Name (Obj)));
9497 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9500 -- For convenience we handle qualified expressions, even though
9501 -- they aren't technically object names.
9503 elsif Nkind (Obj) = N_Qualified_Expression then
9504 return Object_Access_Level (Expression (Obj));
9506 -- Otherwise return the scope level of Standard.
9507 -- (If there are cases that fall through
9508 -- to this point they will be treated as
9509 -- having global accessibility for now. ???)
9512 return Scope_Depth (Standard_Standard);
9514 end Object_Access_Level;
9516 -----------------------
9517 -- Private_Component --
9518 -----------------------
9520 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9521 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9523 function Trace_Components
9525 Check : Boolean) return Entity_Id;
9526 -- Recursive function that does the work, and checks against circular
9527 -- definition for each subcomponent type.
9529 ----------------------
9530 -- Trace_Components --
9531 ----------------------
9533 function Trace_Components
9535 Check : Boolean) return Entity_Id
9537 Btype : constant Entity_Id := Base_Type (T);
9538 Component : Entity_Id;
9540 Candidate : Entity_Id := Empty;
9543 if Check and then Btype = Ancestor then
9544 Error_Msg_N ("circular type definition", Type_Id);
9548 if Is_Private_Type (Btype)
9549 and then not Is_Generic_Type (Btype)
9551 if Present (Full_View (Btype))
9552 and then Is_Record_Type (Full_View (Btype))
9553 and then not Is_Frozen (Btype)
9555 -- To indicate that the ancestor depends on a private type, the
9556 -- current Btype is sufficient. However, to check for circular
9557 -- definition we must recurse on the full view.
9559 Candidate := Trace_Components (Full_View (Btype), True);
9561 if Candidate = Any_Type then
9571 elsif Is_Array_Type (Btype) then
9572 return Trace_Components (Component_Type (Btype), True);
9574 elsif Is_Record_Type (Btype) then
9575 Component := First_Entity (Btype);
9576 while Present (Component) loop
9578 -- Skip anonymous types generated by constrained components
9580 if not Is_Type (Component) then
9581 P := Trace_Components (Etype (Component), True);
9584 if P = Any_Type then
9592 Next_Entity (Component);
9600 end Trace_Components;
9602 -- Start of processing for Private_Component
9605 return Trace_Components (Type_Id, False);
9606 end Private_Component;
9608 ---------------------------
9609 -- Primitive_Names_Match --
9610 ---------------------------
9612 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9614 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9615 -- Given an internal name, returns the corresponding non-internal name
9617 ------------------------
9618 -- Non_Internal_Name --
9619 ------------------------
9621 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9623 Get_Name_String (Chars (E));
9624 Name_Len := Name_Len - 1;
9626 end Non_Internal_Name;
9628 -- Start of processing for Primitive_Names_Match
9631 pragma Assert (Present (E1) and then Present (E2));
9633 return Chars (E1) = Chars (E2)
9635 (not Is_Internal_Name (Chars (E1))
9636 and then Is_Internal_Name (Chars (E2))
9637 and then Non_Internal_Name (E2) = Chars (E1))
9639 (not Is_Internal_Name (Chars (E2))
9640 and then Is_Internal_Name (Chars (E1))
9641 and then Non_Internal_Name (E1) = Chars (E2))
9643 (Is_Predefined_Dispatching_Operation (E1)
9644 and then Is_Predefined_Dispatching_Operation (E2)
9645 and then Same_TSS (E1, E2))
9647 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9648 end Primitive_Names_Match;
9650 -----------------------
9651 -- Process_End_Label --
9652 -----------------------
9654 procedure Process_End_Label
9663 Label_Ref : Boolean;
9664 -- Set True if reference to end label itself is required
9667 -- Gets set to the operator symbol or identifier that references the
9668 -- entity Ent. For the child unit case, this is the identifier from the
9669 -- designator. For other cases, this is simply Endl.
9671 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9672 -- N is an identifier node that appears as a parent unit reference in
9673 -- the case where Ent is a child unit. This procedure generates an
9674 -- appropriate cross-reference entry. E is the corresponding entity.
9676 -------------------------
9677 -- Generate_Parent_Ref --
9678 -------------------------
9680 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9682 -- If names do not match, something weird, skip reference
9684 if Chars (E) = Chars (N) then
9686 -- Generate the reference. We do NOT consider this as a reference
9687 -- for unreferenced symbol purposes.
9689 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9692 Style.Check_Identifier (N, E);
9695 end Generate_Parent_Ref;
9697 -- Start of processing for Process_End_Label
9700 -- If no node, ignore. This happens in some error situations, and
9701 -- also for some internally generated structures where no end label
9702 -- references are required in any case.
9708 -- Nothing to do if no End_Label, happens for internally generated
9709 -- constructs where we don't want an end label reference anyway. Also
9710 -- nothing to do if Endl is a string literal, which means there was
9711 -- some prior error (bad operator symbol)
9713 Endl := End_Label (N);
9715 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9719 -- Reference node is not in extended main source unit
9721 if not In_Extended_Main_Source_Unit (N) then
9723 -- Generally we do not collect references except for the extended
9724 -- main source unit. The one exception is the 'e' entry for a
9725 -- package spec, where it is useful for a client to have the
9726 -- ending information to define scopes.
9734 -- For this case, we can ignore any parent references, but we
9735 -- need the package name itself for the 'e' entry.
9737 if Nkind (Endl) = N_Designator then
9738 Endl := Identifier (Endl);
9742 -- Reference is in extended main source unit
9747 -- For designator, generate references for the parent entries
9749 if Nkind (Endl) = N_Designator then
9751 -- Generate references for the prefix if the END line comes from
9752 -- source (otherwise we do not need these references) We climb the
9753 -- scope stack to find the expected entities.
9755 if Comes_From_Source (Endl) then
9757 Scop := Current_Scope;
9758 while Nkind (Nam) = N_Selected_Component loop
9759 Scop := Scope (Scop);
9760 exit when No (Scop);
9761 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9762 Nam := Prefix (Nam);
9765 if Present (Scop) then
9766 Generate_Parent_Ref (Nam, Scope (Scop));
9770 Endl := Identifier (Endl);
9774 -- If the end label is not for the given entity, then either we have
9775 -- some previous error, or this is a generic instantiation for which
9776 -- we do not need to make a cross-reference in this case anyway. In
9777 -- either case we simply ignore the call.
9779 if Chars (Ent) /= Chars (Endl) then
9783 -- If label was really there, then generate a normal reference and then
9784 -- adjust the location in the end label to point past the name (which
9785 -- should almost always be the semicolon).
9789 if Comes_From_Source (Endl) then
9791 -- If a label reference is required, then do the style check and
9792 -- generate an l-type cross-reference entry for the label
9796 Style.Check_Identifier (Endl, Ent);
9799 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9802 -- Set the location to point past the label (normally this will
9803 -- mean the semicolon immediately following the label). This is
9804 -- done for the sake of the 'e' or 't' entry generated below.
9806 Get_Decoded_Name_String (Chars (Endl));
9807 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9810 -- Now generate the e/t reference
9812 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9814 -- Restore Sloc, in case modified above, since we have an identifier
9815 -- and the normal Sloc should be left set in the tree.
9817 Set_Sloc (Endl, Loc);
9818 end Process_End_Label;
9824 -- We do the conversion to get the value of the real string by using
9825 -- the scanner, see Sinput for details on use of the internal source
9826 -- buffer for scanning internal strings.
9828 function Real_Convert (S : String) return Node_Id is
9829 Save_Src : constant Source_Buffer_Ptr := Source;
9833 Source := Internal_Source_Ptr;
9836 for J in S'Range loop
9837 Source (Source_Ptr (J)) := S (J);
9840 Source (S'Length + 1) := EOF;
9842 if Source (Scan_Ptr) = '-' then
9844 Scan_Ptr := Scan_Ptr + 1;
9852 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9859 ------------------------------------
9860 -- References_Generic_Formal_Type --
9861 ------------------------------------
9863 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
9865 function Process (N : Node_Id) return Traverse_Result;
9866 -- Process one node in search for generic formal type
9872 function Process (N : Node_Id) return Traverse_Result is
9874 if Nkind (N) in N_Has_Entity then
9876 E : constant Entity_Id := Entity (N);
9879 if Is_Generic_Type (E) then
9881 elsif Present (Etype (E))
9882 and then Is_Generic_Type (Etype (E))
9893 function Traverse is new Traverse_Func (Process);
9894 -- Traverse tree to look for generic type
9897 if Inside_A_Generic then
9898 return Traverse (N) = Abandon;
9902 end References_Generic_Formal_Type;
9904 --------------------
9905 -- Remove_Homonym --
9906 --------------------
9908 procedure Remove_Homonym (E : Entity_Id) is
9909 Prev : Entity_Id := Empty;
9913 if E = Current_Entity (E) then
9914 if Present (Homonym (E)) then
9915 Set_Current_Entity (Homonym (E));
9917 Set_Name_Entity_Id (Chars (E), Empty);
9920 H := Current_Entity (E);
9921 while Present (H) and then H /= E loop
9926 Set_Homonym (Prev, Homonym (E));
9930 ---------------------
9931 -- Rep_To_Pos_Flag --
9932 ---------------------
9934 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
9936 return New_Occurrence_Of
9937 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
9938 end Rep_To_Pos_Flag;
9940 --------------------
9941 -- Require_Entity --
9942 --------------------
9944 procedure Require_Entity (N : Node_Id) is
9946 if Is_Entity_Name (N) and then No (Entity (N)) then
9947 if Total_Errors_Detected /= 0 then
9948 Set_Entity (N, Any_Id);
9950 raise Program_Error;
9955 ------------------------------
9956 -- Requires_Transient_Scope --
9957 ------------------------------
9959 -- A transient scope is required when variable-sized temporaries are
9960 -- allocated in the primary or secondary stack, or when finalization
9961 -- actions must be generated before the next instruction.
9963 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
9964 Typ : constant Entity_Id := Underlying_Type (Id);
9966 -- Start of processing for Requires_Transient_Scope
9969 -- This is a private type which is not completed yet. This can only
9970 -- happen in a default expression (of a formal parameter or of a
9971 -- record component). Do not expand transient scope in this case
9976 -- Do not expand transient scope for non-existent procedure return
9978 elsif Typ = Standard_Void_Type then
9981 -- Elementary types do not require a transient scope
9983 elsif Is_Elementary_Type (Typ) then
9986 -- Generally, indefinite subtypes require a transient scope, since the
9987 -- back end cannot generate temporaries, since this is not a valid type
9988 -- for declaring an object. It might be possible to relax this in the
9989 -- future, e.g. by declaring the maximum possible space for the type.
9991 elsif Is_Indefinite_Subtype (Typ) then
9994 -- Functions returning tagged types may dispatch on result so their
9995 -- returned value is allocated on the secondary stack. Controlled
9996 -- type temporaries need finalization.
9998 elsif Is_Tagged_Type (Typ)
9999 or else Has_Controlled_Component (Typ)
10001 return not Is_Value_Type (Typ);
10005 elsif Is_Record_Type (Typ) then
10009 Comp := First_Entity (Typ);
10010 while Present (Comp) loop
10011 if Ekind (Comp) = E_Component
10012 and then Requires_Transient_Scope (Etype (Comp))
10016 Next_Entity (Comp);
10023 -- String literal types never require transient scope
10025 elsif Ekind (Typ) = E_String_Literal_Subtype then
10028 -- Array type. Note that we already know that this is a constrained
10029 -- array, since unconstrained arrays will fail the indefinite test.
10031 elsif Is_Array_Type (Typ) then
10033 -- If component type requires a transient scope, the array does too
10035 if Requires_Transient_Scope (Component_Type (Typ)) then
10038 -- Otherwise, we only need a transient scope if the size is not
10039 -- known at compile time.
10042 return not Size_Known_At_Compile_Time (Typ);
10045 -- All other cases do not require a transient scope
10050 end Requires_Transient_Scope;
10052 --------------------------
10053 -- Reset_Analyzed_Flags --
10054 --------------------------
10056 procedure Reset_Analyzed_Flags (N : Node_Id) is
10058 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10059 -- Function used to reset Analyzed flags in tree. Note that we do
10060 -- not reset Analyzed flags in entities, since there is no need to
10061 -- reanalyze entities, and indeed, it is wrong to do so, since it
10062 -- can result in generating auxiliary stuff more than once.
10064 --------------------
10065 -- Clear_Analyzed --
10066 --------------------
10068 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10070 if not Has_Extension (N) then
10071 Set_Analyzed (N, False);
10075 end Clear_Analyzed;
10077 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10079 -- Start of processing for Reset_Analyzed_Flags
10082 Reset_Analyzed (N);
10083 end Reset_Analyzed_Flags;
10085 ---------------------------
10086 -- Safe_To_Capture_Value --
10087 ---------------------------
10089 function Safe_To_Capture_Value
10092 Cond : Boolean := False) return Boolean
10095 -- The only entities for which we track constant values are variables
10096 -- which are not renamings, constants, out parameters, and in out
10097 -- parameters, so check if we have this case.
10099 -- Note: it may seem odd to track constant values for constants, but in
10100 -- fact this routine is used for other purposes than simply capturing
10101 -- the value. In particular, the setting of Known[_Non]_Null.
10103 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10105 Ekind (Ent) = E_Constant
10107 Ekind (Ent) = E_Out_Parameter
10109 Ekind (Ent) = E_In_Out_Parameter
10113 -- For conditionals, we also allow loop parameters and all formals,
10114 -- including in parameters.
10118 (Ekind (Ent) = E_Loop_Parameter
10120 Ekind (Ent) = E_In_Parameter)
10124 -- For all other cases, not just unsafe, but impossible to capture
10125 -- Current_Value, since the above are the only entities which have
10126 -- Current_Value fields.
10132 -- Skip if volatile or aliased, since funny things might be going on in
10133 -- these cases which we cannot necessarily track. Also skip any variable
10134 -- for which an address clause is given, or whose address is taken. Also
10135 -- never capture value of library level variables (an attempt to do so
10136 -- can occur in the case of package elaboration code).
10138 if Treat_As_Volatile (Ent)
10139 or else Is_Aliased (Ent)
10140 or else Present (Address_Clause (Ent))
10141 or else Address_Taken (Ent)
10142 or else (Is_Library_Level_Entity (Ent)
10143 and then Ekind (Ent) = E_Variable)
10148 -- OK, all above conditions are met. We also require that the scope of
10149 -- the reference be the same as the scope of the entity, not counting
10150 -- packages and blocks and loops.
10153 E_Scope : constant Entity_Id := Scope (Ent);
10154 R_Scope : Entity_Id;
10157 R_Scope := Current_Scope;
10158 while R_Scope /= Standard_Standard loop
10159 exit when R_Scope = E_Scope;
10161 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10164 R_Scope := Scope (R_Scope);
10169 -- We also require that the reference does not appear in a context
10170 -- where it is not sure to be executed (i.e. a conditional context
10171 -- or an exception handler). We skip this if Cond is True, since the
10172 -- capturing of values from conditional tests handles this ok.
10186 while Present (P) loop
10187 if Nkind (P) = N_If_Statement
10188 or else Nkind (P) = N_Case_Statement
10189 or else (Nkind (P) in N_Short_Circuit
10190 and then Desc = Right_Opnd (P))
10191 or else (Nkind (P) = N_Conditional_Expression
10192 and then Desc /= First (Expressions (P)))
10193 or else Nkind (P) = N_Exception_Handler
10194 or else Nkind (P) = N_Selective_Accept
10195 or else Nkind (P) = N_Conditional_Entry_Call
10196 or else Nkind (P) = N_Timed_Entry_Call
10197 or else Nkind (P) = N_Asynchronous_Select
10207 -- OK, looks safe to set value
10210 end Safe_To_Capture_Value;
10216 function Same_Name (N1, N2 : Node_Id) return Boolean is
10217 K1 : constant Node_Kind := Nkind (N1);
10218 K2 : constant Node_Kind := Nkind (N2);
10221 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10222 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10224 return Chars (N1) = Chars (N2);
10226 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10227 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10229 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10230 and then Same_Name (Prefix (N1), Prefix (N2));
10241 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10242 N1 : constant Node_Id := Original_Node (Node1);
10243 N2 : constant Node_Id := Original_Node (Node2);
10244 -- We do the tests on original nodes, since we are most interested
10245 -- in the original source, not any expansion that got in the way.
10247 K1 : constant Node_Kind := Nkind (N1);
10248 K2 : constant Node_Kind := Nkind (N2);
10251 -- First case, both are entities with same entity
10253 if K1 in N_Has_Entity
10254 and then K2 in N_Has_Entity
10255 and then Present (Entity (N1))
10256 and then Present (Entity (N2))
10257 and then (Ekind (Entity (N1)) = E_Variable
10259 Ekind (Entity (N1)) = E_Constant)
10260 and then Entity (N1) = Entity (N2)
10264 -- Second case, selected component with same selector, same record
10266 elsif K1 = N_Selected_Component
10267 and then K2 = N_Selected_Component
10268 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10270 return Same_Object (Prefix (N1), Prefix (N2));
10272 -- Third case, indexed component with same subscripts, same array
10274 elsif K1 = N_Indexed_Component
10275 and then K2 = N_Indexed_Component
10276 and then Same_Object (Prefix (N1), Prefix (N2))
10281 E1 := First (Expressions (N1));
10282 E2 := First (Expressions (N2));
10283 while Present (E1) loop
10284 if not Same_Value (E1, E2) then
10295 -- Fourth case, slice of same array with same bounds
10298 and then K2 = N_Slice
10299 and then Nkind (Discrete_Range (N1)) = N_Range
10300 and then Nkind (Discrete_Range (N2)) = N_Range
10301 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10302 Low_Bound (Discrete_Range (N2)))
10303 and then Same_Value (High_Bound (Discrete_Range (N1)),
10304 High_Bound (Discrete_Range (N2)))
10306 return Same_Name (Prefix (N1), Prefix (N2));
10308 -- All other cases, not clearly the same object
10319 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10324 elsif not Is_Constrained (T1)
10325 and then not Is_Constrained (T2)
10326 and then Base_Type (T1) = Base_Type (T2)
10330 -- For now don't bother with case of identical constraints, to be
10331 -- fiddled with later on perhaps (this is only used for optimization
10332 -- purposes, so it is not critical to do a best possible job)
10343 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10345 if Compile_Time_Known_Value (Node1)
10346 and then Compile_Time_Known_Value (Node2)
10347 and then Expr_Value (Node1) = Expr_Value (Node2)
10350 elsif Same_Object (Node1, Node2) then
10357 ------------------------
10358 -- Scope_Is_Transient --
10359 ------------------------
10361 function Scope_Is_Transient return Boolean is
10363 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10364 end Scope_Is_Transient;
10370 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10375 while Scop /= Standard_Standard loop
10376 Scop := Scope (Scop);
10378 if Scop = Scope2 then
10386 --------------------------
10387 -- Scope_Within_Or_Same --
10388 --------------------------
10390 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10395 while Scop /= Standard_Standard loop
10396 if Scop = Scope2 then
10399 Scop := Scope (Scop);
10404 end Scope_Within_Or_Same;
10406 --------------------
10407 -- Set_Convention --
10408 --------------------
10410 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10412 Basic_Set_Convention (E, Val);
10415 and then Is_Access_Subprogram_Type (Base_Type (E))
10416 and then Has_Foreign_Convention (E)
10418 Set_Can_Use_Internal_Rep (E, False);
10420 end Set_Convention;
10422 ------------------------
10423 -- Set_Current_Entity --
10424 ------------------------
10426 -- The given entity is to be set as the currently visible definition
10427 -- of its associated name (i.e. the Node_Id associated with its name).
10428 -- All we have to do is to get the name from the identifier, and
10429 -- then set the associated Node_Id to point to the given entity.
10431 procedure Set_Current_Entity (E : Entity_Id) is
10433 Set_Name_Entity_Id (Chars (E), E);
10434 end Set_Current_Entity;
10436 ---------------------------
10437 -- Set_Debug_Info_Needed --
10438 ---------------------------
10440 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10442 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10443 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10444 -- Used to set debug info in a related node if not set already
10446 --------------------------------------
10447 -- Set_Debug_Info_Needed_If_Not_Set --
10448 --------------------------------------
10450 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10453 and then not Needs_Debug_Info (E)
10455 Set_Debug_Info_Needed (E);
10457 -- For a private type, indicate that the full view also needs
10458 -- debug information.
10461 and then Is_Private_Type (E)
10462 and then Present (Full_View (E))
10464 Set_Debug_Info_Needed (Full_View (E));
10467 end Set_Debug_Info_Needed_If_Not_Set;
10469 -- Start of processing for Set_Debug_Info_Needed
10472 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10473 -- indicates that Debug_Info_Needed is never required for the entity.
10476 or else Debug_Info_Off (T)
10481 -- Set flag in entity itself. Note that we will go through the following
10482 -- circuitry even if the flag is already set on T. That's intentional,
10483 -- it makes sure that the flag will be set in subsidiary entities.
10485 Set_Needs_Debug_Info (T);
10487 -- Set flag on subsidiary entities if not set already
10489 if Is_Object (T) then
10490 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10492 elsif Is_Type (T) then
10493 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10495 if Is_Record_Type (T) then
10497 Ent : Entity_Id := First_Entity (T);
10499 while Present (Ent) loop
10500 Set_Debug_Info_Needed_If_Not_Set (Ent);
10505 -- For a class wide subtype, we also need debug information
10506 -- for the equivalent type.
10508 if Ekind (T) = E_Class_Wide_Subtype then
10509 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10512 elsif Is_Array_Type (T) then
10513 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10516 Indx : Node_Id := First_Index (T);
10518 while Present (Indx) loop
10519 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10520 Indx := Next_Index (Indx);
10524 if Is_Packed (T) then
10525 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10528 elsif Is_Access_Type (T) then
10529 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10531 elsif Is_Private_Type (T) then
10532 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10534 elsif Is_Protected_Type (T) then
10535 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10538 end Set_Debug_Info_Needed;
10540 ---------------------------------
10541 -- Set_Entity_With_Style_Check --
10542 ---------------------------------
10544 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10545 Val_Actual : Entity_Id;
10549 Set_Entity (N, Val);
10552 and then not Suppress_Style_Checks (Val)
10553 and then not In_Instance
10555 if Nkind (N) = N_Identifier then
10557 elsif Nkind (N) = N_Expanded_Name then
10558 Nod := Selector_Name (N);
10563 -- A special situation arises for derived operations, where we want
10564 -- to do the check against the parent (since the Sloc of the derived
10565 -- operation points to the derived type declaration itself).
10568 while not Comes_From_Source (Val_Actual)
10569 and then Nkind (Val_Actual) in N_Entity
10570 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10571 or else Is_Subprogram (Val_Actual)
10572 or else Is_Generic_Subprogram (Val_Actual))
10573 and then Present (Alias (Val_Actual))
10575 Val_Actual := Alias (Val_Actual);
10578 -- Renaming declarations for generic actuals do not come from source,
10579 -- and have a different name from that of the entity they rename, so
10580 -- there is no style check to perform here.
10582 if Chars (Nod) = Chars (Val_Actual) then
10583 Style.Check_Identifier (Nod, Val_Actual);
10587 Set_Entity (N, Val);
10588 end Set_Entity_With_Style_Check;
10590 ------------------------
10591 -- Set_Name_Entity_Id --
10592 ------------------------
10594 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10596 Set_Name_Table_Info (Id, Int (Val));
10597 end Set_Name_Entity_Id;
10599 ---------------------
10600 -- Set_Next_Actual --
10601 ---------------------
10603 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10605 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10606 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10608 end Set_Next_Actual;
10610 ----------------------------------
10611 -- Set_Optimize_Alignment_Flags --
10612 ----------------------------------
10614 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10616 if Optimize_Alignment = 'S' then
10617 Set_Optimize_Alignment_Space (E);
10618 elsif Optimize_Alignment = 'T' then
10619 Set_Optimize_Alignment_Time (E);
10621 end Set_Optimize_Alignment_Flags;
10623 -----------------------
10624 -- Set_Public_Status --
10625 -----------------------
10627 procedure Set_Public_Status (Id : Entity_Id) is
10628 S : constant Entity_Id := Current_Scope;
10630 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10631 -- Determines if E is defined within handled statement sequence or
10632 -- an if statement, returns True if so, False otherwise.
10634 ----------------------
10635 -- Within_HSS_Or_If --
10636 ----------------------
10638 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10641 N := Declaration_Node (E);
10648 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10654 end Within_HSS_Or_If;
10656 -- Start of processing for Set_Public_Status
10659 -- Everything in the scope of Standard is public
10661 if S = Standard_Standard then
10662 Set_Is_Public (Id);
10664 -- Entity is definitely not public if enclosing scope is not public
10666 elsif not Is_Public (S) then
10669 -- An object or function declaration that occurs in a handled sequence
10670 -- of statements or within an if statement is the declaration for a
10671 -- temporary object or local subprogram generated by the expander. It
10672 -- never needs to be made public and furthermore, making it public can
10673 -- cause back end problems.
10675 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10676 N_Function_Specification)
10677 and then Within_HSS_Or_If (Id)
10681 -- Entities in public packages or records are public
10683 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10684 Set_Is_Public (Id);
10686 -- The bounds of an entry family declaration can generate object
10687 -- declarations that are visible to the back-end, e.g. in the
10688 -- the declaration of a composite type that contains tasks.
10690 elsif Is_Concurrent_Type (S)
10691 and then not Has_Completion (S)
10692 and then Nkind (Parent (Id)) = N_Object_Declaration
10694 Set_Is_Public (Id);
10696 end Set_Public_Status;
10698 -----------------------------
10699 -- Set_Referenced_Modified --
10700 -----------------------------
10702 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10706 -- Deal with indexed or selected component where prefix is modified
10708 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
10709 Pref := Prefix (N);
10711 -- If prefix is access type, then it is the designated object that is
10712 -- being modified, which means we have no entity to set the flag on.
10714 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10717 -- Otherwise chase the prefix
10720 Set_Referenced_Modified (Pref, Out_Param);
10723 -- Otherwise see if we have an entity name (only other case to process)
10725 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10726 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10727 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10729 end Set_Referenced_Modified;
10731 ----------------------------
10732 -- Set_Scope_Is_Transient --
10733 ----------------------------
10735 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10737 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10738 end Set_Scope_Is_Transient;
10740 -------------------
10741 -- Set_Size_Info --
10742 -------------------
10744 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10746 -- We copy Esize, but not RM_Size, since in general RM_Size is
10747 -- subtype specific and does not get inherited by all subtypes.
10749 Set_Esize (T1, Esize (T2));
10750 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10752 if Is_Discrete_Or_Fixed_Point_Type (T1)
10754 Is_Discrete_Or_Fixed_Point_Type (T2)
10756 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10759 Set_Alignment (T1, Alignment (T2));
10762 --------------------
10763 -- Static_Integer --
10764 --------------------
10766 function Static_Integer (N : Node_Id) return Uint is
10768 Analyze_And_Resolve (N, Any_Integer);
10771 or else Error_Posted (N)
10772 or else Etype (N) = Any_Type
10777 if Is_Static_Expression (N) then
10778 if not Raises_Constraint_Error (N) then
10779 return Expr_Value (N);
10784 elsif Etype (N) = Any_Type then
10788 Flag_Non_Static_Expr
10789 ("static integer expression required here", N);
10792 end Static_Integer;
10794 --------------------------
10795 -- Statically_Different --
10796 --------------------------
10798 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10799 R1 : constant Node_Id := Get_Referenced_Object (E1);
10800 R2 : constant Node_Id := Get_Referenced_Object (E2);
10802 return Is_Entity_Name (R1)
10803 and then Is_Entity_Name (R2)
10804 and then Entity (R1) /= Entity (R2)
10805 and then not Is_Formal (Entity (R1))
10806 and then not Is_Formal (Entity (R2));
10807 end Statically_Different;
10809 -----------------------------
10810 -- Subprogram_Access_Level --
10811 -----------------------------
10813 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10815 if Present (Alias (Subp)) then
10816 return Subprogram_Access_Level (Alias (Subp));
10818 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10820 end Subprogram_Access_Level;
10826 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10828 if Debug_Flag_W then
10829 for J in 0 .. Scope_Stack.Last loop
10834 Write_Name (Chars (E));
10835 Write_Str (" from ");
10836 Write_Location (Sloc (N));
10841 -----------------------
10842 -- Transfer_Entities --
10843 -----------------------
10845 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10846 Ent : Entity_Id := First_Entity (From);
10853 if (Last_Entity (To)) = Empty then
10854 Set_First_Entity (To, Ent);
10856 Set_Next_Entity (Last_Entity (To), Ent);
10859 Set_Last_Entity (To, Last_Entity (From));
10861 while Present (Ent) loop
10862 Set_Scope (Ent, To);
10864 if not Is_Public (Ent) then
10865 Set_Public_Status (Ent);
10868 and then Ekind (Ent) = E_Record_Subtype
10871 -- The components of the propagated Itype must be public
10877 Comp := First_Entity (Ent);
10878 while Present (Comp) loop
10879 Set_Is_Public (Comp);
10880 Next_Entity (Comp);
10889 Set_First_Entity (From, Empty);
10890 Set_Last_Entity (From, Empty);
10891 end Transfer_Entities;
10893 -----------------------
10894 -- Type_Access_Level --
10895 -----------------------
10897 function Type_Access_Level (Typ : Entity_Id) return Uint is
10901 Btyp := Base_Type (Typ);
10903 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10904 -- simply use the level where the type is declared. This is true for
10905 -- stand-alone object declarations, and for anonymous access types
10906 -- associated with components the level is the same as that of the
10907 -- enclosing composite type. However, special treatment is needed for
10908 -- the cases of access parameters, return objects of an anonymous access
10909 -- type, and, in Ada 95, access discriminants of limited types.
10911 if Ekind (Btyp) in Access_Kind then
10912 if Ekind (Btyp) = E_Anonymous_Access_Type then
10914 -- If the type is a nonlocal anonymous access type (such as for
10915 -- an access parameter) we treat it as being declared at the
10916 -- library level to ensure that names such as X.all'access don't
10917 -- fail static accessibility checks.
10919 if not Is_Local_Anonymous_Access (Typ) then
10920 return Scope_Depth (Standard_Standard);
10922 -- If this is a return object, the accessibility level is that of
10923 -- the result subtype of the enclosing function. The test here is
10924 -- little complicated, because we have to account for extended
10925 -- return statements that have been rewritten as blocks, in which
10926 -- case we have to find and the Is_Return_Object attribute of the
10927 -- itype's associated object. It would be nice to find a way to
10928 -- simplify this test, but it doesn't seem worthwhile to add a new
10929 -- flag just for purposes of this test. ???
10931 elsif Ekind (Scope (Btyp)) = E_Return_Statement
10934 and then Nkind (Associated_Node_For_Itype (Btyp)) =
10935 N_Object_Declaration
10936 and then Is_Return_Object
10937 (Defining_Identifier
10938 (Associated_Node_For_Itype (Btyp))))
10944 Scop := Scope (Scope (Btyp));
10945 while Present (Scop) loop
10946 exit when Ekind (Scop) = E_Function;
10947 Scop := Scope (Scop);
10950 -- Treat the return object's type as having the level of the
10951 -- function's result subtype (as per RM05-6.5(5.3/2)).
10953 return Type_Access_Level (Etype (Scop));
10958 Btyp := Root_Type (Btyp);
10960 -- The accessibility level of anonymous access types associated with
10961 -- discriminants is that of the current instance of the type, and
10962 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10964 -- AI-402: access discriminants have accessibility based on the
10965 -- object rather than the type in Ada 2005, so the above paragraph
10968 -- ??? Needs completion with rules from AI-416
10970 if Ada_Version <= Ada_95
10971 and then Ekind (Typ) = E_Anonymous_Access_Type
10972 and then Present (Associated_Node_For_Itype (Typ))
10973 and then Nkind (Associated_Node_For_Itype (Typ)) =
10974 N_Discriminant_Specification
10976 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
10980 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
10981 end Type_Access_Level;
10983 --------------------
10984 -- Ultimate_Alias --
10985 --------------------
10986 -- To do: add occurrences calling this new subprogram
10988 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
10989 E : Entity_Id := Prim;
10992 while Present (Alias (E)) loop
10997 end Ultimate_Alias;
10999 --------------------------
11000 -- Unit_Declaration_Node --
11001 --------------------------
11003 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11004 N : Node_Id := Parent (Unit_Id);
11007 -- Predefined operators do not have a full function declaration
11009 if Ekind (Unit_Id) = E_Operator then
11013 -- Isn't there some better way to express the following ???
11015 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11016 and then Nkind (N) /= N_Formal_Package_Declaration
11017 and then Nkind (N) /= N_Function_Instantiation
11018 and then Nkind (N) /= N_Generic_Package_Declaration
11019 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11020 and then Nkind (N) /= N_Package_Declaration
11021 and then Nkind (N) /= N_Package_Body
11022 and then Nkind (N) /= N_Package_Instantiation
11023 and then Nkind (N) /= N_Package_Renaming_Declaration
11024 and then Nkind (N) /= N_Procedure_Instantiation
11025 and then Nkind (N) /= N_Protected_Body
11026 and then Nkind (N) /= N_Subprogram_Declaration
11027 and then Nkind (N) /= N_Subprogram_Body
11028 and then Nkind (N) /= N_Subprogram_Body_Stub
11029 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11030 and then Nkind (N) /= N_Task_Body
11031 and then Nkind (N) /= N_Task_Type_Declaration
11032 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11033 and then Nkind (N) not in N_Generic_Renaming_Declaration
11036 pragma Assert (Present (N));
11040 end Unit_Declaration_Node;
11042 ------------------------------
11043 -- Universal_Interpretation --
11044 ------------------------------
11046 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11047 Index : Interp_Index;
11051 -- The argument may be a formal parameter of an operator or subprogram
11052 -- with multiple interpretations, or else an expression for an actual.
11054 if Nkind (Opnd) = N_Defining_Identifier
11055 or else not Is_Overloaded (Opnd)
11057 if Etype (Opnd) = Universal_Integer
11058 or else Etype (Opnd) = Universal_Real
11060 return Etype (Opnd);
11066 Get_First_Interp (Opnd, Index, It);
11067 while Present (It.Typ) loop
11068 if It.Typ = Universal_Integer
11069 or else It.Typ = Universal_Real
11074 Get_Next_Interp (Index, It);
11079 end Universal_Interpretation;
11085 function Unqualify (Expr : Node_Id) return Node_Id is
11087 -- Recurse to handle unlikely case of multiple levels of qualification
11089 if Nkind (Expr) = N_Qualified_Expression then
11090 return Unqualify (Expression (Expr));
11092 -- Normal case, not a qualified expression
11099 ----------------------
11100 -- Within_Init_Proc --
11101 ----------------------
11103 function Within_Init_Proc return Boolean is
11107 S := Current_Scope;
11108 while not Is_Overloadable (S) loop
11109 if S = Standard_Standard then
11116 return Is_Init_Proc (S);
11117 end Within_Init_Proc;
11123 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11124 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11125 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11127 function Has_One_Matching_Field return Boolean;
11128 -- Determines if Expec_Type is a record type with a single component or
11129 -- discriminant whose type matches the found type or is one dimensional
11130 -- array whose component type matches the found type.
11132 ----------------------------
11133 -- Has_One_Matching_Field --
11134 ----------------------------
11136 function Has_One_Matching_Field return Boolean is
11140 if Is_Array_Type (Expec_Type)
11141 and then Number_Dimensions (Expec_Type) = 1
11143 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11147 elsif not Is_Record_Type (Expec_Type) then
11151 E := First_Entity (Expec_Type);
11156 elsif (Ekind (E) /= E_Discriminant
11157 and then Ekind (E) /= E_Component)
11158 or else (Chars (E) = Name_uTag
11159 or else Chars (E) = Name_uParent)
11168 if not Covers (Etype (E), Found_Type) then
11171 elsif Present (Next_Entity (E)) then
11178 end Has_One_Matching_Field;
11180 -- Start of processing for Wrong_Type
11183 -- Don't output message if either type is Any_Type, or if a message
11184 -- has already been posted for this node. We need to do the latter
11185 -- check explicitly (it is ordinarily done in Errout), because we
11186 -- are using ! to force the output of the error messages.
11188 if Expec_Type = Any_Type
11189 or else Found_Type = Any_Type
11190 or else Error_Posted (Expr)
11194 -- In an instance, there is an ongoing problem with completion of
11195 -- type derived from private types. Their structure is what Gigi
11196 -- expects, but the Etype is the parent type rather than the
11197 -- derived private type itself. Do not flag error in this case. The
11198 -- private completion is an entity without a parent, like an Itype.
11199 -- Similarly, full and partial views may be incorrect in the instance.
11200 -- There is no simple way to insure that it is consistent ???
11202 elsif In_Instance then
11203 if Etype (Etype (Expr)) = Etype (Expected_Type)
11205 (Has_Private_Declaration (Expected_Type)
11206 or else Has_Private_Declaration (Etype (Expr)))
11207 and then No (Parent (Expected_Type))
11213 -- An interesting special check. If the expression is parenthesized
11214 -- and its type corresponds to the type of the sole component of the
11215 -- expected record type, or to the component type of the expected one
11216 -- dimensional array type, then assume we have a bad aggregate attempt.
11218 if Nkind (Expr) in N_Subexpr
11219 and then Paren_Count (Expr) /= 0
11220 and then Has_One_Matching_Field
11222 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11224 -- Another special check, if we are looking for a pool-specific access
11225 -- type and we found an E_Access_Attribute_Type, then we have the case
11226 -- of an Access attribute being used in a context which needs a pool-
11227 -- specific type, which is never allowed. The one extra check we make
11228 -- is that the expected designated type covers the Found_Type.
11230 elsif Is_Access_Type (Expec_Type)
11231 and then Ekind (Found_Type) = E_Access_Attribute_Type
11232 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11233 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11235 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11237 Error_Msg_N ("result must be general access type!", Expr);
11238 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
11240 -- Another special check, if the expected type is an integer type,
11241 -- but the expression is of type System.Address, and the parent is
11242 -- an addition or subtraction operation whose left operand is the
11243 -- expression in question and whose right operand is of an integral
11244 -- type, then this is an attempt at address arithmetic, so give
11245 -- appropriate message.
11247 elsif Is_Integer_Type (Expec_Type)
11248 and then Is_RTE (Found_Type, RE_Address)
11249 and then (Nkind (Parent (Expr)) = N_Op_Add
11251 Nkind (Parent (Expr)) = N_Op_Subtract)
11252 and then Expr = Left_Opnd (Parent (Expr))
11253 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11256 ("address arithmetic not predefined in package System",
11259 ("\possible missing with/use of System.Storage_Elements",
11263 -- If the expected type is an anonymous access type, as for access
11264 -- parameters and discriminants, the error is on the designated types.
11266 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11267 if Comes_From_Source (Expec_Type) then
11268 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11271 ("expected an access type with designated}",
11272 Expr, Designated_Type (Expec_Type));
11275 if Is_Access_Type (Found_Type)
11276 and then not Comes_From_Source (Found_Type)
11279 ("\\found an access type with designated}!",
11280 Expr, Designated_Type (Found_Type));
11282 if From_With_Type (Found_Type) then
11283 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11284 Error_Msg_Qual_Level := 99;
11285 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
11286 Error_Msg_Qual_Level := 0;
11288 Error_Msg_NE ("found}!", Expr, Found_Type);
11292 -- Normal case of one type found, some other type expected
11295 -- If the names of the two types are the same, see if some number
11296 -- of levels of qualification will help. Don't try more than three
11297 -- levels, and if we get to standard, it's no use (and probably
11298 -- represents an error in the compiler) Also do not bother with
11299 -- internal scope names.
11302 Expec_Scope : Entity_Id;
11303 Found_Scope : Entity_Id;
11306 Expec_Scope := Expec_Type;
11307 Found_Scope := Found_Type;
11309 for Levels in Int range 0 .. 3 loop
11310 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11311 Error_Msg_Qual_Level := Levels;
11315 Expec_Scope := Scope (Expec_Scope);
11316 Found_Scope := Scope (Found_Scope);
11318 exit when Expec_Scope = Standard_Standard
11319 or else Found_Scope = Standard_Standard
11320 or else not Comes_From_Source (Expec_Scope)
11321 or else not Comes_From_Source (Found_Scope);
11325 if Is_Record_Type (Expec_Type)
11326 and then Present (Corresponding_Remote_Type (Expec_Type))
11328 Error_Msg_NE ("expected}!", Expr,
11329 Corresponding_Remote_Type (Expec_Type));
11331 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11334 if Is_Entity_Name (Expr)
11335 and then Is_Package_Or_Generic_Package (Entity (Expr))
11337 Error_Msg_N ("\\found package name!", Expr);
11339 elsif Is_Entity_Name (Expr)
11341 (Ekind (Entity (Expr)) = E_Procedure
11343 Ekind (Entity (Expr)) = E_Generic_Procedure)
11345 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11347 ("found procedure name, possibly missing Access attribute!",
11351 ("\\found procedure name instead of function!", Expr);
11354 elsif Nkind (Expr) = N_Function_Call
11355 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11356 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11357 and then No (Parameter_Associations (Expr))
11360 ("found function name, possibly missing Access attribute!",
11363 -- Catch common error: a prefix or infix operator which is not
11364 -- directly visible because the type isn't.
11366 elsif Nkind (Expr) in N_Op
11367 and then Is_Overloaded (Expr)
11368 and then not Is_Immediately_Visible (Expec_Type)
11369 and then not Is_Potentially_Use_Visible (Expec_Type)
11370 and then not In_Use (Expec_Type)
11371 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11374 ("operator of the type is not directly visible!", Expr);
11376 elsif Ekind (Found_Type) = E_Void
11377 and then Present (Parent (Found_Type))
11378 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11380 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11383 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11386 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11387 -- of the same modular type, and (M1 and M2) = 0 was intended.
11389 if Expec_Type = Standard_Boolean
11390 and then Is_Modular_Integer_Type (Found_Type)
11391 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11392 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11395 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11396 L : constant Node_Id := Left_Opnd (Op);
11397 R : constant Node_Id := Right_Opnd (Op);
11399 -- The case for the message is when the left operand of the
11400 -- comparison is the same modular type, or when it is an
11401 -- integer literal (or other universal integer expression),
11402 -- which would have been typed as the modular type if the
11403 -- parens had been there.
11405 if (Etype (L) = Found_Type
11407 Etype (L) = Universal_Integer)
11408 and then Is_Integer_Type (Etype (R))
11411 ("\\possible missing parens for modular operation", Expr);
11416 -- Reset error message qualification indication
11418 Error_Msg_Qual_Level := 0;