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));
2968 -- Choice is a subtype indication
2970 elsif Nkind (Choice) = N_Subtype_Indication then
2972 C : constant Node_Id := Constraint (Choice);
2973 R : constant Node_Id := Range_Expression (C);
2977 Val >= Expr_Value (Low_Bound (R))
2979 Val <= Expr_Value (High_Bound (R));
2982 -- Choice is a simple expression
2985 exit Search when Val = Expr_Value (Choice);
2993 pragma Assert (Present (Alt));
2996 -- The above loop *must* terminate by finding a match, since
2997 -- we know the case statement is valid, and the value of the
2998 -- expression is known at compile time. When we fall out of
2999 -- the loop, Alt points to the alternative that we know will
3000 -- be selected at run time.
3003 end Find_Static_Alternative;
3009 function First_Actual (Node : Node_Id) return Node_Id is
3013 if No (Parameter_Associations (Node)) then
3017 N := First (Parameter_Associations (Node));
3019 if Nkind (N) = N_Parameter_Association then
3020 return First_Named_Actual (Node);
3026 -------------------------
3027 -- Full_Qualified_Name --
3028 -------------------------
3030 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3032 pragma Warnings (Off, Res);
3034 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3035 -- Compute recursively the qualified name without NUL at the end
3037 ----------------------------------
3038 -- Internal_Full_Qualified_Name --
3039 ----------------------------------
3041 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3042 Ent : Entity_Id := E;
3043 Parent_Name : String_Id := No_String;
3046 -- Deals properly with child units
3048 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3049 Ent := Defining_Identifier (Ent);
3052 -- Compute qualification recursively (only "Standard" has no scope)
3054 if Present (Scope (Scope (Ent))) then
3055 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3058 -- Every entity should have a name except some expanded blocks
3059 -- don't bother about those.
3061 if Chars (Ent) = No_Name then
3065 -- Add a period between Name and qualification
3067 if Parent_Name /= No_String then
3068 Start_String (Parent_Name);
3069 Store_String_Char (Get_Char_Code ('.'));
3075 -- Generates the entity name in upper case
3077 Get_Decoded_Name_String (Chars (Ent));
3079 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3081 end Internal_Full_Qualified_Name;
3083 -- Start of processing for Full_Qualified_Name
3086 Res := Internal_Full_Qualified_Name (E);
3087 Store_String_Char (Get_Char_Code (ASCII.NUL));
3089 end Full_Qualified_Name;
3091 -----------------------
3092 -- Gather_Components --
3093 -----------------------
3095 procedure Gather_Components
3097 Comp_List : Node_Id;
3098 Governed_By : List_Id;
3100 Report_Errors : out Boolean)
3104 Discrete_Choice : Node_Id;
3105 Comp_Item : Node_Id;
3107 Discrim : Entity_Id;
3108 Discrim_Name : Node_Id;
3109 Discrim_Value : Node_Id;
3112 Report_Errors := False;
3114 if No (Comp_List) or else Null_Present (Comp_List) then
3117 elsif Present (Component_Items (Comp_List)) then
3118 Comp_Item := First (Component_Items (Comp_List));
3124 while Present (Comp_Item) loop
3126 -- Skip the tag of a tagged record, the interface tags, as well
3127 -- as all items that are not user components (anonymous types,
3128 -- rep clauses, Parent field, controller field).
3130 if Nkind (Comp_Item) = N_Component_Declaration then
3132 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3134 if not Is_Tag (Comp)
3135 and then Chars (Comp) /= Name_uParent
3136 and then Chars (Comp) /= Name_uController
3138 Append_Elmt (Comp, Into);
3146 if No (Variant_Part (Comp_List)) then
3149 Discrim_Name := Name (Variant_Part (Comp_List));
3150 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3153 -- Look for the discriminant that governs this variant part.
3154 -- The discriminant *must* be in the Governed_By List
3156 Assoc := First (Governed_By);
3157 Find_Constraint : loop
3158 Discrim := First (Choices (Assoc));
3159 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3160 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3162 Chars (Corresponding_Discriminant (Entity (Discrim)))
3163 = Chars (Discrim_Name))
3164 or else Chars (Original_Record_Component (Entity (Discrim)))
3165 = Chars (Discrim_Name);
3167 if No (Next (Assoc)) then
3168 if not Is_Constrained (Typ)
3169 and then Is_Derived_Type (Typ)
3170 and then Present (Stored_Constraint (Typ))
3172 -- If the type is a tagged type with inherited discriminants,
3173 -- use the stored constraint on the parent in order to find
3174 -- the values of discriminants that are otherwise hidden by an
3175 -- explicit constraint. Renamed discriminants are handled in
3178 -- If several parent discriminants are renamed by a single
3179 -- discriminant of the derived type, the call to obtain the
3180 -- Corresponding_Discriminant field only retrieves the last
3181 -- of them. We recover the constraint on the others from the
3182 -- Stored_Constraint as well.
3189 D := First_Discriminant (Etype (Typ));
3190 C := First_Elmt (Stored_Constraint (Typ));
3191 while Present (D) and then Present (C) loop
3192 if Chars (Discrim_Name) = Chars (D) then
3193 if Is_Entity_Name (Node (C))
3194 and then Entity (Node (C)) = Entity (Discrim)
3196 -- D is renamed by Discrim, whose value is given in
3203 Make_Component_Association (Sloc (Typ),
3205 (New_Occurrence_Of (D, Sloc (Typ))),
3206 Duplicate_Subexpr_No_Checks (Node (C)));
3208 exit Find_Constraint;
3211 Next_Discriminant (D);
3218 if No (Next (Assoc)) then
3219 Error_Msg_NE (" missing value for discriminant&",
3220 First (Governed_By), Discrim_Name);
3221 Report_Errors := True;
3226 end loop Find_Constraint;
3228 Discrim_Value := Expression (Assoc);
3230 if not Is_OK_Static_Expression (Discrim_Value) then
3232 ("value for discriminant & must be static!",
3233 Discrim_Value, Discrim);
3234 Why_Not_Static (Discrim_Value);
3235 Report_Errors := True;
3239 Search_For_Discriminant_Value : declare
3245 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3248 Find_Discrete_Value : while Present (Variant) loop
3249 Discrete_Choice := First (Discrete_Choices (Variant));
3250 while Present (Discrete_Choice) loop
3252 exit Find_Discrete_Value when
3253 Nkind (Discrete_Choice) = N_Others_Choice;
3255 Get_Index_Bounds (Discrete_Choice, Low, High);
3257 UI_Low := Expr_Value (Low);
3258 UI_High := Expr_Value (High);
3260 exit Find_Discrete_Value when
3261 UI_Low <= UI_Discrim_Value
3263 UI_High >= UI_Discrim_Value;
3265 Next (Discrete_Choice);
3268 Next_Non_Pragma (Variant);
3269 end loop Find_Discrete_Value;
3270 end Search_For_Discriminant_Value;
3272 if No (Variant) then
3274 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3275 Report_Errors := True;
3279 -- If we have found the corresponding choice, recursively add its
3280 -- components to the Into list.
3282 Gather_Components (Empty,
3283 Component_List (Variant), Governed_By, Into, Report_Errors);
3284 end Gather_Components;
3286 ------------------------
3287 -- Get_Actual_Subtype --
3288 ------------------------
3290 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3291 Typ : constant Entity_Id := Etype (N);
3292 Utyp : Entity_Id := Underlying_Type (Typ);
3301 -- If what we have is an identifier that references a subprogram
3302 -- formal, or a variable or constant object, then we get the actual
3303 -- subtype from the referenced entity if one has been built.
3305 if Nkind (N) = N_Identifier
3307 (Is_Formal (Entity (N))
3308 or else Ekind (Entity (N)) = E_Constant
3309 or else Ekind (Entity (N)) = E_Variable)
3310 and then Present (Actual_Subtype (Entity (N)))
3312 return Actual_Subtype (Entity (N));
3314 -- Actual subtype of unchecked union is always itself. We never need
3315 -- the "real" actual subtype. If we did, we couldn't get it anyway
3316 -- because the discriminant is not available. The restrictions on
3317 -- Unchecked_Union are designed to make sure that this is OK.
3319 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3322 -- Here for the unconstrained case, we must find actual subtype
3323 -- No actual subtype is available, so we must build it on the fly.
3325 -- Checking the type, not the underlying type, for constrainedness
3326 -- seems to be necessary. Maybe all the tests should be on the type???
3328 elsif (not Is_Constrained (Typ))
3329 and then (Is_Array_Type (Utyp)
3330 or else (Is_Record_Type (Utyp)
3331 and then Has_Discriminants (Utyp)))
3332 and then not Has_Unknown_Discriminants (Utyp)
3333 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3335 -- Nothing to do if in spec expression (why not???)
3337 if In_Spec_Expression then
3340 elsif Is_Private_Type (Typ)
3341 and then not Has_Discriminants (Typ)
3343 -- If the type has no discriminants, there is no subtype to
3344 -- build, even if the underlying type is discriminated.
3348 -- Else build the actual subtype
3351 Decl := Build_Actual_Subtype (Typ, N);
3352 Atyp := Defining_Identifier (Decl);
3354 -- If Build_Actual_Subtype generated a new declaration then use it
3358 -- The actual subtype is an Itype, so analyze the declaration,
3359 -- but do not attach it to the tree, to get the type defined.
3361 Set_Parent (Decl, N);
3362 Set_Is_Itype (Atyp);
3363 Analyze (Decl, Suppress => All_Checks);
3364 Set_Associated_Node_For_Itype (Atyp, N);
3365 Set_Has_Delayed_Freeze (Atyp, False);
3367 -- We need to freeze the actual subtype immediately. This is
3368 -- needed, because otherwise this Itype will not get frozen
3369 -- at all, and it is always safe to freeze on creation because
3370 -- any associated types must be frozen at this point.
3372 Freeze_Itype (Atyp, N);
3375 -- Otherwise we did not build a declaration, so return original
3382 -- For all remaining cases, the actual subtype is the same as
3383 -- the nominal type.
3388 end Get_Actual_Subtype;
3390 -------------------------------------
3391 -- Get_Actual_Subtype_If_Available --
3392 -------------------------------------
3394 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3395 Typ : constant Entity_Id := Etype (N);
3398 -- If what we have is an identifier that references a subprogram
3399 -- formal, or a variable or constant object, then we get the actual
3400 -- subtype from the referenced entity if one has been built.
3402 if Nkind (N) = N_Identifier
3404 (Is_Formal (Entity (N))
3405 or else Ekind (Entity (N)) = E_Constant
3406 or else Ekind (Entity (N)) = E_Variable)
3407 and then Present (Actual_Subtype (Entity (N)))
3409 return Actual_Subtype (Entity (N));
3411 -- Otherwise the Etype of N is returned unchanged
3416 end Get_Actual_Subtype_If_Available;
3418 -------------------------------
3419 -- Get_Default_External_Name --
3420 -------------------------------
3422 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3424 Get_Decoded_Name_String (Chars (E));
3426 if Opt.External_Name_Imp_Casing = Uppercase then
3427 Set_Casing (All_Upper_Case);
3429 Set_Casing (All_Lower_Case);
3433 Make_String_Literal (Sloc (E),
3434 Strval => String_From_Name_Buffer);
3435 end Get_Default_External_Name;
3437 ---------------------------
3438 -- Get_Enum_Lit_From_Pos --
3439 ---------------------------
3441 function Get_Enum_Lit_From_Pos
3444 Loc : Source_Ptr) return Node_Id
3449 -- In the case where the literal is of type Character, Wide_Character
3450 -- or Wide_Wide_Character or of a type derived from them, there needs
3451 -- to be some special handling since there is no explicit chain of
3452 -- literals to search. Instead, an N_Character_Literal node is created
3453 -- with the appropriate Char_Code and Chars fields.
3455 if Is_Standard_Character_Type (T) then
3456 Set_Character_Literal_Name (UI_To_CC (Pos));
3458 Make_Character_Literal (Loc,
3460 Char_Literal_Value => Pos);
3462 -- For all other cases, we have a complete table of literals, and
3463 -- we simply iterate through the chain of literal until the one
3464 -- with the desired position value is found.
3468 Lit := First_Literal (Base_Type (T));
3469 for J in 1 .. UI_To_Int (Pos) loop
3473 return New_Occurrence_Of (Lit, Loc);
3475 end Get_Enum_Lit_From_Pos;
3477 ------------------------
3478 -- Get_Generic_Entity --
3479 ------------------------
3481 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3482 Ent : constant Entity_Id := Entity (Name (N));
3484 if Present (Renamed_Object (Ent)) then
3485 return Renamed_Object (Ent);
3489 end Get_Generic_Entity;
3491 ----------------------
3492 -- Get_Index_Bounds --
3493 ----------------------
3495 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3496 Kind : constant Node_Kind := Nkind (N);
3500 if Kind = N_Range then
3502 H := High_Bound (N);
3504 elsif Kind = N_Subtype_Indication then
3505 R := Range_Expression (Constraint (N));
3513 L := Low_Bound (Range_Expression (Constraint (N)));
3514 H := High_Bound (Range_Expression (Constraint (N)));
3517 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3518 if Error_Posted (Scalar_Range (Entity (N))) then
3522 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3523 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3526 L := Low_Bound (Scalar_Range (Entity (N)));
3527 H := High_Bound (Scalar_Range (Entity (N)));
3531 -- N is an expression, indicating a range with one value
3536 end Get_Index_Bounds;
3538 ----------------------------------
3539 -- Get_Library_Unit_Name_string --
3540 ----------------------------------
3542 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3543 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3546 Get_Unit_Name_String (Unit_Name_Id);
3548 -- Remove seven last character (" (spec)" or " (body)")
3550 Name_Len := Name_Len - 7;
3551 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3552 end Get_Library_Unit_Name_String;
3554 ------------------------
3555 -- Get_Name_Entity_Id --
3556 ------------------------
3558 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3560 return Entity_Id (Get_Name_Table_Info (Id));
3561 end Get_Name_Entity_Id;
3567 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3569 return Get_Pragma_Id (Pragma_Name (N));
3572 ---------------------------
3573 -- Get_Referenced_Object --
3574 ---------------------------
3576 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3581 while Is_Entity_Name (R)
3582 and then Present (Renamed_Object (Entity (R)))
3584 R := Renamed_Object (Entity (R));
3588 end Get_Referenced_Object;
3590 ------------------------
3591 -- Get_Renamed_Entity --
3592 ------------------------
3594 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3599 while Present (Renamed_Entity (R)) loop
3600 R := Renamed_Entity (R);
3604 end Get_Renamed_Entity;
3606 -------------------------
3607 -- Get_Subprogram_Body --
3608 -------------------------
3610 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3614 Decl := Unit_Declaration_Node (E);
3616 if Nkind (Decl) = N_Subprogram_Body then
3619 -- The below comment is bad, because it is possible for
3620 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3622 else -- Nkind (Decl) = N_Subprogram_Declaration
3624 if Present (Corresponding_Body (Decl)) then
3625 return Unit_Declaration_Node (Corresponding_Body (Decl));
3627 -- Imported subprogram case
3633 end Get_Subprogram_Body;
3635 ---------------------------
3636 -- Get_Subprogram_Entity --
3637 ---------------------------
3639 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3644 if Nkind (Nod) = N_Accept_Statement then
3645 Nam := Entry_Direct_Name (Nod);
3647 -- For an entry call, the prefix of the call is a selected component.
3648 -- Need additional code for internal calls ???
3650 elsif Nkind (Nod) = N_Entry_Call_Statement then
3651 if Nkind (Name (Nod)) = N_Selected_Component then
3652 Nam := Entity (Selector_Name (Name (Nod)));
3661 if Nkind (Nam) = N_Explicit_Dereference then
3662 Proc := Etype (Prefix (Nam));
3663 elsif Is_Entity_Name (Nam) then
3664 Proc := Entity (Nam);
3669 if Is_Object (Proc) then
3670 Proc := Etype (Proc);
3673 if Ekind (Proc) = E_Access_Subprogram_Type then
3674 Proc := Directly_Designated_Type (Proc);
3677 if not Is_Subprogram (Proc)
3678 and then Ekind (Proc) /= E_Subprogram_Type
3684 end Get_Subprogram_Entity;
3686 -----------------------------
3687 -- Get_Task_Body_Procedure --
3688 -----------------------------
3690 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3692 -- Note: A task type may be the completion of a private type with
3693 -- discriminants. When performing elaboration checks on a task
3694 -- declaration, the current view of the type may be the private one,
3695 -- and the procedure that holds the body of the task is held in its
3698 -- This is an odd function, why not have Task_Body_Procedure do
3699 -- the following digging???
3701 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3702 end Get_Task_Body_Procedure;
3704 -----------------------
3705 -- Has_Access_Values --
3706 -----------------------
3708 function Has_Access_Values (T : Entity_Id) return Boolean is
3709 Typ : constant Entity_Id := Underlying_Type (T);
3712 -- Case of a private type which is not completed yet. This can only
3713 -- happen in the case of a generic format type appearing directly, or
3714 -- as a component of the type to which this function is being applied
3715 -- at the top level. Return False in this case, since we certainly do
3716 -- not know that the type contains access types.
3721 elsif Is_Access_Type (Typ) then
3724 elsif Is_Array_Type (Typ) then
3725 return Has_Access_Values (Component_Type (Typ));
3727 elsif Is_Record_Type (Typ) then
3732 -- Loop to Check components
3734 Comp := First_Component_Or_Discriminant (Typ);
3735 while Present (Comp) loop
3737 -- Check for access component, tag field does not count, even
3738 -- though it is implemented internally using an access type.
3740 if Has_Access_Values (Etype (Comp))
3741 and then Chars (Comp) /= Name_uTag
3746 Next_Component_Or_Discriminant (Comp);
3755 end Has_Access_Values;
3757 ------------------------------
3758 -- Has_Compatible_Alignment --
3759 ------------------------------
3761 function Has_Compatible_Alignment
3763 Expr : Node_Id) return Alignment_Result
3765 function Has_Compatible_Alignment_Internal
3768 Default : Alignment_Result) return Alignment_Result;
3769 -- This is the internal recursive function that actually does the work.
3770 -- There is one additional parameter, which says what the result should
3771 -- be if no alignment information is found, and there is no definite
3772 -- indication of compatible alignments. At the outer level, this is set
3773 -- to Unknown, but for internal recursive calls in the case where types
3774 -- are known to be correct, it is set to Known_Compatible.
3776 ---------------------------------------
3777 -- Has_Compatible_Alignment_Internal --
3778 ---------------------------------------
3780 function Has_Compatible_Alignment_Internal
3783 Default : Alignment_Result) return Alignment_Result
3785 Result : Alignment_Result := Known_Compatible;
3786 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3787 -- Note that once a value of Known_Incompatible is set, it is sticky
3788 -- and does not get changed to Unknown (the value in Result only gets
3789 -- worse as we go along, never better).
3791 procedure Check_Offset (Offs : Uint);
3792 -- Called when Expr is a selected or indexed component with Offs set
3793 -- to resp Component_First_Bit or Component_Size. Checks that if the
3794 -- offset is specified it is compatible with the object alignment
3795 -- requirements. The value in Result is modified accordingly.
3797 procedure Check_Prefix;
3798 -- Checks the prefix recursively in the case where the expression
3799 -- is an indexed or selected component.
3801 procedure Set_Result (R : Alignment_Result);
3802 -- If R represents a worse outcome (unknown instead of known
3803 -- compatible, or known incompatible), then set Result to R.
3809 procedure Check_Offset (Offs : Uint) is
3811 -- Unspecified or zero offset is always OK
3813 if Offs = No_Uint or else Offs = Uint_0 then
3816 -- If we do not know required alignment, any non-zero offset is
3817 -- a potential problem (but certainly may be OK, so result is
3820 elsif Unknown_Alignment (Obj) then
3821 Set_Result (Unknown);
3823 -- If we know the required alignment, see if offset is compatible
3826 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3827 Set_Result (Known_Incompatible);
3836 procedure Check_Prefix is
3838 -- The subtlety here is that in doing a recursive call to check
3839 -- the prefix, we have to decide what to do in the case where we
3840 -- don't find any specific indication of an alignment problem.
3842 -- At the outer level, we normally set Unknown as the result in
3843 -- this case, since we can only set Known_Compatible if we really
3844 -- know that the alignment value is OK, but for the recursive
3845 -- call, in the case where the types match, and we have not
3846 -- specified a peculiar alignment for the object, we are only
3847 -- concerned about suspicious rep clauses, the default case does
3848 -- not affect us, since the compiler will, in the absence of such
3849 -- rep clauses, ensure that the alignment is correct.
3851 if Default = Known_Compatible
3853 (Etype (Obj) = Etype (Expr)
3854 and then (Unknown_Alignment (Obj)
3856 Alignment (Obj) = Alignment (Etype (Obj))))
3859 (Has_Compatible_Alignment_Internal
3860 (Obj, Prefix (Expr), Known_Compatible));
3862 -- In all other cases, we need a full check on the prefix
3866 (Has_Compatible_Alignment_Internal
3867 (Obj, Prefix (Expr), Unknown));
3875 procedure Set_Result (R : Alignment_Result) is
3882 -- Start of processing for Has_Compatible_Alignment_Internal
3885 -- If Expr is a selected component, we must make sure there is no
3886 -- potentially troublesome component clause, and that the record is
3889 if Nkind (Expr) = N_Selected_Component then
3891 -- Packed record always generate unknown alignment
3893 if Is_Packed (Etype (Prefix (Expr))) then
3894 Set_Result (Unknown);
3897 -- Check possible bad component offset and check prefix
3900 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3903 -- If Expr is an indexed component, we must make sure there is no
3904 -- potentially troublesome Component_Size clause and that the array
3905 -- is not bit-packed.
3907 elsif Nkind (Expr) = N_Indexed_Component then
3909 -- Bit packed array always generates unknown alignment
3911 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3912 Set_Result (Unknown);
3915 -- Check possible bad component size and check prefix
3917 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3921 -- Case where we know the alignment of the object
3923 if Known_Alignment (Obj) then
3925 ObjA : constant Uint := Alignment (Obj);
3926 ExpA : Uint := No_Uint;
3927 SizA : Uint := No_Uint;
3930 -- If alignment of Obj is 1, then we are always OK
3933 Set_Result (Known_Compatible);
3935 -- Alignment of Obj is greater than 1, so we need to check
3938 -- See if Expr is an object with known alignment
3940 if Is_Entity_Name (Expr)
3941 and then Known_Alignment (Entity (Expr))
3943 ExpA := Alignment (Entity (Expr));
3945 -- Otherwise, we can use the alignment of the type of
3946 -- Expr given that we already checked for
3947 -- discombobulating rep clauses for the cases of indexed
3948 -- and selected components above.
3950 elsif Known_Alignment (Etype (Expr)) then
3951 ExpA := Alignment (Etype (Expr));
3954 -- If we got an alignment, see if it is acceptable
3956 if ExpA /= No_Uint then
3958 Set_Result (Known_Incompatible);
3961 -- Case of Expr alignment unknown
3964 Set_Result (Default);
3967 -- See if size is given. If so, check that it is not too
3968 -- small for the required alignment.
3969 -- See if Expr is an object with known alignment
3971 if Is_Entity_Name (Expr)
3972 and then Known_Static_Esize (Entity (Expr))
3974 SizA := Esize (Entity (Expr));
3976 -- Otherwise, we check the object size of the Expr type
3978 elsif Known_Static_Esize (Etype (Expr)) then
3979 SizA := Esize (Etype (Expr));
3982 -- If we got a size, see if it is a multiple of the Obj
3983 -- alignment, if not, then the alignment cannot be
3984 -- acceptable, since the size is always a multiple of the
3987 if SizA /= No_Uint then
3988 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
3989 Set_Result (Known_Incompatible);
3995 -- If we can't find the result by direct comparison of alignment
3996 -- values, then there is still one case that we can determine known
3997 -- result, and that is when we can determine that the types are the
3998 -- same, and no alignments are specified. Then we known that the
3999 -- alignments are compatible, even if we don't know the alignment
4000 -- value in the front end.
4002 elsif Etype (Obj) = Etype (Expr) then
4004 -- Types are the same, but we have to check for possible size
4005 -- and alignments on the Expr object that may make the alignment
4006 -- different, even though the types are the same.
4008 if Is_Entity_Name (Expr) then
4010 -- First check alignment of the Expr object. Any alignment less
4011 -- than Maximum_Alignment is worrisome since this is the case
4012 -- where we do not know the alignment of Obj.
4014 if Known_Alignment (Entity (Expr))
4016 UI_To_Int (Alignment (Entity (Expr)))
4017 < Ttypes.Maximum_Alignment
4019 Set_Result (Unknown);
4021 -- Now check size of Expr object. Any size that is not an
4022 -- even multiple of Maximum_Alignment is also worrisome
4023 -- since it may cause the alignment of the object to be less
4024 -- than the alignment of the type.
4026 elsif Known_Static_Esize (Entity (Expr))
4028 (UI_To_Int (Esize (Entity (Expr))) mod
4029 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4032 Set_Result (Unknown);
4034 -- Otherwise same type is decisive
4037 Set_Result (Known_Compatible);
4041 -- Another case to deal with is when there is an explicit size or
4042 -- alignment clause when the types are not the same. If so, then the
4043 -- result is Unknown. We don't need to do this test if the Default is
4044 -- Unknown, since that result will be set in any case.
4046 elsif Default /= Unknown
4047 and then (Has_Size_Clause (Etype (Expr))
4049 Has_Alignment_Clause (Etype (Expr)))
4051 Set_Result (Unknown);
4053 -- If no indication found, set default
4056 Set_Result (Default);
4059 -- Return worst result found
4062 end Has_Compatible_Alignment_Internal;
4064 -- Start of processing for Has_Compatible_Alignment
4067 -- If Obj has no specified alignment, then set alignment from the type
4068 -- alignment. Perhaps we should always do this, but for sure we should
4069 -- do it when there is an address clause since we can do more if the
4070 -- alignment is known.
4072 if Unknown_Alignment (Obj) then
4073 Set_Alignment (Obj, Alignment (Etype (Obj)));
4076 -- Now do the internal call that does all the work
4078 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4079 end Has_Compatible_Alignment;
4081 ----------------------
4082 -- Has_Declarations --
4083 ----------------------
4085 function Has_Declarations (N : Node_Id) return Boolean is
4086 K : constant Node_Kind := Nkind (N);
4088 return K = N_Accept_Statement
4089 or else K = N_Block_Statement
4090 or else K = N_Compilation_Unit_Aux
4091 or else K = N_Entry_Body
4092 or else K = N_Package_Body
4093 or else K = N_Protected_Body
4094 or else K = N_Subprogram_Body
4095 or else K = N_Task_Body
4096 or else K = N_Package_Specification;
4097 end Has_Declarations;
4099 -------------------------------------------
4100 -- Has_Discriminant_Dependent_Constraint --
4101 -------------------------------------------
4103 function Has_Discriminant_Dependent_Constraint
4104 (Comp : Entity_Id) return Boolean
4106 Comp_Decl : constant Node_Id := Parent (Comp);
4107 Subt_Indic : constant Node_Id :=
4108 Subtype_Indication (Component_Definition (Comp_Decl));
4113 if Nkind (Subt_Indic) = N_Subtype_Indication then
4114 Constr := Constraint (Subt_Indic);
4116 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4117 Assn := First (Constraints (Constr));
4118 while Present (Assn) loop
4119 case Nkind (Assn) is
4120 when N_Subtype_Indication |
4124 if Depends_On_Discriminant (Assn) then
4128 when N_Discriminant_Association =>
4129 if Depends_On_Discriminant (Expression (Assn)) then
4144 end Has_Discriminant_Dependent_Constraint;
4146 --------------------
4147 -- Has_Infinities --
4148 --------------------
4150 function Has_Infinities (E : Entity_Id) return Boolean is
4153 Is_Floating_Point_Type (E)
4154 and then Nkind (Scalar_Range (E)) = N_Range
4155 and then Includes_Infinities (Scalar_Range (E));
4158 --------------------
4159 -- Has_Interfaces --
4160 --------------------
4162 function Has_Interfaces
4164 Use_Full_View : Boolean := True) return Boolean
4169 -- Handle concurrent types
4171 if Is_Concurrent_Type (T) then
4172 Typ := Corresponding_Record_Type (T);
4177 if not Present (Typ)
4178 or else not Is_Record_Type (Typ)
4179 or else not Is_Tagged_Type (Typ)
4184 -- Handle private types
4187 and then Present (Full_View (Typ))
4189 Typ := Full_View (Typ);
4192 -- Handle concurrent record types
4194 if Is_Concurrent_Record_Type (Typ)
4195 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4201 if Is_Interface (Typ)
4203 (Is_Record_Type (Typ)
4204 and then Present (Interfaces (Typ))
4205 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4210 exit when Etype (Typ) = Typ
4212 -- Handle private types
4214 or else (Present (Full_View (Etype (Typ)))
4215 and then Full_View (Etype (Typ)) = Typ)
4217 -- Protect the frontend against wrong source with cyclic
4220 or else Etype (Typ) = T;
4222 -- Climb to the ancestor type handling private types
4224 if Present (Full_View (Etype (Typ))) then
4225 Typ := Full_View (Etype (Typ));
4234 ------------------------
4235 -- Has_Null_Exclusion --
4236 ------------------------
4238 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4241 when N_Access_Definition |
4242 N_Access_Function_Definition |
4243 N_Access_Procedure_Definition |
4244 N_Access_To_Object_Definition |
4246 N_Derived_Type_Definition |
4247 N_Function_Specification |
4248 N_Subtype_Declaration =>
4249 return Null_Exclusion_Present (N);
4251 when N_Component_Definition |
4252 N_Formal_Object_Declaration |
4253 N_Object_Renaming_Declaration =>
4254 if Present (Subtype_Mark (N)) then
4255 return Null_Exclusion_Present (N);
4256 else pragma Assert (Present (Access_Definition (N)));
4257 return Null_Exclusion_Present (Access_Definition (N));
4260 when N_Discriminant_Specification =>
4261 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4262 return Null_Exclusion_Present (Discriminant_Type (N));
4264 return Null_Exclusion_Present (N);
4267 when N_Object_Declaration =>
4268 if Nkind (Object_Definition (N)) = N_Access_Definition then
4269 return Null_Exclusion_Present (Object_Definition (N));
4271 return Null_Exclusion_Present (N);
4274 when N_Parameter_Specification =>
4275 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4276 return Null_Exclusion_Present (Parameter_Type (N));
4278 return Null_Exclusion_Present (N);
4285 end Has_Null_Exclusion;
4287 ------------------------
4288 -- Has_Null_Extension --
4289 ------------------------
4291 function Has_Null_Extension (T : Entity_Id) return Boolean is
4292 B : constant Entity_Id := Base_Type (T);
4297 if Nkind (Parent (B)) = N_Full_Type_Declaration
4298 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4300 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4302 if Present (Ext) then
4303 if Null_Present (Ext) then
4306 Comps := Component_List (Ext);
4308 -- The null component list is rewritten during analysis to
4309 -- include the parent component. Any other component indicates
4310 -- that the extension was not originally null.
4312 return Null_Present (Comps)
4313 or else No (Next (First (Component_Items (Comps))));
4322 end Has_Null_Extension;
4324 -------------------------------
4325 -- Has_Overriding_Initialize --
4326 -------------------------------
4328 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4329 BT : constant Entity_Id := Base_Type (T);
4334 if Is_Controlled (BT) then
4336 -- For derived types, check immediate ancestor, excluding
4337 -- Controlled itself.
4339 if Is_Derived_Type (BT)
4340 and then not In_Predefined_Unit (Etype (BT))
4341 and then Has_Overriding_Initialize (Etype (BT))
4345 elsif Present (Primitive_Operations (BT)) then
4346 P := First_Elmt (Primitive_Operations (BT));
4347 while Present (P) loop
4348 if Chars (Node (P)) = Name_Initialize
4349 and then Comes_From_Source (Node (P))
4360 elsif Has_Controlled_Component (BT) then
4361 Comp := First_Component (BT);
4362 while Present (Comp) loop
4363 if Has_Overriding_Initialize (Etype (Comp)) then
4367 Next_Component (Comp);
4375 end Has_Overriding_Initialize;
4377 --------------------------------------
4378 -- Has_Preelaborable_Initialization --
4379 --------------------------------------
4381 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4384 procedure Check_Components (E : Entity_Id);
4385 -- Check component/discriminant chain, sets Has_PE False if a component
4386 -- or discriminant does not meet the preelaborable initialization rules.
4388 ----------------------
4389 -- Check_Components --
4390 ----------------------
4392 procedure Check_Components (E : Entity_Id) is
4396 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4397 -- Returns True if and only if the expression denoted by N does not
4398 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4400 ---------------------------------
4401 -- Is_Preelaborable_Expression --
4402 ---------------------------------
4404 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4408 Comp_Type : Entity_Id;
4409 Is_Array_Aggr : Boolean;
4412 if Is_Static_Expression (N) then
4415 elsif Nkind (N) = N_Null then
4418 -- Attributes are allowed in general, even if their prefix is a
4419 -- formal type. (It seems that certain attributes known not to be
4420 -- static might not be allowed, but there are no rules to prevent
4423 elsif Nkind (N) = N_Attribute_Reference then
4426 -- The name of a discriminant evaluated within its parent type is
4427 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4428 -- names that denote discriminals as well as discriminants to
4429 -- catch references occurring within init procs.
4431 elsif Is_Entity_Name (N)
4433 (Ekind (Entity (N)) = E_Discriminant
4435 ((Ekind (Entity (N)) = E_Constant
4436 or else Ekind (Entity (N)) = E_In_Parameter)
4437 and then Present (Discriminal_Link (Entity (N)))))
4441 elsif Nkind (N) = N_Qualified_Expression then
4442 return Is_Preelaborable_Expression (Expression (N));
4444 -- For aggregates we have to check that each of the associations
4445 -- is preelaborable.
4447 elsif Nkind (N) = N_Aggregate
4448 or else Nkind (N) = N_Extension_Aggregate
4450 Is_Array_Aggr := Is_Array_Type (Etype (N));
4452 if Is_Array_Aggr then
4453 Comp_Type := Component_Type (Etype (N));
4456 -- Check the ancestor part of extension aggregates, which must
4457 -- be either the name of a type that has preelaborable init or
4458 -- an expression that is preelaborable.
4460 if Nkind (N) = N_Extension_Aggregate then
4462 Anc_Part : constant Node_Id := Ancestor_Part (N);
4465 if Is_Entity_Name (Anc_Part)
4466 and then Is_Type (Entity (Anc_Part))
4468 if not Has_Preelaborable_Initialization
4474 elsif not Is_Preelaborable_Expression (Anc_Part) then
4480 -- Check positional associations
4482 Exp := First (Expressions (N));
4483 while Present (Exp) loop
4484 if not Is_Preelaborable_Expression (Exp) then
4491 -- Check named associations
4493 Assn := First (Component_Associations (N));
4494 while Present (Assn) loop
4495 Choice := First (Choices (Assn));
4496 while Present (Choice) loop
4497 if Is_Array_Aggr then
4498 if Nkind (Choice) = N_Others_Choice then
4501 elsif Nkind (Choice) = N_Range then
4502 if not Is_Static_Range (Choice) then
4506 elsif not Is_Static_Expression (Choice) then
4511 Comp_Type := Etype (Choice);
4517 -- If the association has a <> at this point, then we have
4518 -- to check whether the component's type has preelaborable
4519 -- initialization. Note that this only occurs when the
4520 -- association's corresponding component does not have a
4521 -- default expression, the latter case having already been
4522 -- expanded as an expression for the association.
4524 if Box_Present (Assn) then
4525 if not Has_Preelaborable_Initialization (Comp_Type) then
4529 -- In the expression case we check whether the expression
4530 -- is preelaborable.
4533 not Is_Preelaborable_Expression (Expression (Assn))
4541 -- If we get here then aggregate as a whole is preelaborable
4545 -- All other cases are not preelaborable
4550 end Is_Preelaborable_Expression;
4552 -- Start of processing for Check_Components
4555 -- Loop through entities of record or protected type
4558 while Present (Ent) loop
4560 -- We are interested only in components and discriminants
4562 if Ekind (Ent) = E_Component
4564 Ekind (Ent) = E_Discriminant
4566 -- Get default expression if any. If there is no declaration
4567 -- node, it means we have an internal entity. The parent and
4568 -- tag fields are examples of such entities. For these cases,
4569 -- we just test the type of the entity.
4571 if Present (Declaration_Node (Ent)) then
4572 Exp := Expression (Declaration_Node (Ent));
4577 -- A component has PI if it has no default expression and the
4578 -- component type has PI.
4581 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4586 -- Require the default expression to be preelaborable
4588 elsif not Is_Preelaborable_Expression (Exp) then
4596 end Check_Components;
4598 -- Start of processing for Has_Preelaborable_Initialization
4601 -- Immediate return if already marked as known preelaborable init. This
4602 -- covers types for which this function has already been called once
4603 -- and returned True (in which case the result is cached), and also
4604 -- types to which a pragma Preelaborable_Initialization applies.
4606 if Known_To_Have_Preelab_Init (E) then
4610 -- If the type is a subtype representing a generic actual type, then
4611 -- test whether its base type has preelaborable initialization since
4612 -- the subtype representing the actual does not inherit this attribute
4613 -- from the actual or formal. (but maybe it should???)
4615 if Is_Generic_Actual_Type (E) then
4616 return Has_Preelaborable_Initialization (Base_Type (E));
4619 -- All elementary types have preelaborable initialization
4621 if Is_Elementary_Type (E) then
4624 -- Array types have PI if the component type has PI
4626 elsif Is_Array_Type (E) then
4627 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4629 -- A derived type has preelaborable initialization if its parent type
4630 -- has preelaborable initialization and (in the case of a derived record
4631 -- extension) if the non-inherited components all have preelaborable
4632 -- initialization. However, a user-defined controlled type with an
4633 -- overriding Initialize procedure does not have preelaborable
4636 elsif Is_Derived_Type (E) then
4638 -- If the derived type is a private extension then it doesn't have
4639 -- preelaborable initialization.
4641 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4645 -- First check whether ancestor type has preelaborable initialization
4647 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4649 -- If OK, check extension components (if any)
4651 if Has_PE and then Is_Record_Type (E) then
4652 Check_Components (First_Entity (E));
4655 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4656 -- with a user defined Initialize procedure does not have PI.
4659 and then Is_Controlled (E)
4660 and then Has_Overriding_Initialize (E)
4665 -- Private types not derived from a type having preelaborable init and
4666 -- that are not marked with pragma Preelaborable_Initialization do not
4667 -- have preelaborable initialization.
4669 elsif Is_Private_Type (E) then
4672 -- Record type has PI if it is non private and all components have PI
4674 elsif Is_Record_Type (E) then
4676 Check_Components (First_Entity (E));
4678 -- Protected types must not have entries, and components must meet
4679 -- same set of rules as for record components.
4681 elsif Is_Protected_Type (E) then
4682 if Has_Entries (E) then
4686 Check_Components (First_Entity (E));
4687 Check_Components (First_Private_Entity (E));
4690 -- Type System.Address always has preelaborable initialization
4692 elsif Is_RTE (E, RE_Address) then
4695 -- In all other cases, type does not have preelaborable initialization
4701 -- If type has preelaborable initialization, cache result
4704 Set_Known_To_Have_Preelab_Init (E);
4708 end Has_Preelaborable_Initialization;
4710 ---------------------------
4711 -- Has_Private_Component --
4712 ---------------------------
4714 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4715 Btype : Entity_Id := Base_Type (Type_Id);
4716 Component : Entity_Id;
4719 if Error_Posted (Type_Id)
4720 or else Error_Posted (Btype)
4725 if Is_Class_Wide_Type (Btype) then
4726 Btype := Root_Type (Btype);
4729 if Is_Private_Type (Btype) then
4731 UT : constant Entity_Id := Underlying_Type (Btype);
4734 if No (Full_View (Btype)) then
4735 return not Is_Generic_Type (Btype)
4736 and then not Is_Generic_Type (Root_Type (Btype));
4738 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4741 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4745 elsif Is_Array_Type (Btype) then
4746 return Has_Private_Component (Component_Type (Btype));
4748 elsif Is_Record_Type (Btype) then
4749 Component := First_Component (Btype);
4750 while Present (Component) loop
4751 if Has_Private_Component (Etype (Component)) then
4755 Next_Component (Component);
4760 elsif Is_Protected_Type (Btype)
4761 and then Present (Corresponding_Record_Type (Btype))
4763 return Has_Private_Component (Corresponding_Record_Type (Btype));
4768 end Has_Private_Component;
4774 function Has_Stream (T : Entity_Id) return Boolean is
4781 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4784 elsif Is_Array_Type (T) then
4785 return Has_Stream (Component_Type (T));
4787 elsif Is_Record_Type (T) then
4788 E := First_Component (T);
4789 while Present (E) loop
4790 if Has_Stream (Etype (E)) then
4799 elsif Is_Private_Type (T) then
4800 return Has_Stream (Underlying_Type (T));
4807 --------------------------
4808 -- Has_Tagged_Component --
4809 --------------------------
4811 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4815 if Is_Private_Type (Typ)
4816 and then Present (Underlying_Type (Typ))
4818 return Has_Tagged_Component (Underlying_Type (Typ));
4820 elsif Is_Array_Type (Typ) then
4821 return Has_Tagged_Component (Component_Type (Typ));
4823 elsif Is_Tagged_Type (Typ) then
4826 elsif Is_Record_Type (Typ) then
4827 Comp := First_Component (Typ);
4828 while Present (Comp) loop
4829 if Has_Tagged_Component (Etype (Comp)) then
4833 Comp := Next_Component (Typ);
4841 end Has_Tagged_Component;
4843 --------------------------
4844 -- Implements_Interface --
4845 --------------------------
4847 function Implements_Interface
4848 (Typ_Ent : Entity_Id;
4849 Iface_Ent : Entity_Id;
4850 Exclude_Parents : Boolean := False) return Boolean
4852 Ifaces_List : Elist_Id;
4858 if Is_Class_Wide_Type (Typ_Ent) then
4859 Typ := Etype (Typ_Ent);
4864 if Is_Class_Wide_Type (Iface_Ent) then
4865 Iface := Etype (Iface_Ent);
4870 if not Has_Interfaces (Typ) then
4874 Collect_Interfaces (Typ, Ifaces_List);
4876 Elmt := First_Elmt (Ifaces_List);
4877 while Present (Elmt) loop
4878 if Is_Ancestor (Node (Elmt), Typ)
4879 and then Exclude_Parents
4883 elsif Node (Elmt) = Iface then
4891 end Implements_Interface;
4897 function In_Instance return Boolean is
4898 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4904 and then S /= Standard_Standard
4906 if (Ekind (S) = E_Function
4907 or else Ekind (S) = E_Package
4908 or else Ekind (S) = E_Procedure)
4909 and then Is_Generic_Instance (S)
4911 -- A child instance is always compiled in the context of a parent
4912 -- instance. Nevertheless, the actuals are not analyzed in an
4913 -- instance context. We detect this case by examining the current
4914 -- compilation unit, which must be a child instance, and checking
4915 -- that it is not currently on the scope stack.
4917 if Is_Child_Unit (Curr_Unit)
4919 Nkind (Unit (Cunit (Current_Sem_Unit)))
4920 = N_Package_Instantiation
4921 and then not In_Open_Scopes (Curr_Unit)
4935 ----------------------
4936 -- In_Instance_Body --
4937 ----------------------
4939 function In_Instance_Body return Boolean is
4945 and then S /= Standard_Standard
4947 if (Ekind (S) = E_Function
4948 or else Ekind (S) = E_Procedure)
4949 and then Is_Generic_Instance (S)
4953 elsif Ekind (S) = E_Package
4954 and then In_Package_Body (S)
4955 and then Is_Generic_Instance (S)
4964 end In_Instance_Body;
4966 -----------------------------
4967 -- In_Instance_Not_Visible --
4968 -----------------------------
4970 function In_Instance_Not_Visible return Boolean is
4976 and then S /= Standard_Standard
4978 if (Ekind (S) = E_Function
4979 or else Ekind (S) = E_Procedure)
4980 and then Is_Generic_Instance (S)
4984 elsif Ekind (S) = E_Package
4985 and then (In_Package_Body (S) or else In_Private_Part (S))
4986 and then Is_Generic_Instance (S)
4995 end In_Instance_Not_Visible;
4997 ------------------------------
4998 -- In_Instance_Visible_Part --
4999 ------------------------------
5001 function In_Instance_Visible_Part return Boolean is
5007 and then S /= Standard_Standard
5009 if Ekind (S) = E_Package
5010 and then Is_Generic_Instance (S)
5011 and then not In_Package_Body (S)
5012 and then not In_Private_Part (S)
5021 end In_Instance_Visible_Part;
5023 ---------------------
5024 -- In_Package_Body --
5025 ---------------------
5027 function In_Package_Body return Boolean is
5033 and then S /= Standard_Standard
5035 if Ekind (S) = E_Package
5036 and then In_Package_Body (S)
5045 end In_Package_Body;
5047 --------------------------------
5048 -- In_Parameter_Specification --
5049 --------------------------------
5051 function In_Parameter_Specification (N : Node_Id) return Boolean is
5056 while Present (PN) loop
5057 if Nkind (PN) = N_Parameter_Specification then
5065 end In_Parameter_Specification;
5067 --------------------------------------
5068 -- In_Subprogram_Or_Concurrent_Unit --
5069 --------------------------------------
5071 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5076 -- Use scope chain to check successively outer scopes
5082 if K in Subprogram_Kind
5083 or else K in Concurrent_Kind
5084 or else K in Generic_Subprogram_Kind
5088 elsif E = Standard_Standard then
5094 end In_Subprogram_Or_Concurrent_Unit;
5096 ---------------------
5097 -- In_Visible_Part --
5098 ---------------------
5100 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5103 Is_Package_Or_Generic_Package (Scope_Id)
5104 and then In_Open_Scopes (Scope_Id)
5105 and then not In_Package_Body (Scope_Id)
5106 and then not In_Private_Part (Scope_Id);
5107 end In_Visible_Part;
5109 ---------------------------------
5110 -- Insert_Explicit_Dereference --
5111 ---------------------------------
5113 procedure Insert_Explicit_Dereference (N : Node_Id) is
5114 New_Prefix : constant Node_Id := Relocate_Node (N);
5115 Ent : Entity_Id := Empty;
5122 Save_Interps (N, New_Prefix);
5124 Make_Explicit_Dereference (Sloc (N),
5125 Prefix => New_Prefix));
5127 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5129 if Is_Overloaded (New_Prefix) then
5131 -- The deference is also overloaded, and its interpretations are the
5132 -- designated types of the interpretations of the original node.
5134 Set_Etype (N, Any_Type);
5136 Get_First_Interp (New_Prefix, I, It);
5137 while Present (It.Nam) loop
5140 if Is_Access_Type (T) then
5141 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5144 Get_Next_Interp (I, It);
5150 -- Prefix is unambiguous: mark the original prefix (which might
5151 -- Come_From_Source) as a reference, since the new (relocated) one
5152 -- won't be taken into account.
5154 if Is_Entity_Name (New_Prefix) then
5155 Ent := Entity (New_Prefix);
5157 -- For a retrieval of a subcomponent of some composite object,
5158 -- retrieve the ultimate entity if there is one.
5160 elsif Nkind (New_Prefix) = N_Selected_Component
5161 or else Nkind (New_Prefix) = N_Indexed_Component
5163 Pref := Prefix (New_Prefix);
5164 while Present (Pref)
5166 (Nkind (Pref) = N_Selected_Component
5167 or else Nkind (Pref) = N_Indexed_Component)
5169 Pref := Prefix (Pref);
5172 if Present (Pref) and then Is_Entity_Name (Pref) then
5173 Ent := Entity (Pref);
5177 if Present (Ent) then
5178 Generate_Reference (Ent, New_Prefix);
5181 end Insert_Explicit_Dereference;
5183 ------------------------------------------
5184 -- Inspect_Deferred_Constant_Completion --
5185 ------------------------------------------
5187 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5191 Decl := First (Decls);
5192 while Present (Decl) loop
5194 -- Deferred constant signature
5196 if Nkind (Decl) = N_Object_Declaration
5197 and then Constant_Present (Decl)
5198 and then No (Expression (Decl))
5200 -- No need to check internally generated constants
5202 and then Comes_From_Source (Decl)
5204 -- The constant is not completed. A full object declaration
5205 -- or a pragma Import complete a deferred constant.
5207 and then not Has_Completion (Defining_Identifier (Decl))
5210 ("constant declaration requires initialization expression",
5211 Defining_Identifier (Decl));
5214 Decl := Next (Decl);
5216 end Inspect_Deferred_Constant_Completion;
5222 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5223 pragma Assert (Is_Type (E));
5225 return AAMP_On_Target
5226 and then Is_Floating_Point_Type (E)
5227 and then E = Base_Type (E);
5230 -------------------------
5231 -- Is_Actual_Parameter --
5232 -------------------------
5234 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5235 PK : constant Node_Kind := Nkind (Parent (N));
5239 when N_Parameter_Association =>
5240 return N = Explicit_Actual_Parameter (Parent (N));
5242 when N_Function_Call | N_Procedure_Call_Statement =>
5243 return Is_List_Member (N)
5245 List_Containing (N) = Parameter_Associations (Parent (N));
5250 end Is_Actual_Parameter;
5252 ---------------------
5253 -- Is_Aliased_View --
5254 ---------------------
5256 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5260 if Is_Entity_Name (Obj) then
5268 or else (Present (Renamed_Object (E))
5269 and then Is_Aliased_View (Renamed_Object (E)))))
5271 or else ((Is_Formal (E)
5272 or else Ekind (E) = E_Generic_In_Out_Parameter
5273 or else Ekind (E) = E_Generic_In_Parameter)
5274 and then Is_Tagged_Type (Etype (E)))
5276 or else (Is_Concurrent_Type (E)
5277 and then In_Open_Scopes (E))
5279 -- Current instance of type, either directly or as rewritten
5280 -- reference to the current object.
5282 or else (Is_Entity_Name (Original_Node (Obj))
5283 and then Present (Entity (Original_Node (Obj)))
5284 and then Is_Type (Entity (Original_Node (Obj))))
5286 or else (Is_Type (E) and then E = Current_Scope)
5288 or else (Is_Incomplete_Or_Private_Type (E)
5289 and then Full_View (E) = Current_Scope);
5291 elsif Nkind (Obj) = N_Selected_Component then
5292 return Is_Aliased (Entity (Selector_Name (Obj)));
5294 elsif Nkind (Obj) = N_Indexed_Component then
5295 return Has_Aliased_Components (Etype (Prefix (Obj)))
5297 (Is_Access_Type (Etype (Prefix (Obj)))
5299 Has_Aliased_Components
5300 (Designated_Type (Etype (Prefix (Obj)))));
5302 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5303 or else Nkind (Obj) = N_Type_Conversion
5305 return Is_Tagged_Type (Etype (Obj))
5306 and then Is_Aliased_View (Expression (Obj));
5308 elsif Nkind (Obj) = N_Explicit_Dereference then
5309 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5314 end Is_Aliased_View;
5316 -------------------------
5317 -- Is_Ancestor_Package --
5318 -------------------------
5320 function Is_Ancestor_Package
5322 E2 : Entity_Id) return Boolean
5329 and then Par /= Standard_Standard
5339 end Is_Ancestor_Package;
5341 ----------------------
5342 -- Is_Atomic_Object --
5343 ----------------------
5345 function Is_Atomic_Object (N : Node_Id) return Boolean is
5347 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5348 -- Determines if given object has atomic components
5350 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5351 -- If prefix is an implicit dereference, examine designated type
5353 ----------------------
5354 -- Is_Atomic_Prefix --
5355 ----------------------
5357 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5359 if Is_Access_Type (Etype (N)) then
5361 Has_Atomic_Components (Designated_Type (Etype (N)));
5363 return Object_Has_Atomic_Components (N);
5365 end Is_Atomic_Prefix;
5367 ----------------------------------
5368 -- Object_Has_Atomic_Components --
5369 ----------------------------------
5371 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5373 if Has_Atomic_Components (Etype (N))
5374 or else Is_Atomic (Etype (N))
5378 elsif Is_Entity_Name (N)
5379 and then (Has_Atomic_Components (Entity (N))
5380 or else Is_Atomic (Entity (N)))
5384 elsif Nkind (N) = N_Indexed_Component
5385 or else Nkind (N) = N_Selected_Component
5387 return Is_Atomic_Prefix (Prefix (N));
5392 end Object_Has_Atomic_Components;
5394 -- Start of processing for Is_Atomic_Object
5397 if Is_Atomic (Etype (N))
5398 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5402 elsif Nkind (N) = N_Indexed_Component
5403 or else Nkind (N) = N_Selected_Component
5405 return Is_Atomic_Prefix (Prefix (N));
5410 end Is_Atomic_Object;
5412 -------------------------
5413 -- Is_Coextension_Root --
5414 -------------------------
5416 function Is_Coextension_Root (N : Node_Id) return Boolean is
5419 Nkind (N) = N_Allocator
5420 and then Present (Coextensions (N))
5422 -- Anonymous access discriminants carry a list of all nested
5423 -- controlled coextensions.
5425 and then not Is_Dynamic_Coextension (N)
5426 and then not Is_Static_Coextension (N);
5427 end Is_Coextension_Root;
5429 -----------------------------
5430 -- Is_Concurrent_Interface --
5431 -----------------------------
5433 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5438 (Is_Protected_Interface (T)
5439 or else Is_Synchronized_Interface (T)
5440 or else Is_Task_Interface (T));
5441 end Is_Concurrent_Interface;
5443 --------------------------------------
5444 -- Is_Controlling_Limited_Procedure --
5445 --------------------------------------
5447 function Is_Controlling_Limited_Procedure
5448 (Proc_Nam : Entity_Id) return Boolean
5450 Param_Typ : Entity_Id := Empty;
5453 if Ekind (Proc_Nam) = E_Procedure
5454 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5456 Param_Typ := Etype (Parameter_Type (First (
5457 Parameter_Specifications (Parent (Proc_Nam)))));
5459 -- In this case where an Itype was created, the procedure call has been
5462 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5463 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5465 Present (Parameter_Associations
5466 (Associated_Node_For_Itype (Proc_Nam)))
5469 Etype (First (Parameter_Associations
5470 (Associated_Node_For_Itype (Proc_Nam))));
5473 if Present (Param_Typ) then
5475 Is_Interface (Param_Typ)
5476 and then Is_Limited_Record (Param_Typ);
5480 end Is_Controlling_Limited_Procedure;
5482 ----------------------------------------------
5483 -- Is_Dependent_Component_Of_Mutable_Object --
5484 ----------------------------------------------
5486 function Is_Dependent_Component_Of_Mutable_Object
5487 (Object : Node_Id) return Boolean
5490 Prefix_Type : Entity_Id;
5491 P_Aliased : Boolean := False;
5494 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5495 -- Returns True if and only if Comp is declared within a variant part
5497 --------------------------------
5498 -- Is_Declared_Within_Variant --
5499 --------------------------------
5501 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5502 Comp_Decl : constant Node_Id := Parent (Comp);
5503 Comp_List : constant Node_Id := Parent (Comp_Decl);
5505 return Nkind (Parent (Comp_List)) = N_Variant;
5506 end Is_Declared_Within_Variant;
5508 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5511 if Is_Variable (Object) then
5513 if Nkind (Object) = N_Selected_Component then
5514 P := Prefix (Object);
5515 Prefix_Type := Etype (P);
5517 if Is_Entity_Name (P) then
5519 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5520 Prefix_Type := Base_Type (Prefix_Type);
5523 if Is_Aliased (Entity (P)) then
5527 -- A discriminant check on a selected component may be
5528 -- expanded into a dereference when removing side-effects.
5529 -- Recover the original node and its type, which may be
5532 elsif Nkind (P) = N_Explicit_Dereference
5533 and then not (Comes_From_Source (P))
5535 P := Original_Node (P);
5536 Prefix_Type := Etype (P);
5539 -- Check for prefix being an aliased component ???
5544 -- A heap object is constrained by its initial value
5546 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5547 -- the dereferenced case, since the access value might denote an
5548 -- unconstrained aliased object, whereas in Ada 95 the designated
5549 -- object is guaranteed to be constrained. A worst-case assumption
5550 -- has to apply in Ada 2005 because we can't tell at compile time
5551 -- whether the object is "constrained by its initial value"
5552 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5553 -- semantic rules -- these rules are acknowledged to need fixing).
5555 if Ada_Version < Ada_05 then
5556 if Is_Access_Type (Prefix_Type)
5557 or else Nkind (P) = N_Explicit_Dereference
5562 elsif Ada_Version >= Ada_05 then
5563 if Is_Access_Type (Prefix_Type) then
5565 -- If the access type is pool-specific, and there is no
5566 -- constrained partial view of the designated type, then the
5567 -- designated object is known to be constrained.
5569 if Ekind (Prefix_Type) = E_Access_Type
5570 and then not Has_Constrained_Partial_View
5571 (Designated_Type (Prefix_Type))
5575 -- Otherwise (general access type, or there is a constrained
5576 -- partial view of the designated type), we need to check
5577 -- based on the designated type.
5580 Prefix_Type := Designated_Type (Prefix_Type);
5586 Original_Record_Component (Entity (Selector_Name (Object)));
5588 -- As per AI-0017, the renaming is illegal in a generic body,
5589 -- even if the subtype is indefinite.
5591 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5593 if not Is_Constrained (Prefix_Type)
5594 and then (not Is_Indefinite_Subtype (Prefix_Type)
5596 (Is_Generic_Type (Prefix_Type)
5597 and then Ekind (Current_Scope) = E_Generic_Package
5598 and then In_Package_Body (Current_Scope)))
5600 and then (Is_Declared_Within_Variant (Comp)
5601 or else Has_Discriminant_Dependent_Constraint (Comp))
5602 and then (not P_Aliased or else Ada_Version >= Ada_05)
5608 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5612 elsif Nkind (Object) = N_Indexed_Component
5613 or else Nkind (Object) = N_Slice
5615 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5617 -- A type conversion that Is_Variable is a view conversion:
5618 -- go back to the denoted object.
5620 elsif Nkind (Object) = N_Type_Conversion then
5622 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5627 end Is_Dependent_Component_Of_Mutable_Object;
5629 ---------------------
5630 -- Is_Dereferenced --
5631 ---------------------
5633 function Is_Dereferenced (N : Node_Id) return Boolean is
5634 P : constant Node_Id := Parent (N);
5637 (Nkind (P) = N_Selected_Component
5639 Nkind (P) = N_Explicit_Dereference
5641 Nkind (P) = N_Indexed_Component
5643 Nkind (P) = N_Slice)
5644 and then Prefix (P) = N;
5645 end Is_Dereferenced;
5647 ----------------------
5648 -- Is_Descendent_Of --
5649 ----------------------
5651 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5656 pragma Assert (Nkind (T1) in N_Entity);
5657 pragma Assert (Nkind (T2) in N_Entity);
5659 T := Base_Type (T1);
5661 -- Immediate return if the types match
5666 -- Comment needed here ???
5668 elsif Ekind (T) = E_Class_Wide_Type then
5669 return Etype (T) = T2;
5677 -- Done if we found the type we are looking for
5682 -- Done if no more derivations to check
5689 -- Following test catches error cases resulting from prev errors
5691 elsif No (Etyp) then
5694 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5697 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5701 T := Base_Type (Etyp);
5704 end Is_Descendent_Of;
5710 function Is_False (U : Uint) return Boolean is
5715 ---------------------------
5716 -- Is_Fixed_Model_Number --
5717 ---------------------------
5719 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5720 S : constant Ureal := Small_Value (T);
5721 M : Urealp.Save_Mark;
5725 R := (U = UR_Trunc (U / S) * S);
5728 end Is_Fixed_Model_Number;
5730 -------------------------------
5731 -- Is_Fully_Initialized_Type --
5732 -------------------------------
5734 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5736 if Is_Scalar_Type (Typ) then
5739 elsif Is_Access_Type (Typ) then
5742 elsif Is_Array_Type (Typ) then
5743 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5747 -- An interesting case, if we have a constrained type one of whose
5748 -- bounds is known to be null, then there are no elements to be
5749 -- initialized, so all the elements are initialized!
5751 if Is_Constrained (Typ) then
5754 Indx_Typ : Entity_Id;
5758 Indx := First_Index (Typ);
5759 while Present (Indx) loop
5760 if Etype (Indx) = Any_Type then
5763 -- If index is a range, use directly
5765 elsif Nkind (Indx) = N_Range then
5766 Lbd := Low_Bound (Indx);
5767 Hbd := High_Bound (Indx);
5770 Indx_Typ := Etype (Indx);
5772 if Is_Private_Type (Indx_Typ) then
5773 Indx_Typ := Full_View (Indx_Typ);
5776 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5779 Lbd := Type_Low_Bound (Indx_Typ);
5780 Hbd := Type_High_Bound (Indx_Typ);
5784 if Compile_Time_Known_Value (Lbd)
5785 and then Compile_Time_Known_Value (Hbd)
5787 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5797 -- If no null indexes, then type is not fully initialized
5803 elsif Is_Record_Type (Typ) then
5804 if Has_Discriminants (Typ)
5806 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5807 and then Is_Fully_Initialized_Variant (Typ)
5812 -- Controlled records are considered to be fully initialized if
5813 -- there is a user defined Initialize routine. This may not be
5814 -- entirely correct, but as the spec notes, we are guessing here
5815 -- what is best from the point of view of issuing warnings.
5817 if Is_Controlled (Typ) then
5819 Utyp : constant Entity_Id := Underlying_Type (Typ);
5822 if Present (Utyp) then
5824 Init : constant Entity_Id :=
5826 (Underlying_Type (Typ), Name_Initialize));
5830 and then Comes_From_Source (Init)
5832 Is_Predefined_File_Name
5833 (File_Name (Get_Source_File_Index (Sloc (Init))))
5837 elsif Has_Null_Extension (Typ)
5839 Is_Fully_Initialized_Type
5840 (Etype (Base_Type (Typ)))
5849 -- Otherwise see if all record components are initialized
5855 Ent := First_Entity (Typ);
5856 while Present (Ent) loop
5857 if Chars (Ent) = Name_uController then
5860 elsif Ekind (Ent) = E_Component
5861 and then (No (Parent (Ent))
5862 or else No (Expression (Parent (Ent))))
5863 and then not Is_Fully_Initialized_Type (Etype (Ent))
5865 -- Special VM case for tag components, which need to be
5866 -- defined in this case, but are never initialized as VMs
5867 -- are using other dispatching mechanisms. Ignore this
5868 -- uninitialized case. Note that this applies both to the
5869 -- uTag entry and the main vtable pointer (CPP_Class case).
5871 and then (VM_Target = No_VM or else not Is_Tag (Ent))
5880 -- No uninitialized components, so type is fully initialized.
5881 -- Note that this catches the case of no components as well.
5885 elsif Is_Concurrent_Type (Typ) then
5888 elsif Is_Private_Type (Typ) then
5890 U : constant Entity_Id := Underlying_Type (Typ);
5896 return Is_Fully_Initialized_Type (U);
5903 end Is_Fully_Initialized_Type;
5905 ----------------------------------
5906 -- Is_Fully_Initialized_Variant --
5907 ----------------------------------
5909 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5910 Loc : constant Source_Ptr := Sloc (Typ);
5911 Constraints : constant List_Id := New_List;
5912 Components : constant Elist_Id := New_Elmt_List;
5913 Comp_Elmt : Elmt_Id;
5915 Comp_List : Node_Id;
5917 Discr_Val : Node_Id;
5919 Report_Errors : Boolean;
5920 pragma Warnings (Off, Report_Errors);
5923 if Serious_Errors_Detected > 0 then
5927 if Is_Record_Type (Typ)
5928 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5929 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5931 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5933 Discr := First_Discriminant (Typ);
5934 while Present (Discr) loop
5935 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5936 Discr_Val := Expression (Parent (Discr));
5938 if Present (Discr_Val)
5939 and then Is_OK_Static_Expression (Discr_Val)
5941 Append_To (Constraints,
5942 Make_Component_Association (Loc,
5943 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5944 Expression => New_Copy (Discr_Val)));
5952 Next_Discriminant (Discr);
5957 Comp_List => Comp_List,
5958 Governed_By => Constraints,
5960 Report_Errors => Report_Errors);
5962 -- Check that each component present is fully initialized
5964 Comp_Elmt := First_Elmt (Components);
5965 while Present (Comp_Elmt) loop
5966 Comp_Id := Node (Comp_Elmt);
5968 if Ekind (Comp_Id) = E_Component
5969 and then (No (Parent (Comp_Id))
5970 or else No (Expression (Parent (Comp_Id))))
5971 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5976 Next_Elmt (Comp_Elmt);
5981 elsif Is_Private_Type (Typ) then
5983 U : constant Entity_Id := Underlying_Type (Typ);
5989 return Is_Fully_Initialized_Variant (U);
5995 end Is_Fully_Initialized_Variant;
5997 ----------------------------
5998 -- Is_Inherited_Operation --
5999 ----------------------------
6001 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6002 Kind : constant Node_Kind := Nkind (Parent (E));
6004 pragma Assert (Is_Overloadable (E));
6005 return Kind = N_Full_Type_Declaration
6006 or else Kind = N_Private_Extension_Declaration
6007 or else Kind = N_Subtype_Declaration
6008 or else (Ekind (E) = E_Enumeration_Literal
6009 and then Is_Derived_Type (Etype (E)));
6010 end Is_Inherited_Operation;
6012 -----------------------------
6013 -- Is_Library_Level_Entity --
6014 -----------------------------
6016 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6018 -- The following is a small optimization, and it also properly handles
6019 -- discriminals, which in task bodies might appear in expressions before
6020 -- the corresponding procedure has been created, and which therefore do
6021 -- not have an assigned scope.
6023 if Ekind (E) in Formal_Kind then
6027 -- Normal test is simply that the enclosing dynamic scope is Standard
6029 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6030 end Is_Library_Level_Entity;
6032 ---------------------------------
6033 -- Is_Local_Variable_Reference --
6034 ---------------------------------
6036 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6038 if not Is_Entity_Name (Expr) then
6043 Ent : constant Entity_Id := Entity (Expr);
6044 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6046 if Ekind (Ent) /= E_Variable
6048 Ekind (Ent) /= E_In_Out_Parameter
6052 return Present (Sub) and then Sub = Current_Subprogram;
6056 end Is_Local_Variable_Reference;
6058 -------------------------
6059 -- Is_Object_Reference --
6060 -------------------------
6062 function Is_Object_Reference (N : Node_Id) return Boolean is
6064 if Is_Entity_Name (N) then
6065 return Present (Entity (N)) and then Is_Object (Entity (N));
6069 when N_Indexed_Component | N_Slice =>
6071 Is_Object_Reference (Prefix (N))
6072 or else Is_Access_Type (Etype (Prefix (N)));
6074 -- In Ada95, a function call is a constant object; a procedure
6077 when N_Function_Call =>
6078 return Etype (N) /= Standard_Void_Type;
6080 -- A reference to the stream attribute Input is a function call
6082 when N_Attribute_Reference =>
6083 return Attribute_Name (N) = Name_Input;
6085 when N_Selected_Component =>
6087 Is_Object_Reference (Selector_Name (N))
6089 (Is_Object_Reference (Prefix (N))
6090 or else Is_Access_Type (Etype (Prefix (N))));
6092 when N_Explicit_Dereference =>
6095 -- A view conversion of a tagged object is an object reference
6097 when N_Type_Conversion =>
6098 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6099 and then Is_Tagged_Type (Etype (Expression (N)))
6100 and then Is_Object_Reference (Expression (N));
6102 -- An unchecked type conversion is considered to be an object if
6103 -- the operand is an object (this construction arises only as a
6104 -- result of expansion activities).
6106 when N_Unchecked_Type_Conversion =>
6113 end Is_Object_Reference;
6115 -----------------------------------
6116 -- Is_OK_Variable_For_Out_Formal --
6117 -----------------------------------
6119 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6121 Note_Possible_Modification (AV, Sure => True);
6123 -- We must reject parenthesized variable names. The check for
6124 -- Comes_From_Source is present because there are currently
6125 -- cases where the compiler violates this rule (e.g. passing
6126 -- a task object to its controlled Initialize routine).
6128 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6131 -- A variable is always allowed
6133 elsif Is_Variable (AV) then
6136 -- Unchecked conversions are allowed only if they come from the
6137 -- generated code, which sometimes uses unchecked conversions for out
6138 -- parameters in cases where code generation is unaffected. We tell
6139 -- source unchecked conversions by seeing if they are rewrites of an
6140 -- original Unchecked_Conversion function call, or of an explicit
6141 -- conversion of a function call.
6143 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6144 if Nkind (Original_Node (AV)) = N_Function_Call then
6147 elsif Comes_From_Source (AV)
6148 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6152 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6153 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6159 -- Normal type conversions are allowed if argument is a variable
6161 elsif Nkind (AV) = N_Type_Conversion then
6162 if Is_Variable (Expression (AV))
6163 and then Paren_Count (Expression (AV)) = 0
6165 Note_Possible_Modification (Expression (AV), Sure => True);
6168 -- We also allow a non-parenthesized expression that raises
6169 -- constraint error if it rewrites what used to be a variable
6171 elsif Raises_Constraint_Error (Expression (AV))
6172 and then Paren_Count (Expression (AV)) = 0
6173 and then Is_Variable (Original_Node (Expression (AV)))
6177 -- Type conversion of something other than a variable
6183 -- If this node is rewritten, then test the original form, if that is
6184 -- OK, then we consider the rewritten node OK (for example, if the
6185 -- original node is a conversion, then Is_Variable will not be true
6186 -- but we still want to allow the conversion if it converts a variable).
6188 elsif Original_Node (AV) /= AV then
6189 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6191 -- All other non-variables are rejected
6196 end Is_OK_Variable_For_Out_Formal;
6198 -----------------------------------
6199 -- Is_Partially_Initialized_Type --
6200 -----------------------------------
6202 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6204 if Is_Scalar_Type (Typ) then
6207 elsif Is_Access_Type (Typ) then
6210 elsif Is_Array_Type (Typ) then
6212 -- If component type is partially initialized, so is array type
6214 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6217 -- Otherwise we are only partially initialized if we are fully
6218 -- initialized (this is the empty array case, no point in us
6219 -- duplicating that code here).
6222 return Is_Fully_Initialized_Type (Typ);
6225 elsif Is_Record_Type (Typ) then
6227 -- A discriminated type is always partially initialized
6229 if Has_Discriminants (Typ) then
6232 -- A tagged type is always partially initialized
6234 elsif Is_Tagged_Type (Typ) then
6237 -- Case of non-discriminated record
6243 Component_Present : Boolean := False;
6244 -- Set True if at least one component is present. If no
6245 -- components are present, then record type is fully
6246 -- initialized (another odd case, like the null array).
6249 -- Loop through components
6251 Ent := First_Entity (Typ);
6252 while Present (Ent) loop
6253 if Ekind (Ent) = E_Component then
6254 Component_Present := True;
6256 -- If a component has an initialization expression then
6257 -- the enclosing record type is partially initialized
6259 if Present (Parent (Ent))
6260 and then Present (Expression (Parent (Ent)))
6264 -- If a component is of a type which is itself partially
6265 -- initialized, then the enclosing record type is also.
6267 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6275 -- No initialized components found. If we found any components
6276 -- they were all uninitialized so the result is false.
6278 if Component_Present then
6281 -- But if we found no components, then all the components are
6282 -- initialized so we consider the type to be initialized.
6290 -- Concurrent types are always fully initialized
6292 elsif Is_Concurrent_Type (Typ) then
6295 -- For a private type, go to underlying type. If there is no underlying
6296 -- type then just assume this partially initialized. Not clear if this
6297 -- can happen in a non-error case, but no harm in testing for this.
6299 elsif Is_Private_Type (Typ) then
6301 U : constant Entity_Id := Underlying_Type (Typ);
6306 return Is_Partially_Initialized_Type (U);
6310 -- For any other type (are there any?) assume partially initialized
6315 end Is_Partially_Initialized_Type;
6317 ------------------------------------
6318 -- Is_Potentially_Persistent_Type --
6319 ------------------------------------
6321 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6326 -- For private type, test corresponding full type
6328 if Is_Private_Type (T) then
6329 return Is_Potentially_Persistent_Type (Full_View (T));
6331 -- Scalar types are potentially persistent
6333 elsif Is_Scalar_Type (T) then
6336 -- Record type is potentially persistent if not tagged and the types of
6337 -- all it components are potentially persistent, and no component has
6338 -- an initialization expression.
6340 elsif Is_Record_Type (T)
6341 and then not Is_Tagged_Type (T)
6342 and then not Is_Partially_Initialized_Type (T)
6344 Comp := First_Component (T);
6345 while Present (Comp) loop
6346 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6355 -- Array type is potentially persistent if its component type is
6356 -- potentially persistent and if all its constraints are static.
6358 elsif Is_Array_Type (T) then
6359 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6363 Indx := First_Index (T);
6364 while Present (Indx) loop
6365 if not Is_OK_Static_Subtype (Etype (Indx)) then
6374 -- All other types are not potentially persistent
6379 end Is_Potentially_Persistent_Type;
6381 ---------------------------------
6382 -- Is_Protected_Self_Reference --
6383 ---------------------------------
6385 function Is_Protected_Self_Reference (N : Node_Id) return Boolean
6387 function In_Access_Definition (N : Node_Id) return Boolean;
6388 -- Returns true if N belongs to an access definition
6390 --------------------------
6391 -- In_Access_Definition --
6392 --------------------------
6394 function In_Access_Definition (N : Node_Id) return Boolean
6396 P : Node_Id := Parent (N);
6398 while Present (P) loop
6399 if Nkind (P) = N_Access_Definition then
6405 end In_Access_Definition;
6407 -- Start of processing for Is_Protected_Self_Reference
6410 return Ada_Version >= Ada_05
6411 and then Is_Entity_Name (N)
6412 and then Is_Protected_Type (Entity (N))
6413 and then In_Open_Scopes (Entity (N))
6414 and then not In_Access_Definition (N);
6415 end Is_Protected_Self_Reference;
6417 -----------------------------
6418 -- Is_RCI_Pkg_Spec_Or_Body --
6419 -----------------------------
6421 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6423 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6424 -- Return True if the unit of Cunit is an RCI package declaration
6426 ---------------------------
6427 -- Is_RCI_Pkg_Decl_Cunit --
6428 ---------------------------
6430 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6431 The_Unit : constant Node_Id := Unit (Cunit);
6434 if Nkind (The_Unit) /= N_Package_Declaration then
6438 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6439 end Is_RCI_Pkg_Decl_Cunit;
6441 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6444 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6446 (Nkind (Unit (Cunit)) = N_Package_Body
6447 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6448 end Is_RCI_Pkg_Spec_Or_Body;
6450 -----------------------------------------
6451 -- Is_Remote_Access_To_Class_Wide_Type --
6452 -----------------------------------------
6454 function Is_Remote_Access_To_Class_Wide_Type
6455 (E : Entity_Id) return Boolean
6458 -- A remote access to class-wide type is a general access to object type
6459 -- declared in the visible part of a Remote_Types or Remote_Call_
6462 return Ekind (E) = E_General_Access_Type
6463 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6464 end Is_Remote_Access_To_Class_Wide_Type;
6466 -----------------------------------------
6467 -- Is_Remote_Access_To_Subprogram_Type --
6468 -----------------------------------------
6470 function Is_Remote_Access_To_Subprogram_Type
6471 (E : Entity_Id) return Boolean
6474 return (Ekind (E) = E_Access_Subprogram_Type
6475 or else (Ekind (E) = E_Record_Type
6476 and then Present (Corresponding_Remote_Type (E))))
6477 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6478 end Is_Remote_Access_To_Subprogram_Type;
6480 --------------------
6481 -- Is_Remote_Call --
6482 --------------------
6484 function Is_Remote_Call (N : Node_Id) return Boolean is
6486 if Nkind (N) /= N_Procedure_Call_Statement
6487 and then Nkind (N) /= N_Function_Call
6489 -- An entry call cannot be remote
6493 elsif Nkind (Name (N)) in N_Has_Entity
6494 and then Is_Remote_Call_Interface (Entity (Name (N)))
6496 -- A subprogram declared in the spec of a RCI package is remote
6500 elsif Nkind (Name (N)) = N_Explicit_Dereference
6501 and then Is_Remote_Access_To_Subprogram_Type
6502 (Etype (Prefix (Name (N))))
6504 -- The dereference of a RAS is a remote call
6508 elsif Present (Controlling_Argument (N))
6509 and then Is_Remote_Access_To_Class_Wide_Type
6510 (Etype (Controlling_Argument (N)))
6512 -- Any primitive operation call with a controlling argument of
6513 -- a RACW type is a remote call.
6518 -- All other calls are local calls
6523 ----------------------
6524 -- Is_Renamed_Entry --
6525 ----------------------
6527 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6528 Orig_Node : Node_Id := Empty;
6529 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6531 function Is_Entry (Nam : Node_Id) return Boolean;
6532 -- Determine whether Nam is an entry. Traverse selectors if there are
6533 -- nested selected components.
6539 function Is_Entry (Nam : Node_Id) return Boolean is
6541 if Nkind (Nam) = N_Selected_Component then
6542 return Is_Entry (Selector_Name (Nam));
6545 return Ekind (Entity (Nam)) = E_Entry;
6548 -- Start of processing for Is_Renamed_Entry
6551 if Present (Alias (Proc_Nam)) then
6552 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6555 -- Look for a rewritten subprogram renaming declaration
6557 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6558 and then Present (Original_Node (Subp_Decl))
6560 Orig_Node := Original_Node (Subp_Decl);
6563 -- The rewritten subprogram is actually an entry
6565 if Present (Orig_Node)
6566 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6567 and then Is_Entry (Name (Orig_Node))
6573 end Is_Renamed_Entry;
6575 ----------------------
6576 -- Is_Selector_Name --
6577 ----------------------
6579 function Is_Selector_Name (N : Node_Id) return Boolean is
6581 if not Is_List_Member (N) then
6583 P : constant Node_Id := Parent (N);
6584 K : constant Node_Kind := Nkind (P);
6587 (K = N_Expanded_Name or else
6588 K = N_Generic_Association or else
6589 K = N_Parameter_Association or else
6590 K = N_Selected_Component)
6591 and then Selector_Name (P) = N;
6596 L : constant List_Id := List_Containing (N);
6597 P : constant Node_Id := Parent (L);
6599 return (Nkind (P) = N_Discriminant_Association
6600 and then Selector_Names (P) = L)
6602 (Nkind (P) = N_Component_Association
6603 and then Choices (P) = L);
6606 end Is_Selector_Name;
6612 function Is_Statement (N : Node_Id) return Boolean is
6615 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6616 or else Nkind (N) = N_Procedure_Call_Statement;
6619 ---------------------------------
6620 -- Is_Synchronized_Tagged_Type --
6621 ---------------------------------
6623 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6624 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6627 -- A task or protected type derived from an interface is a tagged type.
6628 -- Such a tagged type is called a synchronized tagged type, as are
6629 -- synchronized interfaces and private extensions whose declaration
6630 -- includes the reserved word synchronized.
6632 return (Is_Tagged_Type (E)
6633 and then (Kind = E_Task_Type
6634 or else Kind = E_Protected_Type))
6637 and then Is_Synchronized_Interface (E))
6639 (Ekind (E) = E_Record_Type_With_Private
6640 and then (Synchronized_Present (Parent (E))
6641 or else Is_Synchronized_Interface (Etype (E))));
6642 end Is_Synchronized_Tagged_Type;
6648 function Is_Transfer (N : Node_Id) return Boolean is
6649 Kind : constant Node_Kind := Nkind (N);
6652 if Kind = N_Simple_Return_Statement
6654 Kind = N_Extended_Return_Statement
6656 Kind = N_Goto_Statement
6658 Kind = N_Raise_Statement
6660 Kind = N_Requeue_Statement
6664 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6665 and then No (Condition (N))
6669 elsif Kind = N_Procedure_Call_Statement
6670 and then Is_Entity_Name (Name (N))
6671 and then Present (Entity (Name (N)))
6672 and then No_Return (Entity (Name (N)))
6676 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6688 function Is_True (U : Uint) return Boolean is
6697 function Is_Value_Type (T : Entity_Id) return Boolean is
6699 return VM_Target = CLI_Target
6700 and then Chars (T) /= No_Name
6701 and then Get_Name_String (Chars (T)) = "valuetype";
6708 function Is_Variable (N : Node_Id) return Boolean is
6710 Orig_Node : constant Node_Id := Original_Node (N);
6711 -- We do the test on the original node, since this is basically a
6712 -- test of syntactic categories, so it must not be disturbed by
6713 -- whatever rewriting might have occurred. For example, an aggregate,
6714 -- which is certainly NOT a variable, could be turned into a variable
6717 function In_Protected_Function (E : Entity_Id) return Boolean;
6718 -- Within a protected function, the private components of the
6719 -- enclosing protected type are constants. A function nested within
6720 -- a (protected) procedure is not itself protected.
6722 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6723 -- Prefixes can involve implicit dereferences, in which case we
6724 -- must test for the case of a reference of a constant access
6725 -- type, which can never be a variable.
6727 ---------------------------
6728 -- In_Protected_Function --
6729 ---------------------------
6731 function In_Protected_Function (E : Entity_Id) return Boolean is
6732 Prot : constant Entity_Id := Scope (E);
6736 if not Is_Protected_Type (Prot) then
6740 while Present (S) and then S /= Prot loop
6741 if Ekind (S) = E_Function
6742 and then Scope (S) = Prot
6752 end In_Protected_Function;
6754 ------------------------
6755 -- Is_Variable_Prefix --
6756 ------------------------
6758 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6760 if Is_Access_Type (Etype (P)) then
6761 return not Is_Access_Constant (Root_Type (Etype (P)));
6763 -- For the case of an indexed component whose prefix has a packed
6764 -- array type, the prefix has been rewritten into a type conversion.
6765 -- Determine variable-ness from the converted expression.
6767 elsif Nkind (P) = N_Type_Conversion
6768 and then not Comes_From_Source (P)
6769 and then Is_Array_Type (Etype (P))
6770 and then Is_Packed (Etype (P))
6772 return Is_Variable (Expression (P));
6775 return Is_Variable (P);
6777 end Is_Variable_Prefix;
6779 -- Start of processing for Is_Variable
6782 -- Definitely OK if Assignment_OK is set. Since this is something that
6783 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6785 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6788 -- Normally we go to the original node, but there is one exception
6789 -- where we use the rewritten node, namely when it is an explicit
6790 -- dereference. The generated code may rewrite a prefix which is an
6791 -- access type with an explicit dereference. The dereference is a
6792 -- variable, even though the original node may not be (since it could
6793 -- be a constant of the access type).
6795 -- In Ada 2005 we have a further case to consider: the prefix may be
6796 -- a function call given in prefix notation. The original node appears
6797 -- to be a selected component, but we need to examine the call.
6799 elsif Nkind (N) = N_Explicit_Dereference
6800 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6801 and then Present (Etype (Orig_Node))
6802 and then Is_Access_Type (Etype (Orig_Node))
6804 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6806 (Nkind (Orig_Node) = N_Function_Call
6807 and then not Is_Access_Constant (Etype (Prefix (N))));
6809 -- A function call is never a variable
6811 elsif Nkind (N) = N_Function_Call then
6814 -- All remaining checks use the original node
6816 elsif Is_Entity_Name (Orig_Node)
6817 and then Present (Entity (Orig_Node))
6820 E : constant Entity_Id := Entity (Orig_Node);
6821 K : constant Entity_Kind := Ekind (E);
6824 return (K = E_Variable
6825 and then Nkind (Parent (E)) /= N_Exception_Handler)
6826 or else (K = E_Component
6827 and then not In_Protected_Function (E))
6828 or else K = E_Out_Parameter
6829 or else K = E_In_Out_Parameter
6830 or else K = E_Generic_In_Out_Parameter
6832 -- Current instance of type:
6834 or else (Is_Type (E) and then In_Open_Scopes (E))
6835 or else (Is_Incomplete_Or_Private_Type (E)
6836 and then In_Open_Scopes (Full_View (E)));
6840 case Nkind (Orig_Node) is
6841 when N_Indexed_Component | N_Slice =>
6842 return Is_Variable_Prefix (Prefix (Orig_Node));
6844 when N_Selected_Component =>
6845 return Is_Variable_Prefix (Prefix (Orig_Node))
6846 and then Is_Variable (Selector_Name (Orig_Node));
6848 -- For an explicit dereference, the type of the prefix cannot
6849 -- be an access to constant or an access to subprogram.
6851 when N_Explicit_Dereference =>
6853 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6855 return Is_Access_Type (Typ)
6856 and then not Is_Access_Constant (Root_Type (Typ))
6857 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6860 -- The type conversion is the case where we do not deal with the
6861 -- context dependent special case of an actual parameter. Thus
6862 -- the type conversion is only considered a variable for the
6863 -- purposes of this routine if the target type is tagged. However,
6864 -- a type conversion is considered to be a variable if it does not
6865 -- come from source (this deals for example with the conversions
6866 -- of expressions to their actual subtypes).
6868 when N_Type_Conversion =>
6869 return Is_Variable (Expression (Orig_Node))
6871 (not Comes_From_Source (Orig_Node)
6873 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6875 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6877 -- GNAT allows an unchecked type conversion as a variable. This
6878 -- only affects the generation of internal expanded code, since
6879 -- calls to instantiations of Unchecked_Conversion are never
6880 -- considered variables (since they are function calls).
6881 -- This is also true for expression actions.
6883 when N_Unchecked_Type_Conversion =>
6884 return Is_Variable (Expression (Orig_Node));
6892 ------------------------
6893 -- Is_Volatile_Object --
6894 ------------------------
6896 function Is_Volatile_Object (N : Node_Id) return Boolean is
6898 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6899 -- Determines if given object has volatile components
6901 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6902 -- If prefix is an implicit dereference, examine designated type
6904 ------------------------
6905 -- Is_Volatile_Prefix --
6906 ------------------------
6908 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6909 Typ : constant Entity_Id := Etype (N);
6912 if Is_Access_Type (Typ) then
6914 Dtyp : constant Entity_Id := Designated_Type (Typ);
6917 return Is_Volatile (Dtyp)
6918 or else Has_Volatile_Components (Dtyp);
6922 return Object_Has_Volatile_Components (N);
6924 end Is_Volatile_Prefix;
6926 ------------------------------------
6927 -- Object_Has_Volatile_Components --
6928 ------------------------------------
6930 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6931 Typ : constant Entity_Id := Etype (N);
6934 if Is_Volatile (Typ)
6935 or else Has_Volatile_Components (Typ)
6939 elsif Is_Entity_Name (N)
6940 and then (Has_Volatile_Components (Entity (N))
6941 or else Is_Volatile (Entity (N)))
6945 elsif Nkind (N) = N_Indexed_Component
6946 or else Nkind (N) = N_Selected_Component
6948 return Is_Volatile_Prefix (Prefix (N));
6953 end Object_Has_Volatile_Components;
6955 -- Start of processing for Is_Volatile_Object
6958 if Is_Volatile (Etype (N))
6959 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6963 elsif Nkind (N) = N_Indexed_Component
6964 or else Nkind (N) = N_Selected_Component
6966 return Is_Volatile_Prefix (Prefix (N));
6971 end Is_Volatile_Object;
6973 -------------------------
6974 -- Kill_Current_Values --
6975 -------------------------
6977 procedure Kill_Current_Values
6979 Last_Assignment_Only : Boolean := False)
6982 if Is_Assignable (Ent) then
6983 Set_Last_Assignment (Ent, Empty);
6986 if not Last_Assignment_Only and then Is_Object (Ent) then
6988 Set_Current_Value (Ent, Empty);
6990 if not Can_Never_Be_Null (Ent) then
6991 Set_Is_Known_Non_Null (Ent, False);
6994 Set_Is_Known_Null (Ent, False);
6996 end Kill_Current_Values;
6998 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7001 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7002 -- Clear current value for entity E and all entities chained to E
7004 ------------------------------------------
7005 -- Kill_Current_Values_For_Entity_Chain --
7006 ------------------------------------------
7008 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7012 while Present (Ent) loop
7013 Kill_Current_Values (Ent, Last_Assignment_Only);
7016 end Kill_Current_Values_For_Entity_Chain;
7018 -- Start of processing for Kill_Current_Values
7021 -- Kill all saved checks, a special case of killing saved values
7023 if not Last_Assignment_Only then
7027 -- Loop through relevant scopes, which includes the current scope and
7028 -- any parent scopes if the current scope is a block or a package.
7033 -- Clear current values of all entities in current scope
7035 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7037 -- If scope is a package, also clear current values of all
7038 -- private entities in the scope.
7040 if Is_Package_Or_Generic_Package (S)
7041 or else Is_Concurrent_Type (S)
7043 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7046 -- If this is a not a subprogram, deal with parents
7048 if not Is_Subprogram (S) then
7050 exit Scope_Loop when S = Standard_Standard;
7054 end loop Scope_Loop;
7055 end Kill_Current_Values;
7057 --------------------------
7058 -- Kill_Size_Check_Code --
7059 --------------------------
7061 procedure Kill_Size_Check_Code (E : Entity_Id) is
7063 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7064 and then Present (Size_Check_Code (E))
7066 Remove (Size_Check_Code (E));
7067 Set_Size_Check_Code (E, Empty);
7069 end Kill_Size_Check_Code;
7071 --------------------------
7072 -- Known_To_Be_Assigned --
7073 --------------------------
7075 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7076 P : constant Node_Id := Parent (N);
7081 -- Test left side of assignment
7083 when N_Assignment_Statement =>
7084 return N = Name (P);
7086 -- Function call arguments are never lvalues
7088 when N_Function_Call =>
7091 -- Positional parameter for procedure or accept call
7093 when N_Procedure_Call_Statement |
7102 Proc := Get_Subprogram_Entity (P);
7108 -- If we are not a list member, something is strange, so
7109 -- be conservative and return False.
7111 if not Is_List_Member (N) then
7115 -- We are going to find the right formal by stepping forward
7116 -- through the formals, as we step backwards in the actuals.
7118 Form := First_Formal (Proc);
7121 -- If no formal, something is weird, so be conservative
7122 -- and return False.
7133 return Ekind (Form) /= E_In_Parameter;
7136 -- Named parameter for procedure or accept call
7138 when N_Parameter_Association =>
7144 Proc := Get_Subprogram_Entity (Parent (P));
7150 -- Loop through formals to find the one that matches
7152 Form := First_Formal (Proc);
7154 -- If no matching formal, that's peculiar, some kind of
7155 -- previous error, so return False to be conservative.
7161 -- Else test for match
7163 if Chars (Form) = Chars (Selector_Name (P)) then
7164 return Ekind (Form) /= E_In_Parameter;
7171 -- Test for appearing in a conversion that itself appears
7172 -- in an lvalue context, since this should be an lvalue.
7174 when N_Type_Conversion =>
7175 return Known_To_Be_Assigned (P);
7177 -- All other references are definitely not known to be modifications
7183 end Known_To_Be_Assigned;
7189 function May_Be_Lvalue (N : Node_Id) return Boolean is
7190 P : constant Node_Id := Parent (N);
7195 -- Test left side of assignment
7197 when N_Assignment_Statement =>
7198 return N = Name (P);
7200 -- Test prefix of component or attribute
7202 when N_Attribute_Reference =>
7203 return N = Prefix (P)
7204 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7206 when N_Expanded_Name |
7207 N_Explicit_Dereference |
7208 N_Indexed_Component |
7210 N_Selected_Component |
7212 return N = Prefix (P);
7214 -- Function call arguments are never lvalues
7216 when N_Function_Call =>
7219 -- Positional parameter for procedure, entry, or accept call
7221 when N_Procedure_Call_Statement |
7222 N_Entry_Call_Statement |
7231 Proc := Get_Subprogram_Entity (P);
7237 -- If we are not a list member, something is strange, so
7238 -- be conservative and return True.
7240 if not Is_List_Member (N) then
7244 -- We are going to find the right formal by stepping forward
7245 -- through the formals, as we step backwards in the actuals.
7247 Form := First_Formal (Proc);
7250 -- If no formal, something is weird, so be conservative
7262 return Ekind (Form) /= E_In_Parameter;
7265 -- Named parameter for procedure or accept call
7267 when N_Parameter_Association =>
7273 Proc := Get_Subprogram_Entity (Parent (P));
7279 -- Loop through formals to find the one that matches
7281 Form := First_Formal (Proc);
7283 -- If no matching formal, that's peculiar, some kind of
7284 -- previous error, so return True to be conservative.
7290 -- Else test for match
7292 if Chars (Form) = Chars (Selector_Name (P)) then
7293 return Ekind (Form) /= E_In_Parameter;
7300 -- Test for appearing in a conversion that itself appears in an
7301 -- lvalue context, since this should be an lvalue.
7303 when N_Type_Conversion =>
7304 return May_Be_Lvalue (P);
7306 -- Test for appearance in object renaming declaration
7308 when N_Object_Renaming_Declaration =>
7311 -- All other references are definitely not Lvalues
7319 -----------------------
7320 -- Mark_Coextensions --
7321 -----------------------
7323 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7324 Is_Dynamic : Boolean;
7325 -- Indicates whether the context causes nested coextensions to be
7326 -- dynamic or static
7328 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7329 -- Recognize an allocator node and label it as a dynamic coextension
7331 --------------------
7332 -- Mark_Allocator --
7333 --------------------
7335 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7337 if Nkind (N) = N_Allocator then
7339 Set_Is_Dynamic_Coextension (N);
7341 Set_Is_Static_Coextension (N);
7348 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7350 -- Start of processing Mark_Coextensions
7353 case Nkind (Context_Nod) is
7354 when N_Assignment_Statement |
7355 N_Simple_Return_Statement =>
7356 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7358 when N_Object_Declaration =>
7359 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7361 -- This routine should not be called for constructs which may not
7362 -- contain coextensions.
7365 raise Program_Error;
7368 Mark_Allocators (Root_Nod);
7369 end Mark_Coextensions;
7371 ----------------------
7372 -- Needs_One_Actual --
7373 ----------------------
7375 function Needs_One_Actual (E : Entity_Id) return Boolean is
7379 if Ada_Version >= Ada_05
7380 and then Present (First_Formal (E))
7382 Formal := Next_Formal (First_Formal (E));
7383 while Present (Formal) loop
7384 if No (Default_Value (Formal)) then
7388 Next_Formal (Formal);
7396 end Needs_One_Actual;
7398 -------------------------
7399 -- New_External_Entity --
7400 -------------------------
7402 function New_External_Entity
7403 (Kind : Entity_Kind;
7404 Scope_Id : Entity_Id;
7405 Sloc_Value : Source_Ptr;
7406 Related_Id : Entity_Id;
7408 Suffix_Index : Nat := 0;
7409 Prefix : Character := ' ') return Entity_Id
7411 N : constant Entity_Id :=
7412 Make_Defining_Identifier (Sloc_Value,
7414 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7417 Set_Ekind (N, Kind);
7418 Set_Is_Internal (N, True);
7419 Append_Entity (N, Scope_Id);
7420 Set_Public_Status (N);
7422 if Kind in Type_Kind then
7423 Init_Size_Align (N);
7427 end New_External_Entity;
7429 -------------------------
7430 -- New_Internal_Entity --
7431 -------------------------
7433 function New_Internal_Entity
7434 (Kind : Entity_Kind;
7435 Scope_Id : Entity_Id;
7436 Sloc_Value : Source_Ptr;
7437 Id_Char : Character) return Entity_Id
7439 N : constant Entity_Id :=
7440 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7443 Set_Ekind (N, Kind);
7444 Set_Is_Internal (N, True);
7445 Append_Entity (N, Scope_Id);
7447 if Kind in Type_Kind then
7448 Init_Size_Align (N);
7452 end New_Internal_Entity;
7458 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7462 -- If we are pointing at a positional parameter, it is a member of a
7463 -- node list (the list of parameters), and the next parameter is the
7464 -- next node on the list, unless we hit a parameter association, then
7465 -- we shift to using the chain whose head is the First_Named_Actual in
7466 -- the parent, and then is threaded using the Next_Named_Actual of the
7467 -- Parameter_Association. All this fiddling is because the original node
7468 -- list is in the textual call order, and what we need is the
7469 -- declaration order.
7471 if Is_List_Member (Actual_Id) then
7472 N := Next (Actual_Id);
7474 if Nkind (N) = N_Parameter_Association then
7475 return First_Named_Actual (Parent (Actual_Id));
7481 return Next_Named_Actual (Parent (Actual_Id));
7485 procedure Next_Actual (Actual_Id : in out Node_Id) is
7487 Actual_Id := Next_Actual (Actual_Id);
7490 -----------------------
7491 -- Normalize_Actuals --
7492 -----------------------
7494 -- Chain actuals according to formals of subprogram. If there are no named
7495 -- associations, the chain is simply the list of Parameter Associations,
7496 -- since the order is the same as the declaration order. If there are named
7497 -- associations, then the First_Named_Actual field in the N_Function_Call
7498 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7499 -- node for the parameter that comes first in declaration order. The
7500 -- remaining named parameters are then chained in declaration order using
7501 -- Next_Named_Actual.
7503 -- This routine also verifies that the number of actuals is compatible with
7504 -- the number and default values of formals, but performs no type checking
7505 -- (type checking is done by the caller).
7507 -- If the matching succeeds, Success is set to True and the caller proceeds
7508 -- with type-checking. If the match is unsuccessful, then Success is set to
7509 -- False, and the caller attempts a different interpretation, if there is
7512 -- If the flag Report is on, the call is not overloaded, and a failure to
7513 -- match can be reported here, rather than in the caller.
7515 procedure Normalize_Actuals
7519 Success : out Boolean)
7521 Actuals : constant List_Id := Parameter_Associations (N);
7522 Actual : Node_Id := Empty;
7524 Last : Node_Id := Empty;
7525 First_Named : Node_Id := Empty;
7528 Formals_To_Match : Integer := 0;
7529 Actuals_To_Match : Integer := 0;
7531 procedure Chain (A : Node_Id);
7532 -- Add named actual at the proper place in the list, using the
7533 -- Next_Named_Actual link.
7535 function Reporting return Boolean;
7536 -- Determines if an error is to be reported. To report an error, we
7537 -- need Report to be True, and also we do not report errors caused
7538 -- by calls to init procs that occur within other init procs. Such
7539 -- errors must always be cascaded errors, since if all the types are
7540 -- declared correctly, the compiler will certainly build decent calls!
7546 procedure Chain (A : Node_Id) is
7550 -- Call node points to first actual in list
7552 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7555 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7559 Set_Next_Named_Actual (Last, Empty);
7566 function Reporting return Boolean is
7571 elsif not Within_Init_Proc then
7574 elsif Is_Init_Proc (Entity (Name (N))) then
7582 -- Start of processing for Normalize_Actuals
7585 if Is_Access_Type (S) then
7587 -- The name in the call is a function call that returns an access
7588 -- to subprogram. The designated type has the list of formals.
7590 Formal := First_Formal (Designated_Type (S));
7592 Formal := First_Formal (S);
7595 while Present (Formal) loop
7596 Formals_To_Match := Formals_To_Match + 1;
7597 Next_Formal (Formal);
7600 -- Find if there is a named association, and verify that no positional
7601 -- associations appear after named ones.
7603 if Present (Actuals) then
7604 Actual := First (Actuals);
7607 while Present (Actual)
7608 and then Nkind (Actual) /= N_Parameter_Association
7610 Actuals_To_Match := Actuals_To_Match + 1;
7614 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7616 -- Most common case: positional notation, no defaults
7621 elsif Actuals_To_Match > Formals_To_Match then
7623 -- Too many actuals: will not work
7626 if Is_Entity_Name (Name (N)) then
7627 Error_Msg_N ("too many arguments in call to&", Name (N));
7629 Error_Msg_N ("too many arguments in call", N);
7637 First_Named := Actual;
7639 while Present (Actual) loop
7640 if Nkind (Actual) /= N_Parameter_Association then
7642 ("positional parameters not allowed after named ones", Actual);
7647 Actuals_To_Match := Actuals_To_Match + 1;
7653 if Present (Actuals) then
7654 Actual := First (Actuals);
7657 Formal := First_Formal (S);
7658 while Present (Formal) loop
7660 -- Match the formals in order. If the corresponding actual is
7661 -- positional, nothing to do. Else scan the list of named actuals
7662 -- to find the one with the right name.
7665 and then Nkind (Actual) /= N_Parameter_Association
7668 Actuals_To_Match := Actuals_To_Match - 1;
7669 Formals_To_Match := Formals_To_Match - 1;
7672 -- For named parameters, search the list of actuals to find
7673 -- one that matches the next formal name.
7675 Actual := First_Named;
7677 while Present (Actual) loop
7678 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7681 Actuals_To_Match := Actuals_To_Match - 1;
7682 Formals_To_Match := Formals_To_Match - 1;
7690 if Ekind (Formal) /= E_In_Parameter
7691 or else No (Default_Value (Formal))
7694 if (Comes_From_Source (S)
7695 or else Sloc (S) = Standard_Location)
7696 and then Is_Overloadable (S)
7700 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7702 (Nkind (Parent (N)) = N_Function_Call
7704 Nkind (Parent (N)) = N_Parameter_Association))
7705 and then Ekind (S) /= E_Function
7707 Set_Etype (N, Etype (S));
7709 Error_Msg_Name_1 := Chars (S);
7710 Error_Msg_Sloc := Sloc (S);
7712 ("missing argument for parameter & " &
7713 "in call to % declared #", N, Formal);
7716 elsif Is_Overloadable (S) then
7717 Error_Msg_Name_1 := Chars (S);
7719 -- Point to type derivation that generated the
7722 Error_Msg_Sloc := Sloc (Parent (S));
7725 ("missing argument for parameter & " &
7726 "in call to % (inherited) #", N, Formal);
7730 ("missing argument for parameter &", N, Formal);
7738 Formals_To_Match := Formals_To_Match - 1;
7743 Next_Formal (Formal);
7746 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7753 -- Find some superfluous named actual that did not get
7754 -- attached to the list of associations.
7756 Actual := First (Actuals);
7757 while Present (Actual) loop
7758 if Nkind (Actual) = N_Parameter_Association
7759 and then Actual /= Last
7760 and then No (Next_Named_Actual (Actual))
7762 Error_Msg_N ("unmatched actual & in call",
7763 Selector_Name (Actual));
7774 end Normalize_Actuals;
7776 --------------------------------
7777 -- Note_Possible_Modification --
7778 --------------------------------
7780 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
7781 Modification_Comes_From_Source : constant Boolean :=
7782 Comes_From_Source (Parent (N));
7788 -- Loop to find referenced entity, if there is one
7795 if Is_Entity_Name (Exp) then
7796 Ent := Entity (Exp);
7798 -- If the entity is missing, it is an undeclared identifier,
7799 -- and there is nothing to annotate.
7805 elsif Nkind (Exp) = N_Explicit_Dereference then
7807 P : constant Node_Id := Prefix (Exp);
7810 if Nkind (P) = N_Selected_Component
7812 Entry_Formal (Entity (Selector_Name (P))))
7814 -- Case of a reference to an entry formal
7816 Ent := Entry_Formal (Entity (Selector_Name (P)));
7818 elsif Nkind (P) = N_Identifier
7819 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7820 and then Present (Expression (Parent (Entity (P))))
7821 and then Nkind (Expression (Parent (Entity (P))))
7824 -- Case of a reference to a value on which side effects have
7827 Exp := Prefix (Expression (Parent (Entity (P))));
7836 elsif Nkind (Exp) = N_Type_Conversion
7837 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7839 Exp := Expression (Exp);
7842 elsif Nkind (Exp) = N_Slice
7843 or else Nkind (Exp) = N_Indexed_Component
7844 or else Nkind (Exp) = N_Selected_Component
7846 Exp := Prefix (Exp);
7853 -- Now look for entity being referenced
7855 if Present (Ent) then
7856 if Is_Object (Ent) then
7857 if Comes_From_Source (Exp)
7858 or else Modification_Comes_From_Source
7860 if Has_Pragma_Unmodified (Ent) then
7861 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
7864 Set_Never_Set_In_Source (Ent, False);
7867 Set_Is_True_Constant (Ent, False);
7868 Set_Current_Value (Ent, Empty);
7869 Set_Is_Known_Null (Ent, False);
7871 if not Can_Never_Be_Null (Ent) then
7872 Set_Is_Known_Non_Null (Ent, False);
7875 -- Follow renaming chain
7877 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7878 and then Present (Renamed_Object (Ent))
7880 Exp := Renamed_Object (Ent);
7884 -- Generate a reference only if the assignment comes from
7885 -- source. This excludes, for example, calls to a dispatching
7886 -- assignment operation when the left-hand side is tagged.
7888 if Modification_Comes_From_Source then
7889 Generate_Reference (Ent, Exp, 'm');
7892 Check_Nested_Access (Ent);
7897 -- If we are sure this is a modification from source, and we know
7898 -- this modifies a constant, then give an appropriate warning.
7900 if Overlays_Constant (Ent)
7901 and then Modification_Comes_From_Source
7905 A : constant Node_Id := Address_Clause (Ent);
7909 Exp : constant Node_Id := Expression (A);
7911 if Nkind (Exp) = N_Attribute_Reference
7912 and then Attribute_Name (Exp) = Name_Address
7913 and then Is_Entity_Name (Prefix (Exp))
7915 Error_Msg_Sloc := Sloc (A);
7917 ("constant& may be modified via address clause#?",
7918 N, Entity (Prefix (Exp)));
7928 end Note_Possible_Modification;
7930 -------------------------
7931 -- Object_Access_Level --
7932 -------------------------
7934 function Object_Access_Level (Obj : Node_Id) return Uint is
7937 -- Returns the static accessibility level of the view denoted by Obj. Note
7938 -- that the value returned is the result of a call to Scope_Depth. Only
7939 -- scope depths associated with dynamic scopes can actually be returned.
7940 -- Since only relative levels matter for accessibility checking, the fact
7941 -- that the distance between successive levels of accessibility is not
7942 -- always one is immaterial (invariant: if level(E2) is deeper than
7943 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7945 function Reference_To (Obj : Node_Id) return Node_Id;
7946 -- An explicit dereference is created when removing side-effects from
7947 -- expressions for constraint checking purposes. In this case a local
7948 -- access type is created for it. The correct access level is that of
7949 -- the original source node. We detect this case by noting that the
7950 -- prefix of the dereference is created by an object declaration whose
7951 -- initial expression is a reference.
7957 function Reference_To (Obj : Node_Id) return Node_Id is
7958 Pref : constant Node_Id := Prefix (Obj);
7960 if Is_Entity_Name (Pref)
7961 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7962 and then Present (Expression (Parent (Entity (Pref))))
7963 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7965 return (Prefix (Expression (Parent (Entity (Pref)))));
7971 -- Start of processing for Object_Access_Level
7974 if Is_Entity_Name (Obj) then
7977 if Is_Prival (E) then
7978 E := Prival_Link (E);
7981 -- If E is a type then it denotes a current instance. For this case
7982 -- we add one to the normal accessibility level of the type to ensure
7983 -- that current instances are treated as always being deeper than
7984 -- than the level of any visible named access type (see 3.10.2(21)).
7987 return Type_Access_Level (E) + 1;
7989 elsif Present (Renamed_Object (E)) then
7990 return Object_Access_Level (Renamed_Object (E));
7992 -- Similarly, if E is a component of the current instance of a
7993 -- protected type, any instance of it is assumed to be at a deeper
7994 -- level than the type. For a protected object (whose type is an
7995 -- anonymous protected type) its components are at the same level
7996 -- as the type itself.
7998 elsif not Is_Overloadable (E)
7999 and then Ekind (Scope (E)) = E_Protected_Type
8000 and then Comes_From_Source (Scope (E))
8002 return Type_Access_Level (Scope (E)) + 1;
8005 return Scope_Depth (Enclosing_Dynamic_Scope (E));
8008 elsif Nkind (Obj) = N_Selected_Component then
8009 if Is_Access_Type (Etype (Prefix (Obj))) then
8010 return Type_Access_Level (Etype (Prefix (Obj)));
8012 return Object_Access_Level (Prefix (Obj));
8015 elsif Nkind (Obj) = N_Indexed_Component then
8016 if Is_Access_Type (Etype (Prefix (Obj))) then
8017 return Type_Access_Level (Etype (Prefix (Obj)));
8019 return Object_Access_Level (Prefix (Obj));
8022 elsif Nkind (Obj) = N_Explicit_Dereference then
8024 -- If the prefix is a selected access discriminant then we make a
8025 -- recursive call on the prefix, which will in turn check the level
8026 -- of the prefix object of the selected discriminant.
8028 if Nkind (Prefix (Obj)) = N_Selected_Component
8029 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
8031 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
8033 return Object_Access_Level (Prefix (Obj));
8035 elsif not (Comes_From_Source (Obj)) then
8037 Ref : constant Node_Id := Reference_To (Obj);
8039 if Present (Ref) then
8040 return Object_Access_Level (Ref);
8042 return Type_Access_Level (Etype (Prefix (Obj)));
8047 return Type_Access_Level (Etype (Prefix (Obj)));
8050 elsif Nkind (Obj) = N_Type_Conversion
8051 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8053 return Object_Access_Level (Expression (Obj));
8055 -- Function results are objects, so we get either the access level of
8056 -- the function or, in the case of an indirect call, the level of of the
8057 -- access-to-subprogram type.
8059 elsif Nkind (Obj) = N_Function_Call then
8060 if Is_Entity_Name (Name (Obj)) then
8061 return Subprogram_Access_Level (Entity (Name (Obj)));
8063 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8066 -- For convenience we handle qualified expressions, even though
8067 -- they aren't technically object names.
8069 elsif Nkind (Obj) = N_Qualified_Expression then
8070 return Object_Access_Level (Expression (Obj));
8072 -- Otherwise return the scope level of Standard.
8073 -- (If there are cases that fall through
8074 -- to this point they will be treated as
8075 -- having global accessibility for now. ???)
8078 return Scope_Depth (Standard_Standard);
8080 end Object_Access_Level;
8082 -----------------------
8083 -- Private_Component --
8084 -----------------------
8086 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8087 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8089 function Trace_Components
8091 Check : Boolean) return Entity_Id;
8092 -- Recursive function that does the work, and checks against circular
8093 -- definition for each subcomponent type.
8095 ----------------------
8096 -- Trace_Components --
8097 ----------------------
8099 function Trace_Components
8101 Check : Boolean) return Entity_Id
8103 Btype : constant Entity_Id := Base_Type (T);
8104 Component : Entity_Id;
8106 Candidate : Entity_Id := Empty;
8109 if Check and then Btype = Ancestor then
8110 Error_Msg_N ("circular type definition", Type_Id);
8114 if Is_Private_Type (Btype)
8115 and then not Is_Generic_Type (Btype)
8117 if Present (Full_View (Btype))
8118 and then Is_Record_Type (Full_View (Btype))
8119 and then not Is_Frozen (Btype)
8121 -- To indicate that the ancestor depends on a private type, the
8122 -- current Btype is sufficient. However, to check for circular
8123 -- definition we must recurse on the full view.
8125 Candidate := Trace_Components (Full_View (Btype), True);
8127 if Candidate = Any_Type then
8137 elsif Is_Array_Type (Btype) then
8138 return Trace_Components (Component_Type (Btype), True);
8140 elsif Is_Record_Type (Btype) then
8141 Component := First_Entity (Btype);
8142 while Present (Component) loop
8144 -- Skip anonymous types generated by constrained components
8146 if not Is_Type (Component) then
8147 P := Trace_Components (Etype (Component), True);
8150 if P = Any_Type then
8158 Next_Entity (Component);
8166 end Trace_Components;
8168 -- Start of processing for Private_Component
8171 return Trace_Components (Type_Id, False);
8172 end Private_Component;
8174 ---------------------------
8175 -- Primitive_Names_Match --
8176 ---------------------------
8178 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
8180 function Non_Internal_Name (E : Entity_Id) return Name_Id;
8181 -- Given an internal name, returns the corresponding non-internal name
8183 ------------------------
8184 -- Non_Internal_Name --
8185 ------------------------
8187 function Non_Internal_Name (E : Entity_Id) return Name_Id is
8189 Get_Name_String (Chars (E));
8190 Name_Len := Name_Len - 1;
8192 end Non_Internal_Name;
8194 -- Start of processing for Primitive_Names_Match
8197 pragma Assert (Present (E1) and then Present (E2));
8199 return Chars (E1) = Chars (E2)
8201 (not Is_Internal_Name (Chars (E1))
8202 and then Is_Internal_Name (Chars (E2))
8203 and then Non_Internal_Name (E2) = Chars (E1))
8205 (not Is_Internal_Name (Chars (E2))
8206 and then Is_Internal_Name (Chars (E1))
8207 and then Non_Internal_Name (E1) = Chars (E2))
8209 (Is_Predefined_Dispatching_Operation (E1)
8210 and then Is_Predefined_Dispatching_Operation (E2)
8211 and then Same_TSS (E1, E2))
8213 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
8214 end Primitive_Names_Match;
8216 -----------------------
8217 -- Process_End_Label --
8218 -----------------------
8220 procedure Process_End_Label
8229 Label_Ref : Boolean;
8230 -- Set True if reference to end label itself is required
8233 -- Gets set to the operator symbol or identifier that references the
8234 -- entity Ent. For the child unit case, this is the identifier from the
8235 -- designator. For other cases, this is simply Endl.
8237 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8238 -- N is an identifier node that appears as a parent unit reference in
8239 -- the case where Ent is a child unit. This procedure generates an
8240 -- appropriate cross-reference entry. E is the corresponding entity.
8242 -------------------------
8243 -- Generate_Parent_Ref --
8244 -------------------------
8246 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8248 -- If names do not match, something weird, skip reference
8250 if Chars (E) = Chars (N) then
8252 -- Generate the reference. We do NOT consider this as a reference
8253 -- for unreferenced symbol purposes.
8255 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8258 Style.Check_Identifier (N, E);
8261 end Generate_Parent_Ref;
8263 -- Start of processing for Process_End_Label
8266 -- If no node, ignore. This happens in some error situations, and
8267 -- also for some internally generated structures where no end label
8268 -- references are required in any case.
8274 -- Nothing to do if no End_Label, happens for internally generated
8275 -- constructs where we don't want an end label reference anyway. Also
8276 -- nothing to do if Endl is a string literal, which means there was
8277 -- some prior error (bad operator symbol)
8279 Endl := End_Label (N);
8281 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8285 -- Reference node is not in extended main source unit
8287 if not In_Extended_Main_Source_Unit (N) then
8289 -- Generally we do not collect references except for the extended
8290 -- main source unit. The one exception is the 'e' entry for a
8291 -- package spec, where it is useful for a client to have the
8292 -- ending information to define scopes.
8300 -- For this case, we can ignore any parent references, but we
8301 -- need the package name itself for the 'e' entry.
8303 if Nkind (Endl) = N_Designator then
8304 Endl := Identifier (Endl);
8308 -- Reference is in extended main source unit
8313 -- For designator, generate references for the parent entries
8315 if Nkind (Endl) = N_Designator then
8317 -- Generate references for the prefix if the END line comes from
8318 -- source (otherwise we do not need these references) We climb the
8319 -- scope stack to find the expected entities.
8321 if Comes_From_Source (Endl) then
8323 Scop := Current_Scope;
8324 while Nkind (Nam) = N_Selected_Component loop
8325 Scop := Scope (Scop);
8326 exit when No (Scop);
8327 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8328 Nam := Prefix (Nam);
8331 if Present (Scop) then
8332 Generate_Parent_Ref (Nam, Scope (Scop));
8336 Endl := Identifier (Endl);
8340 -- If the end label is not for the given entity, then either we have
8341 -- some previous error, or this is a generic instantiation for which
8342 -- we do not need to make a cross-reference in this case anyway. In
8343 -- either case we simply ignore the call.
8345 if Chars (Ent) /= Chars (Endl) then
8349 -- If label was really there, then generate a normal reference and then
8350 -- adjust the location in the end label to point past the name (which
8351 -- should almost always be the semicolon).
8355 if Comes_From_Source (Endl) then
8357 -- If a label reference is required, then do the style check and
8358 -- generate an l-type cross-reference entry for the label
8362 Style.Check_Identifier (Endl, Ent);
8365 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8368 -- Set the location to point past the label (normally this will
8369 -- mean the semicolon immediately following the label). This is
8370 -- done for the sake of the 'e' or 't' entry generated below.
8372 Get_Decoded_Name_String (Chars (Endl));
8373 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8376 -- Now generate the e/t reference
8378 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8380 -- Restore Sloc, in case modified above, since we have an identifier
8381 -- and the normal Sloc should be left set in the tree.
8383 Set_Sloc (Endl, Loc);
8384 end Process_End_Label;
8390 -- We do the conversion to get the value of the real string by using
8391 -- the scanner, see Sinput for details on use of the internal source
8392 -- buffer for scanning internal strings.
8394 function Real_Convert (S : String) return Node_Id is
8395 Save_Src : constant Source_Buffer_Ptr := Source;
8399 Source := Internal_Source_Ptr;
8402 for J in S'Range loop
8403 Source (Source_Ptr (J)) := S (J);
8406 Source (S'Length + 1) := EOF;
8408 if Source (Scan_Ptr) = '-' then
8410 Scan_Ptr := Scan_Ptr + 1;
8418 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8425 --------------------
8426 -- Remove_Homonym --
8427 --------------------
8429 procedure Remove_Homonym (E : Entity_Id) is
8430 Prev : Entity_Id := Empty;
8434 if E = Current_Entity (E) then
8435 if Present (Homonym (E)) then
8436 Set_Current_Entity (Homonym (E));
8438 Set_Name_Entity_Id (Chars (E), Empty);
8441 H := Current_Entity (E);
8442 while Present (H) and then H /= E loop
8447 Set_Homonym (Prev, Homonym (E));
8451 ---------------------
8452 -- Rep_To_Pos_Flag --
8453 ---------------------
8455 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8457 return New_Occurrence_Of
8458 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8459 end Rep_To_Pos_Flag;
8461 --------------------
8462 -- Require_Entity --
8463 --------------------
8465 procedure Require_Entity (N : Node_Id) is
8467 if Is_Entity_Name (N) and then No (Entity (N)) then
8468 if Total_Errors_Detected /= 0 then
8469 Set_Entity (N, Any_Id);
8471 raise Program_Error;
8476 ------------------------------
8477 -- Requires_Transient_Scope --
8478 ------------------------------
8480 -- A transient scope is required when variable-sized temporaries are
8481 -- allocated in the primary or secondary stack, or when finalization
8482 -- actions must be generated before the next instruction.
8484 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8485 Typ : constant Entity_Id := Underlying_Type (Id);
8487 -- Start of processing for Requires_Transient_Scope
8490 -- This is a private type which is not completed yet. This can only
8491 -- happen in a default expression (of a formal parameter or of a
8492 -- record component). Do not expand transient scope in this case
8497 -- Do not expand transient scope for non-existent procedure return
8499 elsif Typ = Standard_Void_Type then
8502 -- Elementary types do not require a transient scope
8504 elsif Is_Elementary_Type (Typ) then
8507 -- Generally, indefinite subtypes require a transient scope, since the
8508 -- back end cannot generate temporaries, since this is not a valid type
8509 -- for declaring an object. It might be possible to relax this in the
8510 -- future, e.g. by declaring the maximum possible space for the type.
8512 elsif Is_Indefinite_Subtype (Typ) then
8515 -- Functions returning tagged types may dispatch on result so their
8516 -- returned value is allocated on the secondary stack. Controlled
8517 -- type temporaries need finalization.
8519 elsif Is_Tagged_Type (Typ)
8520 or else Has_Controlled_Component (Typ)
8522 return not Is_Value_Type (Typ);
8526 elsif Is_Record_Type (Typ) then
8530 Comp := First_Entity (Typ);
8531 while Present (Comp) loop
8532 if Ekind (Comp) = E_Component
8533 and then Requires_Transient_Scope (Etype (Comp))
8544 -- String literal types never require transient scope
8546 elsif Ekind (Typ) = E_String_Literal_Subtype then
8549 -- Array type. Note that we already know that this is a constrained
8550 -- array, since unconstrained arrays will fail the indefinite test.
8552 elsif Is_Array_Type (Typ) then
8554 -- If component type requires a transient scope, the array does too
8556 if Requires_Transient_Scope (Component_Type (Typ)) then
8559 -- Otherwise, we only need a transient scope if the size is not
8560 -- known at compile time.
8563 return not Size_Known_At_Compile_Time (Typ);
8566 -- All other cases do not require a transient scope
8571 end Requires_Transient_Scope;
8573 --------------------------
8574 -- Reset_Analyzed_Flags --
8575 --------------------------
8577 procedure Reset_Analyzed_Flags (N : Node_Id) is
8579 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8580 -- Function used to reset Analyzed flags in tree. Note that we do
8581 -- not reset Analyzed flags in entities, since there is no need to
8582 -- reanalyze entities, and indeed, it is wrong to do so, since it
8583 -- can result in generating auxiliary stuff more than once.
8585 --------------------
8586 -- Clear_Analyzed --
8587 --------------------
8589 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8591 if not Has_Extension (N) then
8592 Set_Analyzed (N, False);
8598 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8600 -- Start of processing for Reset_Analyzed_Flags
8604 end Reset_Analyzed_Flags;
8606 ---------------------------
8607 -- Safe_To_Capture_Value --
8608 ---------------------------
8610 function Safe_To_Capture_Value
8613 Cond : Boolean := False) return Boolean
8616 -- The only entities for which we track constant values are variables
8617 -- which are not renamings, constants, out parameters, and in out
8618 -- parameters, so check if we have this case.
8620 -- Note: it may seem odd to track constant values for constants, but in
8621 -- fact this routine is used for other purposes than simply capturing
8622 -- the value. In particular, the setting of Known[_Non]_Null.
8624 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8626 Ekind (Ent) = E_Constant
8628 Ekind (Ent) = E_Out_Parameter
8630 Ekind (Ent) = E_In_Out_Parameter
8634 -- For conditionals, we also allow loop parameters and all formals,
8635 -- including in parameters.
8639 (Ekind (Ent) = E_Loop_Parameter
8641 Ekind (Ent) = E_In_Parameter)
8645 -- For all other cases, not just unsafe, but impossible to capture
8646 -- Current_Value, since the above are the only entities which have
8647 -- Current_Value fields.
8653 -- Skip if volatile or aliased, since funny things might be going on in
8654 -- these cases which we cannot necessarily track. Also skip any variable
8655 -- for which an address clause is given, or whose address is taken. Also
8656 -- never capture value of library level variables (an attempt to do so
8657 -- can occur in the case of package elaboration code).
8659 if Treat_As_Volatile (Ent)
8660 or else Is_Aliased (Ent)
8661 or else Present (Address_Clause (Ent))
8662 or else Address_Taken (Ent)
8663 or else (Is_Library_Level_Entity (Ent)
8664 and then Ekind (Ent) = E_Variable)
8669 -- OK, all above conditions are met. We also require that the scope of
8670 -- the reference be the same as the scope of the entity, not counting
8671 -- packages and blocks and loops.
8674 E_Scope : constant Entity_Id := Scope (Ent);
8675 R_Scope : Entity_Id;
8678 R_Scope := Current_Scope;
8679 while R_Scope /= Standard_Standard loop
8680 exit when R_Scope = E_Scope;
8682 if Ekind (R_Scope) /= E_Package
8684 Ekind (R_Scope) /= E_Block
8686 Ekind (R_Scope) /= E_Loop
8690 R_Scope := Scope (R_Scope);
8695 -- We also require that the reference does not appear in a context
8696 -- where it is not sure to be executed (i.e. a conditional context
8697 -- or an exception handler). We skip this if Cond is True, since the
8698 -- capturing of values from conditional tests handles this ok.
8712 while Present (P) loop
8713 if Nkind (P) = N_If_Statement
8714 or else Nkind (P) = N_Case_Statement
8715 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8716 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8717 or else Nkind (P) = N_Exception_Handler
8718 or else Nkind (P) = N_Selective_Accept
8719 or else Nkind (P) = N_Conditional_Entry_Call
8720 or else Nkind (P) = N_Timed_Entry_Call
8721 or else Nkind (P) = N_Asynchronous_Select
8731 -- OK, looks safe to set value
8734 end Safe_To_Capture_Value;
8740 function Same_Name (N1, N2 : Node_Id) return Boolean is
8741 K1 : constant Node_Kind := Nkind (N1);
8742 K2 : constant Node_Kind := Nkind (N2);
8745 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8746 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8748 return Chars (N1) = Chars (N2);
8750 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8751 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8753 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8754 and then Same_Name (Prefix (N1), Prefix (N2));
8765 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8766 N1 : constant Node_Id := Original_Node (Node1);
8767 N2 : constant Node_Id := Original_Node (Node2);
8768 -- We do the tests on original nodes, since we are most interested
8769 -- in the original source, not any expansion that got in the way.
8771 K1 : constant Node_Kind := Nkind (N1);
8772 K2 : constant Node_Kind := Nkind (N2);
8775 -- First case, both are entities with same entity
8777 if K1 in N_Has_Entity
8778 and then K2 in N_Has_Entity
8779 and then Present (Entity (N1))
8780 and then Present (Entity (N2))
8781 and then (Ekind (Entity (N1)) = E_Variable
8783 Ekind (Entity (N1)) = E_Constant)
8784 and then Entity (N1) = Entity (N2)
8788 -- Second case, selected component with same selector, same record
8790 elsif K1 = N_Selected_Component
8791 and then K2 = N_Selected_Component
8792 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8794 return Same_Object (Prefix (N1), Prefix (N2));
8796 -- Third case, indexed component with same subscripts, same array
8798 elsif K1 = N_Indexed_Component
8799 and then K2 = N_Indexed_Component
8800 and then Same_Object (Prefix (N1), Prefix (N2))
8805 E1 := First (Expressions (N1));
8806 E2 := First (Expressions (N2));
8807 while Present (E1) loop
8808 if not Same_Value (E1, E2) then
8819 -- Fourth case, slice of same array with same bounds
8822 and then K2 = N_Slice
8823 and then Nkind (Discrete_Range (N1)) = N_Range
8824 and then Nkind (Discrete_Range (N2)) = N_Range
8825 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8826 Low_Bound (Discrete_Range (N2)))
8827 and then Same_Value (High_Bound (Discrete_Range (N1)),
8828 High_Bound (Discrete_Range (N2)))
8830 return Same_Name (Prefix (N1), Prefix (N2));
8832 -- All other cases, not clearly the same object
8843 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8848 elsif not Is_Constrained (T1)
8849 and then not Is_Constrained (T2)
8850 and then Base_Type (T1) = Base_Type (T2)
8854 -- For now don't bother with case of identical constraints, to be
8855 -- fiddled with later on perhaps (this is only used for optimization
8856 -- purposes, so it is not critical to do a best possible job)
8867 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8869 if Compile_Time_Known_Value (Node1)
8870 and then Compile_Time_Known_Value (Node2)
8871 and then Expr_Value (Node1) = Expr_Value (Node2)
8874 elsif Same_Object (Node1, Node2) then
8881 ------------------------
8882 -- Scope_Is_Transient --
8883 ------------------------
8885 function Scope_Is_Transient return Boolean is
8887 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8888 end Scope_Is_Transient;
8894 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8899 while Scop /= Standard_Standard loop
8900 Scop := Scope (Scop);
8902 if Scop = Scope2 then
8910 --------------------------
8911 -- Scope_Within_Or_Same --
8912 --------------------------
8914 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8919 while Scop /= Standard_Standard loop
8920 if Scop = Scope2 then
8923 Scop := Scope (Scop);
8928 end Scope_Within_Or_Same;
8930 --------------------
8931 -- Set_Convention --
8932 --------------------
8934 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
8936 Basic_Set_Convention (E, Val);
8939 and then Is_Access_Subprogram_Type (Base_Type (E))
8940 and then Has_Foreign_Convention (E)
8942 Set_Can_Use_Internal_Rep (E, False);
8946 ------------------------
8947 -- Set_Current_Entity --
8948 ------------------------
8950 -- The given entity is to be set as the currently visible definition
8951 -- of its associated name (i.e. the Node_Id associated with its name).
8952 -- All we have to do is to get the name from the identifier, and
8953 -- then set the associated Node_Id to point to the given entity.
8955 procedure Set_Current_Entity (E : Entity_Id) is
8957 Set_Name_Entity_Id (Chars (E), E);
8958 end Set_Current_Entity;
8960 ---------------------------
8961 -- Set_Debug_Info_Needed --
8962 ---------------------------
8964 procedure Set_Debug_Info_Needed (T : Entity_Id) is
8966 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
8967 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
8968 -- Used to set debug info in a related node if not set already
8970 --------------------------------------
8971 -- Set_Debug_Info_Needed_If_Not_Set --
8972 --------------------------------------
8974 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
8977 and then not Needs_Debug_Info (E)
8979 Set_Debug_Info_Needed (E);
8981 -- For a private type, indicate that the full view also needs
8982 -- debug information.
8985 and then Is_Private_Type (E)
8986 and then Present (Full_View (E))
8988 Set_Debug_Info_Needed (Full_View (E));
8991 end Set_Debug_Info_Needed_If_Not_Set;
8993 -- Start of processing for Set_Debug_Info_Needed
8996 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
8997 -- indicates that Debug_Info_Needed is never required for the entity.
9000 or else Debug_Info_Off (T)
9005 -- Set flag in entity itself. Note that we will go through the following
9006 -- circuitry even if the flag is already set on T. That's intentional,
9007 -- it makes sure that the flag will be set in subsidiary entities.
9009 Set_Needs_Debug_Info (T);
9011 -- Set flag on subsidiary entities if not set already
9013 if Is_Object (T) then
9014 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9016 elsif Is_Type (T) then
9017 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9019 if Is_Record_Type (T) then
9021 Ent : Entity_Id := First_Entity (T);
9023 while Present (Ent) loop
9024 Set_Debug_Info_Needed_If_Not_Set (Ent);
9029 elsif Is_Array_Type (T) then
9030 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
9033 Indx : Node_Id := First_Index (T);
9035 while Present (Indx) loop
9036 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
9037 Indx := Next_Index (Indx);
9041 if Is_Packed (T) then
9042 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
9045 elsif Is_Access_Type (T) then
9046 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
9048 elsif Is_Private_Type (T) then
9049 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9051 elsif Is_Protected_Type (T) then
9052 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9055 end Set_Debug_Info_Needed;
9057 ---------------------------------
9058 -- Set_Entity_With_Style_Check --
9059 ---------------------------------
9061 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9062 Val_Actual : Entity_Id;
9066 Set_Entity (N, Val);
9069 and then not Suppress_Style_Checks (Val)
9070 and then not In_Instance
9072 if Nkind (N) = N_Identifier then
9074 elsif Nkind (N) = N_Expanded_Name then
9075 Nod := Selector_Name (N);
9080 -- A special situation arises for derived operations, where we want
9081 -- to do the check against the parent (since the Sloc of the derived
9082 -- operation points to the derived type declaration itself).
9085 while not Comes_From_Source (Val_Actual)
9086 and then Nkind (Val_Actual) in N_Entity
9087 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9088 or else Is_Subprogram (Val_Actual)
9089 or else Is_Generic_Subprogram (Val_Actual))
9090 and then Present (Alias (Val_Actual))
9092 Val_Actual := Alias (Val_Actual);
9095 -- Renaming declarations for generic actuals do not come from source,
9096 -- and have a different name from that of the entity they rename, so
9097 -- there is no style check to perform here.
9099 if Chars (Nod) = Chars (Val_Actual) then
9100 Style.Check_Identifier (Nod, Val_Actual);
9104 Set_Entity (N, Val);
9105 end Set_Entity_With_Style_Check;
9107 ------------------------
9108 -- Set_Name_Entity_Id --
9109 ------------------------
9111 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9113 Set_Name_Table_Info (Id, Int (Val));
9114 end Set_Name_Entity_Id;
9116 ---------------------
9117 -- Set_Next_Actual --
9118 ---------------------
9120 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9122 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9123 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9125 end Set_Next_Actual;
9127 ----------------------------------
9128 -- Set_Optimize_Alignment_Flags --
9129 ----------------------------------
9131 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
9133 if Optimize_Alignment = 'S' then
9134 Set_Optimize_Alignment_Space (E);
9135 elsif Optimize_Alignment = 'T' then
9136 Set_Optimize_Alignment_Time (E);
9138 end Set_Optimize_Alignment_Flags;
9140 -----------------------
9141 -- Set_Public_Status --
9142 -----------------------
9144 procedure Set_Public_Status (Id : Entity_Id) is
9145 S : constant Entity_Id := Current_Scope;
9147 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
9148 -- Determines if E is defined within handled statement sequence or
9149 -- an if statement, returns True if so, False otherwise.
9151 ----------------------
9152 -- Within_HSS_Or_If --
9153 ----------------------
9155 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
9158 N := Declaration_Node (E);
9165 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
9171 end Within_HSS_Or_If;
9173 -- Start of processing for Set_Public_Status
9176 -- Everything in the scope of Standard is public
9178 if S = Standard_Standard then
9181 -- Entity is definitely not public if enclosing scope is not public
9183 elsif not Is_Public (S) then
9186 -- An object or function declaration that occurs in a handled sequence
9187 -- of statements or within an if statement is the declaration for a
9188 -- temporary object or local subprogram generated by the expander. It
9189 -- never needs to be made public and furthermore, making it public can
9190 -- cause back end problems.
9192 elsif Nkind_In (Parent (Id), N_Object_Declaration,
9193 N_Function_Specification)
9194 and then Within_HSS_Or_If (Id)
9198 -- Entities in public packages or records are public
9200 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9203 -- The bounds of an entry family declaration can generate object
9204 -- declarations that are visible to the back-end, e.g. in the
9205 -- the declaration of a composite type that contains tasks.
9207 elsif Is_Concurrent_Type (S)
9208 and then not Has_Completion (S)
9209 and then Nkind (Parent (Id)) = N_Object_Declaration
9213 end Set_Public_Status;
9215 -----------------------------
9216 -- Set_Referenced_Modified --
9217 -----------------------------
9219 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9223 -- Deal with indexed or selected component where prefix is modified
9225 if Nkind (N) = N_Indexed_Component
9227 Nkind (N) = N_Selected_Component
9231 -- If prefix is access type, then it is the designated object that is
9232 -- being modified, which means we have no entity to set the flag on.
9234 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9237 -- Otherwise chase the prefix
9240 Set_Referenced_Modified (Pref, Out_Param);
9243 -- Otherwise see if we have an entity name (only other case to process)
9245 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9246 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9247 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9249 end Set_Referenced_Modified;
9251 ----------------------------
9252 -- Set_Scope_Is_Transient --
9253 ----------------------------
9255 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9257 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9258 end Set_Scope_Is_Transient;
9264 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9266 -- We copy Esize, but not RM_Size, since in general RM_Size is
9267 -- subtype specific and does not get inherited by all subtypes.
9269 Set_Esize (T1, Esize (T2));
9270 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9272 if Is_Discrete_Or_Fixed_Point_Type (T1)
9274 Is_Discrete_Or_Fixed_Point_Type (T2)
9276 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9279 Set_Alignment (T1, Alignment (T2));
9282 --------------------
9283 -- Static_Integer --
9284 --------------------
9286 function Static_Integer (N : Node_Id) return Uint is
9288 Analyze_And_Resolve (N, Any_Integer);
9291 or else Error_Posted (N)
9292 or else Etype (N) = Any_Type
9297 if Is_Static_Expression (N) then
9298 if not Raises_Constraint_Error (N) then
9299 return Expr_Value (N);
9304 elsif Etype (N) = Any_Type then
9308 Flag_Non_Static_Expr
9309 ("static integer expression required here", N);
9314 --------------------------
9315 -- Statically_Different --
9316 --------------------------
9318 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9319 R1 : constant Node_Id := Get_Referenced_Object (E1);
9320 R2 : constant Node_Id := Get_Referenced_Object (E2);
9322 return Is_Entity_Name (R1)
9323 and then Is_Entity_Name (R2)
9324 and then Entity (R1) /= Entity (R2)
9325 and then not Is_Formal (Entity (R1))
9326 and then not Is_Formal (Entity (R2));
9327 end Statically_Different;
9329 -----------------------------
9330 -- Subprogram_Access_Level --
9331 -----------------------------
9333 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9335 if Present (Alias (Subp)) then
9336 return Subprogram_Access_Level (Alias (Subp));
9338 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9340 end Subprogram_Access_Level;
9346 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9348 if Debug_Flag_W then
9349 for J in 0 .. Scope_Stack.Last loop
9354 Write_Name (Chars (E));
9355 Write_Str (" from ");
9356 Write_Location (Sloc (N));
9361 -----------------------
9362 -- Transfer_Entities --
9363 -----------------------
9365 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9366 Ent : Entity_Id := First_Entity (From);
9373 if (Last_Entity (To)) = Empty then
9374 Set_First_Entity (To, Ent);
9376 Set_Next_Entity (Last_Entity (To), Ent);
9379 Set_Last_Entity (To, Last_Entity (From));
9381 while Present (Ent) loop
9382 Set_Scope (Ent, To);
9384 if not Is_Public (Ent) then
9385 Set_Public_Status (Ent);
9388 and then Ekind (Ent) = E_Record_Subtype
9391 -- The components of the propagated Itype must be public
9397 Comp := First_Entity (Ent);
9398 while Present (Comp) loop
9399 Set_Is_Public (Comp);
9409 Set_First_Entity (From, Empty);
9410 Set_Last_Entity (From, Empty);
9411 end Transfer_Entities;
9413 -----------------------
9414 -- Type_Access_Level --
9415 -----------------------
9417 function Type_Access_Level (Typ : Entity_Id) return Uint is
9421 Btyp := Base_Type (Typ);
9423 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9424 -- simply use the level where the type is declared. This is true for
9425 -- stand-alone object declarations, and for anonymous access types
9426 -- associated with components the level is the same as that of the
9427 -- enclosing composite type. However, special treatment is needed for
9428 -- the cases of access parameters, return objects of an anonymous access
9429 -- type, and, in Ada 95, access discriminants of limited types.
9431 if Ekind (Btyp) in Access_Kind then
9432 if Ekind (Btyp) = E_Anonymous_Access_Type then
9434 -- If the type is a nonlocal anonymous access type (such as for
9435 -- an access parameter) we treat it as being declared at the
9436 -- library level to ensure that names such as X.all'access don't
9437 -- fail static accessibility checks.
9439 if not Is_Local_Anonymous_Access (Typ) then
9440 return Scope_Depth (Standard_Standard);
9442 -- If this is a return object, the accessibility level is that of
9443 -- the result subtype of the enclosing function. The test here is
9444 -- little complicated, because we have to account for extended
9445 -- return statements that have been rewritten as blocks, in which
9446 -- case we have to find and the Is_Return_Object attribute of the
9447 -- itype's associated object. It would be nice to find a way to
9448 -- simplify this test, but it doesn't seem worthwhile to add a new
9449 -- flag just for purposes of this test. ???
9451 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9454 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9455 N_Object_Declaration
9456 and then Is_Return_Object
9457 (Defining_Identifier
9458 (Associated_Node_For_Itype (Btyp))))
9464 Scop := Scope (Scope (Btyp));
9465 while Present (Scop) loop
9466 exit when Ekind (Scop) = E_Function;
9467 Scop := Scope (Scop);
9470 -- Treat the return object's type as having the level of the
9471 -- function's result subtype (as per RM05-6.5(5.3/2)).
9473 return Type_Access_Level (Etype (Scop));
9478 Btyp := Root_Type (Btyp);
9480 -- The accessibility level of anonymous access types associated with
9481 -- discriminants is that of the current instance of the type, and
9482 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9484 -- AI-402: access discriminants have accessibility based on the
9485 -- object rather than the type in Ada 2005, so the above paragraph
9488 -- ??? Needs completion with rules from AI-416
9490 if Ada_Version <= Ada_95
9491 and then Ekind (Typ) = E_Anonymous_Access_Type
9492 and then Present (Associated_Node_For_Itype (Typ))
9493 and then Nkind (Associated_Node_For_Itype (Typ)) =
9494 N_Discriminant_Specification
9496 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9500 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9501 end Type_Access_Level;
9503 --------------------
9504 -- Ultimate_Alias --
9505 --------------------
9506 -- To do: add occurrences calling this new subprogram
9508 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
9509 E : Entity_Id := Prim;
9512 while Present (Alias (E)) loop
9519 --------------------------
9520 -- Unit_Declaration_Node --
9521 --------------------------
9523 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9524 N : Node_Id := Parent (Unit_Id);
9527 -- Predefined operators do not have a full function declaration
9529 if Ekind (Unit_Id) = E_Operator then
9533 -- Isn't there some better way to express the following ???
9535 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9536 and then Nkind (N) /= N_Formal_Package_Declaration
9537 and then Nkind (N) /= N_Function_Instantiation
9538 and then Nkind (N) /= N_Generic_Package_Declaration
9539 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9540 and then Nkind (N) /= N_Package_Declaration
9541 and then Nkind (N) /= N_Package_Body
9542 and then Nkind (N) /= N_Package_Instantiation
9543 and then Nkind (N) /= N_Package_Renaming_Declaration
9544 and then Nkind (N) /= N_Procedure_Instantiation
9545 and then Nkind (N) /= N_Protected_Body
9546 and then Nkind (N) /= N_Subprogram_Declaration
9547 and then Nkind (N) /= N_Subprogram_Body
9548 and then Nkind (N) /= N_Subprogram_Body_Stub
9549 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9550 and then Nkind (N) /= N_Task_Body
9551 and then Nkind (N) /= N_Task_Type_Declaration
9552 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9553 and then Nkind (N) not in N_Generic_Renaming_Declaration
9556 pragma Assert (Present (N));
9560 end Unit_Declaration_Node;
9562 ------------------------------
9563 -- Universal_Interpretation --
9564 ------------------------------
9566 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9567 Index : Interp_Index;
9571 -- The argument may be a formal parameter of an operator or subprogram
9572 -- with multiple interpretations, or else an expression for an actual.
9574 if Nkind (Opnd) = N_Defining_Identifier
9575 or else not Is_Overloaded (Opnd)
9577 if Etype (Opnd) = Universal_Integer
9578 or else Etype (Opnd) = Universal_Real
9580 return Etype (Opnd);
9586 Get_First_Interp (Opnd, Index, It);
9587 while Present (It.Typ) loop
9588 if It.Typ = Universal_Integer
9589 or else It.Typ = Universal_Real
9594 Get_Next_Interp (Index, It);
9599 end Universal_Interpretation;
9605 function Unqualify (Expr : Node_Id) return Node_Id is
9607 -- Recurse to handle unlikely case of multiple levels of qualification
9609 if Nkind (Expr) = N_Qualified_Expression then
9610 return Unqualify (Expression (Expr));
9612 -- Normal case, not a qualified expression
9619 ----------------------
9620 -- Within_Init_Proc --
9621 ----------------------
9623 function Within_Init_Proc return Boolean is
9628 while not Is_Overloadable (S) loop
9629 if S = Standard_Standard then
9636 return Is_Init_Proc (S);
9637 end Within_Init_Proc;
9643 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9644 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9645 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9647 function Has_One_Matching_Field return Boolean;
9648 -- Determines if Expec_Type is a record type with a single component or
9649 -- discriminant whose type matches the found type or is one dimensional
9650 -- array whose component type matches the found type.
9652 ----------------------------
9653 -- Has_One_Matching_Field --
9654 ----------------------------
9656 function Has_One_Matching_Field return Boolean is
9660 if Is_Array_Type (Expec_Type)
9661 and then Number_Dimensions (Expec_Type) = 1
9663 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9667 elsif not Is_Record_Type (Expec_Type) then
9671 E := First_Entity (Expec_Type);
9676 elsif (Ekind (E) /= E_Discriminant
9677 and then Ekind (E) /= E_Component)
9678 or else (Chars (E) = Name_uTag
9679 or else Chars (E) = Name_uParent)
9688 if not Covers (Etype (E), Found_Type) then
9691 elsif Present (Next_Entity (E)) then
9698 end Has_One_Matching_Field;
9700 -- Start of processing for Wrong_Type
9703 -- Don't output message if either type is Any_Type, or if a message
9704 -- has already been posted for this node. We need to do the latter
9705 -- check explicitly (it is ordinarily done in Errout), because we
9706 -- are using ! to force the output of the error messages.
9708 if Expec_Type = Any_Type
9709 or else Found_Type = Any_Type
9710 or else Error_Posted (Expr)
9714 -- In an instance, there is an ongoing problem with completion of
9715 -- type derived from private types. Their structure is what Gigi
9716 -- expects, but the Etype is the parent type rather than the
9717 -- derived private type itself. Do not flag error in this case. The
9718 -- private completion is an entity without a parent, like an Itype.
9719 -- Similarly, full and partial views may be incorrect in the instance.
9720 -- There is no simple way to insure that it is consistent ???
9722 elsif In_Instance then
9723 if Etype (Etype (Expr)) = Etype (Expected_Type)
9725 (Has_Private_Declaration (Expected_Type)
9726 or else Has_Private_Declaration (Etype (Expr)))
9727 and then No (Parent (Expected_Type))
9733 -- An interesting special check. If the expression is parenthesized
9734 -- and its type corresponds to the type of the sole component of the
9735 -- expected record type, or to the component type of the expected one
9736 -- dimensional array type, then assume we have a bad aggregate attempt.
9738 if Nkind (Expr) in N_Subexpr
9739 and then Paren_Count (Expr) /= 0
9740 and then Has_One_Matching_Field
9742 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9744 -- Another special check, if we are looking for a pool-specific access
9745 -- type and we found an E_Access_Attribute_Type, then we have the case
9746 -- of an Access attribute being used in a context which needs a pool-
9747 -- specific type, which is never allowed. The one extra check we make
9748 -- is that the expected designated type covers the Found_Type.
9750 elsif Is_Access_Type (Expec_Type)
9751 and then Ekind (Found_Type) = E_Access_Attribute_Type
9752 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9753 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9755 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9757 Error_Msg_N ("result must be general access type!", Expr);
9758 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9760 -- Another special check, if the expected type is an integer type,
9761 -- but the expression is of type System.Address, and the parent is
9762 -- an addition or subtraction operation whose left operand is the
9763 -- expression in question and whose right operand is of an integral
9764 -- type, then this is an attempt at address arithmetic, so give
9765 -- appropriate message.
9767 elsif Is_Integer_Type (Expec_Type)
9768 and then Is_RTE (Found_Type, RE_Address)
9769 and then (Nkind (Parent (Expr)) = N_Op_Add
9771 Nkind (Parent (Expr)) = N_Op_Subtract)
9772 and then Expr = Left_Opnd (Parent (Expr))
9773 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9776 ("address arithmetic not predefined in package System",
9779 ("\possible missing with/use of System.Storage_Elements",
9783 -- If the expected type is an anonymous access type, as for access
9784 -- parameters and discriminants, the error is on the designated types.
9786 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9787 if Comes_From_Source (Expec_Type) then
9788 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9791 ("expected an access type with designated}",
9792 Expr, Designated_Type (Expec_Type));
9795 if Is_Access_Type (Found_Type)
9796 and then not Comes_From_Source (Found_Type)
9799 ("\\found an access type with designated}!",
9800 Expr, Designated_Type (Found_Type));
9802 if From_With_Type (Found_Type) then
9803 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9804 Error_Msg_Qual_Level := 99;
9805 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9806 Error_Msg_Qual_Level := 0;
9808 Error_Msg_NE ("found}!", Expr, Found_Type);
9812 -- Normal case of one type found, some other type expected
9815 -- If the names of the two types are the same, see if some number
9816 -- of levels of qualification will help. Don't try more than three
9817 -- levels, and if we get to standard, it's no use (and probably
9818 -- represents an error in the compiler) Also do not bother with
9819 -- internal scope names.
9822 Expec_Scope : Entity_Id;
9823 Found_Scope : Entity_Id;
9826 Expec_Scope := Expec_Type;
9827 Found_Scope := Found_Type;
9829 for Levels in Int range 0 .. 3 loop
9830 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9831 Error_Msg_Qual_Level := Levels;
9835 Expec_Scope := Scope (Expec_Scope);
9836 Found_Scope := Scope (Found_Scope);
9838 exit when Expec_Scope = Standard_Standard
9839 or else Found_Scope = Standard_Standard
9840 or else not Comes_From_Source (Expec_Scope)
9841 or else not Comes_From_Source (Found_Scope);
9845 if Is_Record_Type (Expec_Type)
9846 and then Present (Corresponding_Remote_Type (Expec_Type))
9848 Error_Msg_NE ("expected}!", Expr,
9849 Corresponding_Remote_Type (Expec_Type));
9851 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9854 if Is_Entity_Name (Expr)
9855 and then Is_Package_Or_Generic_Package (Entity (Expr))
9857 Error_Msg_N ("\\found package name!", Expr);
9859 elsif Is_Entity_Name (Expr)
9861 (Ekind (Entity (Expr)) = E_Procedure
9863 Ekind (Entity (Expr)) = E_Generic_Procedure)
9865 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9867 ("found procedure name, possibly missing Access attribute!",
9871 ("\\found procedure name instead of function!", Expr);
9874 elsif Nkind (Expr) = N_Function_Call
9875 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9876 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9877 and then No (Parameter_Associations (Expr))
9880 ("found function name, possibly missing Access attribute!",
9883 -- Catch common error: a prefix or infix operator which is not
9884 -- directly visible because the type isn't.
9886 elsif Nkind (Expr) in N_Op
9887 and then Is_Overloaded (Expr)
9888 and then not Is_Immediately_Visible (Expec_Type)
9889 and then not Is_Potentially_Use_Visible (Expec_Type)
9890 and then not In_Use (Expec_Type)
9891 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9894 ("operator of the type is not directly visible!", Expr);
9896 elsif Ekind (Found_Type) = E_Void
9897 and then Present (Parent (Found_Type))
9898 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9900 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9903 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9906 Error_Msg_Qual_Level := 0;