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
4339 Arg : constant Node_Id :=
4340 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
4342 return Strval (Expr_Value_S (Arg));
4343 end Get_Name_From_Test_Case_Pragma;
4349 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4351 return Get_Pragma_Id (Pragma_Name (N));
4354 ---------------------------
4355 -- Get_Referenced_Object --
4356 ---------------------------
4358 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4363 while Is_Entity_Name (R)
4364 and then Present (Renamed_Object (Entity (R)))
4366 R := Renamed_Object (Entity (R));
4370 end Get_Referenced_Object;
4372 ------------------------
4373 -- Get_Renamed_Entity --
4374 ------------------------
4376 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4381 while Present (Renamed_Entity (R)) loop
4382 R := Renamed_Entity (R);
4386 end Get_Renamed_Entity;
4388 ----------------------------------------
4389 -- Get_Requires_From_Test_Case_Pragma --
4390 ----------------------------------------
4392 function Get_Requires_From_Test_Case_Pragma (N : Node_Id) return Node_Id is
4393 Args : constant List_Id := Pragma_Argument_Associations (N);
4397 Res := Pick (Args, 3);
4398 if Chars (Res) /= Name_Requires then
4403 end Get_Requires_From_Test_Case_Pragma;
4405 -------------------------
4406 -- Get_Subprogram_Body --
4407 -------------------------
4409 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4413 Decl := Unit_Declaration_Node (E);
4415 if Nkind (Decl) = N_Subprogram_Body then
4418 -- The below comment is bad, because it is possible for
4419 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4421 else -- Nkind (Decl) = N_Subprogram_Declaration
4423 if Present (Corresponding_Body (Decl)) then
4424 return Unit_Declaration_Node (Corresponding_Body (Decl));
4426 -- Imported subprogram case
4432 end Get_Subprogram_Body;
4434 ---------------------------
4435 -- Get_Subprogram_Entity --
4436 ---------------------------
4438 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4443 if Nkind (Nod) = N_Accept_Statement then
4444 Nam := Entry_Direct_Name (Nod);
4446 -- For an entry call, the prefix of the call is a selected component.
4447 -- Need additional code for internal calls ???
4449 elsif Nkind (Nod) = N_Entry_Call_Statement then
4450 if Nkind (Name (Nod)) = N_Selected_Component then
4451 Nam := Entity (Selector_Name (Name (Nod)));
4460 if Nkind (Nam) = N_Explicit_Dereference then
4461 Proc := Etype (Prefix (Nam));
4462 elsif Is_Entity_Name (Nam) then
4463 Proc := Entity (Nam);
4468 if Is_Object (Proc) then
4469 Proc := Etype (Proc);
4472 if Ekind (Proc) = E_Access_Subprogram_Type then
4473 Proc := Directly_Designated_Type (Proc);
4476 if not Is_Subprogram (Proc)
4477 and then Ekind (Proc) /= E_Subprogram_Type
4483 end Get_Subprogram_Entity;
4485 -----------------------------
4486 -- Get_Task_Body_Procedure --
4487 -----------------------------
4489 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4491 -- Note: A task type may be the completion of a private type with
4492 -- discriminants. When performing elaboration checks on a task
4493 -- declaration, the current view of the type may be the private one,
4494 -- and the procedure that holds the body of the task is held in its
4497 -- This is an odd function, why not have Task_Body_Procedure do
4498 -- the following digging???
4500 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4501 end Get_Task_Body_Procedure;
4503 -----------------------
4504 -- Has_Access_Values --
4505 -----------------------
4507 function Has_Access_Values (T : Entity_Id) return Boolean is
4508 Typ : constant Entity_Id := Underlying_Type (T);
4511 -- Case of a private type which is not completed yet. This can only
4512 -- happen in the case of a generic format type appearing directly, or
4513 -- as a component of the type to which this function is being applied
4514 -- at the top level. Return False in this case, since we certainly do
4515 -- not know that the type contains access types.
4520 elsif Is_Access_Type (Typ) then
4523 elsif Is_Array_Type (Typ) then
4524 return Has_Access_Values (Component_Type (Typ));
4526 elsif Is_Record_Type (Typ) then
4531 -- Loop to Check components
4533 Comp := First_Component_Or_Discriminant (Typ);
4534 while Present (Comp) loop
4536 -- Check for access component, tag field does not count, even
4537 -- though it is implemented internally using an access type.
4539 if Has_Access_Values (Etype (Comp))
4540 and then Chars (Comp) /= Name_uTag
4545 Next_Component_Or_Discriminant (Comp);
4554 end Has_Access_Values;
4556 ------------------------------
4557 -- Has_Compatible_Alignment --
4558 ------------------------------
4560 function Has_Compatible_Alignment
4562 Expr : Node_Id) return Alignment_Result
4564 function Has_Compatible_Alignment_Internal
4567 Default : Alignment_Result) return Alignment_Result;
4568 -- This is the internal recursive function that actually does the work.
4569 -- There is one additional parameter, which says what the result should
4570 -- be if no alignment information is found, and there is no definite
4571 -- indication of compatible alignments. At the outer level, this is set
4572 -- to Unknown, but for internal recursive calls in the case where types
4573 -- are known to be correct, it is set to Known_Compatible.
4575 ---------------------------------------
4576 -- Has_Compatible_Alignment_Internal --
4577 ---------------------------------------
4579 function Has_Compatible_Alignment_Internal
4582 Default : Alignment_Result) return Alignment_Result
4584 Result : Alignment_Result := Known_Compatible;
4585 -- Holds the current status of the result. Note that once a value of
4586 -- Known_Incompatible is set, it is sticky and does not get changed
4587 -- to Unknown (the value in Result only gets worse as we go along,
4590 Offs : Uint := No_Uint;
4591 -- Set to a factor of the offset from the base object when Expr is a
4592 -- selected or indexed component, based on Component_Bit_Offset and
4593 -- Component_Size respectively. A negative value is used to represent
4594 -- a value which is not known at compile time.
4596 procedure Check_Prefix;
4597 -- Checks the prefix recursively in the case where the expression
4598 -- is an indexed or selected component.
4600 procedure Set_Result (R : Alignment_Result);
4601 -- If R represents a worse outcome (unknown instead of known
4602 -- compatible, or known incompatible), then set Result to R.
4608 procedure Check_Prefix is
4610 -- The subtlety here is that in doing a recursive call to check
4611 -- the prefix, we have to decide what to do in the case where we
4612 -- don't find any specific indication of an alignment problem.
4614 -- At the outer level, we normally set Unknown as the result in
4615 -- this case, since we can only set Known_Compatible if we really
4616 -- know that the alignment value is OK, but for the recursive
4617 -- call, in the case where the types match, and we have not
4618 -- specified a peculiar alignment for the object, we are only
4619 -- concerned about suspicious rep clauses, the default case does
4620 -- not affect us, since the compiler will, in the absence of such
4621 -- rep clauses, ensure that the alignment is correct.
4623 if Default = Known_Compatible
4625 (Etype (Obj) = Etype (Expr)
4626 and then (Unknown_Alignment (Obj)
4628 Alignment (Obj) = Alignment (Etype (Obj))))
4631 (Has_Compatible_Alignment_Internal
4632 (Obj, Prefix (Expr), Known_Compatible));
4634 -- In all other cases, we need a full check on the prefix
4638 (Has_Compatible_Alignment_Internal
4639 (Obj, Prefix (Expr), Unknown));
4647 procedure Set_Result (R : Alignment_Result) is
4654 -- Start of processing for Has_Compatible_Alignment_Internal
4657 -- If Expr is a selected component, we must make sure there is no
4658 -- potentially troublesome component clause, and that the record is
4661 if Nkind (Expr) = N_Selected_Component then
4663 -- Packed record always generate unknown alignment
4665 if Is_Packed (Etype (Prefix (Expr))) then
4666 Set_Result (Unknown);
4669 -- Check prefix and component offset
4672 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4674 -- If Expr is an indexed component, we must make sure there is no
4675 -- potentially troublesome Component_Size clause and that the array
4676 -- is not bit-packed.
4678 elsif Nkind (Expr) = N_Indexed_Component then
4680 Typ : constant Entity_Id := Etype (Prefix (Expr));
4681 Ind : constant Node_Id := First_Index (Typ);
4684 -- Bit packed array always generates unknown alignment
4686 if Is_Bit_Packed_Array (Typ) then
4687 Set_Result (Unknown);
4690 -- Check prefix and component offset
4693 Offs := Component_Size (Typ);
4695 -- Small optimization: compute the full offset when possible
4698 and then Offs > Uint_0
4699 and then Present (Ind)
4700 and then Nkind (Ind) = N_Range
4701 and then Compile_Time_Known_Value (Low_Bound (Ind))
4702 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4704 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4705 - Expr_Value (Low_Bound ((Ind))));
4710 -- If we have a null offset, the result is entirely determined by
4711 -- the base object and has already been computed recursively.
4713 if Offs = Uint_0 then
4716 -- Case where we know the alignment of the object
4718 elsif Known_Alignment (Obj) then
4720 ObjA : constant Uint := Alignment (Obj);
4721 ExpA : Uint := No_Uint;
4722 SizA : Uint := No_Uint;
4725 -- If alignment of Obj is 1, then we are always OK
4728 Set_Result (Known_Compatible);
4730 -- Alignment of Obj is greater than 1, so we need to check
4733 -- If we have an offset, see if it is compatible
4735 if Offs /= No_Uint and Offs > Uint_0 then
4736 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4737 Set_Result (Known_Incompatible);
4740 -- See if Expr is an object with known alignment
4742 elsif Is_Entity_Name (Expr)
4743 and then Known_Alignment (Entity (Expr))
4745 ExpA := Alignment (Entity (Expr));
4747 -- Otherwise, we can use the alignment of the type of
4748 -- Expr given that we already checked for
4749 -- discombobulating rep clauses for the cases of indexed
4750 -- and selected components above.
4752 elsif Known_Alignment (Etype (Expr)) then
4753 ExpA := Alignment (Etype (Expr));
4755 -- Otherwise the alignment is unknown
4758 Set_Result (Default);
4761 -- If we got an alignment, see if it is acceptable
4763 if ExpA /= No_Uint and then ExpA < ObjA then
4764 Set_Result (Known_Incompatible);
4767 -- If Expr is not a piece of a larger object, see if size
4768 -- is given. If so, check that it is not too small for the
4769 -- required alignment.
4771 if Offs /= No_Uint then
4774 -- See if Expr is an object with known size
4776 elsif Is_Entity_Name (Expr)
4777 and then Known_Static_Esize (Entity (Expr))
4779 SizA := Esize (Entity (Expr));
4781 -- Otherwise, we check the object size of the Expr type
4783 elsif Known_Static_Esize (Etype (Expr)) then
4784 SizA := Esize (Etype (Expr));
4787 -- If we got a size, see if it is a multiple of the Obj
4788 -- alignment, if not, then the alignment cannot be
4789 -- acceptable, since the size is always a multiple of the
4792 if SizA /= No_Uint then
4793 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4794 Set_Result (Known_Incompatible);
4800 -- If we do not know required alignment, any non-zero offset is a
4801 -- potential problem (but certainly may be OK, so result is unknown).
4803 elsif Offs /= No_Uint then
4804 Set_Result (Unknown);
4806 -- If we can't find the result by direct comparison of alignment
4807 -- values, then there is still one case that we can determine known
4808 -- result, and that is when we can determine that the types are the
4809 -- same, and no alignments are specified. Then we known that the
4810 -- alignments are compatible, even if we don't know the alignment
4811 -- value in the front end.
4813 elsif Etype (Obj) = Etype (Expr) then
4815 -- Types are the same, but we have to check for possible size
4816 -- and alignments on the Expr object that may make the alignment
4817 -- different, even though the types are the same.
4819 if Is_Entity_Name (Expr) then
4821 -- First check alignment of the Expr object. Any alignment less
4822 -- than Maximum_Alignment is worrisome since this is the case
4823 -- where we do not know the alignment of Obj.
4825 if Known_Alignment (Entity (Expr))
4827 UI_To_Int (Alignment (Entity (Expr))) <
4828 Ttypes.Maximum_Alignment
4830 Set_Result (Unknown);
4832 -- Now check size of Expr object. Any size that is not an
4833 -- even multiple of Maximum_Alignment is also worrisome
4834 -- since it may cause the alignment of the object to be less
4835 -- than the alignment of the type.
4837 elsif Known_Static_Esize (Entity (Expr))
4839 (UI_To_Int (Esize (Entity (Expr))) mod
4840 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4843 Set_Result (Unknown);
4845 -- Otherwise same type is decisive
4848 Set_Result (Known_Compatible);
4852 -- Another case to deal with is when there is an explicit size or
4853 -- alignment clause when the types are not the same. If so, then the
4854 -- result is Unknown. We don't need to do this test if the Default is
4855 -- Unknown, since that result will be set in any case.
4857 elsif Default /= Unknown
4858 and then (Has_Size_Clause (Etype (Expr))
4860 Has_Alignment_Clause (Etype (Expr)))
4862 Set_Result (Unknown);
4864 -- If no indication found, set default
4867 Set_Result (Default);
4870 -- Return worst result found
4873 end Has_Compatible_Alignment_Internal;
4875 -- Start of processing for Has_Compatible_Alignment
4878 -- If Obj has no specified alignment, then set alignment from the type
4879 -- alignment. Perhaps we should always do this, but for sure we should
4880 -- do it when there is an address clause since we can do more if the
4881 -- alignment is known.
4883 if Unknown_Alignment (Obj) then
4884 Set_Alignment (Obj, Alignment (Etype (Obj)));
4887 -- Now do the internal call that does all the work
4889 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4890 end Has_Compatible_Alignment;
4892 ----------------------
4893 -- Has_Declarations --
4894 ----------------------
4896 function Has_Declarations (N : Node_Id) return Boolean is
4898 return Nkind_In (Nkind (N), N_Accept_Statement,
4900 N_Compilation_Unit_Aux,
4906 N_Package_Specification);
4907 end Has_Declarations;
4909 -------------------------------------------
4910 -- Has_Discriminant_Dependent_Constraint --
4911 -------------------------------------------
4913 function Has_Discriminant_Dependent_Constraint
4914 (Comp : Entity_Id) return Boolean
4916 Comp_Decl : constant Node_Id := Parent (Comp);
4917 Subt_Indic : constant Node_Id :=
4918 Subtype_Indication (Component_Definition (Comp_Decl));
4923 if Nkind (Subt_Indic) = N_Subtype_Indication then
4924 Constr := Constraint (Subt_Indic);
4926 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4927 Assn := First (Constraints (Constr));
4928 while Present (Assn) loop
4929 case Nkind (Assn) is
4930 when N_Subtype_Indication |
4934 if Depends_On_Discriminant (Assn) then
4938 when N_Discriminant_Association =>
4939 if Depends_On_Discriminant (Expression (Assn)) then
4954 end Has_Discriminant_Dependent_Constraint;
4956 --------------------
4957 -- Has_Infinities --
4958 --------------------
4960 function Has_Infinities (E : Entity_Id) return Boolean is
4963 Is_Floating_Point_Type (E)
4964 and then Nkind (Scalar_Range (E)) = N_Range
4965 and then Includes_Infinities (Scalar_Range (E));
4968 --------------------
4969 -- Has_Interfaces --
4970 --------------------
4972 function Has_Interfaces
4974 Use_Full_View : Boolean := True) return Boolean
4976 Typ : Entity_Id := Base_Type (T);
4979 -- Handle concurrent types
4981 if Is_Concurrent_Type (Typ) then
4982 Typ := Corresponding_Record_Type (Typ);
4985 if not Present (Typ)
4986 or else not Is_Record_Type (Typ)
4987 or else not Is_Tagged_Type (Typ)
4992 -- Handle private types
4995 and then Present (Full_View (Typ))
4997 Typ := Full_View (Typ);
5000 -- Handle concurrent record types
5002 if Is_Concurrent_Record_Type (Typ)
5003 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
5009 if Is_Interface (Typ)
5011 (Is_Record_Type (Typ)
5012 and then Present (Interfaces (Typ))
5013 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
5018 exit when Etype (Typ) = Typ
5020 -- Handle private types
5022 or else (Present (Full_View (Etype (Typ)))
5023 and then Full_View (Etype (Typ)) = Typ)
5025 -- Protect the frontend against wrong source with cyclic
5028 or else Etype (Typ) = T;
5030 -- Climb to the ancestor type handling private types
5032 if Present (Full_View (Etype (Typ))) then
5033 Typ := Full_View (Etype (Typ));
5042 ------------------------
5043 -- Has_Null_Exclusion --
5044 ------------------------
5046 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5049 when N_Access_Definition |
5050 N_Access_Function_Definition |
5051 N_Access_Procedure_Definition |
5052 N_Access_To_Object_Definition |
5054 N_Derived_Type_Definition |
5055 N_Function_Specification |
5056 N_Subtype_Declaration =>
5057 return Null_Exclusion_Present (N);
5059 when N_Component_Definition |
5060 N_Formal_Object_Declaration |
5061 N_Object_Renaming_Declaration =>
5062 if Present (Subtype_Mark (N)) then
5063 return Null_Exclusion_Present (N);
5064 else pragma Assert (Present (Access_Definition (N)));
5065 return Null_Exclusion_Present (Access_Definition (N));
5068 when N_Discriminant_Specification =>
5069 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5070 return Null_Exclusion_Present (Discriminant_Type (N));
5072 return Null_Exclusion_Present (N);
5075 when N_Object_Declaration =>
5076 if Nkind (Object_Definition (N)) = N_Access_Definition then
5077 return Null_Exclusion_Present (Object_Definition (N));
5079 return Null_Exclusion_Present (N);
5082 when N_Parameter_Specification =>
5083 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5084 return Null_Exclusion_Present (Parameter_Type (N));
5086 return Null_Exclusion_Present (N);
5093 end Has_Null_Exclusion;
5095 ------------------------
5096 -- Has_Null_Extension --
5097 ------------------------
5099 function Has_Null_Extension (T : Entity_Id) return Boolean is
5100 B : constant Entity_Id := Base_Type (T);
5105 if Nkind (Parent (B)) = N_Full_Type_Declaration
5106 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5108 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5110 if Present (Ext) then
5111 if Null_Present (Ext) then
5114 Comps := Component_List (Ext);
5116 -- The null component list is rewritten during analysis to
5117 -- include the parent component. Any other component indicates
5118 -- that the extension was not originally null.
5120 return Null_Present (Comps)
5121 or else No (Next (First (Component_Items (Comps))));
5130 end Has_Null_Extension;
5132 -------------------------------
5133 -- Has_Overriding_Initialize --
5134 -------------------------------
5136 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5137 BT : constant Entity_Id := Base_Type (T);
5141 if Is_Controlled (BT) then
5142 if Is_RTU (Scope (BT), Ada_Finalization) then
5145 elsif Present (Primitive_Operations (BT)) then
5146 P := First_Elmt (Primitive_Operations (BT));
5147 while Present (P) loop
5149 Init : constant Entity_Id := Node (P);
5150 Formal : constant Entity_Id := First_Formal (Init);
5152 if Ekind (Init) = E_Procedure
5153 and then Chars (Init) = Name_Initialize
5154 and then Comes_From_Source (Init)
5155 and then Present (Formal)
5156 and then Etype (Formal) = BT
5157 and then No (Next_Formal (Formal))
5158 and then (Ada_Version < Ada_2012
5159 or else not Null_Present (Parent (Init)))
5169 -- Here if type itself does not have a non-null Initialize operation:
5170 -- check immediate ancestor.
5172 if Is_Derived_Type (BT)
5173 and then Has_Overriding_Initialize (Etype (BT))
5180 end Has_Overriding_Initialize;
5182 --------------------------------------
5183 -- Has_Preelaborable_Initialization --
5184 --------------------------------------
5186 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5189 procedure Check_Components (E : Entity_Id);
5190 -- Check component/discriminant chain, sets Has_PE False if a component
5191 -- or discriminant does not meet the preelaborable initialization rules.
5193 ----------------------
5194 -- Check_Components --
5195 ----------------------
5197 procedure Check_Components (E : Entity_Id) is
5201 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5202 -- Returns True if and only if the expression denoted by N does not
5203 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5205 ---------------------------------
5206 -- Is_Preelaborable_Expression --
5207 ---------------------------------
5209 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5213 Comp_Type : Entity_Id;
5214 Is_Array_Aggr : Boolean;
5217 if Is_Static_Expression (N) then
5220 elsif Nkind (N) = N_Null then
5223 -- Attributes are allowed in general, even if their prefix is a
5224 -- formal type. (It seems that certain attributes known not to be
5225 -- static might not be allowed, but there are no rules to prevent
5228 elsif Nkind (N) = N_Attribute_Reference then
5231 -- The name of a discriminant evaluated within its parent type is
5232 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5233 -- names that denote discriminals as well as discriminants to
5234 -- catch references occurring within init procs.
5236 elsif Is_Entity_Name (N)
5238 (Ekind (Entity (N)) = E_Discriminant
5240 ((Ekind (Entity (N)) = E_Constant
5241 or else Ekind (Entity (N)) = E_In_Parameter)
5242 and then Present (Discriminal_Link (Entity (N)))))
5246 elsif Nkind (N) = N_Qualified_Expression then
5247 return Is_Preelaborable_Expression (Expression (N));
5249 -- For aggregates we have to check that each of the associations
5250 -- is preelaborable.
5252 elsif Nkind (N) = N_Aggregate
5253 or else Nkind (N) = N_Extension_Aggregate
5255 Is_Array_Aggr := Is_Array_Type (Etype (N));
5257 if Is_Array_Aggr then
5258 Comp_Type := Component_Type (Etype (N));
5261 -- Check the ancestor part of extension aggregates, which must
5262 -- be either the name of a type that has preelaborable init or
5263 -- an expression that is preelaborable.
5265 if Nkind (N) = N_Extension_Aggregate then
5267 Anc_Part : constant Node_Id := Ancestor_Part (N);
5270 if Is_Entity_Name (Anc_Part)
5271 and then Is_Type (Entity (Anc_Part))
5273 if not Has_Preelaborable_Initialization
5279 elsif not Is_Preelaborable_Expression (Anc_Part) then
5285 -- Check positional associations
5287 Exp := First (Expressions (N));
5288 while Present (Exp) loop
5289 if not Is_Preelaborable_Expression (Exp) then
5296 -- Check named associations
5298 Assn := First (Component_Associations (N));
5299 while Present (Assn) loop
5300 Choice := First (Choices (Assn));
5301 while Present (Choice) loop
5302 if Is_Array_Aggr then
5303 if Nkind (Choice) = N_Others_Choice then
5306 elsif Nkind (Choice) = N_Range then
5307 if not Is_Static_Range (Choice) then
5311 elsif not Is_Static_Expression (Choice) then
5316 Comp_Type := Etype (Choice);
5322 -- If the association has a <> at this point, then we have
5323 -- to check whether the component's type has preelaborable
5324 -- initialization. Note that this only occurs when the
5325 -- association's corresponding component does not have a
5326 -- default expression, the latter case having already been
5327 -- expanded as an expression for the association.
5329 if Box_Present (Assn) then
5330 if not Has_Preelaborable_Initialization (Comp_Type) then
5334 -- In the expression case we check whether the expression
5335 -- is preelaborable.
5338 not Is_Preelaborable_Expression (Expression (Assn))
5346 -- If we get here then aggregate as a whole is preelaborable
5350 -- All other cases are not preelaborable
5355 end Is_Preelaborable_Expression;
5357 -- Start of processing for Check_Components
5360 -- Loop through entities of record or protected type
5363 while Present (Ent) loop
5365 -- We are interested only in components and discriminants
5372 -- Get default expression if any. If there is no declaration
5373 -- node, it means we have an internal entity. The parent and
5374 -- tag fields are examples of such entities. For such cases,
5375 -- we just test the type of the entity.
5377 if Present (Declaration_Node (Ent)) then
5378 Exp := Expression (Declaration_Node (Ent));
5381 when E_Discriminant =>
5383 -- Note: for a renamed discriminant, the Declaration_Node
5384 -- may point to the one from the ancestor, and have a
5385 -- different expression, so use the proper attribute to
5386 -- retrieve the expression from the derived constraint.
5388 Exp := Discriminant_Default_Value (Ent);
5391 goto Check_Next_Entity;
5394 -- A component has PI if it has no default expression and the
5395 -- component type has PI.
5398 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5403 -- Require the default expression to be preelaborable
5405 elsif not Is_Preelaborable_Expression (Exp) then
5410 <<Check_Next_Entity>>
5413 end Check_Components;
5415 -- Start of processing for Has_Preelaborable_Initialization
5418 -- Immediate return if already marked as known preelaborable init. This
5419 -- covers types for which this function has already been called once
5420 -- and returned True (in which case the result is cached), and also
5421 -- types to which a pragma Preelaborable_Initialization applies.
5423 if Known_To_Have_Preelab_Init (E) then
5427 -- If the type is a subtype representing a generic actual type, then
5428 -- test whether its base type has preelaborable initialization since
5429 -- the subtype representing the actual does not inherit this attribute
5430 -- from the actual or formal. (but maybe it should???)
5432 if Is_Generic_Actual_Type (E) then
5433 return Has_Preelaborable_Initialization (Base_Type (E));
5436 -- All elementary types have preelaborable initialization
5438 if Is_Elementary_Type (E) then
5441 -- Array types have PI if the component type has PI
5443 elsif Is_Array_Type (E) then
5444 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5446 -- A derived type has preelaborable initialization if its parent type
5447 -- has preelaborable initialization and (in the case of a derived record
5448 -- extension) if the non-inherited components all have preelaborable
5449 -- initialization. However, a user-defined controlled type with an
5450 -- overriding Initialize procedure does not have preelaborable
5453 elsif Is_Derived_Type (E) then
5455 -- If the derived type is a private extension then it doesn't have
5456 -- preelaborable initialization.
5458 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5462 -- First check whether ancestor type has preelaborable initialization
5464 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5466 -- If OK, check extension components (if any)
5468 if Has_PE and then Is_Record_Type (E) then
5469 Check_Components (First_Entity (E));
5472 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5473 -- with a user defined Initialize procedure does not have PI.
5476 and then Is_Controlled (E)
5477 and then Has_Overriding_Initialize (E)
5482 -- Private types not derived from a type having preelaborable init and
5483 -- that are not marked with pragma Preelaborable_Initialization do not
5484 -- have preelaborable initialization.
5486 elsif Is_Private_Type (E) then
5489 -- Record type has PI if it is non private and all components have PI
5491 elsif Is_Record_Type (E) then
5493 Check_Components (First_Entity (E));
5495 -- Protected types must not have entries, and components must meet
5496 -- same set of rules as for record components.
5498 elsif Is_Protected_Type (E) then
5499 if Has_Entries (E) then
5503 Check_Components (First_Entity (E));
5504 Check_Components (First_Private_Entity (E));
5507 -- Type System.Address always has preelaborable initialization
5509 elsif Is_RTE (E, RE_Address) then
5512 -- In all other cases, type does not have preelaborable initialization
5518 -- If type has preelaborable initialization, cache result
5521 Set_Known_To_Have_Preelab_Init (E);
5525 end Has_Preelaborable_Initialization;
5527 ---------------------------
5528 -- Has_Private_Component --
5529 ---------------------------
5531 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5532 Btype : Entity_Id := Base_Type (Type_Id);
5533 Component : Entity_Id;
5536 if Error_Posted (Type_Id)
5537 or else Error_Posted (Btype)
5542 if Is_Class_Wide_Type (Btype) then
5543 Btype := Root_Type (Btype);
5546 if Is_Private_Type (Btype) then
5548 UT : constant Entity_Id := Underlying_Type (Btype);
5551 if No (Full_View (Btype)) then
5552 return not Is_Generic_Type (Btype)
5553 and then not Is_Generic_Type (Root_Type (Btype));
5555 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5558 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5562 elsif Is_Array_Type (Btype) then
5563 return Has_Private_Component (Component_Type (Btype));
5565 elsif Is_Record_Type (Btype) then
5566 Component := First_Component (Btype);
5567 while Present (Component) loop
5568 if Has_Private_Component (Etype (Component)) then
5572 Next_Component (Component);
5577 elsif Is_Protected_Type (Btype)
5578 and then Present (Corresponding_Record_Type (Btype))
5580 return Has_Private_Component (Corresponding_Record_Type (Btype));
5585 end Has_Private_Component;
5587 -----------------------------
5588 -- Has_Static_Array_Bounds --
5589 -----------------------------
5591 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5592 Ndims : constant Nat := Number_Dimensions (Typ);
5599 -- Unconstrained types do not have static bounds
5601 if not Is_Constrained (Typ) then
5605 -- First treat string literals specially, as the lower bound and length
5606 -- of string literals are not stored like those of arrays.
5608 -- A string literal always has static bounds
5610 if Ekind (Typ) = E_String_Literal_Subtype then
5614 -- Treat all dimensions in turn
5616 Index := First_Index (Typ);
5617 for Indx in 1 .. Ndims loop
5619 -- In case of an erroneous index which is not a discrete type, return
5620 -- that the type is not static.
5622 if not Is_Discrete_Type (Etype (Index))
5623 or else Etype (Index) = Any_Type
5628 Get_Index_Bounds (Index, Low, High);
5630 if Error_Posted (Low) or else Error_Posted (High) then
5634 if Is_OK_Static_Expression (Low)
5636 Is_OK_Static_Expression (High)
5646 -- If we fall through the loop, all indexes matched
5649 end Has_Static_Array_Bounds;
5655 function Has_Stream (T : Entity_Id) return Boolean is
5662 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5665 elsif Is_Array_Type (T) then
5666 return Has_Stream (Component_Type (T));
5668 elsif Is_Record_Type (T) then
5669 E := First_Component (T);
5670 while Present (E) loop
5671 if Has_Stream (Etype (E)) then
5680 elsif Is_Private_Type (T) then
5681 return Has_Stream (Underlying_Type (T));
5692 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5694 Get_Name_String (Chars (E));
5695 return Name_Buffer (Name_Len) = Suffix;
5698 --------------------------
5699 -- Has_Tagged_Component --
5700 --------------------------
5702 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5706 if Is_Private_Type (Typ)
5707 and then Present (Underlying_Type (Typ))
5709 return Has_Tagged_Component (Underlying_Type (Typ));
5711 elsif Is_Array_Type (Typ) then
5712 return Has_Tagged_Component (Component_Type (Typ));
5714 elsif Is_Tagged_Type (Typ) then
5717 elsif Is_Record_Type (Typ) then
5718 Comp := First_Component (Typ);
5719 while Present (Comp) loop
5720 if Has_Tagged_Component (Etype (Comp)) then
5724 Next_Component (Comp);
5732 end Has_Tagged_Component;
5734 -------------------------
5735 -- Implementation_Kind --
5736 -------------------------
5738 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5739 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5741 pragma Assert (Present (Impl_Prag));
5743 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5744 end Implementation_Kind;
5746 --------------------------
5747 -- Implements_Interface --
5748 --------------------------
5750 function Implements_Interface
5751 (Typ_Ent : Entity_Id;
5752 Iface_Ent : Entity_Id;
5753 Exclude_Parents : Boolean := False) return Boolean
5755 Ifaces_List : Elist_Id;
5757 Iface : Entity_Id := Base_Type (Iface_Ent);
5758 Typ : Entity_Id := Base_Type (Typ_Ent);
5761 if Is_Class_Wide_Type (Typ) then
5762 Typ := Root_Type (Typ);
5765 if not Has_Interfaces (Typ) then
5769 if Is_Class_Wide_Type (Iface) then
5770 Iface := Root_Type (Iface);
5773 Collect_Interfaces (Typ, Ifaces_List);
5775 Elmt := First_Elmt (Ifaces_List);
5776 while Present (Elmt) loop
5777 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5778 and then Exclude_Parents
5782 elsif Node (Elmt) = Iface then
5790 end Implements_Interface;
5796 function In_Instance return Boolean is
5797 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5803 and then S /= Standard_Standard
5805 if (Ekind (S) = E_Function
5806 or else Ekind (S) = E_Package
5807 or else Ekind (S) = E_Procedure)
5808 and then Is_Generic_Instance (S)
5810 -- A child instance is always compiled in the context of a parent
5811 -- instance. Nevertheless, the actuals are not analyzed in an
5812 -- instance context. We detect this case by examining the current
5813 -- compilation unit, which must be a child instance, and checking
5814 -- that it is not currently on the scope stack.
5816 if Is_Child_Unit (Curr_Unit)
5818 Nkind (Unit (Cunit (Current_Sem_Unit)))
5819 = N_Package_Instantiation
5820 and then not In_Open_Scopes (Curr_Unit)
5834 ----------------------
5835 -- In_Instance_Body --
5836 ----------------------
5838 function In_Instance_Body return Boolean is
5844 and then S /= Standard_Standard
5846 if (Ekind (S) = E_Function
5847 or else Ekind (S) = E_Procedure)
5848 and then Is_Generic_Instance (S)
5852 elsif Ekind (S) = E_Package
5853 and then In_Package_Body (S)
5854 and then Is_Generic_Instance (S)
5863 end In_Instance_Body;
5865 -----------------------------
5866 -- In_Instance_Not_Visible --
5867 -----------------------------
5869 function In_Instance_Not_Visible return Boolean is
5875 and then S /= Standard_Standard
5877 if (Ekind (S) = E_Function
5878 or else Ekind (S) = E_Procedure)
5879 and then Is_Generic_Instance (S)
5883 elsif Ekind (S) = E_Package
5884 and then (In_Package_Body (S) or else In_Private_Part (S))
5885 and then Is_Generic_Instance (S)
5894 end In_Instance_Not_Visible;
5896 ------------------------------
5897 -- In_Instance_Visible_Part --
5898 ------------------------------
5900 function In_Instance_Visible_Part return Boolean is
5906 and then S /= Standard_Standard
5908 if Ekind (S) = E_Package
5909 and then Is_Generic_Instance (S)
5910 and then not In_Package_Body (S)
5911 and then not In_Private_Part (S)
5920 end In_Instance_Visible_Part;
5922 ---------------------
5923 -- In_Package_Body --
5924 ---------------------
5926 function In_Package_Body return Boolean is
5932 and then S /= Standard_Standard
5934 if Ekind (S) = E_Package
5935 and then In_Package_Body (S)
5944 end In_Package_Body;
5946 --------------------------------
5947 -- In_Parameter_Specification --
5948 --------------------------------
5950 function In_Parameter_Specification (N : Node_Id) return Boolean is
5955 while Present (PN) loop
5956 if Nkind (PN) = N_Parameter_Specification then
5964 end In_Parameter_Specification;
5966 --------------------------------------
5967 -- In_Subprogram_Or_Concurrent_Unit --
5968 --------------------------------------
5970 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5975 -- Use scope chain to check successively outer scopes
5981 if K in Subprogram_Kind
5982 or else K in Concurrent_Kind
5983 or else K in Generic_Subprogram_Kind
5987 elsif E = Standard_Standard then
5993 end In_Subprogram_Or_Concurrent_Unit;
5995 ---------------------
5996 -- In_Visible_Part --
5997 ---------------------
5999 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
6002 Is_Package_Or_Generic_Package (Scope_Id)
6003 and then In_Open_Scopes (Scope_Id)
6004 and then not In_Package_Body (Scope_Id)
6005 and then not In_Private_Part (Scope_Id);
6006 end In_Visible_Part;
6008 --------------------------------
6009 -- Incomplete_Or_Private_View --
6010 --------------------------------
6012 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
6013 function Inspect_Decls
6015 Taft : Boolean := False) return Entity_Id;
6016 -- Check whether a declarative region contains the incomplete or private
6023 function Inspect_Decls
6025 Taft : Boolean := False) return Entity_Id
6031 Decl := First (Decls);
6032 while Present (Decl) loop
6036 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6037 Match := Defining_Identifier (Decl);
6041 if Nkind_In (Decl, N_Private_Extension_Declaration,
6042 N_Private_Type_Declaration)
6044 Match := Defining_Identifier (Decl);
6049 and then Present (Full_View (Match))
6050 and then Full_View (Match) = Typ
6065 -- Start of processing for Incomplete_Or_Partial_View
6068 -- Incomplete type case
6070 Prev := Current_Entity_In_Scope (Typ);
6073 and then Is_Incomplete_Type (Prev)
6074 and then Present (Full_View (Prev))
6075 and then Full_View (Prev) = Typ
6080 -- Private or Taft amendment type case
6083 Pkg : constant Entity_Id := Scope (Typ);
6084 Pkg_Decl : Node_Id := Pkg;
6087 if Ekind (Pkg) = E_Package then
6088 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6089 Pkg_Decl := Parent (Pkg_Decl);
6092 -- It is knows that Typ has a private view, look for it in the
6093 -- visible declarations of the enclosing scope. A special case
6094 -- of this is when the two views have been exchanged - the full
6095 -- appears earlier than the private.
6097 if Has_Private_Declaration (Typ) then
6098 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6100 -- Exchanged view case, look in the private declarations
6103 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6108 -- Otherwise if this is the package body, then Typ is a potential
6109 -- Taft amendment type. The incomplete view should be located in
6110 -- the private declarations of the enclosing scope.
6112 elsif In_Package_Body (Pkg) then
6113 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6118 -- The type has no incomplete or private view
6121 end Incomplete_Or_Private_View;
6123 ---------------------------------
6124 -- Insert_Explicit_Dereference --
6125 ---------------------------------
6127 procedure Insert_Explicit_Dereference (N : Node_Id) is
6128 New_Prefix : constant Node_Id := Relocate_Node (N);
6129 Ent : Entity_Id := Empty;
6136 Save_Interps (N, New_Prefix);
6139 Make_Explicit_Dereference (Sloc (Parent (N)),
6140 Prefix => New_Prefix));
6142 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6144 if Is_Overloaded (New_Prefix) then
6146 -- The dereference is also overloaded, and its interpretations are
6147 -- the designated types of the interpretations of the original node.
6149 Set_Etype (N, Any_Type);
6151 Get_First_Interp (New_Prefix, I, It);
6152 while Present (It.Nam) loop
6155 if Is_Access_Type (T) then
6156 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6159 Get_Next_Interp (I, It);
6165 -- Prefix is unambiguous: mark the original prefix (which might
6166 -- Come_From_Source) as a reference, since the new (relocated) one
6167 -- won't be taken into account.
6169 if Is_Entity_Name (New_Prefix) then
6170 Ent := Entity (New_Prefix);
6173 -- For a retrieval of a subcomponent of some composite object,
6174 -- retrieve the ultimate entity if there is one.
6176 elsif Nkind (New_Prefix) = N_Selected_Component
6177 or else Nkind (New_Prefix) = N_Indexed_Component
6179 Pref := Prefix (New_Prefix);
6180 while Present (Pref)
6182 (Nkind (Pref) = N_Selected_Component
6183 or else Nkind (Pref) = N_Indexed_Component)
6185 Pref := Prefix (Pref);
6188 if Present (Pref) and then Is_Entity_Name (Pref) then
6189 Ent := Entity (Pref);
6193 -- Place the reference on the entity node
6195 if Present (Ent) then
6196 Generate_Reference (Ent, Pref);
6199 end Insert_Explicit_Dereference;
6201 ------------------------------------------
6202 -- Inspect_Deferred_Constant_Completion --
6203 ------------------------------------------
6205 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6209 Decl := First (Decls);
6210 while Present (Decl) loop
6212 -- Deferred constant signature
6214 if Nkind (Decl) = N_Object_Declaration
6215 and then Constant_Present (Decl)
6216 and then No (Expression (Decl))
6218 -- No need to check internally generated constants
6220 and then Comes_From_Source (Decl)
6222 -- The constant is not completed. A full object declaration or a
6223 -- pragma Import complete a deferred constant.
6225 and then not Has_Completion (Defining_Identifier (Decl))
6228 ("constant declaration requires initialization expression",
6229 Defining_Identifier (Decl));
6232 Decl := Next (Decl);
6234 end Inspect_Deferred_Constant_Completion;
6236 -----------------------------
6237 -- Is_Actual_Out_Parameter --
6238 -----------------------------
6240 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6244 Find_Actual (N, Formal, Call);
6245 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6246 end Is_Actual_Out_Parameter;
6248 -------------------------
6249 -- Is_Actual_Parameter --
6250 -------------------------
6252 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6253 PK : constant Node_Kind := Nkind (Parent (N));
6257 when N_Parameter_Association =>
6258 return N = Explicit_Actual_Parameter (Parent (N));
6260 when N_Function_Call | N_Procedure_Call_Statement =>
6261 return Is_List_Member (N)
6263 List_Containing (N) = Parameter_Associations (Parent (N));
6268 end Is_Actual_Parameter;
6270 --------------------------------
6271 -- Is_Actual_Tagged_Parameter --
6272 --------------------------------
6274 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6278 Find_Actual (N, Formal, Call);
6279 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6280 end Is_Actual_Tagged_Parameter;
6282 ---------------------
6283 -- Is_Aliased_View --
6284 ---------------------
6286 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6290 if Is_Entity_Name (Obj) then
6298 or else (Present (Renamed_Object (E))
6299 and then Is_Aliased_View (Renamed_Object (E)))))
6301 or else ((Is_Formal (E)
6302 or else Ekind (E) = E_Generic_In_Out_Parameter
6303 or else Ekind (E) = E_Generic_In_Parameter)
6304 and then Is_Tagged_Type (Etype (E)))
6306 or else (Is_Concurrent_Type (E)
6307 and then In_Open_Scopes (E))
6309 -- Current instance of type, either directly or as rewritten
6310 -- reference to the current object.
6312 or else (Is_Entity_Name (Original_Node (Obj))
6313 and then Present (Entity (Original_Node (Obj)))
6314 and then Is_Type (Entity (Original_Node (Obj))))
6316 or else (Is_Type (E) and then E = Current_Scope)
6318 or else (Is_Incomplete_Or_Private_Type (E)
6319 and then Full_View (E) = Current_Scope);
6321 elsif Nkind (Obj) = N_Selected_Component then
6322 return Is_Aliased (Entity (Selector_Name (Obj)));
6324 elsif Nkind (Obj) = N_Indexed_Component then
6325 return Has_Aliased_Components (Etype (Prefix (Obj)))
6327 (Is_Access_Type (Etype (Prefix (Obj)))
6329 Has_Aliased_Components
6330 (Designated_Type (Etype (Prefix (Obj)))));
6332 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6333 or else Nkind (Obj) = N_Type_Conversion
6335 return Is_Tagged_Type (Etype (Obj))
6336 and then Is_Aliased_View (Expression (Obj));
6338 elsif Nkind (Obj) = N_Explicit_Dereference then
6339 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6344 end Is_Aliased_View;
6346 -------------------------
6347 -- Is_Ancestor_Package --
6348 -------------------------
6350 function Is_Ancestor_Package
6352 E2 : Entity_Id) return Boolean
6359 and then Par /= Standard_Standard
6369 end Is_Ancestor_Package;
6371 ----------------------
6372 -- Is_Atomic_Object --
6373 ----------------------
6375 function Is_Atomic_Object (N : Node_Id) return Boolean is
6377 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6378 -- Determines if given object has atomic components
6380 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6381 -- If prefix is an implicit dereference, examine designated type
6383 ----------------------
6384 -- Is_Atomic_Prefix --
6385 ----------------------
6387 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6389 if Is_Access_Type (Etype (N)) then
6391 Has_Atomic_Components (Designated_Type (Etype (N)));
6393 return Object_Has_Atomic_Components (N);
6395 end Is_Atomic_Prefix;
6397 ----------------------------------
6398 -- Object_Has_Atomic_Components --
6399 ----------------------------------
6401 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6403 if Has_Atomic_Components (Etype (N))
6404 or else Is_Atomic (Etype (N))
6408 elsif Is_Entity_Name (N)
6409 and then (Has_Atomic_Components (Entity (N))
6410 or else Is_Atomic (Entity (N)))
6414 elsif Nkind (N) = N_Indexed_Component
6415 or else Nkind (N) = N_Selected_Component
6417 return Is_Atomic_Prefix (Prefix (N));
6422 end Object_Has_Atomic_Components;
6424 -- Start of processing for Is_Atomic_Object
6427 -- Predicate is not relevant to subprograms
6429 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6432 elsif Is_Atomic (Etype (N))
6433 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6437 elsif Nkind (N) = N_Indexed_Component
6438 or else Nkind (N) = N_Selected_Component
6440 return Is_Atomic_Prefix (Prefix (N));
6445 end Is_Atomic_Object;
6447 -----------------------------
6448 -- Is_Concurrent_Interface --
6449 -----------------------------
6451 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6456 (Is_Protected_Interface (T)
6457 or else Is_Synchronized_Interface (T)
6458 or else Is_Task_Interface (T));
6459 end Is_Concurrent_Interface;
6461 --------------------------------------
6462 -- Is_Controlling_Limited_Procedure --
6463 --------------------------------------
6465 function Is_Controlling_Limited_Procedure
6466 (Proc_Nam : Entity_Id) return Boolean
6468 Param_Typ : Entity_Id := Empty;
6471 if Ekind (Proc_Nam) = E_Procedure
6472 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6474 Param_Typ := Etype (Parameter_Type (First (
6475 Parameter_Specifications (Parent (Proc_Nam)))));
6477 -- In this case where an Itype was created, the procedure call has been
6480 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6481 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6483 Present (Parameter_Associations
6484 (Associated_Node_For_Itype (Proc_Nam)))
6487 Etype (First (Parameter_Associations
6488 (Associated_Node_For_Itype (Proc_Nam))));
6491 if Present (Param_Typ) then
6493 Is_Interface (Param_Typ)
6494 and then Is_Limited_Record (Param_Typ);
6498 end Is_Controlling_Limited_Procedure;
6500 -----------------------------
6501 -- Is_CPP_Constructor_Call --
6502 -----------------------------
6504 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6506 return Nkind (N) = N_Function_Call
6507 and then Is_CPP_Class (Etype (Etype (N)))
6508 and then Is_Constructor (Entity (Name (N)))
6509 and then Is_Imported (Entity (Name (N)));
6510 end Is_CPP_Constructor_Call;
6516 function Is_Delegate (T : Entity_Id) return Boolean is
6517 Desig_Type : Entity_Id;
6520 if VM_Target /= CLI_Target then
6524 -- Access-to-subprograms are delegates in CIL
6526 if Ekind (T) = E_Access_Subprogram_Type then
6530 if Ekind (T) not in Access_Kind then
6532 -- A delegate is a managed pointer. If no designated type is defined
6533 -- it means that it's not a delegate.
6538 Desig_Type := Etype (Directly_Designated_Type (T));
6540 if not Is_Tagged_Type (Desig_Type) then
6544 -- Test if the type is inherited from [mscorlib]System.Delegate
6546 while Etype (Desig_Type) /= Desig_Type loop
6547 if Chars (Scope (Desig_Type)) /= No_Name
6548 and then Is_Imported (Scope (Desig_Type))
6549 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6554 Desig_Type := Etype (Desig_Type);
6560 ----------------------------------------------
6561 -- Is_Dependent_Component_Of_Mutable_Object --
6562 ----------------------------------------------
6564 function Is_Dependent_Component_Of_Mutable_Object
6565 (Object : Node_Id) return Boolean
6568 Prefix_Type : Entity_Id;
6569 P_Aliased : Boolean := False;
6572 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6573 -- Returns True if and only if Comp is declared within a variant part
6575 --------------------------------
6576 -- Is_Declared_Within_Variant --
6577 --------------------------------
6579 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6580 Comp_Decl : constant Node_Id := Parent (Comp);
6581 Comp_List : constant Node_Id := Parent (Comp_Decl);
6583 return Nkind (Parent (Comp_List)) = N_Variant;
6584 end Is_Declared_Within_Variant;
6586 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6589 if Is_Variable (Object) then
6591 if Nkind (Object) = N_Selected_Component then
6592 P := Prefix (Object);
6593 Prefix_Type := Etype (P);
6595 if Is_Entity_Name (P) then
6597 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6598 Prefix_Type := Base_Type (Prefix_Type);
6601 if Is_Aliased (Entity (P)) then
6605 -- A discriminant check on a selected component may be expanded
6606 -- into a dereference when removing side-effects. Recover the
6607 -- original node and its type, which may be unconstrained.
6609 elsif Nkind (P) = N_Explicit_Dereference
6610 and then not (Comes_From_Source (P))
6612 P := Original_Node (P);
6613 Prefix_Type := Etype (P);
6616 -- Check for prefix being an aliased component???
6622 -- A heap object is constrained by its initial value
6624 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6625 -- the dereferenced case, since the access value might denote an
6626 -- unconstrained aliased object, whereas in Ada 95 the designated
6627 -- object is guaranteed to be constrained. A worst-case assumption
6628 -- has to apply in Ada 2005 because we can't tell at compile time
6629 -- whether the object is "constrained by its initial value"
6630 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6631 -- semantic rules -- these rules are acknowledged to need fixing).
6633 if Ada_Version < Ada_2005 then
6634 if Is_Access_Type (Prefix_Type)
6635 or else Nkind (P) = N_Explicit_Dereference
6640 elsif Ada_Version >= Ada_2005 then
6641 if Is_Access_Type (Prefix_Type) then
6643 -- If the access type is pool-specific, and there is no
6644 -- constrained partial view of the designated type, then the
6645 -- designated object is known to be constrained.
6647 if Ekind (Prefix_Type) = E_Access_Type
6648 and then not Has_Constrained_Partial_View
6649 (Designated_Type (Prefix_Type))
6653 -- Otherwise (general access type, or there is a constrained
6654 -- partial view of the designated type), we need to check
6655 -- based on the designated type.
6658 Prefix_Type := Designated_Type (Prefix_Type);
6664 Original_Record_Component (Entity (Selector_Name (Object)));
6666 -- As per AI-0017, the renaming is illegal in a generic body, even
6667 -- if the subtype is indefinite.
6669 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6671 if not Is_Constrained (Prefix_Type)
6672 and then (not Is_Indefinite_Subtype (Prefix_Type)
6674 (Is_Generic_Type (Prefix_Type)
6675 and then Ekind (Current_Scope) = E_Generic_Package
6676 and then In_Package_Body (Current_Scope)))
6678 and then (Is_Declared_Within_Variant (Comp)
6679 or else Has_Discriminant_Dependent_Constraint (Comp))
6680 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6686 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6690 elsif Nkind (Object) = N_Indexed_Component
6691 or else Nkind (Object) = N_Slice
6693 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6695 -- A type conversion that Is_Variable is a view conversion:
6696 -- go back to the denoted object.
6698 elsif Nkind (Object) = N_Type_Conversion then
6700 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6705 end Is_Dependent_Component_Of_Mutable_Object;
6707 ---------------------
6708 -- Is_Dereferenced --
6709 ---------------------
6711 function Is_Dereferenced (N : Node_Id) return Boolean is
6712 P : constant Node_Id := Parent (N);
6715 (Nkind (P) = N_Selected_Component
6717 Nkind (P) = N_Explicit_Dereference
6719 Nkind (P) = N_Indexed_Component
6721 Nkind (P) = N_Slice)
6722 and then Prefix (P) = N;
6723 end Is_Dereferenced;
6725 ----------------------
6726 -- Is_Descendent_Of --
6727 ----------------------
6729 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6734 pragma Assert (Nkind (T1) in N_Entity);
6735 pragma Assert (Nkind (T2) in N_Entity);
6737 T := Base_Type (T1);
6739 -- Immediate return if the types match
6744 -- Comment needed here ???
6746 elsif Ekind (T) = E_Class_Wide_Type then
6747 return Etype (T) = T2;
6755 -- Done if we found the type we are looking for
6760 -- Done if no more derivations to check
6767 -- Following test catches error cases resulting from prev errors
6769 elsif No (Etyp) then
6772 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6775 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6779 T := Base_Type (Etyp);
6782 end Is_Descendent_Of;
6784 ----------------------------
6785 -- Is_Expression_Function --
6786 ----------------------------
6788 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6789 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6792 return Ekind (Subp) = E_Function
6793 and then Nkind (Decl) = N_Subprogram_Declaration
6795 (Nkind (Original_Node (Decl)) = N_Expression_Function
6797 (Present (Corresponding_Body (Decl))
6799 Nkind (Original_Node
6800 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6801 = N_Expression_Function));
6802 end Is_Expression_Function;
6808 function Is_False (U : Uint) return Boolean is
6813 ---------------------------
6814 -- Is_Fixed_Model_Number --
6815 ---------------------------
6817 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6818 S : constant Ureal := Small_Value (T);
6819 M : Urealp.Save_Mark;
6823 R := (U = UR_Trunc (U / S) * S);
6826 end Is_Fixed_Model_Number;
6828 -------------------------------
6829 -- Is_Fully_Initialized_Type --
6830 -------------------------------
6832 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6834 if Is_Scalar_Type (Typ) then
6837 elsif Is_Access_Type (Typ) then
6840 elsif Is_Array_Type (Typ) then
6841 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6845 -- An interesting case, if we have a constrained type one of whose
6846 -- bounds is known to be null, then there are no elements to be
6847 -- initialized, so all the elements are initialized!
6849 if Is_Constrained (Typ) then
6852 Indx_Typ : Entity_Id;
6856 Indx := First_Index (Typ);
6857 while Present (Indx) loop
6858 if Etype (Indx) = Any_Type then
6861 -- If index is a range, use directly
6863 elsif Nkind (Indx) = N_Range then
6864 Lbd := Low_Bound (Indx);
6865 Hbd := High_Bound (Indx);
6868 Indx_Typ := Etype (Indx);
6870 if Is_Private_Type (Indx_Typ) then
6871 Indx_Typ := Full_View (Indx_Typ);
6874 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6877 Lbd := Type_Low_Bound (Indx_Typ);
6878 Hbd := Type_High_Bound (Indx_Typ);
6882 if Compile_Time_Known_Value (Lbd)
6883 and then Compile_Time_Known_Value (Hbd)
6885 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6895 -- If no null indexes, then type is not fully initialized
6901 elsif Is_Record_Type (Typ) then
6902 if Has_Discriminants (Typ)
6904 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6905 and then Is_Fully_Initialized_Variant (Typ)
6910 -- Controlled records are considered to be fully initialized if
6911 -- there is a user defined Initialize routine. This may not be
6912 -- entirely correct, but as the spec notes, we are guessing here
6913 -- what is best from the point of view of issuing warnings.
6915 if Is_Controlled (Typ) then
6917 Utyp : constant Entity_Id := Underlying_Type (Typ);
6920 if Present (Utyp) then
6922 Init : constant Entity_Id :=
6924 (Underlying_Type (Typ), Name_Initialize));
6928 and then Comes_From_Source (Init)
6930 Is_Predefined_File_Name
6931 (File_Name (Get_Source_File_Index (Sloc (Init))))
6935 elsif Has_Null_Extension (Typ)
6937 Is_Fully_Initialized_Type
6938 (Etype (Base_Type (Typ)))
6947 -- Otherwise see if all record components are initialized
6953 Ent := First_Entity (Typ);
6954 while Present (Ent) loop
6955 if Ekind (Ent) = E_Component
6956 and then (No (Parent (Ent))
6957 or else No (Expression (Parent (Ent))))
6958 and then not Is_Fully_Initialized_Type (Etype (Ent))
6960 -- Special VM case for tag components, which need to be
6961 -- defined in this case, but are never initialized as VMs
6962 -- are using other dispatching mechanisms. Ignore this
6963 -- uninitialized case. Note that this applies both to the
6964 -- uTag entry and the main vtable pointer (CPP_Class case).
6966 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6975 -- No uninitialized components, so type is fully initialized.
6976 -- Note that this catches the case of no components as well.
6980 elsif Is_Concurrent_Type (Typ) then
6983 elsif Is_Private_Type (Typ) then
6985 U : constant Entity_Id := Underlying_Type (Typ);
6991 return Is_Fully_Initialized_Type (U);
6998 end Is_Fully_Initialized_Type;
7000 ----------------------------------
7001 -- Is_Fully_Initialized_Variant --
7002 ----------------------------------
7004 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
7005 Loc : constant Source_Ptr := Sloc (Typ);
7006 Constraints : constant List_Id := New_List;
7007 Components : constant Elist_Id := New_Elmt_List;
7008 Comp_Elmt : Elmt_Id;
7010 Comp_List : Node_Id;
7012 Discr_Val : Node_Id;
7014 Report_Errors : Boolean;
7015 pragma Warnings (Off, Report_Errors);
7018 if Serious_Errors_Detected > 0 then
7022 if Is_Record_Type (Typ)
7023 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7024 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7026 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7028 Discr := First_Discriminant (Typ);
7029 while Present (Discr) loop
7030 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7031 Discr_Val := Expression (Parent (Discr));
7033 if Present (Discr_Val)
7034 and then Is_OK_Static_Expression (Discr_Val)
7036 Append_To (Constraints,
7037 Make_Component_Association (Loc,
7038 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7039 Expression => New_Copy (Discr_Val)));
7047 Next_Discriminant (Discr);
7052 Comp_List => Comp_List,
7053 Governed_By => Constraints,
7055 Report_Errors => Report_Errors);
7057 -- Check that each component present is fully initialized
7059 Comp_Elmt := First_Elmt (Components);
7060 while Present (Comp_Elmt) loop
7061 Comp_Id := Node (Comp_Elmt);
7063 if Ekind (Comp_Id) = E_Component
7064 and then (No (Parent (Comp_Id))
7065 or else No (Expression (Parent (Comp_Id))))
7066 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7071 Next_Elmt (Comp_Elmt);
7076 elsif Is_Private_Type (Typ) then
7078 U : constant Entity_Id := Underlying_Type (Typ);
7084 return Is_Fully_Initialized_Variant (U);
7090 end Is_Fully_Initialized_Variant;
7096 -- We seem to have a lot of overlapping functions that do similar things
7097 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7098 -- purely syntactic, it should be in Sem_Aux I would think???
7100 function Is_LHS (N : Node_Id) return Boolean is
7101 P : constant Node_Id := Parent (N);
7104 if Nkind (P) = N_Assignment_Statement then
7105 return Name (P) = N;
7108 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7110 return N = Prefix (P) and then Is_LHS (P);
7117 ----------------------------
7118 -- Is_Inherited_Operation --
7119 ----------------------------
7121 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7122 Kind : constant Node_Kind := Nkind (Parent (E));
7124 pragma Assert (Is_Overloadable (E));
7125 return Kind = N_Full_Type_Declaration
7126 or else Kind = N_Private_Extension_Declaration
7127 or else Kind = N_Subtype_Declaration
7128 or else (Ekind (E) = E_Enumeration_Literal
7129 and then Is_Derived_Type (Etype (E)));
7130 end Is_Inherited_Operation;
7132 -------------------------------------
7133 -- Is_Inherited_Operation_For_Type --
7134 -------------------------------------
7136 function Is_Inherited_Operation_For_Type
7137 (E : Entity_Id; Typ : Entity_Id) return Boolean
7140 return Is_Inherited_Operation (E)
7141 and then Etype (Parent (E)) = Typ;
7142 end Is_Inherited_Operation_For_Type;
7144 -----------------------------
7145 -- Is_Library_Level_Entity --
7146 -----------------------------
7148 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7150 -- The following is a small optimization, and it also properly handles
7151 -- discriminals, which in task bodies might appear in expressions before
7152 -- the corresponding procedure has been created, and which therefore do
7153 -- not have an assigned scope.
7155 if Is_Formal (E) then
7159 -- Normal test is simply that the enclosing dynamic scope is Standard
7161 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7162 end Is_Library_Level_Entity;
7164 ---------------------------------
7165 -- Is_Local_Variable_Reference --
7166 ---------------------------------
7168 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7170 if not Is_Entity_Name (Expr) then
7175 Ent : constant Entity_Id := Entity (Expr);
7176 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7178 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7181 return Present (Sub) and then Sub = Current_Subprogram;
7185 end Is_Local_Variable_Reference;
7187 -------------------------
7188 -- Is_Object_Reference --
7189 -------------------------
7191 function Is_Object_Reference (N : Node_Id) return Boolean is
7193 if Is_Entity_Name (N) then
7194 return Present (Entity (N)) and then Is_Object (Entity (N));
7198 when N_Indexed_Component | N_Slice =>
7200 Is_Object_Reference (Prefix (N))
7201 or else Is_Access_Type (Etype (Prefix (N)));
7203 -- In Ada95, a function call is a constant object; a procedure
7206 when N_Function_Call =>
7207 return Etype (N) /= Standard_Void_Type;
7209 -- A reference to the stream attribute Input is a function call
7211 when N_Attribute_Reference =>
7212 return Attribute_Name (N) = Name_Input;
7214 when N_Selected_Component =>
7216 Is_Object_Reference (Selector_Name (N))
7218 (Is_Object_Reference (Prefix (N))
7219 or else Is_Access_Type (Etype (Prefix (N))));
7221 when N_Explicit_Dereference =>
7224 -- A view conversion of a tagged object is an object reference
7226 when N_Type_Conversion =>
7227 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7228 and then Is_Tagged_Type (Etype (Expression (N)))
7229 and then Is_Object_Reference (Expression (N));
7231 -- An unchecked type conversion is considered to be an object if
7232 -- the operand is an object (this construction arises only as a
7233 -- result of expansion activities).
7235 when N_Unchecked_Type_Conversion =>
7242 end Is_Object_Reference;
7244 -----------------------------------
7245 -- Is_OK_Variable_For_Out_Formal --
7246 -----------------------------------
7248 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7250 Note_Possible_Modification (AV, Sure => True);
7252 -- We must reject parenthesized variable names. The check for
7253 -- Comes_From_Source is present because there are currently
7254 -- cases where the compiler violates this rule (e.g. passing
7255 -- a task object to its controlled Initialize routine).
7257 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7260 -- A variable is always allowed
7262 elsif Is_Variable (AV) then
7265 -- Unchecked conversions are allowed only if they come from the
7266 -- generated code, which sometimes uses unchecked conversions for out
7267 -- parameters in cases where code generation is unaffected. We tell
7268 -- source unchecked conversions by seeing if they are rewrites of an
7269 -- original Unchecked_Conversion function call, or of an explicit
7270 -- conversion of a function call.
7272 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7273 if Nkind (Original_Node (AV)) = N_Function_Call then
7276 elsif Comes_From_Source (AV)
7277 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7281 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7282 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7288 -- Normal type conversions are allowed if argument is a variable
7290 elsif Nkind (AV) = N_Type_Conversion then
7291 if Is_Variable (Expression (AV))
7292 and then Paren_Count (Expression (AV)) = 0
7294 Note_Possible_Modification (Expression (AV), Sure => True);
7297 -- We also allow a non-parenthesized expression that raises
7298 -- constraint error if it rewrites what used to be a variable
7300 elsif Raises_Constraint_Error (Expression (AV))
7301 and then Paren_Count (Expression (AV)) = 0
7302 and then Is_Variable (Original_Node (Expression (AV)))
7306 -- Type conversion of something other than a variable
7312 -- If this node is rewritten, then test the original form, if that is
7313 -- OK, then we consider the rewritten node OK (for example, if the
7314 -- original node is a conversion, then Is_Variable will not be true
7315 -- but we still want to allow the conversion if it converts a variable).
7317 elsif Original_Node (AV) /= AV then
7318 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7320 -- All other non-variables are rejected
7325 end Is_OK_Variable_For_Out_Formal;
7327 -----------------------------------
7328 -- Is_Partially_Initialized_Type --
7329 -----------------------------------
7331 function Is_Partially_Initialized_Type
7333 Include_Implicit : Boolean := True) return Boolean
7336 if Is_Scalar_Type (Typ) then
7339 elsif Is_Access_Type (Typ) then
7340 return Include_Implicit;
7342 elsif Is_Array_Type (Typ) then
7344 -- If component type is partially initialized, so is array type
7346 if Is_Partially_Initialized_Type
7347 (Component_Type (Typ), Include_Implicit)
7351 -- Otherwise we are only partially initialized if we are fully
7352 -- initialized (this is the empty array case, no point in us
7353 -- duplicating that code here).
7356 return Is_Fully_Initialized_Type (Typ);
7359 elsif Is_Record_Type (Typ) then
7361 -- A discriminated type is always partially initialized if in
7364 if Has_Discriminants (Typ) and then Include_Implicit then
7367 -- A tagged type is always partially initialized
7369 elsif Is_Tagged_Type (Typ) then
7372 -- Case of non-discriminated record
7378 Component_Present : Boolean := False;
7379 -- Set True if at least one component is present. If no
7380 -- components are present, then record type is fully
7381 -- initialized (another odd case, like the null array).
7384 -- Loop through components
7386 Ent := First_Entity (Typ);
7387 while Present (Ent) loop
7388 if Ekind (Ent) = E_Component then
7389 Component_Present := True;
7391 -- If a component has an initialization expression then
7392 -- the enclosing record type is partially initialized
7394 if Present (Parent (Ent))
7395 and then Present (Expression (Parent (Ent)))
7399 -- If a component is of a type which is itself partially
7400 -- initialized, then the enclosing record type is also.
7402 elsif Is_Partially_Initialized_Type
7403 (Etype (Ent), Include_Implicit)
7412 -- No initialized components found. If we found any components
7413 -- they were all uninitialized so the result is false.
7415 if Component_Present then
7418 -- But if we found no components, then all the components are
7419 -- initialized so we consider the type to be initialized.
7427 -- Concurrent types are always fully initialized
7429 elsif Is_Concurrent_Type (Typ) then
7432 -- For a private type, go to underlying type. If there is no underlying
7433 -- type then just assume this partially initialized. Not clear if this
7434 -- can happen in a non-error case, but no harm in testing for this.
7436 elsif Is_Private_Type (Typ) then
7438 U : constant Entity_Id := Underlying_Type (Typ);
7443 return Is_Partially_Initialized_Type (U, Include_Implicit);
7447 -- For any other type (are there any?) assume partially initialized
7452 end Is_Partially_Initialized_Type;
7454 ------------------------------------
7455 -- Is_Potentially_Persistent_Type --
7456 ------------------------------------
7458 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7463 -- For private type, test corresponding full type
7465 if Is_Private_Type (T) then
7466 return Is_Potentially_Persistent_Type (Full_View (T));
7468 -- Scalar types are potentially persistent
7470 elsif Is_Scalar_Type (T) then
7473 -- Record type is potentially persistent if not tagged and the types of
7474 -- all it components are potentially persistent, and no component has
7475 -- an initialization expression.
7477 elsif Is_Record_Type (T)
7478 and then not Is_Tagged_Type (T)
7479 and then not Is_Partially_Initialized_Type (T)
7481 Comp := First_Component (T);
7482 while Present (Comp) loop
7483 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7492 -- Array type is potentially persistent if its component type is
7493 -- potentially persistent and if all its constraints are static.
7495 elsif Is_Array_Type (T) then
7496 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7500 Indx := First_Index (T);
7501 while Present (Indx) loop
7502 if not Is_OK_Static_Subtype (Etype (Indx)) then
7511 -- All other types are not potentially persistent
7516 end Is_Potentially_Persistent_Type;
7518 ---------------------------------
7519 -- Is_Protected_Self_Reference --
7520 ---------------------------------
7522 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7524 function In_Access_Definition (N : Node_Id) return Boolean;
7525 -- Returns true if N belongs to an access definition
7527 --------------------------
7528 -- In_Access_Definition --
7529 --------------------------
7531 function In_Access_Definition (N : Node_Id) return Boolean is
7536 while Present (P) loop
7537 if Nkind (P) = N_Access_Definition then
7545 end In_Access_Definition;
7547 -- Start of processing for Is_Protected_Self_Reference
7550 -- Verify that prefix is analyzed and has the proper form. Note that
7551 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7552 -- produce the address of an entity, do not analyze their prefix
7553 -- because they denote entities that are not necessarily visible.
7554 -- Neither of them can apply to a protected type.
7556 return Ada_Version >= Ada_2005
7557 and then Is_Entity_Name (N)
7558 and then Present (Entity (N))
7559 and then Is_Protected_Type (Entity (N))
7560 and then In_Open_Scopes (Entity (N))
7561 and then not In_Access_Definition (N);
7562 end Is_Protected_Self_Reference;
7564 -----------------------------
7565 -- Is_RCI_Pkg_Spec_Or_Body --
7566 -----------------------------
7568 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7570 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7571 -- Return True if the unit of Cunit is an RCI package declaration
7573 ---------------------------
7574 -- Is_RCI_Pkg_Decl_Cunit --
7575 ---------------------------
7577 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7578 The_Unit : constant Node_Id := Unit (Cunit);
7581 if Nkind (The_Unit) /= N_Package_Declaration then
7585 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7586 end Is_RCI_Pkg_Decl_Cunit;
7588 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7591 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7593 (Nkind (Unit (Cunit)) = N_Package_Body
7594 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7595 end Is_RCI_Pkg_Spec_Or_Body;
7597 -----------------------------------------
7598 -- Is_Remote_Access_To_Class_Wide_Type --
7599 -----------------------------------------
7601 function Is_Remote_Access_To_Class_Wide_Type
7602 (E : Entity_Id) return Boolean
7605 -- A remote access to class-wide type is a general access to object type
7606 -- declared in the visible part of a Remote_Types or Remote_Call_
7609 return Ekind (E) = E_General_Access_Type
7610 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7611 end Is_Remote_Access_To_Class_Wide_Type;
7613 -----------------------------------------
7614 -- Is_Remote_Access_To_Subprogram_Type --
7615 -----------------------------------------
7617 function Is_Remote_Access_To_Subprogram_Type
7618 (E : Entity_Id) return Boolean
7621 return (Ekind (E) = E_Access_Subprogram_Type
7622 or else (Ekind (E) = E_Record_Type
7623 and then Present (Corresponding_Remote_Type (E))))
7624 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7625 end Is_Remote_Access_To_Subprogram_Type;
7627 --------------------
7628 -- Is_Remote_Call --
7629 --------------------
7631 function Is_Remote_Call (N : Node_Id) return Boolean is
7633 if Nkind (N) /= N_Procedure_Call_Statement
7634 and then Nkind (N) /= N_Function_Call
7636 -- An entry call cannot be remote
7640 elsif Nkind (Name (N)) in N_Has_Entity
7641 and then Is_Remote_Call_Interface (Entity (Name (N)))
7643 -- A subprogram declared in the spec of a RCI package is remote
7647 elsif Nkind (Name (N)) = N_Explicit_Dereference
7648 and then Is_Remote_Access_To_Subprogram_Type
7649 (Etype (Prefix (Name (N))))
7651 -- The dereference of a RAS is a remote call
7655 elsif Present (Controlling_Argument (N))
7656 and then Is_Remote_Access_To_Class_Wide_Type
7657 (Etype (Controlling_Argument (N)))
7659 -- Any primitive operation call with a controlling argument of
7660 -- a RACW type is a remote call.
7665 -- All other calls are local calls
7670 ----------------------
7671 -- Is_Renamed_Entry --
7672 ----------------------
7674 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7675 Orig_Node : Node_Id := Empty;
7676 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7678 function Is_Entry (Nam : Node_Id) return Boolean;
7679 -- Determine whether Nam is an entry. Traverse selectors if there are
7680 -- nested selected components.
7686 function Is_Entry (Nam : Node_Id) return Boolean is
7688 if Nkind (Nam) = N_Selected_Component then
7689 return Is_Entry (Selector_Name (Nam));
7692 return Ekind (Entity (Nam)) = E_Entry;
7695 -- Start of processing for Is_Renamed_Entry
7698 if Present (Alias (Proc_Nam)) then
7699 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7702 -- Look for a rewritten subprogram renaming declaration
7704 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7705 and then Present (Original_Node (Subp_Decl))
7707 Orig_Node := Original_Node (Subp_Decl);
7710 -- The rewritten subprogram is actually an entry
7712 if Present (Orig_Node)
7713 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7714 and then Is_Entry (Name (Orig_Node))
7720 end Is_Renamed_Entry;
7722 ----------------------
7723 -- Is_Selector_Name --
7724 ----------------------
7726 function Is_Selector_Name (N : Node_Id) return Boolean is
7728 if not Is_List_Member (N) then
7730 P : constant Node_Id := Parent (N);
7731 K : constant Node_Kind := Nkind (P);
7734 (K = N_Expanded_Name or else
7735 K = N_Generic_Association or else
7736 K = N_Parameter_Association or else
7737 K = N_Selected_Component)
7738 and then Selector_Name (P) = N;
7743 L : constant List_Id := List_Containing (N);
7744 P : constant Node_Id := Parent (L);
7746 return (Nkind (P) = N_Discriminant_Association
7747 and then Selector_Names (P) = L)
7749 (Nkind (P) = N_Component_Association
7750 and then Choices (P) = L);
7753 end Is_Selector_Name;
7755 ----------------------------------
7756 -- Is_SPARK_Initialization_Expr --
7757 ----------------------------------
7759 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7762 Comp_Assn : Node_Id;
7763 Orig_N : constant Node_Id := Original_Node (N);
7768 if not Comes_From_Source (Orig_N) then
7772 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7774 case Nkind (Orig_N) is
7775 when N_Character_Literal |
7783 if Is_Entity_Name (Orig_N)
7784 and then Present (Entity (Orig_N)) -- needed in some cases
7786 case Ekind (Entity (Orig_N)) is
7788 E_Enumeration_Literal |
7793 if Is_Type (Entity (Orig_N)) then
7801 when N_Qualified_Expression |
7802 N_Type_Conversion =>
7803 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7806 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7810 N_Membership_Test =>
7811 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7812 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7815 N_Extension_Aggregate =>
7816 if Nkind (Orig_N) = N_Extension_Aggregate then
7817 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7820 Expr := First (Expressions (Orig_N));
7821 while Present (Expr) loop
7822 if not Is_SPARK_Initialization_Expr (Expr) then
7830 Comp_Assn := First (Component_Associations (Orig_N));
7831 while Present (Comp_Assn) loop
7832 Expr := Expression (Comp_Assn);
7833 if Present (Expr) -- needed for box association
7834 and then not Is_SPARK_Initialization_Expr (Expr)
7843 when N_Attribute_Reference =>
7844 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7845 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7848 Expr := First (Expressions (Orig_N));
7849 while Present (Expr) loop
7850 if not Is_SPARK_Initialization_Expr (Expr) then
7858 -- Selected components might be expanded named not yet resolved, so
7859 -- default on the safe side. (Eg on sparklex.ads)
7861 when N_Selected_Component =>
7870 end Is_SPARK_Initialization_Expr;
7872 -------------------------------
7873 -- Is_SPARK_Object_Reference --
7874 -------------------------------
7876 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7878 if Is_Entity_Name (N) then
7879 return Present (Entity (N))
7881 (Ekind_In (Entity (N), E_Constant, E_Variable)
7882 or else Ekind (Entity (N)) in Formal_Kind);
7886 when N_Selected_Component =>
7887 return Is_SPARK_Object_Reference (Prefix (N));
7893 end Is_SPARK_Object_Reference;
7899 function Is_Statement (N : Node_Id) return Boolean is
7902 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7903 or else Nkind (N) = N_Procedure_Call_Statement;
7906 ---------------------------------
7907 -- Is_Synchronized_Tagged_Type --
7908 ---------------------------------
7910 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7911 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7914 -- A task or protected type derived from an interface is a tagged type.
7915 -- Such a tagged type is called a synchronized tagged type, as are
7916 -- synchronized interfaces and private extensions whose declaration
7917 -- includes the reserved word synchronized.
7919 return (Is_Tagged_Type (E)
7920 and then (Kind = E_Task_Type
7921 or else Kind = E_Protected_Type))
7924 and then Is_Synchronized_Interface (E))
7926 (Ekind (E) = E_Record_Type_With_Private
7927 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7928 and then (Synchronized_Present (Parent (E))
7929 or else Is_Synchronized_Interface (Etype (E))));
7930 end Is_Synchronized_Tagged_Type;
7936 function Is_Transfer (N : Node_Id) return Boolean is
7937 Kind : constant Node_Kind := Nkind (N);
7940 if Kind = N_Simple_Return_Statement
7942 Kind = N_Extended_Return_Statement
7944 Kind = N_Goto_Statement
7946 Kind = N_Raise_Statement
7948 Kind = N_Requeue_Statement
7952 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7953 and then No (Condition (N))
7957 elsif Kind = N_Procedure_Call_Statement
7958 and then Is_Entity_Name (Name (N))
7959 and then Present (Entity (Name (N)))
7960 and then No_Return (Entity (Name (N)))
7964 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7976 function Is_True (U : Uint) return Boolean is
7981 -------------------------------
7982 -- Is_Universal_Numeric_Type --
7983 -------------------------------
7985 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7987 return T = Universal_Integer or else T = Universal_Real;
7988 end Is_Universal_Numeric_Type;
7994 function Is_Value_Type (T : Entity_Id) return Boolean is
7996 return VM_Target = CLI_Target
7997 and then Nkind (T) in N_Has_Chars
7998 and then Chars (T) /= No_Name
7999 and then Get_Name_String (Chars (T)) = "valuetype";
8002 ---------------------
8003 -- Is_VMS_Operator --
8004 ---------------------
8006 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
8008 -- The VMS operators are declared in a child of System that is loaded
8009 -- through pragma Extend_System. In some rare cases a program is run
8010 -- with this extension but without indicating that the target is VMS.
8012 return Ekind (Op) = E_Function
8013 and then Is_Intrinsic_Subprogram (Op)
8015 ((Present_System_Aux
8016 and then Scope (Op) = System_Aux_Id)
8019 and then Scope (Scope (Op)) = RTU_Entity (System)));
8020 end Is_VMS_Operator;
8026 function Is_Variable
8028 Use_Original_Node : Boolean := True) return Boolean
8030 Orig_Node : Node_Id;
8032 function In_Protected_Function (E : Entity_Id) return Boolean;
8033 -- Within a protected function, the private components of the enclosing
8034 -- protected type are constants. A function nested within a (protected)
8035 -- procedure is not itself protected.
8037 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8038 -- Prefixes can involve implicit dereferences, in which case we must
8039 -- test for the case of a reference of a constant access type, which can
8040 -- can never be a variable.
8042 ---------------------------
8043 -- In_Protected_Function --
8044 ---------------------------
8046 function In_Protected_Function (E : Entity_Id) return Boolean is
8047 Prot : constant Entity_Id := Scope (E);
8051 if not Is_Protected_Type (Prot) then
8055 while Present (S) and then S /= Prot loop
8056 if Ekind (S) = E_Function and then Scope (S) = Prot then
8065 end In_Protected_Function;
8067 ------------------------
8068 -- Is_Variable_Prefix --
8069 ------------------------
8071 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8073 if Is_Access_Type (Etype (P)) then
8074 return not Is_Access_Constant (Root_Type (Etype (P)));
8076 -- For the case of an indexed component whose prefix has a packed
8077 -- array type, the prefix has been rewritten into a type conversion.
8078 -- Determine variable-ness from the converted expression.
8080 elsif Nkind (P) = N_Type_Conversion
8081 and then not Comes_From_Source (P)
8082 and then Is_Array_Type (Etype (P))
8083 and then Is_Packed (Etype (P))
8085 return Is_Variable (Expression (P));
8088 return Is_Variable (P);
8090 end Is_Variable_Prefix;
8092 -- Start of processing for Is_Variable
8095 -- Check if we perform the test on the original node since this may be a
8096 -- test of syntactic categories which must not be disturbed by whatever
8097 -- rewriting might have occurred. For example, an aggregate, which is
8098 -- certainly NOT a variable, could be turned into a variable by
8101 if Use_Original_Node then
8102 Orig_Node := Original_Node (N);
8107 -- Definitely OK if Assignment_OK is set. Since this is something that
8108 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8110 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8113 -- Normally we go to the original node, but there is one exception where
8114 -- we use the rewritten node, namely when it is an explicit dereference.
8115 -- The generated code may rewrite a prefix which is an access type with
8116 -- an explicit dereference. The dereference is a variable, even though
8117 -- the original node may not be (since it could be a constant of the
8120 -- In Ada 2005 we have a further case to consider: the prefix may be a
8121 -- function call given in prefix notation. The original node appears to
8122 -- be a selected component, but we need to examine the call.
8124 elsif Nkind (N) = N_Explicit_Dereference
8125 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8126 and then Present (Etype (Orig_Node))
8127 and then Is_Access_Type (Etype (Orig_Node))
8129 -- Note that if the prefix is an explicit dereference that does not
8130 -- come from source, we must check for a rewritten function call in
8131 -- prefixed notation before other forms of rewriting, to prevent a
8135 (Nkind (Orig_Node) = N_Function_Call
8136 and then not Is_Access_Constant (Etype (Prefix (N))))
8138 Is_Variable_Prefix (Original_Node (Prefix (N)));
8140 -- A function call is never a variable
8142 elsif Nkind (N) = N_Function_Call then
8145 -- All remaining checks use the original node
8147 elsif Is_Entity_Name (Orig_Node)
8148 and then Present (Entity (Orig_Node))
8151 E : constant Entity_Id := Entity (Orig_Node);
8152 K : constant Entity_Kind := Ekind (E);
8155 return (K = E_Variable
8156 and then Nkind (Parent (E)) /= N_Exception_Handler)
8157 or else (K = E_Component
8158 and then not In_Protected_Function (E))
8159 or else K = E_Out_Parameter
8160 or else K = E_In_Out_Parameter
8161 or else K = E_Generic_In_Out_Parameter
8163 -- Current instance of type:
8165 or else (Is_Type (E) and then In_Open_Scopes (E))
8166 or else (Is_Incomplete_Or_Private_Type (E)
8167 and then In_Open_Scopes (Full_View (E)));
8171 case Nkind (Orig_Node) is
8172 when N_Indexed_Component | N_Slice =>
8173 return Is_Variable_Prefix (Prefix (Orig_Node));
8175 when N_Selected_Component =>
8176 return Is_Variable_Prefix (Prefix (Orig_Node))
8177 and then Is_Variable (Selector_Name (Orig_Node));
8179 -- For an explicit dereference, the type of the prefix cannot
8180 -- be an access to constant or an access to subprogram.
8182 when N_Explicit_Dereference =>
8184 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8186 return Is_Access_Type (Typ)
8187 and then not Is_Access_Constant (Root_Type (Typ))
8188 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8191 -- The type conversion is the case where we do not deal with the
8192 -- context dependent special case of an actual parameter. Thus
8193 -- the type conversion is only considered a variable for the
8194 -- purposes of this routine if the target type is tagged. However,
8195 -- a type conversion is considered to be a variable if it does not
8196 -- come from source (this deals for example with the conversions
8197 -- of expressions to their actual subtypes).
8199 when N_Type_Conversion =>
8200 return Is_Variable (Expression (Orig_Node))
8202 (not Comes_From_Source (Orig_Node)
8204 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8206 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8208 -- GNAT allows an unchecked type conversion as a variable. This
8209 -- only affects the generation of internal expanded code, since
8210 -- calls to instantiations of Unchecked_Conversion are never
8211 -- considered variables (since they are function calls).
8212 -- This is also true for expression actions.
8214 when N_Unchecked_Type_Conversion =>
8215 return Is_Variable (Expression (Orig_Node));
8223 ---------------------------
8224 -- Is_Visibly_Controlled --
8225 ---------------------------
8227 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8228 Root : constant Entity_Id := Root_Type (T);
8230 return Chars (Scope (Root)) = Name_Finalization
8231 and then Chars (Scope (Scope (Root))) = Name_Ada
8232 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8233 end Is_Visibly_Controlled;
8235 ------------------------
8236 -- Is_Volatile_Object --
8237 ------------------------
8239 function Is_Volatile_Object (N : Node_Id) return Boolean is
8241 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8242 -- Determines if given object has volatile components
8244 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8245 -- If prefix is an implicit dereference, examine designated type
8247 ------------------------
8248 -- Is_Volatile_Prefix --
8249 ------------------------
8251 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8252 Typ : constant Entity_Id := Etype (N);
8255 if Is_Access_Type (Typ) then
8257 Dtyp : constant Entity_Id := Designated_Type (Typ);
8260 return Is_Volatile (Dtyp)
8261 or else Has_Volatile_Components (Dtyp);
8265 return Object_Has_Volatile_Components (N);
8267 end Is_Volatile_Prefix;
8269 ------------------------------------
8270 -- Object_Has_Volatile_Components --
8271 ------------------------------------
8273 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8274 Typ : constant Entity_Id := Etype (N);
8277 if Is_Volatile (Typ)
8278 or else Has_Volatile_Components (Typ)
8282 elsif Is_Entity_Name (N)
8283 and then (Has_Volatile_Components (Entity (N))
8284 or else Is_Volatile (Entity (N)))
8288 elsif Nkind (N) = N_Indexed_Component
8289 or else Nkind (N) = N_Selected_Component
8291 return Is_Volatile_Prefix (Prefix (N));
8296 end Object_Has_Volatile_Components;
8298 -- Start of processing for Is_Volatile_Object
8301 if Is_Volatile (Etype (N))
8302 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8306 elsif Nkind (N) = N_Indexed_Component
8307 or else Nkind (N) = N_Selected_Component
8309 return Is_Volatile_Prefix (Prefix (N));
8314 end Is_Volatile_Object;
8316 -------------------------
8317 -- Kill_Current_Values --
8318 -------------------------
8320 procedure Kill_Current_Values
8322 Last_Assignment_Only : Boolean := False)
8325 -- ??? do we have to worry about clearing cached checks?
8327 if Is_Assignable (Ent) then
8328 Set_Last_Assignment (Ent, Empty);
8331 if Is_Object (Ent) then
8332 if not Last_Assignment_Only then
8334 Set_Current_Value (Ent, Empty);
8336 if not Can_Never_Be_Null (Ent) then
8337 Set_Is_Known_Non_Null (Ent, False);
8340 Set_Is_Known_Null (Ent, False);
8342 -- Reset Is_Known_Valid unless type is always valid, or if we have
8343 -- a loop parameter (loop parameters are always valid, since their
8344 -- bounds are defined by the bounds given in the loop header).
8346 if not Is_Known_Valid (Etype (Ent))
8347 and then Ekind (Ent) /= E_Loop_Parameter
8349 Set_Is_Known_Valid (Ent, False);
8353 end Kill_Current_Values;
8355 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8358 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8359 -- Clear current value for entity E and all entities chained to E
8361 ------------------------------------------
8362 -- Kill_Current_Values_For_Entity_Chain --
8363 ------------------------------------------
8365 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8369 while Present (Ent) loop
8370 Kill_Current_Values (Ent, Last_Assignment_Only);
8373 end Kill_Current_Values_For_Entity_Chain;
8375 -- Start of processing for Kill_Current_Values
8378 -- Kill all saved checks, a special case of killing saved values
8380 if not Last_Assignment_Only then
8384 -- Loop through relevant scopes, which includes the current scope and
8385 -- any parent scopes if the current scope is a block or a package.
8390 -- Clear current values of all entities in current scope
8392 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8394 -- If scope is a package, also clear current values of all
8395 -- private entities in the scope.
8397 if Is_Package_Or_Generic_Package (S)
8398 or else Is_Concurrent_Type (S)
8400 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8403 -- If this is a not a subprogram, deal with parents
8405 if not Is_Subprogram (S) then
8407 exit Scope_Loop when S = Standard_Standard;
8411 end loop Scope_Loop;
8412 end Kill_Current_Values;
8414 --------------------------
8415 -- Kill_Size_Check_Code --
8416 --------------------------
8418 procedure Kill_Size_Check_Code (E : Entity_Id) is
8420 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8421 and then Present (Size_Check_Code (E))
8423 Remove (Size_Check_Code (E));
8424 Set_Size_Check_Code (E, Empty);
8426 end Kill_Size_Check_Code;
8428 --------------------------
8429 -- Known_To_Be_Assigned --
8430 --------------------------
8432 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8433 P : constant Node_Id := Parent (N);
8438 -- Test left side of assignment
8440 when N_Assignment_Statement =>
8441 return N = Name (P);
8443 -- Function call arguments are never lvalues
8445 when N_Function_Call =>
8448 -- Positional parameter for procedure or accept call
8450 when N_Procedure_Call_Statement |
8459 Proc := Get_Subprogram_Entity (P);
8465 -- If we are not a list member, something is strange, so
8466 -- be conservative and return False.
8468 if not Is_List_Member (N) then
8472 -- We are going to find the right formal by stepping forward
8473 -- through the formals, as we step backwards in the actuals.
8475 Form := First_Formal (Proc);
8478 -- If no formal, something is weird, so be conservative
8479 -- and return False.
8490 return Ekind (Form) /= E_In_Parameter;
8493 -- Named parameter for procedure or accept call
8495 when N_Parameter_Association =>
8501 Proc := Get_Subprogram_Entity (Parent (P));
8507 -- Loop through formals to find the one that matches
8509 Form := First_Formal (Proc);
8511 -- If no matching formal, that's peculiar, some kind of
8512 -- previous error, so return False to be conservative.
8518 -- Else test for match
8520 if Chars (Form) = Chars (Selector_Name (P)) then
8521 return Ekind (Form) /= E_In_Parameter;
8528 -- Test for appearing in a conversion that itself appears
8529 -- in an lvalue context, since this should be an lvalue.
8531 when N_Type_Conversion =>
8532 return Known_To_Be_Assigned (P);
8534 -- All other references are definitely not known to be modifications
8540 end Known_To_Be_Assigned;
8542 ---------------------------
8543 -- Last_Source_Statement --
8544 ---------------------------
8546 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8550 N := Last (Statements (HSS));
8551 while Present (N) loop
8552 exit when Comes_From_Source (N);
8557 end Last_Source_Statement;
8559 ----------------------------------
8560 -- Matching_Static_Array_Bounds --
8561 ----------------------------------
8563 function Matching_Static_Array_Bounds
8565 R_Typ : Node_Id) return Boolean
8567 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8568 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8580 if L_Ndims /= R_Ndims then
8584 -- Unconstrained types do not have static bounds
8586 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8590 -- First treat specially the first dimension, as the lower bound and
8591 -- length of string literals are not stored like those of arrays.
8593 if Ekind (L_Typ) = E_String_Literal_Subtype then
8594 L_Low := String_Literal_Low_Bound (L_Typ);
8595 L_Len := String_Literal_Length (L_Typ);
8597 L_Index := First_Index (L_Typ);
8598 Get_Index_Bounds (L_Index, L_Low, L_High);
8600 if Is_OK_Static_Expression (L_Low)
8601 and then Is_OK_Static_Expression (L_High)
8603 if Expr_Value (L_High) < Expr_Value (L_Low) then
8606 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8613 if Ekind (R_Typ) = E_String_Literal_Subtype then
8614 R_Low := String_Literal_Low_Bound (R_Typ);
8615 R_Len := String_Literal_Length (R_Typ);
8617 R_Index := First_Index (R_Typ);
8618 Get_Index_Bounds (R_Index, R_Low, R_High);
8620 if Is_OK_Static_Expression (R_Low)
8621 and then Is_OK_Static_Expression (R_High)
8623 if Expr_Value (R_High) < Expr_Value (R_Low) then
8626 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8633 if Is_OK_Static_Expression (L_Low)
8634 and then Is_OK_Static_Expression (R_Low)
8635 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8636 and then L_Len = R_Len
8643 -- Then treat all other dimensions
8645 for Indx in 2 .. L_Ndims loop
8649 Get_Index_Bounds (L_Index, L_Low, L_High);
8650 Get_Index_Bounds (R_Index, R_Low, R_High);
8652 if Is_OK_Static_Expression (L_Low)
8653 and then Is_OK_Static_Expression (L_High)
8654 and then Is_OK_Static_Expression (R_Low)
8655 and then Is_OK_Static_Expression (R_High)
8656 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8657 and then Expr_Value (L_High) = Expr_Value (R_High)
8665 -- If we fall through the loop, all indexes matched
8668 end Matching_Static_Array_Bounds;
8674 function May_Be_Lvalue (N : Node_Id) return Boolean is
8675 P : constant Node_Id := Parent (N);
8680 -- Test left side of assignment
8682 when N_Assignment_Statement =>
8683 return N = Name (P);
8685 -- Test prefix of component or attribute. Note that the prefix of an
8686 -- explicit or implicit dereference cannot be an l-value.
8688 when N_Attribute_Reference =>
8689 return N = Prefix (P)
8690 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8692 -- For an expanded name, the name is an lvalue if the expanded name
8693 -- is an lvalue, but the prefix is never an lvalue, since it is just
8694 -- the scope where the name is found.
8696 when N_Expanded_Name =>
8697 if N = Prefix (P) then
8698 return May_Be_Lvalue (P);
8703 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8704 -- B is a little interesting, if we have A.B := 3, there is some
8705 -- discussion as to whether B is an lvalue or not, we choose to say
8706 -- it is. Note however that A is not an lvalue if it is of an access
8707 -- type since this is an implicit dereference.
8709 when N_Selected_Component =>
8711 and then Present (Etype (N))
8712 and then Is_Access_Type (Etype (N))
8716 return May_Be_Lvalue (P);
8719 -- For an indexed component or slice, the index or slice bounds is
8720 -- never an lvalue. The prefix is an lvalue if the indexed component
8721 -- or slice is an lvalue, except if it is an access type, where we
8722 -- have an implicit dereference.
8724 when N_Indexed_Component =>
8726 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8730 return May_Be_Lvalue (P);
8733 -- Prefix of a reference is an lvalue if the reference is an lvalue
8736 return May_Be_Lvalue (P);
8738 -- Prefix of explicit dereference is never an lvalue
8740 when N_Explicit_Dereference =>
8743 -- Positional parameter for subprogram, entry, or accept call.
8744 -- In older versions of Ada function call arguments are never
8745 -- lvalues. In Ada 2012 functions can have in-out parameters.
8747 when N_Function_Call |
8748 N_Procedure_Call_Statement |
8749 N_Entry_Call_Statement |
8752 if Nkind (P) = N_Function_Call
8753 and then Ada_Version < Ada_2012
8758 -- The following mechanism is clumsy and fragile. A single
8759 -- flag set in Resolve_Actuals would be preferable ???
8767 Proc := Get_Subprogram_Entity (P);
8773 -- If we are not a list member, something is strange, so
8774 -- be conservative and return True.
8776 if not Is_List_Member (N) then
8780 -- We are going to find the right formal by stepping forward
8781 -- through the formals, as we step backwards in the actuals.
8783 Form := First_Formal (Proc);
8786 -- If no formal, something is weird, so be conservative
8798 return Ekind (Form) /= E_In_Parameter;
8801 -- Named parameter for procedure or accept call
8803 when N_Parameter_Association =>
8809 Proc := Get_Subprogram_Entity (Parent (P));
8815 -- Loop through formals to find the one that matches
8817 Form := First_Formal (Proc);
8819 -- If no matching formal, that's peculiar, some kind of
8820 -- previous error, so return True to be conservative.
8826 -- Else test for match
8828 if Chars (Form) = Chars (Selector_Name (P)) then
8829 return Ekind (Form) /= E_In_Parameter;
8836 -- Test for appearing in a conversion that itself appears in an
8837 -- lvalue context, since this should be an lvalue.
8839 when N_Type_Conversion =>
8840 return May_Be_Lvalue (P);
8842 -- Test for appearance in object renaming declaration
8844 when N_Object_Renaming_Declaration =>
8847 -- All other references are definitely not lvalues
8855 -----------------------
8856 -- Mark_Coextensions --
8857 -----------------------
8859 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8860 Is_Dynamic : Boolean;
8861 -- Indicates whether the context causes nested coextensions to be
8862 -- dynamic or static
8864 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8865 -- Recognize an allocator node and label it as a dynamic coextension
8867 --------------------
8868 -- Mark_Allocator --
8869 --------------------
8871 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8873 if Nkind (N) = N_Allocator then
8875 Set_Is_Dynamic_Coextension (N);
8877 -- If the allocator expression is potentially dynamic, it may
8878 -- be expanded out of order and require dynamic allocation
8879 -- anyway, so we treat the coextension itself as dynamic.
8880 -- Potential optimization ???
8882 elsif Nkind (Expression (N)) = N_Qualified_Expression
8883 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8885 Set_Is_Dynamic_Coextension (N);
8888 Set_Is_Static_Coextension (N);
8895 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8897 -- Start of processing Mark_Coextensions
8900 case Nkind (Context_Nod) is
8901 when N_Assignment_Statement |
8902 N_Simple_Return_Statement =>
8903 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8905 when N_Object_Declaration =>
8906 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8908 -- This routine should not be called for constructs which may not
8909 -- contain coextensions.
8912 raise Program_Error;
8915 Mark_Allocators (Root_Nod);
8916 end Mark_Coextensions;
8918 ----------------------
8919 -- Needs_One_Actual --
8920 ----------------------
8922 function Needs_One_Actual (E : Entity_Id) return Boolean is
8926 if Ada_Version >= Ada_2005
8927 and then Present (First_Formal (E))
8929 Formal := Next_Formal (First_Formal (E));
8930 while Present (Formal) loop
8931 if No (Default_Value (Formal)) then
8935 Next_Formal (Formal);
8943 end Needs_One_Actual;
8945 ------------------------
8946 -- New_Copy_List_Tree --
8947 ------------------------
8949 function New_Copy_List_Tree (List : List_Id) return List_Id is
8954 if List = No_List then
8961 while Present (E) loop
8962 Append (New_Copy_Tree (E), NL);
8968 end New_Copy_List_Tree;
8974 use Atree.Unchecked_Access;
8975 use Atree_Private_Part;
8977 -- Our approach here requires a two pass traversal of the tree. The
8978 -- first pass visits all nodes that eventually will be copied looking
8979 -- for defining Itypes. If any defining Itypes are found, then they are
8980 -- copied, and an entry is added to the replacement map. In the second
8981 -- phase, the tree is copied, using the replacement map to replace any
8982 -- Itype references within the copied tree.
8984 -- The following hash tables are used if the Map supplied has more
8985 -- than hash threshold entries to speed up access to the map. If
8986 -- there are fewer entries, then the map is searched sequentially
8987 -- (because setting up a hash table for only a few entries takes
8988 -- more time than it saves.
8990 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8991 -- Hash function used for hash operations
8997 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8999 return Nat (E) mod (NCT_Header_Num'Last + 1);
9006 -- The hash table NCT_Assoc associates old entities in the table
9007 -- with their corresponding new entities (i.e. the pairs of entries
9008 -- presented in the original Map argument are Key-Element pairs).
9010 package NCT_Assoc is new Simple_HTable (
9011 Header_Num => NCT_Header_Num,
9012 Element => Entity_Id,
9013 No_Element => Empty,
9015 Hash => New_Copy_Hash,
9016 Equal => Types."=");
9018 ---------------------
9019 -- NCT_Itype_Assoc --
9020 ---------------------
9022 -- The hash table NCT_Itype_Assoc contains entries only for those
9023 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9024 -- The key is the associated node, and the element is the new node
9025 -- itself (NOT the associated node for the new node).
9027 package NCT_Itype_Assoc is new Simple_HTable (
9028 Header_Num => NCT_Header_Num,
9029 Element => Entity_Id,
9030 No_Element => Empty,
9032 Hash => New_Copy_Hash,
9033 Equal => Types."=");
9035 -- Start of processing for New_Copy_Tree function
9037 function New_Copy_Tree
9039 Map : Elist_Id := No_Elist;
9040 New_Sloc : Source_Ptr := No_Location;
9041 New_Scope : Entity_Id := Empty) return Node_Id
9043 Actual_Map : Elist_Id := Map;
9044 -- This is the actual map for the copy. It is initialized with the
9045 -- given elements, and then enlarged as required for Itypes that are
9046 -- copied during the first phase of the copy operation. The visit
9047 -- procedures add elements to this map as Itypes are encountered.
9048 -- The reason we cannot use Map directly, is that it may well be
9049 -- (and normally is) initialized to No_Elist, and if we have mapped
9050 -- entities, we have to reset it to point to a real Elist.
9052 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9053 -- Called during second phase to map entities into their corresponding
9054 -- copies using Actual_Map. If the argument is not an entity, or is not
9055 -- in Actual_Map, then it is returned unchanged.
9057 procedure Build_NCT_Hash_Tables;
9058 -- Builds hash tables (number of elements >= threshold value)
9060 function Copy_Elist_With_Replacement
9061 (Old_Elist : Elist_Id) return Elist_Id;
9062 -- Called during second phase to copy element list doing replacements
9064 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9065 -- Called during the second phase to process a copied Itype. The actual
9066 -- copy happened during the first phase (so that we could make the entry
9067 -- in the mapping), but we still have to deal with the descendents of
9068 -- the copied Itype and copy them where necessary.
9070 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9071 -- Called during second phase to copy list doing replacements
9073 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9074 -- Called during second phase to copy node doing replacements
9076 procedure Visit_Elist (E : Elist_Id);
9077 -- Called during first phase to visit all elements of an Elist
9079 procedure Visit_Field (F : Union_Id; N : Node_Id);
9080 -- Visit a single field, recursing to call Visit_Node or Visit_List
9081 -- if the field is a syntactic descendent of the current node (i.e.
9082 -- its parent is Node N).
9084 procedure Visit_Itype (Old_Itype : Entity_Id);
9085 -- Called during first phase to visit subsidiary fields of a defining
9086 -- Itype, and also create a copy and make an entry in the replacement
9087 -- map for the new copy.
9089 procedure Visit_List (L : List_Id);
9090 -- Called during first phase to visit all elements of a List
9092 procedure Visit_Node (N : Node_Or_Entity_Id);
9093 -- Called during first phase to visit a node and all its subtrees
9099 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9104 if not Has_Extension (N) or else No (Actual_Map) then
9107 elsif NCT_Hash_Tables_Used then
9108 Ent := NCT_Assoc.Get (Entity_Id (N));
9110 if Present (Ent) then
9116 -- No hash table used, do serial search
9119 E := First_Elmt (Actual_Map);
9120 while Present (E) loop
9121 if Node (E) = N then
9122 return Node (Next_Elmt (E));
9124 E := Next_Elmt (Next_Elmt (E));
9132 ---------------------------
9133 -- Build_NCT_Hash_Tables --
9134 ---------------------------
9136 procedure Build_NCT_Hash_Tables is
9140 if NCT_Hash_Table_Setup then
9142 NCT_Itype_Assoc.Reset;
9145 Elmt := First_Elmt (Actual_Map);
9146 while Present (Elmt) loop
9149 -- Get new entity, and associate old and new
9152 NCT_Assoc.Set (Ent, Node (Elmt));
9154 if Is_Type (Ent) then
9156 Anode : constant Entity_Id :=
9157 Associated_Node_For_Itype (Ent);
9160 if Present (Anode) then
9162 -- Enter a link between the associated node of the
9163 -- old Itype and the new Itype, for updating later
9164 -- when node is copied.
9166 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9174 NCT_Hash_Tables_Used := True;
9175 NCT_Hash_Table_Setup := True;
9176 end Build_NCT_Hash_Tables;
9178 ---------------------------------
9179 -- Copy_Elist_With_Replacement --
9180 ---------------------------------
9182 function Copy_Elist_With_Replacement
9183 (Old_Elist : Elist_Id) return Elist_Id
9186 New_Elist : Elist_Id;
9189 if No (Old_Elist) then
9193 New_Elist := New_Elmt_List;
9195 M := First_Elmt (Old_Elist);
9196 while Present (M) loop
9197 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9203 end Copy_Elist_With_Replacement;
9205 ---------------------------------
9206 -- Copy_Itype_With_Replacement --
9207 ---------------------------------
9209 -- This routine exactly parallels its phase one analog Visit_Itype,
9211 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9213 -- Translate Next_Entity, Scope and Etype fields, in case they
9214 -- reference entities that have been mapped into copies.
9216 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9217 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9219 if Present (New_Scope) then
9220 Set_Scope (New_Itype, New_Scope);
9222 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9225 -- Copy referenced fields
9227 if Is_Discrete_Type (New_Itype) then
9228 Set_Scalar_Range (New_Itype,
9229 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9231 elsif Has_Discriminants (Base_Type (New_Itype)) then
9232 Set_Discriminant_Constraint (New_Itype,
9233 Copy_Elist_With_Replacement
9234 (Discriminant_Constraint (New_Itype)));
9236 elsif Is_Array_Type (New_Itype) then
9237 if Present (First_Index (New_Itype)) then
9238 Set_First_Index (New_Itype,
9239 First (Copy_List_With_Replacement
9240 (List_Containing (First_Index (New_Itype)))));
9243 if Is_Packed (New_Itype) then
9244 Set_Packed_Array_Type (New_Itype,
9245 Copy_Node_With_Replacement
9246 (Packed_Array_Type (New_Itype)));
9249 end Copy_Itype_With_Replacement;
9251 --------------------------------
9252 -- Copy_List_With_Replacement --
9253 --------------------------------
9255 function Copy_List_With_Replacement
9256 (Old_List : List_Id) return List_Id
9262 if Old_List = No_List then
9266 New_List := Empty_List;
9268 E := First (Old_List);
9269 while Present (E) loop
9270 Append (Copy_Node_With_Replacement (E), New_List);
9276 end Copy_List_With_Replacement;
9278 --------------------------------
9279 -- Copy_Node_With_Replacement --
9280 --------------------------------
9282 function Copy_Node_With_Replacement
9283 (Old_Node : Node_Id) return Node_Id
9287 procedure Adjust_Named_Associations
9288 (Old_Node : Node_Id;
9289 New_Node : Node_Id);
9290 -- If a call node has named associations, these are chained through
9291 -- the First_Named_Actual, Next_Named_Actual links. These must be
9292 -- propagated separately to the new parameter list, because these
9293 -- are not syntactic fields.
9295 function Copy_Field_With_Replacement
9296 (Field : Union_Id) return Union_Id;
9297 -- Given Field, which is a field of Old_Node, return a copy of it
9298 -- if it is a syntactic field (i.e. its parent is Node), setting
9299 -- the parent of the copy to poit to New_Node. Otherwise returns
9300 -- the field (possibly mapped if it is an entity).
9302 -------------------------------
9303 -- Adjust_Named_Associations --
9304 -------------------------------
9306 procedure Adjust_Named_Associations
9307 (Old_Node : Node_Id;
9317 Old_E := First (Parameter_Associations (Old_Node));
9318 New_E := First (Parameter_Associations (New_Node));
9319 while Present (Old_E) loop
9320 if Nkind (Old_E) = N_Parameter_Association
9321 and then Present (Next_Named_Actual (Old_E))
9323 if First_Named_Actual (Old_Node)
9324 = Explicit_Actual_Parameter (Old_E)
9326 Set_First_Named_Actual
9327 (New_Node, Explicit_Actual_Parameter (New_E));
9330 -- Now scan parameter list from the beginning,to locate
9331 -- next named actual, which can be out of order.
9333 Old_Next := First (Parameter_Associations (Old_Node));
9334 New_Next := First (Parameter_Associations (New_Node));
9336 while Nkind (Old_Next) /= N_Parameter_Association
9337 or else Explicit_Actual_Parameter (Old_Next)
9338 /= Next_Named_Actual (Old_E)
9344 Set_Next_Named_Actual
9345 (New_E, Explicit_Actual_Parameter (New_Next));
9351 end Adjust_Named_Associations;
9353 ---------------------------------
9354 -- Copy_Field_With_Replacement --
9355 ---------------------------------
9357 function Copy_Field_With_Replacement
9358 (Field : Union_Id) return Union_Id
9361 if Field = Union_Id (Empty) then
9364 elsif Field in Node_Range then
9366 Old_N : constant Node_Id := Node_Id (Field);
9370 -- If syntactic field, as indicated by the parent pointer
9371 -- being set, then copy the referenced node recursively.
9373 if Parent (Old_N) = Old_Node then
9374 New_N := Copy_Node_With_Replacement (Old_N);
9376 if New_N /= Old_N then
9377 Set_Parent (New_N, New_Node);
9380 -- For semantic fields, update possible entity reference
9381 -- from the replacement map.
9384 New_N := Assoc (Old_N);
9387 return Union_Id (New_N);
9390 elsif Field in List_Range then
9392 Old_L : constant List_Id := List_Id (Field);
9396 -- If syntactic field, as indicated by the parent pointer,
9397 -- then recursively copy the entire referenced list.
9399 if Parent (Old_L) = Old_Node then
9400 New_L := Copy_List_With_Replacement (Old_L);
9401 Set_Parent (New_L, New_Node);
9403 -- For semantic list, just returned unchanged
9409 return Union_Id (New_L);
9412 -- Anything other than a list or a node is returned unchanged
9417 end Copy_Field_With_Replacement;
9419 -- Start of processing for Copy_Node_With_Replacement
9422 if Old_Node <= Empty_Or_Error then
9425 elsif Has_Extension (Old_Node) then
9426 return Assoc (Old_Node);
9429 New_Node := New_Copy (Old_Node);
9431 -- If the node we are copying is the associated node of a
9432 -- previously copied Itype, then adjust the associated node
9433 -- of the copy of that Itype accordingly.
9435 if Present (Actual_Map) then
9441 -- Case of hash table used
9443 if NCT_Hash_Tables_Used then
9444 Ent := NCT_Itype_Assoc.Get (Old_Node);
9446 if Present (Ent) then
9447 Set_Associated_Node_For_Itype (Ent, New_Node);
9450 -- Case of no hash table used
9453 E := First_Elmt (Actual_Map);
9454 while Present (E) loop
9455 if Is_Itype (Node (E))
9457 Old_Node = Associated_Node_For_Itype (Node (E))
9459 Set_Associated_Node_For_Itype
9460 (Node (Next_Elmt (E)), New_Node);
9463 E := Next_Elmt (Next_Elmt (E));
9469 -- Recursively copy descendents
9472 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9474 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9476 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9478 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9480 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9482 -- Adjust Sloc of new node if necessary
9484 if New_Sloc /= No_Location then
9485 Set_Sloc (New_Node, New_Sloc);
9487 -- If we adjust the Sloc, then we are essentially making
9488 -- a completely new node, so the Comes_From_Source flag
9489 -- should be reset to the proper default value.
9491 Nodes.Table (New_Node).Comes_From_Source :=
9492 Default_Node.Comes_From_Source;
9495 -- If the node is call and has named associations,
9496 -- set the corresponding links in the copy.
9498 if (Nkind (Old_Node) = N_Function_Call
9499 or else Nkind (Old_Node) = N_Entry_Call_Statement
9501 Nkind (Old_Node) = N_Procedure_Call_Statement)
9502 and then Present (First_Named_Actual (Old_Node))
9504 Adjust_Named_Associations (Old_Node, New_Node);
9507 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9508 -- The replacement mechanism applies to entities, and is not used
9509 -- here. Eventually we may need a more general graph-copying
9510 -- routine. For now, do a sequential search to find desired node.
9512 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9513 and then Present (First_Real_Statement (Old_Node))
9516 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9520 N1 := First (Statements (Old_Node));
9521 N2 := First (Statements (New_Node));
9523 while N1 /= Old_F loop
9528 Set_First_Real_Statement (New_Node, N2);
9533 -- All done, return copied node
9536 end Copy_Node_With_Replacement;
9542 procedure Visit_Elist (E : Elist_Id) is
9546 Elmt := First_Elmt (E);
9548 while Elmt /= No_Elmt loop
9549 Visit_Node (Node (Elmt));
9559 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9561 if F = Union_Id (Empty) then
9564 elsif F in Node_Range then
9566 -- Copy node if it is syntactic, i.e. its parent pointer is
9567 -- set to point to the field that referenced it (certain
9568 -- Itypes will also meet this criterion, which is fine, since
9569 -- these are clearly Itypes that do need to be copied, since
9570 -- we are copying their parent.)
9572 if Parent (Node_Id (F)) = N then
9573 Visit_Node (Node_Id (F));
9576 -- Another case, if we are pointing to an Itype, then we want
9577 -- to copy it if its associated node is somewhere in the tree
9580 -- Note: the exclusion of self-referential copies is just an
9581 -- optimization, since the search of the already copied list
9582 -- would catch it, but it is a common case (Etype pointing
9583 -- to itself for an Itype that is a base type).
9585 elsif Has_Extension (Node_Id (F))
9586 and then Is_Itype (Entity_Id (F))
9587 and then Node_Id (F) /= N
9593 P := Associated_Node_For_Itype (Node_Id (F));
9594 while Present (P) loop
9596 Visit_Node (Node_Id (F));
9603 -- An Itype whose parent is not being copied definitely
9604 -- should NOT be copied, since it does not belong in any
9605 -- sense to the copied subtree.
9611 elsif F in List_Range
9612 and then Parent (List_Id (F)) = N
9614 Visit_List (List_Id (F));
9623 procedure Visit_Itype (Old_Itype : Entity_Id) is
9624 New_Itype : Entity_Id;
9629 -- Itypes that describe the designated type of access to subprograms
9630 -- have the structure of subprogram declarations, with signatures,
9631 -- etc. Either we duplicate the signatures completely, or choose to
9632 -- share such itypes, which is fine because their elaboration will
9633 -- have no side effects.
9635 if Ekind (Old_Itype) = E_Subprogram_Type then
9639 New_Itype := New_Copy (Old_Itype);
9641 -- The new Itype has all the attributes of the old one, and
9642 -- we just copy the contents of the entity. However, the back-end
9643 -- needs different names for debugging purposes, so we create a
9644 -- new internal name for it in all cases.
9646 Set_Chars (New_Itype, New_Internal_Name ('T'));
9648 -- If our associated node is an entity that has already been copied,
9649 -- then set the associated node of the copy to point to the right
9650 -- copy. If we have copied an Itype that is itself the associated
9651 -- node of some previously copied Itype, then we set the right
9652 -- pointer in the other direction.
9654 if Present (Actual_Map) then
9656 -- Case of hash tables used
9658 if NCT_Hash_Tables_Used then
9660 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9662 if Present (Ent) then
9663 Set_Associated_Node_For_Itype (New_Itype, Ent);
9666 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9667 if Present (Ent) then
9668 Set_Associated_Node_For_Itype (Ent, New_Itype);
9670 -- If the hash table has no association for this Itype and
9671 -- its associated node, enter one now.
9675 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9678 -- Case of hash tables not used
9681 E := First_Elmt (Actual_Map);
9682 while Present (E) loop
9683 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9684 Set_Associated_Node_For_Itype
9685 (New_Itype, Node (Next_Elmt (E)));
9688 if Is_Type (Node (E))
9690 Old_Itype = Associated_Node_For_Itype (Node (E))
9692 Set_Associated_Node_For_Itype
9693 (Node (Next_Elmt (E)), New_Itype);
9696 E := Next_Elmt (Next_Elmt (E));
9701 if Present (Freeze_Node (New_Itype)) then
9702 Set_Is_Frozen (New_Itype, False);
9703 Set_Freeze_Node (New_Itype, Empty);
9706 -- Add new association to map
9708 if No (Actual_Map) then
9709 Actual_Map := New_Elmt_List;
9712 Append_Elmt (Old_Itype, Actual_Map);
9713 Append_Elmt (New_Itype, Actual_Map);
9715 if NCT_Hash_Tables_Used then
9716 NCT_Assoc.Set (Old_Itype, New_Itype);
9719 NCT_Table_Entries := NCT_Table_Entries + 1;
9721 if NCT_Table_Entries > NCT_Hash_Threshold then
9722 Build_NCT_Hash_Tables;
9726 -- If a record subtype is simply copied, the entity list will be
9727 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9729 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9730 Set_Cloned_Subtype (New_Itype, Old_Itype);
9733 -- Visit descendents that eventually get copied
9735 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9737 if Is_Discrete_Type (Old_Itype) then
9738 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9740 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9741 -- ??? This should involve call to Visit_Field
9742 Visit_Elist (Discriminant_Constraint (Old_Itype));
9744 elsif Is_Array_Type (Old_Itype) then
9745 if Present (First_Index (Old_Itype)) then
9746 Visit_Field (Union_Id (List_Containing
9747 (First_Index (Old_Itype))),
9751 if Is_Packed (Old_Itype) then
9752 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9762 procedure Visit_List (L : List_Id) is
9765 if L /= No_List then
9768 while Present (N) loop
9779 procedure Visit_Node (N : Node_Or_Entity_Id) is
9781 -- Start of processing for Visit_Node
9784 -- Handle case of an Itype, which must be copied
9786 if Has_Extension (N)
9787 and then Is_Itype (N)
9789 -- Nothing to do if already in the list. This can happen with an
9790 -- Itype entity that appears more than once in the tree.
9791 -- Note that we do not want to visit descendents in this case.
9793 -- Test for already in list when hash table is used
9795 if NCT_Hash_Tables_Used then
9796 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9800 -- Test for already in list when hash table not used
9806 if Present (Actual_Map) then
9807 E := First_Elmt (Actual_Map);
9808 while Present (E) loop
9809 if Node (E) = N then
9812 E := Next_Elmt (Next_Elmt (E));
9822 -- Visit descendents
9824 Visit_Field (Field1 (N), N);
9825 Visit_Field (Field2 (N), N);
9826 Visit_Field (Field3 (N), N);
9827 Visit_Field (Field4 (N), N);
9828 Visit_Field (Field5 (N), N);
9831 -- Start of processing for New_Copy_Tree
9836 -- See if we should use hash table
9838 if No (Actual_Map) then
9839 NCT_Hash_Tables_Used := False;
9846 NCT_Table_Entries := 0;
9848 Elmt := First_Elmt (Actual_Map);
9849 while Present (Elmt) loop
9850 NCT_Table_Entries := NCT_Table_Entries + 1;
9855 if NCT_Table_Entries > NCT_Hash_Threshold then
9856 Build_NCT_Hash_Tables;
9858 NCT_Hash_Tables_Used := False;
9863 -- Hash table set up if required, now start phase one by visiting
9864 -- top node (we will recursively visit the descendents).
9866 Visit_Node (Source);
9868 -- Now the second phase of the copy can start. First we process
9869 -- all the mapped entities, copying their descendents.
9871 if Present (Actual_Map) then
9874 New_Itype : Entity_Id;
9876 Elmt := First_Elmt (Actual_Map);
9877 while Present (Elmt) loop
9879 New_Itype := Node (Elmt);
9880 Copy_Itype_With_Replacement (New_Itype);
9886 -- Now we can copy the actual tree
9888 return Copy_Node_With_Replacement (Source);
9891 -------------------------
9892 -- New_External_Entity --
9893 -------------------------
9895 function New_External_Entity
9896 (Kind : Entity_Kind;
9897 Scope_Id : Entity_Id;
9898 Sloc_Value : Source_Ptr;
9899 Related_Id : Entity_Id;
9901 Suffix_Index : Nat := 0;
9902 Prefix : Character := ' ') return Entity_Id
9904 N : constant Entity_Id :=
9905 Make_Defining_Identifier (Sloc_Value,
9907 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9910 Set_Ekind (N, Kind);
9911 Set_Is_Internal (N, True);
9912 Append_Entity (N, Scope_Id);
9913 Set_Public_Status (N);
9915 if Kind in Type_Kind then
9916 Init_Size_Align (N);
9920 end New_External_Entity;
9922 -------------------------
9923 -- New_Internal_Entity --
9924 -------------------------
9926 function New_Internal_Entity
9927 (Kind : Entity_Kind;
9928 Scope_Id : Entity_Id;
9929 Sloc_Value : Source_Ptr;
9930 Id_Char : Character) return Entity_Id
9932 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9935 Set_Ekind (N, Kind);
9936 Set_Is_Internal (N, True);
9937 Append_Entity (N, Scope_Id);
9939 if Kind in Type_Kind then
9940 Init_Size_Align (N);
9944 end New_Internal_Entity;
9950 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9954 -- If we are pointing at a positional parameter, it is a member of a
9955 -- node list (the list of parameters), and the next parameter is the
9956 -- next node on the list, unless we hit a parameter association, then
9957 -- we shift to using the chain whose head is the First_Named_Actual in
9958 -- the parent, and then is threaded using the Next_Named_Actual of the
9959 -- Parameter_Association. All this fiddling is because the original node
9960 -- list is in the textual call order, and what we need is the
9961 -- declaration order.
9963 if Is_List_Member (Actual_Id) then
9964 N := Next (Actual_Id);
9966 if Nkind (N) = N_Parameter_Association then
9967 return First_Named_Actual (Parent (Actual_Id));
9973 return Next_Named_Actual (Parent (Actual_Id));
9977 procedure Next_Actual (Actual_Id : in out Node_Id) is
9979 Actual_Id := Next_Actual (Actual_Id);
9982 -----------------------
9983 -- Normalize_Actuals --
9984 -----------------------
9986 -- Chain actuals according to formals of subprogram. If there are no named
9987 -- associations, the chain is simply the list of Parameter Associations,
9988 -- since the order is the same as the declaration order. If there are named
9989 -- associations, then the First_Named_Actual field in the N_Function_Call
9990 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9991 -- node for the parameter that comes first in declaration order. The
9992 -- remaining named parameters are then chained in declaration order using
9993 -- Next_Named_Actual.
9995 -- This routine also verifies that the number of actuals is compatible with
9996 -- the number and default values of formals, but performs no type checking
9997 -- (type checking is done by the caller).
9999 -- If the matching succeeds, Success is set to True and the caller proceeds
10000 -- with type-checking. If the match is unsuccessful, then Success is set to
10001 -- False, and the caller attempts a different interpretation, if there is
10004 -- If the flag Report is on, the call is not overloaded, and a failure to
10005 -- match can be reported here, rather than in the caller.
10007 procedure Normalize_Actuals
10011 Success : out Boolean)
10013 Actuals : constant List_Id := Parameter_Associations (N);
10014 Actual : Node_Id := Empty;
10015 Formal : Entity_Id;
10016 Last : Node_Id := Empty;
10017 First_Named : Node_Id := Empty;
10020 Formals_To_Match : Integer := 0;
10021 Actuals_To_Match : Integer := 0;
10023 procedure Chain (A : Node_Id);
10024 -- Add named actual at the proper place in the list, using the
10025 -- Next_Named_Actual link.
10027 function Reporting return Boolean;
10028 -- Determines if an error is to be reported. To report an error, we
10029 -- need Report to be True, and also we do not report errors caused
10030 -- by calls to init procs that occur within other init procs. Such
10031 -- errors must always be cascaded errors, since if all the types are
10032 -- declared correctly, the compiler will certainly build decent calls!
10038 procedure Chain (A : Node_Id) is
10042 -- Call node points to first actual in list
10044 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10047 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10051 Set_Next_Named_Actual (Last, Empty);
10058 function Reporting return Boolean is
10063 elsif not Within_Init_Proc then
10066 elsif Is_Init_Proc (Entity (Name (N))) then
10074 -- Start of processing for Normalize_Actuals
10077 if Is_Access_Type (S) then
10079 -- The name in the call is a function call that returns an access
10080 -- to subprogram. The designated type has the list of formals.
10082 Formal := First_Formal (Designated_Type (S));
10084 Formal := First_Formal (S);
10087 while Present (Formal) loop
10088 Formals_To_Match := Formals_To_Match + 1;
10089 Next_Formal (Formal);
10092 -- Find if there is a named association, and verify that no positional
10093 -- associations appear after named ones.
10095 if Present (Actuals) then
10096 Actual := First (Actuals);
10099 while Present (Actual)
10100 and then Nkind (Actual) /= N_Parameter_Association
10102 Actuals_To_Match := Actuals_To_Match + 1;
10106 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10108 -- Most common case: positional notation, no defaults
10113 elsif Actuals_To_Match > Formals_To_Match then
10115 -- Too many actuals: will not work
10118 if Is_Entity_Name (Name (N)) then
10119 Error_Msg_N ("too many arguments in call to&", Name (N));
10121 Error_Msg_N ("too many arguments in call", N);
10129 First_Named := Actual;
10131 while Present (Actual) loop
10132 if Nkind (Actual) /= N_Parameter_Association then
10134 ("positional parameters not allowed after named ones", Actual);
10139 Actuals_To_Match := Actuals_To_Match + 1;
10145 if Present (Actuals) then
10146 Actual := First (Actuals);
10149 Formal := First_Formal (S);
10150 while Present (Formal) loop
10152 -- Match the formals in order. If the corresponding actual is
10153 -- positional, nothing to do. Else scan the list of named actuals
10154 -- to find the one with the right name.
10156 if Present (Actual)
10157 and then Nkind (Actual) /= N_Parameter_Association
10160 Actuals_To_Match := Actuals_To_Match - 1;
10161 Formals_To_Match := Formals_To_Match - 1;
10164 -- For named parameters, search the list of actuals to find
10165 -- one that matches the next formal name.
10167 Actual := First_Named;
10169 while Present (Actual) loop
10170 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10173 Actuals_To_Match := Actuals_To_Match - 1;
10174 Formals_To_Match := Formals_To_Match - 1;
10182 if Ekind (Formal) /= E_In_Parameter
10183 or else No (Default_Value (Formal))
10186 if (Comes_From_Source (S)
10187 or else Sloc (S) = Standard_Location)
10188 and then Is_Overloadable (S)
10192 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10194 (Nkind (Parent (N)) = N_Function_Call
10196 Nkind (Parent (N)) = N_Parameter_Association))
10197 and then Ekind (S) /= E_Function
10199 Set_Etype (N, Etype (S));
10201 Error_Msg_Name_1 := Chars (S);
10202 Error_Msg_Sloc := Sloc (S);
10204 ("missing argument for parameter & " &
10205 "in call to % declared #", N, Formal);
10208 elsif Is_Overloadable (S) then
10209 Error_Msg_Name_1 := Chars (S);
10211 -- Point to type derivation that generated the
10214 Error_Msg_Sloc := Sloc (Parent (S));
10217 ("missing argument for parameter & " &
10218 "in call to % (inherited) #", N, Formal);
10222 ("missing argument for parameter &", N, Formal);
10230 Formals_To_Match := Formals_To_Match - 1;
10235 Next_Formal (Formal);
10238 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10245 -- Find some superfluous named actual that did not get
10246 -- attached to the list of associations.
10248 Actual := First (Actuals);
10249 while Present (Actual) loop
10250 if Nkind (Actual) = N_Parameter_Association
10251 and then Actual /= Last
10252 and then No (Next_Named_Actual (Actual))
10254 Error_Msg_N ("unmatched actual & in call",
10255 Selector_Name (Actual));
10266 end Normalize_Actuals;
10268 --------------------------------
10269 -- Note_Possible_Modification --
10270 --------------------------------
10272 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10273 Modification_Comes_From_Source : constant Boolean :=
10274 Comes_From_Source (Parent (N));
10280 -- Loop to find referenced entity, if there is one
10287 if Is_Entity_Name (Exp) then
10288 Ent := Entity (Exp);
10290 -- If the entity is missing, it is an undeclared identifier,
10291 -- and there is nothing to annotate.
10297 elsif Nkind (Exp) = N_Explicit_Dereference then
10299 P : constant Node_Id := Prefix (Exp);
10302 if Nkind (P) = N_Selected_Component
10304 Entry_Formal (Entity (Selector_Name (P))))
10306 -- Case of a reference to an entry formal
10308 Ent := Entry_Formal (Entity (Selector_Name (P)));
10310 elsif Nkind (P) = N_Identifier
10311 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10312 and then Present (Expression (Parent (Entity (P))))
10313 and then Nkind (Expression (Parent (Entity (P))))
10316 -- Case of a reference to a value on which side effects have
10319 Exp := Prefix (Expression (Parent (Entity (P))));
10328 elsif Nkind (Exp) = N_Type_Conversion
10329 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10331 Exp := Expression (Exp);
10334 elsif Nkind (Exp) = N_Slice
10335 or else Nkind (Exp) = N_Indexed_Component
10336 or else Nkind (Exp) = N_Selected_Component
10338 Exp := Prefix (Exp);
10345 -- Now look for entity being referenced
10347 if Present (Ent) then
10348 if Is_Object (Ent) then
10349 if Comes_From_Source (Exp)
10350 or else Modification_Comes_From_Source
10352 -- Give warning if pragma unmodified given and we are
10353 -- sure this is a modification.
10355 if Has_Pragma_Unmodified (Ent) and then Sure then
10356 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10359 Set_Never_Set_In_Source (Ent, False);
10362 Set_Is_True_Constant (Ent, False);
10363 Set_Current_Value (Ent, Empty);
10364 Set_Is_Known_Null (Ent, False);
10366 if not Can_Never_Be_Null (Ent) then
10367 Set_Is_Known_Non_Null (Ent, False);
10370 -- Follow renaming chain
10372 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10373 and then Present (Renamed_Object (Ent))
10375 Exp := Renamed_Object (Ent);
10379 -- Generate a reference only if the assignment comes from
10380 -- source. This excludes, for example, calls to a dispatching
10381 -- assignment operation when the left-hand side is tagged.
10383 if Modification_Comes_From_Source then
10384 Generate_Reference (Ent, Exp, 'm');
10386 -- If the target of the assignment is the bound variable
10387 -- in an iterator, indicate that the corresponding array
10388 -- or container is also modified.
10390 if Ada_Version >= Ada_2012
10392 Nkind (Parent (Ent)) = N_Iterator_Specification
10395 Domain : constant Node_Id := Name (Parent (Ent));
10398 -- TBD : in the full version of the construct, the
10399 -- domain of iteration can be given by an expression.
10401 if Is_Entity_Name (Domain) then
10402 Generate_Reference (Entity (Domain), Exp, 'm');
10403 Set_Is_True_Constant (Entity (Domain), False);
10404 Set_Never_Set_In_Source (Entity (Domain), False);
10410 Check_Nested_Access (Ent);
10415 -- If we are sure this is a modification from source, and we know
10416 -- this modifies a constant, then give an appropriate warning.
10418 if Overlays_Constant (Ent)
10419 and then Modification_Comes_From_Source
10423 A : constant Node_Id := Address_Clause (Ent);
10425 if Present (A) then
10427 Exp : constant Node_Id := Expression (A);
10429 if Nkind (Exp) = N_Attribute_Reference
10430 and then Attribute_Name (Exp) = Name_Address
10431 and then Is_Entity_Name (Prefix (Exp))
10433 Error_Msg_Sloc := Sloc (A);
10435 ("constant& may be modified via address clause#?",
10436 N, Entity (Prefix (Exp)));
10446 end Note_Possible_Modification;
10448 -------------------------
10449 -- Object_Access_Level --
10450 -------------------------
10452 function Object_Access_Level (Obj : Node_Id) return Uint is
10455 -- Returns the static accessibility level of the view denoted by Obj. Note
10456 -- that the value returned is the result of a call to Scope_Depth. Only
10457 -- scope depths associated with dynamic scopes can actually be returned.
10458 -- Since only relative levels matter for accessibility checking, the fact
10459 -- that the distance between successive levels of accessibility is not
10460 -- always one is immaterial (invariant: if level(E2) is deeper than
10461 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10463 function Reference_To (Obj : Node_Id) return Node_Id;
10464 -- An explicit dereference is created when removing side-effects from
10465 -- expressions for constraint checking purposes. In this case a local
10466 -- access type is created for it. The correct access level is that of
10467 -- the original source node. We detect this case by noting that the
10468 -- prefix of the dereference is created by an object declaration whose
10469 -- initial expression is a reference.
10475 function Reference_To (Obj : Node_Id) return Node_Id is
10476 Pref : constant Node_Id := Prefix (Obj);
10478 if Is_Entity_Name (Pref)
10479 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10480 and then Present (Expression (Parent (Entity (Pref))))
10481 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10483 return (Prefix (Expression (Parent (Entity (Pref)))));
10489 -- Start of processing for Object_Access_Level
10492 if Is_Entity_Name (Obj) then
10495 if Is_Prival (E) then
10496 E := Prival_Link (E);
10499 -- If E is a type then it denotes a current instance. For this case
10500 -- we add one to the normal accessibility level of the type to ensure
10501 -- that current instances are treated as always being deeper than
10502 -- than the level of any visible named access type (see 3.10.2(21)).
10504 if Is_Type (E) then
10505 return Type_Access_Level (E) + 1;
10507 elsif Present (Renamed_Object (E)) then
10508 return Object_Access_Level (Renamed_Object (E));
10510 -- Similarly, if E is a component of the current instance of a
10511 -- protected type, any instance of it is assumed to be at a deeper
10512 -- level than the type. For a protected object (whose type is an
10513 -- anonymous protected type) its components are at the same level
10514 -- as the type itself.
10516 elsif not Is_Overloadable (E)
10517 and then Ekind (Scope (E)) = E_Protected_Type
10518 and then Comes_From_Source (Scope (E))
10520 return Type_Access_Level (Scope (E)) + 1;
10523 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10526 elsif Nkind (Obj) = N_Selected_Component then
10527 if Is_Access_Type (Etype (Prefix (Obj))) then
10528 return Type_Access_Level (Etype (Prefix (Obj)));
10530 return Object_Access_Level (Prefix (Obj));
10533 elsif Nkind (Obj) = N_Indexed_Component then
10534 if Is_Access_Type (Etype (Prefix (Obj))) then
10535 return Type_Access_Level (Etype (Prefix (Obj)));
10537 return Object_Access_Level (Prefix (Obj));
10540 elsif Nkind (Obj) = N_Explicit_Dereference then
10542 -- If the prefix is a selected access discriminant then we make a
10543 -- recursive call on the prefix, which will in turn check the level
10544 -- of the prefix object of the selected discriminant.
10546 if Nkind (Prefix (Obj)) = N_Selected_Component
10547 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10549 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10551 return Object_Access_Level (Prefix (Obj));
10553 elsif not (Comes_From_Source (Obj)) then
10555 Ref : constant Node_Id := Reference_To (Obj);
10557 if Present (Ref) then
10558 return Object_Access_Level (Ref);
10560 return Type_Access_Level (Etype (Prefix (Obj)));
10565 return Type_Access_Level (Etype (Prefix (Obj)));
10568 elsif Nkind (Obj) = N_Type_Conversion
10569 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10571 return Object_Access_Level (Expression (Obj));
10573 elsif Nkind (Obj) = N_Function_Call then
10575 -- Function results are objects, so we get either the access level of
10576 -- the function or, in the case of an indirect call, the level of the
10577 -- access-to-subprogram type. (This code is used for Ada 95, but it
10578 -- looks wrong, because it seems that we should be checking the level
10579 -- of the call itself, even for Ada 95. However, using the Ada 2005
10580 -- version of the code causes regressions in several tests that are
10581 -- compiled with -gnat95. ???)
10583 if Ada_Version < Ada_2005 then
10584 if Is_Entity_Name (Name (Obj)) then
10585 return Subprogram_Access_Level (Entity (Name (Obj)));
10587 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10590 -- For Ada 2005, the level of the result object of a function call is
10591 -- defined to be the level of the call's innermost enclosing master.
10592 -- We determine that by querying the depth of the innermost enclosing
10596 Return_Master_Scope_Depth_Of_Call : declare
10598 function Innermost_Master_Scope_Depth
10599 (N : Node_Id) return Uint;
10600 -- Returns the scope depth of the given node's innermost
10601 -- enclosing dynamic scope (effectively the accessibility
10602 -- level of the innermost enclosing master).
10604 ----------------------------------
10605 -- Innermost_Master_Scope_Depth --
10606 ----------------------------------
10608 function Innermost_Master_Scope_Depth
10609 (N : Node_Id) return Uint
10611 Node_Par : Node_Id := Parent (N);
10614 -- Locate the nearest enclosing node (by traversing Parents)
10615 -- that Defining_Entity can be applied to, and return the
10616 -- depth of that entity's nearest enclosing dynamic scope.
10618 while Present (Node_Par) loop
10619 case Nkind (Node_Par) is
10620 when N_Component_Declaration |
10621 N_Entry_Declaration |
10622 N_Formal_Object_Declaration |
10623 N_Formal_Type_Declaration |
10624 N_Full_Type_Declaration |
10625 N_Incomplete_Type_Declaration |
10626 N_Loop_Parameter_Specification |
10627 N_Object_Declaration |
10628 N_Protected_Type_Declaration |
10629 N_Private_Extension_Declaration |
10630 N_Private_Type_Declaration |
10631 N_Subtype_Declaration |
10632 N_Function_Specification |
10633 N_Procedure_Specification |
10634 N_Task_Type_Declaration |
10636 N_Generic_Instantiation |
10638 N_Implicit_Label_Declaration |
10639 N_Package_Declaration |
10640 N_Single_Task_Declaration |
10641 N_Subprogram_Declaration |
10642 N_Generic_Declaration |
10643 N_Renaming_Declaration |
10644 N_Block_Statement |
10645 N_Formal_Subprogram_Declaration |
10646 N_Abstract_Subprogram_Declaration |
10648 N_Exception_Declaration |
10649 N_Formal_Package_Declaration |
10650 N_Number_Declaration |
10651 N_Package_Specification |
10652 N_Parameter_Specification |
10653 N_Single_Protected_Declaration |
10657 (Nearest_Dynamic_Scope
10658 (Defining_Entity (Node_Par)));
10664 Node_Par := Parent (Node_Par);
10667 pragma Assert (False);
10669 -- Should never reach the following return
10671 return Scope_Depth (Current_Scope) + 1;
10672 end Innermost_Master_Scope_Depth;
10674 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10677 return Innermost_Master_Scope_Depth (Obj);
10678 end Return_Master_Scope_Depth_Of_Call;
10681 -- For convenience we handle qualified expressions, even though
10682 -- they aren't technically object names.
10684 elsif Nkind (Obj) = N_Qualified_Expression then
10685 return Object_Access_Level (Expression (Obj));
10687 -- Otherwise return the scope level of Standard.
10688 -- (If there are cases that fall through
10689 -- to this point they will be treated as
10690 -- having global accessibility for now. ???)
10693 return Scope_Depth (Standard_Standard);
10695 end Object_Access_Level;
10697 --------------------------------------
10698 -- Original_Corresponding_Operation --
10699 --------------------------------------
10701 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10703 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10706 -- If S is an inherited primitive S2 the original corresponding
10707 -- operation of S is the original corresponding operation of S2
10709 if Present (Alias (S))
10710 and then Find_Dispatching_Type (Alias (S)) /= Typ
10712 return Original_Corresponding_Operation (Alias (S));
10714 -- If S overrides an inherited subprogram S2 the original corresponding
10715 -- operation of S is the original corresponding operation of S2
10717 elsif Present (Overridden_Operation (S)) then
10718 return Original_Corresponding_Operation (Overridden_Operation (S));
10720 -- otherwise it is S itself
10725 end Original_Corresponding_Operation;
10727 -----------------------
10728 -- Private_Component --
10729 -----------------------
10731 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10732 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10734 function Trace_Components
10736 Check : Boolean) return Entity_Id;
10737 -- Recursive function that does the work, and checks against circular
10738 -- definition for each subcomponent type.
10740 ----------------------
10741 -- Trace_Components --
10742 ----------------------
10744 function Trace_Components
10746 Check : Boolean) return Entity_Id
10748 Btype : constant Entity_Id := Base_Type (T);
10749 Component : Entity_Id;
10751 Candidate : Entity_Id := Empty;
10754 if Check and then Btype = Ancestor then
10755 Error_Msg_N ("circular type definition", Type_Id);
10759 if Is_Private_Type (Btype)
10760 and then not Is_Generic_Type (Btype)
10762 if Present (Full_View (Btype))
10763 and then Is_Record_Type (Full_View (Btype))
10764 and then not Is_Frozen (Btype)
10766 -- To indicate that the ancestor depends on a private type, the
10767 -- current Btype is sufficient. However, to check for circular
10768 -- definition we must recurse on the full view.
10770 Candidate := Trace_Components (Full_View (Btype), True);
10772 if Candidate = Any_Type then
10782 elsif Is_Array_Type (Btype) then
10783 return Trace_Components (Component_Type (Btype), True);
10785 elsif Is_Record_Type (Btype) then
10786 Component := First_Entity (Btype);
10787 while Present (Component) loop
10789 -- Skip anonymous types generated by constrained components
10791 if not Is_Type (Component) then
10792 P := Trace_Components (Etype (Component), True);
10794 if Present (P) then
10795 if P = Any_Type then
10803 Next_Entity (Component);
10811 end Trace_Components;
10813 -- Start of processing for Private_Component
10816 return Trace_Components (Type_Id, False);
10817 end Private_Component;
10819 ---------------------------
10820 -- Primitive_Names_Match --
10821 ---------------------------
10823 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10825 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10826 -- Given an internal name, returns the corresponding non-internal name
10828 ------------------------
10829 -- Non_Internal_Name --
10830 ------------------------
10832 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10834 Get_Name_String (Chars (E));
10835 Name_Len := Name_Len - 1;
10837 end Non_Internal_Name;
10839 -- Start of processing for Primitive_Names_Match
10842 pragma Assert (Present (E1) and then Present (E2));
10844 return Chars (E1) = Chars (E2)
10846 (not Is_Internal_Name (Chars (E1))
10847 and then Is_Internal_Name (Chars (E2))
10848 and then Non_Internal_Name (E2) = Chars (E1))
10850 (not Is_Internal_Name (Chars (E2))
10851 and then Is_Internal_Name (Chars (E1))
10852 and then Non_Internal_Name (E1) = Chars (E2))
10854 (Is_Predefined_Dispatching_Operation (E1)
10855 and then Is_Predefined_Dispatching_Operation (E2)
10856 and then Same_TSS (E1, E2))
10858 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10859 end Primitive_Names_Match;
10861 -----------------------
10862 -- Process_End_Label --
10863 -----------------------
10865 procedure Process_End_Label
10874 Label_Ref : Boolean;
10875 -- Set True if reference to end label itself is required
10878 -- Gets set to the operator symbol or identifier that references the
10879 -- entity Ent. For the child unit case, this is the identifier from the
10880 -- designator. For other cases, this is simply Endl.
10882 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10883 -- N is an identifier node that appears as a parent unit reference in
10884 -- the case where Ent is a child unit. This procedure generates an
10885 -- appropriate cross-reference entry. E is the corresponding entity.
10887 -------------------------
10888 -- Generate_Parent_Ref --
10889 -------------------------
10891 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10893 -- If names do not match, something weird, skip reference
10895 if Chars (E) = Chars (N) then
10897 -- Generate the reference. We do NOT consider this as a reference
10898 -- for unreferenced symbol purposes.
10900 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10902 if Style_Check then
10903 Style.Check_Identifier (N, E);
10906 end Generate_Parent_Ref;
10908 -- Start of processing for Process_End_Label
10911 -- If no node, ignore. This happens in some error situations, and
10912 -- also for some internally generated structures where no end label
10913 -- references are required in any case.
10919 -- Nothing to do if no End_Label, happens for internally generated
10920 -- constructs where we don't want an end label reference anyway. Also
10921 -- nothing to do if Endl is a string literal, which means there was
10922 -- some prior error (bad operator symbol)
10924 Endl := End_Label (N);
10926 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10930 -- Reference node is not in extended main source unit
10932 if not In_Extended_Main_Source_Unit (N) then
10934 -- Generally we do not collect references except for the extended
10935 -- main source unit. The one exception is the 'e' entry for a
10936 -- package spec, where it is useful for a client to have the
10937 -- ending information to define scopes.
10943 Label_Ref := False;
10945 -- For this case, we can ignore any parent references, but we
10946 -- need the package name itself for the 'e' entry.
10948 if Nkind (Endl) = N_Designator then
10949 Endl := Identifier (Endl);
10953 -- Reference is in extended main source unit
10958 -- For designator, generate references for the parent entries
10960 if Nkind (Endl) = N_Designator then
10962 -- Generate references for the prefix if the END line comes from
10963 -- source (otherwise we do not need these references) We climb the
10964 -- scope stack to find the expected entities.
10966 if Comes_From_Source (Endl) then
10967 Nam := Name (Endl);
10968 Scop := Current_Scope;
10969 while Nkind (Nam) = N_Selected_Component loop
10970 Scop := Scope (Scop);
10971 exit when No (Scop);
10972 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10973 Nam := Prefix (Nam);
10976 if Present (Scop) then
10977 Generate_Parent_Ref (Nam, Scope (Scop));
10981 Endl := Identifier (Endl);
10985 -- If the end label is not for the given entity, then either we have
10986 -- some previous error, or this is a generic instantiation for which
10987 -- we do not need to make a cross-reference in this case anyway. In
10988 -- either case we simply ignore the call.
10990 if Chars (Ent) /= Chars (Endl) then
10994 -- If label was really there, then generate a normal reference and then
10995 -- adjust the location in the end label to point past the name (which
10996 -- should almost always be the semicolon).
10998 Loc := Sloc (Endl);
11000 if Comes_From_Source (Endl) then
11002 -- If a label reference is required, then do the style check and
11003 -- generate an l-type cross-reference entry for the label
11006 if Style_Check then
11007 Style.Check_Identifier (Endl, Ent);
11010 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
11013 -- Set the location to point past the label (normally this will
11014 -- mean the semicolon immediately following the label). This is
11015 -- done for the sake of the 'e' or 't' entry generated below.
11017 Get_Decoded_Name_String (Chars (Endl));
11018 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11021 -- In SPARK mode, no missing label is allowed for packages and
11022 -- subprogram bodies. Detect those cases by testing whether
11023 -- Process_End_Label was called for a body (Typ = 't') or a package.
11025 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
11026 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11028 Error_Msg_Node_1 := Endl;
11029 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11033 -- Now generate the e/t reference
11035 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11037 -- Restore Sloc, in case modified above, since we have an identifier
11038 -- and the normal Sloc should be left set in the tree.
11040 Set_Sloc (Endl, Loc);
11041 end Process_End_Label;
11043 ------------------------------------
11044 -- References_Generic_Formal_Type --
11045 ------------------------------------
11047 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11049 function Process (N : Node_Id) return Traverse_Result;
11050 -- Process one node in search for generic formal type
11056 function Process (N : Node_Id) return Traverse_Result is
11058 if Nkind (N) in N_Has_Entity then
11060 E : constant Entity_Id := Entity (N);
11062 if Present (E) then
11063 if Is_Generic_Type (E) then
11065 elsif Present (Etype (E))
11066 and then Is_Generic_Type (Etype (E))
11077 function Traverse is new Traverse_Func (Process);
11078 -- Traverse tree to look for generic type
11081 if Inside_A_Generic then
11082 return Traverse (N) = Abandon;
11086 end References_Generic_Formal_Type;
11088 --------------------
11089 -- Remove_Homonym --
11090 --------------------
11092 procedure Remove_Homonym (E : Entity_Id) is
11093 Prev : Entity_Id := Empty;
11097 if E = Current_Entity (E) then
11098 if Present (Homonym (E)) then
11099 Set_Current_Entity (Homonym (E));
11101 Set_Name_Entity_Id (Chars (E), Empty);
11104 H := Current_Entity (E);
11105 while Present (H) and then H /= E loop
11110 Set_Homonym (Prev, Homonym (E));
11112 end Remove_Homonym;
11114 ---------------------
11115 -- Rep_To_Pos_Flag --
11116 ---------------------
11118 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11120 return New_Occurrence_Of
11121 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11122 end Rep_To_Pos_Flag;
11124 --------------------
11125 -- Require_Entity --
11126 --------------------
11128 procedure Require_Entity (N : Node_Id) is
11130 if Is_Entity_Name (N) and then No (Entity (N)) then
11131 if Total_Errors_Detected /= 0 then
11132 Set_Entity (N, Any_Id);
11134 raise Program_Error;
11137 end Require_Entity;
11139 ------------------------------
11140 -- Requires_Transient_Scope --
11141 ------------------------------
11143 -- A transient scope is required when variable-sized temporaries are
11144 -- allocated in the primary or secondary stack, or when finalization
11145 -- actions must be generated before the next instruction.
11147 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11148 Typ : constant Entity_Id := Underlying_Type (Id);
11150 -- Start of processing for Requires_Transient_Scope
11153 -- This is a private type which is not completed yet. This can only
11154 -- happen in a default expression (of a formal parameter or of a
11155 -- record component). Do not expand transient scope in this case
11160 -- Do not expand transient scope for non-existent procedure return
11162 elsif Typ = Standard_Void_Type then
11165 -- Elementary types do not require a transient scope
11167 elsif Is_Elementary_Type (Typ) then
11170 -- Generally, indefinite subtypes require a transient scope, since the
11171 -- back end cannot generate temporaries, since this is not a valid type
11172 -- for declaring an object. It might be possible to relax this in the
11173 -- future, e.g. by declaring the maximum possible space for the type.
11175 elsif Is_Indefinite_Subtype (Typ) then
11178 -- Functions returning tagged types may dispatch on result so their
11179 -- returned value is allocated on the secondary stack. Controlled
11180 -- type temporaries need finalization.
11182 elsif Is_Tagged_Type (Typ)
11183 or else Has_Controlled_Component (Typ)
11185 return not Is_Value_Type (Typ);
11189 elsif Is_Record_Type (Typ) then
11193 Comp := First_Entity (Typ);
11194 while Present (Comp) loop
11195 if Ekind (Comp) = E_Component
11196 and then Requires_Transient_Scope (Etype (Comp))
11200 Next_Entity (Comp);
11207 -- String literal types never require transient scope
11209 elsif Ekind (Typ) = E_String_Literal_Subtype then
11212 -- Array type. Note that we already know that this is a constrained
11213 -- array, since unconstrained arrays will fail the indefinite test.
11215 elsif Is_Array_Type (Typ) then
11217 -- If component type requires a transient scope, the array does too
11219 if Requires_Transient_Scope (Component_Type (Typ)) then
11222 -- Otherwise, we only need a transient scope if the size depends on
11223 -- the value of one or more discriminants.
11226 return Size_Depends_On_Discriminant (Typ);
11229 -- All other cases do not require a transient scope
11234 end Requires_Transient_Scope;
11236 --------------------------
11237 -- Reset_Analyzed_Flags --
11238 --------------------------
11240 procedure Reset_Analyzed_Flags (N : Node_Id) is
11242 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11243 -- Function used to reset Analyzed flags in tree. Note that we do
11244 -- not reset Analyzed flags in entities, since there is no need to
11245 -- reanalyze entities, and indeed, it is wrong to do so, since it
11246 -- can result in generating auxiliary stuff more than once.
11248 --------------------
11249 -- Clear_Analyzed --
11250 --------------------
11252 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11254 if not Has_Extension (N) then
11255 Set_Analyzed (N, False);
11259 end Clear_Analyzed;
11261 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11263 -- Start of processing for Reset_Analyzed_Flags
11266 Reset_Analyzed (N);
11267 end Reset_Analyzed_Flags;
11269 ---------------------------
11270 -- Safe_To_Capture_Value --
11271 ---------------------------
11273 function Safe_To_Capture_Value
11276 Cond : Boolean := False) return Boolean
11279 -- The only entities for which we track constant values are variables
11280 -- which are not renamings, constants, out parameters, and in out
11281 -- parameters, so check if we have this case.
11283 -- Note: it may seem odd to track constant values for constants, but in
11284 -- fact this routine is used for other purposes than simply capturing
11285 -- the value. In particular, the setting of Known[_Non]_Null.
11287 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11289 Ekind (Ent) = E_Constant
11291 Ekind (Ent) = E_Out_Parameter
11293 Ekind (Ent) = E_In_Out_Parameter
11297 -- For conditionals, we also allow loop parameters and all formals,
11298 -- including in parameters.
11302 (Ekind (Ent) = E_Loop_Parameter
11304 Ekind (Ent) = E_In_Parameter)
11308 -- For all other cases, not just unsafe, but impossible to capture
11309 -- Current_Value, since the above are the only entities which have
11310 -- Current_Value fields.
11316 -- Skip if volatile or aliased, since funny things might be going on in
11317 -- these cases which we cannot necessarily track. Also skip any variable
11318 -- for which an address clause is given, or whose address is taken. Also
11319 -- never capture value of library level variables (an attempt to do so
11320 -- can occur in the case of package elaboration code).
11322 if Treat_As_Volatile (Ent)
11323 or else Is_Aliased (Ent)
11324 or else Present (Address_Clause (Ent))
11325 or else Address_Taken (Ent)
11326 or else (Is_Library_Level_Entity (Ent)
11327 and then Ekind (Ent) = E_Variable)
11332 -- OK, all above conditions are met. We also require that the scope of
11333 -- the reference be the same as the scope of the entity, not counting
11334 -- packages and blocks and loops.
11337 E_Scope : constant Entity_Id := Scope (Ent);
11338 R_Scope : Entity_Id;
11341 R_Scope := Current_Scope;
11342 while R_Scope /= Standard_Standard loop
11343 exit when R_Scope = E_Scope;
11345 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11348 R_Scope := Scope (R_Scope);
11353 -- We also require that the reference does not appear in a context
11354 -- where it is not sure to be executed (i.e. a conditional context
11355 -- or an exception handler). We skip this if Cond is True, since the
11356 -- capturing of values from conditional tests handles this ok.
11370 while Present (P) loop
11371 if Nkind (P) = N_If_Statement
11372 or else Nkind (P) = N_Case_Statement
11373 or else (Nkind (P) in N_Short_Circuit
11374 and then Desc = Right_Opnd (P))
11375 or else (Nkind (P) = N_Conditional_Expression
11376 and then Desc /= First (Expressions (P)))
11377 or else Nkind (P) = N_Exception_Handler
11378 or else Nkind (P) = N_Selective_Accept
11379 or else Nkind (P) = N_Conditional_Entry_Call
11380 or else Nkind (P) = N_Timed_Entry_Call
11381 or else Nkind (P) = N_Asynchronous_Select
11391 -- OK, looks safe to set value
11394 end Safe_To_Capture_Value;
11400 function Same_Name (N1, N2 : Node_Id) return Boolean is
11401 K1 : constant Node_Kind := Nkind (N1);
11402 K2 : constant Node_Kind := Nkind (N2);
11405 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11406 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11408 return Chars (N1) = Chars (N2);
11410 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11411 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11413 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11414 and then Same_Name (Prefix (N1), Prefix (N2));
11425 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11426 N1 : constant Node_Id := Original_Node (Node1);
11427 N2 : constant Node_Id := Original_Node (Node2);
11428 -- We do the tests on original nodes, since we are most interested
11429 -- in the original source, not any expansion that got in the way.
11431 K1 : constant Node_Kind := Nkind (N1);
11432 K2 : constant Node_Kind := Nkind (N2);
11435 -- First case, both are entities with same entity
11437 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11439 EN1 : constant Entity_Id := Entity (N1);
11440 EN2 : constant Entity_Id := Entity (N2);
11442 if Present (EN1) and then Present (EN2)
11443 and then (Ekind_In (EN1, E_Variable, E_Constant)
11444 or else Is_Formal (EN1))
11452 -- Second case, selected component with same selector, same record
11454 if K1 = N_Selected_Component
11455 and then K2 = N_Selected_Component
11456 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11458 return Same_Object (Prefix (N1), Prefix (N2));
11460 -- Third case, indexed component with same subscripts, same array
11462 elsif K1 = N_Indexed_Component
11463 and then K2 = N_Indexed_Component
11464 and then Same_Object (Prefix (N1), Prefix (N2))
11469 E1 := First (Expressions (N1));
11470 E2 := First (Expressions (N2));
11471 while Present (E1) loop
11472 if not Same_Value (E1, E2) then
11483 -- Fourth case, slice of same array with same bounds
11486 and then K2 = N_Slice
11487 and then Nkind (Discrete_Range (N1)) = N_Range
11488 and then Nkind (Discrete_Range (N2)) = N_Range
11489 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11490 Low_Bound (Discrete_Range (N2)))
11491 and then Same_Value (High_Bound (Discrete_Range (N1)),
11492 High_Bound (Discrete_Range (N2)))
11494 return Same_Name (Prefix (N1), Prefix (N2));
11496 -- All other cases, not clearly the same object
11507 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11512 elsif not Is_Constrained (T1)
11513 and then not Is_Constrained (T2)
11514 and then Base_Type (T1) = Base_Type (T2)
11518 -- For now don't bother with case of identical constraints, to be
11519 -- fiddled with later on perhaps (this is only used for optimization
11520 -- purposes, so it is not critical to do a best possible job)
11531 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11533 if Compile_Time_Known_Value (Node1)
11534 and then Compile_Time_Known_Value (Node2)
11535 and then Expr_Value (Node1) = Expr_Value (Node2)
11538 elsif Same_Object (Node1, Node2) then
11549 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11551 if Ada_Version < Ada_2012 then
11554 elsif Is_Entity_Name (N)
11556 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11558 (Nkind (N) = N_Attribute_Reference
11559 and then Attribute_Name (N) = Name_Access)
11562 -- We are only interested in IN OUT parameters of inner calls
11565 or else Nkind (Parent (N)) = N_Function_Call
11566 or else Nkind (Parent (N)) in N_Op
11568 Actuals_In_Call.Increment_Last;
11569 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11574 ------------------------
11575 -- Scope_Is_Transient --
11576 ------------------------
11578 function Scope_Is_Transient return Boolean is
11580 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11581 end Scope_Is_Transient;
11587 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11592 while Scop /= Standard_Standard loop
11593 Scop := Scope (Scop);
11595 if Scop = Scope2 then
11603 --------------------------
11604 -- Scope_Within_Or_Same --
11605 --------------------------
11607 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11612 while Scop /= Standard_Standard loop
11613 if Scop = Scope2 then
11616 Scop := Scope (Scop);
11621 end Scope_Within_Or_Same;
11623 --------------------
11624 -- Set_Convention --
11625 --------------------
11627 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11629 Basic_Set_Convention (E, Val);
11632 and then Is_Access_Subprogram_Type (Base_Type (E))
11633 and then Has_Foreign_Convention (E)
11635 Set_Can_Use_Internal_Rep (E, False);
11637 end Set_Convention;
11639 ------------------------
11640 -- Set_Current_Entity --
11641 ------------------------
11643 -- The given entity is to be set as the currently visible definition
11644 -- of its associated name (i.e. the Node_Id associated with its name).
11645 -- All we have to do is to get the name from the identifier, and
11646 -- then set the associated Node_Id to point to the given entity.
11648 procedure Set_Current_Entity (E : Entity_Id) is
11650 Set_Name_Entity_Id (Chars (E), E);
11651 end Set_Current_Entity;
11653 ---------------------------
11654 -- Set_Debug_Info_Needed --
11655 ---------------------------
11657 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11659 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11660 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11661 -- Used to set debug info in a related node if not set already
11663 --------------------------------------
11664 -- Set_Debug_Info_Needed_If_Not_Set --
11665 --------------------------------------
11667 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11670 and then not Needs_Debug_Info (E)
11672 Set_Debug_Info_Needed (E);
11674 -- For a private type, indicate that the full view also needs
11675 -- debug information.
11678 and then Is_Private_Type (E)
11679 and then Present (Full_View (E))
11681 Set_Debug_Info_Needed (Full_View (E));
11684 end Set_Debug_Info_Needed_If_Not_Set;
11686 -- Start of processing for Set_Debug_Info_Needed
11689 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11690 -- indicates that Debug_Info_Needed is never required for the entity.
11693 or else Debug_Info_Off (T)
11698 -- Set flag in entity itself. Note that we will go through the following
11699 -- circuitry even if the flag is already set on T. That's intentional,
11700 -- it makes sure that the flag will be set in subsidiary entities.
11702 Set_Needs_Debug_Info (T);
11704 -- Set flag on subsidiary entities if not set already
11706 if Is_Object (T) then
11707 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11709 elsif Is_Type (T) then
11710 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11712 if Is_Record_Type (T) then
11714 Ent : Entity_Id := First_Entity (T);
11716 while Present (Ent) loop
11717 Set_Debug_Info_Needed_If_Not_Set (Ent);
11722 -- For a class wide subtype, we also need debug information
11723 -- for the equivalent type.
11725 if Ekind (T) = E_Class_Wide_Subtype then
11726 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11729 elsif Is_Array_Type (T) then
11730 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11733 Indx : Node_Id := First_Index (T);
11735 while Present (Indx) loop
11736 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11737 Indx := Next_Index (Indx);
11741 if Is_Packed (T) then
11742 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11745 elsif Is_Access_Type (T) then
11746 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11748 elsif Is_Private_Type (T) then
11749 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11751 elsif Is_Protected_Type (T) then
11752 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11755 end Set_Debug_Info_Needed;
11757 ---------------------------------
11758 -- Set_Entity_With_Style_Check --
11759 ---------------------------------
11761 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11762 Val_Actual : Entity_Id;
11766 Set_Entity (N, Val);
11769 and then not Suppress_Style_Checks (Val)
11770 and then not In_Instance
11772 if Nkind (N) = N_Identifier then
11774 elsif Nkind (N) = N_Expanded_Name then
11775 Nod := Selector_Name (N);
11780 -- A special situation arises for derived operations, where we want
11781 -- to do the check against the parent (since the Sloc of the derived
11782 -- operation points to the derived type declaration itself).
11785 while not Comes_From_Source (Val_Actual)
11786 and then Nkind (Val_Actual) in N_Entity
11787 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11788 or else Is_Subprogram (Val_Actual)
11789 or else Is_Generic_Subprogram (Val_Actual))
11790 and then Present (Alias (Val_Actual))
11792 Val_Actual := Alias (Val_Actual);
11795 -- Renaming declarations for generic actuals do not come from source,
11796 -- and have a different name from that of the entity they rename, so
11797 -- there is no style check to perform here.
11799 if Chars (Nod) = Chars (Val_Actual) then
11800 Style.Check_Identifier (Nod, Val_Actual);
11804 Set_Entity (N, Val);
11805 end Set_Entity_With_Style_Check;
11807 ------------------------
11808 -- Set_Name_Entity_Id --
11809 ------------------------
11811 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11813 Set_Name_Table_Info (Id, Int (Val));
11814 end Set_Name_Entity_Id;
11816 ---------------------
11817 -- Set_Next_Actual --
11818 ---------------------
11820 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11822 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11823 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11825 end Set_Next_Actual;
11827 ----------------------------------
11828 -- Set_Optimize_Alignment_Flags --
11829 ----------------------------------
11831 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11833 if Optimize_Alignment = 'S' then
11834 Set_Optimize_Alignment_Space (E);
11835 elsif Optimize_Alignment = 'T' then
11836 Set_Optimize_Alignment_Time (E);
11838 end Set_Optimize_Alignment_Flags;
11840 -----------------------
11841 -- Set_Public_Status --
11842 -----------------------
11844 procedure Set_Public_Status (Id : Entity_Id) is
11845 S : constant Entity_Id := Current_Scope;
11847 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11848 -- Determines if E is defined within handled statement sequence or
11849 -- an if statement, returns True if so, False otherwise.
11851 ----------------------
11852 -- Within_HSS_Or_If --
11853 ----------------------
11855 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11858 N := Declaration_Node (E);
11865 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11871 end Within_HSS_Or_If;
11873 -- Start of processing for Set_Public_Status
11876 -- Everything in the scope of Standard is public
11878 if S = Standard_Standard then
11879 Set_Is_Public (Id);
11881 -- Entity is definitely not public if enclosing scope is not public
11883 elsif not Is_Public (S) then
11886 -- An object or function declaration that occurs in a handled sequence
11887 -- of statements or within an if statement is the declaration for a
11888 -- temporary object or local subprogram generated by the expander. It
11889 -- never needs to be made public and furthermore, making it public can
11890 -- cause back end problems.
11892 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11893 N_Function_Specification)
11894 and then Within_HSS_Or_If (Id)
11898 -- Entities in public packages or records are public
11900 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11901 Set_Is_Public (Id);
11903 -- The bounds of an entry family declaration can generate object
11904 -- declarations that are visible to the back-end, e.g. in the
11905 -- the declaration of a composite type that contains tasks.
11907 elsif Is_Concurrent_Type (S)
11908 and then not Has_Completion (S)
11909 and then Nkind (Parent (Id)) = N_Object_Declaration
11911 Set_Is_Public (Id);
11913 end Set_Public_Status;
11915 -----------------------------
11916 -- Set_Referenced_Modified --
11917 -----------------------------
11919 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11923 -- Deal with indexed or selected component where prefix is modified
11925 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11926 Pref := Prefix (N);
11928 -- If prefix is access type, then it is the designated object that is
11929 -- being modified, which means we have no entity to set the flag on.
11931 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11934 -- Otherwise chase the prefix
11937 Set_Referenced_Modified (Pref, Out_Param);
11940 -- Otherwise see if we have an entity name (only other case to process)
11942 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11943 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11944 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11946 end Set_Referenced_Modified;
11948 ----------------------------
11949 -- Set_Scope_Is_Transient --
11950 ----------------------------
11952 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11954 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11955 end Set_Scope_Is_Transient;
11957 -------------------
11958 -- Set_Size_Info --
11959 -------------------
11961 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11963 -- We copy Esize, but not RM_Size, since in general RM_Size is
11964 -- subtype specific and does not get inherited by all subtypes.
11966 Set_Esize (T1, Esize (T2));
11967 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11969 if Is_Discrete_Or_Fixed_Point_Type (T1)
11971 Is_Discrete_Or_Fixed_Point_Type (T2)
11973 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11976 Set_Alignment (T1, Alignment (T2));
11979 --------------------
11980 -- Static_Boolean --
11981 --------------------
11983 function Static_Boolean (N : Node_Id) return Uint is
11985 Analyze_And_Resolve (N, Standard_Boolean);
11988 or else Error_Posted (N)
11989 or else Etype (N) = Any_Type
11994 if Is_Static_Expression (N) then
11995 if not Raises_Constraint_Error (N) then
11996 return Expr_Value (N);
12001 elsif Etype (N) = Any_Type then
12005 Flag_Non_Static_Expr
12006 ("static boolean expression required here", N);
12009 end Static_Boolean;
12011 --------------------
12012 -- Static_Integer --
12013 --------------------
12015 function Static_Integer (N : Node_Id) return Uint is
12017 Analyze_And_Resolve (N, Any_Integer);
12020 or else Error_Posted (N)
12021 or else Etype (N) = Any_Type
12026 if Is_Static_Expression (N) then
12027 if not Raises_Constraint_Error (N) then
12028 return Expr_Value (N);
12033 elsif Etype (N) = Any_Type then
12037 Flag_Non_Static_Expr
12038 ("static integer expression required here", N);
12041 end Static_Integer;
12043 --------------------------
12044 -- Statically_Different --
12045 --------------------------
12047 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12048 R1 : constant Node_Id := Get_Referenced_Object (E1);
12049 R2 : constant Node_Id := Get_Referenced_Object (E2);
12051 return Is_Entity_Name (R1)
12052 and then Is_Entity_Name (R2)
12053 and then Entity (R1) /= Entity (R2)
12054 and then not Is_Formal (Entity (R1))
12055 and then not Is_Formal (Entity (R2));
12056 end Statically_Different;
12058 -----------------------------
12059 -- Subprogram_Access_Level --
12060 -----------------------------
12062 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12064 if Present (Alias (Subp)) then
12065 return Subprogram_Access_Level (Alias (Subp));
12067 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12069 end Subprogram_Access_Level;
12075 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12077 if Debug_Flag_W then
12078 for J in 0 .. Scope_Stack.Last loop
12083 Write_Name (Chars (E));
12084 Write_Str (" from ");
12085 Write_Location (Sloc (N));
12090 -----------------------
12091 -- Transfer_Entities --
12092 -----------------------
12094 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12095 Ent : Entity_Id := First_Entity (From);
12102 if (Last_Entity (To)) = Empty then
12103 Set_First_Entity (To, Ent);
12105 Set_Next_Entity (Last_Entity (To), Ent);
12108 Set_Last_Entity (To, Last_Entity (From));
12110 while Present (Ent) loop
12111 Set_Scope (Ent, To);
12113 if not Is_Public (Ent) then
12114 Set_Public_Status (Ent);
12117 and then Ekind (Ent) = E_Record_Subtype
12120 -- The components of the propagated Itype must be public
12126 Comp := First_Entity (Ent);
12127 while Present (Comp) loop
12128 Set_Is_Public (Comp);
12129 Next_Entity (Comp);
12138 Set_First_Entity (From, Empty);
12139 Set_Last_Entity (From, Empty);
12140 end Transfer_Entities;
12142 -----------------------
12143 -- Type_Access_Level --
12144 -----------------------
12146 function Type_Access_Level (Typ : Entity_Id) return Uint is
12150 Btyp := Base_Type (Typ);
12152 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12153 -- simply use the level where the type is declared. This is true for
12154 -- stand-alone object declarations, and for anonymous access types
12155 -- associated with components the level is the same as that of the
12156 -- enclosing composite type. However, special treatment is needed for
12157 -- the cases of access parameters, return objects of an anonymous access
12158 -- type, and, in Ada 95, access discriminants of limited types.
12160 if Ekind (Btyp) in Access_Kind then
12161 if Ekind (Btyp) = E_Anonymous_Access_Type then
12163 -- If the type is a nonlocal anonymous access type (such as for
12164 -- an access parameter) we treat it as being declared at the
12165 -- library level to ensure that names such as X.all'access don't
12166 -- fail static accessibility checks.
12168 if not Is_Local_Anonymous_Access (Typ) then
12169 return Scope_Depth (Standard_Standard);
12171 -- If this is a return object, the accessibility level is that of
12172 -- the result subtype of the enclosing function. The test here is
12173 -- little complicated, because we have to account for extended
12174 -- return statements that have been rewritten as blocks, in which
12175 -- case we have to find and the Is_Return_Object attribute of the
12176 -- itype's associated object. It would be nice to find a way to
12177 -- simplify this test, but it doesn't seem worthwhile to add a new
12178 -- flag just for purposes of this test. ???
12180 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12183 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12184 N_Object_Declaration
12185 and then Is_Return_Object
12186 (Defining_Identifier
12187 (Associated_Node_For_Itype (Btyp))))
12193 Scop := Scope (Scope (Btyp));
12194 while Present (Scop) loop
12195 exit when Ekind (Scop) = E_Function;
12196 Scop := Scope (Scop);
12199 -- Treat the return object's type as having the level of the
12200 -- function's result subtype (as per RM05-6.5(5.3/2)).
12202 return Type_Access_Level (Etype (Scop));
12207 Btyp := Root_Type (Btyp);
12209 -- The accessibility level of anonymous access types associated with
12210 -- discriminants is that of the current instance of the type, and
12211 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12213 -- AI-402: access discriminants have accessibility based on the
12214 -- object rather than the type in Ada 2005, so the above paragraph
12217 -- ??? Needs completion with rules from AI-416
12219 if Ada_Version <= Ada_95
12220 and then Ekind (Typ) = E_Anonymous_Access_Type
12221 and then Present (Associated_Node_For_Itype (Typ))
12222 and then Nkind (Associated_Node_For_Itype (Typ)) =
12223 N_Discriminant_Specification
12225 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12229 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12230 end Type_Access_Level;
12232 ----------------------------
12233 -- Unique_Defining_Entity --
12234 ----------------------------
12236 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
12239 when N_Package_Body =>
12240 return Corresponding_Spec (N);
12242 when N_Subprogram_Body =>
12243 if Acts_As_Spec (N) then
12244 return Defining_Entity (N);
12246 return Corresponding_Spec (N);
12250 return Defining_Entity (N);
12252 end Unique_Defining_Entity;
12258 function Unique_Name (E : Entity_Id) return String is
12259 Name : constant String := Get_Name_String (Chars (E));
12261 if Has_Fully_Qualified_Name (E)
12262 or else E = Standard_Standard
12266 return Unique_Name (Scope (E)) & "__" & Name;
12270 --------------------------
12271 -- Unit_Declaration_Node --
12272 --------------------------
12274 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12275 N : Node_Id := Parent (Unit_Id);
12278 -- Predefined operators do not have a full function declaration
12280 if Ekind (Unit_Id) = E_Operator then
12284 -- Isn't there some better way to express the following ???
12286 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12287 and then Nkind (N) /= N_Formal_Package_Declaration
12288 and then Nkind (N) /= N_Function_Instantiation
12289 and then Nkind (N) /= N_Generic_Package_Declaration
12290 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12291 and then Nkind (N) /= N_Package_Declaration
12292 and then Nkind (N) /= N_Package_Body
12293 and then Nkind (N) /= N_Package_Instantiation
12294 and then Nkind (N) /= N_Package_Renaming_Declaration
12295 and then Nkind (N) /= N_Procedure_Instantiation
12296 and then Nkind (N) /= N_Protected_Body
12297 and then Nkind (N) /= N_Subprogram_Declaration
12298 and then Nkind (N) /= N_Subprogram_Body
12299 and then Nkind (N) /= N_Subprogram_Body_Stub
12300 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12301 and then Nkind (N) /= N_Task_Body
12302 and then Nkind (N) /= N_Task_Type_Declaration
12303 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12304 and then Nkind (N) not in N_Generic_Renaming_Declaration
12307 pragma Assert (Present (N));
12311 end Unit_Declaration_Node;
12313 ---------------------
12314 -- Unit_Is_Visible --
12315 ---------------------
12317 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12318 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12319 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12321 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12322 -- For a child unit, check whether unit appears in a with_clause
12325 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12326 -- Scan the context clause of one compilation unit looking for a
12327 -- with_clause for the unit in question.
12329 ----------------------------
12330 -- Unit_In_Parent_Context --
12331 ----------------------------
12333 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12335 if Unit_In_Context (Par_Unit) then
12338 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12339 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12344 end Unit_In_Parent_Context;
12346 ---------------------
12347 -- Unit_In_Context --
12348 ---------------------
12350 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12354 Clause := First (Context_Items (Comp_Unit));
12355 while Present (Clause) loop
12356 if Nkind (Clause) = N_With_Clause then
12357 if Library_Unit (Clause) = U then
12360 -- The with_clause may denote a renaming of the unit we are
12361 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12364 Renamed_Entity (Entity (Name (Clause))) =
12365 Defining_Entity (Unit (U))
12375 end Unit_In_Context;
12377 -- Start of processing for Unit_Is_Visible
12380 -- The currrent unit is directly visible.
12385 elsif Unit_In_Context (Curr) then
12388 -- If the current unit is a body, check the context of the spec.
12390 elsif Nkind (Unit (Curr)) = N_Package_Body
12392 (Nkind (Unit (Curr)) = N_Subprogram_Body
12393 and then not Acts_As_Spec (Unit (Curr)))
12395 if Unit_In_Context (Library_Unit (Curr)) then
12400 -- If the spec is a child unit, examine the parents.
12402 if Is_Child_Unit (Curr_Entity) then
12403 if Nkind (Unit (Curr)) in N_Unit_Body then
12405 Unit_In_Parent_Context
12406 (Parent_Spec (Unit (Library_Unit (Curr))));
12408 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12414 end Unit_Is_Visible;
12416 ------------------------------
12417 -- Universal_Interpretation --
12418 ------------------------------
12420 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12421 Index : Interp_Index;
12425 -- The argument may be a formal parameter of an operator or subprogram
12426 -- with multiple interpretations, or else an expression for an actual.
12428 if Nkind (Opnd) = N_Defining_Identifier
12429 or else not Is_Overloaded (Opnd)
12431 if Etype (Opnd) = Universal_Integer
12432 or else Etype (Opnd) = Universal_Real
12434 return Etype (Opnd);
12440 Get_First_Interp (Opnd, Index, It);
12441 while Present (It.Typ) loop
12442 if It.Typ = Universal_Integer
12443 or else It.Typ = Universal_Real
12448 Get_Next_Interp (Index, It);
12453 end Universal_Interpretation;
12459 function Unqualify (Expr : Node_Id) return Node_Id is
12461 -- Recurse to handle unlikely case of multiple levels of qualification
12463 if Nkind (Expr) = N_Qualified_Expression then
12464 return Unqualify (Expression (Expr));
12466 -- Normal case, not a qualified expression
12473 -----------------------
12474 -- Visible_Ancestors --
12475 -----------------------
12477 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12483 pragma Assert (Is_Record_Type (Typ)
12484 and then Is_Tagged_Type (Typ));
12486 -- Collect all the parents and progenitors of Typ. If the full-view of
12487 -- private parents and progenitors is available then it is used to
12488 -- generate the list of visible ancestors; otherwise their partial
12489 -- view is added to the resulting list.
12494 Use_Full_View => True);
12498 Ifaces_List => List_2,
12499 Exclude_Parents => True,
12500 Use_Full_View => True);
12502 -- Join the two lists. Avoid duplications because an interface may
12503 -- simultaneously be parent and progenitor of a type.
12505 Elmt := First_Elmt (List_2);
12506 while Present (Elmt) loop
12507 Append_Unique_Elmt (Node (Elmt), List_1);
12512 end Visible_Ancestors;
12514 ----------------------
12515 -- Within_Init_Proc --
12516 ----------------------
12518 function Within_Init_Proc return Boolean is
12522 S := Current_Scope;
12523 while not Is_Overloadable (S) loop
12524 if S = Standard_Standard then
12531 return Is_Init_Proc (S);
12532 end Within_Init_Proc;
12538 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12539 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12540 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12542 Matching_Field : Entity_Id;
12543 -- Entity to give a more precise suggestion on how to write a one-
12544 -- element positional aggregate.
12546 function Has_One_Matching_Field return Boolean;
12547 -- Determines if Expec_Type is a record type with a single component or
12548 -- discriminant whose type matches the found type or is one dimensional
12549 -- array whose component type matches the found type.
12551 ----------------------------
12552 -- Has_One_Matching_Field --
12553 ----------------------------
12555 function Has_One_Matching_Field return Boolean is
12559 Matching_Field := Empty;
12561 if Is_Array_Type (Expec_Type)
12562 and then Number_Dimensions (Expec_Type) = 1
12564 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12566 -- Use type name if available. This excludes multidimensional
12567 -- arrays and anonymous arrays.
12569 if Comes_From_Source (Expec_Type) then
12570 Matching_Field := Expec_Type;
12572 -- For an assignment, use name of target.
12574 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
12575 and then Is_Entity_Name (Name (Parent (Expr)))
12577 Matching_Field := Entity (Name (Parent (Expr)));
12582 elsif not Is_Record_Type (Expec_Type) then
12586 E := First_Entity (Expec_Type);
12591 elsif (Ekind (E) /= E_Discriminant
12592 and then Ekind (E) /= E_Component)
12593 or else (Chars (E) = Name_uTag
12594 or else Chars (E) = Name_uParent)
12603 if not Covers (Etype (E), Found_Type) then
12606 elsif Present (Next_Entity (E)) then
12610 Matching_Field := E;
12614 end Has_One_Matching_Field;
12616 -- Start of processing for Wrong_Type
12619 -- Don't output message if either type is Any_Type, or if a message
12620 -- has already been posted for this node. We need to do the latter
12621 -- check explicitly (it is ordinarily done in Errout), because we
12622 -- are using ! to force the output of the error messages.
12624 if Expec_Type = Any_Type
12625 or else Found_Type = Any_Type
12626 or else Error_Posted (Expr)
12630 -- In an instance, there is an ongoing problem with completion of
12631 -- type derived from private types. Their structure is what Gigi
12632 -- expects, but the Etype is the parent type rather than the
12633 -- derived private type itself. Do not flag error in this case. The
12634 -- private completion is an entity without a parent, like an Itype.
12635 -- Similarly, full and partial views may be incorrect in the instance.
12636 -- There is no simple way to insure that it is consistent ???
12638 elsif In_Instance then
12639 if Etype (Etype (Expr)) = Etype (Expected_Type)
12641 (Has_Private_Declaration (Expected_Type)
12642 or else Has_Private_Declaration (Etype (Expr)))
12643 and then No (Parent (Expected_Type))
12649 -- An interesting special check. If the expression is parenthesized
12650 -- and its type corresponds to the type of the sole component of the
12651 -- expected record type, or to the component type of the expected one
12652 -- dimensional array type, then assume we have a bad aggregate attempt.
12654 if Nkind (Expr) in N_Subexpr
12655 and then Paren_Count (Expr) /= 0
12656 and then Has_One_Matching_Field
12658 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12659 if Present (Matching_Field) then
12660 if Is_Array_Type (Expec_Type) then
12662 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
12666 ("\write instead `& ='> ...`", Expr, Matching_Field);
12670 -- Another special check, if we are looking for a pool-specific access
12671 -- type and we found an E_Access_Attribute_Type, then we have the case
12672 -- of an Access attribute being used in a context which needs a pool-
12673 -- specific type, which is never allowed. The one extra check we make
12674 -- is that the expected designated type covers the Found_Type.
12676 elsif Is_Access_Type (Expec_Type)
12677 and then Ekind (Found_Type) = E_Access_Attribute_Type
12678 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12679 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12681 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12683 Error_Msg_N -- CODEFIX
12684 ("result must be general access type!", Expr);
12685 Error_Msg_NE -- CODEFIX
12686 ("add ALL to }!", Expr, Expec_Type);
12688 -- Another special check, if the expected type is an integer type,
12689 -- but the expression is of type System.Address, and the parent is
12690 -- an addition or subtraction operation whose left operand is the
12691 -- expression in question and whose right operand is of an integral
12692 -- type, then this is an attempt at address arithmetic, so give
12693 -- appropriate message.
12695 elsif Is_Integer_Type (Expec_Type)
12696 and then Is_RTE (Found_Type, RE_Address)
12697 and then (Nkind (Parent (Expr)) = N_Op_Add
12699 Nkind (Parent (Expr)) = N_Op_Subtract)
12700 and then Expr = Left_Opnd (Parent (Expr))
12701 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12704 ("address arithmetic not predefined in package System",
12707 ("\possible missing with/use of System.Storage_Elements",
12711 -- If the expected type is an anonymous access type, as for access
12712 -- parameters and discriminants, the error is on the designated types.
12714 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12715 if Comes_From_Source (Expec_Type) then
12716 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12719 ("expected an access type with designated}",
12720 Expr, Designated_Type (Expec_Type));
12723 if Is_Access_Type (Found_Type)
12724 and then not Comes_From_Source (Found_Type)
12727 ("\\found an access type with designated}!",
12728 Expr, Designated_Type (Found_Type));
12730 if From_With_Type (Found_Type) then
12731 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12732 Error_Msg_Qual_Level := 99;
12733 Error_Msg_NE -- CODEFIX
12734 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12735 Error_Msg_Qual_Level := 0;
12737 Error_Msg_NE ("found}!", Expr, Found_Type);
12741 -- Normal case of one type found, some other type expected
12744 -- If the names of the two types are the same, see if some number
12745 -- of levels of qualification will help. Don't try more than three
12746 -- levels, and if we get to standard, it's no use (and probably
12747 -- represents an error in the compiler) Also do not bother with
12748 -- internal scope names.
12751 Expec_Scope : Entity_Id;
12752 Found_Scope : Entity_Id;
12755 Expec_Scope := Expec_Type;
12756 Found_Scope := Found_Type;
12758 for Levels in Int range 0 .. 3 loop
12759 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12760 Error_Msg_Qual_Level := Levels;
12764 Expec_Scope := Scope (Expec_Scope);
12765 Found_Scope := Scope (Found_Scope);
12767 exit when Expec_Scope = Standard_Standard
12768 or else Found_Scope = Standard_Standard
12769 or else not Comes_From_Source (Expec_Scope)
12770 or else not Comes_From_Source (Found_Scope);
12774 if Is_Record_Type (Expec_Type)
12775 and then Present (Corresponding_Remote_Type (Expec_Type))
12777 Error_Msg_NE ("expected}!", Expr,
12778 Corresponding_Remote_Type (Expec_Type));
12780 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12783 if Is_Entity_Name (Expr)
12784 and then Is_Package_Or_Generic_Package (Entity (Expr))
12786 Error_Msg_N ("\\found package name!", Expr);
12788 elsif Is_Entity_Name (Expr)
12790 (Ekind (Entity (Expr)) = E_Procedure
12792 Ekind (Entity (Expr)) = E_Generic_Procedure)
12794 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12796 ("found procedure name, possibly missing Access attribute!",
12800 ("\\found procedure name instead of function!", Expr);
12803 elsif Nkind (Expr) = N_Function_Call
12804 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12805 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12806 and then No (Parameter_Associations (Expr))
12809 ("found function name, possibly missing Access attribute!",
12812 -- Catch common error: a prefix or infix operator which is not
12813 -- directly visible because the type isn't.
12815 elsif Nkind (Expr) in N_Op
12816 and then Is_Overloaded (Expr)
12817 and then not Is_Immediately_Visible (Expec_Type)
12818 and then not Is_Potentially_Use_Visible (Expec_Type)
12819 and then not In_Use (Expec_Type)
12820 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12823 ("operator of the type is not directly visible!", Expr);
12825 elsif Ekind (Found_Type) = E_Void
12826 and then Present (Parent (Found_Type))
12827 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12829 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12832 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12835 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12836 -- of the same modular type, and (M1 and M2) = 0 was intended.
12838 if Expec_Type = Standard_Boolean
12839 and then Is_Modular_Integer_Type (Found_Type)
12840 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12841 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12844 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12845 L : constant Node_Id := Left_Opnd (Op);
12846 R : constant Node_Id := Right_Opnd (Op);
12848 -- The case for the message is when the left operand of the
12849 -- comparison is the same modular type, or when it is an
12850 -- integer literal (or other universal integer expression),
12851 -- which would have been typed as the modular type if the
12852 -- parens had been there.
12854 if (Etype (L) = Found_Type
12856 Etype (L) = Universal_Integer)
12857 and then Is_Integer_Type (Etype (R))
12860 ("\\possible missing parens for modular operation", Expr);
12865 -- Reset error message qualification indication
12867 Error_Msg_Qual_Level := 0;