1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Errout; use Errout;
32 with Elists; use Elists;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rtsfind; use Rtsfind;
46 with Scans; use Scans;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Type; use Sem_Type;
53 with Sinfo; use Sinfo;
54 with Sinput; use Sinput;
55 with Snames; use Snames;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
59 with Targparm; use Targparm;
60 with Tbuild; use Tbuild;
61 with Ttypes; use Ttypes;
63 package body Sem_Util is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 function Build_Component_Subtype
72 T : Entity_Id) return Node_Id;
73 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
74 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
75 -- Loc is the source location, T is the original subtype.
77 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
78 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
79 -- with discriminants whose default values are static, examine only the
80 -- components in the selected variant to determine whether all of them
83 function Has_Null_Extension (T : Entity_Id) return Boolean;
84 -- T is a derived tagged type. Check whether the type extension is null.
85 -- If the parent type is fully initialized, T can be treated as such.
87 --------------------------------
88 -- Add_Access_Type_To_Process --
89 --------------------------------
91 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
95 Ensure_Freeze_Node (E);
96 L := Access_Types_To_Process (Freeze_Node (E));
100 Set_Access_Types_To_Process (Freeze_Node (E), L);
104 end Add_Access_Type_To_Process;
106 -----------------------
107 -- Alignment_In_Bits --
108 -----------------------
110 function Alignment_In_Bits (E : Entity_Id) return Uint is
112 return Alignment (E) * System_Storage_Unit;
113 end Alignment_In_Bits;
115 -----------------------------------------
116 -- Apply_Compile_Time_Constraint_Error --
117 -----------------------------------------
119 procedure Apply_Compile_Time_Constraint_Error
122 Reason : RT_Exception_Code;
123 Ent : Entity_Id := Empty;
124 Typ : Entity_Id := Empty;
125 Loc : Source_Ptr := No_Location;
126 Rep : Boolean := True;
127 Warn : Boolean := False)
129 Stat : constant Boolean := Is_Static_Expression (N);
140 Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
146 -- Now we replace the node by an N_Raise_Constraint_Error node
147 -- This does not need reanalyzing, so set it as analyzed now.
150 Make_Raise_Constraint_Error (Sloc (N),
152 Set_Analyzed (N, True);
154 Set_Raises_Constraint_Error (N);
156 -- If the original expression was marked as static, the result is
157 -- still marked as static, but the Raises_Constraint_Error flag is
158 -- always set so that further static evaluation is not attempted.
161 Set_Is_Static_Expression (N);
163 end Apply_Compile_Time_Constraint_Error;
165 --------------------------
166 -- Build_Actual_Subtype --
167 --------------------------
169 function Build_Actual_Subtype
171 N : Node_Or_Entity_Id) return Node_Id
175 Loc : constant Source_Ptr := Sloc (N);
176 Constraints : List_Id;
182 Disc_Type : Entity_Id;
185 if Nkind (N) = N_Defining_Identifier then
186 Obj := New_Reference_To (N, Loc);
191 if Is_Array_Type (T) then
192 Constraints := New_List;
194 for J in 1 .. Number_Dimensions (T) loop
196 -- Build an array subtype declaration with the nominal
197 -- subtype and the bounds of the actual. Add the declaration
198 -- in front of the local declarations for the subprogram, for
199 -- analysis before any reference to the formal in the body.
202 Make_Attribute_Reference (Loc,
204 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
205 Attribute_Name => Name_First,
206 Expressions => New_List (
207 Make_Integer_Literal (Loc, J)));
210 Make_Attribute_Reference (Loc,
212 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
213 Attribute_Name => Name_Last,
214 Expressions => New_List (
215 Make_Integer_Literal (Loc, J)));
217 Append (Make_Range (Loc, Lo, Hi), Constraints);
220 -- If the type has unknown discriminants there is no constrained
221 -- subtype to build. This is never called for a formal or for a
222 -- lhs, so returning the type is ok ???
224 elsif Has_Unknown_Discriminants (T) then
228 Constraints := New_List;
230 if Is_Private_Type (T) and then No (Full_View (T)) then
232 -- Type is a generic derived type. Inherit discriminants from
235 Disc_Type := Etype (Base_Type (T));
240 Discr := First_Discriminant (Disc_Type);
242 while Present (Discr) loop
243 Append_To (Constraints,
244 Make_Selected_Component (Loc,
246 Duplicate_Subexpr_No_Checks (Obj),
247 Selector_Name => New_Occurrence_Of (Discr, Loc)));
248 Next_Discriminant (Discr);
253 Make_Defining_Identifier (Loc,
254 Chars => New_Internal_Name ('S'));
255 Set_Is_Internal (Subt);
258 Make_Subtype_Declaration (Loc,
259 Defining_Identifier => Subt,
260 Subtype_Indication =>
261 Make_Subtype_Indication (Loc,
262 Subtype_Mark => New_Reference_To (T, Loc),
264 Make_Index_Or_Discriminant_Constraint (Loc,
265 Constraints => Constraints)));
267 Mark_Rewrite_Insertion (Decl);
269 end Build_Actual_Subtype;
271 ---------------------------------------
272 -- Build_Actual_Subtype_Of_Component --
273 ---------------------------------------
275 function Build_Actual_Subtype_Of_Component
277 N : Node_Id) return Node_Id
279 Loc : constant Source_Ptr := Sloc (N);
280 P : constant Node_Id := Prefix (N);
283 Indx_Type : Entity_Id;
285 Deaccessed_T : Entity_Id;
286 -- This is either a copy of T, or if T is an access type, then it is
287 -- the directly designated type of this access type.
289 function Build_Actual_Array_Constraint return List_Id;
290 -- If one or more of the bounds of the component depends on
291 -- discriminants, build actual constraint using the discriminants
294 function Build_Actual_Record_Constraint return List_Id;
295 -- Similar to previous one, for discriminated components constrained
296 -- by the discriminant of the enclosing object.
298 -----------------------------------
299 -- Build_Actual_Array_Constraint --
300 -----------------------------------
302 function Build_Actual_Array_Constraint return List_Id is
303 Constraints : constant List_Id := New_List;
311 Indx := First_Index (Deaccessed_T);
312 while Present (Indx) loop
313 Old_Lo := Type_Low_Bound (Etype (Indx));
314 Old_Hi := Type_High_Bound (Etype (Indx));
316 if Denotes_Discriminant (Old_Lo) then
318 Make_Selected_Component (Loc,
319 Prefix => New_Copy_Tree (P),
320 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
323 Lo := New_Copy_Tree (Old_Lo);
325 -- The new bound will be reanalyzed in the enclosing
326 -- declaration. For literal bounds that come from a type
327 -- declaration, the type of the context must be imposed, so
328 -- insure that analysis will take place. For non-universal
329 -- types this is not strictly necessary.
331 Set_Analyzed (Lo, False);
334 if Denotes_Discriminant (Old_Hi) then
336 Make_Selected_Component (Loc,
337 Prefix => New_Copy_Tree (P),
338 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
341 Hi := New_Copy_Tree (Old_Hi);
342 Set_Analyzed (Hi, False);
345 Append (Make_Range (Loc, Lo, Hi), Constraints);
350 end Build_Actual_Array_Constraint;
352 ------------------------------------
353 -- Build_Actual_Record_Constraint --
354 ------------------------------------
356 function Build_Actual_Record_Constraint return List_Id is
357 Constraints : constant List_Id := New_List;
362 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
363 while Present (D) loop
365 if Denotes_Discriminant (Node (D)) then
366 D_Val := Make_Selected_Component (Loc,
367 Prefix => New_Copy_Tree (P),
368 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
371 D_Val := New_Copy_Tree (Node (D));
374 Append (D_Val, Constraints);
379 end Build_Actual_Record_Constraint;
381 -- Start of processing for Build_Actual_Subtype_Of_Component
384 if In_Default_Expression then
387 elsif Nkind (N) = N_Explicit_Dereference then
388 if Is_Composite_Type (T)
389 and then not Is_Constrained (T)
390 and then not (Is_Class_Wide_Type (T)
391 and then Is_Constrained (Root_Type (T)))
392 and then not Has_Unknown_Discriminants (T)
394 -- If the type of the dereference is already constrained, it
395 -- is an actual subtype.
397 if Is_Array_Type (Etype (N))
398 and then Is_Constrained (Etype (N))
402 Remove_Side_Effects (P);
403 return Build_Actual_Subtype (T, N);
410 if Ekind (T) = E_Access_Subtype then
411 Deaccessed_T := Designated_Type (T);
416 if Ekind (Deaccessed_T) = E_Array_Subtype then
417 Id := First_Index (Deaccessed_T);
418 Indx_Type := Underlying_Type (Etype (Id));
420 while Present (Id) loop
422 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
423 Denotes_Discriminant (Type_High_Bound (Indx_Type))
425 Remove_Side_Effects (P);
427 Build_Component_Subtype (
428 Build_Actual_Array_Constraint, Loc, Base_Type (T));
434 elsif Is_Composite_Type (Deaccessed_T)
435 and then Has_Discriminants (Deaccessed_T)
436 and then not Has_Unknown_Discriminants (Deaccessed_T)
438 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
439 while Present (D) loop
441 if Denotes_Discriminant (Node (D)) then
442 Remove_Side_Effects (P);
444 Build_Component_Subtype (
445 Build_Actual_Record_Constraint, Loc, Base_Type (T));
452 -- If none of the above, the actual and nominal subtypes are the same.
455 end Build_Actual_Subtype_Of_Component;
457 -----------------------------
458 -- Build_Component_Subtype --
459 -----------------------------
461 function Build_Component_Subtype
464 T : Entity_Id) return Node_Id
471 Make_Defining_Identifier (Loc,
472 Chars => New_Internal_Name ('S'));
473 Set_Is_Internal (Subt);
476 Make_Subtype_Declaration (Loc,
477 Defining_Identifier => Subt,
478 Subtype_Indication =>
479 Make_Subtype_Indication (Loc,
480 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
482 Make_Index_Or_Discriminant_Constraint (Loc,
485 Mark_Rewrite_Insertion (Decl);
487 end Build_Component_Subtype;
489 --------------------------------------------
490 -- Build_Discriminal_Subtype_Of_Component --
491 --------------------------------------------
493 function Build_Discriminal_Subtype_Of_Component
494 (T : Entity_Id) return Node_Id
496 Loc : constant Source_Ptr := Sloc (T);
500 function Build_Discriminal_Array_Constraint return List_Id;
501 -- If one or more of the bounds of the component depends on
502 -- discriminants, build actual constraint using the discriminants
505 function Build_Discriminal_Record_Constraint return List_Id;
506 -- Similar to previous one, for discriminated components constrained
507 -- by the discriminant of the enclosing object.
509 ----------------------------------------
510 -- Build_Discriminal_Array_Constraint --
511 ----------------------------------------
513 function Build_Discriminal_Array_Constraint return List_Id is
514 Constraints : constant List_Id := New_List;
522 Indx := First_Index (T);
523 while Present (Indx) loop
524 Old_Lo := Type_Low_Bound (Etype (Indx));
525 Old_Hi := Type_High_Bound (Etype (Indx));
527 if Denotes_Discriminant (Old_Lo) then
528 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
531 Lo := New_Copy_Tree (Old_Lo);
534 if Denotes_Discriminant (Old_Hi) then
535 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
538 Hi := New_Copy_Tree (Old_Hi);
541 Append (Make_Range (Loc, Lo, Hi), Constraints);
546 end Build_Discriminal_Array_Constraint;
548 -----------------------------------------
549 -- Build_Discriminal_Record_Constraint --
550 -----------------------------------------
552 function Build_Discriminal_Record_Constraint return List_Id is
553 Constraints : constant List_Id := New_List;
558 D := First_Elmt (Discriminant_Constraint (T));
559 while Present (D) loop
560 if Denotes_Discriminant (Node (D)) then
562 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
565 D_Val := New_Copy_Tree (Node (D));
568 Append (D_Val, Constraints);
573 end Build_Discriminal_Record_Constraint;
575 -- Start of processing for Build_Discriminal_Subtype_Of_Component
578 if Ekind (T) = E_Array_Subtype then
579 Id := First_Index (T);
581 while Present (Id) loop
582 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
583 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
585 return Build_Component_Subtype
586 (Build_Discriminal_Array_Constraint, Loc, T);
592 elsif Ekind (T) = E_Record_Subtype
593 and then Has_Discriminants (T)
594 and then not Has_Unknown_Discriminants (T)
596 D := First_Elmt (Discriminant_Constraint (T));
597 while Present (D) loop
598 if Denotes_Discriminant (Node (D)) then
599 return Build_Component_Subtype
600 (Build_Discriminal_Record_Constraint, Loc, T);
607 -- If none of the above, the actual and nominal subtypes are the same.
610 end Build_Discriminal_Subtype_Of_Component;
612 ------------------------------
613 -- Build_Elaboration_Entity --
614 ------------------------------
616 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
617 Loc : constant Source_Ptr := Sloc (N);
618 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
621 Elab_Ent : Entity_Id;
624 -- Ignore if already constructed
626 if Present (Elaboration_Entity (Spec_Id)) then
630 -- Construct name of elaboration entity as xxx_E, where xxx
631 -- is the unit name with dots replaced by double underscore.
632 -- We have to manually construct this name, since it will
633 -- be elaborated in the outer scope, and thus will not have
634 -- the unit name automatically prepended.
636 Get_Name_String (Unit_Name (Unum));
638 -- Replace the %s by _E
640 Name_Buffer (Name_Len - 1 .. Name_Len) := "_E";
642 -- Replace dots by double underscore
645 while P < Name_Len - 2 loop
646 if Name_Buffer (P) = '.' then
647 Name_Buffer (P + 2 .. Name_Len + 1) :=
648 Name_Buffer (P + 1 .. Name_Len);
649 Name_Len := Name_Len + 1;
650 Name_Buffer (P) := '_';
651 Name_Buffer (P + 1) := '_';
658 -- Create elaboration flag
661 Make_Defining_Identifier (Loc, Chars => Name_Find);
662 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
664 if No (Declarations (Aux_Decls_Node (N))) then
665 Set_Declarations (Aux_Decls_Node (N), New_List);
669 Make_Object_Declaration (Loc,
670 Defining_Identifier => Elab_Ent,
672 New_Occurrence_Of (Standard_Boolean, Loc),
674 New_Occurrence_Of (Standard_False, Loc));
676 Append_To (Declarations (Aux_Decls_Node (N)), Decl);
679 -- Reset True_Constant indication, since we will indeed
680 -- assign a value to the variable in the binder main.
682 Set_Is_True_Constant (Elab_Ent, False);
683 Set_Current_Value (Elab_Ent, Empty);
685 -- We do not want any further qualification of the name (if we did
686 -- not do this, we would pick up the name of the generic package
687 -- in the case of a library level generic instantiation).
689 Set_Has_Qualified_Name (Elab_Ent);
690 Set_Has_Fully_Qualified_Name (Elab_Ent);
691 end Build_Elaboration_Entity;
693 -----------------------------------
694 -- Cannot_Raise_Constraint_Error --
695 -----------------------------------
697 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
699 if Compile_Time_Known_Value (Expr) then
702 elsif Do_Range_Check (Expr) then
705 elsif Raises_Constraint_Error (Expr) then
713 when N_Expanded_Name =>
716 when N_Selected_Component =>
717 return not Do_Discriminant_Check (Expr);
719 when N_Attribute_Reference =>
720 if Do_Overflow_Check (Expr) then
723 elsif No (Expressions (Expr)) then
728 N : Node_Id := First (Expressions (Expr));
731 while Present (N) loop
732 if Cannot_Raise_Constraint_Error (N) then
743 when N_Type_Conversion =>
744 if Do_Overflow_Check (Expr)
745 or else Do_Length_Check (Expr)
746 or else Do_Tag_Check (Expr)
751 Cannot_Raise_Constraint_Error (Expression (Expr));
754 when N_Unchecked_Type_Conversion =>
755 return Cannot_Raise_Constraint_Error (Expression (Expr));
758 if Do_Overflow_Check (Expr) then
762 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
769 if Do_Division_Check (Expr)
770 or else Do_Overflow_Check (Expr)
775 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
777 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
796 N_Op_Shift_Right_Arithmetic |
800 if Do_Overflow_Check (Expr) then
804 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
806 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
813 end Cannot_Raise_Constraint_Error;
815 --------------------------
816 -- Check_Fully_Declared --
817 --------------------------
819 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
821 if Ekind (T) = E_Incomplete_Type then
823 -- Ada 2005 (AI-50217): If the type is available through a limited
824 -- with_clause, verify that its full view has been analyzed.
826 if From_With_Type (T)
827 and then Present (Non_Limited_View (T))
828 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
830 -- The non-limited view is fully declared
835 ("premature usage of incomplete}", N, First_Subtype (T));
838 elsif Has_Private_Component (T)
839 and then not Is_Generic_Type (Root_Type (T))
840 and then not In_Default_Expression
843 -- Special case: if T is the anonymous type created for a single
844 -- task or protected object, use the name of the source object.
846 if Is_Concurrent_Type (T)
847 and then not Comes_From_Source (T)
848 and then Nkind (N) = N_Object_Declaration
850 Error_Msg_NE ("type of& has incomplete component", N,
851 Defining_Identifier (N));
855 ("premature usage of incomplete}", N, First_Subtype (T));
858 end Check_Fully_Declared;
860 ------------------------------------------
861 -- Check_Potentially_Blocking_Operation --
862 ------------------------------------------
864 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
866 Loc : constant Source_Ptr := Sloc (N);
869 -- N is one of the potentially blocking operations listed in
870 -- 9.5.1 (8). When using the Ravenscar profile, raise Program_Error
871 -- before N if the context is a protected action. Otherwise, only issue
872 -- a warning, since some users are relying on blocking operations
873 -- inside protected objects.
874 -- Indirect blocking through a subprogram call
875 -- cannot be diagnosed statically without interprocedural analysis,
876 -- so we do not attempt to do it here.
878 S := Scope (Current_Scope);
880 while Present (S) and then S /= Standard_Standard loop
881 if Is_Protected_Type (S) then
882 if Restricted_Profile then
883 Insert_Before_And_Analyze (N,
884 Make_Raise_Program_Error (Loc,
885 Reason => PE_Potentially_Blocking_Operation));
886 Error_Msg_N ("potentially blocking operation, " &
887 " Program Error will be raised at run time?", N);
891 ("potentially blocking operation in protected operation?", N);
899 end Check_Potentially_Blocking_Operation;
905 procedure Check_VMS (Construct : Node_Id) is
907 if not OpenVMS_On_Target then
909 ("this construct is allowed only in Open'V'M'S", Construct);
913 ----------------------------------
914 -- Collect_Primitive_Operations --
915 ----------------------------------
917 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
918 B_Type : constant Entity_Id := Base_Type (T);
919 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
920 B_Scope : Entity_Id := Scope (B_Type);
924 Formal_Derived : Boolean := False;
928 -- For tagged types, the primitive operations are collected as they
929 -- are declared, and held in an explicit list which is simply returned.
931 if Is_Tagged_Type (B_Type) then
932 return Primitive_Operations (B_Type);
934 -- An untagged generic type that is a derived type inherits the
935 -- primitive operations of its parent type. Other formal types only
936 -- have predefined operators, which are not explicitly represented.
938 elsif Is_Generic_Type (B_Type) then
939 if Nkind (B_Decl) = N_Formal_Type_Declaration
940 and then Nkind (Formal_Type_Definition (B_Decl))
941 = N_Formal_Derived_Type_Definition
943 Formal_Derived := True;
945 return New_Elmt_List;
949 Op_List := New_Elmt_List;
951 if B_Scope = Standard_Standard then
952 if B_Type = Standard_String then
953 Append_Elmt (Standard_Op_Concat, Op_List);
955 elsif B_Type = Standard_Wide_String then
956 Append_Elmt (Standard_Op_Concatw, Op_List);
962 elsif (Is_Package (B_Scope)
964 Parent (Declaration_Node (First_Subtype (T))))
967 or else Is_Derived_Type (B_Type)
969 -- The primitive operations appear after the base type, except
970 -- if the derivation happens within the private part of B_Scope
971 -- and the type is a private type, in which case both the type
972 -- and some primitive operations may appear before the base
973 -- type, and the list of candidates starts after the type.
975 if In_Open_Scopes (B_Scope)
976 and then Scope (T) = B_Scope
977 and then In_Private_Part (B_Scope)
979 Id := Next_Entity (T);
981 Id := Next_Entity (B_Type);
984 while Present (Id) loop
986 -- Note that generic formal subprograms are not
987 -- considered to be primitive operations and thus
988 -- are never inherited.
990 if Is_Overloadable (Id)
991 and then Nkind (Parent (Parent (Id)))
992 /= N_Formal_Subprogram_Declaration
996 if Base_Type (Etype (Id)) = B_Type then
999 Formal := First_Formal (Id);
1000 while Present (Formal) loop
1001 if Base_Type (Etype (Formal)) = B_Type then
1005 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1007 (Designated_Type (Etype (Formal))) = B_Type
1013 Next_Formal (Formal);
1017 -- For a formal derived type, the only primitives are the
1018 -- ones inherited from the parent type. Operations appearing
1019 -- in the package declaration are not primitive for it.
1022 and then (not Formal_Derived
1023 or else Present (Alias (Id)))
1025 Append_Elmt (Id, Op_List);
1031 -- For a type declared in System, some of its operations
1032 -- may appear in the target-specific extension to System.
1035 and then Chars (B_Scope) = Name_System
1036 and then Scope (B_Scope) = Standard_Standard
1037 and then Present_System_Aux
1039 B_Scope := System_Aux_Id;
1040 Id := First_Entity (System_Aux_Id);
1046 end Collect_Primitive_Operations;
1048 -----------------------------------
1049 -- Compile_Time_Constraint_Error --
1050 -----------------------------------
1052 function Compile_Time_Constraint_Error
1055 Ent : Entity_Id := Empty;
1056 Loc : Source_Ptr := No_Location;
1057 Warn : Boolean := False) return Node_Id
1059 Msgc : String (1 .. Msg'Length + 2);
1067 -- A static constraint error in an instance body is not a fatal error.
1068 -- we choose to inhibit the message altogether, because there is no
1069 -- obvious node (for now) on which to post it. On the other hand the
1070 -- offending node must be replaced with a constraint_error in any case.
1072 -- No messages are generated if we already posted an error on this node
1074 if not Error_Posted (N) then
1075 if Loc /= No_Location then
1081 -- Make all such messages unconditional
1083 Msgc (1 .. Msg'Length) := Msg;
1084 Msgc (Msg'Length + 1) := '!';
1085 Msgl := Msg'Length + 1;
1087 -- Message is a warning, even in Ada 95 case
1089 if Msg (Msg'Length) = '?' then
1092 -- In Ada 83, all messages are warnings. In the private part and
1093 -- the body of an instance, constraint_checks are only warnings.
1094 -- We also make this a warning if the Warn parameter is set.
1097 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1103 elsif In_Instance_Not_Visible then
1108 -- Otherwise we have a real error message (Ada 95 static case)
1114 -- Should we generate a warning? The answer is not quite yes. The
1115 -- very annoying exception occurs in the case of a short circuit
1116 -- operator where the left operand is static and decisive. Climb
1117 -- parents to see if that is the case we have here.
1125 if (Nkind (P) = N_And_Then
1126 and then Compile_Time_Known_Value (Left_Opnd (P))
1127 and then Is_False (Expr_Value (Left_Opnd (P))))
1128 or else (Nkind (P) = N_Or_Else
1129 and then Compile_Time_Known_Value (Left_Opnd (P))
1130 and then Is_True (Expr_Value (Left_Opnd (P))))
1135 elsif Nkind (P) = N_Component_Association
1136 and then Nkind (Parent (P)) = N_Aggregate
1138 null; -- Keep going.
1141 exit when Nkind (P) not in N_Subexpr;
1146 if Present (Ent) then
1147 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1149 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1153 if Inside_Init_Proc then
1155 ("\& will be raised for objects of this type!?",
1156 N, Standard_Constraint_Error, Eloc);
1159 ("\& will be raised at run time!?",
1160 N, Standard_Constraint_Error, Eloc);
1164 ("\static expression raises&!",
1165 N, Standard_Constraint_Error, Eloc);
1171 end Compile_Time_Constraint_Error;
1173 -----------------------
1174 -- Conditional_Delay --
1175 -----------------------
1177 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1179 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1180 Set_Has_Delayed_Freeze (New_Ent);
1182 end Conditional_Delay;
1184 --------------------
1185 -- Current_Entity --
1186 --------------------
1188 -- The currently visible definition for a given identifier is the
1189 -- one most chained at the start of the visibility chain, i.e. the
1190 -- one that is referenced by the Node_Id value of the name of the
1191 -- given identifier.
1193 function Current_Entity (N : Node_Id) return Entity_Id is
1195 return Get_Name_Entity_Id (Chars (N));
1198 -----------------------------
1199 -- Current_Entity_In_Scope --
1200 -----------------------------
1202 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1204 CS : constant Entity_Id := Current_Scope;
1206 Transient_Case : constant Boolean := Scope_Is_Transient;
1209 E := Get_Name_Entity_Id (Chars (N));
1212 and then Scope (E) /= CS
1213 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1219 end Current_Entity_In_Scope;
1225 function Current_Scope return Entity_Id is
1227 if Scope_Stack.Last = -1 then
1228 return Standard_Standard;
1231 C : constant Entity_Id :=
1232 Scope_Stack.Table (Scope_Stack.Last).Entity;
1237 return Standard_Standard;
1243 ------------------------
1244 -- Current_Subprogram --
1245 ------------------------
1247 function Current_Subprogram return Entity_Id is
1248 Scop : constant Entity_Id := Current_Scope;
1251 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1254 return Enclosing_Subprogram (Scop);
1256 end Current_Subprogram;
1258 ---------------------
1259 -- Defining_Entity --
1260 ---------------------
1262 function Defining_Entity (N : Node_Id) return Entity_Id is
1263 K : constant Node_Kind := Nkind (N);
1264 Err : Entity_Id := Empty;
1269 N_Subprogram_Declaration |
1270 N_Abstract_Subprogram_Declaration |
1272 N_Package_Declaration |
1273 N_Subprogram_Renaming_Declaration |
1274 N_Subprogram_Body_Stub |
1275 N_Generic_Subprogram_Declaration |
1276 N_Generic_Package_Declaration |
1277 N_Formal_Subprogram_Declaration
1279 return Defining_Entity (Specification (N));
1282 N_Component_Declaration |
1283 N_Defining_Program_Unit_Name |
1284 N_Discriminant_Specification |
1286 N_Entry_Declaration |
1287 N_Entry_Index_Specification |
1288 N_Exception_Declaration |
1289 N_Exception_Renaming_Declaration |
1290 N_Formal_Object_Declaration |
1291 N_Formal_Package_Declaration |
1292 N_Formal_Type_Declaration |
1293 N_Full_Type_Declaration |
1294 N_Implicit_Label_Declaration |
1295 N_Incomplete_Type_Declaration |
1296 N_Loop_Parameter_Specification |
1297 N_Number_Declaration |
1298 N_Object_Declaration |
1299 N_Object_Renaming_Declaration |
1300 N_Package_Body_Stub |
1301 N_Parameter_Specification |
1302 N_Private_Extension_Declaration |
1303 N_Private_Type_Declaration |
1305 N_Protected_Body_Stub |
1306 N_Protected_Type_Declaration |
1307 N_Single_Protected_Declaration |
1308 N_Single_Task_Declaration |
1309 N_Subtype_Declaration |
1312 N_Task_Type_Declaration
1314 return Defining_Identifier (N);
1317 return Defining_Entity (Proper_Body (N));
1320 N_Function_Instantiation |
1321 N_Function_Specification |
1322 N_Generic_Function_Renaming_Declaration |
1323 N_Generic_Package_Renaming_Declaration |
1324 N_Generic_Procedure_Renaming_Declaration |
1326 N_Package_Instantiation |
1327 N_Package_Renaming_Declaration |
1328 N_Package_Specification |
1329 N_Procedure_Instantiation |
1330 N_Procedure_Specification
1333 Nam : constant Node_Id := Defining_Unit_Name (N);
1336 if Nkind (Nam) in N_Entity then
1339 -- For Error, make up a name and attach to declaration
1340 -- so we can continue semantic analysis
1342 elsif Nam = Error then
1344 Make_Defining_Identifier (Sloc (N),
1345 Chars => New_Internal_Name ('T'));
1346 Set_Defining_Unit_Name (N, Err);
1349 -- If not an entity, get defining identifier
1352 return Defining_Identifier (Nam);
1356 when N_Block_Statement =>
1357 return Entity (Identifier (N));
1360 raise Program_Error;
1363 end Defining_Entity;
1365 --------------------------
1366 -- Denotes_Discriminant --
1367 --------------------------
1369 function Denotes_Discriminant
1371 Check_Protected : Boolean := False) return Boolean
1375 if not Is_Entity_Name (N)
1376 or else No (Entity (N))
1383 -- If we are checking for a protected type, the discriminant may have
1384 -- been rewritten as the corresponding discriminal of the original type
1385 -- or of the corresponding concurrent record, depending on whether we
1386 -- are in the spec or body of the protected type.
1388 return Ekind (E) = E_Discriminant
1391 and then Ekind (E) = E_In_Parameter
1392 and then Present (Discriminal_Link (E))
1394 (Is_Protected_Type (Scope (Discriminal_Link (E)))
1396 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1398 end Denotes_Discriminant;
1400 -----------------------------
1401 -- Depends_On_Discriminant --
1402 -----------------------------
1404 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1409 Get_Index_Bounds (N, L, H);
1410 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1411 end Depends_On_Discriminant;
1413 -------------------------
1414 -- Designate_Same_Unit --
1415 -------------------------
1417 function Designate_Same_Unit
1419 Name2 : Node_Id) return Boolean
1421 K1 : constant Node_Kind := Nkind (Name1);
1422 K2 : constant Node_Kind := Nkind (Name2);
1424 function Prefix_Node (N : Node_Id) return Node_Id;
1425 -- Returns the parent unit name node of a defining program unit name
1426 -- or the prefix if N is a selected component or an expanded name.
1428 function Select_Node (N : Node_Id) return Node_Id;
1429 -- Returns the defining identifier node of a defining program unit
1430 -- name or the selector node if N is a selected component or an
1437 function Prefix_Node (N : Node_Id) return Node_Id is
1439 if Nkind (N) = N_Defining_Program_Unit_Name then
1451 function Select_Node (N : Node_Id) return Node_Id is
1453 if Nkind (N) = N_Defining_Program_Unit_Name then
1454 return Defining_Identifier (N);
1457 return Selector_Name (N);
1461 -- Start of processing for Designate_Next_Unit
1464 if (K1 = N_Identifier or else
1465 K1 = N_Defining_Identifier)
1467 (K2 = N_Identifier or else
1468 K2 = N_Defining_Identifier)
1470 return Chars (Name1) = Chars (Name2);
1473 (K1 = N_Expanded_Name or else
1474 K1 = N_Selected_Component or else
1475 K1 = N_Defining_Program_Unit_Name)
1477 (K2 = N_Expanded_Name or else
1478 K2 = N_Selected_Component or else
1479 K2 = N_Defining_Program_Unit_Name)
1482 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
1484 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
1489 end Designate_Same_Unit;
1491 ----------------------------
1492 -- Enclosing_Generic_Body --
1493 ----------------------------
1495 function Enclosing_Generic_Body
1496 (E : Entity_Id) return Node_Id
1505 while Present (P) loop
1506 if Nkind (P) = N_Package_Body
1507 or else Nkind (P) = N_Subprogram_Body
1509 Spec := Corresponding_Spec (P);
1511 if Present (Spec) then
1512 Decl := Unit_Declaration_Node (Spec);
1514 if Nkind (Decl) = N_Generic_Package_Declaration
1515 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1526 end Enclosing_Generic_Body;
1528 -------------------------------
1529 -- Enclosing_Lib_Unit_Entity --
1530 -------------------------------
1532 function Enclosing_Lib_Unit_Entity return Entity_Id is
1533 Unit_Entity : Entity_Id := Current_Scope;
1536 -- Look for enclosing library unit entity by following scope links.
1537 -- Equivalent to, but faster than indexing through the scope stack.
1539 while (Present (Scope (Unit_Entity))
1540 and then Scope (Unit_Entity) /= Standard_Standard)
1541 and not Is_Child_Unit (Unit_Entity)
1543 Unit_Entity := Scope (Unit_Entity);
1547 end Enclosing_Lib_Unit_Entity;
1549 -----------------------------
1550 -- Enclosing_Lib_Unit_Node --
1551 -----------------------------
1553 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
1554 Current_Node : Node_Id := N;
1557 while Present (Current_Node)
1558 and then Nkind (Current_Node) /= N_Compilation_Unit
1560 Current_Node := Parent (Current_Node);
1563 if Nkind (Current_Node) /= N_Compilation_Unit then
1567 return Current_Node;
1568 end Enclosing_Lib_Unit_Node;
1570 --------------------------
1571 -- Enclosing_Subprogram --
1572 --------------------------
1574 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
1575 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
1578 if Dynamic_Scope = Standard_Standard then
1581 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
1582 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
1584 elsif Ekind (Dynamic_Scope) = E_Block then
1585 return Enclosing_Subprogram (Dynamic_Scope);
1587 elsif Ekind (Dynamic_Scope) = E_Task_Type then
1588 return Get_Task_Body_Procedure (Dynamic_Scope);
1590 elsif Convention (Dynamic_Scope) = Convention_Protected then
1591 return Protected_Body_Subprogram (Dynamic_Scope);
1594 return Dynamic_Scope;
1596 end Enclosing_Subprogram;
1598 ------------------------
1599 -- Ensure_Freeze_Node --
1600 ------------------------
1602 procedure Ensure_Freeze_Node (E : Entity_Id) is
1606 if No (Freeze_Node (E)) then
1607 FN := Make_Freeze_Entity (Sloc (E));
1608 Set_Has_Delayed_Freeze (E);
1609 Set_Freeze_Node (E, FN);
1610 Set_Access_Types_To_Process (FN, No_Elist);
1611 Set_TSS_Elist (FN, No_Elist);
1614 end Ensure_Freeze_Node;
1620 procedure Enter_Name (Def_Id : Node_Id) is
1621 C : constant Entity_Id := Current_Entity (Def_Id);
1622 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
1623 S : constant Entity_Id := Current_Scope;
1626 Generate_Definition (Def_Id);
1628 -- Add new name to current scope declarations. Check for duplicate
1629 -- declaration, which may or may not be a genuine error.
1633 -- Case of previous entity entered because of a missing declaration
1634 -- or else a bad subtype indication. Best is to use the new entity,
1635 -- and make the previous one invisible.
1637 if Etype (E) = Any_Type then
1638 Set_Is_Immediately_Visible (E, False);
1640 -- Case of renaming declaration constructed for package instances.
1641 -- if there is an explicit declaration with the same identifier,
1642 -- the renaming is not immediately visible any longer, but remains
1643 -- visible through selected component notation.
1645 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
1646 and then not Comes_From_Source (E)
1648 Set_Is_Immediately_Visible (E, False);
1650 -- The new entity may be the package renaming, which has the same
1651 -- same name as a generic formal which has been seen already.
1653 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
1654 and then not Comes_From_Source (Def_Id)
1656 Set_Is_Immediately_Visible (E, False);
1658 -- For a fat pointer corresponding to a remote access to subprogram,
1659 -- we use the same identifier as the RAS type, so that the proper
1660 -- name appears in the stub. This type is only retrieved through
1661 -- the RAS type and never by visibility, and is not added to the
1662 -- visibility list (see below).
1664 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
1665 and then Present (Corresponding_Remote_Type (Def_Id))
1669 -- A controller component for a type extension overrides the
1670 -- inherited component.
1672 elsif Chars (E) = Name_uController then
1675 -- Case of an implicit operation or derived literal. The new entity
1676 -- hides the implicit one, which is removed from all visibility,
1677 -- i.e. the entity list of its scope, and homonym chain of its name.
1679 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
1680 or else Is_Internal (E)
1684 Prev_Vis : Entity_Id;
1685 Decl : constant Node_Id := Parent (E);
1688 -- If E is an implicit declaration, it cannot be the first
1689 -- entity in the scope.
1691 Prev := First_Entity (Current_Scope);
1693 while Present (Prev)
1694 and then Next_Entity (Prev) /= E
1701 -- If E is not on the entity chain of the current scope,
1702 -- it is an implicit declaration in the generic formal
1703 -- part of a generic subprogram. When analyzing the body,
1704 -- the generic formals are visible but not on the entity
1705 -- chain of the subprogram. The new entity will become
1706 -- the visible one in the body.
1709 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
1713 Set_Next_Entity (Prev, Next_Entity (E));
1715 if No (Next_Entity (Prev)) then
1716 Set_Last_Entity (Current_Scope, Prev);
1719 if E = Current_Entity (E) then
1723 Prev_Vis := Current_Entity (E);
1724 while Homonym (Prev_Vis) /= E loop
1725 Prev_Vis := Homonym (Prev_Vis);
1729 if Present (Prev_Vis) then
1731 -- Skip E in the visibility chain
1733 Set_Homonym (Prev_Vis, Homonym (E));
1736 Set_Name_Entity_Id (Chars (E), Homonym (E));
1741 -- This section of code could use a comment ???
1743 elsif Present (Etype (E))
1744 and then Is_Concurrent_Type (Etype (E))
1749 -- In the body or private part of an instance, a type extension
1750 -- may introduce a component with the same name as that of an
1751 -- actual. The legality rule is not enforced, but the semantics
1752 -- of the full type with two components of the same name are not
1753 -- clear at this point ???
1755 elsif In_Instance_Not_Visible then
1758 -- When compiling a package body, some child units may have become
1759 -- visible. They cannot conflict with local entities that hide them.
1761 elsif Is_Child_Unit (E)
1762 and then In_Open_Scopes (Scope (E))
1763 and then not Is_Immediately_Visible (E)
1767 -- Conversely, with front-end inlining we may compile the parent
1768 -- body first, and a child unit subsequently. The context is now
1769 -- the parent spec, and body entities are not visible.
1771 elsif Is_Child_Unit (Def_Id)
1772 and then Is_Package_Body_Entity (E)
1773 and then not In_Package_Body (Current_Scope)
1777 -- Case of genuine duplicate declaration
1780 Error_Msg_Sloc := Sloc (E);
1782 -- If the previous declaration is an incomplete type declaration
1783 -- this may be an attempt to complete it with a private type.
1784 -- The following avoids confusing cascaded errors.
1786 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
1787 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
1790 ("incomplete type cannot be completed" &
1791 " with a private declaration",
1793 Set_Is_Immediately_Visible (E, False);
1794 Set_Full_View (E, Def_Id);
1796 elsif Ekind (E) = E_Discriminant
1797 and then Present (Scope (Def_Id))
1798 and then Scope (Def_Id) /= Current_Scope
1800 -- An inherited component of a record conflicts with
1801 -- a new discriminant. The discriminant is inserted first
1802 -- in the scope, but the error should be posted on it, not
1803 -- on the component.
1805 Error_Msg_Sloc := Sloc (Def_Id);
1806 Error_Msg_N ("& conflicts with declaration#", E);
1809 -- If the name of the unit appears in its own context clause,
1810 -- a dummy package with the name has already been created, and
1811 -- the error emitted. Try to continue quietly.
1813 elsif Error_Posted (E)
1814 and then Sloc (E) = No_Location
1815 and then Nkind (Parent (E)) = N_Package_Specification
1816 and then Current_Scope = Standard_Standard
1818 Set_Scope (Def_Id, Current_Scope);
1822 Error_Msg_N ("& conflicts with declaration#", Def_Id);
1824 -- Avoid cascaded messages with duplicate components in
1827 if Ekind (E) = E_Component
1828 or else Ekind (E) = E_Discriminant
1834 if Nkind (Parent (Parent (Def_Id)))
1835 = N_Generic_Subprogram_Declaration
1837 Defining_Entity (Specification (Parent (Parent (Def_Id))))
1839 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
1842 -- If entity is in standard, then we are in trouble, because
1843 -- it means that we have a library package with a duplicated
1844 -- name. That's hard to recover from, so abort!
1846 if S = Standard_Standard then
1847 raise Unrecoverable_Error;
1849 -- Otherwise we continue with the declaration. Having two
1850 -- identical declarations should not cause us too much trouble!
1858 -- If we fall through, declaration is OK , or OK enough to continue
1860 -- If Def_Id is a discriminant or a record component we are in the
1861 -- midst of inheriting components in a derived record definition.
1862 -- Preserve their Ekind and Etype.
1864 if Ekind (Def_Id) = E_Discriminant
1865 or else Ekind (Def_Id) = E_Component
1869 -- If a type is already set, leave it alone (happens whey a type
1870 -- declaration is reanalyzed following a call to the optimizer)
1872 elsif Present (Etype (Def_Id)) then
1875 -- Otherwise, the kind E_Void insures that premature uses of the entity
1876 -- will be detected. Any_Type insures that no cascaded errors will occur
1879 Set_Ekind (Def_Id, E_Void);
1880 Set_Etype (Def_Id, Any_Type);
1883 -- Inherited discriminants and components in derived record types are
1884 -- immediately visible. Itypes are not.
1886 if Ekind (Def_Id) = E_Discriminant
1887 or else Ekind (Def_Id) = E_Component
1888 or else (No (Corresponding_Remote_Type (Def_Id))
1889 and then not Is_Itype (Def_Id))
1891 Set_Is_Immediately_Visible (Def_Id);
1892 Set_Current_Entity (Def_Id);
1895 Set_Homonym (Def_Id, C);
1896 Append_Entity (Def_Id, S);
1897 Set_Public_Status (Def_Id);
1899 -- Warn if new entity hides an old one
1902 and then Present (C)
1903 and then Length_Of_Name (Chars (C)) /= 1
1904 and then Comes_From_Source (C)
1905 and then Comes_From_Source (Def_Id)
1906 and then In_Extended_Main_Source_Unit (Def_Id)
1908 Error_Msg_Sloc := Sloc (C);
1909 Error_Msg_N ("declaration hides &#?", Def_Id);
1913 --------------------------
1914 -- Explain_Limited_Type --
1915 --------------------------
1917 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
1921 -- For array, component type must be limited
1923 if Is_Array_Type (T) then
1924 Error_Msg_Node_2 := T;
1926 ("component type& of type& is limited", N, Component_Type (T));
1927 Explain_Limited_Type (Component_Type (T), N);
1929 elsif Is_Record_Type (T) then
1931 -- No need for extra messages if explicit limited record
1933 if Is_Limited_Record (Base_Type (T)) then
1937 -- Otherwise find a limited component
1939 C := First_Component (T);
1940 while Present (C) loop
1941 if Is_Limited_Type (Etype (C)) then
1942 Error_Msg_Node_2 := T;
1943 Error_Msg_NE ("\component& of type& has limited type", N, C);
1944 Explain_Limited_Type (Etype (C), N);
1951 -- It's odd if the loop falls through, but this is only an extra
1952 -- error message, so we just let it go and ignore the situation.
1956 end Explain_Limited_Type;
1958 -------------------------------------
1959 -- Find_Corresponding_Discriminant --
1960 -------------------------------------
1962 function Find_Corresponding_Discriminant
1964 Typ : Entity_Id) return Entity_Id
1966 Par_Disc : Entity_Id;
1967 Old_Disc : Entity_Id;
1968 New_Disc : Entity_Id;
1971 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
1973 -- The original type may currently be private, and the discriminant
1974 -- only appear on its full view.
1976 if Is_Private_Type (Scope (Par_Disc))
1977 and then not Has_Discriminants (Scope (Par_Disc))
1978 and then Present (Full_View (Scope (Par_Disc)))
1980 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
1982 Old_Disc := First_Discriminant (Scope (Par_Disc));
1985 if Is_Class_Wide_Type (Typ) then
1986 New_Disc := First_Discriminant (Root_Type (Typ));
1988 New_Disc := First_Discriminant (Typ);
1991 while Present (Old_Disc) and then Present (New_Disc) loop
1992 if Old_Disc = Par_Disc then
1995 Next_Discriminant (Old_Disc);
1996 Next_Discriminant (New_Disc);
2000 -- Should always find it
2002 raise Program_Error;
2003 end Find_Corresponding_Discriminant;
2005 -----------------------------
2006 -- Find_Static_Alternative --
2007 -----------------------------
2009 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2010 Expr : constant Node_Id := Expression (N);
2011 Val : constant Uint := Expr_Value (Expr);
2016 Alt := First (Alternatives (N));
2019 if Nkind (Alt) /= N_Pragma then
2020 Choice := First (Discrete_Choices (Alt));
2022 while Present (Choice) loop
2024 -- Others choice, always matches
2026 if Nkind (Choice) = N_Others_Choice then
2029 -- Range, check if value is in the range
2031 elsif Nkind (Choice) = N_Range then
2033 Val >= Expr_Value (Low_Bound (Choice))
2035 Val <= Expr_Value (High_Bound (Choice));
2037 -- Choice is a subtype name. Note that we know it must
2038 -- be a static subtype, since otherwise it would have
2039 -- been diagnosed as illegal.
2041 elsif Is_Entity_Name (Choice)
2042 and then Is_Type (Entity (Choice))
2044 exit Search when Is_In_Range (Expr, Etype (Choice));
2046 -- Choice is a subtype indication
2048 elsif Nkind (Choice) = N_Subtype_Indication then
2050 C : constant Node_Id := Constraint (Choice);
2051 R : constant Node_Id := Range_Expression (C);
2055 Val >= Expr_Value (Low_Bound (R))
2057 Val <= Expr_Value (High_Bound (R));
2060 -- Choice is a simple expression
2063 exit Search when Val = Expr_Value (Choice);
2071 pragma Assert (Present (Alt));
2074 -- The above loop *must* terminate by finding a match, since
2075 -- we know the case statement is valid, and the value of the
2076 -- expression is known at compile time. When we fall out of
2077 -- the loop, Alt points to the alternative that we know will
2078 -- be selected at run time.
2081 end Find_Static_Alternative;
2087 function First_Actual (Node : Node_Id) return Node_Id is
2091 if No (Parameter_Associations (Node)) then
2095 N := First (Parameter_Associations (Node));
2097 if Nkind (N) = N_Parameter_Association then
2098 return First_Named_Actual (Node);
2104 -------------------------
2105 -- Full_Qualified_Name --
2106 -------------------------
2108 function Full_Qualified_Name (E : Entity_Id) return String_Id is
2110 pragma Warnings (Off, Res);
2112 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
2113 -- Compute recursively the qualified name without NUL at the end.
2115 ----------------------------------
2116 -- Internal_Full_Qualified_Name --
2117 ----------------------------------
2119 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
2120 Ent : Entity_Id := E;
2121 Parent_Name : String_Id := No_String;
2124 -- Deals properly with child units
2126 if Nkind (Ent) = N_Defining_Program_Unit_Name then
2127 Ent := Defining_Identifier (Ent);
2130 -- Compute recursively the qualification. Only "Standard" has no
2133 if Present (Scope (Scope (Ent))) then
2134 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
2137 -- Every entity should have a name except some expanded blocks
2138 -- don't bother about those.
2140 if Chars (Ent) = No_Name then
2144 -- Add a period between Name and qualification
2146 if Parent_Name /= No_String then
2147 Start_String (Parent_Name);
2148 Store_String_Char (Get_Char_Code ('.'));
2154 -- Generates the entity name in upper case
2156 Get_Name_String (Chars (Ent));
2158 Store_String_Chars (Name_Buffer (1 .. Name_Len));
2160 end Internal_Full_Qualified_Name;
2162 -- Start of processing for Full_Qualified_Name
2165 Res := Internal_Full_Qualified_Name (E);
2166 Store_String_Char (Get_Char_Code (ASCII.nul));
2168 end Full_Qualified_Name;
2170 -----------------------
2171 -- Gather_Components --
2172 -----------------------
2174 procedure Gather_Components
2176 Comp_List : Node_Id;
2177 Governed_By : List_Id;
2179 Report_Errors : out Boolean)
2183 Discrete_Choice : Node_Id;
2184 Comp_Item : Node_Id;
2186 Discrim : Entity_Id;
2187 Discrim_Name : Node_Id;
2188 Discrim_Value : Node_Id;
2191 Report_Errors := False;
2193 if No (Comp_List) or else Null_Present (Comp_List) then
2196 elsif Present (Component_Items (Comp_List)) then
2197 Comp_Item := First (Component_Items (Comp_List));
2203 while Present (Comp_Item) loop
2205 -- Skip the tag of a tagged record, as well as all items
2206 -- that are not user components (anonymous types, rep clauses,
2207 -- Parent field, controller field).
2209 if Nkind (Comp_Item) = N_Component_Declaration
2210 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uTag
2211 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uParent
2212 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uController
2214 Append_Elmt (Defining_Identifier (Comp_Item), Into);
2220 if No (Variant_Part (Comp_List)) then
2223 Discrim_Name := Name (Variant_Part (Comp_List));
2224 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
2227 -- Look for the discriminant that governs this variant part.
2228 -- The discriminant *must* be in the Governed_By List
2230 Assoc := First (Governed_By);
2231 Find_Constraint : loop
2232 Discrim := First (Choices (Assoc));
2233 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
2234 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
2236 Chars (Corresponding_Discriminant (Entity (Discrim)))
2237 = Chars (Discrim_Name))
2238 or else Chars (Original_Record_Component (Entity (Discrim)))
2239 = Chars (Discrim_Name);
2241 if No (Next (Assoc)) then
2242 if not Is_Constrained (Typ)
2243 and then Is_Derived_Type (Typ)
2244 and then Present (Stored_Constraint (Typ))
2247 -- If the type is a tagged type with inherited discriminants,
2248 -- use the stored constraint on the parent in order to find
2249 -- the values of discriminants that are otherwise hidden by an
2250 -- explicit constraint. Renamed discriminants are handled in
2253 -- If several parent discriminants are renamed by a single
2254 -- discriminant of the derived type, the call to obtain the
2255 -- Corresponding_Discriminant field only retrieves the last
2256 -- of them. We recover the constraint on the others from the
2257 -- Stored_Constraint as well.
2264 D := First_Discriminant (Etype (Typ));
2265 C := First_Elmt (Stored_Constraint (Typ));
2268 and then Present (C)
2270 if Chars (Discrim_Name) = Chars (D) then
2271 if Is_Entity_Name (Node (C))
2272 and then Entity (Node (C)) = Entity (Discrim)
2274 -- D is renamed by Discrim, whose value is
2281 Make_Component_Association (Sloc (Typ),
2283 (New_Occurrence_Of (D, Sloc (Typ))),
2284 Duplicate_Subexpr_No_Checks (Node (C)));
2286 exit Find_Constraint;
2289 D := Next_Discriminant (D);
2296 if No (Next (Assoc)) then
2297 Error_Msg_NE (" missing value for discriminant&",
2298 First (Governed_By), Discrim_Name);
2299 Report_Errors := True;
2304 end loop Find_Constraint;
2306 Discrim_Value := Expression (Assoc);
2308 if not Is_OK_Static_Expression (Discrim_Value) then
2310 ("value for discriminant & must be static!",
2311 Discrim_Value, Discrim);
2312 Why_Not_Static (Discrim_Value);
2313 Report_Errors := True;
2317 Search_For_Discriminant_Value : declare
2323 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
2326 Find_Discrete_Value : while Present (Variant) loop
2327 Discrete_Choice := First (Discrete_Choices (Variant));
2328 while Present (Discrete_Choice) loop
2330 exit Find_Discrete_Value when
2331 Nkind (Discrete_Choice) = N_Others_Choice;
2333 Get_Index_Bounds (Discrete_Choice, Low, High);
2335 UI_Low := Expr_Value (Low);
2336 UI_High := Expr_Value (High);
2338 exit Find_Discrete_Value when
2339 UI_Low <= UI_Discrim_Value
2341 UI_High >= UI_Discrim_Value;
2343 Next (Discrete_Choice);
2346 Next_Non_Pragma (Variant);
2347 end loop Find_Discrete_Value;
2348 end Search_For_Discriminant_Value;
2350 if No (Variant) then
2352 ("value of discriminant & is out of range", Discrim_Value, Discrim);
2353 Report_Errors := True;
2357 -- If we have found the corresponding choice, recursively add its
2358 -- components to the Into list.
2360 Gather_Components (Empty,
2361 Component_List (Variant), Governed_By, Into, Report_Errors);
2362 end Gather_Components;
2364 ------------------------
2365 -- Get_Actual_Subtype --
2366 ------------------------
2368 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
2369 Typ : constant Entity_Id := Etype (N);
2370 Utyp : Entity_Id := Underlying_Type (Typ);
2375 if not Present (Utyp) then
2379 -- If what we have is an identifier that references a subprogram
2380 -- formal, or a variable or constant object, then we get the actual
2381 -- subtype from the referenced entity if one has been built.
2383 if Nkind (N) = N_Identifier
2385 (Is_Formal (Entity (N))
2386 or else Ekind (Entity (N)) = E_Constant
2387 or else Ekind (Entity (N)) = E_Variable)
2388 and then Present (Actual_Subtype (Entity (N)))
2390 return Actual_Subtype (Entity (N));
2392 -- Actual subtype of unchecked union is always itself. We never need
2393 -- the "real" actual subtype. If we did, we couldn't get it anyway
2394 -- because the discriminant is not available. The restrictions on
2395 -- Unchecked_Union are designed to make sure that this is OK.
2397 elsif Is_Unchecked_Union (Utyp) then
2400 -- Here for the unconstrained case, we must find actual subtype
2401 -- No actual subtype is available, so we must build it on the fly.
2403 -- Checking the type, not the underlying type, for constrainedness
2404 -- seems to be necessary. Maybe all the tests should be on the type???
2406 elsif (not Is_Constrained (Typ))
2407 and then (Is_Array_Type (Utyp)
2408 or else (Is_Record_Type (Utyp)
2409 and then Has_Discriminants (Utyp)))
2410 and then not Has_Unknown_Discriminants (Utyp)
2411 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
2413 -- Nothing to do if in default expression
2415 if In_Default_Expression then
2418 elsif Is_Private_Type (Typ)
2419 and then not Has_Discriminants (Typ)
2421 -- If the type has no discriminants, there is no subtype to
2422 -- build, even if the underlying type is discriminated.
2426 -- Else build the actual subtype
2429 Decl := Build_Actual_Subtype (Typ, N);
2430 Atyp := Defining_Identifier (Decl);
2432 -- If Build_Actual_Subtype generated a new declaration then use it
2436 -- The actual subtype is an Itype, so analyze the declaration,
2437 -- but do not attach it to the tree, to get the type defined.
2439 Set_Parent (Decl, N);
2440 Set_Is_Itype (Atyp);
2441 Analyze (Decl, Suppress => All_Checks);
2442 Set_Associated_Node_For_Itype (Atyp, N);
2443 Set_Has_Delayed_Freeze (Atyp, False);
2445 -- We need to freeze the actual subtype immediately. This is
2446 -- needed, because otherwise this Itype will not get frozen
2447 -- at all, and it is always safe to freeze on creation because
2448 -- any associated types must be frozen at this point.
2450 Freeze_Itype (Atyp, N);
2453 -- Otherwise we did not build a declaration, so return original
2460 -- For all remaining cases, the actual subtype is the same as
2461 -- the nominal type.
2466 end Get_Actual_Subtype;
2468 -------------------------------------
2469 -- Get_Actual_Subtype_If_Available --
2470 -------------------------------------
2472 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
2473 Typ : constant Entity_Id := Etype (N);
2476 -- If what we have is an identifier that references a subprogram
2477 -- formal, or a variable or constant object, then we get the actual
2478 -- subtype from the referenced entity if one has been built.
2480 if Nkind (N) = N_Identifier
2482 (Is_Formal (Entity (N))
2483 or else Ekind (Entity (N)) = E_Constant
2484 or else Ekind (Entity (N)) = E_Variable)
2485 and then Present (Actual_Subtype (Entity (N)))
2487 return Actual_Subtype (Entity (N));
2489 -- Otherwise the Etype of N is returned unchanged
2494 end Get_Actual_Subtype_If_Available;
2496 -------------------------------
2497 -- Get_Default_External_Name --
2498 -------------------------------
2500 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
2502 Get_Decoded_Name_String (Chars (E));
2504 if Opt.External_Name_Imp_Casing = Uppercase then
2505 Set_Casing (All_Upper_Case);
2507 Set_Casing (All_Lower_Case);
2511 Make_String_Literal (Sloc (E),
2512 Strval => String_From_Name_Buffer);
2513 end Get_Default_External_Name;
2515 ---------------------------
2516 -- Get_Enum_Lit_From_Pos --
2517 ---------------------------
2519 function Get_Enum_Lit_From_Pos
2522 Loc : Source_Ptr) return Node_Id
2525 P : constant Nat := UI_To_Int (Pos);
2528 -- In the case where the literal is either of type Wide_Character
2529 -- or Character or of a type derived from them, there needs to be
2530 -- some special handling since there is no explicit chain of
2531 -- literals to search. Instead, an N_Character_Literal node is
2532 -- created with the appropriate Char_Code and Chars fields.
2534 if Root_Type (T) = Standard_Character
2535 or else Root_Type (T) = Standard_Wide_Character
2537 Set_Character_Literal_Name (Char_Code (P));
2539 Make_Character_Literal (Loc,
2541 Char_Literal_Value => Char_Code (P));
2543 -- For all other cases, we have a complete table of literals, and
2544 -- we simply iterate through the chain of literal until the one
2545 -- with the desired position value is found.
2549 Lit := First_Literal (Base_Type (T));
2550 for J in 1 .. P loop
2554 return New_Occurrence_Of (Lit, Loc);
2556 end Get_Enum_Lit_From_Pos;
2558 ------------------------
2559 -- Get_Generic_Entity --
2560 ------------------------
2562 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
2563 Ent : constant Entity_Id := Entity (Name (N));
2566 if Present (Renamed_Object (Ent)) then
2567 return Renamed_Object (Ent);
2571 end Get_Generic_Entity;
2573 ----------------------
2574 -- Get_Index_Bounds --
2575 ----------------------
2577 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
2578 Kind : constant Node_Kind := Nkind (N);
2582 if Kind = N_Range then
2584 H := High_Bound (N);
2586 elsif Kind = N_Subtype_Indication then
2587 R := Range_Expression (Constraint (N));
2595 L := Low_Bound (Range_Expression (Constraint (N)));
2596 H := High_Bound (Range_Expression (Constraint (N)));
2599 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
2600 if Error_Posted (Scalar_Range (Entity (N))) then
2604 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
2605 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
2608 L := Low_Bound (Scalar_Range (Entity (N)));
2609 H := High_Bound (Scalar_Range (Entity (N)));
2613 -- N is an expression, indicating a range with one value.
2618 end Get_Index_Bounds;
2620 ------------------------
2621 -- Get_Name_Entity_Id --
2622 ------------------------
2624 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
2626 return Entity_Id (Get_Name_Table_Info (Id));
2627 end Get_Name_Entity_Id;
2629 ---------------------------
2630 -- Get_Referenced_Object --
2631 ---------------------------
2633 function Get_Referenced_Object (N : Node_Id) return Node_Id is
2637 while Is_Entity_Name (R)
2638 and then Present (Renamed_Object (Entity (R)))
2640 R := Renamed_Object (Entity (R));
2644 end Get_Referenced_Object;
2646 -------------------------
2647 -- Get_Subprogram_Body --
2648 -------------------------
2650 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
2654 Decl := Unit_Declaration_Node (E);
2656 if Nkind (Decl) = N_Subprogram_Body then
2659 -- The below comment is bad, because it is possible for
2660 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
2662 else -- Nkind (Decl) = N_Subprogram_Declaration
2664 if Present (Corresponding_Body (Decl)) then
2665 return Unit_Declaration_Node (Corresponding_Body (Decl));
2667 -- Imported subprogram case
2673 end Get_Subprogram_Body;
2675 -----------------------------
2676 -- Get_Task_Body_Procedure --
2677 -----------------------------
2679 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
2681 return Task_Body_Procedure (Declaration_Node (Root_Type (E)));
2682 end Get_Task_Body_Procedure;
2684 -----------------------
2685 -- Has_Access_Values --
2686 -----------------------
2688 function Has_Access_Values (T : Entity_Id) return Boolean is
2689 Typ : constant Entity_Id := Underlying_Type (T);
2692 -- Case of a private type which is not completed yet. This can only
2693 -- happen in the case of a generic format type appearing directly, or
2694 -- as a component of the type to which this function is being applied
2695 -- at the top level. Return False in this case, since we certainly do
2696 -- not know that the type contains access types.
2701 elsif Is_Access_Type (Typ) then
2704 elsif Is_Array_Type (Typ) then
2705 return Has_Access_Values (Component_Type (Typ));
2707 elsif Is_Record_Type (Typ) then
2712 Comp := First_Entity (Typ);
2713 while Present (Comp) loop
2714 if (Ekind (Comp) = E_Component
2716 Ekind (Comp) = E_Discriminant)
2717 and then Has_Access_Values (Etype (Comp))
2731 end Has_Access_Values;
2733 ----------------------
2734 -- Has_Declarations --
2735 ----------------------
2737 function Has_Declarations (N : Node_Id) return Boolean is
2738 K : constant Node_Kind := Nkind (N);
2740 return K = N_Accept_Statement
2741 or else K = N_Block_Statement
2742 or else K = N_Compilation_Unit_Aux
2743 or else K = N_Entry_Body
2744 or else K = N_Package_Body
2745 or else K = N_Protected_Body
2746 or else K = N_Subprogram_Body
2747 or else K = N_Task_Body
2748 or else K = N_Package_Specification;
2749 end Has_Declarations;
2751 --------------------
2752 -- Has_Infinities --
2753 --------------------
2755 function Has_Infinities (E : Entity_Id) return Boolean is
2758 Is_Floating_Point_Type (E)
2759 and then Nkind (Scalar_Range (E)) = N_Range
2760 and then Includes_Infinities (Scalar_Range (E));
2763 ------------------------
2764 -- Has_Null_Extension --
2765 ------------------------
2767 function Has_Null_Extension (T : Entity_Id) return Boolean is
2768 B : constant Entity_Id := Base_Type (T);
2773 if Nkind (Parent (B)) = N_Full_Type_Declaration
2774 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
2776 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
2778 if Present (Ext) then
2779 if Null_Present (Ext) then
2782 Comps := Component_List (Ext);
2784 -- The null component list is rewritten during analysis to
2785 -- include the parent component. Any other component indicates
2786 -- that the extension was not originally null.
2788 return Null_Present (Comps)
2789 or else No (Next (First (Component_Items (Comps))));
2798 end Has_Null_Extension;
2800 ---------------------------
2801 -- Has_Private_Component --
2802 ---------------------------
2804 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
2805 Btype : Entity_Id := Base_Type (Type_Id);
2806 Component : Entity_Id;
2809 if Error_Posted (Type_Id)
2810 or else Error_Posted (Btype)
2815 if Is_Class_Wide_Type (Btype) then
2816 Btype := Root_Type (Btype);
2819 if Is_Private_Type (Btype) then
2821 UT : constant Entity_Id := Underlying_Type (Btype);
2825 if No (Full_View (Btype)) then
2826 return not Is_Generic_Type (Btype)
2827 and then not Is_Generic_Type (Root_Type (Btype));
2830 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
2834 return not Is_Frozen (UT) and then Has_Private_Component (UT);
2837 elsif Is_Array_Type (Btype) then
2838 return Has_Private_Component (Component_Type (Btype));
2840 elsif Is_Record_Type (Btype) then
2842 Component := First_Component (Btype);
2843 while Present (Component) loop
2845 if Has_Private_Component (Etype (Component)) then
2849 Next_Component (Component);
2854 elsif Is_Protected_Type (Btype)
2855 and then Present (Corresponding_Record_Type (Btype))
2857 return Has_Private_Component (Corresponding_Record_Type (Btype));
2862 end Has_Private_Component;
2864 --------------------------
2865 -- Has_Tagged_Component --
2866 --------------------------
2868 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
2872 if Is_Private_Type (Typ)
2873 and then Present (Underlying_Type (Typ))
2875 return Has_Tagged_Component (Underlying_Type (Typ));
2877 elsif Is_Array_Type (Typ) then
2878 return Has_Tagged_Component (Component_Type (Typ));
2880 elsif Is_Tagged_Type (Typ) then
2883 elsif Is_Record_Type (Typ) then
2884 Comp := First_Component (Typ);
2886 while Present (Comp) loop
2887 if Has_Tagged_Component (Etype (Comp)) then
2891 Comp := Next_Component (Typ);
2899 end Has_Tagged_Component;
2905 function In_Instance return Boolean is
2906 S : Entity_Id := Current_Scope;
2910 and then S /= Standard_Standard
2912 if (Ekind (S) = E_Function
2913 or else Ekind (S) = E_Package
2914 or else Ekind (S) = E_Procedure)
2915 and then Is_Generic_Instance (S)
2926 ----------------------
2927 -- In_Instance_Body --
2928 ----------------------
2930 function In_Instance_Body return Boolean is
2931 S : Entity_Id := Current_Scope;
2935 and then S /= Standard_Standard
2937 if (Ekind (S) = E_Function
2938 or else Ekind (S) = E_Procedure)
2939 and then Is_Generic_Instance (S)
2943 elsif Ekind (S) = E_Package
2944 and then In_Package_Body (S)
2945 and then Is_Generic_Instance (S)
2954 end In_Instance_Body;
2956 -----------------------------
2957 -- In_Instance_Not_Visible --
2958 -----------------------------
2960 function In_Instance_Not_Visible return Boolean is
2961 S : Entity_Id := Current_Scope;
2965 and then S /= Standard_Standard
2967 if (Ekind (S) = E_Function
2968 or else Ekind (S) = E_Procedure)
2969 and then Is_Generic_Instance (S)
2973 elsif Ekind (S) = E_Package
2974 and then (In_Package_Body (S) or else In_Private_Part (S))
2975 and then Is_Generic_Instance (S)
2984 end In_Instance_Not_Visible;
2986 ------------------------------
2987 -- In_Instance_Visible_Part --
2988 ------------------------------
2990 function In_Instance_Visible_Part return Boolean is
2991 S : Entity_Id := Current_Scope;
2995 and then S /= Standard_Standard
2997 if Ekind (S) = E_Package
2998 and then Is_Generic_Instance (S)
2999 and then not In_Package_Body (S)
3000 and then not In_Private_Part (S)
3009 end In_Instance_Visible_Part;
3011 ----------------------
3012 -- In_Packiage_Body --
3013 ----------------------
3015 function In_Package_Body return Boolean is
3016 S : Entity_Id := Current_Scope;
3020 and then S /= Standard_Standard
3022 if Ekind (S) = E_Package
3023 and then In_Package_Body (S)
3032 end In_Package_Body;
3034 --------------------------------------
3035 -- In_Subprogram_Or_Concurrent_Unit --
3036 --------------------------------------
3038 function In_Subprogram_Or_Concurrent_Unit return Boolean is
3043 -- Use scope chain to check successively outer scopes
3049 if K in Subprogram_Kind
3050 or else K in Concurrent_Kind
3051 or else K in Generic_Subprogram_Kind
3055 elsif E = Standard_Standard then
3061 end In_Subprogram_Or_Concurrent_Unit;
3063 ---------------------
3064 -- In_Visible_Part --
3065 ---------------------
3067 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
3070 Is_Package (Scope_Id)
3071 and then In_Open_Scopes (Scope_Id)
3072 and then not In_Package_Body (Scope_Id)
3073 and then not In_Private_Part (Scope_Id);
3074 end In_Visible_Part;
3076 ---------------------------------
3077 -- Insert_Explicit_Dereference --
3078 ---------------------------------
3080 procedure Insert_Explicit_Dereference (N : Node_Id) is
3081 New_Prefix : constant Node_Id := Relocate_Node (N);
3087 Save_Interps (N, New_Prefix);
3089 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
3091 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
3093 if Is_Overloaded (New_Prefix) then
3095 -- The deference is also overloaded, and its interpretations are the
3096 -- designated types of the interpretations of the original node.
3098 Set_Etype (N, Any_Type);
3099 Get_First_Interp (New_Prefix, I, It);
3101 while Present (It.Nam) loop
3104 if Is_Access_Type (T) then
3105 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
3108 Get_Next_Interp (I, It);
3113 end Insert_Explicit_Dereference;
3119 function Is_AAMP_Float (E : Entity_Id) return Boolean is
3121 pragma Assert (Is_Type (E));
3123 return AAMP_On_Target
3124 and then Is_Floating_Point_Type (E)
3125 and then E = Base_Type (E);
3128 -------------------------
3129 -- Is_Actual_Parameter --
3130 -------------------------
3132 function Is_Actual_Parameter (N : Node_Id) return Boolean is
3133 PK : constant Node_Kind := Nkind (Parent (N));
3137 when N_Parameter_Association =>
3138 return N = Explicit_Actual_Parameter (Parent (N));
3140 when N_Function_Call | N_Procedure_Call_Statement =>
3141 return Is_List_Member (N)
3143 List_Containing (N) = Parameter_Associations (Parent (N));
3148 end Is_Actual_Parameter;
3150 ---------------------
3151 -- Is_Aliased_View --
3152 ---------------------
3154 function Is_Aliased_View (Obj : Node_Id) return Boolean is
3158 if Is_Entity_Name (Obj) then
3160 -- Shouldn't we check that we really have an object here?
3161 -- If we do, then a-caldel.adb blows up mysteriously ???
3165 return Is_Aliased (E)
3166 or else (Present (Renamed_Object (E))
3167 and then Is_Aliased_View (Renamed_Object (E)))
3169 or else ((Is_Formal (E)
3170 or else Ekind (E) = E_Generic_In_Out_Parameter
3171 or else Ekind (E) = E_Generic_In_Parameter)
3172 and then Is_Tagged_Type (Etype (E)))
3174 or else ((Ekind (E) = E_Task_Type or else
3175 Ekind (E) = E_Protected_Type)
3176 and then In_Open_Scopes (E))
3178 -- Current instance of type
3180 or else (Is_Type (E) and then E = Current_Scope)
3181 or else (Is_Incomplete_Or_Private_Type (E)
3182 and then Full_View (E) = Current_Scope);
3184 elsif Nkind (Obj) = N_Selected_Component then
3185 return Is_Aliased (Entity (Selector_Name (Obj)));
3187 elsif Nkind (Obj) = N_Indexed_Component then
3188 return Has_Aliased_Components (Etype (Prefix (Obj)))
3190 (Is_Access_Type (Etype (Prefix (Obj)))
3192 Has_Aliased_Components
3193 (Designated_Type (Etype (Prefix (Obj)))));
3195 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
3196 or else Nkind (Obj) = N_Type_Conversion
3198 return Is_Tagged_Type (Etype (Obj))
3199 and then Is_Aliased_View (Expression (Obj));
3201 elsif Nkind (Obj) = N_Explicit_Dereference then
3202 return Nkind (Original_Node (Obj)) /= N_Function_Call;
3207 end Is_Aliased_View;
3209 -------------------------
3210 -- Is_Ancestor_Package --
3211 -------------------------
3213 function Is_Ancestor_Package
3215 E2 : Entity_Id) return Boolean
3222 and then Par /= Standard_Standard
3232 end Is_Ancestor_Package;
3234 ----------------------
3235 -- Is_Atomic_Object --
3236 ----------------------
3238 function Is_Atomic_Object (N : Node_Id) return Boolean is
3240 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
3241 -- Determines if given object has atomic components
3243 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
3244 -- If prefix is an implicit dereference, examine designated type.
3246 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
3248 if Is_Access_Type (Etype (N)) then
3250 Has_Atomic_Components (Designated_Type (Etype (N)));
3252 return Object_Has_Atomic_Components (N);
3254 end Is_Atomic_Prefix;
3256 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
3258 if Has_Atomic_Components (Etype (N))
3259 or else Is_Atomic (Etype (N))
3263 elsif Is_Entity_Name (N)
3264 and then (Has_Atomic_Components (Entity (N))
3265 or else Is_Atomic (Entity (N)))
3269 elsif Nkind (N) = N_Indexed_Component
3270 or else Nkind (N) = N_Selected_Component
3272 return Is_Atomic_Prefix (Prefix (N));
3277 end Object_Has_Atomic_Components;
3279 -- Start of processing for Is_Atomic_Object
3282 if Is_Atomic (Etype (N))
3283 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
3287 elsif Nkind (N) = N_Indexed_Component
3288 or else Nkind (N) = N_Selected_Component
3290 return Is_Atomic_Prefix (Prefix (N));
3295 end Is_Atomic_Object;
3297 ----------------------------------------------
3298 -- Is_Dependent_Component_Of_Mutable_Object --
3299 ----------------------------------------------
3301 function Is_Dependent_Component_Of_Mutable_Object
3302 (Object : Node_Id) return Boolean
3305 Prefix_Type : Entity_Id;
3306 P_Aliased : Boolean := False;
3309 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean;
3310 -- Returns True if and only if Comp has a constrained subtype
3311 -- that depends on a discriminant.
3313 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
3314 -- Returns True if and only if Comp is declared within a variant part.
3316 ------------------------------
3317 -- Has_Dependent_Constraint --
3318 ------------------------------
3320 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean is
3321 Comp_Decl : constant Node_Id := Parent (Comp);
3322 Subt_Indic : constant Node_Id :=
3323 Subtype_Indication (Component_Definition (Comp_Decl));
3328 if Nkind (Subt_Indic) = N_Subtype_Indication then
3329 Constr := Constraint (Subt_Indic);
3331 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
3332 Assn := First (Constraints (Constr));
3333 while Present (Assn) loop
3334 case Nkind (Assn) is
3335 when N_Subtype_Indication |
3339 if Depends_On_Discriminant (Assn) then
3343 when N_Discriminant_Association =>
3344 if Depends_On_Discriminant (Expression (Assn)) then
3359 end Has_Dependent_Constraint;
3361 --------------------------------
3362 -- Is_Declared_Within_Variant --
3363 --------------------------------
3365 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
3366 Comp_Decl : constant Node_Id := Parent (Comp);
3367 Comp_List : constant Node_Id := Parent (Comp_Decl);
3370 return Nkind (Parent (Comp_List)) = N_Variant;
3371 end Is_Declared_Within_Variant;
3373 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
3376 if Is_Variable (Object) then
3378 if Nkind (Object) = N_Selected_Component then
3379 P := Prefix (Object);
3380 Prefix_Type := Etype (P);
3382 if Is_Entity_Name (P) then
3384 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
3385 Prefix_Type := Base_Type (Prefix_Type);
3388 if Is_Aliased (Entity (P)) then
3392 -- A discriminant check on a selected component may be
3393 -- expanded into a dereference when removing side-effects.
3394 -- Recover the original node and its type, which may be
3397 elsif Nkind (P) = N_Explicit_Dereference
3398 and then not (Comes_From_Source (P))
3400 P := Original_Node (P);
3401 Prefix_Type := Etype (P);
3404 -- Check for prefix being an aliased component ???
3409 if Is_Access_Type (Prefix_Type)
3410 or else Nkind (P) = N_Explicit_Dereference
3416 Original_Record_Component (Entity (Selector_Name (Object)));
3418 -- As per AI-0017, the renaming is illegal in a generic body,
3419 -- even if the subtype is indefinite.
3421 if not Is_Constrained (Prefix_Type)
3422 and then (not Is_Indefinite_Subtype (Prefix_Type)
3424 (Is_Generic_Type (Prefix_Type)
3425 and then Ekind (Current_Scope) = E_Generic_Package
3426 and then In_Package_Body (Current_Scope)))
3428 and then (Is_Declared_Within_Variant (Comp)
3429 or else Has_Dependent_Constraint (Comp))
3430 and then not P_Aliased
3436 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3440 elsif Nkind (Object) = N_Indexed_Component
3441 or else Nkind (Object) = N_Slice
3443 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3445 -- A type conversion that Is_Variable is a view conversion:
3446 -- go back to the denoted object.
3448 elsif Nkind (Object) = N_Type_Conversion then
3450 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
3455 end Is_Dependent_Component_Of_Mutable_Object;
3457 ---------------------
3458 -- Is_Dereferenced --
3459 ---------------------
3461 function Is_Dereferenced (N : Node_Id) return Boolean is
3462 P : constant Node_Id := Parent (N);
3466 (Nkind (P) = N_Selected_Component
3468 Nkind (P) = N_Explicit_Dereference
3470 Nkind (P) = N_Indexed_Component
3472 Nkind (P) = N_Slice)
3473 and then Prefix (P) = N;
3474 end Is_Dereferenced;
3476 ----------------------
3477 -- Is_Descendent_Of --
3478 ----------------------
3480 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
3485 pragma Assert (Nkind (T1) in N_Entity);
3486 pragma Assert (Nkind (T2) in N_Entity);
3488 T := Base_Type (T1);
3490 -- Immediate return if the types match
3495 -- Comment needed here ???
3497 elsif Ekind (T) = E_Class_Wide_Type then
3498 return Etype (T) = T2;
3506 -- Done if we found the type we are looking for
3511 -- Done if no more derivations to check
3518 -- Following test catches error cases resulting from prev errors
3520 elsif No (Etyp) then
3523 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
3526 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
3530 T := Base_Type (Etyp);
3534 raise Program_Error;
3535 end Is_Descendent_Of;
3537 ------------------------------
3538 -- Is_Descendent_Of_Address --
3539 ------------------------------
3541 function Is_Descendent_Of_Address (T1 : Entity_Id) return Boolean is
3543 -- If Address has not been loaded, answer must be False
3545 if not RTU_Loaded (System) then
3548 -- Otherwise we can get the entity we are interested in without
3549 -- causing an unwanted dependency on System, and do the test.
3552 return Is_Descendent_Of (T1, Base_Type (RTE (RE_Address)));
3554 end Is_Descendent_Of_Address;
3560 function Is_False (U : Uint) return Boolean is
3565 ---------------------------
3566 -- Is_Fixed_Model_Number --
3567 ---------------------------
3569 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
3570 S : constant Ureal := Small_Value (T);
3571 M : Urealp.Save_Mark;
3576 R := (U = UR_Trunc (U / S) * S);
3579 end Is_Fixed_Model_Number;
3581 -------------------------------
3582 -- Is_Fully_Initialized_Type --
3583 -------------------------------
3585 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
3587 if Is_Scalar_Type (Typ) then
3590 elsif Is_Access_Type (Typ) then
3593 elsif Is_Array_Type (Typ) then
3594 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
3598 -- An interesting case, if we have a constrained type one of whose
3599 -- bounds is known to be null, then there are no elements to be
3600 -- initialized, so all the elements are initialized!
3602 if Is_Constrained (Typ) then
3605 Indx_Typ : Entity_Id;
3609 Indx := First_Index (Typ);
3610 while Present (Indx) loop
3612 if Etype (Indx) = Any_Type then
3615 -- If index is a range, use directly.
3617 elsif Nkind (Indx) = N_Range then
3618 Lbd := Low_Bound (Indx);
3619 Hbd := High_Bound (Indx);
3622 Indx_Typ := Etype (Indx);
3624 if Is_Private_Type (Indx_Typ) then
3625 Indx_Typ := Full_View (Indx_Typ);
3628 if No (Indx_Typ) then
3631 Lbd := Type_Low_Bound (Indx_Typ);
3632 Hbd := Type_High_Bound (Indx_Typ);
3636 if Compile_Time_Known_Value (Lbd)
3637 and then Compile_Time_Known_Value (Hbd)
3639 if Expr_Value (Hbd) < Expr_Value (Lbd) then
3649 -- If no null indexes, then type is not fully initialized
3655 elsif Is_Record_Type (Typ) then
3656 if Has_Discriminants (Typ)
3658 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
3659 and then Is_Fully_Initialized_Variant (Typ)
3664 -- Controlled records are considered to be fully initialized if
3665 -- there is a user defined Initialize routine. This may not be
3666 -- entirely correct, but as the spec notes, we are guessing here
3667 -- what is best from the point of view of issuing warnings.
3669 if Is_Controlled (Typ) then
3671 Utyp : constant Entity_Id := Underlying_Type (Typ);
3674 if Present (Utyp) then
3676 Init : constant Entity_Id :=
3678 (Underlying_Type (Typ), Name_Initialize));
3682 and then Comes_From_Source (Init)
3684 Is_Predefined_File_Name
3685 (File_Name (Get_Source_File_Index (Sloc (Init))))
3689 elsif Has_Null_Extension (Typ)
3691 Is_Fully_Initialized_Type
3692 (Etype (Base_Type (Typ)))
3701 -- Otherwise see if all record components are initialized
3707 Ent := First_Entity (Typ);
3709 while Present (Ent) loop
3710 if Chars (Ent) = Name_uController then
3713 elsif Ekind (Ent) = E_Component
3714 and then (No (Parent (Ent))
3715 or else No (Expression (Parent (Ent))))
3716 and then not Is_Fully_Initialized_Type (Etype (Ent))
3725 -- No uninitialized components, so type is fully initialized.
3726 -- Note that this catches the case of no components as well.
3730 elsif Is_Concurrent_Type (Typ) then
3733 elsif Is_Private_Type (Typ) then
3735 U : constant Entity_Id := Underlying_Type (Typ);
3741 return Is_Fully_Initialized_Type (U);
3748 end Is_Fully_Initialized_Type;
3750 ----------------------------------
3751 -- Is_Fully_Initialized_Variant --
3752 ----------------------------------
3754 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
3755 Loc : constant Source_Ptr := Sloc (Typ);
3756 Constraints : constant List_Id := New_List;
3757 Components : constant Elist_Id := New_Elmt_List;
3758 Comp_Elmt : Elmt_Id;
3760 Comp_List : Node_Id;
3762 Discr_Val : Node_Id;
3763 Report_Errors : Boolean;
3766 if Serious_Errors_Detected > 0 then
3770 if Is_Record_Type (Typ)
3771 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
3772 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
3774 Comp_List := Component_List (Type_Definition (Parent (Typ)));
3775 Discr := First_Discriminant (Typ);
3777 while Present (Discr) loop
3778 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
3779 Discr_Val := Expression (Parent (Discr));
3780 if not Is_OK_Static_Expression (Discr_Val) then
3783 Append_To (Constraints,
3784 Make_Component_Association (Loc,
3785 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
3786 Expression => New_Copy (Discr_Val)));
3793 Next_Discriminant (Discr);
3798 Comp_List => Comp_List,
3799 Governed_By => Constraints,
3801 Report_Errors => Report_Errors);
3803 -- Check that each component present is fully initialized.
3805 Comp_Elmt := First_Elmt (Components);
3807 while Present (Comp_Elmt) loop
3808 Comp_Id := Node (Comp_Elmt);
3810 if Ekind (Comp_Id) = E_Component
3811 and then (No (Parent (Comp_Id))
3812 or else No (Expression (Parent (Comp_Id))))
3813 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
3818 Next_Elmt (Comp_Elmt);
3823 elsif Is_Private_Type (Typ) then
3825 U : constant Entity_Id := Underlying_Type (Typ);
3831 return Is_Fully_Initialized_Variant (U);
3837 end Is_Fully_Initialized_Variant;
3839 ----------------------------
3840 -- Is_Inherited_Operation --
3841 ----------------------------
3843 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
3844 Kind : constant Node_Kind := Nkind (Parent (E));
3847 pragma Assert (Is_Overloadable (E));
3848 return Kind = N_Full_Type_Declaration
3849 or else Kind = N_Private_Extension_Declaration
3850 or else Kind = N_Subtype_Declaration
3851 or else (Ekind (E) = E_Enumeration_Literal
3852 and then Is_Derived_Type (Etype (E)));
3853 end Is_Inherited_Operation;
3855 -----------------------------
3856 -- Is_Library_Level_Entity --
3857 -----------------------------
3859 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
3861 -- The following is a small optimization, and it also handles
3862 -- properly discriminals, which in task bodies might appear in
3863 -- expressions before the corresponding procedure has been
3864 -- created, and which therefore do not have an assigned scope.
3866 if Ekind (E) in Formal_Kind then
3870 -- Normal test is simply that the enclosing dynamic scope is Standard
3872 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
3873 end Is_Library_Level_Entity;
3875 ---------------------------------
3876 -- Is_Local_Variable_Reference --
3877 ---------------------------------
3879 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
3881 if not Is_Entity_Name (Expr) then
3886 Ent : constant Entity_Id := Entity (Expr);
3887 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
3890 if Ekind (Ent) /= E_Variable
3892 Ekind (Ent) /= E_In_Out_Parameter
3897 return Present (Sub) and then Sub = Current_Subprogram;
3901 end Is_Local_Variable_Reference;
3907 function Is_Lvalue (N : Node_Id) return Boolean is
3908 P : constant Node_Id := Parent (N);
3913 -- Test left side of assignment
3915 when N_Assignment_Statement =>
3916 return N = Name (P);
3918 -- Test prefix of component or attribute
3920 when N_Attribute_Reference |
3922 N_Explicit_Dereference |
3923 N_Indexed_Component |
3925 N_Selected_Component |
3927 return N = Prefix (P);
3929 -- Test subprogram parameter (we really should check the
3930 -- parameter mode, but it is not worth the trouble)
3932 when N_Function_Call |
3933 N_Procedure_Call_Statement |
3934 N_Accept_Statement |
3935 N_Parameter_Association =>
3938 -- Test for appearing in a conversion that itself appears
3939 -- in an lvalue context, since this should be an lvalue.
3941 when N_Type_Conversion =>
3942 return Is_Lvalue (P);
3944 -- Test for appearence in object renaming declaration
3946 when N_Object_Renaming_Declaration =>
3949 -- All other references are definitely not Lvalues
3957 -------------------------
3958 -- Is_Object_Reference --
3959 -------------------------
3961 function Is_Object_Reference (N : Node_Id) return Boolean is
3963 if Is_Entity_Name (N) then
3964 return Is_Object (Entity (N));
3968 when N_Indexed_Component | N_Slice =>
3969 return Is_Object_Reference (Prefix (N));
3971 -- In Ada95, a function call is a constant object
3973 when N_Function_Call =>
3976 -- A reference to the stream attribute Input is a function call
3978 when N_Attribute_Reference =>
3979 return Attribute_Name (N) = Name_Input;
3981 when N_Selected_Component =>
3983 Is_Object_Reference (Selector_Name (N))
3984 and then Is_Object_Reference (Prefix (N));
3986 when N_Explicit_Dereference =>
3989 -- A view conversion of a tagged object is an object reference.
3991 when N_Type_Conversion =>
3992 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
3993 and then Is_Tagged_Type (Etype (Expression (N)))
3994 and then Is_Object_Reference (Expression (N));
3996 -- An unchecked type conversion is considered to be an object if
3997 -- the operand is an object (this construction arises only as a
3998 -- result of expansion activities).
4000 when N_Unchecked_Type_Conversion =>
4007 end Is_Object_Reference;
4009 -----------------------------------
4010 -- Is_OK_Variable_For_Out_Formal --
4011 -----------------------------------
4013 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
4015 Note_Possible_Modification (AV);
4017 -- We must reject parenthesized variable names. The check for
4018 -- Comes_From_Source is present because there are currently
4019 -- cases where the compiler violates this rule (e.g. passing
4020 -- a task object to its controlled Initialize routine).
4022 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
4025 -- A variable is always allowed
4027 elsif Is_Variable (AV) then
4030 -- Unchecked conversions are allowed only if they come from the
4031 -- generated code, which sometimes uses unchecked conversions for
4032 -- out parameters in cases where code generation is unaffected.
4033 -- We tell source unchecked conversions by seeing if they are
4034 -- rewrites of an original UC function call, or of an explicit
4035 -- conversion of a function call.
4037 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
4038 if Nkind (Original_Node (AV)) = N_Function_Call then
4041 elsif Comes_From_Source (AV)
4042 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
4050 -- Normal type conversions are allowed if argument is a variable
4052 elsif Nkind (AV) = N_Type_Conversion then
4053 if Is_Variable (Expression (AV))
4054 and then Paren_Count (Expression (AV)) = 0
4056 Note_Possible_Modification (Expression (AV));
4059 -- We also allow a non-parenthesized expression that raises
4060 -- constraint error if it rewrites what used to be a variable
4062 elsif Raises_Constraint_Error (Expression (AV))
4063 and then Paren_Count (Expression (AV)) = 0
4064 and then Is_Variable (Original_Node (Expression (AV)))
4068 -- Type conversion of something other than a variable
4074 -- If this node is rewritten, then test the original form, if that is
4075 -- OK, then we consider the rewritten node OK (for example, if the
4076 -- original node is a conversion, then Is_Variable will not be true
4077 -- but we still want to allow the conversion if it converts a variable).
4079 elsif Original_Node (AV) /= AV then
4080 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
4082 -- All other non-variables are rejected
4087 end Is_OK_Variable_For_Out_Formal;
4089 -----------------------------------
4090 -- Is_Partially_Initialized_Type --
4091 -----------------------------------
4093 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
4095 if Is_Scalar_Type (Typ) then
4098 elsif Is_Access_Type (Typ) then
4101 elsif Is_Array_Type (Typ) then
4103 -- If component type is partially initialized, so is array type
4105 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
4108 -- Otherwise we are only partially initialized if we are fully
4109 -- initialized (this is the empty array case, no point in us
4110 -- duplicating that code here).
4113 return Is_Fully_Initialized_Type (Typ);
4116 elsif Is_Record_Type (Typ) then
4118 -- A discriminated type is always partially initialized
4120 if Has_Discriminants (Typ) then
4123 -- A tagged type is always partially initialized
4125 elsif Is_Tagged_Type (Typ) then
4128 -- Case of non-discriminated record
4134 Component_Present : Boolean := False;
4135 -- Set True if at least one component is present. If no
4136 -- components are present, then record type is fully
4137 -- initialized (another odd case, like the null array).
4140 -- Loop through components
4142 Ent := First_Entity (Typ);
4143 while Present (Ent) loop
4144 if Ekind (Ent) = E_Component then
4145 Component_Present := True;
4147 -- If a component has an initialization expression then
4148 -- the enclosing record type is partially initialized
4150 if Present (Parent (Ent))
4151 and then Present (Expression (Parent (Ent)))
4155 -- If a component is of a type which is itself partially
4156 -- initialized, then the enclosing record type is also.
4158 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
4166 -- No initialized components found. If we found any components
4167 -- they were all uninitialized so the result is false.
4169 if Component_Present then
4172 -- But if we found no components, then all the components are
4173 -- initialized so we consider the type to be initialized.
4181 -- Concurrent types are always fully initialized
4183 elsif Is_Concurrent_Type (Typ) then
4186 -- For a private type, go to underlying type. If there is no underlying
4187 -- type then just assume this partially initialized. Not clear if this
4188 -- can happen in a non-error case, but no harm in testing for this.
4190 elsif Is_Private_Type (Typ) then
4192 U : constant Entity_Id := Underlying_Type (Typ);
4198 return Is_Partially_Initialized_Type (U);
4202 -- For any other type (are there any?) assume partially initialized
4207 end Is_Partially_Initialized_Type;
4209 -----------------------------
4210 -- Is_RCI_Pkg_Spec_Or_Body --
4211 -----------------------------
4213 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
4215 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
4216 -- Return True if the unit of Cunit is an RCI package declaration
4218 ---------------------------
4219 -- Is_RCI_Pkg_Decl_Cunit --
4220 ---------------------------
4222 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
4223 The_Unit : constant Node_Id := Unit (Cunit);
4226 if Nkind (The_Unit) /= N_Package_Declaration then
4229 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
4230 end Is_RCI_Pkg_Decl_Cunit;
4232 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
4235 return Is_RCI_Pkg_Decl_Cunit (Cunit)
4237 (Nkind (Unit (Cunit)) = N_Package_Body
4238 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
4239 end Is_RCI_Pkg_Spec_Or_Body;
4241 -----------------------------------------
4242 -- Is_Remote_Access_To_Class_Wide_Type --
4243 -----------------------------------------
4245 function Is_Remote_Access_To_Class_Wide_Type
4246 (E : Entity_Id) return Boolean
4250 function Comes_From_Limited_Private_Type_Declaration
4253 -- Check that the type is declared by a limited type declaration,
4254 -- or else is derived from a Remote_Type ancestor through private
4257 -------------------------------------------------
4258 -- Comes_From_Limited_Private_Type_Declaration --
4259 -------------------------------------------------
4261 function Comes_From_Limited_Private_Type_Declaration (E : in Entity_Id)
4264 N : constant Node_Id := Declaration_Node (E);
4266 if Nkind (N) = N_Private_Type_Declaration
4267 and then Limited_Present (N)
4272 if Nkind (N) = N_Private_Extension_Declaration then
4274 Comes_From_Limited_Private_Type_Declaration (Etype (E))
4276 (Is_Remote_Types (Etype (E))
4277 and then Is_Limited_Record (Etype (E))
4278 and then Has_Private_Declaration (Etype (E)));
4282 end Comes_From_Limited_Private_Type_Declaration;
4284 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
4287 if not (Is_Remote_Call_Interface (E)
4288 or else Is_Remote_Types (E))
4289 or else Ekind (E) /= E_General_Access_Type
4294 D := Designated_Type (E);
4296 if Ekind (D) /= E_Class_Wide_Type then
4300 return Comes_From_Limited_Private_Type_Declaration
4301 (Defining_Identifier (Parent (D)));
4302 end Is_Remote_Access_To_Class_Wide_Type;
4304 -----------------------------------------
4305 -- Is_Remote_Access_To_Subprogram_Type --
4306 -----------------------------------------
4308 function Is_Remote_Access_To_Subprogram_Type
4309 (E : Entity_Id) return Boolean
4312 return (Ekind (E) = E_Access_Subprogram_Type
4313 or else (Ekind (E) = E_Record_Type
4314 and then Present (Corresponding_Remote_Type (E))))
4315 and then (Is_Remote_Call_Interface (E)
4316 or else Is_Remote_Types (E));
4317 end Is_Remote_Access_To_Subprogram_Type;
4319 --------------------
4320 -- Is_Remote_Call --
4321 --------------------
4323 function Is_Remote_Call (N : Node_Id) return Boolean is
4325 if Nkind (N) /= N_Procedure_Call_Statement
4326 and then Nkind (N) /= N_Function_Call
4328 -- An entry call cannot be remote
4332 elsif Nkind (Name (N)) in N_Has_Entity
4333 and then Is_Remote_Call_Interface (Entity (Name (N)))
4335 -- A subprogram declared in the spec of a RCI package is remote
4339 elsif Nkind (Name (N)) = N_Explicit_Dereference
4340 and then Is_Remote_Access_To_Subprogram_Type
4341 (Etype (Prefix (Name (N))))
4343 -- The dereference of a RAS is a remote call
4347 elsif Present (Controlling_Argument (N))
4348 and then Is_Remote_Access_To_Class_Wide_Type
4349 (Etype (Controlling_Argument (N)))
4351 -- Any primitive operation call with a controlling argument of
4352 -- a RACW type is a remote call.
4357 -- All other calls are local calls
4362 ----------------------
4363 -- Is_Selector_Name --
4364 ----------------------
4366 function Is_Selector_Name (N : Node_Id) return Boolean is
4369 if not Is_List_Member (N) then
4371 P : constant Node_Id := Parent (N);
4372 K : constant Node_Kind := Nkind (P);
4376 (K = N_Expanded_Name or else
4377 K = N_Generic_Association or else
4378 K = N_Parameter_Association or else
4379 K = N_Selected_Component)
4380 and then Selector_Name (P) = N;
4385 L : constant List_Id := List_Containing (N);
4386 P : constant Node_Id := Parent (L);
4389 return (Nkind (P) = N_Discriminant_Association
4390 and then Selector_Names (P) = L)
4392 (Nkind (P) = N_Component_Association
4393 and then Choices (P) = L);
4396 end Is_Selector_Name;
4402 function Is_Statement (N : Node_Id) return Boolean is
4405 Nkind (N) in N_Statement_Other_Than_Procedure_Call
4406 or else Nkind (N) = N_Procedure_Call_Statement;
4413 function Is_Transfer (N : Node_Id) return Boolean is
4414 Kind : constant Node_Kind := Nkind (N);
4417 if Kind = N_Return_Statement
4419 Kind = N_Goto_Statement
4421 Kind = N_Raise_Statement
4423 Kind = N_Requeue_Statement
4427 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
4428 and then No (Condition (N))
4432 elsif Kind = N_Procedure_Call_Statement
4433 and then Is_Entity_Name (Name (N))
4434 and then Present (Entity (Name (N)))
4435 and then No_Return (Entity (Name (N)))
4439 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
4451 function Is_True (U : Uint) return Boolean is
4460 function Is_Variable (N : Node_Id) return Boolean is
4462 Orig_Node : constant Node_Id := Original_Node (N);
4463 -- We do the test on the original node, since this is basically a
4464 -- test of syntactic categories, so it must not be disturbed by
4465 -- whatever rewriting might have occurred. For example, an aggregate,
4466 -- which is certainly NOT a variable, could be turned into a variable
4469 function In_Protected_Function (E : Entity_Id) return Boolean;
4470 -- Within a protected function, the private components of the
4471 -- enclosing protected type are constants. A function nested within
4472 -- a (protected) procedure is not itself protected.
4474 function Is_Variable_Prefix (P : Node_Id) return Boolean;
4475 -- Prefixes can involve implicit dereferences, in which case we
4476 -- must test for the case of a reference of a constant access
4477 -- type, which can never be a variable.
4479 ---------------------------
4480 -- In_Protected_Function --
4481 ---------------------------
4483 function In_Protected_Function (E : Entity_Id) return Boolean is
4484 Prot : constant Entity_Id := Scope (E);
4488 if not Is_Protected_Type (Prot) then
4493 while Present (S) and then S /= Prot loop
4495 if Ekind (S) = E_Function
4496 and then Scope (S) = Prot
4506 end In_Protected_Function;
4508 ------------------------
4509 -- Is_Variable_Prefix --
4510 ------------------------
4512 function Is_Variable_Prefix (P : Node_Id) return Boolean is
4514 if Is_Access_Type (Etype (P)) then
4515 return not Is_Access_Constant (Root_Type (Etype (P)));
4517 return Is_Variable (P);
4519 end Is_Variable_Prefix;
4521 -- Start of processing for Is_Variable
4524 -- Definitely OK if Assignment_OK is set. Since this is something that
4525 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
4527 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
4530 -- Normally we go to the original node, but there is one exception
4531 -- where we use the rewritten node, namely when it is an explicit
4532 -- dereference. The generated code may rewrite a prefix which is an
4533 -- access type with an explicit dereference. The dereference is a
4534 -- variable, even though the original node may not be (since it could
4535 -- be a constant of the access type).
4537 elsif Nkind (N) = N_Explicit_Dereference
4538 and then Nkind (Orig_Node) /= N_Explicit_Dereference
4539 and then Is_Access_Type (Etype (Orig_Node))
4541 return Is_Variable_Prefix (Original_Node (Prefix (N)));
4543 -- All remaining checks use the original node
4545 elsif Is_Entity_Name (Orig_Node) then
4547 E : constant Entity_Id := Entity (Orig_Node);
4548 K : constant Entity_Kind := Ekind (E);
4551 return (K = E_Variable
4552 and then Nkind (Parent (E)) /= N_Exception_Handler)
4553 or else (K = E_Component
4554 and then not In_Protected_Function (E))
4555 or else K = E_Out_Parameter
4556 or else K = E_In_Out_Parameter
4557 or else K = E_Generic_In_Out_Parameter
4559 -- Current instance of type:
4561 or else (Is_Type (E) and then In_Open_Scopes (E))
4562 or else (Is_Incomplete_Or_Private_Type (E)
4563 and then In_Open_Scopes (Full_View (E)));
4567 case Nkind (Orig_Node) is
4568 when N_Indexed_Component | N_Slice =>
4569 return Is_Variable_Prefix (Prefix (Orig_Node));
4571 when N_Selected_Component =>
4572 return Is_Variable_Prefix (Prefix (Orig_Node))
4573 and then Is_Variable (Selector_Name (Orig_Node));
4575 -- For an explicit dereference, the type of the prefix cannot
4576 -- be an access to constant or an access to subprogram.
4578 when N_Explicit_Dereference =>
4580 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
4583 return Is_Access_Type (Typ)
4584 and then not Is_Access_Constant (Root_Type (Typ))
4585 and then Ekind (Typ) /= E_Access_Subprogram_Type;
4588 -- The type conversion is the case where we do not deal with the
4589 -- context dependent special case of an actual parameter. Thus
4590 -- the type conversion is only considered a variable for the
4591 -- purposes of this routine if the target type is tagged. However,
4592 -- a type conversion is considered to be a variable if it does not
4593 -- come from source (this deals for example with the conversions
4594 -- of expressions to their actual subtypes).
4596 when N_Type_Conversion =>
4597 return Is_Variable (Expression (Orig_Node))
4599 (not Comes_From_Source (Orig_Node)
4601 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
4603 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
4605 -- GNAT allows an unchecked type conversion as a variable. This
4606 -- only affects the generation of internal expanded code, since
4607 -- calls to instantiations of Unchecked_Conversion are never
4608 -- considered variables (since they are function calls).
4609 -- This is also true for expression actions.
4611 when N_Unchecked_Type_Conversion =>
4612 return Is_Variable (Expression (Orig_Node));
4620 ------------------------
4621 -- Is_Volatile_Object --
4622 ------------------------
4624 function Is_Volatile_Object (N : Node_Id) return Boolean is
4626 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
4627 -- Determines if given object has volatile components
4629 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
4630 -- If prefix is an implicit dereference, examine designated type.
4632 ------------------------
4633 -- Is_Volatile_Prefix --
4634 ------------------------
4636 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
4637 Typ : constant Entity_Id := Etype (N);
4640 if Is_Access_Type (Typ) then
4642 Dtyp : constant Entity_Id := Designated_Type (Typ);
4645 return Is_Volatile (Dtyp)
4646 or else Has_Volatile_Components (Dtyp);
4650 return Object_Has_Volatile_Components (N);
4652 end Is_Volatile_Prefix;
4654 ------------------------------------
4655 -- Object_Has_Volatile_Components --
4656 ------------------------------------
4658 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
4659 Typ : constant Entity_Id := Etype (N);
4662 if Is_Volatile (Typ)
4663 or else Has_Volatile_Components (Typ)
4667 elsif Is_Entity_Name (N)
4668 and then (Has_Volatile_Components (Entity (N))
4669 or else Is_Volatile (Entity (N)))
4673 elsif Nkind (N) = N_Indexed_Component
4674 or else Nkind (N) = N_Selected_Component
4676 return Is_Volatile_Prefix (Prefix (N));
4681 end Object_Has_Volatile_Components;
4683 -- Start of processing for Is_Volatile_Object
4686 if Is_Volatile (Etype (N))
4687 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
4691 elsif Nkind (N) = N_Indexed_Component
4692 or else Nkind (N) = N_Selected_Component
4694 return Is_Volatile_Prefix (Prefix (N));
4699 end Is_Volatile_Object;
4701 -------------------------
4702 -- Kill_Current_Values --
4703 -------------------------
4705 procedure Kill_Current_Values is
4708 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
4709 -- Clear current value for entity E and all entities chained to E
4711 ------------------------------------------
4712 -- Kill_Current_Values_For_Entity_Chain --
4713 ------------------------------------------
4715 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
4720 while Present (Ent) loop
4721 if Is_Object (Ent) then
4722 Set_Current_Value (Ent, Empty);
4724 if not Can_Never_Be_Null (Ent) then
4725 Set_Is_Known_Non_Null (Ent, False);
4731 end Kill_Current_Values_For_Entity_Chain;
4733 -- Start of processing for Kill_Current_Values
4736 -- Kill all saved checks, a special case of killing saved values
4740 -- Loop through relevant scopes, which includes the current scope and
4741 -- any parent scopes if the current scope is a block or a package.
4746 -- Clear current values of all entities in current scope
4748 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
4750 -- If scope is a package, also clear current values of all
4751 -- private entities in the scope.
4753 if Ekind (S) = E_Package
4755 Ekind (S) = E_Generic_Package
4757 Is_Concurrent_Type (S)
4759 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
4762 -- If this is a block or nested package, deal with parent
4764 if Ekind (S) = E_Block
4765 or else (Ekind (S) = E_Package
4766 and then not Is_Library_Level_Entity (S))
4772 end loop Scope_Loop;
4773 end Kill_Current_Values;
4775 --------------------------
4776 -- Kill_Size_Check_Code --
4777 --------------------------
4779 procedure Kill_Size_Check_Code (E : Entity_Id) is
4781 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4782 and then Present (Size_Check_Code (E))
4784 Remove (Size_Check_Code (E));
4785 Set_Size_Check_Code (E, Empty);
4787 end Kill_Size_Check_Code;
4789 -------------------------
4790 -- New_External_Entity --
4791 -------------------------
4793 function New_External_Entity
4794 (Kind : Entity_Kind;
4795 Scope_Id : Entity_Id;
4796 Sloc_Value : Source_Ptr;
4797 Related_Id : Entity_Id;
4799 Suffix_Index : Nat := 0;
4800 Prefix : Character := ' ') return Entity_Id
4802 N : constant Entity_Id :=
4803 Make_Defining_Identifier (Sloc_Value,
4805 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
4808 Set_Ekind (N, Kind);
4809 Set_Is_Internal (N, True);
4810 Append_Entity (N, Scope_Id);
4811 Set_Public_Status (N);
4813 if Kind in Type_Kind then
4814 Init_Size_Align (N);
4818 end New_External_Entity;
4820 -------------------------
4821 -- New_Internal_Entity --
4822 -------------------------
4824 function New_Internal_Entity
4825 (Kind : Entity_Kind;
4826 Scope_Id : Entity_Id;
4827 Sloc_Value : Source_Ptr;
4828 Id_Char : Character) return Entity_Id
4830 N : constant Entity_Id :=
4831 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
4834 Set_Ekind (N, Kind);
4835 Set_Is_Internal (N, True);
4836 Append_Entity (N, Scope_Id);
4838 if Kind in Type_Kind then
4839 Init_Size_Align (N);
4843 end New_Internal_Entity;
4849 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
4853 -- If we are pointing at a positional parameter, it is a member of
4854 -- a node list (the list of parameters), and the next parameter
4855 -- is the next node on the list, unless we hit a parameter
4856 -- association, in which case we shift to using the chain whose
4857 -- head is the First_Named_Actual in the parent, and then is
4858 -- threaded using the Next_Named_Actual of the Parameter_Association.
4859 -- All this fiddling is because the original node list is in the
4860 -- textual call order, and what we need is the declaration order.
4862 if Is_List_Member (Actual_Id) then
4863 N := Next (Actual_Id);
4865 if Nkind (N) = N_Parameter_Association then
4866 return First_Named_Actual (Parent (Actual_Id));
4872 return Next_Named_Actual (Parent (Actual_Id));
4876 procedure Next_Actual (Actual_Id : in out Node_Id) is
4878 Actual_Id := Next_Actual (Actual_Id);
4881 -----------------------
4882 -- Normalize_Actuals --
4883 -----------------------
4885 -- Chain actuals according to formals of subprogram. If there are
4886 -- no named associations, the chain is simply the list of Parameter
4887 -- Associations, since the order is the same as the declaration order.
4888 -- If there are named associations, then the First_Named_Actual field
4889 -- in the N_Procedure_Call_Statement node or N_Function_Call node
4890 -- points to the Parameter_Association node for the parameter that
4891 -- comes first in declaration order. The remaining named parameters
4892 -- are then chained in declaration order using Next_Named_Actual.
4894 -- This routine also verifies that the number of actuals is compatible
4895 -- with the number and default values of formals, but performs no type
4896 -- checking (type checking is done by the caller).
4898 -- If the matching succeeds, Success is set to True, and the caller
4899 -- proceeds with type-checking. If the match is unsuccessful, then
4900 -- Success is set to False, and the caller attempts a different
4901 -- interpretation, if there is one.
4903 -- If the flag Report is on, the call is not overloaded, and a failure
4904 -- to match can be reported here, rather than in the caller.
4906 procedure Normalize_Actuals
4910 Success : out Boolean)
4912 Actuals : constant List_Id := Parameter_Associations (N);
4913 Actual : Node_Id := Empty;
4915 Last : Node_Id := Empty;
4916 First_Named : Node_Id := Empty;
4919 Formals_To_Match : Integer := 0;
4920 Actuals_To_Match : Integer := 0;
4922 procedure Chain (A : Node_Id);
4923 -- Add named actual at the proper place in the list, using the
4924 -- Next_Named_Actual link.
4926 function Reporting return Boolean;
4927 -- Determines if an error is to be reported. To report an error, we
4928 -- need Report to be True, and also we do not report errors caused
4929 -- by calls to init procs that occur within other init procs. Such
4930 -- errors must always be cascaded errors, since if all the types are
4931 -- declared correctly, the compiler will certainly build decent calls!
4937 procedure Chain (A : Node_Id) is
4941 -- Call node points to first actual in list.
4943 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
4946 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
4950 Set_Next_Named_Actual (Last, Empty);
4957 function Reporting return Boolean is
4962 elsif not Within_Init_Proc then
4965 elsif Is_Init_Proc (Entity (Name (N))) then
4973 -- Start of processing for Normalize_Actuals
4976 if Is_Access_Type (S) then
4978 -- The name in the call is a function call that returns an access
4979 -- to subprogram. The designated type has the list of formals.
4981 Formal := First_Formal (Designated_Type (S));
4983 Formal := First_Formal (S);
4986 while Present (Formal) loop
4987 Formals_To_Match := Formals_To_Match + 1;
4988 Next_Formal (Formal);
4991 -- Find if there is a named association, and verify that no positional
4992 -- associations appear after named ones.
4994 if Present (Actuals) then
4995 Actual := First (Actuals);
4998 while Present (Actual)
4999 and then Nkind (Actual) /= N_Parameter_Association
5001 Actuals_To_Match := Actuals_To_Match + 1;
5005 if No (Actual) and Actuals_To_Match = Formals_To_Match then
5007 -- Most common case: positional notation, no defaults
5012 elsif Actuals_To_Match > Formals_To_Match then
5014 -- Too many actuals: will not work.
5017 if Is_Entity_Name (Name (N)) then
5018 Error_Msg_N ("too many arguments in call to&", Name (N));
5020 Error_Msg_N ("too many arguments in call", N);
5028 First_Named := Actual;
5030 while Present (Actual) loop
5031 if Nkind (Actual) /= N_Parameter_Association then
5033 ("positional parameters not allowed after named ones", Actual);
5038 Actuals_To_Match := Actuals_To_Match + 1;
5044 if Present (Actuals) then
5045 Actual := First (Actuals);
5048 Formal := First_Formal (S);
5049 while Present (Formal) loop
5051 -- Match the formals in order. If the corresponding actual
5052 -- is positional, nothing to do. Else scan the list of named
5053 -- actuals to find the one with the right name.
5056 and then Nkind (Actual) /= N_Parameter_Association
5059 Actuals_To_Match := Actuals_To_Match - 1;
5060 Formals_To_Match := Formals_To_Match - 1;
5063 -- For named parameters, search the list of actuals to find
5064 -- one that matches the next formal name.
5066 Actual := First_Named;
5069 while Present (Actual) loop
5070 if Chars (Selector_Name (Actual)) = Chars (Formal) then
5073 Actuals_To_Match := Actuals_To_Match - 1;
5074 Formals_To_Match := Formals_To_Match - 1;
5082 if Ekind (Formal) /= E_In_Parameter
5083 or else No (Default_Value (Formal))
5086 if (Comes_From_Source (S)
5087 or else Sloc (S) = Standard_Location)
5088 and then Is_Overloadable (S)
5092 (Nkind (Parent (N)) = N_Procedure_Call_Statement
5094 (Nkind (Parent (N)) = N_Function_Call
5096 Nkind (Parent (N)) = N_Parameter_Association))
5098 Set_Etype (N, Etype (S));
5100 Error_Msg_Name_1 := Chars (S);
5101 Error_Msg_Sloc := Sloc (S);
5103 ("missing argument for parameter & " &
5104 "in call to % declared #", N, Formal);
5107 elsif Is_Overloadable (S) then
5108 Error_Msg_Name_1 := Chars (S);
5110 -- Point to type derivation that generated the
5113 Error_Msg_Sloc := Sloc (Parent (S));
5116 ("missing argument for parameter & " &
5117 "in call to % (inherited) #", N, Formal);
5121 ("missing argument for parameter &", N, Formal);
5129 Formals_To_Match := Formals_To_Match - 1;
5134 Next_Formal (Formal);
5137 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
5144 -- Find some superfluous named actual that did not get
5145 -- attached to the list of associations.
5147 Actual := First (Actuals);
5149 while Present (Actual) loop
5150 if Nkind (Actual) = N_Parameter_Association
5151 and then Actual /= Last
5152 and then No (Next_Named_Actual (Actual))
5154 Error_Msg_N ("unmatched actual & in call",
5155 Selector_Name (Actual));
5166 end Normalize_Actuals;
5168 --------------------------------
5169 -- Note_Possible_Modification --
5170 --------------------------------
5172 procedure Note_Possible_Modification (N : Node_Id) is
5173 Modification_Comes_From_Source : constant Boolean :=
5174 Comes_From_Source (Parent (N));
5180 -- Loop to find referenced entity, if there is one
5187 if Is_Entity_Name (Exp) then
5188 Ent := Entity (Exp);
5190 elsif Nkind (Exp) = N_Explicit_Dereference then
5192 P : constant Node_Id := Prefix (Exp);
5195 if Nkind (P) = N_Selected_Component
5197 Entry_Formal (Entity (Selector_Name (P))))
5199 -- Case of a reference to an entry formal
5201 Ent := Entry_Formal (Entity (Selector_Name (P)));
5203 elsif Nkind (P) = N_Identifier
5204 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
5205 and then Present (Expression (Parent (Entity (P))))
5206 and then Nkind (Expression (Parent (Entity (P))))
5209 -- Case of a reference to a value on which
5210 -- side effects have been removed.
5212 Exp := Prefix (Expression (Parent (Entity (P))));
5220 elsif Nkind (Exp) = N_Type_Conversion
5221 or else Nkind (Exp) = N_Unchecked_Type_Conversion
5223 Exp := Expression (Exp);
5225 elsif Nkind (Exp) = N_Slice
5226 or else Nkind (Exp) = N_Indexed_Component
5227 or else Nkind (Exp) = N_Selected_Component
5229 Exp := Prefix (Exp);
5236 -- Now look for entity being referenced
5238 if Present (Ent) then
5240 if Is_Object (Ent) then
5241 if Comes_From_Source (Exp)
5242 or else Modification_Comes_From_Source
5244 Set_Never_Set_In_Source (Ent, False);
5247 Set_Is_True_Constant (Ent, False);
5248 Set_Current_Value (Ent, Empty);
5250 if not Can_Never_Be_Null (Ent) then
5251 Set_Is_Known_Non_Null (Ent, False);
5254 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
5255 and then Present (Renamed_Object (Ent))
5257 Exp := Renamed_Object (Ent);
5261 Generate_Reference (Ent, Exp, 'm');
5268 end Note_Possible_Modification;
5270 -------------------------
5271 -- Object_Access_Level --
5272 -------------------------
5274 function Object_Access_Level (Obj : Node_Id) return Uint is
5277 -- Returns the static accessibility level of the view denoted
5278 -- by Obj. Note that the value returned is the result of a
5279 -- call to Scope_Depth. Only scope depths associated with
5280 -- dynamic scopes can actually be returned. Since only
5281 -- relative levels matter for accessibility checking, the fact
5282 -- that the distance between successive levels of accessibility
5283 -- is not always one is immaterial (invariant: if level(E2) is
5284 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
5287 if Is_Entity_Name (Obj) then
5290 -- If E is a type then it denotes a current instance.
5291 -- For this case we add one to the normal accessibility
5292 -- level of the type to ensure that current instances
5293 -- are treated as always being deeper than than the level
5294 -- of any visible named access type (see 3.10.2(21)).
5297 return Type_Access_Level (E) + 1;
5299 elsif Present (Renamed_Object (E)) then
5300 return Object_Access_Level (Renamed_Object (E));
5302 -- Similarly, if E is a component of the current instance of a
5303 -- protected type, any instance of it is assumed to be at a deeper
5304 -- level than the type. For a protected object (whose type is an
5305 -- anonymous protected type) its components are at the same level
5306 -- as the type itself.
5308 elsif not Is_Overloadable (E)
5309 and then Ekind (Scope (E)) = E_Protected_Type
5310 and then Comes_From_Source (Scope (E))
5312 return Type_Access_Level (Scope (E)) + 1;
5315 return Scope_Depth (Enclosing_Dynamic_Scope (E));
5318 elsif Nkind (Obj) = N_Selected_Component then
5319 if Is_Access_Type (Etype (Prefix (Obj))) then
5320 return Type_Access_Level (Etype (Prefix (Obj)));
5322 return Object_Access_Level (Prefix (Obj));
5325 elsif Nkind (Obj) = N_Indexed_Component then
5326 if Is_Access_Type (Etype (Prefix (Obj))) then
5327 return Type_Access_Level (Etype (Prefix (Obj)));
5329 return Object_Access_Level (Prefix (Obj));
5332 elsif Nkind (Obj) = N_Explicit_Dereference then
5334 -- If the prefix is a selected access discriminant then
5335 -- we make a recursive call on the prefix, which will
5336 -- in turn check the level of the prefix object of
5337 -- the selected discriminant.
5339 if Nkind (Prefix (Obj)) = N_Selected_Component
5340 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
5342 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
5344 return Object_Access_Level (Prefix (Obj));
5346 return Type_Access_Level (Etype (Prefix (Obj)));
5349 elsif Nkind (Obj) = N_Type_Conversion
5350 or else Nkind (Obj) = N_Unchecked_Type_Conversion
5352 return Object_Access_Level (Expression (Obj));
5354 -- Function results are objects, so we get either the access level
5355 -- of the function or, in the case of an indirect call, the level of
5356 -- of the access-to-subprogram type.
5358 elsif Nkind (Obj) = N_Function_Call then
5359 if Is_Entity_Name (Name (Obj)) then
5360 return Subprogram_Access_Level (Entity (Name (Obj)));
5362 return Type_Access_Level (Etype (Prefix (Name (Obj))));
5365 -- For convenience we handle qualified expressions, even though
5366 -- they aren't technically object names.
5368 elsif Nkind (Obj) = N_Qualified_Expression then
5369 return Object_Access_Level (Expression (Obj));
5371 -- Otherwise return the scope level of Standard.
5372 -- (If there are cases that fall through
5373 -- to this point they will be treated as
5374 -- having global accessibility for now. ???)
5377 return Scope_Depth (Standard_Standard);
5379 end Object_Access_Level;
5381 -----------------------
5382 -- Private_Component --
5383 -----------------------
5385 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
5386 Ancestor : constant Entity_Id := Base_Type (Type_Id);
5388 function Trace_Components
5390 Check : Boolean) return Entity_Id;
5391 -- Recursive function that does the work, and checks against circular
5392 -- definition for each subcomponent type.
5394 ----------------------
5395 -- Trace_Components --
5396 ----------------------
5398 function Trace_Components
5400 Check : Boolean) return Entity_Id
5402 Btype : constant Entity_Id := Base_Type (T);
5403 Component : Entity_Id;
5405 Candidate : Entity_Id := Empty;
5408 if Check and then Btype = Ancestor then
5409 Error_Msg_N ("circular type definition", Type_Id);
5413 if Is_Private_Type (Btype)
5414 and then not Is_Generic_Type (Btype)
5416 if Present (Full_View (Btype))
5417 and then Is_Record_Type (Full_View (Btype))
5418 and then not Is_Frozen (Btype)
5420 -- To indicate that the ancestor depends on a private type,
5421 -- the current Btype is sufficient. However, to check for
5422 -- circular definition we must recurse on the full view.
5424 Candidate := Trace_Components (Full_View (Btype), True);
5426 if Candidate = Any_Type then
5436 elsif Is_Array_Type (Btype) then
5437 return Trace_Components (Component_Type (Btype), True);
5439 elsif Is_Record_Type (Btype) then
5440 Component := First_Entity (Btype);
5441 while Present (Component) loop
5443 -- skip anonymous types generated by constrained components.
5445 if not Is_Type (Component) then
5446 P := Trace_Components (Etype (Component), True);
5449 if P = Any_Type then
5457 Next_Entity (Component);
5465 end Trace_Components;
5467 -- Start of processing for Private_Component
5470 return Trace_Components (Type_Id, False);
5471 end Private_Component;
5473 -----------------------
5474 -- Process_End_Label --
5475 -----------------------
5477 procedure Process_End_Label
5485 Label_Ref : Boolean;
5486 -- Set True if reference to end label itself is required
5489 -- Gets set to the operator symbol or identifier that references
5490 -- the entity Ent. For the child unit case, this is the identifier
5491 -- from the designator. For other cases, this is simply Endl.
5493 procedure Generate_Parent_Ref (N : Node_Id);
5494 -- N is an identifier node that appears as a parent unit reference
5495 -- in the case where Ent is a child unit. This procedure generates
5496 -- an appropriate cross-reference entry.
5498 -------------------------
5499 -- Generate_Parent_Ref --
5500 -------------------------
5502 procedure Generate_Parent_Ref (N : Node_Id) is
5503 Parent_Ent : Entity_Id;
5506 -- Search up scope stack. The reason we do this is that normal
5507 -- visibility analysis would not work for two reasons. First in
5508 -- some subunit cases, the entry for the parent unit may not be
5509 -- visible, and in any case there can be a local entity that
5510 -- hides the scope entity.
5512 Parent_Ent := Current_Scope;
5513 while Present (Parent_Ent) loop
5514 if Chars (Parent_Ent) = Chars (N) then
5516 -- Generate the reference. We do NOT consider this as a
5517 -- reference for unreferenced symbol purposes, but we do
5518 -- force a cross-reference even if the end line does not
5519 -- come from source (the caller already generated the
5520 -- appropriate Typ for this situation).
5523 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
5524 Style.Check_Identifier (N, Parent_Ent);
5528 Parent_Ent := Scope (Parent_Ent);
5531 -- Fall through means entity was not found -- that's odd, but
5532 -- the appropriate thing is simply to ignore and not generate
5533 -- any cross-reference for this entry.
5536 end Generate_Parent_Ref;
5538 -- Start of processing for Process_End_Label
5541 -- If no node, ignore. This happens in some error situations,
5542 -- and also for some internally generated structures where no
5543 -- end label references are required in any case.
5549 -- Nothing to do if no End_Label, happens for internally generated
5550 -- constructs where we don't want an end label reference anyway.
5551 -- Also nothing to do if Endl is a string literal, which means
5552 -- there was some prior error (bad operator symbol)
5554 Endl := End_Label (N);
5556 if No (Endl) or else Nkind (Endl) = N_String_Literal then
5560 -- Reference node is not in extended main source unit
5562 if not In_Extended_Main_Source_Unit (N) then
5564 -- Generally we do not collect references except for the
5565 -- extended main source unit. The one exception is the 'e'
5566 -- entry for a package spec, where it is useful for a client
5567 -- to have the ending information to define scopes.
5575 -- For this case, we can ignore any parent references,
5576 -- but we need the package name itself for the 'e' entry.
5578 if Nkind (Endl) = N_Designator then
5579 Endl := Identifier (Endl);
5583 -- Reference is in extended main source unit
5588 -- For designator, generate references for the parent entries
5590 if Nkind (Endl) = N_Designator then
5592 -- Generate references for the prefix if the END line comes
5593 -- from source (otherwise we do not need these references)
5595 if Comes_From_Source (Endl) then
5597 while Nkind (Nam) = N_Selected_Component loop
5598 Generate_Parent_Ref (Selector_Name (Nam));
5599 Nam := Prefix (Nam);
5602 Generate_Parent_Ref (Nam);
5605 Endl := Identifier (Endl);
5609 -- If the end label is not for the given entity, then either we have
5610 -- some previous error, or this is a generic instantiation for which
5611 -- we do not need to make a cross-reference in this case anyway. In
5612 -- either case we simply ignore the call.
5614 if Chars (Ent) /= Chars (Endl) then
5618 -- If label was really there, then generate a normal reference
5619 -- and then adjust the location in the end label to point past
5620 -- the name (which should almost always be the semicolon).
5624 if Comes_From_Source (Endl) then
5626 -- If a label reference is required, then do the style check
5627 -- and generate an l-type cross-reference entry for the label
5631 Style.Check_Identifier (Endl, Ent);
5633 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
5636 -- Set the location to point past the label (normally this will
5637 -- mean the semicolon immediately following the label). This is
5638 -- done for the sake of the 'e' or 't' entry generated below.
5640 Get_Decoded_Name_String (Chars (Endl));
5641 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
5644 -- Now generate the e/t reference
5646 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
5648 -- Restore Sloc, in case modified above, since we have an identifier
5649 -- and the normal Sloc should be left set in the tree.
5651 Set_Sloc (Endl, Loc);
5652 end Process_End_Label;
5658 -- We do the conversion to get the value of the real string by using
5659 -- the scanner, see Sinput for details on use of the internal source
5660 -- buffer for scanning internal strings.
5662 function Real_Convert (S : String) return Node_Id is
5663 Save_Src : constant Source_Buffer_Ptr := Source;
5667 Source := Internal_Source_Ptr;
5670 for J in S'Range loop
5671 Source (Source_Ptr (J)) := S (J);
5674 Source (S'Length + 1) := EOF;
5676 if Source (Scan_Ptr) = '-' then
5678 Scan_Ptr := Scan_Ptr + 1;
5686 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
5693 ---------------------
5694 -- Rep_To_Pos_Flag --
5695 ---------------------
5697 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
5699 return New_Occurrence_Of
5700 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
5701 end Rep_To_Pos_Flag;
5703 --------------------
5704 -- Require_Entity --
5705 --------------------
5707 procedure Require_Entity (N : Node_Id) is
5709 if Is_Entity_Name (N) and then No (Entity (N)) then
5710 if Total_Errors_Detected /= 0 then
5711 Set_Entity (N, Any_Id);
5713 raise Program_Error;
5718 ------------------------------
5719 -- Requires_Transient_Scope --
5720 ------------------------------
5722 -- A transient scope is required when variable-sized temporaries are
5723 -- allocated in the primary or secondary stack, or when finalization
5724 -- actions must be generated before the next instruction.
5726 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
5727 Typ : constant Entity_Id := Underlying_Type (Id);
5729 -- Start of processing for Requires_Transient_Scope
5732 -- This is a private type which is not completed yet. This can only
5733 -- happen in a default expression (of a formal parameter or of a
5734 -- record component). Do not expand transient scope in this case
5739 -- Do not expand transient scope for non-existent procedure return
5741 elsif Typ = Standard_Void_Type then
5744 -- Elementary types do not require a transient scope
5746 elsif Is_Elementary_Type (Typ) then
5749 -- Generally, indefinite subtypes require a transient scope, since the
5750 -- back end cannot generate temporaries, since this is not a valid type
5751 -- for declaring an object. It might be possible to relax this in the
5752 -- future, e.g. by declaring the maximum possible space for the type.
5754 elsif Is_Indefinite_Subtype (Typ) then
5757 -- Functions returning tagged types may dispatch on result so their
5758 -- returned value is allocated on the secondary stack. Controlled
5759 -- type temporaries need finalization.
5761 elsif Is_Tagged_Type (Typ)
5762 or else Has_Controlled_Component (Typ)
5766 -- Record type. OK if none of the component types requires a transient
5767 -- scope. Note that we already know that this is a definite type (i.e.
5768 -- has discriminant defaults if it is a discriminated record).
5770 elsif Is_Record_Type (Typ) then
5774 Comp := First_Entity (Typ);
5775 while Present (Comp) loop
5776 if Requires_Transient_Scope (Etype (Comp)) then
5786 -- String literal types never require transient scope
5788 elsif Ekind (Typ) = E_String_Literal_Subtype then
5791 -- Array type. Note that we already know that this is a constrained
5792 -- array, since unconstrained arrays will fail the indefinite test.
5794 elsif Is_Array_Type (Typ) then
5796 -- If component type requires a transient scope, the array does too
5798 if Requires_Transient_Scope (Component_Type (Typ)) then
5801 -- Otherwise, we only need a transient scope if the size is not
5802 -- known at compile time.
5805 return not Size_Known_At_Compile_Time (Typ);
5808 -- All other cases do not require a transient scope
5813 end Requires_Transient_Scope;
5815 --------------------------
5816 -- Reset_Analyzed_Flags --
5817 --------------------------
5819 procedure Reset_Analyzed_Flags (N : Node_Id) is
5821 function Clear_Analyzed
5822 (N : Node_Id) return Traverse_Result;
5823 -- Function used to reset Analyzed flags in tree. Note that we do
5824 -- not reset Analyzed flags in entities, since there is no need to
5825 -- renalalyze entities, and indeed, it is wrong to do so, since it
5826 -- can result in generating auxiliary stuff more than once.
5828 --------------------
5829 -- Clear_Analyzed --
5830 --------------------
5832 function Clear_Analyzed
5833 (N : Node_Id) return Traverse_Result
5836 if not Has_Extension (N) then
5837 Set_Analyzed (N, False);
5843 function Reset_Analyzed is
5844 new Traverse_Func (Clear_Analyzed);
5846 Discard : Traverse_Result;
5847 pragma Warnings (Off, Discard);
5849 -- Start of processing for Reset_Analyzed_Flags
5852 Discard := Reset_Analyzed (N);
5853 end Reset_Analyzed_Flags;
5855 ---------------------------
5856 -- Safe_To_Capture_Value --
5857 ---------------------------
5859 function Safe_To_Capture_Value
5861 Ent : Entity_Id) return Boolean
5864 -- The only entities for which we track constant values are variables,
5865 -- out parameters and in out parameters, so check if we have this case.
5867 if Ekind (Ent) /= E_Variable
5869 Ekind (Ent) /= E_Out_Parameter
5871 Ekind (Ent) /= E_In_Out_Parameter
5876 -- Skip volatile and aliased variables, since funny things might
5877 -- be going on in these cases which we cannot necessarily track.
5879 if Treat_As_Volatile (Ent) or else Is_Aliased (Ent) then
5883 -- OK, all above conditions are met. We also require that the scope
5884 -- of the reference be the same as the scope of the entity, not
5885 -- counting packages and blocks.
5888 E_Scope : constant Entity_Id := Scope (Ent);
5889 R_Scope : Entity_Id;
5892 R_Scope := Current_Scope;
5893 while R_Scope /= Standard_Standard loop
5894 exit when R_Scope = E_Scope;
5896 if Ekind (R_Scope) /= E_Package
5898 Ekind (R_Scope) /= E_Block
5902 R_Scope := Scope (R_Scope);
5907 -- We also require that the reference does not appear in a context
5908 -- where it is not sure to be executed (i.e. a conditional context
5909 -- or an exception handler).
5916 while Present (P) loop
5917 if Nkind (P) = N_If_Statement
5919 Nkind (P) = N_Case_Statement
5921 Nkind (P) = N_Exception_Handler
5923 Nkind (P) = N_Selective_Accept
5925 Nkind (P) = N_Conditional_Entry_Call
5927 Nkind (P) = N_Timed_Entry_Call
5929 Nkind (P) = N_Asynchronous_Select
5938 -- OK, looks safe to set value
5941 end Safe_To_Capture_Value;
5947 function Same_Name (N1, N2 : Node_Id) return Boolean is
5948 K1 : constant Node_Kind := Nkind (N1);
5949 K2 : constant Node_Kind := Nkind (N2);
5952 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
5953 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
5955 return Chars (N1) = Chars (N2);
5957 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
5958 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
5960 return Same_Name (Selector_Name (N1), Selector_Name (N2))
5961 and then Same_Name (Prefix (N1), Prefix (N2));
5972 function Same_Type (T1, T2 : Entity_Id) return Boolean is
5977 elsif not Is_Constrained (T1)
5978 and then not Is_Constrained (T2)
5979 and then Base_Type (T1) = Base_Type (T2)
5983 -- For now don't bother with case of identical constraints, to be
5984 -- fiddled with later on perhaps (this is only used for optimization
5985 -- purposes, so it is not critical to do a best possible job)
5992 ------------------------
5993 -- Scope_Is_Transient --
5994 ------------------------
5996 function Scope_Is_Transient return Boolean is
5998 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
5999 end Scope_Is_Transient;
6005 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
6010 while Scop /= Standard_Standard loop
6011 Scop := Scope (Scop);
6013 if Scop = Scope2 then
6021 --------------------------
6022 -- Scope_Within_Or_Same --
6023 --------------------------
6025 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
6030 while Scop /= Standard_Standard loop
6031 if Scop = Scope2 then
6034 Scop := Scope (Scop);
6039 end Scope_Within_Or_Same;
6041 ------------------------
6042 -- Set_Current_Entity --
6043 ------------------------
6045 -- The given entity is to be set as the currently visible definition
6046 -- of its associated name (i.e. the Node_Id associated with its name).
6047 -- All we have to do is to get the name from the identifier, and
6048 -- then set the associated Node_Id to point to the given entity.
6050 procedure Set_Current_Entity (E : Entity_Id) is
6052 Set_Name_Entity_Id (Chars (E), E);
6053 end Set_Current_Entity;
6055 ---------------------------------
6056 -- Set_Entity_With_Style_Check --
6057 ---------------------------------
6059 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
6060 Val_Actual : Entity_Id;
6064 Set_Entity (N, Val);
6067 and then not Suppress_Style_Checks (Val)
6068 and then not In_Instance
6070 if Nkind (N) = N_Identifier then
6073 elsif Nkind (N) = N_Expanded_Name then
6074 Nod := Selector_Name (N);
6082 -- A special situation arises for derived operations, where we want
6083 -- to do the check against the parent (since the Sloc of the derived
6084 -- operation points to the derived type declaration itself).
6086 while not Comes_From_Source (Val_Actual)
6087 and then Nkind (Val_Actual) in N_Entity
6088 and then (Ekind (Val_Actual) = E_Enumeration_Literal
6089 or else Is_Subprogram (Val_Actual)
6090 or else Is_Generic_Subprogram (Val_Actual))
6091 and then Present (Alias (Val_Actual))
6093 Val_Actual := Alias (Val_Actual);
6096 -- Renaming declarations for generic actuals do not come from source,
6097 -- and have a different name from that of the entity they rename, so
6098 -- there is no style check to perform here.
6100 if Chars (Nod) = Chars (Val_Actual) then
6101 Style.Check_Identifier (Nod, Val_Actual);
6105 Set_Entity (N, Val);
6106 end Set_Entity_With_Style_Check;
6108 ------------------------
6109 -- Set_Name_Entity_Id --
6110 ------------------------
6112 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
6114 Set_Name_Table_Info (Id, Int (Val));
6115 end Set_Name_Entity_Id;
6117 ---------------------
6118 -- Set_Next_Actual --
6119 ---------------------
6121 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
6123 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
6124 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
6126 end Set_Next_Actual;
6128 -----------------------
6129 -- Set_Public_Status --
6130 -----------------------
6132 procedure Set_Public_Status (Id : Entity_Id) is
6133 S : constant Entity_Id := Current_Scope;
6136 if S = Standard_Standard
6137 or else (Is_Public (S)
6138 and then (Ekind (S) = E_Package
6139 or else Is_Record_Type (S)
6140 or else Ekind (S) = E_Void))
6144 -- The bounds of an entry family declaration can generate object
6145 -- declarations that are visible to the back-end, e.g. in the
6146 -- the declaration of a composite type that contains tasks.
6149 and then Is_Concurrent_Type (S)
6150 and then not Has_Completion (S)
6151 and then Nkind (Parent (Id)) = N_Object_Declaration
6155 end Set_Public_Status;
6157 ----------------------------
6158 -- Set_Scope_Is_Transient --
6159 ----------------------------
6161 procedure Set_Scope_Is_Transient (V : Boolean := True) is
6163 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
6164 end Set_Scope_Is_Transient;
6170 procedure Set_Size_Info (T1, T2 : Entity_Id) is
6172 -- We copy Esize, but not RM_Size, since in general RM_Size is
6173 -- subtype specific and does not get inherited by all subtypes.
6175 Set_Esize (T1, Esize (T2));
6176 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
6178 if Is_Discrete_Or_Fixed_Point_Type (T1)
6180 Is_Discrete_Or_Fixed_Point_Type (T2)
6182 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
6184 Set_Alignment (T1, Alignment (T2));
6187 --------------------
6188 -- Static_Integer --
6189 --------------------
6191 function Static_Integer (N : Node_Id) return Uint is
6193 Analyze_And_Resolve (N, Any_Integer);
6196 or else Error_Posted (N)
6197 or else Etype (N) = Any_Type
6202 if Is_Static_Expression (N) then
6203 if not Raises_Constraint_Error (N) then
6204 return Expr_Value (N);
6209 elsif Etype (N) = Any_Type then
6213 Flag_Non_Static_Expr
6214 ("static integer expression required here", N);
6219 --------------------------
6220 -- Statically_Different --
6221 --------------------------
6223 function Statically_Different (E1, E2 : Node_Id) return Boolean is
6224 R1 : constant Node_Id := Get_Referenced_Object (E1);
6225 R2 : constant Node_Id := Get_Referenced_Object (E2);
6228 return Is_Entity_Name (R1)
6229 and then Is_Entity_Name (R2)
6230 and then Entity (R1) /= Entity (R2)
6231 and then not Is_Formal (Entity (R1))
6232 and then not Is_Formal (Entity (R2));
6233 end Statically_Different;
6235 -----------------------------
6236 -- Subprogram_Access_Level --
6237 -----------------------------
6239 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
6241 if Present (Alias (Subp)) then
6242 return Subprogram_Access_Level (Alias (Subp));
6244 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
6246 end Subprogram_Access_Level;
6252 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
6254 if Debug_Flag_W then
6255 for J in 0 .. Scope_Stack.Last loop
6260 Write_Name (Chars (E));
6261 Write_Str (" line ");
6262 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
6267 -----------------------
6268 -- Transfer_Entities --
6269 -----------------------
6271 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
6272 Ent : Entity_Id := First_Entity (From);
6279 if (Last_Entity (To)) = Empty then
6280 Set_First_Entity (To, Ent);
6282 Set_Next_Entity (Last_Entity (To), Ent);
6285 Set_Last_Entity (To, Last_Entity (From));
6287 while Present (Ent) loop
6288 Set_Scope (Ent, To);
6290 if not Is_Public (Ent) then
6291 Set_Public_Status (Ent);
6294 and then Ekind (Ent) = E_Record_Subtype
6297 -- The components of the propagated Itype must be public
6304 Comp := First_Entity (Ent);
6306 while Present (Comp) loop
6307 Set_Is_Public (Comp);
6317 Set_First_Entity (From, Empty);
6318 Set_Last_Entity (From, Empty);
6319 end Transfer_Entities;
6321 -----------------------
6322 -- Type_Access_Level --
6323 -----------------------
6325 function Type_Access_Level (Typ : Entity_Id) return Uint is
6329 -- If the type is an anonymous access type we treat it as being
6330 -- declared at the library level to ensure that names such as
6331 -- X.all'access don't fail static accessibility checks.
6333 -- Ada 2005 (AI-230): In case of anonymous access types that are
6334 -- component_definition or discriminants of a nonlimited type,
6335 -- the level is the same as that of the enclosing component type.
6337 Btyp := Base_Type (Typ);
6338 if Ekind (Btyp) in Access_Kind then
6339 if Ekind (Btyp) = E_Anonymous_Access_Type
6340 and then not Is_Array_Type (Scope (Btyp)) -- Ada 2005 (AI-230)
6341 and then Ekind (Scope (Btyp)) /= E_Record_Type -- Ada 2005 (AI-230)
6343 return Scope_Depth (Standard_Standard);
6346 Btyp := Root_Type (Btyp);
6349 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
6350 end Type_Access_Level;
6352 --------------------------
6353 -- Unit_Declaration_Node --
6354 --------------------------
6356 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
6357 N : Node_Id := Parent (Unit_Id);
6360 -- Predefined operators do not have a full function declaration.
6362 if Ekind (Unit_Id) = E_Operator then
6366 while Nkind (N) /= N_Abstract_Subprogram_Declaration
6367 and then Nkind (N) /= N_Formal_Package_Declaration
6368 and then Nkind (N) /= N_Formal_Subprogram_Declaration
6369 and then Nkind (N) /= N_Function_Instantiation
6370 and then Nkind (N) /= N_Generic_Package_Declaration
6371 and then Nkind (N) /= N_Generic_Subprogram_Declaration
6372 and then Nkind (N) /= N_Package_Declaration
6373 and then Nkind (N) /= N_Package_Body
6374 and then Nkind (N) /= N_Package_Instantiation
6375 and then Nkind (N) /= N_Package_Renaming_Declaration
6376 and then Nkind (N) /= N_Procedure_Instantiation
6377 and then Nkind (N) /= N_Protected_Body
6378 and then Nkind (N) /= N_Subprogram_Declaration
6379 and then Nkind (N) /= N_Subprogram_Body
6380 and then Nkind (N) /= N_Subprogram_Body_Stub
6381 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
6382 and then Nkind (N) /= N_Task_Body
6383 and then Nkind (N) /= N_Task_Type_Declaration
6384 and then Nkind (N) not in N_Generic_Renaming_Declaration
6387 pragma Assert (Present (N));
6391 end Unit_Declaration_Node;
6393 ------------------------------
6394 -- Universal_Interpretation --
6395 ------------------------------
6397 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
6398 Index : Interp_Index;
6402 -- The argument may be a formal parameter of an operator or subprogram
6403 -- with multiple interpretations, or else an expression for an actual.
6405 if Nkind (Opnd) = N_Defining_Identifier
6406 or else not Is_Overloaded (Opnd)
6408 if Etype (Opnd) = Universal_Integer
6409 or else Etype (Opnd) = Universal_Real
6411 return Etype (Opnd);
6417 Get_First_Interp (Opnd, Index, It);
6419 while Present (It.Typ) loop
6421 if It.Typ = Universal_Integer
6422 or else It.Typ = Universal_Real
6427 Get_Next_Interp (Index, It);
6432 end Universal_Interpretation;
6434 ----------------------
6435 -- Within_Init_Proc --
6436 ----------------------
6438 function Within_Init_Proc return Boolean is
6443 while not Is_Overloadable (S) loop
6444 if S = Standard_Standard then
6451 return Is_Init_Proc (S);
6452 end Within_Init_Proc;
6458 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
6459 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
6460 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
6462 function Has_One_Matching_Field return Boolean;
6463 -- Determines whether Expec_Type is a record type with a single
6464 -- component or discriminant whose type matches the found type or
6465 -- is a one dimensional array whose component type matches the
6468 function Has_One_Matching_Field return Boolean is
6472 if Is_Array_Type (Expec_Type)
6473 and then Number_Dimensions (Expec_Type) = 1
6475 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
6479 elsif not Is_Record_Type (Expec_Type) then
6483 E := First_Entity (Expec_Type);
6489 elsif (Ekind (E) /= E_Discriminant
6490 and then Ekind (E) /= E_Component)
6491 or else (Chars (E) = Name_uTag
6492 or else Chars (E) = Name_uParent)
6501 if not Covers (Etype (E), Found_Type) then
6504 elsif Present (Next_Entity (E)) then
6511 end Has_One_Matching_Field;
6513 -- Start of processing for Wrong_Type
6516 -- Don't output message if either type is Any_Type, or if a message
6517 -- has already been posted for this node. We need to do the latter
6518 -- check explicitly (it is ordinarily done in Errout), because we
6519 -- are using ! to force the output of the error messages.
6521 if Expec_Type = Any_Type
6522 or else Found_Type = Any_Type
6523 or else Error_Posted (Expr)
6527 -- In an instance, there is an ongoing problem with completion of
6528 -- type derived from private types. Their structure is what Gigi
6529 -- expects, but the Etype is the parent type rather than the
6530 -- derived private type itself. Do not flag error in this case. The
6531 -- private completion is an entity without a parent, like an Itype.
6532 -- Similarly, full and partial views may be incorrect in the instance.
6533 -- There is no simple way to insure that it is consistent ???
6535 elsif In_Instance then
6537 if Etype (Etype (Expr)) = Etype (Expected_Type)
6539 (Has_Private_Declaration (Expected_Type)
6540 or else Has_Private_Declaration (Etype (Expr)))
6541 and then No (Parent (Expected_Type))
6547 -- An interesting special check. If the expression is parenthesized
6548 -- and its type corresponds to the type of the sole component of the
6549 -- expected record type, or to the component type of the expected one
6550 -- dimensional array type, then assume we have a bad aggregate attempt.
6552 if Nkind (Expr) in N_Subexpr
6553 and then Paren_Count (Expr) /= 0
6554 and then Has_One_Matching_Field
6556 Error_Msg_N ("positional aggregate cannot have one component", Expr);
6558 -- Another special check, if we are looking for a pool-specific access
6559 -- type and we found an E_Access_Attribute_Type, then we have the case
6560 -- of an Access attribute being used in a context which needs a pool-
6561 -- specific type, which is never allowed. The one extra check we make
6562 -- is that the expected designated type covers the Found_Type.
6564 elsif Is_Access_Type (Expec_Type)
6565 and then Ekind (Found_Type) = E_Access_Attribute_Type
6566 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
6567 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
6569 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
6571 Error_Msg_N ("result must be general access type!", Expr);
6572 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
6574 -- If the expected type is an anonymous access type, as for access
6575 -- parameters and discriminants, the error is on the designated types.
6577 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
6578 if Comes_From_Source (Expec_Type) then
6579 Error_Msg_NE ("expected}!", Expr, Expec_Type);
6582 ("expected an access type with designated}",
6583 Expr, Designated_Type (Expec_Type));
6586 if Is_Access_Type (Found_Type)
6587 and then not Comes_From_Source (Found_Type)
6590 ("found an access type with designated}!",
6591 Expr, Designated_Type (Found_Type));
6593 if From_With_Type (Found_Type) then
6594 Error_Msg_NE ("found incomplete}!", Expr, Found_Type);
6596 ("\possibly missing with_clause on&", Expr,
6597 Scope (Found_Type));
6599 Error_Msg_NE ("found}!", Expr, Found_Type);
6603 -- Normal case of one type found, some other type expected
6606 -- If the names of the two types are the same, see if some
6607 -- number of levels of qualification will help. Don't try
6608 -- more than three levels, and if we get to standard, it's
6609 -- no use (and probably represents an error in the compiler)
6610 -- Also do not bother with internal scope names.
6613 Expec_Scope : Entity_Id;
6614 Found_Scope : Entity_Id;
6617 Expec_Scope := Expec_Type;
6618 Found_Scope := Found_Type;
6620 for Levels in Int range 0 .. 3 loop
6621 if Chars (Expec_Scope) /= Chars (Found_Scope) then
6622 Error_Msg_Qual_Level := Levels;
6626 Expec_Scope := Scope (Expec_Scope);
6627 Found_Scope := Scope (Found_Scope);
6629 exit when Expec_Scope = Standard_Standard
6631 Found_Scope = Standard_Standard
6633 not Comes_From_Source (Expec_Scope)
6635 not Comes_From_Source (Found_Scope);
6639 Error_Msg_NE ("expected}!", Expr, Expec_Type);
6641 if Is_Entity_Name (Expr)
6642 and then Is_Package (Entity (Expr))
6644 Error_Msg_N ("found package name!", Expr);
6646 elsif Is_Entity_Name (Expr)
6648 (Ekind (Entity (Expr)) = E_Procedure
6650 Ekind (Entity (Expr)) = E_Generic_Procedure)
6652 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
6654 ("found procedure name, possibly missing Access attribute!",
6657 Error_Msg_N ("found procedure name instead of function!", Expr);
6660 elsif Nkind (Expr) = N_Function_Call
6661 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
6662 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
6663 and then No (Parameter_Associations (Expr))
6666 ("found function name, possibly missing Access attribute!",
6669 -- Catch common error: a prefix or infix operator which is not
6670 -- directly visible because the type isn't.
6672 elsif Nkind (Expr) in N_Op
6673 and then Is_Overloaded (Expr)
6674 and then not Is_Immediately_Visible (Expec_Type)
6675 and then not Is_Potentially_Use_Visible (Expec_Type)
6676 and then not In_Use (Expec_Type)
6677 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
6680 "operator of the type is not directly visible!", Expr);
6682 elsif Ekind (Found_Type) = E_Void
6683 and then Present (Parent (Found_Type))
6684 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
6686 Error_Msg_NE ("found premature usage of}!", Expr, Found_Type);
6689 Error_Msg_NE ("found}!", Expr, Found_Type);
6692 Error_Msg_Qual_Level := 0;