1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Type; use Sem_Type;
54 with Sinfo; use Sinfo;
55 with Sinput; use Sinput;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
67 package body Sem_Util is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold : constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used : Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries : Nat;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup : Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num is Int range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 ----------------------------------
99 -- Order Dependence (AI05-0144) --
100 ----------------------------------
102 -- Each actual in a call is entered into the table below. A flag indicates
103 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
104 -- (procedure call, condition, assignment) examines all the actuals for a
105 -- possible order dependence. The table is reset after each such check.
106 -- The actuals to be checked in a call to Check_Order_Dependence are at
107 -- positions 1 .. Last.
109 type Actual_Name is record
111 Is_Writable : Boolean;
114 package Actuals_In_Call is new Table.Table (
115 Table_Component_Type => Actual_Name,
116 Table_Index_Type => Int,
117 Table_Low_Bound => 0,
119 Table_Increment => 100,
120 Table_Name => "Actuals");
122 -----------------------
123 -- Local Subprograms --
124 -----------------------
126 function Build_Component_Subtype
129 T : Entity_Id) return Node_Id;
130 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
131 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
132 -- Loc is the source location, T is the original subtype.
134 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
135 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
136 -- with discriminants whose default values are static, examine only the
137 -- components in the selected variant to determine whether all of them
140 function Has_Null_Extension (T : Entity_Id) return Boolean;
141 -- T is a derived tagged type. Check whether the type extension is null.
142 -- If the parent type is fully initialized, T can be treated as such.
144 ------------------------------
145 -- Abstract_Interface_List --
146 ------------------------------
148 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
152 if Is_Concurrent_Type (Typ) then
154 -- If we are dealing with a synchronized subtype, go to the base
155 -- type, whose declaration has the interface list.
157 -- Shouldn't this be Declaration_Node???
159 Nod := Parent (Base_Type (Typ));
161 if Nkind (Nod) = N_Full_Type_Declaration then
165 elsif Ekind (Typ) = E_Record_Type_With_Private then
166 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
167 Nod := Type_Definition (Parent (Typ));
169 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
170 if Present (Full_View (Typ))
171 and then Nkind (Parent (Full_View (Typ)))
172 = N_Full_Type_Declaration
174 Nod := Type_Definition (Parent (Full_View (Typ)));
176 -- If the full-view is not available we cannot do anything else
177 -- here (the source has errors).
183 -- Support for generic formals with interfaces is still missing ???
185 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
190 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
194 elsif Ekind (Typ) = E_Record_Subtype then
195 Nod := Type_Definition (Parent (Etype (Typ)));
197 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
199 -- Recurse, because parent may still be a private extension. Also
200 -- note that the full view of the subtype or the full view of its
201 -- base type may (both) be unavailable.
203 return Abstract_Interface_List (Etype (Typ));
205 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
206 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
207 Nod := Formal_Type_Definition (Parent (Typ));
209 Nod := Type_Definition (Parent (Typ));
213 return Interface_List (Nod);
214 end Abstract_Interface_List;
216 --------------------------------
217 -- Add_Access_Type_To_Process --
218 --------------------------------
220 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
224 Ensure_Freeze_Node (E);
225 L := Access_Types_To_Process (Freeze_Node (E));
229 Set_Access_Types_To_Process (Freeze_Node (E), L);
233 end Add_Access_Type_To_Process;
235 ----------------------------
236 -- Add_Global_Declaration --
237 ----------------------------
239 procedure Add_Global_Declaration (N : Node_Id) is
240 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
243 if No (Declarations (Aux_Node)) then
244 Set_Declarations (Aux_Node, New_List);
247 Append_To (Declarations (Aux_Node), N);
249 end Add_Global_Declaration;
255 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
257 function Addressable (V : Uint) return Boolean is
259 return V = Uint_8 or else
265 function Addressable (V : Int) return Boolean is
273 -----------------------
274 -- Alignment_In_Bits --
275 -----------------------
277 function Alignment_In_Bits (E : Entity_Id) return Uint is
279 return Alignment (E) * System_Storage_Unit;
280 end Alignment_In_Bits;
282 -----------------------------------------
283 -- Apply_Compile_Time_Constraint_Error --
284 -----------------------------------------
286 procedure Apply_Compile_Time_Constraint_Error
289 Reason : RT_Exception_Code;
290 Ent : Entity_Id := Empty;
291 Typ : Entity_Id := Empty;
292 Loc : Source_Ptr := No_Location;
293 Rep : Boolean := True;
294 Warn : Boolean := False)
296 Stat : constant Boolean := Is_Static_Expression (N);
297 R_Stat : constant Node_Id :=
298 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
309 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
315 -- Now we replace the node by an N_Raise_Constraint_Error node
316 -- This does not need reanalyzing, so set it as analyzed now.
319 Set_Analyzed (N, True);
322 Set_Raises_Constraint_Error (N);
324 -- Now deal with possible local raise handling
326 Possible_Local_Raise (N, Standard_Constraint_Error);
328 -- If the original expression was marked as static, the result is
329 -- still marked as static, but the Raises_Constraint_Error flag is
330 -- always set so that further static evaluation is not attempted.
333 Set_Is_Static_Expression (N);
335 end Apply_Compile_Time_Constraint_Error;
337 --------------------------------
338 -- Bad_Predicated_Subtype_Use --
339 --------------------------------
341 procedure Bad_Predicated_Subtype_Use
347 if Has_Predicates (Typ) then
348 if Is_Generic_Actual_Type (Typ) then
349 Error_Msg_FE (Msg & '?', N, Typ);
350 Error_Msg_F ("\Program_Error will be raised at run time?", N);
352 Make_Raise_Program_Error (Sloc (N),
353 Reason => PE_Bad_Predicated_Generic_Type));
356 Error_Msg_FE (Msg, N, Typ);
359 end Bad_Predicated_Subtype_Use;
361 --------------------------
362 -- Build_Actual_Subtype --
363 --------------------------
365 function Build_Actual_Subtype
367 N : Node_Or_Entity_Id) return Node_Id
370 -- Normally Sloc (N), but may point to corresponding body in some cases
372 Constraints : List_Id;
378 Disc_Type : Entity_Id;
384 if Nkind (N) = N_Defining_Identifier then
385 Obj := New_Reference_To (N, Loc);
387 -- If this is a formal parameter of a subprogram declaration, and
388 -- we are compiling the body, we want the declaration for the
389 -- actual subtype to carry the source position of the body, to
390 -- prevent anomalies in gdb when stepping through the code.
392 if Is_Formal (N) then
394 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
396 if Nkind (Decl) = N_Subprogram_Declaration
397 and then Present (Corresponding_Body (Decl))
399 Loc := Sloc (Corresponding_Body (Decl));
408 if Is_Array_Type (T) then
409 Constraints := New_List;
410 for J in 1 .. Number_Dimensions (T) loop
412 -- Build an array subtype declaration with the nominal subtype and
413 -- the bounds of the actual. Add the declaration in front of the
414 -- local declarations for the subprogram, for analysis before any
415 -- reference to the formal in the body.
418 Make_Attribute_Reference (Loc,
420 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
421 Attribute_Name => Name_First,
422 Expressions => New_List (
423 Make_Integer_Literal (Loc, J)));
426 Make_Attribute_Reference (Loc,
428 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
429 Attribute_Name => Name_Last,
430 Expressions => New_List (
431 Make_Integer_Literal (Loc, J)));
433 Append (Make_Range (Loc, Lo, Hi), Constraints);
436 -- If the type has unknown discriminants there is no constrained
437 -- subtype to build. This is never called for a formal or for a
438 -- lhs, so returning the type is ok ???
440 elsif Has_Unknown_Discriminants (T) then
444 Constraints := New_List;
446 -- Type T is a generic derived type, inherit the discriminants from
449 if Is_Private_Type (T)
450 and then No (Full_View (T))
452 -- T was flagged as an error if it was declared as a formal
453 -- derived type with known discriminants. In this case there
454 -- is no need to look at the parent type since T already carries
455 -- its own discriminants.
457 and then not Error_Posted (T)
459 Disc_Type := Etype (Base_Type (T));
464 Discr := First_Discriminant (Disc_Type);
465 while Present (Discr) loop
466 Append_To (Constraints,
467 Make_Selected_Component (Loc,
469 Duplicate_Subexpr_No_Checks (Obj),
470 Selector_Name => New_Occurrence_Of (Discr, Loc)));
471 Next_Discriminant (Discr);
475 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
476 Set_Is_Internal (Subt);
479 Make_Subtype_Declaration (Loc,
480 Defining_Identifier => Subt,
481 Subtype_Indication =>
482 Make_Subtype_Indication (Loc,
483 Subtype_Mark => New_Reference_To (T, Loc),
485 Make_Index_Or_Discriminant_Constraint (Loc,
486 Constraints => Constraints)));
488 Mark_Rewrite_Insertion (Decl);
490 end Build_Actual_Subtype;
492 ---------------------------------------
493 -- Build_Actual_Subtype_Of_Component --
494 ---------------------------------------
496 function Build_Actual_Subtype_Of_Component
498 N : Node_Id) return Node_Id
500 Loc : constant Source_Ptr := Sloc (N);
501 P : constant Node_Id := Prefix (N);
504 Index_Typ : Entity_Id;
506 Desig_Typ : Entity_Id;
507 -- This is either a copy of T, or if T is an access type, then it is
508 -- the directly designated type of this access type.
510 function Build_Actual_Array_Constraint return List_Id;
511 -- If one or more of the bounds of the component depends on
512 -- discriminants, build actual constraint using the discriminants
515 function Build_Actual_Record_Constraint return List_Id;
516 -- Similar to previous one, for discriminated components constrained
517 -- by the discriminant of the enclosing object.
519 -----------------------------------
520 -- Build_Actual_Array_Constraint --
521 -----------------------------------
523 function Build_Actual_Array_Constraint return List_Id is
524 Constraints : constant List_Id := New_List;
532 Indx := First_Index (Desig_Typ);
533 while Present (Indx) loop
534 Old_Lo := Type_Low_Bound (Etype (Indx));
535 Old_Hi := Type_High_Bound (Etype (Indx));
537 if Denotes_Discriminant (Old_Lo) then
539 Make_Selected_Component (Loc,
540 Prefix => New_Copy_Tree (P),
541 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
544 Lo := New_Copy_Tree (Old_Lo);
546 -- The new bound will be reanalyzed in the enclosing
547 -- declaration. For literal bounds that come from a type
548 -- declaration, the type of the context must be imposed, so
549 -- insure that analysis will take place. For non-universal
550 -- types this is not strictly necessary.
552 Set_Analyzed (Lo, False);
555 if Denotes_Discriminant (Old_Hi) then
557 Make_Selected_Component (Loc,
558 Prefix => New_Copy_Tree (P),
559 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
562 Hi := New_Copy_Tree (Old_Hi);
563 Set_Analyzed (Hi, False);
566 Append (Make_Range (Loc, Lo, Hi), Constraints);
571 end Build_Actual_Array_Constraint;
573 ------------------------------------
574 -- Build_Actual_Record_Constraint --
575 ------------------------------------
577 function Build_Actual_Record_Constraint return List_Id is
578 Constraints : constant List_Id := New_List;
583 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
584 while Present (D) loop
585 if Denotes_Discriminant (Node (D)) then
586 D_Val := Make_Selected_Component (Loc,
587 Prefix => New_Copy_Tree (P),
588 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
591 D_Val := New_Copy_Tree (Node (D));
594 Append (D_Val, Constraints);
599 end Build_Actual_Record_Constraint;
601 -- Start of processing for Build_Actual_Subtype_Of_Component
604 -- Why the test for Spec_Expression mode here???
606 if In_Spec_Expression then
609 -- More comments for the rest of this body would be good ???
611 elsif Nkind (N) = N_Explicit_Dereference then
612 if Is_Composite_Type (T)
613 and then not Is_Constrained (T)
614 and then not (Is_Class_Wide_Type (T)
615 and then Is_Constrained (Root_Type (T)))
616 and then not Has_Unknown_Discriminants (T)
618 -- If the type of the dereference is already constrained, it is an
621 if Is_Array_Type (Etype (N))
622 and then Is_Constrained (Etype (N))
626 Remove_Side_Effects (P);
627 return Build_Actual_Subtype (T, N);
634 if Ekind (T) = E_Access_Subtype then
635 Desig_Typ := Designated_Type (T);
640 if Ekind (Desig_Typ) = E_Array_Subtype then
641 Id := First_Index (Desig_Typ);
642 while Present (Id) loop
643 Index_Typ := Underlying_Type (Etype (Id));
645 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
647 Denotes_Discriminant (Type_High_Bound (Index_Typ))
649 Remove_Side_Effects (P);
651 Build_Component_Subtype
652 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
658 elsif Is_Composite_Type (Desig_Typ)
659 and then Has_Discriminants (Desig_Typ)
660 and then not Has_Unknown_Discriminants (Desig_Typ)
662 if Is_Private_Type (Desig_Typ)
663 and then No (Discriminant_Constraint (Desig_Typ))
665 Desig_Typ := Full_View (Desig_Typ);
668 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
669 while Present (D) loop
670 if Denotes_Discriminant (Node (D)) then
671 Remove_Side_Effects (P);
673 Build_Component_Subtype (
674 Build_Actual_Record_Constraint, Loc, Base_Type (T));
681 -- If none of the above, the actual and nominal subtypes are the same
684 end Build_Actual_Subtype_Of_Component;
686 -----------------------------
687 -- Build_Component_Subtype --
688 -----------------------------
690 function Build_Component_Subtype
693 T : Entity_Id) return Node_Id
699 -- Unchecked_Union components do not require component subtypes
701 if Is_Unchecked_Union (T) then
705 Subt := Make_Temporary (Loc, 'S');
706 Set_Is_Internal (Subt);
709 Make_Subtype_Declaration (Loc,
710 Defining_Identifier => Subt,
711 Subtype_Indication =>
712 Make_Subtype_Indication (Loc,
713 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
715 Make_Index_Or_Discriminant_Constraint (Loc,
718 Mark_Rewrite_Insertion (Decl);
720 end Build_Component_Subtype;
722 ---------------------------
723 -- Build_Default_Subtype --
724 ---------------------------
726 function Build_Default_Subtype
728 N : Node_Id) return Entity_Id
730 Loc : constant Source_Ptr := Sloc (N);
734 if not Has_Discriminants (T) or else Is_Constrained (T) then
738 Disc := First_Discriminant (T);
740 if No (Discriminant_Default_Value (Disc)) then
745 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
746 Constraints : constant List_Id := New_List;
750 while Present (Disc) loop
751 Append_To (Constraints,
752 New_Copy_Tree (Discriminant_Default_Value (Disc)));
753 Next_Discriminant (Disc);
757 Make_Subtype_Declaration (Loc,
758 Defining_Identifier => Act,
759 Subtype_Indication =>
760 Make_Subtype_Indication (Loc,
761 Subtype_Mark => New_Occurrence_Of (T, Loc),
763 Make_Index_Or_Discriminant_Constraint (Loc,
764 Constraints => Constraints)));
766 Insert_Action (N, Decl);
770 end Build_Default_Subtype;
772 --------------------------------------------
773 -- Build_Discriminal_Subtype_Of_Component --
774 --------------------------------------------
776 function Build_Discriminal_Subtype_Of_Component
777 (T : Entity_Id) return Node_Id
779 Loc : constant Source_Ptr := Sloc (T);
783 function Build_Discriminal_Array_Constraint return List_Id;
784 -- If one or more of the bounds of the component depends on
785 -- discriminants, build actual constraint using the discriminants
788 function Build_Discriminal_Record_Constraint return List_Id;
789 -- Similar to previous one, for discriminated components constrained
790 -- by the discriminant of the enclosing object.
792 ----------------------------------------
793 -- Build_Discriminal_Array_Constraint --
794 ----------------------------------------
796 function Build_Discriminal_Array_Constraint return List_Id is
797 Constraints : constant List_Id := New_List;
805 Indx := First_Index (T);
806 while Present (Indx) loop
807 Old_Lo := Type_Low_Bound (Etype (Indx));
808 Old_Hi := Type_High_Bound (Etype (Indx));
810 if Denotes_Discriminant (Old_Lo) then
811 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
814 Lo := New_Copy_Tree (Old_Lo);
817 if Denotes_Discriminant (Old_Hi) then
818 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
821 Hi := New_Copy_Tree (Old_Hi);
824 Append (Make_Range (Loc, Lo, Hi), Constraints);
829 end Build_Discriminal_Array_Constraint;
831 -----------------------------------------
832 -- Build_Discriminal_Record_Constraint --
833 -----------------------------------------
835 function Build_Discriminal_Record_Constraint return List_Id is
836 Constraints : constant List_Id := New_List;
841 D := First_Elmt (Discriminant_Constraint (T));
842 while Present (D) loop
843 if Denotes_Discriminant (Node (D)) then
845 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
848 D_Val := New_Copy_Tree (Node (D));
851 Append (D_Val, Constraints);
856 end Build_Discriminal_Record_Constraint;
858 -- Start of processing for Build_Discriminal_Subtype_Of_Component
861 if Ekind (T) = E_Array_Subtype then
862 Id := First_Index (T);
863 while Present (Id) loop
864 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
865 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
867 return Build_Component_Subtype
868 (Build_Discriminal_Array_Constraint, Loc, T);
874 elsif Ekind (T) = E_Record_Subtype
875 and then Has_Discriminants (T)
876 and then not Has_Unknown_Discriminants (T)
878 D := First_Elmt (Discriminant_Constraint (T));
879 while Present (D) loop
880 if Denotes_Discriminant (Node (D)) then
881 return Build_Component_Subtype
882 (Build_Discriminal_Record_Constraint, Loc, T);
889 -- If none of the above, the actual and nominal subtypes are the same
892 end Build_Discriminal_Subtype_Of_Component;
894 ------------------------------
895 -- Build_Elaboration_Entity --
896 ------------------------------
898 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
899 Loc : constant Source_Ptr := Sloc (N);
901 Elab_Ent : Entity_Id;
903 procedure Set_Package_Name (Ent : Entity_Id);
904 -- Given an entity, sets the fully qualified name of the entity in
905 -- Name_Buffer, with components separated by double underscores. This
906 -- is a recursive routine that climbs the scope chain to Standard.
908 ----------------------
909 -- Set_Package_Name --
910 ----------------------
912 procedure Set_Package_Name (Ent : Entity_Id) is
914 if Scope (Ent) /= Standard_Standard then
915 Set_Package_Name (Scope (Ent));
918 Nam : constant String := Get_Name_String (Chars (Ent));
920 Name_Buffer (Name_Len + 1) := '_';
921 Name_Buffer (Name_Len + 2) := '_';
922 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
923 Name_Len := Name_Len + Nam'Length + 2;
927 Get_Name_String (Chars (Ent));
929 end Set_Package_Name;
931 -- Start of processing for Build_Elaboration_Entity
934 -- Ignore if already constructed
936 if Present (Elaboration_Entity (Spec_Id)) then
940 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
941 -- name with dots replaced by double underscore. We have to manually
942 -- construct this name, since it will be elaborated in the outer scope,
943 -- and thus will not have the unit name automatically prepended.
945 Set_Package_Name (Spec_Id);
949 Name_Buffer (Name_Len + 1) := '_';
950 Name_Buffer (Name_Len + 2) := 'E';
951 Name_Len := Name_Len + 2;
953 -- Create elaboration counter
955 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
956 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
959 Make_Object_Declaration (Loc,
960 Defining_Identifier => Elab_Ent,
962 New_Occurrence_Of (Standard_Short_Integer, Loc),
963 Expression => Make_Integer_Literal (Loc, Uint_0));
965 Push_Scope (Standard_Standard);
966 Add_Global_Declaration (Decl);
969 -- Reset True_Constant indication, since we will indeed assign a value
970 -- to the variable in the binder main. We also kill the Current_Value
971 -- and Last_Assignment fields for the same reason.
973 Set_Is_True_Constant (Elab_Ent, False);
974 Set_Current_Value (Elab_Ent, Empty);
975 Set_Last_Assignment (Elab_Ent, Empty);
977 -- We do not want any further qualification of the name (if we did
978 -- not do this, we would pick up the name of the generic package
979 -- in the case of a library level generic instantiation).
981 Set_Has_Qualified_Name (Elab_Ent);
982 Set_Has_Fully_Qualified_Name (Elab_Ent);
983 end Build_Elaboration_Entity;
985 -----------------------------------
986 -- Cannot_Raise_Constraint_Error --
987 -----------------------------------
989 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
991 if Compile_Time_Known_Value (Expr) then
994 elsif Do_Range_Check (Expr) then
997 elsif Raises_Constraint_Error (Expr) then
1001 case Nkind (Expr) is
1002 when N_Identifier =>
1005 when N_Expanded_Name =>
1008 when N_Selected_Component =>
1009 return not Do_Discriminant_Check (Expr);
1011 when N_Attribute_Reference =>
1012 if Do_Overflow_Check (Expr) then
1015 elsif No (Expressions (Expr)) then
1023 N := First (Expressions (Expr));
1024 while Present (N) loop
1025 if Cannot_Raise_Constraint_Error (N) then
1036 when N_Type_Conversion =>
1037 if Do_Overflow_Check (Expr)
1038 or else Do_Length_Check (Expr)
1039 or else Do_Tag_Check (Expr)
1044 Cannot_Raise_Constraint_Error (Expression (Expr));
1047 when N_Unchecked_Type_Conversion =>
1048 return Cannot_Raise_Constraint_Error (Expression (Expr));
1051 if Do_Overflow_Check (Expr) then
1055 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1062 if Do_Division_Check (Expr)
1063 or else Do_Overflow_Check (Expr)
1068 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1070 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1089 N_Op_Shift_Right_Arithmetic |
1093 if Do_Overflow_Check (Expr) then
1097 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1099 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1106 end Cannot_Raise_Constraint_Error;
1108 ---------------------------------------
1109 -- Check_Later_Vs_Basic_Declarations --
1110 ---------------------------------------
1112 procedure Check_Later_Vs_Basic_Declarations
1114 During_Parsing : Boolean)
1116 Body_Sloc : Source_Ptr;
1119 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1120 -- Return whether Decl is considered as a declarative item.
1121 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1122 -- When During_Parsing is False, the semantics of SPARK is followed.
1124 -------------------------------
1125 -- Is_Later_Declarative_Item --
1126 -------------------------------
1128 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1130 if Nkind (Decl) in N_Later_Decl_Item then
1133 elsif Nkind (Decl) = N_Pragma then
1136 elsif During_Parsing then
1139 -- In SPARK, a package declaration is not considered as a later
1140 -- declarative item.
1142 elsif Nkind (Decl) = N_Package_Declaration then
1145 -- In SPARK, a renaming is considered as a later declarative item
1147 elsif Nkind (Decl) in N_Renaming_Declaration then
1153 end Is_Later_Declarative_Item;
1155 -- Start of Check_Later_Vs_Basic_Declarations
1158 Decl := First (Decls);
1160 -- Loop through sequence of basic declarative items
1162 Outer : while Present (Decl) loop
1163 if Nkind (Decl) /= N_Subprogram_Body
1164 and then Nkind (Decl) /= N_Package_Body
1165 and then Nkind (Decl) /= N_Task_Body
1166 and then Nkind (Decl) not in N_Body_Stub
1170 -- Once a body is encountered, we only allow later declarative
1171 -- items. The inner loop checks the rest of the list.
1174 Body_Sloc := Sloc (Decl);
1176 Inner : while Present (Decl) loop
1177 if not Is_Later_Declarative_Item (Decl) then
1178 if During_Parsing then
1179 if Ada_Version = Ada_83 then
1180 Error_Msg_Sloc := Body_Sloc;
1182 ("(Ada 83) decl cannot appear after body#", Decl);
1185 Error_Msg_Sloc := Body_Sloc;
1186 Check_SPARK_Restriction
1187 ("decl cannot appear after body#", Decl);
1195 end Check_Later_Vs_Basic_Declarations;
1197 -----------------------------------------
1198 -- Check_Dynamically_Tagged_Expression --
1199 -----------------------------------------
1201 procedure Check_Dynamically_Tagged_Expression
1204 Related_Nod : Node_Id)
1207 pragma Assert (Is_Tagged_Type (Typ));
1209 -- In order to avoid spurious errors when analyzing the expanded code,
1210 -- this check is done only for nodes that come from source and for
1211 -- actuals of generic instantiations.
1213 if (Comes_From_Source (Related_Nod)
1214 or else In_Generic_Actual (Expr))
1215 and then (Is_Class_Wide_Type (Etype (Expr))
1216 or else Is_Dynamically_Tagged (Expr))
1217 and then Is_Tagged_Type (Typ)
1218 and then not Is_Class_Wide_Type (Typ)
1220 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1222 end Check_Dynamically_Tagged_Expression;
1224 --------------------------
1225 -- Check_Fully_Declared --
1226 --------------------------
1228 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1230 if Ekind (T) = E_Incomplete_Type then
1232 -- Ada 2005 (AI-50217): If the type is available through a limited
1233 -- with_clause, verify that its full view has been analyzed.
1235 if From_With_Type (T)
1236 and then Present (Non_Limited_View (T))
1237 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1239 -- The non-limited view is fully declared
1244 ("premature usage of incomplete}", N, First_Subtype (T));
1247 -- Need comments for these tests ???
1249 elsif Has_Private_Component (T)
1250 and then not Is_Generic_Type (Root_Type (T))
1251 and then not In_Spec_Expression
1253 -- Special case: if T is the anonymous type created for a single
1254 -- task or protected object, use the name of the source object.
1256 if Is_Concurrent_Type (T)
1257 and then not Comes_From_Source (T)
1258 and then Nkind (N) = N_Object_Declaration
1260 Error_Msg_NE ("type of& has incomplete component", N,
1261 Defining_Identifier (N));
1265 ("premature usage of incomplete}", N, First_Subtype (T));
1268 end Check_Fully_Declared;
1270 -------------------------
1271 -- Check_Nested_Access --
1272 -------------------------
1274 procedure Check_Nested_Access (Ent : Entity_Id) is
1275 Scop : constant Entity_Id := Current_Scope;
1276 Current_Subp : Entity_Id;
1277 Enclosing : Entity_Id;
1280 -- Currently only enabled for VM back-ends for efficiency, should we
1281 -- enable it more systematically ???
1283 -- Check for Is_Imported needs commenting below ???
1285 if VM_Target /= No_VM
1286 and then (Ekind (Ent) = E_Variable
1288 Ekind (Ent) = E_Constant
1290 Ekind (Ent) = E_Loop_Parameter)
1291 and then Scope (Ent) /= Empty
1292 and then not Is_Library_Level_Entity (Ent)
1293 and then not Is_Imported (Ent)
1295 if Is_Subprogram (Scop)
1296 or else Is_Generic_Subprogram (Scop)
1297 or else Is_Entry (Scop)
1299 Current_Subp := Scop;
1301 Current_Subp := Current_Subprogram;
1304 Enclosing := Enclosing_Subprogram (Ent);
1306 if Enclosing /= Empty
1307 and then Enclosing /= Current_Subp
1309 Set_Has_Up_Level_Access (Ent, True);
1312 end Check_Nested_Access;
1314 ----------------------------
1315 -- Check_Order_Dependence --
1316 ----------------------------
1318 procedure Check_Order_Dependence is
1323 if Ada_Version < Ada_2012 then
1327 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1328 -- calls within a construct have been collected. If one of them is
1329 -- writable and overlaps with another one, evaluation of the enclosing
1330 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1331 -- treated as a warning for now.
1333 for J in 1 .. Actuals_In_Call.Last loop
1334 if Actuals_In_Call.Table (J).Is_Writable then
1335 Act1 := Actuals_In_Call.Table (J).Act;
1337 if Nkind (Act1) = N_Attribute_Reference then
1338 Act1 := Prefix (Act1);
1341 for K in 1 .. Actuals_In_Call.Last loop
1343 Act2 := Actuals_In_Call.Table (K).Act;
1345 if Nkind (Act2) = N_Attribute_Reference then
1346 Act2 := Prefix (Act2);
1349 if Actuals_In_Call.Table (K).Is_Writable
1356 elsif Denotes_Same_Object (Act1, Act2)
1357 and then Parent (Act1) /= Parent (Act2)
1360 ("result may differ if evaluated "
1361 & "after other actual in expression?", Act1);
1368 -- Remove checked actuals from table
1370 Actuals_In_Call.Set_Last (0);
1371 end Check_Order_Dependence;
1373 ------------------------------------------
1374 -- Check_Potentially_Blocking_Operation --
1375 ------------------------------------------
1377 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1381 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1382 -- When pragma Detect_Blocking is active, the run time will raise
1383 -- Program_Error. Here we only issue a warning, since we generally
1384 -- support the use of potentially blocking operations in the absence
1387 -- Indirect blocking through a subprogram call cannot be diagnosed
1388 -- statically without interprocedural analysis, so we do not attempt
1391 S := Scope (Current_Scope);
1392 while Present (S) and then S /= Standard_Standard loop
1393 if Is_Protected_Type (S) then
1395 ("potentially blocking operation in protected operation?", N);
1401 end Check_Potentially_Blocking_Operation;
1403 ------------------------------
1404 -- Check_Unprotected_Access --
1405 ------------------------------
1407 procedure Check_Unprotected_Access
1411 Cont_Encl_Typ : Entity_Id;
1412 Pref_Encl_Typ : Entity_Id;
1414 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1415 -- Check whether Obj is a private component of a protected object.
1416 -- Return the protected type where the component resides, Empty
1419 function Is_Public_Operation return Boolean;
1420 -- Verify that the enclosing operation is callable from outside the
1421 -- protected object, to minimize false positives.
1423 ------------------------------
1424 -- Enclosing_Protected_Type --
1425 ------------------------------
1427 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1429 if Is_Entity_Name (Obj) then
1431 Ent : Entity_Id := Entity (Obj);
1434 -- The object can be a renaming of a private component, use
1435 -- the original record component.
1437 if Is_Prival (Ent) then
1438 Ent := Prival_Link (Ent);
1441 if Is_Protected_Type (Scope (Ent)) then
1447 -- For indexed and selected components, recursively check the prefix
1449 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1450 return Enclosing_Protected_Type (Prefix (Obj));
1452 -- The object does not denote a protected component
1457 end Enclosing_Protected_Type;
1459 -------------------------
1460 -- Is_Public_Operation --
1461 -------------------------
1463 function Is_Public_Operation return Boolean is
1470 and then S /= Pref_Encl_Typ
1472 if Scope (S) = Pref_Encl_Typ then
1473 E := First_Entity (Pref_Encl_Typ);
1475 and then E /= First_Private_Entity (Pref_Encl_Typ)
1488 end Is_Public_Operation;
1490 -- Start of processing for Check_Unprotected_Access
1493 if Nkind (Expr) = N_Attribute_Reference
1494 and then Attribute_Name (Expr) = Name_Unchecked_Access
1496 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1497 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1499 -- Check whether we are trying to export a protected component to a
1500 -- context with an equal or lower access level.
1502 if Present (Pref_Encl_Typ)
1503 and then No (Cont_Encl_Typ)
1504 and then Is_Public_Operation
1505 and then Scope_Depth (Pref_Encl_Typ) >=
1506 Object_Access_Level (Context)
1509 ("?possible unprotected access to protected data", Expr);
1512 end Check_Unprotected_Access;
1518 procedure Check_VMS (Construct : Node_Id) is
1520 if not OpenVMS_On_Target then
1522 ("this construct is allowed only in Open'V'M'S", Construct);
1526 ------------------------
1527 -- Collect_Interfaces --
1528 ------------------------
1530 procedure Collect_Interfaces
1532 Ifaces_List : out Elist_Id;
1533 Exclude_Parents : Boolean := False;
1534 Use_Full_View : Boolean := True)
1536 procedure Collect (Typ : Entity_Id);
1537 -- Subsidiary subprogram used to traverse the whole list
1538 -- of directly and indirectly implemented interfaces
1544 procedure Collect (Typ : Entity_Id) is
1545 Ancestor : Entity_Id;
1553 -- Handle private types
1556 and then Is_Private_Type (Typ)
1557 and then Present (Full_View (Typ))
1559 Full_T := Full_View (Typ);
1562 -- Include the ancestor if we are generating the whole list of
1563 -- abstract interfaces.
1565 if Etype (Full_T) /= Typ
1567 -- Protect the frontend against wrong sources. For example:
1570 -- type A is tagged null record;
1571 -- type B is new A with private;
1572 -- type C is new A with private;
1574 -- type B is new C with null record;
1575 -- type C is new B with null record;
1578 and then Etype (Full_T) /= T
1580 Ancestor := Etype (Full_T);
1583 if Is_Interface (Ancestor)
1584 and then not Exclude_Parents
1586 Append_Unique_Elmt (Ancestor, Ifaces_List);
1590 -- Traverse the graph of ancestor interfaces
1592 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1593 Id := First (Abstract_Interface_List (Full_T));
1594 while Present (Id) loop
1595 Iface := Etype (Id);
1597 -- Protect against wrong uses. For example:
1598 -- type I is interface;
1599 -- type O is tagged null record;
1600 -- type Wrong is new I and O with null record; -- ERROR
1602 if Is_Interface (Iface) then
1604 and then Etype (T) /= T
1605 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1610 Append_Unique_Elmt (Iface, Ifaces_List);
1619 -- Start of processing for Collect_Interfaces
1622 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1623 Ifaces_List := New_Elmt_List;
1625 end Collect_Interfaces;
1627 ----------------------------------
1628 -- Collect_Interface_Components --
1629 ----------------------------------
1631 procedure Collect_Interface_Components
1632 (Tagged_Type : Entity_Id;
1633 Components_List : out Elist_Id)
1635 procedure Collect (Typ : Entity_Id);
1636 -- Subsidiary subprogram used to climb to the parents
1642 procedure Collect (Typ : Entity_Id) is
1643 Tag_Comp : Entity_Id;
1644 Parent_Typ : Entity_Id;
1647 -- Handle private types
1649 if Present (Full_View (Etype (Typ))) then
1650 Parent_Typ := Full_View (Etype (Typ));
1652 Parent_Typ := Etype (Typ);
1655 if Parent_Typ /= Typ
1657 -- Protect the frontend against wrong sources. For example:
1660 -- type A is tagged null record;
1661 -- type B is new A with private;
1662 -- type C is new A with private;
1664 -- type B is new C with null record;
1665 -- type C is new B with null record;
1668 and then Parent_Typ /= Tagged_Type
1670 Collect (Parent_Typ);
1673 -- Collect the components containing tags of secondary dispatch
1676 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1677 while Present (Tag_Comp) loop
1678 pragma Assert (Present (Related_Type (Tag_Comp)));
1679 Append_Elmt (Tag_Comp, Components_List);
1681 Tag_Comp := Next_Tag_Component (Tag_Comp);
1685 -- Start of processing for Collect_Interface_Components
1688 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1689 and then Is_Tagged_Type (Tagged_Type));
1691 Components_List := New_Elmt_List;
1692 Collect (Tagged_Type);
1693 end Collect_Interface_Components;
1695 -----------------------------
1696 -- Collect_Interfaces_Info --
1697 -----------------------------
1699 procedure Collect_Interfaces_Info
1701 Ifaces_List : out Elist_Id;
1702 Components_List : out Elist_Id;
1703 Tags_List : out Elist_Id)
1705 Comps_List : Elist_Id;
1706 Comp_Elmt : Elmt_Id;
1707 Comp_Iface : Entity_Id;
1708 Iface_Elmt : Elmt_Id;
1711 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1712 -- Search for the secondary tag associated with the interface type
1713 -- Iface that is implemented by T.
1719 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1722 if not Is_CPP_Class (T) then
1723 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1725 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1729 and then Is_Tag (Node (ADT))
1730 and then Related_Type (Node (ADT)) /= Iface
1732 -- Skip secondary dispatch table referencing thunks to user
1733 -- defined primitives covered by this interface.
1735 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1738 -- Skip secondary dispatch tables of Ada types
1740 if not Is_CPP_Class (T) then
1742 -- Skip secondary dispatch table referencing thunks to
1743 -- predefined primitives.
1745 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1748 -- Skip secondary dispatch table referencing user-defined
1749 -- primitives covered by this interface.
1751 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1754 -- Skip secondary dispatch table referencing predefined
1757 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1762 pragma Assert (Is_Tag (Node (ADT)));
1766 -- Start of processing for Collect_Interfaces_Info
1769 Collect_Interfaces (T, Ifaces_List);
1770 Collect_Interface_Components (T, Comps_List);
1772 -- Search for the record component and tag associated with each
1773 -- interface type of T.
1775 Components_List := New_Elmt_List;
1776 Tags_List := New_Elmt_List;
1778 Iface_Elmt := First_Elmt (Ifaces_List);
1779 while Present (Iface_Elmt) loop
1780 Iface := Node (Iface_Elmt);
1782 -- Associate the primary tag component and the primary dispatch table
1783 -- with all the interfaces that are parents of T
1785 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1786 Append_Elmt (First_Tag_Component (T), Components_List);
1787 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1789 -- Otherwise search for the tag component and secondary dispatch
1793 Comp_Elmt := First_Elmt (Comps_List);
1794 while Present (Comp_Elmt) loop
1795 Comp_Iface := Related_Type (Node (Comp_Elmt));
1797 if Comp_Iface = Iface
1798 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1800 Append_Elmt (Node (Comp_Elmt), Components_List);
1801 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1805 Next_Elmt (Comp_Elmt);
1807 pragma Assert (Present (Comp_Elmt));
1810 Next_Elmt (Iface_Elmt);
1812 end Collect_Interfaces_Info;
1814 ---------------------
1815 -- Collect_Parents --
1816 ---------------------
1818 procedure Collect_Parents
1820 List : out Elist_Id;
1821 Use_Full_View : Boolean := True)
1823 Current_Typ : Entity_Id := T;
1824 Parent_Typ : Entity_Id;
1827 List := New_Elmt_List;
1829 -- No action if the if the type has no parents
1831 if T = Etype (T) then
1836 Parent_Typ := Etype (Current_Typ);
1838 if Is_Private_Type (Parent_Typ)
1839 and then Present (Full_View (Parent_Typ))
1840 and then Use_Full_View
1842 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1845 Append_Elmt (Parent_Typ, List);
1847 exit when Parent_Typ = Current_Typ;
1848 Current_Typ := Parent_Typ;
1850 end Collect_Parents;
1852 ----------------------------------
1853 -- Collect_Primitive_Operations --
1854 ----------------------------------
1856 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1857 B_Type : constant Entity_Id := Base_Type (T);
1858 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1859 B_Scope : Entity_Id := Scope (B_Type);
1863 Formal_Derived : Boolean := False;
1866 function Match (E : Entity_Id) return Boolean;
1867 -- True if E's base type is B_Type, or E is of an anonymous access type
1868 -- and the base type of its designated type is B_Type.
1874 function Match (E : Entity_Id) return Boolean is
1875 Etyp : Entity_Id := Etype (E);
1878 if Ekind (Etyp) = E_Anonymous_Access_Type then
1879 Etyp := Designated_Type (Etyp);
1882 return Base_Type (Etyp) = B_Type;
1885 -- Start of processing for Collect_Primitive_Operations
1888 -- For tagged types, the primitive operations are collected as they
1889 -- are declared, and held in an explicit list which is simply returned.
1891 if Is_Tagged_Type (B_Type) then
1892 return Primitive_Operations (B_Type);
1894 -- An untagged generic type that is a derived type inherits the
1895 -- primitive operations of its parent type. Other formal types only
1896 -- have predefined operators, which are not explicitly represented.
1898 elsif Is_Generic_Type (B_Type) then
1899 if Nkind (B_Decl) = N_Formal_Type_Declaration
1900 and then Nkind (Formal_Type_Definition (B_Decl))
1901 = N_Formal_Derived_Type_Definition
1903 Formal_Derived := True;
1905 return New_Elmt_List;
1909 Op_List := New_Elmt_List;
1911 if B_Scope = Standard_Standard then
1912 if B_Type = Standard_String then
1913 Append_Elmt (Standard_Op_Concat, Op_List);
1915 elsif B_Type = Standard_Wide_String then
1916 Append_Elmt (Standard_Op_Concatw, Op_List);
1922 elsif (Is_Package_Or_Generic_Package (B_Scope)
1924 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1926 or else Is_Derived_Type (B_Type)
1928 -- The primitive operations appear after the base type, except
1929 -- if the derivation happens within the private part of B_Scope
1930 -- and the type is a private type, in which case both the type
1931 -- and some primitive operations may appear before the base
1932 -- type, and the list of candidates starts after the type.
1934 if In_Open_Scopes (B_Scope)
1935 and then Scope (T) = B_Scope
1936 and then In_Private_Part (B_Scope)
1938 Id := Next_Entity (T);
1940 Id := Next_Entity (B_Type);
1943 while Present (Id) loop
1945 -- Note that generic formal subprograms are not
1946 -- considered to be primitive operations and thus
1947 -- are never inherited.
1949 if Is_Overloadable (Id)
1950 and then Nkind (Parent (Parent (Id)))
1951 not in N_Formal_Subprogram_Declaration
1959 Formal := First_Formal (Id);
1960 while Present (Formal) loop
1961 if Match (Formal) then
1966 Next_Formal (Formal);
1970 -- For a formal derived type, the only primitives are the
1971 -- ones inherited from the parent type. Operations appearing
1972 -- in the package declaration are not primitive for it.
1975 and then (not Formal_Derived
1976 or else Present (Alias (Id)))
1978 -- In the special case of an equality operator aliased to
1979 -- an overriding dispatching equality belonging to the same
1980 -- type, we don't include it in the list of primitives.
1981 -- This avoids inheriting multiple equality operators when
1982 -- deriving from untagged private types whose full type is
1983 -- tagged, which can otherwise cause ambiguities. Note that
1984 -- this should only happen for this kind of untagged parent
1985 -- type, since normally dispatching operations are inherited
1986 -- using the type's Primitive_Operations list.
1988 if Chars (Id) = Name_Op_Eq
1989 and then Is_Dispatching_Operation (Id)
1990 and then Present (Alias (Id))
1991 and then Present (Overridden_Operation (Alias (Id)))
1992 and then Base_Type (Etype (First_Entity (Id))) =
1993 Base_Type (Etype (First_Entity (Alias (Id))))
1997 -- Include the subprogram in the list of primitives
2000 Append_Elmt (Id, Op_List);
2007 -- For a type declared in System, some of its operations may
2008 -- appear in the target-specific extension to System.
2011 and then B_Scope = RTU_Entity (System)
2012 and then Present_System_Aux
2014 B_Scope := System_Aux_Id;
2015 Id := First_Entity (System_Aux_Id);
2021 end Collect_Primitive_Operations;
2023 -----------------------------------
2024 -- Compile_Time_Constraint_Error --
2025 -----------------------------------
2027 function Compile_Time_Constraint_Error
2030 Ent : Entity_Id := Empty;
2031 Loc : Source_Ptr := No_Location;
2032 Warn : Boolean := False) return Node_Id
2034 Msgc : String (1 .. Msg'Length + 2);
2035 -- Copy of message, with room for possible ? and ! at end
2045 -- A static constraint error in an instance body is not a fatal error.
2046 -- we choose to inhibit the message altogether, because there is no
2047 -- obvious node (for now) on which to post it. On the other hand the
2048 -- offending node must be replaced with a constraint_error in any case.
2050 -- No messages are generated if we already posted an error on this node
2052 if not Error_Posted (N) then
2053 if Loc /= No_Location then
2059 Msgc (1 .. Msg'Length) := Msg;
2062 -- Message is a warning, even in Ada 95 case
2064 if Msg (Msg'Last) = '?' then
2067 -- In Ada 83, all messages are warnings. In the private part and
2068 -- the body of an instance, constraint_checks are only warnings.
2069 -- We also make this a warning if the Warn parameter is set.
2072 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2078 elsif In_Instance_Not_Visible then
2083 -- Otherwise we have a real error message (Ada 95 static case)
2084 -- and we make this an unconditional message. Note that in the
2085 -- warning case we do not make the message unconditional, it seems
2086 -- quite reasonable to delete messages like this (about exceptions
2087 -- that will be raised) in dead code.
2095 -- Should we generate a warning? The answer is not quite yes. The
2096 -- very annoying exception occurs in the case of a short circuit
2097 -- operator where the left operand is static and decisive. Climb
2098 -- parents to see if that is the case we have here. Conditional
2099 -- expressions with decisive conditions are a similar situation.
2107 -- And then with False as left operand
2109 if Nkind (P) = N_And_Then
2110 and then Compile_Time_Known_Value (Left_Opnd (P))
2111 and then Is_False (Expr_Value (Left_Opnd (P)))
2116 -- OR ELSE with True as left operand
2118 elsif Nkind (P) = N_Or_Else
2119 and then Compile_Time_Known_Value (Left_Opnd (P))
2120 and then Is_True (Expr_Value (Left_Opnd (P)))
2125 -- Conditional expression
2127 elsif Nkind (P) = N_Conditional_Expression then
2129 Cond : constant Node_Id := First (Expressions (P));
2130 Texp : constant Node_Id := Next (Cond);
2131 Fexp : constant Node_Id := Next (Texp);
2134 if Compile_Time_Known_Value (Cond) then
2136 -- Condition is True and we are in the right operand
2138 if Is_True (Expr_Value (Cond))
2139 and then OldP = Fexp
2144 -- Condition is False and we are in the left operand
2146 elsif Is_False (Expr_Value (Cond))
2147 and then OldP = Texp
2155 -- Special case for component association in aggregates, where
2156 -- we want to keep climbing up to the parent aggregate.
2158 elsif Nkind (P) = N_Component_Association
2159 and then Nkind (Parent (P)) = N_Aggregate
2163 -- Keep going if within subexpression
2166 exit when Nkind (P) not in N_Subexpr;
2171 if Present (Ent) then
2172 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2174 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2178 if Inside_Init_Proc then
2180 ("\?& will be raised for objects of this type",
2181 N, Standard_Constraint_Error, Eloc);
2184 ("\?& will be raised at run time",
2185 N, Standard_Constraint_Error, Eloc);
2190 ("\static expression fails Constraint_Check", Eloc);
2191 Set_Error_Posted (N);
2197 end Compile_Time_Constraint_Error;
2199 -----------------------
2200 -- Conditional_Delay --
2201 -----------------------
2203 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2205 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2206 Set_Has_Delayed_Freeze (New_Ent);
2208 end Conditional_Delay;
2210 -------------------------
2211 -- Copy_Parameter_List --
2212 -------------------------
2214 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2215 Loc : constant Source_Ptr := Sloc (Subp_Id);
2220 if No (First_Formal (Subp_Id)) then
2224 Formal := First_Formal (Subp_Id);
2225 while Present (Formal) loop
2227 (Make_Parameter_Specification (Loc,
2228 Defining_Identifier =>
2229 Make_Defining_Identifier (Sloc (Formal),
2230 Chars => Chars (Formal)),
2231 In_Present => In_Present (Parent (Formal)),
2232 Out_Present => Out_Present (Parent (Formal)),
2234 New_Reference_To (Etype (Formal), Loc),
2236 New_Copy_Tree (Expression (Parent (Formal)))),
2239 Next_Formal (Formal);
2244 end Copy_Parameter_List;
2246 --------------------
2247 -- Current_Entity --
2248 --------------------
2250 -- The currently visible definition for a given identifier is the
2251 -- one most chained at the start of the visibility chain, i.e. the
2252 -- one that is referenced by the Node_Id value of the name of the
2253 -- given identifier.
2255 function Current_Entity (N : Node_Id) return Entity_Id is
2257 return Get_Name_Entity_Id (Chars (N));
2260 -----------------------------
2261 -- Current_Entity_In_Scope --
2262 -----------------------------
2264 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2266 CS : constant Entity_Id := Current_Scope;
2268 Transient_Case : constant Boolean := Scope_Is_Transient;
2271 E := Get_Name_Entity_Id (Chars (N));
2273 and then Scope (E) /= CS
2274 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2280 end Current_Entity_In_Scope;
2286 function Current_Scope return Entity_Id is
2288 if Scope_Stack.Last = -1 then
2289 return Standard_Standard;
2292 C : constant Entity_Id :=
2293 Scope_Stack.Table (Scope_Stack.Last).Entity;
2298 return Standard_Standard;
2304 ------------------------
2305 -- Current_Subprogram --
2306 ------------------------
2308 function Current_Subprogram return Entity_Id is
2309 Scop : constant Entity_Id := Current_Scope;
2311 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2314 return Enclosing_Subprogram (Scop);
2316 end Current_Subprogram;
2318 ---------------------
2319 -- Defining_Entity --
2320 ---------------------
2322 function Defining_Entity (N : Node_Id) return Entity_Id is
2323 K : constant Node_Kind := Nkind (N);
2324 Err : Entity_Id := Empty;
2329 N_Subprogram_Declaration |
2330 N_Abstract_Subprogram_Declaration |
2332 N_Package_Declaration |
2333 N_Subprogram_Renaming_Declaration |
2334 N_Subprogram_Body_Stub |
2335 N_Generic_Subprogram_Declaration |
2336 N_Generic_Package_Declaration |
2337 N_Formal_Subprogram_Declaration
2339 return Defining_Entity (Specification (N));
2342 N_Component_Declaration |
2343 N_Defining_Program_Unit_Name |
2344 N_Discriminant_Specification |
2346 N_Entry_Declaration |
2347 N_Entry_Index_Specification |
2348 N_Exception_Declaration |
2349 N_Exception_Renaming_Declaration |
2350 N_Formal_Object_Declaration |
2351 N_Formal_Package_Declaration |
2352 N_Formal_Type_Declaration |
2353 N_Full_Type_Declaration |
2354 N_Implicit_Label_Declaration |
2355 N_Incomplete_Type_Declaration |
2356 N_Loop_Parameter_Specification |
2357 N_Number_Declaration |
2358 N_Object_Declaration |
2359 N_Object_Renaming_Declaration |
2360 N_Package_Body_Stub |
2361 N_Parameter_Specification |
2362 N_Private_Extension_Declaration |
2363 N_Private_Type_Declaration |
2365 N_Protected_Body_Stub |
2366 N_Protected_Type_Declaration |
2367 N_Single_Protected_Declaration |
2368 N_Single_Task_Declaration |
2369 N_Subtype_Declaration |
2372 N_Task_Type_Declaration
2374 return Defining_Identifier (N);
2377 return Defining_Entity (Proper_Body (N));
2380 N_Function_Instantiation |
2381 N_Function_Specification |
2382 N_Generic_Function_Renaming_Declaration |
2383 N_Generic_Package_Renaming_Declaration |
2384 N_Generic_Procedure_Renaming_Declaration |
2386 N_Package_Instantiation |
2387 N_Package_Renaming_Declaration |
2388 N_Package_Specification |
2389 N_Procedure_Instantiation |
2390 N_Procedure_Specification
2393 Nam : constant Node_Id := Defining_Unit_Name (N);
2396 if Nkind (Nam) in N_Entity then
2399 -- For Error, make up a name and attach to declaration
2400 -- so we can continue semantic analysis
2402 elsif Nam = Error then
2403 Err := Make_Temporary (Sloc (N), 'T');
2404 Set_Defining_Unit_Name (N, Err);
2407 -- If not an entity, get defining identifier
2410 return Defining_Identifier (Nam);
2414 when N_Block_Statement =>
2415 return Entity (Identifier (N));
2418 raise Program_Error;
2421 end Defining_Entity;
2423 --------------------------
2424 -- Denotes_Discriminant --
2425 --------------------------
2427 function Denotes_Discriminant
2429 Check_Concurrent : Boolean := False) return Boolean
2433 if not Is_Entity_Name (N)
2434 or else No (Entity (N))
2441 -- If we are checking for a protected type, the discriminant may have
2442 -- been rewritten as the corresponding discriminal of the original type
2443 -- or of the corresponding concurrent record, depending on whether we
2444 -- are in the spec or body of the protected type.
2446 return Ekind (E) = E_Discriminant
2449 and then Ekind (E) = E_In_Parameter
2450 and then Present (Discriminal_Link (E))
2452 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2454 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2456 end Denotes_Discriminant;
2458 -------------------------
2459 -- Denotes_Same_Object --
2460 -------------------------
2462 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2463 Obj1 : Node_Id := A1;
2464 Obj2 : Node_Id := A2;
2466 procedure Check_Renaming (Obj : in out Node_Id);
2467 -- If an object is a renaming, examine renamed object. If it is a
2468 -- dereference of a variable, or an indexed expression with non-constant
2469 -- indexes, no overlap check can be reported.
2471 --------------------
2472 -- Check_Renaming --
2473 --------------------
2475 procedure Check_Renaming (Obj : in out Node_Id) is
2477 if Is_Entity_Name (Obj)
2478 and then Present (Renamed_Entity (Entity (Obj)))
2480 Obj := Renamed_Entity (Entity (Obj));
2481 if Nkind (Obj) = N_Explicit_Dereference
2482 and then Is_Variable (Prefix (Obj))
2486 elsif Nkind (Obj) = N_Indexed_Component then
2491 Indx := First (Expressions (Obj));
2492 while Present (Indx) loop
2493 if not Is_OK_Static_Expression (Indx) then
2505 -- Start of processing for Denotes_Same_Object
2508 Check_Renaming (Obj1);
2509 Check_Renaming (Obj2);
2517 -- If we have entity names, then must be same entity
2519 if Is_Entity_Name (Obj1) then
2520 if Is_Entity_Name (Obj2) then
2521 return Entity (Obj1) = Entity (Obj2);
2526 -- No match if not same node kind
2528 elsif Nkind (Obj1) /= Nkind (Obj2) then
2531 -- For selected components, must have same prefix and selector
2533 elsif Nkind (Obj1) = N_Selected_Component then
2534 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2536 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2538 -- For explicit dereferences, prefixes must be same
2540 elsif Nkind (Obj1) = N_Explicit_Dereference then
2541 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2543 -- For indexed components, prefixes and all subscripts must be the same
2545 elsif Nkind (Obj1) = N_Indexed_Component then
2546 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2552 Indx1 := First (Expressions (Obj1));
2553 Indx2 := First (Expressions (Obj2));
2554 while Present (Indx1) loop
2556 -- Indexes must denote the same static value or same object
2558 if Is_OK_Static_Expression (Indx1) then
2559 if not Is_OK_Static_Expression (Indx2) then
2562 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2566 elsif not Denotes_Same_Object (Indx1, Indx2) then
2580 -- For slices, prefixes must match and bounds must match
2582 elsif Nkind (Obj1) = N_Slice
2583 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2586 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2589 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2590 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2592 -- Check whether bounds are statically identical. There is no
2593 -- attempt to detect partial overlap of slices.
2595 return Denotes_Same_Object (Lo1, Lo2)
2596 and then Denotes_Same_Object (Hi1, Hi2);
2599 -- Literals will appear as indexes. Isn't this where we should check
2600 -- Known_At_Compile_Time at least if we are generating warnings ???
2602 elsif Nkind (Obj1) = N_Integer_Literal then
2603 return Intval (Obj1) = Intval (Obj2);
2608 end Denotes_Same_Object;
2610 -------------------------
2611 -- Denotes_Same_Prefix --
2612 -------------------------
2614 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2617 if Is_Entity_Name (A1) then
2618 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2619 and then not Is_Access_Type (Etype (A1))
2621 return Denotes_Same_Object (A1, Prefix (A2))
2622 or else Denotes_Same_Prefix (A1, Prefix (A2));
2627 elsif Is_Entity_Name (A2) then
2628 return Denotes_Same_Prefix (A2, A1);
2630 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2632 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2635 Root1, Root2 : Node_Id;
2636 Depth1, Depth2 : Int := 0;
2639 Root1 := Prefix (A1);
2640 while not Is_Entity_Name (Root1) loop
2642 (Root1, N_Selected_Component, N_Indexed_Component)
2646 Root1 := Prefix (Root1);
2649 Depth1 := Depth1 + 1;
2652 Root2 := Prefix (A2);
2653 while not Is_Entity_Name (Root2) loop
2655 (Root2, N_Selected_Component, N_Indexed_Component)
2659 Root2 := Prefix (Root2);
2662 Depth2 := Depth2 + 1;
2665 -- If both have the same depth and they do not denote the same
2666 -- object, they are disjoint and not warning is needed.
2668 if Depth1 = Depth2 then
2671 elsif Depth1 > Depth2 then
2672 Root1 := Prefix (A1);
2673 for I in 1 .. Depth1 - Depth2 - 1 loop
2674 Root1 := Prefix (Root1);
2677 return Denotes_Same_Object (Root1, A2);
2680 Root2 := Prefix (A2);
2681 for I in 1 .. Depth2 - Depth1 - 1 loop
2682 Root2 := Prefix (Root2);
2685 return Denotes_Same_Object (A1, Root2);
2692 end Denotes_Same_Prefix;
2694 ----------------------
2695 -- Denotes_Variable --
2696 ----------------------
2698 function Denotes_Variable (N : Node_Id) return Boolean is
2700 return Is_Variable (N) and then Paren_Count (N) = 0;
2701 end Denotes_Variable;
2703 -----------------------------
2704 -- Depends_On_Discriminant --
2705 -----------------------------
2707 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2712 Get_Index_Bounds (N, L, H);
2713 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2714 end Depends_On_Discriminant;
2716 -------------------------
2717 -- Designate_Same_Unit --
2718 -------------------------
2720 function Designate_Same_Unit
2722 Name2 : Node_Id) return Boolean
2724 K1 : constant Node_Kind := Nkind (Name1);
2725 K2 : constant Node_Kind := Nkind (Name2);
2727 function Prefix_Node (N : Node_Id) return Node_Id;
2728 -- Returns the parent unit name node of a defining program unit name
2729 -- or the prefix if N is a selected component or an expanded name.
2731 function Select_Node (N : Node_Id) return Node_Id;
2732 -- Returns the defining identifier node of a defining program unit
2733 -- name or the selector node if N is a selected component or an
2740 function Prefix_Node (N : Node_Id) return Node_Id is
2742 if Nkind (N) = N_Defining_Program_Unit_Name then
2754 function Select_Node (N : Node_Id) return Node_Id is
2756 if Nkind (N) = N_Defining_Program_Unit_Name then
2757 return Defining_Identifier (N);
2760 return Selector_Name (N);
2764 -- Start of processing for Designate_Next_Unit
2767 if (K1 = N_Identifier or else
2768 K1 = N_Defining_Identifier)
2770 (K2 = N_Identifier or else
2771 K2 = N_Defining_Identifier)
2773 return Chars (Name1) = Chars (Name2);
2776 (K1 = N_Expanded_Name or else
2777 K1 = N_Selected_Component or else
2778 K1 = N_Defining_Program_Unit_Name)
2780 (K2 = N_Expanded_Name or else
2781 K2 = N_Selected_Component or else
2782 K2 = N_Defining_Program_Unit_Name)
2785 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2787 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2792 end Designate_Same_Unit;
2794 --------------------------
2795 -- Enclosing_CPP_Parent --
2796 --------------------------
2798 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2799 Parent_Typ : Entity_Id := Typ;
2802 while not Is_CPP_Class (Parent_Typ)
2803 and then Etype (Parent_Typ) /= Parent_Typ
2805 Parent_Typ := Etype (Parent_Typ);
2807 if Is_Private_Type (Parent_Typ) then
2808 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2812 pragma Assert (Is_CPP_Class (Parent_Typ));
2814 end Enclosing_CPP_Parent;
2816 ----------------------------
2817 -- Enclosing_Generic_Body --
2818 ----------------------------
2820 function Enclosing_Generic_Body
2821 (N : Node_Id) return Node_Id
2829 while Present (P) loop
2830 if Nkind (P) = N_Package_Body
2831 or else Nkind (P) = N_Subprogram_Body
2833 Spec := Corresponding_Spec (P);
2835 if Present (Spec) then
2836 Decl := Unit_Declaration_Node (Spec);
2838 if Nkind (Decl) = N_Generic_Package_Declaration
2839 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2850 end Enclosing_Generic_Body;
2852 ----------------------------
2853 -- Enclosing_Generic_Unit --
2854 ----------------------------
2856 function Enclosing_Generic_Unit
2857 (N : Node_Id) return Node_Id
2865 while Present (P) loop
2866 if Nkind (P) = N_Generic_Package_Declaration
2867 or else Nkind (P) = N_Generic_Subprogram_Declaration
2871 elsif Nkind (P) = N_Package_Body
2872 or else Nkind (P) = N_Subprogram_Body
2874 Spec := Corresponding_Spec (P);
2876 if Present (Spec) then
2877 Decl := Unit_Declaration_Node (Spec);
2879 if Nkind (Decl) = N_Generic_Package_Declaration
2880 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2891 end Enclosing_Generic_Unit;
2893 -------------------------------
2894 -- Enclosing_Lib_Unit_Entity --
2895 -------------------------------
2897 function Enclosing_Lib_Unit_Entity return Entity_Id is
2898 Unit_Entity : Entity_Id;
2901 -- Look for enclosing library unit entity by following scope links.
2902 -- Equivalent to, but faster than indexing through the scope stack.
2904 Unit_Entity := Current_Scope;
2905 while (Present (Scope (Unit_Entity))
2906 and then Scope (Unit_Entity) /= Standard_Standard)
2907 and not Is_Child_Unit (Unit_Entity)
2909 Unit_Entity := Scope (Unit_Entity);
2913 end Enclosing_Lib_Unit_Entity;
2915 -----------------------------
2916 -- Enclosing_Lib_Unit_Node --
2917 -----------------------------
2919 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2920 Current_Node : Node_Id;
2924 while Present (Current_Node)
2925 and then Nkind (Current_Node) /= N_Compilation_Unit
2927 Current_Node := Parent (Current_Node);
2930 if Nkind (Current_Node) /= N_Compilation_Unit then
2934 return Current_Node;
2935 end Enclosing_Lib_Unit_Node;
2937 -----------------------
2938 -- Enclosing_Package --
2939 -----------------------
2941 function Enclosing_Package (E : Entity_Id) return Entity_Id is
2942 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2945 if Dynamic_Scope = Standard_Standard then
2946 return Standard_Standard;
2948 elsif Dynamic_Scope = Empty then
2951 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
2954 return Dynamic_Scope;
2957 return Enclosing_Package (Dynamic_Scope);
2959 end Enclosing_Package;
2961 --------------------------
2962 -- Enclosing_Subprogram --
2963 --------------------------
2965 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2966 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2969 if Dynamic_Scope = Standard_Standard then
2972 elsif Dynamic_Scope = Empty then
2975 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2976 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2978 elsif Ekind (Dynamic_Scope) = E_Block
2979 or else Ekind (Dynamic_Scope) = E_Return_Statement
2981 return Enclosing_Subprogram (Dynamic_Scope);
2983 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2984 return Get_Task_Body_Procedure (Dynamic_Scope);
2986 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2987 and then Present (Full_View (Dynamic_Scope))
2988 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2990 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2992 -- No body is generated if the protected operation is eliminated
2994 elsif Convention (Dynamic_Scope) = Convention_Protected
2995 and then not Is_Eliminated (Dynamic_Scope)
2996 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2998 return Protected_Body_Subprogram (Dynamic_Scope);
3001 return Dynamic_Scope;
3003 end Enclosing_Subprogram;
3005 ------------------------
3006 -- Ensure_Freeze_Node --
3007 ------------------------
3009 procedure Ensure_Freeze_Node (E : Entity_Id) is
3013 if No (Freeze_Node (E)) then
3014 FN := Make_Freeze_Entity (Sloc (E));
3015 Set_Has_Delayed_Freeze (E);
3016 Set_Freeze_Node (E, FN);
3017 Set_Access_Types_To_Process (FN, No_Elist);
3018 Set_TSS_Elist (FN, No_Elist);
3021 end Ensure_Freeze_Node;
3027 procedure Enter_Name (Def_Id : Entity_Id) is
3028 C : constant Entity_Id := Current_Entity (Def_Id);
3029 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3030 S : constant Entity_Id := Current_Scope;
3033 Generate_Definition (Def_Id);
3035 -- Add new name to current scope declarations. Check for duplicate
3036 -- declaration, which may or may not be a genuine error.
3040 -- Case of previous entity entered because of a missing declaration
3041 -- or else a bad subtype indication. Best is to use the new entity,
3042 -- and make the previous one invisible.
3044 if Etype (E) = Any_Type then
3045 Set_Is_Immediately_Visible (E, False);
3047 -- Case of renaming declaration constructed for package instances.
3048 -- if there is an explicit declaration with the same identifier,
3049 -- the renaming is not immediately visible any longer, but remains
3050 -- visible through selected component notation.
3052 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3053 and then not Comes_From_Source (E)
3055 Set_Is_Immediately_Visible (E, False);
3057 -- The new entity may be the package renaming, which has the same
3058 -- same name as a generic formal which has been seen already.
3060 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3061 and then not Comes_From_Source (Def_Id)
3063 Set_Is_Immediately_Visible (E, False);
3065 -- For a fat pointer corresponding to a remote access to subprogram,
3066 -- we use the same identifier as the RAS type, so that the proper
3067 -- name appears in the stub. This type is only retrieved through
3068 -- the RAS type and never by visibility, and is not added to the
3069 -- visibility list (see below).
3071 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3072 and then Present (Corresponding_Remote_Type (Def_Id))
3076 -- Case of an implicit operation or derived literal. The new entity
3077 -- hides the implicit one, which is removed from all visibility,
3078 -- i.e. the entity list of its scope, and homonym chain of its name.
3080 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3081 or else Is_Internal (E)
3085 Prev_Vis : Entity_Id;
3086 Decl : constant Node_Id := Parent (E);
3089 -- If E is an implicit declaration, it cannot be the first
3090 -- entity in the scope.
3092 Prev := First_Entity (Current_Scope);
3093 while Present (Prev)
3094 and then Next_Entity (Prev) /= E
3101 -- If E is not on the entity chain of the current scope,
3102 -- it is an implicit declaration in the generic formal
3103 -- part of a generic subprogram. When analyzing the body,
3104 -- the generic formals are visible but not on the entity
3105 -- chain of the subprogram. The new entity will become
3106 -- the visible one in the body.
3109 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3113 Set_Next_Entity (Prev, Next_Entity (E));
3115 if No (Next_Entity (Prev)) then
3116 Set_Last_Entity (Current_Scope, Prev);
3119 if E = Current_Entity (E) then
3123 Prev_Vis := Current_Entity (E);
3124 while Homonym (Prev_Vis) /= E loop
3125 Prev_Vis := Homonym (Prev_Vis);
3129 if Present (Prev_Vis) then
3131 -- Skip E in the visibility chain
3133 Set_Homonym (Prev_Vis, Homonym (E));
3136 Set_Name_Entity_Id (Chars (E), Homonym (E));
3141 -- This section of code could use a comment ???
3143 elsif Present (Etype (E))
3144 and then Is_Concurrent_Type (Etype (E))
3149 -- If the homograph is a protected component renaming, it should not
3150 -- be hiding the current entity. Such renamings are treated as weak
3153 elsif Is_Prival (E) then
3154 Set_Is_Immediately_Visible (E, False);
3156 -- In this case the current entity is a protected component renaming.
3157 -- Perform minimal decoration by setting the scope and return since
3158 -- the prival should not be hiding other visible entities.
3160 elsif Is_Prival (Def_Id) then
3161 Set_Scope (Def_Id, Current_Scope);
3164 -- Analogous to privals, the discriminal generated for an entry index
3165 -- parameter acts as a weak declaration. Perform minimal decoration
3166 -- to avoid bogus errors.
3168 elsif Is_Discriminal (Def_Id)
3169 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3171 Set_Scope (Def_Id, Current_Scope);
3174 -- In the body or private part of an instance, a type extension may
3175 -- introduce a component with the same name as that of an actual. The
3176 -- legality rule is not enforced, but the semantics of the full type
3177 -- with two components of same name are not clear at this point???
3179 elsif In_Instance_Not_Visible then
3182 -- When compiling a package body, some child units may have become
3183 -- visible. They cannot conflict with local entities that hide them.
3185 elsif Is_Child_Unit (E)
3186 and then In_Open_Scopes (Scope (E))
3187 and then not Is_Immediately_Visible (E)
3191 -- Conversely, with front-end inlining we may compile the parent body
3192 -- first, and a child unit subsequently. The context is now the
3193 -- parent spec, and body entities are not visible.
3195 elsif Is_Child_Unit (Def_Id)
3196 and then Is_Package_Body_Entity (E)
3197 and then not In_Package_Body (Current_Scope)
3201 -- Case of genuine duplicate declaration
3204 Error_Msg_Sloc := Sloc (E);
3206 -- If the previous declaration is an incomplete type declaration
3207 -- this may be an attempt to complete it with a private type. The
3208 -- following avoids confusing cascaded errors.
3210 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3211 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3214 ("incomplete type cannot be completed with a private " &
3215 "declaration", Parent (Def_Id));
3216 Set_Is_Immediately_Visible (E, False);
3217 Set_Full_View (E, Def_Id);
3219 -- An inherited component of a record conflicts with a new
3220 -- discriminant. The discriminant is inserted first in the scope,
3221 -- but the error should be posted on it, not on the component.
3223 elsif Ekind (E) = E_Discriminant
3224 and then Present (Scope (Def_Id))
3225 and then Scope (Def_Id) /= Current_Scope
3227 Error_Msg_Sloc := Sloc (Def_Id);
3228 Error_Msg_N ("& conflicts with declaration#", E);
3231 -- If the name of the unit appears in its own context clause, a
3232 -- dummy package with the name has already been created, and the
3233 -- error emitted. Try to continue quietly.
3235 elsif Error_Posted (E)
3236 and then Sloc (E) = No_Location
3237 and then Nkind (Parent (E)) = N_Package_Specification
3238 and then Current_Scope = Standard_Standard
3240 Set_Scope (Def_Id, Current_Scope);
3244 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3246 -- Avoid cascaded messages with duplicate components in
3249 if Ekind_In (E, E_Component, E_Discriminant) then
3254 if Nkind (Parent (Parent (Def_Id))) =
3255 N_Generic_Subprogram_Declaration
3257 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3259 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3262 -- If entity is in standard, then we are in trouble, because it
3263 -- means that we have a library package with a duplicated name.
3264 -- That's hard to recover from, so abort!
3266 if S = Standard_Standard then
3267 raise Unrecoverable_Error;
3269 -- Otherwise we continue with the declaration. Having two
3270 -- identical declarations should not cause us too much trouble!
3278 -- If we fall through, declaration is OK, at least OK enough to continue
3280 -- If Def_Id is a discriminant or a record component we are in the midst
3281 -- of inheriting components in a derived record definition. Preserve
3282 -- their Ekind and Etype.
3284 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3287 -- If a type is already set, leave it alone (happens when a type
3288 -- declaration is reanalyzed following a call to the optimizer).
3290 elsif Present (Etype (Def_Id)) then
3293 -- Otherwise, the kind E_Void insures that premature uses of the entity
3294 -- will be detected. Any_Type insures that no cascaded errors will occur
3297 Set_Ekind (Def_Id, E_Void);
3298 Set_Etype (Def_Id, Any_Type);
3301 -- Inherited discriminants and components in derived record types are
3302 -- immediately visible. Itypes are not.
3304 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3305 or else (No (Corresponding_Remote_Type (Def_Id))
3306 and then not Is_Itype (Def_Id))
3308 Set_Is_Immediately_Visible (Def_Id);
3309 Set_Current_Entity (Def_Id);
3312 Set_Homonym (Def_Id, C);
3313 Append_Entity (Def_Id, S);
3314 Set_Public_Status (Def_Id);
3316 -- Declaring a homonym is not allowed in SPARK ...
3319 and then Restriction_Check_Required (SPARK)
3323 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3324 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3325 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3328 -- ... unless the new declaration is in a subprogram, and the
3329 -- visible declaration is a variable declaration or a parameter
3330 -- specification outside that subprogram.
3332 if Present (Enclosing_Subp)
3333 and then Nkind_In (Parent (C), N_Object_Declaration,
3334 N_Parameter_Specification)
3335 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3339 -- ... or the new declaration is in a package, and the visible
3340 -- declaration occurs outside that package.
3342 elsif Present (Enclosing_Pack)
3343 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3347 -- ... or the new declaration is a component declaration in a
3348 -- record type definition.
3350 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3353 -- Don't issue error for non-source entities
3355 elsif Comes_From_Source (Def_Id)
3356 and then Comes_From_Source (C)
3358 Error_Msg_Sloc := Sloc (C);
3359 Check_SPARK_Restriction
3360 ("redeclaration of identifier &#", Def_Id);
3365 -- Warn if new entity hides an old one
3367 if Warn_On_Hiding and then Present (C)
3369 -- Don't warn for record components since they always have a well
3370 -- defined scope which does not confuse other uses. Note that in
3371 -- some cases, Ekind has not been set yet.
3373 and then Ekind (C) /= E_Component
3374 and then Ekind (C) /= E_Discriminant
3375 and then Nkind (Parent (C)) /= N_Component_Declaration
3376 and then Ekind (Def_Id) /= E_Component
3377 and then Ekind (Def_Id) /= E_Discriminant
3378 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3380 -- Don't warn for one character variables. It is too common to use
3381 -- such variables as locals and will just cause too many false hits.
3383 and then Length_Of_Name (Chars (C)) /= 1
3385 -- Don't warn for non-source entities
3387 and then Comes_From_Source (C)
3388 and then Comes_From_Source (Def_Id)
3390 -- Don't warn unless entity in question is in extended main source
3392 and then In_Extended_Main_Source_Unit (Def_Id)
3394 -- Finally, the hidden entity must be either immediately visible or
3395 -- use visible (i.e. from a used package).
3398 (Is_Immediately_Visible (C)
3400 Is_Potentially_Use_Visible (C))
3402 Error_Msg_Sloc := Sloc (C);
3403 Error_Msg_N ("declaration hides &#?", Def_Id);
3407 --------------------------
3408 -- Explain_Limited_Type --
3409 --------------------------
3411 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3415 -- For array, component type must be limited
3417 if Is_Array_Type (T) then
3418 Error_Msg_Node_2 := T;
3420 ("\component type& of type& is limited", N, Component_Type (T));
3421 Explain_Limited_Type (Component_Type (T), N);
3423 elsif Is_Record_Type (T) then
3425 -- No need for extra messages if explicit limited record
3427 if Is_Limited_Record (Base_Type (T)) then
3431 -- Otherwise find a limited component. Check only components that
3432 -- come from source, or inherited components that appear in the
3433 -- source of the ancestor.
3435 C := First_Component (T);
3436 while Present (C) loop
3437 if Is_Limited_Type (Etype (C))
3439 (Comes_From_Source (C)
3441 (Present (Original_Record_Component (C))
3443 Comes_From_Source (Original_Record_Component (C))))
3445 Error_Msg_Node_2 := T;
3446 Error_Msg_NE ("\component& of type& has limited type", N, C);
3447 Explain_Limited_Type (Etype (C), N);
3454 -- The type may be declared explicitly limited, even if no component
3455 -- of it is limited, in which case we fall out of the loop.
3458 end Explain_Limited_Type;
3464 procedure Find_Actual
3466 Formal : out Entity_Id;
3469 Parnt : constant Node_Id := Parent (N);
3473 if (Nkind (Parnt) = N_Indexed_Component
3475 Nkind (Parnt) = N_Selected_Component)
3476 and then N = Prefix (Parnt)
3478 Find_Actual (Parnt, Formal, Call);
3481 elsif Nkind (Parnt) = N_Parameter_Association
3482 and then N = Explicit_Actual_Parameter (Parnt)
3484 Call := Parent (Parnt);
3486 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3495 -- If we have a call to a subprogram look for the parameter. Note that
3496 -- we exclude overloaded calls, since we don't know enough to be sure
3497 -- of giving the right answer in this case.
3499 if Is_Entity_Name (Name (Call))
3500 and then Present (Entity (Name (Call)))
3501 and then Is_Overloadable (Entity (Name (Call)))
3502 and then not Is_Overloaded (Name (Call))
3504 -- Fall here if we are definitely a parameter
3506 Actual := First_Actual (Call);
3507 Formal := First_Formal (Entity (Name (Call)));
3508 while Present (Formal) and then Present (Actual) loop
3512 Actual := Next_Actual (Actual);
3513 Formal := Next_Formal (Formal);
3518 -- Fall through here if we did not find matching actual
3524 ---------------------------
3525 -- Find_Body_Discriminal --
3526 ---------------------------
3528 function Find_Body_Discriminal
3529 (Spec_Discriminant : Entity_Id) return Entity_Id
3531 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3533 Tsk : constant Entity_Id :=
3534 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3538 -- Find discriminant of original concurrent type, and use its current
3539 -- discriminal, which is the renaming within the task/protected body.
3541 Disc := First_Discriminant (Tsk);
3542 while Present (Disc) loop
3543 if Chars (Disc) = Chars (Spec_Discriminant) then
3544 return Discriminal (Disc);
3547 Next_Discriminant (Disc);
3550 -- That loop should always succeed in finding a matching entry and
3551 -- returning. Fatal error if not.
3553 raise Program_Error;
3554 end Find_Body_Discriminal;
3556 -------------------------------------
3557 -- Find_Corresponding_Discriminant --
3558 -------------------------------------
3560 function Find_Corresponding_Discriminant
3562 Typ : Entity_Id) return Entity_Id
3564 Par_Disc : Entity_Id;
3565 Old_Disc : Entity_Id;
3566 New_Disc : Entity_Id;
3569 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3571 -- The original type may currently be private, and the discriminant
3572 -- only appear on its full view.
3574 if Is_Private_Type (Scope (Par_Disc))
3575 and then not Has_Discriminants (Scope (Par_Disc))
3576 and then Present (Full_View (Scope (Par_Disc)))
3578 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3580 Old_Disc := First_Discriminant (Scope (Par_Disc));
3583 if Is_Class_Wide_Type (Typ) then
3584 New_Disc := First_Discriminant (Root_Type (Typ));
3586 New_Disc := First_Discriminant (Typ);
3589 while Present (Old_Disc) and then Present (New_Disc) loop
3590 if Old_Disc = Par_Disc then
3593 Next_Discriminant (Old_Disc);
3594 Next_Discriminant (New_Disc);
3598 -- Should always find it
3600 raise Program_Error;
3601 end Find_Corresponding_Discriminant;
3603 --------------------------
3604 -- Find_Overlaid_Entity --
3605 --------------------------
3607 procedure Find_Overlaid_Entity
3609 Ent : out Entity_Id;
3615 -- We are looking for one of the two following forms:
3617 -- for X'Address use Y'Address
3621 -- Const : constant Address := expr;
3623 -- for X'Address use Const;
3625 -- In the second case, the expr is either Y'Address, or recursively a
3626 -- constant that eventually references Y'Address.
3631 if Nkind (N) = N_Attribute_Definition_Clause
3632 and then Chars (N) = Name_Address
3634 Expr := Expression (N);
3636 -- This loop checks the form of the expression for Y'Address,
3637 -- using recursion to deal with intermediate constants.
3640 -- Check for Y'Address
3642 if Nkind (Expr) = N_Attribute_Reference
3643 and then Attribute_Name (Expr) = Name_Address
3645 Expr := Prefix (Expr);
3648 -- Check for Const where Const is a constant entity
3650 elsif Is_Entity_Name (Expr)
3651 and then Ekind (Entity (Expr)) = E_Constant
3653 Expr := Constant_Value (Entity (Expr));
3655 -- Anything else does not need checking
3662 -- This loop checks the form of the prefix for an entity,
3663 -- using recursion to deal with intermediate components.
3666 -- Check for Y where Y is an entity
3668 if Is_Entity_Name (Expr) then
3669 Ent := Entity (Expr);
3672 -- Check for components
3675 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3677 Expr := Prefix (Expr);
3680 -- Anything else does not need checking
3687 end Find_Overlaid_Entity;
3689 -------------------------
3690 -- Find_Parameter_Type --
3691 -------------------------
3693 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3695 if Nkind (Param) /= N_Parameter_Specification then
3698 -- For an access parameter, obtain the type from the formal entity
3699 -- itself, because access to subprogram nodes do not carry a type.
3700 -- Shouldn't we always use the formal entity ???
3702 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3703 return Etype (Defining_Identifier (Param));
3706 return Etype (Parameter_Type (Param));
3708 end Find_Parameter_Type;
3710 -----------------------------
3711 -- Find_Static_Alternative --
3712 -----------------------------
3714 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3715 Expr : constant Node_Id := Expression (N);
3716 Val : constant Uint := Expr_Value (Expr);
3721 Alt := First (Alternatives (N));
3724 if Nkind (Alt) /= N_Pragma then
3725 Choice := First (Discrete_Choices (Alt));
3726 while Present (Choice) loop
3728 -- Others choice, always matches
3730 if Nkind (Choice) = N_Others_Choice then
3733 -- Range, check if value is in the range
3735 elsif Nkind (Choice) = N_Range then
3737 Val >= Expr_Value (Low_Bound (Choice))
3739 Val <= Expr_Value (High_Bound (Choice));
3741 -- Choice is a subtype name. Note that we know it must
3742 -- be a static subtype, since otherwise it would have
3743 -- been diagnosed as illegal.
3745 elsif Is_Entity_Name (Choice)
3746 and then Is_Type (Entity (Choice))
3748 exit Search when Is_In_Range (Expr, Etype (Choice),
3749 Assume_Valid => False);
3751 -- Choice is a subtype indication
3753 elsif Nkind (Choice) = N_Subtype_Indication then
3755 C : constant Node_Id := Constraint (Choice);
3756 R : constant Node_Id := Range_Expression (C);
3760 Val >= Expr_Value (Low_Bound (R))
3762 Val <= Expr_Value (High_Bound (R));
3765 -- Choice is a simple expression
3768 exit Search when Val = Expr_Value (Choice);
3776 pragma Assert (Present (Alt));
3779 -- The above loop *must* terminate by finding a match, since
3780 -- we know the case statement is valid, and the value of the
3781 -- expression is known at compile time. When we fall out of
3782 -- the loop, Alt points to the alternative that we know will
3783 -- be selected at run time.
3786 end Find_Static_Alternative;
3792 function First_Actual (Node : Node_Id) return Node_Id is
3796 if No (Parameter_Associations (Node)) then
3800 N := First (Parameter_Associations (Node));
3802 if Nkind (N) = N_Parameter_Association then
3803 return First_Named_Actual (Node);
3809 -----------------------
3810 -- Gather_Components --
3811 -----------------------
3813 procedure Gather_Components
3815 Comp_List : Node_Id;
3816 Governed_By : List_Id;
3818 Report_Errors : out Boolean)
3822 Discrete_Choice : Node_Id;
3823 Comp_Item : Node_Id;
3825 Discrim : Entity_Id;
3826 Discrim_Name : Node_Id;
3827 Discrim_Value : Node_Id;
3830 Report_Errors := False;
3832 if No (Comp_List) or else Null_Present (Comp_List) then
3835 elsif Present (Component_Items (Comp_List)) then
3836 Comp_Item := First (Component_Items (Comp_List));
3842 while Present (Comp_Item) loop
3844 -- Skip the tag of a tagged record, the interface tags, as well
3845 -- as all items that are not user components (anonymous types,
3846 -- rep clauses, Parent field, controller field).
3848 if Nkind (Comp_Item) = N_Component_Declaration then
3850 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3852 if not Is_Tag (Comp)
3853 and then Chars (Comp) /= Name_uParent
3855 Append_Elmt (Comp, Into);
3863 if No (Variant_Part (Comp_List)) then
3866 Discrim_Name := Name (Variant_Part (Comp_List));
3867 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3870 -- Look for the discriminant that governs this variant part.
3871 -- The discriminant *must* be in the Governed_By List
3873 Assoc := First (Governed_By);
3874 Find_Constraint : loop
3875 Discrim := First (Choices (Assoc));
3876 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3877 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3879 Chars (Corresponding_Discriminant (Entity (Discrim)))
3880 = Chars (Discrim_Name))
3881 or else Chars (Original_Record_Component (Entity (Discrim)))
3882 = Chars (Discrim_Name);
3884 if No (Next (Assoc)) then
3885 if not Is_Constrained (Typ)
3886 and then Is_Derived_Type (Typ)
3887 and then Present (Stored_Constraint (Typ))
3889 -- If the type is a tagged type with inherited discriminants,
3890 -- use the stored constraint on the parent in order to find
3891 -- the values of discriminants that are otherwise hidden by an
3892 -- explicit constraint. Renamed discriminants are handled in
3895 -- If several parent discriminants are renamed by a single
3896 -- discriminant of the derived type, the call to obtain the
3897 -- Corresponding_Discriminant field only retrieves the last
3898 -- of them. We recover the constraint on the others from the
3899 -- Stored_Constraint as well.
3906 D := First_Discriminant (Etype (Typ));
3907 C := First_Elmt (Stored_Constraint (Typ));
3908 while Present (D) and then Present (C) loop
3909 if Chars (Discrim_Name) = Chars (D) then
3910 if Is_Entity_Name (Node (C))
3911 and then Entity (Node (C)) = Entity (Discrim)
3913 -- D is renamed by Discrim, whose value is given in
3920 Make_Component_Association (Sloc (Typ),
3922 (New_Occurrence_Of (D, Sloc (Typ))),
3923 Duplicate_Subexpr_No_Checks (Node (C)));
3925 exit Find_Constraint;
3928 Next_Discriminant (D);
3935 if No (Next (Assoc)) then
3936 Error_Msg_NE (" missing value for discriminant&",
3937 First (Governed_By), Discrim_Name);
3938 Report_Errors := True;
3943 end loop Find_Constraint;
3945 Discrim_Value := Expression (Assoc);
3947 if not Is_OK_Static_Expression (Discrim_Value) then
3949 ("value for discriminant & must be static!",
3950 Discrim_Value, Discrim);
3951 Why_Not_Static (Discrim_Value);
3952 Report_Errors := True;
3956 Search_For_Discriminant_Value : declare
3962 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3965 Find_Discrete_Value : while Present (Variant) loop
3966 Discrete_Choice := First (Discrete_Choices (Variant));
3967 while Present (Discrete_Choice) loop
3969 exit Find_Discrete_Value when
3970 Nkind (Discrete_Choice) = N_Others_Choice;
3972 Get_Index_Bounds (Discrete_Choice, Low, High);
3974 UI_Low := Expr_Value (Low);
3975 UI_High := Expr_Value (High);
3977 exit Find_Discrete_Value when
3978 UI_Low <= UI_Discrim_Value
3980 UI_High >= UI_Discrim_Value;
3982 Next (Discrete_Choice);
3985 Next_Non_Pragma (Variant);
3986 end loop Find_Discrete_Value;
3987 end Search_For_Discriminant_Value;
3989 if No (Variant) then
3991 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3992 Report_Errors := True;
3996 -- If we have found the corresponding choice, recursively add its
3997 -- components to the Into list.
3999 Gather_Components (Empty,
4000 Component_List (Variant), Governed_By, Into, Report_Errors);
4001 end Gather_Components;
4003 ------------------------
4004 -- Get_Actual_Subtype --
4005 ------------------------
4007 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4008 Typ : constant Entity_Id := Etype (N);
4009 Utyp : Entity_Id := Underlying_Type (Typ);
4018 -- If what we have is an identifier that references a subprogram
4019 -- formal, or a variable or constant object, then we get the actual
4020 -- subtype from the referenced entity if one has been built.
4022 if Nkind (N) = N_Identifier
4024 (Is_Formal (Entity (N))
4025 or else Ekind (Entity (N)) = E_Constant
4026 or else Ekind (Entity (N)) = E_Variable)
4027 and then Present (Actual_Subtype (Entity (N)))
4029 return Actual_Subtype (Entity (N));
4031 -- Actual subtype of unchecked union is always itself. We never need
4032 -- the "real" actual subtype. If we did, we couldn't get it anyway
4033 -- because the discriminant is not available. The restrictions on
4034 -- Unchecked_Union are designed to make sure that this is OK.
4036 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4039 -- Here for the unconstrained case, we must find actual subtype
4040 -- No actual subtype is available, so we must build it on the fly.
4042 -- Checking the type, not the underlying type, for constrainedness
4043 -- seems to be necessary. Maybe all the tests should be on the type???
4045 elsif (not Is_Constrained (Typ))
4046 and then (Is_Array_Type (Utyp)
4047 or else (Is_Record_Type (Utyp)
4048 and then Has_Discriminants (Utyp)))
4049 and then not Has_Unknown_Discriminants (Utyp)
4050 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4052 -- Nothing to do if in spec expression (why not???)
4054 if In_Spec_Expression then
4057 elsif Is_Private_Type (Typ)
4058 and then not Has_Discriminants (Typ)
4060 -- If the type has no discriminants, there is no subtype to
4061 -- build, even if the underlying type is discriminated.
4065 -- Else build the actual subtype
4068 Decl := Build_Actual_Subtype (Typ, N);
4069 Atyp := Defining_Identifier (Decl);
4071 -- If Build_Actual_Subtype generated a new declaration then use it
4075 -- The actual subtype is an Itype, so analyze the declaration,
4076 -- but do not attach it to the tree, to get the type defined.
4078 Set_Parent (Decl, N);
4079 Set_Is_Itype (Atyp);
4080 Analyze (Decl, Suppress => All_Checks);
4081 Set_Associated_Node_For_Itype (Atyp, N);
4082 Set_Has_Delayed_Freeze (Atyp, False);
4084 -- We need to freeze the actual subtype immediately. This is
4085 -- needed, because otherwise this Itype will not get frozen
4086 -- at all, and it is always safe to freeze on creation because
4087 -- any associated types must be frozen at this point.
4089 Freeze_Itype (Atyp, N);
4092 -- Otherwise we did not build a declaration, so return original
4099 -- For all remaining cases, the actual subtype is the same as
4100 -- the nominal type.
4105 end Get_Actual_Subtype;
4107 -------------------------------------
4108 -- Get_Actual_Subtype_If_Available --
4109 -------------------------------------
4111 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4112 Typ : constant Entity_Id := Etype (N);
4115 -- If what we have is an identifier that references a subprogram
4116 -- formal, or a variable or constant object, then we get the actual
4117 -- subtype from the referenced entity if one has been built.
4119 if Nkind (N) = N_Identifier
4121 (Is_Formal (Entity (N))
4122 or else Ekind (Entity (N)) = E_Constant
4123 or else Ekind (Entity (N)) = E_Variable)
4124 and then Present (Actual_Subtype (Entity (N)))
4126 return Actual_Subtype (Entity (N));
4128 -- Otherwise the Etype of N is returned unchanged
4133 end Get_Actual_Subtype_If_Available;
4135 -------------------------------
4136 -- Get_Default_External_Name --
4137 -------------------------------
4139 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4141 Get_Decoded_Name_String (Chars (E));
4143 if Opt.External_Name_Imp_Casing = Uppercase then
4144 Set_Casing (All_Upper_Case);
4146 Set_Casing (All_Lower_Case);
4150 Make_String_Literal (Sloc (E),
4151 Strval => String_From_Name_Buffer);
4152 end Get_Default_External_Name;
4154 --------------------------
4155 -- Get_Enclosing_Object --
4156 --------------------------
4158 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
4160 if Is_Entity_Name (N) then
4164 when N_Indexed_Component |
4166 N_Selected_Component =>
4168 -- If not generating code, a dereference may be left implicit.
4169 -- In thoses cases, return Empty.
4171 if Is_Access_Type (Etype (Prefix (N))) then
4174 return Get_Enclosing_Object (Prefix (N));
4177 when N_Type_Conversion =>
4178 return Get_Enclosing_Object (Expression (N));
4184 end Get_Enclosing_Object;
4186 ---------------------------
4187 -- Get_Enum_Lit_From_Pos --
4188 ---------------------------
4190 function Get_Enum_Lit_From_Pos
4193 Loc : Source_Ptr) return Node_Id
4198 -- In the case where the literal is of type Character, Wide_Character
4199 -- or Wide_Wide_Character or of a type derived from them, there needs
4200 -- to be some special handling since there is no explicit chain of
4201 -- literals to search. Instead, an N_Character_Literal node is created
4202 -- with the appropriate Char_Code and Chars fields.
4204 if Is_Standard_Character_Type (T) then
4205 Set_Character_Literal_Name (UI_To_CC (Pos));
4207 Make_Character_Literal (Loc,
4209 Char_Literal_Value => Pos);
4211 -- For all other cases, we have a complete table of literals, and
4212 -- we simply iterate through the chain of literal until the one
4213 -- with the desired position value is found.
4217 Lit := First_Literal (Base_Type (T));
4218 for J in 1 .. UI_To_Int (Pos) loop
4222 return New_Occurrence_Of (Lit, Loc);
4224 end Get_Enum_Lit_From_Pos;
4226 ---------------------------------------
4227 -- Get_Ensures_From_Test_Case_Pragma --
4228 ---------------------------------------
4230 function Get_Ensures_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4231 Args : constant List_Id := Pragma_Argument_Associations (N);
4235 if List_Length (Args) = 4 then
4236 Res := Pick (Args, 4);
4239 Res := Pick (Args, 3);
4240 if Chars (Res) /= Name_Ensures then
4246 end Get_Ensures_From_Test_Case_Pragma;
4248 ------------------------
4249 -- Get_Generic_Entity --
4250 ------------------------
4252 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4253 Ent : constant Entity_Id := Entity (Name (N));
4255 if Present (Renamed_Object (Ent)) then
4256 return Renamed_Object (Ent);
4260 end Get_Generic_Entity;
4262 ----------------------
4263 -- Get_Index_Bounds --
4264 ----------------------
4266 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4267 Kind : constant Node_Kind := Nkind (N);
4271 if Kind = N_Range then
4273 H := High_Bound (N);
4275 elsif Kind = N_Subtype_Indication then
4276 R := Range_Expression (Constraint (N));
4284 L := Low_Bound (Range_Expression (Constraint (N)));
4285 H := High_Bound (Range_Expression (Constraint (N)));
4288 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4289 if Error_Posted (Scalar_Range (Entity (N))) then
4293 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4294 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4297 L := Low_Bound (Scalar_Range (Entity (N)));
4298 H := High_Bound (Scalar_Range (Entity (N)));
4302 -- N is an expression, indicating a range with one value
4307 end Get_Index_Bounds;
4309 ----------------------------------
4310 -- Get_Library_Unit_Name_string --
4311 ----------------------------------
4313 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4314 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4317 Get_Unit_Name_String (Unit_Name_Id);
4319 -- Remove seven last character (" (spec)" or " (body)")
4321 Name_Len := Name_Len - 7;
4322 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4323 end Get_Library_Unit_Name_String;
4325 ------------------------
4326 -- Get_Name_Entity_Id --
4327 ------------------------
4329 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4331 return Entity_Id (Get_Name_Table_Info (Id));
4332 end Get_Name_Entity_Id;
4334 ------------------------------------
4335 -- Get_Name_From_Test_Case_Pragma --
4336 ------------------------------------
4338 function Get_Name_From_Test_Case_Pragma (N : Node_Id) return String_Id is
4341 Strval (Get_Pragma_Arg (First (Pragma_Argument_Associations (N))));
4342 end Get_Name_From_Test_Case_Pragma;
4348 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4350 return Get_Pragma_Id (Pragma_Name (N));
4353 ---------------------------
4354 -- Get_Referenced_Object --
4355 ---------------------------
4357 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4362 while Is_Entity_Name (R)
4363 and then Present (Renamed_Object (Entity (R)))
4365 R := Renamed_Object (Entity (R));
4369 end Get_Referenced_Object;
4371 ------------------------
4372 -- Get_Renamed_Entity --
4373 ------------------------
4375 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4380 while Present (Renamed_Entity (R)) loop
4381 R := Renamed_Entity (R);
4385 end Get_Renamed_Entity;
4387 ----------------------------------------
4388 -- Get_Requires_From_Test_Case_Pragma --
4389 ----------------------------------------
4391 function Get_Requires_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4392 Args : constant List_Id := Pragma_Argument_Associations (N);
4396 Res := Pick (Args, 3);
4397 if Chars (Res) /= Name_Requires then
4402 end Get_Requires_From_Test_Case_Pragma;
4404 -------------------------
4405 -- Get_Subprogram_Body --
4406 -------------------------
4408 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4412 Decl := Unit_Declaration_Node (E);
4414 if Nkind (Decl) = N_Subprogram_Body then
4417 -- The below comment is bad, because it is possible for
4418 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4420 else -- Nkind (Decl) = N_Subprogram_Declaration
4422 if Present (Corresponding_Body (Decl)) then
4423 return Unit_Declaration_Node (Corresponding_Body (Decl));
4425 -- Imported subprogram case
4431 end Get_Subprogram_Body;
4433 ---------------------------
4434 -- Get_Subprogram_Entity --
4435 ---------------------------
4437 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4442 if Nkind (Nod) = N_Accept_Statement then
4443 Nam := Entry_Direct_Name (Nod);
4445 -- For an entry call, the prefix of the call is a selected component.
4446 -- Need additional code for internal calls ???
4448 elsif Nkind (Nod) = N_Entry_Call_Statement then
4449 if Nkind (Name (Nod)) = N_Selected_Component then
4450 Nam := Entity (Selector_Name (Name (Nod)));
4459 if Nkind (Nam) = N_Explicit_Dereference then
4460 Proc := Etype (Prefix (Nam));
4461 elsif Is_Entity_Name (Nam) then
4462 Proc := Entity (Nam);
4467 if Is_Object (Proc) then
4468 Proc := Etype (Proc);
4471 if Ekind (Proc) = E_Access_Subprogram_Type then
4472 Proc := Directly_Designated_Type (Proc);
4475 if not Is_Subprogram (Proc)
4476 and then Ekind (Proc) /= E_Subprogram_Type
4482 end Get_Subprogram_Entity;
4484 -----------------------------
4485 -- Get_Task_Body_Procedure --
4486 -----------------------------
4488 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4490 -- Note: A task type may be the completion of a private type with
4491 -- discriminants. When performing elaboration checks on a task
4492 -- declaration, the current view of the type may be the private one,
4493 -- and the procedure that holds the body of the task is held in its
4496 -- This is an odd function, why not have Task_Body_Procedure do
4497 -- the following digging???
4499 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4500 end Get_Task_Body_Procedure;
4502 -----------------------
4503 -- Has_Access_Values --
4504 -----------------------
4506 function Has_Access_Values (T : Entity_Id) return Boolean is
4507 Typ : constant Entity_Id := Underlying_Type (T);
4510 -- Case of a private type which is not completed yet. This can only
4511 -- happen in the case of a generic format type appearing directly, or
4512 -- as a component of the type to which this function is being applied
4513 -- at the top level. Return False in this case, since we certainly do
4514 -- not know that the type contains access types.
4519 elsif Is_Access_Type (Typ) then
4522 elsif Is_Array_Type (Typ) then
4523 return Has_Access_Values (Component_Type (Typ));
4525 elsif Is_Record_Type (Typ) then
4530 -- Loop to Check components
4532 Comp := First_Component_Or_Discriminant (Typ);
4533 while Present (Comp) loop
4535 -- Check for access component, tag field does not count, even
4536 -- though it is implemented internally using an access type.
4538 if Has_Access_Values (Etype (Comp))
4539 and then Chars (Comp) /= Name_uTag
4544 Next_Component_Or_Discriminant (Comp);
4553 end Has_Access_Values;
4555 ------------------------------
4556 -- Has_Compatible_Alignment --
4557 ------------------------------
4559 function Has_Compatible_Alignment
4561 Expr : Node_Id) return Alignment_Result
4563 function Has_Compatible_Alignment_Internal
4566 Default : Alignment_Result) return Alignment_Result;
4567 -- This is the internal recursive function that actually does the work.
4568 -- There is one additional parameter, which says what the result should
4569 -- be if no alignment information is found, and there is no definite
4570 -- indication of compatible alignments. At the outer level, this is set
4571 -- to Unknown, but for internal recursive calls in the case where types
4572 -- are known to be correct, it is set to Known_Compatible.
4574 ---------------------------------------
4575 -- Has_Compatible_Alignment_Internal --
4576 ---------------------------------------
4578 function Has_Compatible_Alignment_Internal
4581 Default : Alignment_Result) return Alignment_Result
4583 Result : Alignment_Result := Known_Compatible;
4584 -- Holds the current status of the result. Note that once a value of
4585 -- Known_Incompatible is set, it is sticky and does not get changed
4586 -- to Unknown (the value in Result only gets worse as we go along,
4589 Offs : Uint := No_Uint;
4590 -- Set to a factor of the offset from the base object when Expr is a
4591 -- selected or indexed component, based on Component_Bit_Offset and
4592 -- Component_Size respectively. A negative value is used to represent
4593 -- a value which is not known at compile time.
4595 procedure Check_Prefix;
4596 -- Checks the prefix recursively in the case where the expression
4597 -- is an indexed or selected component.
4599 procedure Set_Result (R : Alignment_Result);
4600 -- If R represents a worse outcome (unknown instead of known
4601 -- compatible, or known incompatible), then set Result to R.
4607 procedure Check_Prefix is
4609 -- The subtlety here is that in doing a recursive call to check
4610 -- the prefix, we have to decide what to do in the case where we
4611 -- don't find any specific indication of an alignment problem.
4613 -- At the outer level, we normally set Unknown as the result in
4614 -- this case, since we can only set Known_Compatible if we really
4615 -- know that the alignment value is OK, but for the recursive
4616 -- call, in the case where the types match, and we have not
4617 -- specified a peculiar alignment for the object, we are only
4618 -- concerned about suspicious rep clauses, the default case does
4619 -- not affect us, since the compiler will, in the absence of such
4620 -- rep clauses, ensure that the alignment is correct.
4622 if Default = Known_Compatible
4624 (Etype (Obj) = Etype (Expr)
4625 and then (Unknown_Alignment (Obj)
4627 Alignment (Obj) = Alignment (Etype (Obj))))
4630 (Has_Compatible_Alignment_Internal
4631 (Obj, Prefix (Expr), Known_Compatible));
4633 -- In all other cases, we need a full check on the prefix
4637 (Has_Compatible_Alignment_Internal
4638 (Obj, Prefix (Expr), Unknown));
4646 procedure Set_Result (R : Alignment_Result) is
4653 -- Start of processing for Has_Compatible_Alignment_Internal
4656 -- If Expr is a selected component, we must make sure there is no
4657 -- potentially troublesome component clause, and that the record is
4660 if Nkind (Expr) = N_Selected_Component then
4662 -- Packed record always generate unknown alignment
4664 if Is_Packed (Etype (Prefix (Expr))) then
4665 Set_Result (Unknown);
4668 -- Check prefix and component offset
4671 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4673 -- If Expr is an indexed component, we must make sure there is no
4674 -- potentially troublesome Component_Size clause and that the array
4675 -- is not bit-packed.
4677 elsif Nkind (Expr) = N_Indexed_Component then
4679 Typ : constant Entity_Id := Etype (Prefix (Expr));
4680 Ind : constant Node_Id := First_Index (Typ);
4683 -- Bit packed array always generates unknown alignment
4685 if Is_Bit_Packed_Array (Typ) then
4686 Set_Result (Unknown);
4689 -- Check prefix and component offset
4692 Offs := Component_Size (Typ);
4694 -- Small optimization: compute the full offset when possible
4697 and then Offs > Uint_0
4698 and then Present (Ind)
4699 and then Nkind (Ind) = N_Range
4700 and then Compile_Time_Known_Value (Low_Bound (Ind))
4701 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4703 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4704 - Expr_Value (Low_Bound ((Ind))));
4709 -- If we have a null offset, the result is entirely determined by
4710 -- the base object and has already been computed recursively.
4712 if Offs = Uint_0 then
4715 -- Case where we know the alignment of the object
4717 elsif Known_Alignment (Obj) then
4719 ObjA : constant Uint := Alignment (Obj);
4720 ExpA : Uint := No_Uint;
4721 SizA : Uint := No_Uint;
4724 -- If alignment of Obj is 1, then we are always OK
4727 Set_Result (Known_Compatible);
4729 -- Alignment of Obj is greater than 1, so we need to check
4732 -- If we have an offset, see if it is compatible
4734 if Offs /= No_Uint and Offs > Uint_0 then
4735 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4736 Set_Result (Known_Incompatible);
4739 -- See if Expr is an object with known alignment
4741 elsif Is_Entity_Name (Expr)
4742 and then Known_Alignment (Entity (Expr))
4744 ExpA := Alignment (Entity (Expr));
4746 -- Otherwise, we can use the alignment of the type of
4747 -- Expr given that we already checked for
4748 -- discombobulating rep clauses for the cases of indexed
4749 -- and selected components above.
4751 elsif Known_Alignment (Etype (Expr)) then
4752 ExpA := Alignment (Etype (Expr));
4754 -- Otherwise the alignment is unknown
4757 Set_Result (Default);
4760 -- If we got an alignment, see if it is acceptable
4762 if ExpA /= No_Uint and then ExpA < ObjA then
4763 Set_Result (Known_Incompatible);
4766 -- If Expr is not a piece of a larger object, see if size
4767 -- is given. If so, check that it is not too small for the
4768 -- required alignment.
4770 if Offs /= No_Uint then
4773 -- See if Expr is an object with known size
4775 elsif Is_Entity_Name (Expr)
4776 and then Known_Static_Esize (Entity (Expr))
4778 SizA := Esize (Entity (Expr));
4780 -- Otherwise, we check the object size of the Expr type
4782 elsif Known_Static_Esize (Etype (Expr)) then
4783 SizA := Esize (Etype (Expr));
4786 -- If we got a size, see if it is a multiple of the Obj
4787 -- alignment, if not, then the alignment cannot be
4788 -- acceptable, since the size is always a multiple of the
4791 if SizA /= No_Uint then
4792 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4793 Set_Result (Known_Incompatible);
4799 -- If we do not know required alignment, any non-zero offset is a
4800 -- potential problem (but certainly may be OK, so result is unknown).
4802 elsif Offs /= No_Uint then
4803 Set_Result (Unknown);
4805 -- If we can't find the result by direct comparison of alignment
4806 -- values, then there is still one case that we can determine known
4807 -- result, and that is when we can determine that the types are the
4808 -- same, and no alignments are specified. Then we known that the
4809 -- alignments are compatible, even if we don't know the alignment
4810 -- value in the front end.
4812 elsif Etype (Obj) = Etype (Expr) then
4814 -- Types are the same, but we have to check for possible size
4815 -- and alignments on the Expr object that may make the alignment
4816 -- different, even though the types are the same.
4818 if Is_Entity_Name (Expr) then
4820 -- First check alignment of the Expr object. Any alignment less
4821 -- than Maximum_Alignment is worrisome since this is the case
4822 -- where we do not know the alignment of Obj.
4824 if Known_Alignment (Entity (Expr))
4826 UI_To_Int (Alignment (Entity (Expr))) <
4827 Ttypes.Maximum_Alignment
4829 Set_Result (Unknown);
4831 -- Now check size of Expr object. Any size that is not an
4832 -- even multiple of Maximum_Alignment is also worrisome
4833 -- since it may cause the alignment of the object to be less
4834 -- than the alignment of the type.
4836 elsif Known_Static_Esize (Entity (Expr))
4838 (UI_To_Int (Esize (Entity (Expr))) mod
4839 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4842 Set_Result (Unknown);
4844 -- Otherwise same type is decisive
4847 Set_Result (Known_Compatible);
4851 -- Another case to deal with is when there is an explicit size or
4852 -- alignment clause when the types are not the same. If so, then the
4853 -- result is Unknown. We don't need to do this test if the Default is
4854 -- Unknown, since that result will be set in any case.
4856 elsif Default /= Unknown
4857 and then (Has_Size_Clause (Etype (Expr))
4859 Has_Alignment_Clause (Etype (Expr)))
4861 Set_Result (Unknown);
4863 -- If no indication found, set default
4866 Set_Result (Default);
4869 -- Return worst result found
4872 end Has_Compatible_Alignment_Internal;
4874 -- Start of processing for Has_Compatible_Alignment
4877 -- If Obj has no specified alignment, then set alignment from the type
4878 -- alignment. Perhaps we should always do this, but for sure we should
4879 -- do it when there is an address clause since we can do more if the
4880 -- alignment is known.
4882 if Unknown_Alignment (Obj) then
4883 Set_Alignment (Obj, Alignment (Etype (Obj)));
4886 -- Now do the internal call that does all the work
4888 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4889 end Has_Compatible_Alignment;
4891 ----------------------
4892 -- Has_Declarations --
4893 ----------------------
4895 function Has_Declarations (N : Node_Id) return Boolean is
4897 return Nkind_In (Nkind (N), N_Accept_Statement,
4899 N_Compilation_Unit_Aux,
4905 N_Package_Specification);
4906 end Has_Declarations;
4908 -------------------------------------------
4909 -- Has_Discriminant_Dependent_Constraint --
4910 -------------------------------------------
4912 function Has_Discriminant_Dependent_Constraint
4913 (Comp : Entity_Id) return Boolean
4915 Comp_Decl : constant Node_Id := Parent (Comp);
4916 Subt_Indic : constant Node_Id :=
4917 Subtype_Indication (Component_Definition (Comp_Decl));
4922 if Nkind (Subt_Indic) = N_Subtype_Indication then
4923 Constr := Constraint (Subt_Indic);
4925 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4926 Assn := First (Constraints (Constr));
4927 while Present (Assn) loop
4928 case Nkind (Assn) is
4929 when N_Subtype_Indication |
4933 if Depends_On_Discriminant (Assn) then
4937 when N_Discriminant_Association =>
4938 if Depends_On_Discriminant (Expression (Assn)) then
4953 end Has_Discriminant_Dependent_Constraint;
4955 --------------------
4956 -- Has_Infinities --
4957 --------------------
4959 function Has_Infinities (E : Entity_Id) return Boolean is
4962 Is_Floating_Point_Type (E)
4963 and then Nkind (Scalar_Range (E)) = N_Range
4964 and then Includes_Infinities (Scalar_Range (E));
4967 --------------------
4968 -- Has_Interfaces --
4969 --------------------
4971 function Has_Interfaces
4973 Use_Full_View : Boolean := True) return Boolean
4975 Typ : Entity_Id := Base_Type (T);
4978 -- Handle concurrent types
4980 if Is_Concurrent_Type (Typ) then
4981 Typ := Corresponding_Record_Type (Typ);
4984 if not Present (Typ)
4985 or else not Is_Record_Type (Typ)
4986 or else not Is_Tagged_Type (Typ)
4991 -- Handle private types
4994 and then Present (Full_View (Typ))
4996 Typ := Full_View (Typ);
4999 -- Handle concurrent record types
5001 if Is_Concurrent_Record_Type (Typ)
5002 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
5008 if Is_Interface (Typ)
5010 (Is_Record_Type (Typ)
5011 and then Present (Interfaces (Typ))
5012 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
5017 exit when Etype (Typ) = Typ
5019 -- Handle private types
5021 or else (Present (Full_View (Etype (Typ)))
5022 and then Full_View (Etype (Typ)) = Typ)
5024 -- Protect the frontend against wrong source with cyclic
5027 or else Etype (Typ) = T;
5029 -- Climb to the ancestor type handling private types
5031 if Present (Full_View (Etype (Typ))) then
5032 Typ := Full_View (Etype (Typ));
5041 ------------------------
5042 -- Has_Null_Exclusion --
5043 ------------------------
5045 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5048 when N_Access_Definition |
5049 N_Access_Function_Definition |
5050 N_Access_Procedure_Definition |
5051 N_Access_To_Object_Definition |
5053 N_Derived_Type_Definition |
5054 N_Function_Specification |
5055 N_Subtype_Declaration =>
5056 return Null_Exclusion_Present (N);
5058 when N_Component_Definition |
5059 N_Formal_Object_Declaration |
5060 N_Object_Renaming_Declaration =>
5061 if Present (Subtype_Mark (N)) then
5062 return Null_Exclusion_Present (N);
5063 else pragma Assert (Present (Access_Definition (N)));
5064 return Null_Exclusion_Present (Access_Definition (N));
5067 when N_Discriminant_Specification =>
5068 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5069 return Null_Exclusion_Present (Discriminant_Type (N));
5071 return Null_Exclusion_Present (N);
5074 when N_Object_Declaration =>
5075 if Nkind (Object_Definition (N)) = N_Access_Definition then
5076 return Null_Exclusion_Present (Object_Definition (N));
5078 return Null_Exclusion_Present (N);
5081 when N_Parameter_Specification =>
5082 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5083 return Null_Exclusion_Present (Parameter_Type (N));
5085 return Null_Exclusion_Present (N);
5092 end Has_Null_Exclusion;
5094 ------------------------
5095 -- Has_Null_Extension --
5096 ------------------------
5098 function Has_Null_Extension (T : Entity_Id) return Boolean is
5099 B : constant Entity_Id := Base_Type (T);
5104 if Nkind (Parent (B)) = N_Full_Type_Declaration
5105 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5107 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5109 if Present (Ext) then
5110 if Null_Present (Ext) then
5113 Comps := Component_List (Ext);
5115 -- The null component list is rewritten during analysis to
5116 -- include the parent component. Any other component indicates
5117 -- that the extension was not originally null.
5119 return Null_Present (Comps)
5120 or else No (Next (First (Component_Items (Comps))));
5129 end Has_Null_Extension;
5131 -------------------------------
5132 -- Has_Overriding_Initialize --
5133 -------------------------------
5135 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5136 BT : constant Entity_Id := Base_Type (T);
5140 if Is_Controlled (BT) then
5141 if Is_RTU (Scope (BT), Ada_Finalization) then
5144 elsif Present (Primitive_Operations (BT)) then
5145 P := First_Elmt (Primitive_Operations (BT));
5146 while Present (P) loop
5148 Init : constant Entity_Id := Node (P);
5149 Formal : constant Entity_Id := First_Formal (Init);
5151 if Ekind (Init) = E_Procedure
5152 and then Chars (Init) = Name_Initialize
5153 and then Comes_From_Source (Init)
5154 and then Present (Formal)
5155 and then Etype (Formal) = BT
5156 and then No (Next_Formal (Formal))
5157 and then (Ada_Version < Ada_2012
5158 or else not Null_Present (Parent (Init)))
5168 -- Here if type itself does not have a non-null Initialize operation:
5169 -- check immediate ancestor.
5171 if Is_Derived_Type (BT)
5172 and then Has_Overriding_Initialize (Etype (BT))
5179 end Has_Overriding_Initialize;
5181 --------------------------------------
5182 -- Has_Preelaborable_Initialization --
5183 --------------------------------------
5185 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5188 procedure Check_Components (E : Entity_Id);
5189 -- Check component/discriminant chain, sets Has_PE False if a component
5190 -- or discriminant does not meet the preelaborable initialization rules.
5192 ----------------------
5193 -- Check_Components --
5194 ----------------------
5196 procedure Check_Components (E : Entity_Id) is
5200 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5201 -- Returns True if and only if the expression denoted by N does not
5202 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5204 ---------------------------------
5205 -- Is_Preelaborable_Expression --
5206 ---------------------------------
5208 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5212 Comp_Type : Entity_Id;
5213 Is_Array_Aggr : Boolean;
5216 if Is_Static_Expression (N) then
5219 elsif Nkind (N) = N_Null then
5222 -- Attributes are allowed in general, even if their prefix is a
5223 -- formal type. (It seems that certain attributes known not to be
5224 -- static might not be allowed, but there are no rules to prevent
5227 elsif Nkind (N) = N_Attribute_Reference then
5230 -- The name of a discriminant evaluated within its parent type is
5231 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5232 -- names that denote discriminals as well as discriminants to
5233 -- catch references occurring within init procs.
5235 elsif Is_Entity_Name (N)
5237 (Ekind (Entity (N)) = E_Discriminant
5239 ((Ekind (Entity (N)) = E_Constant
5240 or else Ekind (Entity (N)) = E_In_Parameter)
5241 and then Present (Discriminal_Link (Entity (N)))))
5245 elsif Nkind (N) = N_Qualified_Expression then
5246 return Is_Preelaborable_Expression (Expression (N));
5248 -- For aggregates we have to check that each of the associations
5249 -- is preelaborable.
5251 elsif Nkind (N) = N_Aggregate
5252 or else Nkind (N) = N_Extension_Aggregate
5254 Is_Array_Aggr := Is_Array_Type (Etype (N));
5256 if Is_Array_Aggr then
5257 Comp_Type := Component_Type (Etype (N));
5260 -- Check the ancestor part of extension aggregates, which must
5261 -- be either the name of a type that has preelaborable init or
5262 -- an expression that is preelaborable.
5264 if Nkind (N) = N_Extension_Aggregate then
5266 Anc_Part : constant Node_Id := Ancestor_Part (N);
5269 if Is_Entity_Name (Anc_Part)
5270 and then Is_Type (Entity (Anc_Part))
5272 if not Has_Preelaborable_Initialization
5278 elsif not Is_Preelaborable_Expression (Anc_Part) then
5284 -- Check positional associations
5286 Exp := First (Expressions (N));
5287 while Present (Exp) loop
5288 if not Is_Preelaborable_Expression (Exp) then
5295 -- Check named associations
5297 Assn := First (Component_Associations (N));
5298 while Present (Assn) loop
5299 Choice := First (Choices (Assn));
5300 while Present (Choice) loop
5301 if Is_Array_Aggr then
5302 if Nkind (Choice) = N_Others_Choice then
5305 elsif Nkind (Choice) = N_Range then
5306 if not Is_Static_Range (Choice) then
5310 elsif not Is_Static_Expression (Choice) then
5315 Comp_Type := Etype (Choice);
5321 -- If the association has a <> at this point, then we have
5322 -- to check whether the component's type has preelaborable
5323 -- initialization. Note that this only occurs when the
5324 -- association's corresponding component does not have a
5325 -- default expression, the latter case having already been
5326 -- expanded as an expression for the association.
5328 if Box_Present (Assn) then
5329 if not Has_Preelaborable_Initialization (Comp_Type) then
5333 -- In the expression case we check whether the expression
5334 -- is preelaborable.
5337 not Is_Preelaborable_Expression (Expression (Assn))
5345 -- If we get here then aggregate as a whole is preelaborable
5349 -- All other cases are not preelaborable
5354 end Is_Preelaborable_Expression;
5356 -- Start of processing for Check_Components
5359 -- Loop through entities of record or protected type
5362 while Present (Ent) loop
5364 -- We are interested only in components and discriminants
5371 -- Get default expression if any. If there is no declaration
5372 -- node, it means we have an internal entity. The parent and
5373 -- tag fields are examples of such entities. For such cases,
5374 -- we just test the type of the entity.
5376 if Present (Declaration_Node (Ent)) then
5377 Exp := Expression (Declaration_Node (Ent));
5380 when E_Discriminant =>
5382 -- Note: for a renamed discriminant, the Declaration_Node
5383 -- may point to the one from the ancestor, and have a
5384 -- different expression, so use the proper attribute to
5385 -- retrieve the expression from the derived constraint.
5387 Exp := Discriminant_Default_Value (Ent);
5390 goto Check_Next_Entity;
5393 -- A component has PI if it has no default expression and the
5394 -- component type has PI.
5397 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5402 -- Require the default expression to be preelaborable
5404 elsif not Is_Preelaborable_Expression (Exp) then
5409 <<Check_Next_Entity>>
5412 end Check_Components;
5414 -- Start of processing for Has_Preelaborable_Initialization
5417 -- Immediate return if already marked as known preelaborable init. This
5418 -- covers types for which this function has already been called once
5419 -- and returned True (in which case the result is cached), and also
5420 -- types to which a pragma Preelaborable_Initialization applies.
5422 if Known_To_Have_Preelab_Init (E) then
5426 -- If the type is a subtype representing a generic actual type, then
5427 -- test whether its base type has preelaborable initialization since
5428 -- the subtype representing the actual does not inherit this attribute
5429 -- from the actual or formal. (but maybe it should???)
5431 if Is_Generic_Actual_Type (E) then
5432 return Has_Preelaborable_Initialization (Base_Type (E));
5435 -- All elementary types have preelaborable initialization
5437 if Is_Elementary_Type (E) then
5440 -- Array types have PI if the component type has PI
5442 elsif Is_Array_Type (E) then
5443 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5445 -- A derived type has preelaborable initialization if its parent type
5446 -- has preelaborable initialization and (in the case of a derived record
5447 -- extension) if the non-inherited components all have preelaborable
5448 -- initialization. However, a user-defined controlled type with an
5449 -- overriding Initialize procedure does not have preelaborable
5452 elsif Is_Derived_Type (E) then
5454 -- If the derived type is a private extension then it doesn't have
5455 -- preelaborable initialization.
5457 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5461 -- First check whether ancestor type has preelaborable initialization
5463 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5465 -- If OK, check extension components (if any)
5467 if Has_PE and then Is_Record_Type (E) then
5468 Check_Components (First_Entity (E));
5471 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5472 -- with a user defined Initialize procedure does not have PI.
5475 and then Is_Controlled (E)
5476 and then Has_Overriding_Initialize (E)
5481 -- Private types not derived from a type having preelaborable init and
5482 -- that are not marked with pragma Preelaborable_Initialization do not
5483 -- have preelaborable initialization.
5485 elsif Is_Private_Type (E) then
5488 -- Record type has PI if it is non private and all components have PI
5490 elsif Is_Record_Type (E) then
5492 Check_Components (First_Entity (E));
5494 -- Protected types must not have entries, and components must meet
5495 -- same set of rules as for record components.
5497 elsif Is_Protected_Type (E) then
5498 if Has_Entries (E) then
5502 Check_Components (First_Entity (E));
5503 Check_Components (First_Private_Entity (E));
5506 -- Type System.Address always has preelaborable initialization
5508 elsif Is_RTE (E, RE_Address) then
5511 -- In all other cases, type does not have preelaborable initialization
5517 -- If type has preelaborable initialization, cache result
5520 Set_Known_To_Have_Preelab_Init (E);
5524 end Has_Preelaborable_Initialization;
5526 ---------------------------
5527 -- Has_Private_Component --
5528 ---------------------------
5530 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5531 Btype : Entity_Id := Base_Type (Type_Id);
5532 Component : Entity_Id;
5535 if Error_Posted (Type_Id)
5536 or else Error_Posted (Btype)
5541 if Is_Class_Wide_Type (Btype) then
5542 Btype := Root_Type (Btype);
5545 if Is_Private_Type (Btype) then
5547 UT : constant Entity_Id := Underlying_Type (Btype);
5550 if No (Full_View (Btype)) then
5551 return not Is_Generic_Type (Btype)
5552 and then not Is_Generic_Type (Root_Type (Btype));
5554 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5557 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5561 elsif Is_Array_Type (Btype) then
5562 return Has_Private_Component (Component_Type (Btype));
5564 elsif Is_Record_Type (Btype) then
5565 Component := First_Component (Btype);
5566 while Present (Component) loop
5567 if Has_Private_Component (Etype (Component)) then
5571 Next_Component (Component);
5576 elsif Is_Protected_Type (Btype)
5577 and then Present (Corresponding_Record_Type (Btype))
5579 return Has_Private_Component (Corresponding_Record_Type (Btype));
5584 end Has_Private_Component;
5586 -----------------------------
5587 -- Has_Static_Array_Bounds --
5588 -----------------------------
5590 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5591 Ndims : constant Nat := Number_Dimensions (Typ);
5598 -- Unconstrained types do not have static bounds
5600 if not Is_Constrained (Typ) then
5604 -- First treat string literals specially, as the lower bound and length
5605 -- of string literals are not stored like those of arrays.
5607 -- A string literal always has static bounds
5609 if Ekind (Typ) = E_String_Literal_Subtype then
5613 -- Treat all dimensions in turn
5615 Index := First_Index (Typ);
5616 for Indx in 1 .. Ndims loop
5618 -- In case of an erroneous index which is not a discrete type, return
5619 -- that the type is not static.
5621 if not Is_Discrete_Type (Etype (Index))
5622 or else Etype (Index) = Any_Type
5627 Get_Index_Bounds (Index, Low, High);
5629 if Error_Posted (Low) or else Error_Posted (High) then
5633 if Is_OK_Static_Expression (Low)
5635 Is_OK_Static_Expression (High)
5645 -- If we fall through the loop, all indexes matched
5648 end Has_Static_Array_Bounds;
5654 function Has_Stream (T : Entity_Id) return Boolean is
5661 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5664 elsif Is_Array_Type (T) then
5665 return Has_Stream (Component_Type (T));
5667 elsif Is_Record_Type (T) then
5668 E := First_Component (T);
5669 while Present (E) loop
5670 if Has_Stream (Etype (E)) then
5679 elsif Is_Private_Type (T) then
5680 return Has_Stream (Underlying_Type (T));
5691 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5693 Get_Name_String (Chars (E));
5694 return Name_Buffer (Name_Len) = Suffix;
5697 --------------------------
5698 -- Has_Tagged_Component --
5699 --------------------------
5701 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5705 if Is_Private_Type (Typ)
5706 and then Present (Underlying_Type (Typ))
5708 return Has_Tagged_Component (Underlying_Type (Typ));
5710 elsif Is_Array_Type (Typ) then
5711 return Has_Tagged_Component (Component_Type (Typ));
5713 elsif Is_Tagged_Type (Typ) then
5716 elsif Is_Record_Type (Typ) then
5717 Comp := First_Component (Typ);
5718 while Present (Comp) loop
5719 if Has_Tagged_Component (Etype (Comp)) then
5723 Next_Component (Comp);
5731 end Has_Tagged_Component;
5733 -------------------------
5734 -- Implementation_Kind --
5735 -------------------------
5737 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5738 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5740 pragma Assert (Present (Impl_Prag));
5742 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5743 end Implementation_Kind;
5745 --------------------------
5746 -- Implements_Interface --
5747 --------------------------
5749 function Implements_Interface
5750 (Typ_Ent : Entity_Id;
5751 Iface_Ent : Entity_Id;
5752 Exclude_Parents : Boolean := False) return Boolean
5754 Ifaces_List : Elist_Id;
5756 Iface : Entity_Id := Base_Type (Iface_Ent);
5757 Typ : Entity_Id := Base_Type (Typ_Ent);
5760 if Is_Class_Wide_Type (Typ) then
5761 Typ := Root_Type (Typ);
5764 if not Has_Interfaces (Typ) then
5768 if Is_Class_Wide_Type (Iface) then
5769 Iface := Root_Type (Iface);
5772 Collect_Interfaces (Typ, Ifaces_List);
5774 Elmt := First_Elmt (Ifaces_List);
5775 while Present (Elmt) loop
5776 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5777 and then Exclude_Parents
5781 elsif Node (Elmt) = Iface then
5789 end Implements_Interface;
5795 function In_Instance return Boolean is
5796 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5802 and then S /= Standard_Standard
5804 if (Ekind (S) = E_Function
5805 or else Ekind (S) = E_Package
5806 or else Ekind (S) = E_Procedure)
5807 and then Is_Generic_Instance (S)
5809 -- A child instance is always compiled in the context of a parent
5810 -- instance. Nevertheless, the actuals are not analyzed in an
5811 -- instance context. We detect this case by examining the current
5812 -- compilation unit, which must be a child instance, and checking
5813 -- that it is not currently on the scope stack.
5815 if Is_Child_Unit (Curr_Unit)
5817 Nkind (Unit (Cunit (Current_Sem_Unit)))
5818 = N_Package_Instantiation
5819 and then not In_Open_Scopes (Curr_Unit)
5833 ----------------------
5834 -- In_Instance_Body --
5835 ----------------------
5837 function In_Instance_Body return Boolean is
5843 and then S /= Standard_Standard
5845 if (Ekind (S) = E_Function
5846 or else Ekind (S) = E_Procedure)
5847 and then Is_Generic_Instance (S)
5851 elsif Ekind (S) = E_Package
5852 and then In_Package_Body (S)
5853 and then Is_Generic_Instance (S)
5862 end In_Instance_Body;
5864 -----------------------------
5865 -- In_Instance_Not_Visible --
5866 -----------------------------
5868 function In_Instance_Not_Visible return Boolean is
5874 and then S /= Standard_Standard
5876 if (Ekind (S) = E_Function
5877 or else Ekind (S) = E_Procedure)
5878 and then Is_Generic_Instance (S)
5882 elsif Ekind (S) = E_Package
5883 and then (In_Package_Body (S) or else In_Private_Part (S))
5884 and then Is_Generic_Instance (S)
5893 end In_Instance_Not_Visible;
5895 ------------------------------
5896 -- In_Instance_Visible_Part --
5897 ------------------------------
5899 function In_Instance_Visible_Part return Boolean is
5905 and then S /= Standard_Standard
5907 if Ekind (S) = E_Package
5908 and then Is_Generic_Instance (S)
5909 and then not In_Package_Body (S)
5910 and then not In_Private_Part (S)
5919 end In_Instance_Visible_Part;
5921 ---------------------
5922 -- In_Package_Body --
5923 ---------------------
5925 function In_Package_Body return Boolean is
5931 and then S /= Standard_Standard
5933 if Ekind (S) = E_Package
5934 and then In_Package_Body (S)
5943 end In_Package_Body;
5945 --------------------------------
5946 -- In_Parameter_Specification --
5947 --------------------------------
5949 function In_Parameter_Specification (N : Node_Id) return Boolean is
5954 while Present (PN) loop
5955 if Nkind (PN) = N_Parameter_Specification then
5963 end In_Parameter_Specification;
5965 --------------------------------------
5966 -- In_Subprogram_Or_Concurrent_Unit --
5967 --------------------------------------
5969 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5974 -- Use scope chain to check successively outer scopes
5980 if K in Subprogram_Kind
5981 or else K in Concurrent_Kind
5982 or else K in Generic_Subprogram_Kind
5986 elsif E = Standard_Standard then
5992 end In_Subprogram_Or_Concurrent_Unit;
5994 ---------------------
5995 -- In_Visible_Part --
5996 ---------------------
5998 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
6001 Is_Package_Or_Generic_Package (Scope_Id)
6002 and then In_Open_Scopes (Scope_Id)
6003 and then not In_Package_Body (Scope_Id)
6004 and then not In_Private_Part (Scope_Id);
6005 end In_Visible_Part;
6007 --------------------------------
6008 -- Incomplete_Or_Private_View --
6009 --------------------------------
6011 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
6012 function Inspect_Decls
6014 Taft : Boolean := False) return Entity_Id;
6015 -- Check whether a declarative region contains the incomplete or private
6022 function Inspect_Decls
6024 Taft : Boolean := False) return Entity_Id
6030 Decl := First (Decls);
6031 while Present (Decl) loop
6035 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6036 Match := Defining_Identifier (Decl);
6040 if Nkind_In (Decl, N_Private_Extension_Declaration,
6041 N_Private_Type_Declaration)
6043 Match := Defining_Identifier (Decl);
6048 and then Present (Full_View (Match))
6049 and then Full_View (Match) = Typ
6064 -- Start of processing for Incomplete_Or_Partial_View
6067 -- Incomplete type case
6069 Prev := Current_Entity_In_Scope (Typ);
6072 and then Is_Incomplete_Type (Prev)
6073 and then Present (Full_View (Prev))
6074 and then Full_View (Prev) = Typ
6079 -- Private or Taft amendment type case
6082 Pkg : constant Entity_Id := Scope (Typ);
6083 Pkg_Decl : Node_Id := Pkg;
6086 if Ekind (Pkg) = E_Package then
6087 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6088 Pkg_Decl := Parent (Pkg_Decl);
6091 -- It is knows that Typ has a private view, look for it in the
6092 -- visible declarations of the enclosing scope. A special case
6093 -- of this is when the two views have been exchanged - the full
6094 -- appears earlier than the private.
6096 if Has_Private_Declaration (Typ) then
6097 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6099 -- Exchanged view case, look in the private declarations
6102 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6107 -- Otherwise if this is the package body, then Typ is a potential
6108 -- Taft amendment type. The incomplete view should be located in
6109 -- the private declarations of the enclosing scope.
6111 elsif In_Package_Body (Pkg) then
6112 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6117 -- The type has no incomplete or private view
6120 end Incomplete_Or_Private_View;
6122 ---------------------------------
6123 -- Insert_Explicit_Dereference --
6124 ---------------------------------
6126 procedure Insert_Explicit_Dereference (N : Node_Id) is
6127 New_Prefix : constant Node_Id := Relocate_Node (N);
6128 Ent : Entity_Id := Empty;
6135 Save_Interps (N, New_Prefix);
6138 Make_Explicit_Dereference (Sloc (Parent (N)),
6139 Prefix => New_Prefix));
6141 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6143 if Is_Overloaded (New_Prefix) then
6145 -- The dereference is also overloaded, and its interpretations are
6146 -- the designated types of the interpretations of the original node.
6148 Set_Etype (N, Any_Type);
6150 Get_First_Interp (New_Prefix, I, It);
6151 while Present (It.Nam) loop
6154 if Is_Access_Type (T) then
6155 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6158 Get_Next_Interp (I, It);
6164 -- Prefix is unambiguous: mark the original prefix (which might
6165 -- Come_From_Source) as a reference, since the new (relocated) one
6166 -- won't be taken into account.
6168 if Is_Entity_Name (New_Prefix) then
6169 Ent := Entity (New_Prefix);
6172 -- For a retrieval of a subcomponent of some composite object,
6173 -- retrieve the ultimate entity if there is one.
6175 elsif Nkind (New_Prefix) = N_Selected_Component
6176 or else Nkind (New_Prefix) = N_Indexed_Component
6178 Pref := Prefix (New_Prefix);
6179 while Present (Pref)
6181 (Nkind (Pref) = N_Selected_Component
6182 or else Nkind (Pref) = N_Indexed_Component)
6184 Pref := Prefix (Pref);
6187 if Present (Pref) and then Is_Entity_Name (Pref) then
6188 Ent := Entity (Pref);
6192 -- Place the reference on the entity node
6194 if Present (Ent) then
6195 Generate_Reference (Ent, Pref);
6198 end Insert_Explicit_Dereference;
6200 ------------------------------------------
6201 -- Inspect_Deferred_Constant_Completion --
6202 ------------------------------------------
6204 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6208 Decl := First (Decls);
6209 while Present (Decl) loop
6211 -- Deferred constant signature
6213 if Nkind (Decl) = N_Object_Declaration
6214 and then Constant_Present (Decl)
6215 and then No (Expression (Decl))
6217 -- No need to check internally generated constants
6219 and then Comes_From_Source (Decl)
6221 -- The constant is not completed. A full object declaration or a
6222 -- pragma Import complete a deferred constant.
6224 and then not Has_Completion (Defining_Identifier (Decl))
6227 ("constant declaration requires initialization expression",
6228 Defining_Identifier (Decl));
6231 Decl := Next (Decl);
6233 end Inspect_Deferred_Constant_Completion;
6235 -----------------------------
6236 -- Is_Actual_Out_Parameter --
6237 -----------------------------
6239 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6243 Find_Actual (N, Formal, Call);
6244 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6245 end Is_Actual_Out_Parameter;
6247 -------------------------
6248 -- Is_Actual_Parameter --
6249 -------------------------
6251 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6252 PK : constant Node_Kind := Nkind (Parent (N));
6256 when N_Parameter_Association =>
6257 return N = Explicit_Actual_Parameter (Parent (N));
6259 when N_Function_Call | N_Procedure_Call_Statement =>
6260 return Is_List_Member (N)
6262 List_Containing (N) = Parameter_Associations (Parent (N));
6267 end Is_Actual_Parameter;
6269 --------------------------------
6270 -- Is_Actual_Tagged_Parameter --
6271 --------------------------------
6273 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6277 Find_Actual (N, Formal, Call);
6278 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6279 end Is_Actual_Tagged_Parameter;
6281 ---------------------
6282 -- Is_Aliased_View --
6283 ---------------------
6285 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6289 if Is_Entity_Name (Obj) then
6297 or else (Present (Renamed_Object (E))
6298 and then Is_Aliased_View (Renamed_Object (E)))))
6300 or else ((Is_Formal (E)
6301 or else Ekind (E) = E_Generic_In_Out_Parameter
6302 or else Ekind (E) = E_Generic_In_Parameter)
6303 and then Is_Tagged_Type (Etype (E)))
6305 or else (Is_Concurrent_Type (E)
6306 and then In_Open_Scopes (E))
6308 -- Current instance of type, either directly or as rewritten
6309 -- reference to the current object.
6311 or else (Is_Entity_Name (Original_Node (Obj))
6312 and then Present (Entity (Original_Node (Obj)))
6313 and then Is_Type (Entity (Original_Node (Obj))))
6315 or else (Is_Type (E) and then E = Current_Scope)
6317 or else (Is_Incomplete_Or_Private_Type (E)
6318 and then Full_View (E) = Current_Scope);
6320 elsif Nkind (Obj) = N_Selected_Component then
6321 return Is_Aliased (Entity (Selector_Name (Obj)));
6323 elsif Nkind (Obj) = N_Indexed_Component then
6324 return Has_Aliased_Components (Etype (Prefix (Obj)))
6326 (Is_Access_Type (Etype (Prefix (Obj)))
6328 Has_Aliased_Components
6329 (Designated_Type (Etype (Prefix (Obj)))));
6331 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6332 or else Nkind (Obj) = N_Type_Conversion
6334 return Is_Tagged_Type (Etype (Obj))
6335 and then Is_Aliased_View (Expression (Obj));
6337 elsif Nkind (Obj) = N_Explicit_Dereference then
6338 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6343 end Is_Aliased_View;
6345 -------------------------
6346 -- Is_Ancestor_Package --
6347 -------------------------
6349 function Is_Ancestor_Package
6351 E2 : Entity_Id) return Boolean
6358 and then Par /= Standard_Standard
6368 end Is_Ancestor_Package;
6370 ----------------------
6371 -- Is_Atomic_Object --
6372 ----------------------
6374 function Is_Atomic_Object (N : Node_Id) return Boolean is
6376 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6377 -- Determines if given object has atomic components
6379 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6380 -- If prefix is an implicit dereference, examine designated type
6382 ----------------------
6383 -- Is_Atomic_Prefix --
6384 ----------------------
6386 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6388 if Is_Access_Type (Etype (N)) then
6390 Has_Atomic_Components (Designated_Type (Etype (N)));
6392 return Object_Has_Atomic_Components (N);
6394 end Is_Atomic_Prefix;
6396 ----------------------------------
6397 -- Object_Has_Atomic_Components --
6398 ----------------------------------
6400 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6402 if Has_Atomic_Components (Etype (N))
6403 or else Is_Atomic (Etype (N))
6407 elsif Is_Entity_Name (N)
6408 and then (Has_Atomic_Components (Entity (N))
6409 or else Is_Atomic (Entity (N)))
6413 elsif Nkind (N) = N_Indexed_Component
6414 or else Nkind (N) = N_Selected_Component
6416 return Is_Atomic_Prefix (Prefix (N));
6421 end Object_Has_Atomic_Components;
6423 -- Start of processing for Is_Atomic_Object
6426 -- Predicate is not relevant to subprograms
6428 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6431 elsif Is_Atomic (Etype (N))
6432 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6436 elsif Nkind (N) = N_Indexed_Component
6437 or else Nkind (N) = N_Selected_Component
6439 return Is_Atomic_Prefix (Prefix (N));
6444 end Is_Atomic_Object;
6446 -----------------------------
6447 -- Is_Concurrent_Interface --
6448 -----------------------------
6450 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6455 (Is_Protected_Interface (T)
6456 or else Is_Synchronized_Interface (T)
6457 or else Is_Task_Interface (T));
6458 end Is_Concurrent_Interface;
6460 --------------------------------------
6461 -- Is_Controlling_Limited_Procedure --
6462 --------------------------------------
6464 function Is_Controlling_Limited_Procedure
6465 (Proc_Nam : Entity_Id) return Boolean
6467 Param_Typ : Entity_Id := Empty;
6470 if Ekind (Proc_Nam) = E_Procedure
6471 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6473 Param_Typ := Etype (Parameter_Type (First (
6474 Parameter_Specifications (Parent (Proc_Nam)))));
6476 -- In this case where an Itype was created, the procedure call has been
6479 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6480 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6482 Present (Parameter_Associations
6483 (Associated_Node_For_Itype (Proc_Nam)))
6486 Etype (First (Parameter_Associations
6487 (Associated_Node_For_Itype (Proc_Nam))));
6490 if Present (Param_Typ) then
6492 Is_Interface (Param_Typ)
6493 and then Is_Limited_Record (Param_Typ);
6497 end Is_Controlling_Limited_Procedure;
6499 -----------------------------
6500 -- Is_CPP_Constructor_Call --
6501 -----------------------------
6503 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6505 return Nkind (N) = N_Function_Call
6506 and then Is_CPP_Class (Etype (Etype (N)))
6507 and then Is_Constructor (Entity (Name (N)))
6508 and then Is_Imported (Entity (Name (N)));
6509 end Is_CPP_Constructor_Call;
6515 function Is_Delegate (T : Entity_Id) return Boolean is
6516 Desig_Type : Entity_Id;
6519 if VM_Target /= CLI_Target then
6523 -- Access-to-subprograms are delegates in CIL
6525 if Ekind (T) = E_Access_Subprogram_Type then
6529 if Ekind (T) not in Access_Kind then
6531 -- A delegate is a managed pointer. If no designated type is defined
6532 -- it means that it's not a delegate.
6537 Desig_Type := Etype (Directly_Designated_Type (T));
6539 if not Is_Tagged_Type (Desig_Type) then
6543 -- Test if the type is inherited from [mscorlib]System.Delegate
6545 while Etype (Desig_Type) /= Desig_Type loop
6546 if Chars (Scope (Desig_Type)) /= No_Name
6547 and then Is_Imported (Scope (Desig_Type))
6548 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6553 Desig_Type := Etype (Desig_Type);
6559 ----------------------------------------------
6560 -- Is_Dependent_Component_Of_Mutable_Object --
6561 ----------------------------------------------
6563 function Is_Dependent_Component_Of_Mutable_Object
6564 (Object : Node_Id) return Boolean
6567 Prefix_Type : Entity_Id;
6568 P_Aliased : Boolean := False;
6571 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6572 -- Returns True if and only if Comp is declared within a variant part
6574 --------------------------------
6575 -- Is_Declared_Within_Variant --
6576 --------------------------------
6578 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6579 Comp_Decl : constant Node_Id := Parent (Comp);
6580 Comp_List : constant Node_Id := Parent (Comp_Decl);
6582 return Nkind (Parent (Comp_List)) = N_Variant;
6583 end Is_Declared_Within_Variant;
6585 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6588 if Is_Variable (Object) then
6590 if Nkind (Object) = N_Selected_Component then
6591 P := Prefix (Object);
6592 Prefix_Type := Etype (P);
6594 if Is_Entity_Name (P) then
6596 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6597 Prefix_Type := Base_Type (Prefix_Type);
6600 if Is_Aliased (Entity (P)) then
6604 -- A discriminant check on a selected component may be expanded
6605 -- into a dereference when removing side-effects. Recover the
6606 -- original node and its type, which may be unconstrained.
6608 elsif Nkind (P) = N_Explicit_Dereference
6609 and then not (Comes_From_Source (P))
6611 P := Original_Node (P);
6612 Prefix_Type := Etype (P);
6615 -- Check for prefix being an aliased component???
6621 -- A heap object is constrained by its initial value
6623 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6624 -- the dereferenced case, since the access value might denote an
6625 -- unconstrained aliased object, whereas in Ada 95 the designated
6626 -- object is guaranteed to be constrained. A worst-case assumption
6627 -- has to apply in Ada 2005 because we can't tell at compile time
6628 -- whether the object is "constrained by its initial value"
6629 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6630 -- semantic rules -- these rules are acknowledged to need fixing).
6632 if Ada_Version < Ada_2005 then
6633 if Is_Access_Type (Prefix_Type)
6634 or else Nkind (P) = N_Explicit_Dereference
6639 elsif Ada_Version >= Ada_2005 then
6640 if Is_Access_Type (Prefix_Type) then
6642 -- If the access type is pool-specific, and there is no
6643 -- constrained partial view of the designated type, then the
6644 -- designated object is known to be constrained.
6646 if Ekind (Prefix_Type) = E_Access_Type
6647 and then not Has_Constrained_Partial_View
6648 (Designated_Type (Prefix_Type))
6652 -- Otherwise (general access type, or there is a constrained
6653 -- partial view of the designated type), we need to check
6654 -- based on the designated type.
6657 Prefix_Type := Designated_Type (Prefix_Type);
6663 Original_Record_Component (Entity (Selector_Name (Object)));
6665 -- As per AI-0017, the renaming is illegal in a generic body, even
6666 -- if the subtype is indefinite.
6668 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6670 if not Is_Constrained (Prefix_Type)
6671 and then (not Is_Indefinite_Subtype (Prefix_Type)
6673 (Is_Generic_Type (Prefix_Type)
6674 and then Ekind (Current_Scope) = E_Generic_Package
6675 and then In_Package_Body (Current_Scope)))
6677 and then (Is_Declared_Within_Variant (Comp)
6678 or else Has_Discriminant_Dependent_Constraint (Comp))
6679 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6685 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6689 elsif Nkind (Object) = N_Indexed_Component
6690 or else Nkind (Object) = N_Slice
6692 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6694 -- A type conversion that Is_Variable is a view conversion:
6695 -- go back to the denoted object.
6697 elsif Nkind (Object) = N_Type_Conversion then
6699 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6704 end Is_Dependent_Component_Of_Mutable_Object;
6706 ---------------------
6707 -- Is_Dereferenced --
6708 ---------------------
6710 function Is_Dereferenced (N : Node_Id) return Boolean is
6711 P : constant Node_Id := Parent (N);
6714 (Nkind (P) = N_Selected_Component
6716 Nkind (P) = N_Explicit_Dereference
6718 Nkind (P) = N_Indexed_Component
6720 Nkind (P) = N_Slice)
6721 and then Prefix (P) = N;
6722 end Is_Dereferenced;
6724 ----------------------
6725 -- Is_Descendent_Of --
6726 ----------------------
6728 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6733 pragma Assert (Nkind (T1) in N_Entity);
6734 pragma Assert (Nkind (T2) in N_Entity);
6736 T := Base_Type (T1);
6738 -- Immediate return if the types match
6743 -- Comment needed here ???
6745 elsif Ekind (T) = E_Class_Wide_Type then
6746 return Etype (T) = T2;
6754 -- Done if we found the type we are looking for
6759 -- Done if no more derivations to check
6766 -- Following test catches error cases resulting from prev errors
6768 elsif No (Etyp) then
6771 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6774 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6778 T := Base_Type (Etyp);
6781 end Is_Descendent_Of;
6783 ----------------------------
6784 -- Is_Expression_Function --
6785 ----------------------------
6787 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6788 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6791 return Ekind (Subp) = E_Function
6792 and then Nkind (Decl) = N_Subprogram_Declaration
6794 (Nkind (Original_Node (Decl)) = N_Expression_Function
6796 (Present (Corresponding_Body (Decl))
6798 Nkind (Original_Node
6799 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6800 = N_Expression_Function));
6801 end Is_Expression_Function;
6807 function Is_False (U : Uint) return Boolean is
6812 ---------------------------
6813 -- Is_Fixed_Model_Number --
6814 ---------------------------
6816 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6817 S : constant Ureal := Small_Value (T);
6818 M : Urealp.Save_Mark;
6822 R := (U = UR_Trunc (U / S) * S);
6825 end Is_Fixed_Model_Number;
6827 -------------------------------
6828 -- Is_Fully_Initialized_Type --
6829 -------------------------------
6831 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6833 if Is_Scalar_Type (Typ) then
6836 elsif Is_Access_Type (Typ) then
6839 elsif Is_Array_Type (Typ) then
6840 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6844 -- An interesting case, if we have a constrained type one of whose
6845 -- bounds is known to be null, then there are no elements to be
6846 -- initialized, so all the elements are initialized!
6848 if Is_Constrained (Typ) then
6851 Indx_Typ : Entity_Id;
6855 Indx := First_Index (Typ);
6856 while Present (Indx) loop
6857 if Etype (Indx) = Any_Type then
6860 -- If index is a range, use directly
6862 elsif Nkind (Indx) = N_Range then
6863 Lbd := Low_Bound (Indx);
6864 Hbd := High_Bound (Indx);
6867 Indx_Typ := Etype (Indx);
6869 if Is_Private_Type (Indx_Typ) then
6870 Indx_Typ := Full_View (Indx_Typ);
6873 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6876 Lbd := Type_Low_Bound (Indx_Typ);
6877 Hbd := Type_High_Bound (Indx_Typ);
6881 if Compile_Time_Known_Value (Lbd)
6882 and then Compile_Time_Known_Value (Hbd)
6884 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6894 -- If no null indexes, then type is not fully initialized
6900 elsif Is_Record_Type (Typ) then
6901 if Has_Discriminants (Typ)
6903 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6904 and then Is_Fully_Initialized_Variant (Typ)
6909 -- Controlled records are considered to be fully initialized if
6910 -- there is a user defined Initialize routine. This may not be
6911 -- entirely correct, but as the spec notes, we are guessing here
6912 -- what is best from the point of view of issuing warnings.
6914 if Is_Controlled (Typ) then
6916 Utyp : constant Entity_Id := Underlying_Type (Typ);
6919 if Present (Utyp) then
6921 Init : constant Entity_Id :=
6923 (Underlying_Type (Typ), Name_Initialize));
6927 and then Comes_From_Source (Init)
6929 Is_Predefined_File_Name
6930 (File_Name (Get_Source_File_Index (Sloc (Init))))
6934 elsif Has_Null_Extension (Typ)
6936 Is_Fully_Initialized_Type
6937 (Etype (Base_Type (Typ)))
6946 -- Otherwise see if all record components are initialized
6952 Ent := First_Entity (Typ);
6953 while Present (Ent) loop
6954 if Ekind (Ent) = E_Component
6955 and then (No (Parent (Ent))
6956 or else No (Expression (Parent (Ent))))
6957 and then not Is_Fully_Initialized_Type (Etype (Ent))
6959 -- Special VM case for tag components, which need to be
6960 -- defined in this case, but are never initialized as VMs
6961 -- are using other dispatching mechanisms. Ignore this
6962 -- uninitialized case. Note that this applies both to the
6963 -- uTag entry and the main vtable pointer (CPP_Class case).
6965 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6974 -- No uninitialized components, so type is fully initialized.
6975 -- Note that this catches the case of no components as well.
6979 elsif Is_Concurrent_Type (Typ) then
6982 elsif Is_Private_Type (Typ) then
6984 U : constant Entity_Id := Underlying_Type (Typ);
6990 return Is_Fully_Initialized_Type (U);
6997 end Is_Fully_Initialized_Type;
6999 ----------------------------------
7000 -- Is_Fully_Initialized_Variant --
7001 ----------------------------------
7003 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
7004 Loc : constant Source_Ptr := Sloc (Typ);
7005 Constraints : constant List_Id := New_List;
7006 Components : constant Elist_Id := New_Elmt_List;
7007 Comp_Elmt : Elmt_Id;
7009 Comp_List : Node_Id;
7011 Discr_Val : Node_Id;
7013 Report_Errors : Boolean;
7014 pragma Warnings (Off, Report_Errors);
7017 if Serious_Errors_Detected > 0 then
7021 if Is_Record_Type (Typ)
7022 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7023 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7025 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7027 Discr := First_Discriminant (Typ);
7028 while Present (Discr) loop
7029 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7030 Discr_Val := Expression (Parent (Discr));
7032 if Present (Discr_Val)
7033 and then Is_OK_Static_Expression (Discr_Val)
7035 Append_To (Constraints,
7036 Make_Component_Association (Loc,
7037 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7038 Expression => New_Copy (Discr_Val)));
7046 Next_Discriminant (Discr);
7051 Comp_List => Comp_List,
7052 Governed_By => Constraints,
7054 Report_Errors => Report_Errors);
7056 -- Check that each component present is fully initialized
7058 Comp_Elmt := First_Elmt (Components);
7059 while Present (Comp_Elmt) loop
7060 Comp_Id := Node (Comp_Elmt);
7062 if Ekind (Comp_Id) = E_Component
7063 and then (No (Parent (Comp_Id))
7064 or else No (Expression (Parent (Comp_Id))))
7065 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7070 Next_Elmt (Comp_Elmt);
7075 elsif Is_Private_Type (Typ) then
7077 U : constant Entity_Id := Underlying_Type (Typ);
7083 return Is_Fully_Initialized_Variant (U);
7089 end Is_Fully_Initialized_Variant;
7095 -- We seem to have a lot of overlapping functions that do similar things
7096 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7097 -- purely syntactic, it should be in Sem_Aux I would think???
7099 function Is_LHS (N : Node_Id) return Boolean is
7100 P : constant Node_Id := Parent (N);
7103 if Nkind (P) = N_Assignment_Statement then
7104 return Name (P) = N;
7107 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7109 return N = Prefix (P) and then Is_LHS (P);
7116 ----------------------------
7117 -- Is_Inherited_Operation --
7118 ----------------------------
7120 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7121 Kind : constant Node_Kind := Nkind (Parent (E));
7123 pragma Assert (Is_Overloadable (E));
7124 return Kind = N_Full_Type_Declaration
7125 or else Kind = N_Private_Extension_Declaration
7126 or else Kind = N_Subtype_Declaration
7127 or else (Ekind (E) = E_Enumeration_Literal
7128 and then Is_Derived_Type (Etype (E)));
7129 end Is_Inherited_Operation;
7131 -------------------------------------
7132 -- Is_Inherited_Operation_For_Type --
7133 -------------------------------------
7135 function Is_Inherited_Operation_For_Type
7136 (E : Entity_Id; Typ : Entity_Id) return Boolean
7139 return Is_Inherited_Operation (E)
7140 and then Etype (Parent (E)) = Typ;
7141 end Is_Inherited_Operation_For_Type;
7143 -----------------------------
7144 -- Is_Library_Level_Entity --
7145 -----------------------------
7147 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7149 -- The following is a small optimization, and it also properly handles
7150 -- discriminals, which in task bodies might appear in expressions before
7151 -- the corresponding procedure has been created, and which therefore do
7152 -- not have an assigned scope.
7154 if Is_Formal (E) then
7158 -- Normal test is simply that the enclosing dynamic scope is Standard
7160 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7161 end Is_Library_Level_Entity;
7163 ---------------------------------
7164 -- Is_Local_Variable_Reference --
7165 ---------------------------------
7167 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7169 if not Is_Entity_Name (Expr) then
7174 Ent : constant Entity_Id := Entity (Expr);
7175 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7177 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7180 return Present (Sub) and then Sub = Current_Subprogram;
7184 end Is_Local_Variable_Reference;
7186 -------------------------
7187 -- Is_Object_Reference --
7188 -------------------------
7190 function Is_Object_Reference (N : Node_Id) return Boolean is
7192 if Is_Entity_Name (N) then
7193 return Present (Entity (N)) and then Is_Object (Entity (N));
7197 when N_Indexed_Component | N_Slice =>
7199 Is_Object_Reference (Prefix (N))
7200 or else Is_Access_Type (Etype (Prefix (N)));
7202 -- In Ada95, a function call is a constant object; a procedure
7205 when N_Function_Call =>
7206 return Etype (N) /= Standard_Void_Type;
7208 -- A reference to the stream attribute Input is a function call
7210 when N_Attribute_Reference =>
7211 return Attribute_Name (N) = Name_Input;
7213 when N_Selected_Component =>
7215 Is_Object_Reference (Selector_Name (N))
7217 (Is_Object_Reference (Prefix (N))
7218 or else Is_Access_Type (Etype (Prefix (N))));
7220 when N_Explicit_Dereference =>
7223 -- A view conversion of a tagged object is an object reference
7225 when N_Type_Conversion =>
7226 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7227 and then Is_Tagged_Type (Etype (Expression (N)))
7228 and then Is_Object_Reference (Expression (N));
7230 -- An unchecked type conversion is considered to be an object if
7231 -- the operand is an object (this construction arises only as a
7232 -- result of expansion activities).
7234 when N_Unchecked_Type_Conversion =>
7241 end Is_Object_Reference;
7243 -----------------------------------
7244 -- Is_OK_Variable_For_Out_Formal --
7245 -----------------------------------
7247 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7249 Note_Possible_Modification (AV, Sure => True);
7251 -- We must reject parenthesized variable names. The check for
7252 -- Comes_From_Source is present because there are currently
7253 -- cases where the compiler violates this rule (e.g. passing
7254 -- a task object to its controlled Initialize routine).
7256 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7259 -- A variable is always allowed
7261 elsif Is_Variable (AV) then
7264 -- Unchecked conversions are allowed only if they come from the
7265 -- generated code, which sometimes uses unchecked conversions for out
7266 -- parameters in cases where code generation is unaffected. We tell
7267 -- source unchecked conversions by seeing if they are rewrites of an
7268 -- original Unchecked_Conversion function call, or of an explicit
7269 -- conversion of a function call.
7271 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7272 if Nkind (Original_Node (AV)) = N_Function_Call then
7275 elsif Comes_From_Source (AV)
7276 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7280 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7281 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7287 -- Normal type conversions are allowed if argument is a variable
7289 elsif Nkind (AV) = N_Type_Conversion then
7290 if Is_Variable (Expression (AV))
7291 and then Paren_Count (Expression (AV)) = 0
7293 Note_Possible_Modification (Expression (AV), Sure => True);
7296 -- We also allow a non-parenthesized expression that raises
7297 -- constraint error if it rewrites what used to be a variable
7299 elsif Raises_Constraint_Error (Expression (AV))
7300 and then Paren_Count (Expression (AV)) = 0
7301 and then Is_Variable (Original_Node (Expression (AV)))
7305 -- Type conversion of something other than a variable
7311 -- If this node is rewritten, then test the original form, if that is
7312 -- OK, then we consider the rewritten node OK (for example, if the
7313 -- original node is a conversion, then Is_Variable will not be true
7314 -- but we still want to allow the conversion if it converts a variable).
7316 elsif Original_Node (AV) /= AV then
7317 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7319 -- All other non-variables are rejected
7324 end Is_OK_Variable_For_Out_Formal;
7326 -----------------------------------
7327 -- Is_Partially_Initialized_Type --
7328 -----------------------------------
7330 function Is_Partially_Initialized_Type
7332 Include_Implicit : Boolean := True) return Boolean
7335 if Is_Scalar_Type (Typ) then
7338 elsif Is_Access_Type (Typ) then
7339 return Include_Implicit;
7341 elsif Is_Array_Type (Typ) then
7343 -- If component type is partially initialized, so is array type
7345 if Is_Partially_Initialized_Type
7346 (Component_Type (Typ), Include_Implicit)
7350 -- Otherwise we are only partially initialized if we are fully
7351 -- initialized (this is the empty array case, no point in us
7352 -- duplicating that code here).
7355 return Is_Fully_Initialized_Type (Typ);
7358 elsif Is_Record_Type (Typ) then
7360 -- A discriminated type is always partially initialized if in
7363 if Has_Discriminants (Typ) and then Include_Implicit then
7366 -- A tagged type is always partially initialized
7368 elsif Is_Tagged_Type (Typ) then
7371 -- Case of non-discriminated record
7377 Component_Present : Boolean := False;
7378 -- Set True if at least one component is present. If no
7379 -- components are present, then record type is fully
7380 -- initialized (another odd case, like the null array).
7383 -- Loop through components
7385 Ent := First_Entity (Typ);
7386 while Present (Ent) loop
7387 if Ekind (Ent) = E_Component then
7388 Component_Present := True;
7390 -- If a component has an initialization expression then
7391 -- the enclosing record type is partially initialized
7393 if Present (Parent (Ent))
7394 and then Present (Expression (Parent (Ent)))
7398 -- If a component is of a type which is itself partially
7399 -- initialized, then the enclosing record type is also.
7401 elsif Is_Partially_Initialized_Type
7402 (Etype (Ent), Include_Implicit)
7411 -- No initialized components found. If we found any components
7412 -- they were all uninitialized so the result is false.
7414 if Component_Present then
7417 -- But if we found no components, then all the components are
7418 -- initialized so we consider the type to be initialized.
7426 -- Concurrent types are always fully initialized
7428 elsif Is_Concurrent_Type (Typ) then
7431 -- For a private type, go to underlying type. If there is no underlying
7432 -- type then just assume this partially initialized. Not clear if this
7433 -- can happen in a non-error case, but no harm in testing for this.
7435 elsif Is_Private_Type (Typ) then
7437 U : constant Entity_Id := Underlying_Type (Typ);
7442 return Is_Partially_Initialized_Type (U, Include_Implicit);
7446 -- For any other type (are there any?) assume partially initialized
7451 end Is_Partially_Initialized_Type;
7453 ------------------------------------
7454 -- Is_Potentially_Persistent_Type --
7455 ------------------------------------
7457 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7462 -- For private type, test corresponding full type
7464 if Is_Private_Type (T) then
7465 return Is_Potentially_Persistent_Type (Full_View (T));
7467 -- Scalar types are potentially persistent
7469 elsif Is_Scalar_Type (T) then
7472 -- Record type is potentially persistent if not tagged and the types of
7473 -- all it components are potentially persistent, and no component has
7474 -- an initialization expression.
7476 elsif Is_Record_Type (T)
7477 and then not Is_Tagged_Type (T)
7478 and then not Is_Partially_Initialized_Type (T)
7480 Comp := First_Component (T);
7481 while Present (Comp) loop
7482 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7491 -- Array type is potentially persistent if its component type is
7492 -- potentially persistent and if all its constraints are static.
7494 elsif Is_Array_Type (T) then
7495 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7499 Indx := First_Index (T);
7500 while Present (Indx) loop
7501 if not Is_OK_Static_Subtype (Etype (Indx)) then
7510 -- All other types are not potentially persistent
7515 end Is_Potentially_Persistent_Type;
7517 ---------------------------------
7518 -- Is_Protected_Self_Reference --
7519 ---------------------------------
7521 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7523 function In_Access_Definition (N : Node_Id) return Boolean;
7524 -- Returns true if N belongs to an access definition
7526 --------------------------
7527 -- In_Access_Definition --
7528 --------------------------
7530 function In_Access_Definition (N : Node_Id) return Boolean is
7535 while Present (P) loop
7536 if Nkind (P) = N_Access_Definition then
7544 end In_Access_Definition;
7546 -- Start of processing for Is_Protected_Self_Reference
7549 -- Verify that prefix is analyzed and has the proper form. Note that
7550 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7551 -- produce the address of an entity, do not analyze their prefix
7552 -- because they denote entities that are not necessarily visible.
7553 -- Neither of them can apply to a protected type.
7555 return Ada_Version >= Ada_2005
7556 and then Is_Entity_Name (N)
7557 and then Present (Entity (N))
7558 and then Is_Protected_Type (Entity (N))
7559 and then In_Open_Scopes (Entity (N))
7560 and then not In_Access_Definition (N);
7561 end Is_Protected_Self_Reference;
7563 -----------------------------
7564 -- Is_RCI_Pkg_Spec_Or_Body --
7565 -----------------------------
7567 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7569 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7570 -- Return True if the unit of Cunit is an RCI package declaration
7572 ---------------------------
7573 -- Is_RCI_Pkg_Decl_Cunit --
7574 ---------------------------
7576 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7577 The_Unit : constant Node_Id := Unit (Cunit);
7580 if Nkind (The_Unit) /= N_Package_Declaration then
7584 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7585 end Is_RCI_Pkg_Decl_Cunit;
7587 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7590 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7592 (Nkind (Unit (Cunit)) = N_Package_Body
7593 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7594 end Is_RCI_Pkg_Spec_Or_Body;
7596 -----------------------------------------
7597 -- Is_Remote_Access_To_Class_Wide_Type --
7598 -----------------------------------------
7600 function Is_Remote_Access_To_Class_Wide_Type
7601 (E : Entity_Id) return Boolean
7604 -- A remote access to class-wide type is a general access to object type
7605 -- declared in the visible part of a Remote_Types or Remote_Call_
7608 return Ekind (E) = E_General_Access_Type
7609 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7610 end Is_Remote_Access_To_Class_Wide_Type;
7612 -----------------------------------------
7613 -- Is_Remote_Access_To_Subprogram_Type --
7614 -----------------------------------------
7616 function Is_Remote_Access_To_Subprogram_Type
7617 (E : Entity_Id) return Boolean
7620 return (Ekind (E) = E_Access_Subprogram_Type
7621 or else (Ekind (E) = E_Record_Type
7622 and then Present (Corresponding_Remote_Type (E))))
7623 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7624 end Is_Remote_Access_To_Subprogram_Type;
7626 --------------------
7627 -- Is_Remote_Call --
7628 --------------------
7630 function Is_Remote_Call (N : Node_Id) return Boolean is
7632 if Nkind (N) /= N_Procedure_Call_Statement
7633 and then Nkind (N) /= N_Function_Call
7635 -- An entry call cannot be remote
7639 elsif Nkind (Name (N)) in N_Has_Entity
7640 and then Is_Remote_Call_Interface (Entity (Name (N)))
7642 -- A subprogram declared in the spec of a RCI package is remote
7646 elsif Nkind (Name (N)) = N_Explicit_Dereference
7647 and then Is_Remote_Access_To_Subprogram_Type
7648 (Etype (Prefix (Name (N))))
7650 -- The dereference of a RAS is a remote call
7654 elsif Present (Controlling_Argument (N))
7655 and then Is_Remote_Access_To_Class_Wide_Type
7656 (Etype (Controlling_Argument (N)))
7658 -- Any primitive operation call with a controlling argument of
7659 -- a RACW type is a remote call.
7664 -- All other calls are local calls
7669 ----------------------
7670 -- Is_Renamed_Entry --
7671 ----------------------
7673 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7674 Orig_Node : Node_Id := Empty;
7675 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7677 function Is_Entry (Nam : Node_Id) return Boolean;
7678 -- Determine whether Nam is an entry. Traverse selectors if there are
7679 -- nested selected components.
7685 function Is_Entry (Nam : Node_Id) return Boolean is
7687 if Nkind (Nam) = N_Selected_Component then
7688 return Is_Entry (Selector_Name (Nam));
7691 return Ekind (Entity (Nam)) = E_Entry;
7694 -- Start of processing for Is_Renamed_Entry
7697 if Present (Alias (Proc_Nam)) then
7698 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7701 -- Look for a rewritten subprogram renaming declaration
7703 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7704 and then Present (Original_Node (Subp_Decl))
7706 Orig_Node := Original_Node (Subp_Decl);
7709 -- The rewritten subprogram is actually an entry
7711 if Present (Orig_Node)
7712 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7713 and then Is_Entry (Name (Orig_Node))
7719 end Is_Renamed_Entry;
7721 ----------------------
7722 -- Is_Selector_Name --
7723 ----------------------
7725 function Is_Selector_Name (N : Node_Id) return Boolean is
7727 if not Is_List_Member (N) then
7729 P : constant Node_Id := Parent (N);
7730 K : constant Node_Kind := Nkind (P);
7733 (K = N_Expanded_Name or else
7734 K = N_Generic_Association or else
7735 K = N_Parameter_Association or else
7736 K = N_Selected_Component)
7737 and then Selector_Name (P) = N;
7742 L : constant List_Id := List_Containing (N);
7743 P : constant Node_Id := Parent (L);
7745 return (Nkind (P) = N_Discriminant_Association
7746 and then Selector_Names (P) = L)
7748 (Nkind (P) = N_Component_Association
7749 and then Choices (P) = L);
7752 end Is_Selector_Name;
7754 ----------------------------------
7755 -- Is_SPARK_Initialization_Expr --
7756 ----------------------------------
7758 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7761 Comp_Assn : Node_Id;
7762 Orig_N : constant Node_Id := Original_Node (N);
7767 if not Comes_From_Source (Orig_N) then
7771 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7773 case Nkind (Orig_N) is
7774 when N_Character_Literal |
7782 if Is_Entity_Name (Orig_N)
7783 and then Present (Entity (Orig_N)) -- needed in some cases
7785 case Ekind (Entity (Orig_N)) is
7787 E_Enumeration_Literal |
7792 if Is_Type (Entity (Orig_N)) then
7800 when N_Qualified_Expression |
7801 N_Type_Conversion =>
7802 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7805 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7809 N_Membership_Test =>
7810 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7811 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7814 N_Extension_Aggregate =>
7815 if Nkind (Orig_N) = N_Extension_Aggregate then
7816 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7819 Expr := First (Expressions (Orig_N));
7820 while Present (Expr) loop
7821 if not Is_SPARK_Initialization_Expr (Expr) then
7829 Comp_Assn := First (Component_Associations (Orig_N));
7830 while Present (Comp_Assn) loop
7831 Expr := Expression (Comp_Assn);
7832 if Present (Expr) -- needed for box association
7833 and then not Is_SPARK_Initialization_Expr (Expr)
7842 when N_Attribute_Reference =>
7843 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7844 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7847 Expr := First (Expressions (Orig_N));
7848 while Present (Expr) loop
7849 if not Is_SPARK_Initialization_Expr (Expr) then
7857 -- Selected components might be expanded named not yet resolved, so
7858 -- default on the safe side. (Eg on sparklex.ads)
7860 when N_Selected_Component =>
7869 end Is_SPARK_Initialization_Expr;
7871 -------------------------------
7872 -- Is_SPARK_Object_Reference --
7873 -------------------------------
7875 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7877 if Is_Entity_Name (N) then
7878 return Present (Entity (N))
7880 (Ekind_In (Entity (N), E_Constant, E_Variable)
7881 or else Ekind (Entity (N)) in Formal_Kind);
7885 when N_Selected_Component =>
7886 return Is_SPARK_Object_Reference (Prefix (N));
7892 end Is_SPARK_Object_Reference;
7898 function Is_Statement (N : Node_Id) return Boolean is
7901 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7902 or else Nkind (N) = N_Procedure_Call_Statement;
7905 ---------------------------------
7906 -- Is_Synchronized_Tagged_Type --
7907 ---------------------------------
7909 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7910 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7913 -- A task or protected type derived from an interface is a tagged type.
7914 -- Such a tagged type is called a synchronized tagged type, as are
7915 -- synchronized interfaces and private extensions whose declaration
7916 -- includes the reserved word synchronized.
7918 return (Is_Tagged_Type (E)
7919 and then (Kind = E_Task_Type
7920 or else Kind = E_Protected_Type))
7923 and then Is_Synchronized_Interface (E))
7925 (Ekind (E) = E_Record_Type_With_Private
7926 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7927 and then (Synchronized_Present (Parent (E))
7928 or else Is_Synchronized_Interface (Etype (E))));
7929 end Is_Synchronized_Tagged_Type;
7935 function Is_Transfer (N : Node_Id) return Boolean is
7936 Kind : constant Node_Kind := Nkind (N);
7939 if Kind = N_Simple_Return_Statement
7941 Kind = N_Extended_Return_Statement
7943 Kind = N_Goto_Statement
7945 Kind = N_Raise_Statement
7947 Kind = N_Requeue_Statement
7951 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7952 and then No (Condition (N))
7956 elsif Kind = N_Procedure_Call_Statement
7957 and then Is_Entity_Name (Name (N))
7958 and then Present (Entity (Name (N)))
7959 and then No_Return (Entity (Name (N)))
7963 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7975 function Is_True (U : Uint) return Boolean is
7980 -------------------------------
7981 -- Is_Universal_Numeric_Type --
7982 -------------------------------
7984 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7986 return T = Universal_Integer or else T = Universal_Real;
7987 end Is_Universal_Numeric_Type;
7993 function Is_Value_Type (T : Entity_Id) return Boolean is
7995 return VM_Target = CLI_Target
7996 and then Nkind (T) in N_Has_Chars
7997 and then Chars (T) /= No_Name
7998 and then Get_Name_String (Chars (T)) = "valuetype";
8001 ---------------------
8002 -- Is_VMS_Operator --
8003 ---------------------
8005 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
8007 -- The VMS operators are declared in a child of System that is loaded
8008 -- through pragma Extend_System. In some rare cases a program is run
8009 -- with this extension but without indicating that the target is VMS.
8011 return Ekind (Op) = E_Function
8012 and then Is_Intrinsic_Subprogram (Op)
8014 ((Present_System_Aux
8015 and then Scope (Op) = System_Aux_Id)
8018 and then Scope (Scope (Op)) = RTU_Entity (System)));
8019 end Is_VMS_Operator;
8025 function Is_Variable
8027 Use_Original_Node : Boolean := True) return Boolean
8029 Orig_Node : Node_Id;
8031 function In_Protected_Function (E : Entity_Id) return Boolean;
8032 -- Within a protected function, the private components of the enclosing
8033 -- protected type are constants. A function nested within a (protected)
8034 -- procedure is not itself protected.
8036 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8037 -- Prefixes can involve implicit dereferences, in which case we must
8038 -- test for the case of a reference of a constant access type, which can
8039 -- can never be a variable.
8041 ---------------------------
8042 -- In_Protected_Function --
8043 ---------------------------
8045 function In_Protected_Function (E : Entity_Id) return Boolean is
8046 Prot : constant Entity_Id := Scope (E);
8050 if not Is_Protected_Type (Prot) then
8054 while Present (S) and then S /= Prot loop
8055 if Ekind (S) = E_Function and then Scope (S) = Prot then
8064 end In_Protected_Function;
8066 ------------------------
8067 -- Is_Variable_Prefix --
8068 ------------------------
8070 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8072 if Is_Access_Type (Etype (P)) then
8073 return not Is_Access_Constant (Root_Type (Etype (P)));
8075 -- For the case of an indexed component whose prefix has a packed
8076 -- array type, the prefix has been rewritten into a type conversion.
8077 -- Determine variable-ness from the converted expression.
8079 elsif Nkind (P) = N_Type_Conversion
8080 and then not Comes_From_Source (P)
8081 and then Is_Array_Type (Etype (P))
8082 and then Is_Packed (Etype (P))
8084 return Is_Variable (Expression (P));
8087 return Is_Variable (P);
8089 end Is_Variable_Prefix;
8091 -- Start of processing for Is_Variable
8094 -- Check if we perform the test on the original node since this may be a
8095 -- test of syntactic categories which must not be disturbed by whatever
8096 -- rewriting might have occurred. For example, an aggregate, which is
8097 -- certainly NOT a variable, could be turned into a variable by
8100 if Use_Original_Node then
8101 Orig_Node := Original_Node (N);
8106 -- Definitely OK if Assignment_OK is set. Since this is something that
8107 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8109 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8112 -- Normally we go to the original node, but there is one exception where
8113 -- we use the rewritten node, namely when it is an explicit dereference.
8114 -- The generated code may rewrite a prefix which is an access type with
8115 -- an explicit dereference. The dereference is a variable, even though
8116 -- the original node may not be (since it could be a constant of the
8119 -- In Ada 2005 we have a further case to consider: the prefix may be a
8120 -- function call given in prefix notation. The original node appears to
8121 -- be a selected component, but we need to examine the call.
8123 elsif Nkind (N) = N_Explicit_Dereference
8124 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8125 and then Present (Etype (Orig_Node))
8126 and then Is_Access_Type (Etype (Orig_Node))
8128 -- Note that if the prefix is an explicit dereference that does not
8129 -- come from source, we must check for a rewritten function call in
8130 -- prefixed notation before other forms of rewriting, to prevent a
8134 (Nkind (Orig_Node) = N_Function_Call
8135 and then not Is_Access_Constant (Etype (Prefix (N))))
8137 Is_Variable_Prefix (Original_Node (Prefix (N)));
8139 -- A function call is never a variable
8141 elsif Nkind (N) = N_Function_Call then
8144 -- All remaining checks use the original node
8146 elsif Is_Entity_Name (Orig_Node)
8147 and then Present (Entity (Orig_Node))
8150 E : constant Entity_Id := Entity (Orig_Node);
8151 K : constant Entity_Kind := Ekind (E);
8154 return (K = E_Variable
8155 and then Nkind (Parent (E)) /= N_Exception_Handler)
8156 or else (K = E_Component
8157 and then not In_Protected_Function (E))
8158 or else K = E_Out_Parameter
8159 or else K = E_In_Out_Parameter
8160 or else K = E_Generic_In_Out_Parameter
8162 -- Current instance of type:
8164 or else (Is_Type (E) and then In_Open_Scopes (E))
8165 or else (Is_Incomplete_Or_Private_Type (E)
8166 and then In_Open_Scopes (Full_View (E)));
8170 case Nkind (Orig_Node) is
8171 when N_Indexed_Component | N_Slice =>
8172 return Is_Variable_Prefix (Prefix (Orig_Node));
8174 when N_Selected_Component =>
8175 return Is_Variable_Prefix (Prefix (Orig_Node))
8176 and then Is_Variable (Selector_Name (Orig_Node));
8178 -- For an explicit dereference, the type of the prefix cannot
8179 -- be an access to constant or an access to subprogram.
8181 when N_Explicit_Dereference =>
8183 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8185 return Is_Access_Type (Typ)
8186 and then not Is_Access_Constant (Root_Type (Typ))
8187 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8190 -- The type conversion is the case where we do not deal with the
8191 -- context dependent special case of an actual parameter. Thus
8192 -- the type conversion is only considered a variable for the
8193 -- purposes of this routine if the target type is tagged. However,
8194 -- a type conversion is considered to be a variable if it does not
8195 -- come from source (this deals for example with the conversions
8196 -- of expressions to their actual subtypes).
8198 when N_Type_Conversion =>
8199 return Is_Variable (Expression (Orig_Node))
8201 (not Comes_From_Source (Orig_Node)
8203 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8205 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8207 -- GNAT allows an unchecked type conversion as a variable. This
8208 -- only affects the generation of internal expanded code, since
8209 -- calls to instantiations of Unchecked_Conversion are never
8210 -- considered variables (since they are function calls).
8211 -- This is also true for expression actions.
8213 when N_Unchecked_Type_Conversion =>
8214 return Is_Variable (Expression (Orig_Node));
8222 ---------------------------
8223 -- Is_Visibly_Controlled --
8224 ---------------------------
8226 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8227 Root : constant Entity_Id := Root_Type (T);
8229 return Chars (Scope (Root)) = Name_Finalization
8230 and then Chars (Scope (Scope (Root))) = Name_Ada
8231 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8232 end Is_Visibly_Controlled;
8234 ------------------------
8235 -- Is_Volatile_Object --
8236 ------------------------
8238 function Is_Volatile_Object (N : Node_Id) return Boolean is
8240 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8241 -- Determines if given object has volatile components
8243 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8244 -- If prefix is an implicit dereference, examine designated type
8246 ------------------------
8247 -- Is_Volatile_Prefix --
8248 ------------------------
8250 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8251 Typ : constant Entity_Id := Etype (N);
8254 if Is_Access_Type (Typ) then
8256 Dtyp : constant Entity_Id := Designated_Type (Typ);
8259 return Is_Volatile (Dtyp)
8260 or else Has_Volatile_Components (Dtyp);
8264 return Object_Has_Volatile_Components (N);
8266 end Is_Volatile_Prefix;
8268 ------------------------------------
8269 -- Object_Has_Volatile_Components --
8270 ------------------------------------
8272 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8273 Typ : constant Entity_Id := Etype (N);
8276 if Is_Volatile (Typ)
8277 or else Has_Volatile_Components (Typ)
8281 elsif Is_Entity_Name (N)
8282 and then (Has_Volatile_Components (Entity (N))
8283 or else Is_Volatile (Entity (N)))
8287 elsif Nkind (N) = N_Indexed_Component
8288 or else Nkind (N) = N_Selected_Component
8290 return Is_Volatile_Prefix (Prefix (N));
8295 end Object_Has_Volatile_Components;
8297 -- Start of processing for Is_Volatile_Object
8300 if Is_Volatile (Etype (N))
8301 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8305 elsif Nkind (N) = N_Indexed_Component
8306 or else Nkind (N) = N_Selected_Component
8308 return Is_Volatile_Prefix (Prefix (N));
8313 end Is_Volatile_Object;
8315 -------------------------
8316 -- Kill_Current_Values --
8317 -------------------------
8319 procedure Kill_Current_Values
8321 Last_Assignment_Only : Boolean := False)
8324 -- ??? do we have to worry about clearing cached checks?
8326 if Is_Assignable (Ent) then
8327 Set_Last_Assignment (Ent, Empty);
8330 if Is_Object (Ent) then
8331 if not Last_Assignment_Only then
8333 Set_Current_Value (Ent, Empty);
8335 if not Can_Never_Be_Null (Ent) then
8336 Set_Is_Known_Non_Null (Ent, False);
8339 Set_Is_Known_Null (Ent, False);
8341 -- Reset Is_Known_Valid unless type is always valid, or if we have
8342 -- a loop parameter (loop parameters are always valid, since their
8343 -- bounds are defined by the bounds given in the loop header).
8345 if not Is_Known_Valid (Etype (Ent))
8346 and then Ekind (Ent) /= E_Loop_Parameter
8348 Set_Is_Known_Valid (Ent, False);
8352 end Kill_Current_Values;
8354 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8357 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8358 -- Clear current value for entity E and all entities chained to E
8360 ------------------------------------------
8361 -- Kill_Current_Values_For_Entity_Chain --
8362 ------------------------------------------
8364 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8368 while Present (Ent) loop
8369 Kill_Current_Values (Ent, Last_Assignment_Only);
8372 end Kill_Current_Values_For_Entity_Chain;
8374 -- Start of processing for Kill_Current_Values
8377 -- Kill all saved checks, a special case of killing saved values
8379 if not Last_Assignment_Only then
8383 -- Loop through relevant scopes, which includes the current scope and
8384 -- any parent scopes if the current scope is a block or a package.
8389 -- Clear current values of all entities in current scope
8391 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8393 -- If scope is a package, also clear current values of all
8394 -- private entities in the scope.
8396 if Is_Package_Or_Generic_Package (S)
8397 or else Is_Concurrent_Type (S)
8399 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8402 -- If this is a not a subprogram, deal with parents
8404 if not Is_Subprogram (S) then
8406 exit Scope_Loop when S = Standard_Standard;
8410 end loop Scope_Loop;
8411 end Kill_Current_Values;
8413 --------------------------
8414 -- Kill_Size_Check_Code --
8415 --------------------------
8417 procedure Kill_Size_Check_Code (E : Entity_Id) is
8419 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8420 and then Present (Size_Check_Code (E))
8422 Remove (Size_Check_Code (E));
8423 Set_Size_Check_Code (E, Empty);
8425 end Kill_Size_Check_Code;
8427 --------------------------
8428 -- Known_To_Be_Assigned --
8429 --------------------------
8431 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8432 P : constant Node_Id := Parent (N);
8437 -- Test left side of assignment
8439 when N_Assignment_Statement =>
8440 return N = Name (P);
8442 -- Function call arguments are never lvalues
8444 when N_Function_Call =>
8447 -- Positional parameter for procedure or accept call
8449 when N_Procedure_Call_Statement |
8458 Proc := Get_Subprogram_Entity (P);
8464 -- If we are not a list member, something is strange, so
8465 -- be conservative and return False.
8467 if not Is_List_Member (N) then
8471 -- We are going to find the right formal by stepping forward
8472 -- through the formals, as we step backwards in the actuals.
8474 Form := First_Formal (Proc);
8477 -- If no formal, something is weird, so be conservative
8478 -- and return False.
8489 return Ekind (Form) /= E_In_Parameter;
8492 -- Named parameter for procedure or accept call
8494 when N_Parameter_Association =>
8500 Proc := Get_Subprogram_Entity (Parent (P));
8506 -- Loop through formals to find the one that matches
8508 Form := First_Formal (Proc);
8510 -- If no matching formal, that's peculiar, some kind of
8511 -- previous error, so return False to be conservative.
8517 -- Else test for match
8519 if Chars (Form) = Chars (Selector_Name (P)) then
8520 return Ekind (Form) /= E_In_Parameter;
8527 -- Test for appearing in a conversion that itself appears
8528 -- in an lvalue context, since this should be an lvalue.
8530 when N_Type_Conversion =>
8531 return Known_To_Be_Assigned (P);
8533 -- All other references are definitely not known to be modifications
8539 end Known_To_Be_Assigned;
8541 ---------------------------
8542 -- Last_Source_Statement --
8543 ---------------------------
8545 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8549 N := Last (Statements (HSS));
8550 while Present (N) loop
8551 exit when Comes_From_Source (N);
8556 end Last_Source_Statement;
8558 ----------------------------------
8559 -- Matching_Static_Array_Bounds --
8560 ----------------------------------
8562 function Matching_Static_Array_Bounds
8564 R_Typ : Node_Id) return Boolean
8566 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8567 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8579 if L_Ndims /= R_Ndims then
8583 -- Unconstrained types do not have static bounds
8585 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8589 -- First treat specially the first dimension, as the lower bound and
8590 -- length of string literals are not stored like those of arrays.
8592 if Ekind (L_Typ) = E_String_Literal_Subtype then
8593 L_Low := String_Literal_Low_Bound (L_Typ);
8594 L_Len := String_Literal_Length (L_Typ);
8596 L_Index := First_Index (L_Typ);
8597 Get_Index_Bounds (L_Index, L_Low, L_High);
8599 if Is_OK_Static_Expression (L_Low)
8600 and then Is_OK_Static_Expression (L_High)
8602 if Expr_Value (L_High) < Expr_Value (L_Low) then
8605 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8612 if Ekind (R_Typ) = E_String_Literal_Subtype then
8613 R_Low := String_Literal_Low_Bound (R_Typ);
8614 R_Len := String_Literal_Length (R_Typ);
8616 R_Index := First_Index (R_Typ);
8617 Get_Index_Bounds (R_Index, R_Low, R_High);
8619 if Is_OK_Static_Expression (R_Low)
8620 and then Is_OK_Static_Expression (R_High)
8622 if Expr_Value (R_High) < Expr_Value (R_Low) then
8625 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8632 if Is_OK_Static_Expression (L_Low)
8633 and then Is_OK_Static_Expression (R_Low)
8634 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8635 and then L_Len = R_Len
8642 -- Then treat all other dimensions
8644 for Indx in 2 .. L_Ndims loop
8648 Get_Index_Bounds (L_Index, L_Low, L_High);
8649 Get_Index_Bounds (R_Index, R_Low, R_High);
8651 if Is_OK_Static_Expression (L_Low)
8652 and then Is_OK_Static_Expression (L_High)
8653 and then Is_OK_Static_Expression (R_Low)
8654 and then Is_OK_Static_Expression (R_High)
8655 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8656 and then Expr_Value (L_High) = Expr_Value (R_High)
8664 -- If we fall through the loop, all indexes matched
8667 end Matching_Static_Array_Bounds;
8673 function May_Be_Lvalue (N : Node_Id) return Boolean is
8674 P : constant Node_Id := Parent (N);
8679 -- Test left side of assignment
8681 when N_Assignment_Statement =>
8682 return N = Name (P);
8684 -- Test prefix of component or attribute. Note that the prefix of an
8685 -- explicit or implicit dereference cannot be an l-value.
8687 when N_Attribute_Reference =>
8688 return N = Prefix (P)
8689 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8691 -- For an expanded name, the name is an lvalue if the expanded name
8692 -- is an lvalue, but the prefix is never an lvalue, since it is just
8693 -- the scope where the name is found.
8695 when N_Expanded_Name =>
8696 if N = Prefix (P) then
8697 return May_Be_Lvalue (P);
8702 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8703 -- B is a little interesting, if we have A.B := 3, there is some
8704 -- discussion as to whether B is an lvalue or not, we choose to say
8705 -- it is. Note however that A is not an lvalue if it is of an access
8706 -- type since this is an implicit dereference.
8708 when N_Selected_Component =>
8710 and then Present (Etype (N))
8711 and then Is_Access_Type (Etype (N))
8715 return May_Be_Lvalue (P);
8718 -- For an indexed component or slice, the index or slice bounds is
8719 -- never an lvalue. The prefix is an lvalue if the indexed component
8720 -- or slice is an lvalue, except if it is an access type, where we
8721 -- have an implicit dereference.
8723 when N_Indexed_Component =>
8725 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8729 return May_Be_Lvalue (P);
8732 -- Prefix of a reference is an lvalue if the reference is an lvalue
8735 return May_Be_Lvalue (P);
8737 -- Prefix of explicit dereference is never an lvalue
8739 when N_Explicit_Dereference =>
8742 -- Positional parameter for subprogram, entry, or accept call.
8743 -- In older versions of Ada function call arguments are never
8744 -- lvalues. In Ada 2012 functions can have in-out parameters.
8746 when N_Function_Call |
8747 N_Procedure_Call_Statement |
8748 N_Entry_Call_Statement |
8751 if Nkind (P) = N_Function_Call
8752 and then Ada_Version < Ada_2012
8757 -- The following mechanism is clumsy and fragile. A single
8758 -- flag set in Resolve_Actuals would be preferable ???
8766 Proc := Get_Subprogram_Entity (P);
8772 -- If we are not a list member, something is strange, so
8773 -- be conservative and return True.
8775 if not Is_List_Member (N) then
8779 -- We are going to find the right formal by stepping forward
8780 -- through the formals, as we step backwards in the actuals.
8782 Form := First_Formal (Proc);
8785 -- If no formal, something is weird, so be conservative
8797 return Ekind (Form) /= E_In_Parameter;
8800 -- Named parameter for procedure or accept call
8802 when N_Parameter_Association =>
8808 Proc := Get_Subprogram_Entity (Parent (P));
8814 -- Loop through formals to find the one that matches
8816 Form := First_Formal (Proc);
8818 -- If no matching formal, that's peculiar, some kind of
8819 -- previous error, so return True to be conservative.
8825 -- Else test for match
8827 if Chars (Form) = Chars (Selector_Name (P)) then
8828 return Ekind (Form) /= E_In_Parameter;
8835 -- Test for appearing in a conversion that itself appears in an
8836 -- lvalue context, since this should be an lvalue.
8838 when N_Type_Conversion =>
8839 return May_Be_Lvalue (P);
8841 -- Test for appearance in object renaming declaration
8843 when N_Object_Renaming_Declaration =>
8846 -- All other references are definitely not lvalues
8854 -----------------------
8855 -- Mark_Coextensions --
8856 -----------------------
8858 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8859 Is_Dynamic : Boolean;
8860 -- Indicates whether the context causes nested coextensions to be
8861 -- dynamic or static
8863 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8864 -- Recognize an allocator node and label it as a dynamic coextension
8866 --------------------
8867 -- Mark_Allocator --
8868 --------------------
8870 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8872 if Nkind (N) = N_Allocator then
8874 Set_Is_Dynamic_Coextension (N);
8876 -- If the allocator expression is potentially dynamic, it may
8877 -- be expanded out of order and require dynamic allocation
8878 -- anyway, so we treat the coextension itself as dynamic.
8879 -- Potential optimization ???
8881 elsif Nkind (Expression (N)) = N_Qualified_Expression
8882 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8884 Set_Is_Dynamic_Coextension (N);
8887 Set_Is_Static_Coextension (N);
8894 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8896 -- Start of processing Mark_Coextensions
8899 case Nkind (Context_Nod) is
8900 when N_Assignment_Statement |
8901 N_Simple_Return_Statement =>
8902 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8904 when N_Object_Declaration =>
8905 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8907 -- This routine should not be called for constructs which may not
8908 -- contain coextensions.
8911 raise Program_Error;
8914 Mark_Allocators (Root_Nod);
8915 end Mark_Coextensions;
8917 ----------------------
8918 -- Needs_One_Actual --
8919 ----------------------
8921 function Needs_One_Actual (E : Entity_Id) return Boolean is
8925 if Ada_Version >= Ada_2005
8926 and then Present (First_Formal (E))
8928 Formal := Next_Formal (First_Formal (E));
8929 while Present (Formal) loop
8930 if No (Default_Value (Formal)) then
8934 Next_Formal (Formal);
8942 end Needs_One_Actual;
8944 ------------------------
8945 -- New_Copy_List_Tree --
8946 ------------------------
8948 function New_Copy_List_Tree (List : List_Id) return List_Id is
8953 if List = No_List then
8960 while Present (E) loop
8961 Append (New_Copy_Tree (E), NL);
8967 end New_Copy_List_Tree;
8973 use Atree.Unchecked_Access;
8974 use Atree_Private_Part;
8976 -- Our approach here requires a two pass traversal of the tree. The
8977 -- first pass visits all nodes that eventually will be copied looking
8978 -- for defining Itypes. If any defining Itypes are found, then they are
8979 -- copied, and an entry is added to the replacement map. In the second
8980 -- phase, the tree is copied, using the replacement map to replace any
8981 -- Itype references within the copied tree.
8983 -- The following hash tables are used if the Map supplied has more
8984 -- than hash threshold entries to speed up access to the map. If
8985 -- there are fewer entries, then the map is searched sequentially
8986 -- (because setting up a hash table for only a few entries takes
8987 -- more time than it saves.
8989 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8990 -- Hash function used for hash operations
8996 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8998 return Nat (E) mod (NCT_Header_Num'Last + 1);
9005 -- The hash table NCT_Assoc associates old entities in the table
9006 -- with their corresponding new entities (i.e. the pairs of entries
9007 -- presented in the original Map argument are Key-Element pairs).
9009 package NCT_Assoc is new Simple_HTable (
9010 Header_Num => NCT_Header_Num,
9011 Element => Entity_Id,
9012 No_Element => Empty,
9014 Hash => New_Copy_Hash,
9015 Equal => Types."=");
9017 ---------------------
9018 -- NCT_Itype_Assoc --
9019 ---------------------
9021 -- The hash table NCT_Itype_Assoc contains entries only for those
9022 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9023 -- The key is the associated node, and the element is the new node
9024 -- itself (NOT the associated node for the new node).
9026 package NCT_Itype_Assoc is new Simple_HTable (
9027 Header_Num => NCT_Header_Num,
9028 Element => Entity_Id,
9029 No_Element => Empty,
9031 Hash => New_Copy_Hash,
9032 Equal => Types."=");
9034 -- Start of processing for New_Copy_Tree function
9036 function New_Copy_Tree
9038 Map : Elist_Id := No_Elist;
9039 New_Sloc : Source_Ptr := No_Location;
9040 New_Scope : Entity_Id := Empty) return Node_Id
9042 Actual_Map : Elist_Id := Map;
9043 -- This is the actual map for the copy. It is initialized with the
9044 -- given elements, and then enlarged as required for Itypes that are
9045 -- copied during the first phase of the copy operation. The visit
9046 -- procedures add elements to this map as Itypes are encountered.
9047 -- The reason we cannot use Map directly, is that it may well be
9048 -- (and normally is) initialized to No_Elist, and if we have mapped
9049 -- entities, we have to reset it to point to a real Elist.
9051 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9052 -- Called during second phase to map entities into their corresponding
9053 -- copies using Actual_Map. If the argument is not an entity, or is not
9054 -- in Actual_Map, then it is returned unchanged.
9056 procedure Build_NCT_Hash_Tables;
9057 -- Builds hash tables (number of elements >= threshold value)
9059 function Copy_Elist_With_Replacement
9060 (Old_Elist : Elist_Id) return Elist_Id;
9061 -- Called during second phase to copy element list doing replacements
9063 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9064 -- Called during the second phase to process a copied Itype. The actual
9065 -- copy happened during the first phase (so that we could make the entry
9066 -- in the mapping), but we still have to deal with the descendents of
9067 -- the copied Itype and copy them where necessary.
9069 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9070 -- Called during second phase to copy list doing replacements
9072 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9073 -- Called during second phase to copy node doing replacements
9075 procedure Visit_Elist (E : Elist_Id);
9076 -- Called during first phase to visit all elements of an Elist
9078 procedure Visit_Field (F : Union_Id; N : Node_Id);
9079 -- Visit a single field, recursing to call Visit_Node or Visit_List
9080 -- if the field is a syntactic descendent of the current node (i.e.
9081 -- its parent is Node N).
9083 procedure Visit_Itype (Old_Itype : Entity_Id);
9084 -- Called during first phase to visit subsidiary fields of a defining
9085 -- Itype, and also create a copy and make an entry in the replacement
9086 -- map for the new copy.
9088 procedure Visit_List (L : List_Id);
9089 -- Called during first phase to visit all elements of a List
9091 procedure Visit_Node (N : Node_Or_Entity_Id);
9092 -- Called during first phase to visit a node and all its subtrees
9098 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9103 if not Has_Extension (N) or else No (Actual_Map) then
9106 elsif NCT_Hash_Tables_Used then
9107 Ent := NCT_Assoc.Get (Entity_Id (N));
9109 if Present (Ent) then
9115 -- No hash table used, do serial search
9118 E := First_Elmt (Actual_Map);
9119 while Present (E) loop
9120 if Node (E) = N then
9121 return Node (Next_Elmt (E));
9123 E := Next_Elmt (Next_Elmt (E));
9131 ---------------------------
9132 -- Build_NCT_Hash_Tables --
9133 ---------------------------
9135 procedure Build_NCT_Hash_Tables is
9139 if NCT_Hash_Table_Setup then
9141 NCT_Itype_Assoc.Reset;
9144 Elmt := First_Elmt (Actual_Map);
9145 while Present (Elmt) loop
9148 -- Get new entity, and associate old and new
9151 NCT_Assoc.Set (Ent, Node (Elmt));
9153 if Is_Type (Ent) then
9155 Anode : constant Entity_Id :=
9156 Associated_Node_For_Itype (Ent);
9159 if Present (Anode) then
9161 -- Enter a link between the associated node of the
9162 -- old Itype and the new Itype, for updating later
9163 -- when node is copied.
9165 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9173 NCT_Hash_Tables_Used := True;
9174 NCT_Hash_Table_Setup := True;
9175 end Build_NCT_Hash_Tables;
9177 ---------------------------------
9178 -- Copy_Elist_With_Replacement --
9179 ---------------------------------
9181 function Copy_Elist_With_Replacement
9182 (Old_Elist : Elist_Id) return Elist_Id
9185 New_Elist : Elist_Id;
9188 if No (Old_Elist) then
9192 New_Elist := New_Elmt_List;
9194 M := First_Elmt (Old_Elist);
9195 while Present (M) loop
9196 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9202 end Copy_Elist_With_Replacement;
9204 ---------------------------------
9205 -- Copy_Itype_With_Replacement --
9206 ---------------------------------
9208 -- This routine exactly parallels its phase one analog Visit_Itype,
9210 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9212 -- Translate Next_Entity, Scope and Etype fields, in case they
9213 -- reference entities that have been mapped into copies.
9215 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9216 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9218 if Present (New_Scope) then
9219 Set_Scope (New_Itype, New_Scope);
9221 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9224 -- Copy referenced fields
9226 if Is_Discrete_Type (New_Itype) then
9227 Set_Scalar_Range (New_Itype,
9228 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9230 elsif Has_Discriminants (Base_Type (New_Itype)) then
9231 Set_Discriminant_Constraint (New_Itype,
9232 Copy_Elist_With_Replacement
9233 (Discriminant_Constraint (New_Itype)));
9235 elsif Is_Array_Type (New_Itype) then
9236 if Present (First_Index (New_Itype)) then
9237 Set_First_Index (New_Itype,
9238 First (Copy_List_With_Replacement
9239 (List_Containing (First_Index (New_Itype)))));
9242 if Is_Packed (New_Itype) then
9243 Set_Packed_Array_Type (New_Itype,
9244 Copy_Node_With_Replacement
9245 (Packed_Array_Type (New_Itype)));
9248 end Copy_Itype_With_Replacement;
9250 --------------------------------
9251 -- Copy_List_With_Replacement --
9252 --------------------------------
9254 function Copy_List_With_Replacement
9255 (Old_List : List_Id) return List_Id
9261 if Old_List = No_List then
9265 New_List := Empty_List;
9267 E := First (Old_List);
9268 while Present (E) loop
9269 Append (Copy_Node_With_Replacement (E), New_List);
9275 end Copy_List_With_Replacement;
9277 --------------------------------
9278 -- Copy_Node_With_Replacement --
9279 --------------------------------
9281 function Copy_Node_With_Replacement
9282 (Old_Node : Node_Id) return Node_Id
9286 procedure Adjust_Named_Associations
9287 (Old_Node : Node_Id;
9288 New_Node : Node_Id);
9289 -- If a call node has named associations, these are chained through
9290 -- the First_Named_Actual, Next_Named_Actual links. These must be
9291 -- propagated separately to the new parameter list, because these
9292 -- are not syntactic fields.
9294 function Copy_Field_With_Replacement
9295 (Field : Union_Id) return Union_Id;
9296 -- Given Field, which is a field of Old_Node, return a copy of it
9297 -- if it is a syntactic field (i.e. its parent is Node), setting
9298 -- the parent of the copy to poit to New_Node. Otherwise returns
9299 -- the field (possibly mapped if it is an entity).
9301 -------------------------------
9302 -- Adjust_Named_Associations --
9303 -------------------------------
9305 procedure Adjust_Named_Associations
9306 (Old_Node : Node_Id;
9316 Old_E := First (Parameter_Associations (Old_Node));
9317 New_E := First (Parameter_Associations (New_Node));
9318 while Present (Old_E) loop
9319 if Nkind (Old_E) = N_Parameter_Association
9320 and then Present (Next_Named_Actual (Old_E))
9322 if First_Named_Actual (Old_Node)
9323 = Explicit_Actual_Parameter (Old_E)
9325 Set_First_Named_Actual
9326 (New_Node, Explicit_Actual_Parameter (New_E));
9329 -- Now scan parameter list from the beginning,to locate
9330 -- next named actual, which can be out of order.
9332 Old_Next := First (Parameter_Associations (Old_Node));
9333 New_Next := First (Parameter_Associations (New_Node));
9335 while Nkind (Old_Next) /= N_Parameter_Association
9336 or else Explicit_Actual_Parameter (Old_Next)
9337 /= Next_Named_Actual (Old_E)
9343 Set_Next_Named_Actual
9344 (New_E, Explicit_Actual_Parameter (New_Next));
9350 end Adjust_Named_Associations;
9352 ---------------------------------
9353 -- Copy_Field_With_Replacement --
9354 ---------------------------------
9356 function Copy_Field_With_Replacement
9357 (Field : Union_Id) return Union_Id
9360 if Field = Union_Id (Empty) then
9363 elsif Field in Node_Range then
9365 Old_N : constant Node_Id := Node_Id (Field);
9369 -- If syntactic field, as indicated by the parent pointer
9370 -- being set, then copy the referenced node recursively.
9372 if Parent (Old_N) = Old_Node then
9373 New_N := Copy_Node_With_Replacement (Old_N);
9375 if New_N /= Old_N then
9376 Set_Parent (New_N, New_Node);
9379 -- For semantic fields, update possible entity reference
9380 -- from the replacement map.
9383 New_N := Assoc (Old_N);
9386 return Union_Id (New_N);
9389 elsif Field in List_Range then
9391 Old_L : constant List_Id := List_Id (Field);
9395 -- If syntactic field, as indicated by the parent pointer,
9396 -- then recursively copy the entire referenced list.
9398 if Parent (Old_L) = Old_Node then
9399 New_L := Copy_List_With_Replacement (Old_L);
9400 Set_Parent (New_L, New_Node);
9402 -- For semantic list, just returned unchanged
9408 return Union_Id (New_L);
9411 -- Anything other than a list or a node is returned unchanged
9416 end Copy_Field_With_Replacement;
9418 -- Start of processing for Copy_Node_With_Replacement
9421 if Old_Node <= Empty_Or_Error then
9424 elsif Has_Extension (Old_Node) then
9425 return Assoc (Old_Node);
9428 New_Node := New_Copy (Old_Node);
9430 -- If the node we are copying is the associated node of a
9431 -- previously copied Itype, then adjust the associated node
9432 -- of the copy of that Itype accordingly.
9434 if Present (Actual_Map) then
9440 -- Case of hash table used
9442 if NCT_Hash_Tables_Used then
9443 Ent := NCT_Itype_Assoc.Get (Old_Node);
9445 if Present (Ent) then
9446 Set_Associated_Node_For_Itype (Ent, New_Node);
9449 -- Case of no hash table used
9452 E := First_Elmt (Actual_Map);
9453 while Present (E) loop
9454 if Is_Itype (Node (E))
9456 Old_Node = Associated_Node_For_Itype (Node (E))
9458 Set_Associated_Node_For_Itype
9459 (Node (Next_Elmt (E)), New_Node);
9462 E := Next_Elmt (Next_Elmt (E));
9468 -- Recursively copy descendents
9471 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9473 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9475 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9477 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9479 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9481 -- Adjust Sloc of new node if necessary
9483 if New_Sloc /= No_Location then
9484 Set_Sloc (New_Node, New_Sloc);
9486 -- If we adjust the Sloc, then we are essentially making
9487 -- a completely new node, so the Comes_From_Source flag
9488 -- should be reset to the proper default value.
9490 Nodes.Table (New_Node).Comes_From_Source :=
9491 Default_Node.Comes_From_Source;
9494 -- If the node is call and has named associations,
9495 -- set the corresponding links in the copy.
9497 if (Nkind (Old_Node) = N_Function_Call
9498 or else Nkind (Old_Node) = N_Entry_Call_Statement
9500 Nkind (Old_Node) = N_Procedure_Call_Statement)
9501 and then Present (First_Named_Actual (Old_Node))
9503 Adjust_Named_Associations (Old_Node, New_Node);
9506 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9507 -- The replacement mechanism applies to entities, and is not used
9508 -- here. Eventually we may need a more general graph-copying
9509 -- routine. For now, do a sequential search to find desired node.
9511 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9512 and then Present (First_Real_Statement (Old_Node))
9515 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9519 N1 := First (Statements (Old_Node));
9520 N2 := First (Statements (New_Node));
9522 while N1 /= Old_F loop
9527 Set_First_Real_Statement (New_Node, N2);
9532 -- All done, return copied node
9535 end Copy_Node_With_Replacement;
9541 procedure Visit_Elist (E : Elist_Id) is
9545 Elmt := First_Elmt (E);
9547 while Elmt /= No_Elmt loop
9548 Visit_Node (Node (Elmt));
9558 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9560 if F = Union_Id (Empty) then
9563 elsif F in Node_Range then
9565 -- Copy node if it is syntactic, i.e. its parent pointer is
9566 -- set to point to the field that referenced it (certain
9567 -- Itypes will also meet this criterion, which is fine, since
9568 -- these are clearly Itypes that do need to be copied, since
9569 -- we are copying their parent.)
9571 if Parent (Node_Id (F)) = N then
9572 Visit_Node (Node_Id (F));
9575 -- Another case, if we are pointing to an Itype, then we want
9576 -- to copy it if its associated node is somewhere in the tree
9579 -- Note: the exclusion of self-referential copies is just an
9580 -- optimization, since the search of the already copied list
9581 -- would catch it, but it is a common case (Etype pointing
9582 -- to itself for an Itype that is a base type).
9584 elsif Has_Extension (Node_Id (F))
9585 and then Is_Itype (Entity_Id (F))
9586 and then Node_Id (F) /= N
9592 P := Associated_Node_For_Itype (Node_Id (F));
9593 while Present (P) loop
9595 Visit_Node (Node_Id (F));
9602 -- An Itype whose parent is not being copied definitely
9603 -- should NOT be copied, since it does not belong in any
9604 -- sense to the copied subtree.
9610 elsif F in List_Range
9611 and then Parent (List_Id (F)) = N
9613 Visit_List (List_Id (F));
9622 procedure Visit_Itype (Old_Itype : Entity_Id) is
9623 New_Itype : Entity_Id;
9628 -- Itypes that describe the designated type of access to subprograms
9629 -- have the structure of subprogram declarations, with signatures,
9630 -- etc. Either we duplicate the signatures completely, or choose to
9631 -- share such itypes, which is fine because their elaboration will
9632 -- have no side effects.
9634 if Ekind (Old_Itype) = E_Subprogram_Type then
9638 New_Itype := New_Copy (Old_Itype);
9640 -- The new Itype has all the attributes of the old one, and
9641 -- we just copy the contents of the entity. However, the back-end
9642 -- needs different names for debugging purposes, so we create a
9643 -- new internal name for it in all cases.
9645 Set_Chars (New_Itype, New_Internal_Name ('T'));
9647 -- If our associated node is an entity that has already been copied,
9648 -- then set the associated node of the copy to point to the right
9649 -- copy. If we have copied an Itype that is itself the associated
9650 -- node of some previously copied Itype, then we set the right
9651 -- pointer in the other direction.
9653 if Present (Actual_Map) then
9655 -- Case of hash tables used
9657 if NCT_Hash_Tables_Used then
9659 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9661 if Present (Ent) then
9662 Set_Associated_Node_For_Itype (New_Itype, Ent);
9665 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9666 if Present (Ent) then
9667 Set_Associated_Node_For_Itype (Ent, New_Itype);
9669 -- If the hash table has no association for this Itype and
9670 -- its associated node, enter one now.
9674 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9677 -- Case of hash tables not used
9680 E := First_Elmt (Actual_Map);
9681 while Present (E) loop
9682 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9683 Set_Associated_Node_For_Itype
9684 (New_Itype, Node (Next_Elmt (E)));
9687 if Is_Type (Node (E))
9689 Old_Itype = Associated_Node_For_Itype (Node (E))
9691 Set_Associated_Node_For_Itype
9692 (Node (Next_Elmt (E)), New_Itype);
9695 E := Next_Elmt (Next_Elmt (E));
9700 if Present (Freeze_Node (New_Itype)) then
9701 Set_Is_Frozen (New_Itype, False);
9702 Set_Freeze_Node (New_Itype, Empty);
9705 -- Add new association to map
9707 if No (Actual_Map) then
9708 Actual_Map := New_Elmt_List;
9711 Append_Elmt (Old_Itype, Actual_Map);
9712 Append_Elmt (New_Itype, Actual_Map);
9714 if NCT_Hash_Tables_Used then
9715 NCT_Assoc.Set (Old_Itype, New_Itype);
9718 NCT_Table_Entries := NCT_Table_Entries + 1;
9720 if NCT_Table_Entries > NCT_Hash_Threshold then
9721 Build_NCT_Hash_Tables;
9725 -- If a record subtype is simply copied, the entity list will be
9726 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9728 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9729 Set_Cloned_Subtype (New_Itype, Old_Itype);
9732 -- Visit descendents that eventually get copied
9734 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9736 if Is_Discrete_Type (Old_Itype) then
9737 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9739 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9740 -- ??? This should involve call to Visit_Field
9741 Visit_Elist (Discriminant_Constraint (Old_Itype));
9743 elsif Is_Array_Type (Old_Itype) then
9744 if Present (First_Index (Old_Itype)) then
9745 Visit_Field (Union_Id (List_Containing
9746 (First_Index (Old_Itype))),
9750 if Is_Packed (Old_Itype) then
9751 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9761 procedure Visit_List (L : List_Id) is
9764 if L /= No_List then
9767 while Present (N) loop
9778 procedure Visit_Node (N : Node_Or_Entity_Id) is
9780 -- Start of processing for Visit_Node
9783 -- Handle case of an Itype, which must be copied
9785 if Has_Extension (N)
9786 and then Is_Itype (N)
9788 -- Nothing to do if already in the list. This can happen with an
9789 -- Itype entity that appears more than once in the tree.
9790 -- Note that we do not want to visit descendents in this case.
9792 -- Test for already in list when hash table is used
9794 if NCT_Hash_Tables_Used then
9795 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9799 -- Test for already in list when hash table not used
9805 if Present (Actual_Map) then
9806 E := First_Elmt (Actual_Map);
9807 while Present (E) loop
9808 if Node (E) = N then
9811 E := Next_Elmt (Next_Elmt (E));
9821 -- Visit descendents
9823 Visit_Field (Field1 (N), N);
9824 Visit_Field (Field2 (N), N);
9825 Visit_Field (Field3 (N), N);
9826 Visit_Field (Field4 (N), N);
9827 Visit_Field (Field5 (N), N);
9830 -- Start of processing for New_Copy_Tree
9835 -- See if we should use hash table
9837 if No (Actual_Map) then
9838 NCT_Hash_Tables_Used := False;
9845 NCT_Table_Entries := 0;
9847 Elmt := First_Elmt (Actual_Map);
9848 while Present (Elmt) loop
9849 NCT_Table_Entries := NCT_Table_Entries + 1;
9854 if NCT_Table_Entries > NCT_Hash_Threshold then
9855 Build_NCT_Hash_Tables;
9857 NCT_Hash_Tables_Used := False;
9862 -- Hash table set up if required, now start phase one by visiting
9863 -- top node (we will recursively visit the descendents).
9865 Visit_Node (Source);
9867 -- Now the second phase of the copy can start. First we process
9868 -- all the mapped entities, copying their descendents.
9870 if Present (Actual_Map) then
9873 New_Itype : Entity_Id;
9875 Elmt := First_Elmt (Actual_Map);
9876 while Present (Elmt) loop
9878 New_Itype := Node (Elmt);
9879 Copy_Itype_With_Replacement (New_Itype);
9885 -- Now we can copy the actual tree
9887 return Copy_Node_With_Replacement (Source);
9890 -------------------------
9891 -- New_External_Entity --
9892 -------------------------
9894 function New_External_Entity
9895 (Kind : Entity_Kind;
9896 Scope_Id : Entity_Id;
9897 Sloc_Value : Source_Ptr;
9898 Related_Id : Entity_Id;
9900 Suffix_Index : Nat := 0;
9901 Prefix : Character := ' ') return Entity_Id
9903 N : constant Entity_Id :=
9904 Make_Defining_Identifier (Sloc_Value,
9906 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9909 Set_Ekind (N, Kind);
9910 Set_Is_Internal (N, True);
9911 Append_Entity (N, Scope_Id);
9912 Set_Public_Status (N);
9914 if Kind in Type_Kind then
9915 Init_Size_Align (N);
9919 end New_External_Entity;
9921 -------------------------
9922 -- New_Internal_Entity --
9923 -------------------------
9925 function New_Internal_Entity
9926 (Kind : Entity_Kind;
9927 Scope_Id : Entity_Id;
9928 Sloc_Value : Source_Ptr;
9929 Id_Char : Character) return Entity_Id
9931 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9934 Set_Ekind (N, Kind);
9935 Set_Is_Internal (N, True);
9936 Append_Entity (N, Scope_Id);
9938 if Kind in Type_Kind then
9939 Init_Size_Align (N);
9943 end New_Internal_Entity;
9949 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9953 -- If we are pointing at a positional parameter, it is a member of a
9954 -- node list (the list of parameters), and the next parameter is the
9955 -- next node on the list, unless we hit a parameter association, then
9956 -- we shift to using the chain whose head is the First_Named_Actual in
9957 -- the parent, and then is threaded using the Next_Named_Actual of the
9958 -- Parameter_Association. All this fiddling is because the original node
9959 -- list is in the textual call order, and what we need is the
9960 -- declaration order.
9962 if Is_List_Member (Actual_Id) then
9963 N := Next (Actual_Id);
9965 if Nkind (N) = N_Parameter_Association then
9966 return First_Named_Actual (Parent (Actual_Id));
9972 return Next_Named_Actual (Parent (Actual_Id));
9976 procedure Next_Actual (Actual_Id : in out Node_Id) is
9978 Actual_Id := Next_Actual (Actual_Id);
9981 -----------------------
9982 -- Normalize_Actuals --
9983 -----------------------
9985 -- Chain actuals according to formals of subprogram. If there are no named
9986 -- associations, the chain is simply the list of Parameter Associations,
9987 -- since the order is the same as the declaration order. If there are named
9988 -- associations, then the First_Named_Actual field in the N_Function_Call
9989 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9990 -- node for the parameter that comes first in declaration order. The
9991 -- remaining named parameters are then chained in declaration order using
9992 -- Next_Named_Actual.
9994 -- This routine also verifies that the number of actuals is compatible with
9995 -- the number and default values of formals, but performs no type checking
9996 -- (type checking is done by the caller).
9998 -- If the matching succeeds, Success is set to True and the caller proceeds
9999 -- with type-checking. If the match is unsuccessful, then Success is set to
10000 -- False, and the caller attempts a different interpretation, if there is
10003 -- If the flag Report is on, the call is not overloaded, and a failure to
10004 -- match can be reported here, rather than in the caller.
10006 procedure Normalize_Actuals
10010 Success : out Boolean)
10012 Actuals : constant List_Id := Parameter_Associations (N);
10013 Actual : Node_Id := Empty;
10014 Formal : Entity_Id;
10015 Last : Node_Id := Empty;
10016 First_Named : Node_Id := Empty;
10019 Formals_To_Match : Integer := 0;
10020 Actuals_To_Match : Integer := 0;
10022 procedure Chain (A : Node_Id);
10023 -- Add named actual at the proper place in the list, using the
10024 -- Next_Named_Actual link.
10026 function Reporting return Boolean;
10027 -- Determines if an error is to be reported. To report an error, we
10028 -- need Report to be True, and also we do not report errors caused
10029 -- by calls to init procs that occur within other init procs. Such
10030 -- errors must always be cascaded errors, since if all the types are
10031 -- declared correctly, the compiler will certainly build decent calls!
10037 procedure Chain (A : Node_Id) is
10041 -- Call node points to first actual in list
10043 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10046 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10050 Set_Next_Named_Actual (Last, Empty);
10057 function Reporting return Boolean is
10062 elsif not Within_Init_Proc then
10065 elsif Is_Init_Proc (Entity (Name (N))) then
10073 -- Start of processing for Normalize_Actuals
10076 if Is_Access_Type (S) then
10078 -- The name in the call is a function call that returns an access
10079 -- to subprogram. The designated type has the list of formals.
10081 Formal := First_Formal (Designated_Type (S));
10083 Formal := First_Formal (S);
10086 while Present (Formal) loop
10087 Formals_To_Match := Formals_To_Match + 1;
10088 Next_Formal (Formal);
10091 -- Find if there is a named association, and verify that no positional
10092 -- associations appear after named ones.
10094 if Present (Actuals) then
10095 Actual := First (Actuals);
10098 while Present (Actual)
10099 and then Nkind (Actual) /= N_Parameter_Association
10101 Actuals_To_Match := Actuals_To_Match + 1;
10105 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10107 -- Most common case: positional notation, no defaults
10112 elsif Actuals_To_Match > Formals_To_Match then
10114 -- Too many actuals: will not work
10117 if Is_Entity_Name (Name (N)) then
10118 Error_Msg_N ("too many arguments in call to&", Name (N));
10120 Error_Msg_N ("too many arguments in call", N);
10128 First_Named := Actual;
10130 while Present (Actual) loop
10131 if Nkind (Actual) /= N_Parameter_Association then
10133 ("positional parameters not allowed after named ones", Actual);
10138 Actuals_To_Match := Actuals_To_Match + 1;
10144 if Present (Actuals) then
10145 Actual := First (Actuals);
10148 Formal := First_Formal (S);
10149 while Present (Formal) loop
10151 -- Match the formals in order. If the corresponding actual is
10152 -- positional, nothing to do. Else scan the list of named actuals
10153 -- to find the one with the right name.
10155 if Present (Actual)
10156 and then Nkind (Actual) /= N_Parameter_Association
10159 Actuals_To_Match := Actuals_To_Match - 1;
10160 Formals_To_Match := Formals_To_Match - 1;
10163 -- For named parameters, search the list of actuals to find
10164 -- one that matches the next formal name.
10166 Actual := First_Named;
10168 while Present (Actual) loop
10169 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10172 Actuals_To_Match := Actuals_To_Match - 1;
10173 Formals_To_Match := Formals_To_Match - 1;
10181 if Ekind (Formal) /= E_In_Parameter
10182 or else No (Default_Value (Formal))
10185 if (Comes_From_Source (S)
10186 or else Sloc (S) = Standard_Location)
10187 and then Is_Overloadable (S)
10191 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10193 (Nkind (Parent (N)) = N_Function_Call
10195 Nkind (Parent (N)) = N_Parameter_Association))
10196 and then Ekind (S) /= E_Function
10198 Set_Etype (N, Etype (S));
10200 Error_Msg_Name_1 := Chars (S);
10201 Error_Msg_Sloc := Sloc (S);
10203 ("missing argument for parameter & " &
10204 "in call to % declared #", N, Formal);
10207 elsif Is_Overloadable (S) then
10208 Error_Msg_Name_1 := Chars (S);
10210 -- Point to type derivation that generated the
10213 Error_Msg_Sloc := Sloc (Parent (S));
10216 ("missing argument for parameter & " &
10217 "in call to % (inherited) #", N, Formal);
10221 ("missing argument for parameter &", N, Formal);
10229 Formals_To_Match := Formals_To_Match - 1;
10234 Next_Formal (Formal);
10237 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10244 -- Find some superfluous named actual that did not get
10245 -- attached to the list of associations.
10247 Actual := First (Actuals);
10248 while Present (Actual) loop
10249 if Nkind (Actual) = N_Parameter_Association
10250 and then Actual /= Last
10251 and then No (Next_Named_Actual (Actual))
10253 Error_Msg_N ("unmatched actual & in call",
10254 Selector_Name (Actual));
10265 end Normalize_Actuals;
10267 --------------------------------
10268 -- Note_Possible_Modification --
10269 --------------------------------
10271 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10272 Modification_Comes_From_Source : constant Boolean :=
10273 Comes_From_Source (Parent (N));
10279 -- Loop to find referenced entity, if there is one
10286 if Is_Entity_Name (Exp) then
10287 Ent := Entity (Exp);
10289 -- If the entity is missing, it is an undeclared identifier,
10290 -- and there is nothing to annotate.
10296 elsif Nkind (Exp) = N_Explicit_Dereference then
10298 P : constant Node_Id := Prefix (Exp);
10301 if Nkind (P) = N_Selected_Component
10303 Entry_Formal (Entity (Selector_Name (P))))
10305 -- Case of a reference to an entry formal
10307 Ent := Entry_Formal (Entity (Selector_Name (P)));
10309 elsif Nkind (P) = N_Identifier
10310 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10311 and then Present (Expression (Parent (Entity (P))))
10312 and then Nkind (Expression (Parent (Entity (P))))
10315 -- Case of a reference to a value on which side effects have
10318 Exp := Prefix (Expression (Parent (Entity (P))));
10327 elsif Nkind (Exp) = N_Type_Conversion
10328 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10330 Exp := Expression (Exp);
10333 elsif Nkind (Exp) = N_Slice
10334 or else Nkind (Exp) = N_Indexed_Component
10335 or else Nkind (Exp) = N_Selected_Component
10337 Exp := Prefix (Exp);
10344 -- Now look for entity being referenced
10346 if Present (Ent) then
10347 if Is_Object (Ent) then
10348 if Comes_From_Source (Exp)
10349 or else Modification_Comes_From_Source
10351 -- Give warning if pragma unmodified given and we are
10352 -- sure this is a modification.
10354 if Has_Pragma_Unmodified (Ent) and then Sure then
10355 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10358 Set_Never_Set_In_Source (Ent, False);
10361 Set_Is_True_Constant (Ent, False);
10362 Set_Current_Value (Ent, Empty);
10363 Set_Is_Known_Null (Ent, False);
10365 if not Can_Never_Be_Null (Ent) then
10366 Set_Is_Known_Non_Null (Ent, False);
10369 -- Follow renaming chain
10371 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10372 and then Present (Renamed_Object (Ent))
10374 Exp := Renamed_Object (Ent);
10378 -- Generate a reference only if the assignment comes from
10379 -- source. This excludes, for example, calls to a dispatching
10380 -- assignment operation when the left-hand side is tagged.
10382 if Modification_Comes_From_Source then
10383 Generate_Reference (Ent, Exp, 'm');
10385 -- If the target of the assignment is the bound variable
10386 -- in an iterator, indicate that the corresponding array
10387 -- or container is also modified.
10389 if Ada_Version >= Ada_2012
10391 Nkind (Parent (Ent)) = N_Iterator_Specification
10394 Domain : constant Node_Id := Name (Parent (Ent));
10397 -- TBD : in the full version of the construct, the
10398 -- domain of iteration can be given by an expression.
10400 if Is_Entity_Name (Domain) then
10401 Generate_Reference (Entity (Domain), Exp, 'm');
10402 Set_Is_True_Constant (Entity (Domain), False);
10403 Set_Never_Set_In_Source (Entity (Domain), False);
10409 Check_Nested_Access (Ent);
10414 -- If we are sure this is a modification from source, and we know
10415 -- this modifies a constant, then give an appropriate warning.
10417 if Overlays_Constant (Ent)
10418 and then Modification_Comes_From_Source
10422 A : constant Node_Id := Address_Clause (Ent);
10424 if Present (A) then
10426 Exp : constant Node_Id := Expression (A);
10428 if Nkind (Exp) = N_Attribute_Reference
10429 and then Attribute_Name (Exp) = Name_Address
10430 and then Is_Entity_Name (Prefix (Exp))
10432 Error_Msg_Sloc := Sloc (A);
10434 ("constant& may be modified via address clause#?",
10435 N, Entity (Prefix (Exp)));
10445 end Note_Possible_Modification;
10447 -------------------------
10448 -- Object_Access_Level --
10449 -------------------------
10451 function Object_Access_Level (Obj : Node_Id) return Uint is
10454 -- Returns the static accessibility level of the view denoted by Obj. Note
10455 -- that the value returned is the result of a call to Scope_Depth. Only
10456 -- scope depths associated with dynamic scopes can actually be returned.
10457 -- Since only relative levels matter for accessibility checking, the fact
10458 -- that the distance between successive levels of accessibility is not
10459 -- always one is immaterial (invariant: if level(E2) is deeper than
10460 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10462 function Reference_To (Obj : Node_Id) return Node_Id;
10463 -- An explicit dereference is created when removing side-effects from
10464 -- expressions for constraint checking purposes. In this case a local
10465 -- access type is created for it. The correct access level is that of
10466 -- the original source node. We detect this case by noting that the
10467 -- prefix of the dereference is created by an object declaration whose
10468 -- initial expression is a reference.
10474 function Reference_To (Obj : Node_Id) return Node_Id is
10475 Pref : constant Node_Id := Prefix (Obj);
10477 if Is_Entity_Name (Pref)
10478 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10479 and then Present (Expression (Parent (Entity (Pref))))
10480 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10482 return (Prefix (Expression (Parent (Entity (Pref)))));
10488 -- Start of processing for Object_Access_Level
10491 if Is_Entity_Name (Obj) then
10494 if Is_Prival (E) then
10495 E := Prival_Link (E);
10498 -- If E is a type then it denotes a current instance. For this case
10499 -- we add one to the normal accessibility level of the type to ensure
10500 -- that current instances are treated as always being deeper than
10501 -- than the level of any visible named access type (see 3.10.2(21)).
10503 if Is_Type (E) then
10504 return Type_Access_Level (E) + 1;
10506 elsif Present (Renamed_Object (E)) then
10507 return Object_Access_Level (Renamed_Object (E));
10509 -- Similarly, if E is a component of the current instance of a
10510 -- protected type, any instance of it is assumed to be at a deeper
10511 -- level than the type. For a protected object (whose type is an
10512 -- anonymous protected type) its components are at the same level
10513 -- as the type itself.
10515 elsif not Is_Overloadable (E)
10516 and then Ekind (Scope (E)) = E_Protected_Type
10517 and then Comes_From_Source (Scope (E))
10519 return Type_Access_Level (Scope (E)) + 1;
10522 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10525 elsif Nkind (Obj) = N_Selected_Component then
10526 if Is_Access_Type (Etype (Prefix (Obj))) then
10527 return Type_Access_Level (Etype (Prefix (Obj)));
10529 return Object_Access_Level (Prefix (Obj));
10532 elsif Nkind (Obj) = N_Indexed_Component then
10533 if Is_Access_Type (Etype (Prefix (Obj))) then
10534 return Type_Access_Level (Etype (Prefix (Obj)));
10536 return Object_Access_Level (Prefix (Obj));
10539 elsif Nkind (Obj) = N_Explicit_Dereference then
10541 -- If the prefix is a selected access discriminant then we make a
10542 -- recursive call on the prefix, which will in turn check the level
10543 -- of the prefix object of the selected discriminant.
10545 if Nkind (Prefix (Obj)) = N_Selected_Component
10546 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10548 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10550 return Object_Access_Level (Prefix (Obj));
10552 elsif not (Comes_From_Source (Obj)) then
10554 Ref : constant Node_Id := Reference_To (Obj);
10556 if Present (Ref) then
10557 return Object_Access_Level (Ref);
10559 return Type_Access_Level (Etype (Prefix (Obj)));
10564 return Type_Access_Level (Etype (Prefix (Obj)));
10567 elsif Nkind (Obj) = N_Type_Conversion
10568 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10570 return Object_Access_Level (Expression (Obj));
10572 elsif Nkind (Obj) = N_Function_Call then
10574 -- Function results are objects, so we get either the access level of
10575 -- the function or, in the case of an indirect call, the level of the
10576 -- access-to-subprogram type. (This code is used for Ada 95, but it
10577 -- looks wrong, because it seems that we should be checking the level
10578 -- of the call itself, even for Ada 95. However, using the Ada 2005
10579 -- version of the code causes regressions in several tests that are
10580 -- compiled with -gnat95. ???)
10582 if Ada_Version < Ada_2005 then
10583 if Is_Entity_Name (Name (Obj)) then
10584 return Subprogram_Access_Level (Entity (Name (Obj)));
10586 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10589 -- For Ada 2005, the level of the result object of a function call is
10590 -- defined to be the level of the call's innermost enclosing master.
10591 -- We determine that by querying the depth of the innermost enclosing
10595 Return_Master_Scope_Depth_Of_Call : declare
10597 function Innermost_Master_Scope_Depth
10598 (N : Node_Id) return Uint;
10599 -- Returns the scope depth of the given node's innermost
10600 -- enclosing dynamic scope (effectively the accessibility
10601 -- level of the innermost enclosing master).
10603 ----------------------------------
10604 -- Innermost_Master_Scope_Depth --
10605 ----------------------------------
10607 function Innermost_Master_Scope_Depth
10608 (N : Node_Id) return Uint
10610 Node_Par : Node_Id := Parent (N);
10613 -- Locate the nearest enclosing node (by traversing Parents)
10614 -- that Defining_Entity can be applied to, and return the
10615 -- depth of that entity's nearest enclosing dynamic scope.
10617 while Present (Node_Par) loop
10618 case Nkind (Node_Par) is
10619 when N_Component_Declaration |
10620 N_Entry_Declaration |
10621 N_Formal_Object_Declaration |
10622 N_Formal_Type_Declaration |
10623 N_Full_Type_Declaration |
10624 N_Incomplete_Type_Declaration |
10625 N_Loop_Parameter_Specification |
10626 N_Object_Declaration |
10627 N_Protected_Type_Declaration |
10628 N_Private_Extension_Declaration |
10629 N_Private_Type_Declaration |
10630 N_Subtype_Declaration |
10631 N_Function_Specification |
10632 N_Procedure_Specification |
10633 N_Task_Type_Declaration |
10635 N_Generic_Instantiation |
10637 N_Implicit_Label_Declaration |
10638 N_Package_Declaration |
10639 N_Single_Task_Declaration |
10640 N_Subprogram_Declaration |
10641 N_Generic_Declaration |
10642 N_Renaming_Declaration |
10643 N_Block_Statement |
10644 N_Formal_Subprogram_Declaration |
10645 N_Abstract_Subprogram_Declaration |
10647 N_Exception_Declaration |
10648 N_Formal_Package_Declaration |
10649 N_Number_Declaration |
10650 N_Package_Specification |
10651 N_Parameter_Specification |
10652 N_Single_Protected_Declaration |
10656 (Nearest_Dynamic_Scope
10657 (Defining_Entity (Node_Par)));
10663 Node_Par := Parent (Node_Par);
10666 pragma Assert (False);
10668 -- Should never reach the following return
10670 return Scope_Depth (Current_Scope) + 1;
10671 end Innermost_Master_Scope_Depth;
10673 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10676 return Innermost_Master_Scope_Depth (Obj);
10677 end Return_Master_Scope_Depth_Of_Call;
10680 -- For convenience we handle qualified expressions, even though
10681 -- they aren't technically object names.
10683 elsif Nkind (Obj) = N_Qualified_Expression then
10684 return Object_Access_Level (Expression (Obj));
10686 -- Otherwise return the scope level of Standard.
10687 -- (If there are cases that fall through
10688 -- to this point they will be treated as
10689 -- having global accessibility for now. ???)
10692 return Scope_Depth (Standard_Standard);
10694 end Object_Access_Level;
10696 --------------------------------------
10697 -- Original_Corresponding_Operation --
10698 --------------------------------------
10700 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10702 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10705 -- If S is an inherited primitive S2 the original corresponding
10706 -- operation of S is the original corresponding operation of S2
10708 if Present (Alias (S))
10709 and then Find_Dispatching_Type (Alias (S)) /= Typ
10711 return Original_Corresponding_Operation (Alias (S));
10713 -- If S overrides an inherited subprogram S2 the original corresponding
10714 -- operation of S is the original corresponding operation of S2
10716 elsif Present (Overridden_Operation (S)) then
10717 return Original_Corresponding_Operation (Overridden_Operation (S));
10719 -- otherwise it is S itself
10724 end Original_Corresponding_Operation;
10726 -----------------------
10727 -- Private_Component --
10728 -----------------------
10730 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10731 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10733 function Trace_Components
10735 Check : Boolean) return Entity_Id;
10736 -- Recursive function that does the work, and checks against circular
10737 -- definition for each subcomponent type.
10739 ----------------------
10740 -- Trace_Components --
10741 ----------------------
10743 function Trace_Components
10745 Check : Boolean) return Entity_Id
10747 Btype : constant Entity_Id := Base_Type (T);
10748 Component : Entity_Id;
10750 Candidate : Entity_Id := Empty;
10753 if Check and then Btype = Ancestor then
10754 Error_Msg_N ("circular type definition", Type_Id);
10758 if Is_Private_Type (Btype)
10759 and then not Is_Generic_Type (Btype)
10761 if Present (Full_View (Btype))
10762 and then Is_Record_Type (Full_View (Btype))
10763 and then not Is_Frozen (Btype)
10765 -- To indicate that the ancestor depends on a private type, the
10766 -- current Btype is sufficient. However, to check for circular
10767 -- definition we must recurse on the full view.
10769 Candidate := Trace_Components (Full_View (Btype), True);
10771 if Candidate = Any_Type then
10781 elsif Is_Array_Type (Btype) then
10782 return Trace_Components (Component_Type (Btype), True);
10784 elsif Is_Record_Type (Btype) then
10785 Component := First_Entity (Btype);
10786 while Present (Component) loop
10788 -- Skip anonymous types generated by constrained components
10790 if not Is_Type (Component) then
10791 P := Trace_Components (Etype (Component), True);
10793 if Present (P) then
10794 if P = Any_Type then
10802 Next_Entity (Component);
10810 end Trace_Components;
10812 -- Start of processing for Private_Component
10815 return Trace_Components (Type_Id, False);
10816 end Private_Component;
10818 ---------------------------
10819 -- Primitive_Names_Match --
10820 ---------------------------
10822 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10824 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10825 -- Given an internal name, returns the corresponding non-internal name
10827 ------------------------
10828 -- Non_Internal_Name --
10829 ------------------------
10831 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10833 Get_Name_String (Chars (E));
10834 Name_Len := Name_Len - 1;
10836 end Non_Internal_Name;
10838 -- Start of processing for Primitive_Names_Match
10841 pragma Assert (Present (E1) and then Present (E2));
10843 return Chars (E1) = Chars (E2)
10845 (not Is_Internal_Name (Chars (E1))
10846 and then Is_Internal_Name (Chars (E2))
10847 and then Non_Internal_Name (E2) = Chars (E1))
10849 (not Is_Internal_Name (Chars (E2))
10850 and then Is_Internal_Name (Chars (E1))
10851 and then Non_Internal_Name (E1) = Chars (E2))
10853 (Is_Predefined_Dispatching_Operation (E1)
10854 and then Is_Predefined_Dispatching_Operation (E2)
10855 and then Same_TSS (E1, E2))
10857 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10858 end Primitive_Names_Match;
10860 -----------------------
10861 -- Process_End_Label --
10862 -----------------------
10864 procedure Process_End_Label
10873 Label_Ref : Boolean;
10874 -- Set True if reference to end label itself is required
10877 -- Gets set to the operator symbol or identifier that references the
10878 -- entity Ent. For the child unit case, this is the identifier from the
10879 -- designator. For other cases, this is simply Endl.
10881 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10882 -- N is an identifier node that appears as a parent unit reference in
10883 -- the case where Ent is a child unit. This procedure generates an
10884 -- appropriate cross-reference entry. E is the corresponding entity.
10886 -------------------------
10887 -- Generate_Parent_Ref --
10888 -------------------------
10890 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10892 -- If names do not match, something weird, skip reference
10894 if Chars (E) = Chars (N) then
10896 -- Generate the reference. We do NOT consider this as a reference
10897 -- for unreferenced symbol purposes.
10899 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10901 if Style_Check then
10902 Style.Check_Identifier (N, E);
10905 end Generate_Parent_Ref;
10907 -- Start of processing for Process_End_Label
10910 -- If no node, ignore. This happens in some error situations, and
10911 -- also for some internally generated structures where no end label
10912 -- references are required in any case.
10918 -- Nothing to do if no End_Label, happens for internally generated
10919 -- constructs where we don't want an end label reference anyway. Also
10920 -- nothing to do if Endl is a string literal, which means there was
10921 -- some prior error (bad operator symbol)
10923 Endl := End_Label (N);
10925 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10929 -- Reference node is not in extended main source unit
10931 if not In_Extended_Main_Source_Unit (N) then
10933 -- Generally we do not collect references except for the extended
10934 -- main source unit. The one exception is the 'e' entry for a
10935 -- package spec, where it is useful for a client to have the
10936 -- ending information to define scopes.
10942 Label_Ref := False;
10944 -- For this case, we can ignore any parent references, but we
10945 -- need the package name itself for the 'e' entry.
10947 if Nkind (Endl) = N_Designator then
10948 Endl := Identifier (Endl);
10952 -- Reference is in extended main source unit
10957 -- For designator, generate references for the parent entries
10959 if Nkind (Endl) = N_Designator then
10961 -- Generate references for the prefix if the END line comes from
10962 -- source (otherwise we do not need these references) We climb the
10963 -- scope stack to find the expected entities.
10965 if Comes_From_Source (Endl) then
10966 Nam := Name (Endl);
10967 Scop := Current_Scope;
10968 while Nkind (Nam) = N_Selected_Component loop
10969 Scop := Scope (Scop);
10970 exit when No (Scop);
10971 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10972 Nam := Prefix (Nam);
10975 if Present (Scop) then
10976 Generate_Parent_Ref (Nam, Scope (Scop));
10980 Endl := Identifier (Endl);
10984 -- If the end label is not for the given entity, then either we have
10985 -- some previous error, or this is a generic instantiation for which
10986 -- we do not need to make a cross-reference in this case anyway. In
10987 -- either case we simply ignore the call.
10989 if Chars (Ent) /= Chars (Endl) then
10993 -- If label was really there, then generate a normal reference and then
10994 -- adjust the location in the end label to point past the name (which
10995 -- should almost always be the semicolon).
10997 Loc := Sloc (Endl);
10999 if Comes_From_Source (Endl) then
11001 -- If a label reference is required, then do the style check and
11002 -- generate an l-type cross-reference entry for the label
11005 if Style_Check then
11006 Style.Check_Identifier (Endl, Ent);
11009 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
11012 -- Set the location to point past the label (normally this will
11013 -- mean the semicolon immediately following the label). This is
11014 -- done for the sake of the 'e' or 't' entry generated below.
11016 Get_Decoded_Name_String (Chars (Endl));
11017 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11020 -- In SPARK mode, no missing label is allowed for packages and
11021 -- subprogram bodies. Detect those cases by testing whether
11022 -- Process_End_Label was called for a body (Typ = 't') or a package.
11024 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
11025 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11027 Error_Msg_Node_1 := Endl;
11028 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11032 -- Now generate the e/t reference
11034 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11036 -- Restore Sloc, in case modified above, since we have an identifier
11037 -- and the normal Sloc should be left set in the tree.
11039 Set_Sloc (Endl, Loc);
11040 end Process_End_Label;
11042 ------------------------------------
11043 -- References_Generic_Formal_Type --
11044 ------------------------------------
11046 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11048 function Process (N : Node_Id) return Traverse_Result;
11049 -- Process one node in search for generic formal type
11055 function Process (N : Node_Id) return Traverse_Result is
11057 if Nkind (N) in N_Has_Entity then
11059 E : constant Entity_Id := Entity (N);
11061 if Present (E) then
11062 if Is_Generic_Type (E) then
11064 elsif Present (Etype (E))
11065 and then Is_Generic_Type (Etype (E))
11076 function Traverse is new Traverse_Func (Process);
11077 -- Traverse tree to look for generic type
11080 if Inside_A_Generic then
11081 return Traverse (N) = Abandon;
11085 end References_Generic_Formal_Type;
11087 --------------------
11088 -- Remove_Homonym --
11089 --------------------
11091 procedure Remove_Homonym (E : Entity_Id) is
11092 Prev : Entity_Id := Empty;
11096 if E = Current_Entity (E) then
11097 if Present (Homonym (E)) then
11098 Set_Current_Entity (Homonym (E));
11100 Set_Name_Entity_Id (Chars (E), Empty);
11103 H := Current_Entity (E);
11104 while Present (H) and then H /= E loop
11109 Set_Homonym (Prev, Homonym (E));
11111 end Remove_Homonym;
11113 ---------------------
11114 -- Rep_To_Pos_Flag --
11115 ---------------------
11117 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11119 return New_Occurrence_Of
11120 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11121 end Rep_To_Pos_Flag;
11123 --------------------
11124 -- Require_Entity --
11125 --------------------
11127 procedure Require_Entity (N : Node_Id) is
11129 if Is_Entity_Name (N) and then No (Entity (N)) then
11130 if Total_Errors_Detected /= 0 then
11131 Set_Entity (N, Any_Id);
11133 raise Program_Error;
11136 end Require_Entity;
11138 ------------------------------
11139 -- Requires_Transient_Scope --
11140 ------------------------------
11142 -- A transient scope is required when variable-sized temporaries are
11143 -- allocated in the primary or secondary stack, or when finalization
11144 -- actions must be generated before the next instruction.
11146 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11147 Typ : constant Entity_Id := Underlying_Type (Id);
11149 -- Start of processing for Requires_Transient_Scope
11152 -- This is a private type which is not completed yet. This can only
11153 -- happen in a default expression (of a formal parameter or of a
11154 -- record component). Do not expand transient scope in this case
11159 -- Do not expand transient scope for non-existent procedure return
11161 elsif Typ = Standard_Void_Type then
11164 -- Elementary types do not require a transient scope
11166 elsif Is_Elementary_Type (Typ) then
11169 -- Generally, indefinite subtypes require a transient scope, since the
11170 -- back end cannot generate temporaries, since this is not a valid type
11171 -- for declaring an object. It might be possible to relax this in the
11172 -- future, e.g. by declaring the maximum possible space for the type.
11174 elsif Is_Indefinite_Subtype (Typ) then
11177 -- Functions returning tagged types may dispatch on result so their
11178 -- returned value is allocated on the secondary stack. Controlled
11179 -- type temporaries need finalization.
11181 elsif Is_Tagged_Type (Typ)
11182 or else Has_Controlled_Component (Typ)
11184 return not Is_Value_Type (Typ);
11188 elsif Is_Record_Type (Typ) then
11192 Comp := First_Entity (Typ);
11193 while Present (Comp) loop
11194 if Ekind (Comp) = E_Component
11195 and then Requires_Transient_Scope (Etype (Comp))
11199 Next_Entity (Comp);
11206 -- String literal types never require transient scope
11208 elsif Ekind (Typ) = E_String_Literal_Subtype then
11211 -- Array type. Note that we already know that this is a constrained
11212 -- array, since unconstrained arrays will fail the indefinite test.
11214 elsif Is_Array_Type (Typ) then
11216 -- If component type requires a transient scope, the array does too
11218 if Requires_Transient_Scope (Component_Type (Typ)) then
11221 -- Otherwise, we only need a transient scope if the size depends on
11222 -- the value of one or more discriminants.
11225 return Size_Depends_On_Discriminant (Typ);
11228 -- All other cases do not require a transient scope
11233 end Requires_Transient_Scope;
11235 --------------------------
11236 -- Reset_Analyzed_Flags --
11237 --------------------------
11239 procedure Reset_Analyzed_Flags (N : Node_Id) is
11241 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11242 -- Function used to reset Analyzed flags in tree. Note that we do
11243 -- not reset Analyzed flags in entities, since there is no need to
11244 -- reanalyze entities, and indeed, it is wrong to do so, since it
11245 -- can result in generating auxiliary stuff more than once.
11247 --------------------
11248 -- Clear_Analyzed --
11249 --------------------
11251 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11253 if not Has_Extension (N) then
11254 Set_Analyzed (N, False);
11258 end Clear_Analyzed;
11260 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11262 -- Start of processing for Reset_Analyzed_Flags
11265 Reset_Analyzed (N);
11266 end Reset_Analyzed_Flags;
11268 ---------------------------
11269 -- Safe_To_Capture_Value --
11270 ---------------------------
11272 function Safe_To_Capture_Value
11275 Cond : Boolean := False) return Boolean
11278 -- The only entities for which we track constant values are variables
11279 -- which are not renamings, constants, out parameters, and in out
11280 -- parameters, so check if we have this case.
11282 -- Note: it may seem odd to track constant values for constants, but in
11283 -- fact this routine is used for other purposes than simply capturing
11284 -- the value. In particular, the setting of Known[_Non]_Null.
11286 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11288 Ekind (Ent) = E_Constant
11290 Ekind (Ent) = E_Out_Parameter
11292 Ekind (Ent) = E_In_Out_Parameter
11296 -- For conditionals, we also allow loop parameters and all formals,
11297 -- including in parameters.
11301 (Ekind (Ent) = E_Loop_Parameter
11303 Ekind (Ent) = E_In_Parameter)
11307 -- For all other cases, not just unsafe, but impossible to capture
11308 -- Current_Value, since the above are the only entities which have
11309 -- Current_Value fields.
11315 -- Skip if volatile or aliased, since funny things might be going on in
11316 -- these cases which we cannot necessarily track. Also skip any variable
11317 -- for which an address clause is given, or whose address is taken. Also
11318 -- never capture value of library level variables (an attempt to do so
11319 -- can occur in the case of package elaboration code).
11321 if Treat_As_Volatile (Ent)
11322 or else Is_Aliased (Ent)
11323 or else Present (Address_Clause (Ent))
11324 or else Address_Taken (Ent)
11325 or else (Is_Library_Level_Entity (Ent)
11326 and then Ekind (Ent) = E_Variable)
11331 -- OK, all above conditions are met. We also require that the scope of
11332 -- the reference be the same as the scope of the entity, not counting
11333 -- packages and blocks and loops.
11336 E_Scope : constant Entity_Id := Scope (Ent);
11337 R_Scope : Entity_Id;
11340 R_Scope := Current_Scope;
11341 while R_Scope /= Standard_Standard loop
11342 exit when R_Scope = E_Scope;
11344 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11347 R_Scope := Scope (R_Scope);
11352 -- We also require that the reference does not appear in a context
11353 -- where it is not sure to be executed (i.e. a conditional context
11354 -- or an exception handler). We skip this if Cond is True, since the
11355 -- capturing of values from conditional tests handles this ok.
11369 while Present (P) loop
11370 if Nkind (P) = N_If_Statement
11371 or else Nkind (P) = N_Case_Statement
11372 or else (Nkind (P) in N_Short_Circuit
11373 and then Desc = Right_Opnd (P))
11374 or else (Nkind (P) = N_Conditional_Expression
11375 and then Desc /= First (Expressions (P)))
11376 or else Nkind (P) = N_Exception_Handler
11377 or else Nkind (P) = N_Selective_Accept
11378 or else Nkind (P) = N_Conditional_Entry_Call
11379 or else Nkind (P) = N_Timed_Entry_Call
11380 or else Nkind (P) = N_Asynchronous_Select
11390 -- OK, looks safe to set value
11393 end Safe_To_Capture_Value;
11399 function Same_Name (N1, N2 : Node_Id) return Boolean is
11400 K1 : constant Node_Kind := Nkind (N1);
11401 K2 : constant Node_Kind := Nkind (N2);
11404 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11405 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11407 return Chars (N1) = Chars (N2);
11409 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11410 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11412 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11413 and then Same_Name (Prefix (N1), Prefix (N2));
11424 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11425 N1 : constant Node_Id := Original_Node (Node1);
11426 N2 : constant Node_Id := Original_Node (Node2);
11427 -- We do the tests on original nodes, since we are most interested
11428 -- in the original source, not any expansion that got in the way.
11430 K1 : constant Node_Kind := Nkind (N1);
11431 K2 : constant Node_Kind := Nkind (N2);
11434 -- First case, both are entities with same entity
11436 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11438 EN1 : constant Entity_Id := Entity (N1);
11439 EN2 : constant Entity_Id := Entity (N2);
11441 if Present (EN1) and then Present (EN2)
11442 and then (Ekind_In (EN1, E_Variable, E_Constant)
11443 or else Is_Formal (EN1))
11451 -- Second case, selected component with same selector, same record
11453 if K1 = N_Selected_Component
11454 and then K2 = N_Selected_Component
11455 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11457 return Same_Object (Prefix (N1), Prefix (N2));
11459 -- Third case, indexed component with same subscripts, same array
11461 elsif K1 = N_Indexed_Component
11462 and then K2 = N_Indexed_Component
11463 and then Same_Object (Prefix (N1), Prefix (N2))
11468 E1 := First (Expressions (N1));
11469 E2 := First (Expressions (N2));
11470 while Present (E1) loop
11471 if not Same_Value (E1, E2) then
11482 -- Fourth case, slice of same array with same bounds
11485 and then K2 = N_Slice
11486 and then Nkind (Discrete_Range (N1)) = N_Range
11487 and then Nkind (Discrete_Range (N2)) = N_Range
11488 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11489 Low_Bound (Discrete_Range (N2)))
11490 and then Same_Value (High_Bound (Discrete_Range (N1)),
11491 High_Bound (Discrete_Range (N2)))
11493 return Same_Name (Prefix (N1), Prefix (N2));
11495 -- All other cases, not clearly the same object
11506 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11511 elsif not Is_Constrained (T1)
11512 and then not Is_Constrained (T2)
11513 and then Base_Type (T1) = Base_Type (T2)
11517 -- For now don't bother with case of identical constraints, to be
11518 -- fiddled with later on perhaps (this is only used for optimization
11519 -- purposes, so it is not critical to do a best possible job)
11530 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11532 if Compile_Time_Known_Value (Node1)
11533 and then Compile_Time_Known_Value (Node2)
11534 and then Expr_Value (Node1) = Expr_Value (Node2)
11537 elsif Same_Object (Node1, Node2) then
11548 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11550 if Ada_Version < Ada_2012 then
11553 elsif Is_Entity_Name (N)
11555 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11557 (Nkind (N) = N_Attribute_Reference
11558 and then Attribute_Name (N) = Name_Access)
11561 -- We are only interested in IN OUT parameters of inner calls
11564 or else Nkind (Parent (N)) = N_Function_Call
11565 or else Nkind (Parent (N)) in N_Op
11567 Actuals_In_Call.Increment_Last;
11568 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11573 ------------------------
11574 -- Scope_Is_Transient --
11575 ------------------------
11577 function Scope_Is_Transient return Boolean is
11579 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11580 end Scope_Is_Transient;
11586 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11591 while Scop /= Standard_Standard loop
11592 Scop := Scope (Scop);
11594 if Scop = Scope2 then
11602 --------------------------
11603 -- Scope_Within_Or_Same --
11604 --------------------------
11606 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11611 while Scop /= Standard_Standard loop
11612 if Scop = Scope2 then
11615 Scop := Scope (Scop);
11620 end Scope_Within_Or_Same;
11622 --------------------
11623 -- Set_Convention --
11624 --------------------
11626 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11628 Basic_Set_Convention (E, Val);
11631 and then Is_Access_Subprogram_Type (Base_Type (E))
11632 and then Has_Foreign_Convention (E)
11634 Set_Can_Use_Internal_Rep (E, False);
11636 end Set_Convention;
11638 ------------------------
11639 -- Set_Current_Entity --
11640 ------------------------
11642 -- The given entity is to be set as the currently visible definition
11643 -- of its associated name (i.e. the Node_Id associated with its name).
11644 -- All we have to do is to get the name from the identifier, and
11645 -- then set the associated Node_Id to point to the given entity.
11647 procedure Set_Current_Entity (E : Entity_Id) is
11649 Set_Name_Entity_Id (Chars (E), E);
11650 end Set_Current_Entity;
11652 ---------------------------
11653 -- Set_Debug_Info_Needed --
11654 ---------------------------
11656 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11658 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11659 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11660 -- Used to set debug info in a related node if not set already
11662 --------------------------------------
11663 -- Set_Debug_Info_Needed_If_Not_Set --
11664 --------------------------------------
11666 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11669 and then not Needs_Debug_Info (E)
11671 Set_Debug_Info_Needed (E);
11673 -- For a private type, indicate that the full view also needs
11674 -- debug information.
11677 and then Is_Private_Type (E)
11678 and then Present (Full_View (E))
11680 Set_Debug_Info_Needed (Full_View (E));
11683 end Set_Debug_Info_Needed_If_Not_Set;
11685 -- Start of processing for Set_Debug_Info_Needed
11688 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11689 -- indicates that Debug_Info_Needed is never required for the entity.
11692 or else Debug_Info_Off (T)
11697 -- Set flag in entity itself. Note that we will go through the following
11698 -- circuitry even if the flag is already set on T. That's intentional,
11699 -- it makes sure that the flag will be set in subsidiary entities.
11701 Set_Needs_Debug_Info (T);
11703 -- Set flag on subsidiary entities if not set already
11705 if Is_Object (T) then
11706 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11708 elsif Is_Type (T) then
11709 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11711 if Is_Record_Type (T) then
11713 Ent : Entity_Id := First_Entity (T);
11715 while Present (Ent) loop
11716 Set_Debug_Info_Needed_If_Not_Set (Ent);
11721 -- For a class wide subtype, we also need debug information
11722 -- for the equivalent type.
11724 if Ekind (T) = E_Class_Wide_Subtype then
11725 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11728 elsif Is_Array_Type (T) then
11729 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11732 Indx : Node_Id := First_Index (T);
11734 while Present (Indx) loop
11735 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11736 Indx := Next_Index (Indx);
11740 if Is_Packed (T) then
11741 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11744 elsif Is_Access_Type (T) then
11745 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11747 elsif Is_Private_Type (T) then
11748 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11750 elsif Is_Protected_Type (T) then
11751 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11754 end Set_Debug_Info_Needed;
11756 ---------------------------------
11757 -- Set_Entity_With_Style_Check --
11758 ---------------------------------
11760 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11761 Val_Actual : Entity_Id;
11765 Set_Entity (N, Val);
11768 and then not Suppress_Style_Checks (Val)
11769 and then not In_Instance
11771 if Nkind (N) = N_Identifier then
11773 elsif Nkind (N) = N_Expanded_Name then
11774 Nod := Selector_Name (N);
11779 -- A special situation arises for derived operations, where we want
11780 -- to do the check against the parent (since the Sloc of the derived
11781 -- operation points to the derived type declaration itself).
11784 while not Comes_From_Source (Val_Actual)
11785 and then Nkind (Val_Actual) in N_Entity
11786 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11787 or else Is_Subprogram (Val_Actual)
11788 or else Is_Generic_Subprogram (Val_Actual))
11789 and then Present (Alias (Val_Actual))
11791 Val_Actual := Alias (Val_Actual);
11794 -- Renaming declarations for generic actuals do not come from source,
11795 -- and have a different name from that of the entity they rename, so
11796 -- there is no style check to perform here.
11798 if Chars (Nod) = Chars (Val_Actual) then
11799 Style.Check_Identifier (Nod, Val_Actual);
11803 Set_Entity (N, Val);
11804 end Set_Entity_With_Style_Check;
11806 ------------------------
11807 -- Set_Name_Entity_Id --
11808 ------------------------
11810 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11812 Set_Name_Table_Info (Id, Int (Val));
11813 end Set_Name_Entity_Id;
11815 ---------------------
11816 -- Set_Next_Actual --
11817 ---------------------
11819 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11821 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11822 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11824 end Set_Next_Actual;
11826 ----------------------------------
11827 -- Set_Optimize_Alignment_Flags --
11828 ----------------------------------
11830 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11832 if Optimize_Alignment = 'S' then
11833 Set_Optimize_Alignment_Space (E);
11834 elsif Optimize_Alignment = 'T' then
11835 Set_Optimize_Alignment_Time (E);
11837 end Set_Optimize_Alignment_Flags;
11839 -----------------------
11840 -- Set_Public_Status --
11841 -----------------------
11843 procedure Set_Public_Status (Id : Entity_Id) is
11844 S : constant Entity_Id := Current_Scope;
11846 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11847 -- Determines if E is defined within handled statement sequence or
11848 -- an if statement, returns True if so, False otherwise.
11850 ----------------------
11851 -- Within_HSS_Or_If --
11852 ----------------------
11854 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11857 N := Declaration_Node (E);
11864 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11870 end Within_HSS_Or_If;
11872 -- Start of processing for Set_Public_Status
11875 -- Everything in the scope of Standard is public
11877 if S = Standard_Standard then
11878 Set_Is_Public (Id);
11880 -- Entity is definitely not public if enclosing scope is not public
11882 elsif not Is_Public (S) then
11885 -- An object or function declaration that occurs in a handled sequence
11886 -- of statements or within an if statement is the declaration for a
11887 -- temporary object or local subprogram generated by the expander. It
11888 -- never needs to be made public and furthermore, making it public can
11889 -- cause back end problems.
11891 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11892 N_Function_Specification)
11893 and then Within_HSS_Or_If (Id)
11897 -- Entities in public packages or records are public
11899 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11900 Set_Is_Public (Id);
11902 -- The bounds of an entry family declaration can generate object
11903 -- declarations that are visible to the back-end, e.g. in the
11904 -- the declaration of a composite type that contains tasks.
11906 elsif Is_Concurrent_Type (S)
11907 and then not Has_Completion (S)
11908 and then Nkind (Parent (Id)) = N_Object_Declaration
11910 Set_Is_Public (Id);
11912 end Set_Public_Status;
11914 -----------------------------
11915 -- Set_Referenced_Modified --
11916 -----------------------------
11918 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11922 -- Deal with indexed or selected component where prefix is modified
11924 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11925 Pref := Prefix (N);
11927 -- If prefix is access type, then it is the designated object that is
11928 -- being modified, which means we have no entity to set the flag on.
11930 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11933 -- Otherwise chase the prefix
11936 Set_Referenced_Modified (Pref, Out_Param);
11939 -- Otherwise see if we have an entity name (only other case to process)
11941 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11942 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11943 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11945 end Set_Referenced_Modified;
11947 ----------------------------
11948 -- Set_Scope_Is_Transient --
11949 ----------------------------
11951 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11953 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11954 end Set_Scope_Is_Transient;
11956 -------------------
11957 -- Set_Size_Info --
11958 -------------------
11960 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11962 -- We copy Esize, but not RM_Size, since in general RM_Size is
11963 -- subtype specific and does not get inherited by all subtypes.
11965 Set_Esize (T1, Esize (T2));
11966 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11968 if Is_Discrete_Or_Fixed_Point_Type (T1)
11970 Is_Discrete_Or_Fixed_Point_Type (T2)
11972 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11975 Set_Alignment (T1, Alignment (T2));
11978 --------------------
11979 -- Static_Boolean --
11980 --------------------
11982 function Static_Boolean (N : Node_Id) return Uint is
11984 Analyze_And_Resolve (N, Standard_Boolean);
11987 or else Error_Posted (N)
11988 or else Etype (N) = Any_Type
11993 if Is_Static_Expression (N) then
11994 if not Raises_Constraint_Error (N) then
11995 return Expr_Value (N);
12000 elsif Etype (N) = Any_Type then
12004 Flag_Non_Static_Expr
12005 ("static boolean expression required here", N);
12008 end Static_Boolean;
12010 --------------------
12011 -- Static_Integer --
12012 --------------------
12014 function Static_Integer (N : Node_Id) return Uint is
12016 Analyze_And_Resolve (N, Any_Integer);
12019 or else Error_Posted (N)
12020 or else Etype (N) = Any_Type
12025 if Is_Static_Expression (N) then
12026 if not Raises_Constraint_Error (N) then
12027 return Expr_Value (N);
12032 elsif Etype (N) = Any_Type then
12036 Flag_Non_Static_Expr
12037 ("static integer expression required here", N);
12040 end Static_Integer;
12042 --------------------------
12043 -- Statically_Different --
12044 --------------------------
12046 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12047 R1 : constant Node_Id := Get_Referenced_Object (E1);
12048 R2 : constant Node_Id := Get_Referenced_Object (E2);
12050 return Is_Entity_Name (R1)
12051 and then Is_Entity_Name (R2)
12052 and then Entity (R1) /= Entity (R2)
12053 and then not Is_Formal (Entity (R1))
12054 and then not Is_Formal (Entity (R2));
12055 end Statically_Different;
12057 -----------------------------
12058 -- Subprogram_Access_Level --
12059 -----------------------------
12061 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12063 if Present (Alias (Subp)) then
12064 return Subprogram_Access_Level (Alias (Subp));
12066 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12068 end Subprogram_Access_Level;
12074 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12076 if Debug_Flag_W then
12077 for J in 0 .. Scope_Stack.Last loop
12082 Write_Name (Chars (E));
12083 Write_Str (" from ");
12084 Write_Location (Sloc (N));
12089 -----------------------
12090 -- Transfer_Entities --
12091 -----------------------
12093 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12094 Ent : Entity_Id := First_Entity (From);
12101 if (Last_Entity (To)) = Empty then
12102 Set_First_Entity (To, Ent);
12104 Set_Next_Entity (Last_Entity (To), Ent);
12107 Set_Last_Entity (To, Last_Entity (From));
12109 while Present (Ent) loop
12110 Set_Scope (Ent, To);
12112 if not Is_Public (Ent) then
12113 Set_Public_Status (Ent);
12116 and then Ekind (Ent) = E_Record_Subtype
12119 -- The components of the propagated Itype must be public
12125 Comp := First_Entity (Ent);
12126 while Present (Comp) loop
12127 Set_Is_Public (Comp);
12128 Next_Entity (Comp);
12137 Set_First_Entity (From, Empty);
12138 Set_Last_Entity (From, Empty);
12139 end Transfer_Entities;
12141 -----------------------
12142 -- Type_Access_Level --
12143 -----------------------
12145 function Type_Access_Level (Typ : Entity_Id) return Uint is
12149 Btyp := Base_Type (Typ);
12151 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12152 -- simply use the level where the type is declared. This is true for
12153 -- stand-alone object declarations, and for anonymous access types
12154 -- associated with components the level is the same as that of the
12155 -- enclosing composite type. However, special treatment is needed for
12156 -- the cases of access parameters, return objects of an anonymous access
12157 -- type, and, in Ada 95, access discriminants of limited types.
12159 if Ekind (Btyp) in Access_Kind then
12160 if Ekind (Btyp) = E_Anonymous_Access_Type then
12162 -- If the type is a nonlocal anonymous access type (such as for
12163 -- an access parameter) we treat it as being declared at the
12164 -- library level to ensure that names such as X.all'access don't
12165 -- fail static accessibility checks.
12167 if not Is_Local_Anonymous_Access (Typ) then
12168 return Scope_Depth (Standard_Standard);
12170 -- If this is a return object, the accessibility level is that of
12171 -- the result subtype of the enclosing function. The test here is
12172 -- little complicated, because we have to account for extended
12173 -- return statements that have been rewritten as blocks, in which
12174 -- case we have to find and the Is_Return_Object attribute of the
12175 -- itype's associated object. It would be nice to find a way to
12176 -- simplify this test, but it doesn't seem worthwhile to add a new
12177 -- flag just for purposes of this test. ???
12179 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12182 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12183 N_Object_Declaration
12184 and then Is_Return_Object
12185 (Defining_Identifier
12186 (Associated_Node_For_Itype (Btyp))))
12192 Scop := Scope (Scope (Btyp));
12193 while Present (Scop) loop
12194 exit when Ekind (Scop) = E_Function;
12195 Scop := Scope (Scop);
12198 -- Treat the return object's type as having the level of the
12199 -- function's result subtype (as per RM05-6.5(5.3/2)).
12201 return Type_Access_Level (Etype (Scop));
12206 Btyp := Root_Type (Btyp);
12208 -- The accessibility level of anonymous access types associated with
12209 -- discriminants is that of the current instance of the type, and
12210 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12212 -- AI-402: access discriminants have accessibility based on the
12213 -- object rather than the type in Ada 2005, so the above paragraph
12216 -- ??? Needs completion with rules from AI-416
12218 if Ada_Version <= Ada_95
12219 and then Ekind (Typ) = E_Anonymous_Access_Type
12220 and then Present (Associated_Node_For_Itype (Typ))
12221 and then Nkind (Associated_Node_For_Itype (Typ)) =
12222 N_Discriminant_Specification
12224 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12228 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12229 end Type_Access_Level;
12231 ----------------------------
12232 -- Unique_Defining_Entity --
12233 ----------------------------
12235 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
12238 when N_Package_Body =>
12239 return Corresponding_Spec (N);
12241 when N_Subprogram_Body =>
12242 if Acts_As_Spec (N) then
12243 return Defining_Entity (N);
12245 return Corresponding_Spec (N);
12249 return Defining_Entity (N);
12251 end Unique_Defining_Entity;
12257 function Unique_Name (E : Entity_Id) return String is
12258 Name : constant String := Get_Name_String (Chars (E));
12260 if Has_Fully_Qualified_Name (E)
12261 or else E = Standard_Standard
12265 return Unique_Name (Scope (E)) & "__" & Name;
12269 --------------------------
12270 -- Unit_Declaration_Node --
12271 --------------------------
12273 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12274 N : Node_Id := Parent (Unit_Id);
12277 -- Predefined operators do not have a full function declaration
12279 if Ekind (Unit_Id) = E_Operator then
12283 -- Isn't there some better way to express the following ???
12285 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12286 and then Nkind (N) /= N_Formal_Package_Declaration
12287 and then Nkind (N) /= N_Function_Instantiation
12288 and then Nkind (N) /= N_Generic_Package_Declaration
12289 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12290 and then Nkind (N) /= N_Package_Declaration
12291 and then Nkind (N) /= N_Package_Body
12292 and then Nkind (N) /= N_Package_Instantiation
12293 and then Nkind (N) /= N_Package_Renaming_Declaration
12294 and then Nkind (N) /= N_Procedure_Instantiation
12295 and then Nkind (N) /= N_Protected_Body
12296 and then Nkind (N) /= N_Subprogram_Declaration
12297 and then Nkind (N) /= N_Subprogram_Body
12298 and then Nkind (N) /= N_Subprogram_Body_Stub
12299 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12300 and then Nkind (N) /= N_Task_Body
12301 and then Nkind (N) /= N_Task_Type_Declaration
12302 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12303 and then Nkind (N) not in N_Generic_Renaming_Declaration
12306 pragma Assert (Present (N));
12310 end Unit_Declaration_Node;
12312 ---------------------
12313 -- Unit_Is_Visible --
12314 ---------------------
12316 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12317 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12318 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12320 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12321 -- For a child unit, check whether unit appears in a with_clause
12324 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12325 -- Scan the context clause of one compilation unit looking for a
12326 -- with_clause for the unit in question.
12328 ----------------------------
12329 -- Unit_In_Parent_Context --
12330 ----------------------------
12332 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12334 if Unit_In_Context (Par_Unit) then
12337 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12338 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12343 end Unit_In_Parent_Context;
12345 ---------------------
12346 -- Unit_In_Context --
12347 ---------------------
12349 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12353 Clause := First (Context_Items (Comp_Unit));
12354 while Present (Clause) loop
12355 if Nkind (Clause) = N_With_Clause then
12356 if Library_Unit (Clause) = U then
12359 -- The with_clause may denote a renaming of the unit we are
12360 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12363 Renamed_Entity (Entity (Name (Clause))) =
12364 Defining_Entity (Unit (U))
12374 end Unit_In_Context;
12376 -- Start of processing for Unit_Is_Visible
12379 -- The currrent unit is directly visible.
12384 elsif Unit_In_Context (Curr) then
12387 -- If the current unit is a body, check the context of the spec.
12389 elsif Nkind (Unit (Curr)) = N_Package_Body
12391 (Nkind (Unit (Curr)) = N_Subprogram_Body
12392 and then not Acts_As_Spec (Unit (Curr)))
12394 if Unit_In_Context (Library_Unit (Curr)) then
12399 -- If the spec is a child unit, examine the parents.
12401 if Is_Child_Unit (Curr_Entity) then
12402 if Nkind (Unit (Curr)) in N_Unit_Body then
12404 Unit_In_Parent_Context
12405 (Parent_Spec (Unit (Library_Unit (Curr))));
12407 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12413 end Unit_Is_Visible;
12415 ------------------------------
12416 -- Universal_Interpretation --
12417 ------------------------------
12419 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12420 Index : Interp_Index;
12424 -- The argument may be a formal parameter of an operator or subprogram
12425 -- with multiple interpretations, or else an expression for an actual.
12427 if Nkind (Opnd) = N_Defining_Identifier
12428 or else not Is_Overloaded (Opnd)
12430 if Etype (Opnd) = Universal_Integer
12431 or else Etype (Opnd) = Universal_Real
12433 return Etype (Opnd);
12439 Get_First_Interp (Opnd, Index, It);
12440 while Present (It.Typ) loop
12441 if It.Typ = Universal_Integer
12442 or else It.Typ = Universal_Real
12447 Get_Next_Interp (Index, It);
12452 end Universal_Interpretation;
12458 function Unqualify (Expr : Node_Id) return Node_Id is
12460 -- Recurse to handle unlikely case of multiple levels of qualification
12462 if Nkind (Expr) = N_Qualified_Expression then
12463 return Unqualify (Expression (Expr));
12465 -- Normal case, not a qualified expression
12472 -----------------------
12473 -- Visible_Ancestors --
12474 -----------------------
12476 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12482 pragma Assert (Is_Record_Type (Typ)
12483 and then Is_Tagged_Type (Typ));
12485 -- Collect all the parents and progenitors of Typ. If the full-view of
12486 -- private parents and progenitors is available then it is used to
12487 -- generate the list of visible ancestors; otherwise their partial
12488 -- view is added to the resulting list.
12493 Use_Full_View => True);
12497 Ifaces_List => List_2,
12498 Exclude_Parents => True,
12499 Use_Full_View => True);
12501 -- Join the two lists. Avoid duplications because an interface may
12502 -- simultaneously be parent and progenitor of a type.
12504 Elmt := First_Elmt (List_2);
12505 while Present (Elmt) loop
12506 Append_Unique_Elmt (Node (Elmt), List_1);
12511 end Visible_Ancestors;
12513 ----------------------
12514 -- Within_Init_Proc --
12515 ----------------------
12517 function Within_Init_Proc return Boolean is
12521 S := Current_Scope;
12522 while not Is_Overloadable (S) loop
12523 if S = Standard_Standard then
12530 return Is_Init_Proc (S);
12531 end Within_Init_Proc;
12537 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12538 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12539 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12541 Matching_Field : Entity_Id;
12542 -- Entity to give a more precise suggestion on how to write a one-
12543 -- element positional aggregate.
12545 function Has_One_Matching_Field return Boolean;
12546 -- Determines if Expec_Type is a record type with a single component or
12547 -- discriminant whose type matches the found type or is one dimensional
12548 -- array whose component type matches the found type.
12550 ----------------------------
12551 -- Has_One_Matching_Field --
12552 ----------------------------
12554 function Has_One_Matching_Field return Boolean is
12558 Matching_Field := Empty;
12560 if Is_Array_Type (Expec_Type)
12561 and then Number_Dimensions (Expec_Type) = 1
12563 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12565 -- Use type name if available. This excludes multidimensional
12566 -- arrays and anonymous arrays.
12568 if Comes_From_Source (Expec_Type) then
12569 Matching_Field := Expec_Type;
12571 -- For an assignment, use name of target.
12573 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
12574 and then Is_Entity_Name (Name (Parent (Expr)))
12576 Matching_Field := Entity (Name (Parent (Expr)));
12581 elsif not Is_Record_Type (Expec_Type) then
12585 E := First_Entity (Expec_Type);
12590 elsif (Ekind (E) /= E_Discriminant
12591 and then Ekind (E) /= E_Component)
12592 or else (Chars (E) = Name_uTag
12593 or else Chars (E) = Name_uParent)
12602 if not Covers (Etype (E), Found_Type) then
12605 elsif Present (Next_Entity (E)) then
12609 Matching_Field := E;
12613 end Has_One_Matching_Field;
12615 -- Start of processing for Wrong_Type
12618 -- Don't output message if either type is Any_Type, or if a message
12619 -- has already been posted for this node. We need to do the latter
12620 -- check explicitly (it is ordinarily done in Errout), because we
12621 -- are using ! to force the output of the error messages.
12623 if Expec_Type = Any_Type
12624 or else Found_Type = Any_Type
12625 or else Error_Posted (Expr)
12629 -- In an instance, there is an ongoing problem with completion of
12630 -- type derived from private types. Their structure is what Gigi
12631 -- expects, but the Etype is the parent type rather than the
12632 -- derived private type itself. Do not flag error in this case. The
12633 -- private completion is an entity without a parent, like an Itype.
12634 -- Similarly, full and partial views may be incorrect in the instance.
12635 -- There is no simple way to insure that it is consistent ???
12637 elsif In_Instance then
12638 if Etype (Etype (Expr)) = Etype (Expected_Type)
12640 (Has_Private_Declaration (Expected_Type)
12641 or else Has_Private_Declaration (Etype (Expr)))
12642 and then No (Parent (Expected_Type))
12648 -- An interesting special check. If the expression is parenthesized
12649 -- and its type corresponds to the type of the sole component of the
12650 -- expected record type, or to the component type of the expected one
12651 -- dimensional array type, then assume we have a bad aggregate attempt.
12653 if Nkind (Expr) in N_Subexpr
12654 and then Paren_Count (Expr) /= 0
12655 and then Has_One_Matching_Field
12657 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12658 if Present (Matching_Field) then
12659 if Is_Array_Type (Expec_Type) then
12661 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
12665 ("\write instead `& ='> ...`", Expr, Matching_Field);
12669 -- Another special check, if we are looking for a pool-specific access
12670 -- type and we found an E_Access_Attribute_Type, then we have the case
12671 -- of an Access attribute being used in a context which needs a pool-
12672 -- specific type, which is never allowed. The one extra check we make
12673 -- is that the expected designated type covers the Found_Type.
12675 elsif Is_Access_Type (Expec_Type)
12676 and then Ekind (Found_Type) = E_Access_Attribute_Type
12677 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12678 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12680 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12682 Error_Msg_N -- CODEFIX
12683 ("result must be general access type!", Expr);
12684 Error_Msg_NE -- CODEFIX
12685 ("add ALL to }!", Expr, Expec_Type);
12687 -- Another special check, if the expected type is an integer type,
12688 -- but the expression is of type System.Address, and the parent is
12689 -- an addition or subtraction operation whose left operand is the
12690 -- expression in question and whose right operand is of an integral
12691 -- type, then this is an attempt at address arithmetic, so give
12692 -- appropriate message.
12694 elsif Is_Integer_Type (Expec_Type)
12695 and then Is_RTE (Found_Type, RE_Address)
12696 and then (Nkind (Parent (Expr)) = N_Op_Add
12698 Nkind (Parent (Expr)) = N_Op_Subtract)
12699 and then Expr = Left_Opnd (Parent (Expr))
12700 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12703 ("address arithmetic not predefined in package System",
12706 ("\possible missing with/use of System.Storage_Elements",
12710 -- If the expected type is an anonymous access type, as for access
12711 -- parameters and discriminants, the error is on the designated types.
12713 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12714 if Comes_From_Source (Expec_Type) then
12715 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12718 ("expected an access type with designated}",
12719 Expr, Designated_Type (Expec_Type));
12722 if Is_Access_Type (Found_Type)
12723 and then not Comes_From_Source (Found_Type)
12726 ("\\found an access type with designated}!",
12727 Expr, Designated_Type (Found_Type));
12729 if From_With_Type (Found_Type) then
12730 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12731 Error_Msg_Qual_Level := 99;
12732 Error_Msg_NE -- CODEFIX
12733 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12734 Error_Msg_Qual_Level := 0;
12736 Error_Msg_NE ("found}!", Expr, Found_Type);
12740 -- Normal case of one type found, some other type expected
12743 -- If the names of the two types are the same, see if some number
12744 -- of levels of qualification will help. Don't try more than three
12745 -- levels, and if we get to standard, it's no use (and probably
12746 -- represents an error in the compiler) Also do not bother with
12747 -- internal scope names.
12750 Expec_Scope : Entity_Id;
12751 Found_Scope : Entity_Id;
12754 Expec_Scope := Expec_Type;
12755 Found_Scope := Found_Type;
12757 for Levels in Int range 0 .. 3 loop
12758 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12759 Error_Msg_Qual_Level := Levels;
12763 Expec_Scope := Scope (Expec_Scope);
12764 Found_Scope := Scope (Found_Scope);
12766 exit when Expec_Scope = Standard_Standard
12767 or else Found_Scope = Standard_Standard
12768 or else not Comes_From_Source (Expec_Scope)
12769 or else not Comes_From_Source (Found_Scope);
12773 if Is_Record_Type (Expec_Type)
12774 and then Present (Corresponding_Remote_Type (Expec_Type))
12776 Error_Msg_NE ("expected}!", Expr,
12777 Corresponding_Remote_Type (Expec_Type));
12779 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12782 if Is_Entity_Name (Expr)
12783 and then Is_Package_Or_Generic_Package (Entity (Expr))
12785 Error_Msg_N ("\\found package name!", Expr);
12787 elsif Is_Entity_Name (Expr)
12789 (Ekind (Entity (Expr)) = E_Procedure
12791 Ekind (Entity (Expr)) = E_Generic_Procedure)
12793 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12795 ("found procedure name, possibly missing Access attribute!",
12799 ("\\found procedure name instead of function!", Expr);
12802 elsif Nkind (Expr) = N_Function_Call
12803 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12804 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12805 and then No (Parameter_Associations (Expr))
12808 ("found function name, possibly missing Access attribute!",
12811 -- Catch common error: a prefix or infix operator which is not
12812 -- directly visible because the type isn't.
12814 elsif Nkind (Expr) in N_Op
12815 and then Is_Overloaded (Expr)
12816 and then not Is_Immediately_Visible (Expec_Type)
12817 and then not Is_Potentially_Use_Visible (Expec_Type)
12818 and then not In_Use (Expec_Type)
12819 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12822 ("operator of the type is not directly visible!", Expr);
12824 elsif Ekind (Found_Type) = E_Void
12825 and then Present (Parent (Found_Type))
12826 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12828 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12831 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12834 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12835 -- of the same modular type, and (M1 and M2) = 0 was intended.
12837 if Expec_Type = Standard_Boolean
12838 and then Is_Modular_Integer_Type (Found_Type)
12839 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12840 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12843 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12844 L : constant Node_Id := Left_Opnd (Op);
12845 R : constant Node_Id := Right_Opnd (Op);
12847 -- The case for the message is when the left operand of the
12848 -- comparison is the same modular type, or when it is an
12849 -- integer literal (or other universal integer expression),
12850 -- which would have been typed as the modular type if the
12851 -- parens had been there.
12853 if (Etype (L) = Found_Type
12855 Etype (L) = Universal_Integer)
12856 and then Is_Integer_Type (Etype (R))
12859 ("\\possible missing parens for modular operation", Expr);
12864 -- Reset error message qualification indication
12866 Error_Msg_Qual_Level := 0;