1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Namet.Sp; use Namet.Sp;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Attr; use Sem_Attr;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Disp; use Sem_Disp;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Res; use Sem_Res;
54 with Sem_Type; use Sem_Type;
55 with Sinfo; use Sinfo;
56 with Sinput; use Sinput;
57 with Stand; use Stand;
59 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 := 0;
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 -- Local Subprograms --
100 -----------------------
102 function Build_Component_Subtype
105 T : Entity_Id) return Node_Id;
106 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
107 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
108 -- Loc is the source location, T is the original subtype.
110 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
111 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
112 -- with discriminants whose default values are static, examine only the
113 -- components in the selected variant to determine whether all of them
116 function Has_Null_Extension (T : Entity_Id) return Boolean;
117 -- T is a derived tagged type. Check whether the type extension is null.
118 -- If the parent type is fully initialized, T can be treated as such.
120 ------------------------------
121 -- Abstract_Interface_List --
122 ------------------------------
124 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
128 if Is_Concurrent_Type (Typ) then
130 -- If we are dealing with a synchronized subtype, go to the base
131 -- type, whose declaration has the interface list.
133 -- Shouldn't this be Declaration_Node???
135 Nod := Parent (Base_Type (Typ));
137 if Nkind (Nod) = N_Full_Type_Declaration then
141 elsif Ekind (Typ) = E_Record_Type_With_Private then
142 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
143 Nod := Type_Definition (Parent (Typ));
145 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
146 if Present (Full_View (Typ))
147 and then Nkind (Parent (Full_View (Typ)))
148 = N_Full_Type_Declaration
150 Nod := Type_Definition (Parent (Full_View (Typ)));
152 -- If the full-view is not available we cannot do anything else
153 -- here (the source has errors).
159 -- Support for generic formals with interfaces is still missing ???
161 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
166 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
170 elsif Ekind (Typ) = E_Record_Subtype then
171 Nod := Type_Definition (Parent (Etype (Typ)));
173 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
175 -- Recurse, because parent may still be a private extension. Also
176 -- note that the full view of the subtype or the full view of its
177 -- base type may (both) be unavailable.
179 return Abstract_Interface_List (Etype (Typ));
181 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
182 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
183 Nod := Formal_Type_Definition (Parent (Typ));
185 Nod := Type_Definition (Parent (Typ));
189 return Interface_List (Nod);
190 end Abstract_Interface_List;
192 --------------------------------
193 -- Add_Access_Type_To_Process --
194 --------------------------------
196 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
200 Ensure_Freeze_Node (E);
201 L := Access_Types_To_Process (Freeze_Node (E));
205 Set_Access_Types_To_Process (Freeze_Node (E), L);
209 end Add_Access_Type_To_Process;
211 -----------------------
212 -- Add_Contract_Item --
213 -----------------------
215 procedure Add_Contract_Item (Prag : Node_Id; Subp_Id : Entity_Id) is
216 Items : constant Node_Id := Contract (Subp_Id);
220 -- The related subprogram [body] must have a contract and the item to be
221 -- added must be a pragma.
223 pragma Assert (Present (Items));
224 pragma Assert (Nkind (Prag) = N_Pragma);
226 Nam := Pragma_Name (Prag);
228 -- Contract items related to subprogram bodies
230 if Ekind (Subp_Id) = E_Subprogram_Body then
231 if Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
232 Set_Next_Pragma (Prag, Classifications (Items));
233 Set_Classifications (Items, Prag);
235 -- The pragma is not a proper contract item
241 -- Contract items related to subprogram declarations
244 if Nam_In (Nam, Name_Precondition, Name_Postcondition) then
245 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
246 Set_Pre_Post_Conditions (Items, Prag);
248 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
249 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
250 Set_Contract_Test_Cases (Items, Prag);
252 elsif Nam_In (Nam, Name_Depends, Name_Global) then
253 Set_Next_Pragma (Prag, Classifications (Items));
254 Set_Classifications (Items, Prag);
256 -- The pragma is not a proper contract item
262 end Add_Contract_Item;
264 ----------------------------
265 -- Add_Global_Declaration --
266 ----------------------------
268 procedure Add_Global_Declaration (N : Node_Id) is
269 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
272 if No (Declarations (Aux_Node)) then
273 Set_Declarations (Aux_Node, New_List);
276 Append_To (Declarations (Aux_Node), N);
278 end Add_Global_Declaration;
284 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
286 function Addressable (V : Uint) return Boolean is
288 return V = Uint_8 or else
294 function Addressable (V : Int) return Boolean is
302 -----------------------
303 -- Alignment_In_Bits --
304 -----------------------
306 function Alignment_In_Bits (E : Entity_Id) return Uint is
308 return Alignment (E) * System_Storage_Unit;
309 end Alignment_In_Bits;
311 ---------------------------------
312 -- Append_Inherited_Subprogram --
313 ---------------------------------
315 procedure Append_Inherited_Subprogram (S : Entity_Id) is
316 Par : constant Entity_Id := Alias (S);
317 -- The parent subprogram
319 Scop : constant Entity_Id := Scope (Par);
320 -- The scope of definition of the parent subprogram
322 Typ : constant Entity_Id := Defining_Entity (Parent (S));
323 -- The derived type of which S is a primitive operation
329 if Ekind (Current_Scope) = E_Package
330 and then In_Private_Part (Current_Scope)
331 and then Has_Private_Declaration (Typ)
332 and then Is_Tagged_Type (Typ)
333 and then Scop = Current_Scope
335 -- The inherited operation is available at the earliest place after
336 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
337 -- relevant for type extensions. If the parent operation appears
338 -- after the type extension, the operation is not visible.
341 (Visible_Declarations
342 (Specification (Unit_Declaration_Node (Current_Scope))));
343 while Present (Decl) loop
344 if Nkind (Decl) = N_Private_Extension_Declaration
345 and then Defining_Entity (Decl) = Typ
347 if Sloc (Decl) > Sloc (Par) then
348 Next_E := Next_Entity (Par);
349 Set_Next_Entity (Par, S);
350 Set_Next_Entity (S, Next_E);
362 -- If partial view is not a type extension, or it appears before the
363 -- subprogram declaration, insert normally at end of entity list.
365 Append_Entity (S, Current_Scope);
366 end Append_Inherited_Subprogram;
368 -----------------------------------------
369 -- Apply_Compile_Time_Constraint_Error --
370 -----------------------------------------
372 procedure Apply_Compile_Time_Constraint_Error
375 Reason : RT_Exception_Code;
376 Ent : Entity_Id := Empty;
377 Typ : Entity_Id := Empty;
378 Loc : Source_Ptr := No_Location;
379 Rep : Boolean := True;
380 Warn : Boolean := False)
382 Stat : constant Boolean := Is_Static_Expression (N);
383 R_Stat : constant Node_Id :=
384 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
395 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
401 -- Now we replace the node by an N_Raise_Constraint_Error node
402 -- This does not need reanalyzing, so set it as analyzed now.
405 Set_Analyzed (N, True);
408 Set_Raises_Constraint_Error (N);
410 -- Now deal with possible local raise handling
412 Possible_Local_Raise (N, Standard_Constraint_Error);
414 -- If the original expression was marked as static, the result is
415 -- still marked as static, but the Raises_Constraint_Error flag is
416 -- always set so that further static evaluation is not attempted.
419 Set_Is_Static_Expression (N);
421 end Apply_Compile_Time_Constraint_Error;
423 --------------------------------------
424 -- Available_Full_View_Of_Component --
425 --------------------------------------
427 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
428 ST : constant Entity_Id := Scope (T);
429 SCT : constant Entity_Id := Scope (Component_Type (T));
431 return In_Open_Scopes (ST)
432 and then In_Open_Scopes (SCT)
433 and then Scope_Depth (ST) >= Scope_Depth (SCT);
434 end Available_Full_View_Of_Component;
440 procedure Bad_Attribute
443 Warn : Boolean := False)
446 Error_Msg_Warn := Warn;
447 Error_Msg_N ("unrecognized attribute&<", N);
449 -- Check for possible misspelling
451 Error_Msg_Name_1 := First_Attribute_Name;
452 while Error_Msg_Name_1 <= Last_Attribute_Name loop
453 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
454 Error_Msg_N -- CODEFIX
455 ("\possible misspelling of %<", N);
459 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
463 --------------------------------
464 -- Bad_Predicated_Subtype_Use --
465 --------------------------------
467 procedure Bad_Predicated_Subtype_Use
471 Suggest_Static : Boolean := False)
474 if Has_Predicates (Typ) then
475 if Is_Generic_Actual_Type (Typ) then
476 Error_Msg_FE (Msg & "??", N, Typ);
477 Error_Msg_F ("\Program_Error will be raised at run time??", N);
479 Make_Raise_Program_Error (Sloc (N),
480 Reason => PE_Bad_Predicated_Generic_Type));
483 Error_Msg_FE (Msg, N, Typ);
486 -- Emit an optional suggestion on how to remedy the error if the
487 -- context warrants it.
489 if Suggest_Static and then Present (Static_Predicate (Typ)) then
490 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
493 end Bad_Predicated_Subtype_Use;
495 --------------------------
496 -- Build_Actual_Subtype --
497 --------------------------
499 function Build_Actual_Subtype
501 N : Node_Or_Entity_Id) return Node_Id
504 -- Normally Sloc (N), but may point to corresponding body in some cases
506 Constraints : List_Id;
512 Disc_Type : Entity_Id;
518 if Nkind (N) = N_Defining_Identifier then
519 Obj := New_Reference_To (N, Loc);
521 -- If this is a formal parameter of a subprogram declaration, and
522 -- we are compiling the body, we want the declaration for the
523 -- actual subtype to carry the source position of the body, to
524 -- prevent anomalies in gdb when stepping through the code.
526 if Is_Formal (N) then
528 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
530 if Nkind (Decl) = N_Subprogram_Declaration
531 and then Present (Corresponding_Body (Decl))
533 Loc := Sloc (Corresponding_Body (Decl));
542 if Is_Array_Type (T) then
543 Constraints := New_List;
544 for J in 1 .. Number_Dimensions (T) loop
546 -- Build an array subtype declaration with the nominal subtype and
547 -- the bounds of the actual. Add the declaration in front of the
548 -- local declarations for the subprogram, for analysis before any
549 -- reference to the formal in the body.
552 Make_Attribute_Reference (Loc,
554 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
555 Attribute_Name => Name_First,
556 Expressions => New_List (
557 Make_Integer_Literal (Loc, J)));
560 Make_Attribute_Reference (Loc,
562 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
563 Attribute_Name => Name_Last,
564 Expressions => New_List (
565 Make_Integer_Literal (Loc, J)));
567 Append (Make_Range (Loc, Lo, Hi), Constraints);
570 -- If the type has unknown discriminants there is no constrained
571 -- subtype to build. This is never called for a formal or for a
572 -- lhs, so returning the type is ok ???
574 elsif Has_Unknown_Discriminants (T) then
578 Constraints := New_List;
580 -- Type T is a generic derived type, inherit the discriminants from
583 if Is_Private_Type (T)
584 and then No (Full_View (T))
586 -- T was flagged as an error if it was declared as a formal
587 -- derived type with known discriminants. In this case there
588 -- is no need to look at the parent type since T already carries
589 -- its own discriminants.
591 and then not Error_Posted (T)
593 Disc_Type := Etype (Base_Type (T));
598 Discr := First_Discriminant (Disc_Type);
599 while Present (Discr) loop
600 Append_To (Constraints,
601 Make_Selected_Component (Loc,
603 Duplicate_Subexpr_No_Checks (Obj),
604 Selector_Name => New_Occurrence_Of (Discr, Loc)));
605 Next_Discriminant (Discr);
609 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
610 Set_Is_Internal (Subt);
613 Make_Subtype_Declaration (Loc,
614 Defining_Identifier => Subt,
615 Subtype_Indication =>
616 Make_Subtype_Indication (Loc,
617 Subtype_Mark => New_Reference_To (T, Loc),
619 Make_Index_Or_Discriminant_Constraint (Loc,
620 Constraints => Constraints)));
622 Mark_Rewrite_Insertion (Decl);
624 end Build_Actual_Subtype;
626 ---------------------------------------
627 -- Build_Actual_Subtype_Of_Component --
628 ---------------------------------------
630 function Build_Actual_Subtype_Of_Component
632 N : Node_Id) return Node_Id
634 Loc : constant Source_Ptr := Sloc (N);
635 P : constant Node_Id := Prefix (N);
638 Index_Typ : Entity_Id;
640 Desig_Typ : Entity_Id;
641 -- This is either a copy of T, or if T is an access type, then it is
642 -- the directly designated type of this access type.
644 function Build_Actual_Array_Constraint return List_Id;
645 -- If one or more of the bounds of the component depends on
646 -- discriminants, build actual constraint using the discriminants
649 function Build_Actual_Record_Constraint return List_Id;
650 -- Similar to previous one, for discriminated components constrained
651 -- by the discriminant of the enclosing object.
653 -----------------------------------
654 -- Build_Actual_Array_Constraint --
655 -----------------------------------
657 function Build_Actual_Array_Constraint return List_Id is
658 Constraints : constant List_Id := New_List;
666 Indx := First_Index (Desig_Typ);
667 while Present (Indx) loop
668 Old_Lo := Type_Low_Bound (Etype (Indx));
669 Old_Hi := Type_High_Bound (Etype (Indx));
671 if Denotes_Discriminant (Old_Lo) then
673 Make_Selected_Component (Loc,
674 Prefix => New_Copy_Tree (P),
675 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
678 Lo := New_Copy_Tree (Old_Lo);
680 -- The new bound will be reanalyzed in the enclosing
681 -- declaration. For literal bounds that come from a type
682 -- declaration, the type of the context must be imposed, so
683 -- insure that analysis will take place. For non-universal
684 -- types this is not strictly necessary.
686 Set_Analyzed (Lo, False);
689 if Denotes_Discriminant (Old_Hi) then
691 Make_Selected_Component (Loc,
692 Prefix => New_Copy_Tree (P),
693 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
696 Hi := New_Copy_Tree (Old_Hi);
697 Set_Analyzed (Hi, False);
700 Append (Make_Range (Loc, Lo, Hi), Constraints);
705 end Build_Actual_Array_Constraint;
707 ------------------------------------
708 -- Build_Actual_Record_Constraint --
709 ------------------------------------
711 function Build_Actual_Record_Constraint return List_Id is
712 Constraints : constant List_Id := New_List;
717 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
718 while Present (D) loop
719 if Denotes_Discriminant (Node (D)) then
720 D_Val := Make_Selected_Component (Loc,
721 Prefix => New_Copy_Tree (P),
722 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
725 D_Val := New_Copy_Tree (Node (D));
728 Append (D_Val, Constraints);
733 end Build_Actual_Record_Constraint;
735 -- Start of processing for Build_Actual_Subtype_Of_Component
738 -- Why the test for Spec_Expression mode here???
740 if In_Spec_Expression then
743 -- More comments for the rest of this body would be good ???
745 elsif Nkind (N) = N_Explicit_Dereference then
746 if Is_Composite_Type (T)
747 and then not Is_Constrained (T)
748 and then not (Is_Class_Wide_Type (T)
749 and then Is_Constrained (Root_Type (T)))
750 and then not Has_Unknown_Discriminants (T)
752 -- If the type of the dereference is already constrained, it is an
755 if Is_Array_Type (Etype (N))
756 and then Is_Constrained (Etype (N))
760 Remove_Side_Effects (P);
761 return Build_Actual_Subtype (T, N);
768 if Ekind (T) = E_Access_Subtype then
769 Desig_Typ := Designated_Type (T);
774 if Ekind (Desig_Typ) = E_Array_Subtype then
775 Id := First_Index (Desig_Typ);
776 while Present (Id) loop
777 Index_Typ := Underlying_Type (Etype (Id));
779 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
781 Denotes_Discriminant (Type_High_Bound (Index_Typ))
783 Remove_Side_Effects (P);
785 Build_Component_Subtype
786 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
792 elsif Is_Composite_Type (Desig_Typ)
793 and then Has_Discriminants (Desig_Typ)
794 and then not Has_Unknown_Discriminants (Desig_Typ)
796 if Is_Private_Type (Desig_Typ)
797 and then No (Discriminant_Constraint (Desig_Typ))
799 Desig_Typ := Full_View (Desig_Typ);
802 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
803 while Present (D) loop
804 if Denotes_Discriminant (Node (D)) then
805 Remove_Side_Effects (P);
807 Build_Component_Subtype (
808 Build_Actual_Record_Constraint, Loc, Base_Type (T));
815 -- If none of the above, the actual and nominal subtypes are the same
818 end Build_Actual_Subtype_Of_Component;
820 -----------------------------
821 -- Build_Component_Subtype --
822 -----------------------------
824 function Build_Component_Subtype
827 T : Entity_Id) return Node_Id
833 -- Unchecked_Union components do not require component subtypes
835 if Is_Unchecked_Union (T) then
839 Subt := Make_Temporary (Loc, 'S');
840 Set_Is_Internal (Subt);
843 Make_Subtype_Declaration (Loc,
844 Defining_Identifier => Subt,
845 Subtype_Indication =>
846 Make_Subtype_Indication (Loc,
847 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
849 Make_Index_Or_Discriminant_Constraint (Loc,
852 Mark_Rewrite_Insertion (Decl);
854 end Build_Component_Subtype;
856 ---------------------------
857 -- Build_Default_Subtype --
858 ---------------------------
860 function Build_Default_Subtype
862 N : Node_Id) return Entity_Id
864 Loc : constant Source_Ptr := Sloc (N);
868 -- The base type that is to be constrained by the defaults
871 if not Has_Discriminants (T) or else Is_Constrained (T) then
875 Bas := Base_Type (T);
877 -- If T is non-private but its base type is private, this is the
878 -- completion of a subtype declaration whose parent type is private
879 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
880 -- are to be found in the full view of the base.
882 if Is_Private_Type (Bas) and then Present (Full_View (Bas)) then
883 Bas := Full_View (Bas);
886 Disc := First_Discriminant (T);
888 if No (Discriminant_Default_Value (Disc)) then
893 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
894 Constraints : constant List_Id := New_List;
898 while Present (Disc) loop
899 Append_To (Constraints,
900 New_Copy_Tree (Discriminant_Default_Value (Disc)));
901 Next_Discriminant (Disc);
905 Make_Subtype_Declaration (Loc,
906 Defining_Identifier => Act,
907 Subtype_Indication =>
908 Make_Subtype_Indication (Loc,
909 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
911 Make_Index_Or_Discriminant_Constraint (Loc,
912 Constraints => Constraints)));
914 Insert_Action (N, Decl);
918 end Build_Default_Subtype;
920 --------------------------------------------
921 -- Build_Discriminal_Subtype_Of_Component --
922 --------------------------------------------
924 function Build_Discriminal_Subtype_Of_Component
925 (T : Entity_Id) return Node_Id
927 Loc : constant Source_Ptr := Sloc (T);
931 function Build_Discriminal_Array_Constraint return List_Id;
932 -- If one or more of the bounds of the component depends on
933 -- discriminants, build actual constraint using the discriminants
936 function Build_Discriminal_Record_Constraint return List_Id;
937 -- Similar to previous one, for discriminated components constrained by
938 -- the discriminant of the enclosing object.
940 ----------------------------------------
941 -- Build_Discriminal_Array_Constraint --
942 ----------------------------------------
944 function Build_Discriminal_Array_Constraint return List_Id is
945 Constraints : constant List_Id := New_List;
953 Indx := First_Index (T);
954 while Present (Indx) loop
955 Old_Lo := Type_Low_Bound (Etype (Indx));
956 Old_Hi := Type_High_Bound (Etype (Indx));
958 if Denotes_Discriminant (Old_Lo) then
959 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
962 Lo := New_Copy_Tree (Old_Lo);
965 if Denotes_Discriminant (Old_Hi) then
966 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
969 Hi := New_Copy_Tree (Old_Hi);
972 Append (Make_Range (Loc, Lo, Hi), Constraints);
977 end Build_Discriminal_Array_Constraint;
979 -----------------------------------------
980 -- Build_Discriminal_Record_Constraint --
981 -----------------------------------------
983 function Build_Discriminal_Record_Constraint return List_Id is
984 Constraints : constant List_Id := New_List;
989 D := First_Elmt (Discriminant_Constraint (T));
990 while Present (D) loop
991 if Denotes_Discriminant (Node (D)) then
993 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
996 D_Val := New_Copy_Tree (Node (D));
999 Append (D_Val, Constraints);
1004 end Build_Discriminal_Record_Constraint;
1006 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1009 if Ekind (T) = E_Array_Subtype then
1010 Id := First_Index (T);
1011 while Present (Id) loop
1012 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
1013 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1015 return Build_Component_Subtype
1016 (Build_Discriminal_Array_Constraint, Loc, T);
1022 elsif Ekind (T) = E_Record_Subtype
1023 and then Has_Discriminants (T)
1024 and then not Has_Unknown_Discriminants (T)
1026 D := First_Elmt (Discriminant_Constraint (T));
1027 while Present (D) loop
1028 if Denotes_Discriminant (Node (D)) then
1029 return Build_Component_Subtype
1030 (Build_Discriminal_Record_Constraint, Loc, T);
1037 -- If none of the above, the actual and nominal subtypes are the same
1040 end Build_Discriminal_Subtype_Of_Component;
1042 ------------------------------
1043 -- Build_Elaboration_Entity --
1044 ------------------------------
1046 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1047 Loc : constant Source_Ptr := Sloc (N);
1049 Elab_Ent : Entity_Id;
1051 procedure Set_Package_Name (Ent : Entity_Id);
1052 -- Given an entity, sets the fully qualified name of the entity in
1053 -- Name_Buffer, with components separated by double underscores. This
1054 -- is a recursive routine that climbs the scope chain to Standard.
1056 ----------------------
1057 -- Set_Package_Name --
1058 ----------------------
1060 procedure Set_Package_Name (Ent : Entity_Id) is
1062 if Scope (Ent) /= Standard_Standard then
1063 Set_Package_Name (Scope (Ent));
1066 Nam : constant String := Get_Name_String (Chars (Ent));
1068 Name_Buffer (Name_Len + 1) := '_';
1069 Name_Buffer (Name_Len + 2) := '_';
1070 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1071 Name_Len := Name_Len + Nam'Length + 2;
1075 Get_Name_String (Chars (Ent));
1077 end Set_Package_Name;
1079 -- Start of processing for Build_Elaboration_Entity
1082 -- Ignore if already constructed
1084 if Present (Elaboration_Entity (Spec_Id)) then
1088 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1089 -- name with dots replaced by double underscore. We have to manually
1090 -- construct this name, since it will be elaborated in the outer scope,
1091 -- and thus will not have the unit name automatically prepended.
1093 Set_Package_Name (Spec_Id);
1094 Add_Str_To_Name_Buffer ("_E");
1096 -- Create elaboration counter
1098 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1099 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1102 Make_Object_Declaration (Loc,
1103 Defining_Identifier => Elab_Ent,
1104 Object_Definition =>
1105 New_Occurrence_Of (Standard_Short_Integer, Loc),
1106 Expression => Make_Integer_Literal (Loc, Uint_0));
1108 Push_Scope (Standard_Standard);
1109 Add_Global_Declaration (Decl);
1112 -- Reset True_Constant indication, since we will indeed assign a value
1113 -- to the variable in the binder main. We also kill the Current_Value
1114 -- and Last_Assignment fields for the same reason.
1116 Set_Is_True_Constant (Elab_Ent, False);
1117 Set_Current_Value (Elab_Ent, Empty);
1118 Set_Last_Assignment (Elab_Ent, Empty);
1120 -- We do not want any further qualification of the name (if we did not
1121 -- do this, we would pick up the name of the generic package in the case
1122 -- of a library level generic instantiation).
1124 Set_Has_Qualified_Name (Elab_Ent);
1125 Set_Has_Fully_Qualified_Name (Elab_Ent);
1126 end Build_Elaboration_Entity;
1128 --------------------------------
1129 -- Build_Explicit_Dereference --
1130 --------------------------------
1132 procedure Build_Explicit_Dereference
1136 Loc : constant Source_Ptr := Sloc (Expr);
1139 -- An entity of a type with a reference aspect is overloaded with
1140 -- both interpretations: with and without the dereference. Now that
1141 -- the dereference is made explicit, set the type of the node properly,
1142 -- to prevent anomalies in the backend. Same if the expression is an
1143 -- overloaded function call whose return type has a reference aspect.
1145 if Is_Entity_Name (Expr) then
1146 Set_Etype (Expr, Etype (Entity (Expr)));
1148 elsif Nkind (Expr) = N_Function_Call then
1149 Set_Etype (Expr, Etype (Name (Expr)));
1152 Set_Is_Overloaded (Expr, False);
1154 Make_Explicit_Dereference (Loc,
1156 Make_Selected_Component (Loc,
1157 Prefix => Relocate_Node (Expr),
1158 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1159 Set_Etype (Prefix (Expr), Etype (Disc));
1160 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1161 end Build_Explicit_Dereference;
1163 -----------------------------------
1164 -- Cannot_Raise_Constraint_Error --
1165 -----------------------------------
1167 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1169 if Compile_Time_Known_Value (Expr) then
1172 elsif Do_Range_Check (Expr) then
1175 elsif Raises_Constraint_Error (Expr) then
1179 case Nkind (Expr) is
1180 when N_Identifier =>
1183 when N_Expanded_Name =>
1186 when N_Selected_Component =>
1187 return not Do_Discriminant_Check (Expr);
1189 when N_Attribute_Reference =>
1190 if Do_Overflow_Check (Expr) then
1193 elsif No (Expressions (Expr)) then
1201 N := First (Expressions (Expr));
1202 while Present (N) loop
1203 if Cannot_Raise_Constraint_Error (N) then
1214 when N_Type_Conversion =>
1215 if Do_Overflow_Check (Expr)
1216 or else Do_Length_Check (Expr)
1217 or else Do_Tag_Check (Expr)
1221 return Cannot_Raise_Constraint_Error (Expression (Expr));
1224 when N_Unchecked_Type_Conversion =>
1225 return Cannot_Raise_Constraint_Error (Expression (Expr));
1228 if Do_Overflow_Check (Expr) then
1231 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1238 if Do_Division_Check (Expr)
1239 or else Do_Overflow_Check (Expr)
1244 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1246 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1265 N_Op_Shift_Right_Arithmetic |
1269 if Do_Overflow_Check (Expr) then
1273 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1275 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1282 end Cannot_Raise_Constraint_Error;
1284 -----------------------------------------
1285 -- Check_Dynamically_Tagged_Expression --
1286 -----------------------------------------
1288 procedure Check_Dynamically_Tagged_Expression
1291 Related_Nod : Node_Id)
1294 pragma Assert (Is_Tagged_Type (Typ));
1296 -- In order to avoid spurious errors when analyzing the expanded code,
1297 -- this check is done only for nodes that come from source and for
1298 -- actuals of generic instantiations.
1300 if (Comes_From_Source (Related_Nod)
1301 or else In_Generic_Actual (Expr))
1302 and then (Is_Class_Wide_Type (Etype (Expr))
1303 or else Is_Dynamically_Tagged (Expr))
1304 and then Is_Tagged_Type (Typ)
1305 and then not Is_Class_Wide_Type (Typ)
1307 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1309 end Check_Dynamically_Tagged_Expression;
1311 -----------------------------------------------
1312 -- Check_Expression_Against_Static_Predicate --
1313 -----------------------------------------------
1315 procedure Check_Expression_Against_Static_Predicate
1320 -- When the predicate is static and the value of the expression is known
1321 -- at compile time, evaluate the predicate check. A type is non-static
1322 -- when it has aspect Dynamic_Predicate.
1324 if Compile_Time_Known_Value (Expr)
1325 and then Has_Predicates (Typ)
1326 and then Present (Static_Predicate (Typ))
1327 and then not Has_Dynamic_Predicate_Aspect (Typ)
1329 -- Either -gnatc is enabled or the expression is ok
1331 if Operating_Mode < Generate_Code
1332 or else Eval_Static_Predicate_Check (Expr, Typ)
1336 -- The expression is prohibited by the static predicate
1340 ("?static expression fails static predicate check on &",
1344 end Check_Expression_Against_Static_Predicate;
1346 --------------------------
1347 -- Check_Fully_Declared --
1348 --------------------------
1350 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1352 if Ekind (T) = E_Incomplete_Type then
1354 -- Ada 2005 (AI-50217): If the type is available through a limited
1355 -- with_clause, verify that its full view has been analyzed.
1357 if From_With_Type (T)
1358 and then Present (Non_Limited_View (T))
1359 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1361 -- The non-limited view is fully declared
1366 ("premature usage of incomplete}", N, First_Subtype (T));
1369 -- Need comments for these tests ???
1371 elsif Has_Private_Component (T)
1372 and then not Is_Generic_Type (Root_Type (T))
1373 and then not In_Spec_Expression
1375 -- Special case: if T is the anonymous type created for a single
1376 -- task or protected object, use the name of the source object.
1378 if Is_Concurrent_Type (T)
1379 and then not Comes_From_Source (T)
1380 and then Nkind (N) = N_Object_Declaration
1382 Error_Msg_NE ("type of& has incomplete component", N,
1383 Defining_Identifier (N));
1387 ("premature usage of incomplete}", N, First_Subtype (T));
1390 end Check_Fully_Declared;
1392 -------------------------------------
1393 -- Check_Function_Writable_Actuals --
1394 -------------------------------------
1396 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1397 Writable_Actuals_List : Elist_Id := No_Elist;
1398 Identifiers_List : Elist_Id := No_Elist;
1399 Error_Node : Node_Id := Empty;
1401 procedure Collect_Identifiers (N : Node_Id);
1402 -- In a single traversal of subtree N collect in Writable_Actuals_List
1403 -- all the actuals of functions with writable actuals, and in the list
1404 -- Identifiers_List collect all the identifiers that are not actuals of
1405 -- functions with writable actuals. If a writable actual is referenced
1406 -- twice as writable actual then Error_Node is set to reference its
1407 -- second occurrence, the error is reported, and the tree traversal
1410 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1411 -- Return the entity associated with the function call
1413 procedure Preanalyze_Without_Errors (N : Node_Id);
1414 -- Preanalyze N without reporting errors. Very dubious, you can't just
1415 -- go analyzing things more than once???
1417 -------------------------
1418 -- Collect_Identifiers --
1419 -------------------------
1421 procedure Collect_Identifiers (N : Node_Id) is
1423 function Check_Node (N : Node_Id) return Traverse_Result;
1424 -- Process a single node during the tree traversal to collect the
1425 -- writable actuals of functions and all the identifiers which are
1426 -- not writable actuals of functions.
1428 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1429 -- Returns True if List has a node whose Entity is Entity (N)
1431 -------------------------
1432 -- Check_Function_Call --
1433 -------------------------
1435 function Check_Node (N : Node_Id) return Traverse_Result is
1436 Is_Writable_Actual : Boolean := False;
1439 if Nkind (N) = N_Identifier then
1441 -- No analysis possible if the entity is not decorated
1443 if No (Entity (N)) then
1446 -- Don't collect identifiers of packages, called functions, etc
1448 elsif Ekind_In (Entity (N), E_Package,
1455 -- Analyze if N is a writable actual of a function
1457 elsif Nkind (Parent (N)) = N_Function_Call then
1459 Call : constant Node_Id := Parent (N);
1460 Id : constant Entity_Id := Get_Function_Id (Call);
1465 Formal := First_Formal (Id);
1466 Actual := First_Actual (Call);
1467 while Present (Actual) and then Present (Formal) loop
1469 if Ekind_In (Formal, E_Out_Parameter,
1472 Is_Writable_Actual := True;
1478 Next_Formal (Formal);
1479 Next_Actual (Actual);
1484 if Is_Writable_Actual then
1485 if Contains (Writable_Actuals_List, N) then
1487 ("conflict of writable function parameter in "
1488 & "construct with arbitrary order of evaluation", N);
1493 if Writable_Actuals_List = No_Elist then
1494 Writable_Actuals_List := New_Elmt_List;
1497 Append_Elmt (N, Writable_Actuals_List);
1499 if Identifiers_List = No_Elist then
1500 Identifiers_List := New_Elmt_List;
1503 Append_Unique_Elmt (N, Identifiers_List);
1516 N : Node_Id) return Boolean
1518 pragma Assert (Nkind (N) in N_Has_Entity);
1523 if List = No_Elist then
1527 Elmt := First_Elmt (List);
1528 while Present (Elmt) loop
1529 if Entity (Node (Elmt)) = Entity (N) then
1543 procedure Do_Traversal is new Traverse_Proc (Check_Node);
1544 -- The traversal procedure
1546 -- Start of processing for Collect_Identifiers
1549 if Present (Error_Node) then
1553 if Nkind (N) in N_Subexpr
1554 and then Is_Static_Expression (N)
1560 end Collect_Identifiers;
1562 ---------------------
1563 -- Get_Function_Id --
1564 ---------------------
1566 function Get_Function_Id (Call : Node_Id) return Entity_Id is
1567 Nam : constant Node_Id := Name (Call);
1571 if Nkind (Nam) = N_Explicit_Dereference then
1573 pragma Assert (Ekind (Id) = E_Subprogram_Type);
1575 elsif Nkind (Nam) = N_Selected_Component then
1576 Id := Entity (Selector_Name (Nam));
1578 elsif Nkind (Nam) = N_Indexed_Component then
1579 Id := Entity (Selector_Name (Prefix (Nam)));
1586 end Get_Function_Id;
1588 ---------------------------
1589 -- Preanalyze_Expression --
1590 ---------------------------
1592 procedure Preanalyze_Without_Errors (N : Node_Id) is
1593 Status : constant Boolean := Get_Ignore_Errors;
1595 Set_Ignore_Errors (True);
1597 Set_Ignore_Errors (Status);
1598 end Preanalyze_Without_Errors;
1600 -- Start of processing for Check_Function_Writable_Actuals
1603 if Ada_Version < Ada_2012
1604 or else (not (Nkind (N) in N_Op)
1605 and then not (Nkind (N) in N_Membership_Test)
1606 and then not Nkind_In (N, N_Range,
1608 N_Extension_Aggregate,
1609 N_Full_Type_Declaration,
1611 N_Procedure_Call_Statement,
1612 N_Entry_Call_Statement))
1613 or else (Nkind (N) = N_Full_Type_Declaration
1614 and then not Is_Record_Type (Defining_Identifier (N)))
1619 -- If a construct C has two or more direct constituents that are names
1620 -- or expressions whose evaluation may occur in an arbitrary order, at
1621 -- least one of which contains a function call with an in out or out
1622 -- parameter, then the construct is legal only if: for each name N that
1623 -- is passed as a parameter of mode in out or out to some inner function
1624 -- call C2 (not including the construct C itself), there is no other
1625 -- name anywhere within a direct constituent of the construct C other
1626 -- than the one containing C2, that is known to refer to the same
1627 -- object (RM 6.4.1(6.17/3)).
1631 Collect_Identifiers (Low_Bound (N));
1632 Collect_Identifiers (High_Bound (N));
1634 when N_Op | N_Membership_Test =>
1638 Collect_Identifiers (Left_Opnd (N));
1640 if Present (Right_Opnd (N)) then
1641 Collect_Identifiers (Right_Opnd (N));
1644 if Nkind_In (N, N_In, N_Not_In)
1645 and then Present (Alternatives (N))
1647 Expr := First (Alternatives (N));
1648 while Present (Expr) loop
1649 Collect_Identifiers (Expr);
1656 when N_Full_Type_Declaration =>
1658 function Get_Record_Part (N : Node_Id) return Node_Id;
1659 -- Return the record part of this record type definition
1661 function Get_Record_Part (N : Node_Id) return Node_Id is
1662 Type_Def : constant Node_Id := Type_Definition (N);
1664 if Nkind (Type_Def) = N_Derived_Type_Definition then
1665 return Record_Extension_Part (Type_Def);
1669 end Get_Record_Part;
1672 Def_Id : Entity_Id := Defining_Identifier (N);
1673 Rec : Node_Id := Get_Record_Part (N);
1676 -- No need to perform any analysis if the record has no
1679 if No (Rec) or else No (Component_List (Rec)) then
1683 -- Collect the identifiers starting from the deepest
1684 -- derivation. Done to report the error in the deepest
1688 if Present (Component_List (Rec)) then
1689 Comp := First (Component_Items (Component_List (Rec)));
1690 while Present (Comp) loop
1691 if Nkind (Comp) = N_Component_Declaration
1692 and then Present (Expression (Comp))
1694 Collect_Identifiers (Expression (Comp));
1701 exit when No (Underlying_Type (Etype (Def_Id)))
1702 or else Base_Type (Underlying_Type (Etype (Def_Id)))
1705 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
1706 Rec := Get_Record_Part (Parent (Def_Id));
1710 when N_Subprogram_Call |
1711 N_Entry_Call_Statement =>
1713 Id : constant Entity_Id := Get_Function_Id (N);
1718 Formal := First_Formal (Id);
1719 Actual := First_Actual (N);
1720 while Present (Actual) and then Present (Formal) loop
1721 if Ekind_In (Formal, E_Out_Parameter,
1724 Collect_Identifiers (Actual);
1727 Next_Formal (Formal);
1728 Next_Actual (Actual);
1733 N_Extension_Aggregate =>
1737 Comp_Expr : Node_Id;
1740 -- Handle the N_Others_Choice of array aggregates with static
1741 -- bounds. There is no need to perform this analysis in
1742 -- aggregates without static bounds since we cannot evaluate
1743 -- if the N_Others_Choice covers several elements. There is
1744 -- no need to handle the N_Others choice of record aggregates
1745 -- since at this stage it has been already expanded by
1746 -- Resolve_Record_Aggregate.
1748 if Is_Array_Type (Etype (N))
1749 and then Nkind (N) = N_Aggregate
1750 and then Present (Aggregate_Bounds (N))
1751 and then Compile_Time_Known_Bounds (Etype (N))
1752 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
1753 > Expr_Value (Low_Bound (Aggregate_Bounds (N)))
1756 Count_Components : Uint := Uint_0;
1757 Num_Components : Uint;
1758 Others_Assoc : Node_Id;
1759 Others_Choice : Node_Id := Empty;
1760 Others_Box_Present : Boolean := False;
1763 -- Count positional associations
1765 if Present (Expressions (N)) then
1766 Comp_Expr := First (Expressions (N));
1767 while Present (Comp_Expr) loop
1768 Count_Components := Count_Components + 1;
1773 -- Count the rest of elements and locate the N_Others
1776 Assoc := First (Component_Associations (N));
1777 while Present (Assoc) loop
1778 Choice := First (Choices (Assoc));
1779 while Present (Choice) loop
1780 if Nkind (Choice) = N_Others_Choice then
1781 Others_Assoc := Assoc;
1782 Others_Choice := Choice;
1783 Others_Box_Present := Box_Present (Assoc);
1785 -- Count several components
1787 elsif Nkind_In (Choice, N_Range,
1788 N_Subtype_Indication)
1789 or else (Is_Entity_Name (Choice)
1790 and then Is_Type (Entity (Choice)))
1795 Get_Index_Bounds (Choice, L, H);
1797 (Compile_Time_Known_Value (L)
1798 and then Compile_Time_Known_Value (H));
1801 + Expr_Value (H) - Expr_Value (L) + 1;
1804 -- Count single component. No other case available
1805 -- since we are handling an aggregate with static
1809 pragma Assert (Is_Static_Expression (Choice)
1810 or else Nkind (Choice) = N_Identifier
1811 or else Nkind (Choice) = N_Integer_Literal);
1813 Count_Components := Count_Components + 1;
1823 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
1824 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
1826 pragma Assert (Count_Components <= Num_Components);
1828 -- Handle the N_Others choice if it covers several
1831 if Present (Others_Choice)
1832 and then (Num_Components - Count_Components) > 1
1834 if not Others_Box_Present then
1836 -- At this stage, if expansion is active, the
1837 -- expression of the others choice has not been
1838 -- analyzed. Hence we generate a duplicate and
1839 -- we analyze it silently to have available the
1840 -- minimum decoration required to collect the
1843 if not Expander_Active then
1844 Comp_Expr := Expression (Others_Assoc);
1847 New_Copy_Tree (Expression (Others_Assoc));
1848 Preanalyze_Without_Errors (Comp_Expr);
1851 Collect_Identifiers (Comp_Expr);
1853 if Writable_Actuals_List /= No_Elist then
1855 -- As suggested by Robert, at current stage we
1856 -- report occurrences of this case as warnings.
1859 ("conflict of writable function parameter in "
1860 & "construct with arbitrary order of "
1862 Node (First_Elmt (Writable_Actuals_List)));
1869 -- Handle ancestor part of extension aggregates
1871 if Nkind (N) = N_Extension_Aggregate then
1872 Collect_Identifiers (Ancestor_Part (N));
1875 -- Handle positional associations
1877 if Present (Expressions (N)) then
1878 Comp_Expr := First (Expressions (N));
1879 while Present (Comp_Expr) loop
1880 if not Is_Static_Expression (Comp_Expr) then
1881 Collect_Identifiers (Comp_Expr);
1888 -- Handle discrete associations
1890 if Present (Component_Associations (N)) then
1891 Assoc := First (Component_Associations (N));
1892 while Present (Assoc) loop
1894 if not Box_Present (Assoc) then
1895 Choice := First (Choices (Assoc));
1896 while Present (Choice) loop
1898 -- For now we skip discriminants since it requires
1899 -- performing the analysis in two phases: first one
1900 -- analyzing discriminants and second one analyzing
1901 -- the rest of components since discriminants are
1902 -- evaluated prior to components: too much extra
1903 -- work to detect a corner case???
1905 if Nkind (Choice) in N_Has_Entity
1906 and then Present (Entity (Choice))
1907 and then Ekind (Entity (Choice)) = E_Discriminant
1911 elsif Box_Present (Assoc) then
1915 if not Analyzed (Expression (Assoc)) then
1917 New_Copy_Tree (Expression (Assoc));
1918 Set_Parent (Comp_Expr, Parent (N));
1919 Preanalyze_Without_Errors (Comp_Expr);
1921 Comp_Expr := Expression (Assoc);
1924 Collect_Identifiers (Comp_Expr);
1940 -- No further action needed if we already reported an error
1942 if Present (Error_Node) then
1946 -- Check if some writable argument of a function is referenced
1948 if Writable_Actuals_List /= No_Elist
1949 and then Identifiers_List /= No_Elist
1956 Elmt_1 := First_Elmt (Writable_Actuals_List);
1957 while Present (Elmt_1) loop
1958 Elmt_2 := First_Elmt (Identifiers_List);
1959 while Present (Elmt_2) loop
1960 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
1962 ("conflict of writable function parameter in construct "
1963 & "with arbitrary order of evaluation",
1974 end Check_Function_Writable_Actuals;
1976 --------------------------------
1977 -- Check_Implicit_Dereference --
1978 --------------------------------
1980 procedure Check_Implicit_Dereference (Nam : Node_Id; Typ : Entity_Id) is
1985 if Ada_Version < Ada_2012
1986 or else not Has_Implicit_Dereference (Base_Type (Typ))
1990 elsif not Comes_From_Source (Nam) then
1993 elsif Is_Entity_Name (Nam)
1994 and then Is_Type (Entity (Nam))
1999 Disc := First_Discriminant (Typ);
2000 while Present (Disc) loop
2001 if Has_Implicit_Dereference (Disc) then
2002 Desig := Designated_Type (Etype (Disc));
2003 Add_One_Interp (Nam, Disc, Desig);
2007 Next_Discriminant (Disc);
2010 end Check_Implicit_Dereference;
2012 ----------------------------------
2013 -- Check_Internal_Protected_Use --
2014 ----------------------------------
2016 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2022 while Present (S) loop
2023 if S = Standard_Standard then
2026 elsif Ekind (S) = E_Function
2027 and then Ekind (Scope (S)) = E_Protected_Type
2036 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2037 if Nkind (N) = N_Subprogram_Renaming_Declaration then
2039 ("within protected function cannot use protected "
2040 & "procedure in renaming or as generic actual", N);
2042 elsif Nkind (N) = N_Attribute_Reference then
2044 ("within protected function cannot take access of "
2045 & " protected procedure", N);
2049 ("within protected function, protected object is constant", N);
2051 ("\cannot call operation that may modify it", N);
2054 end Check_Internal_Protected_Use;
2056 ---------------------------------------
2057 -- Check_Later_Vs_Basic_Declarations --
2058 ---------------------------------------
2060 procedure Check_Later_Vs_Basic_Declarations
2062 During_Parsing : Boolean)
2064 Body_Sloc : Source_Ptr;
2067 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2068 -- Return whether Decl is considered as a declarative item.
2069 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2070 -- When During_Parsing is False, the semantics of SPARK is followed.
2072 -------------------------------
2073 -- Is_Later_Declarative_Item --
2074 -------------------------------
2076 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2078 if Nkind (Decl) in N_Later_Decl_Item then
2081 elsif Nkind (Decl) = N_Pragma then
2084 elsif During_Parsing then
2087 -- In SPARK, a package declaration is not considered as a later
2088 -- declarative item.
2090 elsif Nkind (Decl) = N_Package_Declaration then
2093 -- In SPARK, a renaming is considered as a later declarative item
2095 elsif Nkind (Decl) in N_Renaming_Declaration then
2101 end Is_Later_Declarative_Item;
2103 -- Start of Check_Later_Vs_Basic_Declarations
2106 Decl := First (Decls);
2108 -- Loop through sequence of basic declarative items
2110 Outer : while Present (Decl) loop
2111 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2112 and then Nkind (Decl) not in N_Body_Stub
2116 -- Once a body is encountered, we only allow later declarative
2117 -- items. The inner loop checks the rest of the list.
2120 Body_Sloc := Sloc (Decl);
2122 Inner : while Present (Decl) loop
2123 if not Is_Later_Declarative_Item (Decl) then
2124 if During_Parsing then
2125 if Ada_Version = Ada_83 then
2126 Error_Msg_Sloc := Body_Sloc;
2128 ("(Ada 83) decl cannot appear after body#", Decl);
2131 Error_Msg_Sloc := Body_Sloc;
2132 Check_SPARK_Restriction
2133 ("decl cannot appear after body#", Decl);
2141 end Check_Later_Vs_Basic_Declarations;
2143 -------------------------
2144 -- Check_Nested_Access --
2145 -------------------------
2147 procedure Check_Nested_Access (Ent : Entity_Id) is
2148 Scop : constant Entity_Id := Current_Scope;
2149 Current_Subp : Entity_Id;
2150 Enclosing : Entity_Id;
2153 -- Currently only enabled for VM back-ends for efficiency, should we
2154 -- enable it more systematically ???
2156 -- Check for Is_Imported needs commenting below ???
2158 if VM_Target /= No_VM
2159 and then (Ekind (Ent) = E_Variable
2161 Ekind (Ent) = E_Constant
2163 Ekind (Ent) = E_Loop_Parameter)
2164 and then Scope (Ent) /= Empty
2165 and then not Is_Library_Level_Entity (Ent)
2166 and then not Is_Imported (Ent)
2168 if Is_Subprogram (Scop)
2169 or else Is_Generic_Subprogram (Scop)
2170 or else Is_Entry (Scop)
2172 Current_Subp := Scop;
2174 Current_Subp := Current_Subprogram;
2177 Enclosing := Enclosing_Subprogram (Ent);
2179 if Enclosing /= Empty
2180 and then Enclosing /= Current_Subp
2182 Set_Has_Up_Level_Access (Ent, True);
2185 end Check_Nested_Access;
2187 ---------------------------
2188 -- Check_No_Hidden_State --
2189 ---------------------------
2191 procedure Check_No_Hidden_State (Id : Entity_Id) is
2192 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2193 -- Determine whether the entity of a package denoted by Pkg has a null
2196 -----------------------------
2197 -- Has_Null_Abstract_State --
2198 -----------------------------
2200 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2201 States : constant Elist_Id := Abstract_States (Pkg);
2204 -- Check first available state of related package. A null abstract
2205 -- state always appears as the sole element of the state list.
2209 and then Is_Null_State (Node (First_Elmt (States)));
2210 end Has_Null_Abstract_State;
2214 Context : Entity_Id := Empty;
2215 Not_Visible : Boolean := False;
2218 -- Start of processing for Check_No_Hidden_State
2221 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2223 -- Find the proper context where the object or state appears
2226 while Present (Scop) loop
2229 -- Keep track of the context's visibility
2231 Not_Visible := Not_Visible or else In_Private_Part (Context);
2233 -- Prevent the search from going too far
2235 if Context = Standard_Standard then
2238 -- Objects and states that appear immediately within a subprogram or
2239 -- inside a construct nested within a subprogram do not introduce a
2240 -- hidden state. They behave as local variable declarations.
2242 elsif Is_Subprogram (Context) then
2245 -- When examining a package body, use the entity of the spec as it
2246 -- carries the abstract state declarations.
2248 elsif Ekind (Context) = E_Package_Body then
2249 Context := Spec_Entity (Context);
2252 -- Stop the traversal when a package subject to a null abstract state
2255 if Ekind_In (Context, E_Generic_Package, E_Package)
2256 and then Has_Null_Abstract_State (Context)
2261 Scop := Scope (Scop);
2264 -- At this point we know that there is at least one package with a null
2265 -- abstract state in visibility. Emit an error message unconditionally
2266 -- if the entity being processed is a state because the placement of the
2267 -- related package is irrelevant. This is not the case for objects as
2268 -- the intermediate context matters.
2270 if Present (Context)
2271 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2273 Error_Msg_N ("cannot introduce hidden state &", Id);
2274 Error_Msg_NE ("\package & has null abstract state", Id, Context);
2276 end Check_No_Hidden_State;
2278 ------------------------------------------
2279 -- Check_Potentially_Blocking_Operation --
2280 ------------------------------------------
2282 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
2286 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2287 -- When pragma Detect_Blocking is active, the run time will raise
2288 -- Program_Error. Here we only issue a warning, since we generally
2289 -- support the use of potentially blocking operations in the absence
2292 -- Indirect blocking through a subprogram call cannot be diagnosed
2293 -- statically without interprocedural analysis, so we do not attempt
2296 S := Scope (Current_Scope);
2297 while Present (S) and then S /= Standard_Standard loop
2298 if Is_Protected_Type (S) then
2300 ("potentially blocking operation in protected operation??", N);
2306 end Check_Potentially_Blocking_Operation;
2308 ------------------------------
2309 -- Check_Unprotected_Access --
2310 ------------------------------
2312 procedure Check_Unprotected_Access
2316 Cont_Encl_Typ : Entity_Id;
2317 Pref_Encl_Typ : Entity_Id;
2319 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
2320 -- Check whether Obj is a private component of a protected object.
2321 -- Return the protected type where the component resides, Empty
2324 function Is_Public_Operation return Boolean;
2325 -- Verify that the enclosing operation is callable from outside the
2326 -- protected object, to minimize false positives.
2328 ------------------------------
2329 -- Enclosing_Protected_Type --
2330 ------------------------------
2332 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
2334 if Is_Entity_Name (Obj) then
2336 Ent : Entity_Id := Entity (Obj);
2339 -- The object can be a renaming of a private component, use
2340 -- the original record component.
2342 if Is_Prival (Ent) then
2343 Ent := Prival_Link (Ent);
2346 if Is_Protected_Type (Scope (Ent)) then
2352 -- For indexed and selected components, recursively check the prefix
2354 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
2355 return Enclosing_Protected_Type (Prefix (Obj));
2357 -- The object does not denote a protected component
2362 end Enclosing_Protected_Type;
2364 -------------------------
2365 -- Is_Public_Operation --
2366 -------------------------
2368 function Is_Public_Operation return Boolean is
2375 and then S /= Pref_Encl_Typ
2377 if Scope (S) = Pref_Encl_Typ then
2378 E := First_Entity (Pref_Encl_Typ);
2380 and then E /= First_Private_Entity (Pref_Encl_Typ)
2393 end Is_Public_Operation;
2395 -- Start of processing for Check_Unprotected_Access
2398 if Nkind (Expr) = N_Attribute_Reference
2399 and then Attribute_Name (Expr) = Name_Unchecked_Access
2401 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
2402 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
2404 -- Check whether we are trying to export a protected component to a
2405 -- context with an equal or lower access level.
2407 if Present (Pref_Encl_Typ)
2408 and then No (Cont_Encl_Typ)
2409 and then Is_Public_Operation
2410 and then Scope_Depth (Pref_Encl_Typ) >=
2411 Object_Access_Level (Context)
2414 ("??possible unprotected access to protected data", Expr);
2417 end Check_Unprotected_Access;
2423 procedure Check_VMS (Construct : Node_Id) is
2425 if not OpenVMS_On_Target then
2427 ("this construct is allowed only in Open'V'M'S", Construct);
2431 ------------------------
2432 -- Collect_Interfaces --
2433 ------------------------
2435 procedure Collect_Interfaces
2437 Ifaces_List : out Elist_Id;
2438 Exclude_Parents : Boolean := False;
2439 Use_Full_View : Boolean := True)
2441 procedure Collect (Typ : Entity_Id);
2442 -- Subsidiary subprogram used to traverse the whole list
2443 -- of directly and indirectly implemented interfaces
2449 procedure Collect (Typ : Entity_Id) is
2450 Ancestor : Entity_Id;
2458 -- Handle private types
2461 and then Is_Private_Type (Typ)
2462 and then Present (Full_View (Typ))
2464 Full_T := Full_View (Typ);
2467 -- Include the ancestor if we are generating the whole list of
2468 -- abstract interfaces.
2470 if Etype (Full_T) /= Typ
2472 -- Protect the frontend against wrong sources. For example:
2475 -- type A is tagged null record;
2476 -- type B is new A with private;
2477 -- type C is new A with private;
2479 -- type B is new C with null record;
2480 -- type C is new B with null record;
2483 and then Etype (Full_T) /= T
2485 Ancestor := Etype (Full_T);
2488 if Is_Interface (Ancestor)
2489 and then not Exclude_Parents
2491 Append_Unique_Elmt (Ancestor, Ifaces_List);
2495 -- Traverse the graph of ancestor interfaces
2497 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
2498 Id := First (Abstract_Interface_List (Full_T));
2499 while Present (Id) loop
2500 Iface := Etype (Id);
2502 -- Protect against wrong uses. For example:
2503 -- type I is interface;
2504 -- type O is tagged null record;
2505 -- type Wrong is new I and O with null record; -- ERROR
2507 if Is_Interface (Iface) then
2509 and then Etype (T) /= T
2510 and then Interface_Present_In_Ancestor (Etype (T), Iface)
2515 Append_Unique_Elmt (Iface, Ifaces_List);
2524 -- Start of processing for Collect_Interfaces
2527 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
2528 Ifaces_List := New_Elmt_List;
2530 end Collect_Interfaces;
2532 ----------------------------------
2533 -- Collect_Interface_Components --
2534 ----------------------------------
2536 procedure Collect_Interface_Components
2537 (Tagged_Type : Entity_Id;
2538 Components_List : out Elist_Id)
2540 procedure Collect (Typ : Entity_Id);
2541 -- Subsidiary subprogram used to climb to the parents
2547 procedure Collect (Typ : Entity_Id) is
2548 Tag_Comp : Entity_Id;
2549 Parent_Typ : Entity_Id;
2552 -- Handle private types
2554 if Present (Full_View (Etype (Typ))) then
2555 Parent_Typ := Full_View (Etype (Typ));
2557 Parent_Typ := Etype (Typ);
2560 if Parent_Typ /= Typ
2562 -- Protect the frontend against wrong sources. For example:
2565 -- type A is tagged null record;
2566 -- type B is new A with private;
2567 -- type C is new A with private;
2569 -- type B is new C with null record;
2570 -- type C is new B with null record;
2573 and then Parent_Typ /= Tagged_Type
2575 Collect (Parent_Typ);
2578 -- Collect the components containing tags of secondary dispatch
2581 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
2582 while Present (Tag_Comp) loop
2583 pragma Assert (Present (Related_Type (Tag_Comp)));
2584 Append_Elmt (Tag_Comp, Components_List);
2586 Tag_Comp := Next_Tag_Component (Tag_Comp);
2590 -- Start of processing for Collect_Interface_Components
2593 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
2594 and then Is_Tagged_Type (Tagged_Type));
2596 Components_List := New_Elmt_List;
2597 Collect (Tagged_Type);
2598 end Collect_Interface_Components;
2600 -----------------------------
2601 -- Collect_Interfaces_Info --
2602 -----------------------------
2604 procedure Collect_Interfaces_Info
2606 Ifaces_List : out Elist_Id;
2607 Components_List : out Elist_Id;
2608 Tags_List : out Elist_Id)
2610 Comps_List : Elist_Id;
2611 Comp_Elmt : Elmt_Id;
2612 Comp_Iface : Entity_Id;
2613 Iface_Elmt : Elmt_Id;
2616 function Search_Tag (Iface : Entity_Id) return Entity_Id;
2617 -- Search for the secondary tag associated with the interface type
2618 -- Iface that is implemented by T.
2624 function Search_Tag (Iface : Entity_Id) return Entity_Id is
2627 if not Is_CPP_Class (T) then
2628 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
2630 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
2634 and then Is_Tag (Node (ADT))
2635 and then Related_Type (Node (ADT)) /= Iface
2637 -- Skip secondary dispatch table referencing thunks to user
2638 -- defined primitives covered by this interface.
2640 pragma Assert (Has_Suffix (Node (ADT), 'P'));
2643 -- Skip secondary dispatch tables of Ada types
2645 if not Is_CPP_Class (T) then
2647 -- Skip secondary dispatch table referencing thunks to
2648 -- predefined primitives.
2650 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
2653 -- Skip secondary dispatch table referencing user-defined
2654 -- primitives covered by this interface.
2656 pragma Assert (Has_Suffix (Node (ADT), 'D'));
2659 -- Skip secondary dispatch table referencing predefined
2662 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
2667 pragma Assert (Is_Tag (Node (ADT)));
2671 -- Start of processing for Collect_Interfaces_Info
2674 Collect_Interfaces (T, Ifaces_List);
2675 Collect_Interface_Components (T, Comps_List);
2677 -- Search for the record component and tag associated with each
2678 -- interface type of T.
2680 Components_List := New_Elmt_List;
2681 Tags_List := New_Elmt_List;
2683 Iface_Elmt := First_Elmt (Ifaces_List);
2684 while Present (Iface_Elmt) loop
2685 Iface := Node (Iface_Elmt);
2687 -- Associate the primary tag component and the primary dispatch table
2688 -- with all the interfaces that are parents of T
2690 if Is_Ancestor (Iface, T, Use_Full_View => True) then
2691 Append_Elmt (First_Tag_Component (T), Components_List);
2692 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
2694 -- Otherwise search for the tag component and secondary dispatch
2698 Comp_Elmt := First_Elmt (Comps_List);
2699 while Present (Comp_Elmt) loop
2700 Comp_Iface := Related_Type (Node (Comp_Elmt));
2702 if Comp_Iface = Iface
2703 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
2705 Append_Elmt (Node (Comp_Elmt), Components_List);
2706 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
2710 Next_Elmt (Comp_Elmt);
2712 pragma Assert (Present (Comp_Elmt));
2715 Next_Elmt (Iface_Elmt);
2717 end Collect_Interfaces_Info;
2719 ---------------------
2720 -- Collect_Parents --
2721 ---------------------
2723 procedure Collect_Parents
2725 List : out Elist_Id;
2726 Use_Full_View : Boolean := True)
2728 Current_Typ : Entity_Id := T;
2729 Parent_Typ : Entity_Id;
2732 List := New_Elmt_List;
2734 -- No action if the if the type has no parents
2736 if T = Etype (T) then
2741 Parent_Typ := Etype (Current_Typ);
2743 if Is_Private_Type (Parent_Typ)
2744 and then Present (Full_View (Parent_Typ))
2745 and then Use_Full_View
2747 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2750 Append_Elmt (Parent_Typ, List);
2752 exit when Parent_Typ = Current_Typ;
2753 Current_Typ := Parent_Typ;
2755 end Collect_Parents;
2757 ----------------------------------
2758 -- Collect_Primitive_Operations --
2759 ----------------------------------
2761 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
2762 B_Type : constant Entity_Id := Base_Type (T);
2763 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
2764 B_Scope : Entity_Id := Scope (B_Type);
2768 Is_Type_In_Pkg : Boolean;
2769 Formal_Derived : Boolean := False;
2772 function Match (E : Entity_Id) return Boolean;
2773 -- True if E's base type is B_Type, or E is of an anonymous access type
2774 -- and the base type of its designated type is B_Type.
2780 function Match (E : Entity_Id) return Boolean is
2781 Etyp : Entity_Id := Etype (E);
2784 if Ekind (Etyp) = E_Anonymous_Access_Type then
2785 Etyp := Designated_Type (Etyp);
2788 return Base_Type (Etyp) = B_Type;
2791 -- Start of processing for Collect_Primitive_Operations
2794 -- For tagged types, the primitive operations are collected as they
2795 -- are declared, and held in an explicit list which is simply returned.
2797 if Is_Tagged_Type (B_Type) then
2798 return Primitive_Operations (B_Type);
2800 -- An untagged generic type that is a derived type inherits the
2801 -- primitive operations of its parent type. Other formal types only
2802 -- have predefined operators, which are not explicitly represented.
2804 elsif Is_Generic_Type (B_Type) then
2805 if Nkind (B_Decl) = N_Formal_Type_Declaration
2806 and then Nkind (Formal_Type_Definition (B_Decl))
2807 = N_Formal_Derived_Type_Definition
2809 Formal_Derived := True;
2811 return New_Elmt_List;
2815 Op_List := New_Elmt_List;
2817 if B_Scope = Standard_Standard then
2818 if B_Type = Standard_String then
2819 Append_Elmt (Standard_Op_Concat, Op_List);
2821 elsif B_Type = Standard_Wide_String then
2822 Append_Elmt (Standard_Op_Concatw, Op_List);
2828 -- Locate the primitive subprograms of the type
2831 -- The primitive operations appear after the base type, except
2832 -- if the derivation happens within the private part of B_Scope
2833 -- and the type is a private type, in which case both the type
2834 -- and some primitive operations may appear before the base
2835 -- type, and the list of candidates starts after the type.
2837 if In_Open_Scopes (B_Scope)
2838 and then Scope (T) = B_Scope
2839 and then In_Private_Part (B_Scope)
2841 Id := Next_Entity (T);
2843 Id := Next_Entity (B_Type);
2846 -- Set flag if this is a type in a package spec
2849 Is_Package_Or_Generic_Package (B_Scope)
2851 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
2854 while Present (Id) loop
2856 -- Test whether the result type or any of the parameter types of
2857 -- each subprogram following the type match that type when the
2858 -- type is declared in a package spec, is a derived type, or the
2859 -- subprogram is marked as primitive. (The Is_Primitive test is
2860 -- needed to find primitives of nonderived types in declarative
2861 -- parts that happen to override the predefined "=" operator.)
2863 -- Note that generic formal subprograms are not considered to be
2864 -- primitive operations and thus are never inherited.
2866 if Is_Overloadable (Id)
2867 and then (Is_Type_In_Pkg
2868 or else Is_Derived_Type (B_Type)
2869 or else Is_Primitive (Id))
2870 and then Nkind (Parent (Parent (Id)))
2871 not in N_Formal_Subprogram_Declaration
2879 Formal := First_Formal (Id);
2880 while Present (Formal) loop
2881 if Match (Formal) then
2886 Next_Formal (Formal);
2890 -- For a formal derived type, the only primitives are the ones
2891 -- inherited from the parent type. Operations appearing in the
2892 -- package declaration are not primitive for it.
2895 and then (not Formal_Derived
2896 or else Present (Alias (Id)))
2898 -- In the special case of an equality operator aliased to
2899 -- an overriding dispatching equality belonging to the same
2900 -- type, we don't include it in the list of primitives.
2901 -- This avoids inheriting multiple equality operators when
2902 -- deriving from untagged private types whose full type is
2903 -- tagged, which can otherwise cause ambiguities. Note that
2904 -- this should only happen for this kind of untagged parent
2905 -- type, since normally dispatching operations are inherited
2906 -- using the type's Primitive_Operations list.
2908 if Chars (Id) = Name_Op_Eq
2909 and then Is_Dispatching_Operation (Id)
2910 and then Present (Alias (Id))
2911 and then Present (Overridden_Operation (Alias (Id)))
2912 and then Base_Type (Etype (First_Entity (Id))) =
2913 Base_Type (Etype (First_Entity (Alias (Id))))
2917 -- Include the subprogram in the list of primitives
2920 Append_Elmt (Id, Op_List);
2927 -- For a type declared in System, some of its operations may
2928 -- appear in the target-specific extension to System.
2931 and then B_Scope = RTU_Entity (System)
2932 and then Present_System_Aux
2934 B_Scope := System_Aux_Id;
2935 Id := First_Entity (System_Aux_Id);
2941 end Collect_Primitive_Operations;
2943 -----------------------------------
2944 -- Compile_Time_Constraint_Error --
2945 -----------------------------------
2947 function Compile_Time_Constraint_Error
2950 Ent : Entity_Id := Empty;
2951 Loc : Source_Ptr := No_Location;
2952 Warn : Boolean := False) return Node_Id
2954 Msgc : String (1 .. Msg'Length + 3);
2955 -- Copy of message, with room for possible ?? and ! at end
2965 -- A static constraint error in an instance body is not a fatal error.
2966 -- we choose to inhibit the message altogether, because there is no
2967 -- obvious node (for now) on which to post it. On the other hand the
2968 -- offending node must be replaced with a constraint_error in any case.
2970 -- No messages are generated if we already posted an error on this node
2972 if not Error_Posted (N) then
2973 if Loc /= No_Location then
2979 Msgc (1 .. Msg'Length) := Msg;
2982 -- Message is a warning, even in Ada 95 case
2984 if Msg (Msg'Last) = '?' then
2987 -- In Ada 83, all messages are warnings. In the private part and
2988 -- the body of an instance, constraint_checks are only warnings.
2989 -- We also make this a warning if the Warn parameter is set.
2992 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3000 elsif In_Instance_Not_Visible then
3007 -- Otherwise we have a real error message (Ada 95 static case)
3008 -- and we make this an unconditional message. Note that in the
3009 -- warning case we do not make the message unconditional, it seems
3010 -- quite reasonable to delete messages like this (about exceptions
3011 -- that will be raised) in dead code.
3019 -- Should we generate a warning? The answer is not quite yes. The
3020 -- very annoying exception occurs in the case of a short circuit
3021 -- operator where the left operand is static and decisive. Climb
3022 -- parents to see if that is the case we have here. Conditional
3023 -- expressions with decisive conditions are a similar situation.
3031 -- And then with False as left operand
3033 if Nkind (P) = N_And_Then
3034 and then Compile_Time_Known_Value (Left_Opnd (P))
3035 and then Is_False (Expr_Value (Left_Opnd (P)))
3040 -- OR ELSE with True as left operand
3042 elsif Nkind (P) = N_Or_Else
3043 and then Compile_Time_Known_Value (Left_Opnd (P))
3044 and then Is_True (Expr_Value (Left_Opnd (P)))
3051 elsif Nkind (P) = N_If_Expression then
3053 Cond : constant Node_Id := First (Expressions (P));
3054 Texp : constant Node_Id := Next (Cond);
3055 Fexp : constant Node_Id := Next (Texp);
3058 if Compile_Time_Known_Value (Cond) then
3060 -- Condition is True and we are in the right operand
3062 if Is_True (Expr_Value (Cond))
3063 and then OldP = Fexp
3068 -- Condition is False and we are in the left operand
3070 elsif Is_False (Expr_Value (Cond))
3071 and then OldP = Texp
3079 -- Special case for component association in aggregates, where
3080 -- we want to keep climbing up to the parent aggregate.
3082 elsif Nkind (P) = N_Component_Association
3083 and then Nkind (Parent (P)) = N_Aggregate
3087 -- Keep going if within subexpression
3090 exit when Nkind (P) not in N_Subexpr;
3095 if Present (Ent) then
3096 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3098 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3103 -- Check whether the context is an Init_Proc
3105 if Inside_Init_Proc then
3107 Conc_Typ : constant Entity_Id :=
3108 Corresponding_Concurrent_Type
3109 (Entity (Parameter_Type (First
3110 (Parameter_Specifications
3111 (Parent (Current_Scope))))));
3114 -- Don't complain if the corresponding concurrent type
3115 -- doesn't come from source (i.e. a single task/protected
3118 if Present (Conc_Typ)
3119 and then not Comes_From_Source (Conc_Typ)
3122 ("\??& will be raised at run time",
3123 N, Standard_Constraint_Error, Eloc);
3127 ("\??& will be raised for objects of this type",
3128 N, Standard_Constraint_Error, Eloc);
3134 ("\??& will be raised at run time",
3135 N, Standard_Constraint_Error, Eloc);
3140 ("\static expression fails Constraint_Check", Eloc);
3141 Set_Error_Posted (N);
3147 end Compile_Time_Constraint_Error;
3149 -----------------------
3150 -- Conditional_Delay --
3151 -----------------------
3153 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
3155 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
3156 Set_Has_Delayed_Freeze (New_Ent);
3158 end Conditional_Delay;
3160 -------------------------
3161 -- Copy_Component_List --
3162 -------------------------
3164 function Copy_Component_List
3166 Loc : Source_Ptr) return List_Id
3169 Comps : constant List_Id := New_List;
3172 Comp := First_Component (Underlying_Type (R_Typ));
3173 while Present (Comp) loop
3174 if Comes_From_Source (Comp) then
3176 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
3179 Make_Component_Declaration (Loc,
3180 Defining_Identifier =>
3181 Make_Defining_Identifier (Loc, Chars (Comp)),
3182 Component_Definition =>
3184 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
3188 Next_Component (Comp);
3192 end Copy_Component_List;
3194 -------------------------
3195 -- Copy_Parameter_List --
3196 -------------------------
3198 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
3199 Loc : constant Source_Ptr := Sloc (Subp_Id);
3204 if No (First_Formal (Subp_Id)) then
3208 Formal := First_Formal (Subp_Id);
3209 while Present (Formal) loop
3211 (Make_Parameter_Specification (Loc,
3212 Defining_Identifier =>
3213 Make_Defining_Identifier (Sloc (Formal),
3214 Chars => Chars (Formal)),
3215 In_Present => In_Present (Parent (Formal)),
3216 Out_Present => Out_Present (Parent (Formal)),
3218 New_Reference_To (Etype (Formal), Loc),
3220 New_Copy_Tree (Expression (Parent (Formal)))),
3223 Next_Formal (Formal);
3228 end Copy_Parameter_List;
3230 --------------------------------
3231 -- Corresponding_Generic_Type --
3232 --------------------------------
3234 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
3240 if not Is_Generic_Actual_Type (T) then
3243 -- If the actual is the actual of an enclosing instance, resolution
3244 -- was correct in the generic.
3246 elsif Nkind (Parent (T)) = N_Subtype_Declaration
3247 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
3249 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
3256 if Is_Wrapper_Package (Inst) then
3257 Inst := Related_Instance (Inst);
3262 (Specification (Unit_Declaration_Node (Inst)));
3264 -- Generic actual has the same name as the corresponding formal
3266 Typ := First_Entity (Gen);
3267 while Present (Typ) loop
3268 if Chars (Typ) = Chars (T) then
3277 end Corresponding_Generic_Type;
3279 --------------------
3280 -- Current_Entity --
3281 --------------------
3283 -- The currently visible definition for a given identifier is the
3284 -- one most chained at the start of the visibility chain, i.e. the
3285 -- one that is referenced by the Node_Id value of the name of the
3286 -- given identifier.
3288 function Current_Entity (N : Node_Id) return Entity_Id is
3290 return Get_Name_Entity_Id (Chars (N));
3293 -----------------------------
3294 -- Current_Entity_In_Scope --
3295 -----------------------------
3297 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
3299 CS : constant Entity_Id := Current_Scope;
3301 Transient_Case : constant Boolean := Scope_Is_Transient;
3304 E := Get_Name_Entity_Id (Chars (N));
3306 and then Scope (E) /= CS
3307 and then (not Transient_Case or else Scope (E) /= Scope (CS))
3313 end Current_Entity_In_Scope;
3319 function Current_Scope return Entity_Id is
3321 if Scope_Stack.Last = -1 then
3322 return Standard_Standard;
3325 C : constant Entity_Id :=
3326 Scope_Stack.Table (Scope_Stack.Last).Entity;
3331 return Standard_Standard;
3337 ------------------------
3338 -- Current_Subprogram --
3339 ------------------------
3341 function Current_Subprogram return Entity_Id is
3342 Scop : constant Entity_Id := Current_Scope;
3344 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
3347 return Enclosing_Subprogram (Scop);
3349 end Current_Subprogram;
3351 ----------------------------------
3352 -- Deepest_Type_Access_Level --
3353 ----------------------------------
3355 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
3357 if Ekind (Typ) = E_Anonymous_Access_Type
3358 and then not Is_Local_Anonymous_Access (Typ)
3359 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
3361 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3365 Scope_Depth (Enclosing_Dynamic_Scope
3366 (Defining_Identifier
3367 (Associated_Node_For_Itype (Typ))));
3369 -- For generic formal type, return Int'Last (infinite).
3370 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3372 elsif Is_Generic_Type (Root_Type (Typ)) then
3373 return UI_From_Int (Int'Last);
3376 return Type_Access_Level (Typ);
3378 end Deepest_Type_Access_Level;
3380 ---------------------
3381 -- Defining_Entity --
3382 ---------------------
3384 function Defining_Entity (N : Node_Id) return Entity_Id is
3385 K : constant Node_Kind := Nkind (N);
3386 Err : Entity_Id := Empty;
3391 N_Subprogram_Declaration |
3392 N_Abstract_Subprogram_Declaration |
3394 N_Package_Declaration |
3395 N_Subprogram_Renaming_Declaration |
3396 N_Subprogram_Body_Stub |
3397 N_Generic_Subprogram_Declaration |
3398 N_Generic_Package_Declaration |
3399 N_Formal_Subprogram_Declaration |
3400 N_Expression_Function
3402 return Defining_Entity (Specification (N));
3405 N_Component_Declaration |
3406 N_Defining_Program_Unit_Name |
3407 N_Discriminant_Specification |
3409 N_Entry_Declaration |
3410 N_Entry_Index_Specification |
3411 N_Exception_Declaration |
3412 N_Exception_Renaming_Declaration |
3413 N_Formal_Object_Declaration |
3414 N_Formal_Package_Declaration |
3415 N_Formal_Type_Declaration |
3416 N_Full_Type_Declaration |
3417 N_Implicit_Label_Declaration |
3418 N_Incomplete_Type_Declaration |
3419 N_Loop_Parameter_Specification |
3420 N_Number_Declaration |
3421 N_Object_Declaration |
3422 N_Object_Renaming_Declaration |
3423 N_Package_Body_Stub |
3424 N_Parameter_Specification |
3425 N_Private_Extension_Declaration |
3426 N_Private_Type_Declaration |
3428 N_Protected_Body_Stub |
3429 N_Protected_Type_Declaration |
3430 N_Single_Protected_Declaration |
3431 N_Single_Task_Declaration |
3432 N_Subtype_Declaration |
3435 N_Task_Type_Declaration
3437 return Defining_Identifier (N);
3440 return Defining_Entity (Proper_Body (N));
3443 N_Function_Instantiation |
3444 N_Function_Specification |
3445 N_Generic_Function_Renaming_Declaration |
3446 N_Generic_Package_Renaming_Declaration |
3447 N_Generic_Procedure_Renaming_Declaration |
3449 N_Package_Instantiation |
3450 N_Package_Renaming_Declaration |
3451 N_Package_Specification |
3452 N_Procedure_Instantiation |
3453 N_Procedure_Specification
3456 Nam : constant Node_Id := Defining_Unit_Name (N);
3459 if Nkind (Nam) in N_Entity then
3462 -- For Error, make up a name and attach to declaration
3463 -- so we can continue semantic analysis
3465 elsif Nam = Error then
3466 Err := Make_Temporary (Sloc (N), 'T');
3467 Set_Defining_Unit_Name (N, Err);
3470 -- If not an entity, get defining identifier
3473 return Defining_Identifier (Nam);
3477 when N_Block_Statement =>
3478 return Entity (Identifier (N));
3481 raise Program_Error;
3484 end Defining_Entity;
3486 --------------------------
3487 -- Denotes_Discriminant --
3488 --------------------------
3490 function Denotes_Discriminant
3492 Check_Concurrent : Boolean := False) return Boolean
3496 if not Is_Entity_Name (N)
3497 or else No (Entity (N))
3504 -- If we are checking for a protected type, the discriminant may have
3505 -- been rewritten as the corresponding discriminal of the original type
3506 -- or of the corresponding concurrent record, depending on whether we
3507 -- are in the spec or body of the protected type.
3509 return Ekind (E) = E_Discriminant
3512 and then Ekind (E) = E_In_Parameter
3513 and then Present (Discriminal_Link (E))
3515 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
3517 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
3519 end Denotes_Discriminant;
3521 -------------------------
3522 -- Denotes_Same_Object --
3523 -------------------------
3525 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
3526 Obj1 : Node_Id := A1;
3527 Obj2 : Node_Id := A2;
3529 function Has_Prefix (N : Node_Id) return Boolean;
3530 -- Return True if N has attribute Prefix
3532 function Is_Renaming (N : Node_Id) return Boolean;
3533 -- Return true if N names a renaming entity
3535 function Is_Valid_Renaming (N : Node_Id) return Boolean;
3536 -- For renamings, return False if the prefix of any dereference within
3537 -- the renamed object_name is a variable, or any expression within the
3538 -- renamed object_name contains references to variables or calls on
3539 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
3545 function Has_Prefix (N : Node_Id) return Boolean is
3549 N_Attribute_Reference,
3551 N_Explicit_Dereference,
3552 N_Indexed_Component,
3554 N_Selected_Component,
3562 function Is_Renaming (N : Node_Id) return Boolean is
3564 return Is_Entity_Name (N)
3565 and then Present (Renamed_Entity (Entity (N)));
3568 -----------------------
3569 -- Is_Valid_Renaming --
3570 -----------------------
3572 function Is_Valid_Renaming (N : Node_Id) return Boolean is
3574 function Check_Renaming (N : Node_Id) return Boolean;
3575 -- Recursive function used to traverse all the prefixes of N
3577 function Check_Renaming (N : Node_Id) return Boolean is
3580 and then not Check_Renaming (Renamed_Entity (Entity (N)))
3585 if Nkind (N) = N_Indexed_Component then
3590 Indx := First (Expressions (N));
3591 while Present (Indx) loop
3592 if not Is_OK_Static_Expression (Indx) then
3601 if Has_Prefix (N) then
3603 P : constant Node_Id := Prefix (N);
3606 if Nkind (N) = N_Explicit_Dereference
3607 and then Is_Variable (P)
3611 elsif Is_Entity_Name (P)
3612 and then Ekind (Entity (P)) = E_Function
3616 elsif Nkind (P) = N_Function_Call then
3620 -- Recursion to continue traversing the prefix of the
3621 -- renaming expression
3623 return Check_Renaming (P);
3630 -- Start of processing for Is_Valid_Renaming
3633 return Check_Renaming (N);
3634 end Is_Valid_Renaming;
3636 -- Start of processing for Denotes_Same_Object
3639 -- Both names statically denote the same stand-alone object or parameter
3640 -- (RM 6.4.1(6.5/3))
3642 if Is_Entity_Name (Obj1)
3643 and then Is_Entity_Name (Obj2)
3644 and then Entity (Obj1) = Entity (Obj2)
3649 -- For renamings, the prefix of any dereference within the renamed
3650 -- object_name is not a variable, and any expression within the
3651 -- renamed object_name contains no references to variables nor
3652 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
3654 if Is_Renaming (Obj1) then
3655 if Is_Valid_Renaming (Obj1) then
3656 Obj1 := Renamed_Entity (Entity (Obj1));
3662 if Is_Renaming (Obj2) then
3663 if Is_Valid_Renaming (Obj2) then
3664 Obj2 := Renamed_Entity (Entity (Obj2));
3670 -- No match if not same node kind (such cases are handled by
3671 -- Denotes_Same_Prefix)
3673 if Nkind (Obj1) /= Nkind (Obj2) then
3676 -- After handling valid renamings, one of the two names statically
3677 -- denoted a renaming declaration whose renamed object_name is known
3678 -- to denote the same object as the other (RM 6.4.1(6.10/3))
3680 elsif Is_Entity_Name (Obj1) then
3681 if Is_Entity_Name (Obj2) then
3682 return Entity (Obj1) = Entity (Obj2);
3687 -- Both names are selected_components, their prefixes are known to
3688 -- denote the same object, and their selector_names denote the same
3689 -- component (RM 6.4.1(6.6/3)
3691 elsif Nkind (Obj1) = N_Selected_Component then
3692 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
3694 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
3696 -- Both names are dereferences and the dereferenced names are known to
3697 -- denote the same object (RM 6.4.1(6.7/3))
3699 elsif Nkind (Obj1) = N_Explicit_Dereference then
3700 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
3702 -- Both names are indexed_components, their prefixes are known to denote
3703 -- the same object, and each of the pairs of corresponding index values
3704 -- are either both static expressions with the same static value or both
3705 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
3707 elsif Nkind (Obj1) = N_Indexed_Component then
3708 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
3716 Indx1 := First (Expressions (Obj1));
3717 Indx2 := First (Expressions (Obj2));
3718 while Present (Indx1) loop
3720 -- Indexes must denote the same static value or same object
3722 if Is_OK_Static_Expression (Indx1) then
3723 if not Is_OK_Static_Expression (Indx2) then
3726 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
3730 elsif not Denotes_Same_Object (Indx1, Indx2) then
3742 -- Both names are slices, their prefixes are known to denote the same
3743 -- object, and the two slices have statically matching index constraints
3744 -- (RM 6.4.1(6.9/3))
3746 elsif Nkind (Obj1) = N_Slice
3747 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
3750 Lo1, Lo2, Hi1, Hi2 : Node_Id;
3753 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
3754 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
3756 -- Check whether bounds are statically identical. There is no
3757 -- attempt to detect partial overlap of slices.
3759 return Denotes_Same_Object (Lo1, Lo2)
3760 and then Denotes_Same_Object (Hi1, Hi2);
3763 -- In the recursion, literals appear as indexes.
3765 elsif Nkind (Obj1) = N_Integer_Literal
3766 and then Nkind (Obj2) = N_Integer_Literal
3768 return Intval (Obj1) = Intval (Obj2);
3773 end Denotes_Same_Object;
3775 -------------------------
3776 -- Denotes_Same_Prefix --
3777 -------------------------
3779 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
3782 if Is_Entity_Name (A1) then
3783 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
3784 and then not Is_Access_Type (Etype (A1))
3786 return Denotes_Same_Object (A1, Prefix (A2))
3787 or else Denotes_Same_Prefix (A1, Prefix (A2));
3792 elsif Is_Entity_Name (A2) then
3793 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
3795 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
3797 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
3800 Root1, Root2 : Node_Id;
3801 Depth1, Depth2 : Int := 0;
3804 Root1 := Prefix (A1);
3805 while not Is_Entity_Name (Root1) loop
3807 (Root1, N_Selected_Component, N_Indexed_Component)
3811 Root1 := Prefix (Root1);
3814 Depth1 := Depth1 + 1;
3817 Root2 := Prefix (A2);
3818 while not Is_Entity_Name (Root2) loop
3820 (Root2, N_Selected_Component, N_Indexed_Component)
3824 Root2 := Prefix (Root2);
3827 Depth2 := Depth2 + 1;
3830 -- If both have the same depth and they do not denote the same
3831 -- object, they are disjoint and no warning is needed.
3833 if Depth1 = Depth2 then
3836 elsif Depth1 > Depth2 then
3837 Root1 := Prefix (A1);
3838 for I in 1 .. Depth1 - Depth2 - 1 loop
3839 Root1 := Prefix (Root1);
3842 return Denotes_Same_Object (Root1, A2);
3845 Root2 := Prefix (A2);
3846 for I in 1 .. Depth2 - Depth1 - 1 loop
3847 Root2 := Prefix (Root2);
3850 return Denotes_Same_Object (A1, Root2);
3857 end Denotes_Same_Prefix;
3859 ----------------------
3860 -- Denotes_Variable --
3861 ----------------------
3863 function Denotes_Variable (N : Node_Id) return Boolean is
3865 return Is_Variable (N) and then Paren_Count (N) = 0;
3866 end Denotes_Variable;
3868 -----------------------------
3869 -- Depends_On_Discriminant --
3870 -----------------------------
3872 function Depends_On_Discriminant (N : Node_Id) return Boolean is
3877 Get_Index_Bounds (N, L, H);
3878 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
3879 end Depends_On_Discriminant;
3881 -------------------------
3882 -- Designate_Same_Unit --
3883 -------------------------
3885 function Designate_Same_Unit
3887 Name2 : Node_Id) return Boolean
3889 K1 : constant Node_Kind := Nkind (Name1);
3890 K2 : constant Node_Kind := Nkind (Name2);
3892 function Prefix_Node (N : Node_Id) return Node_Id;
3893 -- Returns the parent unit name node of a defining program unit name
3894 -- or the prefix if N is a selected component or an expanded name.
3896 function Select_Node (N : Node_Id) return Node_Id;
3897 -- Returns the defining identifier node of a defining program unit
3898 -- name or the selector node if N is a selected component or an
3905 function Prefix_Node (N : Node_Id) return Node_Id is
3907 if Nkind (N) = N_Defining_Program_Unit_Name then
3919 function Select_Node (N : Node_Id) return Node_Id is
3921 if Nkind (N) = N_Defining_Program_Unit_Name then
3922 return Defining_Identifier (N);
3925 return Selector_Name (N);
3929 -- Start of processing for Designate_Next_Unit
3932 if (K1 = N_Identifier or else
3933 K1 = N_Defining_Identifier)
3935 (K2 = N_Identifier or else
3936 K2 = N_Defining_Identifier)
3938 return Chars (Name1) = Chars (Name2);
3941 (K1 = N_Expanded_Name or else
3942 K1 = N_Selected_Component or else
3943 K1 = N_Defining_Program_Unit_Name)
3945 (K2 = N_Expanded_Name or else
3946 K2 = N_Selected_Component or else
3947 K2 = N_Defining_Program_Unit_Name)
3950 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
3952 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
3957 end Designate_Same_Unit;
3959 ------------------------------------------
3960 -- function Dynamic_Accessibility_Level --
3961 ------------------------------------------
3963 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
3965 Loc : constant Source_Ptr := Sloc (Expr);
3967 function Make_Level_Literal (Level : Uint) return Node_Id;
3968 -- Construct an integer literal representing an accessibility level
3969 -- with its type set to Natural.
3971 ------------------------
3972 -- Make_Level_Literal --
3973 ------------------------
3975 function Make_Level_Literal (Level : Uint) return Node_Id is
3976 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
3978 Set_Etype (Result, Standard_Natural);
3980 end Make_Level_Literal;
3982 -- Start of processing for Dynamic_Accessibility_Level
3985 if Is_Entity_Name (Expr) then
3988 if Present (Renamed_Object (E)) then
3989 return Dynamic_Accessibility_Level (Renamed_Object (E));
3992 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
3993 if Present (Extra_Accessibility (E)) then
3994 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
3999 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4001 case Nkind (Expr) is
4003 -- For access discriminant, the level of the enclosing object
4005 when N_Selected_Component =>
4006 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
4007 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
4008 E_Anonymous_Access_Type
4010 return Make_Level_Literal (Object_Access_Level (Expr));
4013 when N_Attribute_Reference =>
4014 case Get_Attribute_Id (Attribute_Name (Expr)) is
4016 -- For X'Access, the level of the prefix X
4018 when Attribute_Access =>
4019 return Make_Level_Literal
4020 (Object_Access_Level (Prefix (Expr)));
4022 -- Treat the unchecked attributes as library-level
4024 when Attribute_Unchecked_Access |
4025 Attribute_Unrestricted_Access =>
4026 return Make_Level_Literal (Scope_Depth (Standard_Standard));
4028 -- No other access-valued attributes
4031 raise Program_Error;
4036 -- Unimplemented: depends on context. As an actual parameter where
4037 -- formal type is anonymous, use
4038 -- Scope_Depth (Current_Scope) + 1.
4039 -- For other cases, see 3.10.2(14/3) and following. ???
4043 when N_Type_Conversion =>
4044 if not Is_Local_Anonymous_Access (Etype (Expr)) then
4046 -- Handle type conversions introduced for a rename of an
4047 -- Ada 2012 stand-alone object of an anonymous access type.
4049 return Dynamic_Accessibility_Level (Expression (Expr));
4056 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
4057 end Dynamic_Accessibility_Level;
4059 -----------------------------------
4060 -- Effective_Extra_Accessibility --
4061 -----------------------------------
4063 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
4065 if Present (Renamed_Object (Id))
4066 and then Is_Entity_Name (Renamed_Object (Id))
4068 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
4070 return Extra_Accessibility (Id);
4072 end Effective_Extra_Accessibility;
4074 ------------------------------
4075 -- Enclosing_Comp_Unit_Node --
4076 ------------------------------
4078 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
4079 Current_Node : Node_Id;
4083 while Present (Current_Node)
4084 and then Nkind (Current_Node) /= N_Compilation_Unit
4086 Current_Node := Parent (Current_Node);
4089 if Nkind (Current_Node) /= N_Compilation_Unit then
4092 return Current_Node;
4094 end Enclosing_Comp_Unit_Node;
4096 --------------------------
4097 -- Enclosing_CPP_Parent --
4098 --------------------------
4100 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
4101 Parent_Typ : Entity_Id := Typ;
4104 while not Is_CPP_Class (Parent_Typ)
4105 and then Etype (Parent_Typ) /= Parent_Typ
4107 Parent_Typ := Etype (Parent_Typ);
4109 if Is_Private_Type (Parent_Typ) then
4110 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4114 pragma Assert (Is_CPP_Class (Parent_Typ));
4116 end Enclosing_CPP_Parent;
4118 ----------------------------
4119 -- Enclosing_Generic_Body --
4120 ----------------------------
4122 function Enclosing_Generic_Body
4123 (N : Node_Id) return Node_Id
4131 while Present (P) loop
4132 if Nkind (P) = N_Package_Body
4133 or else Nkind (P) = N_Subprogram_Body
4135 Spec := Corresponding_Spec (P);
4137 if Present (Spec) then
4138 Decl := Unit_Declaration_Node (Spec);
4140 if Nkind (Decl) = N_Generic_Package_Declaration
4141 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
4152 end Enclosing_Generic_Body;
4154 ----------------------------
4155 -- Enclosing_Generic_Unit --
4156 ----------------------------
4158 function Enclosing_Generic_Unit
4159 (N : Node_Id) return Node_Id
4167 while Present (P) loop
4168 if Nkind (P) = N_Generic_Package_Declaration
4169 or else Nkind (P) = N_Generic_Subprogram_Declaration
4173 elsif Nkind (P) = N_Package_Body
4174 or else Nkind (P) = N_Subprogram_Body
4176 Spec := Corresponding_Spec (P);
4178 if Present (Spec) then
4179 Decl := Unit_Declaration_Node (Spec);
4181 if Nkind (Decl) = N_Generic_Package_Declaration
4182 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
4193 end Enclosing_Generic_Unit;
4195 -------------------------------
4196 -- Enclosing_Lib_Unit_Entity --
4197 -------------------------------
4199 function Enclosing_Lib_Unit_Entity
4200 (E : Entity_Id := Current_Scope) return Entity_Id
4202 Unit_Entity : Entity_Id;
4205 -- Look for enclosing library unit entity by following scope links.
4206 -- Equivalent to, but faster than indexing through the scope stack.
4209 while (Present (Scope (Unit_Entity))
4210 and then Scope (Unit_Entity) /= Standard_Standard)
4211 and not Is_Child_Unit (Unit_Entity)
4213 Unit_Entity := Scope (Unit_Entity);
4217 end Enclosing_Lib_Unit_Entity;
4219 -----------------------
4220 -- Enclosing_Package --
4221 -----------------------
4223 function Enclosing_Package (E : Entity_Id) return Entity_Id is
4224 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
4227 if Dynamic_Scope = Standard_Standard then
4228 return Standard_Standard;
4230 elsif Dynamic_Scope = Empty then
4233 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
4236 return Dynamic_Scope;
4239 return Enclosing_Package (Dynamic_Scope);
4241 end Enclosing_Package;
4243 --------------------------
4244 -- Enclosing_Subprogram --
4245 --------------------------
4247 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
4248 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
4251 if Dynamic_Scope = Standard_Standard then
4254 elsif Dynamic_Scope = Empty then
4257 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
4258 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
4260 elsif Ekind (Dynamic_Scope) = E_Block
4261 or else Ekind (Dynamic_Scope) = E_Return_Statement
4263 return Enclosing_Subprogram (Dynamic_Scope);
4265 elsif Ekind (Dynamic_Scope) = E_Task_Type then
4266 return Get_Task_Body_Procedure (Dynamic_Scope);
4268 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
4269 and then Present (Full_View (Dynamic_Scope))
4270 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
4272 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
4274 -- No body is generated if the protected operation is eliminated
4276 elsif Convention (Dynamic_Scope) = Convention_Protected
4277 and then not Is_Eliminated (Dynamic_Scope)
4278 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
4280 return Protected_Body_Subprogram (Dynamic_Scope);
4283 return Dynamic_Scope;
4285 end Enclosing_Subprogram;
4287 ------------------------
4288 -- Ensure_Freeze_Node --
4289 ------------------------
4291 procedure Ensure_Freeze_Node (E : Entity_Id) is
4295 if No (Freeze_Node (E)) then
4296 FN := Make_Freeze_Entity (Sloc (E));
4297 Set_Has_Delayed_Freeze (E);
4298 Set_Freeze_Node (E, FN);
4299 Set_Access_Types_To_Process (FN, No_Elist);
4300 Set_TSS_Elist (FN, No_Elist);
4303 end Ensure_Freeze_Node;
4309 procedure Enter_Name (Def_Id : Entity_Id) is
4310 C : constant Entity_Id := Current_Entity (Def_Id);
4311 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
4312 S : constant Entity_Id := Current_Scope;
4315 Generate_Definition (Def_Id);
4317 -- Add new name to current scope declarations. Check for duplicate
4318 -- declaration, which may or may not be a genuine error.
4322 -- Case of previous entity entered because of a missing declaration
4323 -- or else a bad subtype indication. Best is to use the new entity,
4324 -- and make the previous one invisible.
4326 if Etype (E) = Any_Type then
4327 Set_Is_Immediately_Visible (E, False);
4329 -- Case of renaming declaration constructed for package instances.
4330 -- if there is an explicit declaration with the same identifier,
4331 -- the renaming is not immediately visible any longer, but remains
4332 -- visible through selected component notation.
4334 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
4335 and then not Comes_From_Source (E)
4337 Set_Is_Immediately_Visible (E, False);
4339 -- The new entity may be the package renaming, which has the same
4340 -- same name as a generic formal which has been seen already.
4342 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
4343 and then not Comes_From_Source (Def_Id)
4345 Set_Is_Immediately_Visible (E, False);
4347 -- For a fat pointer corresponding to a remote access to subprogram,
4348 -- we use the same identifier as the RAS type, so that the proper
4349 -- name appears in the stub. This type is only retrieved through
4350 -- the RAS type and never by visibility, and is not added to the
4351 -- visibility list (see below).
4353 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
4354 and then Present (Corresponding_Remote_Type (Def_Id))
4358 -- Case of an implicit operation or derived literal. The new entity
4359 -- hides the implicit one, which is removed from all visibility,
4360 -- i.e. the entity list of its scope, and homonym chain of its name.
4362 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
4363 or else Is_Internal (E)
4367 Prev_Vis : Entity_Id;
4368 Decl : constant Node_Id := Parent (E);
4371 -- If E is an implicit declaration, it cannot be the first
4372 -- entity in the scope.
4374 Prev := First_Entity (Current_Scope);
4375 while Present (Prev)
4376 and then Next_Entity (Prev) /= E
4383 -- If E is not on the entity chain of the current scope,
4384 -- it is an implicit declaration in the generic formal
4385 -- part of a generic subprogram. When analyzing the body,
4386 -- the generic formals are visible but not on the entity
4387 -- chain of the subprogram. The new entity will become
4388 -- the visible one in the body.
4391 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
4395 Set_Next_Entity (Prev, Next_Entity (E));
4397 if No (Next_Entity (Prev)) then
4398 Set_Last_Entity (Current_Scope, Prev);
4401 if E = Current_Entity (E) then
4405 Prev_Vis := Current_Entity (E);
4406 while Homonym (Prev_Vis) /= E loop
4407 Prev_Vis := Homonym (Prev_Vis);
4411 if Present (Prev_Vis) then
4413 -- Skip E in the visibility chain
4415 Set_Homonym (Prev_Vis, Homonym (E));
4418 Set_Name_Entity_Id (Chars (E), Homonym (E));
4423 -- This section of code could use a comment ???
4425 elsif Present (Etype (E))
4426 and then Is_Concurrent_Type (Etype (E))
4431 -- If the homograph is a protected component renaming, it should not
4432 -- be hiding the current entity. Such renamings are treated as weak
4435 elsif Is_Prival (E) then
4436 Set_Is_Immediately_Visible (E, False);
4438 -- In this case the current entity is a protected component renaming.
4439 -- Perform minimal decoration by setting the scope and return since
4440 -- the prival should not be hiding other visible entities.
4442 elsif Is_Prival (Def_Id) then
4443 Set_Scope (Def_Id, Current_Scope);
4446 -- Analogous to privals, the discriminal generated for an entry index
4447 -- parameter acts as a weak declaration. Perform minimal decoration
4448 -- to avoid bogus errors.
4450 elsif Is_Discriminal (Def_Id)
4451 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
4453 Set_Scope (Def_Id, Current_Scope);
4456 -- In the body or private part of an instance, a type extension may
4457 -- introduce a component with the same name as that of an actual. The
4458 -- legality rule is not enforced, but the semantics of the full type
4459 -- with two components of same name are not clear at this point???
4461 elsif In_Instance_Not_Visible then
4464 -- When compiling a package body, some child units may have become
4465 -- visible. They cannot conflict with local entities that hide them.
4467 elsif Is_Child_Unit (E)
4468 and then In_Open_Scopes (Scope (E))
4469 and then not Is_Immediately_Visible (E)
4473 -- Conversely, with front-end inlining we may compile the parent body
4474 -- first, and a child unit subsequently. The context is now the
4475 -- parent spec, and body entities are not visible.
4477 elsif Is_Child_Unit (Def_Id)
4478 and then Is_Package_Body_Entity (E)
4479 and then not In_Package_Body (Current_Scope)
4483 -- Case of genuine duplicate declaration
4486 Error_Msg_Sloc := Sloc (E);
4488 -- If the previous declaration is an incomplete type declaration
4489 -- this may be an attempt to complete it with a private type. The
4490 -- following avoids confusing cascaded errors.
4492 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
4493 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
4496 ("incomplete type cannot be completed with a private " &
4497 "declaration", Parent (Def_Id));
4498 Set_Is_Immediately_Visible (E, False);
4499 Set_Full_View (E, Def_Id);
4501 -- An inherited component of a record conflicts with a new
4502 -- discriminant. The discriminant is inserted first in the scope,
4503 -- but the error should be posted on it, not on the component.
4505 elsif Ekind (E) = E_Discriminant
4506 and then Present (Scope (Def_Id))
4507 and then Scope (Def_Id) /= Current_Scope
4509 Error_Msg_Sloc := Sloc (Def_Id);
4510 Error_Msg_N ("& conflicts with declaration#", E);
4513 -- If the name of the unit appears in its own context clause, a
4514 -- dummy package with the name has already been created, and the
4515 -- error emitted. Try to continue quietly.
4517 elsif Error_Posted (E)
4518 and then Sloc (E) = No_Location
4519 and then Nkind (Parent (E)) = N_Package_Specification
4520 and then Current_Scope = Standard_Standard
4522 Set_Scope (Def_Id, Current_Scope);
4526 Error_Msg_N ("& conflicts with declaration#", Def_Id);
4528 -- Avoid cascaded messages with duplicate components in
4531 if Ekind_In (E, E_Component, E_Discriminant) then
4536 if Nkind (Parent (Parent (Def_Id))) =
4537 N_Generic_Subprogram_Declaration
4539 Defining_Entity (Specification (Parent (Parent (Def_Id))))
4541 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
4544 -- If entity is in standard, then we are in trouble, because it
4545 -- means that we have a library package with a duplicated name.
4546 -- That's hard to recover from, so abort!
4548 if S = Standard_Standard then
4549 raise Unrecoverable_Error;
4551 -- Otherwise we continue with the declaration. Having two
4552 -- identical declarations should not cause us too much trouble!
4560 -- If we fall through, declaration is OK, at least OK enough to continue
4562 -- If Def_Id is a discriminant or a record component we are in the midst
4563 -- of inheriting components in a derived record definition. Preserve
4564 -- their Ekind and Etype.
4566 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
4569 -- If a type is already set, leave it alone (happens when a type
4570 -- declaration is reanalyzed following a call to the optimizer).
4572 elsif Present (Etype (Def_Id)) then
4575 -- Otherwise, the kind E_Void insures that premature uses of the entity
4576 -- will be detected. Any_Type insures that no cascaded errors will occur
4579 Set_Ekind (Def_Id, E_Void);
4580 Set_Etype (Def_Id, Any_Type);
4583 -- Inherited discriminants and components in derived record types are
4584 -- immediately visible. Itypes are not.
4586 if Ekind_In (Def_Id, E_Discriminant, E_Component)
4587 or else (No (Corresponding_Remote_Type (Def_Id))
4588 and then not Is_Itype (Def_Id))
4590 Set_Is_Immediately_Visible (Def_Id);
4591 Set_Current_Entity (Def_Id);
4594 Set_Homonym (Def_Id, C);
4595 Append_Entity (Def_Id, S);
4596 Set_Public_Status (Def_Id);
4598 -- Declaring a homonym is not allowed in SPARK ...
4601 and then Restriction_Check_Required (SPARK_05)
4604 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
4605 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
4606 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
4609 -- ... unless the new declaration is in a subprogram, and the
4610 -- visible declaration is a variable declaration or a parameter
4611 -- specification outside that subprogram.
4613 if Present (Enclosing_Subp)
4614 and then Nkind_In (Parent (C), N_Object_Declaration,
4615 N_Parameter_Specification)
4616 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
4620 -- ... or the new declaration is in a package, and the visible
4621 -- declaration occurs outside that package.
4623 elsif Present (Enclosing_Pack)
4624 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
4628 -- ... or the new declaration is a component declaration in a
4629 -- record type definition.
4631 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
4634 -- Don't issue error for non-source entities
4636 elsif Comes_From_Source (Def_Id)
4637 and then Comes_From_Source (C)
4639 Error_Msg_Sloc := Sloc (C);
4640 Check_SPARK_Restriction
4641 ("redeclaration of identifier &#", Def_Id);
4646 -- Warn if new entity hides an old one
4648 if Warn_On_Hiding and then Present (C)
4650 -- Don't warn for record components since they always have a well
4651 -- defined scope which does not confuse other uses. Note that in
4652 -- some cases, Ekind has not been set yet.
4654 and then Ekind (C) /= E_Component
4655 and then Ekind (C) /= E_Discriminant
4656 and then Nkind (Parent (C)) /= N_Component_Declaration
4657 and then Ekind (Def_Id) /= E_Component
4658 and then Ekind (Def_Id) /= E_Discriminant
4659 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
4661 -- Don't warn for one character variables. It is too common to use
4662 -- such variables as locals and will just cause too many false hits.
4664 and then Length_Of_Name (Chars (C)) /= 1
4666 -- Don't warn for non-source entities
4668 and then Comes_From_Source (C)
4669 and then Comes_From_Source (Def_Id)
4671 -- Don't warn unless entity in question is in extended main source
4673 and then In_Extended_Main_Source_Unit (Def_Id)
4675 -- Finally, the hidden entity must be either immediately visible or
4676 -- use visible (i.e. from a used package).
4679 (Is_Immediately_Visible (C)
4681 Is_Potentially_Use_Visible (C))
4683 Error_Msg_Sloc := Sloc (C);
4684 Error_Msg_N ("declaration hides &#?h?", Def_Id);
4688 --------------------------
4689 -- Explain_Limited_Type --
4690 --------------------------
4692 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
4696 -- For array, component type must be limited
4698 if Is_Array_Type (T) then
4699 Error_Msg_Node_2 := T;
4701 ("\component type& of type& is limited", N, Component_Type (T));
4702 Explain_Limited_Type (Component_Type (T), N);
4704 elsif Is_Record_Type (T) then
4706 -- No need for extra messages if explicit limited record
4708 if Is_Limited_Record (Base_Type (T)) then
4712 -- Otherwise find a limited component. Check only components that
4713 -- come from source, or inherited components that appear in the
4714 -- source of the ancestor.
4716 C := First_Component (T);
4717 while Present (C) loop
4718 if Is_Limited_Type (Etype (C))
4720 (Comes_From_Source (C)
4722 (Present (Original_Record_Component (C))
4724 Comes_From_Source (Original_Record_Component (C))))
4726 Error_Msg_Node_2 := T;
4727 Error_Msg_NE ("\component& of type& has limited type", N, C);
4728 Explain_Limited_Type (Etype (C), N);
4735 -- The type may be declared explicitly limited, even if no component
4736 -- of it is limited, in which case we fall out of the loop.
4739 end Explain_Limited_Type;
4745 procedure Find_Actual
4747 Formal : out Entity_Id;
4750 Parnt : constant Node_Id := Parent (N);
4754 if (Nkind (Parnt) = N_Indexed_Component
4756 Nkind (Parnt) = N_Selected_Component)
4757 and then N = Prefix (Parnt)
4759 Find_Actual (Parnt, Formal, Call);
4762 elsif Nkind (Parnt) = N_Parameter_Association
4763 and then N = Explicit_Actual_Parameter (Parnt)
4765 Call := Parent (Parnt);
4767 elsif Nkind (Parnt) in N_Subprogram_Call then
4776 -- If we have a call to a subprogram look for the parameter. Note that
4777 -- we exclude overloaded calls, since we don't know enough to be sure
4778 -- of giving the right answer in this case.
4780 if Is_Entity_Name (Name (Call))
4781 and then Present (Entity (Name (Call)))
4782 and then Is_Overloadable (Entity (Name (Call)))
4783 and then not Is_Overloaded (Name (Call))
4785 -- Fall here if we are definitely a parameter
4787 Actual := First_Actual (Call);
4788 Formal := First_Formal (Entity (Name (Call)));
4789 while Present (Formal) and then Present (Actual) loop
4793 Actual := Next_Actual (Actual);
4794 Formal := Next_Formal (Formal);
4799 -- Fall through here if we did not find matching actual
4805 ---------------------------
4806 -- Find_Body_Discriminal --
4807 ---------------------------
4809 function Find_Body_Discriminal
4810 (Spec_Discriminant : Entity_Id) return Entity_Id
4816 -- If expansion is suppressed, then the scope can be the concurrent type
4817 -- itself rather than a corresponding concurrent record type.
4819 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
4820 Tsk := Scope (Spec_Discriminant);
4823 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
4825 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
4828 -- Find discriminant of original concurrent type, and use its current
4829 -- discriminal, which is the renaming within the task/protected body.
4831 Disc := First_Discriminant (Tsk);
4832 while Present (Disc) loop
4833 if Chars (Disc) = Chars (Spec_Discriminant) then
4834 return Discriminal (Disc);
4837 Next_Discriminant (Disc);
4840 -- That loop should always succeed in finding a matching entry and
4841 -- returning. Fatal error if not.
4843 raise Program_Error;
4844 end Find_Body_Discriminal;
4846 -------------------------------------
4847 -- Find_Corresponding_Discriminant --
4848 -------------------------------------
4850 function Find_Corresponding_Discriminant
4852 Typ : Entity_Id) return Entity_Id
4854 Par_Disc : Entity_Id;
4855 Old_Disc : Entity_Id;
4856 New_Disc : Entity_Id;
4859 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
4861 -- The original type may currently be private, and the discriminant
4862 -- only appear on its full view.
4864 if Is_Private_Type (Scope (Par_Disc))
4865 and then not Has_Discriminants (Scope (Par_Disc))
4866 and then Present (Full_View (Scope (Par_Disc)))
4868 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
4870 Old_Disc := First_Discriminant (Scope (Par_Disc));
4873 if Is_Class_Wide_Type (Typ) then
4874 New_Disc := First_Discriminant (Root_Type (Typ));
4876 New_Disc := First_Discriminant (Typ);
4879 while Present (Old_Disc) and then Present (New_Disc) loop
4880 if Old_Disc = Par_Disc then
4883 Next_Discriminant (Old_Disc);
4884 Next_Discriminant (New_Disc);
4888 -- Should always find it
4890 raise Program_Error;
4891 end Find_Corresponding_Discriminant;
4893 ------------------------------------
4894 -- Find_Loop_In_Conditional_Block --
4895 ------------------------------------
4897 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
4903 if Nkind (Stmt) = N_If_Statement then
4904 Stmt := First (Then_Statements (Stmt));
4907 pragma Assert (Nkind (Stmt) = N_Block_Statement);
4909 -- Inspect the statements of the conditional block. In general the loop
4910 -- should be the first statement in the statement sequence of the block,
4911 -- but the finalization machinery may have introduced extra object
4914 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
4915 while Present (Stmt) loop
4916 if Nkind (Stmt) = N_Loop_Statement then
4923 -- The expansion of attribute 'Loop_Entry produced a malformed block
4925 raise Program_Error;
4926 end Find_Loop_In_Conditional_Block;
4928 --------------------------
4929 -- Find_Overlaid_Entity --
4930 --------------------------
4932 procedure Find_Overlaid_Entity
4934 Ent : out Entity_Id;
4940 -- We are looking for one of the two following forms:
4942 -- for X'Address use Y'Address
4946 -- Const : constant Address := expr;
4948 -- for X'Address use Const;
4950 -- In the second case, the expr is either Y'Address, or recursively a
4951 -- constant that eventually references Y'Address.
4956 if Nkind (N) = N_Attribute_Definition_Clause
4957 and then Chars (N) = Name_Address
4959 Expr := Expression (N);
4961 -- This loop checks the form of the expression for Y'Address,
4962 -- using recursion to deal with intermediate constants.
4965 -- Check for Y'Address
4967 if Nkind (Expr) = N_Attribute_Reference
4968 and then Attribute_Name (Expr) = Name_Address
4970 Expr := Prefix (Expr);
4973 -- Check for Const where Const is a constant entity
4975 elsif Is_Entity_Name (Expr)
4976 and then Ekind (Entity (Expr)) = E_Constant
4978 Expr := Constant_Value (Entity (Expr));
4980 -- Anything else does not need checking
4987 -- This loop checks the form of the prefix for an entity, using
4988 -- recursion to deal with intermediate components.
4991 -- Check for Y where Y is an entity
4993 if Is_Entity_Name (Expr) then
4994 Ent := Entity (Expr);
4997 -- Check for components
5000 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
5002 Expr := Prefix (Expr);
5005 -- Anything else does not need checking
5012 end Find_Overlaid_Entity;
5014 -------------------------
5015 -- Find_Parameter_Type --
5016 -------------------------
5018 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
5020 if Nkind (Param) /= N_Parameter_Specification then
5023 -- For an access parameter, obtain the type from the formal entity
5024 -- itself, because access to subprogram nodes do not carry a type.
5025 -- Shouldn't we always use the formal entity ???
5027 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
5028 return Etype (Defining_Identifier (Param));
5031 return Etype (Parameter_Type (Param));
5033 end Find_Parameter_Type;
5035 -----------------------------
5036 -- Find_Static_Alternative --
5037 -----------------------------
5039 function Find_Static_Alternative (N : Node_Id) return Node_Id is
5040 Expr : constant Node_Id := Expression (N);
5041 Val : constant Uint := Expr_Value (Expr);
5046 Alt := First (Alternatives (N));
5049 if Nkind (Alt) /= N_Pragma then
5050 Choice := First (Discrete_Choices (Alt));
5051 while Present (Choice) loop
5053 -- Others choice, always matches
5055 if Nkind (Choice) = N_Others_Choice then
5058 -- Range, check if value is in the range
5060 elsif Nkind (Choice) = N_Range then
5062 Val >= Expr_Value (Low_Bound (Choice))
5064 Val <= Expr_Value (High_Bound (Choice));
5066 -- Choice is a subtype name. Note that we know it must
5067 -- be a static subtype, since otherwise it would have
5068 -- been diagnosed as illegal.
5070 elsif Is_Entity_Name (Choice)
5071 and then Is_Type (Entity (Choice))
5073 exit Search when Is_In_Range (Expr, Etype (Choice),
5074 Assume_Valid => False);
5076 -- Choice is a subtype indication
5078 elsif Nkind (Choice) = N_Subtype_Indication then
5080 C : constant Node_Id := Constraint (Choice);
5081 R : constant Node_Id := Range_Expression (C);
5085 Val >= Expr_Value (Low_Bound (R))
5087 Val <= Expr_Value (High_Bound (R));
5090 -- Choice is a simple expression
5093 exit Search when Val = Expr_Value (Choice);
5101 pragma Assert (Present (Alt));
5104 -- The above loop *must* terminate by finding a match, since
5105 -- we know the case statement is valid, and the value of the
5106 -- expression is known at compile time. When we fall out of
5107 -- the loop, Alt points to the alternative that we know will
5108 -- be selected at run time.
5111 end Find_Static_Alternative;
5117 function First_Actual (Node : Node_Id) return Node_Id is
5121 if No (Parameter_Associations (Node)) then
5125 N := First (Parameter_Associations (Node));
5127 if Nkind (N) = N_Parameter_Association then
5128 return First_Named_Actual (Node);
5134 -----------------------
5135 -- Gather_Components --
5136 -----------------------
5138 procedure Gather_Components
5140 Comp_List : Node_Id;
5141 Governed_By : List_Id;
5143 Report_Errors : out Boolean)
5147 Discrete_Choice : Node_Id;
5148 Comp_Item : Node_Id;
5150 Discrim : Entity_Id;
5151 Discrim_Name : Node_Id;
5152 Discrim_Value : Node_Id;
5155 Report_Errors := False;
5157 if No (Comp_List) or else Null_Present (Comp_List) then
5160 elsif Present (Component_Items (Comp_List)) then
5161 Comp_Item := First (Component_Items (Comp_List));
5167 while Present (Comp_Item) loop
5169 -- Skip the tag of a tagged record, the interface tags, as well
5170 -- as all items that are not user components (anonymous types,
5171 -- rep clauses, Parent field, controller field).
5173 if Nkind (Comp_Item) = N_Component_Declaration then
5175 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
5177 if not Is_Tag (Comp)
5178 and then Chars (Comp) /= Name_uParent
5180 Append_Elmt (Comp, Into);
5188 if No (Variant_Part (Comp_List)) then
5191 Discrim_Name := Name (Variant_Part (Comp_List));
5192 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
5195 -- Look for the discriminant that governs this variant part.
5196 -- The discriminant *must* be in the Governed_By List
5198 Assoc := First (Governed_By);
5199 Find_Constraint : loop
5200 Discrim := First (Choices (Assoc));
5201 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
5202 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
5204 Chars (Corresponding_Discriminant (Entity (Discrim))) =
5205 Chars (Discrim_Name))
5206 or else Chars (Original_Record_Component (Entity (Discrim)))
5207 = Chars (Discrim_Name);
5209 if No (Next (Assoc)) then
5210 if not Is_Constrained (Typ)
5211 and then Is_Derived_Type (Typ)
5212 and then Present (Stored_Constraint (Typ))
5214 -- If the type is a tagged type with inherited discriminants,
5215 -- use the stored constraint on the parent in order to find
5216 -- the values of discriminants that are otherwise hidden by an
5217 -- explicit constraint. Renamed discriminants are handled in
5220 -- If several parent discriminants are renamed by a single
5221 -- discriminant of the derived type, the call to obtain the
5222 -- Corresponding_Discriminant field only retrieves the last
5223 -- of them. We recover the constraint on the others from the
5224 -- Stored_Constraint as well.
5231 D := First_Discriminant (Etype (Typ));
5232 C := First_Elmt (Stored_Constraint (Typ));
5233 while Present (D) and then Present (C) loop
5234 if Chars (Discrim_Name) = Chars (D) then
5235 if Is_Entity_Name (Node (C))
5236 and then Entity (Node (C)) = Entity (Discrim)
5238 -- D is renamed by Discrim, whose value is given in
5245 Make_Component_Association (Sloc (Typ),
5247 (New_Occurrence_Of (D, Sloc (Typ))),
5248 Duplicate_Subexpr_No_Checks (Node (C)));
5250 exit Find_Constraint;
5253 Next_Discriminant (D);
5260 if No (Next (Assoc)) then
5261 Error_Msg_NE (" missing value for discriminant&",
5262 First (Governed_By), Discrim_Name);
5263 Report_Errors := True;
5268 end loop Find_Constraint;
5270 Discrim_Value := Expression (Assoc);
5272 if not Is_OK_Static_Expression (Discrim_Value) then
5274 ("value for discriminant & must be static!",
5275 Discrim_Value, Discrim);
5276 Why_Not_Static (Discrim_Value);
5277 Report_Errors := True;
5281 Search_For_Discriminant_Value : declare
5287 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
5290 Find_Discrete_Value : while Present (Variant) loop
5291 Discrete_Choice := First (Discrete_Choices (Variant));
5292 while Present (Discrete_Choice) loop
5293 exit Find_Discrete_Value when
5294 Nkind (Discrete_Choice) = N_Others_Choice;
5296 Get_Index_Bounds (Discrete_Choice, Low, High);
5298 UI_Low := Expr_Value (Low);
5299 UI_High := Expr_Value (High);
5301 exit Find_Discrete_Value when
5302 UI_Low <= UI_Discrim_Value
5304 UI_High >= UI_Discrim_Value;
5306 Next (Discrete_Choice);
5309 Next_Non_Pragma (Variant);
5310 end loop Find_Discrete_Value;
5311 end Search_For_Discriminant_Value;
5313 if No (Variant) then
5315 ("value of discriminant & is out of range", Discrim_Value, Discrim);
5316 Report_Errors := True;
5320 -- If we have found the corresponding choice, recursively add its
5321 -- components to the Into list.
5324 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
5325 end Gather_Components;
5327 ------------------------
5328 -- Get_Actual_Subtype --
5329 ------------------------
5331 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
5332 Typ : constant Entity_Id := Etype (N);
5333 Utyp : Entity_Id := Underlying_Type (Typ);
5342 -- If what we have is an identifier that references a subprogram
5343 -- formal, or a variable or constant object, then we get the actual
5344 -- subtype from the referenced entity if one has been built.
5346 if Nkind (N) = N_Identifier
5348 (Is_Formal (Entity (N))
5349 or else Ekind (Entity (N)) = E_Constant
5350 or else Ekind (Entity (N)) = E_Variable)
5351 and then Present (Actual_Subtype (Entity (N)))
5353 return Actual_Subtype (Entity (N));
5355 -- Actual subtype of unchecked union is always itself. We never need
5356 -- the "real" actual subtype. If we did, we couldn't get it anyway
5357 -- because the discriminant is not available. The restrictions on
5358 -- Unchecked_Union are designed to make sure that this is OK.
5360 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
5363 -- Here for the unconstrained case, we must find actual subtype
5364 -- No actual subtype is available, so we must build it on the fly.
5366 -- Checking the type, not the underlying type, for constrainedness
5367 -- seems to be necessary. Maybe all the tests should be on the type???
5369 elsif (not Is_Constrained (Typ))
5370 and then (Is_Array_Type (Utyp)
5371 or else (Is_Record_Type (Utyp)
5372 and then Has_Discriminants (Utyp)))
5373 and then not Has_Unknown_Discriminants (Utyp)
5374 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
5376 -- Nothing to do if in spec expression (why not???)
5378 if In_Spec_Expression then
5381 elsif Is_Private_Type (Typ)
5382 and then not Has_Discriminants (Typ)
5384 -- If the type has no discriminants, there is no subtype to
5385 -- build, even if the underlying type is discriminated.
5389 -- Else build the actual subtype
5392 Decl := Build_Actual_Subtype (Typ, N);
5393 Atyp := Defining_Identifier (Decl);
5395 -- If Build_Actual_Subtype generated a new declaration then use it
5399 -- The actual subtype is an Itype, so analyze the declaration,
5400 -- but do not attach it to the tree, to get the type defined.
5402 Set_Parent (Decl, N);
5403 Set_Is_Itype (Atyp);
5404 Analyze (Decl, Suppress => All_Checks);
5405 Set_Associated_Node_For_Itype (Atyp, N);
5406 Set_Has_Delayed_Freeze (Atyp, False);
5408 -- We need to freeze the actual subtype immediately. This is
5409 -- needed, because otherwise this Itype will not get frozen
5410 -- at all, and it is always safe to freeze on creation because
5411 -- any associated types must be frozen at this point.
5413 Freeze_Itype (Atyp, N);
5416 -- Otherwise we did not build a declaration, so return original
5423 -- For all remaining cases, the actual subtype is the same as
5424 -- the nominal type.
5429 end Get_Actual_Subtype;
5431 -------------------------------------
5432 -- Get_Actual_Subtype_If_Available --
5433 -------------------------------------
5435 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
5436 Typ : constant Entity_Id := Etype (N);
5439 -- If what we have is an identifier that references a subprogram
5440 -- formal, or a variable or constant object, then we get the actual
5441 -- subtype from the referenced entity if one has been built.
5443 if Nkind (N) = N_Identifier
5445 (Is_Formal (Entity (N))
5446 or else Ekind (Entity (N)) = E_Constant
5447 or else Ekind (Entity (N)) = E_Variable)
5448 and then Present (Actual_Subtype (Entity (N)))
5450 return Actual_Subtype (Entity (N));
5452 -- Otherwise the Etype of N is returned unchanged
5457 end Get_Actual_Subtype_If_Available;
5459 ------------------------
5460 -- Get_Body_From_Stub --
5461 ------------------------
5463 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
5465 return Proper_Body (Unit (Library_Unit (N)));
5466 end Get_Body_From_Stub;
5468 -------------------------------
5469 -- Get_Default_External_Name --
5470 -------------------------------
5472 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
5474 Get_Decoded_Name_String (Chars (E));
5476 if Opt.External_Name_Imp_Casing = Uppercase then
5477 Set_Casing (All_Upper_Case);
5479 Set_Casing (All_Lower_Case);
5483 Make_String_Literal (Sloc (E),
5484 Strval => String_From_Name_Buffer);
5485 end Get_Default_External_Name;
5487 --------------------------
5488 -- Get_Enclosing_Object --
5489 --------------------------
5491 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
5493 if Is_Entity_Name (N) then
5497 when N_Indexed_Component |
5499 N_Selected_Component =>
5501 -- If not generating code, a dereference may be left implicit.
5502 -- In thoses cases, return Empty.
5504 if Is_Access_Type (Etype (Prefix (N))) then
5507 return Get_Enclosing_Object (Prefix (N));
5510 when N_Type_Conversion =>
5511 return Get_Enclosing_Object (Expression (N));
5517 end Get_Enclosing_Object;
5519 ---------------------------
5520 -- Get_Enum_Lit_From_Pos --
5521 ---------------------------
5523 function Get_Enum_Lit_From_Pos
5526 Loc : Source_Ptr) return Node_Id
5528 Btyp : Entity_Id := Base_Type (T);
5532 -- In the case where the literal is of type Character, Wide_Character
5533 -- or Wide_Wide_Character or of a type derived from them, there needs
5534 -- to be some special handling since there is no explicit chain of
5535 -- literals to search. Instead, an N_Character_Literal node is created
5536 -- with the appropriate Char_Code and Chars fields.
5538 if Is_Standard_Character_Type (T) then
5539 Set_Character_Literal_Name (UI_To_CC (Pos));
5541 Make_Character_Literal (Loc,
5543 Char_Literal_Value => Pos);
5545 -- For all other cases, we have a complete table of literals, and
5546 -- we simply iterate through the chain of literal until the one
5547 -- with the desired position value is found.
5551 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
5552 Btyp := Full_View (Btyp);
5555 Lit := First_Literal (Btyp);
5556 for J in 1 .. UI_To_Int (Pos) loop
5560 return New_Occurrence_Of (Lit, Loc);
5562 end Get_Enum_Lit_From_Pos;
5564 ---------------------------------
5565 -- Get_Ensures_From_CTC_Pragma --
5566 ---------------------------------
5568 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
5569 Args : constant List_Id := Pragma_Argument_Associations (N);
5573 if List_Length (Args) = 4 then
5574 Res := Pick (Args, 4);
5576 elsif List_Length (Args) = 3 then
5577 Res := Pick (Args, 3);
5579 if Chars (Res) /= Name_Ensures then
5588 end Get_Ensures_From_CTC_Pragma;
5590 ------------------------
5591 -- Get_Generic_Entity --
5592 ------------------------
5594 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
5595 Ent : constant Entity_Id := Entity (Name (N));
5597 if Present (Renamed_Object (Ent)) then
5598 return Renamed_Object (Ent);
5602 end Get_Generic_Entity;
5604 -------------------------------------
5605 -- Get_Incomplete_View_Of_Ancestor --
5606 -------------------------------------
5608 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
5609 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5610 Par_Scope : Entity_Id;
5611 Par_Type : Entity_Id;
5614 -- The incomplete view of an ancestor is only relevant for private
5615 -- derived types in child units.
5617 if not Is_Derived_Type (E)
5618 or else not Is_Child_Unit (Cur_Unit)
5623 Par_Scope := Scope (Cur_Unit);
5624 if No (Par_Scope) then
5628 Par_Type := Etype (Base_Type (E));
5630 -- Traverse list of ancestor types until we find one declared in
5631 -- a parent or grandparent unit (two levels seem sufficient).
5633 while Present (Par_Type) loop
5634 if Scope (Par_Type) = Par_Scope
5635 or else Scope (Par_Type) = Scope (Par_Scope)
5639 elsif not Is_Derived_Type (Par_Type) then
5643 Par_Type := Etype (Base_Type (Par_Type));
5647 -- If none found, there is no relevant ancestor type.
5651 end Get_Incomplete_View_Of_Ancestor;
5653 ----------------------
5654 -- Get_Index_Bounds --
5655 ----------------------
5657 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
5658 Kind : constant Node_Kind := Nkind (N);
5662 if Kind = N_Range then
5664 H := High_Bound (N);
5666 elsif Kind = N_Subtype_Indication then
5667 R := Range_Expression (Constraint (N));
5675 L := Low_Bound (Range_Expression (Constraint (N)));
5676 H := High_Bound (Range_Expression (Constraint (N)));
5679 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
5680 if Error_Posted (Scalar_Range (Entity (N))) then
5684 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
5685 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
5688 L := Low_Bound (Scalar_Range (Entity (N)));
5689 H := High_Bound (Scalar_Range (Entity (N)));
5693 -- N is an expression, indicating a range with one value
5698 end Get_Index_Bounds;
5700 ----------------------------------
5701 -- Get_Library_Unit_Name_string --
5702 ----------------------------------
5704 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
5705 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
5708 Get_Unit_Name_String (Unit_Name_Id);
5710 -- Remove seven last character (" (spec)" or " (body)")
5712 Name_Len := Name_Len - 7;
5713 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
5714 end Get_Library_Unit_Name_String;
5716 ------------------------
5717 -- Get_Name_Entity_Id --
5718 ------------------------
5720 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
5722 return Entity_Id (Get_Name_Table_Info (Id));
5723 end Get_Name_Entity_Id;
5725 ------------------------------
5726 -- Get_Name_From_CTC_Pragma --
5727 ------------------------------
5729 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
5730 Arg : constant Node_Id :=
5731 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
5733 return Strval (Expr_Value_S (Arg));
5734 end Get_Name_From_CTC_Pragma;
5740 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
5742 return Get_Pragma_Id (Pragma_Name (N));
5745 ---------------------------
5746 -- Get_Referenced_Object --
5747 ---------------------------
5749 function Get_Referenced_Object (N : Node_Id) return Node_Id is
5754 while Is_Entity_Name (R)
5755 and then Present (Renamed_Object (Entity (R)))
5757 R := Renamed_Object (Entity (R));
5761 end Get_Referenced_Object;
5763 ------------------------
5764 -- Get_Renamed_Entity --
5765 ------------------------
5767 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
5772 while Present (Renamed_Entity (R)) loop
5773 R := Renamed_Entity (R);
5777 end Get_Renamed_Entity;
5779 ----------------------------------
5780 -- Get_Requires_From_CTC_Pragma --
5781 ----------------------------------
5783 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
5784 Args : constant List_Id := Pragma_Argument_Associations (N);
5788 if List_Length (Args) >= 3 then
5789 Res := Pick (Args, 3);
5791 if Chars (Res) /= Name_Requires then
5800 end Get_Requires_From_CTC_Pragma;
5802 -------------------------
5803 -- Get_Subprogram_Body --
5804 -------------------------
5806 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
5810 Decl := Unit_Declaration_Node (E);
5812 if Nkind (Decl) = N_Subprogram_Body then
5815 -- The below comment is bad, because it is possible for
5816 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
5818 else -- Nkind (Decl) = N_Subprogram_Declaration
5820 if Present (Corresponding_Body (Decl)) then
5821 return Unit_Declaration_Node (Corresponding_Body (Decl));
5823 -- Imported subprogram case
5829 end Get_Subprogram_Body;
5831 ---------------------------
5832 -- Get_Subprogram_Entity --
5833 ---------------------------
5835 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
5837 Subp_Id : Entity_Id;
5840 if Nkind (Nod) = N_Accept_Statement then
5841 Subp := Entry_Direct_Name (Nod);
5843 elsif Nkind (Nod) = N_Slice then
5844 Subp := Prefix (Nod);
5850 -- Strip the subprogram call
5853 if Nkind_In (Subp, N_Explicit_Dereference,
5854 N_Indexed_Component,
5855 N_Selected_Component)
5857 Subp := Prefix (Subp);
5859 elsif Nkind_In (Subp, N_Type_Conversion,
5860 N_Unchecked_Type_Conversion)
5862 Subp := Expression (Subp);
5869 -- Extract the entity of the subprogram call
5871 if Is_Entity_Name (Subp) then
5872 Subp_Id := Entity (Subp);
5874 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
5875 Subp_Id := Directly_Designated_Type (Subp_Id);
5878 if Is_Subprogram (Subp_Id) then
5884 -- The search did not find a construct that denotes a subprogram
5889 end Get_Subprogram_Entity;
5891 -----------------------------
5892 -- Get_Task_Body_Procedure --
5893 -----------------------------
5895 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
5897 -- Note: A task type may be the completion of a private type with
5898 -- discriminants. When performing elaboration checks on a task
5899 -- declaration, the current view of the type may be the private one,
5900 -- and the procedure that holds the body of the task is held in its
5903 -- This is an odd function, why not have Task_Body_Procedure do
5904 -- the following digging???
5906 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
5907 end Get_Task_Body_Procedure;
5909 -----------------------
5910 -- Has_Access_Values --
5911 -----------------------
5913 function Has_Access_Values (T : Entity_Id) return Boolean is
5914 Typ : constant Entity_Id := Underlying_Type (T);
5917 -- Case of a private type which is not completed yet. This can only
5918 -- happen in the case of a generic format type appearing directly, or
5919 -- as a component of the type to which this function is being applied
5920 -- at the top level. Return False in this case, since we certainly do
5921 -- not know that the type contains access types.
5926 elsif Is_Access_Type (Typ) then
5929 elsif Is_Array_Type (Typ) then
5930 return Has_Access_Values (Component_Type (Typ));
5932 elsif Is_Record_Type (Typ) then
5937 -- Loop to Check components
5939 Comp := First_Component_Or_Discriminant (Typ);
5940 while Present (Comp) loop
5942 -- Check for access component, tag field does not count, even
5943 -- though it is implemented internally using an access type.
5945 if Has_Access_Values (Etype (Comp))
5946 and then Chars (Comp) /= Name_uTag
5951 Next_Component_Or_Discriminant (Comp);
5960 end Has_Access_Values;
5962 ------------------------------
5963 -- Has_Compatible_Alignment --
5964 ------------------------------
5966 function Has_Compatible_Alignment
5968 Expr : Node_Id) return Alignment_Result
5970 function Has_Compatible_Alignment_Internal
5973 Default : Alignment_Result) return Alignment_Result;
5974 -- This is the internal recursive function that actually does the work.
5975 -- There is one additional parameter, which says what the result should
5976 -- be if no alignment information is found, and there is no definite
5977 -- indication of compatible alignments. At the outer level, this is set
5978 -- to Unknown, but for internal recursive calls in the case where types
5979 -- are known to be correct, it is set to Known_Compatible.
5981 ---------------------------------------
5982 -- Has_Compatible_Alignment_Internal --
5983 ---------------------------------------
5985 function Has_Compatible_Alignment_Internal
5988 Default : Alignment_Result) return Alignment_Result
5990 Result : Alignment_Result := Known_Compatible;
5991 -- Holds the current status of the result. Note that once a value of
5992 -- Known_Incompatible is set, it is sticky and does not get changed
5993 -- to Unknown (the value in Result only gets worse as we go along,
5996 Offs : Uint := No_Uint;
5997 -- Set to a factor of the offset from the base object when Expr is a
5998 -- selected or indexed component, based on Component_Bit_Offset and
5999 -- Component_Size respectively. A negative value is used to represent
6000 -- a value which is not known at compile time.
6002 procedure Check_Prefix;
6003 -- Checks the prefix recursively in the case where the expression
6004 -- is an indexed or selected component.
6006 procedure Set_Result (R : Alignment_Result);
6007 -- If R represents a worse outcome (unknown instead of known
6008 -- compatible, or known incompatible), then set Result to R.
6014 procedure Check_Prefix is
6016 -- The subtlety here is that in doing a recursive call to check
6017 -- the prefix, we have to decide what to do in the case where we
6018 -- don't find any specific indication of an alignment problem.
6020 -- At the outer level, we normally set Unknown as the result in
6021 -- this case, since we can only set Known_Compatible if we really
6022 -- know that the alignment value is OK, but for the recursive
6023 -- call, in the case where the types match, and we have not
6024 -- specified a peculiar alignment for the object, we are only
6025 -- concerned about suspicious rep clauses, the default case does
6026 -- not affect us, since the compiler will, in the absence of such
6027 -- rep clauses, ensure that the alignment is correct.
6029 if Default = Known_Compatible
6031 (Etype (Obj) = Etype (Expr)
6032 and then (Unknown_Alignment (Obj)
6034 Alignment (Obj) = Alignment (Etype (Obj))))
6037 (Has_Compatible_Alignment_Internal
6038 (Obj, Prefix (Expr), Known_Compatible));
6040 -- In all other cases, we need a full check on the prefix
6044 (Has_Compatible_Alignment_Internal
6045 (Obj, Prefix (Expr), Unknown));
6053 procedure Set_Result (R : Alignment_Result) is
6060 -- Start of processing for Has_Compatible_Alignment_Internal
6063 -- If Expr is a selected component, we must make sure there is no
6064 -- potentially troublesome component clause, and that the record is
6067 if Nkind (Expr) = N_Selected_Component then
6069 -- Packed record always generate unknown alignment
6071 if Is_Packed (Etype (Prefix (Expr))) then
6072 Set_Result (Unknown);
6075 -- Check prefix and component offset
6078 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
6080 -- If Expr is an indexed component, we must make sure there is no
6081 -- potentially troublesome Component_Size clause and that the array
6082 -- is not bit-packed.
6084 elsif Nkind (Expr) = N_Indexed_Component then
6086 Typ : constant Entity_Id := Etype (Prefix (Expr));
6087 Ind : constant Node_Id := First_Index (Typ);
6090 -- Bit packed array always generates unknown alignment
6092 if Is_Bit_Packed_Array (Typ) then
6093 Set_Result (Unknown);
6096 -- Check prefix and component offset
6099 Offs := Component_Size (Typ);
6101 -- Small optimization: compute the full offset when possible
6104 and then Offs > Uint_0
6105 and then Present (Ind)
6106 and then Nkind (Ind) = N_Range
6107 and then Compile_Time_Known_Value (Low_Bound (Ind))
6108 and then Compile_Time_Known_Value (First (Expressions (Expr)))
6110 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
6111 - Expr_Value (Low_Bound ((Ind))));
6116 -- If we have a null offset, the result is entirely determined by
6117 -- the base object and has already been computed recursively.
6119 if Offs = Uint_0 then
6122 -- Case where we know the alignment of the object
6124 elsif Known_Alignment (Obj) then
6126 ObjA : constant Uint := Alignment (Obj);
6127 ExpA : Uint := No_Uint;
6128 SizA : Uint := No_Uint;
6131 -- If alignment of Obj is 1, then we are always OK
6134 Set_Result (Known_Compatible);
6136 -- Alignment of Obj is greater than 1, so we need to check
6139 -- If we have an offset, see if it is compatible
6141 if Offs /= No_Uint and Offs > Uint_0 then
6142 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
6143 Set_Result (Known_Incompatible);
6146 -- See if Expr is an object with known alignment
6148 elsif Is_Entity_Name (Expr)
6149 and then Known_Alignment (Entity (Expr))
6151 ExpA := Alignment (Entity (Expr));
6153 -- Otherwise, we can use the alignment of the type of
6154 -- Expr given that we already checked for
6155 -- discombobulating rep clauses for the cases of indexed
6156 -- and selected components above.
6158 elsif Known_Alignment (Etype (Expr)) then
6159 ExpA := Alignment (Etype (Expr));
6161 -- Otherwise the alignment is unknown
6164 Set_Result (Default);
6167 -- If we got an alignment, see if it is acceptable
6169 if ExpA /= No_Uint and then ExpA < ObjA then
6170 Set_Result (Known_Incompatible);
6173 -- If Expr is not a piece of a larger object, see if size
6174 -- is given. If so, check that it is not too small for the
6175 -- required alignment.
6177 if Offs /= No_Uint then
6180 -- See if Expr is an object with known size
6182 elsif Is_Entity_Name (Expr)
6183 and then Known_Static_Esize (Entity (Expr))
6185 SizA := Esize (Entity (Expr));
6187 -- Otherwise, we check the object size of the Expr type
6189 elsif Known_Static_Esize (Etype (Expr)) then
6190 SizA := Esize (Etype (Expr));
6193 -- If we got a size, see if it is a multiple of the Obj
6194 -- alignment, if not, then the alignment cannot be
6195 -- acceptable, since the size is always a multiple of the
6198 if SizA /= No_Uint then
6199 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
6200 Set_Result (Known_Incompatible);
6206 -- If we do not know required alignment, any non-zero offset is a
6207 -- potential problem (but certainly may be OK, so result is unknown).
6209 elsif Offs /= No_Uint then
6210 Set_Result (Unknown);
6212 -- If we can't find the result by direct comparison of alignment
6213 -- values, then there is still one case that we can determine known
6214 -- result, and that is when we can determine that the types are the
6215 -- same, and no alignments are specified. Then we known that the
6216 -- alignments are compatible, even if we don't know the alignment
6217 -- value in the front end.
6219 elsif Etype (Obj) = Etype (Expr) then
6221 -- Types are the same, but we have to check for possible size
6222 -- and alignments on the Expr object that may make the alignment
6223 -- different, even though the types are the same.
6225 if Is_Entity_Name (Expr) then
6227 -- First check alignment of the Expr object. Any alignment less
6228 -- than Maximum_Alignment is worrisome since this is the case
6229 -- where we do not know the alignment of Obj.
6231 if Known_Alignment (Entity (Expr))
6233 UI_To_Int (Alignment (Entity (Expr))) <
6234 Ttypes.Maximum_Alignment
6236 Set_Result (Unknown);
6238 -- Now check size of Expr object. Any size that is not an
6239 -- even multiple of Maximum_Alignment is also worrisome
6240 -- since it may cause the alignment of the object to be less
6241 -- than the alignment of the type.
6243 elsif Known_Static_Esize (Entity (Expr))
6245 (UI_To_Int (Esize (Entity (Expr))) mod
6246 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
6249 Set_Result (Unknown);
6251 -- Otherwise same type is decisive
6254 Set_Result (Known_Compatible);
6258 -- Another case to deal with is when there is an explicit size or
6259 -- alignment clause when the types are not the same. If so, then the
6260 -- result is Unknown. We don't need to do this test if the Default is
6261 -- Unknown, since that result will be set in any case.
6263 elsif Default /= Unknown
6264 and then (Has_Size_Clause (Etype (Expr))
6266 Has_Alignment_Clause (Etype (Expr)))
6268 Set_Result (Unknown);
6270 -- If no indication found, set default
6273 Set_Result (Default);
6276 -- Return worst result found
6279 end Has_Compatible_Alignment_Internal;
6281 -- Start of processing for Has_Compatible_Alignment
6284 -- If Obj has no specified alignment, then set alignment from the type
6285 -- alignment. Perhaps we should always do this, but for sure we should
6286 -- do it when there is an address clause since we can do more if the
6287 -- alignment is known.
6289 if Unknown_Alignment (Obj) then
6290 Set_Alignment (Obj, Alignment (Etype (Obj)));
6293 -- Now do the internal call that does all the work
6295 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
6296 end Has_Compatible_Alignment;
6298 ----------------------
6299 -- Has_Declarations --
6300 ----------------------
6302 function Has_Declarations (N : Node_Id) return Boolean is
6304 return Nkind_In (Nkind (N), N_Accept_Statement,
6306 N_Compilation_Unit_Aux,
6312 N_Package_Specification);
6313 end Has_Declarations;
6319 function Has_Denormals (E : Entity_Id) return Boolean is
6321 return Is_Floating_Point_Type (E)
6322 and then Denorm_On_Target
6323 and then not Vax_Float (E);
6326 -------------------------------------------
6327 -- Has_Discriminant_Dependent_Constraint --
6328 -------------------------------------------
6330 function Has_Discriminant_Dependent_Constraint
6331 (Comp : Entity_Id) return Boolean
6333 Comp_Decl : constant Node_Id := Parent (Comp);
6334 Subt_Indic : constant Node_Id :=
6335 Subtype_Indication (Component_Definition (Comp_Decl));
6340 if Nkind (Subt_Indic) = N_Subtype_Indication then
6341 Constr := Constraint (Subt_Indic);
6343 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
6344 Assn := First (Constraints (Constr));
6345 while Present (Assn) loop
6346 case Nkind (Assn) is
6347 when N_Subtype_Indication |
6351 if Depends_On_Discriminant (Assn) then
6355 when N_Discriminant_Association =>
6356 if Depends_On_Discriminant (Expression (Assn)) then
6371 end Has_Discriminant_Dependent_Constraint;
6373 --------------------
6374 -- Has_Infinities --
6375 --------------------
6377 function Has_Infinities (E : Entity_Id) return Boolean is
6380 Is_Floating_Point_Type (E)
6381 and then Nkind (Scalar_Range (E)) = N_Range
6382 and then Includes_Infinities (Scalar_Range (E));
6385 --------------------
6386 -- Has_Interfaces --
6387 --------------------
6389 function Has_Interfaces
6391 Use_Full_View : Boolean := True) return Boolean
6393 Typ : Entity_Id := Base_Type (T);
6396 -- Handle concurrent types
6398 if Is_Concurrent_Type (Typ) then
6399 Typ := Corresponding_Record_Type (Typ);
6402 if not Present (Typ)
6403 or else not Is_Record_Type (Typ)
6404 or else not Is_Tagged_Type (Typ)
6409 -- Handle private types
6412 and then Present (Full_View (Typ))
6414 Typ := Full_View (Typ);
6417 -- Handle concurrent record types
6419 if Is_Concurrent_Record_Type (Typ)
6420 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
6426 if Is_Interface (Typ)
6428 (Is_Record_Type (Typ)
6429 and then Present (Interfaces (Typ))
6430 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
6435 exit when Etype (Typ) = Typ
6437 -- Handle private types
6439 or else (Present (Full_View (Etype (Typ)))
6440 and then Full_View (Etype (Typ)) = Typ)
6442 -- Protect the frontend against wrong source with cyclic
6445 or else Etype (Typ) = T;
6447 -- Climb to the ancestor type handling private types
6449 if Present (Full_View (Etype (Typ))) then
6450 Typ := Full_View (Etype (Typ));
6459 ------------------------
6460 -- Has_Null_Exclusion --
6461 ------------------------
6463 function Has_Null_Exclusion (N : Node_Id) return Boolean is
6466 when N_Access_Definition |
6467 N_Access_Function_Definition |
6468 N_Access_Procedure_Definition |
6469 N_Access_To_Object_Definition |
6471 N_Derived_Type_Definition |
6472 N_Function_Specification |
6473 N_Subtype_Declaration =>
6474 return Null_Exclusion_Present (N);
6476 when N_Component_Definition |
6477 N_Formal_Object_Declaration |
6478 N_Object_Renaming_Declaration =>
6479 if Present (Subtype_Mark (N)) then
6480 return Null_Exclusion_Present (N);
6481 else pragma Assert (Present (Access_Definition (N)));
6482 return Null_Exclusion_Present (Access_Definition (N));
6485 when N_Discriminant_Specification =>
6486 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
6487 return Null_Exclusion_Present (Discriminant_Type (N));
6489 return Null_Exclusion_Present (N);
6492 when N_Object_Declaration =>
6493 if Nkind (Object_Definition (N)) = N_Access_Definition then
6494 return Null_Exclusion_Present (Object_Definition (N));
6496 return Null_Exclusion_Present (N);
6499 when N_Parameter_Specification =>
6500 if Nkind (Parameter_Type (N)) = N_Access_Definition then
6501 return Null_Exclusion_Present (Parameter_Type (N));
6503 return Null_Exclusion_Present (N);
6510 end Has_Null_Exclusion;
6512 ------------------------
6513 -- Has_Null_Extension --
6514 ------------------------
6516 function Has_Null_Extension (T : Entity_Id) return Boolean is
6517 B : constant Entity_Id := Base_Type (T);
6522 if Nkind (Parent (B)) = N_Full_Type_Declaration
6523 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
6525 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
6527 if Present (Ext) then
6528 if Null_Present (Ext) then
6531 Comps := Component_List (Ext);
6533 -- The null component list is rewritten during analysis to
6534 -- include the parent component. Any other component indicates
6535 -- that the extension was not originally null.
6537 return Null_Present (Comps)
6538 or else No (Next (First (Component_Items (Comps))));
6547 end Has_Null_Extension;
6549 -------------------------------
6550 -- Has_Overriding_Initialize --
6551 -------------------------------
6553 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
6554 BT : constant Entity_Id := Base_Type (T);
6558 if Is_Controlled (BT) then
6559 if Is_RTU (Scope (BT), Ada_Finalization) then
6562 elsif Present (Primitive_Operations (BT)) then
6563 P := First_Elmt (Primitive_Operations (BT));
6564 while Present (P) loop
6566 Init : constant Entity_Id := Node (P);
6567 Formal : constant Entity_Id := First_Formal (Init);
6569 if Ekind (Init) = E_Procedure
6570 and then Chars (Init) = Name_Initialize
6571 and then Comes_From_Source (Init)
6572 and then Present (Formal)
6573 and then Etype (Formal) = BT
6574 and then No (Next_Formal (Formal))
6575 and then (Ada_Version < Ada_2012
6576 or else not Null_Present (Parent (Init)))
6586 -- Here if type itself does not have a non-null Initialize operation:
6587 -- check immediate ancestor.
6589 if Is_Derived_Type (BT)
6590 and then Has_Overriding_Initialize (Etype (BT))
6597 end Has_Overriding_Initialize;
6599 --------------------------------------
6600 -- Has_Preelaborable_Initialization --
6601 --------------------------------------
6603 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
6606 procedure Check_Components (E : Entity_Id);
6607 -- Check component/discriminant chain, sets Has_PE False if a component
6608 -- or discriminant does not meet the preelaborable initialization rules.
6610 ----------------------
6611 -- Check_Components --
6612 ----------------------
6614 procedure Check_Components (E : Entity_Id) is
6618 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
6619 -- Returns True if and only if the expression denoted by N does not
6620 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
6622 ---------------------------------
6623 -- Is_Preelaborable_Expression --
6624 ---------------------------------
6626 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
6630 Comp_Type : Entity_Id;
6631 Is_Array_Aggr : Boolean;
6634 if Is_Static_Expression (N) then
6637 elsif Nkind (N) = N_Null then
6640 -- Attributes are allowed in general, even if their prefix is a
6641 -- formal type. (It seems that certain attributes known not to be
6642 -- static might not be allowed, but there are no rules to prevent
6645 elsif Nkind (N) = N_Attribute_Reference then
6648 -- The name of a discriminant evaluated within its parent type is
6649 -- defined to be preelaborable (10.2.1(8)). Note that we test for
6650 -- names that denote discriminals as well as discriminants to
6651 -- catch references occurring within init procs.
6653 elsif Is_Entity_Name (N)
6655 (Ekind (Entity (N)) = E_Discriminant
6657 ((Ekind (Entity (N)) = E_Constant
6658 or else Ekind (Entity (N)) = E_In_Parameter)
6659 and then Present (Discriminal_Link (Entity (N)))))
6663 elsif Nkind (N) = N_Qualified_Expression then
6664 return Is_Preelaborable_Expression (Expression (N));
6666 -- For aggregates we have to check that each of the associations
6667 -- is preelaborable.
6669 elsif Nkind (N) = N_Aggregate
6670 or else Nkind (N) = N_Extension_Aggregate
6672 Is_Array_Aggr := Is_Array_Type (Etype (N));
6674 if Is_Array_Aggr then
6675 Comp_Type := Component_Type (Etype (N));
6678 -- Check the ancestor part of extension aggregates, which must
6679 -- be either the name of a type that has preelaborable init or
6680 -- an expression that is preelaborable.
6682 if Nkind (N) = N_Extension_Aggregate then
6684 Anc_Part : constant Node_Id := Ancestor_Part (N);
6687 if Is_Entity_Name (Anc_Part)
6688 and then Is_Type (Entity (Anc_Part))
6690 if not Has_Preelaborable_Initialization
6696 elsif not Is_Preelaborable_Expression (Anc_Part) then
6702 -- Check positional associations
6704 Exp := First (Expressions (N));
6705 while Present (Exp) loop
6706 if not Is_Preelaborable_Expression (Exp) then
6713 -- Check named associations
6715 Assn := First (Component_Associations (N));
6716 while Present (Assn) loop
6717 Choice := First (Choices (Assn));
6718 while Present (Choice) loop
6719 if Is_Array_Aggr then
6720 if Nkind (Choice) = N_Others_Choice then
6723 elsif Nkind (Choice) = N_Range then
6724 if not Is_Static_Range (Choice) then
6728 elsif not Is_Static_Expression (Choice) then
6733 Comp_Type := Etype (Choice);
6739 -- If the association has a <> at this point, then we have
6740 -- to check whether the component's type has preelaborable
6741 -- initialization. Note that this only occurs when the
6742 -- association's corresponding component does not have a
6743 -- default expression, the latter case having already been
6744 -- expanded as an expression for the association.
6746 if Box_Present (Assn) then
6747 if not Has_Preelaborable_Initialization (Comp_Type) then
6751 -- In the expression case we check whether the expression
6752 -- is preelaborable.
6755 not Is_Preelaborable_Expression (Expression (Assn))
6763 -- If we get here then aggregate as a whole is preelaborable
6767 -- All other cases are not preelaborable
6772 end Is_Preelaborable_Expression;
6774 -- Start of processing for Check_Components
6777 -- Loop through entities of record or protected type
6780 while Present (Ent) loop
6782 -- We are interested only in components and discriminants
6789 -- Get default expression if any. If there is no declaration
6790 -- node, it means we have an internal entity. The parent and
6791 -- tag fields are examples of such entities. For such cases,
6792 -- we just test the type of the entity.
6794 if Present (Declaration_Node (Ent)) then
6795 Exp := Expression (Declaration_Node (Ent));
6798 when E_Discriminant =>
6800 -- Note: for a renamed discriminant, the Declaration_Node
6801 -- may point to the one from the ancestor, and have a
6802 -- different expression, so use the proper attribute to
6803 -- retrieve the expression from the derived constraint.
6805 Exp := Discriminant_Default_Value (Ent);
6808 goto Check_Next_Entity;
6811 -- A component has PI if it has no default expression and the
6812 -- component type has PI.
6815 if not Has_Preelaborable_Initialization (Etype (Ent)) then
6820 -- Require the default expression to be preelaborable
6822 elsif not Is_Preelaborable_Expression (Exp) then
6827 <<Check_Next_Entity>>
6830 end Check_Components;
6832 -- Start of processing for Has_Preelaborable_Initialization
6835 -- Immediate return if already marked as known preelaborable init. This
6836 -- covers types for which this function has already been called once
6837 -- and returned True (in which case the result is cached), and also
6838 -- types to which a pragma Preelaborable_Initialization applies.
6840 if Known_To_Have_Preelab_Init (E) then
6844 -- If the type is a subtype representing a generic actual type, then
6845 -- test whether its base type has preelaborable initialization since
6846 -- the subtype representing the actual does not inherit this attribute
6847 -- from the actual or formal. (but maybe it should???)
6849 if Is_Generic_Actual_Type (E) then
6850 return Has_Preelaborable_Initialization (Base_Type (E));
6853 -- All elementary types have preelaborable initialization
6855 if Is_Elementary_Type (E) then
6858 -- Array types have PI if the component type has PI
6860 elsif Is_Array_Type (E) then
6861 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
6863 -- A derived type has preelaborable initialization if its parent type
6864 -- has preelaborable initialization and (in the case of a derived record
6865 -- extension) if the non-inherited components all have preelaborable
6866 -- initialization. However, a user-defined controlled type with an
6867 -- overriding Initialize procedure does not have preelaborable
6870 elsif Is_Derived_Type (E) then
6872 -- If the derived type is a private extension then it doesn't have
6873 -- preelaborable initialization.
6875 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
6879 -- First check whether ancestor type has preelaborable initialization
6881 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
6883 -- If OK, check extension components (if any)
6885 if Has_PE and then Is_Record_Type (E) then
6886 Check_Components (First_Entity (E));
6889 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
6890 -- with a user defined Initialize procedure does not have PI.
6893 and then Is_Controlled (E)
6894 and then Has_Overriding_Initialize (E)
6899 -- Private types not derived from a type having preelaborable init and
6900 -- that are not marked with pragma Preelaborable_Initialization do not
6901 -- have preelaborable initialization.
6903 elsif Is_Private_Type (E) then
6906 -- Record type has PI if it is non private and all components have PI
6908 elsif Is_Record_Type (E) then
6910 Check_Components (First_Entity (E));
6912 -- Protected types must not have entries, and components must meet
6913 -- same set of rules as for record components.
6915 elsif Is_Protected_Type (E) then
6916 if Has_Entries (E) then
6920 Check_Components (First_Entity (E));
6921 Check_Components (First_Private_Entity (E));
6924 -- Type System.Address always has preelaborable initialization
6926 elsif Is_RTE (E, RE_Address) then
6929 -- In all other cases, type does not have preelaborable initialization
6935 -- If type has preelaborable initialization, cache result
6938 Set_Known_To_Have_Preelab_Init (E);
6942 end Has_Preelaborable_Initialization;
6944 ---------------------------
6945 -- Has_Private_Component --
6946 ---------------------------
6948 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
6949 Btype : Entity_Id := Base_Type (Type_Id);
6950 Component : Entity_Id;
6953 if Error_Posted (Type_Id)
6954 or else Error_Posted (Btype)
6959 if Is_Class_Wide_Type (Btype) then
6960 Btype := Root_Type (Btype);
6963 if Is_Private_Type (Btype) then
6965 UT : constant Entity_Id := Underlying_Type (Btype);
6968 if No (Full_View (Btype)) then
6969 return not Is_Generic_Type (Btype)
6970 and then not Is_Generic_Type (Root_Type (Btype));
6972 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
6975 return not Is_Frozen (UT) and then Has_Private_Component (UT);
6979 elsif Is_Array_Type (Btype) then
6980 return Has_Private_Component (Component_Type (Btype));
6982 elsif Is_Record_Type (Btype) then
6983 Component := First_Component (Btype);
6984 while Present (Component) loop
6985 if Has_Private_Component (Etype (Component)) then
6989 Next_Component (Component);
6994 elsif Is_Protected_Type (Btype)
6995 and then Present (Corresponding_Record_Type (Btype))
6997 return Has_Private_Component (Corresponding_Record_Type (Btype));
7002 end Has_Private_Component;
7004 ----------------------
7005 -- Has_Signed_Zeros --
7006 ----------------------
7008 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
7010 return Is_Floating_Point_Type (E)
7011 and then Signed_Zeros_On_Target
7012 and then not Vax_Float (E);
7013 end Has_Signed_Zeros;
7015 -----------------------------
7016 -- Has_Static_Array_Bounds --
7017 -----------------------------
7019 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
7020 Ndims : constant Nat := Number_Dimensions (Typ);
7027 -- Unconstrained types do not have static bounds
7029 if not Is_Constrained (Typ) then
7033 -- First treat string literals specially, as the lower bound and length
7034 -- of string literals are not stored like those of arrays.
7036 -- A string literal always has static bounds
7038 if Ekind (Typ) = E_String_Literal_Subtype then
7042 -- Treat all dimensions in turn
7044 Index := First_Index (Typ);
7045 for Indx in 1 .. Ndims loop
7047 -- In case of an erroneous index which is not a discrete type, return
7048 -- that the type is not static.
7050 if not Is_Discrete_Type (Etype (Index))
7051 or else Etype (Index) = Any_Type
7056 Get_Index_Bounds (Index, Low, High);
7058 if Error_Posted (Low) or else Error_Posted (High) then
7062 if Is_OK_Static_Expression (Low)
7064 Is_OK_Static_Expression (High)
7074 -- If we fall through the loop, all indexes matched
7077 end Has_Static_Array_Bounds;
7083 function Has_Stream (T : Entity_Id) return Boolean is
7090 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
7093 elsif Is_Array_Type (T) then
7094 return Has_Stream (Component_Type (T));
7096 elsif Is_Record_Type (T) then
7097 E := First_Component (T);
7098 while Present (E) loop
7099 if Has_Stream (Etype (E)) then
7108 elsif Is_Private_Type (T) then
7109 return Has_Stream (Underlying_Type (T));
7120 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
7122 Get_Name_String (Chars (E));
7123 return Name_Buffer (Name_Len) = Suffix;
7130 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
7132 Get_Name_String (Chars (E));
7133 Add_Char_To_Name_Buffer (Suffix);
7141 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
7143 pragma Assert (Has_Suffix (E, Suffix));
7144 Get_Name_String (Chars (E));
7145 Name_Len := Name_Len - 1;
7149 --------------------------
7150 -- Has_Tagged_Component --
7151 --------------------------
7153 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
7157 if Is_Private_Type (Typ)
7158 and then Present (Underlying_Type (Typ))
7160 return Has_Tagged_Component (Underlying_Type (Typ));
7162 elsif Is_Array_Type (Typ) then
7163 return Has_Tagged_Component (Component_Type (Typ));
7165 elsif Is_Tagged_Type (Typ) then
7168 elsif Is_Record_Type (Typ) then
7169 Comp := First_Component (Typ);
7170 while Present (Comp) loop
7171 if Has_Tagged_Component (Etype (Comp)) then
7175 Next_Component (Comp);
7183 end Has_Tagged_Component;
7185 -------------------------
7186 -- Implementation_Kind --
7187 -------------------------
7189 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
7190 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
7193 pragma Assert (Present (Impl_Prag));
7194 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
7195 return Chars (Get_Pragma_Arg (Arg));
7196 end Implementation_Kind;
7198 --------------------------
7199 -- Implements_Interface --
7200 --------------------------
7202 function Implements_Interface
7203 (Typ_Ent : Entity_Id;
7204 Iface_Ent : Entity_Id;
7205 Exclude_Parents : Boolean := False) return Boolean
7207 Ifaces_List : Elist_Id;
7209 Iface : Entity_Id := Base_Type (Iface_Ent);
7210 Typ : Entity_Id := Base_Type (Typ_Ent);
7213 if Is_Class_Wide_Type (Typ) then
7214 Typ := Root_Type (Typ);
7217 if not Has_Interfaces (Typ) then
7221 if Is_Class_Wide_Type (Iface) then
7222 Iface := Root_Type (Iface);
7225 Collect_Interfaces (Typ, Ifaces_List);
7227 Elmt := First_Elmt (Ifaces_List);
7228 while Present (Elmt) loop
7229 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
7230 and then Exclude_Parents
7234 elsif Node (Elmt) = Iface then
7242 end Implements_Interface;
7248 function In_Instance return Boolean is
7249 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7255 and then S /= Standard_Standard
7257 if (Ekind (S) = E_Function
7258 or else Ekind (S) = E_Package
7259 or else Ekind (S) = E_Procedure)
7260 and then Is_Generic_Instance (S)
7262 -- A child instance is always compiled in the context of a parent
7263 -- instance. Nevertheless, the actuals are not analyzed in an
7264 -- instance context. We detect this case by examining the current
7265 -- compilation unit, which must be a child instance, and checking
7266 -- that it is not currently on the scope stack.
7268 if Is_Child_Unit (Curr_Unit)
7270 Nkind (Unit (Cunit (Current_Sem_Unit)))
7271 = N_Package_Instantiation
7272 and then not In_Open_Scopes (Curr_Unit)
7286 ----------------------
7287 -- In_Instance_Body --
7288 ----------------------
7290 function In_Instance_Body return Boolean is
7296 and then S /= Standard_Standard
7298 if (Ekind (S) = E_Function
7299 or else Ekind (S) = E_Procedure)
7300 and then Is_Generic_Instance (S)
7304 elsif Ekind (S) = E_Package
7305 and then In_Package_Body (S)
7306 and then Is_Generic_Instance (S)
7315 end In_Instance_Body;
7317 -----------------------------
7318 -- In_Instance_Not_Visible --
7319 -----------------------------
7321 function In_Instance_Not_Visible return Boolean is
7327 and then S /= Standard_Standard
7329 if (Ekind (S) = E_Function
7330 or else Ekind (S) = E_Procedure)
7331 and then Is_Generic_Instance (S)
7335 elsif Ekind (S) = E_Package
7336 and then (In_Package_Body (S) or else In_Private_Part (S))
7337 and then Is_Generic_Instance (S)
7346 end In_Instance_Not_Visible;
7348 ------------------------------
7349 -- In_Instance_Visible_Part --
7350 ------------------------------
7352 function In_Instance_Visible_Part return Boolean is
7358 and then S /= Standard_Standard
7360 if Ekind (S) = E_Package
7361 and then Is_Generic_Instance (S)
7362 and then not In_Package_Body (S)
7363 and then not In_Private_Part (S)
7372 end In_Instance_Visible_Part;
7374 ---------------------
7375 -- In_Package_Body --
7376 ---------------------
7378 function In_Package_Body return Boolean is
7384 and then S /= Standard_Standard
7386 if Ekind (S) = E_Package
7387 and then In_Package_Body (S)
7396 end In_Package_Body;
7398 --------------------------------
7399 -- In_Parameter_Specification --
7400 --------------------------------
7402 function In_Parameter_Specification (N : Node_Id) return Boolean is
7407 while Present (PN) loop
7408 if Nkind (PN) = N_Parameter_Specification then
7416 end In_Parameter_Specification;
7418 -------------------------------------
7419 -- In_Reverse_Storage_Order_Object --
7420 -------------------------------------
7422 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
7424 Btyp : Entity_Id := Empty;
7427 -- Climb up indexed components
7431 case Nkind (Pref) is
7432 when N_Selected_Component =>
7433 Pref := Prefix (Pref);
7436 when N_Indexed_Component =>
7437 Pref := Prefix (Pref);
7445 if Present (Pref) then
7446 Btyp := Base_Type (Etype (Pref));
7451 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
7452 and then Reverse_Storage_Order (Btyp);
7453 end In_Reverse_Storage_Order_Object;
7455 --------------------------------------
7456 -- In_Subprogram_Or_Concurrent_Unit --
7457 --------------------------------------
7459 function In_Subprogram_Or_Concurrent_Unit return Boolean is
7464 -- Use scope chain to check successively outer scopes
7470 if K in Subprogram_Kind
7471 or else K in Concurrent_Kind
7472 or else K in Generic_Subprogram_Kind
7476 elsif E = Standard_Standard then
7482 end In_Subprogram_Or_Concurrent_Unit;
7484 ---------------------
7485 -- In_Visible_Part --
7486 ---------------------
7488 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
7491 Is_Package_Or_Generic_Package (Scope_Id)
7492 and then In_Open_Scopes (Scope_Id)
7493 and then not In_Package_Body (Scope_Id)
7494 and then not In_Private_Part (Scope_Id);
7495 end In_Visible_Part;
7497 --------------------------------
7498 -- Incomplete_Or_Private_View --
7499 --------------------------------
7501 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
7502 function Inspect_Decls
7504 Taft : Boolean := False) return Entity_Id;
7505 -- Check whether a declarative region contains the incomplete or private
7512 function Inspect_Decls
7514 Taft : Boolean := False) return Entity_Id
7520 Decl := First (Decls);
7521 while Present (Decl) loop
7525 if Nkind (Decl) = N_Incomplete_Type_Declaration then
7526 Match := Defining_Identifier (Decl);
7530 if Nkind_In (Decl, N_Private_Extension_Declaration,
7531 N_Private_Type_Declaration)
7533 Match := Defining_Identifier (Decl);
7538 and then Present (Full_View (Match))
7539 and then Full_View (Match) = Typ
7554 -- Start of processing for Incomplete_Or_Partial_View
7557 -- Incomplete type case
7559 Prev := Current_Entity_In_Scope (Typ);
7562 and then Is_Incomplete_Type (Prev)
7563 and then Present (Full_View (Prev))
7564 and then Full_View (Prev) = Typ
7569 -- Private or Taft amendment type case
7572 Pkg : constant Entity_Id := Scope (Typ);
7573 Pkg_Decl : Node_Id := Pkg;
7576 if Ekind (Pkg) = E_Package then
7577 while Nkind (Pkg_Decl) /= N_Package_Specification loop
7578 Pkg_Decl := Parent (Pkg_Decl);
7581 -- It is knows that Typ has a private view, look for it in the
7582 -- visible declarations of the enclosing scope. A special case
7583 -- of this is when the two views have been exchanged - the full
7584 -- appears earlier than the private.
7586 if Has_Private_Declaration (Typ) then
7587 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
7589 -- Exchanged view case, look in the private declarations
7592 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
7597 -- Otherwise if this is the package body, then Typ is a potential
7598 -- Taft amendment type. The incomplete view should be located in
7599 -- the private declarations of the enclosing scope.
7601 elsif In_Package_Body (Pkg) then
7602 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
7607 -- The type has no incomplete or private view
7610 end Incomplete_Or_Private_View;
7612 ---------------------------------
7613 -- Insert_Explicit_Dereference --
7614 ---------------------------------
7616 procedure Insert_Explicit_Dereference (N : Node_Id) is
7617 New_Prefix : constant Node_Id := Relocate_Node (N);
7618 Ent : Entity_Id := Empty;
7625 Save_Interps (N, New_Prefix);
7628 Make_Explicit_Dereference (Sloc (Parent (N)),
7629 Prefix => New_Prefix));
7631 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
7633 if Is_Overloaded (New_Prefix) then
7635 -- The dereference is also overloaded, and its interpretations are
7636 -- the designated types of the interpretations of the original node.
7638 Set_Etype (N, Any_Type);
7640 Get_First_Interp (New_Prefix, I, It);
7641 while Present (It.Nam) loop
7644 if Is_Access_Type (T) then
7645 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
7648 Get_Next_Interp (I, It);
7654 -- Prefix is unambiguous: mark the original prefix (which might
7655 -- Come_From_Source) as a reference, since the new (relocated) one
7656 -- won't be taken into account.
7658 if Is_Entity_Name (New_Prefix) then
7659 Ent := Entity (New_Prefix);
7662 -- For a retrieval of a subcomponent of some composite object,
7663 -- retrieve the ultimate entity if there is one.
7665 elsif Nkind (New_Prefix) = N_Selected_Component
7666 or else Nkind (New_Prefix) = N_Indexed_Component
7668 Pref := Prefix (New_Prefix);
7669 while Present (Pref)
7671 (Nkind (Pref) = N_Selected_Component
7672 or else Nkind (Pref) = N_Indexed_Component)
7674 Pref := Prefix (Pref);
7677 if Present (Pref) and then Is_Entity_Name (Pref) then
7678 Ent := Entity (Pref);
7682 -- Place the reference on the entity node
7684 if Present (Ent) then
7685 Generate_Reference (Ent, Pref);
7688 end Insert_Explicit_Dereference;
7690 ------------------------------------------
7691 -- Inspect_Deferred_Constant_Completion --
7692 ------------------------------------------
7694 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
7698 Decl := First (Decls);
7699 while Present (Decl) loop
7701 -- Deferred constant signature
7703 if Nkind (Decl) = N_Object_Declaration
7704 and then Constant_Present (Decl)
7705 and then No (Expression (Decl))
7707 -- No need to check internally generated constants
7709 and then Comes_From_Source (Decl)
7711 -- The constant is not completed. A full object declaration or a
7712 -- pragma Import complete a deferred constant.
7714 and then not Has_Completion (Defining_Identifier (Decl))
7717 ("constant declaration requires initialization expression",
7718 Defining_Identifier (Decl));
7721 Decl := Next (Decl);
7723 end Inspect_Deferred_Constant_Completion;
7725 -----------------------------
7726 -- Is_Actual_Out_Parameter --
7727 -----------------------------
7729 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
7733 Find_Actual (N, Formal, Call);
7734 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
7735 end Is_Actual_Out_Parameter;
7737 -------------------------
7738 -- Is_Actual_Parameter --
7739 -------------------------
7741 function Is_Actual_Parameter (N : Node_Id) return Boolean is
7742 PK : constant Node_Kind := Nkind (Parent (N));
7746 when N_Parameter_Association =>
7747 return N = Explicit_Actual_Parameter (Parent (N));
7749 when N_Subprogram_Call =>
7750 return Is_List_Member (N)
7752 List_Containing (N) = Parameter_Associations (Parent (N));
7757 end Is_Actual_Parameter;
7759 --------------------------------
7760 -- Is_Actual_Tagged_Parameter --
7761 --------------------------------
7763 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
7767 Find_Actual (N, Formal, Call);
7768 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
7769 end Is_Actual_Tagged_Parameter;
7771 ---------------------
7772 -- Is_Aliased_View --
7773 ---------------------
7775 function Is_Aliased_View (Obj : Node_Id) return Boolean is
7779 if Is_Entity_Name (Obj) then
7786 or else (Present (Renamed_Object (E))
7787 and then Is_Aliased_View (Renamed_Object (E)))))
7789 or else ((Is_Formal (E)
7790 or else Ekind (E) = E_Generic_In_Out_Parameter
7791 or else Ekind (E) = E_Generic_In_Parameter)
7792 and then Is_Tagged_Type (Etype (E)))
7794 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
7796 -- Current instance of type, either directly or as rewritten
7797 -- reference to the current object.
7799 or else (Is_Entity_Name (Original_Node (Obj))
7800 and then Present (Entity (Original_Node (Obj)))
7801 and then Is_Type (Entity (Original_Node (Obj))))
7803 or else (Is_Type (E) and then E = Current_Scope)
7805 or else (Is_Incomplete_Or_Private_Type (E)
7806 and then Full_View (E) = Current_Scope)
7808 -- Ada 2012 AI05-0053: the return object of an extended return
7809 -- statement is aliased if its type is immutably limited.
7811 or else (Is_Return_Object (E)
7812 and then Is_Immutably_Limited_Type (Etype (E)));
7814 elsif Nkind (Obj) = N_Selected_Component then
7815 return Is_Aliased (Entity (Selector_Name (Obj)));
7817 elsif Nkind (Obj) = N_Indexed_Component then
7818 return Has_Aliased_Components (Etype (Prefix (Obj)))
7820 (Is_Access_Type (Etype (Prefix (Obj)))
7821 and then Has_Aliased_Components
7822 (Designated_Type (Etype (Prefix (Obj)))));
7824 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
7825 return Is_Tagged_Type (Etype (Obj))
7826 and then Is_Aliased_View (Expression (Obj));
7828 elsif Nkind (Obj) = N_Explicit_Dereference then
7829 return Nkind (Original_Node (Obj)) /= N_Function_Call;
7834 end Is_Aliased_View;
7836 -------------------------
7837 -- Is_Ancestor_Package --
7838 -------------------------
7840 function Is_Ancestor_Package
7842 E2 : Entity_Id) return Boolean
7849 and then Par /= Standard_Standard
7859 end Is_Ancestor_Package;
7861 ----------------------
7862 -- Is_Atomic_Object --
7863 ----------------------
7865 function Is_Atomic_Object (N : Node_Id) return Boolean is
7867 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
7868 -- Determines if given object has atomic components
7870 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
7871 -- If prefix is an implicit dereference, examine designated type
7873 ----------------------
7874 -- Is_Atomic_Prefix --
7875 ----------------------
7877 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
7879 if Is_Access_Type (Etype (N)) then
7881 Has_Atomic_Components (Designated_Type (Etype (N)));
7883 return Object_Has_Atomic_Components (N);
7885 end Is_Atomic_Prefix;
7887 ----------------------------------
7888 -- Object_Has_Atomic_Components --
7889 ----------------------------------
7891 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
7893 if Has_Atomic_Components (Etype (N))
7894 or else Is_Atomic (Etype (N))
7898 elsif Is_Entity_Name (N)
7899 and then (Has_Atomic_Components (Entity (N))
7900 or else Is_Atomic (Entity (N)))
7904 elsif Nkind (N) = N_Selected_Component
7905 and then Is_Atomic (Entity (Selector_Name (N)))
7909 elsif Nkind (N) = N_Indexed_Component
7910 or else Nkind (N) = N_Selected_Component
7912 return Is_Atomic_Prefix (Prefix (N));
7917 end Object_Has_Atomic_Components;
7919 -- Start of processing for Is_Atomic_Object
7922 -- Predicate is not relevant to subprograms
7924 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
7927 elsif Is_Atomic (Etype (N))
7928 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
7932 elsif Nkind (N) = N_Selected_Component
7933 and then Is_Atomic (Entity (Selector_Name (N)))
7937 elsif Nkind (N) = N_Indexed_Component
7938 or else Nkind (N) = N_Selected_Component
7940 return Is_Atomic_Prefix (Prefix (N));
7945 end Is_Atomic_Object;
7947 ------------------------------------
7948 -- Is_Body_Or_Package_Declaration --
7949 ------------------------------------
7951 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
7953 return Nkind_In (N, N_Entry_Body,
7955 N_Package_Declaration,
7959 end Is_Body_Or_Package_Declaration;
7961 -----------------------
7962 -- Is_Bounded_String --
7963 -----------------------
7965 function Is_Bounded_String (T : Entity_Id) return Boolean is
7966 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
7969 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
7970 -- Super_String, or one of the [Wide_]Wide_ versions. This will
7971 -- be True for all the Bounded_String types in instances of the
7972 -- Generic_Bounded_Length generics, and for types derived from those.
7974 return Present (Under)
7975 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
7976 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
7977 Is_RTE (Root_Type (Under), RO_WW_Super_String));
7978 end Is_Bounded_String;
7980 -----------------------------
7981 -- Is_Concurrent_Interface --
7982 -----------------------------
7984 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
7989 (Is_Protected_Interface (T)
7990 or else Is_Synchronized_Interface (T)
7991 or else Is_Task_Interface (T));
7992 end Is_Concurrent_Interface;
7994 -----------------------
7995 -- Is_Constant_Bound --
7996 -----------------------
7998 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
8000 if Compile_Time_Known_Value (Exp) then
8003 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
8004 return Is_Constant_Object (Entity (Exp))
8005 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
8007 elsif Nkind (Exp) in N_Binary_Op then
8008 return Is_Constant_Bound (Left_Opnd (Exp))
8009 and then Is_Constant_Bound (Right_Opnd (Exp))
8010 and then Scope (Entity (Exp)) = Standard_Standard;
8015 end Is_Constant_Bound;
8017 --------------------------------------
8018 -- Is_Controlling_Limited_Procedure --
8019 --------------------------------------
8021 function Is_Controlling_Limited_Procedure
8022 (Proc_Nam : Entity_Id) return Boolean
8024 Param_Typ : Entity_Id := Empty;
8027 if Ekind (Proc_Nam) = E_Procedure
8028 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
8030 Param_Typ := Etype (Parameter_Type (First (
8031 Parameter_Specifications (Parent (Proc_Nam)))));
8033 -- In this case where an Itype was created, the procedure call has been
8036 elsif Present (Associated_Node_For_Itype (Proc_Nam))
8037 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
8039 Present (Parameter_Associations
8040 (Associated_Node_For_Itype (Proc_Nam)))
8043 Etype (First (Parameter_Associations
8044 (Associated_Node_For_Itype (Proc_Nam))));
8047 if Present (Param_Typ) then
8049 Is_Interface (Param_Typ)
8050 and then Is_Limited_Record (Param_Typ);
8054 end Is_Controlling_Limited_Procedure;
8056 -----------------------------
8057 -- Is_CPP_Constructor_Call --
8058 -----------------------------
8060 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
8062 return Nkind (N) = N_Function_Call
8063 and then Is_CPP_Class (Etype (Etype (N)))
8064 and then Is_Constructor (Entity (Name (N)))
8065 and then Is_Imported (Entity (Name (N)));
8066 end Is_CPP_Constructor_Call;
8072 function Is_Delegate (T : Entity_Id) return Boolean is
8073 Desig_Type : Entity_Id;
8076 if VM_Target /= CLI_Target then
8080 -- Access-to-subprograms are delegates in CIL
8082 if Ekind (T) = E_Access_Subprogram_Type then
8086 if Ekind (T) not in Access_Kind then
8088 -- A delegate is a managed pointer. If no designated type is defined
8089 -- it means that it's not a delegate.
8094 Desig_Type := Etype (Directly_Designated_Type (T));
8096 if not Is_Tagged_Type (Desig_Type) then
8100 -- Test if the type is inherited from [mscorlib]System.Delegate
8102 while Etype (Desig_Type) /= Desig_Type loop
8103 if Chars (Scope (Desig_Type)) /= No_Name
8104 and then Is_Imported (Scope (Desig_Type))
8105 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
8110 Desig_Type := Etype (Desig_Type);
8116 ----------------------------------------------
8117 -- Is_Dependent_Component_Of_Mutable_Object --
8118 ----------------------------------------------
8120 function Is_Dependent_Component_Of_Mutable_Object
8121 (Object : Node_Id) return Boolean
8124 Prefix_Type : Entity_Id;
8125 P_Aliased : Boolean := False;
8128 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
8129 -- Returns True if and only if Comp is declared within a variant part
8131 --------------------------------
8132 -- Is_Declared_Within_Variant --
8133 --------------------------------
8135 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
8136 Comp_Decl : constant Node_Id := Parent (Comp);
8137 Comp_List : constant Node_Id := Parent (Comp_Decl);
8139 return Nkind (Parent (Comp_List)) = N_Variant;
8140 end Is_Declared_Within_Variant;
8142 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
8145 if Is_Variable (Object) then
8147 if Nkind (Object) = N_Selected_Component then
8148 P := Prefix (Object);
8149 Prefix_Type := Etype (P);
8151 if Is_Entity_Name (P) then
8153 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
8154 Prefix_Type := Base_Type (Prefix_Type);
8157 if Is_Aliased (Entity (P)) then
8161 -- A discriminant check on a selected component may be expanded
8162 -- into a dereference when removing side-effects. Recover the
8163 -- original node and its type, which may be unconstrained.
8165 elsif Nkind (P) = N_Explicit_Dereference
8166 and then not (Comes_From_Source (P))
8168 P := Original_Node (P);
8169 Prefix_Type := Etype (P);
8172 -- Check for prefix being an aliased component???
8178 -- A heap object is constrained by its initial value
8180 -- Ada 2005 (AI-363): Always assume the object could be mutable in
8181 -- the dereferenced case, since the access value might denote an
8182 -- unconstrained aliased object, whereas in Ada 95 the designated
8183 -- object is guaranteed to be constrained. A worst-case assumption
8184 -- has to apply in Ada 2005 because we can't tell at compile time
8185 -- whether the object is "constrained by its initial value"
8186 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
8187 -- semantic rules -- these rules are acknowledged to need fixing).
8189 if Ada_Version < Ada_2005 then
8190 if Is_Access_Type (Prefix_Type)
8191 or else Nkind (P) = N_Explicit_Dereference
8196 elsif Ada_Version >= Ada_2005 then
8197 if Is_Access_Type (Prefix_Type) then
8199 -- If the access type is pool-specific, and there is no
8200 -- constrained partial view of the designated type, then the
8201 -- designated object is known to be constrained.
8203 if Ekind (Prefix_Type) = E_Access_Type
8204 and then not Object_Type_Has_Constrained_Partial_View
8205 (Typ => Designated_Type (Prefix_Type),
8206 Scop => Current_Scope)
8210 -- Otherwise (general access type, or there is a constrained
8211 -- partial view of the designated type), we need to check
8212 -- based on the designated type.
8215 Prefix_Type := Designated_Type (Prefix_Type);
8221 Original_Record_Component (Entity (Selector_Name (Object)));
8223 -- As per AI-0017, the renaming is illegal in a generic body, even
8224 -- if the subtype is indefinite.
8226 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
8228 if not Is_Constrained (Prefix_Type)
8229 and then (not Is_Indefinite_Subtype (Prefix_Type)
8231 (Is_Generic_Type (Prefix_Type)
8232 and then Ekind (Current_Scope) = E_Generic_Package
8233 and then In_Package_Body (Current_Scope)))
8235 and then (Is_Declared_Within_Variant (Comp)
8236 or else Has_Discriminant_Dependent_Constraint (Comp))
8237 and then (not P_Aliased or else Ada_Version >= Ada_2005)
8241 -- If the prefix is of an access type at this point, then we want
8242 -- to return False, rather than calling this function recursively
8243 -- on the access object (which itself might be a discriminant-
8244 -- dependent component of some other object, but that isn't
8245 -- relevant to checking the object passed to us). This avoids
8246 -- issuing wrong errors when compiling with -gnatc, where there
8247 -- can be implicit dereferences that have not been expanded.
8249 elsif Is_Access_Type (Etype (Prefix (Object))) then
8254 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
8257 elsif Nkind (Object) = N_Indexed_Component
8258 or else Nkind (Object) = N_Slice
8260 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
8262 -- A type conversion that Is_Variable is a view conversion:
8263 -- go back to the denoted object.
8265 elsif Nkind (Object) = N_Type_Conversion then
8267 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
8272 end Is_Dependent_Component_Of_Mutable_Object;
8274 ---------------------
8275 -- Is_Dereferenced --
8276 ---------------------
8278 function Is_Dereferenced (N : Node_Id) return Boolean is
8279 P : constant Node_Id := Parent (N);
8282 (Nkind (P) = N_Selected_Component
8284 Nkind (P) = N_Explicit_Dereference
8286 Nkind (P) = N_Indexed_Component
8288 Nkind (P) = N_Slice)
8289 and then Prefix (P) = N;
8290 end Is_Dereferenced;
8292 ----------------------
8293 -- Is_Descendent_Of --
8294 ----------------------
8296 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
8301 pragma Assert (Nkind (T1) in N_Entity);
8302 pragma Assert (Nkind (T2) in N_Entity);
8304 T := Base_Type (T1);
8306 -- Immediate return if the types match
8311 -- Comment needed here ???
8313 elsif Ekind (T) = E_Class_Wide_Type then
8314 return Etype (T) = T2;
8322 -- Done if we found the type we are looking for
8327 -- Done if no more derivations to check
8334 -- Following test catches error cases resulting from prev errors
8336 elsif No (Etyp) then
8339 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
8342 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
8346 T := Base_Type (Etyp);
8349 end Is_Descendent_Of;
8351 ----------------------------
8352 -- Is_Expression_Function --
8353 ----------------------------
8355 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
8359 if Ekind (Subp) /= E_Function then
8363 Decl := Unit_Declaration_Node (Subp);
8364 return Nkind (Decl) = N_Subprogram_Declaration
8366 (Nkind (Original_Node (Decl)) = N_Expression_Function
8368 (Present (Corresponding_Body (Decl))
8370 Nkind (Original_Node
8371 (Unit_Declaration_Node
8372 (Corresponding_Body (Decl)))) =
8373 N_Expression_Function));
8375 end Is_Expression_Function;
8381 function Is_False (U : Uint) return Boolean is
8386 ---------------------------
8387 -- Is_Fixed_Model_Number --
8388 ---------------------------
8390 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
8391 S : constant Ureal := Small_Value (T);
8392 M : Urealp.Save_Mark;
8396 R := (U = UR_Trunc (U / S) * S);
8399 end Is_Fixed_Model_Number;
8401 -------------------------------
8402 -- Is_Fully_Initialized_Type --
8403 -------------------------------
8405 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
8407 -- In Ada2012, a scalar type with an aspect Default_Value
8408 -- is fully initialized.
8410 if Is_Scalar_Type (Typ) then
8411 return Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ);
8413 elsif Is_Access_Type (Typ) then
8416 elsif Is_Array_Type (Typ) then
8417 if Is_Fully_Initialized_Type (Component_Type (Typ))
8418 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
8423 -- An interesting case, if we have a constrained type one of whose
8424 -- bounds is known to be null, then there are no elements to be
8425 -- initialized, so all the elements are initialized!
8427 if Is_Constrained (Typ) then
8430 Indx_Typ : Entity_Id;
8434 Indx := First_Index (Typ);
8435 while Present (Indx) loop
8436 if Etype (Indx) = Any_Type then
8439 -- If index is a range, use directly
8441 elsif Nkind (Indx) = N_Range then
8442 Lbd := Low_Bound (Indx);
8443 Hbd := High_Bound (Indx);
8446 Indx_Typ := Etype (Indx);
8448 if Is_Private_Type (Indx_Typ) then
8449 Indx_Typ := Full_View (Indx_Typ);
8452 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
8455 Lbd := Type_Low_Bound (Indx_Typ);
8456 Hbd := Type_High_Bound (Indx_Typ);
8460 if Compile_Time_Known_Value (Lbd)
8461 and then Compile_Time_Known_Value (Hbd)
8463 if Expr_Value (Hbd) < Expr_Value (Lbd) then
8473 -- If no null indexes, then type is not fully initialized
8479 elsif Is_Record_Type (Typ) then
8480 if Has_Discriminants (Typ)
8482 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
8483 and then Is_Fully_Initialized_Variant (Typ)
8488 -- We consider bounded string types to be fully initialized, because
8489 -- otherwise we get false alarms when the Data component is not
8490 -- default-initialized.
8492 if Is_Bounded_String (Typ) then
8496 -- Controlled records are considered to be fully initialized if
8497 -- there is a user defined Initialize routine. This may not be
8498 -- entirely correct, but as the spec notes, we are guessing here
8499 -- what is best from the point of view of issuing warnings.
8501 if Is_Controlled (Typ) then
8503 Utyp : constant Entity_Id := Underlying_Type (Typ);
8506 if Present (Utyp) then
8508 Init : constant Entity_Id :=
8510 (Underlying_Type (Typ), Name_Initialize));
8514 and then Comes_From_Source (Init)
8516 Is_Predefined_File_Name
8517 (File_Name (Get_Source_File_Index (Sloc (Init))))
8521 elsif Has_Null_Extension (Typ)
8523 Is_Fully_Initialized_Type
8524 (Etype (Base_Type (Typ)))
8533 -- Otherwise see if all record components are initialized
8539 Ent := First_Entity (Typ);
8540 while Present (Ent) loop
8541 if Ekind (Ent) = E_Component
8542 and then (No (Parent (Ent))
8543 or else No (Expression (Parent (Ent))))
8544 and then not Is_Fully_Initialized_Type (Etype (Ent))
8546 -- Special VM case for tag components, which need to be
8547 -- defined in this case, but are never initialized as VMs
8548 -- are using other dispatching mechanisms. Ignore this
8549 -- uninitialized case. Note that this applies both to the
8550 -- uTag entry and the main vtable pointer (CPP_Class case).
8552 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
8561 -- No uninitialized components, so type is fully initialized.
8562 -- Note that this catches the case of no components as well.
8566 elsif Is_Concurrent_Type (Typ) then
8569 elsif Is_Private_Type (Typ) then
8571 U : constant Entity_Id := Underlying_Type (Typ);
8577 return Is_Fully_Initialized_Type (U);
8584 end Is_Fully_Initialized_Type;
8586 ----------------------------------
8587 -- Is_Fully_Initialized_Variant --
8588 ----------------------------------
8590 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
8591 Loc : constant Source_Ptr := Sloc (Typ);
8592 Constraints : constant List_Id := New_List;
8593 Components : constant Elist_Id := New_Elmt_List;
8594 Comp_Elmt : Elmt_Id;
8596 Comp_List : Node_Id;
8598 Discr_Val : Node_Id;
8600 Report_Errors : Boolean;
8601 pragma Warnings (Off, Report_Errors);
8604 if Serious_Errors_Detected > 0 then
8608 if Is_Record_Type (Typ)
8609 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
8610 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
8612 Comp_List := Component_List (Type_Definition (Parent (Typ)));
8614 Discr := First_Discriminant (Typ);
8615 while Present (Discr) loop
8616 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
8617 Discr_Val := Expression (Parent (Discr));
8619 if Present (Discr_Val)
8620 and then Is_OK_Static_Expression (Discr_Val)
8622 Append_To (Constraints,
8623 Make_Component_Association (Loc,
8624 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
8625 Expression => New_Copy (Discr_Val)));
8633 Next_Discriminant (Discr);
8638 Comp_List => Comp_List,
8639 Governed_By => Constraints,
8641 Report_Errors => Report_Errors);
8643 -- Check that each component present is fully initialized
8645 Comp_Elmt := First_Elmt (Components);
8646 while Present (Comp_Elmt) loop
8647 Comp_Id := Node (Comp_Elmt);
8649 if Ekind (Comp_Id) = E_Component
8650 and then (No (Parent (Comp_Id))
8651 or else No (Expression (Parent (Comp_Id))))
8652 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
8657 Next_Elmt (Comp_Elmt);
8662 elsif Is_Private_Type (Typ) then
8664 U : constant Entity_Id := Underlying_Type (Typ);
8670 return Is_Fully_Initialized_Variant (U);
8677 end Is_Fully_Initialized_Variant;
8679 ----------------------------
8680 -- Is_Inherited_Operation --
8681 ----------------------------
8683 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
8684 pragma Assert (Is_Overloadable (E));
8685 Kind : constant Node_Kind := Nkind (Parent (E));
8687 return Kind = N_Full_Type_Declaration
8688 or else Kind = N_Private_Extension_Declaration
8689 or else Kind = N_Subtype_Declaration
8690 or else (Ekind (E) = E_Enumeration_Literal
8691 and then Is_Derived_Type (Etype (E)));
8692 end Is_Inherited_Operation;
8694 -------------------------------------
8695 -- Is_Inherited_Operation_For_Type --
8696 -------------------------------------
8698 function Is_Inherited_Operation_For_Type
8700 Typ : Entity_Id) return Boolean
8703 -- Check that the operation has been created by the type declaration
8705 return Is_Inherited_Operation (E)
8706 and then Defining_Identifier (Parent (E)) = Typ;
8707 end Is_Inherited_Operation_For_Type;
8713 function Is_Iterator (Typ : Entity_Id) return Boolean is
8714 Ifaces_List : Elist_Id;
8715 Iface_Elmt : Elmt_Id;
8719 if Is_Class_Wide_Type (Typ)
8721 Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
8722 Name_Reversible_Iterator)
8724 Is_Predefined_File_Name
8725 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
8729 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
8733 Collect_Interfaces (Typ, Ifaces_List);
8735 Iface_Elmt := First_Elmt (Ifaces_List);
8736 while Present (Iface_Elmt) loop
8737 Iface := Node (Iface_Elmt);
8738 if Chars (Iface) = Name_Forward_Iterator
8740 Is_Predefined_File_Name
8741 (Unit_File_Name (Get_Source_Unit (Iface)))
8746 Next_Elmt (Iface_Elmt);
8757 -- We seem to have a lot of overlapping functions that do similar things
8758 -- (testing for left hand sides or lvalues???). Anyway, since this one is
8759 -- purely syntactic, it should be in Sem_Aux I would think???
8761 function Is_LHS (N : Node_Id) return Boolean is
8762 P : constant Node_Id := Parent (N);
8765 if Nkind (P) = N_Assignment_Statement then
8766 return Name (P) = N;
8769 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
8771 return N = Prefix (P) and then Is_LHS (P);
8778 -----------------------------
8779 -- Is_Library_Level_Entity --
8780 -----------------------------
8782 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
8784 -- The following is a small optimization, and it also properly handles
8785 -- discriminals, which in task bodies might appear in expressions before
8786 -- the corresponding procedure has been created, and which therefore do
8787 -- not have an assigned scope.
8789 if Is_Formal (E) then
8793 -- Normal test is simply that the enclosing dynamic scope is Standard
8795 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
8796 end Is_Library_Level_Entity;
8798 --------------------------------
8799 -- Is_Limited_Class_Wide_Type --
8800 --------------------------------
8802 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
8805 Is_Class_Wide_Type (Typ)
8806 and then (Is_Limited_Type (Typ) or else From_With_Type (Typ));
8807 end Is_Limited_Class_Wide_Type;
8809 ---------------------------------
8810 -- Is_Local_Variable_Reference --
8811 ---------------------------------
8813 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
8815 if not Is_Entity_Name (Expr) then
8820 Ent : constant Entity_Id := Entity (Expr);
8821 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
8823 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
8826 return Present (Sub) and then Sub = Current_Subprogram;
8830 end Is_Local_Variable_Reference;
8832 -------------------------
8833 -- Is_Object_Reference --
8834 -------------------------
8836 function Is_Object_Reference (N : Node_Id) return Boolean is
8838 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
8839 -- Determine whether N is the name of an internally-generated renaming
8841 --------------------------------------
8842 -- Is_Internally_Generated_Renaming --
8843 --------------------------------------
8845 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
8850 while Present (P) loop
8851 if Nkind (P) = N_Object_Renaming_Declaration then
8852 return not Comes_From_Source (P);
8853 elsif Is_List_Member (P) then
8861 end Is_Internally_Generated_Renaming;
8863 -- Start of processing for Is_Object_Reference
8866 if Is_Entity_Name (N) then
8867 return Present (Entity (N)) and then Is_Object (Entity (N));
8871 when N_Indexed_Component | N_Slice =>
8873 Is_Object_Reference (Prefix (N))
8874 or else Is_Access_Type (Etype (Prefix (N)));
8876 -- In Ada 95, a function call is a constant object; a procedure
8879 when N_Function_Call =>
8880 return Etype (N) /= Standard_Void_Type;
8882 -- Attributes 'Input, 'Old and 'Result produce objects
8884 when N_Attribute_Reference =>
8887 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
8889 when N_Selected_Component =>
8891 Is_Object_Reference (Selector_Name (N))
8893 (Is_Object_Reference (Prefix (N))
8894 or else Is_Access_Type (Etype (Prefix (N))));
8896 when N_Explicit_Dereference =>
8899 -- A view conversion of a tagged object is an object reference
8901 when N_Type_Conversion =>
8902 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
8903 and then Is_Tagged_Type (Etype (Expression (N)))
8904 and then Is_Object_Reference (Expression (N));
8906 -- An unchecked type conversion is considered to be an object if
8907 -- the operand is an object (this construction arises only as a
8908 -- result of expansion activities).
8910 when N_Unchecked_Type_Conversion =>
8913 -- Allow string literals to act as objects as long as they appear
8914 -- in internally-generated renamings. The expansion of iterators
8915 -- may generate such renamings when the range involves a string
8918 when N_String_Literal =>
8919 return Is_Internally_Generated_Renaming (Parent (N));
8921 -- AI05-0003: In Ada 2012 a qualified expression is a name.
8922 -- This allows disambiguation of function calls and the use
8923 -- of aggregates in more contexts.
8925 when N_Qualified_Expression =>
8926 if Ada_Version < Ada_2012 then
8929 return Is_Object_Reference (Expression (N))
8930 or else Nkind (Expression (N)) = N_Aggregate;
8937 end Is_Object_Reference;
8939 -----------------------------------
8940 -- Is_OK_Variable_For_Out_Formal --
8941 -----------------------------------
8943 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
8945 Note_Possible_Modification (AV, Sure => True);
8947 -- We must reject parenthesized variable names. Comes_From_Source is
8948 -- checked because there are currently cases where the compiler violates
8949 -- this rule (e.g. passing a task object to its controlled Initialize
8950 -- routine). This should be properly documented in sinfo???
8952 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
8955 -- A variable is always allowed
8957 elsif Is_Variable (AV) then
8960 -- Unchecked conversions are allowed only if they come from the
8961 -- generated code, which sometimes uses unchecked conversions for out
8962 -- parameters in cases where code generation is unaffected. We tell
8963 -- source unchecked conversions by seeing if they are rewrites of
8964 -- an original Unchecked_Conversion function call, or of an explicit
8965 -- conversion of a function call or an aggregate (as may happen in the
8966 -- expansion of a packed array aggregate).
8968 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
8969 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
8972 elsif Comes_From_Source (AV)
8973 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
8977 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
8978 return Is_OK_Variable_For_Out_Formal (Expression (AV));
8984 -- Normal type conversions are allowed if argument is a variable
8986 elsif Nkind (AV) = N_Type_Conversion then
8987 if Is_Variable (Expression (AV))
8988 and then Paren_Count (Expression (AV)) = 0
8990 Note_Possible_Modification (Expression (AV), Sure => True);
8993 -- We also allow a non-parenthesized expression that raises
8994 -- constraint error if it rewrites what used to be a variable
8996 elsif Raises_Constraint_Error (Expression (AV))
8997 and then Paren_Count (Expression (AV)) = 0
8998 and then Is_Variable (Original_Node (Expression (AV)))
9002 -- Type conversion of something other than a variable
9008 -- If this node is rewritten, then test the original form, if that is
9009 -- OK, then we consider the rewritten node OK (for example, if the
9010 -- original node is a conversion, then Is_Variable will not be true
9011 -- but we still want to allow the conversion if it converts a variable).
9013 elsif Original_Node (AV) /= AV then
9015 -- In Ada 2012, the explicit dereference may be a rewritten call to a
9016 -- Reference function.
9018 if Ada_Version >= Ada_2012
9019 and then Nkind (Original_Node (AV)) = N_Function_Call
9021 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
9026 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
9029 -- All other non-variables are rejected
9034 end Is_OK_Variable_For_Out_Formal;
9036 -----------------------------------
9037 -- Is_Partially_Initialized_Type --
9038 -----------------------------------
9040 function Is_Partially_Initialized_Type
9042 Include_Implicit : Boolean := True) return Boolean
9045 if Is_Scalar_Type (Typ) then
9048 elsif Is_Access_Type (Typ) then
9049 return Include_Implicit;
9051 elsif Is_Array_Type (Typ) then
9053 -- If component type is partially initialized, so is array type
9055 if Is_Partially_Initialized_Type
9056 (Component_Type (Typ), Include_Implicit)
9060 -- Otherwise we are only partially initialized if we are fully
9061 -- initialized (this is the empty array case, no point in us
9062 -- duplicating that code here).
9065 return Is_Fully_Initialized_Type (Typ);
9068 elsif Is_Record_Type (Typ) then
9070 -- A discriminated type is always partially initialized if in
9073 if Has_Discriminants (Typ) and then Include_Implicit then
9076 -- A tagged type is always partially initialized
9078 elsif Is_Tagged_Type (Typ) then
9081 -- Case of non-discriminated record
9087 Component_Present : Boolean := False;
9088 -- Set True if at least one component is present. If no
9089 -- components are present, then record type is fully
9090 -- initialized (another odd case, like the null array).
9093 -- Loop through components
9095 Ent := First_Entity (Typ);
9096 while Present (Ent) loop
9097 if Ekind (Ent) = E_Component then
9098 Component_Present := True;
9100 -- If a component has an initialization expression then
9101 -- the enclosing record type is partially initialized
9103 if Present (Parent (Ent))
9104 and then Present (Expression (Parent (Ent)))
9108 -- If a component is of a type which is itself partially
9109 -- initialized, then the enclosing record type is also.
9111 elsif Is_Partially_Initialized_Type
9112 (Etype (Ent), Include_Implicit)
9121 -- No initialized components found. If we found any components
9122 -- they were all uninitialized so the result is false.
9124 if Component_Present then
9127 -- But if we found no components, then all the components are
9128 -- initialized so we consider the type to be initialized.
9136 -- Concurrent types are always fully initialized
9138 elsif Is_Concurrent_Type (Typ) then
9141 -- For a private type, go to underlying type. If there is no underlying
9142 -- type then just assume this partially initialized. Not clear if this
9143 -- can happen in a non-error case, but no harm in testing for this.
9145 elsif Is_Private_Type (Typ) then
9147 U : constant Entity_Id := Underlying_Type (Typ);
9152 return Is_Partially_Initialized_Type (U, Include_Implicit);
9156 -- For any other type (are there any?) assume partially initialized
9161 end Is_Partially_Initialized_Type;
9163 ------------------------------------
9164 -- Is_Potentially_Persistent_Type --
9165 ------------------------------------
9167 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
9172 -- For private type, test corresponding full type
9174 if Is_Private_Type (T) then
9175 return Is_Potentially_Persistent_Type (Full_View (T));
9177 -- Scalar types are potentially persistent
9179 elsif Is_Scalar_Type (T) then
9182 -- Record type is potentially persistent if not tagged and the types of
9183 -- all it components are potentially persistent, and no component has
9184 -- an initialization expression.
9186 elsif Is_Record_Type (T)
9187 and then not Is_Tagged_Type (T)
9188 and then not Is_Partially_Initialized_Type (T)
9190 Comp := First_Component (T);
9191 while Present (Comp) loop
9192 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
9201 -- Array type is potentially persistent if its component type is
9202 -- potentially persistent and if all its constraints are static.
9204 elsif Is_Array_Type (T) then
9205 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
9209 Indx := First_Index (T);
9210 while Present (Indx) loop
9211 if not Is_OK_Static_Subtype (Etype (Indx)) then
9220 -- All other types are not potentially persistent
9225 end Is_Potentially_Persistent_Type;
9227 ---------------------------------
9228 -- Is_Protected_Self_Reference --
9229 ---------------------------------
9231 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
9233 function In_Access_Definition (N : Node_Id) return Boolean;
9234 -- Returns true if N belongs to an access definition
9236 --------------------------
9237 -- In_Access_Definition --
9238 --------------------------
9240 function In_Access_Definition (N : Node_Id) return Boolean is
9245 while Present (P) loop
9246 if Nkind (P) = N_Access_Definition then
9254 end In_Access_Definition;
9256 -- Start of processing for Is_Protected_Self_Reference
9259 -- Verify that prefix is analyzed and has the proper form. Note that
9260 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
9261 -- which also produce the address of an entity, do not analyze their
9262 -- prefix because they denote entities that are not necessarily visible.
9263 -- Neither of them can apply to a protected type.
9265 return Ada_Version >= Ada_2005
9266 and then Is_Entity_Name (N)
9267 and then Present (Entity (N))
9268 and then Is_Protected_Type (Entity (N))
9269 and then In_Open_Scopes (Entity (N))
9270 and then not In_Access_Definition (N);
9271 end Is_Protected_Self_Reference;
9273 -----------------------------
9274 -- Is_RCI_Pkg_Spec_Or_Body --
9275 -----------------------------
9277 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
9279 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
9280 -- Return True if the unit of Cunit is an RCI package declaration
9282 ---------------------------
9283 -- Is_RCI_Pkg_Decl_Cunit --
9284 ---------------------------
9286 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
9287 The_Unit : constant Node_Id := Unit (Cunit);
9290 if Nkind (The_Unit) /= N_Package_Declaration then
9294 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
9295 end Is_RCI_Pkg_Decl_Cunit;
9297 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
9300 return Is_RCI_Pkg_Decl_Cunit (Cunit)
9302 (Nkind (Unit (Cunit)) = N_Package_Body
9303 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
9304 end Is_RCI_Pkg_Spec_Or_Body;
9306 -----------------------------------------
9307 -- Is_Remote_Access_To_Class_Wide_Type --
9308 -----------------------------------------
9310 function Is_Remote_Access_To_Class_Wide_Type
9311 (E : Entity_Id) return Boolean
9314 -- A remote access to class-wide type is a general access to object type
9315 -- declared in the visible part of a Remote_Types or Remote_Call_
9318 return Ekind (E) = E_General_Access_Type
9319 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
9320 end Is_Remote_Access_To_Class_Wide_Type;
9322 -----------------------------------------
9323 -- Is_Remote_Access_To_Subprogram_Type --
9324 -----------------------------------------
9326 function Is_Remote_Access_To_Subprogram_Type
9327 (E : Entity_Id) return Boolean
9330 return (Ekind (E) = E_Access_Subprogram_Type
9331 or else (Ekind (E) = E_Record_Type
9332 and then Present (Corresponding_Remote_Type (E))))
9333 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
9334 end Is_Remote_Access_To_Subprogram_Type;
9336 --------------------
9337 -- Is_Remote_Call --
9338 --------------------
9340 function Is_Remote_Call (N : Node_Id) return Boolean is
9342 if Nkind (N) not in N_Subprogram_Call then
9344 -- An entry call cannot be remote
9348 elsif Nkind (Name (N)) in N_Has_Entity
9349 and then Is_Remote_Call_Interface (Entity (Name (N)))
9351 -- A subprogram declared in the spec of a RCI package is remote
9355 elsif Nkind (Name (N)) = N_Explicit_Dereference
9356 and then Is_Remote_Access_To_Subprogram_Type
9357 (Etype (Prefix (Name (N))))
9359 -- The dereference of a RAS is a remote call
9363 elsif Present (Controlling_Argument (N))
9364 and then Is_Remote_Access_To_Class_Wide_Type
9365 (Etype (Controlling_Argument (N)))
9367 -- Any primitive operation call with a controlling argument of
9368 -- a RACW type is a remote call.
9373 -- All other calls are local calls
9378 ----------------------
9379 -- Is_Renamed_Entry --
9380 ----------------------
9382 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
9383 Orig_Node : Node_Id := Empty;
9384 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
9386 function Is_Entry (Nam : Node_Id) return Boolean;
9387 -- Determine whether Nam is an entry. Traverse selectors if there are
9388 -- nested selected components.
9394 function Is_Entry (Nam : Node_Id) return Boolean is
9396 if Nkind (Nam) = N_Selected_Component then
9397 return Is_Entry (Selector_Name (Nam));
9400 return Ekind (Entity (Nam)) = E_Entry;
9403 -- Start of processing for Is_Renamed_Entry
9406 if Present (Alias (Proc_Nam)) then
9407 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
9410 -- Look for a rewritten subprogram renaming declaration
9412 if Nkind (Subp_Decl) = N_Subprogram_Declaration
9413 and then Present (Original_Node (Subp_Decl))
9415 Orig_Node := Original_Node (Subp_Decl);
9418 -- The rewritten subprogram is actually an entry
9420 if Present (Orig_Node)
9421 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
9422 and then Is_Entry (Name (Orig_Node))
9428 end Is_Renamed_Entry;
9430 ----------------------------
9431 -- Is_Reversible_Iterator --
9432 ----------------------------
9434 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
9435 Ifaces_List : Elist_Id;
9436 Iface_Elmt : Elmt_Id;
9440 if Is_Class_Wide_Type (Typ)
9441 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
9443 Is_Predefined_File_Name
9444 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
9448 elsif not Is_Tagged_Type (Typ)
9449 or else not Is_Derived_Type (Typ)
9454 Collect_Interfaces (Typ, Ifaces_List);
9456 Iface_Elmt := First_Elmt (Ifaces_List);
9457 while Present (Iface_Elmt) loop
9458 Iface := Node (Iface_Elmt);
9459 if Chars (Iface) = Name_Reversible_Iterator
9461 Is_Predefined_File_Name
9462 (Unit_File_Name (Get_Source_Unit (Iface)))
9467 Next_Elmt (Iface_Elmt);
9472 end Is_Reversible_Iterator;
9474 ----------------------
9475 -- Is_Selector_Name --
9476 ----------------------
9478 function Is_Selector_Name (N : Node_Id) return Boolean is
9480 if not Is_List_Member (N) then
9482 P : constant Node_Id := Parent (N);
9483 K : constant Node_Kind := Nkind (P);
9486 (K = N_Expanded_Name or else
9487 K = N_Generic_Association or else
9488 K = N_Parameter_Association or else
9489 K = N_Selected_Component)
9490 and then Selector_Name (P) = N;
9495 L : constant List_Id := List_Containing (N);
9496 P : constant Node_Id := Parent (L);
9498 return (Nkind (P) = N_Discriminant_Association
9499 and then Selector_Names (P) = L)
9501 (Nkind (P) = N_Component_Association
9502 and then Choices (P) = L);
9505 end Is_Selector_Name;
9507 ----------------------------------
9508 -- Is_SPARK_Initialization_Expr --
9509 ----------------------------------
9511 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
9514 Comp_Assn : Node_Id;
9515 Orig_N : constant Node_Id := Original_Node (N);
9520 if not Comes_From_Source (Orig_N) then
9524 pragma Assert (Nkind (Orig_N) in N_Subexpr);
9526 case Nkind (Orig_N) is
9527 when N_Character_Literal |
9535 if Is_Entity_Name (Orig_N)
9536 and then Present (Entity (Orig_N)) -- needed in some cases
9538 case Ekind (Entity (Orig_N)) is
9540 E_Enumeration_Literal |
9545 if Is_Type (Entity (Orig_N)) then
9553 when N_Qualified_Expression |
9554 N_Type_Conversion =>
9555 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
9558 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
9562 N_Membership_Test =>
9563 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
9564 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
9567 N_Extension_Aggregate =>
9568 if Nkind (Orig_N) = N_Extension_Aggregate then
9569 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
9572 Expr := First (Expressions (Orig_N));
9573 while Present (Expr) loop
9574 if not Is_SPARK_Initialization_Expr (Expr) then
9582 Comp_Assn := First (Component_Associations (Orig_N));
9583 while Present (Comp_Assn) loop
9584 Expr := Expression (Comp_Assn);
9585 if Present (Expr) -- needed for box association
9586 and then not Is_SPARK_Initialization_Expr (Expr)
9595 when N_Attribute_Reference =>
9596 if Nkind (Prefix (Orig_N)) in N_Subexpr then
9597 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
9600 Expr := First (Expressions (Orig_N));
9601 while Present (Expr) loop
9602 if not Is_SPARK_Initialization_Expr (Expr) then
9610 -- Selected components might be expanded named not yet resolved, so
9611 -- default on the safe side. (Eg on sparklex.ads)
9613 when N_Selected_Component =>
9622 end Is_SPARK_Initialization_Expr;
9624 -------------------------------
9625 -- Is_SPARK_Object_Reference --
9626 -------------------------------
9628 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
9630 if Is_Entity_Name (N) then
9631 return Present (Entity (N))
9633 (Ekind_In (Entity (N), E_Constant, E_Variable)
9634 or else Ekind (Entity (N)) in Formal_Kind);
9638 when N_Selected_Component =>
9639 return Is_SPARK_Object_Reference (Prefix (N));
9645 end Is_SPARK_Object_Reference;
9651 function Is_Statement (N : Node_Id) return Boolean is
9654 Nkind (N) in N_Statement_Other_Than_Procedure_Call
9655 or else Nkind (N) = N_Procedure_Call_Statement;
9658 --------------------------------------------------
9659 -- Is_Subprogram_Stub_Without_Prior_Declaration --
9660 --------------------------------------------------
9662 function Is_Subprogram_Stub_Without_Prior_Declaration
9663 (N : Node_Id) return Boolean
9666 -- A subprogram stub without prior declaration serves as declaration for
9667 -- the actual subprogram body. As such, it has an attached defining
9668 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
9670 return Nkind (N) = N_Subprogram_Body_Stub
9671 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
9672 end Is_Subprogram_Stub_Without_Prior_Declaration;
9674 ---------------------------------
9675 -- Is_Synchronized_Tagged_Type --
9676 ---------------------------------
9678 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
9679 Kind : constant Entity_Kind := Ekind (Base_Type (E));
9682 -- A task or protected type derived from an interface is a tagged type.
9683 -- Such a tagged type is called a synchronized tagged type, as are
9684 -- synchronized interfaces and private extensions whose declaration
9685 -- includes the reserved word synchronized.
9687 return (Is_Tagged_Type (E)
9688 and then (Kind = E_Task_Type
9689 or else Kind = E_Protected_Type))
9692 and then Is_Synchronized_Interface (E))
9694 (Ekind (E) = E_Record_Type_With_Private
9695 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
9696 and then (Synchronized_Present (Parent (E))
9697 or else Is_Synchronized_Interface (Etype (E))));
9698 end Is_Synchronized_Tagged_Type;
9704 function Is_Transfer (N : Node_Id) return Boolean is
9705 Kind : constant Node_Kind := Nkind (N);
9708 if Kind = N_Simple_Return_Statement
9710 Kind = N_Extended_Return_Statement
9712 Kind = N_Goto_Statement
9714 Kind = N_Raise_Statement
9716 Kind = N_Requeue_Statement
9720 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
9721 and then No (Condition (N))
9725 elsif Kind = N_Procedure_Call_Statement
9726 and then Is_Entity_Name (Name (N))
9727 and then Present (Entity (Name (N)))
9728 and then No_Return (Entity (Name (N)))
9732 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
9744 function Is_True (U : Uint) return Boolean is
9749 -------------------------------
9750 -- Is_Universal_Numeric_Type --
9751 -------------------------------
9753 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
9755 return T = Universal_Integer or else T = Universal_Real;
9756 end Is_Universal_Numeric_Type;
9762 function Is_Value_Type (T : Entity_Id) return Boolean is
9764 return VM_Target = CLI_Target
9765 and then Nkind (T) in N_Has_Chars
9766 and then Chars (T) /= No_Name
9767 and then Get_Name_String (Chars (T)) = "valuetype";
9770 ----------------------------
9771 -- Is_Variable_Size_Array --
9772 ----------------------------
9774 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
9778 pragma Assert (Is_Array_Type (E));
9780 -- Check if some index is initialized with a non-constant value
9782 Idx := First_Index (E);
9783 while Present (Idx) loop
9784 if Nkind (Idx) = N_Range then
9785 if not Is_Constant_Bound (Low_Bound (Idx))
9786 or else not Is_Constant_Bound (High_Bound (Idx))
9792 Idx := Next_Index (Idx);
9796 end Is_Variable_Size_Array;
9798 -----------------------------
9799 -- Is_Variable_Size_Record --
9800 -----------------------------
9802 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
9804 Comp_Typ : Entity_Id;
9807 pragma Assert (Is_Record_Type (E));
9809 Comp := First_Entity (E);
9810 while Present (Comp) loop
9811 Comp_Typ := Etype (Comp);
9813 -- Recursive call if the record type has discriminants
9815 if Is_Record_Type (Comp_Typ)
9816 and then Has_Discriminants (Comp_Typ)
9817 and then Is_Variable_Size_Record (Comp_Typ)
9821 elsif Is_Array_Type (Comp_Typ)
9822 and then Is_Variable_Size_Array (Comp_Typ)
9831 end Is_Variable_Size_Record;
9833 ---------------------
9834 -- Is_VMS_Operator --
9835 ---------------------
9837 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
9839 -- The VMS operators are declared in a child of System that is loaded
9840 -- through pragma Extend_System. In some rare cases a program is run
9841 -- with this extension but without indicating that the target is VMS.
9843 return Ekind (Op) = E_Function
9844 and then Is_Intrinsic_Subprogram (Op)
9846 ((Present_System_Aux and then Scope (Op) = System_Aux_Id)
9849 and then Scope (Scope (Op)) = RTU_Entity (System)));
9850 end Is_VMS_Operator;
9856 function Is_Variable
9858 Use_Original_Node : Boolean := True) return Boolean
9860 Orig_Node : Node_Id;
9862 function In_Protected_Function (E : Entity_Id) return Boolean;
9863 -- Within a protected function, the private components of the enclosing
9864 -- protected type are constants. A function nested within a (protected)
9865 -- procedure is not itself protected.
9867 function Is_Variable_Prefix (P : Node_Id) return Boolean;
9868 -- Prefixes can involve implicit dereferences, in which case we must
9869 -- test for the case of a reference of a constant access type, which can
9870 -- can never be a variable.
9872 ---------------------------
9873 -- In_Protected_Function --
9874 ---------------------------
9876 function In_Protected_Function (E : Entity_Id) return Boolean is
9877 Prot : constant Entity_Id := Scope (E);
9881 if not Is_Protected_Type (Prot) then
9885 while Present (S) and then S /= Prot loop
9886 if Ekind (S) = E_Function and then Scope (S) = Prot then
9895 end In_Protected_Function;
9897 ------------------------
9898 -- Is_Variable_Prefix --
9899 ------------------------
9901 function Is_Variable_Prefix (P : Node_Id) return Boolean is
9903 if Is_Access_Type (Etype (P)) then
9904 return not Is_Access_Constant (Root_Type (Etype (P)));
9906 -- For the case of an indexed component whose prefix has a packed
9907 -- array type, the prefix has been rewritten into a type conversion.
9908 -- Determine variable-ness from the converted expression.
9910 elsif Nkind (P) = N_Type_Conversion
9911 and then not Comes_From_Source (P)
9912 and then Is_Array_Type (Etype (P))
9913 and then Is_Packed (Etype (P))
9915 return Is_Variable (Expression (P));
9918 return Is_Variable (P);
9920 end Is_Variable_Prefix;
9922 -- Start of processing for Is_Variable
9925 -- Check if we perform the test on the original node since this may be a
9926 -- test of syntactic categories which must not be disturbed by whatever
9927 -- rewriting might have occurred. For example, an aggregate, which is
9928 -- certainly NOT a variable, could be turned into a variable by
9931 if Use_Original_Node then
9932 Orig_Node := Original_Node (N);
9937 -- Definitely OK if Assignment_OK is set. Since this is something that
9938 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
9940 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
9943 -- Normally we go to the original node, but there is one exception where
9944 -- we use the rewritten node, namely when it is an explicit dereference.
9945 -- The generated code may rewrite a prefix which is an access type with
9946 -- an explicit dereference. The dereference is a variable, even though
9947 -- the original node may not be (since it could be a constant of the
9950 -- In Ada 2005 we have a further case to consider: the prefix may be a
9951 -- function call given in prefix notation. The original node appears to
9952 -- be a selected component, but we need to examine the call.
9954 elsif Nkind (N) = N_Explicit_Dereference
9955 and then Nkind (Orig_Node) /= N_Explicit_Dereference
9956 and then Present (Etype (Orig_Node))
9957 and then Is_Access_Type (Etype (Orig_Node))
9959 -- Note that if the prefix is an explicit dereference that does not
9960 -- come from source, we must check for a rewritten function call in
9961 -- prefixed notation before other forms of rewriting, to prevent a
9965 (Nkind (Orig_Node) = N_Function_Call
9966 and then not Is_Access_Constant (Etype (Prefix (N))))
9968 Is_Variable_Prefix (Original_Node (Prefix (N)));
9970 -- in Ada 2012, the dereference may have been added for a type with
9971 -- a declared implicit dereference aspect.
9973 elsif Nkind (N) = N_Explicit_Dereference
9974 and then Present (Etype (Orig_Node))
9975 and then Ada_Version >= Ada_2012
9976 and then Has_Implicit_Dereference (Etype (Orig_Node))
9980 -- A function call is never a variable
9982 elsif Nkind (N) = N_Function_Call then
9985 -- All remaining checks use the original node
9987 elsif Is_Entity_Name (Orig_Node)
9988 and then Present (Entity (Orig_Node))
9991 E : constant Entity_Id := Entity (Orig_Node);
9992 K : constant Entity_Kind := Ekind (E);
9995 return (K = E_Variable
9996 and then Nkind (Parent (E)) /= N_Exception_Handler)
9997 or else (K = E_Component
9998 and then not In_Protected_Function (E))
9999 or else K = E_Out_Parameter
10000 or else K = E_In_Out_Parameter
10001 or else K = E_Generic_In_Out_Parameter
10003 -- Current instance of type
10005 or else (Is_Type (E) and then In_Open_Scopes (E))
10006 or else (Is_Incomplete_Or_Private_Type (E)
10007 and then In_Open_Scopes (Full_View (E)));
10011 case Nkind (Orig_Node) is
10012 when N_Indexed_Component | N_Slice =>
10013 return Is_Variable_Prefix (Prefix (Orig_Node));
10015 when N_Selected_Component =>
10016 return Is_Variable_Prefix (Prefix (Orig_Node))
10017 and then Is_Variable (Selector_Name (Orig_Node));
10019 -- For an explicit dereference, the type of the prefix cannot
10020 -- be an access to constant or an access to subprogram.
10022 when N_Explicit_Dereference =>
10024 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
10026 return Is_Access_Type (Typ)
10027 and then not Is_Access_Constant (Root_Type (Typ))
10028 and then Ekind (Typ) /= E_Access_Subprogram_Type;
10031 -- The type conversion is the case where we do not deal with the
10032 -- context dependent special case of an actual parameter. Thus
10033 -- the type conversion is only considered a variable for the
10034 -- purposes of this routine if the target type is tagged. However,
10035 -- a type conversion is considered to be a variable if it does not
10036 -- come from source (this deals for example with the conversions
10037 -- of expressions to their actual subtypes).
10039 when N_Type_Conversion =>
10040 return Is_Variable (Expression (Orig_Node))
10042 (not Comes_From_Source (Orig_Node)
10044 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
10046 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
10048 -- GNAT allows an unchecked type conversion as a variable. This
10049 -- only affects the generation of internal expanded code, since
10050 -- calls to instantiations of Unchecked_Conversion are never
10051 -- considered variables (since they are function calls).
10053 when N_Unchecked_Type_Conversion =>
10054 return Is_Variable (Expression (Orig_Node));
10062 ---------------------------
10063 -- Is_Visibly_Controlled --
10064 ---------------------------
10066 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
10067 Root : constant Entity_Id := Root_Type (T);
10069 return Chars (Scope (Root)) = Name_Finalization
10070 and then Chars (Scope (Scope (Root))) = Name_Ada
10071 and then Scope (Scope (Scope (Root))) = Standard_Standard;
10072 end Is_Visibly_Controlled;
10074 ------------------------
10075 -- Is_Volatile_Object --
10076 ------------------------
10078 function Is_Volatile_Object (N : Node_Id) return Boolean is
10080 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
10081 -- Determines if given object has volatile components
10083 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
10084 -- If prefix is an implicit dereference, examine designated type
10086 ------------------------
10087 -- Is_Volatile_Prefix --
10088 ------------------------
10090 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
10091 Typ : constant Entity_Id := Etype (N);
10094 if Is_Access_Type (Typ) then
10096 Dtyp : constant Entity_Id := Designated_Type (Typ);
10099 return Is_Volatile (Dtyp)
10100 or else Has_Volatile_Components (Dtyp);
10104 return Object_Has_Volatile_Components (N);
10106 end Is_Volatile_Prefix;
10108 ------------------------------------
10109 -- Object_Has_Volatile_Components --
10110 ------------------------------------
10112 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
10113 Typ : constant Entity_Id := Etype (N);
10116 if Is_Volatile (Typ)
10117 or else Has_Volatile_Components (Typ)
10121 elsif Is_Entity_Name (N)
10122 and then (Has_Volatile_Components (Entity (N))
10123 or else Is_Volatile (Entity (N)))
10127 elsif Nkind (N) = N_Indexed_Component
10128 or else Nkind (N) = N_Selected_Component
10130 return Is_Volatile_Prefix (Prefix (N));
10135 end Object_Has_Volatile_Components;
10137 -- Start of processing for Is_Volatile_Object
10140 if Is_Volatile (Etype (N))
10141 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
10145 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
10146 and then Is_Volatile_Prefix (Prefix (N))
10150 elsif Nkind (N) = N_Selected_Component
10151 and then Is_Volatile (Entity (Selector_Name (N)))
10158 end Is_Volatile_Object;
10160 ---------------------------
10161 -- Itype_Has_Declaration --
10162 ---------------------------
10164 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
10166 pragma Assert (Is_Itype (Id));
10167 return Present (Parent (Id))
10168 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
10169 N_Subtype_Declaration)
10170 and then Defining_Entity (Parent (Id)) = Id;
10171 end Itype_Has_Declaration;
10173 -------------------------
10174 -- Kill_Current_Values --
10175 -------------------------
10177 procedure Kill_Current_Values
10179 Last_Assignment_Only : Boolean := False)
10182 -- ??? do we have to worry about clearing cached checks?
10184 if Is_Assignable (Ent) then
10185 Set_Last_Assignment (Ent, Empty);
10188 if Is_Object (Ent) then
10189 if not Last_Assignment_Only then
10191 Set_Current_Value (Ent, Empty);
10193 if not Can_Never_Be_Null (Ent) then
10194 Set_Is_Known_Non_Null (Ent, False);
10197 Set_Is_Known_Null (Ent, False);
10199 -- Reset Is_Known_Valid unless type is always valid, or if we have
10200 -- a loop parameter (loop parameters are always valid, since their
10201 -- bounds are defined by the bounds given in the loop header).
10203 if not Is_Known_Valid (Etype (Ent))
10204 and then Ekind (Ent) /= E_Loop_Parameter
10206 Set_Is_Known_Valid (Ent, False);
10210 end Kill_Current_Values;
10212 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
10215 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
10216 -- Clear current value for entity E and all entities chained to E
10218 ------------------------------------------
10219 -- Kill_Current_Values_For_Entity_Chain --
10220 ------------------------------------------
10222 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
10226 while Present (Ent) loop
10227 Kill_Current_Values (Ent, Last_Assignment_Only);
10230 end Kill_Current_Values_For_Entity_Chain;
10232 -- Start of processing for Kill_Current_Values
10235 -- Kill all saved checks, a special case of killing saved values
10237 if not Last_Assignment_Only then
10241 -- Loop through relevant scopes, which includes the current scope and
10242 -- any parent scopes if the current scope is a block or a package.
10244 S := Current_Scope;
10247 -- Clear current values of all entities in current scope
10249 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
10251 -- If scope is a package, also clear current values of all private
10252 -- entities in the scope.
10254 if Is_Package_Or_Generic_Package (S)
10255 or else Is_Concurrent_Type (S)
10257 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
10260 -- If this is a not a subprogram, deal with parents
10262 if not Is_Subprogram (S) then
10264 exit Scope_Loop when S = Standard_Standard;
10268 end loop Scope_Loop;
10269 end Kill_Current_Values;
10271 --------------------------
10272 -- Kill_Size_Check_Code --
10273 --------------------------
10275 procedure Kill_Size_Check_Code (E : Entity_Id) is
10277 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
10278 and then Present (Size_Check_Code (E))
10280 Remove (Size_Check_Code (E));
10281 Set_Size_Check_Code (E, Empty);
10283 end Kill_Size_Check_Code;
10285 --------------------------
10286 -- Known_To_Be_Assigned --
10287 --------------------------
10289 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
10290 P : constant Node_Id := Parent (N);
10295 -- Test left side of assignment
10297 when N_Assignment_Statement =>
10298 return N = Name (P);
10300 -- Function call arguments are never lvalues
10302 when N_Function_Call =>
10305 -- Positional parameter for procedure or accept call
10307 when N_Procedure_Call_Statement |
10316 Proc := Get_Subprogram_Entity (P);
10322 -- If we are not a list member, something is strange, so
10323 -- be conservative and return False.
10325 if not Is_List_Member (N) then
10329 -- We are going to find the right formal by stepping forward
10330 -- through the formals, as we step backwards in the actuals.
10332 Form := First_Formal (Proc);
10335 -- If no formal, something is weird, so be conservative
10336 -- and return False.
10343 exit when No (Act);
10344 Next_Formal (Form);
10347 return Ekind (Form) /= E_In_Parameter;
10350 -- Named parameter for procedure or accept call
10352 when N_Parameter_Association =>
10358 Proc := Get_Subprogram_Entity (Parent (P));
10364 -- Loop through formals to find the one that matches
10366 Form := First_Formal (Proc);
10368 -- If no matching formal, that's peculiar, some kind of
10369 -- previous error, so return False to be conservative.
10370 -- Actually this also happens in legal code in the case
10371 -- where P is a parameter association for an Extra_Formal???
10377 -- Else test for match
10379 if Chars (Form) = Chars (Selector_Name (P)) then
10380 return Ekind (Form) /= E_In_Parameter;
10383 Next_Formal (Form);
10387 -- Test for appearing in a conversion that itself appears
10388 -- in an lvalue context, since this should be an lvalue.
10390 when N_Type_Conversion =>
10391 return Known_To_Be_Assigned (P);
10393 -- All other references are definitely not known to be modifications
10399 end Known_To_Be_Assigned;
10401 ---------------------------
10402 -- Last_Source_Statement --
10403 ---------------------------
10405 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
10409 N := Last (Statements (HSS));
10410 while Present (N) loop
10411 exit when Comes_From_Source (N);
10416 end Last_Source_Statement;
10418 ----------------------------------
10419 -- Matching_Static_Array_Bounds --
10420 ----------------------------------
10422 function Matching_Static_Array_Bounds
10424 R_Typ : Node_Id) return Boolean
10426 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
10427 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
10439 if L_Ndims /= R_Ndims then
10443 -- Unconstrained types do not have static bounds
10445 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
10449 -- First treat specially the first dimension, as the lower bound and
10450 -- length of string literals are not stored like those of arrays.
10452 if Ekind (L_Typ) = E_String_Literal_Subtype then
10453 L_Low := String_Literal_Low_Bound (L_Typ);
10454 L_Len := String_Literal_Length (L_Typ);
10456 L_Index := First_Index (L_Typ);
10457 Get_Index_Bounds (L_Index, L_Low, L_High);
10459 if Is_OK_Static_Expression (L_Low)
10460 and then Is_OK_Static_Expression (L_High)
10462 if Expr_Value (L_High) < Expr_Value (L_Low) then
10465 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
10472 if Ekind (R_Typ) = E_String_Literal_Subtype then
10473 R_Low := String_Literal_Low_Bound (R_Typ);
10474 R_Len := String_Literal_Length (R_Typ);
10476 R_Index := First_Index (R_Typ);
10477 Get_Index_Bounds (R_Index, R_Low, R_High);
10479 if Is_OK_Static_Expression (R_Low)
10480 and then Is_OK_Static_Expression (R_High)
10482 if Expr_Value (R_High) < Expr_Value (R_Low) then
10485 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
10492 if Is_OK_Static_Expression (L_Low)
10493 and then Is_OK_Static_Expression (R_Low)
10494 and then Expr_Value (L_Low) = Expr_Value (R_Low)
10495 and then L_Len = R_Len
10502 -- Then treat all other dimensions
10504 for Indx in 2 .. L_Ndims loop
10508 Get_Index_Bounds (L_Index, L_Low, L_High);
10509 Get_Index_Bounds (R_Index, R_Low, R_High);
10511 if Is_OK_Static_Expression (L_Low)
10512 and then Is_OK_Static_Expression (L_High)
10513 and then Is_OK_Static_Expression (R_Low)
10514 and then Is_OK_Static_Expression (R_High)
10515 and then Expr_Value (L_Low) = Expr_Value (R_Low)
10516 and then Expr_Value (L_High) = Expr_Value (R_High)
10524 -- If we fall through the loop, all indexes matched
10527 end Matching_Static_Array_Bounds;
10529 -------------------
10530 -- May_Be_Lvalue --
10531 -------------------
10533 function May_Be_Lvalue (N : Node_Id) return Boolean is
10534 P : constant Node_Id := Parent (N);
10539 -- Test left side of assignment
10541 when N_Assignment_Statement =>
10542 return N = Name (P);
10544 -- Test prefix of component or attribute. Note that the prefix of an
10545 -- explicit or implicit dereference cannot be an l-value.
10547 when N_Attribute_Reference =>
10548 return N = Prefix (P)
10549 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
10551 -- For an expanded name, the name is an lvalue if the expanded name
10552 -- is an lvalue, but the prefix is never an lvalue, since it is just
10553 -- the scope where the name is found.
10555 when N_Expanded_Name =>
10556 if N = Prefix (P) then
10557 return May_Be_Lvalue (P);
10562 -- For a selected component A.B, A is certainly an lvalue if A.B is.
10563 -- B is a little interesting, if we have A.B := 3, there is some
10564 -- discussion as to whether B is an lvalue or not, we choose to say
10565 -- it is. Note however that A is not an lvalue if it is of an access
10566 -- type since this is an implicit dereference.
10568 when N_Selected_Component =>
10570 and then Present (Etype (N))
10571 and then Is_Access_Type (Etype (N))
10575 return May_Be_Lvalue (P);
10578 -- For an indexed component or slice, the index or slice bounds is
10579 -- never an lvalue. The prefix is an lvalue if the indexed component
10580 -- or slice is an lvalue, except if it is an access type, where we
10581 -- have an implicit dereference.
10583 when N_Indexed_Component | N_Slice =>
10585 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
10589 return May_Be_Lvalue (P);
10592 -- Prefix of a reference is an lvalue if the reference is an lvalue
10594 when N_Reference =>
10595 return May_Be_Lvalue (P);
10597 -- Prefix of explicit dereference is never an lvalue
10599 when N_Explicit_Dereference =>
10602 -- Positional parameter for subprogram, entry, or accept call.
10603 -- In older versions of Ada function call arguments are never
10604 -- lvalues. In Ada 2012 functions can have in-out parameters.
10606 when N_Subprogram_Call |
10607 N_Entry_Call_Statement |
10610 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
10614 -- The following mechanism is clumsy and fragile. A single flag
10615 -- set in Resolve_Actuals would be preferable ???
10623 Proc := Get_Subprogram_Entity (P);
10629 -- If we are not a list member, something is strange, so be
10630 -- conservative and return True.
10632 if not Is_List_Member (N) then
10636 -- We are going to find the right formal by stepping forward
10637 -- through the formals, as we step backwards in the actuals.
10639 Form := First_Formal (Proc);
10642 -- If no formal, something is weird, so be conservative and
10650 exit when No (Act);
10651 Next_Formal (Form);
10654 return Ekind (Form) /= E_In_Parameter;
10657 -- Named parameter for procedure or accept call
10659 when N_Parameter_Association =>
10665 Proc := Get_Subprogram_Entity (Parent (P));
10671 -- Loop through formals to find the one that matches
10673 Form := First_Formal (Proc);
10675 -- If no matching formal, that's peculiar, some kind of
10676 -- previous error, so return True to be conservative.
10677 -- Actually happens with legal code for an unresolved call
10678 -- where we may get the wrong homonym???
10684 -- Else test for match
10686 if Chars (Form) = Chars (Selector_Name (P)) then
10687 return Ekind (Form) /= E_In_Parameter;
10690 Next_Formal (Form);
10694 -- Test for appearing in a conversion that itself appears in an
10695 -- lvalue context, since this should be an lvalue.
10697 when N_Type_Conversion =>
10698 return May_Be_Lvalue (P);
10700 -- Test for appearance in object renaming declaration
10702 when N_Object_Renaming_Declaration =>
10705 -- All other references are definitely not lvalues
10713 -----------------------
10714 -- Mark_Coextensions --
10715 -----------------------
10717 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
10718 Is_Dynamic : Boolean;
10719 -- Indicates whether the context causes nested coextensions to be
10720 -- dynamic or static
10722 function Mark_Allocator (N : Node_Id) return Traverse_Result;
10723 -- Recognize an allocator node and label it as a dynamic coextension
10725 --------------------
10726 -- Mark_Allocator --
10727 --------------------
10729 function Mark_Allocator (N : Node_Id) return Traverse_Result is
10731 if Nkind (N) = N_Allocator then
10733 Set_Is_Dynamic_Coextension (N);
10735 -- If the allocator expression is potentially dynamic, it may
10736 -- be expanded out of order and require dynamic allocation
10737 -- anyway, so we treat the coextension itself as dynamic.
10738 -- Potential optimization ???
10740 elsif Nkind (Expression (N)) = N_Qualified_Expression
10741 and then Nkind (Expression (Expression (N))) = N_Op_Concat
10743 Set_Is_Dynamic_Coextension (N);
10745 Set_Is_Static_Coextension (N);
10750 end Mark_Allocator;
10752 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
10754 -- Start of processing Mark_Coextensions
10757 case Nkind (Context_Nod) is
10759 -- Comment here ???
10761 when N_Assignment_Statement =>
10762 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
10764 -- An allocator that is a component of a returned aggregate
10765 -- must be dynamic.
10767 when N_Simple_Return_Statement =>
10769 Expr : constant Node_Id := Expression (Context_Nod);
10772 Nkind (Expr) = N_Allocator
10774 (Nkind (Expr) = N_Qualified_Expression
10775 and then Nkind (Expression (Expr)) = N_Aggregate);
10778 -- An alloctor within an object declaration in an extended return
10779 -- statement is of necessity dynamic.
10781 when N_Object_Declaration =>
10782 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
10784 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
10786 -- This routine should not be called for constructs which may not
10787 -- contain coextensions.
10790 raise Program_Error;
10793 Mark_Allocators (Root_Nod);
10794 end Mark_Coextensions;
10800 function Must_Inline (Subp : Entity_Id) return Boolean is
10803 (Optimization_Level = 0
10805 -- AAMP and VM targets have no support for inlining in the backend.
10806 -- Hence we do as much inlining as possible in the front end.
10808 or else AAMP_On_Target
10809 or else VM_Target /= No_VM)
10810 and then Has_Pragma_Inline (Subp)
10811 and then (Has_Pragma_Inline_Always (Subp) or else Front_End_Inlining);
10814 ----------------------
10815 -- Needs_One_Actual --
10816 ----------------------
10818 function Needs_One_Actual (E : Entity_Id) return Boolean is
10819 Formal : Entity_Id;
10822 -- Ada 2005 or later, and formals present
10824 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
10825 Formal := Next_Formal (First_Formal (E));
10826 while Present (Formal) loop
10827 if No (Default_Value (Formal)) then
10831 Next_Formal (Formal);
10836 -- Ada 83/95 or no formals
10841 end Needs_One_Actual;
10843 ------------------------
10844 -- New_Copy_List_Tree --
10845 ------------------------
10847 function New_Copy_List_Tree (List : List_Id) return List_Id is
10852 if List = No_List then
10859 while Present (E) loop
10860 Append (New_Copy_Tree (E), NL);
10866 end New_Copy_List_Tree;
10868 -------------------
10869 -- New_Copy_Tree --
10870 -------------------
10872 use Atree.Unchecked_Access;
10873 use Atree_Private_Part;
10875 -- Our approach here requires a two pass traversal of the tree. The
10876 -- first pass visits all nodes that eventually will be copied looking
10877 -- for defining Itypes. If any defining Itypes are found, then they are
10878 -- copied, and an entry is added to the replacement map. In the second
10879 -- phase, the tree is copied, using the replacement map to replace any
10880 -- Itype references within the copied tree.
10882 -- The following hash tables are used if the Map supplied has more
10883 -- than hash threshold entries to speed up access to the map. If
10884 -- there are fewer entries, then the map is searched sequentially
10885 -- (because setting up a hash table for only a few entries takes
10886 -- more time than it saves.
10888 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
10889 -- Hash function used for hash operations
10891 -------------------
10892 -- New_Copy_Hash --
10893 -------------------
10895 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
10897 return Nat (E) mod (NCT_Header_Num'Last + 1);
10904 -- The hash table NCT_Assoc associates old entities in the table
10905 -- with their corresponding new entities (i.e. the pairs of entries
10906 -- presented in the original Map argument are Key-Element pairs).
10908 package NCT_Assoc is new Simple_HTable (
10909 Header_Num => NCT_Header_Num,
10910 Element => Entity_Id,
10911 No_Element => Empty,
10913 Hash => New_Copy_Hash,
10914 Equal => Types."=");
10916 ---------------------
10917 -- NCT_Itype_Assoc --
10918 ---------------------
10920 -- The hash table NCT_Itype_Assoc contains entries only for those
10921 -- old nodes which have a non-empty Associated_Node_For_Itype set.
10922 -- The key is the associated node, and the element is the new node
10923 -- itself (NOT the associated node for the new node).
10925 package NCT_Itype_Assoc is new Simple_HTable (
10926 Header_Num => NCT_Header_Num,
10927 Element => Entity_Id,
10928 No_Element => Empty,
10930 Hash => New_Copy_Hash,
10931 Equal => Types."=");
10933 -- Start of processing for New_Copy_Tree function
10935 function New_Copy_Tree
10937 Map : Elist_Id := No_Elist;
10938 New_Sloc : Source_Ptr := No_Location;
10939 New_Scope : Entity_Id := Empty) return Node_Id
10941 Actual_Map : Elist_Id := Map;
10942 -- This is the actual map for the copy. It is initialized with the
10943 -- given elements, and then enlarged as required for Itypes that are
10944 -- copied during the first phase of the copy operation. The visit
10945 -- procedures add elements to this map as Itypes are encountered.
10946 -- The reason we cannot use Map directly, is that it may well be
10947 -- (and normally is) initialized to No_Elist, and if we have mapped
10948 -- entities, we have to reset it to point to a real Elist.
10950 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
10951 -- Called during second phase to map entities into their corresponding
10952 -- copies using Actual_Map. If the argument is not an entity, or is not
10953 -- in Actual_Map, then it is returned unchanged.
10955 procedure Build_NCT_Hash_Tables;
10956 -- Builds hash tables (number of elements >= threshold value)
10958 function Copy_Elist_With_Replacement
10959 (Old_Elist : Elist_Id) return Elist_Id;
10960 -- Called during second phase to copy element list doing replacements
10962 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
10963 -- Called during the second phase to process a copied Itype. The actual
10964 -- copy happened during the first phase (so that we could make the entry
10965 -- in the mapping), but we still have to deal with the descendents of
10966 -- the copied Itype and copy them where necessary.
10968 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
10969 -- Called during second phase to copy list doing replacements
10971 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
10972 -- Called during second phase to copy node doing replacements
10974 procedure Visit_Elist (E : Elist_Id);
10975 -- Called during first phase to visit all elements of an Elist
10977 procedure Visit_Field (F : Union_Id; N : Node_Id);
10978 -- Visit a single field, recursing to call Visit_Node or Visit_List
10979 -- if the field is a syntactic descendent of the current node (i.e.
10980 -- its parent is Node N).
10982 procedure Visit_Itype (Old_Itype : Entity_Id);
10983 -- Called during first phase to visit subsidiary fields of a defining
10984 -- Itype, and also create a copy and make an entry in the replacement
10985 -- map for the new copy.
10987 procedure Visit_List (L : List_Id);
10988 -- Called during first phase to visit all elements of a List
10990 procedure Visit_Node (N : Node_Or_Entity_Id);
10991 -- Called during first phase to visit a node and all its subtrees
10997 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
11002 if not Has_Extension (N) or else No (Actual_Map) then
11005 elsif NCT_Hash_Tables_Used then
11006 Ent := NCT_Assoc.Get (Entity_Id (N));
11008 if Present (Ent) then
11014 -- No hash table used, do serial search
11017 E := First_Elmt (Actual_Map);
11018 while Present (E) loop
11019 if Node (E) = N then
11020 return Node (Next_Elmt (E));
11022 E := Next_Elmt (Next_Elmt (E));
11030 ---------------------------
11031 -- Build_NCT_Hash_Tables --
11032 ---------------------------
11034 procedure Build_NCT_Hash_Tables is
11038 if NCT_Hash_Table_Setup then
11040 NCT_Itype_Assoc.Reset;
11043 Elmt := First_Elmt (Actual_Map);
11044 while Present (Elmt) loop
11045 Ent := Node (Elmt);
11047 -- Get new entity, and associate old and new
11050 NCT_Assoc.Set (Ent, Node (Elmt));
11052 if Is_Type (Ent) then
11054 Anode : constant Entity_Id :=
11055 Associated_Node_For_Itype (Ent);
11058 if Present (Anode) then
11060 -- Enter a link between the associated node of the
11061 -- old Itype and the new Itype, for updating later
11062 -- when node is copied.
11064 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
11072 NCT_Hash_Tables_Used := True;
11073 NCT_Hash_Table_Setup := True;
11074 end Build_NCT_Hash_Tables;
11076 ---------------------------------
11077 -- Copy_Elist_With_Replacement --
11078 ---------------------------------
11080 function Copy_Elist_With_Replacement
11081 (Old_Elist : Elist_Id) return Elist_Id
11084 New_Elist : Elist_Id;
11087 if No (Old_Elist) then
11091 New_Elist := New_Elmt_List;
11093 M := First_Elmt (Old_Elist);
11094 while Present (M) loop
11095 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
11101 end Copy_Elist_With_Replacement;
11103 ---------------------------------
11104 -- Copy_Itype_With_Replacement --
11105 ---------------------------------
11107 -- This routine exactly parallels its phase one analog Visit_Itype,
11109 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
11111 -- Translate Next_Entity, Scope and Etype fields, in case they
11112 -- reference entities that have been mapped into copies.
11114 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
11115 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
11117 if Present (New_Scope) then
11118 Set_Scope (New_Itype, New_Scope);
11120 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
11123 -- Copy referenced fields
11125 if Is_Discrete_Type (New_Itype) then
11126 Set_Scalar_Range (New_Itype,
11127 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
11129 elsif Has_Discriminants (Base_Type (New_Itype)) then
11130 Set_Discriminant_Constraint (New_Itype,
11131 Copy_Elist_With_Replacement
11132 (Discriminant_Constraint (New_Itype)));
11134 elsif Is_Array_Type (New_Itype) then
11135 if Present (First_Index (New_Itype)) then
11136 Set_First_Index (New_Itype,
11137 First (Copy_List_With_Replacement
11138 (List_Containing (First_Index (New_Itype)))));
11141 if Is_Packed (New_Itype) then
11142 Set_Packed_Array_Type (New_Itype,
11143 Copy_Node_With_Replacement
11144 (Packed_Array_Type (New_Itype)));
11147 end Copy_Itype_With_Replacement;
11149 --------------------------------
11150 -- Copy_List_With_Replacement --
11151 --------------------------------
11153 function Copy_List_With_Replacement
11154 (Old_List : List_Id) return List_Id
11156 New_List : List_Id;
11160 if Old_List = No_List then
11164 New_List := Empty_List;
11166 E := First (Old_List);
11167 while Present (E) loop
11168 Append (Copy_Node_With_Replacement (E), New_List);
11174 end Copy_List_With_Replacement;
11176 --------------------------------
11177 -- Copy_Node_With_Replacement --
11178 --------------------------------
11180 function Copy_Node_With_Replacement
11181 (Old_Node : Node_Id) return Node_Id
11183 New_Node : Node_Id;
11185 procedure Adjust_Named_Associations
11186 (Old_Node : Node_Id;
11187 New_Node : Node_Id);
11188 -- If a call node has named associations, these are chained through
11189 -- the First_Named_Actual, Next_Named_Actual links. These must be
11190 -- propagated separately to the new parameter list, because these
11191 -- are not syntactic fields.
11193 function Copy_Field_With_Replacement
11194 (Field : Union_Id) return Union_Id;
11195 -- Given Field, which is a field of Old_Node, return a copy of it
11196 -- if it is a syntactic field (i.e. its parent is Node), setting
11197 -- the parent of the copy to poit to New_Node. Otherwise returns
11198 -- the field (possibly mapped if it is an entity).
11200 -------------------------------
11201 -- Adjust_Named_Associations --
11202 -------------------------------
11204 procedure Adjust_Named_Associations
11205 (Old_Node : Node_Id;
11206 New_Node : Node_Id)
11211 Old_Next : Node_Id;
11212 New_Next : Node_Id;
11215 Old_E := First (Parameter_Associations (Old_Node));
11216 New_E := First (Parameter_Associations (New_Node));
11217 while Present (Old_E) loop
11218 if Nkind (Old_E) = N_Parameter_Association
11219 and then Present (Next_Named_Actual (Old_E))
11221 if First_Named_Actual (Old_Node)
11222 = Explicit_Actual_Parameter (Old_E)
11224 Set_First_Named_Actual
11225 (New_Node, Explicit_Actual_Parameter (New_E));
11228 -- Now scan parameter list from the beginning,to locate
11229 -- next named actual, which can be out of order.
11231 Old_Next := First (Parameter_Associations (Old_Node));
11232 New_Next := First (Parameter_Associations (New_Node));
11234 while Nkind (Old_Next) /= N_Parameter_Association
11235 or else Explicit_Actual_Parameter (Old_Next)
11236 /= Next_Named_Actual (Old_E)
11242 Set_Next_Named_Actual
11243 (New_E, Explicit_Actual_Parameter (New_Next));
11249 end Adjust_Named_Associations;
11251 ---------------------------------
11252 -- Copy_Field_With_Replacement --
11253 ---------------------------------
11255 function Copy_Field_With_Replacement
11256 (Field : Union_Id) return Union_Id
11259 if Field = Union_Id (Empty) then
11262 elsif Field in Node_Range then
11264 Old_N : constant Node_Id := Node_Id (Field);
11268 -- If syntactic field, as indicated by the parent pointer
11269 -- being set, then copy the referenced node recursively.
11271 if Parent (Old_N) = Old_Node then
11272 New_N := Copy_Node_With_Replacement (Old_N);
11274 if New_N /= Old_N then
11275 Set_Parent (New_N, New_Node);
11278 -- For semantic fields, update possible entity reference
11279 -- from the replacement map.
11282 New_N := Assoc (Old_N);
11285 return Union_Id (New_N);
11288 elsif Field in List_Range then
11290 Old_L : constant List_Id := List_Id (Field);
11294 -- If syntactic field, as indicated by the parent pointer,
11295 -- then recursively copy the entire referenced list.
11297 if Parent (Old_L) = Old_Node then
11298 New_L := Copy_List_With_Replacement (Old_L);
11299 Set_Parent (New_L, New_Node);
11301 -- For semantic list, just returned unchanged
11307 return Union_Id (New_L);
11310 -- Anything other than a list or a node is returned unchanged
11315 end Copy_Field_With_Replacement;
11317 -- Start of processing for Copy_Node_With_Replacement
11320 if Old_Node <= Empty_Or_Error then
11323 elsif Has_Extension (Old_Node) then
11324 return Assoc (Old_Node);
11327 New_Node := New_Copy (Old_Node);
11329 -- If the node we are copying is the associated node of a
11330 -- previously copied Itype, then adjust the associated node
11331 -- of the copy of that Itype accordingly.
11333 if Present (Actual_Map) then
11339 -- Case of hash table used
11341 if NCT_Hash_Tables_Used then
11342 Ent := NCT_Itype_Assoc.Get (Old_Node);
11344 if Present (Ent) then
11345 Set_Associated_Node_For_Itype (Ent, New_Node);
11348 -- Case of no hash table used
11351 E := First_Elmt (Actual_Map);
11352 while Present (E) loop
11353 if Is_Itype (Node (E))
11355 Old_Node = Associated_Node_For_Itype (Node (E))
11357 Set_Associated_Node_For_Itype
11358 (Node (Next_Elmt (E)), New_Node);
11361 E := Next_Elmt (Next_Elmt (E));
11367 -- Recursively copy descendents
11370 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
11372 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
11374 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
11376 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
11378 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
11380 -- Adjust Sloc of new node if necessary
11382 if New_Sloc /= No_Location then
11383 Set_Sloc (New_Node, New_Sloc);
11385 -- If we adjust the Sloc, then we are essentially making
11386 -- a completely new node, so the Comes_From_Source flag
11387 -- should be reset to the proper default value.
11389 Nodes.Table (New_Node).Comes_From_Source :=
11390 Default_Node.Comes_From_Source;
11393 -- If the node is call and has named associations,
11394 -- set the corresponding links in the copy.
11396 if (Nkind (Old_Node) = N_Function_Call
11397 or else Nkind (Old_Node) = N_Entry_Call_Statement
11399 Nkind (Old_Node) = N_Procedure_Call_Statement)
11400 and then Present (First_Named_Actual (Old_Node))
11402 Adjust_Named_Associations (Old_Node, New_Node);
11405 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
11406 -- The replacement mechanism applies to entities, and is not used
11407 -- here. Eventually we may need a more general graph-copying
11408 -- routine. For now, do a sequential search to find desired node.
11410 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
11411 and then Present (First_Real_Statement (Old_Node))
11414 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
11418 N1 := First (Statements (Old_Node));
11419 N2 := First (Statements (New_Node));
11421 while N1 /= Old_F loop
11426 Set_First_Real_Statement (New_Node, N2);
11431 -- All done, return copied node
11434 end Copy_Node_With_Replacement;
11440 procedure Visit_Elist (E : Elist_Id) is
11443 if Present (E) then
11444 Elmt := First_Elmt (E);
11446 while Elmt /= No_Elmt loop
11447 Visit_Node (Node (Elmt));
11457 procedure Visit_Field (F : Union_Id; N : Node_Id) is
11459 if F = Union_Id (Empty) then
11462 elsif F in Node_Range then
11464 -- Copy node if it is syntactic, i.e. its parent pointer is
11465 -- set to point to the field that referenced it (certain
11466 -- Itypes will also meet this criterion, which is fine, since
11467 -- these are clearly Itypes that do need to be copied, since
11468 -- we are copying their parent.)
11470 if Parent (Node_Id (F)) = N then
11471 Visit_Node (Node_Id (F));
11474 -- Another case, if we are pointing to an Itype, then we want
11475 -- to copy it if its associated node is somewhere in the tree
11478 -- Note: the exclusion of self-referential copies is just an
11479 -- optimization, since the search of the already copied list
11480 -- would catch it, but it is a common case (Etype pointing
11481 -- to itself for an Itype that is a base type).
11483 elsif Has_Extension (Node_Id (F))
11484 and then Is_Itype (Entity_Id (F))
11485 and then Node_Id (F) /= N
11491 P := Associated_Node_For_Itype (Node_Id (F));
11492 while Present (P) loop
11494 Visit_Node (Node_Id (F));
11501 -- An Itype whose parent is not being copied definitely
11502 -- should NOT be copied, since it does not belong in any
11503 -- sense to the copied subtree.
11509 elsif F in List_Range
11510 and then Parent (List_Id (F)) = N
11512 Visit_List (List_Id (F));
11521 procedure Visit_Itype (Old_Itype : Entity_Id) is
11522 New_Itype : Entity_Id;
11527 -- Itypes that describe the designated type of access to subprograms
11528 -- have the structure of subprogram declarations, with signatures,
11529 -- etc. Either we duplicate the signatures completely, or choose to
11530 -- share such itypes, which is fine because their elaboration will
11531 -- have no side effects.
11533 if Ekind (Old_Itype) = E_Subprogram_Type then
11537 New_Itype := New_Copy (Old_Itype);
11539 -- The new Itype has all the attributes of the old one, and
11540 -- we just copy the contents of the entity. However, the back-end
11541 -- needs different names for debugging purposes, so we create a
11542 -- new internal name for it in all cases.
11544 Set_Chars (New_Itype, New_Internal_Name ('T'));
11546 -- If our associated node is an entity that has already been copied,
11547 -- then set the associated node of the copy to point to the right
11548 -- copy. If we have copied an Itype that is itself the associated
11549 -- node of some previously copied Itype, then we set the right
11550 -- pointer in the other direction.
11552 if Present (Actual_Map) then
11554 -- Case of hash tables used
11556 if NCT_Hash_Tables_Used then
11558 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
11560 if Present (Ent) then
11561 Set_Associated_Node_For_Itype (New_Itype, Ent);
11564 Ent := NCT_Itype_Assoc.Get (Old_Itype);
11565 if Present (Ent) then
11566 Set_Associated_Node_For_Itype (Ent, New_Itype);
11568 -- If the hash table has no association for this Itype and
11569 -- its associated node, enter one now.
11572 NCT_Itype_Assoc.Set
11573 (Associated_Node_For_Itype (Old_Itype), New_Itype);
11576 -- Case of hash tables not used
11579 E := First_Elmt (Actual_Map);
11580 while Present (E) loop
11581 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
11582 Set_Associated_Node_For_Itype
11583 (New_Itype, Node (Next_Elmt (E)));
11586 if Is_Type (Node (E))
11588 Old_Itype = Associated_Node_For_Itype (Node (E))
11590 Set_Associated_Node_For_Itype
11591 (Node (Next_Elmt (E)), New_Itype);
11594 E := Next_Elmt (Next_Elmt (E));
11599 if Present (Freeze_Node (New_Itype)) then
11600 Set_Is_Frozen (New_Itype, False);
11601 Set_Freeze_Node (New_Itype, Empty);
11604 -- Add new association to map
11606 if No (Actual_Map) then
11607 Actual_Map := New_Elmt_List;
11610 Append_Elmt (Old_Itype, Actual_Map);
11611 Append_Elmt (New_Itype, Actual_Map);
11613 if NCT_Hash_Tables_Used then
11614 NCT_Assoc.Set (Old_Itype, New_Itype);
11617 NCT_Table_Entries := NCT_Table_Entries + 1;
11619 if NCT_Table_Entries > NCT_Hash_Threshold then
11620 Build_NCT_Hash_Tables;
11624 -- If a record subtype is simply copied, the entity list will be
11625 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
11627 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
11628 Set_Cloned_Subtype (New_Itype, Old_Itype);
11631 -- Visit descendents that eventually get copied
11633 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
11635 if Is_Discrete_Type (Old_Itype) then
11636 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
11638 elsif Has_Discriminants (Base_Type (Old_Itype)) then
11639 -- ??? This should involve call to Visit_Field
11640 Visit_Elist (Discriminant_Constraint (Old_Itype));
11642 elsif Is_Array_Type (Old_Itype) then
11643 if Present (First_Index (Old_Itype)) then
11644 Visit_Field (Union_Id (List_Containing
11645 (First_Index (Old_Itype))),
11649 if Is_Packed (Old_Itype) then
11650 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
11660 procedure Visit_List (L : List_Id) is
11663 if L /= No_List then
11666 while Present (N) loop
11677 procedure Visit_Node (N : Node_Or_Entity_Id) is
11679 -- Start of processing for Visit_Node
11682 -- Handle case of an Itype, which must be copied
11684 if Has_Extension (N)
11685 and then Is_Itype (N)
11687 -- Nothing to do if already in the list. This can happen with an
11688 -- Itype entity that appears more than once in the tree.
11689 -- Note that we do not want to visit descendents in this case.
11691 -- Test for already in list when hash table is used
11693 if NCT_Hash_Tables_Used then
11694 if Present (NCT_Assoc.Get (Entity_Id (N))) then
11698 -- Test for already in list when hash table not used
11704 if Present (Actual_Map) then
11705 E := First_Elmt (Actual_Map);
11706 while Present (E) loop
11707 if Node (E) = N then
11710 E := Next_Elmt (Next_Elmt (E));
11720 -- Visit descendents
11722 Visit_Field (Field1 (N), N);
11723 Visit_Field (Field2 (N), N);
11724 Visit_Field (Field3 (N), N);
11725 Visit_Field (Field4 (N), N);
11726 Visit_Field (Field5 (N), N);
11729 -- Start of processing for New_Copy_Tree
11734 -- See if we should use hash table
11736 if No (Actual_Map) then
11737 NCT_Hash_Tables_Used := False;
11744 NCT_Table_Entries := 0;
11746 Elmt := First_Elmt (Actual_Map);
11747 while Present (Elmt) loop
11748 NCT_Table_Entries := NCT_Table_Entries + 1;
11753 if NCT_Table_Entries > NCT_Hash_Threshold then
11754 Build_NCT_Hash_Tables;
11756 NCT_Hash_Tables_Used := False;
11761 -- Hash table set up if required, now start phase one by visiting
11762 -- top node (we will recursively visit the descendents).
11764 Visit_Node (Source);
11766 -- Now the second phase of the copy can start. First we process
11767 -- all the mapped entities, copying their descendents.
11769 if Present (Actual_Map) then
11772 New_Itype : Entity_Id;
11774 Elmt := First_Elmt (Actual_Map);
11775 while Present (Elmt) loop
11777 New_Itype := Node (Elmt);
11778 Copy_Itype_With_Replacement (New_Itype);
11784 -- Now we can copy the actual tree
11786 return Copy_Node_With_Replacement (Source);
11789 -------------------------
11790 -- New_External_Entity --
11791 -------------------------
11793 function New_External_Entity
11794 (Kind : Entity_Kind;
11795 Scope_Id : Entity_Id;
11796 Sloc_Value : Source_Ptr;
11797 Related_Id : Entity_Id;
11798 Suffix : Character;
11799 Suffix_Index : Nat := 0;
11800 Prefix : Character := ' ') return Entity_Id
11802 N : constant Entity_Id :=
11803 Make_Defining_Identifier (Sloc_Value,
11805 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
11808 Set_Ekind (N, Kind);
11809 Set_Is_Internal (N, True);
11810 Append_Entity (N, Scope_Id);
11811 Set_Public_Status (N);
11813 if Kind in Type_Kind then
11814 Init_Size_Align (N);
11818 end New_External_Entity;
11820 -------------------------
11821 -- New_Internal_Entity --
11822 -------------------------
11824 function New_Internal_Entity
11825 (Kind : Entity_Kind;
11826 Scope_Id : Entity_Id;
11827 Sloc_Value : Source_Ptr;
11828 Id_Char : Character) return Entity_Id
11830 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
11833 Set_Ekind (N, Kind);
11834 Set_Is_Internal (N, True);
11835 Append_Entity (N, Scope_Id);
11837 if Kind in Type_Kind then
11838 Init_Size_Align (N);
11842 end New_Internal_Entity;
11848 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
11852 -- If we are pointing at a positional parameter, it is a member of a
11853 -- node list (the list of parameters), and the next parameter is the
11854 -- next node on the list, unless we hit a parameter association, then
11855 -- we shift to using the chain whose head is the First_Named_Actual in
11856 -- the parent, and then is threaded using the Next_Named_Actual of the
11857 -- Parameter_Association. All this fiddling is because the original node
11858 -- list is in the textual call order, and what we need is the
11859 -- declaration order.
11861 if Is_List_Member (Actual_Id) then
11862 N := Next (Actual_Id);
11864 if Nkind (N) = N_Parameter_Association then
11865 return First_Named_Actual (Parent (Actual_Id));
11871 return Next_Named_Actual (Parent (Actual_Id));
11875 procedure Next_Actual (Actual_Id : in out Node_Id) is
11877 Actual_Id := Next_Actual (Actual_Id);
11880 ---------------------
11881 -- No_Scalar_Parts --
11882 ---------------------
11884 function No_Scalar_Parts (T : Entity_Id) return Boolean is
11888 if Is_Scalar_Type (T) then
11891 elsif Is_Array_Type (T) then
11892 return No_Scalar_Parts (Component_Type (T));
11894 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
11895 C := First_Component_Or_Discriminant (T);
11896 while Present (C) loop
11897 if not No_Scalar_Parts (Etype (C)) then
11900 Next_Component_Or_Discriminant (C);
11906 end No_Scalar_Parts;
11908 -----------------------
11909 -- Normalize_Actuals --
11910 -----------------------
11912 -- Chain actuals according to formals of subprogram. If there are no named
11913 -- associations, the chain is simply the list of Parameter Associations,
11914 -- since the order is the same as the declaration order. If there are named
11915 -- associations, then the First_Named_Actual field in the N_Function_Call
11916 -- or N_Procedure_Call_Statement node points to the Parameter_Association
11917 -- node for the parameter that comes first in declaration order. The
11918 -- remaining named parameters are then chained in declaration order using
11919 -- Next_Named_Actual.
11921 -- This routine also verifies that the number of actuals is compatible with
11922 -- the number and default values of formals, but performs no type checking
11923 -- (type checking is done by the caller).
11925 -- If the matching succeeds, Success is set to True and the caller proceeds
11926 -- with type-checking. If the match is unsuccessful, then Success is set to
11927 -- False, and the caller attempts a different interpretation, if there is
11930 -- If the flag Report is on, the call is not overloaded, and a failure to
11931 -- match can be reported here, rather than in the caller.
11933 procedure Normalize_Actuals
11937 Success : out Boolean)
11939 Actuals : constant List_Id := Parameter_Associations (N);
11940 Actual : Node_Id := Empty;
11941 Formal : Entity_Id;
11942 Last : Node_Id := Empty;
11943 First_Named : Node_Id := Empty;
11946 Formals_To_Match : Integer := 0;
11947 Actuals_To_Match : Integer := 0;
11949 procedure Chain (A : Node_Id);
11950 -- Add named actual at the proper place in the list, using the
11951 -- Next_Named_Actual link.
11953 function Reporting return Boolean;
11954 -- Determines if an error is to be reported. To report an error, we
11955 -- need Report to be True, and also we do not report errors caused
11956 -- by calls to init procs that occur within other init procs. Such
11957 -- errors must always be cascaded errors, since if all the types are
11958 -- declared correctly, the compiler will certainly build decent calls!
11964 procedure Chain (A : Node_Id) is
11968 -- Call node points to first actual in list
11970 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
11973 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
11977 Set_Next_Named_Actual (Last, Empty);
11984 function Reporting return Boolean is
11989 elsif not Within_Init_Proc then
11992 elsif Is_Init_Proc (Entity (Name (N))) then
12000 -- Start of processing for Normalize_Actuals
12003 if Is_Access_Type (S) then
12005 -- The name in the call is a function call that returns an access
12006 -- to subprogram. The designated type has the list of formals.
12008 Formal := First_Formal (Designated_Type (S));
12010 Formal := First_Formal (S);
12013 while Present (Formal) loop
12014 Formals_To_Match := Formals_To_Match + 1;
12015 Next_Formal (Formal);
12018 -- Find if there is a named association, and verify that no positional
12019 -- associations appear after named ones.
12021 if Present (Actuals) then
12022 Actual := First (Actuals);
12025 while Present (Actual)
12026 and then Nkind (Actual) /= N_Parameter_Association
12028 Actuals_To_Match := Actuals_To_Match + 1;
12032 if No (Actual) and Actuals_To_Match = Formals_To_Match then
12034 -- Most common case: positional notation, no defaults
12039 elsif Actuals_To_Match > Formals_To_Match then
12041 -- Too many actuals: will not work
12044 if Is_Entity_Name (Name (N)) then
12045 Error_Msg_N ("too many arguments in call to&", Name (N));
12047 Error_Msg_N ("too many arguments in call", N);
12055 First_Named := Actual;
12057 while Present (Actual) loop
12058 if Nkind (Actual) /= N_Parameter_Association then
12060 ("positional parameters not allowed after named ones", Actual);
12065 Actuals_To_Match := Actuals_To_Match + 1;
12071 if Present (Actuals) then
12072 Actual := First (Actuals);
12075 Formal := First_Formal (S);
12076 while Present (Formal) loop
12078 -- Match the formals in order. If the corresponding actual is
12079 -- positional, nothing to do. Else scan the list of named actuals
12080 -- to find the one with the right name.
12082 if Present (Actual)
12083 and then Nkind (Actual) /= N_Parameter_Association
12086 Actuals_To_Match := Actuals_To_Match - 1;
12087 Formals_To_Match := Formals_To_Match - 1;
12090 -- For named parameters, search the list of actuals to find
12091 -- one that matches the next formal name.
12093 Actual := First_Named;
12095 while Present (Actual) loop
12096 if Chars (Selector_Name (Actual)) = Chars (Formal) then
12099 Actuals_To_Match := Actuals_To_Match - 1;
12100 Formals_To_Match := Formals_To_Match - 1;
12108 if Ekind (Formal) /= E_In_Parameter
12109 or else No (Default_Value (Formal))
12112 if (Comes_From_Source (S)
12113 or else Sloc (S) = Standard_Location)
12114 and then Is_Overloadable (S)
12118 (Nkind (Parent (N)) = N_Procedure_Call_Statement
12120 (Nkind (Parent (N)) = N_Function_Call
12122 Nkind (Parent (N)) = N_Parameter_Association))
12123 and then Ekind (S) /= E_Function
12125 Set_Etype (N, Etype (S));
12127 Error_Msg_Name_1 := Chars (S);
12128 Error_Msg_Sloc := Sloc (S);
12130 ("missing argument for parameter & " &
12131 "in call to % declared #", N, Formal);
12134 elsif Is_Overloadable (S) then
12135 Error_Msg_Name_1 := Chars (S);
12137 -- Point to type derivation that generated the
12140 Error_Msg_Sloc := Sloc (Parent (S));
12143 ("missing argument for parameter & " &
12144 "in call to % (inherited) #", N, Formal);
12148 ("missing argument for parameter &", N, Formal);
12156 Formals_To_Match := Formals_To_Match - 1;
12161 Next_Formal (Formal);
12164 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
12171 -- Find some superfluous named actual that did not get
12172 -- attached to the list of associations.
12174 Actual := First (Actuals);
12175 while Present (Actual) loop
12176 if Nkind (Actual) = N_Parameter_Association
12177 and then Actual /= Last
12178 and then No (Next_Named_Actual (Actual))
12180 Error_Msg_N ("unmatched actual & in call",
12181 Selector_Name (Actual));
12192 end Normalize_Actuals;
12194 --------------------------------
12195 -- Note_Possible_Modification --
12196 --------------------------------
12198 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
12199 Modification_Comes_From_Source : constant Boolean :=
12200 Comes_From_Source (Parent (N));
12206 -- Loop to find referenced entity, if there is one
12213 if Is_Entity_Name (Exp) then
12214 Ent := Entity (Exp);
12216 -- If the entity is missing, it is an undeclared identifier,
12217 -- and there is nothing to annotate.
12223 elsif Nkind (Exp) = N_Explicit_Dereference then
12225 P : constant Node_Id := Prefix (Exp);
12228 -- In formal verification mode, keep track of all reads and
12229 -- writes through explicit dereferences.
12232 SPARK_Specific.Generate_Dereference (N, 'm');
12235 if Nkind (P) = N_Selected_Component
12237 Present (Entry_Formal (Entity (Selector_Name (P))))
12239 -- Case of a reference to an entry formal
12241 Ent := Entry_Formal (Entity (Selector_Name (P)));
12243 elsif Nkind (P) = N_Identifier
12244 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
12245 and then Present (Expression (Parent (Entity (P))))
12246 and then Nkind (Expression (Parent (Entity (P))))
12249 -- Case of a reference to a value on which side effects have
12252 Exp := Prefix (Expression (Parent (Entity (P))));
12261 elsif Nkind_In (Exp, N_Type_Conversion,
12262 N_Unchecked_Type_Conversion)
12264 Exp := Expression (Exp);
12267 elsif Nkind_In (Exp, N_Slice,
12268 N_Indexed_Component,
12269 N_Selected_Component)
12271 Exp := Prefix (Exp);
12278 -- Now look for entity being referenced
12280 if Present (Ent) then
12281 if Is_Object (Ent) then
12282 if Comes_From_Source (Exp)
12283 or else Modification_Comes_From_Source
12285 -- Give warning if pragma unmodified given and we are
12286 -- sure this is a modification.
12288 if Has_Pragma_Unmodified (Ent) and then Sure then
12290 ("??pragma Unmodified given for &!", N, Ent);
12293 Set_Never_Set_In_Source (Ent, False);
12296 Set_Is_True_Constant (Ent, False);
12297 Set_Current_Value (Ent, Empty);
12298 Set_Is_Known_Null (Ent, False);
12300 if not Can_Never_Be_Null (Ent) then
12301 Set_Is_Known_Non_Null (Ent, False);
12304 -- Follow renaming chain
12306 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
12307 and then Present (Renamed_Object (Ent))
12309 Exp := Renamed_Object (Ent);
12312 -- The expression may be the renaming of a subcomponent of an
12313 -- array or container. The assignment to the subcomponent is
12314 -- a modification of the container.
12316 elsif Comes_From_Source (Original_Node (Exp))
12317 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
12318 N_Indexed_Component)
12320 Exp := Prefix (Original_Node (Exp));
12324 -- Generate a reference only if the assignment comes from
12325 -- source. This excludes, for example, calls to a dispatching
12326 -- assignment operation when the left-hand side is tagged.
12328 -- Why is SPARK mode different here ???
12330 if Modification_Comes_From_Source or SPARK_Mode then
12331 Generate_Reference (Ent, Exp, 'm');
12333 -- If the target of the assignment is the bound variable
12334 -- in an iterator, indicate that the corresponding array
12335 -- or container is also modified.
12337 if Ada_Version >= Ada_2012
12339 Nkind (Parent (Ent)) = N_Iterator_Specification
12342 Domain : constant Node_Id := Name (Parent (Ent));
12345 -- TBD : in the full version of the construct, the
12346 -- domain of iteration can be given by an expression.
12348 if Is_Entity_Name (Domain) then
12349 Generate_Reference (Entity (Domain), Exp, 'm');
12350 Set_Is_True_Constant (Entity (Domain), False);
12351 Set_Never_Set_In_Source (Entity (Domain), False);
12357 Check_Nested_Access (Ent);
12362 -- If we are sure this is a modification from source, and we know
12363 -- this modifies a constant, then give an appropriate warning.
12365 if Overlays_Constant (Ent)
12366 and then Modification_Comes_From_Source
12370 A : constant Node_Id := Address_Clause (Ent);
12372 if Present (A) then
12374 Exp : constant Node_Id := Expression (A);
12376 if Nkind (Exp) = N_Attribute_Reference
12377 and then Attribute_Name (Exp) = Name_Address
12378 and then Is_Entity_Name (Prefix (Exp))
12380 Error_Msg_Sloc := Sloc (A);
12382 ("constant& may be modified via address "
12383 & "clause#??", N, Entity (Prefix (Exp)));
12393 end Note_Possible_Modification;
12395 -------------------------
12396 -- Object_Access_Level --
12397 -------------------------
12399 -- Returns the static accessibility level of the view denoted by Obj. Note
12400 -- that the value returned is the result of a call to Scope_Depth. Only
12401 -- scope depths associated with dynamic scopes can actually be returned.
12402 -- Since only relative levels matter for accessibility checking, the fact
12403 -- that the distance between successive levels of accessibility is not
12404 -- always one is immaterial (invariant: if level(E2) is deeper than
12405 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
12407 function Object_Access_Level (Obj : Node_Id) return Uint is
12408 function Is_Interface_Conversion (N : Node_Id) return Boolean;
12409 -- Determine whether N is a construct of the form
12410 -- Some_Type (Operand._tag'Address)
12411 -- This construct appears in the context of dispatching calls.
12413 function Reference_To (Obj : Node_Id) return Node_Id;
12414 -- An explicit dereference is created when removing side-effects from
12415 -- expressions for constraint checking purposes. In this case a local
12416 -- access type is created for it. The correct access level is that of
12417 -- the original source node. We detect this case by noting that the
12418 -- prefix of the dereference is created by an object declaration whose
12419 -- initial expression is a reference.
12421 -----------------------------
12422 -- Is_Interface_Conversion --
12423 -----------------------------
12425 function Is_Interface_Conversion (N : Node_Id) return Boolean is
12428 Nkind (N) = N_Unchecked_Type_Conversion
12429 and then Nkind (Expression (N)) = N_Attribute_Reference
12430 and then Attribute_Name (Expression (N)) = Name_Address;
12431 end Is_Interface_Conversion;
12437 function Reference_To (Obj : Node_Id) return Node_Id is
12438 Pref : constant Node_Id := Prefix (Obj);
12440 if Is_Entity_Name (Pref)
12441 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
12442 and then Present (Expression (Parent (Entity (Pref))))
12443 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
12445 return (Prefix (Expression (Parent (Entity (Pref)))));
12455 -- Start of processing for Object_Access_Level
12458 if Nkind (Obj) = N_Defining_Identifier
12459 or else Is_Entity_Name (Obj)
12461 if Nkind (Obj) = N_Defining_Identifier then
12467 if Is_Prival (E) then
12468 E := Prival_Link (E);
12471 -- If E is a type then it denotes a current instance. For this case
12472 -- we add one to the normal accessibility level of the type to ensure
12473 -- that current instances are treated as always being deeper than
12474 -- than the level of any visible named access type (see 3.10.2(21)).
12476 if Is_Type (E) then
12477 return Type_Access_Level (E) + 1;
12479 elsif Present (Renamed_Object (E)) then
12480 return Object_Access_Level (Renamed_Object (E));
12482 -- Similarly, if E is a component of the current instance of a
12483 -- protected type, any instance of it is assumed to be at a deeper
12484 -- level than the type. For a protected object (whose type is an
12485 -- anonymous protected type) its components are at the same level
12486 -- as the type itself.
12488 elsif not Is_Overloadable (E)
12489 and then Ekind (Scope (E)) = E_Protected_Type
12490 and then Comes_From_Source (Scope (E))
12492 return Type_Access_Level (Scope (E)) + 1;
12495 return Scope_Depth (Enclosing_Dynamic_Scope (E));
12498 elsif Nkind (Obj) = N_Selected_Component then
12499 if Is_Access_Type (Etype (Prefix (Obj))) then
12500 return Type_Access_Level (Etype (Prefix (Obj)));
12502 return Object_Access_Level (Prefix (Obj));
12505 elsif Nkind (Obj) = N_Indexed_Component then
12506 if Is_Access_Type (Etype (Prefix (Obj))) then
12507 return Type_Access_Level (Etype (Prefix (Obj)));
12509 return Object_Access_Level (Prefix (Obj));
12512 elsif Nkind (Obj) = N_Explicit_Dereference then
12514 -- If the prefix is a selected access discriminant then we make a
12515 -- recursive call on the prefix, which will in turn check the level
12516 -- of the prefix object of the selected discriminant.
12518 if Nkind (Prefix (Obj)) = N_Selected_Component
12519 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
12521 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
12523 return Object_Access_Level (Prefix (Obj));
12525 -- Detect an interface conversion in the context of a dispatching
12526 -- call. Use the original form of the conversion to find the access
12527 -- level of the operand.
12529 elsif Is_Interface (Etype (Obj))
12530 and then Is_Interface_Conversion (Prefix (Obj))
12531 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
12533 return Object_Access_Level (Original_Node (Obj));
12535 elsif not Comes_From_Source (Obj) then
12537 Ref : constant Node_Id := Reference_To (Obj);
12539 if Present (Ref) then
12540 return Object_Access_Level (Ref);
12542 return Type_Access_Level (Etype (Prefix (Obj)));
12547 return Type_Access_Level (Etype (Prefix (Obj)));
12550 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
12551 return Object_Access_Level (Expression (Obj));
12553 elsif Nkind (Obj) = N_Function_Call then
12555 -- Function results are objects, so we get either the access level of
12556 -- the function or, in the case of an indirect call, the level of the
12557 -- access-to-subprogram type. (This code is used for Ada 95, but it
12558 -- looks wrong, because it seems that we should be checking the level
12559 -- of the call itself, even for Ada 95. However, using the Ada 2005
12560 -- version of the code causes regressions in several tests that are
12561 -- compiled with -gnat95. ???)
12563 if Ada_Version < Ada_2005 then
12564 if Is_Entity_Name (Name (Obj)) then
12565 return Subprogram_Access_Level (Entity (Name (Obj)));
12567 return Type_Access_Level (Etype (Prefix (Name (Obj))));
12570 -- For Ada 2005, the level of the result object of a function call is
12571 -- defined to be the level of the call's innermost enclosing master.
12572 -- We determine that by querying the depth of the innermost enclosing
12576 Return_Master_Scope_Depth_Of_Call : declare
12578 function Innermost_Master_Scope_Depth
12579 (N : Node_Id) return Uint;
12580 -- Returns the scope depth of the given node's innermost
12581 -- enclosing dynamic scope (effectively the accessibility
12582 -- level of the innermost enclosing master).
12584 ----------------------------------
12585 -- Innermost_Master_Scope_Depth --
12586 ----------------------------------
12588 function Innermost_Master_Scope_Depth
12589 (N : Node_Id) return Uint
12591 Node_Par : Node_Id := Parent (N);
12594 -- Locate the nearest enclosing node (by traversing Parents)
12595 -- that Defining_Entity can be applied to, and return the
12596 -- depth of that entity's nearest enclosing dynamic scope.
12598 while Present (Node_Par) loop
12599 case Nkind (Node_Par) is
12600 when N_Component_Declaration |
12601 N_Entry_Declaration |
12602 N_Formal_Object_Declaration |
12603 N_Formal_Type_Declaration |
12604 N_Full_Type_Declaration |
12605 N_Incomplete_Type_Declaration |
12606 N_Loop_Parameter_Specification |
12607 N_Object_Declaration |
12608 N_Protected_Type_Declaration |
12609 N_Private_Extension_Declaration |
12610 N_Private_Type_Declaration |
12611 N_Subtype_Declaration |
12612 N_Function_Specification |
12613 N_Procedure_Specification |
12614 N_Task_Type_Declaration |
12616 N_Generic_Instantiation |
12618 N_Implicit_Label_Declaration |
12619 N_Package_Declaration |
12620 N_Single_Task_Declaration |
12621 N_Subprogram_Declaration |
12622 N_Generic_Declaration |
12623 N_Renaming_Declaration |
12624 N_Block_Statement |
12625 N_Formal_Subprogram_Declaration |
12626 N_Abstract_Subprogram_Declaration |
12628 N_Exception_Declaration |
12629 N_Formal_Package_Declaration |
12630 N_Number_Declaration |
12631 N_Package_Specification |
12632 N_Parameter_Specification |
12633 N_Single_Protected_Declaration |
12637 (Nearest_Dynamic_Scope
12638 (Defining_Entity (Node_Par)));
12644 Node_Par := Parent (Node_Par);
12647 pragma Assert (False);
12649 -- Should never reach the following return
12651 return Scope_Depth (Current_Scope) + 1;
12652 end Innermost_Master_Scope_Depth;
12654 -- Start of processing for Return_Master_Scope_Depth_Of_Call
12657 return Innermost_Master_Scope_Depth (Obj);
12658 end Return_Master_Scope_Depth_Of_Call;
12661 -- For convenience we handle qualified expressions, even though they
12662 -- aren't technically object names.
12664 elsif Nkind (Obj) = N_Qualified_Expression then
12665 return Object_Access_Level (Expression (Obj));
12667 -- Otherwise return the scope level of Standard. (If there are cases
12668 -- that fall through to this point they will be treated as having
12669 -- global accessibility for now. ???)
12672 return Scope_Depth (Standard_Standard);
12674 end Object_Access_Level;
12676 --------------------------------------
12677 -- Original_Corresponding_Operation --
12678 --------------------------------------
12680 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
12682 Typ : constant Entity_Id := Find_Dispatching_Type (S);
12685 -- If S is an inherited primitive S2 the original corresponding
12686 -- operation of S is the original corresponding operation of S2
12688 if Present (Alias (S))
12689 and then Find_Dispatching_Type (Alias (S)) /= Typ
12691 return Original_Corresponding_Operation (Alias (S));
12693 -- If S overrides an inherited subprogram S2 the original corresponding
12694 -- operation of S is the original corresponding operation of S2
12696 elsif Present (Overridden_Operation (S)) then
12697 return Original_Corresponding_Operation (Overridden_Operation (S));
12699 -- otherwise it is S itself
12704 end Original_Corresponding_Operation;
12706 -----------------------
12707 -- Private_Component --
12708 -----------------------
12710 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
12711 Ancestor : constant Entity_Id := Base_Type (Type_Id);
12713 function Trace_Components
12715 Check : Boolean) return Entity_Id;
12716 -- Recursive function that does the work, and checks against circular
12717 -- definition for each subcomponent type.
12719 ----------------------
12720 -- Trace_Components --
12721 ----------------------
12723 function Trace_Components
12725 Check : Boolean) return Entity_Id
12727 Btype : constant Entity_Id := Base_Type (T);
12728 Component : Entity_Id;
12730 Candidate : Entity_Id := Empty;
12733 if Check and then Btype = Ancestor then
12734 Error_Msg_N ("circular type definition", Type_Id);
12738 if Is_Private_Type (Btype)
12739 and then not Is_Generic_Type (Btype)
12741 if Present (Full_View (Btype))
12742 and then Is_Record_Type (Full_View (Btype))
12743 and then not Is_Frozen (Btype)
12745 -- To indicate that the ancestor depends on a private type, the
12746 -- current Btype is sufficient. However, to check for circular
12747 -- definition we must recurse on the full view.
12749 Candidate := Trace_Components (Full_View (Btype), True);
12751 if Candidate = Any_Type then
12761 elsif Is_Array_Type (Btype) then
12762 return Trace_Components (Component_Type (Btype), True);
12764 elsif Is_Record_Type (Btype) then
12765 Component := First_Entity (Btype);
12766 while Present (Component)
12767 and then Comes_From_Source (Component)
12769 -- Skip anonymous types generated by constrained components
12771 if not Is_Type (Component) then
12772 P := Trace_Components (Etype (Component), True);
12774 if Present (P) then
12775 if P = Any_Type then
12783 Next_Entity (Component);
12791 end Trace_Components;
12793 -- Start of processing for Private_Component
12796 return Trace_Components (Type_Id, False);
12797 end Private_Component;
12799 ---------------------------
12800 -- Primitive_Names_Match --
12801 ---------------------------
12803 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
12805 function Non_Internal_Name (E : Entity_Id) return Name_Id;
12806 -- Given an internal name, returns the corresponding non-internal name
12808 ------------------------
12809 -- Non_Internal_Name --
12810 ------------------------
12812 function Non_Internal_Name (E : Entity_Id) return Name_Id is
12814 Get_Name_String (Chars (E));
12815 Name_Len := Name_Len - 1;
12817 end Non_Internal_Name;
12819 -- Start of processing for Primitive_Names_Match
12822 pragma Assert (Present (E1) and then Present (E2));
12824 return Chars (E1) = Chars (E2)
12826 (not Is_Internal_Name (Chars (E1))
12827 and then Is_Internal_Name (Chars (E2))
12828 and then Non_Internal_Name (E2) = Chars (E1))
12830 (not Is_Internal_Name (Chars (E2))
12831 and then Is_Internal_Name (Chars (E1))
12832 and then Non_Internal_Name (E1) = Chars (E2))
12834 (Is_Predefined_Dispatching_Operation (E1)
12835 and then Is_Predefined_Dispatching_Operation (E2)
12836 and then Same_TSS (E1, E2))
12838 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
12839 end Primitive_Names_Match;
12841 -----------------------
12842 -- Process_End_Label --
12843 -----------------------
12845 procedure Process_End_Label
12854 Label_Ref : Boolean;
12855 -- Set True if reference to end label itself is required
12858 -- Gets set to the operator symbol or identifier that references the
12859 -- entity Ent. For the child unit case, this is the identifier from the
12860 -- designator. For other cases, this is simply Endl.
12862 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
12863 -- N is an identifier node that appears as a parent unit reference in
12864 -- the case where Ent is a child unit. This procedure generates an
12865 -- appropriate cross-reference entry. E is the corresponding entity.
12867 -------------------------
12868 -- Generate_Parent_Ref --
12869 -------------------------
12871 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
12873 -- If names do not match, something weird, skip reference
12875 if Chars (E) = Chars (N) then
12877 -- Generate the reference. We do NOT consider this as a reference
12878 -- for unreferenced symbol purposes.
12880 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
12882 if Style_Check then
12883 Style.Check_Identifier (N, E);
12886 end Generate_Parent_Ref;
12888 -- Start of processing for Process_End_Label
12891 -- If no node, ignore. This happens in some error situations, and
12892 -- also for some internally generated structures where no end label
12893 -- references are required in any case.
12899 -- Nothing to do if no End_Label, happens for internally generated
12900 -- constructs where we don't want an end label reference anyway. Also
12901 -- nothing to do if Endl is a string literal, which means there was
12902 -- some prior error (bad operator symbol)
12904 Endl := End_Label (N);
12906 if No (Endl) or else Nkind (Endl) = N_String_Literal then
12910 -- Reference node is not in extended main source unit
12912 if not In_Extended_Main_Source_Unit (N) then
12914 -- Generally we do not collect references except for the extended
12915 -- main source unit. The one exception is the 'e' entry for a
12916 -- package spec, where it is useful for a client to have the
12917 -- ending information to define scopes.
12923 Label_Ref := False;
12925 -- For this case, we can ignore any parent references, but we
12926 -- need the package name itself for the 'e' entry.
12928 if Nkind (Endl) = N_Designator then
12929 Endl := Identifier (Endl);
12933 -- Reference is in extended main source unit
12938 -- For designator, generate references for the parent entries
12940 if Nkind (Endl) = N_Designator then
12942 -- Generate references for the prefix if the END line comes from
12943 -- source (otherwise we do not need these references) We climb the
12944 -- scope stack to find the expected entities.
12946 if Comes_From_Source (Endl) then
12947 Nam := Name (Endl);
12948 Scop := Current_Scope;
12949 while Nkind (Nam) = N_Selected_Component loop
12950 Scop := Scope (Scop);
12951 exit when No (Scop);
12952 Generate_Parent_Ref (Selector_Name (Nam), Scop);
12953 Nam := Prefix (Nam);
12956 if Present (Scop) then
12957 Generate_Parent_Ref (Nam, Scope (Scop));
12961 Endl := Identifier (Endl);
12965 -- If the end label is not for the given entity, then either we have
12966 -- some previous error, or this is a generic instantiation for which
12967 -- we do not need to make a cross-reference in this case anyway. In
12968 -- either case we simply ignore the call.
12970 if Chars (Ent) /= Chars (Endl) then
12974 -- If label was really there, then generate a normal reference and then
12975 -- adjust the location in the end label to point past the name (which
12976 -- should almost always be the semicolon).
12978 Loc := Sloc (Endl);
12980 if Comes_From_Source (Endl) then
12982 -- If a label reference is required, then do the style check and
12983 -- generate an l-type cross-reference entry for the label
12986 if Style_Check then
12987 Style.Check_Identifier (Endl, Ent);
12990 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
12993 -- Set the location to point past the label (normally this will
12994 -- mean the semicolon immediately following the label). This is
12995 -- done for the sake of the 'e' or 't' entry generated below.
12997 Get_Decoded_Name_String (Chars (Endl));
12998 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
13001 -- In SPARK mode, no missing label is allowed for packages and
13002 -- subprogram bodies. Detect those cases by testing whether
13003 -- Process_End_Label was called for a body (Typ = 't') or a package.
13005 if Restriction_Check_Required (SPARK_05)
13006 and then (Typ = 't' or else Ekind (Ent) = E_Package)
13008 Error_Msg_Node_1 := Endl;
13009 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
13013 -- Now generate the e/t reference
13015 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
13017 -- Restore Sloc, in case modified above, since we have an identifier
13018 -- and the normal Sloc should be left set in the tree.
13020 Set_Sloc (Endl, Loc);
13021 end Process_End_Label;
13027 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
13028 Seen : Boolean := False;
13030 function Is_Reference (N : Node_Id) return Traverse_Result;
13031 -- Determine whether node N denotes a reference to Id. If this is the
13032 -- case, set global flag Seen to True and stop the traversal.
13038 function Is_Reference (N : Node_Id) return Traverse_Result is
13040 if Is_Entity_Name (N)
13041 and then Present (Entity (N))
13042 and then Entity (N) = Id
13051 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
13053 -- Start of processing for Referenced
13056 Inspect_Expression (Expr);
13060 ------------------------------------
13061 -- References_Generic_Formal_Type --
13062 ------------------------------------
13064 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
13066 function Process (N : Node_Id) return Traverse_Result;
13067 -- Process one node in search for generic formal type
13073 function Process (N : Node_Id) return Traverse_Result is
13075 if Nkind (N) in N_Has_Entity then
13077 E : constant Entity_Id := Entity (N);
13079 if Present (E) then
13080 if Is_Generic_Type (E) then
13082 elsif Present (Etype (E))
13083 and then Is_Generic_Type (Etype (E))
13094 function Traverse is new Traverse_Func (Process);
13095 -- Traverse tree to look for generic type
13098 if Inside_A_Generic then
13099 return Traverse (N) = Abandon;
13103 end References_Generic_Formal_Type;
13105 --------------------
13106 -- Remove_Homonym --
13107 --------------------
13109 procedure Remove_Homonym (E : Entity_Id) is
13110 Prev : Entity_Id := Empty;
13114 if E = Current_Entity (E) then
13115 if Present (Homonym (E)) then
13116 Set_Current_Entity (Homonym (E));
13118 Set_Name_Entity_Id (Chars (E), Empty);
13122 H := Current_Entity (E);
13123 while Present (H) and then H /= E loop
13128 -- If E is not on the homonym chain, nothing to do
13130 if Present (H) then
13131 Set_Homonym (Prev, Homonym (E));
13134 end Remove_Homonym;
13136 ---------------------
13137 -- Rep_To_Pos_Flag --
13138 ---------------------
13140 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
13142 return New_Occurrence_Of
13143 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
13144 end Rep_To_Pos_Flag;
13146 --------------------
13147 -- Require_Entity --
13148 --------------------
13150 procedure Require_Entity (N : Node_Id) is
13152 if Is_Entity_Name (N) and then No (Entity (N)) then
13153 if Total_Errors_Detected /= 0 then
13154 Set_Entity (N, Any_Id);
13156 raise Program_Error;
13159 end Require_Entity;
13161 ------------------------------
13162 -- Requires_Transient_Scope --
13163 ------------------------------
13165 -- A transient scope is required when variable-sized temporaries are
13166 -- allocated in the primary or secondary stack, or when finalization
13167 -- actions must be generated before the next instruction.
13169 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
13170 Typ : constant Entity_Id := Underlying_Type (Id);
13172 -- Start of processing for Requires_Transient_Scope
13175 -- This is a private type which is not completed yet. This can only
13176 -- happen in a default expression (of a formal parameter or of a
13177 -- record component). Do not expand transient scope in this case
13182 -- Do not expand transient scope for non-existent procedure return
13184 elsif Typ = Standard_Void_Type then
13187 -- Elementary types do not require a transient scope
13189 elsif Is_Elementary_Type (Typ) then
13192 -- Generally, indefinite subtypes require a transient scope, since the
13193 -- back end cannot generate temporaries, since this is not a valid type
13194 -- for declaring an object. It might be possible to relax this in the
13195 -- future, e.g. by declaring the maximum possible space for the type.
13197 elsif Is_Indefinite_Subtype (Typ) then
13200 -- Functions returning tagged types may dispatch on result so their
13201 -- returned value is allocated on the secondary stack. Controlled
13202 -- type temporaries need finalization.
13204 elsif Is_Tagged_Type (Typ)
13205 or else Has_Controlled_Component (Typ)
13207 return not Is_Value_Type (Typ);
13211 elsif Is_Record_Type (Typ) then
13215 Comp := First_Entity (Typ);
13216 while Present (Comp) loop
13217 if Ekind (Comp) = E_Component
13218 and then Requires_Transient_Scope (Etype (Comp))
13222 Next_Entity (Comp);
13229 -- String literal types never require transient scope
13231 elsif Ekind (Typ) = E_String_Literal_Subtype then
13234 -- Array type. Note that we already know that this is a constrained
13235 -- array, since unconstrained arrays will fail the indefinite test.
13237 elsif Is_Array_Type (Typ) then
13239 -- If component type requires a transient scope, the array does too
13241 if Requires_Transient_Scope (Component_Type (Typ)) then
13244 -- Otherwise, we only need a transient scope if the size depends on
13245 -- the value of one or more discriminants.
13248 return Size_Depends_On_Discriminant (Typ);
13251 -- All other cases do not require a transient scope
13256 end Requires_Transient_Scope;
13258 --------------------------
13259 -- Reset_Analyzed_Flags --
13260 --------------------------
13262 procedure Reset_Analyzed_Flags (N : Node_Id) is
13264 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
13265 -- Function used to reset Analyzed flags in tree. Note that we do
13266 -- not reset Analyzed flags in entities, since there is no need to
13267 -- reanalyze entities, and indeed, it is wrong to do so, since it
13268 -- can result in generating auxiliary stuff more than once.
13270 --------------------
13271 -- Clear_Analyzed --
13272 --------------------
13274 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
13276 if not Has_Extension (N) then
13277 Set_Analyzed (N, False);
13281 end Clear_Analyzed;
13283 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
13285 -- Start of processing for Reset_Analyzed_Flags
13288 Reset_Analyzed (N);
13289 end Reset_Analyzed_Flags;
13291 --------------------------------
13292 -- Returns_Unconstrained_Type --
13293 --------------------------------
13295 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
13297 return Ekind (Subp) = E_Function
13298 and then not Is_Scalar_Type (Etype (Subp))
13299 and then not Is_Access_Type (Etype (Subp))
13300 and then not Is_Constrained (Etype (Subp));
13301 end Returns_Unconstrained_Type;
13303 ---------------------------
13304 -- Safe_To_Capture_Value --
13305 ---------------------------
13307 function Safe_To_Capture_Value
13310 Cond : Boolean := False) return Boolean
13313 -- The only entities for which we track constant values are variables
13314 -- which are not renamings, constants, out parameters, and in out
13315 -- parameters, so check if we have this case.
13317 -- Note: it may seem odd to track constant values for constants, but in
13318 -- fact this routine is used for other purposes than simply capturing
13319 -- the value. In particular, the setting of Known[_Non]_Null.
13321 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
13323 Ekind (Ent) = E_Constant
13325 Ekind (Ent) = E_Out_Parameter
13327 Ekind (Ent) = E_In_Out_Parameter
13331 -- For conditionals, we also allow loop parameters and all formals,
13332 -- including in parameters.
13336 (Ekind (Ent) = E_Loop_Parameter
13338 Ekind (Ent) = E_In_Parameter)
13342 -- For all other cases, not just unsafe, but impossible to capture
13343 -- Current_Value, since the above are the only entities which have
13344 -- Current_Value fields.
13350 -- Skip if volatile or aliased, since funny things might be going on in
13351 -- these cases which we cannot necessarily track. Also skip any variable
13352 -- for which an address clause is given, or whose address is taken. Also
13353 -- never capture value of library level variables (an attempt to do so
13354 -- can occur in the case of package elaboration code).
13356 if Treat_As_Volatile (Ent)
13357 or else Is_Aliased (Ent)
13358 or else Present (Address_Clause (Ent))
13359 or else Address_Taken (Ent)
13360 or else (Is_Library_Level_Entity (Ent)
13361 and then Ekind (Ent) = E_Variable)
13366 -- OK, all above conditions are met. We also require that the scope of
13367 -- the reference be the same as the scope of the entity, not counting
13368 -- packages and blocks and loops.
13371 E_Scope : constant Entity_Id := Scope (Ent);
13372 R_Scope : Entity_Id;
13375 R_Scope := Current_Scope;
13376 while R_Scope /= Standard_Standard loop
13377 exit when R_Scope = E_Scope;
13379 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
13382 R_Scope := Scope (R_Scope);
13387 -- We also require that the reference does not appear in a context
13388 -- where it is not sure to be executed (i.e. a conditional context
13389 -- or an exception handler). We skip this if Cond is True, since the
13390 -- capturing of values from conditional tests handles this ok.
13403 -- Seems dubious that case expressions are not handled here ???
13406 while Present (P) loop
13407 if Nkind (P) = N_If_Statement
13408 or else Nkind (P) = N_Case_Statement
13409 or else (Nkind (P) in N_Short_Circuit
13410 and then Desc = Right_Opnd (P))
13411 or else (Nkind (P) = N_If_Expression
13412 and then Desc /= First (Expressions (P)))
13413 or else Nkind (P) = N_Exception_Handler
13414 or else Nkind (P) = N_Selective_Accept
13415 or else Nkind (P) = N_Conditional_Entry_Call
13416 or else Nkind (P) = N_Timed_Entry_Call
13417 or else Nkind (P) = N_Asynchronous_Select
13424 -- A special Ada 2012 case: the original node may be part
13425 -- of the else_actions of a conditional expression, in which
13426 -- case it might not have been expanded yet, and appears in
13427 -- a non-syntactic list of actions. In that case it is clearly
13428 -- not safe to save a value.
13431 and then Is_List_Member (Desc)
13432 and then No (Parent (List_Containing (Desc)))
13440 -- OK, looks safe to set value
13443 end Safe_To_Capture_Value;
13449 function Same_Name (N1, N2 : Node_Id) return Boolean is
13450 K1 : constant Node_Kind := Nkind (N1);
13451 K2 : constant Node_Kind := Nkind (N2);
13454 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
13455 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
13457 return Chars (N1) = Chars (N2);
13459 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
13460 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
13462 return Same_Name (Selector_Name (N1), Selector_Name (N2))
13463 and then Same_Name (Prefix (N1), Prefix (N2));
13474 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
13475 N1 : constant Node_Id := Original_Node (Node1);
13476 N2 : constant Node_Id := Original_Node (Node2);
13477 -- We do the tests on original nodes, since we are most interested
13478 -- in the original source, not any expansion that got in the way.
13480 K1 : constant Node_Kind := Nkind (N1);
13481 K2 : constant Node_Kind := Nkind (N2);
13484 -- First case, both are entities with same entity
13486 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
13488 EN1 : constant Entity_Id := Entity (N1);
13489 EN2 : constant Entity_Id := Entity (N2);
13491 if Present (EN1) and then Present (EN2)
13492 and then (Ekind_In (EN1, E_Variable, E_Constant)
13493 or else Is_Formal (EN1))
13501 -- Second case, selected component with same selector, same record
13503 if K1 = N_Selected_Component
13504 and then K2 = N_Selected_Component
13505 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
13507 return Same_Object (Prefix (N1), Prefix (N2));
13509 -- Third case, indexed component with same subscripts, same array
13511 elsif K1 = N_Indexed_Component
13512 and then K2 = N_Indexed_Component
13513 and then Same_Object (Prefix (N1), Prefix (N2))
13518 E1 := First (Expressions (N1));
13519 E2 := First (Expressions (N2));
13520 while Present (E1) loop
13521 if not Same_Value (E1, E2) then
13532 -- Fourth case, slice of same array with same bounds
13535 and then K2 = N_Slice
13536 and then Nkind (Discrete_Range (N1)) = N_Range
13537 and then Nkind (Discrete_Range (N2)) = N_Range
13538 and then Same_Value (Low_Bound (Discrete_Range (N1)),
13539 Low_Bound (Discrete_Range (N2)))
13540 and then Same_Value (High_Bound (Discrete_Range (N1)),
13541 High_Bound (Discrete_Range (N2)))
13543 return Same_Name (Prefix (N1), Prefix (N2));
13545 -- All other cases, not clearly the same object
13556 function Same_Type (T1, T2 : Entity_Id) return Boolean is
13561 elsif not Is_Constrained (T1)
13562 and then not Is_Constrained (T2)
13563 and then Base_Type (T1) = Base_Type (T2)
13567 -- For now don't bother with case of identical constraints, to be
13568 -- fiddled with later on perhaps (this is only used for optimization
13569 -- purposes, so it is not critical to do a best possible job)
13580 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
13582 if Compile_Time_Known_Value (Node1)
13583 and then Compile_Time_Known_Value (Node2)
13584 and then Expr_Value (Node1) = Expr_Value (Node2)
13587 elsif Same_Object (Node1, Node2) then
13594 ------------------------
13595 -- Scope_Is_Transient --
13596 ------------------------
13598 function Scope_Is_Transient return Boolean is
13600 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
13601 end Scope_Is_Transient;
13607 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
13612 while Scop /= Standard_Standard loop
13613 Scop := Scope (Scop);
13615 if Scop = Scope2 then
13623 --------------------------
13624 -- Scope_Within_Or_Same --
13625 --------------------------
13627 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
13632 while Scop /= Standard_Standard loop
13633 if Scop = Scope2 then
13636 Scop := Scope (Scop);
13641 end Scope_Within_Or_Same;
13643 --------------------
13644 -- Set_Convention --
13645 --------------------
13647 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
13649 Basic_Set_Convention (E, Val);
13652 and then Is_Access_Subprogram_Type (Base_Type (E))
13653 and then Has_Foreign_Convention (E)
13655 Set_Can_Use_Internal_Rep (E, False);
13657 end Set_Convention;
13659 ------------------------
13660 -- Set_Current_Entity --
13661 ------------------------
13663 -- The given entity is to be set as the currently visible definition of its
13664 -- associated name (i.e. the Node_Id associated with its name). All we have
13665 -- to do is to get the name from the identifier, and then set the
13666 -- associated Node_Id to point to the given entity.
13668 procedure Set_Current_Entity (E : Entity_Id) is
13670 Set_Name_Entity_Id (Chars (E), E);
13671 end Set_Current_Entity;
13673 ---------------------------
13674 -- Set_Debug_Info_Needed --
13675 ---------------------------
13677 procedure Set_Debug_Info_Needed (T : Entity_Id) is
13679 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
13680 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
13681 -- Used to set debug info in a related node if not set already
13683 --------------------------------------
13684 -- Set_Debug_Info_Needed_If_Not_Set --
13685 --------------------------------------
13687 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
13690 and then not Needs_Debug_Info (E)
13692 Set_Debug_Info_Needed (E);
13694 -- For a private type, indicate that the full view also needs
13695 -- debug information.
13698 and then Is_Private_Type (E)
13699 and then Present (Full_View (E))
13701 Set_Debug_Info_Needed (Full_View (E));
13704 end Set_Debug_Info_Needed_If_Not_Set;
13706 -- Start of processing for Set_Debug_Info_Needed
13709 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
13710 -- indicates that Debug_Info_Needed is never required for the entity.
13713 or else Debug_Info_Off (T)
13718 -- Set flag in entity itself. Note that we will go through the following
13719 -- circuitry even if the flag is already set on T. That's intentional,
13720 -- it makes sure that the flag will be set in subsidiary entities.
13722 Set_Needs_Debug_Info (T);
13724 -- Set flag on subsidiary entities if not set already
13726 if Is_Object (T) then
13727 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
13729 elsif Is_Type (T) then
13730 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
13732 if Is_Record_Type (T) then
13734 Ent : Entity_Id := First_Entity (T);
13736 while Present (Ent) loop
13737 Set_Debug_Info_Needed_If_Not_Set (Ent);
13742 -- For a class wide subtype, we also need debug information
13743 -- for the equivalent type.
13745 if Ekind (T) = E_Class_Wide_Subtype then
13746 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
13749 elsif Is_Array_Type (T) then
13750 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
13753 Indx : Node_Id := First_Index (T);
13755 while Present (Indx) loop
13756 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
13757 Indx := Next_Index (Indx);
13761 -- For a packed array type, we also need debug information for
13762 -- the type used to represent the packed array. Conversely, we
13763 -- also need it for the former if we need it for the latter.
13765 if Is_Packed (T) then
13766 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
13769 if Is_Packed_Array_Type (T) then
13770 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
13773 elsif Is_Access_Type (T) then
13774 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
13776 elsif Is_Private_Type (T) then
13777 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
13779 elsif Is_Protected_Type (T) then
13780 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
13783 end Set_Debug_Info_Needed;
13785 ---------------------------------
13786 -- Set_Entity_With_Style_Check --
13787 ---------------------------------
13789 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
13790 Val_Actual : Entity_Id;
13794 -- Unconditionally set the entity
13796 Set_Entity (N, Val);
13798 -- Check for No_Implementation_Identifiers
13800 if Restriction_Check_Required (No_Implementation_Identifiers) then
13802 -- We have an implementation defined entity if it is marked as
13803 -- implementation defined, or is defined in a package marked as
13804 -- implementation defined. However, library packages themselves
13805 -- are excluded (we don't want to flag Interfaces itself, just
13806 -- the entities within it).
13808 if (Is_Implementation_Defined (Val)
13810 Is_Implementation_Defined (Scope (Val)))
13811 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
13812 and then Is_Library_Level_Entity (Val))
13814 Check_Restriction (No_Implementation_Identifiers, N);
13818 -- Do the style check
13821 and then not Suppress_Style_Checks (Val)
13822 and then not In_Instance
13824 if Nkind (N) = N_Identifier then
13826 elsif Nkind (N) = N_Expanded_Name then
13827 Nod := Selector_Name (N);
13832 -- A special situation arises for derived operations, where we want
13833 -- to do the check against the parent (since the Sloc of the derived
13834 -- operation points to the derived type declaration itself).
13837 while not Comes_From_Source (Val_Actual)
13838 and then Nkind (Val_Actual) in N_Entity
13839 and then (Ekind (Val_Actual) = E_Enumeration_Literal
13840 or else Is_Subprogram (Val_Actual)
13841 or else Is_Generic_Subprogram (Val_Actual))
13842 and then Present (Alias (Val_Actual))
13844 Val_Actual := Alias (Val_Actual);
13847 -- Renaming declarations for generic actuals do not come from source,
13848 -- and have a different name from that of the entity they rename, so
13849 -- there is no style check to perform here.
13851 if Chars (Nod) = Chars (Val_Actual) then
13852 Style.Check_Identifier (Nod, Val_Actual);
13856 Set_Entity (N, Val);
13857 end Set_Entity_With_Style_Check;
13859 ------------------------
13860 -- Set_Name_Entity_Id --
13861 ------------------------
13863 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
13865 Set_Name_Table_Info (Id, Int (Val));
13866 end Set_Name_Entity_Id;
13868 ---------------------
13869 -- Set_Next_Actual --
13870 ---------------------
13872 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
13874 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
13875 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
13877 end Set_Next_Actual;
13879 ----------------------------------
13880 -- Set_Optimize_Alignment_Flags --
13881 ----------------------------------
13883 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
13885 if Optimize_Alignment = 'S' then
13886 Set_Optimize_Alignment_Space (E);
13887 elsif Optimize_Alignment = 'T' then
13888 Set_Optimize_Alignment_Time (E);
13890 end Set_Optimize_Alignment_Flags;
13892 -----------------------
13893 -- Set_Public_Status --
13894 -----------------------
13896 procedure Set_Public_Status (Id : Entity_Id) is
13897 S : constant Entity_Id := Current_Scope;
13899 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
13900 -- Determines if E is defined within handled statement sequence or
13901 -- an if statement, returns True if so, False otherwise.
13903 ----------------------
13904 -- Within_HSS_Or_If --
13905 ----------------------
13907 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
13910 N := Declaration_Node (E);
13917 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
13923 end Within_HSS_Or_If;
13925 -- Start of processing for Set_Public_Status
13928 -- Everything in the scope of Standard is public
13930 if S = Standard_Standard then
13931 Set_Is_Public (Id);
13933 -- Entity is definitely not public if enclosing scope is not public
13935 elsif not Is_Public (S) then
13938 -- An object or function declaration that occurs in a handled sequence
13939 -- of statements or within an if statement is the declaration for a
13940 -- temporary object or local subprogram generated by the expander. It
13941 -- never needs to be made public and furthermore, making it public can
13942 -- cause back end problems.
13944 elsif Nkind_In (Parent (Id), N_Object_Declaration,
13945 N_Function_Specification)
13946 and then Within_HSS_Or_If (Id)
13950 -- Entities in public packages or records are public
13952 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
13953 Set_Is_Public (Id);
13955 -- The bounds of an entry family declaration can generate object
13956 -- declarations that are visible to the back-end, e.g. in the
13957 -- the declaration of a composite type that contains tasks.
13959 elsif Is_Concurrent_Type (S)
13960 and then not Has_Completion (S)
13961 and then Nkind (Parent (Id)) = N_Object_Declaration
13963 Set_Is_Public (Id);
13965 end Set_Public_Status;
13967 -----------------------------
13968 -- Set_Referenced_Modified --
13969 -----------------------------
13971 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
13975 -- Deal with indexed or selected component where prefix is modified
13977 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
13978 Pref := Prefix (N);
13980 -- If prefix is access type, then it is the designated object that is
13981 -- being modified, which means we have no entity to set the flag on.
13983 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
13986 -- Otherwise chase the prefix
13989 Set_Referenced_Modified (Pref, Out_Param);
13992 -- Otherwise see if we have an entity name (only other case to process)
13994 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
13995 Set_Referenced_As_LHS (Entity (N), not Out_Param);
13996 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
13998 end Set_Referenced_Modified;
14000 ----------------------------
14001 -- Set_Scope_Is_Transient --
14002 ----------------------------
14004 procedure Set_Scope_Is_Transient (V : Boolean := True) is
14006 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
14007 end Set_Scope_Is_Transient;
14009 -------------------
14010 -- Set_Size_Info --
14011 -------------------
14013 procedure Set_Size_Info (T1, T2 : Entity_Id) is
14015 -- We copy Esize, but not RM_Size, since in general RM_Size is
14016 -- subtype specific and does not get inherited by all subtypes.
14018 Set_Esize (T1, Esize (T2));
14019 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
14021 if Is_Discrete_Or_Fixed_Point_Type (T1)
14023 Is_Discrete_Or_Fixed_Point_Type (T2)
14025 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
14028 Set_Alignment (T1, Alignment (T2));
14031 --------------------
14032 -- Static_Boolean --
14033 --------------------
14035 function Static_Boolean (N : Node_Id) return Uint is
14037 Analyze_And_Resolve (N, Standard_Boolean);
14040 or else Error_Posted (N)
14041 or else Etype (N) = Any_Type
14046 if Is_Static_Expression (N) then
14047 if not Raises_Constraint_Error (N) then
14048 return Expr_Value (N);
14053 elsif Etype (N) = Any_Type then
14057 Flag_Non_Static_Expr
14058 ("static boolean expression required here", N);
14061 end Static_Boolean;
14063 --------------------
14064 -- Static_Integer --
14065 --------------------
14067 function Static_Integer (N : Node_Id) return Uint is
14069 Analyze_And_Resolve (N, Any_Integer);
14072 or else Error_Posted (N)
14073 or else Etype (N) = Any_Type
14078 if Is_Static_Expression (N) then
14079 if not Raises_Constraint_Error (N) then
14080 return Expr_Value (N);
14085 elsif Etype (N) = Any_Type then
14089 Flag_Non_Static_Expr
14090 ("static integer expression required here", N);
14093 end Static_Integer;
14095 --------------------------
14096 -- Statically_Different --
14097 --------------------------
14099 function Statically_Different (E1, E2 : Node_Id) return Boolean is
14100 R1 : constant Node_Id := Get_Referenced_Object (E1);
14101 R2 : constant Node_Id := Get_Referenced_Object (E2);
14103 return Is_Entity_Name (R1)
14104 and then Is_Entity_Name (R2)
14105 and then Entity (R1) /= Entity (R2)
14106 and then not Is_Formal (Entity (R1))
14107 and then not Is_Formal (Entity (R2));
14108 end Statically_Different;
14110 --------------------------------------
14111 -- Subject_To_Loop_Entry_Attributes --
14112 --------------------------------------
14114 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
14120 -- The expansion mechanism transform a loop subject to at least one
14121 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
14122 -- the conditional part.
14124 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
14125 and then Nkind (Original_Node (N)) = N_Loop_Statement
14127 Stmt := Original_Node (N);
14131 Nkind (Stmt) = N_Loop_Statement
14132 and then Present (Identifier (Stmt))
14133 and then Present (Entity (Identifier (Stmt)))
14134 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
14135 end Subject_To_Loop_Entry_Attributes;
14137 -----------------------------
14138 -- Subprogram_Access_Level --
14139 -----------------------------
14141 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
14143 if Present (Alias (Subp)) then
14144 return Subprogram_Access_Level (Alias (Subp));
14146 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
14148 end Subprogram_Access_Level;
14150 -------------------------------
14151 -- Support_Atomic_Primitives --
14152 -------------------------------
14154 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
14158 -- Verify the alignment of Typ is known
14160 if not Known_Alignment (Typ) then
14164 if Known_Static_Esize (Typ) then
14165 Size := UI_To_Int (Esize (Typ));
14167 -- If the Esize (Object_Size) is unknown at compile time, look at the
14168 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
14170 elsif Known_Static_RM_Size (Typ) then
14171 Size := UI_To_Int (RM_Size (Typ));
14173 -- Otherwise, the size is considered to be unknown.
14179 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
14180 -- Typ is properly aligned.
14183 when 8 | 16 | 32 | 64 =>
14184 return Size = UI_To_Int (Alignment (Typ)) * 8;
14188 end Support_Atomic_Primitives;
14194 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
14196 if Debug_Flag_W then
14197 for J in 0 .. Scope_Stack.Last loop
14202 Write_Name (Chars (E));
14203 Write_Str (" from ");
14204 Write_Location (Sloc (N));
14209 -----------------------
14210 -- Transfer_Entities --
14211 -----------------------
14213 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
14214 Ent : Entity_Id := First_Entity (From);
14221 if (Last_Entity (To)) = Empty then
14222 Set_First_Entity (To, Ent);
14224 Set_Next_Entity (Last_Entity (To), Ent);
14227 Set_Last_Entity (To, Last_Entity (From));
14229 while Present (Ent) loop
14230 Set_Scope (Ent, To);
14232 if not Is_Public (Ent) then
14233 Set_Public_Status (Ent);
14236 and then Ekind (Ent) = E_Record_Subtype
14239 -- The components of the propagated Itype must be public
14245 Comp := First_Entity (Ent);
14246 while Present (Comp) loop
14247 Set_Is_Public (Comp);
14248 Next_Entity (Comp);
14257 Set_First_Entity (From, Empty);
14258 Set_Last_Entity (From, Empty);
14259 end Transfer_Entities;
14261 -----------------------
14262 -- Type_Access_Level --
14263 -----------------------
14265 function Type_Access_Level (Typ : Entity_Id) return Uint is
14269 Btyp := Base_Type (Typ);
14271 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
14272 -- simply use the level where the type is declared. This is true for
14273 -- stand-alone object declarations, and for anonymous access types
14274 -- associated with components the level is the same as that of the
14275 -- enclosing composite type. However, special treatment is needed for
14276 -- the cases of access parameters, return objects of an anonymous access
14277 -- type, and, in Ada 95, access discriminants of limited types.
14279 if Ekind (Btyp) in Access_Kind then
14280 if Ekind (Btyp) = E_Anonymous_Access_Type then
14282 -- If the type is a nonlocal anonymous access type (such as for
14283 -- an access parameter) we treat it as being declared at the
14284 -- library level to ensure that names such as X.all'access don't
14285 -- fail static accessibility checks.
14287 if not Is_Local_Anonymous_Access (Typ) then
14288 return Scope_Depth (Standard_Standard);
14290 -- If this is a return object, the accessibility level is that of
14291 -- the result subtype of the enclosing function. The test here is
14292 -- little complicated, because we have to account for extended
14293 -- return statements that have been rewritten as blocks, in which
14294 -- case we have to find and the Is_Return_Object attribute of the
14295 -- itype's associated object. It would be nice to find a way to
14296 -- simplify this test, but it doesn't seem worthwhile to add a new
14297 -- flag just for purposes of this test. ???
14299 elsif Ekind (Scope (Btyp)) = E_Return_Statement
14302 and then Nkind (Associated_Node_For_Itype (Btyp)) =
14303 N_Object_Declaration
14304 and then Is_Return_Object
14305 (Defining_Identifier
14306 (Associated_Node_For_Itype (Btyp))))
14312 Scop := Scope (Scope (Btyp));
14313 while Present (Scop) loop
14314 exit when Ekind (Scop) = E_Function;
14315 Scop := Scope (Scop);
14318 -- Treat the return object's type as having the level of the
14319 -- function's result subtype (as per RM05-6.5(5.3/2)).
14321 return Type_Access_Level (Etype (Scop));
14326 Btyp := Root_Type (Btyp);
14328 -- The accessibility level of anonymous access types associated with
14329 -- discriminants is that of the current instance of the type, and
14330 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
14332 -- AI-402: access discriminants have accessibility based on the
14333 -- object rather than the type in Ada 2005, so the above paragraph
14336 -- ??? Needs completion with rules from AI-416
14338 if Ada_Version <= Ada_95
14339 and then Ekind (Typ) = E_Anonymous_Access_Type
14340 and then Present (Associated_Node_For_Itype (Typ))
14341 and then Nkind (Associated_Node_For_Itype (Typ)) =
14342 N_Discriminant_Specification
14344 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
14348 -- Return library level for a generic formal type. This is done because
14349 -- RM(10.3.2) says that "The statically deeper relationship does not
14350 -- apply to ... a descendant of a generic formal type". Rather than
14351 -- checking at each point where a static accessibility check is
14352 -- performed to see if we are dealing with a formal type, this rule is
14353 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
14354 -- return extreme values for a formal type; Deepest_Type_Access_Level
14355 -- returns Int'Last. By calling the appropriate function from among the
14356 -- two, we ensure that the static accessibility check will pass if we
14357 -- happen to run into a formal type. More specifically, we should call
14358 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
14359 -- call occurs as part of a static accessibility check and the error
14360 -- case is the case where the type's level is too shallow (as opposed
14363 if Is_Generic_Type (Root_Type (Btyp)) then
14364 return Scope_Depth (Standard_Standard);
14367 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
14368 end Type_Access_Level;
14370 ------------------------------------
14371 -- Type_Without_Stream_Operation --
14372 ------------------------------------
14374 function Type_Without_Stream_Operation
14376 Op : TSS_Name_Type := TSS_Null) return Entity_Id
14378 BT : constant Entity_Id := Base_Type (T);
14379 Op_Missing : Boolean;
14382 if not Restriction_Active (No_Default_Stream_Attributes) then
14386 if Is_Elementary_Type (T) then
14387 if Op = TSS_Null then
14389 No (TSS (BT, TSS_Stream_Read))
14390 or else No (TSS (BT, TSS_Stream_Write));
14393 Op_Missing := No (TSS (BT, Op));
14402 elsif Is_Array_Type (T) then
14403 return Type_Without_Stream_Operation (Component_Type (T), Op);
14405 elsif Is_Record_Type (T) then
14411 Comp := First_Component (T);
14412 while Present (Comp) loop
14413 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
14415 if Present (C_Typ) then
14419 Next_Component (Comp);
14425 elsif Is_Private_Type (T)
14426 and then Present (Full_View (T))
14428 return Type_Without_Stream_Operation (Full_View (T), Op);
14432 end Type_Without_Stream_Operation;
14434 ----------------------------
14435 -- Unique_Defining_Entity --
14436 ----------------------------
14438 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
14440 return Unique_Entity (Defining_Entity (N));
14441 end Unique_Defining_Entity;
14443 -------------------
14444 -- Unique_Entity --
14445 -------------------
14447 function Unique_Entity (E : Entity_Id) return Entity_Id is
14448 U : Entity_Id := E;
14454 if Present (Full_View (E)) then
14455 U := Full_View (E);
14459 if Present (Full_View (E)) then
14460 U := Full_View (E);
14463 when E_Package_Body =>
14466 if Nkind (P) = N_Defining_Program_Unit_Name then
14470 U := Corresponding_Spec (P);
14472 when E_Subprogram_Body =>
14475 if Nkind (P) = N_Defining_Program_Unit_Name then
14481 if Nkind (P) = N_Subprogram_Body_Stub then
14482 if Present (Library_Unit (P)) then
14484 -- Get to the function or procedure (generic) entity through
14485 -- the body entity.
14488 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
14491 U := Corresponding_Spec (P);
14494 when Formal_Kind =>
14495 if Present (Spec_Entity (E)) then
14496 U := Spec_Entity (E);
14510 function Unique_Name (E : Entity_Id) return String is
14512 -- Names of E_Subprogram_Body or E_Package_Body entities are not
14513 -- reliable, as they may not include the overloading suffix. Instead,
14514 -- when looking for the name of E or one of its enclosing scope, we get
14515 -- the name of the corresponding Unique_Entity.
14517 function Get_Scoped_Name (E : Entity_Id) return String;
14518 -- Return the name of E prefixed by all the names of the scopes to which
14519 -- E belongs, except for Standard.
14521 ---------------------
14522 -- Get_Scoped_Name --
14523 ---------------------
14525 function Get_Scoped_Name (E : Entity_Id) return String is
14526 Name : constant String := Get_Name_String (Chars (E));
14528 if Has_Fully_Qualified_Name (E)
14529 or else Scope (E) = Standard_Standard
14533 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
14535 end Get_Scoped_Name;
14537 -- Start of processing for Unique_Name
14540 if E = Standard_Standard then
14541 return Get_Name_String (Name_Standard);
14543 elsif Scope (E) = Standard_Standard
14544 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
14546 return Get_Name_String (Name_Standard) & "__" &
14547 Get_Name_String (Chars (E));
14549 elsif Ekind (E) = E_Enumeration_Literal then
14550 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
14553 return Get_Scoped_Name (Unique_Entity (E));
14557 ---------------------
14558 -- Unit_Is_Visible --
14559 ---------------------
14561 function Unit_Is_Visible (U : Entity_Id) return Boolean is
14562 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
14563 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
14565 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
14566 -- For a child unit, check whether unit appears in a with_clause
14569 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
14570 -- Scan the context clause of one compilation unit looking for a
14571 -- with_clause for the unit in question.
14573 ----------------------------
14574 -- Unit_In_Parent_Context --
14575 ----------------------------
14577 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
14579 if Unit_In_Context (Par_Unit) then
14582 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
14583 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
14588 end Unit_In_Parent_Context;
14590 ---------------------
14591 -- Unit_In_Context --
14592 ---------------------
14594 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
14598 Clause := First (Context_Items (Comp_Unit));
14599 while Present (Clause) loop
14600 if Nkind (Clause) = N_With_Clause then
14601 if Library_Unit (Clause) = U then
14604 -- The with_clause may denote a renaming of the unit we are
14605 -- looking for, eg. Text_IO which renames Ada.Text_IO.
14608 Renamed_Entity (Entity (Name (Clause))) =
14609 Defining_Entity (Unit (U))
14619 end Unit_In_Context;
14621 -- Start of processing for Unit_Is_Visible
14624 -- The currrent unit is directly visible
14629 elsif Unit_In_Context (Curr) then
14632 -- If the current unit is a body, check the context of the spec
14634 elsif Nkind (Unit (Curr)) = N_Package_Body
14636 (Nkind (Unit (Curr)) = N_Subprogram_Body
14637 and then not Acts_As_Spec (Unit (Curr)))
14639 if Unit_In_Context (Library_Unit (Curr)) then
14644 -- If the spec is a child unit, examine the parents
14646 if Is_Child_Unit (Curr_Entity) then
14647 if Nkind (Unit (Curr)) in N_Unit_Body then
14649 Unit_In_Parent_Context
14650 (Parent_Spec (Unit (Library_Unit (Curr))));
14652 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
14658 end Unit_Is_Visible;
14660 ------------------------------
14661 -- Universal_Interpretation --
14662 ------------------------------
14664 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
14665 Index : Interp_Index;
14669 -- The argument may be a formal parameter of an operator or subprogram
14670 -- with multiple interpretations, or else an expression for an actual.
14672 if Nkind (Opnd) = N_Defining_Identifier
14673 or else not Is_Overloaded (Opnd)
14675 if Etype (Opnd) = Universal_Integer
14676 or else Etype (Opnd) = Universal_Real
14678 return Etype (Opnd);
14684 Get_First_Interp (Opnd, Index, It);
14685 while Present (It.Typ) loop
14686 if It.Typ = Universal_Integer
14687 or else It.Typ = Universal_Real
14692 Get_Next_Interp (Index, It);
14697 end Universal_Interpretation;
14703 function Unqualify (Expr : Node_Id) return Node_Id is
14705 -- Recurse to handle unlikely case of multiple levels of qualification
14707 if Nkind (Expr) = N_Qualified_Expression then
14708 return Unqualify (Expression (Expr));
14710 -- Normal case, not a qualified expression
14717 -----------------------
14718 -- Visible_Ancestors --
14719 -----------------------
14721 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
14727 pragma Assert (Is_Record_Type (Typ)
14728 and then Is_Tagged_Type (Typ));
14730 -- Collect all the parents and progenitors of Typ. If the full-view of
14731 -- private parents and progenitors is available then it is used to
14732 -- generate the list of visible ancestors; otherwise their partial
14733 -- view is added to the resulting list.
14738 Use_Full_View => True);
14742 Ifaces_List => List_2,
14743 Exclude_Parents => True,
14744 Use_Full_View => True);
14746 -- Join the two lists. Avoid duplications because an interface may
14747 -- simultaneously be parent and progenitor of a type.
14749 Elmt := First_Elmt (List_2);
14750 while Present (Elmt) loop
14751 Append_Unique_Elmt (Node (Elmt), List_1);
14756 end Visible_Ancestors;
14758 ----------------------
14759 -- Within_Init_Proc --
14760 ----------------------
14762 function Within_Init_Proc return Boolean is
14766 S := Current_Scope;
14767 while not Is_Overloadable (S) loop
14768 if S = Standard_Standard then
14775 return Is_Init_Proc (S);
14776 end Within_Init_Proc;
14782 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
14783 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
14784 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
14786 Matching_Field : Entity_Id;
14787 -- Entity to give a more precise suggestion on how to write a one-
14788 -- element positional aggregate.
14790 function Has_One_Matching_Field return Boolean;
14791 -- Determines if Expec_Type is a record type with a single component or
14792 -- discriminant whose type matches the found type or is one dimensional
14793 -- array whose component type matches the found type. In the case of
14794 -- one discriminant, we ignore the variant parts. That's not accurate,
14795 -- but good enough for the warning.
14797 ----------------------------
14798 -- Has_One_Matching_Field --
14799 ----------------------------
14801 function Has_One_Matching_Field return Boolean is
14805 Matching_Field := Empty;
14807 if Is_Array_Type (Expec_Type)
14808 and then Number_Dimensions (Expec_Type) = 1
14810 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
14812 -- Use type name if available. This excludes multidimensional
14813 -- arrays and anonymous arrays.
14815 if Comes_From_Source (Expec_Type) then
14816 Matching_Field := Expec_Type;
14818 -- For an assignment, use name of target
14820 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
14821 and then Is_Entity_Name (Name (Parent (Expr)))
14823 Matching_Field := Entity (Name (Parent (Expr)));
14828 elsif not Is_Record_Type (Expec_Type) then
14832 E := First_Entity (Expec_Type);
14837 elsif not Ekind_In (E, E_Discriminant, E_Component)
14838 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
14847 if not Covers (Etype (E), Found_Type) then
14850 elsif Present (Next_Entity (E))
14851 and then (Ekind (E) = E_Component
14852 or else Ekind (Next_Entity (E)) = E_Discriminant)
14857 Matching_Field := E;
14861 end Has_One_Matching_Field;
14863 -- Start of processing for Wrong_Type
14866 -- Don't output message if either type is Any_Type, or if a message
14867 -- has already been posted for this node. We need to do the latter
14868 -- check explicitly (it is ordinarily done in Errout), because we
14869 -- are using ! to force the output of the error messages.
14871 if Expec_Type = Any_Type
14872 or else Found_Type = Any_Type
14873 or else Error_Posted (Expr)
14877 -- If one of the types is a Taft-Amendment type and the other it its
14878 -- completion, it must be an illegal use of a TAT in the spec, for
14879 -- which an error was already emitted. Avoid cascaded errors.
14881 elsif Is_Incomplete_Type (Expec_Type)
14882 and then Has_Completion_In_Body (Expec_Type)
14883 and then Full_View (Expec_Type) = Etype (Expr)
14887 elsif Is_Incomplete_Type (Etype (Expr))
14888 and then Has_Completion_In_Body (Etype (Expr))
14889 and then Full_View (Etype (Expr)) = Expec_Type
14893 -- In an instance, there is an ongoing problem with completion of
14894 -- type derived from private types. Their structure is what Gigi
14895 -- expects, but the Etype is the parent type rather than the
14896 -- derived private type itself. Do not flag error in this case. The
14897 -- private completion is an entity without a parent, like an Itype.
14898 -- Similarly, full and partial views may be incorrect in the instance.
14899 -- There is no simple way to insure that it is consistent ???
14901 elsif In_Instance then
14902 if Etype (Etype (Expr)) = Etype (Expected_Type)
14904 (Has_Private_Declaration (Expected_Type)
14905 or else Has_Private_Declaration (Etype (Expr)))
14906 and then No (Parent (Expected_Type))
14912 -- An interesting special check. If the expression is parenthesized
14913 -- and its type corresponds to the type of the sole component of the
14914 -- expected record type, or to the component type of the expected one
14915 -- dimensional array type, then assume we have a bad aggregate attempt.
14917 if Nkind (Expr) in N_Subexpr
14918 and then Paren_Count (Expr) /= 0
14919 and then Has_One_Matching_Field
14921 Error_Msg_N ("positional aggregate cannot have one component", Expr);
14922 if Present (Matching_Field) then
14923 if Is_Array_Type (Expec_Type) then
14925 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
14929 ("\write instead `& ='> ...`", Expr, Matching_Field);
14933 -- Another special check, if we are looking for a pool-specific access
14934 -- type and we found an E_Access_Attribute_Type, then we have the case
14935 -- of an Access attribute being used in a context which needs a pool-
14936 -- specific type, which is never allowed. The one extra check we make
14937 -- is that the expected designated type covers the Found_Type.
14939 elsif Is_Access_Type (Expec_Type)
14940 and then Ekind (Found_Type) = E_Access_Attribute_Type
14941 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
14942 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
14944 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
14946 Error_Msg_N -- CODEFIX
14947 ("result must be general access type!", Expr);
14948 Error_Msg_NE -- CODEFIX
14949 ("add ALL to }!", Expr, Expec_Type);
14951 -- Another special check, if the expected type is an integer type,
14952 -- but the expression is of type System.Address, and the parent is
14953 -- an addition or subtraction operation whose left operand is the
14954 -- expression in question and whose right operand is of an integral
14955 -- type, then this is an attempt at address arithmetic, so give
14956 -- appropriate message.
14958 elsif Is_Integer_Type (Expec_Type)
14959 and then Is_RTE (Found_Type, RE_Address)
14960 and then (Nkind (Parent (Expr)) = N_Op_Add
14962 Nkind (Parent (Expr)) = N_Op_Subtract)
14963 and then Expr = Left_Opnd (Parent (Expr))
14964 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
14967 ("address arithmetic not predefined in package System",
14970 ("\possible missing with/use of System.Storage_Elements",
14974 -- If the expected type is an anonymous access type, as for access
14975 -- parameters and discriminants, the error is on the designated types.
14977 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
14978 if Comes_From_Source (Expec_Type) then
14979 Error_Msg_NE ("expected}!", Expr, Expec_Type);
14982 ("expected an access type with designated}",
14983 Expr, Designated_Type (Expec_Type));
14986 if Is_Access_Type (Found_Type)
14987 and then not Comes_From_Source (Found_Type)
14990 ("\\found an access type with designated}!",
14991 Expr, Designated_Type (Found_Type));
14993 if From_With_Type (Found_Type) then
14994 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
14995 Error_Msg_Qual_Level := 99;
14996 Error_Msg_NE -- CODEFIX
14997 ("\\missing `WITH &;", Expr, Scope (Found_Type));
14998 Error_Msg_Qual_Level := 0;
15000 Error_Msg_NE ("found}!", Expr, Found_Type);
15004 -- Normal case of one type found, some other type expected
15007 -- If the names of the two types are the same, see if some number
15008 -- of levels of qualification will help. Don't try more than three
15009 -- levels, and if we get to standard, it's no use (and probably
15010 -- represents an error in the compiler) Also do not bother with
15011 -- internal scope names.
15014 Expec_Scope : Entity_Id;
15015 Found_Scope : Entity_Id;
15018 Expec_Scope := Expec_Type;
15019 Found_Scope := Found_Type;
15021 for Levels in Int range 0 .. 3 loop
15022 if Chars (Expec_Scope) /= Chars (Found_Scope) then
15023 Error_Msg_Qual_Level := Levels;
15027 Expec_Scope := Scope (Expec_Scope);
15028 Found_Scope := Scope (Found_Scope);
15030 exit when Expec_Scope = Standard_Standard
15031 or else Found_Scope = Standard_Standard
15032 or else not Comes_From_Source (Expec_Scope)
15033 or else not Comes_From_Source (Found_Scope);
15037 if Is_Record_Type (Expec_Type)
15038 and then Present (Corresponding_Remote_Type (Expec_Type))
15040 Error_Msg_NE ("expected}!", Expr,
15041 Corresponding_Remote_Type (Expec_Type));
15043 Error_Msg_NE ("expected}!", Expr, Expec_Type);
15046 if Is_Entity_Name (Expr)
15047 and then Is_Package_Or_Generic_Package (Entity (Expr))
15049 Error_Msg_N ("\\found package name!", Expr);
15051 elsif Is_Entity_Name (Expr)
15053 (Ekind (Entity (Expr)) = E_Procedure
15055 Ekind (Entity (Expr)) = E_Generic_Procedure)
15057 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
15059 ("found procedure name, possibly missing Access attribute!",
15063 ("\\found procedure name instead of function!", Expr);
15066 elsif Nkind (Expr) = N_Function_Call
15067 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
15068 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
15069 and then No (Parameter_Associations (Expr))
15072 ("found function name, possibly missing Access attribute!",
15075 -- Catch common error: a prefix or infix operator which is not
15076 -- directly visible because the type isn't.
15078 elsif Nkind (Expr) in N_Op
15079 and then Is_Overloaded (Expr)
15080 and then not Is_Immediately_Visible (Expec_Type)
15081 and then not Is_Potentially_Use_Visible (Expec_Type)
15082 and then not In_Use (Expec_Type)
15083 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
15086 ("operator of the type is not directly visible!", Expr);
15088 elsif Ekind (Found_Type) = E_Void
15089 and then Present (Parent (Found_Type))
15090 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
15092 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
15095 Error_Msg_NE ("\\found}!", Expr, Found_Type);
15098 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
15099 -- of the same modular type, and (M1 and M2) = 0 was intended.
15101 if Expec_Type = Standard_Boolean
15102 and then Is_Modular_Integer_Type (Found_Type)
15103 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
15104 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
15107 Op : constant Node_Id := Right_Opnd (Parent (Expr));
15108 L : constant Node_Id := Left_Opnd (Op);
15109 R : constant Node_Id := Right_Opnd (Op);
15111 -- The case for the message is when the left operand of the
15112 -- comparison is the same modular type, or when it is an
15113 -- integer literal (or other universal integer expression),
15114 -- which would have been typed as the modular type if the
15115 -- parens had been there.
15117 if (Etype (L) = Found_Type
15119 Etype (L) = Universal_Integer)
15120 and then Is_Integer_Type (Etype (R))
15123 ("\\possible missing parens for modular operation", Expr);
15128 -- Reset error message qualification indication
15130 Error_Msg_Qual_Level := 0;