1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Freeze; use Freeze;
37 with Lib.Xref; use Lib.Xref;
38 with Nlists; use Nlists;
39 with Output; use Output;
41 with Rtsfind; use Rtsfind;
42 with Scans; use Scans;
45 with Sem_Attr; use Sem_Attr;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with Stand; use Stand;
55 with Stringt; use Stringt;
56 with Targparm; use Targparm;
57 with Tbuild; use Tbuild;
58 with Ttypes; use Ttypes;
59 with Uname; use Uname;
61 package body Sem_Util is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Component_Subtype
70 T : Entity_Id) return Node_Id;
71 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
72 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
73 -- Loc is the source location, T is the original subtype.
75 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
76 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
77 -- with discriminants whose default values are static, examine only the
78 -- components in the selected variant to determine whether all of them
81 function Has_Null_Extension (T : Entity_Id) return Boolean;
82 -- T is a derived tagged type. Check whether the type extension is null.
83 -- If the parent type is fully initialized, T can be treated as such.
85 ------------------------------
86 -- Abstract_Interface_List --
87 ------------------------------
89 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
93 if Is_Concurrent_Type (Typ) then
95 -- If we are dealing with a synchronized subtype, go to the base
96 -- type, whose declaration has the interface list.
98 -- Shouldn't this be Declaration_Node???
100 Nod := Parent (Base_Type (Typ));
102 elsif Ekind (Typ) = E_Record_Type_With_Private then
103 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
104 Nod := Type_Definition (Parent (Typ));
106 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
107 if Present (Full_View (Typ)) then
108 Nod := Type_Definition (Parent (Full_View (Typ)));
110 -- If the full-view is not available we cannot do anything else
111 -- here (the source has errors).
117 -- Support for generic formals with interfaces is still missing ???
119 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
124 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
128 elsif Ekind (Typ) = E_Record_Subtype then
129 Nod := Type_Definition (Parent (Etype (Typ)));
131 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
133 -- Recurse, because parent may still be a private extension. Also
134 -- note that the full view of the subtype or the full view of its
135 -- base type may (both) be unavailable.
137 return Abstract_Interface_List (Etype (Typ));
139 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
140 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
141 Nod := Formal_Type_Definition (Parent (Typ));
143 Nod := Type_Definition (Parent (Typ));
147 return Interface_List (Nod);
148 end Abstract_Interface_List;
150 --------------------------------
151 -- Add_Access_Type_To_Process --
152 --------------------------------
154 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
158 Ensure_Freeze_Node (E);
159 L := Access_Types_To_Process (Freeze_Node (E));
163 Set_Access_Types_To_Process (Freeze_Node (E), L);
167 end Add_Access_Type_To_Process;
169 ----------------------------
170 -- Add_Global_Declaration --
171 ----------------------------
173 procedure Add_Global_Declaration (N : Node_Id) is
174 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
177 if No (Declarations (Aux_Node)) then
178 Set_Declarations (Aux_Node, New_List);
181 Append_To (Declarations (Aux_Node), N);
183 end Add_Global_Declaration;
185 -----------------------
186 -- Alignment_In_Bits --
187 -----------------------
189 function Alignment_In_Bits (E : Entity_Id) return Uint is
191 return Alignment (E) * System_Storage_Unit;
192 end Alignment_In_Bits;
194 -----------------------------------------
195 -- Apply_Compile_Time_Constraint_Error --
196 -----------------------------------------
198 procedure Apply_Compile_Time_Constraint_Error
201 Reason : RT_Exception_Code;
202 Ent : Entity_Id := Empty;
203 Typ : Entity_Id := Empty;
204 Loc : Source_Ptr := No_Location;
205 Rep : Boolean := True;
206 Warn : Boolean := False)
208 Stat : constant Boolean := Is_Static_Expression (N);
209 R_Stat : constant Node_Id :=
210 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
221 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
227 -- Now we replace the node by an N_Raise_Constraint_Error node
228 -- This does not need reanalyzing, so set it as analyzed now.
231 Set_Analyzed (N, True);
234 Set_Raises_Constraint_Error (N);
236 -- If the original expression was marked as static, the result is
237 -- still marked as static, but the Raises_Constraint_Error flag is
238 -- always set so that further static evaluation is not attempted.
241 Set_Is_Static_Expression (N);
243 end Apply_Compile_Time_Constraint_Error;
245 --------------------------
246 -- Build_Actual_Subtype --
247 --------------------------
249 function Build_Actual_Subtype
251 N : Node_Or_Entity_Id) return Node_Id
254 -- Normally Sloc (N), but may point to corresponding body in some cases
256 Constraints : List_Id;
262 Disc_Type : Entity_Id;
268 if Nkind (N) = N_Defining_Identifier then
269 Obj := New_Reference_To (N, Loc);
271 -- If this is a formal parameter of a subprogram declaration, and
272 -- we are compiling the body, we want the declaration for the
273 -- actual subtype to carry the source position of the body, to
274 -- prevent anomalies in gdb when stepping through the code.
276 if Is_Formal (N) then
278 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
280 if Nkind (Decl) = N_Subprogram_Declaration
281 and then Present (Corresponding_Body (Decl))
283 Loc := Sloc (Corresponding_Body (Decl));
292 if Is_Array_Type (T) then
293 Constraints := New_List;
294 for J in 1 .. Number_Dimensions (T) loop
296 -- Build an array subtype declaration with the nominal subtype and
297 -- the bounds of the actual. Add the declaration in front of the
298 -- local declarations for the subprogram, for analysis before any
299 -- reference to the formal in the body.
302 Make_Attribute_Reference (Loc,
304 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
305 Attribute_Name => Name_First,
306 Expressions => New_List (
307 Make_Integer_Literal (Loc, J)));
310 Make_Attribute_Reference (Loc,
312 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
313 Attribute_Name => Name_Last,
314 Expressions => New_List (
315 Make_Integer_Literal (Loc, J)));
317 Append (Make_Range (Loc, Lo, Hi), Constraints);
320 -- If the type has unknown discriminants there is no constrained
321 -- subtype to build. This is never called for a formal or for a
322 -- lhs, so returning the type is ok ???
324 elsif Has_Unknown_Discriminants (T) then
328 Constraints := New_List;
330 -- Type T is a generic derived type, inherit the discriminants from
333 if Is_Private_Type (T)
334 and then No (Full_View (T))
336 -- T was flagged as an error if it was declared as a formal
337 -- derived type with known discriminants. In this case there
338 -- is no need to look at the parent type since T already carries
339 -- its own discriminants.
341 and then not Error_Posted (T)
343 Disc_Type := Etype (Base_Type (T));
348 Discr := First_Discriminant (Disc_Type);
349 while Present (Discr) loop
350 Append_To (Constraints,
351 Make_Selected_Component (Loc,
353 Duplicate_Subexpr_No_Checks (Obj),
354 Selector_Name => New_Occurrence_Of (Discr, Loc)));
355 Next_Discriminant (Discr);
360 Make_Defining_Identifier (Loc,
361 Chars => New_Internal_Name ('S'));
362 Set_Is_Internal (Subt);
365 Make_Subtype_Declaration (Loc,
366 Defining_Identifier => Subt,
367 Subtype_Indication =>
368 Make_Subtype_Indication (Loc,
369 Subtype_Mark => New_Reference_To (T, Loc),
371 Make_Index_Or_Discriminant_Constraint (Loc,
372 Constraints => Constraints)));
374 Mark_Rewrite_Insertion (Decl);
376 end Build_Actual_Subtype;
378 ---------------------------------------
379 -- Build_Actual_Subtype_Of_Component --
380 ---------------------------------------
382 function Build_Actual_Subtype_Of_Component
384 N : Node_Id) return Node_Id
386 Loc : constant Source_Ptr := Sloc (N);
387 P : constant Node_Id := Prefix (N);
390 Indx_Type : Entity_Id;
392 Deaccessed_T : Entity_Id;
393 -- This is either a copy of T, or if T is an access type, then it is
394 -- the directly designated type of this access type.
396 function Build_Actual_Array_Constraint return List_Id;
397 -- If one or more of the bounds of the component depends on
398 -- discriminants, build actual constraint using the discriminants
401 function Build_Actual_Record_Constraint return List_Id;
402 -- Similar to previous one, for discriminated components constrained
403 -- by the discriminant of the enclosing object.
405 -----------------------------------
406 -- Build_Actual_Array_Constraint --
407 -----------------------------------
409 function Build_Actual_Array_Constraint return List_Id is
410 Constraints : constant List_Id := New_List;
418 Indx := First_Index (Deaccessed_T);
419 while Present (Indx) loop
420 Old_Lo := Type_Low_Bound (Etype (Indx));
421 Old_Hi := Type_High_Bound (Etype (Indx));
423 if Denotes_Discriminant (Old_Lo) then
425 Make_Selected_Component (Loc,
426 Prefix => New_Copy_Tree (P),
427 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
430 Lo := New_Copy_Tree (Old_Lo);
432 -- The new bound will be reanalyzed in the enclosing
433 -- declaration. For literal bounds that come from a type
434 -- declaration, the type of the context must be imposed, so
435 -- insure that analysis will take place. For non-universal
436 -- types this is not strictly necessary.
438 Set_Analyzed (Lo, False);
441 if Denotes_Discriminant (Old_Hi) then
443 Make_Selected_Component (Loc,
444 Prefix => New_Copy_Tree (P),
445 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
448 Hi := New_Copy_Tree (Old_Hi);
449 Set_Analyzed (Hi, False);
452 Append (Make_Range (Loc, Lo, Hi), Constraints);
457 end Build_Actual_Array_Constraint;
459 ------------------------------------
460 -- Build_Actual_Record_Constraint --
461 ------------------------------------
463 function Build_Actual_Record_Constraint return List_Id is
464 Constraints : constant List_Id := New_List;
469 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
470 while Present (D) loop
471 if Denotes_Discriminant (Node (D)) then
472 D_Val := Make_Selected_Component (Loc,
473 Prefix => New_Copy_Tree (P),
474 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
477 D_Val := New_Copy_Tree (Node (D));
480 Append (D_Val, Constraints);
485 end Build_Actual_Record_Constraint;
487 -- Start of processing for Build_Actual_Subtype_Of_Component
490 -- Why the test for Spec_Expression mode here???
492 if In_Spec_Expression then
495 -- More commments for the rest of this body would be good ???
497 elsif Nkind (N) = N_Explicit_Dereference then
498 if Is_Composite_Type (T)
499 and then not Is_Constrained (T)
500 and then not (Is_Class_Wide_Type (T)
501 and then Is_Constrained (Root_Type (T)))
502 and then not Has_Unknown_Discriminants (T)
504 -- If the type of the dereference is already constrained, it
505 -- is an actual subtype.
507 if Is_Array_Type (Etype (N))
508 and then Is_Constrained (Etype (N))
512 Remove_Side_Effects (P);
513 return Build_Actual_Subtype (T, N);
520 if Ekind (T) = E_Access_Subtype then
521 Deaccessed_T := Designated_Type (T);
526 if Ekind (Deaccessed_T) = E_Array_Subtype then
527 Id := First_Index (Deaccessed_T);
528 while Present (Id) loop
529 Indx_Type := Underlying_Type (Etype (Id));
531 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
533 Denotes_Discriminant (Type_High_Bound (Indx_Type))
535 Remove_Side_Effects (P);
537 Build_Component_Subtype
538 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
544 elsif Is_Composite_Type (Deaccessed_T)
545 and then Has_Discriminants (Deaccessed_T)
546 and then not Has_Unknown_Discriminants (Deaccessed_T)
548 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
549 while Present (D) loop
550 if Denotes_Discriminant (Node (D)) then
551 Remove_Side_Effects (P);
553 Build_Component_Subtype (
554 Build_Actual_Record_Constraint, Loc, Base_Type (T));
561 -- If none of the above, the actual and nominal subtypes are the same
564 end Build_Actual_Subtype_Of_Component;
566 -----------------------------
567 -- Build_Component_Subtype --
568 -----------------------------
570 function Build_Component_Subtype
573 T : Entity_Id) return Node_Id
579 -- Unchecked_Union components do not require component subtypes
581 if Is_Unchecked_Union (T) then
586 Make_Defining_Identifier (Loc,
587 Chars => New_Internal_Name ('S'));
588 Set_Is_Internal (Subt);
591 Make_Subtype_Declaration (Loc,
592 Defining_Identifier => Subt,
593 Subtype_Indication =>
594 Make_Subtype_Indication (Loc,
595 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
597 Make_Index_Or_Discriminant_Constraint (Loc,
600 Mark_Rewrite_Insertion (Decl);
602 end Build_Component_Subtype;
604 ---------------------------
605 -- Build_Default_Subtype --
606 ---------------------------
608 function Build_Default_Subtype
610 N : Node_Id) return Entity_Id
612 Loc : constant Source_Ptr := Sloc (N);
616 if not Has_Discriminants (T) or else Is_Constrained (T) then
620 Disc := First_Discriminant (T);
622 if No (Discriminant_Default_Value (Disc)) then
627 Act : constant Entity_Id :=
628 Make_Defining_Identifier (Loc,
629 Chars => New_Internal_Name ('S'));
631 Constraints : constant List_Id := New_List;
635 while Present (Disc) loop
636 Append_To (Constraints,
637 New_Copy_Tree (Discriminant_Default_Value (Disc)));
638 Next_Discriminant (Disc);
642 Make_Subtype_Declaration (Loc,
643 Defining_Identifier => Act,
644 Subtype_Indication =>
645 Make_Subtype_Indication (Loc,
646 Subtype_Mark => New_Occurrence_Of (T, Loc),
648 Make_Index_Or_Discriminant_Constraint (Loc,
649 Constraints => Constraints)));
651 Insert_Action (N, Decl);
655 end Build_Default_Subtype;
657 --------------------------------------------
658 -- Build_Discriminal_Subtype_Of_Component --
659 --------------------------------------------
661 function Build_Discriminal_Subtype_Of_Component
662 (T : Entity_Id) return Node_Id
664 Loc : constant Source_Ptr := Sloc (T);
668 function Build_Discriminal_Array_Constraint return List_Id;
669 -- If one or more of the bounds of the component depends on
670 -- discriminants, build actual constraint using the discriminants
673 function Build_Discriminal_Record_Constraint return List_Id;
674 -- Similar to previous one, for discriminated components constrained
675 -- by the discriminant of the enclosing object.
677 ----------------------------------------
678 -- Build_Discriminal_Array_Constraint --
679 ----------------------------------------
681 function Build_Discriminal_Array_Constraint return List_Id is
682 Constraints : constant List_Id := New_List;
690 Indx := First_Index (T);
691 while Present (Indx) loop
692 Old_Lo := Type_Low_Bound (Etype (Indx));
693 Old_Hi := Type_High_Bound (Etype (Indx));
695 if Denotes_Discriminant (Old_Lo) then
696 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
699 Lo := New_Copy_Tree (Old_Lo);
702 if Denotes_Discriminant (Old_Hi) then
703 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
706 Hi := New_Copy_Tree (Old_Hi);
709 Append (Make_Range (Loc, Lo, Hi), Constraints);
714 end Build_Discriminal_Array_Constraint;
716 -----------------------------------------
717 -- Build_Discriminal_Record_Constraint --
718 -----------------------------------------
720 function Build_Discriminal_Record_Constraint return List_Id is
721 Constraints : constant List_Id := New_List;
726 D := First_Elmt (Discriminant_Constraint (T));
727 while Present (D) loop
728 if Denotes_Discriminant (Node (D)) then
730 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
733 D_Val := New_Copy_Tree (Node (D));
736 Append (D_Val, Constraints);
741 end Build_Discriminal_Record_Constraint;
743 -- Start of processing for Build_Discriminal_Subtype_Of_Component
746 if Ekind (T) = E_Array_Subtype then
747 Id := First_Index (T);
748 while Present (Id) loop
749 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
750 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
752 return Build_Component_Subtype
753 (Build_Discriminal_Array_Constraint, Loc, T);
759 elsif Ekind (T) = E_Record_Subtype
760 and then Has_Discriminants (T)
761 and then not Has_Unknown_Discriminants (T)
763 D := First_Elmt (Discriminant_Constraint (T));
764 while Present (D) loop
765 if Denotes_Discriminant (Node (D)) then
766 return Build_Component_Subtype
767 (Build_Discriminal_Record_Constraint, Loc, T);
774 -- If none of the above, the actual and nominal subtypes are the same
777 end Build_Discriminal_Subtype_Of_Component;
779 ------------------------------
780 -- Build_Elaboration_Entity --
781 ------------------------------
783 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
784 Loc : constant Source_Ptr := Sloc (N);
786 Elab_Ent : Entity_Id;
788 procedure Set_Package_Name (Ent : Entity_Id);
789 -- Given an entity, sets the fully qualified name of the entity in
790 -- Name_Buffer, with components separated by double underscores. This
791 -- is a recursive routine that climbs the scope chain to Standard.
793 ----------------------
794 -- Set_Package_Name --
795 ----------------------
797 procedure Set_Package_Name (Ent : Entity_Id) is
799 if Scope (Ent) /= Standard_Standard then
800 Set_Package_Name (Scope (Ent));
803 Nam : constant String := Get_Name_String (Chars (Ent));
805 Name_Buffer (Name_Len + 1) := '_';
806 Name_Buffer (Name_Len + 2) := '_';
807 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
808 Name_Len := Name_Len + Nam'Length + 2;
812 Get_Name_String (Chars (Ent));
814 end Set_Package_Name;
816 -- Start of processing for Build_Elaboration_Entity
819 -- Ignore if already constructed
821 if Present (Elaboration_Entity (Spec_Id)) then
825 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
826 -- name with dots replaced by double underscore. We have to manually
827 -- construct this name, since it will be elaborated in the outer scope,
828 -- and thus will not have the unit name automatically prepended.
830 Set_Package_Name (Spec_Id);
834 Name_Buffer (Name_Len + 1) := '_';
835 Name_Buffer (Name_Len + 2) := 'E';
836 Name_Len := Name_Len + 2;
838 -- Create elaboration flag
841 Make_Defining_Identifier (Loc, Chars => Name_Find);
842 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
845 Make_Object_Declaration (Loc,
846 Defining_Identifier => Elab_Ent,
848 New_Occurrence_Of (Standard_Boolean, Loc),
850 New_Occurrence_Of (Standard_False, Loc));
852 Push_Scope (Standard_Standard);
853 Add_Global_Declaration (Decl);
856 -- Reset True_Constant indication, since we will indeed assign a value
857 -- to the variable in the binder main. We also kill the Current_Value
858 -- and Last_Assignment fields for the same reason.
860 Set_Is_True_Constant (Elab_Ent, False);
861 Set_Current_Value (Elab_Ent, Empty);
862 Set_Last_Assignment (Elab_Ent, Empty);
864 -- We do not want any further qualification of the name (if we did
865 -- not do this, we would pick up the name of the generic package
866 -- in the case of a library level generic instantiation).
868 Set_Has_Qualified_Name (Elab_Ent);
869 Set_Has_Fully_Qualified_Name (Elab_Ent);
870 end Build_Elaboration_Entity;
872 -----------------------------------
873 -- Cannot_Raise_Constraint_Error --
874 -----------------------------------
876 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
878 if Compile_Time_Known_Value (Expr) then
881 elsif Do_Range_Check (Expr) then
884 elsif Raises_Constraint_Error (Expr) then
892 when N_Expanded_Name =>
895 when N_Selected_Component =>
896 return not Do_Discriminant_Check (Expr);
898 when N_Attribute_Reference =>
899 if Do_Overflow_Check (Expr) then
902 elsif No (Expressions (Expr)) then
910 N := First (Expressions (Expr));
911 while Present (N) loop
912 if Cannot_Raise_Constraint_Error (N) then
923 when N_Type_Conversion =>
924 if Do_Overflow_Check (Expr)
925 or else Do_Length_Check (Expr)
926 or else Do_Tag_Check (Expr)
931 Cannot_Raise_Constraint_Error (Expression (Expr));
934 when N_Unchecked_Type_Conversion =>
935 return Cannot_Raise_Constraint_Error (Expression (Expr));
938 if Do_Overflow_Check (Expr) then
942 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
949 if Do_Division_Check (Expr)
950 or else Do_Overflow_Check (Expr)
955 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
957 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
976 N_Op_Shift_Right_Arithmetic |
980 if Do_Overflow_Check (Expr) then
984 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
986 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
993 end Cannot_Raise_Constraint_Error;
995 --------------------------
996 -- Check_Fully_Declared --
997 --------------------------
999 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1001 if Ekind (T) = E_Incomplete_Type then
1003 -- Ada 2005 (AI-50217): If the type is available through a limited
1004 -- with_clause, verify that its full view has been analyzed.
1006 if From_With_Type (T)
1007 and then Present (Non_Limited_View (T))
1008 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1010 -- The non-limited view is fully declared
1015 ("premature usage of incomplete}", N, First_Subtype (T));
1018 -- Need comments for these tests ???
1020 elsif Has_Private_Component (T)
1021 and then not Is_Generic_Type (Root_Type (T))
1022 and then not In_Spec_Expression
1024 -- Special case: if T is the anonymous type created for a single
1025 -- task or protected object, use the name of the source object.
1027 if Is_Concurrent_Type (T)
1028 and then not Comes_From_Source (T)
1029 and then Nkind (N) = N_Object_Declaration
1031 Error_Msg_NE ("type of& has incomplete component", N,
1032 Defining_Identifier (N));
1036 ("premature usage of incomplete}", N, First_Subtype (T));
1039 end Check_Fully_Declared;
1041 -------------------------
1042 -- Check_Nested_Access --
1043 -------------------------
1045 procedure Check_Nested_Access (Ent : Entity_Id) is
1046 Scop : constant Entity_Id := Current_Scope;
1047 Current_Subp : Entity_Id;
1048 Enclosing : Entity_Id;
1051 -- Currently only enabled for VM back-ends for efficiency, should we
1052 -- enable it more systematically ???
1054 -- Check for Is_Imported needs commenting below ???
1056 if VM_Target /= No_VM
1057 and then (Ekind (Ent) = E_Variable
1059 Ekind (Ent) = E_Constant
1061 Ekind (Ent) = E_Loop_Parameter)
1062 and then Scope (Ent) /= Empty
1063 and then not Is_Library_Level_Entity (Ent)
1064 and then not Is_Imported (Ent)
1066 if Is_Subprogram (Scop)
1067 or else Is_Generic_Subprogram (Scop)
1068 or else Is_Entry (Scop)
1070 Current_Subp := Scop;
1072 Current_Subp := Current_Subprogram;
1075 Enclosing := Enclosing_Subprogram (Ent);
1077 if Enclosing /= Empty
1078 and then Enclosing /= Current_Subp
1080 Set_Has_Up_Level_Access (Ent, True);
1083 end Check_Nested_Access;
1085 ------------------------------------------
1086 -- Check_Potentially_Blocking_Operation --
1087 ------------------------------------------
1089 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1092 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1093 -- When pragma Detect_Blocking is active, the run time will raise
1094 -- Program_Error. Here we only issue a warning, since we generally
1095 -- support the use of potentially blocking operations in the absence
1098 -- Indirect blocking through a subprogram call cannot be diagnosed
1099 -- statically without interprocedural analysis, so we do not attempt
1102 S := Scope (Current_Scope);
1103 while Present (S) and then S /= Standard_Standard loop
1104 if Is_Protected_Type (S) then
1106 ("potentially blocking operation in protected operation?", N);
1113 end Check_Potentially_Blocking_Operation;
1115 ------------------------------
1116 -- Check_Unprotected_Access --
1117 ------------------------------
1119 procedure Check_Unprotected_Access
1123 Cont_Encl_Typ : Entity_Id;
1124 Pref_Encl_Typ : Entity_Id;
1126 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1127 -- Check whether Obj is a private component of a protected object.
1128 -- Return the protected type where the component resides, Empty
1131 function Is_Public_Operation return Boolean;
1132 -- Verify that the enclosing operation is callable from outside the
1133 -- protected object, to minimize false positives.
1135 ------------------------------
1136 -- Enclosing_Protected_Type --
1137 ------------------------------
1139 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1141 if Is_Entity_Name (Obj) then
1143 Ent : Entity_Id := Entity (Obj);
1146 -- The object can be a renaming of a private component, use
1147 -- the original record component.
1149 if Is_Prival (Ent) then
1150 Ent := Prival_Link (Ent);
1153 if Is_Protected_Type (Scope (Ent)) then
1159 -- For indexed and selected components, recursively check the prefix
1161 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1162 return Enclosing_Protected_Type (Prefix (Obj));
1164 -- The object does not denote a protected component
1169 end Enclosing_Protected_Type;
1171 -------------------------
1172 -- Is_Public_Operation --
1173 -------------------------
1175 function Is_Public_Operation return Boolean is
1182 and then S /= Pref_Encl_Typ
1184 if Scope (S) = Pref_Encl_Typ then
1185 E := First_Entity (Pref_Encl_Typ);
1187 and then E /= First_Private_Entity (Pref_Encl_Typ)
1200 end Is_Public_Operation;
1202 -- Start of processing for Check_Unprotected_Access
1205 if Nkind (Expr) = N_Attribute_Reference
1206 and then Attribute_Name (Expr) = Name_Unchecked_Access
1208 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1209 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1211 -- Check whether we are trying to export a protected component to a
1212 -- context with an equal or lower access level.
1214 if Present (Pref_Encl_Typ)
1215 and then No (Cont_Encl_Typ)
1216 and then Is_Public_Operation
1217 and then Scope_Depth (Pref_Encl_Typ) >=
1218 Object_Access_Level (Context)
1221 ("?possible unprotected access to protected data", Expr);
1224 end Check_Unprotected_Access;
1230 procedure Check_VMS (Construct : Node_Id) is
1232 if not OpenVMS_On_Target then
1234 ("this construct is allowed only in Open'V'M'S", Construct);
1238 ---------------------------------
1239 -- Collect_Abstract_Interfaces --
1240 ---------------------------------
1242 procedure Collect_Abstract_Interfaces
1244 Ifaces_List : out Elist_Id;
1245 Exclude_Parent_Interfaces : Boolean := False;
1246 Use_Full_View : Boolean := True)
1248 procedure Add_Interface (Iface : Entity_Id);
1249 -- Add the interface it if is not already in the list
1251 procedure Collect (Typ : Entity_Id);
1252 -- Subsidiary subprogram used to traverse the whole list
1253 -- of directly and indirectly implemented interfaces
1255 function Interface_Present_In_Parent
1257 Iface : Entity_Id) return Boolean;
1258 -- Typ must be a tagged record type/subtype and Iface must be an
1259 -- abstract interface type. This function is used to check if Typ
1260 -- or some parent of Typ implements Iface.
1266 procedure Add_Interface (Iface : Entity_Id) is
1270 Elmt := First_Elmt (Ifaces_List);
1271 while Present (Elmt) and then Node (Elmt) /= Iface loop
1276 Append_Elmt (Iface, Ifaces_List);
1284 procedure Collect (Typ : Entity_Id) is
1285 Ancestor : Entity_Id;
1287 Iface_List : List_Id;
1294 -- Handle private types
1297 and then Is_Private_Type (Typ)
1298 and then Present (Full_View (Typ))
1300 Full_T := Full_View (Typ);
1303 Iface_List := Abstract_Interface_List (Full_T);
1305 -- Include the ancestor if we are generating the whole list of
1306 -- abstract interfaces.
1308 -- In concurrent types the ancestor interface (if any) is the
1309 -- first element of the list of interface types.
1311 if Is_Concurrent_Type (Full_T)
1312 or else Is_Concurrent_Record_Type (Full_T)
1314 if Is_Non_Empty_List (Iface_List) then
1315 Ancestor := Etype (First (Iface_List));
1318 if not Exclude_Parent_Interfaces then
1319 Add_Interface (Ancestor);
1323 elsif Etype (Full_T) /= Typ
1325 -- Protect the frontend against wrong sources. For example:
1328 -- type A is tagged null record;
1329 -- type B is new A with private;
1330 -- type C is new A with private;
1332 -- type B is new C with null record;
1333 -- type C is new B with null record;
1336 and then Etype (Full_T) /= T
1338 Ancestor := Etype (Full_T);
1341 if Is_Interface (Ancestor)
1342 and then not Exclude_Parent_Interfaces
1344 Add_Interface (Ancestor);
1348 -- Traverse the graph of ancestor interfaces
1350 if Is_Non_Empty_List (Iface_List) then
1351 Id := First (Iface_List);
1353 -- In concurrent types the ancestor interface (if any) is the
1354 -- first element of the list of interface types and we have
1355 -- already processed them while climbing to the root type.
1357 if Is_Concurrent_Type (Full_T)
1358 or else Is_Concurrent_Record_Type (Full_T)
1363 while Present (Id) loop
1364 Iface := Etype (Id);
1366 -- Protect against wrong uses. For example:
1367 -- type I is interface;
1368 -- type O is tagged null record;
1369 -- type Wrong is new I and O with null record; -- ERROR
1371 if Is_Interface (Iface) then
1372 if Exclude_Parent_Interfaces
1373 and then Interface_Present_In_Parent (T, Iface)
1378 Add_Interface (Iface);
1387 ---------------------------------
1388 -- Interface_Present_In_Parent --
1389 ---------------------------------
1391 function Interface_Present_In_Parent
1393 Iface : Entity_Id) return Boolean
1395 Aux : Entity_Id := Typ;
1396 Iface_List : List_Id;
1399 if Is_Concurrent_Type (Typ)
1400 or else Is_Concurrent_Record_Type (Typ)
1402 Iface_List := Abstract_Interface_List (Typ);
1404 if Is_Non_Empty_List (Iface_List) then
1405 Aux := Etype (First (Iface_List));
1411 return Interface_Present_In_Ancestor (Aux, Iface);
1412 end Interface_Present_In_Parent;
1414 -- Start of processing for Collect_Abstract_Interfaces
1417 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1418 Ifaces_List := New_Elmt_List;
1420 end Collect_Abstract_Interfaces;
1422 ----------------------------------
1423 -- Collect_Interface_Components --
1424 ----------------------------------
1426 procedure Collect_Interface_Components
1427 (Tagged_Type : Entity_Id;
1428 Components_List : out Elist_Id)
1430 procedure Collect (Typ : Entity_Id);
1431 -- Subsidiary subprogram used to climb to the parents
1437 procedure Collect (Typ : Entity_Id) is
1438 Tag_Comp : Entity_Id;
1441 if Etype (Typ) /= Typ
1443 -- Protect the frontend against wrong sources. For example:
1446 -- type A is tagged null record;
1447 -- type B is new A with private;
1448 -- type C is new A with private;
1450 -- type B is new C with null record;
1451 -- type C is new B with null record;
1454 and then Etype (Typ) /= Tagged_Type
1456 Collect (Etype (Typ));
1459 -- Collect the components containing tags of secondary dispatch
1462 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1463 while Present (Tag_Comp) loop
1464 pragma Assert (Present (Related_Type (Tag_Comp)));
1465 Append_Elmt (Tag_Comp, Components_List);
1467 Tag_Comp := Next_Tag_Component (Tag_Comp);
1471 -- Start of processing for Collect_Interface_Components
1474 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1475 and then Is_Tagged_Type (Tagged_Type));
1477 Components_List := New_Elmt_List;
1478 Collect (Tagged_Type);
1479 end Collect_Interface_Components;
1481 -----------------------------
1482 -- Collect_Interfaces_Info --
1483 -----------------------------
1485 procedure Collect_Interfaces_Info
1487 Ifaces_List : out Elist_Id;
1488 Components_List : out Elist_Id;
1489 Tags_List : out Elist_Id)
1491 Comps_List : Elist_Id;
1492 Comp_Elmt : Elmt_Id;
1493 Comp_Iface : Entity_Id;
1494 Iface_Elmt : Elmt_Id;
1497 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1498 -- Search for the secondary tag associated with the interface type
1499 -- Iface that is implemented by T.
1505 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1509 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1511 and then Ekind (Node (ADT)) = E_Constant
1512 and then Related_Type (Node (ADT)) /= Iface
1514 -- Skip the secondary dispatch tables of Iface
1522 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1526 -- Start of processing for Collect_Interfaces_Info
1529 Collect_Abstract_Interfaces (T, Ifaces_List);
1530 Collect_Interface_Components (T, Comps_List);
1532 -- Search for the record component and tag associated with each
1533 -- interface type of T.
1535 Components_List := New_Elmt_List;
1536 Tags_List := New_Elmt_List;
1538 Iface_Elmt := First_Elmt (Ifaces_List);
1539 while Present (Iface_Elmt) loop
1540 Iface := Node (Iface_Elmt);
1542 -- Associate the primary tag component and the primary dispatch table
1543 -- with all the interfaces that are parents of T
1545 if Is_Parent (Iface, T) then
1546 Append_Elmt (First_Tag_Component (T), Components_List);
1547 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1549 -- Otherwise search for the tag component and secondary dispatch
1553 Comp_Elmt := First_Elmt (Comps_List);
1554 while Present (Comp_Elmt) loop
1555 Comp_Iface := Related_Type (Node (Comp_Elmt));
1557 if Comp_Iface = Iface
1558 or else Is_Parent (Iface, Comp_Iface)
1560 Append_Elmt (Node (Comp_Elmt), Components_List);
1561 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1565 Next_Elmt (Comp_Elmt);
1567 pragma Assert (Present (Comp_Elmt));
1570 Next_Elmt (Iface_Elmt);
1572 end Collect_Interfaces_Info;
1574 ----------------------------------
1575 -- Collect_Primitive_Operations --
1576 ----------------------------------
1578 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1579 B_Type : constant Entity_Id := Base_Type (T);
1580 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1581 B_Scope : Entity_Id := Scope (B_Type);
1585 Formal_Derived : Boolean := False;
1589 -- For tagged types, the primitive operations are collected as they
1590 -- are declared, and held in an explicit list which is simply returned.
1592 if Is_Tagged_Type (B_Type) then
1593 return Primitive_Operations (B_Type);
1595 -- An untagged generic type that is a derived type inherits the
1596 -- primitive operations of its parent type. Other formal types only
1597 -- have predefined operators, which are not explicitly represented.
1599 elsif Is_Generic_Type (B_Type) then
1600 if Nkind (B_Decl) = N_Formal_Type_Declaration
1601 and then Nkind (Formal_Type_Definition (B_Decl))
1602 = N_Formal_Derived_Type_Definition
1604 Formal_Derived := True;
1606 return New_Elmt_List;
1610 Op_List := New_Elmt_List;
1612 if B_Scope = Standard_Standard then
1613 if B_Type = Standard_String then
1614 Append_Elmt (Standard_Op_Concat, Op_List);
1616 elsif B_Type = Standard_Wide_String then
1617 Append_Elmt (Standard_Op_Concatw, Op_List);
1623 elsif (Is_Package_Or_Generic_Package (B_Scope)
1625 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1627 or else Is_Derived_Type (B_Type)
1629 -- The primitive operations appear after the base type, except
1630 -- if the derivation happens within the private part of B_Scope
1631 -- and the type is a private type, in which case both the type
1632 -- and some primitive operations may appear before the base
1633 -- type, and the list of candidates starts after the type.
1635 if In_Open_Scopes (B_Scope)
1636 and then Scope (T) = B_Scope
1637 and then In_Private_Part (B_Scope)
1639 Id := Next_Entity (T);
1641 Id := Next_Entity (B_Type);
1644 while Present (Id) loop
1646 -- Note that generic formal subprograms are not
1647 -- considered to be primitive operations and thus
1648 -- are never inherited.
1650 if Is_Overloadable (Id)
1651 and then Nkind (Parent (Parent (Id)))
1652 not in N_Formal_Subprogram_Declaration
1656 if Base_Type (Etype (Id)) = B_Type then
1659 Formal := First_Formal (Id);
1660 while Present (Formal) loop
1661 if Base_Type (Etype (Formal)) = B_Type then
1665 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1667 (Designated_Type (Etype (Formal))) = B_Type
1673 Next_Formal (Formal);
1677 -- For a formal derived type, the only primitives are the
1678 -- ones inherited from the parent type. Operations appearing
1679 -- in the package declaration are not primitive for it.
1682 and then (not Formal_Derived
1683 or else Present (Alias (Id)))
1685 Append_Elmt (Id, Op_List);
1691 -- For a type declared in System, some of its operations
1692 -- may appear in the target-specific extension to System.
1695 and then Chars (B_Scope) = Name_System
1696 and then Scope (B_Scope) = Standard_Standard
1697 and then Present_System_Aux
1699 B_Scope := System_Aux_Id;
1700 Id := First_Entity (System_Aux_Id);
1706 end Collect_Primitive_Operations;
1708 -----------------------------------
1709 -- Compile_Time_Constraint_Error --
1710 -----------------------------------
1712 function Compile_Time_Constraint_Error
1715 Ent : Entity_Id := Empty;
1716 Loc : Source_Ptr := No_Location;
1717 Warn : Boolean := False) return Node_Id
1719 Msgc : String (1 .. Msg'Length + 2);
1720 -- Copy of message, with room for possible ? and ! at end
1730 -- A static constraint error in an instance body is not a fatal error.
1731 -- we choose to inhibit the message altogether, because there is no
1732 -- obvious node (for now) on which to post it. On the other hand the
1733 -- offending node must be replaced with a constraint_error in any case.
1735 -- No messages are generated if we already posted an error on this node
1737 if not Error_Posted (N) then
1738 if Loc /= No_Location then
1744 Msgc (1 .. Msg'Length) := Msg;
1747 -- Message is a warning, even in Ada 95 case
1749 if Msg (Msg'Last) = '?' then
1752 -- In Ada 83, all messages are warnings. In the private part and
1753 -- the body of an instance, constraint_checks are only warnings.
1754 -- We also make this a warning if the Warn parameter is set.
1757 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1763 elsif In_Instance_Not_Visible then
1768 -- Otherwise we have a real error message (Ada 95 static case)
1769 -- and we make this an unconditional message. Note that in the
1770 -- warning case we do not make the message unconditional, it seems
1771 -- quite reasonable to delete messages like this (about exceptions
1772 -- that will be raised) in dead code.
1780 -- Should we generate a warning? The answer is not quite yes. The
1781 -- very annoying exception occurs in the case of a short circuit
1782 -- operator where the left operand is static and decisive. Climb
1783 -- parents to see if that is the case we have here. Conditional
1784 -- expressions with decisive conditions are a similar situation.
1792 -- And then with False as left operand
1794 if Nkind (P) = N_And_Then
1795 and then Compile_Time_Known_Value (Left_Opnd (P))
1796 and then Is_False (Expr_Value (Left_Opnd (P)))
1801 -- OR ELSE with True as left operand
1803 elsif Nkind (P) = N_Or_Else
1804 and then Compile_Time_Known_Value (Left_Opnd (P))
1805 and then Is_True (Expr_Value (Left_Opnd (P)))
1810 -- Conditional expression
1812 elsif Nkind (P) = N_Conditional_Expression then
1814 Cond : constant Node_Id := First (Expressions (P));
1815 Texp : constant Node_Id := Next (Cond);
1816 Fexp : constant Node_Id := Next (Texp);
1819 if Compile_Time_Known_Value (Cond) then
1821 -- Condition is True and we are in the right operand
1823 if Is_True (Expr_Value (Cond))
1824 and then OldP = Fexp
1829 -- Condition is False and we are in the left operand
1831 elsif Is_False (Expr_Value (Cond))
1832 and then OldP = Texp
1840 -- Special case for component association in aggregates, where
1841 -- we want to keep climbing up to the parent aggregate.
1843 elsif Nkind (P) = N_Component_Association
1844 and then Nkind (Parent (P)) = N_Aggregate
1848 -- Keep going if within subexpression
1851 exit when Nkind (P) not in N_Subexpr;
1856 if Present (Ent) then
1857 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1859 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1863 if Inside_Init_Proc then
1865 ("\?& will be raised for objects of this type",
1866 N, Standard_Constraint_Error, Eloc);
1869 ("\?& will be raised at run time",
1870 N, Standard_Constraint_Error, Eloc);
1875 ("\static expression fails Constraint_Check", Eloc);
1876 Set_Error_Posted (N);
1882 end Compile_Time_Constraint_Error;
1884 -----------------------
1885 -- Conditional_Delay --
1886 -----------------------
1888 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1890 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1891 Set_Has_Delayed_Freeze (New_Ent);
1893 end Conditional_Delay;
1895 -------------------------
1896 -- Copy_Parameter_List --
1897 -------------------------
1899 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1900 Loc : constant Source_Ptr := Sloc (Subp_Id);
1905 if No (First_Formal (Subp_Id)) then
1909 Formal := First_Formal (Subp_Id);
1910 while Present (Formal) loop
1912 (Make_Parameter_Specification (Loc,
1913 Defining_Identifier =>
1914 Make_Defining_Identifier (Sloc (Formal),
1915 Chars => Chars (Formal)),
1916 In_Present => In_Present (Parent (Formal)),
1917 Out_Present => Out_Present (Parent (Formal)),
1919 New_Reference_To (Etype (Formal), Loc),
1921 New_Copy_Tree (Expression (Parent (Formal)))),
1924 Next_Formal (Formal);
1929 end Copy_Parameter_List;
1931 --------------------
1932 -- Current_Entity --
1933 --------------------
1935 -- The currently visible definition for a given identifier is the
1936 -- one most chained at the start of the visibility chain, i.e. the
1937 -- one that is referenced by the Node_Id value of the name of the
1938 -- given identifier.
1940 function Current_Entity (N : Node_Id) return Entity_Id is
1942 return Get_Name_Entity_Id (Chars (N));
1945 -----------------------------
1946 -- Current_Entity_In_Scope --
1947 -----------------------------
1949 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1951 CS : constant Entity_Id := Current_Scope;
1953 Transient_Case : constant Boolean := Scope_Is_Transient;
1956 E := Get_Name_Entity_Id (Chars (N));
1958 and then Scope (E) /= CS
1959 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1965 end Current_Entity_In_Scope;
1971 function Current_Scope return Entity_Id is
1973 if Scope_Stack.Last = -1 then
1974 return Standard_Standard;
1977 C : constant Entity_Id :=
1978 Scope_Stack.Table (Scope_Stack.Last).Entity;
1983 return Standard_Standard;
1989 ------------------------
1990 -- Current_Subprogram --
1991 ------------------------
1993 function Current_Subprogram return Entity_Id is
1994 Scop : constant Entity_Id := Current_Scope;
1997 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2000 return Enclosing_Subprogram (Scop);
2002 end Current_Subprogram;
2004 ---------------------
2005 -- Defining_Entity --
2006 ---------------------
2008 function Defining_Entity (N : Node_Id) return Entity_Id is
2009 K : constant Node_Kind := Nkind (N);
2010 Err : Entity_Id := Empty;
2015 N_Subprogram_Declaration |
2016 N_Abstract_Subprogram_Declaration |
2018 N_Package_Declaration |
2019 N_Subprogram_Renaming_Declaration |
2020 N_Subprogram_Body_Stub |
2021 N_Generic_Subprogram_Declaration |
2022 N_Generic_Package_Declaration |
2023 N_Formal_Subprogram_Declaration
2025 return Defining_Entity (Specification (N));
2028 N_Component_Declaration |
2029 N_Defining_Program_Unit_Name |
2030 N_Discriminant_Specification |
2032 N_Entry_Declaration |
2033 N_Entry_Index_Specification |
2034 N_Exception_Declaration |
2035 N_Exception_Renaming_Declaration |
2036 N_Formal_Object_Declaration |
2037 N_Formal_Package_Declaration |
2038 N_Formal_Type_Declaration |
2039 N_Full_Type_Declaration |
2040 N_Implicit_Label_Declaration |
2041 N_Incomplete_Type_Declaration |
2042 N_Loop_Parameter_Specification |
2043 N_Number_Declaration |
2044 N_Object_Declaration |
2045 N_Object_Renaming_Declaration |
2046 N_Package_Body_Stub |
2047 N_Parameter_Specification |
2048 N_Private_Extension_Declaration |
2049 N_Private_Type_Declaration |
2051 N_Protected_Body_Stub |
2052 N_Protected_Type_Declaration |
2053 N_Single_Protected_Declaration |
2054 N_Single_Task_Declaration |
2055 N_Subtype_Declaration |
2058 N_Task_Type_Declaration
2060 return Defining_Identifier (N);
2063 return Defining_Entity (Proper_Body (N));
2066 N_Function_Instantiation |
2067 N_Function_Specification |
2068 N_Generic_Function_Renaming_Declaration |
2069 N_Generic_Package_Renaming_Declaration |
2070 N_Generic_Procedure_Renaming_Declaration |
2072 N_Package_Instantiation |
2073 N_Package_Renaming_Declaration |
2074 N_Package_Specification |
2075 N_Procedure_Instantiation |
2076 N_Procedure_Specification
2079 Nam : constant Node_Id := Defining_Unit_Name (N);
2082 if Nkind (Nam) in N_Entity then
2085 -- For Error, make up a name and attach to declaration
2086 -- so we can continue semantic analysis
2088 elsif Nam = Error then
2090 Make_Defining_Identifier (Sloc (N),
2091 Chars => New_Internal_Name ('T'));
2092 Set_Defining_Unit_Name (N, Err);
2095 -- If not an entity, get defining identifier
2098 return Defining_Identifier (Nam);
2102 when N_Block_Statement =>
2103 return Entity (Identifier (N));
2106 raise Program_Error;
2109 end Defining_Entity;
2111 --------------------------
2112 -- Denotes_Discriminant --
2113 --------------------------
2115 function Denotes_Discriminant
2117 Check_Concurrent : Boolean := False) return Boolean
2121 if not Is_Entity_Name (N)
2122 or else No (Entity (N))
2129 -- If we are checking for a protected type, the discriminant may have
2130 -- been rewritten as the corresponding discriminal of the original type
2131 -- or of the corresponding concurrent record, depending on whether we
2132 -- are in the spec or body of the protected type.
2134 return Ekind (E) = E_Discriminant
2137 and then Ekind (E) = E_In_Parameter
2138 and then Present (Discriminal_Link (E))
2140 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2142 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2144 end Denotes_Discriminant;
2146 -----------------------------
2147 -- Depends_On_Discriminant --
2148 -----------------------------
2150 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2155 Get_Index_Bounds (N, L, H);
2156 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2157 end Depends_On_Discriminant;
2159 -------------------------
2160 -- Designate_Same_Unit --
2161 -------------------------
2163 function Designate_Same_Unit
2165 Name2 : Node_Id) return Boolean
2167 K1 : constant Node_Kind := Nkind (Name1);
2168 K2 : constant Node_Kind := Nkind (Name2);
2170 function Prefix_Node (N : Node_Id) return Node_Id;
2171 -- Returns the parent unit name node of a defining program unit name
2172 -- or the prefix if N is a selected component or an expanded name.
2174 function Select_Node (N : Node_Id) return Node_Id;
2175 -- Returns the defining identifier node of a defining program unit
2176 -- name or the selector node if N is a selected component or an
2183 function Prefix_Node (N : Node_Id) return Node_Id is
2185 if Nkind (N) = N_Defining_Program_Unit_Name then
2197 function Select_Node (N : Node_Id) return Node_Id is
2199 if Nkind (N) = N_Defining_Program_Unit_Name then
2200 return Defining_Identifier (N);
2203 return Selector_Name (N);
2207 -- Start of processing for Designate_Next_Unit
2210 if (K1 = N_Identifier or else
2211 K1 = N_Defining_Identifier)
2213 (K2 = N_Identifier or else
2214 K2 = N_Defining_Identifier)
2216 return Chars (Name1) = Chars (Name2);
2219 (K1 = N_Expanded_Name or else
2220 K1 = N_Selected_Component or else
2221 K1 = N_Defining_Program_Unit_Name)
2223 (K2 = N_Expanded_Name or else
2224 K2 = N_Selected_Component or else
2225 K2 = N_Defining_Program_Unit_Name)
2228 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2230 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2235 end Designate_Same_Unit;
2237 ----------------------------
2238 -- Enclosing_Generic_Body --
2239 ----------------------------
2241 function Enclosing_Generic_Body
2242 (N : Node_Id) return Node_Id
2250 while Present (P) loop
2251 if Nkind (P) = N_Package_Body
2252 or else Nkind (P) = N_Subprogram_Body
2254 Spec := Corresponding_Spec (P);
2256 if Present (Spec) then
2257 Decl := Unit_Declaration_Node (Spec);
2259 if Nkind (Decl) = N_Generic_Package_Declaration
2260 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2271 end Enclosing_Generic_Body;
2273 ----------------------------
2274 -- Enclosing_Generic_Unit --
2275 ----------------------------
2277 function Enclosing_Generic_Unit
2278 (N : Node_Id) return Node_Id
2286 while Present (P) loop
2287 if Nkind (P) = N_Generic_Package_Declaration
2288 or else Nkind (P) = N_Generic_Subprogram_Declaration
2292 elsif Nkind (P) = N_Package_Body
2293 or else Nkind (P) = N_Subprogram_Body
2295 Spec := Corresponding_Spec (P);
2297 if Present (Spec) then
2298 Decl := Unit_Declaration_Node (Spec);
2300 if Nkind (Decl) = N_Generic_Package_Declaration
2301 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2312 end Enclosing_Generic_Unit;
2314 -------------------------------
2315 -- Enclosing_Lib_Unit_Entity --
2316 -------------------------------
2318 function Enclosing_Lib_Unit_Entity return Entity_Id is
2319 Unit_Entity : Entity_Id;
2322 -- Look for enclosing library unit entity by following scope links.
2323 -- Equivalent to, but faster than indexing through the scope stack.
2325 Unit_Entity := Current_Scope;
2326 while (Present (Scope (Unit_Entity))
2327 and then Scope (Unit_Entity) /= Standard_Standard)
2328 and not Is_Child_Unit (Unit_Entity)
2330 Unit_Entity := Scope (Unit_Entity);
2334 end Enclosing_Lib_Unit_Entity;
2336 -----------------------------
2337 -- Enclosing_Lib_Unit_Node --
2338 -----------------------------
2340 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2341 Current_Node : Node_Id;
2345 while Present (Current_Node)
2346 and then Nkind (Current_Node) /= N_Compilation_Unit
2348 Current_Node := Parent (Current_Node);
2351 if Nkind (Current_Node) /= N_Compilation_Unit then
2355 return Current_Node;
2356 end Enclosing_Lib_Unit_Node;
2358 --------------------------
2359 -- Enclosing_Subprogram --
2360 --------------------------
2362 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2363 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2366 if Dynamic_Scope = Standard_Standard then
2369 elsif Dynamic_Scope = Empty then
2372 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2373 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2375 elsif Ekind (Dynamic_Scope) = E_Block
2376 or else Ekind (Dynamic_Scope) = E_Return_Statement
2378 return Enclosing_Subprogram (Dynamic_Scope);
2380 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2381 return Get_Task_Body_Procedure (Dynamic_Scope);
2383 elsif Convention (Dynamic_Scope) = Convention_Protected then
2384 return Protected_Body_Subprogram (Dynamic_Scope);
2387 return Dynamic_Scope;
2389 end Enclosing_Subprogram;
2391 ------------------------
2392 -- Ensure_Freeze_Node --
2393 ------------------------
2395 procedure Ensure_Freeze_Node (E : Entity_Id) is
2399 if No (Freeze_Node (E)) then
2400 FN := Make_Freeze_Entity (Sloc (E));
2401 Set_Has_Delayed_Freeze (E);
2402 Set_Freeze_Node (E, FN);
2403 Set_Access_Types_To_Process (FN, No_Elist);
2404 Set_TSS_Elist (FN, No_Elist);
2407 end Ensure_Freeze_Node;
2413 procedure Enter_Name (Def_Id : Entity_Id) is
2414 C : constant Entity_Id := Current_Entity (Def_Id);
2415 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2416 S : constant Entity_Id := Current_Scope;
2419 Generate_Definition (Def_Id);
2421 -- Add new name to current scope declarations. Check for duplicate
2422 -- declaration, which may or may not be a genuine error.
2426 -- Case of previous entity entered because of a missing declaration
2427 -- or else a bad subtype indication. Best is to use the new entity,
2428 -- and make the previous one invisible.
2430 if Etype (E) = Any_Type then
2431 Set_Is_Immediately_Visible (E, False);
2433 -- Case of renaming declaration constructed for package instances.
2434 -- if there is an explicit declaration with the same identifier,
2435 -- the renaming is not immediately visible any longer, but remains
2436 -- visible through selected component notation.
2438 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2439 and then not Comes_From_Source (E)
2441 Set_Is_Immediately_Visible (E, False);
2443 -- The new entity may be the package renaming, which has the same
2444 -- same name as a generic formal which has been seen already.
2446 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2447 and then not Comes_From_Source (Def_Id)
2449 Set_Is_Immediately_Visible (E, False);
2451 -- For a fat pointer corresponding to a remote access to subprogram,
2452 -- we use the same identifier as the RAS type, so that the proper
2453 -- name appears in the stub. This type is only retrieved through
2454 -- the RAS type and never by visibility, and is not added to the
2455 -- visibility list (see below).
2457 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2458 and then Present (Corresponding_Remote_Type (Def_Id))
2462 -- A controller component for a type extension overrides the
2463 -- inherited component.
2465 elsif Chars (E) = Name_uController then
2468 -- Case of an implicit operation or derived literal. The new entity
2469 -- hides the implicit one, which is removed from all visibility,
2470 -- i.e. the entity list of its scope, and homonym chain of its name.
2472 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2473 or else Is_Internal (E)
2477 Prev_Vis : Entity_Id;
2478 Decl : constant Node_Id := Parent (E);
2481 -- If E is an implicit declaration, it cannot be the first
2482 -- entity in the scope.
2484 Prev := First_Entity (Current_Scope);
2485 while Present (Prev)
2486 and then Next_Entity (Prev) /= E
2493 -- If E is not on the entity chain of the current scope,
2494 -- it is an implicit declaration in the generic formal
2495 -- part of a generic subprogram. When analyzing the body,
2496 -- the generic formals are visible but not on the entity
2497 -- chain of the subprogram. The new entity will become
2498 -- the visible one in the body.
2501 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2505 Set_Next_Entity (Prev, Next_Entity (E));
2507 if No (Next_Entity (Prev)) then
2508 Set_Last_Entity (Current_Scope, Prev);
2511 if E = Current_Entity (E) then
2515 Prev_Vis := Current_Entity (E);
2516 while Homonym (Prev_Vis) /= E loop
2517 Prev_Vis := Homonym (Prev_Vis);
2521 if Present (Prev_Vis) then
2523 -- Skip E in the visibility chain
2525 Set_Homonym (Prev_Vis, Homonym (E));
2528 Set_Name_Entity_Id (Chars (E), Homonym (E));
2533 -- This section of code could use a comment ???
2535 elsif Present (Etype (E))
2536 and then Is_Concurrent_Type (Etype (E))
2541 -- If the homograph is a protected component renaming, it should not
2542 -- be hiding the current entity. Such renamings are treated as weak
2545 elsif Is_Prival (E) then
2546 Set_Is_Immediately_Visible (E, False);
2548 -- In this case the current entity is a protected component renaming.
2549 -- Perform minimal decoration by setting the scope and return since
2550 -- the prival should not be hiding other visible entities.
2552 elsif Is_Prival (Def_Id) then
2553 Set_Scope (Def_Id, Current_Scope);
2556 -- Analogous to privals, the discriminal generated for an entry
2557 -- index parameter acts as a weak declaration. Perform minimal
2558 -- decoration to avoid bogus errors.
2560 elsif Is_Discriminal (Def_Id)
2561 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2563 Set_Scope (Def_Id, Current_Scope);
2566 -- In the body or private part of an instance, a type extension
2567 -- may introduce a component with the same name as that of an
2568 -- actual. The legality rule is not enforced, but the semantics
2569 -- of the full type with two components of the same name are not
2570 -- clear at this point ???
2572 elsif In_Instance_Not_Visible then
2575 -- When compiling a package body, some child units may have become
2576 -- visible. They cannot conflict with local entities that hide them.
2578 elsif Is_Child_Unit (E)
2579 and then In_Open_Scopes (Scope (E))
2580 and then not Is_Immediately_Visible (E)
2584 -- Conversely, with front-end inlining we may compile the parent
2585 -- body first, and a child unit subsequently. The context is now
2586 -- the parent spec, and body entities are not visible.
2588 elsif Is_Child_Unit (Def_Id)
2589 and then Is_Package_Body_Entity (E)
2590 and then not In_Package_Body (Current_Scope)
2594 -- Case of genuine duplicate declaration
2597 Error_Msg_Sloc := Sloc (E);
2599 -- If the previous declaration is an incomplete type declaration
2600 -- this may be an attempt to complete it with a private type.
2601 -- The following avoids confusing cascaded errors.
2603 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2604 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2607 ("incomplete type cannot be completed with a private " &
2608 "declaration", Parent (Def_Id));
2609 Set_Is_Immediately_Visible (E, False);
2610 Set_Full_View (E, Def_Id);
2612 -- An inherited component of a record conflicts with a new
2613 -- discriminant. The discriminant is inserted first in the scope,
2614 -- but the error should be posted on it, not on the component.
2616 elsif Ekind (E) = E_Discriminant
2617 and then Present (Scope (Def_Id))
2618 and then Scope (Def_Id) /= Current_Scope
2620 Error_Msg_Sloc := Sloc (Def_Id);
2621 Error_Msg_N ("& conflicts with declaration#", E);
2624 -- If the name of the unit appears in its own context clause,
2625 -- a dummy package with the name has already been created, and
2626 -- the error emitted. Try to continue quietly.
2628 elsif Error_Posted (E)
2629 and then Sloc (E) = No_Location
2630 and then Nkind (Parent (E)) = N_Package_Specification
2631 and then Current_Scope = Standard_Standard
2633 Set_Scope (Def_Id, Current_Scope);
2637 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2639 -- Avoid cascaded messages with duplicate components in
2642 if Ekind (E) = E_Component
2643 or else Ekind (E) = E_Discriminant
2649 if Nkind (Parent (Parent (Def_Id))) =
2650 N_Generic_Subprogram_Declaration
2652 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2654 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2657 -- If entity is in standard, then we are in trouble, because
2658 -- it means that we have a library package with a duplicated
2659 -- name. That's hard to recover from, so abort!
2661 if S = Standard_Standard then
2662 raise Unrecoverable_Error;
2664 -- Otherwise we continue with the declaration. Having two
2665 -- identical declarations should not cause us too much trouble!
2673 -- If we fall through, declaration is OK , or OK enough to continue
2675 -- If Def_Id is a discriminant or a record component we are in the
2676 -- midst of inheriting components in a derived record definition.
2677 -- Preserve their Ekind and Etype.
2679 if Ekind (Def_Id) = E_Discriminant
2680 or else Ekind (Def_Id) = E_Component
2684 -- If a type is already set, leave it alone (happens whey a type
2685 -- declaration is reanalyzed following a call to the optimizer)
2687 elsif Present (Etype (Def_Id)) then
2690 -- Otherwise, the kind E_Void insures that premature uses of the entity
2691 -- will be detected. Any_Type insures that no cascaded errors will occur
2694 Set_Ekind (Def_Id, E_Void);
2695 Set_Etype (Def_Id, Any_Type);
2698 -- Inherited discriminants and components in derived record types are
2699 -- immediately visible. Itypes are not.
2701 if Ekind (Def_Id) = E_Discriminant
2702 or else Ekind (Def_Id) = E_Component
2703 or else (No (Corresponding_Remote_Type (Def_Id))
2704 and then not Is_Itype (Def_Id))
2706 Set_Is_Immediately_Visible (Def_Id);
2707 Set_Current_Entity (Def_Id);
2710 Set_Homonym (Def_Id, C);
2711 Append_Entity (Def_Id, S);
2712 Set_Public_Status (Def_Id);
2714 -- Warn if new entity hides an old one
2716 if Warn_On_Hiding and then Present (C)
2718 -- Don't warn for record components since they always have a well
2719 -- defined scope which does not confuse other uses. Note that in
2720 -- some cases, Ekind has not been set yet.
2722 and then Ekind (C) /= E_Component
2723 and then Ekind (C) /= E_Discriminant
2724 and then Nkind (Parent (C)) /= N_Component_Declaration
2725 and then Ekind (Def_Id) /= E_Component
2726 and then Ekind (Def_Id) /= E_Discriminant
2727 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2729 -- Don't warn for one character variables. It is too common to use
2730 -- such variables as locals and will just cause too many false hits.
2732 and then Length_Of_Name (Chars (C)) /= 1
2734 -- Don't warn for non-source eneities
2736 and then Comes_From_Source (C)
2737 and then Comes_From_Source (Def_Id)
2739 -- Don't warn unless entity in question is in extended main source
2741 and then In_Extended_Main_Source_Unit (Def_Id)
2743 -- Finally, the hidden entity must be either immediately visible
2744 -- or use visible (from a used package)
2747 (Is_Immediately_Visible (C)
2749 Is_Potentially_Use_Visible (C))
2751 Error_Msg_Sloc := Sloc (C);
2752 Error_Msg_N ("declaration hides &#?", Def_Id);
2756 --------------------------
2757 -- Explain_Limited_Type --
2758 --------------------------
2760 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2764 -- For array, component type must be limited
2766 if Is_Array_Type (T) then
2767 Error_Msg_Node_2 := T;
2769 ("\component type& of type& is limited", N, Component_Type (T));
2770 Explain_Limited_Type (Component_Type (T), N);
2772 elsif Is_Record_Type (T) then
2774 -- No need for extra messages if explicit limited record
2776 if Is_Limited_Record (Base_Type (T)) then
2780 -- Otherwise find a limited component. Check only components that
2781 -- come from source, or inherited components that appear in the
2782 -- source of the ancestor.
2784 C := First_Component (T);
2785 while Present (C) loop
2786 if Is_Limited_Type (Etype (C))
2788 (Comes_From_Source (C)
2790 (Present (Original_Record_Component (C))
2792 Comes_From_Source (Original_Record_Component (C))))
2794 Error_Msg_Node_2 := T;
2795 Error_Msg_NE ("\component& of type& has limited type", N, C);
2796 Explain_Limited_Type (Etype (C), N);
2803 -- The type may be declared explicitly limited, even if no component
2804 -- of it is limited, in which case we fall out of the loop.
2807 end Explain_Limited_Type;
2813 procedure Find_Actual
2815 Formal : out Entity_Id;
2818 Parnt : constant Node_Id := Parent (N);
2822 if (Nkind (Parnt) = N_Indexed_Component
2824 Nkind (Parnt) = N_Selected_Component)
2825 and then N = Prefix (Parnt)
2827 Find_Actual (Parnt, Formal, Call);
2830 elsif Nkind (Parnt) = N_Parameter_Association
2831 and then N = Explicit_Actual_Parameter (Parnt)
2833 Call := Parent (Parnt);
2835 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2844 -- If we have a call to a subprogram look for the parameter. Note that
2845 -- we exclude overloaded calls, since we don't know enough to be sure
2846 -- of giving the right answer in this case.
2848 if Is_Entity_Name (Name (Call))
2849 and then Present (Entity (Name (Call)))
2850 and then Is_Overloadable (Entity (Name (Call)))
2851 and then not Is_Overloaded (Name (Call))
2853 -- Fall here if we are definitely a parameter
2855 Actual := First_Actual (Call);
2856 Formal := First_Formal (Entity (Name (Call)));
2857 while Present (Formal) and then Present (Actual) loop
2861 Actual := Next_Actual (Actual);
2862 Formal := Next_Formal (Formal);
2867 -- Fall through here if we did not find matching actual
2873 -------------------------------------
2874 -- Find_Corresponding_Discriminant --
2875 -------------------------------------
2877 function Find_Corresponding_Discriminant
2879 Typ : Entity_Id) return Entity_Id
2881 Par_Disc : Entity_Id;
2882 Old_Disc : Entity_Id;
2883 New_Disc : Entity_Id;
2886 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2888 -- The original type may currently be private, and the discriminant
2889 -- only appear on its full view.
2891 if Is_Private_Type (Scope (Par_Disc))
2892 and then not Has_Discriminants (Scope (Par_Disc))
2893 and then Present (Full_View (Scope (Par_Disc)))
2895 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2897 Old_Disc := First_Discriminant (Scope (Par_Disc));
2900 if Is_Class_Wide_Type (Typ) then
2901 New_Disc := First_Discriminant (Root_Type (Typ));
2903 New_Disc := First_Discriminant (Typ);
2906 while Present (Old_Disc) and then Present (New_Disc) loop
2907 if Old_Disc = Par_Disc then
2910 Next_Discriminant (Old_Disc);
2911 Next_Discriminant (New_Disc);
2915 -- Should always find it
2917 raise Program_Error;
2918 end Find_Corresponding_Discriminant;
2920 --------------------------
2921 -- Find_Overlaid_Object --
2922 --------------------------
2924 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2928 -- We are looking for one of the two following forms:
2930 -- for X'Address use Y'Address
2934 -- Const : constant Address := expr;
2936 -- for X'Address use Const;
2938 -- In the second case, the expr is either Y'Address, or recursively a
2939 -- constant that eventually references Y'Address.
2941 if Nkind (N) = N_Attribute_Definition_Clause
2942 and then Chars (N) = Name_Address
2944 -- This loop checks the form of the expression for Y'Address where Y
2945 -- is an object entity name. The first loop checks the original
2946 -- expression in the attribute definition clause. Subsequent loops
2947 -- check referenced constants.
2949 Expr := Expression (N);
2951 -- Check for Y'Address where Y is an object entity
2953 if Nkind (Expr) = N_Attribute_Reference
2954 and then Attribute_Name (Expr) = Name_Address
2955 and then Is_Entity_Name (Prefix (Expr))
2956 and then Is_Object (Entity (Prefix (Expr)))
2958 return Entity (Prefix (Expr));
2960 -- Check for Const where Const is a constant entity
2962 elsif Is_Entity_Name (Expr)
2963 and then Ekind (Entity (Expr)) = E_Constant
2965 Expr := Constant_Value (Entity (Expr));
2967 -- Anything else does not need checking
2976 end Find_Overlaid_Object;
2978 --------------------------------------------
2979 -- Find_Overridden_Synchronized_Primitive --
2980 --------------------------------------------
2982 function Find_Overridden_Synchronized_Primitive
2983 (Def_Id : Entity_Id;
2984 First_Hom : Entity_Id;
2985 Ifaces_List : Elist_Id;
2986 In_Scope : Boolean) return Entity_Id
2988 Candidate : Entity_Id := Empty;
2989 Hom : Entity_Id := Empty;
2990 Iface_Typ : Entity_Id;
2991 Subp : Entity_Id := Empty;
2992 Tag_Typ : Entity_Id;
2994 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
2995 -- For an overridden subprogram Subp, check whether the mode of its
2996 -- first parameter is correct depending on the kind of Tag_Typ.
2998 function Matches_Prefixed_View_Profile
2999 (Prim_Params : List_Id;
3000 Iface_Params : List_Id) return Boolean;
3001 -- Determine whether a subprogram's parameter profile Prim_Params
3002 -- matches that of a potentially overriden interface subprogram
3003 -- Iface_Params. Also determine if the type of first parameter of
3004 -- Iface_Params is an implemented interface.
3006 -----------------------------
3007 -- Has_Correct_Formal_Mode --
3008 -----------------------------
3010 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
3014 Param := First_Formal (Subp);
3016 -- In order for an entry or a protected procedure to override, the
3017 -- first parameter of the overridden routine must be of mode "out",
3018 -- "in out" or access-to-variable.
3020 if (Ekind (Subp) = E_Entry
3021 or else Ekind (Subp) = E_Procedure)
3022 and then Is_Protected_Type (Tag_Typ)
3023 and then Ekind (Param) /= E_In_Out_Parameter
3024 and then Ekind (Param) /= E_Out_Parameter
3025 and then Nkind (Parameter_Type (Parent (Param))) /=
3031 -- All other cases are OK since a task entry or routine does not
3032 -- have a restriction on the mode of the first parameter of the
3033 -- overridden interface routine.
3036 end Has_Correct_Formal_Mode;
3038 -----------------------------------
3039 -- Matches_Prefixed_View_Profile --
3040 -----------------------------------
3042 function Matches_Prefixed_View_Profile
3043 (Prim_Params : List_Id;
3044 Iface_Params : List_Id) return Boolean
3046 Iface_Id : Entity_Id;
3047 Iface_Param : Node_Id;
3048 Iface_Typ : Entity_Id;
3049 Prim_Id : Entity_Id;
3050 Prim_Param : Node_Id;
3051 Prim_Typ : Entity_Id;
3053 function Is_Implemented (Iface : Entity_Id) return Boolean;
3054 -- Determine if Iface is implemented by the current task or
3057 --------------------
3058 -- Is_Implemented --
3059 --------------------
3061 function Is_Implemented (Iface : Entity_Id) return Boolean is
3062 Iface_Elmt : Elmt_Id;
3065 Iface_Elmt := First_Elmt (Ifaces_List);
3066 while Present (Iface_Elmt) loop
3067 if Node (Iface_Elmt) = Iface then
3071 Next_Elmt (Iface_Elmt);
3077 -- Start of processing for Matches_Prefixed_View_Profile
3080 Iface_Param := First (Iface_Params);
3082 if Nkind (Parameter_Type (Iface_Param)) = N_Access_Definition then
3084 Designated_Type (Etype (Defining_Identifier (Iface_Param)));
3086 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
3089 Prim_Param := First (Prim_Params);
3091 -- The first parameter of the potentially overriden subprogram
3092 -- must be an interface implemented by Prim.
3094 if not Is_Interface (Iface_Typ)
3095 or else not Is_Implemented (Iface_Typ)
3100 -- The checks on the object parameters are done, move onto the rest
3101 -- of the parameters.
3103 if not In_Scope then
3104 Prim_Param := Next (Prim_Param);
3107 Iface_Param := Next (Iface_Param);
3108 while Present (Iface_Param) and then Present (Prim_Param) loop
3109 Iface_Id := Defining_Identifier (Iface_Param);
3110 Iface_Typ := Find_Parameter_Type (Iface_Param);
3111 Prim_Id := Defining_Identifier (Prim_Param);
3112 Prim_Typ := Find_Parameter_Type (Prim_Param);
3114 -- Case of multiple interface types inside a parameter profile
3116 -- (Obj_Param : in out Iface; ...; Param : Iface)
3118 -- If the interface type is implemented, then the matching type
3119 -- in the primitive should be the implementing record type.
3121 if Ekind (Iface_Typ) = E_Record_Type
3122 and then Is_Interface (Iface_Typ)
3123 and then Is_Implemented (Iface_Typ)
3125 if Prim_Typ /= Tag_Typ then
3129 -- The two parameters must be both mode and subtype conformant
3131 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
3133 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
3142 -- One of the two lists contains more parameters than the other
3144 if Present (Iface_Param) or else Present (Prim_Param) then
3149 end Matches_Prefixed_View_Profile;
3151 -- Start of processing for Find_Overridden_Synchronized_Primitive
3154 -- At this point the caller should have collected the interfaces
3155 -- implemented by the synchronized type.
3157 pragma Assert (Present (Ifaces_List));
3159 -- Find the tagged type to which subprogram Def_Id is primitive. If the
3160 -- subprogram was declared within a protected or a task type, the type
3161 -- is the scope itself, otherwise it is the type of the first parameter.
3164 Tag_Typ := Scope (Def_Id);
3166 elsif Present (First_Formal (Def_Id)) then
3167 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
3169 -- A parameterless subprogram which is declared outside a synchronized
3170 -- type cannot act as a primitive, thus it cannot override anything.
3176 -- Traverse the homonym chain, looking at a potentially overriden
3177 -- subprogram that belongs to an implemented interface.
3180 while Present (Hom) loop
3183 -- Entries can override abstract or null interface procedures
3185 if Ekind (Def_Id) = E_Entry
3186 and then Ekind (Subp) = E_Procedure
3187 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3188 and then (Is_Abstract_Subprogram (Subp)
3189 or else Null_Present (Parent (Subp)))
3191 while Present (Alias (Subp)) loop
3192 Subp := Alias (Subp);
3195 if Matches_Prefixed_View_Profile
3196 (Parameter_Specifications (Parent (Def_Id)),
3197 Parameter_Specifications (Parent (Subp)))
3203 if Has_Correct_Formal_Mode (Candidate) then
3208 -- Procedures can override abstract or null interface procedures
3210 elsif Ekind (Def_Id) = E_Procedure
3211 and then Ekind (Subp) = E_Procedure
3212 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3213 and then (Is_Abstract_Subprogram (Subp)
3214 or else Null_Present (Parent (Subp)))
3215 and then Matches_Prefixed_View_Profile
3216 (Parameter_Specifications (Parent (Def_Id)),
3217 Parameter_Specifications (Parent (Subp)))
3223 if Has_Correct_Formal_Mode (Candidate) then
3227 -- Functions can override abstract interface functions
3229 elsif Ekind (Def_Id) = E_Function
3230 and then Ekind (Subp) = E_Function
3231 and then Nkind (Parent (Subp)) = N_Function_Specification
3232 and then Is_Abstract_Subprogram (Subp)
3233 and then Matches_Prefixed_View_Profile
3234 (Parameter_Specifications (Parent (Def_Id)),
3235 Parameter_Specifications (Parent (Subp)))
3236 and then Etype (Result_Definition (Parent (Def_Id))) =
3237 Etype (Result_Definition (Parent (Subp)))
3242 Hom := Homonym (Hom);
3245 -- After examining all candidates for overriding, we are left with
3246 -- the best match which is a mode incompatible interface routine.
3247 -- Do not emit an error if the Expander is active since this error
3248 -- will be detected later on after all concurrent types are expanded
3249 -- and all wrappers are built. This check is meant for spec-only
3252 if Present (Candidate)
3253 and then not Expander_Active
3255 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
3257 -- Def_Id is primitive of a protected type, declared inside the type,
3258 -- and the candidate is primitive of a limited or synchronized
3262 and then Is_Protected_Type (Tag_Typ)
3264 (Is_Limited_Interface (Iface_Typ)
3265 or else Is_Protected_Interface (Iface_Typ)
3266 or else Is_Synchronized_Interface (Iface_Typ)
3267 or else Is_Task_Interface (Iface_Typ))
3269 -- Must reword this message, comma before to in -gnatj mode ???
3272 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3273 "access-to-variable", Tag_Typ, Candidate);
3275 ("\to be overridden by protected procedure or entry " &
3276 "(RM 9.4(11.9/2))", Tag_Typ);
3281 end Find_Overridden_Synchronized_Primitive;
3283 -------------------------
3284 -- Find_Parameter_Type --
3285 -------------------------
3287 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3289 if Nkind (Param) /= N_Parameter_Specification then
3292 -- For an access parameter, obtain the type from the formal entity
3293 -- itself, because access to subprogram nodes do not carry a type.
3294 -- Shouldn't we always use the formal entity ???
3296 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3297 return Etype (Defining_Identifier (Param));
3300 return Etype (Parameter_Type (Param));
3302 end Find_Parameter_Type;
3304 -----------------------------
3305 -- Find_Static_Alternative --
3306 -----------------------------
3308 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3309 Expr : constant Node_Id := Expression (N);
3310 Val : constant Uint := Expr_Value (Expr);
3315 Alt := First (Alternatives (N));
3318 if Nkind (Alt) /= N_Pragma then
3319 Choice := First (Discrete_Choices (Alt));
3320 while Present (Choice) loop
3322 -- Others choice, always matches
3324 if Nkind (Choice) = N_Others_Choice then
3327 -- Range, check if value is in the range
3329 elsif Nkind (Choice) = N_Range then
3331 Val >= Expr_Value (Low_Bound (Choice))
3333 Val <= Expr_Value (High_Bound (Choice));
3335 -- Choice is a subtype name. Note that we know it must
3336 -- be a static subtype, since otherwise it would have
3337 -- been diagnosed as illegal.
3339 elsif Is_Entity_Name (Choice)
3340 and then Is_Type (Entity (Choice))
3342 exit Search when Is_In_Range (Expr, Etype (Choice));
3344 -- Choice is a subtype indication
3346 elsif Nkind (Choice) = N_Subtype_Indication then
3348 C : constant Node_Id := Constraint (Choice);
3349 R : constant Node_Id := Range_Expression (C);
3353 Val >= Expr_Value (Low_Bound (R))
3355 Val <= Expr_Value (High_Bound (R));
3358 -- Choice is a simple expression
3361 exit Search when Val = Expr_Value (Choice);
3369 pragma Assert (Present (Alt));
3372 -- The above loop *must* terminate by finding a match, since
3373 -- we know the case statement is valid, and the value of the
3374 -- expression is known at compile time. When we fall out of
3375 -- the loop, Alt points to the alternative that we know will
3376 -- be selected at run time.
3379 end Find_Static_Alternative;
3385 function First_Actual (Node : Node_Id) return Node_Id is
3389 if No (Parameter_Associations (Node)) then
3393 N := First (Parameter_Associations (Node));
3395 if Nkind (N) = N_Parameter_Association then
3396 return First_Named_Actual (Node);
3402 -------------------------
3403 -- Full_Qualified_Name --
3404 -------------------------
3406 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3408 pragma Warnings (Off, Res);
3410 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3411 -- Compute recursively the qualified name without NUL at the end
3413 ----------------------------------
3414 -- Internal_Full_Qualified_Name --
3415 ----------------------------------
3417 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3418 Ent : Entity_Id := E;
3419 Parent_Name : String_Id := No_String;
3422 -- Deals properly with child units
3424 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3425 Ent := Defining_Identifier (Ent);
3428 -- Compute qualification recursively (only "Standard" has no scope)
3430 if Present (Scope (Scope (Ent))) then
3431 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3434 -- Every entity should have a name except some expanded blocks
3435 -- don't bother about those.
3437 if Chars (Ent) = No_Name then
3441 -- Add a period between Name and qualification
3443 if Parent_Name /= No_String then
3444 Start_String (Parent_Name);
3445 Store_String_Char (Get_Char_Code ('.'));
3451 -- Generates the entity name in upper case
3453 Get_Decoded_Name_String (Chars (Ent));
3455 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3457 end Internal_Full_Qualified_Name;
3459 -- Start of processing for Full_Qualified_Name
3462 Res := Internal_Full_Qualified_Name (E);
3463 Store_String_Char (Get_Char_Code (ASCII.NUL));
3465 end Full_Qualified_Name;
3467 -----------------------
3468 -- Gather_Components --
3469 -----------------------
3471 procedure Gather_Components
3473 Comp_List : Node_Id;
3474 Governed_By : List_Id;
3476 Report_Errors : out Boolean)
3480 Discrete_Choice : Node_Id;
3481 Comp_Item : Node_Id;
3483 Discrim : Entity_Id;
3484 Discrim_Name : Node_Id;
3485 Discrim_Value : Node_Id;
3488 Report_Errors := False;
3490 if No (Comp_List) or else Null_Present (Comp_List) then
3493 elsif Present (Component_Items (Comp_List)) then
3494 Comp_Item := First (Component_Items (Comp_List));
3500 while Present (Comp_Item) loop
3502 -- Skip the tag of a tagged record, the interface tags, as well
3503 -- as all items that are not user components (anonymous types,
3504 -- rep clauses, Parent field, controller field).
3506 if Nkind (Comp_Item) = N_Component_Declaration then
3508 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3510 if not Is_Tag (Comp)
3511 and then Chars (Comp) /= Name_uParent
3512 and then Chars (Comp) /= Name_uController
3514 Append_Elmt (Comp, Into);
3522 if No (Variant_Part (Comp_List)) then
3525 Discrim_Name := Name (Variant_Part (Comp_List));
3526 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3529 -- Look for the discriminant that governs this variant part.
3530 -- The discriminant *must* be in the Governed_By List
3532 Assoc := First (Governed_By);
3533 Find_Constraint : loop
3534 Discrim := First (Choices (Assoc));
3535 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3536 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3538 Chars (Corresponding_Discriminant (Entity (Discrim)))
3539 = Chars (Discrim_Name))
3540 or else Chars (Original_Record_Component (Entity (Discrim)))
3541 = Chars (Discrim_Name);
3543 if No (Next (Assoc)) then
3544 if not Is_Constrained (Typ)
3545 and then Is_Derived_Type (Typ)
3546 and then Present (Stored_Constraint (Typ))
3548 -- If the type is a tagged type with inherited discriminants,
3549 -- use the stored constraint on the parent in order to find
3550 -- the values of discriminants that are otherwise hidden by an
3551 -- explicit constraint. Renamed discriminants are handled in
3554 -- If several parent discriminants are renamed by a single
3555 -- discriminant of the derived type, the call to obtain the
3556 -- Corresponding_Discriminant field only retrieves the last
3557 -- of them. We recover the constraint on the others from the
3558 -- Stored_Constraint as well.
3565 D := First_Discriminant (Etype (Typ));
3566 C := First_Elmt (Stored_Constraint (Typ));
3567 while Present (D) and then Present (C) loop
3568 if Chars (Discrim_Name) = Chars (D) then
3569 if Is_Entity_Name (Node (C))
3570 and then Entity (Node (C)) = Entity (Discrim)
3572 -- D is renamed by Discrim, whose value is given in
3579 Make_Component_Association (Sloc (Typ),
3581 (New_Occurrence_Of (D, Sloc (Typ))),
3582 Duplicate_Subexpr_No_Checks (Node (C)));
3584 exit Find_Constraint;
3587 Next_Discriminant (D);
3594 if No (Next (Assoc)) then
3595 Error_Msg_NE (" missing value for discriminant&",
3596 First (Governed_By), Discrim_Name);
3597 Report_Errors := True;
3602 end loop Find_Constraint;
3604 Discrim_Value := Expression (Assoc);
3606 if not Is_OK_Static_Expression (Discrim_Value) then
3608 ("value for discriminant & must be static!",
3609 Discrim_Value, Discrim);
3610 Why_Not_Static (Discrim_Value);
3611 Report_Errors := True;
3615 Search_For_Discriminant_Value : declare
3621 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3624 Find_Discrete_Value : while Present (Variant) loop
3625 Discrete_Choice := First (Discrete_Choices (Variant));
3626 while Present (Discrete_Choice) loop
3628 exit Find_Discrete_Value when
3629 Nkind (Discrete_Choice) = N_Others_Choice;
3631 Get_Index_Bounds (Discrete_Choice, Low, High);
3633 UI_Low := Expr_Value (Low);
3634 UI_High := Expr_Value (High);
3636 exit Find_Discrete_Value when
3637 UI_Low <= UI_Discrim_Value
3639 UI_High >= UI_Discrim_Value;
3641 Next (Discrete_Choice);
3644 Next_Non_Pragma (Variant);
3645 end loop Find_Discrete_Value;
3646 end Search_For_Discriminant_Value;
3648 if No (Variant) then
3650 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3651 Report_Errors := True;
3655 -- If we have found the corresponding choice, recursively add its
3656 -- components to the Into list.
3658 Gather_Components (Empty,
3659 Component_List (Variant), Governed_By, Into, Report_Errors);
3660 end Gather_Components;
3662 ------------------------
3663 -- Get_Actual_Subtype --
3664 ------------------------
3666 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3667 Typ : constant Entity_Id := Etype (N);
3668 Utyp : Entity_Id := Underlying_Type (Typ);
3677 -- If what we have is an identifier that references a subprogram
3678 -- formal, or a variable or constant object, then we get the actual
3679 -- subtype from the referenced entity if one has been built.
3681 if Nkind (N) = N_Identifier
3683 (Is_Formal (Entity (N))
3684 or else Ekind (Entity (N)) = E_Constant
3685 or else Ekind (Entity (N)) = E_Variable)
3686 and then Present (Actual_Subtype (Entity (N)))
3688 return Actual_Subtype (Entity (N));
3690 -- Actual subtype of unchecked union is always itself. We never need
3691 -- the "real" actual subtype. If we did, we couldn't get it anyway
3692 -- because the discriminant is not available. The restrictions on
3693 -- Unchecked_Union are designed to make sure that this is OK.
3695 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3698 -- Here for the unconstrained case, we must find actual subtype
3699 -- No actual subtype is available, so we must build it on the fly.
3701 -- Checking the type, not the underlying type, for constrainedness
3702 -- seems to be necessary. Maybe all the tests should be on the type???
3704 elsif (not Is_Constrained (Typ))
3705 and then (Is_Array_Type (Utyp)
3706 or else (Is_Record_Type (Utyp)
3707 and then Has_Discriminants (Utyp)))
3708 and then not Has_Unknown_Discriminants (Utyp)
3709 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3711 -- Nothing to do if in spec expression (why not???)
3713 if In_Spec_Expression then
3716 elsif Is_Private_Type (Typ)
3717 and then not Has_Discriminants (Typ)
3719 -- If the type has no discriminants, there is no subtype to
3720 -- build, even if the underlying type is discriminated.
3724 -- Else build the actual subtype
3727 Decl := Build_Actual_Subtype (Typ, N);
3728 Atyp := Defining_Identifier (Decl);
3730 -- If Build_Actual_Subtype generated a new declaration then use it
3734 -- The actual subtype is an Itype, so analyze the declaration,
3735 -- but do not attach it to the tree, to get the type defined.
3737 Set_Parent (Decl, N);
3738 Set_Is_Itype (Atyp);
3739 Analyze (Decl, Suppress => All_Checks);
3740 Set_Associated_Node_For_Itype (Atyp, N);
3741 Set_Has_Delayed_Freeze (Atyp, False);
3743 -- We need to freeze the actual subtype immediately. This is
3744 -- needed, because otherwise this Itype will not get frozen
3745 -- at all, and it is always safe to freeze on creation because
3746 -- any associated types must be frozen at this point.
3748 Freeze_Itype (Atyp, N);
3751 -- Otherwise we did not build a declaration, so return original
3758 -- For all remaining cases, the actual subtype is the same as
3759 -- the nominal type.
3764 end Get_Actual_Subtype;
3766 -------------------------------------
3767 -- Get_Actual_Subtype_If_Available --
3768 -------------------------------------
3770 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3771 Typ : constant Entity_Id := Etype (N);
3774 -- If what we have is an identifier that references a subprogram
3775 -- formal, or a variable or constant object, then we get the actual
3776 -- subtype from the referenced entity if one has been built.
3778 if Nkind (N) = N_Identifier
3780 (Is_Formal (Entity (N))
3781 or else Ekind (Entity (N)) = E_Constant
3782 or else Ekind (Entity (N)) = E_Variable)
3783 and then Present (Actual_Subtype (Entity (N)))
3785 return Actual_Subtype (Entity (N));
3787 -- Otherwise the Etype of N is returned unchanged
3792 end Get_Actual_Subtype_If_Available;
3794 -------------------------------
3795 -- Get_Default_External_Name --
3796 -------------------------------
3798 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3800 Get_Decoded_Name_String (Chars (E));
3802 if Opt.External_Name_Imp_Casing = Uppercase then
3803 Set_Casing (All_Upper_Case);
3805 Set_Casing (All_Lower_Case);
3809 Make_String_Literal (Sloc (E),
3810 Strval => String_From_Name_Buffer);
3811 end Get_Default_External_Name;
3813 ---------------------------
3814 -- Get_Enum_Lit_From_Pos --
3815 ---------------------------
3817 function Get_Enum_Lit_From_Pos
3820 Loc : Source_Ptr) return Node_Id
3825 -- In the case where the literal is of type Character, Wide_Character
3826 -- or Wide_Wide_Character or of a type derived from them, there needs
3827 -- to be some special handling since there is no explicit chain of
3828 -- literals to search. Instead, an N_Character_Literal node is created
3829 -- with the appropriate Char_Code and Chars fields.
3831 if Is_Standard_Character_Type (T) then
3832 Set_Character_Literal_Name (UI_To_CC (Pos));
3834 Make_Character_Literal (Loc,
3836 Char_Literal_Value => Pos);
3838 -- For all other cases, we have a complete table of literals, and
3839 -- we simply iterate through the chain of literal until the one
3840 -- with the desired position value is found.
3844 Lit := First_Literal (Base_Type (T));
3845 for J in 1 .. UI_To_Int (Pos) loop
3849 return New_Occurrence_Of (Lit, Loc);
3851 end Get_Enum_Lit_From_Pos;
3853 ------------------------
3854 -- Get_Generic_Entity --
3855 ------------------------
3857 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3858 Ent : constant Entity_Id := Entity (Name (N));
3860 if Present (Renamed_Object (Ent)) then
3861 return Renamed_Object (Ent);
3865 end Get_Generic_Entity;
3867 ----------------------
3868 -- Get_Index_Bounds --
3869 ----------------------
3871 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3872 Kind : constant Node_Kind := Nkind (N);
3876 if Kind = N_Range then
3878 H := High_Bound (N);
3880 elsif Kind = N_Subtype_Indication then
3881 R := Range_Expression (Constraint (N));
3889 L := Low_Bound (Range_Expression (Constraint (N)));
3890 H := High_Bound (Range_Expression (Constraint (N)));
3893 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3894 if Error_Posted (Scalar_Range (Entity (N))) then
3898 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3899 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3902 L := Low_Bound (Scalar_Range (Entity (N)));
3903 H := High_Bound (Scalar_Range (Entity (N)));
3907 -- N is an expression, indicating a range with one value
3912 end Get_Index_Bounds;
3914 ----------------------------------
3915 -- Get_Library_Unit_Name_string --
3916 ----------------------------------
3918 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3919 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3922 Get_Unit_Name_String (Unit_Name_Id);
3924 -- Remove seven last character (" (spec)" or " (body)")
3926 Name_Len := Name_Len - 7;
3927 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3928 end Get_Library_Unit_Name_String;
3930 ------------------------
3931 -- Get_Name_Entity_Id --
3932 ------------------------
3934 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3936 return Entity_Id (Get_Name_Table_Info (Id));
3937 end Get_Name_Entity_Id;
3943 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3945 return Get_Pragma_Id (Pragma_Name (N));
3948 ---------------------------
3949 -- Get_Referenced_Object --
3950 ---------------------------
3952 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3957 while Is_Entity_Name (R)
3958 and then Present (Renamed_Object (Entity (R)))
3960 R := Renamed_Object (Entity (R));
3964 end Get_Referenced_Object;
3966 ------------------------
3967 -- Get_Renamed_Entity --
3968 ------------------------
3970 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3975 while Present (Renamed_Entity (R)) loop
3976 R := Renamed_Entity (R);
3980 end Get_Renamed_Entity;
3982 -------------------------
3983 -- Get_Subprogram_Body --
3984 -------------------------
3986 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3990 Decl := Unit_Declaration_Node (E);
3992 if Nkind (Decl) = N_Subprogram_Body then
3995 -- The below comment is bad, because it is possible for
3996 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3998 else -- Nkind (Decl) = N_Subprogram_Declaration
4000 if Present (Corresponding_Body (Decl)) then
4001 return Unit_Declaration_Node (Corresponding_Body (Decl));
4003 -- Imported subprogram case
4009 end Get_Subprogram_Body;
4011 ---------------------------
4012 -- Get_Subprogram_Entity --
4013 ---------------------------
4015 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4020 if Nkind (Nod) = N_Accept_Statement then
4021 Nam := Entry_Direct_Name (Nod);
4023 -- For an entry call, the prefix of the call is a selected component.
4024 -- Need additional code for internal calls ???
4026 elsif Nkind (Nod) = N_Entry_Call_Statement then
4027 if Nkind (Name (Nod)) = N_Selected_Component then
4028 Nam := Entity (Selector_Name (Name (Nod)));
4037 if Nkind (Nam) = N_Explicit_Dereference then
4038 Proc := Etype (Prefix (Nam));
4039 elsif Is_Entity_Name (Nam) then
4040 Proc := Entity (Nam);
4045 if Is_Object (Proc) then
4046 Proc := Etype (Proc);
4049 if Ekind (Proc) = E_Access_Subprogram_Type then
4050 Proc := Directly_Designated_Type (Proc);
4053 if not Is_Subprogram (Proc)
4054 and then Ekind (Proc) /= E_Subprogram_Type
4060 end Get_Subprogram_Entity;
4062 -----------------------------
4063 -- Get_Task_Body_Procedure --
4064 -----------------------------
4066 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4068 -- Note: A task type may be the completion of a private type with
4069 -- discriminants. When performing elaboration checks on a task
4070 -- declaration, the current view of the type may be the private one,
4071 -- and the procedure that holds the body of the task is held in its
4074 -- This is an odd function, why not have Task_Body_Procedure do
4075 -- the following digging???
4077 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4078 end Get_Task_Body_Procedure;
4080 -----------------------------
4081 -- Has_Abstract_Interfaces --
4082 -----------------------------
4084 function Has_Abstract_Interfaces
4086 Use_Full_View : Boolean := True) return Boolean
4091 -- Handle concurrent types
4093 if Is_Concurrent_Type (T) then
4094 Typ := Corresponding_Record_Type (T);
4099 if not Present (Typ)
4100 or else not Is_Tagged_Type (Typ)
4105 pragma Assert (Is_Record_Type (Typ));
4107 -- Handle private types
4110 and then Present (Full_View (Typ))
4112 Typ := Full_View (Typ);
4115 -- Handle concurrent record types
4117 if Is_Concurrent_Record_Type (Typ)
4118 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4124 if Is_Interface (Typ)
4126 (Is_Record_Type (Typ)
4127 and then Present (Abstract_Interfaces (Typ))
4128 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
4133 exit when Etype (Typ) = Typ
4135 -- Handle private types
4137 or else (Present (Full_View (Etype (Typ)))
4138 and then Full_View (Etype (Typ)) = Typ)
4140 -- Protect the frontend against wrong source with cyclic
4143 or else Etype (Typ) = T;
4145 -- Climb to the ancestor type handling private types
4147 if Present (Full_View (Etype (Typ))) then
4148 Typ := Full_View (Etype (Typ));
4155 end Has_Abstract_Interfaces;
4157 -----------------------
4158 -- Has_Access_Values --
4159 -----------------------
4161 function Has_Access_Values (T : Entity_Id) return Boolean is
4162 Typ : constant Entity_Id := Underlying_Type (T);
4165 -- Case of a private type which is not completed yet. This can only
4166 -- happen in the case of a generic format type appearing directly, or
4167 -- as a component of the type to which this function is being applied
4168 -- at the top level. Return False in this case, since we certainly do
4169 -- not know that the type contains access types.
4174 elsif Is_Access_Type (Typ) then
4177 elsif Is_Array_Type (Typ) then
4178 return Has_Access_Values (Component_Type (Typ));
4180 elsif Is_Record_Type (Typ) then
4185 -- Loop to Check components
4187 Comp := First_Component_Or_Discriminant (Typ);
4188 while Present (Comp) loop
4190 -- Check for access component, tag field does not count, even
4191 -- though it is implemented internally using an access type.
4193 if Has_Access_Values (Etype (Comp))
4194 and then Chars (Comp) /= Name_uTag
4199 Next_Component_Or_Discriminant (Comp);
4208 end Has_Access_Values;
4210 ------------------------------
4211 -- Has_Compatible_Alignment --
4212 ------------------------------
4214 function Has_Compatible_Alignment
4216 Expr : Node_Id) return Alignment_Result
4218 function Has_Compatible_Alignment_Internal
4221 Default : Alignment_Result) return Alignment_Result;
4222 -- This is the internal recursive function that actually does the work.
4223 -- There is one additional parameter, which says what the result should
4224 -- be if no alignment information is found, and there is no definite
4225 -- indication of compatible alignments. At the outer level, this is set
4226 -- to Unknown, but for internal recursive calls in the case where types
4227 -- are known to be correct, it is set to Known_Compatible.
4229 ---------------------------------------
4230 -- Has_Compatible_Alignment_Internal --
4231 ---------------------------------------
4233 function Has_Compatible_Alignment_Internal
4236 Default : Alignment_Result) return Alignment_Result
4238 Result : Alignment_Result := Known_Compatible;
4239 -- Set to result if Problem_Prefix or Problem_Offset returns True.
4240 -- Note that once a value of Known_Incompatible is set, it is sticky
4241 -- and does not get changed to Unknown (the value in Result only gets
4242 -- worse as we go along, never better).
4244 procedure Check_Offset (Offs : Uint);
4245 -- Called when Expr is a selected or indexed component with Offs set
4246 -- to resp Component_First_Bit or Component_Size. Checks that if the
4247 -- offset is specified it is compatible with the object alignment
4248 -- requirements. The value in Result is modified accordingly.
4250 procedure Check_Prefix;
4251 -- Checks the prefix recursively in the case where the expression
4252 -- is an indexed or selected component.
4254 procedure Set_Result (R : Alignment_Result);
4255 -- If R represents a worse outcome (unknown instead of known
4256 -- compatible, or known incompatible), then set Result to R.
4262 procedure Check_Offset (Offs : Uint) is
4264 -- Unspecified or zero offset is always OK
4266 if Offs = No_Uint or else Offs = Uint_0 then
4269 -- If we do not know required alignment, any non-zero offset is
4270 -- a potential problem (but certainly may be OK, so result is
4273 elsif Unknown_Alignment (Obj) then
4274 Set_Result (Unknown);
4276 -- If we know the required alignment, see if offset is compatible
4279 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
4280 Set_Result (Known_Incompatible);
4289 procedure Check_Prefix is
4291 -- The subtlety here is that in doing a recursive call to check
4292 -- the prefix, we have to decide what to do in the case where we
4293 -- don't find any specific indication of an alignment problem.
4295 -- At the outer level, we normally set Unknown as the result in
4296 -- this case, since we can only set Known_Compatible if we really
4297 -- know that the alignment value is OK, but for the recursive
4298 -- call, in the case where the types match, and we have not
4299 -- specified a peculiar alignment for the object, we are only
4300 -- concerned about suspicious rep clauses, the default case does
4301 -- not affect us, since the compiler will, in the absence of such
4302 -- rep clauses, ensure that the alignment is correct.
4304 if Default = Known_Compatible
4306 (Etype (Obj) = Etype (Expr)
4307 and then (Unknown_Alignment (Obj)
4309 Alignment (Obj) = Alignment (Etype (Obj))))
4312 (Has_Compatible_Alignment_Internal
4313 (Obj, Prefix (Expr), Known_Compatible));
4315 -- In all other cases, we need a full check on the prefix
4319 (Has_Compatible_Alignment_Internal
4320 (Obj, Prefix (Expr), Unknown));
4328 procedure Set_Result (R : Alignment_Result) is
4335 -- Start of processing for Has_Compatible_Alignment_Internal
4338 -- If Expr is a selected component, we must make sure there is no
4339 -- potentially troublesome component clause, and that the record is
4342 if Nkind (Expr) = N_Selected_Component then
4344 -- Packed record always generate unknown alignment
4346 if Is_Packed (Etype (Prefix (Expr))) then
4347 Set_Result (Unknown);
4350 -- Check possible bad component offset and check prefix
4353 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4356 -- If Expr is an indexed component, we must make sure there is no
4357 -- potentially troublesome Component_Size clause and that the array
4358 -- is not bit-packed.
4360 elsif Nkind (Expr) = N_Indexed_Component then
4362 -- Bit packed array always generates unknown alignment
4364 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4365 Set_Result (Unknown);
4368 -- Check possible bad component size and check prefix
4370 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4374 -- Case where we know the alignment of the object
4376 if Known_Alignment (Obj) then
4378 ObjA : constant Uint := Alignment (Obj);
4379 ExpA : Uint := No_Uint;
4380 SizA : Uint := No_Uint;
4383 -- If alignment of Obj is 1, then we are always OK
4386 Set_Result (Known_Compatible);
4388 -- Alignment of Obj is greater than 1, so we need to check
4391 -- See if Expr is an object with known alignment
4393 if Is_Entity_Name (Expr)
4394 and then Known_Alignment (Entity (Expr))
4396 ExpA := Alignment (Entity (Expr));
4398 -- Otherwise, we can use the alignment of the type of
4399 -- Expr given that we already checked for
4400 -- discombobulating rep clauses for the cases of indexed
4401 -- and selected components above.
4403 elsif Known_Alignment (Etype (Expr)) then
4404 ExpA := Alignment (Etype (Expr));
4407 -- If we got an alignment, see if it is acceptable
4409 if ExpA /= No_Uint then
4411 Set_Result (Known_Incompatible);
4414 -- Case of Expr alignment unknown
4417 Set_Result (Default);
4420 -- See if size is given. If so, check that it is not too
4421 -- small for the required alignment.
4422 -- See if Expr is an object with known alignment
4424 if Is_Entity_Name (Expr)
4425 and then Known_Static_Esize (Entity (Expr))
4427 SizA := Esize (Entity (Expr));
4429 -- Otherwise, we check the object size of the Expr type
4431 elsif Known_Static_Esize (Etype (Expr)) then
4432 SizA := Esize (Etype (Expr));
4435 -- If we got a size, see if it is a multiple of the Obj
4436 -- alignment, if not, then the alignment cannot be
4437 -- acceptable, since the size is always a multiple of the
4440 if SizA /= No_Uint then
4441 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4442 Set_Result (Known_Incompatible);
4448 -- If we can't find the result by direct comparison of alignment
4449 -- values, then there is still one case that we can determine known
4450 -- result, and that is when we can determine that the types are the
4451 -- same, and no alignments are specified. Then we known that the
4452 -- alignments are compatible, even if we don't know the alignment
4453 -- value in the front end.
4455 elsif Etype (Obj) = Etype (Expr) then
4457 -- Types are the same, but we have to check for possible size
4458 -- and alignments on the Expr object that may make the alignment
4459 -- different, even though the types are the same.
4461 if Is_Entity_Name (Expr) then
4463 -- First check alignment of the Expr object. Any alignment less
4464 -- than Maximum_Alignment is worrisome since this is the case
4465 -- where we do not know the alignment of Obj.
4467 if Known_Alignment (Entity (Expr))
4469 UI_To_Int (Alignment (Entity (Expr)))
4470 < Ttypes.Maximum_Alignment
4472 Set_Result (Unknown);
4474 -- Now check size of Expr object. Any size that is not an
4475 -- even multiple of Maxiumum_Alignment is also worrisome
4476 -- since it may cause the alignment of the object to be less
4477 -- than the alignment of the type.
4479 elsif Known_Static_Esize (Entity (Expr))
4481 (UI_To_Int (Esize (Entity (Expr))) mod
4482 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4485 Set_Result (Unknown);
4487 -- Otherwise same type is decisive
4490 Set_Result (Known_Compatible);
4494 -- Another case to deal with is when there is an explicit size or
4495 -- alignment clause when the types are not the same. If so, then the
4496 -- result is Unknown. We don't need to do this test if the Default is
4497 -- Unknown, since that result will be set in any case.
4499 elsif Default /= Unknown
4500 and then (Has_Size_Clause (Etype (Expr))
4502 Has_Alignment_Clause (Etype (Expr)))
4504 Set_Result (Unknown);
4506 -- If no indication found, set default
4509 Set_Result (Default);
4512 -- Return worst result found
4515 end Has_Compatible_Alignment_Internal;
4517 -- Start of processing for Has_Compatible_Alignment
4520 -- If Obj has no specified alignment, then set alignment from the type
4521 -- alignment. Perhaps we should always do this, but for sure we should
4522 -- do it when there is an address clause since we can do more if the
4523 -- alignment is known.
4525 if Unknown_Alignment (Obj) then
4526 Set_Alignment (Obj, Alignment (Etype (Obj)));
4529 -- Now do the internal call that does all the work
4531 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4532 end Has_Compatible_Alignment;
4534 ----------------------
4535 -- Has_Declarations --
4536 ----------------------
4538 function Has_Declarations (N : Node_Id) return Boolean is
4539 K : constant Node_Kind := Nkind (N);
4541 return K = N_Accept_Statement
4542 or else K = N_Block_Statement
4543 or else K = N_Compilation_Unit_Aux
4544 or else K = N_Entry_Body
4545 or else K = N_Package_Body
4546 or else K = N_Protected_Body
4547 or else K = N_Subprogram_Body
4548 or else K = N_Task_Body
4549 or else K = N_Package_Specification;
4550 end Has_Declarations;
4552 -------------------------------------------
4553 -- Has_Discriminant_Dependent_Constraint --
4554 -------------------------------------------
4556 function Has_Discriminant_Dependent_Constraint
4557 (Comp : Entity_Id) return Boolean
4559 Comp_Decl : constant Node_Id := Parent (Comp);
4560 Subt_Indic : constant Node_Id :=
4561 Subtype_Indication (Component_Definition (Comp_Decl));
4566 if Nkind (Subt_Indic) = N_Subtype_Indication then
4567 Constr := Constraint (Subt_Indic);
4569 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4570 Assn := First (Constraints (Constr));
4571 while Present (Assn) loop
4572 case Nkind (Assn) is
4573 when N_Subtype_Indication |
4577 if Depends_On_Discriminant (Assn) then
4581 when N_Discriminant_Association =>
4582 if Depends_On_Discriminant (Expression (Assn)) then
4597 end Has_Discriminant_Dependent_Constraint;
4599 --------------------
4600 -- Has_Infinities --
4601 --------------------
4603 function Has_Infinities (E : Entity_Id) return Boolean is
4606 Is_Floating_Point_Type (E)
4607 and then Nkind (Scalar_Range (E)) = N_Range
4608 and then Includes_Infinities (Scalar_Range (E));
4611 ------------------------
4612 -- Has_Null_Exclusion --
4613 ------------------------
4615 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4618 when N_Access_Definition |
4619 N_Access_Function_Definition |
4620 N_Access_Procedure_Definition |
4621 N_Access_To_Object_Definition |
4623 N_Derived_Type_Definition |
4624 N_Function_Specification |
4625 N_Subtype_Declaration =>
4626 return Null_Exclusion_Present (N);
4628 when N_Component_Definition |
4629 N_Formal_Object_Declaration |
4630 N_Object_Renaming_Declaration =>
4631 if Present (Subtype_Mark (N)) then
4632 return Null_Exclusion_Present (N);
4633 else pragma Assert (Present (Access_Definition (N)));
4634 return Null_Exclusion_Present (Access_Definition (N));
4637 when N_Discriminant_Specification =>
4638 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4639 return Null_Exclusion_Present (Discriminant_Type (N));
4641 return Null_Exclusion_Present (N);
4644 when N_Object_Declaration =>
4645 if Nkind (Object_Definition (N)) = N_Access_Definition then
4646 return Null_Exclusion_Present (Object_Definition (N));
4648 return Null_Exclusion_Present (N);
4651 when N_Parameter_Specification =>
4652 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4653 return Null_Exclusion_Present (Parameter_Type (N));
4655 return Null_Exclusion_Present (N);
4662 end Has_Null_Exclusion;
4664 ------------------------
4665 -- Has_Null_Extension --
4666 ------------------------
4668 function Has_Null_Extension (T : Entity_Id) return Boolean is
4669 B : constant Entity_Id := Base_Type (T);
4674 if Nkind (Parent (B)) = N_Full_Type_Declaration
4675 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4677 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4679 if Present (Ext) then
4680 if Null_Present (Ext) then
4683 Comps := Component_List (Ext);
4685 -- The null component list is rewritten during analysis to
4686 -- include the parent component. Any other component indicates
4687 -- that the extension was not originally null.
4689 return Null_Present (Comps)
4690 or else No (Next (First (Component_Items (Comps))));
4699 end Has_Null_Extension;
4701 -------------------------------
4702 -- Has_Overriding_Initialize --
4703 -------------------------------
4705 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4706 BT : constant Entity_Id := Base_Type (T);
4711 if Is_Controlled (BT) then
4713 -- For derived types, check immediate ancestor, excluding
4714 -- Controlled itself.
4716 if Is_Derived_Type (BT)
4717 and then not In_Predefined_Unit (Etype (BT))
4718 and then Has_Overriding_Initialize (Etype (BT))
4722 elsif Present (Primitive_Operations (BT)) then
4723 P := First_Elmt (Primitive_Operations (BT));
4724 while Present (P) loop
4725 if Chars (Node (P)) = Name_Initialize
4726 and then Comes_From_Source (Node (P))
4737 elsif Has_Controlled_Component (BT) then
4738 Comp := First_Component (BT);
4739 while Present (Comp) loop
4740 if Has_Overriding_Initialize (Etype (Comp)) then
4744 Next_Component (Comp);
4752 end Has_Overriding_Initialize;
4754 --------------------------------------
4755 -- Has_Preelaborable_Initialization --
4756 --------------------------------------
4758 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4761 procedure Check_Components (E : Entity_Id);
4762 -- Check component/discriminant chain, sets Has_PE False if a component
4763 -- or discriminant does not meet the preelaborable initialization rules.
4765 ----------------------
4766 -- Check_Components --
4767 ----------------------
4769 procedure Check_Components (E : Entity_Id) is
4773 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4774 -- Returns True if and only if the expression denoted by N does not
4775 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4777 ---------------------------------
4778 -- Is_Preelaborable_Expression --
4779 ---------------------------------
4781 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4785 Comp_Type : Entity_Id;
4786 Is_Array_Aggr : Boolean;
4789 if Is_Static_Expression (N) then
4792 elsif Nkind (N) = N_Null then
4795 -- Attributes are allowed in general, even if their prefix is a
4796 -- formal type. (It seems that certain attributes known not to be
4797 -- static might not be allowed, but there are no rules to prevent
4800 elsif Nkind (N) = N_Attribute_Reference then
4803 -- The name of a discriminant evaluated within its parent type is
4804 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4805 -- names that denote discriminals as well as discriminants to
4806 -- catch references occurring within init procs.
4808 elsif Is_Entity_Name (N)
4810 (Ekind (Entity (N)) = E_Discriminant
4812 ((Ekind (Entity (N)) = E_Constant
4813 or else Ekind (Entity (N)) = E_In_Parameter)
4814 and then Present (Discriminal_Link (Entity (N)))))
4818 elsif Nkind (N) = N_Qualified_Expression then
4819 return Is_Preelaborable_Expression (Expression (N));
4821 -- For aggregates we have to check that each of the associations
4822 -- is preelaborable.
4824 elsif Nkind (N) = N_Aggregate
4825 or else Nkind (N) = N_Extension_Aggregate
4827 Is_Array_Aggr := Is_Array_Type (Etype (N));
4829 if Is_Array_Aggr then
4830 Comp_Type := Component_Type (Etype (N));
4833 -- Check the ancestor part of extension aggregates, which must
4834 -- be either the name of a type that has preelaborable init or
4835 -- an expression that is preelaborable.
4837 if Nkind (N) = N_Extension_Aggregate then
4839 Anc_Part : constant Node_Id := Ancestor_Part (N);
4842 if Is_Entity_Name (Anc_Part)
4843 and then Is_Type (Entity (Anc_Part))
4845 if not Has_Preelaborable_Initialization
4851 elsif not Is_Preelaborable_Expression (Anc_Part) then
4857 -- Check positional associations
4859 Exp := First (Expressions (N));
4860 while Present (Exp) loop
4861 if not Is_Preelaborable_Expression (Exp) then
4868 -- Check named associations
4870 Assn := First (Component_Associations (N));
4871 while Present (Assn) loop
4872 Choice := First (Choices (Assn));
4873 while Present (Choice) loop
4874 if Is_Array_Aggr then
4875 if Nkind (Choice) = N_Others_Choice then
4878 elsif Nkind (Choice) = N_Range then
4879 if not Is_Static_Range (Choice) then
4883 elsif not Is_Static_Expression (Choice) then
4888 Comp_Type := Etype (Choice);
4894 -- If the association has a <> at this point, then we have
4895 -- to check whether the component's type has preelaborable
4896 -- initialization. Note that this only occurs when the
4897 -- association's corresponding component does not have a
4898 -- default expression, the latter case having already been
4899 -- expanded as an expression for the association.
4901 if Box_Present (Assn) then
4902 if not Has_Preelaborable_Initialization (Comp_Type) then
4906 -- In the expression case we check whether the expression
4907 -- is preelaborable.
4910 not Is_Preelaborable_Expression (Expression (Assn))
4918 -- If we get here then aggregate as a whole is preelaborable
4922 -- All other cases are not preelaborable
4927 end Is_Preelaborable_Expression;
4929 -- Start of processing for Check_Components
4932 -- Loop through entities of record or protected type
4935 while Present (Ent) loop
4937 -- We are interested only in components and discriminants
4939 if Ekind (Ent) = E_Component
4941 Ekind (Ent) = E_Discriminant
4943 -- Get default expression if any. If there is no declaration
4944 -- node, it means we have an internal entity. The parent and
4945 -- tag fields are examples of such entitires. For these cases,
4946 -- we just test the type of the entity.
4948 if Present (Declaration_Node (Ent)) then
4949 Exp := Expression (Declaration_Node (Ent));
4954 -- A component has PI if it has no default expression and the
4955 -- component type has PI.
4958 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4963 -- Require the default expression to be preelaborable
4965 elsif not Is_Preelaborable_Expression (Exp) then
4973 end Check_Components;
4975 -- Start of processing for Has_Preelaborable_Initialization
4978 -- Immediate return if already marked as known preelaborable init. This
4979 -- covers types for which this function has already been called once
4980 -- and returned True (in which case the result is cached), and also
4981 -- types to which a pragma Preelaborable_Initialization applies.
4983 if Known_To_Have_Preelab_Init (E) then
4987 -- If the type is a subtype representing a generic actual type, then
4988 -- test whether its base type has preelaborable initialization since
4989 -- the subtype representing the actual does not inherit this attribute
4990 -- from the actual or formal. (but maybe it should???)
4992 if Is_Generic_Actual_Type (E) then
4993 return Has_Preelaborable_Initialization (Base_Type (E));
4996 -- Other private types never have preelaborable initialization
4998 if Is_Private_Type (E) then
5002 -- Here for all non-private view
5004 -- All elementary types have preelaborable initialization
5006 if Is_Elementary_Type (E) then
5009 -- Array types have PI if the component type has PI
5011 elsif Is_Array_Type (E) then
5012 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5014 -- A derived type has preelaborable initialization if its parent type
5015 -- has preelaborable initialization and (in the case of a derived record
5016 -- extension) if the non-inherited components all have preelaborable
5017 -- initialization. However, a user-defined controlled type with an
5018 -- overriding Initialize procedure does not have preelaborable
5021 elsif Is_Derived_Type (E) then
5023 -- First check whether ancestor type has preelaborable initialization
5025 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5027 -- If OK, check extension components (if any)
5029 if Has_PE and then Is_Record_Type (E) then
5030 Check_Components (First_Entity (E));
5033 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5034 -- with a user defined Initialize procedure does not have PI.
5037 and then Is_Controlled (E)
5038 and then Has_Overriding_Initialize (E)
5043 -- Record type has PI if it is non private and all components have PI
5045 elsif Is_Record_Type (E) then
5047 Check_Components (First_Entity (E));
5049 -- Protected types must not have entries, and components must meet
5050 -- same set of rules as for record components.
5052 elsif Is_Protected_Type (E) then
5053 if Has_Entries (E) then
5057 Check_Components (First_Entity (E));
5058 Check_Components (First_Private_Entity (E));
5061 -- Type System.Address always has preelaborable initialization
5063 elsif Is_RTE (E, RE_Address) then
5066 -- In all other cases, type does not have preelaborable initialization
5072 -- If type has preelaborable initialization, cache result
5075 Set_Known_To_Have_Preelab_Init (E);
5079 end Has_Preelaborable_Initialization;
5081 ---------------------------
5082 -- Has_Private_Component --
5083 ---------------------------
5085 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5086 Btype : Entity_Id := Base_Type (Type_Id);
5087 Component : Entity_Id;
5090 if Error_Posted (Type_Id)
5091 or else Error_Posted (Btype)
5096 if Is_Class_Wide_Type (Btype) then
5097 Btype := Root_Type (Btype);
5100 if Is_Private_Type (Btype) then
5102 UT : constant Entity_Id := Underlying_Type (Btype);
5105 if No (Full_View (Btype)) then
5106 return not Is_Generic_Type (Btype)
5107 and then not Is_Generic_Type (Root_Type (Btype));
5109 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5112 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5116 elsif Is_Array_Type (Btype) then
5117 return Has_Private_Component (Component_Type (Btype));
5119 elsif Is_Record_Type (Btype) then
5120 Component := First_Component (Btype);
5121 while Present (Component) loop
5122 if Has_Private_Component (Etype (Component)) then
5126 Next_Component (Component);
5131 elsif Is_Protected_Type (Btype)
5132 and then Present (Corresponding_Record_Type (Btype))
5134 return Has_Private_Component (Corresponding_Record_Type (Btype));
5139 end Has_Private_Component;
5145 function Has_Stream (T : Entity_Id) return Boolean is
5152 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5155 elsif Is_Array_Type (T) then
5156 return Has_Stream (Component_Type (T));
5158 elsif Is_Record_Type (T) then
5159 E := First_Component (T);
5160 while Present (E) loop
5161 if Has_Stream (Etype (E)) then
5170 elsif Is_Private_Type (T) then
5171 return Has_Stream (Underlying_Type (T));
5178 --------------------------
5179 -- Has_Tagged_Component --
5180 --------------------------
5182 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5186 if Is_Private_Type (Typ)
5187 and then Present (Underlying_Type (Typ))
5189 return Has_Tagged_Component (Underlying_Type (Typ));
5191 elsif Is_Array_Type (Typ) then
5192 return Has_Tagged_Component (Component_Type (Typ));
5194 elsif Is_Tagged_Type (Typ) then
5197 elsif Is_Record_Type (Typ) then
5198 Comp := First_Component (Typ);
5199 while Present (Comp) loop
5200 if Has_Tagged_Component (Etype (Comp)) then
5204 Comp := Next_Component (Typ);
5212 end Has_Tagged_Component;
5218 function In_Instance return Boolean is
5219 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5225 and then S /= Standard_Standard
5227 if (Ekind (S) = E_Function
5228 or else Ekind (S) = E_Package
5229 or else Ekind (S) = E_Procedure)
5230 and then Is_Generic_Instance (S)
5232 -- A child instance is always compiled in the context of a parent
5233 -- instance. Nevertheless, the actuals are not analyzed in an
5234 -- instance context. We detect this case by examining the current
5235 -- compilation unit, which must be a child instance, and checking
5236 -- that it is not currently on the scope stack.
5238 if Is_Child_Unit (Curr_Unit)
5240 Nkind (Unit (Cunit (Current_Sem_Unit)))
5241 = N_Package_Instantiation
5242 and then not In_Open_Scopes (Curr_Unit)
5256 ----------------------
5257 -- In_Instance_Body --
5258 ----------------------
5260 function In_Instance_Body return Boolean is
5266 and then S /= Standard_Standard
5268 if (Ekind (S) = E_Function
5269 or else Ekind (S) = E_Procedure)
5270 and then Is_Generic_Instance (S)
5274 elsif Ekind (S) = E_Package
5275 and then In_Package_Body (S)
5276 and then Is_Generic_Instance (S)
5285 end In_Instance_Body;
5287 -----------------------------
5288 -- In_Instance_Not_Visible --
5289 -----------------------------
5291 function In_Instance_Not_Visible return Boolean is
5297 and then S /= Standard_Standard
5299 if (Ekind (S) = E_Function
5300 or else Ekind (S) = E_Procedure)
5301 and then Is_Generic_Instance (S)
5305 elsif Ekind (S) = E_Package
5306 and then (In_Package_Body (S) or else In_Private_Part (S))
5307 and then Is_Generic_Instance (S)
5316 end In_Instance_Not_Visible;
5318 ------------------------------
5319 -- In_Instance_Visible_Part --
5320 ------------------------------
5322 function In_Instance_Visible_Part return Boolean is
5328 and then S /= Standard_Standard
5330 if Ekind (S) = E_Package
5331 and then Is_Generic_Instance (S)
5332 and then not In_Package_Body (S)
5333 and then not In_Private_Part (S)
5342 end In_Instance_Visible_Part;
5344 ----------------------
5345 -- In_Packiage_Body --
5346 ----------------------
5348 function In_Package_Body return Boolean is
5354 and then S /= Standard_Standard
5356 if Ekind (S) = E_Package
5357 and then In_Package_Body (S)
5366 end In_Package_Body;
5368 --------------------------------------
5369 -- In_Subprogram_Or_Concurrent_Unit --
5370 --------------------------------------
5372 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5377 -- Use scope chain to check successively outer scopes
5383 if K in Subprogram_Kind
5384 or else K in Concurrent_Kind
5385 or else K in Generic_Subprogram_Kind
5389 elsif E = Standard_Standard then
5395 end In_Subprogram_Or_Concurrent_Unit;
5397 ---------------------
5398 -- In_Visible_Part --
5399 ---------------------
5401 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5404 Is_Package_Or_Generic_Package (Scope_Id)
5405 and then In_Open_Scopes (Scope_Id)
5406 and then not In_Package_Body (Scope_Id)
5407 and then not In_Private_Part (Scope_Id);
5408 end In_Visible_Part;
5410 ---------------------------------
5411 -- Insert_Explicit_Dereference --
5412 ---------------------------------
5414 procedure Insert_Explicit_Dereference (N : Node_Id) is
5415 New_Prefix : constant Node_Id := Relocate_Node (N);
5416 Ent : Entity_Id := Empty;
5423 Save_Interps (N, New_Prefix);
5425 Make_Explicit_Dereference (Sloc (N),
5426 Prefix => New_Prefix));
5428 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5430 if Is_Overloaded (New_Prefix) then
5432 -- The deference is also overloaded, and its interpretations are the
5433 -- designated types of the interpretations of the original node.
5435 Set_Etype (N, Any_Type);
5437 Get_First_Interp (New_Prefix, I, It);
5438 while Present (It.Nam) loop
5441 if Is_Access_Type (T) then
5442 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5445 Get_Next_Interp (I, It);
5451 -- Prefix is unambiguous: mark the original prefix (which might
5452 -- Come_From_Source) as a reference, since the new (relocated) one
5453 -- won't be taken into account.
5455 if Is_Entity_Name (New_Prefix) then
5456 Ent := Entity (New_Prefix);
5458 -- For a retrieval of a subcomponent of some composite object,
5459 -- retrieve the ultimate entity if there is one.
5461 elsif Nkind (New_Prefix) = N_Selected_Component
5462 or else Nkind (New_Prefix) = N_Indexed_Component
5464 Pref := Prefix (New_Prefix);
5465 while Present (Pref)
5467 (Nkind (Pref) = N_Selected_Component
5468 or else Nkind (Pref) = N_Indexed_Component)
5470 Pref := Prefix (Pref);
5473 if Present (Pref) and then Is_Entity_Name (Pref) then
5474 Ent := Entity (Pref);
5478 if Present (Ent) then
5479 Generate_Reference (Ent, New_Prefix);
5482 end Insert_Explicit_Dereference;
5488 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5489 pragma Assert (Is_Type (E));
5491 return AAMP_On_Target
5492 and then Is_Floating_Point_Type (E)
5493 and then E = Base_Type (E);
5496 -------------------------
5497 -- Is_Actual_Parameter --
5498 -------------------------
5500 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5501 PK : constant Node_Kind := Nkind (Parent (N));
5505 when N_Parameter_Association =>
5506 return N = Explicit_Actual_Parameter (Parent (N));
5508 when N_Function_Call | N_Procedure_Call_Statement =>
5509 return Is_List_Member (N)
5511 List_Containing (N) = Parameter_Associations (Parent (N));
5516 end Is_Actual_Parameter;
5518 ---------------------
5519 -- Is_Aliased_View --
5520 ---------------------
5522 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5526 if Is_Entity_Name (Obj) then
5534 or else (Present (Renamed_Object (E))
5535 and then Is_Aliased_View (Renamed_Object (E)))))
5537 or else ((Is_Formal (E)
5538 or else Ekind (E) = E_Generic_In_Out_Parameter
5539 or else Ekind (E) = E_Generic_In_Parameter)
5540 and then Is_Tagged_Type (Etype (E)))
5542 or else (Is_Concurrent_Type (E)
5543 and then In_Open_Scopes (E))
5545 -- Current instance of type, either directly or as rewritten
5546 -- reference to the current object.
5548 or else (Is_Entity_Name (Original_Node (Obj))
5549 and then Present (Entity (Original_Node (Obj)))
5550 and then Is_Type (Entity (Original_Node (Obj))))
5552 or else (Is_Type (E) and then E = Current_Scope)
5554 or else (Is_Incomplete_Or_Private_Type (E)
5555 and then Full_View (E) = Current_Scope);
5557 elsif Nkind (Obj) = N_Selected_Component then
5558 return Is_Aliased (Entity (Selector_Name (Obj)));
5560 elsif Nkind (Obj) = N_Indexed_Component then
5561 return Has_Aliased_Components (Etype (Prefix (Obj)))
5563 (Is_Access_Type (Etype (Prefix (Obj)))
5565 Has_Aliased_Components
5566 (Designated_Type (Etype (Prefix (Obj)))));
5568 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5569 or else Nkind (Obj) = N_Type_Conversion
5571 return Is_Tagged_Type (Etype (Obj))
5572 and then Is_Aliased_View (Expression (Obj));
5574 elsif Nkind (Obj) = N_Explicit_Dereference then
5575 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5580 end Is_Aliased_View;
5582 -------------------------
5583 -- Is_Ancestor_Package --
5584 -------------------------
5586 function Is_Ancestor_Package
5588 E2 : Entity_Id) return Boolean
5595 and then Par /= Standard_Standard
5605 end Is_Ancestor_Package;
5607 ----------------------
5608 -- Is_Atomic_Object --
5609 ----------------------
5611 function Is_Atomic_Object (N : Node_Id) return Boolean is
5613 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5614 -- Determines if given object has atomic components
5616 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5617 -- If prefix is an implicit dereference, examine designated type
5619 ----------------------
5620 -- Is_Atomic_Prefix --
5621 ----------------------
5623 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5625 if Is_Access_Type (Etype (N)) then
5627 Has_Atomic_Components (Designated_Type (Etype (N)));
5629 return Object_Has_Atomic_Components (N);
5631 end Is_Atomic_Prefix;
5633 ----------------------------------
5634 -- Object_Has_Atomic_Components --
5635 ----------------------------------
5637 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5639 if Has_Atomic_Components (Etype (N))
5640 or else Is_Atomic (Etype (N))
5644 elsif Is_Entity_Name (N)
5645 and then (Has_Atomic_Components (Entity (N))
5646 or else Is_Atomic (Entity (N)))
5650 elsif Nkind (N) = N_Indexed_Component
5651 or else Nkind (N) = N_Selected_Component
5653 return Is_Atomic_Prefix (Prefix (N));
5658 end Object_Has_Atomic_Components;
5660 -- Start of processing for Is_Atomic_Object
5663 if Is_Atomic (Etype (N))
5664 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5668 elsif Nkind (N) = N_Indexed_Component
5669 or else Nkind (N) = N_Selected_Component
5671 return Is_Atomic_Prefix (Prefix (N));
5676 end Is_Atomic_Object;
5678 -------------------------
5679 -- Is_Coextension_Root --
5680 -------------------------
5682 function Is_Coextension_Root (N : Node_Id) return Boolean is
5685 Nkind (N) = N_Allocator
5686 and then Present (Coextensions (N))
5688 -- Anonymous access discriminants carry a list of all nested
5689 -- controlled coextensions.
5691 and then not Is_Dynamic_Coextension (N)
5692 and then not Is_Static_Coextension (N);
5693 end Is_Coextension_Root;
5695 -----------------------------
5696 -- Is_Concurrent_Interface --
5697 -----------------------------
5699 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5704 (Is_Protected_Interface (T)
5705 or else Is_Synchronized_Interface (T)
5706 or else Is_Task_Interface (T));
5707 end Is_Concurrent_Interface;
5709 --------------------------------------
5710 -- Is_Controlling_Limited_Procedure --
5711 --------------------------------------
5713 function Is_Controlling_Limited_Procedure
5714 (Proc_Nam : Entity_Id) return Boolean
5716 Param_Typ : Entity_Id := Empty;
5719 if Ekind (Proc_Nam) = E_Procedure
5720 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5722 Param_Typ := Etype (Parameter_Type (First (
5723 Parameter_Specifications (Parent (Proc_Nam)))));
5725 -- In this case where an Itype was created, the procedure call has been
5728 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5729 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5731 Present (Parameter_Associations
5732 (Associated_Node_For_Itype (Proc_Nam)))
5735 Etype (First (Parameter_Associations
5736 (Associated_Node_For_Itype (Proc_Nam))));
5739 if Present (Param_Typ) then
5741 Is_Interface (Param_Typ)
5742 and then Is_Limited_Record (Param_Typ);
5746 end Is_Controlling_Limited_Procedure;
5748 ----------------------------------------------
5749 -- Is_Dependent_Component_Of_Mutable_Object --
5750 ----------------------------------------------
5752 function Is_Dependent_Component_Of_Mutable_Object
5753 (Object : Node_Id) return Boolean
5756 Prefix_Type : Entity_Id;
5757 P_Aliased : Boolean := False;
5760 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5761 -- Returns True if and only if Comp is declared within a variant part
5763 --------------------------------
5764 -- Is_Declared_Within_Variant --
5765 --------------------------------
5767 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5768 Comp_Decl : constant Node_Id := Parent (Comp);
5769 Comp_List : constant Node_Id := Parent (Comp_Decl);
5771 return Nkind (Parent (Comp_List)) = N_Variant;
5772 end Is_Declared_Within_Variant;
5774 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5777 if Is_Variable (Object) then
5779 if Nkind (Object) = N_Selected_Component then
5780 P := Prefix (Object);
5781 Prefix_Type := Etype (P);
5783 if Is_Entity_Name (P) then
5785 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5786 Prefix_Type := Base_Type (Prefix_Type);
5789 if Is_Aliased (Entity (P)) then
5793 -- A discriminant check on a selected component may be
5794 -- expanded into a dereference when removing side-effects.
5795 -- Recover the original node and its type, which may be
5798 elsif Nkind (P) = N_Explicit_Dereference
5799 and then not (Comes_From_Source (P))
5801 P := Original_Node (P);
5802 Prefix_Type := Etype (P);
5805 -- Check for prefix being an aliased component ???
5810 -- A heap object is constrained by its initial value
5812 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5813 -- the dereferenced case, since the access value might denote an
5814 -- unconstrained aliased object, whereas in Ada 95 the designated
5815 -- object is guaranteed to be constrained. A worst-case assumption
5816 -- has to apply in Ada 2005 because we can't tell at compile time
5817 -- whether the object is "constrained by its initial value"
5818 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5819 -- semantic rules -- these rules are acknowledged to need fixing).
5821 if Ada_Version < Ada_05 then
5822 if Is_Access_Type (Prefix_Type)
5823 or else Nkind (P) = N_Explicit_Dereference
5828 elsif Ada_Version >= Ada_05 then
5829 if Is_Access_Type (Prefix_Type) then
5831 -- If the access type is pool-specific, and there is no
5832 -- constrained partial view of the designated type, then the
5833 -- designated object is known to be constrained.
5835 if Ekind (Prefix_Type) = E_Access_Type
5836 and then not Has_Constrained_Partial_View
5837 (Designated_Type (Prefix_Type))
5841 -- Otherwise (general access type, or there is a constrained
5842 -- partial view of the designated type), we need to check
5843 -- based on the designated type.
5846 Prefix_Type := Designated_Type (Prefix_Type);
5852 Original_Record_Component (Entity (Selector_Name (Object)));
5854 -- As per AI-0017, the renaming is illegal in a generic body,
5855 -- even if the subtype is indefinite.
5857 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5859 if not Is_Constrained (Prefix_Type)
5860 and then (not Is_Indefinite_Subtype (Prefix_Type)
5862 (Is_Generic_Type (Prefix_Type)
5863 and then Ekind (Current_Scope) = E_Generic_Package
5864 and then In_Package_Body (Current_Scope)))
5866 and then (Is_Declared_Within_Variant (Comp)
5867 or else Has_Discriminant_Dependent_Constraint (Comp))
5868 and then (not P_Aliased or else Ada_Version >= Ada_05)
5874 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5878 elsif Nkind (Object) = N_Indexed_Component
5879 or else Nkind (Object) = N_Slice
5881 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5883 -- A type conversion that Is_Variable is a view conversion:
5884 -- go back to the denoted object.
5886 elsif Nkind (Object) = N_Type_Conversion then
5888 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5893 end Is_Dependent_Component_Of_Mutable_Object;
5895 ---------------------
5896 -- Is_Dereferenced --
5897 ---------------------
5899 function Is_Dereferenced (N : Node_Id) return Boolean is
5900 P : constant Node_Id := Parent (N);
5903 (Nkind (P) = N_Selected_Component
5905 Nkind (P) = N_Explicit_Dereference
5907 Nkind (P) = N_Indexed_Component
5909 Nkind (P) = N_Slice)
5910 and then Prefix (P) = N;
5911 end Is_Dereferenced;
5913 ----------------------
5914 -- Is_Descendent_Of --
5915 ----------------------
5917 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5922 pragma Assert (Nkind (T1) in N_Entity);
5923 pragma Assert (Nkind (T2) in N_Entity);
5925 T := Base_Type (T1);
5927 -- Immediate return if the types match
5932 -- Comment needed here ???
5934 elsif Ekind (T) = E_Class_Wide_Type then
5935 return Etype (T) = T2;
5943 -- Done if we found the type we are looking for
5948 -- Done if no more derivations to check
5955 -- Following test catches error cases resulting from prev errors
5957 elsif No (Etyp) then
5960 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5963 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5967 T := Base_Type (Etyp);
5970 end Is_Descendent_Of;
5976 function Is_False (U : Uint) return Boolean is
5981 ---------------------------
5982 -- Is_Fixed_Model_Number --
5983 ---------------------------
5985 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5986 S : constant Ureal := Small_Value (T);
5987 M : Urealp.Save_Mark;
5991 R := (U = UR_Trunc (U / S) * S);
5994 end Is_Fixed_Model_Number;
5996 -------------------------------
5997 -- Is_Fully_Initialized_Type --
5998 -------------------------------
6000 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6002 if Is_Scalar_Type (Typ) then
6005 elsif Is_Access_Type (Typ) then
6008 elsif Is_Array_Type (Typ) then
6009 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6013 -- An interesting case, if we have a constrained type one of whose
6014 -- bounds is known to be null, then there are no elements to be
6015 -- initialized, so all the elements are initialized!
6017 if Is_Constrained (Typ) then
6020 Indx_Typ : Entity_Id;
6024 Indx := First_Index (Typ);
6025 while Present (Indx) loop
6026 if Etype (Indx) = Any_Type then
6029 -- If index is a range, use directly
6031 elsif Nkind (Indx) = N_Range then
6032 Lbd := Low_Bound (Indx);
6033 Hbd := High_Bound (Indx);
6036 Indx_Typ := Etype (Indx);
6038 if Is_Private_Type (Indx_Typ) then
6039 Indx_Typ := Full_View (Indx_Typ);
6042 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6045 Lbd := Type_Low_Bound (Indx_Typ);
6046 Hbd := Type_High_Bound (Indx_Typ);
6050 if Compile_Time_Known_Value (Lbd)
6051 and then Compile_Time_Known_Value (Hbd)
6053 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6063 -- If no null indexes, then type is not fully initialized
6069 elsif Is_Record_Type (Typ) then
6070 if Has_Discriminants (Typ)
6072 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6073 and then Is_Fully_Initialized_Variant (Typ)
6078 -- Controlled records are considered to be fully initialized if
6079 -- there is a user defined Initialize routine. This may not be
6080 -- entirely correct, but as the spec notes, we are guessing here
6081 -- what is best from the point of view of issuing warnings.
6083 if Is_Controlled (Typ) then
6085 Utyp : constant Entity_Id := Underlying_Type (Typ);
6088 if Present (Utyp) then
6090 Init : constant Entity_Id :=
6092 (Underlying_Type (Typ), Name_Initialize));
6096 and then Comes_From_Source (Init)
6098 Is_Predefined_File_Name
6099 (File_Name (Get_Source_File_Index (Sloc (Init))))
6103 elsif Has_Null_Extension (Typ)
6105 Is_Fully_Initialized_Type
6106 (Etype (Base_Type (Typ)))
6115 -- Otherwise see if all record components are initialized
6121 Ent := First_Entity (Typ);
6122 while Present (Ent) loop
6123 if Chars (Ent) = Name_uController then
6126 elsif Ekind (Ent) = E_Component
6127 and then (No (Parent (Ent))
6128 or else No (Expression (Parent (Ent))))
6129 and then not Is_Fully_Initialized_Type (Etype (Ent))
6131 -- Special VM case for tag components, which need to be
6132 -- defined in this case, but are never initialized as VMs
6133 -- are using other dispatching mechanisms. Ignore this
6134 -- uninitialized case. Note that this applies both to the
6135 -- uTag entry and the main vtable pointer (CPP_Class case).
6137 and then (VM_Target = No_VM or else not Is_Tag (Ent))
6146 -- No uninitialized components, so type is fully initialized.
6147 -- Note that this catches the case of no components as well.
6151 elsif Is_Concurrent_Type (Typ) then
6154 elsif Is_Private_Type (Typ) then
6156 U : constant Entity_Id := Underlying_Type (Typ);
6162 return Is_Fully_Initialized_Type (U);
6169 end Is_Fully_Initialized_Type;
6171 ----------------------------------
6172 -- Is_Fully_Initialized_Variant --
6173 ----------------------------------
6175 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6176 Loc : constant Source_Ptr := Sloc (Typ);
6177 Constraints : constant List_Id := New_List;
6178 Components : constant Elist_Id := New_Elmt_List;
6179 Comp_Elmt : Elmt_Id;
6181 Comp_List : Node_Id;
6183 Discr_Val : Node_Id;
6185 Report_Errors : Boolean;
6186 pragma Warnings (Off, Report_Errors);
6189 if Serious_Errors_Detected > 0 then
6193 if Is_Record_Type (Typ)
6194 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6195 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6197 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6199 Discr := First_Discriminant (Typ);
6200 while Present (Discr) loop
6201 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6202 Discr_Val := Expression (Parent (Discr));
6204 if Present (Discr_Val)
6205 and then Is_OK_Static_Expression (Discr_Val)
6207 Append_To (Constraints,
6208 Make_Component_Association (Loc,
6209 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6210 Expression => New_Copy (Discr_Val)));
6218 Next_Discriminant (Discr);
6223 Comp_List => Comp_List,
6224 Governed_By => Constraints,
6226 Report_Errors => Report_Errors);
6228 -- Check that each component present is fully initialized
6230 Comp_Elmt := First_Elmt (Components);
6231 while Present (Comp_Elmt) loop
6232 Comp_Id := Node (Comp_Elmt);
6234 if Ekind (Comp_Id) = E_Component
6235 and then (No (Parent (Comp_Id))
6236 or else No (Expression (Parent (Comp_Id))))
6237 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6242 Next_Elmt (Comp_Elmt);
6247 elsif Is_Private_Type (Typ) then
6249 U : constant Entity_Id := Underlying_Type (Typ);
6255 return Is_Fully_Initialized_Variant (U);
6261 end Is_Fully_Initialized_Variant;
6263 ----------------------------
6264 -- Is_Inherited_Operation --
6265 ----------------------------
6267 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6268 Kind : constant Node_Kind := Nkind (Parent (E));
6270 pragma Assert (Is_Overloadable (E));
6271 return Kind = N_Full_Type_Declaration
6272 or else Kind = N_Private_Extension_Declaration
6273 or else Kind = N_Subtype_Declaration
6274 or else (Ekind (E) = E_Enumeration_Literal
6275 and then Is_Derived_Type (Etype (E)));
6276 end Is_Inherited_Operation;
6278 -----------------------------
6279 -- Is_Library_Level_Entity --
6280 -----------------------------
6282 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6284 -- The following is a small optimization, and it also properly handles
6285 -- discriminals, which in task bodies might appear in expressions before
6286 -- the corresponding procedure has been created, and which therefore do
6287 -- not have an assigned scope.
6289 if Ekind (E) in Formal_Kind then
6293 -- Normal test is simply that the enclosing dynamic scope is Standard
6295 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6296 end Is_Library_Level_Entity;
6298 ---------------------------------
6299 -- Is_Local_Variable_Reference --
6300 ---------------------------------
6302 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6304 if not Is_Entity_Name (Expr) then
6309 Ent : constant Entity_Id := Entity (Expr);
6310 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6312 if Ekind (Ent) /= E_Variable
6314 Ekind (Ent) /= E_In_Out_Parameter
6318 return Present (Sub) and then Sub = Current_Subprogram;
6322 end Is_Local_Variable_Reference;
6324 -------------------------
6325 -- Is_Object_Reference --
6326 -------------------------
6328 function Is_Object_Reference (N : Node_Id) return Boolean is
6330 if Is_Entity_Name (N) then
6331 return Present (Entity (N)) and then Is_Object (Entity (N));
6335 when N_Indexed_Component | N_Slice =>
6337 Is_Object_Reference (Prefix (N))
6338 or else Is_Access_Type (Etype (Prefix (N)));
6340 -- In Ada95, a function call is a constant object; a procedure
6343 when N_Function_Call =>
6344 return Etype (N) /= Standard_Void_Type;
6346 -- A reference to the stream attribute Input is a function call
6348 when N_Attribute_Reference =>
6349 return Attribute_Name (N) = Name_Input;
6351 when N_Selected_Component =>
6353 Is_Object_Reference (Selector_Name (N))
6355 (Is_Object_Reference (Prefix (N))
6356 or else Is_Access_Type (Etype (Prefix (N))));
6358 when N_Explicit_Dereference =>
6361 -- A view conversion of a tagged object is an object reference
6363 when N_Type_Conversion =>
6364 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6365 and then Is_Tagged_Type (Etype (Expression (N)))
6366 and then Is_Object_Reference (Expression (N));
6368 -- An unchecked type conversion is considered to be an object if
6369 -- the operand is an object (this construction arises only as a
6370 -- result of expansion activities).
6372 when N_Unchecked_Type_Conversion =>
6379 end Is_Object_Reference;
6381 -----------------------------------
6382 -- Is_OK_Variable_For_Out_Formal --
6383 -----------------------------------
6385 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6387 Note_Possible_Modification (AV, Sure => True);
6389 -- We must reject parenthesized variable names. The check for
6390 -- Comes_From_Source is present because there are currently
6391 -- cases where the compiler violates this rule (e.g. passing
6392 -- a task object to its controlled Initialize routine).
6394 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6397 -- A variable is always allowed
6399 elsif Is_Variable (AV) then
6402 -- Unchecked conversions are allowed only if they come from the
6403 -- generated code, which sometimes uses unchecked conversions for out
6404 -- parameters in cases where code generation is unaffected. We tell
6405 -- source unchecked conversions by seeing if they are rewrites of an
6406 -- original Unchecked_Conversion function call, or of an explicit
6407 -- conversion of a function call.
6409 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6410 if Nkind (Original_Node (AV)) = N_Function_Call then
6413 elsif Comes_From_Source (AV)
6414 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6418 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6419 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6425 -- Normal type conversions are allowed if argument is a variable
6427 elsif Nkind (AV) = N_Type_Conversion then
6428 if Is_Variable (Expression (AV))
6429 and then Paren_Count (Expression (AV)) = 0
6431 Note_Possible_Modification (Expression (AV), Sure => True);
6434 -- We also allow a non-parenthesized expression that raises
6435 -- constraint error if it rewrites what used to be a variable
6437 elsif Raises_Constraint_Error (Expression (AV))
6438 and then Paren_Count (Expression (AV)) = 0
6439 and then Is_Variable (Original_Node (Expression (AV)))
6443 -- Type conversion of something other than a variable
6449 -- If this node is rewritten, then test the original form, if that is
6450 -- OK, then we consider the rewritten node OK (for example, if the
6451 -- original node is a conversion, then Is_Variable will not be true
6452 -- but we still want to allow the conversion if it converts a variable).
6454 elsif Original_Node (AV) /= AV then
6455 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6457 -- All other non-variables are rejected
6462 end Is_OK_Variable_For_Out_Formal;
6470 E2 : Entity_Id) return Boolean
6472 Iface_List : List_Id;
6473 T : Entity_Id := E2;
6476 if Is_Concurrent_Type (T)
6477 or else Is_Concurrent_Record_Type (T)
6479 Iface_List := Abstract_Interface_List (E2);
6481 if Is_Empty_List (Iface_List) then
6485 T := Etype (First (Iface_List));
6488 return Is_Ancestor (E1, T);
6491 -----------------------------------
6492 -- Is_Partially_Initialized_Type --
6493 -----------------------------------
6495 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6497 if Is_Scalar_Type (Typ) then
6500 elsif Is_Access_Type (Typ) then
6503 elsif Is_Array_Type (Typ) then
6505 -- If component type is partially initialized, so is array type
6507 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6510 -- Otherwise we are only partially initialized if we are fully
6511 -- initialized (this is the empty array case, no point in us
6512 -- duplicating that code here).
6515 return Is_Fully_Initialized_Type (Typ);
6518 elsif Is_Record_Type (Typ) then
6520 -- A discriminated type is always partially initialized
6522 if Has_Discriminants (Typ) then
6525 -- A tagged type is always partially initialized
6527 elsif Is_Tagged_Type (Typ) then
6530 -- Case of non-discriminated record
6536 Component_Present : Boolean := False;
6537 -- Set True if at least one component is present. If no
6538 -- components are present, then record type is fully
6539 -- initialized (another odd case, like the null array).
6542 -- Loop through components
6544 Ent := First_Entity (Typ);
6545 while Present (Ent) loop
6546 if Ekind (Ent) = E_Component then
6547 Component_Present := True;
6549 -- If a component has an initialization expression then
6550 -- the enclosing record type is partially initialized
6552 if Present (Parent (Ent))
6553 and then Present (Expression (Parent (Ent)))
6557 -- If a component is of a type which is itself partially
6558 -- initialized, then the enclosing record type is also.
6560 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6568 -- No initialized components found. If we found any components
6569 -- they were all uninitialized so the result is false.
6571 if Component_Present then
6574 -- But if we found no components, then all the components are
6575 -- initialized so we consider the type to be initialized.
6583 -- Concurrent types are always fully initialized
6585 elsif Is_Concurrent_Type (Typ) then
6588 -- For a private type, go to underlying type. If there is no underlying
6589 -- type then just assume this partially initialized. Not clear if this
6590 -- can happen in a non-error case, but no harm in testing for this.
6592 elsif Is_Private_Type (Typ) then
6594 U : constant Entity_Id := Underlying_Type (Typ);
6599 return Is_Partially_Initialized_Type (U);
6603 -- For any other type (are there any?) assume partially initialized
6608 end Is_Partially_Initialized_Type;
6610 ------------------------------------
6611 -- Is_Potentially_Persistent_Type --
6612 ------------------------------------
6614 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6619 -- For private type, test corrresponding full type
6621 if Is_Private_Type (T) then
6622 return Is_Potentially_Persistent_Type (Full_View (T));
6624 -- Scalar types are potentially persistent
6626 elsif Is_Scalar_Type (T) then
6629 -- Record type is potentially persistent if not tagged and the types of
6630 -- all it components are potentially persistent, and no component has
6631 -- an initialization expression.
6633 elsif Is_Record_Type (T)
6634 and then not Is_Tagged_Type (T)
6635 and then not Is_Partially_Initialized_Type (T)
6637 Comp := First_Component (T);
6638 while Present (Comp) loop
6639 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6648 -- Array type is potentially persistent if its component type is
6649 -- potentially persistent and if all its constraints are static.
6651 elsif Is_Array_Type (T) then
6652 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6656 Indx := First_Index (T);
6657 while Present (Indx) loop
6658 if not Is_OK_Static_Subtype (Etype (Indx)) then
6667 -- All other types are not potentially persistent
6672 end Is_Potentially_Persistent_Type;
6674 -----------------------------
6675 -- Is_RCI_Pkg_Spec_Or_Body --
6676 -----------------------------
6678 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6680 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6681 -- Return True if the unit of Cunit is an RCI package declaration
6683 ---------------------------
6684 -- Is_RCI_Pkg_Decl_Cunit --
6685 ---------------------------
6687 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6688 The_Unit : constant Node_Id := Unit (Cunit);
6691 if Nkind (The_Unit) /= N_Package_Declaration then
6695 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6696 end Is_RCI_Pkg_Decl_Cunit;
6698 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6701 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6703 (Nkind (Unit (Cunit)) = N_Package_Body
6704 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6705 end Is_RCI_Pkg_Spec_Or_Body;
6707 -----------------------------------------
6708 -- Is_Remote_Access_To_Class_Wide_Type --
6709 -----------------------------------------
6711 function Is_Remote_Access_To_Class_Wide_Type
6712 (E : Entity_Id) return Boolean
6716 function Comes_From_Limited_Private_Type_Declaration
6717 (E : Entity_Id) return Boolean;
6718 -- Check that the type is declared by a limited type declaration,
6719 -- or else is derived from a Remote_Type ancestor through private
6722 -------------------------------------------------
6723 -- Comes_From_Limited_Private_Type_Declaration --
6724 -------------------------------------------------
6726 function Comes_From_Limited_Private_Type_Declaration
6727 (E : Entity_Id) return Boolean
6729 N : constant Node_Id := Declaration_Node (E);
6732 if Nkind (N) = N_Private_Type_Declaration
6733 and then Limited_Present (N)
6738 if Nkind (N) = N_Private_Extension_Declaration then
6740 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6742 (Is_Remote_Types (Etype (E))
6743 and then Is_Limited_Record (Etype (E))
6744 and then Has_Private_Declaration (Etype (E)));
6748 end Comes_From_Limited_Private_Type_Declaration;
6750 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6753 if not (Is_Remote_Call_Interface (E)
6754 or else Is_Remote_Types (E))
6755 or else Ekind (E) /= E_General_Access_Type
6760 D := Designated_Type (E);
6762 if Ekind (D) /= E_Class_Wide_Type then
6766 return Comes_From_Limited_Private_Type_Declaration
6767 (Defining_Identifier (Parent (D)));
6768 end Is_Remote_Access_To_Class_Wide_Type;
6770 -----------------------------------------
6771 -- Is_Remote_Access_To_Subprogram_Type --
6772 -----------------------------------------
6774 function Is_Remote_Access_To_Subprogram_Type
6775 (E : Entity_Id) return Boolean
6778 return (Ekind (E) = E_Access_Subprogram_Type
6779 or else (Ekind (E) = E_Record_Type
6780 and then Present (Corresponding_Remote_Type (E))))
6781 and then (Is_Remote_Call_Interface (E)
6782 or else Is_Remote_Types (E));
6783 end Is_Remote_Access_To_Subprogram_Type;
6785 --------------------
6786 -- Is_Remote_Call --
6787 --------------------
6789 function Is_Remote_Call (N : Node_Id) return Boolean is
6791 if Nkind (N) /= N_Procedure_Call_Statement
6792 and then Nkind (N) /= N_Function_Call
6794 -- An entry call cannot be remote
6798 elsif Nkind (Name (N)) in N_Has_Entity
6799 and then Is_Remote_Call_Interface (Entity (Name (N)))
6801 -- A subprogram declared in the spec of a RCI package is remote
6805 elsif Nkind (Name (N)) = N_Explicit_Dereference
6806 and then Is_Remote_Access_To_Subprogram_Type
6807 (Etype (Prefix (Name (N))))
6809 -- The dereference of a RAS is a remote call
6813 elsif Present (Controlling_Argument (N))
6814 and then Is_Remote_Access_To_Class_Wide_Type
6815 (Etype (Controlling_Argument (N)))
6817 -- Any primitive operation call with a controlling argument of
6818 -- a RACW type is a remote call.
6823 -- All other calls are local calls
6828 ----------------------
6829 -- Is_Renamed_Entry --
6830 ----------------------
6832 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6833 Orig_Node : Node_Id := Empty;
6834 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6836 function Is_Entry (Nam : Node_Id) return Boolean;
6837 -- Determine whether Nam is an entry. Traverse selectors
6838 -- if there are nested selected components.
6844 function Is_Entry (Nam : Node_Id) return Boolean is
6846 if Nkind (Nam) = N_Selected_Component then
6847 return Is_Entry (Selector_Name (Nam));
6850 return Ekind (Entity (Nam)) = E_Entry;
6853 -- Start of processing for Is_Renamed_Entry
6856 if Present (Alias (Proc_Nam)) then
6857 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6860 -- Look for a rewritten subprogram renaming declaration
6862 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6863 and then Present (Original_Node (Subp_Decl))
6865 Orig_Node := Original_Node (Subp_Decl);
6868 -- The rewritten subprogram is actually an entry
6870 if Present (Orig_Node)
6871 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6872 and then Is_Entry (Name (Orig_Node))
6878 end Is_Renamed_Entry;
6880 ----------------------
6881 -- Is_Selector_Name --
6882 ----------------------
6884 function Is_Selector_Name (N : Node_Id) return Boolean is
6886 if not Is_List_Member (N) then
6888 P : constant Node_Id := Parent (N);
6889 K : constant Node_Kind := Nkind (P);
6892 (K = N_Expanded_Name or else
6893 K = N_Generic_Association or else
6894 K = N_Parameter_Association or else
6895 K = N_Selected_Component)
6896 and then Selector_Name (P) = N;
6901 L : constant List_Id := List_Containing (N);
6902 P : constant Node_Id := Parent (L);
6904 return (Nkind (P) = N_Discriminant_Association
6905 and then Selector_Names (P) = L)
6907 (Nkind (P) = N_Component_Association
6908 and then Choices (P) = L);
6911 end Is_Selector_Name;
6917 function Is_Statement (N : Node_Id) return Boolean is
6920 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6921 or else Nkind (N) = N_Procedure_Call_Statement;
6924 ---------------------------------
6925 -- Is_Synchronized_Tagged_Type --
6926 ---------------------------------
6928 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6929 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6932 -- A task or protected type derived from an interface is a tagged type.
6933 -- Such a tagged type is called a synchronized tagged type, as are
6934 -- synchronized interfaces and private extensions whose declaration
6935 -- includes the reserved word synchronized.
6937 return (Is_Tagged_Type (E)
6938 and then (Kind = E_Task_Type
6939 or else Kind = E_Protected_Type))
6942 and then Is_Synchronized_Interface (E))
6944 (Ekind (E) = E_Record_Type_With_Private
6945 and then (Synchronized_Present (Parent (E))
6946 or else Is_Synchronized_Interface (Etype (E))));
6947 end Is_Synchronized_Tagged_Type;
6953 function Is_Transfer (N : Node_Id) return Boolean is
6954 Kind : constant Node_Kind := Nkind (N);
6957 if Kind = N_Simple_Return_Statement
6959 Kind = N_Extended_Return_Statement
6961 Kind = N_Goto_Statement
6963 Kind = N_Raise_Statement
6965 Kind = N_Requeue_Statement
6969 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6970 and then No (Condition (N))
6974 elsif Kind = N_Procedure_Call_Statement
6975 and then Is_Entity_Name (Name (N))
6976 and then Present (Entity (Name (N)))
6977 and then No_Return (Entity (Name (N)))
6981 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6993 function Is_True (U : Uint) return Boolean is
7002 function Is_Value_Type (T : Entity_Id) return Boolean is
7004 return VM_Target = CLI_Target
7005 and then Chars (T) /= No_Name
7006 and then Get_Name_String (Chars (T)) = "valuetype";
7013 function Is_Variable (N : Node_Id) return Boolean is
7015 Orig_Node : constant Node_Id := Original_Node (N);
7016 -- We do the test on the original node, since this is basically a
7017 -- test of syntactic categories, so it must not be disturbed by
7018 -- whatever rewriting might have occurred. For example, an aggregate,
7019 -- which is certainly NOT a variable, could be turned into a variable
7022 function In_Protected_Function (E : Entity_Id) return Boolean;
7023 -- Within a protected function, the private components of the
7024 -- enclosing protected type are constants. A function nested within
7025 -- a (protected) procedure is not itself protected.
7027 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7028 -- Prefixes can involve implicit dereferences, in which case we
7029 -- must test for the case of a reference of a constant access
7030 -- type, which can never be a variable.
7032 ---------------------------
7033 -- In_Protected_Function --
7034 ---------------------------
7036 function In_Protected_Function (E : Entity_Id) return Boolean is
7037 Prot : constant Entity_Id := Scope (E);
7041 if not Is_Protected_Type (Prot) then
7045 while Present (S) and then S /= Prot loop
7046 if Ekind (S) = E_Function
7047 and then Scope (S) = Prot
7057 end In_Protected_Function;
7059 ------------------------
7060 -- Is_Variable_Prefix --
7061 ------------------------
7063 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7065 if Is_Access_Type (Etype (P)) then
7066 return not Is_Access_Constant (Root_Type (Etype (P)));
7068 -- For the case of an indexed component whose prefix has a packed
7069 -- array type, the prefix has been rewritten into a type conversion.
7070 -- Determine variable-ness from the converted expression.
7072 elsif Nkind (P) = N_Type_Conversion
7073 and then not Comes_From_Source (P)
7074 and then Is_Array_Type (Etype (P))
7075 and then Is_Packed (Etype (P))
7077 return Is_Variable (Expression (P));
7080 return Is_Variable (P);
7082 end Is_Variable_Prefix;
7084 -- Start of processing for Is_Variable
7087 -- Definitely OK if Assignment_OK is set. Since this is something that
7088 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7090 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7093 -- Normally we go to the original node, but there is one exception
7094 -- where we use the rewritten node, namely when it is an explicit
7095 -- dereference. The generated code may rewrite a prefix which is an
7096 -- access type with an explicit dereference. The dereference is a
7097 -- variable, even though the original node may not be (since it could
7098 -- be a constant of the access type).
7100 -- In Ada 2005 we have a further case to consider: the prefix may be
7101 -- a function call given in prefix notation. The original node appears
7102 -- to be a selected component, but we need to examine the call.
7104 elsif Nkind (N) = N_Explicit_Dereference
7105 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7106 and then Present (Etype (Orig_Node))
7107 and then Is_Access_Type (Etype (Orig_Node))
7109 return Is_Variable_Prefix (Original_Node (Prefix (N)))
7111 (Nkind (Orig_Node) = N_Function_Call
7112 and then not Is_Access_Constant (Etype (Prefix (N))));
7114 -- A function call is never a variable
7116 elsif Nkind (N) = N_Function_Call then
7119 -- All remaining checks use the original node
7121 elsif Is_Entity_Name (Orig_Node)
7122 and then Present (Entity (Orig_Node))
7125 E : constant Entity_Id := Entity (Orig_Node);
7126 K : constant Entity_Kind := Ekind (E);
7129 return (K = E_Variable
7130 and then Nkind (Parent (E)) /= N_Exception_Handler)
7131 or else (K = E_Component
7132 and then not In_Protected_Function (E))
7133 or else K = E_Out_Parameter
7134 or else K = E_In_Out_Parameter
7135 or else K = E_Generic_In_Out_Parameter
7137 -- Current instance of type:
7139 or else (Is_Type (E) and then In_Open_Scopes (E))
7140 or else (Is_Incomplete_Or_Private_Type (E)
7141 and then In_Open_Scopes (Full_View (E)));
7145 case Nkind (Orig_Node) is
7146 when N_Indexed_Component | N_Slice =>
7147 return Is_Variable_Prefix (Prefix (Orig_Node));
7149 when N_Selected_Component =>
7150 return Is_Variable_Prefix (Prefix (Orig_Node))
7151 and then Is_Variable (Selector_Name (Orig_Node));
7153 -- For an explicit dereference, the type of the prefix cannot
7154 -- be an access to constant or an access to subprogram.
7156 when N_Explicit_Dereference =>
7158 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7160 return Is_Access_Type (Typ)
7161 and then not Is_Access_Constant (Root_Type (Typ))
7162 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7165 -- The type conversion is the case where we do not deal with the
7166 -- context dependent special case of an actual parameter. Thus
7167 -- the type conversion is only considered a variable for the
7168 -- purposes of this routine if the target type is tagged. However,
7169 -- a type conversion is considered to be a variable if it does not
7170 -- come from source (this deals for example with the conversions
7171 -- of expressions to their actual subtypes).
7173 when N_Type_Conversion =>
7174 return Is_Variable (Expression (Orig_Node))
7176 (not Comes_From_Source (Orig_Node)
7178 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7180 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7182 -- GNAT allows an unchecked type conversion as a variable. This
7183 -- only affects the generation of internal expanded code, since
7184 -- calls to instantiations of Unchecked_Conversion are never
7185 -- considered variables (since they are function calls).
7186 -- This is also true for expression actions.
7188 when N_Unchecked_Type_Conversion =>
7189 return Is_Variable (Expression (Orig_Node));
7197 ------------------------
7198 -- Is_Volatile_Object --
7199 ------------------------
7201 function Is_Volatile_Object (N : Node_Id) return Boolean is
7203 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7204 -- Determines if given object has volatile components
7206 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7207 -- If prefix is an implicit dereference, examine designated type
7209 ------------------------
7210 -- Is_Volatile_Prefix --
7211 ------------------------
7213 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7214 Typ : constant Entity_Id := Etype (N);
7217 if Is_Access_Type (Typ) then
7219 Dtyp : constant Entity_Id := Designated_Type (Typ);
7222 return Is_Volatile (Dtyp)
7223 or else Has_Volatile_Components (Dtyp);
7227 return Object_Has_Volatile_Components (N);
7229 end Is_Volatile_Prefix;
7231 ------------------------------------
7232 -- Object_Has_Volatile_Components --
7233 ------------------------------------
7235 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7236 Typ : constant Entity_Id := Etype (N);
7239 if Is_Volatile (Typ)
7240 or else Has_Volatile_Components (Typ)
7244 elsif Is_Entity_Name (N)
7245 and then (Has_Volatile_Components (Entity (N))
7246 or else Is_Volatile (Entity (N)))
7250 elsif Nkind (N) = N_Indexed_Component
7251 or else Nkind (N) = N_Selected_Component
7253 return Is_Volatile_Prefix (Prefix (N));
7258 end Object_Has_Volatile_Components;
7260 -- Start of processing for Is_Volatile_Object
7263 if Is_Volatile (Etype (N))
7264 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7268 elsif Nkind (N) = N_Indexed_Component
7269 or else Nkind (N) = N_Selected_Component
7271 return Is_Volatile_Prefix (Prefix (N));
7276 end Is_Volatile_Object;
7278 -------------------------
7279 -- Kill_Current_Values --
7280 -------------------------
7282 procedure Kill_Current_Values
7284 Last_Assignment_Only : Boolean := False)
7287 if Is_Assignable (Ent) then
7288 Set_Last_Assignment (Ent, Empty);
7291 if not Last_Assignment_Only and then Is_Object (Ent) then
7293 Set_Current_Value (Ent, Empty);
7295 if not Can_Never_Be_Null (Ent) then
7296 Set_Is_Known_Non_Null (Ent, False);
7299 Set_Is_Known_Null (Ent, False);
7301 end Kill_Current_Values;
7303 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7306 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7307 -- Clear current value for entity E and all entities chained to E
7309 ------------------------------------------
7310 -- Kill_Current_Values_For_Entity_Chain --
7311 ------------------------------------------
7313 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7317 while Present (Ent) loop
7318 Kill_Current_Values (Ent, Last_Assignment_Only);
7321 end Kill_Current_Values_For_Entity_Chain;
7323 -- Start of processing for Kill_Current_Values
7326 -- Kill all saved checks, a special case of killing saved values
7328 if not Last_Assignment_Only then
7332 -- Loop through relevant scopes, which includes the current scope and
7333 -- any parent scopes if the current scope is a block or a package.
7338 -- Clear current values of all entities in current scope
7340 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7342 -- If scope is a package, also clear current values of all
7343 -- private entities in the scope.
7345 if Ekind (S) = E_Package
7347 Ekind (S) = E_Generic_Package
7349 Is_Concurrent_Type (S)
7351 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7354 -- If this is a not a subprogram, deal with parents
7356 if not Is_Subprogram (S) then
7358 exit Scope_Loop when S = Standard_Standard;
7362 end loop Scope_Loop;
7363 end Kill_Current_Values;
7365 --------------------------
7366 -- Kill_Size_Check_Code --
7367 --------------------------
7369 procedure Kill_Size_Check_Code (E : Entity_Id) is
7371 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7372 and then Present (Size_Check_Code (E))
7374 Remove (Size_Check_Code (E));
7375 Set_Size_Check_Code (E, Empty);
7377 end Kill_Size_Check_Code;
7379 --------------------------
7380 -- Known_To_Be_Assigned --
7381 --------------------------
7383 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7384 P : constant Node_Id := Parent (N);
7389 -- Test left side of assignment
7391 when N_Assignment_Statement =>
7392 return N = Name (P);
7394 -- Function call arguments are never lvalues
7396 when N_Function_Call =>
7399 -- Positional parameter for procedure or accept call
7401 when N_Procedure_Call_Statement |
7410 Proc := Get_Subprogram_Entity (P);
7416 -- If we are not a list member, something is strange, so
7417 -- be conservative and return False.
7419 if not Is_List_Member (N) then
7423 -- We are going to find the right formal by stepping forward
7424 -- through the formals, as we step backwards in the actuals.
7426 Form := First_Formal (Proc);
7429 -- If no formal, something is weird, so be conservative
7430 -- and return False.
7441 return Ekind (Form) /= E_In_Parameter;
7444 -- Named parameter for procedure or accept call
7446 when N_Parameter_Association =>
7452 Proc := Get_Subprogram_Entity (Parent (P));
7458 -- Loop through formals to find the one that matches
7460 Form := First_Formal (Proc);
7462 -- If no matching formal, that's peculiar, some kind of
7463 -- previous error, so return False to be conservative.
7469 -- Else test for match
7471 if Chars (Form) = Chars (Selector_Name (P)) then
7472 return Ekind (Form) /= E_In_Parameter;
7479 -- Test for appearing in a conversion that itself appears
7480 -- in an lvalue context, since this should be an lvalue.
7482 when N_Type_Conversion =>
7483 return Known_To_Be_Assigned (P);
7485 -- All other references are definitely not knwon to be modifications
7491 end Known_To_Be_Assigned;
7497 function May_Be_Lvalue (N : Node_Id) return Boolean is
7498 P : constant Node_Id := Parent (N);
7503 -- Test left side of assignment
7505 when N_Assignment_Statement =>
7506 return N = Name (P);
7508 -- Test prefix of component or attribute
7510 when N_Attribute_Reference =>
7511 return N = Prefix (P)
7512 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7514 when N_Expanded_Name |
7515 N_Explicit_Dereference |
7516 N_Indexed_Component |
7518 N_Selected_Component |
7520 return N = Prefix (P);
7522 -- Function call arguments are never lvalues
7524 when N_Function_Call =>
7527 -- Positional parameter for procedure, entry, or accept call
7529 when N_Procedure_Call_Statement |
7530 N_Entry_Call_Statement |
7539 Proc := Get_Subprogram_Entity (P);
7545 -- If we are not a list member, something is strange, so
7546 -- be conservative and return True.
7548 if not Is_List_Member (N) then
7552 -- We are going to find the right formal by stepping forward
7553 -- through the formals, as we step backwards in the actuals.
7555 Form := First_Formal (Proc);
7558 -- If no formal, something is weird, so be conservative
7570 return Ekind (Form) /= E_In_Parameter;
7573 -- Named parameter for procedure or accept call
7575 when N_Parameter_Association =>
7581 Proc := Get_Subprogram_Entity (Parent (P));
7587 -- Loop through formals to find the one that matches
7589 Form := First_Formal (Proc);
7591 -- If no matching formal, that's peculiar, some kind of
7592 -- previous error, so return True to be conservative.
7598 -- Else test for match
7600 if Chars (Form) = Chars (Selector_Name (P)) then
7601 return Ekind (Form) /= E_In_Parameter;
7608 -- Test for appearing in a conversion that itself appears in an
7609 -- lvalue context, since this should be an lvalue.
7611 when N_Type_Conversion =>
7612 return May_Be_Lvalue (P);
7614 -- Test for appearence in object renaming declaration
7616 when N_Object_Renaming_Declaration =>
7619 -- All other references are definitely not Lvalues
7627 -----------------------
7628 -- Mark_Coextensions --
7629 -----------------------
7631 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7632 Is_Dynamic : Boolean;
7633 -- Indicates whether the context causes nested coextensions to be
7634 -- dynamic or static
7636 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7637 -- Recognize an allocator node and label it as a dynamic coextension
7639 --------------------
7640 -- Mark_Allocator --
7641 --------------------
7643 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7645 if Nkind (N) = N_Allocator then
7647 Set_Is_Dynamic_Coextension (N);
7649 Set_Is_Static_Coextension (N);
7656 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7658 -- Start of processing Mark_Coextensions
7661 case Nkind (Context_Nod) is
7662 when N_Assignment_Statement |
7663 N_Simple_Return_Statement =>
7664 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7666 when N_Object_Declaration =>
7667 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7669 -- This routine should not be called for constructs which may not
7670 -- contain coextensions.
7673 raise Program_Error;
7676 Mark_Allocators (Root_Nod);
7677 end Mark_Coextensions;
7679 ----------------------
7680 -- Needs_One_Actual --
7681 ----------------------
7683 function Needs_One_Actual (E : Entity_Id) return Boolean is
7687 if Ada_Version >= Ada_05
7688 and then Present (First_Formal (E))
7690 Formal := Next_Formal (First_Formal (E));
7691 while Present (Formal) loop
7692 if No (Default_Value (Formal)) then
7696 Next_Formal (Formal);
7704 end Needs_One_Actual;
7706 -------------------------
7707 -- New_External_Entity --
7708 -------------------------
7710 function New_External_Entity
7711 (Kind : Entity_Kind;
7712 Scope_Id : Entity_Id;
7713 Sloc_Value : Source_Ptr;
7714 Related_Id : Entity_Id;
7716 Suffix_Index : Nat := 0;
7717 Prefix : Character := ' ') return Entity_Id
7719 N : constant Entity_Id :=
7720 Make_Defining_Identifier (Sloc_Value,
7722 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7725 Set_Ekind (N, Kind);
7726 Set_Is_Internal (N, True);
7727 Append_Entity (N, Scope_Id);
7728 Set_Public_Status (N);
7730 if Kind in Type_Kind then
7731 Init_Size_Align (N);
7735 end New_External_Entity;
7737 -------------------------
7738 -- New_Internal_Entity --
7739 -------------------------
7741 function New_Internal_Entity
7742 (Kind : Entity_Kind;
7743 Scope_Id : Entity_Id;
7744 Sloc_Value : Source_Ptr;
7745 Id_Char : Character) return Entity_Id
7747 N : constant Entity_Id :=
7748 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7751 Set_Ekind (N, Kind);
7752 Set_Is_Internal (N, True);
7753 Append_Entity (N, Scope_Id);
7755 if Kind in Type_Kind then
7756 Init_Size_Align (N);
7760 end New_Internal_Entity;
7766 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7770 -- If we are pointing at a positional parameter, it is a member of a
7771 -- node list (the list of parameters), and the next parameter is the
7772 -- next node on the list, unless we hit a parameter association, then
7773 -- we shift to using the chain whose head is the First_Named_Actual in
7774 -- the parent, and then is threaded using the Next_Named_Actual of the
7775 -- Parameter_Association. All this fiddling is because the original node
7776 -- list is in the textual call order, and what we need is the
7777 -- declaration order.
7779 if Is_List_Member (Actual_Id) then
7780 N := Next (Actual_Id);
7782 if Nkind (N) = N_Parameter_Association then
7783 return First_Named_Actual (Parent (Actual_Id));
7789 return Next_Named_Actual (Parent (Actual_Id));
7793 procedure Next_Actual (Actual_Id : in out Node_Id) is
7795 Actual_Id := Next_Actual (Actual_Id);
7798 -----------------------
7799 -- Normalize_Actuals --
7800 -----------------------
7802 -- Chain actuals according to formals of subprogram. If there are no named
7803 -- associations, the chain is simply the list of Parameter Associations,
7804 -- since the order is the same as the declaration order. If there are named
7805 -- associations, then the First_Named_Actual field in the N_Function_Call
7806 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7807 -- node for the parameter that comes first in declaration order. The
7808 -- remaining named parameters are then chained in declaration order using
7809 -- Next_Named_Actual.
7811 -- This routine also verifies that the number of actuals is compatible with
7812 -- the number and default values of formals, but performs no type checking
7813 -- (type checking is done by the caller).
7815 -- If the matching succeeds, Success is set to True and the caller proceeds
7816 -- with type-checking. If the match is unsuccessful, then Success is set to
7817 -- False, and the caller attempts a different interpretation, if there is
7820 -- If the flag Report is on, the call is not overloaded, and a failure to
7821 -- match can be reported here, rather than in the caller.
7823 procedure Normalize_Actuals
7827 Success : out Boolean)
7829 Actuals : constant List_Id := Parameter_Associations (N);
7830 Actual : Node_Id := Empty;
7832 Last : Node_Id := Empty;
7833 First_Named : Node_Id := Empty;
7836 Formals_To_Match : Integer := 0;
7837 Actuals_To_Match : Integer := 0;
7839 procedure Chain (A : Node_Id);
7840 -- Add named actual at the proper place in the list, using the
7841 -- Next_Named_Actual link.
7843 function Reporting return Boolean;
7844 -- Determines if an error is to be reported. To report an error, we
7845 -- need Report to be True, and also we do not report errors caused
7846 -- by calls to init procs that occur within other init procs. Such
7847 -- errors must always be cascaded errors, since if all the types are
7848 -- declared correctly, the compiler will certainly build decent calls!
7854 procedure Chain (A : Node_Id) is
7858 -- Call node points to first actual in list
7860 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7863 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7867 Set_Next_Named_Actual (Last, Empty);
7874 function Reporting return Boolean is
7879 elsif not Within_Init_Proc then
7882 elsif Is_Init_Proc (Entity (Name (N))) then
7890 -- Start of processing for Normalize_Actuals
7893 if Is_Access_Type (S) then
7895 -- The name in the call is a function call that returns an access
7896 -- to subprogram. The designated type has the list of formals.
7898 Formal := First_Formal (Designated_Type (S));
7900 Formal := First_Formal (S);
7903 while Present (Formal) loop
7904 Formals_To_Match := Formals_To_Match + 1;
7905 Next_Formal (Formal);
7908 -- Find if there is a named association, and verify that no positional
7909 -- associations appear after named ones.
7911 if Present (Actuals) then
7912 Actual := First (Actuals);
7915 while Present (Actual)
7916 and then Nkind (Actual) /= N_Parameter_Association
7918 Actuals_To_Match := Actuals_To_Match + 1;
7922 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7924 -- Most common case: positional notation, no defaults
7929 elsif Actuals_To_Match > Formals_To_Match then
7931 -- Too many actuals: will not work
7934 if Is_Entity_Name (Name (N)) then
7935 Error_Msg_N ("too many arguments in call to&", Name (N));
7937 Error_Msg_N ("too many arguments in call", N);
7945 First_Named := Actual;
7947 while Present (Actual) loop
7948 if Nkind (Actual) /= N_Parameter_Association then
7950 ("positional parameters not allowed after named ones", Actual);
7955 Actuals_To_Match := Actuals_To_Match + 1;
7961 if Present (Actuals) then
7962 Actual := First (Actuals);
7965 Formal := First_Formal (S);
7966 while Present (Formal) loop
7968 -- Match the formals in order. If the corresponding actual is
7969 -- positional, nothing to do. Else scan the list of named actuals
7970 -- to find the one with the right name.
7973 and then Nkind (Actual) /= N_Parameter_Association
7976 Actuals_To_Match := Actuals_To_Match - 1;
7977 Formals_To_Match := Formals_To_Match - 1;
7980 -- For named parameters, search the list of actuals to find
7981 -- one that matches the next formal name.
7983 Actual := First_Named;
7985 while Present (Actual) loop
7986 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7989 Actuals_To_Match := Actuals_To_Match - 1;
7990 Formals_To_Match := Formals_To_Match - 1;
7998 if Ekind (Formal) /= E_In_Parameter
7999 or else No (Default_Value (Formal))
8002 if (Comes_From_Source (S)
8003 or else Sloc (S) = Standard_Location)
8004 and then Is_Overloadable (S)
8008 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8010 (Nkind (Parent (N)) = N_Function_Call
8012 Nkind (Parent (N)) = N_Parameter_Association))
8013 and then Ekind (S) /= E_Function
8015 Set_Etype (N, Etype (S));
8017 Error_Msg_Name_1 := Chars (S);
8018 Error_Msg_Sloc := Sloc (S);
8020 ("missing argument for parameter & " &
8021 "in call to % declared #", N, Formal);
8024 elsif Is_Overloadable (S) then
8025 Error_Msg_Name_1 := Chars (S);
8027 -- Point to type derivation that generated the
8030 Error_Msg_Sloc := Sloc (Parent (S));
8033 ("missing argument for parameter & " &
8034 "in call to % (inherited) #", N, Formal);
8038 ("missing argument for parameter &", N, Formal);
8046 Formals_To_Match := Formals_To_Match - 1;
8051 Next_Formal (Formal);
8054 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8061 -- Find some superfluous named actual that did not get
8062 -- attached to the list of associations.
8064 Actual := First (Actuals);
8065 while Present (Actual) loop
8066 if Nkind (Actual) = N_Parameter_Association
8067 and then Actual /= Last
8068 and then No (Next_Named_Actual (Actual))
8070 Error_Msg_N ("unmatched actual & in call",
8071 Selector_Name (Actual));
8082 end Normalize_Actuals;
8084 --------------------------------
8085 -- Note_Possible_Modification --
8086 --------------------------------
8088 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8089 Modification_Comes_From_Source : constant Boolean :=
8090 Comes_From_Source (Parent (N));
8096 -- Loop to find referenced entity, if there is one
8103 if Is_Entity_Name (Exp) then
8104 Ent := Entity (Exp);
8106 -- If the entity is missing, it is an undeclared identifier,
8107 -- and there is nothing to annotate.
8113 elsif Nkind (Exp) = N_Explicit_Dereference then
8115 P : constant Node_Id := Prefix (Exp);
8118 if Nkind (P) = N_Selected_Component
8120 Entry_Formal (Entity (Selector_Name (P))))
8122 -- Case of a reference to an entry formal
8124 Ent := Entry_Formal (Entity (Selector_Name (P)));
8126 elsif Nkind (P) = N_Identifier
8127 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
8128 and then Present (Expression (Parent (Entity (P))))
8129 and then Nkind (Expression (Parent (Entity (P))))
8132 -- Case of a reference to a value on which side effects have
8135 Exp := Prefix (Expression (Parent (Entity (P))));
8144 elsif Nkind (Exp) = N_Type_Conversion
8145 or else Nkind (Exp) = N_Unchecked_Type_Conversion
8147 Exp := Expression (Exp);
8150 elsif Nkind (Exp) = N_Slice
8151 or else Nkind (Exp) = N_Indexed_Component
8152 or else Nkind (Exp) = N_Selected_Component
8154 Exp := Prefix (Exp);
8161 -- Now look for entity being referenced
8163 if Present (Ent) then
8164 if Is_Object (Ent) then
8165 if Comes_From_Source (Exp)
8166 or else Modification_Comes_From_Source
8168 if Has_Pragma_Unmodified (Ent) then
8169 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
8172 Set_Never_Set_In_Source (Ent, False);
8175 Set_Is_True_Constant (Ent, False);
8176 Set_Current_Value (Ent, Empty);
8177 Set_Is_Known_Null (Ent, False);
8179 if not Can_Never_Be_Null (Ent) then
8180 Set_Is_Known_Non_Null (Ent, False);
8183 -- Follow renaming chain
8185 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
8186 and then Present (Renamed_Object (Ent))
8188 Exp := Renamed_Object (Ent);
8192 -- Generate a reference only if the assignment comes from
8193 -- source. This excludes, for example, calls to a dispatching
8194 -- assignment operation when the left-hand side is tagged.
8196 if Modification_Comes_From_Source then
8197 Generate_Reference (Ent, Exp, 'm');
8200 Check_Nested_Access (Ent);
8205 -- If we are sure this is a modification from source, and we know
8206 -- this modifies a constant, then give an appropriate warning.
8208 if Overlays_Constant (Ent)
8209 and then Modification_Comes_From_Source
8213 A : constant Node_Id := Address_Clause (Ent);
8217 Exp : constant Node_Id := Expression (A);
8219 if Nkind (Exp) = N_Attribute_Reference
8220 and then Attribute_Name (Exp) = Name_Address
8221 and then Is_Entity_Name (Prefix (Exp))
8223 Error_Msg_Sloc := Sloc (A);
8225 ("constant& may be modified via address clause#?",
8226 N, Entity (Prefix (Exp)));
8236 end Note_Possible_Modification;
8238 -------------------------
8239 -- Object_Access_Level --
8240 -------------------------
8242 function Object_Access_Level (Obj : Node_Id) return Uint is
8245 -- Returns the static accessibility level of the view denoted by Obj. Note
8246 -- that the value returned is the result of a call to Scope_Depth. Only
8247 -- scope depths associated with dynamic scopes can actually be returned.
8248 -- Since only relative levels matter for accessibility checking, the fact
8249 -- that the distance between successive levels of accessibility is not
8250 -- always one is immaterial (invariant: if level(E2) is deeper than
8251 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
8253 function Reference_To (Obj : Node_Id) return Node_Id;
8254 -- An explicit dereference is created when removing side-effects from
8255 -- expressions for constraint checking purposes. In this case a local
8256 -- access type is created for it. The correct access level is that of
8257 -- the original source node. We detect this case by noting that the
8258 -- prefix of the dereference is created by an object declaration whose
8259 -- initial expression is a reference.
8265 function Reference_To (Obj : Node_Id) return Node_Id is
8266 Pref : constant Node_Id := Prefix (Obj);
8268 if Is_Entity_Name (Pref)
8269 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
8270 and then Present (Expression (Parent (Entity (Pref))))
8271 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
8273 return (Prefix (Expression (Parent (Entity (Pref)))));
8279 -- Start of processing for Object_Access_Level
8282 if Is_Entity_Name (Obj) then
8285 if Is_Prival (E) then
8286 E := Prival_Link (E);
8289 -- If E is a type then it denotes a current instance. For this case
8290 -- we add one to the normal accessibility level of the type to ensure
8291 -- that current instances are treated as always being deeper than
8292 -- than the level of any visible named access type (see 3.10.2(21)).
8295 return Type_Access_Level (E) + 1;
8297 elsif Present (Renamed_Object (E)) then
8298 return Object_Access_Level (Renamed_Object (E));
8300 -- Similarly, if E is a component of the current instance of a
8301 -- protected type, any instance of it is assumed to be at a deeper
8302 -- level than the type. For a protected object (whose type is an
8303 -- anonymous protected type) its components are at the same level
8304 -- as the type itself.
8306 elsif not Is_Overloadable (E)
8307 and then Ekind (Scope (E)) = E_Protected_Type
8308 and then Comes_From_Source (Scope (E))
8310 return Type_Access_Level (Scope (E)) + 1;
8313 return Scope_Depth (Enclosing_Dynamic_Scope (E));
8316 elsif Nkind (Obj) = N_Selected_Component then
8317 if Is_Access_Type (Etype (Prefix (Obj))) then
8318 return Type_Access_Level (Etype (Prefix (Obj)));
8320 return Object_Access_Level (Prefix (Obj));
8323 elsif Nkind (Obj) = N_Indexed_Component then
8324 if Is_Access_Type (Etype (Prefix (Obj))) then
8325 return Type_Access_Level (Etype (Prefix (Obj)));
8327 return Object_Access_Level (Prefix (Obj));
8330 elsif Nkind (Obj) = N_Explicit_Dereference then
8332 -- If the prefix is a selected access discriminant then we make a
8333 -- recursive call on the prefix, which will in turn check the level
8334 -- of the prefix object of the selected discriminant.
8336 if Nkind (Prefix (Obj)) = N_Selected_Component
8337 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
8339 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
8341 return Object_Access_Level (Prefix (Obj));
8343 elsif not (Comes_From_Source (Obj)) then
8345 Ref : constant Node_Id := Reference_To (Obj);
8347 if Present (Ref) then
8348 return Object_Access_Level (Ref);
8350 return Type_Access_Level (Etype (Prefix (Obj)));
8355 return Type_Access_Level (Etype (Prefix (Obj)));
8358 elsif Nkind (Obj) = N_Type_Conversion
8359 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8361 return Object_Access_Level (Expression (Obj));
8363 -- Function results are objects, so we get either the access level of
8364 -- the function or, in the case of an indirect call, the level of of the
8365 -- access-to-subprogram type.
8367 elsif Nkind (Obj) = N_Function_Call then
8368 if Is_Entity_Name (Name (Obj)) then
8369 return Subprogram_Access_Level (Entity (Name (Obj)));
8371 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8374 -- For convenience we handle qualified expressions, even though
8375 -- they aren't technically object names.
8377 elsif Nkind (Obj) = N_Qualified_Expression then
8378 return Object_Access_Level (Expression (Obj));
8380 -- Otherwise return the scope level of Standard.
8381 -- (If there are cases that fall through
8382 -- to this point they will be treated as
8383 -- having global accessibility for now. ???)
8386 return Scope_Depth (Standard_Standard);
8388 end Object_Access_Level;
8390 -----------------------
8391 -- Private_Component --
8392 -----------------------
8394 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8395 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8397 function Trace_Components
8399 Check : Boolean) return Entity_Id;
8400 -- Recursive function that does the work, and checks against circular
8401 -- definition for each subcomponent type.
8403 ----------------------
8404 -- Trace_Components --
8405 ----------------------
8407 function Trace_Components
8409 Check : Boolean) return Entity_Id
8411 Btype : constant Entity_Id := Base_Type (T);
8412 Component : Entity_Id;
8414 Candidate : Entity_Id := Empty;
8417 if Check and then Btype = Ancestor then
8418 Error_Msg_N ("circular type definition", Type_Id);
8422 if Is_Private_Type (Btype)
8423 and then not Is_Generic_Type (Btype)
8425 if Present (Full_View (Btype))
8426 and then Is_Record_Type (Full_View (Btype))
8427 and then not Is_Frozen (Btype)
8429 -- To indicate that the ancestor depends on a private type, the
8430 -- current Btype is sufficient. However, to check for circular
8431 -- definition we must recurse on the full view.
8433 Candidate := Trace_Components (Full_View (Btype), True);
8435 if Candidate = Any_Type then
8445 elsif Is_Array_Type (Btype) then
8446 return Trace_Components (Component_Type (Btype), True);
8448 elsif Is_Record_Type (Btype) then
8449 Component := First_Entity (Btype);
8450 while Present (Component) loop
8452 -- Skip anonymous types generated by constrained components
8454 if not Is_Type (Component) then
8455 P := Trace_Components (Etype (Component), True);
8458 if P = Any_Type then
8466 Next_Entity (Component);
8474 end Trace_Components;
8476 -- Start of processing for Private_Component
8479 return Trace_Components (Type_Id, False);
8480 end Private_Component;
8482 -----------------------
8483 -- Process_End_Label --
8484 -----------------------
8486 procedure Process_End_Label
8495 Label_Ref : Boolean;
8496 -- Set True if reference to end label itself is required
8499 -- Gets set to the operator symbol or identifier that references the
8500 -- entity Ent. For the child unit case, this is the identifier from the
8501 -- designator. For other cases, this is simply Endl.
8503 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8504 -- N is an identifier node that appears as a parent unit reference in
8505 -- the case where Ent is a child unit. This procedure generates an
8506 -- appropriate cross-reference entry. E is the corresponding entity.
8508 -------------------------
8509 -- Generate_Parent_Ref --
8510 -------------------------
8512 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8514 -- If names do not match, something weird, skip reference
8516 if Chars (E) = Chars (N) then
8518 -- Generate the reference. We do NOT consider this as a reference
8519 -- for unreferenced symbol purposes.
8521 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8524 Style.Check_Identifier (N, E);
8527 end Generate_Parent_Ref;
8529 -- Start of processing for Process_End_Label
8532 -- If no node, ignore. This happens in some error situations, and
8533 -- also for some internally generated structures where no end label
8534 -- references are required in any case.
8540 -- Nothing to do if no End_Label, happens for internally generated
8541 -- constructs where we don't want an end label reference anyway. Also
8542 -- nothing to do if Endl is a string literal, which means there was
8543 -- some prior error (bad operator symbol)
8545 Endl := End_Label (N);
8547 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8551 -- Reference node is not in extended main source unit
8553 if not In_Extended_Main_Source_Unit (N) then
8555 -- Generally we do not collect references except for the extended
8556 -- main source unit. The one exception is the 'e' entry for a
8557 -- package spec, where it is useful for a client to have the
8558 -- ending information to define scopes.
8566 -- For this case, we can ignore any parent references, but we
8567 -- need the package name itself for the 'e' entry.
8569 if Nkind (Endl) = N_Designator then
8570 Endl := Identifier (Endl);
8574 -- Reference is in extended main source unit
8579 -- For designator, generate references for the parent entries
8581 if Nkind (Endl) = N_Designator then
8583 -- Generate references for the prefix if the END line comes from
8584 -- source (otherwise we do not need these references) We climb the
8585 -- scope stack to find the expected entities.
8587 if Comes_From_Source (Endl) then
8589 Scop := Current_Scope;
8590 while Nkind (Nam) = N_Selected_Component loop
8591 Scop := Scope (Scop);
8592 exit when No (Scop);
8593 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8594 Nam := Prefix (Nam);
8597 if Present (Scop) then
8598 Generate_Parent_Ref (Nam, Scope (Scop));
8602 Endl := Identifier (Endl);
8606 -- If the end label is not for the given entity, then either we have
8607 -- some previous error, or this is a generic instantiation for which
8608 -- we do not need to make a cross-reference in this case anyway. In
8609 -- either case we simply ignore the call.
8611 if Chars (Ent) /= Chars (Endl) then
8615 -- If label was really there, then generate a normal reference and then
8616 -- adjust the location in the end label to point past the name (which
8617 -- should almost always be the semicolon).
8621 if Comes_From_Source (Endl) then
8623 -- If a label reference is required, then do the style check and
8624 -- generate an l-type cross-reference entry for the label
8628 Style.Check_Identifier (Endl, Ent);
8631 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8634 -- Set the location to point past the label (normally this will
8635 -- mean the semicolon immediately following the label). This is
8636 -- done for the sake of the 'e' or 't' entry generated below.
8638 Get_Decoded_Name_String (Chars (Endl));
8639 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8642 -- Now generate the e/t reference
8644 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8646 -- Restore Sloc, in case modified above, since we have an identifier
8647 -- and the normal Sloc should be left set in the tree.
8649 Set_Sloc (Endl, Loc);
8650 end Process_End_Label;
8656 -- We do the conversion to get the value of the real string by using
8657 -- the scanner, see Sinput for details on use of the internal source
8658 -- buffer for scanning internal strings.
8660 function Real_Convert (S : String) return Node_Id is
8661 Save_Src : constant Source_Buffer_Ptr := Source;
8665 Source := Internal_Source_Ptr;
8668 for J in S'Range loop
8669 Source (Source_Ptr (J)) := S (J);
8672 Source (S'Length + 1) := EOF;
8674 if Source (Scan_Ptr) = '-' then
8676 Scan_Ptr := Scan_Ptr + 1;
8684 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8691 ---------------------
8692 -- Rep_To_Pos_Flag --
8693 ---------------------
8695 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8697 return New_Occurrence_Of
8698 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8699 end Rep_To_Pos_Flag;
8701 --------------------
8702 -- Require_Entity --
8703 --------------------
8705 procedure Require_Entity (N : Node_Id) is
8707 if Is_Entity_Name (N) and then No (Entity (N)) then
8708 if Total_Errors_Detected /= 0 then
8709 Set_Entity (N, Any_Id);
8711 raise Program_Error;
8716 ------------------------------
8717 -- Requires_Transient_Scope --
8718 ------------------------------
8720 -- A transient scope is required when variable-sized temporaries are
8721 -- allocated in the primary or secondary stack, or when finalization
8722 -- actions must be generated before the next instruction.
8724 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8725 Typ : constant Entity_Id := Underlying_Type (Id);
8727 -- Start of processing for Requires_Transient_Scope
8730 -- This is a private type which is not completed yet. This can only
8731 -- happen in a default expression (of a formal parameter or of a
8732 -- record component). Do not expand transient scope in this case
8737 -- Do not expand transient scope for non-existent procedure return
8739 elsif Typ = Standard_Void_Type then
8742 -- Elementary types do not require a transient scope
8744 elsif Is_Elementary_Type (Typ) then
8747 -- Generally, indefinite subtypes require a transient scope, since the
8748 -- back end cannot generate temporaries, since this is not a valid type
8749 -- for declaring an object. It might be possible to relax this in the
8750 -- future, e.g. by declaring the maximum possible space for the type.
8752 elsif Is_Indefinite_Subtype (Typ) then
8755 -- Functions returning tagged types may dispatch on result so their
8756 -- returned value is allocated on the secondary stack. Controlled
8757 -- type temporaries need finalization.
8759 elsif Is_Tagged_Type (Typ)
8760 or else Has_Controlled_Component (Typ)
8762 return not Is_Value_Type (Typ);
8766 elsif Is_Record_Type (Typ) then
8770 Comp := First_Entity (Typ);
8771 while Present (Comp) loop
8772 if Ekind (Comp) = E_Component
8773 and then Requires_Transient_Scope (Etype (Comp))
8784 -- String literal types never require transient scope
8786 elsif Ekind (Typ) = E_String_Literal_Subtype then
8789 -- Array type. Note that we already know that this is a constrained
8790 -- array, since unconstrained arrays will fail the indefinite test.
8792 elsif Is_Array_Type (Typ) then
8794 -- If component type requires a transient scope, the array does too
8796 if Requires_Transient_Scope (Component_Type (Typ)) then
8799 -- Otherwise, we only need a transient scope if the size is not
8800 -- known at compile time.
8803 return not Size_Known_At_Compile_Time (Typ);
8806 -- All other cases do not require a transient scope
8811 end Requires_Transient_Scope;
8813 --------------------------
8814 -- Reset_Analyzed_Flags --
8815 --------------------------
8817 procedure Reset_Analyzed_Flags (N : Node_Id) is
8819 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8820 -- Function used to reset Analyzed flags in tree. Note that we do
8821 -- not reset Analyzed flags in entities, since there is no need to
8822 -- renalalyze entities, and indeed, it is wrong to do so, since it
8823 -- can result in generating auxiliary stuff more than once.
8825 --------------------
8826 -- Clear_Analyzed --
8827 --------------------
8829 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8831 if not Has_Extension (N) then
8832 Set_Analyzed (N, False);
8838 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8840 -- Start of processing for Reset_Analyzed_Flags
8844 end Reset_Analyzed_Flags;
8846 ---------------------------
8847 -- Safe_To_Capture_Value --
8848 ---------------------------
8850 function Safe_To_Capture_Value
8853 Cond : Boolean := False) return Boolean
8856 -- The only entities for which we track constant values are variables
8857 -- which are not renamings, constants, out parameters, and in out
8858 -- parameters, so check if we have this case.
8860 -- Note: it may seem odd to track constant values for constants, but in
8861 -- fact this routine is used for other purposes than simply capturing
8862 -- the value. In particular, the setting of Known[_Non]_Null.
8864 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8866 Ekind (Ent) = E_Constant
8868 Ekind (Ent) = E_Out_Parameter
8870 Ekind (Ent) = E_In_Out_Parameter
8874 -- For conditionals, we also allow loop parameters and all formals,
8875 -- including in parameters.
8879 (Ekind (Ent) = E_Loop_Parameter
8881 Ekind (Ent) = E_In_Parameter)
8885 -- For all other cases, not just unsafe, but impossible to capture
8886 -- Current_Value, since the above are the only entities which have
8887 -- Current_Value fields.
8893 -- Skip if volatile or aliased, since funny things might be going on in
8894 -- these cases which we cannot necessarily track. Also skip any variable
8895 -- for which an address clause is given, or whose address is taken. Also
8896 -- never capture value of library level variables (an attempt to do so
8897 -- can occur in the case of package elaboration code).
8899 if Treat_As_Volatile (Ent)
8900 or else Is_Aliased (Ent)
8901 or else Present (Address_Clause (Ent))
8902 or else Address_Taken (Ent)
8903 or else (Is_Library_Level_Entity (Ent)
8904 and then Ekind (Ent) = E_Variable)
8909 -- OK, all above conditions are met. We also require that the scope of
8910 -- the reference be the same as the scope of the entity, not counting
8911 -- packages and blocks and loops.
8914 E_Scope : constant Entity_Id := Scope (Ent);
8915 R_Scope : Entity_Id;
8918 R_Scope := Current_Scope;
8919 while R_Scope /= Standard_Standard loop
8920 exit when R_Scope = E_Scope;
8922 if Ekind (R_Scope) /= E_Package
8924 Ekind (R_Scope) /= E_Block
8926 Ekind (R_Scope) /= E_Loop
8930 R_Scope := Scope (R_Scope);
8935 -- We also require that the reference does not appear in a context
8936 -- where it is not sure to be executed (i.e. a conditional context
8937 -- or an exception handler). We skip this if Cond is True, since the
8938 -- capturing of values from conditional tests handles this ok.
8952 while Present (P) loop
8953 if Nkind (P) = N_If_Statement
8954 or else Nkind (P) = N_Case_Statement
8955 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8956 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8957 or else Nkind (P) = N_Exception_Handler
8958 or else Nkind (P) = N_Selective_Accept
8959 or else Nkind (P) = N_Conditional_Entry_Call
8960 or else Nkind (P) = N_Timed_Entry_Call
8961 or else Nkind (P) = N_Asynchronous_Select
8971 -- OK, looks safe to set value
8974 end Safe_To_Capture_Value;
8980 function Same_Name (N1, N2 : Node_Id) return Boolean is
8981 K1 : constant Node_Kind := Nkind (N1);
8982 K2 : constant Node_Kind := Nkind (N2);
8985 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8986 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8988 return Chars (N1) = Chars (N2);
8990 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8991 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8993 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8994 and then Same_Name (Prefix (N1), Prefix (N2));
9005 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9006 N1 : constant Node_Id := Original_Node (Node1);
9007 N2 : constant Node_Id := Original_Node (Node2);
9008 -- We do the tests on original nodes, since we are most interested
9009 -- in the original source, not any expansion that got in the way.
9011 K1 : constant Node_Kind := Nkind (N1);
9012 K2 : constant Node_Kind := Nkind (N2);
9015 -- First case, both are entities with same entity
9017 if K1 in N_Has_Entity
9018 and then K2 in N_Has_Entity
9019 and then Present (Entity (N1))
9020 and then Present (Entity (N2))
9021 and then (Ekind (Entity (N1)) = E_Variable
9023 Ekind (Entity (N1)) = E_Constant)
9024 and then Entity (N1) = Entity (N2)
9028 -- Second case, selected component with same selector, same record
9030 elsif K1 = N_Selected_Component
9031 and then K2 = N_Selected_Component
9032 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
9034 return Same_Object (Prefix (N1), Prefix (N2));
9036 -- Third case, indexed component with same subscripts, same array
9038 elsif K1 = N_Indexed_Component
9039 and then K2 = N_Indexed_Component
9040 and then Same_Object (Prefix (N1), Prefix (N2))
9045 E1 := First (Expressions (N1));
9046 E2 := First (Expressions (N2));
9047 while Present (E1) loop
9048 if not Same_Value (E1, E2) then
9059 -- Fourth case, slice of same array with same bounds
9062 and then K2 = N_Slice
9063 and then Nkind (Discrete_Range (N1)) = N_Range
9064 and then Nkind (Discrete_Range (N2)) = N_Range
9065 and then Same_Value (Low_Bound (Discrete_Range (N1)),
9066 Low_Bound (Discrete_Range (N2)))
9067 and then Same_Value (High_Bound (Discrete_Range (N1)),
9068 High_Bound (Discrete_Range (N2)))
9070 return Same_Name (Prefix (N1), Prefix (N2));
9072 -- All other cases, not clearly the same object
9083 function Same_Type (T1, T2 : Entity_Id) return Boolean is
9088 elsif not Is_Constrained (T1)
9089 and then not Is_Constrained (T2)
9090 and then Base_Type (T1) = Base_Type (T2)
9094 -- For now don't bother with case of identical constraints, to be
9095 -- fiddled with later on perhaps (this is only used for optimization
9096 -- purposes, so it is not critical to do a best possible job)
9107 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
9109 if Compile_Time_Known_Value (Node1)
9110 and then Compile_Time_Known_Value (Node2)
9111 and then Expr_Value (Node1) = Expr_Value (Node2)
9114 elsif Same_Object (Node1, Node2) then
9121 ------------------------
9122 -- Scope_Is_Transient --
9123 ------------------------
9125 function Scope_Is_Transient return Boolean is
9127 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
9128 end Scope_Is_Transient;
9134 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
9139 while Scop /= Standard_Standard loop
9140 Scop := Scope (Scop);
9142 if Scop = Scope2 then
9150 --------------------------
9151 -- Scope_Within_Or_Same --
9152 --------------------------
9154 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
9159 while Scop /= Standard_Standard loop
9160 if Scop = Scope2 then
9163 Scop := Scope (Scop);
9168 end Scope_Within_Or_Same;
9170 --------------------
9171 -- Set_Convention --
9172 --------------------
9174 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
9176 Basic_Set_Convention (E, Val);
9179 and then Is_Access_Subprogram_Type (Base_Type (E))
9180 and then Has_Foreign_Convention (E)
9182 Set_Can_Use_Internal_Rep (E, False);
9186 ------------------------
9187 -- Set_Current_Entity --
9188 ------------------------
9190 -- The given entity is to be set as the currently visible definition
9191 -- of its associated name (i.e. the Node_Id associated with its name).
9192 -- All we have to do is to get the name from the identifier, and
9193 -- then set the associated Node_Id to point to the given entity.
9195 procedure Set_Current_Entity (E : Entity_Id) is
9197 Set_Name_Entity_Id (Chars (E), E);
9198 end Set_Current_Entity;
9200 ---------------------------
9201 -- Set_Debug_Info_Needed --
9202 ---------------------------
9204 procedure Set_Debug_Info_Needed (T : Entity_Id) is
9206 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
9207 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
9208 -- Used to set debug info in a related node if not set already
9210 --------------------------------------
9211 -- Set_Debug_Info_Needed_If_Not_Set --
9212 --------------------------------------
9214 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
9217 and then not Needs_Debug_Info (E)
9219 Set_Debug_Info_Needed (E);
9221 end Set_Debug_Info_Needed_If_Not_Set;
9223 -- Start of processing for Set_Debug_Info_Needed
9226 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
9227 -- indicates that Debug_Info_Needed is never required for the entity.
9230 or else Debug_Info_Off (T)
9235 -- Set flag in entity itself. Note that we will go through the following
9236 -- circuitry even if the flag is already set on T. That's intentional,
9237 -- it makes sure that the flag will be set in subsidiary entities.
9239 Set_Needs_Debug_Info (T);
9241 -- Set flag on subsidiary entities if not set already
9243 if Is_Object (T) then
9244 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9246 elsif Is_Type (T) then
9247 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9249 if Is_Record_Type (T) then
9251 Ent : Entity_Id := First_Entity (T);
9253 while Present (Ent) loop
9254 Set_Debug_Info_Needed_If_Not_Set (Ent);
9259 elsif Is_Array_Type (T) then
9260 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
9263 Indx : Node_Id := First_Index (T);
9265 while Present (Indx) loop
9266 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
9267 Indx := Next_Index (Indx);
9271 if Is_Packed (T) then
9272 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
9275 elsif Is_Access_Type (T) then
9276 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
9278 elsif Is_Private_Type (T) then
9279 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9281 elsif Is_Protected_Type (T) then
9282 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9285 end Set_Debug_Info_Needed;
9287 ---------------------------------
9288 -- Set_Entity_With_Style_Check --
9289 ---------------------------------
9291 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9292 Val_Actual : Entity_Id;
9296 Set_Entity (N, Val);
9299 and then not Suppress_Style_Checks (Val)
9300 and then not In_Instance
9302 if Nkind (N) = N_Identifier then
9304 elsif Nkind (N) = N_Expanded_Name then
9305 Nod := Selector_Name (N);
9310 -- A special situation arises for derived operations, where we want
9311 -- to do the check against the parent (since the Sloc of the derived
9312 -- operation points to the derived type declaration itself).
9315 while not Comes_From_Source (Val_Actual)
9316 and then Nkind (Val_Actual) in N_Entity
9317 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9318 or else Is_Subprogram (Val_Actual)
9319 or else Is_Generic_Subprogram (Val_Actual))
9320 and then Present (Alias (Val_Actual))
9322 Val_Actual := Alias (Val_Actual);
9325 -- Renaming declarations for generic actuals do not come from source,
9326 -- and have a different name from that of the entity they rename, so
9327 -- there is no style check to perform here.
9329 if Chars (Nod) = Chars (Val_Actual) then
9330 Style.Check_Identifier (Nod, Val_Actual);
9334 Set_Entity (N, Val);
9335 end Set_Entity_With_Style_Check;
9337 ------------------------
9338 -- Set_Name_Entity_Id --
9339 ------------------------
9341 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9343 Set_Name_Table_Info (Id, Int (Val));
9344 end Set_Name_Entity_Id;
9346 ---------------------
9347 -- Set_Next_Actual --
9348 ---------------------
9350 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9352 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9353 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9355 end Set_Next_Actual;
9357 ----------------------------------
9358 -- Set_Optimize_Alignment_Flags --
9359 ----------------------------------
9361 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
9363 if Optimize_Alignment = 'S' then
9364 Set_Optimize_Alignment_Space (E);
9365 elsif Optimize_Alignment = 'T' then
9366 Set_Optimize_Alignment_Time (E);
9368 end Set_Optimize_Alignment_Flags;
9370 -----------------------
9371 -- Set_Public_Status --
9372 -----------------------
9374 procedure Set_Public_Status (Id : Entity_Id) is
9375 S : constant Entity_Id := Current_Scope;
9377 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
9378 -- Determines if E is defined within handled statement sequence or
9379 -- an if statement, returns True if so, False otherwise.
9381 ----------------------
9382 -- Within_HSS_Or_If --
9383 ----------------------
9385 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
9388 N := Declaration_Node (E);
9395 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
9401 end Within_HSS_Or_If;
9403 -- Start of processing for Set_Public_Status
9406 -- Everything in the scope of Standard is public
9408 if S = Standard_Standard then
9411 -- Entity is definitely not public if enclosing scope is not public
9413 elsif not Is_Public (S) then
9416 -- An object or function declaration that occurs in a handled sequence
9417 -- of statements or within an if statement is the declaration for a
9418 -- temporary object or local subprogram generated by the expander. It
9419 -- never needs to be made public and furthermore, making it public can
9420 -- cause back end problems.
9422 elsif Nkind_In (Parent (Id), N_Object_Declaration,
9423 N_Function_Specification)
9424 and then Within_HSS_Or_If (Id)
9428 -- Entities in public packages or records are public
9430 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9433 -- The bounds of an entry family declaration can generate object
9434 -- declarations that are visible to the back-end, e.g. in the
9435 -- the declaration of a composite type that contains tasks.
9437 elsif Is_Concurrent_Type (S)
9438 and then not Has_Completion (S)
9439 and then Nkind (Parent (Id)) = N_Object_Declaration
9443 end Set_Public_Status;
9445 -----------------------------
9446 -- Set_Referenced_Modified --
9447 -----------------------------
9449 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9453 -- Deal with indexed or selected component where prefix is modified
9455 if Nkind (N) = N_Indexed_Component
9457 Nkind (N) = N_Selected_Component
9461 -- If prefix is access type, then it is the designated object that is
9462 -- being modified, which means we have no entity to set the flag on.
9464 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9467 -- Otherwise chase the prefix
9470 Set_Referenced_Modified (Pref, Out_Param);
9473 -- Otherwise see if we have an entity name (only other case to process)
9475 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9476 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9477 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9479 end Set_Referenced_Modified;
9481 ----------------------------
9482 -- Set_Scope_Is_Transient --
9483 ----------------------------
9485 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9487 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9488 end Set_Scope_Is_Transient;
9494 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9496 -- We copy Esize, but not RM_Size, since in general RM_Size is
9497 -- subtype specific and does not get inherited by all subtypes.
9499 Set_Esize (T1, Esize (T2));
9500 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9502 if Is_Discrete_Or_Fixed_Point_Type (T1)
9504 Is_Discrete_Or_Fixed_Point_Type (T2)
9506 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9509 Set_Alignment (T1, Alignment (T2));
9512 --------------------
9513 -- Static_Integer --
9514 --------------------
9516 function Static_Integer (N : Node_Id) return Uint is
9518 Analyze_And_Resolve (N, Any_Integer);
9521 or else Error_Posted (N)
9522 or else Etype (N) = Any_Type
9527 if Is_Static_Expression (N) then
9528 if not Raises_Constraint_Error (N) then
9529 return Expr_Value (N);
9534 elsif Etype (N) = Any_Type then
9538 Flag_Non_Static_Expr
9539 ("static integer expression required here", N);
9544 --------------------------
9545 -- Statically_Different --
9546 --------------------------
9548 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9549 R1 : constant Node_Id := Get_Referenced_Object (E1);
9550 R2 : constant Node_Id := Get_Referenced_Object (E2);
9552 return Is_Entity_Name (R1)
9553 and then Is_Entity_Name (R2)
9554 and then Entity (R1) /= Entity (R2)
9555 and then not Is_Formal (Entity (R1))
9556 and then not Is_Formal (Entity (R2));
9557 end Statically_Different;
9559 -----------------------------
9560 -- Subprogram_Access_Level --
9561 -----------------------------
9563 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9565 if Present (Alias (Subp)) then
9566 return Subprogram_Access_Level (Alias (Subp));
9568 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9570 end Subprogram_Access_Level;
9576 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9578 if Debug_Flag_W then
9579 for J in 0 .. Scope_Stack.Last loop
9584 Write_Name (Chars (E));
9585 Write_Str (" from ");
9586 Write_Location (Sloc (N));
9591 -----------------------
9592 -- Transfer_Entities --
9593 -----------------------
9595 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9596 Ent : Entity_Id := First_Entity (From);
9603 if (Last_Entity (To)) = Empty then
9604 Set_First_Entity (To, Ent);
9606 Set_Next_Entity (Last_Entity (To), Ent);
9609 Set_Last_Entity (To, Last_Entity (From));
9611 while Present (Ent) loop
9612 Set_Scope (Ent, To);
9614 if not Is_Public (Ent) then
9615 Set_Public_Status (Ent);
9618 and then Ekind (Ent) = E_Record_Subtype
9621 -- The components of the propagated Itype must be public
9627 Comp := First_Entity (Ent);
9628 while Present (Comp) loop
9629 Set_Is_Public (Comp);
9639 Set_First_Entity (From, Empty);
9640 Set_Last_Entity (From, Empty);
9641 end Transfer_Entities;
9643 -----------------------
9644 -- Type_Access_Level --
9645 -----------------------
9647 function Type_Access_Level (Typ : Entity_Id) return Uint is
9651 Btyp := Base_Type (Typ);
9653 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9654 -- simply use the level where the type is declared. This is true for
9655 -- stand-alone object declarations, and for anonymous access types
9656 -- associated with components the level is the same as that of the
9657 -- enclosing composite type. However, special treatment is needed for
9658 -- the cases of access parameters, return objects of an anonymous access
9659 -- type, and, in Ada 95, access discriminants of limited types.
9661 if Ekind (Btyp) in Access_Kind then
9662 if Ekind (Btyp) = E_Anonymous_Access_Type then
9664 -- If the type is a nonlocal anonymous access type (such as for
9665 -- an access parameter) we treat it as being declared at the
9666 -- library level to ensure that names such as X.all'access don't
9667 -- fail static accessibility checks.
9669 if not Is_Local_Anonymous_Access (Typ) then
9670 return Scope_Depth (Standard_Standard);
9672 -- If this is a return object, the accessibility level is that of
9673 -- the result subtype of the enclosing function. The test here is
9674 -- little complicated, because we have to account for extended
9675 -- return statements that have been rewritten as blocks, in which
9676 -- case we have to find and the Is_Return_Object attribute of the
9677 -- itype's associated object. It would be nice to find a way to
9678 -- simplify this test, but it doesn't seem worthwhile to add a new
9679 -- flag just for purposes of this test. ???
9681 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9684 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9685 N_Object_Declaration
9686 and then Is_Return_Object
9687 (Defining_Identifier
9688 (Associated_Node_For_Itype (Btyp))))
9694 Scop := Scope (Scope (Btyp));
9695 while Present (Scop) loop
9696 exit when Ekind (Scop) = E_Function;
9697 Scop := Scope (Scop);
9700 -- Treat the return object's type as having the level of the
9701 -- function's result subtype (as per RM05-6.5(5.3/2)).
9703 return Type_Access_Level (Etype (Scop));
9708 Btyp := Root_Type (Btyp);
9710 -- The accessibility level of anonymous acccess types associated with
9711 -- discriminants is that of the current instance of the type, and
9712 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9714 -- AI-402: access discriminants have accessibility based on the
9715 -- object rather than the type in Ada 2005, so the above paragraph
9718 -- ??? Needs completion with rules from AI-416
9720 if Ada_Version <= Ada_95
9721 and then Ekind (Typ) = E_Anonymous_Access_Type
9722 and then Present (Associated_Node_For_Itype (Typ))
9723 and then Nkind (Associated_Node_For_Itype (Typ)) =
9724 N_Discriminant_Specification
9726 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9730 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9731 end Type_Access_Level;
9733 --------------------------
9734 -- Unit_Declaration_Node --
9735 --------------------------
9737 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9738 N : Node_Id := Parent (Unit_Id);
9741 -- Predefined operators do not have a full function declaration
9743 if Ekind (Unit_Id) = E_Operator then
9747 -- Isn't there some better way to express the following ???
9749 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9750 and then Nkind (N) /= N_Formal_Package_Declaration
9751 and then Nkind (N) /= N_Function_Instantiation
9752 and then Nkind (N) /= N_Generic_Package_Declaration
9753 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9754 and then Nkind (N) /= N_Package_Declaration
9755 and then Nkind (N) /= N_Package_Body
9756 and then Nkind (N) /= N_Package_Instantiation
9757 and then Nkind (N) /= N_Package_Renaming_Declaration
9758 and then Nkind (N) /= N_Procedure_Instantiation
9759 and then Nkind (N) /= N_Protected_Body
9760 and then Nkind (N) /= N_Subprogram_Declaration
9761 and then Nkind (N) /= N_Subprogram_Body
9762 and then Nkind (N) /= N_Subprogram_Body_Stub
9763 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9764 and then Nkind (N) /= N_Task_Body
9765 and then Nkind (N) /= N_Task_Type_Declaration
9766 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9767 and then Nkind (N) not in N_Generic_Renaming_Declaration
9770 pragma Assert (Present (N));
9774 end Unit_Declaration_Node;
9776 ------------------------------
9777 -- Universal_Interpretation --
9778 ------------------------------
9780 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9781 Index : Interp_Index;
9785 -- The argument may be a formal parameter of an operator or subprogram
9786 -- with multiple interpretations, or else an expression for an actual.
9788 if Nkind (Opnd) = N_Defining_Identifier
9789 or else not Is_Overloaded (Opnd)
9791 if Etype (Opnd) = Universal_Integer
9792 or else Etype (Opnd) = Universal_Real
9794 return Etype (Opnd);
9800 Get_First_Interp (Opnd, Index, It);
9801 while Present (It.Typ) loop
9802 if It.Typ = Universal_Integer
9803 or else It.Typ = Universal_Real
9808 Get_Next_Interp (Index, It);
9813 end Universal_Interpretation;
9819 function Unqualify (Expr : Node_Id) return Node_Id is
9821 -- Recurse to handle unlikely case of multiple levels of qualification
9823 if Nkind (Expr) = N_Qualified_Expression then
9824 return Unqualify (Expression (Expr));
9826 -- Normal case, not a qualified expression
9833 ----------------------
9834 -- Within_Init_Proc --
9835 ----------------------
9837 function Within_Init_Proc return Boolean is
9842 while not Is_Overloadable (S) loop
9843 if S = Standard_Standard then
9850 return Is_Init_Proc (S);
9851 end Within_Init_Proc;
9857 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9858 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9859 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9861 function Has_One_Matching_Field return Boolean;
9862 -- Determines if Expec_Type is a record type with a single component or
9863 -- discriminant whose type matches the found type or is one dimensional
9864 -- array whose component type matches the found type.
9866 ----------------------------
9867 -- Has_One_Matching_Field --
9868 ----------------------------
9870 function Has_One_Matching_Field return Boolean is
9874 if Is_Array_Type (Expec_Type)
9875 and then Number_Dimensions (Expec_Type) = 1
9877 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9881 elsif not Is_Record_Type (Expec_Type) then
9885 E := First_Entity (Expec_Type);
9890 elsif (Ekind (E) /= E_Discriminant
9891 and then Ekind (E) /= E_Component)
9892 or else (Chars (E) = Name_uTag
9893 or else Chars (E) = Name_uParent)
9902 if not Covers (Etype (E), Found_Type) then
9905 elsif Present (Next_Entity (E)) then
9912 end Has_One_Matching_Field;
9914 -- Start of processing for Wrong_Type
9917 -- Don't output message if either type is Any_Type, or if a message
9918 -- has already been posted for this node. We need to do the latter
9919 -- check explicitly (it is ordinarily done in Errout), because we
9920 -- are using ! to force the output of the error messages.
9922 if Expec_Type = Any_Type
9923 or else Found_Type = Any_Type
9924 or else Error_Posted (Expr)
9928 -- In an instance, there is an ongoing problem with completion of
9929 -- type derived from private types. Their structure is what Gigi
9930 -- expects, but the Etype is the parent type rather than the
9931 -- derived private type itself. Do not flag error in this case. The
9932 -- private completion is an entity without a parent, like an Itype.
9933 -- Similarly, full and partial views may be incorrect in the instance.
9934 -- There is no simple way to insure that it is consistent ???
9936 elsif In_Instance then
9937 if Etype (Etype (Expr)) = Etype (Expected_Type)
9939 (Has_Private_Declaration (Expected_Type)
9940 or else Has_Private_Declaration (Etype (Expr)))
9941 and then No (Parent (Expected_Type))
9947 -- An interesting special check. If the expression is parenthesized
9948 -- and its type corresponds to the type of the sole component of the
9949 -- expected record type, or to the component type of the expected one
9950 -- dimensional array type, then assume we have a bad aggregate attempt.
9952 if Nkind (Expr) in N_Subexpr
9953 and then Paren_Count (Expr) /= 0
9954 and then Has_One_Matching_Field
9956 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9958 -- Another special check, if we are looking for a pool-specific access
9959 -- type and we found an E_Access_Attribute_Type, then we have the case
9960 -- of an Access attribute being used in a context which needs a pool-
9961 -- specific type, which is never allowed. The one extra check we make
9962 -- is that the expected designated type covers the Found_Type.
9964 elsif Is_Access_Type (Expec_Type)
9965 and then Ekind (Found_Type) = E_Access_Attribute_Type
9966 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9967 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9969 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9971 Error_Msg_N ("result must be general access type!", Expr);
9972 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9974 -- Another special check, if the expected type is an integer type,
9975 -- but the expression is of type System.Address, and the parent is
9976 -- an addition or subtraction operation whose left operand is the
9977 -- expression in question and whose right operand is of an integral
9978 -- type, then this is an attempt at address arithmetic, so give
9979 -- appropriate message.
9981 elsif Is_Integer_Type (Expec_Type)
9982 and then Is_RTE (Found_Type, RE_Address)
9983 and then (Nkind (Parent (Expr)) = N_Op_Add
9985 Nkind (Parent (Expr)) = N_Op_Subtract)
9986 and then Expr = Left_Opnd (Parent (Expr))
9987 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9990 ("address arithmetic not predefined in package System",
9993 ("\possible missing with/use of System.Storage_Elements",
9997 -- If the expected type is an anonymous access type, as for access
9998 -- parameters and discriminants, the error is on the designated types.
10000 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
10001 if Comes_From_Source (Expec_Type) then
10002 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10005 ("expected an access type with designated}",
10006 Expr, Designated_Type (Expec_Type));
10009 if Is_Access_Type (Found_Type)
10010 and then not Comes_From_Source (Found_Type)
10013 ("\\found an access type with designated}!",
10014 Expr, Designated_Type (Found_Type));
10016 if From_With_Type (Found_Type) then
10017 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
10018 Error_Msg_Qual_Level := 99;
10019 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
10020 Error_Msg_Qual_Level := 0;
10022 Error_Msg_NE ("found}!", Expr, Found_Type);
10026 -- Normal case of one type found, some other type expected
10029 -- If the names of the two types are the same, see if some number
10030 -- of levels of qualification will help. Don't try more than three
10031 -- levels, and if we get to standard, it's no use (and probably
10032 -- represents an error in the compiler) Also do not bother with
10033 -- internal scope names.
10036 Expec_Scope : Entity_Id;
10037 Found_Scope : Entity_Id;
10040 Expec_Scope := Expec_Type;
10041 Found_Scope := Found_Type;
10043 for Levels in Int range 0 .. 3 loop
10044 if Chars (Expec_Scope) /= Chars (Found_Scope) then
10045 Error_Msg_Qual_Level := Levels;
10049 Expec_Scope := Scope (Expec_Scope);
10050 Found_Scope := Scope (Found_Scope);
10052 exit when Expec_Scope = Standard_Standard
10053 or else Found_Scope = Standard_Standard
10054 or else not Comes_From_Source (Expec_Scope)
10055 or else not Comes_From_Source (Found_Scope);
10059 if Is_Record_Type (Expec_Type)
10060 and then Present (Corresponding_Remote_Type (Expec_Type))
10062 Error_Msg_NE ("expected}!", Expr,
10063 Corresponding_Remote_Type (Expec_Type));
10065 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10068 if Is_Entity_Name (Expr)
10069 and then Is_Package_Or_Generic_Package (Entity (Expr))
10071 Error_Msg_N ("\\found package name!", Expr);
10073 elsif Is_Entity_Name (Expr)
10075 (Ekind (Entity (Expr)) = E_Procedure
10077 Ekind (Entity (Expr)) = E_Generic_Procedure)
10079 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
10081 ("found procedure name, possibly missing Access attribute!",
10085 ("\\found procedure name instead of function!", Expr);
10088 elsif Nkind (Expr) = N_Function_Call
10089 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
10090 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
10091 and then No (Parameter_Associations (Expr))
10094 ("found function name, possibly missing Access attribute!",
10097 -- Catch common error: a prefix or infix operator which is not
10098 -- directly visible because the type isn't.
10100 elsif Nkind (Expr) in N_Op
10101 and then Is_Overloaded (Expr)
10102 and then not Is_Immediately_Visible (Expec_Type)
10103 and then not Is_Potentially_Use_Visible (Expec_Type)
10104 and then not In_Use (Expec_Type)
10105 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
10108 ("operator of the type is not directly visible!", Expr);
10110 elsif Ekind (Found_Type) = E_Void
10111 and then Present (Parent (Found_Type))
10112 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
10114 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
10117 Error_Msg_NE ("\\found}!", Expr, Found_Type);
10120 Error_Msg_Qual_Level := 0;