1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 Snames; use Snames;
54 with Stand; use Stand;
56 with Stringt; use Stringt;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
60 with Uname; use Uname;
62 package body Sem_Util is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 function Build_Component_Subtype
73 T : Entity_Id) return Node_Id;
74 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
75 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
76 -- Loc is the source location, T is the original subtype.
78 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
79 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
80 -- with discriminants whose default values are static, examine only the
81 -- components in the selected variant to determine whether all of them
84 function Has_Null_Extension (T : Entity_Id) return Boolean;
85 -- T is a derived tagged type. Check whether the type extension is null.
86 -- If the parent type is fully initialized, T can be treated as such.
88 ------------------------------
89 -- Abstract_Interface_List --
90 ------------------------------
92 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
96 if Is_Concurrent_Type (Typ) then
98 -- If we are dealing with a synchronized subtype, go to the base
99 -- type, whose declaration has the interface list.
101 -- Shouldn't this be Declaration_Node???
103 Nod := Parent (Base_Type (Typ));
105 elsif Ekind (Typ) = E_Record_Type_With_Private then
106 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
107 Nod := Type_Definition (Parent (Typ));
109 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
110 if Present (Full_View (Typ)) then
111 Nod := Type_Definition (Parent (Full_View (Typ)));
113 -- If the full-view is not available we cannot do anything
114 -- else here (the source has errors)
120 -- The support for generic formals with interfaces is still
123 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
128 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
132 elsif Ekind (Typ) = E_Record_Subtype then
133 Nod := Type_Definition (Parent (Etype (Typ)));
135 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
137 -- Recurse, because parent may still be a private extension
139 return Abstract_Interface_List (Etype (Full_View (Typ)));
141 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
142 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
143 Nod := Formal_Type_Definition (Parent (Typ));
145 Nod := Type_Definition (Parent (Typ));
149 return Interface_List (Nod);
150 end Abstract_Interface_List;
152 --------------------------------
153 -- Add_Access_Type_To_Process --
154 --------------------------------
156 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
160 Ensure_Freeze_Node (E);
161 L := Access_Types_To_Process (Freeze_Node (E));
165 Set_Access_Types_To_Process (Freeze_Node (E), L);
169 end Add_Access_Type_To_Process;
171 ----------------------------
172 -- Add_Global_Declaration --
173 ----------------------------
175 procedure Add_Global_Declaration (N : Node_Id) is
176 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
179 if No (Declarations (Aux_Node)) then
180 Set_Declarations (Aux_Node, New_List);
183 Append_To (Declarations (Aux_Node), N);
185 end Add_Global_Declaration;
187 -----------------------
188 -- Alignment_In_Bits --
189 -----------------------
191 function Alignment_In_Bits (E : Entity_Id) return Uint is
193 return Alignment (E) * System_Storage_Unit;
194 end Alignment_In_Bits;
196 -----------------------------------------
197 -- Apply_Compile_Time_Constraint_Error --
198 -----------------------------------------
200 procedure Apply_Compile_Time_Constraint_Error
203 Reason : RT_Exception_Code;
204 Ent : Entity_Id := Empty;
205 Typ : Entity_Id := Empty;
206 Loc : Source_Ptr := No_Location;
207 Rep : Boolean := True;
208 Warn : Boolean := False)
210 Stat : constant Boolean := Is_Static_Expression (N);
221 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
227 -- Now we replace the node by an N_Raise_Constraint_Error node
228 -- This does not need reanalyzing, so set it as analyzed now.
231 Make_Raise_Constraint_Error (Sloc (N),
233 Set_Analyzed (N, True);
235 Set_Raises_Constraint_Error (N);
237 -- If the original expression was marked as static, the result is
238 -- still marked as static, but the Raises_Constraint_Error flag is
239 -- always set so that further static evaluation is not attempted.
242 Set_Is_Static_Expression (N);
244 end Apply_Compile_Time_Constraint_Error;
246 --------------------------
247 -- Build_Actual_Subtype --
248 --------------------------
250 function Build_Actual_Subtype
252 N : Node_Or_Entity_Id) return Node_Id
255 -- Normally Sloc (N), but may point to corresponding body in some cases
257 Constraints : List_Id;
263 Disc_Type : Entity_Id;
269 if Nkind (N) = N_Defining_Identifier then
270 Obj := New_Reference_To (N, Loc);
272 -- If this is a formal parameter of a subprogram declaration, and
273 -- we are compiling the body, we want the declaration for the
274 -- actual subtype to carry the source position of the body, to
275 -- prevent anomalies in gdb when stepping through the code.
277 if Is_Formal (N) then
279 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
281 if Nkind (Decl) = N_Subprogram_Declaration
282 and then Present (Corresponding_Body (Decl))
284 Loc := Sloc (Corresponding_Body (Decl));
293 if Is_Array_Type (T) then
294 Constraints := New_List;
295 for J in 1 .. Number_Dimensions (T) loop
297 -- Build an array subtype declaration with the nominal subtype and
298 -- the bounds of the actual. Add the declaration in front of the
299 -- local declarations for the subprogram, for analysis before any
300 -- reference to the formal in the body.
303 Make_Attribute_Reference (Loc,
305 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
306 Attribute_Name => Name_First,
307 Expressions => New_List (
308 Make_Integer_Literal (Loc, J)));
311 Make_Attribute_Reference (Loc,
313 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
314 Attribute_Name => Name_Last,
315 Expressions => New_List (
316 Make_Integer_Literal (Loc, J)));
318 Append (Make_Range (Loc, Lo, Hi), Constraints);
321 -- If the type has unknown discriminants there is no constrained
322 -- subtype to build. This is never called for a formal or for a
323 -- lhs, so returning the type is ok ???
325 elsif Has_Unknown_Discriminants (T) then
329 Constraints := New_List;
331 if Is_Private_Type (T) and then No (Full_View (T)) then
333 -- Type is a generic derived type. Inherit discriminants from
336 Disc_Type := Etype (Base_Type (T));
341 Discr := First_Discriminant (Disc_Type);
342 while Present (Discr) loop
343 Append_To (Constraints,
344 Make_Selected_Component (Loc,
346 Duplicate_Subexpr_No_Checks (Obj),
347 Selector_Name => New_Occurrence_Of (Discr, Loc)));
348 Next_Discriminant (Discr);
353 Make_Defining_Identifier (Loc,
354 Chars => New_Internal_Name ('S'));
355 Set_Is_Internal (Subt);
358 Make_Subtype_Declaration (Loc,
359 Defining_Identifier => Subt,
360 Subtype_Indication =>
361 Make_Subtype_Indication (Loc,
362 Subtype_Mark => New_Reference_To (T, Loc),
364 Make_Index_Or_Discriminant_Constraint (Loc,
365 Constraints => Constraints)));
367 Mark_Rewrite_Insertion (Decl);
369 end Build_Actual_Subtype;
371 ---------------------------------------
372 -- Build_Actual_Subtype_Of_Component --
373 ---------------------------------------
375 function Build_Actual_Subtype_Of_Component
377 N : Node_Id) return Node_Id
379 Loc : constant Source_Ptr := Sloc (N);
380 P : constant Node_Id := Prefix (N);
383 Indx_Type : Entity_Id;
385 Deaccessed_T : Entity_Id;
386 -- This is either a copy of T, or if T is an access type, then it is
387 -- the directly designated type of this access type.
389 function Build_Actual_Array_Constraint return List_Id;
390 -- If one or more of the bounds of the component depends on
391 -- discriminants, build actual constraint using the discriminants
394 function Build_Actual_Record_Constraint return List_Id;
395 -- Similar to previous one, for discriminated components constrained
396 -- by the discriminant of the enclosing object.
398 -----------------------------------
399 -- Build_Actual_Array_Constraint --
400 -----------------------------------
402 function Build_Actual_Array_Constraint return List_Id is
403 Constraints : constant List_Id := New_List;
411 Indx := First_Index (Deaccessed_T);
412 while Present (Indx) loop
413 Old_Lo := Type_Low_Bound (Etype (Indx));
414 Old_Hi := Type_High_Bound (Etype (Indx));
416 if Denotes_Discriminant (Old_Lo) then
418 Make_Selected_Component (Loc,
419 Prefix => New_Copy_Tree (P),
420 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
423 Lo := New_Copy_Tree (Old_Lo);
425 -- The new bound will be reanalyzed in the enclosing
426 -- declaration. For literal bounds that come from a type
427 -- declaration, the type of the context must be imposed, so
428 -- insure that analysis will take place. For non-universal
429 -- types this is not strictly necessary.
431 Set_Analyzed (Lo, False);
434 if Denotes_Discriminant (Old_Hi) then
436 Make_Selected_Component (Loc,
437 Prefix => New_Copy_Tree (P),
438 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
441 Hi := New_Copy_Tree (Old_Hi);
442 Set_Analyzed (Hi, False);
445 Append (Make_Range (Loc, Lo, Hi), Constraints);
450 end Build_Actual_Array_Constraint;
452 ------------------------------------
453 -- Build_Actual_Record_Constraint --
454 ------------------------------------
456 function Build_Actual_Record_Constraint return List_Id is
457 Constraints : constant List_Id := New_List;
462 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
463 while Present (D) loop
464 if Denotes_Discriminant (Node (D)) then
465 D_Val := Make_Selected_Component (Loc,
466 Prefix => New_Copy_Tree (P),
467 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
470 D_Val := New_Copy_Tree (Node (D));
473 Append (D_Val, Constraints);
478 end Build_Actual_Record_Constraint;
480 -- Start of processing for Build_Actual_Subtype_Of_Component
483 if In_Default_Expression then
486 elsif Nkind (N) = N_Explicit_Dereference then
487 if Is_Composite_Type (T)
488 and then not Is_Constrained (T)
489 and then not (Is_Class_Wide_Type (T)
490 and then Is_Constrained (Root_Type (T)))
491 and then not Has_Unknown_Discriminants (T)
493 -- If the type of the dereference is already constrained, it
494 -- is an actual subtype.
496 if Is_Array_Type (Etype (N))
497 and then Is_Constrained (Etype (N))
501 Remove_Side_Effects (P);
502 return Build_Actual_Subtype (T, N);
509 if Ekind (T) = E_Access_Subtype then
510 Deaccessed_T := Designated_Type (T);
515 if Ekind (Deaccessed_T) = E_Array_Subtype then
516 Id := First_Index (Deaccessed_T);
517 while Present (Id) loop
518 Indx_Type := Underlying_Type (Etype (Id));
520 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
521 Denotes_Discriminant (Type_High_Bound (Indx_Type))
523 Remove_Side_Effects (P);
525 Build_Component_Subtype (
526 Build_Actual_Array_Constraint, Loc, Base_Type (T));
532 elsif Is_Composite_Type (Deaccessed_T)
533 and then Has_Discriminants (Deaccessed_T)
534 and then not Has_Unknown_Discriminants (Deaccessed_T)
536 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
537 while Present (D) loop
538 if Denotes_Discriminant (Node (D)) then
539 Remove_Side_Effects (P);
541 Build_Component_Subtype (
542 Build_Actual_Record_Constraint, Loc, Base_Type (T));
549 -- If none of the above, the actual and nominal subtypes are the same
552 end Build_Actual_Subtype_Of_Component;
554 -----------------------------
555 -- Build_Component_Subtype --
556 -----------------------------
558 function Build_Component_Subtype
561 T : Entity_Id) return Node_Id
567 -- Unchecked_Union components do not require component subtypes
569 if Is_Unchecked_Union (T) then
574 Make_Defining_Identifier (Loc,
575 Chars => New_Internal_Name ('S'));
576 Set_Is_Internal (Subt);
579 Make_Subtype_Declaration (Loc,
580 Defining_Identifier => Subt,
581 Subtype_Indication =>
582 Make_Subtype_Indication (Loc,
583 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
585 Make_Index_Or_Discriminant_Constraint (Loc,
588 Mark_Rewrite_Insertion (Decl);
590 end Build_Component_Subtype;
592 ---------------------------
593 -- Build_Default_Subtype --
594 ---------------------------
596 function Build_Default_Subtype
598 N : Node_Id) return Entity_Id
600 Loc : constant Source_Ptr := Sloc (N);
604 if not Has_Discriminants (T) or else Is_Constrained (T) then
608 Disc := First_Discriminant (T);
610 if No (Discriminant_Default_Value (Disc)) then
615 Act : constant Entity_Id :=
616 Make_Defining_Identifier (Loc,
617 Chars => New_Internal_Name ('S'));
619 Constraints : constant List_Id := New_List;
623 while Present (Disc) loop
624 Append_To (Constraints,
625 New_Copy_Tree (Discriminant_Default_Value (Disc)));
626 Next_Discriminant (Disc);
630 Make_Subtype_Declaration (Loc,
631 Defining_Identifier => Act,
632 Subtype_Indication =>
633 Make_Subtype_Indication (Loc,
634 Subtype_Mark => New_Occurrence_Of (T, Loc),
636 Make_Index_Or_Discriminant_Constraint (Loc,
637 Constraints => Constraints)));
639 Insert_Action (N, Decl);
643 end Build_Default_Subtype;
645 --------------------------------------------
646 -- Build_Discriminal_Subtype_Of_Component --
647 --------------------------------------------
649 function Build_Discriminal_Subtype_Of_Component
650 (T : Entity_Id) return Node_Id
652 Loc : constant Source_Ptr := Sloc (T);
656 function Build_Discriminal_Array_Constraint return List_Id;
657 -- If one or more of the bounds of the component depends on
658 -- discriminants, build actual constraint using the discriminants
661 function Build_Discriminal_Record_Constraint return List_Id;
662 -- Similar to previous one, for discriminated components constrained
663 -- by the discriminant of the enclosing object.
665 ----------------------------------------
666 -- Build_Discriminal_Array_Constraint --
667 ----------------------------------------
669 function Build_Discriminal_Array_Constraint return List_Id is
670 Constraints : constant List_Id := New_List;
678 Indx := First_Index (T);
679 while Present (Indx) loop
680 Old_Lo := Type_Low_Bound (Etype (Indx));
681 Old_Hi := Type_High_Bound (Etype (Indx));
683 if Denotes_Discriminant (Old_Lo) then
684 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
687 Lo := New_Copy_Tree (Old_Lo);
690 if Denotes_Discriminant (Old_Hi) then
691 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
694 Hi := New_Copy_Tree (Old_Hi);
697 Append (Make_Range (Loc, Lo, Hi), Constraints);
702 end Build_Discriminal_Array_Constraint;
704 -----------------------------------------
705 -- Build_Discriminal_Record_Constraint --
706 -----------------------------------------
708 function Build_Discriminal_Record_Constraint return List_Id is
709 Constraints : constant List_Id := New_List;
714 D := First_Elmt (Discriminant_Constraint (T));
715 while Present (D) loop
716 if Denotes_Discriminant (Node (D)) then
718 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
721 D_Val := New_Copy_Tree (Node (D));
724 Append (D_Val, Constraints);
729 end Build_Discriminal_Record_Constraint;
731 -- Start of processing for Build_Discriminal_Subtype_Of_Component
734 if Ekind (T) = E_Array_Subtype then
735 Id := First_Index (T);
736 while Present (Id) loop
737 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
738 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
740 return Build_Component_Subtype
741 (Build_Discriminal_Array_Constraint, Loc, T);
747 elsif Ekind (T) = E_Record_Subtype
748 and then Has_Discriminants (T)
749 and then not Has_Unknown_Discriminants (T)
751 D := First_Elmt (Discriminant_Constraint (T));
752 while Present (D) loop
753 if Denotes_Discriminant (Node (D)) then
754 return Build_Component_Subtype
755 (Build_Discriminal_Record_Constraint, Loc, T);
762 -- If none of the above, the actual and nominal subtypes are the same
765 end Build_Discriminal_Subtype_Of_Component;
767 ------------------------------
768 -- Build_Elaboration_Entity --
769 ------------------------------
771 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
772 Loc : constant Source_Ptr := Sloc (N);
774 Elab_Ent : Entity_Id;
776 procedure Set_Package_Name (Ent : Entity_Id);
777 -- Given an entity, sets the fully qualified name of the entity in
778 -- Name_Buffer, with components separated by double underscores. This
779 -- is a recursive routine that climbs the scope chain to Standard.
781 ----------------------
782 -- Set_Package_Name --
783 ----------------------
785 procedure Set_Package_Name (Ent : Entity_Id) is
787 if Scope (Ent) /= Standard_Standard then
788 Set_Package_Name (Scope (Ent));
791 Nam : constant String := Get_Name_String (Chars (Ent));
793 Name_Buffer (Name_Len + 1) := '_';
794 Name_Buffer (Name_Len + 2) := '_';
795 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
796 Name_Len := Name_Len + Nam'Length + 2;
800 Get_Name_String (Chars (Ent));
802 end Set_Package_Name;
804 -- Start of processing for Build_Elaboration_Entity
807 -- Ignore if already constructed
809 if Present (Elaboration_Entity (Spec_Id)) then
813 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
814 -- name with dots replaced by double underscore. We have to manually
815 -- construct this name, since it will be elaborated in the outer scope,
816 -- and thus will not have the unit name automatically prepended.
818 Set_Package_Name (Spec_Id);
822 Name_Buffer (Name_Len + 1) := '_';
823 Name_Buffer (Name_Len + 2) := 'E';
824 Name_Len := Name_Len + 2;
826 -- Create elaboration flag
829 Make_Defining_Identifier (Loc, Chars => Name_Find);
830 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
833 Make_Object_Declaration (Loc,
834 Defining_Identifier => Elab_Ent,
836 New_Occurrence_Of (Standard_Boolean, Loc),
838 New_Occurrence_Of (Standard_False, Loc));
840 Push_Scope (Standard_Standard);
841 Add_Global_Declaration (Decl);
844 -- Reset True_Constant indication, since we will indeed assign a value
845 -- to the variable in the binder main. We also kill the Current_Value
846 -- and Last_Assignment fields for the same reason.
848 Set_Is_True_Constant (Elab_Ent, False);
849 Set_Current_Value (Elab_Ent, Empty);
850 Set_Last_Assignment (Elab_Ent, Empty);
852 -- We do not want any further qualification of the name (if we did
853 -- not do this, we would pick up the name of the generic package
854 -- in the case of a library level generic instantiation).
856 Set_Has_Qualified_Name (Elab_Ent);
857 Set_Has_Fully_Qualified_Name (Elab_Ent);
858 end Build_Elaboration_Entity;
860 -----------------------------------
861 -- Cannot_Raise_Constraint_Error --
862 -----------------------------------
864 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
866 if Compile_Time_Known_Value (Expr) then
869 elsif Do_Range_Check (Expr) then
872 elsif Raises_Constraint_Error (Expr) then
880 when N_Expanded_Name =>
883 when N_Selected_Component =>
884 return not Do_Discriminant_Check (Expr);
886 when N_Attribute_Reference =>
887 if Do_Overflow_Check (Expr) then
890 elsif No (Expressions (Expr)) then
898 N := First (Expressions (Expr));
899 while Present (N) loop
900 if Cannot_Raise_Constraint_Error (N) then
911 when N_Type_Conversion =>
912 if Do_Overflow_Check (Expr)
913 or else Do_Length_Check (Expr)
914 or else Do_Tag_Check (Expr)
919 Cannot_Raise_Constraint_Error (Expression (Expr));
922 when N_Unchecked_Type_Conversion =>
923 return Cannot_Raise_Constraint_Error (Expression (Expr));
926 if Do_Overflow_Check (Expr) then
930 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
937 if Do_Division_Check (Expr)
938 or else Do_Overflow_Check (Expr)
943 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
945 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
964 N_Op_Shift_Right_Arithmetic |
968 if Do_Overflow_Check (Expr) then
972 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
974 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
981 end Cannot_Raise_Constraint_Error;
983 --------------------------
984 -- Check_Fully_Declared --
985 --------------------------
987 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
989 if Ekind (T) = E_Incomplete_Type then
991 -- Ada 2005 (AI-50217): If the type is available through a limited
992 -- with_clause, verify that its full view has been analyzed.
994 if From_With_Type (T)
995 and then Present (Non_Limited_View (T))
996 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
998 -- The non-limited view is fully declared
1003 ("premature usage of incomplete}", N, First_Subtype (T));
1006 elsif Has_Private_Component (T)
1007 and then not Is_Generic_Type (Root_Type (T))
1008 and then not In_Default_Expression
1011 -- Special case: if T is the anonymous type created for a single
1012 -- task or protected object, use the name of the source object.
1014 if Is_Concurrent_Type (T)
1015 and then not Comes_From_Source (T)
1016 and then Nkind (N) = N_Object_Declaration
1018 Error_Msg_NE ("type of& has incomplete component", N,
1019 Defining_Identifier (N));
1023 ("premature usage of incomplete}", N, First_Subtype (T));
1026 end Check_Fully_Declared;
1028 -------------------------
1029 -- Check_Nested_Access --
1030 -------------------------
1032 procedure Check_Nested_Access (Ent : Entity_Id) is
1033 Scop : constant Entity_Id := Current_Scope;
1034 Current_Subp : Entity_Id;
1037 -- Currently only enabled for VM back-ends for efficiency, should we
1038 -- enable it more systematically ???
1040 if VM_Target /= No_VM
1041 and then (Ekind (Ent) = E_Variable
1043 Ekind (Ent) = E_Constant
1045 Ekind (Ent) = E_Loop_Parameter)
1046 and then Scope (Ent) /= Empty
1047 and then not Is_Library_Level_Entity (Ent)
1049 if Is_Subprogram (Scop)
1050 or else Is_Generic_Subprogram (Scop)
1051 or else Is_Entry (Scop)
1053 Current_Subp := Scop;
1055 Current_Subp := Current_Subprogram;
1058 if Enclosing_Subprogram (Ent) /= Current_Subp then
1059 Set_Has_Up_Level_Access (Ent, True);
1062 end Check_Nested_Access;
1064 ------------------------------------------
1065 -- Check_Potentially_Blocking_Operation --
1066 ------------------------------------------
1068 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1071 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1072 -- When pragma Detect_Blocking is active, the run time will raise
1073 -- Program_Error. Here we only issue a warning, since we generally
1074 -- support the use of potentially blocking operations in the absence
1077 -- Indirect blocking through a subprogram call cannot be diagnosed
1078 -- statically without interprocedural analysis, so we do not attempt
1081 S := Scope (Current_Scope);
1082 while Present (S) and then S /= Standard_Standard loop
1083 if Is_Protected_Type (S) then
1085 ("potentially blocking operation in protected operation?", N);
1092 end Check_Potentially_Blocking_Operation;
1098 procedure Check_VMS (Construct : Node_Id) is
1100 if not OpenVMS_On_Target then
1102 ("this construct is allowed only in Open'V'M'S", Construct);
1106 ---------------------------------
1107 -- Collect_Abstract_Interfaces --
1108 ---------------------------------
1110 procedure Collect_Abstract_Interfaces
1112 Ifaces_List : out Elist_Id;
1113 Exclude_Parent_Interfaces : Boolean := False;
1114 Use_Full_View : Boolean := True)
1116 procedure Add_Interface (Iface : Entity_Id);
1117 -- Add the interface it if is not already in the list
1119 procedure Collect (Typ : Entity_Id);
1120 -- Subsidiary subprogram used to traverse the whole list
1121 -- of directly and indirectly implemented interfaces
1123 function Interface_Present_In_Parent
1125 Iface : Entity_Id) return Boolean;
1126 -- Typ must be a tagged record type/subtype and Iface must be an
1127 -- abstract interface type. This function is used to check if Typ
1128 -- or some parent of Typ implements Iface.
1134 procedure Add_Interface (Iface : Entity_Id) is
1138 Elmt := First_Elmt (Ifaces_List);
1139 while Present (Elmt) and then Node (Elmt) /= Iface loop
1144 Append_Elmt (Iface, Ifaces_List);
1152 procedure Collect (Typ : Entity_Id) is
1153 Ancestor : Entity_Id;
1155 Iface_List : List_Id;
1162 -- Handle private types
1165 and then Is_Private_Type (Typ)
1166 and then Present (Full_View (Typ))
1168 Full_T := Full_View (Typ);
1171 Iface_List := Abstract_Interface_List (Full_T);
1173 -- Include the ancestor if we are generating the whole list of
1174 -- abstract interfaces.
1176 -- In concurrent types the ancestor interface (if any) is the
1177 -- first element of the list of interface types.
1179 if Is_Concurrent_Type (Full_T)
1180 or else Is_Concurrent_Record_Type (Full_T)
1182 if Is_Non_Empty_List (Iface_List) then
1183 Ancestor := Etype (First (Iface_List));
1186 if not Exclude_Parent_Interfaces then
1187 Add_Interface (Ancestor);
1191 elsif Etype (Full_T) /= Typ
1193 -- Protect the frontend against wrong sources. For example:
1196 -- type A is tagged null record;
1197 -- type B is new A with private;
1198 -- type C is new A with private;
1200 -- type B is new C with null record;
1201 -- type C is new B with null record;
1204 and then Etype (Full_T) /= T
1206 Ancestor := Etype (Full_T);
1209 if Is_Interface (Ancestor)
1210 and then not Exclude_Parent_Interfaces
1212 Add_Interface (Ancestor);
1216 -- Traverse the graph of ancestor interfaces
1218 if Is_Non_Empty_List (Iface_List) then
1219 Id := First (Iface_List);
1221 -- In concurrent types the ancestor interface (if any) is the
1222 -- first element of the list of interface types and we have
1223 -- already processed them while climbing to the root type.
1225 if Is_Concurrent_Type (Full_T)
1226 or else Is_Concurrent_Record_Type (Full_T)
1231 while Present (Id) loop
1232 Iface := Etype (Id);
1234 -- Protect against wrong uses. For example:
1235 -- type I is interface;
1236 -- type O is tagged null record;
1237 -- type Wrong is new I and O with null record; -- ERROR
1239 if Is_Interface (Iface) then
1240 if Exclude_Parent_Interfaces
1241 and then Interface_Present_In_Parent (T, Iface)
1246 Add_Interface (Iface);
1255 ---------------------------------
1256 -- Interface_Present_In_Parent --
1257 ---------------------------------
1259 function Interface_Present_In_Parent
1261 Iface : Entity_Id) return Boolean
1263 Aux : Entity_Id := Typ;
1264 Iface_List : List_Id;
1267 if Is_Concurrent_Type (Typ)
1268 or else Is_Concurrent_Record_Type (Typ)
1270 Iface_List := Abstract_Interface_List (Typ);
1272 if Is_Non_Empty_List (Iface_List) then
1273 Aux := Etype (First (Iface_List));
1279 return Interface_Present_In_Ancestor (Aux, Iface);
1280 end Interface_Present_In_Parent;
1282 -- Start of processing for Collect_Abstract_Interfaces
1285 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1286 Ifaces_List := New_Elmt_List;
1288 end Collect_Abstract_Interfaces;
1290 ----------------------------------
1291 -- Collect_Interface_Components --
1292 ----------------------------------
1294 procedure Collect_Interface_Components
1295 (Tagged_Type : Entity_Id;
1296 Components_List : out Elist_Id)
1298 procedure Collect (Typ : Entity_Id);
1299 -- Subsidiary subprogram used to climb to the parents
1305 procedure Collect (Typ : Entity_Id) is
1306 Tag_Comp : Entity_Id;
1309 if Etype (Typ) /= Typ
1311 -- Protect the frontend against wrong sources. For example:
1314 -- type A is tagged null record;
1315 -- type B is new A with private;
1316 -- type C is new A with private;
1318 -- type B is new C with null record;
1319 -- type C is new B with null record;
1322 and then Etype (Typ) /= Tagged_Type
1324 Collect (Etype (Typ));
1327 -- Collect the components containing tags of secondary dispatch
1330 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1331 while Present (Tag_Comp) loop
1332 pragma Assert (Present (Related_Interface (Tag_Comp)));
1333 Append_Elmt (Tag_Comp, Components_List);
1335 Tag_Comp := Next_Tag_Component (Tag_Comp);
1339 -- Start of processing for Collect_Interface_Components
1342 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1343 and then Is_Tagged_Type (Tagged_Type));
1345 Components_List := New_Elmt_List;
1346 Collect (Tagged_Type);
1347 end Collect_Interface_Components;
1349 -----------------------------
1350 -- Collect_Interfaces_Info --
1351 -----------------------------
1353 procedure Collect_Interfaces_Info
1355 Ifaces_List : out Elist_Id;
1356 Components_List : out Elist_Id;
1357 Tags_List : out Elist_Id)
1359 Comps_List : Elist_Id;
1360 Comp_Elmt : Elmt_Id;
1361 Comp_Iface : Entity_Id;
1362 Iface_Elmt : Elmt_Id;
1365 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1366 -- Search for the secondary tag associated with the interface type
1367 -- Iface that is implemented by T.
1373 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1377 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1379 and then Ekind (Node (ADT)) = E_Constant
1380 and then Related_Interface (Node (ADT)) /= Iface
1385 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1389 -- Start of processing for Collect_Interfaces_Info
1392 Collect_Abstract_Interfaces (T, Ifaces_List);
1393 Collect_Interface_Components (T, Comps_List);
1395 -- Search for the record component and tag associated with each
1396 -- interface type of T.
1398 Components_List := New_Elmt_List;
1399 Tags_List := New_Elmt_List;
1401 Iface_Elmt := First_Elmt (Ifaces_List);
1402 while Present (Iface_Elmt) loop
1403 Iface := Node (Iface_Elmt);
1405 -- Associate the primary tag component and the primary dispatch table
1406 -- with all the interfaces that are parents of T
1408 if Is_Parent (Iface, T) then
1409 Append_Elmt (First_Tag_Component (T), Components_List);
1410 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1412 -- Otherwise search for the tag component and secondary dispatch
1416 Comp_Elmt := First_Elmt (Comps_List);
1417 while Present (Comp_Elmt) loop
1418 Comp_Iface := Related_Interface (Node (Comp_Elmt));
1420 if Comp_Iface = Iface
1421 or else Is_Parent (Iface, Comp_Iface)
1423 Append_Elmt (Node (Comp_Elmt), Components_List);
1424 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1428 Next_Elmt (Comp_Elmt);
1430 pragma Assert (Present (Comp_Elmt));
1433 Next_Elmt (Iface_Elmt);
1435 end Collect_Interfaces_Info;
1437 ----------------------------------
1438 -- Collect_Primitive_Operations --
1439 ----------------------------------
1441 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1442 B_Type : constant Entity_Id := Base_Type (T);
1443 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1444 B_Scope : Entity_Id := Scope (B_Type);
1448 Formal_Derived : Boolean := False;
1452 -- For tagged types, the primitive operations are collected as they
1453 -- are declared, and held in an explicit list which is simply returned.
1455 if Is_Tagged_Type (B_Type) then
1456 return Primitive_Operations (B_Type);
1458 -- An untagged generic type that is a derived type inherits the
1459 -- primitive operations of its parent type. Other formal types only
1460 -- have predefined operators, which are not explicitly represented.
1462 elsif Is_Generic_Type (B_Type) then
1463 if Nkind (B_Decl) = N_Formal_Type_Declaration
1464 and then Nkind (Formal_Type_Definition (B_Decl))
1465 = N_Formal_Derived_Type_Definition
1467 Formal_Derived := True;
1469 return New_Elmt_List;
1473 Op_List := New_Elmt_List;
1475 if B_Scope = Standard_Standard then
1476 if B_Type = Standard_String then
1477 Append_Elmt (Standard_Op_Concat, Op_List);
1479 elsif B_Type = Standard_Wide_String then
1480 Append_Elmt (Standard_Op_Concatw, Op_List);
1486 elsif (Is_Package_Or_Generic_Package (B_Scope)
1488 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1490 or else Is_Derived_Type (B_Type)
1492 -- The primitive operations appear after the base type, except
1493 -- if the derivation happens within the private part of B_Scope
1494 -- and the type is a private type, in which case both the type
1495 -- and some primitive operations may appear before the base
1496 -- type, and the list of candidates starts after the type.
1498 if In_Open_Scopes (B_Scope)
1499 and then Scope (T) = B_Scope
1500 and then In_Private_Part (B_Scope)
1502 Id := Next_Entity (T);
1504 Id := Next_Entity (B_Type);
1507 while Present (Id) loop
1509 -- Note that generic formal subprograms are not
1510 -- considered to be primitive operations and thus
1511 -- are never inherited.
1513 if Is_Overloadable (Id)
1514 and then Nkind (Parent (Parent (Id)))
1515 not in N_Formal_Subprogram_Declaration
1519 if Base_Type (Etype (Id)) = B_Type then
1522 Formal := First_Formal (Id);
1523 while Present (Formal) loop
1524 if Base_Type (Etype (Formal)) = B_Type then
1528 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1530 (Designated_Type (Etype (Formal))) = B_Type
1536 Next_Formal (Formal);
1540 -- For a formal derived type, the only primitives are the
1541 -- ones inherited from the parent type. Operations appearing
1542 -- in the package declaration are not primitive for it.
1545 and then (not Formal_Derived
1546 or else Present (Alias (Id)))
1548 Append_Elmt (Id, Op_List);
1554 -- For a type declared in System, some of its operations
1555 -- may appear in the target-specific extension to System.
1558 and then Chars (B_Scope) = Name_System
1559 and then Scope (B_Scope) = Standard_Standard
1560 and then Present_System_Aux
1562 B_Scope := System_Aux_Id;
1563 Id := First_Entity (System_Aux_Id);
1569 end Collect_Primitive_Operations;
1571 -----------------------------------
1572 -- Compile_Time_Constraint_Error --
1573 -----------------------------------
1575 function Compile_Time_Constraint_Error
1578 Ent : Entity_Id := Empty;
1579 Loc : Source_Ptr := No_Location;
1580 Warn : Boolean := False) return Node_Id
1582 Msgc : String (1 .. Msg'Length + 2);
1583 -- Copy of message, with room for possible ? and ! at end
1593 -- A static constraint error in an instance body is not a fatal error.
1594 -- we choose to inhibit the message altogether, because there is no
1595 -- obvious node (for now) on which to post it. On the other hand the
1596 -- offending node must be replaced with a constraint_error in any case.
1598 -- No messages are generated if we already posted an error on this node
1600 if not Error_Posted (N) then
1601 if Loc /= No_Location then
1607 Msgc (1 .. Msg'Length) := Msg;
1610 -- Message is a warning, even in Ada 95 case
1612 if Msg (Msg'Last) = '?' then
1615 -- In Ada 83, all messages are warnings. In the private part and
1616 -- the body of an instance, constraint_checks are only warnings.
1617 -- We also make this a warning if the Warn parameter is set.
1620 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1626 elsif In_Instance_Not_Visible then
1631 -- Otherwise we have a real error message (Ada 95 static case)
1632 -- and we make this an unconditional message. Note that in the
1633 -- warning case we do not make the message unconditional, it seems
1634 -- quite reasonable to delete messages like this (about exceptions
1635 -- that will be raised) in dead code.
1643 -- Should we generate a warning? The answer is not quite yes. The
1644 -- very annoying exception occurs in the case of a short circuit
1645 -- operator where the left operand is static and decisive. Climb
1646 -- parents to see if that is the case we have here. Conditional
1647 -- expressions with decisive conditions are a similar situation.
1655 -- And then with False as left operand
1657 if Nkind (P) = N_And_Then
1658 and then Compile_Time_Known_Value (Left_Opnd (P))
1659 and then Is_False (Expr_Value (Left_Opnd (P)))
1664 -- OR ELSE with True as left operand
1666 elsif Nkind (P) = N_Or_Else
1667 and then Compile_Time_Known_Value (Left_Opnd (P))
1668 and then Is_True (Expr_Value (Left_Opnd (P)))
1673 -- Conditional expression
1675 elsif Nkind (P) = N_Conditional_Expression then
1677 Cond : constant Node_Id := First (Expressions (P));
1678 Texp : constant Node_Id := Next (Cond);
1679 Fexp : constant Node_Id := Next (Texp);
1682 if Compile_Time_Known_Value (Cond) then
1684 -- Condition is True and we are in the right operand
1686 if Is_True (Expr_Value (Cond))
1687 and then OldP = Fexp
1692 -- Condition is False and we are in the left operand
1694 elsif Is_False (Expr_Value (Cond))
1695 and then OldP = Texp
1703 -- Special case for component association in aggregates, where
1704 -- we want to keep climbing up to the parent aggregate.
1706 elsif Nkind (P) = N_Component_Association
1707 and then Nkind (Parent (P)) = N_Aggregate
1711 -- Keep going if within subexpression
1714 exit when Nkind (P) not in N_Subexpr;
1719 if Present (Ent) then
1720 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1722 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1726 if Inside_Init_Proc then
1728 ("\?& will be raised for objects of this type",
1729 N, Standard_Constraint_Error, Eloc);
1732 ("\?& will be raised at run time",
1733 N, Standard_Constraint_Error, Eloc);
1738 ("\static expression fails Constraint_Check", Eloc);
1739 Set_Error_Posted (N);
1745 end Compile_Time_Constraint_Error;
1747 -----------------------
1748 -- Conditional_Delay --
1749 -----------------------
1751 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1753 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1754 Set_Has_Delayed_Freeze (New_Ent);
1756 end Conditional_Delay;
1758 --------------------
1759 -- Current_Entity --
1760 --------------------
1762 -- The currently visible definition for a given identifier is the
1763 -- one most chained at the start of the visibility chain, i.e. the
1764 -- one that is referenced by the Node_Id value of the name of the
1765 -- given identifier.
1767 function Current_Entity (N : Node_Id) return Entity_Id is
1769 return Get_Name_Entity_Id (Chars (N));
1772 -----------------------------
1773 -- Current_Entity_In_Scope --
1774 -----------------------------
1776 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1778 CS : constant Entity_Id := Current_Scope;
1780 Transient_Case : constant Boolean := Scope_Is_Transient;
1783 E := Get_Name_Entity_Id (Chars (N));
1785 and then Scope (E) /= CS
1786 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1792 end Current_Entity_In_Scope;
1798 function Current_Scope return Entity_Id is
1800 if Scope_Stack.Last = -1 then
1801 return Standard_Standard;
1804 C : constant Entity_Id :=
1805 Scope_Stack.Table (Scope_Stack.Last).Entity;
1810 return Standard_Standard;
1816 ------------------------
1817 -- Current_Subprogram --
1818 ------------------------
1820 function Current_Subprogram return Entity_Id is
1821 Scop : constant Entity_Id := Current_Scope;
1824 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1827 return Enclosing_Subprogram (Scop);
1829 end Current_Subprogram;
1831 ---------------------
1832 -- Defining_Entity --
1833 ---------------------
1835 function Defining_Entity (N : Node_Id) return Entity_Id is
1836 K : constant Node_Kind := Nkind (N);
1837 Err : Entity_Id := Empty;
1842 N_Subprogram_Declaration |
1843 N_Abstract_Subprogram_Declaration |
1845 N_Package_Declaration |
1846 N_Subprogram_Renaming_Declaration |
1847 N_Subprogram_Body_Stub |
1848 N_Generic_Subprogram_Declaration |
1849 N_Generic_Package_Declaration |
1850 N_Formal_Subprogram_Declaration
1852 return Defining_Entity (Specification (N));
1855 N_Component_Declaration |
1856 N_Defining_Program_Unit_Name |
1857 N_Discriminant_Specification |
1859 N_Entry_Declaration |
1860 N_Entry_Index_Specification |
1861 N_Exception_Declaration |
1862 N_Exception_Renaming_Declaration |
1863 N_Formal_Object_Declaration |
1864 N_Formal_Package_Declaration |
1865 N_Formal_Type_Declaration |
1866 N_Full_Type_Declaration |
1867 N_Implicit_Label_Declaration |
1868 N_Incomplete_Type_Declaration |
1869 N_Loop_Parameter_Specification |
1870 N_Number_Declaration |
1871 N_Object_Declaration |
1872 N_Object_Renaming_Declaration |
1873 N_Package_Body_Stub |
1874 N_Parameter_Specification |
1875 N_Private_Extension_Declaration |
1876 N_Private_Type_Declaration |
1878 N_Protected_Body_Stub |
1879 N_Protected_Type_Declaration |
1880 N_Single_Protected_Declaration |
1881 N_Single_Task_Declaration |
1882 N_Subtype_Declaration |
1885 N_Task_Type_Declaration
1887 return Defining_Identifier (N);
1890 return Defining_Entity (Proper_Body (N));
1893 N_Function_Instantiation |
1894 N_Function_Specification |
1895 N_Generic_Function_Renaming_Declaration |
1896 N_Generic_Package_Renaming_Declaration |
1897 N_Generic_Procedure_Renaming_Declaration |
1899 N_Package_Instantiation |
1900 N_Package_Renaming_Declaration |
1901 N_Package_Specification |
1902 N_Procedure_Instantiation |
1903 N_Procedure_Specification
1906 Nam : constant Node_Id := Defining_Unit_Name (N);
1909 if Nkind (Nam) in N_Entity then
1912 -- For Error, make up a name and attach to declaration
1913 -- so we can continue semantic analysis
1915 elsif Nam = Error then
1917 Make_Defining_Identifier (Sloc (N),
1918 Chars => New_Internal_Name ('T'));
1919 Set_Defining_Unit_Name (N, Err);
1922 -- If not an entity, get defining identifier
1925 return Defining_Identifier (Nam);
1929 when N_Block_Statement =>
1930 return Entity (Identifier (N));
1933 raise Program_Error;
1936 end Defining_Entity;
1938 --------------------------
1939 -- Denotes_Discriminant --
1940 --------------------------
1942 function Denotes_Discriminant
1944 Check_Concurrent : Boolean := False) return Boolean
1948 if not Is_Entity_Name (N)
1949 or else No (Entity (N))
1956 -- If we are checking for a protected type, the discriminant may have
1957 -- been rewritten as the corresponding discriminal of the original type
1958 -- or of the corresponding concurrent record, depending on whether we
1959 -- are in the spec or body of the protected type.
1961 return Ekind (E) = E_Discriminant
1964 and then Ekind (E) = E_In_Parameter
1965 and then Present (Discriminal_Link (E))
1967 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
1969 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1971 end Denotes_Discriminant;
1973 -----------------------------
1974 -- Depends_On_Discriminant --
1975 -----------------------------
1977 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1982 Get_Index_Bounds (N, L, H);
1983 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1984 end Depends_On_Discriminant;
1986 -------------------------
1987 -- Designate_Same_Unit --
1988 -------------------------
1990 function Designate_Same_Unit
1992 Name2 : Node_Id) return Boolean
1994 K1 : constant Node_Kind := Nkind (Name1);
1995 K2 : constant Node_Kind := Nkind (Name2);
1997 function Prefix_Node (N : Node_Id) return Node_Id;
1998 -- Returns the parent unit name node of a defining program unit name
1999 -- or the prefix if N is a selected component or an expanded name.
2001 function Select_Node (N : Node_Id) return Node_Id;
2002 -- Returns the defining identifier node of a defining program unit
2003 -- name or the selector node if N is a selected component or an
2010 function Prefix_Node (N : Node_Id) return Node_Id is
2012 if Nkind (N) = N_Defining_Program_Unit_Name then
2024 function Select_Node (N : Node_Id) return Node_Id is
2026 if Nkind (N) = N_Defining_Program_Unit_Name then
2027 return Defining_Identifier (N);
2030 return Selector_Name (N);
2034 -- Start of processing for Designate_Next_Unit
2037 if (K1 = N_Identifier or else
2038 K1 = N_Defining_Identifier)
2040 (K2 = N_Identifier or else
2041 K2 = N_Defining_Identifier)
2043 return Chars (Name1) = Chars (Name2);
2046 (K1 = N_Expanded_Name or else
2047 K1 = N_Selected_Component or else
2048 K1 = N_Defining_Program_Unit_Name)
2050 (K2 = N_Expanded_Name or else
2051 K2 = N_Selected_Component or else
2052 K2 = N_Defining_Program_Unit_Name)
2055 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2057 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2062 end Designate_Same_Unit;
2064 ----------------------------
2065 -- Enclosing_Generic_Body --
2066 ----------------------------
2068 function Enclosing_Generic_Body
2069 (N : Node_Id) return Node_Id
2077 while Present (P) loop
2078 if Nkind (P) = N_Package_Body
2079 or else Nkind (P) = N_Subprogram_Body
2081 Spec := Corresponding_Spec (P);
2083 if Present (Spec) then
2084 Decl := Unit_Declaration_Node (Spec);
2086 if Nkind (Decl) = N_Generic_Package_Declaration
2087 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2098 end Enclosing_Generic_Body;
2100 ----------------------------
2101 -- Enclosing_Generic_Unit --
2102 ----------------------------
2104 function Enclosing_Generic_Unit
2105 (N : Node_Id) return Node_Id
2113 while Present (P) loop
2114 if Nkind (P) = N_Generic_Package_Declaration
2115 or else Nkind (P) = N_Generic_Subprogram_Declaration
2119 elsif Nkind (P) = N_Package_Body
2120 or else Nkind (P) = N_Subprogram_Body
2122 Spec := Corresponding_Spec (P);
2124 if Present (Spec) then
2125 Decl := Unit_Declaration_Node (Spec);
2127 if Nkind (Decl) = N_Generic_Package_Declaration
2128 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2139 end Enclosing_Generic_Unit;
2141 -------------------------------
2142 -- Enclosing_Lib_Unit_Entity --
2143 -------------------------------
2145 function Enclosing_Lib_Unit_Entity return Entity_Id is
2146 Unit_Entity : Entity_Id;
2149 -- Look for enclosing library unit entity by following scope links.
2150 -- Equivalent to, but faster than indexing through the scope stack.
2152 Unit_Entity := Current_Scope;
2153 while (Present (Scope (Unit_Entity))
2154 and then Scope (Unit_Entity) /= Standard_Standard)
2155 and not Is_Child_Unit (Unit_Entity)
2157 Unit_Entity := Scope (Unit_Entity);
2161 end Enclosing_Lib_Unit_Entity;
2163 -----------------------------
2164 -- Enclosing_Lib_Unit_Node --
2165 -----------------------------
2167 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2168 Current_Node : Node_Id;
2172 while Present (Current_Node)
2173 and then Nkind (Current_Node) /= N_Compilation_Unit
2175 Current_Node := Parent (Current_Node);
2178 if Nkind (Current_Node) /= N_Compilation_Unit then
2182 return Current_Node;
2183 end Enclosing_Lib_Unit_Node;
2185 --------------------------
2186 -- Enclosing_Subprogram --
2187 --------------------------
2189 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2190 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2193 if Dynamic_Scope = Standard_Standard then
2196 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2197 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2199 elsif Ekind (Dynamic_Scope) = E_Block
2200 or else Ekind (Dynamic_Scope) = E_Return_Statement
2202 return Enclosing_Subprogram (Dynamic_Scope);
2204 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2205 return Get_Task_Body_Procedure (Dynamic_Scope);
2207 elsif Convention (Dynamic_Scope) = Convention_Protected then
2208 return Protected_Body_Subprogram (Dynamic_Scope);
2211 return Dynamic_Scope;
2213 end Enclosing_Subprogram;
2215 ------------------------
2216 -- Ensure_Freeze_Node --
2217 ------------------------
2219 procedure Ensure_Freeze_Node (E : Entity_Id) is
2223 if No (Freeze_Node (E)) then
2224 FN := Make_Freeze_Entity (Sloc (E));
2225 Set_Has_Delayed_Freeze (E);
2226 Set_Freeze_Node (E, FN);
2227 Set_Access_Types_To_Process (FN, No_Elist);
2228 Set_TSS_Elist (FN, No_Elist);
2231 end Ensure_Freeze_Node;
2237 procedure Enter_Name (Def_Id : Entity_Id) is
2238 C : constant Entity_Id := Current_Entity (Def_Id);
2239 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2240 S : constant Entity_Id := Current_Scope;
2242 function Is_Private_Component_Renaming (N : Node_Id) return Boolean;
2243 -- Recognize a renaming declaration that is introduced for private
2244 -- components of a protected type. We treat these as weak declarations
2245 -- so that they are overridden by entities with the same name that
2246 -- come from source, such as formals or local variables of a given
2247 -- protected declaration.
2249 -----------------------------------
2250 -- Is_Private_Component_Renaming --
2251 -----------------------------------
2253 function Is_Private_Component_Renaming (N : Node_Id) return Boolean is
2255 return not Comes_From_Source (N)
2256 and then not Comes_From_Source (Current_Scope)
2257 and then Nkind (N) = N_Object_Renaming_Declaration;
2258 end Is_Private_Component_Renaming;
2260 -- Start of processing for Enter_Name
2263 Generate_Definition (Def_Id);
2265 -- Add new name to current scope declarations. Check for duplicate
2266 -- declaration, which may or may not be a genuine error.
2270 -- Case of previous entity entered because of a missing declaration
2271 -- or else a bad subtype indication. Best is to use the new entity,
2272 -- and make the previous one invisible.
2274 if Etype (E) = Any_Type then
2275 Set_Is_Immediately_Visible (E, False);
2277 -- Case of renaming declaration constructed for package instances.
2278 -- if there is an explicit declaration with the same identifier,
2279 -- the renaming is not immediately visible any longer, but remains
2280 -- visible through selected component notation.
2282 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2283 and then not Comes_From_Source (E)
2285 Set_Is_Immediately_Visible (E, False);
2287 -- The new entity may be the package renaming, which has the same
2288 -- same name as a generic formal which has been seen already.
2290 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2291 and then not Comes_From_Source (Def_Id)
2293 Set_Is_Immediately_Visible (E, False);
2295 -- For a fat pointer corresponding to a remote access to subprogram,
2296 -- we use the same identifier as the RAS type, so that the proper
2297 -- name appears in the stub. This type is only retrieved through
2298 -- the RAS type and never by visibility, and is not added to the
2299 -- visibility list (see below).
2301 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2302 and then Present (Corresponding_Remote_Type (Def_Id))
2306 -- A controller component for a type extension overrides the
2307 -- inherited component.
2309 elsif Chars (E) = Name_uController then
2312 -- Case of an implicit operation or derived literal. The new entity
2313 -- hides the implicit one, which is removed from all visibility,
2314 -- i.e. the entity list of its scope, and homonym chain of its name.
2316 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2317 or else Is_Internal (E)
2321 Prev_Vis : Entity_Id;
2322 Decl : constant Node_Id := Parent (E);
2325 -- If E is an implicit declaration, it cannot be the first
2326 -- entity in the scope.
2328 Prev := First_Entity (Current_Scope);
2329 while Present (Prev)
2330 and then Next_Entity (Prev) /= E
2337 -- If E is not on the entity chain of the current scope,
2338 -- it is an implicit declaration in the generic formal
2339 -- part of a generic subprogram. When analyzing the body,
2340 -- the generic formals are visible but not on the entity
2341 -- chain of the subprogram. The new entity will become
2342 -- the visible one in the body.
2345 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2349 Set_Next_Entity (Prev, Next_Entity (E));
2351 if No (Next_Entity (Prev)) then
2352 Set_Last_Entity (Current_Scope, Prev);
2355 if E = Current_Entity (E) then
2359 Prev_Vis := Current_Entity (E);
2360 while Homonym (Prev_Vis) /= E loop
2361 Prev_Vis := Homonym (Prev_Vis);
2365 if Present (Prev_Vis) then
2367 -- Skip E in the visibility chain
2369 Set_Homonym (Prev_Vis, Homonym (E));
2372 Set_Name_Entity_Id (Chars (E), Homonym (E));
2377 -- This section of code could use a comment ???
2379 elsif Present (Etype (E))
2380 and then Is_Concurrent_Type (Etype (E))
2385 elsif Is_Private_Component_Renaming (Parent (Def_Id)) then
2388 -- In the body or private part of an instance, a type extension
2389 -- may introduce a component with the same name as that of an
2390 -- actual. The legality rule is not enforced, but the semantics
2391 -- of the full type with two components of the same name are not
2392 -- clear at this point ???
2394 elsif In_Instance_Not_Visible then
2397 -- When compiling a package body, some child units may have become
2398 -- visible. They cannot conflict with local entities that hide them.
2400 elsif Is_Child_Unit (E)
2401 and then In_Open_Scopes (Scope (E))
2402 and then not Is_Immediately_Visible (E)
2406 -- Conversely, with front-end inlining we may compile the parent
2407 -- body first, and a child unit subsequently. The context is now
2408 -- the parent spec, and body entities are not visible.
2410 elsif Is_Child_Unit (Def_Id)
2411 and then Is_Package_Body_Entity (E)
2412 and then not In_Package_Body (Current_Scope)
2416 -- Case of genuine duplicate declaration
2419 Error_Msg_Sloc := Sloc (E);
2421 -- If the previous declaration is an incomplete type declaration
2422 -- this may be an attempt to complete it with a private type.
2423 -- The following avoids confusing cascaded errors.
2425 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2426 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2429 ("incomplete type cannot be completed" &
2430 " with a private declaration",
2432 Set_Is_Immediately_Visible (E, False);
2433 Set_Full_View (E, Def_Id);
2435 elsif Ekind (E) = E_Discriminant
2436 and then Present (Scope (Def_Id))
2437 and then Scope (Def_Id) /= Current_Scope
2439 -- An inherited component of a record conflicts with
2440 -- a new discriminant. The discriminant is inserted first
2441 -- in the scope, but the error should be posted on it, not
2442 -- on the component.
2444 Error_Msg_Sloc := Sloc (Def_Id);
2445 Error_Msg_N ("& conflicts with declaration#", E);
2448 -- If the name of the unit appears in its own context clause,
2449 -- a dummy package with the name has already been created, and
2450 -- the error emitted. Try to continue quietly.
2452 elsif Error_Posted (E)
2453 and then Sloc (E) = No_Location
2454 and then Nkind (Parent (E)) = N_Package_Specification
2455 and then Current_Scope = Standard_Standard
2457 Set_Scope (Def_Id, Current_Scope);
2461 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2463 -- Avoid cascaded messages with duplicate components in
2466 if Ekind (E) = E_Component
2467 or else Ekind (E) = E_Discriminant
2473 if Nkind (Parent (Parent (Def_Id)))
2474 = N_Generic_Subprogram_Declaration
2476 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2478 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2481 -- If entity is in standard, then we are in trouble, because
2482 -- it means that we have a library package with a duplicated
2483 -- name. That's hard to recover from, so abort!
2485 if S = Standard_Standard then
2486 raise Unrecoverable_Error;
2488 -- Otherwise we continue with the declaration. Having two
2489 -- identical declarations should not cause us too much trouble!
2497 -- If we fall through, declaration is OK , or OK enough to continue
2499 -- If Def_Id is a discriminant or a record component we are in the
2500 -- midst of inheriting components in a derived record definition.
2501 -- Preserve their Ekind and Etype.
2503 if Ekind (Def_Id) = E_Discriminant
2504 or else Ekind (Def_Id) = E_Component
2508 -- If a type is already set, leave it alone (happens whey a type
2509 -- declaration is reanalyzed following a call to the optimizer)
2511 elsif Present (Etype (Def_Id)) then
2514 -- Otherwise, the kind E_Void insures that premature uses of the entity
2515 -- will be detected. Any_Type insures that no cascaded errors will occur
2518 Set_Ekind (Def_Id, E_Void);
2519 Set_Etype (Def_Id, Any_Type);
2522 -- Inherited discriminants and components in derived record types are
2523 -- immediately visible. Itypes are not.
2525 if Ekind (Def_Id) = E_Discriminant
2526 or else Ekind (Def_Id) = E_Component
2527 or else (No (Corresponding_Remote_Type (Def_Id))
2528 and then not Is_Itype (Def_Id))
2530 Set_Is_Immediately_Visible (Def_Id);
2531 Set_Current_Entity (Def_Id);
2534 Set_Homonym (Def_Id, C);
2535 Append_Entity (Def_Id, S);
2536 Set_Public_Status (Def_Id);
2538 -- Warn if new entity hides an old one
2540 if Warn_On_Hiding and then Present (C)
2542 -- Don't warn for record components since they always have a well
2543 -- defined scope which does not confuse other uses. Note that in
2544 -- some cases, Ekind has not been set yet.
2546 and then Ekind (C) /= E_Component
2547 and then Ekind (C) /= E_Discriminant
2548 and then Nkind (Parent (C)) /= N_Component_Declaration
2549 and then Ekind (Def_Id) /= E_Component
2550 and then Ekind (Def_Id) /= E_Discriminant
2551 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2553 -- Don't warn for one character variables. It is too common to use
2554 -- such variables as locals and will just cause too many false hits.
2556 and then Length_Of_Name (Chars (C)) /= 1
2558 -- Don't warn for non-source eneities
2560 and then Comes_From_Source (C)
2561 and then Comes_From_Source (Def_Id)
2563 -- Don't warn unless entity in question is in extended main source
2565 and then In_Extended_Main_Source_Unit (Def_Id)
2567 -- Finally, the hidden entity must be either immediately visible
2568 -- or use visible (from a used package)
2571 (Is_Immediately_Visible (C)
2573 Is_Potentially_Use_Visible (C))
2575 Error_Msg_Sloc := Sloc (C);
2576 Error_Msg_N ("declaration hides &#?", Def_Id);
2580 --------------------------
2581 -- Explain_Limited_Type --
2582 --------------------------
2584 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2588 -- For array, component type must be limited
2590 if Is_Array_Type (T) then
2591 Error_Msg_Node_2 := T;
2593 ("\component type& of type& is limited", N, Component_Type (T));
2594 Explain_Limited_Type (Component_Type (T), N);
2596 elsif Is_Record_Type (T) then
2598 -- No need for extra messages if explicit limited record
2600 if Is_Limited_Record (Base_Type (T)) then
2604 -- Otherwise find a limited component. Check only components that
2605 -- come from source, or inherited components that appear in the
2606 -- source of the ancestor.
2608 C := First_Component (T);
2609 while Present (C) loop
2610 if Is_Limited_Type (Etype (C))
2612 (Comes_From_Source (C)
2614 (Present (Original_Record_Component (C))
2616 Comes_From_Source (Original_Record_Component (C))))
2618 Error_Msg_Node_2 := T;
2619 Error_Msg_NE ("\component& of type& has limited type", N, C);
2620 Explain_Limited_Type (Etype (C), N);
2627 -- The type may be declared explicitly limited, even if no component
2628 -- of it is limited, in which case we fall out of the loop.
2631 end Explain_Limited_Type;
2633 -------------------------------------
2634 -- Find_Corresponding_Discriminant --
2635 -------------------------------------
2637 function Find_Corresponding_Discriminant
2639 Typ : Entity_Id) return Entity_Id
2641 Par_Disc : Entity_Id;
2642 Old_Disc : Entity_Id;
2643 New_Disc : Entity_Id;
2646 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2648 -- The original type may currently be private, and the discriminant
2649 -- only appear on its full view.
2651 if Is_Private_Type (Scope (Par_Disc))
2652 and then not Has_Discriminants (Scope (Par_Disc))
2653 and then Present (Full_View (Scope (Par_Disc)))
2655 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2657 Old_Disc := First_Discriminant (Scope (Par_Disc));
2660 if Is_Class_Wide_Type (Typ) then
2661 New_Disc := First_Discriminant (Root_Type (Typ));
2663 New_Disc := First_Discriminant (Typ);
2666 while Present (Old_Disc) and then Present (New_Disc) loop
2667 if Old_Disc = Par_Disc then
2670 Next_Discriminant (Old_Disc);
2671 Next_Discriminant (New_Disc);
2675 -- Should always find it
2677 raise Program_Error;
2678 end Find_Corresponding_Discriminant;
2680 --------------------------------------------
2681 -- Find_Overridden_Synchronized_Primitive --
2682 --------------------------------------------
2684 function Find_Overridden_Synchronized_Primitive
2685 (Def_Id : Entity_Id;
2686 First_Hom : Entity_Id;
2687 Ifaces_List : Elist_Id;
2688 In_Scope : Boolean) return Entity_Id
2690 Candidate : Entity_Id := Empty;
2691 Hom : Entity_Id := Empty;
2692 Iface_Typ : Entity_Id;
2693 Subp : Entity_Id := Empty;
2694 Tag_Typ : Entity_Id;
2696 function Find_Parameter_Type (Param : Node_Id) return Entity_Id;
2697 -- Return the type of a formal parameter as determined by its
2700 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
2701 -- For an overridden subprogram Subp, check whether the mode of its
2702 -- first parameter is correct depending on the kind of Tag_Typ.
2704 function Matches_Prefixed_View_Profile
2705 (Prim_Params : List_Id;
2706 Iface_Params : List_Id) return Boolean;
2707 -- Determine whether a subprogram's parameter profile Prim_Params
2708 -- matches that of a potentially overriden interface subprogram
2709 -- Iface_Params. Also determine if the type of first parameter of
2710 -- Iface_Params is an implemented interface.
2712 -------------------------
2713 -- Find_Parameter_Type --
2714 -------------------------
2716 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2718 pragma Assert (Nkind (Param) = N_Parameter_Specification);
2720 if Nkind (Parameter_Type (Param)) = N_Access_Definition then
2721 return Etype (Subtype_Mark (Parameter_Type (Param)));
2724 return Etype (Parameter_Type (Param));
2726 end Find_Parameter_Type;
2728 -----------------------------
2729 -- Has_Correct_Formal_Mode --
2730 -----------------------------
2732 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
2736 Param := First_Formal (Subp);
2738 -- In order for an entry or a protected procedure to override, the
2739 -- first parameter of the overridden routine must be of mode "out",
2740 -- "in out" or access-to-variable.
2742 if (Ekind (Subp) = E_Entry
2743 or else Ekind (Subp) = E_Procedure)
2744 and then Is_Protected_Type (Tag_Typ)
2745 and then Ekind (Param) /= E_In_Out_Parameter
2746 and then Ekind (Param) /= E_Out_Parameter
2747 and then Nkind (Parameter_Type (Parent (Param))) /=
2753 -- All other cases are OK since a task entry or routine does not
2754 -- have a restriction on the mode of the first parameter of the
2755 -- overridden interface routine.
2758 end Has_Correct_Formal_Mode;
2760 -----------------------------------
2761 -- Matches_Prefixed_View_Profile --
2762 -----------------------------------
2764 function Matches_Prefixed_View_Profile
2765 (Prim_Params : List_Id;
2766 Iface_Params : List_Id) return Boolean
2768 Iface_Id : Entity_Id;
2769 Iface_Param : Node_Id;
2770 Iface_Typ : Entity_Id;
2771 Prim_Id : Entity_Id;
2772 Prim_Param : Node_Id;
2773 Prim_Typ : Entity_Id;
2775 function Is_Implemented (Iface : Entity_Id) return Boolean;
2776 -- Determine if Iface is implemented by the current task or
2779 --------------------
2780 -- Is_Implemented --
2781 --------------------
2783 function Is_Implemented (Iface : Entity_Id) return Boolean is
2784 Iface_Elmt : Elmt_Id;
2787 Iface_Elmt := First_Elmt (Ifaces_List);
2788 while Present (Iface_Elmt) loop
2789 if Node (Iface_Elmt) = Iface then
2793 Next_Elmt (Iface_Elmt);
2799 -- Start of processing for Matches_Prefixed_View_Profile
2802 Iface_Param := First (Iface_Params);
2803 Iface_Typ := Find_Parameter_Type (Iface_Param);
2804 Prim_Param := First (Prim_Params);
2806 -- The first parameter of the potentially overriden subprogram
2807 -- must be an interface implemented by Prim.
2809 if not Is_Interface (Iface_Typ)
2810 or else not Is_Implemented (Iface_Typ)
2815 -- The checks on the object parameters are done, move onto the rest
2816 -- of the parameters.
2818 if not In_Scope then
2819 Prim_Param := Next (Prim_Param);
2822 Iface_Param := Next (Iface_Param);
2823 while Present (Iface_Param) and then Present (Prim_Param) loop
2824 Iface_Id := Defining_Identifier (Iface_Param);
2825 Iface_Typ := Find_Parameter_Type (Iface_Param);
2826 Prim_Id := Defining_Identifier (Prim_Param);
2827 Prim_Typ := Find_Parameter_Type (Prim_Param);
2829 -- Case of multiple interface types inside a parameter profile
2831 -- (Obj_Param : in out Iface; ...; Param : Iface)
2833 -- If the interface type is implemented, then the matching type
2834 -- in the primitive should be the implementing record type.
2836 if Ekind (Iface_Typ) = E_Record_Type
2837 and then Is_Interface (Iface_Typ)
2838 and then Is_Implemented (Iface_Typ)
2840 if Prim_Typ /= Tag_Typ then
2844 -- The two parameters must be both mode and subtype conformant
2846 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
2848 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
2857 -- One of the two lists contains more parameters than the other
2859 if Present (Iface_Param) or else Present (Prim_Param) then
2864 end Matches_Prefixed_View_Profile;
2866 -- Start of processing for Find_Overridden_Synchronized_Primitive
2869 -- At this point the caller should have collected the interfaces
2870 -- implemented by the synchronized type.
2872 pragma Assert (Present (Ifaces_List));
2874 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2875 -- subprogram was declared within a protected or a task type, the type
2876 -- is the scope itself, otherwise it is the type of the first parameter.
2879 Tag_Typ := Scope (Def_Id);
2881 elsif Present (First_Formal (Def_Id)) then
2882 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
2884 -- A parameterless subprogram which is declared outside a synchronized
2885 -- type cannot act as a primitive, thus it cannot override anything.
2891 -- Traverse the homonym chain, looking at a potentially overriden
2892 -- subprogram that belongs to an implemented interface.
2895 while Present (Hom) loop
2898 -- Entries can override abstract or null interface procedures
2900 if Ekind (Def_Id) = E_Entry
2901 and then Ekind (Subp) = E_Procedure
2902 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2903 and then (Is_Abstract_Subprogram (Subp)
2904 or else Null_Present (Parent (Subp)))
2906 while Present (Alias (Subp)) loop
2907 Subp := Alias (Subp);
2910 if Matches_Prefixed_View_Profile
2911 (Parameter_Specifications (Parent (Def_Id)),
2912 Parameter_Specifications (Parent (Subp)))
2918 if Has_Correct_Formal_Mode (Candidate) then
2923 -- Procedures can override abstract or null interface procedures
2925 elsif Ekind (Def_Id) = E_Procedure
2926 and then Ekind (Subp) = E_Procedure
2927 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2928 and then (Is_Abstract_Subprogram (Subp)
2929 or else Null_Present (Parent (Subp)))
2930 and then Matches_Prefixed_View_Profile
2931 (Parameter_Specifications (Parent (Def_Id)),
2932 Parameter_Specifications (Parent (Subp)))
2938 if Has_Correct_Formal_Mode (Candidate) then
2942 -- Functions can override abstract interface functions
2944 elsif Ekind (Def_Id) = E_Function
2945 and then Ekind (Subp) = E_Function
2946 and then Nkind (Parent (Subp)) = N_Function_Specification
2947 and then Is_Abstract_Subprogram (Subp)
2948 and then Matches_Prefixed_View_Profile
2949 (Parameter_Specifications (Parent (Def_Id)),
2950 Parameter_Specifications (Parent (Subp)))
2951 and then Etype (Result_Definition (Parent (Def_Id))) =
2952 Etype (Result_Definition (Parent (Subp)))
2957 Hom := Homonym (Hom);
2960 -- After examining all candidates for overriding, we are left with
2961 -- the best match which is a mode incompatible interface routine.
2962 -- Do not emit an error if the Expander is active since this error
2963 -- will be detected later on after all concurrent types are expanded
2964 -- and all wrappers are built. This check is meant for spec-only
2967 if Present (Candidate)
2968 and then not Expander_Active
2970 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
2972 -- Def_Id is primitive of a protected type, declared inside the type,
2973 -- and the candidate is primitive of a limited or synchronized
2977 and then Is_Protected_Type (Tag_Typ)
2979 (Is_Limited_Interface (Iface_Typ)
2980 or else Is_Protected_Interface (Iface_Typ)
2981 or else Is_Synchronized_Interface (Iface_Typ)
2982 or else Is_Task_Interface (Iface_Typ))
2984 -- Must reword this message, comma before to in -gnatj mode ???
2987 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
2988 "access-to-variable", Tag_Typ, Candidate);
2990 ("\to be overridden by protected procedure or entry " &
2991 "(RM 9.4(11.9/2))", Tag_Typ);
2996 end Find_Overridden_Synchronized_Primitive;
2998 -----------------------------
2999 -- Find_Static_Alternative --
3000 -----------------------------
3002 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3003 Expr : constant Node_Id := Expression (N);
3004 Val : constant Uint := Expr_Value (Expr);
3009 Alt := First (Alternatives (N));
3012 if Nkind (Alt) /= N_Pragma then
3013 Choice := First (Discrete_Choices (Alt));
3014 while Present (Choice) loop
3016 -- Others choice, always matches
3018 if Nkind (Choice) = N_Others_Choice then
3021 -- Range, check if value is in the range
3023 elsif Nkind (Choice) = N_Range then
3025 Val >= Expr_Value (Low_Bound (Choice))
3027 Val <= Expr_Value (High_Bound (Choice));
3029 -- Choice is a subtype name. Note that we know it must
3030 -- be a static subtype, since otherwise it would have
3031 -- been diagnosed as illegal.
3033 elsif Is_Entity_Name (Choice)
3034 and then Is_Type (Entity (Choice))
3036 exit Search when Is_In_Range (Expr, Etype (Choice));
3038 -- Choice is a subtype indication
3040 elsif Nkind (Choice) = N_Subtype_Indication then
3042 C : constant Node_Id := Constraint (Choice);
3043 R : constant Node_Id := Range_Expression (C);
3047 Val >= Expr_Value (Low_Bound (R))
3049 Val <= Expr_Value (High_Bound (R));
3052 -- Choice is a simple expression
3055 exit Search when Val = Expr_Value (Choice);
3063 pragma Assert (Present (Alt));
3066 -- The above loop *must* terminate by finding a match, since
3067 -- we know the case statement is valid, and the value of the
3068 -- expression is known at compile time. When we fall out of
3069 -- the loop, Alt points to the alternative that we know will
3070 -- be selected at run time.
3073 end Find_Static_Alternative;
3079 function First_Actual (Node : Node_Id) return Node_Id is
3083 if No (Parameter_Associations (Node)) then
3087 N := First (Parameter_Associations (Node));
3089 if Nkind (N) = N_Parameter_Association then
3090 return First_Named_Actual (Node);
3096 -------------------------
3097 -- Full_Qualified_Name --
3098 -------------------------
3100 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3102 pragma Warnings (Off, Res);
3104 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3105 -- Compute recursively the qualified name without NUL at the end
3107 ----------------------------------
3108 -- Internal_Full_Qualified_Name --
3109 ----------------------------------
3111 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3112 Ent : Entity_Id := E;
3113 Parent_Name : String_Id := No_String;
3116 -- Deals properly with child units
3118 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3119 Ent := Defining_Identifier (Ent);
3122 -- Compute qualification recursively (only "Standard" has no scope)
3124 if Present (Scope (Scope (Ent))) then
3125 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3128 -- Every entity should have a name except some expanded blocks
3129 -- don't bother about those.
3131 if Chars (Ent) = No_Name then
3135 -- Add a period between Name and qualification
3137 if Parent_Name /= No_String then
3138 Start_String (Parent_Name);
3139 Store_String_Char (Get_Char_Code ('.'));
3145 -- Generates the entity name in upper case
3147 Get_Decoded_Name_String (Chars (Ent));
3149 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3151 end Internal_Full_Qualified_Name;
3153 -- Start of processing for Full_Qualified_Name
3156 Res := Internal_Full_Qualified_Name (E);
3157 Store_String_Char (Get_Char_Code (ASCII.nul));
3159 end Full_Qualified_Name;
3161 -----------------------
3162 -- Gather_Components --
3163 -----------------------
3165 procedure Gather_Components
3167 Comp_List : Node_Id;
3168 Governed_By : List_Id;
3170 Report_Errors : out Boolean)
3174 Discrete_Choice : Node_Id;
3175 Comp_Item : Node_Id;
3177 Discrim : Entity_Id;
3178 Discrim_Name : Node_Id;
3179 Discrim_Value : Node_Id;
3182 Report_Errors := False;
3184 if No (Comp_List) or else Null_Present (Comp_List) then
3187 elsif Present (Component_Items (Comp_List)) then
3188 Comp_Item := First (Component_Items (Comp_List));
3194 while Present (Comp_Item) loop
3196 -- Skip the tag of a tagged record, the interface tags, as well
3197 -- as all items that are not user components (anonymous types,
3198 -- rep clauses, Parent field, controller field).
3200 if Nkind (Comp_Item) = N_Component_Declaration then
3202 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3204 if not Is_Tag (Comp)
3205 and then Chars (Comp) /= Name_uParent
3206 and then Chars (Comp) /= Name_uController
3208 Append_Elmt (Comp, Into);
3216 if No (Variant_Part (Comp_List)) then
3219 Discrim_Name := Name (Variant_Part (Comp_List));
3220 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3223 -- Look for the discriminant that governs this variant part.
3224 -- The discriminant *must* be in the Governed_By List
3226 Assoc := First (Governed_By);
3227 Find_Constraint : loop
3228 Discrim := First (Choices (Assoc));
3229 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3230 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3232 Chars (Corresponding_Discriminant (Entity (Discrim)))
3233 = Chars (Discrim_Name))
3234 or else Chars (Original_Record_Component (Entity (Discrim)))
3235 = Chars (Discrim_Name);
3237 if No (Next (Assoc)) then
3238 if not Is_Constrained (Typ)
3239 and then Is_Derived_Type (Typ)
3240 and then Present (Stored_Constraint (Typ))
3242 -- If the type is a tagged type with inherited discriminants,
3243 -- use the stored constraint on the parent in order to find
3244 -- the values of discriminants that are otherwise hidden by an
3245 -- explicit constraint. Renamed discriminants are handled in
3248 -- If several parent discriminants are renamed by a single
3249 -- discriminant of the derived type, the call to obtain the
3250 -- Corresponding_Discriminant field only retrieves the last
3251 -- of them. We recover the constraint on the others from the
3252 -- Stored_Constraint as well.
3259 D := First_Discriminant (Etype (Typ));
3260 C := First_Elmt (Stored_Constraint (Typ));
3261 while Present (D) and then Present (C) loop
3262 if Chars (Discrim_Name) = Chars (D) then
3263 if Is_Entity_Name (Node (C))
3264 and then Entity (Node (C)) = Entity (Discrim)
3266 -- D is renamed by Discrim, whose value is given in
3273 Make_Component_Association (Sloc (Typ),
3275 (New_Occurrence_Of (D, Sloc (Typ))),
3276 Duplicate_Subexpr_No_Checks (Node (C)));
3278 exit Find_Constraint;
3281 Next_Discriminant (D);
3288 if No (Next (Assoc)) then
3289 Error_Msg_NE (" missing value for discriminant&",
3290 First (Governed_By), Discrim_Name);
3291 Report_Errors := True;
3296 end loop Find_Constraint;
3298 Discrim_Value := Expression (Assoc);
3300 if not Is_OK_Static_Expression (Discrim_Value) then
3302 ("value for discriminant & must be static!",
3303 Discrim_Value, Discrim);
3304 Why_Not_Static (Discrim_Value);
3305 Report_Errors := True;
3309 Search_For_Discriminant_Value : declare
3315 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3318 Find_Discrete_Value : while Present (Variant) loop
3319 Discrete_Choice := First (Discrete_Choices (Variant));
3320 while Present (Discrete_Choice) loop
3322 exit Find_Discrete_Value when
3323 Nkind (Discrete_Choice) = N_Others_Choice;
3325 Get_Index_Bounds (Discrete_Choice, Low, High);
3327 UI_Low := Expr_Value (Low);
3328 UI_High := Expr_Value (High);
3330 exit Find_Discrete_Value when
3331 UI_Low <= UI_Discrim_Value
3333 UI_High >= UI_Discrim_Value;
3335 Next (Discrete_Choice);
3338 Next_Non_Pragma (Variant);
3339 end loop Find_Discrete_Value;
3340 end Search_For_Discriminant_Value;
3342 if No (Variant) then
3344 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3345 Report_Errors := True;
3349 -- If we have found the corresponding choice, recursively add its
3350 -- components to the Into list.
3352 Gather_Components (Empty,
3353 Component_List (Variant), Governed_By, Into, Report_Errors);
3354 end Gather_Components;
3356 ------------------------
3357 -- Get_Actual_Subtype --
3358 ------------------------
3360 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3361 Typ : constant Entity_Id := Etype (N);
3362 Utyp : Entity_Id := Underlying_Type (Typ);
3371 -- If what we have is an identifier that references a subprogram
3372 -- formal, or a variable or constant object, then we get the actual
3373 -- subtype from the referenced entity if one has been built.
3375 if Nkind (N) = N_Identifier
3377 (Is_Formal (Entity (N))
3378 or else Ekind (Entity (N)) = E_Constant
3379 or else Ekind (Entity (N)) = E_Variable)
3380 and then Present (Actual_Subtype (Entity (N)))
3382 return Actual_Subtype (Entity (N));
3384 -- Actual subtype of unchecked union is always itself. We never need
3385 -- the "real" actual subtype. If we did, we couldn't get it anyway
3386 -- because the discriminant is not available. The restrictions on
3387 -- Unchecked_Union are designed to make sure that this is OK.
3389 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3392 -- Here for the unconstrained case, we must find actual subtype
3393 -- No actual subtype is available, so we must build it on the fly.
3395 -- Checking the type, not the underlying type, for constrainedness
3396 -- seems to be necessary. Maybe all the tests should be on the type???
3398 elsif (not Is_Constrained (Typ))
3399 and then (Is_Array_Type (Utyp)
3400 or else (Is_Record_Type (Utyp)
3401 and then Has_Discriminants (Utyp)))
3402 and then not Has_Unknown_Discriminants (Utyp)
3403 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3405 -- Nothing to do if in default expression
3407 if In_Default_Expression then
3410 elsif Is_Private_Type (Typ)
3411 and then not Has_Discriminants (Typ)
3413 -- If the type has no discriminants, there is no subtype to
3414 -- build, even if the underlying type is discriminated.
3418 -- Else build the actual subtype
3421 Decl := Build_Actual_Subtype (Typ, N);
3422 Atyp := Defining_Identifier (Decl);
3424 -- If Build_Actual_Subtype generated a new declaration then use it
3428 -- The actual subtype is an Itype, so analyze the declaration,
3429 -- but do not attach it to the tree, to get the type defined.
3431 Set_Parent (Decl, N);
3432 Set_Is_Itype (Atyp);
3433 Analyze (Decl, Suppress => All_Checks);
3434 Set_Associated_Node_For_Itype (Atyp, N);
3435 Set_Has_Delayed_Freeze (Atyp, False);
3437 -- We need to freeze the actual subtype immediately. This is
3438 -- needed, because otherwise this Itype will not get frozen
3439 -- at all, and it is always safe to freeze on creation because
3440 -- any associated types must be frozen at this point.
3442 Freeze_Itype (Atyp, N);
3445 -- Otherwise we did not build a declaration, so return original
3452 -- For all remaining cases, the actual subtype is the same as
3453 -- the nominal type.
3458 end Get_Actual_Subtype;
3460 -------------------------------------
3461 -- Get_Actual_Subtype_If_Available --
3462 -------------------------------------
3464 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3465 Typ : constant Entity_Id := Etype (N);
3468 -- If what we have is an identifier that references a subprogram
3469 -- formal, or a variable or constant object, then we get the actual
3470 -- subtype from the referenced entity if one has been built.
3472 if Nkind (N) = N_Identifier
3474 (Is_Formal (Entity (N))
3475 or else Ekind (Entity (N)) = E_Constant
3476 or else Ekind (Entity (N)) = E_Variable)
3477 and then Present (Actual_Subtype (Entity (N)))
3479 return Actual_Subtype (Entity (N));
3481 -- Otherwise the Etype of N is returned unchanged
3486 end Get_Actual_Subtype_If_Available;
3488 -------------------------------
3489 -- Get_Default_External_Name --
3490 -------------------------------
3492 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3494 Get_Decoded_Name_String (Chars (E));
3496 if Opt.External_Name_Imp_Casing = Uppercase then
3497 Set_Casing (All_Upper_Case);
3499 Set_Casing (All_Lower_Case);
3503 Make_String_Literal (Sloc (E),
3504 Strval => String_From_Name_Buffer);
3505 end Get_Default_External_Name;
3507 ---------------------------
3508 -- Get_Enum_Lit_From_Pos --
3509 ---------------------------
3511 function Get_Enum_Lit_From_Pos
3514 Loc : Source_Ptr) return Node_Id
3519 -- In the case where the literal is of type Character, Wide_Character
3520 -- or Wide_Wide_Character or of a type derived from them, there needs
3521 -- to be some special handling since there is no explicit chain of
3522 -- literals to search. Instead, an N_Character_Literal node is created
3523 -- with the appropriate Char_Code and Chars fields.
3525 if Root_Type (T) = Standard_Character
3526 or else Root_Type (T) = Standard_Wide_Character
3527 or else Root_Type (T) = Standard_Wide_Wide_Character
3529 Set_Character_Literal_Name (UI_To_CC (Pos));
3531 Make_Character_Literal (Loc,
3533 Char_Literal_Value => Pos);
3535 -- For all other cases, we have a complete table of literals, and
3536 -- we simply iterate through the chain of literal until the one
3537 -- with the desired position value is found.
3541 Lit := First_Literal (Base_Type (T));
3542 for J in 1 .. UI_To_Int (Pos) loop
3546 return New_Occurrence_Of (Lit, Loc);
3548 end Get_Enum_Lit_From_Pos;
3550 ------------------------
3551 -- Get_Generic_Entity --
3552 ------------------------
3554 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3555 Ent : constant Entity_Id := Entity (Name (N));
3557 if Present (Renamed_Object (Ent)) then
3558 return Renamed_Object (Ent);
3562 end Get_Generic_Entity;
3564 ----------------------
3565 -- Get_Index_Bounds --
3566 ----------------------
3568 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3569 Kind : constant Node_Kind := Nkind (N);
3573 if Kind = N_Range then
3575 H := High_Bound (N);
3577 elsif Kind = N_Subtype_Indication then
3578 R := Range_Expression (Constraint (N));
3586 L := Low_Bound (Range_Expression (Constraint (N)));
3587 H := High_Bound (Range_Expression (Constraint (N)));
3590 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3591 if Error_Posted (Scalar_Range (Entity (N))) then
3595 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3596 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3599 L := Low_Bound (Scalar_Range (Entity (N)));
3600 H := High_Bound (Scalar_Range (Entity (N)));
3604 -- N is an expression, indicating a range with one value
3609 end Get_Index_Bounds;
3611 ----------------------------------
3612 -- Get_Library_Unit_Name_string --
3613 ----------------------------------
3615 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3616 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3619 Get_Unit_Name_String (Unit_Name_Id);
3621 -- Remove seven last character (" (spec)" or " (body)")
3623 Name_Len := Name_Len - 7;
3624 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3625 end Get_Library_Unit_Name_String;
3627 ------------------------
3628 -- Get_Name_Entity_Id --
3629 ------------------------
3631 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3633 return Entity_Id (Get_Name_Table_Info (Id));
3634 end Get_Name_Entity_Id;
3636 ---------------------------
3637 -- Get_Referenced_Object --
3638 ---------------------------
3640 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3645 while Is_Entity_Name (R)
3646 and then Present (Renamed_Object (Entity (R)))
3648 R := Renamed_Object (Entity (R));
3652 end Get_Referenced_Object;
3654 ------------------------
3655 -- Get_Renamed_Entity --
3656 ------------------------
3658 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3663 while Present (Renamed_Entity (R)) loop
3664 R := Renamed_Entity (R);
3668 end Get_Renamed_Entity;
3670 -------------------------
3671 -- Get_Subprogram_Body --
3672 -------------------------
3674 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3678 Decl := Unit_Declaration_Node (E);
3680 if Nkind (Decl) = N_Subprogram_Body then
3683 -- The below comment is bad, because it is possible for
3684 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3686 else -- Nkind (Decl) = N_Subprogram_Declaration
3688 if Present (Corresponding_Body (Decl)) then
3689 return Unit_Declaration_Node (Corresponding_Body (Decl));
3691 -- Imported subprogram case
3697 end Get_Subprogram_Body;
3699 ---------------------------
3700 -- Get_Subprogram_Entity --
3701 ---------------------------
3703 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3708 if Nkind (Nod) = N_Accept_Statement then
3709 Nam := Entry_Direct_Name (Nod);
3711 -- For an entry call, the prefix of the call is a selected component.
3712 -- Need additional code for internal calls ???
3714 elsif Nkind (Nod) = N_Entry_Call_Statement then
3715 if Nkind (Name (Nod)) = N_Selected_Component then
3716 Nam := Entity (Selector_Name (Name (Nod)));
3725 if Nkind (Nam) = N_Explicit_Dereference then
3726 Proc := Etype (Prefix (Nam));
3727 elsif Is_Entity_Name (Nam) then
3728 Proc := Entity (Nam);
3733 if Is_Object (Proc) then
3734 Proc := Etype (Proc);
3737 if Ekind (Proc) = E_Access_Subprogram_Type then
3738 Proc := Directly_Designated_Type (Proc);
3741 if not Is_Subprogram (Proc)
3742 and then Ekind (Proc) /= E_Subprogram_Type
3748 end Get_Subprogram_Entity;
3750 -----------------------------
3751 -- Get_Task_Body_Procedure --
3752 -----------------------------
3754 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3756 -- Note: A task type may be the completion of a private type with
3757 -- discriminants. when performing elaboration checks on a task
3758 -- declaration, the current view of the type may be the private one,
3759 -- and the procedure that holds the body of the task is held in its
3762 -- This is an odd function, why not have Task_Body_Procedure do
3763 -- the following digging???
3765 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3766 end Get_Task_Body_Procedure;
3768 -----------------------------
3769 -- Has_Abstract_Interfaces --
3770 -----------------------------
3772 function Has_Abstract_Interfaces
3773 (Tagged_Type : Entity_Id;
3774 Use_Full_View : Boolean := True) return Boolean
3779 pragma Assert (Is_Record_Type (Tagged_Type)
3780 and then Is_Tagged_Type (Tagged_Type));
3782 -- Handle concurrent record types
3784 if Is_Concurrent_Record_Type (Tagged_Type)
3785 and then Is_Non_Empty_List (Abstract_Interface_List (Tagged_Type))
3792 -- Handle private types
3795 and then Present (Full_View (Tagged_Type))
3797 Typ := Full_View (Tagged_Type);
3801 if Is_Interface (Typ)
3803 (Is_Record_Type (Typ)
3804 and then Present (Abstract_Interfaces (Typ))
3805 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
3810 exit when Etype (Typ) = Typ
3812 -- Handle private types
3814 or else (Present (Full_View (Etype (Typ)))
3815 and then Full_View (Etype (Typ)) = Typ)
3817 -- Protect the frontend against wrong source with cyclic
3820 or else Etype (Typ) = Tagged_Type;
3822 -- Climb to the ancestor type handling private types
3824 if Present (Full_View (Etype (Typ))) then
3825 Typ := Full_View (Etype (Typ));
3832 end Has_Abstract_Interfaces;
3834 -----------------------
3835 -- Has_Access_Values --
3836 -----------------------
3838 function Has_Access_Values (T : Entity_Id) return Boolean is
3839 Typ : constant Entity_Id := Underlying_Type (T);
3842 -- Case of a private type which is not completed yet. This can only
3843 -- happen in the case of a generic format type appearing directly, or
3844 -- as a component of the type to which this function is being applied
3845 -- at the top level. Return False in this case, since we certainly do
3846 -- not know that the type contains access types.
3851 elsif Is_Access_Type (Typ) then
3854 elsif Is_Array_Type (Typ) then
3855 return Has_Access_Values (Component_Type (Typ));
3857 elsif Is_Record_Type (Typ) then
3862 Comp := First_Component_Or_Discriminant (Typ);
3863 while Present (Comp) loop
3864 if Has_Access_Values (Etype (Comp)) then
3868 Next_Component_Or_Discriminant (Comp);
3877 end Has_Access_Values;
3879 ------------------------------
3880 -- Has_Compatible_Alignment --
3881 ------------------------------
3883 function Has_Compatible_Alignment
3885 Expr : Node_Id) return Alignment_Result
3887 function Has_Compatible_Alignment_Internal
3890 Default : Alignment_Result) return Alignment_Result;
3891 -- This is the internal recursive function that actually does the work.
3892 -- There is one additional parameter, which says what the result should
3893 -- be if no alignment information is found, and there is no definite
3894 -- indication of compatible alignments. At the outer level, this is set
3895 -- to Unknown, but for internal recursive calls in the case where types
3896 -- are known to be correct, it is set to Known_Compatible.
3898 ---------------------------------------
3899 -- Has_Compatible_Alignment_Internal --
3900 ---------------------------------------
3902 function Has_Compatible_Alignment_Internal
3905 Default : Alignment_Result) return Alignment_Result
3907 Result : Alignment_Result := Known_Compatible;
3908 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3909 -- Note that once a value of Known_Incompatible is set, it is sticky
3910 -- and does not get changed to Unknown (the value in Result only gets
3911 -- worse as we go along, never better).
3913 procedure Check_Offset (Offs : Uint);
3914 -- Called when Expr is a selected or indexed component with Offs set
3915 -- to resp Component_First_Bit or Component_Size. Checks that if the
3916 -- offset is specified it is compatible with the object alignment
3917 -- requirements. The value in Result is modified accordingly.
3919 procedure Check_Prefix;
3920 -- Checks the prefix recursively in the case where the expression
3921 -- is an indexed or selected component.
3923 procedure Set_Result (R : Alignment_Result);
3924 -- If R represents a worse outcome (unknown instead of known
3925 -- compatible, or known incompatible), then set Result to R.
3931 procedure Check_Offset (Offs : Uint) is
3933 -- Unspecified or zero offset is always OK
3935 if Offs = No_Uint or else Offs = Uint_0 then
3938 -- If we do not know required alignment, any non-zero offset is
3939 -- a potential problem (but certainly may be OK, so result is
3942 elsif Unknown_Alignment (Obj) then
3943 Set_Result (Unknown);
3945 -- If we know the required alignment, see if offset is compatible
3948 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3949 Set_Result (Known_Incompatible);
3958 procedure Check_Prefix is
3960 -- The subtlety here is that in doing a recursive call to check
3961 -- the prefix, we have to decide what to do in the case where we
3962 -- don't find any specific indication of an alignment problem.
3964 -- At the outer level, we normally set Unknown as the result in
3965 -- this case, since we can only set Known_Compatible if we really
3966 -- know that the alignment value is OK, but for the recursive
3967 -- call, in the case where the types match, and we have not
3968 -- specified a peculiar alignment for the object, we are only
3969 -- concerned about suspicious rep clauses, the default case does
3970 -- not affect us, since the compiler will, in the absence of such
3971 -- rep clauses, ensure that the alignment is correct.
3973 if Default = Known_Compatible
3975 (Etype (Obj) = Etype (Expr)
3976 and then (Unknown_Alignment (Obj)
3978 Alignment (Obj) = Alignment (Etype (Obj))))
3981 (Has_Compatible_Alignment_Internal
3982 (Obj, Prefix (Expr), Known_Compatible));
3984 -- In all other cases, we need a full check on the prefix
3988 (Has_Compatible_Alignment_Internal
3989 (Obj, Prefix (Expr), Unknown));
3997 procedure Set_Result (R : Alignment_Result) is
4004 -- Start of processing for Has_Compatible_Alignment_Internal
4007 -- If Expr is a selected component, we must make sure there is no
4008 -- potentially troublesome component clause, and that the record is
4011 if Nkind (Expr) = N_Selected_Component then
4013 -- Packed record always generate unknown alignment
4015 if Is_Packed (Etype (Prefix (Expr))) then
4016 Set_Result (Unknown);
4019 -- Check possible bad component offset and check prefix
4022 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4025 -- If Expr is an indexed component, we must make sure there is no
4026 -- potentially troublesome Component_Size clause and that the array
4027 -- is not bit-packed.
4029 elsif Nkind (Expr) = N_Indexed_Component then
4031 -- Bit packed array always generates unknown alignment
4033 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4034 Set_Result (Unknown);
4037 -- Check possible bad component size and check prefix
4039 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4043 -- Case where we know the alignment of the object
4045 if Known_Alignment (Obj) then
4047 ObjA : constant Uint := Alignment (Obj);
4048 ExpA : Uint := No_Uint;
4049 SizA : Uint := No_Uint;
4052 -- If alignment of Obj is 1, then we are always OK
4055 Set_Result (Known_Compatible);
4057 -- Alignment of Obj is greater than 1, so we need to check
4060 -- See if Expr is an object with known alignment
4062 if Is_Entity_Name (Expr)
4063 and then Known_Alignment (Entity (Expr))
4065 ExpA := Alignment (Entity (Expr));
4067 -- Otherwise, we can use the alignment of the type of
4068 -- Expr given that we already checked for
4069 -- discombobulating rep clauses for the cases of indexed
4070 -- and selected components above.
4072 elsif Known_Alignment (Etype (Expr)) then
4073 ExpA := Alignment (Etype (Expr));
4076 -- If we got an alignment, see if it is acceptable
4078 if ExpA /= No_Uint then
4080 Set_Result (Known_Incompatible);
4083 -- Case of Expr alignment unknown
4086 Set_Result (Default);
4089 -- See if size is given. If so, check that it is not too
4090 -- small for the required alignment.
4091 -- See if Expr is an object with known alignment
4093 if Is_Entity_Name (Expr)
4094 and then Known_Static_Esize (Entity (Expr))
4096 SizA := Esize (Entity (Expr));
4098 -- Otherwise, we check the object size of the Expr type
4100 elsif Known_Static_Esize (Etype (Expr)) then
4101 SizA := Esize (Etype (Expr));
4104 -- If we got a size, see if it is a multiple of the Obj
4105 -- alignment, if not, then the alignment cannot be
4106 -- acceptable, since the size is always a multiple of the
4109 if SizA /= No_Uint then
4110 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4111 Set_Result (Known_Incompatible);
4117 -- If we can't find the result by direct comparison of alignment
4118 -- values, then there is still one case that we can determine known
4119 -- result, and that is when we can determine that the types are the
4120 -- same, and no alignments are specified. Then we known that the
4121 -- alignments are compatible, even if we don't know the alignment
4122 -- value in the front end.
4124 elsif Etype (Obj) = Etype (Expr) then
4126 -- Types are the same, but we have to check for possible size
4127 -- and alignments on the Expr object that may make the alignment
4128 -- different, even though the types are the same.
4130 if Is_Entity_Name (Expr) then
4132 -- First check alignment of the Expr object. Any alignment less
4133 -- than Maximum_Alignment is worrisome since this is the case
4134 -- where we do not know the alignment of Obj.
4136 if Known_Alignment (Entity (Expr))
4138 UI_To_Int (Alignment (Entity (Expr)))
4139 < Ttypes.Maximum_Alignment
4141 Set_Result (Unknown);
4143 -- Now check size of Expr object. Any size that is not an
4144 -- even multiple of Maxiumum_Alignment is also worrisome
4145 -- since it may cause the alignment of the object to be less
4146 -- than the alignment of the type.
4148 elsif Known_Static_Esize (Entity (Expr))
4150 (UI_To_Int (Esize (Entity (Expr))) mod
4151 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4154 Set_Result (Unknown);
4156 -- Otherwise same type is decisive
4159 Set_Result (Known_Compatible);
4163 -- Another case to deal with is when there is an explicit size or
4164 -- alignment clause when the types are not the same. If so, then the
4165 -- result is Unknown. We don't need to do this test if the Default is
4166 -- Unknown, since that result will be set in any case.
4168 elsif Default /= Unknown
4169 and then (Has_Size_Clause (Etype (Expr))
4171 Has_Alignment_Clause (Etype (Expr)))
4173 Set_Result (Unknown);
4175 -- If no indication found, set default
4178 Set_Result (Default);
4181 -- Return worst result found
4184 end Has_Compatible_Alignment_Internal;
4186 -- Start of processing for Has_Compatible_Alignment
4189 -- If Obj has no specified alignment, then set alignment from the type
4190 -- alignment. Perhaps we should always do this, but for sure we should
4191 -- do it when there is an address clause since we can do more if the
4192 -- alignment is known.
4194 if Unknown_Alignment (Obj) then
4195 Set_Alignment (Obj, Alignment (Etype (Obj)));
4198 -- Now do the internal call that does all the work
4200 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4201 end Has_Compatible_Alignment;
4203 ----------------------
4204 -- Has_Declarations --
4205 ----------------------
4207 function Has_Declarations (N : Node_Id) return Boolean is
4208 K : constant Node_Kind := Nkind (N);
4210 return K = N_Accept_Statement
4211 or else K = N_Block_Statement
4212 or else K = N_Compilation_Unit_Aux
4213 or else K = N_Entry_Body
4214 or else K = N_Package_Body
4215 or else K = N_Protected_Body
4216 or else K = N_Subprogram_Body
4217 or else K = N_Task_Body
4218 or else K = N_Package_Specification;
4219 end Has_Declarations;
4221 -------------------------------------------
4222 -- Has_Discriminant_Dependent_Constraint --
4223 -------------------------------------------
4225 function Has_Discriminant_Dependent_Constraint
4226 (Comp : Entity_Id) return Boolean
4228 Comp_Decl : constant Node_Id := Parent (Comp);
4229 Subt_Indic : constant Node_Id :=
4230 Subtype_Indication (Component_Definition (Comp_Decl));
4235 if Nkind (Subt_Indic) = N_Subtype_Indication then
4236 Constr := Constraint (Subt_Indic);
4238 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4239 Assn := First (Constraints (Constr));
4240 while Present (Assn) loop
4241 case Nkind (Assn) is
4242 when N_Subtype_Indication |
4246 if Depends_On_Discriminant (Assn) then
4250 when N_Discriminant_Association =>
4251 if Depends_On_Discriminant (Expression (Assn)) then
4266 end Has_Discriminant_Dependent_Constraint;
4268 --------------------
4269 -- Has_Infinities --
4270 --------------------
4272 function Has_Infinities (E : Entity_Id) return Boolean is
4275 Is_Floating_Point_Type (E)
4276 and then Nkind (Scalar_Range (E)) = N_Range
4277 and then Includes_Infinities (Scalar_Range (E));
4280 ------------------------
4281 -- Has_Null_Exclusion --
4282 ------------------------
4284 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4287 when N_Access_Definition |
4288 N_Access_Function_Definition |
4289 N_Access_Procedure_Definition |
4290 N_Access_To_Object_Definition |
4292 N_Derived_Type_Definition |
4293 N_Function_Specification |
4294 N_Subtype_Declaration =>
4295 return Null_Exclusion_Present (N);
4297 when N_Component_Definition |
4298 N_Formal_Object_Declaration |
4299 N_Object_Renaming_Declaration =>
4300 if Present (Subtype_Mark (N)) then
4301 return Null_Exclusion_Present (N);
4302 else pragma Assert (Present (Access_Definition (N)));
4303 return Null_Exclusion_Present (Access_Definition (N));
4306 when N_Discriminant_Specification =>
4307 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4308 return Null_Exclusion_Present (Discriminant_Type (N));
4310 return Null_Exclusion_Present (N);
4313 when N_Object_Declaration =>
4314 if Nkind (Object_Definition (N)) = N_Access_Definition then
4315 return Null_Exclusion_Present (Object_Definition (N));
4317 return Null_Exclusion_Present (N);
4320 when N_Parameter_Specification =>
4321 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4322 return Null_Exclusion_Present (Parameter_Type (N));
4324 return Null_Exclusion_Present (N);
4331 end Has_Null_Exclusion;
4333 ------------------------
4334 -- Has_Null_Extension --
4335 ------------------------
4337 function Has_Null_Extension (T : Entity_Id) return Boolean is
4338 B : constant Entity_Id := Base_Type (T);
4343 if Nkind (Parent (B)) = N_Full_Type_Declaration
4344 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4346 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4348 if Present (Ext) then
4349 if Null_Present (Ext) then
4352 Comps := Component_List (Ext);
4354 -- The null component list is rewritten during analysis to
4355 -- include the parent component. Any other component indicates
4356 -- that the extension was not originally null.
4358 return Null_Present (Comps)
4359 or else No (Next (First (Component_Items (Comps))));
4368 end Has_Null_Extension;
4370 --------------------------------------
4371 -- Has_Preelaborable_Initialization --
4372 --------------------------------------
4374 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4377 procedure Check_Components (E : Entity_Id);
4378 -- Check component/discriminant chain, sets Has_PE False if a component
4379 -- or discriminant does not meet the preelaborable initialization rules.
4381 ----------------------
4382 -- Check_Components --
4383 ----------------------
4385 procedure Check_Components (E : Entity_Id) is
4390 -- Loop through entities of record or protected type
4393 while Present (Ent) loop
4395 -- We are interested only in components and discriminants
4397 if Ekind (Ent) = E_Component
4399 Ekind (Ent) = E_Discriminant
4401 -- Get default expression if any. If there is no declaration
4402 -- node, it means we have an internal entity. The parent and
4403 -- tag fields are examples of such entitires. For these
4404 -- cases, we just test the type of the entity.
4406 if Present (Declaration_Node (Ent)) then
4407 Exp := Expression (Declaration_Node (Ent));
4412 -- A component has PI if it has no default expression and
4413 -- the component type has PI.
4416 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4421 -- Or if expression obeys rules for preelaboration. For
4422 -- now we approximate this by testing if the default
4423 -- expression is a static expression or if it is an
4424 -- access attribute reference, or the literal null.
4426 -- This is an approximation, it is probably incomplete???
4428 elsif Is_Static_Expression (Exp) then
4431 elsif Nkind (Exp) = N_Attribute_Reference
4432 and then (Attribute_Name (Exp) = Name_Access
4434 Attribute_Name (Exp) = Name_Unchecked_Access
4436 Attribute_Name (Exp) = Name_Unrestricted_Access)
4440 elsif Nkind (Exp) = N_Null then
4451 end Check_Components;
4453 -- Start of processing for Has_Preelaborable_Initialization
4456 -- Immediate return if already marked as known preelaborable init. This
4457 -- covers types for which this function has already been called once
4458 -- and returned True (in which case the result is cached), and also
4459 -- types to which a pragma Preelaborable_Initialization applies.
4461 if Known_To_Have_Preelab_Init (E) then
4465 -- Other private types never have preelaborable initialization
4467 if Is_Private_Type (E) then
4471 -- Here for all non-private view
4473 -- All elementary types have preelaborable initialization
4475 if Is_Elementary_Type (E) then
4478 -- Array types have PI if the component type has PI
4480 elsif Is_Array_Type (E) then
4481 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4483 -- A derived type has preelaborable initialization if its parent type
4484 -- has preelaborable initialization and (in the case of a derived record
4485 -- extension) if the non-inherited components all have preelaborable
4486 -- initialization. However, a user-defined controlled type with an
4487 -- overriding Initialize procedure does not have preelaborable
4490 elsif Is_Derived_Type (E) then
4492 -- First check whether ancestor type has preelaborable initialization
4494 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4496 -- If OK, check extension components (if any)
4498 if Has_PE and then Is_Record_Type (E) then
4499 Check_Components (First_Entity (E));
4502 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4503 -- with a user defined Initialize procedure does not have PI.
4506 and then Is_Controlled (E)
4507 and then Present (Primitive_Operations (E))
4513 P := First_Elmt (Primitive_Operations (E));
4514 while Present (P) loop
4515 if Chars (Node (P)) = Name_Initialize
4516 and then Comes_From_Source (Node (P))
4527 -- Record type has PI if it is non private and all components have PI
4529 elsif Is_Record_Type (E) then
4531 Check_Components (First_Entity (E));
4533 -- Protected types must not have entries, and components must meet
4534 -- same set of rules as for record components.
4536 elsif Is_Protected_Type (E) then
4537 if Has_Entries (E) then
4541 Check_Components (First_Entity (E));
4542 Check_Components (First_Private_Entity (E));
4545 -- Type System.Address always has preelaborable initialization
4547 elsif Is_RTE (E, RE_Address) then
4550 -- In all other cases, type does not have preelaborable initialization
4556 -- If type has preelaborable initialization, cache result
4559 Set_Known_To_Have_Preelab_Init (E);
4563 end Has_Preelaborable_Initialization;
4565 ---------------------------
4566 -- Has_Private_Component --
4567 ---------------------------
4569 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4570 Btype : Entity_Id := Base_Type (Type_Id);
4571 Component : Entity_Id;
4574 if Error_Posted (Type_Id)
4575 or else Error_Posted (Btype)
4580 if Is_Class_Wide_Type (Btype) then
4581 Btype := Root_Type (Btype);
4584 if Is_Private_Type (Btype) then
4586 UT : constant Entity_Id := Underlying_Type (Btype);
4590 if No (Full_View (Btype)) then
4591 return not Is_Generic_Type (Btype)
4592 and then not Is_Generic_Type (Root_Type (Btype));
4595 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4599 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4602 elsif Is_Array_Type (Btype) then
4603 return Has_Private_Component (Component_Type (Btype));
4605 elsif Is_Record_Type (Btype) then
4607 Component := First_Component (Btype);
4608 while Present (Component) loop
4609 if Has_Private_Component (Etype (Component)) then
4613 Next_Component (Component);
4618 elsif Is_Protected_Type (Btype)
4619 and then Present (Corresponding_Record_Type (Btype))
4621 return Has_Private_Component (Corresponding_Record_Type (Btype));
4626 end Has_Private_Component;
4632 function Has_Stream (T : Entity_Id) return Boolean is
4639 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4642 elsif Is_Array_Type (T) then
4643 return Has_Stream (Component_Type (T));
4645 elsif Is_Record_Type (T) then
4646 E := First_Component (T);
4647 while Present (E) loop
4648 if Has_Stream (Etype (E)) then
4657 elsif Is_Private_Type (T) then
4658 return Has_Stream (Underlying_Type (T));
4665 --------------------------
4666 -- Has_Tagged_Component --
4667 --------------------------
4669 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4673 if Is_Private_Type (Typ)
4674 and then Present (Underlying_Type (Typ))
4676 return Has_Tagged_Component (Underlying_Type (Typ));
4678 elsif Is_Array_Type (Typ) then
4679 return Has_Tagged_Component (Component_Type (Typ));
4681 elsif Is_Tagged_Type (Typ) then
4684 elsif Is_Record_Type (Typ) then
4685 Comp := First_Component (Typ);
4686 while Present (Comp) loop
4687 if Has_Tagged_Component (Etype (Comp)) then
4691 Comp := Next_Component (Typ);
4699 end Has_Tagged_Component;
4705 function In_Instance return Boolean is
4706 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4712 and then S /= Standard_Standard
4714 if (Ekind (S) = E_Function
4715 or else Ekind (S) = E_Package
4716 or else Ekind (S) = E_Procedure)
4717 and then Is_Generic_Instance (S)
4720 -- A child instance is always compiled in the context of a parent
4721 -- instance. Nevertheless, the actuals are not analyzed in an
4722 -- instance context. We detect this case by examining the current
4723 -- compilation unit, which must be a child instance, and checking
4724 -- that it is not currently on the scope stack.
4726 if Is_Child_Unit (Curr_Unit)
4728 Nkind (Unit (Cunit (Current_Sem_Unit)))
4729 = N_Package_Instantiation
4730 and then not In_Open_Scopes (Curr_Unit)
4744 ----------------------
4745 -- In_Instance_Body --
4746 ----------------------
4748 function In_Instance_Body return Boolean is
4754 and then S /= Standard_Standard
4756 if (Ekind (S) = E_Function
4757 or else Ekind (S) = E_Procedure)
4758 and then Is_Generic_Instance (S)
4762 elsif Ekind (S) = E_Package
4763 and then In_Package_Body (S)
4764 and then Is_Generic_Instance (S)
4773 end In_Instance_Body;
4775 -----------------------------
4776 -- In_Instance_Not_Visible --
4777 -----------------------------
4779 function In_Instance_Not_Visible return Boolean is
4785 and then S /= Standard_Standard
4787 if (Ekind (S) = E_Function
4788 or else Ekind (S) = E_Procedure)
4789 and then Is_Generic_Instance (S)
4793 elsif Ekind (S) = E_Package
4794 and then (In_Package_Body (S) or else In_Private_Part (S))
4795 and then Is_Generic_Instance (S)
4804 end In_Instance_Not_Visible;
4806 ------------------------------
4807 -- In_Instance_Visible_Part --
4808 ------------------------------
4810 function In_Instance_Visible_Part return Boolean is
4816 and then S /= Standard_Standard
4818 if Ekind (S) = E_Package
4819 and then Is_Generic_Instance (S)
4820 and then not In_Package_Body (S)
4821 and then not In_Private_Part (S)
4830 end In_Instance_Visible_Part;
4832 ----------------------
4833 -- In_Packiage_Body --
4834 ----------------------
4836 function In_Package_Body return Boolean is
4842 and then S /= Standard_Standard
4844 if Ekind (S) = E_Package
4845 and then In_Package_Body (S)
4854 end In_Package_Body;
4856 --------------------------------------
4857 -- In_Subprogram_Or_Concurrent_Unit --
4858 --------------------------------------
4860 function In_Subprogram_Or_Concurrent_Unit return Boolean is
4865 -- Use scope chain to check successively outer scopes
4871 if K in Subprogram_Kind
4872 or else K in Concurrent_Kind
4873 or else K in Generic_Subprogram_Kind
4877 elsif E = Standard_Standard then
4883 end In_Subprogram_Or_Concurrent_Unit;
4885 ---------------------
4886 -- In_Visible_Part --
4887 ---------------------
4889 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
4892 Is_Package_Or_Generic_Package (Scope_Id)
4893 and then In_Open_Scopes (Scope_Id)
4894 and then not In_Package_Body (Scope_Id)
4895 and then not In_Private_Part (Scope_Id);
4896 end In_Visible_Part;
4898 ---------------------------------
4899 -- Insert_Explicit_Dereference --
4900 ---------------------------------
4902 procedure Insert_Explicit_Dereference (N : Node_Id) is
4903 New_Prefix : constant Node_Id := Relocate_Node (N);
4904 Ent : Entity_Id := Empty;
4911 Save_Interps (N, New_Prefix);
4913 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
4915 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
4917 if Is_Overloaded (New_Prefix) then
4919 -- The deference is also overloaded, and its interpretations are the
4920 -- designated types of the interpretations of the original node.
4922 Set_Etype (N, Any_Type);
4924 Get_First_Interp (New_Prefix, I, It);
4925 while Present (It.Nam) loop
4928 if Is_Access_Type (T) then
4929 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
4932 Get_Next_Interp (I, It);
4938 -- Prefix is unambiguous: mark the original prefix (which might
4939 -- Come_From_Source) as a reference, since the new (relocated) one
4940 -- won't be taken into account.
4942 if Is_Entity_Name (New_Prefix) then
4943 Ent := Entity (New_Prefix);
4945 -- For a retrieval of a subcomponent of some composite object,
4946 -- retrieve the ultimate entity if there is one.
4948 elsif Nkind (New_Prefix) = N_Selected_Component
4949 or else Nkind (New_Prefix) = N_Indexed_Component
4951 Pref := Prefix (New_Prefix);
4952 while Present (Pref)
4954 (Nkind (Pref) = N_Selected_Component
4955 or else Nkind (Pref) = N_Indexed_Component)
4957 Pref := Prefix (Pref);
4960 if Present (Pref) and then Is_Entity_Name (Pref) then
4961 Ent := Entity (Pref);
4965 if Present (Ent) then
4966 Generate_Reference (Ent, New_Prefix);
4969 end Insert_Explicit_Dereference;
4975 function Is_AAMP_Float (E : Entity_Id) return Boolean is
4977 pragma Assert (Is_Type (E));
4979 return AAMP_On_Target
4980 and then Is_Floating_Point_Type (E)
4981 and then E = Base_Type (E);
4984 -------------------------
4985 -- Is_Actual_Parameter --
4986 -------------------------
4988 function Is_Actual_Parameter (N : Node_Id) return Boolean is
4989 PK : constant Node_Kind := Nkind (Parent (N));
4993 when N_Parameter_Association =>
4994 return N = Explicit_Actual_Parameter (Parent (N));
4996 when N_Function_Call | N_Procedure_Call_Statement =>
4997 return Is_List_Member (N)
4999 List_Containing (N) = Parameter_Associations (Parent (N));
5004 end Is_Actual_Parameter;
5006 ---------------------
5007 -- Is_Aliased_View --
5008 ---------------------
5010 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5014 if Is_Entity_Name (Obj) then
5022 or else (Present (Renamed_Object (E))
5023 and then Is_Aliased_View (Renamed_Object (E)))))
5025 or else ((Is_Formal (E)
5026 or else Ekind (E) = E_Generic_In_Out_Parameter
5027 or else Ekind (E) = E_Generic_In_Parameter)
5028 and then Is_Tagged_Type (Etype (E)))
5030 or else (Is_Concurrent_Type (E)
5031 and then In_Open_Scopes (E))
5033 -- Current instance of type, either directly or as rewritten
5034 -- reference to the current object.
5036 or else (Is_Entity_Name (Original_Node (Obj))
5037 and then Present (Entity (Original_Node (Obj)))
5038 and then Is_Type (Entity (Original_Node (Obj))))
5040 or else (Is_Type (E) and then E = Current_Scope)
5042 or else (Is_Incomplete_Or_Private_Type (E)
5043 and then Full_View (E) = Current_Scope);
5045 elsif Nkind (Obj) = N_Selected_Component then
5046 return Is_Aliased (Entity (Selector_Name (Obj)));
5048 elsif Nkind (Obj) = N_Indexed_Component then
5049 return Has_Aliased_Components (Etype (Prefix (Obj)))
5051 (Is_Access_Type (Etype (Prefix (Obj)))
5053 Has_Aliased_Components
5054 (Designated_Type (Etype (Prefix (Obj)))));
5056 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5057 or else Nkind (Obj) = N_Type_Conversion
5059 return Is_Tagged_Type (Etype (Obj))
5060 and then Is_Aliased_View (Expression (Obj));
5062 elsif Nkind (Obj) = N_Explicit_Dereference then
5063 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5068 end Is_Aliased_View;
5070 -------------------------
5071 -- Is_Ancestor_Package --
5072 -------------------------
5074 function Is_Ancestor_Package
5076 E2 : Entity_Id) return Boolean
5083 and then Par /= Standard_Standard
5093 end Is_Ancestor_Package;
5095 ----------------------
5096 -- Is_Atomic_Object --
5097 ----------------------
5099 function Is_Atomic_Object (N : Node_Id) return Boolean is
5101 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5102 -- Determines if given object has atomic components
5104 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5105 -- If prefix is an implicit dereference, examine designated type
5107 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5109 if Is_Access_Type (Etype (N)) then
5111 Has_Atomic_Components (Designated_Type (Etype (N)));
5113 return Object_Has_Atomic_Components (N);
5115 end Is_Atomic_Prefix;
5117 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5119 if Has_Atomic_Components (Etype (N))
5120 or else Is_Atomic (Etype (N))
5124 elsif Is_Entity_Name (N)
5125 and then (Has_Atomic_Components (Entity (N))
5126 or else Is_Atomic (Entity (N)))
5130 elsif Nkind (N) = N_Indexed_Component
5131 or else Nkind (N) = N_Selected_Component
5133 return Is_Atomic_Prefix (Prefix (N));
5138 end Object_Has_Atomic_Components;
5140 -- Start of processing for Is_Atomic_Object
5143 if Is_Atomic (Etype (N))
5144 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5148 elsif Nkind (N) = N_Indexed_Component
5149 or else Nkind (N) = N_Selected_Component
5151 return Is_Atomic_Prefix (Prefix (N));
5156 end Is_Atomic_Object;
5158 -------------------------
5159 -- Is_Coextension_Root --
5160 -------------------------
5162 function Is_Coextension_Root (N : Node_Id) return Boolean is
5165 Nkind (N) = N_Allocator
5166 and then Present (Coextensions (N))
5168 -- Anonymous access discriminants carry a list of all nested
5169 -- controlled coextensions.
5171 and then not Is_Dynamic_Coextension (N)
5172 and then not Is_Static_Coextension (N);
5173 end Is_Coextension_Root;
5175 --------------------------------------
5176 -- Is_Controlling_Limited_Procedure --
5177 --------------------------------------
5179 function Is_Controlling_Limited_Procedure
5180 (Proc_Nam : Entity_Id) return Boolean
5182 Param_Typ : Entity_Id := Empty;
5185 if Ekind (Proc_Nam) = E_Procedure
5186 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5188 Param_Typ := Etype (Parameter_Type (First (
5189 Parameter_Specifications (Parent (Proc_Nam)))));
5191 -- In this case where an Itype was created, the procedure call has been
5194 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5195 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5197 Present (Parameter_Associations
5198 (Associated_Node_For_Itype (Proc_Nam)))
5201 Etype (First (Parameter_Associations
5202 (Associated_Node_For_Itype (Proc_Nam))));
5205 if Present (Param_Typ) then
5207 Is_Interface (Param_Typ)
5208 and then Is_Limited_Record (Param_Typ);
5212 end Is_Controlling_Limited_Procedure;
5214 ----------------------------------------------
5215 -- Is_Dependent_Component_Of_Mutable_Object --
5216 ----------------------------------------------
5218 function Is_Dependent_Component_Of_Mutable_Object
5219 (Object : Node_Id) return Boolean
5222 Prefix_Type : Entity_Id;
5223 P_Aliased : Boolean := False;
5226 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5227 -- Returns True if and only if Comp is declared within a variant part
5229 --------------------------------
5230 -- Is_Declared_Within_Variant --
5231 --------------------------------
5233 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5234 Comp_Decl : constant Node_Id := Parent (Comp);
5235 Comp_List : constant Node_Id := Parent (Comp_Decl);
5237 return Nkind (Parent (Comp_List)) = N_Variant;
5238 end Is_Declared_Within_Variant;
5240 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5243 if Is_Variable (Object) then
5245 if Nkind (Object) = N_Selected_Component then
5246 P := Prefix (Object);
5247 Prefix_Type := Etype (P);
5249 if Is_Entity_Name (P) then
5251 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5252 Prefix_Type := Base_Type (Prefix_Type);
5255 if Is_Aliased (Entity (P)) then
5259 -- A discriminant check on a selected component may be
5260 -- expanded into a dereference when removing side-effects.
5261 -- Recover the original node and its type, which may be
5264 elsif Nkind (P) = N_Explicit_Dereference
5265 and then not (Comes_From_Source (P))
5267 P := Original_Node (P);
5268 Prefix_Type := Etype (P);
5271 -- Check for prefix being an aliased component ???
5276 -- A heap object is constrained by its initial value
5278 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5279 -- the dereferenced case, since the access value might denote an
5280 -- unconstrained aliased object, whereas in Ada 95 the designated
5281 -- object is guaranteed to be constrained. A worst-case assumption
5282 -- has to apply in Ada 2005 because we can't tell at compile time
5283 -- whether the object is "constrained by its initial value"
5284 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5285 -- semantic rules -- these rules are acknowledged to need fixing).
5287 if Ada_Version < Ada_05 then
5288 if Is_Access_Type (Prefix_Type)
5289 or else Nkind (P) = N_Explicit_Dereference
5294 elsif Ada_Version >= Ada_05 then
5295 if Is_Access_Type (Prefix_Type) then
5296 Prefix_Type := Designated_Type (Prefix_Type);
5301 Original_Record_Component (Entity (Selector_Name (Object)));
5303 -- As per AI-0017, the renaming is illegal in a generic body,
5304 -- even if the subtype is indefinite.
5306 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5308 if not Is_Constrained (Prefix_Type)
5309 and then (not Is_Indefinite_Subtype (Prefix_Type)
5311 (Is_Generic_Type (Prefix_Type)
5312 and then Ekind (Current_Scope) = E_Generic_Package
5313 and then In_Package_Body (Current_Scope)))
5315 and then (Is_Declared_Within_Variant (Comp)
5316 or else Has_Discriminant_Dependent_Constraint (Comp))
5317 and then (not P_Aliased or else Ada_Version >= Ada_05)
5323 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5327 elsif Nkind (Object) = N_Indexed_Component
5328 or else Nkind (Object) = N_Slice
5330 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5332 -- A type conversion that Is_Variable is a view conversion:
5333 -- go back to the denoted object.
5335 elsif Nkind (Object) = N_Type_Conversion then
5337 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5342 end Is_Dependent_Component_Of_Mutable_Object;
5344 ---------------------
5345 -- Is_Dereferenced --
5346 ---------------------
5348 function Is_Dereferenced (N : Node_Id) return Boolean is
5349 P : constant Node_Id := Parent (N);
5352 (Nkind (P) = N_Selected_Component
5354 Nkind (P) = N_Explicit_Dereference
5356 Nkind (P) = N_Indexed_Component
5358 Nkind (P) = N_Slice)
5359 and then Prefix (P) = N;
5360 end Is_Dereferenced;
5362 ----------------------
5363 -- Is_Descendent_Of --
5364 ----------------------
5366 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5371 pragma Assert (Nkind (T1) in N_Entity);
5372 pragma Assert (Nkind (T2) in N_Entity);
5374 T := Base_Type (T1);
5376 -- Immediate return if the types match
5381 -- Comment needed here ???
5383 elsif Ekind (T) = E_Class_Wide_Type then
5384 return Etype (T) = T2;
5392 -- Done if we found the type we are looking for
5397 -- Done if no more derivations to check
5404 -- Following test catches error cases resulting from prev errors
5406 elsif No (Etyp) then
5409 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5412 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5416 T := Base_Type (Etyp);
5420 raise Program_Error;
5421 end Is_Descendent_Of;
5427 function Is_False (U : Uint) return Boolean is
5432 ---------------------------
5433 -- Is_Fixed_Model_Number --
5434 ---------------------------
5436 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5437 S : constant Ureal := Small_Value (T);
5438 M : Urealp.Save_Mark;
5442 R := (U = UR_Trunc (U / S) * S);
5445 end Is_Fixed_Model_Number;
5447 -------------------------------
5448 -- Is_Fully_Initialized_Type --
5449 -------------------------------
5451 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5453 if Is_Scalar_Type (Typ) then
5456 elsif Is_Access_Type (Typ) then
5459 elsif Is_Array_Type (Typ) then
5460 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5464 -- An interesting case, if we have a constrained type one of whose
5465 -- bounds is known to be null, then there are no elements to be
5466 -- initialized, so all the elements are initialized!
5468 if Is_Constrained (Typ) then
5471 Indx_Typ : Entity_Id;
5475 Indx := First_Index (Typ);
5476 while Present (Indx) loop
5477 if Etype (Indx) = Any_Type then
5480 -- If index is a range, use directly
5482 elsif Nkind (Indx) = N_Range then
5483 Lbd := Low_Bound (Indx);
5484 Hbd := High_Bound (Indx);
5487 Indx_Typ := Etype (Indx);
5489 if Is_Private_Type (Indx_Typ) then
5490 Indx_Typ := Full_View (Indx_Typ);
5493 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5496 Lbd := Type_Low_Bound (Indx_Typ);
5497 Hbd := Type_High_Bound (Indx_Typ);
5501 if Compile_Time_Known_Value (Lbd)
5502 and then Compile_Time_Known_Value (Hbd)
5504 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5514 -- If no null indexes, then type is not fully initialized
5520 elsif Is_Record_Type (Typ) then
5521 if Has_Discriminants (Typ)
5523 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5524 and then Is_Fully_Initialized_Variant (Typ)
5529 -- Controlled records are considered to be fully initialized if
5530 -- there is a user defined Initialize routine. This may not be
5531 -- entirely correct, but as the spec notes, we are guessing here
5532 -- what is best from the point of view of issuing warnings.
5534 if Is_Controlled (Typ) then
5536 Utyp : constant Entity_Id := Underlying_Type (Typ);
5539 if Present (Utyp) then
5541 Init : constant Entity_Id :=
5543 (Underlying_Type (Typ), Name_Initialize));
5547 and then Comes_From_Source (Init)
5549 Is_Predefined_File_Name
5550 (File_Name (Get_Source_File_Index (Sloc (Init))))
5554 elsif Has_Null_Extension (Typ)
5556 Is_Fully_Initialized_Type
5557 (Etype (Base_Type (Typ)))
5566 -- Otherwise see if all record components are initialized
5572 Ent := First_Entity (Typ);
5573 while Present (Ent) loop
5574 if Chars (Ent) = Name_uController then
5577 elsif Ekind (Ent) = E_Component
5578 and then (No (Parent (Ent))
5579 or else No (Expression (Parent (Ent))))
5580 and then not Is_Fully_Initialized_Type (Etype (Ent))
5582 -- Special VM case for uTag component, which needs to be
5583 -- defined in this case, but is never initialized as VMs
5584 -- are using other dispatching mechanisms. Ignore this
5585 -- uninitialized case.
5587 and then (VM_Target = No_VM
5588 or else Chars (Ent) /= Name_uTag)
5597 -- No uninitialized components, so type is fully initialized.
5598 -- Note that this catches the case of no components as well.
5602 elsif Is_Concurrent_Type (Typ) then
5605 elsif Is_Private_Type (Typ) then
5607 U : constant Entity_Id := Underlying_Type (Typ);
5613 return Is_Fully_Initialized_Type (U);
5620 end Is_Fully_Initialized_Type;
5622 ----------------------------------
5623 -- Is_Fully_Initialized_Variant --
5624 ----------------------------------
5626 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5627 Loc : constant Source_Ptr := Sloc (Typ);
5628 Constraints : constant List_Id := New_List;
5629 Components : constant Elist_Id := New_Elmt_List;
5630 Comp_Elmt : Elmt_Id;
5632 Comp_List : Node_Id;
5634 Discr_Val : Node_Id;
5635 Report_Errors : Boolean;
5638 if Serious_Errors_Detected > 0 then
5642 if Is_Record_Type (Typ)
5643 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5644 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5646 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5648 Discr := First_Discriminant (Typ);
5649 while Present (Discr) loop
5650 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5651 Discr_Val := Expression (Parent (Discr));
5653 if Present (Discr_Val)
5654 and then Is_OK_Static_Expression (Discr_Val)
5656 Append_To (Constraints,
5657 Make_Component_Association (Loc,
5658 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5659 Expression => New_Copy (Discr_Val)));
5667 Next_Discriminant (Discr);
5672 Comp_List => Comp_List,
5673 Governed_By => Constraints,
5675 Report_Errors => Report_Errors);
5677 -- Check that each component present is fully initialized
5679 Comp_Elmt := First_Elmt (Components);
5680 while Present (Comp_Elmt) loop
5681 Comp_Id := Node (Comp_Elmt);
5683 if Ekind (Comp_Id) = E_Component
5684 and then (No (Parent (Comp_Id))
5685 or else No (Expression (Parent (Comp_Id))))
5686 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5691 Next_Elmt (Comp_Elmt);
5696 elsif Is_Private_Type (Typ) then
5698 U : constant Entity_Id := Underlying_Type (Typ);
5704 return Is_Fully_Initialized_Variant (U);
5710 end Is_Fully_Initialized_Variant;
5712 ----------------------------
5713 -- Is_Inherited_Operation --
5714 ----------------------------
5716 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
5717 Kind : constant Node_Kind := Nkind (Parent (E));
5719 pragma Assert (Is_Overloadable (E));
5720 return Kind = N_Full_Type_Declaration
5721 or else Kind = N_Private_Extension_Declaration
5722 or else Kind = N_Subtype_Declaration
5723 or else (Ekind (E) = E_Enumeration_Literal
5724 and then Is_Derived_Type (Etype (E)));
5725 end Is_Inherited_Operation;
5727 -----------------------------
5728 -- Is_Library_Level_Entity --
5729 -----------------------------
5731 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
5733 -- The following is a small optimization, and it also properly handles
5734 -- discriminals, which in task bodies might appear in expressions before
5735 -- the corresponding procedure has been created, and which therefore do
5736 -- not have an assigned scope.
5738 if Ekind (E) in Formal_Kind then
5742 -- Normal test is simply that the enclosing dynamic scope is Standard
5744 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
5745 end Is_Library_Level_Entity;
5747 ---------------------------------
5748 -- Is_Local_Variable_Reference --
5749 ---------------------------------
5751 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
5753 if not Is_Entity_Name (Expr) then
5758 Ent : constant Entity_Id := Entity (Expr);
5759 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
5761 if Ekind (Ent) /= E_Variable
5763 Ekind (Ent) /= E_In_Out_Parameter
5767 return Present (Sub) and then Sub = Current_Subprogram;
5771 end Is_Local_Variable_Reference;
5773 -------------------------
5774 -- Is_Object_Reference --
5775 -------------------------
5777 function Is_Object_Reference (N : Node_Id) return Boolean is
5779 if Is_Entity_Name (N) then
5780 return Present (Entity (N)) and then Is_Object (Entity (N));
5784 when N_Indexed_Component | N_Slice =>
5786 Is_Object_Reference (Prefix (N))
5787 or else Is_Access_Type (Etype (Prefix (N)));
5789 -- In Ada95, a function call is a constant object; a procedure
5792 when N_Function_Call =>
5793 return Etype (N) /= Standard_Void_Type;
5795 -- A reference to the stream attribute Input is a function call
5797 when N_Attribute_Reference =>
5798 return Attribute_Name (N) = Name_Input;
5800 when N_Selected_Component =>
5802 Is_Object_Reference (Selector_Name (N))
5804 (Is_Object_Reference (Prefix (N))
5805 or else Is_Access_Type (Etype (Prefix (N))));
5807 when N_Explicit_Dereference =>
5810 -- A view conversion of a tagged object is an object reference
5812 when N_Type_Conversion =>
5813 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
5814 and then Is_Tagged_Type (Etype (Expression (N)))
5815 and then Is_Object_Reference (Expression (N));
5817 -- An unchecked type conversion is considered to be an object if
5818 -- the operand is an object (this construction arises only as a
5819 -- result of expansion activities).
5821 when N_Unchecked_Type_Conversion =>
5828 end Is_Object_Reference;
5830 -----------------------------------
5831 -- Is_OK_Variable_For_Out_Formal --
5832 -----------------------------------
5834 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
5836 Note_Possible_Modification (AV);
5838 -- We must reject parenthesized variable names. The check for
5839 -- Comes_From_Source is present because there are currently
5840 -- cases where the compiler violates this rule (e.g. passing
5841 -- a task object to its controlled Initialize routine).
5843 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
5846 -- A variable is always allowed
5848 elsif Is_Variable (AV) then
5851 -- Unchecked conversions are allowed only if they come from the
5852 -- generated code, which sometimes uses unchecked conversions for out
5853 -- parameters in cases where code generation is unaffected. We tell
5854 -- source unchecked conversions by seeing if they are rewrites of an
5855 -- original Unchecked_Conversion function call, or of an explicit
5856 -- conversion of a function call.
5858 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
5859 if Nkind (Original_Node (AV)) = N_Function_Call then
5862 elsif Comes_From_Source (AV)
5863 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
5867 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
5868 return Is_OK_Variable_For_Out_Formal (Expression (AV));
5874 -- Normal type conversions are allowed if argument is a variable
5876 elsif Nkind (AV) = N_Type_Conversion then
5877 if Is_Variable (Expression (AV))
5878 and then Paren_Count (Expression (AV)) = 0
5880 Note_Possible_Modification (Expression (AV));
5883 -- We also allow a non-parenthesized expression that raises
5884 -- constraint error if it rewrites what used to be a variable
5886 elsif Raises_Constraint_Error (Expression (AV))
5887 and then Paren_Count (Expression (AV)) = 0
5888 and then Is_Variable (Original_Node (Expression (AV)))
5892 -- Type conversion of something other than a variable
5898 -- If this node is rewritten, then test the original form, if that is
5899 -- OK, then we consider the rewritten node OK (for example, if the
5900 -- original node is a conversion, then Is_Variable will not be true
5901 -- but we still want to allow the conversion if it converts a variable).
5903 elsif Original_Node (AV) /= AV then
5904 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
5906 -- All other non-variables are rejected
5911 end Is_OK_Variable_For_Out_Formal;
5919 E2 : Entity_Id) return Boolean
5921 Iface_List : List_Id;
5922 T : Entity_Id := E2;
5925 if Is_Concurrent_Type (T)
5926 or else Is_Concurrent_Record_Type (T)
5928 Iface_List := Abstract_Interface_List (E2);
5930 if Is_Empty_List (Iface_List) then
5934 T := Etype (First (Iface_List));
5937 return Is_Ancestor (E1, T);
5940 -----------------------------------
5941 -- Is_Partially_Initialized_Type --
5942 -----------------------------------
5944 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
5946 if Is_Scalar_Type (Typ) then
5949 elsif Is_Access_Type (Typ) then
5952 elsif Is_Array_Type (Typ) then
5954 -- If component type is partially initialized, so is array type
5956 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
5959 -- Otherwise we are only partially initialized if we are fully
5960 -- initialized (this is the empty array case, no point in us
5961 -- duplicating that code here).
5964 return Is_Fully_Initialized_Type (Typ);
5967 elsif Is_Record_Type (Typ) then
5969 -- A discriminated type is always partially initialized
5971 if Has_Discriminants (Typ) then
5974 -- A tagged type is always partially initialized
5976 elsif Is_Tagged_Type (Typ) then
5979 -- Case of non-discriminated record
5985 Component_Present : Boolean := False;
5986 -- Set True if at least one component is present. If no
5987 -- components are present, then record type is fully
5988 -- initialized (another odd case, like the null array).
5991 -- Loop through components
5993 Ent := First_Entity (Typ);
5994 while Present (Ent) loop
5995 if Ekind (Ent) = E_Component then
5996 Component_Present := True;
5998 -- If a component has an initialization expression then
5999 -- the enclosing record type is partially initialized
6001 if Present (Parent (Ent))
6002 and then Present (Expression (Parent (Ent)))
6006 -- If a component is of a type which is itself partially
6007 -- initialized, then the enclosing record type is also.
6009 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6017 -- No initialized components found. If we found any components
6018 -- they were all uninitialized so the result is false.
6020 if Component_Present then
6023 -- But if we found no components, then all the components are
6024 -- initialized so we consider the type to be initialized.
6032 -- Concurrent types are always fully initialized
6034 elsif Is_Concurrent_Type (Typ) then
6037 -- For a private type, go to underlying type. If there is no underlying
6038 -- type then just assume this partially initialized. Not clear if this
6039 -- can happen in a non-error case, but no harm in testing for this.
6041 elsif Is_Private_Type (Typ) then
6043 U : constant Entity_Id := Underlying_Type (Typ);
6048 return Is_Partially_Initialized_Type (U);
6052 -- For any other type (are there any?) assume partially initialized
6057 end Is_Partially_Initialized_Type;
6059 ------------------------------------
6060 -- Is_Potentially_Persistent_Type --
6061 ------------------------------------
6063 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6068 -- For private type, test corrresponding full type
6070 if Is_Private_Type (T) then
6071 return Is_Potentially_Persistent_Type (Full_View (T));
6073 -- Scalar types are potentially persistent
6075 elsif Is_Scalar_Type (T) then
6078 -- Record type is potentially persistent if not tagged and the types of
6079 -- all it components are potentially persistent, and no component has
6080 -- an initialization expression.
6082 elsif Is_Record_Type (T)
6083 and then not Is_Tagged_Type (T)
6084 and then not Is_Partially_Initialized_Type (T)
6086 Comp := First_Component (T);
6087 while Present (Comp) loop
6088 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6097 -- Array type is potentially persistent if its component type is
6098 -- potentially persistent and if all its constraints are static.
6100 elsif Is_Array_Type (T) then
6101 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6105 Indx := First_Index (T);
6106 while Present (Indx) loop
6107 if not Is_OK_Static_Subtype (Etype (Indx)) then
6116 -- All other types are not potentially persistent
6121 end Is_Potentially_Persistent_Type;
6123 -----------------------------
6124 -- Is_RCI_Pkg_Spec_Or_Body --
6125 -----------------------------
6127 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6129 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6130 -- Return True if the unit of Cunit is an RCI package declaration
6132 ---------------------------
6133 -- Is_RCI_Pkg_Decl_Cunit --
6134 ---------------------------
6136 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6137 The_Unit : constant Node_Id := Unit (Cunit);
6140 if Nkind (The_Unit) /= N_Package_Declaration then
6144 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6145 end Is_RCI_Pkg_Decl_Cunit;
6147 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6150 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6152 (Nkind (Unit (Cunit)) = N_Package_Body
6153 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6154 end Is_RCI_Pkg_Spec_Or_Body;
6156 -----------------------------------------
6157 -- Is_Remote_Access_To_Class_Wide_Type --
6158 -----------------------------------------
6160 function Is_Remote_Access_To_Class_Wide_Type
6161 (E : Entity_Id) return Boolean
6165 function Comes_From_Limited_Private_Type_Declaration
6166 (E : Entity_Id) return Boolean;
6167 -- Check that the type is declared by a limited type declaration,
6168 -- or else is derived from a Remote_Type ancestor through private
6171 -------------------------------------------------
6172 -- Comes_From_Limited_Private_Type_Declaration --
6173 -------------------------------------------------
6175 function Comes_From_Limited_Private_Type_Declaration
6176 (E : Entity_Id) return Boolean
6178 N : constant Node_Id := Declaration_Node (E);
6181 if Nkind (N) = N_Private_Type_Declaration
6182 and then Limited_Present (N)
6187 if Nkind (N) = N_Private_Extension_Declaration then
6189 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6191 (Is_Remote_Types (Etype (E))
6192 and then Is_Limited_Record (Etype (E))
6193 and then Has_Private_Declaration (Etype (E)));
6197 end Comes_From_Limited_Private_Type_Declaration;
6199 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6202 if not (Is_Remote_Call_Interface (E)
6203 or else Is_Remote_Types (E))
6204 or else Ekind (E) /= E_General_Access_Type
6209 D := Designated_Type (E);
6211 if Ekind (D) /= E_Class_Wide_Type then
6215 return Comes_From_Limited_Private_Type_Declaration
6216 (Defining_Identifier (Parent (D)));
6217 end Is_Remote_Access_To_Class_Wide_Type;
6219 -----------------------------------------
6220 -- Is_Remote_Access_To_Subprogram_Type --
6221 -----------------------------------------
6223 function Is_Remote_Access_To_Subprogram_Type
6224 (E : Entity_Id) return Boolean
6227 return (Ekind (E) = E_Access_Subprogram_Type
6228 or else (Ekind (E) = E_Record_Type
6229 and then Present (Corresponding_Remote_Type (E))))
6230 and then (Is_Remote_Call_Interface (E)
6231 or else Is_Remote_Types (E));
6232 end Is_Remote_Access_To_Subprogram_Type;
6234 --------------------
6235 -- Is_Remote_Call --
6236 --------------------
6238 function Is_Remote_Call (N : Node_Id) return Boolean is
6240 if Nkind (N) /= N_Procedure_Call_Statement
6241 and then Nkind (N) /= N_Function_Call
6243 -- An entry call cannot be remote
6247 elsif Nkind (Name (N)) in N_Has_Entity
6248 and then Is_Remote_Call_Interface (Entity (Name (N)))
6250 -- A subprogram declared in the spec of a RCI package is remote
6254 elsif Nkind (Name (N)) = N_Explicit_Dereference
6255 and then Is_Remote_Access_To_Subprogram_Type
6256 (Etype (Prefix (Name (N))))
6258 -- The dereference of a RAS is a remote call
6262 elsif Present (Controlling_Argument (N))
6263 and then Is_Remote_Access_To_Class_Wide_Type
6264 (Etype (Controlling_Argument (N)))
6266 -- Any primitive operation call with a controlling argument of
6267 -- a RACW type is a remote call.
6272 -- All other calls are local calls
6277 ----------------------
6278 -- Is_Renamed_Entry --
6279 ----------------------
6281 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6282 Orig_Node : Node_Id := Empty;
6283 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6285 function Is_Entry (Nam : Node_Id) return Boolean;
6286 -- Determine whether Nam is an entry. Traverse selectors
6287 -- if there are nested selected components.
6293 function Is_Entry (Nam : Node_Id) return Boolean is
6295 if Nkind (Nam) = N_Selected_Component then
6296 return Is_Entry (Selector_Name (Nam));
6299 return Ekind (Entity (Nam)) = E_Entry;
6302 -- Start of processing for Is_Renamed_Entry
6305 if Present (Alias (Proc_Nam)) then
6306 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6309 -- Look for a rewritten subprogram renaming declaration
6311 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6312 and then Present (Original_Node (Subp_Decl))
6314 Orig_Node := Original_Node (Subp_Decl);
6317 -- The rewritten subprogram is actually an entry
6319 if Present (Orig_Node)
6320 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6321 and then Is_Entry (Name (Orig_Node))
6327 end Is_Renamed_Entry;
6329 ----------------------
6330 -- Is_Selector_Name --
6331 ----------------------
6333 function Is_Selector_Name (N : Node_Id) return Boolean is
6335 if not Is_List_Member (N) then
6337 P : constant Node_Id := Parent (N);
6338 K : constant Node_Kind := Nkind (P);
6341 (K = N_Expanded_Name or else
6342 K = N_Generic_Association or else
6343 K = N_Parameter_Association or else
6344 K = N_Selected_Component)
6345 and then Selector_Name (P) = N;
6350 L : constant List_Id := List_Containing (N);
6351 P : constant Node_Id := Parent (L);
6353 return (Nkind (P) = N_Discriminant_Association
6354 and then Selector_Names (P) = L)
6356 (Nkind (P) = N_Component_Association
6357 and then Choices (P) = L);
6360 end Is_Selector_Name;
6366 function Is_Statement (N : Node_Id) return Boolean is
6369 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6370 or else Nkind (N) = N_Procedure_Call_Statement;
6373 ---------------------------------
6374 -- Is_Synchronized_Tagged_Type --
6375 ---------------------------------
6377 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6378 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6381 -- A task or protected type derived from an interface is a tagged type.
6382 -- Such a tagged type is called a synchronized tagged type, as are
6383 -- synchronized interfaces and private extensions whose declaration
6384 -- includes the reserved word synchronized.
6386 return (Is_Tagged_Type (E)
6387 and then (Kind = E_Task_Type
6388 or else Kind = E_Protected_Type))
6391 and then Is_Synchronized_Interface (E))
6393 (Ekind (E) = E_Record_Type_With_Private
6394 and then (Synchronized_Present (Parent (E))
6395 or else Is_Synchronized_Interface (Etype (E))));
6396 end Is_Synchronized_Tagged_Type;
6402 function Is_Transfer (N : Node_Id) return Boolean is
6403 Kind : constant Node_Kind := Nkind (N);
6406 if Kind = N_Simple_Return_Statement
6408 Kind = N_Extended_Return_Statement
6410 Kind = N_Goto_Statement
6412 Kind = N_Raise_Statement
6414 Kind = N_Requeue_Statement
6418 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6419 and then No (Condition (N))
6423 elsif Kind = N_Procedure_Call_Statement
6424 and then Is_Entity_Name (Name (N))
6425 and then Present (Entity (Name (N)))
6426 and then No_Return (Entity (Name (N)))
6430 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6442 function Is_True (U : Uint) return Boolean is
6451 function Is_Value_Type (T : Entity_Id) return Boolean is
6453 return VM_Target = CLI_Target
6454 and then Chars (T) /= No_Name
6455 and then Get_Name_String (Chars (T)) = "valuetype";
6462 function Is_Variable (N : Node_Id) return Boolean is
6464 Orig_Node : constant Node_Id := Original_Node (N);
6465 -- We do the test on the original node, since this is basically a
6466 -- test of syntactic categories, so it must not be disturbed by
6467 -- whatever rewriting might have occurred. For example, an aggregate,
6468 -- which is certainly NOT a variable, could be turned into a variable
6471 function In_Protected_Function (E : Entity_Id) return Boolean;
6472 -- Within a protected function, the private components of the
6473 -- enclosing protected type are constants. A function nested within
6474 -- a (protected) procedure is not itself protected.
6476 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6477 -- Prefixes can involve implicit dereferences, in which case we
6478 -- must test for the case of a reference of a constant access
6479 -- type, which can never be a variable.
6481 ---------------------------
6482 -- In_Protected_Function --
6483 ---------------------------
6485 function In_Protected_Function (E : Entity_Id) return Boolean is
6486 Prot : constant Entity_Id := Scope (E);
6490 if not Is_Protected_Type (Prot) then
6494 while Present (S) and then S /= Prot loop
6495 if Ekind (S) = E_Function
6496 and then Scope (S) = Prot
6506 end In_Protected_Function;
6508 ------------------------
6509 -- Is_Variable_Prefix --
6510 ------------------------
6512 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6514 if Is_Access_Type (Etype (P)) then
6515 return not Is_Access_Constant (Root_Type (Etype (P)));
6517 -- For the case of an indexed component whose prefix has a packed
6518 -- array type, the prefix has been rewritten into a type conversion.
6519 -- Determine variable-ness from the converted expression.
6521 elsif Nkind (P) = N_Type_Conversion
6522 and then not Comes_From_Source (P)
6523 and then Is_Array_Type (Etype (P))
6524 and then Is_Packed (Etype (P))
6526 return Is_Variable (Expression (P));
6529 return Is_Variable (P);
6531 end Is_Variable_Prefix;
6533 -- Start of processing for Is_Variable
6536 -- Definitely OK if Assignment_OK is set. Since this is something that
6537 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6539 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6542 -- Normally we go to the original node, but there is one exception
6543 -- where we use the rewritten node, namely when it is an explicit
6544 -- dereference. The generated code may rewrite a prefix which is an
6545 -- access type with an explicit dereference. The dereference is a
6546 -- variable, even though the original node may not be (since it could
6547 -- be a constant of the access type).
6549 -- In Ada 2005 we have a further case to consider: the prefix may be
6550 -- a function call given in prefix notation. The original node appears
6551 -- to be a selected component, but we need to examine the call.
6553 elsif Nkind (N) = N_Explicit_Dereference
6554 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6555 and then Present (Etype (Orig_Node))
6556 and then Is_Access_Type (Etype (Orig_Node))
6558 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6560 (Nkind (Orig_Node) = N_Function_Call
6561 and then not Is_Access_Constant (Etype (Prefix (N))));
6563 -- A function call is never a variable
6565 elsif Nkind (N) = N_Function_Call then
6568 -- All remaining checks use the original node
6570 elsif Is_Entity_Name (Orig_Node)
6571 and then Present (Entity (Orig_Node))
6574 E : constant Entity_Id := Entity (Orig_Node);
6575 K : constant Entity_Kind := Ekind (E);
6578 return (K = E_Variable
6579 and then Nkind (Parent (E)) /= N_Exception_Handler)
6580 or else (K = E_Component
6581 and then not In_Protected_Function (E))
6582 or else K = E_Out_Parameter
6583 or else K = E_In_Out_Parameter
6584 or else K = E_Generic_In_Out_Parameter
6586 -- Current instance of type:
6588 or else (Is_Type (E) and then In_Open_Scopes (E))
6589 or else (Is_Incomplete_Or_Private_Type (E)
6590 and then In_Open_Scopes (Full_View (E)));
6594 case Nkind (Orig_Node) is
6595 when N_Indexed_Component | N_Slice =>
6596 return Is_Variable_Prefix (Prefix (Orig_Node));
6598 when N_Selected_Component =>
6599 return Is_Variable_Prefix (Prefix (Orig_Node))
6600 and then Is_Variable (Selector_Name (Orig_Node));
6602 -- For an explicit dereference, the type of the prefix cannot
6603 -- be an access to constant or an access to subprogram.
6605 when N_Explicit_Dereference =>
6607 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6609 return Is_Access_Type (Typ)
6610 and then not Is_Access_Constant (Root_Type (Typ))
6611 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6614 -- The type conversion is the case where we do not deal with the
6615 -- context dependent special case of an actual parameter. Thus
6616 -- the type conversion is only considered a variable for the
6617 -- purposes of this routine if the target type is tagged. However,
6618 -- a type conversion is considered to be a variable if it does not
6619 -- come from source (this deals for example with the conversions
6620 -- of expressions to their actual subtypes).
6622 when N_Type_Conversion =>
6623 return Is_Variable (Expression (Orig_Node))
6625 (not Comes_From_Source (Orig_Node)
6627 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6629 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6631 -- GNAT allows an unchecked type conversion as a variable. This
6632 -- only affects the generation of internal expanded code, since
6633 -- calls to instantiations of Unchecked_Conversion are never
6634 -- considered variables (since they are function calls).
6635 -- This is also true for expression actions.
6637 when N_Unchecked_Type_Conversion =>
6638 return Is_Variable (Expression (Orig_Node));
6646 ------------------------
6647 -- Is_Volatile_Object --
6648 ------------------------
6650 function Is_Volatile_Object (N : Node_Id) return Boolean is
6652 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6653 -- Determines if given object has volatile components
6655 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6656 -- If prefix is an implicit dereference, examine designated type
6658 ------------------------
6659 -- Is_Volatile_Prefix --
6660 ------------------------
6662 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6663 Typ : constant Entity_Id := Etype (N);
6666 if Is_Access_Type (Typ) then
6668 Dtyp : constant Entity_Id := Designated_Type (Typ);
6671 return Is_Volatile (Dtyp)
6672 or else Has_Volatile_Components (Dtyp);
6676 return Object_Has_Volatile_Components (N);
6678 end Is_Volatile_Prefix;
6680 ------------------------------------
6681 -- Object_Has_Volatile_Components --
6682 ------------------------------------
6684 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6685 Typ : constant Entity_Id := Etype (N);
6688 if Is_Volatile (Typ)
6689 or else Has_Volatile_Components (Typ)
6693 elsif Is_Entity_Name (N)
6694 and then (Has_Volatile_Components (Entity (N))
6695 or else Is_Volatile (Entity (N)))
6699 elsif Nkind (N) = N_Indexed_Component
6700 or else Nkind (N) = N_Selected_Component
6702 return Is_Volatile_Prefix (Prefix (N));
6707 end Object_Has_Volatile_Components;
6709 -- Start of processing for Is_Volatile_Object
6712 if Is_Volatile (Etype (N))
6713 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6717 elsif Nkind (N) = N_Indexed_Component
6718 or else Nkind (N) = N_Selected_Component
6720 return Is_Volatile_Prefix (Prefix (N));
6725 end Is_Volatile_Object;
6727 -------------------------
6728 -- Kill_Current_Values --
6729 -------------------------
6731 procedure Kill_Current_Values (Ent : Entity_Id) is
6733 if Is_Object (Ent) then
6735 Set_Current_Value (Ent, Empty);
6737 if Ekind (Ent) = E_Variable then
6738 Set_Last_Assignment (Ent, Empty);
6741 if not Can_Never_Be_Null (Ent) then
6742 Set_Is_Known_Non_Null (Ent, False);
6745 Set_Is_Known_Null (Ent, False);
6747 end Kill_Current_Values;
6749 procedure Kill_Current_Values is
6752 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
6753 -- Clear current value for entity E and all entities chained to E
6755 ------------------------------------------
6756 -- Kill_Current_Values_For_Entity_Chain --
6757 ------------------------------------------
6759 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
6763 while Present (Ent) loop
6764 Kill_Current_Values (Ent);
6767 end Kill_Current_Values_For_Entity_Chain;
6769 -- Start of processing for Kill_Current_Values
6772 -- Kill all saved checks, a special case of killing saved values
6776 -- Loop through relevant scopes, which includes the current scope and
6777 -- any parent scopes if the current scope is a block or a package.
6782 -- Clear current values of all entities in current scope
6784 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
6786 -- If scope is a package, also clear current values of all
6787 -- private entities in the scope.
6789 if Ekind (S) = E_Package
6791 Ekind (S) = E_Generic_Package
6793 Is_Concurrent_Type (S)
6795 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
6798 -- If this is a not a subprogram, deal with parents
6800 if not Is_Subprogram (S) then
6802 exit Scope_Loop when S = Standard_Standard;
6806 end loop Scope_Loop;
6807 end Kill_Current_Values;
6809 --------------------------
6810 -- Kill_Size_Check_Code --
6811 --------------------------
6813 procedure Kill_Size_Check_Code (E : Entity_Id) is
6815 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6816 and then Present (Size_Check_Code (E))
6818 Remove (Size_Check_Code (E));
6819 Set_Size_Check_Code (E, Empty);
6821 end Kill_Size_Check_Code;
6823 --------------------------
6824 -- Known_To_Be_Assigned --
6825 --------------------------
6827 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
6828 P : constant Node_Id := Parent (N);
6833 -- Test left side of assignment
6835 when N_Assignment_Statement =>
6836 return N = Name (P);
6838 -- Function call arguments are never lvalues
6840 when N_Function_Call =>
6843 -- Positional parameter for procedure or accept call
6845 when N_Procedure_Call_Statement |
6854 Proc := Get_Subprogram_Entity (P);
6860 -- If we are not a list member, something is strange, so
6861 -- be conservative and return False.
6863 if not Is_List_Member (N) then
6867 -- We are going to find the right formal by stepping forward
6868 -- through the formals, as we step backwards in the actuals.
6870 Form := First_Formal (Proc);
6873 -- If no formal, something is weird, so be conservative
6874 -- and return False.
6885 return Ekind (Form) /= E_In_Parameter;
6888 -- Named parameter for procedure or accept call
6890 when N_Parameter_Association =>
6896 Proc := Get_Subprogram_Entity (Parent (P));
6902 -- Loop through formals to find the one that matches
6904 Form := First_Formal (Proc);
6906 -- If no matching formal, that's peculiar, some kind of
6907 -- previous error, so return False to be conservative.
6913 -- Else test for match
6915 if Chars (Form) = Chars (Selector_Name (P)) then
6916 return Ekind (Form) /= E_In_Parameter;
6923 -- Test for appearing in a conversion that itself appears
6924 -- in an lvalue context, since this should be an lvalue.
6926 when N_Type_Conversion =>
6927 return Known_To_Be_Assigned (P);
6929 -- All other references are definitely not knwon to be modifications
6935 end Known_To_Be_Assigned;
6941 function May_Be_Lvalue (N : Node_Id) return Boolean is
6942 P : constant Node_Id := Parent (N);
6947 -- Test left side of assignment
6949 when N_Assignment_Statement =>
6950 return N = Name (P);
6952 -- Test prefix of component or attribute
6954 when N_Attribute_Reference =>
6955 return N = Prefix (P)
6956 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
6958 when N_Expanded_Name |
6959 N_Explicit_Dereference |
6960 N_Indexed_Component |
6962 N_Selected_Component |
6964 return N = Prefix (P);
6966 -- Function call arguments are never lvalues
6968 when N_Function_Call =>
6971 -- Positional parameter for procedure, entry, or accept call
6973 when N_Procedure_Call_Statement |
6974 N_Entry_Call_Statement |
6983 Proc := Get_Subprogram_Entity (P);
6989 -- If we are not a list member, something is strange, so
6990 -- be conservative and return True.
6992 if not Is_List_Member (N) then
6996 -- We are going to find the right formal by stepping forward
6997 -- through the formals, as we step backwards in the actuals.
6999 Form := First_Formal (Proc);
7002 -- If no formal, something is weird, so be conservative
7014 return Ekind (Form) /= E_In_Parameter;
7017 -- Named parameter for procedure or accept call
7019 when N_Parameter_Association =>
7025 Proc := Get_Subprogram_Entity (Parent (P));
7031 -- Loop through formals to find the one that matches
7033 Form := First_Formal (Proc);
7035 -- If no matching formal, that's peculiar, some kind of
7036 -- previous error, so return True to be conservative.
7042 -- Else test for match
7044 if Chars (Form) = Chars (Selector_Name (P)) then
7045 return Ekind (Form) /= E_In_Parameter;
7052 -- Test for appearing in a conversion that itself appears
7053 -- in an lvalue context, since this should be an lvalue.
7055 when N_Type_Conversion =>
7056 return May_Be_Lvalue (P);
7058 -- Test for appearence in object renaming declaration
7060 when N_Object_Renaming_Declaration =>
7063 -- All other references are definitely not Lvalues
7071 -----------------------
7072 -- Mark_Coextensions --
7073 -----------------------
7075 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7076 Is_Dynamic : Boolean := False;
7078 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7079 -- Recognize an allocator node and label it as a dynamic coextension
7081 --------------------
7082 -- Mark_Allocator --
7083 --------------------
7085 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7087 if Nkind (N) = N_Allocator then
7089 Set_Is_Dynamic_Coextension (N);
7091 Set_Is_Static_Coextension (N);
7098 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7100 -- Start of processing Mark_Coextensions
7103 case Nkind (Context_Nod) is
7104 when N_Assignment_Statement |
7105 N_Simple_Return_Statement =>
7106 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7108 when N_Object_Declaration =>
7109 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7111 -- This routine should not be called for constructs which may not
7112 -- contain coextensions.
7115 raise Program_Error;
7118 Mark_Allocators (Root_Nod);
7119 end Mark_Coextensions;
7121 ----------------------
7122 -- Needs_One_Actual --
7123 ----------------------
7125 function Needs_One_Actual (E : Entity_Id) return Boolean is
7129 if Ada_Version >= Ada_05
7130 and then Present (First_Formal (E))
7132 Formal := Next_Formal (First_Formal (E));
7133 while Present (Formal) loop
7134 if No (Default_Value (Formal)) then
7138 Next_Formal (Formal);
7146 end Needs_One_Actual;
7148 -------------------------
7149 -- New_External_Entity --
7150 -------------------------
7152 function New_External_Entity
7153 (Kind : Entity_Kind;
7154 Scope_Id : Entity_Id;
7155 Sloc_Value : Source_Ptr;
7156 Related_Id : Entity_Id;
7158 Suffix_Index : Nat := 0;
7159 Prefix : Character := ' ') return Entity_Id
7161 N : constant Entity_Id :=
7162 Make_Defining_Identifier (Sloc_Value,
7164 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7167 Set_Ekind (N, Kind);
7168 Set_Is_Internal (N, True);
7169 Append_Entity (N, Scope_Id);
7170 Set_Public_Status (N);
7172 if Kind in Type_Kind then
7173 Init_Size_Align (N);
7177 end New_External_Entity;
7179 -------------------------
7180 -- New_Internal_Entity --
7181 -------------------------
7183 function New_Internal_Entity
7184 (Kind : Entity_Kind;
7185 Scope_Id : Entity_Id;
7186 Sloc_Value : Source_Ptr;
7187 Id_Char : Character) return Entity_Id
7189 N : constant Entity_Id :=
7190 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7193 Set_Ekind (N, Kind);
7194 Set_Is_Internal (N, True);
7195 Append_Entity (N, Scope_Id);
7197 if Kind in Type_Kind then
7198 Init_Size_Align (N);
7202 end New_Internal_Entity;
7208 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7212 -- If we are pointing at a positional parameter, it is a member of
7213 -- a node list (the list of parameters), and the next parameter
7214 -- is the next node on the list, unless we hit a parameter
7215 -- association, in which case we shift to using the chain whose
7216 -- head is the First_Named_Actual in the parent, and then is
7217 -- threaded using the Next_Named_Actual of the Parameter_Association.
7218 -- All this fiddling is because the original node list is in the
7219 -- textual call order, and what we need is the declaration order.
7221 if Is_List_Member (Actual_Id) then
7222 N := Next (Actual_Id);
7224 if Nkind (N) = N_Parameter_Association then
7225 return First_Named_Actual (Parent (Actual_Id));
7231 return Next_Named_Actual (Parent (Actual_Id));
7235 procedure Next_Actual (Actual_Id : in out Node_Id) is
7237 Actual_Id := Next_Actual (Actual_Id);
7240 -----------------------
7241 -- Normalize_Actuals --
7242 -----------------------
7244 -- Chain actuals according to formals of subprogram. If there are no named
7245 -- associations, the chain is simply the list of Parameter Associations,
7246 -- since the order is the same as the declaration order. If there are named
7247 -- associations, then the First_Named_Actual field in the N_Function_Call
7248 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7249 -- node for the parameter that comes first in declaration order. The
7250 -- remaining named parameters are then chained in declaration order using
7251 -- Next_Named_Actual.
7253 -- This routine also verifies that the number of actuals is compatible with
7254 -- the number and default values of formals, but performs no type checking
7255 -- (type checking is done by the caller).
7257 -- If the matching succeeds, Success is set to True and the caller proceeds
7258 -- with type-checking. If the match is unsuccessful, then Success is set to
7259 -- False, and the caller attempts a different interpretation, if there is
7262 -- If the flag Report is on, the call is not overloaded, and a failure to
7263 -- match can be reported here, rather than in the caller.
7265 procedure Normalize_Actuals
7269 Success : out Boolean)
7271 Actuals : constant List_Id := Parameter_Associations (N);
7272 Actual : Node_Id := Empty;
7274 Last : Node_Id := Empty;
7275 First_Named : Node_Id := Empty;
7278 Formals_To_Match : Integer := 0;
7279 Actuals_To_Match : Integer := 0;
7281 procedure Chain (A : Node_Id);
7282 -- Add named actual at the proper place in the list, using the
7283 -- Next_Named_Actual link.
7285 function Reporting return Boolean;
7286 -- Determines if an error is to be reported. To report an error, we
7287 -- need Report to be True, and also we do not report errors caused
7288 -- by calls to init procs that occur within other init procs. Such
7289 -- errors must always be cascaded errors, since if all the types are
7290 -- declared correctly, the compiler will certainly build decent calls!
7296 procedure Chain (A : Node_Id) is
7300 -- Call node points to first actual in list
7302 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7305 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7309 Set_Next_Named_Actual (Last, Empty);
7316 function Reporting return Boolean is
7321 elsif not Within_Init_Proc then
7324 elsif Is_Init_Proc (Entity (Name (N))) then
7332 -- Start of processing for Normalize_Actuals
7335 if Is_Access_Type (S) then
7337 -- The name in the call is a function call that returns an access
7338 -- to subprogram. The designated type has the list of formals.
7340 Formal := First_Formal (Designated_Type (S));
7342 Formal := First_Formal (S);
7345 while Present (Formal) loop
7346 Formals_To_Match := Formals_To_Match + 1;
7347 Next_Formal (Formal);
7350 -- Find if there is a named association, and verify that no positional
7351 -- associations appear after named ones.
7353 if Present (Actuals) then
7354 Actual := First (Actuals);
7357 while Present (Actual)
7358 and then Nkind (Actual) /= N_Parameter_Association
7360 Actuals_To_Match := Actuals_To_Match + 1;
7364 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7366 -- Most common case: positional notation, no defaults
7371 elsif Actuals_To_Match > Formals_To_Match then
7373 -- Too many actuals: will not work
7376 if Is_Entity_Name (Name (N)) then
7377 Error_Msg_N ("too many arguments in call to&", Name (N));
7379 Error_Msg_N ("too many arguments in call", N);
7387 First_Named := Actual;
7389 while Present (Actual) loop
7390 if Nkind (Actual) /= N_Parameter_Association then
7392 ("positional parameters not allowed after named ones", Actual);
7397 Actuals_To_Match := Actuals_To_Match + 1;
7403 if Present (Actuals) then
7404 Actual := First (Actuals);
7407 Formal := First_Formal (S);
7408 while Present (Formal) loop
7410 -- Match the formals in order. If the corresponding actual
7411 -- is positional, nothing to do. Else scan the list of named
7412 -- actuals to find the one with the right name.
7415 and then Nkind (Actual) /= N_Parameter_Association
7418 Actuals_To_Match := Actuals_To_Match - 1;
7419 Formals_To_Match := Formals_To_Match - 1;
7422 -- For named parameters, search the list of actuals to find
7423 -- one that matches the next formal name.
7425 Actual := First_Named;
7427 while Present (Actual) loop
7428 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7431 Actuals_To_Match := Actuals_To_Match - 1;
7432 Formals_To_Match := Formals_To_Match - 1;
7440 if Ekind (Formal) /= E_In_Parameter
7441 or else No (Default_Value (Formal))
7444 if (Comes_From_Source (S)
7445 or else Sloc (S) = Standard_Location)
7446 and then Is_Overloadable (S)
7450 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7452 (Nkind (Parent (N)) = N_Function_Call
7454 Nkind (Parent (N)) = N_Parameter_Association))
7455 and then Ekind (S) /= E_Function
7457 Set_Etype (N, Etype (S));
7459 Error_Msg_Name_1 := Chars (S);
7460 Error_Msg_Sloc := Sloc (S);
7462 ("missing argument for parameter & " &
7463 "in call to % declared #", N, Formal);
7466 elsif Is_Overloadable (S) then
7467 Error_Msg_Name_1 := Chars (S);
7469 -- Point to type derivation that generated the
7472 Error_Msg_Sloc := Sloc (Parent (S));
7475 ("missing argument for parameter & " &
7476 "in call to % (inherited) #", N, Formal);
7480 ("missing argument for parameter &", N, Formal);
7488 Formals_To_Match := Formals_To_Match - 1;
7493 Next_Formal (Formal);
7496 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7503 -- Find some superfluous named actual that did not get
7504 -- attached to the list of associations.
7506 Actual := First (Actuals);
7507 while Present (Actual) loop
7508 if Nkind (Actual) = N_Parameter_Association
7509 and then Actual /= Last
7510 and then No (Next_Named_Actual (Actual))
7512 Error_Msg_N ("unmatched actual & in call",
7513 Selector_Name (Actual));
7524 end Normalize_Actuals;
7526 --------------------------------
7527 -- Note_Possible_Modification --
7528 --------------------------------
7530 procedure Note_Possible_Modification (N : Node_Id) is
7531 Modification_Comes_From_Source : constant Boolean :=
7532 Comes_From_Source (Parent (N));
7538 -- Loop to find referenced entity, if there is one
7545 if Is_Entity_Name (Exp) then
7546 Ent := Entity (Exp);
7548 -- If the entity is missing, it is an undeclared identifier,
7549 -- and there is nothing to annotate.
7555 elsif Nkind (Exp) = N_Explicit_Dereference then
7557 P : constant Node_Id := Prefix (Exp);
7560 if Nkind (P) = N_Selected_Component
7562 Entry_Formal (Entity (Selector_Name (P))))
7564 -- Case of a reference to an entry formal
7566 Ent := Entry_Formal (Entity (Selector_Name (P)));
7568 elsif Nkind (P) = N_Identifier
7569 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7570 and then Present (Expression (Parent (Entity (P))))
7571 and then Nkind (Expression (Parent (Entity (P))))
7574 -- Case of a reference to a value on which
7575 -- side effects have been removed.
7577 Exp := Prefix (Expression (Parent (Entity (P))));
7586 elsif Nkind (Exp) = N_Type_Conversion
7587 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7589 Exp := Expression (Exp);
7592 elsif Nkind (Exp) = N_Slice
7593 or else Nkind (Exp) = N_Indexed_Component
7594 or else Nkind (Exp) = N_Selected_Component
7596 Exp := Prefix (Exp);
7603 -- Now look for entity being referenced
7605 if Present (Ent) then
7606 if Is_Object (Ent) then
7607 if Comes_From_Source (Exp)
7608 or else Modification_Comes_From_Source
7610 Set_Never_Set_In_Source (Ent, False);
7613 Set_Is_True_Constant (Ent, False);
7614 Set_Current_Value (Ent, Empty);
7615 Set_Is_Known_Null (Ent, False);
7617 if not Can_Never_Be_Null (Ent) then
7618 Set_Is_Known_Non_Null (Ent, False);
7621 -- Follow renaming chain
7623 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7624 and then Present (Renamed_Object (Ent))
7626 Exp := Renamed_Object (Ent);
7630 -- Generate a reference only if the assignment comes from
7631 -- source. This excludes, for example, calls to a dispatching
7632 -- assignment operation when the left-hand side is tagged.
7634 if Modification_Comes_From_Source then
7635 Generate_Reference (Ent, Exp, 'm');
7638 Check_Nested_Access (Ent);
7645 end Note_Possible_Modification;
7647 -------------------------
7648 -- Object_Access_Level --
7649 -------------------------
7651 function Object_Access_Level (Obj : Node_Id) return Uint is
7654 -- Returns the static accessibility level of the view denoted
7655 -- by Obj. Note that the value returned is the result of a
7656 -- call to Scope_Depth. Only scope depths associated with
7657 -- dynamic scopes can actually be returned. Since only
7658 -- relative levels matter for accessibility checking, the fact
7659 -- that the distance between successive levels of accessibility
7660 -- is not always one is immaterial (invariant: if level(E2) is
7661 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7663 function Reference_To (Obj : Node_Id) return Node_Id;
7664 -- An explicit dereference is created when removing side-effects
7665 -- from expressions for constraint checking purposes. In this case
7666 -- a local access type is created for it. The correct access level
7667 -- is that of the original source node. We detect this case by
7668 -- noting that the prefix of the dereference is created by an object
7669 -- declaration whose initial expression is a reference.
7675 function Reference_To (Obj : Node_Id) return Node_Id is
7676 Pref : constant Node_Id := Prefix (Obj);
7678 if Is_Entity_Name (Pref)
7679 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7680 and then Present (Expression (Parent (Entity (Pref))))
7681 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7683 return (Prefix (Expression (Parent (Entity (Pref)))));
7689 -- Start of processing for Object_Access_Level
7692 if Is_Entity_Name (Obj) then
7695 -- If E is a type then it denotes a current instance.
7696 -- For this case we add one to the normal accessibility
7697 -- level of the type to ensure that current instances
7698 -- are treated as always being deeper than than the level
7699 -- of any visible named access type (see 3.10.2(21)).
7702 return Type_Access_Level (E) + 1;
7704 elsif Present (Renamed_Object (E)) then
7705 return Object_Access_Level (Renamed_Object (E));
7707 -- Similarly, if E is a component of the current instance of a
7708 -- protected type, any instance of it is assumed to be at a deeper
7709 -- level than the type. For a protected object (whose type is an
7710 -- anonymous protected type) its components are at the same level
7711 -- as the type itself.
7713 elsif not Is_Overloadable (E)
7714 and then Ekind (Scope (E)) = E_Protected_Type
7715 and then Comes_From_Source (Scope (E))
7717 return Type_Access_Level (Scope (E)) + 1;
7720 return Scope_Depth (Enclosing_Dynamic_Scope (E));
7723 elsif Nkind (Obj) = N_Selected_Component then
7724 if Is_Access_Type (Etype (Prefix (Obj))) then
7725 return Type_Access_Level (Etype (Prefix (Obj)));
7727 return Object_Access_Level (Prefix (Obj));
7730 elsif Nkind (Obj) = N_Indexed_Component then
7731 if Is_Access_Type (Etype (Prefix (Obj))) then
7732 return Type_Access_Level (Etype (Prefix (Obj)));
7734 return Object_Access_Level (Prefix (Obj));
7737 elsif Nkind (Obj) = N_Explicit_Dereference then
7739 -- If the prefix is a selected access discriminant then
7740 -- we make a recursive call on the prefix, which will
7741 -- in turn check the level of the prefix object of
7742 -- the selected discriminant.
7744 if Nkind (Prefix (Obj)) = N_Selected_Component
7745 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
7747 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
7749 return Object_Access_Level (Prefix (Obj));
7751 elsif not (Comes_From_Source (Obj)) then
7753 Ref : constant Node_Id := Reference_To (Obj);
7755 if Present (Ref) then
7756 return Object_Access_Level (Ref);
7758 return Type_Access_Level (Etype (Prefix (Obj)));
7763 return Type_Access_Level (Etype (Prefix (Obj)));
7766 elsif Nkind (Obj) = N_Type_Conversion
7767 or else Nkind (Obj) = N_Unchecked_Type_Conversion
7769 return Object_Access_Level (Expression (Obj));
7771 -- Function results are objects, so we get either the access level
7772 -- of the function or, in the case of an indirect call, the level of
7773 -- of the access-to-subprogram type.
7775 elsif Nkind (Obj) = N_Function_Call then
7776 if Is_Entity_Name (Name (Obj)) then
7777 return Subprogram_Access_Level (Entity (Name (Obj)));
7779 return Type_Access_Level (Etype (Prefix (Name (Obj))));
7782 -- For convenience we handle qualified expressions, even though
7783 -- they aren't technically object names.
7785 elsif Nkind (Obj) = N_Qualified_Expression then
7786 return Object_Access_Level (Expression (Obj));
7788 -- Otherwise return the scope level of Standard.
7789 -- (If there are cases that fall through
7790 -- to this point they will be treated as
7791 -- having global accessibility for now. ???)
7794 return Scope_Depth (Standard_Standard);
7796 end Object_Access_Level;
7798 -----------------------
7799 -- Private_Component --
7800 -----------------------
7802 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
7803 Ancestor : constant Entity_Id := Base_Type (Type_Id);
7805 function Trace_Components
7807 Check : Boolean) return Entity_Id;
7808 -- Recursive function that does the work, and checks against circular
7809 -- definition for each subcomponent type.
7811 ----------------------
7812 -- Trace_Components --
7813 ----------------------
7815 function Trace_Components
7817 Check : Boolean) return Entity_Id
7819 Btype : constant Entity_Id := Base_Type (T);
7820 Component : Entity_Id;
7822 Candidate : Entity_Id := Empty;
7825 if Check and then Btype = Ancestor then
7826 Error_Msg_N ("circular type definition", Type_Id);
7830 if Is_Private_Type (Btype)
7831 and then not Is_Generic_Type (Btype)
7833 if Present (Full_View (Btype))
7834 and then Is_Record_Type (Full_View (Btype))
7835 and then not Is_Frozen (Btype)
7837 -- To indicate that the ancestor depends on a private type,
7838 -- the current Btype is sufficient. However, to check for
7839 -- circular definition we must recurse on the full view.
7841 Candidate := Trace_Components (Full_View (Btype), True);
7843 if Candidate = Any_Type then
7853 elsif Is_Array_Type (Btype) then
7854 return Trace_Components (Component_Type (Btype), True);
7856 elsif Is_Record_Type (Btype) then
7857 Component := First_Entity (Btype);
7858 while Present (Component) loop
7860 -- Skip anonymous types generated by constrained components
7862 if not Is_Type (Component) then
7863 P := Trace_Components (Etype (Component), True);
7866 if P = Any_Type then
7874 Next_Entity (Component);
7882 end Trace_Components;
7884 -- Start of processing for Private_Component
7887 return Trace_Components (Type_Id, False);
7888 end Private_Component;
7890 -----------------------
7891 -- Process_End_Label --
7892 -----------------------
7894 procedure Process_End_Label
7902 Label_Ref : Boolean;
7903 -- Set True if reference to end label itself is required
7906 -- Gets set to the operator symbol or identifier that references
7907 -- the entity Ent. For the child unit case, this is the identifier
7908 -- from the designator. For other cases, this is simply Endl.
7910 procedure Generate_Parent_Ref (N : Node_Id);
7911 -- N is an identifier node that appears as a parent unit reference
7912 -- in the case where Ent is a child unit. This procedure generates
7913 -- an appropriate cross-reference entry.
7915 -------------------------
7916 -- Generate_Parent_Ref --
7917 -------------------------
7919 procedure Generate_Parent_Ref (N : Node_Id) is
7920 Parent_Ent : Entity_Id;
7923 -- Search up scope stack. The reason we do this is that normal
7924 -- visibility analysis would not work for two reasons. First in
7925 -- some subunit cases, the entry for the parent unit may not be
7926 -- visible, and in any case there can be a local entity that
7927 -- hides the scope entity.
7929 Parent_Ent := Current_Scope;
7930 while Present (Parent_Ent) loop
7931 if Chars (Parent_Ent) = Chars (N) then
7933 -- Generate the reference. We do NOT consider this as a
7934 -- reference for unreferenced symbol purposes, but we do
7935 -- force a cross-reference even if the end line does not
7936 -- come from source (the caller already generated the
7937 -- appropriate Typ for this situation).
7940 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
7941 Style.Check_Identifier (N, Parent_Ent);
7945 Parent_Ent := Scope (Parent_Ent);
7948 -- Fall through means entity was not found -- that's odd, but
7949 -- the appropriate thing is simply to ignore and not generate
7950 -- any cross-reference for this entry.
7953 end Generate_Parent_Ref;
7955 -- Start of processing for Process_End_Label
7958 -- If no node, ignore. This happens in some error situations,
7959 -- and also for some internally generated structures where no
7960 -- end label references are required in any case.
7966 -- Nothing to do if no End_Label, happens for internally generated
7967 -- constructs where we don't want an end label reference anyway.
7968 -- Also nothing to do if Endl is a string literal, which means
7969 -- there was some prior error (bad operator symbol)
7971 Endl := End_Label (N);
7973 if No (Endl) or else Nkind (Endl) = N_String_Literal then
7977 -- Reference node is not in extended main source unit
7979 if not In_Extended_Main_Source_Unit (N) then
7981 -- Generally we do not collect references except for the
7982 -- extended main source unit. The one exception is the 'e'
7983 -- entry for a package spec, where it is useful for a client
7984 -- to have the ending information to define scopes.
7992 -- For this case, we can ignore any parent references,
7993 -- but we need the package name itself for the 'e' entry.
7995 if Nkind (Endl) = N_Designator then
7996 Endl := Identifier (Endl);
8000 -- Reference is in extended main source unit
8005 -- For designator, generate references for the parent entries
8007 if Nkind (Endl) = N_Designator then
8009 -- Generate references for the prefix if the END line comes
8010 -- from source (otherwise we do not need these references)
8012 if Comes_From_Source (Endl) then
8014 while Nkind (Nam) = N_Selected_Component loop
8015 Generate_Parent_Ref (Selector_Name (Nam));
8016 Nam := Prefix (Nam);
8019 Generate_Parent_Ref (Nam);
8022 Endl := Identifier (Endl);
8026 -- If the end label is not for the given entity, then either we have
8027 -- some previous error, or this is a generic instantiation for which
8028 -- we do not need to make a cross-reference in this case anyway. In
8029 -- either case we simply ignore the call.
8031 if Chars (Ent) /= Chars (Endl) then
8035 -- If label was really there, then generate a normal reference
8036 -- and then adjust the location in the end label to point past
8037 -- the name (which should almost always be the semicolon).
8041 if Comes_From_Source (Endl) then
8043 -- If a label reference is required, then do the style check
8044 -- and generate an l-type cross-reference entry for the label
8048 Style.Check_Identifier (Endl, Ent);
8050 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8053 -- Set the location to point past the label (normally this will
8054 -- mean the semicolon immediately following the label). This is
8055 -- done for the sake of the 'e' or 't' entry generated below.
8057 Get_Decoded_Name_String (Chars (Endl));
8058 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8061 -- Now generate the e/t reference
8063 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8065 -- Restore Sloc, in case modified above, since we have an identifier
8066 -- and the normal Sloc should be left set in the tree.
8068 Set_Sloc (Endl, Loc);
8069 end Process_End_Label;
8075 -- We do the conversion to get the value of the real string by using
8076 -- the scanner, see Sinput for details on use of the internal source
8077 -- buffer for scanning internal strings.
8079 function Real_Convert (S : String) return Node_Id is
8080 Save_Src : constant Source_Buffer_Ptr := Source;
8084 Source := Internal_Source_Ptr;
8087 for J in S'Range loop
8088 Source (Source_Ptr (J)) := S (J);
8091 Source (S'Length + 1) := EOF;
8093 if Source (Scan_Ptr) = '-' then
8095 Scan_Ptr := Scan_Ptr + 1;
8103 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8110 ---------------------
8111 -- Rep_To_Pos_Flag --
8112 ---------------------
8114 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8116 return New_Occurrence_Of
8117 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8118 end Rep_To_Pos_Flag;
8120 --------------------
8121 -- Require_Entity --
8122 --------------------
8124 procedure Require_Entity (N : Node_Id) is
8126 if Is_Entity_Name (N) and then No (Entity (N)) then
8127 if Total_Errors_Detected /= 0 then
8128 Set_Entity (N, Any_Id);
8130 raise Program_Error;
8135 ------------------------------
8136 -- Requires_Transient_Scope --
8137 ------------------------------
8139 -- A transient scope is required when variable-sized temporaries are
8140 -- allocated in the primary or secondary stack, or when finalization
8141 -- actions must be generated before the next instruction.
8143 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8144 Typ : constant Entity_Id := Underlying_Type (Id);
8146 -- Start of processing for Requires_Transient_Scope
8149 -- This is a private type which is not completed yet. This can only
8150 -- happen in a default expression (of a formal parameter or of a
8151 -- record component). Do not expand transient scope in this case
8156 -- Do not expand transient scope for non-existent procedure return
8158 elsif Typ = Standard_Void_Type then
8161 -- Elementary types do not require a transient scope
8163 elsif Is_Elementary_Type (Typ) then
8166 -- Generally, indefinite subtypes require a transient scope, since the
8167 -- back end cannot generate temporaries, since this is not a valid type
8168 -- for declaring an object. It might be possible to relax this in the
8169 -- future, e.g. by declaring the maximum possible space for the type.
8171 elsif Is_Indefinite_Subtype (Typ) then
8174 -- Functions returning tagged types may dispatch on result so their
8175 -- returned value is allocated on the secondary stack. Controlled
8176 -- type temporaries need finalization.
8178 elsif Is_Tagged_Type (Typ)
8179 or else Has_Controlled_Component (Typ)
8181 return not Is_Value_Type (Typ);
8185 elsif Is_Record_Type (Typ) then
8189 Comp := First_Entity (Typ);
8190 while Present (Comp) loop
8191 if Ekind (Comp) = E_Component
8192 and then Requires_Transient_Scope (Etype (Comp))
8203 -- String literal types never require transient scope
8205 elsif Ekind (Typ) = E_String_Literal_Subtype then
8208 -- Array type. Note that we already know that this is a constrained
8209 -- array, since unconstrained arrays will fail the indefinite test.
8211 elsif Is_Array_Type (Typ) then
8213 -- If component type requires a transient scope, the array does too
8215 if Requires_Transient_Scope (Component_Type (Typ)) then
8218 -- Otherwise, we only need a transient scope if the size is not
8219 -- known at compile time.
8222 return not Size_Known_At_Compile_Time (Typ);
8225 -- All other cases do not require a transient scope
8230 end Requires_Transient_Scope;
8232 --------------------------
8233 -- Reset_Analyzed_Flags --
8234 --------------------------
8236 procedure Reset_Analyzed_Flags (N : Node_Id) is
8238 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8239 -- Function used to reset Analyzed flags in tree. Note that we do
8240 -- not reset Analyzed flags in entities, since there is no need to
8241 -- renalalyze entities, and indeed, it is wrong to do so, since it
8242 -- can result in generating auxiliary stuff more than once.
8244 --------------------
8245 -- Clear_Analyzed --
8246 --------------------
8248 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8250 if not Has_Extension (N) then
8251 Set_Analyzed (N, False);
8257 function Reset_Analyzed is
8258 new Traverse_Func (Clear_Analyzed);
8260 Discard : Traverse_Result;
8261 pragma Warnings (Off, Discard);
8263 -- Start of processing for Reset_Analyzed_Flags
8266 Discard := Reset_Analyzed (N);
8267 end Reset_Analyzed_Flags;
8269 ---------------------------
8270 -- Safe_To_Capture_Value --
8271 ---------------------------
8273 function Safe_To_Capture_Value
8276 Cond : Boolean := False) return Boolean
8279 -- The only entities for which we track constant values are variables
8280 -- which are not renamings, constants, out parameters, and in out
8281 -- parameters, so check if we have this case.
8283 -- Note: it may seem odd to track constant values for constants, but in
8284 -- fact this routine is used for other purposes than simply capturing
8285 -- the value. In particular, the setting of Known[_Non]_Null.
8287 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8289 Ekind (Ent) = E_Constant
8291 Ekind (Ent) = E_Out_Parameter
8293 Ekind (Ent) = E_In_Out_Parameter
8297 -- For conditionals, we also allow loop parameters and all formals,
8298 -- including in parameters.
8302 (Ekind (Ent) = E_Loop_Parameter
8304 Ekind (Ent) = E_In_Parameter)
8308 -- For all other cases, not just unsafe, but impossible to capture
8309 -- Current_Value, since the above are the only entities which have
8310 -- Current_Value fields.
8316 -- Skip if volatile or aliased, since funny things might be going on in
8317 -- these cases which we cannot necessarily track. Also skip any variable
8318 -- for which an address clause is given, or whose address is taken.
8320 if Treat_As_Volatile (Ent)
8321 or else Is_Aliased (Ent)
8322 or else Present (Address_Clause (Ent))
8323 or else Address_Taken (Ent)
8328 -- OK, all above conditions are met. We also require that the scope of
8329 -- the reference be the same as the scope of the entity, not counting
8330 -- packages and blocks and loops.
8333 E_Scope : constant Entity_Id := Scope (Ent);
8334 R_Scope : Entity_Id;
8337 R_Scope := Current_Scope;
8338 while R_Scope /= Standard_Standard loop
8339 exit when R_Scope = E_Scope;
8341 if Ekind (R_Scope) /= E_Package
8343 Ekind (R_Scope) /= E_Block
8345 Ekind (R_Scope) /= E_Loop
8349 R_Scope := Scope (R_Scope);
8354 -- We also require that the reference does not appear in a context
8355 -- where it is not sure to be executed (i.e. a conditional context
8356 -- or an exception handler). We skip this if Cond is True, since the
8357 -- capturing of values from conditional tests handles this ok.
8371 while Present (P) loop
8372 if Nkind (P) = N_If_Statement
8373 or else Nkind (P) = N_Case_Statement
8374 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8375 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8376 or else Nkind (P) = N_Exception_Handler
8377 or else Nkind (P) = N_Selective_Accept
8378 or else Nkind (P) = N_Conditional_Entry_Call
8379 or else Nkind (P) = N_Timed_Entry_Call
8380 or else Nkind (P) = N_Asynchronous_Select
8390 -- OK, looks safe to set value
8393 end Safe_To_Capture_Value;
8399 function Same_Name (N1, N2 : Node_Id) return Boolean is
8400 K1 : constant Node_Kind := Nkind (N1);
8401 K2 : constant Node_Kind := Nkind (N2);
8404 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8405 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8407 return Chars (N1) = Chars (N2);
8409 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8410 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8412 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8413 and then Same_Name (Prefix (N1), Prefix (N2));
8424 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8425 N1 : constant Node_Id := Original_Node (Node1);
8426 N2 : constant Node_Id := Original_Node (Node2);
8427 -- We do the tests on original nodes, since we are most interested
8428 -- in the original source, not any expansion that got in the way.
8430 K1 : constant Node_Kind := Nkind (N1);
8431 K2 : constant Node_Kind := Nkind (N2);
8434 -- First case, both are entities with same entity
8436 if K1 in N_Has_Entity
8437 and then K2 in N_Has_Entity
8438 and then Present (Entity (N1))
8439 and then Present (Entity (N2))
8440 and then (Ekind (Entity (N1)) = E_Variable
8442 Ekind (Entity (N1)) = E_Constant)
8443 and then Entity (N1) = Entity (N2)
8447 -- Second case, selected component with same selector, same record
8449 elsif K1 = N_Selected_Component
8450 and then K2 = N_Selected_Component
8451 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8453 return Same_Object (Prefix (N1), Prefix (N2));
8455 -- Third case, indexed component with same subscripts, same array
8457 elsif K1 = N_Indexed_Component
8458 and then K2 = N_Indexed_Component
8459 and then Same_Object (Prefix (N1), Prefix (N2))
8464 E1 := First (Expressions (N1));
8465 E2 := First (Expressions (N2));
8466 while Present (E1) loop
8467 if not Same_Value (E1, E2) then
8478 -- Fourth case, slice of same array with same bounds
8481 and then K2 = N_Slice
8482 and then Nkind (Discrete_Range (N1)) = N_Range
8483 and then Nkind (Discrete_Range (N2)) = N_Range
8484 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8485 Low_Bound (Discrete_Range (N2)))
8486 and then Same_Value (High_Bound (Discrete_Range (N1)),
8487 High_Bound (Discrete_Range (N2)))
8489 return Same_Name (Prefix (N1), Prefix (N2));
8491 -- All other cases, not clearly the same object
8502 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8507 elsif not Is_Constrained (T1)
8508 and then not Is_Constrained (T2)
8509 and then Base_Type (T1) = Base_Type (T2)
8513 -- For now don't bother with case of identical constraints, to be
8514 -- fiddled with later on perhaps (this is only used for optimization
8515 -- purposes, so it is not critical to do a best possible job)
8526 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8528 if Compile_Time_Known_Value (Node1)
8529 and then Compile_Time_Known_Value (Node2)
8530 and then Expr_Value (Node1) = Expr_Value (Node2)
8533 elsif Same_Object (Node1, Node2) then
8540 ------------------------
8541 -- Scope_Is_Transient --
8542 ------------------------
8544 function Scope_Is_Transient return Boolean is
8546 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8547 end Scope_Is_Transient;
8553 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8558 while Scop /= Standard_Standard loop
8559 Scop := Scope (Scop);
8561 if Scop = Scope2 then
8569 --------------------------
8570 -- Scope_Within_Or_Same --
8571 --------------------------
8573 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8578 while Scop /= Standard_Standard loop
8579 if Scop = Scope2 then
8582 Scop := Scope (Scop);
8587 end Scope_Within_Or_Same;
8589 ------------------------
8590 -- Set_Current_Entity --
8591 ------------------------
8593 -- The given entity is to be set as the currently visible definition
8594 -- of its associated name (i.e. the Node_Id associated with its name).
8595 -- All we have to do is to get the name from the identifier, and
8596 -- then set the associated Node_Id to point to the given entity.
8598 procedure Set_Current_Entity (E : Entity_Id) is
8600 Set_Name_Entity_Id (Chars (E), E);
8601 end Set_Current_Entity;
8603 ---------------------------------
8604 -- Set_Entity_With_Style_Check --
8605 ---------------------------------
8607 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
8608 Val_Actual : Entity_Id;
8612 Set_Entity (N, Val);
8615 and then not Suppress_Style_Checks (Val)
8616 and then not In_Instance
8618 if Nkind (N) = N_Identifier then
8620 elsif Nkind (N) = N_Expanded_Name then
8621 Nod := Selector_Name (N);
8626 -- A special situation arises for derived operations, where we want
8627 -- to do the check against the parent (since the Sloc of the derived
8628 -- operation points to the derived type declaration itself).
8631 while not Comes_From_Source (Val_Actual)
8632 and then Nkind (Val_Actual) in N_Entity
8633 and then (Ekind (Val_Actual) = E_Enumeration_Literal
8634 or else Is_Subprogram (Val_Actual)
8635 or else Is_Generic_Subprogram (Val_Actual))
8636 and then Present (Alias (Val_Actual))
8638 Val_Actual := Alias (Val_Actual);
8641 -- Renaming declarations for generic actuals do not come from source,
8642 -- and have a different name from that of the entity they rename, so
8643 -- there is no style check to perform here.
8645 if Chars (Nod) = Chars (Val_Actual) then
8646 Style.Check_Identifier (Nod, Val_Actual);
8650 Set_Entity (N, Val);
8651 end Set_Entity_With_Style_Check;
8653 ------------------------
8654 -- Set_Name_Entity_Id --
8655 ------------------------
8657 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
8659 Set_Name_Table_Info (Id, Int (Val));
8660 end Set_Name_Entity_Id;
8662 ---------------------
8663 -- Set_Next_Actual --
8664 ---------------------
8666 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
8668 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
8669 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
8671 end Set_Next_Actual;
8673 -----------------------
8674 -- Set_Public_Status --
8675 -----------------------
8677 procedure Set_Public_Status (Id : Entity_Id) is
8678 S : constant Entity_Id := Current_Scope;
8681 -- Everything in the scope of Standard is public
8683 if S = Standard_Standard then
8686 -- Entity is definitely not public if enclosing scope is not public
8688 elsif not Is_Public (S) then
8691 -- An object declaration that occurs in a handled sequence of statements
8692 -- is the declaration for a temporary object generated by the expander.
8693 -- It never needs to be made public and furthermore, making it public
8694 -- can cause back end problems if it is of variable size.
8696 elsif Nkind (Parent (Id)) = N_Object_Declaration
8698 Nkind (Parent (Parent (Id))) = N_Handled_Sequence_Of_Statements
8702 -- Entities in public packages or records are public
8704 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
8707 -- The bounds of an entry family declaration can generate object
8708 -- declarations that are visible to the back-end, e.g. in the
8709 -- the declaration of a composite type that contains tasks.
8711 elsif Is_Concurrent_Type (S)
8712 and then not Has_Completion (S)
8713 and then Nkind (Parent (Id)) = N_Object_Declaration
8717 end Set_Public_Status;
8719 ----------------------------
8720 -- Set_Scope_Is_Transient --
8721 ----------------------------
8723 procedure Set_Scope_Is_Transient (V : Boolean := True) is
8725 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
8726 end Set_Scope_Is_Transient;
8732 procedure Set_Size_Info (T1, T2 : Entity_Id) is
8734 -- We copy Esize, but not RM_Size, since in general RM_Size is
8735 -- subtype specific and does not get inherited by all subtypes.
8737 Set_Esize (T1, Esize (T2));
8738 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
8740 if Is_Discrete_Or_Fixed_Point_Type (T1)
8742 Is_Discrete_Or_Fixed_Point_Type (T2)
8744 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
8747 Set_Alignment (T1, Alignment (T2));
8750 --------------------
8751 -- Static_Integer --
8752 --------------------
8754 function Static_Integer (N : Node_Id) return Uint is
8756 Analyze_And_Resolve (N, Any_Integer);
8759 or else Error_Posted (N)
8760 or else Etype (N) = Any_Type
8765 if Is_Static_Expression (N) then
8766 if not Raises_Constraint_Error (N) then
8767 return Expr_Value (N);
8772 elsif Etype (N) = Any_Type then
8776 Flag_Non_Static_Expr
8777 ("static integer expression required here", N);
8782 --------------------------
8783 -- Statically_Different --
8784 --------------------------
8786 function Statically_Different (E1, E2 : Node_Id) return Boolean is
8787 R1 : constant Node_Id := Get_Referenced_Object (E1);
8788 R2 : constant Node_Id := Get_Referenced_Object (E2);
8790 return Is_Entity_Name (R1)
8791 and then Is_Entity_Name (R2)
8792 and then Entity (R1) /= Entity (R2)
8793 and then not Is_Formal (Entity (R1))
8794 and then not Is_Formal (Entity (R2));
8795 end Statically_Different;
8797 -----------------------------
8798 -- Subprogram_Access_Level --
8799 -----------------------------
8801 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
8803 if Present (Alias (Subp)) then
8804 return Subprogram_Access_Level (Alias (Subp));
8806 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
8808 end Subprogram_Access_Level;
8814 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
8816 if Debug_Flag_W then
8817 for J in 0 .. Scope_Stack.Last loop
8822 Write_Name (Chars (E));
8823 Write_Str (" line ");
8824 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
8829 -----------------------
8830 -- Transfer_Entities --
8831 -----------------------
8833 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
8834 Ent : Entity_Id := First_Entity (From);
8841 if (Last_Entity (To)) = Empty then
8842 Set_First_Entity (To, Ent);
8844 Set_Next_Entity (Last_Entity (To), Ent);
8847 Set_Last_Entity (To, Last_Entity (From));
8849 while Present (Ent) loop
8850 Set_Scope (Ent, To);
8852 if not Is_Public (Ent) then
8853 Set_Public_Status (Ent);
8856 and then Ekind (Ent) = E_Record_Subtype
8859 -- The components of the propagated Itype must be public
8865 Comp := First_Entity (Ent);
8866 while Present (Comp) loop
8867 Set_Is_Public (Comp);
8877 Set_First_Entity (From, Empty);
8878 Set_Last_Entity (From, Empty);
8879 end Transfer_Entities;
8881 -----------------------
8882 -- Type_Access_Level --
8883 -----------------------
8885 function Type_Access_Level (Typ : Entity_Id) return Uint is
8889 Btyp := Base_Type (Typ);
8891 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
8892 -- simply use the level where the type is declared. This is true for
8893 -- stand-alone object declarations, and for anonymous access types
8894 -- associated with components the level is the same as that of the
8895 -- enclosing composite type. However, special treatment is needed for
8896 -- the cases of access parameters, return objects of an anonymous access
8897 -- type, and, in Ada 95, access discriminants of limited types.
8899 if Ekind (Btyp) in Access_Kind then
8900 if Ekind (Btyp) = E_Anonymous_Access_Type then
8902 -- If the type is a nonlocal anonymous access type (such as for
8903 -- an access parameter) we treat it as being declared at the
8904 -- library level to ensure that names such as X.all'access don't
8905 -- fail static accessibility checks.
8907 if not Is_Local_Anonymous_Access (Typ) then
8908 return Scope_Depth (Standard_Standard);
8910 -- If this is a return object, the accessibility level is that of
8911 -- the result subtype of the enclosing function. The test here is
8912 -- little complicated, because we have to account for extended
8913 -- return statements that have been rewritten as blocks, in which
8914 -- case we have to find and the Is_Return_Object attribute of the
8915 -- itype's associated object. It would be nice to find a way to
8916 -- simplify this test, but it doesn't seem worthwhile to add a new
8917 -- flag just for purposes of this test. ???
8919 elsif Ekind (Scope (Btyp)) = E_Return_Statement
8922 and then Nkind (Associated_Node_For_Itype (Btyp)) =
8923 N_Object_Declaration
8924 and then Is_Return_Object
8925 (Defining_Identifier
8926 (Associated_Node_For_Itype (Btyp))))
8932 Scop := Scope (Scope (Btyp));
8933 while Present (Scop) loop
8934 exit when Ekind (Scop) = E_Function;
8935 Scop := Scope (Scop);
8938 -- Treat the return object's type as having the level of the
8939 -- function's result subtype (as per RM05-6.5(5.3/2)).
8941 return Type_Access_Level (Etype (Scop));
8946 Btyp := Root_Type (Btyp);
8948 -- The accessibility level of anonymous acccess types associated with
8949 -- discriminants is that of the current instance of the type, and
8950 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
8952 -- AI-402: access discriminants have accessibility based on the
8953 -- object rather than the type in Ada 2005, so the above paragraph
8956 -- ??? Needs completion with rules from AI-416
8958 if Ada_Version <= Ada_95
8959 and then Ekind (Typ) = E_Anonymous_Access_Type
8960 and then Present (Associated_Node_For_Itype (Typ))
8961 and then Nkind (Associated_Node_For_Itype (Typ)) =
8962 N_Discriminant_Specification
8964 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
8968 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
8969 end Type_Access_Level;
8971 --------------------------
8972 -- Unit_Declaration_Node --
8973 --------------------------
8975 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
8976 N : Node_Id := Parent (Unit_Id);
8979 -- Predefined operators do not have a full function declaration
8981 if Ekind (Unit_Id) = E_Operator then
8985 -- Isn't there some better way to express the following ???
8987 while Nkind (N) /= N_Abstract_Subprogram_Declaration
8988 and then Nkind (N) /= N_Formal_Package_Declaration
8989 and then Nkind (N) /= N_Function_Instantiation
8990 and then Nkind (N) /= N_Generic_Package_Declaration
8991 and then Nkind (N) /= N_Generic_Subprogram_Declaration
8992 and then Nkind (N) /= N_Package_Declaration
8993 and then Nkind (N) /= N_Package_Body
8994 and then Nkind (N) /= N_Package_Instantiation
8995 and then Nkind (N) /= N_Package_Renaming_Declaration
8996 and then Nkind (N) /= N_Procedure_Instantiation
8997 and then Nkind (N) /= N_Protected_Body
8998 and then Nkind (N) /= N_Subprogram_Declaration
8999 and then Nkind (N) /= N_Subprogram_Body
9000 and then Nkind (N) /= N_Subprogram_Body_Stub
9001 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9002 and then Nkind (N) /= N_Task_Body
9003 and then Nkind (N) /= N_Task_Type_Declaration
9004 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9005 and then Nkind (N) not in N_Generic_Renaming_Declaration
9008 pragma Assert (Present (N));
9012 end Unit_Declaration_Node;
9014 ------------------------------
9015 -- Universal_Interpretation --
9016 ------------------------------
9018 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9019 Index : Interp_Index;
9023 -- The argument may be a formal parameter of an operator or subprogram
9024 -- with multiple interpretations, or else an expression for an actual.
9026 if Nkind (Opnd) = N_Defining_Identifier
9027 or else not Is_Overloaded (Opnd)
9029 if Etype (Opnd) = Universal_Integer
9030 or else Etype (Opnd) = Universal_Real
9032 return Etype (Opnd);
9038 Get_First_Interp (Opnd, Index, It);
9039 while Present (It.Typ) loop
9040 if It.Typ = Universal_Integer
9041 or else It.Typ = Universal_Real
9046 Get_Next_Interp (Index, It);
9051 end Universal_Interpretation;
9057 function Unqualify (Expr : Node_Id) return Node_Id is
9059 -- Recurse to handle unlikely case of multiple levels of qualification
9061 if Nkind (Expr) = N_Qualified_Expression then
9062 return Unqualify (Expression (Expr));
9064 -- Normal case, not a qualified expression
9071 ----------------------
9072 -- Within_Init_Proc --
9073 ----------------------
9075 function Within_Init_Proc return Boolean is
9080 while not Is_Overloadable (S) loop
9081 if S = Standard_Standard then
9088 return Is_Init_Proc (S);
9089 end Within_Init_Proc;
9095 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9096 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9097 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9099 function Has_One_Matching_Field return Boolean;
9100 -- Determines if Expec_Type is a record type with a single component or
9101 -- discriminant whose type matches the found type or is one dimensional
9102 -- array whose component type matches the found type.
9104 ----------------------------
9105 -- Has_One_Matching_Field --
9106 ----------------------------
9108 function Has_One_Matching_Field return Boolean is
9112 if Is_Array_Type (Expec_Type)
9113 and then Number_Dimensions (Expec_Type) = 1
9115 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9119 elsif not Is_Record_Type (Expec_Type) then
9123 E := First_Entity (Expec_Type);
9128 elsif (Ekind (E) /= E_Discriminant
9129 and then Ekind (E) /= E_Component)
9130 or else (Chars (E) = Name_uTag
9131 or else Chars (E) = Name_uParent)
9140 if not Covers (Etype (E), Found_Type) then
9143 elsif Present (Next_Entity (E)) then
9150 end Has_One_Matching_Field;
9152 -- Start of processing for Wrong_Type
9155 -- Don't output message if either type is Any_Type, or if a message
9156 -- has already been posted for this node. We need to do the latter
9157 -- check explicitly (it is ordinarily done in Errout), because we
9158 -- are using ! to force the output of the error messages.
9160 if Expec_Type = Any_Type
9161 or else Found_Type = Any_Type
9162 or else Error_Posted (Expr)
9166 -- In an instance, there is an ongoing problem with completion of
9167 -- type derived from private types. Their structure is what Gigi
9168 -- expects, but the Etype is the parent type rather than the
9169 -- derived private type itself. Do not flag error in this case. The
9170 -- private completion is an entity without a parent, like an Itype.
9171 -- Similarly, full and partial views may be incorrect in the instance.
9172 -- There is no simple way to insure that it is consistent ???
9174 elsif In_Instance then
9175 if Etype (Etype (Expr)) = Etype (Expected_Type)
9177 (Has_Private_Declaration (Expected_Type)
9178 or else Has_Private_Declaration (Etype (Expr)))
9179 and then No (Parent (Expected_Type))
9185 -- An interesting special check. If the expression is parenthesized
9186 -- and its type corresponds to the type of the sole component of the
9187 -- expected record type, or to the component type of the expected one
9188 -- dimensional array type, then assume we have a bad aggregate attempt.
9190 if Nkind (Expr) in N_Subexpr
9191 and then Paren_Count (Expr) /= 0
9192 and then Has_One_Matching_Field
9194 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9196 -- Another special check, if we are looking for a pool-specific access
9197 -- type and we found an E_Access_Attribute_Type, then we have the case
9198 -- of an Access attribute being used in a context which needs a pool-
9199 -- specific type, which is never allowed. The one extra check we make
9200 -- is that the expected designated type covers the Found_Type.
9202 elsif Is_Access_Type (Expec_Type)
9203 and then Ekind (Found_Type) = E_Access_Attribute_Type
9204 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9205 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9207 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9209 Error_Msg_N ("result must be general access type!", Expr);
9210 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9212 -- Another special check, if the expected type is an integer type,
9213 -- but the expression is of type System.Address, and the parent is
9214 -- an addition or subtraction operation whose left operand is the
9215 -- expression in question and whose right operand is of an integral
9216 -- type, then this is an attempt at address arithmetic, so give
9217 -- appropriate message.
9219 elsif Is_Integer_Type (Expec_Type)
9220 and then Is_RTE (Found_Type, RE_Address)
9221 and then (Nkind (Parent (Expr)) = N_Op_Add
9223 Nkind (Parent (Expr)) = N_Op_Subtract)
9224 and then Expr = Left_Opnd (Parent (Expr))
9225 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9228 ("address arithmetic not predefined in package System",
9231 ("\possible missing with/use of System.Storage_Elements",
9235 -- If the expected type is an anonymous access type, as for access
9236 -- parameters and discriminants, the error is on the designated types.
9238 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9239 if Comes_From_Source (Expec_Type) then
9240 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9243 ("expected an access type with designated}",
9244 Expr, Designated_Type (Expec_Type));
9247 if Is_Access_Type (Found_Type)
9248 and then not Comes_From_Source (Found_Type)
9251 ("\\found an access type with designated}!",
9252 Expr, Designated_Type (Found_Type));
9254 if From_With_Type (Found_Type) then
9255 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9256 Error_Msg_Qual_Level := 99;
9257 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9258 Error_Msg_Qual_Level := 0;
9260 Error_Msg_NE ("found}!", Expr, Found_Type);
9264 -- Normal case of one type found, some other type expected
9267 -- If the names of the two types are the same, see if some number
9268 -- of levels of qualification will help. Don't try more than three
9269 -- levels, and if we get to standard, it's no use (and probably
9270 -- represents an error in the compiler) Also do not bother with
9271 -- internal scope names.
9274 Expec_Scope : Entity_Id;
9275 Found_Scope : Entity_Id;
9278 Expec_Scope := Expec_Type;
9279 Found_Scope := Found_Type;
9281 for Levels in Int range 0 .. 3 loop
9282 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9283 Error_Msg_Qual_Level := Levels;
9287 Expec_Scope := Scope (Expec_Scope);
9288 Found_Scope := Scope (Found_Scope);
9290 exit when Expec_Scope = Standard_Standard
9291 or else Found_Scope = Standard_Standard
9292 or else not Comes_From_Source (Expec_Scope)
9293 or else not Comes_From_Source (Found_Scope);
9297 if Is_Record_Type (Expec_Type)
9298 and then Present (Corresponding_Remote_Type (Expec_Type))
9300 Error_Msg_NE ("expected}!", Expr,
9301 Corresponding_Remote_Type (Expec_Type));
9303 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9306 if Is_Entity_Name (Expr)
9307 and then Is_Package_Or_Generic_Package (Entity (Expr))
9309 Error_Msg_N ("\\found package name!", Expr);
9311 elsif Is_Entity_Name (Expr)
9313 (Ekind (Entity (Expr)) = E_Procedure
9315 Ekind (Entity (Expr)) = E_Generic_Procedure)
9317 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9319 ("found procedure name, possibly missing Access attribute!",
9323 ("\\found procedure name instead of function!", Expr);
9326 elsif Nkind (Expr) = N_Function_Call
9327 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9328 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9329 and then No (Parameter_Associations (Expr))
9332 ("found function name, possibly missing Access attribute!",
9335 -- Catch common error: a prefix or infix operator which is not
9336 -- directly visible because the type isn't.
9338 elsif Nkind (Expr) in N_Op
9339 and then Is_Overloaded (Expr)
9340 and then not Is_Immediately_Visible (Expec_Type)
9341 and then not Is_Potentially_Use_Visible (Expec_Type)
9342 and then not In_Use (Expec_Type)
9343 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9346 ("operator of the type is not directly visible!", Expr);
9348 elsif Ekind (Found_Type) = E_Void
9349 and then Present (Parent (Found_Type))
9350 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9352 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9355 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9358 Error_Msg_Qual_Level := 0;