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);
219 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
225 -- Now we replace the node by an N_Raise_Constraint_Error node
226 -- This does not need reanalyzing, so set it as analyzed now.
229 Make_Raise_Constraint_Error (Sloc (N),
231 Set_Analyzed (N, True);
233 Set_Raises_Constraint_Error (N);
235 -- If the original expression was marked as static, the result is
236 -- still marked as static, but the Raises_Constraint_Error flag is
237 -- always set so that further static evaluation is not attempted.
240 Set_Is_Static_Expression (N);
242 end Apply_Compile_Time_Constraint_Error;
244 --------------------------
245 -- Build_Actual_Subtype --
246 --------------------------
248 function Build_Actual_Subtype
250 N : Node_Or_Entity_Id) return Node_Id
253 -- Normally Sloc (N), but may point to corresponding body in some cases
255 Constraints : List_Id;
261 Disc_Type : Entity_Id;
267 if Nkind (N) = N_Defining_Identifier then
268 Obj := New_Reference_To (N, Loc);
270 -- If this is a formal parameter of a subprogram declaration, and
271 -- we are compiling the body, we want the declaration for the
272 -- actual subtype to carry the source position of the body, to
273 -- prevent anomalies in gdb when stepping through the code.
275 if Is_Formal (N) then
277 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
279 if Nkind (Decl) = N_Subprogram_Declaration
280 and then Present (Corresponding_Body (Decl))
282 Loc := Sloc (Corresponding_Body (Decl));
291 if Is_Array_Type (T) then
292 Constraints := New_List;
293 for J in 1 .. Number_Dimensions (T) loop
295 -- Build an array subtype declaration with the nominal subtype and
296 -- the bounds of the actual. Add the declaration in front of the
297 -- local declarations for the subprogram, for analysis before any
298 -- reference to the formal in the body.
301 Make_Attribute_Reference (Loc,
303 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
304 Attribute_Name => Name_First,
305 Expressions => New_List (
306 Make_Integer_Literal (Loc, J)));
309 Make_Attribute_Reference (Loc,
311 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
312 Attribute_Name => Name_Last,
313 Expressions => New_List (
314 Make_Integer_Literal (Loc, J)));
316 Append (Make_Range (Loc, Lo, Hi), Constraints);
319 -- If the type has unknown discriminants there is no constrained
320 -- subtype to build. This is never called for a formal or for a
321 -- lhs, so returning the type is ok ???
323 elsif Has_Unknown_Discriminants (T) then
327 Constraints := New_List;
329 -- Type T is a generic derived type, inherit the discriminants from
332 if Is_Private_Type (T)
333 and then No (Full_View (T))
335 -- T was flagged as an error if it was declared as a formal
336 -- derived type with known discriminants. In this case there
337 -- is no need to look at the parent type since T already carries
338 -- its own discriminants.
340 and then not Error_Posted (T)
342 Disc_Type := Etype (Base_Type (T));
347 Discr := First_Discriminant (Disc_Type);
348 while Present (Discr) loop
349 Append_To (Constraints,
350 Make_Selected_Component (Loc,
352 Duplicate_Subexpr_No_Checks (Obj),
353 Selector_Name => New_Occurrence_Of (Discr, Loc)));
354 Next_Discriminant (Discr);
359 Make_Defining_Identifier (Loc,
360 Chars => New_Internal_Name ('S'));
361 Set_Is_Internal (Subt);
364 Make_Subtype_Declaration (Loc,
365 Defining_Identifier => Subt,
366 Subtype_Indication =>
367 Make_Subtype_Indication (Loc,
368 Subtype_Mark => New_Reference_To (T, Loc),
370 Make_Index_Or_Discriminant_Constraint (Loc,
371 Constraints => Constraints)));
373 Mark_Rewrite_Insertion (Decl);
375 end Build_Actual_Subtype;
377 ---------------------------------------
378 -- Build_Actual_Subtype_Of_Component --
379 ---------------------------------------
381 function Build_Actual_Subtype_Of_Component
383 N : Node_Id) return Node_Id
385 Loc : constant Source_Ptr := Sloc (N);
386 P : constant Node_Id := Prefix (N);
389 Indx_Type : Entity_Id;
391 Deaccessed_T : Entity_Id;
392 -- This is either a copy of T, or if T is an access type, then it is
393 -- the directly designated type of this access type.
395 function Build_Actual_Array_Constraint return List_Id;
396 -- If one or more of the bounds of the component depends on
397 -- discriminants, build actual constraint using the discriminants
400 function Build_Actual_Record_Constraint return List_Id;
401 -- Similar to previous one, for discriminated components constrained
402 -- by the discriminant of the enclosing object.
404 -----------------------------------
405 -- Build_Actual_Array_Constraint --
406 -----------------------------------
408 function Build_Actual_Array_Constraint return List_Id is
409 Constraints : constant List_Id := New_List;
417 Indx := First_Index (Deaccessed_T);
418 while Present (Indx) loop
419 Old_Lo := Type_Low_Bound (Etype (Indx));
420 Old_Hi := Type_High_Bound (Etype (Indx));
422 if Denotes_Discriminant (Old_Lo) then
424 Make_Selected_Component (Loc,
425 Prefix => New_Copy_Tree (P),
426 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
429 Lo := New_Copy_Tree (Old_Lo);
431 -- The new bound will be reanalyzed in the enclosing
432 -- declaration. For literal bounds that come from a type
433 -- declaration, the type of the context must be imposed, so
434 -- insure that analysis will take place. For non-universal
435 -- types this is not strictly necessary.
437 Set_Analyzed (Lo, False);
440 if Denotes_Discriminant (Old_Hi) then
442 Make_Selected_Component (Loc,
443 Prefix => New_Copy_Tree (P),
444 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
447 Hi := New_Copy_Tree (Old_Hi);
448 Set_Analyzed (Hi, False);
451 Append (Make_Range (Loc, Lo, Hi), Constraints);
456 end Build_Actual_Array_Constraint;
458 ------------------------------------
459 -- Build_Actual_Record_Constraint --
460 ------------------------------------
462 function Build_Actual_Record_Constraint return List_Id is
463 Constraints : constant List_Id := New_List;
468 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
469 while Present (D) loop
470 if Denotes_Discriminant (Node (D)) then
471 D_Val := Make_Selected_Component (Loc,
472 Prefix => New_Copy_Tree (P),
473 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
476 D_Val := New_Copy_Tree (Node (D));
479 Append (D_Val, Constraints);
484 end Build_Actual_Record_Constraint;
486 -- Start of processing for Build_Actual_Subtype_Of_Component
489 if In_Default_Expression then
492 elsif Nkind (N) = N_Explicit_Dereference then
493 if Is_Composite_Type (T)
494 and then not Is_Constrained (T)
495 and then not (Is_Class_Wide_Type (T)
496 and then Is_Constrained (Root_Type (T)))
497 and then not Has_Unknown_Discriminants (T)
499 -- If the type of the dereference is already constrained, it
500 -- is an actual subtype.
502 if Is_Array_Type (Etype (N))
503 and then Is_Constrained (Etype (N))
507 Remove_Side_Effects (P);
508 return Build_Actual_Subtype (T, N);
515 if Ekind (T) = E_Access_Subtype then
516 Deaccessed_T := Designated_Type (T);
521 if Ekind (Deaccessed_T) = E_Array_Subtype then
522 Id := First_Index (Deaccessed_T);
523 while Present (Id) loop
524 Indx_Type := Underlying_Type (Etype (Id));
526 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
528 Denotes_Discriminant (Type_High_Bound (Indx_Type))
530 Remove_Side_Effects (P);
532 Build_Component_Subtype
533 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
539 elsif Is_Composite_Type (Deaccessed_T)
540 and then Has_Discriminants (Deaccessed_T)
541 and then not Has_Unknown_Discriminants (Deaccessed_T)
543 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
544 while Present (D) loop
545 if Denotes_Discriminant (Node (D)) then
546 Remove_Side_Effects (P);
548 Build_Component_Subtype (
549 Build_Actual_Record_Constraint, Loc, Base_Type (T));
556 -- If none of the above, the actual and nominal subtypes are the same
559 end Build_Actual_Subtype_Of_Component;
561 -----------------------------
562 -- Build_Component_Subtype --
563 -----------------------------
565 function Build_Component_Subtype
568 T : Entity_Id) return Node_Id
574 -- Unchecked_Union components do not require component subtypes
576 if Is_Unchecked_Union (T) then
581 Make_Defining_Identifier (Loc,
582 Chars => New_Internal_Name ('S'));
583 Set_Is_Internal (Subt);
586 Make_Subtype_Declaration (Loc,
587 Defining_Identifier => Subt,
588 Subtype_Indication =>
589 Make_Subtype_Indication (Loc,
590 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
592 Make_Index_Or_Discriminant_Constraint (Loc,
595 Mark_Rewrite_Insertion (Decl);
597 end Build_Component_Subtype;
599 ---------------------------
600 -- Build_Default_Subtype --
601 ---------------------------
603 function Build_Default_Subtype
605 N : Node_Id) return Entity_Id
607 Loc : constant Source_Ptr := Sloc (N);
611 if not Has_Discriminants (T) or else Is_Constrained (T) then
615 Disc := First_Discriminant (T);
617 if No (Discriminant_Default_Value (Disc)) then
622 Act : constant Entity_Id :=
623 Make_Defining_Identifier (Loc,
624 Chars => New_Internal_Name ('S'));
626 Constraints : constant List_Id := New_List;
630 while Present (Disc) loop
631 Append_To (Constraints,
632 New_Copy_Tree (Discriminant_Default_Value (Disc)));
633 Next_Discriminant (Disc);
637 Make_Subtype_Declaration (Loc,
638 Defining_Identifier => Act,
639 Subtype_Indication =>
640 Make_Subtype_Indication (Loc,
641 Subtype_Mark => New_Occurrence_Of (T, Loc),
643 Make_Index_Or_Discriminant_Constraint (Loc,
644 Constraints => Constraints)));
646 Insert_Action (N, Decl);
650 end Build_Default_Subtype;
652 --------------------------------------------
653 -- Build_Discriminal_Subtype_Of_Component --
654 --------------------------------------------
656 function Build_Discriminal_Subtype_Of_Component
657 (T : Entity_Id) return Node_Id
659 Loc : constant Source_Ptr := Sloc (T);
663 function Build_Discriminal_Array_Constraint return List_Id;
664 -- If one or more of the bounds of the component depends on
665 -- discriminants, build actual constraint using the discriminants
668 function Build_Discriminal_Record_Constraint return List_Id;
669 -- Similar to previous one, for discriminated components constrained
670 -- by the discriminant of the enclosing object.
672 ----------------------------------------
673 -- Build_Discriminal_Array_Constraint --
674 ----------------------------------------
676 function Build_Discriminal_Array_Constraint return List_Id is
677 Constraints : constant List_Id := New_List;
685 Indx := First_Index (T);
686 while Present (Indx) loop
687 Old_Lo := Type_Low_Bound (Etype (Indx));
688 Old_Hi := Type_High_Bound (Etype (Indx));
690 if Denotes_Discriminant (Old_Lo) then
691 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
694 Lo := New_Copy_Tree (Old_Lo);
697 if Denotes_Discriminant (Old_Hi) then
698 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
701 Hi := New_Copy_Tree (Old_Hi);
704 Append (Make_Range (Loc, Lo, Hi), Constraints);
709 end Build_Discriminal_Array_Constraint;
711 -----------------------------------------
712 -- Build_Discriminal_Record_Constraint --
713 -----------------------------------------
715 function Build_Discriminal_Record_Constraint return List_Id is
716 Constraints : constant List_Id := New_List;
721 D := First_Elmt (Discriminant_Constraint (T));
722 while Present (D) loop
723 if Denotes_Discriminant (Node (D)) then
725 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
728 D_Val := New_Copy_Tree (Node (D));
731 Append (D_Val, Constraints);
736 end Build_Discriminal_Record_Constraint;
738 -- Start of processing for Build_Discriminal_Subtype_Of_Component
741 if Ekind (T) = E_Array_Subtype then
742 Id := First_Index (T);
743 while Present (Id) loop
744 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
745 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
747 return Build_Component_Subtype
748 (Build_Discriminal_Array_Constraint, Loc, T);
754 elsif Ekind (T) = E_Record_Subtype
755 and then Has_Discriminants (T)
756 and then not Has_Unknown_Discriminants (T)
758 D := First_Elmt (Discriminant_Constraint (T));
759 while Present (D) loop
760 if Denotes_Discriminant (Node (D)) then
761 return Build_Component_Subtype
762 (Build_Discriminal_Record_Constraint, Loc, T);
769 -- If none of the above, the actual and nominal subtypes are the same
772 end Build_Discriminal_Subtype_Of_Component;
774 ------------------------------
775 -- Build_Elaboration_Entity --
776 ------------------------------
778 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
779 Loc : constant Source_Ptr := Sloc (N);
781 Elab_Ent : Entity_Id;
783 procedure Set_Package_Name (Ent : Entity_Id);
784 -- Given an entity, sets the fully qualified name of the entity in
785 -- Name_Buffer, with components separated by double underscores. This
786 -- is a recursive routine that climbs the scope chain to Standard.
788 ----------------------
789 -- Set_Package_Name --
790 ----------------------
792 procedure Set_Package_Name (Ent : Entity_Id) is
794 if Scope (Ent) /= Standard_Standard then
795 Set_Package_Name (Scope (Ent));
798 Nam : constant String := Get_Name_String (Chars (Ent));
800 Name_Buffer (Name_Len + 1) := '_';
801 Name_Buffer (Name_Len + 2) := '_';
802 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
803 Name_Len := Name_Len + Nam'Length + 2;
807 Get_Name_String (Chars (Ent));
809 end Set_Package_Name;
811 -- Start of processing for Build_Elaboration_Entity
814 -- Ignore if already constructed
816 if Present (Elaboration_Entity (Spec_Id)) then
820 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
821 -- name with dots replaced by double underscore. We have to manually
822 -- construct this name, since it will be elaborated in the outer scope,
823 -- and thus will not have the unit name automatically prepended.
825 Set_Package_Name (Spec_Id);
829 Name_Buffer (Name_Len + 1) := '_';
830 Name_Buffer (Name_Len + 2) := 'E';
831 Name_Len := Name_Len + 2;
833 -- Create elaboration flag
836 Make_Defining_Identifier (Loc, Chars => Name_Find);
837 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
840 Make_Object_Declaration (Loc,
841 Defining_Identifier => Elab_Ent,
843 New_Occurrence_Of (Standard_Boolean, Loc),
845 New_Occurrence_Of (Standard_False, Loc));
847 Push_Scope (Standard_Standard);
848 Add_Global_Declaration (Decl);
851 -- Reset True_Constant indication, since we will indeed assign a value
852 -- to the variable in the binder main. We also kill the Current_Value
853 -- and Last_Assignment fields for the same reason.
855 Set_Is_True_Constant (Elab_Ent, False);
856 Set_Current_Value (Elab_Ent, Empty);
857 Set_Last_Assignment (Elab_Ent, Empty);
859 -- We do not want any further qualification of the name (if we did
860 -- not do this, we would pick up the name of the generic package
861 -- in the case of a library level generic instantiation).
863 Set_Has_Qualified_Name (Elab_Ent);
864 Set_Has_Fully_Qualified_Name (Elab_Ent);
865 end Build_Elaboration_Entity;
867 -----------------------------------
868 -- Cannot_Raise_Constraint_Error --
869 -----------------------------------
871 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
873 if Compile_Time_Known_Value (Expr) then
876 elsif Do_Range_Check (Expr) then
879 elsif Raises_Constraint_Error (Expr) then
887 when N_Expanded_Name =>
890 when N_Selected_Component =>
891 return not Do_Discriminant_Check (Expr);
893 when N_Attribute_Reference =>
894 if Do_Overflow_Check (Expr) then
897 elsif No (Expressions (Expr)) then
905 N := First (Expressions (Expr));
906 while Present (N) loop
907 if Cannot_Raise_Constraint_Error (N) then
918 when N_Type_Conversion =>
919 if Do_Overflow_Check (Expr)
920 or else Do_Length_Check (Expr)
921 or else Do_Tag_Check (Expr)
926 Cannot_Raise_Constraint_Error (Expression (Expr));
929 when N_Unchecked_Type_Conversion =>
930 return Cannot_Raise_Constraint_Error (Expression (Expr));
933 if Do_Overflow_Check (Expr) then
937 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
944 if Do_Division_Check (Expr)
945 or else Do_Overflow_Check (Expr)
950 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
952 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
971 N_Op_Shift_Right_Arithmetic |
975 if Do_Overflow_Check (Expr) then
979 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
981 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
988 end Cannot_Raise_Constraint_Error;
990 --------------------------
991 -- Check_Fully_Declared --
992 --------------------------
994 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
996 if Ekind (T) = E_Incomplete_Type then
998 -- Ada 2005 (AI-50217): If the type is available through a limited
999 -- with_clause, verify that its full view has been analyzed.
1001 if From_With_Type (T)
1002 and then Present (Non_Limited_View (T))
1003 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1005 -- The non-limited view is fully declared
1010 ("premature usage of incomplete}", N, First_Subtype (T));
1013 elsif Has_Private_Component (T)
1014 and then not Is_Generic_Type (Root_Type (T))
1015 and then not In_Default_Expression
1018 -- Special case: if T is the anonymous type created for a single
1019 -- task or protected object, use the name of the source object.
1021 if Is_Concurrent_Type (T)
1022 and then not Comes_From_Source (T)
1023 and then Nkind (N) = N_Object_Declaration
1025 Error_Msg_NE ("type of& has incomplete component", N,
1026 Defining_Identifier (N));
1030 ("premature usage of incomplete}", N, First_Subtype (T));
1033 end Check_Fully_Declared;
1035 -------------------------
1036 -- Check_Nested_Access --
1037 -------------------------
1039 procedure Check_Nested_Access (Ent : Entity_Id) is
1040 Scop : constant Entity_Id := Current_Scope;
1041 Current_Subp : Entity_Id;
1042 Enclosing : Entity_Id;
1045 -- Currently only enabled for VM back-ends for efficiency, should we
1046 -- enable it more systematically ???
1048 if VM_Target /= No_VM
1049 and then (Ekind (Ent) = E_Variable
1051 Ekind (Ent) = E_Constant
1053 Ekind (Ent) = E_Loop_Parameter)
1054 and then Scope (Ent) /= Empty
1055 and then not Is_Library_Level_Entity (Ent)
1057 if Is_Subprogram (Scop)
1058 or else Is_Generic_Subprogram (Scop)
1059 or else Is_Entry (Scop)
1061 Current_Subp := Scop;
1063 Current_Subp := Current_Subprogram;
1066 Enclosing := Enclosing_Subprogram (Ent);
1068 if Enclosing /= Empty
1069 and then Enclosing /= Current_Subp
1071 Set_Has_Up_Level_Access (Ent, True);
1074 end Check_Nested_Access;
1076 ------------------------------------------
1077 -- Check_Potentially_Blocking_Operation --
1078 ------------------------------------------
1080 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1083 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1084 -- When pragma Detect_Blocking is active, the run time will raise
1085 -- Program_Error. Here we only issue a warning, since we generally
1086 -- support the use of potentially blocking operations in the absence
1089 -- Indirect blocking through a subprogram call cannot be diagnosed
1090 -- statically without interprocedural analysis, so we do not attempt
1093 S := Scope (Current_Scope);
1094 while Present (S) and then S /= Standard_Standard loop
1095 if Is_Protected_Type (S) then
1097 ("potentially blocking operation in protected operation?", N);
1104 end Check_Potentially_Blocking_Operation;
1110 procedure Check_VMS (Construct : Node_Id) is
1112 if not OpenVMS_On_Target then
1114 ("this construct is allowed only in Open'V'M'S", Construct);
1118 ---------------------------------
1119 -- Collect_Abstract_Interfaces --
1120 ---------------------------------
1122 procedure Collect_Abstract_Interfaces
1124 Ifaces_List : out Elist_Id;
1125 Exclude_Parent_Interfaces : Boolean := False;
1126 Use_Full_View : Boolean := True)
1128 procedure Add_Interface (Iface : Entity_Id);
1129 -- Add the interface it if is not already in the list
1131 procedure Collect (Typ : Entity_Id);
1132 -- Subsidiary subprogram used to traverse the whole list
1133 -- of directly and indirectly implemented interfaces
1135 function Interface_Present_In_Parent
1137 Iface : Entity_Id) return Boolean;
1138 -- Typ must be a tagged record type/subtype and Iface must be an
1139 -- abstract interface type. This function is used to check if Typ
1140 -- or some parent of Typ implements Iface.
1146 procedure Add_Interface (Iface : Entity_Id) is
1150 Elmt := First_Elmt (Ifaces_List);
1151 while Present (Elmt) and then Node (Elmt) /= Iface loop
1156 Append_Elmt (Iface, Ifaces_List);
1164 procedure Collect (Typ : Entity_Id) is
1165 Ancestor : Entity_Id;
1167 Iface_List : List_Id;
1174 -- Handle private types
1177 and then Is_Private_Type (Typ)
1178 and then Present (Full_View (Typ))
1180 Full_T := Full_View (Typ);
1183 Iface_List := Abstract_Interface_List (Full_T);
1185 -- Include the ancestor if we are generating the whole list of
1186 -- abstract interfaces.
1188 -- In concurrent types the ancestor interface (if any) is the
1189 -- first element of the list of interface types.
1191 if Is_Concurrent_Type (Full_T)
1192 or else Is_Concurrent_Record_Type (Full_T)
1194 if Is_Non_Empty_List (Iface_List) then
1195 Ancestor := Etype (First (Iface_List));
1198 if not Exclude_Parent_Interfaces then
1199 Add_Interface (Ancestor);
1203 elsif Etype (Full_T) /= Typ
1205 -- Protect the frontend against wrong sources. For example:
1208 -- type A is tagged null record;
1209 -- type B is new A with private;
1210 -- type C is new A with private;
1212 -- type B is new C with null record;
1213 -- type C is new B with null record;
1216 and then Etype (Full_T) /= T
1218 Ancestor := Etype (Full_T);
1221 if Is_Interface (Ancestor)
1222 and then not Exclude_Parent_Interfaces
1224 Add_Interface (Ancestor);
1228 -- Traverse the graph of ancestor interfaces
1230 if Is_Non_Empty_List (Iface_List) then
1231 Id := First (Iface_List);
1233 -- In concurrent types the ancestor interface (if any) is the
1234 -- first element of the list of interface types and we have
1235 -- already processed them while climbing to the root type.
1237 if Is_Concurrent_Type (Full_T)
1238 or else Is_Concurrent_Record_Type (Full_T)
1243 while Present (Id) loop
1244 Iface := Etype (Id);
1246 -- Protect against wrong uses. For example:
1247 -- type I is interface;
1248 -- type O is tagged null record;
1249 -- type Wrong is new I and O with null record; -- ERROR
1251 if Is_Interface (Iface) then
1252 if Exclude_Parent_Interfaces
1253 and then Interface_Present_In_Parent (T, Iface)
1258 Add_Interface (Iface);
1267 ---------------------------------
1268 -- Interface_Present_In_Parent --
1269 ---------------------------------
1271 function Interface_Present_In_Parent
1273 Iface : Entity_Id) return Boolean
1275 Aux : Entity_Id := Typ;
1276 Iface_List : List_Id;
1279 if Is_Concurrent_Type (Typ)
1280 or else Is_Concurrent_Record_Type (Typ)
1282 Iface_List := Abstract_Interface_List (Typ);
1284 if Is_Non_Empty_List (Iface_List) then
1285 Aux := Etype (First (Iface_List));
1291 return Interface_Present_In_Ancestor (Aux, Iface);
1292 end Interface_Present_In_Parent;
1294 -- Start of processing for Collect_Abstract_Interfaces
1297 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1298 Ifaces_List := New_Elmt_List;
1300 end Collect_Abstract_Interfaces;
1302 ----------------------------------
1303 -- Collect_Interface_Components --
1304 ----------------------------------
1306 procedure Collect_Interface_Components
1307 (Tagged_Type : Entity_Id;
1308 Components_List : out Elist_Id)
1310 procedure Collect (Typ : Entity_Id);
1311 -- Subsidiary subprogram used to climb to the parents
1317 procedure Collect (Typ : Entity_Id) is
1318 Tag_Comp : Entity_Id;
1321 if Etype (Typ) /= Typ
1323 -- Protect the frontend against wrong sources. For example:
1326 -- type A is tagged null record;
1327 -- type B is new A with private;
1328 -- type C is new A with private;
1330 -- type B is new C with null record;
1331 -- type C is new B with null record;
1334 and then Etype (Typ) /= Tagged_Type
1336 Collect (Etype (Typ));
1339 -- Collect the components containing tags of secondary dispatch
1342 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1343 while Present (Tag_Comp) loop
1344 pragma Assert (Present (Related_Type (Tag_Comp)));
1345 Append_Elmt (Tag_Comp, Components_List);
1347 Tag_Comp := Next_Tag_Component (Tag_Comp);
1351 -- Start of processing for Collect_Interface_Components
1354 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1355 and then Is_Tagged_Type (Tagged_Type));
1357 Components_List := New_Elmt_List;
1358 Collect (Tagged_Type);
1359 end Collect_Interface_Components;
1361 -----------------------------
1362 -- Collect_Interfaces_Info --
1363 -----------------------------
1365 procedure Collect_Interfaces_Info
1367 Ifaces_List : out Elist_Id;
1368 Components_List : out Elist_Id;
1369 Tags_List : out Elist_Id)
1371 Comps_List : Elist_Id;
1372 Comp_Elmt : Elmt_Id;
1373 Comp_Iface : Entity_Id;
1374 Iface_Elmt : Elmt_Id;
1377 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1378 -- Search for the secondary tag associated with the interface type
1379 -- Iface that is implemented by T.
1385 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1389 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1391 and then Ekind (Node (ADT)) = E_Constant
1392 and then Related_Type (Node (ADT)) /= Iface
1394 -- Skip the secondary dispatch tables of Iface
1402 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1406 -- Start of processing for Collect_Interfaces_Info
1409 Collect_Abstract_Interfaces (T, Ifaces_List);
1410 Collect_Interface_Components (T, Comps_List);
1412 -- Search for the record component and tag associated with each
1413 -- interface type of T.
1415 Components_List := New_Elmt_List;
1416 Tags_List := New_Elmt_List;
1418 Iface_Elmt := First_Elmt (Ifaces_List);
1419 while Present (Iface_Elmt) loop
1420 Iface := Node (Iface_Elmt);
1422 -- Associate the primary tag component and the primary dispatch table
1423 -- with all the interfaces that are parents of T
1425 if Is_Parent (Iface, T) then
1426 Append_Elmt (First_Tag_Component (T), Components_List);
1427 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1429 -- Otherwise search for the tag component and secondary dispatch
1433 Comp_Elmt := First_Elmt (Comps_List);
1434 while Present (Comp_Elmt) loop
1435 Comp_Iface := Related_Type (Node (Comp_Elmt));
1437 if Comp_Iface = Iface
1438 or else Is_Parent (Iface, Comp_Iface)
1440 Append_Elmt (Node (Comp_Elmt), Components_List);
1441 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1445 Next_Elmt (Comp_Elmt);
1447 pragma Assert (Present (Comp_Elmt));
1450 Next_Elmt (Iface_Elmt);
1452 end Collect_Interfaces_Info;
1454 ----------------------------------
1455 -- Collect_Primitive_Operations --
1456 ----------------------------------
1458 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1459 B_Type : constant Entity_Id := Base_Type (T);
1460 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1461 B_Scope : Entity_Id := Scope (B_Type);
1465 Formal_Derived : Boolean := False;
1469 -- For tagged types, the primitive operations are collected as they
1470 -- are declared, and held in an explicit list which is simply returned.
1472 if Is_Tagged_Type (B_Type) then
1473 return Primitive_Operations (B_Type);
1475 -- An untagged generic type that is a derived type inherits the
1476 -- primitive operations of its parent type. Other formal types only
1477 -- have predefined operators, which are not explicitly represented.
1479 elsif Is_Generic_Type (B_Type) then
1480 if Nkind (B_Decl) = N_Formal_Type_Declaration
1481 and then Nkind (Formal_Type_Definition (B_Decl))
1482 = N_Formal_Derived_Type_Definition
1484 Formal_Derived := True;
1486 return New_Elmt_List;
1490 Op_List := New_Elmt_List;
1492 if B_Scope = Standard_Standard then
1493 if B_Type = Standard_String then
1494 Append_Elmt (Standard_Op_Concat, Op_List);
1496 elsif B_Type = Standard_Wide_String then
1497 Append_Elmt (Standard_Op_Concatw, Op_List);
1503 elsif (Is_Package_Or_Generic_Package (B_Scope)
1505 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1507 or else Is_Derived_Type (B_Type)
1509 -- The primitive operations appear after the base type, except
1510 -- if the derivation happens within the private part of B_Scope
1511 -- and the type is a private type, in which case both the type
1512 -- and some primitive operations may appear before the base
1513 -- type, and the list of candidates starts after the type.
1515 if In_Open_Scopes (B_Scope)
1516 and then Scope (T) = B_Scope
1517 and then In_Private_Part (B_Scope)
1519 Id := Next_Entity (T);
1521 Id := Next_Entity (B_Type);
1524 while Present (Id) loop
1526 -- Note that generic formal subprograms are not
1527 -- considered to be primitive operations and thus
1528 -- are never inherited.
1530 if Is_Overloadable (Id)
1531 and then Nkind (Parent (Parent (Id)))
1532 not in N_Formal_Subprogram_Declaration
1536 if Base_Type (Etype (Id)) = B_Type then
1539 Formal := First_Formal (Id);
1540 while Present (Formal) loop
1541 if Base_Type (Etype (Formal)) = B_Type then
1545 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1547 (Designated_Type (Etype (Formal))) = B_Type
1553 Next_Formal (Formal);
1557 -- For a formal derived type, the only primitives are the
1558 -- ones inherited from the parent type. Operations appearing
1559 -- in the package declaration are not primitive for it.
1562 and then (not Formal_Derived
1563 or else Present (Alias (Id)))
1565 Append_Elmt (Id, Op_List);
1571 -- For a type declared in System, some of its operations
1572 -- may appear in the target-specific extension to System.
1575 and then Chars (B_Scope) = Name_System
1576 and then Scope (B_Scope) = Standard_Standard
1577 and then Present_System_Aux
1579 B_Scope := System_Aux_Id;
1580 Id := First_Entity (System_Aux_Id);
1586 end Collect_Primitive_Operations;
1588 -----------------------------------
1589 -- Compile_Time_Constraint_Error --
1590 -----------------------------------
1592 function Compile_Time_Constraint_Error
1595 Ent : Entity_Id := Empty;
1596 Loc : Source_Ptr := No_Location;
1597 Warn : Boolean := False) return Node_Id
1599 Msgc : String (1 .. Msg'Length + 2);
1600 -- Copy of message, with room for possible ? and ! at end
1610 -- A static constraint error in an instance body is not a fatal error.
1611 -- we choose to inhibit the message altogether, because there is no
1612 -- obvious node (for now) on which to post it. On the other hand the
1613 -- offending node must be replaced with a constraint_error in any case.
1615 -- No messages are generated if we already posted an error on this node
1617 if not Error_Posted (N) then
1618 if Loc /= No_Location then
1624 Msgc (1 .. Msg'Length) := Msg;
1627 -- Message is a warning, even in Ada 95 case
1629 if Msg (Msg'Last) = '?' then
1632 -- In Ada 83, all messages are warnings. In the private part and
1633 -- the body of an instance, constraint_checks are only warnings.
1634 -- We also make this a warning if the Warn parameter is set.
1637 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1643 elsif In_Instance_Not_Visible then
1648 -- Otherwise we have a real error message (Ada 95 static case)
1649 -- and we make this an unconditional message. Note that in the
1650 -- warning case we do not make the message unconditional, it seems
1651 -- quite reasonable to delete messages like this (about exceptions
1652 -- that will be raised) in dead code.
1660 -- Should we generate a warning? The answer is not quite yes. The
1661 -- very annoying exception occurs in the case of a short circuit
1662 -- operator where the left operand is static and decisive. Climb
1663 -- parents to see if that is the case we have here. Conditional
1664 -- expressions with decisive conditions are a similar situation.
1672 -- And then with False as left operand
1674 if Nkind (P) = N_And_Then
1675 and then Compile_Time_Known_Value (Left_Opnd (P))
1676 and then Is_False (Expr_Value (Left_Opnd (P)))
1681 -- OR ELSE with True as left operand
1683 elsif Nkind (P) = N_Or_Else
1684 and then Compile_Time_Known_Value (Left_Opnd (P))
1685 and then Is_True (Expr_Value (Left_Opnd (P)))
1690 -- Conditional expression
1692 elsif Nkind (P) = N_Conditional_Expression then
1694 Cond : constant Node_Id := First (Expressions (P));
1695 Texp : constant Node_Id := Next (Cond);
1696 Fexp : constant Node_Id := Next (Texp);
1699 if Compile_Time_Known_Value (Cond) then
1701 -- Condition is True and we are in the right operand
1703 if Is_True (Expr_Value (Cond))
1704 and then OldP = Fexp
1709 -- Condition is False and we are in the left operand
1711 elsif Is_False (Expr_Value (Cond))
1712 and then OldP = Texp
1720 -- Special case for component association in aggregates, where
1721 -- we want to keep climbing up to the parent aggregate.
1723 elsif Nkind (P) = N_Component_Association
1724 and then Nkind (Parent (P)) = N_Aggregate
1728 -- Keep going if within subexpression
1731 exit when Nkind (P) not in N_Subexpr;
1736 if Present (Ent) then
1737 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1739 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1743 if Inside_Init_Proc then
1745 ("\?& will be raised for objects of this type",
1746 N, Standard_Constraint_Error, Eloc);
1749 ("\?& will be raised at run time",
1750 N, Standard_Constraint_Error, Eloc);
1755 ("\static expression fails Constraint_Check", Eloc);
1756 Set_Error_Posted (N);
1762 end Compile_Time_Constraint_Error;
1764 -----------------------
1765 -- Conditional_Delay --
1766 -----------------------
1768 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1770 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1771 Set_Has_Delayed_Freeze (New_Ent);
1773 end Conditional_Delay;
1775 --------------------
1776 -- Current_Entity --
1777 --------------------
1779 -- The currently visible definition for a given identifier is the
1780 -- one most chained at the start of the visibility chain, i.e. the
1781 -- one that is referenced by the Node_Id value of the name of the
1782 -- given identifier.
1784 function Current_Entity (N : Node_Id) return Entity_Id is
1786 return Get_Name_Entity_Id (Chars (N));
1789 -----------------------------
1790 -- Current_Entity_In_Scope --
1791 -----------------------------
1793 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1795 CS : constant Entity_Id := Current_Scope;
1797 Transient_Case : constant Boolean := Scope_Is_Transient;
1800 E := Get_Name_Entity_Id (Chars (N));
1802 and then Scope (E) /= CS
1803 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1809 end Current_Entity_In_Scope;
1815 function Current_Scope return Entity_Id is
1817 if Scope_Stack.Last = -1 then
1818 return Standard_Standard;
1821 C : constant Entity_Id :=
1822 Scope_Stack.Table (Scope_Stack.Last).Entity;
1827 return Standard_Standard;
1833 ------------------------
1834 -- Current_Subprogram --
1835 ------------------------
1837 function Current_Subprogram return Entity_Id is
1838 Scop : constant Entity_Id := Current_Scope;
1841 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1844 return Enclosing_Subprogram (Scop);
1846 end Current_Subprogram;
1848 ---------------------
1849 -- Defining_Entity --
1850 ---------------------
1852 function Defining_Entity (N : Node_Id) return Entity_Id is
1853 K : constant Node_Kind := Nkind (N);
1854 Err : Entity_Id := Empty;
1859 N_Subprogram_Declaration |
1860 N_Abstract_Subprogram_Declaration |
1862 N_Package_Declaration |
1863 N_Subprogram_Renaming_Declaration |
1864 N_Subprogram_Body_Stub |
1865 N_Generic_Subprogram_Declaration |
1866 N_Generic_Package_Declaration |
1867 N_Formal_Subprogram_Declaration
1869 return Defining_Entity (Specification (N));
1872 N_Component_Declaration |
1873 N_Defining_Program_Unit_Name |
1874 N_Discriminant_Specification |
1876 N_Entry_Declaration |
1877 N_Entry_Index_Specification |
1878 N_Exception_Declaration |
1879 N_Exception_Renaming_Declaration |
1880 N_Formal_Object_Declaration |
1881 N_Formal_Package_Declaration |
1882 N_Formal_Type_Declaration |
1883 N_Full_Type_Declaration |
1884 N_Implicit_Label_Declaration |
1885 N_Incomplete_Type_Declaration |
1886 N_Loop_Parameter_Specification |
1887 N_Number_Declaration |
1888 N_Object_Declaration |
1889 N_Object_Renaming_Declaration |
1890 N_Package_Body_Stub |
1891 N_Parameter_Specification |
1892 N_Private_Extension_Declaration |
1893 N_Private_Type_Declaration |
1895 N_Protected_Body_Stub |
1896 N_Protected_Type_Declaration |
1897 N_Single_Protected_Declaration |
1898 N_Single_Task_Declaration |
1899 N_Subtype_Declaration |
1902 N_Task_Type_Declaration
1904 return Defining_Identifier (N);
1907 return Defining_Entity (Proper_Body (N));
1910 N_Function_Instantiation |
1911 N_Function_Specification |
1912 N_Generic_Function_Renaming_Declaration |
1913 N_Generic_Package_Renaming_Declaration |
1914 N_Generic_Procedure_Renaming_Declaration |
1916 N_Package_Instantiation |
1917 N_Package_Renaming_Declaration |
1918 N_Package_Specification |
1919 N_Procedure_Instantiation |
1920 N_Procedure_Specification
1923 Nam : constant Node_Id := Defining_Unit_Name (N);
1926 if Nkind (Nam) in N_Entity then
1929 -- For Error, make up a name and attach to declaration
1930 -- so we can continue semantic analysis
1932 elsif Nam = Error then
1934 Make_Defining_Identifier (Sloc (N),
1935 Chars => New_Internal_Name ('T'));
1936 Set_Defining_Unit_Name (N, Err);
1939 -- If not an entity, get defining identifier
1942 return Defining_Identifier (Nam);
1946 when N_Block_Statement =>
1947 return Entity (Identifier (N));
1950 raise Program_Error;
1953 end Defining_Entity;
1955 --------------------------
1956 -- Denotes_Discriminant --
1957 --------------------------
1959 function Denotes_Discriminant
1961 Check_Concurrent : Boolean := False) return Boolean
1965 if not Is_Entity_Name (N)
1966 or else No (Entity (N))
1973 -- If we are checking for a protected type, the discriminant may have
1974 -- been rewritten as the corresponding discriminal of the original type
1975 -- or of the corresponding concurrent record, depending on whether we
1976 -- are in the spec or body of the protected type.
1978 return Ekind (E) = E_Discriminant
1981 and then Ekind (E) = E_In_Parameter
1982 and then Present (Discriminal_Link (E))
1984 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
1986 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1988 end Denotes_Discriminant;
1990 -----------------------------
1991 -- Depends_On_Discriminant --
1992 -----------------------------
1994 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1999 Get_Index_Bounds (N, L, H);
2000 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2001 end Depends_On_Discriminant;
2003 -------------------------
2004 -- Designate_Same_Unit --
2005 -------------------------
2007 function Designate_Same_Unit
2009 Name2 : Node_Id) return Boolean
2011 K1 : constant Node_Kind := Nkind (Name1);
2012 K2 : constant Node_Kind := Nkind (Name2);
2014 function Prefix_Node (N : Node_Id) return Node_Id;
2015 -- Returns the parent unit name node of a defining program unit name
2016 -- or the prefix if N is a selected component or an expanded name.
2018 function Select_Node (N : Node_Id) return Node_Id;
2019 -- Returns the defining identifier node of a defining program unit
2020 -- name or the selector node if N is a selected component or an
2027 function Prefix_Node (N : Node_Id) return Node_Id is
2029 if Nkind (N) = N_Defining_Program_Unit_Name then
2041 function Select_Node (N : Node_Id) return Node_Id is
2043 if Nkind (N) = N_Defining_Program_Unit_Name then
2044 return Defining_Identifier (N);
2047 return Selector_Name (N);
2051 -- Start of processing for Designate_Next_Unit
2054 if (K1 = N_Identifier or else
2055 K1 = N_Defining_Identifier)
2057 (K2 = N_Identifier or else
2058 K2 = N_Defining_Identifier)
2060 return Chars (Name1) = Chars (Name2);
2063 (K1 = N_Expanded_Name or else
2064 K1 = N_Selected_Component or else
2065 K1 = N_Defining_Program_Unit_Name)
2067 (K2 = N_Expanded_Name or else
2068 K2 = N_Selected_Component or else
2069 K2 = N_Defining_Program_Unit_Name)
2072 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2074 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2079 end Designate_Same_Unit;
2081 ----------------------------
2082 -- Enclosing_Generic_Body --
2083 ----------------------------
2085 function Enclosing_Generic_Body
2086 (N : Node_Id) return Node_Id
2094 while Present (P) loop
2095 if Nkind (P) = N_Package_Body
2096 or else Nkind (P) = N_Subprogram_Body
2098 Spec := Corresponding_Spec (P);
2100 if Present (Spec) then
2101 Decl := Unit_Declaration_Node (Spec);
2103 if Nkind (Decl) = N_Generic_Package_Declaration
2104 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2115 end Enclosing_Generic_Body;
2117 ----------------------------
2118 -- Enclosing_Generic_Unit --
2119 ----------------------------
2121 function Enclosing_Generic_Unit
2122 (N : Node_Id) return Node_Id
2130 while Present (P) loop
2131 if Nkind (P) = N_Generic_Package_Declaration
2132 or else Nkind (P) = N_Generic_Subprogram_Declaration
2136 elsif Nkind (P) = N_Package_Body
2137 or else Nkind (P) = N_Subprogram_Body
2139 Spec := Corresponding_Spec (P);
2141 if Present (Spec) then
2142 Decl := Unit_Declaration_Node (Spec);
2144 if Nkind (Decl) = N_Generic_Package_Declaration
2145 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2156 end Enclosing_Generic_Unit;
2158 -------------------------------
2159 -- Enclosing_Lib_Unit_Entity --
2160 -------------------------------
2162 function Enclosing_Lib_Unit_Entity return Entity_Id is
2163 Unit_Entity : Entity_Id;
2166 -- Look for enclosing library unit entity by following scope links.
2167 -- Equivalent to, but faster than indexing through the scope stack.
2169 Unit_Entity := Current_Scope;
2170 while (Present (Scope (Unit_Entity))
2171 and then Scope (Unit_Entity) /= Standard_Standard)
2172 and not Is_Child_Unit (Unit_Entity)
2174 Unit_Entity := Scope (Unit_Entity);
2178 end Enclosing_Lib_Unit_Entity;
2180 -----------------------------
2181 -- Enclosing_Lib_Unit_Node --
2182 -----------------------------
2184 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2185 Current_Node : Node_Id;
2189 while Present (Current_Node)
2190 and then Nkind (Current_Node) /= N_Compilation_Unit
2192 Current_Node := Parent (Current_Node);
2195 if Nkind (Current_Node) /= N_Compilation_Unit then
2199 return Current_Node;
2200 end Enclosing_Lib_Unit_Node;
2202 --------------------------
2203 -- Enclosing_Subprogram --
2204 --------------------------
2206 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2207 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2210 if Dynamic_Scope = Standard_Standard then
2213 elsif Dynamic_Scope = Empty then
2216 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2217 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2219 elsif Ekind (Dynamic_Scope) = E_Block
2220 or else Ekind (Dynamic_Scope) = E_Return_Statement
2222 return Enclosing_Subprogram (Dynamic_Scope);
2224 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2225 return Get_Task_Body_Procedure (Dynamic_Scope);
2227 elsif Convention (Dynamic_Scope) = Convention_Protected then
2228 return Protected_Body_Subprogram (Dynamic_Scope);
2231 return Dynamic_Scope;
2233 end Enclosing_Subprogram;
2235 ------------------------
2236 -- Ensure_Freeze_Node --
2237 ------------------------
2239 procedure Ensure_Freeze_Node (E : Entity_Id) is
2243 if No (Freeze_Node (E)) then
2244 FN := Make_Freeze_Entity (Sloc (E));
2245 Set_Has_Delayed_Freeze (E);
2246 Set_Freeze_Node (E, FN);
2247 Set_Access_Types_To_Process (FN, No_Elist);
2248 Set_TSS_Elist (FN, No_Elist);
2251 end Ensure_Freeze_Node;
2257 procedure Enter_Name (Def_Id : Entity_Id) is
2258 C : constant Entity_Id := Current_Entity (Def_Id);
2259 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2260 S : constant Entity_Id := Current_Scope;
2262 function Is_Private_Component_Renaming (N : Node_Id) return Boolean;
2263 -- Recognize a renaming declaration that is introduced for private
2264 -- components of a protected type. We treat these as weak declarations
2265 -- so that they are overridden by entities with the same name that
2266 -- come from source, such as formals or local variables of a given
2267 -- protected declaration.
2269 -----------------------------------
2270 -- Is_Private_Component_Renaming --
2271 -----------------------------------
2273 function Is_Private_Component_Renaming (N : Node_Id) return Boolean is
2275 return not Comes_From_Source (N)
2276 and then not Comes_From_Source (Current_Scope)
2277 and then Nkind (N) = N_Object_Renaming_Declaration;
2278 end Is_Private_Component_Renaming;
2280 -- Start of processing for Enter_Name
2283 Generate_Definition (Def_Id);
2285 -- Add new name to current scope declarations. Check for duplicate
2286 -- declaration, which may or may not be a genuine error.
2290 -- Case of previous entity entered because of a missing declaration
2291 -- or else a bad subtype indication. Best is to use the new entity,
2292 -- and make the previous one invisible.
2294 if Etype (E) = Any_Type then
2295 Set_Is_Immediately_Visible (E, False);
2297 -- Case of renaming declaration constructed for package instances.
2298 -- if there is an explicit declaration with the same identifier,
2299 -- the renaming is not immediately visible any longer, but remains
2300 -- visible through selected component notation.
2302 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2303 and then not Comes_From_Source (E)
2305 Set_Is_Immediately_Visible (E, False);
2307 -- The new entity may be the package renaming, which has the same
2308 -- same name as a generic formal which has been seen already.
2310 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2311 and then not Comes_From_Source (Def_Id)
2313 Set_Is_Immediately_Visible (E, False);
2315 -- For a fat pointer corresponding to a remote access to subprogram,
2316 -- we use the same identifier as the RAS type, so that the proper
2317 -- name appears in the stub. This type is only retrieved through
2318 -- the RAS type and never by visibility, and is not added to the
2319 -- visibility list (see below).
2321 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2322 and then Present (Corresponding_Remote_Type (Def_Id))
2326 -- A controller component for a type extension overrides the
2327 -- inherited component.
2329 elsif Chars (E) = Name_uController then
2332 -- Case of an implicit operation or derived literal. The new entity
2333 -- hides the implicit one, which is removed from all visibility,
2334 -- i.e. the entity list of its scope, and homonym chain of its name.
2336 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2337 or else Is_Internal (E)
2341 Prev_Vis : Entity_Id;
2342 Decl : constant Node_Id := Parent (E);
2345 -- If E is an implicit declaration, it cannot be the first
2346 -- entity in the scope.
2348 Prev := First_Entity (Current_Scope);
2349 while Present (Prev)
2350 and then Next_Entity (Prev) /= E
2357 -- If E is not on the entity chain of the current scope,
2358 -- it is an implicit declaration in the generic formal
2359 -- part of a generic subprogram. When analyzing the body,
2360 -- the generic formals are visible but not on the entity
2361 -- chain of the subprogram. The new entity will become
2362 -- the visible one in the body.
2365 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2369 Set_Next_Entity (Prev, Next_Entity (E));
2371 if No (Next_Entity (Prev)) then
2372 Set_Last_Entity (Current_Scope, Prev);
2375 if E = Current_Entity (E) then
2379 Prev_Vis := Current_Entity (E);
2380 while Homonym (Prev_Vis) /= E loop
2381 Prev_Vis := Homonym (Prev_Vis);
2385 if Present (Prev_Vis) then
2387 -- Skip E in the visibility chain
2389 Set_Homonym (Prev_Vis, Homonym (E));
2392 Set_Name_Entity_Id (Chars (E), Homonym (E));
2397 -- This section of code could use a comment ???
2399 elsif Present (Etype (E))
2400 and then Is_Concurrent_Type (Etype (E))
2405 elsif Is_Private_Component_Renaming (Parent (Def_Id)) then
2408 -- In the body or private part of an instance, a type extension
2409 -- may introduce a component with the same name as that of an
2410 -- actual. The legality rule is not enforced, but the semantics
2411 -- of the full type with two components of the same name are not
2412 -- clear at this point ???
2414 elsif In_Instance_Not_Visible then
2417 -- When compiling a package body, some child units may have become
2418 -- visible. They cannot conflict with local entities that hide them.
2420 elsif Is_Child_Unit (E)
2421 and then In_Open_Scopes (Scope (E))
2422 and then not Is_Immediately_Visible (E)
2426 -- Conversely, with front-end inlining we may compile the parent
2427 -- body first, and a child unit subsequently. The context is now
2428 -- the parent spec, and body entities are not visible.
2430 elsif Is_Child_Unit (Def_Id)
2431 and then Is_Package_Body_Entity (E)
2432 and then not In_Package_Body (Current_Scope)
2436 -- Case of genuine duplicate declaration
2439 Error_Msg_Sloc := Sloc (E);
2441 -- If the previous declaration is an incomplete type declaration
2442 -- this may be an attempt to complete it with a private type.
2443 -- The following avoids confusing cascaded errors.
2445 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2446 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2449 ("incomplete type cannot be completed" &
2450 " with a private declaration",
2452 Set_Is_Immediately_Visible (E, False);
2453 Set_Full_View (E, Def_Id);
2455 elsif Ekind (E) = E_Discriminant
2456 and then Present (Scope (Def_Id))
2457 and then Scope (Def_Id) /= Current_Scope
2459 -- An inherited component of a record conflicts with
2460 -- a new discriminant. The discriminant is inserted first
2461 -- in the scope, but the error should be posted on it, not
2462 -- on the component.
2464 Error_Msg_Sloc := Sloc (Def_Id);
2465 Error_Msg_N ("& conflicts with declaration#", E);
2468 -- If the name of the unit appears in its own context clause,
2469 -- a dummy package with the name has already been created, and
2470 -- the error emitted. Try to continue quietly.
2472 elsif Error_Posted (E)
2473 and then Sloc (E) = No_Location
2474 and then Nkind (Parent (E)) = N_Package_Specification
2475 and then Current_Scope = Standard_Standard
2477 Set_Scope (Def_Id, Current_Scope);
2481 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2483 -- Avoid cascaded messages with duplicate components in
2486 if Ekind (E) = E_Component
2487 or else Ekind (E) = E_Discriminant
2493 if Nkind (Parent (Parent (Def_Id)))
2494 = N_Generic_Subprogram_Declaration
2496 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2498 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2501 -- If entity is in standard, then we are in trouble, because
2502 -- it means that we have a library package with a duplicated
2503 -- name. That's hard to recover from, so abort!
2505 if S = Standard_Standard then
2506 raise Unrecoverable_Error;
2508 -- Otherwise we continue with the declaration. Having two
2509 -- identical declarations should not cause us too much trouble!
2517 -- If we fall through, declaration is OK , or OK enough to continue
2519 -- If Def_Id is a discriminant or a record component we are in the
2520 -- midst of inheriting components in a derived record definition.
2521 -- Preserve their Ekind and Etype.
2523 if Ekind (Def_Id) = E_Discriminant
2524 or else Ekind (Def_Id) = E_Component
2528 -- If a type is already set, leave it alone (happens whey a type
2529 -- declaration is reanalyzed following a call to the optimizer)
2531 elsif Present (Etype (Def_Id)) then
2534 -- Otherwise, the kind E_Void insures that premature uses of the entity
2535 -- will be detected. Any_Type insures that no cascaded errors will occur
2538 Set_Ekind (Def_Id, E_Void);
2539 Set_Etype (Def_Id, Any_Type);
2542 -- Inherited discriminants and components in derived record types are
2543 -- immediately visible. Itypes are not.
2545 if Ekind (Def_Id) = E_Discriminant
2546 or else Ekind (Def_Id) = E_Component
2547 or else (No (Corresponding_Remote_Type (Def_Id))
2548 and then not Is_Itype (Def_Id))
2550 Set_Is_Immediately_Visible (Def_Id);
2551 Set_Current_Entity (Def_Id);
2554 Set_Homonym (Def_Id, C);
2555 Append_Entity (Def_Id, S);
2556 Set_Public_Status (Def_Id);
2558 -- Warn if new entity hides an old one
2560 if Warn_On_Hiding and then Present (C)
2562 -- Don't warn for record components since they always have a well
2563 -- defined scope which does not confuse other uses. Note that in
2564 -- some cases, Ekind has not been set yet.
2566 and then Ekind (C) /= E_Component
2567 and then Ekind (C) /= E_Discriminant
2568 and then Nkind (Parent (C)) /= N_Component_Declaration
2569 and then Ekind (Def_Id) /= E_Component
2570 and then Ekind (Def_Id) /= E_Discriminant
2571 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2573 -- Don't warn for one character variables. It is too common to use
2574 -- such variables as locals and will just cause too many false hits.
2576 and then Length_Of_Name (Chars (C)) /= 1
2578 -- Don't warn for non-source eneities
2580 and then Comes_From_Source (C)
2581 and then Comes_From_Source (Def_Id)
2583 -- Don't warn unless entity in question is in extended main source
2585 and then In_Extended_Main_Source_Unit (Def_Id)
2587 -- Finally, the hidden entity must be either immediately visible
2588 -- or use visible (from a used package)
2591 (Is_Immediately_Visible (C)
2593 Is_Potentially_Use_Visible (C))
2595 Error_Msg_Sloc := Sloc (C);
2596 Error_Msg_N ("declaration hides &#?", Def_Id);
2600 --------------------------
2601 -- Explain_Limited_Type --
2602 --------------------------
2604 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2608 -- For array, component type must be limited
2610 if Is_Array_Type (T) then
2611 Error_Msg_Node_2 := T;
2613 ("\component type& of type& is limited", N, Component_Type (T));
2614 Explain_Limited_Type (Component_Type (T), N);
2616 elsif Is_Record_Type (T) then
2618 -- No need for extra messages if explicit limited record
2620 if Is_Limited_Record (Base_Type (T)) then
2624 -- Otherwise find a limited component. Check only components that
2625 -- come from source, or inherited components that appear in the
2626 -- source of the ancestor.
2628 C := First_Component (T);
2629 while Present (C) loop
2630 if Is_Limited_Type (Etype (C))
2632 (Comes_From_Source (C)
2634 (Present (Original_Record_Component (C))
2636 Comes_From_Source (Original_Record_Component (C))))
2638 Error_Msg_Node_2 := T;
2639 Error_Msg_NE ("\component& of type& has limited type", N, C);
2640 Explain_Limited_Type (Etype (C), N);
2647 -- The type may be declared explicitly limited, even if no component
2648 -- of it is limited, in which case we fall out of the loop.
2651 end Explain_Limited_Type;
2657 procedure Find_Actual
2659 Formal : out Entity_Id;
2662 Parnt : constant Node_Id := Parent (N);
2666 if (Nkind (Parnt) = N_Indexed_Component
2668 Nkind (Parnt) = N_Selected_Component)
2669 and then N = Prefix (Parnt)
2671 Find_Actual (Parnt, Formal, Call);
2674 elsif Nkind (Parnt) = N_Parameter_Association
2675 and then N = Explicit_Actual_Parameter (Parnt)
2677 Call := Parent (Parnt);
2679 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2688 -- If we have a call to a subprogram look for the parameter. Note that
2689 -- we exclude overloaded calls, since we don't know enough to be sure
2690 -- of giving the right answer in this case.
2692 if Is_Entity_Name (Name (Call))
2693 and then Present (Entity (Name (Call)))
2694 and then Is_Overloadable (Entity (Name (Call)))
2695 and then not Is_Overloaded (Name (Call))
2697 -- Fall here if we are definitely a parameter
2699 Actual := First_Actual (Call);
2700 Formal := First_Formal (Entity (Name (Call)));
2701 while Present (Formal) and then Present (Actual) loop
2705 Actual := Next_Actual (Actual);
2706 Formal := Next_Formal (Formal);
2711 -- Fall through here if we did not find matching actual
2717 -------------------------------------
2718 -- Find_Corresponding_Discriminant --
2719 -------------------------------------
2721 function Find_Corresponding_Discriminant
2723 Typ : Entity_Id) return Entity_Id
2725 Par_Disc : Entity_Id;
2726 Old_Disc : Entity_Id;
2727 New_Disc : Entity_Id;
2730 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2732 -- The original type may currently be private, and the discriminant
2733 -- only appear on its full view.
2735 if Is_Private_Type (Scope (Par_Disc))
2736 and then not Has_Discriminants (Scope (Par_Disc))
2737 and then Present (Full_View (Scope (Par_Disc)))
2739 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2741 Old_Disc := First_Discriminant (Scope (Par_Disc));
2744 if Is_Class_Wide_Type (Typ) then
2745 New_Disc := First_Discriminant (Root_Type (Typ));
2747 New_Disc := First_Discriminant (Typ);
2750 while Present (Old_Disc) and then Present (New_Disc) loop
2751 if Old_Disc = Par_Disc then
2754 Next_Discriminant (Old_Disc);
2755 Next_Discriminant (New_Disc);
2759 -- Should always find it
2761 raise Program_Error;
2762 end Find_Corresponding_Discriminant;
2764 --------------------------
2765 -- Find_Overlaid_Object --
2766 --------------------------
2768 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2772 -- We are looking for one of the two following forms:
2774 -- for X'Address use Y'Address
2778 -- Const : constant Address := expr;
2780 -- for X'Address use Const;
2782 -- In the second case, the expr is either Y'Address, or recursively a
2783 -- constant that eventually references Y'Address.
2785 if Nkind (N) = N_Attribute_Definition_Clause
2786 and then Chars (N) = Name_Address
2788 -- This loop checks the form of the expression for Y'Address where Y
2789 -- is an object entity name. The first loop checks the original
2790 -- expression in the attribute definition clause. Subsequent loops
2791 -- check referenced constants.
2793 Expr := Expression (N);
2795 -- Check for Y'Address where Y is an object entity
2797 if Nkind (Expr) = N_Attribute_Reference
2798 and then Attribute_Name (Expr) = Name_Address
2799 and then Is_Entity_Name (Prefix (Expr))
2800 and then Is_Object (Entity (Prefix (Expr)))
2802 return Entity (Prefix (Expr));
2804 -- Check for Const where Const is a constant entity
2806 elsif Is_Entity_Name (Expr)
2807 and then Ekind (Entity (Expr)) = E_Constant
2809 Expr := Constant_Value (Entity (Expr));
2811 -- Anything else does not need checking
2820 end Find_Overlaid_Object;
2822 --------------------------------------------
2823 -- Find_Overridden_Synchronized_Primitive --
2824 --------------------------------------------
2826 function Find_Overridden_Synchronized_Primitive
2827 (Def_Id : Entity_Id;
2828 First_Hom : Entity_Id;
2829 Ifaces_List : Elist_Id;
2830 In_Scope : Boolean) return Entity_Id
2832 Candidate : Entity_Id := Empty;
2833 Hom : Entity_Id := Empty;
2834 Iface_Typ : Entity_Id;
2835 Subp : Entity_Id := Empty;
2836 Tag_Typ : Entity_Id;
2838 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
2839 -- For an overridden subprogram Subp, check whether the mode of its
2840 -- first parameter is correct depending on the kind of Tag_Typ.
2842 function Matches_Prefixed_View_Profile
2843 (Prim_Params : List_Id;
2844 Iface_Params : List_Id) return Boolean;
2845 -- Determine whether a subprogram's parameter profile Prim_Params
2846 -- matches that of a potentially overriden interface subprogram
2847 -- Iface_Params. Also determine if the type of first parameter of
2848 -- Iface_Params is an implemented interface.
2850 -----------------------------
2851 -- Has_Correct_Formal_Mode --
2852 -----------------------------
2854 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
2858 Param := First_Formal (Subp);
2860 -- In order for an entry or a protected procedure to override, the
2861 -- first parameter of the overridden routine must be of mode "out",
2862 -- "in out" or access-to-variable.
2864 if (Ekind (Subp) = E_Entry
2865 or else Ekind (Subp) = E_Procedure)
2866 and then Is_Protected_Type (Tag_Typ)
2867 and then Ekind (Param) /= E_In_Out_Parameter
2868 and then Ekind (Param) /= E_Out_Parameter
2869 and then Nkind (Parameter_Type (Parent (Param))) /=
2875 -- All other cases are OK since a task entry or routine does not
2876 -- have a restriction on the mode of the first parameter of the
2877 -- overridden interface routine.
2880 end Has_Correct_Formal_Mode;
2882 -----------------------------------
2883 -- Matches_Prefixed_View_Profile --
2884 -----------------------------------
2886 function Matches_Prefixed_View_Profile
2887 (Prim_Params : List_Id;
2888 Iface_Params : List_Id) return Boolean
2890 Iface_Id : Entity_Id;
2891 Iface_Param : Node_Id;
2892 Iface_Typ : Entity_Id;
2893 Prim_Id : Entity_Id;
2894 Prim_Param : Node_Id;
2895 Prim_Typ : Entity_Id;
2897 function Is_Implemented (Iface : Entity_Id) return Boolean;
2898 -- Determine if Iface is implemented by the current task or
2901 --------------------
2902 -- Is_Implemented --
2903 --------------------
2905 function Is_Implemented (Iface : Entity_Id) return Boolean is
2906 Iface_Elmt : Elmt_Id;
2909 Iface_Elmt := First_Elmt (Ifaces_List);
2910 while Present (Iface_Elmt) loop
2911 if Node (Iface_Elmt) = Iface then
2915 Next_Elmt (Iface_Elmt);
2921 -- Start of processing for Matches_Prefixed_View_Profile
2924 Iface_Param := First (Iface_Params);
2925 Iface_Typ := Find_Parameter_Type (Iface_Param);
2926 Prim_Param := First (Prim_Params);
2928 -- The first parameter of the potentially overriden subprogram
2929 -- must be an interface implemented by Prim.
2931 if not Is_Interface (Iface_Typ)
2932 or else not Is_Implemented (Iface_Typ)
2937 -- The checks on the object parameters are done, move onto the rest
2938 -- of the parameters.
2940 if not In_Scope then
2941 Prim_Param := Next (Prim_Param);
2944 Iface_Param := Next (Iface_Param);
2945 while Present (Iface_Param) and then Present (Prim_Param) loop
2946 Iface_Id := Defining_Identifier (Iface_Param);
2947 Iface_Typ := Find_Parameter_Type (Iface_Param);
2948 Prim_Id := Defining_Identifier (Prim_Param);
2949 Prim_Typ := Find_Parameter_Type (Prim_Param);
2951 -- Case of multiple interface types inside a parameter profile
2953 -- (Obj_Param : in out Iface; ...; Param : Iface)
2955 -- If the interface type is implemented, then the matching type
2956 -- in the primitive should be the implementing record type.
2958 if Ekind (Iface_Typ) = E_Record_Type
2959 and then Is_Interface (Iface_Typ)
2960 and then Is_Implemented (Iface_Typ)
2962 if Prim_Typ /= Tag_Typ then
2966 -- The two parameters must be both mode and subtype conformant
2968 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
2970 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
2979 -- One of the two lists contains more parameters than the other
2981 if Present (Iface_Param) or else Present (Prim_Param) then
2986 end Matches_Prefixed_View_Profile;
2988 -- Start of processing for Find_Overridden_Synchronized_Primitive
2991 -- At this point the caller should have collected the interfaces
2992 -- implemented by the synchronized type.
2994 pragma Assert (Present (Ifaces_List));
2996 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2997 -- subprogram was declared within a protected or a task type, the type
2998 -- is the scope itself, otherwise it is the type of the first parameter.
3001 Tag_Typ := Scope (Def_Id);
3003 elsif Present (First_Formal (Def_Id)) then
3004 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
3006 -- A parameterless subprogram which is declared outside a synchronized
3007 -- type cannot act as a primitive, thus it cannot override anything.
3013 -- Traverse the homonym chain, looking at a potentially overriden
3014 -- subprogram that belongs to an implemented interface.
3017 while Present (Hom) loop
3020 -- Entries can override abstract or null interface procedures
3022 if Ekind (Def_Id) = E_Entry
3023 and then Ekind (Subp) = E_Procedure
3024 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3025 and then (Is_Abstract_Subprogram (Subp)
3026 or else Null_Present (Parent (Subp)))
3028 while Present (Alias (Subp)) loop
3029 Subp := Alias (Subp);
3032 if Matches_Prefixed_View_Profile
3033 (Parameter_Specifications (Parent (Def_Id)),
3034 Parameter_Specifications (Parent (Subp)))
3040 if Has_Correct_Formal_Mode (Candidate) then
3045 -- Procedures can override abstract or null interface procedures
3047 elsif Ekind (Def_Id) = E_Procedure
3048 and then Ekind (Subp) = E_Procedure
3049 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3050 and then (Is_Abstract_Subprogram (Subp)
3051 or else Null_Present (Parent (Subp)))
3052 and then Matches_Prefixed_View_Profile
3053 (Parameter_Specifications (Parent (Def_Id)),
3054 Parameter_Specifications (Parent (Subp)))
3060 if Has_Correct_Formal_Mode (Candidate) then
3064 -- Functions can override abstract interface functions
3066 elsif Ekind (Def_Id) = E_Function
3067 and then Ekind (Subp) = E_Function
3068 and then Nkind (Parent (Subp)) = N_Function_Specification
3069 and then Is_Abstract_Subprogram (Subp)
3070 and then Matches_Prefixed_View_Profile
3071 (Parameter_Specifications (Parent (Def_Id)),
3072 Parameter_Specifications (Parent (Subp)))
3073 and then Etype (Result_Definition (Parent (Def_Id))) =
3074 Etype (Result_Definition (Parent (Subp)))
3079 Hom := Homonym (Hom);
3082 -- After examining all candidates for overriding, we are left with
3083 -- the best match which is a mode incompatible interface routine.
3084 -- Do not emit an error if the Expander is active since this error
3085 -- will be detected later on after all concurrent types are expanded
3086 -- and all wrappers are built. This check is meant for spec-only
3089 if Present (Candidate)
3090 and then not Expander_Active
3092 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
3094 -- Def_Id is primitive of a protected type, declared inside the type,
3095 -- and the candidate is primitive of a limited or synchronized
3099 and then Is_Protected_Type (Tag_Typ)
3101 (Is_Limited_Interface (Iface_Typ)
3102 or else Is_Protected_Interface (Iface_Typ)
3103 or else Is_Synchronized_Interface (Iface_Typ)
3104 or else Is_Task_Interface (Iface_Typ))
3106 -- Must reword this message, comma before to in -gnatj mode ???
3109 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3110 "access-to-variable", Tag_Typ, Candidate);
3112 ("\to be overridden by protected procedure or entry " &
3113 "(RM 9.4(11.9/2))", Tag_Typ);
3118 end Find_Overridden_Synchronized_Primitive;
3120 -------------------------
3121 -- Find_Parameter_Type --
3122 -------------------------
3124 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3126 if Nkind (Param) /= N_Parameter_Specification then
3129 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3130 return Etype (Subtype_Mark (Parameter_Type (Param)));
3133 return Etype (Parameter_Type (Param));
3135 end Find_Parameter_Type;
3137 -----------------------------
3138 -- Find_Static_Alternative --
3139 -----------------------------
3141 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3142 Expr : constant Node_Id := Expression (N);
3143 Val : constant Uint := Expr_Value (Expr);
3148 Alt := First (Alternatives (N));
3151 if Nkind (Alt) /= N_Pragma then
3152 Choice := First (Discrete_Choices (Alt));
3153 while Present (Choice) loop
3155 -- Others choice, always matches
3157 if Nkind (Choice) = N_Others_Choice then
3160 -- Range, check if value is in the range
3162 elsif Nkind (Choice) = N_Range then
3164 Val >= Expr_Value (Low_Bound (Choice))
3166 Val <= Expr_Value (High_Bound (Choice));
3168 -- Choice is a subtype name. Note that we know it must
3169 -- be a static subtype, since otherwise it would have
3170 -- been diagnosed as illegal.
3172 elsif Is_Entity_Name (Choice)
3173 and then Is_Type (Entity (Choice))
3175 exit Search when Is_In_Range (Expr, Etype (Choice));
3177 -- Choice is a subtype indication
3179 elsif Nkind (Choice) = N_Subtype_Indication then
3181 C : constant Node_Id := Constraint (Choice);
3182 R : constant Node_Id := Range_Expression (C);
3186 Val >= Expr_Value (Low_Bound (R))
3188 Val <= Expr_Value (High_Bound (R));
3191 -- Choice is a simple expression
3194 exit Search when Val = Expr_Value (Choice);
3202 pragma Assert (Present (Alt));
3205 -- The above loop *must* terminate by finding a match, since
3206 -- we know the case statement is valid, and the value of the
3207 -- expression is known at compile time. When we fall out of
3208 -- the loop, Alt points to the alternative that we know will
3209 -- be selected at run time.
3212 end Find_Static_Alternative;
3218 function First_Actual (Node : Node_Id) return Node_Id is
3222 if No (Parameter_Associations (Node)) then
3226 N := First (Parameter_Associations (Node));
3228 if Nkind (N) = N_Parameter_Association then
3229 return First_Named_Actual (Node);
3235 -------------------------
3236 -- Full_Qualified_Name --
3237 -------------------------
3239 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3241 pragma Warnings (Off, Res);
3243 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3244 -- Compute recursively the qualified name without NUL at the end
3246 ----------------------------------
3247 -- Internal_Full_Qualified_Name --
3248 ----------------------------------
3250 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3251 Ent : Entity_Id := E;
3252 Parent_Name : String_Id := No_String;
3255 -- Deals properly with child units
3257 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3258 Ent := Defining_Identifier (Ent);
3261 -- Compute qualification recursively (only "Standard" has no scope)
3263 if Present (Scope (Scope (Ent))) then
3264 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3267 -- Every entity should have a name except some expanded blocks
3268 -- don't bother about those.
3270 if Chars (Ent) = No_Name then
3274 -- Add a period between Name and qualification
3276 if Parent_Name /= No_String then
3277 Start_String (Parent_Name);
3278 Store_String_Char (Get_Char_Code ('.'));
3284 -- Generates the entity name in upper case
3286 Get_Decoded_Name_String (Chars (Ent));
3288 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3290 end Internal_Full_Qualified_Name;
3292 -- Start of processing for Full_Qualified_Name
3295 Res := Internal_Full_Qualified_Name (E);
3296 Store_String_Char (Get_Char_Code (ASCII.nul));
3298 end Full_Qualified_Name;
3300 -----------------------
3301 -- Gather_Components --
3302 -----------------------
3304 procedure Gather_Components
3306 Comp_List : Node_Id;
3307 Governed_By : List_Id;
3309 Report_Errors : out Boolean)
3313 Discrete_Choice : Node_Id;
3314 Comp_Item : Node_Id;
3316 Discrim : Entity_Id;
3317 Discrim_Name : Node_Id;
3318 Discrim_Value : Node_Id;
3321 Report_Errors := False;
3323 if No (Comp_List) or else Null_Present (Comp_List) then
3326 elsif Present (Component_Items (Comp_List)) then
3327 Comp_Item := First (Component_Items (Comp_List));
3333 while Present (Comp_Item) loop
3335 -- Skip the tag of a tagged record, the interface tags, as well
3336 -- as all items that are not user components (anonymous types,
3337 -- rep clauses, Parent field, controller field).
3339 if Nkind (Comp_Item) = N_Component_Declaration then
3341 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3343 if not Is_Tag (Comp)
3344 and then Chars (Comp) /= Name_uParent
3345 and then Chars (Comp) /= Name_uController
3347 Append_Elmt (Comp, Into);
3355 if No (Variant_Part (Comp_List)) then
3358 Discrim_Name := Name (Variant_Part (Comp_List));
3359 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3362 -- Look for the discriminant that governs this variant part.
3363 -- The discriminant *must* be in the Governed_By List
3365 Assoc := First (Governed_By);
3366 Find_Constraint : loop
3367 Discrim := First (Choices (Assoc));
3368 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3369 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3371 Chars (Corresponding_Discriminant (Entity (Discrim)))
3372 = Chars (Discrim_Name))
3373 or else Chars (Original_Record_Component (Entity (Discrim)))
3374 = Chars (Discrim_Name);
3376 if No (Next (Assoc)) then
3377 if not Is_Constrained (Typ)
3378 and then Is_Derived_Type (Typ)
3379 and then Present (Stored_Constraint (Typ))
3381 -- If the type is a tagged type with inherited discriminants,
3382 -- use the stored constraint on the parent in order to find
3383 -- the values of discriminants that are otherwise hidden by an
3384 -- explicit constraint. Renamed discriminants are handled in
3387 -- If several parent discriminants are renamed by a single
3388 -- discriminant of the derived type, the call to obtain the
3389 -- Corresponding_Discriminant field only retrieves the last
3390 -- of them. We recover the constraint on the others from the
3391 -- Stored_Constraint as well.
3398 D := First_Discriminant (Etype (Typ));
3399 C := First_Elmt (Stored_Constraint (Typ));
3400 while Present (D) and then Present (C) loop
3401 if Chars (Discrim_Name) = Chars (D) then
3402 if Is_Entity_Name (Node (C))
3403 and then Entity (Node (C)) = Entity (Discrim)
3405 -- D is renamed by Discrim, whose value is given in
3412 Make_Component_Association (Sloc (Typ),
3414 (New_Occurrence_Of (D, Sloc (Typ))),
3415 Duplicate_Subexpr_No_Checks (Node (C)));
3417 exit Find_Constraint;
3420 Next_Discriminant (D);
3427 if No (Next (Assoc)) then
3428 Error_Msg_NE (" missing value for discriminant&",
3429 First (Governed_By), Discrim_Name);
3430 Report_Errors := True;
3435 end loop Find_Constraint;
3437 Discrim_Value := Expression (Assoc);
3439 if not Is_OK_Static_Expression (Discrim_Value) then
3441 ("value for discriminant & must be static!",
3442 Discrim_Value, Discrim);
3443 Why_Not_Static (Discrim_Value);
3444 Report_Errors := True;
3448 Search_For_Discriminant_Value : declare
3454 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3457 Find_Discrete_Value : while Present (Variant) loop
3458 Discrete_Choice := First (Discrete_Choices (Variant));
3459 while Present (Discrete_Choice) loop
3461 exit Find_Discrete_Value when
3462 Nkind (Discrete_Choice) = N_Others_Choice;
3464 Get_Index_Bounds (Discrete_Choice, Low, High);
3466 UI_Low := Expr_Value (Low);
3467 UI_High := Expr_Value (High);
3469 exit Find_Discrete_Value when
3470 UI_Low <= UI_Discrim_Value
3472 UI_High >= UI_Discrim_Value;
3474 Next (Discrete_Choice);
3477 Next_Non_Pragma (Variant);
3478 end loop Find_Discrete_Value;
3479 end Search_For_Discriminant_Value;
3481 if No (Variant) then
3483 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3484 Report_Errors := True;
3488 -- If we have found the corresponding choice, recursively add its
3489 -- components to the Into list.
3491 Gather_Components (Empty,
3492 Component_List (Variant), Governed_By, Into, Report_Errors);
3493 end Gather_Components;
3495 ------------------------
3496 -- Get_Actual_Subtype --
3497 ------------------------
3499 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3500 Typ : constant Entity_Id := Etype (N);
3501 Utyp : Entity_Id := Underlying_Type (Typ);
3510 -- If what we have is an identifier that references a subprogram
3511 -- formal, or a variable or constant object, then we get the actual
3512 -- subtype from the referenced entity if one has been built.
3514 if Nkind (N) = N_Identifier
3516 (Is_Formal (Entity (N))
3517 or else Ekind (Entity (N)) = E_Constant
3518 or else Ekind (Entity (N)) = E_Variable)
3519 and then Present (Actual_Subtype (Entity (N)))
3521 return Actual_Subtype (Entity (N));
3523 -- Actual subtype of unchecked union is always itself. We never need
3524 -- the "real" actual subtype. If we did, we couldn't get it anyway
3525 -- because the discriminant is not available. The restrictions on
3526 -- Unchecked_Union are designed to make sure that this is OK.
3528 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3531 -- Here for the unconstrained case, we must find actual subtype
3532 -- No actual subtype is available, so we must build it on the fly.
3534 -- Checking the type, not the underlying type, for constrainedness
3535 -- seems to be necessary. Maybe all the tests should be on the type???
3537 elsif (not Is_Constrained (Typ))
3538 and then (Is_Array_Type (Utyp)
3539 or else (Is_Record_Type (Utyp)
3540 and then Has_Discriminants (Utyp)))
3541 and then not Has_Unknown_Discriminants (Utyp)
3542 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3544 -- Nothing to do if in default expression
3546 if In_Default_Expression then
3549 elsif Is_Private_Type (Typ)
3550 and then not Has_Discriminants (Typ)
3552 -- If the type has no discriminants, there is no subtype to
3553 -- build, even if the underlying type is discriminated.
3557 -- Else build the actual subtype
3560 Decl := Build_Actual_Subtype (Typ, N);
3561 Atyp := Defining_Identifier (Decl);
3563 -- If Build_Actual_Subtype generated a new declaration then use it
3567 -- The actual subtype is an Itype, so analyze the declaration,
3568 -- but do not attach it to the tree, to get the type defined.
3570 Set_Parent (Decl, N);
3571 Set_Is_Itype (Atyp);
3572 Analyze (Decl, Suppress => All_Checks);
3573 Set_Associated_Node_For_Itype (Atyp, N);
3574 Set_Has_Delayed_Freeze (Atyp, False);
3576 -- We need to freeze the actual subtype immediately. This is
3577 -- needed, because otherwise this Itype will not get frozen
3578 -- at all, and it is always safe to freeze on creation because
3579 -- any associated types must be frozen at this point.
3581 Freeze_Itype (Atyp, N);
3584 -- Otherwise we did not build a declaration, so return original
3591 -- For all remaining cases, the actual subtype is the same as
3592 -- the nominal type.
3597 end Get_Actual_Subtype;
3599 -------------------------------------
3600 -- Get_Actual_Subtype_If_Available --
3601 -------------------------------------
3603 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3604 Typ : constant Entity_Id := Etype (N);
3607 -- If what we have is an identifier that references a subprogram
3608 -- formal, or a variable or constant object, then we get the actual
3609 -- subtype from the referenced entity if one has been built.
3611 if Nkind (N) = N_Identifier
3613 (Is_Formal (Entity (N))
3614 or else Ekind (Entity (N)) = E_Constant
3615 or else Ekind (Entity (N)) = E_Variable)
3616 and then Present (Actual_Subtype (Entity (N)))
3618 return Actual_Subtype (Entity (N));
3620 -- Otherwise the Etype of N is returned unchanged
3625 end Get_Actual_Subtype_If_Available;
3627 -------------------------------
3628 -- Get_Default_External_Name --
3629 -------------------------------
3631 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3633 Get_Decoded_Name_String (Chars (E));
3635 if Opt.External_Name_Imp_Casing = Uppercase then
3636 Set_Casing (All_Upper_Case);
3638 Set_Casing (All_Lower_Case);
3642 Make_String_Literal (Sloc (E),
3643 Strval => String_From_Name_Buffer);
3644 end Get_Default_External_Name;
3646 ---------------------------
3647 -- Get_Enum_Lit_From_Pos --
3648 ---------------------------
3650 function Get_Enum_Lit_From_Pos
3653 Loc : Source_Ptr) return Node_Id
3658 -- In the case where the literal is of type Character, Wide_Character
3659 -- or Wide_Wide_Character or of a type derived from them, there needs
3660 -- to be some special handling since there is no explicit chain of
3661 -- literals to search. Instead, an N_Character_Literal node is created
3662 -- with the appropriate Char_Code and Chars fields.
3664 if Root_Type (T) = Standard_Character
3665 or else Root_Type (T) = Standard_Wide_Character
3666 or else Root_Type (T) = Standard_Wide_Wide_Character
3668 Set_Character_Literal_Name (UI_To_CC (Pos));
3670 Make_Character_Literal (Loc,
3672 Char_Literal_Value => Pos);
3674 -- For all other cases, we have a complete table of literals, and
3675 -- we simply iterate through the chain of literal until the one
3676 -- with the desired position value is found.
3680 Lit := First_Literal (Base_Type (T));
3681 for J in 1 .. UI_To_Int (Pos) loop
3685 return New_Occurrence_Of (Lit, Loc);
3687 end Get_Enum_Lit_From_Pos;
3689 ------------------------
3690 -- Get_Generic_Entity --
3691 ------------------------
3693 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3694 Ent : constant Entity_Id := Entity (Name (N));
3696 if Present (Renamed_Object (Ent)) then
3697 return Renamed_Object (Ent);
3701 end Get_Generic_Entity;
3703 ----------------------
3704 -- Get_Index_Bounds --
3705 ----------------------
3707 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3708 Kind : constant Node_Kind := Nkind (N);
3712 if Kind = N_Range then
3714 H := High_Bound (N);
3716 elsif Kind = N_Subtype_Indication then
3717 R := Range_Expression (Constraint (N));
3725 L := Low_Bound (Range_Expression (Constraint (N)));
3726 H := High_Bound (Range_Expression (Constraint (N)));
3729 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3730 if Error_Posted (Scalar_Range (Entity (N))) then
3734 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3735 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3738 L := Low_Bound (Scalar_Range (Entity (N)));
3739 H := High_Bound (Scalar_Range (Entity (N)));
3743 -- N is an expression, indicating a range with one value
3748 end Get_Index_Bounds;
3750 ----------------------------------
3751 -- Get_Library_Unit_Name_string --
3752 ----------------------------------
3754 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3755 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3758 Get_Unit_Name_String (Unit_Name_Id);
3760 -- Remove seven last character (" (spec)" or " (body)")
3762 Name_Len := Name_Len - 7;
3763 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3764 end Get_Library_Unit_Name_String;
3766 ------------------------
3767 -- Get_Name_Entity_Id --
3768 ------------------------
3770 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3772 return Entity_Id (Get_Name_Table_Info (Id));
3773 end Get_Name_Entity_Id;
3779 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3781 return Get_Pragma_Id (Pragma_Name (N));
3784 ---------------------------
3785 -- Get_Referenced_Object --
3786 ---------------------------
3788 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3793 while Is_Entity_Name (R)
3794 and then Present (Renamed_Object (Entity (R)))
3796 R := Renamed_Object (Entity (R));
3800 end Get_Referenced_Object;
3802 ------------------------
3803 -- Get_Renamed_Entity --
3804 ------------------------
3806 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3811 while Present (Renamed_Entity (R)) loop
3812 R := Renamed_Entity (R);
3816 end Get_Renamed_Entity;
3818 -------------------------
3819 -- Get_Subprogram_Body --
3820 -------------------------
3822 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3826 Decl := Unit_Declaration_Node (E);
3828 if Nkind (Decl) = N_Subprogram_Body then
3831 -- The below comment is bad, because it is possible for
3832 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3834 else -- Nkind (Decl) = N_Subprogram_Declaration
3836 if Present (Corresponding_Body (Decl)) then
3837 return Unit_Declaration_Node (Corresponding_Body (Decl));
3839 -- Imported subprogram case
3845 end Get_Subprogram_Body;
3847 ---------------------------
3848 -- Get_Subprogram_Entity --
3849 ---------------------------
3851 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3856 if Nkind (Nod) = N_Accept_Statement then
3857 Nam := Entry_Direct_Name (Nod);
3859 -- For an entry call, the prefix of the call is a selected component.
3860 -- Need additional code for internal calls ???
3862 elsif Nkind (Nod) = N_Entry_Call_Statement then
3863 if Nkind (Name (Nod)) = N_Selected_Component then
3864 Nam := Entity (Selector_Name (Name (Nod)));
3873 if Nkind (Nam) = N_Explicit_Dereference then
3874 Proc := Etype (Prefix (Nam));
3875 elsif Is_Entity_Name (Nam) then
3876 Proc := Entity (Nam);
3881 if Is_Object (Proc) then
3882 Proc := Etype (Proc);
3885 if Ekind (Proc) = E_Access_Subprogram_Type then
3886 Proc := Directly_Designated_Type (Proc);
3889 if not Is_Subprogram (Proc)
3890 and then Ekind (Proc) /= E_Subprogram_Type
3896 end Get_Subprogram_Entity;
3898 -----------------------------
3899 -- Get_Task_Body_Procedure --
3900 -----------------------------
3902 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3904 -- Note: A task type may be the completion of a private type with
3905 -- discriminants. when performing elaboration checks on a task
3906 -- declaration, the current view of the type may be the private one,
3907 -- and the procedure that holds the body of the task is held in its
3910 -- This is an odd function, why not have Task_Body_Procedure do
3911 -- the following digging???
3913 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3914 end Get_Task_Body_Procedure;
3916 -----------------------------
3917 -- Has_Abstract_Interfaces --
3918 -----------------------------
3920 function Has_Abstract_Interfaces
3922 Use_Full_View : Boolean := True) return Boolean
3927 -- Handle concurrent types
3929 if Is_Concurrent_Type (T) then
3930 Typ := Corresponding_Record_Type (T);
3935 if not Present (Typ)
3936 or else not Is_Tagged_Type (Typ)
3941 pragma Assert (Is_Record_Type (Typ));
3943 -- Handle private types
3946 and then Present (Full_View (Typ))
3948 Typ := Full_View (Typ);
3951 -- Handle concurrent record types
3953 if Is_Concurrent_Record_Type (Typ)
3954 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
3960 if Is_Interface (Typ)
3962 (Is_Record_Type (Typ)
3963 and then Present (Abstract_Interfaces (Typ))
3964 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
3969 exit when Etype (Typ) = Typ
3971 -- Handle private types
3973 or else (Present (Full_View (Etype (Typ)))
3974 and then Full_View (Etype (Typ)) = Typ)
3976 -- Protect the frontend against wrong source with cyclic
3979 or else Etype (Typ) = T;
3981 -- Climb to the ancestor type handling private types
3983 if Present (Full_View (Etype (Typ))) then
3984 Typ := Full_View (Etype (Typ));
3991 end Has_Abstract_Interfaces;
3993 -----------------------
3994 -- Has_Access_Values --
3995 -----------------------
3997 function Has_Access_Values (T : Entity_Id) return Boolean is
3998 Typ : constant Entity_Id := Underlying_Type (T);
4001 -- Case of a private type which is not completed yet. This can only
4002 -- happen in the case of a generic format type appearing directly, or
4003 -- as a component of the type to which this function is being applied
4004 -- at the top level. Return False in this case, since we certainly do
4005 -- not know that the type contains access types.
4010 elsif Is_Access_Type (Typ) then
4013 elsif Is_Array_Type (Typ) then
4014 return Has_Access_Values (Component_Type (Typ));
4016 elsif Is_Record_Type (Typ) then
4021 Comp := First_Component_Or_Discriminant (Typ);
4022 while Present (Comp) loop
4023 if Has_Access_Values (Etype (Comp)) then
4027 Next_Component_Or_Discriminant (Comp);
4036 end Has_Access_Values;
4038 ------------------------------
4039 -- Has_Compatible_Alignment --
4040 ------------------------------
4042 function Has_Compatible_Alignment
4044 Expr : Node_Id) return Alignment_Result
4046 function Has_Compatible_Alignment_Internal
4049 Default : Alignment_Result) return Alignment_Result;
4050 -- This is the internal recursive function that actually does the work.
4051 -- There is one additional parameter, which says what the result should
4052 -- be if no alignment information is found, and there is no definite
4053 -- indication of compatible alignments. At the outer level, this is set
4054 -- to Unknown, but for internal recursive calls in the case where types
4055 -- are known to be correct, it is set to Known_Compatible.
4057 ---------------------------------------
4058 -- Has_Compatible_Alignment_Internal --
4059 ---------------------------------------
4061 function Has_Compatible_Alignment_Internal
4064 Default : Alignment_Result) return Alignment_Result
4066 Result : Alignment_Result := Known_Compatible;
4067 -- Set to result if Problem_Prefix or Problem_Offset returns True.
4068 -- Note that once a value of Known_Incompatible is set, it is sticky
4069 -- and does not get changed to Unknown (the value in Result only gets
4070 -- worse as we go along, never better).
4072 procedure Check_Offset (Offs : Uint);
4073 -- Called when Expr is a selected or indexed component with Offs set
4074 -- to resp Component_First_Bit or Component_Size. Checks that if the
4075 -- offset is specified it is compatible with the object alignment
4076 -- requirements. The value in Result is modified accordingly.
4078 procedure Check_Prefix;
4079 -- Checks the prefix recursively in the case where the expression
4080 -- is an indexed or selected component.
4082 procedure Set_Result (R : Alignment_Result);
4083 -- If R represents a worse outcome (unknown instead of known
4084 -- compatible, or known incompatible), then set Result to R.
4090 procedure Check_Offset (Offs : Uint) is
4092 -- Unspecified or zero offset is always OK
4094 if Offs = No_Uint or else Offs = Uint_0 then
4097 -- If we do not know required alignment, any non-zero offset is
4098 -- a potential problem (but certainly may be OK, so result is
4101 elsif Unknown_Alignment (Obj) then
4102 Set_Result (Unknown);
4104 -- If we know the required alignment, see if offset is compatible
4107 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
4108 Set_Result (Known_Incompatible);
4117 procedure Check_Prefix is
4119 -- The subtlety here is that in doing a recursive call to check
4120 -- the prefix, we have to decide what to do in the case where we
4121 -- don't find any specific indication of an alignment problem.
4123 -- At the outer level, we normally set Unknown as the result in
4124 -- this case, since we can only set Known_Compatible if we really
4125 -- know that the alignment value is OK, but for the recursive
4126 -- call, in the case where the types match, and we have not
4127 -- specified a peculiar alignment for the object, we are only
4128 -- concerned about suspicious rep clauses, the default case does
4129 -- not affect us, since the compiler will, in the absence of such
4130 -- rep clauses, ensure that the alignment is correct.
4132 if Default = Known_Compatible
4134 (Etype (Obj) = Etype (Expr)
4135 and then (Unknown_Alignment (Obj)
4137 Alignment (Obj) = Alignment (Etype (Obj))))
4140 (Has_Compatible_Alignment_Internal
4141 (Obj, Prefix (Expr), Known_Compatible));
4143 -- In all other cases, we need a full check on the prefix
4147 (Has_Compatible_Alignment_Internal
4148 (Obj, Prefix (Expr), Unknown));
4156 procedure Set_Result (R : Alignment_Result) is
4163 -- Start of processing for Has_Compatible_Alignment_Internal
4166 -- If Expr is a selected component, we must make sure there is no
4167 -- potentially troublesome component clause, and that the record is
4170 if Nkind (Expr) = N_Selected_Component then
4172 -- Packed record always generate unknown alignment
4174 if Is_Packed (Etype (Prefix (Expr))) then
4175 Set_Result (Unknown);
4178 -- Check possible bad component offset and check prefix
4181 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4184 -- If Expr is an indexed component, we must make sure there is no
4185 -- potentially troublesome Component_Size clause and that the array
4186 -- is not bit-packed.
4188 elsif Nkind (Expr) = N_Indexed_Component then
4190 -- Bit packed array always generates unknown alignment
4192 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4193 Set_Result (Unknown);
4196 -- Check possible bad component size and check prefix
4198 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4202 -- Case where we know the alignment of the object
4204 if Known_Alignment (Obj) then
4206 ObjA : constant Uint := Alignment (Obj);
4207 ExpA : Uint := No_Uint;
4208 SizA : Uint := No_Uint;
4211 -- If alignment of Obj is 1, then we are always OK
4214 Set_Result (Known_Compatible);
4216 -- Alignment of Obj is greater than 1, so we need to check
4219 -- See if Expr is an object with known alignment
4221 if Is_Entity_Name (Expr)
4222 and then Known_Alignment (Entity (Expr))
4224 ExpA := Alignment (Entity (Expr));
4226 -- Otherwise, we can use the alignment of the type of
4227 -- Expr given that we already checked for
4228 -- discombobulating rep clauses for the cases of indexed
4229 -- and selected components above.
4231 elsif Known_Alignment (Etype (Expr)) then
4232 ExpA := Alignment (Etype (Expr));
4235 -- If we got an alignment, see if it is acceptable
4237 if ExpA /= No_Uint then
4239 Set_Result (Known_Incompatible);
4242 -- Case of Expr alignment unknown
4245 Set_Result (Default);
4248 -- See if size is given. If so, check that it is not too
4249 -- small for the required alignment.
4250 -- See if Expr is an object with known alignment
4252 if Is_Entity_Name (Expr)
4253 and then Known_Static_Esize (Entity (Expr))
4255 SizA := Esize (Entity (Expr));
4257 -- Otherwise, we check the object size of the Expr type
4259 elsif Known_Static_Esize (Etype (Expr)) then
4260 SizA := Esize (Etype (Expr));
4263 -- If we got a size, see if it is a multiple of the Obj
4264 -- alignment, if not, then the alignment cannot be
4265 -- acceptable, since the size is always a multiple of the
4268 if SizA /= No_Uint then
4269 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4270 Set_Result (Known_Incompatible);
4276 -- If we can't find the result by direct comparison of alignment
4277 -- values, then there is still one case that we can determine known
4278 -- result, and that is when we can determine that the types are the
4279 -- same, and no alignments are specified. Then we known that the
4280 -- alignments are compatible, even if we don't know the alignment
4281 -- value in the front end.
4283 elsif Etype (Obj) = Etype (Expr) then
4285 -- Types are the same, but we have to check for possible size
4286 -- and alignments on the Expr object that may make the alignment
4287 -- different, even though the types are the same.
4289 if Is_Entity_Name (Expr) then
4291 -- First check alignment of the Expr object. Any alignment less
4292 -- than Maximum_Alignment is worrisome since this is the case
4293 -- where we do not know the alignment of Obj.
4295 if Known_Alignment (Entity (Expr))
4297 UI_To_Int (Alignment (Entity (Expr)))
4298 < Ttypes.Maximum_Alignment
4300 Set_Result (Unknown);
4302 -- Now check size of Expr object. Any size that is not an
4303 -- even multiple of Maxiumum_Alignment is also worrisome
4304 -- since it may cause the alignment of the object to be less
4305 -- than the alignment of the type.
4307 elsif Known_Static_Esize (Entity (Expr))
4309 (UI_To_Int (Esize (Entity (Expr))) mod
4310 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4313 Set_Result (Unknown);
4315 -- Otherwise same type is decisive
4318 Set_Result (Known_Compatible);
4322 -- Another case to deal with is when there is an explicit size or
4323 -- alignment clause when the types are not the same. If so, then the
4324 -- result is Unknown. We don't need to do this test if the Default is
4325 -- Unknown, since that result will be set in any case.
4327 elsif Default /= Unknown
4328 and then (Has_Size_Clause (Etype (Expr))
4330 Has_Alignment_Clause (Etype (Expr)))
4332 Set_Result (Unknown);
4334 -- If no indication found, set default
4337 Set_Result (Default);
4340 -- Return worst result found
4343 end Has_Compatible_Alignment_Internal;
4345 -- Start of processing for Has_Compatible_Alignment
4348 -- If Obj has no specified alignment, then set alignment from the type
4349 -- alignment. Perhaps we should always do this, but for sure we should
4350 -- do it when there is an address clause since we can do more if the
4351 -- alignment is known.
4353 if Unknown_Alignment (Obj) then
4354 Set_Alignment (Obj, Alignment (Etype (Obj)));
4357 -- Now do the internal call that does all the work
4359 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4360 end Has_Compatible_Alignment;
4362 ----------------------
4363 -- Has_Declarations --
4364 ----------------------
4366 function Has_Declarations (N : Node_Id) return Boolean is
4367 K : constant Node_Kind := Nkind (N);
4369 return K = N_Accept_Statement
4370 or else K = N_Block_Statement
4371 or else K = N_Compilation_Unit_Aux
4372 or else K = N_Entry_Body
4373 or else K = N_Package_Body
4374 or else K = N_Protected_Body
4375 or else K = N_Subprogram_Body
4376 or else K = N_Task_Body
4377 or else K = N_Package_Specification;
4378 end Has_Declarations;
4380 -------------------------------------------
4381 -- Has_Discriminant_Dependent_Constraint --
4382 -------------------------------------------
4384 function Has_Discriminant_Dependent_Constraint
4385 (Comp : Entity_Id) return Boolean
4387 Comp_Decl : constant Node_Id := Parent (Comp);
4388 Subt_Indic : constant Node_Id :=
4389 Subtype_Indication (Component_Definition (Comp_Decl));
4394 if Nkind (Subt_Indic) = N_Subtype_Indication then
4395 Constr := Constraint (Subt_Indic);
4397 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4398 Assn := First (Constraints (Constr));
4399 while Present (Assn) loop
4400 case Nkind (Assn) is
4401 when N_Subtype_Indication |
4405 if Depends_On_Discriminant (Assn) then
4409 when N_Discriminant_Association =>
4410 if Depends_On_Discriminant (Expression (Assn)) then
4425 end Has_Discriminant_Dependent_Constraint;
4427 --------------------
4428 -- Has_Infinities --
4429 --------------------
4431 function Has_Infinities (E : Entity_Id) return Boolean is
4434 Is_Floating_Point_Type (E)
4435 and then Nkind (Scalar_Range (E)) = N_Range
4436 and then Includes_Infinities (Scalar_Range (E));
4439 ------------------------
4440 -- Has_Null_Exclusion --
4441 ------------------------
4443 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4446 when N_Access_Definition |
4447 N_Access_Function_Definition |
4448 N_Access_Procedure_Definition |
4449 N_Access_To_Object_Definition |
4451 N_Derived_Type_Definition |
4452 N_Function_Specification |
4453 N_Subtype_Declaration =>
4454 return Null_Exclusion_Present (N);
4456 when N_Component_Definition |
4457 N_Formal_Object_Declaration |
4458 N_Object_Renaming_Declaration =>
4459 if Present (Subtype_Mark (N)) then
4460 return Null_Exclusion_Present (N);
4461 else pragma Assert (Present (Access_Definition (N)));
4462 return Null_Exclusion_Present (Access_Definition (N));
4465 when N_Discriminant_Specification =>
4466 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4467 return Null_Exclusion_Present (Discriminant_Type (N));
4469 return Null_Exclusion_Present (N);
4472 when N_Object_Declaration =>
4473 if Nkind (Object_Definition (N)) = N_Access_Definition then
4474 return Null_Exclusion_Present (Object_Definition (N));
4476 return Null_Exclusion_Present (N);
4479 when N_Parameter_Specification =>
4480 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4481 return Null_Exclusion_Present (Parameter_Type (N));
4483 return Null_Exclusion_Present (N);
4490 end Has_Null_Exclusion;
4492 ------------------------
4493 -- Has_Null_Extension --
4494 ------------------------
4496 function Has_Null_Extension (T : Entity_Id) return Boolean is
4497 B : constant Entity_Id := Base_Type (T);
4502 if Nkind (Parent (B)) = N_Full_Type_Declaration
4503 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4505 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4507 if Present (Ext) then
4508 if Null_Present (Ext) then
4511 Comps := Component_List (Ext);
4513 -- The null component list is rewritten during analysis to
4514 -- include the parent component. Any other component indicates
4515 -- that the extension was not originally null.
4517 return Null_Present (Comps)
4518 or else No (Next (First (Component_Items (Comps))));
4527 end Has_Null_Extension;
4529 --------------------------------------
4530 -- Has_Preelaborable_Initialization --
4531 --------------------------------------
4533 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4536 procedure Check_Components (E : Entity_Id);
4537 -- Check component/discriminant chain, sets Has_PE False if a component
4538 -- or discriminant does not meet the preelaborable initialization rules.
4540 ----------------------
4541 -- Check_Components --
4542 ----------------------
4544 procedure Check_Components (E : Entity_Id) is
4548 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4549 -- Returns True if and only if the expression denoted by N does not
4550 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4552 ---------------------------------
4553 -- Is_Preelaborable_Expression --
4554 ---------------------------------
4556 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4560 Comp_Type : Entity_Id;
4561 Is_Array_Aggr : Boolean;
4564 if Is_Static_Expression (N) then
4567 elsif Nkind (N) = N_Null then
4570 -- Attributes are allowed in general, even if their prefix is a
4571 -- formal type. (It seems that certain attributes known not to be
4572 -- static might not be allowed, but there are no rules to prevent
4575 elsif Nkind (N) = N_Attribute_Reference then
4578 -- The name of a discriminant evaluated within its parent type is
4579 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4580 -- names that denote discriminals as well as discriminants to
4581 -- catch references occurring within init procs.
4583 elsif Is_Entity_Name (N)
4585 (Ekind (Entity (N)) = E_Discriminant
4587 ((Ekind (Entity (N)) = E_Constant
4588 or else Ekind (Entity (N)) = E_In_Parameter)
4589 and then Present (Discriminal_Link (Entity (N)))))
4593 elsif Nkind (N) = N_Qualified_Expression then
4594 return Is_Preelaborable_Expression (Expression (N));
4596 -- For aggregates we have to check that each of the associations
4597 -- is preelaborable.
4599 elsif Nkind (N) = N_Aggregate
4600 or else Nkind (N) = N_Extension_Aggregate
4602 Is_Array_Aggr := Is_Array_Type (Etype (N));
4604 if Is_Array_Aggr then
4605 Comp_Type := Component_Type (Etype (N));
4608 -- Check the ancestor part of extension aggregates, which must
4609 -- be either the name of a type that has preelaborable init or
4610 -- an expression that is preelaborable.
4612 if Nkind (N) = N_Extension_Aggregate then
4614 Anc_Part : constant Node_Id := Ancestor_Part (N);
4617 if Is_Entity_Name (Anc_Part)
4618 and then Is_Type (Entity (Anc_Part))
4620 if not Has_Preelaborable_Initialization
4626 elsif not Is_Preelaborable_Expression (Anc_Part) then
4632 -- Check positional associations
4634 Exp := First (Expressions (N));
4635 while Present (Exp) loop
4636 if not Is_Preelaborable_Expression (Exp) then
4643 -- Check named associations
4645 Assn := First (Component_Associations (N));
4646 while Present (Assn) loop
4647 Choice := First (Choices (Assn));
4648 while Present (Choice) loop
4649 if Is_Array_Aggr then
4650 if Nkind (Choice) = N_Others_Choice then
4653 elsif Nkind (Choice) = N_Range then
4654 if not Is_Static_Range (Choice) then
4658 elsif not Is_Static_Expression (Choice) then
4663 Comp_Type := Etype (Choice);
4669 -- If the association has a <> at this point, then we have
4670 -- to check whether the component's type has preelaborable
4671 -- initialization. Note that this only occurs when the
4672 -- association's corresponding component does not have a
4673 -- default expression, the latter case having already been
4674 -- expanded as an expression for the association.
4676 if Box_Present (Assn) then
4677 if not Has_Preelaborable_Initialization (Comp_Type) then
4681 -- In the expression case we check whether the expression
4682 -- is preelaborable.
4685 not Is_Preelaborable_Expression (Expression (Assn))
4693 -- If we get here then aggregate as a whole is preelaborable
4697 -- All other cases are not preelaborable
4702 end Is_Preelaborable_Expression;
4704 -- Start of processing for Check_Components
4707 -- Loop through entities of record or protected type
4710 while Present (Ent) loop
4712 -- We are interested only in components and discriminants
4714 if Ekind (Ent) = E_Component
4716 Ekind (Ent) = E_Discriminant
4718 -- Get default expression if any. If there is no declaration
4719 -- node, it means we have an internal entity. The parent and
4720 -- tag fields are examples of such entitires. For these cases,
4721 -- we just test the type of the entity.
4723 if Present (Declaration_Node (Ent)) then
4724 Exp := Expression (Declaration_Node (Ent));
4729 -- A component has PI if it has no default expression and the
4730 -- component type has PI.
4733 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4738 -- Require the default expression to be preelaborable
4740 elsif not Is_Preelaborable_Expression (Exp) then
4748 end Check_Components;
4750 -- Start of processing for Has_Preelaborable_Initialization
4753 -- Immediate return if already marked as known preelaborable init. This
4754 -- covers types for which this function has already been called once
4755 -- and returned True (in which case the result is cached), and also
4756 -- types to which a pragma Preelaborable_Initialization applies.
4758 if Known_To_Have_Preelab_Init (E) then
4762 -- If the type is a subtype representing a generic actual type, then
4763 -- test whether its base type has preelaborable initialization since
4764 -- the subtype representing the actual does not inherit this attribute
4765 -- from the actual or formal. (but maybe it should???)
4767 if Is_Generic_Actual_Type (E) then
4768 return Has_Preelaborable_Initialization (Base_Type (E));
4771 -- Other private types never have preelaborable initialization
4773 if Is_Private_Type (E) then
4777 -- Here for all non-private view
4779 -- All elementary types have preelaborable initialization
4781 if Is_Elementary_Type (E) then
4784 -- Array types have PI if the component type has PI
4786 elsif Is_Array_Type (E) then
4787 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4789 -- A derived type has preelaborable initialization if its parent type
4790 -- has preelaborable initialization and (in the case of a derived record
4791 -- extension) if the non-inherited components all have preelaborable
4792 -- initialization. However, a user-defined controlled type with an
4793 -- overriding Initialize procedure does not have preelaborable
4796 elsif Is_Derived_Type (E) then
4798 -- First check whether ancestor type has preelaborable initialization
4800 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4802 -- If OK, check extension components (if any)
4804 if Has_PE and then Is_Record_Type (E) then
4805 Check_Components (First_Entity (E));
4808 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4809 -- with a user defined Initialize procedure does not have PI.
4812 and then Is_Controlled (E)
4813 and then Present (Primitive_Operations (E))
4819 P := First_Elmt (Primitive_Operations (E));
4820 while Present (P) loop
4821 if Chars (Node (P)) = Name_Initialize
4822 and then Comes_From_Source (Node (P))
4833 -- Record type has PI if it is non private and all components have PI
4835 elsif Is_Record_Type (E) then
4837 Check_Components (First_Entity (E));
4839 -- Protected types must not have entries, and components must meet
4840 -- same set of rules as for record components.
4842 elsif Is_Protected_Type (E) then
4843 if Has_Entries (E) then
4847 Check_Components (First_Entity (E));
4848 Check_Components (First_Private_Entity (E));
4851 -- Type System.Address always has preelaborable initialization
4853 elsif Is_RTE (E, RE_Address) then
4856 -- In all other cases, type does not have preelaborable initialization
4862 -- If type has preelaborable initialization, cache result
4865 Set_Known_To_Have_Preelab_Init (E);
4869 end Has_Preelaborable_Initialization;
4871 ---------------------------
4872 -- Has_Private_Component --
4873 ---------------------------
4875 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4876 Btype : Entity_Id := Base_Type (Type_Id);
4877 Component : Entity_Id;
4880 if Error_Posted (Type_Id)
4881 or else Error_Posted (Btype)
4886 if Is_Class_Wide_Type (Btype) then
4887 Btype := Root_Type (Btype);
4890 if Is_Private_Type (Btype) then
4892 UT : constant Entity_Id := Underlying_Type (Btype);
4895 if No (Full_View (Btype)) then
4896 return not Is_Generic_Type (Btype)
4897 and then not Is_Generic_Type (Root_Type (Btype));
4899 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4902 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4906 elsif Is_Array_Type (Btype) then
4907 return Has_Private_Component (Component_Type (Btype));
4909 elsif Is_Record_Type (Btype) then
4910 Component := First_Component (Btype);
4911 while Present (Component) loop
4912 if Has_Private_Component (Etype (Component)) then
4916 Next_Component (Component);
4921 elsif Is_Protected_Type (Btype)
4922 and then Present (Corresponding_Record_Type (Btype))
4924 return Has_Private_Component (Corresponding_Record_Type (Btype));
4929 end Has_Private_Component;
4935 function Has_Stream (T : Entity_Id) return Boolean is
4942 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4945 elsif Is_Array_Type (T) then
4946 return Has_Stream (Component_Type (T));
4948 elsif Is_Record_Type (T) then
4949 E := First_Component (T);
4950 while Present (E) loop
4951 if Has_Stream (Etype (E)) then
4960 elsif Is_Private_Type (T) then
4961 return Has_Stream (Underlying_Type (T));
4968 --------------------------
4969 -- Has_Tagged_Component --
4970 --------------------------
4972 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4976 if Is_Private_Type (Typ)
4977 and then Present (Underlying_Type (Typ))
4979 return Has_Tagged_Component (Underlying_Type (Typ));
4981 elsif Is_Array_Type (Typ) then
4982 return Has_Tagged_Component (Component_Type (Typ));
4984 elsif Is_Tagged_Type (Typ) then
4987 elsif Is_Record_Type (Typ) then
4988 Comp := First_Component (Typ);
4989 while Present (Comp) loop
4990 if Has_Tagged_Component (Etype (Comp)) then
4994 Comp := Next_Component (Typ);
5002 end Has_Tagged_Component;
5008 function In_Instance return Boolean is
5009 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5015 and then S /= Standard_Standard
5017 if (Ekind (S) = E_Function
5018 or else Ekind (S) = E_Package
5019 or else Ekind (S) = E_Procedure)
5020 and then Is_Generic_Instance (S)
5022 -- A child instance is always compiled in the context of a parent
5023 -- instance. Nevertheless, the actuals are not analyzed in an
5024 -- instance context. We detect this case by examining the current
5025 -- compilation unit, which must be a child instance, and checking
5026 -- that it is not currently on the scope stack.
5028 if Is_Child_Unit (Curr_Unit)
5030 Nkind (Unit (Cunit (Current_Sem_Unit)))
5031 = N_Package_Instantiation
5032 and then not In_Open_Scopes (Curr_Unit)
5046 ----------------------
5047 -- In_Instance_Body --
5048 ----------------------
5050 function In_Instance_Body return Boolean is
5056 and then S /= Standard_Standard
5058 if (Ekind (S) = E_Function
5059 or else Ekind (S) = E_Procedure)
5060 and then Is_Generic_Instance (S)
5064 elsif Ekind (S) = E_Package
5065 and then In_Package_Body (S)
5066 and then Is_Generic_Instance (S)
5075 end In_Instance_Body;
5077 -----------------------------
5078 -- In_Instance_Not_Visible --
5079 -----------------------------
5081 function In_Instance_Not_Visible return Boolean is
5087 and then S /= Standard_Standard
5089 if (Ekind (S) = E_Function
5090 or else Ekind (S) = E_Procedure)
5091 and then Is_Generic_Instance (S)
5095 elsif Ekind (S) = E_Package
5096 and then (In_Package_Body (S) or else In_Private_Part (S))
5097 and then Is_Generic_Instance (S)
5106 end In_Instance_Not_Visible;
5108 ------------------------------
5109 -- In_Instance_Visible_Part --
5110 ------------------------------
5112 function In_Instance_Visible_Part return Boolean is
5118 and then S /= Standard_Standard
5120 if Ekind (S) = E_Package
5121 and then Is_Generic_Instance (S)
5122 and then not In_Package_Body (S)
5123 and then not In_Private_Part (S)
5132 end In_Instance_Visible_Part;
5134 ----------------------
5135 -- In_Packiage_Body --
5136 ----------------------
5138 function In_Package_Body return Boolean is
5144 and then S /= Standard_Standard
5146 if Ekind (S) = E_Package
5147 and then In_Package_Body (S)
5156 end In_Package_Body;
5158 --------------------------------------
5159 -- In_Subprogram_Or_Concurrent_Unit --
5160 --------------------------------------
5162 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5167 -- Use scope chain to check successively outer scopes
5173 if K in Subprogram_Kind
5174 or else K in Concurrent_Kind
5175 or else K in Generic_Subprogram_Kind
5179 elsif E = Standard_Standard then
5185 end In_Subprogram_Or_Concurrent_Unit;
5187 ---------------------
5188 -- In_Visible_Part --
5189 ---------------------
5191 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5194 Is_Package_Or_Generic_Package (Scope_Id)
5195 and then In_Open_Scopes (Scope_Id)
5196 and then not In_Package_Body (Scope_Id)
5197 and then not In_Private_Part (Scope_Id);
5198 end In_Visible_Part;
5200 ---------------------------------
5201 -- Insert_Explicit_Dereference --
5202 ---------------------------------
5204 procedure Insert_Explicit_Dereference (N : Node_Id) is
5205 New_Prefix : constant Node_Id := Relocate_Node (N);
5206 Ent : Entity_Id := Empty;
5213 Save_Interps (N, New_Prefix);
5215 Make_Explicit_Dereference (Sloc (N),
5216 Prefix => New_Prefix));
5218 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5220 if Is_Overloaded (New_Prefix) then
5222 -- The deference is also overloaded, and its interpretations are the
5223 -- designated types of the interpretations of the original node.
5225 Set_Etype (N, Any_Type);
5227 Get_First_Interp (New_Prefix, I, It);
5228 while Present (It.Nam) loop
5231 if Is_Access_Type (T) then
5232 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5235 Get_Next_Interp (I, It);
5241 -- Prefix is unambiguous: mark the original prefix (which might
5242 -- Come_From_Source) as a reference, since the new (relocated) one
5243 -- won't be taken into account.
5245 if Is_Entity_Name (New_Prefix) then
5246 Ent := Entity (New_Prefix);
5248 -- For a retrieval of a subcomponent of some composite object,
5249 -- retrieve the ultimate entity if there is one.
5251 elsif Nkind (New_Prefix) = N_Selected_Component
5252 or else Nkind (New_Prefix) = N_Indexed_Component
5254 Pref := Prefix (New_Prefix);
5255 while Present (Pref)
5257 (Nkind (Pref) = N_Selected_Component
5258 or else Nkind (Pref) = N_Indexed_Component)
5260 Pref := Prefix (Pref);
5263 if Present (Pref) and then Is_Entity_Name (Pref) then
5264 Ent := Entity (Pref);
5268 if Present (Ent) then
5269 Generate_Reference (Ent, New_Prefix);
5272 end Insert_Explicit_Dereference;
5278 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5279 pragma Assert (Is_Type (E));
5281 return AAMP_On_Target
5282 and then Is_Floating_Point_Type (E)
5283 and then E = Base_Type (E);
5286 -------------------------
5287 -- Is_Actual_Parameter --
5288 -------------------------
5290 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5291 PK : constant Node_Kind := Nkind (Parent (N));
5295 when N_Parameter_Association =>
5296 return N = Explicit_Actual_Parameter (Parent (N));
5298 when N_Function_Call | N_Procedure_Call_Statement =>
5299 return Is_List_Member (N)
5301 List_Containing (N) = Parameter_Associations (Parent (N));
5306 end Is_Actual_Parameter;
5308 ---------------------
5309 -- Is_Aliased_View --
5310 ---------------------
5312 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5316 if Is_Entity_Name (Obj) then
5324 or else (Present (Renamed_Object (E))
5325 and then Is_Aliased_View (Renamed_Object (E)))))
5327 or else ((Is_Formal (E)
5328 or else Ekind (E) = E_Generic_In_Out_Parameter
5329 or else Ekind (E) = E_Generic_In_Parameter)
5330 and then Is_Tagged_Type (Etype (E)))
5332 or else (Is_Concurrent_Type (E)
5333 and then In_Open_Scopes (E))
5335 -- Current instance of type, either directly or as rewritten
5336 -- reference to the current object.
5338 or else (Is_Entity_Name (Original_Node (Obj))
5339 and then Present (Entity (Original_Node (Obj)))
5340 and then Is_Type (Entity (Original_Node (Obj))))
5342 or else (Is_Type (E) and then E = Current_Scope)
5344 or else (Is_Incomplete_Or_Private_Type (E)
5345 and then Full_View (E) = Current_Scope);
5347 elsif Nkind (Obj) = N_Selected_Component then
5348 return Is_Aliased (Entity (Selector_Name (Obj)));
5350 elsif Nkind (Obj) = N_Indexed_Component then
5351 return Has_Aliased_Components (Etype (Prefix (Obj)))
5353 (Is_Access_Type (Etype (Prefix (Obj)))
5355 Has_Aliased_Components
5356 (Designated_Type (Etype (Prefix (Obj)))));
5358 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5359 or else Nkind (Obj) = N_Type_Conversion
5361 return Is_Tagged_Type (Etype (Obj))
5362 and then Is_Aliased_View (Expression (Obj));
5364 elsif Nkind (Obj) = N_Explicit_Dereference then
5365 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5370 end Is_Aliased_View;
5372 -------------------------
5373 -- Is_Ancestor_Package --
5374 -------------------------
5376 function Is_Ancestor_Package
5378 E2 : Entity_Id) return Boolean
5385 and then Par /= Standard_Standard
5395 end Is_Ancestor_Package;
5397 ----------------------
5398 -- Is_Atomic_Object --
5399 ----------------------
5401 function Is_Atomic_Object (N : Node_Id) return Boolean is
5403 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5404 -- Determines if given object has atomic components
5406 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5407 -- If prefix is an implicit dereference, examine designated type
5409 ----------------------
5410 -- Is_Atomic_Prefix --
5411 ----------------------
5413 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5415 if Is_Access_Type (Etype (N)) then
5417 Has_Atomic_Components (Designated_Type (Etype (N)));
5419 return Object_Has_Atomic_Components (N);
5421 end Is_Atomic_Prefix;
5423 ----------------------------------
5424 -- Object_Has_Atomic_Components --
5425 ----------------------------------
5427 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5429 if Has_Atomic_Components (Etype (N))
5430 or else Is_Atomic (Etype (N))
5434 elsif Is_Entity_Name (N)
5435 and then (Has_Atomic_Components (Entity (N))
5436 or else Is_Atomic (Entity (N)))
5440 elsif Nkind (N) = N_Indexed_Component
5441 or else Nkind (N) = N_Selected_Component
5443 return Is_Atomic_Prefix (Prefix (N));
5448 end Object_Has_Atomic_Components;
5450 -- Start of processing for Is_Atomic_Object
5453 if Is_Atomic (Etype (N))
5454 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5458 elsif Nkind (N) = N_Indexed_Component
5459 or else Nkind (N) = N_Selected_Component
5461 return Is_Atomic_Prefix (Prefix (N));
5466 end Is_Atomic_Object;
5468 -------------------------
5469 -- Is_Coextension_Root --
5470 -------------------------
5472 function Is_Coextension_Root (N : Node_Id) return Boolean is
5475 Nkind (N) = N_Allocator
5476 and then Present (Coextensions (N))
5478 -- Anonymous access discriminants carry a list of all nested
5479 -- controlled coextensions.
5481 and then not Is_Dynamic_Coextension (N)
5482 and then not Is_Static_Coextension (N);
5483 end Is_Coextension_Root;
5485 -----------------------------
5486 -- Is_Concurrent_Interface --
5487 -----------------------------
5489 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5494 (Is_Protected_Interface (T)
5495 or else Is_Synchronized_Interface (T)
5496 or else Is_Task_Interface (T));
5497 end Is_Concurrent_Interface;
5499 --------------------------------------
5500 -- Is_Controlling_Limited_Procedure --
5501 --------------------------------------
5503 function Is_Controlling_Limited_Procedure
5504 (Proc_Nam : Entity_Id) return Boolean
5506 Param_Typ : Entity_Id := Empty;
5509 if Ekind (Proc_Nam) = E_Procedure
5510 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5512 Param_Typ := Etype (Parameter_Type (First (
5513 Parameter_Specifications (Parent (Proc_Nam)))));
5515 -- In this case where an Itype was created, the procedure call has been
5518 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5519 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5521 Present (Parameter_Associations
5522 (Associated_Node_For_Itype (Proc_Nam)))
5525 Etype (First (Parameter_Associations
5526 (Associated_Node_For_Itype (Proc_Nam))));
5529 if Present (Param_Typ) then
5531 Is_Interface (Param_Typ)
5532 and then Is_Limited_Record (Param_Typ);
5536 end Is_Controlling_Limited_Procedure;
5538 ----------------------------------------------
5539 -- Is_Dependent_Component_Of_Mutable_Object --
5540 ----------------------------------------------
5542 function Is_Dependent_Component_Of_Mutable_Object
5543 (Object : Node_Id) return Boolean
5546 Prefix_Type : Entity_Id;
5547 P_Aliased : Boolean := False;
5550 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5551 -- Returns True if and only if Comp is declared within a variant part
5553 --------------------------------
5554 -- Is_Declared_Within_Variant --
5555 --------------------------------
5557 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5558 Comp_Decl : constant Node_Id := Parent (Comp);
5559 Comp_List : constant Node_Id := Parent (Comp_Decl);
5561 return Nkind (Parent (Comp_List)) = N_Variant;
5562 end Is_Declared_Within_Variant;
5564 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5567 if Is_Variable (Object) then
5569 if Nkind (Object) = N_Selected_Component then
5570 P := Prefix (Object);
5571 Prefix_Type := Etype (P);
5573 if Is_Entity_Name (P) then
5575 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5576 Prefix_Type := Base_Type (Prefix_Type);
5579 if Is_Aliased (Entity (P)) then
5583 -- A discriminant check on a selected component may be
5584 -- expanded into a dereference when removing side-effects.
5585 -- Recover the original node and its type, which may be
5588 elsif Nkind (P) = N_Explicit_Dereference
5589 and then not (Comes_From_Source (P))
5591 P := Original_Node (P);
5592 Prefix_Type := Etype (P);
5595 -- Check for prefix being an aliased component ???
5600 -- A heap object is constrained by its initial value
5602 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5603 -- the dereferenced case, since the access value might denote an
5604 -- unconstrained aliased object, whereas in Ada 95 the designated
5605 -- object is guaranteed to be constrained. A worst-case assumption
5606 -- has to apply in Ada 2005 because we can't tell at compile time
5607 -- whether the object is "constrained by its initial value"
5608 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5609 -- semantic rules -- these rules are acknowledged to need fixing).
5611 if Ada_Version < Ada_05 then
5612 if Is_Access_Type (Prefix_Type)
5613 or else Nkind (P) = N_Explicit_Dereference
5618 elsif Ada_Version >= Ada_05 then
5619 if Is_Access_Type (Prefix_Type) then
5621 -- If the access type is pool-specific, and there is no
5622 -- constrained partial view of the designated type, then the
5623 -- designated object is known to be constrained.
5625 if Ekind (Prefix_Type) = E_Access_Type
5626 and then not Has_Constrained_Partial_View
5627 (Designated_Type (Prefix_Type))
5631 -- Otherwise (general access type, or there is a constrained
5632 -- partial view of the designated type), we need to check
5633 -- based on the designated type.
5636 Prefix_Type := Designated_Type (Prefix_Type);
5642 Original_Record_Component (Entity (Selector_Name (Object)));
5644 -- As per AI-0017, the renaming is illegal in a generic body,
5645 -- even if the subtype is indefinite.
5647 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5649 if not Is_Constrained (Prefix_Type)
5650 and then (not Is_Indefinite_Subtype (Prefix_Type)
5652 (Is_Generic_Type (Prefix_Type)
5653 and then Ekind (Current_Scope) = E_Generic_Package
5654 and then In_Package_Body (Current_Scope)))
5656 and then (Is_Declared_Within_Variant (Comp)
5657 or else Has_Discriminant_Dependent_Constraint (Comp))
5658 and then (not P_Aliased or else Ada_Version >= Ada_05)
5664 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5668 elsif Nkind (Object) = N_Indexed_Component
5669 or else Nkind (Object) = N_Slice
5671 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5673 -- A type conversion that Is_Variable is a view conversion:
5674 -- go back to the denoted object.
5676 elsif Nkind (Object) = N_Type_Conversion then
5678 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5683 end Is_Dependent_Component_Of_Mutable_Object;
5685 ---------------------
5686 -- Is_Dereferenced --
5687 ---------------------
5689 function Is_Dereferenced (N : Node_Id) return Boolean is
5690 P : constant Node_Id := Parent (N);
5693 (Nkind (P) = N_Selected_Component
5695 Nkind (P) = N_Explicit_Dereference
5697 Nkind (P) = N_Indexed_Component
5699 Nkind (P) = N_Slice)
5700 and then Prefix (P) = N;
5701 end Is_Dereferenced;
5703 ----------------------
5704 -- Is_Descendent_Of --
5705 ----------------------
5707 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5712 pragma Assert (Nkind (T1) in N_Entity);
5713 pragma Assert (Nkind (T2) in N_Entity);
5715 T := Base_Type (T1);
5717 -- Immediate return if the types match
5722 -- Comment needed here ???
5724 elsif Ekind (T) = E_Class_Wide_Type then
5725 return Etype (T) = T2;
5733 -- Done if we found the type we are looking for
5738 -- Done if no more derivations to check
5745 -- Following test catches error cases resulting from prev errors
5747 elsif No (Etyp) then
5750 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5753 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5757 T := Base_Type (Etyp);
5761 raise Program_Error;
5762 end Is_Descendent_Of;
5768 function Is_False (U : Uint) return Boolean is
5773 ---------------------------
5774 -- Is_Fixed_Model_Number --
5775 ---------------------------
5777 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5778 S : constant Ureal := Small_Value (T);
5779 M : Urealp.Save_Mark;
5783 R := (U = UR_Trunc (U / S) * S);
5786 end Is_Fixed_Model_Number;
5788 -------------------------------
5789 -- Is_Fully_Initialized_Type --
5790 -------------------------------
5792 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5794 if Is_Scalar_Type (Typ) then
5797 elsif Is_Access_Type (Typ) then
5800 elsif Is_Array_Type (Typ) then
5801 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5805 -- An interesting case, if we have a constrained type one of whose
5806 -- bounds is known to be null, then there are no elements to be
5807 -- initialized, so all the elements are initialized!
5809 if Is_Constrained (Typ) then
5812 Indx_Typ : Entity_Id;
5816 Indx := First_Index (Typ);
5817 while Present (Indx) loop
5818 if Etype (Indx) = Any_Type then
5821 -- If index is a range, use directly
5823 elsif Nkind (Indx) = N_Range then
5824 Lbd := Low_Bound (Indx);
5825 Hbd := High_Bound (Indx);
5828 Indx_Typ := Etype (Indx);
5830 if Is_Private_Type (Indx_Typ) then
5831 Indx_Typ := Full_View (Indx_Typ);
5834 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5837 Lbd := Type_Low_Bound (Indx_Typ);
5838 Hbd := Type_High_Bound (Indx_Typ);
5842 if Compile_Time_Known_Value (Lbd)
5843 and then Compile_Time_Known_Value (Hbd)
5845 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5855 -- If no null indexes, then type is not fully initialized
5861 elsif Is_Record_Type (Typ) then
5862 if Has_Discriminants (Typ)
5864 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5865 and then Is_Fully_Initialized_Variant (Typ)
5870 -- Controlled records are considered to be fully initialized if
5871 -- there is a user defined Initialize routine. This may not be
5872 -- entirely correct, but as the spec notes, we are guessing here
5873 -- what is best from the point of view of issuing warnings.
5875 if Is_Controlled (Typ) then
5877 Utyp : constant Entity_Id := Underlying_Type (Typ);
5880 if Present (Utyp) then
5882 Init : constant Entity_Id :=
5884 (Underlying_Type (Typ), Name_Initialize));
5888 and then Comes_From_Source (Init)
5890 Is_Predefined_File_Name
5891 (File_Name (Get_Source_File_Index (Sloc (Init))))
5895 elsif Has_Null_Extension (Typ)
5897 Is_Fully_Initialized_Type
5898 (Etype (Base_Type (Typ)))
5907 -- Otherwise see if all record components are initialized
5913 Ent := First_Entity (Typ);
5914 while Present (Ent) loop
5915 if Chars (Ent) = Name_uController then
5918 elsif Ekind (Ent) = E_Component
5919 and then (No (Parent (Ent))
5920 or else No (Expression (Parent (Ent))))
5921 and then not Is_Fully_Initialized_Type (Etype (Ent))
5923 -- Special VM case for uTag component, which needs to be
5924 -- defined in this case, but is never initialized as VMs
5925 -- are using other dispatching mechanisms. Ignore this
5926 -- uninitialized case.
5928 and then (VM_Target = No_VM
5929 or else Chars (Ent) /= Name_uTag)
5938 -- No uninitialized components, so type is fully initialized.
5939 -- Note that this catches the case of no components as well.
5943 elsif Is_Concurrent_Type (Typ) then
5946 elsif Is_Private_Type (Typ) then
5948 U : constant Entity_Id := Underlying_Type (Typ);
5954 return Is_Fully_Initialized_Type (U);
5961 end Is_Fully_Initialized_Type;
5963 ----------------------------------
5964 -- Is_Fully_Initialized_Variant --
5965 ----------------------------------
5967 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5968 Loc : constant Source_Ptr := Sloc (Typ);
5969 Constraints : constant List_Id := New_List;
5970 Components : constant Elist_Id := New_Elmt_List;
5971 Comp_Elmt : Elmt_Id;
5973 Comp_List : Node_Id;
5975 Discr_Val : Node_Id;
5977 Report_Errors : Boolean;
5978 pragma Warnings (Off, Report_Errors);
5981 if Serious_Errors_Detected > 0 then
5985 if Is_Record_Type (Typ)
5986 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5987 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5989 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5991 Discr := First_Discriminant (Typ);
5992 while Present (Discr) loop
5993 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5994 Discr_Val := Expression (Parent (Discr));
5996 if Present (Discr_Val)
5997 and then Is_OK_Static_Expression (Discr_Val)
5999 Append_To (Constraints,
6000 Make_Component_Association (Loc,
6001 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6002 Expression => New_Copy (Discr_Val)));
6010 Next_Discriminant (Discr);
6015 Comp_List => Comp_List,
6016 Governed_By => Constraints,
6018 Report_Errors => Report_Errors);
6020 -- Check that each component present is fully initialized
6022 Comp_Elmt := First_Elmt (Components);
6023 while Present (Comp_Elmt) loop
6024 Comp_Id := Node (Comp_Elmt);
6026 if Ekind (Comp_Id) = E_Component
6027 and then (No (Parent (Comp_Id))
6028 or else No (Expression (Parent (Comp_Id))))
6029 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6034 Next_Elmt (Comp_Elmt);
6039 elsif Is_Private_Type (Typ) then
6041 U : constant Entity_Id := Underlying_Type (Typ);
6047 return Is_Fully_Initialized_Variant (U);
6053 end Is_Fully_Initialized_Variant;
6055 ----------------------------
6056 -- Is_Inherited_Operation --
6057 ----------------------------
6059 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6060 Kind : constant Node_Kind := Nkind (Parent (E));
6062 pragma Assert (Is_Overloadable (E));
6063 return Kind = N_Full_Type_Declaration
6064 or else Kind = N_Private_Extension_Declaration
6065 or else Kind = N_Subtype_Declaration
6066 or else (Ekind (E) = E_Enumeration_Literal
6067 and then Is_Derived_Type (Etype (E)));
6068 end Is_Inherited_Operation;
6070 -----------------------------
6071 -- Is_Library_Level_Entity --
6072 -----------------------------
6074 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6076 -- The following is a small optimization, and it also properly handles
6077 -- discriminals, which in task bodies might appear in expressions before
6078 -- the corresponding procedure has been created, and which therefore do
6079 -- not have an assigned scope.
6081 if Ekind (E) in Formal_Kind then
6085 -- Normal test is simply that the enclosing dynamic scope is Standard
6087 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6088 end Is_Library_Level_Entity;
6090 ---------------------------------
6091 -- Is_Local_Variable_Reference --
6092 ---------------------------------
6094 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6096 if not Is_Entity_Name (Expr) then
6101 Ent : constant Entity_Id := Entity (Expr);
6102 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6104 if Ekind (Ent) /= E_Variable
6106 Ekind (Ent) /= E_In_Out_Parameter
6110 return Present (Sub) and then Sub = Current_Subprogram;
6114 end Is_Local_Variable_Reference;
6116 -------------------------
6117 -- Is_Object_Reference --
6118 -------------------------
6120 function Is_Object_Reference (N : Node_Id) return Boolean is
6122 if Is_Entity_Name (N) then
6123 return Present (Entity (N)) and then Is_Object (Entity (N));
6127 when N_Indexed_Component | N_Slice =>
6129 Is_Object_Reference (Prefix (N))
6130 or else Is_Access_Type (Etype (Prefix (N)));
6132 -- In Ada95, a function call is a constant object; a procedure
6135 when N_Function_Call =>
6136 return Etype (N) /= Standard_Void_Type;
6138 -- A reference to the stream attribute Input is a function call
6140 when N_Attribute_Reference =>
6141 return Attribute_Name (N) = Name_Input;
6143 when N_Selected_Component =>
6145 Is_Object_Reference (Selector_Name (N))
6147 (Is_Object_Reference (Prefix (N))
6148 or else Is_Access_Type (Etype (Prefix (N))));
6150 when N_Explicit_Dereference =>
6153 -- A view conversion of a tagged object is an object reference
6155 when N_Type_Conversion =>
6156 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6157 and then Is_Tagged_Type (Etype (Expression (N)))
6158 and then Is_Object_Reference (Expression (N));
6160 -- An unchecked type conversion is considered to be an object if
6161 -- the operand is an object (this construction arises only as a
6162 -- result of expansion activities).
6164 when N_Unchecked_Type_Conversion =>
6171 end Is_Object_Reference;
6173 -----------------------------------
6174 -- Is_OK_Variable_For_Out_Formal --
6175 -----------------------------------
6177 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6179 Note_Possible_Modification (AV);
6181 -- We must reject parenthesized variable names. The check for
6182 -- Comes_From_Source is present because there are currently
6183 -- cases where the compiler violates this rule (e.g. passing
6184 -- a task object to its controlled Initialize routine).
6186 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6189 -- A variable is always allowed
6191 elsif Is_Variable (AV) then
6194 -- Unchecked conversions are allowed only if they come from the
6195 -- generated code, which sometimes uses unchecked conversions for out
6196 -- parameters in cases where code generation is unaffected. We tell
6197 -- source unchecked conversions by seeing if they are rewrites of an
6198 -- original Unchecked_Conversion function call, or of an explicit
6199 -- conversion of a function call.
6201 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6202 if Nkind (Original_Node (AV)) = N_Function_Call then
6205 elsif Comes_From_Source (AV)
6206 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6210 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6211 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6217 -- Normal type conversions are allowed if argument is a variable
6219 elsif Nkind (AV) = N_Type_Conversion then
6220 if Is_Variable (Expression (AV))
6221 and then Paren_Count (Expression (AV)) = 0
6223 Note_Possible_Modification (Expression (AV));
6226 -- We also allow a non-parenthesized expression that raises
6227 -- constraint error if it rewrites what used to be a variable
6229 elsif Raises_Constraint_Error (Expression (AV))
6230 and then Paren_Count (Expression (AV)) = 0
6231 and then Is_Variable (Original_Node (Expression (AV)))
6235 -- Type conversion of something other than a variable
6241 -- If this node is rewritten, then test the original form, if that is
6242 -- OK, then we consider the rewritten node OK (for example, if the
6243 -- original node is a conversion, then Is_Variable will not be true
6244 -- but we still want to allow the conversion if it converts a variable).
6246 elsif Original_Node (AV) /= AV then
6247 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6249 -- All other non-variables are rejected
6254 end Is_OK_Variable_For_Out_Formal;
6262 E2 : Entity_Id) return Boolean
6264 Iface_List : List_Id;
6265 T : Entity_Id := E2;
6268 if Is_Concurrent_Type (T)
6269 or else Is_Concurrent_Record_Type (T)
6271 Iface_List := Abstract_Interface_List (E2);
6273 if Is_Empty_List (Iface_List) then
6277 T := Etype (First (Iface_List));
6280 return Is_Ancestor (E1, T);
6283 -----------------------------------
6284 -- Is_Partially_Initialized_Type --
6285 -----------------------------------
6287 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6289 if Is_Scalar_Type (Typ) then
6292 elsif Is_Access_Type (Typ) then
6295 elsif Is_Array_Type (Typ) then
6297 -- If component type is partially initialized, so is array type
6299 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6302 -- Otherwise we are only partially initialized if we are fully
6303 -- initialized (this is the empty array case, no point in us
6304 -- duplicating that code here).
6307 return Is_Fully_Initialized_Type (Typ);
6310 elsif Is_Record_Type (Typ) then
6312 -- A discriminated type is always partially initialized
6314 if Has_Discriminants (Typ) then
6317 -- A tagged type is always partially initialized
6319 elsif Is_Tagged_Type (Typ) then
6322 -- Case of non-discriminated record
6328 Component_Present : Boolean := False;
6329 -- Set True if at least one component is present. If no
6330 -- components are present, then record type is fully
6331 -- initialized (another odd case, like the null array).
6334 -- Loop through components
6336 Ent := First_Entity (Typ);
6337 while Present (Ent) loop
6338 if Ekind (Ent) = E_Component then
6339 Component_Present := True;
6341 -- If a component has an initialization expression then
6342 -- the enclosing record type is partially initialized
6344 if Present (Parent (Ent))
6345 and then Present (Expression (Parent (Ent)))
6349 -- If a component is of a type which is itself partially
6350 -- initialized, then the enclosing record type is also.
6352 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6360 -- No initialized components found. If we found any components
6361 -- they were all uninitialized so the result is false.
6363 if Component_Present then
6366 -- But if we found no components, then all the components are
6367 -- initialized so we consider the type to be initialized.
6375 -- Concurrent types are always fully initialized
6377 elsif Is_Concurrent_Type (Typ) then
6380 -- For a private type, go to underlying type. If there is no underlying
6381 -- type then just assume this partially initialized. Not clear if this
6382 -- can happen in a non-error case, but no harm in testing for this.
6384 elsif Is_Private_Type (Typ) then
6386 U : constant Entity_Id := Underlying_Type (Typ);
6391 return Is_Partially_Initialized_Type (U);
6395 -- For any other type (are there any?) assume partially initialized
6400 end Is_Partially_Initialized_Type;
6402 ------------------------------------
6403 -- Is_Potentially_Persistent_Type --
6404 ------------------------------------
6406 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6411 -- For private type, test corrresponding full type
6413 if Is_Private_Type (T) then
6414 return Is_Potentially_Persistent_Type (Full_View (T));
6416 -- Scalar types are potentially persistent
6418 elsif Is_Scalar_Type (T) then
6421 -- Record type is potentially persistent if not tagged and the types of
6422 -- all it components are potentially persistent, and no component has
6423 -- an initialization expression.
6425 elsif Is_Record_Type (T)
6426 and then not Is_Tagged_Type (T)
6427 and then not Is_Partially_Initialized_Type (T)
6429 Comp := First_Component (T);
6430 while Present (Comp) loop
6431 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6440 -- Array type is potentially persistent if its component type is
6441 -- potentially persistent and if all its constraints are static.
6443 elsif Is_Array_Type (T) then
6444 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6448 Indx := First_Index (T);
6449 while Present (Indx) loop
6450 if not Is_OK_Static_Subtype (Etype (Indx)) then
6459 -- All other types are not potentially persistent
6464 end Is_Potentially_Persistent_Type;
6466 -----------------------------
6467 -- Is_RCI_Pkg_Spec_Or_Body --
6468 -----------------------------
6470 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6472 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6473 -- Return True if the unit of Cunit is an RCI package declaration
6475 ---------------------------
6476 -- Is_RCI_Pkg_Decl_Cunit --
6477 ---------------------------
6479 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6480 The_Unit : constant Node_Id := Unit (Cunit);
6483 if Nkind (The_Unit) /= N_Package_Declaration then
6487 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6488 end Is_RCI_Pkg_Decl_Cunit;
6490 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6493 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6495 (Nkind (Unit (Cunit)) = N_Package_Body
6496 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6497 end Is_RCI_Pkg_Spec_Or_Body;
6499 -----------------------------------------
6500 -- Is_Remote_Access_To_Class_Wide_Type --
6501 -----------------------------------------
6503 function Is_Remote_Access_To_Class_Wide_Type
6504 (E : Entity_Id) return Boolean
6508 function Comes_From_Limited_Private_Type_Declaration
6509 (E : Entity_Id) return Boolean;
6510 -- Check that the type is declared by a limited type declaration,
6511 -- or else is derived from a Remote_Type ancestor through private
6514 -------------------------------------------------
6515 -- Comes_From_Limited_Private_Type_Declaration --
6516 -------------------------------------------------
6518 function Comes_From_Limited_Private_Type_Declaration
6519 (E : Entity_Id) return Boolean
6521 N : constant Node_Id := Declaration_Node (E);
6524 if Nkind (N) = N_Private_Type_Declaration
6525 and then Limited_Present (N)
6530 if Nkind (N) = N_Private_Extension_Declaration then
6532 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6534 (Is_Remote_Types (Etype (E))
6535 and then Is_Limited_Record (Etype (E))
6536 and then Has_Private_Declaration (Etype (E)));
6540 end Comes_From_Limited_Private_Type_Declaration;
6542 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6545 if not (Is_Remote_Call_Interface (E)
6546 or else Is_Remote_Types (E))
6547 or else Ekind (E) /= E_General_Access_Type
6552 D := Designated_Type (E);
6554 if Ekind (D) /= E_Class_Wide_Type then
6558 return Comes_From_Limited_Private_Type_Declaration
6559 (Defining_Identifier (Parent (D)));
6560 end Is_Remote_Access_To_Class_Wide_Type;
6562 -----------------------------------------
6563 -- Is_Remote_Access_To_Subprogram_Type --
6564 -----------------------------------------
6566 function Is_Remote_Access_To_Subprogram_Type
6567 (E : Entity_Id) return Boolean
6570 return (Ekind (E) = E_Access_Subprogram_Type
6571 or else (Ekind (E) = E_Record_Type
6572 and then Present (Corresponding_Remote_Type (E))))
6573 and then (Is_Remote_Call_Interface (E)
6574 or else Is_Remote_Types (E));
6575 end Is_Remote_Access_To_Subprogram_Type;
6577 --------------------
6578 -- Is_Remote_Call --
6579 --------------------
6581 function Is_Remote_Call (N : Node_Id) return Boolean is
6583 if Nkind (N) /= N_Procedure_Call_Statement
6584 and then Nkind (N) /= N_Function_Call
6586 -- An entry call cannot be remote
6590 elsif Nkind (Name (N)) in N_Has_Entity
6591 and then Is_Remote_Call_Interface (Entity (Name (N)))
6593 -- A subprogram declared in the spec of a RCI package is remote
6597 elsif Nkind (Name (N)) = N_Explicit_Dereference
6598 and then Is_Remote_Access_To_Subprogram_Type
6599 (Etype (Prefix (Name (N))))
6601 -- The dereference of a RAS is a remote call
6605 elsif Present (Controlling_Argument (N))
6606 and then Is_Remote_Access_To_Class_Wide_Type
6607 (Etype (Controlling_Argument (N)))
6609 -- Any primitive operation call with a controlling argument of
6610 -- a RACW type is a remote call.
6615 -- All other calls are local calls
6620 ----------------------
6621 -- Is_Renamed_Entry --
6622 ----------------------
6624 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6625 Orig_Node : Node_Id := Empty;
6626 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6628 function Is_Entry (Nam : Node_Id) return Boolean;
6629 -- Determine whether Nam is an entry. Traverse selectors
6630 -- if there are nested selected components.
6636 function Is_Entry (Nam : Node_Id) return Boolean is
6638 if Nkind (Nam) = N_Selected_Component then
6639 return Is_Entry (Selector_Name (Nam));
6642 return Ekind (Entity (Nam)) = E_Entry;
6645 -- Start of processing for Is_Renamed_Entry
6648 if Present (Alias (Proc_Nam)) then
6649 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6652 -- Look for a rewritten subprogram renaming declaration
6654 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6655 and then Present (Original_Node (Subp_Decl))
6657 Orig_Node := Original_Node (Subp_Decl);
6660 -- The rewritten subprogram is actually an entry
6662 if Present (Orig_Node)
6663 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6664 and then Is_Entry (Name (Orig_Node))
6670 end Is_Renamed_Entry;
6672 ----------------------
6673 -- Is_Selector_Name --
6674 ----------------------
6676 function Is_Selector_Name (N : Node_Id) return Boolean is
6678 if not Is_List_Member (N) then
6680 P : constant Node_Id := Parent (N);
6681 K : constant Node_Kind := Nkind (P);
6684 (K = N_Expanded_Name or else
6685 K = N_Generic_Association or else
6686 K = N_Parameter_Association or else
6687 K = N_Selected_Component)
6688 and then Selector_Name (P) = N;
6693 L : constant List_Id := List_Containing (N);
6694 P : constant Node_Id := Parent (L);
6696 return (Nkind (P) = N_Discriminant_Association
6697 and then Selector_Names (P) = L)
6699 (Nkind (P) = N_Component_Association
6700 and then Choices (P) = L);
6703 end Is_Selector_Name;
6709 function Is_Statement (N : Node_Id) return Boolean is
6712 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6713 or else Nkind (N) = N_Procedure_Call_Statement;
6716 ---------------------------------
6717 -- Is_Synchronized_Tagged_Type --
6718 ---------------------------------
6720 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6721 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6724 -- A task or protected type derived from an interface is a tagged type.
6725 -- Such a tagged type is called a synchronized tagged type, as are
6726 -- synchronized interfaces and private extensions whose declaration
6727 -- includes the reserved word synchronized.
6729 return (Is_Tagged_Type (E)
6730 and then (Kind = E_Task_Type
6731 or else Kind = E_Protected_Type))
6734 and then Is_Synchronized_Interface (E))
6736 (Ekind (E) = E_Record_Type_With_Private
6737 and then (Synchronized_Present (Parent (E))
6738 or else Is_Synchronized_Interface (Etype (E))));
6739 end Is_Synchronized_Tagged_Type;
6745 function Is_Transfer (N : Node_Id) return Boolean is
6746 Kind : constant Node_Kind := Nkind (N);
6749 if Kind = N_Simple_Return_Statement
6751 Kind = N_Extended_Return_Statement
6753 Kind = N_Goto_Statement
6755 Kind = N_Raise_Statement
6757 Kind = N_Requeue_Statement
6761 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6762 and then No (Condition (N))
6766 elsif Kind = N_Procedure_Call_Statement
6767 and then Is_Entity_Name (Name (N))
6768 and then Present (Entity (Name (N)))
6769 and then No_Return (Entity (Name (N)))
6773 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6785 function Is_True (U : Uint) return Boolean is
6794 function Is_Value_Type (T : Entity_Id) return Boolean is
6796 return VM_Target = CLI_Target
6797 and then Chars (T) /= No_Name
6798 and then Get_Name_String (Chars (T)) = "valuetype";
6805 function Is_Variable (N : Node_Id) return Boolean is
6807 Orig_Node : constant Node_Id := Original_Node (N);
6808 -- We do the test on the original node, since this is basically a
6809 -- test of syntactic categories, so it must not be disturbed by
6810 -- whatever rewriting might have occurred. For example, an aggregate,
6811 -- which is certainly NOT a variable, could be turned into a variable
6814 function In_Protected_Function (E : Entity_Id) return Boolean;
6815 -- Within a protected function, the private components of the
6816 -- enclosing protected type are constants. A function nested within
6817 -- a (protected) procedure is not itself protected.
6819 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6820 -- Prefixes can involve implicit dereferences, in which case we
6821 -- must test for the case of a reference of a constant access
6822 -- type, which can never be a variable.
6824 ---------------------------
6825 -- In_Protected_Function --
6826 ---------------------------
6828 function In_Protected_Function (E : Entity_Id) return Boolean is
6829 Prot : constant Entity_Id := Scope (E);
6833 if not Is_Protected_Type (Prot) then
6837 while Present (S) and then S /= Prot loop
6838 if Ekind (S) = E_Function
6839 and then Scope (S) = Prot
6849 end In_Protected_Function;
6851 ------------------------
6852 -- Is_Variable_Prefix --
6853 ------------------------
6855 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6857 if Is_Access_Type (Etype (P)) then
6858 return not Is_Access_Constant (Root_Type (Etype (P)));
6860 -- For the case of an indexed component whose prefix has a packed
6861 -- array type, the prefix has been rewritten into a type conversion.
6862 -- Determine variable-ness from the converted expression.
6864 elsif Nkind (P) = N_Type_Conversion
6865 and then not Comes_From_Source (P)
6866 and then Is_Array_Type (Etype (P))
6867 and then Is_Packed (Etype (P))
6869 return Is_Variable (Expression (P));
6872 return Is_Variable (P);
6874 end Is_Variable_Prefix;
6876 -- Start of processing for Is_Variable
6879 -- Definitely OK if Assignment_OK is set. Since this is something that
6880 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6882 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6885 -- Normally we go to the original node, but there is one exception
6886 -- where we use the rewritten node, namely when it is an explicit
6887 -- dereference. The generated code may rewrite a prefix which is an
6888 -- access type with an explicit dereference. The dereference is a
6889 -- variable, even though the original node may not be (since it could
6890 -- be a constant of the access type).
6892 -- In Ada 2005 we have a further case to consider: the prefix may be
6893 -- a function call given in prefix notation. The original node appears
6894 -- to be a selected component, but we need to examine the call.
6896 elsif Nkind (N) = N_Explicit_Dereference
6897 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6898 and then Present (Etype (Orig_Node))
6899 and then Is_Access_Type (Etype (Orig_Node))
6901 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6903 (Nkind (Orig_Node) = N_Function_Call
6904 and then not Is_Access_Constant (Etype (Prefix (N))));
6906 -- A function call is never a variable
6908 elsif Nkind (N) = N_Function_Call then
6911 -- All remaining checks use the original node
6913 elsif Is_Entity_Name (Orig_Node)
6914 and then Present (Entity (Orig_Node))
6917 E : constant Entity_Id := Entity (Orig_Node);
6918 K : constant Entity_Kind := Ekind (E);
6921 return (K = E_Variable
6922 and then Nkind (Parent (E)) /= N_Exception_Handler)
6923 or else (K = E_Component
6924 and then not In_Protected_Function (E))
6925 or else K = E_Out_Parameter
6926 or else K = E_In_Out_Parameter
6927 or else K = E_Generic_In_Out_Parameter
6929 -- Current instance of type:
6931 or else (Is_Type (E) and then In_Open_Scopes (E))
6932 or else (Is_Incomplete_Or_Private_Type (E)
6933 and then In_Open_Scopes (Full_View (E)));
6937 case Nkind (Orig_Node) is
6938 when N_Indexed_Component | N_Slice =>
6939 return Is_Variable_Prefix (Prefix (Orig_Node));
6941 when N_Selected_Component =>
6942 return Is_Variable_Prefix (Prefix (Orig_Node))
6943 and then Is_Variable (Selector_Name (Orig_Node));
6945 -- For an explicit dereference, the type of the prefix cannot
6946 -- be an access to constant or an access to subprogram.
6948 when N_Explicit_Dereference =>
6950 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6952 return Is_Access_Type (Typ)
6953 and then not Is_Access_Constant (Root_Type (Typ))
6954 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6957 -- The type conversion is the case where we do not deal with the
6958 -- context dependent special case of an actual parameter. Thus
6959 -- the type conversion is only considered a variable for the
6960 -- purposes of this routine if the target type is tagged. However,
6961 -- a type conversion is considered to be a variable if it does not
6962 -- come from source (this deals for example with the conversions
6963 -- of expressions to their actual subtypes).
6965 when N_Type_Conversion =>
6966 return Is_Variable (Expression (Orig_Node))
6968 (not Comes_From_Source (Orig_Node)
6970 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6972 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6974 -- GNAT allows an unchecked type conversion as a variable. This
6975 -- only affects the generation of internal expanded code, since
6976 -- calls to instantiations of Unchecked_Conversion are never
6977 -- considered variables (since they are function calls).
6978 -- This is also true for expression actions.
6980 when N_Unchecked_Type_Conversion =>
6981 return Is_Variable (Expression (Orig_Node));
6989 ------------------------
6990 -- Is_Volatile_Object --
6991 ------------------------
6993 function Is_Volatile_Object (N : Node_Id) return Boolean is
6995 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6996 -- Determines if given object has volatile components
6998 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6999 -- If prefix is an implicit dereference, examine designated type
7001 ------------------------
7002 -- Is_Volatile_Prefix --
7003 ------------------------
7005 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7006 Typ : constant Entity_Id := Etype (N);
7009 if Is_Access_Type (Typ) then
7011 Dtyp : constant Entity_Id := Designated_Type (Typ);
7014 return Is_Volatile (Dtyp)
7015 or else Has_Volatile_Components (Dtyp);
7019 return Object_Has_Volatile_Components (N);
7021 end Is_Volatile_Prefix;
7023 ------------------------------------
7024 -- Object_Has_Volatile_Components --
7025 ------------------------------------
7027 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7028 Typ : constant Entity_Id := Etype (N);
7031 if Is_Volatile (Typ)
7032 or else Has_Volatile_Components (Typ)
7036 elsif Is_Entity_Name (N)
7037 and then (Has_Volatile_Components (Entity (N))
7038 or else Is_Volatile (Entity (N)))
7042 elsif Nkind (N) = N_Indexed_Component
7043 or else Nkind (N) = N_Selected_Component
7045 return Is_Volatile_Prefix (Prefix (N));
7050 end Object_Has_Volatile_Components;
7052 -- Start of processing for Is_Volatile_Object
7055 if Is_Volatile (Etype (N))
7056 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7060 elsif Nkind (N) = N_Indexed_Component
7061 or else Nkind (N) = N_Selected_Component
7063 return Is_Volatile_Prefix (Prefix (N));
7068 end Is_Volatile_Object;
7070 -------------------------
7071 -- Kill_Current_Values --
7072 -------------------------
7074 procedure Kill_Current_Values
7076 Last_Assignment_Only : Boolean := False)
7079 if Is_Assignable (Ent) then
7080 Set_Last_Assignment (Ent, Empty);
7083 if not Last_Assignment_Only and then Is_Object (Ent) then
7085 Set_Current_Value (Ent, Empty);
7087 if not Can_Never_Be_Null (Ent) then
7088 Set_Is_Known_Non_Null (Ent, False);
7091 Set_Is_Known_Null (Ent, False);
7093 end Kill_Current_Values;
7095 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7098 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7099 -- Clear current value for entity E and all entities chained to E
7101 ------------------------------------------
7102 -- Kill_Current_Values_For_Entity_Chain --
7103 ------------------------------------------
7105 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7109 while Present (Ent) loop
7110 Kill_Current_Values (Ent, Last_Assignment_Only);
7113 end Kill_Current_Values_For_Entity_Chain;
7115 -- Start of processing for Kill_Current_Values
7118 -- Kill all saved checks, a special case of killing saved values
7120 if not Last_Assignment_Only then
7124 -- Loop through relevant scopes, which includes the current scope and
7125 -- any parent scopes if the current scope is a block or a package.
7130 -- Clear current values of all entities in current scope
7132 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7134 -- If scope is a package, also clear current values of all
7135 -- private entities in the scope.
7137 if Ekind (S) = E_Package
7139 Ekind (S) = E_Generic_Package
7141 Is_Concurrent_Type (S)
7143 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7146 -- If this is a not a subprogram, deal with parents
7148 if not Is_Subprogram (S) then
7150 exit Scope_Loop when S = Standard_Standard;
7154 end loop Scope_Loop;
7155 end Kill_Current_Values;
7157 --------------------------
7158 -- Kill_Size_Check_Code --
7159 --------------------------
7161 procedure Kill_Size_Check_Code (E : Entity_Id) is
7163 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7164 and then Present (Size_Check_Code (E))
7166 Remove (Size_Check_Code (E));
7167 Set_Size_Check_Code (E, Empty);
7169 end Kill_Size_Check_Code;
7171 --------------------------
7172 -- Known_To_Be_Assigned --
7173 --------------------------
7175 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7176 P : constant Node_Id := Parent (N);
7181 -- Test left side of assignment
7183 when N_Assignment_Statement =>
7184 return N = Name (P);
7186 -- Function call arguments are never lvalues
7188 when N_Function_Call =>
7191 -- Positional parameter for procedure or accept call
7193 when N_Procedure_Call_Statement |
7202 Proc := Get_Subprogram_Entity (P);
7208 -- If we are not a list member, something is strange, so
7209 -- be conservative and return False.
7211 if not Is_List_Member (N) then
7215 -- We are going to find the right formal by stepping forward
7216 -- through the formals, as we step backwards in the actuals.
7218 Form := First_Formal (Proc);
7221 -- If no formal, something is weird, so be conservative
7222 -- and return False.
7233 return Ekind (Form) /= E_In_Parameter;
7236 -- Named parameter for procedure or accept call
7238 when N_Parameter_Association =>
7244 Proc := Get_Subprogram_Entity (Parent (P));
7250 -- Loop through formals to find the one that matches
7252 Form := First_Formal (Proc);
7254 -- If no matching formal, that's peculiar, some kind of
7255 -- previous error, so return False to be conservative.
7261 -- Else test for match
7263 if Chars (Form) = Chars (Selector_Name (P)) then
7264 return Ekind (Form) /= E_In_Parameter;
7271 -- Test for appearing in a conversion that itself appears
7272 -- in an lvalue context, since this should be an lvalue.
7274 when N_Type_Conversion =>
7275 return Known_To_Be_Assigned (P);
7277 -- All other references are definitely not knwon to be modifications
7283 end Known_To_Be_Assigned;
7289 function May_Be_Lvalue (N : Node_Id) return Boolean is
7290 P : constant Node_Id := Parent (N);
7295 -- Test left side of assignment
7297 when N_Assignment_Statement =>
7298 return N = Name (P);
7300 -- Test prefix of component or attribute
7302 when N_Attribute_Reference =>
7303 return N = Prefix (P)
7304 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7306 when N_Expanded_Name |
7307 N_Explicit_Dereference |
7308 N_Indexed_Component |
7310 N_Selected_Component |
7312 return N = Prefix (P);
7314 -- Function call arguments are never lvalues
7316 when N_Function_Call =>
7319 -- Positional parameter for procedure, entry, or accept call
7321 when N_Procedure_Call_Statement |
7322 N_Entry_Call_Statement |
7331 Proc := Get_Subprogram_Entity (P);
7337 -- If we are not a list member, something is strange, so
7338 -- be conservative and return True.
7340 if not Is_List_Member (N) then
7344 -- We are going to find the right formal by stepping forward
7345 -- through the formals, as we step backwards in the actuals.
7347 Form := First_Formal (Proc);
7350 -- If no formal, something is weird, so be conservative
7362 return Ekind (Form) /= E_In_Parameter;
7365 -- Named parameter for procedure or accept call
7367 when N_Parameter_Association =>
7373 Proc := Get_Subprogram_Entity (Parent (P));
7379 -- Loop through formals to find the one that matches
7381 Form := First_Formal (Proc);
7383 -- If no matching formal, that's peculiar, some kind of
7384 -- previous error, so return True to be conservative.
7390 -- Else test for match
7392 if Chars (Form) = Chars (Selector_Name (P)) then
7393 return Ekind (Form) /= E_In_Parameter;
7400 -- Test for appearing in a conversion that itself appears in an
7401 -- lvalue context, since this should be an lvalue.
7403 when N_Type_Conversion =>
7404 return May_Be_Lvalue (P);
7406 -- Test for appearence in object renaming declaration
7408 when N_Object_Renaming_Declaration =>
7411 -- All other references are definitely not Lvalues
7419 -----------------------
7420 -- Mark_Coextensions --
7421 -----------------------
7423 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7424 Is_Dynamic : Boolean;
7425 -- Indicates whether the context causes nested coextensions to be
7426 -- dynamic or static
7428 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7429 -- Recognize an allocator node and label it as a dynamic coextension
7431 --------------------
7432 -- Mark_Allocator --
7433 --------------------
7435 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7437 if Nkind (N) = N_Allocator then
7439 Set_Is_Dynamic_Coextension (N);
7441 Set_Is_Static_Coextension (N);
7448 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7450 -- Start of processing Mark_Coextensions
7453 case Nkind (Context_Nod) is
7454 when N_Assignment_Statement |
7455 N_Simple_Return_Statement =>
7456 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7458 when N_Object_Declaration =>
7459 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7461 -- This routine should not be called for constructs which may not
7462 -- contain coextensions.
7465 raise Program_Error;
7468 Mark_Allocators (Root_Nod);
7469 end Mark_Coextensions;
7471 ----------------------
7472 -- Needs_One_Actual --
7473 ----------------------
7475 function Needs_One_Actual (E : Entity_Id) return Boolean is
7479 if Ada_Version >= Ada_05
7480 and then Present (First_Formal (E))
7482 Formal := Next_Formal (First_Formal (E));
7483 while Present (Formal) loop
7484 if No (Default_Value (Formal)) then
7488 Next_Formal (Formal);
7496 end Needs_One_Actual;
7498 -------------------------
7499 -- New_External_Entity --
7500 -------------------------
7502 function New_External_Entity
7503 (Kind : Entity_Kind;
7504 Scope_Id : Entity_Id;
7505 Sloc_Value : Source_Ptr;
7506 Related_Id : Entity_Id;
7508 Suffix_Index : Nat := 0;
7509 Prefix : Character := ' ') return Entity_Id
7511 N : constant Entity_Id :=
7512 Make_Defining_Identifier (Sloc_Value,
7514 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7517 Set_Ekind (N, Kind);
7518 Set_Is_Internal (N, True);
7519 Append_Entity (N, Scope_Id);
7520 Set_Public_Status (N);
7522 if Kind in Type_Kind then
7523 Init_Size_Align (N);
7527 end New_External_Entity;
7529 -------------------------
7530 -- New_Internal_Entity --
7531 -------------------------
7533 function New_Internal_Entity
7534 (Kind : Entity_Kind;
7535 Scope_Id : Entity_Id;
7536 Sloc_Value : Source_Ptr;
7537 Id_Char : Character) return Entity_Id
7539 N : constant Entity_Id :=
7540 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7543 Set_Ekind (N, Kind);
7544 Set_Is_Internal (N, True);
7545 Append_Entity (N, Scope_Id);
7547 if Kind in Type_Kind then
7548 Init_Size_Align (N);
7552 end New_Internal_Entity;
7558 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7562 -- If we are pointing at a positional parameter, it is a member of a
7563 -- node list (the list of parameters), and the next parameter is the
7564 -- next node on the list, unless we hit a parameter association, then
7565 -- we shift to using the chain whose head is the First_Named_Actual in
7566 -- the parent, and then is threaded using the Next_Named_Actual of the
7567 -- Parameter_Association. All this fiddling is because the original node
7568 -- list is in the textual call order, and what we need is the
7569 -- declaration order.
7571 if Is_List_Member (Actual_Id) then
7572 N := Next (Actual_Id);
7574 if Nkind (N) = N_Parameter_Association then
7575 return First_Named_Actual (Parent (Actual_Id));
7581 return Next_Named_Actual (Parent (Actual_Id));
7585 procedure Next_Actual (Actual_Id : in out Node_Id) is
7587 Actual_Id := Next_Actual (Actual_Id);
7590 -----------------------
7591 -- Normalize_Actuals --
7592 -----------------------
7594 -- Chain actuals according to formals of subprogram. If there are no named
7595 -- associations, the chain is simply the list of Parameter Associations,
7596 -- since the order is the same as the declaration order. If there are named
7597 -- associations, then the First_Named_Actual field in the N_Function_Call
7598 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7599 -- node for the parameter that comes first in declaration order. The
7600 -- remaining named parameters are then chained in declaration order using
7601 -- Next_Named_Actual.
7603 -- This routine also verifies that the number of actuals is compatible with
7604 -- the number and default values of formals, but performs no type checking
7605 -- (type checking is done by the caller).
7607 -- If the matching succeeds, Success is set to True and the caller proceeds
7608 -- with type-checking. If the match is unsuccessful, then Success is set to
7609 -- False, and the caller attempts a different interpretation, if there is
7612 -- If the flag Report is on, the call is not overloaded, and a failure to
7613 -- match can be reported here, rather than in the caller.
7615 procedure Normalize_Actuals
7619 Success : out Boolean)
7621 Actuals : constant List_Id := Parameter_Associations (N);
7622 Actual : Node_Id := Empty;
7624 Last : Node_Id := Empty;
7625 First_Named : Node_Id := Empty;
7628 Formals_To_Match : Integer := 0;
7629 Actuals_To_Match : Integer := 0;
7631 procedure Chain (A : Node_Id);
7632 -- Add named actual at the proper place in the list, using the
7633 -- Next_Named_Actual link.
7635 function Reporting return Boolean;
7636 -- Determines if an error is to be reported. To report an error, we
7637 -- need Report to be True, and also we do not report errors caused
7638 -- by calls to init procs that occur within other init procs. Such
7639 -- errors must always be cascaded errors, since if all the types are
7640 -- declared correctly, the compiler will certainly build decent calls!
7646 procedure Chain (A : Node_Id) is
7650 -- Call node points to first actual in list
7652 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7655 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7659 Set_Next_Named_Actual (Last, Empty);
7666 function Reporting return Boolean is
7671 elsif not Within_Init_Proc then
7674 elsif Is_Init_Proc (Entity (Name (N))) then
7682 -- Start of processing for Normalize_Actuals
7685 if Is_Access_Type (S) then
7687 -- The name in the call is a function call that returns an access
7688 -- to subprogram. The designated type has the list of formals.
7690 Formal := First_Formal (Designated_Type (S));
7692 Formal := First_Formal (S);
7695 while Present (Formal) loop
7696 Formals_To_Match := Formals_To_Match + 1;
7697 Next_Formal (Formal);
7700 -- Find if there is a named association, and verify that no positional
7701 -- associations appear after named ones.
7703 if Present (Actuals) then
7704 Actual := First (Actuals);
7707 while Present (Actual)
7708 and then Nkind (Actual) /= N_Parameter_Association
7710 Actuals_To_Match := Actuals_To_Match + 1;
7714 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7716 -- Most common case: positional notation, no defaults
7721 elsif Actuals_To_Match > Formals_To_Match then
7723 -- Too many actuals: will not work
7726 if Is_Entity_Name (Name (N)) then
7727 Error_Msg_N ("too many arguments in call to&", Name (N));
7729 Error_Msg_N ("too many arguments in call", N);
7737 First_Named := Actual;
7739 while Present (Actual) loop
7740 if Nkind (Actual) /= N_Parameter_Association then
7742 ("positional parameters not allowed after named ones", Actual);
7747 Actuals_To_Match := Actuals_To_Match + 1;
7753 if Present (Actuals) then
7754 Actual := First (Actuals);
7757 Formal := First_Formal (S);
7758 while Present (Formal) loop
7760 -- Match the formals in order. If the corresponding actual is
7761 -- positional, nothing to do. Else scan the list of named actuals
7762 -- to find the one with the right name.
7765 and then Nkind (Actual) /= N_Parameter_Association
7768 Actuals_To_Match := Actuals_To_Match - 1;
7769 Formals_To_Match := Formals_To_Match - 1;
7772 -- For named parameters, search the list of actuals to find
7773 -- one that matches the next formal name.
7775 Actual := First_Named;
7777 while Present (Actual) loop
7778 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7781 Actuals_To_Match := Actuals_To_Match - 1;
7782 Formals_To_Match := Formals_To_Match - 1;
7790 if Ekind (Formal) /= E_In_Parameter
7791 or else No (Default_Value (Formal))
7794 if (Comes_From_Source (S)
7795 or else Sloc (S) = Standard_Location)
7796 and then Is_Overloadable (S)
7800 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7802 (Nkind (Parent (N)) = N_Function_Call
7804 Nkind (Parent (N)) = N_Parameter_Association))
7805 and then Ekind (S) /= E_Function
7807 Set_Etype (N, Etype (S));
7809 Error_Msg_Name_1 := Chars (S);
7810 Error_Msg_Sloc := Sloc (S);
7812 ("missing argument for parameter & " &
7813 "in call to % declared #", N, Formal);
7816 elsif Is_Overloadable (S) then
7817 Error_Msg_Name_1 := Chars (S);
7819 -- Point to type derivation that generated the
7822 Error_Msg_Sloc := Sloc (Parent (S));
7825 ("missing argument for parameter & " &
7826 "in call to % (inherited) #", N, Formal);
7830 ("missing argument for parameter &", N, Formal);
7838 Formals_To_Match := Formals_To_Match - 1;
7843 Next_Formal (Formal);
7846 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7853 -- Find some superfluous named actual that did not get
7854 -- attached to the list of associations.
7856 Actual := First (Actuals);
7857 while Present (Actual) loop
7858 if Nkind (Actual) = N_Parameter_Association
7859 and then Actual /= Last
7860 and then No (Next_Named_Actual (Actual))
7862 Error_Msg_N ("unmatched actual & in call",
7863 Selector_Name (Actual));
7874 end Normalize_Actuals;
7876 --------------------------------
7877 -- Note_Possible_Modification --
7878 --------------------------------
7880 procedure Note_Possible_Modification (N : Node_Id) is
7881 Modification_Comes_From_Source : constant Boolean :=
7882 Comes_From_Source (Parent (N));
7888 -- Loop to find referenced entity, if there is one
7895 if Is_Entity_Name (Exp) then
7896 Ent := Entity (Exp);
7898 -- If the entity is missing, it is an undeclared identifier,
7899 -- and there is nothing to annotate.
7905 elsif Nkind (Exp) = N_Explicit_Dereference then
7907 P : constant Node_Id := Prefix (Exp);
7910 if Nkind (P) = N_Selected_Component
7912 Entry_Formal (Entity (Selector_Name (P))))
7914 -- Case of a reference to an entry formal
7916 Ent := Entry_Formal (Entity (Selector_Name (P)));
7918 elsif Nkind (P) = N_Identifier
7919 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7920 and then Present (Expression (Parent (Entity (P))))
7921 and then Nkind (Expression (Parent (Entity (P))))
7924 -- Case of a reference to a value on which side effects have
7927 Exp := Prefix (Expression (Parent (Entity (P))));
7936 elsif Nkind (Exp) = N_Type_Conversion
7937 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7939 Exp := Expression (Exp);
7942 elsif Nkind (Exp) = N_Slice
7943 or else Nkind (Exp) = N_Indexed_Component
7944 or else Nkind (Exp) = N_Selected_Component
7946 Exp := Prefix (Exp);
7953 -- Now look for entity being referenced
7955 if Present (Ent) then
7956 if Is_Object (Ent) then
7957 if Comes_From_Source (Exp)
7958 or else Modification_Comes_From_Source
7960 if Has_Pragma_Unmodified (Ent) then
7961 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
7964 Set_Never_Set_In_Source (Ent, False);
7967 Set_Is_True_Constant (Ent, False);
7968 Set_Current_Value (Ent, Empty);
7969 Set_Is_Known_Null (Ent, False);
7971 if not Can_Never_Be_Null (Ent) then
7972 Set_Is_Known_Non_Null (Ent, False);
7975 -- Follow renaming chain
7977 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7978 and then Present (Renamed_Object (Ent))
7980 Exp := Renamed_Object (Ent);
7984 -- Generate a reference only if the assignment comes from
7985 -- source. This excludes, for example, calls to a dispatching
7986 -- assignment operation when the left-hand side is tagged.
7988 if Modification_Comes_From_Source then
7989 Generate_Reference (Ent, Exp, 'm');
7992 Check_Nested_Access (Ent);
7999 end Note_Possible_Modification;
8001 -------------------------
8002 -- Object_Access_Level --
8003 -------------------------
8005 function Object_Access_Level (Obj : Node_Id) return Uint is
8008 -- Returns the static accessibility level of the view denoted by Obj. Note
8009 -- that the value returned is the result of a call to Scope_Depth. Only
8010 -- scope depths associated with dynamic scopes can actually be returned.
8011 -- Since only relative levels matter for accessibility checking, the fact
8012 -- that the distance between successive levels of accessibility is not
8013 -- always one is immaterial (invariant: if level(E2) is deeper than
8014 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
8016 function Reference_To (Obj : Node_Id) return Node_Id;
8017 -- An explicit dereference is created when removing side-effects from
8018 -- expressions for constraint checking purposes. In this case a local
8019 -- access type is created for it. The correct access level is that of
8020 -- the original source node. We detect this case by noting that the
8021 -- prefix of the dereference is created by an object declaration whose
8022 -- initial expression is a reference.
8028 function Reference_To (Obj : Node_Id) return Node_Id is
8029 Pref : constant Node_Id := Prefix (Obj);
8031 if Is_Entity_Name (Pref)
8032 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
8033 and then Present (Expression (Parent (Entity (Pref))))
8034 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
8036 return (Prefix (Expression (Parent (Entity (Pref)))));
8042 -- Start of processing for Object_Access_Level
8045 if Is_Entity_Name (Obj) then
8048 -- If E is a type then it denotes a current instance. For this case
8049 -- we add one to the normal accessibility level of the type to ensure
8050 -- that current instances are treated as always being deeper than
8051 -- than the level of any visible named access type (see 3.10.2(21)).
8054 return Type_Access_Level (E) + 1;
8056 elsif Present (Renamed_Object (E)) then
8057 return Object_Access_Level (Renamed_Object (E));
8059 -- Similarly, if E is a component of the current instance of a
8060 -- protected type, any instance of it is assumed to be at a deeper
8061 -- level than the type. For a protected object (whose type is an
8062 -- anonymous protected type) its components are at the same level
8063 -- as the type itself.
8065 elsif not Is_Overloadable (E)
8066 and then Ekind (Scope (E)) = E_Protected_Type
8067 and then Comes_From_Source (Scope (E))
8069 return Type_Access_Level (Scope (E)) + 1;
8072 return Scope_Depth (Enclosing_Dynamic_Scope (E));
8075 elsif Nkind (Obj) = N_Selected_Component then
8076 if Is_Access_Type (Etype (Prefix (Obj))) then
8077 return Type_Access_Level (Etype (Prefix (Obj)));
8079 return Object_Access_Level (Prefix (Obj));
8082 elsif Nkind (Obj) = N_Indexed_Component then
8083 if Is_Access_Type (Etype (Prefix (Obj))) then
8084 return Type_Access_Level (Etype (Prefix (Obj)));
8086 return Object_Access_Level (Prefix (Obj));
8089 elsif Nkind (Obj) = N_Explicit_Dereference then
8091 -- If the prefix is a selected access discriminant then we make a
8092 -- recursive call on the prefix, which will in turn check the level
8093 -- of the prefix object of the selected discriminant.
8095 if Nkind (Prefix (Obj)) = N_Selected_Component
8096 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
8098 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
8100 return Object_Access_Level (Prefix (Obj));
8102 elsif not (Comes_From_Source (Obj)) then
8104 Ref : constant Node_Id := Reference_To (Obj);
8106 if Present (Ref) then
8107 return Object_Access_Level (Ref);
8109 return Type_Access_Level (Etype (Prefix (Obj)));
8114 return Type_Access_Level (Etype (Prefix (Obj)));
8117 elsif Nkind (Obj) = N_Type_Conversion
8118 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8120 return Object_Access_Level (Expression (Obj));
8122 -- Function results are objects, so we get either the access level of
8123 -- the function or, in the case of an indirect call, the level of of the
8124 -- access-to-subprogram type.
8126 elsif Nkind (Obj) = N_Function_Call then
8127 if Is_Entity_Name (Name (Obj)) then
8128 return Subprogram_Access_Level (Entity (Name (Obj)));
8130 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8133 -- For convenience we handle qualified expressions, even though
8134 -- they aren't technically object names.
8136 elsif Nkind (Obj) = N_Qualified_Expression then
8137 return Object_Access_Level (Expression (Obj));
8139 -- Otherwise return the scope level of Standard.
8140 -- (If there are cases that fall through
8141 -- to this point they will be treated as
8142 -- having global accessibility for now. ???)
8145 return Scope_Depth (Standard_Standard);
8147 end Object_Access_Level;
8149 -----------------------
8150 -- Private_Component --
8151 -----------------------
8153 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8154 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8156 function Trace_Components
8158 Check : Boolean) return Entity_Id;
8159 -- Recursive function that does the work, and checks against circular
8160 -- definition for each subcomponent type.
8162 ----------------------
8163 -- Trace_Components --
8164 ----------------------
8166 function Trace_Components
8168 Check : Boolean) return Entity_Id
8170 Btype : constant Entity_Id := Base_Type (T);
8171 Component : Entity_Id;
8173 Candidate : Entity_Id := Empty;
8176 if Check and then Btype = Ancestor then
8177 Error_Msg_N ("circular type definition", Type_Id);
8181 if Is_Private_Type (Btype)
8182 and then not Is_Generic_Type (Btype)
8184 if Present (Full_View (Btype))
8185 and then Is_Record_Type (Full_View (Btype))
8186 and then not Is_Frozen (Btype)
8188 -- To indicate that the ancestor depends on a private type, the
8189 -- current Btype is sufficient. However, to check for circular
8190 -- definition we must recurse on the full view.
8192 Candidate := Trace_Components (Full_View (Btype), True);
8194 if Candidate = Any_Type then
8204 elsif Is_Array_Type (Btype) then
8205 return Trace_Components (Component_Type (Btype), True);
8207 elsif Is_Record_Type (Btype) then
8208 Component := First_Entity (Btype);
8209 while Present (Component) loop
8211 -- Skip anonymous types generated by constrained components
8213 if not Is_Type (Component) then
8214 P := Trace_Components (Etype (Component), True);
8217 if P = Any_Type then
8225 Next_Entity (Component);
8233 end Trace_Components;
8235 -- Start of processing for Private_Component
8238 return Trace_Components (Type_Id, False);
8239 end Private_Component;
8241 -----------------------
8242 -- Process_End_Label --
8243 -----------------------
8245 procedure Process_End_Label
8254 Label_Ref : Boolean;
8255 -- Set True if reference to end label itself is required
8258 -- Gets set to the operator symbol or identifier that references the
8259 -- entity Ent. For the child unit case, this is the identifier from the
8260 -- designator. For other cases, this is simply Endl.
8262 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8263 -- N is an identifier node that appears as a parent unit reference in
8264 -- the case where Ent is a child unit. This procedure generates an
8265 -- appropriate cross-reference entry. E is the corresponding entity.
8267 -------------------------
8268 -- Generate_Parent_Ref --
8269 -------------------------
8271 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8273 -- If names do not match, something weird, skip reference
8275 if Chars (E) = Chars (N) then
8277 -- Generate the reference. We do NOT consider this as a reference
8278 -- for unreferenced symbol purposes.
8280 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8283 Style.Check_Identifier (N, E);
8286 end Generate_Parent_Ref;
8288 -- Start of processing for Process_End_Label
8291 -- If no node, ignore. This happens in some error situations, and
8292 -- also for some internally generated structures where no end label
8293 -- references are required in any case.
8299 -- Nothing to do if no End_Label, happens for internally generated
8300 -- constructs where we don't want an end label reference anyway. Also
8301 -- nothing to do if Endl is a string literal, which means there was
8302 -- some prior error (bad operator symbol)
8304 Endl := End_Label (N);
8306 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8310 -- Reference node is not in extended main source unit
8312 if not In_Extended_Main_Source_Unit (N) then
8314 -- Generally we do not collect references except for the extended
8315 -- main source unit. The one exception is the 'e' entry for a
8316 -- package spec, where it is useful for a client to have the
8317 -- ending information to define scopes.
8325 -- For this case, we can ignore any parent references, but we
8326 -- need the package name itself for the 'e' entry.
8328 if Nkind (Endl) = N_Designator then
8329 Endl := Identifier (Endl);
8333 -- Reference is in extended main source unit
8338 -- For designator, generate references for the parent entries
8340 if Nkind (Endl) = N_Designator then
8342 -- Generate references for the prefix if the END line comes from
8343 -- source (otherwise we do not need these references) We climb the
8344 -- scope stack to find the expected entities.
8346 if Comes_From_Source (Endl) then
8348 Scop := Current_Scope;
8349 while Nkind (Nam) = N_Selected_Component loop
8350 Scop := Scope (Scop);
8351 exit when No (Scop);
8352 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8353 Nam := Prefix (Nam);
8356 if Present (Scop) then
8357 Generate_Parent_Ref (Nam, Scope (Scop));
8361 Endl := Identifier (Endl);
8365 -- If the end label is not for the given entity, then either we have
8366 -- some previous error, or this is a generic instantiation for which
8367 -- we do not need to make a cross-reference in this case anyway. In
8368 -- either case we simply ignore the call.
8370 if Chars (Ent) /= Chars (Endl) then
8374 -- If label was really there, then generate a normal reference and then
8375 -- adjust the location in the end label to point past the name (which
8376 -- should almost always be the semicolon).
8380 if Comes_From_Source (Endl) then
8382 -- If a label reference is required, then do the style check and
8383 -- generate an l-type cross-reference entry for the label
8387 Style.Check_Identifier (Endl, Ent);
8390 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8393 -- Set the location to point past the label (normally this will
8394 -- mean the semicolon immediately following the label). This is
8395 -- done for the sake of the 'e' or 't' entry generated below.
8397 Get_Decoded_Name_String (Chars (Endl));
8398 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8401 -- Now generate the e/t reference
8403 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8405 -- Restore Sloc, in case modified above, since we have an identifier
8406 -- and the normal Sloc should be left set in the tree.
8408 Set_Sloc (Endl, Loc);
8409 end Process_End_Label;
8415 -- We do the conversion to get the value of the real string by using
8416 -- the scanner, see Sinput for details on use of the internal source
8417 -- buffer for scanning internal strings.
8419 function Real_Convert (S : String) return Node_Id is
8420 Save_Src : constant Source_Buffer_Ptr := Source;
8424 Source := Internal_Source_Ptr;
8427 for J in S'Range loop
8428 Source (Source_Ptr (J)) := S (J);
8431 Source (S'Length + 1) := EOF;
8433 if Source (Scan_Ptr) = '-' then
8435 Scan_Ptr := Scan_Ptr + 1;
8443 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8450 ---------------------
8451 -- Rep_To_Pos_Flag --
8452 ---------------------
8454 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8456 return New_Occurrence_Of
8457 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8458 end Rep_To_Pos_Flag;
8460 --------------------
8461 -- Require_Entity --
8462 --------------------
8464 procedure Require_Entity (N : Node_Id) is
8466 if Is_Entity_Name (N) and then No (Entity (N)) then
8467 if Total_Errors_Detected /= 0 then
8468 Set_Entity (N, Any_Id);
8470 raise Program_Error;
8475 ------------------------------
8476 -- Requires_Transient_Scope --
8477 ------------------------------
8479 -- A transient scope is required when variable-sized temporaries are
8480 -- allocated in the primary or secondary stack, or when finalization
8481 -- actions must be generated before the next instruction.
8483 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8484 Typ : constant Entity_Id := Underlying_Type (Id);
8486 -- Start of processing for Requires_Transient_Scope
8489 -- This is a private type which is not completed yet. This can only
8490 -- happen in a default expression (of a formal parameter or of a
8491 -- record component). Do not expand transient scope in this case
8496 -- Do not expand transient scope for non-existent procedure return
8498 elsif Typ = Standard_Void_Type then
8501 -- Elementary types do not require a transient scope
8503 elsif Is_Elementary_Type (Typ) then
8506 -- Generally, indefinite subtypes require a transient scope, since the
8507 -- back end cannot generate temporaries, since this is not a valid type
8508 -- for declaring an object. It might be possible to relax this in the
8509 -- future, e.g. by declaring the maximum possible space for the type.
8511 elsif Is_Indefinite_Subtype (Typ) then
8514 -- Functions returning tagged types may dispatch on result so their
8515 -- returned value is allocated on the secondary stack. Controlled
8516 -- type temporaries need finalization.
8518 elsif Is_Tagged_Type (Typ)
8519 or else Has_Controlled_Component (Typ)
8521 return not Is_Value_Type (Typ);
8525 elsif Is_Record_Type (Typ) then
8529 Comp := First_Entity (Typ);
8530 while Present (Comp) loop
8531 if Ekind (Comp) = E_Component
8532 and then Requires_Transient_Scope (Etype (Comp))
8543 -- String literal types never require transient scope
8545 elsif Ekind (Typ) = E_String_Literal_Subtype then
8548 -- Array type. Note that we already know that this is a constrained
8549 -- array, since unconstrained arrays will fail the indefinite test.
8551 elsif Is_Array_Type (Typ) then
8553 -- If component type requires a transient scope, the array does too
8555 if Requires_Transient_Scope (Component_Type (Typ)) then
8558 -- Otherwise, we only need a transient scope if the size is not
8559 -- known at compile time.
8562 return not Size_Known_At_Compile_Time (Typ);
8565 -- All other cases do not require a transient scope
8570 end Requires_Transient_Scope;
8572 --------------------------
8573 -- Reset_Analyzed_Flags --
8574 --------------------------
8576 procedure Reset_Analyzed_Flags (N : Node_Id) is
8578 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8579 -- Function used to reset Analyzed flags in tree. Note that we do
8580 -- not reset Analyzed flags in entities, since there is no need to
8581 -- renalalyze entities, and indeed, it is wrong to do so, since it
8582 -- can result in generating auxiliary stuff more than once.
8584 --------------------
8585 -- Clear_Analyzed --
8586 --------------------
8588 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8590 if not Has_Extension (N) then
8591 Set_Analyzed (N, False);
8597 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8599 -- Start of processing for Reset_Analyzed_Flags
8603 end Reset_Analyzed_Flags;
8605 ---------------------------
8606 -- Safe_To_Capture_Value --
8607 ---------------------------
8609 function Safe_To_Capture_Value
8612 Cond : Boolean := False) return Boolean
8615 -- The only entities for which we track constant values are variables
8616 -- which are not renamings, constants, out parameters, and in out
8617 -- parameters, so check if we have this case.
8619 -- Note: it may seem odd to track constant values for constants, but in
8620 -- fact this routine is used for other purposes than simply capturing
8621 -- the value. In particular, the setting of Known[_Non]_Null.
8623 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8625 Ekind (Ent) = E_Constant
8627 Ekind (Ent) = E_Out_Parameter
8629 Ekind (Ent) = E_In_Out_Parameter
8633 -- For conditionals, we also allow loop parameters and all formals,
8634 -- including in parameters.
8638 (Ekind (Ent) = E_Loop_Parameter
8640 Ekind (Ent) = E_In_Parameter)
8644 -- For all other cases, not just unsafe, but impossible to capture
8645 -- Current_Value, since the above are the only entities which have
8646 -- Current_Value fields.
8652 -- Skip if volatile or aliased, since funny things might be going on in
8653 -- these cases which we cannot necessarily track. Also skip any variable
8654 -- for which an address clause is given, or whose address is taken. Also
8655 -- never capture value of library level variables (an attempt to do so
8656 -- can occur in the case of package elaboration code).
8658 if Treat_As_Volatile (Ent)
8659 or else Is_Aliased (Ent)
8660 or else Present (Address_Clause (Ent))
8661 or else Address_Taken (Ent)
8662 or else (Is_Library_Level_Entity (Ent)
8663 and then Ekind (Ent) = E_Variable)
8668 -- OK, all above conditions are met. We also require that the scope of
8669 -- the reference be the same as the scope of the entity, not counting
8670 -- packages and blocks and loops.
8673 E_Scope : constant Entity_Id := Scope (Ent);
8674 R_Scope : Entity_Id;
8677 R_Scope := Current_Scope;
8678 while R_Scope /= Standard_Standard loop
8679 exit when R_Scope = E_Scope;
8681 if Ekind (R_Scope) /= E_Package
8683 Ekind (R_Scope) /= E_Block
8685 Ekind (R_Scope) /= E_Loop
8689 R_Scope := Scope (R_Scope);
8694 -- We also require that the reference does not appear in a context
8695 -- where it is not sure to be executed (i.e. a conditional context
8696 -- or an exception handler). We skip this if Cond is True, since the
8697 -- capturing of values from conditional tests handles this ok.
8711 while Present (P) loop
8712 if Nkind (P) = N_If_Statement
8713 or else Nkind (P) = N_Case_Statement
8714 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8715 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8716 or else Nkind (P) = N_Exception_Handler
8717 or else Nkind (P) = N_Selective_Accept
8718 or else Nkind (P) = N_Conditional_Entry_Call
8719 or else Nkind (P) = N_Timed_Entry_Call
8720 or else Nkind (P) = N_Asynchronous_Select
8730 -- OK, looks safe to set value
8733 end Safe_To_Capture_Value;
8739 function Same_Name (N1, N2 : Node_Id) return Boolean is
8740 K1 : constant Node_Kind := Nkind (N1);
8741 K2 : constant Node_Kind := Nkind (N2);
8744 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8745 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8747 return Chars (N1) = Chars (N2);
8749 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8750 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8752 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8753 and then Same_Name (Prefix (N1), Prefix (N2));
8764 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8765 N1 : constant Node_Id := Original_Node (Node1);
8766 N2 : constant Node_Id := Original_Node (Node2);
8767 -- We do the tests on original nodes, since we are most interested
8768 -- in the original source, not any expansion that got in the way.
8770 K1 : constant Node_Kind := Nkind (N1);
8771 K2 : constant Node_Kind := Nkind (N2);
8774 -- First case, both are entities with same entity
8776 if K1 in N_Has_Entity
8777 and then K2 in N_Has_Entity
8778 and then Present (Entity (N1))
8779 and then Present (Entity (N2))
8780 and then (Ekind (Entity (N1)) = E_Variable
8782 Ekind (Entity (N1)) = E_Constant)
8783 and then Entity (N1) = Entity (N2)
8787 -- Second case, selected component with same selector, same record
8789 elsif K1 = N_Selected_Component
8790 and then K2 = N_Selected_Component
8791 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8793 return Same_Object (Prefix (N1), Prefix (N2));
8795 -- Third case, indexed component with same subscripts, same array
8797 elsif K1 = N_Indexed_Component
8798 and then K2 = N_Indexed_Component
8799 and then Same_Object (Prefix (N1), Prefix (N2))
8804 E1 := First (Expressions (N1));
8805 E2 := First (Expressions (N2));
8806 while Present (E1) loop
8807 if not Same_Value (E1, E2) then
8818 -- Fourth case, slice of same array with same bounds
8821 and then K2 = N_Slice
8822 and then Nkind (Discrete_Range (N1)) = N_Range
8823 and then Nkind (Discrete_Range (N2)) = N_Range
8824 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8825 Low_Bound (Discrete_Range (N2)))
8826 and then Same_Value (High_Bound (Discrete_Range (N1)),
8827 High_Bound (Discrete_Range (N2)))
8829 return Same_Name (Prefix (N1), Prefix (N2));
8831 -- All other cases, not clearly the same object
8842 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8847 elsif not Is_Constrained (T1)
8848 and then not Is_Constrained (T2)
8849 and then Base_Type (T1) = Base_Type (T2)
8853 -- For now don't bother with case of identical constraints, to be
8854 -- fiddled with later on perhaps (this is only used for optimization
8855 -- purposes, so it is not critical to do a best possible job)
8866 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8868 if Compile_Time_Known_Value (Node1)
8869 and then Compile_Time_Known_Value (Node2)
8870 and then Expr_Value (Node1) = Expr_Value (Node2)
8873 elsif Same_Object (Node1, Node2) then
8880 ------------------------
8881 -- Scope_Is_Transient --
8882 ------------------------
8884 function Scope_Is_Transient return Boolean is
8886 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8887 end Scope_Is_Transient;
8893 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8898 while Scop /= Standard_Standard loop
8899 Scop := Scope (Scop);
8901 if Scop = Scope2 then
8909 --------------------------
8910 -- Scope_Within_Or_Same --
8911 --------------------------
8913 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8918 while Scop /= Standard_Standard loop
8919 if Scop = Scope2 then
8922 Scop := Scope (Scop);
8927 end Scope_Within_Or_Same;
8929 --------------------
8930 -- Set_Convention --
8931 --------------------
8933 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
8935 Basic_Set_Convention (E, Val);
8938 and then Is_Access_Subprogram_Type (Base_Type (E))
8939 and then Has_Foreign_Convention (E)
8941 Set_Can_Use_Internal_Rep (E, False);
8945 ------------------------
8946 -- Set_Current_Entity --
8947 ------------------------
8949 -- The given entity is to be set as the currently visible definition
8950 -- of its associated name (i.e. the Node_Id associated with its name).
8951 -- All we have to do is to get the name from the identifier, and
8952 -- then set the associated Node_Id to point to the given entity.
8954 procedure Set_Current_Entity (E : Entity_Id) is
8956 Set_Name_Entity_Id (Chars (E), E);
8957 end Set_Current_Entity;
8959 ---------------------------
8960 -- Set_Debug_Info_Needed --
8961 ---------------------------
8963 procedure Set_Debug_Info_Needed (T : Entity_Id) is
8965 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
8966 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
8967 -- Used to set debug info in a related node if not set already
8969 --------------------------------------
8970 -- Set_Debug_Info_Needed_If_Not_Set --
8971 --------------------------------------
8973 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
8976 and then not Needs_Debug_Info (E)
8978 Set_Debug_Info_Needed (E);
8980 end Set_Debug_Info_Needed_If_Not_Set;
8982 -- Start of processing for Set_Debug_Info_Needed
8985 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
8986 -- indicates that Debug_Info_Needed is never required for the entity.
8989 or else Debug_Info_Off (T)
8994 -- Set flag in entity itself. Note that we will go through the following
8995 -- circuitry even if the flag is already set on T. That's intentional,
8996 -- it makes sure that the flag will be set in subsidiary entities.
8998 Set_Needs_Debug_Info (T);
9000 -- Set flag on subsidiary entities if not set already
9002 if Is_Object (T) then
9003 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9005 elsif Is_Type (T) then
9006 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9008 if Is_Record_Type (T) then
9010 Ent : Entity_Id := First_Entity (T);
9012 while Present (Ent) loop
9013 Set_Debug_Info_Needed_If_Not_Set (Ent);
9018 elsif Is_Array_Type (T) then
9019 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
9022 Indx : Node_Id := First_Index (T);
9024 while Present (Indx) loop
9025 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
9026 Indx := Next_Index (Indx);
9030 if Is_Packed (T) then
9031 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
9034 elsif Is_Access_Type (T) then
9035 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
9037 elsif Is_Private_Type (T) then
9038 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9040 elsif Is_Protected_Type (T) then
9041 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9044 end Set_Debug_Info_Needed;
9046 ---------------------------------
9047 -- Set_Entity_With_Style_Check --
9048 ---------------------------------
9050 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9051 Val_Actual : Entity_Id;
9055 Set_Entity (N, Val);
9058 and then not Suppress_Style_Checks (Val)
9059 and then not In_Instance
9061 if Nkind (N) = N_Identifier then
9063 elsif Nkind (N) = N_Expanded_Name then
9064 Nod := Selector_Name (N);
9069 -- A special situation arises for derived operations, where we want
9070 -- to do the check against the parent (since the Sloc of the derived
9071 -- operation points to the derived type declaration itself).
9074 while not Comes_From_Source (Val_Actual)
9075 and then Nkind (Val_Actual) in N_Entity
9076 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9077 or else Is_Subprogram (Val_Actual)
9078 or else Is_Generic_Subprogram (Val_Actual))
9079 and then Present (Alias (Val_Actual))
9081 Val_Actual := Alias (Val_Actual);
9084 -- Renaming declarations for generic actuals do not come from source,
9085 -- and have a different name from that of the entity they rename, so
9086 -- there is no style check to perform here.
9088 if Chars (Nod) = Chars (Val_Actual) then
9089 Style.Check_Identifier (Nod, Val_Actual);
9093 Set_Entity (N, Val);
9094 end Set_Entity_With_Style_Check;
9096 ------------------------
9097 -- Set_Name_Entity_Id --
9098 ------------------------
9100 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9102 Set_Name_Table_Info (Id, Int (Val));
9103 end Set_Name_Entity_Id;
9105 ---------------------
9106 -- Set_Next_Actual --
9107 ---------------------
9109 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9111 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9112 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9114 end Set_Next_Actual;
9116 -----------------------
9117 -- Set_Public_Status --
9118 -----------------------
9120 procedure Set_Public_Status (Id : Entity_Id) is
9121 S : constant Entity_Id := Current_Scope;
9124 -- Everything in the scope of Standard is public
9126 if S = Standard_Standard then
9129 -- Entity is definitely not public if enclosing scope is not public
9131 elsif not Is_Public (S) then
9134 -- An object declaration that occurs in a handled sequence of statements
9135 -- is the declaration for a temporary object generated by the expander.
9136 -- It never needs to be made public and furthermore, making it public
9137 -- can cause back end problems if it is of variable size.
9139 elsif Nkind (Parent (Id)) = N_Object_Declaration
9141 Nkind (Parent (Parent (Id))) = N_Handled_Sequence_Of_Statements
9145 -- Entities in public packages or records are public
9147 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9150 -- The bounds of an entry family declaration can generate object
9151 -- declarations that are visible to the back-end, e.g. in the
9152 -- the declaration of a composite type that contains tasks.
9154 elsif Is_Concurrent_Type (S)
9155 and then not Has_Completion (S)
9156 and then Nkind (Parent (Id)) = N_Object_Declaration
9160 end Set_Public_Status;
9162 -----------------------------
9163 -- Set_Referenced_Modified --
9164 -----------------------------
9166 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9170 -- Deal with indexed or selected component where prefix is modified
9172 if Nkind (N) = N_Indexed_Component
9174 Nkind (N) = N_Selected_Component
9178 -- If prefix is access type, then it is the designated object that is
9179 -- being modified, which means we have no entity to set the flag on.
9181 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9184 -- Otherwise chase the prefix
9187 Set_Referenced_Modified (Pref, Out_Param);
9190 -- Otherwise see if we have an entity name (only other case to process)
9192 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9193 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9194 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9196 end Set_Referenced_Modified;
9198 ----------------------------
9199 -- Set_Scope_Is_Transient --
9200 ----------------------------
9202 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9204 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9205 end Set_Scope_Is_Transient;
9211 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9213 -- We copy Esize, but not RM_Size, since in general RM_Size is
9214 -- subtype specific and does not get inherited by all subtypes.
9216 Set_Esize (T1, Esize (T2));
9217 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9219 if Is_Discrete_Or_Fixed_Point_Type (T1)
9221 Is_Discrete_Or_Fixed_Point_Type (T2)
9223 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9226 Set_Alignment (T1, Alignment (T2));
9229 --------------------
9230 -- Static_Integer --
9231 --------------------
9233 function Static_Integer (N : Node_Id) return Uint is
9235 Analyze_And_Resolve (N, Any_Integer);
9238 or else Error_Posted (N)
9239 or else Etype (N) = Any_Type
9244 if Is_Static_Expression (N) then
9245 if not Raises_Constraint_Error (N) then
9246 return Expr_Value (N);
9251 elsif Etype (N) = Any_Type then
9255 Flag_Non_Static_Expr
9256 ("static integer expression required here", N);
9261 --------------------------
9262 -- Statically_Different --
9263 --------------------------
9265 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9266 R1 : constant Node_Id := Get_Referenced_Object (E1);
9267 R2 : constant Node_Id := Get_Referenced_Object (E2);
9269 return Is_Entity_Name (R1)
9270 and then Is_Entity_Name (R2)
9271 and then Entity (R1) /= Entity (R2)
9272 and then not Is_Formal (Entity (R1))
9273 and then not Is_Formal (Entity (R2));
9274 end Statically_Different;
9276 -----------------------------
9277 -- Subprogram_Access_Level --
9278 -----------------------------
9280 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9282 if Present (Alias (Subp)) then
9283 return Subprogram_Access_Level (Alias (Subp));
9285 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9287 end Subprogram_Access_Level;
9293 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9295 if Debug_Flag_W then
9296 for J in 0 .. Scope_Stack.Last loop
9301 Write_Name (Chars (E));
9302 Write_Str (" from ");
9303 Write_Location (Sloc (N));
9308 -----------------------
9309 -- Transfer_Entities --
9310 -----------------------
9312 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9313 Ent : Entity_Id := First_Entity (From);
9320 if (Last_Entity (To)) = Empty then
9321 Set_First_Entity (To, Ent);
9323 Set_Next_Entity (Last_Entity (To), Ent);
9326 Set_Last_Entity (To, Last_Entity (From));
9328 while Present (Ent) loop
9329 Set_Scope (Ent, To);
9331 if not Is_Public (Ent) then
9332 Set_Public_Status (Ent);
9335 and then Ekind (Ent) = E_Record_Subtype
9338 -- The components of the propagated Itype must be public
9344 Comp := First_Entity (Ent);
9345 while Present (Comp) loop
9346 Set_Is_Public (Comp);
9356 Set_First_Entity (From, Empty);
9357 Set_Last_Entity (From, Empty);
9358 end Transfer_Entities;
9360 -----------------------
9361 -- Type_Access_Level --
9362 -----------------------
9364 function Type_Access_Level (Typ : Entity_Id) return Uint is
9368 Btyp := Base_Type (Typ);
9370 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9371 -- simply use the level where the type is declared. This is true for
9372 -- stand-alone object declarations, and for anonymous access types
9373 -- associated with components the level is the same as that of the
9374 -- enclosing composite type. However, special treatment is needed for
9375 -- the cases of access parameters, return objects of an anonymous access
9376 -- type, and, in Ada 95, access discriminants of limited types.
9378 if Ekind (Btyp) in Access_Kind then
9379 if Ekind (Btyp) = E_Anonymous_Access_Type then
9381 -- If the type is a nonlocal anonymous access type (such as for
9382 -- an access parameter) we treat it as being declared at the
9383 -- library level to ensure that names such as X.all'access don't
9384 -- fail static accessibility checks.
9386 if not Is_Local_Anonymous_Access (Typ) then
9387 return Scope_Depth (Standard_Standard);
9389 -- If this is a return object, the accessibility level is that of
9390 -- the result subtype of the enclosing function. The test here is
9391 -- little complicated, because we have to account for extended
9392 -- return statements that have been rewritten as blocks, in which
9393 -- case we have to find and the Is_Return_Object attribute of the
9394 -- itype's associated object. It would be nice to find a way to
9395 -- simplify this test, but it doesn't seem worthwhile to add a new
9396 -- flag just for purposes of this test. ???
9398 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9401 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9402 N_Object_Declaration
9403 and then Is_Return_Object
9404 (Defining_Identifier
9405 (Associated_Node_For_Itype (Btyp))))
9411 Scop := Scope (Scope (Btyp));
9412 while Present (Scop) loop
9413 exit when Ekind (Scop) = E_Function;
9414 Scop := Scope (Scop);
9417 -- Treat the return object's type as having the level of the
9418 -- function's result subtype (as per RM05-6.5(5.3/2)).
9420 return Type_Access_Level (Etype (Scop));
9425 Btyp := Root_Type (Btyp);
9427 -- The accessibility level of anonymous acccess types associated with
9428 -- discriminants is that of the current instance of the type, and
9429 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9431 -- AI-402: access discriminants have accessibility based on the
9432 -- object rather than the type in Ada 2005, so the above paragraph
9435 -- ??? Needs completion with rules from AI-416
9437 if Ada_Version <= Ada_95
9438 and then Ekind (Typ) = E_Anonymous_Access_Type
9439 and then Present (Associated_Node_For_Itype (Typ))
9440 and then Nkind (Associated_Node_For_Itype (Typ)) =
9441 N_Discriminant_Specification
9443 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9447 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9448 end Type_Access_Level;
9450 --------------------------
9451 -- Unit_Declaration_Node --
9452 --------------------------
9454 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9455 N : Node_Id := Parent (Unit_Id);
9458 -- Predefined operators do not have a full function declaration
9460 if Ekind (Unit_Id) = E_Operator then
9464 -- Isn't there some better way to express the following ???
9466 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9467 and then Nkind (N) /= N_Formal_Package_Declaration
9468 and then Nkind (N) /= N_Function_Instantiation
9469 and then Nkind (N) /= N_Generic_Package_Declaration
9470 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9471 and then Nkind (N) /= N_Package_Declaration
9472 and then Nkind (N) /= N_Package_Body
9473 and then Nkind (N) /= N_Package_Instantiation
9474 and then Nkind (N) /= N_Package_Renaming_Declaration
9475 and then Nkind (N) /= N_Procedure_Instantiation
9476 and then Nkind (N) /= N_Protected_Body
9477 and then Nkind (N) /= N_Subprogram_Declaration
9478 and then Nkind (N) /= N_Subprogram_Body
9479 and then Nkind (N) /= N_Subprogram_Body_Stub
9480 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9481 and then Nkind (N) /= N_Task_Body
9482 and then Nkind (N) /= N_Task_Type_Declaration
9483 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9484 and then Nkind (N) not in N_Generic_Renaming_Declaration
9487 pragma Assert (Present (N));
9491 end Unit_Declaration_Node;
9493 ------------------------------
9494 -- Universal_Interpretation --
9495 ------------------------------
9497 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9498 Index : Interp_Index;
9502 -- The argument may be a formal parameter of an operator or subprogram
9503 -- with multiple interpretations, or else an expression for an actual.
9505 if Nkind (Opnd) = N_Defining_Identifier
9506 or else not Is_Overloaded (Opnd)
9508 if Etype (Opnd) = Universal_Integer
9509 or else Etype (Opnd) = Universal_Real
9511 return Etype (Opnd);
9517 Get_First_Interp (Opnd, Index, It);
9518 while Present (It.Typ) loop
9519 if It.Typ = Universal_Integer
9520 or else It.Typ = Universal_Real
9525 Get_Next_Interp (Index, It);
9530 end Universal_Interpretation;
9536 function Unqualify (Expr : Node_Id) return Node_Id is
9538 -- Recurse to handle unlikely case of multiple levels of qualification
9540 if Nkind (Expr) = N_Qualified_Expression then
9541 return Unqualify (Expression (Expr));
9543 -- Normal case, not a qualified expression
9550 ----------------------
9551 -- Within_Init_Proc --
9552 ----------------------
9554 function Within_Init_Proc return Boolean is
9559 while not Is_Overloadable (S) loop
9560 if S = Standard_Standard then
9567 return Is_Init_Proc (S);
9568 end Within_Init_Proc;
9574 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9575 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9576 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9578 function Has_One_Matching_Field return Boolean;
9579 -- Determines if Expec_Type is a record type with a single component or
9580 -- discriminant whose type matches the found type or is one dimensional
9581 -- array whose component type matches the found type.
9583 ----------------------------
9584 -- Has_One_Matching_Field --
9585 ----------------------------
9587 function Has_One_Matching_Field return Boolean is
9591 if Is_Array_Type (Expec_Type)
9592 and then Number_Dimensions (Expec_Type) = 1
9594 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9598 elsif not Is_Record_Type (Expec_Type) then
9602 E := First_Entity (Expec_Type);
9607 elsif (Ekind (E) /= E_Discriminant
9608 and then Ekind (E) /= E_Component)
9609 or else (Chars (E) = Name_uTag
9610 or else Chars (E) = Name_uParent)
9619 if not Covers (Etype (E), Found_Type) then
9622 elsif Present (Next_Entity (E)) then
9629 end Has_One_Matching_Field;
9631 -- Start of processing for Wrong_Type
9634 -- Don't output message if either type is Any_Type, or if a message
9635 -- has already been posted for this node. We need to do the latter
9636 -- check explicitly (it is ordinarily done in Errout), because we
9637 -- are using ! to force the output of the error messages.
9639 if Expec_Type = Any_Type
9640 or else Found_Type = Any_Type
9641 or else Error_Posted (Expr)
9645 -- In an instance, there is an ongoing problem with completion of
9646 -- type derived from private types. Their structure is what Gigi
9647 -- expects, but the Etype is the parent type rather than the
9648 -- derived private type itself. Do not flag error in this case. The
9649 -- private completion is an entity without a parent, like an Itype.
9650 -- Similarly, full and partial views may be incorrect in the instance.
9651 -- There is no simple way to insure that it is consistent ???
9653 elsif In_Instance then
9654 if Etype (Etype (Expr)) = Etype (Expected_Type)
9656 (Has_Private_Declaration (Expected_Type)
9657 or else Has_Private_Declaration (Etype (Expr)))
9658 and then No (Parent (Expected_Type))
9664 -- An interesting special check. If the expression is parenthesized
9665 -- and its type corresponds to the type of the sole component of the
9666 -- expected record type, or to the component type of the expected one
9667 -- dimensional array type, then assume we have a bad aggregate attempt.
9669 if Nkind (Expr) in N_Subexpr
9670 and then Paren_Count (Expr) /= 0
9671 and then Has_One_Matching_Field
9673 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9675 -- Another special check, if we are looking for a pool-specific access
9676 -- type and we found an E_Access_Attribute_Type, then we have the case
9677 -- of an Access attribute being used in a context which needs a pool-
9678 -- specific type, which is never allowed. The one extra check we make
9679 -- is that the expected designated type covers the Found_Type.
9681 elsif Is_Access_Type (Expec_Type)
9682 and then Ekind (Found_Type) = E_Access_Attribute_Type
9683 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9684 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9686 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9688 Error_Msg_N ("result must be general access type!", Expr);
9689 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9691 -- Another special check, if the expected type is an integer type,
9692 -- but the expression is of type System.Address, and the parent is
9693 -- an addition or subtraction operation whose left operand is the
9694 -- expression in question and whose right operand is of an integral
9695 -- type, then this is an attempt at address arithmetic, so give
9696 -- appropriate message.
9698 elsif Is_Integer_Type (Expec_Type)
9699 and then Is_RTE (Found_Type, RE_Address)
9700 and then (Nkind (Parent (Expr)) = N_Op_Add
9702 Nkind (Parent (Expr)) = N_Op_Subtract)
9703 and then Expr = Left_Opnd (Parent (Expr))
9704 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9707 ("address arithmetic not predefined in package System",
9710 ("\possible missing with/use of System.Storage_Elements",
9714 -- If the expected type is an anonymous access type, as for access
9715 -- parameters and discriminants, the error is on the designated types.
9717 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9718 if Comes_From_Source (Expec_Type) then
9719 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9722 ("expected an access type with designated}",
9723 Expr, Designated_Type (Expec_Type));
9726 if Is_Access_Type (Found_Type)
9727 and then not Comes_From_Source (Found_Type)
9730 ("\\found an access type with designated}!",
9731 Expr, Designated_Type (Found_Type));
9733 if From_With_Type (Found_Type) then
9734 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9735 Error_Msg_Qual_Level := 99;
9736 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9737 Error_Msg_Qual_Level := 0;
9739 Error_Msg_NE ("found}!", Expr, Found_Type);
9743 -- Normal case of one type found, some other type expected
9746 -- If the names of the two types are the same, see if some number
9747 -- of levels of qualification will help. Don't try more than three
9748 -- levels, and if we get to standard, it's no use (and probably
9749 -- represents an error in the compiler) Also do not bother with
9750 -- internal scope names.
9753 Expec_Scope : Entity_Id;
9754 Found_Scope : Entity_Id;
9757 Expec_Scope := Expec_Type;
9758 Found_Scope := Found_Type;
9760 for Levels in Int range 0 .. 3 loop
9761 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9762 Error_Msg_Qual_Level := Levels;
9766 Expec_Scope := Scope (Expec_Scope);
9767 Found_Scope := Scope (Found_Scope);
9769 exit when Expec_Scope = Standard_Standard
9770 or else Found_Scope = Standard_Standard
9771 or else not Comes_From_Source (Expec_Scope)
9772 or else not Comes_From_Source (Found_Scope);
9776 if Is_Record_Type (Expec_Type)
9777 and then Present (Corresponding_Remote_Type (Expec_Type))
9779 Error_Msg_NE ("expected}!", Expr,
9780 Corresponding_Remote_Type (Expec_Type));
9782 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9785 if Is_Entity_Name (Expr)
9786 and then Is_Package_Or_Generic_Package (Entity (Expr))
9788 Error_Msg_N ("\\found package name!", Expr);
9790 elsif Is_Entity_Name (Expr)
9792 (Ekind (Entity (Expr)) = E_Procedure
9794 Ekind (Entity (Expr)) = E_Generic_Procedure)
9796 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9798 ("found procedure name, possibly missing Access attribute!",
9802 ("\\found procedure name instead of function!", Expr);
9805 elsif Nkind (Expr) = N_Function_Call
9806 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9807 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9808 and then No (Parameter_Associations (Expr))
9811 ("found function name, possibly missing Access attribute!",
9814 -- Catch common error: a prefix or infix operator which is not
9815 -- directly visible because the type isn't.
9817 elsif Nkind (Expr) in N_Op
9818 and then Is_Overloaded (Expr)
9819 and then not Is_Immediately_Visible (Expec_Type)
9820 and then not Is_Potentially_Use_Visible (Expec_Type)
9821 and then not In_Use (Expec_Type)
9822 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9825 ("operator of the type is not directly visible!", Expr);
9827 elsif Ekind (Found_Type) = E_Void
9828 and then Present (Parent (Found_Type))
9829 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9831 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9834 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9837 Error_Msg_Qual_Level := 0;