1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Errout; use Errout;
32 with Elists; use Elists;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
44 with Rtsfind; use Rtsfind;
45 with Scans; use Scans;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Snames; use Snames;
55 with Stand; use Stand;
57 with Stringt; use Stringt;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
62 package body Sem_Util is
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 function Build_Component_Subtype
71 T : Entity_Id) return Node_Id;
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 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
77 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
78 -- with discriminants whose default values are static, examine only the
79 -- components in the selected variant to determine whether all of them
82 function Has_Null_Extension (T : Entity_Id) return Boolean;
83 -- T is a derived tagged type. Check whether the type extension is null.
84 -- If the parent type is fully initialized, T can be treated as such.
86 --------------------------------
87 -- Add_Access_Type_To_Process --
88 --------------------------------
90 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
94 Ensure_Freeze_Node (E);
95 L := Access_Types_To_Process (Freeze_Node (E));
99 Set_Access_Types_To_Process (Freeze_Node (E), L);
103 end Add_Access_Type_To_Process;
105 -----------------------
106 -- Alignment_In_Bits --
107 -----------------------
109 function Alignment_In_Bits (E : Entity_Id) return Uint is
111 return Alignment (E) * System_Storage_Unit;
112 end Alignment_In_Bits;
114 -----------------------------------------
115 -- Apply_Compile_Time_Constraint_Error --
116 -----------------------------------------
118 procedure Apply_Compile_Time_Constraint_Error
121 Reason : RT_Exception_Code;
122 Ent : Entity_Id := Empty;
123 Typ : Entity_Id := Empty;
124 Loc : Source_Ptr := No_Location;
125 Rep : Boolean := True;
126 Warn : Boolean := False)
128 Stat : constant Boolean := Is_Static_Expression (N);
139 Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
145 -- Now we replace the node by an N_Raise_Constraint_Error node
146 -- This does not need reanalyzing, so set it as analyzed now.
149 Make_Raise_Constraint_Error (Sloc (N),
151 Set_Analyzed (N, True);
153 Set_Raises_Constraint_Error (N);
155 -- If the original expression was marked as static, the result is
156 -- still marked as static, but the Raises_Constraint_Error flag is
157 -- always set so that further static evaluation is not attempted.
160 Set_Is_Static_Expression (N);
162 end Apply_Compile_Time_Constraint_Error;
164 --------------------------
165 -- Build_Actual_Subtype --
166 --------------------------
168 function Build_Actual_Subtype
170 N : Node_Or_Entity_Id) return Node_Id
174 Loc : constant Source_Ptr := Sloc (N);
175 Constraints : List_Id;
181 Disc_Type : Entity_Id;
184 if Nkind (N) = N_Defining_Identifier then
185 Obj := New_Reference_To (N, Loc);
190 if Is_Array_Type (T) then
191 Constraints := New_List;
193 for J in 1 .. Number_Dimensions (T) loop
195 -- Build an array subtype declaration with the nominal
196 -- subtype and the bounds of the actual. Add the declaration
197 -- in front of the local declarations for the subprogram, for
198 -- analysis before any reference to the formal in the body.
201 Make_Attribute_Reference (Loc,
203 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
204 Attribute_Name => Name_First,
205 Expressions => New_List (
206 Make_Integer_Literal (Loc, J)));
209 Make_Attribute_Reference (Loc,
211 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
212 Attribute_Name => Name_Last,
213 Expressions => New_List (
214 Make_Integer_Literal (Loc, J)));
216 Append (Make_Range (Loc, Lo, Hi), Constraints);
219 -- If the type has unknown discriminants there is no constrained
220 -- subtype to build. This is never called for a formal or for a
221 -- lhs, so returning the type is ok ???
223 elsif Has_Unknown_Discriminants (T) then
227 Constraints := New_List;
229 if Is_Private_Type (T) and then No (Full_View (T)) then
231 -- Type is a generic derived type. Inherit discriminants from
234 Disc_Type := Etype (Base_Type (T));
239 Discr := First_Discriminant (Disc_Type);
241 while Present (Discr) loop
242 Append_To (Constraints,
243 Make_Selected_Component (Loc,
245 Duplicate_Subexpr_No_Checks (Obj),
246 Selector_Name => New_Occurrence_Of (Discr, Loc)));
247 Next_Discriminant (Discr);
252 Make_Defining_Identifier (Loc,
253 Chars => New_Internal_Name ('S'));
254 Set_Is_Internal (Subt);
257 Make_Subtype_Declaration (Loc,
258 Defining_Identifier => Subt,
259 Subtype_Indication =>
260 Make_Subtype_Indication (Loc,
261 Subtype_Mark => New_Reference_To (T, Loc),
263 Make_Index_Or_Discriminant_Constraint (Loc,
264 Constraints => Constraints)));
266 Mark_Rewrite_Insertion (Decl);
268 end Build_Actual_Subtype;
270 ---------------------------------------
271 -- Build_Actual_Subtype_Of_Component --
272 ---------------------------------------
274 function Build_Actual_Subtype_Of_Component
276 N : Node_Id) return Node_Id
278 Loc : constant Source_Ptr := Sloc (N);
279 P : constant Node_Id := Prefix (N);
282 Indx_Type : Entity_Id;
284 Deaccessed_T : Entity_Id;
285 -- This is either a copy of T, or if T is an access type, then it is
286 -- the directly designated type of this access type.
288 function Build_Actual_Array_Constraint return List_Id;
289 -- If one or more of the bounds of the component depends on
290 -- discriminants, build actual constraint using the discriminants
293 function Build_Actual_Record_Constraint return List_Id;
294 -- Similar to previous one, for discriminated components constrained
295 -- by the discriminant of the enclosing object.
297 -----------------------------------
298 -- Build_Actual_Array_Constraint --
299 -----------------------------------
301 function Build_Actual_Array_Constraint return List_Id is
302 Constraints : constant List_Id := New_List;
310 Indx := First_Index (Deaccessed_T);
311 while Present (Indx) loop
312 Old_Lo := Type_Low_Bound (Etype (Indx));
313 Old_Hi := Type_High_Bound (Etype (Indx));
315 if Denotes_Discriminant (Old_Lo) then
317 Make_Selected_Component (Loc,
318 Prefix => New_Copy_Tree (P),
319 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
322 Lo := New_Copy_Tree (Old_Lo);
324 -- The new bound will be reanalyzed in the enclosing
325 -- declaration. For literal bounds that come from a type
326 -- declaration, the type of the context must be imposed, so
327 -- insure that analysis will take place. For non-universal
328 -- types this is not strictly necessary.
330 Set_Analyzed (Lo, False);
333 if Denotes_Discriminant (Old_Hi) then
335 Make_Selected_Component (Loc,
336 Prefix => New_Copy_Tree (P),
337 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
340 Hi := New_Copy_Tree (Old_Hi);
341 Set_Analyzed (Hi, False);
344 Append (Make_Range (Loc, Lo, Hi), Constraints);
349 end Build_Actual_Array_Constraint;
351 ------------------------------------
352 -- Build_Actual_Record_Constraint --
353 ------------------------------------
355 function Build_Actual_Record_Constraint return List_Id is
356 Constraints : constant List_Id := New_List;
361 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
362 while Present (D) loop
364 if Denotes_Discriminant (Node (D)) then
365 D_Val := Make_Selected_Component (Loc,
366 Prefix => New_Copy_Tree (P),
367 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
370 D_Val := New_Copy_Tree (Node (D));
373 Append (D_Val, Constraints);
378 end Build_Actual_Record_Constraint;
380 -- Start of processing for Build_Actual_Subtype_Of_Component
383 if In_Default_Expression then
386 elsif Nkind (N) = N_Explicit_Dereference then
387 if Is_Composite_Type (T)
388 and then not Is_Constrained (T)
389 and then not (Is_Class_Wide_Type (T)
390 and then Is_Constrained (Root_Type (T)))
391 and then not Has_Unknown_Discriminants (T)
393 -- If the type of the dereference is already constrained, it
394 -- is an actual subtype.
396 if Is_Array_Type (Etype (N))
397 and then Is_Constrained (Etype (N))
401 Remove_Side_Effects (P);
402 return Build_Actual_Subtype (T, N);
409 if Ekind (T) = E_Access_Subtype then
410 Deaccessed_T := Designated_Type (T);
415 if Ekind (Deaccessed_T) = E_Array_Subtype then
416 Id := First_Index (Deaccessed_T);
417 Indx_Type := Underlying_Type (Etype (Id));
419 while Present (Id) loop
421 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
422 Denotes_Discriminant (Type_High_Bound (Indx_Type))
424 Remove_Side_Effects (P);
426 Build_Component_Subtype (
427 Build_Actual_Array_Constraint, Loc, Base_Type (T));
433 elsif Is_Composite_Type (Deaccessed_T)
434 and then Has_Discriminants (Deaccessed_T)
435 and then not Has_Unknown_Discriminants (Deaccessed_T)
437 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
438 while Present (D) loop
440 if Denotes_Discriminant (Node (D)) then
441 Remove_Side_Effects (P);
443 Build_Component_Subtype (
444 Build_Actual_Record_Constraint, Loc, Base_Type (T));
451 -- If none of the above, the actual and nominal subtypes are the same
454 end Build_Actual_Subtype_Of_Component;
456 -----------------------------
457 -- Build_Component_Subtype --
458 -----------------------------
460 function Build_Component_Subtype
463 T : Entity_Id) return Node_Id
469 -- Unchecked_Union components do not require component subtypes
471 if Is_Unchecked_Union (T) then
476 Make_Defining_Identifier (Loc,
477 Chars => New_Internal_Name ('S'));
478 Set_Is_Internal (Subt);
481 Make_Subtype_Declaration (Loc,
482 Defining_Identifier => Subt,
483 Subtype_Indication =>
484 Make_Subtype_Indication (Loc,
485 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
487 Make_Index_Or_Discriminant_Constraint (Loc,
490 Mark_Rewrite_Insertion (Decl);
492 end Build_Component_Subtype;
494 --------------------------------------------
495 -- Build_Discriminal_Subtype_Of_Component --
496 --------------------------------------------
498 function Build_Discriminal_Subtype_Of_Component
499 (T : Entity_Id) return Node_Id
501 Loc : constant Source_Ptr := Sloc (T);
505 function Build_Discriminal_Array_Constraint return List_Id;
506 -- If one or more of the bounds of the component depends on
507 -- discriminants, build actual constraint using the discriminants
510 function Build_Discriminal_Record_Constraint return List_Id;
511 -- Similar to previous one, for discriminated components constrained
512 -- by the discriminant of the enclosing object.
514 ----------------------------------------
515 -- Build_Discriminal_Array_Constraint --
516 ----------------------------------------
518 function Build_Discriminal_Array_Constraint return List_Id is
519 Constraints : constant List_Id := New_List;
527 Indx := First_Index (T);
528 while Present (Indx) loop
529 Old_Lo := Type_Low_Bound (Etype (Indx));
530 Old_Hi := Type_High_Bound (Etype (Indx));
532 if Denotes_Discriminant (Old_Lo) then
533 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
536 Lo := New_Copy_Tree (Old_Lo);
539 if Denotes_Discriminant (Old_Hi) then
540 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
543 Hi := New_Copy_Tree (Old_Hi);
546 Append (Make_Range (Loc, Lo, Hi), Constraints);
551 end Build_Discriminal_Array_Constraint;
553 -----------------------------------------
554 -- Build_Discriminal_Record_Constraint --
555 -----------------------------------------
557 function Build_Discriminal_Record_Constraint return List_Id is
558 Constraints : constant List_Id := New_List;
563 D := First_Elmt (Discriminant_Constraint (T));
564 while Present (D) loop
565 if Denotes_Discriminant (Node (D)) then
567 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
570 D_Val := New_Copy_Tree (Node (D));
573 Append (D_Val, Constraints);
578 end Build_Discriminal_Record_Constraint;
580 -- Start of processing for Build_Discriminal_Subtype_Of_Component
583 if Ekind (T) = E_Array_Subtype then
584 Id := First_Index (T);
586 while Present (Id) loop
587 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
588 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
590 return Build_Component_Subtype
591 (Build_Discriminal_Array_Constraint, Loc, T);
597 elsif Ekind (T) = E_Record_Subtype
598 and then Has_Discriminants (T)
599 and then not Has_Unknown_Discriminants (T)
601 D := First_Elmt (Discriminant_Constraint (T));
602 while Present (D) loop
603 if Denotes_Discriminant (Node (D)) then
604 return Build_Component_Subtype
605 (Build_Discriminal_Record_Constraint, Loc, T);
612 -- If none of the above, the actual and nominal subtypes are the same
615 end Build_Discriminal_Subtype_Of_Component;
617 ------------------------------
618 -- Build_Elaboration_Entity --
619 ------------------------------
621 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
622 Loc : constant Source_Ptr := Sloc (N);
623 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
626 Elab_Ent : Entity_Id;
629 -- Ignore if already constructed
631 if Present (Elaboration_Entity (Spec_Id)) then
635 -- Construct name of elaboration entity as xxx_E, where xxx
636 -- is the unit name with dots replaced by double underscore.
637 -- We have to manually construct this name, since it will
638 -- be elaborated in the outer scope, and thus will not have
639 -- the unit name automatically prepended.
641 Get_Name_String (Unit_Name (Unum));
643 -- Replace the %s by _E
645 Name_Buffer (Name_Len - 1 .. Name_Len) := "_E";
647 -- Replace dots by double underscore
650 while P < Name_Len - 2 loop
651 if Name_Buffer (P) = '.' then
652 Name_Buffer (P + 2 .. Name_Len + 1) :=
653 Name_Buffer (P + 1 .. Name_Len);
654 Name_Len := Name_Len + 1;
655 Name_Buffer (P) := '_';
656 Name_Buffer (P + 1) := '_';
663 -- Create elaboration flag
666 Make_Defining_Identifier (Loc, Chars => Name_Find);
667 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
669 if No (Declarations (Aux_Decls_Node (N))) then
670 Set_Declarations (Aux_Decls_Node (N), New_List);
674 Make_Object_Declaration (Loc,
675 Defining_Identifier => Elab_Ent,
677 New_Occurrence_Of (Standard_Boolean, Loc),
679 New_Occurrence_Of (Standard_False, Loc));
681 Append_To (Declarations (Aux_Decls_Node (N)), Decl);
684 -- Reset True_Constant indication, since we will indeed
685 -- assign a value to the variable in the binder main.
687 Set_Is_True_Constant (Elab_Ent, False);
688 Set_Current_Value (Elab_Ent, Empty);
690 -- We do not want any further qualification of the name (if we did
691 -- not do this, we would pick up the name of the generic package
692 -- in the case of a library level generic instantiation).
694 Set_Has_Qualified_Name (Elab_Ent);
695 Set_Has_Fully_Qualified_Name (Elab_Ent);
696 end Build_Elaboration_Entity;
698 -----------------------------------
699 -- Cannot_Raise_Constraint_Error --
700 -----------------------------------
702 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
704 if Compile_Time_Known_Value (Expr) then
707 elsif Do_Range_Check (Expr) then
710 elsif Raises_Constraint_Error (Expr) then
718 when N_Expanded_Name =>
721 when N_Selected_Component =>
722 return not Do_Discriminant_Check (Expr);
724 when N_Attribute_Reference =>
725 if Do_Overflow_Check (Expr) then
728 elsif No (Expressions (Expr)) then
733 N : Node_Id := First (Expressions (Expr));
736 while Present (N) loop
737 if Cannot_Raise_Constraint_Error (N) then
748 when N_Type_Conversion =>
749 if Do_Overflow_Check (Expr)
750 or else Do_Length_Check (Expr)
751 or else Do_Tag_Check (Expr)
756 Cannot_Raise_Constraint_Error (Expression (Expr));
759 when N_Unchecked_Type_Conversion =>
760 return Cannot_Raise_Constraint_Error (Expression (Expr));
763 if Do_Overflow_Check (Expr) then
767 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
774 if Do_Division_Check (Expr)
775 or else Do_Overflow_Check (Expr)
780 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
782 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
801 N_Op_Shift_Right_Arithmetic |
805 if Do_Overflow_Check (Expr) then
809 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
811 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
818 end Cannot_Raise_Constraint_Error;
820 --------------------------
821 -- Check_Fully_Declared --
822 --------------------------
824 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
826 if Ekind (T) = E_Incomplete_Type then
828 -- Ada 2005 (AI-50217): If the type is available through a limited
829 -- with_clause, verify that its full view has been analyzed.
831 if From_With_Type (T)
832 and then Present (Non_Limited_View (T))
833 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
835 -- The non-limited view is fully declared
840 ("premature usage of incomplete}", N, First_Subtype (T));
843 elsif Has_Private_Component (T)
844 and then not Is_Generic_Type (Root_Type (T))
845 and then not In_Default_Expression
848 -- Special case: if T is the anonymous type created for a single
849 -- task or protected object, use the name of the source object.
851 if Is_Concurrent_Type (T)
852 and then not Comes_From_Source (T)
853 and then Nkind (N) = N_Object_Declaration
855 Error_Msg_NE ("type of& has incomplete component", N,
856 Defining_Identifier (N));
860 ("premature usage of incomplete}", N, First_Subtype (T));
863 end Check_Fully_Declared;
865 ------------------------------------------
866 -- Check_Potentially_Blocking_Operation --
867 ------------------------------------------
869 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
873 -- N is one of the potentially blocking operations listed in 9.5.1(8).
874 -- When pragma Detect_Blocking is active, the run time will raise
875 -- Program_Error. Here we only issue a warning, since we generally
876 -- support the use of potentially blocking operations in the absence
879 -- Indirect blocking through a subprogram call cannot be diagnosed
880 -- statically without interprocedural analysis, so we do not attempt
883 S := Scope (Current_Scope);
884 while Present (S) and then S /= Standard_Standard loop
885 if Is_Protected_Type (S) then
887 ("potentially blocking operation in protected operation?", N);
894 end Check_Potentially_Blocking_Operation;
900 procedure Check_VMS (Construct : Node_Id) is
902 if not OpenVMS_On_Target then
904 ("this construct is allowed only in Open'V'M'S", Construct);
908 ----------------------------------
909 -- Collect_Primitive_Operations --
910 ----------------------------------
912 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
913 B_Type : constant Entity_Id := Base_Type (T);
914 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
915 B_Scope : Entity_Id := Scope (B_Type);
919 Formal_Derived : Boolean := False;
923 -- For tagged types, the primitive operations are collected as they
924 -- are declared, and held in an explicit list which is simply returned.
926 if Is_Tagged_Type (B_Type) then
927 return Primitive_Operations (B_Type);
929 -- An untagged generic type that is a derived type inherits the
930 -- primitive operations of its parent type. Other formal types only
931 -- have predefined operators, which are not explicitly represented.
933 elsif Is_Generic_Type (B_Type) then
934 if Nkind (B_Decl) = N_Formal_Type_Declaration
935 and then Nkind (Formal_Type_Definition (B_Decl))
936 = N_Formal_Derived_Type_Definition
938 Formal_Derived := True;
940 return New_Elmt_List;
944 Op_List := New_Elmt_List;
946 if B_Scope = Standard_Standard then
947 if B_Type = Standard_String then
948 Append_Elmt (Standard_Op_Concat, Op_List);
950 elsif B_Type = Standard_Wide_String then
951 Append_Elmt (Standard_Op_Concatw, Op_List);
957 elsif (Is_Package (B_Scope)
959 Parent (Declaration_Node (First_Subtype (T))))
962 or else Is_Derived_Type (B_Type)
964 -- The primitive operations appear after the base type, except
965 -- if the derivation happens within the private part of B_Scope
966 -- and the type is a private type, in which case both the type
967 -- and some primitive operations may appear before the base
968 -- type, and the list of candidates starts after the type.
970 if In_Open_Scopes (B_Scope)
971 and then Scope (T) = B_Scope
972 and then In_Private_Part (B_Scope)
974 Id := Next_Entity (T);
976 Id := Next_Entity (B_Type);
979 while Present (Id) loop
981 -- Note that generic formal subprograms are not
982 -- considered to be primitive operations and thus
983 -- are never inherited.
985 if Is_Overloadable (Id)
986 and then Nkind (Parent (Parent (Id)))
987 /= N_Formal_Subprogram_Declaration
991 if Base_Type (Etype (Id)) = B_Type then
994 Formal := First_Formal (Id);
995 while Present (Formal) loop
996 if Base_Type (Etype (Formal)) = B_Type then
1000 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1002 (Designated_Type (Etype (Formal))) = B_Type
1008 Next_Formal (Formal);
1012 -- For a formal derived type, the only primitives are the
1013 -- ones inherited from the parent type. Operations appearing
1014 -- in the package declaration are not primitive for it.
1017 and then (not Formal_Derived
1018 or else Present (Alias (Id)))
1020 Append_Elmt (Id, Op_List);
1026 -- For a type declared in System, some of its operations
1027 -- may appear in the target-specific extension to System.
1030 and then Chars (B_Scope) = Name_System
1031 and then Scope (B_Scope) = Standard_Standard
1032 and then Present_System_Aux
1034 B_Scope := System_Aux_Id;
1035 Id := First_Entity (System_Aux_Id);
1041 end Collect_Primitive_Operations;
1043 -----------------------------------
1044 -- Compile_Time_Constraint_Error --
1045 -----------------------------------
1047 function Compile_Time_Constraint_Error
1050 Ent : Entity_Id := Empty;
1051 Loc : Source_Ptr := No_Location;
1052 Warn : Boolean := False) return Node_Id
1054 Msgc : String (1 .. Msg'Length + 2);
1062 -- A static constraint error in an instance body is not a fatal error.
1063 -- we choose to inhibit the message altogether, because there is no
1064 -- obvious node (for now) on which to post it. On the other hand the
1065 -- offending node must be replaced with a constraint_error in any case.
1067 -- No messages are generated if we already posted an error on this node
1069 if not Error_Posted (N) then
1070 if Loc /= No_Location then
1076 -- Make all such messages unconditional
1078 Msgc (1 .. Msg'Length) := Msg;
1079 Msgc (Msg'Length + 1) := '!';
1080 Msgl := Msg'Length + 1;
1082 -- Message is a warning, even in Ada 95 case
1084 if Msg (Msg'Length) = '?' then
1087 -- In Ada 83, all messages are warnings. In the private part and
1088 -- the body of an instance, constraint_checks are only warnings.
1089 -- We also make this a warning if the Warn parameter is set.
1092 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1098 elsif In_Instance_Not_Visible then
1103 -- Otherwise we have a real error message (Ada 95 static case)
1109 -- Should we generate a warning? The answer is not quite yes. The
1110 -- very annoying exception occurs in the case of a short circuit
1111 -- operator where the left operand is static and decisive. Climb
1112 -- parents to see if that is the case we have here.
1120 if (Nkind (P) = N_And_Then
1121 and then Compile_Time_Known_Value (Left_Opnd (P))
1122 and then Is_False (Expr_Value (Left_Opnd (P))))
1123 or else (Nkind (P) = N_Or_Else
1124 and then Compile_Time_Known_Value (Left_Opnd (P))
1125 and then Is_True (Expr_Value (Left_Opnd (P))))
1130 elsif Nkind (P) = N_Component_Association
1131 and then Nkind (Parent (P)) = N_Aggregate
1133 null; -- Keep going.
1136 exit when Nkind (P) not in N_Subexpr;
1141 if Present (Ent) then
1142 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1144 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1148 if Inside_Init_Proc then
1150 ("\& will be raised for objects of this type!?",
1151 N, Standard_Constraint_Error, Eloc);
1154 ("\& will be raised at run time!?",
1155 N, Standard_Constraint_Error, Eloc);
1159 ("\static expression raises&!",
1160 N, Standard_Constraint_Error, Eloc);
1166 end Compile_Time_Constraint_Error;
1168 -----------------------
1169 -- Conditional_Delay --
1170 -----------------------
1172 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1174 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1175 Set_Has_Delayed_Freeze (New_Ent);
1177 end Conditional_Delay;
1179 --------------------
1180 -- Current_Entity --
1181 --------------------
1183 -- The currently visible definition for a given identifier is the
1184 -- one most chained at the start of the visibility chain, i.e. the
1185 -- one that is referenced by the Node_Id value of the name of the
1186 -- given identifier.
1188 function Current_Entity (N : Node_Id) return Entity_Id is
1190 return Get_Name_Entity_Id (Chars (N));
1193 -----------------------------
1194 -- Current_Entity_In_Scope --
1195 -----------------------------
1197 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1199 CS : constant Entity_Id := Current_Scope;
1201 Transient_Case : constant Boolean := Scope_Is_Transient;
1204 E := Get_Name_Entity_Id (Chars (N));
1207 and then Scope (E) /= CS
1208 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1214 end Current_Entity_In_Scope;
1220 function Current_Scope return Entity_Id is
1222 if Scope_Stack.Last = -1 then
1223 return Standard_Standard;
1226 C : constant Entity_Id :=
1227 Scope_Stack.Table (Scope_Stack.Last).Entity;
1232 return Standard_Standard;
1238 ------------------------
1239 -- Current_Subprogram --
1240 ------------------------
1242 function Current_Subprogram return Entity_Id is
1243 Scop : constant Entity_Id := Current_Scope;
1246 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1249 return Enclosing_Subprogram (Scop);
1251 end Current_Subprogram;
1253 ---------------------
1254 -- Defining_Entity --
1255 ---------------------
1257 function Defining_Entity (N : Node_Id) return Entity_Id is
1258 K : constant Node_Kind := Nkind (N);
1259 Err : Entity_Id := Empty;
1264 N_Subprogram_Declaration |
1265 N_Abstract_Subprogram_Declaration |
1267 N_Package_Declaration |
1268 N_Subprogram_Renaming_Declaration |
1269 N_Subprogram_Body_Stub |
1270 N_Generic_Subprogram_Declaration |
1271 N_Generic_Package_Declaration |
1272 N_Formal_Subprogram_Declaration
1274 return Defining_Entity (Specification (N));
1277 N_Component_Declaration |
1278 N_Defining_Program_Unit_Name |
1279 N_Discriminant_Specification |
1281 N_Entry_Declaration |
1282 N_Entry_Index_Specification |
1283 N_Exception_Declaration |
1284 N_Exception_Renaming_Declaration |
1285 N_Formal_Object_Declaration |
1286 N_Formal_Package_Declaration |
1287 N_Formal_Type_Declaration |
1288 N_Full_Type_Declaration |
1289 N_Implicit_Label_Declaration |
1290 N_Incomplete_Type_Declaration |
1291 N_Loop_Parameter_Specification |
1292 N_Number_Declaration |
1293 N_Object_Declaration |
1294 N_Object_Renaming_Declaration |
1295 N_Package_Body_Stub |
1296 N_Parameter_Specification |
1297 N_Private_Extension_Declaration |
1298 N_Private_Type_Declaration |
1300 N_Protected_Body_Stub |
1301 N_Protected_Type_Declaration |
1302 N_Single_Protected_Declaration |
1303 N_Single_Task_Declaration |
1304 N_Subtype_Declaration |
1307 N_Task_Type_Declaration
1309 return Defining_Identifier (N);
1312 return Defining_Entity (Proper_Body (N));
1315 N_Function_Instantiation |
1316 N_Function_Specification |
1317 N_Generic_Function_Renaming_Declaration |
1318 N_Generic_Package_Renaming_Declaration |
1319 N_Generic_Procedure_Renaming_Declaration |
1321 N_Package_Instantiation |
1322 N_Package_Renaming_Declaration |
1323 N_Package_Specification |
1324 N_Procedure_Instantiation |
1325 N_Procedure_Specification
1328 Nam : constant Node_Id := Defining_Unit_Name (N);
1331 if Nkind (Nam) in N_Entity then
1334 -- For Error, make up a name and attach to declaration
1335 -- so we can continue semantic analysis
1337 elsif Nam = Error then
1339 Make_Defining_Identifier (Sloc (N),
1340 Chars => New_Internal_Name ('T'));
1341 Set_Defining_Unit_Name (N, Err);
1344 -- If not an entity, get defining identifier
1347 return Defining_Identifier (Nam);
1351 when N_Block_Statement =>
1352 return Entity (Identifier (N));
1355 raise Program_Error;
1358 end Defining_Entity;
1360 --------------------------
1361 -- Denotes_Discriminant --
1362 --------------------------
1364 function Denotes_Discriminant
1366 Check_Protected : Boolean := False) return Boolean
1370 if not Is_Entity_Name (N)
1371 or else No (Entity (N))
1378 -- If we are checking for a protected type, the discriminant may have
1379 -- been rewritten as the corresponding discriminal of the original type
1380 -- or of the corresponding concurrent record, depending on whether we
1381 -- are in the spec or body of the protected type.
1383 return Ekind (E) = E_Discriminant
1386 and then Ekind (E) = E_In_Parameter
1387 and then Present (Discriminal_Link (E))
1389 (Is_Protected_Type (Scope (Discriminal_Link (E)))
1391 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1393 end Denotes_Discriminant;
1395 -----------------------------
1396 -- Depends_On_Discriminant --
1397 -----------------------------
1399 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1404 Get_Index_Bounds (N, L, H);
1405 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1406 end Depends_On_Discriminant;
1408 -------------------------
1409 -- Designate_Same_Unit --
1410 -------------------------
1412 function Designate_Same_Unit
1414 Name2 : Node_Id) return Boolean
1416 K1 : constant Node_Kind := Nkind (Name1);
1417 K2 : constant Node_Kind := Nkind (Name2);
1419 function Prefix_Node (N : Node_Id) return Node_Id;
1420 -- Returns the parent unit name node of a defining program unit name
1421 -- or the prefix if N is a selected component or an expanded name.
1423 function Select_Node (N : Node_Id) return Node_Id;
1424 -- Returns the defining identifier node of a defining program unit
1425 -- name or the selector node if N is a selected component or an
1432 function Prefix_Node (N : Node_Id) return Node_Id is
1434 if Nkind (N) = N_Defining_Program_Unit_Name then
1446 function Select_Node (N : Node_Id) return Node_Id is
1448 if Nkind (N) = N_Defining_Program_Unit_Name then
1449 return Defining_Identifier (N);
1452 return Selector_Name (N);
1456 -- Start of processing for Designate_Next_Unit
1459 if (K1 = N_Identifier or else
1460 K1 = N_Defining_Identifier)
1462 (K2 = N_Identifier or else
1463 K2 = N_Defining_Identifier)
1465 return Chars (Name1) = Chars (Name2);
1468 (K1 = N_Expanded_Name or else
1469 K1 = N_Selected_Component or else
1470 K1 = N_Defining_Program_Unit_Name)
1472 (K2 = N_Expanded_Name or else
1473 K2 = N_Selected_Component or else
1474 K2 = N_Defining_Program_Unit_Name)
1477 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
1479 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
1484 end Designate_Same_Unit;
1486 ----------------------------
1487 -- Enclosing_Generic_Body --
1488 ----------------------------
1490 function Enclosing_Generic_Body
1491 (E : Entity_Id) return Node_Id
1500 while Present (P) loop
1501 if Nkind (P) = N_Package_Body
1502 or else Nkind (P) = N_Subprogram_Body
1504 Spec := Corresponding_Spec (P);
1506 if Present (Spec) then
1507 Decl := Unit_Declaration_Node (Spec);
1509 if Nkind (Decl) = N_Generic_Package_Declaration
1510 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1521 end Enclosing_Generic_Body;
1523 -------------------------------
1524 -- Enclosing_Lib_Unit_Entity --
1525 -------------------------------
1527 function Enclosing_Lib_Unit_Entity return Entity_Id is
1528 Unit_Entity : Entity_Id := Current_Scope;
1531 -- Look for enclosing library unit entity by following scope links.
1532 -- Equivalent to, but faster than indexing through the scope stack.
1534 while (Present (Scope (Unit_Entity))
1535 and then Scope (Unit_Entity) /= Standard_Standard)
1536 and not Is_Child_Unit (Unit_Entity)
1538 Unit_Entity := Scope (Unit_Entity);
1542 end Enclosing_Lib_Unit_Entity;
1544 -----------------------------
1545 -- Enclosing_Lib_Unit_Node --
1546 -----------------------------
1548 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
1549 Current_Node : Node_Id := N;
1552 while Present (Current_Node)
1553 and then Nkind (Current_Node) /= N_Compilation_Unit
1555 Current_Node := Parent (Current_Node);
1558 if Nkind (Current_Node) /= N_Compilation_Unit then
1562 return Current_Node;
1563 end Enclosing_Lib_Unit_Node;
1565 --------------------------
1566 -- Enclosing_Subprogram --
1567 --------------------------
1569 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
1570 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
1573 if Dynamic_Scope = Standard_Standard then
1576 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
1577 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
1579 elsif Ekind (Dynamic_Scope) = E_Block then
1580 return Enclosing_Subprogram (Dynamic_Scope);
1582 elsif Ekind (Dynamic_Scope) = E_Task_Type then
1583 return Get_Task_Body_Procedure (Dynamic_Scope);
1585 elsif Convention (Dynamic_Scope) = Convention_Protected then
1586 return Protected_Body_Subprogram (Dynamic_Scope);
1589 return Dynamic_Scope;
1591 end Enclosing_Subprogram;
1593 ------------------------
1594 -- Ensure_Freeze_Node --
1595 ------------------------
1597 procedure Ensure_Freeze_Node (E : Entity_Id) is
1601 if No (Freeze_Node (E)) then
1602 FN := Make_Freeze_Entity (Sloc (E));
1603 Set_Has_Delayed_Freeze (E);
1604 Set_Freeze_Node (E, FN);
1605 Set_Access_Types_To_Process (FN, No_Elist);
1606 Set_TSS_Elist (FN, No_Elist);
1609 end Ensure_Freeze_Node;
1615 procedure Enter_Name (Def_Id : Node_Id) is
1616 C : constant Entity_Id := Current_Entity (Def_Id);
1617 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
1618 S : constant Entity_Id := Current_Scope;
1621 Generate_Definition (Def_Id);
1623 -- Add new name to current scope declarations. Check for duplicate
1624 -- declaration, which may or may not be a genuine error.
1628 -- Case of previous entity entered because of a missing declaration
1629 -- or else a bad subtype indication. Best is to use the new entity,
1630 -- and make the previous one invisible.
1632 if Etype (E) = Any_Type then
1633 Set_Is_Immediately_Visible (E, False);
1635 -- Case of renaming declaration constructed for package instances.
1636 -- if there is an explicit declaration with the same identifier,
1637 -- the renaming is not immediately visible any longer, but remains
1638 -- visible through selected component notation.
1640 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
1641 and then not Comes_From_Source (E)
1643 Set_Is_Immediately_Visible (E, False);
1645 -- The new entity may be the package renaming, which has the same
1646 -- same name as a generic formal which has been seen already.
1648 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
1649 and then not Comes_From_Source (Def_Id)
1651 Set_Is_Immediately_Visible (E, False);
1653 -- For a fat pointer corresponding to a remote access to subprogram,
1654 -- we use the same identifier as the RAS type, so that the proper
1655 -- name appears in the stub. This type is only retrieved through
1656 -- the RAS type and never by visibility, and is not added to the
1657 -- visibility list (see below).
1659 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
1660 and then Present (Corresponding_Remote_Type (Def_Id))
1664 -- A controller component for a type extension overrides the
1665 -- inherited component.
1667 elsif Chars (E) = Name_uController then
1670 -- Case of an implicit operation or derived literal. The new entity
1671 -- hides the implicit one, which is removed from all visibility,
1672 -- i.e. the entity list of its scope, and homonym chain of its name.
1674 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
1675 or else Is_Internal (E)
1679 Prev_Vis : Entity_Id;
1680 Decl : constant Node_Id := Parent (E);
1683 -- If E is an implicit declaration, it cannot be the first
1684 -- entity in the scope.
1686 Prev := First_Entity (Current_Scope);
1688 while Present (Prev)
1689 and then Next_Entity (Prev) /= E
1696 -- If E is not on the entity chain of the current scope,
1697 -- it is an implicit declaration in the generic formal
1698 -- part of a generic subprogram. When analyzing the body,
1699 -- the generic formals are visible but not on the entity
1700 -- chain of the subprogram. The new entity will become
1701 -- the visible one in the body.
1704 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
1708 Set_Next_Entity (Prev, Next_Entity (E));
1710 if No (Next_Entity (Prev)) then
1711 Set_Last_Entity (Current_Scope, Prev);
1714 if E = Current_Entity (E) then
1718 Prev_Vis := Current_Entity (E);
1719 while Homonym (Prev_Vis) /= E loop
1720 Prev_Vis := Homonym (Prev_Vis);
1724 if Present (Prev_Vis) then
1726 -- Skip E in the visibility chain
1728 Set_Homonym (Prev_Vis, Homonym (E));
1731 Set_Name_Entity_Id (Chars (E), Homonym (E));
1736 -- This section of code could use a comment ???
1738 elsif Present (Etype (E))
1739 and then Is_Concurrent_Type (Etype (E))
1744 -- In the body or private part of an instance, a type extension
1745 -- may introduce a component with the same name as that of an
1746 -- actual. The legality rule is not enforced, but the semantics
1747 -- of the full type with two components of the same name are not
1748 -- clear at this point ???
1750 elsif In_Instance_Not_Visible then
1753 -- When compiling a package body, some child units may have become
1754 -- visible. They cannot conflict with local entities that hide them.
1756 elsif Is_Child_Unit (E)
1757 and then In_Open_Scopes (Scope (E))
1758 and then not Is_Immediately_Visible (E)
1762 -- Conversely, with front-end inlining we may compile the parent
1763 -- body first, and a child unit subsequently. The context is now
1764 -- the parent spec, and body entities are not visible.
1766 elsif Is_Child_Unit (Def_Id)
1767 and then Is_Package_Body_Entity (E)
1768 and then not In_Package_Body (Current_Scope)
1772 -- Case of genuine duplicate declaration
1775 Error_Msg_Sloc := Sloc (E);
1777 -- If the previous declaration is an incomplete type declaration
1778 -- this may be an attempt to complete it with a private type.
1779 -- The following avoids confusing cascaded errors.
1781 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
1782 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
1785 ("incomplete type cannot be completed" &
1786 " with a private declaration",
1788 Set_Is_Immediately_Visible (E, False);
1789 Set_Full_View (E, Def_Id);
1791 elsif Ekind (E) = E_Discriminant
1792 and then Present (Scope (Def_Id))
1793 and then Scope (Def_Id) /= Current_Scope
1795 -- An inherited component of a record conflicts with
1796 -- a new discriminant. The discriminant is inserted first
1797 -- in the scope, but the error should be posted on it, not
1798 -- on the component.
1800 Error_Msg_Sloc := Sloc (Def_Id);
1801 Error_Msg_N ("& conflicts with declaration#", E);
1804 -- If the name of the unit appears in its own context clause,
1805 -- a dummy package with the name has already been created, and
1806 -- the error emitted. Try to continue quietly.
1808 elsif Error_Posted (E)
1809 and then Sloc (E) = No_Location
1810 and then Nkind (Parent (E)) = N_Package_Specification
1811 and then Current_Scope = Standard_Standard
1813 Set_Scope (Def_Id, Current_Scope);
1817 Error_Msg_N ("& conflicts with declaration#", Def_Id);
1819 -- Avoid cascaded messages with duplicate components in
1822 if Ekind (E) = E_Component
1823 or else Ekind (E) = E_Discriminant
1829 if Nkind (Parent (Parent (Def_Id)))
1830 = N_Generic_Subprogram_Declaration
1832 Defining_Entity (Specification (Parent (Parent (Def_Id))))
1834 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
1837 -- If entity is in standard, then we are in trouble, because
1838 -- it means that we have a library package with a duplicated
1839 -- name. That's hard to recover from, so abort!
1841 if S = Standard_Standard then
1842 raise Unrecoverable_Error;
1844 -- Otherwise we continue with the declaration. Having two
1845 -- identical declarations should not cause us too much trouble!
1853 -- If we fall through, declaration is OK , or OK enough to continue
1855 -- If Def_Id is a discriminant or a record component we are in the
1856 -- midst of inheriting components in a derived record definition.
1857 -- Preserve their Ekind and Etype.
1859 if Ekind (Def_Id) = E_Discriminant
1860 or else Ekind (Def_Id) = E_Component
1864 -- If a type is already set, leave it alone (happens whey a type
1865 -- declaration is reanalyzed following a call to the optimizer)
1867 elsif Present (Etype (Def_Id)) then
1870 -- Otherwise, the kind E_Void insures that premature uses of the entity
1871 -- will be detected. Any_Type insures that no cascaded errors will occur
1874 Set_Ekind (Def_Id, E_Void);
1875 Set_Etype (Def_Id, Any_Type);
1878 -- Inherited discriminants and components in derived record types are
1879 -- immediately visible. Itypes are not.
1881 if Ekind (Def_Id) = E_Discriminant
1882 or else Ekind (Def_Id) = E_Component
1883 or else (No (Corresponding_Remote_Type (Def_Id))
1884 and then not Is_Itype (Def_Id))
1886 Set_Is_Immediately_Visible (Def_Id);
1887 Set_Current_Entity (Def_Id);
1890 Set_Homonym (Def_Id, C);
1891 Append_Entity (Def_Id, S);
1892 Set_Public_Status (Def_Id);
1894 -- Warn if new entity hides an old one
1897 and then Present (C)
1898 and then Length_Of_Name (Chars (C)) /= 1
1899 and then Comes_From_Source (C)
1900 and then Comes_From_Source (Def_Id)
1901 and then In_Extended_Main_Source_Unit (Def_Id)
1903 Error_Msg_Sloc := Sloc (C);
1904 Error_Msg_N ("declaration hides &#?", Def_Id);
1908 --------------------------
1909 -- Explain_Limited_Type --
1910 --------------------------
1912 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
1916 -- For array, component type must be limited
1918 if Is_Array_Type (T) then
1919 Error_Msg_Node_2 := T;
1921 ("component type& of type& is limited", N, Component_Type (T));
1922 Explain_Limited_Type (Component_Type (T), N);
1924 elsif Is_Record_Type (T) then
1926 -- No need for extra messages if explicit limited record
1928 if Is_Limited_Record (Base_Type (T)) then
1932 -- Otherwise find a limited component. Check only components that
1933 -- come from source, or inherited components that appear in the
1934 -- source of the ancestor.
1936 C := First_Component (T);
1937 while Present (C) loop
1938 if Is_Limited_Type (Etype (C))
1940 (Comes_From_Source (C)
1942 (Present (Original_Record_Component (C))
1944 Comes_From_Source (Original_Record_Component (C))))
1946 Error_Msg_Node_2 := T;
1947 Error_Msg_NE ("\component& of type& has limited type", N, C);
1948 Explain_Limited_Type (Etype (C), N);
1955 -- The type may be declared explicitly limited, even if no component
1956 -- of it is limited, in which case we fall out of the loop.
1959 end Explain_Limited_Type;
1961 -------------------------------------
1962 -- Find_Corresponding_Discriminant --
1963 -------------------------------------
1965 function Find_Corresponding_Discriminant
1967 Typ : Entity_Id) return Entity_Id
1969 Par_Disc : Entity_Id;
1970 Old_Disc : Entity_Id;
1971 New_Disc : Entity_Id;
1974 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
1976 -- The original type may currently be private, and the discriminant
1977 -- only appear on its full view.
1979 if Is_Private_Type (Scope (Par_Disc))
1980 and then not Has_Discriminants (Scope (Par_Disc))
1981 and then Present (Full_View (Scope (Par_Disc)))
1983 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
1985 Old_Disc := First_Discriminant (Scope (Par_Disc));
1988 if Is_Class_Wide_Type (Typ) then
1989 New_Disc := First_Discriminant (Root_Type (Typ));
1991 New_Disc := First_Discriminant (Typ);
1994 while Present (Old_Disc) and then Present (New_Disc) loop
1995 if Old_Disc = Par_Disc then
1998 Next_Discriminant (Old_Disc);
1999 Next_Discriminant (New_Disc);
2003 -- Should always find it
2005 raise Program_Error;
2006 end Find_Corresponding_Discriminant;
2008 -----------------------------
2009 -- Find_Static_Alternative --
2010 -----------------------------
2012 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2013 Expr : constant Node_Id := Expression (N);
2014 Val : constant Uint := Expr_Value (Expr);
2019 Alt := First (Alternatives (N));
2022 if Nkind (Alt) /= N_Pragma then
2023 Choice := First (Discrete_Choices (Alt));
2025 while Present (Choice) loop
2027 -- Others choice, always matches
2029 if Nkind (Choice) = N_Others_Choice then
2032 -- Range, check if value is in the range
2034 elsif Nkind (Choice) = N_Range then
2036 Val >= Expr_Value (Low_Bound (Choice))
2038 Val <= Expr_Value (High_Bound (Choice));
2040 -- Choice is a subtype name. Note that we know it must
2041 -- be a static subtype, since otherwise it would have
2042 -- been diagnosed as illegal.
2044 elsif Is_Entity_Name (Choice)
2045 and then Is_Type (Entity (Choice))
2047 exit Search when Is_In_Range (Expr, Etype (Choice));
2049 -- Choice is a subtype indication
2051 elsif Nkind (Choice) = N_Subtype_Indication then
2053 C : constant Node_Id := Constraint (Choice);
2054 R : constant Node_Id := Range_Expression (C);
2058 Val >= Expr_Value (Low_Bound (R))
2060 Val <= Expr_Value (High_Bound (R));
2063 -- Choice is a simple expression
2066 exit Search when Val = Expr_Value (Choice);
2074 pragma Assert (Present (Alt));
2077 -- The above loop *must* terminate by finding a match, since
2078 -- we know the case statement is valid, and the value of the
2079 -- expression is known at compile time. When we fall out of
2080 -- the loop, Alt points to the alternative that we know will
2081 -- be selected at run time.
2084 end Find_Static_Alternative;
2090 function First_Actual (Node : Node_Id) return Node_Id is
2094 if No (Parameter_Associations (Node)) then
2098 N := First (Parameter_Associations (Node));
2100 if Nkind (N) = N_Parameter_Association then
2101 return First_Named_Actual (Node);
2107 -------------------------
2108 -- Full_Qualified_Name --
2109 -------------------------
2111 function Full_Qualified_Name (E : Entity_Id) return String_Id is
2113 pragma Warnings (Off, Res);
2115 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
2116 -- Compute recursively the qualified name without NUL at the end
2118 ----------------------------------
2119 -- Internal_Full_Qualified_Name --
2120 ----------------------------------
2122 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
2123 Ent : Entity_Id := E;
2124 Parent_Name : String_Id := No_String;
2127 -- Deals properly with child units
2129 if Nkind (Ent) = N_Defining_Program_Unit_Name then
2130 Ent := Defining_Identifier (Ent);
2133 -- Compute recursively the qualification. Only "Standard" has no
2136 if Present (Scope (Scope (Ent))) then
2137 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
2140 -- Every entity should have a name except some expanded blocks
2141 -- don't bother about those.
2143 if Chars (Ent) = No_Name then
2147 -- Add a period between Name and qualification
2149 if Parent_Name /= No_String then
2150 Start_String (Parent_Name);
2151 Store_String_Char (Get_Char_Code ('.'));
2157 -- Generates the entity name in upper case
2159 Get_Name_String (Chars (Ent));
2161 Store_String_Chars (Name_Buffer (1 .. Name_Len));
2163 end Internal_Full_Qualified_Name;
2165 -- Start of processing for Full_Qualified_Name
2168 Res := Internal_Full_Qualified_Name (E);
2169 Store_String_Char (Get_Char_Code (ASCII.nul));
2171 end Full_Qualified_Name;
2173 -----------------------
2174 -- Gather_Components --
2175 -----------------------
2177 procedure Gather_Components
2179 Comp_List : Node_Id;
2180 Governed_By : List_Id;
2182 Report_Errors : out Boolean)
2186 Discrete_Choice : Node_Id;
2187 Comp_Item : Node_Id;
2189 Discrim : Entity_Id;
2190 Discrim_Name : Node_Id;
2191 Discrim_Value : Node_Id;
2194 Report_Errors := False;
2196 if No (Comp_List) or else Null_Present (Comp_List) then
2199 elsif Present (Component_Items (Comp_List)) then
2200 Comp_Item := First (Component_Items (Comp_List));
2206 while Present (Comp_Item) loop
2208 -- Skip the tag of a tagged record, as well as all items
2209 -- that are not user components (anonymous types, rep clauses,
2210 -- Parent field, controller field).
2212 if Nkind (Comp_Item) = N_Component_Declaration
2213 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uTag
2214 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uParent
2215 and then Chars (Defining_Identifier (Comp_Item)) /= Name_uController
2217 Append_Elmt (Defining_Identifier (Comp_Item), Into);
2223 if No (Variant_Part (Comp_List)) then
2226 Discrim_Name := Name (Variant_Part (Comp_List));
2227 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
2230 -- Look for the discriminant that governs this variant part.
2231 -- The discriminant *must* be in the Governed_By List
2233 Assoc := First (Governed_By);
2234 Find_Constraint : loop
2235 Discrim := First (Choices (Assoc));
2236 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
2237 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
2239 Chars (Corresponding_Discriminant (Entity (Discrim)))
2240 = Chars (Discrim_Name))
2241 or else Chars (Original_Record_Component (Entity (Discrim)))
2242 = Chars (Discrim_Name);
2244 if No (Next (Assoc)) then
2245 if not Is_Constrained (Typ)
2246 and then Is_Derived_Type (Typ)
2247 and then Present (Stored_Constraint (Typ))
2250 -- If the type is a tagged type with inherited discriminants,
2251 -- use the stored constraint on the parent in order to find
2252 -- the values of discriminants that are otherwise hidden by an
2253 -- explicit constraint. Renamed discriminants are handled in
2256 -- If several parent discriminants are renamed by a single
2257 -- discriminant of the derived type, the call to obtain the
2258 -- Corresponding_Discriminant field only retrieves the last
2259 -- of them. We recover the constraint on the others from the
2260 -- Stored_Constraint as well.
2267 D := First_Discriminant (Etype (Typ));
2268 C := First_Elmt (Stored_Constraint (Typ));
2271 and then Present (C)
2273 if Chars (Discrim_Name) = Chars (D) then
2274 if Is_Entity_Name (Node (C))
2275 and then Entity (Node (C)) = Entity (Discrim)
2277 -- D is renamed by Discrim, whose value is
2284 Make_Component_Association (Sloc (Typ),
2286 (New_Occurrence_Of (D, Sloc (Typ))),
2287 Duplicate_Subexpr_No_Checks (Node (C)));
2289 exit Find_Constraint;
2292 D := Next_Discriminant (D);
2299 if No (Next (Assoc)) then
2300 Error_Msg_NE (" missing value for discriminant&",
2301 First (Governed_By), Discrim_Name);
2302 Report_Errors := True;
2307 end loop Find_Constraint;
2309 Discrim_Value := Expression (Assoc);
2311 if not Is_OK_Static_Expression (Discrim_Value) then
2313 ("value for discriminant & must be static!",
2314 Discrim_Value, Discrim);
2315 Why_Not_Static (Discrim_Value);
2316 Report_Errors := True;
2320 Search_For_Discriminant_Value : declare
2326 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
2329 Find_Discrete_Value : while Present (Variant) loop
2330 Discrete_Choice := First (Discrete_Choices (Variant));
2331 while Present (Discrete_Choice) loop
2333 exit Find_Discrete_Value when
2334 Nkind (Discrete_Choice) = N_Others_Choice;
2336 Get_Index_Bounds (Discrete_Choice, Low, High);
2338 UI_Low := Expr_Value (Low);
2339 UI_High := Expr_Value (High);
2341 exit Find_Discrete_Value when
2342 UI_Low <= UI_Discrim_Value
2344 UI_High >= UI_Discrim_Value;
2346 Next (Discrete_Choice);
2349 Next_Non_Pragma (Variant);
2350 end loop Find_Discrete_Value;
2351 end Search_For_Discriminant_Value;
2353 if No (Variant) then
2355 ("value of discriminant & is out of range", Discrim_Value, Discrim);
2356 Report_Errors := True;
2360 -- If we have found the corresponding choice, recursively add its
2361 -- components to the Into list.
2363 Gather_Components (Empty,
2364 Component_List (Variant), Governed_By, Into, Report_Errors);
2365 end Gather_Components;
2367 ------------------------
2368 -- Get_Actual_Subtype --
2369 ------------------------
2371 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
2372 Typ : constant Entity_Id := Etype (N);
2373 Utyp : Entity_Id := Underlying_Type (Typ);
2378 if not Present (Utyp) then
2382 -- If what we have is an identifier that references a subprogram
2383 -- formal, or a variable or constant object, then we get the actual
2384 -- subtype from the referenced entity if one has been built.
2386 if Nkind (N) = N_Identifier
2388 (Is_Formal (Entity (N))
2389 or else Ekind (Entity (N)) = E_Constant
2390 or else Ekind (Entity (N)) = E_Variable)
2391 and then Present (Actual_Subtype (Entity (N)))
2393 return Actual_Subtype (Entity (N));
2395 -- Actual subtype of unchecked union is always itself. We never need
2396 -- the "real" actual subtype. If we did, we couldn't get it anyway
2397 -- because the discriminant is not available. The restrictions on
2398 -- Unchecked_Union are designed to make sure that this is OK.
2400 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
2403 -- Here for the unconstrained case, we must find actual subtype
2404 -- No actual subtype is available, so we must build it on the fly.
2406 -- Checking the type, not the underlying type, for constrainedness
2407 -- seems to be necessary. Maybe all the tests should be on the type???
2409 elsif (not Is_Constrained (Typ))
2410 and then (Is_Array_Type (Utyp)
2411 or else (Is_Record_Type (Utyp)
2412 and then Has_Discriminants (Utyp)))
2413 and then not Has_Unknown_Discriminants (Utyp)
2414 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
2416 -- Nothing to do if in default expression
2418 if In_Default_Expression then
2421 elsif Is_Private_Type (Typ)
2422 and then not Has_Discriminants (Typ)
2424 -- If the type has no discriminants, there is no subtype to
2425 -- build, even if the underlying type is discriminated.
2429 -- Else build the actual subtype
2432 Decl := Build_Actual_Subtype (Typ, N);
2433 Atyp := Defining_Identifier (Decl);
2435 -- If Build_Actual_Subtype generated a new declaration then use it
2439 -- The actual subtype is an Itype, so analyze the declaration,
2440 -- but do not attach it to the tree, to get the type defined.
2442 Set_Parent (Decl, N);
2443 Set_Is_Itype (Atyp);
2444 Analyze (Decl, Suppress => All_Checks);
2445 Set_Associated_Node_For_Itype (Atyp, N);
2446 Set_Has_Delayed_Freeze (Atyp, False);
2448 -- We need to freeze the actual subtype immediately. This is
2449 -- needed, because otherwise this Itype will not get frozen
2450 -- at all, and it is always safe to freeze on creation because
2451 -- any associated types must be frozen at this point.
2453 Freeze_Itype (Atyp, N);
2456 -- Otherwise we did not build a declaration, so return original
2463 -- For all remaining cases, the actual subtype is the same as
2464 -- the nominal type.
2469 end Get_Actual_Subtype;
2471 -------------------------------------
2472 -- Get_Actual_Subtype_If_Available --
2473 -------------------------------------
2475 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
2476 Typ : constant Entity_Id := Etype (N);
2479 -- If what we have is an identifier that references a subprogram
2480 -- formal, or a variable or constant object, then we get the actual
2481 -- subtype from the referenced entity if one has been built.
2483 if Nkind (N) = N_Identifier
2485 (Is_Formal (Entity (N))
2486 or else Ekind (Entity (N)) = E_Constant
2487 or else Ekind (Entity (N)) = E_Variable)
2488 and then Present (Actual_Subtype (Entity (N)))
2490 return Actual_Subtype (Entity (N));
2492 -- Otherwise the Etype of N is returned unchanged
2497 end Get_Actual_Subtype_If_Available;
2499 -------------------------------
2500 -- Get_Default_External_Name --
2501 -------------------------------
2503 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
2505 Get_Decoded_Name_String (Chars (E));
2507 if Opt.External_Name_Imp_Casing = Uppercase then
2508 Set_Casing (All_Upper_Case);
2510 Set_Casing (All_Lower_Case);
2514 Make_String_Literal (Sloc (E),
2515 Strval => String_From_Name_Buffer);
2516 end Get_Default_External_Name;
2518 ---------------------------
2519 -- Get_Enum_Lit_From_Pos --
2520 ---------------------------
2522 function Get_Enum_Lit_From_Pos
2525 Loc : Source_Ptr) return Node_Id
2528 P : constant Nat := UI_To_Int (Pos);
2531 -- In the case where the literal is either of type Wide_Character
2532 -- or Character or of a type derived from them, there needs to be
2533 -- some special handling since there is no explicit chain of
2534 -- literals to search. Instead, an N_Character_Literal node is
2535 -- created with the appropriate Char_Code and Chars fields.
2537 if Root_Type (T) = Standard_Character
2538 or else Root_Type (T) = Standard_Wide_Character
2540 Set_Character_Literal_Name (Char_Code (P));
2542 Make_Character_Literal (Loc,
2544 Char_Literal_Value => Char_Code (P));
2546 -- For all other cases, we have a complete table of literals, and
2547 -- we simply iterate through the chain of literal until the one
2548 -- with the desired position value is found.
2552 Lit := First_Literal (Base_Type (T));
2553 for J in 1 .. P loop
2557 return New_Occurrence_Of (Lit, Loc);
2559 end Get_Enum_Lit_From_Pos;
2561 ------------------------
2562 -- Get_Generic_Entity --
2563 ------------------------
2565 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
2566 Ent : constant Entity_Id := Entity (Name (N));
2569 if Present (Renamed_Object (Ent)) then
2570 return Renamed_Object (Ent);
2574 end Get_Generic_Entity;
2576 ----------------------
2577 -- Get_Index_Bounds --
2578 ----------------------
2580 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
2581 Kind : constant Node_Kind := Nkind (N);
2585 if Kind = N_Range then
2587 H := High_Bound (N);
2589 elsif Kind = N_Subtype_Indication then
2590 R := Range_Expression (Constraint (N));
2598 L := Low_Bound (Range_Expression (Constraint (N)));
2599 H := High_Bound (Range_Expression (Constraint (N)));
2602 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
2603 if Error_Posted (Scalar_Range (Entity (N))) then
2607 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
2608 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
2611 L := Low_Bound (Scalar_Range (Entity (N)));
2612 H := High_Bound (Scalar_Range (Entity (N)));
2616 -- N is an expression, indicating a range with one value
2621 end Get_Index_Bounds;
2623 ------------------------
2624 -- Get_Name_Entity_Id --
2625 ------------------------
2627 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
2629 return Entity_Id (Get_Name_Table_Info (Id));
2630 end Get_Name_Entity_Id;
2632 ---------------------------
2633 -- Get_Referenced_Object --
2634 ---------------------------
2636 function Get_Referenced_Object (N : Node_Id) return Node_Id is
2640 while Is_Entity_Name (R)
2641 and then Present (Renamed_Object (Entity (R)))
2643 R := Renamed_Object (Entity (R));
2647 end Get_Referenced_Object;
2649 -------------------------
2650 -- Get_Subprogram_Body --
2651 -------------------------
2653 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
2657 Decl := Unit_Declaration_Node (E);
2659 if Nkind (Decl) = N_Subprogram_Body then
2662 -- The below comment is bad, because it is possible for
2663 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
2665 else -- Nkind (Decl) = N_Subprogram_Declaration
2667 if Present (Corresponding_Body (Decl)) then
2668 return Unit_Declaration_Node (Corresponding_Body (Decl));
2670 -- Imported subprogram case
2676 end Get_Subprogram_Body;
2678 -----------------------------
2679 -- Get_Task_Body_Procedure --
2680 -----------------------------
2682 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
2684 return Task_Body_Procedure (Declaration_Node (Root_Type (E)));
2685 end Get_Task_Body_Procedure;
2687 -----------------------
2688 -- Has_Access_Values --
2689 -----------------------
2691 function Has_Access_Values (T : Entity_Id) return Boolean is
2692 Typ : constant Entity_Id := Underlying_Type (T);
2695 -- Case of a private type which is not completed yet. This can only
2696 -- happen in the case of a generic format type appearing directly, or
2697 -- as a component of the type to which this function is being applied
2698 -- at the top level. Return False in this case, since we certainly do
2699 -- not know that the type contains access types.
2704 elsif Is_Access_Type (Typ) then
2707 elsif Is_Array_Type (Typ) then
2708 return Has_Access_Values (Component_Type (Typ));
2710 elsif Is_Record_Type (Typ) then
2715 Comp := First_Entity (Typ);
2716 while Present (Comp) loop
2717 if (Ekind (Comp) = E_Component
2719 Ekind (Comp) = E_Discriminant)
2720 and then Has_Access_Values (Etype (Comp))
2734 end Has_Access_Values;
2736 ----------------------
2737 -- Has_Declarations --
2738 ----------------------
2740 function Has_Declarations (N : Node_Id) return Boolean is
2741 K : constant Node_Kind := Nkind (N);
2743 return K = N_Accept_Statement
2744 or else K = N_Block_Statement
2745 or else K = N_Compilation_Unit_Aux
2746 or else K = N_Entry_Body
2747 or else K = N_Package_Body
2748 or else K = N_Protected_Body
2749 or else K = N_Subprogram_Body
2750 or else K = N_Task_Body
2751 or else K = N_Package_Specification;
2752 end Has_Declarations;
2754 --------------------
2755 -- Has_Infinities --
2756 --------------------
2758 function Has_Infinities (E : Entity_Id) return Boolean is
2761 Is_Floating_Point_Type (E)
2762 and then Nkind (Scalar_Range (E)) = N_Range
2763 and then Includes_Infinities (Scalar_Range (E));
2766 ------------------------
2767 -- Has_Null_Extension --
2768 ------------------------
2770 function Has_Null_Extension (T : Entity_Id) return Boolean is
2771 B : constant Entity_Id := Base_Type (T);
2776 if Nkind (Parent (B)) = N_Full_Type_Declaration
2777 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
2779 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
2781 if Present (Ext) then
2782 if Null_Present (Ext) then
2785 Comps := Component_List (Ext);
2787 -- The null component list is rewritten during analysis to
2788 -- include the parent component. Any other component indicates
2789 -- that the extension was not originally null.
2791 return Null_Present (Comps)
2792 or else No (Next (First (Component_Items (Comps))));
2801 end Has_Null_Extension;
2803 ---------------------------
2804 -- Has_Private_Component --
2805 ---------------------------
2807 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
2808 Btype : Entity_Id := Base_Type (Type_Id);
2809 Component : Entity_Id;
2812 if Error_Posted (Type_Id)
2813 or else Error_Posted (Btype)
2818 if Is_Class_Wide_Type (Btype) then
2819 Btype := Root_Type (Btype);
2822 if Is_Private_Type (Btype) then
2824 UT : constant Entity_Id := Underlying_Type (Btype);
2828 if No (Full_View (Btype)) then
2829 return not Is_Generic_Type (Btype)
2830 and then not Is_Generic_Type (Root_Type (Btype));
2833 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
2837 return not Is_Frozen (UT) and then Has_Private_Component (UT);
2840 elsif Is_Array_Type (Btype) then
2841 return Has_Private_Component (Component_Type (Btype));
2843 elsif Is_Record_Type (Btype) then
2845 Component := First_Component (Btype);
2846 while Present (Component) loop
2848 if Has_Private_Component (Etype (Component)) then
2852 Next_Component (Component);
2857 elsif Is_Protected_Type (Btype)
2858 and then Present (Corresponding_Record_Type (Btype))
2860 return Has_Private_Component (Corresponding_Record_Type (Btype));
2865 end Has_Private_Component;
2867 --------------------------
2868 -- Has_Tagged_Component --
2869 --------------------------
2871 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
2875 if Is_Private_Type (Typ)
2876 and then Present (Underlying_Type (Typ))
2878 return Has_Tagged_Component (Underlying_Type (Typ));
2880 elsif Is_Array_Type (Typ) then
2881 return Has_Tagged_Component (Component_Type (Typ));
2883 elsif Is_Tagged_Type (Typ) then
2886 elsif Is_Record_Type (Typ) then
2887 Comp := First_Component (Typ);
2889 while Present (Comp) loop
2890 if Has_Tagged_Component (Etype (Comp)) then
2894 Comp := Next_Component (Typ);
2902 end Has_Tagged_Component;
2908 function In_Instance return Boolean is
2909 S : Entity_Id := Current_Scope;
2913 and then S /= Standard_Standard
2915 if (Ekind (S) = E_Function
2916 or else Ekind (S) = E_Package
2917 or else Ekind (S) = E_Procedure)
2918 and then Is_Generic_Instance (S)
2929 ----------------------
2930 -- In_Instance_Body --
2931 ----------------------
2933 function In_Instance_Body return Boolean is
2934 S : Entity_Id := Current_Scope;
2938 and then S /= Standard_Standard
2940 if (Ekind (S) = E_Function
2941 or else Ekind (S) = E_Procedure)
2942 and then Is_Generic_Instance (S)
2946 elsif Ekind (S) = E_Package
2947 and then In_Package_Body (S)
2948 and then Is_Generic_Instance (S)
2957 end In_Instance_Body;
2959 -----------------------------
2960 -- In_Instance_Not_Visible --
2961 -----------------------------
2963 function In_Instance_Not_Visible return Boolean is
2964 S : Entity_Id := Current_Scope;
2968 and then S /= Standard_Standard
2970 if (Ekind (S) = E_Function
2971 or else Ekind (S) = E_Procedure)
2972 and then Is_Generic_Instance (S)
2976 elsif Ekind (S) = E_Package
2977 and then (In_Package_Body (S) or else In_Private_Part (S))
2978 and then Is_Generic_Instance (S)
2987 end In_Instance_Not_Visible;
2989 ------------------------------
2990 -- In_Instance_Visible_Part --
2991 ------------------------------
2993 function In_Instance_Visible_Part return Boolean is
2994 S : Entity_Id := Current_Scope;
2998 and then S /= Standard_Standard
3000 if Ekind (S) = E_Package
3001 and then Is_Generic_Instance (S)
3002 and then not In_Package_Body (S)
3003 and then not In_Private_Part (S)
3012 end In_Instance_Visible_Part;
3014 ----------------------
3015 -- In_Packiage_Body --
3016 ----------------------
3018 function In_Package_Body return Boolean is
3019 S : Entity_Id := Current_Scope;
3023 and then S /= Standard_Standard
3025 if Ekind (S) = E_Package
3026 and then In_Package_Body (S)
3035 end In_Package_Body;
3037 --------------------------------------
3038 -- In_Subprogram_Or_Concurrent_Unit --
3039 --------------------------------------
3041 function In_Subprogram_Or_Concurrent_Unit return Boolean is
3046 -- Use scope chain to check successively outer scopes
3052 if K in Subprogram_Kind
3053 or else K in Concurrent_Kind
3054 or else K in Generic_Subprogram_Kind
3058 elsif E = Standard_Standard then
3064 end In_Subprogram_Or_Concurrent_Unit;
3066 ---------------------
3067 -- In_Visible_Part --
3068 ---------------------
3070 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
3073 Is_Package (Scope_Id)
3074 and then In_Open_Scopes (Scope_Id)
3075 and then not In_Package_Body (Scope_Id)
3076 and then not In_Private_Part (Scope_Id);
3077 end In_Visible_Part;
3079 ---------------------------------
3080 -- Insert_Explicit_Dereference --
3081 ---------------------------------
3083 procedure Insert_Explicit_Dereference (N : Node_Id) is
3084 New_Prefix : constant Node_Id := Relocate_Node (N);
3090 Save_Interps (N, New_Prefix);
3092 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
3094 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
3096 if Is_Overloaded (New_Prefix) then
3098 -- The deference is also overloaded, and its interpretations are the
3099 -- designated types of the interpretations of the original node.
3101 Set_Etype (N, Any_Type);
3102 Get_First_Interp (New_Prefix, I, It);
3104 while Present (It.Nam) loop
3107 if Is_Access_Type (T) then
3108 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
3111 Get_Next_Interp (I, It);
3116 end Insert_Explicit_Dereference;
3122 function Is_AAMP_Float (E : Entity_Id) return Boolean is
3124 pragma Assert (Is_Type (E));
3126 return AAMP_On_Target
3127 and then Is_Floating_Point_Type (E)
3128 and then E = Base_Type (E);
3131 -------------------------
3132 -- Is_Actual_Parameter --
3133 -------------------------
3135 function Is_Actual_Parameter (N : Node_Id) return Boolean is
3136 PK : constant Node_Kind := Nkind (Parent (N));
3140 when N_Parameter_Association =>
3141 return N = Explicit_Actual_Parameter (Parent (N));
3143 when N_Function_Call | N_Procedure_Call_Statement =>
3144 return Is_List_Member (N)
3146 List_Containing (N) = Parameter_Associations (Parent (N));
3151 end Is_Actual_Parameter;
3153 ---------------------
3154 -- Is_Aliased_View --
3155 ---------------------
3157 function Is_Aliased_View (Obj : Node_Id) return Boolean is
3161 if Is_Entity_Name (Obj) then
3169 or else (Present (Renamed_Object (E))
3170 and then Is_Aliased_View (Renamed_Object (E)))))
3172 or else ((Is_Formal (E)
3173 or else Ekind (E) = E_Generic_In_Out_Parameter
3174 or else Ekind (E) = E_Generic_In_Parameter)
3175 and then Is_Tagged_Type (Etype (E)))
3177 or else ((Ekind (E) = E_Task_Type
3178 or else Ekind (E) = E_Protected_Type)
3179 and then In_Open_Scopes (E))
3181 -- Current instance of type
3183 or else (Is_Type (E) and then E = Current_Scope)
3184 or else (Is_Incomplete_Or_Private_Type (E)
3185 and then Full_View (E) = Current_Scope);
3187 elsif Nkind (Obj) = N_Selected_Component then
3188 return Is_Aliased (Entity (Selector_Name (Obj)));
3190 elsif Nkind (Obj) = N_Indexed_Component then
3191 return Has_Aliased_Components (Etype (Prefix (Obj)))
3193 (Is_Access_Type (Etype (Prefix (Obj)))
3195 Has_Aliased_Components
3196 (Designated_Type (Etype (Prefix (Obj)))));
3198 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
3199 or else Nkind (Obj) = N_Type_Conversion
3201 return Is_Tagged_Type (Etype (Obj))
3202 and then Is_Aliased_View (Expression (Obj));
3204 elsif Nkind (Obj) = N_Explicit_Dereference then
3205 return Nkind (Original_Node (Obj)) /= N_Function_Call;
3210 end Is_Aliased_View;
3212 -------------------------
3213 -- Is_Ancestor_Package --
3214 -------------------------
3216 function Is_Ancestor_Package
3218 E2 : Entity_Id) return Boolean
3225 and then Par /= Standard_Standard
3235 end Is_Ancestor_Package;
3237 ----------------------
3238 -- Is_Atomic_Object --
3239 ----------------------
3241 function Is_Atomic_Object (N : Node_Id) return Boolean is
3243 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
3244 -- Determines if given object has atomic components
3246 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
3247 -- If prefix is an implicit dereference, examine designated type
3249 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
3251 if Is_Access_Type (Etype (N)) then
3253 Has_Atomic_Components (Designated_Type (Etype (N)));
3255 return Object_Has_Atomic_Components (N);
3257 end Is_Atomic_Prefix;
3259 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
3261 if Has_Atomic_Components (Etype (N))
3262 or else Is_Atomic (Etype (N))
3266 elsif Is_Entity_Name (N)
3267 and then (Has_Atomic_Components (Entity (N))
3268 or else Is_Atomic (Entity (N)))
3272 elsif Nkind (N) = N_Indexed_Component
3273 or else Nkind (N) = N_Selected_Component
3275 return Is_Atomic_Prefix (Prefix (N));
3280 end Object_Has_Atomic_Components;
3282 -- Start of processing for Is_Atomic_Object
3285 if Is_Atomic (Etype (N))
3286 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
3290 elsif Nkind (N) = N_Indexed_Component
3291 or else Nkind (N) = N_Selected_Component
3293 return Is_Atomic_Prefix (Prefix (N));
3298 end Is_Atomic_Object;
3300 ----------------------------------------------
3301 -- Is_Dependent_Component_Of_Mutable_Object --
3302 ----------------------------------------------
3304 function Is_Dependent_Component_Of_Mutable_Object
3305 (Object : Node_Id) return Boolean
3308 Prefix_Type : Entity_Id;
3309 P_Aliased : Boolean := False;
3312 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean;
3313 -- Returns True if and only if Comp has a constrained subtype
3314 -- that depends on a discriminant.
3316 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
3317 -- Returns True if and only if Comp is declared within a variant part
3319 ------------------------------
3320 -- Has_Dependent_Constraint --
3321 ------------------------------
3323 function Has_Dependent_Constraint (Comp : Entity_Id) return Boolean is
3324 Comp_Decl : constant Node_Id := Parent (Comp);
3325 Subt_Indic : constant Node_Id :=
3326 Subtype_Indication (Component_Definition (Comp_Decl));
3331 if Nkind (Subt_Indic) = N_Subtype_Indication then
3332 Constr := Constraint (Subt_Indic);
3334 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
3335 Assn := First (Constraints (Constr));
3336 while Present (Assn) loop
3337 case Nkind (Assn) is
3338 when N_Subtype_Indication |
3342 if Depends_On_Discriminant (Assn) then
3346 when N_Discriminant_Association =>
3347 if Depends_On_Discriminant (Expression (Assn)) then
3362 end Has_Dependent_Constraint;
3364 --------------------------------
3365 -- Is_Declared_Within_Variant --
3366 --------------------------------
3368 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
3369 Comp_Decl : constant Node_Id := Parent (Comp);
3370 Comp_List : constant Node_Id := Parent (Comp_Decl);
3373 return Nkind (Parent (Comp_List)) = N_Variant;
3374 end Is_Declared_Within_Variant;
3376 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
3379 if Is_Variable (Object) then
3381 if Nkind (Object) = N_Selected_Component then
3382 P := Prefix (Object);
3383 Prefix_Type := Etype (P);
3385 if Is_Entity_Name (P) then
3387 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
3388 Prefix_Type := Base_Type (Prefix_Type);
3391 if Is_Aliased (Entity (P)) then
3395 -- A discriminant check on a selected component may be
3396 -- expanded into a dereference when removing side-effects.
3397 -- Recover the original node and its type, which may be
3400 elsif Nkind (P) = N_Explicit_Dereference
3401 and then not (Comes_From_Source (P))
3403 P := Original_Node (P);
3404 Prefix_Type := Etype (P);
3407 -- Check for prefix being an aliased component ???
3412 if Is_Access_Type (Prefix_Type)
3413 or else Nkind (P) = N_Explicit_Dereference
3419 Original_Record_Component (Entity (Selector_Name (Object)));
3421 -- As per AI-0017, the renaming is illegal in a generic body,
3422 -- even if the subtype is indefinite.
3424 if not Is_Constrained (Prefix_Type)
3425 and then (not Is_Indefinite_Subtype (Prefix_Type)
3427 (Is_Generic_Type (Prefix_Type)
3428 and then Ekind (Current_Scope) = E_Generic_Package
3429 and then In_Package_Body (Current_Scope)))
3431 and then (Is_Declared_Within_Variant (Comp)
3432 or else Has_Dependent_Constraint (Comp))
3433 and then not P_Aliased
3439 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3443 elsif Nkind (Object) = N_Indexed_Component
3444 or else Nkind (Object) = N_Slice
3446 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
3448 -- A type conversion that Is_Variable is a view conversion:
3449 -- go back to the denoted object.
3451 elsif Nkind (Object) = N_Type_Conversion then
3453 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
3458 end Is_Dependent_Component_Of_Mutable_Object;
3460 ---------------------
3461 -- Is_Dereferenced --
3462 ---------------------
3464 function Is_Dereferenced (N : Node_Id) return Boolean is
3465 P : constant Node_Id := Parent (N);
3469 (Nkind (P) = N_Selected_Component
3471 Nkind (P) = N_Explicit_Dereference
3473 Nkind (P) = N_Indexed_Component
3475 Nkind (P) = N_Slice)
3476 and then Prefix (P) = N;
3477 end Is_Dereferenced;
3479 ----------------------
3480 -- Is_Descendent_Of --
3481 ----------------------
3483 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
3488 pragma Assert (Nkind (T1) in N_Entity);
3489 pragma Assert (Nkind (T2) in N_Entity);
3491 T := Base_Type (T1);
3493 -- Immediate return if the types match
3498 -- Comment needed here ???
3500 elsif Ekind (T) = E_Class_Wide_Type then
3501 return Etype (T) = T2;
3509 -- Done if we found the type we are looking for
3514 -- Done if no more derivations to check
3521 -- Following test catches error cases resulting from prev errors
3523 elsif No (Etyp) then
3526 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
3529 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
3533 T := Base_Type (Etyp);
3537 raise Program_Error;
3538 end Is_Descendent_Of;
3540 ------------------------------
3541 -- Is_Descendent_Of_Address --
3542 ------------------------------
3544 function Is_Descendent_Of_Address (T1 : Entity_Id) return Boolean is
3546 -- If Address has not been loaded, answer must be False
3548 if not RTU_Loaded (System) then
3551 -- Otherwise we can get the entity we are interested in without
3552 -- causing an unwanted dependency on System, and do the test.
3555 return Is_Descendent_Of (T1, Base_Type (RTE (RE_Address)));
3557 end Is_Descendent_Of_Address;
3563 function Is_False (U : Uint) return Boolean is
3568 ---------------------------
3569 -- Is_Fixed_Model_Number --
3570 ---------------------------
3572 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
3573 S : constant Ureal := Small_Value (T);
3574 M : Urealp.Save_Mark;
3579 R := (U = UR_Trunc (U / S) * S);
3582 end Is_Fixed_Model_Number;
3584 -------------------------------
3585 -- Is_Fully_Initialized_Type --
3586 -------------------------------
3588 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
3590 if Is_Scalar_Type (Typ) then
3593 elsif Is_Access_Type (Typ) then
3596 elsif Is_Array_Type (Typ) then
3597 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
3601 -- An interesting case, if we have a constrained type one of whose
3602 -- bounds is known to be null, then there are no elements to be
3603 -- initialized, so all the elements are initialized!
3605 if Is_Constrained (Typ) then
3608 Indx_Typ : Entity_Id;
3612 Indx := First_Index (Typ);
3613 while Present (Indx) loop
3615 if Etype (Indx) = Any_Type then
3618 -- If index is a range, use directly
3620 elsif Nkind (Indx) = N_Range then
3621 Lbd := Low_Bound (Indx);
3622 Hbd := High_Bound (Indx);
3625 Indx_Typ := Etype (Indx);
3627 if Is_Private_Type (Indx_Typ) then
3628 Indx_Typ := Full_View (Indx_Typ);
3631 if No (Indx_Typ) then
3634 Lbd := Type_Low_Bound (Indx_Typ);
3635 Hbd := Type_High_Bound (Indx_Typ);
3639 if Compile_Time_Known_Value (Lbd)
3640 and then Compile_Time_Known_Value (Hbd)
3642 if Expr_Value (Hbd) < Expr_Value (Lbd) then
3652 -- If no null indexes, then type is not fully initialized
3658 elsif Is_Record_Type (Typ) then
3659 if Has_Discriminants (Typ)
3661 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
3662 and then Is_Fully_Initialized_Variant (Typ)
3667 -- Controlled records are considered to be fully initialized if
3668 -- there is a user defined Initialize routine. This may not be
3669 -- entirely correct, but as the spec notes, we are guessing here
3670 -- what is best from the point of view of issuing warnings.
3672 if Is_Controlled (Typ) then
3674 Utyp : constant Entity_Id := Underlying_Type (Typ);
3677 if Present (Utyp) then
3679 Init : constant Entity_Id :=
3681 (Underlying_Type (Typ), Name_Initialize));
3685 and then Comes_From_Source (Init)
3687 Is_Predefined_File_Name
3688 (File_Name (Get_Source_File_Index (Sloc (Init))))
3692 elsif Has_Null_Extension (Typ)
3694 Is_Fully_Initialized_Type
3695 (Etype (Base_Type (Typ)))
3704 -- Otherwise see if all record components are initialized
3710 Ent := First_Entity (Typ);
3712 while Present (Ent) loop
3713 if Chars (Ent) = Name_uController then
3716 elsif Ekind (Ent) = E_Component
3717 and then (No (Parent (Ent))
3718 or else No (Expression (Parent (Ent))))
3719 and then not Is_Fully_Initialized_Type (Etype (Ent))
3728 -- No uninitialized components, so type is fully initialized.
3729 -- Note that this catches the case of no components as well.
3733 elsif Is_Concurrent_Type (Typ) then
3736 elsif Is_Private_Type (Typ) then
3738 U : constant Entity_Id := Underlying_Type (Typ);
3744 return Is_Fully_Initialized_Type (U);
3751 end Is_Fully_Initialized_Type;
3753 ----------------------------------
3754 -- Is_Fully_Initialized_Variant --
3755 ----------------------------------
3757 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
3758 Loc : constant Source_Ptr := Sloc (Typ);
3759 Constraints : constant List_Id := New_List;
3760 Components : constant Elist_Id := New_Elmt_List;
3761 Comp_Elmt : Elmt_Id;
3763 Comp_List : Node_Id;
3765 Discr_Val : Node_Id;
3766 Report_Errors : Boolean;
3769 if Serious_Errors_Detected > 0 then
3773 if Is_Record_Type (Typ)
3774 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
3775 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
3777 Comp_List := Component_List (Type_Definition (Parent (Typ)));
3778 Discr := First_Discriminant (Typ);
3780 while Present (Discr) loop
3781 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
3782 Discr_Val := Expression (Parent (Discr));
3784 if Present (Discr_Val)
3785 and then Is_OK_Static_Expression (Discr_Val)
3787 Append_To (Constraints,
3788 Make_Component_Association (Loc,
3789 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
3790 Expression => New_Copy (Discr_Val)));
3798 Next_Discriminant (Discr);
3803 Comp_List => Comp_List,
3804 Governed_By => Constraints,
3806 Report_Errors => Report_Errors);
3808 -- Check that each component present is fully initialized
3810 Comp_Elmt := First_Elmt (Components);
3812 while Present (Comp_Elmt) loop
3813 Comp_Id := Node (Comp_Elmt);
3815 if Ekind (Comp_Id) = E_Component
3816 and then (No (Parent (Comp_Id))
3817 or else No (Expression (Parent (Comp_Id))))
3818 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
3823 Next_Elmt (Comp_Elmt);
3828 elsif Is_Private_Type (Typ) then
3830 U : constant Entity_Id := Underlying_Type (Typ);
3836 return Is_Fully_Initialized_Variant (U);
3842 end Is_Fully_Initialized_Variant;
3844 ----------------------------
3845 -- Is_Inherited_Operation --
3846 ----------------------------
3848 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
3849 Kind : constant Node_Kind := Nkind (Parent (E));
3852 pragma Assert (Is_Overloadable (E));
3853 return Kind = N_Full_Type_Declaration
3854 or else Kind = N_Private_Extension_Declaration
3855 or else Kind = N_Subtype_Declaration
3856 or else (Ekind (E) = E_Enumeration_Literal
3857 and then Is_Derived_Type (Etype (E)));
3858 end Is_Inherited_Operation;
3860 -----------------------------
3861 -- Is_Library_Level_Entity --
3862 -----------------------------
3864 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
3866 -- The following is a small optimization, and it also handles
3867 -- properly discriminals, which in task bodies might appear in
3868 -- expressions before the corresponding procedure has been
3869 -- created, and which therefore do not have an assigned scope.
3871 if Ekind (E) in Formal_Kind then
3875 -- Normal test is simply that the enclosing dynamic scope is Standard
3877 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
3878 end Is_Library_Level_Entity;
3880 ---------------------------------
3881 -- Is_Local_Variable_Reference --
3882 ---------------------------------
3884 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
3886 if not Is_Entity_Name (Expr) then
3891 Ent : constant Entity_Id := Entity (Expr);
3892 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
3895 if Ekind (Ent) /= E_Variable
3897 Ekind (Ent) /= E_In_Out_Parameter
3902 return Present (Sub) and then Sub = Current_Subprogram;
3906 end Is_Local_Variable_Reference;
3912 function Is_Lvalue (N : Node_Id) return Boolean is
3913 P : constant Node_Id := Parent (N);
3918 -- Test left side of assignment
3920 when N_Assignment_Statement =>
3921 return N = Name (P);
3923 -- Test prefix of component or attribute
3925 when N_Attribute_Reference |
3927 N_Explicit_Dereference |
3928 N_Indexed_Component |
3930 N_Selected_Component |
3932 return N = Prefix (P);
3934 -- Test subprogram parameter (we really should check the
3935 -- parameter mode, but it is not worth the trouble)
3937 when N_Function_Call |
3938 N_Procedure_Call_Statement |
3939 N_Accept_Statement |
3940 N_Parameter_Association =>
3943 -- Test for appearing in a conversion that itself appears
3944 -- in an lvalue context, since this should be an lvalue.
3946 when N_Type_Conversion =>
3947 return Is_Lvalue (P);
3949 -- Test for appearence in object renaming declaration
3951 when N_Object_Renaming_Declaration =>
3954 -- All other references are definitely not Lvalues
3962 -------------------------
3963 -- Is_Object_Reference --
3964 -------------------------
3966 function Is_Object_Reference (N : Node_Id) return Boolean is
3968 if Is_Entity_Name (N) then
3969 return Is_Object (Entity (N));
3973 when N_Indexed_Component | N_Slice =>
3974 return Is_Object_Reference (Prefix (N));
3976 -- In Ada95, a function call is a constant object
3978 when N_Function_Call =>
3981 -- A reference to the stream attribute Input is a function call
3983 when N_Attribute_Reference =>
3984 return Attribute_Name (N) = Name_Input;
3986 when N_Selected_Component =>
3988 Is_Object_Reference (Selector_Name (N))
3989 and then Is_Object_Reference (Prefix (N));
3991 when N_Explicit_Dereference =>
3994 -- A view conversion of a tagged object is an object reference
3996 when N_Type_Conversion =>
3997 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
3998 and then Is_Tagged_Type (Etype (Expression (N)))
3999 and then Is_Object_Reference (Expression (N));
4001 -- An unchecked type conversion is considered to be an object if
4002 -- the operand is an object (this construction arises only as a
4003 -- result of expansion activities).
4005 when N_Unchecked_Type_Conversion =>
4012 end Is_Object_Reference;
4014 -----------------------------------
4015 -- Is_OK_Variable_For_Out_Formal --
4016 -----------------------------------
4018 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
4020 Note_Possible_Modification (AV);
4022 -- We must reject parenthesized variable names. The check for
4023 -- Comes_From_Source is present because there are currently
4024 -- cases where the compiler violates this rule (e.g. passing
4025 -- a task object to its controlled Initialize routine).
4027 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
4030 -- A variable is always allowed
4032 elsif Is_Variable (AV) then
4035 -- Unchecked conversions are allowed only if they come from the
4036 -- generated code, which sometimes uses unchecked conversions for
4037 -- out parameters in cases where code generation is unaffected.
4038 -- We tell source unchecked conversions by seeing if they are
4039 -- rewrites of an original UC function call, or of an explicit
4040 -- conversion of a function call.
4042 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
4043 if Nkind (Original_Node (AV)) = N_Function_Call then
4046 elsif Comes_From_Source (AV)
4047 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
4051 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
4052 return Is_OK_Variable_For_Out_Formal (Expression (AV));
4058 -- Normal type conversions are allowed if argument is a variable
4060 elsif Nkind (AV) = N_Type_Conversion then
4061 if Is_Variable (Expression (AV))
4062 and then Paren_Count (Expression (AV)) = 0
4064 Note_Possible_Modification (Expression (AV));
4067 -- We also allow a non-parenthesized expression that raises
4068 -- constraint error if it rewrites what used to be a variable
4070 elsif Raises_Constraint_Error (Expression (AV))
4071 and then Paren_Count (Expression (AV)) = 0
4072 and then Is_Variable (Original_Node (Expression (AV)))
4076 -- Type conversion of something other than a variable
4082 -- If this node is rewritten, then test the original form, if that is
4083 -- OK, then we consider the rewritten node OK (for example, if the
4084 -- original node is a conversion, then Is_Variable will not be true
4085 -- but we still want to allow the conversion if it converts a variable).
4087 elsif Original_Node (AV) /= AV then
4088 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
4090 -- All other non-variables are rejected
4095 end Is_OK_Variable_For_Out_Formal;
4097 -----------------------------------
4098 -- Is_Partially_Initialized_Type --
4099 -----------------------------------
4101 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
4103 if Is_Scalar_Type (Typ) then
4106 elsif Is_Access_Type (Typ) then
4109 elsif Is_Array_Type (Typ) then
4111 -- If component type is partially initialized, so is array type
4113 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
4116 -- Otherwise we are only partially initialized if we are fully
4117 -- initialized (this is the empty array case, no point in us
4118 -- duplicating that code here).
4121 return Is_Fully_Initialized_Type (Typ);
4124 elsif Is_Record_Type (Typ) then
4126 -- A discriminated type is always partially initialized
4128 if Has_Discriminants (Typ) then
4131 -- A tagged type is always partially initialized
4133 elsif Is_Tagged_Type (Typ) then
4136 -- Case of non-discriminated record
4142 Component_Present : Boolean := False;
4143 -- Set True if at least one component is present. If no
4144 -- components are present, then record type is fully
4145 -- initialized (another odd case, like the null array).
4148 -- Loop through components
4150 Ent := First_Entity (Typ);
4151 while Present (Ent) loop
4152 if Ekind (Ent) = E_Component then
4153 Component_Present := True;
4155 -- If a component has an initialization expression then
4156 -- the enclosing record type is partially initialized
4158 if Present (Parent (Ent))
4159 and then Present (Expression (Parent (Ent)))
4163 -- If a component is of a type which is itself partially
4164 -- initialized, then the enclosing record type is also.
4166 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
4174 -- No initialized components found. If we found any components
4175 -- they were all uninitialized so the result is false.
4177 if Component_Present then
4180 -- But if we found no components, then all the components are
4181 -- initialized so we consider the type to be initialized.
4189 -- Concurrent types are always fully initialized
4191 elsif Is_Concurrent_Type (Typ) then
4194 -- For a private type, go to underlying type. If there is no underlying
4195 -- type then just assume this partially initialized. Not clear if this
4196 -- can happen in a non-error case, but no harm in testing for this.
4198 elsif Is_Private_Type (Typ) then
4200 U : constant Entity_Id := Underlying_Type (Typ);
4206 return Is_Partially_Initialized_Type (U);
4210 -- For any other type (are there any?) assume partially initialized
4215 end Is_Partially_Initialized_Type;
4217 -----------------------------
4218 -- Is_RCI_Pkg_Spec_Or_Body --
4219 -----------------------------
4221 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
4223 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
4224 -- Return True if the unit of Cunit is an RCI package declaration
4226 ---------------------------
4227 -- Is_RCI_Pkg_Decl_Cunit --
4228 ---------------------------
4230 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
4231 The_Unit : constant Node_Id := Unit (Cunit);
4234 if Nkind (The_Unit) /= N_Package_Declaration then
4237 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
4238 end Is_RCI_Pkg_Decl_Cunit;
4240 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
4243 return Is_RCI_Pkg_Decl_Cunit (Cunit)
4245 (Nkind (Unit (Cunit)) = N_Package_Body
4246 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
4247 end Is_RCI_Pkg_Spec_Or_Body;
4249 -----------------------------------------
4250 -- Is_Remote_Access_To_Class_Wide_Type --
4251 -----------------------------------------
4253 function Is_Remote_Access_To_Class_Wide_Type
4254 (E : Entity_Id) return Boolean
4258 function Comes_From_Limited_Private_Type_Declaration
4261 -- Check that the type is declared by a limited type declaration,
4262 -- or else is derived from a Remote_Type ancestor through private
4265 -------------------------------------------------
4266 -- Comes_From_Limited_Private_Type_Declaration --
4267 -------------------------------------------------
4269 function Comes_From_Limited_Private_Type_Declaration (E : in Entity_Id)
4272 N : constant Node_Id := Declaration_Node (E);
4274 if Nkind (N) = N_Private_Type_Declaration
4275 and then Limited_Present (N)
4280 if Nkind (N) = N_Private_Extension_Declaration then
4282 Comes_From_Limited_Private_Type_Declaration (Etype (E))
4284 (Is_Remote_Types (Etype (E))
4285 and then Is_Limited_Record (Etype (E))
4286 and then Has_Private_Declaration (Etype (E)));
4290 end Comes_From_Limited_Private_Type_Declaration;
4292 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
4295 if not (Is_Remote_Call_Interface (E)
4296 or else Is_Remote_Types (E))
4297 or else Ekind (E) /= E_General_Access_Type
4302 D := Designated_Type (E);
4304 if Ekind (D) /= E_Class_Wide_Type then
4308 return Comes_From_Limited_Private_Type_Declaration
4309 (Defining_Identifier (Parent (D)));
4310 end Is_Remote_Access_To_Class_Wide_Type;
4312 -----------------------------------------
4313 -- Is_Remote_Access_To_Subprogram_Type --
4314 -----------------------------------------
4316 function Is_Remote_Access_To_Subprogram_Type
4317 (E : Entity_Id) return Boolean
4320 return (Ekind (E) = E_Access_Subprogram_Type
4321 or else (Ekind (E) = E_Record_Type
4322 and then Present (Corresponding_Remote_Type (E))))
4323 and then (Is_Remote_Call_Interface (E)
4324 or else Is_Remote_Types (E));
4325 end Is_Remote_Access_To_Subprogram_Type;
4327 --------------------
4328 -- Is_Remote_Call --
4329 --------------------
4331 function Is_Remote_Call (N : Node_Id) return Boolean is
4333 if Nkind (N) /= N_Procedure_Call_Statement
4334 and then Nkind (N) /= N_Function_Call
4336 -- An entry call cannot be remote
4340 elsif Nkind (Name (N)) in N_Has_Entity
4341 and then Is_Remote_Call_Interface (Entity (Name (N)))
4343 -- A subprogram declared in the spec of a RCI package is remote
4347 elsif Nkind (Name (N)) = N_Explicit_Dereference
4348 and then Is_Remote_Access_To_Subprogram_Type
4349 (Etype (Prefix (Name (N))))
4351 -- The dereference of a RAS is a remote call
4355 elsif Present (Controlling_Argument (N))
4356 and then Is_Remote_Access_To_Class_Wide_Type
4357 (Etype (Controlling_Argument (N)))
4359 -- Any primitive operation call with a controlling argument of
4360 -- a RACW type is a remote call.
4365 -- All other calls are local calls
4370 ----------------------
4371 -- Is_Selector_Name --
4372 ----------------------
4374 function Is_Selector_Name (N : Node_Id) return Boolean is
4377 if not Is_List_Member (N) then
4379 P : constant Node_Id := Parent (N);
4380 K : constant Node_Kind := Nkind (P);
4384 (K = N_Expanded_Name or else
4385 K = N_Generic_Association or else
4386 K = N_Parameter_Association or else
4387 K = N_Selected_Component)
4388 and then Selector_Name (P) = N;
4393 L : constant List_Id := List_Containing (N);
4394 P : constant Node_Id := Parent (L);
4397 return (Nkind (P) = N_Discriminant_Association
4398 and then Selector_Names (P) = L)
4400 (Nkind (P) = N_Component_Association
4401 and then Choices (P) = L);
4404 end Is_Selector_Name;
4410 function Is_Statement (N : Node_Id) return Boolean is
4413 Nkind (N) in N_Statement_Other_Than_Procedure_Call
4414 or else Nkind (N) = N_Procedure_Call_Statement;
4421 function Is_Transfer (N : Node_Id) return Boolean is
4422 Kind : constant Node_Kind := Nkind (N);
4425 if Kind = N_Return_Statement
4427 Kind = N_Goto_Statement
4429 Kind = N_Raise_Statement
4431 Kind = N_Requeue_Statement
4435 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
4436 and then No (Condition (N))
4440 elsif Kind = N_Procedure_Call_Statement
4441 and then Is_Entity_Name (Name (N))
4442 and then Present (Entity (Name (N)))
4443 and then No_Return (Entity (Name (N)))
4447 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
4459 function Is_True (U : Uint) return Boolean is
4468 function Is_Variable (N : Node_Id) return Boolean is
4470 Orig_Node : constant Node_Id := Original_Node (N);
4471 -- We do the test on the original node, since this is basically a
4472 -- test of syntactic categories, so it must not be disturbed by
4473 -- whatever rewriting might have occurred. For example, an aggregate,
4474 -- which is certainly NOT a variable, could be turned into a variable
4477 function In_Protected_Function (E : Entity_Id) return Boolean;
4478 -- Within a protected function, the private components of the
4479 -- enclosing protected type are constants. A function nested within
4480 -- a (protected) procedure is not itself protected.
4482 function Is_Variable_Prefix (P : Node_Id) return Boolean;
4483 -- Prefixes can involve implicit dereferences, in which case we
4484 -- must test for the case of a reference of a constant access
4485 -- type, which can never be a variable.
4487 ---------------------------
4488 -- In_Protected_Function --
4489 ---------------------------
4491 function In_Protected_Function (E : Entity_Id) return Boolean is
4492 Prot : constant Entity_Id := Scope (E);
4496 if not Is_Protected_Type (Prot) then
4501 while Present (S) and then S /= Prot loop
4503 if Ekind (S) = E_Function
4504 and then Scope (S) = Prot
4514 end In_Protected_Function;
4516 ------------------------
4517 -- Is_Variable_Prefix --
4518 ------------------------
4520 function Is_Variable_Prefix (P : Node_Id) return Boolean is
4522 if Is_Access_Type (Etype (P)) then
4523 return not Is_Access_Constant (Root_Type (Etype (P)));
4525 return Is_Variable (P);
4527 end Is_Variable_Prefix;
4529 -- Start of processing for Is_Variable
4532 -- Definitely OK if Assignment_OK is set. Since this is something that
4533 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
4535 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
4538 -- Normally we go to the original node, but there is one exception
4539 -- where we use the rewritten node, namely when it is an explicit
4540 -- dereference. The generated code may rewrite a prefix which is an
4541 -- access type with an explicit dereference. The dereference is a
4542 -- variable, even though the original node may not be (since it could
4543 -- be a constant of the access type).
4545 elsif Nkind (N) = N_Explicit_Dereference
4546 and then Nkind (Orig_Node) /= N_Explicit_Dereference
4547 and then Is_Access_Type (Etype (Orig_Node))
4549 return Is_Variable_Prefix (Original_Node (Prefix (N)));
4551 -- All remaining checks use the original node
4553 elsif Is_Entity_Name (Orig_Node) then
4555 E : constant Entity_Id := Entity (Orig_Node);
4556 K : constant Entity_Kind := Ekind (E);
4559 return (K = E_Variable
4560 and then Nkind (Parent (E)) /= N_Exception_Handler)
4561 or else (K = E_Component
4562 and then not In_Protected_Function (E))
4563 or else K = E_Out_Parameter
4564 or else K = E_In_Out_Parameter
4565 or else K = E_Generic_In_Out_Parameter
4567 -- Current instance of type:
4569 or else (Is_Type (E) and then In_Open_Scopes (E))
4570 or else (Is_Incomplete_Or_Private_Type (E)
4571 and then In_Open_Scopes (Full_View (E)));
4575 case Nkind (Orig_Node) is
4576 when N_Indexed_Component | N_Slice =>
4577 return Is_Variable_Prefix (Prefix (Orig_Node));
4579 when N_Selected_Component =>
4580 return Is_Variable_Prefix (Prefix (Orig_Node))
4581 and then Is_Variable (Selector_Name (Orig_Node));
4583 -- For an explicit dereference, the type of the prefix cannot
4584 -- be an access to constant or an access to subprogram.
4586 when N_Explicit_Dereference =>
4588 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
4591 return Is_Access_Type (Typ)
4592 and then not Is_Access_Constant (Root_Type (Typ))
4593 and then Ekind (Typ) /= E_Access_Subprogram_Type;
4596 -- The type conversion is the case where we do not deal with the
4597 -- context dependent special case of an actual parameter. Thus
4598 -- the type conversion is only considered a variable for the
4599 -- purposes of this routine if the target type is tagged. However,
4600 -- a type conversion is considered to be a variable if it does not
4601 -- come from source (this deals for example with the conversions
4602 -- of expressions to their actual subtypes).
4604 when N_Type_Conversion =>
4605 return Is_Variable (Expression (Orig_Node))
4607 (not Comes_From_Source (Orig_Node)
4609 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
4611 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
4613 -- GNAT allows an unchecked type conversion as a variable. This
4614 -- only affects the generation of internal expanded code, since
4615 -- calls to instantiations of Unchecked_Conversion are never
4616 -- considered variables (since they are function calls).
4617 -- This is also true for expression actions.
4619 when N_Unchecked_Type_Conversion =>
4620 return Is_Variable (Expression (Orig_Node));
4628 ------------------------
4629 -- Is_Volatile_Object --
4630 ------------------------
4632 function Is_Volatile_Object (N : Node_Id) return Boolean is
4634 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
4635 -- Determines if given object has volatile components
4637 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
4638 -- If prefix is an implicit dereference, examine designated type
4640 ------------------------
4641 -- Is_Volatile_Prefix --
4642 ------------------------
4644 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
4645 Typ : constant Entity_Id := Etype (N);
4648 if Is_Access_Type (Typ) then
4650 Dtyp : constant Entity_Id := Designated_Type (Typ);
4653 return Is_Volatile (Dtyp)
4654 or else Has_Volatile_Components (Dtyp);
4658 return Object_Has_Volatile_Components (N);
4660 end Is_Volatile_Prefix;
4662 ------------------------------------
4663 -- Object_Has_Volatile_Components --
4664 ------------------------------------
4666 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
4667 Typ : constant Entity_Id := Etype (N);
4670 if Is_Volatile (Typ)
4671 or else Has_Volatile_Components (Typ)
4675 elsif Is_Entity_Name (N)
4676 and then (Has_Volatile_Components (Entity (N))
4677 or else Is_Volatile (Entity (N)))
4681 elsif Nkind (N) = N_Indexed_Component
4682 or else Nkind (N) = N_Selected_Component
4684 return Is_Volatile_Prefix (Prefix (N));
4689 end Object_Has_Volatile_Components;
4691 -- Start of processing for Is_Volatile_Object
4694 if Is_Volatile (Etype (N))
4695 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
4699 elsif Nkind (N) = N_Indexed_Component
4700 or else Nkind (N) = N_Selected_Component
4702 return Is_Volatile_Prefix (Prefix (N));
4707 end Is_Volatile_Object;
4709 -------------------------
4710 -- Kill_Current_Values --
4711 -------------------------
4713 procedure Kill_Current_Values is
4716 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
4717 -- Clear current value for entity E and all entities chained to E
4719 ------------------------------------------
4720 -- Kill_Current_Values_For_Entity_Chain --
4721 ------------------------------------------
4723 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
4728 while Present (Ent) loop
4729 if Is_Object (Ent) then
4730 Set_Current_Value (Ent, Empty);
4732 if not Can_Never_Be_Null (Ent) then
4733 Set_Is_Known_Non_Null (Ent, False);
4739 end Kill_Current_Values_For_Entity_Chain;
4741 -- Start of processing for Kill_Current_Values
4744 -- Kill all saved checks, a special case of killing saved values
4748 -- Loop through relevant scopes, which includes the current scope and
4749 -- any parent scopes if the current scope is a block or a package.
4754 -- Clear current values of all entities in current scope
4756 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
4758 -- If scope is a package, also clear current values of all
4759 -- private entities in the scope.
4761 if Ekind (S) = E_Package
4763 Ekind (S) = E_Generic_Package
4765 Is_Concurrent_Type (S)
4767 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
4770 -- If this is a block or nested package, deal with parent
4772 if Ekind (S) = E_Block
4773 or else (Ekind (S) = E_Package
4774 and then not Is_Library_Level_Entity (S))
4780 end loop Scope_Loop;
4781 end Kill_Current_Values;
4783 --------------------------
4784 -- Kill_Size_Check_Code --
4785 --------------------------
4787 procedure Kill_Size_Check_Code (E : Entity_Id) is
4789 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4790 and then Present (Size_Check_Code (E))
4792 Remove (Size_Check_Code (E));
4793 Set_Size_Check_Code (E, Empty);
4795 end Kill_Size_Check_Code;
4797 -------------------------
4798 -- New_External_Entity --
4799 -------------------------
4801 function New_External_Entity
4802 (Kind : Entity_Kind;
4803 Scope_Id : Entity_Id;
4804 Sloc_Value : Source_Ptr;
4805 Related_Id : Entity_Id;
4807 Suffix_Index : Nat := 0;
4808 Prefix : Character := ' ') return Entity_Id
4810 N : constant Entity_Id :=
4811 Make_Defining_Identifier (Sloc_Value,
4813 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
4816 Set_Ekind (N, Kind);
4817 Set_Is_Internal (N, True);
4818 Append_Entity (N, Scope_Id);
4819 Set_Public_Status (N);
4821 if Kind in Type_Kind then
4822 Init_Size_Align (N);
4826 end New_External_Entity;
4828 -------------------------
4829 -- New_Internal_Entity --
4830 -------------------------
4832 function New_Internal_Entity
4833 (Kind : Entity_Kind;
4834 Scope_Id : Entity_Id;
4835 Sloc_Value : Source_Ptr;
4836 Id_Char : Character) return Entity_Id
4838 N : constant Entity_Id :=
4839 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
4842 Set_Ekind (N, Kind);
4843 Set_Is_Internal (N, True);
4844 Append_Entity (N, Scope_Id);
4846 if Kind in Type_Kind then
4847 Init_Size_Align (N);
4851 end New_Internal_Entity;
4857 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
4861 -- If we are pointing at a positional parameter, it is a member of
4862 -- a node list (the list of parameters), and the next parameter
4863 -- is the next node on the list, unless we hit a parameter
4864 -- association, in which case we shift to using the chain whose
4865 -- head is the First_Named_Actual in the parent, and then is
4866 -- threaded using the Next_Named_Actual of the Parameter_Association.
4867 -- All this fiddling is because the original node list is in the
4868 -- textual call order, and what we need is the declaration order.
4870 if Is_List_Member (Actual_Id) then
4871 N := Next (Actual_Id);
4873 if Nkind (N) = N_Parameter_Association then
4874 return First_Named_Actual (Parent (Actual_Id));
4880 return Next_Named_Actual (Parent (Actual_Id));
4884 procedure Next_Actual (Actual_Id : in out Node_Id) is
4886 Actual_Id := Next_Actual (Actual_Id);
4889 -----------------------
4890 -- Normalize_Actuals --
4891 -----------------------
4893 -- Chain actuals according to formals of subprogram. If there are
4894 -- no named associations, the chain is simply the list of Parameter
4895 -- Associations, since the order is the same as the declaration order.
4896 -- If there are named associations, then the First_Named_Actual field
4897 -- in the N_Procedure_Call_Statement node or N_Function_Call node
4898 -- points to the Parameter_Association node for the parameter that
4899 -- comes first in declaration order. The remaining named parameters
4900 -- are then chained in declaration order using Next_Named_Actual.
4902 -- This routine also verifies that the number of actuals is compatible
4903 -- with the number and default values of formals, but performs no type
4904 -- checking (type checking is done by the caller).
4906 -- If the matching succeeds, Success is set to True, and the caller
4907 -- proceeds with type-checking. If the match is unsuccessful, then
4908 -- Success is set to False, and the caller attempts a different
4909 -- interpretation, if there is one.
4911 -- If the flag Report is on, the call is not overloaded, and a failure
4912 -- to match can be reported here, rather than in the caller.
4914 procedure Normalize_Actuals
4918 Success : out Boolean)
4920 Actuals : constant List_Id := Parameter_Associations (N);
4921 Actual : Node_Id := Empty;
4923 Last : Node_Id := Empty;
4924 First_Named : Node_Id := Empty;
4927 Formals_To_Match : Integer := 0;
4928 Actuals_To_Match : Integer := 0;
4930 procedure Chain (A : Node_Id);
4931 -- Add named actual at the proper place in the list, using the
4932 -- Next_Named_Actual link.
4934 function Reporting return Boolean;
4935 -- Determines if an error is to be reported. To report an error, we
4936 -- need Report to be True, and also we do not report errors caused
4937 -- by calls to init procs that occur within other init procs. Such
4938 -- errors must always be cascaded errors, since if all the types are
4939 -- declared correctly, the compiler will certainly build decent calls!
4945 procedure Chain (A : Node_Id) is
4949 -- Call node points to first actual in list
4951 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
4954 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
4958 Set_Next_Named_Actual (Last, Empty);
4965 function Reporting return Boolean is
4970 elsif not Within_Init_Proc then
4973 elsif Is_Init_Proc (Entity (Name (N))) then
4981 -- Start of processing for Normalize_Actuals
4984 if Is_Access_Type (S) then
4986 -- The name in the call is a function call that returns an access
4987 -- to subprogram. The designated type has the list of formals.
4989 Formal := First_Formal (Designated_Type (S));
4991 Formal := First_Formal (S);
4994 while Present (Formal) loop
4995 Formals_To_Match := Formals_To_Match + 1;
4996 Next_Formal (Formal);
4999 -- Find if there is a named association, and verify that no positional
5000 -- associations appear after named ones.
5002 if Present (Actuals) then
5003 Actual := First (Actuals);
5006 while Present (Actual)
5007 and then Nkind (Actual) /= N_Parameter_Association
5009 Actuals_To_Match := Actuals_To_Match + 1;
5013 if No (Actual) and Actuals_To_Match = Formals_To_Match then
5015 -- Most common case: positional notation, no defaults
5020 elsif Actuals_To_Match > Formals_To_Match then
5022 -- Too many actuals: will not work
5025 if Is_Entity_Name (Name (N)) then
5026 Error_Msg_N ("too many arguments in call to&", Name (N));
5028 Error_Msg_N ("too many arguments in call", N);
5036 First_Named := Actual;
5038 while Present (Actual) loop
5039 if Nkind (Actual) /= N_Parameter_Association then
5041 ("positional parameters not allowed after named ones", Actual);
5046 Actuals_To_Match := Actuals_To_Match + 1;
5052 if Present (Actuals) then
5053 Actual := First (Actuals);
5056 Formal := First_Formal (S);
5057 while Present (Formal) loop
5059 -- Match the formals in order. If the corresponding actual
5060 -- is positional, nothing to do. Else scan the list of named
5061 -- actuals to find the one with the right name.
5064 and then Nkind (Actual) /= N_Parameter_Association
5067 Actuals_To_Match := Actuals_To_Match - 1;
5068 Formals_To_Match := Formals_To_Match - 1;
5071 -- For named parameters, search the list of actuals to find
5072 -- one that matches the next formal name.
5074 Actual := First_Named;
5077 while Present (Actual) loop
5078 if Chars (Selector_Name (Actual)) = Chars (Formal) then
5081 Actuals_To_Match := Actuals_To_Match - 1;
5082 Formals_To_Match := Formals_To_Match - 1;
5090 if Ekind (Formal) /= E_In_Parameter
5091 or else No (Default_Value (Formal))
5094 if (Comes_From_Source (S)
5095 or else Sloc (S) = Standard_Location)
5096 and then Is_Overloadable (S)
5100 (Nkind (Parent (N)) = N_Procedure_Call_Statement
5102 (Nkind (Parent (N)) = N_Function_Call
5104 Nkind (Parent (N)) = N_Parameter_Association))
5105 and then Ekind (S) /= E_Function
5107 Set_Etype (N, Etype (S));
5109 Error_Msg_Name_1 := Chars (S);
5110 Error_Msg_Sloc := Sloc (S);
5112 ("missing argument for parameter & " &
5113 "in call to % declared #", N, Formal);
5116 elsif Is_Overloadable (S) then
5117 Error_Msg_Name_1 := Chars (S);
5119 -- Point to type derivation that generated the
5122 Error_Msg_Sloc := Sloc (Parent (S));
5125 ("missing argument for parameter & " &
5126 "in call to % (inherited) #", N, Formal);
5130 ("missing argument for parameter &", N, Formal);
5138 Formals_To_Match := Formals_To_Match - 1;
5143 Next_Formal (Formal);
5146 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
5153 -- Find some superfluous named actual that did not get
5154 -- attached to the list of associations.
5156 Actual := First (Actuals);
5158 while Present (Actual) loop
5159 if Nkind (Actual) = N_Parameter_Association
5160 and then Actual /= Last
5161 and then No (Next_Named_Actual (Actual))
5163 Error_Msg_N ("unmatched actual & in call",
5164 Selector_Name (Actual));
5175 end Normalize_Actuals;
5177 --------------------------------
5178 -- Note_Possible_Modification --
5179 --------------------------------
5181 procedure Note_Possible_Modification (N : Node_Id) is
5182 Modification_Comes_From_Source : constant Boolean :=
5183 Comes_From_Source (Parent (N));
5189 -- Loop to find referenced entity, if there is one
5196 if Is_Entity_Name (Exp) then
5197 Ent := Entity (Exp);
5199 elsif Nkind (Exp) = N_Explicit_Dereference then
5201 P : constant Node_Id := Prefix (Exp);
5204 if Nkind (P) = N_Selected_Component
5206 Entry_Formal (Entity (Selector_Name (P))))
5208 -- Case of a reference to an entry formal
5210 Ent := Entry_Formal (Entity (Selector_Name (P)));
5212 elsif Nkind (P) = N_Identifier
5213 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
5214 and then Present (Expression (Parent (Entity (P))))
5215 and then Nkind (Expression (Parent (Entity (P))))
5218 -- Case of a reference to a value on which
5219 -- side effects have been removed.
5221 Exp := Prefix (Expression (Parent (Entity (P))));
5229 elsif Nkind (Exp) = N_Type_Conversion
5230 or else Nkind (Exp) = N_Unchecked_Type_Conversion
5232 Exp := Expression (Exp);
5234 elsif Nkind (Exp) = N_Slice
5235 or else Nkind (Exp) = N_Indexed_Component
5236 or else Nkind (Exp) = N_Selected_Component
5238 Exp := Prefix (Exp);
5245 -- Now look for entity being referenced
5247 if Present (Ent) then
5249 if Is_Object (Ent) then
5250 if Comes_From_Source (Exp)
5251 or else Modification_Comes_From_Source
5253 Set_Never_Set_In_Source (Ent, False);
5256 Set_Is_True_Constant (Ent, False);
5257 Set_Current_Value (Ent, Empty);
5259 if not Can_Never_Be_Null (Ent) then
5260 Set_Is_Known_Non_Null (Ent, False);
5263 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
5264 and then Present (Renamed_Object (Ent))
5266 Exp := Renamed_Object (Ent);
5270 Generate_Reference (Ent, Exp, 'm');
5277 end Note_Possible_Modification;
5279 -------------------------
5280 -- Object_Access_Level --
5281 -------------------------
5283 function Object_Access_Level (Obj : Node_Id) return Uint is
5286 -- Returns the static accessibility level of the view denoted
5287 -- by Obj. Note that the value returned is the result of a
5288 -- call to Scope_Depth. Only scope depths associated with
5289 -- dynamic scopes can actually be returned. Since only
5290 -- relative levels matter for accessibility checking, the fact
5291 -- that the distance between successive levels of accessibility
5292 -- is not always one is immaterial (invariant: if level(E2) is
5293 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
5296 if Is_Entity_Name (Obj) then
5299 -- If E is a type then it denotes a current instance.
5300 -- For this case we add one to the normal accessibility
5301 -- level of the type to ensure that current instances
5302 -- are treated as always being deeper than than the level
5303 -- of any visible named access type (see 3.10.2(21)).
5306 return Type_Access_Level (E) + 1;
5308 elsif Present (Renamed_Object (E)) then
5309 return Object_Access_Level (Renamed_Object (E));
5311 -- Similarly, if E is a component of the current instance of a
5312 -- protected type, any instance of it is assumed to be at a deeper
5313 -- level than the type. For a protected object (whose type is an
5314 -- anonymous protected type) its components are at the same level
5315 -- as the type itself.
5317 elsif not Is_Overloadable (E)
5318 and then Ekind (Scope (E)) = E_Protected_Type
5319 and then Comes_From_Source (Scope (E))
5321 return Type_Access_Level (Scope (E)) + 1;
5324 return Scope_Depth (Enclosing_Dynamic_Scope (E));
5327 elsif Nkind (Obj) = N_Selected_Component then
5328 if Is_Access_Type (Etype (Prefix (Obj))) then
5329 return Type_Access_Level (Etype (Prefix (Obj)));
5331 return Object_Access_Level (Prefix (Obj));
5334 elsif Nkind (Obj) = N_Indexed_Component then
5335 if Is_Access_Type (Etype (Prefix (Obj))) then
5336 return Type_Access_Level (Etype (Prefix (Obj)));
5338 return Object_Access_Level (Prefix (Obj));
5341 elsif Nkind (Obj) = N_Explicit_Dereference then
5343 -- If the prefix is a selected access discriminant then
5344 -- we make a recursive call on the prefix, which will
5345 -- in turn check the level of the prefix object of
5346 -- the selected discriminant.
5348 if Nkind (Prefix (Obj)) = N_Selected_Component
5349 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
5351 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
5353 return Object_Access_Level (Prefix (Obj));
5355 return Type_Access_Level (Etype (Prefix (Obj)));
5358 elsif Nkind (Obj) = N_Type_Conversion
5359 or else Nkind (Obj) = N_Unchecked_Type_Conversion
5361 return Object_Access_Level (Expression (Obj));
5363 -- Function results are objects, so we get either the access level
5364 -- of the function or, in the case of an indirect call, the level of
5365 -- of the access-to-subprogram type.
5367 elsif Nkind (Obj) = N_Function_Call then
5368 if Is_Entity_Name (Name (Obj)) then
5369 return Subprogram_Access_Level (Entity (Name (Obj)));
5371 return Type_Access_Level (Etype (Prefix (Name (Obj))));
5374 -- For convenience we handle qualified expressions, even though
5375 -- they aren't technically object names.
5377 elsif Nkind (Obj) = N_Qualified_Expression then
5378 return Object_Access_Level (Expression (Obj));
5380 -- Otherwise return the scope level of Standard.
5381 -- (If there are cases that fall through
5382 -- to this point they will be treated as
5383 -- having global accessibility for now. ???)
5386 return Scope_Depth (Standard_Standard);
5388 end Object_Access_Level;
5390 -----------------------
5391 -- Private_Component --
5392 -----------------------
5394 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
5395 Ancestor : constant Entity_Id := Base_Type (Type_Id);
5397 function Trace_Components
5399 Check : Boolean) return Entity_Id;
5400 -- Recursive function that does the work, and checks against circular
5401 -- definition for each subcomponent type.
5403 ----------------------
5404 -- Trace_Components --
5405 ----------------------
5407 function Trace_Components
5409 Check : Boolean) return Entity_Id
5411 Btype : constant Entity_Id := Base_Type (T);
5412 Component : Entity_Id;
5414 Candidate : Entity_Id := Empty;
5417 if Check and then Btype = Ancestor then
5418 Error_Msg_N ("circular type definition", Type_Id);
5422 if Is_Private_Type (Btype)
5423 and then not Is_Generic_Type (Btype)
5425 if Present (Full_View (Btype))
5426 and then Is_Record_Type (Full_View (Btype))
5427 and then not Is_Frozen (Btype)
5429 -- To indicate that the ancestor depends on a private type,
5430 -- the current Btype is sufficient. However, to check for
5431 -- circular definition we must recurse on the full view.
5433 Candidate := Trace_Components (Full_View (Btype), True);
5435 if Candidate = Any_Type then
5445 elsif Is_Array_Type (Btype) then
5446 return Trace_Components (Component_Type (Btype), True);
5448 elsif Is_Record_Type (Btype) then
5449 Component := First_Entity (Btype);
5450 while Present (Component) loop
5452 -- Skip anonymous types generated by constrained components
5454 if not Is_Type (Component) then
5455 P := Trace_Components (Etype (Component), True);
5458 if P = Any_Type then
5466 Next_Entity (Component);
5474 end Trace_Components;
5476 -- Start of processing for Private_Component
5479 return Trace_Components (Type_Id, False);
5480 end Private_Component;
5482 -----------------------
5483 -- Process_End_Label --
5484 -----------------------
5486 procedure Process_End_Label
5494 Label_Ref : Boolean;
5495 -- Set True if reference to end label itself is required
5498 -- Gets set to the operator symbol or identifier that references
5499 -- the entity Ent. For the child unit case, this is the identifier
5500 -- from the designator. For other cases, this is simply Endl.
5502 procedure Generate_Parent_Ref (N : Node_Id);
5503 -- N is an identifier node that appears as a parent unit reference
5504 -- in the case where Ent is a child unit. This procedure generates
5505 -- an appropriate cross-reference entry.
5507 -------------------------
5508 -- Generate_Parent_Ref --
5509 -------------------------
5511 procedure Generate_Parent_Ref (N : Node_Id) is
5512 Parent_Ent : Entity_Id;
5515 -- Search up scope stack. The reason we do this is that normal
5516 -- visibility analysis would not work for two reasons. First in
5517 -- some subunit cases, the entry for the parent unit may not be
5518 -- visible, and in any case there can be a local entity that
5519 -- hides the scope entity.
5521 Parent_Ent := Current_Scope;
5522 while Present (Parent_Ent) loop
5523 if Chars (Parent_Ent) = Chars (N) then
5525 -- Generate the reference. We do NOT consider this as a
5526 -- reference for unreferenced symbol purposes, but we do
5527 -- force a cross-reference even if the end line does not
5528 -- come from source (the caller already generated the
5529 -- appropriate Typ for this situation).
5532 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
5533 Style.Check_Identifier (N, Parent_Ent);
5537 Parent_Ent := Scope (Parent_Ent);
5540 -- Fall through means entity was not found -- that's odd, but
5541 -- the appropriate thing is simply to ignore and not generate
5542 -- any cross-reference for this entry.
5545 end Generate_Parent_Ref;
5547 -- Start of processing for Process_End_Label
5550 -- If no node, ignore. This happens in some error situations,
5551 -- and also for some internally generated structures where no
5552 -- end label references are required in any case.
5558 -- Nothing to do if no End_Label, happens for internally generated
5559 -- constructs where we don't want an end label reference anyway.
5560 -- Also nothing to do if Endl is a string literal, which means
5561 -- there was some prior error (bad operator symbol)
5563 Endl := End_Label (N);
5565 if No (Endl) or else Nkind (Endl) = N_String_Literal then
5569 -- Reference node is not in extended main source unit
5571 if not In_Extended_Main_Source_Unit (N) then
5573 -- Generally we do not collect references except for the
5574 -- extended main source unit. The one exception is the 'e'
5575 -- entry for a package spec, where it is useful for a client
5576 -- to have the ending information to define scopes.
5584 -- For this case, we can ignore any parent references,
5585 -- but we need the package name itself for the 'e' entry.
5587 if Nkind (Endl) = N_Designator then
5588 Endl := Identifier (Endl);
5592 -- Reference is in extended main source unit
5597 -- For designator, generate references for the parent entries
5599 if Nkind (Endl) = N_Designator then
5601 -- Generate references for the prefix if the END line comes
5602 -- from source (otherwise we do not need these references)
5604 if Comes_From_Source (Endl) then
5606 while Nkind (Nam) = N_Selected_Component loop
5607 Generate_Parent_Ref (Selector_Name (Nam));
5608 Nam := Prefix (Nam);
5611 Generate_Parent_Ref (Nam);
5614 Endl := Identifier (Endl);
5618 -- If the end label is not for the given entity, then either we have
5619 -- some previous error, or this is a generic instantiation for which
5620 -- we do not need to make a cross-reference in this case anyway. In
5621 -- either case we simply ignore the call.
5623 if Chars (Ent) /= Chars (Endl) then
5627 -- If label was really there, then generate a normal reference
5628 -- and then adjust the location in the end label to point past
5629 -- the name (which should almost always be the semicolon).
5633 if Comes_From_Source (Endl) then
5635 -- If a label reference is required, then do the style check
5636 -- and generate an l-type cross-reference entry for the label
5640 Style.Check_Identifier (Endl, Ent);
5642 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
5645 -- Set the location to point past the label (normally this will
5646 -- mean the semicolon immediately following the label). This is
5647 -- done for the sake of the 'e' or 't' entry generated below.
5649 Get_Decoded_Name_String (Chars (Endl));
5650 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
5653 -- Now generate the e/t reference
5655 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
5657 -- Restore Sloc, in case modified above, since we have an identifier
5658 -- and the normal Sloc should be left set in the tree.
5660 Set_Sloc (Endl, Loc);
5661 end Process_End_Label;
5667 -- We do the conversion to get the value of the real string by using
5668 -- the scanner, see Sinput for details on use of the internal source
5669 -- buffer for scanning internal strings.
5671 function Real_Convert (S : String) return Node_Id is
5672 Save_Src : constant Source_Buffer_Ptr := Source;
5676 Source := Internal_Source_Ptr;
5679 for J in S'Range loop
5680 Source (Source_Ptr (J)) := S (J);
5683 Source (S'Length + 1) := EOF;
5685 if Source (Scan_Ptr) = '-' then
5687 Scan_Ptr := Scan_Ptr + 1;
5695 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
5702 ---------------------
5703 -- Rep_To_Pos_Flag --
5704 ---------------------
5706 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
5708 return New_Occurrence_Of
5709 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
5710 end Rep_To_Pos_Flag;
5712 --------------------
5713 -- Require_Entity --
5714 --------------------
5716 procedure Require_Entity (N : Node_Id) is
5718 if Is_Entity_Name (N) and then No (Entity (N)) then
5719 if Total_Errors_Detected /= 0 then
5720 Set_Entity (N, Any_Id);
5722 raise Program_Error;
5727 ------------------------------
5728 -- Requires_Transient_Scope --
5729 ------------------------------
5731 -- A transient scope is required when variable-sized temporaries are
5732 -- allocated in the primary or secondary stack, or when finalization
5733 -- actions must be generated before the next instruction.
5735 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
5736 Typ : constant Entity_Id := Underlying_Type (Id);
5738 -- Start of processing for Requires_Transient_Scope
5741 -- This is a private type which is not completed yet. This can only
5742 -- happen in a default expression (of a formal parameter or of a
5743 -- record component). Do not expand transient scope in this case
5748 -- Do not expand transient scope for non-existent procedure return
5750 elsif Typ = Standard_Void_Type then
5753 -- Elementary types do not require a transient scope
5755 elsif Is_Elementary_Type (Typ) then
5758 -- Generally, indefinite subtypes require a transient scope, since the
5759 -- back end cannot generate temporaries, since this is not a valid type
5760 -- for declaring an object. It might be possible to relax this in the
5761 -- future, e.g. by declaring the maximum possible space for the type.
5763 elsif Is_Indefinite_Subtype (Typ) then
5766 -- Functions returning tagged types may dispatch on result so their
5767 -- returned value is allocated on the secondary stack. Controlled
5768 -- type temporaries need finalization.
5770 elsif Is_Tagged_Type (Typ)
5771 or else Has_Controlled_Component (Typ)
5777 elsif Is_Record_Type (Typ) then
5779 -- In GCC 2, discriminated records always require a transient
5780 -- scope because the back end otherwise tries to allocate a
5781 -- variable length temporary for the particular variant.
5783 if Opt.GCC_Version = 2
5784 and then Has_Discriminants (Typ)
5788 -- For GCC 3, or for a non-discriminated record in GCC 2, we are
5789 -- OK if none of the component types requires a transient scope.
5790 -- Note that we already know that this is a definite type (i.e.
5791 -- has discriminant defaults if it is a discriminated record).
5797 Comp := First_Entity (Typ);
5798 while Present (Comp) loop
5799 if Requires_Transient_Scope (Etype (Comp)) then
5810 -- String literal types never require transient scope
5812 elsif Ekind (Typ) = E_String_Literal_Subtype then
5815 -- Array type. Note that we already know that this is a constrained
5816 -- array, since unconstrained arrays will fail the indefinite test.
5818 elsif Is_Array_Type (Typ) then
5820 -- If component type requires a transient scope, the array does too
5822 if Requires_Transient_Scope (Component_Type (Typ)) then
5825 -- Otherwise, we only need a transient scope if the size is not
5826 -- known at compile time.
5829 return not Size_Known_At_Compile_Time (Typ);
5832 -- All other cases do not require a transient scope
5837 end Requires_Transient_Scope;
5839 --------------------------
5840 -- Reset_Analyzed_Flags --
5841 --------------------------
5843 procedure Reset_Analyzed_Flags (N : Node_Id) is
5845 function Clear_Analyzed
5846 (N : Node_Id) return Traverse_Result;
5847 -- Function used to reset Analyzed flags in tree. Note that we do
5848 -- not reset Analyzed flags in entities, since there is no need to
5849 -- renalalyze entities, and indeed, it is wrong to do so, since it
5850 -- can result in generating auxiliary stuff more than once.
5852 --------------------
5853 -- Clear_Analyzed --
5854 --------------------
5856 function Clear_Analyzed
5857 (N : Node_Id) return Traverse_Result
5860 if not Has_Extension (N) then
5861 Set_Analyzed (N, False);
5867 function Reset_Analyzed is
5868 new Traverse_Func (Clear_Analyzed);
5870 Discard : Traverse_Result;
5871 pragma Warnings (Off, Discard);
5873 -- Start of processing for Reset_Analyzed_Flags
5876 Discard := Reset_Analyzed (N);
5877 end Reset_Analyzed_Flags;
5879 ---------------------------
5880 -- Safe_To_Capture_Value --
5881 ---------------------------
5883 function Safe_To_Capture_Value
5885 Ent : Entity_Id) return Boolean
5888 -- The only entities for which we track constant values are variables,
5889 -- out parameters and in out parameters, so check if we have this case.
5891 if Ekind (Ent) /= E_Variable
5893 Ekind (Ent) /= E_Out_Parameter
5895 Ekind (Ent) /= E_In_Out_Parameter
5900 -- Skip volatile and aliased variables, since funny things might
5901 -- be going on in these cases which we cannot necessarily track.
5903 if Treat_As_Volatile (Ent) or else Is_Aliased (Ent) then
5907 -- OK, all above conditions are met. We also require that the scope
5908 -- of the reference be the same as the scope of the entity, not
5909 -- counting packages and blocks.
5912 E_Scope : constant Entity_Id := Scope (Ent);
5913 R_Scope : Entity_Id;
5916 R_Scope := Current_Scope;
5917 while R_Scope /= Standard_Standard loop
5918 exit when R_Scope = E_Scope;
5920 if Ekind (R_Scope) /= E_Package
5922 Ekind (R_Scope) /= E_Block
5926 R_Scope := Scope (R_Scope);
5931 -- We also require that the reference does not appear in a context
5932 -- where it is not sure to be executed (i.e. a conditional context
5933 -- or an exception handler).
5940 while Present (P) loop
5941 if Nkind (P) = N_If_Statement
5943 Nkind (P) = N_Case_Statement
5945 Nkind (P) = N_Exception_Handler
5947 Nkind (P) = N_Selective_Accept
5949 Nkind (P) = N_Conditional_Entry_Call
5951 Nkind (P) = N_Timed_Entry_Call
5953 Nkind (P) = N_Asynchronous_Select
5962 -- OK, looks safe to set value
5965 end Safe_To_Capture_Value;
5971 function Same_Name (N1, N2 : Node_Id) return Boolean is
5972 K1 : constant Node_Kind := Nkind (N1);
5973 K2 : constant Node_Kind := Nkind (N2);
5976 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
5977 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
5979 return Chars (N1) = Chars (N2);
5981 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
5982 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
5984 return Same_Name (Selector_Name (N1), Selector_Name (N2))
5985 and then Same_Name (Prefix (N1), Prefix (N2));
5996 function Same_Type (T1, T2 : Entity_Id) return Boolean is
6001 elsif not Is_Constrained (T1)
6002 and then not Is_Constrained (T2)
6003 and then Base_Type (T1) = Base_Type (T2)
6007 -- For now don't bother with case of identical constraints, to be
6008 -- fiddled with later on perhaps (this is only used for optimization
6009 -- purposes, so it is not critical to do a best possible job)
6016 ------------------------
6017 -- Scope_Is_Transient --
6018 ------------------------
6020 function Scope_Is_Transient return Boolean is
6022 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
6023 end Scope_Is_Transient;
6029 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
6034 while Scop /= Standard_Standard loop
6035 Scop := Scope (Scop);
6037 if Scop = Scope2 then
6045 --------------------------
6046 -- Scope_Within_Or_Same --
6047 --------------------------
6049 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
6054 while Scop /= Standard_Standard loop
6055 if Scop = Scope2 then
6058 Scop := Scope (Scop);
6063 end Scope_Within_Or_Same;
6065 ------------------------
6066 -- Set_Current_Entity --
6067 ------------------------
6069 -- The given entity is to be set as the currently visible definition
6070 -- of its associated name (i.e. the Node_Id associated with its name).
6071 -- All we have to do is to get the name from the identifier, and
6072 -- then set the associated Node_Id to point to the given entity.
6074 procedure Set_Current_Entity (E : Entity_Id) is
6076 Set_Name_Entity_Id (Chars (E), E);
6077 end Set_Current_Entity;
6079 ---------------------------------
6080 -- Set_Entity_With_Style_Check --
6081 ---------------------------------
6083 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
6084 Val_Actual : Entity_Id;
6088 Set_Entity (N, Val);
6091 and then not Suppress_Style_Checks (Val)
6092 and then not In_Instance
6094 if Nkind (N) = N_Identifier then
6097 elsif Nkind (N) = N_Expanded_Name then
6098 Nod := Selector_Name (N);
6106 -- A special situation arises for derived operations, where we want
6107 -- to do the check against the parent (since the Sloc of the derived
6108 -- operation points to the derived type declaration itself).
6110 while not Comes_From_Source (Val_Actual)
6111 and then Nkind (Val_Actual) in N_Entity
6112 and then (Ekind (Val_Actual) = E_Enumeration_Literal
6113 or else Is_Subprogram (Val_Actual)
6114 or else Is_Generic_Subprogram (Val_Actual))
6115 and then Present (Alias (Val_Actual))
6117 Val_Actual := Alias (Val_Actual);
6120 -- Renaming declarations for generic actuals do not come from source,
6121 -- and have a different name from that of the entity they rename, so
6122 -- there is no style check to perform here.
6124 if Chars (Nod) = Chars (Val_Actual) then
6125 Style.Check_Identifier (Nod, Val_Actual);
6129 Set_Entity (N, Val);
6130 end Set_Entity_With_Style_Check;
6132 ------------------------
6133 -- Set_Name_Entity_Id --
6134 ------------------------
6136 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
6138 Set_Name_Table_Info (Id, Int (Val));
6139 end Set_Name_Entity_Id;
6141 ---------------------
6142 -- Set_Next_Actual --
6143 ---------------------
6145 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
6147 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
6148 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
6150 end Set_Next_Actual;
6152 -----------------------
6153 -- Set_Public_Status --
6154 -----------------------
6156 procedure Set_Public_Status (Id : Entity_Id) is
6157 S : constant Entity_Id := Current_Scope;
6160 if S = Standard_Standard
6161 or else (Is_Public (S)
6162 and then (Ekind (S) = E_Package
6163 or else Is_Record_Type (S)
6164 or else Ekind (S) = E_Void))
6168 -- The bounds of an entry family declaration can generate object
6169 -- declarations that are visible to the back-end, e.g. in the
6170 -- the declaration of a composite type that contains tasks.
6173 and then Is_Concurrent_Type (S)
6174 and then not Has_Completion (S)
6175 and then Nkind (Parent (Id)) = N_Object_Declaration
6179 end Set_Public_Status;
6181 ----------------------------
6182 -- Set_Scope_Is_Transient --
6183 ----------------------------
6185 procedure Set_Scope_Is_Transient (V : Boolean := True) is
6187 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
6188 end Set_Scope_Is_Transient;
6194 procedure Set_Size_Info (T1, T2 : Entity_Id) is
6196 -- We copy Esize, but not RM_Size, since in general RM_Size is
6197 -- subtype specific and does not get inherited by all subtypes.
6199 Set_Esize (T1, Esize (T2));
6200 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
6202 if Is_Discrete_Or_Fixed_Point_Type (T1)
6204 Is_Discrete_Or_Fixed_Point_Type (T2)
6206 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
6208 Set_Alignment (T1, Alignment (T2));
6211 --------------------
6212 -- Static_Integer --
6213 --------------------
6215 function Static_Integer (N : Node_Id) return Uint is
6217 Analyze_And_Resolve (N, Any_Integer);
6220 or else Error_Posted (N)
6221 or else Etype (N) = Any_Type
6226 if Is_Static_Expression (N) then
6227 if not Raises_Constraint_Error (N) then
6228 return Expr_Value (N);
6233 elsif Etype (N) = Any_Type then
6237 Flag_Non_Static_Expr
6238 ("static integer expression required here", N);
6243 --------------------------
6244 -- Statically_Different --
6245 --------------------------
6247 function Statically_Different (E1, E2 : Node_Id) return Boolean is
6248 R1 : constant Node_Id := Get_Referenced_Object (E1);
6249 R2 : constant Node_Id := Get_Referenced_Object (E2);
6252 return Is_Entity_Name (R1)
6253 and then Is_Entity_Name (R2)
6254 and then Entity (R1) /= Entity (R2)
6255 and then not Is_Formal (Entity (R1))
6256 and then not Is_Formal (Entity (R2));
6257 end Statically_Different;
6259 -----------------------------
6260 -- Subprogram_Access_Level --
6261 -----------------------------
6263 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
6265 if Present (Alias (Subp)) then
6266 return Subprogram_Access_Level (Alias (Subp));
6268 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
6270 end Subprogram_Access_Level;
6276 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
6278 if Debug_Flag_W then
6279 for J in 0 .. Scope_Stack.Last loop
6284 Write_Name (Chars (E));
6285 Write_Str (" line ");
6286 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
6291 -----------------------
6292 -- Transfer_Entities --
6293 -----------------------
6295 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
6296 Ent : Entity_Id := First_Entity (From);
6303 if (Last_Entity (To)) = Empty then
6304 Set_First_Entity (To, Ent);
6306 Set_Next_Entity (Last_Entity (To), Ent);
6309 Set_Last_Entity (To, Last_Entity (From));
6311 while Present (Ent) loop
6312 Set_Scope (Ent, To);
6314 if not Is_Public (Ent) then
6315 Set_Public_Status (Ent);
6318 and then Ekind (Ent) = E_Record_Subtype
6321 -- The components of the propagated Itype must be public
6328 Comp := First_Entity (Ent);
6330 while Present (Comp) loop
6331 Set_Is_Public (Comp);
6341 Set_First_Entity (From, Empty);
6342 Set_Last_Entity (From, Empty);
6343 end Transfer_Entities;
6345 -----------------------
6346 -- Type_Access_Level --
6347 -----------------------
6349 function Type_Access_Level (Typ : Entity_Id) return Uint is
6353 -- If the type is an anonymous access type we treat it as being
6354 -- declared at the library level to ensure that names such as
6355 -- X.all'access don't fail static accessibility checks.
6357 -- Ada 2005 (AI-230): In case of anonymous access types that are
6358 -- component_definition or discriminants of a nonlimited type,
6359 -- the level is the same as that of the enclosing component type.
6361 Btyp := Base_Type (Typ);
6362 if Ekind (Btyp) in Access_Kind then
6363 if Ekind (Btyp) = E_Anonymous_Access_Type
6364 and then not Is_Array_Type (Scope (Btyp)) -- Ada 2005 (AI-230)
6365 and then Ekind (Scope (Btyp)) /= E_Record_Type -- Ada 2005 (AI-230)
6367 return Scope_Depth (Standard_Standard);
6370 Btyp := Root_Type (Btyp);
6373 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
6374 end Type_Access_Level;
6376 --------------------------
6377 -- Unit_Declaration_Node --
6378 --------------------------
6380 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
6381 N : Node_Id := Parent (Unit_Id);
6384 -- Predefined operators do not have a full function declaration
6386 if Ekind (Unit_Id) = E_Operator then
6390 while Nkind (N) /= N_Abstract_Subprogram_Declaration
6391 and then Nkind (N) /= N_Formal_Package_Declaration
6392 and then Nkind (N) /= N_Formal_Subprogram_Declaration
6393 and then Nkind (N) /= N_Function_Instantiation
6394 and then Nkind (N) /= N_Generic_Package_Declaration
6395 and then Nkind (N) /= N_Generic_Subprogram_Declaration
6396 and then Nkind (N) /= N_Package_Declaration
6397 and then Nkind (N) /= N_Package_Body
6398 and then Nkind (N) /= N_Package_Instantiation
6399 and then Nkind (N) /= N_Package_Renaming_Declaration
6400 and then Nkind (N) /= N_Procedure_Instantiation
6401 and then Nkind (N) /= N_Protected_Body
6402 and then Nkind (N) /= N_Subprogram_Declaration
6403 and then Nkind (N) /= N_Subprogram_Body
6404 and then Nkind (N) /= N_Subprogram_Body_Stub
6405 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
6406 and then Nkind (N) /= N_Task_Body
6407 and then Nkind (N) /= N_Task_Type_Declaration
6408 and then Nkind (N) not in N_Generic_Renaming_Declaration
6411 pragma Assert (Present (N));
6415 end Unit_Declaration_Node;
6417 ------------------------------
6418 -- Universal_Interpretation --
6419 ------------------------------
6421 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
6422 Index : Interp_Index;
6426 -- The argument may be a formal parameter of an operator or subprogram
6427 -- with multiple interpretations, or else an expression for an actual.
6429 if Nkind (Opnd) = N_Defining_Identifier
6430 or else not Is_Overloaded (Opnd)
6432 if Etype (Opnd) = Universal_Integer
6433 or else Etype (Opnd) = Universal_Real
6435 return Etype (Opnd);
6441 Get_First_Interp (Opnd, Index, It);
6443 while Present (It.Typ) loop
6445 if It.Typ = Universal_Integer
6446 or else It.Typ = Universal_Real
6451 Get_Next_Interp (Index, It);
6456 end Universal_Interpretation;
6458 ----------------------
6459 -- Within_Init_Proc --
6460 ----------------------
6462 function Within_Init_Proc return Boolean is
6467 while not Is_Overloadable (S) loop
6468 if S = Standard_Standard then
6475 return Is_Init_Proc (S);
6476 end Within_Init_Proc;
6482 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
6483 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
6484 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
6486 function Has_One_Matching_Field return Boolean;
6487 -- Determines whether Expec_Type is a record type with a single
6488 -- component or discriminant whose type matches the found type or
6489 -- is a one dimensional array whose component type matches the
6492 function Has_One_Matching_Field return Boolean is
6496 if Is_Array_Type (Expec_Type)
6497 and then Number_Dimensions (Expec_Type) = 1
6499 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
6503 elsif not Is_Record_Type (Expec_Type) then
6507 E := First_Entity (Expec_Type);
6513 elsif (Ekind (E) /= E_Discriminant
6514 and then Ekind (E) /= E_Component)
6515 or else (Chars (E) = Name_uTag
6516 or else Chars (E) = Name_uParent)
6525 if not Covers (Etype (E), Found_Type) then
6528 elsif Present (Next_Entity (E)) then
6535 end Has_One_Matching_Field;
6537 -- Start of processing for Wrong_Type
6540 -- Don't output message if either type is Any_Type, or if a message
6541 -- has already been posted for this node. We need to do the latter
6542 -- check explicitly (it is ordinarily done in Errout), because we
6543 -- are using ! to force the output of the error messages.
6545 if Expec_Type = Any_Type
6546 or else Found_Type = Any_Type
6547 or else Error_Posted (Expr)
6551 -- In an instance, there is an ongoing problem with completion of
6552 -- type derived from private types. Their structure is what Gigi
6553 -- expects, but the Etype is the parent type rather than the
6554 -- derived private type itself. Do not flag error in this case. The
6555 -- private completion is an entity without a parent, like an Itype.
6556 -- Similarly, full and partial views may be incorrect in the instance.
6557 -- There is no simple way to insure that it is consistent ???
6559 elsif In_Instance then
6561 if Etype (Etype (Expr)) = Etype (Expected_Type)
6563 (Has_Private_Declaration (Expected_Type)
6564 or else Has_Private_Declaration (Etype (Expr)))
6565 and then No (Parent (Expected_Type))
6571 -- An interesting special check. If the expression is parenthesized
6572 -- and its type corresponds to the type of the sole component of the
6573 -- expected record type, or to the component type of the expected one
6574 -- dimensional array type, then assume we have a bad aggregate attempt.
6576 if Nkind (Expr) in N_Subexpr
6577 and then Paren_Count (Expr) /= 0
6578 and then Has_One_Matching_Field
6580 Error_Msg_N ("positional aggregate cannot have one component", Expr);
6582 -- Another special check, if we are looking for a pool-specific access
6583 -- type and we found an E_Access_Attribute_Type, then we have the case
6584 -- of an Access attribute being used in a context which needs a pool-
6585 -- specific type, which is never allowed. The one extra check we make
6586 -- is that the expected designated type covers the Found_Type.
6588 elsif Is_Access_Type (Expec_Type)
6589 and then Ekind (Found_Type) = E_Access_Attribute_Type
6590 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
6591 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
6593 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
6595 Error_Msg_N ("result must be general access type!", Expr);
6596 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
6598 -- If the expected type is an anonymous access type, as for access
6599 -- parameters and discriminants, the error is on the designated types.
6601 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
6602 if Comes_From_Source (Expec_Type) then
6603 Error_Msg_NE ("expected}!", Expr, Expec_Type);
6606 ("expected an access type with designated}",
6607 Expr, Designated_Type (Expec_Type));
6610 if Is_Access_Type (Found_Type)
6611 and then not Comes_From_Source (Found_Type)
6614 ("found an access type with designated}!",
6615 Expr, Designated_Type (Found_Type));
6617 if From_With_Type (Found_Type) then
6618 Error_Msg_NE ("found incomplete}!", Expr, Found_Type);
6620 ("\possibly missing with_clause on&", Expr,
6621 Scope (Found_Type));
6623 Error_Msg_NE ("found}!", Expr, Found_Type);
6627 -- Normal case of one type found, some other type expected
6630 -- If the names of the two types are the same, see if some
6631 -- number of levels of qualification will help. Don't try
6632 -- more than three levels, and if we get to standard, it's
6633 -- no use (and probably represents an error in the compiler)
6634 -- Also do not bother with internal scope names.
6637 Expec_Scope : Entity_Id;
6638 Found_Scope : Entity_Id;
6641 Expec_Scope := Expec_Type;
6642 Found_Scope := Found_Type;
6644 for Levels in Int range 0 .. 3 loop
6645 if Chars (Expec_Scope) /= Chars (Found_Scope) then
6646 Error_Msg_Qual_Level := Levels;
6650 Expec_Scope := Scope (Expec_Scope);
6651 Found_Scope := Scope (Found_Scope);
6653 exit when Expec_Scope = Standard_Standard
6655 Found_Scope = Standard_Standard
6657 not Comes_From_Source (Expec_Scope)
6659 not Comes_From_Source (Found_Scope);
6663 Error_Msg_NE ("expected}!", Expr, Expec_Type);
6665 if Is_Entity_Name (Expr)
6666 and then Is_Package (Entity (Expr))
6668 Error_Msg_N ("found package name!", Expr);
6670 elsif Is_Entity_Name (Expr)
6672 (Ekind (Entity (Expr)) = E_Procedure
6674 Ekind (Entity (Expr)) = E_Generic_Procedure)
6676 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
6678 ("found procedure name, possibly missing Access attribute!",
6681 Error_Msg_N ("found procedure name instead of function!", Expr);
6684 elsif Nkind (Expr) = N_Function_Call
6685 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
6686 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
6687 and then No (Parameter_Associations (Expr))
6690 ("found function name, possibly missing Access attribute!",
6693 -- Catch common error: a prefix or infix operator which is not
6694 -- directly visible because the type isn't.
6696 elsif Nkind (Expr) in N_Op
6697 and then Is_Overloaded (Expr)
6698 and then not Is_Immediately_Visible (Expec_Type)
6699 and then not Is_Potentially_Use_Visible (Expec_Type)
6700 and then not In_Use (Expec_Type)
6701 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
6704 "operator of the type is not directly visible!", Expr);
6706 elsif Ekind (Found_Type) = E_Void
6707 and then Present (Parent (Found_Type))
6708 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
6710 Error_Msg_NE ("found premature usage of}!", Expr, Found_Type);
6713 Error_Msg_NE ("found}!", Expr, Found_Type);
6716 Error_Msg_Qual_Level := 0;