1 -----------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Debug; use Debug;
32 with Errout; use Errout;
33 with Elists; use Elists;
34 with Exp_Util; use Exp_Util;
35 with Freeze; use Freeze;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Output; use Output;
43 with Restrict; use Restrict;
44 with Scans; use Scans;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with Snames; use Snames;
54 with Stand; use Stand;
56 with Stringt; use Stringt;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
61 package body Sem_Util is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Component_Subtype
72 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
73 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
74 -- Loc is the source location, T is the original subtype.
76 --------------------------------
77 -- Add_Access_Type_To_Process --
78 --------------------------------
80 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id)
84 Ensure_Freeze_Node (E);
85 L := Access_Types_To_Process (Freeze_Node (E));
89 Set_Access_Types_To_Process (Freeze_Node (E), L);
93 end Add_Access_Type_To_Process;
95 -----------------------
96 -- Alignment_In_Bits --
97 -----------------------
99 function Alignment_In_Bits (E : Entity_Id) return Uint is
101 return Alignment (E) * System_Storage_Unit;
102 end Alignment_In_Bits;
104 -----------------------------------------
105 -- Apply_Compile_Time_Constraint_Error --
106 -----------------------------------------
108 procedure Apply_Compile_Time_Constraint_Error
111 Ent : Entity_Id := Empty;
112 Typ : Entity_Id := Empty;
113 Loc : Source_Ptr := No_Location;
114 Rep : Boolean := True)
116 Stat : constant Boolean := Is_Static_Expression (N);
126 if No (Compile_Time_Constraint_Error (N, Msg, Ent, Loc))
132 -- Now we replace the node by an N_Raise_Constraint_Error node
133 -- This does not need reanalyzing, so set it as analyzed now.
135 Rewrite (N, Make_Raise_Constraint_Error (Sloc (N)));
136 Set_Analyzed (N, True);
138 Set_Raises_Constraint_Error (N);
140 -- If the original expression was marked as static, the result is
141 -- still marked as static, but the Raises_Constraint_Error flag is
142 -- always set so that further static evaluation is not attempted.
145 Set_Is_Static_Expression (N);
147 end Apply_Compile_Time_Constraint_Error;
149 --------------------------
150 -- Build_Actual_Subtype --
151 --------------------------
153 function Build_Actual_Subtype
155 N : Node_Or_Entity_Id)
160 Loc : constant Source_Ptr := Sloc (N);
161 Constraints : List_Id;
167 Disc_Type : Entity_Id;
170 if Nkind (N) = N_Defining_Identifier then
171 Obj := New_Reference_To (N, Loc);
176 if Is_Array_Type (T) then
177 Constraints := New_List;
179 for J in 1 .. Number_Dimensions (T) loop
181 -- Build an array subtype declaration with the nominal
182 -- subtype and the bounds of the actual. Add the declaration
183 -- in front of the local declarations for the subprogram,for
184 -- analysis before any reference to the formal in the body.
187 Make_Attribute_Reference (Loc,
188 Prefix => Duplicate_Subexpr (Obj, Name_Req => True),
189 Attribute_Name => Name_First,
190 Expressions => New_List (
191 Make_Integer_Literal (Loc, J)));
194 Make_Attribute_Reference (Loc,
195 Prefix => Duplicate_Subexpr (Obj, Name_Req => True),
196 Attribute_Name => Name_Last,
197 Expressions => New_List (
198 Make_Integer_Literal (Loc, J)));
200 Append (Make_Range (Loc, Lo, Hi), Constraints);
203 -- If the type has unknown discriminants there is no constrained
206 elsif Has_Unknown_Discriminants (T) then
210 Constraints := New_List;
212 if Is_Private_Type (T) and then No (Full_View (T)) then
214 -- Type is a generic derived type. Inherit discriminants from
217 Disc_Type := Etype (Base_Type (T));
222 Discr := First_Discriminant (Disc_Type);
224 while Present (Discr) loop
225 Append_To (Constraints,
226 Make_Selected_Component (Loc,
227 Prefix => Duplicate_Subexpr (Obj),
228 Selector_Name => New_Occurrence_Of (Discr, Loc)));
229 Next_Discriminant (Discr);
234 Make_Defining_Identifier (Loc,
235 Chars => New_Internal_Name ('S'));
236 Set_Is_Internal (Subt);
239 Make_Subtype_Declaration (Loc,
240 Defining_Identifier => Subt,
241 Subtype_Indication =>
242 Make_Subtype_Indication (Loc,
243 Subtype_Mark => New_Reference_To (T, Loc),
245 Make_Index_Or_Discriminant_Constraint (Loc,
246 Constraints => Constraints)));
248 Mark_Rewrite_Insertion (Decl);
250 end Build_Actual_Subtype;
252 ---------------------------------------
253 -- Build_Actual_Subtype_Of_Component --
254 ---------------------------------------
256 function Build_Actual_Subtype_Of_Component
261 Loc : constant Source_Ptr := Sloc (N);
262 P : constant Node_Id := Prefix (N);
265 Indx_Type : Entity_Id;
267 Deaccessed_T : Entity_Id;
268 -- This is either a copy of T, or if T is an access type, then it is
269 -- the directly designated type of this access type.
271 function Build_Actual_Array_Constraint return List_Id;
272 -- If one or more of the bounds of the component depends on
273 -- discriminants, build actual constraint using the discriminants
276 function Build_Actual_Record_Constraint return List_Id;
277 -- Similar to previous one, for discriminated components constrained
278 -- by the discriminant of the enclosing object.
280 -----------------------------------
281 -- Build_Actual_Array_Constraint --
282 -----------------------------------
284 function Build_Actual_Array_Constraint return List_Id is
285 Constraints : List_Id := New_List;
293 Indx := First_Index (Deaccessed_T);
294 while Present (Indx) loop
295 Old_Lo := Type_Low_Bound (Etype (Indx));
296 Old_Hi := Type_High_Bound (Etype (Indx));
298 if Denotes_Discriminant (Old_Lo) then
300 Make_Selected_Component (Loc,
301 Prefix => New_Copy_Tree (P),
302 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
305 Lo := New_Copy_Tree (Old_Lo);
307 -- The new bound will be reanalyzed in the enclosing
308 -- declaration. For literal bounds that come from a type
309 -- declaration, the type of the context must be imposed, so
310 -- insure that analysis will take place. For non-universal
311 -- types this is not strictly necessary.
313 Set_Analyzed (Lo, False);
316 if Denotes_Discriminant (Old_Hi) then
318 Make_Selected_Component (Loc,
319 Prefix => New_Copy_Tree (P),
320 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
323 Hi := New_Copy_Tree (Old_Hi);
324 Set_Analyzed (Hi, False);
327 Append (Make_Range (Loc, Lo, Hi), Constraints);
332 end Build_Actual_Array_Constraint;
334 ------------------------------------
335 -- Build_Actual_Record_Constraint --
336 ------------------------------------
338 function Build_Actual_Record_Constraint return List_Id is
339 Constraints : List_Id := New_List;
344 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
345 while Present (D) loop
347 if Denotes_Discriminant (Node (D)) then
348 D_Val := Make_Selected_Component (Loc,
349 Prefix => New_Copy_Tree (P),
350 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
353 D_Val := New_Copy_Tree (Node (D));
356 Append (D_Val, Constraints);
361 end Build_Actual_Record_Constraint;
363 -- Start of processing for Build_Actual_Subtype_Of_Component
366 if Nkind (N) = N_Explicit_Dereference then
367 if Is_Composite_Type (T)
368 and then not Is_Constrained (T)
369 and then not (Is_Class_Wide_Type (T)
370 and then Is_Constrained (Root_Type (T)))
371 and then not Has_Unknown_Discriminants (T)
373 -- If the type of the dereference is already constrained, it
374 -- is an actual subtype.
376 if Is_Array_Type (Etype (N))
377 and then Is_Constrained (Etype (N))
381 Remove_Side_Effects (P);
382 return Build_Actual_Subtype (T, N);
389 if Ekind (T) = E_Access_Subtype then
390 Deaccessed_T := Designated_Type (T);
395 if Ekind (Deaccessed_T) = E_Array_Subtype then
397 Id := First_Index (Deaccessed_T);
398 Indx_Type := Underlying_Type (Etype (Id));
400 while Present (Id) loop
402 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
403 Denotes_Discriminant (Type_High_Bound (Indx_Type))
405 Remove_Side_Effects (P);
407 Build_Component_Subtype (
408 Build_Actual_Array_Constraint, Loc, Base_Type (T));
414 elsif Is_Composite_Type (Deaccessed_T)
415 and then Has_Discriminants (Deaccessed_T)
416 and then not Has_Unknown_Discriminants (Deaccessed_T)
418 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
419 while Present (D) loop
421 if Denotes_Discriminant (Node (D)) then
422 Remove_Side_Effects (P);
424 Build_Component_Subtype (
425 Build_Actual_Record_Constraint, Loc, Base_Type (T));
432 -- If none of the above, the actual and nominal subtypes are the same.
436 end Build_Actual_Subtype_Of_Component;
438 -----------------------------
439 -- Build_Component_Subtype --
440 -----------------------------
442 function Build_Component_Subtype
453 Make_Defining_Identifier (Loc,
454 Chars => New_Internal_Name ('S'));
455 Set_Is_Internal (Subt);
458 Make_Subtype_Declaration (Loc,
459 Defining_Identifier => Subt,
460 Subtype_Indication =>
461 Make_Subtype_Indication (Loc,
462 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
464 Make_Index_Or_Discriminant_Constraint (Loc,
467 Mark_Rewrite_Insertion (Decl);
469 end Build_Component_Subtype;
471 --------------------------------------------
472 -- Build_Discriminal_Subtype_Of_Component --
473 --------------------------------------------
475 function Build_Discriminal_Subtype_Of_Component
479 Loc : constant Source_Ptr := Sloc (T);
483 function Build_Discriminal_Array_Constraint return List_Id;
484 -- If one or more of the bounds of the component depends on
485 -- discriminants, build actual constraint using the discriminants
488 function Build_Discriminal_Record_Constraint return List_Id;
489 -- Similar to previous one, for discriminated components constrained
490 -- by the discriminant of the enclosing object.
492 ----------------------------------------
493 -- Build_Discriminal_Array_Constraint --
494 ----------------------------------------
496 function Build_Discriminal_Array_Constraint return List_Id is
497 Constraints : List_Id := New_List;
505 Indx := First_Index (T);
506 while Present (Indx) loop
507 Old_Lo := Type_Low_Bound (Etype (Indx));
508 Old_Hi := Type_High_Bound (Etype (Indx));
510 if Denotes_Discriminant (Old_Lo) then
511 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
514 Lo := New_Copy_Tree (Old_Lo);
517 if Denotes_Discriminant (Old_Hi) then
518 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
521 Hi := New_Copy_Tree (Old_Hi);
524 Append (Make_Range (Loc, Lo, Hi), Constraints);
529 end Build_Discriminal_Array_Constraint;
531 -----------------------------------------
532 -- Build_Discriminal_Record_Constraint --
533 -----------------------------------------
535 function Build_Discriminal_Record_Constraint return List_Id is
536 Constraints : List_Id := New_List;
541 D := First_Elmt (Discriminant_Constraint (T));
542 while Present (D) loop
544 if Denotes_Discriminant (Node (D)) then
546 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
549 D_Val := New_Copy_Tree (Node (D));
552 Append (D_Val, Constraints);
557 end Build_Discriminal_Record_Constraint;
559 -- Start of processing for Build_Discriminal_Subtype_Of_Component
562 if Ekind (T) = E_Array_Subtype then
564 Id := First_Index (T);
566 while Present (Id) loop
568 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
569 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
571 return Build_Component_Subtype
572 (Build_Discriminal_Array_Constraint, Loc, T);
578 elsif Ekind (T) = E_Record_Subtype
579 and then Has_Discriminants (T)
580 and then not Has_Unknown_Discriminants (T)
582 D := First_Elmt (Discriminant_Constraint (T));
583 while Present (D) loop
585 if Denotes_Discriminant (Node (D)) then
586 return Build_Component_Subtype
587 (Build_Discriminal_Record_Constraint, Loc, T);
594 -- If none of the above, the actual and nominal subtypes are the same.
598 end Build_Discriminal_Subtype_Of_Component;
600 ------------------------------
601 -- Build_Elaboration_Entity --
602 ------------------------------
604 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
605 Loc : constant Source_Ptr := Sloc (N);
606 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
609 Elab_Ent : Entity_Id;
612 -- Ignore if already constructed
614 if Present (Elaboration_Entity (Spec_Id)) then
618 -- Construct name of elaboration entity as xxx_E, where xxx
619 -- is the unit name with dots replaced by double underscore.
620 -- We have to manually construct this name, since it will
621 -- be elaborated in the outer scope, and thus will not have
622 -- the unit name automatically prepended.
624 Get_Name_String (Unit_Name (Unum));
626 -- Replace the %s by _E
628 Name_Buffer (Name_Len - 1 .. Name_Len) := "_E";
630 -- Replace dots by double underscore
633 while P < Name_Len - 2 loop
634 if Name_Buffer (P) = '.' then
635 Name_Buffer (P + 2 .. Name_Len + 1) :=
636 Name_Buffer (P + 1 .. Name_Len);
637 Name_Len := Name_Len + 1;
638 Name_Buffer (P) := '_';
639 Name_Buffer (P + 1) := '_';
646 -- Create elaboration flag
649 Make_Defining_Identifier (Loc, Chars => Name_Find);
650 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
652 if No (Declarations (Aux_Decls_Node (N))) then
653 Set_Declarations (Aux_Decls_Node (N), New_List);
657 Make_Object_Declaration (Loc,
658 Defining_Identifier => Elab_Ent,
660 New_Occurrence_Of (Standard_Boolean, Loc),
662 New_Occurrence_Of (Standard_False, Loc));
664 Append_To (Declarations (Aux_Decls_Node (N)), Decl);
667 -- Reset True_Constant indication, since we will indeed
668 -- assign a value to the variable in the binder main.
670 Set_Is_True_Constant (Elab_Ent, False);
672 -- We do not want any further qualification of the name (if we did
673 -- not do this, we would pick up the name of the generic package
674 -- in the case of a library level generic instantiation).
676 Set_Has_Qualified_Name (Elab_Ent);
677 Set_Has_Fully_Qualified_Name (Elab_Ent);
678 end Build_Elaboration_Entity;
680 --------------------------
681 -- Check_Fully_Declared --
682 --------------------------
684 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
686 if Ekind (T) = E_Incomplete_Type then
688 ("premature usage of incomplete}", N, First_Subtype (T));
690 elsif Has_Private_Component (T)
691 and then not Is_Generic_Type (Root_Type (T))
692 and then not In_Default_Expression
695 ("premature usage of incomplete}", N, First_Subtype (T));
697 end Check_Fully_Declared;
699 ------------------------------------------
700 -- Check_Potentially_Blocking_Operation --
701 ------------------------------------------
703 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
705 Loc : constant Source_Ptr := Sloc (N);
708 -- N is one of the potentially blocking operations listed in
709 -- 9.5.1 (8). When using the Ravenscar profile, raise Program_Error
710 -- before N if the context is a protected action. Otherwise, only issue
711 -- a warning, since some users are relying on blocking operations
712 -- inside protected objects.
713 -- Indirect blocking through a subprogram call
714 -- cannot be diagnosed statically without interprocedural analysis,
715 -- so we do not attempt to do it here.
717 S := Scope (Current_Scope);
719 while Present (S) and then S /= Standard_Standard loop
720 if Is_Protected_Type (S) then
721 if Restricted_Profile then
723 Make_Raise_Statement (Loc,
724 Name => New_Occurrence_Of (Standard_Program_Error, Loc)));
725 Error_Msg_N ("potentially blocking operation, " &
726 " Program Error will be raised at run time?", N);
730 ("potentially blocking operation in protected operation?", N);
738 end Check_Potentially_Blocking_Operation;
744 procedure Check_VMS (Construct : Node_Id) is
746 if not OpenVMS_On_Target then
748 ("this construct is allowed only in Open'V'M'S", Construct);
752 ----------------------------------
753 -- Collect_Primitive_Operations --
754 ----------------------------------
756 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
757 B_Type : constant Entity_Id := Base_Type (T);
758 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
759 B_Scope : Entity_Id := Scope (B_Type);
763 Formal_Derived : Boolean := False;
767 -- For tagged types, the primitive operations are collected as they
768 -- are declared, and held in an explicit list which is simply returned.
770 if Is_Tagged_Type (B_Type) then
771 return Primitive_Operations (B_Type);
773 -- An untagged generic type that is a derived type inherits the
774 -- primitive operations of its parent type. Other formal types only
775 -- have predefined operators, which are not explicitly represented.
777 elsif Is_Generic_Type (B_Type) then
778 if Nkind (B_Decl) = N_Formal_Type_Declaration
779 and then Nkind (Formal_Type_Definition (B_Decl))
780 = N_Formal_Derived_Type_Definition
782 Formal_Derived := True;
784 return New_Elmt_List;
788 Op_List := New_Elmt_List;
790 if B_Scope = Standard_Standard then
791 if B_Type = Standard_String then
792 Append_Elmt (Standard_Op_Concat, Op_List);
794 elsif B_Type = Standard_Wide_String then
795 Append_Elmt (Standard_Op_Concatw, Op_List);
801 elsif (Is_Package (B_Scope)
803 Parent (Declaration_Node (First_Subtype (T))))
806 or else Is_Derived_Type (B_Type)
808 -- The primitive operations appear after the base type, except
809 -- if the derivation happens within the private part of B_Scope
810 -- and the type is a private type, in which case both the type
811 -- and some primitive operations may appear before the base
812 -- type, and the list of candidates starts after the type.
814 if In_Open_Scopes (B_Scope)
815 and then Scope (T) = B_Scope
816 and then In_Private_Part (B_Scope)
818 Id := Next_Entity (T);
820 Id := Next_Entity (B_Type);
823 while Present (Id) loop
825 -- Note that generic formal subprograms are not
826 -- considered to be primitive operations and thus
827 -- are never inherited.
829 if Is_Overloadable (Id)
830 and then Nkind (Parent (Parent (Id)))
831 /= N_Formal_Subprogram_Declaration
835 if Base_Type (Etype (Id)) = B_Type then
838 Formal := First_Formal (Id);
839 while Present (Formal) loop
840 if Base_Type (Etype (Formal)) = B_Type then
844 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
846 (Designated_Type (Etype (Formal))) = B_Type
852 Next_Formal (Formal);
856 -- For a formal derived type, the only primitives are the
857 -- ones inherited from the parent type. Operations appearing
858 -- in the package declaration are not primitive for it.
861 and then (not Formal_Derived
862 or else Present (Alias (Id)))
864 Append_Elmt (Id, Op_List);
870 -- For a type declared in System, some of its operations
871 -- may appear in the target-specific extension to System.
874 and then Chars (B_Scope) = Name_System
875 and then Scope (B_Scope) = Standard_Standard
876 and then Present_System_Aux
878 B_Scope := System_Aux_Id;
879 Id := First_Entity (System_Aux_Id);
887 end Collect_Primitive_Operations;
889 -----------------------------------
890 -- Compile_Time_Constraint_Error --
891 -----------------------------------
893 function Compile_Time_Constraint_Error
896 Ent : Entity_Id := Empty;
897 Loc : Source_Ptr := No_Location)
900 Msgc : String (1 .. Msg'Length + 2);
907 -- A static constraint error in an instance body is not a fatal error.
908 -- we choose to inhibit the message altogether, because there is no
909 -- obvious node (for now) on which to post it. On the other hand the
910 -- offending node must be replaced with a constraint_error in any case.
912 -- No messages are generated if we already posted an error on this node
914 if not Error_Posted (N) then
916 -- Make all such messages unconditional
918 Msgc (1 .. Msg'Length) := Msg;
919 Msgc (Msg'Length + 1) := '!';
920 Msgl := Msg'Length + 1;
922 -- Message is a warning, even in Ada 95 case
924 if Msg (Msg'Length) = '?' then
927 -- In Ada 83, all messages are warnings. In the private part and
928 -- the body of an instance, constraint_checks are only warnings.
930 elsif Ada_83 and then Comes_From_Source (N) then
936 elsif In_Instance_Not_Visible then
941 Warn_On_Instance := True;
943 -- Otherwise we have a real error message (Ada 95 static case)
949 -- Should we generate a warning? The answer is not quite yes. The
950 -- very annoying exception occurs in the case of a short circuit
951 -- operator where the left operand is static and decisive. Climb
952 -- parents to see if that is the case we have here.
960 if (Nkind (P) = N_And_Then
961 and then Compile_Time_Known_Value (Left_Opnd (P))
962 and then Is_False (Expr_Value (Left_Opnd (P))))
963 or else (Nkind (P) = N_Or_Else
964 and then Compile_Time_Known_Value (Left_Opnd (P))
965 and then Is_True (Expr_Value (Left_Opnd (P))))
970 elsif Nkind (P) = N_Component_Association
971 and then Nkind (Parent (P)) = N_Aggregate
976 exit when Nkind (P) not in N_Subexpr;
981 if Present (Ent) then
982 Error_Msg_NE (Msgc (1 .. Msgl), N, Ent);
984 Error_Msg_NE (Msgc (1 .. Msgl), N, Etype (N));
988 if Inside_Init_Proc then
990 ("\& will be raised for objects of this type!?",
991 N, Standard_Constraint_Error);
994 ("\& will be raised at run time!?",
995 N, Standard_Constraint_Error);
999 ("\static expression raises&!",
1000 N, Standard_Constraint_Error);
1006 end Compile_Time_Constraint_Error;
1008 -----------------------
1009 -- Conditional_Delay --
1010 -----------------------
1012 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1014 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1015 Set_Has_Delayed_Freeze (New_Ent);
1017 end Conditional_Delay;
1019 --------------------
1020 -- Current_Entity --
1021 --------------------
1023 -- The currently visible definition for a given identifier is the
1024 -- one most chained at the start of the visibility chain, i.e. the
1025 -- one that is referenced by the Node_Id value of the name of the
1026 -- given identifier.
1028 function Current_Entity (N : Node_Id) return Entity_Id is
1030 return Get_Name_Entity_Id (Chars (N));
1033 -----------------------------
1034 -- Current_Entity_In_Scope --
1035 -----------------------------
1037 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1039 CS : constant Entity_Id := Current_Scope;
1041 Transient_Case : constant Boolean := Scope_Is_Transient;
1044 E := Get_Name_Entity_Id (Chars (N));
1047 and then Scope (E) /= CS
1048 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1054 end Current_Entity_In_Scope;
1060 function Current_Scope return Entity_Id is
1062 if Scope_Stack.Last = -1 then
1063 return Standard_Standard;
1066 C : constant Entity_Id :=
1067 Scope_Stack.Table (Scope_Stack.Last).Entity;
1072 return Standard_Standard;
1078 ------------------------
1079 -- Current_Subprogram --
1080 ------------------------
1082 function Current_Subprogram return Entity_Id is
1083 Scop : constant Entity_Id := Current_Scope;
1086 if Ekind (Scop) = E_Function
1088 Ekind (Scop) = E_Procedure
1090 Ekind (Scop) = E_Generic_Function
1092 Ekind (Scop) = E_Generic_Procedure
1097 return Enclosing_Subprogram (Scop);
1099 end Current_Subprogram;
1101 ---------------------
1102 -- Defining_Entity --
1103 ---------------------
1105 function Defining_Entity (N : Node_Id) return Entity_Id is
1106 K : constant Node_Kind := Nkind (N);
1111 N_Subprogram_Declaration |
1112 N_Abstract_Subprogram_Declaration |
1114 N_Package_Declaration |
1115 N_Subprogram_Renaming_Declaration |
1116 N_Subprogram_Body_Stub |
1117 N_Generic_Subprogram_Declaration |
1118 N_Generic_Package_Declaration |
1119 N_Formal_Subprogram_Declaration
1121 return Defining_Entity (Specification (N));
1124 N_Component_Declaration |
1125 N_Defining_Program_Unit_Name |
1126 N_Discriminant_Specification |
1128 N_Entry_Declaration |
1129 N_Entry_Index_Specification |
1130 N_Exception_Declaration |
1131 N_Exception_Renaming_Declaration |
1132 N_Formal_Object_Declaration |
1133 N_Formal_Package_Declaration |
1134 N_Formal_Type_Declaration |
1135 N_Full_Type_Declaration |
1136 N_Implicit_Label_Declaration |
1137 N_Incomplete_Type_Declaration |
1138 N_Loop_Parameter_Specification |
1139 N_Number_Declaration |
1140 N_Object_Declaration |
1141 N_Object_Renaming_Declaration |
1142 N_Package_Body_Stub |
1143 N_Parameter_Specification |
1144 N_Private_Extension_Declaration |
1145 N_Private_Type_Declaration |
1147 N_Protected_Body_Stub |
1148 N_Protected_Type_Declaration |
1149 N_Single_Protected_Declaration |
1150 N_Single_Task_Declaration |
1151 N_Subtype_Declaration |
1154 N_Task_Type_Declaration
1156 return Defining_Identifier (N);
1159 return Defining_Entity (Proper_Body (N));
1162 N_Function_Instantiation |
1163 N_Function_Specification |
1164 N_Generic_Function_Renaming_Declaration |
1165 N_Generic_Package_Renaming_Declaration |
1166 N_Generic_Procedure_Renaming_Declaration |
1168 N_Package_Instantiation |
1169 N_Package_Renaming_Declaration |
1170 N_Package_Specification |
1171 N_Procedure_Instantiation |
1172 N_Procedure_Specification
1175 Nam : constant Node_Id := Defining_Unit_Name (N);
1178 if Nkind (Nam) in N_Entity then
1181 return Defining_Identifier (Nam);
1185 when N_Block_Statement =>
1186 return Entity (Identifier (N));
1189 raise Program_Error;
1192 end Defining_Entity;
1194 --------------------------
1195 -- Denotes_Discriminant --
1196 --------------------------
1198 function Denotes_Discriminant (N : Node_Id) return Boolean is
1200 return Is_Entity_Name (N)
1201 and then Present (Entity (N))
1202 and then Ekind (Entity (N)) = E_Discriminant;
1203 end Denotes_Discriminant;
1205 -----------------------------
1206 -- Depends_On_Discriminant --
1207 -----------------------------
1209 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1214 Get_Index_Bounds (N, L, H);
1215 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1216 end Depends_On_Discriminant;
1218 -------------------------
1219 -- Designate_Same_Unit --
1220 -------------------------
1222 function Designate_Same_Unit
1227 K1 : Node_Kind := Nkind (Name1);
1228 K2 : Node_Kind := Nkind (Name2);
1230 function Prefix_Node (N : Node_Id) return Node_Id;
1231 -- Returns the parent unit name node of a defining program unit name
1232 -- or the prefix if N is a selected component or an expanded name.
1234 function Select_Node (N : Node_Id) return Node_Id;
1235 -- Returns the defining identifier node of a defining program unit
1236 -- name or the selector node if N is a selected component or an
1239 function Prefix_Node (N : Node_Id) return Node_Id is
1241 if Nkind (N) = N_Defining_Program_Unit_Name then
1249 function Select_Node (N : Node_Id) return Node_Id is
1251 if Nkind (N) = N_Defining_Program_Unit_Name then
1252 return Defining_Identifier (N);
1255 return Selector_Name (N);
1259 -- Start of processing for Designate_Next_Unit
1262 if (K1 = N_Identifier or else
1263 K1 = N_Defining_Identifier)
1265 (K2 = N_Identifier or else
1266 K2 = N_Defining_Identifier)
1268 return Chars (Name1) = Chars (Name2);
1271 (K1 = N_Expanded_Name or else
1272 K1 = N_Selected_Component or else
1273 K1 = N_Defining_Program_Unit_Name)
1275 (K2 = N_Expanded_Name or else
1276 K2 = N_Selected_Component or else
1277 K2 = N_Defining_Program_Unit_Name)
1280 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
1282 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
1287 end Designate_Same_Unit;
1289 ----------------------------
1290 -- Enclosing_Generic_Body --
1291 ----------------------------
1293 function Enclosing_Generic_Body
1304 while Present (P) loop
1305 if Nkind (P) = N_Package_Body
1306 or else Nkind (P) = N_Subprogram_Body
1308 Spec := Corresponding_Spec (P);
1310 if Present (Spec) then
1311 Decl := Unit_Declaration_Node (Spec);
1313 if Nkind (Decl) = N_Generic_Package_Declaration
1314 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1325 end Enclosing_Generic_Body;
1327 -------------------------------
1328 -- Enclosing_Lib_Unit_Entity --
1329 -------------------------------
1331 function Enclosing_Lib_Unit_Entity return Entity_Id is
1332 Unit_Entity : Entity_Id := Current_Scope;
1335 -- Look for enclosing library unit entity by following scope links.
1336 -- Equivalent to, but faster than indexing through the scope stack.
1338 while (Present (Scope (Unit_Entity))
1339 and then Scope (Unit_Entity) /= Standard_Standard)
1340 and not Is_Child_Unit (Unit_Entity)
1342 Unit_Entity := Scope (Unit_Entity);
1346 end Enclosing_Lib_Unit_Entity;
1348 -----------------------------
1349 -- Enclosing_Lib_Unit_Node --
1350 -----------------------------
1352 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
1353 Current_Node : Node_Id := N;
1356 while Present (Current_Node)
1357 and then Nkind (Current_Node) /= N_Compilation_Unit
1359 Current_Node := Parent (Current_Node);
1362 if Nkind (Current_Node) /= N_Compilation_Unit then
1366 return Current_Node;
1367 end Enclosing_Lib_Unit_Node;
1369 --------------------------
1370 -- Enclosing_Subprogram --
1371 --------------------------
1373 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
1374 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
1377 if Dynamic_Scope = Standard_Standard then
1380 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
1381 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
1383 elsif Ekind (Dynamic_Scope) = E_Block then
1384 return Enclosing_Subprogram (Dynamic_Scope);
1386 elsif Ekind (Dynamic_Scope) = E_Task_Type then
1387 return Get_Task_Body_Procedure (Dynamic_Scope);
1389 elsif Convention (Dynamic_Scope) = Convention_Protected then
1390 return Protected_Body_Subprogram (Dynamic_Scope);
1393 return Dynamic_Scope;
1395 end Enclosing_Subprogram;
1397 ------------------------
1398 -- Ensure_Freeze_Node --
1399 ------------------------
1401 procedure Ensure_Freeze_Node (E : Entity_Id) is
1405 if No (Freeze_Node (E)) then
1406 FN := Make_Freeze_Entity (Sloc (E));
1407 Set_Has_Delayed_Freeze (E);
1408 Set_Freeze_Node (E, FN);
1409 Set_Access_Types_To_Process (FN, No_Elist);
1410 Set_TSS_Elist (FN, No_Elist);
1413 end Ensure_Freeze_Node;
1419 procedure Enter_Name (Def_Id : Node_Id) is
1420 C : constant Entity_Id := Current_Entity (Def_Id);
1421 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
1422 S : constant Entity_Id := Current_Scope;
1425 Generate_Definition (Def_Id);
1427 -- Add new name to current scope declarations. Check for duplicate
1428 -- declaration, which may or may not be a genuine error.
1432 -- Case of previous entity entered because of a missing declaration
1433 -- or else a bad subtype indication. Best is to use the new entity,
1434 -- and make the previous one invisible.
1436 if Etype (E) = Any_Type then
1437 Set_Is_Immediately_Visible (E, False);
1439 -- Case of renaming declaration constructed for package instances.
1440 -- if there is an explicit declaration with the same identifier,
1441 -- the renaming is not immediately visible any longer, but remains
1442 -- visible through selected component notation.
1444 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
1445 and then not Comes_From_Source (E)
1447 Set_Is_Immediately_Visible (E, False);
1449 -- The new entity may be the package renaming, which has the same
1450 -- same name as a generic formal which has been seen already.
1452 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
1453 and then not Comes_From_Source (Def_Id)
1455 Set_Is_Immediately_Visible (E, False);
1457 -- For a fat pointer corresponding to a remote access to subprogram,
1458 -- we use the same identifier as the RAS type, so that the proper
1459 -- name appears in the stub. This type is only retrieved through
1460 -- the RAS type and never by visibility, and is not added to the
1461 -- visibility list (see below).
1463 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
1464 and then Present (Corresponding_Remote_Type (Def_Id))
1468 -- A controller component for a type extension overrides the
1469 -- inherited component.
1471 elsif Chars (E) = Name_uController then
1474 -- Case of an implicit operation or derived literal. The new entity
1475 -- hides the implicit one, which is removed from all visibility,
1476 -- i.e. the entity list of its scope, and homonym chain of its name.
1478 elsif (Is_Overloadable (E) and then Present (Alias (E)))
1479 or else Is_Internal (E)
1480 or else (Ekind (E) = E_Enumeration_Literal
1481 and then Is_Derived_Type (Etype (E)))
1485 Prev_Vis : Entity_Id;
1488 -- If E is an implicit declaration, it cannot be the first
1489 -- entity in the scope.
1491 Prev := First_Entity (Current_Scope);
1493 while Next_Entity (Prev) /= E loop
1497 Set_Next_Entity (Prev, Next_Entity (E));
1499 if No (Next_Entity (Prev)) then
1500 Set_Last_Entity (Current_Scope, Prev);
1503 if E = Current_Entity (E) then
1506 Prev_Vis := Current_Entity (E);
1507 while Homonym (Prev_Vis) /= E loop
1508 Prev_Vis := Homonym (Prev_Vis);
1512 if Present (Prev_Vis) then
1514 -- Skip E in the visibility chain
1516 Set_Homonym (Prev_Vis, Homonym (E));
1519 Set_Name_Entity_Id (Chars (E), Homonym (E));
1523 -- This section of code could use a comment ???
1525 elsif Present (Etype (E))
1526 and then Is_Concurrent_Type (Etype (E))
1531 -- In the body or private part of an instance, a type extension
1532 -- may introduce a component with the same name as that of an
1533 -- actual. The legality rule is not enforced, but the semantics
1534 -- of the full type with two components of the same name are not
1535 -- clear at this point ???
1537 elsif In_Instance_Not_Visible then
1540 -- When compiling a package body, some child units may have become
1541 -- visible. They cannot conflict with local entities that hide them.
1543 elsif Is_Child_Unit (E)
1544 and then In_Open_Scopes (Scope (E))
1545 and then not Is_Immediately_Visible (E)
1549 -- Conversely, with front-end inlining we may compile the parent
1550 -- body first, and a child unit subsequently. The context is now
1551 -- the parent spec, and body entities are not visible.
1553 elsif Is_Child_Unit (Def_Id)
1554 and then Is_Package_Body_Entity (E)
1555 and then not In_Package_Body (Current_Scope)
1559 -- Case of genuine duplicate declaration
1562 Error_Msg_Sloc := Sloc (E);
1564 -- If the previous declaration is an incomplete type declaration
1565 -- this may be an attempt to complete it with a private type.
1566 -- The following avoids confusing cascaded errors.
1568 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
1569 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
1572 ("incomplete type cannot be completed" &
1573 " with a private declaration",
1575 Set_Is_Immediately_Visible (E, False);
1576 Set_Full_View (E, Def_Id);
1578 elsif Ekind (E) = E_Discriminant
1579 and then Present (Scope (Def_Id))
1580 and then Scope (Def_Id) /= Current_Scope
1582 -- An inherited component of a record conflicts with
1583 -- a new discriminant. The discriminant is inserted first
1584 -- in the scope, but the error should be posted on it, not
1585 -- on the component.
1587 Error_Msg_Sloc := Sloc (Def_Id);
1588 Error_Msg_N ("& conflicts with declaration#", E);
1592 Error_Msg_N ("& conflicts with declaration#", Def_Id);
1594 -- Avoid cascaded messages with duplicate components in
1597 if Ekind (E) = E_Component
1598 or else Ekind (E) = E_Discriminant
1604 if Nkind (Parent (Parent (Def_Id)))
1605 = N_Generic_Subprogram_Declaration
1607 Defining_Entity (Specification (Parent (Parent (Def_Id))))
1609 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
1612 -- If entity is in standard, then we are in trouble, because
1613 -- it means that we have a library package with a duplicated
1614 -- name. That's hard to recover from, so abort!
1616 if S = Standard_Standard then
1617 raise Unrecoverable_Error;
1619 -- Otherwise we continue with the declaration. Having two
1620 -- identical declarations should not cause us too much trouble!
1628 -- If we fall through, declaration is OK , or OK enough to continue
1630 -- If Def_Id is a discriminant or a record component we are in the
1631 -- midst of inheriting components in a derived record definition.
1632 -- Preserve their Ekind and Etype.
1634 if Ekind (Def_Id) = E_Discriminant
1635 or else Ekind (Def_Id) = E_Component
1639 -- If a type is already set, leave it alone (happens whey a type
1640 -- declaration is reanalyzed following a call to the optimizer)
1642 elsif Present (Etype (Def_Id)) then
1645 -- Otherwise, the kind E_Void insures that premature uses of the entity
1646 -- will be detected. Any_Type insures that no cascaded errors will occur
1649 Set_Ekind (Def_Id, E_Void);
1650 Set_Etype (Def_Id, Any_Type);
1653 -- Inherited discriminants and components in derived record types are
1654 -- immediately visible. Itypes are not.
1656 if Ekind (Def_Id) = E_Discriminant
1657 or else Ekind (Def_Id) = E_Component
1658 or else (No (Corresponding_Remote_Type (Def_Id))
1659 and then not Is_Itype (Def_Id))
1661 Set_Is_Immediately_Visible (Def_Id);
1662 Set_Current_Entity (Def_Id);
1665 Set_Homonym (Def_Id, C);
1666 Append_Entity (Def_Id, S);
1667 Set_Public_Status (Def_Id);
1669 -- Warn if new entity hides an old one
1672 and then Length_Of_Name (Chars (C)) /= 1
1673 and then Present (C)
1674 and then Comes_From_Source (C)
1675 and then Comes_From_Source (Def_Id)
1676 and then In_Extended_Main_Source_Unit (Def_Id)
1678 Error_Msg_Sloc := Sloc (C);
1679 Error_Msg_N ("declaration hides &#?", Def_Id);
1684 -------------------------------------
1685 -- Find_Corresponding_Discriminant --
1686 -------------------------------------
1688 function Find_Corresponding_Discriminant
1693 Par_Disc : Entity_Id;
1694 Old_Disc : Entity_Id;
1695 New_Disc : Entity_Id;
1698 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
1699 Old_Disc := First_Discriminant (Scope (Par_Disc));
1701 if Is_Class_Wide_Type (Typ) then
1702 New_Disc := First_Discriminant (Root_Type (Typ));
1704 New_Disc := First_Discriminant (Typ);
1707 while Present (Old_Disc) and then Present (New_Disc) loop
1708 if Old_Disc = Par_Disc then
1711 Next_Discriminant (Old_Disc);
1712 Next_Discriminant (New_Disc);
1716 -- Should always find it
1718 raise Program_Error;
1719 end Find_Corresponding_Discriminant;
1725 function First_Actual (Node : Node_Id) return Node_Id is
1729 if No (Parameter_Associations (Node)) then
1733 N := First (Parameter_Associations (Node));
1735 if Nkind (N) = N_Parameter_Association then
1736 return First_Named_Actual (Node);
1742 -------------------------
1743 -- Full_Qualified_Name --
1744 -------------------------
1746 function Full_Qualified_Name (E : Entity_Id) return String_Id is
1750 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
1751 -- Compute recursively the qualified name without NUL at the end.
1753 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
1754 Ent : Entity_Id := E;
1755 Parent_Name : String_Id := No_String;
1758 -- Deals properly with child units
1760 if Nkind (Ent) = N_Defining_Program_Unit_Name then
1761 Ent := Defining_Identifier (Ent);
1764 -- Compute recursively the qualification. Only "Standard" has no
1767 if Present (Scope (Scope (Ent))) then
1768 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
1771 -- Every entity should have a name except some expanded blocks
1772 -- don't bother about those.
1774 if Chars (Ent) = No_Name then
1778 -- Add a period between Name and qualification
1780 if Parent_Name /= No_String then
1781 Start_String (Parent_Name);
1782 Store_String_Char (Get_Char_Code ('.'));
1788 -- Generates the entity name in upper case
1790 Get_Name_String (Chars (Ent));
1792 Store_String_Chars (Name_Buffer (1 .. Name_Len));
1794 end Internal_Full_Qualified_Name;
1797 Res := Internal_Full_Qualified_Name (E);
1798 Store_String_Char (Get_Char_Code (ASCII.nul));
1800 end Full_Qualified_Name;
1802 -----------------------
1803 -- Gather_Components --
1804 -----------------------
1806 procedure Gather_Components
1808 Comp_List : Node_Id;
1809 Governed_By : List_Id;
1811 Report_Errors : out Boolean)
1815 Discrete_Choice : Node_Id;
1816 Comp_Item : Node_Id;
1818 Discrim : Entity_Id;
1819 Discrim_Name : Node_Id;
1820 Discrim_Value : Node_Id;
1823 Report_Errors := False;
1825 if No (Comp_List) or else Null_Present (Comp_List) then
1828 elsif Present (Component_Items (Comp_List)) then
1829 Comp_Item := First (Component_Items (Comp_List));
1835 while Present (Comp_Item) loop
1837 -- Skip the tag of a tagged record, as well as all items
1838 -- that are not user components (anonymous types, rep clauses,
1839 -- Parent field, controller field).
1841 if Nkind (Comp_Item) = N_Component_Declaration
1842 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uTag
1843 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uParent
1844 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uController
1846 Append_Elmt (Defining_Identifier (Comp_Item), Into);
1852 if No (Variant_Part (Comp_List)) then
1855 Discrim_Name := Name (Variant_Part (Comp_List));
1856 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
1859 -- Look for the discriminant that governs this variant part.
1860 -- The discriminant *must* be in the Governed_By List
1862 Assoc := First (Governed_By);
1863 Find_Constraint : loop
1864 Discrim := First (Choices (Assoc));
1865 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
1866 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
1868 Chars (Corresponding_Discriminant (Entity (Discrim)))
1869 = Chars (Discrim_Name))
1870 or else Chars (Original_Record_Component (Entity (Discrim)))
1871 = Chars (Discrim_Name);
1873 if No (Next (Assoc)) then
1874 if not Is_Constrained (Typ)
1875 and then Is_Derived_Type (Typ)
1876 and then Present (Girder_Constraint (Typ))
1879 -- If the type is a tagged type with inherited discriminants,
1880 -- use the girder constraint on the parent in order to find
1881 -- the values of discriminants that are otherwise hidden by an
1882 -- explicit constraint. Renamed discriminants are handled in
1890 D := First_Discriminant (Etype (Typ));
1891 C := First_Elmt (Girder_Constraint (Typ));
1894 and then Present (C)
1896 if Chars (Discrim_Name) = Chars (D) then
1898 Make_Component_Association (Sloc (Typ),
1900 (New_Occurrence_Of (D, Sloc (Typ))),
1901 Duplicate_Subexpr (Node (C)));
1902 exit Find_Constraint;
1905 D := Next_Discriminant (D);
1912 if No (Next (Assoc)) then
1913 Error_Msg_NE (" missing value for discriminant&",
1914 First (Governed_By), Discrim_Name);
1915 Report_Errors := True;
1920 end loop Find_Constraint;
1922 Discrim_Value := Expression (Assoc);
1924 if not Is_OK_Static_Expression (Discrim_Value) then
1926 ("value for discriminant & must be static", Discrim_Value, Discrim);
1927 Report_Errors := True;
1931 Search_For_Discriminant_Value : declare
1937 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
1940 Find_Discrete_Value : while Present (Variant) loop
1941 Discrete_Choice := First (Discrete_Choices (Variant));
1942 while Present (Discrete_Choice) loop
1944 exit Find_Discrete_Value when
1945 Nkind (Discrete_Choice) = N_Others_Choice;
1947 Get_Index_Bounds (Discrete_Choice, Low, High);
1949 UI_Low := Expr_Value (Low);
1950 UI_High := Expr_Value (High);
1952 exit Find_Discrete_Value when
1953 UI_Low <= UI_Discrim_Value
1955 UI_High >= UI_Discrim_Value;
1957 Next (Discrete_Choice);
1960 Next_Non_Pragma (Variant);
1961 end loop Find_Discrete_Value;
1962 end Search_For_Discriminant_Value;
1964 if No (Variant) then
1966 ("value of discriminant & is out of range", Discrim_Value, Discrim);
1967 Report_Errors := True;
1971 -- If we have found the corresponding choice, recursively add its
1972 -- components to the Into list.
1974 Gather_Components (Empty,
1975 Component_List (Variant), Governed_By, Into, Report_Errors);
1976 end Gather_Components;
1978 ------------------------
1979 -- Get_Actual_Subtype --
1980 ------------------------
1982 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
1983 Typ : constant Entity_Id := Etype (N);
1984 Utyp : Entity_Id := Underlying_Type (Typ);
1989 if not Present (Utyp) then
1993 -- If what we have is an identifier that references a subprogram
1994 -- formal, or a variable or constant object, then we get the actual
1995 -- subtype from the referenced entity if one has been built.
1997 if Nkind (N) = N_Identifier
1999 (Is_Formal (Entity (N))
2000 or else Ekind (Entity (N)) = E_Constant
2001 or else Ekind (Entity (N)) = E_Variable)
2002 and then Present (Actual_Subtype (Entity (N)))
2004 return Actual_Subtype (Entity (N));
2006 -- Actual subtype of unchecked union is always itself. We never need
2007 -- the "real" actual subtype. If we did, we couldn't get it anyway
2008 -- because the discriminant is not available. The restrictions on
2009 -- Unchecked_Union are designed to make sure that this is OK.
2011 elsif Is_Unchecked_Union (Utyp) then
2014 -- Here for the unconstrained case, we must find actual subtype
2015 -- No actual subtype is available, so we must build it on the fly.
2017 -- Checking the type, not the underlying type, for constrainedness
2018 -- seems to be necessary. Maybe all the tests should be on the type???
2020 elsif (not Is_Constrained (Typ))
2021 and then (Is_Array_Type (Utyp)
2022 or else (Is_Record_Type (Utyp)
2023 and then Has_Discriminants (Utyp)))
2024 and then not Has_Unknown_Discriminants (Utyp)
2025 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
2027 -- Nothing to do if in default expression
2029 if In_Default_Expression then
2032 -- Else build the actual subtype
2035 Decl := Build_Actual_Subtype (Typ, N);
2036 Atyp := Defining_Identifier (Decl);
2038 -- If Build_Actual_Subtype generated a new declaration then use it
2042 -- The actual subtype is an Itype, so analyze the declaration,
2043 -- but do not attach it to the tree, to get the type defined.
2045 Set_Parent (Decl, N);
2046 Set_Is_Itype (Atyp);
2047 Analyze (Decl, Suppress => All_Checks);
2048 Set_Associated_Node_For_Itype (Atyp, N);
2049 Set_Has_Delayed_Freeze (Atyp, False);
2051 -- We need to freeze the actual subtype immediately. This is
2052 -- needed, because otherwise this Itype will not get frozen
2053 -- at all, and it is always safe to freeze on creation because
2054 -- any associated types must be frozen at this point.
2056 Freeze_Itype (Atyp, N);
2059 -- Otherwise we did not build a declaration, so return original
2066 -- For all remaining cases, the actual subtype is the same as
2067 -- the nominal type.
2072 end Get_Actual_Subtype;
2074 -------------------------------------
2075 -- Get_Actual_Subtype_If_Available --
2076 -------------------------------------
2078 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
2079 Typ : constant Entity_Id := Etype (N);
2082 -- If what we have is an identifier that references a subprogram
2083 -- formal, or a variable or constant object, then we get the actual
2084 -- subtype from the referenced entity if one has been built.
2086 if Nkind (N) = N_Identifier
2088 (Is_Formal (Entity (N))
2089 or else Ekind (Entity (N)) = E_Constant
2090 or else Ekind (Entity (N)) = E_Variable)
2091 and then Present (Actual_Subtype (Entity (N)))
2093 return Actual_Subtype (Entity (N));
2095 -- Otherwise the Etype of N is returned unchanged
2100 end Get_Actual_Subtype_If_Available;
2102 -------------------------------
2103 -- Get_Default_External_Name --
2104 -------------------------------
2106 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
2108 Get_Decoded_Name_String (Chars (E));
2110 if Opt.External_Name_Imp_Casing = Uppercase then
2111 Set_Casing (All_Upper_Case);
2113 Set_Casing (All_Lower_Case);
2117 Make_String_Literal (Sloc (E),
2118 Strval => String_From_Name_Buffer);
2120 end Get_Default_External_Name;
2122 ---------------------------
2123 -- Get_Enum_Lit_From_Pos --
2124 ---------------------------
2126 function Get_Enum_Lit_From_Pos
2133 P : constant Nat := UI_To_Int (Pos);
2136 -- In the case where the literal is either of type Wide_Character
2137 -- or Character or of a type derived from them, there needs to be
2138 -- some special handling since there is no explicit chain of
2139 -- literals to search. Instead, an N_Character_Literal node is
2140 -- created with the appropriate Char_Code and Chars fields.
2142 if Root_Type (T) = Standard_Character
2143 or else Root_Type (T) = Standard_Wide_Character
2145 Set_Character_Literal_Name (Char_Code (P));
2147 Make_Character_Literal (Loc,
2149 Char_Literal_Value => Char_Code (P));
2151 -- For all other cases, we have a complete table of literals, and
2152 -- we simply iterate through the chain of literal until the one
2153 -- with the desired position value is found.
2157 Lit := First_Literal (Base_Type (T));
2158 for J in 1 .. P loop
2162 return New_Occurrence_Of (Lit, Loc);
2164 end Get_Enum_Lit_From_Pos;
2166 ----------------------
2167 -- Get_Index_Bounds --
2168 ----------------------
2170 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
2171 Kind : constant Node_Kind := Nkind (N);
2175 if Kind = N_Range then
2177 H := High_Bound (N);
2179 elsif Kind = N_Subtype_Indication then
2180 R := Range_Expression (Constraint (N));
2188 L := Low_Bound (Range_Expression (Constraint (N)));
2189 H := High_Bound (Range_Expression (Constraint (N)));
2192 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
2193 if Error_Posted (Scalar_Range (Entity (N))) then
2197 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
2198 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
2201 L := Low_Bound (Scalar_Range (Entity (N)));
2202 H := High_Bound (Scalar_Range (Entity (N)));
2206 -- N is an expression, indicating a range with one value.
2211 end Get_Index_Bounds;
2213 ------------------------
2214 -- Get_Name_Entity_Id --
2215 ------------------------
2217 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
2219 return Entity_Id (Get_Name_Table_Info (Id));
2220 end Get_Name_Entity_Id;
2222 ---------------------------
2223 -- Get_Referenced_Object --
2224 ---------------------------
2226 function Get_Referenced_Object (N : Node_Id) return Node_Id is
2230 while Is_Entity_Name (R)
2231 and then Present (Renamed_Object (Entity (R)))
2233 R := Renamed_Object (Entity (R));
2237 end Get_Referenced_Object;
2239 -------------------------
2240 -- Get_Subprogram_Body --
2241 -------------------------
2243 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
2247 Decl := Unit_Declaration_Node (E);
2249 if Nkind (Decl) = N_Subprogram_Body then
2252 else -- Nkind (Decl) = N_Subprogram_Declaration
2254 if Present (Corresponding_Body (Decl)) then
2255 return Unit_Declaration_Node (Corresponding_Body (Decl));
2257 else -- imported subprogram.
2261 end Get_Subprogram_Body;
2263 -----------------------------
2264 -- Get_Task_Body_Procedure --
2265 -----------------------------
2267 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
2269 return Task_Body_Procedure (Declaration_Node (Root_Type (E)));
2270 end Get_Task_Body_Procedure;
2272 --------------------
2273 -- Has_Infinities --
2274 --------------------
2276 function Has_Infinities (E : Entity_Id) return Boolean is
2279 Is_Floating_Point_Type (E)
2280 and then Nkind (Scalar_Range (E)) = N_Range
2281 and then Includes_Infinities (Scalar_Range (E));
2284 ---------------------------
2285 -- Has_Private_Component --
2286 ---------------------------
2288 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
2289 Btype : Entity_Id := Base_Type (Type_Id);
2290 Component : Entity_Id;
2293 if Error_Posted (Type_Id)
2294 or else Error_Posted (Btype)
2299 if Is_Class_Wide_Type (Btype) then
2300 Btype := Root_Type (Btype);
2303 if Is_Private_Type (Btype) then
2305 UT : constant Entity_Id := Underlying_Type (Btype);
2309 if No (Full_View (Btype)) then
2310 return not Is_Generic_Type (Btype)
2311 and then not Is_Generic_Type (Root_Type (Btype));
2314 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
2318 return not Is_Frozen (UT) and then Has_Private_Component (UT);
2321 elsif Is_Array_Type (Btype) then
2322 return Has_Private_Component (Component_Type (Btype));
2324 elsif Is_Record_Type (Btype) then
2326 Component := First_Component (Btype);
2327 while Present (Component) loop
2329 if Has_Private_Component (Etype (Component)) then
2333 Next_Component (Component);
2338 elsif Is_Protected_Type (Btype)
2339 and then Present (Corresponding_Record_Type (Btype))
2341 return Has_Private_Component (Corresponding_Record_Type (Btype));
2346 end Has_Private_Component;
2348 --------------------------
2349 -- Has_Tagged_Component --
2350 --------------------------
2352 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
2356 if Is_Private_Type (Typ)
2357 and then Present (Underlying_Type (Typ))
2359 return Has_Tagged_Component (Underlying_Type (Typ));
2361 elsif Is_Array_Type (Typ) then
2362 return Has_Tagged_Component (Component_Type (Typ));
2364 elsif Is_Tagged_Type (Typ) then
2367 elsif Is_Record_Type (Typ) then
2368 Comp := First_Component (Typ);
2370 while Present (Comp) loop
2371 if Has_Tagged_Component (Etype (Comp)) then
2375 Comp := Next_Component (Typ);
2383 end Has_Tagged_Component;
2389 function In_Instance return Boolean is
2390 S : Entity_Id := Current_Scope;
2394 and then S /= Standard_Standard
2396 if (Ekind (S) = E_Function
2397 or else Ekind (S) = E_Package
2398 or else Ekind (S) = E_Procedure)
2399 and then Is_Generic_Instance (S)
2410 ----------------------
2411 -- In_Instance_Body --
2412 ----------------------
2414 function In_Instance_Body return Boolean is
2415 S : Entity_Id := Current_Scope;
2419 and then S /= Standard_Standard
2421 if (Ekind (S) = E_Function
2422 or else Ekind (S) = E_Procedure)
2423 and then Is_Generic_Instance (S)
2427 elsif Ekind (S) = E_Package
2428 and then In_Package_Body (S)
2429 and then Is_Generic_Instance (S)
2438 end In_Instance_Body;
2440 -----------------------------
2441 -- In_Instance_Not_Visible --
2442 -----------------------------
2444 function In_Instance_Not_Visible return Boolean is
2445 S : Entity_Id := Current_Scope;
2449 and then S /= Standard_Standard
2451 if (Ekind (S) = E_Function
2452 or else Ekind (S) = E_Procedure)
2453 and then Is_Generic_Instance (S)
2457 elsif Ekind (S) = E_Package
2458 and then (In_Package_Body (S) or else In_Private_Part (S))
2459 and then Is_Generic_Instance (S)
2468 end In_Instance_Not_Visible;
2470 ------------------------------
2471 -- In_Instance_Visible_Part --
2472 ------------------------------
2474 function In_Instance_Visible_Part return Boolean is
2475 S : Entity_Id := Current_Scope;
2479 and then S /= Standard_Standard
2481 if Ekind (S) = E_Package
2482 and then Is_Generic_Instance (S)
2483 and then not In_Package_Body (S)
2484 and then not In_Private_Part (S)
2493 end In_Instance_Visible_Part;
2495 --------------------------------------
2496 -- In_Subprogram_Or_Concurrent_Unit --
2497 --------------------------------------
2499 function In_Subprogram_Or_Concurrent_Unit return Boolean is
2504 -- Use scope chain to check successively outer scopes
2510 if K in Subprogram_Kind
2511 or else K in Concurrent_Kind
2512 or else K = E_Generic_Procedure
2513 or else K = E_Generic_Function
2517 elsif E = Standard_Standard then
2524 end In_Subprogram_Or_Concurrent_Unit;
2526 ---------------------
2527 -- In_Visible_Part --
2528 ---------------------
2530 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
2533 Is_Package (Scope_Id)
2534 and then In_Open_Scopes (Scope_Id)
2535 and then not In_Package_Body (Scope_Id)
2536 and then not In_Private_Part (Scope_Id);
2537 end In_Visible_Part;
2543 function Is_AAMP_Float (E : Entity_Id) return Boolean is
2545 pragma Assert (Is_Type (E));
2547 return AAMP_On_Target
2548 and then Is_Floating_Point_Type (E)
2549 and then E = Base_Type (E);
2552 -------------------------
2553 -- Is_Actual_Parameter --
2554 -------------------------
2556 function Is_Actual_Parameter (N : Node_Id) return Boolean is
2557 PK : constant Node_Kind := Nkind (Parent (N));
2561 when N_Parameter_Association =>
2562 return N = Explicit_Actual_Parameter (Parent (N));
2564 when N_Function_Call | N_Procedure_Call_Statement =>
2565 return Is_List_Member (N)
2567 List_Containing (N) = Parameter_Associations (Parent (N));
2572 end Is_Actual_Parameter;
2574 ---------------------
2575 -- Is_Aliased_View --
2576 ---------------------
2578 function Is_Aliased_View (Obj : Node_Id) return Boolean is
2582 if Is_Entity_Name (Obj) then
2584 -- Shouldn't we check that we really have an object here?
2585 -- If we do, then a-caldel.adb blows up mysteriously ???
2589 return Is_Aliased (E)
2590 or else (Present (Renamed_Object (E))
2591 and then Is_Aliased_View (Renamed_Object (E)))
2593 or else ((Is_Formal (E)
2594 or else Ekind (E) = E_Generic_In_Out_Parameter
2595 or else Ekind (E) = E_Generic_In_Parameter)
2596 and then Is_Tagged_Type (Etype (E)))
2598 or else ((Ekind (E) = E_Task_Type or else
2599 Ekind (E) = E_Protected_Type)
2600 and then In_Open_Scopes (E))
2602 -- Current instance of type
2604 or else (Is_Type (E) and then E = Current_Scope)
2605 or else (Is_Incomplete_Or_Private_Type (E)
2606 and then Full_View (E) = Current_Scope);
2608 elsif Nkind (Obj) = N_Selected_Component then
2609 return Is_Aliased (Entity (Selector_Name (Obj)));
2611 elsif Nkind (Obj) = N_Indexed_Component then
2612 return Has_Aliased_Components (Etype (Prefix (Obj)))
2614 (Is_Access_Type (Etype (Prefix (Obj)))
2616 Has_Aliased_Components
2617 (Designated_Type (Etype (Prefix (Obj)))));
2619 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
2620 or else Nkind (Obj) = N_Type_Conversion
2622 return Is_Tagged_Type (Etype (Obj))
2623 or else Is_Aliased_View (Expression (Obj));
2625 elsif Nkind (Obj) = N_Explicit_Dereference then
2626 return Nkind (Original_Node (Obj)) /= N_Function_Call;
2631 end Is_Aliased_View;
2633 ----------------------
2634 -- Is_Atomic_Object --
2635 ----------------------
2637 function Is_Atomic_Object (N : Node_Id) return Boolean is
2639 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
2640 -- Determines if given object has atomic components
2642 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
2643 -- If prefix is an implicit dereference, examine designated type.
2645 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
2647 if Is_Access_Type (Etype (N)) then
2649 Has_Atomic_Components (Designated_Type (Etype (N)));
2651 return Object_Has_Atomic_Components (N);
2653 end Is_Atomic_Prefix;
2655 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
2657 if Has_Atomic_Components (Etype (N))
2658 or else Is_Atomic (Etype (N))
2662 elsif Is_Entity_Name (N)
2663 and then (Has_Atomic_Components (Entity (N))
2664 or else Is_Atomic (Entity (N)))
2668 elsif Nkind (N) = N_Indexed_Component
2669 or else Nkind (N) = N_Selected_Component
2671 return Is_Atomic_Prefix (Prefix (N));
2676 end Object_Has_Atomic_Components;
2678 -- Start of processing for Is_Atomic_Object
2681 if Is_Atomic (Etype (N))
2682 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
2686 elsif Nkind (N) = N_Indexed_Component
2687 or else Nkind (N) = N_Selected_Component
2689 return Is_Atomic_Prefix (Prefix (N));
2694 end Is_Atomic_Object;
2696 ----------------------------------------------
2697 -- Is_Dependent_Component_Of_Mutable_Object --
2698 ----------------------------------------------
2700 function Is_Dependent_Component_Of_Mutable_Object
2705 Prefix_Type : Entity_Id;
2706 P_Aliased : Boolean := False;
2709 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean;
2710 -- Returns True if and only if Comp has a constrained subtype
2711 -- that depends on a discriminant.
2713 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
2714 -- Returns True if and only if Comp is declared within a variant part.
2716 ------------------------------
2717 -- Has_Dependent_Constraint --
2718 ------------------------------
2720 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean is
2721 Comp_Decl : constant Node_Id := Parent (Comp);
2722 Subt_Indic : constant Node_Id := Subtype_Indication (Comp_Decl);
2727 if Nkind (Subt_Indic) = N_Subtype_Indication then
2728 Constr := Constraint (Subt_Indic);
2730 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
2731 Assn := First (Constraints (Constr));
2732 while Present (Assn) loop
2733 case Nkind (Assn) is
2734 when N_Subtype_Indication |
2738 if Depends_On_Discriminant (Assn) then
2742 when N_Discriminant_Association =>
2743 if Depends_On_Discriminant (Expression (Assn)) then
2758 end Has_Dependent_Constraint;
2760 --------------------------------
2761 -- Is_Declared_Within_Variant --
2762 --------------------------------
2764 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
2765 Comp_Decl : constant Node_Id := Parent (Comp);
2766 Comp_List : constant Node_Id := Parent (Comp_Decl);
2769 return Nkind (Parent (Comp_List)) = N_Variant;
2770 end Is_Declared_Within_Variant;
2772 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
2775 if Is_Variable (Object) then
2777 if Nkind (Object) = N_Selected_Component then
2778 P := Prefix (Object);
2779 Prefix_Type := Etype (P);
2781 if Is_Entity_Name (P) then
2783 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
2784 Prefix_Type := Base_Type (Prefix_Type);
2787 if Is_Aliased (Entity (P)) then
2792 -- Check for prefix being an aliased component ???
2796 if Is_Access_Type (Prefix_Type)
2797 or else Nkind (P) = N_Explicit_Dereference
2803 Original_Record_Component (Entity (Selector_Name (Object)));
2805 if not Is_Constrained (Prefix_Type)
2806 and then not Is_Indefinite_Subtype (Prefix_Type)
2807 and then (Is_Declared_Within_Variant (Comp)
2808 or else Has_Dependent_Constraint (Comp))
2809 and then not P_Aliased
2815 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
2819 elsif Nkind (Object) = N_Indexed_Component
2820 or else Nkind (Object) = N_Slice
2822 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
2827 end Is_Dependent_Component_Of_Mutable_Object;
2833 function Is_False (U : Uint) return Boolean is
2838 ---------------------------
2839 -- Is_Fixed_Model_Number --
2840 ---------------------------
2842 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
2843 S : constant Ureal := Small_Value (T);
2844 M : Urealp.Save_Mark;
2849 R := (U = UR_Trunc (U / S) * S);
2852 end Is_Fixed_Model_Number;
2854 -------------------------------
2855 -- Is_Fully_Initialized_Type --
2856 -------------------------------
2858 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
2860 if Is_Scalar_Type (Typ) then
2863 elsif Is_Access_Type (Typ) then
2866 elsif Is_Array_Type (Typ) then
2867 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
2871 -- An interesting case, if we have a constrained type one of whose
2872 -- bounds is known to be null, then there are no elements to be
2873 -- initialized, so all the elements are initialized!
2875 if Is_Constrained (Typ) then
2878 Indx_Typ : Entity_Id;
2882 Indx := First_Index (Typ);
2883 while Present (Indx) loop
2885 if Etype (Indx) = Any_Type then
2888 -- If index is a range, use directly.
2890 elsif Nkind (Indx) = N_Range then
2891 Lbd := Low_Bound (Indx);
2892 Hbd := High_Bound (Indx);
2895 Indx_Typ := Etype (Indx);
2897 if Is_Private_Type (Indx_Typ) then
2898 Indx_Typ := Full_View (Indx_Typ);
2901 if No (Indx_Typ) then
2904 Lbd := Type_Low_Bound (Indx_Typ);
2905 Hbd := Type_High_Bound (Indx_Typ);
2909 if Compile_Time_Known_Value (Lbd)
2910 and then Compile_Time_Known_Value (Hbd)
2912 if Expr_Value (Hbd) < Expr_Value (Lbd) then
2924 elsif Is_Record_Type (Typ) then
2929 Ent := First_Entity (Typ);
2931 while Present (Ent) loop
2932 if Ekind (Ent) = E_Component
2933 and then (No (Parent (Ent))
2934 or else No (Expression (Parent (Ent))))
2935 and then not Is_Fully_Initialized_Type (Etype (Ent))
2946 elsif Is_Concurrent_Type (Typ) then
2949 elsif Is_Private_Type (Typ) then
2951 U : constant Entity_Id := Underlying_Type (Typ);
2957 return Is_Fully_Initialized_Type (U);
2964 end Is_Fully_Initialized_Type;
2966 ----------------------------
2967 -- Is_Inherited_Operation --
2968 ----------------------------
2970 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
2971 Kind : constant Node_Kind := Nkind (Parent (E));
2974 pragma Assert (Is_Overloadable (E));
2975 return Kind = N_Full_Type_Declaration
2976 or else Kind = N_Private_Extension_Declaration
2977 or else Kind = N_Subtype_Declaration
2978 or else (Ekind (E) = E_Enumeration_Literal
2979 and then Is_Derived_Type (Etype (E)));
2980 end Is_Inherited_Operation;
2982 -----------------------------
2983 -- Is_Library_Level_Entity --
2984 -----------------------------
2986 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
2988 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
2989 end Is_Library_Level_Entity;
2991 ---------------------------------
2992 -- Is_Local_Variable_Reference --
2993 ---------------------------------
2995 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
2997 if not Is_Entity_Name (Expr) then
3002 Ent : constant Entity_Id := Entity (Expr);
3003 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
3006 if Ekind (Ent) /= E_Variable
3008 Ekind (Ent) /= E_In_Out_Parameter
3013 return Present (Sub) and then Sub = Current_Subprogram;
3017 end Is_Local_Variable_Reference;
3019 -------------------------
3020 -- Is_Object_Reference --
3021 -------------------------
3023 function Is_Object_Reference (N : Node_Id) return Boolean is
3025 if Is_Entity_Name (N) then
3026 return Is_Object (Entity (N));
3030 when N_Indexed_Component | N_Slice =>
3033 -- In Ada95, a function call is a constant object.
3035 when N_Function_Call =>
3038 when N_Selected_Component =>
3039 return Is_Object_Reference (Selector_Name (N));
3041 when N_Explicit_Dereference =>
3044 -- An unchecked type conversion is considered to be an object if
3045 -- the operand is an object (this construction arises only as a
3046 -- result of expansion activities).
3048 when N_Unchecked_Type_Conversion =>
3055 end Is_Object_Reference;
3057 -----------------------------------
3058 -- Is_OK_Variable_For_Out_Formal --
3059 -----------------------------------
3061 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
3063 Note_Possible_Modification (AV);
3065 -- We must reject parenthesized variable names. The check for
3066 -- Comes_From_Source is present because there are currently
3067 -- cases where the compiler violates this rule (e.g. passing
3068 -- a task object to its controlled Initialize routine).
3070 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
3073 -- A variable is always allowed
3075 elsif Is_Variable (AV) then
3078 -- Unchecked conversions are allowed only if they come from the
3079 -- generated code, which sometimes uses unchecked conversions for
3080 -- out parameters in cases where code generation is unaffected.
3081 -- We tell source unchecked conversions by seeing if they are
3082 -- rewrites of an original UC function call, or of an explicit
3083 -- conversion of a function call.
3085 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
3086 if Nkind (Original_Node (AV)) = N_Function_Call then
3089 elsif Comes_From_Source (AV)
3090 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
3098 -- Normal type conversions are allowed if argument is a variable
3100 elsif Nkind (AV) = N_Type_Conversion then
3101 if Is_Variable (Expression (AV))
3102 and then Paren_Count (Expression (AV)) = 0
3104 Note_Possible_Modification (Expression (AV));
3107 -- We also allow a non-parenthesized expression that raises
3108 -- constraint error if it rewrites what used to be a variable
3110 elsif Raises_Constraint_Error (Expression (AV))
3111 and then Paren_Count (Expression (AV)) = 0
3112 and then Is_Variable (Original_Node (Expression (AV)))
3116 -- Type conversion of something other than a variable
3122 -- If this node is rewritten, then test the original form, if that is
3123 -- OK, then we consider the rewritten node OK (for example, if the
3124 -- original node is a conversion, then Is_Variable will not be true
3125 -- but we still want to allow the conversion if it converts a variable.
3127 elsif Original_Node (AV) /= AV then
3128 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
3130 -- All other non-variables are rejected
3135 end Is_OK_Variable_For_Out_Formal;
3137 -----------------------------
3138 -- Is_RCI_Pkg_Spec_Or_Body --
3139 -----------------------------
3141 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
3143 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
3144 -- Return True if the unit of Cunit is an RCI package declaration
3146 ---------------------------
3147 -- Is_RCI_Pkg_Decl_Cunit --
3148 ---------------------------
3150 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
3151 The_Unit : constant Node_Id := Unit (Cunit);
3154 if Nkind (The_Unit) /= N_Package_Declaration then
3157 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
3158 end Is_RCI_Pkg_Decl_Cunit;
3160 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
3163 return Is_RCI_Pkg_Decl_Cunit (Cunit)
3165 (Nkind (Unit (Cunit)) = N_Package_Body
3166 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
3167 end Is_RCI_Pkg_Spec_Or_Body;
3169 -----------------------------------------
3170 -- Is_Remote_Access_To_Class_Wide_Type --
3171 -----------------------------------------
3173 function Is_Remote_Access_To_Class_Wide_Type
3179 function Comes_From_Limited_Private_Type_Declaration
3182 -- Check if the original declaration is a limited private one and
3183 -- if all the derivations have been using private extensions.
3185 -------------------------------------------------
3186 -- Comes_From_Limited_Private_Type_Declaration --
3187 -------------------------------------------------
3189 function Comes_From_Limited_Private_Type_Declaration (E : in Entity_Id)
3192 N : constant Node_Id := Declaration_Node (E);
3194 if Nkind (N) = N_Private_Type_Declaration
3195 and then Limited_Present (N)
3200 if Nkind (N) = N_Private_Extension_Declaration then
3201 return Comes_From_Limited_Private_Type_Declaration (Etype (E));
3205 end Comes_From_Limited_Private_Type_Declaration;
3207 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
3210 if not (Is_Remote_Call_Interface (E)
3211 or else Is_Remote_Types (E))
3212 or else Ekind (E) /= E_General_Access_Type
3217 D := Designated_Type (E);
3219 if Ekind (D) /= E_Class_Wide_Type then
3223 return Comes_From_Limited_Private_Type_Declaration
3224 (Defining_Identifier (Parent (D)));
3225 end Is_Remote_Access_To_Class_Wide_Type;
3227 -----------------------------------------
3228 -- Is_Remote_Access_To_Subprogram_Type --
3229 -----------------------------------------
3231 function Is_Remote_Access_To_Subprogram_Type
3236 return (Ekind (E) = E_Access_Subprogram_Type
3237 or else (Ekind (E) = E_Record_Type
3238 and then Present (Corresponding_Remote_Type (E))))
3239 and then (Is_Remote_Call_Interface (E)
3240 or else Is_Remote_Types (E));
3241 end Is_Remote_Access_To_Subprogram_Type;
3243 --------------------
3244 -- Is_Remote_Call --
3245 --------------------
3247 function Is_Remote_Call (N : Node_Id) return Boolean is
3249 if Nkind (N) /= N_Procedure_Call_Statement
3250 and then Nkind (N) /= N_Function_Call
3252 -- An entry call cannot be remote
3256 elsif Nkind (Name (N)) in N_Has_Entity
3257 and then Is_Remote_Call_Interface (Entity (Name (N)))
3259 -- A subprogram declared in the spec of a RCI package is remote
3263 elsif Nkind (Name (N)) = N_Explicit_Dereference
3264 and then Is_Remote_Access_To_Subprogram_Type
3265 (Etype (Prefix (Name (N))))
3267 -- The dereference of a RAS is a remote call
3271 elsif Present (Controlling_Argument (N))
3272 and then Is_Remote_Access_To_Class_Wide_Type
3273 (Etype (Controlling_Argument (N)))
3275 -- Any primitive operation call with a controlling argument of
3276 -- a RACW type is a remote call.
3281 -- All other calls are local calls
3286 ----------------------
3287 -- Is_Selector_Name --
3288 ----------------------
3290 function Is_Selector_Name (N : Node_Id) return Boolean is
3293 if not Is_List_Member (N) then
3295 P : constant Node_Id := Parent (N);
3296 K : constant Node_Kind := Nkind (P);
3300 (K = N_Expanded_Name or else
3301 K = N_Generic_Association or else
3302 K = N_Parameter_Association or else
3303 K = N_Selected_Component)
3304 and then Selector_Name (P) = N;
3309 L : constant List_Id := List_Containing (N);
3310 P : constant Node_Id := Parent (L);
3313 return (Nkind (P) = N_Discriminant_Association
3314 and then Selector_Names (P) = L)
3316 (Nkind (P) = N_Component_Association
3317 and then Choices (P) = L);
3320 end Is_Selector_Name;
3326 function Is_Statement (N : Node_Id) return Boolean is
3329 Nkind (N) in N_Statement_Other_Than_Procedure_Call
3330 or else Nkind (N) = N_Procedure_Call_Statement;
3337 function Is_Transfer (N : Node_Id) return Boolean is
3338 Kind : constant Node_Kind := Nkind (N);
3341 if Kind = N_Return_Statement
3343 Kind = N_Goto_Statement
3345 Kind = N_Raise_Statement
3347 Kind = N_Requeue_Statement
3351 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
3352 and then No (Condition (N))
3356 elsif Kind = N_Procedure_Call_Statement
3357 and then Is_Entity_Name (Name (N))
3358 and then Present (Entity (Name (N)))
3359 and then No_Return (Entity (Name (N)))
3363 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
3375 function Is_True (U : Uint) return Boolean is
3384 function Is_Variable (N : Node_Id) return Boolean is
3386 Orig_Node : constant Node_Id := Original_Node (N);
3387 -- We do the test on the original node, since this is basically a
3388 -- test of syntactic categories, so it must not be disturbed by
3389 -- whatever rewriting might have occurred. For example, an aggregate,
3390 -- which is certainly NOT a variable, could be turned into a variable
3393 function In_Protected_Function (E : Entity_Id) return Boolean;
3394 -- Within a protected function, the private components of the
3395 -- enclosing protected type are constants. A function nested within
3396 -- a (protected) procedure is not itself protected.
3398 function Is_Variable_Prefix (P : Node_Id) return Boolean;
3399 -- Prefixes can involve implicit dereferences, in which case we
3400 -- must test for the case of a reference of a constant access
3401 -- type, which can never be a variable.
3403 function In_Protected_Function (E : Entity_Id) return Boolean is
3404 Prot : constant Entity_Id := Scope (E);
3408 if not Is_Protected_Type (Prot) then
3413 while Present (S) and then S /= Prot loop
3415 if Ekind (S) = E_Function
3416 and then Scope (S) = Prot
3426 end In_Protected_Function;
3428 function Is_Variable_Prefix (P : Node_Id) return Boolean is
3430 if Is_Access_Type (Etype (P)) then
3431 return not Is_Access_Constant (Root_Type (Etype (P)));
3433 return Is_Variable (P);
3435 end Is_Variable_Prefix;
3437 -- Start of processing for Is_Variable
3440 -- Definitely OK if Assignment_OK is set. Since this is something that
3441 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
3443 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
3446 -- Normally we go to the original node, but there is one exception
3447 -- where we use the rewritten node, namely when it is an explicit
3448 -- dereference. The generated code may rewrite a prefix which is an
3449 -- access type with an explicit dereference. The dereference is a
3450 -- variable, even though the original node may not be (since it could
3451 -- be a constant of the access type).
3453 elsif Nkind (N) = N_Explicit_Dereference
3454 and then Nkind (Orig_Node) /= N_Explicit_Dereference
3455 and then Is_Access_Type (Etype (Orig_Node))
3457 return Is_Variable_Prefix (Original_Node (Prefix (N)));
3459 -- All remaining checks use the original node
3461 elsif Is_Entity_Name (Orig_Node) then
3463 E : constant Entity_Id := Entity (Orig_Node);
3464 K : constant Entity_Kind := Ekind (E);
3467 return (K = E_Variable
3468 and then Nkind (Parent (E)) /= N_Exception_Handler)
3469 or else (K = E_Component
3470 and then not In_Protected_Function (E))
3471 or else K = E_Out_Parameter
3472 or else K = E_In_Out_Parameter
3473 or else K = E_Generic_In_Out_Parameter
3475 -- Current instance of type:
3477 or else (Is_Type (E) and then In_Open_Scopes (E))
3478 or else (Is_Incomplete_Or_Private_Type (E)
3479 and then In_Open_Scopes (Full_View (E)));
3483 case Nkind (Orig_Node) is
3484 when N_Indexed_Component | N_Slice =>
3485 return Is_Variable_Prefix (Prefix (Orig_Node));
3487 when N_Selected_Component =>
3488 return Is_Variable_Prefix (Prefix (Orig_Node))
3489 and then Is_Variable (Selector_Name (Orig_Node));
3491 -- For an explicit dereference, we must check whether the type
3492 -- is ACCESS CONSTANT, since if it is, then it is not a variable.
3494 when N_Explicit_Dereference =>
3495 return Is_Access_Type (Etype (Prefix (Orig_Node)))
3497 Is_Access_Constant (Root_Type (Etype (Prefix (Orig_Node))));
3499 -- The type conversion is the case where we do not deal with the
3500 -- context dependent special case of an actual parameter. Thus
3501 -- the type conversion is only considered a variable for the
3502 -- purposes of this routine if the target type is tagged. However,
3503 -- a type conversion is considered to be a variable if it does not
3504 -- come from source (this deals for example with the conversions
3505 -- of expressions to their actual subtypes).
3507 when N_Type_Conversion =>
3508 return Is_Variable (Expression (Orig_Node))
3510 (not Comes_From_Source (Orig_Node)
3512 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
3514 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
3516 -- GNAT allows an unchecked type conversion as a variable. This
3517 -- only affects the generation of internal expanded code, since
3518 -- calls to instantiations of Unchecked_Conversion are never
3519 -- considered variables (since they are function calls).
3520 -- This is also true for expression actions.
3522 when N_Unchecked_Type_Conversion =>
3523 return Is_Variable (Expression (Orig_Node));
3531 ------------------------
3532 -- Is_Volatile_Object --
3533 ------------------------
3535 function Is_Volatile_Object (N : Node_Id) return Boolean is
3537 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
3538 -- Determines if given object has volatile components
3540 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
3541 -- If prefix is an implicit dereference, examine designated type.
3543 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
3545 if Is_Access_Type (Etype (N)) then
3546 return Has_Volatile_Components (Designated_Type (Etype (N)));
3548 return Object_Has_Volatile_Components (N);
3550 end Is_Volatile_Prefix;
3552 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
3554 if Is_Volatile (Etype (N))
3555 or else Has_Volatile_Components (Etype (N))
3559 elsif Is_Entity_Name (N)
3560 and then (Has_Volatile_Components (Entity (N))
3561 or else Is_Volatile (Entity (N)))
3565 elsif Nkind (N) = N_Indexed_Component
3566 or else Nkind (N) = N_Selected_Component
3568 return Is_Volatile_Prefix (Prefix (N));
3573 end Object_Has_Volatile_Components;
3575 -- Start of processing for Is_Volatile_Object
3578 if Is_Volatile (Etype (N))
3579 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
3583 elsif Nkind (N) = N_Indexed_Component
3584 or else Nkind (N) = N_Selected_Component
3586 return Is_Volatile_Prefix (Prefix (N));
3591 end Is_Volatile_Object;
3593 --------------------------
3594 -- Kill_Size_Check_Code --
3595 --------------------------
3597 procedure Kill_Size_Check_Code (E : Entity_Id) is
3599 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
3600 and then Present (Size_Check_Code (E))
3602 Remove (Size_Check_Code (E));
3603 Set_Size_Check_Code (E, Empty);
3605 end Kill_Size_Check_Code;
3607 -------------------------
3608 -- New_External_Entity --
3609 -------------------------
3611 function New_External_Entity
3612 (Kind : Entity_Kind;
3613 Scope_Id : Entity_Id;
3614 Sloc_Value : Source_Ptr;
3615 Related_Id : Entity_Id;
3617 Suffix_Index : Nat := 0;
3618 Prefix : Character := ' ')
3621 N : constant Entity_Id :=
3622 Make_Defining_Identifier (Sloc_Value,
3624 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
3627 Set_Ekind (N, Kind);
3628 Set_Is_Internal (N, True);
3629 Append_Entity (N, Scope_Id);
3630 Set_Public_Status (N);
3632 if Kind in Type_Kind then
3633 Init_Size_Align (N);
3637 end New_External_Entity;
3639 -------------------------
3640 -- New_Internal_Entity --
3641 -------------------------
3643 function New_Internal_Entity
3644 (Kind : Entity_Kind;
3645 Scope_Id : Entity_Id;
3646 Sloc_Value : Source_Ptr;
3647 Id_Char : Character)
3650 N : constant Entity_Id :=
3651 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
3654 Set_Ekind (N, Kind);
3655 Set_Is_Internal (N, True);
3656 Append_Entity (N, Scope_Id);
3658 if Kind in Type_Kind then
3659 Init_Size_Align (N);
3663 end New_Internal_Entity;
3669 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
3673 -- If we are pointing at a positional parameter, it is a member of
3674 -- a node list (the list of parameters), and the next parameter
3675 -- is the next node on the list, unless we hit a parameter
3676 -- association, in which case we shift to using the chain whose
3677 -- head is the First_Named_Actual in the parent, and then is
3678 -- threaded using the Next_Named_Actual of the Parameter_Association.
3679 -- All this fiddling is because the original node list is in the
3680 -- textual call order, and what we need is the declaration order.
3682 if Is_List_Member (Actual_Id) then
3683 N := Next (Actual_Id);
3685 if Nkind (N) = N_Parameter_Association then
3686 return First_Named_Actual (Parent (Actual_Id));
3692 return Next_Named_Actual (Parent (Actual_Id));
3696 procedure Next_Actual (Actual_Id : in out Node_Id) is
3698 Actual_Id := Next_Actual (Actual_Id);
3701 -----------------------
3702 -- Normalize_Actuals --
3703 -----------------------
3705 -- Chain actuals according to formals of subprogram. If there are
3706 -- no named associations, the chain is simply the list of Parameter
3707 -- Associations, since the order is the same as the declaration order.
3708 -- If there are named associations, then the First_Named_Actual field
3709 -- in the N_Procedure_Call_Statement node or N_Function_Call node
3710 -- points to the Parameter_Association node for the parameter that
3711 -- comes first in declaration order. The remaining named parameters
3712 -- are then chained in declaration order using Next_Named_Actual.
3714 -- This routine also verifies that the number of actuals is compatible
3715 -- with the number and default values of formals, but performs no type
3716 -- checking (type checking is done by the caller).
3718 -- If the matching succeeds, Success is set to True, and the caller
3719 -- proceeds with type-checking. If the match is unsuccessful, then
3720 -- Success is set to False, and the caller attempts a different
3721 -- interpretation, if there is one.
3723 -- If the flag Report is on, the call is not overloaded, and a failure
3724 -- to match can be reported here, rather than in the caller.
3726 procedure Normalize_Actuals
3730 Success : out Boolean)
3732 Actuals : constant List_Id := Parameter_Associations (N);
3733 Actual : Node_Id := Empty;
3735 Last : Node_Id := Empty;
3736 First_Named : Node_Id := Empty;
3739 Formals_To_Match : Integer := 0;
3740 Actuals_To_Match : Integer := 0;
3742 procedure Chain (A : Node_Id);
3743 -- Add named actual at the proper place in the list, using the
3744 -- Next_Named_Actual link.
3746 function Reporting return Boolean;
3747 -- Determines if an error is to be reported. To report an error, we
3748 -- need Report to be True, and also we do not report errors caused
3749 -- by calls to Init_Proc's that occur within other Init_Proc's. Such
3750 -- errors must always be cascaded errors, since if all the types are
3751 -- declared correctly, the compiler will certainly build decent calls!
3753 procedure Chain (A : Node_Id) is
3757 -- Call node points to first actual in list.
3759 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
3762 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
3766 Set_Next_Named_Actual (Last, Empty);
3769 function Reporting return Boolean is
3774 elsif not Within_Init_Proc then
3777 elsif Chars (Entity (Name (N))) = Name_uInit_Proc then
3785 -- Start of processing for Normalize_Actuals
3788 if Is_Access_Type (S) then
3790 -- The name in the call is a function call that returns an access
3791 -- to subprogram. The designated type has the list of formals.
3793 Formal := First_Formal (Designated_Type (S));
3795 Formal := First_Formal (S);
3798 while Present (Formal) loop
3799 Formals_To_Match := Formals_To_Match + 1;
3800 Next_Formal (Formal);
3803 -- Find if there is a named association, and verify that no positional
3804 -- associations appear after named ones.
3806 if Present (Actuals) then
3807 Actual := First (Actuals);
3810 while Present (Actual)
3811 and then Nkind (Actual) /= N_Parameter_Association
3813 Actuals_To_Match := Actuals_To_Match + 1;
3817 if No (Actual) and Actuals_To_Match = Formals_To_Match then
3819 -- Most common case: positional notation, no defaults
3824 elsif Actuals_To_Match > Formals_To_Match then
3826 -- Too many actuals: will not work.
3829 Error_Msg_N ("too many arguments in call", N);
3836 First_Named := Actual;
3838 while Present (Actual) loop
3839 if Nkind (Actual) /= N_Parameter_Association then
3841 ("positional parameters not allowed after named ones", Actual);
3846 Actuals_To_Match := Actuals_To_Match + 1;
3852 if Present (Actuals) then
3853 Actual := First (Actuals);
3856 Formal := First_Formal (S);
3858 while Present (Formal) loop
3860 -- Match the formals in order. If the corresponding actual
3861 -- is positional, nothing to do. Else scan the list of named
3862 -- actuals to find the one with the right name.
3865 and then Nkind (Actual) /= N_Parameter_Association
3868 Actuals_To_Match := Actuals_To_Match - 1;
3869 Formals_To_Match := Formals_To_Match - 1;
3872 -- For named parameters, search the list of actuals to find
3873 -- one that matches the next formal name.
3875 Actual := First_Named;
3878 while Present (Actual) loop
3879 if Chars (Selector_Name (Actual)) = Chars (Formal) then
3882 Actuals_To_Match := Actuals_To_Match - 1;
3883 Formals_To_Match := Formals_To_Match - 1;
3891 if Ekind (Formal) /= E_In_Parameter
3892 or else No (Default_Value (Formal))
3895 if Comes_From_Source (S)
3896 and then Is_Overloadable (S)
3898 Error_Msg_Name_1 := Chars (S);
3899 Error_Msg_Sloc := Sloc (S);
3901 ("missing argument for parameter & " &
3902 "in call to % declared #", N, Formal);
3905 ("missing argument for parameter &", N, Formal);
3913 Formals_To_Match := Formals_To_Match - 1;
3918 Next_Formal (Formal);
3921 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
3928 -- Find some superfluous named actual that did not get
3929 -- attached to the list of associations.
3931 Actual := First (Actuals);
3933 while Present (Actual) loop
3935 if Nkind (Actual) = N_Parameter_Association
3936 and then Actual /= Last
3937 and then No (Next_Named_Actual (Actual))
3939 Error_Msg_N ("Unmatched actual in call", Actual);
3950 end Normalize_Actuals;
3952 --------------------------------
3953 -- Note_Possible_Modification --
3954 --------------------------------
3956 procedure Note_Possible_Modification (N : Node_Id) is
3960 procedure Set_Ref (E : Entity_Id; N : Node_Id);
3961 -- Internal routine to note modification on entity E by node N
3963 procedure Set_Ref (E : Entity_Id; N : Node_Id) is
3965 Set_Not_Source_Assigned (E, False);
3966 Set_Is_True_Constant (E, False);
3967 Generate_Reference (E, N, 'm');
3970 -- Start of processing for Note_Possible_Modification
3973 -- Loop to find referenced entity, if there is one
3977 -- Test for node rewritten as dereference (e.g. accept parameter)
3979 if Nkind (Exp) = N_Explicit_Dereference
3980 and then Is_Entity_Name (Original_Node (Exp))
3982 Set_Ref (Entity (Original_Node (Exp)), Original_Node (Exp));
3985 elsif Is_Entity_Name (Exp) then
3986 Ent := Entity (Exp);
3988 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
3989 and then Present (Renamed_Object (Ent))
3991 Exp := Renamed_Object (Ent);
3998 elsif Nkind (Exp) = N_Type_Conversion
3999 or else Nkind (Exp) = N_Unchecked_Type_Conversion
4001 Exp := Expression (Exp);
4003 elsif Nkind (Exp) = N_Slice
4004 or else Nkind (Exp) = N_Indexed_Component
4005 or else Nkind (Exp) = N_Selected_Component
4007 Exp := Prefix (Exp);
4013 end Note_Possible_Modification;
4015 -------------------------
4016 -- Object_Access_Level --
4017 -------------------------
4019 function Object_Access_Level (Obj : Node_Id) return Uint is
4022 -- Returns the static accessibility level of the view denoted
4023 -- by Obj. Note that the value returned is the result of a
4024 -- call to Scope_Depth. Only scope depths associated with
4025 -- dynamic scopes can actually be returned. Since only
4026 -- relative levels matter for accessibility checking, the fact
4027 -- that the distance between successive levels of accessibility
4028 -- is not always one is immaterial (invariant: if level(E2) is
4029 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
4032 if Is_Entity_Name (Obj) then
4035 -- If E is a type then it denotes a current instance.
4036 -- For this case we add one to the normal accessibility
4037 -- level of the type to ensure that current instances
4038 -- are treated as always being deeper than than the level
4039 -- of any visible named access type (see 3.10.2(21)).
4042 return Type_Access_Level (E) + 1;
4044 elsif Present (Renamed_Object (E)) then
4045 return Object_Access_Level (Renamed_Object (E));
4047 -- Similarly, if E is a component of the current instance of a
4048 -- protected type, any instance of it is assumed to be at a deeper
4049 -- level than the type. For a protected object (whose type is an
4050 -- anonymous protected type) its components are at the same level
4051 -- as the type itself.
4053 elsif not Is_Overloadable (E)
4054 and then Ekind (Scope (E)) = E_Protected_Type
4055 and then Comes_From_Source (Scope (E))
4057 return Type_Access_Level (Scope (E)) + 1;
4060 return Scope_Depth (Enclosing_Dynamic_Scope (E));
4063 elsif Nkind (Obj) = N_Selected_Component then
4064 if Is_Access_Type (Etype (Prefix (Obj))) then
4065 return Type_Access_Level (Etype (Prefix (Obj)));
4067 return Object_Access_Level (Prefix (Obj));
4070 elsif Nkind (Obj) = N_Indexed_Component then
4071 if Is_Access_Type (Etype (Prefix (Obj))) then
4072 return Type_Access_Level (Etype (Prefix (Obj)));
4074 return Object_Access_Level (Prefix (Obj));
4077 elsif Nkind (Obj) = N_Explicit_Dereference then
4079 -- If the prefix is a selected access discriminant then
4080 -- we make a recursive call on the prefix, which will
4081 -- in turn check the level of the prefix object of
4082 -- the selected discriminant.
4084 if Nkind (Prefix (Obj)) = N_Selected_Component
4085 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
4087 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
4089 return Object_Access_Level (Prefix (Obj));
4091 return Type_Access_Level (Etype (Prefix (Obj)));
4094 elsif Nkind (Obj) = N_Type_Conversion then
4095 return Object_Access_Level (Expression (Obj));
4097 -- Function results are objects, so we get either the access level
4098 -- of the function or, in the case of an indirect call, the level of
4099 -- of the access-to-subprogram type.
4101 elsif Nkind (Obj) = N_Function_Call then
4102 if Is_Entity_Name (Name (Obj)) then
4103 return Subprogram_Access_Level (Entity (Name (Obj)));
4105 return Type_Access_Level (Etype (Prefix (Name (Obj))));
4108 -- For convenience we handle qualified expressions, even though
4109 -- they aren't technically object names.
4111 elsif Nkind (Obj) = N_Qualified_Expression then
4112 return Object_Access_Level (Expression (Obj));
4114 -- Otherwise return the scope level of Standard.
4115 -- (If there are cases that fall through
4116 -- to this point they will be treated as
4117 -- having global accessibility for now. ???)
4120 return Scope_Depth (Standard_Standard);
4122 end Object_Access_Level;
4124 -----------------------
4125 -- Private_Component --
4126 -----------------------
4128 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
4129 Ancestor : constant Entity_Id := Base_Type (Type_Id);
4131 function Trace_Components
4135 -- Recursive function that does the work, and checks against circular
4136 -- definition for each subcomponent type.
4138 ----------------------
4139 -- Trace_Components --
4140 ----------------------
4142 function Trace_Components
4144 Check : Boolean) return Entity_Id
4146 Btype : constant Entity_Id := Base_Type (T);
4147 Component : Entity_Id;
4149 Candidate : Entity_Id := Empty;
4152 if Check and then Btype = Ancestor then
4153 Error_Msg_N ("circular type definition", Type_Id);
4157 if Is_Private_Type (Btype)
4158 and then not Is_Generic_Type (Btype)
4162 elsif Is_Array_Type (Btype) then
4163 return Trace_Components (Component_Type (Btype), True);
4165 elsif Is_Record_Type (Btype) then
4166 Component := First_Entity (Btype);
4167 while Present (Component) loop
4169 -- skip anonymous types generated by constrained components.
4171 if not Is_Type (Component) then
4172 P := Trace_Components (Etype (Component), True);
4175 if P = Any_Type then
4183 Next_Entity (Component);
4191 end Trace_Components;
4193 -- Start of processing for Private_Component
4196 return Trace_Components (Type_Id, False);
4197 end Private_Component;
4199 -----------------------
4200 -- Process_End_Label --
4201 -----------------------
4203 procedure Process_End_Label (N : Node_Id; Typ : Character) is
4208 Label_Ref : Boolean;
4209 -- Set True if reference to end label itself is required
4212 -- Gets set to the operator symbol or identifier that references
4213 -- the entity Ent. For the child unit case, this is the identifier
4214 -- from the designator. For other cases, this is simply Endl.
4217 -- This is the entity for the construct to which the End_Label applies
4219 procedure Generate_Parent_Ref (N : Node_Id);
4220 -- N is an identifier node that appears as a parent unit reference
4221 -- in the case where Ent is a child unit. This procedure generates
4222 -- an appropriate cross-reference entry.
4224 procedure Generate_Parent_Ref (N : Node_Id) is
4225 Parent_Ent : Entity_Id;
4228 -- Search up scope stack. The reason we do this is that normal
4229 -- visibility analysis would not work for two reasons. First in
4230 -- some subunit cases, the entry for the parent unit may not be
4231 -- visible, and in any case there can be a local entity that
4232 -- hides the scope entity.
4234 Parent_Ent := Current_Scope;
4235 while Present (Parent_Ent) loop
4236 if Chars (Parent_Ent) = Chars (N) then
4238 -- Generate the reference. We do NOT consider this as a
4239 -- reference for unreferenced symbol purposes, but we do
4240 -- force a cross-reference even if the end line does not
4241 -- come from source (the caller already generated the
4242 -- appropriate Typ for this situation).
4245 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
4246 Style.Check_Identifier (N, Parent_Ent);
4250 Parent_Ent := Scope (Parent_Ent);
4253 -- Fall through means entity was not found -- that's odd, but
4254 -- the appropriate thing is simply to ignore and not generate
4255 -- any cross-reference for this entry.
4258 end Generate_Parent_Ref;
4260 -- Start of processing for Process_End_Label
4263 -- If no node, ignore. This happens in some error situations,
4264 -- and also for some internally generated structures where no
4265 -- end label references are required in any case.
4271 -- Nothing to do if no End_Label, happens for internally generated
4272 -- constructs where we don't want an end label reference anyway.
4274 Endl := End_Label (N);
4280 -- Reference node is not in extended main source unit
4282 if not In_Extended_Main_Source_Unit (N) then
4284 -- Generally we do not collect references except for the
4285 -- extended main source unit. The one exception is the 'e'
4286 -- entry for a package spec, where it is useful for a client
4287 -- to have the ending information to define scopes.
4295 -- For this case, we can ignore any parent references,
4296 -- but we need the package name itself for the 'e' entry.
4298 if Nkind (Endl) = N_Designator then
4299 Endl := Identifier (Endl);
4303 -- Reference is in extended main source unit
4308 -- For designator, generate references for the parent entries
4310 if Nkind (Endl) = N_Designator then
4312 -- Generate references for the prefix if the END line comes
4313 -- from source (otherwise we do not need these references)
4315 if Comes_From_Source (Endl) then
4317 while Nkind (Nam) = N_Selected_Component loop
4318 Generate_Parent_Ref (Selector_Name (Nam));
4319 Nam := Prefix (Nam);
4322 Generate_Parent_Ref (Nam);
4325 Endl := Identifier (Endl);
4329 -- Locate the entity to which the end label applies. Most of the
4330 -- time this is simply the current scope containing the construct.
4332 Ent := Current_Scope;
4334 if Chars (Ent) = Chars (Endl) then
4337 -- But in the case of single tasks and single protected objects,
4338 -- the current scope is the anonymous task or protected type and
4339 -- what we want is the object. There is no direct link so what we
4340 -- do is search ahead in the entity chain for the object with the
4341 -- matching type and name. In practice it is almost certain to be
4342 -- the very next entity on the chain, so this is not inefficient.
4345 Ctyp := Etype (Ent);
4349 -- If we don't find the entry we are looking for, that's
4350 -- odd, perhaps results from some error condition? Anyway
4351 -- the appropriate thing is just to abandon the attempt.
4356 -- Exit if we find the entity we are looking for
4358 elsif Etype (Ent) = Ctyp
4359 and then Chars (Ent) = Chars (Endl)
4366 -- If label was really there, then generate a normal reference
4367 -- and then adjust the location in the end label to point past
4368 -- the name (which should almost always be the semicolon).
4372 if Comes_From_Source (Endl) then
4374 -- If a label reference is required, then do the style check
4375 -- and generate a normal cross-reference entry for the label
4378 Style.Check_Identifier (Endl, Ent);
4379 Generate_Reference (Ent, Endl, 'r', Set_Ref => False);
4382 -- Set the location to point past the label (normally this will
4383 -- mean the semicolon immediately following the label). This is
4384 -- done for the sake of the 'e' or 't' entry generated below.
4386 Get_Decoded_Name_String (Chars (Endl));
4387 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
4390 -- Now generate the e/t reference
4392 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
4394 -- Restore Sloc, in case modified above, since we have an identifier
4395 -- and the normal Sloc should be left set in the tree.
4397 Set_Sloc (Endl, Loc);
4398 end Process_End_Label;
4404 -- We do the conversion to get the value of the real string by using
4405 -- the scanner, see Sinput for details on use of the internal source
4406 -- buffer for scanning internal strings.
4408 function Real_Convert (S : String) return Node_Id is
4409 Save_Src : constant Source_Buffer_Ptr := Source;
4413 Source := Internal_Source_Ptr;
4416 for J in S'Range loop
4417 Source (Source_Ptr (J)) := S (J);
4420 Source (S'Length + 1) := EOF;
4422 if Source (Scan_Ptr) = '-' then
4424 Scan_Ptr := Scan_Ptr + 1;
4432 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
4439 ------------------------------
4440 -- Requires_Transient_Scope --
4441 ------------------------------
4443 -- A transient scope is required when variable-sized temporaries are
4444 -- allocated in the primary or secondary stack, or when finalization
4445 -- actions must be generated before the next instruction
4447 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
4448 Typ : constant Entity_Id := Underlying_Type (Id);
4451 -- This is a private type which is not completed yet. This can only
4452 -- happen in a default expression (of a formal parameter or of a
4453 -- record component). Do not expand transient scope in this case
4458 elsif Typ = Standard_Void_Type then
4461 -- The back-end has trouble allocating variable-size temporaries so
4462 -- we generate them in the front-end and need a transient scope to
4463 -- reclaim them properly
4465 elsif not Size_Known_At_Compile_Time (Typ) then
4468 -- Unconstrained discriminated records always require a variable
4469 -- length temporary, since the length may depend on the variant.
4471 elsif Is_Record_Type (Typ)
4472 and then Has_Discriminants (Typ)
4473 and then not Is_Constrained (Typ)
4477 -- Functions returning tagged types may dispatch on result so their
4478 -- returned value is allocated on the secondary stack. Controlled
4479 -- type temporaries need finalization.
4481 elsif Is_Tagged_Type (Typ)
4482 or else Has_Controlled_Component (Typ)
4486 -- Unconstrained array types are returned on the secondary stack
4488 elsif Is_Array_Type (Typ) then
4489 return not Is_Constrained (Typ);
4493 end Requires_Transient_Scope;
4495 --------------------------
4496 -- Reset_Analyzed_Flags --
4497 --------------------------
4499 procedure Reset_Analyzed_Flags (N : Node_Id) is
4501 function Clear_Analyzed
4503 return Traverse_Result;
4504 -- Function used to reset Analyzed flags in tree. Note that we do
4505 -- not reset Analyzed flags in entities, since there is no need to
4506 -- renalalyze entities, and indeed, it is wrong to do so, since it
4507 -- can result in generating auxiliary stuff more than once.
4509 function Clear_Analyzed
4511 return Traverse_Result
4514 if not Has_Extension (N) then
4515 Set_Analyzed (N, False);
4521 function Reset_Analyzed is
4522 new Traverse_Func (Clear_Analyzed);
4524 Discard : Traverse_Result;
4526 -- Start of processing for Reset_Analyzed_Flags
4529 Discard := Reset_Analyzed (N);
4530 end Reset_Analyzed_Flags;
4536 function Same_Name (N1, N2 : Node_Id) return Boolean is
4537 K1 : constant Node_Kind := Nkind (N1);
4538 K2 : constant Node_Kind := Nkind (N2);
4541 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
4542 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
4544 return Chars (N1) = Chars (N2);
4546 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
4547 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
4549 return Same_Name (Selector_Name (N1), Selector_Name (N2))
4550 and then Same_Name (Prefix (N1), Prefix (N2));
4561 function Same_Type (T1, T2 : Entity_Id) return Boolean is
4566 elsif not Is_Constrained (T1)
4567 and then not Is_Constrained (T2)
4568 and then Base_Type (T1) = Base_Type (T2)
4572 -- For now don't bother with case of identical constraints, to be
4573 -- fiddled with later on perhaps (this is only used for optimization
4574 -- purposes, so it is not critical to do a best possible job)
4581 ------------------------
4582 -- Scope_Is_Transient --
4583 ------------------------
4585 function Scope_Is_Transient return Boolean is
4587 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
4588 end Scope_Is_Transient;
4594 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
4599 while Scop /= Standard_Standard loop
4600 Scop := Scope (Scop);
4602 if Scop = Scope2 then
4610 --------------------------
4611 -- Scope_Within_Or_Same --
4612 --------------------------
4614 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
4619 while Scop /= Standard_Standard loop
4620 if Scop = Scope2 then
4623 Scop := Scope (Scop);
4628 end Scope_Within_Or_Same;
4630 ------------------------
4631 -- Set_Current_Entity --
4632 ------------------------
4634 -- The given entity is to be set as the currently visible definition
4635 -- of its associated name (i.e. the Node_Id associated with its name).
4636 -- All we have to do is to get the name from the identifier, and
4637 -- then set the associated Node_Id to point to the given entity.
4639 procedure Set_Current_Entity (E : Entity_Id) is
4641 Set_Name_Entity_Id (Chars (E), E);
4642 end Set_Current_Entity;
4644 ---------------------------------
4645 -- Set_Entity_With_Style_Check --
4646 ---------------------------------
4648 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
4649 Val_Actual : Entity_Id;
4653 Set_Entity (N, Val);
4656 and then not Suppress_Style_Checks (Val)
4657 and then not In_Instance
4659 if Nkind (N) = N_Identifier then
4662 elsif Nkind (N) = N_Expanded_Name then
4663 Nod := Selector_Name (N);
4671 -- A special situation arises for derived operations, where we want
4672 -- to do the check against the parent (since the Sloc of the derived
4673 -- operation points to the derived type declaration itself).
4675 while not Comes_From_Source (Val_Actual)
4676 and then Nkind (Val_Actual) in N_Entity
4677 and then (Ekind (Val_Actual) = E_Enumeration_Literal
4678 or else Ekind (Val_Actual) = E_Function
4679 or else Ekind (Val_Actual) = E_Generic_Function
4680 or else Ekind (Val_Actual) = E_Procedure
4681 or else Ekind (Val_Actual) = E_Generic_Procedure)
4682 and then Present (Alias (Val_Actual))
4684 Val_Actual := Alias (Val_Actual);
4687 -- Renaming declarations for generic actuals do not come from source,
4688 -- and have a different name from that of the entity they rename, so
4689 -- there is no style check to perform here.
4691 if Chars (Nod) = Chars (Val_Actual) then
4692 Style.Check_Identifier (Nod, Val_Actual);
4697 Set_Entity (N, Val);
4698 end Set_Entity_With_Style_Check;
4700 ------------------------
4701 -- Set_Name_Entity_Id --
4702 ------------------------
4704 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
4706 Set_Name_Table_Info (Id, Int (Val));
4707 end Set_Name_Entity_Id;
4709 ---------------------
4710 -- Set_Next_Actual --
4711 ---------------------
4713 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
4715 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
4716 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
4718 end Set_Next_Actual;
4720 -----------------------
4721 -- Set_Public_Status --
4722 -----------------------
4724 procedure Set_Public_Status (Id : Entity_Id) is
4725 S : constant Entity_Id := Current_Scope;
4728 if S = Standard_Standard
4729 or else (Is_Public (S)
4730 and then (Ekind (S) = E_Package
4731 or else Is_Record_Type (S)
4732 or else Ekind (S) = E_Void))
4736 -- The bounds of an entry family declaration can generate object
4737 -- declarations that are visible to the back-end, e.g. in the
4738 -- the declaration of a composite type that contains tasks.
4741 and then Is_Concurrent_Type (S)
4742 and then not Has_Completion (S)
4743 and then Nkind (Parent (Id)) = N_Object_Declaration
4747 end Set_Public_Status;
4749 ----------------------------
4750 -- Set_Scope_Is_Transient --
4751 ----------------------------
4753 procedure Set_Scope_Is_Transient (V : Boolean := True) is
4755 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
4756 end Set_Scope_Is_Transient;
4762 procedure Set_Size_Info (T1, T2 : Entity_Id) is
4764 -- We copy Esize, but not RM_Size, since in general RM_Size is
4765 -- subtype specific and does not get inherited by all subtypes.
4767 Set_Esize (T1, Esize (T2));
4768 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
4770 if Is_Discrete_Or_Fixed_Point_Type (T1)
4772 Is_Discrete_Or_Fixed_Point_Type (T2)
4774 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
4777 Set_Alignment (T1, Alignment (T2));
4780 --------------------
4781 -- Static_Integer --
4782 --------------------
4784 function Static_Integer (N : Node_Id) return Uint is
4786 Analyze_And_Resolve (N, Any_Integer);
4789 or else Error_Posted (N)
4790 or else Etype (N) = Any_Type
4795 if Is_Static_Expression (N) then
4796 if not Raises_Constraint_Error (N) then
4797 return Expr_Value (N);
4802 elsif Etype (N) = Any_Type then
4806 Error_Msg_N ("static integer expression required here", N);
4811 --------------------------
4812 -- Statically_Different --
4813 --------------------------
4815 function Statically_Different (E1, E2 : Node_Id) return Boolean is
4816 R1 : constant Node_Id := Get_Referenced_Object (E1);
4817 R2 : constant Node_Id := Get_Referenced_Object (E2);
4820 return Is_Entity_Name (R1)
4821 and then Is_Entity_Name (R2)
4822 and then Entity (R1) /= Entity (R2)
4823 and then not Is_Formal (Entity (R1))
4824 and then not Is_Formal (Entity (R2));
4825 end Statically_Different;
4827 -----------------------------
4828 -- Subprogram_Access_Level --
4829 -----------------------------
4831 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
4833 if Present (Alias (Subp)) then
4834 return Subprogram_Access_Level (Alias (Subp));
4836 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
4838 end Subprogram_Access_Level;
4844 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
4846 if Debug_Flag_W then
4847 for J in 0 .. Scope_Stack.Last loop
4852 Write_Name (Chars (E));
4853 Write_Str (" line ");
4854 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
4859 -----------------------
4860 -- Transfer_Entities --
4861 -----------------------
4863 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
4864 Ent : Entity_Id := First_Entity (From);
4871 if (Last_Entity (To)) = Empty then
4872 Set_First_Entity (To, Ent);
4874 Set_Next_Entity (Last_Entity (To), Ent);
4877 Set_Last_Entity (To, Last_Entity (From));
4879 while Present (Ent) loop
4880 Set_Scope (Ent, To);
4882 if not Is_Public (Ent) then
4883 Set_Public_Status (Ent);
4886 and then Ekind (Ent) = E_Record_Subtype
4889 -- The components of the propagated Itype must be public
4896 Comp := First_Entity (Ent);
4898 while Present (Comp) loop
4899 Set_Is_Public (Comp);
4909 Set_First_Entity (From, Empty);
4910 Set_Last_Entity (From, Empty);
4911 end Transfer_Entities;
4913 -----------------------
4914 -- Type_Access_Level --
4915 -----------------------
4917 function Type_Access_Level (Typ : Entity_Id) return Uint is
4918 Btyp : Entity_Id := Base_Type (Typ);
4921 -- If the type is an anonymous access type we treat it as being
4922 -- declared at the library level to ensure that names such as
4923 -- X.all'access don't fail static accessibility checks.
4925 if Ekind (Btyp) in Access_Kind then
4926 if Ekind (Btyp) = E_Anonymous_Access_Type then
4927 return Scope_Depth (Standard_Standard);
4930 Btyp := Root_Type (Btyp);
4933 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
4934 end Type_Access_Level;
4936 --------------------------
4937 -- Unit_Declaration_Node --
4938 --------------------------
4940 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
4941 N : Node_Id := Parent (Unit_Id);
4944 -- Predefined operators do not have a full function declaration.
4946 if Ekind (Unit_Id) = E_Operator then
4950 while Nkind (N) /= N_Abstract_Subprogram_Declaration
4951 and then Nkind (N) /= N_Formal_Package_Declaration
4952 and then Nkind (N) /= N_Formal_Subprogram_Declaration
4953 and then Nkind (N) /= N_Function_Instantiation
4954 and then Nkind (N) /= N_Generic_Package_Declaration
4955 and then Nkind (N) /= N_Generic_Subprogram_Declaration
4956 and then Nkind (N) /= N_Package_Declaration
4957 and then Nkind (N) /= N_Package_Body
4958 and then Nkind (N) /= N_Package_Instantiation
4959 and then Nkind (N) /= N_Package_Renaming_Declaration
4960 and then Nkind (N) /= N_Procedure_Instantiation
4961 and then Nkind (N) /= N_Subprogram_Declaration
4962 and then Nkind (N) /= N_Subprogram_Body
4963 and then Nkind (N) /= N_Subprogram_Body_Stub
4964 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
4965 and then Nkind (N) /= N_Task_Body
4966 and then Nkind (N) /= N_Task_Type_Declaration
4967 and then Nkind (N) not in N_Generic_Renaming_Declaration
4970 pragma Assert (Present (N));
4974 end Unit_Declaration_Node;
4976 ----------------------
4977 -- Within_Init_Proc --
4978 ----------------------
4980 function Within_Init_Proc return Boolean is
4985 while not Is_Overloadable (S) loop
4986 if S = Standard_Standard then
4993 return Chars (S) = Name_uInit_Proc;
4994 end Within_Init_Proc;
5000 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
5001 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
5002 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
5004 function Has_One_Matching_Field return Boolean;
5005 -- Determines whether Expec_Type is a record type with a single
5006 -- component or discriminant whose type matches the found type or
5007 -- is a one dimensional array whose component type matches the
5010 function Has_One_Matching_Field return Boolean is
5014 if Is_Array_Type (Expec_Type)
5015 and then Number_Dimensions (Expec_Type) = 1
5017 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
5021 elsif not Is_Record_Type (Expec_Type) then
5025 E := First_Entity (Expec_Type);
5031 elsif (Ekind (E) /= E_Discriminant
5032 and then Ekind (E) /= E_Component)
5033 or else (Chars (E) = Name_uTag
5034 or else Chars (E) = Name_uParent)
5043 if not Covers (Etype (E), Found_Type) then
5046 elsif Present (Next_Entity (E)) then
5053 end Has_One_Matching_Field;
5055 -- Start of processing for Wrong_Type
5058 -- Don't output message if either type is Any_Type, or if a message
5059 -- has already been posted for this node. We need to do the latter
5060 -- check explicitly (it is ordinarily done in Errout), because we
5061 -- are using ! to force the output of the error messages.
5063 if Expec_Type = Any_Type
5064 or else Found_Type = Any_Type
5065 or else Error_Posted (Expr)
5069 -- In an instance, there is an ongoing problem with completion of
5070 -- type derived from private types. Their structure is what Gigi
5071 -- expects, but the Etype is the parent type rather than the
5072 -- derived private type itself. Do not flag error in this case. The
5073 -- private completion is an entity without a parent, like an Itype.
5074 -- Similarly, full and partial views may be incorrect in the instance.
5075 -- There is no simple way to insure that it is consistent ???
5077 elsif In_Instance then
5079 if Etype (Etype (Expr)) = Etype (Expected_Type)
5080 and then No (Parent (Expected_Type))
5086 -- An interesting special check. If the expression is parenthesized
5087 -- and its type corresponds to the type of the sole component of the
5088 -- expected record type, or to the component type of the expected one
5089 -- dimensional array type, then assume we have a bad aggregate attempt.
5091 if Nkind (Expr) in N_Subexpr
5092 and then Paren_Count (Expr) /= 0
5093 and then Has_One_Matching_Field
5095 Error_Msg_N ("positional aggregate cannot have one component", Expr);
5097 -- Another special check, if we are looking for a pool-specific access
5098 -- type and we found an E_Access_Attribute_Type, then we have the case
5099 -- of an Access attribute being used in a context which needs a pool-
5100 -- specific type, which is never allowed. The one extra check we make
5101 -- is that the expected designated type covers the Found_Type.
5103 elsif Is_Access_Type (Expec_Type)
5104 and then Ekind (Found_Type) = E_Access_Attribute_Type
5105 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
5106 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
5108 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
5110 Error_Msg_N ("result must be general access type!", Expr);
5111 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
5113 -- If the expected type is an anonymous access type, as for access
5114 -- parameters and discriminants, the error is on the designated types.
5116 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
5117 if Comes_From_Source (Expec_Type) then
5118 Error_Msg_NE ("expected}!", Expr, Expec_Type);
5121 ("expected an access type with designated}",
5122 Expr, Designated_Type (Expec_Type));
5125 if Is_Access_Type (Found_Type)
5126 and then not Comes_From_Source (Found_Type)
5129 ("found an access type with designated}!",
5130 Expr, Designated_Type (Found_Type));
5132 if From_With_Type (Found_Type) then
5133 Error_Msg_NE ("found incomplete}!", Expr, Found_Type);
5135 ("\possibly missing with_clause on&", Expr,
5136 Scope (Found_Type));
5138 Error_Msg_NE ("found}!", Expr, Found_Type);
5142 -- Normal case of one type found, some other type expected
5145 -- If the names of the two types are the same, see if some
5146 -- number of levels of qualification will help. Don't try
5147 -- more than three levels, and if we get to standard, it's
5148 -- no use (and probably represents an error in the compiler)
5149 -- Also do not bother with internal scope names.
5152 Expec_Scope : Entity_Id;
5153 Found_Scope : Entity_Id;
5156 Expec_Scope := Expec_Type;
5157 Found_Scope := Found_Type;
5159 for Levels in Int range 0 .. 3 loop
5160 if Chars (Expec_Scope) /= Chars (Found_Scope) then
5161 Error_Msg_Qual_Level := Levels;
5165 Expec_Scope := Scope (Expec_Scope);
5166 Found_Scope := Scope (Found_Scope);
5168 exit when Expec_Scope = Standard_Standard
5170 Found_Scope = Standard_Standard
5172 not Comes_From_Source (Expec_Scope)
5174 not Comes_From_Source (Found_Scope);
5178 Error_Msg_NE ("expected}!", Expr, Expec_Type);
5180 if Is_Entity_Name (Expr)
5181 and then Is_Package (Entity (Expr))
5183 Error_Msg_N ("found package name!", Expr);
5185 elsif Is_Entity_Name (Expr)
5187 (Ekind (Entity (Expr)) = E_Procedure
5189 Ekind (Entity (Expr)) = E_Generic_Procedure)
5191 Error_Msg_N ("found procedure name instead of function!", Expr);
5193 -- catch common error: a prefix or infix operator which is not
5194 -- directly visible because the type isn't.
5196 elsif Nkind (Expr) in N_Op
5197 and then Is_Overloaded (Expr)
5198 and then not Is_Immediately_Visible (Expec_Type)
5199 and then not Is_Potentially_Use_Visible (Expec_Type)
5200 and then not In_Use (Expec_Type)
5201 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
5204 "operator of the type is not directly visible!", Expr);
5207 Error_Msg_NE ("found}!", Expr, Found_Type);
5210 Error_Msg_Qual_Level := 0;