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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Errout; use Errout;
32 with Elists; use Elists;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Output; use Output;
42 with Rtsfind; use Rtsfind;
43 with Scans; use Scans;
46 with Sem_Attr; use Sem_Attr;
47 with Sem_Ch6; use Sem_Ch6;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Snames; use Snames;
55 with Stand; use Stand;
57 with Stringt; use Stringt;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uname; use Uname;
63 package body Sem_Util is
67 -----------------------
68 -- Local Subprograms --
69 -----------------------
71 function Build_Component_Subtype
74 T : Entity_Id) return Node_Id;
75 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
76 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
77 -- Loc is the source location, T is the original subtype.
79 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
80 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
81 -- with discriminants whose default values are static, examine only the
82 -- components in the selected variant to determine whether all of them
85 function Has_Null_Extension (T : Entity_Id) return Boolean;
86 -- T is a derived tagged type. Check whether the type extension is null.
87 -- If the parent type is fully initialized, T can be treated as such.
89 ------------------------------
90 -- Abstract_Interface_List --
91 ------------------------------
93 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
97 if Is_Concurrent_Type (Typ) then
99 -- If we are dealing with a synchronized subtype, go to the base
100 -- type, whose declaration has the interface list.
102 -- Shouldn't this be Declaration_Node???
104 Nod := Parent (Base_Type (Typ));
106 elsif Ekind (Typ) = E_Record_Type_With_Private then
107 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
108 Nod := Type_Definition (Parent (Typ));
110 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
111 if Present (Full_View (Typ)) then
112 Nod := Type_Definition (Parent (Full_View (Typ)));
114 -- If the full-view is not available we cannot do anything
115 -- else here (the source has errors)
121 -- The support for generic formals with interfaces is still
124 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
129 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
133 elsif Ekind (Typ) = E_Record_Subtype then
134 Nod := Type_Definition (Parent (Etype (Typ)));
136 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
138 -- Recurse, because parent may still be a private extension
140 return Abstract_Interface_List (Etype (Full_View (Typ)));
142 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
143 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
144 Nod := Formal_Type_Definition (Parent (Typ));
146 Nod := Type_Definition (Parent (Typ));
150 return Interface_List (Nod);
151 end Abstract_Interface_List;
153 --------------------------------
154 -- Add_Access_Type_To_Process --
155 --------------------------------
157 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
161 Ensure_Freeze_Node (E);
162 L := Access_Types_To_Process (Freeze_Node (E));
166 Set_Access_Types_To_Process (Freeze_Node (E), L);
170 end Add_Access_Type_To_Process;
172 ----------------------------
173 -- Add_Global_Declaration --
174 ----------------------------
176 procedure Add_Global_Declaration (N : Node_Id) is
177 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
180 if No (Declarations (Aux_Node)) then
181 Set_Declarations (Aux_Node, New_List);
184 Append_To (Declarations (Aux_Node), N);
186 end Add_Global_Declaration;
188 -----------------------
189 -- Alignment_In_Bits --
190 -----------------------
192 function Alignment_In_Bits (E : Entity_Id) return Uint is
194 return Alignment (E) * System_Storage_Unit;
195 end Alignment_In_Bits;
197 -----------------------------------------
198 -- Apply_Compile_Time_Constraint_Error --
199 -----------------------------------------
201 procedure Apply_Compile_Time_Constraint_Error
204 Reason : RT_Exception_Code;
205 Ent : Entity_Id := Empty;
206 Typ : Entity_Id := Empty;
207 Loc : Source_Ptr := No_Location;
208 Rep : Boolean := True;
209 Warn : Boolean := False)
211 Stat : constant Boolean := Is_Static_Expression (N);
222 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
228 -- Now we replace the node by an N_Raise_Constraint_Error node
229 -- This does not need reanalyzing, so set it as analyzed now.
232 Make_Raise_Constraint_Error (Sloc (N),
234 Set_Analyzed (N, True);
236 Set_Raises_Constraint_Error (N);
238 -- If the original expression was marked as static, the result is
239 -- still marked as static, but the Raises_Constraint_Error flag is
240 -- always set so that further static evaluation is not attempted.
243 Set_Is_Static_Expression (N);
245 end Apply_Compile_Time_Constraint_Error;
247 --------------------------
248 -- Build_Actual_Subtype --
249 --------------------------
251 function Build_Actual_Subtype
253 N : Node_Or_Entity_Id) return Node_Id
256 -- Normally Sloc (N), but may point to corresponding body in some cases
258 Constraints : List_Id;
264 Disc_Type : Entity_Id;
270 if Nkind (N) = N_Defining_Identifier then
271 Obj := New_Reference_To (N, Loc);
273 -- If this is a formal parameter of a subprogram declaration, and
274 -- we are compiling the body, we want the declaration for the
275 -- actual subtype to carry the source position of the body, to
276 -- prevent anomalies in gdb when stepping through the code.
278 if Is_Formal (N) then
280 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
282 if Nkind (Decl) = N_Subprogram_Declaration
283 and then Present (Corresponding_Body (Decl))
285 Loc := Sloc (Corresponding_Body (Decl));
294 if Is_Array_Type (T) then
295 Constraints := New_List;
296 for J in 1 .. Number_Dimensions (T) loop
298 -- Build an array subtype declaration with the nominal subtype and
299 -- the bounds of the actual. Add the declaration in front of the
300 -- local declarations for the subprogram, for analysis before any
301 -- reference to the formal in the body.
304 Make_Attribute_Reference (Loc,
306 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
307 Attribute_Name => Name_First,
308 Expressions => New_List (
309 Make_Integer_Literal (Loc, J)));
312 Make_Attribute_Reference (Loc,
314 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
315 Attribute_Name => Name_Last,
316 Expressions => New_List (
317 Make_Integer_Literal (Loc, J)));
319 Append (Make_Range (Loc, Lo, Hi), Constraints);
322 -- If the type has unknown discriminants there is no constrained
323 -- subtype to build. This is never called for a formal or for a
324 -- lhs, so returning the type is ok ???
326 elsif Has_Unknown_Discriminants (T) then
330 Constraints := New_List;
332 if Is_Private_Type (T) and then No (Full_View (T)) then
334 -- Type is a generic derived type. Inherit discriminants from
337 Disc_Type := Etype (Base_Type (T));
342 Discr := First_Discriminant (Disc_Type);
343 while Present (Discr) loop
344 Append_To (Constraints,
345 Make_Selected_Component (Loc,
347 Duplicate_Subexpr_No_Checks (Obj),
348 Selector_Name => New_Occurrence_Of (Discr, Loc)));
349 Next_Discriminant (Discr);
354 Make_Defining_Identifier (Loc,
355 Chars => New_Internal_Name ('S'));
356 Set_Is_Internal (Subt);
359 Make_Subtype_Declaration (Loc,
360 Defining_Identifier => Subt,
361 Subtype_Indication =>
362 Make_Subtype_Indication (Loc,
363 Subtype_Mark => New_Reference_To (T, Loc),
365 Make_Index_Or_Discriminant_Constraint (Loc,
366 Constraints => Constraints)));
368 Mark_Rewrite_Insertion (Decl);
370 end Build_Actual_Subtype;
372 ---------------------------------------
373 -- Build_Actual_Subtype_Of_Component --
374 ---------------------------------------
376 function Build_Actual_Subtype_Of_Component
378 N : Node_Id) return Node_Id
380 Loc : constant Source_Ptr := Sloc (N);
381 P : constant Node_Id := Prefix (N);
384 Indx_Type : Entity_Id;
386 Deaccessed_T : Entity_Id;
387 -- This is either a copy of T, or if T is an access type, then it is
388 -- the directly designated type of this access type.
390 function Build_Actual_Array_Constraint return List_Id;
391 -- If one or more of the bounds of the component depends on
392 -- discriminants, build actual constraint using the discriminants
395 function Build_Actual_Record_Constraint return List_Id;
396 -- Similar to previous one, for discriminated components constrained
397 -- by the discriminant of the enclosing object.
399 -----------------------------------
400 -- Build_Actual_Array_Constraint --
401 -----------------------------------
403 function Build_Actual_Array_Constraint return List_Id is
404 Constraints : constant List_Id := New_List;
412 Indx := First_Index (Deaccessed_T);
413 while Present (Indx) loop
414 Old_Lo := Type_Low_Bound (Etype (Indx));
415 Old_Hi := Type_High_Bound (Etype (Indx));
417 if Denotes_Discriminant (Old_Lo) then
419 Make_Selected_Component (Loc,
420 Prefix => New_Copy_Tree (P),
421 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
424 Lo := New_Copy_Tree (Old_Lo);
426 -- The new bound will be reanalyzed in the enclosing
427 -- declaration. For literal bounds that come from a type
428 -- declaration, the type of the context must be imposed, so
429 -- insure that analysis will take place. For non-universal
430 -- types this is not strictly necessary.
432 Set_Analyzed (Lo, False);
435 if Denotes_Discriminant (Old_Hi) then
437 Make_Selected_Component (Loc,
438 Prefix => New_Copy_Tree (P),
439 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
442 Hi := New_Copy_Tree (Old_Hi);
443 Set_Analyzed (Hi, False);
446 Append (Make_Range (Loc, Lo, Hi), Constraints);
451 end Build_Actual_Array_Constraint;
453 ------------------------------------
454 -- Build_Actual_Record_Constraint --
455 ------------------------------------
457 function Build_Actual_Record_Constraint return List_Id is
458 Constraints : constant List_Id := New_List;
463 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
464 while Present (D) loop
465 if Denotes_Discriminant (Node (D)) then
466 D_Val := Make_Selected_Component (Loc,
467 Prefix => New_Copy_Tree (P),
468 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
471 D_Val := New_Copy_Tree (Node (D));
474 Append (D_Val, Constraints);
479 end Build_Actual_Record_Constraint;
481 -- Start of processing for Build_Actual_Subtype_Of_Component
484 if In_Default_Expression then
487 elsif Nkind (N) = N_Explicit_Dereference then
488 if Is_Composite_Type (T)
489 and then not Is_Constrained (T)
490 and then not (Is_Class_Wide_Type (T)
491 and then Is_Constrained (Root_Type (T)))
492 and then not Has_Unknown_Discriminants (T)
494 -- If the type of the dereference is already constrained, it
495 -- is an actual subtype.
497 if Is_Array_Type (Etype (N))
498 and then Is_Constrained (Etype (N))
502 Remove_Side_Effects (P);
503 return Build_Actual_Subtype (T, N);
510 if Ekind (T) = E_Access_Subtype then
511 Deaccessed_T := Designated_Type (T);
516 if Ekind (Deaccessed_T) = E_Array_Subtype then
517 Id := First_Index (Deaccessed_T);
518 while Present (Id) loop
519 Indx_Type := Underlying_Type (Etype (Id));
521 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
522 Denotes_Discriminant (Type_High_Bound (Indx_Type))
524 Remove_Side_Effects (P);
526 Build_Component_Subtype (
527 Build_Actual_Array_Constraint, Loc, Base_Type (T));
533 elsif Is_Composite_Type (Deaccessed_T)
534 and then Has_Discriminants (Deaccessed_T)
535 and then not Has_Unknown_Discriminants (Deaccessed_T)
537 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
538 while Present (D) loop
539 if Denotes_Discriminant (Node (D)) then
540 Remove_Side_Effects (P);
542 Build_Component_Subtype (
543 Build_Actual_Record_Constraint, Loc, Base_Type (T));
550 -- If none of the above, the actual and nominal subtypes are the same
553 end Build_Actual_Subtype_Of_Component;
555 -----------------------------
556 -- Build_Component_Subtype --
557 -----------------------------
559 function Build_Component_Subtype
562 T : Entity_Id) return Node_Id
568 -- Unchecked_Union components do not require component subtypes
570 if Is_Unchecked_Union (T) then
575 Make_Defining_Identifier (Loc,
576 Chars => New_Internal_Name ('S'));
577 Set_Is_Internal (Subt);
580 Make_Subtype_Declaration (Loc,
581 Defining_Identifier => Subt,
582 Subtype_Indication =>
583 Make_Subtype_Indication (Loc,
584 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
586 Make_Index_Or_Discriminant_Constraint (Loc,
589 Mark_Rewrite_Insertion (Decl);
591 end Build_Component_Subtype;
593 ---------------------------
594 -- Build_Default_Subtype --
595 ---------------------------
597 function Build_Default_Subtype
599 N : Node_Id) return Entity_Id
601 Loc : constant Source_Ptr := Sloc (N);
605 if not Has_Discriminants (T) or else Is_Constrained (T) then
609 Disc := First_Discriminant (T);
611 if No (Discriminant_Default_Value (Disc)) then
616 Act : constant Entity_Id :=
617 Make_Defining_Identifier (Loc,
618 Chars => New_Internal_Name ('S'));
620 Constraints : constant List_Id := New_List;
624 while Present (Disc) loop
625 Append_To (Constraints,
626 New_Copy_Tree (Discriminant_Default_Value (Disc)));
627 Next_Discriminant (Disc);
631 Make_Subtype_Declaration (Loc,
632 Defining_Identifier => Act,
633 Subtype_Indication =>
634 Make_Subtype_Indication (Loc,
635 Subtype_Mark => New_Occurrence_Of (T, Loc),
637 Make_Index_Or_Discriminant_Constraint (Loc,
638 Constraints => Constraints)));
640 Insert_Action (N, Decl);
644 end Build_Default_Subtype;
646 --------------------------------------------
647 -- Build_Discriminal_Subtype_Of_Component --
648 --------------------------------------------
650 function Build_Discriminal_Subtype_Of_Component
651 (T : Entity_Id) return Node_Id
653 Loc : constant Source_Ptr := Sloc (T);
657 function Build_Discriminal_Array_Constraint return List_Id;
658 -- If one or more of the bounds of the component depends on
659 -- discriminants, build actual constraint using the discriminants
662 function Build_Discriminal_Record_Constraint return List_Id;
663 -- Similar to previous one, for discriminated components constrained
664 -- by the discriminant of the enclosing object.
666 ----------------------------------------
667 -- Build_Discriminal_Array_Constraint --
668 ----------------------------------------
670 function Build_Discriminal_Array_Constraint return List_Id is
671 Constraints : constant List_Id := New_List;
679 Indx := First_Index (T);
680 while Present (Indx) loop
681 Old_Lo := Type_Low_Bound (Etype (Indx));
682 Old_Hi := Type_High_Bound (Etype (Indx));
684 if Denotes_Discriminant (Old_Lo) then
685 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
688 Lo := New_Copy_Tree (Old_Lo);
691 if Denotes_Discriminant (Old_Hi) then
692 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
695 Hi := New_Copy_Tree (Old_Hi);
698 Append (Make_Range (Loc, Lo, Hi), Constraints);
703 end Build_Discriminal_Array_Constraint;
705 -----------------------------------------
706 -- Build_Discriminal_Record_Constraint --
707 -----------------------------------------
709 function Build_Discriminal_Record_Constraint return List_Id is
710 Constraints : constant List_Id := New_List;
715 D := First_Elmt (Discriminant_Constraint (T));
716 while Present (D) loop
717 if Denotes_Discriminant (Node (D)) then
719 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
722 D_Val := New_Copy_Tree (Node (D));
725 Append (D_Val, Constraints);
730 end Build_Discriminal_Record_Constraint;
732 -- Start of processing for Build_Discriminal_Subtype_Of_Component
735 if Ekind (T) = E_Array_Subtype then
736 Id := First_Index (T);
737 while Present (Id) loop
738 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
739 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
741 return Build_Component_Subtype
742 (Build_Discriminal_Array_Constraint, Loc, T);
748 elsif Ekind (T) = E_Record_Subtype
749 and then Has_Discriminants (T)
750 and then not Has_Unknown_Discriminants (T)
752 D := First_Elmt (Discriminant_Constraint (T));
753 while Present (D) loop
754 if Denotes_Discriminant (Node (D)) then
755 return Build_Component_Subtype
756 (Build_Discriminal_Record_Constraint, Loc, T);
763 -- If none of the above, the actual and nominal subtypes are the same
766 end Build_Discriminal_Subtype_Of_Component;
768 ------------------------------
769 -- Build_Elaboration_Entity --
770 ------------------------------
772 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
773 Loc : constant Source_Ptr := Sloc (N);
775 Elab_Ent : Entity_Id;
777 procedure Set_Package_Name (Ent : Entity_Id);
778 -- Given an entity, sets the fully qualified name of the entity in
779 -- Name_Buffer, with components separated by double underscores. This
780 -- is a recursive routine that climbs the scope chain to Standard.
782 ----------------------
783 -- Set_Package_Name --
784 ----------------------
786 procedure Set_Package_Name (Ent : Entity_Id) is
788 if Scope (Ent) /= Standard_Standard then
789 Set_Package_Name (Scope (Ent));
792 Nam : constant String := Get_Name_String (Chars (Ent));
794 Name_Buffer (Name_Len + 1) := '_';
795 Name_Buffer (Name_Len + 2) := '_';
796 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
797 Name_Len := Name_Len + Nam'Length + 2;
801 Get_Name_String (Chars (Ent));
803 end Set_Package_Name;
805 -- Start of processing for Build_Elaboration_Entity
808 -- Ignore if already constructed
810 if Present (Elaboration_Entity (Spec_Id)) then
814 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
815 -- name with dots replaced by double underscore. We have to manually
816 -- construct this name, since it will be elaborated in the outer scope,
817 -- and thus will not have the unit name automatically prepended.
819 Set_Package_Name (Spec_Id);
823 Name_Buffer (Name_Len + 1) := '_';
824 Name_Buffer (Name_Len + 2) := 'E';
825 Name_Len := Name_Len + 2;
827 -- Create elaboration flag
830 Make_Defining_Identifier (Loc, Chars => Name_Find);
831 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
834 Make_Object_Declaration (Loc,
835 Defining_Identifier => Elab_Ent,
837 New_Occurrence_Of (Standard_Boolean, Loc),
839 New_Occurrence_Of (Standard_False, Loc));
841 Push_Scope (Standard_Standard);
842 Add_Global_Declaration (Decl);
845 -- Reset True_Constant indication, since we will indeed assign a value
846 -- to the variable in the binder main. We also kill the Current_Value
847 -- and Last_Assignment fields for the same reason.
849 Set_Is_True_Constant (Elab_Ent, False);
850 Set_Current_Value (Elab_Ent, Empty);
851 Set_Last_Assignment (Elab_Ent, Empty);
853 -- We do not want any further qualification of the name (if we did
854 -- not do this, we would pick up the name of the generic package
855 -- in the case of a library level generic instantiation).
857 Set_Has_Qualified_Name (Elab_Ent);
858 Set_Has_Fully_Qualified_Name (Elab_Ent);
859 end Build_Elaboration_Entity;
861 -----------------------------------
862 -- Cannot_Raise_Constraint_Error --
863 -----------------------------------
865 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
867 if Compile_Time_Known_Value (Expr) then
870 elsif Do_Range_Check (Expr) then
873 elsif Raises_Constraint_Error (Expr) then
881 when N_Expanded_Name =>
884 when N_Selected_Component =>
885 return not Do_Discriminant_Check (Expr);
887 when N_Attribute_Reference =>
888 if Do_Overflow_Check (Expr) then
891 elsif No (Expressions (Expr)) then
899 N := First (Expressions (Expr));
900 while Present (N) loop
901 if Cannot_Raise_Constraint_Error (N) then
912 when N_Type_Conversion =>
913 if Do_Overflow_Check (Expr)
914 or else Do_Length_Check (Expr)
915 or else Do_Tag_Check (Expr)
920 Cannot_Raise_Constraint_Error (Expression (Expr));
923 when N_Unchecked_Type_Conversion =>
924 return Cannot_Raise_Constraint_Error (Expression (Expr));
927 if Do_Overflow_Check (Expr) then
931 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
938 if Do_Division_Check (Expr)
939 or else Do_Overflow_Check (Expr)
944 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
946 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
965 N_Op_Shift_Right_Arithmetic |
969 if Do_Overflow_Check (Expr) then
973 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
975 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
982 end Cannot_Raise_Constraint_Error;
984 --------------------------
985 -- Check_Fully_Declared --
986 --------------------------
988 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
990 if Ekind (T) = E_Incomplete_Type then
992 -- Ada 2005 (AI-50217): If the type is available through a limited
993 -- with_clause, verify that its full view has been analyzed.
995 if From_With_Type (T)
996 and then Present (Non_Limited_View (T))
997 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
999 -- The non-limited view is fully declared
1004 ("premature usage of incomplete}", N, First_Subtype (T));
1007 elsif Has_Private_Component (T)
1008 and then not Is_Generic_Type (Root_Type (T))
1009 and then not In_Default_Expression
1012 -- Special case: if T is the anonymous type created for a single
1013 -- task or protected object, use the name of the source object.
1015 if Is_Concurrent_Type (T)
1016 and then not Comes_From_Source (T)
1017 and then Nkind (N) = N_Object_Declaration
1019 Error_Msg_NE ("type of& has incomplete component", N,
1020 Defining_Identifier (N));
1024 ("premature usage of incomplete}", N, First_Subtype (T));
1027 end Check_Fully_Declared;
1029 -------------------------
1030 -- Check_Nested_Access --
1031 -------------------------
1033 procedure Check_Nested_Access (Ent : Entity_Id) is
1034 Scop : constant Entity_Id := Current_Scope;
1035 Current_Subp : Entity_Id;
1038 -- Currently only enabled for VM back-ends for efficiency, should we
1039 -- enable it more systematically ???
1041 if VM_Target /= No_VM
1042 and then (Ekind (Ent) = E_Variable
1044 Ekind (Ent) = E_Constant
1046 Ekind (Ent) = E_Loop_Parameter)
1047 and then Scope (Ent) /= Empty
1048 and then not Is_Library_Level_Entity (Ent)
1050 if Is_Subprogram (Scop)
1051 or else Is_Generic_Subprogram (Scop)
1052 or else Is_Entry (Scop)
1054 Current_Subp := Scop;
1056 Current_Subp := Current_Subprogram;
1059 if Enclosing_Subprogram (Ent) /= Current_Subp then
1060 Set_Has_Up_Level_Access (Ent, True);
1063 end Check_Nested_Access;
1065 ------------------------------------------
1066 -- Check_Potentially_Blocking_Operation --
1067 ------------------------------------------
1069 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1072 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1073 -- When pragma Detect_Blocking is active, the run time will raise
1074 -- Program_Error. Here we only issue a warning, since we generally
1075 -- support the use of potentially blocking operations in the absence
1078 -- Indirect blocking through a subprogram call cannot be diagnosed
1079 -- statically without interprocedural analysis, so we do not attempt
1082 S := Scope (Current_Scope);
1083 while Present (S) and then S /= Standard_Standard loop
1084 if Is_Protected_Type (S) then
1086 ("potentially blocking operation in protected operation?", N);
1093 end Check_Potentially_Blocking_Operation;
1099 procedure Check_VMS (Construct : Node_Id) is
1101 if not OpenVMS_On_Target then
1103 ("this construct is allowed only in Open'V'M'S", Construct);
1107 ---------------------------------
1108 -- Collect_Abstract_Interfaces --
1109 ---------------------------------
1111 procedure Collect_Abstract_Interfaces
1113 Ifaces_List : out Elist_Id;
1114 Exclude_Parent_Interfaces : Boolean := False;
1115 Use_Full_View : Boolean := True)
1117 procedure Add_Interface (Iface : Entity_Id);
1118 -- Add the interface it if is not already in the list
1120 procedure Collect (Typ : Entity_Id);
1121 -- Subsidiary subprogram used to traverse the whole list
1122 -- of directly and indirectly implemented interfaces
1124 function Interface_Present_In_Parent
1126 Iface : Entity_Id) return Boolean;
1127 -- Typ must be a tagged record type/subtype and Iface must be an
1128 -- abstract interface type. This function is used to check if Typ
1129 -- or some parent of Typ implements Iface.
1135 procedure Add_Interface (Iface : Entity_Id) is
1139 Elmt := First_Elmt (Ifaces_List);
1140 while Present (Elmt) and then Node (Elmt) /= Iface loop
1145 Append_Elmt (Iface, Ifaces_List);
1153 procedure Collect (Typ : Entity_Id) is
1154 Ancestor : Entity_Id;
1156 Iface_List : List_Id;
1163 -- Handle private types
1166 and then Is_Private_Type (Typ)
1167 and then Present (Full_View (Typ))
1169 Full_T := Full_View (Typ);
1172 Iface_List := Abstract_Interface_List (Full_T);
1174 -- Include the ancestor if we are generating the whole list of
1175 -- abstract interfaces.
1177 -- In concurrent types the ancestor interface (if any) is the
1178 -- first element of the list of interface types.
1180 if Is_Concurrent_Type (Full_T)
1181 or else Is_Concurrent_Record_Type (Full_T)
1183 if Is_Non_Empty_List (Iface_List) then
1184 Ancestor := Etype (First (Iface_List));
1187 if not Exclude_Parent_Interfaces then
1188 Add_Interface (Ancestor);
1192 elsif Etype (Full_T) /= Typ
1194 -- Protect the frontend against wrong sources. For example:
1197 -- type A is tagged null record;
1198 -- type B is new A with private;
1199 -- type C is new A with private;
1201 -- type B is new C with null record;
1202 -- type C is new B with null record;
1205 and then Etype (Full_T) /= T
1207 Ancestor := Etype (Full_T);
1210 if Is_Interface (Ancestor)
1211 and then not Exclude_Parent_Interfaces
1213 Add_Interface (Ancestor);
1217 -- Traverse the graph of ancestor interfaces
1219 if Is_Non_Empty_List (Iface_List) then
1220 Id := First (Iface_List);
1222 -- In concurrent types the ancestor interface (if any) is the
1223 -- first element of the list of interface types and we have
1224 -- already processed them while climbing to the root type.
1226 if Is_Concurrent_Type (Full_T)
1227 or else Is_Concurrent_Record_Type (Full_T)
1232 while Present (Id) loop
1233 Iface := Etype (Id);
1235 -- Protect against wrong uses. For example:
1236 -- type I is interface;
1237 -- type O is tagged null record;
1238 -- type Wrong is new I and O with null record; -- ERROR
1240 if Is_Interface (Iface) then
1241 if Exclude_Parent_Interfaces
1242 and then Interface_Present_In_Parent (T, Iface)
1247 Add_Interface (Iface);
1256 ---------------------------------
1257 -- Interface_Present_In_Parent --
1258 ---------------------------------
1260 function Interface_Present_In_Parent
1262 Iface : Entity_Id) return Boolean
1264 Aux : Entity_Id := Typ;
1265 Iface_List : List_Id;
1268 if Is_Concurrent_Type (Typ)
1269 or else Is_Concurrent_Record_Type (Typ)
1271 Iface_List := Abstract_Interface_List (Typ);
1273 if Is_Non_Empty_List (Iface_List) then
1274 Aux := Etype (First (Iface_List));
1280 return Interface_Present_In_Ancestor (Aux, Iface);
1281 end Interface_Present_In_Parent;
1283 -- Start of processing for Collect_Abstract_Interfaces
1286 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1287 Ifaces_List := New_Elmt_List;
1289 end Collect_Abstract_Interfaces;
1291 ----------------------------------
1292 -- Collect_Interface_Components --
1293 ----------------------------------
1295 procedure Collect_Interface_Components
1296 (Tagged_Type : Entity_Id;
1297 Components_List : out Elist_Id)
1299 procedure Collect (Typ : Entity_Id);
1300 -- Subsidiary subprogram used to climb to the parents
1306 procedure Collect (Typ : Entity_Id) is
1307 Tag_Comp : Entity_Id;
1310 if Etype (Typ) /= Typ
1312 -- Protect the frontend against wrong sources. For example:
1315 -- type A is tagged null record;
1316 -- type B is new A with private;
1317 -- type C is new A with private;
1319 -- type B is new C with null record;
1320 -- type C is new B with null record;
1323 and then Etype (Typ) /= Tagged_Type
1325 Collect (Etype (Typ));
1328 -- Collect the components containing tags of secondary dispatch
1331 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1332 while Present (Tag_Comp) loop
1333 pragma Assert (Present (Related_Interface (Tag_Comp)));
1334 Append_Elmt (Tag_Comp, Components_List);
1336 Tag_Comp := Next_Tag_Component (Tag_Comp);
1340 -- Start of processing for Collect_Interface_Components
1343 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1344 and then Is_Tagged_Type (Tagged_Type));
1346 Components_List := New_Elmt_List;
1347 Collect (Tagged_Type);
1348 end Collect_Interface_Components;
1350 -----------------------------
1351 -- Collect_Interfaces_Info --
1352 -----------------------------
1354 procedure Collect_Interfaces_Info
1356 Ifaces_List : out Elist_Id;
1357 Components_List : out Elist_Id;
1358 Tags_List : out Elist_Id)
1360 Comps_List : Elist_Id;
1361 Comp_Elmt : Elmt_Id;
1362 Comp_Iface : Entity_Id;
1363 Iface_Elmt : Elmt_Id;
1366 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1367 -- Search for the secondary tag associated with the interface type
1368 -- Iface that is implemented by T.
1374 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1378 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1380 and then Ekind (Node (ADT)) = E_Constant
1381 and then Related_Interface (Node (ADT)) /= Iface
1386 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1390 -- Start of processing for Collect_Interfaces_Info
1393 Collect_Abstract_Interfaces (T, Ifaces_List);
1394 Collect_Interface_Components (T, Comps_List);
1396 -- Search for the record component and tag associated with each
1397 -- interface type of T.
1399 Components_List := New_Elmt_List;
1400 Tags_List := New_Elmt_List;
1402 Iface_Elmt := First_Elmt (Ifaces_List);
1403 while Present (Iface_Elmt) loop
1404 Iface := Node (Iface_Elmt);
1406 -- Associate the primary tag component and the primary dispatch table
1407 -- with all the interfaces that are parents of T
1409 if Is_Parent (Iface, T) then
1410 Append_Elmt (First_Tag_Component (T), Components_List);
1411 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1413 -- Otherwise search for the tag component and secondary dispatch
1417 Comp_Elmt := First_Elmt (Comps_List);
1418 while Present (Comp_Elmt) loop
1419 Comp_Iface := Related_Interface (Node (Comp_Elmt));
1421 if Comp_Iface = Iface
1422 or else Is_Parent (Iface, Comp_Iface)
1424 Append_Elmt (Node (Comp_Elmt), Components_List);
1425 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1429 Next_Elmt (Comp_Elmt);
1431 pragma Assert (Present (Comp_Elmt));
1434 Next_Elmt (Iface_Elmt);
1436 end Collect_Interfaces_Info;
1438 ----------------------------------
1439 -- Collect_Primitive_Operations --
1440 ----------------------------------
1442 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1443 B_Type : constant Entity_Id := Base_Type (T);
1444 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1445 B_Scope : Entity_Id := Scope (B_Type);
1449 Formal_Derived : Boolean := False;
1453 -- For tagged types, the primitive operations are collected as they
1454 -- are declared, and held in an explicit list which is simply returned.
1456 if Is_Tagged_Type (B_Type) then
1457 return Primitive_Operations (B_Type);
1459 -- An untagged generic type that is a derived type inherits the
1460 -- primitive operations of its parent type. Other formal types only
1461 -- have predefined operators, which are not explicitly represented.
1463 elsif Is_Generic_Type (B_Type) then
1464 if Nkind (B_Decl) = N_Formal_Type_Declaration
1465 and then Nkind (Formal_Type_Definition (B_Decl))
1466 = N_Formal_Derived_Type_Definition
1468 Formal_Derived := True;
1470 return New_Elmt_List;
1474 Op_List := New_Elmt_List;
1476 if B_Scope = Standard_Standard then
1477 if B_Type = Standard_String then
1478 Append_Elmt (Standard_Op_Concat, Op_List);
1480 elsif B_Type = Standard_Wide_String then
1481 Append_Elmt (Standard_Op_Concatw, Op_List);
1487 elsif (Is_Package_Or_Generic_Package (B_Scope)
1489 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1491 or else Is_Derived_Type (B_Type)
1493 -- The primitive operations appear after the base type, except
1494 -- if the derivation happens within the private part of B_Scope
1495 -- and the type is a private type, in which case both the type
1496 -- and some primitive operations may appear before the base
1497 -- type, and the list of candidates starts after the type.
1499 if In_Open_Scopes (B_Scope)
1500 and then Scope (T) = B_Scope
1501 and then In_Private_Part (B_Scope)
1503 Id := Next_Entity (T);
1505 Id := Next_Entity (B_Type);
1508 while Present (Id) loop
1510 -- Note that generic formal subprograms are not
1511 -- considered to be primitive operations and thus
1512 -- are never inherited.
1514 if Is_Overloadable (Id)
1515 and then Nkind (Parent (Parent (Id)))
1516 not in N_Formal_Subprogram_Declaration
1520 if Base_Type (Etype (Id)) = B_Type then
1523 Formal := First_Formal (Id);
1524 while Present (Formal) loop
1525 if Base_Type (Etype (Formal)) = B_Type then
1529 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1531 (Designated_Type (Etype (Formal))) = B_Type
1537 Next_Formal (Formal);
1541 -- For a formal derived type, the only primitives are the
1542 -- ones inherited from the parent type. Operations appearing
1543 -- in the package declaration are not primitive for it.
1546 and then (not Formal_Derived
1547 or else Present (Alias (Id)))
1549 Append_Elmt (Id, Op_List);
1555 -- For a type declared in System, some of its operations
1556 -- may appear in the target-specific extension to System.
1559 and then Chars (B_Scope) = Name_System
1560 and then Scope (B_Scope) = Standard_Standard
1561 and then Present_System_Aux
1563 B_Scope := System_Aux_Id;
1564 Id := First_Entity (System_Aux_Id);
1570 end Collect_Primitive_Operations;
1572 -----------------------------------
1573 -- Compile_Time_Constraint_Error --
1574 -----------------------------------
1576 function Compile_Time_Constraint_Error
1579 Ent : Entity_Id := Empty;
1580 Loc : Source_Ptr := No_Location;
1581 Warn : Boolean := False) return Node_Id
1583 Msgc : String (1 .. Msg'Length + 2);
1584 -- Copy of message, with room for possible ? and ! at end
1594 -- A static constraint error in an instance body is not a fatal error.
1595 -- we choose to inhibit the message altogether, because there is no
1596 -- obvious node (for now) on which to post it. On the other hand the
1597 -- offending node must be replaced with a constraint_error in any case.
1599 -- No messages are generated if we already posted an error on this node
1601 if not Error_Posted (N) then
1602 if Loc /= No_Location then
1608 Msgc (1 .. Msg'Length) := Msg;
1611 -- Message is a warning, even in Ada 95 case
1613 if Msg (Msg'Last) = '?' then
1616 -- In Ada 83, all messages are warnings. In the private part and
1617 -- the body of an instance, constraint_checks are only warnings.
1618 -- We also make this a warning if the Warn parameter is set.
1621 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1627 elsif In_Instance_Not_Visible then
1632 -- Otherwise we have a real error message (Ada 95 static case)
1633 -- and we make this an unconditional message. Note that in the
1634 -- warning case we do not make the message unconditional, it seems
1635 -- quite reasonable to delete messages like this (about exceptions
1636 -- that will be raised) in dead code.
1644 -- Should we generate a warning? The answer is not quite yes. The
1645 -- very annoying exception occurs in the case of a short circuit
1646 -- operator where the left operand is static and decisive. Climb
1647 -- parents to see if that is the case we have here. Conditional
1648 -- expressions with decisive conditions are a similar situation.
1656 -- And then with False as left operand
1658 if Nkind (P) = N_And_Then
1659 and then Compile_Time_Known_Value (Left_Opnd (P))
1660 and then Is_False (Expr_Value (Left_Opnd (P)))
1665 -- OR ELSE with True as left operand
1667 elsif Nkind (P) = N_Or_Else
1668 and then Compile_Time_Known_Value (Left_Opnd (P))
1669 and then Is_True (Expr_Value (Left_Opnd (P)))
1674 -- Conditional expression
1676 elsif Nkind (P) = N_Conditional_Expression then
1678 Cond : constant Node_Id := First (Expressions (P));
1679 Texp : constant Node_Id := Next (Cond);
1680 Fexp : constant Node_Id := Next (Texp);
1683 if Compile_Time_Known_Value (Cond) then
1685 -- Condition is True and we are in the right operand
1687 if Is_True (Expr_Value (Cond))
1688 and then OldP = Fexp
1693 -- Condition is False and we are in the left operand
1695 elsif Is_False (Expr_Value (Cond))
1696 and then OldP = Texp
1704 -- Special case for component association in aggregates, where
1705 -- we want to keep climbing up to the parent aggregate.
1707 elsif Nkind (P) = N_Component_Association
1708 and then Nkind (Parent (P)) = N_Aggregate
1712 -- Keep going if within subexpression
1715 exit when Nkind (P) not in N_Subexpr;
1720 if Present (Ent) then
1721 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1723 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1727 if Inside_Init_Proc then
1729 ("\?& will be raised for objects of this type",
1730 N, Standard_Constraint_Error, Eloc);
1733 ("\?& will be raised at run time",
1734 N, Standard_Constraint_Error, Eloc);
1739 ("\static expression fails Constraint_Check", Eloc);
1740 Set_Error_Posted (N);
1746 end Compile_Time_Constraint_Error;
1748 -----------------------
1749 -- Conditional_Delay --
1750 -----------------------
1752 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1754 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1755 Set_Has_Delayed_Freeze (New_Ent);
1757 end Conditional_Delay;
1759 --------------------
1760 -- Current_Entity --
1761 --------------------
1763 -- The currently visible definition for a given identifier is the
1764 -- one most chained at the start of the visibility chain, i.e. the
1765 -- one that is referenced by the Node_Id value of the name of the
1766 -- given identifier.
1768 function Current_Entity (N : Node_Id) return Entity_Id is
1770 return Get_Name_Entity_Id (Chars (N));
1773 -----------------------------
1774 -- Current_Entity_In_Scope --
1775 -----------------------------
1777 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1779 CS : constant Entity_Id := Current_Scope;
1781 Transient_Case : constant Boolean := Scope_Is_Transient;
1784 E := Get_Name_Entity_Id (Chars (N));
1786 and then Scope (E) /= CS
1787 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1793 end Current_Entity_In_Scope;
1799 function Current_Scope return Entity_Id is
1801 if Scope_Stack.Last = -1 then
1802 return Standard_Standard;
1805 C : constant Entity_Id :=
1806 Scope_Stack.Table (Scope_Stack.Last).Entity;
1811 return Standard_Standard;
1817 ------------------------
1818 -- Current_Subprogram --
1819 ------------------------
1821 function Current_Subprogram return Entity_Id is
1822 Scop : constant Entity_Id := Current_Scope;
1825 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1828 return Enclosing_Subprogram (Scop);
1830 end Current_Subprogram;
1832 ---------------------
1833 -- Defining_Entity --
1834 ---------------------
1836 function Defining_Entity (N : Node_Id) return Entity_Id is
1837 K : constant Node_Kind := Nkind (N);
1838 Err : Entity_Id := Empty;
1843 N_Subprogram_Declaration |
1844 N_Abstract_Subprogram_Declaration |
1846 N_Package_Declaration |
1847 N_Subprogram_Renaming_Declaration |
1848 N_Subprogram_Body_Stub |
1849 N_Generic_Subprogram_Declaration |
1850 N_Generic_Package_Declaration |
1851 N_Formal_Subprogram_Declaration
1853 return Defining_Entity (Specification (N));
1856 N_Component_Declaration |
1857 N_Defining_Program_Unit_Name |
1858 N_Discriminant_Specification |
1860 N_Entry_Declaration |
1861 N_Entry_Index_Specification |
1862 N_Exception_Declaration |
1863 N_Exception_Renaming_Declaration |
1864 N_Formal_Object_Declaration |
1865 N_Formal_Package_Declaration |
1866 N_Formal_Type_Declaration |
1867 N_Full_Type_Declaration |
1868 N_Implicit_Label_Declaration |
1869 N_Incomplete_Type_Declaration |
1870 N_Loop_Parameter_Specification |
1871 N_Number_Declaration |
1872 N_Object_Declaration |
1873 N_Object_Renaming_Declaration |
1874 N_Package_Body_Stub |
1875 N_Parameter_Specification |
1876 N_Private_Extension_Declaration |
1877 N_Private_Type_Declaration |
1879 N_Protected_Body_Stub |
1880 N_Protected_Type_Declaration |
1881 N_Single_Protected_Declaration |
1882 N_Single_Task_Declaration |
1883 N_Subtype_Declaration |
1886 N_Task_Type_Declaration
1888 return Defining_Identifier (N);
1891 return Defining_Entity (Proper_Body (N));
1894 N_Function_Instantiation |
1895 N_Function_Specification |
1896 N_Generic_Function_Renaming_Declaration |
1897 N_Generic_Package_Renaming_Declaration |
1898 N_Generic_Procedure_Renaming_Declaration |
1900 N_Package_Instantiation |
1901 N_Package_Renaming_Declaration |
1902 N_Package_Specification |
1903 N_Procedure_Instantiation |
1904 N_Procedure_Specification
1907 Nam : constant Node_Id := Defining_Unit_Name (N);
1910 if Nkind (Nam) in N_Entity then
1913 -- For Error, make up a name and attach to declaration
1914 -- so we can continue semantic analysis
1916 elsif Nam = Error then
1918 Make_Defining_Identifier (Sloc (N),
1919 Chars => New_Internal_Name ('T'));
1920 Set_Defining_Unit_Name (N, Err);
1923 -- If not an entity, get defining identifier
1926 return Defining_Identifier (Nam);
1930 when N_Block_Statement =>
1931 return Entity (Identifier (N));
1934 raise Program_Error;
1937 end Defining_Entity;
1939 --------------------------
1940 -- Denotes_Discriminant --
1941 --------------------------
1943 function Denotes_Discriminant
1945 Check_Concurrent : Boolean := False) return Boolean
1949 if not Is_Entity_Name (N)
1950 or else No (Entity (N))
1957 -- If we are checking for a protected type, the discriminant may have
1958 -- been rewritten as the corresponding discriminal of the original type
1959 -- or of the corresponding concurrent record, depending on whether we
1960 -- are in the spec or body of the protected type.
1962 return Ekind (E) = E_Discriminant
1965 and then Ekind (E) = E_In_Parameter
1966 and then Present (Discriminal_Link (E))
1968 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
1970 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1972 end Denotes_Discriminant;
1974 -----------------------------
1975 -- Depends_On_Discriminant --
1976 -----------------------------
1978 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1983 Get_Index_Bounds (N, L, H);
1984 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1985 end Depends_On_Discriminant;
1987 -------------------------
1988 -- Designate_Same_Unit --
1989 -------------------------
1991 function Designate_Same_Unit
1993 Name2 : Node_Id) return Boolean
1995 K1 : constant Node_Kind := Nkind (Name1);
1996 K2 : constant Node_Kind := Nkind (Name2);
1998 function Prefix_Node (N : Node_Id) return Node_Id;
1999 -- Returns the parent unit name node of a defining program unit name
2000 -- or the prefix if N is a selected component or an expanded name.
2002 function Select_Node (N : Node_Id) return Node_Id;
2003 -- Returns the defining identifier node of a defining program unit
2004 -- name or the selector node if N is a selected component or an
2011 function Prefix_Node (N : Node_Id) return Node_Id is
2013 if Nkind (N) = N_Defining_Program_Unit_Name then
2025 function Select_Node (N : Node_Id) return Node_Id is
2027 if Nkind (N) = N_Defining_Program_Unit_Name then
2028 return Defining_Identifier (N);
2031 return Selector_Name (N);
2035 -- Start of processing for Designate_Next_Unit
2038 if (K1 = N_Identifier or else
2039 K1 = N_Defining_Identifier)
2041 (K2 = N_Identifier or else
2042 K2 = N_Defining_Identifier)
2044 return Chars (Name1) = Chars (Name2);
2047 (K1 = N_Expanded_Name or else
2048 K1 = N_Selected_Component or else
2049 K1 = N_Defining_Program_Unit_Name)
2051 (K2 = N_Expanded_Name or else
2052 K2 = N_Selected_Component or else
2053 K2 = N_Defining_Program_Unit_Name)
2056 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2058 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2063 end Designate_Same_Unit;
2065 ----------------------------
2066 -- Enclosing_Generic_Body --
2067 ----------------------------
2069 function Enclosing_Generic_Body
2070 (N : Node_Id) return Node_Id
2078 while Present (P) loop
2079 if Nkind (P) = N_Package_Body
2080 or else Nkind (P) = N_Subprogram_Body
2082 Spec := Corresponding_Spec (P);
2084 if Present (Spec) then
2085 Decl := Unit_Declaration_Node (Spec);
2087 if Nkind (Decl) = N_Generic_Package_Declaration
2088 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2099 end Enclosing_Generic_Body;
2101 ----------------------------
2102 -- Enclosing_Generic_Unit --
2103 ----------------------------
2105 function Enclosing_Generic_Unit
2106 (N : Node_Id) return Node_Id
2114 while Present (P) loop
2115 if Nkind (P) = N_Generic_Package_Declaration
2116 or else Nkind (P) = N_Generic_Subprogram_Declaration
2120 elsif Nkind (P) = N_Package_Body
2121 or else Nkind (P) = N_Subprogram_Body
2123 Spec := Corresponding_Spec (P);
2125 if Present (Spec) then
2126 Decl := Unit_Declaration_Node (Spec);
2128 if Nkind (Decl) = N_Generic_Package_Declaration
2129 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2140 end Enclosing_Generic_Unit;
2142 -------------------------------
2143 -- Enclosing_Lib_Unit_Entity --
2144 -------------------------------
2146 function Enclosing_Lib_Unit_Entity return Entity_Id is
2147 Unit_Entity : Entity_Id;
2150 -- Look for enclosing library unit entity by following scope links.
2151 -- Equivalent to, but faster than indexing through the scope stack.
2153 Unit_Entity := Current_Scope;
2154 while (Present (Scope (Unit_Entity))
2155 and then Scope (Unit_Entity) /= Standard_Standard)
2156 and not Is_Child_Unit (Unit_Entity)
2158 Unit_Entity := Scope (Unit_Entity);
2162 end Enclosing_Lib_Unit_Entity;
2164 -----------------------------
2165 -- Enclosing_Lib_Unit_Node --
2166 -----------------------------
2168 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2169 Current_Node : Node_Id;
2173 while Present (Current_Node)
2174 and then Nkind (Current_Node) /= N_Compilation_Unit
2176 Current_Node := Parent (Current_Node);
2179 if Nkind (Current_Node) /= N_Compilation_Unit then
2183 return Current_Node;
2184 end Enclosing_Lib_Unit_Node;
2186 --------------------------
2187 -- Enclosing_Subprogram --
2188 --------------------------
2190 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2191 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2194 if Dynamic_Scope = Standard_Standard then
2197 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2198 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2200 elsif Ekind (Dynamic_Scope) = E_Block
2201 or else Ekind (Dynamic_Scope) = E_Return_Statement
2203 return Enclosing_Subprogram (Dynamic_Scope);
2205 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2206 return Get_Task_Body_Procedure (Dynamic_Scope);
2208 elsif Convention (Dynamic_Scope) = Convention_Protected then
2209 return Protected_Body_Subprogram (Dynamic_Scope);
2212 return Dynamic_Scope;
2214 end Enclosing_Subprogram;
2216 ------------------------
2217 -- Ensure_Freeze_Node --
2218 ------------------------
2220 procedure Ensure_Freeze_Node (E : Entity_Id) is
2224 if No (Freeze_Node (E)) then
2225 FN := Make_Freeze_Entity (Sloc (E));
2226 Set_Has_Delayed_Freeze (E);
2227 Set_Freeze_Node (E, FN);
2228 Set_Access_Types_To_Process (FN, No_Elist);
2229 Set_TSS_Elist (FN, No_Elist);
2232 end Ensure_Freeze_Node;
2238 procedure Enter_Name (Def_Id : Entity_Id) is
2239 C : constant Entity_Id := Current_Entity (Def_Id);
2240 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2241 S : constant Entity_Id := Current_Scope;
2243 function Is_Private_Component_Renaming (N : Node_Id) return Boolean;
2244 -- Recognize a renaming declaration that is introduced for private
2245 -- components of a protected type. We treat these as weak declarations
2246 -- so that they are overridden by entities with the same name that
2247 -- come from source, such as formals or local variables of a given
2248 -- protected declaration.
2250 -----------------------------------
2251 -- Is_Private_Component_Renaming --
2252 -----------------------------------
2254 function Is_Private_Component_Renaming (N : Node_Id) return Boolean is
2256 return not Comes_From_Source (N)
2257 and then not Comes_From_Source (Current_Scope)
2258 and then Nkind (N) = N_Object_Renaming_Declaration;
2259 end Is_Private_Component_Renaming;
2261 -- Start of processing for Enter_Name
2264 Generate_Definition (Def_Id);
2266 -- Add new name to current scope declarations. Check for duplicate
2267 -- declaration, which may or may not be a genuine error.
2271 -- Case of previous entity entered because of a missing declaration
2272 -- or else a bad subtype indication. Best is to use the new entity,
2273 -- and make the previous one invisible.
2275 if Etype (E) = Any_Type then
2276 Set_Is_Immediately_Visible (E, False);
2278 -- Case of renaming declaration constructed for package instances.
2279 -- if there is an explicit declaration with the same identifier,
2280 -- the renaming is not immediately visible any longer, but remains
2281 -- visible through selected component notation.
2283 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2284 and then not Comes_From_Source (E)
2286 Set_Is_Immediately_Visible (E, False);
2288 -- The new entity may be the package renaming, which has the same
2289 -- same name as a generic formal which has been seen already.
2291 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2292 and then not Comes_From_Source (Def_Id)
2294 Set_Is_Immediately_Visible (E, False);
2296 -- For a fat pointer corresponding to a remote access to subprogram,
2297 -- we use the same identifier as the RAS type, so that the proper
2298 -- name appears in the stub. This type is only retrieved through
2299 -- the RAS type and never by visibility, and is not added to the
2300 -- visibility list (see below).
2302 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2303 and then Present (Corresponding_Remote_Type (Def_Id))
2307 -- A controller component for a type extension overrides the
2308 -- inherited component.
2310 elsif Chars (E) = Name_uController then
2313 -- Case of an implicit operation or derived literal. The new entity
2314 -- hides the implicit one, which is removed from all visibility,
2315 -- i.e. the entity list of its scope, and homonym chain of its name.
2317 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2318 or else Is_Internal (E)
2322 Prev_Vis : Entity_Id;
2323 Decl : constant Node_Id := Parent (E);
2326 -- If E is an implicit declaration, it cannot be the first
2327 -- entity in the scope.
2329 Prev := First_Entity (Current_Scope);
2330 while Present (Prev)
2331 and then Next_Entity (Prev) /= E
2338 -- If E is not on the entity chain of the current scope,
2339 -- it is an implicit declaration in the generic formal
2340 -- part of a generic subprogram. When analyzing the body,
2341 -- the generic formals are visible but not on the entity
2342 -- chain of the subprogram. The new entity will become
2343 -- the visible one in the body.
2346 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2350 Set_Next_Entity (Prev, Next_Entity (E));
2352 if No (Next_Entity (Prev)) then
2353 Set_Last_Entity (Current_Scope, Prev);
2356 if E = Current_Entity (E) then
2360 Prev_Vis := Current_Entity (E);
2361 while Homonym (Prev_Vis) /= E loop
2362 Prev_Vis := Homonym (Prev_Vis);
2366 if Present (Prev_Vis) then
2368 -- Skip E in the visibility chain
2370 Set_Homonym (Prev_Vis, Homonym (E));
2373 Set_Name_Entity_Id (Chars (E), Homonym (E));
2378 -- This section of code could use a comment ???
2380 elsif Present (Etype (E))
2381 and then Is_Concurrent_Type (Etype (E))
2386 elsif Is_Private_Component_Renaming (Parent (Def_Id)) then
2389 -- In the body or private part of an instance, a type extension
2390 -- may introduce a component with the same name as that of an
2391 -- actual. The legality rule is not enforced, but the semantics
2392 -- of the full type with two components of the same name are not
2393 -- clear at this point ???
2395 elsif In_Instance_Not_Visible then
2398 -- When compiling a package body, some child units may have become
2399 -- visible. They cannot conflict with local entities that hide them.
2401 elsif Is_Child_Unit (E)
2402 and then In_Open_Scopes (Scope (E))
2403 and then not Is_Immediately_Visible (E)
2407 -- Conversely, with front-end inlining we may compile the parent
2408 -- body first, and a child unit subsequently. The context is now
2409 -- the parent spec, and body entities are not visible.
2411 elsif Is_Child_Unit (Def_Id)
2412 and then Is_Package_Body_Entity (E)
2413 and then not In_Package_Body (Current_Scope)
2417 -- Case of genuine duplicate declaration
2420 Error_Msg_Sloc := Sloc (E);
2422 -- If the previous declaration is an incomplete type declaration
2423 -- this may be an attempt to complete it with a private type.
2424 -- The following avoids confusing cascaded errors.
2426 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2427 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2430 ("incomplete type cannot be completed" &
2431 " with a private declaration",
2433 Set_Is_Immediately_Visible (E, False);
2434 Set_Full_View (E, Def_Id);
2436 elsif Ekind (E) = E_Discriminant
2437 and then Present (Scope (Def_Id))
2438 and then Scope (Def_Id) /= Current_Scope
2440 -- An inherited component of a record conflicts with
2441 -- a new discriminant. The discriminant is inserted first
2442 -- in the scope, but the error should be posted on it, not
2443 -- on the component.
2445 Error_Msg_Sloc := Sloc (Def_Id);
2446 Error_Msg_N ("& conflicts with declaration#", E);
2449 -- If the name of the unit appears in its own context clause,
2450 -- a dummy package with the name has already been created, and
2451 -- the error emitted. Try to continue quietly.
2453 elsif Error_Posted (E)
2454 and then Sloc (E) = No_Location
2455 and then Nkind (Parent (E)) = N_Package_Specification
2456 and then Current_Scope = Standard_Standard
2458 Set_Scope (Def_Id, Current_Scope);
2462 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2464 -- Avoid cascaded messages with duplicate components in
2467 if Ekind (E) = E_Component
2468 or else Ekind (E) = E_Discriminant
2474 if Nkind (Parent (Parent (Def_Id)))
2475 = N_Generic_Subprogram_Declaration
2477 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2479 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2482 -- If entity is in standard, then we are in trouble, because
2483 -- it means that we have a library package with a duplicated
2484 -- name. That's hard to recover from, so abort!
2486 if S = Standard_Standard then
2487 raise Unrecoverable_Error;
2489 -- Otherwise we continue with the declaration. Having two
2490 -- identical declarations should not cause us too much trouble!
2498 -- If we fall through, declaration is OK , or OK enough to continue
2500 -- If Def_Id is a discriminant or a record component we are in the
2501 -- midst of inheriting components in a derived record definition.
2502 -- Preserve their Ekind and Etype.
2504 if Ekind (Def_Id) = E_Discriminant
2505 or else Ekind (Def_Id) = E_Component
2509 -- If a type is already set, leave it alone (happens whey a type
2510 -- declaration is reanalyzed following a call to the optimizer)
2512 elsif Present (Etype (Def_Id)) then
2515 -- Otherwise, the kind E_Void insures that premature uses of the entity
2516 -- will be detected. Any_Type insures that no cascaded errors will occur
2519 Set_Ekind (Def_Id, E_Void);
2520 Set_Etype (Def_Id, Any_Type);
2523 -- Inherited discriminants and components in derived record types are
2524 -- immediately visible. Itypes are not.
2526 if Ekind (Def_Id) = E_Discriminant
2527 or else Ekind (Def_Id) = E_Component
2528 or else (No (Corresponding_Remote_Type (Def_Id))
2529 and then not Is_Itype (Def_Id))
2531 Set_Is_Immediately_Visible (Def_Id);
2532 Set_Current_Entity (Def_Id);
2535 Set_Homonym (Def_Id, C);
2536 Append_Entity (Def_Id, S);
2537 Set_Public_Status (Def_Id);
2539 -- Warn if new entity hides an old one
2541 if Warn_On_Hiding and then Present (C)
2543 -- Don't warn for record components since they always have a well
2544 -- defined scope which does not confuse other uses. Note that in
2545 -- some cases, Ekind has not been set yet.
2547 and then Ekind (C) /= E_Component
2548 and then Ekind (C) /= E_Discriminant
2549 and then Nkind (Parent (C)) /= N_Component_Declaration
2550 and then Ekind (Def_Id) /= E_Component
2551 and then Ekind (Def_Id) /= E_Discriminant
2552 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2554 -- Don't warn for one character variables. It is too common to use
2555 -- such variables as locals and will just cause too many false hits.
2557 and then Length_Of_Name (Chars (C)) /= 1
2559 -- Don't warn for non-source eneities
2561 and then Comes_From_Source (C)
2562 and then Comes_From_Source (Def_Id)
2564 -- Don't warn unless entity in question is in extended main source
2566 and then In_Extended_Main_Source_Unit (Def_Id)
2568 -- Finally, the hidden entity must be either immediately visible
2569 -- or use visible (from a used package)
2572 (Is_Immediately_Visible (C)
2574 Is_Potentially_Use_Visible (C))
2576 Error_Msg_Sloc := Sloc (C);
2577 Error_Msg_N ("declaration hides &#?", Def_Id);
2581 --------------------------
2582 -- Explain_Limited_Type --
2583 --------------------------
2585 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2589 -- For array, component type must be limited
2591 if Is_Array_Type (T) then
2592 Error_Msg_Node_2 := T;
2594 ("\component type& of type& is limited", N, Component_Type (T));
2595 Explain_Limited_Type (Component_Type (T), N);
2597 elsif Is_Record_Type (T) then
2599 -- No need for extra messages if explicit limited record
2601 if Is_Limited_Record (Base_Type (T)) then
2605 -- Otherwise find a limited component. Check only components that
2606 -- come from source, or inherited components that appear in the
2607 -- source of the ancestor.
2609 C := First_Component (T);
2610 while Present (C) loop
2611 if Is_Limited_Type (Etype (C))
2613 (Comes_From_Source (C)
2615 (Present (Original_Record_Component (C))
2617 Comes_From_Source (Original_Record_Component (C))))
2619 Error_Msg_Node_2 := T;
2620 Error_Msg_NE ("\component& of type& has limited type", N, C);
2621 Explain_Limited_Type (Etype (C), N);
2628 -- The type may be declared explicitly limited, even if no component
2629 -- of it is limited, in which case we fall out of the loop.
2632 end Explain_Limited_Type;
2634 -------------------------------------
2635 -- Find_Corresponding_Discriminant --
2636 -------------------------------------
2638 function Find_Corresponding_Discriminant
2640 Typ : Entity_Id) return Entity_Id
2642 Par_Disc : Entity_Id;
2643 Old_Disc : Entity_Id;
2644 New_Disc : Entity_Id;
2647 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2649 -- The original type may currently be private, and the discriminant
2650 -- only appear on its full view.
2652 if Is_Private_Type (Scope (Par_Disc))
2653 and then not Has_Discriminants (Scope (Par_Disc))
2654 and then Present (Full_View (Scope (Par_Disc)))
2656 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2658 Old_Disc := First_Discriminant (Scope (Par_Disc));
2661 if Is_Class_Wide_Type (Typ) then
2662 New_Disc := First_Discriminant (Root_Type (Typ));
2664 New_Disc := First_Discriminant (Typ);
2667 while Present (Old_Disc) and then Present (New_Disc) loop
2668 if Old_Disc = Par_Disc then
2671 Next_Discriminant (Old_Disc);
2672 Next_Discriminant (New_Disc);
2676 -- Should always find it
2678 raise Program_Error;
2679 end Find_Corresponding_Discriminant;
2681 --------------------------------------------
2682 -- Find_Overridden_Synchronized_Primitive --
2683 --------------------------------------------
2685 function Find_Overridden_Synchronized_Primitive
2686 (Def_Id : Entity_Id;
2687 First_Hom : Entity_Id;
2688 Ifaces_List : Elist_Id;
2689 In_Scope : Boolean) return Entity_Id
2691 Candidate : Entity_Id := Empty;
2692 Hom : Entity_Id := Empty;
2693 Iface_Typ : Entity_Id;
2694 Subp : Entity_Id := Empty;
2695 Tag_Typ : Entity_Id;
2697 function Find_Parameter_Type (Param : Node_Id) return Entity_Id;
2698 -- Return the type of a formal parameter as determined by its
2701 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
2702 -- For an overridden subprogram Subp, check whether the mode of its
2703 -- first parameter is correct depending on the kind of Tag_Typ.
2705 function Matches_Prefixed_View_Profile
2706 (Prim_Params : List_Id;
2707 Iface_Params : List_Id) return Boolean;
2708 -- Determine whether a subprogram's parameter profile Prim_Params
2709 -- matches that of a potentially overriden interface subprogram
2710 -- Iface_Params. Also determine if the type of first parameter of
2711 -- Iface_Params is an implemented interface.
2713 -------------------------
2714 -- Find_Parameter_Type --
2715 -------------------------
2717 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2719 pragma Assert (Nkind (Param) = N_Parameter_Specification);
2721 if Nkind (Parameter_Type (Param)) = N_Access_Definition then
2722 return Etype (Subtype_Mark (Parameter_Type (Param)));
2725 return Etype (Parameter_Type (Param));
2727 end Find_Parameter_Type;
2729 -----------------------------
2730 -- Has_Correct_Formal_Mode --
2731 -----------------------------
2733 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
2737 Param := First_Formal (Subp);
2739 -- In order for an entry or a protected procedure to override, the
2740 -- first parameter of the overridden routine must be of mode "out",
2741 -- "in out" or access-to-variable.
2743 if (Ekind (Subp) = E_Entry
2744 or else Ekind (Subp) = E_Procedure)
2745 and then Is_Protected_Type (Tag_Typ)
2746 and then Ekind (Param) /= E_In_Out_Parameter
2747 and then Ekind (Param) /= E_Out_Parameter
2748 and then Nkind (Parameter_Type (Parent (Param))) /=
2754 -- All other cases are OK since a task entry or routine does not
2755 -- have a restriction on the mode of the first parameter of the
2756 -- overridden interface routine.
2759 end Has_Correct_Formal_Mode;
2761 -----------------------------------
2762 -- Matches_Prefixed_View_Profile --
2763 -----------------------------------
2765 function Matches_Prefixed_View_Profile
2766 (Prim_Params : List_Id;
2767 Iface_Params : List_Id) return Boolean
2769 Iface_Id : Entity_Id;
2770 Iface_Param : Node_Id;
2771 Iface_Typ : Entity_Id;
2772 Prim_Id : Entity_Id;
2773 Prim_Param : Node_Id;
2774 Prim_Typ : Entity_Id;
2776 function Is_Implemented (Iface : Entity_Id) return Boolean;
2777 -- Determine if Iface is implemented by the current task or
2780 --------------------
2781 -- Is_Implemented --
2782 --------------------
2784 function Is_Implemented (Iface : Entity_Id) return Boolean is
2785 Iface_Elmt : Elmt_Id;
2788 Iface_Elmt := First_Elmt (Ifaces_List);
2789 while Present (Iface_Elmt) loop
2790 if Node (Iface_Elmt) = Iface then
2794 Next_Elmt (Iface_Elmt);
2800 -- Start of processing for Matches_Prefixed_View_Profile
2803 Iface_Param := First (Iface_Params);
2804 Iface_Typ := Find_Parameter_Type (Iface_Param);
2805 Prim_Param := First (Prim_Params);
2807 -- The first parameter of the potentially overriden subprogram
2808 -- must be an interface implemented by Prim.
2810 if not Is_Interface (Iface_Typ)
2811 or else not Is_Implemented (Iface_Typ)
2816 -- The checks on the object parameters are done, move onto the rest
2817 -- of the parameters.
2819 if not In_Scope then
2820 Prim_Param := Next (Prim_Param);
2823 Iface_Param := Next (Iface_Param);
2824 while Present (Iface_Param) and then Present (Prim_Param) loop
2825 Iface_Id := Defining_Identifier (Iface_Param);
2826 Iface_Typ := Find_Parameter_Type (Iface_Param);
2827 Prim_Id := Defining_Identifier (Prim_Param);
2828 Prim_Typ := Find_Parameter_Type (Prim_Param);
2830 -- Case of multiple interface types inside a parameter profile
2832 -- (Obj_Param : in out Iface; ...; Param : Iface)
2834 -- If the interface type is implemented, then the matching type
2835 -- in the primitive should be the implementing record type.
2837 if Ekind (Iface_Typ) = E_Record_Type
2838 and then Is_Interface (Iface_Typ)
2839 and then Is_Implemented (Iface_Typ)
2841 if Prim_Typ /= Tag_Typ then
2845 -- The two parameters must be both mode and subtype conformant
2847 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
2849 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
2858 -- One of the two lists contains more parameters than the other
2860 if Present (Iface_Param) or else Present (Prim_Param) then
2865 end Matches_Prefixed_View_Profile;
2867 -- Start of processing for Find_Overridden_Synchronized_Primitive
2870 -- At this point the caller should have collected the interfaces
2871 -- implemented by the synchronized type.
2873 pragma Assert (Present (Ifaces_List));
2875 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2876 -- subprogram was declared within a protected or a task type, the type
2877 -- is the scope itself, otherwise it is the type of the first parameter.
2880 Tag_Typ := Scope (Def_Id);
2882 elsif Present (First_Formal (Def_Id)) then
2883 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
2885 -- A parameterless subprogram which is declared outside a synchronized
2886 -- type cannot act as a primitive, thus it cannot override anything.
2892 -- Traverse the homonym chain, looking at a potentially overriden
2893 -- subprogram that belongs to an implemented interface.
2896 while Present (Hom) loop
2899 -- Entries can override abstract or null interface procedures
2901 if Ekind (Def_Id) = E_Entry
2902 and then Ekind (Subp) = E_Procedure
2903 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2904 and then (Is_Abstract_Subprogram (Subp)
2905 or else Null_Present (Parent (Subp)))
2907 while Present (Alias (Subp)) loop
2908 Subp := Alias (Subp);
2911 if Matches_Prefixed_View_Profile
2912 (Parameter_Specifications (Parent (Def_Id)),
2913 Parameter_Specifications (Parent (Subp)))
2919 if Has_Correct_Formal_Mode (Candidate) then
2924 -- Procedures can override abstract or null interface procedures
2926 elsif Ekind (Def_Id) = E_Procedure
2927 and then Ekind (Subp) = E_Procedure
2928 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2929 and then (Is_Abstract_Subprogram (Subp)
2930 or else Null_Present (Parent (Subp)))
2931 and then Matches_Prefixed_View_Profile
2932 (Parameter_Specifications (Parent (Def_Id)),
2933 Parameter_Specifications (Parent (Subp)))
2939 if Has_Correct_Formal_Mode (Candidate) then
2943 -- Functions can override abstract interface functions
2945 elsif Ekind (Def_Id) = E_Function
2946 and then Ekind (Subp) = E_Function
2947 and then Nkind (Parent (Subp)) = N_Function_Specification
2948 and then Is_Abstract_Subprogram (Subp)
2949 and then Matches_Prefixed_View_Profile
2950 (Parameter_Specifications (Parent (Def_Id)),
2951 Parameter_Specifications (Parent (Subp)))
2952 and then Etype (Result_Definition (Parent (Def_Id))) =
2953 Etype (Result_Definition (Parent (Subp)))
2958 Hom := Homonym (Hom);
2961 -- After examining all candidates for overriding, we are left with
2962 -- the best match which is a mode incompatible interface routine.
2963 -- Do not emit an error if the Expander is active since this error
2964 -- will be detected later on after all concurrent types are expanded
2965 -- and all wrappers are built. This check is meant for spec-only
2968 if Present (Candidate)
2969 and then not Expander_Active
2971 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
2973 -- Def_Id is primitive of a protected type, declared inside the type,
2974 -- and the candidate is primitive of a limited or synchronized
2978 and then Is_Protected_Type (Tag_Typ)
2980 (Is_Limited_Interface (Iface_Typ)
2981 or else Is_Protected_Interface (Iface_Typ)
2982 or else Is_Synchronized_Interface (Iface_Typ)
2983 or else Is_Task_Interface (Iface_Typ))
2985 -- Must reword this message, comma before to in -gnatj mode ???
2988 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
2989 "access-to-variable", Tag_Typ, Candidate);
2991 ("\to be overridden by protected procedure or entry " &
2992 "(RM 9.4(11.9/2))", Tag_Typ);
2997 end Find_Overridden_Synchronized_Primitive;
2999 -----------------------------
3000 -- Find_Static_Alternative --
3001 -----------------------------
3003 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3004 Expr : constant Node_Id := Expression (N);
3005 Val : constant Uint := Expr_Value (Expr);
3010 Alt := First (Alternatives (N));
3013 if Nkind (Alt) /= N_Pragma then
3014 Choice := First (Discrete_Choices (Alt));
3015 while Present (Choice) loop
3017 -- Others choice, always matches
3019 if Nkind (Choice) = N_Others_Choice then
3022 -- Range, check if value is in the range
3024 elsif Nkind (Choice) = N_Range then
3026 Val >= Expr_Value (Low_Bound (Choice))
3028 Val <= Expr_Value (High_Bound (Choice));
3030 -- Choice is a subtype name. Note that we know it must
3031 -- be a static subtype, since otherwise it would have
3032 -- been diagnosed as illegal.
3034 elsif Is_Entity_Name (Choice)
3035 and then Is_Type (Entity (Choice))
3037 exit Search when Is_In_Range (Expr, Etype (Choice));
3039 -- Choice is a subtype indication
3041 elsif Nkind (Choice) = N_Subtype_Indication then
3043 C : constant Node_Id := Constraint (Choice);
3044 R : constant Node_Id := Range_Expression (C);
3048 Val >= Expr_Value (Low_Bound (R))
3050 Val <= Expr_Value (High_Bound (R));
3053 -- Choice is a simple expression
3056 exit Search when Val = Expr_Value (Choice);
3064 pragma Assert (Present (Alt));
3067 -- The above loop *must* terminate by finding a match, since
3068 -- we know the case statement is valid, and the value of the
3069 -- expression is known at compile time. When we fall out of
3070 -- the loop, Alt points to the alternative that we know will
3071 -- be selected at run time.
3074 end Find_Static_Alternative;
3080 function First_Actual (Node : Node_Id) return Node_Id is
3084 if No (Parameter_Associations (Node)) then
3088 N := First (Parameter_Associations (Node));
3090 if Nkind (N) = N_Parameter_Association then
3091 return First_Named_Actual (Node);
3097 -------------------------
3098 -- Full_Qualified_Name --
3099 -------------------------
3101 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3103 pragma Warnings (Off, Res);
3105 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3106 -- Compute recursively the qualified name without NUL at the end
3108 ----------------------------------
3109 -- Internal_Full_Qualified_Name --
3110 ----------------------------------
3112 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3113 Ent : Entity_Id := E;
3114 Parent_Name : String_Id := No_String;
3117 -- Deals properly with child units
3119 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3120 Ent := Defining_Identifier (Ent);
3123 -- Compute qualification recursively (only "Standard" has no scope)
3125 if Present (Scope (Scope (Ent))) then
3126 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3129 -- Every entity should have a name except some expanded blocks
3130 -- don't bother about those.
3132 if Chars (Ent) = No_Name then
3136 -- Add a period between Name and qualification
3138 if Parent_Name /= No_String then
3139 Start_String (Parent_Name);
3140 Store_String_Char (Get_Char_Code ('.'));
3146 -- Generates the entity name in upper case
3148 Get_Decoded_Name_String (Chars (Ent));
3150 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3152 end Internal_Full_Qualified_Name;
3154 -- Start of processing for Full_Qualified_Name
3157 Res := Internal_Full_Qualified_Name (E);
3158 Store_String_Char (Get_Char_Code (ASCII.nul));
3160 end Full_Qualified_Name;
3162 -----------------------
3163 -- Gather_Components --
3164 -----------------------
3166 procedure Gather_Components
3168 Comp_List : Node_Id;
3169 Governed_By : List_Id;
3171 Report_Errors : out Boolean)
3175 Discrete_Choice : Node_Id;
3176 Comp_Item : Node_Id;
3178 Discrim : Entity_Id;
3179 Discrim_Name : Node_Id;
3180 Discrim_Value : Node_Id;
3183 Report_Errors := False;
3185 if No (Comp_List) or else Null_Present (Comp_List) then
3188 elsif Present (Component_Items (Comp_List)) then
3189 Comp_Item := First (Component_Items (Comp_List));
3195 while Present (Comp_Item) loop
3197 -- Skip the tag of a tagged record, the interface tags, as well
3198 -- as all items that are not user components (anonymous types,
3199 -- rep clauses, Parent field, controller field).
3201 if Nkind (Comp_Item) = N_Component_Declaration then
3203 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3205 if not Is_Tag (Comp)
3206 and then Chars (Comp) /= Name_uParent
3207 and then Chars (Comp) /= Name_uController
3209 Append_Elmt (Comp, Into);
3217 if No (Variant_Part (Comp_List)) then
3220 Discrim_Name := Name (Variant_Part (Comp_List));
3221 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3224 -- Look for the discriminant that governs this variant part.
3225 -- The discriminant *must* be in the Governed_By List
3227 Assoc := First (Governed_By);
3228 Find_Constraint : loop
3229 Discrim := First (Choices (Assoc));
3230 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3231 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3233 Chars (Corresponding_Discriminant (Entity (Discrim)))
3234 = Chars (Discrim_Name))
3235 or else Chars (Original_Record_Component (Entity (Discrim)))
3236 = Chars (Discrim_Name);
3238 if No (Next (Assoc)) then
3239 if not Is_Constrained (Typ)
3240 and then Is_Derived_Type (Typ)
3241 and then Present (Stored_Constraint (Typ))
3243 -- If the type is a tagged type with inherited discriminants,
3244 -- use the stored constraint on the parent in order to find
3245 -- the values of discriminants that are otherwise hidden by an
3246 -- explicit constraint. Renamed discriminants are handled in
3249 -- If several parent discriminants are renamed by a single
3250 -- discriminant of the derived type, the call to obtain the
3251 -- Corresponding_Discriminant field only retrieves the last
3252 -- of them. We recover the constraint on the others from the
3253 -- Stored_Constraint as well.
3260 D := First_Discriminant (Etype (Typ));
3261 C := First_Elmt (Stored_Constraint (Typ));
3262 while Present (D) and then Present (C) loop
3263 if Chars (Discrim_Name) = Chars (D) then
3264 if Is_Entity_Name (Node (C))
3265 and then Entity (Node (C)) = Entity (Discrim)
3267 -- D is renamed by Discrim, whose value is given in
3274 Make_Component_Association (Sloc (Typ),
3276 (New_Occurrence_Of (D, Sloc (Typ))),
3277 Duplicate_Subexpr_No_Checks (Node (C)));
3279 exit Find_Constraint;
3282 Next_Discriminant (D);
3289 if No (Next (Assoc)) then
3290 Error_Msg_NE (" missing value for discriminant&",
3291 First (Governed_By), Discrim_Name);
3292 Report_Errors := True;
3297 end loop Find_Constraint;
3299 Discrim_Value := Expression (Assoc);
3301 if not Is_OK_Static_Expression (Discrim_Value) then
3303 ("value for discriminant & must be static!",
3304 Discrim_Value, Discrim);
3305 Why_Not_Static (Discrim_Value);
3306 Report_Errors := True;
3310 Search_For_Discriminant_Value : declare
3316 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3319 Find_Discrete_Value : while Present (Variant) loop
3320 Discrete_Choice := First (Discrete_Choices (Variant));
3321 while Present (Discrete_Choice) loop
3323 exit Find_Discrete_Value when
3324 Nkind (Discrete_Choice) = N_Others_Choice;
3326 Get_Index_Bounds (Discrete_Choice, Low, High);
3328 UI_Low := Expr_Value (Low);
3329 UI_High := Expr_Value (High);
3331 exit Find_Discrete_Value when
3332 UI_Low <= UI_Discrim_Value
3334 UI_High >= UI_Discrim_Value;
3336 Next (Discrete_Choice);
3339 Next_Non_Pragma (Variant);
3340 end loop Find_Discrete_Value;
3341 end Search_For_Discriminant_Value;
3343 if No (Variant) then
3345 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3346 Report_Errors := True;
3350 -- If we have found the corresponding choice, recursively add its
3351 -- components to the Into list.
3353 Gather_Components (Empty,
3354 Component_List (Variant), Governed_By, Into, Report_Errors);
3355 end Gather_Components;
3357 ------------------------
3358 -- Get_Actual_Subtype --
3359 ------------------------
3361 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3362 Typ : constant Entity_Id := Etype (N);
3363 Utyp : Entity_Id := Underlying_Type (Typ);
3372 -- If what we have is an identifier that references a subprogram
3373 -- formal, or a variable or constant object, then we get the actual
3374 -- subtype from the referenced entity if one has been built.
3376 if Nkind (N) = N_Identifier
3378 (Is_Formal (Entity (N))
3379 or else Ekind (Entity (N)) = E_Constant
3380 or else Ekind (Entity (N)) = E_Variable)
3381 and then Present (Actual_Subtype (Entity (N)))
3383 return Actual_Subtype (Entity (N));
3385 -- Actual subtype of unchecked union is always itself. We never need
3386 -- the "real" actual subtype. If we did, we couldn't get it anyway
3387 -- because the discriminant is not available. The restrictions on
3388 -- Unchecked_Union are designed to make sure that this is OK.
3390 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3393 -- Here for the unconstrained case, we must find actual subtype
3394 -- No actual subtype is available, so we must build it on the fly.
3396 -- Checking the type, not the underlying type, for constrainedness
3397 -- seems to be necessary. Maybe all the tests should be on the type???
3399 elsif (not Is_Constrained (Typ))
3400 and then (Is_Array_Type (Utyp)
3401 or else (Is_Record_Type (Utyp)
3402 and then Has_Discriminants (Utyp)))
3403 and then not Has_Unknown_Discriminants (Utyp)
3404 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3406 -- Nothing to do if in default expression
3408 if In_Default_Expression then
3411 elsif Is_Private_Type (Typ)
3412 and then not Has_Discriminants (Typ)
3414 -- If the type has no discriminants, there is no subtype to
3415 -- build, even if the underlying type is discriminated.
3419 -- Else build the actual subtype
3422 Decl := Build_Actual_Subtype (Typ, N);
3423 Atyp := Defining_Identifier (Decl);
3425 -- If Build_Actual_Subtype generated a new declaration then use it
3429 -- The actual subtype is an Itype, so analyze the declaration,
3430 -- but do not attach it to the tree, to get the type defined.
3432 Set_Parent (Decl, N);
3433 Set_Is_Itype (Atyp);
3434 Analyze (Decl, Suppress => All_Checks);
3435 Set_Associated_Node_For_Itype (Atyp, N);
3436 Set_Has_Delayed_Freeze (Atyp, False);
3438 -- We need to freeze the actual subtype immediately. This is
3439 -- needed, because otherwise this Itype will not get frozen
3440 -- at all, and it is always safe to freeze on creation because
3441 -- any associated types must be frozen at this point.
3443 Freeze_Itype (Atyp, N);
3446 -- Otherwise we did not build a declaration, so return original
3453 -- For all remaining cases, the actual subtype is the same as
3454 -- the nominal type.
3459 end Get_Actual_Subtype;
3461 -------------------------------------
3462 -- Get_Actual_Subtype_If_Available --
3463 -------------------------------------
3465 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3466 Typ : constant Entity_Id := Etype (N);
3469 -- If what we have is an identifier that references a subprogram
3470 -- formal, or a variable or constant object, then we get the actual
3471 -- subtype from the referenced entity if one has been built.
3473 if Nkind (N) = N_Identifier
3475 (Is_Formal (Entity (N))
3476 or else Ekind (Entity (N)) = E_Constant
3477 or else Ekind (Entity (N)) = E_Variable)
3478 and then Present (Actual_Subtype (Entity (N)))
3480 return Actual_Subtype (Entity (N));
3482 -- Otherwise the Etype of N is returned unchanged
3487 end Get_Actual_Subtype_If_Available;
3489 -------------------------------
3490 -- Get_Default_External_Name --
3491 -------------------------------
3493 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3495 Get_Decoded_Name_String (Chars (E));
3497 if Opt.External_Name_Imp_Casing = Uppercase then
3498 Set_Casing (All_Upper_Case);
3500 Set_Casing (All_Lower_Case);
3504 Make_String_Literal (Sloc (E),
3505 Strval => String_From_Name_Buffer);
3506 end Get_Default_External_Name;
3508 ---------------------------
3509 -- Get_Enum_Lit_From_Pos --
3510 ---------------------------
3512 function Get_Enum_Lit_From_Pos
3515 Loc : Source_Ptr) return Node_Id
3520 -- In the case where the literal is of type Character, Wide_Character
3521 -- or Wide_Wide_Character or of a type derived from them, there needs
3522 -- to be some special handling since there is no explicit chain of
3523 -- literals to search. Instead, an N_Character_Literal node is created
3524 -- with the appropriate Char_Code and Chars fields.
3526 if Root_Type (T) = Standard_Character
3527 or else Root_Type (T) = Standard_Wide_Character
3528 or else Root_Type (T) = Standard_Wide_Wide_Character
3530 Set_Character_Literal_Name (UI_To_CC (Pos));
3532 Make_Character_Literal (Loc,
3534 Char_Literal_Value => Pos);
3536 -- For all other cases, we have a complete table of literals, and
3537 -- we simply iterate through the chain of literal until the one
3538 -- with the desired position value is found.
3542 Lit := First_Literal (Base_Type (T));
3543 for J in 1 .. UI_To_Int (Pos) loop
3547 return New_Occurrence_Of (Lit, Loc);
3549 end Get_Enum_Lit_From_Pos;
3551 ------------------------
3552 -- Get_Generic_Entity --
3553 ------------------------
3555 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3556 Ent : constant Entity_Id := Entity (Name (N));
3558 if Present (Renamed_Object (Ent)) then
3559 return Renamed_Object (Ent);
3563 end Get_Generic_Entity;
3565 ----------------------
3566 -- Get_Index_Bounds --
3567 ----------------------
3569 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3570 Kind : constant Node_Kind := Nkind (N);
3574 if Kind = N_Range then
3576 H := High_Bound (N);
3578 elsif Kind = N_Subtype_Indication then
3579 R := Range_Expression (Constraint (N));
3587 L := Low_Bound (Range_Expression (Constraint (N)));
3588 H := High_Bound (Range_Expression (Constraint (N)));
3591 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3592 if Error_Posted (Scalar_Range (Entity (N))) then
3596 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3597 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3600 L := Low_Bound (Scalar_Range (Entity (N)));
3601 H := High_Bound (Scalar_Range (Entity (N)));
3605 -- N is an expression, indicating a range with one value
3610 end Get_Index_Bounds;
3612 ----------------------------------
3613 -- Get_Library_Unit_Name_string --
3614 ----------------------------------
3616 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3617 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3620 Get_Unit_Name_String (Unit_Name_Id);
3622 -- Remove seven last character (" (spec)" or " (body)")
3624 Name_Len := Name_Len - 7;
3625 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3626 end Get_Library_Unit_Name_String;
3628 ------------------------
3629 -- Get_Name_Entity_Id --
3630 ------------------------
3632 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3634 return Entity_Id (Get_Name_Table_Info (Id));
3635 end Get_Name_Entity_Id;
3637 ---------------------------
3638 -- Get_Referenced_Object --
3639 ---------------------------
3641 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3646 while Is_Entity_Name (R)
3647 and then Present (Renamed_Object (Entity (R)))
3649 R := Renamed_Object (Entity (R));
3653 end Get_Referenced_Object;
3655 ------------------------
3656 -- Get_Renamed_Entity --
3657 ------------------------
3659 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3664 while Present (Renamed_Entity (R)) loop
3665 R := Renamed_Entity (R);
3669 end Get_Renamed_Entity;
3671 -------------------------
3672 -- Get_Subprogram_Body --
3673 -------------------------
3675 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3679 Decl := Unit_Declaration_Node (E);
3681 if Nkind (Decl) = N_Subprogram_Body then
3684 -- The below comment is bad, because it is possible for
3685 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3687 else -- Nkind (Decl) = N_Subprogram_Declaration
3689 if Present (Corresponding_Body (Decl)) then
3690 return Unit_Declaration_Node (Corresponding_Body (Decl));
3692 -- Imported subprogram case
3698 end Get_Subprogram_Body;
3700 ---------------------------
3701 -- Get_Subprogram_Entity --
3702 ---------------------------
3704 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3709 if Nkind (Nod) = N_Accept_Statement then
3710 Nam := Entry_Direct_Name (Nod);
3712 -- For an entry call, the prefix of the call is a selected component.
3713 -- Need additional code for internal calls ???
3715 elsif Nkind (Nod) = N_Entry_Call_Statement then
3716 if Nkind (Name (Nod)) = N_Selected_Component then
3717 Nam := Entity (Selector_Name (Name (Nod)));
3726 if Nkind (Nam) = N_Explicit_Dereference then
3727 Proc := Etype (Prefix (Nam));
3728 elsif Is_Entity_Name (Nam) then
3729 Proc := Entity (Nam);
3734 if Is_Object (Proc) then
3735 Proc := Etype (Proc);
3738 if Ekind (Proc) = E_Access_Subprogram_Type then
3739 Proc := Directly_Designated_Type (Proc);
3742 if not Is_Subprogram (Proc)
3743 and then Ekind (Proc) /= E_Subprogram_Type
3749 end Get_Subprogram_Entity;
3751 -----------------------------
3752 -- Get_Task_Body_Procedure --
3753 -----------------------------
3755 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3757 -- Note: A task type may be the completion of a private type with
3758 -- discriminants. when performing elaboration checks on a task
3759 -- declaration, the current view of the type may be the private one,
3760 -- and the procedure that holds the body of the task is held in its
3763 -- This is an odd function, why not have Task_Body_Procedure do
3764 -- the following digging???
3766 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3767 end Get_Task_Body_Procedure;
3769 -----------------------------
3770 -- Has_Abstract_Interfaces --
3771 -----------------------------
3773 function Has_Abstract_Interfaces
3774 (Tagged_Type : Entity_Id;
3775 Use_Full_View : Boolean := True) return Boolean
3780 pragma Assert (Is_Record_Type (Tagged_Type)
3781 and then Is_Tagged_Type (Tagged_Type));
3783 -- Handle concurrent record types
3785 if Is_Concurrent_Record_Type (Tagged_Type)
3786 and then Is_Non_Empty_List (Abstract_Interface_List (Tagged_Type))
3793 -- Handle private types
3796 and then Present (Full_View (Tagged_Type))
3798 Typ := Full_View (Tagged_Type);
3802 if Is_Interface (Typ)
3804 (Is_Record_Type (Typ)
3805 and then Present (Abstract_Interfaces (Typ))
3806 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
3811 exit when Etype (Typ) = Typ
3813 -- Handle private types
3815 or else (Present (Full_View (Etype (Typ)))
3816 and then Full_View (Etype (Typ)) = Typ)
3818 -- Protect the frontend against wrong source with cyclic
3821 or else Etype (Typ) = Tagged_Type;
3823 -- Climb to the ancestor type handling private types
3825 if Present (Full_View (Etype (Typ))) then
3826 Typ := Full_View (Etype (Typ));
3833 end Has_Abstract_Interfaces;
3835 -----------------------
3836 -- Has_Access_Values --
3837 -----------------------
3839 function Has_Access_Values (T : Entity_Id) return Boolean is
3840 Typ : constant Entity_Id := Underlying_Type (T);
3843 -- Case of a private type which is not completed yet. This can only
3844 -- happen in the case of a generic format type appearing directly, or
3845 -- as a component of the type to which this function is being applied
3846 -- at the top level. Return False in this case, since we certainly do
3847 -- not know that the type contains access types.
3852 elsif Is_Access_Type (Typ) then
3855 elsif Is_Array_Type (Typ) then
3856 return Has_Access_Values (Component_Type (Typ));
3858 elsif Is_Record_Type (Typ) then
3863 Comp := First_Component_Or_Discriminant (Typ);
3864 while Present (Comp) loop
3865 if Has_Access_Values (Etype (Comp)) then
3869 Next_Component_Or_Discriminant (Comp);
3878 end Has_Access_Values;
3880 ------------------------------
3881 -- Has_Compatible_Alignment --
3882 ------------------------------
3884 function Has_Compatible_Alignment
3886 Expr : Node_Id) return Alignment_Result
3888 function Has_Compatible_Alignment_Internal
3891 Default : Alignment_Result) return Alignment_Result;
3892 -- This is the internal recursive function that actually does the work.
3893 -- There is one additional parameter, which says what the result should
3894 -- be if no alignment information is found, and there is no definite
3895 -- indication of compatible alignments. At the outer level, this is set
3896 -- to Unknown, but for internal recursive calls in the case where types
3897 -- are known to be correct, it is set to Known_Compatible.
3899 ---------------------------------------
3900 -- Has_Compatible_Alignment_Internal --
3901 ---------------------------------------
3903 function Has_Compatible_Alignment_Internal
3906 Default : Alignment_Result) return Alignment_Result
3908 Result : Alignment_Result := Known_Compatible;
3909 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3910 -- Note that once a value of Known_Incompatible is set, it is sticky
3911 -- and does not get changed to Unknown (the value in Result only gets
3912 -- worse as we go along, never better).
3914 procedure Check_Offset (Offs : Uint);
3915 -- Called when Expr is a selected or indexed component with Offs set
3916 -- to resp Component_First_Bit or Component_Size. Checks that if the
3917 -- offset is specified it is compatible with the object alignment
3918 -- requirements. The value in Result is modified accordingly.
3920 procedure Check_Prefix;
3921 -- Checks the prefix recursively in the case where the expression
3922 -- is an indexed or selected component.
3924 procedure Set_Result (R : Alignment_Result);
3925 -- If R represents a worse outcome (unknown instead of known
3926 -- compatible, or known incompatible), then set Result to R.
3932 procedure Check_Offset (Offs : Uint) is
3934 -- Unspecified or zero offset is always OK
3936 if Offs = No_Uint or else Offs = Uint_0 then
3939 -- If we do not know required alignment, any non-zero offset is
3940 -- a potential problem (but certainly may be OK, so result is
3943 elsif Unknown_Alignment (Obj) then
3944 Set_Result (Unknown);
3946 -- If we know the required alignment, see if offset is compatible
3949 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3950 Set_Result (Known_Incompatible);
3959 procedure Check_Prefix is
3961 -- The subtlety here is that in doing a recursive call to check
3962 -- the prefix, we have to decide what to do in the case where we
3963 -- don't find any specific indication of an alignment problem.
3965 -- At the outer level, we normally set Unknown as the result in
3966 -- this case, since we can only set Known_Compatible if we really
3967 -- know that the alignment value is OK, but for the recursive
3968 -- call, in the case where the types match, and we have not
3969 -- specified a peculiar alignment for the object, we are only
3970 -- concerned about suspicious rep clauses, the default case does
3971 -- not affect us, since the compiler will, in the absence of such
3972 -- rep clauses, ensure that the alignment is correct.
3974 if Default = Known_Compatible
3976 (Etype (Obj) = Etype (Expr)
3977 and then (Unknown_Alignment (Obj)
3979 Alignment (Obj) = Alignment (Etype (Obj))))
3982 (Has_Compatible_Alignment_Internal
3983 (Obj, Prefix (Expr), Known_Compatible));
3985 -- In all other cases, we need a full check on the prefix
3989 (Has_Compatible_Alignment_Internal
3990 (Obj, Prefix (Expr), Unknown));
3998 procedure Set_Result (R : Alignment_Result) is
4005 -- Start of processing for Has_Compatible_Alignment_Internal
4008 -- If Expr is a selected component, we must make sure there is no
4009 -- potentially troublesome component clause, and that the record is
4012 if Nkind (Expr) = N_Selected_Component then
4014 -- Packed record always generate unknown alignment
4016 if Is_Packed (Etype (Prefix (Expr))) then
4017 Set_Result (Unknown);
4020 -- Check possible bad component offset and check prefix
4023 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4026 -- If Expr is an indexed component, we must make sure there is no
4027 -- potentially troublesome Component_Size clause and that the array
4028 -- is not bit-packed.
4030 elsif Nkind (Expr) = N_Indexed_Component then
4032 -- Bit packed array always generates unknown alignment
4034 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4035 Set_Result (Unknown);
4038 -- Check possible bad component size and check prefix
4040 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4044 -- Case where we know the alignment of the object
4046 if Known_Alignment (Obj) then
4048 ObjA : constant Uint := Alignment (Obj);
4049 ExpA : Uint := No_Uint;
4050 SizA : Uint := No_Uint;
4053 -- If alignment of Obj is 1, then we are always OK
4056 Set_Result (Known_Compatible);
4058 -- Alignment of Obj is greater than 1, so we need to check
4061 -- See if Expr is an object with known alignment
4063 if Is_Entity_Name (Expr)
4064 and then Known_Alignment (Entity (Expr))
4066 ExpA := Alignment (Entity (Expr));
4068 -- Otherwise, we can use the alignment of the type of
4069 -- Expr given that we already checked for
4070 -- discombobulating rep clauses for the cases of indexed
4071 -- and selected components above.
4073 elsif Known_Alignment (Etype (Expr)) then
4074 ExpA := Alignment (Etype (Expr));
4077 -- If we got an alignment, see if it is acceptable
4079 if ExpA /= No_Uint then
4081 Set_Result (Known_Incompatible);
4084 -- Case of Expr alignment unknown
4087 Set_Result (Default);
4090 -- See if size is given. If so, check that it is not too
4091 -- small for the required alignment.
4092 -- See if Expr is an object with known alignment
4094 if Is_Entity_Name (Expr)
4095 and then Known_Static_Esize (Entity (Expr))
4097 SizA := Esize (Entity (Expr));
4099 -- Otherwise, we check the object size of the Expr type
4101 elsif Known_Static_Esize (Etype (Expr)) then
4102 SizA := Esize (Etype (Expr));
4105 -- If we got a size, see if it is a multiple of the Obj
4106 -- alignment, if not, then the alignment cannot be
4107 -- acceptable, since the size is always a multiple of the
4110 if SizA /= No_Uint then
4111 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4112 Set_Result (Known_Incompatible);
4118 -- If we can't find the result by direct comparison of alignment
4119 -- values, then there is still one case that we can determine known
4120 -- result, and that is when we can determine that the types are the
4121 -- same, and no alignments are specified. Then we known that the
4122 -- alignments are compatible, even if we don't know the alignment
4123 -- value in the front end.
4125 elsif Etype (Obj) = Etype (Expr) then
4127 -- Types are the same, but we have to check for possible size
4128 -- and alignments on the Expr object that may make the alignment
4129 -- different, even though the types are the same.
4131 if Is_Entity_Name (Expr) then
4133 -- First check alignment of the Expr object. Any alignment less
4134 -- than Maximum_Alignment is worrisome since this is the case
4135 -- where we do not know the alignment of Obj.
4137 if Known_Alignment (Entity (Expr))
4139 UI_To_Int (Alignment (Entity (Expr)))
4140 < Ttypes.Maximum_Alignment
4142 Set_Result (Unknown);
4144 -- Now check size of Expr object. Any size that is not an
4145 -- even multiple of Maxiumum_Alignment is also worrisome
4146 -- since it may cause the alignment of the object to be less
4147 -- than the alignment of the type.
4149 elsif Known_Static_Esize (Entity (Expr))
4151 (UI_To_Int (Esize (Entity (Expr))) mod
4152 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4155 Set_Result (Unknown);
4157 -- Otherwise same type is decisive
4160 Set_Result (Known_Compatible);
4164 -- Another case to deal with is when there is an explicit size or
4165 -- alignment clause when the types are not the same. If so, then the
4166 -- result is Unknown. We don't need to do this test if the Default is
4167 -- Unknown, since that result will be set in any case.
4169 elsif Default /= Unknown
4170 and then (Has_Size_Clause (Etype (Expr))
4172 Has_Alignment_Clause (Etype (Expr)))
4174 Set_Result (Unknown);
4176 -- If no indication found, set default
4179 Set_Result (Default);
4182 -- Return worst result found
4185 end Has_Compatible_Alignment_Internal;
4187 -- Start of processing for Has_Compatible_Alignment
4190 -- If Obj has no specified alignment, then set alignment from the type
4191 -- alignment. Perhaps we should always do this, but for sure we should
4192 -- do it when there is an address clause since we can do more if the
4193 -- alignment is known.
4195 if Unknown_Alignment (Obj) then
4196 Set_Alignment (Obj, Alignment (Etype (Obj)));
4199 -- Now do the internal call that does all the work
4201 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4202 end Has_Compatible_Alignment;
4204 ----------------------
4205 -- Has_Declarations --
4206 ----------------------
4208 function Has_Declarations (N : Node_Id) return Boolean is
4209 K : constant Node_Kind := Nkind (N);
4211 return K = N_Accept_Statement
4212 or else K = N_Block_Statement
4213 or else K = N_Compilation_Unit_Aux
4214 or else K = N_Entry_Body
4215 or else K = N_Package_Body
4216 or else K = N_Protected_Body
4217 or else K = N_Subprogram_Body
4218 or else K = N_Task_Body
4219 or else K = N_Package_Specification;
4220 end Has_Declarations;
4222 -------------------------------------------
4223 -- Has_Discriminant_Dependent_Constraint --
4224 -------------------------------------------
4226 function Has_Discriminant_Dependent_Constraint
4227 (Comp : Entity_Id) return Boolean
4229 Comp_Decl : constant Node_Id := Parent (Comp);
4230 Subt_Indic : constant Node_Id :=
4231 Subtype_Indication (Component_Definition (Comp_Decl));
4236 if Nkind (Subt_Indic) = N_Subtype_Indication then
4237 Constr := Constraint (Subt_Indic);
4239 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4240 Assn := First (Constraints (Constr));
4241 while Present (Assn) loop
4242 case Nkind (Assn) is
4243 when N_Subtype_Indication |
4247 if Depends_On_Discriminant (Assn) then
4251 when N_Discriminant_Association =>
4252 if Depends_On_Discriminant (Expression (Assn)) then
4267 end Has_Discriminant_Dependent_Constraint;
4269 --------------------
4270 -- Has_Infinities --
4271 --------------------
4273 function Has_Infinities (E : Entity_Id) return Boolean is
4276 Is_Floating_Point_Type (E)
4277 and then Nkind (Scalar_Range (E)) = N_Range
4278 and then Includes_Infinities (Scalar_Range (E));
4281 ------------------------
4282 -- Has_Null_Exclusion --
4283 ------------------------
4285 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4288 when N_Access_Definition |
4289 N_Access_Function_Definition |
4290 N_Access_Procedure_Definition |
4291 N_Access_To_Object_Definition |
4293 N_Derived_Type_Definition |
4294 N_Function_Specification |
4295 N_Subtype_Declaration =>
4296 return Null_Exclusion_Present (N);
4298 when N_Component_Definition |
4299 N_Formal_Object_Declaration |
4300 N_Object_Renaming_Declaration =>
4301 if Present (Subtype_Mark (N)) then
4302 return Null_Exclusion_Present (N);
4303 else pragma Assert (Present (Access_Definition (N)));
4304 return Null_Exclusion_Present (Access_Definition (N));
4307 when N_Discriminant_Specification =>
4308 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4309 return Null_Exclusion_Present (Discriminant_Type (N));
4311 return Null_Exclusion_Present (N);
4314 when N_Object_Declaration =>
4315 if Nkind (Object_Definition (N)) = N_Access_Definition then
4316 return Null_Exclusion_Present (Object_Definition (N));
4318 return Null_Exclusion_Present (N);
4321 when N_Parameter_Specification =>
4322 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4323 return Null_Exclusion_Present (Parameter_Type (N));
4325 return Null_Exclusion_Present (N);
4332 end Has_Null_Exclusion;
4334 ------------------------
4335 -- Has_Null_Extension --
4336 ------------------------
4338 function Has_Null_Extension (T : Entity_Id) return Boolean is
4339 B : constant Entity_Id := Base_Type (T);
4344 if Nkind (Parent (B)) = N_Full_Type_Declaration
4345 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4347 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4349 if Present (Ext) then
4350 if Null_Present (Ext) then
4353 Comps := Component_List (Ext);
4355 -- The null component list is rewritten during analysis to
4356 -- include the parent component. Any other component indicates
4357 -- that the extension was not originally null.
4359 return Null_Present (Comps)
4360 or else No (Next (First (Component_Items (Comps))));
4369 end Has_Null_Extension;
4371 --------------------------------------
4372 -- Has_Preelaborable_Initialization --
4373 --------------------------------------
4375 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4378 procedure Check_Components (E : Entity_Id);
4379 -- Check component/discriminant chain, sets Has_PE False if a component
4380 -- or discriminant does not meet the preelaborable initialization rules.
4382 ----------------------
4383 -- Check_Components --
4384 ----------------------
4386 procedure Check_Components (E : Entity_Id) is
4391 -- Loop through entities of record or protected type
4394 while Present (Ent) loop
4396 -- We are interested only in components and discriminants
4398 if Ekind (Ent) = E_Component
4400 Ekind (Ent) = E_Discriminant
4402 -- Get default expression if any. If there is no declaration
4403 -- node, it means we have an internal entity. The parent and
4404 -- tag fields are examples of such entitires. For these
4405 -- cases, we just test the type of the entity.
4407 if Present (Declaration_Node (Ent)) then
4408 Exp := Expression (Declaration_Node (Ent));
4413 -- A component has PI if it has no default expression and
4414 -- the component type has PI.
4417 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4422 -- Or if expression obeys rules for preelaboration. For
4423 -- now we approximate this by testing if the default
4424 -- expression is a static expression or if it is an
4425 -- access attribute reference, or the literal null.
4427 -- This is an approximation, it is probably incomplete???
4429 elsif Is_Static_Expression (Exp) then
4432 elsif Nkind (Exp) = N_Attribute_Reference
4433 and then (Attribute_Name (Exp) = Name_Access
4435 Attribute_Name (Exp) = Name_Unchecked_Access
4437 Attribute_Name (Exp) = Name_Unrestricted_Access)
4441 elsif Nkind (Exp) = N_Null then
4452 end Check_Components;
4454 -- Start of processing for Has_Preelaborable_Initialization
4457 -- Immediate return if already marked as known preelaborable init. This
4458 -- covers types for which this function has already been called once
4459 -- and returned True (in which case the result is cached), and also
4460 -- types to which a pragma Preelaborable_Initialization applies.
4462 if Known_To_Have_Preelab_Init (E) then
4466 -- Other private types never have preelaborable initialization
4468 if Is_Private_Type (E) then
4472 -- Here for all non-private view
4474 -- All elementary types have preelaborable initialization
4476 if Is_Elementary_Type (E) then
4479 -- Array types have PI if the component type has PI
4481 elsif Is_Array_Type (E) then
4482 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4484 -- A derived type has preelaborable initialization if its parent type
4485 -- has preelaborable initialization and (in the case of a derived record
4486 -- extension) if the non-inherited components all have preelaborable
4487 -- initialization. However, a user-defined controlled type with an
4488 -- overriding Initialize procedure does not have preelaborable
4491 elsif Is_Derived_Type (E) then
4493 -- First check whether ancestor type has preelaborable initialization
4495 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4497 -- If OK, check extension components (if any)
4499 if Has_PE and then Is_Record_Type (E) then
4500 Check_Components (First_Entity (E));
4503 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4504 -- with a user defined Initialize procedure does not have PI.
4507 and then Is_Controlled (E)
4508 and then Present (Primitive_Operations (E))
4514 P := First_Elmt (Primitive_Operations (E));
4515 while Present (P) loop
4516 if Chars (Node (P)) = Name_Initialize
4517 and then Comes_From_Source (Node (P))
4528 -- Record type has PI if it is non private and all components have PI
4530 elsif Is_Record_Type (E) then
4532 Check_Components (First_Entity (E));
4534 -- Protected types must not have entries, and components must meet
4535 -- same set of rules as for record components.
4537 elsif Is_Protected_Type (E) then
4538 if Has_Entries (E) then
4542 Check_Components (First_Entity (E));
4543 Check_Components (First_Private_Entity (E));
4546 -- Type System.Address always has preelaborable initialization
4548 elsif Is_RTE (E, RE_Address) then
4551 -- In all other cases, type does not have preelaborable initialization
4557 -- If type has preelaborable initialization, cache result
4560 Set_Known_To_Have_Preelab_Init (E);
4564 end Has_Preelaborable_Initialization;
4566 ---------------------------
4567 -- Has_Private_Component --
4568 ---------------------------
4570 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4571 Btype : Entity_Id := Base_Type (Type_Id);
4572 Component : Entity_Id;
4575 if Error_Posted (Type_Id)
4576 or else Error_Posted (Btype)
4581 if Is_Class_Wide_Type (Btype) then
4582 Btype := Root_Type (Btype);
4585 if Is_Private_Type (Btype) then
4587 UT : constant Entity_Id := Underlying_Type (Btype);
4591 if No (Full_View (Btype)) then
4592 return not Is_Generic_Type (Btype)
4593 and then not Is_Generic_Type (Root_Type (Btype));
4596 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4600 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4603 elsif Is_Array_Type (Btype) then
4604 return Has_Private_Component (Component_Type (Btype));
4606 elsif Is_Record_Type (Btype) then
4608 Component := First_Component (Btype);
4609 while Present (Component) loop
4610 if Has_Private_Component (Etype (Component)) then
4614 Next_Component (Component);
4619 elsif Is_Protected_Type (Btype)
4620 and then Present (Corresponding_Record_Type (Btype))
4622 return Has_Private_Component (Corresponding_Record_Type (Btype));
4627 end Has_Private_Component;
4633 function Has_Stream (T : Entity_Id) return Boolean is
4640 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4643 elsif Is_Array_Type (T) then
4644 return Has_Stream (Component_Type (T));
4646 elsif Is_Record_Type (T) then
4647 E := First_Component (T);
4648 while Present (E) loop
4649 if Has_Stream (Etype (E)) then
4658 elsif Is_Private_Type (T) then
4659 return Has_Stream (Underlying_Type (T));
4666 --------------------------
4667 -- Has_Tagged_Component --
4668 --------------------------
4670 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4674 if Is_Private_Type (Typ)
4675 and then Present (Underlying_Type (Typ))
4677 return Has_Tagged_Component (Underlying_Type (Typ));
4679 elsif Is_Array_Type (Typ) then
4680 return Has_Tagged_Component (Component_Type (Typ));
4682 elsif Is_Tagged_Type (Typ) then
4685 elsif Is_Record_Type (Typ) then
4686 Comp := First_Component (Typ);
4687 while Present (Comp) loop
4688 if Has_Tagged_Component (Etype (Comp)) then
4692 Comp := Next_Component (Typ);
4700 end Has_Tagged_Component;
4706 function In_Instance return Boolean is
4707 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4713 and then S /= Standard_Standard
4715 if (Ekind (S) = E_Function
4716 or else Ekind (S) = E_Package
4717 or else Ekind (S) = E_Procedure)
4718 and then Is_Generic_Instance (S)
4721 -- A child instance is always compiled in the context of a parent
4722 -- instance. Nevertheless, the actuals are not analyzed in an
4723 -- instance context. We detect this case by examining the current
4724 -- compilation unit, which must be a child instance, and checking
4725 -- that it is not currently on the scope stack.
4727 if Is_Child_Unit (Curr_Unit)
4729 Nkind (Unit (Cunit (Current_Sem_Unit)))
4730 = N_Package_Instantiation
4731 and then not In_Open_Scopes (Curr_Unit)
4745 ----------------------
4746 -- In_Instance_Body --
4747 ----------------------
4749 function In_Instance_Body return Boolean is
4755 and then S /= Standard_Standard
4757 if (Ekind (S) = E_Function
4758 or else Ekind (S) = E_Procedure)
4759 and then Is_Generic_Instance (S)
4763 elsif Ekind (S) = E_Package
4764 and then In_Package_Body (S)
4765 and then Is_Generic_Instance (S)
4774 end In_Instance_Body;
4776 -----------------------------
4777 -- In_Instance_Not_Visible --
4778 -----------------------------
4780 function In_Instance_Not_Visible return Boolean is
4786 and then S /= Standard_Standard
4788 if (Ekind (S) = E_Function
4789 or else Ekind (S) = E_Procedure)
4790 and then Is_Generic_Instance (S)
4794 elsif Ekind (S) = E_Package
4795 and then (In_Package_Body (S) or else In_Private_Part (S))
4796 and then Is_Generic_Instance (S)
4805 end In_Instance_Not_Visible;
4807 ------------------------------
4808 -- In_Instance_Visible_Part --
4809 ------------------------------
4811 function In_Instance_Visible_Part return Boolean is
4817 and then S /= Standard_Standard
4819 if Ekind (S) = E_Package
4820 and then Is_Generic_Instance (S)
4821 and then not In_Package_Body (S)
4822 and then not In_Private_Part (S)
4831 end In_Instance_Visible_Part;
4833 ----------------------
4834 -- In_Packiage_Body --
4835 ----------------------
4837 function In_Package_Body return Boolean is
4843 and then S /= Standard_Standard
4845 if Ekind (S) = E_Package
4846 and then In_Package_Body (S)
4855 end In_Package_Body;
4857 --------------------------------------
4858 -- In_Subprogram_Or_Concurrent_Unit --
4859 --------------------------------------
4861 function In_Subprogram_Or_Concurrent_Unit return Boolean is
4866 -- Use scope chain to check successively outer scopes
4872 if K in Subprogram_Kind
4873 or else K in Concurrent_Kind
4874 or else K in Generic_Subprogram_Kind
4878 elsif E = Standard_Standard then
4884 end In_Subprogram_Or_Concurrent_Unit;
4886 ---------------------
4887 -- In_Visible_Part --
4888 ---------------------
4890 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
4893 Is_Package_Or_Generic_Package (Scope_Id)
4894 and then In_Open_Scopes (Scope_Id)
4895 and then not In_Package_Body (Scope_Id)
4896 and then not In_Private_Part (Scope_Id);
4897 end In_Visible_Part;
4899 ---------------------------------
4900 -- Insert_Explicit_Dereference --
4901 ---------------------------------
4903 procedure Insert_Explicit_Dereference (N : Node_Id) is
4904 New_Prefix : constant Node_Id := Relocate_Node (N);
4905 Ent : Entity_Id := Empty;
4912 Save_Interps (N, New_Prefix);
4914 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
4916 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
4918 if Is_Overloaded (New_Prefix) then
4920 -- The deference is also overloaded, and its interpretations are the
4921 -- designated types of the interpretations of the original node.
4923 Set_Etype (N, Any_Type);
4925 Get_First_Interp (New_Prefix, I, It);
4926 while Present (It.Nam) loop
4929 if Is_Access_Type (T) then
4930 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
4933 Get_Next_Interp (I, It);
4939 -- Prefix is unambiguous: mark the original prefix (which might
4940 -- Come_From_Source) as a reference, since the new (relocated) one
4941 -- won't be taken into account.
4943 if Is_Entity_Name (New_Prefix) then
4944 Ent := Entity (New_Prefix);
4946 -- For a retrieval of a subcomponent of some composite object,
4947 -- retrieve the ultimate entity if there is one.
4949 elsif Nkind (New_Prefix) = N_Selected_Component
4950 or else Nkind (New_Prefix) = N_Indexed_Component
4952 Pref := Prefix (New_Prefix);
4953 while Present (Pref)
4955 (Nkind (Pref) = N_Selected_Component
4956 or else Nkind (Pref) = N_Indexed_Component)
4958 Pref := Prefix (Pref);
4961 if Present (Pref) and then Is_Entity_Name (Pref) then
4962 Ent := Entity (Pref);
4966 if Present (Ent) then
4967 Generate_Reference (Ent, New_Prefix);
4970 end Insert_Explicit_Dereference;
4976 function Is_AAMP_Float (E : Entity_Id) return Boolean is
4978 pragma Assert (Is_Type (E));
4980 return AAMP_On_Target
4981 and then Is_Floating_Point_Type (E)
4982 and then E = Base_Type (E);
4985 -------------------------
4986 -- Is_Actual_Parameter --
4987 -------------------------
4989 function Is_Actual_Parameter (N : Node_Id) return Boolean is
4990 PK : constant Node_Kind := Nkind (Parent (N));
4994 when N_Parameter_Association =>
4995 return N = Explicit_Actual_Parameter (Parent (N));
4997 when N_Function_Call | N_Procedure_Call_Statement =>
4998 return Is_List_Member (N)
5000 List_Containing (N) = Parameter_Associations (Parent (N));
5005 end Is_Actual_Parameter;
5007 ---------------------
5008 -- Is_Aliased_View --
5009 ---------------------
5011 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5015 if Is_Entity_Name (Obj) then
5023 or else (Present (Renamed_Object (E))
5024 and then Is_Aliased_View (Renamed_Object (E)))))
5026 or else ((Is_Formal (E)
5027 or else Ekind (E) = E_Generic_In_Out_Parameter
5028 or else Ekind (E) = E_Generic_In_Parameter)
5029 and then Is_Tagged_Type (Etype (E)))
5031 or else (Is_Concurrent_Type (E)
5032 and then In_Open_Scopes (E))
5034 -- Current instance of type, either directly or as rewritten
5035 -- reference to the current object.
5037 or else (Is_Entity_Name (Original_Node (Obj))
5038 and then Present (Entity (Original_Node (Obj)))
5039 and then Is_Type (Entity (Original_Node (Obj))))
5041 or else (Is_Type (E) and then E = Current_Scope)
5043 or else (Is_Incomplete_Or_Private_Type (E)
5044 and then Full_View (E) = Current_Scope);
5046 elsif Nkind (Obj) = N_Selected_Component then
5047 return Is_Aliased (Entity (Selector_Name (Obj)));
5049 elsif Nkind (Obj) = N_Indexed_Component then
5050 return Has_Aliased_Components (Etype (Prefix (Obj)))
5052 (Is_Access_Type (Etype (Prefix (Obj)))
5054 Has_Aliased_Components
5055 (Designated_Type (Etype (Prefix (Obj)))));
5057 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5058 or else Nkind (Obj) = N_Type_Conversion
5060 return Is_Tagged_Type (Etype (Obj))
5061 and then Is_Aliased_View (Expression (Obj));
5063 elsif Nkind (Obj) = N_Explicit_Dereference then
5064 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5069 end Is_Aliased_View;
5071 -------------------------
5072 -- Is_Ancestor_Package --
5073 -------------------------
5075 function Is_Ancestor_Package
5077 E2 : Entity_Id) return Boolean
5084 and then Par /= Standard_Standard
5094 end Is_Ancestor_Package;
5096 ----------------------
5097 -- Is_Atomic_Object --
5098 ----------------------
5100 function Is_Atomic_Object (N : Node_Id) return Boolean is
5102 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5103 -- Determines if given object has atomic components
5105 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5106 -- If prefix is an implicit dereference, examine designated type
5108 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5110 if Is_Access_Type (Etype (N)) then
5112 Has_Atomic_Components (Designated_Type (Etype (N)));
5114 return Object_Has_Atomic_Components (N);
5116 end Is_Atomic_Prefix;
5118 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5120 if Has_Atomic_Components (Etype (N))
5121 or else Is_Atomic (Etype (N))
5125 elsif Is_Entity_Name (N)
5126 and then (Has_Atomic_Components (Entity (N))
5127 or else Is_Atomic (Entity (N)))
5131 elsif Nkind (N) = N_Indexed_Component
5132 or else Nkind (N) = N_Selected_Component
5134 return Is_Atomic_Prefix (Prefix (N));
5139 end Object_Has_Atomic_Components;
5141 -- Start of processing for Is_Atomic_Object
5144 if Is_Atomic (Etype (N))
5145 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5149 elsif Nkind (N) = N_Indexed_Component
5150 or else Nkind (N) = N_Selected_Component
5152 return Is_Atomic_Prefix (Prefix (N));
5157 end Is_Atomic_Object;
5159 -------------------------
5160 -- Is_Coextension_Root --
5161 -------------------------
5163 function Is_Coextension_Root (N : Node_Id) return Boolean is
5166 Nkind (N) = N_Allocator
5167 and then Present (Coextensions (N))
5169 -- Anonymous access discriminants carry a list of all nested
5170 -- controlled coextensions.
5172 and then not Is_Dynamic_Coextension (N)
5173 and then not Is_Static_Coextension (N);
5174 end Is_Coextension_Root;
5176 --------------------------------------
5177 -- Is_Controlling_Limited_Procedure --
5178 --------------------------------------
5180 function Is_Controlling_Limited_Procedure
5181 (Proc_Nam : Entity_Id) return Boolean
5183 Param_Typ : Entity_Id := Empty;
5186 if Ekind (Proc_Nam) = E_Procedure
5187 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5189 Param_Typ := Etype (Parameter_Type (First (
5190 Parameter_Specifications (Parent (Proc_Nam)))));
5192 -- In this case where an Itype was created, the procedure call has been
5195 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5196 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5198 Present (Parameter_Associations
5199 (Associated_Node_For_Itype (Proc_Nam)))
5202 Etype (First (Parameter_Associations
5203 (Associated_Node_For_Itype (Proc_Nam))));
5206 if Present (Param_Typ) then
5208 Is_Interface (Param_Typ)
5209 and then Is_Limited_Record (Param_Typ);
5213 end Is_Controlling_Limited_Procedure;
5215 ----------------------------------------------
5216 -- Is_Dependent_Component_Of_Mutable_Object --
5217 ----------------------------------------------
5219 function Is_Dependent_Component_Of_Mutable_Object
5220 (Object : Node_Id) return Boolean
5223 Prefix_Type : Entity_Id;
5224 P_Aliased : Boolean := False;
5227 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5228 -- Returns True if and only if Comp is declared within a variant part
5230 --------------------------------
5231 -- Is_Declared_Within_Variant --
5232 --------------------------------
5234 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5235 Comp_Decl : constant Node_Id := Parent (Comp);
5236 Comp_List : constant Node_Id := Parent (Comp_Decl);
5238 return Nkind (Parent (Comp_List)) = N_Variant;
5239 end Is_Declared_Within_Variant;
5241 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5244 if Is_Variable (Object) then
5246 if Nkind (Object) = N_Selected_Component then
5247 P := Prefix (Object);
5248 Prefix_Type := Etype (P);
5250 if Is_Entity_Name (P) then
5252 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5253 Prefix_Type := Base_Type (Prefix_Type);
5256 if Is_Aliased (Entity (P)) then
5260 -- A discriminant check on a selected component may be
5261 -- expanded into a dereference when removing side-effects.
5262 -- Recover the original node and its type, which may be
5265 elsif Nkind (P) = N_Explicit_Dereference
5266 and then not (Comes_From_Source (P))
5268 P := Original_Node (P);
5269 Prefix_Type := Etype (P);
5272 -- Check for prefix being an aliased component ???
5277 -- A heap object is constrained by its initial value
5279 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5280 -- the dereferenced case, since the access value might denote an
5281 -- unconstrained aliased object, whereas in Ada 95 the designated
5282 -- object is guaranteed to be constrained. A worst-case assumption
5283 -- has to apply in Ada 2005 because we can't tell at compile time
5284 -- whether the object is "constrained by its initial value"
5285 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5286 -- semantic rules -- these rules are acknowledged to need fixing).
5288 if Ada_Version < Ada_05 then
5289 if Is_Access_Type (Prefix_Type)
5290 or else Nkind (P) = N_Explicit_Dereference
5295 elsif Ada_Version >= Ada_05 then
5296 if Is_Access_Type (Prefix_Type) then
5297 Prefix_Type := Designated_Type (Prefix_Type);
5302 Original_Record_Component (Entity (Selector_Name (Object)));
5304 -- As per AI-0017, the renaming is illegal in a generic body,
5305 -- even if the subtype is indefinite.
5307 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5309 if not Is_Constrained (Prefix_Type)
5310 and then (not Is_Indefinite_Subtype (Prefix_Type)
5312 (Is_Generic_Type (Prefix_Type)
5313 and then Ekind (Current_Scope) = E_Generic_Package
5314 and then In_Package_Body (Current_Scope)))
5316 and then (Is_Declared_Within_Variant (Comp)
5317 or else Has_Discriminant_Dependent_Constraint (Comp))
5318 and then (not P_Aliased or else Ada_Version >= Ada_05)
5324 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5328 elsif Nkind (Object) = N_Indexed_Component
5329 or else Nkind (Object) = N_Slice
5331 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5333 -- A type conversion that Is_Variable is a view conversion:
5334 -- go back to the denoted object.
5336 elsif Nkind (Object) = N_Type_Conversion then
5338 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5343 end Is_Dependent_Component_Of_Mutable_Object;
5345 ---------------------
5346 -- Is_Dereferenced --
5347 ---------------------
5349 function Is_Dereferenced (N : Node_Id) return Boolean is
5350 P : constant Node_Id := Parent (N);
5353 (Nkind (P) = N_Selected_Component
5355 Nkind (P) = N_Explicit_Dereference
5357 Nkind (P) = N_Indexed_Component
5359 Nkind (P) = N_Slice)
5360 and then Prefix (P) = N;
5361 end Is_Dereferenced;
5363 ----------------------
5364 -- Is_Descendent_Of --
5365 ----------------------
5367 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5372 pragma Assert (Nkind (T1) in N_Entity);
5373 pragma Assert (Nkind (T2) in N_Entity);
5375 T := Base_Type (T1);
5377 -- Immediate return if the types match
5382 -- Comment needed here ???
5384 elsif Ekind (T) = E_Class_Wide_Type then
5385 return Etype (T) = T2;
5393 -- Done if we found the type we are looking for
5398 -- Done if no more derivations to check
5405 -- Following test catches error cases resulting from prev errors
5407 elsif No (Etyp) then
5410 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5413 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5417 T := Base_Type (Etyp);
5421 raise Program_Error;
5422 end Is_Descendent_Of;
5424 ------------------------------
5425 -- Is_Descendent_Of_Address --
5426 ------------------------------
5428 function Is_Descendent_Of_Address (T1 : Entity_Id) return Boolean is
5430 -- If Address has not been loaded, answer must be False
5432 if not RTU_Loaded (System) then
5435 -- Otherwise we can get the entity we are interested in without
5436 -- causing an unwanted dependency on System, and do the test.
5439 return Is_Descendent_Of (T1, Base_Type (RTE (RE_Address)));
5441 end Is_Descendent_Of_Address;
5447 function Is_False (U : Uint) return Boolean is
5452 ---------------------------
5453 -- Is_Fixed_Model_Number --
5454 ---------------------------
5456 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5457 S : constant Ureal := Small_Value (T);
5458 M : Urealp.Save_Mark;
5462 R := (U = UR_Trunc (U / S) * S);
5465 end Is_Fixed_Model_Number;
5467 -------------------------------
5468 -- Is_Fully_Initialized_Type --
5469 -------------------------------
5471 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5473 if Is_Scalar_Type (Typ) then
5476 elsif Is_Access_Type (Typ) then
5479 elsif Is_Array_Type (Typ) then
5480 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5484 -- An interesting case, if we have a constrained type one of whose
5485 -- bounds is known to be null, then there are no elements to be
5486 -- initialized, so all the elements are initialized!
5488 if Is_Constrained (Typ) then
5491 Indx_Typ : Entity_Id;
5495 Indx := First_Index (Typ);
5496 while Present (Indx) loop
5497 if Etype (Indx) = Any_Type then
5500 -- If index is a range, use directly
5502 elsif Nkind (Indx) = N_Range then
5503 Lbd := Low_Bound (Indx);
5504 Hbd := High_Bound (Indx);
5507 Indx_Typ := Etype (Indx);
5509 if Is_Private_Type (Indx_Typ) then
5510 Indx_Typ := Full_View (Indx_Typ);
5513 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5516 Lbd := Type_Low_Bound (Indx_Typ);
5517 Hbd := Type_High_Bound (Indx_Typ);
5521 if Compile_Time_Known_Value (Lbd)
5522 and then Compile_Time_Known_Value (Hbd)
5524 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5534 -- If no null indexes, then type is not fully initialized
5540 elsif Is_Record_Type (Typ) then
5541 if Has_Discriminants (Typ)
5543 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5544 and then Is_Fully_Initialized_Variant (Typ)
5549 -- Controlled records are considered to be fully initialized if
5550 -- there is a user defined Initialize routine. This may not be
5551 -- entirely correct, but as the spec notes, we are guessing here
5552 -- what is best from the point of view of issuing warnings.
5554 if Is_Controlled (Typ) then
5556 Utyp : constant Entity_Id := Underlying_Type (Typ);
5559 if Present (Utyp) then
5561 Init : constant Entity_Id :=
5563 (Underlying_Type (Typ), Name_Initialize));
5567 and then Comes_From_Source (Init)
5569 Is_Predefined_File_Name
5570 (File_Name (Get_Source_File_Index (Sloc (Init))))
5574 elsif Has_Null_Extension (Typ)
5576 Is_Fully_Initialized_Type
5577 (Etype (Base_Type (Typ)))
5586 -- Otherwise see if all record components are initialized
5592 Ent := First_Entity (Typ);
5593 while Present (Ent) loop
5594 if Chars (Ent) = Name_uController then
5597 elsif Ekind (Ent) = E_Component
5598 and then (No (Parent (Ent))
5599 or else No (Expression (Parent (Ent))))
5600 and then not Is_Fully_Initialized_Type (Etype (Ent))
5602 -- Special VM case for uTag component, which needs to be
5603 -- defined in this case, but is never initialized as VMs
5604 -- are using other dispatching mechanisms. Ignore this
5605 -- uninitialized case.
5607 and then (VM_Target = No_VM
5608 or else Chars (Ent) /= Name_uTag)
5617 -- No uninitialized components, so type is fully initialized.
5618 -- Note that this catches the case of no components as well.
5622 elsif Is_Concurrent_Type (Typ) then
5625 elsif Is_Private_Type (Typ) then
5627 U : constant Entity_Id := Underlying_Type (Typ);
5633 return Is_Fully_Initialized_Type (U);
5640 end Is_Fully_Initialized_Type;
5642 ----------------------------------
5643 -- Is_Fully_Initialized_Variant --
5644 ----------------------------------
5646 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5647 Loc : constant Source_Ptr := Sloc (Typ);
5648 Constraints : constant List_Id := New_List;
5649 Components : constant Elist_Id := New_Elmt_List;
5650 Comp_Elmt : Elmt_Id;
5652 Comp_List : Node_Id;
5654 Discr_Val : Node_Id;
5655 Report_Errors : Boolean;
5658 if Serious_Errors_Detected > 0 then
5662 if Is_Record_Type (Typ)
5663 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5664 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5666 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5668 Discr := First_Discriminant (Typ);
5669 while Present (Discr) loop
5670 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5671 Discr_Val := Expression (Parent (Discr));
5673 if Present (Discr_Val)
5674 and then Is_OK_Static_Expression (Discr_Val)
5676 Append_To (Constraints,
5677 Make_Component_Association (Loc,
5678 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5679 Expression => New_Copy (Discr_Val)));
5687 Next_Discriminant (Discr);
5692 Comp_List => Comp_List,
5693 Governed_By => Constraints,
5695 Report_Errors => Report_Errors);
5697 -- Check that each component present is fully initialized
5699 Comp_Elmt := First_Elmt (Components);
5700 while Present (Comp_Elmt) loop
5701 Comp_Id := Node (Comp_Elmt);
5703 if Ekind (Comp_Id) = E_Component
5704 and then (No (Parent (Comp_Id))
5705 or else No (Expression (Parent (Comp_Id))))
5706 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5711 Next_Elmt (Comp_Elmt);
5716 elsif Is_Private_Type (Typ) then
5718 U : constant Entity_Id := Underlying_Type (Typ);
5724 return Is_Fully_Initialized_Variant (U);
5730 end Is_Fully_Initialized_Variant;
5732 ----------------------------
5733 -- Is_Inherited_Operation --
5734 ----------------------------
5736 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
5737 Kind : constant Node_Kind := Nkind (Parent (E));
5739 pragma Assert (Is_Overloadable (E));
5740 return Kind = N_Full_Type_Declaration
5741 or else Kind = N_Private_Extension_Declaration
5742 or else Kind = N_Subtype_Declaration
5743 or else (Ekind (E) = E_Enumeration_Literal
5744 and then Is_Derived_Type (Etype (E)));
5745 end Is_Inherited_Operation;
5747 -----------------------------
5748 -- Is_Library_Level_Entity --
5749 -----------------------------
5751 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
5753 -- The following is a small optimization, and it also properly handles
5754 -- discriminals, which in task bodies might appear in expressions before
5755 -- the corresponding procedure has been created, and which therefore do
5756 -- not have an assigned scope.
5758 if Ekind (E) in Formal_Kind then
5762 -- Normal test is simply that the enclosing dynamic scope is Standard
5764 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
5765 end Is_Library_Level_Entity;
5767 ---------------------------------
5768 -- Is_Local_Variable_Reference --
5769 ---------------------------------
5771 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
5773 if not Is_Entity_Name (Expr) then
5778 Ent : constant Entity_Id := Entity (Expr);
5779 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
5781 if Ekind (Ent) /= E_Variable
5783 Ekind (Ent) /= E_In_Out_Parameter
5787 return Present (Sub) and then Sub = Current_Subprogram;
5791 end Is_Local_Variable_Reference;
5793 -------------------------
5794 -- Is_Object_Reference --
5795 -------------------------
5797 function Is_Object_Reference (N : Node_Id) return Boolean is
5799 if Is_Entity_Name (N) then
5800 return Present (Entity (N)) and then Is_Object (Entity (N));
5804 when N_Indexed_Component | N_Slice =>
5806 Is_Object_Reference (Prefix (N))
5807 or else Is_Access_Type (Etype (Prefix (N)));
5809 -- In Ada95, a function call is a constant object; a procedure
5812 when N_Function_Call =>
5813 return Etype (N) /= Standard_Void_Type;
5815 -- A reference to the stream attribute Input is a function call
5817 when N_Attribute_Reference =>
5818 return Attribute_Name (N) = Name_Input;
5820 when N_Selected_Component =>
5822 Is_Object_Reference (Selector_Name (N))
5824 (Is_Object_Reference (Prefix (N))
5825 or else Is_Access_Type (Etype (Prefix (N))));
5827 when N_Explicit_Dereference =>
5830 -- A view conversion of a tagged object is an object reference
5832 when N_Type_Conversion =>
5833 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
5834 and then Is_Tagged_Type (Etype (Expression (N)))
5835 and then Is_Object_Reference (Expression (N));
5837 -- An unchecked type conversion is considered to be an object if
5838 -- the operand is an object (this construction arises only as a
5839 -- result of expansion activities).
5841 when N_Unchecked_Type_Conversion =>
5848 end Is_Object_Reference;
5850 -----------------------------------
5851 -- Is_OK_Variable_For_Out_Formal --
5852 -----------------------------------
5854 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
5856 Note_Possible_Modification (AV);
5858 -- We must reject parenthesized variable names. The check for
5859 -- Comes_From_Source is present because there are currently
5860 -- cases where the compiler violates this rule (e.g. passing
5861 -- a task object to its controlled Initialize routine).
5863 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
5866 -- A variable is always allowed
5868 elsif Is_Variable (AV) then
5871 -- Unchecked conversions are allowed only if they come from the
5872 -- generated code, which sometimes uses unchecked conversions for out
5873 -- parameters in cases where code generation is unaffected. We tell
5874 -- source unchecked conversions by seeing if they are rewrites of an
5875 -- original Unchecked_Conversion function call, or of an explicit
5876 -- conversion of a function call.
5878 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
5879 if Nkind (Original_Node (AV)) = N_Function_Call then
5882 elsif Comes_From_Source (AV)
5883 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
5887 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
5888 return Is_OK_Variable_For_Out_Formal (Expression (AV));
5894 -- Normal type conversions are allowed if argument is a variable
5896 elsif Nkind (AV) = N_Type_Conversion then
5897 if Is_Variable (Expression (AV))
5898 and then Paren_Count (Expression (AV)) = 0
5900 Note_Possible_Modification (Expression (AV));
5903 -- We also allow a non-parenthesized expression that raises
5904 -- constraint error if it rewrites what used to be a variable
5906 elsif Raises_Constraint_Error (Expression (AV))
5907 and then Paren_Count (Expression (AV)) = 0
5908 and then Is_Variable (Original_Node (Expression (AV)))
5912 -- Type conversion of something other than a variable
5918 -- If this node is rewritten, then test the original form, if that is
5919 -- OK, then we consider the rewritten node OK (for example, if the
5920 -- original node is a conversion, then Is_Variable will not be true
5921 -- but we still want to allow the conversion if it converts a variable).
5923 elsif Original_Node (AV) /= AV then
5924 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
5926 -- All other non-variables are rejected
5931 end Is_OK_Variable_For_Out_Formal;
5939 E2 : Entity_Id) return Boolean
5941 Iface_List : List_Id;
5942 T : Entity_Id := E2;
5945 if Is_Concurrent_Type (T)
5946 or else Is_Concurrent_Record_Type (T)
5948 Iface_List := Abstract_Interface_List (E2);
5950 if Is_Empty_List (Iface_List) then
5954 T := Etype (First (Iface_List));
5957 return Is_Ancestor (E1, T);
5960 -----------------------------------
5961 -- Is_Partially_Initialized_Type --
5962 -----------------------------------
5964 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
5966 if Is_Scalar_Type (Typ) then
5969 elsif Is_Access_Type (Typ) then
5972 elsif Is_Array_Type (Typ) then
5974 -- If component type is partially initialized, so is array type
5976 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
5979 -- Otherwise we are only partially initialized if we are fully
5980 -- initialized (this is the empty array case, no point in us
5981 -- duplicating that code here).
5984 return Is_Fully_Initialized_Type (Typ);
5987 elsif Is_Record_Type (Typ) then
5989 -- A discriminated type is always partially initialized
5991 if Has_Discriminants (Typ) then
5994 -- A tagged type is always partially initialized
5996 elsif Is_Tagged_Type (Typ) then
5999 -- Case of non-discriminated record
6005 Component_Present : Boolean := False;
6006 -- Set True if at least one component is present. If no
6007 -- components are present, then record type is fully
6008 -- initialized (another odd case, like the null array).
6011 -- Loop through components
6013 Ent := First_Entity (Typ);
6014 while Present (Ent) loop
6015 if Ekind (Ent) = E_Component then
6016 Component_Present := True;
6018 -- If a component has an initialization expression then
6019 -- the enclosing record type is partially initialized
6021 if Present (Parent (Ent))
6022 and then Present (Expression (Parent (Ent)))
6026 -- If a component is of a type which is itself partially
6027 -- initialized, then the enclosing record type is also.
6029 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6037 -- No initialized components found. If we found any components
6038 -- they were all uninitialized so the result is false.
6040 if Component_Present then
6043 -- But if we found no components, then all the components are
6044 -- initialized so we consider the type to be initialized.
6052 -- Concurrent types are always fully initialized
6054 elsif Is_Concurrent_Type (Typ) then
6057 -- For a private type, go to underlying type. If there is no underlying
6058 -- type then just assume this partially initialized. Not clear if this
6059 -- can happen in a non-error case, but no harm in testing for this.
6061 elsif Is_Private_Type (Typ) then
6063 U : constant Entity_Id := Underlying_Type (Typ);
6068 return Is_Partially_Initialized_Type (U);
6072 -- For any other type (are there any?) assume partially initialized
6077 end Is_Partially_Initialized_Type;
6079 ------------------------------------
6080 -- Is_Potentially_Persistent_Type --
6081 ------------------------------------
6083 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6088 -- For private type, test corrresponding full type
6090 if Is_Private_Type (T) then
6091 return Is_Potentially_Persistent_Type (Full_View (T));
6093 -- Scalar types are potentially persistent
6095 elsif Is_Scalar_Type (T) then
6098 -- Record type is potentially persistent if not tagged and the types of
6099 -- all it components are potentially persistent, and no component has
6100 -- an initialization expression.
6102 elsif Is_Record_Type (T)
6103 and then not Is_Tagged_Type (T)
6104 and then not Is_Partially_Initialized_Type (T)
6106 Comp := First_Component (T);
6107 while Present (Comp) loop
6108 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6117 -- Array type is potentially persistent if its component type is
6118 -- potentially persistent and if all its constraints are static.
6120 elsif Is_Array_Type (T) then
6121 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6125 Indx := First_Index (T);
6126 while Present (Indx) loop
6127 if not Is_OK_Static_Subtype (Etype (Indx)) then
6136 -- All other types are not potentially persistent
6141 end Is_Potentially_Persistent_Type;
6143 -----------------------------
6144 -- Is_RCI_Pkg_Spec_Or_Body --
6145 -----------------------------
6147 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6149 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6150 -- Return True if the unit of Cunit is an RCI package declaration
6152 ---------------------------
6153 -- Is_RCI_Pkg_Decl_Cunit --
6154 ---------------------------
6156 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6157 The_Unit : constant Node_Id := Unit (Cunit);
6160 if Nkind (The_Unit) /= N_Package_Declaration then
6164 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6165 end Is_RCI_Pkg_Decl_Cunit;
6167 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6170 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6172 (Nkind (Unit (Cunit)) = N_Package_Body
6173 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6174 end Is_RCI_Pkg_Spec_Or_Body;
6176 -----------------------------------------
6177 -- Is_Remote_Access_To_Class_Wide_Type --
6178 -----------------------------------------
6180 function Is_Remote_Access_To_Class_Wide_Type
6181 (E : Entity_Id) return Boolean
6185 function Comes_From_Limited_Private_Type_Declaration
6186 (E : Entity_Id) return Boolean;
6187 -- Check that the type is declared by a limited type declaration,
6188 -- or else is derived from a Remote_Type ancestor through private
6191 -------------------------------------------------
6192 -- Comes_From_Limited_Private_Type_Declaration --
6193 -------------------------------------------------
6195 function Comes_From_Limited_Private_Type_Declaration
6196 (E : Entity_Id) return Boolean
6198 N : constant Node_Id := Declaration_Node (E);
6201 if Nkind (N) = N_Private_Type_Declaration
6202 and then Limited_Present (N)
6207 if Nkind (N) = N_Private_Extension_Declaration then
6209 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6211 (Is_Remote_Types (Etype (E))
6212 and then Is_Limited_Record (Etype (E))
6213 and then Has_Private_Declaration (Etype (E)));
6217 end Comes_From_Limited_Private_Type_Declaration;
6219 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6222 if not (Is_Remote_Call_Interface (E)
6223 or else Is_Remote_Types (E))
6224 or else Ekind (E) /= E_General_Access_Type
6229 D := Designated_Type (E);
6231 if Ekind (D) /= E_Class_Wide_Type then
6235 return Comes_From_Limited_Private_Type_Declaration
6236 (Defining_Identifier (Parent (D)));
6237 end Is_Remote_Access_To_Class_Wide_Type;
6239 -----------------------------------------
6240 -- Is_Remote_Access_To_Subprogram_Type --
6241 -----------------------------------------
6243 function Is_Remote_Access_To_Subprogram_Type
6244 (E : Entity_Id) return Boolean
6247 return (Ekind (E) = E_Access_Subprogram_Type
6248 or else (Ekind (E) = E_Record_Type
6249 and then Present (Corresponding_Remote_Type (E))))
6250 and then (Is_Remote_Call_Interface (E)
6251 or else Is_Remote_Types (E));
6252 end Is_Remote_Access_To_Subprogram_Type;
6254 --------------------
6255 -- Is_Remote_Call --
6256 --------------------
6258 function Is_Remote_Call (N : Node_Id) return Boolean is
6260 if Nkind (N) /= N_Procedure_Call_Statement
6261 and then Nkind (N) /= N_Function_Call
6263 -- An entry call cannot be remote
6267 elsif Nkind (Name (N)) in N_Has_Entity
6268 and then Is_Remote_Call_Interface (Entity (Name (N)))
6270 -- A subprogram declared in the spec of a RCI package is remote
6274 elsif Nkind (Name (N)) = N_Explicit_Dereference
6275 and then Is_Remote_Access_To_Subprogram_Type
6276 (Etype (Prefix (Name (N))))
6278 -- The dereference of a RAS is a remote call
6282 elsif Present (Controlling_Argument (N))
6283 and then Is_Remote_Access_To_Class_Wide_Type
6284 (Etype (Controlling_Argument (N)))
6286 -- Any primitive operation call with a controlling argument of
6287 -- a RACW type is a remote call.
6292 -- All other calls are local calls
6297 ----------------------
6298 -- Is_Renamed_Entry --
6299 ----------------------
6301 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6302 Orig_Node : Node_Id := Empty;
6303 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6305 function Is_Entry (Nam : Node_Id) return Boolean;
6306 -- Determine whether Nam is an entry. Traverse selectors
6307 -- if there are nested selected components.
6313 function Is_Entry (Nam : Node_Id) return Boolean is
6315 if Nkind (Nam) = N_Selected_Component then
6316 return Is_Entry (Selector_Name (Nam));
6319 return Ekind (Entity (Nam)) = E_Entry;
6322 -- Start of processing for Is_Renamed_Entry
6325 if Present (Alias (Proc_Nam)) then
6326 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6329 -- Look for a rewritten subprogram renaming declaration
6331 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6332 and then Present (Original_Node (Subp_Decl))
6334 Orig_Node := Original_Node (Subp_Decl);
6337 -- The rewritten subprogram is actually an entry
6339 if Present (Orig_Node)
6340 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6341 and then Is_Entry (Name (Orig_Node))
6347 end Is_Renamed_Entry;
6349 ----------------------
6350 -- Is_Selector_Name --
6351 ----------------------
6353 function Is_Selector_Name (N : Node_Id) return Boolean is
6355 if not Is_List_Member (N) then
6357 P : constant Node_Id := Parent (N);
6358 K : constant Node_Kind := Nkind (P);
6361 (K = N_Expanded_Name or else
6362 K = N_Generic_Association or else
6363 K = N_Parameter_Association or else
6364 K = N_Selected_Component)
6365 and then Selector_Name (P) = N;
6370 L : constant List_Id := List_Containing (N);
6371 P : constant Node_Id := Parent (L);
6373 return (Nkind (P) = N_Discriminant_Association
6374 and then Selector_Names (P) = L)
6376 (Nkind (P) = N_Component_Association
6377 and then Choices (P) = L);
6380 end Is_Selector_Name;
6386 function Is_Statement (N : Node_Id) return Boolean is
6389 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6390 or else Nkind (N) = N_Procedure_Call_Statement;
6393 ---------------------------------
6394 -- Is_Synchronized_Tagged_Type --
6395 ---------------------------------
6397 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6398 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6401 -- A task or protected type derived from an interface is a tagged type.
6402 -- Such a tagged type is called a synchronized tagged type, as are
6403 -- synchronized interfaces and private extensions whose declaration
6404 -- includes the reserved word synchronized.
6406 return (Is_Tagged_Type (E)
6407 and then (Kind = E_Task_Type
6408 or else Kind = E_Protected_Type))
6411 and then Is_Synchronized_Interface (E))
6413 (Ekind (E) = E_Record_Type_With_Private
6414 and then (Synchronized_Present (Parent (E))
6415 or else Is_Synchronized_Interface (Etype (E))));
6416 end Is_Synchronized_Tagged_Type;
6422 function Is_Transfer (N : Node_Id) return Boolean is
6423 Kind : constant Node_Kind := Nkind (N);
6426 if Kind = N_Simple_Return_Statement
6428 Kind = N_Extended_Return_Statement
6430 Kind = N_Goto_Statement
6432 Kind = N_Raise_Statement
6434 Kind = N_Requeue_Statement
6438 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6439 and then No (Condition (N))
6443 elsif Kind = N_Procedure_Call_Statement
6444 and then Is_Entity_Name (Name (N))
6445 and then Present (Entity (Name (N)))
6446 and then No_Return (Entity (Name (N)))
6450 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6462 function Is_True (U : Uint) return Boolean is
6471 function Is_Value_Type (T : Entity_Id) return Boolean is
6473 return VM_Target = CLI_Target
6474 and then Chars (T) /= No_Name
6475 and then Get_Name_String (Chars (T)) = "valuetype";
6482 function Is_Variable (N : Node_Id) return Boolean is
6484 Orig_Node : constant Node_Id := Original_Node (N);
6485 -- We do the test on the original node, since this is basically a
6486 -- test of syntactic categories, so it must not be disturbed by
6487 -- whatever rewriting might have occurred. For example, an aggregate,
6488 -- which is certainly NOT a variable, could be turned into a variable
6491 function In_Protected_Function (E : Entity_Id) return Boolean;
6492 -- Within a protected function, the private components of the
6493 -- enclosing protected type are constants. A function nested within
6494 -- a (protected) procedure is not itself protected.
6496 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6497 -- Prefixes can involve implicit dereferences, in which case we
6498 -- must test for the case of a reference of a constant access
6499 -- type, which can never be a variable.
6501 ---------------------------
6502 -- In_Protected_Function --
6503 ---------------------------
6505 function In_Protected_Function (E : Entity_Id) return Boolean is
6506 Prot : constant Entity_Id := Scope (E);
6510 if not Is_Protected_Type (Prot) then
6514 while Present (S) and then S /= Prot loop
6515 if Ekind (S) = E_Function
6516 and then Scope (S) = Prot
6526 end In_Protected_Function;
6528 ------------------------
6529 -- Is_Variable_Prefix --
6530 ------------------------
6532 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6534 if Is_Access_Type (Etype (P)) then
6535 return not Is_Access_Constant (Root_Type (Etype (P)));
6537 -- For the case of an indexed component whose prefix has a packed
6538 -- array type, the prefix has been rewritten into a type conversion.
6539 -- Determine variable-ness from the converted expression.
6541 elsif Nkind (P) = N_Type_Conversion
6542 and then not Comes_From_Source (P)
6543 and then Is_Array_Type (Etype (P))
6544 and then Is_Packed (Etype (P))
6546 return Is_Variable (Expression (P));
6549 return Is_Variable (P);
6551 end Is_Variable_Prefix;
6553 -- Start of processing for Is_Variable
6556 -- Definitely OK if Assignment_OK is set. Since this is something that
6557 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6559 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6562 -- Normally we go to the original node, but there is one exception
6563 -- where we use the rewritten node, namely when it is an explicit
6564 -- dereference. The generated code may rewrite a prefix which is an
6565 -- access type with an explicit dereference. The dereference is a
6566 -- variable, even though the original node may not be (since it could
6567 -- be a constant of the access type).
6569 -- In Ada 2005 we have a further case to consider: the prefix may be
6570 -- a function call given in prefix notation. The original node appears
6571 -- to be a selected component, but we need to examine the call.
6573 elsif Nkind (N) = N_Explicit_Dereference
6574 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6575 and then Present (Etype (Orig_Node))
6576 and then Is_Access_Type (Etype (Orig_Node))
6578 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6580 (Nkind (Orig_Node) = N_Function_Call
6581 and then not Is_Access_Constant (Etype (Prefix (N))));
6583 -- A function call is never a variable
6585 elsif Nkind (N) = N_Function_Call then
6588 -- All remaining checks use the original node
6590 elsif Is_Entity_Name (Orig_Node)
6591 and then Present (Entity (Orig_Node))
6594 E : constant Entity_Id := Entity (Orig_Node);
6595 K : constant Entity_Kind := Ekind (E);
6598 return (K = E_Variable
6599 and then Nkind (Parent (E)) /= N_Exception_Handler)
6600 or else (K = E_Component
6601 and then not In_Protected_Function (E))
6602 or else K = E_Out_Parameter
6603 or else K = E_In_Out_Parameter
6604 or else K = E_Generic_In_Out_Parameter
6606 -- Current instance of type:
6608 or else (Is_Type (E) and then In_Open_Scopes (E))
6609 or else (Is_Incomplete_Or_Private_Type (E)
6610 and then In_Open_Scopes (Full_View (E)));
6614 case Nkind (Orig_Node) is
6615 when N_Indexed_Component | N_Slice =>
6616 return Is_Variable_Prefix (Prefix (Orig_Node));
6618 when N_Selected_Component =>
6619 return Is_Variable_Prefix (Prefix (Orig_Node))
6620 and then Is_Variable (Selector_Name (Orig_Node));
6622 -- For an explicit dereference, the type of the prefix cannot
6623 -- be an access to constant or an access to subprogram.
6625 when N_Explicit_Dereference =>
6627 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6629 return Is_Access_Type (Typ)
6630 and then not Is_Access_Constant (Root_Type (Typ))
6631 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6634 -- The type conversion is the case where we do not deal with the
6635 -- context dependent special case of an actual parameter. Thus
6636 -- the type conversion is only considered a variable for the
6637 -- purposes of this routine if the target type is tagged. However,
6638 -- a type conversion is considered to be a variable if it does not
6639 -- come from source (this deals for example with the conversions
6640 -- of expressions to their actual subtypes).
6642 when N_Type_Conversion =>
6643 return Is_Variable (Expression (Orig_Node))
6645 (not Comes_From_Source (Orig_Node)
6647 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6649 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6651 -- GNAT allows an unchecked type conversion as a variable. This
6652 -- only affects the generation of internal expanded code, since
6653 -- calls to instantiations of Unchecked_Conversion are never
6654 -- considered variables (since they are function calls).
6655 -- This is also true for expression actions.
6657 when N_Unchecked_Type_Conversion =>
6658 return Is_Variable (Expression (Orig_Node));
6666 ------------------------
6667 -- Is_Volatile_Object --
6668 ------------------------
6670 function Is_Volatile_Object (N : Node_Id) return Boolean is
6672 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6673 -- Determines if given object has volatile components
6675 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6676 -- If prefix is an implicit dereference, examine designated type
6678 ------------------------
6679 -- Is_Volatile_Prefix --
6680 ------------------------
6682 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6683 Typ : constant Entity_Id := Etype (N);
6686 if Is_Access_Type (Typ) then
6688 Dtyp : constant Entity_Id := Designated_Type (Typ);
6691 return Is_Volatile (Dtyp)
6692 or else Has_Volatile_Components (Dtyp);
6696 return Object_Has_Volatile_Components (N);
6698 end Is_Volatile_Prefix;
6700 ------------------------------------
6701 -- Object_Has_Volatile_Components --
6702 ------------------------------------
6704 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6705 Typ : constant Entity_Id := Etype (N);
6708 if Is_Volatile (Typ)
6709 or else Has_Volatile_Components (Typ)
6713 elsif Is_Entity_Name (N)
6714 and then (Has_Volatile_Components (Entity (N))
6715 or else Is_Volatile (Entity (N)))
6719 elsif Nkind (N) = N_Indexed_Component
6720 or else Nkind (N) = N_Selected_Component
6722 return Is_Volatile_Prefix (Prefix (N));
6727 end Object_Has_Volatile_Components;
6729 -- Start of processing for Is_Volatile_Object
6732 if Is_Volatile (Etype (N))
6733 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6737 elsif Nkind (N) = N_Indexed_Component
6738 or else Nkind (N) = N_Selected_Component
6740 return Is_Volatile_Prefix (Prefix (N));
6745 end Is_Volatile_Object;
6747 -------------------------
6748 -- Kill_Current_Values --
6749 -------------------------
6751 procedure Kill_Current_Values (Ent : Entity_Id) is
6753 if Is_Object (Ent) then
6755 Set_Current_Value (Ent, Empty);
6757 if Ekind (Ent) = E_Variable then
6758 Set_Last_Assignment (Ent, Empty);
6761 if not Can_Never_Be_Null (Ent) then
6762 Set_Is_Known_Non_Null (Ent, False);
6765 Set_Is_Known_Null (Ent, False);
6767 end Kill_Current_Values;
6769 procedure Kill_Current_Values is
6772 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
6773 -- Clear current value for entity E and all entities chained to E
6775 ------------------------------------------
6776 -- Kill_Current_Values_For_Entity_Chain --
6777 ------------------------------------------
6779 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
6783 while Present (Ent) loop
6784 Kill_Current_Values (Ent);
6787 end Kill_Current_Values_For_Entity_Chain;
6789 -- Start of processing for Kill_Current_Values
6792 -- Kill all saved checks, a special case of killing saved values
6796 -- Loop through relevant scopes, which includes the current scope and
6797 -- any parent scopes if the current scope is a block or a package.
6802 -- Clear current values of all entities in current scope
6804 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
6806 -- If scope is a package, also clear current values of all
6807 -- private entities in the scope.
6809 if Ekind (S) = E_Package
6811 Ekind (S) = E_Generic_Package
6813 Is_Concurrent_Type (S)
6815 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
6818 -- If this is a not a subprogram, deal with parents
6820 if not Is_Subprogram (S) then
6822 exit Scope_Loop when S = Standard_Standard;
6826 end loop Scope_Loop;
6827 end Kill_Current_Values;
6829 --------------------------
6830 -- Kill_Size_Check_Code --
6831 --------------------------
6833 procedure Kill_Size_Check_Code (E : Entity_Id) is
6835 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6836 and then Present (Size_Check_Code (E))
6838 Remove (Size_Check_Code (E));
6839 Set_Size_Check_Code (E, Empty);
6841 end Kill_Size_Check_Code;
6843 --------------------------
6844 -- Known_To_Be_Assigned --
6845 --------------------------
6847 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
6848 P : constant Node_Id := Parent (N);
6853 -- Test left side of assignment
6855 when N_Assignment_Statement =>
6856 return N = Name (P);
6858 -- Function call arguments are never lvalues
6860 when N_Function_Call =>
6863 -- Positional parameter for procedure or accept call
6865 when N_Procedure_Call_Statement |
6874 Proc := Get_Subprogram_Entity (P);
6880 -- If we are not a list member, something is strange, so
6881 -- be conservative and return False.
6883 if not Is_List_Member (N) then
6887 -- We are going to find the right formal by stepping forward
6888 -- through the formals, as we step backwards in the actuals.
6890 Form := First_Formal (Proc);
6893 -- If no formal, something is weird, so be conservative
6894 -- and return False.
6905 return Ekind (Form) /= E_In_Parameter;
6908 -- Named parameter for procedure or accept call
6910 when N_Parameter_Association =>
6916 Proc := Get_Subprogram_Entity (Parent (P));
6922 -- Loop through formals to find the one that matches
6924 Form := First_Formal (Proc);
6926 -- If no matching formal, that's peculiar, some kind of
6927 -- previous error, so return False to be conservative.
6933 -- Else test for match
6935 if Chars (Form) = Chars (Selector_Name (P)) then
6936 return Ekind (Form) /= E_In_Parameter;
6943 -- Test for appearing in a conversion that itself appears
6944 -- in an lvalue context, since this should be an lvalue.
6946 when N_Type_Conversion =>
6947 return Known_To_Be_Assigned (P);
6949 -- All other references are definitely not knwon to be modifications
6955 end Known_To_Be_Assigned;
6961 function May_Be_Lvalue (N : Node_Id) return Boolean is
6962 P : constant Node_Id := Parent (N);
6967 -- Test left side of assignment
6969 when N_Assignment_Statement =>
6970 return N = Name (P);
6972 -- Test prefix of component or attribute
6974 when N_Attribute_Reference =>
6975 return N = Prefix (P)
6976 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
6978 when N_Expanded_Name |
6979 N_Explicit_Dereference |
6980 N_Indexed_Component |
6982 N_Selected_Component |
6984 return N = Prefix (P);
6986 -- Function call arguments are never lvalues
6988 when N_Function_Call =>
6991 -- Positional parameter for procedure, entry, or accept call
6993 when N_Procedure_Call_Statement |
6994 N_Entry_Call_Statement |
7003 Proc := Get_Subprogram_Entity (P);
7009 -- If we are not a list member, something is strange, so
7010 -- be conservative and return True.
7012 if not Is_List_Member (N) then
7016 -- We are going to find the right formal by stepping forward
7017 -- through the formals, as we step backwards in the actuals.
7019 Form := First_Formal (Proc);
7022 -- If no formal, something is weird, so be conservative
7034 return Ekind (Form) /= E_In_Parameter;
7037 -- Named parameter for procedure or accept call
7039 when N_Parameter_Association =>
7045 Proc := Get_Subprogram_Entity (Parent (P));
7051 -- Loop through formals to find the one that matches
7053 Form := First_Formal (Proc);
7055 -- If no matching formal, that's peculiar, some kind of
7056 -- previous error, so return True to be conservative.
7062 -- Else test for match
7064 if Chars (Form) = Chars (Selector_Name (P)) then
7065 return Ekind (Form) /= E_In_Parameter;
7072 -- Test for appearing in a conversion that itself appears
7073 -- in an lvalue context, since this should be an lvalue.
7075 when N_Type_Conversion =>
7076 return May_Be_Lvalue (P);
7078 -- Test for appearence in object renaming declaration
7080 when N_Object_Renaming_Declaration =>
7083 -- All other references are definitely not Lvalues
7091 -----------------------
7092 -- Mark_Coextensions --
7093 -----------------------
7095 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7096 Is_Dynamic : Boolean := False;
7098 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7099 -- Recognize an allocator node and label it as a dynamic coextension
7101 --------------------
7102 -- Mark_Allocator --
7103 --------------------
7105 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7107 if Nkind (N) = N_Allocator then
7109 Set_Is_Dynamic_Coextension (N);
7111 Set_Is_Static_Coextension (N);
7118 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7120 -- Start of processing Mark_Coextensions
7123 case Nkind (Context_Nod) is
7124 when N_Assignment_Statement |
7125 N_Simple_Return_Statement =>
7126 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7128 when N_Object_Declaration =>
7129 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7131 -- This routine should not be called for constructs which may not
7132 -- contain coextensions.
7135 raise Program_Error;
7138 Mark_Allocators (Root_Nod);
7139 end Mark_Coextensions;
7141 ----------------------
7142 -- Needs_One_Actual --
7143 ----------------------
7145 function Needs_One_Actual (E : Entity_Id) return Boolean is
7149 if Ada_Version >= Ada_05
7150 and then Present (First_Formal (E))
7152 Formal := Next_Formal (First_Formal (E));
7153 while Present (Formal) loop
7154 if No (Default_Value (Formal)) then
7158 Next_Formal (Formal);
7166 end Needs_One_Actual;
7168 -------------------------
7169 -- New_External_Entity --
7170 -------------------------
7172 function New_External_Entity
7173 (Kind : Entity_Kind;
7174 Scope_Id : Entity_Id;
7175 Sloc_Value : Source_Ptr;
7176 Related_Id : Entity_Id;
7178 Suffix_Index : Nat := 0;
7179 Prefix : Character := ' ') return Entity_Id
7181 N : constant Entity_Id :=
7182 Make_Defining_Identifier (Sloc_Value,
7184 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7187 Set_Ekind (N, Kind);
7188 Set_Is_Internal (N, True);
7189 Append_Entity (N, Scope_Id);
7190 Set_Public_Status (N);
7192 if Kind in Type_Kind then
7193 Init_Size_Align (N);
7197 end New_External_Entity;
7199 -------------------------
7200 -- New_Internal_Entity --
7201 -------------------------
7203 function New_Internal_Entity
7204 (Kind : Entity_Kind;
7205 Scope_Id : Entity_Id;
7206 Sloc_Value : Source_Ptr;
7207 Id_Char : Character) return Entity_Id
7209 N : constant Entity_Id :=
7210 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7213 Set_Ekind (N, Kind);
7214 Set_Is_Internal (N, True);
7215 Append_Entity (N, Scope_Id);
7217 if Kind in Type_Kind then
7218 Init_Size_Align (N);
7222 end New_Internal_Entity;
7228 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7232 -- If we are pointing at a positional parameter, it is a member of
7233 -- a node list (the list of parameters), and the next parameter
7234 -- is the next node on the list, unless we hit a parameter
7235 -- association, in which case we shift to using the chain whose
7236 -- head is the First_Named_Actual in the parent, and then is
7237 -- threaded using the Next_Named_Actual of the Parameter_Association.
7238 -- All this fiddling is because the original node list is in the
7239 -- textual call order, and what we need is the declaration order.
7241 if Is_List_Member (Actual_Id) then
7242 N := Next (Actual_Id);
7244 if Nkind (N) = N_Parameter_Association then
7245 return First_Named_Actual (Parent (Actual_Id));
7251 return Next_Named_Actual (Parent (Actual_Id));
7255 procedure Next_Actual (Actual_Id : in out Node_Id) is
7257 Actual_Id := Next_Actual (Actual_Id);
7260 -----------------------
7261 -- Normalize_Actuals --
7262 -----------------------
7264 -- Chain actuals according to formals of subprogram. If there are no named
7265 -- associations, the chain is simply the list of Parameter Associations,
7266 -- since the order is the same as the declaration order. If there are named
7267 -- associations, then the First_Named_Actual field in the N_Function_Call
7268 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7269 -- node for the parameter that comes first in declaration order. The
7270 -- remaining named parameters are then chained in declaration order using
7271 -- Next_Named_Actual.
7273 -- This routine also verifies that the number of actuals is compatible with
7274 -- the number and default values of formals, but performs no type checking
7275 -- (type checking is done by the caller).
7277 -- If the matching succeeds, Success is set to True and the caller proceeds
7278 -- with type-checking. If the match is unsuccessful, then Success is set to
7279 -- False, and the caller attempts a different interpretation, if there is
7282 -- If the flag Report is on, the call is not overloaded, and a failure to
7283 -- match can be reported here, rather than in the caller.
7285 procedure Normalize_Actuals
7289 Success : out Boolean)
7291 Actuals : constant List_Id := Parameter_Associations (N);
7292 Actual : Node_Id := Empty;
7294 Last : Node_Id := Empty;
7295 First_Named : Node_Id := Empty;
7298 Formals_To_Match : Integer := 0;
7299 Actuals_To_Match : Integer := 0;
7301 procedure Chain (A : Node_Id);
7302 -- Add named actual at the proper place in the list, using the
7303 -- Next_Named_Actual link.
7305 function Reporting return Boolean;
7306 -- Determines if an error is to be reported. To report an error, we
7307 -- need Report to be True, and also we do not report errors caused
7308 -- by calls to init procs that occur within other init procs. Such
7309 -- errors must always be cascaded errors, since if all the types are
7310 -- declared correctly, the compiler will certainly build decent calls!
7316 procedure Chain (A : Node_Id) is
7320 -- Call node points to first actual in list
7322 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7325 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7329 Set_Next_Named_Actual (Last, Empty);
7336 function Reporting return Boolean is
7341 elsif not Within_Init_Proc then
7344 elsif Is_Init_Proc (Entity (Name (N))) then
7352 -- Start of processing for Normalize_Actuals
7355 if Is_Access_Type (S) then
7357 -- The name in the call is a function call that returns an access
7358 -- to subprogram. The designated type has the list of formals.
7360 Formal := First_Formal (Designated_Type (S));
7362 Formal := First_Formal (S);
7365 while Present (Formal) loop
7366 Formals_To_Match := Formals_To_Match + 1;
7367 Next_Formal (Formal);
7370 -- Find if there is a named association, and verify that no positional
7371 -- associations appear after named ones.
7373 if Present (Actuals) then
7374 Actual := First (Actuals);
7377 while Present (Actual)
7378 and then Nkind (Actual) /= N_Parameter_Association
7380 Actuals_To_Match := Actuals_To_Match + 1;
7384 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7386 -- Most common case: positional notation, no defaults
7391 elsif Actuals_To_Match > Formals_To_Match then
7393 -- Too many actuals: will not work
7396 if Is_Entity_Name (Name (N)) then
7397 Error_Msg_N ("too many arguments in call to&", Name (N));
7399 Error_Msg_N ("too many arguments in call", N);
7407 First_Named := Actual;
7409 while Present (Actual) loop
7410 if Nkind (Actual) /= N_Parameter_Association then
7412 ("positional parameters not allowed after named ones", Actual);
7417 Actuals_To_Match := Actuals_To_Match + 1;
7423 if Present (Actuals) then
7424 Actual := First (Actuals);
7427 Formal := First_Formal (S);
7428 while Present (Formal) loop
7430 -- Match the formals in order. If the corresponding actual
7431 -- is positional, nothing to do. Else scan the list of named
7432 -- actuals to find the one with the right name.
7435 and then Nkind (Actual) /= N_Parameter_Association
7438 Actuals_To_Match := Actuals_To_Match - 1;
7439 Formals_To_Match := Formals_To_Match - 1;
7442 -- For named parameters, search the list of actuals to find
7443 -- one that matches the next formal name.
7445 Actual := First_Named;
7447 while Present (Actual) loop
7448 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7451 Actuals_To_Match := Actuals_To_Match - 1;
7452 Formals_To_Match := Formals_To_Match - 1;
7460 if Ekind (Formal) /= E_In_Parameter
7461 or else No (Default_Value (Formal))
7464 if (Comes_From_Source (S)
7465 or else Sloc (S) = Standard_Location)
7466 and then Is_Overloadable (S)
7470 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7472 (Nkind (Parent (N)) = N_Function_Call
7474 Nkind (Parent (N)) = N_Parameter_Association))
7475 and then Ekind (S) /= E_Function
7477 Set_Etype (N, Etype (S));
7479 Error_Msg_Name_1 := Chars (S);
7480 Error_Msg_Sloc := Sloc (S);
7482 ("missing argument for parameter & " &
7483 "in call to % declared #", N, Formal);
7486 elsif Is_Overloadable (S) then
7487 Error_Msg_Name_1 := Chars (S);
7489 -- Point to type derivation that generated the
7492 Error_Msg_Sloc := Sloc (Parent (S));
7495 ("missing argument for parameter & " &
7496 "in call to % (inherited) #", N, Formal);
7500 ("missing argument for parameter &", N, Formal);
7508 Formals_To_Match := Formals_To_Match - 1;
7513 Next_Formal (Formal);
7516 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7523 -- Find some superfluous named actual that did not get
7524 -- attached to the list of associations.
7526 Actual := First (Actuals);
7527 while Present (Actual) loop
7528 if Nkind (Actual) = N_Parameter_Association
7529 and then Actual /= Last
7530 and then No (Next_Named_Actual (Actual))
7532 Error_Msg_N ("unmatched actual & in call",
7533 Selector_Name (Actual));
7544 end Normalize_Actuals;
7546 --------------------------------
7547 -- Note_Possible_Modification --
7548 --------------------------------
7550 procedure Note_Possible_Modification (N : Node_Id) is
7551 Modification_Comes_From_Source : constant Boolean :=
7552 Comes_From_Source (Parent (N));
7558 -- Loop to find referenced entity, if there is one
7565 if Is_Entity_Name (Exp) then
7566 Ent := Entity (Exp);
7568 -- If the entity is missing, it is an undeclared identifier,
7569 -- and there is nothing to annotate.
7575 elsif Nkind (Exp) = N_Explicit_Dereference then
7577 P : constant Node_Id := Prefix (Exp);
7580 if Nkind (P) = N_Selected_Component
7582 Entry_Formal (Entity (Selector_Name (P))))
7584 -- Case of a reference to an entry formal
7586 Ent := Entry_Formal (Entity (Selector_Name (P)));
7588 elsif Nkind (P) = N_Identifier
7589 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7590 and then Present (Expression (Parent (Entity (P))))
7591 and then Nkind (Expression (Parent (Entity (P))))
7594 -- Case of a reference to a value on which
7595 -- side effects have been removed.
7597 Exp := Prefix (Expression (Parent (Entity (P))));
7606 elsif Nkind (Exp) = N_Type_Conversion
7607 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7609 Exp := Expression (Exp);
7612 elsif Nkind (Exp) = N_Slice
7613 or else Nkind (Exp) = N_Indexed_Component
7614 or else Nkind (Exp) = N_Selected_Component
7616 Exp := Prefix (Exp);
7623 -- Now look for entity being referenced
7625 if Present (Ent) then
7626 if Is_Object (Ent) then
7627 if Comes_From_Source (Exp)
7628 or else Modification_Comes_From_Source
7630 Set_Never_Set_In_Source (Ent, False);
7633 Set_Is_True_Constant (Ent, False);
7634 Set_Current_Value (Ent, Empty);
7635 Set_Is_Known_Null (Ent, False);
7637 if not Can_Never_Be_Null (Ent) then
7638 Set_Is_Known_Non_Null (Ent, False);
7641 -- Follow renaming chain
7643 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7644 and then Present (Renamed_Object (Ent))
7646 Exp := Renamed_Object (Ent);
7650 -- Generate a reference only if the assignment comes from
7651 -- source. This excludes, for example, calls to a dispatching
7652 -- assignment operation when the left-hand side is tagged.
7654 if Modification_Comes_From_Source then
7655 Generate_Reference (Ent, Exp, 'm');
7658 Check_Nested_Access (Ent);
7665 end Note_Possible_Modification;
7667 -------------------------
7668 -- Object_Access_Level --
7669 -------------------------
7671 function Object_Access_Level (Obj : Node_Id) return Uint is
7674 -- Returns the static accessibility level of the view denoted
7675 -- by Obj. Note that the value returned is the result of a
7676 -- call to Scope_Depth. Only scope depths associated with
7677 -- dynamic scopes can actually be returned. Since only
7678 -- relative levels matter for accessibility checking, the fact
7679 -- that the distance between successive levels of accessibility
7680 -- is not always one is immaterial (invariant: if level(E2) is
7681 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7683 function Reference_To (Obj : Node_Id) return Node_Id;
7684 -- An explicit dereference is created when removing side-effects
7685 -- from expressions for constraint checking purposes. In this case
7686 -- a local access type is created for it. The correct access level
7687 -- is that of the original source node. We detect this case by
7688 -- noting that the prefix of the dereference is created by an object
7689 -- declaration whose initial expression is a reference.
7695 function Reference_To (Obj : Node_Id) return Node_Id is
7696 Pref : constant Node_Id := Prefix (Obj);
7698 if Is_Entity_Name (Pref)
7699 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7700 and then Present (Expression (Parent (Entity (Pref))))
7701 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7703 return (Prefix (Expression (Parent (Entity (Pref)))));
7709 -- Start of processing for Object_Access_Level
7712 if Is_Entity_Name (Obj) then
7715 -- If E is a type then it denotes a current instance.
7716 -- For this case we add one to the normal accessibility
7717 -- level of the type to ensure that current instances
7718 -- are treated as always being deeper than than the level
7719 -- of any visible named access type (see 3.10.2(21)).
7722 return Type_Access_Level (E) + 1;
7724 elsif Present (Renamed_Object (E)) then
7725 return Object_Access_Level (Renamed_Object (E));
7727 -- Similarly, if E is a component of the current instance of a
7728 -- protected type, any instance of it is assumed to be at a deeper
7729 -- level than the type. For a protected object (whose type is an
7730 -- anonymous protected type) its components are at the same level
7731 -- as the type itself.
7733 elsif not Is_Overloadable (E)
7734 and then Ekind (Scope (E)) = E_Protected_Type
7735 and then Comes_From_Source (Scope (E))
7737 return Type_Access_Level (Scope (E)) + 1;
7740 return Scope_Depth (Enclosing_Dynamic_Scope (E));
7743 elsif Nkind (Obj) = N_Selected_Component then
7744 if Is_Access_Type (Etype (Prefix (Obj))) then
7745 return Type_Access_Level (Etype (Prefix (Obj)));
7747 return Object_Access_Level (Prefix (Obj));
7750 elsif Nkind (Obj) = N_Indexed_Component then
7751 if Is_Access_Type (Etype (Prefix (Obj))) then
7752 return Type_Access_Level (Etype (Prefix (Obj)));
7754 return Object_Access_Level (Prefix (Obj));
7757 elsif Nkind (Obj) = N_Explicit_Dereference then
7759 -- If the prefix is a selected access discriminant then
7760 -- we make a recursive call on the prefix, which will
7761 -- in turn check the level of the prefix object of
7762 -- the selected discriminant.
7764 if Nkind (Prefix (Obj)) = N_Selected_Component
7765 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
7767 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
7769 return Object_Access_Level (Prefix (Obj));
7771 elsif not (Comes_From_Source (Obj)) then
7773 Ref : constant Node_Id := Reference_To (Obj);
7775 if Present (Ref) then
7776 return Object_Access_Level (Ref);
7778 return Type_Access_Level (Etype (Prefix (Obj)));
7783 return Type_Access_Level (Etype (Prefix (Obj)));
7786 elsif Nkind (Obj) = N_Type_Conversion
7787 or else Nkind (Obj) = N_Unchecked_Type_Conversion
7789 return Object_Access_Level (Expression (Obj));
7791 -- Function results are objects, so we get either the access level
7792 -- of the function or, in the case of an indirect call, the level of
7793 -- of the access-to-subprogram type.
7795 elsif Nkind (Obj) = N_Function_Call then
7796 if Is_Entity_Name (Name (Obj)) then
7797 return Subprogram_Access_Level (Entity (Name (Obj)));
7799 return Type_Access_Level (Etype (Prefix (Name (Obj))));
7802 -- For convenience we handle qualified expressions, even though
7803 -- they aren't technically object names.
7805 elsif Nkind (Obj) = N_Qualified_Expression then
7806 return Object_Access_Level (Expression (Obj));
7808 -- Otherwise return the scope level of Standard.
7809 -- (If there are cases that fall through
7810 -- to this point they will be treated as
7811 -- having global accessibility for now. ???)
7814 return Scope_Depth (Standard_Standard);
7816 end Object_Access_Level;
7818 -----------------------
7819 -- Private_Component --
7820 -----------------------
7822 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
7823 Ancestor : constant Entity_Id := Base_Type (Type_Id);
7825 function Trace_Components
7827 Check : Boolean) return Entity_Id;
7828 -- Recursive function that does the work, and checks against circular
7829 -- definition for each subcomponent type.
7831 ----------------------
7832 -- Trace_Components --
7833 ----------------------
7835 function Trace_Components
7837 Check : Boolean) return Entity_Id
7839 Btype : constant Entity_Id := Base_Type (T);
7840 Component : Entity_Id;
7842 Candidate : Entity_Id := Empty;
7845 if Check and then Btype = Ancestor then
7846 Error_Msg_N ("circular type definition", Type_Id);
7850 if Is_Private_Type (Btype)
7851 and then not Is_Generic_Type (Btype)
7853 if Present (Full_View (Btype))
7854 and then Is_Record_Type (Full_View (Btype))
7855 and then not Is_Frozen (Btype)
7857 -- To indicate that the ancestor depends on a private type,
7858 -- the current Btype is sufficient. However, to check for
7859 -- circular definition we must recurse on the full view.
7861 Candidate := Trace_Components (Full_View (Btype), True);
7863 if Candidate = Any_Type then
7873 elsif Is_Array_Type (Btype) then
7874 return Trace_Components (Component_Type (Btype), True);
7876 elsif Is_Record_Type (Btype) then
7877 Component := First_Entity (Btype);
7878 while Present (Component) loop
7880 -- Skip anonymous types generated by constrained components
7882 if not Is_Type (Component) then
7883 P := Trace_Components (Etype (Component), True);
7886 if P = Any_Type then
7894 Next_Entity (Component);
7902 end Trace_Components;
7904 -- Start of processing for Private_Component
7907 return Trace_Components (Type_Id, False);
7908 end Private_Component;
7910 -----------------------
7911 -- Process_End_Label --
7912 -----------------------
7914 procedure Process_End_Label
7922 Label_Ref : Boolean;
7923 -- Set True if reference to end label itself is required
7926 -- Gets set to the operator symbol or identifier that references
7927 -- the entity Ent. For the child unit case, this is the identifier
7928 -- from the designator. For other cases, this is simply Endl.
7930 procedure Generate_Parent_Ref (N : Node_Id);
7931 -- N is an identifier node that appears as a parent unit reference
7932 -- in the case where Ent is a child unit. This procedure generates
7933 -- an appropriate cross-reference entry.
7935 -------------------------
7936 -- Generate_Parent_Ref --
7937 -------------------------
7939 procedure Generate_Parent_Ref (N : Node_Id) is
7940 Parent_Ent : Entity_Id;
7943 -- Search up scope stack. The reason we do this is that normal
7944 -- visibility analysis would not work for two reasons. First in
7945 -- some subunit cases, the entry for the parent unit may not be
7946 -- visible, and in any case there can be a local entity that
7947 -- hides the scope entity.
7949 Parent_Ent := Current_Scope;
7950 while Present (Parent_Ent) loop
7951 if Chars (Parent_Ent) = Chars (N) then
7953 -- Generate the reference. We do NOT consider this as a
7954 -- reference for unreferenced symbol purposes, but we do
7955 -- force a cross-reference even if the end line does not
7956 -- come from source (the caller already generated the
7957 -- appropriate Typ for this situation).
7960 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
7961 Style.Check_Identifier (N, Parent_Ent);
7965 Parent_Ent := Scope (Parent_Ent);
7968 -- Fall through means entity was not found -- that's odd, but
7969 -- the appropriate thing is simply to ignore and not generate
7970 -- any cross-reference for this entry.
7973 end Generate_Parent_Ref;
7975 -- Start of processing for Process_End_Label
7978 -- If no node, ignore. This happens in some error situations,
7979 -- and also for some internally generated structures where no
7980 -- end label references are required in any case.
7986 -- Nothing to do if no End_Label, happens for internally generated
7987 -- constructs where we don't want an end label reference anyway.
7988 -- Also nothing to do if Endl is a string literal, which means
7989 -- there was some prior error (bad operator symbol)
7991 Endl := End_Label (N);
7993 if No (Endl) or else Nkind (Endl) = N_String_Literal then
7997 -- Reference node is not in extended main source unit
7999 if not In_Extended_Main_Source_Unit (N) then
8001 -- Generally we do not collect references except for the
8002 -- extended main source unit. The one exception is the 'e'
8003 -- entry for a package spec, where it is useful for a client
8004 -- to have the ending information to define scopes.
8012 -- For this case, we can ignore any parent references,
8013 -- but we need the package name itself for the 'e' entry.
8015 if Nkind (Endl) = N_Designator then
8016 Endl := Identifier (Endl);
8020 -- Reference is in extended main source unit
8025 -- For designator, generate references for the parent entries
8027 if Nkind (Endl) = N_Designator then
8029 -- Generate references for the prefix if the END line comes
8030 -- from source (otherwise we do not need these references)
8032 if Comes_From_Source (Endl) then
8034 while Nkind (Nam) = N_Selected_Component loop
8035 Generate_Parent_Ref (Selector_Name (Nam));
8036 Nam := Prefix (Nam);
8039 Generate_Parent_Ref (Nam);
8042 Endl := Identifier (Endl);
8046 -- If the end label is not for the given entity, then either we have
8047 -- some previous error, or this is a generic instantiation for which
8048 -- we do not need to make a cross-reference in this case anyway. In
8049 -- either case we simply ignore the call.
8051 if Chars (Ent) /= Chars (Endl) then
8055 -- If label was really there, then generate a normal reference
8056 -- and then adjust the location in the end label to point past
8057 -- the name (which should almost always be the semicolon).
8061 if Comes_From_Source (Endl) then
8063 -- If a label reference is required, then do the style check
8064 -- and generate an l-type cross-reference entry for the label
8068 Style.Check_Identifier (Endl, Ent);
8070 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8073 -- Set the location to point past the label (normally this will
8074 -- mean the semicolon immediately following the label). This is
8075 -- done for the sake of the 'e' or 't' entry generated below.
8077 Get_Decoded_Name_String (Chars (Endl));
8078 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8081 -- Now generate the e/t reference
8083 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8085 -- Restore Sloc, in case modified above, since we have an identifier
8086 -- and the normal Sloc should be left set in the tree.
8088 Set_Sloc (Endl, Loc);
8089 end Process_End_Label;
8095 -- We do the conversion to get the value of the real string by using
8096 -- the scanner, see Sinput for details on use of the internal source
8097 -- buffer for scanning internal strings.
8099 function Real_Convert (S : String) return Node_Id is
8100 Save_Src : constant Source_Buffer_Ptr := Source;
8104 Source := Internal_Source_Ptr;
8107 for J in S'Range loop
8108 Source (Source_Ptr (J)) := S (J);
8111 Source (S'Length + 1) := EOF;
8113 if Source (Scan_Ptr) = '-' then
8115 Scan_Ptr := Scan_Ptr + 1;
8123 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8130 ---------------------
8131 -- Rep_To_Pos_Flag --
8132 ---------------------
8134 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8136 return New_Occurrence_Of
8137 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8138 end Rep_To_Pos_Flag;
8140 --------------------
8141 -- Require_Entity --
8142 --------------------
8144 procedure Require_Entity (N : Node_Id) is
8146 if Is_Entity_Name (N) and then No (Entity (N)) then
8147 if Total_Errors_Detected /= 0 then
8148 Set_Entity (N, Any_Id);
8150 raise Program_Error;
8155 ------------------------------
8156 -- Requires_Transient_Scope --
8157 ------------------------------
8159 -- A transient scope is required when variable-sized temporaries are
8160 -- allocated in the primary or secondary stack, or when finalization
8161 -- actions must be generated before the next instruction.
8163 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8164 Typ : constant Entity_Id := Underlying_Type (Id);
8166 -- Start of processing for Requires_Transient_Scope
8169 -- This is a private type which is not completed yet. This can only
8170 -- happen in a default expression (of a formal parameter or of a
8171 -- record component). Do not expand transient scope in this case
8176 -- Do not expand transient scope for non-existent procedure return
8178 elsif Typ = Standard_Void_Type then
8181 -- Elementary types do not require a transient scope
8183 elsif Is_Elementary_Type (Typ) then
8186 -- Generally, indefinite subtypes require a transient scope, since the
8187 -- back end cannot generate temporaries, since this is not a valid type
8188 -- for declaring an object. It might be possible to relax this in the
8189 -- future, e.g. by declaring the maximum possible space for the type.
8191 elsif Is_Indefinite_Subtype (Typ) then
8194 -- Functions returning tagged types may dispatch on result so their
8195 -- returned value is allocated on the secondary stack. Controlled
8196 -- type temporaries need finalization.
8198 elsif Is_Tagged_Type (Typ)
8199 or else Has_Controlled_Component (Typ)
8201 return not Is_Value_Type (Typ);
8205 elsif Is_Record_Type (Typ) then
8209 Comp := First_Entity (Typ);
8210 while Present (Comp) loop
8211 if Ekind (Comp) = E_Component
8212 and then Requires_Transient_Scope (Etype (Comp))
8223 -- String literal types never require transient scope
8225 elsif Ekind (Typ) = E_String_Literal_Subtype then
8228 -- Array type. Note that we already know that this is a constrained
8229 -- array, since unconstrained arrays will fail the indefinite test.
8231 elsif Is_Array_Type (Typ) then
8233 -- If component type requires a transient scope, the array does too
8235 if Requires_Transient_Scope (Component_Type (Typ)) then
8238 -- Otherwise, we only need a transient scope if the size is not
8239 -- known at compile time.
8242 return not Size_Known_At_Compile_Time (Typ);
8245 -- All other cases do not require a transient scope
8250 end Requires_Transient_Scope;
8252 --------------------------
8253 -- Reset_Analyzed_Flags --
8254 --------------------------
8256 procedure Reset_Analyzed_Flags (N : Node_Id) is
8258 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8259 -- Function used to reset Analyzed flags in tree. Note that we do
8260 -- not reset Analyzed flags in entities, since there is no need to
8261 -- renalalyze entities, and indeed, it is wrong to do so, since it
8262 -- can result in generating auxiliary stuff more than once.
8264 --------------------
8265 -- Clear_Analyzed --
8266 --------------------
8268 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8270 if not Has_Extension (N) then
8271 Set_Analyzed (N, False);
8277 function Reset_Analyzed is
8278 new Traverse_Func (Clear_Analyzed);
8280 Discard : Traverse_Result;
8281 pragma Warnings (Off, Discard);
8283 -- Start of processing for Reset_Analyzed_Flags
8286 Discard := Reset_Analyzed (N);
8287 end Reset_Analyzed_Flags;
8289 ---------------------------
8290 -- Safe_To_Capture_Value --
8291 ---------------------------
8293 function Safe_To_Capture_Value
8296 Cond : Boolean := False) return Boolean
8299 -- The only entities for which we track constant values are variables
8300 -- which are not renamings, constants, out parameters, and in out
8301 -- parameters, so check if we have this case.
8303 -- Note: it may seem odd to track constant values for constants, but in
8304 -- fact this routine is used for other purposes than simply capturing
8305 -- the value. In particular, the setting of Known[_Non]_Null.
8307 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8309 Ekind (Ent) = E_Constant
8311 Ekind (Ent) = E_Out_Parameter
8313 Ekind (Ent) = E_In_Out_Parameter
8317 -- For conditionals, we also allow loop parameters and all formals,
8318 -- including in parameters.
8322 (Ekind (Ent) = E_Loop_Parameter
8324 Ekind (Ent) = E_In_Parameter)
8328 -- For all other cases, not just unsafe, but impossible to capture
8329 -- Current_Value, since the above are the only entities which have
8330 -- Current_Value fields.
8336 -- Skip if volatile or aliased, since funny things might be going on in
8337 -- these cases which we cannot necessarily track. Also skip any variable
8338 -- for which an address clause is given, or whose address is taken.
8340 if Treat_As_Volatile (Ent)
8341 or else Is_Aliased (Ent)
8342 or else Present (Address_Clause (Ent))
8343 or else Address_Taken (Ent)
8348 -- OK, all above conditions are met. We also require that the scope of
8349 -- the reference be the same as the scope of the entity, not counting
8350 -- packages and blocks and loops.
8353 E_Scope : constant Entity_Id := Scope (Ent);
8354 R_Scope : Entity_Id;
8357 R_Scope := Current_Scope;
8358 while R_Scope /= Standard_Standard loop
8359 exit when R_Scope = E_Scope;
8361 if Ekind (R_Scope) /= E_Package
8363 Ekind (R_Scope) /= E_Block
8365 Ekind (R_Scope) /= E_Loop
8369 R_Scope := Scope (R_Scope);
8374 -- We also require that the reference does not appear in a context
8375 -- where it is not sure to be executed (i.e. a conditional context
8376 -- or an exception handler). We skip this if Cond is True, since the
8377 -- capturing of values from conditional tests handles this ok.
8391 while Present (P) loop
8392 if Nkind (P) = N_If_Statement
8393 or else Nkind (P) = N_Case_Statement
8394 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8395 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8396 or else Nkind (P) = N_Exception_Handler
8397 or else Nkind (P) = N_Selective_Accept
8398 or else Nkind (P) = N_Conditional_Entry_Call
8399 or else Nkind (P) = N_Timed_Entry_Call
8400 or else Nkind (P) = N_Asynchronous_Select
8410 -- OK, looks safe to set value
8413 end Safe_To_Capture_Value;
8419 function Same_Name (N1, N2 : Node_Id) return Boolean is
8420 K1 : constant Node_Kind := Nkind (N1);
8421 K2 : constant Node_Kind := Nkind (N2);
8424 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8425 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8427 return Chars (N1) = Chars (N2);
8429 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8430 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8432 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8433 and then Same_Name (Prefix (N1), Prefix (N2));
8444 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8445 N1 : constant Node_Id := Original_Node (Node1);
8446 N2 : constant Node_Id := Original_Node (Node2);
8447 -- We do the tests on original nodes, since we are most interested
8448 -- in the original source, not any expansion that got in the way.
8450 K1 : constant Node_Kind := Nkind (N1);
8451 K2 : constant Node_Kind := Nkind (N2);
8454 -- First case, both are entities with same entity
8456 if K1 in N_Has_Entity
8457 and then K2 in N_Has_Entity
8458 and then Present (Entity (N1))
8459 and then Present (Entity (N2))
8460 and then (Ekind (Entity (N1)) = E_Variable
8462 Ekind (Entity (N1)) = E_Constant)
8463 and then Entity (N1) = Entity (N2)
8467 -- Second case, selected component with same selector, same record
8469 elsif K1 = N_Selected_Component
8470 and then K2 = N_Selected_Component
8471 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8473 return Same_Object (Prefix (N1), Prefix (N2));
8475 -- Third case, indexed component with same subscripts, same array
8477 elsif K1 = N_Indexed_Component
8478 and then K2 = N_Indexed_Component
8479 and then Same_Object (Prefix (N1), Prefix (N2))
8484 E1 := First (Expressions (N1));
8485 E2 := First (Expressions (N2));
8486 while Present (E1) loop
8487 if not Same_Value (E1, E2) then
8498 -- Fourth case, slice of same array with same bounds
8501 and then K2 = N_Slice
8502 and then Nkind (Discrete_Range (N1)) = N_Range
8503 and then Nkind (Discrete_Range (N2)) = N_Range
8504 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8505 Low_Bound (Discrete_Range (N2)))
8506 and then Same_Value (High_Bound (Discrete_Range (N1)),
8507 High_Bound (Discrete_Range (N2)))
8509 return Same_Name (Prefix (N1), Prefix (N2));
8511 -- All other cases, not clearly the same object
8522 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8527 elsif not Is_Constrained (T1)
8528 and then not Is_Constrained (T2)
8529 and then Base_Type (T1) = Base_Type (T2)
8533 -- For now don't bother with case of identical constraints, to be
8534 -- fiddled with later on perhaps (this is only used for optimization
8535 -- purposes, so it is not critical to do a best possible job)
8546 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8548 if Compile_Time_Known_Value (Node1)
8549 and then Compile_Time_Known_Value (Node2)
8550 and then Expr_Value (Node1) = Expr_Value (Node2)
8553 elsif Same_Object (Node1, Node2) then
8560 ------------------------
8561 -- Scope_Is_Transient --
8562 ------------------------
8564 function Scope_Is_Transient return Boolean is
8566 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8567 end Scope_Is_Transient;
8573 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8578 while Scop /= Standard_Standard loop
8579 Scop := Scope (Scop);
8581 if Scop = Scope2 then
8589 --------------------------
8590 -- Scope_Within_Or_Same --
8591 --------------------------
8593 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8598 while Scop /= Standard_Standard loop
8599 if Scop = Scope2 then
8602 Scop := Scope (Scop);
8607 end Scope_Within_Or_Same;
8609 ------------------------
8610 -- Set_Current_Entity --
8611 ------------------------
8613 -- The given entity is to be set as the currently visible definition
8614 -- of its associated name (i.e. the Node_Id associated with its name).
8615 -- All we have to do is to get the name from the identifier, and
8616 -- then set the associated Node_Id to point to the given entity.
8618 procedure Set_Current_Entity (E : Entity_Id) is
8620 Set_Name_Entity_Id (Chars (E), E);
8621 end Set_Current_Entity;
8623 ---------------------------------
8624 -- Set_Entity_With_Style_Check --
8625 ---------------------------------
8627 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
8628 Val_Actual : Entity_Id;
8632 Set_Entity (N, Val);
8635 and then not Suppress_Style_Checks (Val)
8636 and then not In_Instance
8638 if Nkind (N) = N_Identifier then
8640 elsif Nkind (N) = N_Expanded_Name then
8641 Nod := Selector_Name (N);
8646 -- A special situation arises for derived operations, where we want
8647 -- to do the check against the parent (since the Sloc of the derived
8648 -- operation points to the derived type declaration itself).
8651 while not Comes_From_Source (Val_Actual)
8652 and then Nkind (Val_Actual) in N_Entity
8653 and then (Ekind (Val_Actual) = E_Enumeration_Literal
8654 or else Is_Subprogram (Val_Actual)
8655 or else Is_Generic_Subprogram (Val_Actual))
8656 and then Present (Alias (Val_Actual))
8658 Val_Actual := Alias (Val_Actual);
8661 -- Renaming declarations for generic actuals do not come from source,
8662 -- and have a different name from that of the entity they rename, so
8663 -- there is no style check to perform here.
8665 if Chars (Nod) = Chars (Val_Actual) then
8666 Style.Check_Identifier (Nod, Val_Actual);
8670 Set_Entity (N, Val);
8671 end Set_Entity_With_Style_Check;
8673 ------------------------
8674 -- Set_Name_Entity_Id --
8675 ------------------------
8677 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
8679 Set_Name_Table_Info (Id, Int (Val));
8680 end Set_Name_Entity_Id;
8682 ---------------------
8683 -- Set_Next_Actual --
8684 ---------------------
8686 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
8688 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
8689 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
8691 end Set_Next_Actual;
8693 -----------------------
8694 -- Set_Public_Status --
8695 -----------------------
8697 procedure Set_Public_Status (Id : Entity_Id) is
8698 S : constant Entity_Id := Current_Scope;
8701 -- Everything in the scope of Standard is public
8703 if S = Standard_Standard then
8706 -- Entity is definitely not public if enclosing scope is not public
8708 elsif not Is_Public (S) then
8711 -- An object declaration that occurs in a handled sequence of statements
8712 -- is the declaration for a temporary object generated by the expander.
8713 -- It never needs to be made public and furthermore, making it public
8714 -- can cause back end problems if it is of variable size.
8716 elsif Nkind (Parent (Id)) = N_Object_Declaration
8718 Nkind (Parent (Parent (Id))) = N_Handled_Sequence_Of_Statements
8722 -- Entities in public packages or records are public
8724 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
8727 -- The bounds of an entry family declaration can generate object
8728 -- declarations that are visible to the back-end, e.g. in the
8729 -- the declaration of a composite type that contains tasks.
8731 elsif Is_Concurrent_Type (S)
8732 and then not Has_Completion (S)
8733 and then Nkind (Parent (Id)) = N_Object_Declaration
8737 end Set_Public_Status;
8739 ----------------------------
8740 -- Set_Scope_Is_Transient --
8741 ----------------------------
8743 procedure Set_Scope_Is_Transient (V : Boolean := True) is
8745 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
8746 end Set_Scope_Is_Transient;
8752 procedure Set_Size_Info (T1, T2 : Entity_Id) is
8754 -- We copy Esize, but not RM_Size, since in general RM_Size is
8755 -- subtype specific and does not get inherited by all subtypes.
8757 Set_Esize (T1, Esize (T2));
8758 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
8760 if Is_Discrete_Or_Fixed_Point_Type (T1)
8762 Is_Discrete_Or_Fixed_Point_Type (T2)
8764 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
8767 Set_Alignment (T1, Alignment (T2));
8770 --------------------
8771 -- Static_Integer --
8772 --------------------
8774 function Static_Integer (N : Node_Id) return Uint is
8776 Analyze_And_Resolve (N, Any_Integer);
8779 or else Error_Posted (N)
8780 or else Etype (N) = Any_Type
8785 if Is_Static_Expression (N) then
8786 if not Raises_Constraint_Error (N) then
8787 return Expr_Value (N);
8792 elsif Etype (N) = Any_Type then
8796 Flag_Non_Static_Expr
8797 ("static integer expression required here", N);
8802 --------------------------
8803 -- Statically_Different --
8804 --------------------------
8806 function Statically_Different (E1, E2 : Node_Id) return Boolean is
8807 R1 : constant Node_Id := Get_Referenced_Object (E1);
8808 R2 : constant Node_Id := Get_Referenced_Object (E2);
8810 return Is_Entity_Name (R1)
8811 and then Is_Entity_Name (R2)
8812 and then Entity (R1) /= Entity (R2)
8813 and then not Is_Formal (Entity (R1))
8814 and then not Is_Formal (Entity (R2));
8815 end Statically_Different;
8817 -----------------------------
8818 -- Subprogram_Access_Level --
8819 -----------------------------
8821 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
8823 if Present (Alias (Subp)) then
8824 return Subprogram_Access_Level (Alias (Subp));
8826 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
8828 end Subprogram_Access_Level;
8834 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
8836 if Debug_Flag_W then
8837 for J in 0 .. Scope_Stack.Last loop
8842 Write_Name (Chars (E));
8843 Write_Str (" line ");
8844 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
8849 -----------------------
8850 -- Transfer_Entities --
8851 -----------------------
8853 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
8854 Ent : Entity_Id := First_Entity (From);
8861 if (Last_Entity (To)) = Empty then
8862 Set_First_Entity (To, Ent);
8864 Set_Next_Entity (Last_Entity (To), Ent);
8867 Set_Last_Entity (To, Last_Entity (From));
8869 while Present (Ent) loop
8870 Set_Scope (Ent, To);
8872 if not Is_Public (Ent) then
8873 Set_Public_Status (Ent);
8876 and then Ekind (Ent) = E_Record_Subtype
8879 -- The components of the propagated Itype must be public
8885 Comp := First_Entity (Ent);
8886 while Present (Comp) loop
8887 Set_Is_Public (Comp);
8897 Set_First_Entity (From, Empty);
8898 Set_Last_Entity (From, Empty);
8899 end Transfer_Entities;
8901 -----------------------
8902 -- Type_Access_Level --
8903 -----------------------
8905 function Type_Access_Level (Typ : Entity_Id) return Uint is
8909 Btyp := Base_Type (Typ);
8911 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
8912 -- simply use the level where the type is declared. This is true for
8913 -- stand-alone object declarations, and for anonymous access types
8914 -- associated with components the level is the same as that of the
8915 -- enclosing composite type. However, special treatment is needed for
8916 -- the cases of access parameters, return objects of an anonymous access
8917 -- type, and, in Ada 95, access discriminants of limited types.
8919 if Ekind (Btyp) in Access_Kind then
8920 if Ekind (Btyp) = E_Anonymous_Access_Type then
8922 -- If the type is a nonlocal anonymous access type (such as for
8923 -- an access parameter) we treat it as being declared at the
8924 -- library level to ensure that names such as X.all'access don't
8925 -- fail static accessibility checks.
8927 if not Is_Local_Anonymous_Access (Typ) then
8928 return Scope_Depth (Standard_Standard);
8930 -- If this is a return object, the accessibility level is that of
8931 -- the result subtype of the enclosing function. The test here is
8932 -- little complicated, because we have to account for extended
8933 -- return statements that have been rewritten as blocks, in which
8934 -- case we have to find and the Is_Return_Object attribute of the
8935 -- itype's associated object. It would be nice to find a way to
8936 -- simplify this test, but it doesn't seem worthwhile to add a new
8937 -- flag just for purposes of this test. ???
8939 elsif Ekind (Scope (Btyp)) = E_Return_Statement
8942 and then Nkind (Associated_Node_For_Itype (Btyp)) =
8943 N_Object_Declaration
8944 and then Is_Return_Object
8945 (Defining_Identifier
8946 (Associated_Node_For_Itype (Btyp))))
8952 Scop := Scope (Scope (Btyp));
8953 while Present (Scop) loop
8954 exit when Ekind (Scop) = E_Function;
8955 Scop := Scope (Scop);
8958 -- Treat the return object's type as having the level of the
8959 -- function's result subtype (as per RM05-6.5(5.3/2)).
8961 return Type_Access_Level (Etype (Scop));
8966 Btyp := Root_Type (Btyp);
8968 -- The accessibility level of anonymous acccess types associated with
8969 -- discriminants is that of the current instance of the type, and
8970 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
8972 -- AI-402: access discriminants have accessibility based on the
8973 -- object rather than the type in Ada 2005, so the above paragraph
8976 -- ??? Needs completion with rules from AI-416
8978 if Ada_Version <= Ada_95
8979 and then Ekind (Typ) = E_Anonymous_Access_Type
8980 and then Present (Associated_Node_For_Itype (Typ))
8981 and then Nkind (Associated_Node_For_Itype (Typ)) =
8982 N_Discriminant_Specification
8984 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
8988 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
8989 end Type_Access_Level;
8991 --------------------------
8992 -- Unit_Declaration_Node --
8993 --------------------------
8995 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
8996 N : Node_Id := Parent (Unit_Id);
8999 -- Predefined operators do not have a full function declaration
9001 if Ekind (Unit_Id) = E_Operator then
9005 -- Isn't there some better way to express the following ???
9007 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9008 and then Nkind (N) /= N_Formal_Package_Declaration
9009 and then Nkind (N) /= N_Function_Instantiation
9010 and then Nkind (N) /= N_Generic_Package_Declaration
9011 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9012 and then Nkind (N) /= N_Package_Declaration
9013 and then Nkind (N) /= N_Package_Body
9014 and then Nkind (N) /= N_Package_Instantiation
9015 and then Nkind (N) /= N_Package_Renaming_Declaration
9016 and then Nkind (N) /= N_Procedure_Instantiation
9017 and then Nkind (N) /= N_Protected_Body
9018 and then Nkind (N) /= N_Subprogram_Declaration
9019 and then Nkind (N) /= N_Subprogram_Body
9020 and then Nkind (N) /= N_Subprogram_Body_Stub
9021 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9022 and then Nkind (N) /= N_Task_Body
9023 and then Nkind (N) /= N_Task_Type_Declaration
9024 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9025 and then Nkind (N) not in N_Generic_Renaming_Declaration
9028 pragma Assert (Present (N));
9032 end Unit_Declaration_Node;
9034 ------------------------------
9035 -- Universal_Interpretation --
9036 ------------------------------
9038 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9039 Index : Interp_Index;
9043 -- The argument may be a formal parameter of an operator or subprogram
9044 -- with multiple interpretations, or else an expression for an actual.
9046 if Nkind (Opnd) = N_Defining_Identifier
9047 or else not Is_Overloaded (Opnd)
9049 if Etype (Opnd) = Universal_Integer
9050 or else Etype (Opnd) = Universal_Real
9052 return Etype (Opnd);
9058 Get_First_Interp (Opnd, Index, It);
9059 while Present (It.Typ) loop
9060 if It.Typ = Universal_Integer
9061 or else It.Typ = Universal_Real
9066 Get_Next_Interp (Index, It);
9071 end Universal_Interpretation;
9077 function Unqualify (Expr : Node_Id) return Node_Id is
9079 -- Recurse to handle unlikely case of multiple levels of qualification
9081 if Nkind (Expr) = N_Qualified_Expression then
9082 return Unqualify (Expression (Expr));
9084 -- Normal case, not a qualified expression
9091 ----------------------
9092 -- Within_Init_Proc --
9093 ----------------------
9095 function Within_Init_Proc return Boolean is
9100 while not Is_Overloadable (S) loop
9101 if S = Standard_Standard then
9108 return Is_Init_Proc (S);
9109 end Within_Init_Proc;
9115 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9116 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9117 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9119 function Has_One_Matching_Field return Boolean;
9120 -- Determines if Expec_Type is a record type with a single component or
9121 -- discriminant whose type matches the found type or is one dimensional
9122 -- array whose component type matches the found type.
9124 ----------------------------
9125 -- Has_One_Matching_Field --
9126 ----------------------------
9128 function Has_One_Matching_Field return Boolean is
9132 if Is_Array_Type (Expec_Type)
9133 and then Number_Dimensions (Expec_Type) = 1
9135 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9139 elsif not Is_Record_Type (Expec_Type) then
9143 E := First_Entity (Expec_Type);
9148 elsif (Ekind (E) /= E_Discriminant
9149 and then Ekind (E) /= E_Component)
9150 or else (Chars (E) = Name_uTag
9151 or else Chars (E) = Name_uParent)
9160 if not Covers (Etype (E), Found_Type) then
9163 elsif Present (Next_Entity (E)) then
9170 end Has_One_Matching_Field;
9172 -- Start of processing for Wrong_Type
9175 -- Don't output message if either type is Any_Type, or if a message
9176 -- has already been posted for this node. We need to do the latter
9177 -- check explicitly (it is ordinarily done in Errout), because we
9178 -- are using ! to force the output of the error messages.
9180 if Expec_Type = Any_Type
9181 or else Found_Type = Any_Type
9182 or else Error_Posted (Expr)
9186 -- In an instance, there is an ongoing problem with completion of
9187 -- type derived from private types. Their structure is what Gigi
9188 -- expects, but the Etype is the parent type rather than the
9189 -- derived private type itself. Do not flag error in this case. The
9190 -- private completion is an entity without a parent, like an Itype.
9191 -- Similarly, full and partial views may be incorrect in the instance.
9192 -- There is no simple way to insure that it is consistent ???
9194 elsif In_Instance then
9195 if Etype (Etype (Expr)) = Etype (Expected_Type)
9197 (Has_Private_Declaration (Expected_Type)
9198 or else Has_Private_Declaration (Etype (Expr)))
9199 and then No (Parent (Expected_Type))
9205 -- An interesting special check. If the expression is parenthesized
9206 -- and its type corresponds to the type of the sole component of the
9207 -- expected record type, or to the component type of the expected one
9208 -- dimensional array type, then assume we have a bad aggregate attempt.
9210 if Nkind (Expr) in N_Subexpr
9211 and then Paren_Count (Expr) /= 0
9212 and then Has_One_Matching_Field
9214 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9216 -- Another special check, if we are looking for a pool-specific access
9217 -- type and we found an E_Access_Attribute_Type, then we have the case
9218 -- of an Access attribute being used in a context which needs a pool-
9219 -- specific type, which is never allowed. The one extra check we make
9220 -- is that the expected designated type covers the Found_Type.
9222 elsif Is_Access_Type (Expec_Type)
9223 and then Ekind (Found_Type) = E_Access_Attribute_Type
9224 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9225 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9227 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9229 Error_Msg_N ("result must be general access type!", Expr);
9230 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9232 -- Another special check, if the expected type is an integer type,
9233 -- but the expression is of type System.Address, and the parent is
9234 -- an addition or subtraction operation whose left operand is the
9235 -- expression in question and whose right operand is of an integral
9236 -- type, then this is an attempt at address arithmetic, so give
9237 -- appropriate message.
9239 elsif Is_Integer_Type (Expec_Type)
9240 and then Is_RTE (Found_Type, RE_Address)
9241 and then (Nkind (Parent (Expr)) = N_Op_Add
9243 Nkind (Parent (Expr)) = N_Op_Subtract)
9244 and then Expr = Left_Opnd (Parent (Expr))
9245 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9248 ("address arithmetic not predefined in package System",
9251 ("\possible missing with/use of System.Storage_Elements",
9255 -- If the expected type is an anonymous access type, as for access
9256 -- parameters and discriminants, the error is on the designated types.
9258 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9259 if Comes_From_Source (Expec_Type) then
9260 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9263 ("expected an access type with designated}",
9264 Expr, Designated_Type (Expec_Type));
9267 if Is_Access_Type (Found_Type)
9268 and then not Comes_From_Source (Found_Type)
9271 ("\\found an access type with designated}!",
9272 Expr, Designated_Type (Found_Type));
9274 if From_With_Type (Found_Type) then
9275 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9276 Error_Msg_Qual_Level := 99;
9277 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9278 Error_Msg_Qual_Level := 0;
9280 Error_Msg_NE ("found}!", Expr, Found_Type);
9284 -- Normal case of one type found, some other type expected
9287 -- If the names of the two types are the same, see if some number
9288 -- of levels of qualification will help. Don't try more than three
9289 -- levels, and if we get to standard, it's no use (and probably
9290 -- represents an error in the compiler) Also do not bother with
9291 -- internal scope names.
9294 Expec_Scope : Entity_Id;
9295 Found_Scope : Entity_Id;
9298 Expec_Scope := Expec_Type;
9299 Found_Scope := Found_Type;
9301 for Levels in Int range 0 .. 3 loop
9302 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9303 Error_Msg_Qual_Level := Levels;
9307 Expec_Scope := Scope (Expec_Scope);
9308 Found_Scope := Scope (Found_Scope);
9310 exit when Expec_Scope = Standard_Standard
9311 or else Found_Scope = Standard_Standard
9312 or else not Comes_From_Source (Expec_Scope)
9313 or else not Comes_From_Source (Found_Scope);
9317 if Is_Record_Type (Expec_Type)
9318 and then Present (Corresponding_Remote_Type (Expec_Type))
9320 Error_Msg_NE ("expected}!", Expr,
9321 Corresponding_Remote_Type (Expec_Type));
9323 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9326 if Is_Entity_Name (Expr)
9327 and then Is_Package_Or_Generic_Package (Entity (Expr))
9329 Error_Msg_N ("\\found package name!", Expr);
9331 elsif Is_Entity_Name (Expr)
9333 (Ekind (Entity (Expr)) = E_Procedure
9335 Ekind (Entity (Expr)) = E_Generic_Procedure)
9337 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9339 ("found procedure name, possibly missing Access attribute!",
9343 ("\\found procedure name instead of function!", Expr);
9346 elsif Nkind (Expr) = N_Function_Call
9347 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9348 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9349 and then No (Parameter_Associations (Expr))
9352 ("found function name, possibly missing Access attribute!",
9355 -- Catch common error: a prefix or infix operator which is not
9356 -- directly visible because the type isn't.
9358 elsif Nkind (Expr) in N_Op
9359 and then Is_Overloaded (Expr)
9360 and then not Is_Immediately_Visible (Expec_Type)
9361 and then not Is_Potentially_Use_Visible (Expec_Type)
9362 and then not In_Use (Expec_Type)
9363 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9366 ("operator of the type is not directly visible!", Expr);
9368 elsif Ekind (Found_Type) = E_Void
9369 and then Present (Parent (Found_Type))
9370 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9372 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9375 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9378 Error_Msg_Qual_Level := 0;