1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2002, 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 Reason : RT_Exception_Code;
112 Ent : Entity_Id := Empty;
113 Typ : Entity_Id := Empty;
114 Loc : Source_Ptr := No_Location;
115 Rep : Boolean := True)
117 Stat : constant Boolean := Is_Static_Expression (N);
127 if No (Compile_Time_Constraint_Error (N, Msg, Ent, Loc))
133 -- Now we replace the node by an N_Raise_Constraint_Error node
134 -- This does not need reanalyzing, so set it as analyzed now.
137 Make_Raise_Constraint_Error (Sloc (N),
139 Set_Analyzed (N, True);
141 Set_Raises_Constraint_Error (N);
143 -- If the original expression was marked as static, the result is
144 -- still marked as static, but the Raises_Constraint_Error flag is
145 -- always set so that further static evaluation is not attempted.
148 Set_Is_Static_Expression (N);
150 end Apply_Compile_Time_Constraint_Error;
152 --------------------------
153 -- Build_Actual_Subtype --
154 --------------------------
156 function Build_Actual_Subtype
158 N : Node_Or_Entity_Id)
163 Loc : constant Source_Ptr := Sloc (N);
164 Constraints : List_Id;
170 Disc_Type : Entity_Id;
173 if Nkind (N) = N_Defining_Identifier then
174 Obj := New_Reference_To (N, Loc);
179 if Is_Array_Type (T) then
180 Constraints := New_List;
182 for J in 1 .. Number_Dimensions (T) loop
184 -- Build an array subtype declaration with the nominal
185 -- subtype and the bounds of the actual. Add the declaration
186 -- in front of the local declarations for the subprogram,for
187 -- analysis before any reference to the formal in the body.
190 Make_Attribute_Reference (Loc,
191 Prefix => Duplicate_Subexpr (Obj, Name_Req => True),
192 Attribute_Name => Name_First,
193 Expressions => New_List (
194 Make_Integer_Literal (Loc, J)));
197 Make_Attribute_Reference (Loc,
198 Prefix => Duplicate_Subexpr (Obj, Name_Req => True),
199 Attribute_Name => Name_Last,
200 Expressions => New_List (
201 Make_Integer_Literal (Loc, J)));
203 Append (Make_Range (Loc, Lo, Hi), Constraints);
206 -- If the type has unknown discriminants there is no constrained
209 elsif Has_Unknown_Discriminants (T) then
213 Constraints := New_List;
215 if Is_Private_Type (T) and then No (Full_View (T)) then
217 -- Type is a generic derived type. Inherit discriminants from
220 Disc_Type := Etype (Base_Type (T));
225 Discr := First_Discriminant (Disc_Type);
227 while Present (Discr) loop
228 Append_To (Constraints,
229 Make_Selected_Component (Loc,
230 Prefix => Duplicate_Subexpr (Obj),
231 Selector_Name => New_Occurrence_Of (Discr, Loc)));
232 Next_Discriminant (Discr);
237 Make_Defining_Identifier (Loc,
238 Chars => New_Internal_Name ('S'));
239 Set_Is_Internal (Subt);
242 Make_Subtype_Declaration (Loc,
243 Defining_Identifier => Subt,
244 Subtype_Indication =>
245 Make_Subtype_Indication (Loc,
246 Subtype_Mark => New_Reference_To (T, Loc),
248 Make_Index_Or_Discriminant_Constraint (Loc,
249 Constraints => Constraints)));
251 Mark_Rewrite_Insertion (Decl);
253 end Build_Actual_Subtype;
255 ---------------------------------------
256 -- Build_Actual_Subtype_Of_Component --
257 ---------------------------------------
259 function Build_Actual_Subtype_Of_Component
264 Loc : constant Source_Ptr := Sloc (N);
265 P : constant Node_Id := Prefix (N);
268 Indx_Type : Entity_Id;
270 Deaccessed_T : Entity_Id;
271 -- This is either a copy of T, or if T is an access type, then it is
272 -- the directly designated type of this access type.
274 function Build_Actual_Array_Constraint return List_Id;
275 -- If one or more of the bounds of the component depends on
276 -- discriminants, build actual constraint using the discriminants
279 function Build_Actual_Record_Constraint return List_Id;
280 -- Similar to previous one, for discriminated components constrained
281 -- by the discriminant of the enclosing object.
283 -----------------------------------
284 -- Build_Actual_Array_Constraint --
285 -----------------------------------
287 function Build_Actual_Array_Constraint return List_Id is
288 Constraints : List_Id := New_List;
296 Indx := First_Index (Deaccessed_T);
297 while Present (Indx) loop
298 Old_Lo := Type_Low_Bound (Etype (Indx));
299 Old_Hi := Type_High_Bound (Etype (Indx));
301 if Denotes_Discriminant (Old_Lo) then
303 Make_Selected_Component (Loc,
304 Prefix => New_Copy_Tree (P),
305 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
308 Lo := New_Copy_Tree (Old_Lo);
310 -- The new bound will be reanalyzed in the enclosing
311 -- declaration. For literal bounds that come from a type
312 -- declaration, the type of the context must be imposed, so
313 -- insure that analysis will take place. For non-universal
314 -- types this is not strictly necessary.
316 Set_Analyzed (Lo, False);
319 if Denotes_Discriminant (Old_Hi) then
321 Make_Selected_Component (Loc,
322 Prefix => New_Copy_Tree (P),
323 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
326 Hi := New_Copy_Tree (Old_Hi);
327 Set_Analyzed (Hi, False);
330 Append (Make_Range (Loc, Lo, Hi), Constraints);
335 end Build_Actual_Array_Constraint;
337 ------------------------------------
338 -- Build_Actual_Record_Constraint --
339 ------------------------------------
341 function Build_Actual_Record_Constraint return List_Id is
342 Constraints : List_Id := New_List;
347 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
348 while Present (D) loop
350 if Denotes_Discriminant (Node (D)) then
351 D_Val := Make_Selected_Component (Loc,
352 Prefix => New_Copy_Tree (P),
353 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
356 D_Val := New_Copy_Tree (Node (D));
359 Append (D_Val, Constraints);
364 end Build_Actual_Record_Constraint;
366 -- Start of processing for Build_Actual_Subtype_Of_Component
369 if Nkind (N) = N_Explicit_Dereference then
370 if Is_Composite_Type (T)
371 and then not Is_Constrained (T)
372 and then not (Is_Class_Wide_Type (T)
373 and then Is_Constrained (Root_Type (T)))
374 and then not Has_Unknown_Discriminants (T)
376 -- If the type of the dereference is already constrained, it
377 -- is an actual subtype.
379 if Is_Array_Type (Etype (N))
380 and then Is_Constrained (Etype (N))
384 Remove_Side_Effects (P);
385 return Build_Actual_Subtype (T, N);
392 if Ekind (T) = E_Access_Subtype then
393 Deaccessed_T := Designated_Type (T);
398 if Ekind (Deaccessed_T) = E_Array_Subtype then
400 Id := First_Index (Deaccessed_T);
401 Indx_Type := Underlying_Type (Etype (Id));
403 while Present (Id) loop
405 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
406 Denotes_Discriminant (Type_High_Bound (Indx_Type))
408 Remove_Side_Effects (P);
410 Build_Component_Subtype (
411 Build_Actual_Array_Constraint, Loc, Base_Type (T));
417 elsif Is_Composite_Type (Deaccessed_T)
418 and then Has_Discriminants (Deaccessed_T)
419 and then not Has_Unknown_Discriminants (Deaccessed_T)
421 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
422 while Present (D) loop
424 if Denotes_Discriminant (Node (D)) then
425 Remove_Side_Effects (P);
427 Build_Component_Subtype (
428 Build_Actual_Record_Constraint, Loc, Base_Type (T));
435 -- If none of the above, the actual and nominal subtypes are the same.
439 end Build_Actual_Subtype_Of_Component;
441 -----------------------------
442 -- Build_Component_Subtype --
443 -----------------------------
445 function Build_Component_Subtype
456 Make_Defining_Identifier (Loc,
457 Chars => New_Internal_Name ('S'));
458 Set_Is_Internal (Subt);
461 Make_Subtype_Declaration (Loc,
462 Defining_Identifier => Subt,
463 Subtype_Indication =>
464 Make_Subtype_Indication (Loc,
465 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
467 Make_Index_Or_Discriminant_Constraint (Loc,
470 Mark_Rewrite_Insertion (Decl);
472 end Build_Component_Subtype;
474 --------------------------------------------
475 -- Build_Discriminal_Subtype_Of_Component --
476 --------------------------------------------
478 function Build_Discriminal_Subtype_Of_Component
482 Loc : constant Source_Ptr := Sloc (T);
486 function Build_Discriminal_Array_Constraint return List_Id;
487 -- If one or more of the bounds of the component depends on
488 -- discriminants, build actual constraint using the discriminants
491 function Build_Discriminal_Record_Constraint return List_Id;
492 -- Similar to previous one, for discriminated components constrained
493 -- by the discriminant of the enclosing object.
495 ----------------------------------------
496 -- Build_Discriminal_Array_Constraint --
497 ----------------------------------------
499 function Build_Discriminal_Array_Constraint return List_Id is
500 Constraints : List_Id := New_List;
508 Indx := First_Index (T);
509 while Present (Indx) loop
510 Old_Lo := Type_Low_Bound (Etype (Indx));
511 Old_Hi := Type_High_Bound (Etype (Indx));
513 if Denotes_Discriminant (Old_Lo) then
514 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
517 Lo := New_Copy_Tree (Old_Lo);
520 if Denotes_Discriminant (Old_Hi) then
521 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
524 Hi := New_Copy_Tree (Old_Hi);
527 Append (Make_Range (Loc, Lo, Hi), Constraints);
532 end Build_Discriminal_Array_Constraint;
534 -----------------------------------------
535 -- Build_Discriminal_Record_Constraint --
536 -----------------------------------------
538 function Build_Discriminal_Record_Constraint return List_Id is
539 Constraints : List_Id := New_List;
544 D := First_Elmt (Discriminant_Constraint (T));
545 while Present (D) loop
547 if Denotes_Discriminant (Node (D)) then
549 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
552 D_Val := New_Copy_Tree (Node (D));
555 Append (D_Val, Constraints);
560 end Build_Discriminal_Record_Constraint;
562 -- Start of processing for Build_Discriminal_Subtype_Of_Component
565 if Ekind (T) = E_Array_Subtype then
567 Id := First_Index (T);
569 while Present (Id) loop
571 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
572 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
574 return Build_Component_Subtype
575 (Build_Discriminal_Array_Constraint, Loc, T);
581 elsif Ekind (T) = E_Record_Subtype
582 and then Has_Discriminants (T)
583 and then not Has_Unknown_Discriminants (T)
585 D := First_Elmt (Discriminant_Constraint (T));
586 while Present (D) loop
588 if Denotes_Discriminant (Node (D)) then
589 return Build_Component_Subtype
590 (Build_Discriminal_Record_Constraint, Loc, T);
597 -- If none of the above, the actual and nominal subtypes are the same.
601 end Build_Discriminal_Subtype_Of_Component;
603 ------------------------------
604 -- Build_Elaboration_Entity --
605 ------------------------------
607 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
608 Loc : constant Source_Ptr := Sloc (N);
609 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
612 Elab_Ent : Entity_Id;
615 -- Ignore if already constructed
617 if Present (Elaboration_Entity (Spec_Id)) then
621 -- Construct name of elaboration entity as xxx_E, where xxx
622 -- is the unit name with dots replaced by double underscore.
623 -- We have to manually construct this name, since it will
624 -- be elaborated in the outer scope, and thus will not have
625 -- the unit name automatically prepended.
627 Get_Name_String (Unit_Name (Unum));
629 -- Replace the %s by _E
631 Name_Buffer (Name_Len - 1 .. Name_Len) := "_E";
633 -- Replace dots by double underscore
636 while P < Name_Len - 2 loop
637 if Name_Buffer (P) = '.' then
638 Name_Buffer (P + 2 .. Name_Len + 1) :=
639 Name_Buffer (P + 1 .. Name_Len);
640 Name_Len := Name_Len + 1;
641 Name_Buffer (P) := '_';
642 Name_Buffer (P + 1) := '_';
649 -- Create elaboration flag
652 Make_Defining_Identifier (Loc, Chars => Name_Find);
653 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
655 if No (Declarations (Aux_Decls_Node (N))) then
656 Set_Declarations (Aux_Decls_Node (N), New_List);
660 Make_Object_Declaration (Loc,
661 Defining_Identifier => Elab_Ent,
663 New_Occurrence_Of (Standard_Boolean, Loc),
665 New_Occurrence_Of (Standard_False, Loc));
667 Append_To (Declarations (Aux_Decls_Node (N)), Decl);
670 -- Reset True_Constant indication, since we will indeed
671 -- assign a value to the variable in the binder main.
673 Set_Is_True_Constant (Elab_Ent, False);
675 -- We do not want any further qualification of the name (if we did
676 -- not do this, we would pick up the name of the generic package
677 -- in the case of a library level generic instantiation).
679 Set_Has_Qualified_Name (Elab_Ent);
680 Set_Has_Fully_Qualified_Name (Elab_Ent);
681 end Build_Elaboration_Entity;
683 -----------------------------------
684 -- Cannot_Raise_Constraint_Error --
685 -----------------------------------
687 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
689 if Compile_Time_Known_Value (Expr) then
692 elsif Do_Range_Check (Expr) then
695 elsif Raises_Constraint_Error (Expr) then
703 when N_Expanded_Name =>
706 when N_Selected_Component =>
707 return not Do_Discriminant_Check (Expr);
709 when N_Attribute_Reference =>
710 if Do_Overflow_Check (Expr)
711 or else Do_Access_Check (Expr)
715 elsif No (Expressions (Expr)) then
720 N : Node_Id := First (Expressions (Expr));
723 while Present (N) loop
724 if Cannot_Raise_Constraint_Error (N) then
735 when N_Type_Conversion =>
736 if Do_Overflow_Check (Expr)
737 or else Do_Length_Check (Expr)
738 or else Do_Tag_Check (Expr)
743 Cannot_Raise_Constraint_Error (Expression (Expr));
746 when N_Unchecked_Type_Conversion =>
747 return Cannot_Raise_Constraint_Error (Expression (Expr));
750 if Do_Overflow_Check (Expr) then
754 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
761 if Do_Division_Check (Expr)
762 or else Do_Overflow_Check (Expr)
767 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
769 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
788 N_Op_Shift_Right_Arithmetic |
792 if Do_Overflow_Check (Expr) then
796 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
798 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
805 end Cannot_Raise_Constraint_Error;
807 --------------------------
808 -- Check_Fully_Declared --
809 --------------------------
811 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
813 if Ekind (T) = E_Incomplete_Type then
815 ("premature usage of incomplete}", N, First_Subtype (T));
817 elsif Has_Private_Component (T)
818 and then not Is_Generic_Type (Root_Type (T))
819 and then not In_Default_Expression
822 ("premature usage of incomplete}", N, First_Subtype (T));
824 end Check_Fully_Declared;
826 ------------------------------------------
827 -- Check_Potentially_Blocking_Operation --
828 ------------------------------------------
830 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
832 Loc : constant Source_Ptr := Sloc (N);
835 -- N is one of the potentially blocking operations listed in
836 -- 9.5.1 (8). When using the Ravenscar profile, raise Program_Error
837 -- before N if the context is a protected action. Otherwise, only issue
838 -- a warning, since some users are relying on blocking operations
839 -- inside protected objects.
840 -- Indirect blocking through a subprogram call
841 -- cannot be diagnosed statically without interprocedural analysis,
842 -- so we do not attempt to do it here.
844 S := Scope (Current_Scope);
846 while Present (S) and then S /= Standard_Standard loop
847 if Is_Protected_Type (S) then
848 if Restricted_Profile then
850 Make_Raise_Program_Error (Loc,
851 Reason => PE_Potentially_Blocking_Operation));
852 Error_Msg_N ("potentially blocking operation, " &
853 " Program Error will be raised at run time?", N);
857 ("potentially blocking operation in protected operation?", N);
865 end Check_Potentially_Blocking_Operation;
871 procedure Check_VMS (Construct : Node_Id) is
873 if not OpenVMS_On_Target then
875 ("this construct is allowed only in Open'V'M'S", Construct);
879 ----------------------------------
880 -- Collect_Primitive_Operations --
881 ----------------------------------
883 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
884 B_Type : constant Entity_Id := Base_Type (T);
885 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
886 B_Scope : Entity_Id := Scope (B_Type);
890 Formal_Derived : Boolean := False;
894 -- For tagged types, the primitive operations are collected as they
895 -- are declared, and held in an explicit list which is simply returned.
897 if Is_Tagged_Type (B_Type) then
898 return Primitive_Operations (B_Type);
900 -- An untagged generic type that is a derived type inherits the
901 -- primitive operations of its parent type. Other formal types only
902 -- have predefined operators, which are not explicitly represented.
904 elsif Is_Generic_Type (B_Type) then
905 if Nkind (B_Decl) = N_Formal_Type_Declaration
906 and then Nkind (Formal_Type_Definition (B_Decl))
907 = N_Formal_Derived_Type_Definition
909 Formal_Derived := True;
911 return New_Elmt_List;
915 Op_List := New_Elmt_List;
917 if B_Scope = Standard_Standard then
918 if B_Type = Standard_String then
919 Append_Elmt (Standard_Op_Concat, Op_List);
921 elsif B_Type = Standard_Wide_String then
922 Append_Elmt (Standard_Op_Concatw, Op_List);
928 elsif (Is_Package (B_Scope)
930 Parent (Declaration_Node (First_Subtype (T))))
933 or else Is_Derived_Type (B_Type)
935 -- The primitive operations appear after the base type, except
936 -- if the derivation happens within the private part of B_Scope
937 -- and the type is a private type, in which case both the type
938 -- and some primitive operations may appear before the base
939 -- type, and the list of candidates starts after the type.
941 if In_Open_Scopes (B_Scope)
942 and then Scope (T) = B_Scope
943 and then In_Private_Part (B_Scope)
945 Id := Next_Entity (T);
947 Id := Next_Entity (B_Type);
950 while Present (Id) loop
952 -- Note that generic formal subprograms are not
953 -- considered to be primitive operations and thus
954 -- are never inherited.
956 if Is_Overloadable (Id)
957 and then Nkind (Parent (Parent (Id)))
958 /= N_Formal_Subprogram_Declaration
962 if Base_Type (Etype (Id)) = B_Type then
965 Formal := First_Formal (Id);
966 while Present (Formal) loop
967 if Base_Type (Etype (Formal)) = B_Type then
971 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
973 (Designated_Type (Etype (Formal))) = B_Type
979 Next_Formal (Formal);
983 -- For a formal derived type, the only primitives are the
984 -- ones inherited from the parent type. Operations appearing
985 -- in the package declaration are not primitive for it.
988 and then (not Formal_Derived
989 or else Present (Alias (Id)))
991 Append_Elmt (Id, Op_List);
997 -- For a type declared in System, some of its operations
998 -- may appear in the target-specific extension to System.
1001 and then Chars (B_Scope) = Name_System
1002 and then Scope (B_Scope) = Standard_Standard
1003 and then Present_System_Aux
1005 B_Scope := System_Aux_Id;
1006 Id := First_Entity (System_Aux_Id);
1014 end Collect_Primitive_Operations;
1016 -----------------------------------
1017 -- Compile_Time_Constraint_Error --
1018 -----------------------------------
1020 function Compile_Time_Constraint_Error
1023 Ent : Entity_Id := Empty;
1024 Loc : Source_Ptr := No_Location)
1027 Msgc : String (1 .. Msg'Length + 2);
1035 -- A static constraint error in an instance body is not a fatal error.
1036 -- we choose to inhibit the message altogether, because there is no
1037 -- obvious node (for now) on which to post it. On the other hand the
1038 -- offending node must be replaced with a constraint_error in any case.
1040 -- No messages are generated if we already posted an error on this node
1042 if not Error_Posted (N) then
1043 if Loc /= No_Location then
1049 -- Make all such messages unconditional
1051 Msgc (1 .. Msg'Length) := Msg;
1052 Msgc (Msg'Length + 1) := '!';
1053 Msgl := Msg'Length + 1;
1055 -- Message is a warning, even in Ada 95 case
1057 if Msg (Msg'Length) = '?' then
1060 -- In Ada 83, all messages are warnings. In the private part and
1061 -- the body of an instance, constraint_checks are only warnings.
1063 elsif Ada_83 and then Comes_From_Source (N) then
1069 elsif In_Instance_Not_Visible then
1074 Warn_On_Instance := True;
1076 -- Otherwise we have a real error message (Ada 95 static case)
1082 -- Should we generate a warning? The answer is not quite yes. The
1083 -- very annoying exception occurs in the case of a short circuit
1084 -- operator where the left operand is static and decisive. Climb
1085 -- parents to see if that is the case we have here.
1093 if (Nkind (P) = N_And_Then
1094 and then Compile_Time_Known_Value (Left_Opnd (P))
1095 and then Is_False (Expr_Value (Left_Opnd (P))))
1096 or else (Nkind (P) = N_Or_Else
1097 and then Compile_Time_Known_Value (Left_Opnd (P))
1098 and then Is_True (Expr_Value (Left_Opnd (P))))
1103 elsif Nkind (P) = N_Component_Association
1104 and then Nkind (Parent (P)) = N_Aggregate
1106 null; -- Keep going.
1109 exit when Nkind (P) not in N_Subexpr;
1114 if Present (Ent) then
1115 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1117 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1121 if Inside_Init_Proc then
1123 ("\& will be raised for objects of this type!?",
1124 N, Standard_Constraint_Error, Eloc);
1127 ("\& will be raised at run time!?",
1128 N, Standard_Constraint_Error, Eloc);
1132 ("\static expression raises&!",
1133 N, Standard_Constraint_Error, Eloc);
1139 end Compile_Time_Constraint_Error;
1141 -----------------------
1142 -- Conditional_Delay --
1143 -----------------------
1145 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1147 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1148 Set_Has_Delayed_Freeze (New_Ent);
1150 end Conditional_Delay;
1152 --------------------
1153 -- Current_Entity --
1154 --------------------
1156 -- The currently visible definition for a given identifier is the
1157 -- one most chained at the start of the visibility chain, i.e. the
1158 -- one that is referenced by the Node_Id value of the name of the
1159 -- given identifier.
1161 function Current_Entity (N : Node_Id) return Entity_Id is
1163 return Get_Name_Entity_Id (Chars (N));
1166 -----------------------------
1167 -- Current_Entity_In_Scope --
1168 -----------------------------
1170 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1172 CS : constant Entity_Id := Current_Scope;
1174 Transient_Case : constant Boolean := Scope_Is_Transient;
1177 E := Get_Name_Entity_Id (Chars (N));
1180 and then Scope (E) /= CS
1181 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1187 end Current_Entity_In_Scope;
1193 function Current_Scope return Entity_Id is
1195 if Scope_Stack.Last = -1 then
1196 return Standard_Standard;
1199 C : constant Entity_Id :=
1200 Scope_Stack.Table (Scope_Stack.Last).Entity;
1205 return Standard_Standard;
1211 ------------------------
1212 -- Current_Subprogram --
1213 ------------------------
1215 function Current_Subprogram return Entity_Id is
1216 Scop : constant Entity_Id := Current_Scope;
1219 if Ekind (Scop) = E_Function
1221 Ekind (Scop) = E_Procedure
1223 Ekind (Scop) = E_Generic_Function
1225 Ekind (Scop) = E_Generic_Procedure
1230 return Enclosing_Subprogram (Scop);
1232 end Current_Subprogram;
1234 ---------------------
1235 -- Defining_Entity --
1236 ---------------------
1238 function Defining_Entity (N : Node_Id) return Entity_Id is
1239 K : constant Node_Kind := Nkind (N);
1240 Err : Entity_Id := Empty;
1245 N_Subprogram_Declaration |
1246 N_Abstract_Subprogram_Declaration |
1248 N_Package_Declaration |
1249 N_Subprogram_Renaming_Declaration |
1250 N_Subprogram_Body_Stub |
1251 N_Generic_Subprogram_Declaration |
1252 N_Generic_Package_Declaration |
1253 N_Formal_Subprogram_Declaration
1255 return Defining_Entity (Specification (N));
1258 N_Component_Declaration |
1259 N_Defining_Program_Unit_Name |
1260 N_Discriminant_Specification |
1262 N_Entry_Declaration |
1263 N_Entry_Index_Specification |
1264 N_Exception_Declaration |
1265 N_Exception_Renaming_Declaration |
1266 N_Formal_Object_Declaration |
1267 N_Formal_Package_Declaration |
1268 N_Formal_Type_Declaration |
1269 N_Full_Type_Declaration |
1270 N_Implicit_Label_Declaration |
1271 N_Incomplete_Type_Declaration |
1272 N_Loop_Parameter_Specification |
1273 N_Number_Declaration |
1274 N_Object_Declaration |
1275 N_Object_Renaming_Declaration |
1276 N_Package_Body_Stub |
1277 N_Parameter_Specification |
1278 N_Private_Extension_Declaration |
1279 N_Private_Type_Declaration |
1281 N_Protected_Body_Stub |
1282 N_Protected_Type_Declaration |
1283 N_Single_Protected_Declaration |
1284 N_Single_Task_Declaration |
1285 N_Subtype_Declaration |
1288 N_Task_Type_Declaration
1290 return Defining_Identifier (N);
1293 return Defining_Entity (Proper_Body (N));
1296 N_Function_Instantiation |
1297 N_Function_Specification |
1298 N_Generic_Function_Renaming_Declaration |
1299 N_Generic_Package_Renaming_Declaration |
1300 N_Generic_Procedure_Renaming_Declaration |
1302 N_Package_Instantiation |
1303 N_Package_Renaming_Declaration |
1304 N_Package_Specification |
1305 N_Procedure_Instantiation |
1306 N_Procedure_Specification
1309 Nam : constant Node_Id := Defining_Unit_Name (N);
1312 if Nkind (Nam) in N_Entity then
1315 -- For Error, make up a name and attach to declaration
1316 -- so we can continue semantic analysis
1318 elsif Nam = Error then
1320 Make_Defining_Identifier (Sloc (N),
1321 Chars => New_Internal_Name ('T'));
1322 Set_Defining_Unit_Name (N, Err);
1325 -- If not an entity, get defining identifier
1328 return Defining_Identifier (Nam);
1332 when N_Block_Statement =>
1333 return Entity (Identifier (N));
1336 raise Program_Error;
1339 end Defining_Entity;
1341 --------------------------
1342 -- Denotes_Discriminant --
1343 --------------------------
1345 function Denotes_Discriminant (N : Node_Id) return Boolean is
1347 return Is_Entity_Name (N)
1348 and then Present (Entity (N))
1349 and then Ekind (Entity (N)) = E_Discriminant;
1350 end Denotes_Discriminant;
1352 -----------------------------
1353 -- Depends_On_Discriminant --
1354 -----------------------------
1356 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1361 Get_Index_Bounds (N, L, H);
1362 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1363 end Depends_On_Discriminant;
1365 -------------------------
1366 -- Designate_Same_Unit --
1367 -------------------------
1369 function Designate_Same_Unit
1374 K1 : Node_Kind := Nkind (Name1);
1375 K2 : Node_Kind := Nkind (Name2);
1377 function Prefix_Node (N : Node_Id) return Node_Id;
1378 -- Returns the parent unit name node of a defining program unit name
1379 -- or the prefix if N is a selected component or an expanded name.
1381 function Select_Node (N : Node_Id) return Node_Id;
1382 -- Returns the defining identifier node of a defining program unit
1383 -- name or the selector node if N is a selected component or an
1386 function Prefix_Node (N : Node_Id) return Node_Id is
1388 if Nkind (N) = N_Defining_Program_Unit_Name then
1396 function Select_Node (N : Node_Id) return Node_Id is
1398 if Nkind (N) = N_Defining_Program_Unit_Name then
1399 return Defining_Identifier (N);
1402 return Selector_Name (N);
1406 -- Start of processing for Designate_Next_Unit
1409 if (K1 = N_Identifier or else
1410 K1 = N_Defining_Identifier)
1412 (K2 = N_Identifier or else
1413 K2 = N_Defining_Identifier)
1415 return Chars (Name1) = Chars (Name2);
1418 (K1 = N_Expanded_Name or else
1419 K1 = N_Selected_Component or else
1420 K1 = N_Defining_Program_Unit_Name)
1422 (K2 = N_Expanded_Name or else
1423 K2 = N_Selected_Component or else
1424 K2 = N_Defining_Program_Unit_Name)
1427 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
1429 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
1434 end Designate_Same_Unit;
1436 ----------------------------
1437 -- Enclosing_Generic_Body --
1438 ----------------------------
1440 function Enclosing_Generic_Body
1451 while Present (P) loop
1452 if Nkind (P) = N_Package_Body
1453 or else Nkind (P) = N_Subprogram_Body
1455 Spec := Corresponding_Spec (P);
1457 if Present (Spec) then
1458 Decl := Unit_Declaration_Node (Spec);
1460 if Nkind (Decl) = N_Generic_Package_Declaration
1461 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1472 end Enclosing_Generic_Body;
1474 -------------------------------
1475 -- Enclosing_Lib_Unit_Entity --
1476 -------------------------------
1478 function Enclosing_Lib_Unit_Entity return Entity_Id is
1479 Unit_Entity : Entity_Id := Current_Scope;
1482 -- Look for enclosing library unit entity by following scope links.
1483 -- Equivalent to, but faster than indexing through the scope stack.
1485 while (Present (Scope (Unit_Entity))
1486 and then Scope (Unit_Entity) /= Standard_Standard)
1487 and not Is_Child_Unit (Unit_Entity)
1489 Unit_Entity := Scope (Unit_Entity);
1493 end Enclosing_Lib_Unit_Entity;
1495 -----------------------------
1496 -- Enclosing_Lib_Unit_Node --
1497 -----------------------------
1499 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
1500 Current_Node : Node_Id := N;
1503 while Present (Current_Node)
1504 and then Nkind (Current_Node) /= N_Compilation_Unit
1506 Current_Node := Parent (Current_Node);
1509 if Nkind (Current_Node) /= N_Compilation_Unit then
1513 return Current_Node;
1514 end Enclosing_Lib_Unit_Node;
1516 --------------------------
1517 -- Enclosing_Subprogram --
1518 --------------------------
1520 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
1521 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
1524 if Dynamic_Scope = Standard_Standard then
1527 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
1528 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
1530 elsif Ekind (Dynamic_Scope) = E_Block then
1531 return Enclosing_Subprogram (Dynamic_Scope);
1533 elsif Ekind (Dynamic_Scope) = E_Task_Type then
1534 return Get_Task_Body_Procedure (Dynamic_Scope);
1536 elsif Convention (Dynamic_Scope) = Convention_Protected then
1537 return Protected_Body_Subprogram (Dynamic_Scope);
1540 return Dynamic_Scope;
1542 end Enclosing_Subprogram;
1544 ------------------------
1545 -- Ensure_Freeze_Node --
1546 ------------------------
1548 procedure Ensure_Freeze_Node (E : Entity_Id) is
1552 if No (Freeze_Node (E)) then
1553 FN := Make_Freeze_Entity (Sloc (E));
1554 Set_Has_Delayed_Freeze (E);
1555 Set_Freeze_Node (E, FN);
1556 Set_Access_Types_To_Process (FN, No_Elist);
1557 Set_TSS_Elist (FN, No_Elist);
1560 end Ensure_Freeze_Node;
1566 procedure Enter_Name (Def_Id : Node_Id) is
1567 C : constant Entity_Id := Current_Entity (Def_Id);
1568 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
1569 S : constant Entity_Id := Current_Scope;
1572 Generate_Definition (Def_Id);
1574 -- Add new name to current scope declarations. Check for duplicate
1575 -- declaration, which may or may not be a genuine error.
1579 -- Case of previous entity entered because of a missing declaration
1580 -- or else a bad subtype indication. Best is to use the new entity,
1581 -- and make the previous one invisible.
1583 if Etype (E) = Any_Type then
1584 Set_Is_Immediately_Visible (E, False);
1586 -- Case of renaming declaration constructed for package instances.
1587 -- if there is an explicit declaration with the same identifier,
1588 -- the renaming is not immediately visible any longer, but remains
1589 -- visible through selected component notation.
1591 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
1592 and then not Comes_From_Source (E)
1594 Set_Is_Immediately_Visible (E, False);
1596 -- The new entity may be the package renaming, which has the same
1597 -- same name as a generic formal which has been seen already.
1599 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
1600 and then not Comes_From_Source (Def_Id)
1602 Set_Is_Immediately_Visible (E, False);
1604 -- For a fat pointer corresponding to a remote access to subprogram,
1605 -- we use the same identifier as the RAS type, so that the proper
1606 -- name appears in the stub. This type is only retrieved through
1607 -- the RAS type and never by visibility, and is not added to the
1608 -- visibility list (see below).
1610 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
1611 and then Present (Corresponding_Remote_Type (Def_Id))
1615 -- A controller component for a type extension overrides the
1616 -- inherited component.
1618 elsif Chars (E) = Name_uController then
1621 -- Case of an implicit operation or derived literal. The new entity
1622 -- hides the implicit one, which is removed from all visibility,
1623 -- i.e. the entity list of its scope, and homonym chain of its name.
1625 elsif (Is_Overloadable (E) and then Present (Alias (E)))
1626 or else Is_Internal (E)
1627 or else (Ekind (E) = E_Enumeration_Literal
1628 and then Is_Derived_Type (Etype (E)))
1632 Prev_Vis : Entity_Id;
1635 -- If E is an implicit declaration, it cannot be the first
1636 -- entity in the scope.
1638 Prev := First_Entity (Current_Scope);
1640 while Next_Entity (Prev) /= E loop
1644 Set_Next_Entity (Prev, Next_Entity (E));
1646 if No (Next_Entity (Prev)) then
1647 Set_Last_Entity (Current_Scope, Prev);
1650 if E = Current_Entity (E) then
1653 Prev_Vis := Current_Entity (E);
1654 while Homonym (Prev_Vis) /= E loop
1655 Prev_Vis := Homonym (Prev_Vis);
1659 if Present (Prev_Vis) then
1661 -- Skip E in the visibility chain
1663 Set_Homonym (Prev_Vis, Homonym (E));
1666 Set_Name_Entity_Id (Chars (E), Homonym (E));
1670 -- This section of code could use a comment ???
1672 elsif Present (Etype (E))
1673 and then Is_Concurrent_Type (Etype (E))
1678 -- In the body or private part of an instance, a type extension
1679 -- may introduce a component with the same name as that of an
1680 -- actual. The legality rule is not enforced, but the semantics
1681 -- of the full type with two components of the same name are not
1682 -- clear at this point ???
1684 elsif In_Instance_Not_Visible then
1687 -- When compiling a package body, some child units may have become
1688 -- visible. They cannot conflict with local entities that hide them.
1690 elsif Is_Child_Unit (E)
1691 and then In_Open_Scopes (Scope (E))
1692 and then not Is_Immediately_Visible (E)
1696 -- Conversely, with front-end inlining we may compile the parent
1697 -- body first, and a child unit subsequently. The context is now
1698 -- the parent spec, and body entities are not visible.
1700 elsif Is_Child_Unit (Def_Id)
1701 and then Is_Package_Body_Entity (E)
1702 and then not In_Package_Body (Current_Scope)
1706 -- Case of genuine duplicate declaration
1709 Error_Msg_Sloc := Sloc (E);
1711 -- If the previous declaration is an incomplete type declaration
1712 -- this may be an attempt to complete it with a private type.
1713 -- The following avoids confusing cascaded errors.
1715 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
1716 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
1719 ("incomplete type cannot be completed" &
1720 " with a private declaration",
1722 Set_Is_Immediately_Visible (E, False);
1723 Set_Full_View (E, Def_Id);
1725 elsif Ekind (E) = E_Discriminant
1726 and then Present (Scope (Def_Id))
1727 and then Scope (Def_Id) /= Current_Scope
1729 -- An inherited component of a record conflicts with
1730 -- a new discriminant. The discriminant is inserted first
1731 -- in the scope, but the error should be posted on it, not
1732 -- on the component.
1734 Error_Msg_Sloc := Sloc (Def_Id);
1735 Error_Msg_N ("& conflicts with declaration#", E);
1738 -- If the name of the unit appears in its own context clause,
1739 -- a dummy package with the name has already been created, and
1740 -- the error emitted. Try to continue quietly.
1742 elsif Error_Posted (E)
1743 and then Sloc (E) = No_Location
1744 and then Nkind (Parent (E)) = N_Package_Specification
1745 and then Current_Scope = Standard_Standard
1747 Set_Scope (Def_Id, Current_Scope);
1751 Error_Msg_N ("& conflicts with declaration#", Def_Id);
1753 -- Avoid cascaded messages with duplicate components in
1756 if Ekind (E) = E_Component
1757 or else Ekind (E) = E_Discriminant
1763 if Nkind (Parent (Parent (Def_Id)))
1764 = N_Generic_Subprogram_Declaration
1766 Defining_Entity (Specification (Parent (Parent (Def_Id))))
1768 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
1771 -- If entity is in standard, then we are in trouble, because
1772 -- it means that we have a library package with a duplicated
1773 -- name. That's hard to recover from, so abort!
1775 if S = Standard_Standard then
1776 raise Unrecoverable_Error;
1778 -- Otherwise we continue with the declaration. Having two
1779 -- identical declarations should not cause us too much trouble!
1787 -- If we fall through, declaration is OK , or OK enough to continue
1789 -- If Def_Id is a discriminant or a record component we are in the
1790 -- midst of inheriting components in a derived record definition.
1791 -- Preserve their Ekind and Etype.
1793 if Ekind (Def_Id) = E_Discriminant
1794 or else Ekind (Def_Id) = E_Component
1798 -- If a type is already set, leave it alone (happens whey a type
1799 -- declaration is reanalyzed following a call to the optimizer)
1801 elsif Present (Etype (Def_Id)) then
1804 -- Otherwise, the kind E_Void insures that premature uses of the entity
1805 -- will be detected. Any_Type insures that no cascaded errors will occur
1808 Set_Ekind (Def_Id, E_Void);
1809 Set_Etype (Def_Id, Any_Type);
1812 -- Inherited discriminants and components in derived record types are
1813 -- immediately visible. Itypes are not.
1815 if Ekind (Def_Id) = E_Discriminant
1816 or else Ekind (Def_Id) = E_Component
1817 or else (No (Corresponding_Remote_Type (Def_Id))
1818 and then not Is_Itype (Def_Id))
1820 Set_Is_Immediately_Visible (Def_Id);
1821 Set_Current_Entity (Def_Id);
1824 Set_Homonym (Def_Id, C);
1825 Append_Entity (Def_Id, S);
1826 Set_Public_Status (Def_Id);
1828 -- Warn if new entity hides an old one
1831 and then Length_Of_Name (Chars (C)) /= 1
1832 and then Present (C)
1833 and then Comes_From_Source (C)
1834 and then Comes_From_Source (Def_Id)
1835 and then In_Extended_Main_Source_Unit (Def_Id)
1837 Error_Msg_Sloc := Sloc (C);
1838 Error_Msg_N ("declaration hides &#?", Def_Id);
1843 -------------------------------------
1844 -- Find_Corresponding_Discriminant --
1845 -------------------------------------
1847 function Find_Corresponding_Discriminant
1852 Par_Disc : Entity_Id;
1853 Old_Disc : Entity_Id;
1854 New_Disc : Entity_Id;
1857 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
1858 Old_Disc := First_Discriminant (Scope (Par_Disc));
1860 if Is_Class_Wide_Type (Typ) then
1861 New_Disc := First_Discriminant (Root_Type (Typ));
1863 New_Disc := First_Discriminant (Typ);
1866 while Present (Old_Disc) and then Present (New_Disc) loop
1867 if Old_Disc = Par_Disc then
1870 Next_Discriminant (Old_Disc);
1871 Next_Discriminant (New_Disc);
1875 -- Should always find it
1877 raise Program_Error;
1878 end Find_Corresponding_Discriminant;
1884 function First_Actual (Node : Node_Id) return Node_Id is
1888 if No (Parameter_Associations (Node)) then
1892 N := First (Parameter_Associations (Node));
1894 if Nkind (N) = N_Parameter_Association then
1895 return First_Named_Actual (Node);
1901 -------------------------
1902 -- Full_Qualified_Name --
1903 -------------------------
1905 function Full_Qualified_Name (E : Entity_Id) return String_Id is
1909 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
1910 -- Compute recursively the qualified name without NUL at the end.
1912 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
1913 Ent : Entity_Id := E;
1914 Parent_Name : String_Id := No_String;
1917 -- Deals properly with child units
1919 if Nkind (Ent) = N_Defining_Program_Unit_Name then
1920 Ent := Defining_Identifier (Ent);
1923 -- Compute recursively the qualification. Only "Standard" has no
1926 if Present (Scope (Scope (Ent))) then
1927 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
1930 -- Every entity should have a name except some expanded blocks
1931 -- don't bother about those.
1933 if Chars (Ent) = No_Name then
1937 -- Add a period between Name and qualification
1939 if Parent_Name /= No_String then
1940 Start_String (Parent_Name);
1941 Store_String_Char (Get_Char_Code ('.'));
1947 -- Generates the entity name in upper case
1949 Get_Name_String (Chars (Ent));
1951 Store_String_Chars (Name_Buffer (1 .. Name_Len));
1953 end Internal_Full_Qualified_Name;
1956 Res := Internal_Full_Qualified_Name (E);
1957 Store_String_Char (Get_Char_Code (ASCII.nul));
1959 end Full_Qualified_Name;
1961 -----------------------
1962 -- Gather_Components --
1963 -----------------------
1965 procedure Gather_Components
1967 Comp_List : Node_Id;
1968 Governed_By : List_Id;
1970 Report_Errors : out Boolean)
1974 Discrete_Choice : Node_Id;
1975 Comp_Item : Node_Id;
1977 Discrim : Entity_Id;
1978 Discrim_Name : Node_Id;
1979 Discrim_Value : Node_Id;
1982 Report_Errors := False;
1984 if No (Comp_List) or else Null_Present (Comp_List) then
1987 elsif Present (Component_Items (Comp_List)) then
1988 Comp_Item := First (Component_Items (Comp_List));
1994 while Present (Comp_Item) loop
1996 -- Skip the tag of a tagged record, as well as all items
1997 -- that are not user components (anonymous types, rep clauses,
1998 -- Parent field, controller field).
2000 if Nkind (Comp_Item) = N_Component_Declaration
2001 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uTag
2002 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uParent
2003 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uController
2005 Append_Elmt (Defining_Identifier (Comp_Item), Into);
2011 if No (Variant_Part (Comp_List)) then
2014 Discrim_Name := Name (Variant_Part (Comp_List));
2015 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
2018 -- Look for the discriminant that governs this variant part.
2019 -- The discriminant *must* be in the Governed_By List
2021 Assoc := First (Governed_By);
2022 Find_Constraint : loop
2023 Discrim := First (Choices (Assoc));
2024 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
2025 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
2027 Chars (Corresponding_Discriminant (Entity (Discrim)))
2028 = Chars (Discrim_Name))
2029 or else Chars (Original_Record_Component (Entity (Discrim)))
2030 = Chars (Discrim_Name);
2032 if No (Next (Assoc)) then
2033 if not Is_Constrained (Typ)
2034 and then Is_Derived_Type (Typ)
2035 and then Present (Girder_Constraint (Typ))
2038 -- If the type is a tagged type with inherited discriminants,
2039 -- use the girder constraint on the parent in order to find
2040 -- the values of discriminants that are otherwise hidden by an
2041 -- explicit constraint. Renamed discriminants are handled in
2049 D := First_Discriminant (Etype (Typ));
2050 C := First_Elmt (Girder_Constraint (Typ));
2053 and then Present (C)
2055 if Chars (Discrim_Name) = Chars (D) then
2057 Make_Component_Association (Sloc (Typ),
2059 (New_Occurrence_Of (D, Sloc (Typ))),
2060 Duplicate_Subexpr (Node (C)));
2061 exit Find_Constraint;
2064 D := Next_Discriminant (D);
2071 if No (Next (Assoc)) then
2072 Error_Msg_NE (" missing value for discriminant&",
2073 First (Governed_By), Discrim_Name);
2074 Report_Errors := True;
2079 end loop Find_Constraint;
2081 Discrim_Value := Expression (Assoc);
2083 if not Is_OK_Static_Expression (Discrim_Value) then
2085 ("value for discriminant & must be static", Discrim_Value, Discrim);
2086 Report_Errors := True;
2090 Search_For_Discriminant_Value : declare
2096 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
2099 Find_Discrete_Value : while Present (Variant) loop
2100 Discrete_Choice := First (Discrete_Choices (Variant));
2101 while Present (Discrete_Choice) loop
2103 exit Find_Discrete_Value when
2104 Nkind (Discrete_Choice) = N_Others_Choice;
2106 Get_Index_Bounds (Discrete_Choice, Low, High);
2108 UI_Low := Expr_Value (Low);
2109 UI_High := Expr_Value (High);
2111 exit Find_Discrete_Value when
2112 UI_Low <= UI_Discrim_Value
2114 UI_High >= UI_Discrim_Value;
2116 Next (Discrete_Choice);
2119 Next_Non_Pragma (Variant);
2120 end loop Find_Discrete_Value;
2121 end Search_For_Discriminant_Value;
2123 if No (Variant) then
2125 ("value of discriminant & is out of range", Discrim_Value, Discrim);
2126 Report_Errors := True;
2130 -- If we have found the corresponding choice, recursively add its
2131 -- components to the Into list.
2133 Gather_Components (Empty,
2134 Component_List (Variant), Governed_By, Into, Report_Errors);
2135 end Gather_Components;
2137 ------------------------
2138 -- Get_Actual_Subtype --
2139 ------------------------
2141 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
2142 Typ : constant Entity_Id := Etype (N);
2143 Utyp : Entity_Id := Underlying_Type (Typ);
2148 if not Present (Utyp) then
2152 -- If what we have is an identifier that references a subprogram
2153 -- formal, or a variable or constant object, then we get the actual
2154 -- subtype from the referenced entity if one has been built.
2156 if Nkind (N) = N_Identifier
2158 (Is_Formal (Entity (N))
2159 or else Ekind (Entity (N)) = E_Constant
2160 or else Ekind (Entity (N)) = E_Variable)
2161 and then Present (Actual_Subtype (Entity (N)))
2163 return Actual_Subtype (Entity (N));
2165 -- Actual subtype of unchecked union is always itself. We never need
2166 -- the "real" actual subtype. If we did, we couldn't get it anyway
2167 -- because the discriminant is not available. The restrictions on
2168 -- Unchecked_Union are designed to make sure that this is OK.
2170 elsif Is_Unchecked_Union (Utyp) then
2173 -- Here for the unconstrained case, we must find actual subtype
2174 -- No actual subtype is available, so we must build it on the fly.
2176 -- Checking the type, not the underlying type, for constrainedness
2177 -- seems to be necessary. Maybe all the tests should be on the type???
2179 elsif (not Is_Constrained (Typ))
2180 and then (Is_Array_Type (Utyp)
2181 or else (Is_Record_Type (Utyp)
2182 and then Has_Discriminants (Utyp)))
2183 and then not Has_Unknown_Discriminants (Utyp)
2184 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
2186 -- Nothing to do if in default expression
2188 if In_Default_Expression then
2191 -- Else build the actual subtype
2194 Decl := Build_Actual_Subtype (Typ, N);
2195 Atyp := Defining_Identifier (Decl);
2197 -- If Build_Actual_Subtype generated a new declaration then use it
2201 -- The actual subtype is an Itype, so analyze the declaration,
2202 -- but do not attach it to the tree, to get the type defined.
2204 Set_Parent (Decl, N);
2205 Set_Is_Itype (Atyp);
2206 Analyze (Decl, Suppress => All_Checks);
2207 Set_Associated_Node_For_Itype (Atyp, N);
2208 Set_Has_Delayed_Freeze (Atyp, False);
2210 -- We need to freeze the actual subtype immediately. This is
2211 -- needed, because otherwise this Itype will not get frozen
2212 -- at all, and it is always safe to freeze on creation because
2213 -- any associated types must be frozen at this point.
2215 Freeze_Itype (Atyp, N);
2218 -- Otherwise we did not build a declaration, so return original
2225 -- For all remaining cases, the actual subtype is the same as
2226 -- the nominal type.
2231 end Get_Actual_Subtype;
2233 -------------------------------------
2234 -- Get_Actual_Subtype_If_Available --
2235 -------------------------------------
2237 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
2238 Typ : constant Entity_Id := Etype (N);
2241 -- If what we have is an identifier that references a subprogram
2242 -- formal, or a variable or constant object, then we get the actual
2243 -- subtype from the referenced entity if one has been built.
2245 if Nkind (N) = N_Identifier
2247 (Is_Formal (Entity (N))
2248 or else Ekind (Entity (N)) = E_Constant
2249 or else Ekind (Entity (N)) = E_Variable)
2250 and then Present (Actual_Subtype (Entity (N)))
2252 return Actual_Subtype (Entity (N));
2254 -- Otherwise the Etype of N is returned unchanged
2259 end Get_Actual_Subtype_If_Available;
2261 -------------------------------
2262 -- Get_Default_External_Name --
2263 -------------------------------
2265 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
2267 Get_Decoded_Name_String (Chars (E));
2269 if Opt.External_Name_Imp_Casing = Uppercase then
2270 Set_Casing (All_Upper_Case);
2272 Set_Casing (All_Lower_Case);
2276 Make_String_Literal (Sloc (E),
2277 Strval => String_From_Name_Buffer);
2279 end Get_Default_External_Name;
2281 ---------------------------
2282 -- Get_Enum_Lit_From_Pos --
2283 ---------------------------
2285 function Get_Enum_Lit_From_Pos
2292 P : constant Nat := UI_To_Int (Pos);
2295 -- In the case where the literal is either of type Wide_Character
2296 -- or Character or of a type derived from them, there needs to be
2297 -- some special handling since there is no explicit chain of
2298 -- literals to search. Instead, an N_Character_Literal node is
2299 -- created with the appropriate Char_Code and Chars fields.
2301 if Root_Type (T) = Standard_Character
2302 or else Root_Type (T) = Standard_Wide_Character
2304 Set_Character_Literal_Name (Char_Code (P));
2306 Make_Character_Literal (Loc,
2308 Char_Literal_Value => Char_Code (P));
2310 -- For all other cases, we have a complete table of literals, and
2311 -- we simply iterate through the chain of literal until the one
2312 -- with the desired position value is found.
2316 Lit := First_Literal (Base_Type (T));
2317 for J in 1 .. P loop
2321 return New_Occurrence_Of (Lit, Loc);
2323 end Get_Enum_Lit_From_Pos;
2325 ------------------------
2326 -- Get_Generic_Entity --
2327 ------------------------
2329 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
2330 Ent : constant Entity_Id := Entity (Name (N));
2333 if Present (Renamed_Object (Ent)) then
2334 return Renamed_Object (Ent);
2338 end Get_Generic_Entity;
2340 ----------------------
2341 -- Get_Index_Bounds --
2342 ----------------------
2344 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
2345 Kind : constant Node_Kind := Nkind (N);
2349 if Kind = N_Range then
2351 H := High_Bound (N);
2353 elsif Kind = N_Subtype_Indication then
2354 R := Range_Expression (Constraint (N));
2362 L := Low_Bound (Range_Expression (Constraint (N)));
2363 H := High_Bound (Range_Expression (Constraint (N)));
2366 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
2367 if Error_Posted (Scalar_Range (Entity (N))) then
2371 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
2372 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
2375 L := Low_Bound (Scalar_Range (Entity (N)));
2376 H := High_Bound (Scalar_Range (Entity (N)));
2380 -- N is an expression, indicating a range with one value.
2385 end Get_Index_Bounds;
2387 ------------------------
2388 -- Get_Name_Entity_Id --
2389 ------------------------
2391 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
2393 return Entity_Id (Get_Name_Table_Info (Id));
2394 end Get_Name_Entity_Id;
2396 ---------------------------
2397 -- Get_Referenced_Object --
2398 ---------------------------
2400 function Get_Referenced_Object (N : Node_Id) return Node_Id is
2404 while Is_Entity_Name (R)
2405 and then Present (Renamed_Object (Entity (R)))
2407 R := Renamed_Object (Entity (R));
2411 end Get_Referenced_Object;
2413 -------------------------
2414 -- Get_Subprogram_Body --
2415 -------------------------
2417 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
2421 Decl := Unit_Declaration_Node (E);
2423 if Nkind (Decl) = N_Subprogram_Body then
2426 else -- Nkind (Decl) = N_Subprogram_Declaration
2428 if Present (Corresponding_Body (Decl)) then
2429 return Unit_Declaration_Node (Corresponding_Body (Decl));
2431 else -- imported subprogram.
2435 end Get_Subprogram_Body;
2437 -----------------------------
2438 -- Get_Task_Body_Procedure --
2439 -----------------------------
2441 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
2443 return Task_Body_Procedure (Declaration_Node (Root_Type (E)));
2444 end Get_Task_Body_Procedure;
2446 --------------------
2447 -- Has_Infinities --
2448 --------------------
2450 function Has_Infinities (E : Entity_Id) return Boolean is
2453 Is_Floating_Point_Type (E)
2454 and then Nkind (Scalar_Range (E)) = N_Range
2455 and then Includes_Infinities (Scalar_Range (E));
2458 ---------------------------
2459 -- Has_Private_Component --
2460 ---------------------------
2462 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
2463 Btype : Entity_Id := Base_Type (Type_Id);
2464 Component : Entity_Id;
2467 if Error_Posted (Type_Id)
2468 or else Error_Posted (Btype)
2473 if Is_Class_Wide_Type (Btype) then
2474 Btype := Root_Type (Btype);
2477 if Is_Private_Type (Btype) then
2479 UT : constant Entity_Id := Underlying_Type (Btype);
2483 if No (Full_View (Btype)) then
2484 return not Is_Generic_Type (Btype)
2485 and then not Is_Generic_Type (Root_Type (Btype));
2488 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
2492 return not Is_Frozen (UT) and then Has_Private_Component (UT);
2495 elsif Is_Array_Type (Btype) then
2496 return Has_Private_Component (Component_Type (Btype));
2498 elsif Is_Record_Type (Btype) then
2500 Component := First_Component (Btype);
2501 while Present (Component) loop
2503 if Has_Private_Component (Etype (Component)) then
2507 Next_Component (Component);
2512 elsif Is_Protected_Type (Btype)
2513 and then Present (Corresponding_Record_Type (Btype))
2515 return Has_Private_Component (Corresponding_Record_Type (Btype));
2520 end Has_Private_Component;
2522 --------------------------
2523 -- Has_Tagged_Component --
2524 --------------------------
2526 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
2530 if Is_Private_Type (Typ)
2531 and then Present (Underlying_Type (Typ))
2533 return Has_Tagged_Component (Underlying_Type (Typ));
2535 elsif Is_Array_Type (Typ) then
2536 return Has_Tagged_Component (Component_Type (Typ));
2538 elsif Is_Tagged_Type (Typ) then
2541 elsif Is_Record_Type (Typ) then
2542 Comp := First_Component (Typ);
2544 while Present (Comp) loop
2545 if Has_Tagged_Component (Etype (Comp)) then
2549 Comp := Next_Component (Typ);
2557 end Has_Tagged_Component;
2563 function In_Instance return Boolean is
2564 S : Entity_Id := Current_Scope;
2568 and then S /= Standard_Standard
2570 if (Ekind (S) = E_Function
2571 or else Ekind (S) = E_Package
2572 or else Ekind (S) = E_Procedure)
2573 and then Is_Generic_Instance (S)
2584 ----------------------
2585 -- In_Instance_Body --
2586 ----------------------
2588 function In_Instance_Body return Boolean is
2589 S : Entity_Id := Current_Scope;
2593 and then S /= Standard_Standard
2595 if (Ekind (S) = E_Function
2596 or else Ekind (S) = E_Procedure)
2597 and then Is_Generic_Instance (S)
2601 elsif Ekind (S) = E_Package
2602 and then In_Package_Body (S)
2603 and then Is_Generic_Instance (S)
2612 end In_Instance_Body;
2614 -----------------------------
2615 -- In_Instance_Not_Visible --
2616 -----------------------------
2618 function In_Instance_Not_Visible return Boolean is
2619 S : Entity_Id := Current_Scope;
2623 and then S /= Standard_Standard
2625 if (Ekind (S) = E_Function
2626 or else Ekind (S) = E_Procedure)
2627 and then Is_Generic_Instance (S)
2631 elsif Ekind (S) = E_Package
2632 and then (In_Package_Body (S) or else In_Private_Part (S))
2633 and then Is_Generic_Instance (S)
2642 end In_Instance_Not_Visible;
2644 ------------------------------
2645 -- In_Instance_Visible_Part --
2646 ------------------------------
2648 function In_Instance_Visible_Part return Boolean is
2649 S : Entity_Id := Current_Scope;
2653 and then S /= Standard_Standard
2655 if Ekind (S) = E_Package
2656 and then Is_Generic_Instance (S)
2657 and then not In_Package_Body (S)
2658 and then not In_Private_Part (S)
2667 end In_Instance_Visible_Part;
2669 --------------------------------------
2670 -- In_Subprogram_Or_Concurrent_Unit --
2671 --------------------------------------
2673 function In_Subprogram_Or_Concurrent_Unit return Boolean is
2678 -- Use scope chain to check successively outer scopes
2684 if K in Subprogram_Kind
2685 or else K in Concurrent_Kind
2686 or else K = E_Generic_Procedure
2687 or else K = E_Generic_Function
2691 elsif E = Standard_Standard then
2698 end In_Subprogram_Or_Concurrent_Unit;
2700 ---------------------
2701 -- In_Visible_Part --
2702 ---------------------
2704 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
2707 Is_Package (Scope_Id)
2708 and then In_Open_Scopes (Scope_Id)
2709 and then not In_Package_Body (Scope_Id)
2710 and then not In_Private_Part (Scope_Id);
2711 end In_Visible_Part;
2717 function Is_AAMP_Float (E : Entity_Id) return Boolean is
2719 pragma Assert (Is_Type (E));
2721 return AAMP_On_Target
2722 and then Is_Floating_Point_Type (E)
2723 and then E = Base_Type (E);
2726 -------------------------
2727 -- Is_Actual_Parameter --
2728 -------------------------
2730 function Is_Actual_Parameter (N : Node_Id) return Boolean is
2731 PK : constant Node_Kind := Nkind (Parent (N));
2735 when N_Parameter_Association =>
2736 return N = Explicit_Actual_Parameter (Parent (N));
2738 when N_Function_Call | N_Procedure_Call_Statement =>
2739 return Is_List_Member (N)
2741 List_Containing (N) = Parameter_Associations (Parent (N));
2746 end Is_Actual_Parameter;
2748 ---------------------
2749 -- Is_Aliased_View --
2750 ---------------------
2752 function Is_Aliased_View (Obj : Node_Id) return Boolean is
2756 if Is_Entity_Name (Obj) then
2758 -- Shouldn't we check that we really have an object here?
2759 -- If we do, then a-caldel.adb blows up mysteriously ???
2763 return Is_Aliased (E)
2764 or else (Present (Renamed_Object (E))
2765 and then Is_Aliased_View (Renamed_Object (E)))
2767 or else ((Is_Formal (E)
2768 or else Ekind (E) = E_Generic_In_Out_Parameter
2769 or else Ekind (E) = E_Generic_In_Parameter)
2770 and then Is_Tagged_Type (Etype (E)))
2772 or else ((Ekind (E) = E_Task_Type or else
2773 Ekind (E) = E_Protected_Type)
2774 and then In_Open_Scopes (E))
2776 -- Current instance of type
2778 or else (Is_Type (E) and then E = Current_Scope)
2779 or else (Is_Incomplete_Or_Private_Type (E)
2780 and then Full_View (E) = Current_Scope);
2782 elsif Nkind (Obj) = N_Selected_Component then
2783 return Is_Aliased (Entity (Selector_Name (Obj)));
2785 elsif Nkind (Obj) = N_Indexed_Component then
2786 return Has_Aliased_Components (Etype (Prefix (Obj)))
2788 (Is_Access_Type (Etype (Prefix (Obj)))
2790 Has_Aliased_Components
2791 (Designated_Type (Etype (Prefix (Obj)))));
2793 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
2794 or else Nkind (Obj) = N_Type_Conversion
2796 return Is_Tagged_Type (Etype (Obj))
2797 or else Is_Aliased_View (Expression (Obj));
2799 elsif Nkind (Obj) = N_Explicit_Dereference then
2800 return Nkind (Original_Node (Obj)) /= N_Function_Call;
2805 end Is_Aliased_View;
2807 ----------------------
2808 -- Is_Atomic_Object --
2809 ----------------------
2811 function Is_Atomic_Object (N : Node_Id) return Boolean is
2813 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
2814 -- Determines if given object has atomic components
2816 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
2817 -- If prefix is an implicit dereference, examine designated type.
2819 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
2821 if Is_Access_Type (Etype (N)) then
2823 Has_Atomic_Components (Designated_Type (Etype (N)));
2825 return Object_Has_Atomic_Components (N);
2827 end Is_Atomic_Prefix;
2829 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
2831 if Has_Atomic_Components (Etype (N))
2832 or else Is_Atomic (Etype (N))
2836 elsif Is_Entity_Name (N)
2837 and then (Has_Atomic_Components (Entity (N))
2838 or else Is_Atomic (Entity (N)))
2842 elsif Nkind (N) = N_Indexed_Component
2843 or else Nkind (N) = N_Selected_Component
2845 return Is_Atomic_Prefix (Prefix (N));
2850 end Object_Has_Atomic_Components;
2852 -- Start of processing for Is_Atomic_Object
2855 if Is_Atomic (Etype (N))
2856 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
2860 elsif Nkind (N) = N_Indexed_Component
2861 or else Nkind (N) = N_Selected_Component
2863 return Is_Atomic_Prefix (Prefix (N));
2868 end Is_Atomic_Object;
2870 ----------------------------------------------
2871 -- Is_Dependent_Component_Of_Mutable_Object --
2872 ----------------------------------------------
2874 function Is_Dependent_Component_Of_Mutable_Object
2879 Prefix_Type : Entity_Id;
2880 P_Aliased : Boolean := False;
2883 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean;
2884 -- Returns True if and only if Comp has a constrained subtype
2885 -- that depends on a discriminant.
2887 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
2888 -- Returns True if and only if Comp is declared within a variant part.
2890 ------------------------------
2891 -- Has_Dependent_Constraint --
2892 ------------------------------
2894 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean is
2895 Comp_Decl : constant Node_Id := Parent (Comp);
2896 Subt_Indic : constant Node_Id := Subtype_Indication (Comp_Decl);
2901 if Nkind (Subt_Indic) = N_Subtype_Indication then
2902 Constr := Constraint (Subt_Indic);
2904 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
2905 Assn := First (Constraints (Constr));
2906 while Present (Assn) loop
2907 case Nkind (Assn) is
2908 when N_Subtype_Indication |
2912 if Depends_On_Discriminant (Assn) then
2916 when N_Discriminant_Association =>
2917 if Depends_On_Discriminant (Expression (Assn)) then
2932 end Has_Dependent_Constraint;
2934 --------------------------------
2935 -- Is_Declared_Within_Variant --
2936 --------------------------------
2938 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
2939 Comp_Decl : constant Node_Id := Parent (Comp);
2940 Comp_List : constant Node_Id := Parent (Comp_Decl);
2943 return Nkind (Parent (Comp_List)) = N_Variant;
2944 end Is_Declared_Within_Variant;
2946 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
2949 if Is_Variable (Object) then
2951 if Nkind (Object) = N_Selected_Component then
2952 P := Prefix (Object);
2953 Prefix_Type := Etype (P);
2955 if Is_Entity_Name (P) then
2957 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
2958 Prefix_Type := Base_Type (Prefix_Type);
2961 if Is_Aliased (Entity (P)) then
2966 -- Check for prefix being an aliased component ???
2970 if Is_Access_Type (Prefix_Type)
2971 or else Nkind (P) = N_Explicit_Dereference
2977 Original_Record_Component (Entity (Selector_Name (Object)));
2979 -- As per AI-0017, the renaming is illegal in a generic body,
2980 -- even if the subtype is indefinite.
2982 if not Is_Constrained (Prefix_Type)
2983 and then (not Is_Indefinite_Subtype (Prefix_Type)
2985 (Is_Generic_Type (Prefix_Type)
2986 and then Ekind (Current_Scope) = E_Generic_Package
2987 and then In_Package_Body (Current_Scope)))
2989 and then (Is_Declared_Within_Variant (Comp)
2990 or else Has_Dependent_Constraint (Comp))
2991 and then not P_Aliased
2997 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3001 elsif Nkind (Object) = N_Indexed_Component
3002 or else Nkind (Object) = N_Slice
3004 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3009 end Is_Dependent_Component_Of_Mutable_Object;
3015 function Is_False (U : Uint) return Boolean is
3020 ---------------------------
3021 -- Is_Fixed_Model_Number --
3022 ---------------------------
3024 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
3025 S : constant Ureal := Small_Value (T);
3026 M : Urealp.Save_Mark;
3031 R := (U = UR_Trunc (U / S) * S);
3034 end Is_Fixed_Model_Number;
3036 -------------------------------
3037 -- Is_Fully_Initialized_Type --
3038 -------------------------------
3040 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
3042 if Is_Scalar_Type (Typ) then
3045 elsif Is_Access_Type (Typ) then
3048 elsif Is_Array_Type (Typ) then
3049 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
3053 -- An interesting case, if we have a constrained type one of whose
3054 -- bounds is known to be null, then there are no elements to be
3055 -- initialized, so all the elements are initialized!
3057 if Is_Constrained (Typ) then
3060 Indx_Typ : Entity_Id;
3064 Indx := First_Index (Typ);
3065 while Present (Indx) loop
3067 if Etype (Indx) = Any_Type then
3070 -- If index is a range, use directly.
3072 elsif Nkind (Indx) = N_Range then
3073 Lbd := Low_Bound (Indx);
3074 Hbd := High_Bound (Indx);
3077 Indx_Typ := Etype (Indx);
3079 if Is_Private_Type (Indx_Typ) then
3080 Indx_Typ := Full_View (Indx_Typ);
3083 if No (Indx_Typ) then
3086 Lbd := Type_Low_Bound (Indx_Typ);
3087 Hbd := Type_High_Bound (Indx_Typ);
3091 if Compile_Time_Known_Value (Lbd)
3092 and then Compile_Time_Known_Value (Hbd)
3094 if Expr_Value (Hbd) < Expr_Value (Lbd) then
3104 -- If no null indexes, then type is not fully initialized
3108 elsif Is_Record_Type (Typ) then
3113 Ent := First_Entity (Typ);
3115 while Present (Ent) loop
3116 if Ekind (Ent) = E_Component
3117 and then (No (Parent (Ent))
3118 or else No (Expression (Parent (Ent))))
3119 and then not Is_Fully_Initialized_Type (Etype (Ent))
3128 -- No uninitialized components, so type is fully initialized.
3129 -- Note that this catches the case of no components as well.
3133 elsif Is_Concurrent_Type (Typ) then
3136 elsif Is_Private_Type (Typ) then
3138 U : constant Entity_Id := Underlying_Type (Typ);
3144 return Is_Fully_Initialized_Type (U);
3151 end Is_Fully_Initialized_Type;
3153 ----------------------------
3154 -- Is_Inherited_Operation --
3155 ----------------------------
3157 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
3158 Kind : constant Node_Kind := Nkind (Parent (E));
3161 pragma Assert (Is_Overloadable (E));
3162 return Kind = N_Full_Type_Declaration
3163 or else Kind = N_Private_Extension_Declaration
3164 or else Kind = N_Subtype_Declaration
3165 or else (Ekind (E) = E_Enumeration_Literal
3166 and then Is_Derived_Type (Etype (E)));
3167 end Is_Inherited_Operation;
3169 -----------------------------
3170 -- Is_Library_Level_Entity --
3171 -----------------------------
3173 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
3175 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
3176 end Is_Library_Level_Entity;
3178 ---------------------------------
3179 -- Is_Local_Variable_Reference --
3180 ---------------------------------
3182 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
3184 if not Is_Entity_Name (Expr) then
3189 Ent : constant Entity_Id := Entity (Expr);
3190 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
3193 if Ekind (Ent) /= E_Variable
3195 Ekind (Ent) /= E_In_Out_Parameter
3200 return Present (Sub) and then Sub = Current_Subprogram;
3204 end Is_Local_Variable_Reference;
3206 -------------------------
3207 -- Is_Object_Reference --
3208 -------------------------
3210 function Is_Object_Reference (N : Node_Id) return Boolean is
3212 if Is_Entity_Name (N) then
3213 return Is_Object (Entity (N));
3217 when N_Indexed_Component | N_Slice =>
3218 return Is_Object_Reference (Prefix (N));
3220 -- In Ada95, a function call is a constant object.
3222 when N_Function_Call =>
3225 -- A reference to the stream attribute Input is a function call.
3227 when N_Attribute_Reference =>
3228 return Attribute_Name (N) = Name_Input;
3230 when N_Selected_Component =>
3231 return Is_Object_Reference (Selector_Name (N));
3233 when N_Explicit_Dereference =>
3236 -- An unchecked type conversion is considered to be an object if
3237 -- the operand is an object (this construction arises only as a
3238 -- result of expansion activities).
3240 when N_Unchecked_Type_Conversion =>
3247 end Is_Object_Reference;
3249 -----------------------------------
3250 -- Is_OK_Variable_For_Out_Formal --
3251 -----------------------------------
3253 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
3255 Note_Possible_Modification (AV);
3257 -- We must reject parenthesized variable names. The check for
3258 -- Comes_From_Source is present because there are currently
3259 -- cases where the compiler violates this rule (e.g. passing
3260 -- a task object to its controlled Initialize routine).
3262 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
3265 -- A variable is always allowed
3267 elsif Is_Variable (AV) then
3270 -- Unchecked conversions are allowed only if they come from the
3271 -- generated code, which sometimes uses unchecked conversions for
3272 -- out parameters in cases where code generation is unaffected.
3273 -- We tell source unchecked conversions by seeing if they are
3274 -- rewrites of an original UC function call, or of an explicit
3275 -- conversion of a function call.
3277 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
3278 if Nkind (Original_Node (AV)) = N_Function_Call then
3281 elsif Comes_From_Source (AV)
3282 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
3290 -- Normal type conversions are allowed if argument is a variable
3292 elsif Nkind (AV) = N_Type_Conversion then
3293 if Is_Variable (Expression (AV))
3294 and then Paren_Count (Expression (AV)) = 0
3296 Note_Possible_Modification (Expression (AV));
3299 -- We also allow a non-parenthesized expression that raises
3300 -- constraint error if it rewrites what used to be a variable
3302 elsif Raises_Constraint_Error (Expression (AV))
3303 and then Paren_Count (Expression (AV)) = 0
3304 and then Is_Variable (Original_Node (Expression (AV)))
3308 -- Type conversion of something other than a variable
3314 -- If this node is rewritten, then test the original form, if that is
3315 -- OK, then we consider the rewritten node OK (for example, if the
3316 -- original node is a conversion, then Is_Variable will not be true
3317 -- but we still want to allow the conversion if it converts a variable.
3319 elsif Original_Node (AV) /= AV then
3320 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
3322 -- All other non-variables are rejected
3327 end Is_OK_Variable_For_Out_Formal;
3329 -----------------------------------
3330 -- Is_Partially_Initialized_Type --
3331 -----------------------------------
3333 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
3335 if Is_Scalar_Type (Typ) then
3338 elsif Is_Access_Type (Typ) then
3341 elsif Is_Array_Type (Typ) then
3343 -- If component type is partially initialized, so is array type
3345 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
3348 -- Otherwise we are only partially initialized if we are fully
3349 -- initialized (this is the empty array case, no point in us
3350 -- duplicating that code here).
3353 return Is_Fully_Initialized_Type (Typ);
3356 elsif Is_Record_Type (Typ) then
3358 -- A discriminated type is always partially initialized
3360 if Has_Discriminants (Typ) then
3363 -- A tagged type is always partially initialized
3365 elsif Is_Tagged_Type (Typ) then
3368 -- Case of non-discriminated record
3374 Component_Present : Boolean := False;
3375 -- Set True if at least one component is present. If no
3376 -- components are present, then record type is fully
3377 -- initialized (another odd case, like the null array).
3380 -- Loop through components
3382 Ent := First_Entity (Typ);
3383 while Present (Ent) loop
3384 if Ekind (Ent) = E_Component then
3385 Component_Present := True;
3387 -- If a component has an initialization expression then
3388 -- the enclosing record type is partially initialized
3390 if Present (Parent (Ent))
3391 and then Present (Expression (Parent (Ent)))
3395 -- If a component is of a type which is itself partially
3396 -- initialized, then the enclosing record type is also.
3398 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
3406 -- No initialized components found. If we found any components
3407 -- they were all uninitialized so the result is false.
3409 if Component_Present then
3412 -- But if we found no components, then all the components are
3413 -- initialized so we consider the type to be initialized.
3421 -- Concurrent types are always fully initialized
3423 elsif Is_Concurrent_Type (Typ) then
3426 -- For a private type, go to underlying type. If there is no underlying
3427 -- type then just assume this partially initialized. Not clear if this
3428 -- can happen in a non-error case, but no harm in testing for this.
3430 elsif Is_Private_Type (Typ) then
3432 U : constant Entity_Id := Underlying_Type (Typ);
3438 return Is_Partially_Initialized_Type (U);
3442 -- For any other type (are there any?) assume partially initialized
3447 end Is_Partially_Initialized_Type;
3449 -----------------------------
3450 -- Is_RCI_Pkg_Spec_Or_Body --
3451 -----------------------------
3453 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
3455 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
3456 -- Return True if the unit of Cunit is an RCI package declaration
3458 ---------------------------
3459 -- Is_RCI_Pkg_Decl_Cunit --
3460 ---------------------------
3462 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
3463 The_Unit : constant Node_Id := Unit (Cunit);
3466 if Nkind (The_Unit) /= N_Package_Declaration then
3469 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
3470 end Is_RCI_Pkg_Decl_Cunit;
3472 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
3475 return Is_RCI_Pkg_Decl_Cunit (Cunit)
3477 (Nkind (Unit (Cunit)) = N_Package_Body
3478 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
3479 end Is_RCI_Pkg_Spec_Or_Body;
3481 -----------------------------------------
3482 -- Is_Remote_Access_To_Class_Wide_Type --
3483 -----------------------------------------
3485 function Is_Remote_Access_To_Class_Wide_Type
3491 function Comes_From_Limited_Private_Type_Declaration
3494 -- Check if the original declaration is a limited private one and
3495 -- if all the derivations have been using private extensions.
3497 -------------------------------------------------
3498 -- Comes_From_Limited_Private_Type_Declaration --
3499 -------------------------------------------------
3501 function Comes_From_Limited_Private_Type_Declaration (E : in Entity_Id)
3504 N : constant Node_Id := Declaration_Node (E);
3506 if Nkind (N) = N_Private_Type_Declaration
3507 and then Limited_Present (N)
3512 if Nkind (N) = N_Private_Extension_Declaration then
3513 return Comes_From_Limited_Private_Type_Declaration (Etype (E));
3517 end Comes_From_Limited_Private_Type_Declaration;
3519 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
3522 if not (Is_Remote_Call_Interface (E)
3523 or else Is_Remote_Types (E))
3524 or else Ekind (E) /= E_General_Access_Type
3529 D := Designated_Type (E);
3531 if Ekind (D) /= E_Class_Wide_Type then
3535 return Comes_From_Limited_Private_Type_Declaration
3536 (Defining_Identifier (Parent (D)));
3537 end Is_Remote_Access_To_Class_Wide_Type;
3539 -----------------------------------------
3540 -- Is_Remote_Access_To_Subprogram_Type --
3541 -----------------------------------------
3543 function Is_Remote_Access_To_Subprogram_Type
3548 return (Ekind (E) = E_Access_Subprogram_Type
3549 or else (Ekind (E) = E_Record_Type
3550 and then Present (Corresponding_Remote_Type (E))))
3551 and then (Is_Remote_Call_Interface (E)
3552 or else Is_Remote_Types (E));
3553 end Is_Remote_Access_To_Subprogram_Type;
3555 --------------------
3556 -- Is_Remote_Call --
3557 --------------------
3559 function Is_Remote_Call (N : Node_Id) return Boolean is
3561 if Nkind (N) /= N_Procedure_Call_Statement
3562 and then Nkind (N) /= N_Function_Call
3564 -- An entry call cannot be remote
3568 elsif Nkind (Name (N)) in N_Has_Entity
3569 and then Is_Remote_Call_Interface (Entity (Name (N)))
3571 -- A subprogram declared in the spec of a RCI package is remote
3575 elsif Nkind (Name (N)) = N_Explicit_Dereference
3576 and then Is_Remote_Access_To_Subprogram_Type
3577 (Etype (Prefix (Name (N))))
3579 -- The dereference of a RAS is a remote call
3583 elsif Present (Controlling_Argument (N))
3584 and then Is_Remote_Access_To_Class_Wide_Type
3585 (Etype (Controlling_Argument (N)))
3587 -- Any primitive operation call with a controlling argument of
3588 -- a RACW type is a remote call.
3593 -- All other calls are local calls
3598 ----------------------
3599 -- Is_Selector_Name --
3600 ----------------------
3602 function Is_Selector_Name (N : Node_Id) return Boolean is
3605 if not Is_List_Member (N) then
3607 P : constant Node_Id := Parent (N);
3608 K : constant Node_Kind := Nkind (P);
3612 (K = N_Expanded_Name or else
3613 K = N_Generic_Association or else
3614 K = N_Parameter_Association or else
3615 K = N_Selected_Component)
3616 and then Selector_Name (P) = N;
3621 L : constant List_Id := List_Containing (N);
3622 P : constant Node_Id := Parent (L);
3625 return (Nkind (P) = N_Discriminant_Association
3626 and then Selector_Names (P) = L)
3628 (Nkind (P) = N_Component_Association
3629 and then Choices (P) = L);
3632 end Is_Selector_Name;
3638 function Is_Statement (N : Node_Id) return Boolean is
3641 Nkind (N) in N_Statement_Other_Than_Procedure_Call
3642 or else Nkind (N) = N_Procedure_Call_Statement;
3649 function Is_Transfer (N : Node_Id) return Boolean is
3650 Kind : constant Node_Kind := Nkind (N);
3653 if Kind = N_Return_Statement
3655 Kind = N_Goto_Statement
3657 Kind = N_Raise_Statement
3659 Kind = N_Requeue_Statement
3663 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
3664 and then No (Condition (N))
3668 elsif Kind = N_Procedure_Call_Statement
3669 and then Is_Entity_Name (Name (N))
3670 and then Present (Entity (Name (N)))
3671 and then No_Return (Entity (Name (N)))
3675 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
3687 function Is_True (U : Uint) return Boolean is
3696 function Is_Variable (N : Node_Id) return Boolean is
3698 Orig_Node : constant Node_Id := Original_Node (N);
3699 -- We do the test on the original node, since this is basically a
3700 -- test of syntactic categories, so it must not be disturbed by
3701 -- whatever rewriting might have occurred. For example, an aggregate,
3702 -- which is certainly NOT a variable, could be turned into a variable
3705 function In_Protected_Function (E : Entity_Id) return Boolean;
3706 -- Within a protected function, the private components of the
3707 -- enclosing protected type are constants. A function nested within
3708 -- a (protected) procedure is not itself protected.
3710 function Is_Variable_Prefix (P : Node_Id) return Boolean;
3711 -- Prefixes can involve implicit dereferences, in which case we
3712 -- must test for the case of a reference of a constant access
3713 -- type, which can never be a variable.
3715 function In_Protected_Function (E : Entity_Id) return Boolean is
3716 Prot : constant Entity_Id := Scope (E);
3720 if not Is_Protected_Type (Prot) then
3725 while Present (S) and then S /= Prot loop
3727 if Ekind (S) = E_Function
3728 and then Scope (S) = Prot
3738 end In_Protected_Function;
3740 function Is_Variable_Prefix (P : Node_Id) return Boolean is
3742 if Is_Access_Type (Etype (P)) then
3743 return not Is_Access_Constant (Root_Type (Etype (P)));
3745 return Is_Variable (P);
3747 end Is_Variable_Prefix;
3749 -- Start of processing for Is_Variable
3752 -- Definitely OK if Assignment_OK is set. Since this is something that
3753 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
3755 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
3758 -- Normally we go to the original node, but there is one exception
3759 -- where we use the rewritten node, namely when it is an explicit
3760 -- dereference. The generated code may rewrite a prefix which is an
3761 -- access type with an explicit dereference. The dereference is a
3762 -- variable, even though the original node may not be (since it could
3763 -- be a constant of the access type).
3765 elsif Nkind (N) = N_Explicit_Dereference
3766 and then Nkind (Orig_Node) /= N_Explicit_Dereference
3767 and then Is_Access_Type (Etype (Orig_Node))
3769 return Is_Variable_Prefix (Original_Node (Prefix (N)));
3771 -- All remaining checks use the original node
3773 elsif Is_Entity_Name (Orig_Node) then
3775 E : constant Entity_Id := Entity (Orig_Node);
3776 K : constant Entity_Kind := Ekind (E);
3779 return (K = E_Variable
3780 and then Nkind (Parent (E)) /= N_Exception_Handler)
3781 or else (K = E_Component
3782 and then not In_Protected_Function (E))
3783 or else K = E_Out_Parameter
3784 or else K = E_In_Out_Parameter
3785 or else K = E_Generic_In_Out_Parameter
3787 -- Current instance of type:
3789 or else (Is_Type (E) and then In_Open_Scopes (E))
3790 or else (Is_Incomplete_Or_Private_Type (E)
3791 and then In_Open_Scopes (Full_View (E)));
3795 case Nkind (Orig_Node) is
3796 when N_Indexed_Component | N_Slice =>
3797 return Is_Variable_Prefix (Prefix (Orig_Node));
3799 when N_Selected_Component =>
3800 return Is_Variable_Prefix (Prefix (Orig_Node))
3801 and then Is_Variable (Selector_Name (Orig_Node));
3803 -- For an explicit dereference, we must check whether the type
3804 -- is ACCESS CONSTANT, since if it is, then it is not a variable.
3806 when N_Explicit_Dereference =>
3807 return Is_Access_Type (Etype (Prefix (Orig_Node)))
3809 Is_Access_Constant (Root_Type (Etype (Prefix (Orig_Node))));
3811 -- The type conversion is the case where we do not deal with the
3812 -- context dependent special case of an actual parameter. Thus
3813 -- the type conversion is only considered a variable for the
3814 -- purposes of this routine if the target type is tagged. However,
3815 -- a type conversion is considered to be a variable if it does not
3816 -- come from source (this deals for example with the conversions
3817 -- of expressions to their actual subtypes).
3819 when N_Type_Conversion =>
3820 return Is_Variable (Expression (Orig_Node))
3822 (not Comes_From_Source (Orig_Node)
3824 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
3826 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
3828 -- GNAT allows an unchecked type conversion as a variable. This
3829 -- only affects the generation of internal expanded code, since
3830 -- calls to instantiations of Unchecked_Conversion are never
3831 -- considered variables (since they are function calls).
3832 -- This is also true for expression actions.
3834 when N_Unchecked_Type_Conversion =>
3835 return Is_Variable (Expression (Orig_Node));
3843 ------------------------
3844 -- Is_Volatile_Object --
3845 ------------------------
3847 function Is_Volatile_Object (N : Node_Id) return Boolean is
3849 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
3850 -- Determines if given object has volatile components
3852 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
3853 -- If prefix is an implicit dereference, examine designated type.
3855 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
3857 if Is_Access_Type (Etype (N)) then
3858 return Has_Volatile_Components (Designated_Type (Etype (N)));
3860 return Object_Has_Volatile_Components (N);
3862 end Is_Volatile_Prefix;
3864 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
3866 if Is_Volatile (Etype (N))
3867 or else Has_Volatile_Components (Etype (N))
3871 elsif Is_Entity_Name (N)
3872 and then (Has_Volatile_Components (Entity (N))
3873 or else Is_Volatile (Entity (N)))
3877 elsif Nkind (N) = N_Indexed_Component
3878 or else Nkind (N) = N_Selected_Component
3880 return Is_Volatile_Prefix (Prefix (N));
3885 end Object_Has_Volatile_Components;
3887 -- Start of processing for Is_Volatile_Object
3890 if Is_Volatile (Etype (N))
3891 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
3895 elsif Nkind (N) = N_Indexed_Component
3896 or else Nkind (N) = N_Selected_Component
3898 return Is_Volatile_Prefix (Prefix (N));
3903 end Is_Volatile_Object;
3905 --------------------------
3906 -- Kill_Size_Check_Code --
3907 --------------------------
3909 procedure Kill_Size_Check_Code (E : Entity_Id) is
3911 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
3912 and then Present (Size_Check_Code (E))
3914 Remove (Size_Check_Code (E));
3915 Set_Size_Check_Code (E, Empty);
3917 end Kill_Size_Check_Code;
3919 -------------------------
3920 -- New_External_Entity --
3921 -------------------------
3923 function New_External_Entity
3924 (Kind : Entity_Kind;
3925 Scope_Id : Entity_Id;
3926 Sloc_Value : Source_Ptr;
3927 Related_Id : Entity_Id;
3929 Suffix_Index : Nat := 0;
3930 Prefix : Character := ' ')
3933 N : constant Entity_Id :=
3934 Make_Defining_Identifier (Sloc_Value,
3936 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
3939 Set_Ekind (N, Kind);
3940 Set_Is_Internal (N, True);
3941 Append_Entity (N, Scope_Id);
3942 Set_Public_Status (N);
3944 if Kind in Type_Kind then
3945 Init_Size_Align (N);
3949 end New_External_Entity;
3951 -------------------------
3952 -- New_Internal_Entity --
3953 -------------------------
3955 function New_Internal_Entity
3956 (Kind : Entity_Kind;
3957 Scope_Id : Entity_Id;
3958 Sloc_Value : Source_Ptr;
3959 Id_Char : Character)
3962 N : constant Entity_Id :=
3963 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
3966 Set_Ekind (N, Kind);
3967 Set_Is_Internal (N, True);
3968 Append_Entity (N, Scope_Id);
3970 if Kind in Type_Kind then
3971 Init_Size_Align (N);
3975 end New_Internal_Entity;
3981 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
3985 -- If we are pointing at a positional parameter, it is a member of
3986 -- a node list (the list of parameters), and the next parameter
3987 -- is the next node on the list, unless we hit a parameter
3988 -- association, in which case we shift to using the chain whose
3989 -- head is the First_Named_Actual in the parent, and then is
3990 -- threaded using the Next_Named_Actual of the Parameter_Association.
3991 -- All this fiddling is because the original node list is in the
3992 -- textual call order, and what we need is the declaration order.
3994 if Is_List_Member (Actual_Id) then
3995 N := Next (Actual_Id);
3997 if Nkind (N) = N_Parameter_Association then
3998 return First_Named_Actual (Parent (Actual_Id));
4004 return Next_Named_Actual (Parent (Actual_Id));
4008 procedure Next_Actual (Actual_Id : in out Node_Id) is
4010 Actual_Id := Next_Actual (Actual_Id);
4013 -----------------------
4014 -- Normalize_Actuals --
4015 -----------------------
4017 -- Chain actuals according to formals of subprogram. If there are
4018 -- no named associations, the chain is simply the list of Parameter
4019 -- Associations, since the order is the same as the declaration order.
4020 -- If there are named associations, then the First_Named_Actual field
4021 -- in the N_Procedure_Call_Statement node or N_Function_Call node
4022 -- points to the Parameter_Association node for the parameter that
4023 -- comes first in declaration order. The remaining named parameters
4024 -- are then chained in declaration order using Next_Named_Actual.
4026 -- This routine also verifies that the number of actuals is compatible
4027 -- with the number and default values of formals, but performs no type
4028 -- checking (type checking is done by the caller).
4030 -- If the matching succeeds, Success is set to True, and the caller
4031 -- proceeds with type-checking. If the match is unsuccessful, then
4032 -- Success is set to False, and the caller attempts a different
4033 -- interpretation, if there is one.
4035 -- If the flag Report is on, the call is not overloaded, and a failure
4036 -- to match can be reported here, rather than in the caller.
4038 procedure Normalize_Actuals
4042 Success : out Boolean)
4044 Actuals : constant List_Id := Parameter_Associations (N);
4045 Actual : Node_Id := Empty;
4047 Last : Node_Id := Empty;
4048 First_Named : Node_Id := Empty;
4051 Formals_To_Match : Integer := 0;
4052 Actuals_To_Match : Integer := 0;
4054 procedure Chain (A : Node_Id);
4055 -- Add named actual at the proper place in the list, using the
4056 -- Next_Named_Actual link.
4058 function Reporting return Boolean;
4059 -- Determines if an error is to be reported. To report an error, we
4060 -- need Report to be True, and also we do not report errors caused
4061 -- by calls to Init_Proc's that occur within other Init_Proc's. Such
4062 -- errors must always be cascaded errors, since if all the types are
4063 -- declared correctly, the compiler will certainly build decent calls!
4065 procedure Chain (A : Node_Id) is
4069 -- Call node points to first actual in list.
4071 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
4074 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
4078 Set_Next_Named_Actual (Last, Empty);
4081 function Reporting return Boolean is
4086 elsif not Within_Init_Proc then
4089 elsif Chars (Entity (Name (N))) = Name_uInit_Proc then
4097 -- Start of processing for Normalize_Actuals
4100 if Is_Access_Type (S) then
4102 -- The name in the call is a function call that returns an access
4103 -- to subprogram. The designated type has the list of formals.
4105 Formal := First_Formal (Designated_Type (S));
4107 Formal := First_Formal (S);
4110 while Present (Formal) loop
4111 Formals_To_Match := Formals_To_Match + 1;
4112 Next_Formal (Formal);
4115 -- Find if there is a named association, and verify that no positional
4116 -- associations appear after named ones.
4118 if Present (Actuals) then
4119 Actual := First (Actuals);
4122 while Present (Actual)
4123 and then Nkind (Actual) /= N_Parameter_Association
4125 Actuals_To_Match := Actuals_To_Match + 1;
4129 if No (Actual) and Actuals_To_Match = Formals_To_Match then
4131 -- Most common case: positional notation, no defaults
4136 elsif Actuals_To_Match > Formals_To_Match then
4138 -- Too many actuals: will not work.
4141 Error_Msg_N ("too many arguments in call", N);
4148 First_Named := Actual;
4150 while Present (Actual) loop
4151 if Nkind (Actual) /= N_Parameter_Association then
4153 ("positional parameters not allowed after named ones", Actual);
4158 Actuals_To_Match := Actuals_To_Match + 1;
4164 if Present (Actuals) then
4165 Actual := First (Actuals);
4168 Formal := First_Formal (S);
4170 while Present (Formal) loop
4172 -- Match the formals in order. If the corresponding actual
4173 -- is positional, nothing to do. Else scan the list of named
4174 -- actuals to find the one with the right name.
4177 and then Nkind (Actual) /= N_Parameter_Association
4180 Actuals_To_Match := Actuals_To_Match - 1;
4181 Formals_To_Match := Formals_To_Match - 1;
4184 -- For named parameters, search the list of actuals to find
4185 -- one that matches the next formal name.
4187 Actual := First_Named;
4190 while Present (Actual) loop
4191 if Chars (Selector_Name (Actual)) = Chars (Formal) then
4194 Actuals_To_Match := Actuals_To_Match - 1;
4195 Formals_To_Match := Formals_To_Match - 1;
4203 if Ekind (Formal) /= E_In_Parameter
4204 or else No (Default_Value (Formal))
4207 if Comes_From_Source (S)
4208 and then Is_Overloadable (S)
4210 Error_Msg_Name_1 := Chars (S);
4211 Error_Msg_Sloc := Sloc (S);
4213 ("missing argument for parameter & " &
4214 "in call to % declared #", N, Formal);
4217 ("missing argument for parameter &", N, Formal);
4225 Formals_To_Match := Formals_To_Match - 1;
4230 Next_Formal (Formal);
4233 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
4240 -- Find some superfluous named actual that did not get
4241 -- attached to the list of associations.
4243 Actual := First (Actuals);
4245 while Present (Actual) loop
4247 if Nkind (Actual) = N_Parameter_Association
4248 and then Actual /= Last
4249 and then No (Next_Named_Actual (Actual))
4251 Error_Msg_N ("Unmatched actual in call", Actual);
4262 end Normalize_Actuals;
4264 --------------------------------
4265 -- Note_Possible_Modification --
4266 --------------------------------
4268 procedure Note_Possible_Modification (N : Node_Id) is
4272 procedure Set_Ref (E : Entity_Id; N : Node_Id);
4273 -- Internal routine to note modification on entity E by node N
4275 procedure Set_Ref (E : Entity_Id; N : Node_Id) is
4277 Set_Not_Source_Assigned (E, False);
4278 Set_Is_True_Constant (E, False);
4279 Generate_Reference (E, N, 'm');
4282 -- Start of processing for Note_Possible_Modification
4285 -- Loop to find referenced entity, if there is one
4289 -- Test for node rewritten as dereference (e.g. accept parameter)
4291 if Nkind (Exp) = N_Explicit_Dereference
4292 and then Is_Entity_Name (Original_Node (Exp))
4294 Set_Ref (Entity (Original_Node (Exp)), Original_Node (Exp));
4297 elsif Is_Entity_Name (Exp) then
4298 Ent := Entity (Exp);
4300 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
4301 and then Present (Renamed_Object (Ent))
4303 Exp := Renamed_Object (Ent);
4310 elsif Nkind (Exp) = N_Type_Conversion
4311 or else Nkind (Exp) = N_Unchecked_Type_Conversion
4313 Exp := Expression (Exp);
4315 elsif Nkind (Exp) = N_Slice
4316 or else Nkind (Exp) = N_Indexed_Component
4317 or else Nkind (Exp) = N_Selected_Component
4319 Exp := Prefix (Exp);
4325 end Note_Possible_Modification;
4327 -------------------------
4328 -- Object_Access_Level --
4329 -------------------------
4331 function Object_Access_Level (Obj : Node_Id) return Uint is
4334 -- Returns the static accessibility level of the view denoted
4335 -- by Obj. Note that the value returned is the result of a
4336 -- call to Scope_Depth. Only scope depths associated with
4337 -- dynamic scopes can actually be returned. Since only
4338 -- relative levels matter for accessibility checking, the fact
4339 -- that the distance between successive levels of accessibility
4340 -- is not always one is immaterial (invariant: if level(E2) is
4341 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
4344 if Is_Entity_Name (Obj) then
4347 -- If E is a type then it denotes a current instance.
4348 -- For this case we add one to the normal accessibility
4349 -- level of the type to ensure that current instances
4350 -- are treated as always being deeper than than the level
4351 -- of any visible named access type (see 3.10.2(21)).
4354 return Type_Access_Level (E) + 1;
4356 elsif Present (Renamed_Object (E)) then
4357 return Object_Access_Level (Renamed_Object (E));
4359 -- Similarly, if E is a component of the current instance of a
4360 -- protected type, any instance of it is assumed to be at a deeper
4361 -- level than the type. For a protected object (whose type is an
4362 -- anonymous protected type) its components are at the same level
4363 -- as the type itself.
4365 elsif not Is_Overloadable (E)
4366 and then Ekind (Scope (E)) = E_Protected_Type
4367 and then Comes_From_Source (Scope (E))
4369 return Type_Access_Level (Scope (E)) + 1;
4372 return Scope_Depth (Enclosing_Dynamic_Scope (E));
4375 elsif Nkind (Obj) = N_Selected_Component then
4376 if Is_Access_Type (Etype (Prefix (Obj))) then
4377 return Type_Access_Level (Etype (Prefix (Obj)));
4379 return Object_Access_Level (Prefix (Obj));
4382 elsif Nkind (Obj) = N_Indexed_Component then
4383 if Is_Access_Type (Etype (Prefix (Obj))) then
4384 return Type_Access_Level (Etype (Prefix (Obj)));
4386 return Object_Access_Level (Prefix (Obj));
4389 elsif Nkind (Obj) = N_Explicit_Dereference then
4391 -- If the prefix is a selected access discriminant then
4392 -- we make a recursive call on the prefix, which will
4393 -- in turn check the level of the prefix object of
4394 -- the selected discriminant.
4396 if Nkind (Prefix (Obj)) = N_Selected_Component
4397 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
4399 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
4401 return Object_Access_Level (Prefix (Obj));
4403 return Type_Access_Level (Etype (Prefix (Obj)));
4406 elsif Nkind (Obj) = N_Type_Conversion then
4407 return Object_Access_Level (Expression (Obj));
4409 -- Function results are objects, so we get either the access level
4410 -- of the function or, in the case of an indirect call, the level of
4411 -- of the access-to-subprogram type.
4413 elsif Nkind (Obj) = N_Function_Call then
4414 if Is_Entity_Name (Name (Obj)) then
4415 return Subprogram_Access_Level (Entity (Name (Obj)));
4417 return Type_Access_Level (Etype (Prefix (Name (Obj))));
4420 -- For convenience we handle qualified expressions, even though
4421 -- they aren't technically object names.
4423 elsif Nkind (Obj) = N_Qualified_Expression then
4424 return Object_Access_Level (Expression (Obj));
4426 -- Otherwise return the scope level of Standard.
4427 -- (If there are cases that fall through
4428 -- to this point they will be treated as
4429 -- having global accessibility for now. ???)
4432 return Scope_Depth (Standard_Standard);
4434 end Object_Access_Level;
4436 -----------------------
4437 -- Private_Component --
4438 -----------------------
4440 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
4441 Ancestor : constant Entity_Id := Base_Type (Type_Id);
4443 function Trace_Components
4447 -- Recursive function that does the work, and checks against circular
4448 -- definition for each subcomponent type.
4450 ----------------------
4451 -- Trace_Components --
4452 ----------------------
4454 function Trace_Components
4456 Check : Boolean) return Entity_Id
4458 Btype : constant Entity_Id := Base_Type (T);
4459 Component : Entity_Id;
4461 Candidate : Entity_Id := Empty;
4464 if Check and then Btype = Ancestor then
4465 Error_Msg_N ("circular type definition", Type_Id);
4469 if Is_Private_Type (Btype)
4470 and then not Is_Generic_Type (Btype)
4474 elsif Is_Array_Type (Btype) then
4475 return Trace_Components (Component_Type (Btype), True);
4477 elsif Is_Record_Type (Btype) then
4478 Component := First_Entity (Btype);
4479 while Present (Component) loop
4481 -- skip anonymous types generated by constrained components.
4483 if not Is_Type (Component) then
4484 P := Trace_Components (Etype (Component), True);
4487 if P = Any_Type then
4495 Next_Entity (Component);
4503 end Trace_Components;
4505 -- Start of processing for Private_Component
4508 return Trace_Components (Type_Id, False);
4509 end Private_Component;
4511 -----------------------
4512 -- Process_End_Label --
4513 -----------------------
4515 procedure Process_End_Label
4523 Label_Ref : Boolean;
4524 -- Set True if reference to end label itself is required
4527 -- Gets set to the operator symbol or identifier that references
4528 -- the entity Ent. For the child unit case, this is the identifier
4529 -- from the designator. For other cases, this is simply Endl.
4531 procedure Generate_Parent_Ref (N : Node_Id);
4532 -- N is an identifier node that appears as a parent unit reference
4533 -- in the case where Ent is a child unit. This procedure generates
4534 -- an appropriate cross-reference entry.
4536 -------------------------
4537 -- Generate_Parent_Ref --
4538 -------------------------
4540 procedure Generate_Parent_Ref (N : Node_Id) is
4541 Parent_Ent : Entity_Id;
4544 -- Search up scope stack. The reason we do this is that normal
4545 -- visibility analysis would not work for two reasons. First in
4546 -- some subunit cases, the entry for the parent unit may not be
4547 -- visible, and in any case there can be a local entity that
4548 -- hides the scope entity.
4550 Parent_Ent := Current_Scope;
4551 while Present (Parent_Ent) loop
4552 if Chars (Parent_Ent) = Chars (N) then
4554 -- Generate the reference. We do NOT consider this as a
4555 -- reference for unreferenced symbol purposes, but we do
4556 -- force a cross-reference even if the end line does not
4557 -- come from source (the caller already generated the
4558 -- appropriate Typ for this situation).
4561 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
4562 Style.Check_Identifier (N, Parent_Ent);
4566 Parent_Ent := Scope (Parent_Ent);
4569 -- Fall through means entity was not found -- that's odd, but
4570 -- the appropriate thing is simply to ignore and not generate
4571 -- any cross-reference for this entry.
4574 end Generate_Parent_Ref;
4576 -- Start of processing for Process_End_Label
4579 -- If no node, ignore. This happens in some error situations,
4580 -- and also for some internally generated structures where no
4581 -- end label references are required in any case.
4587 -- Nothing to do if no End_Label, happens for internally generated
4588 -- constructs where we don't want an end label reference anyway.
4589 -- Also nothing to do if Endl is a string literal, which means
4590 -- there was some prior error (bad operator symbol)
4592 Endl := End_Label (N);
4594 if No (Endl) or else Nkind (Endl) = N_String_Literal then
4598 -- Reference node is not in extended main source unit
4600 if not In_Extended_Main_Source_Unit (N) then
4602 -- Generally we do not collect references except for the
4603 -- extended main source unit. The one exception is the 'e'
4604 -- entry for a package spec, where it is useful for a client
4605 -- to have the ending information to define scopes.
4613 -- For this case, we can ignore any parent references,
4614 -- but we need the package name itself for the 'e' entry.
4616 if Nkind (Endl) = N_Designator then
4617 Endl := Identifier (Endl);
4621 -- Reference is in extended main source unit
4626 -- For designator, generate references for the parent entries
4628 if Nkind (Endl) = N_Designator then
4630 -- Generate references for the prefix if the END line comes
4631 -- from source (otherwise we do not need these references)
4633 if Comes_From_Source (Endl) then
4635 while Nkind (Nam) = N_Selected_Component loop
4636 Generate_Parent_Ref (Selector_Name (Nam));
4637 Nam := Prefix (Nam);
4640 Generate_Parent_Ref (Nam);
4643 Endl := Identifier (Endl);
4647 -- If the end label is not for the given entity, then either we have
4648 -- some previous error, or this is a generic instantiation for which
4649 -- we do not need to make a cross-reference in this case anyway. In
4650 -- either case we simply ignore the call.
4652 if Chars (Ent) /= Chars (Endl) then
4656 -- If label was really there, then generate a normal reference
4657 -- and then adjust the location in the end label to point past
4658 -- the name (which should almost always be the semicolon).
4662 if Comes_From_Source (Endl) then
4664 -- If a label reference is required, then do the style check
4665 -- and generate an l-type cross-reference entry for the label
4668 Style.Check_Identifier (Endl, Ent);
4669 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
4672 -- Set the location to point past the label (normally this will
4673 -- mean the semicolon immediately following the label). This is
4674 -- done for the sake of the 'e' or 't' entry generated below.
4676 Get_Decoded_Name_String (Chars (Endl));
4677 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
4680 -- Now generate the e/t reference
4682 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
4684 -- Restore Sloc, in case modified above, since we have an identifier
4685 -- and the normal Sloc should be left set in the tree.
4687 Set_Sloc (Endl, Loc);
4688 end Process_End_Label;
4694 -- We do the conversion to get the value of the real string by using
4695 -- the scanner, see Sinput for details on use of the internal source
4696 -- buffer for scanning internal strings.
4698 function Real_Convert (S : String) return Node_Id is
4699 Save_Src : constant Source_Buffer_Ptr := Source;
4703 Source := Internal_Source_Ptr;
4706 for J in S'Range loop
4707 Source (Source_Ptr (J)) := S (J);
4710 Source (S'Length + 1) := EOF;
4712 if Source (Scan_Ptr) = '-' then
4714 Scan_Ptr := Scan_Ptr + 1;
4722 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
4729 ------------------------------
4730 -- Requires_Transient_Scope --
4731 ------------------------------
4733 -- A transient scope is required when variable-sized temporaries are
4734 -- allocated in the primary or secondary stack, or when finalization
4735 -- actions must be generated before the next instruction
4737 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
4738 Typ : constant Entity_Id := Underlying_Type (Id);
4741 -- This is a private type which is not completed yet. This can only
4742 -- happen in a default expression (of a formal parameter or of a
4743 -- record component). Do not expand transient scope in this case
4748 elsif Typ = Standard_Void_Type then
4751 -- The back-end has trouble allocating variable-size temporaries so
4752 -- we generate them in the front-end and need a transient scope to
4753 -- reclaim them properly
4755 elsif not Size_Known_At_Compile_Time (Typ) then
4758 -- Unconstrained discriminated records always require a variable
4759 -- length temporary, since the length may depend on the variant.
4761 elsif Is_Record_Type (Typ)
4762 and then Has_Discriminants (Typ)
4763 and then not Is_Constrained (Typ)
4767 -- Functions returning tagged types may dispatch on result so their
4768 -- returned value is allocated on the secondary stack. Controlled
4769 -- type temporaries need finalization.
4771 elsif Is_Tagged_Type (Typ)
4772 or else Has_Controlled_Component (Typ)
4776 -- Unconstrained array types are returned on the secondary stack
4778 elsif Is_Array_Type (Typ) then
4779 return not Is_Constrained (Typ);
4783 end Requires_Transient_Scope;
4785 --------------------------
4786 -- Reset_Analyzed_Flags --
4787 --------------------------
4789 procedure Reset_Analyzed_Flags (N : Node_Id) is
4791 function Clear_Analyzed
4793 return Traverse_Result;
4794 -- Function used to reset Analyzed flags in tree. Note that we do
4795 -- not reset Analyzed flags in entities, since there is no need to
4796 -- renalalyze entities, and indeed, it is wrong to do so, since it
4797 -- can result in generating auxiliary stuff more than once.
4799 function Clear_Analyzed
4801 return Traverse_Result
4804 if not Has_Extension (N) then
4805 Set_Analyzed (N, False);
4811 function Reset_Analyzed is
4812 new Traverse_Func (Clear_Analyzed);
4814 Discard : Traverse_Result;
4816 -- Start of processing for Reset_Analyzed_Flags
4819 Discard := Reset_Analyzed (N);
4820 end Reset_Analyzed_Flags;
4826 function Same_Name (N1, N2 : Node_Id) return Boolean is
4827 K1 : constant Node_Kind := Nkind (N1);
4828 K2 : constant Node_Kind := Nkind (N2);
4831 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
4832 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
4834 return Chars (N1) = Chars (N2);
4836 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
4837 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
4839 return Same_Name (Selector_Name (N1), Selector_Name (N2))
4840 and then Same_Name (Prefix (N1), Prefix (N2));
4851 function Same_Type (T1, T2 : Entity_Id) return Boolean is
4856 elsif not Is_Constrained (T1)
4857 and then not Is_Constrained (T2)
4858 and then Base_Type (T1) = Base_Type (T2)
4862 -- For now don't bother with case of identical constraints, to be
4863 -- fiddled with later on perhaps (this is only used for optimization
4864 -- purposes, so it is not critical to do a best possible job)
4871 ------------------------
4872 -- Scope_Is_Transient --
4873 ------------------------
4875 function Scope_Is_Transient return Boolean is
4877 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
4878 end Scope_Is_Transient;
4884 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
4889 while Scop /= Standard_Standard loop
4890 Scop := Scope (Scop);
4892 if Scop = Scope2 then
4900 --------------------------
4901 -- Scope_Within_Or_Same --
4902 --------------------------
4904 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
4909 while Scop /= Standard_Standard loop
4910 if Scop = Scope2 then
4913 Scop := Scope (Scop);
4918 end Scope_Within_Or_Same;
4920 ------------------------
4921 -- Set_Current_Entity --
4922 ------------------------
4924 -- The given entity is to be set as the currently visible definition
4925 -- of its associated name (i.e. the Node_Id associated with its name).
4926 -- All we have to do is to get the name from the identifier, and
4927 -- then set the associated Node_Id to point to the given entity.
4929 procedure Set_Current_Entity (E : Entity_Id) is
4931 Set_Name_Entity_Id (Chars (E), E);
4932 end Set_Current_Entity;
4934 ---------------------------------
4935 -- Set_Entity_With_Style_Check --
4936 ---------------------------------
4938 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
4939 Val_Actual : Entity_Id;
4943 Set_Entity (N, Val);
4946 and then not Suppress_Style_Checks (Val)
4947 and then not In_Instance
4949 if Nkind (N) = N_Identifier then
4952 elsif Nkind (N) = N_Expanded_Name then
4953 Nod := Selector_Name (N);
4961 -- A special situation arises for derived operations, where we want
4962 -- to do the check against the parent (since the Sloc of the derived
4963 -- operation points to the derived type declaration itself).
4965 while not Comes_From_Source (Val_Actual)
4966 and then Nkind (Val_Actual) in N_Entity
4967 and then (Ekind (Val_Actual) = E_Enumeration_Literal
4968 or else Ekind (Val_Actual) = E_Function
4969 or else Ekind (Val_Actual) = E_Generic_Function
4970 or else Ekind (Val_Actual) = E_Procedure
4971 or else Ekind (Val_Actual) = E_Generic_Procedure)
4972 and then Present (Alias (Val_Actual))
4974 Val_Actual := Alias (Val_Actual);
4977 -- Renaming declarations for generic actuals do not come from source,
4978 -- and have a different name from that of the entity they rename, so
4979 -- there is no style check to perform here.
4981 if Chars (Nod) = Chars (Val_Actual) then
4982 Style.Check_Identifier (Nod, Val_Actual);
4987 Set_Entity (N, Val);
4988 end Set_Entity_With_Style_Check;
4990 ------------------------
4991 -- Set_Name_Entity_Id --
4992 ------------------------
4994 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
4996 Set_Name_Table_Info (Id, Int (Val));
4997 end Set_Name_Entity_Id;
4999 ---------------------
5000 -- Set_Next_Actual --
5001 ---------------------
5003 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
5005 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
5006 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
5008 end Set_Next_Actual;
5010 -----------------------
5011 -- Set_Public_Status --
5012 -----------------------
5014 procedure Set_Public_Status (Id : Entity_Id) is
5015 S : constant Entity_Id := Current_Scope;
5018 if S = Standard_Standard
5019 or else (Is_Public (S)
5020 and then (Ekind (S) = E_Package
5021 or else Is_Record_Type (S)
5022 or else Ekind (S) = E_Void))
5026 -- The bounds of an entry family declaration can generate object
5027 -- declarations that are visible to the back-end, e.g. in the
5028 -- the declaration of a composite type that contains tasks.
5031 and then Is_Concurrent_Type (S)
5032 and then not Has_Completion (S)
5033 and then Nkind (Parent (Id)) = N_Object_Declaration
5037 end Set_Public_Status;
5039 ----------------------------
5040 -- Set_Scope_Is_Transient --
5041 ----------------------------
5043 procedure Set_Scope_Is_Transient (V : Boolean := True) is
5045 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
5046 end Set_Scope_Is_Transient;
5052 procedure Set_Size_Info (T1, T2 : Entity_Id) is
5054 -- We copy Esize, but not RM_Size, since in general RM_Size is
5055 -- subtype specific and does not get inherited by all subtypes.
5057 Set_Esize (T1, Esize (T2));
5058 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
5060 if Is_Discrete_Or_Fixed_Point_Type (T1)
5062 Is_Discrete_Or_Fixed_Point_Type (T2)
5064 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
5067 Set_Alignment (T1, Alignment (T2));
5070 --------------------
5071 -- Static_Integer --
5072 --------------------
5074 function Static_Integer (N : Node_Id) return Uint is
5076 Analyze_And_Resolve (N, Any_Integer);
5079 or else Error_Posted (N)
5080 or else Etype (N) = Any_Type
5085 if Is_Static_Expression (N) then
5086 if not Raises_Constraint_Error (N) then
5087 return Expr_Value (N);
5092 elsif Etype (N) = Any_Type then
5096 Error_Msg_N ("static integer expression required here", N);
5101 --------------------------
5102 -- Statically_Different --
5103 --------------------------
5105 function Statically_Different (E1, E2 : Node_Id) return Boolean is
5106 R1 : constant Node_Id := Get_Referenced_Object (E1);
5107 R2 : constant Node_Id := Get_Referenced_Object (E2);
5110 return Is_Entity_Name (R1)
5111 and then Is_Entity_Name (R2)
5112 and then Entity (R1) /= Entity (R2)
5113 and then not Is_Formal (Entity (R1))
5114 and then not Is_Formal (Entity (R2));
5115 end Statically_Different;
5117 -----------------------------
5118 -- Subprogram_Access_Level --
5119 -----------------------------
5121 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
5123 if Present (Alias (Subp)) then
5124 return Subprogram_Access_Level (Alias (Subp));
5126 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
5128 end Subprogram_Access_Level;
5134 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
5136 if Debug_Flag_W then
5137 for J in 0 .. Scope_Stack.Last loop
5142 Write_Name (Chars (E));
5143 Write_Str (" line ");
5144 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
5149 -----------------------
5150 -- Transfer_Entities --
5151 -----------------------
5153 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
5154 Ent : Entity_Id := First_Entity (From);
5161 if (Last_Entity (To)) = Empty then
5162 Set_First_Entity (To, Ent);
5164 Set_Next_Entity (Last_Entity (To), Ent);
5167 Set_Last_Entity (To, Last_Entity (From));
5169 while Present (Ent) loop
5170 Set_Scope (Ent, To);
5172 if not Is_Public (Ent) then
5173 Set_Public_Status (Ent);
5176 and then Ekind (Ent) = E_Record_Subtype
5179 -- The components of the propagated Itype must be public
5186 Comp := First_Entity (Ent);
5188 while Present (Comp) loop
5189 Set_Is_Public (Comp);
5199 Set_First_Entity (From, Empty);
5200 Set_Last_Entity (From, Empty);
5201 end Transfer_Entities;
5203 -----------------------
5204 -- Type_Access_Level --
5205 -----------------------
5207 function Type_Access_Level (Typ : Entity_Id) return Uint is
5208 Btyp : Entity_Id := Base_Type (Typ);
5211 -- If the type is an anonymous access type we treat it as being
5212 -- declared at the library level to ensure that names such as
5213 -- X.all'access don't fail static accessibility checks.
5215 if Ekind (Btyp) in Access_Kind then
5216 if Ekind (Btyp) = E_Anonymous_Access_Type then
5217 return Scope_Depth (Standard_Standard);
5220 Btyp := Root_Type (Btyp);
5223 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
5224 end Type_Access_Level;
5226 --------------------------
5227 -- Unit_Declaration_Node --
5228 --------------------------
5230 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
5231 N : Node_Id := Parent (Unit_Id);
5234 -- Predefined operators do not have a full function declaration.
5236 if Ekind (Unit_Id) = E_Operator then
5240 while Nkind (N) /= N_Abstract_Subprogram_Declaration
5241 and then Nkind (N) /= N_Formal_Package_Declaration
5242 and then Nkind (N) /= N_Formal_Subprogram_Declaration
5243 and then Nkind (N) /= N_Function_Instantiation
5244 and then Nkind (N) /= N_Generic_Package_Declaration
5245 and then Nkind (N) /= N_Generic_Subprogram_Declaration
5246 and then Nkind (N) /= N_Package_Declaration
5247 and then Nkind (N) /= N_Package_Body
5248 and then Nkind (N) /= N_Package_Instantiation
5249 and then Nkind (N) /= N_Package_Renaming_Declaration
5250 and then Nkind (N) /= N_Procedure_Instantiation
5251 and then Nkind (N) /= N_Subprogram_Declaration
5252 and then Nkind (N) /= N_Subprogram_Body
5253 and then Nkind (N) /= N_Subprogram_Body_Stub
5254 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
5255 and then Nkind (N) /= N_Task_Body
5256 and then Nkind (N) /= N_Task_Type_Declaration
5257 and then Nkind (N) not in N_Generic_Renaming_Declaration
5260 pragma Assert (Present (N));
5264 end Unit_Declaration_Node;
5266 ----------------------
5267 -- Within_Init_Proc --
5268 ----------------------
5270 function Within_Init_Proc return Boolean is
5275 while not Is_Overloadable (S) loop
5276 if S = Standard_Standard then
5283 return Chars (S) = Name_uInit_Proc;
5284 end Within_Init_Proc;
5290 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
5291 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
5292 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
5294 function Has_One_Matching_Field return Boolean;
5295 -- Determines whether Expec_Type is a record type with a single
5296 -- component or discriminant whose type matches the found type or
5297 -- is a one dimensional array whose component type matches the
5300 function Has_One_Matching_Field return Boolean is
5304 if Is_Array_Type (Expec_Type)
5305 and then Number_Dimensions (Expec_Type) = 1
5307 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
5311 elsif not Is_Record_Type (Expec_Type) then
5315 E := First_Entity (Expec_Type);
5321 elsif (Ekind (E) /= E_Discriminant
5322 and then Ekind (E) /= E_Component)
5323 or else (Chars (E) = Name_uTag
5324 or else Chars (E) = Name_uParent)
5333 if not Covers (Etype (E), Found_Type) then
5336 elsif Present (Next_Entity (E)) then
5343 end Has_One_Matching_Field;
5345 -- Start of processing for Wrong_Type
5348 -- Don't output message if either type is Any_Type, or if a message
5349 -- has already been posted for this node. We need to do the latter
5350 -- check explicitly (it is ordinarily done in Errout), because we
5351 -- are using ! to force the output of the error messages.
5353 if Expec_Type = Any_Type
5354 or else Found_Type = Any_Type
5355 or else Error_Posted (Expr)
5359 -- In an instance, there is an ongoing problem with completion of
5360 -- type derived from private types. Their structure is what Gigi
5361 -- expects, but the Etype is the parent type rather than the
5362 -- derived private type itself. Do not flag error in this case. The
5363 -- private completion is an entity without a parent, like an Itype.
5364 -- Similarly, full and partial views may be incorrect in the instance.
5365 -- There is no simple way to insure that it is consistent ???
5367 elsif In_Instance then
5369 if Etype (Etype (Expr)) = Etype (Expected_Type)
5370 and then No (Parent (Expected_Type))
5376 -- An interesting special check. If the expression is parenthesized
5377 -- and its type corresponds to the type of the sole component of the
5378 -- expected record type, or to the component type of the expected one
5379 -- dimensional array type, then assume we have a bad aggregate attempt.
5381 if Nkind (Expr) in N_Subexpr
5382 and then Paren_Count (Expr) /= 0
5383 and then Has_One_Matching_Field
5385 Error_Msg_N ("positional aggregate cannot have one component", Expr);
5387 -- Another special check, if we are looking for a pool-specific access
5388 -- type and we found an E_Access_Attribute_Type, then we have the case
5389 -- of an Access attribute being used in a context which needs a pool-
5390 -- specific type, which is never allowed. The one extra check we make
5391 -- is that the expected designated type covers the Found_Type.
5393 elsif Is_Access_Type (Expec_Type)
5394 and then Ekind (Found_Type) = E_Access_Attribute_Type
5395 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
5396 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
5398 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
5400 Error_Msg_N ("result must be general access type!", Expr);
5401 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
5403 -- If the expected type is an anonymous access type, as for access
5404 -- parameters and discriminants, the error is on the designated types.
5406 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
5407 if Comes_From_Source (Expec_Type) then
5408 Error_Msg_NE ("expected}!", Expr, Expec_Type);
5411 ("expected an access type with designated}",
5412 Expr, Designated_Type (Expec_Type));
5415 if Is_Access_Type (Found_Type)
5416 and then not Comes_From_Source (Found_Type)
5419 ("found an access type with designated}!",
5420 Expr, Designated_Type (Found_Type));
5422 if From_With_Type (Found_Type) then
5423 Error_Msg_NE ("found incomplete}!", Expr, Found_Type);
5425 ("\possibly missing with_clause on&", Expr,
5426 Scope (Found_Type));
5428 Error_Msg_NE ("found}!", Expr, Found_Type);
5432 -- Normal case of one type found, some other type expected
5435 -- If the names of the two types are the same, see if some
5436 -- number of levels of qualification will help. Don't try
5437 -- more than three levels, and if we get to standard, it's
5438 -- no use (and probably represents an error in the compiler)
5439 -- Also do not bother with internal scope names.
5442 Expec_Scope : Entity_Id;
5443 Found_Scope : Entity_Id;
5446 Expec_Scope := Expec_Type;
5447 Found_Scope := Found_Type;
5449 for Levels in Int range 0 .. 3 loop
5450 if Chars (Expec_Scope) /= Chars (Found_Scope) then
5451 Error_Msg_Qual_Level := Levels;
5455 Expec_Scope := Scope (Expec_Scope);
5456 Found_Scope := Scope (Found_Scope);
5458 exit when Expec_Scope = Standard_Standard
5460 Found_Scope = Standard_Standard
5462 not Comes_From_Source (Expec_Scope)
5464 not Comes_From_Source (Found_Scope);
5468 Error_Msg_NE ("expected}!", Expr, Expec_Type);
5470 if Is_Entity_Name (Expr)
5471 and then Is_Package (Entity (Expr))
5473 Error_Msg_N ("found package name!", Expr);
5475 elsif Is_Entity_Name (Expr)
5477 (Ekind (Entity (Expr)) = E_Procedure
5479 Ekind (Entity (Expr)) = E_Generic_Procedure)
5481 Error_Msg_N ("found procedure name instead of function!", Expr);
5483 -- catch common error: a prefix or infix operator which is not
5484 -- directly visible because the type isn't.
5486 elsif Nkind (Expr) in N_Op
5487 and then Is_Overloaded (Expr)
5488 and then not Is_Immediately_Visible (Expec_Type)
5489 and then not Is_Potentially_Use_Visible (Expec_Type)
5490 and then not In_Use (Expec_Type)
5491 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
5494 "operator of the type is not directly visible!", Expr);
5497 Error_Msg_NE ("found}!", Expr, Found_Type);
5500 Error_Msg_Qual_Level := 0;