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;
145 -- Perform the action for Mark_Non_ALFA_Subprogram_Body, which allows the
146 -- latter to be small and inlined.
148 ------------------------------
149 -- Abstract_Interface_List --
150 ------------------------------
152 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
156 if Is_Concurrent_Type (Typ) then
158 -- If we are dealing with a synchronized subtype, go to the base
159 -- type, whose declaration has the interface list.
161 -- Shouldn't this be Declaration_Node???
163 Nod := Parent (Base_Type (Typ));
165 if Nkind (Nod) = N_Full_Type_Declaration then
169 elsif Ekind (Typ) = E_Record_Type_With_Private then
170 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
171 Nod := Type_Definition (Parent (Typ));
173 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
174 if Present (Full_View (Typ))
175 and then Nkind (Parent (Full_View (Typ)))
176 = N_Full_Type_Declaration
178 Nod := Type_Definition (Parent (Full_View (Typ)));
180 -- If the full-view is not available we cannot do anything else
181 -- here (the source has errors).
187 -- Support for generic formals with interfaces is still missing ???
189 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
194 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
198 elsif Ekind (Typ) = E_Record_Subtype then
199 Nod := Type_Definition (Parent (Etype (Typ)));
201 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
203 -- Recurse, because parent may still be a private extension. Also
204 -- note that the full view of the subtype or the full view of its
205 -- base type may (both) be unavailable.
207 return Abstract_Interface_List (Etype (Typ));
209 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
210 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
211 Nod := Formal_Type_Definition (Parent (Typ));
213 Nod := Type_Definition (Parent (Typ));
217 return Interface_List (Nod);
218 end Abstract_Interface_List;
220 --------------------------------
221 -- Add_Access_Type_To_Process --
222 --------------------------------
224 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
228 Ensure_Freeze_Node (E);
229 L := Access_Types_To_Process (Freeze_Node (E));
233 Set_Access_Types_To_Process (Freeze_Node (E), L);
237 end Add_Access_Type_To_Process;
239 ----------------------------
240 -- Add_Global_Declaration --
241 ----------------------------
243 procedure Add_Global_Declaration (N : Node_Id) is
244 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
247 if No (Declarations (Aux_Node)) then
248 Set_Declarations (Aux_Node, New_List);
251 Append_To (Declarations (Aux_Node), N);
253 end Add_Global_Declaration;
259 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
261 function Addressable (V : Uint) return Boolean is
263 return V = Uint_8 or else
269 function Addressable (V : Int) return Boolean is
277 -----------------------
278 -- Alignment_In_Bits --
279 -----------------------
281 function Alignment_In_Bits (E : Entity_Id) return Uint is
283 return Alignment (E) * System_Storage_Unit;
284 end Alignment_In_Bits;
286 -----------------------------------------
287 -- Apply_Compile_Time_Constraint_Error --
288 -----------------------------------------
290 procedure Apply_Compile_Time_Constraint_Error
293 Reason : RT_Exception_Code;
294 Ent : Entity_Id := Empty;
295 Typ : Entity_Id := Empty;
296 Loc : Source_Ptr := No_Location;
297 Rep : Boolean := True;
298 Warn : Boolean := False)
300 Stat : constant Boolean := Is_Static_Expression (N);
301 R_Stat : constant Node_Id :=
302 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
313 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
319 -- Now we replace the node by an N_Raise_Constraint_Error node
320 -- This does not need reanalyzing, so set it as analyzed now.
323 Set_Analyzed (N, True);
326 Set_Raises_Constraint_Error (N);
328 -- Now deal with possible local raise handling
330 Possible_Local_Raise (N, Standard_Constraint_Error);
332 -- If the original expression was marked as static, the result is
333 -- still marked as static, but the Raises_Constraint_Error flag is
334 -- always set so that further static evaluation is not attempted.
337 Set_Is_Static_Expression (N);
339 end Apply_Compile_Time_Constraint_Error;
341 --------------------------------
342 -- Bad_Predicated_Subtype_Use --
343 --------------------------------
345 procedure Bad_Predicated_Subtype_Use
351 if Has_Predicates (Typ) then
352 if Is_Generic_Actual_Type (Typ) then
353 Error_Msg_FE (Msg & '?', N, Typ);
354 Error_Msg_F ("\Program_Error will be raised at run time?", N);
356 Make_Raise_Program_Error (Sloc (N),
357 Reason => PE_Bad_Predicated_Generic_Type));
360 Error_Msg_FE (Msg, N, Typ);
363 end Bad_Predicated_Subtype_Use;
365 --------------------------
366 -- Build_Actual_Subtype --
367 --------------------------
369 function Build_Actual_Subtype
371 N : Node_Or_Entity_Id) return Node_Id
374 -- Normally Sloc (N), but may point to corresponding body in some cases
376 Constraints : List_Id;
382 Disc_Type : Entity_Id;
388 if Nkind (N) = N_Defining_Identifier then
389 Obj := New_Reference_To (N, Loc);
391 -- If this is a formal parameter of a subprogram declaration, and
392 -- we are compiling the body, we want the declaration for the
393 -- actual subtype to carry the source position of the body, to
394 -- prevent anomalies in gdb when stepping through the code.
396 if Is_Formal (N) then
398 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
400 if Nkind (Decl) = N_Subprogram_Declaration
401 and then Present (Corresponding_Body (Decl))
403 Loc := Sloc (Corresponding_Body (Decl));
412 if Is_Array_Type (T) then
413 Constraints := New_List;
414 for J in 1 .. Number_Dimensions (T) loop
416 -- Build an array subtype declaration with the nominal subtype and
417 -- the bounds of the actual. Add the declaration in front of the
418 -- local declarations for the subprogram, for analysis before any
419 -- reference to the formal in the body.
422 Make_Attribute_Reference (Loc,
424 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
425 Attribute_Name => Name_First,
426 Expressions => New_List (
427 Make_Integer_Literal (Loc, J)));
430 Make_Attribute_Reference (Loc,
432 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
433 Attribute_Name => Name_Last,
434 Expressions => New_List (
435 Make_Integer_Literal (Loc, J)));
437 Append (Make_Range (Loc, Lo, Hi), Constraints);
440 -- If the type has unknown discriminants there is no constrained
441 -- subtype to build. This is never called for a formal or for a
442 -- lhs, so returning the type is ok ???
444 elsif Has_Unknown_Discriminants (T) then
448 Constraints := New_List;
450 -- Type T is a generic derived type, inherit the discriminants from
453 if Is_Private_Type (T)
454 and then No (Full_View (T))
456 -- T was flagged as an error if it was declared as a formal
457 -- derived type with known discriminants. In this case there
458 -- is no need to look at the parent type since T already carries
459 -- its own discriminants.
461 and then not Error_Posted (T)
463 Disc_Type := Etype (Base_Type (T));
468 Discr := First_Discriminant (Disc_Type);
469 while Present (Discr) loop
470 Append_To (Constraints,
471 Make_Selected_Component (Loc,
473 Duplicate_Subexpr_No_Checks (Obj),
474 Selector_Name => New_Occurrence_Of (Discr, Loc)));
475 Next_Discriminant (Discr);
479 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
480 Set_Is_Internal (Subt);
483 Make_Subtype_Declaration (Loc,
484 Defining_Identifier => Subt,
485 Subtype_Indication =>
486 Make_Subtype_Indication (Loc,
487 Subtype_Mark => New_Reference_To (T, Loc),
489 Make_Index_Or_Discriminant_Constraint (Loc,
490 Constraints => Constraints)));
492 Mark_Rewrite_Insertion (Decl);
494 end Build_Actual_Subtype;
496 ---------------------------------------
497 -- Build_Actual_Subtype_Of_Component --
498 ---------------------------------------
500 function Build_Actual_Subtype_Of_Component
502 N : Node_Id) return Node_Id
504 Loc : constant Source_Ptr := Sloc (N);
505 P : constant Node_Id := Prefix (N);
508 Index_Typ : Entity_Id;
510 Desig_Typ : Entity_Id;
511 -- This is either a copy of T, or if T is an access type, then it is
512 -- the directly designated type of this access type.
514 function Build_Actual_Array_Constraint return List_Id;
515 -- If one or more of the bounds of the component depends on
516 -- discriminants, build actual constraint using the discriminants
519 function Build_Actual_Record_Constraint return List_Id;
520 -- Similar to previous one, for discriminated components constrained
521 -- by the discriminant of the enclosing object.
523 -----------------------------------
524 -- Build_Actual_Array_Constraint --
525 -----------------------------------
527 function Build_Actual_Array_Constraint return List_Id is
528 Constraints : constant List_Id := New_List;
536 Indx := First_Index (Desig_Typ);
537 while Present (Indx) loop
538 Old_Lo := Type_Low_Bound (Etype (Indx));
539 Old_Hi := Type_High_Bound (Etype (Indx));
541 if Denotes_Discriminant (Old_Lo) then
543 Make_Selected_Component (Loc,
544 Prefix => New_Copy_Tree (P),
545 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
548 Lo := New_Copy_Tree (Old_Lo);
550 -- The new bound will be reanalyzed in the enclosing
551 -- declaration. For literal bounds that come from a type
552 -- declaration, the type of the context must be imposed, so
553 -- insure that analysis will take place. For non-universal
554 -- types this is not strictly necessary.
556 Set_Analyzed (Lo, False);
559 if Denotes_Discriminant (Old_Hi) then
561 Make_Selected_Component (Loc,
562 Prefix => New_Copy_Tree (P),
563 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
566 Hi := New_Copy_Tree (Old_Hi);
567 Set_Analyzed (Hi, False);
570 Append (Make_Range (Loc, Lo, Hi), Constraints);
575 end Build_Actual_Array_Constraint;
577 ------------------------------------
578 -- Build_Actual_Record_Constraint --
579 ------------------------------------
581 function Build_Actual_Record_Constraint return List_Id is
582 Constraints : constant List_Id := New_List;
587 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
588 while Present (D) loop
589 if Denotes_Discriminant (Node (D)) then
590 D_Val := Make_Selected_Component (Loc,
591 Prefix => New_Copy_Tree (P),
592 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
595 D_Val := New_Copy_Tree (Node (D));
598 Append (D_Val, Constraints);
603 end Build_Actual_Record_Constraint;
605 -- Start of processing for Build_Actual_Subtype_Of_Component
608 -- Why the test for Spec_Expression mode here???
610 if In_Spec_Expression then
613 -- More comments for the rest of this body would be good ???
615 elsif Nkind (N) = N_Explicit_Dereference then
616 if Is_Composite_Type (T)
617 and then not Is_Constrained (T)
618 and then not (Is_Class_Wide_Type (T)
619 and then Is_Constrained (Root_Type (T)))
620 and then not Has_Unknown_Discriminants (T)
622 -- If the type of the dereference is already constrained, it is an
625 if Is_Array_Type (Etype (N))
626 and then Is_Constrained (Etype (N))
630 Remove_Side_Effects (P);
631 return Build_Actual_Subtype (T, N);
638 if Ekind (T) = E_Access_Subtype then
639 Desig_Typ := Designated_Type (T);
644 if Ekind (Desig_Typ) = E_Array_Subtype then
645 Id := First_Index (Desig_Typ);
646 while Present (Id) loop
647 Index_Typ := Underlying_Type (Etype (Id));
649 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
651 Denotes_Discriminant (Type_High_Bound (Index_Typ))
653 Remove_Side_Effects (P);
655 Build_Component_Subtype
656 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
662 elsif Is_Composite_Type (Desig_Typ)
663 and then Has_Discriminants (Desig_Typ)
664 and then not Has_Unknown_Discriminants (Desig_Typ)
666 if Is_Private_Type (Desig_Typ)
667 and then No (Discriminant_Constraint (Desig_Typ))
669 Desig_Typ := Full_View (Desig_Typ);
672 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
673 while Present (D) loop
674 if Denotes_Discriminant (Node (D)) then
675 Remove_Side_Effects (P);
677 Build_Component_Subtype (
678 Build_Actual_Record_Constraint, Loc, Base_Type (T));
685 -- If none of the above, the actual and nominal subtypes are the same
688 end Build_Actual_Subtype_Of_Component;
690 -----------------------------
691 -- Build_Component_Subtype --
692 -----------------------------
694 function Build_Component_Subtype
697 T : Entity_Id) return Node_Id
703 -- Unchecked_Union components do not require component subtypes
705 if Is_Unchecked_Union (T) then
709 Subt := Make_Temporary (Loc, 'S');
710 Set_Is_Internal (Subt);
713 Make_Subtype_Declaration (Loc,
714 Defining_Identifier => Subt,
715 Subtype_Indication =>
716 Make_Subtype_Indication (Loc,
717 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
719 Make_Index_Or_Discriminant_Constraint (Loc,
722 Mark_Rewrite_Insertion (Decl);
724 end Build_Component_Subtype;
726 ---------------------------
727 -- Build_Default_Subtype --
728 ---------------------------
730 function Build_Default_Subtype
732 N : Node_Id) return Entity_Id
734 Loc : constant Source_Ptr := Sloc (N);
738 if not Has_Discriminants (T) or else Is_Constrained (T) then
742 Disc := First_Discriminant (T);
744 if No (Discriminant_Default_Value (Disc)) then
749 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
750 Constraints : constant List_Id := New_List;
754 while Present (Disc) loop
755 Append_To (Constraints,
756 New_Copy_Tree (Discriminant_Default_Value (Disc)));
757 Next_Discriminant (Disc);
761 Make_Subtype_Declaration (Loc,
762 Defining_Identifier => Act,
763 Subtype_Indication =>
764 Make_Subtype_Indication (Loc,
765 Subtype_Mark => New_Occurrence_Of (T, Loc),
767 Make_Index_Or_Discriminant_Constraint (Loc,
768 Constraints => Constraints)));
770 Insert_Action (N, Decl);
774 end Build_Default_Subtype;
776 --------------------------------------------
777 -- Build_Discriminal_Subtype_Of_Component --
778 --------------------------------------------
780 function Build_Discriminal_Subtype_Of_Component
781 (T : Entity_Id) return Node_Id
783 Loc : constant Source_Ptr := Sloc (T);
787 function Build_Discriminal_Array_Constraint return List_Id;
788 -- If one or more of the bounds of the component depends on
789 -- discriminants, build actual constraint using the discriminants
792 function Build_Discriminal_Record_Constraint return List_Id;
793 -- Similar to previous one, for discriminated components constrained
794 -- by the discriminant of the enclosing object.
796 ----------------------------------------
797 -- Build_Discriminal_Array_Constraint --
798 ----------------------------------------
800 function Build_Discriminal_Array_Constraint return List_Id is
801 Constraints : constant List_Id := New_List;
809 Indx := First_Index (T);
810 while Present (Indx) loop
811 Old_Lo := Type_Low_Bound (Etype (Indx));
812 Old_Hi := Type_High_Bound (Etype (Indx));
814 if Denotes_Discriminant (Old_Lo) then
815 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
818 Lo := New_Copy_Tree (Old_Lo);
821 if Denotes_Discriminant (Old_Hi) then
822 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
825 Hi := New_Copy_Tree (Old_Hi);
828 Append (Make_Range (Loc, Lo, Hi), Constraints);
833 end Build_Discriminal_Array_Constraint;
835 -----------------------------------------
836 -- Build_Discriminal_Record_Constraint --
837 -----------------------------------------
839 function Build_Discriminal_Record_Constraint return List_Id is
840 Constraints : constant List_Id := New_List;
845 D := First_Elmt (Discriminant_Constraint (T));
846 while Present (D) loop
847 if Denotes_Discriminant (Node (D)) then
849 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
852 D_Val := New_Copy_Tree (Node (D));
855 Append (D_Val, Constraints);
860 end Build_Discriminal_Record_Constraint;
862 -- Start of processing for Build_Discriminal_Subtype_Of_Component
865 if Ekind (T) = E_Array_Subtype then
866 Id := First_Index (T);
867 while Present (Id) loop
868 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
869 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
871 return Build_Component_Subtype
872 (Build_Discriminal_Array_Constraint, Loc, T);
878 elsif Ekind (T) = E_Record_Subtype
879 and then Has_Discriminants (T)
880 and then not Has_Unknown_Discriminants (T)
882 D := First_Elmt (Discriminant_Constraint (T));
883 while Present (D) loop
884 if Denotes_Discriminant (Node (D)) then
885 return Build_Component_Subtype
886 (Build_Discriminal_Record_Constraint, Loc, T);
893 -- If none of the above, the actual and nominal subtypes are the same
896 end Build_Discriminal_Subtype_Of_Component;
898 ------------------------------
899 -- Build_Elaboration_Entity --
900 ------------------------------
902 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
903 Loc : constant Source_Ptr := Sloc (N);
905 Elab_Ent : Entity_Id;
907 procedure Set_Package_Name (Ent : Entity_Id);
908 -- Given an entity, sets the fully qualified name of the entity in
909 -- Name_Buffer, with components separated by double underscores. This
910 -- is a recursive routine that climbs the scope chain to Standard.
912 ----------------------
913 -- Set_Package_Name --
914 ----------------------
916 procedure Set_Package_Name (Ent : Entity_Id) is
918 if Scope (Ent) /= Standard_Standard then
919 Set_Package_Name (Scope (Ent));
922 Nam : constant String := Get_Name_String (Chars (Ent));
924 Name_Buffer (Name_Len + 1) := '_';
925 Name_Buffer (Name_Len + 2) := '_';
926 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
927 Name_Len := Name_Len + Nam'Length + 2;
931 Get_Name_String (Chars (Ent));
933 end Set_Package_Name;
935 -- Start of processing for Build_Elaboration_Entity
938 -- Ignore if already constructed
940 if Present (Elaboration_Entity (Spec_Id)) then
944 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
945 -- name with dots replaced by double underscore. We have to manually
946 -- construct this name, since it will be elaborated in the outer scope,
947 -- and thus will not have the unit name automatically prepended.
949 Set_Package_Name (Spec_Id);
953 Name_Buffer (Name_Len + 1) := '_';
954 Name_Buffer (Name_Len + 2) := 'E';
955 Name_Len := Name_Len + 2;
957 -- Create elaboration flag
960 Make_Defining_Identifier (Loc, Chars => Name_Find);
961 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
964 Make_Object_Declaration (Loc,
965 Defining_Identifier => Elab_Ent,
967 New_Occurrence_Of (Standard_Integer, Loc),
969 Make_Integer_Literal (Loc, Uint_0));
971 Push_Scope (Standard_Standard);
972 Add_Global_Declaration (Decl);
975 -- Reset True_Constant indication, since we will indeed assign a value
976 -- to the variable in the binder main. We also kill the Current_Value
977 -- and Last_Assignment fields for the same reason.
979 Set_Is_True_Constant (Elab_Ent, False);
980 Set_Current_Value (Elab_Ent, Empty);
981 Set_Last_Assignment (Elab_Ent, Empty);
983 -- We do not want any further qualification of the name (if we did
984 -- not do this, we would pick up the name of the generic package
985 -- in the case of a library level generic instantiation).
987 Set_Has_Qualified_Name (Elab_Ent);
988 Set_Has_Fully_Qualified_Name (Elab_Ent);
989 end Build_Elaboration_Entity;
991 -----------------------------------
992 -- Cannot_Raise_Constraint_Error --
993 -----------------------------------
995 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
997 if Compile_Time_Known_Value (Expr) then
1000 elsif Do_Range_Check (Expr) then
1003 elsif Raises_Constraint_Error (Expr) then
1007 case Nkind (Expr) is
1008 when N_Identifier =>
1011 when N_Expanded_Name =>
1014 when N_Selected_Component =>
1015 return not Do_Discriminant_Check (Expr);
1017 when N_Attribute_Reference =>
1018 if Do_Overflow_Check (Expr) then
1021 elsif No (Expressions (Expr)) then
1029 N := First (Expressions (Expr));
1030 while Present (N) loop
1031 if Cannot_Raise_Constraint_Error (N) then
1042 when N_Type_Conversion =>
1043 if Do_Overflow_Check (Expr)
1044 or else Do_Length_Check (Expr)
1045 or else Do_Tag_Check (Expr)
1050 Cannot_Raise_Constraint_Error (Expression (Expr));
1053 when N_Unchecked_Type_Conversion =>
1054 return Cannot_Raise_Constraint_Error (Expression (Expr));
1057 if Do_Overflow_Check (Expr) then
1061 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1068 if Do_Division_Check (Expr)
1069 or else Do_Overflow_Check (Expr)
1074 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1076 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1095 N_Op_Shift_Right_Arithmetic |
1099 if Do_Overflow_Check (Expr) then
1103 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1105 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1112 end Cannot_Raise_Constraint_Error;
1114 ---------------------------------------
1115 -- Check_Later_Vs_Basic_Declarations --
1116 ---------------------------------------
1118 procedure Check_Later_Vs_Basic_Declarations
1120 During_Parsing : Boolean)
1122 Body_Sloc : Source_Ptr;
1125 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1126 -- Return whether Decl is considered as a declarative item.
1127 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1128 -- When During_Parsing is False, the semantics of SPARK is followed.
1130 -------------------------------
1131 -- Is_Later_Declarative_Item --
1132 -------------------------------
1134 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1136 if Nkind (Decl) in N_Later_Decl_Item then
1139 elsif Nkind (Decl) = N_Pragma then
1142 elsif During_Parsing then
1145 -- In SPARK, a package declaration is not considered as a later
1146 -- declarative item.
1148 elsif Nkind (Decl) = N_Package_Declaration then
1151 -- In SPARK, a renaming is considered as a later declarative item
1153 elsif Nkind (Decl) in N_Renaming_Declaration then
1159 end Is_Later_Declarative_Item;
1161 -- Start of Check_Later_Vs_Basic_Declarations
1164 Decl := First (Decls);
1166 -- Loop through sequence of basic declarative items
1168 Outer : while Present (Decl) loop
1169 if Nkind (Decl) /= N_Subprogram_Body
1170 and then Nkind (Decl) /= N_Package_Body
1171 and then Nkind (Decl) /= N_Task_Body
1172 and then Nkind (Decl) not in N_Body_Stub
1176 -- Once a body is encountered, we only allow later declarative
1177 -- items. The inner loop checks the rest of the list.
1180 Body_Sloc := Sloc (Decl);
1182 Inner : while Present (Decl) loop
1183 if not Is_Later_Declarative_Item (Decl) then
1184 if During_Parsing then
1185 if Ada_Version = Ada_83 then
1186 Error_Msg_Sloc := Body_Sloc;
1188 ("(Ada 83) decl cannot appear after body#", Decl);
1191 Error_Msg_Sloc := Body_Sloc;
1192 Check_SPARK_Restriction
1193 ("decl cannot appear after body#", Decl);
1201 end Check_Later_Vs_Basic_Declarations;
1203 -----------------------------------------
1204 -- Check_Dynamically_Tagged_Expression --
1205 -----------------------------------------
1207 procedure Check_Dynamically_Tagged_Expression
1210 Related_Nod : Node_Id)
1213 pragma Assert (Is_Tagged_Type (Typ));
1215 -- In order to avoid spurious errors when analyzing the expanded code,
1216 -- this check is done only for nodes that come from source and for
1217 -- actuals of generic instantiations.
1219 if (Comes_From_Source (Related_Nod)
1220 or else In_Generic_Actual (Expr))
1221 and then (Is_Class_Wide_Type (Etype (Expr))
1222 or else Is_Dynamically_Tagged (Expr))
1223 and then Is_Tagged_Type (Typ)
1224 and then not Is_Class_Wide_Type (Typ)
1226 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1228 end Check_Dynamically_Tagged_Expression;
1230 --------------------------
1231 -- Check_Fully_Declared --
1232 --------------------------
1234 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1236 if Ekind (T) = E_Incomplete_Type then
1238 -- Ada 2005 (AI-50217): If the type is available through a limited
1239 -- with_clause, verify that its full view has been analyzed.
1241 if From_With_Type (T)
1242 and then Present (Non_Limited_View (T))
1243 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1245 -- The non-limited view is fully declared
1250 ("premature usage of incomplete}", N, First_Subtype (T));
1253 -- Need comments for these tests ???
1255 elsif Has_Private_Component (T)
1256 and then not Is_Generic_Type (Root_Type (T))
1257 and then not In_Spec_Expression
1259 -- Special case: if T is the anonymous type created for a single
1260 -- task or protected object, use the name of the source object.
1262 if Is_Concurrent_Type (T)
1263 and then not Comes_From_Source (T)
1264 and then Nkind (N) = N_Object_Declaration
1266 Error_Msg_NE ("type of& has incomplete component", N,
1267 Defining_Identifier (N));
1271 ("premature usage of incomplete}", N, First_Subtype (T));
1274 end Check_Fully_Declared;
1276 -------------------------
1277 -- Check_Nested_Access --
1278 -------------------------
1280 procedure Check_Nested_Access (Ent : Entity_Id) is
1281 Scop : constant Entity_Id := Current_Scope;
1282 Current_Subp : Entity_Id;
1283 Enclosing : Entity_Id;
1286 -- Currently only enabled for VM back-ends for efficiency, should we
1287 -- enable it more systematically ???
1289 -- Check for Is_Imported needs commenting below ???
1291 if VM_Target /= No_VM
1292 and then (Ekind (Ent) = E_Variable
1294 Ekind (Ent) = E_Constant
1296 Ekind (Ent) = E_Loop_Parameter)
1297 and then Scope (Ent) /= Empty
1298 and then not Is_Library_Level_Entity (Ent)
1299 and then not Is_Imported (Ent)
1301 if Is_Subprogram (Scop)
1302 or else Is_Generic_Subprogram (Scop)
1303 or else Is_Entry (Scop)
1305 Current_Subp := Scop;
1307 Current_Subp := Current_Subprogram;
1310 Enclosing := Enclosing_Subprogram (Ent);
1312 if Enclosing /= Empty
1313 and then Enclosing /= Current_Subp
1315 Set_Has_Up_Level_Access (Ent, True);
1318 end Check_Nested_Access;
1320 ----------------------------
1321 -- Check_Order_Dependence --
1322 ----------------------------
1324 procedure Check_Order_Dependence is
1329 if Ada_Version < Ada_2012 then
1333 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1334 -- calls within a construct have been collected. If one of them is
1335 -- writable and overlaps with another one, evaluation of the enclosing
1336 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1337 -- treated as a warning for now.
1339 for J in 1 .. Actuals_In_Call.Last loop
1340 if Actuals_In_Call.Table (J).Is_Writable then
1341 Act1 := Actuals_In_Call.Table (J).Act;
1343 if Nkind (Act1) = N_Attribute_Reference then
1344 Act1 := Prefix (Act1);
1347 for K in 1 .. Actuals_In_Call.Last loop
1349 Act2 := Actuals_In_Call.Table (K).Act;
1351 if Nkind (Act2) = N_Attribute_Reference then
1352 Act2 := Prefix (Act2);
1355 if Actuals_In_Call.Table (K).Is_Writable
1362 elsif Denotes_Same_Object (Act1, Act2)
1363 and then Parent (Act1) /= Parent (Act2)
1366 ("result may differ if evaluated "
1367 & "after other actual in expression?", Act1);
1374 -- Remove checked actuals from table
1376 Actuals_In_Call.Set_Last (0);
1377 end Check_Order_Dependence;
1379 ------------------------------------------
1380 -- Check_Potentially_Blocking_Operation --
1381 ------------------------------------------
1383 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1387 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1388 -- When pragma Detect_Blocking is active, the run time will raise
1389 -- Program_Error. Here we only issue a warning, since we generally
1390 -- support the use of potentially blocking operations in the absence
1393 -- Indirect blocking through a subprogram call cannot be diagnosed
1394 -- statically without interprocedural analysis, so we do not attempt
1397 S := Scope (Current_Scope);
1398 while Present (S) and then S /= Standard_Standard loop
1399 if Is_Protected_Type (S) then
1401 ("potentially blocking operation in protected operation?", N);
1407 end Check_Potentially_Blocking_Operation;
1409 ------------------------------
1410 -- Check_Unprotected_Access --
1411 ------------------------------
1413 procedure Check_Unprotected_Access
1417 Cont_Encl_Typ : Entity_Id;
1418 Pref_Encl_Typ : Entity_Id;
1420 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1421 -- Check whether Obj is a private component of a protected object.
1422 -- Return the protected type where the component resides, Empty
1425 function Is_Public_Operation return Boolean;
1426 -- Verify that the enclosing operation is callable from outside the
1427 -- protected object, to minimize false positives.
1429 ------------------------------
1430 -- Enclosing_Protected_Type --
1431 ------------------------------
1433 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1435 if Is_Entity_Name (Obj) then
1437 Ent : Entity_Id := Entity (Obj);
1440 -- The object can be a renaming of a private component, use
1441 -- the original record component.
1443 if Is_Prival (Ent) then
1444 Ent := Prival_Link (Ent);
1447 if Is_Protected_Type (Scope (Ent)) then
1453 -- For indexed and selected components, recursively check the prefix
1455 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1456 return Enclosing_Protected_Type (Prefix (Obj));
1458 -- The object does not denote a protected component
1463 end Enclosing_Protected_Type;
1465 -------------------------
1466 -- Is_Public_Operation --
1467 -------------------------
1469 function Is_Public_Operation return Boolean is
1476 and then S /= Pref_Encl_Typ
1478 if Scope (S) = Pref_Encl_Typ then
1479 E := First_Entity (Pref_Encl_Typ);
1481 and then E /= First_Private_Entity (Pref_Encl_Typ)
1494 end Is_Public_Operation;
1496 -- Start of processing for Check_Unprotected_Access
1499 if Nkind (Expr) = N_Attribute_Reference
1500 and then Attribute_Name (Expr) = Name_Unchecked_Access
1502 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1503 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1505 -- Check whether we are trying to export a protected component to a
1506 -- context with an equal or lower access level.
1508 if Present (Pref_Encl_Typ)
1509 and then No (Cont_Encl_Typ)
1510 and then Is_Public_Operation
1511 and then Scope_Depth (Pref_Encl_Typ) >=
1512 Object_Access_Level (Context)
1515 ("?possible unprotected access to protected data", Expr);
1518 end Check_Unprotected_Access;
1524 procedure Check_VMS (Construct : Node_Id) is
1526 if not OpenVMS_On_Target then
1528 ("this construct is allowed only in Open'V'M'S", Construct);
1532 ------------------------
1533 -- Collect_Interfaces --
1534 ------------------------
1536 procedure Collect_Interfaces
1538 Ifaces_List : out Elist_Id;
1539 Exclude_Parents : Boolean := False;
1540 Use_Full_View : Boolean := True)
1542 procedure Collect (Typ : Entity_Id);
1543 -- Subsidiary subprogram used to traverse the whole list
1544 -- of directly and indirectly implemented interfaces
1550 procedure Collect (Typ : Entity_Id) is
1551 Ancestor : Entity_Id;
1559 -- Handle private types
1562 and then Is_Private_Type (Typ)
1563 and then Present (Full_View (Typ))
1565 Full_T := Full_View (Typ);
1568 -- Include the ancestor if we are generating the whole list of
1569 -- abstract interfaces.
1571 if Etype (Full_T) /= Typ
1573 -- Protect the frontend against wrong sources. For example:
1576 -- type A is tagged null record;
1577 -- type B is new A with private;
1578 -- type C is new A with private;
1580 -- type B is new C with null record;
1581 -- type C is new B with null record;
1584 and then Etype (Full_T) /= T
1586 Ancestor := Etype (Full_T);
1589 if Is_Interface (Ancestor)
1590 and then not Exclude_Parents
1592 Append_Unique_Elmt (Ancestor, Ifaces_List);
1596 -- Traverse the graph of ancestor interfaces
1598 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1599 Id := First (Abstract_Interface_List (Full_T));
1600 while Present (Id) loop
1601 Iface := Etype (Id);
1603 -- Protect against wrong uses. For example:
1604 -- type I is interface;
1605 -- type O is tagged null record;
1606 -- type Wrong is new I and O with null record; -- ERROR
1608 if Is_Interface (Iface) then
1610 and then Etype (T) /= T
1611 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1616 Append_Unique_Elmt (Iface, Ifaces_List);
1625 -- Start of processing for Collect_Interfaces
1628 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1629 Ifaces_List := New_Elmt_List;
1631 end Collect_Interfaces;
1633 ----------------------------------
1634 -- Collect_Interface_Components --
1635 ----------------------------------
1637 procedure Collect_Interface_Components
1638 (Tagged_Type : Entity_Id;
1639 Components_List : out Elist_Id)
1641 procedure Collect (Typ : Entity_Id);
1642 -- Subsidiary subprogram used to climb to the parents
1648 procedure Collect (Typ : Entity_Id) is
1649 Tag_Comp : Entity_Id;
1650 Parent_Typ : Entity_Id;
1653 -- Handle private types
1655 if Present (Full_View (Etype (Typ))) then
1656 Parent_Typ := Full_View (Etype (Typ));
1658 Parent_Typ := Etype (Typ);
1661 if Parent_Typ /= Typ
1663 -- Protect the frontend against wrong sources. For example:
1666 -- type A is tagged null record;
1667 -- type B is new A with private;
1668 -- type C is new A with private;
1670 -- type B is new C with null record;
1671 -- type C is new B with null record;
1674 and then Parent_Typ /= Tagged_Type
1676 Collect (Parent_Typ);
1679 -- Collect the components containing tags of secondary dispatch
1682 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1683 while Present (Tag_Comp) loop
1684 pragma Assert (Present (Related_Type (Tag_Comp)));
1685 Append_Elmt (Tag_Comp, Components_List);
1687 Tag_Comp := Next_Tag_Component (Tag_Comp);
1691 -- Start of processing for Collect_Interface_Components
1694 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1695 and then Is_Tagged_Type (Tagged_Type));
1697 Components_List := New_Elmt_List;
1698 Collect (Tagged_Type);
1699 end Collect_Interface_Components;
1701 -----------------------------
1702 -- Collect_Interfaces_Info --
1703 -----------------------------
1705 procedure Collect_Interfaces_Info
1707 Ifaces_List : out Elist_Id;
1708 Components_List : out Elist_Id;
1709 Tags_List : out Elist_Id)
1711 Comps_List : Elist_Id;
1712 Comp_Elmt : Elmt_Id;
1713 Comp_Iface : Entity_Id;
1714 Iface_Elmt : Elmt_Id;
1717 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1718 -- Search for the secondary tag associated with the interface type
1719 -- Iface that is implemented by T.
1725 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1728 if not Is_CPP_Class (T) then
1729 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1731 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1735 and then Is_Tag (Node (ADT))
1736 and then Related_Type (Node (ADT)) /= Iface
1738 -- Skip secondary dispatch table referencing thunks to user
1739 -- defined primitives covered by this interface.
1741 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1744 -- Skip secondary dispatch tables of Ada types
1746 if not Is_CPP_Class (T) then
1748 -- Skip secondary dispatch table referencing thunks to
1749 -- predefined primitives.
1751 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1754 -- Skip secondary dispatch table referencing user-defined
1755 -- primitives covered by this interface.
1757 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1760 -- Skip secondary dispatch table referencing predefined
1763 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1768 pragma Assert (Is_Tag (Node (ADT)));
1772 -- Start of processing for Collect_Interfaces_Info
1775 Collect_Interfaces (T, Ifaces_List);
1776 Collect_Interface_Components (T, Comps_List);
1778 -- Search for the record component and tag associated with each
1779 -- interface type of T.
1781 Components_List := New_Elmt_List;
1782 Tags_List := New_Elmt_List;
1784 Iface_Elmt := First_Elmt (Ifaces_List);
1785 while Present (Iface_Elmt) loop
1786 Iface := Node (Iface_Elmt);
1788 -- Associate the primary tag component and the primary dispatch table
1789 -- with all the interfaces that are parents of T
1791 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1792 Append_Elmt (First_Tag_Component (T), Components_List);
1793 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1795 -- Otherwise search for the tag component and secondary dispatch
1799 Comp_Elmt := First_Elmt (Comps_List);
1800 while Present (Comp_Elmt) loop
1801 Comp_Iface := Related_Type (Node (Comp_Elmt));
1803 if Comp_Iface = Iface
1804 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1806 Append_Elmt (Node (Comp_Elmt), Components_List);
1807 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1811 Next_Elmt (Comp_Elmt);
1813 pragma Assert (Present (Comp_Elmt));
1816 Next_Elmt (Iface_Elmt);
1818 end Collect_Interfaces_Info;
1820 ---------------------
1821 -- Collect_Parents --
1822 ---------------------
1824 procedure Collect_Parents
1826 List : out Elist_Id;
1827 Use_Full_View : Boolean := True)
1829 Current_Typ : Entity_Id := T;
1830 Parent_Typ : Entity_Id;
1833 List := New_Elmt_List;
1835 -- No action if the if the type has no parents
1837 if T = Etype (T) then
1842 Parent_Typ := Etype (Current_Typ);
1844 if Is_Private_Type (Parent_Typ)
1845 and then Present (Full_View (Parent_Typ))
1846 and then Use_Full_View
1848 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1851 Append_Elmt (Parent_Typ, List);
1853 exit when Parent_Typ = Current_Typ;
1854 Current_Typ := Parent_Typ;
1856 end Collect_Parents;
1858 ----------------------------------
1859 -- Collect_Primitive_Operations --
1860 ----------------------------------
1862 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1863 B_Type : constant Entity_Id := Base_Type (T);
1864 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1865 B_Scope : Entity_Id := Scope (B_Type);
1869 Formal_Derived : Boolean := False;
1872 function Match (E : Entity_Id) return Boolean;
1873 -- True if E's base type is B_Type, or E is of an anonymous access type
1874 -- and the base type of its designated type is B_Type.
1880 function Match (E : Entity_Id) return Boolean is
1881 Etyp : Entity_Id := Etype (E);
1884 if Ekind (Etyp) = E_Anonymous_Access_Type then
1885 Etyp := Designated_Type (Etyp);
1888 return Base_Type (Etyp) = B_Type;
1891 -- Start of processing for Collect_Primitive_Operations
1894 -- For tagged types, the primitive operations are collected as they
1895 -- are declared, and held in an explicit list which is simply returned.
1897 if Is_Tagged_Type (B_Type) then
1898 return Primitive_Operations (B_Type);
1900 -- An untagged generic type that is a derived type inherits the
1901 -- primitive operations of its parent type. Other formal types only
1902 -- have predefined operators, which are not explicitly represented.
1904 elsif Is_Generic_Type (B_Type) then
1905 if Nkind (B_Decl) = N_Formal_Type_Declaration
1906 and then Nkind (Formal_Type_Definition (B_Decl))
1907 = N_Formal_Derived_Type_Definition
1909 Formal_Derived := True;
1911 return New_Elmt_List;
1915 Op_List := New_Elmt_List;
1917 if B_Scope = Standard_Standard then
1918 if B_Type = Standard_String then
1919 Append_Elmt (Standard_Op_Concat, Op_List);
1921 elsif B_Type = Standard_Wide_String then
1922 Append_Elmt (Standard_Op_Concatw, Op_List);
1928 elsif (Is_Package_Or_Generic_Package (B_Scope)
1930 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1932 or else Is_Derived_Type (B_Type)
1934 -- The primitive operations appear after the base type, except
1935 -- if the derivation happens within the private part of B_Scope
1936 -- and the type is a private type, in which case both the type
1937 -- and some primitive operations may appear before the base
1938 -- type, and the list of candidates starts after the type.
1940 if In_Open_Scopes (B_Scope)
1941 and then Scope (T) = B_Scope
1942 and then In_Private_Part (B_Scope)
1944 Id := Next_Entity (T);
1946 Id := Next_Entity (B_Type);
1949 while Present (Id) loop
1951 -- Note that generic formal subprograms are not
1952 -- considered to be primitive operations and thus
1953 -- are never inherited.
1955 if Is_Overloadable (Id)
1956 and then Nkind (Parent (Parent (Id)))
1957 not in N_Formal_Subprogram_Declaration
1965 Formal := First_Formal (Id);
1966 while Present (Formal) loop
1967 if Match (Formal) then
1972 Next_Formal (Formal);
1976 -- For a formal derived type, the only primitives are the
1977 -- ones inherited from the parent type. Operations appearing
1978 -- in the package declaration are not primitive for it.
1981 and then (not Formal_Derived
1982 or else Present (Alias (Id)))
1984 -- In the special case of an equality operator aliased to
1985 -- an overriding dispatching equality belonging to the same
1986 -- type, we don't include it in the list of primitives.
1987 -- This avoids inheriting multiple equality operators when
1988 -- deriving from untagged private types whose full type is
1989 -- tagged, which can otherwise cause ambiguities. Note that
1990 -- this should only happen for this kind of untagged parent
1991 -- type, since normally dispatching operations are inherited
1992 -- using the type's Primitive_Operations list.
1994 if Chars (Id) = Name_Op_Eq
1995 and then Is_Dispatching_Operation (Id)
1996 and then Present (Alias (Id))
1997 and then Present (Overridden_Operation (Alias (Id)))
1998 and then Base_Type (Etype (First_Entity (Id))) =
1999 Base_Type (Etype (First_Entity (Alias (Id))))
2003 -- Include the subprogram in the list of primitives
2006 Append_Elmt (Id, Op_List);
2013 -- For a type declared in System, some of its operations may
2014 -- appear in the target-specific extension to System.
2017 and then B_Scope = RTU_Entity (System)
2018 and then Present_System_Aux
2020 B_Scope := System_Aux_Id;
2021 Id := First_Entity (System_Aux_Id);
2027 end Collect_Primitive_Operations;
2029 -----------------------------------
2030 -- Compile_Time_Constraint_Error --
2031 -----------------------------------
2033 function Compile_Time_Constraint_Error
2036 Ent : Entity_Id := Empty;
2037 Loc : Source_Ptr := No_Location;
2038 Warn : Boolean := False) return Node_Id
2040 Msgc : String (1 .. Msg'Length + 2);
2041 -- Copy of message, with room for possible ? and ! at end
2051 -- A static constraint error in an instance body is not a fatal error.
2052 -- we choose to inhibit the message altogether, because there is no
2053 -- obvious node (for now) on which to post it. On the other hand the
2054 -- offending node must be replaced with a constraint_error in any case.
2056 -- No messages are generated if we already posted an error on this node
2058 if not Error_Posted (N) then
2059 if Loc /= No_Location then
2065 Msgc (1 .. Msg'Length) := Msg;
2068 -- Message is a warning, even in Ada 95 case
2070 if Msg (Msg'Last) = '?' then
2073 -- In Ada 83, all messages are warnings. In the private part and
2074 -- the body of an instance, constraint_checks are only warnings.
2075 -- We also make this a warning if the Warn parameter is set.
2078 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2084 elsif In_Instance_Not_Visible then
2089 -- Otherwise we have a real error message (Ada 95 static case)
2090 -- and we make this an unconditional message. Note that in the
2091 -- warning case we do not make the message unconditional, it seems
2092 -- quite reasonable to delete messages like this (about exceptions
2093 -- that will be raised) in dead code.
2101 -- Should we generate a warning? The answer is not quite yes. The
2102 -- very annoying exception occurs in the case of a short circuit
2103 -- operator where the left operand is static and decisive. Climb
2104 -- parents to see if that is the case we have here. Conditional
2105 -- expressions with decisive conditions are a similar situation.
2113 -- And then with False as left operand
2115 if Nkind (P) = N_And_Then
2116 and then Compile_Time_Known_Value (Left_Opnd (P))
2117 and then Is_False (Expr_Value (Left_Opnd (P)))
2122 -- OR ELSE with True as left operand
2124 elsif Nkind (P) = N_Or_Else
2125 and then Compile_Time_Known_Value (Left_Opnd (P))
2126 and then Is_True (Expr_Value (Left_Opnd (P)))
2131 -- Conditional expression
2133 elsif Nkind (P) = N_Conditional_Expression then
2135 Cond : constant Node_Id := First (Expressions (P));
2136 Texp : constant Node_Id := Next (Cond);
2137 Fexp : constant Node_Id := Next (Texp);
2140 if Compile_Time_Known_Value (Cond) then
2142 -- Condition is True and we are in the right operand
2144 if Is_True (Expr_Value (Cond))
2145 and then OldP = Fexp
2150 -- Condition is False and we are in the left operand
2152 elsif Is_False (Expr_Value (Cond))
2153 and then OldP = Texp
2161 -- Special case for component association in aggregates, where
2162 -- we want to keep climbing up to the parent aggregate.
2164 elsif Nkind (P) = N_Component_Association
2165 and then Nkind (Parent (P)) = N_Aggregate
2169 -- Keep going if within subexpression
2172 exit when Nkind (P) not in N_Subexpr;
2177 if Present (Ent) then
2178 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2180 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2184 if Inside_Init_Proc then
2186 ("\?& will be raised for objects of this type",
2187 N, Standard_Constraint_Error, Eloc);
2190 ("\?& will be raised at run time",
2191 N, Standard_Constraint_Error, Eloc);
2196 ("\static expression fails Constraint_Check", Eloc);
2197 Set_Error_Posted (N);
2203 end Compile_Time_Constraint_Error;
2205 -----------------------
2206 -- Conditional_Delay --
2207 -----------------------
2209 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2211 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2212 Set_Has_Delayed_Freeze (New_Ent);
2214 end Conditional_Delay;
2216 -------------------------
2217 -- Copy_Parameter_List --
2218 -------------------------
2220 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2221 Loc : constant Source_Ptr := Sloc (Subp_Id);
2226 if No (First_Formal (Subp_Id)) then
2230 Formal := First_Formal (Subp_Id);
2231 while Present (Formal) loop
2233 (Make_Parameter_Specification (Loc,
2234 Defining_Identifier =>
2235 Make_Defining_Identifier (Sloc (Formal),
2236 Chars => Chars (Formal)),
2237 In_Present => In_Present (Parent (Formal)),
2238 Out_Present => Out_Present (Parent (Formal)),
2240 New_Reference_To (Etype (Formal), Loc),
2242 New_Copy_Tree (Expression (Parent (Formal)))),
2245 Next_Formal (Formal);
2250 end Copy_Parameter_List;
2252 --------------------
2253 -- Current_Entity --
2254 --------------------
2256 -- The currently visible definition for a given identifier is the
2257 -- one most chained at the start of the visibility chain, i.e. the
2258 -- one that is referenced by the Node_Id value of the name of the
2259 -- given identifier.
2261 function Current_Entity (N : Node_Id) return Entity_Id is
2263 return Get_Name_Entity_Id (Chars (N));
2266 -----------------------------
2267 -- Current_Entity_In_Scope --
2268 -----------------------------
2270 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2272 CS : constant Entity_Id := Current_Scope;
2274 Transient_Case : constant Boolean := Scope_Is_Transient;
2277 E := Get_Name_Entity_Id (Chars (N));
2279 and then Scope (E) /= CS
2280 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2286 end Current_Entity_In_Scope;
2292 function Current_Scope return Entity_Id is
2294 if Scope_Stack.Last = -1 then
2295 return Standard_Standard;
2298 C : constant Entity_Id :=
2299 Scope_Stack.Table (Scope_Stack.Last).Entity;
2304 return Standard_Standard;
2310 ------------------------
2311 -- Current_Subprogram --
2312 ------------------------
2314 function Current_Subprogram return Entity_Id is
2315 Scop : constant Entity_Id := Current_Scope;
2317 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2320 return Enclosing_Subprogram (Scop);
2322 end Current_Subprogram;
2324 ------------------------------
2325 -- Mark_Non_ALFA_Subprogram --
2326 ------------------------------
2328 procedure Mark_Non_ALFA_Subprogram is
2330 -- Isolate marking of the current subprogram body so that the body of
2331 -- Mark_Non_ALFA_Subprogram is small and inlined.
2334 Mark_Non_ALFA_Subprogram_Unconditional;
2336 end Mark_Non_ALFA_Subprogram;
2338 --------------------------------------------
2339 -- Mark_Non_ALFA_Subprogram_Unconditional --
2340 --------------------------------------------
2342 procedure Mark_Non_ALFA_Subprogram_Unconditional is
2343 Cur_Subp : constant Entity_Id := Current_Subprogram;
2346 if Present (Cur_Subp)
2347 and then (Is_Subprogram (Cur_Subp)
2348 or else Is_Generic_Subprogram (Cur_Subp))
2350 -- If the non-ALFA construct is in a precondition or postcondition,
2351 -- then mark the subprogram as not in ALFA. Otherwise, mark the
2352 -- subprogram body as not in ALFA.
2354 -- This comment just says what is done, but not why ??? and it
2355 -- just repeats what is in the spec ???
2357 if In_Pre_Post_Expression then
2358 Set_Is_In_ALFA (Cur_Subp, False);
2360 Set_Body_Is_In_ALFA (Cur_Subp, False);
2363 end Mark_Non_ALFA_Subprogram_Unconditional;
2365 ---------------------
2366 -- Defining_Entity --
2367 ---------------------
2369 function Defining_Entity (N : Node_Id) return Entity_Id is
2370 K : constant Node_Kind := Nkind (N);
2371 Err : Entity_Id := Empty;
2376 N_Subprogram_Declaration |
2377 N_Abstract_Subprogram_Declaration |
2379 N_Package_Declaration |
2380 N_Subprogram_Renaming_Declaration |
2381 N_Subprogram_Body_Stub |
2382 N_Generic_Subprogram_Declaration |
2383 N_Generic_Package_Declaration |
2384 N_Formal_Subprogram_Declaration
2386 return Defining_Entity (Specification (N));
2389 N_Component_Declaration |
2390 N_Defining_Program_Unit_Name |
2391 N_Discriminant_Specification |
2393 N_Entry_Declaration |
2394 N_Entry_Index_Specification |
2395 N_Exception_Declaration |
2396 N_Exception_Renaming_Declaration |
2397 N_Formal_Object_Declaration |
2398 N_Formal_Package_Declaration |
2399 N_Formal_Type_Declaration |
2400 N_Full_Type_Declaration |
2401 N_Implicit_Label_Declaration |
2402 N_Incomplete_Type_Declaration |
2403 N_Loop_Parameter_Specification |
2404 N_Number_Declaration |
2405 N_Object_Declaration |
2406 N_Object_Renaming_Declaration |
2407 N_Package_Body_Stub |
2408 N_Parameter_Specification |
2409 N_Private_Extension_Declaration |
2410 N_Private_Type_Declaration |
2412 N_Protected_Body_Stub |
2413 N_Protected_Type_Declaration |
2414 N_Single_Protected_Declaration |
2415 N_Single_Task_Declaration |
2416 N_Subtype_Declaration |
2419 N_Task_Type_Declaration
2421 return Defining_Identifier (N);
2424 return Defining_Entity (Proper_Body (N));
2427 N_Function_Instantiation |
2428 N_Function_Specification |
2429 N_Generic_Function_Renaming_Declaration |
2430 N_Generic_Package_Renaming_Declaration |
2431 N_Generic_Procedure_Renaming_Declaration |
2433 N_Package_Instantiation |
2434 N_Package_Renaming_Declaration |
2435 N_Package_Specification |
2436 N_Procedure_Instantiation |
2437 N_Procedure_Specification
2440 Nam : constant Node_Id := Defining_Unit_Name (N);
2443 if Nkind (Nam) in N_Entity then
2446 -- For Error, make up a name and attach to declaration
2447 -- so we can continue semantic analysis
2449 elsif Nam = Error then
2450 Err := Make_Temporary (Sloc (N), 'T');
2451 Set_Defining_Unit_Name (N, Err);
2454 -- If not an entity, get defining identifier
2457 return Defining_Identifier (Nam);
2461 when N_Block_Statement =>
2462 return Entity (Identifier (N));
2465 raise Program_Error;
2468 end Defining_Entity;
2470 --------------------------
2471 -- Denotes_Discriminant --
2472 --------------------------
2474 function Denotes_Discriminant
2476 Check_Concurrent : Boolean := False) return Boolean
2480 if not Is_Entity_Name (N)
2481 or else No (Entity (N))
2488 -- If we are checking for a protected type, the discriminant may have
2489 -- been rewritten as the corresponding discriminal of the original type
2490 -- or of the corresponding concurrent record, depending on whether we
2491 -- are in the spec or body of the protected type.
2493 return Ekind (E) = E_Discriminant
2496 and then Ekind (E) = E_In_Parameter
2497 and then Present (Discriminal_Link (E))
2499 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2501 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2503 end Denotes_Discriminant;
2505 -------------------------
2506 -- Denotes_Same_Object --
2507 -------------------------
2509 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2510 Obj1 : Node_Id := A1;
2511 Obj2 : Node_Id := A2;
2513 procedure Check_Renaming (Obj : in out Node_Id);
2514 -- If an object is a renaming, examine renamed object. If it is a
2515 -- dereference of a variable, or an indexed expression with non-constant
2516 -- indexes, no overlap check can be reported.
2518 --------------------
2519 -- Check_Renaming --
2520 --------------------
2522 procedure Check_Renaming (Obj : in out Node_Id) is
2524 if Is_Entity_Name (Obj)
2525 and then Present (Renamed_Entity (Entity (Obj)))
2527 Obj := Renamed_Entity (Entity (Obj));
2528 if Nkind (Obj) = N_Explicit_Dereference
2529 and then Is_Variable (Prefix (Obj))
2533 elsif Nkind (Obj) = N_Indexed_Component then
2538 Indx := First (Expressions (Obj));
2539 while Present (Indx) loop
2540 if not Is_OK_Static_Expression (Indx) then
2552 -- Start of processing for Denotes_Same_Object
2555 Check_Renaming (Obj1);
2556 Check_Renaming (Obj2);
2564 -- If we have entity names, then must be same entity
2566 if Is_Entity_Name (Obj1) then
2567 if Is_Entity_Name (Obj2) then
2568 return Entity (Obj1) = Entity (Obj2);
2573 -- No match if not same node kind
2575 elsif Nkind (Obj1) /= Nkind (Obj2) then
2578 -- For selected components, must have same prefix and selector
2580 elsif Nkind (Obj1) = N_Selected_Component then
2581 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2583 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2585 -- For explicit dereferences, prefixes must be same
2587 elsif Nkind (Obj1) = N_Explicit_Dereference then
2588 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2590 -- For indexed components, prefixes and all subscripts must be the same
2592 elsif Nkind (Obj1) = N_Indexed_Component then
2593 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2599 Indx1 := First (Expressions (Obj1));
2600 Indx2 := First (Expressions (Obj2));
2601 while Present (Indx1) loop
2603 -- Indexes must denote the same static value or same object
2605 if Is_OK_Static_Expression (Indx1) then
2606 if not Is_OK_Static_Expression (Indx2) then
2609 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2613 elsif not Denotes_Same_Object (Indx1, Indx2) then
2627 -- For slices, prefixes must match and bounds must match
2629 elsif Nkind (Obj1) = N_Slice
2630 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2633 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2636 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2637 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2639 -- Check whether bounds are statically identical. There is no
2640 -- attempt to detect partial overlap of slices.
2642 return Denotes_Same_Object (Lo1, Lo2)
2643 and then Denotes_Same_Object (Hi1, Hi2);
2646 -- Literals will appear as indexes. Isn't this where we should check
2647 -- Known_At_Compile_Time at least if we are generating warnings ???
2649 elsif Nkind (Obj1) = N_Integer_Literal then
2650 return Intval (Obj1) = Intval (Obj2);
2655 end Denotes_Same_Object;
2657 -------------------------
2658 -- Denotes_Same_Prefix --
2659 -------------------------
2661 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2664 if Is_Entity_Name (A1) then
2665 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2666 and then not Is_Access_Type (Etype (A1))
2668 return Denotes_Same_Object (A1, Prefix (A2))
2669 or else Denotes_Same_Prefix (A1, Prefix (A2));
2674 elsif Is_Entity_Name (A2) then
2675 return Denotes_Same_Prefix (A2, A1);
2677 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2679 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2682 Root1, Root2 : Node_Id;
2683 Depth1, Depth2 : Int := 0;
2686 Root1 := Prefix (A1);
2687 while not Is_Entity_Name (Root1) loop
2689 (Root1, N_Selected_Component, N_Indexed_Component)
2693 Root1 := Prefix (Root1);
2696 Depth1 := Depth1 + 1;
2699 Root2 := Prefix (A2);
2700 while not Is_Entity_Name (Root2) loop
2702 (Root2, N_Selected_Component, N_Indexed_Component)
2706 Root2 := Prefix (Root2);
2709 Depth2 := Depth2 + 1;
2712 -- If both have the same depth and they do not denote the same
2713 -- object, they are disjoint and not warning is needed.
2715 if Depth1 = Depth2 then
2718 elsif Depth1 > Depth2 then
2719 Root1 := Prefix (A1);
2720 for I in 1 .. Depth1 - Depth2 - 1 loop
2721 Root1 := Prefix (Root1);
2724 return Denotes_Same_Object (Root1, A2);
2727 Root2 := Prefix (A2);
2728 for I in 1 .. Depth2 - Depth1 - 1 loop
2729 Root2 := Prefix (Root2);
2732 return Denotes_Same_Object (A1, Root2);
2739 end Denotes_Same_Prefix;
2741 ----------------------
2742 -- Denotes_Variable --
2743 ----------------------
2745 function Denotes_Variable (N : Node_Id) return Boolean is
2747 return Is_Variable (N) and then Paren_Count (N) = 0;
2748 end Denotes_Variable;
2750 -----------------------------
2751 -- Depends_On_Discriminant --
2752 -----------------------------
2754 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2759 Get_Index_Bounds (N, L, H);
2760 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2761 end Depends_On_Discriminant;
2763 -------------------------
2764 -- Designate_Same_Unit --
2765 -------------------------
2767 function Designate_Same_Unit
2769 Name2 : Node_Id) return Boolean
2771 K1 : constant Node_Kind := Nkind (Name1);
2772 K2 : constant Node_Kind := Nkind (Name2);
2774 function Prefix_Node (N : Node_Id) return Node_Id;
2775 -- Returns the parent unit name node of a defining program unit name
2776 -- or the prefix if N is a selected component or an expanded name.
2778 function Select_Node (N : Node_Id) return Node_Id;
2779 -- Returns the defining identifier node of a defining program unit
2780 -- name or the selector node if N is a selected component or an
2787 function Prefix_Node (N : Node_Id) return Node_Id is
2789 if Nkind (N) = N_Defining_Program_Unit_Name then
2801 function Select_Node (N : Node_Id) return Node_Id is
2803 if Nkind (N) = N_Defining_Program_Unit_Name then
2804 return Defining_Identifier (N);
2807 return Selector_Name (N);
2811 -- Start of processing for Designate_Next_Unit
2814 if (K1 = N_Identifier or else
2815 K1 = N_Defining_Identifier)
2817 (K2 = N_Identifier or else
2818 K2 = N_Defining_Identifier)
2820 return Chars (Name1) = Chars (Name2);
2823 (K1 = N_Expanded_Name or else
2824 K1 = N_Selected_Component or else
2825 K1 = N_Defining_Program_Unit_Name)
2827 (K2 = N_Expanded_Name or else
2828 K2 = N_Selected_Component or else
2829 K2 = N_Defining_Program_Unit_Name)
2832 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2834 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2839 end Designate_Same_Unit;
2841 --------------------------
2842 -- Enclosing_CPP_Parent --
2843 --------------------------
2845 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2846 Parent_Typ : Entity_Id := Typ;
2849 while not Is_CPP_Class (Parent_Typ)
2850 and then Etype (Parent_Typ) /= Parent_Typ
2852 Parent_Typ := Etype (Parent_Typ);
2854 if Is_Private_Type (Parent_Typ) then
2855 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2859 pragma Assert (Is_CPP_Class (Parent_Typ));
2861 end Enclosing_CPP_Parent;
2863 ----------------------------
2864 -- Enclosing_Generic_Body --
2865 ----------------------------
2867 function Enclosing_Generic_Body
2868 (N : Node_Id) return Node_Id
2876 while Present (P) loop
2877 if Nkind (P) = N_Package_Body
2878 or else Nkind (P) = N_Subprogram_Body
2880 Spec := Corresponding_Spec (P);
2882 if Present (Spec) then
2883 Decl := Unit_Declaration_Node (Spec);
2885 if Nkind (Decl) = N_Generic_Package_Declaration
2886 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2897 end Enclosing_Generic_Body;
2899 ----------------------------
2900 -- Enclosing_Generic_Unit --
2901 ----------------------------
2903 function Enclosing_Generic_Unit
2904 (N : Node_Id) return Node_Id
2912 while Present (P) loop
2913 if Nkind (P) = N_Generic_Package_Declaration
2914 or else Nkind (P) = N_Generic_Subprogram_Declaration
2918 elsif Nkind (P) = N_Package_Body
2919 or else Nkind (P) = N_Subprogram_Body
2921 Spec := Corresponding_Spec (P);
2923 if Present (Spec) then
2924 Decl := Unit_Declaration_Node (Spec);
2926 if Nkind (Decl) = N_Generic_Package_Declaration
2927 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2938 end Enclosing_Generic_Unit;
2940 -------------------------------
2941 -- Enclosing_Lib_Unit_Entity --
2942 -------------------------------
2944 function Enclosing_Lib_Unit_Entity return Entity_Id is
2945 Unit_Entity : Entity_Id;
2948 -- Look for enclosing library unit entity by following scope links.
2949 -- Equivalent to, but faster than indexing through the scope stack.
2951 Unit_Entity := Current_Scope;
2952 while (Present (Scope (Unit_Entity))
2953 and then Scope (Unit_Entity) /= Standard_Standard)
2954 and not Is_Child_Unit (Unit_Entity)
2956 Unit_Entity := Scope (Unit_Entity);
2960 end Enclosing_Lib_Unit_Entity;
2962 -----------------------------
2963 -- Enclosing_Lib_Unit_Node --
2964 -----------------------------
2966 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2967 Current_Node : Node_Id;
2971 while Present (Current_Node)
2972 and then Nkind (Current_Node) /= N_Compilation_Unit
2974 Current_Node := Parent (Current_Node);
2977 if Nkind (Current_Node) /= N_Compilation_Unit then
2981 return Current_Node;
2982 end Enclosing_Lib_Unit_Node;
2984 -----------------------
2985 -- Enclosing_Package --
2986 -----------------------
2988 function Enclosing_Package (E : Entity_Id) return Entity_Id is
2989 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2992 if Dynamic_Scope = Standard_Standard then
2993 return Standard_Standard;
2995 elsif Dynamic_Scope = Empty then
2998 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
3001 return Dynamic_Scope;
3004 return Enclosing_Package (Dynamic_Scope);
3006 end Enclosing_Package;
3008 --------------------------
3009 -- Enclosing_Subprogram --
3010 --------------------------
3012 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3013 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3016 if Dynamic_Scope = Standard_Standard then
3019 elsif Dynamic_Scope = Empty then
3022 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3023 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3025 elsif Ekind (Dynamic_Scope) = E_Block
3026 or else Ekind (Dynamic_Scope) = E_Return_Statement
3028 return Enclosing_Subprogram (Dynamic_Scope);
3030 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3031 return Get_Task_Body_Procedure (Dynamic_Scope);
3033 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3034 and then Present (Full_View (Dynamic_Scope))
3035 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3037 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3039 -- No body is generated if the protected operation is eliminated
3041 elsif Convention (Dynamic_Scope) = Convention_Protected
3042 and then not Is_Eliminated (Dynamic_Scope)
3043 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3045 return Protected_Body_Subprogram (Dynamic_Scope);
3048 return Dynamic_Scope;
3050 end Enclosing_Subprogram;
3052 ------------------------
3053 -- Ensure_Freeze_Node --
3054 ------------------------
3056 procedure Ensure_Freeze_Node (E : Entity_Id) is
3060 if No (Freeze_Node (E)) then
3061 FN := Make_Freeze_Entity (Sloc (E));
3062 Set_Has_Delayed_Freeze (E);
3063 Set_Freeze_Node (E, FN);
3064 Set_Access_Types_To_Process (FN, No_Elist);
3065 Set_TSS_Elist (FN, No_Elist);
3068 end Ensure_Freeze_Node;
3074 procedure Enter_Name (Def_Id : Entity_Id) is
3075 C : constant Entity_Id := Current_Entity (Def_Id);
3076 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3077 S : constant Entity_Id := Current_Scope;
3080 Generate_Definition (Def_Id);
3082 -- Add new name to current scope declarations. Check for duplicate
3083 -- declaration, which may or may not be a genuine error.
3087 -- Case of previous entity entered because of a missing declaration
3088 -- or else a bad subtype indication. Best is to use the new entity,
3089 -- and make the previous one invisible.
3091 if Etype (E) = Any_Type then
3092 Set_Is_Immediately_Visible (E, False);
3094 -- Case of renaming declaration constructed for package instances.
3095 -- if there is an explicit declaration with the same identifier,
3096 -- the renaming is not immediately visible any longer, but remains
3097 -- visible through selected component notation.
3099 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3100 and then not Comes_From_Source (E)
3102 Set_Is_Immediately_Visible (E, False);
3104 -- The new entity may be the package renaming, which has the same
3105 -- same name as a generic formal which has been seen already.
3107 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3108 and then not Comes_From_Source (Def_Id)
3110 Set_Is_Immediately_Visible (E, False);
3112 -- For a fat pointer corresponding to a remote access to subprogram,
3113 -- we use the same identifier as the RAS type, so that the proper
3114 -- name appears in the stub. This type is only retrieved through
3115 -- the RAS type and never by visibility, and is not added to the
3116 -- visibility list (see below).
3118 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3119 and then Present (Corresponding_Remote_Type (Def_Id))
3123 -- Case of an implicit operation or derived literal. The new entity
3124 -- hides the implicit one, which is removed from all visibility,
3125 -- i.e. the entity list of its scope, and homonym chain of its name.
3127 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3128 or else Is_Internal (E)
3132 Prev_Vis : Entity_Id;
3133 Decl : constant Node_Id := Parent (E);
3136 -- If E is an implicit declaration, it cannot be the first
3137 -- entity in the scope.
3139 Prev := First_Entity (Current_Scope);
3140 while Present (Prev)
3141 and then Next_Entity (Prev) /= E
3148 -- If E is not on the entity chain of the current scope,
3149 -- it is an implicit declaration in the generic formal
3150 -- part of a generic subprogram. When analyzing the body,
3151 -- the generic formals are visible but not on the entity
3152 -- chain of the subprogram. The new entity will become
3153 -- the visible one in the body.
3156 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3160 Set_Next_Entity (Prev, Next_Entity (E));
3162 if No (Next_Entity (Prev)) then
3163 Set_Last_Entity (Current_Scope, Prev);
3166 if E = Current_Entity (E) then
3170 Prev_Vis := Current_Entity (E);
3171 while Homonym (Prev_Vis) /= E loop
3172 Prev_Vis := Homonym (Prev_Vis);
3176 if Present (Prev_Vis) then
3178 -- Skip E in the visibility chain
3180 Set_Homonym (Prev_Vis, Homonym (E));
3183 Set_Name_Entity_Id (Chars (E), Homonym (E));
3188 -- This section of code could use a comment ???
3190 elsif Present (Etype (E))
3191 and then Is_Concurrent_Type (Etype (E))
3196 -- If the homograph is a protected component renaming, it should not
3197 -- be hiding the current entity. Such renamings are treated as weak
3200 elsif Is_Prival (E) then
3201 Set_Is_Immediately_Visible (E, False);
3203 -- In this case the current entity is a protected component renaming.
3204 -- Perform minimal decoration by setting the scope and return since
3205 -- the prival should not be hiding other visible entities.
3207 elsif Is_Prival (Def_Id) then
3208 Set_Scope (Def_Id, Current_Scope);
3211 -- Analogous to privals, the discriminal generated for an entry index
3212 -- parameter acts as a weak declaration. Perform minimal decoration
3213 -- to avoid bogus errors.
3215 elsif Is_Discriminal (Def_Id)
3216 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3218 Set_Scope (Def_Id, Current_Scope);
3221 -- In the body or private part of an instance, a type extension may
3222 -- introduce a component with the same name as that of an actual. The
3223 -- legality rule is not enforced, but the semantics of the full type
3224 -- with two components of same name are not clear at this point???
3226 elsif In_Instance_Not_Visible then
3229 -- When compiling a package body, some child units may have become
3230 -- visible. They cannot conflict with local entities that hide them.
3232 elsif Is_Child_Unit (E)
3233 and then In_Open_Scopes (Scope (E))
3234 and then not Is_Immediately_Visible (E)
3238 -- Conversely, with front-end inlining we may compile the parent body
3239 -- first, and a child unit subsequently. The context is now the
3240 -- parent spec, and body entities are not visible.
3242 elsif Is_Child_Unit (Def_Id)
3243 and then Is_Package_Body_Entity (E)
3244 and then not In_Package_Body (Current_Scope)
3248 -- Case of genuine duplicate declaration
3251 Error_Msg_Sloc := Sloc (E);
3253 -- If the previous declaration is an incomplete type declaration
3254 -- this may be an attempt to complete it with a private type. The
3255 -- following avoids confusing cascaded errors.
3257 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3258 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3261 ("incomplete type cannot be completed with a private " &
3262 "declaration", Parent (Def_Id));
3263 Set_Is_Immediately_Visible (E, False);
3264 Set_Full_View (E, Def_Id);
3266 -- An inherited component of a record conflicts with a new
3267 -- discriminant. The discriminant is inserted first in the scope,
3268 -- but the error should be posted on it, not on the component.
3270 elsif Ekind (E) = E_Discriminant
3271 and then Present (Scope (Def_Id))
3272 and then Scope (Def_Id) /= Current_Scope
3274 Error_Msg_Sloc := Sloc (Def_Id);
3275 Error_Msg_N ("& conflicts with declaration#", E);
3278 -- If the name of the unit appears in its own context clause, a
3279 -- dummy package with the name has already been created, and the
3280 -- error emitted. Try to continue quietly.
3282 elsif Error_Posted (E)
3283 and then Sloc (E) = No_Location
3284 and then Nkind (Parent (E)) = N_Package_Specification
3285 and then Current_Scope = Standard_Standard
3287 Set_Scope (Def_Id, Current_Scope);
3291 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3293 -- Avoid cascaded messages with duplicate components in
3296 if Ekind_In (E, E_Component, E_Discriminant) then
3301 if Nkind (Parent (Parent (Def_Id))) =
3302 N_Generic_Subprogram_Declaration
3304 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3306 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3309 -- If entity is in standard, then we are in trouble, because it
3310 -- means that we have a library package with a duplicated name.
3311 -- That's hard to recover from, so abort!
3313 if S = Standard_Standard then
3314 raise Unrecoverable_Error;
3316 -- Otherwise we continue with the declaration. Having two
3317 -- identical declarations should not cause us too much trouble!
3325 -- If we fall through, declaration is OK, at least OK enough to continue
3327 -- If Def_Id is a discriminant or a record component we are in the midst
3328 -- of inheriting components in a derived record definition. Preserve
3329 -- their Ekind and Etype.
3331 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3334 -- If a type is already set, leave it alone (happens when a type
3335 -- declaration is reanalyzed following a call to the optimizer).
3337 elsif Present (Etype (Def_Id)) then
3340 -- Otherwise, the kind E_Void insures that premature uses of the entity
3341 -- will be detected. Any_Type insures that no cascaded errors will occur
3344 Set_Ekind (Def_Id, E_Void);
3345 Set_Etype (Def_Id, Any_Type);
3348 -- Inherited discriminants and components in derived record types are
3349 -- immediately visible. Itypes are not.
3351 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3352 or else (No (Corresponding_Remote_Type (Def_Id))
3353 and then not Is_Itype (Def_Id))
3355 Set_Is_Immediately_Visible (Def_Id);
3356 Set_Current_Entity (Def_Id);
3359 Set_Homonym (Def_Id, C);
3360 Append_Entity (Def_Id, S);
3361 Set_Public_Status (Def_Id);
3363 -- Declaring a homonym is not allowed in SPARK ...
3366 and then Restriction_Check_Required (SPARK)
3370 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3371 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3372 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3375 -- ... unless the new declaration is in a subprogram, and the
3376 -- visible declaration is a variable declaration or a parameter
3377 -- specification outside that subprogram.
3379 if Present (Enclosing_Subp)
3380 and then Nkind_In (Parent (C), N_Object_Declaration,
3381 N_Parameter_Specification)
3382 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3386 -- ... or the new declaration is in a package, and the visible
3387 -- declaration occurs outside that package.
3389 elsif Present (Enclosing_Pack)
3390 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3394 -- ... or the new declaration is a component declaration in a
3395 -- record type definition.
3397 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3400 -- Don't issue error for non-source entities
3402 elsif Comes_From_Source (Def_Id)
3403 and then Comes_From_Source (C)
3405 Error_Msg_Sloc := Sloc (C);
3406 Check_SPARK_Restriction
3407 ("redeclaration of identifier &#", Def_Id);
3412 -- Warn if new entity hides an old one
3414 if Warn_On_Hiding and then Present (C)
3416 -- Don't warn for record components since they always have a well
3417 -- defined scope which does not confuse other uses. Note that in
3418 -- some cases, Ekind has not been set yet.
3420 and then Ekind (C) /= E_Component
3421 and then Ekind (C) /= E_Discriminant
3422 and then Nkind (Parent (C)) /= N_Component_Declaration
3423 and then Ekind (Def_Id) /= E_Component
3424 and then Ekind (Def_Id) /= E_Discriminant
3425 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3427 -- Don't warn for one character variables. It is too common to use
3428 -- such variables as locals and will just cause too many false hits.
3430 and then Length_Of_Name (Chars (C)) /= 1
3432 -- Don't warn for non-source entities
3434 and then Comes_From_Source (C)
3435 and then Comes_From_Source (Def_Id)
3437 -- Don't warn unless entity in question is in extended main source
3439 and then In_Extended_Main_Source_Unit (Def_Id)
3441 -- Finally, the hidden entity must be either immediately visible or
3442 -- use visible (i.e. from a used package).
3445 (Is_Immediately_Visible (C)
3447 Is_Potentially_Use_Visible (C))
3449 Error_Msg_Sloc := Sloc (C);
3450 Error_Msg_N ("declaration hides &#?", Def_Id);
3454 --------------------------
3455 -- Explain_Limited_Type --
3456 --------------------------
3458 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3462 -- For array, component type must be limited
3464 if Is_Array_Type (T) then
3465 Error_Msg_Node_2 := T;
3467 ("\component type& of type& is limited", N, Component_Type (T));
3468 Explain_Limited_Type (Component_Type (T), N);
3470 elsif Is_Record_Type (T) then
3472 -- No need for extra messages if explicit limited record
3474 if Is_Limited_Record (Base_Type (T)) then
3478 -- Otherwise find a limited component. Check only components that
3479 -- come from source, or inherited components that appear in the
3480 -- source of the ancestor.
3482 C := First_Component (T);
3483 while Present (C) loop
3484 if Is_Limited_Type (Etype (C))
3486 (Comes_From_Source (C)
3488 (Present (Original_Record_Component (C))
3490 Comes_From_Source (Original_Record_Component (C))))
3492 Error_Msg_Node_2 := T;
3493 Error_Msg_NE ("\component& of type& has limited type", N, C);
3494 Explain_Limited_Type (Etype (C), N);
3501 -- The type may be declared explicitly limited, even if no component
3502 -- of it is limited, in which case we fall out of the loop.
3505 end Explain_Limited_Type;
3511 procedure Find_Actual
3513 Formal : out Entity_Id;
3516 Parnt : constant Node_Id := Parent (N);
3520 if (Nkind (Parnt) = N_Indexed_Component
3522 Nkind (Parnt) = N_Selected_Component)
3523 and then N = Prefix (Parnt)
3525 Find_Actual (Parnt, Formal, Call);
3528 elsif Nkind (Parnt) = N_Parameter_Association
3529 and then N = Explicit_Actual_Parameter (Parnt)
3531 Call := Parent (Parnt);
3533 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3542 -- If we have a call to a subprogram look for the parameter. Note that
3543 -- we exclude overloaded calls, since we don't know enough to be sure
3544 -- of giving the right answer in this case.
3546 if Is_Entity_Name (Name (Call))
3547 and then Present (Entity (Name (Call)))
3548 and then Is_Overloadable (Entity (Name (Call)))
3549 and then not Is_Overloaded (Name (Call))
3551 -- Fall here if we are definitely a parameter
3553 Actual := First_Actual (Call);
3554 Formal := First_Formal (Entity (Name (Call)));
3555 while Present (Formal) and then Present (Actual) loop
3559 Actual := Next_Actual (Actual);
3560 Formal := Next_Formal (Formal);
3565 -- Fall through here if we did not find matching actual
3571 ---------------------------
3572 -- Find_Body_Discriminal --
3573 ---------------------------
3575 function Find_Body_Discriminal
3576 (Spec_Discriminant : Entity_Id) return Entity_Id
3578 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3580 Tsk : constant Entity_Id :=
3581 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3585 -- Find discriminant of original concurrent type, and use its current
3586 -- discriminal, which is the renaming within the task/protected body.
3588 Disc := First_Discriminant (Tsk);
3589 while Present (Disc) loop
3590 if Chars (Disc) = Chars (Spec_Discriminant) then
3591 return Discriminal (Disc);
3594 Next_Discriminant (Disc);
3597 -- That loop should always succeed in finding a matching entry and
3598 -- returning. Fatal error if not.
3600 raise Program_Error;
3601 end Find_Body_Discriminal;
3603 -------------------------------------
3604 -- Find_Corresponding_Discriminant --
3605 -------------------------------------
3607 function Find_Corresponding_Discriminant
3609 Typ : Entity_Id) return Entity_Id
3611 Par_Disc : Entity_Id;
3612 Old_Disc : Entity_Id;
3613 New_Disc : Entity_Id;
3616 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3618 -- The original type may currently be private, and the discriminant
3619 -- only appear on its full view.
3621 if Is_Private_Type (Scope (Par_Disc))
3622 and then not Has_Discriminants (Scope (Par_Disc))
3623 and then Present (Full_View (Scope (Par_Disc)))
3625 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3627 Old_Disc := First_Discriminant (Scope (Par_Disc));
3630 if Is_Class_Wide_Type (Typ) then
3631 New_Disc := First_Discriminant (Root_Type (Typ));
3633 New_Disc := First_Discriminant (Typ);
3636 while Present (Old_Disc) and then Present (New_Disc) loop
3637 if Old_Disc = Par_Disc then
3640 Next_Discriminant (Old_Disc);
3641 Next_Discriminant (New_Disc);
3645 -- Should always find it
3647 raise Program_Error;
3648 end Find_Corresponding_Discriminant;
3650 --------------------------
3651 -- Find_Overlaid_Entity --
3652 --------------------------
3654 procedure Find_Overlaid_Entity
3656 Ent : out Entity_Id;
3662 -- We are looking for one of the two following forms:
3664 -- for X'Address use Y'Address
3668 -- Const : constant Address := expr;
3670 -- for X'Address use Const;
3672 -- In the second case, the expr is either Y'Address, or recursively a
3673 -- constant that eventually references Y'Address.
3678 if Nkind (N) = N_Attribute_Definition_Clause
3679 and then Chars (N) = Name_Address
3681 Expr := Expression (N);
3683 -- This loop checks the form of the expression for Y'Address,
3684 -- using recursion to deal with intermediate constants.
3687 -- Check for Y'Address
3689 if Nkind (Expr) = N_Attribute_Reference
3690 and then Attribute_Name (Expr) = Name_Address
3692 Expr := Prefix (Expr);
3695 -- Check for Const where Const is a constant entity
3697 elsif Is_Entity_Name (Expr)
3698 and then Ekind (Entity (Expr)) = E_Constant
3700 Expr := Constant_Value (Entity (Expr));
3702 -- Anything else does not need checking
3709 -- This loop checks the form of the prefix for an entity,
3710 -- using recursion to deal with intermediate components.
3713 -- Check for Y where Y is an entity
3715 if Is_Entity_Name (Expr) then
3716 Ent := Entity (Expr);
3719 -- Check for components
3722 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3724 Expr := Prefix (Expr);
3727 -- Anything else does not need checking
3734 end Find_Overlaid_Entity;
3736 -------------------------
3737 -- Find_Parameter_Type --
3738 -------------------------
3740 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3742 if Nkind (Param) /= N_Parameter_Specification then
3745 -- For an access parameter, obtain the type from the formal entity
3746 -- itself, because access to subprogram nodes do not carry a type.
3747 -- Shouldn't we always use the formal entity ???
3749 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3750 return Etype (Defining_Identifier (Param));
3753 return Etype (Parameter_Type (Param));
3755 end Find_Parameter_Type;
3757 -----------------------------
3758 -- Find_Static_Alternative --
3759 -----------------------------
3761 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3762 Expr : constant Node_Id := Expression (N);
3763 Val : constant Uint := Expr_Value (Expr);
3768 Alt := First (Alternatives (N));
3771 if Nkind (Alt) /= N_Pragma then
3772 Choice := First (Discrete_Choices (Alt));
3773 while Present (Choice) loop
3775 -- Others choice, always matches
3777 if Nkind (Choice) = N_Others_Choice then
3780 -- Range, check if value is in the range
3782 elsif Nkind (Choice) = N_Range then
3784 Val >= Expr_Value (Low_Bound (Choice))
3786 Val <= Expr_Value (High_Bound (Choice));
3788 -- Choice is a subtype name. Note that we know it must
3789 -- be a static subtype, since otherwise it would have
3790 -- been diagnosed as illegal.
3792 elsif Is_Entity_Name (Choice)
3793 and then Is_Type (Entity (Choice))
3795 exit Search when Is_In_Range (Expr, Etype (Choice),
3796 Assume_Valid => False);
3798 -- Choice is a subtype indication
3800 elsif Nkind (Choice) = N_Subtype_Indication then
3802 C : constant Node_Id := Constraint (Choice);
3803 R : constant Node_Id := Range_Expression (C);
3807 Val >= Expr_Value (Low_Bound (R))
3809 Val <= Expr_Value (High_Bound (R));
3812 -- Choice is a simple expression
3815 exit Search when Val = Expr_Value (Choice);
3823 pragma Assert (Present (Alt));
3826 -- The above loop *must* terminate by finding a match, since
3827 -- we know the case statement is valid, and the value of the
3828 -- expression is known at compile time. When we fall out of
3829 -- the loop, Alt points to the alternative that we know will
3830 -- be selected at run time.
3833 end Find_Static_Alternative;
3839 function First_Actual (Node : Node_Id) return Node_Id is
3843 if No (Parameter_Associations (Node)) then
3847 N := First (Parameter_Associations (Node));
3849 if Nkind (N) = N_Parameter_Association then
3850 return First_Named_Actual (Node);
3856 -----------------------
3857 -- Gather_Components --
3858 -----------------------
3860 procedure Gather_Components
3862 Comp_List : Node_Id;
3863 Governed_By : List_Id;
3865 Report_Errors : out Boolean)
3869 Discrete_Choice : Node_Id;
3870 Comp_Item : Node_Id;
3872 Discrim : Entity_Id;
3873 Discrim_Name : Node_Id;
3874 Discrim_Value : Node_Id;
3877 Report_Errors := False;
3879 if No (Comp_List) or else Null_Present (Comp_List) then
3882 elsif Present (Component_Items (Comp_List)) then
3883 Comp_Item := First (Component_Items (Comp_List));
3889 while Present (Comp_Item) loop
3891 -- Skip the tag of a tagged record, the interface tags, as well
3892 -- as all items that are not user components (anonymous types,
3893 -- rep clauses, Parent field, controller field).
3895 if Nkind (Comp_Item) = N_Component_Declaration then
3897 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3899 if not Is_Tag (Comp)
3900 and then Chars (Comp) /= Name_uParent
3902 Append_Elmt (Comp, Into);
3910 if No (Variant_Part (Comp_List)) then
3913 Discrim_Name := Name (Variant_Part (Comp_List));
3914 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3917 -- Look for the discriminant that governs this variant part.
3918 -- The discriminant *must* be in the Governed_By List
3920 Assoc := First (Governed_By);
3921 Find_Constraint : loop
3922 Discrim := First (Choices (Assoc));
3923 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3924 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3926 Chars (Corresponding_Discriminant (Entity (Discrim)))
3927 = Chars (Discrim_Name))
3928 or else Chars (Original_Record_Component (Entity (Discrim)))
3929 = Chars (Discrim_Name);
3931 if No (Next (Assoc)) then
3932 if not Is_Constrained (Typ)
3933 and then Is_Derived_Type (Typ)
3934 and then Present (Stored_Constraint (Typ))
3936 -- If the type is a tagged type with inherited discriminants,
3937 -- use the stored constraint on the parent in order to find
3938 -- the values of discriminants that are otherwise hidden by an
3939 -- explicit constraint. Renamed discriminants are handled in
3942 -- If several parent discriminants are renamed by a single
3943 -- discriminant of the derived type, the call to obtain the
3944 -- Corresponding_Discriminant field only retrieves the last
3945 -- of them. We recover the constraint on the others from the
3946 -- Stored_Constraint as well.
3953 D := First_Discriminant (Etype (Typ));
3954 C := First_Elmt (Stored_Constraint (Typ));
3955 while Present (D) and then Present (C) loop
3956 if Chars (Discrim_Name) = Chars (D) then
3957 if Is_Entity_Name (Node (C))
3958 and then Entity (Node (C)) = Entity (Discrim)
3960 -- D is renamed by Discrim, whose value is given in
3967 Make_Component_Association (Sloc (Typ),
3969 (New_Occurrence_Of (D, Sloc (Typ))),
3970 Duplicate_Subexpr_No_Checks (Node (C)));
3972 exit Find_Constraint;
3975 Next_Discriminant (D);
3982 if No (Next (Assoc)) then
3983 Error_Msg_NE (" missing value for discriminant&",
3984 First (Governed_By), Discrim_Name);
3985 Report_Errors := True;
3990 end loop Find_Constraint;
3992 Discrim_Value := Expression (Assoc);
3994 if not Is_OK_Static_Expression (Discrim_Value) then
3996 ("value for discriminant & must be static!",
3997 Discrim_Value, Discrim);
3998 Why_Not_Static (Discrim_Value);
3999 Report_Errors := True;
4003 Search_For_Discriminant_Value : declare
4009 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4012 Find_Discrete_Value : while Present (Variant) loop
4013 Discrete_Choice := First (Discrete_Choices (Variant));
4014 while Present (Discrete_Choice) loop
4016 exit Find_Discrete_Value when
4017 Nkind (Discrete_Choice) = N_Others_Choice;
4019 Get_Index_Bounds (Discrete_Choice, Low, High);
4021 UI_Low := Expr_Value (Low);
4022 UI_High := Expr_Value (High);
4024 exit Find_Discrete_Value when
4025 UI_Low <= UI_Discrim_Value
4027 UI_High >= UI_Discrim_Value;
4029 Next (Discrete_Choice);
4032 Next_Non_Pragma (Variant);
4033 end loop Find_Discrete_Value;
4034 end Search_For_Discriminant_Value;
4036 if No (Variant) then
4038 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4039 Report_Errors := True;
4043 -- If we have found the corresponding choice, recursively add its
4044 -- components to the Into list.
4046 Gather_Components (Empty,
4047 Component_List (Variant), Governed_By, Into, Report_Errors);
4048 end Gather_Components;
4050 ------------------------
4051 -- Get_Actual_Subtype --
4052 ------------------------
4054 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4055 Typ : constant Entity_Id := Etype (N);
4056 Utyp : Entity_Id := Underlying_Type (Typ);
4065 -- If what we have is an identifier that references a subprogram
4066 -- formal, or a variable or constant object, then we get the actual
4067 -- subtype from the referenced entity if one has been built.
4069 if Nkind (N) = N_Identifier
4071 (Is_Formal (Entity (N))
4072 or else Ekind (Entity (N)) = E_Constant
4073 or else Ekind (Entity (N)) = E_Variable)
4074 and then Present (Actual_Subtype (Entity (N)))
4076 return Actual_Subtype (Entity (N));
4078 -- Actual subtype of unchecked union is always itself. We never need
4079 -- the "real" actual subtype. If we did, we couldn't get it anyway
4080 -- because the discriminant is not available. The restrictions on
4081 -- Unchecked_Union are designed to make sure that this is OK.
4083 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4086 -- Here for the unconstrained case, we must find actual subtype
4087 -- No actual subtype is available, so we must build it on the fly.
4089 -- Checking the type, not the underlying type, for constrainedness
4090 -- seems to be necessary. Maybe all the tests should be on the type???
4092 elsif (not Is_Constrained (Typ))
4093 and then (Is_Array_Type (Utyp)
4094 or else (Is_Record_Type (Utyp)
4095 and then Has_Discriminants (Utyp)))
4096 and then not Has_Unknown_Discriminants (Utyp)
4097 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4099 -- Nothing to do if in spec expression (why not???)
4101 if In_Spec_Expression then
4104 elsif Is_Private_Type (Typ)
4105 and then not Has_Discriminants (Typ)
4107 -- If the type has no discriminants, there is no subtype to
4108 -- build, even if the underlying type is discriminated.
4112 -- Else build the actual subtype
4115 Decl := Build_Actual_Subtype (Typ, N);
4116 Atyp := Defining_Identifier (Decl);
4118 -- If Build_Actual_Subtype generated a new declaration then use it
4122 -- The actual subtype is an Itype, so analyze the declaration,
4123 -- but do not attach it to the tree, to get the type defined.
4125 Set_Parent (Decl, N);
4126 Set_Is_Itype (Atyp);
4127 Analyze (Decl, Suppress => All_Checks);
4128 Set_Associated_Node_For_Itype (Atyp, N);
4129 Set_Has_Delayed_Freeze (Atyp, False);
4131 -- We need to freeze the actual subtype immediately. This is
4132 -- needed, because otherwise this Itype will not get frozen
4133 -- at all, and it is always safe to freeze on creation because
4134 -- any associated types must be frozen at this point.
4136 Freeze_Itype (Atyp, N);
4139 -- Otherwise we did not build a declaration, so return original
4146 -- For all remaining cases, the actual subtype is the same as
4147 -- the nominal type.
4152 end Get_Actual_Subtype;
4154 -------------------------------------
4155 -- Get_Actual_Subtype_If_Available --
4156 -------------------------------------
4158 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4159 Typ : constant Entity_Id := Etype (N);
4162 -- If what we have is an identifier that references a subprogram
4163 -- formal, or a variable or constant object, then we get the actual
4164 -- subtype from the referenced entity if one has been built.
4166 if Nkind (N) = N_Identifier
4168 (Is_Formal (Entity (N))
4169 or else Ekind (Entity (N)) = E_Constant
4170 or else Ekind (Entity (N)) = E_Variable)
4171 and then Present (Actual_Subtype (Entity (N)))
4173 return Actual_Subtype (Entity (N));
4175 -- Otherwise the Etype of N is returned unchanged
4180 end Get_Actual_Subtype_If_Available;
4182 -------------------------------
4183 -- Get_Default_External_Name --
4184 -------------------------------
4186 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4188 Get_Decoded_Name_String (Chars (E));
4190 if Opt.External_Name_Imp_Casing = Uppercase then
4191 Set_Casing (All_Upper_Case);
4193 Set_Casing (All_Lower_Case);
4197 Make_String_Literal (Sloc (E),
4198 Strval => String_From_Name_Buffer);
4199 end Get_Default_External_Name;
4201 ---------------------------
4202 -- Get_Enum_Lit_From_Pos --
4203 ---------------------------
4205 function Get_Enum_Lit_From_Pos
4208 Loc : Source_Ptr) return Node_Id
4213 -- In the case where the literal is of type Character, Wide_Character
4214 -- or Wide_Wide_Character or of a type derived from them, there needs
4215 -- to be some special handling since there is no explicit chain of
4216 -- literals to search. Instead, an N_Character_Literal node is created
4217 -- with the appropriate Char_Code and Chars fields.
4219 if Is_Standard_Character_Type (T) then
4220 Set_Character_Literal_Name (UI_To_CC (Pos));
4222 Make_Character_Literal (Loc,
4224 Char_Literal_Value => Pos);
4226 -- For all other cases, we have a complete table of literals, and
4227 -- we simply iterate through the chain of literal until the one
4228 -- with the desired position value is found.
4232 Lit := First_Literal (Base_Type (T));
4233 for J in 1 .. UI_To_Int (Pos) loop
4237 return New_Occurrence_Of (Lit, Loc);
4239 end Get_Enum_Lit_From_Pos;
4241 ------------------------
4242 -- Get_Generic_Entity --
4243 ------------------------
4245 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4246 Ent : constant Entity_Id := Entity (Name (N));
4248 if Present (Renamed_Object (Ent)) then
4249 return Renamed_Object (Ent);
4253 end Get_Generic_Entity;
4255 ----------------------
4256 -- Get_Index_Bounds --
4257 ----------------------
4259 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4260 Kind : constant Node_Kind := Nkind (N);
4264 if Kind = N_Range then
4266 H := High_Bound (N);
4268 elsif Kind = N_Subtype_Indication then
4269 R := Range_Expression (Constraint (N));
4277 L := Low_Bound (Range_Expression (Constraint (N)));
4278 H := High_Bound (Range_Expression (Constraint (N)));
4281 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4282 if Error_Posted (Scalar_Range (Entity (N))) then
4286 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4287 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4290 L := Low_Bound (Scalar_Range (Entity (N)));
4291 H := High_Bound (Scalar_Range (Entity (N)));
4295 -- N is an expression, indicating a range with one value
4300 end Get_Index_Bounds;
4302 ----------------------------------
4303 -- Get_Library_Unit_Name_string --
4304 ----------------------------------
4306 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4307 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4310 Get_Unit_Name_String (Unit_Name_Id);
4312 -- Remove seven last character (" (spec)" or " (body)")
4314 Name_Len := Name_Len - 7;
4315 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4316 end Get_Library_Unit_Name_String;
4318 ------------------------
4319 -- Get_Name_Entity_Id --
4320 ------------------------
4322 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4324 return Entity_Id (Get_Name_Table_Info (Id));
4325 end Get_Name_Entity_Id;
4331 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4333 return Get_Pragma_Id (Pragma_Name (N));
4336 ---------------------------
4337 -- Get_Referenced_Object --
4338 ---------------------------
4340 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4345 while Is_Entity_Name (R)
4346 and then Present (Renamed_Object (Entity (R)))
4348 R := Renamed_Object (Entity (R));
4352 end Get_Referenced_Object;
4354 ------------------------
4355 -- Get_Renamed_Entity --
4356 ------------------------
4358 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4363 while Present (Renamed_Entity (R)) loop
4364 R := Renamed_Entity (R);
4368 end Get_Renamed_Entity;
4370 -------------------------
4371 -- Get_Subprogram_Body --
4372 -------------------------
4374 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4378 Decl := Unit_Declaration_Node (E);
4380 if Nkind (Decl) = N_Subprogram_Body then
4383 -- The below comment is bad, because it is possible for
4384 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4386 else -- Nkind (Decl) = N_Subprogram_Declaration
4388 if Present (Corresponding_Body (Decl)) then
4389 return Unit_Declaration_Node (Corresponding_Body (Decl));
4391 -- Imported subprogram case
4397 end Get_Subprogram_Body;
4399 ---------------------------
4400 -- Get_Subprogram_Entity --
4401 ---------------------------
4403 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4408 if Nkind (Nod) = N_Accept_Statement then
4409 Nam := Entry_Direct_Name (Nod);
4411 -- For an entry call, the prefix of the call is a selected component.
4412 -- Need additional code for internal calls ???
4414 elsif Nkind (Nod) = N_Entry_Call_Statement then
4415 if Nkind (Name (Nod)) = N_Selected_Component then
4416 Nam := Entity (Selector_Name (Name (Nod)));
4425 if Nkind (Nam) = N_Explicit_Dereference then
4426 Proc := Etype (Prefix (Nam));
4427 elsif Is_Entity_Name (Nam) then
4428 Proc := Entity (Nam);
4433 if Is_Object (Proc) then
4434 Proc := Etype (Proc);
4437 if Ekind (Proc) = E_Access_Subprogram_Type then
4438 Proc := Directly_Designated_Type (Proc);
4441 if not Is_Subprogram (Proc)
4442 and then Ekind (Proc) /= E_Subprogram_Type
4448 end Get_Subprogram_Entity;
4450 -----------------------------
4451 -- Get_Task_Body_Procedure --
4452 -----------------------------
4454 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4456 -- Note: A task type may be the completion of a private type with
4457 -- discriminants. When performing elaboration checks on a task
4458 -- declaration, the current view of the type may be the private one,
4459 -- and the procedure that holds the body of the task is held in its
4462 -- This is an odd function, why not have Task_Body_Procedure do
4463 -- the following digging???
4465 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4466 end Get_Task_Body_Procedure;
4468 -----------------------
4469 -- Has_Access_Values --
4470 -----------------------
4472 function Has_Access_Values (T : Entity_Id) return Boolean is
4473 Typ : constant Entity_Id := Underlying_Type (T);
4476 -- Case of a private type which is not completed yet. This can only
4477 -- happen in the case of a generic format type appearing directly, or
4478 -- as a component of the type to which this function is being applied
4479 -- at the top level. Return False in this case, since we certainly do
4480 -- not know that the type contains access types.
4485 elsif Is_Access_Type (Typ) then
4488 elsif Is_Array_Type (Typ) then
4489 return Has_Access_Values (Component_Type (Typ));
4491 elsif Is_Record_Type (Typ) then
4496 -- Loop to Check components
4498 Comp := First_Component_Or_Discriminant (Typ);
4499 while Present (Comp) loop
4501 -- Check for access component, tag field does not count, even
4502 -- though it is implemented internally using an access type.
4504 if Has_Access_Values (Etype (Comp))
4505 and then Chars (Comp) /= Name_uTag
4510 Next_Component_Or_Discriminant (Comp);
4519 end Has_Access_Values;
4521 ------------------------------
4522 -- Has_Compatible_Alignment --
4523 ------------------------------
4525 function Has_Compatible_Alignment
4527 Expr : Node_Id) return Alignment_Result
4529 function Has_Compatible_Alignment_Internal
4532 Default : Alignment_Result) return Alignment_Result;
4533 -- This is the internal recursive function that actually does the work.
4534 -- There is one additional parameter, which says what the result should
4535 -- be if no alignment information is found, and there is no definite
4536 -- indication of compatible alignments. At the outer level, this is set
4537 -- to Unknown, but for internal recursive calls in the case where types
4538 -- are known to be correct, it is set to Known_Compatible.
4540 ---------------------------------------
4541 -- Has_Compatible_Alignment_Internal --
4542 ---------------------------------------
4544 function Has_Compatible_Alignment_Internal
4547 Default : Alignment_Result) return Alignment_Result
4549 Result : Alignment_Result := Known_Compatible;
4550 -- Holds the current status of the result. Note that once a value of
4551 -- Known_Incompatible is set, it is sticky and does not get changed
4552 -- to Unknown (the value in Result only gets worse as we go along,
4555 Offs : Uint := No_Uint;
4556 -- Set to a factor of the offset from the base object when Expr is a
4557 -- selected or indexed component, based on Component_Bit_Offset and
4558 -- Component_Size respectively. A negative value is used to represent
4559 -- a value which is not known at compile time.
4561 procedure Check_Prefix;
4562 -- Checks the prefix recursively in the case where the expression
4563 -- is an indexed or selected component.
4565 procedure Set_Result (R : Alignment_Result);
4566 -- If R represents a worse outcome (unknown instead of known
4567 -- compatible, or known incompatible), then set Result to R.
4573 procedure Check_Prefix is
4575 -- The subtlety here is that in doing a recursive call to check
4576 -- the prefix, we have to decide what to do in the case where we
4577 -- don't find any specific indication of an alignment problem.
4579 -- At the outer level, we normally set Unknown as the result in
4580 -- this case, since we can only set Known_Compatible if we really
4581 -- know that the alignment value is OK, but for the recursive
4582 -- call, in the case where the types match, and we have not
4583 -- specified a peculiar alignment for the object, we are only
4584 -- concerned about suspicious rep clauses, the default case does
4585 -- not affect us, since the compiler will, in the absence of such
4586 -- rep clauses, ensure that the alignment is correct.
4588 if Default = Known_Compatible
4590 (Etype (Obj) = Etype (Expr)
4591 and then (Unknown_Alignment (Obj)
4593 Alignment (Obj) = Alignment (Etype (Obj))))
4596 (Has_Compatible_Alignment_Internal
4597 (Obj, Prefix (Expr), Known_Compatible));
4599 -- In all other cases, we need a full check on the prefix
4603 (Has_Compatible_Alignment_Internal
4604 (Obj, Prefix (Expr), Unknown));
4612 procedure Set_Result (R : Alignment_Result) is
4619 -- Start of processing for Has_Compatible_Alignment_Internal
4622 -- If Expr is a selected component, we must make sure there is no
4623 -- potentially troublesome component clause, and that the record is
4626 if Nkind (Expr) = N_Selected_Component then
4628 -- Packed record always generate unknown alignment
4630 if Is_Packed (Etype (Prefix (Expr))) then
4631 Set_Result (Unknown);
4634 -- Check prefix and component offset
4637 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4639 -- If Expr is an indexed component, we must make sure there is no
4640 -- potentially troublesome Component_Size clause and that the array
4641 -- is not bit-packed.
4643 elsif Nkind (Expr) = N_Indexed_Component then
4645 Typ : constant Entity_Id := Etype (Prefix (Expr));
4646 Ind : constant Node_Id := First_Index (Typ);
4649 -- Bit packed array always generates unknown alignment
4651 if Is_Bit_Packed_Array (Typ) then
4652 Set_Result (Unknown);
4655 -- Check prefix and component offset
4658 Offs := Component_Size (Typ);
4660 -- Small optimization: compute the full offset when possible
4663 and then Offs > Uint_0
4664 and then Present (Ind)
4665 and then Nkind (Ind) = N_Range
4666 and then Compile_Time_Known_Value (Low_Bound (Ind))
4667 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4669 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4670 - Expr_Value (Low_Bound ((Ind))));
4675 -- If we have a null offset, the result is entirely determined by
4676 -- the base object and has already been computed recursively.
4678 if Offs = Uint_0 then
4681 -- Case where we know the alignment of the object
4683 elsif Known_Alignment (Obj) then
4685 ObjA : constant Uint := Alignment (Obj);
4686 ExpA : Uint := No_Uint;
4687 SizA : Uint := No_Uint;
4690 -- If alignment of Obj is 1, then we are always OK
4693 Set_Result (Known_Compatible);
4695 -- Alignment of Obj is greater than 1, so we need to check
4698 -- If we have an offset, see if it is compatible
4700 if Offs /= No_Uint and Offs > Uint_0 then
4701 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4702 Set_Result (Known_Incompatible);
4705 -- See if Expr is an object with known alignment
4707 elsif Is_Entity_Name (Expr)
4708 and then Known_Alignment (Entity (Expr))
4710 ExpA := Alignment (Entity (Expr));
4712 -- Otherwise, we can use the alignment of the type of
4713 -- Expr given that we already checked for
4714 -- discombobulating rep clauses for the cases of indexed
4715 -- and selected components above.
4717 elsif Known_Alignment (Etype (Expr)) then
4718 ExpA := Alignment (Etype (Expr));
4720 -- Otherwise the alignment is unknown
4723 Set_Result (Default);
4726 -- If we got an alignment, see if it is acceptable
4728 if ExpA /= No_Uint and then ExpA < ObjA then
4729 Set_Result (Known_Incompatible);
4732 -- If Expr is not a piece of a larger object, see if size
4733 -- is given. If so, check that it is not too small for the
4734 -- required alignment.
4736 if Offs /= No_Uint then
4739 -- See if Expr is an object with known size
4741 elsif Is_Entity_Name (Expr)
4742 and then Known_Static_Esize (Entity (Expr))
4744 SizA := Esize (Entity (Expr));
4746 -- Otherwise, we check the object size of the Expr type
4748 elsif Known_Static_Esize (Etype (Expr)) then
4749 SizA := Esize (Etype (Expr));
4752 -- If we got a size, see if it is a multiple of the Obj
4753 -- alignment, if not, then the alignment cannot be
4754 -- acceptable, since the size is always a multiple of the
4757 if SizA /= No_Uint then
4758 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4759 Set_Result (Known_Incompatible);
4765 -- If we do not know required alignment, any non-zero offset is a
4766 -- potential problem (but certainly may be OK, so result is unknown).
4768 elsif Offs /= No_Uint then
4769 Set_Result (Unknown);
4771 -- If we can't find the result by direct comparison of alignment
4772 -- values, then there is still one case that we can determine known
4773 -- result, and that is when we can determine that the types are the
4774 -- same, and no alignments are specified. Then we known that the
4775 -- alignments are compatible, even if we don't know the alignment
4776 -- value in the front end.
4778 elsif Etype (Obj) = Etype (Expr) then
4780 -- Types are the same, but we have to check for possible size
4781 -- and alignments on the Expr object that may make the alignment
4782 -- different, even though the types are the same.
4784 if Is_Entity_Name (Expr) then
4786 -- First check alignment of the Expr object. Any alignment less
4787 -- than Maximum_Alignment is worrisome since this is the case
4788 -- where we do not know the alignment of Obj.
4790 if Known_Alignment (Entity (Expr))
4792 UI_To_Int (Alignment (Entity (Expr))) <
4793 Ttypes.Maximum_Alignment
4795 Set_Result (Unknown);
4797 -- Now check size of Expr object. Any size that is not an
4798 -- even multiple of Maximum_Alignment is also worrisome
4799 -- since it may cause the alignment of the object to be less
4800 -- than the alignment of the type.
4802 elsif Known_Static_Esize (Entity (Expr))
4804 (UI_To_Int (Esize (Entity (Expr))) mod
4805 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4808 Set_Result (Unknown);
4810 -- Otherwise same type is decisive
4813 Set_Result (Known_Compatible);
4817 -- Another case to deal with is when there is an explicit size or
4818 -- alignment clause when the types are not the same. If so, then the
4819 -- result is Unknown. We don't need to do this test if the Default is
4820 -- Unknown, since that result will be set in any case.
4822 elsif Default /= Unknown
4823 and then (Has_Size_Clause (Etype (Expr))
4825 Has_Alignment_Clause (Etype (Expr)))
4827 Set_Result (Unknown);
4829 -- If no indication found, set default
4832 Set_Result (Default);
4835 -- Return worst result found
4838 end Has_Compatible_Alignment_Internal;
4840 -- Start of processing for Has_Compatible_Alignment
4843 -- If Obj has no specified alignment, then set alignment from the type
4844 -- alignment. Perhaps we should always do this, but for sure we should
4845 -- do it when there is an address clause since we can do more if the
4846 -- alignment is known.
4848 if Unknown_Alignment (Obj) then
4849 Set_Alignment (Obj, Alignment (Etype (Obj)));
4852 -- Now do the internal call that does all the work
4854 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4855 end Has_Compatible_Alignment;
4857 ----------------------
4858 -- Has_Declarations --
4859 ----------------------
4861 function Has_Declarations (N : Node_Id) return Boolean is
4863 return Nkind_In (Nkind (N), N_Accept_Statement,
4865 N_Compilation_Unit_Aux,
4871 N_Package_Specification);
4872 end Has_Declarations;
4874 -------------------------------------------
4875 -- Has_Discriminant_Dependent_Constraint --
4876 -------------------------------------------
4878 function Has_Discriminant_Dependent_Constraint
4879 (Comp : Entity_Id) return Boolean
4881 Comp_Decl : constant Node_Id := Parent (Comp);
4882 Subt_Indic : constant Node_Id :=
4883 Subtype_Indication (Component_Definition (Comp_Decl));
4888 if Nkind (Subt_Indic) = N_Subtype_Indication then
4889 Constr := Constraint (Subt_Indic);
4891 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4892 Assn := First (Constraints (Constr));
4893 while Present (Assn) loop
4894 case Nkind (Assn) is
4895 when N_Subtype_Indication |
4899 if Depends_On_Discriminant (Assn) then
4903 when N_Discriminant_Association =>
4904 if Depends_On_Discriminant (Expression (Assn)) then
4919 end Has_Discriminant_Dependent_Constraint;
4921 --------------------
4922 -- Has_Infinities --
4923 --------------------
4925 function Has_Infinities (E : Entity_Id) return Boolean is
4928 Is_Floating_Point_Type (E)
4929 and then Nkind (Scalar_Range (E)) = N_Range
4930 and then Includes_Infinities (Scalar_Range (E));
4933 --------------------
4934 -- Has_Interfaces --
4935 --------------------
4937 function Has_Interfaces
4939 Use_Full_View : Boolean := True) return Boolean
4941 Typ : Entity_Id := Base_Type (T);
4944 -- Handle concurrent types
4946 if Is_Concurrent_Type (Typ) then
4947 Typ := Corresponding_Record_Type (Typ);
4950 if not Present (Typ)
4951 or else not Is_Record_Type (Typ)
4952 or else not Is_Tagged_Type (Typ)
4957 -- Handle private types
4960 and then Present (Full_View (Typ))
4962 Typ := Full_View (Typ);
4965 -- Handle concurrent record types
4967 if Is_Concurrent_Record_Type (Typ)
4968 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4974 if Is_Interface (Typ)
4976 (Is_Record_Type (Typ)
4977 and then Present (Interfaces (Typ))
4978 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4983 exit when Etype (Typ) = Typ
4985 -- Handle private types
4987 or else (Present (Full_View (Etype (Typ)))
4988 and then Full_View (Etype (Typ)) = Typ)
4990 -- Protect the frontend against wrong source with cyclic
4993 or else Etype (Typ) = T;
4995 -- Climb to the ancestor type handling private types
4997 if Present (Full_View (Etype (Typ))) then
4998 Typ := Full_View (Etype (Typ));
5007 ------------------------
5008 -- Has_Null_Exclusion --
5009 ------------------------
5011 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5014 when N_Access_Definition |
5015 N_Access_Function_Definition |
5016 N_Access_Procedure_Definition |
5017 N_Access_To_Object_Definition |
5019 N_Derived_Type_Definition |
5020 N_Function_Specification |
5021 N_Subtype_Declaration =>
5022 return Null_Exclusion_Present (N);
5024 when N_Component_Definition |
5025 N_Formal_Object_Declaration |
5026 N_Object_Renaming_Declaration =>
5027 if Present (Subtype_Mark (N)) then
5028 return Null_Exclusion_Present (N);
5029 else pragma Assert (Present (Access_Definition (N)));
5030 return Null_Exclusion_Present (Access_Definition (N));
5033 when N_Discriminant_Specification =>
5034 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5035 return Null_Exclusion_Present (Discriminant_Type (N));
5037 return Null_Exclusion_Present (N);
5040 when N_Object_Declaration =>
5041 if Nkind (Object_Definition (N)) = N_Access_Definition then
5042 return Null_Exclusion_Present (Object_Definition (N));
5044 return Null_Exclusion_Present (N);
5047 when N_Parameter_Specification =>
5048 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5049 return Null_Exclusion_Present (Parameter_Type (N));
5051 return Null_Exclusion_Present (N);
5058 end Has_Null_Exclusion;
5060 ------------------------
5061 -- Has_Null_Extension --
5062 ------------------------
5064 function Has_Null_Extension (T : Entity_Id) return Boolean is
5065 B : constant Entity_Id := Base_Type (T);
5070 if Nkind (Parent (B)) = N_Full_Type_Declaration
5071 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5073 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5075 if Present (Ext) then
5076 if Null_Present (Ext) then
5079 Comps := Component_List (Ext);
5081 -- The null component list is rewritten during analysis to
5082 -- include the parent component. Any other component indicates
5083 -- that the extension was not originally null.
5085 return Null_Present (Comps)
5086 or else No (Next (First (Component_Items (Comps))));
5095 end Has_Null_Extension;
5097 -------------------------------
5098 -- Has_Overriding_Initialize --
5099 -------------------------------
5101 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5102 BT : constant Entity_Id := Base_Type (T);
5106 if Is_Controlled (BT) then
5107 if Is_RTU (Scope (BT), Ada_Finalization) then
5110 elsif Present (Primitive_Operations (BT)) then
5111 P := First_Elmt (Primitive_Operations (BT));
5112 while Present (P) loop
5114 Init : constant Entity_Id := Node (P);
5115 Formal : constant Entity_Id := First_Formal (Init);
5117 if Ekind (Init) = E_Procedure
5118 and then Chars (Init) = Name_Initialize
5119 and then Comes_From_Source (Init)
5120 and then Present (Formal)
5121 and then Etype (Formal) = BT
5122 and then No (Next_Formal (Formal))
5123 and then (Ada_Version < Ada_2012
5124 or else not Null_Present (Parent (Init)))
5134 -- Here if type itself does not have a non-null Initialize operation:
5135 -- check immediate ancestor.
5137 if Is_Derived_Type (BT)
5138 and then Has_Overriding_Initialize (Etype (BT))
5145 end Has_Overriding_Initialize;
5147 --------------------------------------
5148 -- Has_Preelaborable_Initialization --
5149 --------------------------------------
5151 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5154 procedure Check_Components (E : Entity_Id);
5155 -- Check component/discriminant chain, sets Has_PE False if a component
5156 -- or discriminant does not meet the preelaborable initialization rules.
5158 ----------------------
5159 -- Check_Components --
5160 ----------------------
5162 procedure Check_Components (E : Entity_Id) is
5166 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5167 -- Returns True if and only if the expression denoted by N does not
5168 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5170 ---------------------------------
5171 -- Is_Preelaborable_Expression --
5172 ---------------------------------
5174 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5178 Comp_Type : Entity_Id;
5179 Is_Array_Aggr : Boolean;
5182 if Is_Static_Expression (N) then
5185 elsif Nkind (N) = N_Null then
5188 -- Attributes are allowed in general, even if their prefix is a
5189 -- formal type. (It seems that certain attributes known not to be
5190 -- static might not be allowed, but there are no rules to prevent
5193 elsif Nkind (N) = N_Attribute_Reference then
5196 -- The name of a discriminant evaluated within its parent type is
5197 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5198 -- names that denote discriminals as well as discriminants to
5199 -- catch references occurring within init procs.
5201 elsif Is_Entity_Name (N)
5203 (Ekind (Entity (N)) = E_Discriminant
5205 ((Ekind (Entity (N)) = E_Constant
5206 or else Ekind (Entity (N)) = E_In_Parameter)
5207 and then Present (Discriminal_Link (Entity (N)))))
5211 elsif Nkind (N) = N_Qualified_Expression then
5212 return Is_Preelaborable_Expression (Expression (N));
5214 -- For aggregates we have to check that each of the associations
5215 -- is preelaborable.
5217 elsif Nkind (N) = N_Aggregate
5218 or else Nkind (N) = N_Extension_Aggregate
5220 Is_Array_Aggr := Is_Array_Type (Etype (N));
5222 if Is_Array_Aggr then
5223 Comp_Type := Component_Type (Etype (N));
5226 -- Check the ancestor part of extension aggregates, which must
5227 -- be either the name of a type that has preelaborable init or
5228 -- an expression that is preelaborable.
5230 if Nkind (N) = N_Extension_Aggregate then
5232 Anc_Part : constant Node_Id := Ancestor_Part (N);
5235 if Is_Entity_Name (Anc_Part)
5236 and then Is_Type (Entity (Anc_Part))
5238 if not Has_Preelaborable_Initialization
5244 elsif not Is_Preelaborable_Expression (Anc_Part) then
5250 -- Check positional associations
5252 Exp := First (Expressions (N));
5253 while Present (Exp) loop
5254 if not Is_Preelaborable_Expression (Exp) then
5261 -- Check named associations
5263 Assn := First (Component_Associations (N));
5264 while Present (Assn) loop
5265 Choice := First (Choices (Assn));
5266 while Present (Choice) loop
5267 if Is_Array_Aggr then
5268 if Nkind (Choice) = N_Others_Choice then
5271 elsif Nkind (Choice) = N_Range then
5272 if not Is_Static_Range (Choice) then
5276 elsif not Is_Static_Expression (Choice) then
5281 Comp_Type := Etype (Choice);
5287 -- If the association has a <> at this point, then we have
5288 -- to check whether the component's type has preelaborable
5289 -- initialization. Note that this only occurs when the
5290 -- association's corresponding component does not have a
5291 -- default expression, the latter case having already been
5292 -- expanded as an expression for the association.
5294 if Box_Present (Assn) then
5295 if not Has_Preelaborable_Initialization (Comp_Type) then
5299 -- In the expression case we check whether the expression
5300 -- is preelaborable.
5303 not Is_Preelaborable_Expression (Expression (Assn))
5311 -- If we get here then aggregate as a whole is preelaborable
5315 -- All other cases are not preelaborable
5320 end Is_Preelaborable_Expression;
5322 -- Start of processing for Check_Components
5325 -- Loop through entities of record or protected type
5328 while Present (Ent) loop
5330 -- We are interested only in components and discriminants
5337 -- Get default expression if any. If there is no declaration
5338 -- node, it means we have an internal entity. The parent and
5339 -- tag fields are examples of such entities. For such cases,
5340 -- we just test the type of the entity.
5342 if Present (Declaration_Node (Ent)) then
5343 Exp := Expression (Declaration_Node (Ent));
5346 when E_Discriminant =>
5348 -- Note: for a renamed discriminant, the Declaration_Node
5349 -- may point to the one from the ancestor, and have a
5350 -- different expression, so use the proper attribute to
5351 -- retrieve the expression from the derived constraint.
5353 Exp := Discriminant_Default_Value (Ent);
5356 goto Check_Next_Entity;
5359 -- A component has PI if it has no default expression and the
5360 -- component type has PI.
5363 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5368 -- Require the default expression to be preelaborable
5370 elsif not Is_Preelaborable_Expression (Exp) then
5375 <<Check_Next_Entity>>
5378 end Check_Components;
5380 -- Start of processing for Has_Preelaborable_Initialization
5383 -- Immediate return if already marked as known preelaborable init. This
5384 -- covers types for which this function has already been called once
5385 -- and returned True (in which case the result is cached), and also
5386 -- types to which a pragma Preelaborable_Initialization applies.
5388 if Known_To_Have_Preelab_Init (E) then
5392 -- If the type is a subtype representing a generic actual type, then
5393 -- test whether its base type has preelaborable initialization since
5394 -- the subtype representing the actual does not inherit this attribute
5395 -- from the actual or formal. (but maybe it should???)
5397 if Is_Generic_Actual_Type (E) then
5398 return Has_Preelaborable_Initialization (Base_Type (E));
5401 -- All elementary types have preelaborable initialization
5403 if Is_Elementary_Type (E) then
5406 -- Array types have PI if the component type has PI
5408 elsif Is_Array_Type (E) then
5409 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5411 -- A derived type has preelaborable initialization if its parent type
5412 -- has preelaborable initialization and (in the case of a derived record
5413 -- extension) if the non-inherited components all have preelaborable
5414 -- initialization. However, a user-defined controlled type with an
5415 -- overriding Initialize procedure does not have preelaborable
5418 elsif Is_Derived_Type (E) then
5420 -- If the derived type is a private extension then it doesn't have
5421 -- preelaborable initialization.
5423 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5427 -- First check whether ancestor type has preelaborable initialization
5429 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5431 -- If OK, check extension components (if any)
5433 if Has_PE and then Is_Record_Type (E) then
5434 Check_Components (First_Entity (E));
5437 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5438 -- with a user defined Initialize procedure does not have PI.
5441 and then Is_Controlled (E)
5442 and then Has_Overriding_Initialize (E)
5447 -- Private types not derived from a type having preelaborable init and
5448 -- that are not marked with pragma Preelaborable_Initialization do not
5449 -- have preelaborable initialization.
5451 elsif Is_Private_Type (E) then
5454 -- Record type has PI if it is non private and all components have PI
5456 elsif Is_Record_Type (E) then
5458 Check_Components (First_Entity (E));
5460 -- Protected types must not have entries, and components must meet
5461 -- same set of rules as for record components.
5463 elsif Is_Protected_Type (E) then
5464 if Has_Entries (E) then
5468 Check_Components (First_Entity (E));
5469 Check_Components (First_Private_Entity (E));
5472 -- Type System.Address always has preelaborable initialization
5474 elsif Is_RTE (E, RE_Address) then
5477 -- In all other cases, type does not have preelaborable initialization
5483 -- If type has preelaborable initialization, cache result
5486 Set_Known_To_Have_Preelab_Init (E);
5490 end Has_Preelaborable_Initialization;
5492 ---------------------------
5493 -- Has_Private_Component --
5494 ---------------------------
5496 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5497 Btype : Entity_Id := Base_Type (Type_Id);
5498 Component : Entity_Id;
5501 if Error_Posted (Type_Id)
5502 or else Error_Posted (Btype)
5507 if Is_Class_Wide_Type (Btype) then
5508 Btype := Root_Type (Btype);
5511 if Is_Private_Type (Btype) then
5513 UT : constant Entity_Id := Underlying_Type (Btype);
5516 if No (Full_View (Btype)) then
5517 return not Is_Generic_Type (Btype)
5518 and then not Is_Generic_Type (Root_Type (Btype));
5520 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5523 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5527 elsif Is_Array_Type (Btype) then
5528 return Has_Private_Component (Component_Type (Btype));
5530 elsif Is_Record_Type (Btype) then
5531 Component := First_Component (Btype);
5532 while Present (Component) loop
5533 if Has_Private_Component (Etype (Component)) then
5537 Next_Component (Component);
5542 elsif Is_Protected_Type (Btype)
5543 and then Present (Corresponding_Record_Type (Btype))
5545 return Has_Private_Component (Corresponding_Record_Type (Btype));
5550 end Has_Private_Component;
5552 -----------------------------
5553 -- Has_Static_Array_Bounds --
5554 -----------------------------
5556 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5557 Ndims : constant Nat := Number_Dimensions (Typ);
5564 -- Unconstrained types do not have static bounds
5566 if not Is_Constrained (Typ) then
5570 -- First treat specially string literals, as the lower bound and length
5571 -- of string literals are not stored like those of arrays.
5573 -- A string literal always has static bounds
5575 if Ekind (Typ) = E_String_Literal_Subtype then
5579 -- Treat all dimensions in turn
5581 Index := First_Index (Typ);
5582 for Indx in 1 .. Ndims loop
5584 -- In case of an erroneous index which is not a discrete type, return
5585 -- that the type is not static.
5587 if not Is_Discrete_Type (Etype (Index))
5588 or else Etype (Index) = Any_Type
5593 Get_Index_Bounds (Index, Low, High);
5595 if Error_Posted (Low) or else Error_Posted (High) then
5599 if Is_OK_Static_Expression (Low)
5600 and then Is_OK_Static_Expression (High)
5610 -- If we fall through the loop, all indexes matched
5613 end Has_Static_Array_Bounds;
5619 function Has_Stream (T : Entity_Id) return Boolean is
5626 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5629 elsif Is_Array_Type (T) then
5630 return Has_Stream (Component_Type (T));
5632 elsif Is_Record_Type (T) then
5633 E := First_Component (T);
5634 while Present (E) loop
5635 if Has_Stream (Etype (E)) then
5644 elsif Is_Private_Type (T) then
5645 return Has_Stream (Underlying_Type (T));
5656 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5658 Get_Name_String (Chars (E));
5659 return Name_Buffer (Name_Len) = Suffix;
5662 --------------------------
5663 -- Has_Tagged_Component --
5664 --------------------------
5666 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5670 if Is_Private_Type (Typ)
5671 and then Present (Underlying_Type (Typ))
5673 return Has_Tagged_Component (Underlying_Type (Typ));
5675 elsif Is_Array_Type (Typ) then
5676 return Has_Tagged_Component (Component_Type (Typ));
5678 elsif Is_Tagged_Type (Typ) then
5681 elsif Is_Record_Type (Typ) then
5682 Comp := First_Component (Typ);
5683 while Present (Comp) loop
5684 if Has_Tagged_Component (Etype (Comp)) then
5688 Next_Component (Comp);
5696 end Has_Tagged_Component;
5698 -------------------------
5699 -- Implementation_Kind --
5700 -------------------------
5702 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5703 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5705 pragma Assert (Present (Impl_Prag));
5707 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5708 end Implementation_Kind;
5710 --------------------------
5711 -- Implements_Interface --
5712 --------------------------
5714 function Implements_Interface
5715 (Typ_Ent : Entity_Id;
5716 Iface_Ent : Entity_Id;
5717 Exclude_Parents : Boolean := False) return Boolean
5719 Ifaces_List : Elist_Id;
5721 Iface : Entity_Id := Base_Type (Iface_Ent);
5722 Typ : Entity_Id := Base_Type (Typ_Ent);
5725 if Is_Class_Wide_Type (Typ) then
5726 Typ := Root_Type (Typ);
5729 if not Has_Interfaces (Typ) then
5733 if Is_Class_Wide_Type (Iface) then
5734 Iface := Root_Type (Iface);
5737 Collect_Interfaces (Typ, Ifaces_List);
5739 Elmt := First_Elmt (Ifaces_List);
5740 while Present (Elmt) loop
5741 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5742 and then Exclude_Parents
5746 elsif Node (Elmt) = Iface then
5754 end Implements_Interface;
5760 function In_Instance return Boolean is
5761 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5767 and then S /= Standard_Standard
5769 if (Ekind (S) = E_Function
5770 or else Ekind (S) = E_Package
5771 or else Ekind (S) = E_Procedure)
5772 and then Is_Generic_Instance (S)
5774 -- A child instance is always compiled in the context of a parent
5775 -- instance. Nevertheless, the actuals are not analyzed in an
5776 -- instance context. We detect this case by examining the current
5777 -- compilation unit, which must be a child instance, and checking
5778 -- that it is not currently on the scope stack.
5780 if Is_Child_Unit (Curr_Unit)
5782 Nkind (Unit (Cunit (Current_Sem_Unit)))
5783 = N_Package_Instantiation
5784 and then not In_Open_Scopes (Curr_Unit)
5798 ----------------------
5799 -- In_Instance_Body --
5800 ----------------------
5802 function In_Instance_Body return Boolean is
5808 and then S /= Standard_Standard
5810 if (Ekind (S) = E_Function
5811 or else Ekind (S) = E_Procedure)
5812 and then Is_Generic_Instance (S)
5816 elsif Ekind (S) = E_Package
5817 and then In_Package_Body (S)
5818 and then Is_Generic_Instance (S)
5827 end In_Instance_Body;
5829 -----------------------------
5830 -- In_Instance_Not_Visible --
5831 -----------------------------
5833 function In_Instance_Not_Visible return Boolean is
5839 and then S /= Standard_Standard
5841 if (Ekind (S) = E_Function
5842 or else Ekind (S) = E_Procedure)
5843 and then Is_Generic_Instance (S)
5847 elsif Ekind (S) = E_Package
5848 and then (In_Package_Body (S) or else In_Private_Part (S))
5849 and then Is_Generic_Instance (S)
5858 end In_Instance_Not_Visible;
5860 ------------------------------
5861 -- In_Instance_Visible_Part --
5862 ------------------------------
5864 function In_Instance_Visible_Part return Boolean is
5870 and then S /= Standard_Standard
5872 if Ekind (S) = E_Package
5873 and then Is_Generic_Instance (S)
5874 and then not In_Package_Body (S)
5875 and then not In_Private_Part (S)
5884 end In_Instance_Visible_Part;
5886 ---------------------
5887 -- In_Package_Body --
5888 ---------------------
5890 function In_Package_Body return Boolean is
5896 and then S /= Standard_Standard
5898 if Ekind (S) = E_Package
5899 and then In_Package_Body (S)
5908 end In_Package_Body;
5910 --------------------------------
5911 -- In_Parameter_Specification --
5912 --------------------------------
5914 function In_Parameter_Specification (N : Node_Id) return Boolean is
5919 while Present (PN) loop
5920 if Nkind (PN) = N_Parameter_Specification then
5928 end In_Parameter_Specification;
5930 --------------------------------------
5931 -- In_Subprogram_Or_Concurrent_Unit --
5932 --------------------------------------
5934 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5939 -- Use scope chain to check successively outer scopes
5945 if K in Subprogram_Kind
5946 or else K in Concurrent_Kind
5947 or else K in Generic_Subprogram_Kind
5951 elsif E = Standard_Standard then
5957 end In_Subprogram_Or_Concurrent_Unit;
5959 ---------------------
5960 -- In_Visible_Part --
5961 ---------------------
5963 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5966 Is_Package_Or_Generic_Package (Scope_Id)
5967 and then In_Open_Scopes (Scope_Id)
5968 and then not In_Package_Body (Scope_Id)
5969 and then not In_Private_Part (Scope_Id);
5970 end In_Visible_Part;
5972 --------------------------------
5973 -- Incomplete_Or_Private_View --
5974 --------------------------------
5976 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
5977 function Inspect_Decls
5979 Taft : Boolean := False) return Entity_Id;
5980 -- Check whether a declarative region contains the incomplete or private
5987 function Inspect_Decls
5989 Taft : Boolean := False) return Entity_Id
5995 Decl := First (Decls);
5996 while Present (Decl) loop
6000 if Nkind (Decl) = N_Incomplete_Type_Declaration then
6001 Match := Defining_Identifier (Decl);
6004 if Nkind_In (Decl, N_Private_Extension_Declaration,
6005 N_Private_Type_Declaration)
6007 Match := Defining_Identifier (Decl);
6012 and then Present (Full_View (Match))
6013 and then Full_View (Match) = Typ
6026 -- Start of processing for Incomplete_Or_Partial_View
6029 -- Incomplete type case
6031 Prev := Current_Entity_In_Scope (Typ);
6034 and then Is_Incomplete_Type (Prev)
6035 and then Present (Full_View (Prev))
6036 and then Full_View (Prev) = Typ
6041 -- Private or Taft amendment type case
6044 Pkg : constant Entity_Id := Scope (Typ);
6045 Pkg_Decl : Node_Id := Pkg;
6048 if Ekind (Pkg) = E_Package then
6049 while Nkind (Pkg_Decl) /= N_Package_Specification loop
6050 Pkg_Decl := Parent (Pkg_Decl);
6053 -- It is knows that Typ has a private view, look for it in the
6054 -- visible declarations of the enclosing scope. A special case
6055 -- of this is when the two views have been exchanged - the full
6056 -- appears earlier than the private.
6058 if Has_Private_Declaration (Typ) then
6059 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
6061 -- Exchanged view case, look in the private declarations
6064 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
6069 -- Otherwise if this is the package body, then Typ is a potential
6070 -- Taft amendment type. The incomplete view should be located in
6071 -- the private declarations of the enclosing scope.
6073 elsif In_Package_Body (Pkg) then
6074 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
6079 -- The type has no incomplete or private view
6082 end Incomplete_Or_Private_View;
6084 ---------------------------------
6085 -- Insert_Explicit_Dereference --
6086 ---------------------------------
6088 procedure Insert_Explicit_Dereference (N : Node_Id) is
6089 New_Prefix : constant Node_Id := Relocate_Node (N);
6090 Ent : Entity_Id := Empty;
6097 Save_Interps (N, New_Prefix);
6100 Make_Explicit_Dereference (Sloc (Parent (N)),
6101 Prefix => New_Prefix));
6103 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
6105 if Is_Overloaded (New_Prefix) then
6107 -- The dereference is also overloaded, and its interpretations are
6108 -- the designated types of the interpretations of the original node.
6110 Set_Etype (N, Any_Type);
6112 Get_First_Interp (New_Prefix, I, It);
6113 while Present (It.Nam) loop
6116 if Is_Access_Type (T) then
6117 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6120 Get_Next_Interp (I, It);
6126 -- Prefix is unambiguous: mark the original prefix (which might
6127 -- Come_From_Source) as a reference, since the new (relocated) one
6128 -- won't be taken into account.
6130 if Is_Entity_Name (New_Prefix) then
6131 Ent := Entity (New_Prefix);
6134 -- For a retrieval of a subcomponent of some composite object,
6135 -- retrieve the ultimate entity if there is one.
6137 elsif Nkind (New_Prefix) = N_Selected_Component
6138 or else Nkind (New_Prefix) = N_Indexed_Component
6140 Pref := Prefix (New_Prefix);
6141 while Present (Pref)
6143 (Nkind (Pref) = N_Selected_Component
6144 or else Nkind (Pref) = N_Indexed_Component)
6146 Pref := Prefix (Pref);
6149 if Present (Pref) and then Is_Entity_Name (Pref) then
6150 Ent := Entity (Pref);
6154 -- Place the reference on the entity node
6156 if Present (Ent) then
6157 Generate_Reference (Ent, Pref);
6160 end Insert_Explicit_Dereference;
6162 ------------------------------------------
6163 -- Inspect_Deferred_Constant_Completion --
6164 ------------------------------------------
6166 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6170 Decl := First (Decls);
6171 while Present (Decl) loop
6173 -- Deferred constant signature
6175 if Nkind (Decl) = N_Object_Declaration
6176 and then Constant_Present (Decl)
6177 and then No (Expression (Decl))
6179 -- No need to check internally generated constants
6181 and then Comes_From_Source (Decl)
6183 -- The constant is not completed. A full object declaration or a
6184 -- pragma Import complete a deferred constant.
6186 and then not Has_Completion (Defining_Identifier (Decl))
6189 ("constant declaration requires initialization expression",
6190 Defining_Identifier (Decl));
6193 Decl := Next (Decl);
6195 end Inspect_Deferred_Constant_Completion;
6197 -----------------------------
6198 -- Is_Actual_Out_Parameter --
6199 -----------------------------
6201 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6205 Find_Actual (N, Formal, Call);
6206 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6207 end Is_Actual_Out_Parameter;
6209 -------------------------
6210 -- Is_Actual_Parameter --
6211 -------------------------
6213 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6214 PK : constant Node_Kind := Nkind (Parent (N));
6218 when N_Parameter_Association =>
6219 return N = Explicit_Actual_Parameter (Parent (N));
6221 when N_Function_Call | N_Procedure_Call_Statement =>
6222 return Is_List_Member (N)
6224 List_Containing (N) = Parameter_Associations (Parent (N));
6229 end Is_Actual_Parameter;
6231 --------------------------------
6232 -- Is_Actual_Tagged_Parameter --
6233 --------------------------------
6235 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6239 Find_Actual (N, Formal, Call);
6240 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6241 end Is_Actual_Tagged_Parameter;
6243 ---------------------
6244 -- Is_Aliased_View --
6245 ---------------------
6247 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6251 if Is_Entity_Name (Obj) then
6259 or else (Present (Renamed_Object (E))
6260 and then Is_Aliased_View (Renamed_Object (E)))))
6262 or else ((Is_Formal (E)
6263 or else Ekind (E) = E_Generic_In_Out_Parameter
6264 or else Ekind (E) = E_Generic_In_Parameter)
6265 and then Is_Tagged_Type (Etype (E)))
6267 or else (Is_Concurrent_Type (E)
6268 and then In_Open_Scopes (E))
6270 -- Current instance of type, either directly or as rewritten
6271 -- reference to the current object.
6273 or else (Is_Entity_Name (Original_Node (Obj))
6274 and then Present (Entity (Original_Node (Obj)))
6275 and then Is_Type (Entity (Original_Node (Obj))))
6277 or else (Is_Type (E) and then E = Current_Scope)
6279 or else (Is_Incomplete_Or_Private_Type (E)
6280 and then Full_View (E) = Current_Scope);
6282 elsif Nkind (Obj) = N_Selected_Component then
6283 return Is_Aliased (Entity (Selector_Name (Obj)));
6285 elsif Nkind (Obj) = N_Indexed_Component then
6286 return Has_Aliased_Components (Etype (Prefix (Obj)))
6288 (Is_Access_Type (Etype (Prefix (Obj)))
6290 Has_Aliased_Components
6291 (Designated_Type (Etype (Prefix (Obj)))));
6293 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6294 or else Nkind (Obj) = N_Type_Conversion
6296 return Is_Tagged_Type (Etype (Obj))
6297 and then Is_Aliased_View (Expression (Obj));
6299 elsif Nkind (Obj) = N_Explicit_Dereference then
6300 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6305 end Is_Aliased_View;
6307 -------------------------
6308 -- Is_Ancestor_Package --
6309 -------------------------
6311 function Is_Ancestor_Package
6313 E2 : Entity_Id) return Boolean
6320 and then Par /= Standard_Standard
6330 end Is_Ancestor_Package;
6332 ----------------------
6333 -- Is_Atomic_Object --
6334 ----------------------
6336 function Is_Atomic_Object (N : Node_Id) return Boolean is
6338 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6339 -- Determines if given object has atomic components
6341 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6342 -- If prefix is an implicit dereference, examine designated type
6344 ----------------------
6345 -- Is_Atomic_Prefix --
6346 ----------------------
6348 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6350 if Is_Access_Type (Etype (N)) then
6352 Has_Atomic_Components (Designated_Type (Etype (N)));
6354 return Object_Has_Atomic_Components (N);
6356 end Is_Atomic_Prefix;
6358 ----------------------------------
6359 -- Object_Has_Atomic_Components --
6360 ----------------------------------
6362 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6364 if Has_Atomic_Components (Etype (N))
6365 or else Is_Atomic (Etype (N))
6369 elsif Is_Entity_Name (N)
6370 and then (Has_Atomic_Components (Entity (N))
6371 or else Is_Atomic (Entity (N)))
6375 elsif Nkind (N) = N_Indexed_Component
6376 or else Nkind (N) = N_Selected_Component
6378 return Is_Atomic_Prefix (Prefix (N));
6383 end Object_Has_Atomic_Components;
6385 -- Start of processing for Is_Atomic_Object
6388 -- Predicate is not relevant to subprograms
6390 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6393 elsif Is_Atomic (Etype (N))
6394 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6398 elsif Nkind (N) = N_Indexed_Component
6399 or else Nkind (N) = N_Selected_Component
6401 return Is_Atomic_Prefix (Prefix (N));
6406 end Is_Atomic_Object;
6408 -----------------------------
6409 -- Is_Concurrent_Interface --
6410 -----------------------------
6412 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6417 (Is_Protected_Interface (T)
6418 or else Is_Synchronized_Interface (T)
6419 or else Is_Task_Interface (T));
6420 end Is_Concurrent_Interface;
6422 --------------------------------------
6423 -- Is_Controlling_Limited_Procedure --
6424 --------------------------------------
6426 function Is_Controlling_Limited_Procedure
6427 (Proc_Nam : Entity_Id) return Boolean
6429 Param_Typ : Entity_Id := Empty;
6432 if Ekind (Proc_Nam) = E_Procedure
6433 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6435 Param_Typ := Etype (Parameter_Type (First (
6436 Parameter_Specifications (Parent (Proc_Nam)))));
6438 -- In this case where an Itype was created, the procedure call has been
6441 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6442 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6444 Present (Parameter_Associations
6445 (Associated_Node_For_Itype (Proc_Nam)))
6448 Etype (First (Parameter_Associations
6449 (Associated_Node_For_Itype (Proc_Nam))));
6452 if Present (Param_Typ) then
6454 Is_Interface (Param_Typ)
6455 and then Is_Limited_Record (Param_Typ);
6459 end Is_Controlling_Limited_Procedure;
6461 -----------------------------
6462 -- Is_CPP_Constructor_Call --
6463 -----------------------------
6465 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6467 return Nkind (N) = N_Function_Call
6468 and then Is_CPP_Class (Etype (Etype (N)))
6469 and then Is_Constructor (Entity (Name (N)))
6470 and then Is_Imported (Entity (Name (N)));
6471 end Is_CPP_Constructor_Call;
6477 function Is_Delegate (T : Entity_Id) return Boolean is
6478 Desig_Type : Entity_Id;
6481 if VM_Target /= CLI_Target then
6485 -- Access-to-subprograms are delegates in CIL
6487 if Ekind (T) = E_Access_Subprogram_Type then
6491 if Ekind (T) not in Access_Kind then
6493 -- A delegate is a managed pointer. If no designated type is defined
6494 -- it means that it's not a delegate.
6499 Desig_Type := Etype (Directly_Designated_Type (T));
6501 if not Is_Tagged_Type (Desig_Type) then
6505 -- Test if the type is inherited from [mscorlib]System.Delegate
6507 while Etype (Desig_Type) /= Desig_Type loop
6508 if Chars (Scope (Desig_Type)) /= No_Name
6509 and then Is_Imported (Scope (Desig_Type))
6510 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6515 Desig_Type := Etype (Desig_Type);
6521 ----------------------------------------------
6522 -- Is_Dependent_Component_Of_Mutable_Object --
6523 ----------------------------------------------
6525 function Is_Dependent_Component_Of_Mutable_Object
6526 (Object : Node_Id) return Boolean
6529 Prefix_Type : Entity_Id;
6530 P_Aliased : Boolean := False;
6533 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6534 -- Returns True if and only if Comp is declared within a variant part
6536 --------------------------------
6537 -- Is_Declared_Within_Variant --
6538 --------------------------------
6540 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6541 Comp_Decl : constant Node_Id := Parent (Comp);
6542 Comp_List : constant Node_Id := Parent (Comp_Decl);
6544 return Nkind (Parent (Comp_List)) = N_Variant;
6545 end Is_Declared_Within_Variant;
6547 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6550 if Is_Variable (Object) then
6552 if Nkind (Object) = N_Selected_Component then
6553 P := Prefix (Object);
6554 Prefix_Type := Etype (P);
6556 if Is_Entity_Name (P) then
6558 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6559 Prefix_Type := Base_Type (Prefix_Type);
6562 if Is_Aliased (Entity (P)) then
6566 -- A discriminant check on a selected component may be expanded
6567 -- into a dereference when removing side-effects. Recover the
6568 -- original node and its type, which may be unconstrained.
6570 elsif Nkind (P) = N_Explicit_Dereference
6571 and then not (Comes_From_Source (P))
6573 P := Original_Node (P);
6574 Prefix_Type := Etype (P);
6577 -- Check for prefix being an aliased component???
6583 -- A heap object is constrained by its initial value
6585 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6586 -- the dereferenced case, since the access value might denote an
6587 -- unconstrained aliased object, whereas in Ada 95 the designated
6588 -- object is guaranteed to be constrained. A worst-case assumption
6589 -- has to apply in Ada 2005 because we can't tell at compile time
6590 -- whether the object is "constrained by its initial value"
6591 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6592 -- semantic rules -- these rules are acknowledged to need fixing).
6594 if Ada_Version < Ada_2005 then
6595 if Is_Access_Type (Prefix_Type)
6596 or else Nkind (P) = N_Explicit_Dereference
6601 elsif Ada_Version >= Ada_2005 then
6602 if Is_Access_Type (Prefix_Type) then
6604 -- If the access type is pool-specific, and there is no
6605 -- constrained partial view of the designated type, then the
6606 -- designated object is known to be constrained.
6608 if Ekind (Prefix_Type) = E_Access_Type
6609 and then not Has_Constrained_Partial_View
6610 (Designated_Type (Prefix_Type))
6614 -- Otherwise (general access type, or there is a constrained
6615 -- partial view of the designated type), we need to check
6616 -- based on the designated type.
6619 Prefix_Type := Designated_Type (Prefix_Type);
6625 Original_Record_Component (Entity (Selector_Name (Object)));
6627 -- As per AI-0017, the renaming is illegal in a generic body, even
6628 -- if the subtype is indefinite.
6630 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6632 if not Is_Constrained (Prefix_Type)
6633 and then (not Is_Indefinite_Subtype (Prefix_Type)
6635 (Is_Generic_Type (Prefix_Type)
6636 and then Ekind (Current_Scope) = E_Generic_Package
6637 and then In_Package_Body (Current_Scope)))
6639 and then (Is_Declared_Within_Variant (Comp)
6640 or else Has_Discriminant_Dependent_Constraint (Comp))
6641 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6647 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6651 elsif Nkind (Object) = N_Indexed_Component
6652 or else Nkind (Object) = N_Slice
6654 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6656 -- A type conversion that Is_Variable is a view conversion:
6657 -- go back to the denoted object.
6659 elsif Nkind (Object) = N_Type_Conversion then
6661 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6666 end Is_Dependent_Component_Of_Mutable_Object;
6668 ---------------------
6669 -- Is_Dereferenced --
6670 ---------------------
6672 function Is_Dereferenced (N : Node_Id) return Boolean is
6673 P : constant Node_Id := Parent (N);
6676 (Nkind (P) = N_Selected_Component
6678 Nkind (P) = N_Explicit_Dereference
6680 Nkind (P) = N_Indexed_Component
6682 Nkind (P) = N_Slice)
6683 and then Prefix (P) = N;
6684 end Is_Dereferenced;
6686 ----------------------
6687 -- Is_Descendent_Of --
6688 ----------------------
6690 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6695 pragma Assert (Nkind (T1) in N_Entity);
6696 pragma Assert (Nkind (T2) in N_Entity);
6698 T := Base_Type (T1);
6700 -- Immediate return if the types match
6705 -- Comment needed here ???
6707 elsif Ekind (T) = E_Class_Wide_Type then
6708 return Etype (T) = T2;
6716 -- Done if we found the type we are looking for
6721 -- Done if no more derivations to check
6728 -- Following test catches error cases resulting from prev errors
6730 elsif No (Etyp) then
6733 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6736 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6740 T := Base_Type (Etyp);
6743 end Is_Descendent_Of;
6745 ----------------------------
6746 -- Is_Expression_Function --
6747 ----------------------------
6749 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6750 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6753 return Ekind (Subp) = E_Function
6754 and then Nkind (Decl) = N_Subprogram_Declaration
6756 (Nkind (Original_Node (Decl)) = N_Expression_Function
6758 (Present (Corresponding_Body (Decl))
6760 Nkind (Original_Node
6761 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6762 = N_Expression_Function));
6763 end Is_Expression_Function;
6769 function Is_False (U : Uint) return Boolean is
6774 ---------------------------
6775 -- Is_Fixed_Model_Number --
6776 ---------------------------
6778 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6779 S : constant Ureal := Small_Value (T);
6780 M : Urealp.Save_Mark;
6784 R := (U = UR_Trunc (U / S) * S);
6787 end Is_Fixed_Model_Number;
6789 -------------------------------
6790 -- Is_Fully_Initialized_Type --
6791 -------------------------------
6793 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6795 if Is_Scalar_Type (Typ) then
6798 elsif Is_Access_Type (Typ) then
6801 elsif Is_Array_Type (Typ) then
6802 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6806 -- An interesting case, if we have a constrained type one of whose
6807 -- bounds is known to be null, then there are no elements to be
6808 -- initialized, so all the elements are initialized!
6810 if Is_Constrained (Typ) then
6813 Indx_Typ : Entity_Id;
6817 Indx := First_Index (Typ);
6818 while Present (Indx) loop
6819 if Etype (Indx) = Any_Type then
6822 -- If index is a range, use directly
6824 elsif Nkind (Indx) = N_Range then
6825 Lbd := Low_Bound (Indx);
6826 Hbd := High_Bound (Indx);
6829 Indx_Typ := Etype (Indx);
6831 if Is_Private_Type (Indx_Typ) then
6832 Indx_Typ := Full_View (Indx_Typ);
6835 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6838 Lbd := Type_Low_Bound (Indx_Typ);
6839 Hbd := Type_High_Bound (Indx_Typ);
6843 if Compile_Time_Known_Value (Lbd)
6844 and then Compile_Time_Known_Value (Hbd)
6846 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6856 -- If no null indexes, then type is not fully initialized
6862 elsif Is_Record_Type (Typ) then
6863 if Has_Discriminants (Typ)
6865 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6866 and then Is_Fully_Initialized_Variant (Typ)
6871 -- Controlled records are considered to be fully initialized if
6872 -- there is a user defined Initialize routine. This may not be
6873 -- entirely correct, but as the spec notes, we are guessing here
6874 -- what is best from the point of view of issuing warnings.
6876 if Is_Controlled (Typ) then
6878 Utyp : constant Entity_Id := Underlying_Type (Typ);
6881 if Present (Utyp) then
6883 Init : constant Entity_Id :=
6885 (Underlying_Type (Typ), Name_Initialize));
6889 and then Comes_From_Source (Init)
6891 Is_Predefined_File_Name
6892 (File_Name (Get_Source_File_Index (Sloc (Init))))
6896 elsif Has_Null_Extension (Typ)
6898 Is_Fully_Initialized_Type
6899 (Etype (Base_Type (Typ)))
6908 -- Otherwise see if all record components are initialized
6914 Ent := First_Entity (Typ);
6915 while Present (Ent) loop
6916 if Ekind (Ent) = E_Component
6917 and then (No (Parent (Ent))
6918 or else No (Expression (Parent (Ent))))
6919 and then not Is_Fully_Initialized_Type (Etype (Ent))
6921 -- Special VM case for tag components, which need to be
6922 -- defined in this case, but are never initialized as VMs
6923 -- are using other dispatching mechanisms. Ignore this
6924 -- uninitialized case. Note that this applies both to the
6925 -- uTag entry and the main vtable pointer (CPP_Class case).
6927 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6936 -- No uninitialized components, so type is fully initialized.
6937 -- Note that this catches the case of no components as well.
6941 elsif Is_Concurrent_Type (Typ) then
6944 elsif Is_Private_Type (Typ) then
6946 U : constant Entity_Id := Underlying_Type (Typ);
6952 return Is_Fully_Initialized_Type (U);
6959 end Is_Fully_Initialized_Type;
6961 ----------------------------------
6962 -- Is_Fully_Initialized_Variant --
6963 ----------------------------------
6965 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6966 Loc : constant Source_Ptr := Sloc (Typ);
6967 Constraints : constant List_Id := New_List;
6968 Components : constant Elist_Id := New_Elmt_List;
6969 Comp_Elmt : Elmt_Id;
6971 Comp_List : Node_Id;
6973 Discr_Val : Node_Id;
6975 Report_Errors : Boolean;
6976 pragma Warnings (Off, Report_Errors);
6979 if Serious_Errors_Detected > 0 then
6983 if Is_Record_Type (Typ)
6984 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6985 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6987 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6989 Discr := First_Discriminant (Typ);
6990 while Present (Discr) loop
6991 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6992 Discr_Val := Expression (Parent (Discr));
6994 if Present (Discr_Val)
6995 and then Is_OK_Static_Expression (Discr_Val)
6997 Append_To (Constraints,
6998 Make_Component_Association (Loc,
6999 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
7000 Expression => New_Copy (Discr_Val)));
7008 Next_Discriminant (Discr);
7013 Comp_List => Comp_List,
7014 Governed_By => Constraints,
7016 Report_Errors => Report_Errors);
7018 -- Check that each component present is fully initialized
7020 Comp_Elmt := First_Elmt (Components);
7021 while Present (Comp_Elmt) loop
7022 Comp_Id := Node (Comp_Elmt);
7024 if Ekind (Comp_Id) = E_Component
7025 and then (No (Parent (Comp_Id))
7026 or else No (Expression (Parent (Comp_Id))))
7027 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
7032 Next_Elmt (Comp_Elmt);
7037 elsif Is_Private_Type (Typ) then
7039 U : constant Entity_Id := Underlying_Type (Typ);
7045 return Is_Fully_Initialized_Variant (U);
7051 end Is_Fully_Initialized_Variant;
7057 -- We seem to have a lot of overlapping functions that do similar things
7058 -- (testing for left hand sides or lvalues???). Anyway, since this one is
7059 -- purely syntactic, it should be in Sem_Aux I would think???
7061 function Is_LHS (N : Node_Id) return Boolean is
7062 P : constant Node_Id := Parent (N);
7065 if Nkind (P) = N_Assignment_Statement then
7066 return Name (P) = N;
7069 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
7071 return N = Prefix (P) and then Is_LHS (P);
7078 ----------------------------
7079 -- Is_Inherited_Operation --
7080 ----------------------------
7082 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
7083 Kind : constant Node_Kind := Nkind (Parent (E));
7085 pragma Assert (Is_Overloadable (E));
7086 return Kind = N_Full_Type_Declaration
7087 or else Kind = N_Private_Extension_Declaration
7088 or else Kind = N_Subtype_Declaration
7089 or else (Ekind (E) = E_Enumeration_Literal
7090 and then Is_Derived_Type (Etype (E)));
7091 end Is_Inherited_Operation;
7093 -------------------------------------
7094 -- Is_Inherited_Operation_For_Type --
7095 -------------------------------------
7097 function Is_Inherited_Operation_For_Type
7098 (E : Entity_Id; Typ : Entity_Id) return Boolean
7101 return Is_Inherited_Operation (E)
7102 and then Etype (Parent (E)) = Typ;
7103 end Is_Inherited_Operation_For_Type;
7105 -----------------------------
7106 -- Is_Library_Level_Entity --
7107 -----------------------------
7109 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7111 -- The following is a small optimization, and it also properly handles
7112 -- discriminals, which in task bodies might appear in expressions before
7113 -- the corresponding procedure has been created, and which therefore do
7114 -- not have an assigned scope.
7116 if Is_Formal (E) then
7120 -- Normal test is simply that the enclosing dynamic scope is Standard
7122 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7123 end Is_Library_Level_Entity;
7125 ---------------------------------
7126 -- Is_Local_Variable_Reference --
7127 ---------------------------------
7129 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7131 if not Is_Entity_Name (Expr) then
7136 Ent : constant Entity_Id := Entity (Expr);
7137 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7139 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7142 return Present (Sub) and then Sub = Current_Subprogram;
7146 end Is_Local_Variable_Reference;
7148 -------------------------
7149 -- Is_Object_Reference --
7150 -------------------------
7152 function Is_Object_Reference (N : Node_Id) return Boolean is
7154 if Is_Entity_Name (N) then
7155 return Present (Entity (N)) and then Is_Object (Entity (N));
7159 when N_Indexed_Component | N_Slice =>
7161 Is_Object_Reference (Prefix (N))
7162 or else Is_Access_Type (Etype (Prefix (N)));
7164 -- In Ada95, a function call is a constant object; a procedure
7167 when N_Function_Call =>
7168 return Etype (N) /= Standard_Void_Type;
7170 -- A reference to the stream attribute Input is a function call
7172 when N_Attribute_Reference =>
7173 return Attribute_Name (N) = Name_Input;
7175 when N_Selected_Component =>
7177 Is_Object_Reference (Selector_Name (N))
7179 (Is_Object_Reference (Prefix (N))
7180 or else Is_Access_Type (Etype (Prefix (N))));
7182 when N_Explicit_Dereference =>
7185 -- A view conversion of a tagged object is an object reference
7187 when N_Type_Conversion =>
7188 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7189 and then Is_Tagged_Type (Etype (Expression (N)))
7190 and then Is_Object_Reference (Expression (N));
7192 -- An unchecked type conversion is considered to be an object if
7193 -- the operand is an object (this construction arises only as a
7194 -- result of expansion activities).
7196 when N_Unchecked_Type_Conversion =>
7203 end Is_Object_Reference;
7205 -----------------------------------
7206 -- Is_OK_Variable_For_Out_Formal --
7207 -----------------------------------
7209 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7211 Note_Possible_Modification (AV, Sure => True);
7213 -- We must reject parenthesized variable names. The check for
7214 -- Comes_From_Source is present because there are currently
7215 -- cases where the compiler violates this rule (e.g. passing
7216 -- a task object to its controlled Initialize routine).
7218 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7221 -- A variable is always allowed
7223 elsif Is_Variable (AV) then
7226 -- Unchecked conversions are allowed only if they come from the
7227 -- generated code, which sometimes uses unchecked conversions for out
7228 -- parameters in cases where code generation is unaffected. We tell
7229 -- source unchecked conversions by seeing if they are rewrites of an
7230 -- original Unchecked_Conversion function call, or of an explicit
7231 -- conversion of a function call.
7233 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7234 if Nkind (Original_Node (AV)) = N_Function_Call then
7237 elsif Comes_From_Source (AV)
7238 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7242 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7243 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7249 -- Normal type conversions are allowed if argument is a variable
7251 elsif Nkind (AV) = N_Type_Conversion then
7252 if Is_Variable (Expression (AV))
7253 and then Paren_Count (Expression (AV)) = 0
7255 Note_Possible_Modification (Expression (AV), Sure => True);
7258 -- We also allow a non-parenthesized expression that raises
7259 -- constraint error if it rewrites what used to be a variable
7261 elsif Raises_Constraint_Error (Expression (AV))
7262 and then Paren_Count (Expression (AV)) = 0
7263 and then Is_Variable (Original_Node (Expression (AV)))
7267 -- Type conversion of something other than a variable
7273 -- If this node is rewritten, then test the original form, if that is
7274 -- OK, then we consider the rewritten node OK (for example, if the
7275 -- original node is a conversion, then Is_Variable will not be true
7276 -- but we still want to allow the conversion if it converts a variable).
7278 elsif Original_Node (AV) /= AV then
7279 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7281 -- All other non-variables are rejected
7286 end Is_OK_Variable_For_Out_Formal;
7288 -----------------------------------
7289 -- Is_Partially_Initialized_Type --
7290 -----------------------------------
7292 function Is_Partially_Initialized_Type
7294 Include_Implicit : Boolean := True) return Boolean
7297 if Is_Scalar_Type (Typ) then
7300 elsif Is_Access_Type (Typ) then
7301 return Include_Implicit;
7303 elsif Is_Array_Type (Typ) then
7305 -- If component type is partially initialized, so is array type
7307 if Is_Partially_Initialized_Type
7308 (Component_Type (Typ), Include_Implicit)
7312 -- Otherwise we are only partially initialized if we are fully
7313 -- initialized (this is the empty array case, no point in us
7314 -- duplicating that code here).
7317 return Is_Fully_Initialized_Type (Typ);
7320 elsif Is_Record_Type (Typ) then
7322 -- A discriminated type is always partially initialized if in
7325 if Has_Discriminants (Typ) and then Include_Implicit then
7328 -- A tagged type is always partially initialized
7330 elsif Is_Tagged_Type (Typ) then
7333 -- Case of non-discriminated record
7339 Component_Present : Boolean := False;
7340 -- Set True if at least one component is present. If no
7341 -- components are present, then record type is fully
7342 -- initialized (another odd case, like the null array).
7345 -- Loop through components
7347 Ent := First_Entity (Typ);
7348 while Present (Ent) loop
7349 if Ekind (Ent) = E_Component then
7350 Component_Present := True;
7352 -- If a component has an initialization expression then
7353 -- the enclosing record type is partially initialized
7355 if Present (Parent (Ent))
7356 and then Present (Expression (Parent (Ent)))
7360 -- If a component is of a type which is itself partially
7361 -- initialized, then the enclosing record type is also.
7363 elsif Is_Partially_Initialized_Type
7364 (Etype (Ent), Include_Implicit)
7373 -- No initialized components found. If we found any components
7374 -- they were all uninitialized so the result is false.
7376 if Component_Present then
7379 -- But if we found no components, then all the components are
7380 -- initialized so we consider the type to be initialized.
7388 -- Concurrent types are always fully initialized
7390 elsif Is_Concurrent_Type (Typ) then
7393 -- For a private type, go to underlying type. If there is no underlying
7394 -- type then just assume this partially initialized. Not clear if this
7395 -- can happen in a non-error case, but no harm in testing for this.
7397 elsif Is_Private_Type (Typ) then
7399 U : constant Entity_Id := Underlying_Type (Typ);
7404 return Is_Partially_Initialized_Type (U, Include_Implicit);
7408 -- For any other type (are there any?) assume partially initialized
7413 end Is_Partially_Initialized_Type;
7415 ------------------------------------
7416 -- Is_Potentially_Persistent_Type --
7417 ------------------------------------
7419 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7424 -- For private type, test corresponding full type
7426 if Is_Private_Type (T) then
7427 return Is_Potentially_Persistent_Type (Full_View (T));
7429 -- Scalar types are potentially persistent
7431 elsif Is_Scalar_Type (T) then
7434 -- Record type is potentially persistent if not tagged and the types of
7435 -- all it components are potentially persistent, and no component has
7436 -- an initialization expression.
7438 elsif Is_Record_Type (T)
7439 and then not Is_Tagged_Type (T)
7440 and then not Is_Partially_Initialized_Type (T)
7442 Comp := First_Component (T);
7443 while Present (Comp) loop
7444 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7453 -- Array type is potentially persistent if its component type is
7454 -- potentially persistent and if all its constraints are static.
7456 elsif Is_Array_Type (T) then
7457 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7461 Indx := First_Index (T);
7462 while Present (Indx) loop
7463 if not Is_OK_Static_Subtype (Etype (Indx)) then
7472 -- All other types are not potentially persistent
7477 end Is_Potentially_Persistent_Type;
7479 ---------------------------------
7480 -- Is_Protected_Self_Reference --
7481 ---------------------------------
7483 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7485 function In_Access_Definition (N : Node_Id) return Boolean;
7486 -- Returns true if N belongs to an access definition
7488 --------------------------
7489 -- In_Access_Definition --
7490 --------------------------
7492 function In_Access_Definition (N : Node_Id) return Boolean is
7497 while Present (P) loop
7498 if Nkind (P) = N_Access_Definition then
7506 end In_Access_Definition;
7508 -- Start of processing for Is_Protected_Self_Reference
7511 -- Verify that prefix is analyzed and has the proper form. Note that
7512 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7513 -- produce the address of an entity, do not analyze their prefix
7514 -- because they denote entities that are not necessarily visible.
7515 -- Neither of them can apply to a protected type.
7517 return Ada_Version >= Ada_2005
7518 and then Is_Entity_Name (N)
7519 and then Present (Entity (N))
7520 and then Is_Protected_Type (Entity (N))
7521 and then In_Open_Scopes (Entity (N))
7522 and then not In_Access_Definition (N);
7523 end Is_Protected_Self_Reference;
7525 -----------------------------
7526 -- Is_RCI_Pkg_Spec_Or_Body --
7527 -----------------------------
7529 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7531 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7532 -- Return True if the unit of Cunit is an RCI package declaration
7534 ---------------------------
7535 -- Is_RCI_Pkg_Decl_Cunit --
7536 ---------------------------
7538 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7539 The_Unit : constant Node_Id := Unit (Cunit);
7542 if Nkind (The_Unit) /= N_Package_Declaration then
7546 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7547 end Is_RCI_Pkg_Decl_Cunit;
7549 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7552 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7554 (Nkind (Unit (Cunit)) = N_Package_Body
7555 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7556 end Is_RCI_Pkg_Spec_Or_Body;
7558 -----------------------------------------
7559 -- Is_Remote_Access_To_Class_Wide_Type --
7560 -----------------------------------------
7562 function Is_Remote_Access_To_Class_Wide_Type
7563 (E : Entity_Id) return Boolean
7566 -- A remote access to class-wide type is a general access to object type
7567 -- declared in the visible part of a Remote_Types or Remote_Call_
7570 return Ekind (E) = E_General_Access_Type
7571 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7572 end Is_Remote_Access_To_Class_Wide_Type;
7574 -----------------------------------------
7575 -- Is_Remote_Access_To_Subprogram_Type --
7576 -----------------------------------------
7578 function Is_Remote_Access_To_Subprogram_Type
7579 (E : Entity_Id) return Boolean
7582 return (Ekind (E) = E_Access_Subprogram_Type
7583 or else (Ekind (E) = E_Record_Type
7584 and then Present (Corresponding_Remote_Type (E))))
7585 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7586 end Is_Remote_Access_To_Subprogram_Type;
7588 --------------------
7589 -- Is_Remote_Call --
7590 --------------------
7592 function Is_Remote_Call (N : Node_Id) return Boolean is
7594 if Nkind (N) /= N_Procedure_Call_Statement
7595 and then Nkind (N) /= N_Function_Call
7597 -- An entry call cannot be remote
7601 elsif Nkind (Name (N)) in N_Has_Entity
7602 and then Is_Remote_Call_Interface (Entity (Name (N)))
7604 -- A subprogram declared in the spec of a RCI package is remote
7608 elsif Nkind (Name (N)) = N_Explicit_Dereference
7609 and then Is_Remote_Access_To_Subprogram_Type
7610 (Etype (Prefix (Name (N))))
7612 -- The dereference of a RAS is a remote call
7616 elsif Present (Controlling_Argument (N))
7617 and then Is_Remote_Access_To_Class_Wide_Type
7618 (Etype (Controlling_Argument (N)))
7620 -- Any primitive operation call with a controlling argument of
7621 -- a RACW type is a remote call.
7626 -- All other calls are local calls
7631 ----------------------
7632 -- Is_Renamed_Entry --
7633 ----------------------
7635 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7636 Orig_Node : Node_Id := Empty;
7637 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7639 function Is_Entry (Nam : Node_Id) return Boolean;
7640 -- Determine whether Nam is an entry. Traverse selectors if there are
7641 -- nested selected components.
7647 function Is_Entry (Nam : Node_Id) return Boolean is
7649 if Nkind (Nam) = N_Selected_Component then
7650 return Is_Entry (Selector_Name (Nam));
7653 return Ekind (Entity (Nam)) = E_Entry;
7656 -- Start of processing for Is_Renamed_Entry
7659 if Present (Alias (Proc_Nam)) then
7660 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7663 -- Look for a rewritten subprogram renaming declaration
7665 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7666 and then Present (Original_Node (Subp_Decl))
7668 Orig_Node := Original_Node (Subp_Decl);
7671 -- The rewritten subprogram is actually an entry
7673 if Present (Orig_Node)
7674 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7675 and then Is_Entry (Name (Orig_Node))
7681 end Is_Renamed_Entry;
7683 ----------------------
7684 -- Is_Selector_Name --
7685 ----------------------
7687 function Is_Selector_Name (N : Node_Id) return Boolean is
7689 if not Is_List_Member (N) then
7691 P : constant Node_Id := Parent (N);
7692 K : constant Node_Kind := Nkind (P);
7695 (K = N_Expanded_Name or else
7696 K = N_Generic_Association or else
7697 K = N_Parameter_Association or else
7698 K = N_Selected_Component)
7699 and then Selector_Name (P) = N;
7704 L : constant List_Id := List_Containing (N);
7705 P : constant Node_Id := Parent (L);
7707 return (Nkind (P) = N_Discriminant_Association
7708 and then Selector_Names (P) = L)
7710 (Nkind (P) = N_Component_Association
7711 and then Choices (P) = L);
7714 end Is_Selector_Name;
7716 ----------------------------------
7717 -- Is_SPARK_Initialization_Expr --
7718 ----------------------------------
7720 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7723 Comp_Assn : Node_Id;
7724 Orig_N : constant Node_Id := Original_Node (N);
7729 if not Comes_From_Source (Orig_N) then
7733 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7735 case Nkind (Orig_N) is
7736 when N_Character_Literal |
7744 if Is_Entity_Name (Orig_N)
7745 and then Present (Entity (Orig_N)) -- needed in some cases
7747 case Ekind (Entity (Orig_N)) is
7749 E_Enumeration_Literal |
7754 if Is_Type (Entity (Orig_N)) then
7762 when N_Qualified_Expression |
7763 N_Type_Conversion =>
7764 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7767 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7771 N_Membership_Test =>
7772 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7773 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7776 N_Extension_Aggregate =>
7777 if Nkind (Orig_N) = N_Extension_Aggregate then
7778 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7781 Expr := First (Expressions (Orig_N));
7782 while Present (Expr) loop
7783 if not Is_SPARK_Initialization_Expr (Expr) then
7791 Comp_Assn := First (Component_Associations (Orig_N));
7792 while Present (Comp_Assn) loop
7793 Expr := Expression (Comp_Assn);
7794 if Present (Expr) -- needed for box association
7795 and then not Is_SPARK_Initialization_Expr (Expr)
7804 when N_Attribute_Reference =>
7805 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7806 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7809 Expr := First (Expressions (Orig_N));
7810 while Present (Expr) loop
7811 if not Is_SPARK_Initialization_Expr (Expr) then
7819 -- Selected components might be expanded named not yet resolved, so
7820 -- default on the safe side. (Eg on sparklex.ads)
7822 when N_Selected_Component =>
7831 end Is_SPARK_Initialization_Expr;
7833 -------------------------------
7834 -- Is_SPARK_Object_Reference --
7835 -------------------------------
7837 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7839 if Is_Entity_Name (N) then
7840 return Present (Entity (N))
7842 (Ekind_In (Entity (N), E_Constant, E_Variable)
7843 or else Ekind (Entity (N)) in Formal_Kind);
7847 when N_Selected_Component =>
7848 return Is_SPARK_Object_Reference (Prefix (N));
7854 end Is_SPARK_Object_Reference;
7860 function Is_Statement (N : Node_Id) return Boolean is
7863 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7864 or else Nkind (N) = N_Procedure_Call_Statement;
7867 ---------------------------------
7868 -- Is_Synchronized_Tagged_Type --
7869 ---------------------------------
7871 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7872 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7875 -- A task or protected type derived from an interface is a tagged type.
7876 -- Such a tagged type is called a synchronized tagged type, as are
7877 -- synchronized interfaces and private extensions whose declaration
7878 -- includes the reserved word synchronized.
7880 return (Is_Tagged_Type (E)
7881 and then (Kind = E_Task_Type
7882 or else Kind = E_Protected_Type))
7885 and then Is_Synchronized_Interface (E))
7887 (Ekind (E) = E_Record_Type_With_Private
7888 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7889 and then (Synchronized_Present (Parent (E))
7890 or else Is_Synchronized_Interface (Etype (E))));
7891 end Is_Synchronized_Tagged_Type;
7897 function Is_Transfer (N : Node_Id) return Boolean is
7898 Kind : constant Node_Kind := Nkind (N);
7901 if Kind = N_Simple_Return_Statement
7903 Kind = N_Extended_Return_Statement
7905 Kind = N_Goto_Statement
7907 Kind = N_Raise_Statement
7909 Kind = N_Requeue_Statement
7913 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7914 and then No (Condition (N))
7918 elsif Kind = N_Procedure_Call_Statement
7919 and then Is_Entity_Name (Name (N))
7920 and then Present (Entity (Name (N)))
7921 and then No_Return (Entity (Name (N)))
7925 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7937 function Is_True (U : Uint) return Boolean is
7942 -------------------------------
7943 -- Is_Universal_Numeric_Type --
7944 -------------------------------
7946 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7948 return T = Universal_Integer or else T = Universal_Real;
7949 end Is_Universal_Numeric_Type;
7955 function Is_Value_Type (T : Entity_Id) return Boolean is
7957 return VM_Target = CLI_Target
7958 and then Nkind (T) in N_Has_Chars
7959 and then Chars (T) /= No_Name
7960 and then Get_Name_String (Chars (T)) = "valuetype";
7963 ---------------------
7964 -- Is_VMS_Operator --
7965 ---------------------
7967 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7969 -- The VMS operators are declared in a child of System that is loaded
7970 -- through pragma Extend_System. In some rare cases a program is run
7971 -- with this extension but without indicating that the target is VMS.
7973 return Ekind (Op) = E_Function
7974 and then Is_Intrinsic_Subprogram (Op)
7976 ((Present_System_Aux
7977 and then Scope (Op) = System_Aux_Id)
7980 and then Scope (Scope (Op)) = RTU_Entity (System)));
7981 end Is_VMS_Operator;
7987 function Is_Variable
7989 Use_Original_Node : Boolean := True) return Boolean
7991 Orig_Node : Node_Id;
7993 function In_Protected_Function (E : Entity_Id) return Boolean;
7994 -- Within a protected function, the private components of the enclosing
7995 -- protected type are constants. A function nested within a (protected)
7996 -- procedure is not itself protected.
7998 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7999 -- Prefixes can involve implicit dereferences, in which case we must
8000 -- test for the case of a reference of a constant access type, which can
8001 -- can never be a variable.
8003 ---------------------------
8004 -- In_Protected_Function --
8005 ---------------------------
8007 function In_Protected_Function (E : Entity_Id) return Boolean is
8008 Prot : constant Entity_Id := Scope (E);
8012 if not Is_Protected_Type (Prot) then
8016 while Present (S) and then S /= Prot loop
8017 if Ekind (S) = E_Function and then Scope (S) = Prot then
8026 end In_Protected_Function;
8028 ------------------------
8029 -- Is_Variable_Prefix --
8030 ------------------------
8032 function Is_Variable_Prefix (P : Node_Id) return Boolean is
8034 if Is_Access_Type (Etype (P)) then
8035 return not Is_Access_Constant (Root_Type (Etype (P)));
8037 -- For the case of an indexed component whose prefix has a packed
8038 -- array type, the prefix has been rewritten into a type conversion.
8039 -- Determine variable-ness from the converted expression.
8041 elsif Nkind (P) = N_Type_Conversion
8042 and then not Comes_From_Source (P)
8043 and then Is_Array_Type (Etype (P))
8044 and then Is_Packed (Etype (P))
8046 return Is_Variable (Expression (P));
8049 return Is_Variable (P);
8051 end Is_Variable_Prefix;
8053 -- Start of processing for Is_Variable
8056 -- Check if we perform the test on the original node since this may be a
8057 -- test of syntactic categories which must not be disturbed by whatever
8058 -- rewriting might have occurred. For example, an aggregate, which is
8059 -- certainly NOT a variable, could be turned into a variable by
8062 if Use_Original_Node then
8063 Orig_Node := Original_Node (N);
8068 -- Definitely OK if Assignment_OK is set. Since this is something that
8069 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
8071 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
8074 -- Normally we go to the original node, but there is one exception where
8075 -- we use the rewritten node, namely when it is an explicit dereference.
8076 -- The generated code may rewrite a prefix which is an access type with
8077 -- an explicit dereference. The dereference is a variable, even though
8078 -- the original node may not be (since it could be a constant of the
8081 -- In Ada 2005 we have a further case to consider: the prefix may be a
8082 -- function call given in prefix notation. The original node appears to
8083 -- be a selected component, but we need to examine the call.
8085 elsif Nkind (N) = N_Explicit_Dereference
8086 and then Nkind (Orig_Node) /= N_Explicit_Dereference
8087 and then Present (Etype (Orig_Node))
8088 and then Is_Access_Type (Etype (Orig_Node))
8090 -- Note that if the prefix is an explicit dereference that does not
8091 -- come from source, we must check for a rewritten function call in
8092 -- prefixed notation before other forms of rewriting, to prevent a
8096 (Nkind (Orig_Node) = N_Function_Call
8097 and then not Is_Access_Constant (Etype (Prefix (N))))
8099 Is_Variable_Prefix (Original_Node (Prefix (N)));
8101 -- A function call is never a variable
8103 elsif Nkind (N) = N_Function_Call then
8106 -- All remaining checks use the original node
8108 elsif Is_Entity_Name (Orig_Node)
8109 and then Present (Entity (Orig_Node))
8112 E : constant Entity_Id := Entity (Orig_Node);
8113 K : constant Entity_Kind := Ekind (E);
8116 return (K = E_Variable
8117 and then Nkind (Parent (E)) /= N_Exception_Handler)
8118 or else (K = E_Component
8119 and then not In_Protected_Function (E))
8120 or else K = E_Out_Parameter
8121 or else K = E_In_Out_Parameter
8122 or else K = E_Generic_In_Out_Parameter
8124 -- Current instance of type:
8126 or else (Is_Type (E) and then In_Open_Scopes (E))
8127 or else (Is_Incomplete_Or_Private_Type (E)
8128 and then In_Open_Scopes (Full_View (E)));
8132 case Nkind (Orig_Node) is
8133 when N_Indexed_Component | N_Slice =>
8134 return Is_Variable_Prefix (Prefix (Orig_Node));
8136 when N_Selected_Component =>
8137 return Is_Variable_Prefix (Prefix (Orig_Node))
8138 and then Is_Variable (Selector_Name (Orig_Node));
8140 -- For an explicit dereference, the type of the prefix cannot
8141 -- be an access to constant or an access to subprogram.
8143 when N_Explicit_Dereference =>
8145 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8147 return Is_Access_Type (Typ)
8148 and then not Is_Access_Constant (Root_Type (Typ))
8149 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8152 -- The type conversion is the case where we do not deal with the
8153 -- context dependent special case of an actual parameter. Thus
8154 -- the type conversion is only considered a variable for the
8155 -- purposes of this routine if the target type is tagged. However,
8156 -- a type conversion is considered to be a variable if it does not
8157 -- come from source (this deals for example with the conversions
8158 -- of expressions to their actual subtypes).
8160 when N_Type_Conversion =>
8161 return Is_Variable (Expression (Orig_Node))
8163 (not Comes_From_Source (Orig_Node)
8165 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8167 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8169 -- GNAT allows an unchecked type conversion as a variable. This
8170 -- only affects the generation of internal expanded code, since
8171 -- calls to instantiations of Unchecked_Conversion are never
8172 -- considered variables (since they are function calls).
8173 -- This is also true for expression actions.
8175 when N_Unchecked_Type_Conversion =>
8176 return Is_Variable (Expression (Orig_Node));
8184 ---------------------------
8185 -- Is_Visibly_Controlled --
8186 ---------------------------
8188 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8189 Root : constant Entity_Id := Root_Type (T);
8191 return Chars (Scope (Root)) = Name_Finalization
8192 and then Chars (Scope (Scope (Root))) = Name_Ada
8193 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8194 end Is_Visibly_Controlled;
8196 ------------------------
8197 -- Is_Volatile_Object --
8198 ------------------------
8200 function Is_Volatile_Object (N : Node_Id) return Boolean is
8202 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8203 -- Determines if given object has volatile components
8205 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8206 -- If prefix is an implicit dereference, examine designated type
8208 ------------------------
8209 -- Is_Volatile_Prefix --
8210 ------------------------
8212 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8213 Typ : constant Entity_Id := Etype (N);
8216 if Is_Access_Type (Typ) then
8218 Dtyp : constant Entity_Id := Designated_Type (Typ);
8221 return Is_Volatile (Dtyp)
8222 or else Has_Volatile_Components (Dtyp);
8226 return Object_Has_Volatile_Components (N);
8228 end Is_Volatile_Prefix;
8230 ------------------------------------
8231 -- Object_Has_Volatile_Components --
8232 ------------------------------------
8234 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8235 Typ : constant Entity_Id := Etype (N);
8238 if Is_Volatile (Typ)
8239 or else Has_Volatile_Components (Typ)
8243 elsif Is_Entity_Name (N)
8244 and then (Has_Volatile_Components (Entity (N))
8245 or else Is_Volatile (Entity (N)))
8249 elsif Nkind (N) = N_Indexed_Component
8250 or else Nkind (N) = N_Selected_Component
8252 return Is_Volatile_Prefix (Prefix (N));
8257 end Object_Has_Volatile_Components;
8259 -- Start of processing for Is_Volatile_Object
8262 if Is_Volatile (Etype (N))
8263 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8267 elsif Nkind (N) = N_Indexed_Component
8268 or else Nkind (N) = N_Selected_Component
8270 return Is_Volatile_Prefix (Prefix (N));
8275 end Is_Volatile_Object;
8277 -------------------------
8278 -- Kill_Current_Values --
8279 -------------------------
8281 procedure Kill_Current_Values
8283 Last_Assignment_Only : Boolean := False)
8286 -- ??? do we have to worry about clearing cached checks?
8288 if Is_Assignable (Ent) then
8289 Set_Last_Assignment (Ent, Empty);
8292 if Is_Object (Ent) then
8293 if not Last_Assignment_Only then
8295 Set_Current_Value (Ent, Empty);
8297 if not Can_Never_Be_Null (Ent) then
8298 Set_Is_Known_Non_Null (Ent, False);
8301 Set_Is_Known_Null (Ent, False);
8303 -- Reset Is_Known_Valid unless type is always valid, or if we have
8304 -- a loop parameter (loop parameters are always valid, since their
8305 -- bounds are defined by the bounds given in the loop header).
8307 if not Is_Known_Valid (Etype (Ent))
8308 and then Ekind (Ent) /= E_Loop_Parameter
8310 Set_Is_Known_Valid (Ent, False);
8314 end Kill_Current_Values;
8316 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8319 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8320 -- Clear current value for entity E and all entities chained to E
8322 ------------------------------------------
8323 -- Kill_Current_Values_For_Entity_Chain --
8324 ------------------------------------------
8326 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8330 while Present (Ent) loop
8331 Kill_Current_Values (Ent, Last_Assignment_Only);
8334 end Kill_Current_Values_For_Entity_Chain;
8336 -- Start of processing for Kill_Current_Values
8339 -- Kill all saved checks, a special case of killing saved values
8341 if not Last_Assignment_Only then
8345 -- Loop through relevant scopes, which includes the current scope and
8346 -- any parent scopes if the current scope is a block or a package.
8351 -- Clear current values of all entities in current scope
8353 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8355 -- If scope is a package, also clear current values of all
8356 -- private entities in the scope.
8358 if Is_Package_Or_Generic_Package (S)
8359 or else Is_Concurrent_Type (S)
8361 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8364 -- If this is a not a subprogram, deal with parents
8366 if not Is_Subprogram (S) then
8368 exit Scope_Loop when S = Standard_Standard;
8372 end loop Scope_Loop;
8373 end Kill_Current_Values;
8375 --------------------------
8376 -- Kill_Size_Check_Code --
8377 --------------------------
8379 procedure Kill_Size_Check_Code (E : Entity_Id) is
8381 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8382 and then Present (Size_Check_Code (E))
8384 Remove (Size_Check_Code (E));
8385 Set_Size_Check_Code (E, Empty);
8387 end Kill_Size_Check_Code;
8389 --------------------------
8390 -- Known_To_Be_Assigned --
8391 --------------------------
8393 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8394 P : constant Node_Id := Parent (N);
8399 -- Test left side of assignment
8401 when N_Assignment_Statement =>
8402 return N = Name (P);
8404 -- Function call arguments are never lvalues
8406 when N_Function_Call =>
8409 -- Positional parameter for procedure or accept call
8411 when N_Procedure_Call_Statement |
8420 Proc := Get_Subprogram_Entity (P);
8426 -- If we are not a list member, something is strange, so
8427 -- be conservative and return False.
8429 if not Is_List_Member (N) then
8433 -- We are going to find the right formal by stepping forward
8434 -- through the formals, as we step backwards in the actuals.
8436 Form := First_Formal (Proc);
8439 -- If no formal, something is weird, so be conservative
8440 -- and return False.
8451 return Ekind (Form) /= E_In_Parameter;
8454 -- Named parameter for procedure or accept call
8456 when N_Parameter_Association =>
8462 Proc := Get_Subprogram_Entity (Parent (P));
8468 -- Loop through formals to find the one that matches
8470 Form := First_Formal (Proc);
8472 -- If no matching formal, that's peculiar, some kind of
8473 -- previous error, so return False to be conservative.
8479 -- Else test for match
8481 if Chars (Form) = Chars (Selector_Name (P)) then
8482 return Ekind (Form) /= E_In_Parameter;
8489 -- Test for appearing in a conversion that itself appears
8490 -- in an lvalue context, since this should be an lvalue.
8492 when N_Type_Conversion =>
8493 return Known_To_Be_Assigned (P);
8495 -- All other references are definitely not known to be modifications
8501 end Known_To_Be_Assigned;
8503 ---------------------------
8504 -- Last_Source_Statement --
8505 ---------------------------
8507 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8511 N := Last (Statements (HSS));
8512 while Present (N) loop
8513 exit when Comes_From_Source (N);
8518 end Last_Source_Statement;
8520 ----------------------------------
8521 -- Matching_Static_Array_Bounds --
8522 ----------------------------------
8524 function Matching_Static_Array_Bounds
8526 R_Typ : Node_Id) return Boolean
8528 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8529 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8541 if L_Ndims /= R_Ndims then
8545 -- Unconstrained types do not have static bounds
8547 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8551 -- First treat specially the first dimension, as the lower bound and
8552 -- length of string literals are not stored like those of arrays.
8554 if Ekind (L_Typ) = E_String_Literal_Subtype then
8555 L_Low := String_Literal_Low_Bound (L_Typ);
8556 L_Len := String_Literal_Length (L_Typ);
8558 L_Index := First_Index (L_Typ);
8559 Get_Index_Bounds (L_Index, L_Low, L_High);
8561 if Is_OK_Static_Expression (L_Low)
8562 and then Is_OK_Static_Expression (L_High)
8564 if Expr_Value (L_High) < Expr_Value (L_Low) then
8567 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8574 if Ekind (R_Typ) = E_String_Literal_Subtype then
8575 R_Low := String_Literal_Low_Bound (R_Typ);
8576 R_Len := String_Literal_Length (R_Typ);
8578 R_Index := First_Index (R_Typ);
8579 Get_Index_Bounds (R_Index, R_Low, R_High);
8581 if Is_OK_Static_Expression (R_Low)
8582 and then Is_OK_Static_Expression (R_High)
8584 if Expr_Value (R_High) < Expr_Value (R_Low) then
8587 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8594 if Is_OK_Static_Expression (L_Low)
8595 and then Is_OK_Static_Expression (R_Low)
8596 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8597 and then L_Len = R_Len
8604 -- Then treat all other dimensions
8606 for Indx in 2 .. L_Ndims loop
8610 Get_Index_Bounds (L_Index, L_Low, L_High);
8611 Get_Index_Bounds (R_Index, R_Low, R_High);
8613 if Is_OK_Static_Expression (L_Low)
8614 and then Is_OK_Static_Expression (L_High)
8615 and then Is_OK_Static_Expression (R_Low)
8616 and then Is_OK_Static_Expression (R_High)
8617 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8618 and then Expr_Value (L_High) = Expr_Value (R_High)
8626 -- If we fall through the loop, all indexes matched
8629 end Matching_Static_Array_Bounds;
8635 function May_Be_Lvalue (N : Node_Id) return Boolean is
8636 P : constant Node_Id := Parent (N);
8641 -- Test left side of assignment
8643 when N_Assignment_Statement =>
8644 return N = Name (P);
8646 -- Test prefix of component or attribute. Note that the prefix of an
8647 -- explicit or implicit dereference cannot be an l-value.
8649 when N_Attribute_Reference =>
8650 return N = Prefix (P)
8651 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8653 -- For an expanded name, the name is an lvalue if the expanded name
8654 -- is an lvalue, but the prefix is never an lvalue, since it is just
8655 -- the scope where the name is found.
8657 when N_Expanded_Name =>
8658 if N = Prefix (P) then
8659 return May_Be_Lvalue (P);
8664 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8665 -- B is a little interesting, if we have A.B := 3, there is some
8666 -- discussion as to whether B is an lvalue or not, we choose to say
8667 -- it is. Note however that A is not an lvalue if it is of an access
8668 -- type since this is an implicit dereference.
8670 when N_Selected_Component =>
8672 and then Present (Etype (N))
8673 and then Is_Access_Type (Etype (N))
8677 return May_Be_Lvalue (P);
8680 -- For an indexed component or slice, the index or slice bounds is
8681 -- never an lvalue. The prefix is an lvalue if the indexed component
8682 -- or slice is an lvalue, except if it is an access type, where we
8683 -- have an implicit dereference.
8685 when N_Indexed_Component =>
8687 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8691 return May_Be_Lvalue (P);
8694 -- Prefix of a reference is an lvalue if the reference is an lvalue
8697 return May_Be_Lvalue (P);
8699 -- Prefix of explicit dereference is never an lvalue
8701 when N_Explicit_Dereference =>
8704 -- Positional parameter for subprogram, entry, or accept call.
8705 -- In older versions of Ada function call arguments are never
8706 -- lvalues. In Ada 2012 functions can have in-out parameters.
8708 when N_Function_Call |
8709 N_Procedure_Call_Statement |
8710 N_Entry_Call_Statement |
8713 if Nkind (P) = N_Function_Call
8714 and then Ada_Version < Ada_2012
8719 -- The following mechanism is clumsy and fragile. A single
8720 -- flag set in Resolve_Actuals would be preferable ???
8728 Proc := Get_Subprogram_Entity (P);
8734 -- If we are not a list member, something is strange, so
8735 -- be conservative and return True.
8737 if not Is_List_Member (N) then
8741 -- We are going to find the right formal by stepping forward
8742 -- through the formals, as we step backwards in the actuals.
8744 Form := First_Formal (Proc);
8747 -- If no formal, something is weird, so be conservative
8759 return Ekind (Form) /= E_In_Parameter;
8762 -- Named parameter for procedure or accept call
8764 when N_Parameter_Association =>
8770 Proc := Get_Subprogram_Entity (Parent (P));
8776 -- Loop through formals to find the one that matches
8778 Form := First_Formal (Proc);
8780 -- If no matching formal, that's peculiar, some kind of
8781 -- previous error, so return True to be conservative.
8787 -- Else test for match
8789 if Chars (Form) = Chars (Selector_Name (P)) then
8790 return Ekind (Form) /= E_In_Parameter;
8797 -- Test for appearing in a conversion that itself appears in an
8798 -- lvalue context, since this should be an lvalue.
8800 when N_Type_Conversion =>
8801 return May_Be_Lvalue (P);
8803 -- Test for appearance in object renaming declaration
8805 when N_Object_Renaming_Declaration =>
8808 -- All other references are definitely not lvalues
8816 -----------------------
8817 -- Mark_Coextensions --
8818 -----------------------
8820 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8821 Is_Dynamic : Boolean;
8822 -- Indicates whether the context causes nested coextensions to be
8823 -- dynamic or static
8825 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8826 -- Recognize an allocator node and label it as a dynamic coextension
8828 --------------------
8829 -- Mark_Allocator --
8830 --------------------
8832 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8834 if Nkind (N) = N_Allocator then
8836 Set_Is_Dynamic_Coextension (N);
8838 -- If the allocator expression is potentially dynamic, it may
8839 -- be expanded out of order and require dynamic allocation
8840 -- anyway, so we treat the coextension itself as dynamic.
8841 -- Potential optimization ???
8843 elsif Nkind (Expression (N)) = N_Qualified_Expression
8844 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8846 Set_Is_Dynamic_Coextension (N);
8849 Set_Is_Static_Coextension (N);
8856 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8858 -- Start of processing Mark_Coextensions
8861 case Nkind (Context_Nod) is
8862 when N_Assignment_Statement |
8863 N_Simple_Return_Statement =>
8864 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8866 when N_Object_Declaration =>
8867 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8869 -- This routine should not be called for constructs which may not
8870 -- contain coextensions.
8873 raise Program_Error;
8876 Mark_Allocators (Root_Nod);
8877 end Mark_Coextensions;
8879 ----------------------
8880 -- Needs_One_Actual --
8881 ----------------------
8883 function Needs_One_Actual (E : Entity_Id) return Boolean is
8887 if Ada_Version >= Ada_2005
8888 and then Present (First_Formal (E))
8890 Formal := Next_Formal (First_Formal (E));
8891 while Present (Formal) loop
8892 if No (Default_Value (Formal)) then
8896 Next_Formal (Formal);
8904 end Needs_One_Actual;
8906 ------------------------
8907 -- New_Copy_List_Tree --
8908 ------------------------
8910 function New_Copy_List_Tree (List : List_Id) return List_Id is
8915 if List = No_List then
8922 while Present (E) loop
8923 Append (New_Copy_Tree (E), NL);
8929 end New_Copy_List_Tree;
8935 use Atree.Unchecked_Access;
8936 use Atree_Private_Part;
8938 -- Our approach here requires a two pass traversal of the tree. The
8939 -- first pass visits all nodes that eventually will be copied looking
8940 -- for defining Itypes. If any defining Itypes are found, then they are
8941 -- copied, and an entry is added to the replacement map. In the second
8942 -- phase, the tree is copied, using the replacement map to replace any
8943 -- Itype references within the copied tree.
8945 -- The following hash tables are used if the Map supplied has more
8946 -- than hash threshold entries to speed up access to the map. If
8947 -- there are fewer entries, then the map is searched sequentially
8948 -- (because setting up a hash table for only a few entries takes
8949 -- more time than it saves.
8951 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8952 -- Hash function used for hash operations
8958 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8960 return Nat (E) mod (NCT_Header_Num'Last + 1);
8967 -- The hash table NCT_Assoc associates old entities in the table
8968 -- with their corresponding new entities (i.e. the pairs of entries
8969 -- presented in the original Map argument are Key-Element pairs).
8971 package NCT_Assoc is new Simple_HTable (
8972 Header_Num => NCT_Header_Num,
8973 Element => Entity_Id,
8974 No_Element => Empty,
8976 Hash => New_Copy_Hash,
8977 Equal => Types."=");
8979 ---------------------
8980 -- NCT_Itype_Assoc --
8981 ---------------------
8983 -- The hash table NCT_Itype_Assoc contains entries only for those
8984 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8985 -- The key is the associated node, and the element is the new node
8986 -- itself (NOT the associated node for the new node).
8988 package NCT_Itype_Assoc is new Simple_HTable (
8989 Header_Num => NCT_Header_Num,
8990 Element => Entity_Id,
8991 No_Element => Empty,
8993 Hash => New_Copy_Hash,
8994 Equal => Types."=");
8996 -- Start of processing for New_Copy_Tree function
8998 function New_Copy_Tree
9000 Map : Elist_Id := No_Elist;
9001 New_Sloc : Source_Ptr := No_Location;
9002 New_Scope : Entity_Id := Empty) return Node_Id
9004 Actual_Map : Elist_Id := Map;
9005 -- This is the actual map for the copy. It is initialized with the
9006 -- given elements, and then enlarged as required for Itypes that are
9007 -- copied during the first phase of the copy operation. The visit
9008 -- procedures add elements to this map as Itypes are encountered.
9009 -- The reason we cannot use Map directly, is that it may well be
9010 -- (and normally is) initialized to No_Elist, and if we have mapped
9011 -- entities, we have to reset it to point to a real Elist.
9013 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
9014 -- Called during second phase to map entities into their corresponding
9015 -- copies using Actual_Map. If the argument is not an entity, or is not
9016 -- in Actual_Map, then it is returned unchanged.
9018 procedure Build_NCT_Hash_Tables;
9019 -- Builds hash tables (number of elements >= threshold value)
9021 function Copy_Elist_With_Replacement
9022 (Old_Elist : Elist_Id) return Elist_Id;
9023 -- Called during second phase to copy element list doing replacements
9025 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
9026 -- Called during the second phase to process a copied Itype. The actual
9027 -- copy happened during the first phase (so that we could make the entry
9028 -- in the mapping), but we still have to deal with the descendents of
9029 -- the copied Itype and copy them where necessary.
9031 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
9032 -- Called during second phase to copy list doing replacements
9034 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
9035 -- Called during second phase to copy node doing replacements
9037 procedure Visit_Elist (E : Elist_Id);
9038 -- Called during first phase to visit all elements of an Elist
9040 procedure Visit_Field (F : Union_Id; N : Node_Id);
9041 -- Visit a single field, recursing to call Visit_Node or Visit_List
9042 -- if the field is a syntactic descendent of the current node (i.e.
9043 -- its parent is Node N).
9045 procedure Visit_Itype (Old_Itype : Entity_Id);
9046 -- Called during first phase to visit subsidiary fields of a defining
9047 -- Itype, and also create a copy and make an entry in the replacement
9048 -- map for the new copy.
9050 procedure Visit_List (L : List_Id);
9051 -- Called during first phase to visit all elements of a List
9053 procedure Visit_Node (N : Node_Or_Entity_Id);
9054 -- Called during first phase to visit a node and all its subtrees
9060 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
9065 if not Has_Extension (N) or else No (Actual_Map) then
9068 elsif NCT_Hash_Tables_Used then
9069 Ent := NCT_Assoc.Get (Entity_Id (N));
9071 if Present (Ent) then
9077 -- No hash table used, do serial search
9080 E := First_Elmt (Actual_Map);
9081 while Present (E) loop
9082 if Node (E) = N then
9083 return Node (Next_Elmt (E));
9085 E := Next_Elmt (Next_Elmt (E));
9093 ---------------------------
9094 -- Build_NCT_Hash_Tables --
9095 ---------------------------
9097 procedure Build_NCT_Hash_Tables is
9101 if NCT_Hash_Table_Setup then
9103 NCT_Itype_Assoc.Reset;
9106 Elmt := First_Elmt (Actual_Map);
9107 while Present (Elmt) loop
9110 -- Get new entity, and associate old and new
9113 NCT_Assoc.Set (Ent, Node (Elmt));
9115 if Is_Type (Ent) then
9117 Anode : constant Entity_Id :=
9118 Associated_Node_For_Itype (Ent);
9121 if Present (Anode) then
9123 -- Enter a link between the associated node of the
9124 -- old Itype and the new Itype, for updating later
9125 -- when node is copied.
9127 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9135 NCT_Hash_Tables_Used := True;
9136 NCT_Hash_Table_Setup := True;
9137 end Build_NCT_Hash_Tables;
9139 ---------------------------------
9140 -- Copy_Elist_With_Replacement --
9141 ---------------------------------
9143 function Copy_Elist_With_Replacement
9144 (Old_Elist : Elist_Id) return Elist_Id
9147 New_Elist : Elist_Id;
9150 if No (Old_Elist) then
9154 New_Elist := New_Elmt_List;
9156 M := First_Elmt (Old_Elist);
9157 while Present (M) loop
9158 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9164 end Copy_Elist_With_Replacement;
9166 ---------------------------------
9167 -- Copy_Itype_With_Replacement --
9168 ---------------------------------
9170 -- This routine exactly parallels its phase one analog Visit_Itype,
9172 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9174 -- Translate Next_Entity, Scope and Etype fields, in case they
9175 -- reference entities that have been mapped into copies.
9177 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9178 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9180 if Present (New_Scope) then
9181 Set_Scope (New_Itype, New_Scope);
9183 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9186 -- Copy referenced fields
9188 if Is_Discrete_Type (New_Itype) then
9189 Set_Scalar_Range (New_Itype,
9190 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9192 elsif Has_Discriminants (Base_Type (New_Itype)) then
9193 Set_Discriminant_Constraint (New_Itype,
9194 Copy_Elist_With_Replacement
9195 (Discriminant_Constraint (New_Itype)));
9197 elsif Is_Array_Type (New_Itype) then
9198 if Present (First_Index (New_Itype)) then
9199 Set_First_Index (New_Itype,
9200 First (Copy_List_With_Replacement
9201 (List_Containing (First_Index (New_Itype)))));
9204 if Is_Packed (New_Itype) then
9205 Set_Packed_Array_Type (New_Itype,
9206 Copy_Node_With_Replacement
9207 (Packed_Array_Type (New_Itype)));
9210 end Copy_Itype_With_Replacement;
9212 --------------------------------
9213 -- Copy_List_With_Replacement --
9214 --------------------------------
9216 function Copy_List_With_Replacement
9217 (Old_List : List_Id) return List_Id
9223 if Old_List = No_List then
9227 New_List := Empty_List;
9229 E := First (Old_List);
9230 while Present (E) loop
9231 Append (Copy_Node_With_Replacement (E), New_List);
9237 end Copy_List_With_Replacement;
9239 --------------------------------
9240 -- Copy_Node_With_Replacement --
9241 --------------------------------
9243 function Copy_Node_With_Replacement
9244 (Old_Node : Node_Id) return Node_Id
9248 procedure Adjust_Named_Associations
9249 (Old_Node : Node_Id;
9250 New_Node : Node_Id);
9251 -- If a call node has named associations, these are chained through
9252 -- the First_Named_Actual, Next_Named_Actual links. These must be
9253 -- propagated separately to the new parameter list, because these
9254 -- are not syntactic fields.
9256 function Copy_Field_With_Replacement
9257 (Field : Union_Id) return Union_Id;
9258 -- Given Field, which is a field of Old_Node, return a copy of it
9259 -- if it is a syntactic field (i.e. its parent is Node), setting
9260 -- the parent of the copy to poit to New_Node. Otherwise returns
9261 -- the field (possibly mapped if it is an entity).
9263 -------------------------------
9264 -- Adjust_Named_Associations --
9265 -------------------------------
9267 procedure Adjust_Named_Associations
9268 (Old_Node : Node_Id;
9278 Old_E := First (Parameter_Associations (Old_Node));
9279 New_E := First (Parameter_Associations (New_Node));
9280 while Present (Old_E) loop
9281 if Nkind (Old_E) = N_Parameter_Association
9282 and then Present (Next_Named_Actual (Old_E))
9284 if First_Named_Actual (Old_Node)
9285 = Explicit_Actual_Parameter (Old_E)
9287 Set_First_Named_Actual
9288 (New_Node, Explicit_Actual_Parameter (New_E));
9291 -- Now scan parameter list from the beginning,to locate
9292 -- next named actual, which can be out of order.
9294 Old_Next := First (Parameter_Associations (Old_Node));
9295 New_Next := First (Parameter_Associations (New_Node));
9297 while Nkind (Old_Next) /= N_Parameter_Association
9298 or else Explicit_Actual_Parameter (Old_Next)
9299 /= Next_Named_Actual (Old_E)
9305 Set_Next_Named_Actual
9306 (New_E, Explicit_Actual_Parameter (New_Next));
9312 end Adjust_Named_Associations;
9314 ---------------------------------
9315 -- Copy_Field_With_Replacement --
9316 ---------------------------------
9318 function Copy_Field_With_Replacement
9319 (Field : Union_Id) return Union_Id
9322 if Field = Union_Id (Empty) then
9325 elsif Field in Node_Range then
9327 Old_N : constant Node_Id := Node_Id (Field);
9331 -- If syntactic field, as indicated by the parent pointer
9332 -- being set, then copy the referenced node recursively.
9334 if Parent (Old_N) = Old_Node then
9335 New_N := Copy_Node_With_Replacement (Old_N);
9337 if New_N /= Old_N then
9338 Set_Parent (New_N, New_Node);
9341 -- For semantic fields, update possible entity reference
9342 -- from the replacement map.
9345 New_N := Assoc (Old_N);
9348 return Union_Id (New_N);
9351 elsif Field in List_Range then
9353 Old_L : constant List_Id := List_Id (Field);
9357 -- If syntactic field, as indicated by the parent pointer,
9358 -- then recursively copy the entire referenced list.
9360 if Parent (Old_L) = Old_Node then
9361 New_L := Copy_List_With_Replacement (Old_L);
9362 Set_Parent (New_L, New_Node);
9364 -- For semantic list, just returned unchanged
9370 return Union_Id (New_L);
9373 -- Anything other than a list or a node is returned unchanged
9378 end Copy_Field_With_Replacement;
9380 -- Start of processing for Copy_Node_With_Replacement
9383 if Old_Node <= Empty_Or_Error then
9386 elsif Has_Extension (Old_Node) then
9387 return Assoc (Old_Node);
9390 New_Node := New_Copy (Old_Node);
9392 -- If the node we are copying is the associated node of a
9393 -- previously copied Itype, then adjust the associated node
9394 -- of the copy of that Itype accordingly.
9396 if Present (Actual_Map) then
9402 -- Case of hash table used
9404 if NCT_Hash_Tables_Used then
9405 Ent := NCT_Itype_Assoc.Get (Old_Node);
9407 if Present (Ent) then
9408 Set_Associated_Node_For_Itype (Ent, New_Node);
9411 -- Case of no hash table used
9414 E := First_Elmt (Actual_Map);
9415 while Present (E) loop
9416 if Is_Itype (Node (E))
9418 Old_Node = Associated_Node_For_Itype (Node (E))
9420 Set_Associated_Node_For_Itype
9421 (Node (Next_Elmt (E)), New_Node);
9424 E := Next_Elmt (Next_Elmt (E));
9430 -- Recursively copy descendents
9433 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9435 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9437 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9439 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9441 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9443 -- Adjust Sloc of new node if necessary
9445 if New_Sloc /= No_Location then
9446 Set_Sloc (New_Node, New_Sloc);
9448 -- If we adjust the Sloc, then we are essentially making
9449 -- a completely new node, so the Comes_From_Source flag
9450 -- should be reset to the proper default value.
9452 Nodes.Table (New_Node).Comes_From_Source :=
9453 Default_Node.Comes_From_Source;
9456 -- If the node is call and has named associations,
9457 -- set the corresponding links in the copy.
9459 if (Nkind (Old_Node) = N_Function_Call
9460 or else Nkind (Old_Node) = N_Entry_Call_Statement
9462 Nkind (Old_Node) = N_Procedure_Call_Statement)
9463 and then Present (First_Named_Actual (Old_Node))
9465 Adjust_Named_Associations (Old_Node, New_Node);
9468 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9469 -- The replacement mechanism applies to entities, and is not used
9470 -- here. Eventually we may need a more general graph-copying
9471 -- routine. For now, do a sequential search to find desired node.
9473 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9474 and then Present (First_Real_Statement (Old_Node))
9477 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9481 N1 := First (Statements (Old_Node));
9482 N2 := First (Statements (New_Node));
9484 while N1 /= Old_F loop
9489 Set_First_Real_Statement (New_Node, N2);
9494 -- All done, return copied node
9497 end Copy_Node_With_Replacement;
9503 procedure Visit_Elist (E : Elist_Id) is
9507 Elmt := First_Elmt (E);
9509 while Elmt /= No_Elmt loop
9510 Visit_Node (Node (Elmt));
9520 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9522 if F = Union_Id (Empty) then
9525 elsif F in Node_Range then
9527 -- Copy node if it is syntactic, i.e. its parent pointer is
9528 -- set to point to the field that referenced it (certain
9529 -- Itypes will also meet this criterion, which is fine, since
9530 -- these are clearly Itypes that do need to be copied, since
9531 -- we are copying their parent.)
9533 if Parent (Node_Id (F)) = N then
9534 Visit_Node (Node_Id (F));
9537 -- Another case, if we are pointing to an Itype, then we want
9538 -- to copy it if its associated node is somewhere in the tree
9541 -- Note: the exclusion of self-referential copies is just an
9542 -- optimization, since the search of the already copied list
9543 -- would catch it, but it is a common case (Etype pointing
9544 -- to itself for an Itype that is a base type).
9546 elsif Has_Extension (Node_Id (F))
9547 and then Is_Itype (Entity_Id (F))
9548 and then Node_Id (F) /= N
9554 P := Associated_Node_For_Itype (Node_Id (F));
9555 while Present (P) loop
9557 Visit_Node (Node_Id (F));
9564 -- An Itype whose parent is not being copied definitely
9565 -- should NOT be copied, since it does not belong in any
9566 -- sense to the copied subtree.
9572 elsif F in List_Range
9573 and then Parent (List_Id (F)) = N
9575 Visit_List (List_Id (F));
9584 procedure Visit_Itype (Old_Itype : Entity_Id) is
9585 New_Itype : Entity_Id;
9590 -- Itypes that describe the designated type of access to subprograms
9591 -- have the structure of subprogram declarations, with signatures,
9592 -- etc. Either we duplicate the signatures completely, or choose to
9593 -- share such itypes, which is fine because their elaboration will
9594 -- have no side effects.
9596 if Ekind (Old_Itype) = E_Subprogram_Type then
9600 New_Itype := New_Copy (Old_Itype);
9602 -- The new Itype has all the attributes of the old one, and
9603 -- we just copy the contents of the entity. However, the back-end
9604 -- needs different names for debugging purposes, so we create a
9605 -- new internal name for it in all cases.
9607 Set_Chars (New_Itype, New_Internal_Name ('T'));
9609 -- If our associated node is an entity that has already been copied,
9610 -- then set the associated node of the copy to point to the right
9611 -- copy. If we have copied an Itype that is itself the associated
9612 -- node of some previously copied Itype, then we set the right
9613 -- pointer in the other direction.
9615 if Present (Actual_Map) then
9617 -- Case of hash tables used
9619 if NCT_Hash_Tables_Used then
9621 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9623 if Present (Ent) then
9624 Set_Associated_Node_For_Itype (New_Itype, Ent);
9627 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9628 if Present (Ent) then
9629 Set_Associated_Node_For_Itype (Ent, New_Itype);
9631 -- If the hash table has no association for this Itype and
9632 -- its associated node, enter one now.
9636 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9639 -- Case of hash tables not used
9642 E := First_Elmt (Actual_Map);
9643 while Present (E) loop
9644 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9645 Set_Associated_Node_For_Itype
9646 (New_Itype, Node (Next_Elmt (E)));
9649 if Is_Type (Node (E))
9651 Old_Itype = Associated_Node_For_Itype (Node (E))
9653 Set_Associated_Node_For_Itype
9654 (Node (Next_Elmt (E)), New_Itype);
9657 E := Next_Elmt (Next_Elmt (E));
9662 if Present (Freeze_Node (New_Itype)) then
9663 Set_Is_Frozen (New_Itype, False);
9664 Set_Freeze_Node (New_Itype, Empty);
9667 -- Add new association to map
9669 if No (Actual_Map) then
9670 Actual_Map := New_Elmt_List;
9673 Append_Elmt (Old_Itype, Actual_Map);
9674 Append_Elmt (New_Itype, Actual_Map);
9676 if NCT_Hash_Tables_Used then
9677 NCT_Assoc.Set (Old_Itype, New_Itype);
9680 NCT_Table_Entries := NCT_Table_Entries + 1;
9682 if NCT_Table_Entries > NCT_Hash_Threshold then
9683 Build_NCT_Hash_Tables;
9687 -- If a record subtype is simply copied, the entity list will be
9688 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9690 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9691 Set_Cloned_Subtype (New_Itype, Old_Itype);
9694 -- Visit descendents that eventually get copied
9696 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9698 if Is_Discrete_Type (Old_Itype) then
9699 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9701 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9702 -- ??? This should involve call to Visit_Field
9703 Visit_Elist (Discriminant_Constraint (Old_Itype));
9705 elsif Is_Array_Type (Old_Itype) then
9706 if Present (First_Index (Old_Itype)) then
9707 Visit_Field (Union_Id (List_Containing
9708 (First_Index (Old_Itype))),
9712 if Is_Packed (Old_Itype) then
9713 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9723 procedure Visit_List (L : List_Id) is
9726 if L /= No_List then
9729 while Present (N) loop
9740 procedure Visit_Node (N : Node_Or_Entity_Id) is
9742 -- Start of processing for Visit_Node
9745 -- Handle case of an Itype, which must be copied
9747 if Has_Extension (N)
9748 and then Is_Itype (N)
9750 -- Nothing to do if already in the list. This can happen with an
9751 -- Itype entity that appears more than once in the tree.
9752 -- Note that we do not want to visit descendents in this case.
9754 -- Test for already in list when hash table is used
9756 if NCT_Hash_Tables_Used then
9757 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9761 -- Test for already in list when hash table not used
9767 if Present (Actual_Map) then
9768 E := First_Elmt (Actual_Map);
9769 while Present (E) loop
9770 if Node (E) = N then
9773 E := Next_Elmt (Next_Elmt (E));
9783 -- Visit descendents
9785 Visit_Field (Field1 (N), N);
9786 Visit_Field (Field2 (N), N);
9787 Visit_Field (Field3 (N), N);
9788 Visit_Field (Field4 (N), N);
9789 Visit_Field (Field5 (N), N);
9792 -- Start of processing for New_Copy_Tree
9797 -- See if we should use hash table
9799 if No (Actual_Map) then
9800 NCT_Hash_Tables_Used := False;
9807 NCT_Table_Entries := 0;
9809 Elmt := First_Elmt (Actual_Map);
9810 while Present (Elmt) loop
9811 NCT_Table_Entries := NCT_Table_Entries + 1;
9816 if NCT_Table_Entries > NCT_Hash_Threshold then
9817 Build_NCT_Hash_Tables;
9819 NCT_Hash_Tables_Used := False;
9824 -- Hash table set up if required, now start phase one by visiting
9825 -- top node (we will recursively visit the descendents).
9827 Visit_Node (Source);
9829 -- Now the second phase of the copy can start. First we process
9830 -- all the mapped entities, copying their descendents.
9832 if Present (Actual_Map) then
9835 New_Itype : Entity_Id;
9837 Elmt := First_Elmt (Actual_Map);
9838 while Present (Elmt) loop
9840 New_Itype := Node (Elmt);
9841 Copy_Itype_With_Replacement (New_Itype);
9847 -- Now we can copy the actual tree
9849 return Copy_Node_With_Replacement (Source);
9852 -------------------------
9853 -- New_External_Entity --
9854 -------------------------
9856 function New_External_Entity
9857 (Kind : Entity_Kind;
9858 Scope_Id : Entity_Id;
9859 Sloc_Value : Source_Ptr;
9860 Related_Id : Entity_Id;
9862 Suffix_Index : Nat := 0;
9863 Prefix : Character := ' ') return Entity_Id
9865 N : constant Entity_Id :=
9866 Make_Defining_Identifier (Sloc_Value,
9868 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9871 Set_Ekind (N, Kind);
9872 Set_Is_Internal (N, True);
9873 Append_Entity (N, Scope_Id);
9874 Set_Public_Status (N);
9876 if Kind in Type_Kind then
9877 Init_Size_Align (N);
9881 end New_External_Entity;
9883 -------------------------
9884 -- New_Internal_Entity --
9885 -------------------------
9887 function New_Internal_Entity
9888 (Kind : Entity_Kind;
9889 Scope_Id : Entity_Id;
9890 Sloc_Value : Source_Ptr;
9891 Id_Char : Character) return Entity_Id
9893 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9896 Set_Ekind (N, Kind);
9897 Set_Is_Internal (N, True);
9898 Append_Entity (N, Scope_Id);
9900 if Kind in Type_Kind then
9901 Init_Size_Align (N);
9905 end New_Internal_Entity;
9911 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9915 -- If we are pointing at a positional parameter, it is a member of a
9916 -- node list (the list of parameters), and the next parameter is the
9917 -- next node on the list, unless we hit a parameter association, then
9918 -- we shift to using the chain whose head is the First_Named_Actual in
9919 -- the parent, and then is threaded using the Next_Named_Actual of the
9920 -- Parameter_Association. All this fiddling is because the original node
9921 -- list is in the textual call order, and what we need is the
9922 -- declaration order.
9924 if Is_List_Member (Actual_Id) then
9925 N := Next (Actual_Id);
9927 if Nkind (N) = N_Parameter_Association then
9928 return First_Named_Actual (Parent (Actual_Id));
9934 return Next_Named_Actual (Parent (Actual_Id));
9938 procedure Next_Actual (Actual_Id : in out Node_Id) is
9940 Actual_Id := Next_Actual (Actual_Id);
9943 -----------------------
9944 -- Normalize_Actuals --
9945 -----------------------
9947 -- Chain actuals according to formals of subprogram. If there are no named
9948 -- associations, the chain is simply the list of Parameter Associations,
9949 -- since the order is the same as the declaration order. If there are named
9950 -- associations, then the First_Named_Actual field in the N_Function_Call
9951 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9952 -- node for the parameter that comes first in declaration order. The
9953 -- remaining named parameters are then chained in declaration order using
9954 -- Next_Named_Actual.
9956 -- This routine also verifies that the number of actuals is compatible with
9957 -- the number and default values of formals, but performs no type checking
9958 -- (type checking is done by the caller).
9960 -- If the matching succeeds, Success is set to True and the caller proceeds
9961 -- with type-checking. If the match is unsuccessful, then Success is set to
9962 -- False, and the caller attempts a different interpretation, if there is
9965 -- If the flag Report is on, the call is not overloaded, and a failure to
9966 -- match can be reported here, rather than in the caller.
9968 procedure Normalize_Actuals
9972 Success : out Boolean)
9974 Actuals : constant List_Id := Parameter_Associations (N);
9975 Actual : Node_Id := Empty;
9977 Last : Node_Id := Empty;
9978 First_Named : Node_Id := Empty;
9981 Formals_To_Match : Integer := 0;
9982 Actuals_To_Match : Integer := 0;
9984 procedure Chain (A : Node_Id);
9985 -- Add named actual at the proper place in the list, using the
9986 -- Next_Named_Actual link.
9988 function Reporting return Boolean;
9989 -- Determines if an error is to be reported. To report an error, we
9990 -- need Report to be True, and also we do not report errors caused
9991 -- by calls to init procs that occur within other init procs. Such
9992 -- errors must always be cascaded errors, since if all the types are
9993 -- declared correctly, the compiler will certainly build decent calls!
9999 procedure Chain (A : Node_Id) is
10003 -- Call node points to first actual in list
10005 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
10008 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
10012 Set_Next_Named_Actual (Last, Empty);
10019 function Reporting return Boolean is
10024 elsif not Within_Init_Proc then
10027 elsif Is_Init_Proc (Entity (Name (N))) then
10035 -- Start of processing for Normalize_Actuals
10038 if Is_Access_Type (S) then
10040 -- The name in the call is a function call that returns an access
10041 -- to subprogram. The designated type has the list of formals.
10043 Formal := First_Formal (Designated_Type (S));
10045 Formal := First_Formal (S);
10048 while Present (Formal) loop
10049 Formals_To_Match := Formals_To_Match + 1;
10050 Next_Formal (Formal);
10053 -- Find if there is a named association, and verify that no positional
10054 -- associations appear after named ones.
10056 if Present (Actuals) then
10057 Actual := First (Actuals);
10060 while Present (Actual)
10061 and then Nkind (Actual) /= N_Parameter_Association
10063 Actuals_To_Match := Actuals_To_Match + 1;
10067 if No (Actual) and Actuals_To_Match = Formals_To_Match then
10069 -- Most common case: positional notation, no defaults
10074 elsif Actuals_To_Match > Formals_To_Match then
10076 -- Too many actuals: will not work
10079 if Is_Entity_Name (Name (N)) then
10080 Error_Msg_N ("too many arguments in call to&", Name (N));
10082 Error_Msg_N ("too many arguments in call", N);
10090 First_Named := Actual;
10092 while Present (Actual) loop
10093 if Nkind (Actual) /= N_Parameter_Association then
10095 ("positional parameters not allowed after named ones", Actual);
10100 Actuals_To_Match := Actuals_To_Match + 1;
10106 if Present (Actuals) then
10107 Actual := First (Actuals);
10110 Formal := First_Formal (S);
10111 while Present (Formal) loop
10113 -- Match the formals in order. If the corresponding actual is
10114 -- positional, nothing to do. Else scan the list of named actuals
10115 -- to find the one with the right name.
10117 if Present (Actual)
10118 and then Nkind (Actual) /= N_Parameter_Association
10121 Actuals_To_Match := Actuals_To_Match - 1;
10122 Formals_To_Match := Formals_To_Match - 1;
10125 -- For named parameters, search the list of actuals to find
10126 -- one that matches the next formal name.
10128 Actual := First_Named;
10130 while Present (Actual) loop
10131 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10134 Actuals_To_Match := Actuals_To_Match - 1;
10135 Formals_To_Match := Formals_To_Match - 1;
10143 if Ekind (Formal) /= E_In_Parameter
10144 or else No (Default_Value (Formal))
10147 if (Comes_From_Source (S)
10148 or else Sloc (S) = Standard_Location)
10149 and then Is_Overloadable (S)
10153 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10155 (Nkind (Parent (N)) = N_Function_Call
10157 Nkind (Parent (N)) = N_Parameter_Association))
10158 and then Ekind (S) /= E_Function
10160 Set_Etype (N, Etype (S));
10162 Error_Msg_Name_1 := Chars (S);
10163 Error_Msg_Sloc := Sloc (S);
10165 ("missing argument for parameter & " &
10166 "in call to % declared #", N, Formal);
10169 elsif Is_Overloadable (S) then
10170 Error_Msg_Name_1 := Chars (S);
10172 -- Point to type derivation that generated the
10175 Error_Msg_Sloc := Sloc (Parent (S));
10178 ("missing argument for parameter & " &
10179 "in call to % (inherited) #", N, Formal);
10183 ("missing argument for parameter &", N, Formal);
10191 Formals_To_Match := Formals_To_Match - 1;
10196 Next_Formal (Formal);
10199 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10206 -- Find some superfluous named actual that did not get
10207 -- attached to the list of associations.
10209 Actual := First (Actuals);
10210 while Present (Actual) loop
10211 if Nkind (Actual) = N_Parameter_Association
10212 and then Actual /= Last
10213 and then No (Next_Named_Actual (Actual))
10215 Error_Msg_N ("unmatched actual & in call",
10216 Selector_Name (Actual));
10227 end Normalize_Actuals;
10229 --------------------------------
10230 -- Note_Possible_Modification --
10231 --------------------------------
10233 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10234 Modification_Comes_From_Source : constant Boolean :=
10235 Comes_From_Source (Parent (N));
10241 -- Loop to find referenced entity, if there is one
10248 if Is_Entity_Name (Exp) then
10249 Ent := Entity (Exp);
10251 -- If the entity is missing, it is an undeclared identifier,
10252 -- and there is nothing to annotate.
10258 elsif Nkind (Exp) = N_Explicit_Dereference then
10260 P : constant Node_Id := Prefix (Exp);
10263 if Nkind (P) = N_Selected_Component
10265 Entry_Formal (Entity (Selector_Name (P))))
10267 -- Case of a reference to an entry formal
10269 Ent := Entry_Formal (Entity (Selector_Name (P)));
10271 elsif Nkind (P) = N_Identifier
10272 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10273 and then Present (Expression (Parent (Entity (P))))
10274 and then Nkind (Expression (Parent (Entity (P))))
10277 -- Case of a reference to a value on which side effects have
10280 Exp := Prefix (Expression (Parent (Entity (P))));
10289 elsif Nkind (Exp) = N_Type_Conversion
10290 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10292 Exp := Expression (Exp);
10295 elsif Nkind (Exp) = N_Slice
10296 or else Nkind (Exp) = N_Indexed_Component
10297 or else Nkind (Exp) = N_Selected_Component
10299 Exp := Prefix (Exp);
10306 -- Now look for entity being referenced
10308 if Present (Ent) then
10309 if Is_Object (Ent) then
10310 if Comes_From_Source (Exp)
10311 or else Modification_Comes_From_Source
10313 -- Give warning if pragma unmodified given and we are
10314 -- sure this is a modification.
10316 if Has_Pragma_Unmodified (Ent) and then Sure then
10317 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10320 Set_Never_Set_In_Source (Ent, False);
10323 Set_Is_True_Constant (Ent, False);
10324 Set_Current_Value (Ent, Empty);
10325 Set_Is_Known_Null (Ent, False);
10327 if not Can_Never_Be_Null (Ent) then
10328 Set_Is_Known_Non_Null (Ent, False);
10331 -- Follow renaming chain
10333 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10334 and then Present (Renamed_Object (Ent))
10336 Exp := Renamed_Object (Ent);
10340 -- Generate a reference only if the assignment comes from
10341 -- source. This excludes, for example, calls to a dispatching
10342 -- assignment operation when the left-hand side is tagged.
10344 if Modification_Comes_From_Source then
10345 Generate_Reference (Ent, Exp, 'm');
10347 -- If the target of the assignment is the bound variable
10348 -- in an iterator, indicate that the corresponding array
10349 -- or container is also modified.
10351 if Ada_Version >= Ada_2012
10353 Nkind (Parent (Ent)) = N_Iterator_Specification
10356 Domain : constant Node_Id := Name (Parent (Ent));
10359 -- TBD : in the full version of the construct, the
10360 -- domain of iteration can be given by an expression.
10362 if Is_Entity_Name (Domain) then
10363 Generate_Reference (Entity (Domain), Exp, 'm');
10364 Set_Is_True_Constant (Entity (Domain), False);
10365 Set_Never_Set_In_Source (Entity (Domain), False);
10371 Check_Nested_Access (Ent);
10376 -- If we are sure this is a modification from source, and we know
10377 -- this modifies a constant, then give an appropriate warning.
10379 if Overlays_Constant (Ent)
10380 and then Modification_Comes_From_Source
10384 A : constant Node_Id := Address_Clause (Ent);
10386 if Present (A) then
10388 Exp : constant Node_Id := Expression (A);
10390 if Nkind (Exp) = N_Attribute_Reference
10391 and then Attribute_Name (Exp) = Name_Address
10392 and then Is_Entity_Name (Prefix (Exp))
10394 Error_Msg_Sloc := Sloc (A);
10396 ("constant& may be modified via address clause#?",
10397 N, Entity (Prefix (Exp)));
10407 end Note_Possible_Modification;
10409 -------------------------
10410 -- Object_Access_Level --
10411 -------------------------
10413 function Object_Access_Level (Obj : Node_Id) return Uint is
10416 -- Returns the static accessibility level of the view denoted by Obj. Note
10417 -- that the value returned is the result of a call to Scope_Depth. Only
10418 -- scope depths associated with dynamic scopes can actually be returned.
10419 -- Since only relative levels matter for accessibility checking, the fact
10420 -- that the distance between successive levels of accessibility is not
10421 -- always one is immaterial (invariant: if level(E2) is deeper than
10422 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10424 function Reference_To (Obj : Node_Id) return Node_Id;
10425 -- An explicit dereference is created when removing side-effects from
10426 -- expressions for constraint checking purposes. In this case a local
10427 -- access type is created for it. The correct access level is that of
10428 -- the original source node. We detect this case by noting that the
10429 -- prefix of the dereference is created by an object declaration whose
10430 -- initial expression is a reference.
10436 function Reference_To (Obj : Node_Id) return Node_Id is
10437 Pref : constant Node_Id := Prefix (Obj);
10439 if Is_Entity_Name (Pref)
10440 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10441 and then Present (Expression (Parent (Entity (Pref))))
10442 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10444 return (Prefix (Expression (Parent (Entity (Pref)))));
10450 -- Start of processing for Object_Access_Level
10453 if Is_Entity_Name (Obj) then
10456 if Is_Prival (E) then
10457 E := Prival_Link (E);
10460 -- If E is a type then it denotes a current instance. For this case
10461 -- we add one to the normal accessibility level of the type to ensure
10462 -- that current instances are treated as always being deeper than
10463 -- than the level of any visible named access type (see 3.10.2(21)).
10465 if Is_Type (E) then
10466 return Type_Access_Level (E) + 1;
10468 elsif Present (Renamed_Object (E)) then
10469 return Object_Access_Level (Renamed_Object (E));
10471 -- Similarly, if E is a component of the current instance of a
10472 -- protected type, any instance of it is assumed to be at a deeper
10473 -- level than the type. For a protected object (whose type is an
10474 -- anonymous protected type) its components are at the same level
10475 -- as the type itself.
10477 elsif not Is_Overloadable (E)
10478 and then Ekind (Scope (E)) = E_Protected_Type
10479 and then Comes_From_Source (Scope (E))
10481 return Type_Access_Level (Scope (E)) + 1;
10484 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10487 elsif Nkind (Obj) = N_Selected_Component then
10488 if Is_Access_Type (Etype (Prefix (Obj))) then
10489 return Type_Access_Level (Etype (Prefix (Obj)));
10491 return Object_Access_Level (Prefix (Obj));
10494 elsif Nkind (Obj) = N_Indexed_Component then
10495 if Is_Access_Type (Etype (Prefix (Obj))) then
10496 return Type_Access_Level (Etype (Prefix (Obj)));
10498 return Object_Access_Level (Prefix (Obj));
10501 elsif Nkind (Obj) = N_Explicit_Dereference then
10503 -- If the prefix is a selected access discriminant then we make a
10504 -- recursive call on the prefix, which will in turn check the level
10505 -- of the prefix object of the selected discriminant.
10507 if Nkind (Prefix (Obj)) = N_Selected_Component
10508 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10510 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10512 return Object_Access_Level (Prefix (Obj));
10514 elsif not (Comes_From_Source (Obj)) then
10516 Ref : constant Node_Id := Reference_To (Obj);
10518 if Present (Ref) then
10519 return Object_Access_Level (Ref);
10521 return Type_Access_Level (Etype (Prefix (Obj)));
10526 return Type_Access_Level (Etype (Prefix (Obj)));
10529 elsif Nkind (Obj) = N_Type_Conversion
10530 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10532 return Object_Access_Level (Expression (Obj));
10534 elsif Nkind (Obj) = N_Function_Call then
10536 -- Function results are objects, so we get either the access level of
10537 -- the function or, in the case of an indirect call, the level of the
10538 -- access-to-subprogram type. (This code is used for Ada 95, but it
10539 -- looks wrong, because it seems that we should be checking the level
10540 -- of the call itself, even for Ada 95. However, using the Ada 2005
10541 -- version of the code causes regressions in several tests that are
10542 -- compiled with -gnat95. ???)
10544 if Ada_Version < Ada_2005 then
10545 if Is_Entity_Name (Name (Obj)) then
10546 return Subprogram_Access_Level (Entity (Name (Obj)));
10548 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10551 -- For Ada 2005, the level of the result object of a function call is
10552 -- defined to be the level of the call's innermost enclosing master.
10553 -- We determine that by querying the depth of the innermost enclosing
10557 Return_Master_Scope_Depth_Of_Call : declare
10559 function Innermost_Master_Scope_Depth
10560 (N : Node_Id) return Uint;
10561 -- Returns the scope depth of the given node's innermost
10562 -- enclosing dynamic scope (effectively the accessibility
10563 -- level of the innermost enclosing master).
10565 ----------------------------------
10566 -- Innermost_Master_Scope_Depth --
10567 ----------------------------------
10569 function Innermost_Master_Scope_Depth
10570 (N : Node_Id) return Uint
10572 Node_Par : Node_Id := Parent (N);
10575 -- Locate the nearest enclosing node (by traversing Parents)
10576 -- that Defining_Entity can be applied to, and return the
10577 -- depth of that entity's nearest enclosing dynamic scope.
10579 while Present (Node_Par) loop
10580 case Nkind (Node_Par) is
10581 when N_Component_Declaration |
10582 N_Entry_Declaration |
10583 N_Formal_Object_Declaration |
10584 N_Formal_Type_Declaration |
10585 N_Full_Type_Declaration |
10586 N_Incomplete_Type_Declaration |
10587 N_Loop_Parameter_Specification |
10588 N_Object_Declaration |
10589 N_Protected_Type_Declaration |
10590 N_Private_Extension_Declaration |
10591 N_Private_Type_Declaration |
10592 N_Subtype_Declaration |
10593 N_Function_Specification |
10594 N_Procedure_Specification |
10595 N_Task_Type_Declaration |
10597 N_Generic_Instantiation |
10599 N_Implicit_Label_Declaration |
10600 N_Package_Declaration |
10601 N_Single_Task_Declaration |
10602 N_Subprogram_Declaration |
10603 N_Generic_Declaration |
10604 N_Renaming_Declaration |
10605 N_Block_Statement |
10606 N_Formal_Subprogram_Declaration |
10607 N_Abstract_Subprogram_Declaration |
10609 N_Exception_Declaration |
10610 N_Formal_Package_Declaration |
10611 N_Number_Declaration |
10612 N_Package_Specification |
10613 N_Parameter_Specification |
10614 N_Single_Protected_Declaration |
10618 (Nearest_Dynamic_Scope
10619 (Defining_Entity (Node_Par)));
10625 Node_Par := Parent (Node_Par);
10628 pragma Assert (False);
10630 -- Should never reach the following return
10632 return Scope_Depth (Current_Scope) + 1;
10633 end Innermost_Master_Scope_Depth;
10635 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10638 return Innermost_Master_Scope_Depth (Obj);
10639 end Return_Master_Scope_Depth_Of_Call;
10642 -- For convenience we handle qualified expressions, even though
10643 -- they aren't technically object names.
10645 elsif Nkind (Obj) = N_Qualified_Expression then
10646 return Object_Access_Level (Expression (Obj));
10648 -- Otherwise return the scope level of Standard.
10649 -- (If there are cases that fall through
10650 -- to this point they will be treated as
10651 -- having global accessibility for now. ???)
10654 return Scope_Depth (Standard_Standard);
10656 end Object_Access_Level;
10658 --------------------------------------
10659 -- Original_Corresponding_Operation --
10660 --------------------------------------
10662 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10664 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10667 -- If S is an inherited primitive S2 the original corresponding
10668 -- operation of S is the original corresponding operation of S2
10670 if Present (Alias (S))
10671 and then Find_Dispatching_Type (Alias (S)) /= Typ
10673 return Original_Corresponding_Operation (Alias (S));
10675 -- If S overrides an inherited subprogram S2 the original corresponding
10676 -- operation of S is the original corresponding operation of S2
10678 elsif Present (Overridden_Operation (S)) then
10679 return Original_Corresponding_Operation (Overridden_Operation (S));
10681 -- otherwise it is S itself
10686 end Original_Corresponding_Operation;
10688 -----------------------
10689 -- Private_Component --
10690 -----------------------
10692 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10693 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10695 function Trace_Components
10697 Check : Boolean) return Entity_Id;
10698 -- Recursive function that does the work, and checks against circular
10699 -- definition for each subcomponent type.
10701 ----------------------
10702 -- Trace_Components --
10703 ----------------------
10705 function Trace_Components
10707 Check : Boolean) return Entity_Id
10709 Btype : constant Entity_Id := Base_Type (T);
10710 Component : Entity_Id;
10712 Candidate : Entity_Id := Empty;
10715 if Check and then Btype = Ancestor then
10716 Error_Msg_N ("circular type definition", Type_Id);
10720 if Is_Private_Type (Btype)
10721 and then not Is_Generic_Type (Btype)
10723 if Present (Full_View (Btype))
10724 and then Is_Record_Type (Full_View (Btype))
10725 and then not Is_Frozen (Btype)
10727 -- To indicate that the ancestor depends on a private type, the
10728 -- current Btype is sufficient. However, to check for circular
10729 -- definition we must recurse on the full view.
10731 Candidate := Trace_Components (Full_View (Btype), True);
10733 if Candidate = Any_Type then
10743 elsif Is_Array_Type (Btype) then
10744 return Trace_Components (Component_Type (Btype), True);
10746 elsif Is_Record_Type (Btype) then
10747 Component := First_Entity (Btype);
10748 while Present (Component) loop
10750 -- Skip anonymous types generated by constrained components
10752 if not Is_Type (Component) then
10753 P := Trace_Components (Etype (Component), True);
10755 if Present (P) then
10756 if P = Any_Type then
10764 Next_Entity (Component);
10772 end Trace_Components;
10774 -- Start of processing for Private_Component
10777 return Trace_Components (Type_Id, False);
10778 end Private_Component;
10780 ---------------------------
10781 -- Primitive_Names_Match --
10782 ---------------------------
10784 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10786 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10787 -- Given an internal name, returns the corresponding non-internal name
10789 ------------------------
10790 -- Non_Internal_Name --
10791 ------------------------
10793 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10795 Get_Name_String (Chars (E));
10796 Name_Len := Name_Len - 1;
10798 end Non_Internal_Name;
10800 -- Start of processing for Primitive_Names_Match
10803 pragma Assert (Present (E1) and then Present (E2));
10805 return Chars (E1) = Chars (E2)
10807 (not Is_Internal_Name (Chars (E1))
10808 and then Is_Internal_Name (Chars (E2))
10809 and then Non_Internal_Name (E2) = Chars (E1))
10811 (not Is_Internal_Name (Chars (E2))
10812 and then Is_Internal_Name (Chars (E1))
10813 and then Non_Internal_Name (E1) = Chars (E2))
10815 (Is_Predefined_Dispatching_Operation (E1)
10816 and then Is_Predefined_Dispatching_Operation (E2)
10817 and then Same_TSS (E1, E2))
10819 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10820 end Primitive_Names_Match;
10822 -----------------------
10823 -- Process_End_Label --
10824 -----------------------
10826 procedure Process_End_Label
10835 Label_Ref : Boolean;
10836 -- Set True if reference to end label itself is required
10839 -- Gets set to the operator symbol or identifier that references the
10840 -- entity Ent. For the child unit case, this is the identifier from the
10841 -- designator. For other cases, this is simply Endl.
10843 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10844 -- N is an identifier node that appears as a parent unit reference in
10845 -- the case where Ent is a child unit. This procedure generates an
10846 -- appropriate cross-reference entry. E is the corresponding entity.
10848 -------------------------
10849 -- Generate_Parent_Ref --
10850 -------------------------
10852 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10854 -- If names do not match, something weird, skip reference
10856 if Chars (E) = Chars (N) then
10858 -- Generate the reference. We do NOT consider this as a reference
10859 -- for unreferenced symbol purposes.
10861 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10863 if Style_Check then
10864 Style.Check_Identifier (N, E);
10867 end Generate_Parent_Ref;
10869 -- Start of processing for Process_End_Label
10872 -- If no node, ignore. This happens in some error situations, and
10873 -- also for some internally generated structures where no end label
10874 -- references are required in any case.
10880 -- Nothing to do if no End_Label, happens for internally generated
10881 -- constructs where we don't want an end label reference anyway. Also
10882 -- nothing to do if Endl is a string literal, which means there was
10883 -- some prior error (bad operator symbol)
10885 Endl := End_Label (N);
10887 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10891 -- Reference node is not in extended main source unit
10893 if not In_Extended_Main_Source_Unit (N) then
10895 -- Generally we do not collect references except for the extended
10896 -- main source unit. The one exception is the 'e' entry for a
10897 -- package spec, where it is useful for a client to have the
10898 -- ending information to define scopes.
10904 Label_Ref := False;
10906 -- For this case, we can ignore any parent references, but we
10907 -- need the package name itself for the 'e' entry.
10909 if Nkind (Endl) = N_Designator then
10910 Endl := Identifier (Endl);
10914 -- Reference is in extended main source unit
10919 -- For designator, generate references for the parent entries
10921 if Nkind (Endl) = N_Designator then
10923 -- Generate references for the prefix if the END line comes from
10924 -- source (otherwise we do not need these references) We climb the
10925 -- scope stack to find the expected entities.
10927 if Comes_From_Source (Endl) then
10928 Nam := Name (Endl);
10929 Scop := Current_Scope;
10930 while Nkind (Nam) = N_Selected_Component loop
10931 Scop := Scope (Scop);
10932 exit when No (Scop);
10933 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10934 Nam := Prefix (Nam);
10937 if Present (Scop) then
10938 Generate_Parent_Ref (Nam, Scope (Scop));
10942 Endl := Identifier (Endl);
10946 -- If the end label is not for the given entity, then either we have
10947 -- some previous error, or this is a generic instantiation for which
10948 -- we do not need to make a cross-reference in this case anyway. In
10949 -- either case we simply ignore the call.
10951 if Chars (Ent) /= Chars (Endl) then
10955 -- If label was really there, then generate a normal reference and then
10956 -- adjust the location in the end label to point past the name (which
10957 -- should almost always be the semicolon).
10959 Loc := Sloc (Endl);
10961 if Comes_From_Source (Endl) then
10963 -- If a label reference is required, then do the style check and
10964 -- generate an l-type cross-reference entry for the label
10967 if Style_Check then
10968 Style.Check_Identifier (Endl, Ent);
10971 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10974 -- Set the location to point past the label (normally this will
10975 -- mean the semicolon immediately following the label). This is
10976 -- done for the sake of the 'e' or 't' entry generated below.
10978 Get_Decoded_Name_String (Chars (Endl));
10979 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10982 -- In SPARK mode, no missing label is allowed for packages and
10983 -- subprogram bodies. Detect those cases by testing whether
10984 -- Process_End_Label was called for a body (Typ = 't') or a package.
10986 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
10987 and then (Typ = 't' or else Ekind (Ent) = E_Package)
10989 Error_Msg_Node_1 := Endl;
10990 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
10994 -- Now generate the e/t reference
10996 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10998 -- Restore Sloc, in case modified above, since we have an identifier
10999 -- and the normal Sloc should be left set in the tree.
11001 Set_Sloc (Endl, Loc);
11002 end Process_End_Label;
11004 ------------------------------------
11005 -- References_Generic_Formal_Type --
11006 ------------------------------------
11008 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
11010 function Process (N : Node_Id) return Traverse_Result;
11011 -- Process one node in search for generic formal type
11017 function Process (N : Node_Id) return Traverse_Result is
11019 if Nkind (N) in N_Has_Entity then
11021 E : constant Entity_Id := Entity (N);
11023 if Present (E) then
11024 if Is_Generic_Type (E) then
11026 elsif Present (Etype (E))
11027 and then Is_Generic_Type (Etype (E))
11038 function Traverse is new Traverse_Func (Process);
11039 -- Traverse tree to look for generic type
11042 if Inside_A_Generic then
11043 return Traverse (N) = Abandon;
11047 end References_Generic_Formal_Type;
11049 --------------------
11050 -- Remove_Homonym --
11051 --------------------
11053 procedure Remove_Homonym (E : Entity_Id) is
11054 Prev : Entity_Id := Empty;
11058 if E = Current_Entity (E) then
11059 if Present (Homonym (E)) then
11060 Set_Current_Entity (Homonym (E));
11062 Set_Name_Entity_Id (Chars (E), Empty);
11065 H := Current_Entity (E);
11066 while Present (H) and then H /= E loop
11071 Set_Homonym (Prev, Homonym (E));
11073 end Remove_Homonym;
11075 ---------------------
11076 -- Rep_To_Pos_Flag --
11077 ---------------------
11079 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
11081 return New_Occurrence_Of
11082 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
11083 end Rep_To_Pos_Flag;
11085 --------------------
11086 -- Require_Entity --
11087 --------------------
11089 procedure Require_Entity (N : Node_Id) is
11091 if Is_Entity_Name (N) and then No (Entity (N)) then
11092 if Total_Errors_Detected /= 0 then
11093 Set_Entity (N, Any_Id);
11095 raise Program_Error;
11098 end Require_Entity;
11100 ------------------------------
11101 -- Requires_Transient_Scope --
11102 ------------------------------
11104 -- A transient scope is required when variable-sized temporaries are
11105 -- allocated in the primary or secondary stack, or when finalization
11106 -- actions must be generated before the next instruction.
11108 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11109 Typ : constant Entity_Id := Underlying_Type (Id);
11111 -- Start of processing for Requires_Transient_Scope
11114 -- This is a private type which is not completed yet. This can only
11115 -- happen in a default expression (of a formal parameter or of a
11116 -- record component). Do not expand transient scope in this case
11121 -- Do not expand transient scope for non-existent procedure return
11123 elsif Typ = Standard_Void_Type then
11126 -- Elementary types do not require a transient scope
11128 elsif Is_Elementary_Type (Typ) then
11131 -- Generally, indefinite subtypes require a transient scope, since the
11132 -- back end cannot generate temporaries, since this is not a valid type
11133 -- for declaring an object. It might be possible to relax this in the
11134 -- future, e.g. by declaring the maximum possible space for the type.
11136 elsif Is_Indefinite_Subtype (Typ) then
11139 -- Functions returning tagged types may dispatch on result so their
11140 -- returned value is allocated on the secondary stack. Controlled
11141 -- type temporaries need finalization.
11143 elsif Is_Tagged_Type (Typ)
11144 or else Has_Controlled_Component (Typ)
11146 return not Is_Value_Type (Typ);
11150 elsif Is_Record_Type (Typ) then
11154 Comp := First_Entity (Typ);
11155 while Present (Comp) loop
11156 if Ekind (Comp) = E_Component
11157 and then Requires_Transient_Scope (Etype (Comp))
11161 Next_Entity (Comp);
11168 -- String literal types never require transient scope
11170 elsif Ekind (Typ) = E_String_Literal_Subtype then
11173 -- Array type. Note that we already know that this is a constrained
11174 -- array, since unconstrained arrays will fail the indefinite test.
11176 elsif Is_Array_Type (Typ) then
11178 -- If component type requires a transient scope, the array does too
11180 if Requires_Transient_Scope (Component_Type (Typ)) then
11183 -- Otherwise, we only need a transient scope if the size depends on
11184 -- the value of one or more discriminants.
11187 return Size_Depends_On_Discriminant (Typ);
11190 -- All other cases do not require a transient scope
11195 end Requires_Transient_Scope;
11197 --------------------------
11198 -- Reset_Analyzed_Flags --
11199 --------------------------
11201 procedure Reset_Analyzed_Flags (N : Node_Id) is
11203 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11204 -- Function used to reset Analyzed flags in tree. Note that we do
11205 -- not reset Analyzed flags in entities, since there is no need to
11206 -- reanalyze entities, and indeed, it is wrong to do so, since it
11207 -- can result in generating auxiliary stuff more than once.
11209 --------------------
11210 -- Clear_Analyzed --
11211 --------------------
11213 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11215 if not Has_Extension (N) then
11216 Set_Analyzed (N, False);
11220 end Clear_Analyzed;
11222 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11224 -- Start of processing for Reset_Analyzed_Flags
11227 Reset_Analyzed (N);
11228 end Reset_Analyzed_Flags;
11230 ---------------------------
11231 -- Safe_To_Capture_Value --
11232 ---------------------------
11234 function Safe_To_Capture_Value
11237 Cond : Boolean := False) return Boolean
11240 -- The only entities for which we track constant values are variables
11241 -- which are not renamings, constants, out parameters, and in out
11242 -- parameters, so check if we have this case.
11244 -- Note: it may seem odd to track constant values for constants, but in
11245 -- fact this routine is used for other purposes than simply capturing
11246 -- the value. In particular, the setting of Known[_Non]_Null.
11248 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11250 Ekind (Ent) = E_Constant
11252 Ekind (Ent) = E_Out_Parameter
11254 Ekind (Ent) = E_In_Out_Parameter
11258 -- For conditionals, we also allow loop parameters and all formals,
11259 -- including in parameters.
11263 (Ekind (Ent) = E_Loop_Parameter
11265 Ekind (Ent) = E_In_Parameter)
11269 -- For all other cases, not just unsafe, but impossible to capture
11270 -- Current_Value, since the above are the only entities which have
11271 -- Current_Value fields.
11277 -- Skip if volatile or aliased, since funny things might be going on in
11278 -- these cases which we cannot necessarily track. Also skip any variable
11279 -- for which an address clause is given, or whose address is taken. Also
11280 -- never capture value of library level variables (an attempt to do so
11281 -- can occur in the case of package elaboration code).
11283 if Treat_As_Volatile (Ent)
11284 or else Is_Aliased (Ent)
11285 or else Present (Address_Clause (Ent))
11286 or else Address_Taken (Ent)
11287 or else (Is_Library_Level_Entity (Ent)
11288 and then Ekind (Ent) = E_Variable)
11293 -- OK, all above conditions are met. We also require that the scope of
11294 -- the reference be the same as the scope of the entity, not counting
11295 -- packages and blocks and loops.
11298 E_Scope : constant Entity_Id := Scope (Ent);
11299 R_Scope : Entity_Id;
11302 R_Scope := Current_Scope;
11303 while R_Scope /= Standard_Standard loop
11304 exit when R_Scope = E_Scope;
11306 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11309 R_Scope := Scope (R_Scope);
11314 -- We also require that the reference does not appear in a context
11315 -- where it is not sure to be executed (i.e. a conditional context
11316 -- or an exception handler). We skip this if Cond is True, since the
11317 -- capturing of values from conditional tests handles this ok.
11331 while Present (P) loop
11332 if Nkind (P) = N_If_Statement
11333 or else Nkind (P) = N_Case_Statement
11334 or else (Nkind (P) in N_Short_Circuit
11335 and then Desc = Right_Opnd (P))
11336 or else (Nkind (P) = N_Conditional_Expression
11337 and then Desc /= First (Expressions (P)))
11338 or else Nkind (P) = N_Exception_Handler
11339 or else Nkind (P) = N_Selective_Accept
11340 or else Nkind (P) = N_Conditional_Entry_Call
11341 or else Nkind (P) = N_Timed_Entry_Call
11342 or else Nkind (P) = N_Asynchronous_Select
11352 -- OK, looks safe to set value
11355 end Safe_To_Capture_Value;
11361 function Same_Name (N1, N2 : Node_Id) return Boolean is
11362 K1 : constant Node_Kind := Nkind (N1);
11363 K2 : constant Node_Kind := Nkind (N2);
11366 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11367 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11369 return Chars (N1) = Chars (N2);
11371 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11372 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11374 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11375 and then Same_Name (Prefix (N1), Prefix (N2));
11386 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11387 N1 : constant Node_Id := Original_Node (Node1);
11388 N2 : constant Node_Id := Original_Node (Node2);
11389 -- We do the tests on original nodes, since we are most interested
11390 -- in the original source, not any expansion that got in the way.
11392 K1 : constant Node_Kind := Nkind (N1);
11393 K2 : constant Node_Kind := Nkind (N2);
11396 -- First case, both are entities with same entity
11398 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11400 EN1 : constant Entity_Id := Entity (N1);
11401 EN2 : constant Entity_Id := Entity (N2);
11403 if Present (EN1) and then Present (EN2)
11404 and then (Ekind_In (EN1, E_Variable, E_Constant)
11405 or else Is_Formal (EN1))
11413 -- Second case, selected component with same selector, same record
11415 if K1 = N_Selected_Component
11416 and then K2 = N_Selected_Component
11417 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11419 return Same_Object (Prefix (N1), Prefix (N2));
11421 -- Third case, indexed component with same subscripts, same array
11423 elsif K1 = N_Indexed_Component
11424 and then K2 = N_Indexed_Component
11425 and then Same_Object (Prefix (N1), Prefix (N2))
11430 E1 := First (Expressions (N1));
11431 E2 := First (Expressions (N2));
11432 while Present (E1) loop
11433 if not Same_Value (E1, E2) then
11444 -- Fourth case, slice of same array with same bounds
11447 and then K2 = N_Slice
11448 and then Nkind (Discrete_Range (N1)) = N_Range
11449 and then Nkind (Discrete_Range (N2)) = N_Range
11450 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11451 Low_Bound (Discrete_Range (N2)))
11452 and then Same_Value (High_Bound (Discrete_Range (N1)),
11453 High_Bound (Discrete_Range (N2)))
11455 return Same_Name (Prefix (N1), Prefix (N2));
11457 -- All other cases, not clearly the same object
11468 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11473 elsif not Is_Constrained (T1)
11474 and then not Is_Constrained (T2)
11475 and then Base_Type (T1) = Base_Type (T2)
11479 -- For now don't bother with case of identical constraints, to be
11480 -- fiddled with later on perhaps (this is only used for optimization
11481 -- purposes, so it is not critical to do a best possible job)
11492 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11494 if Compile_Time_Known_Value (Node1)
11495 and then Compile_Time_Known_Value (Node2)
11496 and then Expr_Value (Node1) = Expr_Value (Node2)
11499 elsif Same_Object (Node1, Node2) then
11510 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11512 if Ada_Version < Ada_2012 then
11515 elsif Is_Entity_Name (N)
11517 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11519 (Nkind (N) = N_Attribute_Reference
11520 and then Attribute_Name (N) = Name_Access)
11523 -- We are only interested in IN OUT parameters of inner calls
11526 or else Nkind (Parent (N)) = N_Function_Call
11527 or else Nkind (Parent (N)) in N_Op
11529 Actuals_In_Call.Increment_Last;
11530 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11535 ------------------------
11536 -- Scope_Is_Transient --
11537 ------------------------
11539 function Scope_Is_Transient return Boolean is
11541 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11542 end Scope_Is_Transient;
11548 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11553 while Scop /= Standard_Standard loop
11554 Scop := Scope (Scop);
11556 if Scop = Scope2 then
11564 --------------------------
11565 -- Scope_Within_Or_Same --
11566 --------------------------
11568 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11573 while Scop /= Standard_Standard loop
11574 if Scop = Scope2 then
11577 Scop := Scope (Scop);
11582 end Scope_Within_Or_Same;
11584 --------------------
11585 -- Set_Convention --
11586 --------------------
11588 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11590 Basic_Set_Convention (E, Val);
11593 and then Is_Access_Subprogram_Type (Base_Type (E))
11594 and then Has_Foreign_Convention (E)
11596 Set_Can_Use_Internal_Rep (E, False);
11598 end Set_Convention;
11600 ------------------------
11601 -- Set_Current_Entity --
11602 ------------------------
11604 -- The given entity is to be set as the currently visible definition
11605 -- of its associated name (i.e. the Node_Id associated with its name).
11606 -- All we have to do is to get the name from the identifier, and
11607 -- then set the associated Node_Id to point to the given entity.
11609 procedure Set_Current_Entity (E : Entity_Id) is
11611 Set_Name_Entity_Id (Chars (E), E);
11612 end Set_Current_Entity;
11614 ---------------------------
11615 -- Set_Debug_Info_Needed --
11616 ---------------------------
11618 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11620 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11621 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11622 -- Used to set debug info in a related node if not set already
11624 --------------------------------------
11625 -- Set_Debug_Info_Needed_If_Not_Set --
11626 --------------------------------------
11628 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11631 and then not Needs_Debug_Info (E)
11633 Set_Debug_Info_Needed (E);
11635 -- For a private type, indicate that the full view also needs
11636 -- debug information.
11639 and then Is_Private_Type (E)
11640 and then Present (Full_View (E))
11642 Set_Debug_Info_Needed (Full_View (E));
11645 end Set_Debug_Info_Needed_If_Not_Set;
11647 -- Start of processing for Set_Debug_Info_Needed
11650 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11651 -- indicates that Debug_Info_Needed is never required for the entity.
11654 or else Debug_Info_Off (T)
11659 -- Set flag in entity itself. Note that we will go through the following
11660 -- circuitry even if the flag is already set on T. That's intentional,
11661 -- it makes sure that the flag will be set in subsidiary entities.
11663 Set_Needs_Debug_Info (T);
11665 -- Set flag on subsidiary entities if not set already
11667 if Is_Object (T) then
11668 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11670 elsif Is_Type (T) then
11671 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11673 if Is_Record_Type (T) then
11675 Ent : Entity_Id := First_Entity (T);
11677 while Present (Ent) loop
11678 Set_Debug_Info_Needed_If_Not_Set (Ent);
11683 -- For a class wide subtype, we also need debug information
11684 -- for the equivalent type.
11686 if Ekind (T) = E_Class_Wide_Subtype then
11687 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11690 elsif Is_Array_Type (T) then
11691 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11694 Indx : Node_Id := First_Index (T);
11696 while Present (Indx) loop
11697 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11698 Indx := Next_Index (Indx);
11702 if Is_Packed (T) then
11703 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11706 elsif Is_Access_Type (T) then
11707 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11709 elsif Is_Private_Type (T) then
11710 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11712 elsif Is_Protected_Type (T) then
11713 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11716 end Set_Debug_Info_Needed;
11718 ---------------------------------
11719 -- Set_Entity_With_Style_Check --
11720 ---------------------------------
11722 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11723 Val_Actual : Entity_Id;
11727 Set_Entity (N, Val);
11730 and then not Suppress_Style_Checks (Val)
11731 and then not In_Instance
11733 if Nkind (N) = N_Identifier then
11735 elsif Nkind (N) = N_Expanded_Name then
11736 Nod := Selector_Name (N);
11741 -- A special situation arises for derived operations, where we want
11742 -- to do the check against the parent (since the Sloc of the derived
11743 -- operation points to the derived type declaration itself).
11746 while not Comes_From_Source (Val_Actual)
11747 and then Nkind (Val_Actual) in N_Entity
11748 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11749 or else Is_Subprogram (Val_Actual)
11750 or else Is_Generic_Subprogram (Val_Actual))
11751 and then Present (Alias (Val_Actual))
11753 Val_Actual := Alias (Val_Actual);
11756 -- Renaming declarations for generic actuals do not come from source,
11757 -- and have a different name from that of the entity they rename, so
11758 -- there is no style check to perform here.
11760 if Chars (Nod) = Chars (Val_Actual) then
11761 Style.Check_Identifier (Nod, Val_Actual);
11765 Set_Entity (N, Val);
11766 end Set_Entity_With_Style_Check;
11768 ------------------------
11769 -- Set_Name_Entity_Id --
11770 ------------------------
11772 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11774 Set_Name_Table_Info (Id, Int (Val));
11775 end Set_Name_Entity_Id;
11777 ---------------------
11778 -- Set_Next_Actual --
11779 ---------------------
11781 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11783 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11784 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11786 end Set_Next_Actual;
11788 ----------------------------------
11789 -- Set_Optimize_Alignment_Flags --
11790 ----------------------------------
11792 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11794 if Optimize_Alignment = 'S' then
11795 Set_Optimize_Alignment_Space (E);
11796 elsif Optimize_Alignment = 'T' then
11797 Set_Optimize_Alignment_Time (E);
11799 end Set_Optimize_Alignment_Flags;
11801 -----------------------
11802 -- Set_Public_Status --
11803 -----------------------
11805 procedure Set_Public_Status (Id : Entity_Id) is
11806 S : constant Entity_Id := Current_Scope;
11808 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11809 -- Determines if E is defined within handled statement sequence or
11810 -- an if statement, returns True if so, False otherwise.
11812 ----------------------
11813 -- Within_HSS_Or_If --
11814 ----------------------
11816 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11819 N := Declaration_Node (E);
11826 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11832 end Within_HSS_Or_If;
11834 -- Start of processing for Set_Public_Status
11837 -- Everything in the scope of Standard is public
11839 if S = Standard_Standard then
11840 Set_Is_Public (Id);
11842 -- Entity is definitely not public if enclosing scope is not public
11844 elsif not Is_Public (S) then
11847 -- An object or function declaration that occurs in a handled sequence
11848 -- of statements or within an if statement is the declaration for a
11849 -- temporary object or local subprogram generated by the expander. It
11850 -- never needs to be made public and furthermore, making it public can
11851 -- cause back end problems.
11853 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11854 N_Function_Specification)
11855 and then Within_HSS_Or_If (Id)
11859 -- Entities in public packages or records are public
11861 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11862 Set_Is_Public (Id);
11864 -- The bounds of an entry family declaration can generate object
11865 -- declarations that are visible to the back-end, e.g. in the
11866 -- the declaration of a composite type that contains tasks.
11868 elsif Is_Concurrent_Type (S)
11869 and then not Has_Completion (S)
11870 and then Nkind (Parent (Id)) = N_Object_Declaration
11872 Set_Is_Public (Id);
11874 end Set_Public_Status;
11876 -----------------------------
11877 -- Set_Referenced_Modified --
11878 -----------------------------
11880 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11884 -- Deal with indexed or selected component where prefix is modified
11886 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11887 Pref := Prefix (N);
11889 -- If prefix is access type, then it is the designated object that is
11890 -- being modified, which means we have no entity to set the flag on.
11892 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11895 -- Otherwise chase the prefix
11898 Set_Referenced_Modified (Pref, Out_Param);
11901 -- Otherwise see if we have an entity name (only other case to process)
11903 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11904 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11905 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11907 end Set_Referenced_Modified;
11909 ----------------------------
11910 -- Set_Scope_Is_Transient --
11911 ----------------------------
11913 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11915 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11916 end Set_Scope_Is_Transient;
11918 -------------------
11919 -- Set_Size_Info --
11920 -------------------
11922 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11924 -- We copy Esize, but not RM_Size, since in general RM_Size is
11925 -- subtype specific and does not get inherited by all subtypes.
11927 Set_Esize (T1, Esize (T2));
11928 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11930 if Is_Discrete_Or_Fixed_Point_Type (T1)
11932 Is_Discrete_Or_Fixed_Point_Type (T2)
11934 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11937 Set_Alignment (T1, Alignment (T2));
11940 --------------------
11941 -- Static_Boolean --
11942 --------------------
11944 function Static_Boolean (N : Node_Id) return Uint is
11946 Analyze_And_Resolve (N, Standard_Boolean);
11949 or else Error_Posted (N)
11950 or else Etype (N) = Any_Type
11955 if Is_Static_Expression (N) then
11956 if not Raises_Constraint_Error (N) then
11957 return Expr_Value (N);
11962 elsif Etype (N) = Any_Type then
11966 Flag_Non_Static_Expr
11967 ("static boolean expression required here", N);
11970 end Static_Boolean;
11972 --------------------
11973 -- Static_Integer --
11974 --------------------
11976 function Static_Integer (N : Node_Id) return Uint is
11978 Analyze_And_Resolve (N, Any_Integer);
11981 or else Error_Posted (N)
11982 or else Etype (N) = Any_Type
11987 if Is_Static_Expression (N) then
11988 if not Raises_Constraint_Error (N) then
11989 return Expr_Value (N);
11994 elsif Etype (N) = Any_Type then
11998 Flag_Non_Static_Expr
11999 ("static integer expression required here", N);
12002 end Static_Integer;
12004 --------------------------
12005 -- Statically_Different --
12006 --------------------------
12008 function Statically_Different (E1, E2 : Node_Id) return Boolean is
12009 R1 : constant Node_Id := Get_Referenced_Object (E1);
12010 R2 : constant Node_Id := Get_Referenced_Object (E2);
12012 return Is_Entity_Name (R1)
12013 and then Is_Entity_Name (R2)
12014 and then Entity (R1) /= Entity (R2)
12015 and then not Is_Formal (Entity (R1))
12016 and then not Is_Formal (Entity (R2));
12017 end Statically_Different;
12019 -----------------------------
12020 -- Subprogram_Access_Level --
12021 -----------------------------
12023 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
12025 if Present (Alias (Subp)) then
12026 return Subprogram_Access_Level (Alias (Subp));
12028 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
12030 end Subprogram_Access_Level;
12036 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
12038 if Debug_Flag_W then
12039 for J in 0 .. Scope_Stack.Last loop
12044 Write_Name (Chars (E));
12045 Write_Str (" from ");
12046 Write_Location (Sloc (N));
12051 -----------------------
12052 -- Transfer_Entities --
12053 -----------------------
12055 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
12056 Ent : Entity_Id := First_Entity (From);
12063 if (Last_Entity (To)) = Empty then
12064 Set_First_Entity (To, Ent);
12066 Set_Next_Entity (Last_Entity (To), Ent);
12069 Set_Last_Entity (To, Last_Entity (From));
12071 while Present (Ent) loop
12072 Set_Scope (Ent, To);
12074 if not Is_Public (Ent) then
12075 Set_Public_Status (Ent);
12078 and then Ekind (Ent) = E_Record_Subtype
12081 -- The components of the propagated Itype must be public
12087 Comp := First_Entity (Ent);
12088 while Present (Comp) loop
12089 Set_Is_Public (Comp);
12090 Next_Entity (Comp);
12099 Set_First_Entity (From, Empty);
12100 Set_Last_Entity (From, Empty);
12101 end Transfer_Entities;
12103 -----------------------
12104 -- Type_Access_Level --
12105 -----------------------
12107 function Type_Access_Level (Typ : Entity_Id) return Uint is
12111 Btyp := Base_Type (Typ);
12113 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12114 -- simply use the level where the type is declared. This is true for
12115 -- stand-alone object declarations, and for anonymous access types
12116 -- associated with components the level is the same as that of the
12117 -- enclosing composite type. However, special treatment is needed for
12118 -- the cases of access parameters, return objects of an anonymous access
12119 -- type, and, in Ada 95, access discriminants of limited types.
12121 if Ekind (Btyp) in Access_Kind then
12122 if Ekind (Btyp) = E_Anonymous_Access_Type then
12124 -- If the type is a nonlocal anonymous access type (such as for
12125 -- an access parameter) we treat it as being declared at the
12126 -- library level to ensure that names such as X.all'access don't
12127 -- fail static accessibility checks.
12129 if not Is_Local_Anonymous_Access (Typ) then
12130 return Scope_Depth (Standard_Standard);
12132 -- If this is a return object, the accessibility level is that of
12133 -- the result subtype of the enclosing function. The test here is
12134 -- little complicated, because we have to account for extended
12135 -- return statements that have been rewritten as blocks, in which
12136 -- case we have to find and the Is_Return_Object attribute of the
12137 -- itype's associated object. It would be nice to find a way to
12138 -- simplify this test, but it doesn't seem worthwhile to add a new
12139 -- flag just for purposes of this test. ???
12141 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12144 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12145 N_Object_Declaration
12146 and then Is_Return_Object
12147 (Defining_Identifier
12148 (Associated_Node_For_Itype (Btyp))))
12154 Scop := Scope (Scope (Btyp));
12155 while Present (Scop) loop
12156 exit when Ekind (Scop) = E_Function;
12157 Scop := Scope (Scop);
12160 -- Treat the return object's type as having the level of the
12161 -- function's result subtype (as per RM05-6.5(5.3/2)).
12163 return Type_Access_Level (Etype (Scop));
12168 Btyp := Root_Type (Btyp);
12170 -- The accessibility level of anonymous access types associated with
12171 -- discriminants is that of the current instance of the type, and
12172 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12174 -- AI-402: access discriminants have accessibility based on the
12175 -- object rather than the type in Ada 2005, so the above paragraph
12178 -- ??? Needs completion with rules from AI-416
12180 if Ada_Version <= Ada_95
12181 and then Ekind (Typ) = E_Anonymous_Access_Type
12182 and then Present (Associated_Node_For_Itype (Typ))
12183 and then Nkind (Associated_Node_For_Itype (Typ)) =
12184 N_Discriminant_Specification
12186 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12190 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12191 end Type_Access_Level;
12193 --------------------------
12194 -- Unit_Declaration_Node --
12195 --------------------------
12197 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12198 N : Node_Id := Parent (Unit_Id);
12201 -- Predefined operators do not have a full function declaration
12203 if Ekind (Unit_Id) = E_Operator then
12207 -- Isn't there some better way to express the following ???
12209 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12210 and then Nkind (N) /= N_Formal_Package_Declaration
12211 and then Nkind (N) /= N_Function_Instantiation
12212 and then Nkind (N) /= N_Generic_Package_Declaration
12213 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12214 and then Nkind (N) /= N_Package_Declaration
12215 and then Nkind (N) /= N_Package_Body
12216 and then Nkind (N) /= N_Package_Instantiation
12217 and then Nkind (N) /= N_Package_Renaming_Declaration
12218 and then Nkind (N) /= N_Procedure_Instantiation
12219 and then Nkind (N) /= N_Protected_Body
12220 and then Nkind (N) /= N_Subprogram_Declaration
12221 and then Nkind (N) /= N_Subprogram_Body
12222 and then Nkind (N) /= N_Subprogram_Body_Stub
12223 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12224 and then Nkind (N) /= N_Task_Body
12225 and then Nkind (N) /= N_Task_Type_Declaration
12226 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12227 and then Nkind (N) not in N_Generic_Renaming_Declaration
12230 pragma Assert (Present (N));
12234 end Unit_Declaration_Node;
12236 ---------------------
12237 -- Unit_Is_Visible --
12238 ---------------------
12240 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12241 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12242 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12244 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12245 -- For a child unit, check whether unit appears in a with_clause
12248 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12249 -- Scan the context clause of one compilation unit looking for a
12250 -- with_clause for the unit in question.
12252 ----------------------------
12253 -- Unit_In_Parent_Context --
12254 ----------------------------
12256 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12258 if Unit_In_Context (Par_Unit) then
12261 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12262 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12267 end Unit_In_Parent_Context;
12269 ---------------------
12270 -- Unit_In_Context --
12271 ---------------------
12273 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12277 Clause := First (Context_Items (Comp_Unit));
12278 while Present (Clause) loop
12279 if Nkind (Clause) = N_With_Clause then
12280 if Library_Unit (Clause) = U then
12283 -- The with_clause may denote a renaming of the unit we are
12284 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12287 Renamed_Entity (Entity (Name (Clause))) =
12288 Defining_Entity (Unit (U))
12298 end Unit_In_Context;
12300 -- Start of processing for Unit_Is_Visible
12303 -- The currrent unit is directly visible.
12308 elsif Unit_In_Context (Curr) then
12311 -- If the current unit is a body, check the context of the spec.
12313 elsif Nkind (Unit (Curr)) = N_Package_Body
12315 (Nkind (Unit (Curr)) = N_Subprogram_Body
12316 and then not Acts_As_Spec (Unit (Curr)))
12318 if Unit_In_Context (Library_Unit (Curr)) then
12323 -- If the spec is a child unit, examine the parents.
12325 if Is_Child_Unit (Curr_Entity) then
12326 if Nkind (Unit (Curr)) in N_Unit_Body then
12328 Unit_In_Parent_Context
12329 (Parent_Spec (Unit (Library_Unit (Curr))));
12331 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12337 end Unit_Is_Visible;
12339 ------------------------------
12340 -- Universal_Interpretation --
12341 ------------------------------
12343 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12344 Index : Interp_Index;
12348 -- The argument may be a formal parameter of an operator or subprogram
12349 -- with multiple interpretations, or else an expression for an actual.
12351 if Nkind (Opnd) = N_Defining_Identifier
12352 or else not Is_Overloaded (Opnd)
12354 if Etype (Opnd) = Universal_Integer
12355 or else Etype (Opnd) = Universal_Real
12357 return Etype (Opnd);
12363 Get_First_Interp (Opnd, Index, It);
12364 while Present (It.Typ) loop
12365 if It.Typ = Universal_Integer
12366 or else It.Typ = Universal_Real
12371 Get_Next_Interp (Index, It);
12376 end Universal_Interpretation;
12382 function Unqualify (Expr : Node_Id) return Node_Id is
12384 -- Recurse to handle unlikely case of multiple levels of qualification
12386 if Nkind (Expr) = N_Qualified_Expression then
12387 return Unqualify (Expression (Expr));
12389 -- Normal case, not a qualified expression
12396 -----------------------
12397 -- Visible_Ancestors --
12398 -----------------------
12400 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12406 pragma Assert (Is_Record_Type (Typ)
12407 and then Is_Tagged_Type (Typ));
12409 -- Collect all the parents and progenitors of Typ. If the full-view of
12410 -- private parents and progenitors is available then it is used to
12411 -- generate the list of visible ancestors; otherwise their partial
12412 -- view is added to the resulting list.
12417 Use_Full_View => True);
12421 Ifaces_List => List_2,
12422 Exclude_Parents => True,
12423 Use_Full_View => True);
12425 -- Join the two lists. Avoid duplications because an interface may
12426 -- simultaneously be parent and progenitor of a type.
12428 Elmt := First_Elmt (List_2);
12429 while Present (Elmt) loop
12430 Append_Unique_Elmt (Node (Elmt), List_1);
12435 end Visible_Ancestors;
12437 ----------------------
12438 -- Within_Init_Proc --
12439 ----------------------
12441 function Within_Init_Proc return Boolean is
12445 S := Current_Scope;
12446 while not Is_Overloadable (S) loop
12447 if S = Standard_Standard then
12454 return Is_Init_Proc (S);
12455 end Within_Init_Proc;
12461 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12462 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12463 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12465 function Has_One_Matching_Field return Boolean;
12466 -- Determines if Expec_Type is a record type with a single component or
12467 -- discriminant whose type matches the found type or is one dimensional
12468 -- array whose component type matches the found type.
12470 ----------------------------
12471 -- Has_One_Matching_Field --
12472 ----------------------------
12474 function Has_One_Matching_Field return Boolean is
12478 if Is_Array_Type (Expec_Type)
12479 and then Number_Dimensions (Expec_Type) = 1
12481 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12485 elsif not Is_Record_Type (Expec_Type) then
12489 E := First_Entity (Expec_Type);
12494 elsif (Ekind (E) /= E_Discriminant
12495 and then Ekind (E) /= E_Component)
12496 or else (Chars (E) = Name_uTag
12497 or else Chars (E) = Name_uParent)
12506 if not Covers (Etype (E), Found_Type) then
12509 elsif Present (Next_Entity (E)) then
12516 end Has_One_Matching_Field;
12518 -- Start of processing for Wrong_Type
12521 -- Don't output message if either type is Any_Type, or if a message
12522 -- has already been posted for this node. We need to do the latter
12523 -- check explicitly (it is ordinarily done in Errout), because we
12524 -- are using ! to force the output of the error messages.
12526 if Expec_Type = Any_Type
12527 or else Found_Type = Any_Type
12528 or else Error_Posted (Expr)
12532 -- In an instance, there is an ongoing problem with completion of
12533 -- type derived from private types. Their structure is what Gigi
12534 -- expects, but the Etype is the parent type rather than the
12535 -- derived private type itself. Do not flag error in this case. The
12536 -- private completion is an entity without a parent, like an Itype.
12537 -- Similarly, full and partial views may be incorrect in the instance.
12538 -- There is no simple way to insure that it is consistent ???
12540 elsif In_Instance then
12541 if Etype (Etype (Expr)) = Etype (Expected_Type)
12543 (Has_Private_Declaration (Expected_Type)
12544 or else Has_Private_Declaration (Etype (Expr)))
12545 and then No (Parent (Expected_Type))
12551 -- An interesting special check. If the expression is parenthesized
12552 -- and its type corresponds to the type of the sole component of the
12553 -- expected record type, or to the component type of the expected one
12554 -- dimensional array type, then assume we have a bad aggregate attempt.
12556 if Nkind (Expr) in N_Subexpr
12557 and then Paren_Count (Expr) /= 0
12558 and then Has_One_Matching_Field
12560 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12562 -- Another special check, if we are looking for a pool-specific access
12563 -- type and we found an E_Access_Attribute_Type, then we have the case
12564 -- of an Access attribute being used in a context which needs a pool-
12565 -- specific type, which is never allowed. The one extra check we make
12566 -- is that the expected designated type covers the Found_Type.
12568 elsif Is_Access_Type (Expec_Type)
12569 and then Ekind (Found_Type) = E_Access_Attribute_Type
12570 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12571 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12573 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12575 Error_Msg_N -- CODEFIX
12576 ("result must be general access type!", Expr);
12577 Error_Msg_NE -- CODEFIX
12578 ("add ALL to }!", Expr, Expec_Type);
12580 -- Another special check, if the expected type is an integer type,
12581 -- but the expression is of type System.Address, and the parent is
12582 -- an addition or subtraction operation whose left operand is the
12583 -- expression in question and whose right operand is of an integral
12584 -- type, then this is an attempt at address arithmetic, so give
12585 -- appropriate message.
12587 elsif Is_Integer_Type (Expec_Type)
12588 and then Is_RTE (Found_Type, RE_Address)
12589 and then (Nkind (Parent (Expr)) = N_Op_Add
12591 Nkind (Parent (Expr)) = N_Op_Subtract)
12592 and then Expr = Left_Opnd (Parent (Expr))
12593 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12596 ("address arithmetic not predefined in package System",
12599 ("\possible missing with/use of System.Storage_Elements",
12603 -- If the expected type is an anonymous access type, as for access
12604 -- parameters and discriminants, the error is on the designated types.
12606 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12607 if Comes_From_Source (Expec_Type) then
12608 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12611 ("expected an access type with designated}",
12612 Expr, Designated_Type (Expec_Type));
12615 if Is_Access_Type (Found_Type)
12616 and then not Comes_From_Source (Found_Type)
12619 ("\\found an access type with designated}!",
12620 Expr, Designated_Type (Found_Type));
12622 if From_With_Type (Found_Type) then
12623 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12624 Error_Msg_Qual_Level := 99;
12625 Error_Msg_NE -- CODEFIX
12626 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12627 Error_Msg_Qual_Level := 0;
12629 Error_Msg_NE ("found}!", Expr, Found_Type);
12633 -- Normal case of one type found, some other type expected
12636 -- If the names of the two types are the same, see if some number
12637 -- of levels of qualification will help. Don't try more than three
12638 -- levels, and if we get to standard, it's no use (and probably
12639 -- represents an error in the compiler) Also do not bother with
12640 -- internal scope names.
12643 Expec_Scope : Entity_Id;
12644 Found_Scope : Entity_Id;
12647 Expec_Scope := Expec_Type;
12648 Found_Scope := Found_Type;
12650 for Levels in Int range 0 .. 3 loop
12651 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12652 Error_Msg_Qual_Level := Levels;
12656 Expec_Scope := Scope (Expec_Scope);
12657 Found_Scope := Scope (Found_Scope);
12659 exit when Expec_Scope = Standard_Standard
12660 or else Found_Scope = Standard_Standard
12661 or else not Comes_From_Source (Expec_Scope)
12662 or else not Comes_From_Source (Found_Scope);
12666 if Is_Record_Type (Expec_Type)
12667 and then Present (Corresponding_Remote_Type (Expec_Type))
12669 Error_Msg_NE ("expected}!", Expr,
12670 Corresponding_Remote_Type (Expec_Type));
12672 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12675 if Is_Entity_Name (Expr)
12676 and then Is_Package_Or_Generic_Package (Entity (Expr))
12678 Error_Msg_N ("\\found package name!", Expr);
12680 elsif Is_Entity_Name (Expr)
12682 (Ekind (Entity (Expr)) = E_Procedure
12684 Ekind (Entity (Expr)) = E_Generic_Procedure)
12686 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12688 ("found procedure name, possibly missing Access attribute!",
12692 ("\\found procedure name instead of function!", Expr);
12695 elsif Nkind (Expr) = N_Function_Call
12696 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12697 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12698 and then No (Parameter_Associations (Expr))
12701 ("found function name, possibly missing Access attribute!",
12704 -- Catch common error: a prefix or infix operator which is not
12705 -- directly visible because the type isn't.
12707 elsif Nkind (Expr) in N_Op
12708 and then Is_Overloaded (Expr)
12709 and then not Is_Immediately_Visible (Expec_Type)
12710 and then not Is_Potentially_Use_Visible (Expec_Type)
12711 and then not In_Use (Expec_Type)
12712 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12715 ("operator of the type is not directly visible!", Expr);
12717 elsif Ekind (Found_Type) = E_Void
12718 and then Present (Parent (Found_Type))
12719 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12721 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12724 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12727 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12728 -- of the same modular type, and (M1 and M2) = 0 was intended.
12730 if Expec_Type = Standard_Boolean
12731 and then Is_Modular_Integer_Type (Found_Type)
12732 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12733 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12736 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12737 L : constant Node_Id := Left_Opnd (Op);
12738 R : constant Node_Id := Right_Opnd (Op);
12740 -- The case for the message is when the left operand of the
12741 -- comparison is the same modular type, or when it is an
12742 -- integer literal (or other universal integer expression),
12743 -- which would have been typed as the modular type if the
12744 -- parens had been there.
12746 if (Etype (L) = Found_Type
12748 Etype (L) = Universal_Integer)
12749 and then Is_Integer_Type (Etype (R))
12752 ("\\possible missing parens for modular operation", Expr);
12757 -- Reset error message qualification indication
12759 Error_Msg_Qual_Level := 0;