1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Disp; use Exp_Disp;
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_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with Stand; use Stand;
55 with Stringt; use Stringt;
56 with Targparm; use Targparm;
57 with Tbuild; use Tbuild;
58 with Ttypes; use Ttypes;
59 with Uname; use Uname;
61 package body Sem_Util is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Component_Subtype
70 T : Entity_Id) return Node_Id;
71 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
72 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
73 -- Loc is the source location, T is the original subtype.
75 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
76 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
77 -- with discriminants whose default values are static, examine only the
78 -- components in the selected variant to determine whether all of them
81 function Has_Null_Extension (T : Entity_Id) return Boolean;
82 -- T is a derived tagged type. Check whether the type extension is null.
83 -- If the parent type is fully initialized, T can be treated as such.
85 ------------------------------
86 -- Abstract_Interface_List --
87 ------------------------------
89 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
93 if Is_Concurrent_Type (Typ) then
95 -- If we are dealing with a synchronized subtype, go to the base
96 -- type, whose declaration has the interface list.
98 -- Shouldn't this be Declaration_Node???
100 Nod := Parent (Base_Type (Typ));
102 if Nkind (Nod) = N_Full_Type_Declaration then
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 else
115 -- here (the source has errors).
121 -- Support for generic formals with interfaces is still missing ???
123 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
128 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
132 elsif Ekind (Typ) = E_Record_Subtype then
133 Nod := Type_Definition (Parent (Etype (Typ)));
135 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
137 -- Recurse, because parent may still be a private extension. Also
138 -- note that the full view of the subtype or the full view of its
139 -- base type may (both) be unavailable.
141 return Abstract_Interface_List (Etype (Typ));
143 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
144 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
145 Nod := Formal_Type_Definition (Parent (Typ));
147 Nod := Type_Definition (Parent (Typ));
151 return Interface_List (Nod);
152 end Abstract_Interface_List;
154 --------------------------------
155 -- Add_Access_Type_To_Process --
156 --------------------------------
158 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
162 Ensure_Freeze_Node (E);
163 L := Access_Types_To_Process (Freeze_Node (E));
167 Set_Access_Types_To_Process (Freeze_Node (E), L);
171 end Add_Access_Type_To_Process;
173 ----------------------------
174 -- Add_Global_Declaration --
175 ----------------------------
177 procedure Add_Global_Declaration (N : Node_Id) is
178 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
181 if No (Declarations (Aux_Node)) then
182 Set_Declarations (Aux_Node, New_List);
185 Append_To (Declarations (Aux_Node), N);
187 end Add_Global_Declaration;
189 -----------------------
190 -- Alignment_In_Bits --
191 -----------------------
193 function Alignment_In_Bits (E : Entity_Id) return Uint is
195 return Alignment (E) * System_Storage_Unit;
196 end Alignment_In_Bits;
198 -----------------------------------------
199 -- Apply_Compile_Time_Constraint_Error --
200 -----------------------------------------
202 procedure Apply_Compile_Time_Constraint_Error
205 Reason : RT_Exception_Code;
206 Ent : Entity_Id := Empty;
207 Typ : Entity_Id := Empty;
208 Loc : Source_Ptr := No_Location;
209 Rep : Boolean := True;
210 Warn : Boolean := False)
212 Stat : constant Boolean := Is_Static_Expression (N);
213 R_Stat : constant Node_Id :=
214 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
225 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
231 -- Now we replace the node by an N_Raise_Constraint_Error node
232 -- This does not need reanalyzing, so set it as analyzed now.
235 Set_Analyzed (N, True);
238 Set_Raises_Constraint_Error (N);
240 -- If the original expression was marked as static, the result is
241 -- still marked as static, but the Raises_Constraint_Error flag is
242 -- always set so that further static evaluation is not attempted.
245 Set_Is_Static_Expression (N);
247 end Apply_Compile_Time_Constraint_Error;
249 --------------------------
250 -- Build_Actual_Subtype --
251 --------------------------
253 function Build_Actual_Subtype
255 N : Node_Or_Entity_Id) return Node_Id
258 -- Normally Sloc (N), but may point to corresponding body in some cases
260 Constraints : List_Id;
266 Disc_Type : Entity_Id;
272 if Nkind (N) = N_Defining_Identifier then
273 Obj := New_Reference_To (N, Loc);
275 -- If this is a formal parameter of a subprogram declaration, and
276 -- we are compiling the body, we want the declaration for the
277 -- actual subtype to carry the source position of the body, to
278 -- prevent anomalies in gdb when stepping through the code.
280 if Is_Formal (N) then
282 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
284 if Nkind (Decl) = N_Subprogram_Declaration
285 and then Present (Corresponding_Body (Decl))
287 Loc := Sloc (Corresponding_Body (Decl));
296 if Is_Array_Type (T) then
297 Constraints := New_List;
298 for J in 1 .. Number_Dimensions (T) loop
300 -- Build an array subtype declaration with the nominal subtype and
301 -- the bounds of the actual. Add the declaration in front of the
302 -- local declarations for the subprogram, for analysis before any
303 -- reference to the formal in the body.
306 Make_Attribute_Reference (Loc,
308 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
309 Attribute_Name => Name_First,
310 Expressions => New_List (
311 Make_Integer_Literal (Loc, J)));
314 Make_Attribute_Reference (Loc,
316 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
317 Attribute_Name => Name_Last,
318 Expressions => New_List (
319 Make_Integer_Literal (Loc, J)));
321 Append (Make_Range (Loc, Lo, Hi), Constraints);
324 -- If the type has unknown discriminants there is no constrained
325 -- subtype to build. This is never called for a formal or for a
326 -- lhs, so returning the type is ok ???
328 elsif Has_Unknown_Discriminants (T) then
332 Constraints := New_List;
334 -- Type T is a generic derived type, inherit the discriminants from
337 if Is_Private_Type (T)
338 and then No (Full_View (T))
340 -- T was flagged as an error if it was declared as a formal
341 -- derived type with known discriminants. In this case there
342 -- is no need to look at the parent type since T already carries
343 -- its own discriminants.
345 and then not Error_Posted (T)
347 Disc_Type := Etype (Base_Type (T));
352 Discr := First_Discriminant (Disc_Type);
353 while Present (Discr) loop
354 Append_To (Constraints,
355 Make_Selected_Component (Loc,
357 Duplicate_Subexpr_No_Checks (Obj),
358 Selector_Name => New_Occurrence_Of (Discr, Loc)));
359 Next_Discriminant (Discr);
364 Make_Defining_Identifier (Loc,
365 Chars => New_Internal_Name ('S'));
366 Set_Is_Internal (Subt);
369 Make_Subtype_Declaration (Loc,
370 Defining_Identifier => Subt,
371 Subtype_Indication =>
372 Make_Subtype_Indication (Loc,
373 Subtype_Mark => New_Reference_To (T, Loc),
375 Make_Index_Or_Discriminant_Constraint (Loc,
376 Constraints => Constraints)));
378 Mark_Rewrite_Insertion (Decl);
380 end Build_Actual_Subtype;
382 ---------------------------------------
383 -- Build_Actual_Subtype_Of_Component --
384 ---------------------------------------
386 function Build_Actual_Subtype_Of_Component
388 N : Node_Id) return Node_Id
390 Loc : constant Source_Ptr := Sloc (N);
391 P : constant Node_Id := Prefix (N);
394 Indx_Type : Entity_Id;
396 Deaccessed_T : Entity_Id;
397 -- This is either a copy of T, or if T is an access type, then it is
398 -- the directly designated type of this access type.
400 function Build_Actual_Array_Constraint return List_Id;
401 -- If one or more of the bounds of the component depends on
402 -- discriminants, build actual constraint using the discriminants
405 function Build_Actual_Record_Constraint return List_Id;
406 -- Similar to previous one, for discriminated components constrained
407 -- by the discriminant of the enclosing object.
409 -----------------------------------
410 -- Build_Actual_Array_Constraint --
411 -----------------------------------
413 function Build_Actual_Array_Constraint return List_Id is
414 Constraints : constant List_Id := New_List;
422 Indx := First_Index (Deaccessed_T);
423 while Present (Indx) loop
424 Old_Lo := Type_Low_Bound (Etype (Indx));
425 Old_Hi := Type_High_Bound (Etype (Indx));
427 if Denotes_Discriminant (Old_Lo) then
429 Make_Selected_Component (Loc,
430 Prefix => New_Copy_Tree (P),
431 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
434 Lo := New_Copy_Tree (Old_Lo);
436 -- The new bound will be reanalyzed in the enclosing
437 -- declaration. For literal bounds that come from a type
438 -- declaration, the type of the context must be imposed, so
439 -- insure that analysis will take place. For non-universal
440 -- types this is not strictly necessary.
442 Set_Analyzed (Lo, False);
445 if Denotes_Discriminant (Old_Hi) then
447 Make_Selected_Component (Loc,
448 Prefix => New_Copy_Tree (P),
449 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
452 Hi := New_Copy_Tree (Old_Hi);
453 Set_Analyzed (Hi, False);
456 Append (Make_Range (Loc, Lo, Hi), Constraints);
461 end Build_Actual_Array_Constraint;
463 ------------------------------------
464 -- Build_Actual_Record_Constraint --
465 ------------------------------------
467 function Build_Actual_Record_Constraint return List_Id is
468 Constraints : constant List_Id := New_List;
473 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
474 while Present (D) loop
475 if Denotes_Discriminant (Node (D)) then
476 D_Val := Make_Selected_Component (Loc,
477 Prefix => New_Copy_Tree (P),
478 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
481 D_Val := New_Copy_Tree (Node (D));
484 Append (D_Val, Constraints);
489 end Build_Actual_Record_Constraint;
491 -- Start of processing for Build_Actual_Subtype_Of_Component
494 -- Why the test for Spec_Expression mode here???
496 if In_Spec_Expression then
499 -- More comments for the rest of this body would be good ???
501 elsif Nkind (N) = N_Explicit_Dereference then
502 if Is_Composite_Type (T)
503 and then not Is_Constrained (T)
504 and then not (Is_Class_Wide_Type (T)
505 and then Is_Constrained (Root_Type (T)))
506 and then not Has_Unknown_Discriminants (T)
508 -- If the type of the dereference is already constrained, it
509 -- is an actual subtype.
511 if Is_Array_Type (Etype (N))
512 and then Is_Constrained (Etype (N))
516 Remove_Side_Effects (P);
517 return Build_Actual_Subtype (T, N);
524 if Ekind (T) = E_Access_Subtype then
525 Deaccessed_T := Designated_Type (T);
530 if Ekind (Deaccessed_T) = E_Array_Subtype then
531 Id := First_Index (Deaccessed_T);
532 while Present (Id) loop
533 Indx_Type := Underlying_Type (Etype (Id));
535 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
537 Denotes_Discriminant (Type_High_Bound (Indx_Type))
539 Remove_Side_Effects (P);
541 Build_Component_Subtype
542 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
548 elsif Is_Composite_Type (Deaccessed_T)
549 and then Has_Discriminants (Deaccessed_T)
550 and then not Has_Unknown_Discriminants (Deaccessed_T)
552 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
553 while Present (D) loop
554 if Denotes_Discriminant (Node (D)) then
555 Remove_Side_Effects (P);
557 Build_Component_Subtype (
558 Build_Actual_Record_Constraint, Loc, Base_Type (T));
565 -- If none of the above, the actual and nominal subtypes are the same
568 end Build_Actual_Subtype_Of_Component;
570 -----------------------------
571 -- Build_Component_Subtype --
572 -----------------------------
574 function Build_Component_Subtype
577 T : Entity_Id) return Node_Id
583 -- Unchecked_Union components do not require component subtypes
585 if Is_Unchecked_Union (T) then
590 Make_Defining_Identifier (Loc,
591 Chars => New_Internal_Name ('S'));
592 Set_Is_Internal (Subt);
595 Make_Subtype_Declaration (Loc,
596 Defining_Identifier => Subt,
597 Subtype_Indication =>
598 Make_Subtype_Indication (Loc,
599 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
601 Make_Index_Or_Discriminant_Constraint (Loc,
604 Mark_Rewrite_Insertion (Decl);
606 end Build_Component_Subtype;
608 ---------------------------
609 -- Build_Default_Subtype --
610 ---------------------------
612 function Build_Default_Subtype
614 N : Node_Id) return Entity_Id
616 Loc : constant Source_Ptr := Sloc (N);
620 if not Has_Discriminants (T) or else Is_Constrained (T) then
624 Disc := First_Discriminant (T);
626 if No (Discriminant_Default_Value (Disc)) then
631 Act : constant Entity_Id :=
632 Make_Defining_Identifier (Loc,
633 Chars => New_Internal_Name ('S'));
635 Constraints : constant List_Id := New_List;
639 while Present (Disc) loop
640 Append_To (Constraints,
641 New_Copy_Tree (Discriminant_Default_Value (Disc)));
642 Next_Discriminant (Disc);
646 Make_Subtype_Declaration (Loc,
647 Defining_Identifier => Act,
648 Subtype_Indication =>
649 Make_Subtype_Indication (Loc,
650 Subtype_Mark => New_Occurrence_Of (T, Loc),
652 Make_Index_Or_Discriminant_Constraint (Loc,
653 Constraints => Constraints)));
655 Insert_Action (N, Decl);
659 end Build_Default_Subtype;
661 --------------------------------------------
662 -- Build_Discriminal_Subtype_Of_Component --
663 --------------------------------------------
665 function Build_Discriminal_Subtype_Of_Component
666 (T : Entity_Id) return Node_Id
668 Loc : constant Source_Ptr := Sloc (T);
672 function Build_Discriminal_Array_Constraint return List_Id;
673 -- If one or more of the bounds of the component depends on
674 -- discriminants, build actual constraint using the discriminants
677 function Build_Discriminal_Record_Constraint return List_Id;
678 -- Similar to previous one, for discriminated components constrained
679 -- by the discriminant of the enclosing object.
681 ----------------------------------------
682 -- Build_Discriminal_Array_Constraint --
683 ----------------------------------------
685 function Build_Discriminal_Array_Constraint return List_Id is
686 Constraints : constant List_Id := New_List;
694 Indx := First_Index (T);
695 while Present (Indx) loop
696 Old_Lo := Type_Low_Bound (Etype (Indx));
697 Old_Hi := Type_High_Bound (Etype (Indx));
699 if Denotes_Discriminant (Old_Lo) then
700 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
703 Lo := New_Copy_Tree (Old_Lo);
706 if Denotes_Discriminant (Old_Hi) then
707 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
710 Hi := New_Copy_Tree (Old_Hi);
713 Append (Make_Range (Loc, Lo, Hi), Constraints);
718 end Build_Discriminal_Array_Constraint;
720 -----------------------------------------
721 -- Build_Discriminal_Record_Constraint --
722 -----------------------------------------
724 function Build_Discriminal_Record_Constraint return List_Id is
725 Constraints : constant List_Id := New_List;
730 D := First_Elmt (Discriminant_Constraint (T));
731 while Present (D) loop
732 if Denotes_Discriminant (Node (D)) then
734 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
737 D_Val := New_Copy_Tree (Node (D));
740 Append (D_Val, Constraints);
745 end Build_Discriminal_Record_Constraint;
747 -- Start of processing for Build_Discriminal_Subtype_Of_Component
750 if Ekind (T) = E_Array_Subtype then
751 Id := First_Index (T);
752 while Present (Id) loop
753 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
754 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
756 return Build_Component_Subtype
757 (Build_Discriminal_Array_Constraint, Loc, T);
763 elsif Ekind (T) = E_Record_Subtype
764 and then Has_Discriminants (T)
765 and then not Has_Unknown_Discriminants (T)
767 D := First_Elmt (Discriminant_Constraint (T));
768 while Present (D) loop
769 if Denotes_Discriminant (Node (D)) then
770 return Build_Component_Subtype
771 (Build_Discriminal_Record_Constraint, Loc, T);
778 -- If none of the above, the actual and nominal subtypes are the same
781 end Build_Discriminal_Subtype_Of_Component;
783 ------------------------------
784 -- Build_Elaboration_Entity --
785 ------------------------------
787 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
788 Loc : constant Source_Ptr := Sloc (N);
790 Elab_Ent : Entity_Id;
792 procedure Set_Package_Name (Ent : Entity_Id);
793 -- Given an entity, sets the fully qualified name of the entity in
794 -- Name_Buffer, with components separated by double underscores. This
795 -- is a recursive routine that climbs the scope chain to Standard.
797 ----------------------
798 -- Set_Package_Name --
799 ----------------------
801 procedure Set_Package_Name (Ent : Entity_Id) is
803 if Scope (Ent) /= Standard_Standard then
804 Set_Package_Name (Scope (Ent));
807 Nam : constant String := Get_Name_String (Chars (Ent));
809 Name_Buffer (Name_Len + 1) := '_';
810 Name_Buffer (Name_Len + 2) := '_';
811 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
812 Name_Len := Name_Len + Nam'Length + 2;
816 Get_Name_String (Chars (Ent));
818 end Set_Package_Name;
820 -- Start of processing for Build_Elaboration_Entity
823 -- Ignore if already constructed
825 if Present (Elaboration_Entity (Spec_Id)) then
829 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
830 -- name with dots replaced by double underscore. We have to manually
831 -- construct this name, since it will be elaborated in the outer scope,
832 -- and thus will not have the unit name automatically prepended.
834 Set_Package_Name (Spec_Id);
838 Name_Buffer (Name_Len + 1) := '_';
839 Name_Buffer (Name_Len + 2) := 'E';
840 Name_Len := Name_Len + 2;
842 -- Create elaboration flag
845 Make_Defining_Identifier (Loc, Chars => Name_Find);
846 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
849 Make_Object_Declaration (Loc,
850 Defining_Identifier => Elab_Ent,
852 New_Occurrence_Of (Standard_Boolean, Loc),
854 New_Occurrence_Of (Standard_False, Loc));
856 Push_Scope (Standard_Standard);
857 Add_Global_Declaration (Decl);
860 -- Reset True_Constant indication, since we will indeed assign a value
861 -- to the variable in the binder main. We also kill the Current_Value
862 -- and Last_Assignment fields for the same reason.
864 Set_Is_True_Constant (Elab_Ent, False);
865 Set_Current_Value (Elab_Ent, Empty);
866 Set_Last_Assignment (Elab_Ent, Empty);
868 -- We do not want any further qualification of the name (if we did
869 -- not do this, we would pick up the name of the generic package
870 -- in the case of a library level generic instantiation).
872 Set_Has_Qualified_Name (Elab_Ent);
873 Set_Has_Fully_Qualified_Name (Elab_Ent);
874 end Build_Elaboration_Entity;
876 -----------------------------------
877 -- Cannot_Raise_Constraint_Error --
878 -----------------------------------
880 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
882 if Compile_Time_Known_Value (Expr) then
885 elsif Do_Range_Check (Expr) then
888 elsif Raises_Constraint_Error (Expr) then
896 when N_Expanded_Name =>
899 when N_Selected_Component =>
900 return not Do_Discriminant_Check (Expr);
902 when N_Attribute_Reference =>
903 if Do_Overflow_Check (Expr) then
906 elsif No (Expressions (Expr)) then
914 N := First (Expressions (Expr));
915 while Present (N) loop
916 if Cannot_Raise_Constraint_Error (N) then
927 when N_Type_Conversion =>
928 if Do_Overflow_Check (Expr)
929 or else Do_Length_Check (Expr)
930 or else Do_Tag_Check (Expr)
935 Cannot_Raise_Constraint_Error (Expression (Expr));
938 when N_Unchecked_Type_Conversion =>
939 return Cannot_Raise_Constraint_Error (Expression (Expr));
942 if Do_Overflow_Check (Expr) then
946 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
953 if Do_Division_Check (Expr)
954 or else Do_Overflow_Check (Expr)
959 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
961 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
980 N_Op_Shift_Right_Arithmetic |
984 if Do_Overflow_Check (Expr) then
988 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
990 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
997 end Cannot_Raise_Constraint_Error;
999 --------------------------
1000 -- Check_Fully_Declared --
1001 --------------------------
1003 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1005 if Ekind (T) = E_Incomplete_Type then
1007 -- Ada 2005 (AI-50217): If the type is available through a limited
1008 -- with_clause, verify that its full view has been analyzed.
1010 if From_With_Type (T)
1011 and then Present (Non_Limited_View (T))
1012 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1014 -- The non-limited view is fully declared
1019 ("premature usage of incomplete}", N, First_Subtype (T));
1022 -- Need comments for these tests ???
1024 elsif Has_Private_Component (T)
1025 and then not Is_Generic_Type (Root_Type (T))
1026 and then not In_Spec_Expression
1028 -- Special case: if T is the anonymous type created for a single
1029 -- task or protected object, use the name of the source object.
1031 if Is_Concurrent_Type (T)
1032 and then not Comes_From_Source (T)
1033 and then Nkind (N) = N_Object_Declaration
1035 Error_Msg_NE ("type of& has incomplete component", N,
1036 Defining_Identifier (N));
1040 ("premature usage of incomplete}", N, First_Subtype (T));
1043 end Check_Fully_Declared;
1045 -------------------------
1046 -- Check_Nested_Access --
1047 -------------------------
1049 procedure Check_Nested_Access (Ent : Entity_Id) is
1050 Scop : constant Entity_Id := Current_Scope;
1051 Current_Subp : Entity_Id;
1052 Enclosing : Entity_Id;
1055 -- Currently only enabled for VM back-ends for efficiency, should we
1056 -- enable it more systematically ???
1058 -- Check for Is_Imported needs commenting below ???
1060 if VM_Target /= No_VM
1061 and then (Ekind (Ent) = E_Variable
1063 Ekind (Ent) = E_Constant
1065 Ekind (Ent) = E_Loop_Parameter)
1066 and then Scope (Ent) /= Empty
1067 and then not Is_Library_Level_Entity (Ent)
1068 and then not Is_Imported (Ent)
1070 if Is_Subprogram (Scop)
1071 or else Is_Generic_Subprogram (Scop)
1072 or else Is_Entry (Scop)
1074 Current_Subp := Scop;
1076 Current_Subp := Current_Subprogram;
1079 Enclosing := Enclosing_Subprogram (Ent);
1081 if Enclosing /= Empty
1082 and then Enclosing /= Current_Subp
1084 Set_Has_Up_Level_Access (Ent, True);
1087 end Check_Nested_Access;
1089 ------------------------------------------
1090 -- Check_Potentially_Blocking_Operation --
1091 ------------------------------------------
1093 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1096 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1097 -- When pragma Detect_Blocking is active, the run time will raise
1098 -- Program_Error. Here we only issue a warning, since we generally
1099 -- support the use of potentially blocking operations in the absence
1102 -- Indirect blocking through a subprogram call cannot be diagnosed
1103 -- statically without interprocedural analysis, so we do not attempt
1106 S := Scope (Current_Scope);
1107 while Present (S) and then S /= Standard_Standard loop
1108 if Is_Protected_Type (S) then
1110 ("potentially blocking operation in protected operation?", N);
1117 end Check_Potentially_Blocking_Operation;
1119 ------------------------------
1120 -- Check_Unprotected_Access --
1121 ------------------------------
1123 procedure Check_Unprotected_Access
1127 Cont_Encl_Typ : Entity_Id;
1128 Pref_Encl_Typ : Entity_Id;
1130 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1131 -- Check whether Obj is a private component of a protected object.
1132 -- Return the protected type where the component resides, Empty
1135 function Is_Public_Operation return Boolean;
1136 -- Verify that the enclosing operation is callable from outside the
1137 -- protected object, to minimize false positives.
1139 ------------------------------
1140 -- Enclosing_Protected_Type --
1141 ------------------------------
1143 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1145 if Is_Entity_Name (Obj) then
1147 Ent : Entity_Id := Entity (Obj);
1150 -- The object can be a renaming of a private component, use
1151 -- the original record component.
1153 if Is_Prival (Ent) then
1154 Ent := Prival_Link (Ent);
1157 if Is_Protected_Type (Scope (Ent)) then
1163 -- For indexed and selected components, recursively check the prefix
1165 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1166 return Enclosing_Protected_Type (Prefix (Obj));
1168 -- The object does not denote a protected component
1173 end Enclosing_Protected_Type;
1175 -------------------------
1176 -- Is_Public_Operation --
1177 -------------------------
1179 function Is_Public_Operation return Boolean is
1186 and then S /= Pref_Encl_Typ
1188 if Scope (S) = Pref_Encl_Typ then
1189 E := First_Entity (Pref_Encl_Typ);
1191 and then E /= First_Private_Entity (Pref_Encl_Typ)
1204 end Is_Public_Operation;
1206 -- Start of processing for Check_Unprotected_Access
1209 if Nkind (Expr) = N_Attribute_Reference
1210 and then Attribute_Name (Expr) = Name_Unchecked_Access
1212 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1213 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1215 -- Check whether we are trying to export a protected component to a
1216 -- context with an equal or lower access level.
1218 if Present (Pref_Encl_Typ)
1219 and then No (Cont_Encl_Typ)
1220 and then Is_Public_Operation
1221 and then Scope_Depth (Pref_Encl_Typ) >=
1222 Object_Access_Level (Context)
1225 ("?possible unprotected access to protected data", Expr);
1228 end Check_Unprotected_Access;
1234 procedure Check_VMS (Construct : Node_Id) is
1236 if not OpenVMS_On_Target then
1238 ("this construct is allowed only in Open'V'M'S", Construct);
1242 ------------------------
1243 -- Collect_Interfaces --
1244 ------------------------
1246 procedure Collect_Interfaces
1248 Ifaces_List : out Elist_Id;
1249 Exclude_Parents : Boolean := False;
1250 Use_Full_View : Boolean := True)
1252 procedure Collect (Typ : Entity_Id);
1253 -- Subsidiary subprogram used to traverse the whole list
1254 -- of directly and indirectly implemented interfaces
1260 procedure Collect (Typ : Entity_Id) is
1261 Ancestor : Entity_Id;
1269 -- Handle private types
1272 and then Is_Private_Type (Typ)
1273 and then Present (Full_View (Typ))
1275 Full_T := Full_View (Typ);
1278 -- Include the ancestor if we are generating the whole list of
1279 -- abstract interfaces.
1281 if Etype (Full_T) /= Typ
1283 -- Protect the frontend against wrong sources. For example:
1286 -- type A is tagged null record;
1287 -- type B is new A with private;
1288 -- type C is new A with private;
1290 -- type B is new C with null record;
1291 -- type C is new B with null record;
1294 and then Etype (Full_T) /= T
1296 Ancestor := Etype (Full_T);
1299 if Is_Interface (Ancestor)
1300 and then not Exclude_Parents
1302 Append_Unique_Elmt (Ancestor, Ifaces_List);
1306 -- Traverse the graph of ancestor interfaces
1308 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1309 Id := First (Abstract_Interface_List (Full_T));
1310 while Present (Id) loop
1311 Iface := Etype (Id);
1313 -- Protect against wrong uses. For example:
1314 -- type I is interface;
1315 -- type O is tagged null record;
1316 -- type Wrong is new I and O with null record; -- ERROR
1318 if Is_Interface (Iface) then
1320 and then Etype (T) /= T
1321 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1326 Append_Unique_Elmt (Iface, Ifaces_List);
1335 -- Start of processing for Collect_Interfaces
1338 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1339 Ifaces_List := New_Elmt_List;
1341 end Collect_Interfaces;
1343 ----------------------------------
1344 -- Collect_Interface_Components --
1345 ----------------------------------
1347 procedure Collect_Interface_Components
1348 (Tagged_Type : Entity_Id;
1349 Components_List : out Elist_Id)
1351 procedure Collect (Typ : Entity_Id);
1352 -- Subsidiary subprogram used to climb to the parents
1358 procedure Collect (Typ : Entity_Id) is
1359 Tag_Comp : Entity_Id;
1362 if Etype (Typ) /= Typ
1364 -- Protect the frontend against wrong sources. For example:
1367 -- type A is tagged null record;
1368 -- type B is new A with private;
1369 -- type C is new A with private;
1371 -- type B is new C with null record;
1372 -- type C is new B with null record;
1375 and then Etype (Typ) /= Tagged_Type
1377 Collect (Etype (Typ));
1380 -- Collect the components containing tags of secondary dispatch
1383 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1384 while Present (Tag_Comp) loop
1385 pragma Assert (Present (Related_Type (Tag_Comp)));
1386 Append_Elmt (Tag_Comp, Components_List);
1388 Tag_Comp := Next_Tag_Component (Tag_Comp);
1392 -- Start of processing for Collect_Interface_Components
1395 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1396 and then Is_Tagged_Type (Tagged_Type));
1398 Components_List := New_Elmt_List;
1399 Collect (Tagged_Type);
1400 end Collect_Interface_Components;
1402 -----------------------------
1403 -- Collect_Interfaces_Info --
1404 -----------------------------
1406 procedure Collect_Interfaces_Info
1408 Ifaces_List : out Elist_Id;
1409 Components_List : out Elist_Id;
1410 Tags_List : out Elist_Id)
1412 Comps_List : Elist_Id;
1413 Comp_Elmt : Elmt_Id;
1414 Comp_Iface : Entity_Id;
1415 Iface_Elmt : Elmt_Id;
1418 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1419 -- Search for the secondary tag associated with the interface type
1420 -- Iface that is implemented by T.
1426 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1430 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1432 and then Ekind (Node (ADT)) = E_Constant
1433 and then Related_Type (Node (ADT)) /= Iface
1435 -- Skip the secondary dispatch tables of Iface
1443 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1447 -- Start of processing for Collect_Interfaces_Info
1450 Collect_Interfaces (T, Ifaces_List);
1451 Collect_Interface_Components (T, Comps_List);
1453 -- Search for the record component and tag associated with each
1454 -- interface type of T.
1456 Components_List := New_Elmt_List;
1457 Tags_List := New_Elmt_List;
1459 Iface_Elmt := First_Elmt (Ifaces_List);
1460 while Present (Iface_Elmt) loop
1461 Iface := Node (Iface_Elmt);
1463 -- Associate the primary tag component and the primary dispatch table
1464 -- with all the interfaces that are parents of T
1466 if Is_Ancestor (Iface, T) then
1467 Append_Elmt (First_Tag_Component (T), Components_List);
1468 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1470 -- Otherwise search for the tag component and secondary dispatch
1474 Comp_Elmt := First_Elmt (Comps_List);
1475 while Present (Comp_Elmt) loop
1476 Comp_Iface := Related_Type (Node (Comp_Elmt));
1478 if Comp_Iface = Iface
1479 or else Is_Ancestor (Iface, Comp_Iface)
1481 Append_Elmt (Node (Comp_Elmt), Components_List);
1482 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1486 Next_Elmt (Comp_Elmt);
1488 pragma Assert (Present (Comp_Elmt));
1491 Next_Elmt (Iface_Elmt);
1493 end Collect_Interfaces_Info;
1495 ----------------------------------
1496 -- Collect_Primitive_Operations --
1497 ----------------------------------
1499 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1500 B_Type : constant Entity_Id := Base_Type (T);
1501 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1502 B_Scope : Entity_Id := Scope (B_Type);
1506 Formal_Derived : Boolean := False;
1510 -- For tagged types, the primitive operations are collected as they
1511 -- are declared, and held in an explicit list which is simply returned.
1513 if Is_Tagged_Type (B_Type) then
1514 return Primitive_Operations (B_Type);
1516 -- An untagged generic type that is a derived type inherits the
1517 -- primitive operations of its parent type. Other formal types only
1518 -- have predefined operators, which are not explicitly represented.
1520 elsif Is_Generic_Type (B_Type) then
1521 if Nkind (B_Decl) = N_Formal_Type_Declaration
1522 and then Nkind (Formal_Type_Definition (B_Decl))
1523 = N_Formal_Derived_Type_Definition
1525 Formal_Derived := True;
1527 return New_Elmt_List;
1531 Op_List := New_Elmt_List;
1533 if B_Scope = Standard_Standard then
1534 if B_Type = Standard_String then
1535 Append_Elmt (Standard_Op_Concat, Op_List);
1537 elsif B_Type = Standard_Wide_String then
1538 Append_Elmt (Standard_Op_Concatw, Op_List);
1544 elsif (Is_Package_Or_Generic_Package (B_Scope)
1546 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1548 or else Is_Derived_Type (B_Type)
1550 -- The primitive operations appear after the base type, except
1551 -- if the derivation happens within the private part of B_Scope
1552 -- and the type is a private type, in which case both the type
1553 -- and some primitive operations may appear before the base
1554 -- type, and the list of candidates starts after the type.
1556 if In_Open_Scopes (B_Scope)
1557 and then Scope (T) = B_Scope
1558 and then In_Private_Part (B_Scope)
1560 Id := Next_Entity (T);
1562 Id := Next_Entity (B_Type);
1565 while Present (Id) loop
1567 -- Note that generic formal subprograms are not
1568 -- considered to be primitive operations and thus
1569 -- are never inherited.
1571 if Is_Overloadable (Id)
1572 and then Nkind (Parent (Parent (Id)))
1573 not in N_Formal_Subprogram_Declaration
1577 if Base_Type (Etype (Id)) = B_Type then
1580 Formal := First_Formal (Id);
1581 while Present (Formal) loop
1582 if Base_Type (Etype (Formal)) = B_Type then
1586 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1588 (Designated_Type (Etype (Formal))) = B_Type
1594 Next_Formal (Formal);
1598 -- For a formal derived type, the only primitives are the
1599 -- ones inherited from the parent type. Operations appearing
1600 -- in the package declaration are not primitive for it.
1603 and then (not Formal_Derived
1604 or else Present (Alias (Id)))
1606 Append_Elmt (Id, Op_List);
1612 -- For a type declared in System, some of its operations
1613 -- may appear in the target-specific extension to System.
1616 and then Chars (B_Scope) = Name_System
1617 and then Scope (B_Scope) = Standard_Standard
1618 and then Present_System_Aux
1620 B_Scope := System_Aux_Id;
1621 Id := First_Entity (System_Aux_Id);
1627 end Collect_Primitive_Operations;
1629 -----------------------------------
1630 -- Compile_Time_Constraint_Error --
1631 -----------------------------------
1633 function Compile_Time_Constraint_Error
1636 Ent : Entity_Id := Empty;
1637 Loc : Source_Ptr := No_Location;
1638 Warn : Boolean := False) return Node_Id
1640 Msgc : String (1 .. Msg'Length + 2);
1641 -- Copy of message, with room for possible ? and ! at end
1651 -- A static constraint error in an instance body is not a fatal error.
1652 -- we choose to inhibit the message altogether, because there is no
1653 -- obvious node (for now) on which to post it. On the other hand the
1654 -- offending node must be replaced with a constraint_error in any case.
1656 -- No messages are generated if we already posted an error on this node
1658 if not Error_Posted (N) then
1659 if Loc /= No_Location then
1665 Msgc (1 .. Msg'Length) := Msg;
1668 -- Message is a warning, even in Ada 95 case
1670 if Msg (Msg'Last) = '?' then
1673 -- In Ada 83, all messages are warnings. In the private part and
1674 -- the body of an instance, constraint_checks are only warnings.
1675 -- We also make this a warning if the Warn parameter is set.
1678 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1684 elsif In_Instance_Not_Visible then
1689 -- Otherwise we have a real error message (Ada 95 static case)
1690 -- and we make this an unconditional message. Note that in the
1691 -- warning case we do not make the message unconditional, it seems
1692 -- quite reasonable to delete messages like this (about exceptions
1693 -- that will be raised) in dead code.
1701 -- Should we generate a warning? The answer is not quite yes. The
1702 -- very annoying exception occurs in the case of a short circuit
1703 -- operator where the left operand is static and decisive. Climb
1704 -- parents to see if that is the case we have here. Conditional
1705 -- expressions with decisive conditions are a similar situation.
1713 -- And then with False as left operand
1715 if Nkind (P) = N_And_Then
1716 and then Compile_Time_Known_Value (Left_Opnd (P))
1717 and then Is_False (Expr_Value (Left_Opnd (P)))
1722 -- OR ELSE with True as left operand
1724 elsif Nkind (P) = N_Or_Else
1725 and then Compile_Time_Known_Value (Left_Opnd (P))
1726 and then Is_True (Expr_Value (Left_Opnd (P)))
1731 -- Conditional expression
1733 elsif Nkind (P) = N_Conditional_Expression then
1735 Cond : constant Node_Id := First (Expressions (P));
1736 Texp : constant Node_Id := Next (Cond);
1737 Fexp : constant Node_Id := Next (Texp);
1740 if Compile_Time_Known_Value (Cond) then
1742 -- Condition is True and we are in the right operand
1744 if Is_True (Expr_Value (Cond))
1745 and then OldP = Fexp
1750 -- Condition is False and we are in the left operand
1752 elsif Is_False (Expr_Value (Cond))
1753 and then OldP = Texp
1761 -- Special case for component association in aggregates, where
1762 -- we want to keep climbing up to the parent aggregate.
1764 elsif Nkind (P) = N_Component_Association
1765 and then Nkind (Parent (P)) = N_Aggregate
1769 -- Keep going if within subexpression
1772 exit when Nkind (P) not in N_Subexpr;
1777 if Present (Ent) then
1778 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1780 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1784 if Inside_Init_Proc then
1786 ("\?& will be raised for objects of this type",
1787 N, Standard_Constraint_Error, Eloc);
1790 ("\?& will be raised at run time",
1791 N, Standard_Constraint_Error, Eloc);
1796 ("\static expression fails Constraint_Check", Eloc);
1797 Set_Error_Posted (N);
1803 end Compile_Time_Constraint_Error;
1805 -----------------------
1806 -- Conditional_Delay --
1807 -----------------------
1809 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1811 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1812 Set_Has_Delayed_Freeze (New_Ent);
1814 end Conditional_Delay;
1816 -------------------------
1817 -- Copy_Parameter_List --
1818 -------------------------
1820 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1821 Loc : constant Source_Ptr := Sloc (Subp_Id);
1826 if No (First_Formal (Subp_Id)) then
1830 Formal := First_Formal (Subp_Id);
1831 while Present (Formal) loop
1833 (Make_Parameter_Specification (Loc,
1834 Defining_Identifier =>
1835 Make_Defining_Identifier (Sloc (Formal),
1836 Chars => Chars (Formal)),
1837 In_Present => In_Present (Parent (Formal)),
1838 Out_Present => Out_Present (Parent (Formal)),
1840 New_Reference_To (Etype (Formal), Loc),
1842 New_Copy_Tree (Expression (Parent (Formal)))),
1845 Next_Formal (Formal);
1850 end Copy_Parameter_List;
1852 --------------------
1853 -- Current_Entity --
1854 --------------------
1856 -- The currently visible definition for a given identifier is the
1857 -- one most chained at the start of the visibility chain, i.e. the
1858 -- one that is referenced by the Node_Id value of the name of the
1859 -- given identifier.
1861 function Current_Entity (N : Node_Id) return Entity_Id is
1863 return Get_Name_Entity_Id (Chars (N));
1866 -----------------------------
1867 -- Current_Entity_In_Scope --
1868 -----------------------------
1870 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1872 CS : constant Entity_Id := Current_Scope;
1874 Transient_Case : constant Boolean := Scope_Is_Transient;
1877 E := Get_Name_Entity_Id (Chars (N));
1879 and then Scope (E) /= CS
1880 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1886 end Current_Entity_In_Scope;
1892 function Current_Scope return Entity_Id is
1894 if Scope_Stack.Last = -1 then
1895 return Standard_Standard;
1898 C : constant Entity_Id :=
1899 Scope_Stack.Table (Scope_Stack.Last).Entity;
1904 return Standard_Standard;
1910 ------------------------
1911 -- Current_Subprogram --
1912 ------------------------
1914 function Current_Subprogram return Entity_Id is
1915 Scop : constant Entity_Id := Current_Scope;
1917 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1920 return Enclosing_Subprogram (Scop);
1922 end Current_Subprogram;
1924 ---------------------
1925 -- Defining_Entity --
1926 ---------------------
1928 function Defining_Entity (N : Node_Id) return Entity_Id is
1929 K : constant Node_Kind := Nkind (N);
1930 Err : Entity_Id := Empty;
1935 N_Subprogram_Declaration |
1936 N_Abstract_Subprogram_Declaration |
1938 N_Package_Declaration |
1939 N_Subprogram_Renaming_Declaration |
1940 N_Subprogram_Body_Stub |
1941 N_Generic_Subprogram_Declaration |
1942 N_Generic_Package_Declaration |
1943 N_Formal_Subprogram_Declaration
1945 return Defining_Entity (Specification (N));
1948 N_Component_Declaration |
1949 N_Defining_Program_Unit_Name |
1950 N_Discriminant_Specification |
1952 N_Entry_Declaration |
1953 N_Entry_Index_Specification |
1954 N_Exception_Declaration |
1955 N_Exception_Renaming_Declaration |
1956 N_Formal_Object_Declaration |
1957 N_Formal_Package_Declaration |
1958 N_Formal_Type_Declaration |
1959 N_Full_Type_Declaration |
1960 N_Implicit_Label_Declaration |
1961 N_Incomplete_Type_Declaration |
1962 N_Loop_Parameter_Specification |
1963 N_Number_Declaration |
1964 N_Object_Declaration |
1965 N_Object_Renaming_Declaration |
1966 N_Package_Body_Stub |
1967 N_Parameter_Specification |
1968 N_Private_Extension_Declaration |
1969 N_Private_Type_Declaration |
1971 N_Protected_Body_Stub |
1972 N_Protected_Type_Declaration |
1973 N_Single_Protected_Declaration |
1974 N_Single_Task_Declaration |
1975 N_Subtype_Declaration |
1978 N_Task_Type_Declaration
1980 return Defining_Identifier (N);
1983 return Defining_Entity (Proper_Body (N));
1986 N_Function_Instantiation |
1987 N_Function_Specification |
1988 N_Generic_Function_Renaming_Declaration |
1989 N_Generic_Package_Renaming_Declaration |
1990 N_Generic_Procedure_Renaming_Declaration |
1992 N_Package_Instantiation |
1993 N_Package_Renaming_Declaration |
1994 N_Package_Specification |
1995 N_Procedure_Instantiation |
1996 N_Procedure_Specification
1999 Nam : constant Node_Id := Defining_Unit_Name (N);
2002 if Nkind (Nam) in N_Entity then
2005 -- For Error, make up a name and attach to declaration
2006 -- so we can continue semantic analysis
2008 elsif Nam = Error then
2010 Make_Defining_Identifier (Sloc (N),
2011 Chars => New_Internal_Name ('T'));
2012 Set_Defining_Unit_Name (N, Err);
2015 -- If not an entity, get defining identifier
2018 return Defining_Identifier (Nam);
2022 when N_Block_Statement =>
2023 return Entity (Identifier (N));
2026 raise Program_Error;
2029 end Defining_Entity;
2031 --------------------------
2032 -- Denotes_Discriminant --
2033 --------------------------
2035 function Denotes_Discriminant
2037 Check_Concurrent : Boolean := False) return Boolean
2041 if not Is_Entity_Name (N)
2042 or else No (Entity (N))
2049 -- If we are checking for a protected type, the discriminant may have
2050 -- been rewritten as the corresponding discriminal of the original type
2051 -- or of the corresponding concurrent record, depending on whether we
2052 -- are in the spec or body of the protected type.
2054 return Ekind (E) = E_Discriminant
2057 and then Ekind (E) = E_In_Parameter
2058 and then Present (Discriminal_Link (E))
2060 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2062 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2064 end Denotes_Discriminant;
2066 ----------------------
2067 -- Denotes_Variable --
2068 ----------------------
2070 function Denotes_Variable (N : Node_Id) return Boolean is
2072 return Is_Variable (N) and then Paren_Count (N) = 0;
2073 end Denotes_Variable;
2075 -----------------------------
2076 -- Depends_On_Discriminant --
2077 -----------------------------
2079 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2084 Get_Index_Bounds (N, L, H);
2085 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2086 end Depends_On_Discriminant;
2088 -------------------------
2089 -- Designate_Same_Unit --
2090 -------------------------
2092 function Designate_Same_Unit
2094 Name2 : Node_Id) return Boolean
2096 K1 : constant Node_Kind := Nkind (Name1);
2097 K2 : constant Node_Kind := Nkind (Name2);
2099 function Prefix_Node (N : Node_Id) return Node_Id;
2100 -- Returns the parent unit name node of a defining program unit name
2101 -- or the prefix if N is a selected component or an expanded name.
2103 function Select_Node (N : Node_Id) return Node_Id;
2104 -- Returns the defining identifier node of a defining program unit
2105 -- name or the selector node if N is a selected component or an
2112 function Prefix_Node (N : Node_Id) return Node_Id is
2114 if Nkind (N) = N_Defining_Program_Unit_Name then
2126 function Select_Node (N : Node_Id) return Node_Id is
2128 if Nkind (N) = N_Defining_Program_Unit_Name then
2129 return Defining_Identifier (N);
2132 return Selector_Name (N);
2136 -- Start of processing for Designate_Next_Unit
2139 if (K1 = N_Identifier or else
2140 K1 = N_Defining_Identifier)
2142 (K2 = N_Identifier or else
2143 K2 = N_Defining_Identifier)
2145 return Chars (Name1) = Chars (Name2);
2148 (K1 = N_Expanded_Name or else
2149 K1 = N_Selected_Component or else
2150 K1 = N_Defining_Program_Unit_Name)
2152 (K2 = N_Expanded_Name or else
2153 K2 = N_Selected_Component or else
2154 K2 = N_Defining_Program_Unit_Name)
2157 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2159 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2164 end Designate_Same_Unit;
2166 ----------------------------
2167 -- Enclosing_Generic_Body --
2168 ----------------------------
2170 function Enclosing_Generic_Body
2171 (N : Node_Id) return Node_Id
2179 while Present (P) loop
2180 if Nkind (P) = N_Package_Body
2181 or else Nkind (P) = N_Subprogram_Body
2183 Spec := Corresponding_Spec (P);
2185 if Present (Spec) then
2186 Decl := Unit_Declaration_Node (Spec);
2188 if Nkind (Decl) = N_Generic_Package_Declaration
2189 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2200 end Enclosing_Generic_Body;
2202 ----------------------------
2203 -- Enclosing_Generic_Unit --
2204 ----------------------------
2206 function Enclosing_Generic_Unit
2207 (N : Node_Id) return Node_Id
2215 while Present (P) loop
2216 if Nkind (P) = N_Generic_Package_Declaration
2217 or else Nkind (P) = N_Generic_Subprogram_Declaration
2221 elsif Nkind (P) = N_Package_Body
2222 or else Nkind (P) = N_Subprogram_Body
2224 Spec := Corresponding_Spec (P);
2226 if Present (Spec) then
2227 Decl := Unit_Declaration_Node (Spec);
2229 if Nkind (Decl) = N_Generic_Package_Declaration
2230 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2241 end Enclosing_Generic_Unit;
2243 -------------------------------
2244 -- Enclosing_Lib_Unit_Entity --
2245 -------------------------------
2247 function Enclosing_Lib_Unit_Entity return Entity_Id is
2248 Unit_Entity : Entity_Id;
2251 -- Look for enclosing library unit entity by following scope links.
2252 -- Equivalent to, but faster than indexing through the scope stack.
2254 Unit_Entity := Current_Scope;
2255 while (Present (Scope (Unit_Entity))
2256 and then Scope (Unit_Entity) /= Standard_Standard)
2257 and not Is_Child_Unit (Unit_Entity)
2259 Unit_Entity := Scope (Unit_Entity);
2263 end Enclosing_Lib_Unit_Entity;
2265 -----------------------------
2266 -- Enclosing_Lib_Unit_Node --
2267 -----------------------------
2269 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2270 Current_Node : Node_Id;
2274 while Present (Current_Node)
2275 and then Nkind (Current_Node) /= N_Compilation_Unit
2277 Current_Node := Parent (Current_Node);
2280 if Nkind (Current_Node) /= N_Compilation_Unit then
2284 return Current_Node;
2285 end Enclosing_Lib_Unit_Node;
2287 --------------------------
2288 -- Enclosing_Subprogram --
2289 --------------------------
2291 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2292 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2295 if Dynamic_Scope = Standard_Standard then
2298 elsif Dynamic_Scope = Empty then
2301 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2302 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2304 elsif Ekind (Dynamic_Scope) = E_Block
2305 or else Ekind (Dynamic_Scope) = E_Return_Statement
2307 return Enclosing_Subprogram (Dynamic_Scope);
2309 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2310 return Get_Task_Body_Procedure (Dynamic_Scope);
2312 elsif Convention (Dynamic_Scope) = Convention_Protected then
2313 return Protected_Body_Subprogram (Dynamic_Scope);
2316 return Dynamic_Scope;
2318 end Enclosing_Subprogram;
2320 ------------------------
2321 -- Ensure_Freeze_Node --
2322 ------------------------
2324 procedure Ensure_Freeze_Node (E : Entity_Id) is
2328 if No (Freeze_Node (E)) then
2329 FN := Make_Freeze_Entity (Sloc (E));
2330 Set_Has_Delayed_Freeze (E);
2331 Set_Freeze_Node (E, FN);
2332 Set_Access_Types_To_Process (FN, No_Elist);
2333 Set_TSS_Elist (FN, No_Elist);
2336 end Ensure_Freeze_Node;
2342 procedure Enter_Name (Def_Id : Entity_Id) is
2343 C : constant Entity_Id := Current_Entity (Def_Id);
2344 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2345 S : constant Entity_Id := Current_Scope;
2348 Generate_Definition (Def_Id);
2350 -- Add new name to current scope declarations. Check for duplicate
2351 -- declaration, which may or may not be a genuine error.
2355 -- Case of previous entity entered because of a missing declaration
2356 -- or else a bad subtype indication. Best is to use the new entity,
2357 -- and make the previous one invisible.
2359 if Etype (E) = Any_Type then
2360 Set_Is_Immediately_Visible (E, False);
2362 -- Case of renaming declaration constructed for package instances.
2363 -- if there is an explicit declaration with the same identifier,
2364 -- the renaming is not immediately visible any longer, but remains
2365 -- visible through selected component notation.
2367 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2368 and then not Comes_From_Source (E)
2370 Set_Is_Immediately_Visible (E, False);
2372 -- The new entity may be the package renaming, which has the same
2373 -- same name as a generic formal which has been seen already.
2375 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2376 and then not Comes_From_Source (Def_Id)
2378 Set_Is_Immediately_Visible (E, False);
2380 -- For a fat pointer corresponding to a remote access to subprogram,
2381 -- we use the same identifier as the RAS type, so that the proper
2382 -- name appears in the stub. This type is only retrieved through
2383 -- the RAS type and never by visibility, and is not added to the
2384 -- visibility list (see below).
2386 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2387 and then Present (Corresponding_Remote_Type (Def_Id))
2391 -- A controller component for a type extension overrides the
2392 -- inherited component.
2394 elsif Chars (E) = Name_uController then
2397 -- Case of an implicit operation or derived literal. The new entity
2398 -- hides the implicit one, which is removed from all visibility,
2399 -- i.e. the entity list of its scope, and homonym chain of its name.
2401 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2402 or else Is_Internal (E)
2406 Prev_Vis : Entity_Id;
2407 Decl : constant Node_Id := Parent (E);
2410 -- If E is an implicit declaration, it cannot be the first
2411 -- entity in the scope.
2413 Prev := First_Entity (Current_Scope);
2414 while Present (Prev)
2415 and then Next_Entity (Prev) /= E
2422 -- If E is not on the entity chain of the current scope,
2423 -- it is an implicit declaration in the generic formal
2424 -- part of a generic subprogram. When analyzing the body,
2425 -- the generic formals are visible but not on the entity
2426 -- chain of the subprogram. The new entity will become
2427 -- the visible one in the body.
2430 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2434 Set_Next_Entity (Prev, Next_Entity (E));
2436 if No (Next_Entity (Prev)) then
2437 Set_Last_Entity (Current_Scope, Prev);
2440 if E = Current_Entity (E) then
2444 Prev_Vis := Current_Entity (E);
2445 while Homonym (Prev_Vis) /= E loop
2446 Prev_Vis := Homonym (Prev_Vis);
2450 if Present (Prev_Vis) then
2452 -- Skip E in the visibility chain
2454 Set_Homonym (Prev_Vis, Homonym (E));
2457 Set_Name_Entity_Id (Chars (E), Homonym (E));
2462 -- This section of code could use a comment ???
2464 elsif Present (Etype (E))
2465 and then Is_Concurrent_Type (Etype (E))
2470 -- If the homograph is a protected component renaming, it should not
2471 -- be hiding the current entity. Such renamings are treated as weak
2474 elsif Is_Prival (E) then
2475 Set_Is_Immediately_Visible (E, False);
2477 -- In this case the current entity is a protected component renaming.
2478 -- Perform minimal decoration by setting the scope and return since
2479 -- the prival should not be hiding other visible entities.
2481 elsif Is_Prival (Def_Id) then
2482 Set_Scope (Def_Id, Current_Scope);
2485 -- Analogous to privals, the discriminal generated for an entry
2486 -- index parameter acts as a weak declaration. Perform minimal
2487 -- decoration to avoid bogus errors.
2489 elsif Is_Discriminal (Def_Id)
2490 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2492 Set_Scope (Def_Id, Current_Scope);
2495 -- In the body or private part of an instance, a type extension
2496 -- may introduce a component with the same name as that of an
2497 -- actual. The legality rule is not enforced, but the semantics
2498 -- of the full type with two components of the same name are not
2499 -- clear at this point ???
2501 elsif In_Instance_Not_Visible then
2504 -- When compiling a package body, some child units may have become
2505 -- visible. They cannot conflict with local entities that hide them.
2507 elsif Is_Child_Unit (E)
2508 and then In_Open_Scopes (Scope (E))
2509 and then not Is_Immediately_Visible (E)
2513 -- Conversely, with front-end inlining we may compile the parent
2514 -- body first, and a child unit subsequently. The context is now
2515 -- the parent spec, and body entities are not visible.
2517 elsif Is_Child_Unit (Def_Id)
2518 and then Is_Package_Body_Entity (E)
2519 and then not In_Package_Body (Current_Scope)
2523 -- Case of genuine duplicate declaration
2526 Error_Msg_Sloc := Sloc (E);
2528 -- If the previous declaration is an incomplete type declaration
2529 -- this may be an attempt to complete it with a private type.
2530 -- The following avoids confusing cascaded errors.
2532 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2533 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2536 ("incomplete type cannot be completed with a private " &
2537 "declaration", Parent (Def_Id));
2538 Set_Is_Immediately_Visible (E, False);
2539 Set_Full_View (E, Def_Id);
2541 -- An inherited component of a record conflicts with a new
2542 -- discriminant. The discriminant is inserted first in the scope,
2543 -- but the error should be posted on it, not on the component.
2545 elsif Ekind (E) = E_Discriminant
2546 and then Present (Scope (Def_Id))
2547 and then Scope (Def_Id) /= Current_Scope
2549 Error_Msg_Sloc := Sloc (Def_Id);
2550 Error_Msg_N ("& conflicts with declaration#", E);
2553 -- If the name of the unit appears in its own context clause,
2554 -- a dummy package with the name has already been created, and
2555 -- the error emitted. Try to continue quietly.
2557 elsif Error_Posted (E)
2558 and then Sloc (E) = No_Location
2559 and then Nkind (Parent (E)) = N_Package_Specification
2560 and then Current_Scope = Standard_Standard
2562 Set_Scope (Def_Id, Current_Scope);
2566 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2568 -- Avoid cascaded messages with duplicate components in
2571 if Ekind (E) = E_Component
2572 or else Ekind (E) = E_Discriminant
2578 if Nkind (Parent (Parent (Def_Id))) =
2579 N_Generic_Subprogram_Declaration
2581 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2583 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2586 -- If entity is in standard, then we are in trouble, because
2587 -- it means that we have a library package with a duplicated
2588 -- name. That's hard to recover from, so abort!
2590 if S = Standard_Standard then
2591 raise Unrecoverable_Error;
2593 -- Otherwise we continue with the declaration. Having two
2594 -- identical declarations should not cause us too much trouble!
2602 -- If we fall through, declaration is OK , or OK enough to continue
2604 -- If Def_Id is a discriminant or a record component we are in the
2605 -- midst of inheriting components in a derived record definition.
2606 -- Preserve their Ekind and Etype.
2608 if Ekind (Def_Id) = E_Discriminant
2609 or else Ekind (Def_Id) = E_Component
2613 -- If a type is already set, leave it alone (happens whey a type
2614 -- declaration is reanalyzed following a call to the optimizer)
2616 elsif Present (Etype (Def_Id)) then
2619 -- Otherwise, the kind E_Void insures that premature uses of the entity
2620 -- will be detected. Any_Type insures that no cascaded errors will occur
2623 Set_Ekind (Def_Id, E_Void);
2624 Set_Etype (Def_Id, Any_Type);
2627 -- Inherited discriminants and components in derived record types are
2628 -- immediately visible. Itypes are not.
2630 if Ekind (Def_Id) = E_Discriminant
2631 or else Ekind (Def_Id) = E_Component
2632 or else (No (Corresponding_Remote_Type (Def_Id))
2633 and then not Is_Itype (Def_Id))
2635 Set_Is_Immediately_Visible (Def_Id);
2636 Set_Current_Entity (Def_Id);
2639 Set_Homonym (Def_Id, C);
2640 Append_Entity (Def_Id, S);
2641 Set_Public_Status (Def_Id);
2643 -- Warn if new entity hides an old one
2645 if Warn_On_Hiding and then Present (C)
2647 -- Don't warn for record components since they always have a well
2648 -- defined scope which does not confuse other uses. Note that in
2649 -- some cases, Ekind has not been set yet.
2651 and then Ekind (C) /= E_Component
2652 and then Ekind (C) /= E_Discriminant
2653 and then Nkind (Parent (C)) /= N_Component_Declaration
2654 and then Ekind (Def_Id) /= E_Component
2655 and then Ekind (Def_Id) /= E_Discriminant
2656 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2658 -- Don't warn for one character variables. It is too common to use
2659 -- such variables as locals and will just cause too many false hits.
2661 and then Length_Of_Name (Chars (C)) /= 1
2663 -- Don't warn for non-source entities
2665 and then Comes_From_Source (C)
2666 and then Comes_From_Source (Def_Id)
2668 -- Don't warn unless entity in question is in extended main source
2670 and then In_Extended_Main_Source_Unit (Def_Id)
2672 -- Finally, the hidden entity must be either immediately visible
2673 -- or use visible (from a used package)
2676 (Is_Immediately_Visible (C)
2678 Is_Potentially_Use_Visible (C))
2680 Error_Msg_Sloc := Sloc (C);
2681 Error_Msg_N ("declaration hides &#?", Def_Id);
2685 --------------------------
2686 -- Explain_Limited_Type --
2687 --------------------------
2689 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2693 -- For array, component type must be limited
2695 if Is_Array_Type (T) then
2696 Error_Msg_Node_2 := T;
2698 ("\component type& of type& is limited", N, Component_Type (T));
2699 Explain_Limited_Type (Component_Type (T), N);
2701 elsif Is_Record_Type (T) then
2703 -- No need for extra messages if explicit limited record
2705 if Is_Limited_Record (Base_Type (T)) then
2709 -- Otherwise find a limited component. Check only components that
2710 -- come from source, or inherited components that appear in the
2711 -- source of the ancestor.
2713 C := First_Component (T);
2714 while Present (C) loop
2715 if Is_Limited_Type (Etype (C))
2717 (Comes_From_Source (C)
2719 (Present (Original_Record_Component (C))
2721 Comes_From_Source (Original_Record_Component (C))))
2723 Error_Msg_Node_2 := T;
2724 Error_Msg_NE ("\component& of type& has limited type", N, C);
2725 Explain_Limited_Type (Etype (C), N);
2732 -- The type may be declared explicitly limited, even if no component
2733 -- of it is limited, in which case we fall out of the loop.
2736 end Explain_Limited_Type;
2742 procedure Find_Actual
2744 Formal : out Entity_Id;
2747 Parnt : constant Node_Id := Parent (N);
2751 if (Nkind (Parnt) = N_Indexed_Component
2753 Nkind (Parnt) = N_Selected_Component)
2754 and then N = Prefix (Parnt)
2756 Find_Actual (Parnt, Formal, Call);
2759 elsif Nkind (Parnt) = N_Parameter_Association
2760 and then N = Explicit_Actual_Parameter (Parnt)
2762 Call := Parent (Parnt);
2764 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2773 -- If we have a call to a subprogram look for the parameter. Note that
2774 -- we exclude overloaded calls, since we don't know enough to be sure
2775 -- of giving the right answer in this case.
2777 if Is_Entity_Name (Name (Call))
2778 and then Present (Entity (Name (Call)))
2779 and then Is_Overloadable (Entity (Name (Call)))
2780 and then not Is_Overloaded (Name (Call))
2782 -- Fall here if we are definitely a parameter
2784 Actual := First_Actual (Call);
2785 Formal := First_Formal (Entity (Name (Call)));
2786 while Present (Formal) and then Present (Actual) loop
2790 Actual := Next_Actual (Actual);
2791 Formal := Next_Formal (Formal);
2796 -- Fall through here if we did not find matching actual
2802 -------------------------------------
2803 -- Find_Corresponding_Discriminant --
2804 -------------------------------------
2806 function Find_Corresponding_Discriminant
2808 Typ : Entity_Id) return Entity_Id
2810 Par_Disc : Entity_Id;
2811 Old_Disc : Entity_Id;
2812 New_Disc : Entity_Id;
2815 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2817 -- The original type may currently be private, and the discriminant
2818 -- only appear on its full view.
2820 if Is_Private_Type (Scope (Par_Disc))
2821 and then not Has_Discriminants (Scope (Par_Disc))
2822 and then Present (Full_View (Scope (Par_Disc)))
2824 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2826 Old_Disc := First_Discriminant (Scope (Par_Disc));
2829 if Is_Class_Wide_Type (Typ) then
2830 New_Disc := First_Discriminant (Root_Type (Typ));
2832 New_Disc := First_Discriminant (Typ);
2835 while Present (Old_Disc) and then Present (New_Disc) loop
2836 if Old_Disc = Par_Disc then
2839 Next_Discriminant (Old_Disc);
2840 Next_Discriminant (New_Disc);
2844 -- Should always find it
2846 raise Program_Error;
2847 end Find_Corresponding_Discriminant;
2849 --------------------------
2850 -- Find_Overlaid_Object --
2851 --------------------------
2853 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2857 -- We are looking for one of the two following forms:
2859 -- for X'Address use Y'Address
2863 -- Const : constant Address := expr;
2865 -- for X'Address use Const;
2867 -- In the second case, the expr is either Y'Address, or recursively a
2868 -- constant that eventually references Y'Address.
2870 if Nkind (N) = N_Attribute_Definition_Clause
2871 and then Chars (N) = Name_Address
2873 -- This loop checks the form of the expression for Y'Address where Y
2874 -- is an object entity name. The first loop checks the original
2875 -- expression in the attribute definition clause. Subsequent loops
2876 -- check referenced constants.
2878 Expr := Expression (N);
2880 -- Check for Y'Address where Y is an object entity
2882 if Nkind (Expr) = N_Attribute_Reference
2883 and then Attribute_Name (Expr) = Name_Address
2884 and then Is_Entity_Name (Prefix (Expr))
2885 and then Is_Object (Entity (Prefix (Expr)))
2887 return Entity (Prefix (Expr));
2889 -- Check for Const where Const is a constant entity
2891 elsif Is_Entity_Name (Expr)
2892 and then Ekind (Entity (Expr)) = E_Constant
2894 Expr := Constant_Value (Entity (Expr));
2896 -- Anything else does not need checking
2905 end Find_Overlaid_Object;
2907 -------------------------
2908 -- Find_Parameter_Type --
2909 -------------------------
2911 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2913 if Nkind (Param) /= N_Parameter_Specification then
2916 -- For an access parameter, obtain the type from the formal entity
2917 -- itself, because access to subprogram nodes do not carry a type.
2918 -- Shouldn't we always use the formal entity ???
2920 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
2921 return Etype (Defining_Identifier (Param));
2924 return Etype (Parameter_Type (Param));
2926 end Find_Parameter_Type;
2928 -----------------------------
2929 -- Find_Static_Alternative --
2930 -----------------------------
2932 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2933 Expr : constant Node_Id := Expression (N);
2934 Val : constant Uint := Expr_Value (Expr);
2939 Alt := First (Alternatives (N));
2942 if Nkind (Alt) /= N_Pragma then
2943 Choice := First (Discrete_Choices (Alt));
2944 while Present (Choice) loop
2946 -- Others choice, always matches
2948 if Nkind (Choice) = N_Others_Choice then
2951 -- Range, check if value is in the range
2953 elsif Nkind (Choice) = N_Range then
2955 Val >= Expr_Value (Low_Bound (Choice))
2957 Val <= Expr_Value (High_Bound (Choice));
2959 -- Choice is a subtype name. Note that we know it must
2960 -- be a static subtype, since otherwise it would have
2961 -- been diagnosed as illegal.
2963 elsif Is_Entity_Name (Choice)
2964 and then Is_Type (Entity (Choice))
2966 exit Search when Is_In_Range (Expr, Etype (Choice),
2967 Assume_Valid => False);
2969 -- Choice is a subtype indication
2971 elsif Nkind (Choice) = N_Subtype_Indication then
2973 C : constant Node_Id := Constraint (Choice);
2974 R : constant Node_Id := Range_Expression (C);
2978 Val >= Expr_Value (Low_Bound (R))
2980 Val <= Expr_Value (High_Bound (R));
2983 -- Choice is a simple expression
2986 exit Search when Val = Expr_Value (Choice);
2994 pragma Assert (Present (Alt));
2997 -- The above loop *must* terminate by finding a match, since
2998 -- we know the case statement is valid, and the value of the
2999 -- expression is known at compile time. When we fall out of
3000 -- the loop, Alt points to the alternative that we know will
3001 -- be selected at run time.
3004 end Find_Static_Alternative;
3010 function First_Actual (Node : Node_Id) return Node_Id is
3014 if No (Parameter_Associations (Node)) then
3018 N := First (Parameter_Associations (Node));
3020 if Nkind (N) = N_Parameter_Association then
3021 return First_Named_Actual (Node);
3027 -------------------------
3028 -- Full_Qualified_Name --
3029 -------------------------
3031 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3033 pragma Warnings (Off, Res);
3035 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3036 -- Compute recursively the qualified name without NUL at the end
3038 ----------------------------------
3039 -- Internal_Full_Qualified_Name --
3040 ----------------------------------
3042 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3043 Ent : Entity_Id := E;
3044 Parent_Name : String_Id := No_String;
3047 -- Deals properly with child units
3049 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3050 Ent := Defining_Identifier (Ent);
3053 -- Compute qualification recursively (only "Standard" has no scope)
3055 if Present (Scope (Scope (Ent))) then
3056 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3059 -- Every entity should have a name except some expanded blocks
3060 -- don't bother about those.
3062 if Chars (Ent) = No_Name then
3066 -- Add a period between Name and qualification
3068 if Parent_Name /= No_String then
3069 Start_String (Parent_Name);
3070 Store_String_Char (Get_Char_Code ('.'));
3076 -- Generates the entity name in upper case
3078 Get_Decoded_Name_String (Chars (Ent));
3080 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3082 end Internal_Full_Qualified_Name;
3084 -- Start of processing for Full_Qualified_Name
3087 Res := Internal_Full_Qualified_Name (E);
3088 Store_String_Char (Get_Char_Code (ASCII.NUL));
3090 end Full_Qualified_Name;
3092 -----------------------
3093 -- Gather_Components --
3094 -----------------------
3096 procedure Gather_Components
3098 Comp_List : Node_Id;
3099 Governed_By : List_Id;
3101 Report_Errors : out Boolean)
3105 Discrete_Choice : Node_Id;
3106 Comp_Item : Node_Id;
3108 Discrim : Entity_Id;
3109 Discrim_Name : Node_Id;
3110 Discrim_Value : Node_Id;
3113 Report_Errors := False;
3115 if No (Comp_List) or else Null_Present (Comp_List) then
3118 elsif Present (Component_Items (Comp_List)) then
3119 Comp_Item := First (Component_Items (Comp_List));
3125 while Present (Comp_Item) loop
3127 -- Skip the tag of a tagged record, the interface tags, as well
3128 -- as all items that are not user components (anonymous types,
3129 -- rep clauses, Parent field, controller field).
3131 if Nkind (Comp_Item) = N_Component_Declaration then
3133 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3135 if not Is_Tag (Comp)
3136 and then Chars (Comp) /= Name_uParent
3137 and then Chars (Comp) /= Name_uController
3139 Append_Elmt (Comp, Into);
3147 if No (Variant_Part (Comp_List)) then
3150 Discrim_Name := Name (Variant_Part (Comp_List));
3151 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3154 -- Look for the discriminant that governs this variant part.
3155 -- The discriminant *must* be in the Governed_By List
3157 Assoc := First (Governed_By);
3158 Find_Constraint : loop
3159 Discrim := First (Choices (Assoc));
3160 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3161 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3163 Chars (Corresponding_Discriminant (Entity (Discrim)))
3164 = Chars (Discrim_Name))
3165 or else Chars (Original_Record_Component (Entity (Discrim)))
3166 = Chars (Discrim_Name);
3168 if No (Next (Assoc)) then
3169 if not Is_Constrained (Typ)
3170 and then Is_Derived_Type (Typ)
3171 and then Present (Stored_Constraint (Typ))
3173 -- If the type is a tagged type with inherited discriminants,
3174 -- use the stored constraint on the parent in order to find
3175 -- the values of discriminants that are otherwise hidden by an
3176 -- explicit constraint. Renamed discriminants are handled in
3179 -- If several parent discriminants are renamed by a single
3180 -- discriminant of the derived type, the call to obtain the
3181 -- Corresponding_Discriminant field only retrieves the last
3182 -- of them. We recover the constraint on the others from the
3183 -- Stored_Constraint as well.
3190 D := First_Discriminant (Etype (Typ));
3191 C := First_Elmt (Stored_Constraint (Typ));
3192 while Present (D) and then Present (C) loop
3193 if Chars (Discrim_Name) = Chars (D) then
3194 if Is_Entity_Name (Node (C))
3195 and then Entity (Node (C)) = Entity (Discrim)
3197 -- D is renamed by Discrim, whose value is given in
3204 Make_Component_Association (Sloc (Typ),
3206 (New_Occurrence_Of (D, Sloc (Typ))),
3207 Duplicate_Subexpr_No_Checks (Node (C)));
3209 exit Find_Constraint;
3212 Next_Discriminant (D);
3219 if No (Next (Assoc)) then
3220 Error_Msg_NE (" missing value for discriminant&",
3221 First (Governed_By), Discrim_Name);
3222 Report_Errors := True;
3227 end loop Find_Constraint;
3229 Discrim_Value := Expression (Assoc);
3231 if not Is_OK_Static_Expression (Discrim_Value) then
3233 ("value for discriminant & must be static!",
3234 Discrim_Value, Discrim);
3235 Why_Not_Static (Discrim_Value);
3236 Report_Errors := True;
3240 Search_For_Discriminant_Value : declare
3246 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3249 Find_Discrete_Value : while Present (Variant) loop
3250 Discrete_Choice := First (Discrete_Choices (Variant));
3251 while Present (Discrete_Choice) loop
3253 exit Find_Discrete_Value when
3254 Nkind (Discrete_Choice) = N_Others_Choice;
3256 Get_Index_Bounds (Discrete_Choice, Low, High);
3258 UI_Low := Expr_Value (Low);
3259 UI_High := Expr_Value (High);
3261 exit Find_Discrete_Value when
3262 UI_Low <= UI_Discrim_Value
3264 UI_High >= UI_Discrim_Value;
3266 Next (Discrete_Choice);
3269 Next_Non_Pragma (Variant);
3270 end loop Find_Discrete_Value;
3271 end Search_For_Discriminant_Value;
3273 if No (Variant) then
3275 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3276 Report_Errors := True;
3280 -- If we have found the corresponding choice, recursively add its
3281 -- components to the Into list.
3283 Gather_Components (Empty,
3284 Component_List (Variant), Governed_By, Into, Report_Errors);
3285 end Gather_Components;
3287 ------------------------
3288 -- Get_Actual_Subtype --
3289 ------------------------
3291 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3292 Typ : constant Entity_Id := Etype (N);
3293 Utyp : Entity_Id := Underlying_Type (Typ);
3302 -- If what we have is an identifier that references a subprogram
3303 -- formal, or a variable or constant object, then we get the actual
3304 -- subtype from the referenced entity if one has been built.
3306 if Nkind (N) = N_Identifier
3308 (Is_Formal (Entity (N))
3309 or else Ekind (Entity (N)) = E_Constant
3310 or else Ekind (Entity (N)) = E_Variable)
3311 and then Present (Actual_Subtype (Entity (N)))
3313 return Actual_Subtype (Entity (N));
3315 -- Actual subtype of unchecked union is always itself. We never need
3316 -- the "real" actual subtype. If we did, we couldn't get it anyway
3317 -- because the discriminant is not available. The restrictions on
3318 -- Unchecked_Union are designed to make sure that this is OK.
3320 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3323 -- Here for the unconstrained case, we must find actual subtype
3324 -- No actual subtype is available, so we must build it on the fly.
3326 -- Checking the type, not the underlying type, for constrainedness
3327 -- seems to be necessary. Maybe all the tests should be on the type???
3329 elsif (not Is_Constrained (Typ))
3330 and then (Is_Array_Type (Utyp)
3331 or else (Is_Record_Type (Utyp)
3332 and then Has_Discriminants (Utyp)))
3333 and then not Has_Unknown_Discriminants (Utyp)
3334 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3336 -- Nothing to do if in spec expression (why not???)
3338 if In_Spec_Expression then
3341 elsif Is_Private_Type (Typ)
3342 and then not Has_Discriminants (Typ)
3344 -- If the type has no discriminants, there is no subtype to
3345 -- build, even if the underlying type is discriminated.
3349 -- Else build the actual subtype
3352 Decl := Build_Actual_Subtype (Typ, N);
3353 Atyp := Defining_Identifier (Decl);
3355 -- If Build_Actual_Subtype generated a new declaration then use it
3359 -- The actual subtype is an Itype, so analyze the declaration,
3360 -- but do not attach it to the tree, to get the type defined.
3362 Set_Parent (Decl, N);
3363 Set_Is_Itype (Atyp);
3364 Analyze (Decl, Suppress => All_Checks);
3365 Set_Associated_Node_For_Itype (Atyp, N);
3366 Set_Has_Delayed_Freeze (Atyp, False);
3368 -- We need to freeze the actual subtype immediately. This is
3369 -- needed, because otherwise this Itype will not get frozen
3370 -- at all, and it is always safe to freeze on creation because
3371 -- any associated types must be frozen at this point.
3373 Freeze_Itype (Atyp, N);
3376 -- Otherwise we did not build a declaration, so return original
3383 -- For all remaining cases, the actual subtype is the same as
3384 -- the nominal type.
3389 end Get_Actual_Subtype;
3391 -------------------------------------
3392 -- Get_Actual_Subtype_If_Available --
3393 -------------------------------------
3395 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3396 Typ : constant Entity_Id := Etype (N);
3399 -- If what we have is an identifier that references a subprogram
3400 -- formal, or a variable or constant object, then we get the actual
3401 -- subtype from the referenced entity if one has been built.
3403 if Nkind (N) = N_Identifier
3405 (Is_Formal (Entity (N))
3406 or else Ekind (Entity (N)) = E_Constant
3407 or else Ekind (Entity (N)) = E_Variable)
3408 and then Present (Actual_Subtype (Entity (N)))
3410 return Actual_Subtype (Entity (N));
3412 -- Otherwise the Etype of N is returned unchanged
3417 end Get_Actual_Subtype_If_Available;
3419 -------------------------------
3420 -- Get_Default_External_Name --
3421 -------------------------------
3423 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3425 Get_Decoded_Name_String (Chars (E));
3427 if Opt.External_Name_Imp_Casing = Uppercase then
3428 Set_Casing (All_Upper_Case);
3430 Set_Casing (All_Lower_Case);
3434 Make_String_Literal (Sloc (E),
3435 Strval => String_From_Name_Buffer);
3436 end Get_Default_External_Name;
3438 ---------------------------
3439 -- Get_Enum_Lit_From_Pos --
3440 ---------------------------
3442 function Get_Enum_Lit_From_Pos
3445 Loc : Source_Ptr) return Node_Id
3450 -- In the case where the literal is of type Character, Wide_Character
3451 -- or Wide_Wide_Character or of a type derived from them, there needs
3452 -- to be some special handling since there is no explicit chain of
3453 -- literals to search. Instead, an N_Character_Literal node is created
3454 -- with the appropriate Char_Code and Chars fields.
3456 if Is_Standard_Character_Type (T) then
3457 Set_Character_Literal_Name (UI_To_CC (Pos));
3459 Make_Character_Literal (Loc,
3461 Char_Literal_Value => Pos);
3463 -- For all other cases, we have a complete table of literals, and
3464 -- we simply iterate through the chain of literal until the one
3465 -- with the desired position value is found.
3469 Lit := First_Literal (Base_Type (T));
3470 for J in 1 .. UI_To_Int (Pos) loop
3474 return New_Occurrence_Of (Lit, Loc);
3476 end Get_Enum_Lit_From_Pos;
3478 ------------------------
3479 -- Get_Generic_Entity --
3480 ------------------------
3482 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3483 Ent : constant Entity_Id := Entity (Name (N));
3485 if Present (Renamed_Object (Ent)) then
3486 return Renamed_Object (Ent);
3490 end Get_Generic_Entity;
3492 ----------------------
3493 -- Get_Index_Bounds --
3494 ----------------------
3496 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3497 Kind : constant Node_Kind := Nkind (N);
3501 if Kind = N_Range then
3503 H := High_Bound (N);
3505 elsif Kind = N_Subtype_Indication then
3506 R := Range_Expression (Constraint (N));
3514 L := Low_Bound (Range_Expression (Constraint (N)));
3515 H := High_Bound (Range_Expression (Constraint (N)));
3518 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3519 if Error_Posted (Scalar_Range (Entity (N))) then
3523 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3524 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3527 L := Low_Bound (Scalar_Range (Entity (N)));
3528 H := High_Bound (Scalar_Range (Entity (N)));
3532 -- N is an expression, indicating a range with one value
3537 end Get_Index_Bounds;
3539 ----------------------------------
3540 -- Get_Library_Unit_Name_string --
3541 ----------------------------------
3543 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3544 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3547 Get_Unit_Name_String (Unit_Name_Id);
3549 -- Remove seven last character (" (spec)" or " (body)")
3551 Name_Len := Name_Len - 7;
3552 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3553 end Get_Library_Unit_Name_String;
3555 ------------------------
3556 -- Get_Name_Entity_Id --
3557 ------------------------
3559 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3561 return Entity_Id (Get_Name_Table_Info (Id));
3562 end Get_Name_Entity_Id;
3568 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3570 return Get_Pragma_Id (Pragma_Name (N));
3573 ---------------------------
3574 -- Get_Referenced_Object --
3575 ---------------------------
3577 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3582 while Is_Entity_Name (R)
3583 and then Present (Renamed_Object (Entity (R)))
3585 R := Renamed_Object (Entity (R));
3589 end Get_Referenced_Object;
3591 ------------------------
3592 -- Get_Renamed_Entity --
3593 ------------------------
3595 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3600 while Present (Renamed_Entity (R)) loop
3601 R := Renamed_Entity (R);
3605 end Get_Renamed_Entity;
3607 -------------------------
3608 -- Get_Subprogram_Body --
3609 -------------------------
3611 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3615 Decl := Unit_Declaration_Node (E);
3617 if Nkind (Decl) = N_Subprogram_Body then
3620 -- The below comment is bad, because it is possible for
3621 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3623 else -- Nkind (Decl) = N_Subprogram_Declaration
3625 if Present (Corresponding_Body (Decl)) then
3626 return Unit_Declaration_Node (Corresponding_Body (Decl));
3628 -- Imported subprogram case
3634 end Get_Subprogram_Body;
3636 ---------------------------
3637 -- Get_Subprogram_Entity --
3638 ---------------------------
3640 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3645 if Nkind (Nod) = N_Accept_Statement then
3646 Nam := Entry_Direct_Name (Nod);
3648 -- For an entry call, the prefix of the call is a selected component.
3649 -- Need additional code for internal calls ???
3651 elsif Nkind (Nod) = N_Entry_Call_Statement then
3652 if Nkind (Name (Nod)) = N_Selected_Component then
3653 Nam := Entity (Selector_Name (Name (Nod)));
3662 if Nkind (Nam) = N_Explicit_Dereference then
3663 Proc := Etype (Prefix (Nam));
3664 elsif Is_Entity_Name (Nam) then
3665 Proc := Entity (Nam);
3670 if Is_Object (Proc) then
3671 Proc := Etype (Proc);
3674 if Ekind (Proc) = E_Access_Subprogram_Type then
3675 Proc := Directly_Designated_Type (Proc);
3678 if not Is_Subprogram (Proc)
3679 and then Ekind (Proc) /= E_Subprogram_Type
3685 end Get_Subprogram_Entity;
3687 -----------------------------
3688 -- Get_Task_Body_Procedure --
3689 -----------------------------
3691 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3693 -- Note: A task type may be the completion of a private type with
3694 -- discriminants. When performing elaboration checks on a task
3695 -- declaration, the current view of the type may be the private one,
3696 -- and the procedure that holds the body of the task is held in its
3699 -- This is an odd function, why not have Task_Body_Procedure do
3700 -- the following digging???
3702 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3703 end Get_Task_Body_Procedure;
3705 -----------------------
3706 -- Has_Access_Values --
3707 -----------------------
3709 function Has_Access_Values (T : Entity_Id) return Boolean is
3710 Typ : constant Entity_Id := Underlying_Type (T);
3713 -- Case of a private type which is not completed yet. This can only
3714 -- happen in the case of a generic format type appearing directly, or
3715 -- as a component of the type to which this function is being applied
3716 -- at the top level. Return False in this case, since we certainly do
3717 -- not know that the type contains access types.
3722 elsif Is_Access_Type (Typ) then
3725 elsif Is_Array_Type (Typ) then
3726 return Has_Access_Values (Component_Type (Typ));
3728 elsif Is_Record_Type (Typ) then
3733 -- Loop to Check components
3735 Comp := First_Component_Or_Discriminant (Typ);
3736 while Present (Comp) loop
3738 -- Check for access component, tag field does not count, even
3739 -- though it is implemented internally using an access type.
3741 if Has_Access_Values (Etype (Comp))
3742 and then Chars (Comp) /= Name_uTag
3747 Next_Component_Or_Discriminant (Comp);
3756 end Has_Access_Values;
3758 ------------------------------
3759 -- Has_Compatible_Alignment --
3760 ------------------------------
3762 function Has_Compatible_Alignment
3764 Expr : Node_Id) return Alignment_Result
3766 function Has_Compatible_Alignment_Internal
3769 Default : Alignment_Result) return Alignment_Result;
3770 -- This is the internal recursive function that actually does the work.
3771 -- There is one additional parameter, which says what the result should
3772 -- be if no alignment information is found, and there is no definite
3773 -- indication of compatible alignments. At the outer level, this is set
3774 -- to Unknown, but for internal recursive calls in the case where types
3775 -- are known to be correct, it is set to Known_Compatible.
3777 ---------------------------------------
3778 -- Has_Compatible_Alignment_Internal --
3779 ---------------------------------------
3781 function Has_Compatible_Alignment_Internal
3784 Default : Alignment_Result) return Alignment_Result
3786 Result : Alignment_Result := Known_Compatible;
3787 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3788 -- Note that once a value of Known_Incompatible is set, it is sticky
3789 -- and does not get changed to Unknown (the value in Result only gets
3790 -- worse as we go along, never better).
3792 procedure Check_Offset (Offs : Uint);
3793 -- Called when Expr is a selected or indexed component with Offs set
3794 -- to resp Component_First_Bit or Component_Size. Checks that if the
3795 -- offset is specified it is compatible with the object alignment
3796 -- requirements. The value in Result is modified accordingly.
3798 procedure Check_Prefix;
3799 -- Checks the prefix recursively in the case where the expression
3800 -- is an indexed or selected component.
3802 procedure Set_Result (R : Alignment_Result);
3803 -- If R represents a worse outcome (unknown instead of known
3804 -- compatible, or known incompatible), then set Result to R.
3810 procedure Check_Offset (Offs : Uint) is
3812 -- Unspecified or zero offset is always OK
3814 if Offs = No_Uint or else Offs = Uint_0 then
3817 -- If we do not know required alignment, any non-zero offset is
3818 -- a potential problem (but certainly may be OK, so result is
3821 elsif Unknown_Alignment (Obj) then
3822 Set_Result (Unknown);
3824 -- If we know the required alignment, see if offset is compatible
3827 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3828 Set_Result (Known_Incompatible);
3837 procedure Check_Prefix is
3839 -- The subtlety here is that in doing a recursive call to check
3840 -- the prefix, we have to decide what to do in the case where we
3841 -- don't find any specific indication of an alignment problem.
3843 -- At the outer level, we normally set Unknown as the result in
3844 -- this case, since we can only set Known_Compatible if we really
3845 -- know that the alignment value is OK, but for the recursive
3846 -- call, in the case where the types match, and we have not
3847 -- specified a peculiar alignment for the object, we are only
3848 -- concerned about suspicious rep clauses, the default case does
3849 -- not affect us, since the compiler will, in the absence of such
3850 -- rep clauses, ensure that the alignment is correct.
3852 if Default = Known_Compatible
3854 (Etype (Obj) = Etype (Expr)
3855 and then (Unknown_Alignment (Obj)
3857 Alignment (Obj) = Alignment (Etype (Obj))))
3860 (Has_Compatible_Alignment_Internal
3861 (Obj, Prefix (Expr), Known_Compatible));
3863 -- In all other cases, we need a full check on the prefix
3867 (Has_Compatible_Alignment_Internal
3868 (Obj, Prefix (Expr), Unknown));
3876 procedure Set_Result (R : Alignment_Result) is
3883 -- Start of processing for Has_Compatible_Alignment_Internal
3886 -- If Expr is a selected component, we must make sure there is no
3887 -- potentially troublesome component clause, and that the record is
3890 if Nkind (Expr) = N_Selected_Component then
3892 -- Packed record always generate unknown alignment
3894 if Is_Packed (Etype (Prefix (Expr))) then
3895 Set_Result (Unknown);
3898 -- Check possible bad component offset and check prefix
3901 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3904 -- If Expr is an indexed component, we must make sure there is no
3905 -- potentially troublesome Component_Size clause and that the array
3906 -- is not bit-packed.
3908 elsif Nkind (Expr) = N_Indexed_Component then
3910 -- Bit packed array always generates unknown alignment
3912 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3913 Set_Result (Unknown);
3916 -- Check possible bad component size and check prefix
3918 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3922 -- Case where we know the alignment of the object
3924 if Known_Alignment (Obj) then
3926 ObjA : constant Uint := Alignment (Obj);
3927 ExpA : Uint := No_Uint;
3928 SizA : Uint := No_Uint;
3931 -- If alignment of Obj is 1, then we are always OK
3934 Set_Result (Known_Compatible);
3936 -- Alignment of Obj is greater than 1, so we need to check
3939 -- See if Expr is an object with known alignment
3941 if Is_Entity_Name (Expr)
3942 and then Known_Alignment (Entity (Expr))
3944 ExpA := Alignment (Entity (Expr));
3946 -- Otherwise, we can use the alignment of the type of
3947 -- Expr given that we already checked for
3948 -- discombobulating rep clauses for the cases of indexed
3949 -- and selected components above.
3951 elsif Known_Alignment (Etype (Expr)) then
3952 ExpA := Alignment (Etype (Expr));
3955 -- If we got an alignment, see if it is acceptable
3957 if ExpA /= No_Uint then
3959 Set_Result (Known_Incompatible);
3962 -- Case of Expr alignment unknown
3965 Set_Result (Default);
3968 -- See if size is given. If so, check that it is not too
3969 -- small for the required alignment.
3970 -- See if Expr is an object with known alignment
3972 if Is_Entity_Name (Expr)
3973 and then Known_Static_Esize (Entity (Expr))
3975 SizA := Esize (Entity (Expr));
3977 -- Otherwise, we check the object size of the Expr type
3979 elsif Known_Static_Esize (Etype (Expr)) then
3980 SizA := Esize (Etype (Expr));
3983 -- If we got a size, see if it is a multiple of the Obj
3984 -- alignment, if not, then the alignment cannot be
3985 -- acceptable, since the size is always a multiple of the
3988 if SizA /= No_Uint then
3989 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
3990 Set_Result (Known_Incompatible);
3996 -- If we can't find the result by direct comparison of alignment
3997 -- values, then there is still one case that we can determine known
3998 -- result, and that is when we can determine that the types are the
3999 -- same, and no alignments are specified. Then we known that the
4000 -- alignments are compatible, even if we don't know the alignment
4001 -- value in the front end.
4003 elsif Etype (Obj) = Etype (Expr) then
4005 -- Types are the same, but we have to check for possible size
4006 -- and alignments on the Expr object that may make the alignment
4007 -- different, even though the types are the same.
4009 if Is_Entity_Name (Expr) then
4011 -- First check alignment of the Expr object. Any alignment less
4012 -- than Maximum_Alignment is worrisome since this is the case
4013 -- where we do not know the alignment of Obj.
4015 if Known_Alignment (Entity (Expr))
4017 UI_To_Int (Alignment (Entity (Expr)))
4018 < Ttypes.Maximum_Alignment
4020 Set_Result (Unknown);
4022 -- Now check size of Expr object. Any size that is not an
4023 -- even multiple of Maximum_Alignment is also worrisome
4024 -- since it may cause the alignment of the object to be less
4025 -- than the alignment of the type.
4027 elsif Known_Static_Esize (Entity (Expr))
4029 (UI_To_Int (Esize (Entity (Expr))) mod
4030 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4033 Set_Result (Unknown);
4035 -- Otherwise same type is decisive
4038 Set_Result (Known_Compatible);
4042 -- Another case to deal with is when there is an explicit size or
4043 -- alignment clause when the types are not the same. If so, then the
4044 -- result is Unknown. We don't need to do this test if the Default is
4045 -- Unknown, since that result will be set in any case.
4047 elsif Default /= Unknown
4048 and then (Has_Size_Clause (Etype (Expr))
4050 Has_Alignment_Clause (Etype (Expr)))
4052 Set_Result (Unknown);
4054 -- If no indication found, set default
4057 Set_Result (Default);
4060 -- Return worst result found
4063 end Has_Compatible_Alignment_Internal;
4065 -- Start of processing for Has_Compatible_Alignment
4068 -- If Obj has no specified alignment, then set alignment from the type
4069 -- alignment. Perhaps we should always do this, but for sure we should
4070 -- do it when there is an address clause since we can do more if the
4071 -- alignment is known.
4073 if Unknown_Alignment (Obj) then
4074 Set_Alignment (Obj, Alignment (Etype (Obj)));
4077 -- Now do the internal call that does all the work
4079 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4080 end Has_Compatible_Alignment;
4082 ----------------------
4083 -- Has_Declarations --
4084 ----------------------
4086 function Has_Declarations (N : Node_Id) return Boolean is
4087 K : constant Node_Kind := Nkind (N);
4089 return K = N_Accept_Statement
4090 or else K = N_Block_Statement
4091 or else K = N_Compilation_Unit_Aux
4092 or else K = N_Entry_Body
4093 or else K = N_Package_Body
4094 or else K = N_Protected_Body
4095 or else K = N_Subprogram_Body
4096 or else K = N_Task_Body
4097 or else K = N_Package_Specification;
4098 end Has_Declarations;
4100 -------------------------------------------
4101 -- Has_Discriminant_Dependent_Constraint --
4102 -------------------------------------------
4104 function Has_Discriminant_Dependent_Constraint
4105 (Comp : Entity_Id) return Boolean
4107 Comp_Decl : constant Node_Id := Parent (Comp);
4108 Subt_Indic : constant Node_Id :=
4109 Subtype_Indication (Component_Definition (Comp_Decl));
4114 if Nkind (Subt_Indic) = N_Subtype_Indication then
4115 Constr := Constraint (Subt_Indic);
4117 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4118 Assn := First (Constraints (Constr));
4119 while Present (Assn) loop
4120 case Nkind (Assn) is
4121 when N_Subtype_Indication |
4125 if Depends_On_Discriminant (Assn) then
4129 when N_Discriminant_Association =>
4130 if Depends_On_Discriminant (Expression (Assn)) then
4145 end Has_Discriminant_Dependent_Constraint;
4147 --------------------
4148 -- Has_Infinities --
4149 --------------------
4151 function Has_Infinities (E : Entity_Id) return Boolean is
4154 Is_Floating_Point_Type (E)
4155 and then Nkind (Scalar_Range (E)) = N_Range
4156 and then Includes_Infinities (Scalar_Range (E));
4159 --------------------
4160 -- Has_Interfaces --
4161 --------------------
4163 function Has_Interfaces
4165 Use_Full_View : Boolean := True) return Boolean
4170 -- Handle concurrent types
4172 if Is_Concurrent_Type (T) then
4173 Typ := Corresponding_Record_Type (T);
4178 if not Present (Typ)
4179 or else not Is_Record_Type (Typ)
4180 or else not Is_Tagged_Type (Typ)
4185 -- Handle private types
4188 and then Present (Full_View (Typ))
4190 Typ := Full_View (Typ);
4193 -- Handle concurrent record types
4195 if Is_Concurrent_Record_Type (Typ)
4196 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4202 if Is_Interface (Typ)
4204 (Is_Record_Type (Typ)
4205 and then Present (Interfaces (Typ))
4206 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4211 exit when Etype (Typ) = Typ
4213 -- Handle private types
4215 or else (Present (Full_View (Etype (Typ)))
4216 and then Full_View (Etype (Typ)) = Typ)
4218 -- Protect the frontend against wrong source with cyclic
4221 or else Etype (Typ) = T;
4223 -- Climb to the ancestor type handling private types
4225 if Present (Full_View (Etype (Typ))) then
4226 Typ := Full_View (Etype (Typ));
4235 ------------------------
4236 -- Has_Null_Exclusion --
4237 ------------------------
4239 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4242 when N_Access_Definition |
4243 N_Access_Function_Definition |
4244 N_Access_Procedure_Definition |
4245 N_Access_To_Object_Definition |
4247 N_Derived_Type_Definition |
4248 N_Function_Specification |
4249 N_Subtype_Declaration =>
4250 return Null_Exclusion_Present (N);
4252 when N_Component_Definition |
4253 N_Formal_Object_Declaration |
4254 N_Object_Renaming_Declaration =>
4255 if Present (Subtype_Mark (N)) then
4256 return Null_Exclusion_Present (N);
4257 else pragma Assert (Present (Access_Definition (N)));
4258 return Null_Exclusion_Present (Access_Definition (N));
4261 when N_Discriminant_Specification =>
4262 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4263 return Null_Exclusion_Present (Discriminant_Type (N));
4265 return Null_Exclusion_Present (N);
4268 when N_Object_Declaration =>
4269 if Nkind (Object_Definition (N)) = N_Access_Definition then
4270 return Null_Exclusion_Present (Object_Definition (N));
4272 return Null_Exclusion_Present (N);
4275 when N_Parameter_Specification =>
4276 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4277 return Null_Exclusion_Present (Parameter_Type (N));
4279 return Null_Exclusion_Present (N);
4286 end Has_Null_Exclusion;
4288 ------------------------
4289 -- Has_Null_Extension --
4290 ------------------------
4292 function Has_Null_Extension (T : Entity_Id) return Boolean is
4293 B : constant Entity_Id := Base_Type (T);
4298 if Nkind (Parent (B)) = N_Full_Type_Declaration
4299 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4301 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4303 if Present (Ext) then
4304 if Null_Present (Ext) then
4307 Comps := Component_List (Ext);
4309 -- The null component list is rewritten during analysis to
4310 -- include the parent component. Any other component indicates
4311 -- that the extension was not originally null.
4313 return Null_Present (Comps)
4314 or else No (Next (First (Component_Items (Comps))));
4323 end Has_Null_Extension;
4325 -------------------------------
4326 -- Has_Overriding_Initialize --
4327 -------------------------------
4329 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4330 BT : constant Entity_Id := Base_Type (T);
4335 if Is_Controlled (BT) then
4337 -- For derived types, check immediate ancestor, excluding
4338 -- Controlled itself.
4340 if Is_Derived_Type (BT)
4341 and then not In_Predefined_Unit (Etype (BT))
4342 and then Has_Overriding_Initialize (Etype (BT))
4346 elsif Present (Primitive_Operations (BT)) then
4347 P := First_Elmt (Primitive_Operations (BT));
4348 while Present (P) loop
4349 if Chars (Node (P)) = Name_Initialize
4350 and then Comes_From_Source (Node (P))
4361 elsif Has_Controlled_Component (BT) then
4362 Comp := First_Component (BT);
4363 while Present (Comp) loop
4364 if Has_Overriding_Initialize (Etype (Comp)) then
4368 Next_Component (Comp);
4376 end Has_Overriding_Initialize;
4378 --------------------------------------
4379 -- Has_Preelaborable_Initialization --
4380 --------------------------------------
4382 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4385 procedure Check_Components (E : Entity_Id);
4386 -- Check component/discriminant chain, sets Has_PE False if a component
4387 -- or discriminant does not meet the preelaborable initialization rules.
4389 ----------------------
4390 -- Check_Components --
4391 ----------------------
4393 procedure Check_Components (E : Entity_Id) is
4397 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4398 -- Returns True if and only if the expression denoted by N does not
4399 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4401 ---------------------------------
4402 -- Is_Preelaborable_Expression --
4403 ---------------------------------
4405 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4409 Comp_Type : Entity_Id;
4410 Is_Array_Aggr : Boolean;
4413 if Is_Static_Expression (N) then
4416 elsif Nkind (N) = N_Null then
4419 -- Attributes are allowed in general, even if their prefix is a
4420 -- formal type. (It seems that certain attributes known not to be
4421 -- static might not be allowed, but there are no rules to prevent
4424 elsif Nkind (N) = N_Attribute_Reference then
4427 -- The name of a discriminant evaluated within its parent type is
4428 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4429 -- names that denote discriminals as well as discriminants to
4430 -- catch references occurring within init procs.
4432 elsif Is_Entity_Name (N)
4434 (Ekind (Entity (N)) = E_Discriminant
4436 ((Ekind (Entity (N)) = E_Constant
4437 or else Ekind (Entity (N)) = E_In_Parameter)
4438 and then Present (Discriminal_Link (Entity (N)))))
4442 elsif Nkind (N) = N_Qualified_Expression then
4443 return Is_Preelaborable_Expression (Expression (N));
4445 -- For aggregates we have to check that each of the associations
4446 -- is preelaborable.
4448 elsif Nkind (N) = N_Aggregate
4449 or else Nkind (N) = N_Extension_Aggregate
4451 Is_Array_Aggr := Is_Array_Type (Etype (N));
4453 if Is_Array_Aggr then
4454 Comp_Type := Component_Type (Etype (N));
4457 -- Check the ancestor part of extension aggregates, which must
4458 -- be either the name of a type that has preelaborable init or
4459 -- an expression that is preelaborable.
4461 if Nkind (N) = N_Extension_Aggregate then
4463 Anc_Part : constant Node_Id := Ancestor_Part (N);
4466 if Is_Entity_Name (Anc_Part)
4467 and then Is_Type (Entity (Anc_Part))
4469 if not Has_Preelaborable_Initialization
4475 elsif not Is_Preelaborable_Expression (Anc_Part) then
4481 -- Check positional associations
4483 Exp := First (Expressions (N));
4484 while Present (Exp) loop
4485 if not Is_Preelaborable_Expression (Exp) then
4492 -- Check named associations
4494 Assn := First (Component_Associations (N));
4495 while Present (Assn) loop
4496 Choice := First (Choices (Assn));
4497 while Present (Choice) loop
4498 if Is_Array_Aggr then
4499 if Nkind (Choice) = N_Others_Choice then
4502 elsif Nkind (Choice) = N_Range then
4503 if not Is_Static_Range (Choice) then
4507 elsif not Is_Static_Expression (Choice) then
4512 Comp_Type := Etype (Choice);
4518 -- If the association has a <> at this point, then we have
4519 -- to check whether the component's type has preelaborable
4520 -- initialization. Note that this only occurs when the
4521 -- association's corresponding component does not have a
4522 -- default expression, the latter case having already been
4523 -- expanded as an expression for the association.
4525 if Box_Present (Assn) then
4526 if not Has_Preelaborable_Initialization (Comp_Type) then
4530 -- In the expression case we check whether the expression
4531 -- is preelaborable.
4534 not Is_Preelaborable_Expression (Expression (Assn))
4542 -- If we get here then aggregate as a whole is preelaborable
4546 -- All other cases are not preelaborable
4551 end Is_Preelaborable_Expression;
4553 -- Start of processing for Check_Components
4556 -- Loop through entities of record or protected type
4559 while Present (Ent) loop
4561 -- We are interested only in components and discriminants
4563 if Ekind (Ent) = E_Component
4565 Ekind (Ent) = E_Discriminant
4567 -- Get default expression if any. If there is no declaration
4568 -- node, it means we have an internal entity. The parent and
4569 -- tag fields are examples of such entities. For these cases,
4570 -- we just test the type of the entity.
4572 if Present (Declaration_Node (Ent)) then
4573 Exp := Expression (Declaration_Node (Ent));
4578 -- A component has PI if it has no default expression and the
4579 -- component type has PI.
4582 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4587 -- Require the default expression to be preelaborable
4589 elsif not Is_Preelaborable_Expression (Exp) then
4597 end Check_Components;
4599 -- Start of processing for Has_Preelaborable_Initialization
4602 -- Immediate return if already marked as known preelaborable init. This
4603 -- covers types for which this function has already been called once
4604 -- and returned True (in which case the result is cached), and also
4605 -- types to which a pragma Preelaborable_Initialization applies.
4607 if Known_To_Have_Preelab_Init (E) then
4611 -- If the type is a subtype representing a generic actual type, then
4612 -- test whether its base type has preelaborable initialization since
4613 -- the subtype representing the actual does not inherit this attribute
4614 -- from the actual or formal. (but maybe it should???)
4616 if Is_Generic_Actual_Type (E) then
4617 return Has_Preelaborable_Initialization (Base_Type (E));
4620 -- All elementary types have preelaborable initialization
4622 if Is_Elementary_Type (E) then
4625 -- Array types have PI if the component type has PI
4627 elsif Is_Array_Type (E) then
4628 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4630 -- A derived type has preelaborable initialization if its parent type
4631 -- has preelaborable initialization and (in the case of a derived record
4632 -- extension) if the non-inherited components all have preelaborable
4633 -- initialization. However, a user-defined controlled type with an
4634 -- overriding Initialize procedure does not have preelaborable
4637 elsif Is_Derived_Type (E) then
4639 -- If the derived type is a private extension then it doesn't have
4640 -- preelaborable initialization.
4642 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4646 -- First check whether ancestor type has preelaborable initialization
4648 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4650 -- If OK, check extension components (if any)
4652 if Has_PE and then Is_Record_Type (E) then
4653 Check_Components (First_Entity (E));
4656 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4657 -- with a user defined Initialize procedure does not have PI.
4660 and then Is_Controlled (E)
4661 and then Has_Overriding_Initialize (E)
4666 -- Private types not derived from a type having preelaborable init and
4667 -- that are not marked with pragma Preelaborable_Initialization do not
4668 -- have preelaborable initialization.
4670 elsif Is_Private_Type (E) then
4673 -- Record type has PI if it is non private and all components have PI
4675 elsif Is_Record_Type (E) then
4677 Check_Components (First_Entity (E));
4679 -- Protected types must not have entries, and components must meet
4680 -- same set of rules as for record components.
4682 elsif Is_Protected_Type (E) then
4683 if Has_Entries (E) then
4687 Check_Components (First_Entity (E));
4688 Check_Components (First_Private_Entity (E));
4691 -- Type System.Address always has preelaborable initialization
4693 elsif Is_RTE (E, RE_Address) then
4696 -- In all other cases, type does not have preelaborable initialization
4702 -- If type has preelaborable initialization, cache result
4705 Set_Known_To_Have_Preelab_Init (E);
4709 end Has_Preelaborable_Initialization;
4711 ---------------------------
4712 -- Has_Private_Component --
4713 ---------------------------
4715 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4716 Btype : Entity_Id := Base_Type (Type_Id);
4717 Component : Entity_Id;
4720 if Error_Posted (Type_Id)
4721 or else Error_Posted (Btype)
4726 if Is_Class_Wide_Type (Btype) then
4727 Btype := Root_Type (Btype);
4730 if Is_Private_Type (Btype) then
4732 UT : constant Entity_Id := Underlying_Type (Btype);
4735 if No (Full_View (Btype)) then
4736 return not Is_Generic_Type (Btype)
4737 and then not Is_Generic_Type (Root_Type (Btype));
4739 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4742 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4746 elsif Is_Array_Type (Btype) then
4747 return Has_Private_Component (Component_Type (Btype));
4749 elsif Is_Record_Type (Btype) then
4750 Component := First_Component (Btype);
4751 while Present (Component) loop
4752 if Has_Private_Component (Etype (Component)) then
4756 Next_Component (Component);
4761 elsif Is_Protected_Type (Btype)
4762 and then Present (Corresponding_Record_Type (Btype))
4764 return Has_Private_Component (Corresponding_Record_Type (Btype));
4769 end Has_Private_Component;
4775 function Has_Stream (T : Entity_Id) return Boolean is
4782 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4785 elsif Is_Array_Type (T) then
4786 return Has_Stream (Component_Type (T));
4788 elsif Is_Record_Type (T) then
4789 E := First_Component (T);
4790 while Present (E) loop
4791 if Has_Stream (Etype (E)) then
4800 elsif Is_Private_Type (T) then
4801 return Has_Stream (Underlying_Type (T));
4808 --------------------------
4809 -- Has_Tagged_Component --
4810 --------------------------
4812 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4816 if Is_Private_Type (Typ)
4817 and then Present (Underlying_Type (Typ))
4819 return Has_Tagged_Component (Underlying_Type (Typ));
4821 elsif Is_Array_Type (Typ) then
4822 return Has_Tagged_Component (Component_Type (Typ));
4824 elsif Is_Tagged_Type (Typ) then
4827 elsif Is_Record_Type (Typ) then
4828 Comp := First_Component (Typ);
4829 while Present (Comp) loop
4830 if Has_Tagged_Component (Etype (Comp)) then
4834 Next_Component (Comp);
4842 end Has_Tagged_Component;
4844 --------------------------
4845 -- Implements_Interface --
4846 --------------------------
4848 function Implements_Interface
4849 (Typ_Ent : Entity_Id;
4850 Iface_Ent : Entity_Id;
4851 Exclude_Parents : Boolean := False) return Boolean
4853 Ifaces_List : Elist_Id;
4859 if Is_Class_Wide_Type (Typ_Ent) then
4860 Typ := Etype (Typ_Ent);
4865 if Is_Class_Wide_Type (Iface_Ent) then
4866 Iface := Etype (Iface_Ent);
4871 if not Has_Interfaces (Typ) then
4875 Collect_Interfaces (Typ, Ifaces_List);
4877 Elmt := First_Elmt (Ifaces_List);
4878 while Present (Elmt) loop
4879 if Is_Ancestor (Node (Elmt), Typ)
4880 and then Exclude_Parents
4884 elsif Node (Elmt) = Iface then
4892 end Implements_Interface;
4898 function In_Instance return Boolean is
4899 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4905 and then S /= Standard_Standard
4907 if (Ekind (S) = E_Function
4908 or else Ekind (S) = E_Package
4909 or else Ekind (S) = E_Procedure)
4910 and then Is_Generic_Instance (S)
4912 -- A child instance is always compiled in the context of a parent
4913 -- instance. Nevertheless, the actuals are not analyzed in an
4914 -- instance context. We detect this case by examining the current
4915 -- compilation unit, which must be a child instance, and checking
4916 -- that it is not currently on the scope stack.
4918 if Is_Child_Unit (Curr_Unit)
4920 Nkind (Unit (Cunit (Current_Sem_Unit)))
4921 = N_Package_Instantiation
4922 and then not In_Open_Scopes (Curr_Unit)
4936 ----------------------
4937 -- In_Instance_Body --
4938 ----------------------
4940 function In_Instance_Body return Boolean is
4946 and then S /= Standard_Standard
4948 if (Ekind (S) = E_Function
4949 or else Ekind (S) = E_Procedure)
4950 and then Is_Generic_Instance (S)
4954 elsif Ekind (S) = E_Package
4955 and then In_Package_Body (S)
4956 and then Is_Generic_Instance (S)
4965 end In_Instance_Body;
4967 -----------------------------
4968 -- In_Instance_Not_Visible --
4969 -----------------------------
4971 function In_Instance_Not_Visible return Boolean is
4977 and then S /= Standard_Standard
4979 if (Ekind (S) = E_Function
4980 or else Ekind (S) = E_Procedure)
4981 and then Is_Generic_Instance (S)
4985 elsif Ekind (S) = E_Package
4986 and then (In_Package_Body (S) or else In_Private_Part (S))
4987 and then Is_Generic_Instance (S)
4996 end In_Instance_Not_Visible;
4998 ------------------------------
4999 -- In_Instance_Visible_Part --
5000 ------------------------------
5002 function In_Instance_Visible_Part return Boolean is
5008 and then S /= Standard_Standard
5010 if Ekind (S) = E_Package
5011 and then Is_Generic_Instance (S)
5012 and then not In_Package_Body (S)
5013 and then not In_Private_Part (S)
5022 end In_Instance_Visible_Part;
5024 ---------------------
5025 -- In_Package_Body --
5026 ---------------------
5028 function In_Package_Body return Boolean is
5034 and then S /= Standard_Standard
5036 if Ekind (S) = E_Package
5037 and then In_Package_Body (S)
5046 end In_Package_Body;
5048 --------------------------------
5049 -- In_Parameter_Specification --
5050 --------------------------------
5052 function In_Parameter_Specification (N : Node_Id) return Boolean is
5057 while Present (PN) loop
5058 if Nkind (PN) = N_Parameter_Specification then
5066 end In_Parameter_Specification;
5068 --------------------------------------
5069 -- In_Subprogram_Or_Concurrent_Unit --
5070 --------------------------------------
5072 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5077 -- Use scope chain to check successively outer scopes
5083 if K in Subprogram_Kind
5084 or else K in Concurrent_Kind
5085 or else K in Generic_Subprogram_Kind
5089 elsif E = Standard_Standard then
5095 end In_Subprogram_Or_Concurrent_Unit;
5097 ---------------------
5098 -- In_Visible_Part --
5099 ---------------------
5101 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5104 Is_Package_Or_Generic_Package (Scope_Id)
5105 and then In_Open_Scopes (Scope_Id)
5106 and then not In_Package_Body (Scope_Id)
5107 and then not In_Private_Part (Scope_Id);
5108 end In_Visible_Part;
5110 ---------------------------------
5111 -- Insert_Explicit_Dereference --
5112 ---------------------------------
5114 procedure Insert_Explicit_Dereference (N : Node_Id) is
5115 New_Prefix : constant Node_Id := Relocate_Node (N);
5116 Ent : Entity_Id := Empty;
5123 Save_Interps (N, New_Prefix);
5125 Make_Explicit_Dereference (Sloc (N),
5126 Prefix => New_Prefix));
5128 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5130 if Is_Overloaded (New_Prefix) then
5132 -- The deference is also overloaded, and its interpretations are the
5133 -- designated types of the interpretations of the original node.
5135 Set_Etype (N, Any_Type);
5137 Get_First_Interp (New_Prefix, I, It);
5138 while Present (It.Nam) loop
5141 if Is_Access_Type (T) then
5142 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5145 Get_Next_Interp (I, It);
5151 -- Prefix is unambiguous: mark the original prefix (which might
5152 -- Come_From_Source) as a reference, since the new (relocated) one
5153 -- won't be taken into account.
5155 if Is_Entity_Name (New_Prefix) then
5156 Ent := Entity (New_Prefix);
5158 -- For a retrieval of a subcomponent of some composite object,
5159 -- retrieve the ultimate entity if there is one.
5161 elsif Nkind (New_Prefix) = N_Selected_Component
5162 or else Nkind (New_Prefix) = N_Indexed_Component
5164 Pref := Prefix (New_Prefix);
5165 while Present (Pref)
5167 (Nkind (Pref) = N_Selected_Component
5168 or else Nkind (Pref) = N_Indexed_Component)
5170 Pref := Prefix (Pref);
5173 if Present (Pref) and then Is_Entity_Name (Pref) then
5174 Ent := Entity (Pref);
5178 if Present (Ent) then
5179 Generate_Reference (Ent, New_Prefix);
5182 end Insert_Explicit_Dereference;
5184 ------------------------------------------
5185 -- Inspect_Deferred_Constant_Completion --
5186 ------------------------------------------
5188 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5192 Decl := First (Decls);
5193 while Present (Decl) loop
5195 -- Deferred constant signature
5197 if Nkind (Decl) = N_Object_Declaration
5198 and then Constant_Present (Decl)
5199 and then No (Expression (Decl))
5201 -- No need to check internally generated constants
5203 and then Comes_From_Source (Decl)
5205 -- The constant is not completed. A full object declaration
5206 -- or a pragma Import complete a deferred constant.
5208 and then not Has_Completion (Defining_Identifier (Decl))
5211 ("constant declaration requires initialization expression",
5212 Defining_Identifier (Decl));
5215 Decl := Next (Decl);
5217 end Inspect_Deferred_Constant_Completion;
5223 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5224 pragma Assert (Is_Type (E));
5226 return AAMP_On_Target
5227 and then Is_Floating_Point_Type (E)
5228 and then E = Base_Type (E);
5231 -------------------------
5232 -- Is_Actual_Parameter --
5233 -------------------------
5235 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5236 PK : constant Node_Kind := Nkind (Parent (N));
5240 when N_Parameter_Association =>
5241 return N = Explicit_Actual_Parameter (Parent (N));
5243 when N_Function_Call | N_Procedure_Call_Statement =>
5244 return Is_List_Member (N)
5246 List_Containing (N) = Parameter_Associations (Parent (N));
5251 end Is_Actual_Parameter;
5253 ---------------------
5254 -- Is_Aliased_View --
5255 ---------------------
5257 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5261 if Is_Entity_Name (Obj) then
5269 or else (Present (Renamed_Object (E))
5270 and then Is_Aliased_View (Renamed_Object (E)))))
5272 or else ((Is_Formal (E)
5273 or else Ekind (E) = E_Generic_In_Out_Parameter
5274 or else Ekind (E) = E_Generic_In_Parameter)
5275 and then Is_Tagged_Type (Etype (E)))
5277 or else (Is_Concurrent_Type (E)
5278 and then In_Open_Scopes (E))
5280 -- Current instance of type, either directly or as rewritten
5281 -- reference to the current object.
5283 or else (Is_Entity_Name (Original_Node (Obj))
5284 and then Present (Entity (Original_Node (Obj)))
5285 and then Is_Type (Entity (Original_Node (Obj))))
5287 or else (Is_Type (E) and then E = Current_Scope)
5289 or else (Is_Incomplete_Or_Private_Type (E)
5290 and then Full_View (E) = Current_Scope);
5292 elsif Nkind (Obj) = N_Selected_Component then
5293 return Is_Aliased (Entity (Selector_Name (Obj)));
5295 elsif Nkind (Obj) = N_Indexed_Component then
5296 return Has_Aliased_Components (Etype (Prefix (Obj)))
5298 (Is_Access_Type (Etype (Prefix (Obj)))
5300 Has_Aliased_Components
5301 (Designated_Type (Etype (Prefix (Obj)))));
5303 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5304 or else Nkind (Obj) = N_Type_Conversion
5306 return Is_Tagged_Type (Etype (Obj))
5307 and then Is_Aliased_View (Expression (Obj));
5309 elsif Nkind (Obj) = N_Explicit_Dereference then
5310 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5315 end Is_Aliased_View;
5317 -------------------------
5318 -- Is_Ancestor_Package --
5319 -------------------------
5321 function Is_Ancestor_Package
5323 E2 : Entity_Id) return Boolean
5330 and then Par /= Standard_Standard
5340 end Is_Ancestor_Package;
5342 ----------------------
5343 -- Is_Atomic_Object --
5344 ----------------------
5346 function Is_Atomic_Object (N : Node_Id) return Boolean is
5348 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5349 -- Determines if given object has atomic components
5351 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5352 -- If prefix is an implicit dereference, examine designated type
5354 ----------------------
5355 -- Is_Atomic_Prefix --
5356 ----------------------
5358 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5360 if Is_Access_Type (Etype (N)) then
5362 Has_Atomic_Components (Designated_Type (Etype (N)));
5364 return Object_Has_Atomic_Components (N);
5366 end Is_Atomic_Prefix;
5368 ----------------------------------
5369 -- Object_Has_Atomic_Components --
5370 ----------------------------------
5372 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5374 if Has_Atomic_Components (Etype (N))
5375 or else Is_Atomic (Etype (N))
5379 elsif Is_Entity_Name (N)
5380 and then (Has_Atomic_Components (Entity (N))
5381 or else Is_Atomic (Entity (N)))
5385 elsif Nkind (N) = N_Indexed_Component
5386 or else Nkind (N) = N_Selected_Component
5388 return Is_Atomic_Prefix (Prefix (N));
5393 end Object_Has_Atomic_Components;
5395 -- Start of processing for Is_Atomic_Object
5398 if Is_Atomic (Etype (N))
5399 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5403 elsif Nkind (N) = N_Indexed_Component
5404 or else Nkind (N) = N_Selected_Component
5406 return Is_Atomic_Prefix (Prefix (N));
5411 end Is_Atomic_Object;
5413 -------------------------
5414 -- Is_Coextension_Root --
5415 -------------------------
5417 function Is_Coextension_Root (N : Node_Id) return Boolean is
5420 Nkind (N) = N_Allocator
5421 and then Present (Coextensions (N))
5423 -- Anonymous access discriminants carry a list of all nested
5424 -- controlled coextensions.
5426 and then not Is_Dynamic_Coextension (N)
5427 and then not Is_Static_Coextension (N);
5428 end Is_Coextension_Root;
5430 -----------------------------
5431 -- Is_Concurrent_Interface --
5432 -----------------------------
5434 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5439 (Is_Protected_Interface (T)
5440 or else Is_Synchronized_Interface (T)
5441 or else Is_Task_Interface (T));
5442 end Is_Concurrent_Interface;
5444 --------------------------------------
5445 -- Is_Controlling_Limited_Procedure --
5446 --------------------------------------
5448 function Is_Controlling_Limited_Procedure
5449 (Proc_Nam : Entity_Id) return Boolean
5451 Param_Typ : Entity_Id := Empty;
5454 if Ekind (Proc_Nam) = E_Procedure
5455 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5457 Param_Typ := Etype (Parameter_Type (First (
5458 Parameter_Specifications (Parent (Proc_Nam)))));
5460 -- In this case where an Itype was created, the procedure call has been
5463 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5464 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5466 Present (Parameter_Associations
5467 (Associated_Node_For_Itype (Proc_Nam)))
5470 Etype (First (Parameter_Associations
5471 (Associated_Node_For_Itype (Proc_Nam))));
5474 if Present (Param_Typ) then
5476 Is_Interface (Param_Typ)
5477 and then Is_Limited_Record (Param_Typ);
5481 end Is_Controlling_Limited_Procedure;
5483 ----------------------------------------------
5484 -- Is_Dependent_Component_Of_Mutable_Object --
5485 ----------------------------------------------
5487 function Is_Dependent_Component_Of_Mutable_Object
5488 (Object : Node_Id) return Boolean
5491 Prefix_Type : Entity_Id;
5492 P_Aliased : Boolean := False;
5495 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5496 -- Returns True if and only if Comp is declared within a variant part
5498 --------------------------------
5499 -- Is_Declared_Within_Variant --
5500 --------------------------------
5502 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5503 Comp_Decl : constant Node_Id := Parent (Comp);
5504 Comp_List : constant Node_Id := Parent (Comp_Decl);
5506 return Nkind (Parent (Comp_List)) = N_Variant;
5507 end Is_Declared_Within_Variant;
5509 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5512 if Is_Variable (Object) then
5514 if Nkind (Object) = N_Selected_Component then
5515 P := Prefix (Object);
5516 Prefix_Type := Etype (P);
5518 if Is_Entity_Name (P) then
5520 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5521 Prefix_Type := Base_Type (Prefix_Type);
5524 if Is_Aliased (Entity (P)) then
5528 -- A discriminant check on a selected component may be
5529 -- expanded into a dereference when removing side-effects.
5530 -- Recover the original node and its type, which may be
5533 elsif Nkind (P) = N_Explicit_Dereference
5534 and then not (Comes_From_Source (P))
5536 P := Original_Node (P);
5537 Prefix_Type := Etype (P);
5540 -- Check for prefix being an aliased component ???
5545 -- A heap object is constrained by its initial value
5547 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5548 -- the dereferenced case, since the access value might denote an
5549 -- unconstrained aliased object, whereas in Ada 95 the designated
5550 -- object is guaranteed to be constrained. A worst-case assumption
5551 -- has to apply in Ada 2005 because we can't tell at compile time
5552 -- whether the object is "constrained by its initial value"
5553 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5554 -- semantic rules -- these rules are acknowledged to need fixing).
5556 if Ada_Version < Ada_05 then
5557 if Is_Access_Type (Prefix_Type)
5558 or else Nkind (P) = N_Explicit_Dereference
5563 elsif Ada_Version >= Ada_05 then
5564 if Is_Access_Type (Prefix_Type) then
5566 -- If the access type is pool-specific, and there is no
5567 -- constrained partial view of the designated type, then the
5568 -- designated object is known to be constrained.
5570 if Ekind (Prefix_Type) = E_Access_Type
5571 and then not Has_Constrained_Partial_View
5572 (Designated_Type (Prefix_Type))
5576 -- Otherwise (general access type, or there is a constrained
5577 -- partial view of the designated type), we need to check
5578 -- based on the designated type.
5581 Prefix_Type := Designated_Type (Prefix_Type);
5587 Original_Record_Component (Entity (Selector_Name (Object)));
5589 -- As per AI-0017, the renaming is illegal in a generic body,
5590 -- even if the subtype is indefinite.
5592 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5594 if not Is_Constrained (Prefix_Type)
5595 and then (not Is_Indefinite_Subtype (Prefix_Type)
5597 (Is_Generic_Type (Prefix_Type)
5598 and then Ekind (Current_Scope) = E_Generic_Package
5599 and then In_Package_Body (Current_Scope)))
5601 and then (Is_Declared_Within_Variant (Comp)
5602 or else Has_Discriminant_Dependent_Constraint (Comp))
5603 and then (not P_Aliased or else Ada_Version >= Ada_05)
5609 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5613 elsif Nkind (Object) = N_Indexed_Component
5614 or else Nkind (Object) = N_Slice
5616 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5618 -- A type conversion that Is_Variable is a view conversion:
5619 -- go back to the denoted object.
5621 elsif Nkind (Object) = N_Type_Conversion then
5623 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5628 end Is_Dependent_Component_Of_Mutable_Object;
5630 ---------------------
5631 -- Is_Dereferenced --
5632 ---------------------
5634 function Is_Dereferenced (N : Node_Id) return Boolean is
5635 P : constant Node_Id := Parent (N);
5638 (Nkind (P) = N_Selected_Component
5640 Nkind (P) = N_Explicit_Dereference
5642 Nkind (P) = N_Indexed_Component
5644 Nkind (P) = N_Slice)
5645 and then Prefix (P) = N;
5646 end Is_Dereferenced;
5648 ----------------------
5649 -- Is_Descendent_Of --
5650 ----------------------
5652 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5657 pragma Assert (Nkind (T1) in N_Entity);
5658 pragma Assert (Nkind (T2) in N_Entity);
5660 T := Base_Type (T1);
5662 -- Immediate return if the types match
5667 -- Comment needed here ???
5669 elsif Ekind (T) = E_Class_Wide_Type then
5670 return Etype (T) = T2;
5678 -- Done if we found the type we are looking for
5683 -- Done if no more derivations to check
5690 -- Following test catches error cases resulting from prev errors
5692 elsif No (Etyp) then
5695 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5698 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5702 T := Base_Type (Etyp);
5705 end Is_Descendent_Of;
5711 function Is_False (U : Uint) return Boolean is
5716 ---------------------------
5717 -- Is_Fixed_Model_Number --
5718 ---------------------------
5720 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5721 S : constant Ureal := Small_Value (T);
5722 M : Urealp.Save_Mark;
5726 R := (U = UR_Trunc (U / S) * S);
5729 end Is_Fixed_Model_Number;
5731 -------------------------------
5732 -- Is_Fully_Initialized_Type --
5733 -------------------------------
5735 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5737 if Is_Scalar_Type (Typ) then
5740 elsif Is_Access_Type (Typ) then
5743 elsif Is_Array_Type (Typ) then
5744 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5748 -- An interesting case, if we have a constrained type one of whose
5749 -- bounds is known to be null, then there are no elements to be
5750 -- initialized, so all the elements are initialized!
5752 if Is_Constrained (Typ) then
5755 Indx_Typ : Entity_Id;
5759 Indx := First_Index (Typ);
5760 while Present (Indx) loop
5761 if Etype (Indx) = Any_Type then
5764 -- If index is a range, use directly
5766 elsif Nkind (Indx) = N_Range then
5767 Lbd := Low_Bound (Indx);
5768 Hbd := High_Bound (Indx);
5771 Indx_Typ := Etype (Indx);
5773 if Is_Private_Type (Indx_Typ) then
5774 Indx_Typ := Full_View (Indx_Typ);
5777 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5780 Lbd := Type_Low_Bound (Indx_Typ);
5781 Hbd := Type_High_Bound (Indx_Typ);
5785 if Compile_Time_Known_Value (Lbd)
5786 and then Compile_Time_Known_Value (Hbd)
5788 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5798 -- If no null indexes, then type is not fully initialized
5804 elsif Is_Record_Type (Typ) then
5805 if Has_Discriminants (Typ)
5807 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5808 and then Is_Fully_Initialized_Variant (Typ)
5813 -- Controlled records are considered to be fully initialized if
5814 -- there is a user defined Initialize routine. This may not be
5815 -- entirely correct, but as the spec notes, we are guessing here
5816 -- what is best from the point of view of issuing warnings.
5818 if Is_Controlled (Typ) then
5820 Utyp : constant Entity_Id := Underlying_Type (Typ);
5823 if Present (Utyp) then
5825 Init : constant Entity_Id :=
5827 (Underlying_Type (Typ), Name_Initialize));
5831 and then Comes_From_Source (Init)
5833 Is_Predefined_File_Name
5834 (File_Name (Get_Source_File_Index (Sloc (Init))))
5838 elsif Has_Null_Extension (Typ)
5840 Is_Fully_Initialized_Type
5841 (Etype (Base_Type (Typ)))
5850 -- Otherwise see if all record components are initialized
5856 Ent := First_Entity (Typ);
5857 while Present (Ent) loop
5858 if Chars (Ent) = Name_uController then
5861 elsif Ekind (Ent) = E_Component
5862 and then (No (Parent (Ent))
5863 or else No (Expression (Parent (Ent))))
5864 and then not Is_Fully_Initialized_Type (Etype (Ent))
5866 -- Special VM case for tag components, which need to be
5867 -- defined in this case, but are never initialized as VMs
5868 -- are using other dispatching mechanisms. Ignore this
5869 -- uninitialized case. Note that this applies both to the
5870 -- uTag entry and the main vtable pointer (CPP_Class case).
5872 and then (VM_Target = No_VM or else not Is_Tag (Ent))
5881 -- No uninitialized components, so type is fully initialized.
5882 -- Note that this catches the case of no components as well.
5886 elsif Is_Concurrent_Type (Typ) then
5889 elsif Is_Private_Type (Typ) then
5891 U : constant Entity_Id := Underlying_Type (Typ);
5897 return Is_Fully_Initialized_Type (U);
5904 end Is_Fully_Initialized_Type;
5906 ----------------------------------
5907 -- Is_Fully_Initialized_Variant --
5908 ----------------------------------
5910 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5911 Loc : constant Source_Ptr := Sloc (Typ);
5912 Constraints : constant List_Id := New_List;
5913 Components : constant Elist_Id := New_Elmt_List;
5914 Comp_Elmt : Elmt_Id;
5916 Comp_List : Node_Id;
5918 Discr_Val : Node_Id;
5920 Report_Errors : Boolean;
5921 pragma Warnings (Off, Report_Errors);
5924 if Serious_Errors_Detected > 0 then
5928 if Is_Record_Type (Typ)
5929 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5930 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5932 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5934 Discr := First_Discriminant (Typ);
5935 while Present (Discr) loop
5936 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5937 Discr_Val := Expression (Parent (Discr));
5939 if Present (Discr_Val)
5940 and then Is_OK_Static_Expression (Discr_Val)
5942 Append_To (Constraints,
5943 Make_Component_Association (Loc,
5944 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5945 Expression => New_Copy (Discr_Val)));
5953 Next_Discriminant (Discr);
5958 Comp_List => Comp_List,
5959 Governed_By => Constraints,
5961 Report_Errors => Report_Errors);
5963 -- Check that each component present is fully initialized
5965 Comp_Elmt := First_Elmt (Components);
5966 while Present (Comp_Elmt) loop
5967 Comp_Id := Node (Comp_Elmt);
5969 if Ekind (Comp_Id) = E_Component
5970 and then (No (Parent (Comp_Id))
5971 or else No (Expression (Parent (Comp_Id))))
5972 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5977 Next_Elmt (Comp_Elmt);
5982 elsif Is_Private_Type (Typ) then
5984 U : constant Entity_Id := Underlying_Type (Typ);
5990 return Is_Fully_Initialized_Variant (U);
5996 end Is_Fully_Initialized_Variant;
5998 ----------------------------
5999 -- Is_Inherited_Operation --
6000 ----------------------------
6002 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6003 Kind : constant Node_Kind := Nkind (Parent (E));
6005 pragma Assert (Is_Overloadable (E));
6006 return Kind = N_Full_Type_Declaration
6007 or else Kind = N_Private_Extension_Declaration
6008 or else Kind = N_Subtype_Declaration
6009 or else (Ekind (E) = E_Enumeration_Literal
6010 and then Is_Derived_Type (Etype (E)));
6011 end Is_Inherited_Operation;
6013 -----------------------------
6014 -- Is_Library_Level_Entity --
6015 -----------------------------
6017 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6019 -- The following is a small optimization, and it also properly handles
6020 -- discriminals, which in task bodies might appear in expressions before
6021 -- the corresponding procedure has been created, and which therefore do
6022 -- not have an assigned scope.
6024 if Ekind (E) in Formal_Kind then
6028 -- Normal test is simply that the enclosing dynamic scope is Standard
6030 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6031 end Is_Library_Level_Entity;
6033 ---------------------------------
6034 -- Is_Local_Variable_Reference --
6035 ---------------------------------
6037 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6039 if not Is_Entity_Name (Expr) then
6044 Ent : constant Entity_Id := Entity (Expr);
6045 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6047 if Ekind (Ent) /= E_Variable
6049 Ekind (Ent) /= E_In_Out_Parameter
6053 return Present (Sub) and then Sub = Current_Subprogram;
6057 end Is_Local_Variable_Reference;
6059 -------------------------
6060 -- Is_Object_Reference --
6061 -------------------------
6063 function Is_Object_Reference (N : Node_Id) return Boolean is
6065 if Is_Entity_Name (N) then
6066 return Present (Entity (N)) and then Is_Object (Entity (N));
6070 when N_Indexed_Component | N_Slice =>
6072 Is_Object_Reference (Prefix (N))
6073 or else Is_Access_Type (Etype (Prefix (N)));
6075 -- In Ada95, a function call is a constant object; a procedure
6078 when N_Function_Call =>
6079 return Etype (N) /= Standard_Void_Type;
6081 -- A reference to the stream attribute Input is a function call
6083 when N_Attribute_Reference =>
6084 return Attribute_Name (N) = Name_Input;
6086 when N_Selected_Component =>
6088 Is_Object_Reference (Selector_Name (N))
6090 (Is_Object_Reference (Prefix (N))
6091 or else Is_Access_Type (Etype (Prefix (N))));
6093 when N_Explicit_Dereference =>
6096 -- A view conversion of a tagged object is an object reference
6098 when N_Type_Conversion =>
6099 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6100 and then Is_Tagged_Type (Etype (Expression (N)))
6101 and then Is_Object_Reference (Expression (N));
6103 -- An unchecked type conversion is considered to be an object if
6104 -- the operand is an object (this construction arises only as a
6105 -- result of expansion activities).
6107 when N_Unchecked_Type_Conversion =>
6114 end Is_Object_Reference;
6116 -----------------------------------
6117 -- Is_OK_Variable_For_Out_Formal --
6118 -----------------------------------
6120 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6122 Note_Possible_Modification (AV, Sure => True);
6124 -- We must reject parenthesized variable names. The check for
6125 -- Comes_From_Source is present because there are currently
6126 -- cases where the compiler violates this rule (e.g. passing
6127 -- a task object to its controlled Initialize routine).
6129 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6132 -- A variable is always allowed
6134 elsif Is_Variable (AV) then
6137 -- Unchecked conversions are allowed only if they come from the
6138 -- generated code, which sometimes uses unchecked conversions for out
6139 -- parameters in cases where code generation is unaffected. We tell
6140 -- source unchecked conversions by seeing if they are rewrites of an
6141 -- original Unchecked_Conversion function call, or of an explicit
6142 -- conversion of a function call.
6144 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6145 if Nkind (Original_Node (AV)) = N_Function_Call then
6148 elsif Comes_From_Source (AV)
6149 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6153 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6154 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6160 -- Normal type conversions are allowed if argument is a variable
6162 elsif Nkind (AV) = N_Type_Conversion then
6163 if Is_Variable (Expression (AV))
6164 and then Paren_Count (Expression (AV)) = 0
6166 Note_Possible_Modification (Expression (AV), Sure => True);
6169 -- We also allow a non-parenthesized expression that raises
6170 -- constraint error if it rewrites what used to be a variable
6172 elsif Raises_Constraint_Error (Expression (AV))
6173 and then Paren_Count (Expression (AV)) = 0
6174 and then Is_Variable (Original_Node (Expression (AV)))
6178 -- Type conversion of something other than a variable
6184 -- If this node is rewritten, then test the original form, if that is
6185 -- OK, then we consider the rewritten node OK (for example, if the
6186 -- original node is a conversion, then Is_Variable will not be true
6187 -- but we still want to allow the conversion if it converts a variable).
6189 elsif Original_Node (AV) /= AV then
6190 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6192 -- All other non-variables are rejected
6197 end Is_OK_Variable_For_Out_Formal;
6199 -----------------------------------
6200 -- Is_Partially_Initialized_Type --
6201 -----------------------------------
6203 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6205 if Is_Scalar_Type (Typ) then
6208 elsif Is_Access_Type (Typ) then
6211 elsif Is_Array_Type (Typ) then
6213 -- If component type is partially initialized, so is array type
6215 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6218 -- Otherwise we are only partially initialized if we are fully
6219 -- initialized (this is the empty array case, no point in us
6220 -- duplicating that code here).
6223 return Is_Fully_Initialized_Type (Typ);
6226 elsif Is_Record_Type (Typ) then
6228 -- A discriminated type is always partially initialized
6230 if Has_Discriminants (Typ) then
6233 -- A tagged type is always partially initialized
6235 elsif Is_Tagged_Type (Typ) then
6238 -- Case of non-discriminated record
6244 Component_Present : Boolean := False;
6245 -- Set True if at least one component is present. If no
6246 -- components are present, then record type is fully
6247 -- initialized (another odd case, like the null array).
6250 -- Loop through components
6252 Ent := First_Entity (Typ);
6253 while Present (Ent) loop
6254 if Ekind (Ent) = E_Component then
6255 Component_Present := True;
6257 -- If a component has an initialization expression then
6258 -- the enclosing record type is partially initialized
6260 if Present (Parent (Ent))
6261 and then Present (Expression (Parent (Ent)))
6265 -- If a component is of a type which is itself partially
6266 -- initialized, then the enclosing record type is also.
6268 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6276 -- No initialized components found. If we found any components
6277 -- they were all uninitialized so the result is false.
6279 if Component_Present then
6282 -- But if we found no components, then all the components are
6283 -- initialized so we consider the type to be initialized.
6291 -- Concurrent types are always fully initialized
6293 elsif Is_Concurrent_Type (Typ) then
6296 -- For a private type, go to underlying type. If there is no underlying
6297 -- type then just assume this partially initialized. Not clear if this
6298 -- can happen in a non-error case, but no harm in testing for this.
6300 elsif Is_Private_Type (Typ) then
6302 U : constant Entity_Id := Underlying_Type (Typ);
6307 return Is_Partially_Initialized_Type (U);
6311 -- For any other type (are there any?) assume partially initialized
6316 end Is_Partially_Initialized_Type;
6318 ------------------------------------
6319 -- Is_Potentially_Persistent_Type --
6320 ------------------------------------
6322 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6327 -- For private type, test corresponding full type
6329 if Is_Private_Type (T) then
6330 return Is_Potentially_Persistent_Type (Full_View (T));
6332 -- Scalar types are potentially persistent
6334 elsif Is_Scalar_Type (T) then
6337 -- Record type is potentially persistent if not tagged and the types of
6338 -- all it components are potentially persistent, and no component has
6339 -- an initialization expression.
6341 elsif Is_Record_Type (T)
6342 and then not Is_Tagged_Type (T)
6343 and then not Is_Partially_Initialized_Type (T)
6345 Comp := First_Component (T);
6346 while Present (Comp) loop
6347 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6356 -- Array type is potentially persistent if its component type is
6357 -- potentially persistent and if all its constraints are static.
6359 elsif Is_Array_Type (T) then
6360 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6364 Indx := First_Index (T);
6365 while Present (Indx) loop
6366 if not Is_OK_Static_Subtype (Etype (Indx)) then
6375 -- All other types are not potentially persistent
6380 end Is_Potentially_Persistent_Type;
6382 ---------------------------------
6383 -- Is_Protected_Self_Reference --
6384 ---------------------------------
6386 function Is_Protected_Self_Reference (N : Node_Id) return Boolean
6388 function In_Access_Definition (N : Node_Id) return Boolean;
6389 -- Returns true if N belongs to an access definition
6391 --------------------------
6392 -- In_Access_Definition --
6393 --------------------------
6395 function In_Access_Definition (N : Node_Id) return Boolean
6397 P : Node_Id := Parent (N);
6399 while Present (P) loop
6400 if Nkind (P) = N_Access_Definition then
6406 end In_Access_Definition;
6408 -- Start of processing for Is_Protected_Self_Reference
6411 return Ada_Version >= Ada_05
6412 and then Is_Entity_Name (N)
6413 and then Is_Protected_Type (Entity (N))
6414 and then In_Open_Scopes (Entity (N))
6415 and then not In_Access_Definition (N);
6416 end Is_Protected_Self_Reference;
6418 -----------------------------
6419 -- Is_RCI_Pkg_Spec_Or_Body --
6420 -----------------------------
6422 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6424 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6425 -- Return True if the unit of Cunit is an RCI package declaration
6427 ---------------------------
6428 -- Is_RCI_Pkg_Decl_Cunit --
6429 ---------------------------
6431 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6432 The_Unit : constant Node_Id := Unit (Cunit);
6435 if Nkind (The_Unit) /= N_Package_Declaration then
6439 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6440 end Is_RCI_Pkg_Decl_Cunit;
6442 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6445 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6447 (Nkind (Unit (Cunit)) = N_Package_Body
6448 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6449 end Is_RCI_Pkg_Spec_Or_Body;
6451 -----------------------------------------
6452 -- Is_Remote_Access_To_Class_Wide_Type --
6453 -----------------------------------------
6455 function Is_Remote_Access_To_Class_Wide_Type
6456 (E : Entity_Id) return Boolean
6459 -- A remote access to class-wide type is a general access to object type
6460 -- declared in the visible part of a Remote_Types or Remote_Call_
6463 return Ekind (E) = E_General_Access_Type
6464 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6465 end Is_Remote_Access_To_Class_Wide_Type;
6467 -----------------------------------------
6468 -- Is_Remote_Access_To_Subprogram_Type --
6469 -----------------------------------------
6471 function Is_Remote_Access_To_Subprogram_Type
6472 (E : Entity_Id) return Boolean
6475 return (Ekind (E) = E_Access_Subprogram_Type
6476 or else (Ekind (E) = E_Record_Type
6477 and then Present (Corresponding_Remote_Type (E))))
6478 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6479 end Is_Remote_Access_To_Subprogram_Type;
6481 --------------------
6482 -- Is_Remote_Call --
6483 --------------------
6485 function Is_Remote_Call (N : Node_Id) return Boolean is
6487 if Nkind (N) /= N_Procedure_Call_Statement
6488 and then Nkind (N) /= N_Function_Call
6490 -- An entry call cannot be remote
6494 elsif Nkind (Name (N)) in N_Has_Entity
6495 and then Is_Remote_Call_Interface (Entity (Name (N)))
6497 -- A subprogram declared in the spec of a RCI package is remote
6501 elsif Nkind (Name (N)) = N_Explicit_Dereference
6502 and then Is_Remote_Access_To_Subprogram_Type
6503 (Etype (Prefix (Name (N))))
6505 -- The dereference of a RAS is a remote call
6509 elsif Present (Controlling_Argument (N))
6510 and then Is_Remote_Access_To_Class_Wide_Type
6511 (Etype (Controlling_Argument (N)))
6513 -- Any primitive operation call with a controlling argument of
6514 -- a RACW type is a remote call.
6519 -- All other calls are local calls
6524 ----------------------
6525 -- Is_Renamed_Entry --
6526 ----------------------
6528 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6529 Orig_Node : Node_Id := Empty;
6530 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6532 function Is_Entry (Nam : Node_Id) return Boolean;
6533 -- Determine whether Nam is an entry. Traverse selectors if there are
6534 -- nested selected components.
6540 function Is_Entry (Nam : Node_Id) return Boolean is
6542 if Nkind (Nam) = N_Selected_Component then
6543 return Is_Entry (Selector_Name (Nam));
6546 return Ekind (Entity (Nam)) = E_Entry;
6549 -- Start of processing for Is_Renamed_Entry
6552 if Present (Alias (Proc_Nam)) then
6553 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6556 -- Look for a rewritten subprogram renaming declaration
6558 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6559 and then Present (Original_Node (Subp_Decl))
6561 Orig_Node := Original_Node (Subp_Decl);
6564 -- The rewritten subprogram is actually an entry
6566 if Present (Orig_Node)
6567 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6568 and then Is_Entry (Name (Orig_Node))
6574 end Is_Renamed_Entry;
6576 ----------------------
6577 -- Is_Selector_Name --
6578 ----------------------
6580 function Is_Selector_Name (N : Node_Id) return Boolean is
6582 if not Is_List_Member (N) then
6584 P : constant Node_Id := Parent (N);
6585 K : constant Node_Kind := Nkind (P);
6588 (K = N_Expanded_Name or else
6589 K = N_Generic_Association or else
6590 K = N_Parameter_Association or else
6591 K = N_Selected_Component)
6592 and then Selector_Name (P) = N;
6597 L : constant List_Id := List_Containing (N);
6598 P : constant Node_Id := Parent (L);
6600 return (Nkind (P) = N_Discriminant_Association
6601 and then Selector_Names (P) = L)
6603 (Nkind (P) = N_Component_Association
6604 and then Choices (P) = L);
6607 end Is_Selector_Name;
6613 function Is_Statement (N : Node_Id) return Boolean is
6616 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6617 or else Nkind (N) = N_Procedure_Call_Statement;
6620 ---------------------------------
6621 -- Is_Synchronized_Tagged_Type --
6622 ---------------------------------
6624 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6625 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6628 -- A task or protected type derived from an interface is a tagged type.
6629 -- Such a tagged type is called a synchronized tagged type, as are
6630 -- synchronized interfaces and private extensions whose declaration
6631 -- includes the reserved word synchronized.
6633 return (Is_Tagged_Type (E)
6634 and then (Kind = E_Task_Type
6635 or else Kind = E_Protected_Type))
6638 and then Is_Synchronized_Interface (E))
6640 (Ekind (E) = E_Record_Type_With_Private
6641 and then (Synchronized_Present (Parent (E))
6642 or else Is_Synchronized_Interface (Etype (E))));
6643 end Is_Synchronized_Tagged_Type;
6649 function Is_Transfer (N : Node_Id) return Boolean is
6650 Kind : constant Node_Kind := Nkind (N);
6653 if Kind = N_Simple_Return_Statement
6655 Kind = N_Extended_Return_Statement
6657 Kind = N_Goto_Statement
6659 Kind = N_Raise_Statement
6661 Kind = N_Requeue_Statement
6665 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6666 and then No (Condition (N))
6670 elsif Kind = N_Procedure_Call_Statement
6671 and then Is_Entity_Name (Name (N))
6672 and then Present (Entity (Name (N)))
6673 and then No_Return (Entity (Name (N)))
6677 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6689 function Is_True (U : Uint) return Boolean is
6698 function Is_Value_Type (T : Entity_Id) return Boolean is
6700 return VM_Target = CLI_Target
6701 and then Chars (T) /= No_Name
6702 and then Get_Name_String (Chars (T)) = "valuetype";
6709 function Is_Variable (N : Node_Id) return Boolean is
6711 Orig_Node : constant Node_Id := Original_Node (N);
6712 -- We do the test on the original node, since this is basically a
6713 -- test of syntactic categories, so it must not be disturbed by
6714 -- whatever rewriting might have occurred. For example, an aggregate,
6715 -- which is certainly NOT a variable, could be turned into a variable
6718 function In_Protected_Function (E : Entity_Id) return Boolean;
6719 -- Within a protected function, the private components of the
6720 -- enclosing protected type are constants. A function nested within
6721 -- a (protected) procedure is not itself protected.
6723 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6724 -- Prefixes can involve implicit dereferences, in which case we
6725 -- must test for the case of a reference of a constant access
6726 -- type, which can never be a variable.
6728 ---------------------------
6729 -- In_Protected_Function --
6730 ---------------------------
6732 function In_Protected_Function (E : Entity_Id) return Boolean is
6733 Prot : constant Entity_Id := Scope (E);
6737 if not Is_Protected_Type (Prot) then
6741 while Present (S) and then S /= Prot loop
6742 if Ekind (S) = E_Function
6743 and then Scope (S) = Prot
6753 end In_Protected_Function;
6755 ------------------------
6756 -- Is_Variable_Prefix --
6757 ------------------------
6759 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6761 if Is_Access_Type (Etype (P)) then
6762 return not Is_Access_Constant (Root_Type (Etype (P)));
6764 -- For the case of an indexed component whose prefix has a packed
6765 -- array type, the prefix has been rewritten into a type conversion.
6766 -- Determine variable-ness from the converted expression.
6768 elsif Nkind (P) = N_Type_Conversion
6769 and then not Comes_From_Source (P)
6770 and then Is_Array_Type (Etype (P))
6771 and then Is_Packed (Etype (P))
6773 return Is_Variable (Expression (P));
6776 return Is_Variable (P);
6778 end Is_Variable_Prefix;
6780 -- Start of processing for Is_Variable
6783 -- Definitely OK if Assignment_OK is set. Since this is something that
6784 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6786 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6789 -- Normally we go to the original node, but there is one exception
6790 -- where we use the rewritten node, namely when it is an explicit
6791 -- dereference. The generated code may rewrite a prefix which is an
6792 -- access type with an explicit dereference. The dereference is a
6793 -- variable, even though the original node may not be (since it could
6794 -- be a constant of the access type).
6796 -- In Ada 2005 we have a further case to consider: the prefix may be
6797 -- a function call given in prefix notation. The original node appears
6798 -- to be a selected component, but we need to examine the call.
6800 elsif Nkind (N) = N_Explicit_Dereference
6801 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6802 and then Present (Etype (Orig_Node))
6803 and then Is_Access_Type (Etype (Orig_Node))
6806 (Nkind (Orig_Node) = N_Function_Call
6807 and then not Is_Access_Constant (Etype (Prefix (N))))
6809 Is_Variable_Prefix (Original_Node (Prefix (N)));
6811 -- A function call is never a variable
6813 elsif Nkind (N) = N_Function_Call then
6816 -- All remaining checks use the original node
6818 elsif Is_Entity_Name (Orig_Node)
6819 and then Present (Entity (Orig_Node))
6822 E : constant Entity_Id := Entity (Orig_Node);
6823 K : constant Entity_Kind := Ekind (E);
6826 return (K = E_Variable
6827 and then Nkind (Parent (E)) /= N_Exception_Handler)
6828 or else (K = E_Component
6829 and then not In_Protected_Function (E))
6830 or else K = E_Out_Parameter
6831 or else K = E_In_Out_Parameter
6832 or else K = E_Generic_In_Out_Parameter
6834 -- Current instance of type:
6836 or else (Is_Type (E) and then In_Open_Scopes (E))
6837 or else (Is_Incomplete_Or_Private_Type (E)
6838 and then In_Open_Scopes (Full_View (E)));
6842 case Nkind (Orig_Node) is
6843 when N_Indexed_Component | N_Slice =>
6844 return Is_Variable_Prefix (Prefix (Orig_Node));
6846 when N_Selected_Component =>
6847 return Is_Variable_Prefix (Prefix (Orig_Node))
6848 and then Is_Variable (Selector_Name (Orig_Node));
6850 -- For an explicit dereference, the type of the prefix cannot
6851 -- be an access to constant or an access to subprogram.
6853 when N_Explicit_Dereference =>
6855 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6857 return Is_Access_Type (Typ)
6858 and then not Is_Access_Constant (Root_Type (Typ))
6859 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6862 -- The type conversion is the case where we do not deal with the
6863 -- context dependent special case of an actual parameter. Thus
6864 -- the type conversion is only considered a variable for the
6865 -- purposes of this routine if the target type is tagged. However,
6866 -- a type conversion is considered to be a variable if it does not
6867 -- come from source (this deals for example with the conversions
6868 -- of expressions to their actual subtypes).
6870 when N_Type_Conversion =>
6871 return Is_Variable (Expression (Orig_Node))
6873 (not Comes_From_Source (Orig_Node)
6875 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6877 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6879 -- GNAT allows an unchecked type conversion as a variable. This
6880 -- only affects the generation of internal expanded code, since
6881 -- calls to instantiations of Unchecked_Conversion are never
6882 -- considered variables (since they are function calls).
6883 -- This is also true for expression actions.
6885 when N_Unchecked_Type_Conversion =>
6886 return Is_Variable (Expression (Orig_Node));
6894 ------------------------
6895 -- Is_Volatile_Object --
6896 ------------------------
6898 function Is_Volatile_Object (N : Node_Id) return Boolean is
6900 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6901 -- Determines if given object has volatile components
6903 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6904 -- If prefix is an implicit dereference, examine designated type
6906 ------------------------
6907 -- Is_Volatile_Prefix --
6908 ------------------------
6910 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6911 Typ : constant Entity_Id := Etype (N);
6914 if Is_Access_Type (Typ) then
6916 Dtyp : constant Entity_Id := Designated_Type (Typ);
6919 return Is_Volatile (Dtyp)
6920 or else Has_Volatile_Components (Dtyp);
6924 return Object_Has_Volatile_Components (N);
6926 end Is_Volatile_Prefix;
6928 ------------------------------------
6929 -- Object_Has_Volatile_Components --
6930 ------------------------------------
6932 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6933 Typ : constant Entity_Id := Etype (N);
6936 if Is_Volatile (Typ)
6937 or else Has_Volatile_Components (Typ)
6941 elsif Is_Entity_Name (N)
6942 and then (Has_Volatile_Components (Entity (N))
6943 or else Is_Volatile (Entity (N)))
6947 elsif Nkind (N) = N_Indexed_Component
6948 or else Nkind (N) = N_Selected_Component
6950 return Is_Volatile_Prefix (Prefix (N));
6955 end Object_Has_Volatile_Components;
6957 -- Start of processing for Is_Volatile_Object
6960 if Is_Volatile (Etype (N))
6961 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6965 elsif Nkind (N) = N_Indexed_Component
6966 or else Nkind (N) = N_Selected_Component
6968 return Is_Volatile_Prefix (Prefix (N));
6973 end Is_Volatile_Object;
6975 -------------------------
6976 -- Kill_Current_Values --
6977 -------------------------
6979 procedure Kill_Current_Values
6981 Last_Assignment_Only : Boolean := False)
6984 if Is_Assignable (Ent) then
6985 Set_Last_Assignment (Ent, Empty);
6988 if not Last_Assignment_Only and then Is_Object (Ent) then
6990 Set_Current_Value (Ent, Empty);
6992 if not Can_Never_Be_Null (Ent) then
6993 Set_Is_Known_Non_Null (Ent, False);
6996 Set_Is_Known_Null (Ent, False);
6998 end Kill_Current_Values;
7000 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7003 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7004 -- Clear current value for entity E and all entities chained to E
7006 ------------------------------------------
7007 -- Kill_Current_Values_For_Entity_Chain --
7008 ------------------------------------------
7010 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7014 while Present (Ent) loop
7015 Kill_Current_Values (Ent, Last_Assignment_Only);
7018 end Kill_Current_Values_For_Entity_Chain;
7020 -- Start of processing for Kill_Current_Values
7023 -- Kill all saved checks, a special case of killing saved values
7025 if not Last_Assignment_Only then
7029 -- Loop through relevant scopes, which includes the current scope and
7030 -- any parent scopes if the current scope is a block or a package.
7035 -- Clear current values of all entities in current scope
7037 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7039 -- If scope is a package, also clear current values of all
7040 -- private entities in the scope.
7042 if Is_Package_Or_Generic_Package (S)
7043 or else Is_Concurrent_Type (S)
7045 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7048 -- If this is a not a subprogram, deal with parents
7050 if not Is_Subprogram (S) then
7052 exit Scope_Loop when S = Standard_Standard;
7056 end loop Scope_Loop;
7057 end Kill_Current_Values;
7059 --------------------------
7060 -- Kill_Size_Check_Code --
7061 --------------------------
7063 procedure Kill_Size_Check_Code (E : Entity_Id) is
7065 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7066 and then Present (Size_Check_Code (E))
7068 Remove (Size_Check_Code (E));
7069 Set_Size_Check_Code (E, Empty);
7071 end Kill_Size_Check_Code;
7073 --------------------------
7074 -- Known_To_Be_Assigned --
7075 --------------------------
7077 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7078 P : constant Node_Id := Parent (N);
7083 -- Test left side of assignment
7085 when N_Assignment_Statement =>
7086 return N = Name (P);
7088 -- Function call arguments are never lvalues
7090 when N_Function_Call =>
7093 -- Positional parameter for procedure or accept call
7095 when N_Procedure_Call_Statement |
7104 Proc := Get_Subprogram_Entity (P);
7110 -- If we are not a list member, something is strange, so
7111 -- be conservative and return False.
7113 if not Is_List_Member (N) then
7117 -- We are going to find the right formal by stepping forward
7118 -- through the formals, as we step backwards in the actuals.
7120 Form := First_Formal (Proc);
7123 -- If no formal, something is weird, so be conservative
7124 -- and return False.
7135 return Ekind (Form) /= E_In_Parameter;
7138 -- Named parameter for procedure or accept call
7140 when N_Parameter_Association =>
7146 Proc := Get_Subprogram_Entity (Parent (P));
7152 -- Loop through formals to find the one that matches
7154 Form := First_Formal (Proc);
7156 -- If no matching formal, that's peculiar, some kind of
7157 -- previous error, so return False to be conservative.
7163 -- Else test for match
7165 if Chars (Form) = Chars (Selector_Name (P)) then
7166 return Ekind (Form) /= E_In_Parameter;
7173 -- Test for appearing in a conversion that itself appears
7174 -- in an lvalue context, since this should be an lvalue.
7176 when N_Type_Conversion =>
7177 return Known_To_Be_Assigned (P);
7179 -- All other references are definitely not known to be modifications
7185 end Known_To_Be_Assigned;
7191 function May_Be_Lvalue (N : Node_Id) return Boolean is
7192 P : constant Node_Id := Parent (N);
7197 -- Test left side of assignment
7199 when N_Assignment_Statement =>
7200 return N = Name (P);
7202 -- Test prefix of component or attribute
7204 when N_Attribute_Reference =>
7205 return N = Prefix (P)
7206 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7208 when N_Expanded_Name |
7209 N_Explicit_Dereference |
7210 N_Indexed_Component |
7212 N_Selected_Component |
7214 return N = Prefix (P);
7216 -- Function call arguments are never lvalues
7218 when N_Function_Call =>
7221 -- Positional parameter for procedure, entry, or accept call
7223 when N_Procedure_Call_Statement |
7224 N_Entry_Call_Statement |
7233 Proc := Get_Subprogram_Entity (P);
7239 -- If we are not a list member, something is strange, so
7240 -- be conservative and return True.
7242 if not Is_List_Member (N) then
7246 -- We are going to find the right formal by stepping forward
7247 -- through the formals, as we step backwards in the actuals.
7249 Form := First_Formal (Proc);
7252 -- If no formal, something is weird, so be conservative
7264 return Ekind (Form) /= E_In_Parameter;
7267 -- Named parameter for procedure or accept call
7269 when N_Parameter_Association =>
7275 Proc := Get_Subprogram_Entity (Parent (P));
7281 -- Loop through formals to find the one that matches
7283 Form := First_Formal (Proc);
7285 -- If no matching formal, that's peculiar, some kind of
7286 -- previous error, so return True to be conservative.
7292 -- Else test for match
7294 if Chars (Form) = Chars (Selector_Name (P)) then
7295 return Ekind (Form) /= E_In_Parameter;
7302 -- Test for appearing in a conversion that itself appears in an
7303 -- lvalue context, since this should be an lvalue.
7305 when N_Type_Conversion =>
7306 return May_Be_Lvalue (P);
7308 -- Test for appearance in object renaming declaration
7310 when N_Object_Renaming_Declaration =>
7313 -- All other references are definitely not Lvalues
7321 -----------------------
7322 -- Mark_Coextensions --
7323 -----------------------
7325 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7326 Is_Dynamic : Boolean;
7327 -- Indicates whether the context causes nested coextensions to be
7328 -- dynamic or static
7330 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7331 -- Recognize an allocator node and label it as a dynamic coextension
7333 --------------------
7334 -- Mark_Allocator --
7335 --------------------
7337 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7339 if Nkind (N) = N_Allocator then
7341 Set_Is_Dynamic_Coextension (N);
7343 Set_Is_Static_Coextension (N);
7350 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7352 -- Start of processing Mark_Coextensions
7355 case Nkind (Context_Nod) is
7356 when N_Assignment_Statement |
7357 N_Simple_Return_Statement =>
7358 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7360 when N_Object_Declaration =>
7361 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7363 -- This routine should not be called for constructs which may not
7364 -- contain coextensions.
7367 raise Program_Error;
7370 Mark_Allocators (Root_Nod);
7371 end Mark_Coextensions;
7373 ----------------------
7374 -- Needs_One_Actual --
7375 ----------------------
7377 function Needs_One_Actual (E : Entity_Id) return Boolean is
7381 if Ada_Version >= Ada_05
7382 and then Present (First_Formal (E))
7384 Formal := Next_Formal (First_Formal (E));
7385 while Present (Formal) loop
7386 if No (Default_Value (Formal)) then
7390 Next_Formal (Formal);
7398 end Needs_One_Actual;
7400 -------------------------
7401 -- New_External_Entity --
7402 -------------------------
7404 function New_External_Entity
7405 (Kind : Entity_Kind;
7406 Scope_Id : Entity_Id;
7407 Sloc_Value : Source_Ptr;
7408 Related_Id : Entity_Id;
7410 Suffix_Index : Nat := 0;
7411 Prefix : Character := ' ') return Entity_Id
7413 N : constant Entity_Id :=
7414 Make_Defining_Identifier (Sloc_Value,
7416 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7419 Set_Ekind (N, Kind);
7420 Set_Is_Internal (N, True);
7421 Append_Entity (N, Scope_Id);
7422 Set_Public_Status (N);
7424 if Kind in Type_Kind then
7425 Init_Size_Align (N);
7429 end New_External_Entity;
7431 -------------------------
7432 -- New_Internal_Entity --
7433 -------------------------
7435 function New_Internal_Entity
7436 (Kind : Entity_Kind;
7437 Scope_Id : Entity_Id;
7438 Sloc_Value : Source_Ptr;
7439 Id_Char : Character) return Entity_Id
7441 N : constant Entity_Id :=
7442 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7445 Set_Ekind (N, Kind);
7446 Set_Is_Internal (N, True);
7447 Append_Entity (N, Scope_Id);
7449 if Kind in Type_Kind then
7450 Init_Size_Align (N);
7454 end New_Internal_Entity;
7460 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7464 -- If we are pointing at a positional parameter, it is a member of a
7465 -- node list (the list of parameters), and the next parameter is the
7466 -- next node on the list, unless we hit a parameter association, then
7467 -- we shift to using the chain whose head is the First_Named_Actual in
7468 -- the parent, and then is threaded using the Next_Named_Actual of the
7469 -- Parameter_Association. All this fiddling is because the original node
7470 -- list is in the textual call order, and what we need is the
7471 -- declaration order.
7473 if Is_List_Member (Actual_Id) then
7474 N := Next (Actual_Id);
7476 if Nkind (N) = N_Parameter_Association then
7477 return First_Named_Actual (Parent (Actual_Id));
7483 return Next_Named_Actual (Parent (Actual_Id));
7487 procedure Next_Actual (Actual_Id : in out Node_Id) is
7489 Actual_Id := Next_Actual (Actual_Id);
7492 -----------------------
7493 -- Normalize_Actuals --
7494 -----------------------
7496 -- Chain actuals according to formals of subprogram. If there are no named
7497 -- associations, the chain is simply the list of Parameter Associations,
7498 -- since the order is the same as the declaration order. If there are named
7499 -- associations, then the First_Named_Actual field in the N_Function_Call
7500 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7501 -- node for the parameter that comes first in declaration order. The
7502 -- remaining named parameters are then chained in declaration order using
7503 -- Next_Named_Actual.
7505 -- This routine also verifies that the number of actuals is compatible with
7506 -- the number and default values of formals, but performs no type checking
7507 -- (type checking is done by the caller).
7509 -- If the matching succeeds, Success is set to True and the caller proceeds
7510 -- with type-checking. If the match is unsuccessful, then Success is set to
7511 -- False, and the caller attempts a different interpretation, if there is
7514 -- If the flag Report is on, the call is not overloaded, and a failure to
7515 -- match can be reported here, rather than in the caller.
7517 procedure Normalize_Actuals
7521 Success : out Boolean)
7523 Actuals : constant List_Id := Parameter_Associations (N);
7524 Actual : Node_Id := Empty;
7526 Last : Node_Id := Empty;
7527 First_Named : Node_Id := Empty;
7530 Formals_To_Match : Integer := 0;
7531 Actuals_To_Match : Integer := 0;
7533 procedure Chain (A : Node_Id);
7534 -- Add named actual at the proper place in the list, using the
7535 -- Next_Named_Actual link.
7537 function Reporting return Boolean;
7538 -- Determines if an error is to be reported. To report an error, we
7539 -- need Report to be True, and also we do not report errors caused
7540 -- by calls to init procs that occur within other init procs. Such
7541 -- errors must always be cascaded errors, since if all the types are
7542 -- declared correctly, the compiler will certainly build decent calls!
7548 procedure Chain (A : Node_Id) is
7552 -- Call node points to first actual in list
7554 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7557 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7561 Set_Next_Named_Actual (Last, Empty);
7568 function Reporting return Boolean is
7573 elsif not Within_Init_Proc then
7576 elsif Is_Init_Proc (Entity (Name (N))) then
7584 -- Start of processing for Normalize_Actuals
7587 if Is_Access_Type (S) then
7589 -- The name in the call is a function call that returns an access
7590 -- to subprogram. The designated type has the list of formals.
7592 Formal := First_Formal (Designated_Type (S));
7594 Formal := First_Formal (S);
7597 while Present (Formal) loop
7598 Formals_To_Match := Formals_To_Match + 1;
7599 Next_Formal (Formal);
7602 -- Find if there is a named association, and verify that no positional
7603 -- associations appear after named ones.
7605 if Present (Actuals) then
7606 Actual := First (Actuals);
7609 while Present (Actual)
7610 and then Nkind (Actual) /= N_Parameter_Association
7612 Actuals_To_Match := Actuals_To_Match + 1;
7616 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7618 -- Most common case: positional notation, no defaults
7623 elsif Actuals_To_Match > Formals_To_Match then
7625 -- Too many actuals: will not work
7628 if Is_Entity_Name (Name (N)) then
7629 Error_Msg_N ("too many arguments in call to&", Name (N));
7631 Error_Msg_N ("too many arguments in call", N);
7639 First_Named := Actual;
7641 while Present (Actual) loop
7642 if Nkind (Actual) /= N_Parameter_Association then
7644 ("positional parameters not allowed after named ones", Actual);
7649 Actuals_To_Match := Actuals_To_Match + 1;
7655 if Present (Actuals) then
7656 Actual := First (Actuals);
7659 Formal := First_Formal (S);
7660 while Present (Formal) loop
7662 -- Match the formals in order. If the corresponding actual is
7663 -- positional, nothing to do. Else scan the list of named actuals
7664 -- to find the one with the right name.
7667 and then Nkind (Actual) /= N_Parameter_Association
7670 Actuals_To_Match := Actuals_To_Match - 1;
7671 Formals_To_Match := Formals_To_Match - 1;
7674 -- For named parameters, search the list of actuals to find
7675 -- one that matches the next formal name.
7677 Actual := First_Named;
7679 while Present (Actual) loop
7680 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7683 Actuals_To_Match := Actuals_To_Match - 1;
7684 Formals_To_Match := Formals_To_Match - 1;
7692 if Ekind (Formal) /= E_In_Parameter
7693 or else No (Default_Value (Formal))
7696 if (Comes_From_Source (S)
7697 or else Sloc (S) = Standard_Location)
7698 and then Is_Overloadable (S)
7702 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7704 (Nkind (Parent (N)) = N_Function_Call
7706 Nkind (Parent (N)) = N_Parameter_Association))
7707 and then Ekind (S) /= E_Function
7709 Set_Etype (N, Etype (S));
7711 Error_Msg_Name_1 := Chars (S);
7712 Error_Msg_Sloc := Sloc (S);
7714 ("missing argument for parameter & " &
7715 "in call to % declared #", N, Formal);
7718 elsif Is_Overloadable (S) then
7719 Error_Msg_Name_1 := Chars (S);
7721 -- Point to type derivation that generated the
7724 Error_Msg_Sloc := Sloc (Parent (S));
7727 ("missing argument for parameter & " &
7728 "in call to % (inherited) #", N, Formal);
7732 ("missing argument for parameter &", N, Formal);
7740 Formals_To_Match := Formals_To_Match - 1;
7745 Next_Formal (Formal);
7748 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7755 -- Find some superfluous named actual that did not get
7756 -- attached to the list of associations.
7758 Actual := First (Actuals);
7759 while Present (Actual) loop
7760 if Nkind (Actual) = N_Parameter_Association
7761 and then Actual /= Last
7762 and then No (Next_Named_Actual (Actual))
7764 Error_Msg_N ("unmatched actual & in call",
7765 Selector_Name (Actual));
7776 end Normalize_Actuals;
7778 --------------------------------
7779 -- Note_Possible_Modification --
7780 --------------------------------
7782 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
7783 Modification_Comes_From_Source : constant Boolean :=
7784 Comes_From_Source (Parent (N));
7790 -- Loop to find referenced entity, if there is one
7797 if Is_Entity_Name (Exp) then
7798 Ent := Entity (Exp);
7800 -- If the entity is missing, it is an undeclared identifier,
7801 -- and there is nothing to annotate.
7807 elsif Nkind (Exp) = N_Explicit_Dereference then
7809 P : constant Node_Id := Prefix (Exp);
7812 if Nkind (P) = N_Selected_Component
7814 Entry_Formal (Entity (Selector_Name (P))))
7816 -- Case of a reference to an entry formal
7818 Ent := Entry_Formal (Entity (Selector_Name (P)));
7820 elsif Nkind (P) = N_Identifier
7821 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7822 and then Present (Expression (Parent (Entity (P))))
7823 and then Nkind (Expression (Parent (Entity (P))))
7826 -- Case of a reference to a value on which side effects have
7829 Exp := Prefix (Expression (Parent (Entity (P))));
7838 elsif Nkind (Exp) = N_Type_Conversion
7839 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7841 Exp := Expression (Exp);
7844 elsif Nkind (Exp) = N_Slice
7845 or else Nkind (Exp) = N_Indexed_Component
7846 or else Nkind (Exp) = N_Selected_Component
7848 Exp := Prefix (Exp);
7855 -- Now look for entity being referenced
7857 if Present (Ent) then
7858 if Is_Object (Ent) then
7859 if Comes_From_Source (Exp)
7860 or else Modification_Comes_From_Source
7862 if Has_Pragma_Unmodified (Ent) then
7863 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
7866 Set_Never_Set_In_Source (Ent, False);
7869 Set_Is_True_Constant (Ent, False);
7870 Set_Current_Value (Ent, Empty);
7871 Set_Is_Known_Null (Ent, False);
7873 if not Can_Never_Be_Null (Ent) then
7874 Set_Is_Known_Non_Null (Ent, False);
7877 -- Follow renaming chain
7879 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7880 and then Present (Renamed_Object (Ent))
7882 Exp := Renamed_Object (Ent);
7886 -- Generate a reference only if the assignment comes from
7887 -- source. This excludes, for example, calls to a dispatching
7888 -- assignment operation when the left-hand side is tagged.
7890 if Modification_Comes_From_Source then
7891 Generate_Reference (Ent, Exp, 'm');
7894 Check_Nested_Access (Ent);
7899 -- If we are sure this is a modification from source, and we know
7900 -- this modifies a constant, then give an appropriate warning.
7902 if Overlays_Constant (Ent)
7903 and then Modification_Comes_From_Source
7907 A : constant Node_Id := Address_Clause (Ent);
7911 Exp : constant Node_Id := Expression (A);
7913 if Nkind (Exp) = N_Attribute_Reference
7914 and then Attribute_Name (Exp) = Name_Address
7915 and then Is_Entity_Name (Prefix (Exp))
7917 Error_Msg_Sloc := Sloc (A);
7919 ("constant& may be modified via address clause#?",
7920 N, Entity (Prefix (Exp)));
7930 end Note_Possible_Modification;
7932 -------------------------
7933 -- Object_Access_Level --
7934 -------------------------
7936 function Object_Access_Level (Obj : Node_Id) return Uint is
7939 -- Returns the static accessibility level of the view denoted by Obj. Note
7940 -- that the value returned is the result of a call to Scope_Depth. Only
7941 -- scope depths associated with dynamic scopes can actually be returned.
7942 -- Since only relative levels matter for accessibility checking, the fact
7943 -- that the distance between successive levels of accessibility is not
7944 -- always one is immaterial (invariant: if level(E2) is deeper than
7945 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7947 function Reference_To (Obj : Node_Id) return Node_Id;
7948 -- An explicit dereference is created when removing side-effects from
7949 -- expressions for constraint checking purposes. In this case a local
7950 -- access type is created for it. The correct access level is that of
7951 -- the original source node. We detect this case by noting that the
7952 -- prefix of the dereference is created by an object declaration whose
7953 -- initial expression is a reference.
7959 function Reference_To (Obj : Node_Id) return Node_Id is
7960 Pref : constant Node_Id := Prefix (Obj);
7962 if Is_Entity_Name (Pref)
7963 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7964 and then Present (Expression (Parent (Entity (Pref))))
7965 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7967 return (Prefix (Expression (Parent (Entity (Pref)))));
7973 -- Start of processing for Object_Access_Level
7976 if Is_Entity_Name (Obj) then
7979 if Is_Prival (E) then
7980 E := Prival_Link (E);
7983 -- If E is a type then it denotes a current instance. For this case
7984 -- we add one to the normal accessibility level of the type to ensure
7985 -- that current instances are treated as always being deeper than
7986 -- than the level of any visible named access type (see 3.10.2(21)).
7989 return Type_Access_Level (E) + 1;
7991 elsif Present (Renamed_Object (E)) then
7992 return Object_Access_Level (Renamed_Object (E));
7994 -- Similarly, if E is a component of the current instance of a
7995 -- protected type, any instance of it is assumed to be at a deeper
7996 -- level than the type. For a protected object (whose type is an
7997 -- anonymous protected type) its components are at the same level
7998 -- as the type itself.
8000 elsif not Is_Overloadable (E)
8001 and then Ekind (Scope (E)) = E_Protected_Type
8002 and then Comes_From_Source (Scope (E))
8004 return Type_Access_Level (Scope (E)) + 1;
8007 return Scope_Depth (Enclosing_Dynamic_Scope (E));
8010 elsif Nkind (Obj) = N_Selected_Component then
8011 if Is_Access_Type (Etype (Prefix (Obj))) then
8012 return Type_Access_Level (Etype (Prefix (Obj)));
8014 return Object_Access_Level (Prefix (Obj));
8017 elsif Nkind (Obj) = N_Indexed_Component then
8018 if Is_Access_Type (Etype (Prefix (Obj))) then
8019 return Type_Access_Level (Etype (Prefix (Obj)));
8021 return Object_Access_Level (Prefix (Obj));
8024 elsif Nkind (Obj) = N_Explicit_Dereference then
8026 -- If the prefix is a selected access discriminant then we make a
8027 -- recursive call on the prefix, which will in turn check the level
8028 -- of the prefix object of the selected discriminant.
8030 if Nkind (Prefix (Obj)) = N_Selected_Component
8031 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
8033 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
8035 return Object_Access_Level (Prefix (Obj));
8037 elsif not (Comes_From_Source (Obj)) then
8039 Ref : constant Node_Id := Reference_To (Obj);
8041 if Present (Ref) then
8042 return Object_Access_Level (Ref);
8044 return Type_Access_Level (Etype (Prefix (Obj)));
8049 return Type_Access_Level (Etype (Prefix (Obj)));
8052 elsif Nkind (Obj) = N_Type_Conversion
8053 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8055 return Object_Access_Level (Expression (Obj));
8057 -- Function results are objects, so we get either the access level of
8058 -- the function or, in the case of an indirect call, the level of the
8059 -- access-to-subprogram type.
8061 elsif Nkind (Obj) = N_Function_Call then
8062 if Is_Entity_Name (Name (Obj)) then
8063 return Subprogram_Access_Level (Entity (Name (Obj)));
8065 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8068 -- For convenience we handle qualified expressions, even though
8069 -- they aren't technically object names.
8071 elsif Nkind (Obj) = N_Qualified_Expression then
8072 return Object_Access_Level (Expression (Obj));
8074 -- Otherwise return the scope level of Standard.
8075 -- (If there are cases that fall through
8076 -- to this point they will be treated as
8077 -- having global accessibility for now. ???)
8080 return Scope_Depth (Standard_Standard);
8082 end Object_Access_Level;
8084 -----------------------
8085 -- Private_Component --
8086 -----------------------
8088 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8089 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8091 function Trace_Components
8093 Check : Boolean) return Entity_Id;
8094 -- Recursive function that does the work, and checks against circular
8095 -- definition for each subcomponent type.
8097 ----------------------
8098 -- Trace_Components --
8099 ----------------------
8101 function Trace_Components
8103 Check : Boolean) return Entity_Id
8105 Btype : constant Entity_Id := Base_Type (T);
8106 Component : Entity_Id;
8108 Candidate : Entity_Id := Empty;
8111 if Check and then Btype = Ancestor then
8112 Error_Msg_N ("circular type definition", Type_Id);
8116 if Is_Private_Type (Btype)
8117 and then not Is_Generic_Type (Btype)
8119 if Present (Full_View (Btype))
8120 and then Is_Record_Type (Full_View (Btype))
8121 and then not Is_Frozen (Btype)
8123 -- To indicate that the ancestor depends on a private type, the
8124 -- current Btype is sufficient. However, to check for circular
8125 -- definition we must recurse on the full view.
8127 Candidate := Trace_Components (Full_View (Btype), True);
8129 if Candidate = Any_Type then
8139 elsif Is_Array_Type (Btype) then
8140 return Trace_Components (Component_Type (Btype), True);
8142 elsif Is_Record_Type (Btype) then
8143 Component := First_Entity (Btype);
8144 while Present (Component) loop
8146 -- Skip anonymous types generated by constrained components
8148 if not Is_Type (Component) then
8149 P := Trace_Components (Etype (Component), True);
8152 if P = Any_Type then
8160 Next_Entity (Component);
8168 end Trace_Components;
8170 -- Start of processing for Private_Component
8173 return Trace_Components (Type_Id, False);
8174 end Private_Component;
8176 ---------------------------
8177 -- Primitive_Names_Match --
8178 ---------------------------
8180 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
8182 function Non_Internal_Name (E : Entity_Id) return Name_Id;
8183 -- Given an internal name, returns the corresponding non-internal name
8185 ------------------------
8186 -- Non_Internal_Name --
8187 ------------------------
8189 function Non_Internal_Name (E : Entity_Id) return Name_Id is
8191 Get_Name_String (Chars (E));
8192 Name_Len := Name_Len - 1;
8194 end Non_Internal_Name;
8196 -- Start of processing for Primitive_Names_Match
8199 pragma Assert (Present (E1) and then Present (E2));
8201 return Chars (E1) = Chars (E2)
8203 (not Is_Internal_Name (Chars (E1))
8204 and then Is_Internal_Name (Chars (E2))
8205 and then Non_Internal_Name (E2) = Chars (E1))
8207 (not Is_Internal_Name (Chars (E2))
8208 and then Is_Internal_Name (Chars (E1))
8209 and then Non_Internal_Name (E1) = Chars (E2))
8211 (Is_Predefined_Dispatching_Operation (E1)
8212 and then Is_Predefined_Dispatching_Operation (E2)
8213 and then Same_TSS (E1, E2))
8215 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
8216 end Primitive_Names_Match;
8218 -----------------------
8219 -- Process_End_Label --
8220 -----------------------
8222 procedure Process_End_Label
8231 Label_Ref : Boolean;
8232 -- Set True if reference to end label itself is required
8235 -- Gets set to the operator symbol or identifier that references the
8236 -- entity Ent. For the child unit case, this is the identifier from the
8237 -- designator. For other cases, this is simply Endl.
8239 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8240 -- N is an identifier node that appears as a parent unit reference in
8241 -- the case where Ent is a child unit. This procedure generates an
8242 -- appropriate cross-reference entry. E is the corresponding entity.
8244 -------------------------
8245 -- Generate_Parent_Ref --
8246 -------------------------
8248 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8250 -- If names do not match, something weird, skip reference
8252 if Chars (E) = Chars (N) then
8254 -- Generate the reference. We do NOT consider this as a reference
8255 -- for unreferenced symbol purposes.
8257 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8260 Style.Check_Identifier (N, E);
8263 end Generate_Parent_Ref;
8265 -- Start of processing for Process_End_Label
8268 -- If no node, ignore. This happens in some error situations, and
8269 -- also for some internally generated structures where no end label
8270 -- references are required in any case.
8276 -- Nothing to do if no End_Label, happens for internally generated
8277 -- constructs where we don't want an end label reference anyway. Also
8278 -- nothing to do if Endl is a string literal, which means there was
8279 -- some prior error (bad operator symbol)
8281 Endl := End_Label (N);
8283 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8287 -- Reference node is not in extended main source unit
8289 if not In_Extended_Main_Source_Unit (N) then
8291 -- Generally we do not collect references except for the extended
8292 -- main source unit. The one exception is the 'e' entry for a
8293 -- package spec, where it is useful for a client to have the
8294 -- ending information to define scopes.
8302 -- For this case, we can ignore any parent references, but we
8303 -- need the package name itself for the 'e' entry.
8305 if Nkind (Endl) = N_Designator then
8306 Endl := Identifier (Endl);
8310 -- Reference is in extended main source unit
8315 -- For designator, generate references for the parent entries
8317 if Nkind (Endl) = N_Designator then
8319 -- Generate references for the prefix if the END line comes from
8320 -- source (otherwise we do not need these references) We climb the
8321 -- scope stack to find the expected entities.
8323 if Comes_From_Source (Endl) then
8325 Scop := Current_Scope;
8326 while Nkind (Nam) = N_Selected_Component loop
8327 Scop := Scope (Scop);
8328 exit when No (Scop);
8329 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8330 Nam := Prefix (Nam);
8333 if Present (Scop) then
8334 Generate_Parent_Ref (Nam, Scope (Scop));
8338 Endl := Identifier (Endl);
8342 -- If the end label is not for the given entity, then either we have
8343 -- some previous error, or this is a generic instantiation for which
8344 -- we do not need to make a cross-reference in this case anyway. In
8345 -- either case we simply ignore the call.
8347 if Chars (Ent) /= Chars (Endl) then
8351 -- If label was really there, then generate a normal reference and then
8352 -- adjust the location in the end label to point past the name (which
8353 -- should almost always be the semicolon).
8357 if Comes_From_Source (Endl) then
8359 -- If a label reference is required, then do the style check and
8360 -- generate an l-type cross-reference entry for the label
8364 Style.Check_Identifier (Endl, Ent);
8367 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8370 -- Set the location to point past the label (normally this will
8371 -- mean the semicolon immediately following the label). This is
8372 -- done for the sake of the 'e' or 't' entry generated below.
8374 Get_Decoded_Name_String (Chars (Endl));
8375 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8378 -- Now generate the e/t reference
8380 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8382 -- Restore Sloc, in case modified above, since we have an identifier
8383 -- and the normal Sloc should be left set in the tree.
8385 Set_Sloc (Endl, Loc);
8386 end Process_End_Label;
8392 -- We do the conversion to get the value of the real string by using
8393 -- the scanner, see Sinput for details on use of the internal source
8394 -- buffer for scanning internal strings.
8396 function Real_Convert (S : String) return Node_Id is
8397 Save_Src : constant Source_Buffer_Ptr := Source;
8401 Source := Internal_Source_Ptr;
8404 for J in S'Range loop
8405 Source (Source_Ptr (J)) := S (J);
8408 Source (S'Length + 1) := EOF;
8410 if Source (Scan_Ptr) = '-' then
8412 Scan_Ptr := Scan_Ptr + 1;
8420 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8427 --------------------
8428 -- Remove_Homonym --
8429 --------------------
8431 procedure Remove_Homonym (E : Entity_Id) is
8432 Prev : Entity_Id := Empty;
8436 if E = Current_Entity (E) then
8437 if Present (Homonym (E)) then
8438 Set_Current_Entity (Homonym (E));
8440 Set_Name_Entity_Id (Chars (E), Empty);
8443 H := Current_Entity (E);
8444 while Present (H) and then H /= E loop
8449 Set_Homonym (Prev, Homonym (E));
8453 ---------------------
8454 -- Rep_To_Pos_Flag --
8455 ---------------------
8457 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8459 return New_Occurrence_Of
8460 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8461 end Rep_To_Pos_Flag;
8463 --------------------
8464 -- Require_Entity --
8465 --------------------
8467 procedure Require_Entity (N : Node_Id) is
8469 if Is_Entity_Name (N) and then No (Entity (N)) then
8470 if Total_Errors_Detected /= 0 then
8471 Set_Entity (N, Any_Id);
8473 raise Program_Error;
8478 ------------------------------
8479 -- Requires_Transient_Scope --
8480 ------------------------------
8482 -- A transient scope is required when variable-sized temporaries are
8483 -- allocated in the primary or secondary stack, or when finalization
8484 -- actions must be generated before the next instruction.
8486 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8487 Typ : constant Entity_Id := Underlying_Type (Id);
8489 -- Start of processing for Requires_Transient_Scope
8492 -- This is a private type which is not completed yet. This can only
8493 -- happen in a default expression (of a formal parameter or of a
8494 -- record component). Do not expand transient scope in this case
8499 -- Do not expand transient scope for non-existent procedure return
8501 elsif Typ = Standard_Void_Type then
8504 -- Elementary types do not require a transient scope
8506 elsif Is_Elementary_Type (Typ) then
8509 -- Generally, indefinite subtypes require a transient scope, since the
8510 -- back end cannot generate temporaries, since this is not a valid type
8511 -- for declaring an object. It might be possible to relax this in the
8512 -- future, e.g. by declaring the maximum possible space for the type.
8514 elsif Is_Indefinite_Subtype (Typ) then
8517 -- Functions returning tagged types may dispatch on result so their
8518 -- returned value is allocated on the secondary stack. Controlled
8519 -- type temporaries need finalization.
8521 elsif Is_Tagged_Type (Typ)
8522 or else Has_Controlled_Component (Typ)
8524 return not Is_Value_Type (Typ);
8528 elsif Is_Record_Type (Typ) then
8532 Comp := First_Entity (Typ);
8533 while Present (Comp) loop
8534 if Ekind (Comp) = E_Component
8535 and then Requires_Transient_Scope (Etype (Comp))
8546 -- String literal types never require transient scope
8548 elsif Ekind (Typ) = E_String_Literal_Subtype then
8551 -- Array type. Note that we already know that this is a constrained
8552 -- array, since unconstrained arrays will fail the indefinite test.
8554 elsif Is_Array_Type (Typ) then
8556 -- If component type requires a transient scope, the array does too
8558 if Requires_Transient_Scope (Component_Type (Typ)) then
8561 -- Otherwise, we only need a transient scope if the size is not
8562 -- known at compile time.
8565 return not Size_Known_At_Compile_Time (Typ);
8568 -- All other cases do not require a transient scope
8573 end Requires_Transient_Scope;
8575 --------------------------
8576 -- Reset_Analyzed_Flags --
8577 --------------------------
8579 procedure Reset_Analyzed_Flags (N : Node_Id) is
8581 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8582 -- Function used to reset Analyzed flags in tree. Note that we do
8583 -- not reset Analyzed flags in entities, since there is no need to
8584 -- reanalyze entities, and indeed, it is wrong to do so, since it
8585 -- can result in generating auxiliary stuff more than once.
8587 --------------------
8588 -- Clear_Analyzed --
8589 --------------------
8591 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8593 if not Has_Extension (N) then
8594 Set_Analyzed (N, False);
8600 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8602 -- Start of processing for Reset_Analyzed_Flags
8606 end Reset_Analyzed_Flags;
8608 ---------------------------
8609 -- Safe_To_Capture_Value --
8610 ---------------------------
8612 function Safe_To_Capture_Value
8615 Cond : Boolean := False) return Boolean
8618 -- The only entities for which we track constant values are variables
8619 -- which are not renamings, constants, out parameters, and in out
8620 -- parameters, so check if we have this case.
8622 -- Note: it may seem odd to track constant values for constants, but in
8623 -- fact this routine is used for other purposes than simply capturing
8624 -- the value. In particular, the setting of Known[_Non]_Null.
8626 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8628 Ekind (Ent) = E_Constant
8630 Ekind (Ent) = E_Out_Parameter
8632 Ekind (Ent) = E_In_Out_Parameter
8636 -- For conditionals, we also allow loop parameters and all formals,
8637 -- including in parameters.
8641 (Ekind (Ent) = E_Loop_Parameter
8643 Ekind (Ent) = E_In_Parameter)
8647 -- For all other cases, not just unsafe, but impossible to capture
8648 -- Current_Value, since the above are the only entities which have
8649 -- Current_Value fields.
8655 -- Skip if volatile or aliased, since funny things might be going on in
8656 -- these cases which we cannot necessarily track. Also skip any variable
8657 -- for which an address clause is given, or whose address is taken. Also
8658 -- never capture value of library level variables (an attempt to do so
8659 -- can occur in the case of package elaboration code).
8661 if Treat_As_Volatile (Ent)
8662 or else Is_Aliased (Ent)
8663 or else Present (Address_Clause (Ent))
8664 or else Address_Taken (Ent)
8665 or else (Is_Library_Level_Entity (Ent)
8666 and then Ekind (Ent) = E_Variable)
8671 -- OK, all above conditions are met. We also require that the scope of
8672 -- the reference be the same as the scope of the entity, not counting
8673 -- packages and blocks and loops.
8676 E_Scope : constant Entity_Id := Scope (Ent);
8677 R_Scope : Entity_Id;
8680 R_Scope := Current_Scope;
8681 while R_Scope /= Standard_Standard loop
8682 exit when R_Scope = E_Scope;
8684 if Ekind (R_Scope) /= E_Package
8686 Ekind (R_Scope) /= E_Block
8688 Ekind (R_Scope) /= E_Loop
8692 R_Scope := Scope (R_Scope);
8697 -- We also require that the reference does not appear in a context
8698 -- where it is not sure to be executed (i.e. a conditional context
8699 -- or an exception handler). We skip this if Cond is True, since the
8700 -- capturing of values from conditional tests handles this ok.
8714 while Present (P) loop
8715 if Nkind (P) = N_If_Statement
8716 or else Nkind (P) = N_Case_Statement
8717 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8718 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8719 or else Nkind (P) = N_Exception_Handler
8720 or else Nkind (P) = N_Selective_Accept
8721 or else Nkind (P) = N_Conditional_Entry_Call
8722 or else Nkind (P) = N_Timed_Entry_Call
8723 or else Nkind (P) = N_Asynchronous_Select
8733 -- OK, looks safe to set value
8736 end Safe_To_Capture_Value;
8742 function Same_Name (N1, N2 : Node_Id) return Boolean is
8743 K1 : constant Node_Kind := Nkind (N1);
8744 K2 : constant Node_Kind := Nkind (N2);
8747 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8748 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8750 return Chars (N1) = Chars (N2);
8752 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8753 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8755 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8756 and then Same_Name (Prefix (N1), Prefix (N2));
8767 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8768 N1 : constant Node_Id := Original_Node (Node1);
8769 N2 : constant Node_Id := Original_Node (Node2);
8770 -- We do the tests on original nodes, since we are most interested
8771 -- in the original source, not any expansion that got in the way.
8773 K1 : constant Node_Kind := Nkind (N1);
8774 K2 : constant Node_Kind := Nkind (N2);
8777 -- First case, both are entities with same entity
8779 if K1 in N_Has_Entity
8780 and then K2 in N_Has_Entity
8781 and then Present (Entity (N1))
8782 and then Present (Entity (N2))
8783 and then (Ekind (Entity (N1)) = E_Variable
8785 Ekind (Entity (N1)) = E_Constant)
8786 and then Entity (N1) = Entity (N2)
8790 -- Second case, selected component with same selector, same record
8792 elsif K1 = N_Selected_Component
8793 and then K2 = N_Selected_Component
8794 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8796 return Same_Object (Prefix (N1), Prefix (N2));
8798 -- Third case, indexed component with same subscripts, same array
8800 elsif K1 = N_Indexed_Component
8801 and then K2 = N_Indexed_Component
8802 and then Same_Object (Prefix (N1), Prefix (N2))
8807 E1 := First (Expressions (N1));
8808 E2 := First (Expressions (N2));
8809 while Present (E1) loop
8810 if not Same_Value (E1, E2) then
8821 -- Fourth case, slice of same array with same bounds
8824 and then K2 = N_Slice
8825 and then Nkind (Discrete_Range (N1)) = N_Range
8826 and then Nkind (Discrete_Range (N2)) = N_Range
8827 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8828 Low_Bound (Discrete_Range (N2)))
8829 and then Same_Value (High_Bound (Discrete_Range (N1)),
8830 High_Bound (Discrete_Range (N2)))
8832 return Same_Name (Prefix (N1), Prefix (N2));
8834 -- All other cases, not clearly the same object
8845 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8850 elsif not Is_Constrained (T1)
8851 and then not Is_Constrained (T2)
8852 and then Base_Type (T1) = Base_Type (T2)
8856 -- For now don't bother with case of identical constraints, to be
8857 -- fiddled with later on perhaps (this is only used for optimization
8858 -- purposes, so it is not critical to do a best possible job)
8869 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8871 if Compile_Time_Known_Value (Node1)
8872 and then Compile_Time_Known_Value (Node2)
8873 and then Expr_Value (Node1) = Expr_Value (Node2)
8876 elsif Same_Object (Node1, Node2) then
8883 ------------------------
8884 -- Scope_Is_Transient --
8885 ------------------------
8887 function Scope_Is_Transient return Boolean is
8889 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8890 end Scope_Is_Transient;
8896 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8901 while Scop /= Standard_Standard loop
8902 Scop := Scope (Scop);
8904 if Scop = Scope2 then
8912 --------------------------
8913 -- Scope_Within_Or_Same --
8914 --------------------------
8916 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8921 while Scop /= Standard_Standard loop
8922 if Scop = Scope2 then
8925 Scop := Scope (Scop);
8930 end Scope_Within_Or_Same;
8932 --------------------
8933 -- Set_Convention --
8934 --------------------
8936 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
8938 Basic_Set_Convention (E, Val);
8941 and then Is_Access_Subprogram_Type (Base_Type (E))
8942 and then Has_Foreign_Convention (E)
8944 Set_Can_Use_Internal_Rep (E, False);
8948 ------------------------
8949 -- Set_Current_Entity --
8950 ------------------------
8952 -- The given entity is to be set as the currently visible definition
8953 -- of its associated name (i.e. the Node_Id associated with its name).
8954 -- All we have to do is to get the name from the identifier, and
8955 -- then set the associated Node_Id to point to the given entity.
8957 procedure Set_Current_Entity (E : Entity_Id) is
8959 Set_Name_Entity_Id (Chars (E), E);
8960 end Set_Current_Entity;
8962 ---------------------------
8963 -- Set_Debug_Info_Needed --
8964 ---------------------------
8966 procedure Set_Debug_Info_Needed (T : Entity_Id) is
8968 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
8969 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
8970 -- Used to set debug info in a related node if not set already
8972 --------------------------------------
8973 -- Set_Debug_Info_Needed_If_Not_Set --
8974 --------------------------------------
8976 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
8979 and then not Needs_Debug_Info (E)
8981 Set_Debug_Info_Needed (E);
8983 -- For a private type, indicate that the full view also needs
8984 -- debug information.
8987 and then Is_Private_Type (E)
8988 and then Present (Full_View (E))
8990 Set_Debug_Info_Needed (Full_View (E));
8993 end Set_Debug_Info_Needed_If_Not_Set;
8995 -- Start of processing for Set_Debug_Info_Needed
8998 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
8999 -- indicates that Debug_Info_Needed is never required for the entity.
9002 or else Debug_Info_Off (T)
9007 -- Set flag in entity itself. Note that we will go through the following
9008 -- circuitry even if the flag is already set on T. That's intentional,
9009 -- it makes sure that the flag will be set in subsidiary entities.
9011 Set_Needs_Debug_Info (T);
9013 -- Set flag on subsidiary entities if not set already
9015 if Is_Object (T) then
9016 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9018 elsif Is_Type (T) then
9019 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9021 if Is_Record_Type (T) then
9023 Ent : Entity_Id := First_Entity (T);
9025 while Present (Ent) loop
9026 Set_Debug_Info_Needed_If_Not_Set (Ent);
9031 elsif Is_Array_Type (T) then
9032 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
9035 Indx : Node_Id := First_Index (T);
9037 while Present (Indx) loop
9038 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
9039 Indx := Next_Index (Indx);
9043 if Is_Packed (T) then
9044 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
9047 elsif Is_Access_Type (T) then
9048 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
9050 elsif Is_Private_Type (T) then
9051 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9053 elsif Is_Protected_Type (T) then
9054 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9057 end Set_Debug_Info_Needed;
9059 ---------------------------------
9060 -- Set_Entity_With_Style_Check --
9061 ---------------------------------
9063 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9064 Val_Actual : Entity_Id;
9068 Set_Entity (N, Val);
9071 and then not Suppress_Style_Checks (Val)
9072 and then not In_Instance
9074 if Nkind (N) = N_Identifier then
9076 elsif Nkind (N) = N_Expanded_Name then
9077 Nod := Selector_Name (N);
9082 -- A special situation arises for derived operations, where we want
9083 -- to do the check against the parent (since the Sloc of the derived
9084 -- operation points to the derived type declaration itself).
9087 while not Comes_From_Source (Val_Actual)
9088 and then Nkind (Val_Actual) in N_Entity
9089 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9090 or else Is_Subprogram (Val_Actual)
9091 or else Is_Generic_Subprogram (Val_Actual))
9092 and then Present (Alias (Val_Actual))
9094 Val_Actual := Alias (Val_Actual);
9097 -- Renaming declarations for generic actuals do not come from source,
9098 -- and have a different name from that of the entity they rename, so
9099 -- there is no style check to perform here.
9101 if Chars (Nod) = Chars (Val_Actual) then
9102 Style.Check_Identifier (Nod, Val_Actual);
9106 Set_Entity (N, Val);
9107 end Set_Entity_With_Style_Check;
9109 ------------------------
9110 -- Set_Name_Entity_Id --
9111 ------------------------
9113 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9115 Set_Name_Table_Info (Id, Int (Val));
9116 end Set_Name_Entity_Id;
9118 ---------------------
9119 -- Set_Next_Actual --
9120 ---------------------
9122 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9124 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9125 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9127 end Set_Next_Actual;
9129 ----------------------------------
9130 -- Set_Optimize_Alignment_Flags --
9131 ----------------------------------
9133 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
9135 if Optimize_Alignment = 'S' then
9136 Set_Optimize_Alignment_Space (E);
9137 elsif Optimize_Alignment = 'T' then
9138 Set_Optimize_Alignment_Time (E);
9140 end Set_Optimize_Alignment_Flags;
9142 -----------------------
9143 -- Set_Public_Status --
9144 -----------------------
9146 procedure Set_Public_Status (Id : Entity_Id) is
9147 S : constant Entity_Id := Current_Scope;
9149 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
9150 -- Determines if E is defined within handled statement sequence or
9151 -- an if statement, returns True if so, False otherwise.
9153 ----------------------
9154 -- Within_HSS_Or_If --
9155 ----------------------
9157 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
9160 N := Declaration_Node (E);
9167 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
9173 end Within_HSS_Or_If;
9175 -- Start of processing for Set_Public_Status
9178 -- Everything in the scope of Standard is public
9180 if S = Standard_Standard then
9183 -- Entity is definitely not public if enclosing scope is not public
9185 elsif not Is_Public (S) then
9188 -- An object or function declaration that occurs in a handled sequence
9189 -- of statements or within an if statement is the declaration for a
9190 -- temporary object or local subprogram generated by the expander. It
9191 -- never needs to be made public and furthermore, making it public can
9192 -- cause back end problems.
9194 elsif Nkind_In (Parent (Id), N_Object_Declaration,
9195 N_Function_Specification)
9196 and then Within_HSS_Or_If (Id)
9200 -- Entities in public packages or records are public
9202 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9205 -- The bounds of an entry family declaration can generate object
9206 -- declarations that are visible to the back-end, e.g. in the
9207 -- the declaration of a composite type that contains tasks.
9209 elsif Is_Concurrent_Type (S)
9210 and then not Has_Completion (S)
9211 and then Nkind (Parent (Id)) = N_Object_Declaration
9215 end Set_Public_Status;
9217 -----------------------------
9218 -- Set_Referenced_Modified --
9219 -----------------------------
9221 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9225 -- Deal with indexed or selected component where prefix is modified
9227 if Nkind (N) = N_Indexed_Component
9229 Nkind (N) = N_Selected_Component
9233 -- If prefix is access type, then it is the designated object that is
9234 -- being modified, which means we have no entity to set the flag on.
9236 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9239 -- Otherwise chase the prefix
9242 Set_Referenced_Modified (Pref, Out_Param);
9245 -- Otherwise see if we have an entity name (only other case to process)
9247 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9248 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9249 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9251 end Set_Referenced_Modified;
9253 ----------------------------
9254 -- Set_Scope_Is_Transient --
9255 ----------------------------
9257 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9259 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9260 end Set_Scope_Is_Transient;
9266 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9268 -- We copy Esize, but not RM_Size, since in general RM_Size is
9269 -- subtype specific and does not get inherited by all subtypes.
9271 Set_Esize (T1, Esize (T2));
9272 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9274 if Is_Discrete_Or_Fixed_Point_Type (T1)
9276 Is_Discrete_Or_Fixed_Point_Type (T2)
9278 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9281 Set_Alignment (T1, Alignment (T2));
9284 --------------------
9285 -- Static_Integer --
9286 --------------------
9288 function Static_Integer (N : Node_Id) return Uint is
9290 Analyze_And_Resolve (N, Any_Integer);
9293 or else Error_Posted (N)
9294 or else Etype (N) = Any_Type
9299 if Is_Static_Expression (N) then
9300 if not Raises_Constraint_Error (N) then
9301 return Expr_Value (N);
9306 elsif Etype (N) = Any_Type then
9310 Flag_Non_Static_Expr
9311 ("static integer expression required here", N);
9316 --------------------------
9317 -- Statically_Different --
9318 --------------------------
9320 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9321 R1 : constant Node_Id := Get_Referenced_Object (E1);
9322 R2 : constant Node_Id := Get_Referenced_Object (E2);
9324 return Is_Entity_Name (R1)
9325 and then Is_Entity_Name (R2)
9326 and then Entity (R1) /= Entity (R2)
9327 and then not Is_Formal (Entity (R1))
9328 and then not Is_Formal (Entity (R2));
9329 end Statically_Different;
9331 -----------------------------
9332 -- Subprogram_Access_Level --
9333 -----------------------------
9335 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9337 if Present (Alias (Subp)) then
9338 return Subprogram_Access_Level (Alias (Subp));
9340 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9342 end Subprogram_Access_Level;
9348 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9350 if Debug_Flag_W then
9351 for J in 0 .. Scope_Stack.Last loop
9356 Write_Name (Chars (E));
9357 Write_Str (" from ");
9358 Write_Location (Sloc (N));
9363 -----------------------
9364 -- Transfer_Entities --
9365 -----------------------
9367 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9368 Ent : Entity_Id := First_Entity (From);
9375 if (Last_Entity (To)) = Empty then
9376 Set_First_Entity (To, Ent);
9378 Set_Next_Entity (Last_Entity (To), Ent);
9381 Set_Last_Entity (To, Last_Entity (From));
9383 while Present (Ent) loop
9384 Set_Scope (Ent, To);
9386 if not Is_Public (Ent) then
9387 Set_Public_Status (Ent);
9390 and then Ekind (Ent) = E_Record_Subtype
9393 -- The components of the propagated Itype must be public
9399 Comp := First_Entity (Ent);
9400 while Present (Comp) loop
9401 Set_Is_Public (Comp);
9411 Set_First_Entity (From, Empty);
9412 Set_Last_Entity (From, Empty);
9413 end Transfer_Entities;
9415 -----------------------
9416 -- Type_Access_Level --
9417 -----------------------
9419 function Type_Access_Level (Typ : Entity_Id) return Uint is
9423 Btyp := Base_Type (Typ);
9425 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9426 -- simply use the level where the type is declared. This is true for
9427 -- stand-alone object declarations, and for anonymous access types
9428 -- associated with components the level is the same as that of the
9429 -- enclosing composite type. However, special treatment is needed for
9430 -- the cases of access parameters, return objects of an anonymous access
9431 -- type, and, in Ada 95, access discriminants of limited types.
9433 if Ekind (Btyp) in Access_Kind then
9434 if Ekind (Btyp) = E_Anonymous_Access_Type then
9436 -- If the type is a nonlocal anonymous access type (such as for
9437 -- an access parameter) we treat it as being declared at the
9438 -- library level to ensure that names such as X.all'access don't
9439 -- fail static accessibility checks.
9441 if not Is_Local_Anonymous_Access (Typ) then
9442 return Scope_Depth (Standard_Standard);
9444 -- If this is a return object, the accessibility level is that of
9445 -- the result subtype of the enclosing function. The test here is
9446 -- little complicated, because we have to account for extended
9447 -- return statements that have been rewritten as blocks, in which
9448 -- case we have to find and the Is_Return_Object attribute of the
9449 -- itype's associated object. It would be nice to find a way to
9450 -- simplify this test, but it doesn't seem worthwhile to add a new
9451 -- flag just for purposes of this test. ???
9453 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9456 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9457 N_Object_Declaration
9458 and then Is_Return_Object
9459 (Defining_Identifier
9460 (Associated_Node_For_Itype (Btyp))))
9466 Scop := Scope (Scope (Btyp));
9467 while Present (Scop) loop
9468 exit when Ekind (Scop) = E_Function;
9469 Scop := Scope (Scop);
9472 -- Treat the return object's type as having the level of the
9473 -- function's result subtype (as per RM05-6.5(5.3/2)).
9475 return Type_Access_Level (Etype (Scop));
9480 Btyp := Root_Type (Btyp);
9482 -- The accessibility level of anonymous access types associated with
9483 -- discriminants is that of the current instance of the type, and
9484 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9486 -- AI-402: access discriminants have accessibility based on the
9487 -- object rather than the type in Ada 2005, so the above paragraph
9490 -- ??? Needs completion with rules from AI-416
9492 if Ada_Version <= Ada_95
9493 and then Ekind (Typ) = E_Anonymous_Access_Type
9494 and then Present (Associated_Node_For_Itype (Typ))
9495 and then Nkind (Associated_Node_For_Itype (Typ)) =
9496 N_Discriminant_Specification
9498 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9502 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9503 end Type_Access_Level;
9505 --------------------
9506 -- Ultimate_Alias --
9507 --------------------
9508 -- To do: add occurrences calling this new subprogram
9510 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
9511 E : Entity_Id := Prim;
9514 while Present (Alias (E)) loop
9521 --------------------------
9522 -- Unit_Declaration_Node --
9523 --------------------------
9525 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9526 N : Node_Id := Parent (Unit_Id);
9529 -- Predefined operators do not have a full function declaration
9531 if Ekind (Unit_Id) = E_Operator then
9535 -- Isn't there some better way to express the following ???
9537 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9538 and then Nkind (N) /= N_Formal_Package_Declaration
9539 and then Nkind (N) /= N_Function_Instantiation
9540 and then Nkind (N) /= N_Generic_Package_Declaration
9541 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9542 and then Nkind (N) /= N_Package_Declaration
9543 and then Nkind (N) /= N_Package_Body
9544 and then Nkind (N) /= N_Package_Instantiation
9545 and then Nkind (N) /= N_Package_Renaming_Declaration
9546 and then Nkind (N) /= N_Procedure_Instantiation
9547 and then Nkind (N) /= N_Protected_Body
9548 and then Nkind (N) /= N_Subprogram_Declaration
9549 and then Nkind (N) /= N_Subprogram_Body
9550 and then Nkind (N) /= N_Subprogram_Body_Stub
9551 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9552 and then Nkind (N) /= N_Task_Body
9553 and then Nkind (N) /= N_Task_Type_Declaration
9554 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9555 and then Nkind (N) not in N_Generic_Renaming_Declaration
9558 pragma Assert (Present (N));
9562 end Unit_Declaration_Node;
9564 ------------------------------
9565 -- Universal_Interpretation --
9566 ------------------------------
9568 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9569 Index : Interp_Index;
9573 -- The argument may be a formal parameter of an operator or subprogram
9574 -- with multiple interpretations, or else an expression for an actual.
9576 if Nkind (Opnd) = N_Defining_Identifier
9577 or else not Is_Overloaded (Opnd)
9579 if Etype (Opnd) = Universal_Integer
9580 or else Etype (Opnd) = Universal_Real
9582 return Etype (Opnd);
9588 Get_First_Interp (Opnd, Index, It);
9589 while Present (It.Typ) loop
9590 if It.Typ = Universal_Integer
9591 or else It.Typ = Universal_Real
9596 Get_Next_Interp (Index, It);
9601 end Universal_Interpretation;
9607 function Unqualify (Expr : Node_Id) return Node_Id is
9609 -- Recurse to handle unlikely case of multiple levels of qualification
9611 if Nkind (Expr) = N_Qualified_Expression then
9612 return Unqualify (Expression (Expr));
9614 -- Normal case, not a qualified expression
9621 ----------------------
9622 -- Within_Init_Proc --
9623 ----------------------
9625 function Within_Init_Proc return Boolean is
9630 while not Is_Overloadable (S) loop
9631 if S = Standard_Standard then
9638 return Is_Init_Proc (S);
9639 end Within_Init_Proc;
9645 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9646 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9647 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9649 function Has_One_Matching_Field return Boolean;
9650 -- Determines if Expec_Type is a record type with a single component or
9651 -- discriminant whose type matches the found type or is one dimensional
9652 -- array whose component type matches the found type.
9654 ----------------------------
9655 -- Has_One_Matching_Field --
9656 ----------------------------
9658 function Has_One_Matching_Field return Boolean is
9662 if Is_Array_Type (Expec_Type)
9663 and then Number_Dimensions (Expec_Type) = 1
9665 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9669 elsif not Is_Record_Type (Expec_Type) then
9673 E := First_Entity (Expec_Type);
9678 elsif (Ekind (E) /= E_Discriminant
9679 and then Ekind (E) /= E_Component)
9680 or else (Chars (E) = Name_uTag
9681 or else Chars (E) = Name_uParent)
9690 if not Covers (Etype (E), Found_Type) then
9693 elsif Present (Next_Entity (E)) then
9700 end Has_One_Matching_Field;
9702 -- Start of processing for Wrong_Type
9705 -- Don't output message if either type is Any_Type, or if a message
9706 -- has already been posted for this node. We need to do the latter
9707 -- check explicitly (it is ordinarily done in Errout), because we
9708 -- are using ! to force the output of the error messages.
9710 if Expec_Type = Any_Type
9711 or else Found_Type = Any_Type
9712 or else Error_Posted (Expr)
9716 -- In an instance, there is an ongoing problem with completion of
9717 -- type derived from private types. Their structure is what Gigi
9718 -- expects, but the Etype is the parent type rather than the
9719 -- derived private type itself. Do not flag error in this case. The
9720 -- private completion is an entity without a parent, like an Itype.
9721 -- Similarly, full and partial views may be incorrect in the instance.
9722 -- There is no simple way to insure that it is consistent ???
9724 elsif In_Instance then
9725 if Etype (Etype (Expr)) = Etype (Expected_Type)
9727 (Has_Private_Declaration (Expected_Type)
9728 or else Has_Private_Declaration (Etype (Expr)))
9729 and then No (Parent (Expected_Type))
9735 -- An interesting special check. If the expression is parenthesized
9736 -- and its type corresponds to the type of the sole component of the
9737 -- expected record type, or to the component type of the expected one
9738 -- dimensional array type, then assume we have a bad aggregate attempt.
9740 if Nkind (Expr) in N_Subexpr
9741 and then Paren_Count (Expr) /= 0
9742 and then Has_One_Matching_Field
9744 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9746 -- Another special check, if we are looking for a pool-specific access
9747 -- type and we found an E_Access_Attribute_Type, then we have the case
9748 -- of an Access attribute being used in a context which needs a pool-
9749 -- specific type, which is never allowed. The one extra check we make
9750 -- is that the expected designated type covers the Found_Type.
9752 elsif Is_Access_Type (Expec_Type)
9753 and then Ekind (Found_Type) = E_Access_Attribute_Type
9754 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9755 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9757 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9759 Error_Msg_N ("result must be general access type!", Expr);
9760 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9762 -- Another special check, if the expected type is an integer type,
9763 -- but the expression is of type System.Address, and the parent is
9764 -- an addition or subtraction operation whose left operand is the
9765 -- expression in question and whose right operand is of an integral
9766 -- type, then this is an attempt at address arithmetic, so give
9767 -- appropriate message.
9769 elsif Is_Integer_Type (Expec_Type)
9770 and then Is_RTE (Found_Type, RE_Address)
9771 and then (Nkind (Parent (Expr)) = N_Op_Add
9773 Nkind (Parent (Expr)) = N_Op_Subtract)
9774 and then Expr = Left_Opnd (Parent (Expr))
9775 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9778 ("address arithmetic not predefined in package System",
9781 ("\possible missing with/use of System.Storage_Elements",
9785 -- If the expected type is an anonymous access type, as for access
9786 -- parameters and discriminants, the error is on the designated types.
9788 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9789 if Comes_From_Source (Expec_Type) then
9790 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9793 ("expected an access type with designated}",
9794 Expr, Designated_Type (Expec_Type));
9797 if Is_Access_Type (Found_Type)
9798 and then not Comes_From_Source (Found_Type)
9801 ("\\found an access type with designated}!",
9802 Expr, Designated_Type (Found_Type));
9804 if From_With_Type (Found_Type) then
9805 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9806 Error_Msg_Qual_Level := 99;
9807 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9808 Error_Msg_Qual_Level := 0;
9810 Error_Msg_NE ("found}!", Expr, Found_Type);
9814 -- Normal case of one type found, some other type expected
9817 -- If the names of the two types are the same, see if some number
9818 -- of levels of qualification will help. Don't try more than three
9819 -- levels, and if we get to standard, it's no use (and probably
9820 -- represents an error in the compiler) Also do not bother with
9821 -- internal scope names.
9824 Expec_Scope : Entity_Id;
9825 Found_Scope : Entity_Id;
9828 Expec_Scope := Expec_Type;
9829 Found_Scope := Found_Type;
9831 for Levels in Int range 0 .. 3 loop
9832 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9833 Error_Msg_Qual_Level := Levels;
9837 Expec_Scope := Scope (Expec_Scope);
9838 Found_Scope := Scope (Found_Scope);
9840 exit when Expec_Scope = Standard_Standard
9841 or else Found_Scope = Standard_Standard
9842 or else not Comes_From_Source (Expec_Scope)
9843 or else not Comes_From_Source (Found_Scope);
9847 if Is_Record_Type (Expec_Type)
9848 and then Present (Corresponding_Remote_Type (Expec_Type))
9850 Error_Msg_NE ("expected}!", Expr,
9851 Corresponding_Remote_Type (Expec_Type));
9853 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9856 if Is_Entity_Name (Expr)
9857 and then Is_Package_Or_Generic_Package (Entity (Expr))
9859 Error_Msg_N ("\\found package name!", Expr);
9861 elsif Is_Entity_Name (Expr)
9863 (Ekind (Entity (Expr)) = E_Procedure
9865 Ekind (Entity (Expr)) = E_Generic_Procedure)
9867 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9869 ("found procedure name, possibly missing Access attribute!",
9873 ("\\found procedure name instead of function!", Expr);
9876 elsif Nkind (Expr) = N_Function_Call
9877 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9878 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9879 and then No (Parameter_Associations (Expr))
9882 ("found function name, possibly missing Access attribute!",
9885 -- Catch common error: a prefix or infix operator which is not
9886 -- directly visible because the type isn't.
9888 elsif Nkind (Expr) in N_Op
9889 and then Is_Overloaded (Expr)
9890 and then not Is_Immediately_Visible (Expec_Type)
9891 and then not Is_Potentially_Use_Visible (Expec_Type)
9892 and then not In_Use (Expec_Type)
9893 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9896 ("operator of the type is not directly visible!", Expr);
9898 elsif Ekind (Found_Type) = E_Void
9899 and then Present (Parent (Found_Type))
9900 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9902 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9905 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9908 Error_Msg_Qual_Level := 0;