1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Rtsfind; use Rtsfind;
44 with Scans; use Scans;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Type; use Sem_Type;
54 with Sinfo; use Sinfo;
55 with Sinput; use Sinput;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
59 with Targparm; use Targparm;
60 with Tbuild; use Tbuild;
61 with Ttypes; use Ttypes;
62 with Uname; use Uname;
64 with GNAT.HTable; use GNAT.HTable;
65 package body Sem_Util is
67 ----------------------------------------
68 -- Global_Variables for New_Copy_Tree --
69 ----------------------------------------
71 -- These global variables are used by New_Copy_Tree. See description
72 -- of the body of this subprogram for details. Global variables can be
73 -- safely used by New_Copy_Tree, since there is no case of a recursive
74 -- call from the processing inside New_Copy_Tree.
76 NCT_Hash_Threshhold : constant := 20;
77 -- If there are more than this number of pairs of entries in the
78 -- map, then Hash_Tables_Used will be set, and the hash tables will
79 -- be initialized and used for the searches.
81 NCT_Hash_Tables_Used : Boolean := False;
82 -- Set to True if hash tables are in use
84 NCT_Table_Entries : Nat;
85 -- Count entries in table to see if threshhold is reached
87 NCT_Hash_Table_Setup : Boolean := False;
88 -- Set to True if hash table contains data. We set this True if we
89 -- setup the hash table with data, and leave it set permanently
90 -- from then on, this is a signal that second and subsequent users
91 -- of the hash table must clear the old entries before reuse.
93 subtype NCT_Header_Num is Int range 0 .. 511;
94 -- Defines range of headers in hash tables (512 headers)
96 -----------------------
97 -- Local Subprograms --
98 -----------------------
100 function Build_Component_Subtype
103 T : Entity_Id) return Node_Id;
104 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
105 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
106 -- Loc is the source location, T is the original subtype.
108 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
109 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
110 -- with discriminants whose default values are static, examine only the
111 -- components in the selected variant to determine whether all of them
114 function Has_Null_Extension (T : Entity_Id) return Boolean;
115 -- T is a derived tagged type. Check whether the type extension is null.
116 -- If the parent type is fully initialized, T can be treated as such.
118 ------------------------------
119 -- Abstract_Interface_List --
120 ------------------------------
122 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
126 if Is_Concurrent_Type (Typ) then
128 -- If we are dealing with a synchronized subtype, go to the base
129 -- type, whose declaration has the interface list.
131 -- Shouldn't this be Declaration_Node???
133 Nod := Parent (Base_Type (Typ));
135 if Nkind (Nod) = N_Full_Type_Declaration then
139 elsif Ekind (Typ) = E_Record_Type_With_Private then
140 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
141 Nod := Type_Definition (Parent (Typ));
143 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
144 if Present (Full_View (Typ)) then
145 Nod := Type_Definition (Parent (Full_View (Typ)));
147 -- If the full-view is not available we cannot do anything else
148 -- here (the source has errors).
154 -- Support for generic formals with interfaces is still missing ???
156 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
161 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
165 elsif Ekind (Typ) = E_Record_Subtype then
166 Nod := Type_Definition (Parent (Etype (Typ)));
168 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
170 -- Recurse, because parent may still be a private extension. Also
171 -- note that the full view of the subtype or the full view of its
172 -- base type may (both) be unavailable.
174 return Abstract_Interface_List (Etype (Typ));
176 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
177 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
178 Nod := Formal_Type_Definition (Parent (Typ));
180 Nod := Type_Definition (Parent (Typ));
184 return Interface_List (Nod);
185 end Abstract_Interface_List;
187 --------------------------------
188 -- Add_Access_Type_To_Process --
189 --------------------------------
191 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
195 Ensure_Freeze_Node (E);
196 L := Access_Types_To_Process (Freeze_Node (E));
200 Set_Access_Types_To_Process (Freeze_Node (E), L);
204 end Add_Access_Type_To_Process;
206 ----------------------------
207 -- Add_Global_Declaration --
208 ----------------------------
210 procedure Add_Global_Declaration (N : Node_Id) is
211 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
214 if No (Declarations (Aux_Node)) then
215 Set_Declarations (Aux_Node, New_List);
218 Append_To (Declarations (Aux_Node), N);
220 end Add_Global_Declaration;
222 -----------------------
223 -- Alignment_In_Bits --
224 -----------------------
226 function Alignment_In_Bits (E : Entity_Id) return Uint is
228 return Alignment (E) * System_Storage_Unit;
229 end Alignment_In_Bits;
231 -----------------------------------------
232 -- Apply_Compile_Time_Constraint_Error --
233 -----------------------------------------
235 procedure Apply_Compile_Time_Constraint_Error
238 Reason : RT_Exception_Code;
239 Ent : Entity_Id := Empty;
240 Typ : Entity_Id := Empty;
241 Loc : Source_Ptr := No_Location;
242 Rep : Boolean := True;
243 Warn : Boolean := False)
245 Stat : constant Boolean := Is_Static_Expression (N);
246 R_Stat : constant Node_Id :=
247 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
258 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
264 -- Now we replace the node by an N_Raise_Constraint_Error node
265 -- This does not need reanalyzing, so set it as analyzed now.
268 Set_Analyzed (N, True);
271 Set_Raises_Constraint_Error (N);
273 -- Now deal with possible local raise handling
275 Possible_Local_Raise (N, Standard_Constraint_Error);
277 -- If the original expression was marked as static, the result is
278 -- still marked as static, but the Raises_Constraint_Error flag is
279 -- always set so that further static evaluation is not attempted.
282 Set_Is_Static_Expression (N);
284 end Apply_Compile_Time_Constraint_Error;
286 --------------------------
287 -- Build_Actual_Subtype --
288 --------------------------
290 function Build_Actual_Subtype
292 N : Node_Or_Entity_Id) return Node_Id
295 -- Normally Sloc (N), but may point to corresponding body in some cases
297 Constraints : List_Id;
303 Disc_Type : Entity_Id;
309 if Nkind (N) = N_Defining_Identifier then
310 Obj := New_Reference_To (N, Loc);
312 -- If this is a formal parameter of a subprogram declaration, and
313 -- we are compiling the body, we want the declaration for the
314 -- actual subtype to carry the source position of the body, to
315 -- prevent anomalies in gdb when stepping through the code.
317 if Is_Formal (N) then
319 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
321 if Nkind (Decl) = N_Subprogram_Declaration
322 and then Present (Corresponding_Body (Decl))
324 Loc := Sloc (Corresponding_Body (Decl));
333 if Is_Array_Type (T) then
334 Constraints := New_List;
335 for J in 1 .. Number_Dimensions (T) loop
337 -- Build an array subtype declaration with the nominal subtype and
338 -- the bounds of the actual. Add the declaration in front of the
339 -- local declarations for the subprogram, for analysis before any
340 -- reference to the formal in the body.
343 Make_Attribute_Reference (Loc,
345 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
346 Attribute_Name => Name_First,
347 Expressions => New_List (
348 Make_Integer_Literal (Loc, J)));
351 Make_Attribute_Reference (Loc,
353 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
354 Attribute_Name => Name_Last,
355 Expressions => New_List (
356 Make_Integer_Literal (Loc, J)));
358 Append (Make_Range (Loc, Lo, Hi), Constraints);
361 -- If the type has unknown discriminants there is no constrained
362 -- subtype to build. This is never called for a formal or for a
363 -- lhs, so returning the type is ok ???
365 elsif Has_Unknown_Discriminants (T) then
369 Constraints := New_List;
371 -- Type T is a generic derived type, inherit the discriminants from
374 if Is_Private_Type (T)
375 and then No (Full_View (T))
377 -- T was flagged as an error if it was declared as a formal
378 -- derived type with known discriminants. In this case there
379 -- is no need to look at the parent type since T already carries
380 -- its own discriminants.
382 and then not Error_Posted (T)
384 Disc_Type := Etype (Base_Type (T));
389 Discr := First_Discriminant (Disc_Type);
390 while Present (Discr) loop
391 Append_To (Constraints,
392 Make_Selected_Component (Loc,
394 Duplicate_Subexpr_No_Checks (Obj),
395 Selector_Name => New_Occurrence_Of (Discr, Loc)));
396 Next_Discriminant (Discr);
400 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
401 Set_Is_Internal (Subt);
404 Make_Subtype_Declaration (Loc,
405 Defining_Identifier => Subt,
406 Subtype_Indication =>
407 Make_Subtype_Indication (Loc,
408 Subtype_Mark => New_Reference_To (T, Loc),
410 Make_Index_Or_Discriminant_Constraint (Loc,
411 Constraints => Constraints)));
413 Mark_Rewrite_Insertion (Decl);
415 end Build_Actual_Subtype;
417 ---------------------------------------
418 -- Build_Actual_Subtype_Of_Component --
419 ---------------------------------------
421 function Build_Actual_Subtype_Of_Component
423 N : Node_Id) return Node_Id
425 Loc : constant Source_Ptr := Sloc (N);
426 P : constant Node_Id := Prefix (N);
429 Indx_Type : Entity_Id;
431 Deaccessed_T : Entity_Id;
432 -- This is either a copy of T, or if T is an access type, then it is
433 -- the directly designated type of this access type.
435 function Build_Actual_Array_Constraint return List_Id;
436 -- If one or more of the bounds of the component depends on
437 -- discriminants, build actual constraint using the discriminants
440 function Build_Actual_Record_Constraint return List_Id;
441 -- Similar to previous one, for discriminated components constrained
442 -- by the discriminant of the enclosing object.
444 -----------------------------------
445 -- Build_Actual_Array_Constraint --
446 -----------------------------------
448 function Build_Actual_Array_Constraint return List_Id is
449 Constraints : constant List_Id := New_List;
457 Indx := First_Index (Deaccessed_T);
458 while Present (Indx) loop
459 Old_Lo := Type_Low_Bound (Etype (Indx));
460 Old_Hi := Type_High_Bound (Etype (Indx));
462 if Denotes_Discriminant (Old_Lo) then
464 Make_Selected_Component (Loc,
465 Prefix => New_Copy_Tree (P),
466 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
469 Lo := New_Copy_Tree (Old_Lo);
471 -- The new bound will be reanalyzed in the enclosing
472 -- declaration. For literal bounds that come from a type
473 -- declaration, the type of the context must be imposed, so
474 -- insure that analysis will take place. For non-universal
475 -- types this is not strictly necessary.
477 Set_Analyzed (Lo, False);
480 if Denotes_Discriminant (Old_Hi) then
482 Make_Selected_Component (Loc,
483 Prefix => New_Copy_Tree (P),
484 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
487 Hi := New_Copy_Tree (Old_Hi);
488 Set_Analyzed (Hi, False);
491 Append (Make_Range (Loc, Lo, Hi), Constraints);
496 end Build_Actual_Array_Constraint;
498 ------------------------------------
499 -- Build_Actual_Record_Constraint --
500 ------------------------------------
502 function Build_Actual_Record_Constraint return List_Id is
503 Constraints : constant List_Id := New_List;
508 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
509 while Present (D) loop
510 if Denotes_Discriminant (Node (D)) then
511 D_Val := Make_Selected_Component (Loc,
512 Prefix => New_Copy_Tree (P),
513 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
516 D_Val := New_Copy_Tree (Node (D));
519 Append (D_Val, Constraints);
524 end Build_Actual_Record_Constraint;
526 -- Start of processing for Build_Actual_Subtype_Of_Component
529 -- Why the test for Spec_Expression mode here???
531 if In_Spec_Expression then
534 -- More comments for the rest of this body would be good ???
536 elsif Nkind (N) = N_Explicit_Dereference then
537 if Is_Composite_Type (T)
538 and then not Is_Constrained (T)
539 and then not (Is_Class_Wide_Type (T)
540 and then Is_Constrained (Root_Type (T)))
541 and then not Has_Unknown_Discriminants (T)
543 -- If the type of the dereference is already constrained, it is an
546 if Is_Array_Type (Etype (N))
547 and then Is_Constrained (Etype (N))
551 Remove_Side_Effects (P);
552 return Build_Actual_Subtype (T, N);
559 if Ekind (T) = E_Access_Subtype then
560 Deaccessed_T := Designated_Type (T);
565 if Ekind (Deaccessed_T) = E_Array_Subtype then
566 Id := First_Index (Deaccessed_T);
567 while Present (Id) loop
568 Indx_Type := Underlying_Type (Etype (Id));
570 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
572 Denotes_Discriminant (Type_High_Bound (Indx_Type))
574 Remove_Side_Effects (P);
576 Build_Component_Subtype
577 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
583 elsif Is_Composite_Type (Deaccessed_T)
584 and then Has_Discriminants (Deaccessed_T)
585 and then not Has_Unknown_Discriminants (Deaccessed_T)
587 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
588 while Present (D) loop
589 if Denotes_Discriminant (Node (D)) then
590 Remove_Side_Effects (P);
592 Build_Component_Subtype (
593 Build_Actual_Record_Constraint, Loc, Base_Type (T));
600 -- If none of the above, the actual and nominal subtypes are the same
603 end Build_Actual_Subtype_Of_Component;
605 -----------------------------
606 -- Build_Component_Subtype --
607 -----------------------------
609 function Build_Component_Subtype
612 T : Entity_Id) return Node_Id
618 -- Unchecked_Union components do not require component subtypes
620 if Is_Unchecked_Union (T) then
624 Subt := Make_Temporary (Loc, 'S');
625 Set_Is_Internal (Subt);
628 Make_Subtype_Declaration (Loc,
629 Defining_Identifier => Subt,
630 Subtype_Indication =>
631 Make_Subtype_Indication (Loc,
632 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
634 Make_Index_Or_Discriminant_Constraint (Loc,
637 Mark_Rewrite_Insertion (Decl);
639 end Build_Component_Subtype;
641 ---------------------------
642 -- Build_Default_Subtype --
643 ---------------------------
645 function Build_Default_Subtype
647 N : Node_Id) return Entity_Id
649 Loc : constant Source_Ptr := Sloc (N);
653 if not Has_Discriminants (T) or else Is_Constrained (T) then
657 Disc := First_Discriminant (T);
659 if No (Discriminant_Default_Value (Disc)) then
664 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
665 Constraints : constant List_Id := New_List;
669 while Present (Disc) loop
670 Append_To (Constraints,
671 New_Copy_Tree (Discriminant_Default_Value (Disc)));
672 Next_Discriminant (Disc);
676 Make_Subtype_Declaration (Loc,
677 Defining_Identifier => Act,
678 Subtype_Indication =>
679 Make_Subtype_Indication (Loc,
680 Subtype_Mark => New_Occurrence_Of (T, Loc),
682 Make_Index_Or_Discriminant_Constraint (Loc,
683 Constraints => Constraints)));
685 Insert_Action (N, Decl);
689 end Build_Default_Subtype;
691 --------------------------------------------
692 -- Build_Discriminal_Subtype_Of_Component --
693 --------------------------------------------
695 function Build_Discriminal_Subtype_Of_Component
696 (T : Entity_Id) return Node_Id
698 Loc : constant Source_Ptr := Sloc (T);
702 function Build_Discriminal_Array_Constraint return List_Id;
703 -- If one or more of the bounds of the component depends on
704 -- discriminants, build actual constraint using the discriminants
707 function Build_Discriminal_Record_Constraint return List_Id;
708 -- Similar to previous one, for discriminated components constrained
709 -- by the discriminant of the enclosing object.
711 ----------------------------------------
712 -- Build_Discriminal_Array_Constraint --
713 ----------------------------------------
715 function Build_Discriminal_Array_Constraint return List_Id is
716 Constraints : constant List_Id := New_List;
724 Indx := First_Index (T);
725 while Present (Indx) loop
726 Old_Lo := Type_Low_Bound (Etype (Indx));
727 Old_Hi := Type_High_Bound (Etype (Indx));
729 if Denotes_Discriminant (Old_Lo) then
730 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
733 Lo := New_Copy_Tree (Old_Lo);
736 if Denotes_Discriminant (Old_Hi) then
737 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
740 Hi := New_Copy_Tree (Old_Hi);
743 Append (Make_Range (Loc, Lo, Hi), Constraints);
748 end Build_Discriminal_Array_Constraint;
750 -----------------------------------------
751 -- Build_Discriminal_Record_Constraint --
752 -----------------------------------------
754 function Build_Discriminal_Record_Constraint return List_Id is
755 Constraints : constant List_Id := New_List;
760 D := First_Elmt (Discriminant_Constraint (T));
761 while Present (D) loop
762 if Denotes_Discriminant (Node (D)) then
764 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
767 D_Val := New_Copy_Tree (Node (D));
770 Append (D_Val, Constraints);
775 end Build_Discriminal_Record_Constraint;
777 -- Start of processing for Build_Discriminal_Subtype_Of_Component
780 if Ekind (T) = E_Array_Subtype then
781 Id := First_Index (T);
782 while Present (Id) loop
783 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
784 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
786 return Build_Component_Subtype
787 (Build_Discriminal_Array_Constraint, Loc, T);
793 elsif Ekind (T) = E_Record_Subtype
794 and then Has_Discriminants (T)
795 and then not Has_Unknown_Discriminants (T)
797 D := First_Elmt (Discriminant_Constraint (T));
798 while Present (D) loop
799 if Denotes_Discriminant (Node (D)) then
800 return Build_Component_Subtype
801 (Build_Discriminal_Record_Constraint, Loc, T);
808 -- If none of the above, the actual and nominal subtypes are the same
811 end Build_Discriminal_Subtype_Of_Component;
813 ------------------------------
814 -- Build_Elaboration_Entity --
815 ------------------------------
817 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
818 Loc : constant Source_Ptr := Sloc (N);
820 Elab_Ent : Entity_Id;
822 procedure Set_Package_Name (Ent : Entity_Id);
823 -- Given an entity, sets the fully qualified name of the entity in
824 -- Name_Buffer, with components separated by double underscores. This
825 -- is a recursive routine that climbs the scope chain to Standard.
827 ----------------------
828 -- Set_Package_Name --
829 ----------------------
831 procedure Set_Package_Name (Ent : Entity_Id) is
833 if Scope (Ent) /= Standard_Standard then
834 Set_Package_Name (Scope (Ent));
837 Nam : constant String := Get_Name_String (Chars (Ent));
839 Name_Buffer (Name_Len + 1) := '_';
840 Name_Buffer (Name_Len + 2) := '_';
841 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
842 Name_Len := Name_Len + Nam'Length + 2;
846 Get_Name_String (Chars (Ent));
848 end Set_Package_Name;
850 -- Start of processing for Build_Elaboration_Entity
853 -- Ignore if already constructed
855 if Present (Elaboration_Entity (Spec_Id)) then
859 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
860 -- name with dots replaced by double underscore. We have to manually
861 -- construct this name, since it will be elaborated in the outer scope,
862 -- and thus will not have the unit name automatically prepended.
864 Set_Package_Name (Spec_Id);
868 Name_Buffer (Name_Len + 1) := '_';
869 Name_Buffer (Name_Len + 2) := 'E';
870 Name_Len := Name_Len + 2;
872 -- Create elaboration flag
875 Make_Defining_Identifier (Loc, Chars => Name_Find);
876 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
879 Make_Object_Declaration (Loc,
880 Defining_Identifier => Elab_Ent,
882 New_Occurrence_Of (Standard_Boolean, Loc),
884 New_Occurrence_Of (Standard_False, Loc));
886 Push_Scope (Standard_Standard);
887 Add_Global_Declaration (Decl);
890 -- Reset True_Constant indication, since we will indeed assign a value
891 -- to the variable in the binder main. We also kill the Current_Value
892 -- and Last_Assignment fields for the same reason.
894 Set_Is_True_Constant (Elab_Ent, False);
895 Set_Current_Value (Elab_Ent, Empty);
896 Set_Last_Assignment (Elab_Ent, Empty);
898 -- We do not want any further qualification of the name (if we did
899 -- not do this, we would pick up the name of the generic package
900 -- in the case of a library level generic instantiation).
902 Set_Has_Qualified_Name (Elab_Ent);
903 Set_Has_Fully_Qualified_Name (Elab_Ent);
904 end Build_Elaboration_Entity;
906 -----------------------------------
907 -- Cannot_Raise_Constraint_Error --
908 -----------------------------------
910 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
912 if Compile_Time_Known_Value (Expr) then
915 elsif Do_Range_Check (Expr) then
918 elsif Raises_Constraint_Error (Expr) then
926 when N_Expanded_Name =>
929 when N_Selected_Component =>
930 return not Do_Discriminant_Check (Expr);
932 when N_Attribute_Reference =>
933 if Do_Overflow_Check (Expr) then
936 elsif No (Expressions (Expr)) then
944 N := First (Expressions (Expr));
945 while Present (N) loop
946 if Cannot_Raise_Constraint_Error (N) then
957 when N_Type_Conversion =>
958 if Do_Overflow_Check (Expr)
959 or else Do_Length_Check (Expr)
960 or else Do_Tag_Check (Expr)
965 Cannot_Raise_Constraint_Error (Expression (Expr));
968 when N_Unchecked_Type_Conversion =>
969 return Cannot_Raise_Constraint_Error (Expression (Expr));
972 if Do_Overflow_Check (Expr) then
976 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
983 if Do_Division_Check (Expr)
984 or else Do_Overflow_Check (Expr)
989 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
991 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1010 N_Op_Shift_Right_Arithmetic |
1014 if Do_Overflow_Check (Expr) then
1018 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1020 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1027 end Cannot_Raise_Constraint_Error;
1029 -----------------------------------------
1030 -- Check_Dynamically_Tagged_Expression --
1031 -----------------------------------------
1033 procedure Check_Dynamically_Tagged_Expression
1036 Related_Nod : Node_Id)
1039 pragma Assert (Is_Tagged_Type (Typ));
1041 -- In order to avoid spurious errors when analyzing the expanded code,
1042 -- this check is done only for nodes that come from source and for
1043 -- actuals of generic instantiations.
1045 if (Comes_From_Source (Related_Nod)
1046 or else In_Generic_Actual (Expr))
1047 and then (Is_Class_Wide_Type (Etype (Expr))
1048 or else Is_Dynamically_Tagged (Expr))
1049 and then Is_Tagged_Type (Typ)
1050 and then not Is_Class_Wide_Type (Typ)
1052 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1054 end Check_Dynamically_Tagged_Expression;
1056 --------------------------
1057 -- Check_Fully_Declared --
1058 --------------------------
1060 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1062 if Ekind (T) = E_Incomplete_Type then
1064 -- Ada 2005 (AI-50217): If the type is available through a limited
1065 -- with_clause, verify that its full view has been analyzed.
1067 if From_With_Type (T)
1068 and then Present (Non_Limited_View (T))
1069 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1071 -- The non-limited view is fully declared
1076 ("premature usage of incomplete}", N, First_Subtype (T));
1079 -- Need comments for these tests ???
1081 elsif Has_Private_Component (T)
1082 and then not Is_Generic_Type (Root_Type (T))
1083 and then not In_Spec_Expression
1085 -- Special case: if T is the anonymous type created for a single
1086 -- task or protected object, use the name of the source object.
1088 if Is_Concurrent_Type (T)
1089 and then not Comes_From_Source (T)
1090 and then Nkind (N) = N_Object_Declaration
1092 Error_Msg_NE ("type of& has incomplete component", N,
1093 Defining_Identifier (N));
1097 ("premature usage of incomplete}", N, First_Subtype (T));
1100 end Check_Fully_Declared;
1102 -------------------------
1103 -- Check_Nested_Access --
1104 -------------------------
1106 procedure Check_Nested_Access (Ent : Entity_Id) is
1107 Scop : constant Entity_Id := Current_Scope;
1108 Current_Subp : Entity_Id;
1109 Enclosing : Entity_Id;
1112 -- Currently only enabled for VM back-ends for efficiency, should we
1113 -- enable it more systematically ???
1115 -- Check for Is_Imported needs commenting below ???
1117 if VM_Target /= No_VM
1118 and then (Ekind (Ent) = E_Variable
1120 Ekind (Ent) = E_Constant
1122 Ekind (Ent) = E_Loop_Parameter)
1123 and then Scope (Ent) /= Empty
1124 and then not Is_Library_Level_Entity (Ent)
1125 and then not Is_Imported (Ent)
1127 if Is_Subprogram (Scop)
1128 or else Is_Generic_Subprogram (Scop)
1129 or else Is_Entry (Scop)
1131 Current_Subp := Scop;
1133 Current_Subp := Current_Subprogram;
1136 Enclosing := Enclosing_Subprogram (Ent);
1138 if Enclosing /= Empty
1139 and then Enclosing /= Current_Subp
1141 Set_Has_Up_Level_Access (Ent, True);
1144 end Check_Nested_Access;
1146 ------------------------------------------
1147 -- Check_Potentially_Blocking_Operation --
1148 ------------------------------------------
1150 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1153 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1154 -- When pragma Detect_Blocking is active, the run time will raise
1155 -- Program_Error. Here we only issue a warning, since we generally
1156 -- support the use of potentially blocking operations in the absence
1159 -- Indirect blocking through a subprogram call cannot be diagnosed
1160 -- statically without interprocedural analysis, so we do not attempt
1163 S := Scope (Current_Scope);
1164 while Present (S) and then S /= Standard_Standard loop
1165 if Is_Protected_Type (S) then
1167 ("potentially blocking operation in protected operation?", N);
1174 end Check_Potentially_Blocking_Operation;
1176 ------------------------------
1177 -- Check_Unprotected_Access --
1178 ------------------------------
1180 procedure Check_Unprotected_Access
1184 Cont_Encl_Typ : Entity_Id;
1185 Pref_Encl_Typ : Entity_Id;
1187 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1188 -- Check whether Obj is a private component of a protected object.
1189 -- Return the protected type where the component resides, Empty
1192 function Is_Public_Operation return Boolean;
1193 -- Verify that the enclosing operation is callable from outside the
1194 -- protected object, to minimize false positives.
1196 ------------------------------
1197 -- Enclosing_Protected_Type --
1198 ------------------------------
1200 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1202 if Is_Entity_Name (Obj) then
1204 Ent : Entity_Id := Entity (Obj);
1207 -- The object can be a renaming of a private component, use
1208 -- the original record component.
1210 if Is_Prival (Ent) then
1211 Ent := Prival_Link (Ent);
1214 if Is_Protected_Type (Scope (Ent)) then
1220 -- For indexed and selected components, recursively check the prefix
1222 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1223 return Enclosing_Protected_Type (Prefix (Obj));
1225 -- The object does not denote a protected component
1230 end Enclosing_Protected_Type;
1232 -------------------------
1233 -- Is_Public_Operation --
1234 -------------------------
1236 function Is_Public_Operation return Boolean is
1243 and then S /= Pref_Encl_Typ
1245 if Scope (S) = Pref_Encl_Typ then
1246 E := First_Entity (Pref_Encl_Typ);
1248 and then E /= First_Private_Entity (Pref_Encl_Typ)
1261 end Is_Public_Operation;
1263 -- Start of processing for Check_Unprotected_Access
1266 if Nkind (Expr) = N_Attribute_Reference
1267 and then Attribute_Name (Expr) = Name_Unchecked_Access
1269 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1270 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1272 -- Check whether we are trying to export a protected component to a
1273 -- context with an equal or lower access level.
1275 if Present (Pref_Encl_Typ)
1276 and then No (Cont_Encl_Typ)
1277 and then Is_Public_Operation
1278 and then Scope_Depth (Pref_Encl_Typ) >=
1279 Object_Access_Level (Context)
1282 ("?possible unprotected access to protected data", Expr);
1285 end Check_Unprotected_Access;
1291 procedure Check_VMS (Construct : Node_Id) is
1293 if not OpenVMS_On_Target then
1295 ("this construct is allowed only in Open'V'M'S", Construct);
1299 ------------------------
1300 -- Collect_Interfaces --
1301 ------------------------
1303 procedure Collect_Interfaces
1305 Ifaces_List : out Elist_Id;
1306 Exclude_Parents : Boolean := False;
1307 Use_Full_View : Boolean := True)
1309 procedure Collect (Typ : Entity_Id);
1310 -- Subsidiary subprogram used to traverse the whole list
1311 -- of directly and indirectly implemented interfaces
1317 procedure Collect (Typ : Entity_Id) is
1318 Ancestor : Entity_Id;
1326 -- Handle private types
1329 and then Is_Private_Type (Typ)
1330 and then Present (Full_View (Typ))
1332 Full_T := Full_View (Typ);
1335 -- Include the ancestor if we are generating the whole list of
1336 -- abstract interfaces.
1338 if Etype (Full_T) /= Typ
1340 -- Protect the frontend against wrong sources. For example:
1343 -- type A is tagged null record;
1344 -- type B is new A with private;
1345 -- type C is new A with private;
1347 -- type B is new C with null record;
1348 -- type C is new B with null record;
1351 and then Etype (Full_T) /= T
1353 Ancestor := Etype (Full_T);
1356 if Is_Interface (Ancestor)
1357 and then not Exclude_Parents
1359 Append_Unique_Elmt (Ancestor, Ifaces_List);
1363 -- Traverse the graph of ancestor interfaces
1365 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1366 Id := First (Abstract_Interface_List (Full_T));
1367 while Present (Id) loop
1368 Iface := Etype (Id);
1370 -- Protect against wrong uses. For example:
1371 -- type I is interface;
1372 -- type O is tagged null record;
1373 -- type Wrong is new I and O with null record; -- ERROR
1375 if Is_Interface (Iface) then
1377 and then Etype (T) /= T
1378 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1383 Append_Unique_Elmt (Iface, Ifaces_List);
1392 -- Start of processing for Collect_Interfaces
1395 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1396 Ifaces_List := New_Elmt_List;
1398 end Collect_Interfaces;
1400 ----------------------------------
1401 -- Collect_Interface_Components --
1402 ----------------------------------
1404 procedure Collect_Interface_Components
1405 (Tagged_Type : Entity_Id;
1406 Components_List : out Elist_Id)
1408 procedure Collect (Typ : Entity_Id);
1409 -- Subsidiary subprogram used to climb to the parents
1415 procedure Collect (Typ : Entity_Id) is
1416 Tag_Comp : Entity_Id;
1417 Parent_Typ : Entity_Id;
1420 -- Handle private types
1422 if Present (Full_View (Etype (Typ))) then
1423 Parent_Typ := Full_View (Etype (Typ));
1425 Parent_Typ := Etype (Typ);
1428 if Parent_Typ /= Typ
1430 -- Protect the frontend against wrong sources. For example:
1433 -- type A is tagged null record;
1434 -- type B is new A with private;
1435 -- type C is new A with private;
1437 -- type B is new C with null record;
1438 -- type C is new B with null record;
1441 and then Parent_Typ /= Tagged_Type
1443 Collect (Parent_Typ);
1446 -- Collect the components containing tags of secondary dispatch
1449 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1450 while Present (Tag_Comp) loop
1451 pragma Assert (Present (Related_Type (Tag_Comp)));
1452 Append_Elmt (Tag_Comp, Components_List);
1454 Tag_Comp := Next_Tag_Component (Tag_Comp);
1458 -- Start of processing for Collect_Interface_Components
1461 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1462 and then Is_Tagged_Type (Tagged_Type));
1464 Components_List := New_Elmt_List;
1465 Collect (Tagged_Type);
1466 end Collect_Interface_Components;
1468 -----------------------------
1469 -- Collect_Interfaces_Info --
1470 -----------------------------
1472 procedure Collect_Interfaces_Info
1474 Ifaces_List : out Elist_Id;
1475 Components_List : out Elist_Id;
1476 Tags_List : out Elist_Id)
1478 Comps_List : Elist_Id;
1479 Comp_Elmt : Elmt_Id;
1480 Comp_Iface : Entity_Id;
1481 Iface_Elmt : Elmt_Id;
1484 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1485 -- Search for the secondary tag associated with the interface type
1486 -- Iface that is implemented by T.
1492 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1496 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1498 and then Ekind (Node (ADT)) = E_Constant
1499 and then Related_Type (Node (ADT)) /= Iface
1501 -- Skip the secondary dispatch tables of Iface
1509 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1513 -- Start of processing for Collect_Interfaces_Info
1516 Collect_Interfaces (T, Ifaces_List);
1517 Collect_Interface_Components (T, Comps_List);
1519 -- Search for the record component and tag associated with each
1520 -- interface type of T.
1522 Components_List := New_Elmt_List;
1523 Tags_List := New_Elmt_List;
1525 Iface_Elmt := First_Elmt (Ifaces_List);
1526 while Present (Iface_Elmt) loop
1527 Iface := Node (Iface_Elmt);
1529 -- Associate the primary tag component and the primary dispatch table
1530 -- with all the interfaces that are parents of T
1532 if Is_Ancestor (Iface, T) then
1533 Append_Elmt (First_Tag_Component (T), Components_List);
1534 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1536 -- Otherwise search for the tag component and secondary dispatch
1540 Comp_Elmt := First_Elmt (Comps_List);
1541 while Present (Comp_Elmt) loop
1542 Comp_Iface := Related_Type (Node (Comp_Elmt));
1544 if Comp_Iface = Iface
1545 or else Is_Ancestor (Iface, Comp_Iface)
1547 Append_Elmt (Node (Comp_Elmt), Components_List);
1548 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1552 Next_Elmt (Comp_Elmt);
1554 pragma Assert (Present (Comp_Elmt));
1557 Next_Elmt (Iface_Elmt);
1559 end Collect_Interfaces_Info;
1561 ----------------------------------
1562 -- Collect_Primitive_Operations --
1563 ----------------------------------
1565 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1566 B_Type : constant Entity_Id := Base_Type (T);
1567 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1568 B_Scope : Entity_Id := Scope (B_Type);
1572 Formal_Derived : Boolean := False;
1576 -- For tagged types, the primitive operations are collected as they
1577 -- are declared, and held in an explicit list which is simply returned.
1579 if Is_Tagged_Type (B_Type) then
1580 return Primitive_Operations (B_Type);
1582 -- An untagged generic type that is a derived type inherits the
1583 -- primitive operations of its parent type. Other formal types only
1584 -- have predefined operators, which are not explicitly represented.
1586 elsif Is_Generic_Type (B_Type) then
1587 if Nkind (B_Decl) = N_Formal_Type_Declaration
1588 and then Nkind (Formal_Type_Definition (B_Decl))
1589 = N_Formal_Derived_Type_Definition
1591 Formal_Derived := True;
1593 return New_Elmt_List;
1597 Op_List := New_Elmt_List;
1599 if B_Scope = Standard_Standard then
1600 if B_Type = Standard_String then
1601 Append_Elmt (Standard_Op_Concat, Op_List);
1603 elsif B_Type = Standard_Wide_String then
1604 Append_Elmt (Standard_Op_Concatw, Op_List);
1610 elsif (Is_Package_Or_Generic_Package (B_Scope)
1612 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1614 or else Is_Derived_Type (B_Type)
1616 -- The primitive operations appear after the base type, except
1617 -- if the derivation happens within the private part of B_Scope
1618 -- and the type is a private type, in which case both the type
1619 -- and some primitive operations may appear before the base
1620 -- type, and the list of candidates starts after the type.
1622 if In_Open_Scopes (B_Scope)
1623 and then Scope (T) = B_Scope
1624 and then In_Private_Part (B_Scope)
1626 Id := Next_Entity (T);
1628 Id := Next_Entity (B_Type);
1631 while Present (Id) loop
1633 -- Note that generic formal subprograms are not
1634 -- considered to be primitive operations and thus
1635 -- are never inherited.
1637 if Is_Overloadable (Id)
1638 and then Nkind (Parent (Parent (Id)))
1639 not in N_Formal_Subprogram_Declaration
1643 if Base_Type (Etype (Id)) = B_Type then
1646 Formal := First_Formal (Id);
1647 while Present (Formal) loop
1648 if Base_Type (Etype (Formal)) = B_Type then
1652 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1654 (Designated_Type (Etype (Formal))) = B_Type
1660 Next_Formal (Formal);
1664 -- For a formal derived type, the only primitives are the
1665 -- ones inherited from the parent type. Operations appearing
1666 -- in the package declaration are not primitive for it.
1669 and then (not Formal_Derived
1670 or else Present (Alias (Id)))
1672 -- In the special case of an equality operator aliased to
1673 -- an overriding dispatching equality belonging to the same
1674 -- type, we don't include it in the list of primitives.
1675 -- This avoids inheriting multiple equality operators when
1676 -- deriving from untagged private types whose full type is
1677 -- tagged, which can otherwise cause ambiguities. Note that
1678 -- this should only happen for this kind of untagged parent
1679 -- type, since normally dispatching operations are inherited
1680 -- using the type's Primitive_Operations list.
1682 if Chars (Id) = Name_Op_Eq
1683 and then Is_Dispatching_Operation (Id)
1684 and then Present (Alias (Id))
1685 and then Is_Overriding_Operation (Alias (Id))
1686 and then Base_Type (Etype (First_Entity (Id))) =
1687 Base_Type (Etype (First_Entity (Alias (Id))))
1691 -- Include the subprogram in the list of primitives
1694 Append_Elmt (Id, Op_List);
1701 -- For a type declared in System, some of its operations may
1702 -- appear in the target-specific extension to System.
1705 and then Chars (B_Scope) = Name_System
1706 and then Scope (B_Scope) = Standard_Standard
1707 and then Present_System_Aux
1709 B_Scope := System_Aux_Id;
1710 Id := First_Entity (System_Aux_Id);
1716 end Collect_Primitive_Operations;
1718 -----------------------------------
1719 -- Compile_Time_Constraint_Error --
1720 -----------------------------------
1722 function Compile_Time_Constraint_Error
1725 Ent : Entity_Id := Empty;
1726 Loc : Source_Ptr := No_Location;
1727 Warn : Boolean := False) return Node_Id
1729 Msgc : String (1 .. Msg'Length + 2);
1730 -- Copy of message, with room for possible ? and ! at end
1740 -- A static constraint error in an instance body is not a fatal error.
1741 -- we choose to inhibit the message altogether, because there is no
1742 -- obvious node (for now) on which to post it. On the other hand the
1743 -- offending node must be replaced with a constraint_error in any case.
1745 -- No messages are generated if we already posted an error on this node
1747 if not Error_Posted (N) then
1748 if Loc /= No_Location then
1754 Msgc (1 .. Msg'Length) := Msg;
1757 -- Message is a warning, even in Ada 95 case
1759 if Msg (Msg'Last) = '?' then
1762 -- In Ada 83, all messages are warnings. In the private part and
1763 -- the body of an instance, constraint_checks are only warnings.
1764 -- We also make this a warning if the Warn parameter is set.
1767 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1773 elsif In_Instance_Not_Visible then
1778 -- Otherwise we have a real error message (Ada 95 static case)
1779 -- and we make this an unconditional message. Note that in the
1780 -- warning case we do not make the message unconditional, it seems
1781 -- quite reasonable to delete messages like this (about exceptions
1782 -- that will be raised) in dead code.
1790 -- Should we generate a warning? The answer is not quite yes. The
1791 -- very annoying exception occurs in the case of a short circuit
1792 -- operator where the left operand is static and decisive. Climb
1793 -- parents to see if that is the case we have here. Conditional
1794 -- expressions with decisive conditions are a similar situation.
1802 -- And then with False as left operand
1804 if Nkind (P) = N_And_Then
1805 and then Compile_Time_Known_Value (Left_Opnd (P))
1806 and then Is_False (Expr_Value (Left_Opnd (P)))
1811 -- OR ELSE with True as left operand
1813 elsif Nkind (P) = N_Or_Else
1814 and then Compile_Time_Known_Value (Left_Opnd (P))
1815 and then Is_True (Expr_Value (Left_Opnd (P)))
1820 -- Conditional expression
1822 elsif Nkind (P) = N_Conditional_Expression then
1824 Cond : constant Node_Id := First (Expressions (P));
1825 Texp : constant Node_Id := Next (Cond);
1826 Fexp : constant Node_Id := Next (Texp);
1829 if Compile_Time_Known_Value (Cond) then
1831 -- Condition is True and we are in the right operand
1833 if Is_True (Expr_Value (Cond))
1834 and then OldP = Fexp
1839 -- Condition is False and we are in the left operand
1841 elsif Is_False (Expr_Value (Cond))
1842 and then OldP = Texp
1850 -- Special case for component association in aggregates, where
1851 -- we want to keep climbing up to the parent aggregate.
1853 elsif Nkind (P) = N_Component_Association
1854 and then Nkind (Parent (P)) = N_Aggregate
1858 -- Keep going if within subexpression
1861 exit when Nkind (P) not in N_Subexpr;
1866 if Present (Ent) then
1867 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1869 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1873 if Inside_Init_Proc then
1875 ("\?& will be raised for objects of this type",
1876 N, Standard_Constraint_Error, Eloc);
1879 ("\?& will be raised at run time",
1880 N, Standard_Constraint_Error, Eloc);
1885 ("\static expression fails Constraint_Check", Eloc);
1886 Set_Error_Posted (N);
1892 end Compile_Time_Constraint_Error;
1894 -----------------------
1895 -- Conditional_Delay --
1896 -----------------------
1898 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1900 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1901 Set_Has_Delayed_Freeze (New_Ent);
1903 end Conditional_Delay;
1905 -------------------------
1906 -- Copy_Parameter_List --
1907 -------------------------
1909 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1910 Loc : constant Source_Ptr := Sloc (Subp_Id);
1915 if No (First_Formal (Subp_Id)) then
1919 Formal := First_Formal (Subp_Id);
1920 while Present (Formal) loop
1922 (Make_Parameter_Specification (Loc,
1923 Defining_Identifier =>
1924 Make_Defining_Identifier (Sloc (Formal),
1925 Chars => Chars (Formal)),
1926 In_Present => In_Present (Parent (Formal)),
1927 Out_Present => Out_Present (Parent (Formal)),
1929 New_Reference_To (Etype (Formal), Loc),
1931 New_Copy_Tree (Expression (Parent (Formal)))),
1934 Next_Formal (Formal);
1939 end Copy_Parameter_List;
1941 --------------------
1942 -- Current_Entity --
1943 --------------------
1945 -- The currently visible definition for a given identifier is the
1946 -- one most chained at the start of the visibility chain, i.e. the
1947 -- one that is referenced by the Node_Id value of the name of the
1948 -- given identifier.
1950 function Current_Entity (N : Node_Id) return Entity_Id is
1952 return Get_Name_Entity_Id (Chars (N));
1955 -----------------------------
1956 -- Current_Entity_In_Scope --
1957 -----------------------------
1959 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1961 CS : constant Entity_Id := Current_Scope;
1963 Transient_Case : constant Boolean := Scope_Is_Transient;
1966 E := Get_Name_Entity_Id (Chars (N));
1968 and then Scope (E) /= CS
1969 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1975 end Current_Entity_In_Scope;
1981 function Current_Scope return Entity_Id is
1983 if Scope_Stack.Last = -1 then
1984 return Standard_Standard;
1987 C : constant Entity_Id :=
1988 Scope_Stack.Table (Scope_Stack.Last).Entity;
1993 return Standard_Standard;
1999 ------------------------
2000 -- Current_Subprogram --
2001 ------------------------
2003 function Current_Subprogram return Entity_Id is
2004 Scop : constant Entity_Id := Current_Scope;
2006 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2009 return Enclosing_Subprogram (Scop);
2011 end Current_Subprogram;
2013 ---------------------
2014 -- Defining_Entity --
2015 ---------------------
2017 function Defining_Entity (N : Node_Id) return Entity_Id is
2018 K : constant Node_Kind := Nkind (N);
2019 Err : Entity_Id := Empty;
2024 N_Subprogram_Declaration |
2025 N_Abstract_Subprogram_Declaration |
2027 N_Package_Declaration |
2028 N_Subprogram_Renaming_Declaration |
2029 N_Subprogram_Body_Stub |
2030 N_Generic_Subprogram_Declaration |
2031 N_Generic_Package_Declaration |
2032 N_Formal_Subprogram_Declaration
2034 return Defining_Entity (Specification (N));
2037 N_Component_Declaration |
2038 N_Defining_Program_Unit_Name |
2039 N_Discriminant_Specification |
2041 N_Entry_Declaration |
2042 N_Entry_Index_Specification |
2043 N_Exception_Declaration |
2044 N_Exception_Renaming_Declaration |
2045 N_Formal_Object_Declaration |
2046 N_Formal_Package_Declaration |
2047 N_Formal_Type_Declaration |
2048 N_Full_Type_Declaration |
2049 N_Implicit_Label_Declaration |
2050 N_Incomplete_Type_Declaration |
2051 N_Loop_Parameter_Specification |
2052 N_Number_Declaration |
2053 N_Object_Declaration |
2054 N_Object_Renaming_Declaration |
2055 N_Package_Body_Stub |
2056 N_Parameter_Specification |
2057 N_Private_Extension_Declaration |
2058 N_Private_Type_Declaration |
2060 N_Protected_Body_Stub |
2061 N_Protected_Type_Declaration |
2062 N_Single_Protected_Declaration |
2063 N_Single_Task_Declaration |
2064 N_Subtype_Declaration |
2067 N_Task_Type_Declaration
2069 return Defining_Identifier (N);
2072 return Defining_Entity (Proper_Body (N));
2075 N_Function_Instantiation |
2076 N_Function_Specification |
2077 N_Generic_Function_Renaming_Declaration |
2078 N_Generic_Package_Renaming_Declaration |
2079 N_Generic_Procedure_Renaming_Declaration |
2081 N_Package_Instantiation |
2082 N_Package_Renaming_Declaration |
2083 N_Package_Specification |
2084 N_Procedure_Instantiation |
2085 N_Procedure_Specification
2088 Nam : constant Node_Id := Defining_Unit_Name (N);
2091 if Nkind (Nam) in N_Entity then
2094 -- For Error, make up a name and attach to declaration
2095 -- so we can continue semantic analysis
2097 elsif Nam = Error then
2098 Err := Make_Temporary (Sloc (N), 'T');
2099 Set_Defining_Unit_Name (N, Err);
2102 -- If not an entity, get defining identifier
2105 return Defining_Identifier (Nam);
2109 when N_Block_Statement =>
2110 return Entity (Identifier (N));
2113 raise Program_Error;
2116 end Defining_Entity;
2118 --------------------------
2119 -- Denotes_Discriminant --
2120 --------------------------
2122 function Denotes_Discriminant
2124 Check_Concurrent : Boolean := False) return Boolean
2128 if not Is_Entity_Name (N)
2129 or else No (Entity (N))
2136 -- If we are checking for a protected type, the discriminant may have
2137 -- been rewritten as the corresponding discriminal of the original type
2138 -- or of the corresponding concurrent record, depending on whether we
2139 -- are in the spec or body of the protected type.
2141 return Ekind (E) = E_Discriminant
2144 and then Ekind (E) = E_In_Parameter
2145 and then Present (Discriminal_Link (E))
2147 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2149 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2151 end Denotes_Discriminant;
2153 -------------------------
2154 -- Denotes_Same_Object --
2155 -------------------------
2157 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2159 -- If we have entity names, then must be same entity
2161 if Is_Entity_Name (A1) then
2162 if Is_Entity_Name (A2) then
2163 return Entity (A1) = Entity (A2);
2168 -- No match if not same node kind
2170 elsif Nkind (A1) /= Nkind (A2) then
2173 -- For selected components, must have same prefix and selector
2175 elsif Nkind (A1) = N_Selected_Component then
2176 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
2178 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
2180 -- For explicit dereferences, prefixes must be same
2182 elsif Nkind (A1) = N_Explicit_Dereference then
2183 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
2185 -- For indexed components, prefixes and all subscripts must be the same
2187 elsif Nkind (A1) = N_Indexed_Component then
2188 if Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
2194 Indx1 := First (Expressions (A1));
2195 Indx2 := First (Expressions (A2));
2196 while Present (Indx1) loop
2198 -- Shouldn't we be checking that values are the same???
2200 if not Denotes_Same_Object (Indx1, Indx2) then
2214 -- For slices, prefixes must match and bounds must match
2216 elsif Nkind (A1) = N_Slice
2217 and then Denotes_Same_Object (Prefix (A1), Prefix (A2))
2220 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2223 Get_Index_Bounds (Etype (A1), Lo1, Hi1);
2224 Get_Index_Bounds (Etype (A2), Lo2, Hi2);
2226 -- Check whether bounds are statically identical. There is no
2227 -- attempt to detect partial overlap of slices.
2229 -- What about an array and a slice of an array???
2231 return Denotes_Same_Object (Lo1, Lo2)
2232 and then Denotes_Same_Object (Hi1, Hi2);
2235 -- Literals will appear as indices. Isn't this where we should check
2236 -- Known_At_Compile_Time at least if we are generating warnings ???
2238 elsif Nkind (A1) = N_Integer_Literal then
2239 return Intval (A1) = Intval (A2);
2244 end Denotes_Same_Object;
2246 -------------------------
2247 -- Denotes_Same_Prefix --
2248 -------------------------
2250 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2253 if Is_Entity_Name (A1) then
2254 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component) then
2255 return Denotes_Same_Object (A1, Prefix (A2))
2256 or else Denotes_Same_Prefix (A1, Prefix (A2));
2261 elsif Is_Entity_Name (A2) then
2262 return Denotes_Same_Prefix (A2, A1);
2264 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2266 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2269 Root1, Root2 : Node_Id;
2270 Depth1, Depth2 : Int := 0;
2273 Root1 := Prefix (A1);
2274 while not Is_Entity_Name (Root1) loop
2276 (Root1, N_Selected_Component, N_Indexed_Component)
2280 Root1 := Prefix (Root1);
2283 Depth1 := Depth1 + 1;
2286 Root2 := Prefix (A2);
2287 while not Is_Entity_Name (Root2) loop
2289 (Root2, N_Selected_Component, N_Indexed_Component)
2293 Root2 := Prefix (Root2);
2296 Depth2 := Depth2 + 1;
2299 -- If both have the same depth and they do not denote the same
2300 -- object, they are disjoint and not warning is needed.
2302 if Depth1 = Depth2 then
2305 elsif Depth1 > Depth2 then
2306 Root1 := Prefix (A1);
2307 for I in 1 .. Depth1 - Depth2 - 1 loop
2308 Root1 := Prefix (Root1);
2311 return Denotes_Same_Object (Root1, A2);
2314 Root2 := Prefix (A2);
2315 for I in 1 .. Depth2 - Depth1 - 1 loop
2316 Root2 := Prefix (Root2);
2319 return Denotes_Same_Object (A1, Root2);
2326 end Denotes_Same_Prefix;
2328 ----------------------
2329 -- Denotes_Variable --
2330 ----------------------
2332 function Denotes_Variable (N : Node_Id) return Boolean is
2334 return Is_Variable (N) and then Paren_Count (N) = 0;
2335 end Denotes_Variable;
2337 -----------------------------
2338 -- Depends_On_Discriminant --
2339 -----------------------------
2341 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2346 Get_Index_Bounds (N, L, H);
2347 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2348 end Depends_On_Discriminant;
2350 -------------------------
2351 -- Designate_Same_Unit --
2352 -------------------------
2354 function Designate_Same_Unit
2356 Name2 : Node_Id) return Boolean
2358 K1 : constant Node_Kind := Nkind (Name1);
2359 K2 : constant Node_Kind := Nkind (Name2);
2361 function Prefix_Node (N : Node_Id) return Node_Id;
2362 -- Returns the parent unit name node of a defining program unit name
2363 -- or the prefix if N is a selected component or an expanded name.
2365 function Select_Node (N : Node_Id) return Node_Id;
2366 -- Returns the defining identifier node of a defining program unit
2367 -- name or the selector node if N is a selected component or an
2374 function Prefix_Node (N : Node_Id) return Node_Id is
2376 if Nkind (N) = N_Defining_Program_Unit_Name then
2388 function Select_Node (N : Node_Id) return Node_Id is
2390 if Nkind (N) = N_Defining_Program_Unit_Name then
2391 return Defining_Identifier (N);
2394 return Selector_Name (N);
2398 -- Start of processing for Designate_Next_Unit
2401 if (K1 = N_Identifier or else
2402 K1 = N_Defining_Identifier)
2404 (K2 = N_Identifier or else
2405 K2 = N_Defining_Identifier)
2407 return Chars (Name1) = Chars (Name2);
2410 (K1 = N_Expanded_Name or else
2411 K1 = N_Selected_Component or else
2412 K1 = N_Defining_Program_Unit_Name)
2414 (K2 = N_Expanded_Name or else
2415 K2 = N_Selected_Component or else
2416 K2 = N_Defining_Program_Unit_Name)
2419 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2421 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2426 end Designate_Same_Unit;
2428 ----------------------------
2429 -- Enclosing_Generic_Body --
2430 ----------------------------
2432 function Enclosing_Generic_Body
2433 (N : Node_Id) return Node_Id
2441 while Present (P) loop
2442 if Nkind (P) = N_Package_Body
2443 or else Nkind (P) = N_Subprogram_Body
2445 Spec := Corresponding_Spec (P);
2447 if Present (Spec) then
2448 Decl := Unit_Declaration_Node (Spec);
2450 if Nkind (Decl) = N_Generic_Package_Declaration
2451 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2462 end Enclosing_Generic_Body;
2464 ----------------------------
2465 -- Enclosing_Generic_Unit --
2466 ----------------------------
2468 function Enclosing_Generic_Unit
2469 (N : Node_Id) return Node_Id
2477 while Present (P) loop
2478 if Nkind (P) = N_Generic_Package_Declaration
2479 or else Nkind (P) = N_Generic_Subprogram_Declaration
2483 elsif Nkind (P) = N_Package_Body
2484 or else Nkind (P) = N_Subprogram_Body
2486 Spec := Corresponding_Spec (P);
2488 if Present (Spec) then
2489 Decl := Unit_Declaration_Node (Spec);
2491 if Nkind (Decl) = N_Generic_Package_Declaration
2492 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2503 end Enclosing_Generic_Unit;
2505 -------------------------------
2506 -- Enclosing_Lib_Unit_Entity --
2507 -------------------------------
2509 function Enclosing_Lib_Unit_Entity return Entity_Id is
2510 Unit_Entity : Entity_Id;
2513 -- Look for enclosing library unit entity by following scope links.
2514 -- Equivalent to, but faster than indexing through the scope stack.
2516 Unit_Entity := Current_Scope;
2517 while (Present (Scope (Unit_Entity))
2518 and then Scope (Unit_Entity) /= Standard_Standard)
2519 and not Is_Child_Unit (Unit_Entity)
2521 Unit_Entity := Scope (Unit_Entity);
2525 end Enclosing_Lib_Unit_Entity;
2527 -----------------------------
2528 -- Enclosing_Lib_Unit_Node --
2529 -----------------------------
2531 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2532 Current_Node : Node_Id;
2536 while Present (Current_Node)
2537 and then Nkind (Current_Node) /= N_Compilation_Unit
2539 Current_Node := Parent (Current_Node);
2542 if Nkind (Current_Node) /= N_Compilation_Unit then
2546 return Current_Node;
2547 end Enclosing_Lib_Unit_Node;
2549 --------------------------
2550 -- Enclosing_Subprogram --
2551 --------------------------
2553 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2554 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2557 if Dynamic_Scope = Standard_Standard then
2560 elsif Dynamic_Scope = Empty then
2563 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2564 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2566 elsif Ekind (Dynamic_Scope) = E_Block
2567 or else Ekind (Dynamic_Scope) = E_Return_Statement
2569 return Enclosing_Subprogram (Dynamic_Scope);
2571 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2572 return Get_Task_Body_Procedure (Dynamic_Scope);
2574 -- No body is generated if the protected operation is eliminated
2576 elsif Convention (Dynamic_Scope) = Convention_Protected
2577 and then not Is_Eliminated (Dynamic_Scope)
2578 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2580 return Protected_Body_Subprogram (Dynamic_Scope);
2583 return Dynamic_Scope;
2585 end Enclosing_Subprogram;
2587 ------------------------
2588 -- Ensure_Freeze_Node --
2589 ------------------------
2591 procedure Ensure_Freeze_Node (E : Entity_Id) is
2595 if No (Freeze_Node (E)) then
2596 FN := Make_Freeze_Entity (Sloc (E));
2597 Set_Has_Delayed_Freeze (E);
2598 Set_Freeze_Node (E, FN);
2599 Set_Access_Types_To_Process (FN, No_Elist);
2600 Set_TSS_Elist (FN, No_Elist);
2603 end Ensure_Freeze_Node;
2609 procedure Enter_Name (Def_Id : Entity_Id) is
2610 C : constant Entity_Id := Current_Entity (Def_Id);
2611 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2612 S : constant Entity_Id := Current_Scope;
2615 Generate_Definition (Def_Id);
2617 -- Add new name to current scope declarations. Check for duplicate
2618 -- declaration, which may or may not be a genuine error.
2622 -- Case of previous entity entered because of a missing declaration
2623 -- or else a bad subtype indication. Best is to use the new entity,
2624 -- and make the previous one invisible.
2626 if Etype (E) = Any_Type then
2627 Set_Is_Immediately_Visible (E, False);
2629 -- Case of renaming declaration constructed for package instances.
2630 -- if there is an explicit declaration with the same identifier,
2631 -- the renaming is not immediately visible any longer, but remains
2632 -- visible through selected component notation.
2634 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2635 and then not Comes_From_Source (E)
2637 Set_Is_Immediately_Visible (E, False);
2639 -- The new entity may be the package renaming, which has the same
2640 -- same name as a generic formal which has been seen already.
2642 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2643 and then not Comes_From_Source (Def_Id)
2645 Set_Is_Immediately_Visible (E, False);
2647 -- For a fat pointer corresponding to a remote access to subprogram,
2648 -- we use the same identifier as the RAS type, so that the proper
2649 -- name appears in the stub. This type is only retrieved through
2650 -- the RAS type and never by visibility, and is not added to the
2651 -- visibility list (see below).
2653 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2654 and then Present (Corresponding_Remote_Type (Def_Id))
2658 -- A controller component for a type extension overrides the
2659 -- inherited component.
2661 elsif Chars (E) = Name_uController then
2664 -- Case of an implicit operation or derived literal. The new entity
2665 -- hides the implicit one, which is removed from all visibility,
2666 -- i.e. the entity list of its scope, and homonym chain of its name.
2668 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2669 or else Is_Internal (E)
2673 Prev_Vis : Entity_Id;
2674 Decl : constant Node_Id := Parent (E);
2677 -- If E is an implicit declaration, it cannot be the first
2678 -- entity in the scope.
2680 Prev := First_Entity (Current_Scope);
2681 while Present (Prev)
2682 and then Next_Entity (Prev) /= E
2689 -- If E is not on the entity chain of the current scope,
2690 -- it is an implicit declaration in the generic formal
2691 -- part of a generic subprogram. When analyzing the body,
2692 -- the generic formals are visible but not on the entity
2693 -- chain of the subprogram. The new entity will become
2694 -- the visible one in the body.
2697 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2701 Set_Next_Entity (Prev, Next_Entity (E));
2703 if No (Next_Entity (Prev)) then
2704 Set_Last_Entity (Current_Scope, Prev);
2707 if E = Current_Entity (E) then
2711 Prev_Vis := Current_Entity (E);
2712 while Homonym (Prev_Vis) /= E loop
2713 Prev_Vis := Homonym (Prev_Vis);
2717 if Present (Prev_Vis) then
2719 -- Skip E in the visibility chain
2721 Set_Homonym (Prev_Vis, Homonym (E));
2724 Set_Name_Entity_Id (Chars (E), Homonym (E));
2729 -- This section of code could use a comment ???
2731 elsif Present (Etype (E))
2732 and then Is_Concurrent_Type (Etype (E))
2737 -- If the homograph is a protected component renaming, it should not
2738 -- be hiding the current entity. Such renamings are treated as weak
2741 elsif Is_Prival (E) then
2742 Set_Is_Immediately_Visible (E, False);
2744 -- In this case the current entity is a protected component renaming.
2745 -- Perform minimal decoration by setting the scope and return since
2746 -- the prival should not be hiding other visible entities.
2748 elsif Is_Prival (Def_Id) then
2749 Set_Scope (Def_Id, Current_Scope);
2752 -- Analogous to privals, the discriminal generated for an entry
2753 -- index parameter acts as a weak declaration. Perform minimal
2754 -- decoration to avoid bogus errors.
2756 elsif Is_Discriminal (Def_Id)
2757 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2759 Set_Scope (Def_Id, Current_Scope);
2762 -- In the body or private part of an instance, a type extension
2763 -- may introduce a component with the same name as that of an
2764 -- actual. The legality rule is not enforced, but the semantics
2765 -- of the full type with two components of the same name are not
2766 -- clear at this point ???
2768 elsif In_Instance_Not_Visible then
2771 -- When compiling a package body, some child units may have become
2772 -- visible. They cannot conflict with local entities that hide them.
2774 elsif Is_Child_Unit (E)
2775 and then In_Open_Scopes (Scope (E))
2776 and then not Is_Immediately_Visible (E)
2780 -- Conversely, with front-end inlining we may compile the parent
2781 -- body first, and a child unit subsequently. The context is now
2782 -- the parent spec, and body entities are not visible.
2784 elsif Is_Child_Unit (Def_Id)
2785 and then Is_Package_Body_Entity (E)
2786 and then not In_Package_Body (Current_Scope)
2790 -- Case of genuine duplicate declaration
2793 Error_Msg_Sloc := Sloc (E);
2795 -- If the previous declaration is an incomplete type declaration
2796 -- this may be an attempt to complete it with a private type.
2797 -- The following avoids confusing cascaded errors.
2799 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2800 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2803 ("incomplete type cannot be completed with a private " &
2804 "declaration", Parent (Def_Id));
2805 Set_Is_Immediately_Visible (E, False);
2806 Set_Full_View (E, Def_Id);
2808 -- An inherited component of a record conflicts with a new
2809 -- discriminant. The discriminant is inserted first in the scope,
2810 -- but the error should be posted on it, not on the component.
2812 elsif Ekind (E) = E_Discriminant
2813 and then Present (Scope (Def_Id))
2814 and then Scope (Def_Id) /= Current_Scope
2816 Error_Msg_Sloc := Sloc (Def_Id);
2817 Error_Msg_N ("& conflicts with declaration#", E);
2820 -- If the name of the unit appears in its own context clause,
2821 -- a dummy package with the name has already been created, and
2822 -- the error emitted. Try to continue quietly.
2824 elsif Error_Posted (E)
2825 and then Sloc (E) = No_Location
2826 and then Nkind (Parent (E)) = N_Package_Specification
2827 and then Current_Scope = Standard_Standard
2829 Set_Scope (Def_Id, Current_Scope);
2833 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2835 -- Avoid cascaded messages with duplicate components in
2838 if Ekind_In (E, E_Component, E_Discriminant) then
2843 if Nkind (Parent (Parent (Def_Id))) =
2844 N_Generic_Subprogram_Declaration
2846 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2848 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2851 -- If entity is in standard, then we are in trouble, because
2852 -- it means that we have a library package with a duplicated
2853 -- name. That's hard to recover from, so abort!
2855 if S = Standard_Standard then
2856 raise Unrecoverable_Error;
2858 -- Otherwise we continue with the declaration. Having two
2859 -- identical declarations should not cause us too much trouble!
2867 -- If we fall through, declaration is OK , or OK enough to continue
2869 -- If Def_Id is a discriminant or a record component we are in the
2870 -- midst of inheriting components in a derived record definition.
2871 -- Preserve their Ekind and Etype.
2873 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
2876 -- If a type is already set, leave it alone (happens whey a type
2877 -- declaration is reanalyzed following a call to the optimizer)
2879 elsif Present (Etype (Def_Id)) then
2882 -- Otherwise, the kind E_Void insures that premature uses of the entity
2883 -- will be detected. Any_Type insures that no cascaded errors will occur
2886 Set_Ekind (Def_Id, E_Void);
2887 Set_Etype (Def_Id, Any_Type);
2890 -- Inherited discriminants and components in derived record types are
2891 -- immediately visible. Itypes are not.
2893 if Ekind_In (Def_Id, E_Discriminant, E_Component)
2894 or else (No (Corresponding_Remote_Type (Def_Id))
2895 and then not Is_Itype (Def_Id))
2897 Set_Is_Immediately_Visible (Def_Id);
2898 Set_Current_Entity (Def_Id);
2901 Set_Homonym (Def_Id, C);
2902 Append_Entity (Def_Id, S);
2903 Set_Public_Status (Def_Id);
2905 -- Warn if new entity hides an old one
2907 if Warn_On_Hiding and then Present (C)
2909 -- Don't warn for record components since they always have a well
2910 -- defined scope which does not confuse other uses. Note that in
2911 -- some cases, Ekind has not been set yet.
2913 and then Ekind (C) /= E_Component
2914 and then Ekind (C) /= E_Discriminant
2915 and then Nkind (Parent (C)) /= N_Component_Declaration
2916 and then Ekind (Def_Id) /= E_Component
2917 and then Ekind (Def_Id) /= E_Discriminant
2918 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2920 -- Don't warn for one character variables. It is too common to use
2921 -- such variables as locals and will just cause too many false hits.
2923 and then Length_Of_Name (Chars (C)) /= 1
2925 -- Don't warn for non-source entities
2927 and then Comes_From_Source (C)
2928 and then Comes_From_Source (Def_Id)
2930 -- Don't warn unless entity in question is in extended main source
2932 and then In_Extended_Main_Source_Unit (Def_Id)
2934 -- Finally, the hidden entity must be either immediately visible
2935 -- or use visible (from a used package)
2938 (Is_Immediately_Visible (C)
2940 Is_Potentially_Use_Visible (C))
2942 Error_Msg_Sloc := Sloc (C);
2943 Error_Msg_N ("declaration hides &#?", Def_Id);
2947 --------------------------
2948 -- Explain_Limited_Type --
2949 --------------------------
2951 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2955 -- For array, component type must be limited
2957 if Is_Array_Type (T) then
2958 Error_Msg_Node_2 := T;
2960 ("\component type& of type& is limited", N, Component_Type (T));
2961 Explain_Limited_Type (Component_Type (T), N);
2963 elsif Is_Record_Type (T) then
2965 -- No need for extra messages if explicit limited record
2967 if Is_Limited_Record (Base_Type (T)) then
2971 -- Otherwise find a limited component. Check only components that
2972 -- come from source, or inherited components that appear in the
2973 -- source of the ancestor.
2975 C := First_Component (T);
2976 while Present (C) loop
2977 if Is_Limited_Type (Etype (C))
2979 (Comes_From_Source (C)
2981 (Present (Original_Record_Component (C))
2983 Comes_From_Source (Original_Record_Component (C))))
2985 Error_Msg_Node_2 := T;
2986 Error_Msg_NE ("\component& of type& has limited type", N, C);
2987 Explain_Limited_Type (Etype (C), N);
2994 -- The type may be declared explicitly limited, even if no component
2995 -- of it is limited, in which case we fall out of the loop.
2998 end Explain_Limited_Type;
3004 procedure Find_Actual
3006 Formal : out Entity_Id;
3009 Parnt : constant Node_Id := Parent (N);
3013 if (Nkind (Parnt) = N_Indexed_Component
3015 Nkind (Parnt) = N_Selected_Component)
3016 and then N = Prefix (Parnt)
3018 Find_Actual (Parnt, Formal, Call);
3021 elsif Nkind (Parnt) = N_Parameter_Association
3022 and then N = Explicit_Actual_Parameter (Parnt)
3024 Call := Parent (Parnt);
3026 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3035 -- If we have a call to a subprogram look for the parameter. Note that
3036 -- we exclude overloaded calls, since we don't know enough to be sure
3037 -- of giving the right answer in this case.
3039 if Is_Entity_Name (Name (Call))
3040 and then Present (Entity (Name (Call)))
3041 and then Is_Overloadable (Entity (Name (Call)))
3042 and then not Is_Overloaded (Name (Call))
3044 -- Fall here if we are definitely a parameter
3046 Actual := First_Actual (Call);
3047 Formal := First_Formal (Entity (Name (Call)));
3048 while Present (Formal) and then Present (Actual) loop
3052 Actual := Next_Actual (Actual);
3053 Formal := Next_Formal (Formal);
3058 -- Fall through here if we did not find matching actual
3064 ---------------------------
3065 -- Find_Body_Discriminal --
3066 ---------------------------
3068 function Find_Body_Discriminal
3069 (Spec_Discriminant : Entity_Id) return Entity_Id
3071 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3073 Tsk : constant Entity_Id :=
3074 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3078 -- Find discriminant of original concurrent type, and use its current
3079 -- discriminal, which is the renaming within the task/protected body.
3081 Disc := First_Discriminant (Tsk);
3082 while Present (Disc) loop
3083 if Chars (Disc) = Chars (Spec_Discriminant) then
3084 return Discriminal (Disc);
3087 Next_Discriminant (Disc);
3090 -- That loop should always succeed in finding a matching entry and
3091 -- returning. Fatal error if not.
3093 raise Program_Error;
3094 end Find_Body_Discriminal;
3096 -------------------------------------
3097 -- Find_Corresponding_Discriminant --
3098 -------------------------------------
3100 function Find_Corresponding_Discriminant
3102 Typ : Entity_Id) return Entity_Id
3104 Par_Disc : Entity_Id;
3105 Old_Disc : Entity_Id;
3106 New_Disc : Entity_Id;
3109 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3111 -- The original type may currently be private, and the discriminant
3112 -- only appear on its full view.
3114 if Is_Private_Type (Scope (Par_Disc))
3115 and then not Has_Discriminants (Scope (Par_Disc))
3116 and then Present (Full_View (Scope (Par_Disc)))
3118 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3120 Old_Disc := First_Discriminant (Scope (Par_Disc));
3123 if Is_Class_Wide_Type (Typ) then
3124 New_Disc := First_Discriminant (Root_Type (Typ));
3126 New_Disc := First_Discriminant (Typ);
3129 while Present (Old_Disc) and then Present (New_Disc) loop
3130 if Old_Disc = Par_Disc then
3133 Next_Discriminant (Old_Disc);
3134 Next_Discriminant (New_Disc);
3138 -- Should always find it
3140 raise Program_Error;
3141 end Find_Corresponding_Discriminant;
3143 --------------------------
3144 -- Find_Overlaid_Entity --
3145 --------------------------
3147 procedure Find_Overlaid_Entity
3149 Ent : out Entity_Id;
3155 -- We are looking for one of the two following forms:
3157 -- for X'Address use Y'Address
3161 -- Const : constant Address := expr;
3163 -- for X'Address use Const;
3165 -- In the second case, the expr is either Y'Address, or recursively a
3166 -- constant that eventually references Y'Address.
3171 if Nkind (N) = N_Attribute_Definition_Clause
3172 and then Chars (N) = Name_Address
3174 Expr := Expression (N);
3176 -- This loop checks the form of the expression for Y'Address,
3177 -- using recursion to deal with intermediate constants.
3180 -- Check for Y'Address
3182 if Nkind (Expr) = N_Attribute_Reference
3183 and then Attribute_Name (Expr) = Name_Address
3185 Expr := Prefix (Expr);
3188 -- Check for Const where Const is a constant entity
3190 elsif Is_Entity_Name (Expr)
3191 and then Ekind (Entity (Expr)) = E_Constant
3193 Expr := Constant_Value (Entity (Expr));
3195 -- Anything else does not need checking
3202 -- This loop checks the form of the prefix for an entity,
3203 -- using recursion to deal with intermediate components.
3206 -- Check for Y where Y is an entity
3208 if Is_Entity_Name (Expr) then
3209 Ent := Entity (Expr);
3212 -- Check for components
3215 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3217 Expr := Prefix (Expr);
3220 -- Anything else does not need checking
3227 end Find_Overlaid_Entity;
3229 -------------------------
3230 -- Find_Parameter_Type --
3231 -------------------------
3233 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3235 if Nkind (Param) /= N_Parameter_Specification then
3238 -- For an access parameter, obtain the type from the formal entity
3239 -- itself, because access to subprogram nodes do not carry a type.
3240 -- Shouldn't we always use the formal entity ???
3242 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3243 return Etype (Defining_Identifier (Param));
3246 return Etype (Parameter_Type (Param));
3248 end Find_Parameter_Type;
3250 -----------------------------
3251 -- Find_Static_Alternative --
3252 -----------------------------
3254 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3255 Expr : constant Node_Id := Expression (N);
3256 Val : constant Uint := Expr_Value (Expr);
3261 Alt := First (Alternatives (N));
3264 if Nkind (Alt) /= N_Pragma then
3265 Choice := First (Discrete_Choices (Alt));
3266 while Present (Choice) loop
3268 -- Others choice, always matches
3270 if Nkind (Choice) = N_Others_Choice then
3273 -- Range, check if value is in the range
3275 elsif Nkind (Choice) = N_Range then
3277 Val >= Expr_Value (Low_Bound (Choice))
3279 Val <= Expr_Value (High_Bound (Choice));
3281 -- Choice is a subtype name. Note that we know it must
3282 -- be a static subtype, since otherwise it would have
3283 -- been diagnosed as illegal.
3285 elsif Is_Entity_Name (Choice)
3286 and then Is_Type (Entity (Choice))
3288 exit Search when Is_In_Range (Expr, Etype (Choice),
3289 Assume_Valid => False);
3291 -- Choice is a subtype indication
3293 elsif Nkind (Choice) = N_Subtype_Indication then
3295 C : constant Node_Id := Constraint (Choice);
3296 R : constant Node_Id := Range_Expression (C);
3300 Val >= Expr_Value (Low_Bound (R))
3302 Val <= Expr_Value (High_Bound (R));
3305 -- Choice is a simple expression
3308 exit Search when Val = Expr_Value (Choice);
3316 pragma Assert (Present (Alt));
3319 -- The above loop *must* terminate by finding a match, since
3320 -- we know the case statement is valid, and the value of the
3321 -- expression is known at compile time. When we fall out of
3322 -- the loop, Alt points to the alternative that we know will
3323 -- be selected at run time.
3326 end Find_Static_Alternative;
3332 function First_Actual (Node : Node_Id) return Node_Id is
3336 if No (Parameter_Associations (Node)) then
3340 N := First (Parameter_Associations (Node));
3342 if Nkind (N) = N_Parameter_Association then
3343 return First_Named_Actual (Node);
3349 -------------------------
3350 -- Full_Qualified_Name --
3351 -------------------------
3353 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3355 pragma Warnings (Off, Res);
3357 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3358 -- Compute recursively the qualified name without NUL at the end
3360 ----------------------------------
3361 -- Internal_Full_Qualified_Name --
3362 ----------------------------------
3364 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3365 Ent : Entity_Id := E;
3366 Parent_Name : String_Id := No_String;
3369 -- Deals properly with child units
3371 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3372 Ent := Defining_Identifier (Ent);
3375 -- Compute qualification recursively (only "Standard" has no scope)
3377 if Present (Scope (Scope (Ent))) then
3378 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3381 -- Every entity should have a name except some expanded blocks
3382 -- don't bother about those.
3384 if Chars (Ent) = No_Name then
3388 -- Add a period between Name and qualification
3390 if Parent_Name /= No_String then
3391 Start_String (Parent_Name);
3392 Store_String_Char (Get_Char_Code ('.'));
3398 -- Generates the entity name in upper case
3400 Get_Decoded_Name_String (Chars (Ent));
3402 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3404 end Internal_Full_Qualified_Name;
3406 -- Start of processing for Full_Qualified_Name
3409 Res := Internal_Full_Qualified_Name (E);
3410 Store_String_Char (Get_Char_Code (ASCII.NUL));
3412 end Full_Qualified_Name;
3414 -----------------------
3415 -- Gather_Components --
3416 -----------------------
3418 procedure Gather_Components
3420 Comp_List : Node_Id;
3421 Governed_By : List_Id;
3423 Report_Errors : out Boolean)
3427 Discrete_Choice : Node_Id;
3428 Comp_Item : Node_Id;
3430 Discrim : Entity_Id;
3431 Discrim_Name : Node_Id;
3432 Discrim_Value : Node_Id;
3435 Report_Errors := False;
3437 if No (Comp_List) or else Null_Present (Comp_List) then
3440 elsif Present (Component_Items (Comp_List)) then
3441 Comp_Item := First (Component_Items (Comp_List));
3447 while Present (Comp_Item) loop
3449 -- Skip the tag of a tagged record, the interface tags, as well
3450 -- as all items that are not user components (anonymous types,
3451 -- rep clauses, Parent field, controller field).
3453 if Nkind (Comp_Item) = N_Component_Declaration then
3455 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3457 if not Is_Tag (Comp)
3458 and then Chars (Comp) /= Name_uParent
3459 and then Chars (Comp) /= Name_uController
3461 Append_Elmt (Comp, Into);
3469 if No (Variant_Part (Comp_List)) then
3472 Discrim_Name := Name (Variant_Part (Comp_List));
3473 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3476 -- Look for the discriminant that governs this variant part.
3477 -- The discriminant *must* be in the Governed_By List
3479 Assoc := First (Governed_By);
3480 Find_Constraint : loop
3481 Discrim := First (Choices (Assoc));
3482 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3483 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3485 Chars (Corresponding_Discriminant (Entity (Discrim)))
3486 = Chars (Discrim_Name))
3487 or else Chars (Original_Record_Component (Entity (Discrim)))
3488 = Chars (Discrim_Name);
3490 if No (Next (Assoc)) then
3491 if not Is_Constrained (Typ)
3492 and then Is_Derived_Type (Typ)
3493 and then Present (Stored_Constraint (Typ))
3495 -- If the type is a tagged type with inherited discriminants,
3496 -- use the stored constraint on the parent in order to find
3497 -- the values of discriminants that are otherwise hidden by an
3498 -- explicit constraint. Renamed discriminants are handled in
3501 -- If several parent discriminants are renamed by a single
3502 -- discriminant of the derived type, the call to obtain the
3503 -- Corresponding_Discriminant field only retrieves the last
3504 -- of them. We recover the constraint on the others from the
3505 -- Stored_Constraint as well.
3512 D := First_Discriminant (Etype (Typ));
3513 C := First_Elmt (Stored_Constraint (Typ));
3514 while Present (D) and then Present (C) loop
3515 if Chars (Discrim_Name) = Chars (D) then
3516 if Is_Entity_Name (Node (C))
3517 and then Entity (Node (C)) = Entity (Discrim)
3519 -- D is renamed by Discrim, whose value is given in
3526 Make_Component_Association (Sloc (Typ),
3528 (New_Occurrence_Of (D, Sloc (Typ))),
3529 Duplicate_Subexpr_No_Checks (Node (C)));
3531 exit Find_Constraint;
3534 Next_Discriminant (D);
3541 if No (Next (Assoc)) then
3542 Error_Msg_NE (" missing value for discriminant&",
3543 First (Governed_By), Discrim_Name);
3544 Report_Errors := True;
3549 end loop Find_Constraint;
3551 Discrim_Value := Expression (Assoc);
3553 if not Is_OK_Static_Expression (Discrim_Value) then
3555 ("value for discriminant & must be static!",
3556 Discrim_Value, Discrim);
3557 Why_Not_Static (Discrim_Value);
3558 Report_Errors := True;
3562 Search_For_Discriminant_Value : declare
3568 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3571 Find_Discrete_Value : while Present (Variant) loop
3572 Discrete_Choice := First (Discrete_Choices (Variant));
3573 while Present (Discrete_Choice) loop
3575 exit Find_Discrete_Value when
3576 Nkind (Discrete_Choice) = N_Others_Choice;
3578 Get_Index_Bounds (Discrete_Choice, Low, High);
3580 UI_Low := Expr_Value (Low);
3581 UI_High := Expr_Value (High);
3583 exit Find_Discrete_Value when
3584 UI_Low <= UI_Discrim_Value
3586 UI_High >= UI_Discrim_Value;
3588 Next (Discrete_Choice);
3591 Next_Non_Pragma (Variant);
3592 end loop Find_Discrete_Value;
3593 end Search_For_Discriminant_Value;
3595 if No (Variant) then
3597 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3598 Report_Errors := True;
3602 -- If we have found the corresponding choice, recursively add its
3603 -- components to the Into list.
3605 Gather_Components (Empty,
3606 Component_List (Variant), Governed_By, Into, Report_Errors);
3607 end Gather_Components;
3609 ------------------------
3610 -- Get_Actual_Subtype --
3611 ------------------------
3613 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3614 Typ : constant Entity_Id := Etype (N);
3615 Utyp : Entity_Id := Underlying_Type (Typ);
3624 -- If what we have is an identifier that references a subprogram
3625 -- formal, or a variable or constant object, then we get the actual
3626 -- subtype from the referenced entity if one has been built.
3628 if Nkind (N) = N_Identifier
3630 (Is_Formal (Entity (N))
3631 or else Ekind (Entity (N)) = E_Constant
3632 or else Ekind (Entity (N)) = E_Variable)
3633 and then Present (Actual_Subtype (Entity (N)))
3635 return Actual_Subtype (Entity (N));
3637 -- Actual subtype of unchecked union is always itself. We never need
3638 -- the "real" actual subtype. If we did, we couldn't get it anyway
3639 -- because the discriminant is not available. The restrictions on
3640 -- Unchecked_Union are designed to make sure that this is OK.
3642 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3645 -- Here for the unconstrained case, we must find actual subtype
3646 -- No actual subtype is available, so we must build it on the fly.
3648 -- Checking the type, not the underlying type, for constrainedness
3649 -- seems to be necessary. Maybe all the tests should be on the type???
3651 elsif (not Is_Constrained (Typ))
3652 and then (Is_Array_Type (Utyp)
3653 or else (Is_Record_Type (Utyp)
3654 and then Has_Discriminants (Utyp)))
3655 and then not Has_Unknown_Discriminants (Utyp)
3656 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3658 -- Nothing to do if in spec expression (why not???)
3660 if In_Spec_Expression then
3663 elsif Is_Private_Type (Typ)
3664 and then not Has_Discriminants (Typ)
3666 -- If the type has no discriminants, there is no subtype to
3667 -- build, even if the underlying type is discriminated.
3671 -- Else build the actual subtype
3674 Decl := Build_Actual_Subtype (Typ, N);
3675 Atyp := Defining_Identifier (Decl);
3677 -- If Build_Actual_Subtype generated a new declaration then use it
3681 -- The actual subtype is an Itype, so analyze the declaration,
3682 -- but do not attach it to the tree, to get the type defined.
3684 Set_Parent (Decl, N);
3685 Set_Is_Itype (Atyp);
3686 Analyze (Decl, Suppress => All_Checks);
3687 Set_Associated_Node_For_Itype (Atyp, N);
3688 Set_Has_Delayed_Freeze (Atyp, False);
3690 -- We need to freeze the actual subtype immediately. This is
3691 -- needed, because otherwise this Itype will not get frozen
3692 -- at all, and it is always safe to freeze on creation because
3693 -- any associated types must be frozen at this point.
3695 Freeze_Itype (Atyp, N);
3698 -- Otherwise we did not build a declaration, so return original
3705 -- For all remaining cases, the actual subtype is the same as
3706 -- the nominal type.
3711 end Get_Actual_Subtype;
3713 -------------------------------------
3714 -- Get_Actual_Subtype_If_Available --
3715 -------------------------------------
3717 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3718 Typ : constant Entity_Id := Etype (N);
3721 -- If what we have is an identifier that references a subprogram
3722 -- formal, or a variable or constant object, then we get the actual
3723 -- subtype from the referenced entity if one has been built.
3725 if Nkind (N) = N_Identifier
3727 (Is_Formal (Entity (N))
3728 or else Ekind (Entity (N)) = E_Constant
3729 or else Ekind (Entity (N)) = E_Variable)
3730 and then Present (Actual_Subtype (Entity (N)))
3732 return Actual_Subtype (Entity (N));
3734 -- Otherwise the Etype of N is returned unchanged
3739 end Get_Actual_Subtype_If_Available;
3741 -------------------------------
3742 -- Get_Default_External_Name --
3743 -------------------------------
3745 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3747 Get_Decoded_Name_String (Chars (E));
3749 if Opt.External_Name_Imp_Casing = Uppercase then
3750 Set_Casing (All_Upper_Case);
3752 Set_Casing (All_Lower_Case);
3756 Make_String_Literal (Sloc (E),
3757 Strval => String_From_Name_Buffer);
3758 end Get_Default_External_Name;
3760 ---------------------------
3761 -- Get_Enum_Lit_From_Pos --
3762 ---------------------------
3764 function Get_Enum_Lit_From_Pos
3767 Loc : Source_Ptr) return Node_Id
3772 -- In the case where the literal is of type Character, Wide_Character
3773 -- or Wide_Wide_Character or of a type derived from them, there needs
3774 -- to be some special handling since there is no explicit chain of
3775 -- literals to search. Instead, an N_Character_Literal node is created
3776 -- with the appropriate Char_Code and Chars fields.
3778 if Is_Standard_Character_Type (T) then
3779 Set_Character_Literal_Name (UI_To_CC (Pos));
3781 Make_Character_Literal (Loc,
3783 Char_Literal_Value => Pos);
3785 -- For all other cases, we have a complete table of literals, and
3786 -- we simply iterate through the chain of literal until the one
3787 -- with the desired position value is found.
3791 Lit := First_Literal (Base_Type (T));
3792 for J in 1 .. UI_To_Int (Pos) loop
3796 return New_Occurrence_Of (Lit, Loc);
3798 end Get_Enum_Lit_From_Pos;
3800 ------------------------
3801 -- Get_Generic_Entity --
3802 ------------------------
3804 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3805 Ent : constant Entity_Id := Entity (Name (N));
3807 if Present (Renamed_Object (Ent)) then
3808 return Renamed_Object (Ent);
3812 end Get_Generic_Entity;
3814 ----------------------
3815 -- Get_Index_Bounds --
3816 ----------------------
3818 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3819 Kind : constant Node_Kind := Nkind (N);
3823 if Kind = N_Range then
3825 H := High_Bound (N);
3827 elsif Kind = N_Subtype_Indication then
3828 R := Range_Expression (Constraint (N));
3836 L := Low_Bound (Range_Expression (Constraint (N)));
3837 H := High_Bound (Range_Expression (Constraint (N)));
3840 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3841 if Error_Posted (Scalar_Range (Entity (N))) then
3845 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3846 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3849 L := Low_Bound (Scalar_Range (Entity (N)));
3850 H := High_Bound (Scalar_Range (Entity (N)));
3854 -- N is an expression, indicating a range with one value
3859 end Get_Index_Bounds;
3861 ----------------------------------
3862 -- Get_Library_Unit_Name_string --
3863 ----------------------------------
3865 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3866 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3869 Get_Unit_Name_String (Unit_Name_Id);
3871 -- Remove seven last character (" (spec)" or " (body)")
3873 Name_Len := Name_Len - 7;
3874 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3875 end Get_Library_Unit_Name_String;
3877 ------------------------
3878 -- Get_Name_Entity_Id --
3879 ------------------------
3881 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3883 return Entity_Id (Get_Name_Table_Info (Id));
3884 end Get_Name_Entity_Id;
3890 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3892 return Get_Pragma_Id (Pragma_Name (N));
3895 ---------------------------
3896 -- Get_Referenced_Object --
3897 ---------------------------
3899 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3904 while Is_Entity_Name (R)
3905 and then Present (Renamed_Object (Entity (R)))
3907 R := Renamed_Object (Entity (R));
3911 end Get_Referenced_Object;
3913 ------------------------
3914 -- Get_Renamed_Entity --
3915 ------------------------
3917 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3922 while Present (Renamed_Entity (R)) loop
3923 R := Renamed_Entity (R);
3927 end Get_Renamed_Entity;
3929 -------------------------
3930 -- Get_Subprogram_Body --
3931 -------------------------
3933 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3937 Decl := Unit_Declaration_Node (E);
3939 if Nkind (Decl) = N_Subprogram_Body then
3942 -- The below comment is bad, because it is possible for
3943 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3945 else -- Nkind (Decl) = N_Subprogram_Declaration
3947 if Present (Corresponding_Body (Decl)) then
3948 return Unit_Declaration_Node (Corresponding_Body (Decl));
3950 -- Imported subprogram case
3956 end Get_Subprogram_Body;
3958 ---------------------------
3959 -- Get_Subprogram_Entity --
3960 ---------------------------
3962 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3967 if Nkind (Nod) = N_Accept_Statement then
3968 Nam := Entry_Direct_Name (Nod);
3970 -- For an entry call, the prefix of the call is a selected component.
3971 -- Need additional code for internal calls ???
3973 elsif Nkind (Nod) = N_Entry_Call_Statement then
3974 if Nkind (Name (Nod)) = N_Selected_Component then
3975 Nam := Entity (Selector_Name (Name (Nod)));
3984 if Nkind (Nam) = N_Explicit_Dereference then
3985 Proc := Etype (Prefix (Nam));
3986 elsif Is_Entity_Name (Nam) then
3987 Proc := Entity (Nam);
3992 if Is_Object (Proc) then
3993 Proc := Etype (Proc);
3996 if Ekind (Proc) = E_Access_Subprogram_Type then
3997 Proc := Directly_Designated_Type (Proc);
4000 if not Is_Subprogram (Proc)
4001 and then Ekind (Proc) /= E_Subprogram_Type
4007 end Get_Subprogram_Entity;
4009 -----------------------------
4010 -- Get_Task_Body_Procedure --
4011 -----------------------------
4013 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4015 -- Note: A task type may be the completion of a private type with
4016 -- discriminants. When performing elaboration checks on a task
4017 -- declaration, the current view of the type may be the private one,
4018 -- and the procedure that holds the body of the task is held in its
4021 -- This is an odd function, why not have Task_Body_Procedure do
4022 -- the following digging???
4024 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4025 end Get_Task_Body_Procedure;
4027 -----------------------
4028 -- Has_Access_Values --
4029 -----------------------
4031 function Has_Access_Values (T : Entity_Id) return Boolean is
4032 Typ : constant Entity_Id := Underlying_Type (T);
4035 -- Case of a private type which is not completed yet. This can only
4036 -- happen in the case of a generic format type appearing directly, or
4037 -- as a component of the type to which this function is being applied
4038 -- at the top level. Return False in this case, since we certainly do
4039 -- not know that the type contains access types.
4044 elsif Is_Access_Type (Typ) then
4047 elsif Is_Array_Type (Typ) then
4048 return Has_Access_Values (Component_Type (Typ));
4050 elsif Is_Record_Type (Typ) then
4055 -- Loop to Check components
4057 Comp := First_Component_Or_Discriminant (Typ);
4058 while Present (Comp) loop
4060 -- Check for access component, tag field does not count, even
4061 -- though it is implemented internally using an access type.
4063 if Has_Access_Values (Etype (Comp))
4064 and then Chars (Comp) /= Name_uTag
4069 Next_Component_Or_Discriminant (Comp);
4078 end Has_Access_Values;
4080 ------------------------------
4081 -- Has_Compatible_Alignment --
4082 ------------------------------
4084 function Has_Compatible_Alignment
4086 Expr : Node_Id) return Alignment_Result
4088 function Has_Compatible_Alignment_Internal
4091 Default : Alignment_Result) return Alignment_Result;
4092 -- This is the internal recursive function that actually does the work.
4093 -- There is one additional parameter, which says what the result should
4094 -- be if no alignment information is found, and there is no definite
4095 -- indication of compatible alignments. At the outer level, this is set
4096 -- to Unknown, but for internal recursive calls in the case where types
4097 -- are known to be correct, it is set to Known_Compatible.
4099 ---------------------------------------
4100 -- Has_Compatible_Alignment_Internal --
4101 ---------------------------------------
4103 function Has_Compatible_Alignment_Internal
4106 Default : Alignment_Result) return Alignment_Result
4108 Result : Alignment_Result := Known_Compatible;
4109 -- Holds the current status of the result. Note that once a value of
4110 -- Known_Incompatible is set, it is sticky and does not get changed
4111 -- to Unknown (the value in Result only gets worse as we go along,
4114 Offs : Uint := No_Uint;
4115 -- Set to a factor of the offset from the base object when Expr is a
4116 -- selected or indexed component, based on Component_Bit_Offset and
4117 -- Component_Size respectively. A negative value is used to represent
4118 -- a value which is not known at compile time.
4120 procedure Check_Prefix;
4121 -- Checks the prefix recursively in the case where the expression
4122 -- is an indexed or selected component.
4124 procedure Set_Result (R : Alignment_Result);
4125 -- If R represents a worse outcome (unknown instead of known
4126 -- compatible, or known incompatible), then set Result to R.
4132 procedure Check_Prefix is
4134 -- The subtlety here is that in doing a recursive call to check
4135 -- the prefix, we have to decide what to do in the case where we
4136 -- don't find any specific indication of an alignment problem.
4138 -- At the outer level, we normally set Unknown as the result in
4139 -- this case, since we can only set Known_Compatible if we really
4140 -- know that the alignment value is OK, but for the recursive
4141 -- call, in the case where the types match, and we have not
4142 -- specified a peculiar alignment for the object, we are only
4143 -- concerned about suspicious rep clauses, the default case does
4144 -- not affect us, since the compiler will, in the absence of such
4145 -- rep clauses, ensure that the alignment is correct.
4147 if Default = Known_Compatible
4149 (Etype (Obj) = Etype (Expr)
4150 and then (Unknown_Alignment (Obj)
4152 Alignment (Obj) = Alignment (Etype (Obj))))
4155 (Has_Compatible_Alignment_Internal
4156 (Obj, Prefix (Expr), Known_Compatible));
4158 -- In all other cases, we need a full check on the prefix
4162 (Has_Compatible_Alignment_Internal
4163 (Obj, Prefix (Expr), Unknown));
4171 procedure Set_Result (R : Alignment_Result) is
4178 -- Start of processing for Has_Compatible_Alignment_Internal
4181 -- If Expr is a selected component, we must make sure there is no
4182 -- potentially troublesome component clause, and that the record is
4185 if Nkind (Expr) = N_Selected_Component then
4187 -- Packed record always generate unknown alignment
4189 if Is_Packed (Etype (Prefix (Expr))) then
4190 Set_Result (Unknown);
4193 -- Check prefix and component offset
4196 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4198 -- If Expr is an indexed component, we must make sure there is no
4199 -- potentially troublesome Component_Size clause and that the array
4200 -- is not bit-packed.
4202 elsif Nkind (Expr) = N_Indexed_Component then
4204 Typ : constant Entity_Id := Etype (Prefix (Expr));
4205 Ind : constant Node_Id := First_Index (Typ);
4208 -- Bit packed array always generates unknown alignment
4210 if Is_Bit_Packed_Array (Typ) then
4211 Set_Result (Unknown);
4214 -- Check prefix and component offset
4217 Offs := Component_Size (Typ);
4219 -- Small optimization: compute the full offset when possible
4222 and then Offs > Uint_0
4223 and then Present (Ind)
4224 and then Nkind (Ind) = N_Range
4225 and then Compile_Time_Known_Value (Low_Bound (Ind))
4226 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4228 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4229 - Expr_Value (Low_Bound ((Ind))));
4234 -- If we have a null offset, the result is entirely determined by
4235 -- the base object and has already been computed recursively.
4237 if Offs = Uint_0 then
4240 -- Case where we know the alignment of the object
4242 elsif Known_Alignment (Obj) then
4244 ObjA : constant Uint := Alignment (Obj);
4245 ExpA : Uint := No_Uint;
4246 SizA : Uint := No_Uint;
4249 -- If alignment of Obj is 1, then we are always OK
4252 Set_Result (Known_Compatible);
4254 -- Alignment of Obj is greater than 1, so we need to check
4257 -- If we have an offset, see if it is compatible
4259 if Offs /= No_Uint and Offs > Uint_0 then
4260 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4261 Set_Result (Known_Incompatible);
4264 -- See if Expr is an object with known alignment
4266 elsif Is_Entity_Name (Expr)
4267 and then Known_Alignment (Entity (Expr))
4269 ExpA := Alignment (Entity (Expr));
4271 -- Otherwise, we can use the alignment of the type of
4272 -- Expr given that we already checked for
4273 -- discombobulating rep clauses for the cases of indexed
4274 -- and selected components above.
4276 elsif Known_Alignment (Etype (Expr)) then
4277 ExpA := Alignment (Etype (Expr));
4279 -- Otherwise the alignment is unknown
4282 Set_Result (Default);
4285 -- If we got an alignment, see if it is acceptable
4287 if ExpA /= No_Uint and then ExpA < ObjA then
4288 Set_Result (Known_Incompatible);
4291 -- If Expr is not a piece of a larger object, see if size
4292 -- is given. If so, check that it is not too small for the
4293 -- required alignment.
4295 if Offs /= No_Uint then
4298 -- See if Expr is an object with known size
4300 elsif Is_Entity_Name (Expr)
4301 and then Known_Static_Esize (Entity (Expr))
4303 SizA := Esize (Entity (Expr));
4305 -- Otherwise, we check the object size of the Expr type
4307 elsif Known_Static_Esize (Etype (Expr)) then
4308 SizA := Esize (Etype (Expr));
4311 -- If we got a size, see if it is a multiple of the Obj
4312 -- alignment, if not, then the alignment cannot be
4313 -- acceptable, since the size is always a multiple of the
4316 if SizA /= No_Uint then
4317 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4318 Set_Result (Known_Incompatible);
4324 -- If we do not know required alignment, any non-zero offset is a
4325 -- potential problem (but certainly may be OK, so result is unknown).
4327 elsif Offs /= No_Uint then
4328 Set_Result (Unknown);
4330 -- If we can't find the result by direct comparison of alignment
4331 -- values, then there is still one case that we can determine known
4332 -- result, and that is when we can determine that the types are the
4333 -- same, and no alignments are specified. Then we known that the
4334 -- alignments are compatible, even if we don't know the alignment
4335 -- value in the front end.
4337 elsif Etype (Obj) = Etype (Expr) then
4339 -- Types are the same, but we have to check for possible size
4340 -- and alignments on the Expr object that may make the alignment
4341 -- different, even though the types are the same.
4343 if Is_Entity_Name (Expr) then
4345 -- First check alignment of the Expr object. Any alignment less
4346 -- than Maximum_Alignment is worrisome since this is the case
4347 -- where we do not know the alignment of Obj.
4349 if Known_Alignment (Entity (Expr))
4351 UI_To_Int (Alignment (Entity (Expr))) <
4352 Ttypes.Maximum_Alignment
4354 Set_Result (Unknown);
4356 -- Now check size of Expr object. Any size that is not an
4357 -- even multiple of Maximum_Alignment is also worrisome
4358 -- since it may cause the alignment of the object to be less
4359 -- than the alignment of the type.
4361 elsif Known_Static_Esize (Entity (Expr))
4363 (UI_To_Int (Esize (Entity (Expr))) mod
4364 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4367 Set_Result (Unknown);
4369 -- Otherwise same type is decisive
4372 Set_Result (Known_Compatible);
4376 -- Another case to deal with is when there is an explicit size or
4377 -- alignment clause when the types are not the same. If so, then the
4378 -- result is Unknown. We don't need to do this test if the Default is
4379 -- Unknown, since that result will be set in any case.
4381 elsif Default /= Unknown
4382 and then (Has_Size_Clause (Etype (Expr))
4384 Has_Alignment_Clause (Etype (Expr)))
4386 Set_Result (Unknown);
4388 -- If no indication found, set default
4391 Set_Result (Default);
4394 -- Return worst result found
4397 end Has_Compatible_Alignment_Internal;
4399 -- Start of processing for Has_Compatible_Alignment
4402 -- If Obj has no specified alignment, then set alignment from the type
4403 -- alignment. Perhaps we should always do this, but for sure we should
4404 -- do it when there is an address clause since we can do more if the
4405 -- alignment is known.
4407 if Unknown_Alignment (Obj) then
4408 Set_Alignment (Obj, Alignment (Etype (Obj)));
4411 -- Now do the internal call that does all the work
4413 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4414 end Has_Compatible_Alignment;
4416 ----------------------
4417 -- Has_Declarations --
4418 ----------------------
4420 function Has_Declarations (N : Node_Id) return Boolean is
4422 return Nkind_In (Nkind (N), N_Accept_Statement,
4424 N_Compilation_Unit_Aux,
4430 N_Package_Specification);
4431 end Has_Declarations;
4433 -------------------------------------------
4434 -- Has_Discriminant_Dependent_Constraint --
4435 -------------------------------------------
4437 function Has_Discriminant_Dependent_Constraint
4438 (Comp : Entity_Id) return Boolean
4440 Comp_Decl : constant Node_Id := Parent (Comp);
4441 Subt_Indic : constant Node_Id :=
4442 Subtype_Indication (Component_Definition (Comp_Decl));
4447 if Nkind (Subt_Indic) = N_Subtype_Indication then
4448 Constr := Constraint (Subt_Indic);
4450 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4451 Assn := First (Constraints (Constr));
4452 while Present (Assn) loop
4453 case Nkind (Assn) is
4454 when N_Subtype_Indication |
4458 if Depends_On_Discriminant (Assn) then
4462 when N_Discriminant_Association =>
4463 if Depends_On_Discriminant (Expression (Assn)) then
4478 end Has_Discriminant_Dependent_Constraint;
4480 --------------------
4481 -- Has_Infinities --
4482 --------------------
4484 function Has_Infinities (E : Entity_Id) return Boolean is
4487 Is_Floating_Point_Type (E)
4488 and then Nkind (Scalar_Range (E)) = N_Range
4489 and then Includes_Infinities (Scalar_Range (E));
4492 --------------------
4493 -- Has_Interfaces --
4494 --------------------
4496 function Has_Interfaces
4498 Use_Full_View : Boolean := True) return Boolean
4500 Typ : Entity_Id := Base_Type (T);
4503 -- Handle concurrent types
4505 if Is_Concurrent_Type (Typ) then
4506 Typ := Corresponding_Record_Type (Typ);
4509 if not Present (Typ)
4510 or else not Is_Record_Type (Typ)
4511 or else not Is_Tagged_Type (Typ)
4516 -- Handle private types
4519 and then Present (Full_View (Typ))
4521 Typ := Full_View (Typ);
4524 -- Handle concurrent record types
4526 if Is_Concurrent_Record_Type (Typ)
4527 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4533 if Is_Interface (Typ)
4535 (Is_Record_Type (Typ)
4536 and then Present (Interfaces (Typ))
4537 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4542 exit when Etype (Typ) = Typ
4544 -- Handle private types
4546 or else (Present (Full_View (Etype (Typ)))
4547 and then Full_View (Etype (Typ)) = Typ)
4549 -- Protect the frontend against wrong source with cyclic
4552 or else Etype (Typ) = T;
4554 -- Climb to the ancestor type handling private types
4556 if Present (Full_View (Etype (Typ))) then
4557 Typ := Full_View (Etype (Typ));
4566 ------------------------
4567 -- Has_Null_Exclusion --
4568 ------------------------
4570 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4573 when N_Access_Definition |
4574 N_Access_Function_Definition |
4575 N_Access_Procedure_Definition |
4576 N_Access_To_Object_Definition |
4578 N_Derived_Type_Definition |
4579 N_Function_Specification |
4580 N_Subtype_Declaration =>
4581 return Null_Exclusion_Present (N);
4583 when N_Component_Definition |
4584 N_Formal_Object_Declaration |
4585 N_Object_Renaming_Declaration =>
4586 if Present (Subtype_Mark (N)) then
4587 return Null_Exclusion_Present (N);
4588 else pragma Assert (Present (Access_Definition (N)));
4589 return Null_Exclusion_Present (Access_Definition (N));
4592 when N_Discriminant_Specification =>
4593 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4594 return Null_Exclusion_Present (Discriminant_Type (N));
4596 return Null_Exclusion_Present (N);
4599 when N_Object_Declaration =>
4600 if Nkind (Object_Definition (N)) = N_Access_Definition then
4601 return Null_Exclusion_Present (Object_Definition (N));
4603 return Null_Exclusion_Present (N);
4606 when N_Parameter_Specification =>
4607 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4608 return Null_Exclusion_Present (Parameter_Type (N));
4610 return Null_Exclusion_Present (N);
4617 end Has_Null_Exclusion;
4619 ------------------------
4620 -- Has_Null_Extension --
4621 ------------------------
4623 function Has_Null_Extension (T : Entity_Id) return Boolean is
4624 B : constant Entity_Id := Base_Type (T);
4629 if Nkind (Parent (B)) = N_Full_Type_Declaration
4630 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4632 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4634 if Present (Ext) then
4635 if Null_Present (Ext) then
4638 Comps := Component_List (Ext);
4640 -- The null component list is rewritten during analysis to
4641 -- include the parent component. Any other component indicates
4642 -- that the extension was not originally null.
4644 return Null_Present (Comps)
4645 or else No (Next (First (Component_Items (Comps))));
4654 end Has_Null_Extension;
4656 -------------------------------
4657 -- Has_Overriding_Initialize --
4658 -------------------------------
4660 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4661 BT : constant Entity_Id := Base_Type (T);
4666 if Is_Controlled (BT) then
4668 -- For derived types, check immediate ancestor, excluding
4669 -- Controlled itself.
4671 if Is_Derived_Type (BT)
4672 and then not In_Predefined_Unit (Etype (BT))
4673 and then Has_Overriding_Initialize (Etype (BT))
4677 elsif Present (Primitive_Operations (BT)) then
4678 P := First_Elmt (Primitive_Operations (BT));
4679 while Present (P) loop
4680 if Chars (Node (P)) = Name_Initialize
4681 and then Comes_From_Source (Node (P))
4692 elsif Has_Controlled_Component (BT) then
4693 Comp := First_Component (BT);
4694 while Present (Comp) loop
4695 if Has_Overriding_Initialize (Etype (Comp)) then
4699 Next_Component (Comp);
4707 end Has_Overriding_Initialize;
4709 --------------------------------------
4710 -- Has_Preelaborable_Initialization --
4711 --------------------------------------
4713 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4716 procedure Check_Components (E : Entity_Id);
4717 -- Check component/discriminant chain, sets Has_PE False if a component
4718 -- or discriminant does not meet the preelaborable initialization rules.
4720 ----------------------
4721 -- Check_Components --
4722 ----------------------
4724 procedure Check_Components (E : Entity_Id) is
4728 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4729 -- Returns True if and only if the expression denoted by N does not
4730 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4732 ---------------------------------
4733 -- Is_Preelaborable_Expression --
4734 ---------------------------------
4736 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4740 Comp_Type : Entity_Id;
4741 Is_Array_Aggr : Boolean;
4744 if Is_Static_Expression (N) then
4747 elsif Nkind (N) = N_Null then
4750 -- Attributes are allowed in general, even if their prefix is a
4751 -- formal type. (It seems that certain attributes known not to be
4752 -- static might not be allowed, but there are no rules to prevent
4755 elsif Nkind (N) = N_Attribute_Reference then
4758 -- The name of a discriminant evaluated within its parent type is
4759 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4760 -- names that denote discriminals as well as discriminants to
4761 -- catch references occurring within init procs.
4763 elsif Is_Entity_Name (N)
4765 (Ekind (Entity (N)) = E_Discriminant
4767 ((Ekind (Entity (N)) = E_Constant
4768 or else Ekind (Entity (N)) = E_In_Parameter)
4769 and then Present (Discriminal_Link (Entity (N)))))
4773 elsif Nkind (N) = N_Qualified_Expression then
4774 return Is_Preelaborable_Expression (Expression (N));
4776 -- For aggregates we have to check that each of the associations
4777 -- is preelaborable.
4779 elsif Nkind (N) = N_Aggregate
4780 or else Nkind (N) = N_Extension_Aggregate
4782 Is_Array_Aggr := Is_Array_Type (Etype (N));
4784 if Is_Array_Aggr then
4785 Comp_Type := Component_Type (Etype (N));
4788 -- Check the ancestor part of extension aggregates, which must
4789 -- be either the name of a type that has preelaborable init or
4790 -- an expression that is preelaborable.
4792 if Nkind (N) = N_Extension_Aggregate then
4794 Anc_Part : constant Node_Id := Ancestor_Part (N);
4797 if Is_Entity_Name (Anc_Part)
4798 and then Is_Type (Entity (Anc_Part))
4800 if not Has_Preelaborable_Initialization
4806 elsif not Is_Preelaborable_Expression (Anc_Part) then
4812 -- Check positional associations
4814 Exp := First (Expressions (N));
4815 while Present (Exp) loop
4816 if not Is_Preelaborable_Expression (Exp) then
4823 -- Check named associations
4825 Assn := First (Component_Associations (N));
4826 while Present (Assn) loop
4827 Choice := First (Choices (Assn));
4828 while Present (Choice) loop
4829 if Is_Array_Aggr then
4830 if Nkind (Choice) = N_Others_Choice then
4833 elsif Nkind (Choice) = N_Range then
4834 if not Is_Static_Range (Choice) then
4838 elsif not Is_Static_Expression (Choice) then
4843 Comp_Type := Etype (Choice);
4849 -- If the association has a <> at this point, then we have
4850 -- to check whether the component's type has preelaborable
4851 -- initialization. Note that this only occurs when the
4852 -- association's corresponding component does not have a
4853 -- default expression, the latter case having already been
4854 -- expanded as an expression for the association.
4856 if Box_Present (Assn) then
4857 if not Has_Preelaborable_Initialization (Comp_Type) then
4861 -- In the expression case we check whether the expression
4862 -- is preelaborable.
4865 not Is_Preelaborable_Expression (Expression (Assn))
4873 -- If we get here then aggregate as a whole is preelaborable
4877 -- All other cases are not preelaborable
4882 end Is_Preelaborable_Expression;
4884 -- Start of processing for Check_Components
4887 -- Loop through entities of record or protected type
4890 while Present (Ent) loop
4892 -- We are interested only in components and discriminants
4894 if Ekind_In (Ent, E_Component, E_Discriminant) then
4896 -- Get default expression if any. If there is no declaration
4897 -- node, it means we have an internal entity. The parent and
4898 -- tag fields are examples of such entities. For these cases,
4899 -- we just test the type of the entity.
4901 if Present (Declaration_Node (Ent)) then
4902 Exp := Expression (Declaration_Node (Ent));
4907 -- A component has PI if it has no default expression and the
4908 -- component type has PI.
4911 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4916 -- Require the default expression to be preelaborable
4918 elsif not Is_Preelaborable_Expression (Exp) then
4926 end Check_Components;
4928 -- Start of processing for Has_Preelaborable_Initialization
4931 -- Immediate return if already marked as known preelaborable init. This
4932 -- covers types for which this function has already been called once
4933 -- and returned True (in which case the result is cached), and also
4934 -- types to which a pragma Preelaborable_Initialization applies.
4936 if Known_To_Have_Preelab_Init (E) then
4940 -- If the type is a subtype representing a generic actual type, then
4941 -- test whether its base type has preelaborable initialization since
4942 -- the subtype representing the actual does not inherit this attribute
4943 -- from the actual or formal. (but maybe it should???)
4945 if Is_Generic_Actual_Type (E) then
4946 return Has_Preelaborable_Initialization (Base_Type (E));
4949 -- All elementary types have preelaborable initialization
4951 if Is_Elementary_Type (E) then
4954 -- Array types have PI if the component type has PI
4956 elsif Is_Array_Type (E) then
4957 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4959 -- A derived type has preelaborable initialization if its parent type
4960 -- has preelaborable initialization and (in the case of a derived record
4961 -- extension) if the non-inherited components all have preelaborable
4962 -- initialization. However, a user-defined controlled type with an
4963 -- overriding Initialize procedure does not have preelaborable
4966 elsif Is_Derived_Type (E) then
4968 -- If the derived type is a private extension then it doesn't have
4969 -- preelaborable initialization.
4971 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4975 -- First check whether ancestor type has preelaborable initialization
4977 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4979 -- If OK, check extension components (if any)
4981 if Has_PE and then Is_Record_Type (E) then
4982 Check_Components (First_Entity (E));
4985 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4986 -- with a user defined Initialize procedure does not have PI.
4989 and then Is_Controlled (E)
4990 and then Has_Overriding_Initialize (E)
4995 -- Private types not derived from a type having preelaborable init and
4996 -- that are not marked with pragma Preelaborable_Initialization do not
4997 -- have preelaborable initialization.
4999 elsif Is_Private_Type (E) then
5002 -- Record type has PI if it is non private and all components have PI
5004 elsif Is_Record_Type (E) then
5006 Check_Components (First_Entity (E));
5008 -- Protected types must not have entries, and components must meet
5009 -- same set of rules as for record components.
5011 elsif Is_Protected_Type (E) then
5012 if Has_Entries (E) then
5016 Check_Components (First_Entity (E));
5017 Check_Components (First_Private_Entity (E));
5020 -- Type System.Address always has preelaborable initialization
5022 elsif Is_RTE (E, RE_Address) then
5025 -- In all other cases, type does not have preelaborable initialization
5031 -- If type has preelaborable initialization, cache result
5034 Set_Known_To_Have_Preelab_Init (E);
5038 end Has_Preelaborable_Initialization;
5040 ---------------------------
5041 -- Has_Private_Component --
5042 ---------------------------
5044 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5045 Btype : Entity_Id := Base_Type (Type_Id);
5046 Component : Entity_Id;
5049 if Error_Posted (Type_Id)
5050 or else Error_Posted (Btype)
5055 if Is_Class_Wide_Type (Btype) then
5056 Btype := Root_Type (Btype);
5059 if Is_Private_Type (Btype) then
5061 UT : constant Entity_Id := Underlying_Type (Btype);
5064 if No (Full_View (Btype)) then
5065 return not Is_Generic_Type (Btype)
5066 and then not Is_Generic_Type (Root_Type (Btype));
5068 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5071 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5075 elsif Is_Array_Type (Btype) then
5076 return Has_Private_Component (Component_Type (Btype));
5078 elsif Is_Record_Type (Btype) then
5079 Component := First_Component (Btype);
5080 while Present (Component) loop
5081 if Has_Private_Component (Etype (Component)) then
5085 Next_Component (Component);
5090 elsif Is_Protected_Type (Btype)
5091 and then Present (Corresponding_Record_Type (Btype))
5093 return Has_Private_Component (Corresponding_Record_Type (Btype));
5098 end Has_Private_Component;
5104 function Has_Stream (T : Entity_Id) return Boolean is
5111 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5114 elsif Is_Array_Type (T) then
5115 return Has_Stream (Component_Type (T));
5117 elsif Is_Record_Type (T) then
5118 E := First_Component (T);
5119 while Present (E) loop
5120 if Has_Stream (Etype (E)) then
5129 elsif Is_Private_Type (T) then
5130 return Has_Stream (Underlying_Type (T));
5137 --------------------------
5138 -- Has_Tagged_Component --
5139 --------------------------
5141 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5145 if Is_Private_Type (Typ)
5146 and then Present (Underlying_Type (Typ))
5148 return Has_Tagged_Component (Underlying_Type (Typ));
5150 elsif Is_Array_Type (Typ) then
5151 return Has_Tagged_Component (Component_Type (Typ));
5153 elsif Is_Tagged_Type (Typ) then
5156 elsif Is_Record_Type (Typ) then
5157 Comp := First_Component (Typ);
5158 while Present (Comp) loop
5159 if Has_Tagged_Component (Etype (Comp)) then
5163 Next_Component (Comp);
5171 end Has_Tagged_Component;
5173 --------------------------
5174 -- Implements_Interface --
5175 --------------------------
5177 function Implements_Interface
5178 (Typ_Ent : Entity_Id;
5179 Iface_Ent : Entity_Id;
5180 Exclude_Parents : Boolean := False) return Boolean
5182 Ifaces_List : Elist_Id;
5184 Iface : Entity_Id := Base_Type (Iface_Ent);
5185 Typ : Entity_Id := Base_Type (Typ_Ent);
5188 if Is_Class_Wide_Type (Typ) then
5189 Typ := Root_Type (Typ);
5192 if not Has_Interfaces (Typ) then
5196 if Is_Class_Wide_Type (Iface) then
5197 Iface := Root_Type (Iface);
5200 Collect_Interfaces (Typ, Ifaces_List);
5202 Elmt := First_Elmt (Ifaces_List);
5203 while Present (Elmt) loop
5204 if Is_Ancestor (Node (Elmt), Typ)
5205 and then Exclude_Parents
5209 elsif Node (Elmt) = Iface then
5217 end Implements_Interface;
5223 function In_Instance return Boolean is
5224 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5230 and then S /= Standard_Standard
5232 if (Ekind (S) = E_Function
5233 or else Ekind (S) = E_Package
5234 or else Ekind (S) = E_Procedure)
5235 and then Is_Generic_Instance (S)
5237 -- A child instance is always compiled in the context of a parent
5238 -- instance. Nevertheless, the actuals are not analyzed in an
5239 -- instance context. We detect this case by examining the current
5240 -- compilation unit, which must be a child instance, and checking
5241 -- that it is not currently on the scope stack.
5243 if Is_Child_Unit (Curr_Unit)
5245 Nkind (Unit (Cunit (Current_Sem_Unit)))
5246 = N_Package_Instantiation
5247 and then not In_Open_Scopes (Curr_Unit)
5261 ----------------------
5262 -- In_Instance_Body --
5263 ----------------------
5265 function In_Instance_Body return Boolean is
5271 and then S /= Standard_Standard
5273 if (Ekind (S) = E_Function
5274 or else Ekind (S) = E_Procedure)
5275 and then Is_Generic_Instance (S)
5279 elsif Ekind (S) = E_Package
5280 and then In_Package_Body (S)
5281 and then Is_Generic_Instance (S)
5290 end In_Instance_Body;
5292 -----------------------------
5293 -- In_Instance_Not_Visible --
5294 -----------------------------
5296 function In_Instance_Not_Visible return Boolean is
5302 and then S /= Standard_Standard
5304 if (Ekind (S) = E_Function
5305 or else Ekind (S) = E_Procedure)
5306 and then Is_Generic_Instance (S)
5310 elsif Ekind (S) = E_Package
5311 and then (In_Package_Body (S) or else In_Private_Part (S))
5312 and then Is_Generic_Instance (S)
5321 end In_Instance_Not_Visible;
5323 ------------------------------
5324 -- In_Instance_Visible_Part --
5325 ------------------------------
5327 function In_Instance_Visible_Part return Boolean is
5333 and then S /= Standard_Standard
5335 if Ekind (S) = E_Package
5336 and then Is_Generic_Instance (S)
5337 and then not In_Package_Body (S)
5338 and then not In_Private_Part (S)
5347 end In_Instance_Visible_Part;
5349 ---------------------
5350 -- In_Package_Body --
5351 ---------------------
5353 function In_Package_Body return Boolean is
5359 and then S /= Standard_Standard
5361 if Ekind (S) = E_Package
5362 and then In_Package_Body (S)
5371 end In_Package_Body;
5373 --------------------------------
5374 -- In_Parameter_Specification --
5375 --------------------------------
5377 function In_Parameter_Specification (N : Node_Id) return Boolean is
5382 while Present (PN) loop
5383 if Nkind (PN) = N_Parameter_Specification then
5391 end In_Parameter_Specification;
5393 --------------------------------------
5394 -- In_Subprogram_Or_Concurrent_Unit --
5395 --------------------------------------
5397 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5402 -- Use scope chain to check successively outer scopes
5408 if K in Subprogram_Kind
5409 or else K in Concurrent_Kind
5410 or else K in Generic_Subprogram_Kind
5414 elsif E = Standard_Standard then
5420 end In_Subprogram_Or_Concurrent_Unit;
5422 ---------------------
5423 -- In_Visible_Part --
5424 ---------------------
5426 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5429 Is_Package_Or_Generic_Package (Scope_Id)
5430 and then In_Open_Scopes (Scope_Id)
5431 and then not In_Package_Body (Scope_Id)
5432 and then not In_Private_Part (Scope_Id);
5433 end In_Visible_Part;
5435 ---------------------------------
5436 -- Insert_Explicit_Dereference --
5437 ---------------------------------
5439 procedure Insert_Explicit_Dereference (N : Node_Id) is
5440 New_Prefix : constant Node_Id := Relocate_Node (N);
5441 Ent : Entity_Id := Empty;
5448 Save_Interps (N, New_Prefix);
5450 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5452 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5454 if Is_Overloaded (New_Prefix) then
5456 -- The dereference is also overloaded, and its interpretations are
5457 -- the designated types of the interpretations of the original node.
5459 Set_Etype (N, Any_Type);
5461 Get_First_Interp (New_Prefix, I, It);
5462 while Present (It.Nam) loop
5465 if Is_Access_Type (T) then
5466 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5469 Get_Next_Interp (I, It);
5475 -- Prefix is unambiguous: mark the original prefix (which might
5476 -- Come_From_Source) as a reference, since the new (relocated) one
5477 -- won't be taken into account.
5479 if Is_Entity_Name (New_Prefix) then
5480 Ent := Entity (New_Prefix);
5482 -- For a retrieval of a subcomponent of some composite object,
5483 -- retrieve the ultimate entity if there is one.
5485 elsif Nkind (New_Prefix) = N_Selected_Component
5486 or else Nkind (New_Prefix) = N_Indexed_Component
5488 Pref := Prefix (New_Prefix);
5489 while Present (Pref)
5491 (Nkind (Pref) = N_Selected_Component
5492 or else Nkind (Pref) = N_Indexed_Component)
5494 Pref := Prefix (Pref);
5497 if Present (Pref) and then Is_Entity_Name (Pref) then
5498 Ent := Entity (Pref);
5502 if Present (Ent) then
5503 Generate_Reference (Ent, New_Prefix);
5506 end Insert_Explicit_Dereference;
5508 ------------------------------------------
5509 -- Inspect_Deferred_Constant_Completion --
5510 ------------------------------------------
5512 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5516 Decl := First (Decls);
5517 while Present (Decl) loop
5519 -- Deferred constant signature
5521 if Nkind (Decl) = N_Object_Declaration
5522 and then Constant_Present (Decl)
5523 and then No (Expression (Decl))
5525 -- No need to check internally generated constants
5527 and then Comes_From_Source (Decl)
5529 -- The constant is not completed. A full object declaration
5530 -- or a pragma Import complete a deferred constant.
5532 and then not Has_Completion (Defining_Identifier (Decl))
5535 ("constant declaration requires initialization expression",
5536 Defining_Identifier (Decl));
5539 Decl := Next (Decl);
5541 end Inspect_Deferred_Constant_Completion;
5547 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5548 pragma Assert (Is_Type (E));
5550 return AAMP_On_Target
5551 and then Is_Floating_Point_Type (E)
5552 and then E = Base_Type (E);
5555 -----------------------------
5556 -- Is_Actual_Out_Parameter --
5557 -----------------------------
5559 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5563 Find_Actual (N, Formal, Call);
5564 return Present (Formal)
5565 and then Ekind (Formal) = E_Out_Parameter;
5566 end Is_Actual_Out_Parameter;
5568 -------------------------
5569 -- Is_Actual_Parameter --
5570 -------------------------
5572 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5573 PK : constant Node_Kind := Nkind (Parent (N));
5577 when N_Parameter_Association =>
5578 return N = Explicit_Actual_Parameter (Parent (N));
5580 when N_Function_Call | N_Procedure_Call_Statement =>
5581 return Is_List_Member (N)
5583 List_Containing (N) = Parameter_Associations (Parent (N));
5588 end Is_Actual_Parameter;
5590 ---------------------
5591 -- Is_Aliased_View --
5592 ---------------------
5594 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5598 if Is_Entity_Name (Obj) then
5606 or else (Present (Renamed_Object (E))
5607 and then Is_Aliased_View (Renamed_Object (E)))))
5609 or else ((Is_Formal (E)
5610 or else Ekind (E) = E_Generic_In_Out_Parameter
5611 or else Ekind (E) = E_Generic_In_Parameter)
5612 and then Is_Tagged_Type (Etype (E)))
5614 or else (Is_Concurrent_Type (E)
5615 and then In_Open_Scopes (E))
5617 -- Current instance of type, either directly or as rewritten
5618 -- reference to the current object.
5620 or else (Is_Entity_Name (Original_Node (Obj))
5621 and then Present (Entity (Original_Node (Obj)))
5622 and then Is_Type (Entity (Original_Node (Obj))))
5624 or else (Is_Type (E) and then E = Current_Scope)
5626 or else (Is_Incomplete_Or_Private_Type (E)
5627 and then Full_View (E) = Current_Scope);
5629 elsif Nkind (Obj) = N_Selected_Component then
5630 return Is_Aliased (Entity (Selector_Name (Obj)));
5632 elsif Nkind (Obj) = N_Indexed_Component then
5633 return Has_Aliased_Components (Etype (Prefix (Obj)))
5635 (Is_Access_Type (Etype (Prefix (Obj)))
5637 Has_Aliased_Components
5638 (Designated_Type (Etype (Prefix (Obj)))));
5640 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5641 or else Nkind (Obj) = N_Type_Conversion
5643 return Is_Tagged_Type (Etype (Obj))
5644 and then Is_Aliased_View (Expression (Obj));
5646 elsif Nkind (Obj) = N_Explicit_Dereference then
5647 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5652 end Is_Aliased_View;
5654 -------------------------
5655 -- Is_Ancestor_Package --
5656 -------------------------
5658 function Is_Ancestor_Package
5660 E2 : Entity_Id) return Boolean
5667 and then Par /= Standard_Standard
5677 end Is_Ancestor_Package;
5679 ----------------------
5680 -- Is_Atomic_Object --
5681 ----------------------
5683 function Is_Atomic_Object (N : Node_Id) return Boolean is
5685 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5686 -- Determines if given object has atomic components
5688 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5689 -- If prefix is an implicit dereference, examine designated type
5691 ----------------------
5692 -- Is_Atomic_Prefix --
5693 ----------------------
5695 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5697 if Is_Access_Type (Etype (N)) then
5699 Has_Atomic_Components (Designated_Type (Etype (N)));
5701 return Object_Has_Atomic_Components (N);
5703 end Is_Atomic_Prefix;
5705 ----------------------------------
5706 -- Object_Has_Atomic_Components --
5707 ----------------------------------
5709 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5711 if Has_Atomic_Components (Etype (N))
5712 or else Is_Atomic (Etype (N))
5716 elsif Is_Entity_Name (N)
5717 and then (Has_Atomic_Components (Entity (N))
5718 or else Is_Atomic (Entity (N)))
5722 elsif Nkind (N) = N_Indexed_Component
5723 or else Nkind (N) = N_Selected_Component
5725 return Is_Atomic_Prefix (Prefix (N));
5730 end Object_Has_Atomic_Components;
5732 -- Start of processing for Is_Atomic_Object
5735 -- Predicate is not relevant to subprograms
5737 if Is_Entity_Name (N)
5738 and then Is_Overloadable (Entity (N))
5742 elsif Is_Atomic (Etype (N))
5743 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5747 elsif Nkind (N) = N_Indexed_Component
5748 or else Nkind (N) = N_Selected_Component
5750 return Is_Atomic_Prefix (Prefix (N));
5755 end Is_Atomic_Object;
5757 -------------------------
5758 -- Is_Coextension_Root --
5759 -------------------------
5761 function Is_Coextension_Root (N : Node_Id) return Boolean is
5764 Nkind (N) = N_Allocator
5765 and then Present (Coextensions (N))
5767 -- Anonymous access discriminants carry a list of all nested
5768 -- controlled coextensions.
5770 and then not Is_Dynamic_Coextension (N)
5771 and then not Is_Static_Coextension (N);
5772 end Is_Coextension_Root;
5774 -----------------------------
5775 -- Is_Concurrent_Interface --
5776 -----------------------------
5778 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5783 (Is_Protected_Interface (T)
5784 or else Is_Synchronized_Interface (T)
5785 or else Is_Task_Interface (T));
5786 end Is_Concurrent_Interface;
5788 --------------------------------------
5789 -- Is_Controlling_Limited_Procedure --
5790 --------------------------------------
5792 function Is_Controlling_Limited_Procedure
5793 (Proc_Nam : Entity_Id) return Boolean
5795 Param_Typ : Entity_Id := Empty;
5798 if Ekind (Proc_Nam) = E_Procedure
5799 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5801 Param_Typ := Etype (Parameter_Type (First (
5802 Parameter_Specifications (Parent (Proc_Nam)))));
5804 -- In this case where an Itype was created, the procedure call has been
5807 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5808 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5810 Present (Parameter_Associations
5811 (Associated_Node_For_Itype (Proc_Nam)))
5814 Etype (First (Parameter_Associations
5815 (Associated_Node_For_Itype (Proc_Nam))));
5818 if Present (Param_Typ) then
5820 Is_Interface (Param_Typ)
5821 and then Is_Limited_Record (Param_Typ);
5825 end Is_Controlling_Limited_Procedure;
5827 -----------------------------
5828 -- Is_CPP_Constructor_Call --
5829 -----------------------------
5831 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5833 return Nkind (N) = N_Function_Call
5834 and then Is_CPP_Class (Etype (Etype (N)))
5835 and then Is_Constructor (Entity (Name (N)))
5836 and then Is_Imported (Entity (Name (N)));
5837 end Is_CPP_Constructor_Call;
5843 function Is_Delegate (T : Entity_Id) return Boolean is
5844 Desig_Type : Entity_Id;
5847 if VM_Target /= CLI_Target then
5851 -- Access-to-subprograms are delegates in CIL
5853 if Ekind (T) = E_Access_Subprogram_Type then
5857 if Ekind (T) not in Access_Kind then
5859 -- A delegate is a managed pointer. If no designated type is defined
5860 -- it means that it's not a delegate.
5865 Desig_Type := Etype (Directly_Designated_Type (T));
5867 if not Is_Tagged_Type (Desig_Type) then
5871 -- Test if the type is inherited from [mscorlib]System.Delegate
5873 while Etype (Desig_Type) /= Desig_Type loop
5874 if Chars (Scope (Desig_Type)) /= No_Name
5875 and then Is_Imported (Scope (Desig_Type))
5876 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
5881 Desig_Type := Etype (Desig_Type);
5887 ----------------------------------------------
5888 -- Is_Dependent_Component_Of_Mutable_Object --
5889 ----------------------------------------------
5891 function Is_Dependent_Component_Of_Mutable_Object
5892 (Object : Node_Id) return Boolean
5895 Prefix_Type : Entity_Id;
5896 P_Aliased : Boolean := False;
5899 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5900 -- Returns True if and only if Comp is declared within a variant part
5902 --------------------------------
5903 -- Is_Declared_Within_Variant --
5904 --------------------------------
5906 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5907 Comp_Decl : constant Node_Id := Parent (Comp);
5908 Comp_List : constant Node_Id := Parent (Comp_Decl);
5910 return Nkind (Parent (Comp_List)) = N_Variant;
5911 end Is_Declared_Within_Variant;
5913 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5916 if Is_Variable (Object) then
5918 if Nkind (Object) = N_Selected_Component then
5919 P := Prefix (Object);
5920 Prefix_Type := Etype (P);
5922 if Is_Entity_Name (P) then
5924 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5925 Prefix_Type := Base_Type (Prefix_Type);
5928 if Is_Aliased (Entity (P)) then
5932 -- A discriminant check on a selected component may be
5933 -- expanded into a dereference when removing side-effects.
5934 -- Recover the original node and its type, which may be
5937 elsif Nkind (P) = N_Explicit_Dereference
5938 and then not (Comes_From_Source (P))
5940 P := Original_Node (P);
5941 Prefix_Type := Etype (P);
5944 -- Check for prefix being an aliased component ???
5949 -- A heap object is constrained by its initial value
5951 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5952 -- the dereferenced case, since the access value might denote an
5953 -- unconstrained aliased object, whereas in Ada 95 the designated
5954 -- object is guaranteed to be constrained. A worst-case assumption
5955 -- has to apply in Ada 2005 because we can't tell at compile time
5956 -- whether the object is "constrained by its initial value"
5957 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5958 -- semantic rules -- these rules are acknowledged to need fixing).
5960 if Ada_Version < Ada_05 then
5961 if Is_Access_Type (Prefix_Type)
5962 or else Nkind (P) = N_Explicit_Dereference
5967 elsif Ada_Version >= Ada_05 then
5968 if Is_Access_Type (Prefix_Type) then
5970 -- If the access type is pool-specific, and there is no
5971 -- constrained partial view of the designated type, then the
5972 -- designated object is known to be constrained.
5974 if Ekind (Prefix_Type) = E_Access_Type
5975 and then not Has_Constrained_Partial_View
5976 (Designated_Type (Prefix_Type))
5980 -- Otherwise (general access type, or there is a constrained
5981 -- partial view of the designated type), we need to check
5982 -- based on the designated type.
5985 Prefix_Type := Designated_Type (Prefix_Type);
5991 Original_Record_Component (Entity (Selector_Name (Object)));
5993 -- As per AI-0017, the renaming is illegal in a generic body,
5994 -- even if the subtype is indefinite.
5996 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5998 if not Is_Constrained (Prefix_Type)
5999 and then (not Is_Indefinite_Subtype (Prefix_Type)
6001 (Is_Generic_Type (Prefix_Type)
6002 and then Ekind (Current_Scope) = E_Generic_Package
6003 and then In_Package_Body (Current_Scope)))
6005 and then (Is_Declared_Within_Variant (Comp)
6006 or else Has_Discriminant_Dependent_Constraint (Comp))
6007 and then (not P_Aliased or else Ada_Version >= Ada_05)
6013 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6017 elsif Nkind (Object) = N_Indexed_Component
6018 or else Nkind (Object) = N_Slice
6020 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6022 -- A type conversion that Is_Variable is a view conversion:
6023 -- go back to the denoted object.
6025 elsif Nkind (Object) = N_Type_Conversion then
6027 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6032 end Is_Dependent_Component_Of_Mutable_Object;
6034 ---------------------
6035 -- Is_Dereferenced --
6036 ---------------------
6038 function Is_Dereferenced (N : Node_Id) return Boolean is
6039 P : constant Node_Id := Parent (N);
6042 (Nkind (P) = N_Selected_Component
6044 Nkind (P) = N_Explicit_Dereference
6046 Nkind (P) = N_Indexed_Component
6048 Nkind (P) = N_Slice)
6049 and then Prefix (P) = N;
6050 end Is_Dereferenced;
6052 ----------------------
6053 -- Is_Descendent_Of --
6054 ----------------------
6056 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6061 pragma Assert (Nkind (T1) in N_Entity);
6062 pragma Assert (Nkind (T2) in N_Entity);
6064 T := Base_Type (T1);
6066 -- Immediate return if the types match
6071 -- Comment needed here ???
6073 elsif Ekind (T) = E_Class_Wide_Type then
6074 return Etype (T) = T2;
6082 -- Done if we found the type we are looking for
6087 -- Done if no more derivations to check
6094 -- Following test catches error cases resulting from prev errors
6096 elsif No (Etyp) then
6099 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6102 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6106 T := Base_Type (Etyp);
6109 end Is_Descendent_Of;
6115 function Is_False (U : Uint) return Boolean is
6120 ---------------------------
6121 -- Is_Fixed_Model_Number --
6122 ---------------------------
6124 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6125 S : constant Ureal := Small_Value (T);
6126 M : Urealp.Save_Mark;
6130 R := (U = UR_Trunc (U / S) * S);
6133 end Is_Fixed_Model_Number;
6135 -------------------------------
6136 -- Is_Fully_Initialized_Type --
6137 -------------------------------
6139 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6141 if Is_Scalar_Type (Typ) then
6144 elsif Is_Access_Type (Typ) then
6147 elsif Is_Array_Type (Typ) then
6148 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6152 -- An interesting case, if we have a constrained type one of whose
6153 -- bounds is known to be null, then there are no elements to be
6154 -- initialized, so all the elements are initialized!
6156 if Is_Constrained (Typ) then
6159 Indx_Typ : Entity_Id;
6163 Indx := First_Index (Typ);
6164 while Present (Indx) loop
6165 if Etype (Indx) = Any_Type then
6168 -- If index is a range, use directly
6170 elsif Nkind (Indx) = N_Range then
6171 Lbd := Low_Bound (Indx);
6172 Hbd := High_Bound (Indx);
6175 Indx_Typ := Etype (Indx);
6177 if Is_Private_Type (Indx_Typ) then
6178 Indx_Typ := Full_View (Indx_Typ);
6181 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6184 Lbd := Type_Low_Bound (Indx_Typ);
6185 Hbd := Type_High_Bound (Indx_Typ);
6189 if Compile_Time_Known_Value (Lbd)
6190 and then Compile_Time_Known_Value (Hbd)
6192 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6202 -- If no null indexes, then type is not fully initialized
6208 elsif Is_Record_Type (Typ) then
6209 if Has_Discriminants (Typ)
6211 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6212 and then Is_Fully_Initialized_Variant (Typ)
6217 -- Controlled records are considered to be fully initialized if
6218 -- there is a user defined Initialize routine. This may not be
6219 -- entirely correct, but as the spec notes, we are guessing here
6220 -- what is best from the point of view of issuing warnings.
6222 if Is_Controlled (Typ) then
6224 Utyp : constant Entity_Id := Underlying_Type (Typ);
6227 if Present (Utyp) then
6229 Init : constant Entity_Id :=
6231 (Underlying_Type (Typ), Name_Initialize));
6235 and then Comes_From_Source (Init)
6237 Is_Predefined_File_Name
6238 (File_Name (Get_Source_File_Index (Sloc (Init))))
6242 elsif Has_Null_Extension (Typ)
6244 Is_Fully_Initialized_Type
6245 (Etype (Base_Type (Typ)))
6254 -- Otherwise see if all record components are initialized
6260 Ent := First_Entity (Typ);
6261 while Present (Ent) loop
6262 if Chars (Ent) = Name_uController then
6265 elsif Ekind (Ent) = E_Component
6266 and then (No (Parent (Ent))
6267 or else No (Expression (Parent (Ent))))
6268 and then not Is_Fully_Initialized_Type (Etype (Ent))
6270 -- Special VM case for tag components, which need to be
6271 -- defined in this case, but are never initialized as VMs
6272 -- are using other dispatching mechanisms. Ignore this
6273 -- uninitialized case. Note that this applies both to the
6274 -- uTag entry and the main vtable pointer (CPP_Class case).
6276 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6285 -- No uninitialized components, so type is fully initialized.
6286 -- Note that this catches the case of no components as well.
6290 elsif Is_Concurrent_Type (Typ) then
6293 elsif Is_Private_Type (Typ) then
6295 U : constant Entity_Id := Underlying_Type (Typ);
6301 return Is_Fully_Initialized_Type (U);
6308 end Is_Fully_Initialized_Type;
6310 ----------------------------------
6311 -- Is_Fully_Initialized_Variant --
6312 ----------------------------------
6314 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6315 Loc : constant Source_Ptr := Sloc (Typ);
6316 Constraints : constant List_Id := New_List;
6317 Components : constant Elist_Id := New_Elmt_List;
6318 Comp_Elmt : Elmt_Id;
6320 Comp_List : Node_Id;
6322 Discr_Val : Node_Id;
6324 Report_Errors : Boolean;
6325 pragma Warnings (Off, Report_Errors);
6328 if Serious_Errors_Detected > 0 then
6332 if Is_Record_Type (Typ)
6333 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6334 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6336 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6338 Discr := First_Discriminant (Typ);
6339 while Present (Discr) loop
6340 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6341 Discr_Val := Expression (Parent (Discr));
6343 if Present (Discr_Val)
6344 and then Is_OK_Static_Expression (Discr_Val)
6346 Append_To (Constraints,
6347 Make_Component_Association (Loc,
6348 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6349 Expression => New_Copy (Discr_Val)));
6357 Next_Discriminant (Discr);
6362 Comp_List => Comp_List,
6363 Governed_By => Constraints,
6365 Report_Errors => Report_Errors);
6367 -- Check that each component present is fully initialized
6369 Comp_Elmt := First_Elmt (Components);
6370 while Present (Comp_Elmt) loop
6371 Comp_Id := Node (Comp_Elmt);
6373 if Ekind (Comp_Id) = E_Component
6374 and then (No (Parent (Comp_Id))
6375 or else No (Expression (Parent (Comp_Id))))
6376 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6381 Next_Elmt (Comp_Elmt);
6386 elsif Is_Private_Type (Typ) then
6388 U : constant Entity_Id := Underlying_Type (Typ);
6394 return Is_Fully_Initialized_Variant (U);
6400 end Is_Fully_Initialized_Variant;
6406 -- We seem to have a lot of overlapping functions that do similar things
6407 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6408 -- purely syntactic, it should be in Sem_Aux I would think???
6410 function Is_LHS (N : Node_Id) return Boolean is
6411 P : constant Node_Id := Parent (N);
6413 return Nkind (P) = N_Assignment_Statement
6414 and then Name (P) = N;
6417 ----------------------------
6418 -- Is_Inherited_Operation --
6419 ----------------------------
6421 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6422 Kind : constant Node_Kind := Nkind (Parent (E));
6424 pragma Assert (Is_Overloadable (E));
6425 return Kind = N_Full_Type_Declaration
6426 or else Kind = N_Private_Extension_Declaration
6427 or else Kind = N_Subtype_Declaration
6428 or else (Ekind (E) = E_Enumeration_Literal
6429 and then Is_Derived_Type (Etype (E)));
6430 end Is_Inherited_Operation;
6432 -----------------------------
6433 -- Is_Library_Level_Entity --
6434 -----------------------------
6436 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6438 -- The following is a small optimization, and it also properly handles
6439 -- discriminals, which in task bodies might appear in expressions before
6440 -- the corresponding procedure has been created, and which therefore do
6441 -- not have an assigned scope.
6443 if Ekind (E) in Formal_Kind then
6447 -- Normal test is simply that the enclosing dynamic scope is Standard
6449 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6450 end Is_Library_Level_Entity;
6452 ---------------------------------
6453 -- Is_Local_Variable_Reference --
6454 ---------------------------------
6456 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6458 if not Is_Entity_Name (Expr) then
6463 Ent : constant Entity_Id := Entity (Expr);
6464 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6466 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6469 return Present (Sub) and then Sub = Current_Subprogram;
6473 end Is_Local_Variable_Reference;
6475 -------------------------
6476 -- Is_Object_Reference --
6477 -------------------------
6479 function Is_Object_Reference (N : Node_Id) return Boolean is
6481 if Is_Entity_Name (N) then
6482 return Present (Entity (N)) and then Is_Object (Entity (N));
6486 when N_Indexed_Component | N_Slice =>
6488 Is_Object_Reference (Prefix (N))
6489 or else Is_Access_Type (Etype (Prefix (N)));
6491 -- In Ada95, a function call is a constant object; a procedure
6494 when N_Function_Call =>
6495 return Etype (N) /= Standard_Void_Type;
6497 -- A reference to the stream attribute Input is a function call
6499 when N_Attribute_Reference =>
6500 return Attribute_Name (N) = Name_Input;
6502 when N_Selected_Component =>
6504 Is_Object_Reference (Selector_Name (N))
6506 (Is_Object_Reference (Prefix (N))
6507 or else Is_Access_Type (Etype (Prefix (N))));
6509 when N_Explicit_Dereference =>
6512 -- A view conversion of a tagged object is an object reference
6514 when N_Type_Conversion =>
6515 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6516 and then Is_Tagged_Type (Etype (Expression (N)))
6517 and then Is_Object_Reference (Expression (N));
6519 -- An unchecked type conversion is considered to be an object if
6520 -- the operand is an object (this construction arises only as a
6521 -- result of expansion activities).
6523 when N_Unchecked_Type_Conversion =>
6530 end Is_Object_Reference;
6532 -----------------------------------
6533 -- Is_OK_Variable_For_Out_Formal --
6534 -----------------------------------
6536 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6538 Note_Possible_Modification (AV, Sure => True);
6540 -- We must reject parenthesized variable names. The check for
6541 -- Comes_From_Source is present because there are currently
6542 -- cases where the compiler violates this rule (e.g. passing
6543 -- a task object to its controlled Initialize routine).
6545 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6548 -- A variable is always allowed
6550 elsif Is_Variable (AV) then
6553 -- Unchecked conversions are allowed only if they come from the
6554 -- generated code, which sometimes uses unchecked conversions for out
6555 -- parameters in cases where code generation is unaffected. We tell
6556 -- source unchecked conversions by seeing if they are rewrites of an
6557 -- original Unchecked_Conversion function call, or of an explicit
6558 -- conversion of a function call.
6560 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6561 if Nkind (Original_Node (AV)) = N_Function_Call then
6564 elsif Comes_From_Source (AV)
6565 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6569 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6570 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6576 -- Normal type conversions are allowed if argument is a variable
6578 elsif Nkind (AV) = N_Type_Conversion then
6579 if Is_Variable (Expression (AV))
6580 and then Paren_Count (Expression (AV)) = 0
6582 Note_Possible_Modification (Expression (AV), Sure => True);
6585 -- We also allow a non-parenthesized expression that raises
6586 -- constraint error if it rewrites what used to be a variable
6588 elsif Raises_Constraint_Error (Expression (AV))
6589 and then Paren_Count (Expression (AV)) = 0
6590 and then Is_Variable (Original_Node (Expression (AV)))
6594 -- Type conversion of something other than a variable
6600 -- If this node is rewritten, then test the original form, if that is
6601 -- OK, then we consider the rewritten node OK (for example, if the
6602 -- original node is a conversion, then Is_Variable will not be true
6603 -- but we still want to allow the conversion if it converts a variable).
6605 elsif Original_Node (AV) /= AV then
6606 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6608 -- All other non-variables are rejected
6613 end Is_OK_Variable_For_Out_Formal;
6615 -----------------------------------
6616 -- Is_Partially_Initialized_Type --
6617 -----------------------------------
6619 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6621 if Is_Scalar_Type (Typ) then
6624 elsif Is_Access_Type (Typ) then
6627 elsif Is_Array_Type (Typ) then
6629 -- If component type is partially initialized, so is array type
6631 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6634 -- Otherwise we are only partially initialized if we are fully
6635 -- initialized (this is the empty array case, no point in us
6636 -- duplicating that code here).
6639 return Is_Fully_Initialized_Type (Typ);
6642 elsif Is_Record_Type (Typ) then
6644 -- A discriminated type is always partially initialized
6646 if Has_Discriminants (Typ) then
6649 -- A tagged type is always partially initialized
6651 elsif Is_Tagged_Type (Typ) then
6654 -- Case of non-discriminated record
6660 Component_Present : Boolean := False;
6661 -- Set True if at least one component is present. If no
6662 -- components are present, then record type is fully
6663 -- initialized (another odd case, like the null array).
6666 -- Loop through components
6668 Ent := First_Entity (Typ);
6669 while Present (Ent) loop
6670 if Ekind (Ent) = E_Component then
6671 Component_Present := True;
6673 -- If a component has an initialization expression then
6674 -- the enclosing record type is partially initialized
6676 if Present (Parent (Ent))
6677 and then Present (Expression (Parent (Ent)))
6681 -- If a component is of a type which is itself partially
6682 -- initialized, then the enclosing record type is also.
6684 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6692 -- No initialized components found. If we found any components
6693 -- they were all uninitialized so the result is false.
6695 if Component_Present then
6698 -- But if we found no components, then all the components are
6699 -- initialized so we consider the type to be initialized.
6707 -- Concurrent types are always fully initialized
6709 elsif Is_Concurrent_Type (Typ) then
6712 -- For a private type, go to underlying type. If there is no underlying
6713 -- type then just assume this partially initialized. Not clear if this
6714 -- can happen in a non-error case, but no harm in testing for this.
6716 elsif Is_Private_Type (Typ) then
6718 U : constant Entity_Id := Underlying_Type (Typ);
6723 return Is_Partially_Initialized_Type (U);
6727 -- For any other type (are there any?) assume partially initialized
6732 end Is_Partially_Initialized_Type;
6734 ------------------------------------
6735 -- Is_Potentially_Persistent_Type --
6736 ------------------------------------
6738 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6743 -- For private type, test corresponding full type
6745 if Is_Private_Type (T) then
6746 return Is_Potentially_Persistent_Type (Full_View (T));
6748 -- Scalar types are potentially persistent
6750 elsif Is_Scalar_Type (T) then
6753 -- Record type is potentially persistent if not tagged and the types of
6754 -- all it components are potentially persistent, and no component has
6755 -- an initialization expression.
6757 elsif Is_Record_Type (T)
6758 and then not Is_Tagged_Type (T)
6759 and then not Is_Partially_Initialized_Type (T)
6761 Comp := First_Component (T);
6762 while Present (Comp) loop
6763 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6772 -- Array type is potentially persistent if its component type is
6773 -- potentially persistent and if all its constraints are static.
6775 elsif Is_Array_Type (T) then
6776 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6780 Indx := First_Index (T);
6781 while Present (Indx) loop
6782 if not Is_OK_Static_Subtype (Etype (Indx)) then
6791 -- All other types are not potentially persistent
6796 end Is_Potentially_Persistent_Type;
6798 ---------------------------------
6799 -- Is_Protected_Self_Reference --
6800 ---------------------------------
6802 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6804 function In_Access_Definition (N : Node_Id) return Boolean;
6805 -- Returns true if N belongs to an access definition
6807 --------------------------
6808 -- In_Access_Definition --
6809 --------------------------
6811 function In_Access_Definition (N : Node_Id) return Boolean is
6816 while Present (P) loop
6817 if Nkind (P) = N_Access_Definition then
6825 end In_Access_Definition;
6827 -- Start of processing for Is_Protected_Self_Reference
6830 -- Verify that prefix is analyzed and has the proper form. Note that
6831 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6832 -- produce the address of an entity, do not analyze their prefix
6833 -- because they denote entities that are not necessarily visible.
6834 -- Neither of them can apply to a protected type.
6836 return Ada_Version >= Ada_05
6837 and then Is_Entity_Name (N)
6838 and then Present (Entity (N))
6839 and then Is_Protected_Type (Entity (N))
6840 and then In_Open_Scopes (Entity (N))
6841 and then not In_Access_Definition (N);
6842 end Is_Protected_Self_Reference;
6844 -----------------------------
6845 -- Is_RCI_Pkg_Spec_Or_Body --
6846 -----------------------------
6848 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6850 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6851 -- Return True if the unit of Cunit is an RCI package declaration
6853 ---------------------------
6854 -- Is_RCI_Pkg_Decl_Cunit --
6855 ---------------------------
6857 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6858 The_Unit : constant Node_Id := Unit (Cunit);
6861 if Nkind (The_Unit) /= N_Package_Declaration then
6865 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6866 end Is_RCI_Pkg_Decl_Cunit;
6868 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6871 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6873 (Nkind (Unit (Cunit)) = N_Package_Body
6874 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6875 end Is_RCI_Pkg_Spec_Or_Body;
6877 -----------------------------------------
6878 -- Is_Remote_Access_To_Class_Wide_Type --
6879 -----------------------------------------
6881 function Is_Remote_Access_To_Class_Wide_Type
6882 (E : Entity_Id) return Boolean
6885 -- A remote access to class-wide type is a general access to object type
6886 -- declared in the visible part of a Remote_Types or Remote_Call_
6889 return Ekind (E) = E_General_Access_Type
6890 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6891 end Is_Remote_Access_To_Class_Wide_Type;
6893 -----------------------------------------
6894 -- Is_Remote_Access_To_Subprogram_Type --
6895 -----------------------------------------
6897 function Is_Remote_Access_To_Subprogram_Type
6898 (E : Entity_Id) return Boolean
6901 return (Ekind (E) = E_Access_Subprogram_Type
6902 or else (Ekind (E) = E_Record_Type
6903 and then Present (Corresponding_Remote_Type (E))))
6904 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6905 end Is_Remote_Access_To_Subprogram_Type;
6907 --------------------
6908 -- Is_Remote_Call --
6909 --------------------
6911 function Is_Remote_Call (N : Node_Id) return Boolean is
6913 if Nkind (N) /= N_Procedure_Call_Statement
6914 and then Nkind (N) /= N_Function_Call
6916 -- An entry call cannot be remote
6920 elsif Nkind (Name (N)) in N_Has_Entity
6921 and then Is_Remote_Call_Interface (Entity (Name (N)))
6923 -- A subprogram declared in the spec of a RCI package is remote
6927 elsif Nkind (Name (N)) = N_Explicit_Dereference
6928 and then Is_Remote_Access_To_Subprogram_Type
6929 (Etype (Prefix (Name (N))))
6931 -- The dereference of a RAS is a remote call
6935 elsif Present (Controlling_Argument (N))
6936 and then Is_Remote_Access_To_Class_Wide_Type
6937 (Etype (Controlling_Argument (N)))
6939 -- Any primitive operation call with a controlling argument of
6940 -- a RACW type is a remote call.
6945 -- All other calls are local calls
6950 ----------------------
6951 -- Is_Renamed_Entry --
6952 ----------------------
6954 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6955 Orig_Node : Node_Id := Empty;
6956 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6958 function Is_Entry (Nam : Node_Id) return Boolean;
6959 -- Determine whether Nam is an entry. Traverse selectors if there are
6960 -- nested selected components.
6966 function Is_Entry (Nam : Node_Id) return Boolean is
6968 if Nkind (Nam) = N_Selected_Component then
6969 return Is_Entry (Selector_Name (Nam));
6972 return Ekind (Entity (Nam)) = E_Entry;
6975 -- Start of processing for Is_Renamed_Entry
6978 if Present (Alias (Proc_Nam)) then
6979 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6982 -- Look for a rewritten subprogram renaming declaration
6984 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6985 and then Present (Original_Node (Subp_Decl))
6987 Orig_Node := Original_Node (Subp_Decl);
6990 -- The rewritten subprogram is actually an entry
6992 if Present (Orig_Node)
6993 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6994 and then Is_Entry (Name (Orig_Node))
7000 end Is_Renamed_Entry;
7002 ----------------------
7003 -- Is_Selector_Name --
7004 ----------------------
7006 function Is_Selector_Name (N : Node_Id) return Boolean is
7008 if not Is_List_Member (N) then
7010 P : constant Node_Id := Parent (N);
7011 K : constant Node_Kind := Nkind (P);
7014 (K = N_Expanded_Name or else
7015 K = N_Generic_Association or else
7016 K = N_Parameter_Association or else
7017 K = N_Selected_Component)
7018 and then Selector_Name (P) = N;
7023 L : constant List_Id := List_Containing (N);
7024 P : constant Node_Id := Parent (L);
7026 return (Nkind (P) = N_Discriminant_Association
7027 and then Selector_Names (P) = L)
7029 (Nkind (P) = N_Component_Association
7030 and then Choices (P) = L);
7033 end Is_Selector_Name;
7039 function Is_Statement (N : Node_Id) return Boolean is
7042 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7043 or else Nkind (N) = N_Procedure_Call_Statement;
7046 ---------------------------------
7047 -- Is_Synchronized_Tagged_Type --
7048 ---------------------------------
7050 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7051 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7054 -- A task or protected type derived from an interface is a tagged type.
7055 -- Such a tagged type is called a synchronized tagged type, as are
7056 -- synchronized interfaces and private extensions whose declaration
7057 -- includes the reserved word synchronized.
7059 return (Is_Tagged_Type (E)
7060 and then (Kind = E_Task_Type
7061 or else Kind = E_Protected_Type))
7064 and then Is_Synchronized_Interface (E))
7066 (Ekind (E) = E_Record_Type_With_Private
7067 and then (Synchronized_Present (Parent (E))
7068 or else Is_Synchronized_Interface (Etype (E))));
7069 end Is_Synchronized_Tagged_Type;
7075 function Is_Transfer (N : Node_Id) return Boolean is
7076 Kind : constant Node_Kind := Nkind (N);
7079 if Kind = N_Simple_Return_Statement
7081 Kind = N_Extended_Return_Statement
7083 Kind = N_Goto_Statement
7085 Kind = N_Raise_Statement
7087 Kind = N_Requeue_Statement
7091 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7092 and then No (Condition (N))
7096 elsif Kind = N_Procedure_Call_Statement
7097 and then Is_Entity_Name (Name (N))
7098 and then Present (Entity (Name (N)))
7099 and then No_Return (Entity (Name (N)))
7103 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7115 function Is_True (U : Uint) return Boolean is
7120 -------------------------------
7121 -- Is_Universal_Numeric_Type --
7122 -------------------------------
7124 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7126 return T = Universal_Integer or else T = Universal_Real;
7127 end Is_Universal_Numeric_Type;
7133 function Is_Value_Type (T : Entity_Id) return Boolean is
7135 return VM_Target = CLI_Target
7136 and then Nkind (T) in N_Has_Chars
7137 and then Chars (T) /= No_Name
7138 and then Get_Name_String (Chars (T)) = "valuetype";
7141 ---------------------
7142 -- Is_VMS_Operator --
7143 ---------------------
7145 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7147 return Ekind (Op) = E_Function
7148 and then Is_Intrinsic_Subprogram (Op)
7149 and then Chars (Scope (Scope (Op))) = Name_System
7150 and then OpenVMS_On_Target;
7151 end Is_VMS_Operator;
7157 function Is_Variable (N : Node_Id) return Boolean is
7159 Orig_Node : constant Node_Id := Original_Node (N);
7160 -- We do the test on the original node, since this is basically a test
7161 -- of syntactic categories, so it must not be disturbed by whatever
7162 -- rewriting might have occurred. For example, an aggregate, which is
7163 -- certainly NOT a variable, could be turned into a variable by
7166 function In_Protected_Function (E : Entity_Id) return Boolean;
7167 -- Within a protected function, the private components of the
7168 -- enclosing protected type are constants. A function nested within
7169 -- a (protected) procedure is not itself protected.
7171 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7172 -- Prefixes can involve implicit dereferences, in which case we
7173 -- must test for the case of a reference of a constant access
7174 -- type, which can never be a variable.
7176 ---------------------------
7177 -- In_Protected_Function --
7178 ---------------------------
7180 function In_Protected_Function (E : Entity_Id) return Boolean is
7181 Prot : constant Entity_Id := Scope (E);
7185 if not Is_Protected_Type (Prot) then
7189 while Present (S) and then S /= Prot loop
7190 if Ekind (S) = E_Function
7191 and then Scope (S) = Prot
7201 end In_Protected_Function;
7203 ------------------------
7204 -- Is_Variable_Prefix --
7205 ------------------------
7207 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7209 if Is_Access_Type (Etype (P)) then
7210 return not Is_Access_Constant (Root_Type (Etype (P)));
7212 -- For the case of an indexed component whose prefix has a packed
7213 -- array type, the prefix has been rewritten into a type conversion.
7214 -- Determine variable-ness from the converted expression.
7216 elsif Nkind (P) = N_Type_Conversion
7217 and then not Comes_From_Source (P)
7218 and then Is_Array_Type (Etype (P))
7219 and then Is_Packed (Etype (P))
7221 return Is_Variable (Expression (P));
7224 return Is_Variable (P);
7226 end Is_Variable_Prefix;
7228 -- Start of processing for Is_Variable
7231 -- Definitely OK if Assignment_OK is set. Since this is something that
7232 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7234 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7237 -- Normally we go to the original node, but there is one exception
7238 -- where we use the rewritten node, namely when it is an explicit
7239 -- dereference. The generated code may rewrite a prefix which is an
7240 -- access type with an explicit dereference. The dereference is a
7241 -- variable, even though the original node may not be (since it could
7242 -- be a constant of the access type).
7244 -- In Ada 2005 we have a further case to consider: the prefix may be
7245 -- a function call given in prefix notation. The original node appears
7246 -- to be a selected component, but we need to examine the call.
7248 elsif Nkind (N) = N_Explicit_Dereference
7249 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7250 and then Present (Etype (Orig_Node))
7251 and then Is_Access_Type (Etype (Orig_Node))
7253 -- Note that if the prefix is an explicit dereference that does not
7254 -- come from source, we must check for a rewritten function call in
7255 -- prefixed notation before other forms of rewriting, to prevent a
7259 (Nkind (Orig_Node) = N_Function_Call
7260 and then not Is_Access_Constant (Etype (Prefix (N))))
7262 Is_Variable_Prefix (Original_Node (Prefix (N)));
7264 -- A function call is never a variable
7266 elsif Nkind (N) = N_Function_Call then
7269 -- All remaining checks use the original node
7271 elsif Is_Entity_Name (Orig_Node)
7272 and then Present (Entity (Orig_Node))
7275 E : constant Entity_Id := Entity (Orig_Node);
7276 K : constant Entity_Kind := Ekind (E);
7279 return (K = E_Variable
7280 and then Nkind (Parent (E)) /= N_Exception_Handler)
7281 or else (K = E_Component
7282 and then not In_Protected_Function (E))
7283 or else K = E_Out_Parameter
7284 or else K = E_In_Out_Parameter
7285 or else K = E_Generic_In_Out_Parameter
7287 -- Current instance of type:
7289 or else (Is_Type (E) and then In_Open_Scopes (E))
7290 or else (Is_Incomplete_Or_Private_Type (E)
7291 and then In_Open_Scopes (Full_View (E)));
7295 case Nkind (Orig_Node) is
7296 when N_Indexed_Component | N_Slice =>
7297 return Is_Variable_Prefix (Prefix (Orig_Node));
7299 when N_Selected_Component =>
7300 return Is_Variable_Prefix (Prefix (Orig_Node))
7301 and then Is_Variable (Selector_Name (Orig_Node));
7303 -- For an explicit dereference, the type of the prefix cannot
7304 -- be an access to constant or an access to subprogram.
7306 when N_Explicit_Dereference =>
7308 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7310 return Is_Access_Type (Typ)
7311 and then not Is_Access_Constant (Root_Type (Typ))
7312 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7315 -- The type conversion is the case where we do not deal with the
7316 -- context dependent special case of an actual parameter. Thus
7317 -- the type conversion is only considered a variable for the
7318 -- purposes of this routine if the target type is tagged. However,
7319 -- a type conversion is considered to be a variable if it does not
7320 -- come from source (this deals for example with the conversions
7321 -- of expressions to their actual subtypes).
7323 when N_Type_Conversion =>
7324 return Is_Variable (Expression (Orig_Node))
7326 (not Comes_From_Source (Orig_Node)
7328 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7330 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7332 -- GNAT allows an unchecked type conversion as a variable. This
7333 -- only affects the generation of internal expanded code, since
7334 -- calls to instantiations of Unchecked_Conversion are never
7335 -- considered variables (since they are function calls).
7336 -- This is also true for expression actions.
7338 when N_Unchecked_Type_Conversion =>
7339 return Is_Variable (Expression (Orig_Node));
7347 ---------------------------
7348 -- Is_Visibly_Controlled --
7349 ---------------------------
7351 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7352 Root : constant Entity_Id := Root_Type (T);
7354 return Chars (Scope (Root)) = Name_Finalization
7355 and then Chars (Scope (Scope (Root))) = Name_Ada
7356 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7357 end Is_Visibly_Controlled;
7359 ------------------------
7360 -- Is_Volatile_Object --
7361 ------------------------
7363 function Is_Volatile_Object (N : Node_Id) return Boolean is
7365 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7366 -- Determines if given object has volatile components
7368 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7369 -- If prefix is an implicit dereference, examine designated type
7371 ------------------------
7372 -- Is_Volatile_Prefix --
7373 ------------------------
7375 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7376 Typ : constant Entity_Id := Etype (N);
7379 if Is_Access_Type (Typ) then
7381 Dtyp : constant Entity_Id := Designated_Type (Typ);
7384 return Is_Volatile (Dtyp)
7385 or else Has_Volatile_Components (Dtyp);
7389 return Object_Has_Volatile_Components (N);
7391 end Is_Volatile_Prefix;
7393 ------------------------------------
7394 -- Object_Has_Volatile_Components --
7395 ------------------------------------
7397 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7398 Typ : constant Entity_Id := Etype (N);
7401 if Is_Volatile (Typ)
7402 or else Has_Volatile_Components (Typ)
7406 elsif Is_Entity_Name (N)
7407 and then (Has_Volatile_Components (Entity (N))
7408 or else Is_Volatile (Entity (N)))
7412 elsif Nkind (N) = N_Indexed_Component
7413 or else Nkind (N) = N_Selected_Component
7415 return Is_Volatile_Prefix (Prefix (N));
7420 end Object_Has_Volatile_Components;
7422 -- Start of processing for Is_Volatile_Object
7425 if Is_Volatile (Etype (N))
7426 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7430 elsif Nkind (N) = N_Indexed_Component
7431 or else Nkind (N) = N_Selected_Component
7433 return Is_Volatile_Prefix (Prefix (N));
7438 end Is_Volatile_Object;
7440 -------------------------
7441 -- Kill_Current_Values --
7442 -------------------------
7444 procedure Kill_Current_Values
7446 Last_Assignment_Only : Boolean := False)
7449 -- ??? do we have to worry about clearing cached checks?
7451 if Is_Assignable (Ent) then
7452 Set_Last_Assignment (Ent, Empty);
7455 if Is_Object (Ent) then
7456 if not Last_Assignment_Only then
7458 Set_Current_Value (Ent, Empty);
7460 if not Can_Never_Be_Null (Ent) then
7461 Set_Is_Known_Non_Null (Ent, False);
7464 Set_Is_Known_Null (Ent, False);
7466 -- Reset Is_Known_Valid unless type is always valid, or if we have
7467 -- a loop parameter (loop parameters are always valid, since their
7468 -- bounds are defined by the bounds given in the loop header).
7470 if not Is_Known_Valid (Etype (Ent))
7471 and then Ekind (Ent) /= E_Loop_Parameter
7473 Set_Is_Known_Valid (Ent, False);
7477 end Kill_Current_Values;
7479 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7482 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7483 -- Clear current value for entity E and all entities chained to E
7485 ------------------------------------------
7486 -- Kill_Current_Values_For_Entity_Chain --
7487 ------------------------------------------
7489 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7493 while Present (Ent) loop
7494 Kill_Current_Values (Ent, Last_Assignment_Only);
7497 end Kill_Current_Values_For_Entity_Chain;
7499 -- Start of processing for Kill_Current_Values
7502 -- Kill all saved checks, a special case of killing saved values
7504 if not Last_Assignment_Only then
7508 -- Loop through relevant scopes, which includes the current scope and
7509 -- any parent scopes if the current scope is a block or a package.
7514 -- Clear current values of all entities in current scope
7516 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7518 -- If scope is a package, also clear current values of all
7519 -- private entities in the scope.
7521 if Is_Package_Or_Generic_Package (S)
7522 or else Is_Concurrent_Type (S)
7524 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7527 -- If this is a not a subprogram, deal with parents
7529 if not Is_Subprogram (S) then
7531 exit Scope_Loop when S = Standard_Standard;
7535 end loop Scope_Loop;
7536 end Kill_Current_Values;
7538 --------------------------
7539 -- Kill_Size_Check_Code --
7540 --------------------------
7542 procedure Kill_Size_Check_Code (E : Entity_Id) is
7544 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7545 and then Present (Size_Check_Code (E))
7547 Remove (Size_Check_Code (E));
7548 Set_Size_Check_Code (E, Empty);
7550 end Kill_Size_Check_Code;
7552 --------------------------
7553 -- Known_To_Be_Assigned --
7554 --------------------------
7556 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7557 P : constant Node_Id := Parent (N);
7562 -- Test left side of assignment
7564 when N_Assignment_Statement =>
7565 return N = Name (P);
7567 -- Function call arguments are never lvalues
7569 when N_Function_Call =>
7572 -- Positional parameter for procedure or accept call
7574 when N_Procedure_Call_Statement |
7583 Proc := Get_Subprogram_Entity (P);
7589 -- If we are not a list member, something is strange, so
7590 -- be conservative and return False.
7592 if not Is_List_Member (N) then
7596 -- We are going to find the right formal by stepping forward
7597 -- through the formals, as we step backwards in the actuals.
7599 Form := First_Formal (Proc);
7602 -- If no formal, something is weird, so be conservative
7603 -- and return False.
7614 return Ekind (Form) /= E_In_Parameter;
7617 -- Named parameter for procedure or accept call
7619 when N_Parameter_Association =>
7625 Proc := Get_Subprogram_Entity (Parent (P));
7631 -- Loop through formals to find the one that matches
7633 Form := First_Formal (Proc);
7635 -- If no matching formal, that's peculiar, some kind of
7636 -- previous error, so return False to be conservative.
7642 -- Else test for match
7644 if Chars (Form) = Chars (Selector_Name (P)) then
7645 return Ekind (Form) /= E_In_Parameter;
7652 -- Test for appearing in a conversion that itself appears
7653 -- in an lvalue context, since this should be an lvalue.
7655 when N_Type_Conversion =>
7656 return Known_To_Be_Assigned (P);
7658 -- All other references are definitely not known to be modifications
7664 end Known_To_Be_Assigned;
7670 function May_Be_Lvalue (N : Node_Id) return Boolean is
7671 P : constant Node_Id := Parent (N);
7676 -- Test left side of assignment
7678 when N_Assignment_Statement =>
7679 return N = Name (P);
7681 -- Test prefix of component or attribute. Note that the prefix of an
7682 -- explicit or implicit dereference cannot be an l-value.
7684 when N_Attribute_Reference =>
7685 return N = Prefix (P)
7686 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7688 -- For an expanded name, the name is an lvalue if the expanded name
7689 -- is an lvalue, but the prefix is never an lvalue, since it is just
7690 -- the scope where the name is found.
7692 when N_Expanded_Name =>
7693 if N = Prefix (P) then
7694 return May_Be_Lvalue (P);
7699 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7700 -- B is a little interesting, if we have A.B := 3, there is some
7701 -- discussion as to whether B is an lvalue or not, we choose to say
7702 -- it is. Note however that A is not an lvalue if it is of an access
7703 -- type since this is an implicit dereference.
7705 when N_Selected_Component =>
7707 and then Present (Etype (N))
7708 and then Is_Access_Type (Etype (N))
7712 return May_Be_Lvalue (P);
7715 -- For an indexed component or slice, the index or slice bounds is
7716 -- never an lvalue. The prefix is an lvalue if the indexed component
7717 -- or slice is an lvalue, except if it is an access type, where we
7718 -- have an implicit dereference.
7720 when N_Indexed_Component =>
7722 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7726 return May_Be_Lvalue (P);
7729 -- Prefix of a reference is an lvalue if the reference is an lvalue
7732 return May_Be_Lvalue (P);
7734 -- Prefix of explicit dereference is never an lvalue
7736 when N_Explicit_Dereference =>
7739 -- Function call arguments are never lvalues
7741 when N_Function_Call =>
7744 -- Positional parameter for procedure, entry, or accept call
7746 when N_Procedure_Call_Statement |
7747 N_Entry_Call_Statement |
7756 Proc := Get_Subprogram_Entity (P);
7762 -- If we are not a list member, something is strange, so
7763 -- be conservative and return True.
7765 if not Is_List_Member (N) then
7769 -- We are going to find the right formal by stepping forward
7770 -- through the formals, as we step backwards in the actuals.
7772 Form := First_Formal (Proc);
7775 -- If no formal, something is weird, so be conservative
7787 return Ekind (Form) /= E_In_Parameter;
7790 -- Named parameter for procedure or accept call
7792 when N_Parameter_Association =>
7798 Proc := Get_Subprogram_Entity (Parent (P));
7804 -- Loop through formals to find the one that matches
7806 Form := First_Formal (Proc);
7808 -- If no matching formal, that's peculiar, some kind of
7809 -- previous error, so return True to be conservative.
7815 -- Else test for match
7817 if Chars (Form) = Chars (Selector_Name (P)) then
7818 return Ekind (Form) /= E_In_Parameter;
7825 -- Test for appearing in a conversion that itself appears in an
7826 -- lvalue context, since this should be an lvalue.
7828 when N_Type_Conversion =>
7829 return May_Be_Lvalue (P);
7831 -- Test for appearance in object renaming declaration
7833 when N_Object_Renaming_Declaration =>
7836 -- All other references are definitely not lvalues
7844 -----------------------
7845 -- Mark_Coextensions --
7846 -----------------------
7848 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7849 Is_Dynamic : Boolean;
7850 -- Indicates whether the context causes nested coextensions to be
7851 -- dynamic or static
7853 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7854 -- Recognize an allocator node and label it as a dynamic coextension
7856 --------------------
7857 -- Mark_Allocator --
7858 --------------------
7860 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7862 if Nkind (N) = N_Allocator then
7864 Set_Is_Dynamic_Coextension (N);
7866 Set_Is_Static_Coextension (N);
7873 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7875 -- Start of processing Mark_Coextensions
7878 case Nkind (Context_Nod) is
7879 when N_Assignment_Statement |
7880 N_Simple_Return_Statement =>
7881 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7883 when N_Object_Declaration =>
7884 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7886 -- This routine should not be called for constructs which may not
7887 -- contain coextensions.
7890 raise Program_Error;
7893 Mark_Allocators (Root_Nod);
7894 end Mark_Coextensions;
7896 ----------------------
7897 -- Needs_One_Actual --
7898 ----------------------
7900 function Needs_One_Actual (E : Entity_Id) return Boolean is
7904 if Ada_Version >= Ada_05
7905 and then Present (First_Formal (E))
7907 Formal := Next_Formal (First_Formal (E));
7908 while Present (Formal) loop
7909 if No (Default_Value (Formal)) then
7913 Next_Formal (Formal);
7921 end Needs_One_Actual;
7923 ------------------------
7924 -- New_Copy_List_Tree --
7925 ------------------------
7927 function New_Copy_List_Tree (List : List_Id) return List_Id is
7932 if List = No_List then
7939 while Present (E) loop
7940 Append (New_Copy_Tree (E), NL);
7946 end New_Copy_List_Tree;
7952 use Atree.Unchecked_Access;
7953 use Atree_Private_Part;
7955 -- Our approach here requires a two pass traversal of the tree. The
7956 -- first pass visits all nodes that eventually will be copied looking
7957 -- for defining Itypes. If any defining Itypes are found, then they are
7958 -- copied, and an entry is added to the replacement map. In the second
7959 -- phase, the tree is copied, using the replacement map to replace any
7960 -- Itype references within the copied tree.
7962 -- The following hash tables are used if the Map supplied has more
7963 -- than hash threshhold entries to speed up access to the map. If
7964 -- there are fewer entries, then the map is searched sequentially
7965 -- (because setting up a hash table for only a few entries takes
7966 -- more time than it saves.
7968 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7969 -- Hash function used for hash operations
7975 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7977 return Nat (E) mod (NCT_Header_Num'Last + 1);
7984 -- The hash table NCT_Assoc associates old entities in the table
7985 -- with their corresponding new entities (i.e. the pairs of entries
7986 -- presented in the original Map argument are Key-Element pairs).
7988 package NCT_Assoc is new Simple_HTable (
7989 Header_Num => NCT_Header_Num,
7990 Element => Entity_Id,
7991 No_Element => Empty,
7993 Hash => New_Copy_Hash,
7994 Equal => Types."=");
7996 ---------------------
7997 -- NCT_Itype_Assoc --
7998 ---------------------
8000 -- The hash table NCT_Itype_Assoc contains entries only for those
8001 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8002 -- The key is the associated node, and the element is the new node
8003 -- itself (NOT the associated node for the new node).
8005 package NCT_Itype_Assoc is new Simple_HTable (
8006 Header_Num => NCT_Header_Num,
8007 Element => Entity_Id,
8008 No_Element => Empty,
8010 Hash => New_Copy_Hash,
8011 Equal => Types."=");
8013 -- Start of processing for New_Copy_Tree function
8015 function New_Copy_Tree
8017 Map : Elist_Id := No_Elist;
8018 New_Sloc : Source_Ptr := No_Location;
8019 New_Scope : Entity_Id := Empty) return Node_Id
8021 Actual_Map : Elist_Id := Map;
8022 -- This is the actual map for the copy. It is initialized with the
8023 -- given elements, and then enlarged as required for Itypes that are
8024 -- copied during the first phase of the copy operation. The visit
8025 -- procedures add elements to this map as Itypes are encountered.
8026 -- The reason we cannot use Map directly, is that it may well be
8027 -- (and normally is) initialized to No_Elist, and if we have mapped
8028 -- entities, we have to reset it to point to a real Elist.
8030 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8031 -- Called during second phase to map entities into their corresponding
8032 -- copies using Actual_Map. If the argument is not an entity, or is not
8033 -- in Actual_Map, then it is returned unchanged.
8035 procedure Build_NCT_Hash_Tables;
8036 -- Builds hash tables (number of elements >= threshold value)
8038 function Copy_Elist_With_Replacement
8039 (Old_Elist : Elist_Id) return Elist_Id;
8040 -- Called during second phase to copy element list doing replacements
8042 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8043 -- Called during the second phase to process a copied Itype. The actual
8044 -- copy happened during the first phase (so that we could make the entry
8045 -- in the mapping), but we still have to deal with the descendents of
8046 -- the copied Itype and copy them where necessary.
8048 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8049 -- Called during second phase to copy list doing replacements
8051 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8052 -- Called during second phase to copy node doing replacements
8054 procedure Visit_Elist (E : Elist_Id);
8055 -- Called during first phase to visit all elements of an Elist
8057 procedure Visit_Field (F : Union_Id; N : Node_Id);
8058 -- Visit a single field, recursing to call Visit_Node or Visit_List
8059 -- if the field is a syntactic descendent of the current node (i.e.
8060 -- its parent is Node N).
8062 procedure Visit_Itype (Old_Itype : Entity_Id);
8063 -- Called during first phase to visit subsidiary fields of a defining
8064 -- Itype, and also create a copy and make an entry in the replacement
8065 -- map for the new copy.
8067 procedure Visit_List (L : List_Id);
8068 -- Called during first phase to visit all elements of a List
8070 procedure Visit_Node (N : Node_Or_Entity_Id);
8071 -- Called during first phase to visit a node and all its subtrees
8077 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8082 if not Has_Extension (N) or else No (Actual_Map) then
8085 elsif NCT_Hash_Tables_Used then
8086 Ent := NCT_Assoc.Get (Entity_Id (N));
8088 if Present (Ent) then
8094 -- No hash table used, do serial search
8097 E := First_Elmt (Actual_Map);
8098 while Present (E) loop
8099 if Node (E) = N then
8100 return Node (Next_Elmt (E));
8102 E := Next_Elmt (Next_Elmt (E));
8110 ---------------------------
8111 -- Build_NCT_Hash_Tables --
8112 ---------------------------
8114 procedure Build_NCT_Hash_Tables is
8118 if NCT_Hash_Table_Setup then
8120 NCT_Itype_Assoc.Reset;
8123 Elmt := First_Elmt (Actual_Map);
8124 while Present (Elmt) loop
8127 -- Get new entity, and associate old and new
8130 NCT_Assoc.Set (Ent, Node (Elmt));
8132 if Is_Type (Ent) then
8134 Anode : constant Entity_Id :=
8135 Associated_Node_For_Itype (Ent);
8138 if Present (Anode) then
8140 -- Enter a link between the associated node of the
8141 -- old Itype and the new Itype, for updating later
8142 -- when node is copied.
8144 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8152 NCT_Hash_Tables_Used := True;
8153 NCT_Hash_Table_Setup := True;
8154 end Build_NCT_Hash_Tables;
8156 ---------------------------------
8157 -- Copy_Elist_With_Replacement --
8158 ---------------------------------
8160 function Copy_Elist_With_Replacement
8161 (Old_Elist : Elist_Id) return Elist_Id
8164 New_Elist : Elist_Id;
8167 if No (Old_Elist) then
8171 New_Elist := New_Elmt_List;
8173 M := First_Elmt (Old_Elist);
8174 while Present (M) loop
8175 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8181 end Copy_Elist_With_Replacement;
8183 ---------------------------------
8184 -- Copy_Itype_With_Replacement --
8185 ---------------------------------
8187 -- This routine exactly parallels its phase one analog Visit_Itype,
8189 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8191 -- Translate Next_Entity, Scope and Etype fields, in case they
8192 -- reference entities that have been mapped into copies.
8194 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8195 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8197 if Present (New_Scope) then
8198 Set_Scope (New_Itype, New_Scope);
8200 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8203 -- Copy referenced fields
8205 if Is_Discrete_Type (New_Itype) then
8206 Set_Scalar_Range (New_Itype,
8207 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8209 elsif Has_Discriminants (Base_Type (New_Itype)) then
8210 Set_Discriminant_Constraint (New_Itype,
8211 Copy_Elist_With_Replacement
8212 (Discriminant_Constraint (New_Itype)));
8214 elsif Is_Array_Type (New_Itype) then
8215 if Present (First_Index (New_Itype)) then
8216 Set_First_Index (New_Itype,
8217 First (Copy_List_With_Replacement
8218 (List_Containing (First_Index (New_Itype)))));
8221 if Is_Packed (New_Itype) then
8222 Set_Packed_Array_Type (New_Itype,
8223 Copy_Node_With_Replacement
8224 (Packed_Array_Type (New_Itype)));
8227 end Copy_Itype_With_Replacement;
8229 --------------------------------
8230 -- Copy_List_With_Replacement --
8231 --------------------------------
8233 function Copy_List_With_Replacement
8234 (Old_List : List_Id) return List_Id
8240 if Old_List = No_List then
8244 New_List := Empty_List;
8246 E := First (Old_List);
8247 while Present (E) loop
8248 Append (Copy_Node_With_Replacement (E), New_List);
8254 end Copy_List_With_Replacement;
8256 --------------------------------
8257 -- Copy_Node_With_Replacement --
8258 --------------------------------
8260 function Copy_Node_With_Replacement
8261 (Old_Node : Node_Id) return Node_Id
8265 procedure Adjust_Named_Associations
8266 (Old_Node : Node_Id;
8267 New_Node : Node_Id);
8268 -- If a call node has named associations, these are chained through
8269 -- the First_Named_Actual, Next_Named_Actual links. These must be
8270 -- propagated separately to the new parameter list, because these
8271 -- are not syntactic fields.
8273 function Copy_Field_With_Replacement
8274 (Field : Union_Id) return Union_Id;
8275 -- Given Field, which is a field of Old_Node, return a copy of it
8276 -- if it is a syntactic field (i.e. its parent is Node), setting
8277 -- the parent of the copy to poit to New_Node. Otherwise returns
8278 -- the field (possibly mapped if it is an entity).
8280 -------------------------------
8281 -- Adjust_Named_Associations --
8282 -------------------------------
8284 procedure Adjust_Named_Associations
8285 (Old_Node : Node_Id;
8295 Old_E := First (Parameter_Associations (Old_Node));
8296 New_E := First (Parameter_Associations (New_Node));
8297 while Present (Old_E) loop
8298 if Nkind (Old_E) = N_Parameter_Association
8299 and then Present (Next_Named_Actual (Old_E))
8301 if First_Named_Actual (Old_Node)
8302 = Explicit_Actual_Parameter (Old_E)
8304 Set_First_Named_Actual
8305 (New_Node, Explicit_Actual_Parameter (New_E));
8308 -- Now scan parameter list from the beginning,to locate
8309 -- next named actual, which can be out of order.
8311 Old_Next := First (Parameter_Associations (Old_Node));
8312 New_Next := First (Parameter_Associations (New_Node));
8314 while Nkind (Old_Next) /= N_Parameter_Association
8315 or else Explicit_Actual_Parameter (Old_Next)
8316 /= Next_Named_Actual (Old_E)
8322 Set_Next_Named_Actual
8323 (New_E, Explicit_Actual_Parameter (New_Next));
8329 end Adjust_Named_Associations;
8331 ---------------------------------
8332 -- Copy_Field_With_Replacement --
8333 ---------------------------------
8335 function Copy_Field_With_Replacement
8336 (Field : Union_Id) return Union_Id
8339 if Field = Union_Id (Empty) then
8342 elsif Field in Node_Range then
8344 Old_N : constant Node_Id := Node_Id (Field);
8348 -- If syntactic field, as indicated by the parent pointer
8349 -- being set, then copy the referenced node recursively.
8351 if Parent (Old_N) = Old_Node then
8352 New_N := Copy_Node_With_Replacement (Old_N);
8354 if New_N /= Old_N then
8355 Set_Parent (New_N, New_Node);
8358 -- For semantic fields, update possible entity reference
8359 -- from the replacement map.
8362 New_N := Assoc (Old_N);
8365 return Union_Id (New_N);
8368 elsif Field in List_Range then
8370 Old_L : constant List_Id := List_Id (Field);
8374 -- If syntactic field, as indicated by the parent pointer,
8375 -- then recursively copy the entire referenced list.
8377 if Parent (Old_L) = Old_Node then
8378 New_L := Copy_List_With_Replacement (Old_L);
8379 Set_Parent (New_L, New_Node);
8381 -- For semantic list, just returned unchanged
8387 return Union_Id (New_L);
8390 -- Anything other than a list or a node is returned unchanged
8395 end Copy_Field_With_Replacement;
8397 -- Start of processing for Copy_Node_With_Replacement
8400 if Old_Node <= Empty_Or_Error then
8403 elsif Has_Extension (Old_Node) then
8404 return Assoc (Old_Node);
8407 New_Node := New_Copy (Old_Node);
8409 -- If the node we are copying is the associated node of a
8410 -- previously copied Itype, then adjust the associated node
8411 -- of the copy of that Itype accordingly.
8413 if Present (Actual_Map) then
8419 -- Case of hash table used
8421 if NCT_Hash_Tables_Used then
8422 Ent := NCT_Itype_Assoc.Get (Old_Node);
8424 if Present (Ent) then
8425 Set_Associated_Node_For_Itype (Ent, New_Node);
8428 -- Case of no hash table used
8431 E := First_Elmt (Actual_Map);
8432 while Present (E) loop
8433 if Is_Itype (Node (E))
8435 Old_Node = Associated_Node_For_Itype (Node (E))
8437 Set_Associated_Node_For_Itype
8438 (Node (Next_Elmt (E)), New_Node);
8441 E := Next_Elmt (Next_Elmt (E));
8447 -- Recursively copy descendents
8450 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8452 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8454 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8456 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8458 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8460 -- Adjust Sloc of new node if necessary
8462 if New_Sloc /= No_Location then
8463 Set_Sloc (New_Node, New_Sloc);
8465 -- If we adjust the Sloc, then we are essentially making
8466 -- a completely new node, so the Comes_From_Source flag
8467 -- should be reset to the proper default value.
8469 Nodes.Table (New_Node).Comes_From_Source :=
8470 Default_Node.Comes_From_Source;
8473 -- If the node is call and has named associations,
8474 -- set the corresponding links in the copy.
8476 if (Nkind (Old_Node) = N_Function_Call
8477 or else Nkind (Old_Node) = N_Entry_Call_Statement
8479 Nkind (Old_Node) = N_Procedure_Call_Statement)
8480 and then Present (First_Named_Actual (Old_Node))
8482 Adjust_Named_Associations (Old_Node, New_Node);
8485 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8486 -- The replacement mechanism applies to entities, and is not used
8487 -- here. Eventually we may need a more general graph-copying
8488 -- routine. For now, do a sequential search to find desired node.
8490 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8491 and then Present (First_Real_Statement (Old_Node))
8494 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8498 N1 := First (Statements (Old_Node));
8499 N2 := First (Statements (New_Node));
8501 while N1 /= Old_F loop
8506 Set_First_Real_Statement (New_Node, N2);
8511 -- All done, return copied node
8514 end Copy_Node_With_Replacement;
8520 procedure Visit_Elist (E : Elist_Id) is
8524 Elmt := First_Elmt (E);
8526 while Elmt /= No_Elmt loop
8527 Visit_Node (Node (Elmt));
8537 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8539 if F = Union_Id (Empty) then
8542 elsif F in Node_Range then
8544 -- Copy node if it is syntactic, i.e. its parent pointer is
8545 -- set to point to the field that referenced it (certain
8546 -- Itypes will also meet this criterion, which is fine, since
8547 -- these are clearly Itypes that do need to be copied, since
8548 -- we are copying their parent.)
8550 if Parent (Node_Id (F)) = N then
8551 Visit_Node (Node_Id (F));
8554 -- Another case, if we are pointing to an Itype, then we want
8555 -- to copy it if its associated node is somewhere in the tree
8558 -- Note: the exclusion of self-referential copies is just an
8559 -- optimization, since the search of the already copied list
8560 -- would catch it, but it is a common case (Etype pointing
8561 -- to itself for an Itype that is a base type).
8563 elsif Has_Extension (Node_Id (F))
8564 and then Is_Itype (Entity_Id (F))
8565 and then Node_Id (F) /= N
8571 P := Associated_Node_For_Itype (Node_Id (F));
8572 while Present (P) loop
8574 Visit_Node (Node_Id (F));
8581 -- An Itype whose parent is not being copied definitely
8582 -- should NOT be copied, since it does not belong in any
8583 -- sense to the copied subtree.
8589 elsif F in List_Range
8590 and then Parent (List_Id (F)) = N
8592 Visit_List (List_Id (F));
8601 procedure Visit_Itype (Old_Itype : Entity_Id) is
8602 New_Itype : Entity_Id;
8607 -- Itypes that describe the designated type of access to subprograms
8608 -- have the structure of subprogram declarations, with signatures,
8609 -- etc. Either we duplicate the signatures completely, or choose to
8610 -- share such itypes, which is fine because their elaboration will
8611 -- have no side effects.
8613 if Ekind (Old_Itype) = E_Subprogram_Type then
8617 New_Itype := New_Copy (Old_Itype);
8619 -- The new Itype has all the attributes of the old one, and
8620 -- we just copy the contents of the entity. However, the back-end
8621 -- needs different names for debugging purposes, so we create a
8622 -- new internal name for it in all cases.
8624 Set_Chars (New_Itype, New_Internal_Name ('T'));
8626 -- If our associated node is an entity that has already been copied,
8627 -- then set the associated node of the copy to point to the right
8628 -- copy. If we have copied an Itype that is itself the associated
8629 -- node of some previously copied Itype, then we set the right
8630 -- pointer in the other direction.
8632 if Present (Actual_Map) then
8634 -- Case of hash tables used
8636 if NCT_Hash_Tables_Used then
8638 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8640 if Present (Ent) then
8641 Set_Associated_Node_For_Itype (New_Itype, Ent);
8644 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8645 if Present (Ent) then
8646 Set_Associated_Node_For_Itype (Ent, New_Itype);
8648 -- If the hash table has no association for this Itype and
8649 -- its associated node, enter one now.
8653 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8656 -- Case of hash tables not used
8659 E := First_Elmt (Actual_Map);
8660 while Present (E) loop
8661 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8662 Set_Associated_Node_For_Itype
8663 (New_Itype, Node (Next_Elmt (E)));
8666 if Is_Type (Node (E))
8668 Old_Itype = Associated_Node_For_Itype (Node (E))
8670 Set_Associated_Node_For_Itype
8671 (Node (Next_Elmt (E)), New_Itype);
8674 E := Next_Elmt (Next_Elmt (E));
8679 if Present (Freeze_Node (New_Itype)) then
8680 Set_Is_Frozen (New_Itype, False);
8681 Set_Freeze_Node (New_Itype, Empty);
8684 -- Add new association to map
8686 if No (Actual_Map) then
8687 Actual_Map := New_Elmt_List;
8690 Append_Elmt (Old_Itype, Actual_Map);
8691 Append_Elmt (New_Itype, Actual_Map);
8693 if NCT_Hash_Tables_Used then
8694 NCT_Assoc.Set (Old_Itype, New_Itype);
8697 NCT_Table_Entries := NCT_Table_Entries + 1;
8699 if NCT_Table_Entries > NCT_Hash_Threshhold then
8700 Build_NCT_Hash_Tables;
8704 -- If a record subtype is simply copied, the entity list will be
8705 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8707 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
8708 Set_Cloned_Subtype (New_Itype, Old_Itype);
8711 -- Visit descendents that eventually get copied
8713 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8715 if Is_Discrete_Type (Old_Itype) then
8716 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8718 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8719 -- ??? This should involve call to Visit_Field
8720 Visit_Elist (Discriminant_Constraint (Old_Itype));
8722 elsif Is_Array_Type (Old_Itype) then
8723 if Present (First_Index (Old_Itype)) then
8724 Visit_Field (Union_Id (List_Containing
8725 (First_Index (Old_Itype))),
8729 if Is_Packed (Old_Itype) then
8730 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8740 procedure Visit_List (L : List_Id) is
8743 if L /= No_List then
8746 while Present (N) loop
8757 procedure Visit_Node (N : Node_Or_Entity_Id) is
8759 -- Start of processing for Visit_Node
8762 -- Handle case of an Itype, which must be copied
8764 if Has_Extension (N)
8765 and then Is_Itype (N)
8767 -- Nothing to do if already in the list. This can happen with an
8768 -- Itype entity that appears more than once in the tree.
8769 -- Note that we do not want to visit descendents in this case.
8771 -- Test for already in list when hash table is used
8773 if NCT_Hash_Tables_Used then
8774 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8778 -- Test for already in list when hash table not used
8784 if Present (Actual_Map) then
8785 E := First_Elmt (Actual_Map);
8786 while Present (E) loop
8787 if Node (E) = N then
8790 E := Next_Elmt (Next_Elmt (E));
8800 -- Visit descendents
8802 Visit_Field (Field1 (N), N);
8803 Visit_Field (Field2 (N), N);
8804 Visit_Field (Field3 (N), N);
8805 Visit_Field (Field4 (N), N);
8806 Visit_Field (Field5 (N), N);
8809 -- Start of processing for New_Copy_Tree
8814 -- See if we should use hash table
8816 if No (Actual_Map) then
8817 NCT_Hash_Tables_Used := False;
8824 NCT_Table_Entries := 0;
8826 Elmt := First_Elmt (Actual_Map);
8827 while Present (Elmt) loop
8828 NCT_Table_Entries := NCT_Table_Entries + 1;
8833 if NCT_Table_Entries > NCT_Hash_Threshhold then
8834 Build_NCT_Hash_Tables;
8836 NCT_Hash_Tables_Used := False;
8841 -- Hash table set up if required, now start phase one by visiting
8842 -- top node (we will recursively visit the descendents).
8844 Visit_Node (Source);
8846 -- Now the second phase of the copy can start. First we process
8847 -- all the mapped entities, copying their descendents.
8849 if Present (Actual_Map) then
8852 New_Itype : Entity_Id;
8854 Elmt := First_Elmt (Actual_Map);
8855 while Present (Elmt) loop
8857 New_Itype := Node (Elmt);
8858 Copy_Itype_With_Replacement (New_Itype);
8864 -- Now we can copy the actual tree
8866 return Copy_Node_With_Replacement (Source);
8869 -------------------------
8870 -- New_External_Entity --
8871 -------------------------
8873 function New_External_Entity
8874 (Kind : Entity_Kind;
8875 Scope_Id : Entity_Id;
8876 Sloc_Value : Source_Ptr;
8877 Related_Id : Entity_Id;
8879 Suffix_Index : Nat := 0;
8880 Prefix : Character := ' ') return Entity_Id
8882 N : constant Entity_Id :=
8883 Make_Defining_Identifier (Sloc_Value,
8885 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8888 Set_Ekind (N, Kind);
8889 Set_Is_Internal (N, True);
8890 Append_Entity (N, Scope_Id);
8891 Set_Public_Status (N);
8893 if Kind in Type_Kind then
8894 Init_Size_Align (N);
8898 end New_External_Entity;
8900 -------------------------
8901 -- New_Internal_Entity --
8902 -------------------------
8904 function New_Internal_Entity
8905 (Kind : Entity_Kind;
8906 Scope_Id : Entity_Id;
8907 Sloc_Value : Source_Ptr;
8908 Id_Char : Character) return Entity_Id
8910 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
8913 Set_Ekind (N, Kind);
8914 Set_Is_Internal (N, True);
8915 Append_Entity (N, Scope_Id);
8917 if Kind in Type_Kind then
8918 Init_Size_Align (N);
8922 end New_Internal_Entity;
8928 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8932 -- If we are pointing at a positional parameter, it is a member of a
8933 -- node list (the list of parameters), and the next parameter is the
8934 -- next node on the list, unless we hit a parameter association, then
8935 -- we shift to using the chain whose head is the First_Named_Actual in
8936 -- the parent, and then is threaded using the Next_Named_Actual of the
8937 -- Parameter_Association. All this fiddling is because the original node
8938 -- list is in the textual call order, and what we need is the
8939 -- declaration order.
8941 if Is_List_Member (Actual_Id) then
8942 N := Next (Actual_Id);
8944 if Nkind (N) = N_Parameter_Association then
8945 return First_Named_Actual (Parent (Actual_Id));
8951 return Next_Named_Actual (Parent (Actual_Id));
8955 procedure Next_Actual (Actual_Id : in out Node_Id) is
8957 Actual_Id := Next_Actual (Actual_Id);
8960 -----------------------
8961 -- Normalize_Actuals --
8962 -----------------------
8964 -- Chain actuals according to formals of subprogram. If there are no named
8965 -- associations, the chain is simply the list of Parameter Associations,
8966 -- since the order is the same as the declaration order. If there are named
8967 -- associations, then the First_Named_Actual field in the N_Function_Call
8968 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8969 -- node for the parameter that comes first in declaration order. The
8970 -- remaining named parameters are then chained in declaration order using
8971 -- Next_Named_Actual.
8973 -- This routine also verifies that the number of actuals is compatible with
8974 -- the number and default values of formals, but performs no type checking
8975 -- (type checking is done by the caller).
8977 -- If the matching succeeds, Success is set to True and the caller proceeds
8978 -- with type-checking. If the match is unsuccessful, then Success is set to
8979 -- False, and the caller attempts a different interpretation, if there is
8982 -- If the flag Report is on, the call is not overloaded, and a failure to
8983 -- match can be reported here, rather than in the caller.
8985 procedure Normalize_Actuals
8989 Success : out Boolean)
8991 Actuals : constant List_Id := Parameter_Associations (N);
8992 Actual : Node_Id := Empty;
8994 Last : Node_Id := Empty;
8995 First_Named : Node_Id := Empty;
8998 Formals_To_Match : Integer := 0;
8999 Actuals_To_Match : Integer := 0;
9001 procedure Chain (A : Node_Id);
9002 -- Add named actual at the proper place in the list, using the
9003 -- Next_Named_Actual link.
9005 function Reporting return Boolean;
9006 -- Determines if an error is to be reported. To report an error, we
9007 -- need Report to be True, and also we do not report errors caused
9008 -- by calls to init procs that occur within other init procs. Such
9009 -- errors must always be cascaded errors, since if all the types are
9010 -- declared correctly, the compiler will certainly build decent calls!
9016 procedure Chain (A : Node_Id) is
9020 -- Call node points to first actual in list
9022 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9025 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9029 Set_Next_Named_Actual (Last, Empty);
9036 function Reporting return Boolean is
9041 elsif not Within_Init_Proc then
9044 elsif Is_Init_Proc (Entity (Name (N))) then
9052 -- Start of processing for Normalize_Actuals
9055 if Is_Access_Type (S) then
9057 -- The name in the call is a function call that returns an access
9058 -- to subprogram. The designated type has the list of formals.
9060 Formal := First_Formal (Designated_Type (S));
9062 Formal := First_Formal (S);
9065 while Present (Formal) loop
9066 Formals_To_Match := Formals_To_Match + 1;
9067 Next_Formal (Formal);
9070 -- Find if there is a named association, and verify that no positional
9071 -- associations appear after named ones.
9073 if Present (Actuals) then
9074 Actual := First (Actuals);
9077 while Present (Actual)
9078 and then Nkind (Actual) /= N_Parameter_Association
9080 Actuals_To_Match := Actuals_To_Match + 1;
9084 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9086 -- Most common case: positional notation, no defaults
9091 elsif Actuals_To_Match > Formals_To_Match then
9093 -- Too many actuals: will not work
9096 if Is_Entity_Name (Name (N)) then
9097 Error_Msg_N ("too many arguments in call to&", Name (N));
9099 Error_Msg_N ("too many arguments in call", N);
9107 First_Named := Actual;
9109 while Present (Actual) loop
9110 if Nkind (Actual) /= N_Parameter_Association then
9112 ("positional parameters not allowed after named ones", Actual);
9117 Actuals_To_Match := Actuals_To_Match + 1;
9123 if Present (Actuals) then
9124 Actual := First (Actuals);
9127 Formal := First_Formal (S);
9128 while Present (Formal) loop
9130 -- Match the formals in order. If the corresponding actual is
9131 -- positional, nothing to do. Else scan the list of named actuals
9132 -- to find the one with the right name.
9135 and then Nkind (Actual) /= N_Parameter_Association
9138 Actuals_To_Match := Actuals_To_Match - 1;
9139 Formals_To_Match := Formals_To_Match - 1;
9142 -- For named parameters, search the list of actuals to find
9143 -- one that matches the next formal name.
9145 Actual := First_Named;
9147 while Present (Actual) loop
9148 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9151 Actuals_To_Match := Actuals_To_Match - 1;
9152 Formals_To_Match := Formals_To_Match - 1;
9160 if Ekind (Formal) /= E_In_Parameter
9161 or else No (Default_Value (Formal))
9164 if (Comes_From_Source (S)
9165 or else Sloc (S) = Standard_Location)
9166 and then Is_Overloadable (S)
9170 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9172 (Nkind (Parent (N)) = N_Function_Call
9174 Nkind (Parent (N)) = N_Parameter_Association))
9175 and then Ekind (S) /= E_Function
9177 Set_Etype (N, Etype (S));
9179 Error_Msg_Name_1 := Chars (S);
9180 Error_Msg_Sloc := Sloc (S);
9182 ("missing argument for parameter & " &
9183 "in call to % declared #", N, Formal);
9186 elsif Is_Overloadable (S) then
9187 Error_Msg_Name_1 := Chars (S);
9189 -- Point to type derivation that generated the
9192 Error_Msg_Sloc := Sloc (Parent (S));
9195 ("missing argument for parameter & " &
9196 "in call to % (inherited) #", N, Formal);
9200 ("missing argument for parameter &", N, Formal);
9208 Formals_To_Match := Formals_To_Match - 1;
9213 Next_Formal (Formal);
9216 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9223 -- Find some superfluous named actual that did not get
9224 -- attached to the list of associations.
9226 Actual := First (Actuals);
9227 while Present (Actual) loop
9228 if Nkind (Actual) = N_Parameter_Association
9229 and then Actual /= Last
9230 and then No (Next_Named_Actual (Actual))
9232 Error_Msg_N ("unmatched actual & in call",
9233 Selector_Name (Actual));
9244 end Normalize_Actuals;
9246 --------------------------------
9247 -- Note_Possible_Modification --
9248 --------------------------------
9250 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9251 Modification_Comes_From_Source : constant Boolean :=
9252 Comes_From_Source (Parent (N));
9258 -- Loop to find referenced entity, if there is one
9265 if Is_Entity_Name (Exp) then
9266 Ent := Entity (Exp);
9268 -- If the entity is missing, it is an undeclared identifier,
9269 -- and there is nothing to annotate.
9275 elsif Nkind (Exp) = N_Explicit_Dereference then
9277 P : constant Node_Id := Prefix (Exp);
9280 if Nkind (P) = N_Selected_Component
9282 Entry_Formal (Entity (Selector_Name (P))))
9284 -- Case of a reference to an entry formal
9286 Ent := Entry_Formal (Entity (Selector_Name (P)));
9288 elsif Nkind (P) = N_Identifier
9289 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9290 and then Present (Expression (Parent (Entity (P))))
9291 and then Nkind (Expression (Parent (Entity (P))))
9294 -- Case of a reference to a value on which side effects have
9297 Exp := Prefix (Expression (Parent (Entity (P))));
9306 elsif Nkind (Exp) = N_Type_Conversion
9307 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9309 Exp := Expression (Exp);
9312 elsif Nkind (Exp) = N_Slice
9313 or else Nkind (Exp) = N_Indexed_Component
9314 or else Nkind (Exp) = N_Selected_Component
9316 Exp := Prefix (Exp);
9323 -- Now look for entity being referenced
9325 if Present (Ent) then
9326 if Is_Object (Ent) then
9327 if Comes_From_Source (Exp)
9328 or else Modification_Comes_From_Source
9330 if Has_Pragma_Unmodified (Ent) then
9331 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9334 Set_Never_Set_In_Source (Ent, False);
9337 Set_Is_True_Constant (Ent, False);
9338 Set_Current_Value (Ent, Empty);
9339 Set_Is_Known_Null (Ent, False);
9341 if not Can_Never_Be_Null (Ent) then
9342 Set_Is_Known_Non_Null (Ent, False);
9345 -- Follow renaming chain
9347 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9348 and then Present (Renamed_Object (Ent))
9350 Exp := Renamed_Object (Ent);
9354 -- Generate a reference only if the assignment comes from
9355 -- source. This excludes, for example, calls to a dispatching
9356 -- assignment operation when the left-hand side is tagged.
9358 if Modification_Comes_From_Source then
9359 Generate_Reference (Ent, Exp, 'm');
9362 Check_Nested_Access (Ent);
9367 -- If we are sure this is a modification from source, and we know
9368 -- this modifies a constant, then give an appropriate warning.
9370 if Overlays_Constant (Ent)
9371 and then Modification_Comes_From_Source
9375 A : constant Node_Id := Address_Clause (Ent);
9379 Exp : constant Node_Id := Expression (A);
9381 if Nkind (Exp) = N_Attribute_Reference
9382 and then Attribute_Name (Exp) = Name_Address
9383 and then Is_Entity_Name (Prefix (Exp))
9385 Error_Msg_Sloc := Sloc (A);
9387 ("constant& may be modified via address clause#?",
9388 N, Entity (Prefix (Exp)));
9398 end Note_Possible_Modification;
9400 -------------------------
9401 -- Object_Access_Level --
9402 -------------------------
9404 function Object_Access_Level (Obj : Node_Id) return Uint is
9407 -- Returns the static accessibility level of the view denoted by Obj. Note
9408 -- that the value returned is the result of a call to Scope_Depth. Only
9409 -- scope depths associated with dynamic scopes can actually be returned.
9410 -- Since only relative levels matter for accessibility checking, the fact
9411 -- that the distance between successive levels of accessibility is not
9412 -- always one is immaterial (invariant: if level(E2) is deeper than
9413 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9415 function Reference_To (Obj : Node_Id) return Node_Id;
9416 -- An explicit dereference is created when removing side-effects from
9417 -- expressions for constraint checking purposes. In this case a local
9418 -- access type is created for it. The correct access level is that of
9419 -- the original source node. We detect this case by noting that the
9420 -- prefix of the dereference is created by an object declaration whose
9421 -- initial expression is a reference.
9427 function Reference_To (Obj : Node_Id) return Node_Id is
9428 Pref : constant Node_Id := Prefix (Obj);
9430 if Is_Entity_Name (Pref)
9431 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9432 and then Present (Expression (Parent (Entity (Pref))))
9433 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9435 return (Prefix (Expression (Parent (Entity (Pref)))));
9441 -- Start of processing for Object_Access_Level
9444 if Is_Entity_Name (Obj) then
9447 if Is_Prival (E) then
9448 E := Prival_Link (E);
9451 -- If E is a type then it denotes a current instance. For this case
9452 -- we add one to the normal accessibility level of the type to ensure
9453 -- that current instances are treated as always being deeper than
9454 -- than the level of any visible named access type (see 3.10.2(21)).
9457 return Type_Access_Level (E) + 1;
9459 elsif Present (Renamed_Object (E)) then
9460 return Object_Access_Level (Renamed_Object (E));
9462 -- Similarly, if E is a component of the current instance of a
9463 -- protected type, any instance of it is assumed to be at a deeper
9464 -- level than the type. For a protected object (whose type is an
9465 -- anonymous protected type) its components are at the same level
9466 -- as the type itself.
9468 elsif not Is_Overloadable (E)
9469 and then Ekind (Scope (E)) = E_Protected_Type
9470 and then Comes_From_Source (Scope (E))
9472 return Type_Access_Level (Scope (E)) + 1;
9475 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9478 elsif Nkind (Obj) = N_Selected_Component then
9479 if Is_Access_Type (Etype (Prefix (Obj))) then
9480 return Type_Access_Level (Etype (Prefix (Obj)));
9482 return Object_Access_Level (Prefix (Obj));
9485 elsif Nkind (Obj) = N_Indexed_Component then
9486 if Is_Access_Type (Etype (Prefix (Obj))) then
9487 return Type_Access_Level (Etype (Prefix (Obj)));
9489 return Object_Access_Level (Prefix (Obj));
9492 elsif Nkind (Obj) = N_Explicit_Dereference then
9494 -- If the prefix is a selected access discriminant then we make a
9495 -- recursive call on the prefix, which will in turn check the level
9496 -- of the prefix object of the selected discriminant.
9498 if Nkind (Prefix (Obj)) = N_Selected_Component
9499 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9501 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9503 return Object_Access_Level (Prefix (Obj));
9505 elsif not (Comes_From_Source (Obj)) then
9507 Ref : constant Node_Id := Reference_To (Obj);
9509 if Present (Ref) then
9510 return Object_Access_Level (Ref);
9512 return Type_Access_Level (Etype (Prefix (Obj)));
9517 return Type_Access_Level (Etype (Prefix (Obj)));
9520 elsif Nkind (Obj) = N_Type_Conversion
9521 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9523 return Object_Access_Level (Expression (Obj));
9525 elsif Nkind (Obj) = N_Function_Call then
9527 -- Function results are objects, so we get either the access level of
9528 -- the function or, in the case of an indirect call, the level of the
9529 -- access-to-subprogram type. (This code is used for Ada 95, but it
9530 -- looks wrong, because it seems that we should be checking the level
9531 -- of the call itself, even for Ada 95. However, using the Ada 2005
9532 -- version of the code causes regressions in several tests that are
9533 -- compiled with -gnat95. ???)
9535 if Ada_Version < Ada_05 then
9536 if Is_Entity_Name (Name (Obj)) then
9537 return Subprogram_Access_Level (Entity (Name (Obj)));
9539 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9542 -- For Ada 2005, the level of the result object of a function call is
9543 -- defined to be the level of the call's innermost enclosing master.
9544 -- We determine that by querying the depth of the innermost enclosing
9548 Return_Master_Scope_Depth_Of_Call : declare
9550 function Innermost_Master_Scope_Depth
9551 (N : Node_Id) return Uint;
9552 -- Returns the scope depth of the given node's innermost
9553 -- enclosing dynamic scope (effectively the accessibility
9554 -- level of the innermost enclosing master).
9556 ----------------------------------
9557 -- Innermost_Master_Scope_Depth --
9558 ----------------------------------
9560 function Innermost_Master_Scope_Depth
9561 (N : Node_Id) return Uint
9563 Node_Par : Node_Id := Parent (N);
9566 -- Locate the nearest enclosing node (by traversing Parents)
9567 -- that Defining_Entity can be applied to, and return the
9568 -- depth of that entity's nearest enclosing dynamic scope.
9570 while Present (Node_Par) loop
9571 case Nkind (Node_Par) is
9572 when N_Component_Declaration |
9573 N_Entry_Declaration |
9574 N_Formal_Object_Declaration |
9575 N_Formal_Type_Declaration |
9576 N_Full_Type_Declaration |
9577 N_Incomplete_Type_Declaration |
9578 N_Loop_Parameter_Specification |
9579 N_Object_Declaration |
9580 N_Protected_Type_Declaration |
9581 N_Private_Extension_Declaration |
9582 N_Private_Type_Declaration |
9583 N_Subtype_Declaration |
9584 N_Function_Specification |
9585 N_Procedure_Specification |
9586 N_Task_Type_Declaration |
9588 N_Generic_Instantiation |
9590 N_Implicit_Label_Declaration |
9591 N_Package_Declaration |
9592 N_Single_Task_Declaration |
9593 N_Subprogram_Declaration |
9594 N_Generic_Declaration |
9595 N_Renaming_Declaration |
9597 N_Formal_Subprogram_Declaration |
9598 N_Abstract_Subprogram_Declaration |
9600 N_Exception_Declaration |
9601 N_Formal_Package_Declaration |
9602 N_Number_Declaration |
9603 N_Package_Specification |
9604 N_Parameter_Specification |
9605 N_Single_Protected_Declaration |
9609 (Nearest_Dynamic_Scope
9610 (Defining_Entity (Node_Par)));
9616 Node_Par := Parent (Node_Par);
9619 pragma Assert (False);
9621 -- Should never reach the following return
9623 return Scope_Depth (Current_Scope) + 1;
9624 end Innermost_Master_Scope_Depth;
9626 -- Start of processing for Return_Master_Scope_Depth_Of_Call
9629 return Innermost_Master_Scope_Depth (Obj);
9630 end Return_Master_Scope_Depth_Of_Call;
9633 -- For convenience we handle qualified expressions, even though
9634 -- they aren't technically object names.
9636 elsif Nkind (Obj) = N_Qualified_Expression then
9637 return Object_Access_Level (Expression (Obj));
9639 -- Otherwise return the scope level of Standard.
9640 -- (If there are cases that fall through
9641 -- to this point they will be treated as
9642 -- having global accessibility for now. ???)
9645 return Scope_Depth (Standard_Standard);
9647 end Object_Access_Level;
9649 -----------------------
9650 -- Private_Component --
9651 -----------------------
9653 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9654 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9656 function Trace_Components
9658 Check : Boolean) return Entity_Id;
9659 -- Recursive function that does the work, and checks against circular
9660 -- definition for each subcomponent type.
9662 ----------------------
9663 -- Trace_Components --
9664 ----------------------
9666 function Trace_Components
9668 Check : Boolean) return Entity_Id
9670 Btype : constant Entity_Id := Base_Type (T);
9671 Component : Entity_Id;
9673 Candidate : Entity_Id := Empty;
9676 if Check and then Btype = Ancestor then
9677 Error_Msg_N ("circular type definition", Type_Id);
9681 if Is_Private_Type (Btype)
9682 and then not Is_Generic_Type (Btype)
9684 if Present (Full_View (Btype))
9685 and then Is_Record_Type (Full_View (Btype))
9686 and then not Is_Frozen (Btype)
9688 -- To indicate that the ancestor depends on a private type, the
9689 -- current Btype is sufficient. However, to check for circular
9690 -- definition we must recurse on the full view.
9692 Candidate := Trace_Components (Full_View (Btype), True);
9694 if Candidate = Any_Type then
9704 elsif Is_Array_Type (Btype) then
9705 return Trace_Components (Component_Type (Btype), True);
9707 elsif Is_Record_Type (Btype) then
9708 Component := First_Entity (Btype);
9709 while Present (Component) loop
9711 -- Skip anonymous types generated by constrained components
9713 if not Is_Type (Component) then
9714 P := Trace_Components (Etype (Component), True);
9717 if P = Any_Type then
9725 Next_Entity (Component);
9733 end Trace_Components;
9735 -- Start of processing for Private_Component
9738 return Trace_Components (Type_Id, False);
9739 end Private_Component;
9741 ---------------------------
9742 -- Primitive_Names_Match --
9743 ---------------------------
9745 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9747 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9748 -- Given an internal name, returns the corresponding non-internal name
9750 ------------------------
9751 -- Non_Internal_Name --
9752 ------------------------
9754 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9756 Get_Name_String (Chars (E));
9757 Name_Len := Name_Len - 1;
9759 end Non_Internal_Name;
9761 -- Start of processing for Primitive_Names_Match
9764 pragma Assert (Present (E1) and then Present (E2));
9766 return Chars (E1) = Chars (E2)
9768 (not Is_Internal_Name (Chars (E1))
9769 and then Is_Internal_Name (Chars (E2))
9770 and then Non_Internal_Name (E2) = Chars (E1))
9772 (not Is_Internal_Name (Chars (E2))
9773 and then Is_Internal_Name (Chars (E1))
9774 and then Non_Internal_Name (E1) = Chars (E2))
9776 (Is_Predefined_Dispatching_Operation (E1)
9777 and then Is_Predefined_Dispatching_Operation (E2)
9778 and then Same_TSS (E1, E2))
9780 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9781 end Primitive_Names_Match;
9783 -----------------------
9784 -- Process_End_Label --
9785 -----------------------
9787 procedure Process_End_Label
9796 Label_Ref : Boolean;
9797 -- Set True if reference to end label itself is required
9800 -- Gets set to the operator symbol or identifier that references the
9801 -- entity Ent. For the child unit case, this is the identifier from the
9802 -- designator. For other cases, this is simply Endl.
9804 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9805 -- N is an identifier node that appears as a parent unit reference in
9806 -- the case where Ent is a child unit. This procedure generates an
9807 -- appropriate cross-reference entry. E is the corresponding entity.
9809 -------------------------
9810 -- Generate_Parent_Ref --
9811 -------------------------
9813 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9815 -- If names do not match, something weird, skip reference
9817 if Chars (E) = Chars (N) then
9819 -- Generate the reference. We do NOT consider this as a reference
9820 -- for unreferenced symbol purposes.
9822 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9825 Style.Check_Identifier (N, E);
9828 end Generate_Parent_Ref;
9830 -- Start of processing for Process_End_Label
9833 -- If no node, ignore. This happens in some error situations, and
9834 -- also for some internally generated structures where no end label
9835 -- references are required in any case.
9841 -- Nothing to do if no End_Label, happens for internally generated
9842 -- constructs where we don't want an end label reference anyway. Also
9843 -- nothing to do if Endl is a string literal, which means there was
9844 -- some prior error (bad operator symbol)
9846 Endl := End_Label (N);
9848 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9852 -- Reference node is not in extended main source unit
9854 if not In_Extended_Main_Source_Unit (N) then
9856 -- Generally we do not collect references except for the extended
9857 -- main source unit. The one exception is the 'e' entry for a
9858 -- package spec, where it is useful for a client to have the
9859 -- ending information to define scopes.
9867 -- For this case, we can ignore any parent references, but we
9868 -- need the package name itself for the 'e' entry.
9870 if Nkind (Endl) = N_Designator then
9871 Endl := Identifier (Endl);
9875 -- Reference is in extended main source unit
9880 -- For designator, generate references for the parent entries
9882 if Nkind (Endl) = N_Designator then
9884 -- Generate references for the prefix if the END line comes from
9885 -- source (otherwise we do not need these references) We climb the
9886 -- scope stack to find the expected entities.
9888 if Comes_From_Source (Endl) then
9890 Scop := Current_Scope;
9891 while Nkind (Nam) = N_Selected_Component loop
9892 Scop := Scope (Scop);
9893 exit when No (Scop);
9894 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9895 Nam := Prefix (Nam);
9898 if Present (Scop) then
9899 Generate_Parent_Ref (Nam, Scope (Scop));
9903 Endl := Identifier (Endl);
9907 -- If the end label is not for the given entity, then either we have
9908 -- some previous error, or this is a generic instantiation for which
9909 -- we do not need to make a cross-reference in this case anyway. In
9910 -- either case we simply ignore the call.
9912 if Chars (Ent) /= Chars (Endl) then
9916 -- If label was really there, then generate a normal reference and then
9917 -- adjust the location in the end label to point past the name (which
9918 -- should almost always be the semicolon).
9922 if Comes_From_Source (Endl) then
9924 -- If a label reference is required, then do the style check and
9925 -- generate an l-type cross-reference entry for the label
9929 Style.Check_Identifier (Endl, Ent);
9932 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9935 -- Set the location to point past the label (normally this will
9936 -- mean the semicolon immediately following the label). This is
9937 -- done for the sake of the 'e' or 't' entry generated below.
9939 Get_Decoded_Name_String (Chars (Endl));
9940 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9943 -- Now generate the e/t reference
9945 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9947 -- Restore Sloc, in case modified above, since we have an identifier
9948 -- and the normal Sloc should be left set in the tree.
9950 Set_Sloc (Endl, Loc);
9951 end Process_End_Label;
9957 -- We do the conversion to get the value of the real string by using
9958 -- the scanner, see Sinput for details on use of the internal source
9959 -- buffer for scanning internal strings.
9961 function Real_Convert (S : String) return Node_Id is
9962 Save_Src : constant Source_Buffer_Ptr := Source;
9966 Source := Internal_Source_Ptr;
9969 for J in S'Range loop
9970 Source (Source_Ptr (J)) := S (J);
9973 Source (S'Length + 1) := EOF;
9975 if Source (Scan_Ptr) = '-' then
9977 Scan_Ptr := Scan_Ptr + 1;
9985 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9992 ------------------------------------
9993 -- References_Generic_Formal_Type --
9994 ------------------------------------
9996 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
9998 function Process (N : Node_Id) return Traverse_Result;
9999 -- Process one node in search for generic formal type
10005 function Process (N : Node_Id) return Traverse_Result is
10007 if Nkind (N) in N_Has_Entity then
10009 E : constant Entity_Id := Entity (N);
10011 if Present (E) then
10012 if Is_Generic_Type (E) then
10014 elsif Present (Etype (E))
10015 and then Is_Generic_Type (Etype (E))
10026 function Traverse is new Traverse_Func (Process);
10027 -- Traverse tree to look for generic type
10030 if Inside_A_Generic then
10031 return Traverse (N) = Abandon;
10035 end References_Generic_Formal_Type;
10037 --------------------
10038 -- Remove_Homonym --
10039 --------------------
10041 procedure Remove_Homonym (E : Entity_Id) is
10042 Prev : Entity_Id := Empty;
10046 if E = Current_Entity (E) then
10047 if Present (Homonym (E)) then
10048 Set_Current_Entity (Homonym (E));
10050 Set_Name_Entity_Id (Chars (E), Empty);
10053 H := Current_Entity (E);
10054 while Present (H) and then H /= E loop
10059 Set_Homonym (Prev, Homonym (E));
10061 end Remove_Homonym;
10063 ---------------------
10064 -- Rep_To_Pos_Flag --
10065 ---------------------
10067 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10069 return New_Occurrence_Of
10070 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10071 end Rep_To_Pos_Flag;
10073 --------------------
10074 -- Require_Entity --
10075 --------------------
10077 procedure Require_Entity (N : Node_Id) is
10079 if Is_Entity_Name (N) and then No (Entity (N)) then
10080 if Total_Errors_Detected /= 0 then
10081 Set_Entity (N, Any_Id);
10083 raise Program_Error;
10086 end Require_Entity;
10088 ------------------------------
10089 -- Requires_Transient_Scope --
10090 ------------------------------
10092 -- A transient scope is required when variable-sized temporaries are
10093 -- allocated in the primary or secondary stack, or when finalization
10094 -- actions must be generated before the next instruction.
10096 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10097 Typ : constant Entity_Id := Underlying_Type (Id);
10099 -- Start of processing for Requires_Transient_Scope
10102 -- This is a private type which is not completed yet. This can only
10103 -- happen in a default expression (of a formal parameter or of a
10104 -- record component). Do not expand transient scope in this case
10109 -- Do not expand transient scope for non-existent procedure return
10111 elsif Typ = Standard_Void_Type then
10114 -- Elementary types do not require a transient scope
10116 elsif Is_Elementary_Type (Typ) then
10119 -- Generally, indefinite subtypes require a transient scope, since the
10120 -- back end cannot generate temporaries, since this is not a valid type
10121 -- for declaring an object. It might be possible to relax this in the
10122 -- future, e.g. by declaring the maximum possible space for the type.
10124 elsif Is_Indefinite_Subtype (Typ) then
10127 -- Functions returning tagged types may dispatch on result so their
10128 -- returned value is allocated on the secondary stack. Controlled
10129 -- type temporaries need finalization.
10131 elsif Is_Tagged_Type (Typ)
10132 or else Has_Controlled_Component (Typ)
10134 return not Is_Value_Type (Typ);
10138 elsif Is_Record_Type (Typ) then
10142 Comp := First_Entity (Typ);
10143 while Present (Comp) loop
10144 if Ekind (Comp) = E_Component
10145 and then Requires_Transient_Scope (Etype (Comp))
10149 Next_Entity (Comp);
10156 -- String literal types never require transient scope
10158 elsif Ekind (Typ) = E_String_Literal_Subtype then
10161 -- Array type. Note that we already know that this is a constrained
10162 -- array, since unconstrained arrays will fail the indefinite test.
10164 elsif Is_Array_Type (Typ) then
10166 -- If component type requires a transient scope, the array does too
10168 if Requires_Transient_Scope (Component_Type (Typ)) then
10171 -- Otherwise, we only need a transient scope if the size is not
10172 -- known at compile time.
10175 return not Size_Known_At_Compile_Time (Typ);
10178 -- All other cases do not require a transient scope
10183 end Requires_Transient_Scope;
10185 --------------------------
10186 -- Reset_Analyzed_Flags --
10187 --------------------------
10189 procedure Reset_Analyzed_Flags (N : Node_Id) is
10191 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10192 -- Function used to reset Analyzed flags in tree. Note that we do
10193 -- not reset Analyzed flags in entities, since there is no need to
10194 -- reanalyze entities, and indeed, it is wrong to do so, since it
10195 -- can result in generating auxiliary stuff more than once.
10197 --------------------
10198 -- Clear_Analyzed --
10199 --------------------
10201 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10203 if not Has_Extension (N) then
10204 Set_Analyzed (N, False);
10208 end Clear_Analyzed;
10210 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10212 -- Start of processing for Reset_Analyzed_Flags
10215 Reset_Analyzed (N);
10216 end Reset_Analyzed_Flags;
10218 ---------------------------
10219 -- Safe_To_Capture_Value --
10220 ---------------------------
10222 function Safe_To_Capture_Value
10225 Cond : Boolean := False) return Boolean
10228 -- The only entities for which we track constant values are variables
10229 -- which are not renamings, constants, out parameters, and in out
10230 -- parameters, so check if we have this case.
10232 -- Note: it may seem odd to track constant values for constants, but in
10233 -- fact this routine is used for other purposes than simply capturing
10234 -- the value. In particular, the setting of Known[_Non]_Null.
10236 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10238 Ekind (Ent) = E_Constant
10240 Ekind (Ent) = E_Out_Parameter
10242 Ekind (Ent) = E_In_Out_Parameter
10246 -- For conditionals, we also allow loop parameters and all formals,
10247 -- including in parameters.
10251 (Ekind (Ent) = E_Loop_Parameter
10253 Ekind (Ent) = E_In_Parameter)
10257 -- For all other cases, not just unsafe, but impossible to capture
10258 -- Current_Value, since the above are the only entities which have
10259 -- Current_Value fields.
10265 -- Skip if volatile or aliased, since funny things might be going on in
10266 -- these cases which we cannot necessarily track. Also skip any variable
10267 -- for which an address clause is given, or whose address is taken. Also
10268 -- never capture value of library level variables (an attempt to do so
10269 -- can occur in the case of package elaboration code).
10271 if Treat_As_Volatile (Ent)
10272 or else Is_Aliased (Ent)
10273 or else Present (Address_Clause (Ent))
10274 or else Address_Taken (Ent)
10275 or else (Is_Library_Level_Entity (Ent)
10276 and then Ekind (Ent) = E_Variable)
10281 -- OK, all above conditions are met. We also require that the scope of
10282 -- the reference be the same as the scope of the entity, not counting
10283 -- packages and blocks and loops.
10286 E_Scope : constant Entity_Id := Scope (Ent);
10287 R_Scope : Entity_Id;
10290 R_Scope := Current_Scope;
10291 while R_Scope /= Standard_Standard loop
10292 exit when R_Scope = E_Scope;
10294 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10297 R_Scope := Scope (R_Scope);
10302 -- We also require that the reference does not appear in a context
10303 -- where it is not sure to be executed (i.e. a conditional context
10304 -- or an exception handler). We skip this if Cond is True, since the
10305 -- capturing of values from conditional tests handles this ok.
10319 while Present (P) loop
10320 if Nkind (P) = N_If_Statement
10321 or else Nkind (P) = N_Case_Statement
10322 or else (Nkind (P) in N_Short_Circuit
10323 and then Desc = Right_Opnd (P))
10324 or else (Nkind (P) = N_Conditional_Expression
10325 and then Desc /= First (Expressions (P)))
10326 or else Nkind (P) = N_Exception_Handler
10327 or else Nkind (P) = N_Selective_Accept
10328 or else Nkind (P) = N_Conditional_Entry_Call
10329 or else Nkind (P) = N_Timed_Entry_Call
10330 or else Nkind (P) = N_Asynchronous_Select
10340 -- OK, looks safe to set value
10343 end Safe_To_Capture_Value;
10349 function Same_Name (N1, N2 : Node_Id) return Boolean is
10350 K1 : constant Node_Kind := Nkind (N1);
10351 K2 : constant Node_Kind := Nkind (N2);
10354 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10355 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10357 return Chars (N1) = Chars (N2);
10359 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10360 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10362 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10363 and then Same_Name (Prefix (N1), Prefix (N2));
10374 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10375 N1 : constant Node_Id := Original_Node (Node1);
10376 N2 : constant Node_Id := Original_Node (Node2);
10377 -- We do the tests on original nodes, since we are most interested
10378 -- in the original source, not any expansion that got in the way.
10380 K1 : constant Node_Kind := Nkind (N1);
10381 K2 : constant Node_Kind := Nkind (N2);
10384 -- First case, both are entities with same entity
10386 if K1 in N_Has_Entity
10387 and then K2 in N_Has_Entity
10388 and then Present (Entity (N1))
10389 and then Present (Entity (N2))
10390 and then (Ekind (Entity (N1)) = E_Variable
10392 Ekind (Entity (N1)) = E_Constant)
10393 and then Entity (N1) = Entity (N2)
10397 -- Second case, selected component with same selector, same record
10399 elsif K1 = N_Selected_Component
10400 and then K2 = N_Selected_Component
10401 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10403 return Same_Object (Prefix (N1), Prefix (N2));
10405 -- Third case, indexed component with same subscripts, same array
10407 elsif K1 = N_Indexed_Component
10408 and then K2 = N_Indexed_Component
10409 and then Same_Object (Prefix (N1), Prefix (N2))
10414 E1 := First (Expressions (N1));
10415 E2 := First (Expressions (N2));
10416 while Present (E1) loop
10417 if not Same_Value (E1, E2) then
10428 -- Fourth case, slice of same array with same bounds
10431 and then K2 = N_Slice
10432 and then Nkind (Discrete_Range (N1)) = N_Range
10433 and then Nkind (Discrete_Range (N2)) = N_Range
10434 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10435 Low_Bound (Discrete_Range (N2)))
10436 and then Same_Value (High_Bound (Discrete_Range (N1)),
10437 High_Bound (Discrete_Range (N2)))
10439 return Same_Name (Prefix (N1), Prefix (N2));
10441 -- All other cases, not clearly the same object
10452 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10457 elsif not Is_Constrained (T1)
10458 and then not Is_Constrained (T2)
10459 and then Base_Type (T1) = Base_Type (T2)
10463 -- For now don't bother with case of identical constraints, to be
10464 -- fiddled with later on perhaps (this is only used for optimization
10465 -- purposes, so it is not critical to do a best possible job)
10476 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10478 if Compile_Time_Known_Value (Node1)
10479 and then Compile_Time_Known_Value (Node2)
10480 and then Expr_Value (Node1) = Expr_Value (Node2)
10483 elsif Same_Object (Node1, Node2) then
10490 ------------------------
10491 -- Scope_Is_Transient --
10492 ------------------------
10494 function Scope_Is_Transient return Boolean is
10496 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10497 end Scope_Is_Transient;
10503 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10508 while Scop /= Standard_Standard loop
10509 Scop := Scope (Scop);
10511 if Scop = Scope2 then
10519 --------------------------
10520 -- Scope_Within_Or_Same --
10521 --------------------------
10523 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10528 while Scop /= Standard_Standard loop
10529 if Scop = Scope2 then
10532 Scop := Scope (Scop);
10537 end Scope_Within_Or_Same;
10539 --------------------
10540 -- Set_Convention --
10541 --------------------
10543 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10545 Basic_Set_Convention (E, Val);
10548 and then Is_Access_Subprogram_Type (Base_Type (E))
10549 and then Has_Foreign_Convention (E)
10551 Set_Can_Use_Internal_Rep (E, False);
10553 end Set_Convention;
10555 ------------------------
10556 -- Set_Current_Entity --
10557 ------------------------
10559 -- The given entity is to be set as the currently visible definition
10560 -- of its associated name (i.e. the Node_Id associated with its name).
10561 -- All we have to do is to get the name from the identifier, and
10562 -- then set the associated Node_Id to point to the given entity.
10564 procedure Set_Current_Entity (E : Entity_Id) is
10566 Set_Name_Entity_Id (Chars (E), E);
10567 end Set_Current_Entity;
10569 ---------------------------
10570 -- Set_Debug_Info_Needed --
10571 ---------------------------
10573 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10575 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10576 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10577 -- Used to set debug info in a related node if not set already
10579 --------------------------------------
10580 -- Set_Debug_Info_Needed_If_Not_Set --
10581 --------------------------------------
10583 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10586 and then not Needs_Debug_Info (E)
10588 Set_Debug_Info_Needed (E);
10590 -- For a private type, indicate that the full view also needs
10591 -- debug information.
10594 and then Is_Private_Type (E)
10595 and then Present (Full_View (E))
10597 Set_Debug_Info_Needed (Full_View (E));
10600 end Set_Debug_Info_Needed_If_Not_Set;
10602 -- Start of processing for Set_Debug_Info_Needed
10605 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10606 -- indicates that Debug_Info_Needed is never required for the entity.
10609 or else Debug_Info_Off (T)
10614 -- Set flag in entity itself. Note that we will go through the following
10615 -- circuitry even if the flag is already set on T. That's intentional,
10616 -- it makes sure that the flag will be set in subsidiary entities.
10618 Set_Needs_Debug_Info (T);
10620 -- Set flag on subsidiary entities if not set already
10622 if Is_Object (T) then
10623 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10625 elsif Is_Type (T) then
10626 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10628 if Is_Record_Type (T) then
10630 Ent : Entity_Id := First_Entity (T);
10632 while Present (Ent) loop
10633 Set_Debug_Info_Needed_If_Not_Set (Ent);
10638 -- For a class wide subtype, we also need debug information
10639 -- for the equivalent type.
10641 if Ekind (T) = E_Class_Wide_Subtype then
10642 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10645 elsif Is_Array_Type (T) then
10646 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10649 Indx : Node_Id := First_Index (T);
10651 while Present (Indx) loop
10652 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10653 Indx := Next_Index (Indx);
10657 if Is_Packed (T) then
10658 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10661 elsif Is_Access_Type (T) then
10662 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10664 elsif Is_Private_Type (T) then
10665 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10667 elsif Is_Protected_Type (T) then
10668 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10671 end Set_Debug_Info_Needed;
10673 ---------------------------------
10674 -- Set_Entity_With_Style_Check --
10675 ---------------------------------
10677 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10678 Val_Actual : Entity_Id;
10682 Set_Entity (N, Val);
10685 and then not Suppress_Style_Checks (Val)
10686 and then not In_Instance
10688 if Nkind (N) = N_Identifier then
10690 elsif Nkind (N) = N_Expanded_Name then
10691 Nod := Selector_Name (N);
10696 -- A special situation arises for derived operations, where we want
10697 -- to do the check against the parent (since the Sloc of the derived
10698 -- operation points to the derived type declaration itself).
10701 while not Comes_From_Source (Val_Actual)
10702 and then Nkind (Val_Actual) in N_Entity
10703 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10704 or else Is_Subprogram (Val_Actual)
10705 or else Is_Generic_Subprogram (Val_Actual))
10706 and then Present (Alias (Val_Actual))
10708 Val_Actual := Alias (Val_Actual);
10711 -- Renaming declarations for generic actuals do not come from source,
10712 -- and have a different name from that of the entity they rename, so
10713 -- there is no style check to perform here.
10715 if Chars (Nod) = Chars (Val_Actual) then
10716 Style.Check_Identifier (Nod, Val_Actual);
10720 Set_Entity (N, Val);
10721 end Set_Entity_With_Style_Check;
10723 ------------------------
10724 -- Set_Name_Entity_Id --
10725 ------------------------
10727 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10729 Set_Name_Table_Info (Id, Int (Val));
10730 end Set_Name_Entity_Id;
10732 ---------------------
10733 -- Set_Next_Actual --
10734 ---------------------
10736 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10738 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10739 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10741 end Set_Next_Actual;
10743 ----------------------------------
10744 -- Set_Optimize_Alignment_Flags --
10745 ----------------------------------
10747 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10749 if Optimize_Alignment = 'S' then
10750 Set_Optimize_Alignment_Space (E);
10751 elsif Optimize_Alignment = 'T' then
10752 Set_Optimize_Alignment_Time (E);
10754 end Set_Optimize_Alignment_Flags;
10756 -----------------------
10757 -- Set_Public_Status --
10758 -----------------------
10760 procedure Set_Public_Status (Id : Entity_Id) is
10761 S : constant Entity_Id := Current_Scope;
10763 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10764 -- Determines if E is defined within handled statement sequence or
10765 -- an if statement, returns True if so, False otherwise.
10767 ----------------------
10768 -- Within_HSS_Or_If --
10769 ----------------------
10771 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10774 N := Declaration_Node (E);
10781 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10787 end Within_HSS_Or_If;
10789 -- Start of processing for Set_Public_Status
10792 -- Everything in the scope of Standard is public
10794 if S = Standard_Standard then
10795 Set_Is_Public (Id);
10797 -- Entity is definitely not public if enclosing scope is not public
10799 elsif not Is_Public (S) then
10802 -- An object or function declaration that occurs in a handled sequence
10803 -- of statements or within an if statement is the declaration for a
10804 -- temporary object or local subprogram generated by the expander. It
10805 -- never needs to be made public and furthermore, making it public can
10806 -- cause back end problems.
10808 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10809 N_Function_Specification)
10810 and then Within_HSS_Or_If (Id)
10814 -- Entities in public packages or records are public
10816 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10817 Set_Is_Public (Id);
10819 -- The bounds of an entry family declaration can generate object
10820 -- declarations that are visible to the back-end, e.g. in the
10821 -- the declaration of a composite type that contains tasks.
10823 elsif Is_Concurrent_Type (S)
10824 and then not Has_Completion (S)
10825 and then Nkind (Parent (Id)) = N_Object_Declaration
10827 Set_Is_Public (Id);
10829 end Set_Public_Status;
10831 -----------------------------
10832 -- Set_Referenced_Modified --
10833 -----------------------------
10835 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10839 -- Deal with indexed or selected component where prefix is modified
10841 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
10842 Pref := Prefix (N);
10844 -- If prefix is access type, then it is the designated object that is
10845 -- being modified, which means we have no entity to set the flag on.
10847 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10850 -- Otherwise chase the prefix
10853 Set_Referenced_Modified (Pref, Out_Param);
10856 -- Otherwise see if we have an entity name (only other case to process)
10858 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10859 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10860 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10862 end Set_Referenced_Modified;
10864 ----------------------------
10865 -- Set_Scope_Is_Transient --
10866 ----------------------------
10868 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10870 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10871 end Set_Scope_Is_Transient;
10873 -------------------
10874 -- Set_Size_Info --
10875 -------------------
10877 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10879 -- We copy Esize, but not RM_Size, since in general RM_Size is
10880 -- subtype specific and does not get inherited by all subtypes.
10882 Set_Esize (T1, Esize (T2));
10883 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10885 if Is_Discrete_Or_Fixed_Point_Type (T1)
10887 Is_Discrete_Or_Fixed_Point_Type (T2)
10889 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10892 Set_Alignment (T1, Alignment (T2));
10895 --------------------
10896 -- Static_Integer --
10897 --------------------
10899 function Static_Integer (N : Node_Id) return Uint is
10901 Analyze_And_Resolve (N, Any_Integer);
10904 or else Error_Posted (N)
10905 or else Etype (N) = Any_Type
10910 if Is_Static_Expression (N) then
10911 if not Raises_Constraint_Error (N) then
10912 return Expr_Value (N);
10917 elsif Etype (N) = Any_Type then
10921 Flag_Non_Static_Expr
10922 ("static integer expression required here", N);
10925 end Static_Integer;
10927 --------------------------
10928 -- Statically_Different --
10929 --------------------------
10931 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10932 R1 : constant Node_Id := Get_Referenced_Object (E1);
10933 R2 : constant Node_Id := Get_Referenced_Object (E2);
10935 return Is_Entity_Name (R1)
10936 and then Is_Entity_Name (R2)
10937 and then Entity (R1) /= Entity (R2)
10938 and then not Is_Formal (Entity (R1))
10939 and then not Is_Formal (Entity (R2));
10940 end Statically_Different;
10942 -----------------------------
10943 -- Subprogram_Access_Level --
10944 -----------------------------
10946 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10948 if Present (Alias (Subp)) then
10949 return Subprogram_Access_Level (Alias (Subp));
10951 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10953 end Subprogram_Access_Level;
10959 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10961 if Debug_Flag_W then
10962 for J in 0 .. Scope_Stack.Last loop
10967 Write_Name (Chars (E));
10968 Write_Str (" from ");
10969 Write_Location (Sloc (N));
10974 -----------------------
10975 -- Transfer_Entities --
10976 -----------------------
10978 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10979 Ent : Entity_Id := First_Entity (From);
10986 if (Last_Entity (To)) = Empty then
10987 Set_First_Entity (To, Ent);
10989 Set_Next_Entity (Last_Entity (To), Ent);
10992 Set_Last_Entity (To, Last_Entity (From));
10994 while Present (Ent) loop
10995 Set_Scope (Ent, To);
10997 if not Is_Public (Ent) then
10998 Set_Public_Status (Ent);
11001 and then Ekind (Ent) = E_Record_Subtype
11004 -- The components of the propagated Itype must be public
11010 Comp := First_Entity (Ent);
11011 while Present (Comp) loop
11012 Set_Is_Public (Comp);
11013 Next_Entity (Comp);
11022 Set_First_Entity (From, Empty);
11023 Set_Last_Entity (From, Empty);
11024 end Transfer_Entities;
11026 -----------------------
11027 -- Type_Access_Level --
11028 -----------------------
11030 function Type_Access_Level (Typ : Entity_Id) return Uint is
11034 Btyp := Base_Type (Typ);
11036 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11037 -- simply use the level where the type is declared. This is true for
11038 -- stand-alone object declarations, and for anonymous access types
11039 -- associated with components the level is the same as that of the
11040 -- enclosing composite type. However, special treatment is needed for
11041 -- the cases of access parameters, return objects of an anonymous access
11042 -- type, and, in Ada 95, access discriminants of limited types.
11044 if Ekind (Btyp) in Access_Kind then
11045 if Ekind (Btyp) = E_Anonymous_Access_Type then
11047 -- If the type is a nonlocal anonymous access type (such as for
11048 -- an access parameter) we treat it as being declared at the
11049 -- library level to ensure that names such as X.all'access don't
11050 -- fail static accessibility checks.
11052 if not Is_Local_Anonymous_Access (Typ) then
11053 return Scope_Depth (Standard_Standard);
11055 -- If this is a return object, the accessibility level is that of
11056 -- the result subtype of the enclosing function. The test here is
11057 -- little complicated, because we have to account for extended
11058 -- return statements that have been rewritten as blocks, in which
11059 -- case we have to find and the Is_Return_Object attribute of the
11060 -- itype's associated object. It would be nice to find a way to
11061 -- simplify this test, but it doesn't seem worthwhile to add a new
11062 -- flag just for purposes of this test. ???
11064 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11067 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11068 N_Object_Declaration
11069 and then Is_Return_Object
11070 (Defining_Identifier
11071 (Associated_Node_For_Itype (Btyp))))
11077 Scop := Scope (Scope (Btyp));
11078 while Present (Scop) loop
11079 exit when Ekind (Scop) = E_Function;
11080 Scop := Scope (Scop);
11083 -- Treat the return object's type as having the level of the
11084 -- function's result subtype (as per RM05-6.5(5.3/2)).
11086 return Type_Access_Level (Etype (Scop));
11091 Btyp := Root_Type (Btyp);
11093 -- The accessibility level of anonymous access types associated with
11094 -- discriminants is that of the current instance of the type, and
11095 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11097 -- AI-402: access discriminants have accessibility based on the
11098 -- object rather than the type in Ada 2005, so the above paragraph
11101 -- ??? Needs completion with rules from AI-416
11103 if Ada_Version <= Ada_95
11104 and then Ekind (Typ) = E_Anonymous_Access_Type
11105 and then Present (Associated_Node_For_Itype (Typ))
11106 and then Nkind (Associated_Node_For_Itype (Typ)) =
11107 N_Discriminant_Specification
11109 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11113 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11114 end Type_Access_Level;
11116 --------------------------
11117 -- Unit_Declaration_Node --
11118 --------------------------
11120 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11121 N : Node_Id := Parent (Unit_Id);
11124 -- Predefined operators do not have a full function declaration
11126 if Ekind (Unit_Id) = E_Operator then
11130 -- Isn't there some better way to express the following ???
11132 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11133 and then Nkind (N) /= N_Formal_Package_Declaration
11134 and then Nkind (N) /= N_Function_Instantiation
11135 and then Nkind (N) /= N_Generic_Package_Declaration
11136 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11137 and then Nkind (N) /= N_Package_Declaration
11138 and then Nkind (N) /= N_Package_Body
11139 and then Nkind (N) /= N_Package_Instantiation
11140 and then Nkind (N) /= N_Package_Renaming_Declaration
11141 and then Nkind (N) /= N_Procedure_Instantiation
11142 and then Nkind (N) /= N_Protected_Body
11143 and then Nkind (N) /= N_Subprogram_Declaration
11144 and then Nkind (N) /= N_Subprogram_Body
11145 and then Nkind (N) /= N_Subprogram_Body_Stub
11146 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11147 and then Nkind (N) /= N_Task_Body
11148 and then Nkind (N) /= N_Task_Type_Declaration
11149 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11150 and then Nkind (N) not in N_Generic_Renaming_Declaration
11153 pragma Assert (Present (N));
11157 end Unit_Declaration_Node;
11159 ------------------------------
11160 -- Universal_Interpretation --
11161 ------------------------------
11163 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11164 Index : Interp_Index;
11168 -- The argument may be a formal parameter of an operator or subprogram
11169 -- with multiple interpretations, or else an expression for an actual.
11171 if Nkind (Opnd) = N_Defining_Identifier
11172 or else not Is_Overloaded (Opnd)
11174 if Etype (Opnd) = Universal_Integer
11175 or else Etype (Opnd) = Universal_Real
11177 return Etype (Opnd);
11183 Get_First_Interp (Opnd, Index, It);
11184 while Present (It.Typ) loop
11185 if It.Typ = Universal_Integer
11186 or else It.Typ = Universal_Real
11191 Get_Next_Interp (Index, It);
11196 end Universal_Interpretation;
11202 function Unqualify (Expr : Node_Id) return Node_Id is
11204 -- Recurse to handle unlikely case of multiple levels of qualification
11206 if Nkind (Expr) = N_Qualified_Expression then
11207 return Unqualify (Expression (Expr));
11209 -- Normal case, not a qualified expression
11216 ----------------------
11217 -- Within_Init_Proc --
11218 ----------------------
11220 function Within_Init_Proc return Boolean is
11224 S := Current_Scope;
11225 while not Is_Overloadable (S) loop
11226 if S = Standard_Standard then
11233 return Is_Init_Proc (S);
11234 end Within_Init_Proc;
11240 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11241 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11242 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11244 function Has_One_Matching_Field return Boolean;
11245 -- Determines if Expec_Type is a record type with a single component or
11246 -- discriminant whose type matches the found type or is one dimensional
11247 -- array whose component type matches the found type.
11249 ----------------------------
11250 -- Has_One_Matching_Field --
11251 ----------------------------
11253 function Has_One_Matching_Field return Boolean is
11257 if Is_Array_Type (Expec_Type)
11258 and then Number_Dimensions (Expec_Type) = 1
11260 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11264 elsif not Is_Record_Type (Expec_Type) then
11268 E := First_Entity (Expec_Type);
11273 elsif (Ekind (E) /= E_Discriminant
11274 and then Ekind (E) /= E_Component)
11275 or else (Chars (E) = Name_uTag
11276 or else Chars (E) = Name_uParent)
11285 if not Covers (Etype (E), Found_Type) then
11288 elsif Present (Next_Entity (E)) then
11295 end Has_One_Matching_Field;
11297 -- Start of processing for Wrong_Type
11300 -- Don't output message if either type is Any_Type, or if a message
11301 -- has already been posted for this node. We need to do the latter
11302 -- check explicitly (it is ordinarily done in Errout), because we
11303 -- are using ! to force the output of the error messages.
11305 if Expec_Type = Any_Type
11306 or else Found_Type = Any_Type
11307 or else Error_Posted (Expr)
11311 -- In an instance, there is an ongoing problem with completion of
11312 -- type derived from private types. Their structure is what Gigi
11313 -- expects, but the Etype is the parent type rather than the
11314 -- derived private type itself. Do not flag error in this case. The
11315 -- private completion is an entity without a parent, like an Itype.
11316 -- Similarly, full and partial views may be incorrect in the instance.
11317 -- There is no simple way to insure that it is consistent ???
11319 elsif In_Instance then
11320 if Etype (Etype (Expr)) = Etype (Expected_Type)
11322 (Has_Private_Declaration (Expected_Type)
11323 or else Has_Private_Declaration (Etype (Expr)))
11324 and then No (Parent (Expected_Type))
11330 -- An interesting special check. If the expression is parenthesized
11331 -- and its type corresponds to the type of the sole component of the
11332 -- expected record type, or to the component type of the expected one
11333 -- dimensional array type, then assume we have a bad aggregate attempt.
11335 if Nkind (Expr) in N_Subexpr
11336 and then Paren_Count (Expr) /= 0
11337 and then Has_One_Matching_Field
11339 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11341 -- Another special check, if we are looking for a pool-specific access
11342 -- type and we found an E_Access_Attribute_Type, then we have the case
11343 -- of an Access attribute being used in a context which needs a pool-
11344 -- specific type, which is never allowed. The one extra check we make
11345 -- is that the expected designated type covers the Found_Type.
11347 elsif Is_Access_Type (Expec_Type)
11348 and then Ekind (Found_Type) = E_Access_Attribute_Type
11349 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11350 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11352 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11354 Error_Msg_N -- CODEFIX
11355 ("result must be general access type!", Expr);
11356 Error_Msg_NE -- CODEFIX
11357 ("add ALL to }!", Expr, Expec_Type);
11359 -- Another special check, if the expected type is an integer type,
11360 -- but the expression is of type System.Address, and the parent is
11361 -- an addition or subtraction operation whose left operand is the
11362 -- expression in question and whose right operand is of an integral
11363 -- type, then this is an attempt at address arithmetic, so give
11364 -- appropriate message.
11366 elsif Is_Integer_Type (Expec_Type)
11367 and then Is_RTE (Found_Type, RE_Address)
11368 and then (Nkind (Parent (Expr)) = N_Op_Add
11370 Nkind (Parent (Expr)) = N_Op_Subtract)
11371 and then Expr = Left_Opnd (Parent (Expr))
11372 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11375 ("address arithmetic not predefined in package System",
11378 ("\possible missing with/use of System.Storage_Elements",
11382 -- If the expected type is an anonymous access type, as for access
11383 -- parameters and discriminants, the error is on the designated types.
11385 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11386 if Comes_From_Source (Expec_Type) then
11387 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11390 ("expected an access type with designated}",
11391 Expr, Designated_Type (Expec_Type));
11394 if Is_Access_Type (Found_Type)
11395 and then not Comes_From_Source (Found_Type)
11398 ("\\found an access type with designated}!",
11399 Expr, Designated_Type (Found_Type));
11401 if From_With_Type (Found_Type) then
11402 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11403 Error_Msg_Qual_Level := 99;
11404 Error_Msg_NE -- CODEFIX
11405 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11406 Error_Msg_Qual_Level := 0;
11408 Error_Msg_NE ("found}!", Expr, Found_Type);
11412 -- Normal case of one type found, some other type expected
11415 -- If the names of the two types are the same, see if some number
11416 -- of levels of qualification will help. Don't try more than three
11417 -- levels, and if we get to standard, it's no use (and probably
11418 -- represents an error in the compiler) Also do not bother with
11419 -- internal scope names.
11422 Expec_Scope : Entity_Id;
11423 Found_Scope : Entity_Id;
11426 Expec_Scope := Expec_Type;
11427 Found_Scope := Found_Type;
11429 for Levels in Int range 0 .. 3 loop
11430 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11431 Error_Msg_Qual_Level := Levels;
11435 Expec_Scope := Scope (Expec_Scope);
11436 Found_Scope := Scope (Found_Scope);
11438 exit when Expec_Scope = Standard_Standard
11439 or else Found_Scope = Standard_Standard
11440 or else not Comes_From_Source (Expec_Scope)
11441 or else not Comes_From_Source (Found_Scope);
11445 if Is_Record_Type (Expec_Type)
11446 and then Present (Corresponding_Remote_Type (Expec_Type))
11448 Error_Msg_NE ("expected}!", Expr,
11449 Corresponding_Remote_Type (Expec_Type));
11451 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11454 if Is_Entity_Name (Expr)
11455 and then Is_Package_Or_Generic_Package (Entity (Expr))
11457 Error_Msg_N ("\\found package name!", Expr);
11459 elsif Is_Entity_Name (Expr)
11461 (Ekind (Entity (Expr)) = E_Procedure
11463 Ekind (Entity (Expr)) = E_Generic_Procedure)
11465 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11467 ("found procedure name, possibly missing Access attribute!",
11471 ("\\found procedure name instead of function!", Expr);
11474 elsif Nkind (Expr) = N_Function_Call
11475 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11476 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11477 and then No (Parameter_Associations (Expr))
11480 ("found function name, possibly missing Access attribute!",
11483 -- Catch common error: a prefix or infix operator which is not
11484 -- directly visible because the type isn't.
11486 elsif Nkind (Expr) in N_Op
11487 and then Is_Overloaded (Expr)
11488 and then not Is_Immediately_Visible (Expec_Type)
11489 and then not Is_Potentially_Use_Visible (Expec_Type)
11490 and then not In_Use (Expec_Type)
11491 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11494 ("operator of the type is not directly visible!", Expr);
11496 elsif Ekind (Found_Type) = E_Void
11497 and then Present (Parent (Found_Type))
11498 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11500 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11503 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11506 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11507 -- of the same modular type, and (M1 and M2) = 0 was intended.
11509 if Expec_Type = Standard_Boolean
11510 and then Is_Modular_Integer_Type (Found_Type)
11511 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11512 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11515 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11516 L : constant Node_Id := Left_Opnd (Op);
11517 R : constant Node_Id := Right_Opnd (Op);
11519 -- The case for the message is when the left operand of the
11520 -- comparison is the same modular type, or when it is an
11521 -- integer literal (or other universal integer expression),
11522 -- which would have been typed as the modular type if the
11523 -- parens had been there.
11525 if (Etype (L) = Found_Type
11527 Etype (L) = Universal_Integer)
11528 and then Is_Integer_Type (Etype (R))
11531 ("\\possible missing parens for modular operation", Expr);
11536 -- Reset error message qualification indication
11538 Error_Msg_Qual_Level := 0;