1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Type; use Sem_Type;
54 with Sinfo; use Sinfo;
55 with Sinput; use Sinput;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
67 package body Sem_Util is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold : constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used : Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries : Nat;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup : Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num is Int range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 ----------------------------------
99 -- Order Dependence (AI05-0144) --
100 ----------------------------------
102 -- Each actual in a call is entered into the table below. A flag indicates
103 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
104 -- (procedure call, condition, assignment) examines all the actuals for a
105 -- possible order dependence. The table is reset after each such check.
106 -- The actuals to be checked in a call to Check_Order_Dependence are at
107 -- positions 1 .. Last.
109 type Actual_Name is record
111 Is_Writable : Boolean;
114 package Actuals_In_Call is new Table.Table (
115 Table_Component_Type => Actual_Name,
116 Table_Index_Type => Int,
117 Table_Low_Bound => 0,
119 Table_Increment => 100,
120 Table_Name => "Actuals");
122 -----------------------
123 -- Local Subprograms --
124 -----------------------
126 function Build_Component_Subtype
129 T : Entity_Id) return Node_Id;
130 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
131 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
132 -- Loc is the source location, T is the original subtype.
134 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
135 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
136 -- with discriminants whose default values are static, examine only the
137 -- components in the selected variant to determine whether all of them
140 function Has_Null_Extension (T : Entity_Id) return Boolean;
141 -- T is a derived tagged type. Check whether the type extension is null.
142 -- If the parent type is fully initialized, T can be treated as such.
144 procedure Mark_Non_ALFA_Subprogram_Unconditional
147 -- Perform the action for Mark_Non_ALFA_Subprogram_Body, which allows the
148 -- latter to be small and inlined. If the subprogram being marked as not in
149 -- ALFA is annotated with Formal_Proof being On, then an error is issued
150 -- with message Msg on node N.
152 ------------------------------
153 -- Abstract_Interface_List --
154 ------------------------------
156 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
160 if Is_Concurrent_Type (Typ) then
162 -- If we are dealing with a synchronized subtype, go to the base
163 -- type, whose declaration has the interface list.
165 -- Shouldn't this be Declaration_Node???
167 Nod := Parent (Base_Type (Typ));
169 if Nkind (Nod) = N_Full_Type_Declaration then
173 elsif Ekind (Typ) = E_Record_Type_With_Private then
174 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
175 Nod := Type_Definition (Parent (Typ));
177 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
178 if Present (Full_View (Typ))
179 and then Nkind (Parent (Full_View (Typ)))
180 = N_Full_Type_Declaration
182 Nod := Type_Definition (Parent (Full_View (Typ)));
184 -- If the full-view is not available we cannot do anything else
185 -- here (the source has errors).
191 -- Support for generic formals with interfaces is still missing ???
193 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
198 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
202 elsif Ekind (Typ) = E_Record_Subtype then
203 Nod := Type_Definition (Parent (Etype (Typ)));
205 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
207 -- Recurse, because parent may still be a private extension. Also
208 -- note that the full view of the subtype or the full view of its
209 -- base type may (both) be unavailable.
211 return Abstract_Interface_List (Etype (Typ));
213 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
214 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
215 Nod := Formal_Type_Definition (Parent (Typ));
217 Nod := Type_Definition (Parent (Typ));
221 return Interface_List (Nod);
222 end Abstract_Interface_List;
224 --------------------------------
225 -- Add_Access_Type_To_Process --
226 --------------------------------
228 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
232 Ensure_Freeze_Node (E);
233 L := Access_Types_To_Process (Freeze_Node (E));
237 Set_Access_Types_To_Process (Freeze_Node (E), L);
241 end Add_Access_Type_To_Process;
243 ----------------------------
244 -- Add_Global_Declaration --
245 ----------------------------
247 procedure Add_Global_Declaration (N : Node_Id) is
248 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
251 if No (Declarations (Aux_Node)) then
252 Set_Declarations (Aux_Node, New_List);
255 Append_To (Declarations (Aux_Node), N);
257 end Add_Global_Declaration;
263 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
265 function Addressable (V : Uint) return Boolean is
267 return V = Uint_8 or else
273 function Addressable (V : Int) return Boolean is
281 -----------------------
282 -- Alignment_In_Bits --
283 -----------------------
285 function Alignment_In_Bits (E : Entity_Id) return Uint is
287 return Alignment (E) * System_Storage_Unit;
288 end Alignment_In_Bits;
290 -----------------------------------------
291 -- Apply_Compile_Time_Constraint_Error --
292 -----------------------------------------
294 procedure Apply_Compile_Time_Constraint_Error
297 Reason : RT_Exception_Code;
298 Ent : Entity_Id := Empty;
299 Typ : Entity_Id := Empty;
300 Loc : Source_Ptr := No_Location;
301 Rep : Boolean := True;
302 Warn : Boolean := False)
304 Stat : constant Boolean := Is_Static_Expression (N);
305 R_Stat : constant Node_Id :=
306 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
317 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
323 -- Now we replace the node by an N_Raise_Constraint_Error node
324 -- This does not need reanalyzing, so set it as analyzed now.
327 Set_Analyzed (N, True);
330 Set_Raises_Constraint_Error (N);
332 -- Now deal with possible local raise handling
334 Possible_Local_Raise (N, Standard_Constraint_Error);
336 -- If the original expression was marked as static, the result is
337 -- still marked as static, but the Raises_Constraint_Error flag is
338 -- always set so that further static evaluation is not attempted.
341 Set_Is_Static_Expression (N);
343 end Apply_Compile_Time_Constraint_Error;
345 --------------------------------
346 -- Bad_Predicated_Subtype_Use --
347 --------------------------------
349 procedure Bad_Predicated_Subtype_Use
355 if Has_Predicates (Typ) then
356 if Is_Generic_Actual_Type (Typ) then
357 Error_Msg_FE (Msg & '?', N, Typ);
358 Error_Msg_F ("\Program_Error will be raised at run time?", N);
360 Make_Raise_Program_Error (Sloc (N),
361 Reason => PE_Bad_Predicated_Generic_Type));
364 Error_Msg_FE (Msg, N, Typ);
367 end Bad_Predicated_Subtype_Use;
369 --------------------------
370 -- Build_Actual_Subtype --
371 --------------------------
373 function Build_Actual_Subtype
375 N : Node_Or_Entity_Id) return Node_Id
378 -- Normally Sloc (N), but may point to corresponding body in some cases
380 Constraints : List_Id;
386 Disc_Type : Entity_Id;
392 if Nkind (N) = N_Defining_Identifier then
393 Obj := New_Reference_To (N, Loc);
395 -- If this is a formal parameter of a subprogram declaration, and
396 -- we are compiling the body, we want the declaration for the
397 -- actual subtype to carry the source position of the body, to
398 -- prevent anomalies in gdb when stepping through the code.
400 if Is_Formal (N) then
402 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
404 if Nkind (Decl) = N_Subprogram_Declaration
405 and then Present (Corresponding_Body (Decl))
407 Loc := Sloc (Corresponding_Body (Decl));
416 if Is_Array_Type (T) then
417 Constraints := New_List;
418 for J in 1 .. Number_Dimensions (T) loop
420 -- Build an array subtype declaration with the nominal subtype and
421 -- the bounds of the actual. Add the declaration in front of the
422 -- local declarations for the subprogram, for analysis before any
423 -- reference to the formal in the body.
426 Make_Attribute_Reference (Loc,
428 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
429 Attribute_Name => Name_First,
430 Expressions => New_List (
431 Make_Integer_Literal (Loc, J)));
434 Make_Attribute_Reference (Loc,
436 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
437 Attribute_Name => Name_Last,
438 Expressions => New_List (
439 Make_Integer_Literal (Loc, J)));
441 Append (Make_Range (Loc, Lo, Hi), Constraints);
444 -- If the type has unknown discriminants there is no constrained
445 -- subtype to build. This is never called for a formal or for a
446 -- lhs, so returning the type is ok ???
448 elsif Has_Unknown_Discriminants (T) then
452 Constraints := New_List;
454 -- Type T is a generic derived type, inherit the discriminants from
457 if Is_Private_Type (T)
458 and then No (Full_View (T))
460 -- T was flagged as an error if it was declared as a formal
461 -- derived type with known discriminants. In this case there
462 -- is no need to look at the parent type since T already carries
463 -- its own discriminants.
465 and then not Error_Posted (T)
467 Disc_Type := Etype (Base_Type (T));
472 Discr := First_Discriminant (Disc_Type);
473 while Present (Discr) loop
474 Append_To (Constraints,
475 Make_Selected_Component (Loc,
477 Duplicate_Subexpr_No_Checks (Obj),
478 Selector_Name => New_Occurrence_Of (Discr, Loc)));
479 Next_Discriminant (Discr);
483 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
484 Set_Is_Internal (Subt);
487 Make_Subtype_Declaration (Loc,
488 Defining_Identifier => Subt,
489 Subtype_Indication =>
490 Make_Subtype_Indication (Loc,
491 Subtype_Mark => New_Reference_To (T, Loc),
493 Make_Index_Or_Discriminant_Constraint (Loc,
494 Constraints => Constraints)));
496 Mark_Rewrite_Insertion (Decl);
498 end Build_Actual_Subtype;
500 ---------------------------------------
501 -- Build_Actual_Subtype_Of_Component --
502 ---------------------------------------
504 function Build_Actual_Subtype_Of_Component
506 N : Node_Id) return Node_Id
508 Loc : constant Source_Ptr := Sloc (N);
509 P : constant Node_Id := Prefix (N);
512 Index_Typ : Entity_Id;
514 Desig_Typ : Entity_Id;
515 -- This is either a copy of T, or if T is an access type, then it is
516 -- the directly designated type of this access type.
518 function Build_Actual_Array_Constraint return List_Id;
519 -- If one or more of the bounds of the component depends on
520 -- discriminants, build actual constraint using the discriminants
523 function Build_Actual_Record_Constraint return List_Id;
524 -- Similar to previous one, for discriminated components constrained
525 -- by the discriminant of the enclosing object.
527 -----------------------------------
528 -- Build_Actual_Array_Constraint --
529 -----------------------------------
531 function Build_Actual_Array_Constraint return List_Id is
532 Constraints : constant List_Id := New_List;
540 Indx := First_Index (Desig_Typ);
541 while Present (Indx) loop
542 Old_Lo := Type_Low_Bound (Etype (Indx));
543 Old_Hi := Type_High_Bound (Etype (Indx));
545 if Denotes_Discriminant (Old_Lo) then
547 Make_Selected_Component (Loc,
548 Prefix => New_Copy_Tree (P),
549 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
552 Lo := New_Copy_Tree (Old_Lo);
554 -- The new bound will be reanalyzed in the enclosing
555 -- declaration. For literal bounds that come from a type
556 -- declaration, the type of the context must be imposed, so
557 -- insure that analysis will take place. For non-universal
558 -- types this is not strictly necessary.
560 Set_Analyzed (Lo, False);
563 if Denotes_Discriminant (Old_Hi) then
565 Make_Selected_Component (Loc,
566 Prefix => New_Copy_Tree (P),
567 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
570 Hi := New_Copy_Tree (Old_Hi);
571 Set_Analyzed (Hi, False);
574 Append (Make_Range (Loc, Lo, Hi), Constraints);
579 end Build_Actual_Array_Constraint;
581 ------------------------------------
582 -- Build_Actual_Record_Constraint --
583 ------------------------------------
585 function Build_Actual_Record_Constraint return List_Id is
586 Constraints : constant List_Id := New_List;
591 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
592 while Present (D) loop
593 if Denotes_Discriminant (Node (D)) then
594 D_Val := Make_Selected_Component (Loc,
595 Prefix => New_Copy_Tree (P),
596 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
599 D_Val := New_Copy_Tree (Node (D));
602 Append (D_Val, Constraints);
607 end Build_Actual_Record_Constraint;
609 -- Start of processing for Build_Actual_Subtype_Of_Component
612 -- Why the test for Spec_Expression mode here???
614 if In_Spec_Expression then
617 -- More comments for the rest of this body would be good ???
619 elsif Nkind (N) = N_Explicit_Dereference then
620 if Is_Composite_Type (T)
621 and then not Is_Constrained (T)
622 and then not (Is_Class_Wide_Type (T)
623 and then Is_Constrained (Root_Type (T)))
624 and then not Has_Unknown_Discriminants (T)
626 -- If the type of the dereference is already constrained, it is an
629 if Is_Array_Type (Etype (N))
630 and then Is_Constrained (Etype (N))
634 Remove_Side_Effects (P);
635 return Build_Actual_Subtype (T, N);
642 if Ekind (T) = E_Access_Subtype then
643 Desig_Typ := Designated_Type (T);
648 if Ekind (Desig_Typ) = E_Array_Subtype then
649 Id := First_Index (Desig_Typ);
650 while Present (Id) loop
651 Index_Typ := Underlying_Type (Etype (Id));
653 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
655 Denotes_Discriminant (Type_High_Bound (Index_Typ))
657 Remove_Side_Effects (P);
659 Build_Component_Subtype
660 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
666 elsif Is_Composite_Type (Desig_Typ)
667 and then Has_Discriminants (Desig_Typ)
668 and then not Has_Unknown_Discriminants (Desig_Typ)
670 if Is_Private_Type (Desig_Typ)
671 and then No (Discriminant_Constraint (Desig_Typ))
673 Desig_Typ := Full_View (Desig_Typ);
676 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
677 while Present (D) loop
678 if Denotes_Discriminant (Node (D)) then
679 Remove_Side_Effects (P);
681 Build_Component_Subtype (
682 Build_Actual_Record_Constraint, Loc, Base_Type (T));
689 -- If none of the above, the actual and nominal subtypes are the same
692 end Build_Actual_Subtype_Of_Component;
694 -----------------------------
695 -- Build_Component_Subtype --
696 -----------------------------
698 function Build_Component_Subtype
701 T : Entity_Id) return Node_Id
707 -- Unchecked_Union components do not require component subtypes
709 if Is_Unchecked_Union (T) then
713 Subt := Make_Temporary (Loc, 'S');
714 Set_Is_Internal (Subt);
717 Make_Subtype_Declaration (Loc,
718 Defining_Identifier => Subt,
719 Subtype_Indication =>
720 Make_Subtype_Indication (Loc,
721 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
723 Make_Index_Or_Discriminant_Constraint (Loc,
726 Mark_Rewrite_Insertion (Decl);
728 end Build_Component_Subtype;
730 ---------------------------
731 -- Build_Default_Subtype --
732 ---------------------------
734 function Build_Default_Subtype
736 N : Node_Id) return Entity_Id
738 Loc : constant Source_Ptr := Sloc (N);
742 if not Has_Discriminants (T) or else Is_Constrained (T) then
746 Disc := First_Discriminant (T);
748 if No (Discriminant_Default_Value (Disc)) then
753 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
754 Constraints : constant List_Id := New_List;
758 while Present (Disc) loop
759 Append_To (Constraints,
760 New_Copy_Tree (Discriminant_Default_Value (Disc)));
761 Next_Discriminant (Disc);
765 Make_Subtype_Declaration (Loc,
766 Defining_Identifier => Act,
767 Subtype_Indication =>
768 Make_Subtype_Indication (Loc,
769 Subtype_Mark => New_Occurrence_Of (T, Loc),
771 Make_Index_Or_Discriminant_Constraint (Loc,
772 Constraints => Constraints)));
774 Insert_Action (N, Decl);
778 end Build_Default_Subtype;
780 --------------------------------------------
781 -- Build_Discriminal_Subtype_Of_Component --
782 --------------------------------------------
784 function Build_Discriminal_Subtype_Of_Component
785 (T : Entity_Id) return Node_Id
787 Loc : constant Source_Ptr := Sloc (T);
791 function Build_Discriminal_Array_Constraint return List_Id;
792 -- If one or more of the bounds of the component depends on
793 -- discriminants, build actual constraint using the discriminants
796 function Build_Discriminal_Record_Constraint return List_Id;
797 -- Similar to previous one, for discriminated components constrained
798 -- by the discriminant of the enclosing object.
800 ----------------------------------------
801 -- Build_Discriminal_Array_Constraint --
802 ----------------------------------------
804 function Build_Discriminal_Array_Constraint return List_Id is
805 Constraints : constant List_Id := New_List;
813 Indx := First_Index (T);
814 while Present (Indx) loop
815 Old_Lo := Type_Low_Bound (Etype (Indx));
816 Old_Hi := Type_High_Bound (Etype (Indx));
818 if Denotes_Discriminant (Old_Lo) then
819 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
822 Lo := New_Copy_Tree (Old_Lo);
825 if Denotes_Discriminant (Old_Hi) then
826 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
829 Hi := New_Copy_Tree (Old_Hi);
832 Append (Make_Range (Loc, Lo, Hi), Constraints);
837 end Build_Discriminal_Array_Constraint;
839 -----------------------------------------
840 -- Build_Discriminal_Record_Constraint --
841 -----------------------------------------
843 function Build_Discriminal_Record_Constraint return List_Id is
844 Constraints : constant List_Id := New_List;
849 D := First_Elmt (Discriminant_Constraint (T));
850 while Present (D) loop
851 if Denotes_Discriminant (Node (D)) then
853 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
856 D_Val := New_Copy_Tree (Node (D));
859 Append (D_Val, Constraints);
864 end Build_Discriminal_Record_Constraint;
866 -- Start of processing for Build_Discriminal_Subtype_Of_Component
869 if Ekind (T) = E_Array_Subtype then
870 Id := First_Index (T);
871 while Present (Id) loop
872 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
873 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
875 return Build_Component_Subtype
876 (Build_Discriminal_Array_Constraint, Loc, T);
882 elsif Ekind (T) = E_Record_Subtype
883 and then Has_Discriminants (T)
884 and then not Has_Unknown_Discriminants (T)
886 D := First_Elmt (Discriminant_Constraint (T));
887 while Present (D) loop
888 if Denotes_Discriminant (Node (D)) then
889 return Build_Component_Subtype
890 (Build_Discriminal_Record_Constraint, Loc, T);
897 -- If none of the above, the actual and nominal subtypes are the same
900 end Build_Discriminal_Subtype_Of_Component;
902 ------------------------------
903 -- Build_Elaboration_Entity --
904 ------------------------------
906 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
907 Loc : constant Source_Ptr := Sloc (N);
909 Elab_Ent : Entity_Id;
911 procedure Set_Package_Name (Ent : Entity_Id);
912 -- Given an entity, sets the fully qualified name of the entity in
913 -- Name_Buffer, with components separated by double underscores. This
914 -- is a recursive routine that climbs the scope chain to Standard.
916 ----------------------
917 -- Set_Package_Name --
918 ----------------------
920 procedure Set_Package_Name (Ent : Entity_Id) is
922 if Scope (Ent) /= Standard_Standard then
923 Set_Package_Name (Scope (Ent));
926 Nam : constant String := Get_Name_String (Chars (Ent));
928 Name_Buffer (Name_Len + 1) := '_';
929 Name_Buffer (Name_Len + 2) := '_';
930 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
931 Name_Len := Name_Len + Nam'Length + 2;
935 Get_Name_String (Chars (Ent));
937 end Set_Package_Name;
939 -- Start of processing for Build_Elaboration_Entity
942 -- Ignore if already constructed
944 if Present (Elaboration_Entity (Spec_Id)) then
948 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
949 -- name with dots replaced by double underscore. We have to manually
950 -- construct this name, since it will be elaborated in the outer scope,
951 -- and thus will not have the unit name automatically prepended.
953 Set_Package_Name (Spec_Id);
957 Name_Buffer (Name_Len + 1) := '_';
958 Name_Buffer (Name_Len + 2) := 'E';
959 Name_Len := Name_Len + 2;
961 -- Create elaboration counter
963 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
964 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
967 Make_Object_Declaration (Loc,
968 Defining_Identifier => Elab_Ent,
970 New_Occurrence_Of (Standard_Short_Integer, Loc),
971 Expression => Make_Integer_Literal (Loc, Uint_0));
973 Push_Scope (Standard_Standard);
974 Add_Global_Declaration (Decl);
977 -- Reset True_Constant indication, since we will indeed assign a value
978 -- to the variable in the binder main. We also kill the Current_Value
979 -- and Last_Assignment fields for the same reason.
981 Set_Is_True_Constant (Elab_Ent, False);
982 Set_Current_Value (Elab_Ent, Empty);
983 Set_Last_Assignment (Elab_Ent, Empty);
985 -- We do not want any further qualification of the name (if we did
986 -- not do this, we would pick up the name of the generic package
987 -- in the case of a library level generic instantiation).
989 Set_Has_Qualified_Name (Elab_Ent);
990 Set_Has_Fully_Qualified_Name (Elab_Ent);
991 end Build_Elaboration_Entity;
993 -----------------------------------
994 -- Cannot_Raise_Constraint_Error --
995 -----------------------------------
997 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
999 if Compile_Time_Known_Value (Expr) then
1002 elsif Do_Range_Check (Expr) then
1005 elsif Raises_Constraint_Error (Expr) then
1009 case Nkind (Expr) is
1010 when N_Identifier =>
1013 when N_Expanded_Name =>
1016 when N_Selected_Component =>
1017 return not Do_Discriminant_Check (Expr);
1019 when N_Attribute_Reference =>
1020 if Do_Overflow_Check (Expr) then
1023 elsif No (Expressions (Expr)) then
1031 N := First (Expressions (Expr));
1032 while Present (N) loop
1033 if Cannot_Raise_Constraint_Error (N) then
1044 when N_Type_Conversion =>
1045 if Do_Overflow_Check (Expr)
1046 or else Do_Length_Check (Expr)
1047 or else Do_Tag_Check (Expr)
1052 Cannot_Raise_Constraint_Error (Expression (Expr));
1055 when N_Unchecked_Type_Conversion =>
1056 return Cannot_Raise_Constraint_Error (Expression (Expr));
1059 if Do_Overflow_Check (Expr) then
1063 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1070 if Do_Division_Check (Expr)
1071 or else Do_Overflow_Check (Expr)
1076 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1078 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1097 N_Op_Shift_Right_Arithmetic |
1101 if Do_Overflow_Check (Expr) then
1105 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1107 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1114 end Cannot_Raise_Constraint_Error;
1116 ---------------------------------------
1117 -- Check_Later_Vs_Basic_Declarations --
1118 ---------------------------------------
1120 procedure Check_Later_Vs_Basic_Declarations
1122 During_Parsing : Boolean)
1124 Body_Sloc : Source_Ptr;
1127 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1128 -- Return whether Decl is considered as a declarative item.
1129 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1130 -- When During_Parsing is False, the semantics of SPARK is followed.
1132 -------------------------------
1133 -- Is_Later_Declarative_Item --
1134 -------------------------------
1136 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1138 if Nkind (Decl) in N_Later_Decl_Item then
1141 elsif Nkind (Decl) = N_Pragma then
1144 elsif During_Parsing then
1147 -- In SPARK, a package declaration is not considered as a later
1148 -- declarative item.
1150 elsif Nkind (Decl) = N_Package_Declaration then
1153 -- In SPARK, a renaming is considered as a later declarative item
1155 elsif Nkind (Decl) in N_Renaming_Declaration then
1161 end Is_Later_Declarative_Item;
1163 -- Start of Check_Later_Vs_Basic_Declarations
1166 Decl := First (Decls);
1168 -- Loop through sequence of basic declarative items
1170 Outer : while Present (Decl) loop
1171 if Nkind (Decl) /= N_Subprogram_Body
1172 and then Nkind (Decl) /= N_Package_Body
1173 and then Nkind (Decl) /= N_Task_Body
1174 and then Nkind (Decl) not in N_Body_Stub
1178 -- Once a body is encountered, we only allow later declarative
1179 -- items. The inner loop checks the rest of the list.
1182 Body_Sloc := Sloc (Decl);
1184 Inner : while Present (Decl) loop
1185 if not Is_Later_Declarative_Item (Decl) then
1186 if During_Parsing then
1187 if Ada_Version = Ada_83 then
1188 Error_Msg_Sloc := Body_Sloc;
1190 ("(Ada 83) decl cannot appear after body#", Decl);
1193 Error_Msg_Sloc := Body_Sloc;
1194 Check_SPARK_Restriction
1195 ("decl cannot appear after body#", Decl);
1203 end Check_Later_Vs_Basic_Declarations;
1205 -----------------------------------------
1206 -- Check_Dynamically_Tagged_Expression --
1207 -----------------------------------------
1209 procedure Check_Dynamically_Tagged_Expression
1212 Related_Nod : Node_Id)
1215 pragma Assert (Is_Tagged_Type (Typ));
1217 -- In order to avoid spurious errors when analyzing the expanded code,
1218 -- this check is done only for nodes that come from source and for
1219 -- actuals of generic instantiations.
1221 if (Comes_From_Source (Related_Nod)
1222 or else In_Generic_Actual (Expr))
1223 and then (Is_Class_Wide_Type (Etype (Expr))
1224 or else Is_Dynamically_Tagged (Expr))
1225 and then Is_Tagged_Type (Typ)
1226 and then not Is_Class_Wide_Type (Typ)
1228 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1230 end Check_Dynamically_Tagged_Expression;
1232 --------------------------
1233 -- Check_Fully_Declared --
1234 --------------------------
1236 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1238 if Ekind (T) = E_Incomplete_Type then
1240 -- Ada 2005 (AI-50217): If the type is available through a limited
1241 -- with_clause, verify that its full view has been analyzed.
1243 if From_With_Type (T)
1244 and then Present (Non_Limited_View (T))
1245 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1247 -- The non-limited view is fully declared
1252 ("premature usage of incomplete}", N, First_Subtype (T));
1255 -- Need comments for these tests ???
1257 elsif Has_Private_Component (T)
1258 and then not Is_Generic_Type (Root_Type (T))
1259 and then not In_Spec_Expression
1261 -- Special case: if T is the anonymous type created for a single
1262 -- task or protected object, use the name of the source object.
1264 if Is_Concurrent_Type (T)
1265 and then not Comes_From_Source (T)
1266 and then Nkind (N) = N_Object_Declaration
1268 Error_Msg_NE ("type of& has incomplete component", N,
1269 Defining_Identifier (N));
1273 ("premature usage of incomplete}", N, First_Subtype (T));
1276 end Check_Fully_Declared;
1278 -------------------------
1279 -- Check_Nested_Access --
1280 -------------------------
1282 procedure Check_Nested_Access (Ent : Entity_Id) is
1283 Scop : constant Entity_Id := Current_Scope;
1284 Current_Subp : Entity_Id;
1285 Enclosing : Entity_Id;
1288 -- Currently only enabled for VM back-ends for efficiency, should we
1289 -- enable it more systematically ???
1291 -- Check for Is_Imported needs commenting below ???
1293 if VM_Target /= No_VM
1294 and then (Ekind (Ent) = E_Variable
1296 Ekind (Ent) = E_Constant
1298 Ekind (Ent) = E_Loop_Parameter)
1299 and then Scope (Ent) /= Empty
1300 and then not Is_Library_Level_Entity (Ent)
1301 and then not Is_Imported (Ent)
1303 if Is_Subprogram (Scop)
1304 or else Is_Generic_Subprogram (Scop)
1305 or else Is_Entry (Scop)
1307 Current_Subp := Scop;
1309 Current_Subp := Current_Subprogram;
1312 Enclosing := Enclosing_Subprogram (Ent);
1314 if Enclosing /= Empty
1315 and then Enclosing /= Current_Subp
1317 Set_Has_Up_Level_Access (Ent, True);
1320 end Check_Nested_Access;
1322 ----------------------------
1323 -- Check_Order_Dependence --
1324 ----------------------------
1326 procedure Check_Order_Dependence is
1331 if Ada_Version < Ada_2012 then
1335 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1336 -- calls within a construct have been collected. If one of them is
1337 -- writable and overlaps with another one, evaluation of the enclosing
1338 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1339 -- treated as a warning for now.
1341 for J in 1 .. Actuals_In_Call.Last loop
1342 if Actuals_In_Call.Table (J).Is_Writable then
1343 Act1 := Actuals_In_Call.Table (J).Act;
1345 if Nkind (Act1) = N_Attribute_Reference then
1346 Act1 := Prefix (Act1);
1349 for K in 1 .. Actuals_In_Call.Last loop
1351 Act2 := Actuals_In_Call.Table (K).Act;
1353 if Nkind (Act2) = N_Attribute_Reference then
1354 Act2 := Prefix (Act2);
1357 if Actuals_In_Call.Table (K).Is_Writable
1364 elsif Denotes_Same_Object (Act1, Act2)
1365 and then Parent (Act1) /= Parent (Act2)
1368 ("result may differ if evaluated "
1369 & "after other actual in expression?", Act1);
1376 -- Remove checked actuals from table
1378 Actuals_In_Call.Set_Last (0);
1379 end Check_Order_Dependence;
1381 ------------------------------------------
1382 -- Check_Potentially_Blocking_Operation --
1383 ------------------------------------------
1385 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1389 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1390 -- When pragma Detect_Blocking is active, the run time will raise
1391 -- Program_Error. Here we only issue a warning, since we generally
1392 -- support the use of potentially blocking operations in the absence
1395 -- Indirect blocking through a subprogram call cannot be diagnosed
1396 -- statically without interprocedural analysis, so we do not attempt
1399 S := Scope (Current_Scope);
1400 while Present (S) and then S /= Standard_Standard loop
1401 if Is_Protected_Type (S) then
1403 ("potentially blocking operation in protected operation?", N);
1409 end Check_Potentially_Blocking_Operation;
1411 ------------------------------
1412 -- Check_Unprotected_Access --
1413 ------------------------------
1415 procedure Check_Unprotected_Access
1419 Cont_Encl_Typ : Entity_Id;
1420 Pref_Encl_Typ : Entity_Id;
1422 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1423 -- Check whether Obj is a private component of a protected object.
1424 -- Return the protected type where the component resides, Empty
1427 function Is_Public_Operation return Boolean;
1428 -- Verify that the enclosing operation is callable from outside the
1429 -- protected object, to minimize false positives.
1431 ------------------------------
1432 -- Enclosing_Protected_Type --
1433 ------------------------------
1435 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1437 if Is_Entity_Name (Obj) then
1439 Ent : Entity_Id := Entity (Obj);
1442 -- The object can be a renaming of a private component, use
1443 -- the original record component.
1445 if Is_Prival (Ent) then
1446 Ent := Prival_Link (Ent);
1449 if Is_Protected_Type (Scope (Ent)) then
1455 -- For indexed and selected components, recursively check the prefix
1457 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1458 return Enclosing_Protected_Type (Prefix (Obj));
1460 -- The object does not denote a protected component
1465 end Enclosing_Protected_Type;
1467 -------------------------
1468 -- Is_Public_Operation --
1469 -------------------------
1471 function Is_Public_Operation return Boolean is
1478 and then S /= Pref_Encl_Typ
1480 if Scope (S) = Pref_Encl_Typ then
1481 E := First_Entity (Pref_Encl_Typ);
1483 and then E /= First_Private_Entity (Pref_Encl_Typ)
1496 end Is_Public_Operation;
1498 -- Start of processing for Check_Unprotected_Access
1501 if Nkind (Expr) = N_Attribute_Reference
1502 and then Attribute_Name (Expr) = Name_Unchecked_Access
1504 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1505 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1507 -- Check whether we are trying to export a protected component to a
1508 -- context with an equal or lower access level.
1510 if Present (Pref_Encl_Typ)
1511 and then No (Cont_Encl_Typ)
1512 and then Is_Public_Operation
1513 and then Scope_Depth (Pref_Encl_Typ) >=
1514 Object_Access_Level (Context)
1517 ("?possible unprotected access to protected data", Expr);
1520 end Check_Unprotected_Access;
1526 procedure Check_VMS (Construct : Node_Id) is
1528 if not OpenVMS_On_Target then
1530 ("this construct is allowed only in Open'V'M'S", Construct);
1534 ------------------------
1535 -- Collect_Interfaces --
1536 ------------------------
1538 procedure Collect_Interfaces
1540 Ifaces_List : out Elist_Id;
1541 Exclude_Parents : Boolean := False;
1542 Use_Full_View : Boolean := True)
1544 procedure Collect (Typ : Entity_Id);
1545 -- Subsidiary subprogram used to traverse the whole list
1546 -- of directly and indirectly implemented interfaces
1552 procedure Collect (Typ : Entity_Id) is
1553 Ancestor : Entity_Id;
1561 -- Handle private types
1564 and then Is_Private_Type (Typ)
1565 and then Present (Full_View (Typ))
1567 Full_T := Full_View (Typ);
1570 -- Include the ancestor if we are generating the whole list of
1571 -- abstract interfaces.
1573 if Etype (Full_T) /= Typ
1575 -- Protect the frontend against wrong sources. For example:
1578 -- type A is tagged null record;
1579 -- type B is new A with private;
1580 -- type C is new A with private;
1582 -- type B is new C with null record;
1583 -- type C is new B with null record;
1586 and then Etype (Full_T) /= T
1588 Ancestor := Etype (Full_T);
1591 if Is_Interface (Ancestor)
1592 and then not Exclude_Parents
1594 Append_Unique_Elmt (Ancestor, Ifaces_List);
1598 -- Traverse the graph of ancestor interfaces
1600 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1601 Id := First (Abstract_Interface_List (Full_T));
1602 while Present (Id) loop
1603 Iface := Etype (Id);
1605 -- Protect against wrong uses. For example:
1606 -- type I is interface;
1607 -- type O is tagged null record;
1608 -- type Wrong is new I and O with null record; -- ERROR
1610 if Is_Interface (Iface) then
1612 and then Etype (T) /= T
1613 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1618 Append_Unique_Elmt (Iface, Ifaces_List);
1627 -- Start of processing for Collect_Interfaces
1630 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1631 Ifaces_List := New_Elmt_List;
1633 end Collect_Interfaces;
1635 ----------------------------------
1636 -- Collect_Interface_Components --
1637 ----------------------------------
1639 procedure Collect_Interface_Components
1640 (Tagged_Type : Entity_Id;
1641 Components_List : out Elist_Id)
1643 procedure Collect (Typ : Entity_Id);
1644 -- Subsidiary subprogram used to climb to the parents
1650 procedure Collect (Typ : Entity_Id) is
1651 Tag_Comp : Entity_Id;
1652 Parent_Typ : Entity_Id;
1655 -- Handle private types
1657 if Present (Full_View (Etype (Typ))) then
1658 Parent_Typ := Full_View (Etype (Typ));
1660 Parent_Typ := Etype (Typ);
1663 if Parent_Typ /= Typ
1665 -- Protect the frontend against wrong sources. For example:
1668 -- type A is tagged null record;
1669 -- type B is new A with private;
1670 -- type C is new A with private;
1672 -- type B is new C with null record;
1673 -- type C is new B with null record;
1676 and then Parent_Typ /= Tagged_Type
1678 Collect (Parent_Typ);
1681 -- Collect the components containing tags of secondary dispatch
1684 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1685 while Present (Tag_Comp) loop
1686 pragma Assert (Present (Related_Type (Tag_Comp)));
1687 Append_Elmt (Tag_Comp, Components_List);
1689 Tag_Comp := Next_Tag_Component (Tag_Comp);
1693 -- Start of processing for Collect_Interface_Components
1696 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1697 and then Is_Tagged_Type (Tagged_Type));
1699 Components_List := New_Elmt_List;
1700 Collect (Tagged_Type);
1701 end Collect_Interface_Components;
1703 -----------------------------
1704 -- Collect_Interfaces_Info --
1705 -----------------------------
1707 procedure Collect_Interfaces_Info
1709 Ifaces_List : out Elist_Id;
1710 Components_List : out Elist_Id;
1711 Tags_List : out Elist_Id)
1713 Comps_List : Elist_Id;
1714 Comp_Elmt : Elmt_Id;
1715 Comp_Iface : Entity_Id;
1716 Iface_Elmt : Elmt_Id;
1719 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1720 -- Search for the secondary tag associated with the interface type
1721 -- Iface that is implemented by T.
1727 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1730 if not Is_CPP_Class (T) then
1731 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1733 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1737 and then Is_Tag (Node (ADT))
1738 and then Related_Type (Node (ADT)) /= Iface
1740 -- Skip secondary dispatch table referencing thunks to user
1741 -- defined primitives covered by this interface.
1743 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1746 -- Skip secondary dispatch tables of Ada types
1748 if not Is_CPP_Class (T) then
1750 -- Skip secondary dispatch table referencing thunks to
1751 -- predefined primitives.
1753 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1756 -- Skip secondary dispatch table referencing user-defined
1757 -- primitives covered by this interface.
1759 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1762 -- Skip secondary dispatch table referencing predefined
1765 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1770 pragma Assert (Is_Tag (Node (ADT)));
1774 -- Start of processing for Collect_Interfaces_Info
1777 Collect_Interfaces (T, Ifaces_List);
1778 Collect_Interface_Components (T, Comps_List);
1780 -- Search for the record component and tag associated with each
1781 -- interface type of T.
1783 Components_List := New_Elmt_List;
1784 Tags_List := New_Elmt_List;
1786 Iface_Elmt := First_Elmt (Ifaces_List);
1787 while Present (Iface_Elmt) loop
1788 Iface := Node (Iface_Elmt);
1790 -- Associate the primary tag component and the primary dispatch table
1791 -- with all the interfaces that are parents of T
1793 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1794 Append_Elmt (First_Tag_Component (T), Components_List);
1795 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1797 -- Otherwise search for the tag component and secondary dispatch
1801 Comp_Elmt := First_Elmt (Comps_List);
1802 while Present (Comp_Elmt) loop
1803 Comp_Iface := Related_Type (Node (Comp_Elmt));
1805 if Comp_Iface = Iface
1806 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1808 Append_Elmt (Node (Comp_Elmt), Components_List);
1809 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1813 Next_Elmt (Comp_Elmt);
1815 pragma Assert (Present (Comp_Elmt));
1818 Next_Elmt (Iface_Elmt);
1820 end Collect_Interfaces_Info;
1822 ---------------------
1823 -- Collect_Parents --
1824 ---------------------
1826 procedure Collect_Parents
1828 List : out Elist_Id;
1829 Use_Full_View : Boolean := True)
1831 Current_Typ : Entity_Id := T;
1832 Parent_Typ : Entity_Id;
1835 List := New_Elmt_List;
1837 -- No action if the if the type has no parents
1839 if T = Etype (T) then
1844 Parent_Typ := Etype (Current_Typ);
1846 if Is_Private_Type (Parent_Typ)
1847 and then Present (Full_View (Parent_Typ))
1848 and then Use_Full_View
1850 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1853 Append_Elmt (Parent_Typ, List);
1855 exit when Parent_Typ = Current_Typ;
1856 Current_Typ := Parent_Typ;
1858 end Collect_Parents;
1860 ----------------------------------
1861 -- Collect_Primitive_Operations --
1862 ----------------------------------
1864 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1865 B_Type : constant Entity_Id := Base_Type (T);
1866 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1867 B_Scope : Entity_Id := Scope (B_Type);
1871 Formal_Derived : Boolean := False;
1874 function Match (E : Entity_Id) return Boolean;
1875 -- True if E's base type is B_Type, or E is of an anonymous access type
1876 -- and the base type of its designated type is B_Type.
1882 function Match (E : Entity_Id) return Boolean is
1883 Etyp : Entity_Id := Etype (E);
1886 if Ekind (Etyp) = E_Anonymous_Access_Type then
1887 Etyp := Designated_Type (Etyp);
1890 return Base_Type (Etyp) = B_Type;
1893 -- Start of processing for Collect_Primitive_Operations
1896 -- For tagged types, the primitive operations are collected as they
1897 -- are declared, and held in an explicit list which is simply returned.
1899 if Is_Tagged_Type (B_Type) then
1900 return Primitive_Operations (B_Type);
1902 -- An untagged generic type that is a derived type inherits the
1903 -- primitive operations of its parent type. Other formal types only
1904 -- have predefined operators, which are not explicitly represented.
1906 elsif Is_Generic_Type (B_Type) then
1907 if Nkind (B_Decl) = N_Formal_Type_Declaration
1908 and then Nkind (Formal_Type_Definition (B_Decl))
1909 = N_Formal_Derived_Type_Definition
1911 Formal_Derived := True;
1913 return New_Elmt_List;
1917 Op_List := New_Elmt_List;
1919 if B_Scope = Standard_Standard then
1920 if B_Type = Standard_String then
1921 Append_Elmt (Standard_Op_Concat, Op_List);
1923 elsif B_Type = Standard_Wide_String then
1924 Append_Elmt (Standard_Op_Concatw, Op_List);
1930 elsif (Is_Package_Or_Generic_Package (B_Scope)
1932 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1934 or else Is_Derived_Type (B_Type)
1936 -- The primitive operations appear after the base type, except
1937 -- if the derivation happens within the private part of B_Scope
1938 -- and the type is a private type, in which case both the type
1939 -- and some primitive operations may appear before the base
1940 -- type, and the list of candidates starts after the type.
1942 if In_Open_Scopes (B_Scope)
1943 and then Scope (T) = B_Scope
1944 and then In_Private_Part (B_Scope)
1946 Id := Next_Entity (T);
1948 Id := Next_Entity (B_Type);
1951 while Present (Id) loop
1953 -- Note that generic formal subprograms are not
1954 -- considered to be primitive operations and thus
1955 -- are never inherited.
1957 if Is_Overloadable (Id)
1958 and then Nkind (Parent (Parent (Id)))
1959 not in N_Formal_Subprogram_Declaration
1967 Formal := First_Formal (Id);
1968 while Present (Formal) loop
1969 if Match (Formal) then
1974 Next_Formal (Formal);
1978 -- For a formal derived type, the only primitives are the
1979 -- ones inherited from the parent type. Operations appearing
1980 -- in the package declaration are not primitive for it.
1983 and then (not Formal_Derived
1984 or else Present (Alias (Id)))
1986 -- In the special case of an equality operator aliased to
1987 -- an overriding dispatching equality belonging to the same
1988 -- type, we don't include it in the list of primitives.
1989 -- This avoids inheriting multiple equality operators when
1990 -- deriving from untagged private types whose full type is
1991 -- tagged, which can otherwise cause ambiguities. Note that
1992 -- this should only happen for this kind of untagged parent
1993 -- type, since normally dispatching operations are inherited
1994 -- using the type's Primitive_Operations list.
1996 if Chars (Id) = Name_Op_Eq
1997 and then Is_Dispatching_Operation (Id)
1998 and then Present (Alias (Id))
1999 and then Present (Overridden_Operation (Alias (Id)))
2000 and then Base_Type (Etype (First_Entity (Id))) =
2001 Base_Type (Etype (First_Entity (Alias (Id))))
2005 -- Include the subprogram in the list of primitives
2008 Append_Elmt (Id, Op_List);
2015 -- For a type declared in System, some of its operations may
2016 -- appear in the target-specific extension to System.
2019 and then B_Scope = RTU_Entity (System)
2020 and then Present_System_Aux
2022 B_Scope := System_Aux_Id;
2023 Id := First_Entity (System_Aux_Id);
2029 end Collect_Primitive_Operations;
2031 -----------------------------------
2032 -- Compile_Time_Constraint_Error --
2033 -----------------------------------
2035 function Compile_Time_Constraint_Error
2038 Ent : Entity_Id := Empty;
2039 Loc : Source_Ptr := No_Location;
2040 Warn : Boolean := False) return Node_Id
2042 Msgc : String (1 .. Msg'Length + 2);
2043 -- Copy of message, with room for possible ? and ! at end
2053 -- A static constraint error in an instance body is not a fatal error.
2054 -- we choose to inhibit the message altogether, because there is no
2055 -- obvious node (for now) on which to post it. On the other hand the
2056 -- offending node must be replaced with a constraint_error in any case.
2058 -- No messages are generated if we already posted an error on this node
2060 if not Error_Posted (N) then
2061 if Loc /= No_Location then
2067 Msgc (1 .. Msg'Length) := Msg;
2070 -- Message is a warning, even in Ada 95 case
2072 if Msg (Msg'Last) = '?' then
2075 -- In Ada 83, all messages are warnings. In the private part and
2076 -- the body of an instance, constraint_checks are only warnings.
2077 -- We also make this a warning if the Warn parameter is set.
2080 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2086 elsif In_Instance_Not_Visible then
2091 -- Otherwise we have a real error message (Ada 95 static case)
2092 -- and we make this an unconditional message. Note that in the
2093 -- warning case we do not make the message unconditional, it seems
2094 -- quite reasonable to delete messages like this (about exceptions
2095 -- that will be raised) in dead code.
2103 -- Should we generate a warning? The answer is not quite yes. The
2104 -- very annoying exception occurs in the case of a short circuit
2105 -- operator where the left operand is static and decisive. Climb
2106 -- parents to see if that is the case we have here. Conditional
2107 -- expressions with decisive conditions are a similar situation.
2115 -- And then with False as left operand
2117 if Nkind (P) = N_And_Then
2118 and then Compile_Time_Known_Value (Left_Opnd (P))
2119 and then Is_False (Expr_Value (Left_Opnd (P)))
2124 -- OR ELSE with True as left operand
2126 elsif Nkind (P) = N_Or_Else
2127 and then Compile_Time_Known_Value (Left_Opnd (P))
2128 and then Is_True (Expr_Value (Left_Opnd (P)))
2133 -- Conditional expression
2135 elsif Nkind (P) = N_Conditional_Expression then
2137 Cond : constant Node_Id := First (Expressions (P));
2138 Texp : constant Node_Id := Next (Cond);
2139 Fexp : constant Node_Id := Next (Texp);
2142 if Compile_Time_Known_Value (Cond) then
2144 -- Condition is True and we are in the right operand
2146 if Is_True (Expr_Value (Cond))
2147 and then OldP = Fexp
2152 -- Condition is False and we are in the left operand
2154 elsif Is_False (Expr_Value (Cond))
2155 and then OldP = Texp
2163 -- Special case for component association in aggregates, where
2164 -- we want to keep climbing up to the parent aggregate.
2166 elsif Nkind (P) = N_Component_Association
2167 and then Nkind (Parent (P)) = N_Aggregate
2171 -- Keep going if within subexpression
2174 exit when Nkind (P) not in N_Subexpr;
2179 if Present (Ent) then
2180 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2182 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2186 if Inside_Init_Proc then
2188 ("\?& will be raised for objects of this type",
2189 N, Standard_Constraint_Error, Eloc);
2192 ("\?& will be raised at run time",
2193 N, Standard_Constraint_Error, Eloc);
2198 ("\static expression fails Constraint_Check", Eloc);
2199 Set_Error_Posted (N);
2205 end Compile_Time_Constraint_Error;
2207 -----------------------
2208 -- Conditional_Delay --
2209 -----------------------
2211 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2213 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2214 Set_Has_Delayed_Freeze (New_Ent);
2216 end Conditional_Delay;
2218 -------------------------
2219 -- Copy_Parameter_List --
2220 -------------------------
2222 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2223 Loc : constant Source_Ptr := Sloc (Subp_Id);
2228 if No (First_Formal (Subp_Id)) then
2232 Formal := First_Formal (Subp_Id);
2233 while Present (Formal) loop
2235 (Make_Parameter_Specification (Loc,
2236 Defining_Identifier =>
2237 Make_Defining_Identifier (Sloc (Formal),
2238 Chars => Chars (Formal)),
2239 In_Present => In_Present (Parent (Formal)),
2240 Out_Present => Out_Present (Parent (Formal)),
2242 New_Reference_To (Etype (Formal), Loc),
2244 New_Copy_Tree (Expression (Parent (Formal)))),
2247 Next_Formal (Formal);
2252 end Copy_Parameter_List;
2254 --------------------
2255 -- Current_Entity --
2256 --------------------
2258 -- The currently visible definition for a given identifier is the
2259 -- one most chained at the start of the visibility chain, i.e. the
2260 -- one that is referenced by the Node_Id value of the name of the
2261 -- given identifier.
2263 function Current_Entity (N : Node_Id) return Entity_Id is
2265 return Get_Name_Entity_Id (Chars (N));
2268 -----------------------------
2269 -- Current_Entity_In_Scope --
2270 -----------------------------
2272 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2274 CS : constant Entity_Id := Current_Scope;
2276 Transient_Case : constant Boolean := Scope_Is_Transient;
2279 E := Get_Name_Entity_Id (Chars (N));
2281 and then Scope (E) /= CS
2282 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2288 end Current_Entity_In_Scope;
2294 function Current_Scope return Entity_Id is
2296 if Scope_Stack.Last = -1 then
2297 return Standard_Standard;
2300 C : constant Entity_Id :=
2301 Scope_Stack.Table (Scope_Stack.Last).Entity;
2306 return Standard_Standard;
2312 ------------------------
2313 -- Current_Subprogram --
2314 ------------------------
2316 function Current_Subprogram return Entity_Id is
2317 Scop : constant Entity_Id := Current_Scope;
2319 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2322 return Enclosing_Subprogram (Scop);
2324 end Current_Subprogram;
2326 ------------------------------
2327 -- Mark_Non_ALFA_Subprogram --
2328 ------------------------------
2330 procedure Mark_Non_ALFA_Subprogram (Msg : String; N : Node_Id) is
2332 -- Isolate marking of the current subprogram body so that the body of
2333 -- Mark_Non_ALFA_Subprogram is small and inlined.
2336 Mark_Non_ALFA_Subprogram_Unconditional (Msg, N);
2338 end Mark_Non_ALFA_Subprogram;
2340 --------------------------------------------
2341 -- Mark_Non_ALFA_Subprogram_Unconditional --
2342 --------------------------------------------
2344 procedure Mark_Non_ALFA_Subprogram_Unconditional
2348 Cur_Subp : constant Entity_Id := Current_Subprogram;
2351 if Present (Cur_Subp)
2352 and then (Is_Subprogram (Cur_Subp)
2353 or else Is_Generic_Subprogram (Cur_Subp))
2355 -- If the subprogram has been annotated with Formal_Proof being On,
2356 -- then an error must be issued to notify the user that this
2357 -- subprogram unexpectedly falls outside the ALFA subset.
2359 if Formal_Proof_On (Cur_Subp) then
2360 Error_Msg_F (Msg, N);
2363 -- If the non-ALFA construct is in a precondition or postcondition,
2364 -- then mark the subprogram as not in ALFA, because neither the
2365 -- subprogram nor its callers can be proved formally.
2367 -- If the non-ALFA construct is in a regular piece of code inside the
2368 -- body of the subprogram, then mark the subprogram body as not in
2369 -- ALFA, because the subprogram cannot be proved formally, but its
2372 if In_Pre_Post_Expression then
2373 Set_Is_In_ALFA (Cur_Subp, False);
2375 Set_Body_Is_In_ALFA (Cur_Subp, False);
2378 end Mark_Non_ALFA_Subprogram_Unconditional;
2380 ---------------------
2381 -- Defining_Entity --
2382 ---------------------
2384 function Defining_Entity (N : Node_Id) return Entity_Id is
2385 K : constant Node_Kind := Nkind (N);
2386 Err : Entity_Id := Empty;
2391 N_Subprogram_Declaration |
2392 N_Abstract_Subprogram_Declaration |
2394 N_Package_Declaration |
2395 N_Subprogram_Renaming_Declaration |
2396 N_Subprogram_Body_Stub |
2397 N_Generic_Subprogram_Declaration |
2398 N_Generic_Package_Declaration |
2399 N_Formal_Subprogram_Declaration
2401 return Defining_Entity (Specification (N));
2404 N_Component_Declaration |
2405 N_Defining_Program_Unit_Name |
2406 N_Discriminant_Specification |
2408 N_Entry_Declaration |
2409 N_Entry_Index_Specification |
2410 N_Exception_Declaration |
2411 N_Exception_Renaming_Declaration |
2412 N_Formal_Object_Declaration |
2413 N_Formal_Package_Declaration |
2414 N_Formal_Type_Declaration |
2415 N_Full_Type_Declaration |
2416 N_Implicit_Label_Declaration |
2417 N_Incomplete_Type_Declaration |
2418 N_Loop_Parameter_Specification |
2419 N_Number_Declaration |
2420 N_Object_Declaration |
2421 N_Object_Renaming_Declaration |
2422 N_Package_Body_Stub |
2423 N_Parameter_Specification |
2424 N_Private_Extension_Declaration |
2425 N_Private_Type_Declaration |
2427 N_Protected_Body_Stub |
2428 N_Protected_Type_Declaration |
2429 N_Single_Protected_Declaration |
2430 N_Single_Task_Declaration |
2431 N_Subtype_Declaration |
2434 N_Task_Type_Declaration
2436 return Defining_Identifier (N);
2439 return Defining_Entity (Proper_Body (N));
2442 N_Function_Instantiation |
2443 N_Function_Specification |
2444 N_Generic_Function_Renaming_Declaration |
2445 N_Generic_Package_Renaming_Declaration |
2446 N_Generic_Procedure_Renaming_Declaration |
2448 N_Package_Instantiation |
2449 N_Package_Renaming_Declaration |
2450 N_Package_Specification |
2451 N_Procedure_Instantiation |
2452 N_Procedure_Specification
2455 Nam : constant Node_Id := Defining_Unit_Name (N);
2458 if Nkind (Nam) in N_Entity then
2461 -- For Error, make up a name and attach to declaration
2462 -- so we can continue semantic analysis
2464 elsif Nam = Error then
2465 Err := Make_Temporary (Sloc (N), 'T');
2466 Set_Defining_Unit_Name (N, Err);
2469 -- If not an entity, get defining identifier
2472 return Defining_Identifier (Nam);
2476 when N_Block_Statement =>
2477 return Entity (Identifier (N));
2480 raise Program_Error;
2483 end Defining_Entity;
2485 --------------------------
2486 -- Denotes_Discriminant --
2487 --------------------------
2489 function Denotes_Discriminant
2491 Check_Concurrent : Boolean := False) return Boolean
2495 if not Is_Entity_Name (N)
2496 or else No (Entity (N))
2503 -- If we are checking for a protected type, the discriminant may have
2504 -- been rewritten as the corresponding discriminal of the original type
2505 -- or of the corresponding concurrent record, depending on whether we
2506 -- are in the spec or body of the protected type.
2508 return Ekind (E) = E_Discriminant
2511 and then Ekind (E) = E_In_Parameter
2512 and then Present (Discriminal_Link (E))
2514 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2516 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2518 end Denotes_Discriminant;
2520 -------------------------
2521 -- Denotes_Same_Object --
2522 -------------------------
2524 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2525 Obj1 : Node_Id := A1;
2526 Obj2 : Node_Id := A2;
2528 procedure Check_Renaming (Obj : in out Node_Id);
2529 -- If an object is a renaming, examine renamed object. If it is a
2530 -- dereference of a variable, or an indexed expression with non-constant
2531 -- indexes, no overlap check can be reported.
2533 --------------------
2534 -- Check_Renaming --
2535 --------------------
2537 procedure Check_Renaming (Obj : in out Node_Id) is
2539 if Is_Entity_Name (Obj)
2540 and then Present (Renamed_Entity (Entity (Obj)))
2542 Obj := Renamed_Entity (Entity (Obj));
2543 if Nkind (Obj) = N_Explicit_Dereference
2544 and then Is_Variable (Prefix (Obj))
2548 elsif Nkind (Obj) = N_Indexed_Component then
2553 Indx := First (Expressions (Obj));
2554 while Present (Indx) loop
2555 if not Is_OK_Static_Expression (Indx) then
2567 -- Start of processing for Denotes_Same_Object
2570 Check_Renaming (Obj1);
2571 Check_Renaming (Obj2);
2579 -- If we have entity names, then must be same entity
2581 if Is_Entity_Name (Obj1) then
2582 if Is_Entity_Name (Obj2) then
2583 return Entity (Obj1) = Entity (Obj2);
2588 -- No match if not same node kind
2590 elsif Nkind (Obj1) /= Nkind (Obj2) then
2593 -- For selected components, must have same prefix and selector
2595 elsif Nkind (Obj1) = N_Selected_Component then
2596 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2598 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2600 -- For explicit dereferences, prefixes must be same
2602 elsif Nkind (Obj1) = N_Explicit_Dereference then
2603 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2605 -- For indexed components, prefixes and all subscripts must be the same
2607 elsif Nkind (Obj1) = N_Indexed_Component then
2608 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2614 Indx1 := First (Expressions (Obj1));
2615 Indx2 := First (Expressions (Obj2));
2616 while Present (Indx1) loop
2618 -- Indexes must denote the same static value or same object
2620 if Is_OK_Static_Expression (Indx1) then
2621 if not Is_OK_Static_Expression (Indx2) then
2624 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2628 elsif not Denotes_Same_Object (Indx1, Indx2) then
2642 -- For slices, prefixes must match and bounds must match
2644 elsif Nkind (Obj1) = N_Slice
2645 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2648 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2651 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2652 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2654 -- Check whether bounds are statically identical. There is no
2655 -- attempt to detect partial overlap of slices.
2657 return Denotes_Same_Object (Lo1, Lo2)
2658 and then Denotes_Same_Object (Hi1, Hi2);
2661 -- Literals will appear as indexes. Isn't this where we should check
2662 -- Known_At_Compile_Time at least if we are generating warnings ???
2664 elsif Nkind (Obj1) = N_Integer_Literal then
2665 return Intval (Obj1) = Intval (Obj2);
2670 end Denotes_Same_Object;
2672 -------------------------
2673 -- Denotes_Same_Prefix --
2674 -------------------------
2676 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2679 if Is_Entity_Name (A1) then
2680 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2681 and then not Is_Access_Type (Etype (A1))
2683 return Denotes_Same_Object (A1, Prefix (A2))
2684 or else Denotes_Same_Prefix (A1, Prefix (A2));
2689 elsif Is_Entity_Name (A2) then
2690 return Denotes_Same_Prefix (A2, A1);
2692 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2694 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2697 Root1, Root2 : Node_Id;
2698 Depth1, Depth2 : Int := 0;
2701 Root1 := Prefix (A1);
2702 while not Is_Entity_Name (Root1) loop
2704 (Root1, N_Selected_Component, N_Indexed_Component)
2708 Root1 := Prefix (Root1);
2711 Depth1 := Depth1 + 1;
2714 Root2 := Prefix (A2);
2715 while not Is_Entity_Name (Root2) loop
2717 (Root2, N_Selected_Component, N_Indexed_Component)
2721 Root2 := Prefix (Root2);
2724 Depth2 := Depth2 + 1;
2727 -- If both have the same depth and they do not denote the same
2728 -- object, they are disjoint and not warning is needed.
2730 if Depth1 = Depth2 then
2733 elsif Depth1 > Depth2 then
2734 Root1 := Prefix (A1);
2735 for I in 1 .. Depth1 - Depth2 - 1 loop
2736 Root1 := Prefix (Root1);
2739 return Denotes_Same_Object (Root1, A2);
2742 Root2 := Prefix (A2);
2743 for I in 1 .. Depth2 - Depth1 - 1 loop
2744 Root2 := Prefix (Root2);
2747 return Denotes_Same_Object (A1, Root2);
2754 end Denotes_Same_Prefix;
2756 ----------------------
2757 -- Denotes_Variable --
2758 ----------------------
2760 function Denotes_Variable (N : Node_Id) return Boolean is
2762 return Is_Variable (N) and then Paren_Count (N) = 0;
2763 end Denotes_Variable;
2765 -----------------------------
2766 -- Depends_On_Discriminant --
2767 -----------------------------
2769 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2774 Get_Index_Bounds (N, L, H);
2775 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2776 end Depends_On_Discriminant;
2778 -------------------------
2779 -- Designate_Same_Unit --
2780 -------------------------
2782 function Designate_Same_Unit
2784 Name2 : Node_Id) return Boolean
2786 K1 : constant Node_Kind := Nkind (Name1);
2787 K2 : constant Node_Kind := Nkind (Name2);
2789 function Prefix_Node (N : Node_Id) return Node_Id;
2790 -- Returns the parent unit name node of a defining program unit name
2791 -- or the prefix if N is a selected component or an expanded name.
2793 function Select_Node (N : Node_Id) return Node_Id;
2794 -- Returns the defining identifier node of a defining program unit
2795 -- name or the selector node if N is a selected component or an
2802 function Prefix_Node (N : Node_Id) return Node_Id is
2804 if Nkind (N) = N_Defining_Program_Unit_Name then
2816 function Select_Node (N : Node_Id) return Node_Id is
2818 if Nkind (N) = N_Defining_Program_Unit_Name then
2819 return Defining_Identifier (N);
2822 return Selector_Name (N);
2826 -- Start of processing for Designate_Next_Unit
2829 if (K1 = N_Identifier or else
2830 K1 = N_Defining_Identifier)
2832 (K2 = N_Identifier or else
2833 K2 = N_Defining_Identifier)
2835 return Chars (Name1) = Chars (Name2);
2838 (K1 = N_Expanded_Name or else
2839 K1 = N_Selected_Component or else
2840 K1 = N_Defining_Program_Unit_Name)
2842 (K2 = N_Expanded_Name or else
2843 K2 = N_Selected_Component or else
2844 K2 = N_Defining_Program_Unit_Name)
2847 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2849 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2854 end Designate_Same_Unit;
2856 --------------------------
2857 -- Enclosing_CPP_Parent --
2858 --------------------------
2860 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2861 Parent_Typ : Entity_Id := Typ;
2864 while not Is_CPP_Class (Parent_Typ)
2865 and then Etype (Parent_Typ) /= Parent_Typ
2867 Parent_Typ := Etype (Parent_Typ);
2869 if Is_Private_Type (Parent_Typ) then
2870 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2874 pragma Assert (Is_CPP_Class (Parent_Typ));
2876 end Enclosing_CPP_Parent;
2878 ----------------------------
2879 -- Enclosing_Generic_Body --
2880 ----------------------------
2882 function Enclosing_Generic_Body
2883 (N : Node_Id) return Node_Id
2891 while Present (P) loop
2892 if Nkind (P) = N_Package_Body
2893 or else Nkind (P) = N_Subprogram_Body
2895 Spec := Corresponding_Spec (P);
2897 if Present (Spec) then
2898 Decl := Unit_Declaration_Node (Spec);
2900 if Nkind (Decl) = N_Generic_Package_Declaration
2901 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2912 end Enclosing_Generic_Body;
2914 ----------------------------
2915 -- Enclosing_Generic_Unit --
2916 ----------------------------
2918 function Enclosing_Generic_Unit
2919 (N : Node_Id) return Node_Id
2927 while Present (P) loop
2928 if Nkind (P) = N_Generic_Package_Declaration
2929 or else Nkind (P) = N_Generic_Subprogram_Declaration
2933 elsif Nkind (P) = N_Package_Body
2934 or else Nkind (P) = N_Subprogram_Body
2936 Spec := Corresponding_Spec (P);
2938 if Present (Spec) then
2939 Decl := Unit_Declaration_Node (Spec);
2941 if Nkind (Decl) = N_Generic_Package_Declaration
2942 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2953 end Enclosing_Generic_Unit;
2955 -------------------------------
2956 -- Enclosing_Lib_Unit_Entity --
2957 -------------------------------
2959 function Enclosing_Lib_Unit_Entity return Entity_Id is
2960 Unit_Entity : Entity_Id;
2963 -- Look for enclosing library unit entity by following scope links.
2964 -- Equivalent to, but faster than indexing through the scope stack.
2966 Unit_Entity := Current_Scope;
2967 while (Present (Scope (Unit_Entity))
2968 and then Scope (Unit_Entity) /= Standard_Standard)
2969 and not Is_Child_Unit (Unit_Entity)
2971 Unit_Entity := Scope (Unit_Entity);
2975 end Enclosing_Lib_Unit_Entity;
2977 -----------------------------
2978 -- Enclosing_Lib_Unit_Node --
2979 -----------------------------
2981 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2982 Current_Node : Node_Id;
2986 while Present (Current_Node)
2987 and then Nkind (Current_Node) /= N_Compilation_Unit
2989 Current_Node := Parent (Current_Node);
2992 if Nkind (Current_Node) /= N_Compilation_Unit then
2996 return Current_Node;
2997 end Enclosing_Lib_Unit_Node;
2999 -----------------------
3000 -- Enclosing_Package --
3001 -----------------------
3003 function Enclosing_Package (E : Entity_Id) return Entity_Id is
3004 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3007 if Dynamic_Scope = Standard_Standard then
3008 return Standard_Standard;
3010 elsif Dynamic_Scope = Empty then
3013 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
3016 return Dynamic_Scope;
3019 return Enclosing_Package (Dynamic_Scope);
3021 end Enclosing_Package;
3023 --------------------------
3024 -- Enclosing_Subprogram --
3025 --------------------------
3027 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3028 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3031 if Dynamic_Scope = Standard_Standard then
3034 elsif Dynamic_Scope = Empty then
3037 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3038 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3040 elsif Ekind (Dynamic_Scope) = E_Block
3041 or else Ekind (Dynamic_Scope) = E_Return_Statement
3043 return Enclosing_Subprogram (Dynamic_Scope);
3045 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3046 return Get_Task_Body_Procedure (Dynamic_Scope);
3048 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3049 and then Present (Full_View (Dynamic_Scope))
3050 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3052 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3054 -- No body is generated if the protected operation is eliminated
3056 elsif Convention (Dynamic_Scope) = Convention_Protected
3057 and then not Is_Eliminated (Dynamic_Scope)
3058 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3060 return Protected_Body_Subprogram (Dynamic_Scope);
3063 return Dynamic_Scope;
3065 end Enclosing_Subprogram;
3067 ------------------------
3068 -- Ensure_Freeze_Node --
3069 ------------------------
3071 procedure Ensure_Freeze_Node (E : Entity_Id) is
3075 if No (Freeze_Node (E)) then
3076 FN := Make_Freeze_Entity (Sloc (E));
3077 Set_Has_Delayed_Freeze (E);
3078 Set_Freeze_Node (E, FN);
3079 Set_Access_Types_To_Process (FN, No_Elist);
3080 Set_TSS_Elist (FN, No_Elist);
3083 end Ensure_Freeze_Node;
3089 procedure Enter_Name (Def_Id : Entity_Id) is
3090 C : constant Entity_Id := Current_Entity (Def_Id);
3091 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3092 S : constant Entity_Id := Current_Scope;
3095 Generate_Definition (Def_Id);
3097 -- Add new name to current scope declarations. Check for duplicate
3098 -- declaration, which may or may not be a genuine error.
3102 -- Case of previous entity entered because of a missing declaration
3103 -- or else a bad subtype indication. Best is to use the new entity,
3104 -- and make the previous one invisible.
3106 if Etype (E) = Any_Type then
3107 Set_Is_Immediately_Visible (E, False);
3109 -- Case of renaming declaration constructed for package instances.
3110 -- if there is an explicit declaration with the same identifier,
3111 -- the renaming is not immediately visible any longer, but remains
3112 -- visible through selected component notation.
3114 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3115 and then not Comes_From_Source (E)
3117 Set_Is_Immediately_Visible (E, False);
3119 -- The new entity may be the package renaming, which has the same
3120 -- same name as a generic formal which has been seen already.
3122 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3123 and then not Comes_From_Source (Def_Id)
3125 Set_Is_Immediately_Visible (E, False);
3127 -- For a fat pointer corresponding to a remote access to subprogram,
3128 -- we use the same identifier as the RAS type, so that the proper
3129 -- name appears in the stub. This type is only retrieved through
3130 -- the RAS type and never by visibility, and is not added to the
3131 -- visibility list (see below).
3133 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3134 and then Present (Corresponding_Remote_Type (Def_Id))
3138 -- Case of an implicit operation or derived literal. The new entity
3139 -- hides the implicit one, which is removed from all visibility,
3140 -- i.e. the entity list of its scope, and homonym chain of its name.
3142 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3143 or else Is_Internal (E)
3147 Prev_Vis : Entity_Id;
3148 Decl : constant Node_Id := Parent (E);
3151 -- If E is an implicit declaration, it cannot be the first
3152 -- entity in the scope.
3154 Prev := First_Entity (Current_Scope);
3155 while Present (Prev)
3156 and then Next_Entity (Prev) /= E
3163 -- If E is not on the entity chain of the current scope,
3164 -- it is an implicit declaration in the generic formal
3165 -- part of a generic subprogram. When analyzing the body,
3166 -- the generic formals are visible but not on the entity
3167 -- chain of the subprogram. The new entity will become
3168 -- the visible one in the body.
3171 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3175 Set_Next_Entity (Prev, Next_Entity (E));
3177 if No (Next_Entity (Prev)) then
3178 Set_Last_Entity (Current_Scope, Prev);
3181 if E = Current_Entity (E) then
3185 Prev_Vis := Current_Entity (E);
3186 while Homonym (Prev_Vis) /= E loop
3187 Prev_Vis := Homonym (Prev_Vis);
3191 if Present (Prev_Vis) then
3193 -- Skip E in the visibility chain
3195 Set_Homonym (Prev_Vis, Homonym (E));
3198 Set_Name_Entity_Id (Chars (E), Homonym (E));
3203 -- This section of code could use a comment ???
3205 elsif Present (Etype (E))
3206 and then Is_Concurrent_Type (Etype (E))
3211 -- If the homograph is a protected component renaming, it should not
3212 -- be hiding the current entity. Such renamings are treated as weak
3215 elsif Is_Prival (E) then
3216 Set_Is_Immediately_Visible (E, False);
3218 -- In this case the current entity is a protected component renaming.
3219 -- Perform minimal decoration by setting the scope and return since
3220 -- the prival should not be hiding other visible entities.
3222 elsif Is_Prival (Def_Id) then
3223 Set_Scope (Def_Id, Current_Scope);
3226 -- Analogous to privals, the discriminal generated for an entry index
3227 -- parameter acts as a weak declaration. Perform minimal decoration
3228 -- to avoid bogus errors.
3230 elsif Is_Discriminal (Def_Id)
3231 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3233 Set_Scope (Def_Id, Current_Scope);
3236 -- In the body or private part of an instance, a type extension may
3237 -- introduce a component with the same name as that of an actual. The
3238 -- legality rule is not enforced, but the semantics of the full type
3239 -- with two components of same name are not clear at this point???
3241 elsif In_Instance_Not_Visible then
3244 -- When compiling a package body, some child units may have become
3245 -- visible. They cannot conflict with local entities that hide them.
3247 elsif Is_Child_Unit (E)
3248 and then In_Open_Scopes (Scope (E))
3249 and then not Is_Immediately_Visible (E)
3253 -- Conversely, with front-end inlining we may compile the parent body
3254 -- first, and a child unit subsequently. The context is now the
3255 -- parent spec, and body entities are not visible.
3257 elsif Is_Child_Unit (Def_Id)
3258 and then Is_Package_Body_Entity (E)
3259 and then not In_Package_Body (Current_Scope)
3263 -- Case of genuine duplicate declaration
3266 Error_Msg_Sloc := Sloc (E);
3268 -- If the previous declaration is an incomplete type declaration
3269 -- this may be an attempt to complete it with a private type. The
3270 -- following avoids confusing cascaded errors.
3272 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3273 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3276 ("incomplete type cannot be completed with a private " &
3277 "declaration", Parent (Def_Id));
3278 Set_Is_Immediately_Visible (E, False);
3279 Set_Full_View (E, Def_Id);
3281 -- An inherited component of a record conflicts with a new
3282 -- discriminant. The discriminant is inserted first in the scope,
3283 -- but the error should be posted on it, not on the component.
3285 elsif Ekind (E) = E_Discriminant
3286 and then Present (Scope (Def_Id))
3287 and then Scope (Def_Id) /= Current_Scope
3289 Error_Msg_Sloc := Sloc (Def_Id);
3290 Error_Msg_N ("& conflicts with declaration#", E);
3293 -- If the name of the unit appears in its own context clause, a
3294 -- dummy package with the name has already been created, and the
3295 -- error emitted. Try to continue quietly.
3297 elsif Error_Posted (E)
3298 and then Sloc (E) = No_Location
3299 and then Nkind (Parent (E)) = N_Package_Specification
3300 and then Current_Scope = Standard_Standard
3302 Set_Scope (Def_Id, Current_Scope);
3306 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3308 -- Avoid cascaded messages with duplicate components in
3311 if Ekind_In (E, E_Component, E_Discriminant) then
3316 if Nkind (Parent (Parent (Def_Id))) =
3317 N_Generic_Subprogram_Declaration
3319 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3321 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3324 -- If entity is in standard, then we are in trouble, because it
3325 -- means that we have a library package with a duplicated name.
3326 -- That's hard to recover from, so abort!
3328 if S = Standard_Standard then
3329 raise Unrecoverable_Error;
3331 -- Otherwise we continue with the declaration. Having two
3332 -- identical declarations should not cause us too much trouble!
3340 -- If we fall through, declaration is OK, at least OK enough to continue
3342 -- If Def_Id is a discriminant or a record component we are in the midst
3343 -- of inheriting components in a derived record definition. Preserve
3344 -- their Ekind and Etype.
3346 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3349 -- If a type is already set, leave it alone (happens when a type
3350 -- declaration is reanalyzed following a call to the optimizer).
3352 elsif Present (Etype (Def_Id)) then
3355 -- Otherwise, the kind E_Void insures that premature uses of the entity
3356 -- will be detected. Any_Type insures that no cascaded errors will occur
3359 Set_Ekind (Def_Id, E_Void);
3360 Set_Etype (Def_Id, Any_Type);
3363 -- Inherited discriminants and components in derived record types are
3364 -- immediately visible. Itypes are not.
3366 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3367 or else (No (Corresponding_Remote_Type (Def_Id))
3368 and then not Is_Itype (Def_Id))
3370 Set_Is_Immediately_Visible (Def_Id);
3371 Set_Current_Entity (Def_Id);
3374 Set_Homonym (Def_Id, C);
3375 Append_Entity (Def_Id, S);
3376 Set_Public_Status (Def_Id);
3378 -- Declaring a homonym is not allowed in SPARK ...
3381 and then Restriction_Check_Required (SPARK)
3385 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3386 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3387 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3390 -- ... unless the new declaration is in a subprogram, and the
3391 -- visible declaration is a variable declaration or a parameter
3392 -- specification outside that subprogram.
3394 if Present (Enclosing_Subp)
3395 and then Nkind_In (Parent (C), N_Object_Declaration,
3396 N_Parameter_Specification)
3397 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3401 -- ... or the new declaration is in a package, and the visible
3402 -- declaration occurs outside that package.
3404 elsif Present (Enclosing_Pack)
3405 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3409 -- ... or the new declaration is a component declaration in a
3410 -- record type definition.
3412 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3415 -- Don't issue error for non-source entities
3417 elsif Comes_From_Source (Def_Id)
3418 and then Comes_From_Source (C)
3420 Error_Msg_Sloc := Sloc (C);
3421 Check_SPARK_Restriction
3422 ("redeclaration of identifier &#", Def_Id);
3427 -- Warn if new entity hides an old one
3429 if Warn_On_Hiding and then Present (C)
3431 -- Don't warn for record components since they always have a well
3432 -- defined scope which does not confuse other uses. Note that in
3433 -- some cases, Ekind has not been set yet.
3435 and then Ekind (C) /= E_Component
3436 and then Ekind (C) /= E_Discriminant
3437 and then Nkind (Parent (C)) /= N_Component_Declaration
3438 and then Ekind (Def_Id) /= E_Component
3439 and then Ekind (Def_Id) /= E_Discriminant
3440 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3442 -- Don't warn for one character variables. It is too common to use
3443 -- such variables as locals and will just cause too many false hits.
3445 and then Length_Of_Name (Chars (C)) /= 1
3447 -- Don't warn for non-source entities
3449 and then Comes_From_Source (C)
3450 and then Comes_From_Source (Def_Id)
3452 -- Don't warn unless entity in question is in extended main source
3454 and then In_Extended_Main_Source_Unit (Def_Id)
3456 -- Finally, the hidden entity must be either immediately visible or
3457 -- use visible (i.e. from a used package).
3460 (Is_Immediately_Visible (C)
3462 Is_Potentially_Use_Visible (C))
3464 Error_Msg_Sloc := Sloc (C);
3465 Error_Msg_N ("declaration hides &#?", Def_Id);
3469 --------------------------
3470 -- Explain_Limited_Type --
3471 --------------------------
3473 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3477 -- For array, component type must be limited
3479 if Is_Array_Type (T) then
3480 Error_Msg_Node_2 := T;
3482 ("\component type& of type& is limited", N, Component_Type (T));
3483 Explain_Limited_Type (Component_Type (T), N);
3485 elsif Is_Record_Type (T) then
3487 -- No need for extra messages if explicit limited record
3489 if Is_Limited_Record (Base_Type (T)) then
3493 -- Otherwise find a limited component. Check only components that
3494 -- come from source, or inherited components that appear in the
3495 -- source of the ancestor.
3497 C := First_Component (T);
3498 while Present (C) loop
3499 if Is_Limited_Type (Etype (C))
3501 (Comes_From_Source (C)
3503 (Present (Original_Record_Component (C))
3505 Comes_From_Source (Original_Record_Component (C))))
3507 Error_Msg_Node_2 := T;
3508 Error_Msg_NE ("\component& of type& has limited type", N, C);
3509 Explain_Limited_Type (Etype (C), N);
3516 -- The type may be declared explicitly limited, even if no component
3517 -- of it is limited, in which case we fall out of the loop.
3520 end Explain_Limited_Type;
3526 procedure Find_Actual
3528 Formal : out Entity_Id;
3531 Parnt : constant Node_Id := Parent (N);
3535 if (Nkind (Parnt) = N_Indexed_Component
3537 Nkind (Parnt) = N_Selected_Component)
3538 and then N = Prefix (Parnt)
3540 Find_Actual (Parnt, Formal, Call);
3543 elsif Nkind (Parnt) = N_Parameter_Association
3544 and then N = Explicit_Actual_Parameter (Parnt)
3546 Call := Parent (Parnt);
3548 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3557 -- If we have a call to a subprogram look for the parameter. Note that
3558 -- we exclude overloaded calls, since we don't know enough to be sure
3559 -- of giving the right answer in this case.
3561 if Is_Entity_Name (Name (Call))
3562 and then Present (Entity (Name (Call)))
3563 and then Is_Overloadable (Entity (Name (Call)))
3564 and then not Is_Overloaded (Name (Call))
3566 -- Fall here if we are definitely a parameter
3568 Actual := First_Actual (Call);
3569 Formal := First_Formal (Entity (Name (Call)));
3570 while Present (Formal) and then Present (Actual) loop
3574 Actual := Next_Actual (Actual);
3575 Formal := Next_Formal (Formal);
3580 -- Fall through here if we did not find matching actual
3586 ---------------------------
3587 -- Find_Body_Discriminal --
3588 ---------------------------
3590 function Find_Body_Discriminal
3591 (Spec_Discriminant : Entity_Id) return Entity_Id
3593 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3595 Tsk : constant Entity_Id :=
3596 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3600 -- Find discriminant of original concurrent type, and use its current
3601 -- discriminal, which is the renaming within the task/protected body.
3603 Disc := First_Discriminant (Tsk);
3604 while Present (Disc) loop
3605 if Chars (Disc) = Chars (Spec_Discriminant) then
3606 return Discriminal (Disc);
3609 Next_Discriminant (Disc);
3612 -- That loop should always succeed in finding a matching entry and
3613 -- returning. Fatal error if not.
3615 raise Program_Error;
3616 end Find_Body_Discriminal;
3618 -------------------------------------
3619 -- Find_Corresponding_Discriminant --
3620 -------------------------------------
3622 function Find_Corresponding_Discriminant
3624 Typ : Entity_Id) return Entity_Id
3626 Par_Disc : Entity_Id;
3627 Old_Disc : Entity_Id;
3628 New_Disc : Entity_Id;
3631 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3633 -- The original type may currently be private, and the discriminant
3634 -- only appear on its full view.
3636 if Is_Private_Type (Scope (Par_Disc))
3637 and then not Has_Discriminants (Scope (Par_Disc))
3638 and then Present (Full_View (Scope (Par_Disc)))
3640 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3642 Old_Disc := First_Discriminant (Scope (Par_Disc));
3645 if Is_Class_Wide_Type (Typ) then
3646 New_Disc := First_Discriminant (Root_Type (Typ));
3648 New_Disc := First_Discriminant (Typ);
3651 while Present (Old_Disc) and then Present (New_Disc) loop
3652 if Old_Disc = Par_Disc then
3655 Next_Discriminant (Old_Disc);
3656 Next_Discriminant (New_Disc);
3660 -- Should always find it
3662 raise Program_Error;
3663 end Find_Corresponding_Discriminant;
3665 --------------------------
3666 -- Find_Overlaid_Entity --
3667 --------------------------
3669 procedure Find_Overlaid_Entity
3671 Ent : out Entity_Id;
3677 -- We are looking for one of the two following forms:
3679 -- for X'Address use Y'Address
3683 -- Const : constant Address := expr;
3685 -- for X'Address use Const;
3687 -- In the second case, the expr is either Y'Address, or recursively a
3688 -- constant that eventually references Y'Address.
3693 if Nkind (N) = N_Attribute_Definition_Clause
3694 and then Chars (N) = Name_Address
3696 Expr := Expression (N);
3698 -- This loop checks the form of the expression for Y'Address,
3699 -- using recursion to deal with intermediate constants.
3702 -- Check for Y'Address
3704 if Nkind (Expr) = N_Attribute_Reference
3705 and then Attribute_Name (Expr) = Name_Address
3707 Expr := Prefix (Expr);
3710 -- Check for Const where Const is a constant entity
3712 elsif Is_Entity_Name (Expr)
3713 and then Ekind (Entity (Expr)) = E_Constant
3715 Expr := Constant_Value (Entity (Expr));
3717 -- Anything else does not need checking
3724 -- This loop checks the form of the prefix for an entity,
3725 -- using recursion to deal with intermediate components.
3728 -- Check for Y where Y is an entity
3730 if Is_Entity_Name (Expr) then
3731 Ent := Entity (Expr);
3734 -- Check for components
3737 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3739 Expr := Prefix (Expr);
3742 -- Anything else does not need checking
3749 end Find_Overlaid_Entity;
3751 -------------------------
3752 -- Find_Parameter_Type --
3753 -------------------------
3755 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3757 if Nkind (Param) /= N_Parameter_Specification then
3760 -- For an access parameter, obtain the type from the formal entity
3761 -- itself, because access to subprogram nodes do not carry a type.
3762 -- Shouldn't we always use the formal entity ???
3764 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3765 return Etype (Defining_Identifier (Param));
3768 return Etype (Parameter_Type (Param));
3770 end Find_Parameter_Type;
3772 -----------------------------
3773 -- Find_Static_Alternative --
3774 -----------------------------
3776 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3777 Expr : constant Node_Id := Expression (N);
3778 Val : constant Uint := Expr_Value (Expr);
3783 Alt := First (Alternatives (N));
3786 if Nkind (Alt) /= N_Pragma then
3787 Choice := First (Discrete_Choices (Alt));
3788 while Present (Choice) loop
3790 -- Others choice, always matches
3792 if Nkind (Choice) = N_Others_Choice then
3795 -- Range, check if value is in the range
3797 elsif Nkind (Choice) = N_Range then
3799 Val >= Expr_Value (Low_Bound (Choice))
3801 Val <= Expr_Value (High_Bound (Choice));
3803 -- Choice is a subtype name. Note that we know it must
3804 -- be a static subtype, since otherwise it would have
3805 -- been diagnosed as illegal.
3807 elsif Is_Entity_Name (Choice)
3808 and then Is_Type (Entity (Choice))
3810 exit Search when Is_In_Range (Expr, Etype (Choice),
3811 Assume_Valid => False);
3813 -- Choice is a subtype indication
3815 elsif Nkind (Choice) = N_Subtype_Indication then
3817 C : constant Node_Id := Constraint (Choice);
3818 R : constant Node_Id := Range_Expression (C);
3822 Val >= Expr_Value (Low_Bound (R))
3824 Val <= Expr_Value (High_Bound (R));
3827 -- Choice is a simple expression
3830 exit Search when Val = Expr_Value (Choice);
3838 pragma Assert (Present (Alt));
3841 -- The above loop *must* terminate by finding a match, since
3842 -- we know the case statement is valid, and the value of the
3843 -- expression is known at compile time. When we fall out of
3844 -- the loop, Alt points to the alternative that we know will
3845 -- be selected at run time.
3848 end Find_Static_Alternative;
3854 function First_Actual (Node : Node_Id) return Node_Id is
3858 if No (Parameter_Associations (Node)) then
3862 N := First (Parameter_Associations (Node));
3864 if Nkind (N) = N_Parameter_Association then
3865 return First_Named_Actual (Node);
3871 -----------------------
3872 -- Gather_Components --
3873 -----------------------
3875 procedure Gather_Components
3877 Comp_List : Node_Id;
3878 Governed_By : List_Id;
3880 Report_Errors : out Boolean)
3884 Discrete_Choice : Node_Id;
3885 Comp_Item : Node_Id;
3887 Discrim : Entity_Id;
3888 Discrim_Name : Node_Id;
3889 Discrim_Value : Node_Id;
3892 Report_Errors := False;
3894 if No (Comp_List) or else Null_Present (Comp_List) then
3897 elsif Present (Component_Items (Comp_List)) then
3898 Comp_Item := First (Component_Items (Comp_List));
3904 while Present (Comp_Item) loop
3906 -- Skip the tag of a tagged record, the interface tags, as well
3907 -- as all items that are not user components (anonymous types,
3908 -- rep clauses, Parent field, controller field).
3910 if Nkind (Comp_Item) = N_Component_Declaration then
3912 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3914 if not Is_Tag (Comp)
3915 and then Chars (Comp) /= Name_uParent
3917 Append_Elmt (Comp, Into);
3925 if No (Variant_Part (Comp_List)) then
3928 Discrim_Name := Name (Variant_Part (Comp_List));
3929 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3932 -- Look for the discriminant that governs this variant part.
3933 -- The discriminant *must* be in the Governed_By List
3935 Assoc := First (Governed_By);
3936 Find_Constraint : loop
3937 Discrim := First (Choices (Assoc));
3938 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3939 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3941 Chars (Corresponding_Discriminant (Entity (Discrim)))
3942 = Chars (Discrim_Name))
3943 or else Chars (Original_Record_Component (Entity (Discrim)))
3944 = Chars (Discrim_Name);
3946 if No (Next (Assoc)) then
3947 if not Is_Constrained (Typ)
3948 and then Is_Derived_Type (Typ)
3949 and then Present (Stored_Constraint (Typ))
3951 -- If the type is a tagged type with inherited discriminants,
3952 -- use the stored constraint on the parent in order to find
3953 -- the values of discriminants that are otherwise hidden by an
3954 -- explicit constraint. Renamed discriminants are handled in
3957 -- If several parent discriminants are renamed by a single
3958 -- discriminant of the derived type, the call to obtain the
3959 -- Corresponding_Discriminant field only retrieves the last
3960 -- of them. We recover the constraint on the others from the
3961 -- Stored_Constraint as well.
3968 D := First_Discriminant (Etype (Typ));
3969 C := First_Elmt (Stored_Constraint (Typ));
3970 while Present (D) and then Present (C) loop
3971 if Chars (Discrim_Name) = Chars (D) then
3972 if Is_Entity_Name (Node (C))
3973 and then Entity (Node (C)) = Entity (Discrim)
3975 -- D is renamed by Discrim, whose value is given in
3982 Make_Component_Association (Sloc (Typ),
3984 (New_Occurrence_Of (D, Sloc (Typ))),
3985 Duplicate_Subexpr_No_Checks (Node (C)));
3987 exit Find_Constraint;
3990 Next_Discriminant (D);
3997 if No (Next (Assoc)) then
3998 Error_Msg_NE (" missing value for discriminant&",
3999 First (Governed_By), Discrim_Name);
4000 Report_Errors := True;
4005 end loop Find_Constraint;
4007 Discrim_Value := Expression (Assoc);
4009 if not Is_OK_Static_Expression (Discrim_Value) then
4011 ("value for discriminant & must be static!",
4012 Discrim_Value, Discrim);
4013 Why_Not_Static (Discrim_Value);
4014 Report_Errors := True;
4018 Search_For_Discriminant_Value : declare
4024 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4027 Find_Discrete_Value : while Present (Variant) loop
4028 Discrete_Choice := First (Discrete_Choices (Variant));
4029 while Present (Discrete_Choice) loop
4031 exit Find_Discrete_Value when
4032 Nkind (Discrete_Choice) = N_Others_Choice;
4034 Get_Index_Bounds (Discrete_Choice, Low, High);
4036 UI_Low := Expr_Value (Low);
4037 UI_High := Expr_Value (High);
4039 exit Find_Discrete_Value when
4040 UI_Low <= UI_Discrim_Value
4042 UI_High >= UI_Discrim_Value;
4044 Next (Discrete_Choice);
4047 Next_Non_Pragma (Variant);
4048 end loop Find_Discrete_Value;
4049 end Search_For_Discriminant_Value;
4051 if No (Variant) then
4053 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4054 Report_Errors := True;
4058 -- If we have found the corresponding choice, recursively add its
4059 -- components to the Into list.
4061 Gather_Components (Empty,
4062 Component_List (Variant), Governed_By, Into, Report_Errors);
4063 end Gather_Components;
4065 ------------------------
4066 -- Get_Actual_Subtype --
4067 ------------------------
4069 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4070 Typ : constant Entity_Id := Etype (N);
4071 Utyp : Entity_Id := Underlying_Type (Typ);
4080 -- If what we have is an identifier that references a subprogram
4081 -- formal, or a variable or constant object, then we get the actual
4082 -- subtype from the referenced entity if one has been built.
4084 if Nkind (N) = N_Identifier
4086 (Is_Formal (Entity (N))
4087 or else Ekind (Entity (N)) = E_Constant
4088 or else Ekind (Entity (N)) = E_Variable)
4089 and then Present (Actual_Subtype (Entity (N)))
4091 return Actual_Subtype (Entity (N));
4093 -- Actual subtype of unchecked union is always itself. We never need
4094 -- the "real" actual subtype. If we did, we couldn't get it anyway
4095 -- because the discriminant is not available. The restrictions on
4096 -- Unchecked_Union are designed to make sure that this is OK.
4098 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4101 -- Here for the unconstrained case, we must find actual subtype
4102 -- No actual subtype is available, so we must build it on the fly.
4104 -- Checking the type, not the underlying type, for constrainedness
4105 -- seems to be necessary. Maybe all the tests should be on the type???
4107 elsif (not Is_Constrained (Typ))
4108 and then (Is_Array_Type (Utyp)
4109 or else (Is_Record_Type (Utyp)
4110 and then Has_Discriminants (Utyp)))
4111 and then not Has_Unknown_Discriminants (Utyp)
4112 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4114 -- Nothing to do if in spec expression (why not???)
4116 if In_Spec_Expression then
4119 elsif Is_Private_Type (Typ)
4120 and then not Has_Discriminants (Typ)
4122 -- If the type has no discriminants, there is no subtype to
4123 -- build, even if the underlying type is discriminated.
4127 -- Else build the actual subtype
4130 Decl := Build_Actual_Subtype (Typ, N);
4131 Atyp := Defining_Identifier (Decl);
4133 -- If Build_Actual_Subtype generated a new declaration then use it
4137 -- The actual subtype is an Itype, so analyze the declaration,
4138 -- but do not attach it to the tree, to get the type defined.
4140 Set_Parent (Decl, N);
4141 Set_Is_Itype (Atyp);
4142 Analyze (Decl, Suppress => All_Checks);
4143 Set_Associated_Node_For_Itype (Atyp, N);
4144 Set_Has_Delayed_Freeze (Atyp, False);
4146 -- We need to freeze the actual subtype immediately. This is
4147 -- needed, because otherwise this Itype will not get frozen
4148 -- at all, and it is always safe to freeze on creation because
4149 -- any associated types must be frozen at this point.
4151 Freeze_Itype (Atyp, N);
4154 -- Otherwise we did not build a declaration, so return original
4161 -- For all remaining cases, the actual subtype is the same as
4162 -- the nominal type.
4167 end Get_Actual_Subtype;
4169 -------------------------------------
4170 -- Get_Actual_Subtype_If_Available --
4171 -------------------------------------
4173 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4174 Typ : constant Entity_Id := Etype (N);
4177 -- If what we have is an identifier that references a subprogram
4178 -- formal, or a variable or constant object, then we get the actual
4179 -- subtype from the referenced entity if one has been built.
4181 if Nkind (N) = N_Identifier
4183 (Is_Formal (Entity (N))
4184 or else Ekind (Entity (N)) = E_Constant
4185 or else Ekind (Entity (N)) = E_Variable)
4186 and then Present (Actual_Subtype (Entity (N)))
4188 return Actual_Subtype (Entity (N));
4190 -- Otherwise the Etype of N is returned unchanged
4195 end Get_Actual_Subtype_If_Available;
4197 -------------------------------
4198 -- Get_Default_External_Name --
4199 -------------------------------
4201 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4203 Get_Decoded_Name_String (Chars (E));
4205 if Opt.External_Name_Imp_Casing = Uppercase then
4206 Set_Casing (All_Upper_Case);
4208 Set_Casing (All_Lower_Case);
4212 Make_String_Literal (Sloc (E),
4213 Strval => String_From_Name_Buffer);
4214 end Get_Default_External_Name;
4216 ---------------------------
4217 -- Get_Enum_Lit_From_Pos --
4218 ---------------------------
4220 function Get_Enum_Lit_From_Pos
4223 Loc : Source_Ptr) return Node_Id
4228 -- In the case where the literal is of type Character, Wide_Character
4229 -- or Wide_Wide_Character or of a type derived from them, there needs
4230 -- to be some special handling since there is no explicit chain of
4231 -- literals to search. Instead, an N_Character_Literal node is created
4232 -- with the appropriate Char_Code and Chars fields.
4234 if Is_Standard_Character_Type (T) then
4235 Set_Character_Literal_Name (UI_To_CC (Pos));
4237 Make_Character_Literal (Loc,
4239 Char_Literal_Value => Pos);
4241 -- For all other cases, we have a complete table of literals, and
4242 -- we simply iterate through the chain of literal until the one
4243 -- with the desired position value is found.
4247 Lit := First_Literal (Base_Type (T));
4248 for J in 1 .. UI_To_Int (Pos) loop
4252 return New_Occurrence_Of (Lit, Loc);
4254 end Get_Enum_Lit_From_Pos;
4256 ------------------------
4257 -- Get_Generic_Entity --
4258 ------------------------
4260 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4261 Ent : constant Entity_Id := Entity (Name (N));
4263 if Present (Renamed_Object (Ent)) then
4264 return Renamed_Object (Ent);
4268 end Get_Generic_Entity;
4270 ----------------------
4271 -- Get_Index_Bounds --
4272 ----------------------
4274 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4275 Kind : constant Node_Kind := Nkind (N);
4279 if Kind = N_Range then
4281 H := High_Bound (N);
4283 elsif Kind = N_Subtype_Indication then
4284 R := Range_Expression (Constraint (N));
4292 L := Low_Bound (Range_Expression (Constraint (N)));
4293 H := High_Bound (Range_Expression (Constraint (N)));
4296 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4297 if Error_Posted (Scalar_Range (Entity (N))) then
4301 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4302 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4305 L := Low_Bound (Scalar_Range (Entity (N)));
4306 H := High_Bound (Scalar_Range (Entity (N)));
4310 -- N is an expression, indicating a range with one value
4315 end Get_Index_Bounds;
4317 ----------------------------------
4318 -- Get_Library_Unit_Name_string --
4319 ----------------------------------
4321 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4322 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4325 Get_Unit_Name_String (Unit_Name_Id);
4327 -- Remove seven last character (" (spec)" or " (body)")
4329 Name_Len := Name_Len - 7;
4330 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4331 end Get_Library_Unit_Name_String;
4333 ------------------------
4334 -- Get_Name_Entity_Id --
4335 ------------------------
4337 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4339 return Entity_Id (Get_Name_Table_Info (Id));
4340 end Get_Name_Entity_Id;
4346 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4348 return Get_Pragma_Id (Pragma_Name (N));
4351 ---------------------------
4352 -- Get_Referenced_Object --
4353 ---------------------------
4355 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4360 while Is_Entity_Name (R)
4361 and then Present (Renamed_Object (Entity (R)))
4363 R := Renamed_Object (Entity (R));
4367 end Get_Referenced_Object;
4369 ------------------------
4370 -- Get_Renamed_Entity --
4371 ------------------------
4373 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4378 while Present (Renamed_Entity (R)) loop
4379 R := Renamed_Entity (R);
4383 end Get_Renamed_Entity;
4385 -------------------------
4386 -- Get_Subprogram_Body --
4387 -------------------------
4389 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4393 Decl := Unit_Declaration_Node (E);
4395 if Nkind (Decl) = N_Subprogram_Body then
4398 -- The below comment is bad, because it is possible for
4399 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4401 else -- Nkind (Decl) = N_Subprogram_Declaration
4403 if Present (Corresponding_Body (Decl)) then
4404 return Unit_Declaration_Node (Corresponding_Body (Decl));
4406 -- Imported subprogram case
4412 end Get_Subprogram_Body;
4414 ---------------------------
4415 -- Get_Subprogram_Entity --
4416 ---------------------------
4418 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4423 if Nkind (Nod) = N_Accept_Statement then
4424 Nam := Entry_Direct_Name (Nod);
4426 -- For an entry call, the prefix of the call is a selected component.
4427 -- Need additional code for internal calls ???
4429 elsif Nkind (Nod) = N_Entry_Call_Statement then
4430 if Nkind (Name (Nod)) = N_Selected_Component then
4431 Nam := Entity (Selector_Name (Name (Nod)));
4440 if Nkind (Nam) = N_Explicit_Dereference then
4441 Proc := Etype (Prefix (Nam));
4442 elsif Is_Entity_Name (Nam) then
4443 Proc := Entity (Nam);
4448 if Is_Object (Proc) then
4449 Proc := Etype (Proc);
4452 if Ekind (Proc) = E_Access_Subprogram_Type then
4453 Proc := Directly_Designated_Type (Proc);
4456 if not Is_Subprogram (Proc)
4457 and then Ekind (Proc) /= E_Subprogram_Type
4463 end Get_Subprogram_Entity;
4465 -----------------------------
4466 -- Get_Task_Body_Procedure --
4467 -----------------------------
4469 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4471 -- Note: A task type may be the completion of a private type with
4472 -- discriminants. When performing elaboration checks on a task
4473 -- declaration, the current view of the type may be the private one,
4474 -- and the procedure that holds the body of the task is held in its
4477 -- This is an odd function, why not have Task_Body_Procedure do
4478 -- the following digging???
4480 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4481 end Get_Task_Body_Procedure;
4483 -----------------------
4484 -- Has_Access_Values --
4485 -----------------------
4487 function Has_Access_Values (T : Entity_Id) return Boolean is
4488 Typ : constant Entity_Id := Underlying_Type (T);
4491 -- Case of a private type which is not completed yet. This can only
4492 -- happen in the case of a generic format type appearing directly, or
4493 -- as a component of the type to which this function is being applied
4494 -- at the top level. Return False in this case, since we certainly do
4495 -- not know that the type contains access types.
4500 elsif Is_Access_Type (Typ) then
4503 elsif Is_Array_Type (Typ) then
4504 return Has_Access_Values (Component_Type (Typ));
4506 elsif Is_Record_Type (Typ) then
4511 -- Loop to Check components
4513 Comp := First_Component_Or_Discriminant (Typ);
4514 while Present (Comp) loop
4516 -- Check for access component, tag field does not count, even
4517 -- though it is implemented internally using an access type.
4519 if Has_Access_Values (Etype (Comp))
4520 and then Chars (Comp) /= Name_uTag
4525 Next_Component_Or_Discriminant (Comp);
4534 end Has_Access_Values;
4536 ------------------------------
4537 -- Has_Compatible_Alignment --
4538 ------------------------------
4540 function Has_Compatible_Alignment
4542 Expr : Node_Id) return Alignment_Result
4544 function Has_Compatible_Alignment_Internal
4547 Default : Alignment_Result) return Alignment_Result;
4548 -- This is the internal recursive function that actually does the work.
4549 -- There is one additional parameter, which says what the result should
4550 -- be if no alignment information is found, and there is no definite
4551 -- indication of compatible alignments. At the outer level, this is set
4552 -- to Unknown, but for internal recursive calls in the case where types
4553 -- are known to be correct, it is set to Known_Compatible.
4555 ---------------------------------------
4556 -- Has_Compatible_Alignment_Internal --
4557 ---------------------------------------
4559 function Has_Compatible_Alignment_Internal
4562 Default : Alignment_Result) return Alignment_Result
4564 Result : Alignment_Result := Known_Compatible;
4565 -- Holds the current status of the result. Note that once a value of
4566 -- Known_Incompatible is set, it is sticky and does not get changed
4567 -- to Unknown (the value in Result only gets worse as we go along,
4570 Offs : Uint := No_Uint;
4571 -- Set to a factor of the offset from the base object when Expr is a
4572 -- selected or indexed component, based on Component_Bit_Offset and
4573 -- Component_Size respectively. A negative value is used to represent
4574 -- a value which is not known at compile time.
4576 procedure Check_Prefix;
4577 -- Checks the prefix recursively in the case where the expression
4578 -- is an indexed or selected component.
4580 procedure Set_Result (R : Alignment_Result);
4581 -- If R represents a worse outcome (unknown instead of known
4582 -- compatible, or known incompatible), then set Result to R.
4588 procedure Check_Prefix is
4590 -- The subtlety here is that in doing a recursive call to check
4591 -- the prefix, we have to decide what to do in the case where we
4592 -- don't find any specific indication of an alignment problem.
4594 -- At the outer level, we normally set Unknown as the result in
4595 -- this case, since we can only set Known_Compatible if we really
4596 -- know that the alignment value is OK, but for the recursive
4597 -- call, in the case where the types match, and we have not
4598 -- specified a peculiar alignment for the object, we are only
4599 -- concerned about suspicious rep clauses, the default case does
4600 -- not affect us, since the compiler will, in the absence of such
4601 -- rep clauses, ensure that the alignment is correct.
4603 if Default = Known_Compatible
4605 (Etype (Obj) = Etype (Expr)
4606 and then (Unknown_Alignment (Obj)
4608 Alignment (Obj) = Alignment (Etype (Obj))))
4611 (Has_Compatible_Alignment_Internal
4612 (Obj, Prefix (Expr), Known_Compatible));
4614 -- In all other cases, we need a full check on the prefix
4618 (Has_Compatible_Alignment_Internal
4619 (Obj, Prefix (Expr), Unknown));
4627 procedure Set_Result (R : Alignment_Result) is
4634 -- Start of processing for Has_Compatible_Alignment_Internal
4637 -- If Expr is a selected component, we must make sure there is no
4638 -- potentially troublesome component clause, and that the record is
4641 if Nkind (Expr) = N_Selected_Component then
4643 -- Packed record always generate unknown alignment
4645 if Is_Packed (Etype (Prefix (Expr))) then
4646 Set_Result (Unknown);
4649 -- Check prefix and component offset
4652 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4654 -- If Expr is an indexed component, we must make sure there is no
4655 -- potentially troublesome Component_Size clause and that the array
4656 -- is not bit-packed.
4658 elsif Nkind (Expr) = N_Indexed_Component then
4660 Typ : constant Entity_Id := Etype (Prefix (Expr));
4661 Ind : constant Node_Id := First_Index (Typ);
4664 -- Bit packed array always generates unknown alignment
4666 if Is_Bit_Packed_Array (Typ) then
4667 Set_Result (Unknown);
4670 -- Check prefix and component offset
4673 Offs := Component_Size (Typ);
4675 -- Small optimization: compute the full offset when possible
4678 and then Offs > Uint_0
4679 and then Present (Ind)
4680 and then Nkind (Ind) = N_Range
4681 and then Compile_Time_Known_Value (Low_Bound (Ind))
4682 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4684 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4685 - Expr_Value (Low_Bound ((Ind))));
4690 -- If we have a null offset, the result is entirely determined by
4691 -- the base object and has already been computed recursively.
4693 if Offs = Uint_0 then
4696 -- Case where we know the alignment of the object
4698 elsif Known_Alignment (Obj) then
4700 ObjA : constant Uint := Alignment (Obj);
4701 ExpA : Uint := No_Uint;
4702 SizA : Uint := No_Uint;
4705 -- If alignment of Obj is 1, then we are always OK
4708 Set_Result (Known_Compatible);
4710 -- Alignment of Obj is greater than 1, so we need to check
4713 -- If we have an offset, see if it is compatible
4715 if Offs /= No_Uint and Offs > Uint_0 then
4716 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4717 Set_Result (Known_Incompatible);
4720 -- See if Expr is an object with known alignment
4722 elsif Is_Entity_Name (Expr)
4723 and then Known_Alignment (Entity (Expr))
4725 ExpA := Alignment (Entity (Expr));
4727 -- Otherwise, we can use the alignment of the type of
4728 -- Expr given that we already checked for
4729 -- discombobulating rep clauses for the cases of indexed
4730 -- and selected components above.
4732 elsif Known_Alignment (Etype (Expr)) then
4733 ExpA := Alignment (Etype (Expr));
4735 -- Otherwise the alignment is unknown
4738 Set_Result (Default);
4741 -- If we got an alignment, see if it is acceptable
4743 if ExpA /= No_Uint and then ExpA < ObjA then
4744 Set_Result (Known_Incompatible);
4747 -- If Expr is not a piece of a larger object, see if size
4748 -- is given. If so, check that it is not too small for the
4749 -- required alignment.
4751 if Offs /= No_Uint then
4754 -- See if Expr is an object with known size
4756 elsif Is_Entity_Name (Expr)
4757 and then Known_Static_Esize (Entity (Expr))
4759 SizA := Esize (Entity (Expr));
4761 -- Otherwise, we check the object size of the Expr type
4763 elsif Known_Static_Esize (Etype (Expr)) then
4764 SizA := Esize (Etype (Expr));
4767 -- If we got a size, see if it is a multiple of the Obj
4768 -- alignment, if not, then the alignment cannot be
4769 -- acceptable, since the size is always a multiple of the
4772 if SizA /= No_Uint then
4773 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4774 Set_Result (Known_Incompatible);
4780 -- If we do not know required alignment, any non-zero offset is a
4781 -- potential problem (but certainly may be OK, so result is unknown).
4783 elsif Offs /= No_Uint then
4784 Set_Result (Unknown);
4786 -- If we can't find the result by direct comparison of alignment
4787 -- values, then there is still one case that we can determine known
4788 -- result, and that is when we can determine that the types are the
4789 -- same, and no alignments are specified. Then we known that the
4790 -- alignments are compatible, even if we don't know the alignment
4791 -- value in the front end.
4793 elsif Etype (Obj) = Etype (Expr) then
4795 -- Types are the same, but we have to check for possible size
4796 -- and alignments on the Expr object that may make the alignment
4797 -- different, even though the types are the same.
4799 if Is_Entity_Name (Expr) then
4801 -- First check alignment of the Expr object. Any alignment less
4802 -- than Maximum_Alignment is worrisome since this is the case
4803 -- where we do not know the alignment of Obj.
4805 if Known_Alignment (Entity (Expr))
4807 UI_To_Int (Alignment (Entity (Expr))) <
4808 Ttypes.Maximum_Alignment
4810 Set_Result (Unknown);
4812 -- Now check size of Expr object. Any size that is not an
4813 -- even multiple of Maximum_Alignment is also worrisome
4814 -- since it may cause the alignment of the object to be less
4815 -- than the alignment of the type.
4817 elsif Known_Static_Esize (Entity (Expr))
4819 (UI_To_Int (Esize (Entity (Expr))) mod
4820 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4823 Set_Result (Unknown);
4825 -- Otherwise same type is decisive
4828 Set_Result (Known_Compatible);
4832 -- Another case to deal with is when there is an explicit size or
4833 -- alignment clause when the types are not the same. If so, then the
4834 -- result is Unknown. We don't need to do this test if the Default is
4835 -- Unknown, since that result will be set in any case.
4837 elsif Default /= Unknown
4838 and then (Has_Size_Clause (Etype (Expr))
4840 Has_Alignment_Clause (Etype (Expr)))
4842 Set_Result (Unknown);
4844 -- If no indication found, set default
4847 Set_Result (Default);
4850 -- Return worst result found
4853 end Has_Compatible_Alignment_Internal;
4855 -- Start of processing for Has_Compatible_Alignment
4858 -- If Obj has no specified alignment, then set alignment from the type
4859 -- alignment. Perhaps we should always do this, but for sure we should
4860 -- do it when there is an address clause since we can do more if the
4861 -- alignment is known.
4863 if Unknown_Alignment (Obj) then
4864 Set_Alignment (Obj, Alignment (Etype (Obj)));
4867 -- Now do the internal call that does all the work
4869 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4870 end Has_Compatible_Alignment;
4872 ----------------------
4873 -- Has_Declarations --
4874 ----------------------
4876 function Has_Declarations (N : Node_Id) return Boolean is
4878 return Nkind_In (Nkind (N), N_Accept_Statement,
4880 N_Compilation_Unit_Aux,
4886 N_Package_Specification);
4887 end Has_Declarations;
4889 -------------------------------------------
4890 -- Has_Discriminant_Dependent_Constraint --
4891 -------------------------------------------
4893 function Has_Discriminant_Dependent_Constraint
4894 (Comp : Entity_Id) return Boolean
4896 Comp_Decl : constant Node_Id := Parent (Comp);
4897 Subt_Indic : constant Node_Id :=
4898 Subtype_Indication (Component_Definition (Comp_Decl));
4903 if Nkind (Subt_Indic) = N_Subtype_Indication then
4904 Constr := Constraint (Subt_Indic);
4906 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4907 Assn := First (Constraints (Constr));
4908 while Present (Assn) loop
4909 case Nkind (Assn) is
4910 when N_Subtype_Indication |
4914 if Depends_On_Discriminant (Assn) then
4918 when N_Discriminant_Association =>
4919 if Depends_On_Discriminant (Expression (Assn)) then
4934 end Has_Discriminant_Dependent_Constraint;
4936 --------------------
4937 -- Has_Infinities --
4938 --------------------
4940 function Has_Infinities (E : Entity_Id) return Boolean is
4943 Is_Floating_Point_Type (E)
4944 and then Nkind (Scalar_Range (E)) = N_Range
4945 and then Includes_Infinities (Scalar_Range (E));
4948 --------------------
4949 -- Has_Interfaces --
4950 --------------------
4952 function Has_Interfaces
4954 Use_Full_View : Boolean := True) return Boolean
4956 Typ : Entity_Id := Base_Type (T);
4959 -- Handle concurrent types
4961 if Is_Concurrent_Type (Typ) then
4962 Typ := Corresponding_Record_Type (Typ);
4965 if not Present (Typ)
4966 or else not Is_Record_Type (Typ)
4967 or else not Is_Tagged_Type (Typ)
4972 -- Handle private types
4975 and then Present (Full_View (Typ))
4977 Typ := Full_View (Typ);
4980 -- Handle concurrent record types
4982 if Is_Concurrent_Record_Type (Typ)
4983 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4989 if Is_Interface (Typ)
4991 (Is_Record_Type (Typ)
4992 and then Present (Interfaces (Typ))
4993 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4998 exit when Etype (Typ) = Typ
5000 -- Handle private types
5002 or else (Present (Full_View (Etype (Typ)))
5003 and then Full_View (Etype (Typ)) = Typ)
5005 -- Protect the frontend against wrong source with cyclic
5008 or else Etype (Typ) = T;
5010 -- Climb to the ancestor type handling private types
5012 if Present (Full_View (Etype (Typ))) then
5013 Typ := Full_View (Etype (Typ));
5022 ------------------------
5023 -- Has_Null_Exclusion --
5024 ------------------------
5026 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5029 when N_Access_Definition |
5030 N_Access_Function_Definition |
5031 N_Access_Procedure_Definition |
5032 N_Access_To_Object_Definition |
5034 N_Derived_Type_Definition |
5035 N_Function_Specification |
5036 N_Subtype_Declaration =>
5037 return Null_Exclusion_Present (N);
5039 when N_Component_Definition |
5040 N_Formal_Object_Declaration |
5041 N_Object_Renaming_Declaration =>
5042 if Present (Subtype_Mark (N)) then
5043 return Null_Exclusion_Present (N);
5044 else pragma Assert (Present (Access_Definition (N)));
5045 return Null_Exclusion_Present (Access_Definition (N));
5048 when N_Discriminant_Specification =>
5049 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5050 return Null_Exclusion_Present (Discriminant_Type (N));
5052 return Null_Exclusion_Present (N);
5055 when N_Object_Declaration =>
5056 if Nkind (Object_Definition (N)) = N_Access_Definition then
5057 return Null_Exclusion_Present (Object_Definition (N));
5059 return Null_Exclusion_Present (N);
5062 when N_Parameter_Specification =>
5063 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5064 return Null_Exclusion_Present (Parameter_Type (N));
5066 return Null_Exclusion_Present (N);
5073 end Has_Null_Exclusion;
5075 ------------------------
5076 -- Has_Null_Extension --
5077 ------------------------
5079 function Has_Null_Extension (T : Entity_Id) return Boolean is
5080 B : constant Entity_Id := Base_Type (T);
5085 if Nkind (Parent (B)) = N_Full_Type_Declaration
5086 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5088 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5090 if Present (Ext) then
5091 if Null_Present (Ext) then
5094 Comps := Component_List (Ext);
5096 -- The null component list is rewritten during analysis to
5097 -- include the parent component. Any other component indicates
5098 -- that the extension was not originally null.
5100 return Null_Present (Comps)
5101 or else No (Next (First (Component_Items (Comps))));
5110 end Has_Null_Extension;
5112 -------------------------------
5113 -- Has_Overriding_Initialize --
5114 -------------------------------
5116 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5117 BT : constant Entity_Id := Base_Type (T);
5121 if Is_Controlled (BT) then
5122 if Is_RTU (Scope (BT), Ada_Finalization) then
5125 elsif Present (Primitive_Operations (BT)) then
5126 P := First_Elmt (Primitive_Operations (BT));
5127 while Present (P) loop
5129 Init : constant Entity_Id := Node (P);
5130 Formal : constant Entity_Id := First_Formal (Init);
5132 if Ekind (Init) = E_Procedure
5133 and then Chars (Init) = Name_Initialize
5134 and then Comes_From_Source (Init)
5135 and then Present (Formal)
5136 and then Etype (Formal) = BT
5137 and then No (Next_Formal (Formal))
5138 and then (Ada_Version < Ada_2012
5139 or else not Null_Present (Parent (Init)))
5149 -- Here if type itself does not have a non-null Initialize operation:
5150 -- check immediate ancestor.
5152 if Is_Derived_Type (BT)
5153 and then Has_Overriding_Initialize (Etype (BT))
5160 end Has_Overriding_Initialize;
5162 --------------------------------------
5163 -- Has_Preelaborable_Initialization --
5164 --------------------------------------
5166 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5169 procedure Check_Components (E : Entity_Id);
5170 -- Check component/discriminant chain, sets Has_PE False if a component
5171 -- or discriminant does not meet the preelaborable initialization rules.
5173 ----------------------
5174 -- Check_Components --
5175 ----------------------
5177 procedure Check_Components (E : Entity_Id) is
5181 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5182 -- Returns True if and only if the expression denoted by N does not
5183 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5185 ---------------------------------
5186 -- Is_Preelaborable_Expression --
5187 ---------------------------------
5189 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5193 Comp_Type : Entity_Id;
5194 Is_Array_Aggr : Boolean;
5197 if Is_Static_Expression (N) then
5200 elsif Nkind (N) = N_Null then
5203 -- Attributes are allowed in general, even if their prefix is a
5204 -- formal type. (It seems that certain attributes known not to be
5205 -- static might not be allowed, but there are no rules to prevent
5208 elsif Nkind (N) = N_Attribute_Reference then
5211 -- The name of a discriminant evaluated within its parent type is
5212 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5213 -- names that denote discriminals as well as discriminants to
5214 -- catch references occurring within init procs.
5216 elsif Is_Entity_Name (N)
5218 (Ekind (Entity (N)) = E_Discriminant
5220 ((Ekind (Entity (N)) = E_Constant
5221 or else Ekind (Entity (N)) = E_In_Parameter)
5222 and then Present (Discriminal_Link (Entity (N)))))
5226 elsif Nkind (N) = N_Qualified_Expression then
5227 return Is_Preelaborable_Expression (Expression (N));
5229 -- For aggregates we have to check that each of the associations
5230 -- is preelaborable.
5232 elsif Nkind (N) = N_Aggregate
5233 or else Nkind (N) = N_Extension_Aggregate
5235 Is_Array_Aggr := Is_Array_Type (Etype (N));
5237 if Is_Array_Aggr then
5238 Comp_Type := Component_Type (Etype (N));
5241 -- Check the ancestor part of extension aggregates, which must
5242 -- be either the name of a type that has preelaborable init or
5243 -- an expression that is preelaborable.
5245 if Nkind (N) = N_Extension_Aggregate then
5247 Anc_Part : constant Node_Id := Ancestor_Part (N);
5250 if Is_Entity_Name (Anc_Part)
5251 and then Is_Type (Entity (Anc_Part))
5253 if not Has_Preelaborable_Initialization
5259 elsif not Is_Preelaborable_Expression (Anc_Part) then
5265 -- Check positional associations
5267 Exp := First (Expressions (N));
5268 while Present (Exp) loop
5269 if not Is_Preelaborable_Expression (Exp) then
5276 -- Check named associations
5278 Assn := First (Component_Associations (N));
5279 while Present (Assn) loop
5280 Choice := First (Choices (Assn));
5281 while Present (Choice) loop
5282 if Is_Array_Aggr then
5283 if Nkind (Choice) = N_Others_Choice then
5286 elsif Nkind (Choice) = N_Range then
5287 if not Is_Static_Range (Choice) then
5291 elsif not Is_Static_Expression (Choice) then
5296 Comp_Type := Etype (Choice);
5302 -- If the association has a <> at this point, then we have
5303 -- to check whether the component's type has preelaborable
5304 -- initialization. Note that this only occurs when the
5305 -- association's corresponding component does not have a
5306 -- default expression, the latter case having already been
5307 -- expanded as an expression for the association.
5309 if Box_Present (Assn) then
5310 if not Has_Preelaborable_Initialization (Comp_Type) then
5314 -- In the expression case we check whether the expression
5315 -- is preelaborable.
5318 not Is_Preelaborable_Expression (Expression (Assn))
5326 -- If we get here then aggregate as a whole is preelaborable
5330 -- All other cases are not preelaborable
5335 end Is_Preelaborable_Expression;
5337 -- Start of processing for Check_Components
5340 -- Loop through entities of record or protected type
5343 while Present (Ent) loop
5345 -- We are interested only in components and discriminants
5352 -- Get default expression if any. If there is no declaration
5353 -- node, it means we have an internal entity. The parent and
5354 -- tag fields are examples of such entities. For such cases,
5355 -- we just test the type of the entity.
5357 if Present (Declaration_Node (Ent)) then
5358 Exp := Expression (Declaration_Node (Ent));
5361 when E_Discriminant =>
5363 -- Note: for a renamed discriminant, the Declaration_Node
5364 -- may point to the one from the ancestor, and have a
5365 -- different expression, so use the proper attribute to
5366 -- retrieve the expression from the derived constraint.
5368 Exp := Discriminant_Default_Value (Ent);
5371 goto Check_Next_Entity;
5374 -- A component has PI if it has no default expression and the
5375 -- component type has PI.
5378 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5383 -- Require the default expression to be preelaborable
5385 elsif not Is_Preelaborable_Expression (Exp) then
5390 <<Check_Next_Entity>>
5393 end Check_Components;
5395 -- Start of processing for Has_Preelaborable_Initialization
5398 -- Immediate return if already marked as known preelaborable init. This
5399 -- covers types for which this function has already been called once
5400 -- and returned True (in which case the result is cached), and also
5401 -- types to which a pragma Preelaborable_Initialization applies.
5403 if Known_To_Have_Preelab_Init (E) then
5407 -- If the type is a subtype representing a generic actual type, then
5408 -- test whether its base type has preelaborable initialization since
5409 -- the subtype representing the actual does not inherit this attribute
5410 -- from the actual or formal. (but maybe it should???)
5412 if Is_Generic_Actual_Type (E) then
5413 return Has_Preelaborable_Initialization (Base_Type (E));
5416 -- All elementary types have preelaborable initialization
5418 if Is_Elementary_Type (E) then
5421 -- Array types have PI if the component type has PI
5423 elsif Is_Array_Type (E) then
5424 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5426 -- A derived type has preelaborable initialization if its parent type
5427 -- has preelaborable initialization and (in the case of a derived record
5428 -- extension) if the non-inherited components all have preelaborable
5429 -- initialization. However, a user-defined controlled type with an
5430 -- overriding Initialize procedure does not have preelaborable
5433 elsif Is_Derived_Type (E) then
5435 -- If the derived type is a private extension then it doesn't have
5436 -- preelaborable initialization.
5438 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5442 -- First check whether ancestor type has preelaborable initialization
5444 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5446 -- If OK, check extension components (if any)
5448 if Has_PE and then Is_Record_Type (E) then
5449 Check_Components (First_Entity (E));
5452 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5453 -- with a user defined Initialize procedure does not have PI.
5456 and then Is_Controlled (E)
5457 and then Has_Overriding_Initialize (E)
5462 -- Private types not derived from a type having preelaborable init and
5463 -- that are not marked with pragma Preelaborable_Initialization do not
5464 -- have preelaborable initialization.
5466 elsif Is_Private_Type (E) then
5469 -- Record type has PI if it is non private and all components have PI
5471 elsif Is_Record_Type (E) then
5473 Check_Components (First_Entity (E));
5475 -- Protected types must not have entries, and components must meet
5476 -- same set of rules as for record components.
5478 elsif Is_Protected_Type (E) then
5479 if Has_Entries (E) then
5483 Check_Components (First_Entity (E));
5484 Check_Components (First_Private_Entity (E));
5487 -- Type System.Address always has preelaborable initialization
5489 elsif Is_RTE (E, RE_Address) then
5492 -- In all other cases, type does not have preelaborable initialization
5498 -- If type has preelaborable initialization, cache result
5501 Set_Known_To_Have_Preelab_Init (E);
5505 end Has_Preelaborable_Initialization;
5507 ---------------------------
5508 -- Has_Private_Component --
5509 ---------------------------
5511 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5512 Btype : Entity_Id := Base_Type (Type_Id);
5513 Component : Entity_Id;
5516 if Error_Posted (Type_Id)
5517 or else Error_Posted (Btype)
5522 if Is_Class_Wide_Type (Btype) then
5523 Btype := Root_Type (Btype);
5526 if Is_Private_Type (Btype) then
5528 UT : constant Entity_Id := Underlying_Type (Btype);
5531 if No (Full_View (Btype)) then
5532 return not Is_Generic_Type (Btype)
5533 and then not Is_Generic_Type (Root_Type (Btype));
5535 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5538 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5542 elsif Is_Array_Type (Btype) then
5543 return Has_Private_Component (Component_Type (Btype));
5545 elsif Is_Record_Type (Btype) then
5546 Component := First_Component (Btype);
5547 while Present (Component) loop
5548 if Has_Private_Component (Etype (Component)) then
5552 Next_Component (Component);
5557 elsif Is_Protected_Type (Btype)
5558 and then Present (Corresponding_Record_Type (Btype))
5560 return Has_Private_Component (Corresponding_Record_Type (Btype));
5565 end Has_Private_Component;
5567 -----------------------------
5568 -- Has_Static_Array_Bounds --
5569 -----------------------------
5571 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5572 Ndims : constant Nat := Number_Dimensions (Typ);
5579 -- Unconstrained types do not have static bounds
5581 if not Is_Constrained (Typ) then
5585 -- First treat string literals specially, as the lower bound and length
5586 -- of string literals are not stored like those of arrays.
5588 -- A string literal always has static bounds
5590 if Ekind (Typ) = E_String_Literal_Subtype then
5594 -- Treat all dimensions in turn
5596 Index := First_Index (Typ);
5597 for Indx in 1 .. Ndims loop
5599 -- In case of an erroneous index which is not a discrete type, return
5600 -- that the type is not static.
5602 if not Is_Discrete_Type (Etype (Index))
5603 or else Etype (Index) = Any_Type
5608 Get_Index_Bounds (Index, Low, High);
5610 if Error_Posted (Low) or else Error_Posted (High) then
5614 if Is_OK_Static_Expression (Low)
5616 Is_OK_Static_Expression (High)
5626 -- If we fall through the loop, all indexes matched
5629 end Has_Static_Array_Bounds;
5635 function Has_Stream (T : Entity_Id) return Boolean is
5642 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5645 elsif Is_Array_Type (T) then
5646 return Has_Stream (Component_Type (T));
5648 elsif Is_Record_Type (T) then
5649 E := First_Component (T);
5650 while Present (E) loop
5651 if Has_Stream (Etype (E)) then
5660 elsif Is_Private_Type (T) then
5661 return Has_Stream (Underlying_Type (T));
5672 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5674 Get_Name_String (Chars (E));
5675 return Name_Buffer (Name_Len) = Suffix;
5678 --------------------------
5679 -- Has_Tagged_Component --
5680 --------------------------
5682 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5686 if Is_Private_Type (Typ)
5687 and then Present (Underlying_Type (Typ))
5689 return Has_Tagged_Component (Underlying_Type (Typ));
5691 elsif Is_Array_Type (Typ) then
5692 return Has_Tagged_Component (Component_Type (Typ));
5694 elsif Is_Tagged_Type (Typ) then
5697 elsif Is_Record_Type (Typ) then
5698 Comp := First_Component (Typ);
5699 while Present (Comp) loop
5700 if Has_Tagged_Component (Etype (Comp)) then
5704 Next_Component (Comp);
5712 end Has_Tagged_Component;
5714 -------------------------
5715 -- Implementation_Kind --
5716 -------------------------
5718 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5719 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5721 pragma Assert (Present (Impl_Prag));
5723 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5724 end Implementation_Kind;
5726 --------------------------
5727 -- Implements_Interface --
5728 --------------------------
5730 function Implements_Interface
5731 (Typ_Ent : Entity_Id;
5732 Iface_Ent : Entity_Id;
5733 Exclude_Parents : Boolean := False) return Boolean
5735 Ifaces_List : Elist_Id;
5737 Iface : Entity_Id := Base_Type (Iface_Ent);
5738 Typ : Entity_Id := Base_Type (Typ_Ent);
5741 if Is_Class_Wide_Type (Typ) then
5742 Typ := Root_Type (Typ);
5745 if not Has_Interfaces (Typ) then
5749 if Is_Class_Wide_Type (Iface) then
5750 Iface := Root_Type (Iface);
5753 Collect_Interfaces (Typ, Ifaces_List);
5755 Elmt := First_Elmt (Ifaces_List);
5756 while Present (Elmt) loop
5757 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5758 and then Exclude_Parents
5762 elsif Node (Elmt) = Iface then
5770 end Implements_Interface;
5776 function In_Instance return Boolean is
5777 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5783 and then S /= Standard_Standard
5785 if (Ekind (S) = E_Function
5786 or else Ekind (S) = E_Package
5787 or else Ekind (S) = E_Procedure)
5788 and then Is_Generic_Instance (S)
5790 -- A child instance is always compiled in the context of a parent
5791 -- instance. Nevertheless, the actuals are not analyzed in an
5792 -- instance context. We detect this case by examining the current
5793 -- compilation unit, which must be a child instance, and checking
5794 -- that it is not currently on the scope stack.
5796 if Is_Child_Unit (Curr_Unit)
5798 Nkind (Unit (Cunit (Current_Sem_Unit)))
5799 = N_Package_Instantiation
5800 and then not In_Open_Scopes (Curr_Unit)
5814 ----------------------
5815 -- In_Instance_Body --
5816 ----------------------
5818 function In_Instance_Body return Boolean is
5824 and then S /= Standard_Standard
5826 if (Ekind (S) = E_Function
5827 or else Ekind (S) = E_Procedure)
5828 and then Is_Generic_Instance (S)
5832 elsif Ekind (S) = E_Package
5833 and then In_Package_Body (S)
5834 and then Is_Generic_Instance (S)
5843 end In_Instance_Body;
5845 -----------------------------
5846 -- In_Instance_Not_Visible --
5847 -----------------------------
5849 function In_Instance_Not_Visible return Boolean is
5855 and then S /= Standard_Standard
5857 if (Ekind (S) = E_Function
5858 or else Ekind (S) = E_Procedure)
5859 and then Is_Generic_Instance (S)
5863 elsif Ekind (S) = E_Package
5864 and then (In_Package_Body (S) or else In_Private_Part (S))
5865 and then Is_Generic_Instance (S)
5874 end In_Instance_Not_Visible;
5876 ------------------------------
5877 -- In_Instance_Visible_Part --
5878 ------------------------------
5880 function In_Instance_Visible_Part return Boolean is
5886 and then S /= Standard_Standard
5888 if Ekind (S) = E_Package
5889 and then Is_Generic_Instance (S)
5890 and then not In_Package_Body (S)
5891 and then not In_Private_Part (S)
5900 end In_Instance_Visible_Part;
5902 ---------------------
5903 -- In_Package_Body --
5904 ---------------------
5906 function In_Package_Body return Boolean is
5912 and then S /= Standard_Standard
5914 if Ekind (S) = E_Package
5915 and then In_Package_Body (S)
5924 end In_Package_Body;
5926 --------------------------------
5927 -- In_Parameter_Specification --
5928 --------------------------------
5930 function In_Parameter_Specification (N : Node_Id) return Boolean is
5935 while Present (PN) loop
5936 if Nkind (PN) = N_Parameter_Specification then
5944 end In_Parameter_Specification;
5946 --------------------------------------
5947 -- In_Subprogram_Or_Concurrent_Unit --
5948 --------------------------------------
5950 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5955 -- Use scope chain to check successively outer scopes
5961 if K in Subprogram_Kind
5962 or else K in Concurrent_Kind
5963 or else K in Generic_Subprogram_Kind
5967 elsif E = Standard_Standard then
5973 end In_Subprogram_Or_Concurrent_Unit;
5975 ---------------------
5976 -- In_Visible_Part --
5977 ---------------------
5979 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5982 Is_Package_Or_Generic_Package (Scope_Id)
5983 and then In_Open_Scopes (Scope_Id)
5984 and then not In_Package_Body (Scope_Id)
5985 and then not In_Private_Part (Scope_Id);
5986 end In_Visible_Part;
5988 --------------------------------
5989 -- Incomplete_Or_Private_View --
5990 --------------------------------
5992 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
5993 function Inspect_Decls
5995 Taft : Boolean := False) return Entity_Id;
5996 -- Check whether a declarative region contains the incomplete or private
6003 function Inspect_Decls
6005 Taft : Boolean := False) return Entity_Id
6011 Decl := First (Decls);
6012 while Present (Decl) loop
6016 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6017 Match := Defining_Identifier (Decl);
6021 if Nkind_In (Decl, N_Private_Extension_Declaration,
6022 N_Private_Type_Declaration)
6024 Match := Defining_Identifier (Decl);
6029 and then Present (Full_View (Match))
6030 and then Full_View (Match) = Typ
6045 -- Start of processing for Incomplete_Or_Partial_View
6048 -- Incomplete type case
6050 Prev := Current_Entity_In_Scope (Typ);
6053 and then Is_Incomplete_Type (Prev)
6054 and then Present (Full_View (Prev))
6055 and then Full_View (Prev) = Typ
6060 -- Private or Taft amendment type case
6063 Pkg : constant Entity_Id := Scope (Typ);
6064 Pkg_Decl : Node_Id := Pkg;
6067 if Ekind (Pkg) = E_Package then
6068 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6069 Pkg_Decl := Parent (Pkg_Decl);
6072 -- It is knows that Typ has a private view, look for it in the
6073 -- visible declarations of the enclosing scope. A special case
6074 -- of this is when the two views have been exchanged - the full
6075 -- appears earlier than the private.
6077 if Has_Private_Declaration (Typ) then
6078 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6080 -- Exchanged view case, look in the private declarations
6083 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6088 -- Otherwise if this is the package body, then Typ is a potential
6089 -- Taft amendment type. The incomplete view should be located in
6090 -- the private declarations of the enclosing scope.
6092 elsif In_Package_Body (Pkg) then
6093 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6098 -- The type has no incomplete or private view
6101 end Incomplete_Or_Private_View;
6103 ---------------------------------
6104 -- Insert_Explicit_Dereference --
6105 ---------------------------------
6107 procedure Insert_Explicit_Dereference (N : Node_Id) is
6108 New_Prefix : constant Node_Id := Relocate_Node (N);
6109 Ent : Entity_Id := Empty;
6116 Save_Interps (N, New_Prefix);
6119 Make_Explicit_Dereference (Sloc (Parent (N)),
6120 Prefix => New_Prefix));
6122 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6124 if Is_Overloaded (New_Prefix) then
6126 -- The dereference is also overloaded, and its interpretations are
6127 -- the designated types of the interpretations of the original node.
6129 Set_Etype (N, Any_Type);
6131 Get_First_Interp (New_Prefix, I, It);
6132 while Present (It.Nam) loop
6135 if Is_Access_Type (T) then
6136 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6139 Get_Next_Interp (I, It);
6145 -- Prefix is unambiguous: mark the original prefix (which might
6146 -- Come_From_Source) as a reference, since the new (relocated) one
6147 -- won't be taken into account.
6149 if Is_Entity_Name (New_Prefix) then
6150 Ent := Entity (New_Prefix);
6153 -- For a retrieval of a subcomponent of some composite object,
6154 -- retrieve the ultimate entity if there is one.
6156 elsif Nkind (New_Prefix) = N_Selected_Component
6157 or else Nkind (New_Prefix) = N_Indexed_Component
6159 Pref := Prefix (New_Prefix);
6160 while Present (Pref)
6162 (Nkind (Pref) = N_Selected_Component
6163 or else Nkind (Pref) = N_Indexed_Component)
6165 Pref := Prefix (Pref);
6168 if Present (Pref) and then Is_Entity_Name (Pref) then
6169 Ent := Entity (Pref);
6173 -- Place the reference on the entity node
6175 if Present (Ent) then
6176 Generate_Reference (Ent, Pref);
6179 end Insert_Explicit_Dereference;
6181 ------------------------------------------
6182 -- Inspect_Deferred_Constant_Completion --
6183 ------------------------------------------
6185 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6189 Decl := First (Decls);
6190 while Present (Decl) loop
6192 -- Deferred constant signature
6194 if Nkind (Decl) = N_Object_Declaration
6195 and then Constant_Present (Decl)
6196 and then No (Expression (Decl))
6198 -- No need to check internally generated constants
6200 and then Comes_From_Source (Decl)
6202 -- The constant is not completed. A full object declaration or a
6203 -- pragma Import complete a deferred constant.
6205 and then not Has_Completion (Defining_Identifier (Decl))
6208 ("constant declaration requires initialization expression",
6209 Defining_Identifier (Decl));
6212 Decl := Next (Decl);
6214 end Inspect_Deferred_Constant_Completion;
6216 -----------------------------
6217 -- Is_Actual_Out_Parameter --
6218 -----------------------------
6220 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6224 Find_Actual (N, Formal, Call);
6225 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6226 end Is_Actual_Out_Parameter;
6228 -------------------------
6229 -- Is_Actual_Parameter --
6230 -------------------------
6232 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6233 PK : constant Node_Kind := Nkind (Parent (N));
6237 when N_Parameter_Association =>
6238 return N = Explicit_Actual_Parameter (Parent (N));
6240 when N_Function_Call | N_Procedure_Call_Statement =>
6241 return Is_List_Member (N)
6243 List_Containing (N) = Parameter_Associations (Parent (N));
6248 end Is_Actual_Parameter;
6250 --------------------------------
6251 -- Is_Actual_Tagged_Parameter --
6252 --------------------------------
6254 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6258 Find_Actual (N, Formal, Call);
6259 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6260 end Is_Actual_Tagged_Parameter;
6262 ---------------------
6263 -- Is_Aliased_View --
6264 ---------------------
6266 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6270 if Is_Entity_Name (Obj) then
6278 or else (Present (Renamed_Object (E))
6279 and then Is_Aliased_View (Renamed_Object (E)))))
6281 or else ((Is_Formal (E)
6282 or else Ekind (E) = E_Generic_In_Out_Parameter
6283 or else Ekind (E) = E_Generic_In_Parameter)
6284 and then Is_Tagged_Type (Etype (E)))
6286 or else (Is_Concurrent_Type (E)
6287 and then In_Open_Scopes (E))
6289 -- Current instance of type, either directly or as rewritten
6290 -- reference to the current object.
6292 or else (Is_Entity_Name (Original_Node (Obj))
6293 and then Present (Entity (Original_Node (Obj)))
6294 and then Is_Type (Entity (Original_Node (Obj))))
6296 or else (Is_Type (E) and then E = Current_Scope)
6298 or else (Is_Incomplete_Or_Private_Type (E)
6299 and then Full_View (E) = Current_Scope);
6301 elsif Nkind (Obj) = N_Selected_Component then
6302 return Is_Aliased (Entity (Selector_Name (Obj)));
6304 elsif Nkind (Obj) = N_Indexed_Component then
6305 return Has_Aliased_Components (Etype (Prefix (Obj)))
6307 (Is_Access_Type (Etype (Prefix (Obj)))
6309 Has_Aliased_Components
6310 (Designated_Type (Etype (Prefix (Obj)))));
6312 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6313 or else Nkind (Obj) = N_Type_Conversion
6315 return Is_Tagged_Type (Etype (Obj))
6316 and then Is_Aliased_View (Expression (Obj));
6318 elsif Nkind (Obj) = N_Explicit_Dereference then
6319 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6324 end Is_Aliased_View;
6326 -------------------------
6327 -- Is_Ancestor_Package --
6328 -------------------------
6330 function Is_Ancestor_Package
6332 E2 : Entity_Id) return Boolean
6339 and then Par /= Standard_Standard
6349 end Is_Ancestor_Package;
6351 ----------------------
6352 -- Is_Atomic_Object --
6353 ----------------------
6355 function Is_Atomic_Object (N : Node_Id) return Boolean is
6357 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6358 -- Determines if given object has atomic components
6360 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6361 -- If prefix is an implicit dereference, examine designated type
6363 ----------------------
6364 -- Is_Atomic_Prefix --
6365 ----------------------
6367 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6369 if Is_Access_Type (Etype (N)) then
6371 Has_Atomic_Components (Designated_Type (Etype (N)));
6373 return Object_Has_Atomic_Components (N);
6375 end Is_Atomic_Prefix;
6377 ----------------------------------
6378 -- Object_Has_Atomic_Components --
6379 ----------------------------------
6381 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6383 if Has_Atomic_Components (Etype (N))
6384 or else Is_Atomic (Etype (N))
6388 elsif Is_Entity_Name (N)
6389 and then (Has_Atomic_Components (Entity (N))
6390 or else Is_Atomic (Entity (N)))
6394 elsif Nkind (N) = N_Indexed_Component
6395 or else Nkind (N) = N_Selected_Component
6397 return Is_Atomic_Prefix (Prefix (N));
6402 end Object_Has_Atomic_Components;
6404 -- Start of processing for Is_Atomic_Object
6407 -- Predicate is not relevant to subprograms
6409 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6412 elsif Is_Atomic (Etype (N))
6413 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6417 elsif Nkind (N) = N_Indexed_Component
6418 or else Nkind (N) = N_Selected_Component
6420 return Is_Atomic_Prefix (Prefix (N));
6425 end Is_Atomic_Object;
6427 -----------------------------
6428 -- Is_Concurrent_Interface --
6429 -----------------------------
6431 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6436 (Is_Protected_Interface (T)
6437 or else Is_Synchronized_Interface (T)
6438 or else Is_Task_Interface (T));
6439 end Is_Concurrent_Interface;
6441 --------------------------------------
6442 -- Is_Controlling_Limited_Procedure --
6443 --------------------------------------
6445 function Is_Controlling_Limited_Procedure
6446 (Proc_Nam : Entity_Id) return Boolean
6448 Param_Typ : Entity_Id := Empty;
6451 if Ekind (Proc_Nam) = E_Procedure
6452 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6454 Param_Typ := Etype (Parameter_Type (First (
6455 Parameter_Specifications (Parent (Proc_Nam)))));
6457 -- In this case where an Itype was created, the procedure call has been
6460 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6461 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6463 Present (Parameter_Associations
6464 (Associated_Node_For_Itype (Proc_Nam)))
6467 Etype (First (Parameter_Associations
6468 (Associated_Node_For_Itype (Proc_Nam))));
6471 if Present (Param_Typ) then
6473 Is_Interface (Param_Typ)
6474 and then Is_Limited_Record (Param_Typ);
6478 end Is_Controlling_Limited_Procedure;
6480 -----------------------------
6481 -- Is_CPP_Constructor_Call --
6482 -----------------------------
6484 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6486 return Nkind (N) = N_Function_Call
6487 and then Is_CPP_Class (Etype (Etype (N)))
6488 and then Is_Constructor (Entity (Name (N)))
6489 and then Is_Imported (Entity (Name (N)));
6490 end Is_CPP_Constructor_Call;
6496 function Is_Delegate (T : Entity_Id) return Boolean is
6497 Desig_Type : Entity_Id;
6500 if VM_Target /= CLI_Target then
6504 -- Access-to-subprograms are delegates in CIL
6506 if Ekind (T) = E_Access_Subprogram_Type then
6510 if Ekind (T) not in Access_Kind then
6512 -- A delegate is a managed pointer. If no designated type is defined
6513 -- it means that it's not a delegate.
6518 Desig_Type := Etype (Directly_Designated_Type (T));
6520 if not Is_Tagged_Type (Desig_Type) then
6524 -- Test if the type is inherited from [mscorlib]System.Delegate
6526 while Etype (Desig_Type) /= Desig_Type loop
6527 if Chars (Scope (Desig_Type)) /= No_Name
6528 and then Is_Imported (Scope (Desig_Type))
6529 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6534 Desig_Type := Etype (Desig_Type);
6540 ----------------------------------------------
6541 -- Is_Dependent_Component_Of_Mutable_Object --
6542 ----------------------------------------------
6544 function Is_Dependent_Component_Of_Mutable_Object
6545 (Object : Node_Id) return Boolean
6548 Prefix_Type : Entity_Id;
6549 P_Aliased : Boolean := False;
6552 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6553 -- Returns True if and only if Comp is declared within a variant part
6555 --------------------------------
6556 -- Is_Declared_Within_Variant --
6557 --------------------------------
6559 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6560 Comp_Decl : constant Node_Id := Parent (Comp);
6561 Comp_List : constant Node_Id := Parent (Comp_Decl);
6563 return Nkind (Parent (Comp_List)) = N_Variant;
6564 end Is_Declared_Within_Variant;
6566 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6569 if Is_Variable (Object) then
6571 if Nkind (Object) = N_Selected_Component then
6572 P := Prefix (Object);
6573 Prefix_Type := Etype (P);
6575 if Is_Entity_Name (P) then
6577 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6578 Prefix_Type := Base_Type (Prefix_Type);
6581 if Is_Aliased (Entity (P)) then
6585 -- A discriminant check on a selected component may be expanded
6586 -- into a dereference when removing side-effects. Recover the
6587 -- original node and its type, which may be unconstrained.
6589 elsif Nkind (P) = N_Explicit_Dereference
6590 and then not (Comes_From_Source (P))
6592 P := Original_Node (P);
6593 Prefix_Type := Etype (P);
6596 -- Check for prefix being an aliased component???
6602 -- A heap object is constrained by its initial value
6604 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6605 -- the dereferenced case, since the access value might denote an
6606 -- unconstrained aliased object, whereas in Ada 95 the designated
6607 -- object is guaranteed to be constrained. A worst-case assumption
6608 -- has to apply in Ada 2005 because we can't tell at compile time
6609 -- whether the object is "constrained by its initial value"
6610 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6611 -- semantic rules -- these rules are acknowledged to need fixing).
6613 if Ada_Version < Ada_2005 then
6614 if Is_Access_Type (Prefix_Type)
6615 or else Nkind (P) = N_Explicit_Dereference
6620 elsif Ada_Version >= Ada_2005 then
6621 if Is_Access_Type (Prefix_Type) then
6623 -- If the access type is pool-specific, and there is no
6624 -- constrained partial view of the designated type, then the
6625 -- designated object is known to be constrained.
6627 if Ekind (Prefix_Type) = E_Access_Type
6628 and then not Has_Constrained_Partial_View
6629 (Designated_Type (Prefix_Type))
6633 -- Otherwise (general access type, or there is a constrained
6634 -- partial view of the designated type), we need to check
6635 -- based on the designated type.
6638 Prefix_Type := Designated_Type (Prefix_Type);
6644 Original_Record_Component (Entity (Selector_Name (Object)));
6646 -- As per AI-0017, the renaming is illegal in a generic body, even
6647 -- if the subtype is indefinite.
6649 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6651 if not Is_Constrained (Prefix_Type)
6652 and then (not Is_Indefinite_Subtype (Prefix_Type)
6654 (Is_Generic_Type (Prefix_Type)
6655 and then Ekind (Current_Scope) = E_Generic_Package
6656 and then In_Package_Body (Current_Scope)))
6658 and then (Is_Declared_Within_Variant (Comp)
6659 or else Has_Discriminant_Dependent_Constraint (Comp))
6660 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6666 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6670 elsif Nkind (Object) = N_Indexed_Component
6671 or else Nkind (Object) = N_Slice
6673 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6675 -- A type conversion that Is_Variable is a view conversion:
6676 -- go back to the denoted object.
6678 elsif Nkind (Object) = N_Type_Conversion then
6680 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6685 end Is_Dependent_Component_Of_Mutable_Object;
6687 ---------------------
6688 -- Is_Dereferenced --
6689 ---------------------
6691 function Is_Dereferenced (N : Node_Id) return Boolean is
6692 P : constant Node_Id := Parent (N);
6695 (Nkind (P) = N_Selected_Component
6697 Nkind (P) = N_Explicit_Dereference
6699 Nkind (P) = N_Indexed_Component
6701 Nkind (P) = N_Slice)
6702 and then Prefix (P) = N;
6703 end Is_Dereferenced;
6705 ----------------------
6706 -- Is_Descendent_Of --
6707 ----------------------
6709 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6714 pragma Assert (Nkind (T1) in N_Entity);
6715 pragma Assert (Nkind (T2) in N_Entity);
6717 T := Base_Type (T1);
6719 -- Immediate return if the types match
6724 -- Comment needed here ???
6726 elsif Ekind (T) = E_Class_Wide_Type then
6727 return Etype (T) = T2;
6735 -- Done if we found the type we are looking for
6740 -- Done if no more derivations to check
6747 -- Following test catches error cases resulting from prev errors
6749 elsif No (Etyp) then
6752 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6755 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6759 T := Base_Type (Etyp);
6762 end Is_Descendent_Of;
6764 ----------------------------
6765 -- Is_Expression_Function --
6766 ----------------------------
6768 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6769 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6772 return Ekind (Subp) = E_Function
6773 and then Nkind (Decl) = N_Subprogram_Declaration
6775 (Nkind (Original_Node (Decl)) = N_Expression_Function
6777 (Present (Corresponding_Body (Decl))
6779 Nkind (Original_Node
6780 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6781 = N_Expression_Function));
6782 end Is_Expression_Function;
6788 function Is_False (U : Uint) return Boolean is
6793 ---------------------------
6794 -- Is_Fixed_Model_Number --
6795 ---------------------------
6797 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6798 S : constant Ureal := Small_Value (T);
6799 M : Urealp.Save_Mark;
6803 R := (U = UR_Trunc (U / S) * S);
6806 end Is_Fixed_Model_Number;
6808 -------------------------------
6809 -- Is_Fully_Initialized_Type --
6810 -------------------------------
6812 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6814 if Is_Scalar_Type (Typ) then
6817 elsif Is_Access_Type (Typ) then
6820 elsif Is_Array_Type (Typ) then
6821 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6825 -- An interesting case, if we have a constrained type one of whose
6826 -- bounds is known to be null, then there are no elements to be
6827 -- initialized, so all the elements are initialized!
6829 if Is_Constrained (Typ) then
6832 Indx_Typ : Entity_Id;
6836 Indx := First_Index (Typ);
6837 while Present (Indx) loop
6838 if Etype (Indx) = Any_Type then
6841 -- If index is a range, use directly
6843 elsif Nkind (Indx) = N_Range then
6844 Lbd := Low_Bound (Indx);
6845 Hbd := High_Bound (Indx);
6848 Indx_Typ := Etype (Indx);
6850 if Is_Private_Type (Indx_Typ) then
6851 Indx_Typ := Full_View (Indx_Typ);
6854 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6857 Lbd := Type_Low_Bound (Indx_Typ);
6858 Hbd := Type_High_Bound (Indx_Typ);
6862 if Compile_Time_Known_Value (Lbd)
6863 and then Compile_Time_Known_Value (Hbd)
6865 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6875 -- If no null indexes, then type is not fully initialized
6881 elsif Is_Record_Type (Typ) then
6882 if Has_Discriminants (Typ)
6884 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6885 and then Is_Fully_Initialized_Variant (Typ)
6890 -- Controlled records are considered to be fully initialized if
6891 -- there is a user defined Initialize routine. This may not be
6892 -- entirely correct, but as the spec notes, we are guessing here
6893 -- what is best from the point of view of issuing warnings.
6895 if Is_Controlled (Typ) then
6897 Utyp : constant Entity_Id := Underlying_Type (Typ);
6900 if Present (Utyp) then
6902 Init : constant Entity_Id :=
6904 (Underlying_Type (Typ), Name_Initialize));
6908 and then Comes_From_Source (Init)
6910 Is_Predefined_File_Name
6911 (File_Name (Get_Source_File_Index (Sloc (Init))))
6915 elsif Has_Null_Extension (Typ)
6917 Is_Fully_Initialized_Type
6918 (Etype (Base_Type (Typ)))
6927 -- Otherwise see if all record components are initialized
6933 Ent := First_Entity (Typ);
6934 while Present (Ent) loop
6935 if Ekind (Ent) = E_Component
6936 and then (No (Parent (Ent))
6937 or else No (Expression (Parent (Ent))))
6938 and then not Is_Fully_Initialized_Type (Etype (Ent))
6940 -- Special VM case for tag components, which need to be
6941 -- defined in this case, but are never initialized as VMs
6942 -- are using other dispatching mechanisms. Ignore this
6943 -- uninitialized case. Note that this applies both to the
6944 -- uTag entry and the main vtable pointer (CPP_Class case).
6946 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6955 -- No uninitialized components, so type is fully initialized.
6956 -- Note that this catches the case of no components as well.
6960 elsif Is_Concurrent_Type (Typ) then
6963 elsif Is_Private_Type (Typ) then
6965 U : constant Entity_Id := Underlying_Type (Typ);
6971 return Is_Fully_Initialized_Type (U);
6978 end Is_Fully_Initialized_Type;
6980 ----------------------------------
6981 -- Is_Fully_Initialized_Variant --
6982 ----------------------------------
6984 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6985 Loc : constant Source_Ptr := Sloc (Typ);
6986 Constraints : constant List_Id := New_List;
6987 Components : constant Elist_Id := New_Elmt_List;
6988 Comp_Elmt : Elmt_Id;
6990 Comp_List : Node_Id;
6992 Discr_Val : Node_Id;
6994 Report_Errors : Boolean;
6995 pragma Warnings (Off, Report_Errors);
6998 if Serious_Errors_Detected > 0 then
7002 if Is_Record_Type (Typ)
7003 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
7004 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
7006 Comp_List := Component_List (Type_Definition (Parent (Typ)));
7008 Discr := First_Discriminant (Typ);
7009 while Present (Discr) loop
7010 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
7011 Discr_Val := Expression (Parent (Discr));
7013 if Present (Discr_Val)
7014 and then Is_OK_Static_Expression (Discr_Val)
7016 Append_To (Constraints,
7017 Make_Component_Association (Loc,
7018 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7019 Expression => New_Copy (Discr_Val)));
7027 Next_Discriminant (Discr);
7032 Comp_List => Comp_List,
7033 Governed_By => Constraints,
7035 Report_Errors => Report_Errors);
7037 -- Check that each component present is fully initialized
7039 Comp_Elmt := First_Elmt (Components);
7040 while Present (Comp_Elmt) loop
7041 Comp_Id := Node (Comp_Elmt);
7043 if Ekind (Comp_Id) = E_Component
7044 and then (No (Parent (Comp_Id))
7045 or else No (Expression (Parent (Comp_Id))))
7046 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7051 Next_Elmt (Comp_Elmt);
7056 elsif Is_Private_Type (Typ) then
7058 U : constant Entity_Id := Underlying_Type (Typ);
7064 return Is_Fully_Initialized_Variant (U);
7070 end Is_Fully_Initialized_Variant;
7076 -- We seem to have a lot of overlapping functions that do similar things
7077 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7078 -- purely syntactic, it should be in Sem_Aux I would think???
7080 function Is_LHS (N : Node_Id) return Boolean is
7081 P : constant Node_Id := Parent (N);
7084 if Nkind (P) = N_Assignment_Statement then
7085 return Name (P) = N;
7088 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7090 return N = Prefix (P) and then Is_LHS (P);
7097 ----------------------------
7098 -- Is_Inherited_Operation --
7099 ----------------------------
7101 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7102 Kind : constant Node_Kind := Nkind (Parent (E));
7104 pragma Assert (Is_Overloadable (E));
7105 return Kind = N_Full_Type_Declaration
7106 or else Kind = N_Private_Extension_Declaration
7107 or else Kind = N_Subtype_Declaration
7108 or else (Ekind (E) = E_Enumeration_Literal
7109 and then Is_Derived_Type (Etype (E)));
7110 end Is_Inherited_Operation;
7112 -------------------------------------
7113 -- Is_Inherited_Operation_For_Type --
7114 -------------------------------------
7116 function Is_Inherited_Operation_For_Type
7117 (E : Entity_Id; Typ : Entity_Id) return Boolean
7120 return Is_Inherited_Operation (E)
7121 and then Etype (Parent (E)) = Typ;
7122 end Is_Inherited_Operation_For_Type;
7124 -----------------------------
7125 -- Is_Library_Level_Entity --
7126 -----------------------------
7128 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7130 -- The following is a small optimization, and it also properly handles
7131 -- discriminals, which in task bodies might appear in expressions before
7132 -- the corresponding procedure has been created, and which therefore do
7133 -- not have an assigned scope.
7135 if Is_Formal (E) then
7139 -- Normal test is simply that the enclosing dynamic scope is Standard
7141 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7142 end Is_Library_Level_Entity;
7144 ---------------------------------
7145 -- Is_Local_Variable_Reference --
7146 ---------------------------------
7148 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7150 if not Is_Entity_Name (Expr) then
7155 Ent : constant Entity_Id := Entity (Expr);
7156 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7158 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7161 return Present (Sub) and then Sub = Current_Subprogram;
7165 end Is_Local_Variable_Reference;
7167 -------------------------
7168 -- Is_Object_Reference --
7169 -------------------------
7171 function Is_Object_Reference (N : Node_Id) return Boolean is
7173 if Is_Entity_Name (N) then
7174 return Present (Entity (N)) and then Is_Object (Entity (N));
7178 when N_Indexed_Component | N_Slice =>
7180 Is_Object_Reference (Prefix (N))
7181 or else Is_Access_Type (Etype (Prefix (N)));
7183 -- In Ada95, a function call is a constant object; a procedure
7186 when N_Function_Call =>
7187 return Etype (N) /= Standard_Void_Type;
7189 -- A reference to the stream attribute Input is a function call
7191 when N_Attribute_Reference =>
7192 return Attribute_Name (N) = Name_Input;
7194 when N_Selected_Component =>
7196 Is_Object_Reference (Selector_Name (N))
7198 (Is_Object_Reference (Prefix (N))
7199 or else Is_Access_Type (Etype (Prefix (N))));
7201 when N_Explicit_Dereference =>
7204 -- A view conversion of a tagged object is an object reference
7206 when N_Type_Conversion =>
7207 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7208 and then Is_Tagged_Type (Etype (Expression (N)))
7209 and then Is_Object_Reference (Expression (N));
7211 -- An unchecked type conversion is considered to be an object if
7212 -- the operand is an object (this construction arises only as a
7213 -- result of expansion activities).
7215 when N_Unchecked_Type_Conversion =>
7222 end Is_Object_Reference;
7224 -----------------------------------
7225 -- Is_OK_Variable_For_Out_Formal --
7226 -----------------------------------
7228 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7230 Note_Possible_Modification (AV, Sure => True);
7232 -- We must reject parenthesized variable names. The check for
7233 -- Comes_From_Source is present because there are currently
7234 -- cases where the compiler violates this rule (e.g. passing
7235 -- a task object to its controlled Initialize routine).
7237 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7240 -- A variable is always allowed
7242 elsif Is_Variable (AV) then
7245 -- Unchecked conversions are allowed only if they come from the
7246 -- generated code, which sometimes uses unchecked conversions for out
7247 -- parameters in cases where code generation is unaffected. We tell
7248 -- source unchecked conversions by seeing if they are rewrites of an
7249 -- original Unchecked_Conversion function call, or of an explicit
7250 -- conversion of a function call.
7252 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7253 if Nkind (Original_Node (AV)) = N_Function_Call then
7256 elsif Comes_From_Source (AV)
7257 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7261 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7262 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7268 -- Normal type conversions are allowed if argument is a variable
7270 elsif Nkind (AV) = N_Type_Conversion then
7271 if Is_Variable (Expression (AV))
7272 and then Paren_Count (Expression (AV)) = 0
7274 Note_Possible_Modification (Expression (AV), Sure => True);
7277 -- We also allow a non-parenthesized expression that raises
7278 -- constraint error if it rewrites what used to be a variable
7280 elsif Raises_Constraint_Error (Expression (AV))
7281 and then Paren_Count (Expression (AV)) = 0
7282 and then Is_Variable (Original_Node (Expression (AV)))
7286 -- Type conversion of something other than a variable
7292 -- If this node is rewritten, then test the original form, if that is
7293 -- OK, then we consider the rewritten node OK (for example, if the
7294 -- original node is a conversion, then Is_Variable will not be true
7295 -- but we still want to allow the conversion if it converts a variable).
7297 elsif Original_Node (AV) /= AV then
7298 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7300 -- All other non-variables are rejected
7305 end Is_OK_Variable_For_Out_Formal;
7307 -----------------------------------
7308 -- Is_Partially_Initialized_Type --
7309 -----------------------------------
7311 function Is_Partially_Initialized_Type
7313 Include_Implicit : Boolean := True) return Boolean
7316 if Is_Scalar_Type (Typ) then
7319 elsif Is_Access_Type (Typ) then
7320 return Include_Implicit;
7322 elsif Is_Array_Type (Typ) then
7324 -- If component type is partially initialized, so is array type
7326 if Is_Partially_Initialized_Type
7327 (Component_Type (Typ), Include_Implicit)
7331 -- Otherwise we are only partially initialized if we are fully
7332 -- initialized (this is the empty array case, no point in us
7333 -- duplicating that code here).
7336 return Is_Fully_Initialized_Type (Typ);
7339 elsif Is_Record_Type (Typ) then
7341 -- A discriminated type is always partially initialized if in
7344 if Has_Discriminants (Typ) and then Include_Implicit then
7347 -- A tagged type is always partially initialized
7349 elsif Is_Tagged_Type (Typ) then
7352 -- Case of non-discriminated record
7358 Component_Present : Boolean := False;
7359 -- Set True if at least one component is present. If no
7360 -- components are present, then record type is fully
7361 -- initialized (another odd case, like the null array).
7364 -- Loop through components
7366 Ent := First_Entity (Typ);
7367 while Present (Ent) loop
7368 if Ekind (Ent) = E_Component then
7369 Component_Present := True;
7371 -- If a component has an initialization expression then
7372 -- the enclosing record type is partially initialized
7374 if Present (Parent (Ent))
7375 and then Present (Expression (Parent (Ent)))
7379 -- If a component is of a type which is itself partially
7380 -- initialized, then the enclosing record type is also.
7382 elsif Is_Partially_Initialized_Type
7383 (Etype (Ent), Include_Implicit)
7392 -- No initialized components found. If we found any components
7393 -- they were all uninitialized so the result is false.
7395 if Component_Present then
7398 -- But if we found no components, then all the components are
7399 -- initialized so we consider the type to be initialized.
7407 -- Concurrent types are always fully initialized
7409 elsif Is_Concurrent_Type (Typ) then
7412 -- For a private type, go to underlying type. If there is no underlying
7413 -- type then just assume this partially initialized. Not clear if this
7414 -- can happen in a non-error case, but no harm in testing for this.
7416 elsif Is_Private_Type (Typ) then
7418 U : constant Entity_Id := Underlying_Type (Typ);
7423 return Is_Partially_Initialized_Type (U, Include_Implicit);
7427 -- For any other type (are there any?) assume partially initialized
7432 end Is_Partially_Initialized_Type;
7434 ------------------------------------
7435 -- Is_Potentially_Persistent_Type --
7436 ------------------------------------
7438 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7443 -- For private type, test corresponding full type
7445 if Is_Private_Type (T) then
7446 return Is_Potentially_Persistent_Type (Full_View (T));
7448 -- Scalar types are potentially persistent
7450 elsif Is_Scalar_Type (T) then
7453 -- Record type is potentially persistent if not tagged and the types of
7454 -- all it components are potentially persistent, and no component has
7455 -- an initialization expression.
7457 elsif Is_Record_Type (T)
7458 and then not Is_Tagged_Type (T)
7459 and then not Is_Partially_Initialized_Type (T)
7461 Comp := First_Component (T);
7462 while Present (Comp) loop
7463 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7472 -- Array type is potentially persistent if its component type is
7473 -- potentially persistent and if all its constraints are static.
7475 elsif Is_Array_Type (T) then
7476 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7480 Indx := First_Index (T);
7481 while Present (Indx) loop
7482 if not Is_OK_Static_Subtype (Etype (Indx)) then
7491 -- All other types are not potentially persistent
7496 end Is_Potentially_Persistent_Type;
7498 ---------------------------------
7499 -- Is_Protected_Self_Reference --
7500 ---------------------------------
7502 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7504 function In_Access_Definition (N : Node_Id) return Boolean;
7505 -- Returns true if N belongs to an access definition
7507 --------------------------
7508 -- In_Access_Definition --
7509 --------------------------
7511 function In_Access_Definition (N : Node_Id) return Boolean is
7516 while Present (P) loop
7517 if Nkind (P) = N_Access_Definition then
7525 end In_Access_Definition;
7527 -- Start of processing for Is_Protected_Self_Reference
7530 -- Verify that prefix is analyzed and has the proper form. Note that
7531 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7532 -- produce the address of an entity, do not analyze their prefix
7533 -- because they denote entities that are not necessarily visible.
7534 -- Neither of them can apply to a protected type.
7536 return Ada_Version >= Ada_2005
7537 and then Is_Entity_Name (N)
7538 and then Present (Entity (N))
7539 and then Is_Protected_Type (Entity (N))
7540 and then In_Open_Scopes (Entity (N))
7541 and then not In_Access_Definition (N);
7542 end Is_Protected_Self_Reference;
7544 -----------------------------
7545 -- Is_RCI_Pkg_Spec_Or_Body --
7546 -----------------------------
7548 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7550 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7551 -- Return True if the unit of Cunit is an RCI package declaration
7553 ---------------------------
7554 -- Is_RCI_Pkg_Decl_Cunit --
7555 ---------------------------
7557 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7558 The_Unit : constant Node_Id := Unit (Cunit);
7561 if Nkind (The_Unit) /= N_Package_Declaration then
7565 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7566 end Is_RCI_Pkg_Decl_Cunit;
7568 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7571 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7573 (Nkind (Unit (Cunit)) = N_Package_Body
7574 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7575 end Is_RCI_Pkg_Spec_Or_Body;
7577 -----------------------------------------
7578 -- Is_Remote_Access_To_Class_Wide_Type --
7579 -----------------------------------------
7581 function Is_Remote_Access_To_Class_Wide_Type
7582 (E : Entity_Id) return Boolean
7585 -- A remote access to class-wide type is a general access to object type
7586 -- declared in the visible part of a Remote_Types or Remote_Call_
7589 return Ekind (E) = E_General_Access_Type
7590 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7591 end Is_Remote_Access_To_Class_Wide_Type;
7593 -----------------------------------------
7594 -- Is_Remote_Access_To_Subprogram_Type --
7595 -----------------------------------------
7597 function Is_Remote_Access_To_Subprogram_Type
7598 (E : Entity_Id) return Boolean
7601 return (Ekind (E) = E_Access_Subprogram_Type
7602 or else (Ekind (E) = E_Record_Type
7603 and then Present (Corresponding_Remote_Type (E))))
7604 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7605 end Is_Remote_Access_To_Subprogram_Type;
7607 --------------------
7608 -- Is_Remote_Call --
7609 --------------------
7611 function Is_Remote_Call (N : Node_Id) return Boolean is
7613 if Nkind (N) /= N_Procedure_Call_Statement
7614 and then Nkind (N) /= N_Function_Call
7616 -- An entry call cannot be remote
7620 elsif Nkind (Name (N)) in N_Has_Entity
7621 and then Is_Remote_Call_Interface (Entity (Name (N)))
7623 -- A subprogram declared in the spec of a RCI package is remote
7627 elsif Nkind (Name (N)) = N_Explicit_Dereference
7628 and then Is_Remote_Access_To_Subprogram_Type
7629 (Etype (Prefix (Name (N))))
7631 -- The dereference of a RAS is a remote call
7635 elsif Present (Controlling_Argument (N))
7636 and then Is_Remote_Access_To_Class_Wide_Type
7637 (Etype (Controlling_Argument (N)))
7639 -- Any primitive operation call with a controlling argument of
7640 -- a RACW type is a remote call.
7645 -- All other calls are local calls
7650 ----------------------
7651 -- Is_Renamed_Entry --
7652 ----------------------
7654 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7655 Orig_Node : Node_Id := Empty;
7656 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7658 function Is_Entry (Nam : Node_Id) return Boolean;
7659 -- Determine whether Nam is an entry. Traverse selectors if there are
7660 -- nested selected components.
7666 function Is_Entry (Nam : Node_Id) return Boolean is
7668 if Nkind (Nam) = N_Selected_Component then
7669 return Is_Entry (Selector_Name (Nam));
7672 return Ekind (Entity (Nam)) = E_Entry;
7675 -- Start of processing for Is_Renamed_Entry
7678 if Present (Alias (Proc_Nam)) then
7679 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7682 -- Look for a rewritten subprogram renaming declaration
7684 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7685 and then Present (Original_Node (Subp_Decl))
7687 Orig_Node := Original_Node (Subp_Decl);
7690 -- The rewritten subprogram is actually an entry
7692 if Present (Orig_Node)
7693 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7694 and then Is_Entry (Name (Orig_Node))
7700 end Is_Renamed_Entry;
7702 ----------------------
7703 -- Is_Selector_Name --
7704 ----------------------
7706 function Is_Selector_Name (N : Node_Id) return Boolean is
7708 if not Is_List_Member (N) then
7710 P : constant Node_Id := Parent (N);
7711 K : constant Node_Kind := Nkind (P);
7714 (K = N_Expanded_Name or else
7715 K = N_Generic_Association or else
7716 K = N_Parameter_Association or else
7717 K = N_Selected_Component)
7718 and then Selector_Name (P) = N;
7723 L : constant List_Id := List_Containing (N);
7724 P : constant Node_Id := Parent (L);
7726 return (Nkind (P) = N_Discriminant_Association
7727 and then Selector_Names (P) = L)
7729 (Nkind (P) = N_Component_Association
7730 and then Choices (P) = L);
7733 end Is_Selector_Name;
7735 ----------------------------------
7736 -- Is_SPARK_Initialization_Expr --
7737 ----------------------------------
7739 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7742 Comp_Assn : Node_Id;
7743 Orig_N : constant Node_Id := Original_Node (N);
7748 if not Comes_From_Source (Orig_N) then
7752 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7754 case Nkind (Orig_N) is
7755 when N_Character_Literal |
7763 if Is_Entity_Name (Orig_N)
7764 and then Present (Entity (Orig_N)) -- needed in some cases
7766 case Ekind (Entity (Orig_N)) is
7768 E_Enumeration_Literal |
7773 if Is_Type (Entity (Orig_N)) then
7781 when N_Qualified_Expression |
7782 N_Type_Conversion =>
7783 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7786 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7790 N_Membership_Test =>
7791 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7792 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7795 N_Extension_Aggregate =>
7796 if Nkind (Orig_N) = N_Extension_Aggregate then
7797 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7800 Expr := First (Expressions (Orig_N));
7801 while Present (Expr) loop
7802 if not Is_SPARK_Initialization_Expr (Expr) then
7810 Comp_Assn := First (Component_Associations (Orig_N));
7811 while Present (Comp_Assn) loop
7812 Expr := Expression (Comp_Assn);
7813 if Present (Expr) -- needed for box association
7814 and then not Is_SPARK_Initialization_Expr (Expr)
7823 when N_Attribute_Reference =>
7824 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7825 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7828 Expr := First (Expressions (Orig_N));
7829 while Present (Expr) loop
7830 if not Is_SPARK_Initialization_Expr (Expr) then
7838 -- Selected components might be expanded named not yet resolved, so
7839 -- default on the safe side. (Eg on sparklex.ads)
7841 when N_Selected_Component =>
7850 end Is_SPARK_Initialization_Expr;
7852 -------------------------------
7853 -- Is_SPARK_Object_Reference --
7854 -------------------------------
7856 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7858 if Is_Entity_Name (N) then
7859 return Present (Entity (N))
7861 (Ekind_In (Entity (N), E_Constant, E_Variable)
7862 or else Ekind (Entity (N)) in Formal_Kind);
7866 when N_Selected_Component =>
7867 return Is_SPARK_Object_Reference (Prefix (N));
7873 end Is_SPARK_Object_Reference;
7879 function Is_Statement (N : Node_Id) return Boolean is
7882 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7883 or else Nkind (N) = N_Procedure_Call_Statement;
7886 ---------------------------------
7887 -- Is_Synchronized_Tagged_Type --
7888 ---------------------------------
7890 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7891 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7894 -- A task or protected type derived from an interface is a tagged type.
7895 -- Such a tagged type is called a synchronized tagged type, as are
7896 -- synchronized interfaces and private extensions whose declaration
7897 -- includes the reserved word synchronized.
7899 return (Is_Tagged_Type (E)
7900 and then (Kind = E_Task_Type
7901 or else Kind = E_Protected_Type))
7904 and then Is_Synchronized_Interface (E))
7906 (Ekind (E) = E_Record_Type_With_Private
7907 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7908 and then (Synchronized_Present (Parent (E))
7909 or else Is_Synchronized_Interface (Etype (E))));
7910 end Is_Synchronized_Tagged_Type;
7916 function Is_Transfer (N : Node_Id) return Boolean is
7917 Kind : constant Node_Kind := Nkind (N);
7920 if Kind = N_Simple_Return_Statement
7922 Kind = N_Extended_Return_Statement
7924 Kind = N_Goto_Statement
7926 Kind = N_Raise_Statement
7928 Kind = N_Requeue_Statement
7932 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7933 and then No (Condition (N))
7937 elsif Kind = N_Procedure_Call_Statement
7938 and then Is_Entity_Name (Name (N))
7939 and then Present (Entity (Name (N)))
7940 and then No_Return (Entity (Name (N)))
7944 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7956 function Is_True (U : Uint) return Boolean is
7961 -------------------------------
7962 -- Is_Universal_Numeric_Type --
7963 -------------------------------
7965 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7967 return T = Universal_Integer or else T = Universal_Real;
7968 end Is_Universal_Numeric_Type;
7974 function Is_Value_Type (T : Entity_Id) return Boolean is
7976 return VM_Target = CLI_Target
7977 and then Nkind (T) in N_Has_Chars
7978 and then Chars (T) /= No_Name
7979 and then Get_Name_String (Chars (T)) = "valuetype";
7982 ---------------------
7983 -- Is_VMS_Operator --
7984 ---------------------
7986 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7988 -- The VMS operators are declared in a child of System that is loaded
7989 -- through pragma Extend_System. In some rare cases a program is run
7990 -- with this extension but without indicating that the target is VMS.
7992 return Ekind (Op) = E_Function
7993 and then Is_Intrinsic_Subprogram (Op)
7995 ((Present_System_Aux
7996 and then Scope (Op) = System_Aux_Id)
7999 and then Scope (Scope (Op)) = RTU_Entity (System)));
8000 end Is_VMS_Operator;
8006 function Is_Variable
8008 Use_Original_Node : Boolean := True) return Boolean
8010 Orig_Node : Node_Id;
8012 function In_Protected_Function (E : Entity_Id) return Boolean;
8013 -- Within a protected function, the private components of the enclosing
8014 -- protected type are constants. A function nested within a (protected)
8015 -- procedure is not itself protected.
8017 function Is_Variable_Prefix (P : Node_Id) return Boolean;
8018 -- Prefixes can involve implicit dereferences, in which case we must
8019 -- test for the case of a reference of a constant access type, which can
8020 -- can never be a variable.
8022 ---------------------------
8023 -- In_Protected_Function --
8024 ---------------------------
8026 function In_Protected_Function (E : Entity_Id) return Boolean is
8027 Prot : constant Entity_Id := Scope (E);
8031 if not Is_Protected_Type (Prot) then
8035 while Present (S) and then S /= Prot loop
8036 if Ekind (S) = E_Function and then Scope (S) = Prot then
8045 end In_Protected_Function;
8047 ------------------------
8048 -- Is_Variable_Prefix --
8049 ------------------------
8051 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8053 if Is_Access_Type (Etype (P)) then
8054 return not Is_Access_Constant (Root_Type (Etype (P)));
8056 -- For the case of an indexed component whose prefix has a packed
8057 -- array type, the prefix has been rewritten into a type conversion.
8058 -- Determine variable-ness from the converted expression.
8060 elsif Nkind (P) = N_Type_Conversion
8061 and then not Comes_From_Source (P)
8062 and then Is_Array_Type (Etype (P))
8063 and then Is_Packed (Etype (P))
8065 return Is_Variable (Expression (P));
8068 return Is_Variable (P);
8070 end Is_Variable_Prefix;
8072 -- Start of processing for Is_Variable
8075 -- Check if we perform the test on the original node since this may be a
8076 -- test of syntactic categories which must not be disturbed by whatever
8077 -- rewriting might have occurred. For example, an aggregate, which is
8078 -- certainly NOT a variable, could be turned into a variable by
8081 if Use_Original_Node then
8082 Orig_Node := Original_Node (N);
8087 -- Definitely OK if Assignment_OK is set. Since this is something that
8088 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8090 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8093 -- Normally we go to the original node, but there is one exception where
8094 -- we use the rewritten node, namely when it is an explicit dereference.
8095 -- The generated code may rewrite a prefix which is an access type with
8096 -- an explicit dereference. The dereference is a variable, even though
8097 -- the original node may not be (since it could be a constant of the
8100 -- In Ada 2005 we have a further case to consider: the prefix may be a
8101 -- function call given in prefix notation. The original node appears to
8102 -- be a selected component, but we need to examine the call.
8104 elsif Nkind (N) = N_Explicit_Dereference
8105 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8106 and then Present (Etype (Orig_Node))
8107 and then Is_Access_Type (Etype (Orig_Node))
8109 -- Note that if the prefix is an explicit dereference that does not
8110 -- come from source, we must check for a rewritten function call in
8111 -- prefixed notation before other forms of rewriting, to prevent a
8115 (Nkind (Orig_Node) = N_Function_Call
8116 and then not Is_Access_Constant (Etype (Prefix (N))))
8118 Is_Variable_Prefix (Original_Node (Prefix (N)));
8120 -- A function call is never a variable
8122 elsif Nkind (N) = N_Function_Call then
8125 -- All remaining checks use the original node
8127 elsif Is_Entity_Name (Orig_Node)
8128 and then Present (Entity (Orig_Node))
8131 E : constant Entity_Id := Entity (Orig_Node);
8132 K : constant Entity_Kind := Ekind (E);
8135 return (K = E_Variable
8136 and then Nkind (Parent (E)) /= N_Exception_Handler)
8137 or else (K = E_Component
8138 and then not In_Protected_Function (E))
8139 or else K = E_Out_Parameter
8140 or else K = E_In_Out_Parameter
8141 or else K = E_Generic_In_Out_Parameter
8143 -- Current instance of type:
8145 or else (Is_Type (E) and then In_Open_Scopes (E))
8146 or else (Is_Incomplete_Or_Private_Type (E)
8147 and then In_Open_Scopes (Full_View (E)));
8151 case Nkind (Orig_Node) is
8152 when N_Indexed_Component | N_Slice =>
8153 return Is_Variable_Prefix (Prefix (Orig_Node));
8155 when N_Selected_Component =>
8156 return Is_Variable_Prefix (Prefix (Orig_Node))
8157 and then Is_Variable (Selector_Name (Orig_Node));
8159 -- For an explicit dereference, the type of the prefix cannot
8160 -- be an access to constant or an access to subprogram.
8162 when N_Explicit_Dereference =>
8164 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8166 return Is_Access_Type (Typ)
8167 and then not Is_Access_Constant (Root_Type (Typ))
8168 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8171 -- The type conversion is the case where we do not deal with the
8172 -- context dependent special case of an actual parameter. Thus
8173 -- the type conversion is only considered a variable for the
8174 -- purposes of this routine if the target type is tagged. However,
8175 -- a type conversion is considered to be a variable if it does not
8176 -- come from source (this deals for example with the conversions
8177 -- of expressions to their actual subtypes).
8179 when N_Type_Conversion =>
8180 return Is_Variable (Expression (Orig_Node))
8182 (not Comes_From_Source (Orig_Node)
8184 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8186 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8188 -- GNAT allows an unchecked type conversion as a variable. This
8189 -- only affects the generation of internal expanded code, since
8190 -- calls to instantiations of Unchecked_Conversion are never
8191 -- considered variables (since they are function calls).
8192 -- This is also true for expression actions.
8194 when N_Unchecked_Type_Conversion =>
8195 return Is_Variable (Expression (Orig_Node));
8203 ---------------------------
8204 -- Is_Visibly_Controlled --
8205 ---------------------------
8207 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8208 Root : constant Entity_Id := Root_Type (T);
8210 return Chars (Scope (Root)) = Name_Finalization
8211 and then Chars (Scope (Scope (Root))) = Name_Ada
8212 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8213 end Is_Visibly_Controlled;
8215 ------------------------
8216 -- Is_Volatile_Object --
8217 ------------------------
8219 function Is_Volatile_Object (N : Node_Id) return Boolean is
8221 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8222 -- Determines if given object has volatile components
8224 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8225 -- If prefix is an implicit dereference, examine designated type
8227 ------------------------
8228 -- Is_Volatile_Prefix --
8229 ------------------------
8231 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8232 Typ : constant Entity_Id := Etype (N);
8235 if Is_Access_Type (Typ) then
8237 Dtyp : constant Entity_Id := Designated_Type (Typ);
8240 return Is_Volatile (Dtyp)
8241 or else Has_Volatile_Components (Dtyp);
8245 return Object_Has_Volatile_Components (N);
8247 end Is_Volatile_Prefix;
8249 ------------------------------------
8250 -- Object_Has_Volatile_Components --
8251 ------------------------------------
8253 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8254 Typ : constant Entity_Id := Etype (N);
8257 if Is_Volatile (Typ)
8258 or else Has_Volatile_Components (Typ)
8262 elsif Is_Entity_Name (N)
8263 and then (Has_Volatile_Components (Entity (N))
8264 or else Is_Volatile (Entity (N)))
8268 elsif Nkind (N) = N_Indexed_Component
8269 or else Nkind (N) = N_Selected_Component
8271 return Is_Volatile_Prefix (Prefix (N));
8276 end Object_Has_Volatile_Components;
8278 -- Start of processing for Is_Volatile_Object
8281 if Is_Volatile (Etype (N))
8282 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8286 elsif Nkind (N) = N_Indexed_Component
8287 or else Nkind (N) = N_Selected_Component
8289 return Is_Volatile_Prefix (Prefix (N));
8294 end Is_Volatile_Object;
8296 -------------------------
8297 -- Kill_Current_Values --
8298 -------------------------
8300 procedure Kill_Current_Values
8302 Last_Assignment_Only : Boolean := False)
8305 -- ??? do we have to worry about clearing cached checks?
8307 if Is_Assignable (Ent) then
8308 Set_Last_Assignment (Ent, Empty);
8311 if Is_Object (Ent) then
8312 if not Last_Assignment_Only then
8314 Set_Current_Value (Ent, Empty);
8316 if not Can_Never_Be_Null (Ent) then
8317 Set_Is_Known_Non_Null (Ent, False);
8320 Set_Is_Known_Null (Ent, False);
8322 -- Reset Is_Known_Valid unless type is always valid, or if we have
8323 -- a loop parameter (loop parameters are always valid, since their
8324 -- bounds are defined by the bounds given in the loop header).
8326 if not Is_Known_Valid (Etype (Ent))
8327 and then Ekind (Ent) /= E_Loop_Parameter
8329 Set_Is_Known_Valid (Ent, False);
8333 end Kill_Current_Values;
8335 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8338 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8339 -- Clear current value for entity E and all entities chained to E
8341 ------------------------------------------
8342 -- Kill_Current_Values_For_Entity_Chain --
8343 ------------------------------------------
8345 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8349 while Present (Ent) loop
8350 Kill_Current_Values (Ent, Last_Assignment_Only);
8353 end Kill_Current_Values_For_Entity_Chain;
8355 -- Start of processing for Kill_Current_Values
8358 -- Kill all saved checks, a special case of killing saved values
8360 if not Last_Assignment_Only then
8364 -- Loop through relevant scopes, which includes the current scope and
8365 -- any parent scopes if the current scope is a block or a package.
8370 -- Clear current values of all entities in current scope
8372 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8374 -- If scope is a package, also clear current values of all
8375 -- private entities in the scope.
8377 if Is_Package_Or_Generic_Package (S)
8378 or else Is_Concurrent_Type (S)
8380 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8383 -- If this is a not a subprogram, deal with parents
8385 if not Is_Subprogram (S) then
8387 exit Scope_Loop when S = Standard_Standard;
8391 end loop Scope_Loop;
8392 end Kill_Current_Values;
8394 --------------------------
8395 -- Kill_Size_Check_Code --
8396 --------------------------
8398 procedure Kill_Size_Check_Code (E : Entity_Id) is
8400 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8401 and then Present (Size_Check_Code (E))
8403 Remove (Size_Check_Code (E));
8404 Set_Size_Check_Code (E, Empty);
8406 end Kill_Size_Check_Code;
8408 --------------------------
8409 -- Known_To_Be_Assigned --
8410 --------------------------
8412 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8413 P : constant Node_Id := Parent (N);
8418 -- Test left side of assignment
8420 when N_Assignment_Statement =>
8421 return N = Name (P);
8423 -- Function call arguments are never lvalues
8425 when N_Function_Call =>
8428 -- Positional parameter for procedure or accept call
8430 when N_Procedure_Call_Statement |
8439 Proc := Get_Subprogram_Entity (P);
8445 -- If we are not a list member, something is strange, so
8446 -- be conservative and return False.
8448 if not Is_List_Member (N) then
8452 -- We are going to find the right formal by stepping forward
8453 -- through the formals, as we step backwards in the actuals.
8455 Form := First_Formal (Proc);
8458 -- If no formal, something is weird, so be conservative
8459 -- and return False.
8470 return Ekind (Form) /= E_In_Parameter;
8473 -- Named parameter for procedure or accept call
8475 when N_Parameter_Association =>
8481 Proc := Get_Subprogram_Entity (Parent (P));
8487 -- Loop through formals to find the one that matches
8489 Form := First_Formal (Proc);
8491 -- If no matching formal, that's peculiar, some kind of
8492 -- previous error, so return False to be conservative.
8498 -- Else test for match
8500 if Chars (Form) = Chars (Selector_Name (P)) then
8501 return Ekind (Form) /= E_In_Parameter;
8508 -- Test for appearing in a conversion that itself appears
8509 -- in an lvalue context, since this should be an lvalue.
8511 when N_Type_Conversion =>
8512 return Known_To_Be_Assigned (P);
8514 -- All other references are definitely not known to be modifications
8520 end Known_To_Be_Assigned;
8522 ---------------------------
8523 -- Last_Source_Statement --
8524 ---------------------------
8526 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8530 N := Last (Statements (HSS));
8531 while Present (N) loop
8532 exit when Comes_From_Source (N);
8537 end Last_Source_Statement;
8539 ----------------------------------
8540 -- Matching_Static_Array_Bounds --
8541 ----------------------------------
8543 function Matching_Static_Array_Bounds
8545 R_Typ : Node_Id) return Boolean
8547 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8548 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8560 if L_Ndims /= R_Ndims then
8564 -- Unconstrained types do not have static bounds
8566 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8570 -- First treat specially the first dimension, as the lower bound and
8571 -- length of string literals are not stored like those of arrays.
8573 if Ekind (L_Typ) = E_String_Literal_Subtype then
8574 L_Low := String_Literal_Low_Bound (L_Typ);
8575 L_Len := String_Literal_Length (L_Typ);
8577 L_Index := First_Index (L_Typ);
8578 Get_Index_Bounds (L_Index, L_Low, L_High);
8580 if Is_OK_Static_Expression (L_Low)
8581 and then Is_OK_Static_Expression (L_High)
8583 if Expr_Value (L_High) < Expr_Value (L_Low) then
8586 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8593 if Ekind (R_Typ) = E_String_Literal_Subtype then
8594 R_Low := String_Literal_Low_Bound (R_Typ);
8595 R_Len := String_Literal_Length (R_Typ);
8597 R_Index := First_Index (R_Typ);
8598 Get_Index_Bounds (R_Index, R_Low, R_High);
8600 if Is_OK_Static_Expression (R_Low)
8601 and then Is_OK_Static_Expression (R_High)
8603 if Expr_Value (R_High) < Expr_Value (R_Low) then
8606 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8613 if Is_OK_Static_Expression (L_Low)
8614 and then Is_OK_Static_Expression (R_Low)
8615 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8616 and then L_Len = R_Len
8623 -- Then treat all other dimensions
8625 for Indx in 2 .. L_Ndims loop
8629 Get_Index_Bounds (L_Index, L_Low, L_High);
8630 Get_Index_Bounds (R_Index, R_Low, R_High);
8632 if Is_OK_Static_Expression (L_Low)
8633 and then Is_OK_Static_Expression (L_High)
8634 and then Is_OK_Static_Expression (R_Low)
8635 and then Is_OK_Static_Expression (R_High)
8636 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8637 and then Expr_Value (L_High) = Expr_Value (R_High)
8645 -- If we fall through the loop, all indexes matched
8648 end Matching_Static_Array_Bounds;
8654 function May_Be_Lvalue (N : Node_Id) return Boolean is
8655 P : constant Node_Id := Parent (N);
8660 -- Test left side of assignment
8662 when N_Assignment_Statement =>
8663 return N = Name (P);
8665 -- Test prefix of component or attribute. Note that the prefix of an
8666 -- explicit or implicit dereference cannot be an l-value.
8668 when N_Attribute_Reference =>
8669 return N = Prefix (P)
8670 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8672 -- For an expanded name, the name is an lvalue if the expanded name
8673 -- is an lvalue, but the prefix is never an lvalue, since it is just
8674 -- the scope where the name is found.
8676 when N_Expanded_Name =>
8677 if N = Prefix (P) then
8678 return May_Be_Lvalue (P);
8683 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8684 -- B is a little interesting, if we have A.B := 3, there is some
8685 -- discussion as to whether B is an lvalue or not, we choose to say
8686 -- it is. Note however that A is not an lvalue if it is of an access
8687 -- type since this is an implicit dereference.
8689 when N_Selected_Component =>
8691 and then Present (Etype (N))
8692 and then Is_Access_Type (Etype (N))
8696 return May_Be_Lvalue (P);
8699 -- For an indexed component or slice, the index or slice bounds is
8700 -- never an lvalue. The prefix is an lvalue if the indexed component
8701 -- or slice is an lvalue, except if it is an access type, where we
8702 -- have an implicit dereference.
8704 when N_Indexed_Component =>
8706 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8710 return May_Be_Lvalue (P);
8713 -- Prefix of a reference is an lvalue if the reference is an lvalue
8716 return May_Be_Lvalue (P);
8718 -- Prefix of explicit dereference is never an lvalue
8720 when N_Explicit_Dereference =>
8723 -- Positional parameter for subprogram, entry, or accept call.
8724 -- In older versions of Ada function call arguments are never
8725 -- lvalues. In Ada 2012 functions can have in-out parameters.
8727 when N_Function_Call |
8728 N_Procedure_Call_Statement |
8729 N_Entry_Call_Statement |
8732 if Nkind (P) = N_Function_Call
8733 and then Ada_Version < Ada_2012
8738 -- The following mechanism is clumsy and fragile. A single
8739 -- flag set in Resolve_Actuals would be preferable ???
8747 Proc := Get_Subprogram_Entity (P);
8753 -- If we are not a list member, something is strange, so
8754 -- be conservative and return True.
8756 if not Is_List_Member (N) then
8760 -- We are going to find the right formal by stepping forward
8761 -- through the formals, as we step backwards in the actuals.
8763 Form := First_Formal (Proc);
8766 -- If no formal, something is weird, so be conservative
8778 return Ekind (Form) /= E_In_Parameter;
8781 -- Named parameter for procedure or accept call
8783 when N_Parameter_Association =>
8789 Proc := Get_Subprogram_Entity (Parent (P));
8795 -- Loop through formals to find the one that matches
8797 Form := First_Formal (Proc);
8799 -- If no matching formal, that's peculiar, some kind of
8800 -- previous error, so return True to be conservative.
8806 -- Else test for match
8808 if Chars (Form) = Chars (Selector_Name (P)) then
8809 return Ekind (Form) /= E_In_Parameter;
8816 -- Test for appearing in a conversion that itself appears in an
8817 -- lvalue context, since this should be an lvalue.
8819 when N_Type_Conversion =>
8820 return May_Be_Lvalue (P);
8822 -- Test for appearance in object renaming declaration
8824 when N_Object_Renaming_Declaration =>
8827 -- All other references are definitely not lvalues
8835 -----------------------
8836 -- Mark_Coextensions --
8837 -----------------------
8839 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8840 Is_Dynamic : Boolean;
8841 -- Indicates whether the context causes nested coextensions to be
8842 -- dynamic or static
8844 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8845 -- Recognize an allocator node and label it as a dynamic coextension
8847 --------------------
8848 -- Mark_Allocator --
8849 --------------------
8851 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8853 if Nkind (N) = N_Allocator then
8855 Set_Is_Dynamic_Coextension (N);
8857 -- If the allocator expression is potentially dynamic, it may
8858 -- be expanded out of order and require dynamic allocation
8859 -- anyway, so we treat the coextension itself as dynamic.
8860 -- Potential optimization ???
8862 elsif Nkind (Expression (N)) = N_Qualified_Expression
8863 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8865 Set_Is_Dynamic_Coextension (N);
8868 Set_Is_Static_Coextension (N);
8875 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8877 -- Start of processing Mark_Coextensions
8880 case Nkind (Context_Nod) is
8881 when N_Assignment_Statement |
8882 N_Simple_Return_Statement =>
8883 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8885 when N_Object_Declaration =>
8886 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8888 -- This routine should not be called for constructs which may not
8889 -- contain coextensions.
8892 raise Program_Error;
8895 Mark_Allocators (Root_Nod);
8896 end Mark_Coextensions;
8898 ----------------------
8899 -- Needs_One_Actual --
8900 ----------------------
8902 function Needs_One_Actual (E : Entity_Id) return Boolean is
8906 if Ada_Version >= Ada_2005
8907 and then Present (First_Formal (E))
8909 Formal := Next_Formal (First_Formal (E));
8910 while Present (Formal) loop
8911 if No (Default_Value (Formal)) then
8915 Next_Formal (Formal);
8923 end Needs_One_Actual;
8925 ------------------------
8926 -- New_Copy_List_Tree --
8927 ------------------------
8929 function New_Copy_List_Tree (List : List_Id) return List_Id is
8934 if List = No_List then
8941 while Present (E) loop
8942 Append (New_Copy_Tree (E), NL);
8948 end New_Copy_List_Tree;
8954 use Atree.Unchecked_Access;
8955 use Atree_Private_Part;
8957 -- Our approach here requires a two pass traversal of the tree. The
8958 -- first pass visits all nodes that eventually will be copied looking
8959 -- for defining Itypes. If any defining Itypes are found, then they are
8960 -- copied, and an entry is added to the replacement map. In the second
8961 -- phase, the tree is copied, using the replacement map to replace any
8962 -- Itype references within the copied tree.
8964 -- The following hash tables are used if the Map supplied has more
8965 -- than hash threshold entries to speed up access to the map. If
8966 -- there are fewer entries, then the map is searched sequentially
8967 -- (because setting up a hash table for only a few entries takes
8968 -- more time than it saves.
8970 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8971 -- Hash function used for hash operations
8977 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8979 return Nat (E) mod (NCT_Header_Num'Last + 1);
8986 -- The hash table NCT_Assoc associates old entities in the table
8987 -- with their corresponding new entities (i.e. the pairs of entries
8988 -- presented in the original Map argument are Key-Element pairs).
8990 package NCT_Assoc is new Simple_HTable (
8991 Header_Num => NCT_Header_Num,
8992 Element => Entity_Id,
8993 No_Element => Empty,
8995 Hash => New_Copy_Hash,
8996 Equal => Types."=");
8998 ---------------------
8999 -- NCT_Itype_Assoc --
9000 ---------------------
9002 -- The hash table NCT_Itype_Assoc contains entries only for those
9003 -- old nodes which have a non-empty Associated_Node_For_Itype set.
9004 -- The key is the associated node, and the element is the new node
9005 -- itself (NOT the associated node for the new node).
9007 package NCT_Itype_Assoc is new Simple_HTable (
9008 Header_Num => NCT_Header_Num,
9009 Element => Entity_Id,
9010 No_Element => Empty,
9012 Hash => New_Copy_Hash,
9013 Equal => Types."=");
9015 -- Start of processing for New_Copy_Tree function
9017 function New_Copy_Tree
9019 Map : Elist_Id := No_Elist;
9020 New_Sloc : Source_Ptr := No_Location;
9021 New_Scope : Entity_Id := Empty) return Node_Id
9023 Actual_Map : Elist_Id := Map;
9024 -- This is the actual map for the copy. It is initialized with the
9025 -- given elements, and then enlarged as required for Itypes that are
9026 -- copied during the first phase of the copy operation. The visit
9027 -- procedures add elements to this map as Itypes are encountered.
9028 -- The reason we cannot use Map directly, is that it may well be
9029 -- (and normally is) initialized to No_Elist, and if we have mapped
9030 -- entities, we have to reset it to point to a real Elist.
9032 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9033 -- Called during second phase to map entities into their corresponding
9034 -- copies using Actual_Map. If the argument is not an entity, or is not
9035 -- in Actual_Map, then it is returned unchanged.
9037 procedure Build_NCT_Hash_Tables;
9038 -- Builds hash tables (number of elements >= threshold value)
9040 function Copy_Elist_With_Replacement
9041 (Old_Elist : Elist_Id) return Elist_Id;
9042 -- Called during second phase to copy element list doing replacements
9044 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9045 -- Called during the second phase to process a copied Itype. The actual
9046 -- copy happened during the first phase (so that we could make the entry
9047 -- in the mapping), but we still have to deal with the descendents of
9048 -- the copied Itype and copy them where necessary.
9050 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9051 -- Called during second phase to copy list doing replacements
9053 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9054 -- Called during second phase to copy node doing replacements
9056 procedure Visit_Elist (E : Elist_Id);
9057 -- Called during first phase to visit all elements of an Elist
9059 procedure Visit_Field (F : Union_Id; N : Node_Id);
9060 -- Visit a single field, recursing to call Visit_Node or Visit_List
9061 -- if the field is a syntactic descendent of the current node (i.e.
9062 -- its parent is Node N).
9064 procedure Visit_Itype (Old_Itype : Entity_Id);
9065 -- Called during first phase to visit subsidiary fields of a defining
9066 -- Itype, and also create a copy and make an entry in the replacement
9067 -- map for the new copy.
9069 procedure Visit_List (L : List_Id);
9070 -- Called during first phase to visit all elements of a List
9072 procedure Visit_Node (N : Node_Or_Entity_Id);
9073 -- Called during first phase to visit a node and all its subtrees
9079 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9084 if not Has_Extension (N) or else No (Actual_Map) then
9087 elsif NCT_Hash_Tables_Used then
9088 Ent := NCT_Assoc.Get (Entity_Id (N));
9090 if Present (Ent) then
9096 -- No hash table used, do serial search
9099 E := First_Elmt (Actual_Map);
9100 while Present (E) loop
9101 if Node (E) = N then
9102 return Node (Next_Elmt (E));
9104 E := Next_Elmt (Next_Elmt (E));
9112 ---------------------------
9113 -- Build_NCT_Hash_Tables --
9114 ---------------------------
9116 procedure Build_NCT_Hash_Tables is
9120 if NCT_Hash_Table_Setup then
9122 NCT_Itype_Assoc.Reset;
9125 Elmt := First_Elmt (Actual_Map);
9126 while Present (Elmt) loop
9129 -- Get new entity, and associate old and new
9132 NCT_Assoc.Set (Ent, Node (Elmt));
9134 if Is_Type (Ent) then
9136 Anode : constant Entity_Id :=
9137 Associated_Node_For_Itype (Ent);
9140 if Present (Anode) then
9142 -- Enter a link between the associated node of the
9143 -- old Itype and the new Itype, for updating later
9144 -- when node is copied.
9146 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9154 NCT_Hash_Tables_Used := True;
9155 NCT_Hash_Table_Setup := True;
9156 end Build_NCT_Hash_Tables;
9158 ---------------------------------
9159 -- Copy_Elist_With_Replacement --
9160 ---------------------------------
9162 function Copy_Elist_With_Replacement
9163 (Old_Elist : Elist_Id) return Elist_Id
9166 New_Elist : Elist_Id;
9169 if No (Old_Elist) then
9173 New_Elist := New_Elmt_List;
9175 M := First_Elmt (Old_Elist);
9176 while Present (M) loop
9177 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9183 end Copy_Elist_With_Replacement;
9185 ---------------------------------
9186 -- Copy_Itype_With_Replacement --
9187 ---------------------------------
9189 -- This routine exactly parallels its phase one analog Visit_Itype,
9191 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9193 -- Translate Next_Entity, Scope and Etype fields, in case they
9194 -- reference entities that have been mapped into copies.
9196 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9197 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9199 if Present (New_Scope) then
9200 Set_Scope (New_Itype, New_Scope);
9202 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9205 -- Copy referenced fields
9207 if Is_Discrete_Type (New_Itype) then
9208 Set_Scalar_Range (New_Itype,
9209 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9211 elsif Has_Discriminants (Base_Type (New_Itype)) then
9212 Set_Discriminant_Constraint (New_Itype,
9213 Copy_Elist_With_Replacement
9214 (Discriminant_Constraint (New_Itype)));
9216 elsif Is_Array_Type (New_Itype) then
9217 if Present (First_Index (New_Itype)) then
9218 Set_First_Index (New_Itype,
9219 First (Copy_List_With_Replacement
9220 (List_Containing (First_Index (New_Itype)))));
9223 if Is_Packed (New_Itype) then
9224 Set_Packed_Array_Type (New_Itype,
9225 Copy_Node_With_Replacement
9226 (Packed_Array_Type (New_Itype)));
9229 end Copy_Itype_With_Replacement;
9231 --------------------------------
9232 -- Copy_List_With_Replacement --
9233 --------------------------------
9235 function Copy_List_With_Replacement
9236 (Old_List : List_Id) return List_Id
9242 if Old_List = No_List then
9246 New_List := Empty_List;
9248 E := First (Old_List);
9249 while Present (E) loop
9250 Append (Copy_Node_With_Replacement (E), New_List);
9256 end Copy_List_With_Replacement;
9258 --------------------------------
9259 -- Copy_Node_With_Replacement --
9260 --------------------------------
9262 function Copy_Node_With_Replacement
9263 (Old_Node : Node_Id) return Node_Id
9267 procedure Adjust_Named_Associations
9268 (Old_Node : Node_Id;
9269 New_Node : Node_Id);
9270 -- If a call node has named associations, these are chained through
9271 -- the First_Named_Actual, Next_Named_Actual links. These must be
9272 -- propagated separately to the new parameter list, because these
9273 -- are not syntactic fields.
9275 function Copy_Field_With_Replacement
9276 (Field : Union_Id) return Union_Id;
9277 -- Given Field, which is a field of Old_Node, return a copy of it
9278 -- if it is a syntactic field (i.e. its parent is Node), setting
9279 -- the parent of the copy to poit to New_Node. Otherwise returns
9280 -- the field (possibly mapped if it is an entity).
9282 -------------------------------
9283 -- Adjust_Named_Associations --
9284 -------------------------------
9286 procedure Adjust_Named_Associations
9287 (Old_Node : Node_Id;
9297 Old_E := First (Parameter_Associations (Old_Node));
9298 New_E := First (Parameter_Associations (New_Node));
9299 while Present (Old_E) loop
9300 if Nkind (Old_E) = N_Parameter_Association
9301 and then Present (Next_Named_Actual (Old_E))
9303 if First_Named_Actual (Old_Node)
9304 = Explicit_Actual_Parameter (Old_E)
9306 Set_First_Named_Actual
9307 (New_Node, Explicit_Actual_Parameter (New_E));
9310 -- Now scan parameter list from the beginning,to locate
9311 -- next named actual, which can be out of order.
9313 Old_Next := First (Parameter_Associations (Old_Node));
9314 New_Next := First (Parameter_Associations (New_Node));
9316 while Nkind (Old_Next) /= N_Parameter_Association
9317 or else Explicit_Actual_Parameter (Old_Next)
9318 /= Next_Named_Actual (Old_E)
9324 Set_Next_Named_Actual
9325 (New_E, Explicit_Actual_Parameter (New_Next));
9331 end Adjust_Named_Associations;
9333 ---------------------------------
9334 -- Copy_Field_With_Replacement --
9335 ---------------------------------
9337 function Copy_Field_With_Replacement
9338 (Field : Union_Id) return Union_Id
9341 if Field = Union_Id (Empty) then
9344 elsif Field in Node_Range then
9346 Old_N : constant Node_Id := Node_Id (Field);
9350 -- If syntactic field, as indicated by the parent pointer
9351 -- being set, then copy the referenced node recursively.
9353 if Parent (Old_N) = Old_Node then
9354 New_N := Copy_Node_With_Replacement (Old_N);
9356 if New_N /= Old_N then
9357 Set_Parent (New_N, New_Node);
9360 -- For semantic fields, update possible entity reference
9361 -- from the replacement map.
9364 New_N := Assoc (Old_N);
9367 return Union_Id (New_N);
9370 elsif Field in List_Range then
9372 Old_L : constant List_Id := List_Id (Field);
9376 -- If syntactic field, as indicated by the parent pointer,
9377 -- then recursively copy the entire referenced list.
9379 if Parent (Old_L) = Old_Node then
9380 New_L := Copy_List_With_Replacement (Old_L);
9381 Set_Parent (New_L, New_Node);
9383 -- For semantic list, just returned unchanged
9389 return Union_Id (New_L);
9392 -- Anything other than a list or a node is returned unchanged
9397 end Copy_Field_With_Replacement;
9399 -- Start of processing for Copy_Node_With_Replacement
9402 if Old_Node <= Empty_Or_Error then
9405 elsif Has_Extension (Old_Node) then
9406 return Assoc (Old_Node);
9409 New_Node := New_Copy (Old_Node);
9411 -- If the node we are copying is the associated node of a
9412 -- previously copied Itype, then adjust the associated node
9413 -- of the copy of that Itype accordingly.
9415 if Present (Actual_Map) then
9421 -- Case of hash table used
9423 if NCT_Hash_Tables_Used then
9424 Ent := NCT_Itype_Assoc.Get (Old_Node);
9426 if Present (Ent) then
9427 Set_Associated_Node_For_Itype (Ent, New_Node);
9430 -- Case of no hash table used
9433 E := First_Elmt (Actual_Map);
9434 while Present (E) loop
9435 if Is_Itype (Node (E))
9437 Old_Node = Associated_Node_For_Itype (Node (E))
9439 Set_Associated_Node_For_Itype
9440 (Node (Next_Elmt (E)), New_Node);
9443 E := Next_Elmt (Next_Elmt (E));
9449 -- Recursively copy descendents
9452 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9454 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9456 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9458 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9460 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9462 -- Adjust Sloc of new node if necessary
9464 if New_Sloc /= No_Location then
9465 Set_Sloc (New_Node, New_Sloc);
9467 -- If we adjust the Sloc, then we are essentially making
9468 -- a completely new node, so the Comes_From_Source flag
9469 -- should be reset to the proper default value.
9471 Nodes.Table (New_Node).Comes_From_Source :=
9472 Default_Node.Comes_From_Source;
9475 -- If the node is call and has named associations,
9476 -- set the corresponding links in the copy.
9478 if (Nkind (Old_Node) = N_Function_Call
9479 or else Nkind (Old_Node) = N_Entry_Call_Statement
9481 Nkind (Old_Node) = N_Procedure_Call_Statement)
9482 and then Present (First_Named_Actual (Old_Node))
9484 Adjust_Named_Associations (Old_Node, New_Node);
9487 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9488 -- The replacement mechanism applies to entities, and is not used
9489 -- here. Eventually we may need a more general graph-copying
9490 -- routine. For now, do a sequential search to find desired node.
9492 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9493 and then Present (First_Real_Statement (Old_Node))
9496 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9500 N1 := First (Statements (Old_Node));
9501 N2 := First (Statements (New_Node));
9503 while N1 /= Old_F loop
9508 Set_First_Real_Statement (New_Node, N2);
9513 -- All done, return copied node
9516 end Copy_Node_With_Replacement;
9522 procedure Visit_Elist (E : Elist_Id) is
9526 Elmt := First_Elmt (E);
9528 while Elmt /= No_Elmt loop
9529 Visit_Node (Node (Elmt));
9539 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9541 if F = Union_Id (Empty) then
9544 elsif F in Node_Range then
9546 -- Copy node if it is syntactic, i.e. its parent pointer is
9547 -- set to point to the field that referenced it (certain
9548 -- Itypes will also meet this criterion, which is fine, since
9549 -- these are clearly Itypes that do need to be copied, since
9550 -- we are copying their parent.)
9552 if Parent (Node_Id (F)) = N then
9553 Visit_Node (Node_Id (F));
9556 -- Another case, if we are pointing to an Itype, then we want
9557 -- to copy it if its associated node is somewhere in the tree
9560 -- Note: the exclusion of self-referential copies is just an
9561 -- optimization, since the search of the already copied list
9562 -- would catch it, but it is a common case (Etype pointing
9563 -- to itself for an Itype that is a base type).
9565 elsif Has_Extension (Node_Id (F))
9566 and then Is_Itype (Entity_Id (F))
9567 and then Node_Id (F) /= N
9573 P := Associated_Node_For_Itype (Node_Id (F));
9574 while Present (P) loop
9576 Visit_Node (Node_Id (F));
9583 -- An Itype whose parent is not being copied definitely
9584 -- should NOT be copied, since it does not belong in any
9585 -- sense to the copied subtree.
9591 elsif F in List_Range
9592 and then Parent (List_Id (F)) = N
9594 Visit_List (List_Id (F));
9603 procedure Visit_Itype (Old_Itype : Entity_Id) is
9604 New_Itype : Entity_Id;
9609 -- Itypes that describe the designated type of access to subprograms
9610 -- have the structure of subprogram declarations, with signatures,
9611 -- etc. Either we duplicate the signatures completely, or choose to
9612 -- share such itypes, which is fine because their elaboration will
9613 -- have no side effects.
9615 if Ekind (Old_Itype) = E_Subprogram_Type then
9619 New_Itype := New_Copy (Old_Itype);
9621 -- The new Itype has all the attributes of the old one, and
9622 -- we just copy the contents of the entity. However, the back-end
9623 -- needs different names for debugging purposes, so we create a
9624 -- new internal name for it in all cases.
9626 Set_Chars (New_Itype, New_Internal_Name ('T'));
9628 -- If our associated node is an entity that has already been copied,
9629 -- then set the associated node of the copy to point to the right
9630 -- copy. If we have copied an Itype that is itself the associated
9631 -- node of some previously copied Itype, then we set the right
9632 -- pointer in the other direction.
9634 if Present (Actual_Map) then
9636 -- Case of hash tables used
9638 if NCT_Hash_Tables_Used then
9640 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9642 if Present (Ent) then
9643 Set_Associated_Node_For_Itype (New_Itype, Ent);
9646 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9647 if Present (Ent) then
9648 Set_Associated_Node_For_Itype (Ent, New_Itype);
9650 -- If the hash table has no association for this Itype and
9651 -- its associated node, enter one now.
9655 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9658 -- Case of hash tables not used
9661 E := First_Elmt (Actual_Map);
9662 while Present (E) loop
9663 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9664 Set_Associated_Node_For_Itype
9665 (New_Itype, Node (Next_Elmt (E)));
9668 if Is_Type (Node (E))
9670 Old_Itype = Associated_Node_For_Itype (Node (E))
9672 Set_Associated_Node_For_Itype
9673 (Node (Next_Elmt (E)), New_Itype);
9676 E := Next_Elmt (Next_Elmt (E));
9681 if Present (Freeze_Node (New_Itype)) then
9682 Set_Is_Frozen (New_Itype, False);
9683 Set_Freeze_Node (New_Itype, Empty);
9686 -- Add new association to map
9688 if No (Actual_Map) then
9689 Actual_Map := New_Elmt_List;
9692 Append_Elmt (Old_Itype, Actual_Map);
9693 Append_Elmt (New_Itype, Actual_Map);
9695 if NCT_Hash_Tables_Used then
9696 NCT_Assoc.Set (Old_Itype, New_Itype);
9699 NCT_Table_Entries := NCT_Table_Entries + 1;
9701 if NCT_Table_Entries > NCT_Hash_Threshold then
9702 Build_NCT_Hash_Tables;
9706 -- If a record subtype is simply copied, the entity list will be
9707 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9709 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9710 Set_Cloned_Subtype (New_Itype, Old_Itype);
9713 -- Visit descendents that eventually get copied
9715 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9717 if Is_Discrete_Type (Old_Itype) then
9718 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9720 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9721 -- ??? This should involve call to Visit_Field
9722 Visit_Elist (Discriminant_Constraint (Old_Itype));
9724 elsif Is_Array_Type (Old_Itype) then
9725 if Present (First_Index (Old_Itype)) then
9726 Visit_Field (Union_Id (List_Containing
9727 (First_Index (Old_Itype))),
9731 if Is_Packed (Old_Itype) then
9732 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9742 procedure Visit_List (L : List_Id) is
9745 if L /= No_List then
9748 while Present (N) loop
9759 procedure Visit_Node (N : Node_Or_Entity_Id) is
9761 -- Start of processing for Visit_Node
9764 -- Handle case of an Itype, which must be copied
9766 if Has_Extension (N)
9767 and then Is_Itype (N)
9769 -- Nothing to do if already in the list. This can happen with an
9770 -- Itype entity that appears more than once in the tree.
9771 -- Note that we do not want to visit descendents in this case.
9773 -- Test for already in list when hash table is used
9775 if NCT_Hash_Tables_Used then
9776 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9780 -- Test for already in list when hash table not used
9786 if Present (Actual_Map) then
9787 E := First_Elmt (Actual_Map);
9788 while Present (E) loop
9789 if Node (E) = N then
9792 E := Next_Elmt (Next_Elmt (E));
9802 -- Visit descendents
9804 Visit_Field (Field1 (N), N);
9805 Visit_Field (Field2 (N), N);
9806 Visit_Field (Field3 (N), N);
9807 Visit_Field (Field4 (N), N);
9808 Visit_Field (Field5 (N), N);
9811 -- Start of processing for New_Copy_Tree
9816 -- See if we should use hash table
9818 if No (Actual_Map) then
9819 NCT_Hash_Tables_Used := False;
9826 NCT_Table_Entries := 0;
9828 Elmt := First_Elmt (Actual_Map);
9829 while Present (Elmt) loop
9830 NCT_Table_Entries := NCT_Table_Entries + 1;
9835 if NCT_Table_Entries > NCT_Hash_Threshold then
9836 Build_NCT_Hash_Tables;
9838 NCT_Hash_Tables_Used := False;
9843 -- Hash table set up if required, now start phase one by visiting
9844 -- top node (we will recursively visit the descendents).
9846 Visit_Node (Source);
9848 -- Now the second phase of the copy can start. First we process
9849 -- all the mapped entities, copying their descendents.
9851 if Present (Actual_Map) then
9854 New_Itype : Entity_Id;
9856 Elmt := First_Elmt (Actual_Map);
9857 while Present (Elmt) loop
9859 New_Itype := Node (Elmt);
9860 Copy_Itype_With_Replacement (New_Itype);
9866 -- Now we can copy the actual tree
9868 return Copy_Node_With_Replacement (Source);
9871 -------------------------
9872 -- New_External_Entity --
9873 -------------------------
9875 function New_External_Entity
9876 (Kind : Entity_Kind;
9877 Scope_Id : Entity_Id;
9878 Sloc_Value : Source_Ptr;
9879 Related_Id : Entity_Id;
9881 Suffix_Index : Nat := 0;
9882 Prefix : Character := ' ') return Entity_Id
9884 N : constant Entity_Id :=
9885 Make_Defining_Identifier (Sloc_Value,
9887 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9890 Set_Ekind (N, Kind);
9891 Set_Is_Internal (N, True);
9892 Append_Entity (N, Scope_Id);
9893 Set_Public_Status (N);
9895 if Kind in Type_Kind then
9896 Init_Size_Align (N);
9900 end New_External_Entity;
9902 -------------------------
9903 -- New_Internal_Entity --
9904 -------------------------
9906 function New_Internal_Entity
9907 (Kind : Entity_Kind;
9908 Scope_Id : Entity_Id;
9909 Sloc_Value : Source_Ptr;
9910 Id_Char : Character) return Entity_Id
9912 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9915 Set_Ekind (N, Kind);
9916 Set_Is_Internal (N, True);
9917 Append_Entity (N, Scope_Id);
9919 if Kind in Type_Kind then
9920 Init_Size_Align (N);
9924 end New_Internal_Entity;
9930 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9934 -- If we are pointing at a positional parameter, it is a member of a
9935 -- node list (the list of parameters), and the next parameter is the
9936 -- next node on the list, unless we hit a parameter association, then
9937 -- we shift to using the chain whose head is the First_Named_Actual in
9938 -- the parent, and then is threaded using the Next_Named_Actual of the
9939 -- Parameter_Association. All this fiddling is because the original node
9940 -- list is in the textual call order, and what we need is the
9941 -- declaration order.
9943 if Is_List_Member (Actual_Id) then
9944 N := Next (Actual_Id);
9946 if Nkind (N) = N_Parameter_Association then
9947 return First_Named_Actual (Parent (Actual_Id));
9953 return Next_Named_Actual (Parent (Actual_Id));
9957 procedure Next_Actual (Actual_Id : in out Node_Id) is
9959 Actual_Id := Next_Actual (Actual_Id);
9962 -----------------------
9963 -- Normalize_Actuals --
9964 -----------------------
9966 -- Chain actuals according to formals of subprogram. If there are no named
9967 -- associations, the chain is simply the list of Parameter Associations,
9968 -- since the order is the same as the declaration order. If there are named
9969 -- associations, then the First_Named_Actual field in the N_Function_Call
9970 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9971 -- node for the parameter that comes first in declaration order. The
9972 -- remaining named parameters are then chained in declaration order using
9973 -- Next_Named_Actual.
9975 -- This routine also verifies that the number of actuals is compatible with
9976 -- the number and default values of formals, but performs no type checking
9977 -- (type checking is done by the caller).
9979 -- If the matching succeeds, Success is set to True and the caller proceeds
9980 -- with type-checking. If the match is unsuccessful, then Success is set to
9981 -- False, and the caller attempts a different interpretation, if there is
9984 -- If the flag Report is on, the call is not overloaded, and a failure to
9985 -- match can be reported here, rather than in the caller.
9987 procedure Normalize_Actuals
9991 Success : out Boolean)
9993 Actuals : constant List_Id := Parameter_Associations (N);
9994 Actual : Node_Id := Empty;
9996 Last : Node_Id := Empty;
9997 First_Named : Node_Id := Empty;
10000 Formals_To_Match : Integer := 0;
10001 Actuals_To_Match : Integer := 0;
10003 procedure Chain (A : Node_Id);
10004 -- Add named actual at the proper place in the list, using the
10005 -- Next_Named_Actual link.
10007 function Reporting return Boolean;
10008 -- Determines if an error is to be reported. To report an error, we
10009 -- need Report to be True, and also we do not report errors caused
10010 -- by calls to init procs that occur within other init procs. Such
10011 -- errors must always be cascaded errors, since if all the types are
10012 -- declared correctly, the compiler will certainly build decent calls!
10018 procedure Chain (A : Node_Id) is
10022 -- Call node points to first actual in list
10024 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10027 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10031 Set_Next_Named_Actual (Last, Empty);
10038 function Reporting return Boolean is
10043 elsif not Within_Init_Proc then
10046 elsif Is_Init_Proc (Entity (Name (N))) then
10054 -- Start of processing for Normalize_Actuals
10057 if Is_Access_Type (S) then
10059 -- The name in the call is a function call that returns an access
10060 -- to subprogram. The designated type has the list of formals.
10062 Formal := First_Formal (Designated_Type (S));
10064 Formal := First_Formal (S);
10067 while Present (Formal) loop
10068 Formals_To_Match := Formals_To_Match + 1;
10069 Next_Formal (Formal);
10072 -- Find if there is a named association, and verify that no positional
10073 -- associations appear after named ones.
10075 if Present (Actuals) then
10076 Actual := First (Actuals);
10079 while Present (Actual)
10080 and then Nkind (Actual) /= N_Parameter_Association
10082 Actuals_To_Match := Actuals_To_Match + 1;
10086 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10088 -- Most common case: positional notation, no defaults
10093 elsif Actuals_To_Match > Formals_To_Match then
10095 -- Too many actuals: will not work
10098 if Is_Entity_Name (Name (N)) then
10099 Error_Msg_N ("too many arguments in call to&", Name (N));
10101 Error_Msg_N ("too many arguments in call", N);
10109 First_Named := Actual;
10111 while Present (Actual) loop
10112 if Nkind (Actual) /= N_Parameter_Association then
10114 ("positional parameters not allowed after named ones", Actual);
10119 Actuals_To_Match := Actuals_To_Match + 1;
10125 if Present (Actuals) then
10126 Actual := First (Actuals);
10129 Formal := First_Formal (S);
10130 while Present (Formal) loop
10132 -- Match the formals in order. If the corresponding actual is
10133 -- positional, nothing to do. Else scan the list of named actuals
10134 -- to find the one with the right name.
10136 if Present (Actual)
10137 and then Nkind (Actual) /= N_Parameter_Association
10140 Actuals_To_Match := Actuals_To_Match - 1;
10141 Formals_To_Match := Formals_To_Match - 1;
10144 -- For named parameters, search the list of actuals to find
10145 -- one that matches the next formal name.
10147 Actual := First_Named;
10149 while Present (Actual) loop
10150 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10153 Actuals_To_Match := Actuals_To_Match - 1;
10154 Formals_To_Match := Formals_To_Match - 1;
10162 if Ekind (Formal) /= E_In_Parameter
10163 or else No (Default_Value (Formal))
10166 if (Comes_From_Source (S)
10167 or else Sloc (S) = Standard_Location)
10168 and then Is_Overloadable (S)
10172 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10174 (Nkind (Parent (N)) = N_Function_Call
10176 Nkind (Parent (N)) = N_Parameter_Association))
10177 and then Ekind (S) /= E_Function
10179 Set_Etype (N, Etype (S));
10181 Error_Msg_Name_1 := Chars (S);
10182 Error_Msg_Sloc := Sloc (S);
10184 ("missing argument for parameter & " &
10185 "in call to % declared #", N, Formal);
10188 elsif Is_Overloadable (S) then
10189 Error_Msg_Name_1 := Chars (S);
10191 -- Point to type derivation that generated the
10194 Error_Msg_Sloc := Sloc (Parent (S));
10197 ("missing argument for parameter & " &
10198 "in call to % (inherited) #", N, Formal);
10202 ("missing argument for parameter &", N, Formal);
10210 Formals_To_Match := Formals_To_Match - 1;
10215 Next_Formal (Formal);
10218 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10225 -- Find some superfluous named actual that did not get
10226 -- attached to the list of associations.
10228 Actual := First (Actuals);
10229 while Present (Actual) loop
10230 if Nkind (Actual) = N_Parameter_Association
10231 and then Actual /= Last
10232 and then No (Next_Named_Actual (Actual))
10234 Error_Msg_N ("unmatched actual & in call",
10235 Selector_Name (Actual));
10246 end Normalize_Actuals;
10248 --------------------------------
10249 -- Note_Possible_Modification --
10250 --------------------------------
10252 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10253 Modification_Comes_From_Source : constant Boolean :=
10254 Comes_From_Source (Parent (N));
10260 -- Loop to find referenced entity, if there is one
10267 if Is_Entity_Name (Exp) then
10268 Ent := Entity (Exp);
10270 -- If the entity is missing, it is an undeclared identifier,
10271 -- and there is nothing to annotate.
10277 elsif Nkind (Exp) = N_Explicit_Dereference then
10279 P : constant Node_Id := Prefix (Exp);
10282 if Nkind (P) = N_Selected_Component
10284 Entry_Formal (Entity (Selector_Name (P))))
10286 -- Case of a reference to an entry formal
10288 Ent := Entry_Formal (Entity (Selector_Name (P)));
10290 elsif Nkind (P) = N_Identifier
10291 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10292 and then Present (Expression (Parent (Entity (P))))
10293 and then Nkind (Expression (Parent (Entity (P))))
10296 -- Case of a reference to a value on which side effects have
10299 Exp := Prefix (Expression (Parent (Entity (P))));
10308 elsif Nkind (Exp) = N_Type_Conversion
10309 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10311 Exp := Expression (Exp);
10314 elsif Nkind (Exp) = N_Slice
10315 or else Nkind (Exp) = N_Indexed_Component
10316 or else Nkind (Exp) = N_Selected_Component
10318 Exp := Prefix (Exp);
10325 -- Now look for entity being referenced
10327 if Present (Ent) then
10328 if Is_Object (Ent) then
10329 if Comes_From_Source (Exp)
10330 or else Modification_Comes_From_Source
10332 -- Give warning if pragma unmodified given and we are
10333 -- sure this is a modification.
10335 if Has_Pragma_Unmodified (Ent) and then Sure then
10336 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10339 Set_Never_Set_In_Source (Ent, False);
10342 Set_Is_True_Constant (Ent, False);
10343 Set_Current_Value (Ent, Empty);
10344 Set_Is_Known_Null (Ent, False);
10346 if not Can_Never_Be_Null (Ent) then
10347 Set_Is_Known_Non_Null (Ent, False);
10350 -- Follow renaming chain
10352 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10353 and then Present (Renamed_Object (Ent))
10355 Exp := Renamed_Object (Ent);
10359 -- Generate a reference only if the assignment comes from
10360 -- source. This excludes, for example, calls to a dispatching
10361 -- assignment operation when the left-hand side is tagged.
10363 if Modification_Comes_From_Source then
10364 Generate_Reference (Ent, Exp, 'm');
10366 -- If the target of the assignment is the bound variable
10367 -- in an iterator, indicate that the corresponding array
10368 -- or container is also modified.
10370 if Ada_Version >= Ada_2012
10372 Nkind (Parent (Ent)) = N_Iterator_Specification
10375 Domain : constant Node_Id := Name (Parent (Ent));
10378 -- TBD : in the full version of the construct, the
10379 -- domain of iteration can be given by an expression.
10381 if Is_Entity_Name (Domain) then
10382 Generate_Reference (Entity (Domain), Exp, 'm');
10383 Set_Is_True_Constant (Entity (Domain), False);
10384 Set_Never_Set_In_Source (Entity (Domain), False);
10390 Check_Nested_Access (Ent);
10395 -- If we are sure this is a modification from source, and we know
10396 -- this modifies a constant, then give an appropriate warning.
10398 if Overlays_Constant (Ent)
10399 and then Modification_Comes_From_Source
10403 A : constant Node_Id := Address_Clause (Ent);
10405 if Present (A) then
10407 Exp : constant Node_Id := Expression (A);
10409 if Nkind (Exp) = N_Attribute_Reference
10410 and then Attribute_Name (Exp) = Name_Address
10411 and then Is_Entity_Name (Prefix (Exp))
10413 Error_Msg_Sloc := Sloc (A);
10415 ("constant& may be modified via address clause#?",
10416 N, Entity (Prefix (Exp)));
10426 end Note_Possible_Modification;
10428 -------------------------
10429 -- Object_Access_Level --
10430 -------------------------
10432 function Object_Access_Level (Obj : Node_Id) return Uint is
10435 -- Returns the static accessibility level of the view denoted by Obj. Note
10436 -- that the value returned is the result of a call to Scope_Depth. Only
10437 -- scope depths associated with dynamic scopes can actually be returned.
10438 -- Since only relative levels matter for accessibility checking, the fact
10439 -- that the distance between successive levels of accessibility is not
10440 -- always one is immaterial (invariant: if level(E2) is deeper than
10441 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10443 function Reference_To (Obj : Node_Id) return Node_Id;
10444 -- An explicit dereference is created when removing side-effects from
10445 -- expressions for constraint checking purposes. In this case a local
10446 -- access type is created for it. The correct access level is that of
10447 -- the original source node. We detect this case by noting that the
10448 -- prefix of the dereference is created by an object declaration whose
10449 -- initial expression is a reference.
10455 function Reference_To (Obj : Node_Id) return Node_Id is
10456 Pref : constant Node_Id := Prefix (Obj);
10458 if Is_Entity_Name (Pref)
10459 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10460 and then Present (Expression (Parent (Entity (Pref))))
10461 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10463 return (Prefix (Expression (Parent (Entity (Pref)))));
10469 -- Start of processing for Object_Access_Level
10472 if Is_Entity_Name (Obj) then
10475 if Is_Prival (E) then
10476 E := Prival_Link (E);
10479 -- If E is a type then it denotes a current instance. For this case
10480 -- we add one to the normal accessibility level of the type to ensure
10481 -- that current instances are treated as always being deeper than
10482 -- than the level of any visible named access type (see 3.10.2(21)).
10484 if Is_Type (E) then
10485 return Type_Access_Level (E) + 1;
10487 elsif Present (Renamed_Object (E)) then
10488 return Object_Access_Level (Renamed_Object (E));
10490 -- Similarly, if E is a component of the current instance of a
10491 -- protected type, any instance of it is assumed to be at a deeper
10492 -- level than the type. For a protected object (whose type is an
10493 -- anonymous protected type) its components are at the same level
10494 -- as the type itself.
10496 elsif not Is_Overloadable (E)
10497 and then Ekind (Scope (E)) = E_Protected_Type
10498 and then Comes_From_Source (Scope (E))
10500 return Type_Access_Level (Scope (E)) + 1;
10503 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10506 elsif Nkind (Obj) = N_Selected_Component then
10507 if Is_Access_Type (Etype (Prefix (Obj))) then
10508 return Type_Access_Level (Etype (Prefix (Obj)));
10510 return Object_Access_Level (Prefix (Obj));
10513 elsif Nkind (Obj) = N_Indexed_Component then
10514 if Is_Access_Type (Etype (Prefix (Obj))) then
10515 return Type_Access_Level (Etype (Prefix (Obj)));
10517 return Object_Access_Level (Prefix (Obj));
10520 elsif Nkind (Obj) = N_Explicit_Dereference then
10522 -- If the prefix is a selected access discriminant then we make a
10523 -- recursive call on the prefix, which will in turn check the level
10524 -- of the prefix object of the selected discriminant.
10526 if Nkind (Prefix (Obj)) = N_Selected_Component
10527 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10529 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10531 return Object_Access_Level (Prefix (Obj));
10533 elsif not (Comes_From_Source (Obj)) then
10535 Ref : constant Node_Id := Reference_To (Obj);
10537 if Present (Ref) then
10538 return Object_Access_Level (Ref);
10540 return Type_Access_Level (Etype (Prefix (Obj)));
10545 return Type_Access_Level (Etype (Prefix (Obj)));
10548 elsif Nkind (Obj) = N_Type_Conversion
10549 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10551 return Object_Access_Level (Expression (Obj));
10553 elsif Nkind (Obj) = N_Function_Call then
10555 -- Function results are objects, so we get either the access level of
10556 -- the function or, in the case of an indirect call, the level of the
10557 -- access-to-subprogram type. (This code is used for Ada 95, but it
10558 -- looks wrong, because it seems that we should be checking the level
10559 -- of the call itself, even for Ada 95. However, using the Ada 2005
10560 -- version of the code causes regressions in several tests that are
10561 -- compiled with -gnat95. ???)
10563 if Ada_Version < Ada_2005 then
10564 if Is_Entity_Name (Name (Obj)) then
10565 return Subprogram_Access_Level (Entity (Name (Obj)));
10567 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10570 -- For Ada 2005, the level of the result object of a function call is
10571 -- defined to be the level of the call's innermost enclosing master.
10572 -- We determine that by querying the depth of the innermost enclosing
10576 Return_Master_Scope_Depth_Of_Call : declare
10578 function Innermost_Master_Scope_Depth
10579 (N : Node_Id) return Uint;
10580 -- Returns the scope depth of the given node's innermost
10581 -- enclosing dynamic scope (effectively the accessibility
10582 -- level of the innermost enclosing master).
10584 ----------------------------------
10585 -- Innermost_Master_Scope_Depth --
10586 ----------------------------------
10588 function Innermost_Master_Scope_Depth
10589 (N : Node_Id) return Uint
10591 Node_Par : Node_Id := Parent (N);
10594 -- Locate the nearest enclosing node (by traversing Parents)
10595 -- that Defining_Entity can be applied to, and return the
10596 -- depth of that entity's nearest enclosing dynamic scope.
10598 while Present (Node_Par) loop
10599 case Nkind (Node_Par) is
10600 when N_Component_Declaration |
10601 N_Entry_Declaration |
10602 N_Formal_Object_Declaration |
10603 N_Formal_Type_Declaration |
10604 N_Full_Type_Declaration |
10605 N_Incomplete_Type_Declaration |
10606 N_Loop_Parameter_Specification |
10607 N_Object_Declaration |
10608 N_Protected_Type_Declaration |
10609 N_Private_Extension_Declaration |
10610 N_Private_Type_Declaration |
10611 N_Subtype_Declaration |
10612 N_Function_Specification |
10613 N_Procedure_Specification |
10614 N_Task_Type_Declaration |
10616 N_Generic_Instantiation |
10618 N_Implicit_Label_Declaration |
10619 N_Package_Declaration |
10620 N_Single_Task_Declaration |
10621 N_Subprogram_Declaration |
10622 N_Generic_Declaration |
10623 N_Renaming_Declaration |
10624 N_Block_Statement |
10625 N_Formal_Subprogram_Declaration |
10626 N_Abstract_Subprogram_Declaration |
10628 N_Exception_Declaration |
10629 N_Formal_Package_Declaration |
10630 N_Number_Declaration |
10631 N_Package_Specification |
10632 N_Parameter_Specification |
10633 N_Single_Protected_Declaration |
10637 (Nearest_Dynamic_Scope
10638 (Defining_Entity (Node_Par)));
10644 Node_Par := Parent (Node_Par);
10647 pragma Assert (False);
10649 -- Should never reach the following return
10651 return Scope_Depth (Current_Scope) + 1;
10652 end Innermost_Master_Scope_Depth;
10654 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10657 return Innermost_Master_Scope_Depth (Obj);
10658 end Return_Master_Scope_Depth_Of_Call;
10661 -- For convenience we handle qualified expressions, even though
10662 -- they aren't technically object names.
10664 elsif Nkind (Obj) = N_Qualified_Expression then
10665 return Object_Access_Level (Expression (Obj));
10667 -- Otherwise return the scope level of Standard.
10668 -- (If there are cases that fall through
10669 -- to this point they will be treated as
10670 -- having global accessibility for now. ???)
10673 return Scope_Depth (Standard_Standard);
10675 end Object_Access_Level;
10677 --------------------------------------
10678 -- Original_Corresponding_Operation --
10679 --------------------------------------
10681 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10683 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10686 -- If S is an inherited primitive S2 the original corresponding
10687 -- operation of S is the original corresponding operation of S2
10689 if Present (Alias (S))
10690 and then Find_Dispatching_Type (Alias (S)) /= Typ
10692 return Original_Corresponding_Operation (Alias (S));
10694 -- If S overrides an inherited subprogram S2 the original corresponding
10695 -- operation of S is the original corresponding operation of S2
10697 elsif Present (Overridden_Operation (S)) then
10698 return Original_Corresponding_Operation (Overridden_Operation (S));
10700 -- otherwise it is S itself
10705 end Original_Corresponding_Operation;
10707 -----------------------
10708 -- Private_Component --
10709 -----------------------
10711 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10712 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10714 function Trace_Components
10716 Check : Boolean) return Entity_Id;
10717 -- Recursive function that does the work, and checks against circular
10718 -- definition for each subcomponent type.
10720 ----------------------
10721 -- Trace_Components --
10722 ----------------------
10724 function Trace_Components
10726 Check : Boolean) return Entity_Id
10728 Btype : constant Entity_Id := Base_Type (T);
10729 Component : Entity_Id;
10731 Candidate : Entity_Id := Empty;
10734 if Check and then Btype = Ancestor then
10735 Error_Msg_N ("circular type definition", Type_Id);
10739 if Is_Private_Type (Btype)
10740 and then not Is_Generic_Type (Btype)
10742 if Present (Full_View (Btype))
10743 and then Is_Record_Type (Full_View (Btype))
10744 and then not Is_Frozen (Btype)
10746 -- To indicate that the ancestor depends on a private type, the
10747 -- current Btype is sufficient. However, to check for circular
10748 -- definition we must recurse on the full view.
10750 Candidate := Trace_Components (Full_View (Btype), True);
10752 if Candidate = Any_Type then
10762 elsif Is_Array_Type (Btype) then
10763 return Trace_Components (Component_Type (Btype), True);
10765 elsif Is_Record_Type (Btype) then
10766 Component := First_Entity (Btype);
10767 while Present (Component) loop
10769 -- Skip anonymous types generated by constrained components
10771 if not Is_Type (Component) then
10772 P := Trace_Components (Etype (Component), True);
10774 if Present (P) then
10775 if P = Any_Type then
10783 Next_Entity (Component);
10791 end Trace_Components;
10793 -- Start of processing for Private_Component
10796 return Trace_Components (Type_Id, False);
10797 end Private_Component;
10799 ---------------------------
10800 -- Primitive_Names_Match --
10801 ---------------------------
10803 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10805 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10806 -- Given an internal name, returns the corresponding non-internal name
10808 ------------------------
10809 -- Non_Internal_Name --
10810 ------------------------
10812 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10814 Get_Name_String (Chars (E));
10815 Name_Len := Name_Len - 1;
10817 end Non_Internal_Name;
10819 -- Start of processing for Primitive_Names_Match
10822 pragma Assert (Present (E1) and then Present (E2));
10824 return Chars (E1) = Chars (E2)
10826 (not Is_Internal_Name (Chars (E1))
10827 and then Is_Internal_Name (Chars (E2))
10828 and then Non_Internal_Name (E2) = Chars (E1))
10830 (not Is_Internal_Name (Chars (E2))
10831 and then Is_Internal_Name (Chars (E1))
10832 and then Non_Internal_Name (E1) = Chars (E2))
10834 (Is_Predefined_Dispatching_Operation (E1)
10835 and then Is_Predefined_Dispatching_Operation (E2)
10836 and then Same_TSS (E1, E2))
10838 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10839 end Primitive_Names_Match;
10841 -----------------------
10842 -- Process_End_Label --
10843 -----------------------
10845 procedure Process_End_Label
10854 Label_Ref : Boolean;
10855 -- Set True if reference to end label itself is required
10858 -- Gets set to the operator symbol or identifier that references the
10859 -- entity Ent. For the child unit case, this is the identifier from the
10860 -- designator. For other cases, this is simply Endl.
10862 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10863 -- N is an identifier node that appears as a parent unit reference in
10864 -- the case where Ent is a child unit. This procedure generates an
10865 -- appropriate cross-reference entry. E is the corresponding entity.
10867 -------------------------
10868 -- Generate_Parent_Ref --
10869 -------------------------
10871 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10873 -- If names do not match, something weird, skip reference
10875 if Chars (E) = Chars (N) then
10877 -- Generate the reference. We do NOT consider this as a reference
10878 -- for unreferenced symbol purposes.
10880 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10882 if Style_Check then
10883 Style.Check_Identifier (N, E);
10886 end Generate_Parent_Ref;
10888 -- Start of processing for Process_End_Label
10891 -- If no node, ignore. This happens in some error situations, and
10892 -- also for some internally generated structures where no end label
10893 -- references are required in any case.
10899 -- Nothing to do if no End_Label, happens for internally generated
10900 -- constructs where we don't want an end label reference anyway. Also
10901 -- nothing to do if Endl is a string literal, which means there was
10902 -- some prior error (bad operator symbol)
10904 Endl := End_Label (N);
10906 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10910 -- Reference node is not in extended main source unit
10912 if not In_Extended_Main_Source_Unit (N) then
10914 -- Generally we do not collect references except for the extended
10915 -- main source unit. The one exception is the 'e' entry for a
10916 -- package spec, where it is useful for a client to have the
10917 -- ending information to define scopes.
10923 Label_Ref := False;
10925 -- For this case, we can ignore any parent references, but we
10926 -- need the package name itself for the 'e' entry.
10928 if Nkind (Endl) = N_Designator then
10929 Endl := Identifier (Endl);
10933 -- Reference is in extended main source unit
10938 -- For designator, generate references for the parent entries
10940 if Nkind (Endl) = N_Designator then
10942 -- Generate references for the prefix if the END line comes from
10943 -- source (otherwise we do not need these references) We climb the
10944 -- scope stack to find the expected entities.
10946 if Comes_From_Source (Endl) then
10947 Nam := Name (Endl);
10948 Scop := Current_Scope;
10949 while Nkind (Nam) = N_Selected_Component loop
10950 Scop := Scope (Scop);
10951 exit when No (Scop);
10952 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10953 Nam := Prefix (Nam);
10956 if Present (Scop) then
10957 Generate_Parent_Ref (Nam, Scope (Scop));
10961 Endl := Identifier (Endl);
10965 -- If the end label is not for the given entity, then either we have
10966 -- some previous error, or this is a generic instantiation for which
10967 -- we do not need to make a cross-reference in this case anyway. In
10968 -- either case we simply ignore the call.
10970 if Chars (Ent) /= Chars (Endl) then
10974 -- If label was really there, then generate a normal reference and then
10975 -- adjust the location in the end label to point past the name (which
10976 -- should almost always be the semicolon).
10978 Loc := Sloc (Endl);
10980 if Comes_From_Source (Endl) then
10982 -- If a label reference is required, then do the style check and
10983 -- generate an l-type cross-reference entry for the label
10986 if Style_Check then
10987 Style.Check_Identifier (Endl, Ent);
10990 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10993 -- Set the location to point past the label (normally this will
10994 -- mean the semicolon immediately following the label). This is
10995 -- done for the sake of the 'e' or 't' entry generated below.
10997 Get_Decoded_Name_String (Chars (Endl));
10998 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
11001 -- In SPARK mode, no missing label is allowed for packages and
11002 -- subprogram bodies. Detect those cases by testing whether
11003 -- Process_End_Label was called for a body (Typ = 't') or a package.
11005 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
11006 and then (Typ = 't' or else Ekind (Ent) = E_Package)
11008 Error_Msg_Node_1 := Endl;
11009 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
11013 -- Now generate the e/t reference
11015 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
11017 -- Restore Sloc, in case modified above, since we have an identifier
11018 -- and the normal Sloc should be left set in the tree.
11020 Set_Sloc (Endl, Loc);
11021 end Process_End_Label;
11023 ------------------------------------
11024 -- References_Generic_Formal_Type --
11025 ------------------------------------
11027 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11029 function Process (N : Node_Id) return Traverse_Result;
11030 -- Process one node in search for generic formal type
11036 function Process (N : Node_Id) return Traverse_Result is
11038 if Nkind (N) in N_Has_Entity then
11040 E : constant Entity_Id := Entity (N);
11042 if Present (E) then
11043 if Is_Generic_Type (E) then
11045 elsif Present (Etype (E))
11046 and then Is_Generic_Type (Etype (E))
11057 function Traverse is new Traverse_Func (Process);
11058 -- Traverse tree to look for generic type
11061 if Inside_A_Generic then
11062 return Traverse (N) = Abandon;
11066 end References_Generic_Formal_Type;
11068 --------------------
11069 -- Remove_Homonym --
11070 --------------------
11072 procedure Remove_Homonym (E : Entity_Id) is
11073 Prev : Entity_Id := Empty;
11077 if E = Current_Entity (E) then
11078 if Present (Homonym (E)) then
11079 Set_Current_Entity (Homonym (E));
11081 Set_Name_Entity_Id (Chars (E), Empty);
11084 H := Current_Entity (E);
11085 while Present (H) and then H /= E loop
11090 Set_Homonym (Prev, Homonym (E));
11092 end Remove_Homonym;
11094 ---------------------
11095 -- Rep_To_Pos_Flag --
11096 ---------------------
11098 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11100 return New_Occurrence_Of
11101 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11102 end Rep_To_Pos_Flag;
11104 --------------------
11105 -- Require_Entity --
11106 --------------------
11108 procedure Require_Entity (N : Node_Id) is
11110 if Is_Entity_Name (N) and then No (Entity (N)) then
11111 if Total_Errors_Detected /= 0 then
11112 Set_Entity (N, Any_Id);
11114 raise Program_Error;
11117 end Require_Entity;
11119 ------------------------------
11120 -- Requires_Transient_Scope --
11121 ------------------------------
11123 -- A transient scope is required when variable-sized temporaries are
11124 -- allocated in the primary or secondary stack, or when finalization
11125 -- actions must be generated before the next instruction.
11127 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11128 Typ : constant Entity_Id := Underlying_Type (Id);
11130 -- Start of processing for Requires_Transient_Scope
11133 -- This is a private type which is not completed yet. This can only
11134 -- happen in a default expression (of a formal parameter or of a
11135 -- record component). Do not expand transient scope in this case
11140 -- Do not expand transient scope for non-existent procedure return
11142 elsif Typ = Standard_Void_Type then
11145 -- Elementary types do not require a transient scope
11147 elsif Is_Elementary_Type (Typ) then
11150 -- Generally, indefinite subtypes require a transient scope, since the
11151 -- back end cannot generate temporaries, since this is not a valid type
11152 -- for declaring an object. It might be possible to relax this in the
11153 -- future, e.g. by declaring the maximum possible space for the type.
11155 elsif Is_Indefinite_Subtype (Typ) then
11158 -- Functions returning tagged types may dispatch on result so their
11159 -- returned value is allocated on the secondary stack. Controlled
11160 -- type temporaries need finalization.
11162 elsif Is_Tagged_Type (Typ)
11163 or else Has_Controlled_Component (Typ)
11165 return not Is_Value_Type (Typ);
11169 elsif Is_Record_Type (Typ) then
11173 Comp := First_Entity (Typ);
11174 while Present (Comp) loop
11175 if Ekind (Comp) = E_Component
11176 and then Requires_Transient_Scope (Etype (Comp))
11180 Next_Entity (Comp);
11187 -- String literal types never require transient scope
11189 elsif Ekind (Typ) = E_String_Literal_Subtype then
11192 -- Array type. Note that we already know that this is a constrained
11193 -- array, since unconstrained arrays will fail the indefinite test.
11195 elsif Is_Array_Type (Typ) then
11197 -- If component type requires a transient scope, the array does too
11199 if Requires_Transient_Scope (Component_Type (Typ)) then
11202 -- Otherwise, we only need a transient scope if the size depends on
11203 -- the value of one or more discriminants.
11206 return Size_Depends_On_Discriminant (Typ);
11209 -- All other cases do not require a transient scope
11214 end Requires_Transient_Scope;
11216 --------------------------
11217 -- Reset_Analyzed_Flags --
11218 --------------------------
11220 procedure Reset_Analyzed_Flags (N : Node_Id) is
11222 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11223 -- Function used to reset Analyzed flags in tree. Note that we do
11224 -- not reset Analyzed flags in entities, since there is no need to
11225 -- reanalyze entities, and indeed, it is wrong to do so, since it
11226 -- can result in generating auxiliary stuff more than once.
11228 --------------------
11229 -- Clear_Analyzed --
11230 --------------------
11232 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11234 if not Has_Extension (N) then
11235 Set_Analyzed (N, False);
11239 end Clear_Analyzed;
11241 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11243 -- Start of processing for Reset_Analyzed_Flags
11246 Reset_Analyzed (N);
11247 end Reset_Analyzed_Flags;
11249 ---------------------------
11250 -- Safe_To_Capture_Value --
11251 ---------------------------
11253 function Safe_To_Capture_Value
11256 Cond : Boolean := False) return Boolean
11259 -- The only entities for which we track constant values are variables
11260 -- which are not renamings, constants, out parameters, and in out
11261 -- parameters, so check if we have this case.
11263 -- Note: it may seem odd to track constant values for constants, but in
11264 -- fact this routine is used for other purposes than simply capturing
11265 -- the value. In particular, the setting of Known[_Non]_Null.
11267 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11269 Ekind (Ent) = E_Constant
11271 Ekind (Ent) = E_Out_Parameter
11273 Ekind (Ent) = E_In_Out_Parameter
11277 -- For conditionals, we also allow loop parameters and all formals,
11278 -- including in parameters.
11282 (Ekind (Ent) = E_Loop_Parameter
11284 Ekind (Ent) = E_In_Parameter)
11288 -- For all other cases, not just unsafe, but impossible to capture
11289 -- Current_Value, since the above are the only entities which have
11290 -- Current_Value fields.
11296 -- Skip if volatile or aliased, since funny things might be going on in
11297 -- these cases which we cannot necessarily track. Also skip any variable
11298 -- for which an address clause is given, or whose address is taken. Also
11299 -- never capture value of library level variables (an attempt to do so
11300 -- can occur in the case of package elaboration code).
11302 if Treat_As_Volatile (Ent)
11303 or else Is_Aliased (Ent)
11304 or else Present (Address_Clause (Ent))
11305 or else Address_Taken (Ent)
11306 or else (Is_Library_Level_Entity (Ent)
11307 and then Ekind (Ent) = E_Variable)
11312 -- OK, all above conditions are met. We also require that the scope of
11313 -- the reference be the same as the scope of the entity, not counting
11314 -- packages and blocks and loops.
11317 E_Scope : constant Entity_Id := Scope (Ent);
11318 R_Scope : Entity_Id;
11321 R_Scope := Current_Scope;
11322 while R_Scope /= Standard_Standard loop
11323 exit when R_Scope = E_Scope;
11325 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11328 R_Scope := Scope (R_Scope);
11333 -- We also require that the reference does not appear in a context
11334 -- where it is not sure to be executed (i.e. a conditional context
11335 -- or an exception handler). We skip this if Cond is True, since the
11336 -- capturing of values from conditional tests handles this ok.
11350 while Present (P) loop
11351 if Nkind (P) = N_If_Statement
11352 or else Nkind (P) = N_Case_Statement
11353 or else (Nkind (P) in N_Short_Circuit
11354 and then Desc = Right_Opnd (P))
11355 or else (Nkind (P) = N_Conditional_Expression
11356 and then Desc /= First (Expressions (P)))
11357 or else Nkind (P) = N_Exception_Handler
11358 or else Nkind (P) = N_Selective_Accept
11359 or else Nkind (P) = N_Conditional_Entry_Call
11360 or else Nkind (P) = N_Timed_Entry_Call
11361 or else Nkind (P) = N_Asynchronous_Select
11371 -- OK, looks safe to set value
11374 end Safe_To_Capture_Value;
11380 function Same_Name (N1, N2 : Node_Id) return Boolean is
11381 K1 : constant Node_Kind := Nkind (N1);
11382 K2 : constant Node_Kind := Nkind (N2);
11385 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11386 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11388 return Chars (N1) = Chars (N2);
11390 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11391 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11393 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11394 and then Same_Name (Prefix (N1), Prefix (N2));
11405 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11406 N1 : constant Node_Id := Original_Node (Node1);
11407 N2 : constant Node_Id := Original_Node (Node2);
11408 -- We do the tests on original nodes, since we are most interested
11409 -- in the original source, not any expansion that got in the way.
11411 K1 : constant Node_Kind := Nkind (N1);
11412 K2 : constant Node_Kind := Nkind (N2);
11415 -- First case, both are entities with same entity
11417 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11419 EN1 : constant Entity_Id := Entity (N1);
11420 EN2 : constant Entity_Id := Entity (N2);
11422 if Present (EN1) and then Present (EN2)
11423 and then (Ekind_In (EN1, E_Variable, E_Constant)
11424 or else Is_Formal (EN1))
11432 -- Second case, selected component with same selector, same record
11434 if K1 = N_Selected_Component
11435 and then K2 = N_Selected_Component
11436 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11438 return Same_Object (Prefix (N1), Prefix (N2));
11440 -- Third case, indexed component with same subscripts, same array
11442 elsif K1 = N_Indexed_Component
11443 and then K2 = N_Indexed_Component
11444 and then Same_Object (Prefix (N1), Prefix (N2))
11449 E1 := First (Expressions (N1));
11450 E2 := First (Expressions (N2));
11451 while Present (E1) loop
11452 if not Same_Value (E1, E2) then
11463 -- Fourth case, slice of same array with same bounds
11466 and then K2 = N_Slice
11467 and then Nkind (Discrete_Range (N1)) = N_Range
11468 and then Nkind (Discrete_Range (N2)) = N_Range
11469 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11470 Low_Bound (Discrete_Range (N2)))
11471 and then Same_Value (High_Bound (Discrete_Range (N1)),
11472 High_Bound (Discrete_Range (N2)))
11474 return Same_Name (Prefix (N1), Prefix (N2));
11476 -- All other cases, not clearly the same object
11487 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11492 elsif not Is_Constrained (T1)
11493 and then not Is_Constrained (T2)
11494 and then Base_Type (T1) = Base_Type (T2)
11498 -- For now don't bother with case of identical constraints, to be
11499 -- fiddled with later on perhaps (this is only used for optimization
11500 -- purposes, so it is not critical to do a best possible job)
11511 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11513 if Compile_Time_Known_Value (Node1)
11514 and then Compile_Time_Known_Value (Node2)
11515 and then Expr_Value (Node1) = Expr_Value (Node2)
11518 elsif Same_Object (Node1, Node2) then
11529 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11531 if Ada_Version < Ada_2012 then
11534 elsif Is_Entity_Name (N)
11536 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11538 (Nkind (N) = N_Attribute_Reference
11539 and then Attribute_Name (N) = Name_Access)
11542 -- We are only interested in IN OUT parameters of inner calls
11545 or else Nkind (Parent (N)) = N_Function_Call
11546 or else Nkind (Parent (N)) in N_Op
11548 Actuals_In_Call.Increment_Last;
11549 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11554 ------------------------
11555 -- Scope_Is_Transient --
11556 ------------------------
11558 function Scope_Is_Transient return Boolean is
11560 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11561 end Scope_Is_Transient;
11567 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11572 while Scop /= Standard_Standard loop
11573 Scop := Scope (Scop);
11575 if Scop = Scope2 then
11583 --------------------------
11584 -- Scope_Within_Or_Same --
11585 --------------------------
11587 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11592 while Scop /= Standard_Standard loop
11593 if Scop = Scope2 then
11596 Scop := Scope (Scop);
11601 end Scope_Within_Or_Same;
11603 --------------------
11604 -- Set_Convention --
11605 --------------------
11607 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11609 Basic_Set_Convention (E, Val);
11612 and then Is_Access_Subprogram_Type (Base_Type (E))
11613 and then Has_Foreign_Convention (E)
11615 Set_Can_Use_Internal_Rep (E, False);
11617 end Set_Convention;
11619 ------------------------
11620 -- Set_Current_Entity --
11621 ------------------------
11623 -- The given entity is to be set as the currently visible definition
11624 -- of its associated name (i.e. the Node_Id associated with its name).
11625 -- All we have to do is to get the name from the identifier, and
11626 -- then set the associated Node_Id to point to the given entity.
11628 procedure Set_Current_Entity (E : Entity_Id) is
11630 Set_Name_Entity_Id (Chars (E), E);
11631 end Set_Current_Entity;
11633 ---------------------------
11634 -- Set_Debug_Info_Needed --
11635 ---------------------------
11637 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11639 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11640 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11641 -- Used to set debug info in a related node if not set already
11643 --------------------------------------
11644 -- Set_Debug_Info_Needed_If_Not_Set --
11645 --------------------------------------
11647 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11650 and then not Needs_Debug_Info (E)
11652 Set_Debug_Info_Needed (E);
11654 -- For a private type, indicate that the full view also needs
11655 -- debug information.
11658 and then Is_Private_Type (E)
11659 and then Present (Full_View (E))
11661 Set_Debug_Info_Needed (Full_View (E));
11664 end Set_Debug_Info_Needed_If_Not_Set;
11666 -- Start of processing for Set_Debug_Info_Needed
11669 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11670 -- indicates that Debug_Info_Needed is never required for the entity.
11673 or else Debug_Info_Off (T)
11678 -- Set flag in entity itself. Note that we will go through the following
11679 -- circuitry even if the flag is already set on T. That's intentional,
11680 -- it makes sure that the flag will be set in subsidiary entities.
11682 Set_Needs_Debug_Info (T);
11684 -- Set flag on subsidiary entities if not set already
11686 if Is_Object (T) then
11687 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11689 elsif Is_Type (T) then
11690 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11692 if Is_Record_Type (T) then
11694 Ent : Entity_Id := First_Entity (T);
11696 while Present (Ent) loop
11697 Set_Debug_Info_Needed_If_Not_Set (Ent);
11702 -- For a class wide subtype, we also need debug information
11703 -- for the equivalent type.
11705 if Ekind (T) = E_Class_Wide_Subtype then
11706 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11709 elsif Is_Array_Type (T) then
11710 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11713 Indx : Node_Id := First_Index (T);
11715 while Present (Indx) loop
11716 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11717 Indx := Next_Index (Indx);
11721 if Is_Packed (T) then
11722 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11725 elsif Is_Access_Type (T) then
11726 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11728 elsif Is_Private_Type (T) then
11729 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11731 elsif Is_Protected_Type (T) then
11732 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11735 end Set_Debug_Info_Needed;
11737 ---------------------------------
11738 -- Set_Entity_With_Style_Check --
11739 ---------------------------------
11741 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11742 Val_Actual : Entity_Id;
11746 Set_Entity (N, Val);
11749 and then not Suppress_Style_Checks (Val)
11750 and then not In_Instance
11752 if Nkind (N) = N_Identifier then
11754 elsif Nkind (N) = N_Expanded_Name then
11755 Nod := Selector_Name (N);
11760 -- A special situation arises for derived operations, where we want
11761 -- to do the check against the parent (since the Sloc of the derived
11762 -- operation points to the derived type declaration itself).
11765 while not Comes_From_Source (Val_Actual)
11766 and then Nkind (Val_Actual) in N_Entity
11767 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11768 or else Is_Subprogram (Val_Actual)
11769 or else Is_Generic_Subprogram (Val_Actual))
11770 and then Present (Alias (Val_Actual))
11772 Val_Actual := Alias (Val_Actual);
11775 -- Renaming declarations for generic actuals do not come from source,
11776 -- and have a different name from that of the entity they rename, so
11777 -- there is no style check to perform here.
11779 if Chars (Nod) = Chars (Val_Actual) then
11780 Style.Check_Identifier (Nod, Val_Actual);
11784 Set_Entity (N, Val);
11785 end Set_Entity_With_Style_Check;
11787 ------------------------
11788 -- Set_Name_Entity_Id --
11789 ------------------------
11791 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11793 Set_Name_Table_Info (Id, Int (Val));
11794 end Set_Name_Entity_Id;
11796 ---------------------
11797 -- Set_Next_Actual --
11798 ---------------------
11800 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11802 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11803 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11805 end Set_Next_Actual;
11807 ----------------------------------
11808 -- Set_Optimize_Alignment_Flags --
11809 ----------------------------------
11811 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11813 if Optimize_Alignment = 'S' then
11814 Set_Optimize_Alignment_Space (E);
11815 elsif Optimize_Alignment = 'T' then
11816 Set_Optimize_Alignment_Time (E);
11818 end Set_Optimize_Alignment_Flags;
11820 -----------------------
11821 -- Set_Public_Status --
11822 -----------------------
11824 procedure Set_Public_Status (Id : Entity_Id) is
11825 S : constant Entity_Id := Current_Scope;
11827 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11828 -- Determines if E is defined within handled statement sequence or
11829 -- an if statement, returns True if so, False otherwise.
11831 ----------------------
11832 -- Within_HSS_Or_If --
11833 ----------------------
11835 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11838 N := Declaration_Node (E);
11845 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11851 end Within_HSS_Or_If;
11853 -- Start of processing for Set_Public_Status
11856 -- Everything in the scope of Standard is public
11858 if S = Standard_Standard then
11859 Set_Is_Public (Id);
11861 -- Entity is definitely not public if enclosing scope is not public
11863 elsif not Is_Public (S) then
11866 -- An object or function declaration that occurs in a handled sequence
11867 -- of statements or within an if statement is the declaration for a
11868 -- temporary object or local subprogram generated by the expander. It
11869 -- never needs to be made public and furthermore, making it public can
11870 -- cause back end problems.
11872 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11873 N_Function_Specification)
11874 and then Within_HSS_Or_If (Id)
11878 -- Entities in public packages or records are public
11880 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11881 Set_Is_Public (Id);
11883 -- The bounds of an entry family declaration can generate object
11884 -- declarations that are visible to the back-end, e.g. in the
11885 -- the declaration of a composite type that contains tasks.
11887 elsif Is_Concurrent_Type (S)
11888 and then not Has_Completion (S)
11889 and then Nkind (Parent (Id)) = N_Object_Declaration
11891 Set_Is_Public (Id);
11893 end Set_Public_Status;
11895 -----------------------------
11896 -- Set_Referenced_Modified --
11897 -----------------------------
11899 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11903 -- Deal with indexed or selected component where prefix is modified
11905 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11906 Pref := Prefix (N);
11908 -- If prefix is access type, then it is the designated object that is
11909 -- being modified, which means we have no entity to set the flag on.
11911 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11914 -- Otherwise chase the prefix
11917 Set_Referenced_Modified (Pref, Out_Param);
11920 -- Otherwise see if we have an entity name (only other case to process)
11922 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11923 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11924 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11926 end Set_Referenced_Modified;
11928 ----------------------------
11929 -- Set_Scope_Is_Transient --
11930 ----------------------------
11932 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11934 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11935 end Set_Scope_Is_Transient;
11937 -------------------
11938 -- Set_Size_Info --
11939 -------------------
11941 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11943 -- We copy Esize, but not RM_Size, since in general RM_Size is
11944 -- subtype specific and does not get inherited by all subtypes.
11946 Set_Esize (T1, Esize (T2));
11947 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11949 if Is_Discrete_Or_Fixed_Point_Type (T1)
11951 Is_Discrete_Or_Fixed_Point_Type (T2)
11953 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11956 Set_Alignment (T1, Alignment (T2));
11959 --------------------
11960 -- Static_Boolean --
11961 --------------------
11963 function Static_Boolean (N : Node_Id) return Uint is
11965 Analyze_And_Resolve (N, Standard_Boolean);
11968 or else Error_Posted (N)
11969 or else Etype (N) = Any_Type
11974 if Is_Static_Expression (N) then
11975 if not Raises_Constraint_Error (N) then
11976 return Expr_Value (N);
11981 elsif Etype (N) = Any_Type then
11985 Flag_Non_Static_Expr
11986 ("static boolean expression required here", N);
11989 end Static_Boolean;
11991 --------------------
11992 -- Static_Integer --
11993 --------------------
11995 function Static_Integer (N : Node_Id) return Uint is
11997 Analyze_And_Resolve (N, Any_Integer);
12000 or else Error_Posted (N)
12001 or else Etype (N) = Any_Type
12006 if Is_Static_Expression (N) then
12007 if not Raises_Constraint_Error (N) then
12008 return Expr_Value (N);
12013 elsif Etype (N) = Any_Type then
12017 Flag_Non_Static_Expr
12018 ("static integer expression required here", N);
12021 end Static_Integer;
12023 --------------------------
12024 -- Statically_Different --
12025 --------------------------
12027 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12028 R1 : constant Node_Id := Get_Referenced_Object (E1);
12029 R2 : constant Node_Id := Get_Referenced_Object (E2);
12031 return Is_Entity_Name (R1)
12032 and then Is_Entity_Name (R2)
12033 and then Entity (R1) /= Entity (R2)
12034 and then not Is_Formal (Entity (R1))
12035 and then not Is_Formal (Entity (R2));
12036 end Statically_Different;
12038 -----------------------------
12039 -- Subprogram_Access_Level --
12040 -----------------------------
12042 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12044 if Present (Alias (Subp)) then
12045 return Subprogram_Access_Level (Alias (Subp));
12047 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12049 end Subprogram_Access_Level;
12055 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12057 if Debug_Flag_W then
12058 for J in 0 .. Scope_Stack.Last loop
12063 Write_Name (Chars (E));
12064 Write_Str (" from ");
12065 Write_Location (Sloc (N));
12070 -----------------------
12071 -- Transfer_Entities --
12072 -----------------------
12074 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12075 Ent : Entity_Id := First_Entity (From);
12082 if (Last_Entity (To)) = Empty then
12083 Set_First_Entity (To, Ent);
12085 Set_Next_Entity (Last_Entity (To), Ent);
12088 Set_Last_Entity (To, Last_Entity (From));
12090 while Present (Ent) loop
12091 Set_Scope (Ent, To);
12093 if not Is_Public (Ent) then
12094 Set_Public_Status (Ent);
12097 and then Ekind (Ent) = E_Record_Subtype
12100 -- The components of the propagated Itype must be public
12106 Comp := First_Entity (Ent);
12107 while Present (Comp) loop
12108 Set_Is_Public (Comp);
12109 Next_Entity (Comp);
12118 Set_First_Entity (From, Empty);
12119 Set_Last_Entity (From, Empty);
12120 end Transfer_Entities;
12122 -----------------------
12123 -- Type_Access_Level --
12124 -----------------------
12126 function Type_Access_Level (Typ : Entity_Id) return Uint is
12130 Btyp := Base_Type (Typ);
12132 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12133 -- simply use the level where the type is declared. This is true for
12134 -- stand-alone object declarations, and for anonymous access types
12135 -- associated with components the level is the same as that of the
12136 -- enclosing composite type. However, special treatment is needed for
12137 -- the cases of access parameters, return objects of an anonymous access
12138 -- type, and, in Ada 95, access discriminants of limited types.
12140 if Ekind (Btyp) in Access_Kind then
12141 if Ekind (Btyp) = E_Anonymous_Access_Type then
12143 -- If the type is a nonlocal anonymous access type (such as for
12144 -- an access parameter) we treat it as being declared at the
12145 -- library level to ensure that names such as X.all'access don't
12146 -- fail static accessibility checks.
12148 if not Is_Local_Anonymous_Access (Typ) then
12149 return Scope_Depth (Standard_Standard);
12151 -- If this is a return object, the accessibility level is that of
12152 -- the result subtype of the enclosing function. The test here is
12153 -- little complicated, because we have to account for extended
12154 -- return statements that have been rewritten as blocks, in which
12155 -- case we have to find and the Is_Return_Object attribute of the
12156 -- itype's associated object. It would be nice to find a way to
12157 -- simplify this test, but it doesn't seem worthwhile to add a new
12158 -- flag just for purposes of this test. ???
12160 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12163 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12164 N_Object_Declaration
12165 and then Is_Return_Object
12166 (Defining_Identifier
12167 (Associated_Node_For_Itype (Btyp))))
12173 Scop := Scope (Scope (Btyp));
12174 while Present (Scop) loop
12175 exit when Ekind (Scop) = E_Function;
12176 Scop := Scope (Scop);
12179 -- Treat the return object's type as having the level of the
12180 -- function's result subtype (as per RM05-6.5(5.3/2)).
12182 return Type_Access_Level (Etype (Scop));
12187 Btyp := Root_Type (Btyp);
12189 -- The accessibility level of anonymous access types associated with
12190 -- discriminants is that of the current instance of the type, and
12191 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12193 -- AI-402: access discriminants have accessibility based on the
12194 -- object rather than the type in Ada 2005, so the above paragraph
12197 -- ??? Needs completion with rules from AI-416
12199 if Ada_Version <= Ada_95
12200 and then Ekind (Typ) = E_Anonymous_Access_Type
12201 and then Present (Associated_Node_For_Itype (Typ))
12202 and then Nkind (Associated_Node_For_Itype (Typ)) =
12203 N_Discriminant_Specification
12205 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12209 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12210 end Type_Access_Level;
12212 --------------------------
12213 -- Unit_Declaration_Node --
12214 --------------------------
12216 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12217 N : Node_Id := Parent (Unit_Id);
12220 -- Predefined operators do not have a full function declaration
12222 if Ekind (Unit_Id) = E_Operator then
12226 -- Isn't there some better way to express the following ???
12228 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12229 and then Nkind (N) /= N_Formal_Package_Declaration
12230 and then Nkind (N) /= N_Function_Instantiation
12231 and then Nkind (N) /= N_Generic_Package_Declaration
12232 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12233 and then Nkind (N) /= N_Package_Declaration
12234 and then Nkind (N) /= N_Package_Body
12235 and then Nkind (N) /= N_Package_Instantiation
12236 and then Nkind (N) /= N_Package_Renaming_Declaration
12237 and then Nkind (N) /= N_Procedure_Instantiation
12238 and then Nkind (N) /= N_Protected_Body
12239 and then Nkind (N) /= N_Subprogram_Declaration
12240 and then Nkind (N) /= N_Subprogram_Body
12241 and then Nkind (N) /= N_Subprogram_Body_Stub
12242 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12243 and then Nkind (N) /= N_Task_Body
12244 and then Nkind (N) /= N_Task_Type_Declaration
12245 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12246 and then Nkind (N) not in N_Generic_Renaming_Declaration
12249 pragma Assert (Present (N));
12253 end Unit_Declaration_Node;
12255 ---------------------
12256 -- Unit_Is_Visible --
12257 ---------------------
12259 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12260 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12261 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12263 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12264 -- For a child unit, check whether unit appears in a with_clause
12267 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12268 -- Scan the context clause of one compilation unit looking for a
12269 -- with_clause for the unit in question.
12271 ----------------------------
12272 -- Unit_In_Parent_Context --
12273 ----------------------------
12275 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12277 if Unit_In_Context (Par_Unit) then
12280 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12281 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12286 end Unit_In_Parent_Context;
12288 ---------------------
12289 -- Unit_In_Context --
12290 ---------------------
12292 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12296 Clause := First (Context_Items (Comp_Unit));
12297 while Present (Clause) loop
12298 if Nkind (Clause) = N_With_Clause then
12299 if Library_Unit (Clause) = U then
12302 -- The with_clause may denote a renaming of the unit we are
12303 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12306 Renamed_Entity (Entity (Name (Clause))) =
12307 Defining_Entity (Unit (U))
12317 end Unit_In_Context;
12319 -- Start of processing for Unit_Is_Visible
12322 -- The currrent unit is directly visible.
12327 elsif Unit_In_Context (Curr) then
12330 -- If the current unit is a body, check the context of the spec.
12332 elsif Nkind (Unit (Curr)) = N_Package_Body
12334 (Nkind (Unit (Curr)) = N_Subprogram_Body
12335 and then not Acts_As_Spec (Unit (Curr)))
12337 if Unit_In_Context (Library_Unit (Curr)) then
12342 -- If the spec is a child unit, examine the parents.
12344 if Is_Child_Unit (Curr_Entity) then
12345 if Nkind (Unit (Curr)) in N_Unit_Body then
12347 Unit_In_Parent_Context
12348 (Parent_Spec (Unit (Library_Unit (Curr))));
12350 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12356 end Unit_Is_Visible;
12358 ------------------------------
12359 -- Universal_Interpretation --
12360 ------------------------------
12362 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12363 Index : Interp_Index;
12367 -- The argument may be a formal parameter of an operator or subprogram
12368 -- with multiple interpretations, or else an expression for an actual.
12370 if Nkind (Opnd) = N_Defining_Identifier
12371 or else not Is_Overloaded (Opnd)
12373 if Etype (Opnd) = Universal_Integer
12374 or else Etype (Opnd) = Universal_Real
12376 return Etype (Opnd);
12382 Get_First_Interp (Opnd, Index, It);
12383 while Present (It.Typ) loop
12384 if It.Typ = Universal_Integer
12385 or else It.Typ = Universal_Real
12390 Get_Next_Interp (Index, It);
12395 end Universal_Interpretation;
12401 function Unqualify (Expr : Node_Id) return Node_Id is
12403 -- Recurse to handle unlikely case of multiple levels of qualification
12405 if Nkind (Expr) = N_Qualified_Expression then
12406 return Unqualify (Expression (Expr));
12408 -- Normal case, not a qualified expression
12415 -----------------------
12416 -- Visible_Ancestors --
12417 -----------------------
12419 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12425 pragma Assert (Is_Record_Type (Typ)
12426 and then Is_Tagged_Type (Typ));
12428 -- Collect all the parents and progenitors of Typ. If the full-view of
12429 -- private parents and progenitors is available then it is used to
12430 -- generate the list of visible ancestors; otherwise their partial
12431 -- view is added to the resulting list.
12436 Use_Full_View => True);
12440 Ifaces_List => List_2,
12441 Exclude_Parents => True,
12442 Use_Full_View => True);
12444 -- Join the two lists. Avoid duplications because an interface may
12445 -- simultaneously be parent and progenitor of a type.
12447 Elmt := First_Elmt (List_2);
12448 while Present (Elmt) loop
12449 Append_Unique_Elmt (Node (Elmt), List_1);
12454 end Visible_Ancestors;
12456 ----------------------
12457 -- Within_Init_Proc --
12458 ----------------------
12460 function Within_Init_Proc return Boolean is
12464 S := Current_Scope;
12465 while not Is_Overloadable (S) loop
12466 if S = Standard_Standard then
12473 return Is_Init_Proc (S);
12474 end Within_Init_Proc;
12480 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12481 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12482 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12484 Matching_Field : Entity_Id;
12485 -- Entity to give a more precise suggestion on how to write a one-
12486 -- element positional aggregate.
12488 function Has_One_Matching_Field return Boolean;
12489 -- Determines if Expec_Type is a record type with a single component or
12490 -- discriminant whose type matches the found type or is one dimensional
12491 -- array whose component type matches the found type.
12493 ----------------------------
12494 -- Has_One_Matching_Field --
12495 ----------------------------
12497 function Has_One_Matching_Field return Boolean is
12501 Matching_Field := Empty;
12503 if Is_Array_Type (Expec_Type)
12504 and then Number_Dimensions (Expec_Type) = 1
12506 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12508 -- Use type name if available. This excludes multidimensional
12509 -- arrays and anonymous arrays.
12511 if Comes_From_Source (Expec_Type) then
12512 Matching_Field := Expec_Type;
12514 -- For an assignment, use name of target.
12516 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
12517 and then Is_Entity_Name (Name (Parent (Expr)))
12519 Matching_Field := Entity (Name (Parent (Expr)));
12524 elsif not Is_Record_Type (Expec_Type) then
12528 E := First_Entity (Expec_Type);
12533 elsif (Ekind (E) /= E_Discriminant
12534 and then Ekind (E) /= E_Component)
12535 or else (Chars (E) = Name_uTag
12536 or else Chars (E) = Name_uParent)
12545 if not Covers (Etype (E), Found_Type) then
12548 elsif Present (Next_Entity (E)) then
12552 Matching_Field := E;
12556 end Has_One_Matching_Field;
12558 -- Start of processing for Wrong_Type
12561 -- Don't output message if either type is Any_Type, or if a message
12562 -- has already been posted for this node. We need to do the latter
12563 -- check explicitly (it is ordinarily done in Errout), because we
12564 -- are using ! to force the output of the error messages.
12566 if Expec_Type = Any_Type
12567 or else Found_Type = Any_Type
12568 or else Error_Posted (Expr)
12572 -- In an instance, there is an ongoing problem with completion of
12573 -- type derived from private types. Their structure is what Gigi
12574 -- expects, but the Etype is the parent type rather than the
12575 -- derived private type itself. Do not flag error in this case. The
12576 -- private completion is an entity without a parent, like an Itype.
12577 -- Similarly, full and partial views may be incorrect in the instance.
12578 -- There is no simple way to insure that it is consistent ???
12580 elsif In_Instance then
12581 if Etype (Etype (Expr)) = Etype (Expected_Type)
12583 (Has_Private_Declaration (Expected_Type)
12584 or else Has_Private_Declaration (Etype (Expr)))
12585 and then No (Parent (Expected_Type))
12591 -- An interesting special check. If the expression is parenthesized
12592 -- and its type corresponds to the type of the sole component of the
12593 -- expected record type, or to the component type of the expected one
12594 -- dimensional array type, then assume we have a bad aggregate attempt.
12596 if Nkind (Expr) in N_Subexpr
12597 and then Paren_Count (Expr) /= 0
12598 and then Has_One_Matching_Field
12600 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12601 if Present (Matching_Field) then
12602 if Is_Array_Type (Expec_Type) then
12604 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
12608 ("\write instead `& ='> ...`", Expr, Matching_Field);
12612 -- Another special check, if we are looking for a pool-specific access
12613 -- type and we found an E_Access_Attribute_Type, then we have the case
12614 -- of an Access attribute being used in a context which needs a pool-
12615 -- specific type, which is never allowed. The one extra check we make
12616 -- is that the expected designated type covers the Found_Type.
12618 elsif Is_Access_Type (Expec_Type)
12619 and then Ekind (Found_Type) = E_Access_Attribute_Type
12620 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12621 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12623 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12625 Error_Msg_N -- CODEFIX
12626 ("result must be general access type!", Expr);
12627 Error_Msg_NE -- CODEFIX
12628 ("add ALL to }!", Expr, Expec_Type);
12630 -- Another special check, if the expected type is an integer type,
12631 -- but the expression is of type System.Address, and the parent is
12632 -- an addition or subtraction operation whose left operand is the
12633 -- expression in question and whose right operand is of an integral
12634 -- type, then this is an attempt at address arithmetic, so give
12635 -- appropriate message.
12637 elsif Is_Integer_Type (Expec_Type)
12638 and then Is_RTE (Found_Type, RE_Address)
12639 and then (Nkind (Parent (Expr)) = N_Op_Add
12641 Nkind (Parent (Expr)) = N_Op_Subtract)
12642 and then Expr = Left_Opnd (Parent (Expr))
12643 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12646 ("address arithmetic not predefined in package System",
12649 ("\possible missing with/use of System.Storage_Elements",
12653 -- If the expected type is an anonymous access type, as for access
12654 -- parameters and discriminants, the error is on the designated types.
12656 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12657 if Comes_From_Source (Expec_Type) then
12658 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12661 ("expected an access type with designated}",
12662 Expr, Designated_Type (Expec_Type));
12665 if Is_Access_Type (Found_Type)
12666 and then not Comes_From_Source (Found_Type)
12669 ("\\found an access type with designated}!",
12670 Expr, Designated_Type (Found_Type));
12672 if From_With_Type (Found_Type) then
12673 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12674 Error_Msg_Qual_Level := 99;
12675 Error_Msg_NE -- CODEFIX
12676 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12677 Error_Msg_Qual_Level := 0;
12679 Error_Msg_NE ("found}!", Expr, Found_Type);
12683 -- Normal case of one type found, some other type expected
12686 -- If the names of the two types are the same, see if some number
12687 -- of levels of qualification will help. Don't try more than three
12688 -- levels, and if we get to standard, it's no use (and probably
12689 -- represents an error in the compiler) Also do not bother with
12690 -- internal scope names.
12693 Expec_Scope : Entity_Id;
12694 Found_Scope : Entity_Id;
12697 Expec_Scope := Expec_Type;
12698 Found_Scope := Found_Type;
12700 for Levels in Int range 0 .. 3 loop
12701 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12702 Error_Msg_Qual_Level := Levels;
12706 Expec_Scope := Scope (Expec_Scope);
12707 Found_Scope := Scope (Found_Scope);
12709 exit when Expec_Scope = Standard_Standard
12710 or else Found_Scope = Standard_Standard
12711 or else not Comes_From_Source (Expec_Scope)
12712 or else not Comes_From_Source (Found_Scope);
12716 if Is_Record_Type (Expec_Type)
12717 and then Present (Corresponding_Remote_Type (Expec_Type))
12719 Error_Msg_NE ("expected}!", Expr,
12720 Corresponding_Remote_Type (Expec_Type));
12722 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12725 if Is_Entity_Name (Expr)
12726 and then Is_Package_Or_Generic_Package (Entity (Expr))
12728 Error_Msg_N ("\\found package name!", Expr);
12730 elsif Is_Entity_Name (Expr)
12732 (Ekind (Entity (Expr)) = E_Procedure
12734 Ekind (Entity (Expr)) = E_Generic_Procedure)
12736 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12738 ("found procedure name, possibly missing Access attribute!",
12742 ("\\found procedure name instead of function!", Expr);
12745 elsif Nkind (Expr) = N_Function_Call
12746 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12747 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12748 and then No (Parameter_Associations (Expr))
12751 ("found function name, possibly missing Access attribute!",
12754 -- Catch common error: a prefix or infix operator which is not
12755 -- directly visible because the type isn't.
12757 elsif Nkind (Expr) in N_Op
12758 and then Is_Overloaded (Expr)
12759 and then not Is_Immediately_Visible (Expec_Type)
12760 and then not Is_Potentially_Use_Visible (Expec_Type)
12761 and then not In_Use (Expec_Type)
12762 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12765 ("operator of the type is not directly visible!", Expr);
12767 elsif Ekind (Found_Type) = E_Void
12768 and then Present (Parent (Found_Type))
12769 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12771 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12774 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12777 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12778 -- of the same modular type, and (M1 and M2) = 0 was intended.
12780 if Expec_Type = Standard_Boolean
12781 and then Is_Modular_Integer_Type (Found_Type)
12782 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12783 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12786 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12787 L : constant Node_Id := Left_Opnd (Op);
12788 R : constant Node_Id := Right_Opnd (Op);
12790 -- The case for the message is when the left operand of the
12791 -- comparison is the same modular type, or when it is an
12792 -- integer literal (or other universal integer expression),
12793 -- which would have been typed as the modular type if the
12794 -- parens had been there.
12796 if (Etype (L) = Found_Type
12798 Etype (L) = Universal_Integer)
12799 and then Is_Integer_Type (Etype (R))
12802 ("\\possible missing parens for modular operation", Expr);
12807 -- Reset error message qualification indication
12809 Error_Msg_Qual_Level := 0;