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 Indx_Type : Entity_Id;
510 Deaccessed_T : 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 (Deaccessed_T);
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 (Deaccessed_T));
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 Deaccessed_T := Designated_Type (T);
644 if Ekind (Deaccessed_T) = E_Array_Subtype then
645 Id := First_Index (Deaccessed_T);
646 while Present (Id) loop
647 Indx_Type := Underlying_Type (Etype (Id));
649 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
651 Denotes_Discriminant (Type_High_Bound (Indx_Type))
653 Remove_Side_Effects (P);
655 Build_Component_Subtype
656 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
662 elsif Is_Composite_Type (Deaccessed_T)
663 and then Has_Discriminants (Deaccessed_T)
664 and then not Has_Unknown_Discriminants (Deaccessed_T)
666 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
667 while Present (D) loop
668 if Denotes_Discriminant (Node (D)) then
669 Remove_Side_Effects (P);
671 Build_Component_Subtype (
672 Build_Actual_Record_Constraint, Loc, Base_Type (T));
679 -- If none of the above, the actual and nominal subtypes are the same
682 end Build_Actual_Subtype_Of_Component;
684 -----------------------------
685 -- Build_Component_Subtype --
686 -----------------------------
688 function Build_Component_Subtype
691 T : Entity_Id) return Node_Id
697 -- Unchecked_Union components do not require component subtypes
699 if Is_Unchecked_Union (T) then
703 Subt := Make_Temporary (Loc, 'S');
704 Set_Is_Internal (Subt);
707 Make_Subtype_Declaration (Loc,
708 Defining_Identifier => Subt,
709 Subtype_Indication =>
710 Make_Subtype_Indication (Loc,
711 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
713 Make_Index_Or_Discriminant_Constraint (Loc,
716 Mark_Rewrite_Insertion (Decl);
718 end Build_Component_Subtype;
720 ---------------------------
721 -- Build_Default_Subtype --
722 ---------------------------
724 function Build_Default_Subtype
726 N : Node_Id) return Entity_Id
728 Loc : constant Source_Ptr := Sloc (N);
732 if not Has_Discriminants (T) or else Is_Constrained (T) then
736 Disc := First_Discriminant (T);
738 if No (Discriminant_Default_Value (Disc)) then
743 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
744 Constraints : constant List_Id := New_List;
748 while Present (Disc) loop
749 Append_To (Constraints,
750 New_Copy_Tree (Discriminant_Default_Value (Disc)));
751 Next_Discriminant (Disc);
755 Make_Subtype_Declaration (Loc,
756 Defining_Identifier => Act,
757 Subtype_Indication =>
758 Make_Subtype_Indication (Loc,
759 Subtype_Mark => New_Occurrence_Of (T, Loc),
761 Make_Index_Or_Discriminant_Constraint (Loc,
762 Constraints => Constraints)));
764 Insert_Action (N, Decl);
768 end Build_Default_Subtype;
770 --------------------------------------------
771 -- Build_Discriminal_Subtype_Of_Component --
772 --------------------------------------------
774 function Build_Discriminal_Subtype_Of_Component
775 (T : Entity_Id) return Node_Id
777 Loc : constant Source_Ptr := Sloc (T);
781 function Build_Discriminal_Array_Constraint return List_Id;
782 -- If one or more of the bounds of the component depends on
783 -- discriminants, build actual constraint using the discriminants
786 function Build_Discriminal_Record_Constraint return List_Id;
787 -- Similar to previous one, for discriminated components constrained
788 -- by the discriminant of the enclosing object.
790 ----------------------------------------
791 -- Build_Discriminal_Array_Constraint --
792 ----------------------------------------
794 function Build_Discriminal_Array_Constraint return List_Id is
795 Constraints : constant List_Id := New_List;
803 Indx := First_Index (T);
804 while Present (Indx) loop
805 Old_Lo := Type_Low_Bound (Etype (Indx));
806 Old_Hi := Type_High_Bound (Etype (Indx));
808 if Denotes_Discriminant (Old_Lo) then
809 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
812 Lo := New_Copy_Tree (Old_Lo);
815 if Denotes_Discriminant (Old_Hi) then
816 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
819 Hi := New_Copy_Tree (Old_Hi);
822 Append (Make_Range (Loc, Lo, Hi), Constraints);
827 end Build_Discriminal_Array_Constraint;
829 -----------------------------------------
830 -- Build_Discriminal_Record_Constraint --
831 -----------------------------------------
833 function Build_Discriminal_Record_Constraint return List_Id is
834 Constraints : constant List_Id := New_List;
839 D := First_Elmt (Discriminant_Constraint (T));
840 while Present (D) loop
841 if Denotes_Discriminant (Node (D)) then
843 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
846 D_Val := New_Copy_Tree (Node (D));
849 Append (D_Val, Constraints);
854 end Build_Discriminal_Record_Constraint;
856 -- Start of processing for Build_Discriminal_Subtype_Of_Component
859 if Ekind (T) = E_Array_Subtype then
860 Id := First_Index (T);
861 while Present (Id) loop
862 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
863 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
865 return Build_Component_Subtype
866 (Build_Discriminal_Array_Constraint, Loc, T);
872 elsif Ekind (T) = E_Record_Subtype
873 and then Has_Discriminants (T)
874 and then not Has_Unknown_Discriminants (T)
876 D := First_Elmt (Discriminant_Constraint (T));
877 while Present (D) loop
878 if Denotes_Discriminant (Node (D)) then
879 return Build_Component_Subtype
880 (Build_Discriminal_Record_Constraint, Loc, T);
887 -- If none of the above, the actual and nominal subtypes are the same
890 end Build_Discriminal_Subtype_Of_Component;
892 ------------------------------
893 -- Build_Elaboration_Entity --
894 ------------------------------
896 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
897 Loc : constant Source_Ptr := Sloc (N);
899 Elab_Ent : Entity_Id;
901 procedure Set_Package_Name (Ent : Entity_Id);
902 -- Given an entity, sets the fully qualified name of the entity in
903 -- Name_Buffer, with components separated by double underscores. This
904 -- is a recursive routine that climbs the scope chain to Standard.
906 ----------------------
907 -- Set_Package_Name --
908 ----------------------
910 procedure Set_Package_Name (Ent : Entity_Id) is
912 if Scope (Ent) /= Standard_Standard then
913 Set_Package_Name (Scope (Ent));
916 Nam : constant String := Get_Name_String (Chars (Ent));
918 Name_Buffer (Name_Len + 1) := '_';
919 Name_Buffer (Name_Len + 2) := '_';
920 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
921 Name_Len := Name_Len + Nam'Length + 2;
925 Get_Name_String (Chars (Ent));
927 end Set_Package_Name;
929 -- Start of processing for Build_Elaboration_Entity
932 -- Ignore if already constructed
934 if Present (Elaboration_Entity (Spec_Id)) then
938 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
939 -- name with dots replaced by double underscore. We have to manually
940 -- construct this name, since it will be elaborated in the outer scope,
941 -- and thus will not have the unit name automatically prepended.
943 Set_Package_Name (Spec_Id);
947 Name_Buffer (Name_Len + 1) := '_';
948 Name_Buffer (Name_Len + 2) := 'E';
949 Name_Len := Name_Len + 2;
951 -- Create elaboration flag
954 Make_Defining_Identifier (Loc, Chars => Name_Find);
955 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
958 Make_Object_Declaration (Loc,
959 Defining_Identifier => Elab_Ent,
961 New_Occurrence_Of (Standard_Boolean, Loc),
963 New_Occurrence_Of (Standard_False, Loc));
965 Push_Scope (Standard_Standard);
966 Add_Global_Declaration (Decl);
969 -- Reset True_Constant indication, since we will indeed assign a value
970 -- to the variable in the binder main. We also kill the Current_Value
971 -- and Last_Assignment fields for the same reason.
973 Set_Is_True_Constant (Elab_Ent, False);
974 Set_Current_Value (Elab_Ent, Empty);
975 Set_Last_Assignment (Elab_Ent, Empty);
977 -- We do not want any further qualification of the name (if we did
978 -- not do this, we would pick up the name of the generic package
979 -- in the case of a library level generic instantiation).
981 Set_Has_Qualified_Name (Elab_Ent);
982 Set_Has_Fully_Qualified_Name (Elab_Ent);
983 end Build_Elaboration_Entity;
985 -----------------------------------
986 -- Cannot_Raise_Constraint_Error --
987 -----------------------------------
989 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
991 if Compile_Time_Known_Value (Expr) then
994 elsif Do_Range_Check (Expr) then
997 elsif Raises_Constraint_Error (Expr) then
1001 case Nkind (Expr) is
1002 when N_Identifier =>
1005 when N_Expanded_Name =>
1008 when N_Selected_Component =>
1009 return not Do_Discriminant_Check (Expr);
1011 when N_Attribute_Reference =>
1012 if Do_Overflow_Check (Expr) then
1015 elsif No (Expressions (Expr)) then
1023 N := First (Expressions (Expr));
1024 while Present (N) loop
1025 if Cannot_Raise_Constraint_Error (N) then
1036 when N_Type_Conversion =>
1037 if Do_Overflow_Check (Expr)
1038 or else Do_Length_Check (Expr)
1039 or else Do_Tag_Check (Expr)
1044 Cannot_Raise_Constraint_Error (Expression (Expr));
1047 when N_Unchecked_Type_Conversion =>
1048 return Cannot_Raise_Constraint_Error (Expression (Expr));
1051 if Do_Overflow_Check (Expr) then
1055 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1062 if Do_Division_Check (Expr)
1063 or else Do_Overflow_Check (Expr)
1068 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1070 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1089 N_Op_Shift_Right_Arithmetic |
1093 if Do_Overflow_Check (Expr) then
1097 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1099 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1106 end Cannot_Raise_Constraint_Error;
1108 ---------------------------------------
1109 -- Check_Later_Vs_Basic_Declarations --
1110 ---------------------------------------
1112 procedure Check_Later_Vs_Basic_Declarations
1114 During_Parsing : Boolean)
1116 Body_Sloc : Source_Ptr;
1119 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1120 -- Return whether Decl is considered as a declarative item.
1121 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1122 -- When During_Parsing is False, the semantics of SPARK is followed.
1124 -------------------------------
1125 -- Is_Later_Declarative_Item --
1126 -------------------------------
1128 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1130 if Nkind (Decl) in N_Later_Decl_Item then
1133 elsif Nkind (Decl) = N_Pragma then
1136 elsif During_Parsing then
1139 -- In SPARK, a package declaration is not considered as a later
1140 -- declarative item.
1142 elsif Nkind (Decl) = N_Package_Declaration then
1145 -- In SPARK, a renaming is considered as a later declarative item
1147 elsif Nkind (Decl) in N_Renaming_Declaration then
1153 end Is_Later_Declarative_Item;
1155 -- Start of Check_Later_Vs_Basic_Declarations
1158 Decl := First (Decls);
1160 -- Loop through sequence of basic declarative items
1162 Outer : while Present (Decl) loop
1163 if Nkind (Decl) /= N_Subprogram_Body
1164 and then Nkind (Decl) /= N_Package_Body
1165 and then Nkind (Decl) /= N_Task_Body
1166 and then Nkind (Decl) not in N_Body_Stub
1170 -- Once a body is encountered, we only allow later declarative
1171 -- items. The inner loop checks the rest of the list.
1174 Body_Sloc := Sloc (Decl);
1176 Inner : while Present (Decl) loop
1177 if not Is_Later_Declarative_Item (Decl) then
1178 if During_Parsing then
1179 if Ada_Version = Ada_83 then
1180 Error_Msg_Sloc := Body_Sloc;
1182 ("(Ada 83) decl cannot appear after body#", Decl);
1185 Error_Msg_Sloc := Body_Sloc;
1186 Check_SPARK_Restriction
1187 ("decl cannot appear after body#", Decl);
1195 end Check_Later_Vs_Basic_Declarations;
1197 -----------------------------------------
1198 -- Check_Dynamically_Tagged_Expression --
1199 -----------------------------------------
1201 procedure Check_Dynamically_Tagged_Expression
1204 Related_Nod : Node_Id)
1207 pragma Assert (Is_Tagged_Type (Typ));
1209 -- In order to avoid spurious errors when analyzing the expanded code,
1210 -- this check is done only for nodes that come from source and for
1211 -- actuals of generic instantiations.
1213 if (Comes_From_Source (Related_Nod)
1214 or else In_Generic_Actual (Expr))
1215 and then (Is_Class_Wide_Type (Etype (Expr))
1216 or else Is_Dynamically_Tagged (Expr))
1217 and then Is_Tagged_Type (Typ)
1218 and then not Is_Class_Wide_Type (Typ)
1220 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1222 end Check_Dynamically_Tagged_Expression;
1224 --------------------------
1225 -- Check_Fully_Declared --
1226 --------------------------
1228 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1230 if Ekind (T) = E_Incomplete_Type then
1232 -- Ada 2005 (AI-50217): If the type is available through a limited
1233 -- with_clause, verify that its full view has been analyzed.
1235 if From_With_Type (T)
1236 and then Present (Non_Limited_View (T))
1237 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1239 -- The non-limited view is fully declared
1244 ("premature usage of incomplete}", N, First_Subtype (T));
1247 -- Need comments for these tests ???
1249 elsif Has_Private_Component (T)
1250 and then not Is_Generic_Type (Root_Type (T))
1251 and then not In_Spec_Expression
1253 -- Special case: if T is the anonymous type created for a single
1254 -- task or protected object, use the name of the source object.
1256 if Is_Concurrent_Type (T)
1257 and then not Comes_From_Source (T)
1258 and then Nkind (N) = N_Object_Declaration
1260 Error_Msg_NE ("type of& has incomplete component", N,
1261 Defining_Identifier (N));
1265 ("premature usage of incomplete}", N, First_Subtype (T));
1268 end Check_Fully_Declared;
1270 -------------------------
1271 -- Check_Nested_Access --
1272 -------------------------
1274 procedure Check_Nested_Access (Ent : Entity_Id) is
1275 Scop : constant Entity_Id := Current_Scope;
1276 Current_Subp : Entity_Id;
1277 Enclosing : Entity_Id;
1280 -- Currently only enabled for VM back-ends for efficiency, should we
1281 -- enable it more systematically ???
1283 -- Check for Is_Imported needs commenting below ???
1285 if VM_Target /= No_VM
1286 and then (Ekind (Ent) = E_Variable
1288 Ekind (Ent) = E_Constant
1290 Ekind (Ent) = E_Loop_Parameter)
1291 and then Scope (Ent) /= Empty
1292 and then not Is_Library_Level_Entity (Ent)
1293 and then not Is_Imported (Ent)
1295 if Is_Subprogram (Scop)
1296 or else Is_Generic_Subprogram (Scop)
1297 or else Is_Entry (Scop)
1299 Current_Subp := Scop;
1301 Current_Subp := Current_Subprogram;
1304 Enclosing := Enclosing_Subprogram (Ent);
1306 if Enclosing /= Empty
1307 and then Enclosing /= Current_Subp
1309 Set_Has_Up_Level_Access (Ent, True);
1312 end Check_Nested_Access;
1314 ----------------------------
1315 -- Check_Order_Dependence --
1316 ----------------------------
1318 procedure Check_Order_Dependence is
1323 if Ada_Version < Ada_2012 then
1327 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1328 -- calls within a construct have been collected. If one of them is
1329 -- writable and overlaps with another one, evaluation of the enclosing
1330 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1331 -- treated as a warning for now.
1333 for J in 1 .. Actuals_In_Call.Last loop
1334 if Actuals_In_Call.Table (J).Is_Writable then
1335 Act1 := Actuals_In_Call.Table (J).Act;
1337 if Nkind (Act1) = N_Attribute_Reference then
1338 Act1 := Prefix (Act1);
1341 for K in 1 .. Actuals_In_Call.Last loop
1343 Act2 := Actuals_In_Call.Table (K).Act;
1345 if Nkind (Act2) = N_Attribute_Reference then
1346 Act2 := Prefix (Act2);
1349 if Actuals_In_Call.Table (K).Is_Writable
1356 elsif Denotes_Same_Object (Act1, Act2)
1357 and then Parent (Act1) /= Parent (Act2)
1360 ("result may differ if evaluated "
1361 & "after other actual in expression?", Act1);
1368 -- Remove checked actuals from table
1370 Actuals_In_Call.Set_Last (0);
1371 end Check_Order_Dependence;
1373 ------------------------------------------
1374 -- Check_Potentially_Blocking_Operation --
1375 ------------------------------------------
1377 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1381 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1382 -- When pragma Detect_Blocking is active, the run time will raise
1383 -- Program_Error. Here we only issue a warning, since we generally
1384 -- support the use of potentially blocking operations in the absence
1387 -- Indirect blocking through a subprogram call cannot be diagnosed
1388 -- statically without interprocedural analysis, so we do not attempt
1391 S := Scope (Current_Scope);
1392 while Present (S) and then S /= Standard_Standard loop
1393 if Is_Protected_Type (S) then
1395 ("potentially blocking operation in protected operation?", N);
1401 end Check_Potentially_Blocking_Operation;
1403 ------------------------------
1404 -- Check_Unprotected_Access --
1405 ------------------------------
1407 procedure Check_Unprotected_Access
1411 Cont_Encl_Typ : Entity_Id;
1412 Pref_Encl_Typ : Entity_Id;
1414 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1415 -- Check whether Obj is a private component of a protected object.
1416 -- Return the protected type where the component resides, Empty
1419 function Is_Public_Operation return Boolean;
1420 -- Verify that the enclosing operation is callable from outside the
1421 -- protected object, to minimize false positives.
1423 ------------------------------
1424 -- Enclosing_Protected_Type --
1425 ------------------------------
1427 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1429 if Is_Entity_Name (Obj) then
1431 Ent : Entity_Id := Entity (Obj);
1434 -- The object can be a renaming of a private component, use
1435 -- the original record component.
1437 if Is_Prival (Ent) then
1438 Ent := Prival_Link (Ent);
1441 if Is_Protected_Type (Scope (Ent)) then
1447 -- For indexed and selected components, recursively check the prefix
1449 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1450 return Enclosing_Protected_Type (Prefix (Obj));
1452 -- The object does not denote a protected component
1457 end Enclosing_Protected_Type;
1459 -------------------------
1460 -- Is_Public_Operation --
1461 -------------------------
1463 function Is_Public_Operation return Boolean is
1470 and then S /= Pref_Encl_Typ
1472 if Scope (S) = Pref_Encl_Typ then
1473 E := First_Entity (Pref_Encl_Typ);
1475 and then E /= First_Private_Entity (Pref_Encl_Typ)
1488 end Is_Public_Operation;
1490 -- Start of processing for Check_Unprotected_Access
1493 if Nkind (Expr) = N_Attribute_Reference
1494 and then Attribute_Name (Expr) = Name_Unchecked_Access
1496 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1497 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1499 -- Check whether we are trying to export a protected component to a
1500 -- context with an equal or lower access level.
1502 if Present (Pref_Encl_Typ)
1503 and then No (Cont_Encl_Typ)
1504 and then Is_Public_Operation
1505 and then Scope_Depth (Pref_Encl_Typ) >=
1506 Object_Access_Level (Context)
1509 ("?possible unprotected access to protected data", Expr);
1512 end Check_Unprotected_Access;
1518 procedure Check_VMS (Construct : Node_Id) is
1520 if not OpenVMS_On_Target then
1522 ("this construct is allowed only in Open'V'M'S", Construct);
1526 ------------------------
1527 -- Collect_Interfaces --
1528 ------------------------
1530 procedure Collect_Interfaces
1532 Ifaces_List : out Elist_Id;
1533 Exclude_Parents : Boolean := False;
1534 Use_Full_View : Boolean := True)
1536 procedure Collect (Typ : Entity_Id);
1537 -- Subsidiary subprogram used to traverse the whole list
1538 -- of directly and indirectly implemented interfaces
1544 procedure Collect (Typ : Entity_Id) is
1545 Ancestor : Entity_Id;
1553 -- Handle private types
1556 and then Is_Private_Type (Typ)
1557 and then Present (Full_View (Typ))
1559 Full_T := Full_View (Typ);
1562 -- Include the ancestor if we are generating the whole list of
1563 -- abstract interfaces.
1565 if Etype (Full_T) /= Typ
1567 -- Protect the frontend against wrong sources. For example:
1570 -- type A is tagged null record;
1571 -- type B is new A with private;
1572 -- type C is new A with private;
1574 -- type B is new C with null record;
1575 -- type C is new B with null record;
1578 and then Etype (Full_T) /= T
1580 Ancestor := Etype (Full_T);
1583 if Is_Interface (Ancestor)
1584 and then not Exclude_Parents
1586 Append_Unique_Elmt (Ancestor, Ifaces_List);
1590 -- Traverse the graph of ancestor interfaces
1592 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1593 Id := First (Abstract_Interface_List (Full_T));
1594 while Present (Id) loop
1595 Iface := Etype (Id);
1597 -- Protect against wrong uses. For example:
1598 -- type I is interface;
1599 -- type O is tagged null record;
1600 -- type Wrong is new I and O with null record; -- ERROR
1602 if Is_Interface (Iface) then
1604 and then Etype (T) /= T
1605 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1610 Append_Unique_Elmt (Iface, Ifaces_List);
1619 -- Start of processing for Collect_Interfaces
1622 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1623 Ifaces_List := New_Elmt_List;
1625 end Collect_Interfaces;
1627 ----------------------------------
1628 -- Collect_Interface_Components --
1629 ----------------------------------
1631 procedure Collect_Interface_Components
1632 (Tagged_Type : Entity_Id;
1633 Components_List : out Elist_Id)
1635 procedure Collect (Typ : Entity_Id);
1636 -- Subsidiary subprogram used to climb to the parents
1642 procedure Collect (Typ : Entity_Id) is
1643 Tag_Comp : Entity_Id;
1644 Parent_Typ : Entity_Id;
1647 -- Handle private types
1649 if Present (Full_View (Etype (Typ))) then
1650 Parent_Typ := Full_View (Etype (Typ));
1652 Parent_Typ := Etype (Typ);
1655 if Parent_Typ /= Typ
1657 -- Protect the frontend against wrong sources. For example:
1660 -- type A is tagged null record;
1661 -- type B is new A with private;
1662 -- type C is new A with private;
1664 -- type B is new C with null record;
1665 -- type C is new B with null record;
1668 and then Parent_Typ /= Tagged_Type
1670 Collect (Parent_Typ);
1673 -- Collect the components containing tags of secondary dispatch
1676 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1677 while Present (Tag_Comp) loop
1678 pragma Assert (Present (Related_Type (Tag_Comp)));
1679 Append_Elmt (Tag_Comp, Components_List);
1681 Tag_Comp := Next_Tag_Component (Tag_Comp);
1685 -- Start of processing for Collect_Interface_Components
1688 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1689 and then Is_Tagged_Type (Tagged_Type));
1691 Components_List := New_Elmt_List;
1692 Collect (Tagged_Type);
1693 end Collect_Interface_Components;
1695 -----------------------------
1696 -- Collect_Interfaces_Info --
1697 -----------------------------
1699 procedure Collect_Interfaces_Info
1701 Ifaces_List : out Elist_Id;
1702 Components_List : out Elist_Id;
1703 Tags_List : out Elist_Id)
1705 Comps_List : Elist_Id;
1706 Comp_Elmt : Elmt_Id;
1707 Comp_Iface : Entity_Id;
1708 Iface_Elmt : Elmt_Id;
1711 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1712 -- Search for the secondary tag associated with the interface type
1713 -- Iface that is implemented by T.
1719 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1722 if not Is_CPP_Class (T) then
1723 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1725 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1729 and then Is_Tag (Node (ADT))
1730 and then Related_Type (Node (ADT)) /= Iface
1732 -- Skip secondary dispatch table referencing thunks to user
1733 -- defined primitives covered by this interface.
1735 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1738 -- Skip secondary dispatch tables of Ada types
1740 if not Is_CPP_Class (T) then
1742 -- Skip secondary dispatch table referencing thunks to
1743 -- predefined primitives.
1745 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1748 -- Skip secondary dispatch table referencing user-defined
1749 -- primitives covered by this interface.
1751 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1754 -- Skip secondary dispatch table referencing predefined
1757 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1762 pragma Assert (Is_Tag (Node (ADT)));
1766 -- Start of processing for Collect_Interfaces_Info
1769 Collect_Interfaces (T, Ifaces_List);
1770 Collect_Interface_Components (T, Comps_List);
1772 -- Search for the record component and tag associated with each
1773 -- interface type of T.
1775 Components_List := New_Elmt_List;
1776 Tags_List := New_Elmt_List;
1778 Iface_Elmt := First_Elmt (Ifaces_List);
1779 while Present (Iface_Elmt) loop
1780 Iface := Node (Iface_Elmt);
1782 -- Associate the primary tag component and the primary dispatch table
1783 -- with all the interfaces that are parents of T
1785 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1786 Append_Elmt (First_Tag_Component (T), Components_List);
1787 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1789 -- Otherwise search for the tag component and secondary dispatch
1793 Comp_Elmt := First_Elmt (Comps_List);
1794 while Present (Comp_Elmt) loop
1795 Comp_Iface := Related_Type (Node (Comp_Elmt));
1797 if Comp_Iface = Iface
1798 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1800 Append_Elmt (Node (Comp_Elmt), Components_List);
1801 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1805 Next_Elmt (Comp_Elmt);
1807 pragma Assert (Present (Comp_Elmt));
1810 Next_Elmt (Iface_Elmt);
1812 end Collect_Interfaces_Info;
1814 ---------------------
1815 -- Collect_Parents --
1816 ---------------------
1818 procedure Collect_Parents
1820 List : out Elist_Id;
1821 Use_Full_View : Boolean := True)
1823 Current_Typ : Entity_Id := T;
1824 Parent_Typ : Entity_Id;
1827 List := New_Elmt_List;
1829 -- No action if the if the type has no parents
1831 if T = Etype (T) then
1836 Parent_Typ := Etype (Current_Typ);
1838 if Is_Private_Type (Parent_Typ)
1839 and then Present (Full_View (Parent_Typ))
1840 and then Use_Full_View
1842 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1845 Append_Elmt (Parent_Typ, List);
1847 exit when Parent_Typ = Current_Typ;
1848 Current_Typ := Parent_Typ;
1850 end Collect_Parents;
1852 ----------------------------------
1853 -- Collect_Primitive_Operations --
1854 ----------------------------------
1856 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1857 B_Type : constant Entity_Id := Base_Type (T);
1858 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1859 B_Scope : Entity_Id := Scope (B_Type);
1863 Formal_Derived : Boolean := False;
1866 function Match (E : Entity_Id) return Boolean;
1867 -- True if E's base type is B_Type, or E is of an anonymous access type
1868 -- and the base type of its designated type is B_Type.
1874 function Match (E : Entity_Id) return Boolean is
1875 Etyp : Entity_Id := Etype (E);
1878 if Ekind (Etyp) = E_Anonymous_Access_Type then
1879 Etyp := Designated_Type (Etyp);
1882 return Base_Type (Etyp) = B_Type;
1885 -- Start of processing for Collect_Primitive_Operations
1888 -- For tagged types, the primitive operations are collected as they
1889 -- are declared, and held in an explicit list which is simply returned.
1891 if Is_Tagged_Type (B_Type) then
1892 return Primitive_Operations (B_Type);
1894 -- An untagged generic type that is a derived type inherits the
1895 -- primitive operations of its parent type. Other formal types only
1896 -- have predefined operators, which are not explicitly represented.
1898 elsif Is_Generic_Type (B_Type) then
1899 if Nkind (B_Decl) = N_Formal_Type_Declaration
1900 and then Nkind (Formal_Type_Definition (B_Decl))
1901 = N_Formal_Derived_Type_Definition
1903 Formal_Derived := True;
1905 return New_Elmt_List;
1909 Op_List := New_Elmt_List;
1911 if B_Scope = Standard_Standard then
1912 if B_Type = Standard_String then
1913 Append_Elmt (Standard_Op_Concat, Op_List);
1915 elsif B_Type = Standard_Wide_String then
1916 Append_Elmt (Standard_Op_Concatw, Op_List);
1922 elsif (Is_Package_Or_Generic_Package (B_Scope)
1924 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1926 or else Is_Derived_Type (B_Type)
1928 -- The primitive operations appear after the base type, except
1929 -- if the derivation happens within the private part of B_Scope
1930 -- and the type is a private type, in which case both the type
1931 -- and some primitive operations may appear before the base
1932 -- type, and the list of candidates starts after the type.
1934 if In_Open_Scopes (B_Scope)
1935 and then Scope (T) = B_Scope
1936 and then In_Private_Part (B_Scope)
1938 Id := Next_Entity (T);
1940 Id := Next_Entity (B_Type);
1943 while Present (Id) loop
1945 -- Note that generic formal subprograms are not
1946 -- considered to be primitive operations and thus
1947 -- are never inherited.
1949 if Is_Overloadable (Id)
1950 and then Nkind (Parent (Parent (Id)))
1951 not in N_Formal_Subprogram_Declaration
1959 Formal := First_Formal (Id);
1960 while Present (Formal) loop
1961 if Match (Formal) then
1966 Next_Formal (Formal);
1970 -- For a formal derived type, the only primitives are the
1971 -- ones inherited from the parent type. Operations appearing
1972 -- in the package declaration are not primitive for it.
1975 and then (not Formal_Derived
1976 or else Present (Alias (Id)))
1978 -- In the special case of an equality operator aliased to
1979 -- an overriding dispatching equality belonging to the same
1980 -- type, we don't include it in the list of primitives.
1981 -- This avoids inheriting multiple equality operators when
1982 -- deriving from untagged private types whose full type is
1983 -- tagged, which can otherwise cause ambiguities. Note that
1984 -- this should only happen for this kind of untagged parent
1985 -- type, since normally dispatching operations are inherited
1986 -- using the type's Primitive_Operations list.
1988 if Chars (Id) = Name_Op_Eq
1989 and then Is_Dispatching_Operation (Id)
1990 and then Present (Alias (Id))
1991 and then Present (Overridden_Operation (Alias (Id)))
1992 and then Base_Type (Etype (First_Entity (Id))) =
1993 Base_Type (Etype (First_Entity (Alias (Id))))
1997 -- Include the subprogram in the list of primitives
2000 Append_Elmt (Id, Op_List);
2007 -- For a type declared in System, some of its operations may
2008 -- appear in the target-specific extension to System.
2011 and then B_Scope = RTU_Entity (System)
2012 and then Present_System_Aux
2014 B_Scope := System_Aux_Id;
2015 Id := First_Entity (System_Aux_Id);
2021 end Collect_Primitive_Operations;
2023 -----------------------------------
2024 -- Compile_Time_Constraint_Error --
2025 -----------------------------------
2027 function Compile_Time_Constraint_Error
2030 Ent : Entity_Id := Empty;
2031 Loc : Source_Ptr := No_Location;
2032 Warn : Boolean := False) return Node_Id
2034 Msgc : String (1 .. Msg'Length + 2);
2035 -- Copy of message, with room for possible ? and ! at end
2045 -- A static constraint error in an instance body is not a fatal error.
2046 -- we choose to inhibit the message altogether, because there is no
2047 -- obvious node (for now) on which to post it. On the other hand the
2048 -- offending node must be replaced with a constraint_error in any case.
2050 -- No messages are generated if we already posted an error on this node
2052 if not Error_Posted (N) then
2053 if Loc /= No_Location then
2059 Msgc (1 .. Msg'Length) := Msg;
2062 -- Message is a warning, even in Ada 95 case
2064 if Msg (Msg'Last) = '?' then
2067 -- In Ada 83, all messages are warnings. In the private part and
2068 -- the body of an instance, constraint_checks are only warnings.
2069 -- We also make this a warning if the Warn parameter is set.
2072 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2078 elsif In_Instance_Not_Visible then
2083 -- Otherwise we have a real error message (Ada 95 static case)
2084 -- and we make this an unconditional message. Note that in the
2085 -- warning case we do not make the message unconditional, it seems
2086 -- quite reasonable to delete messages like this (about exceptions
2087 -- that will be raised) in dead code.
2095 -- Should we generate a warning? The answer is not quite yes. The
2096 -- very annoying exception occurs in the case of a short circuit
2097 -- operator where the left operand is static and decisive. Climb
2098 -- parents to see if that is the case we have here. Conditional
2099 -- expressions with decisive conditions are a similar situation.
2107 -- And then with False as left operand
2109 if Nkind (P) = N_And_Then
2110 and then Compile_Time_Known_Value (Left_Opnd (P))
2111 and then Is_False (Expr_Value (Left_Opnd (P)))
2116 -- OR ELSE with True as left operand
2118 elsif Nkind (P) = N_Or_Else
2119 and then Compile_Time_Known_Value (Left_Opnd (P))
2120 and then Is_True (Expr_Value (Left_Opnd (P)))
2125 -- Conditional expression
2127 elsif Nkind (P) = N_Conditional_Expression then
2129 Cond : constant Node_Id := First (Expressions (P));
2130 Texp : constant Node_Id := Next (Cond);
2131 Fexp : constant Node_Id := Next (Texp);
2134 if Compile_Time_Known_Value (Cond) then
2136 -- Condition is True and we are in the right operand
2138 if Is_True (Expr_Value (Cond))
2139 and then OldP = Fexp
2144 -- Condition is False and we are in the left operand
2146 elsif Is_False (Expr_Value (Cond))
2147 and then OldP = Texp
2155 -- Special case for component association in aggregates, where
2156 -- we want to keep climbing up to the parent aggregate.
2158 elsif Nkind (P) = N_Component_Association
2159 and then Nkind (Parent (P)) = N_Aggregate
2163 -- Keep going if within subexpression
2166 exit when Nkind (P) not in N_Subexpr;
2171 if Present (Ent) then
2172 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2174 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2178 if Inside_Init_Proc then
2180 ("\?& will be raised for objects of this type",
2181 N, Standard_Constraint_Error, Eloc);
2184 ("\?& will be raised at run time",
2185 N, Standard_Constraint_Error, Eloc);
2190 ("\static expression fails Constraint_Check", Eloc);
2191 Set_Error_Posted (N);
2197 end Compile_Time_Constraint_Error;
2199 -----------------------
2200 -- Conditional_Delay --
2201 -----------------------
2203 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2205 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2206 Set_Has_Delayed_Freeze (New_Ent);
2208 end Conditional_Delay;
2210 -------------------------
2211 -- Copy_Parameter_List --
2212 -------------------------
2214 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2215 Loc : constant Source_Ptr := Sloc (Subp_Id);
2220 if No (First_Formal (Subp_Id)) then
2224 Formal := First_Formal (Subp_Id);
2225 while Present (Formal) loop
2227 (Make_Parameter_Specification (Loc,
2228 Defining_Identifier =>
2229 Make_Defining_Identifier (Sloc (Formal),
2230 Chars => Chars (Formal)),
2231 In_Present => In_Present (Parent (Formal)),
2232 Out_Present => Out_Present (Parent (Formal)),
2234 New_Reference_To (Etype (Formal), Loc),
2236 New_Copy_Tree (Expression (Parent (Formal)))),
2239 Next_Formal (Formal);
2244 end Copy_Parameter_List;
2246 --------------------
2247 -- Current_Entity --
2248 --------------------
2250 -- The currently visible definition for a given identifier is the
2251 -- one most chained at the start of the visibility chain, i.e. the
2252 -- one that is referenced by the Node_Id value of the name of the
2253 -- given identifier.
2255 function Current_Entity (N : Node_Id) return Entity_Id is
2257 return Get_Name_Entity_Id (Chars (N));
2260 -----------------------------
2261 -- Current_Entity_In_Scope --
2262 -----------------------------
2264 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2266 CS : constant Entity_Id := Current_Scope;
2268 Transient_Case : constant Boolean := Scope_Is_Transient;
2271 E := Get_Name_Entity_Id (Chars (N));
2273 and then Scope (E) /= CS
2274 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2280 end Current_Entity_In_Scope;
2286 function Current_Scope return Entity_Id is
2288 if Scope_Stack.Last = -1 then
2289 return Standard_Standard;
2292 C : constant Entity_Id :=
2293 Scope_Stack.Table (Scope_Stack.Last).Entity;
2298 return Standard_Standard;
2304 ------------------------
2305 -- Current_Subprogram --
2306 ------------------------
2308 function Current_Subprogram return Entity_Id is
2309 Scop : constant Entity_Id := Current_Scope;
2311 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2314 return Enclosing_Subprogram (Scop);
2316 end Current_Subprogram;
2318 ------------------------------
2319 -- Mark_Non_ALFA_Subprogram --
2320 ------------------------------
2322 procedure Mark_Non_ALFA_Subprogram is
2324 -- Isolate marking of the current subprogram body so that the body of
2325 -- Mark_Non_ALFA_Subprogram is small and inlined.
2328 Mark_Non_ALFA_Subprogram_Unconditional;
2330 end Mark_Non_ALFA_Subprogram;
2332 --------------------------------------------
2333 -- Mark_Non_ALFA_Subprogram_Unconditional --
2334 --------------------------------------------
2336 procedure Mark_Non_ALFA_Subprogram_Unconditional is
2337 Cur_Subp : constant Entity_Id := Current_Subprogram;
2340 if Present (Cur_Subp)
2341 and then (Is_Subprogram (Cur_Subp)
2342 or else Is_Generic_Subprogram (Cur_Subp))
2344 -- If the non-ALFA construct is in a precondition or postcondition,
2345 -- then mark the subprogram as not in ALFA. Otherwise, mark the
2346 -- subprogram body as not in ALFA.
2348 -- This comment just says what is done, but not why ??? and it
2349 -- just repeats what is in the spec ???
2351 if In_Pre_Post_Expression then
2352 Set_Is_In_ALFA (Cur_Subp, False);
2354 Set_Body_Is_In_ALFA (Cur_Subp, False);
2357 end Mark_Non_ALFA_Subprogram_Unconditional;
2359 ---------------------
2360 -- Defining_Entity --
2361 ---------------------
2363 function Defining_Entity (N : Node_Id) return Entity_Id is
2364 K : constant Node_Kind := Nkind (N);
2365 Err : Entity_Id := Empty;
2370 N_Subprogram_Declaration |
2371 N_Abstract_Subprogram_Declaration |
2373 N_Package_Declaration |
2374 N_Subprogram_Renaming_Declaration |
2375 N_Subprogram_Body_Stub |
2376 N_Generic_Subprogram_Declaration |
2377 N_Generic_Package_Declaration |
2378 N_Formal_Subprogram_Declaration
2380 return Defining_Entity (Specification (N));
2383 N_Component_Declaration |
2384 N_Defining_Program_Unit_Name |
2385 N_Discriminant_Specification |
2387 N_Entry_Declaration |
2388 N_Entry_Index_Specification |
2389 N_Exception_Declaration |
2390 N_Exception_Renaming_Declaration |
2391 N_Formal_Object_Declaration |
2392 N_Formal_Package_Declaration |
2393 N_Formal_Type_Declaration |
2394 N_Full_Type_Declaration |
2395 N_Implicit_Label_Declaration |
2396 N_Incomplete_Type_Declaration |
2397 N_Loop_Parameter_Specification |
2398 N_Number_Declaration |
2399 N_Object_Declaration |
2400 N_Object_Renaming_Declaration |
2401 N_Package_Body_Stub |
2402 N_Parameter_Specification |
2403 N_Private_Extension_Declaration |
2404 N_Private_Type_Declaration |
2406 N_Protected_Body_Stub |
2407 N_Protected_Type_Declaration |
2408 N_Single_Protected_Declaration |
2409 N_Single_Task_Declaration |
2410 N_Subtype_Declaration |
2413 N_Task_Type_Declaration
2415 return Defining_Identifier (N);
2418 return Defining_Entity (Proper_Body (N));
2421 N_Function_Instantiation |
2422 N_Function_Specification |
2423 N_Generic_Function_Renaming_Declaration |
2424 N_Generic_Package_Renaming_Declaration |
2425 N_Generic_Procedure_Renaming_Declaration |
2427 N_Package_Instantiation |
2428 N_Package_Renaming_Declaration |
2429 N_Package_Specification |
2430 N_Procedure_Instantiation |
2431 N_Procedure_Specification
2434 Nam : constant Node_Id := Defining_Unit_Name (N);
2437 if Nkind (Nam) in N_Entity then
2440 -- For Error, make up a name and attach to declaration
2441 -- so we can continue semantic analysis
2443 elsif Nam = Error then
2444 Err := Make_Temporary (Sloc (N), 'T');
2445 Set_Defining_Unit_Name (N, Err);
2448 -- If not an entity, get defining identifier
2451 return Defining_Identifier (Nam);
2455 when N_Block_Statement =>
2456 return Entity (Identifier (N));
2459 raise Program_Error;
2462 end Defining_Entity;
2464 --------------------------
2465 -- Denotes_Discriminant --
2466 --------------------------
2468 function Denotes_Discriminant
2470 Check_Concurrent : Boolean := False) return Boolean
2474 if not Is_Entity_Name (N)
2475 or else No (Entity (N))
2482 -- If we are checking for a protected type, the discriminant may have
2483 -- been rewritten as the corresponding discriminal of the original type
2484 -- or of the corresponding concurrent record, depending on whether we
2485 -- are in the spec or body of the protected type.
2487 return Ekind (E) = E_Discriminant
2490 and then Ekind (E) = E_In_Parameter
2491 and then Present (Discriminal_Link (E))
2493 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2495 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2497 end Denotes_Discriminant;
2499 -------------------------
2500 -- Denotes_Same_Object --
2501 -------------------------
2503 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2504 Obj1 : Node_Id := A1;
2505 Obj2 : Node_Id := A2;
2507 procedure Check_Renaming (Obj : in out Node_Id);
2508 -- If an object is a renaming, examine renamed object. If it is a
2509 -- dereference of a variable, or an indexed expression with non-constant
2510 -- indexes, no overlap check can be reported.
2512 --------------------
2513 -- Check_Renaming --
2514 --------------------
2516 procedure Check_Renaming (Obj : in out Node_Id) is
2518 if Is_Entity_Name (Obj)
2519 and then Present (Renamed_Entity (Entity (Obj)))
2521 Obj := Renamed_Entity (Entity (Obj));
2522 if Nkind (Obj) = N_Explicit_Dereference
2523 and then Is_Variable (Prefix (Obj))
2527 elsif Nkind (Obj) = N_Indexed_Component then
2532 Indx := First (Expressions (Obj));
2533 while Present (Indx) loop
2534 if not Is_OK_Static_Expression (Indx) then
2546 -- Start of processing for Denotes_Same_Object
2549 Check_Renaming (Obj1);
2550 Check_Renaming (Obj2);
2558 -- If we have entity names, then must be same entity
2560 if Is_Entity_Name (Obj1) then
2561 if Is_Entity_Name (Obj2) then
2562 return Entity (Obj1) = Entity (Obj2);
2567 -- No match if not same node kind
2569 elsif Nkind (Obj1) /= Nkind (Obj2) then
2572 -- For selected components, must have same prefix and selector
2574 elsif Nkind (Obj1) = N_Selected_Component then
2575 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2577 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2579 -- For explicit dereferences, prefixes must be same
2581 elsif Nkind (Obj1) = N_Explicit_Dereference then
2582 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2584 -- For indexed components, prefixes and all subscripts must be the same
2586 elsif Nkind (Obj1) = N_Indexed_Component then
2587 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2593 Indx1 := First (Expressions (Obj1));
2594 Indx2 := First (Expressions (Obj2));
2595 while Present (Indx1) loop
2597 -- Indexes must denote the same static value or same object
2599 if Is_OK_Static_Expression (Indx1) then
2600 if not Is_OK_Static_Expression (Indx2) then
2603 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2607 elsif not Denotes_Same_Object (Indx1, Indx2) then
2621 -- For slices, prefixes must match and bounds must match
2623 elsif Nkind (Obj1) = N_Slice
2624 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2627 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2630 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2631 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2633 -- Check whether bounds are statically identical. There is no
2634 -- attempt to detect partial overlap of slices.
2636 return Denotes_Same_Object (Lo1, Lo2)
2637 and then Denotes_Same_Object (Hi1, Hi2);
2640 -- Literals will appear as indexes. Isn't this where we should check
2641 -- Known_At_Compile_Time at least if we are generating warnings ???
2643 elsif Nkind (Obj1) = N_Integer_Literal then
2644 return Intval (Obj1) = Intval (Obj2);
2649 end Denotes_Same_Object;
2651 -------------------------
2652 -- Denotes_Same_Prefix --
2653 -------------------------
2655 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2658 if Is_Entity_Name (A1) then
2659 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2660 and then not Is_Access_Type (Etype (A1))
2662 return Denotes_Same_Object (A1, Prefix (A2))
2663 or else Denotes_Same_Prefix (A1, Prefix (A2));
2668 elsif Is_Entity_Name (A2) then
2669 return Denotes_Same_Prefix (A2, A1);
2671 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2673 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2676 Root1, Root2 : Node_Id;
2677 Depth1, Depth2 : Int := 0;
2680 Root1 := Prefix (A1);
2681 while not Is_Entity_Name (Root1) loop
2683 (Root1, N_Selected_Component, N_Indexed_Component)
2687 Root1 := Prefix (Root1);
2690 Depth1 := Depth1 + 1;
2693 Root2 := Prefix (A2);
2694 while not Is_Entity_Name (Root2) loop
2696 (Root2, N_Selected_Component, N_Indexed_Component)
2700 Root2 := Prefix (Root2);
2703 Depth2 := Depth2 + 1;
2706 -- If both have the same depth and they do not denote the same
2707 -- object, they are disjoint and not warning is needed.
2709 if Depth1 = Depth2 then
2712 elsif Depth1 > Depth2 then
2713 Root1 := Prefix (A1);
2714 for I in 1 .. Depth1 - Depth2 - 1 loop
2715 Root1 := Prefix (Root1);
2718 return Denotes_Same_Object (Root1, A2);
2721 Root2 := Prefix (A2);
2722 for I in 1 .. Depth2 - Depth1 - 1 loop
2723 Root2 := Prefix (Root2);
2726 return Denotes_Same_Object (A1, Root2);
2733 end Denotes_Same_Prefix;
2735 ----------------------
2736 -- Denotes_Variable --
2737 ----------------------
2739 function Denotes_Variable (N : Node_Id) return Boolean is
2741 return Is_Variable (N) and then Paren_Count (N) = 0;
2742 end Denotes_Variable;
2744 -----------------------------
2745 -- Depends_On_Discriminant --
2746 -----------------------------
2748 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2753 Get_Index_Bounds (N, L, H);
2754 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2755 end Depends_On_Discriminant;
2757 -------------------------
2758 -- Designate_Same_Unit --
2759 -------------------------
2761 function Designate_Same_Unit
2763 Name2 : Node_Id) return Boolean
2765 K1 : constant Node_Kind := Nkind (Name1);
2766 K2 : constant Node_Kind := Nkind (Name2);
2768 function Prefix_Node (N : Node_Id) return Node_Id;
2769 -- Returns the parent unit name node of a defining program unit name
2770 -- or the prefix if N is a selected component or an expanded name.
2772 function Select_Node (N : Node_Id) return Node_Id;
2773 -- Returns the defining identifier node of a defining program unit
2774 -- name or the selector node if N is a selected component or an
2781 function Prefix_Node (N : Node_Id) return Node_Id is
2783 if Nkind (N) = N_Defining_Program_Unit_Name then
2795 function Select_Node (N : Node_Id) return Node_Id is
2797 if Nkind (N) = N_Defining_Program_Unit_Name then
2798 return Defining_Identifier (N);
2801 return Selector_Name (N);
2805 -- Start of processing for Designate_Next_Unit
2808 if (K1 = N_Identifier or else
2809 K1 = N_Defining_Identifier)
2811 (K2 = N_Identifier or else
2812 K2 = N_Defining_Identifier)
2814 return Chars (Name1) = Chars (Name2);
2817 (K1 = N_Expanded_Name or else
2818 K1 = N_Selected_Component or else
2819 K1 = N_Defining_Program_Unit_Name)
2821 (K2 = N_Expanded_Name or else
2822 K2 = N_Selected_Component or else
2823 K2 = N_Defining_Program_Unit_Name)
2826 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2828 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2833 end Designate_Same_Unit;
2835 --------------------------
2836 -- Enclosing_CPP_Parent --
2837 --------------------------
2839 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2840 Parent_Typ : Entity_Id := Typ;
2843 while not Is_CPP_Class (Parent_Typ)
2844 and then Etype (Parent_Typ) /= Parent_Typ
2846 Parent_Typ := Etype (Parent_Typ);
2848 if Is_Private_Type (Parent_Typ) then
2849 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2853 pragma Assert (Is_CPP_Class (Parent_Typ));
2855 end Enclosing_CPP_Parent;
2857 ----------------------------
2858 -- Enclosing_Generic_Body --
2859 ----------------------------
2861 function Enclosing_Generic_Body
2862 (N : Node_Id) return Node_Id
2870 while Present (P) loop
2871 if Nkind (P) = N_Package_Body
2872 or else Nkind (P) = N_Subprogram_Body
2874 Spec := Corresponding_Spec (P);
2876 if Present (Spec) then
2877 Decl := Unit_Declaration_Node (Spec);
2879 if Nkind (Decl) = N_Generic_Package_Declaration
2880 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2891 end Enclosing_Generic_Body;
2893 ----------------------------
2894 -- Enclosing_Generic_Unit --
2895 ----------------------------
2897 function Enclosing_Generic_Unit
2898 (N : Node_Id) return Node_Id
2906 while Present (P) loop
2907 if Nkind (P) = N_Generic_Package_Declaration
2908 or else Nkind (P) = N_Generic_Subprogram_Declaration
2912 elsif Nkind (P) = N_Package_Body
2913 or else Nkind (P) = N_Subprogram_Body
2915 Spec := Corresponding_Spec (P);
2917 if Present (Spec) then
2918 Decl := Unit_Declaration_Node (Spec);
2920 if Nkind (Decl) = N_Generic_Package_Declaration
2921 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2932 end Enclosing_Generic_Unit;
2934 -------------------------------
2935 -- Enclosing_Lib_Unit_Entity --
2936 -------------------------------
2938 function Enclosing_Lib_Unit_Entity return Entity_Id is
2939 Unit_Entity : Entity_Id;
2942 -- Look for enclosing library unit entity by following scope links.
2943 -- Equivalent to, but faster than indexing through the scope stack.
2945 Unit_Entity := Current_Scope;
2946 while (Present (Scope (Unit_Entity))
2947 and then Scope (Unit_Entity) /= Standard_Standard)
2948 and not Is_Child_Unit (Unit_Entity)
2950 Unit_Entity := Scope (Unit_Entity);
2954 end Enclosing_Lib_Unit_Entity;
2956 -----------------------------
2957 -- Enclosing_Lib_Unit_Node --
2958 -----------------------------
2960 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2961 Current_Node : Node_Id;
2965 while Present (Current_Node)
2966 and then Nkind (Current_Node) /= N_Compilation_Unit
2968 Current_Node := Parent (Current_Node);
2971 if Nkind (Current_Node) /= N_Compilation_Unit then
2975 return Current_Node;
2976 end Enclosing_Lib_Unit_Node;
2978 -----------------------
2979 -- Enclosing_Package --
2980 -----------------------
2982 function Enclosing_Package (E : Entity_Id) return Entity_Id is
2983 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2986 if Dynamic_Scope = Standard_Standard then
2987 return Standard_Standard;
2989 elsif Dynamic_Scope = Empty then
2992 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
2995 return Dynamic_Scope;
2998 return Enclosing_Package (Dynamic_Scope);
3000 end Enclosing_Package;
3002 --------------------------
3003 -- Enclosing_Subprogram --
3004 --------------------------
3006 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
3007 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
3010 if Dynamic_Scope = Standard_Standard then
3013 elsif Dynamic_Scope = Empty then
3016 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
3017 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
3019 elsif Ekind (Dynamic_Scope) = E_Block
3020 or else Ekind (Dynamic_Scope) = E_Return_Statement
3022 return Enclosing_Subprogram (Dynamic_Scope);
3024 elsif Ekind (Dynamic_Scope) = E_Task_Type then
3025 return Get_Task_Body_Procedure (Dynamic_Scope);
3027 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
3028 and then Present (Full_View (Dynamic_Scope))
3029 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
3031 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
3033 -- No body is generated if the protected operation is eliminated
3035 elsif Convention (Dynamic_Scope) = Convention_Protected
3036 and then not Is_Eliminated (Dynamic_Scope)
3037 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
3039 return Protected_Body_Subprogram (Dynamic_Scope);
3042 return Dynamic_Scope;
3044 end Enclosing_Subprogram;
3046 ------------------------
3047 -- Ensure_Freeze_Node --
3048 ------------------------
3050 procedure Ensure_Freeze_Node (E : Entity_Id) is
3054 if No (Freeze_Node (E)) then
3055 FN := Make_Freeze_Entity (Sloc (E));
3056 Set_Has_Delayed_Freeze (E);
3057 Set_Freeze_Node (E, FN);
3058 Set_Access_Types_To_Process (FN, No_Elist);
3059 Set_TSS_Elist (FN, No_Elist);
3062 end Ensure_Freeze_Node;
3068 procedure Enter_Name (Def_Id : Entity_Id) is
3069 C : constant Entity_Id := Current_Entity (Def_Id);
3070 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3071 S : constant Entity_Id := Current_Scope;
3074 Generate_Definition (Def_Id);
3076 -- Add new name to current scope declarations. Check for duplicate
3077 -- declaration, which may or may not be a genuine error.
3081 -- Case of previous entity entered because of a missing declaration
3082 -- or else a bad subtype indication. Best is to use the new entity,
3083 -- and make the previous one invisible.
3085 if Etype (E) = Any_Type then
3086 Set_Is_Immediately_Visible (E, False);
3088 -- Case of renaming declaration constructed for package instances.
3089 -- if there is an explicit declaration with the same identifier,
3090 -- the renaming is not immediately visible any longer, but remains
3091 -- visible through selected component notation.
3093 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3094 and then not Comes_From_Source (E)
3096 Set_Is_Immediately_Visible (E, False);
3098 -- The new entity may be the package renaming, which has the same
3099 -- same name as a generic formal which has been seen already.
3101 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3102 and then not Comes_From_Source (Def_Id)
3104 Set_Is_Immediately_Visible (E, False);
3106 -- For a fat pointer corresponding to a remote access to subprogram,
3107 -- we use the same identifier as the RAS type, so that the proper
3108 -- name appears in the stub. This type is only retrieved through
3109 -- the RAS type and never by visibility, and is not added to the
3110 -- visibility list (see below).
3112 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3113 and then Present (Corresponding_Remote_Type (Def_Id))
3117 -- A controller component for a type extension overrides the
3118 -- inherited component.
3120 elsif Chars (E) = Name_uController then
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
3901 and then Chars (Comp) /= Name_uController
3903 Append_Elmt (Comp, Into);
3911 if No (Variant_Part (Comp_List)) then
3914 Discrim_Name := Name (Variant_Part (Comp_List));
3915 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3918 -- Look for the discriminant that governs this variant part.
3919 -- The discriminant *must* be in the Governed_By List
3921 Assoc := First (Governed_By);
3922 Find_Constraint : loop
3923 Discrim := First (Choices (Assoc));
3924 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3925 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3927 Chars (Corresponding_Discriminant (Entity (Discrim)))
3928 = Chars (Discrim_Name))
3929 or else Chars (Original_Record_Component (Entity (Discrim)))
3930 = Chars (Discrim_Name);
3932 if No (Next (Assoc)) then
3933 if not Is_Constrained (Typ)
3934 and then Is_Derived_Type (Typ)
3935 and then Present (Stored_Constraint (Typ))
3937 -- If the type is a tagged type with inherited discriminants,
3938 -- use the stored constraint on the parent in order to find
3939 -- the values of discriminants that are otherwise hidden by an
3940 -- explicit constraint. Renamed discriminants are handled in
3943 -- If several parent discriminants are renamed by a single
3944 -- discriminant of the derived type, the call to obtain the
3945 -- Corresponding_Discriminant field only retrieves the last
3946 -- of them. We recover the constraint on the others from the
3947 -- Stored_Constraint as well.
3954 D := First_Discriminant (Etype (Typ));
3955 C := First_Elmt (Stored_Constraint (Typ));
3956 while Present (D) and then Present (C) loop
3957 if Chars (Discrim_Name) = Chars (D) then
3958 if Is_Entity_Name (Node (C))
3959 and then Entity (Node (C)) = Entity (Discrim)
3961 -- D is renamed by Discrim, whose value is given in
3968 Make_Component_Association (Sloc (Typ),
3970 (New_Occurrence_Of (D, Sloc (Typ))),
3971 Duplicate_Subexpr_No_Checks (Node (C)));
3973 exit Find_Constraint;
3976 Next_Discriminant (D);
3983 if No (Next (Assoc)) then
3984 Error_Msg_NE (" missing value for discriminant&",
3985 First (Governed_By), Discrim_Name);
3986 Report_Errors := True;
3991 end loop Find_Constraint;
3993 Discrim_Value := Expression (Assoc);
3995 if not Is_OK_Static_Expression (Discrim_Value) then
3997 ("value for discriminant & must be static!",
3998 Discrim_Value, Discrim);
3999 Why_Not_Static (Discrim_Value);
4000 Report_Errors := True;
4004 Search_For_Discriminant_Value : declare
4010 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
4013 Find_Discrete_Value : while Present (Variant) loop
4014 Discrete_Choice := First (Discrete_Choices (Variant));
4015 while Present (Discrete_Choice) loop
4017 exit Find_Discrete_Value when
4018 Nkind (Discrete_Choice) = N_Others_Choice;
4020 Get_Index_Bounds (Discrete_Choice, Low, High);
4022 UI_Low := Expr_Value (Low);
4023 UI_High := Expr_Value (High);
4025 exit Find_Discrete_Value when
4026 UI_Low <= UI_Discrim_Value
4028 UI_High >= UI_Discrim_Value;
4030 Next (Discrete_Choice);
4033 Next_Non_Pragma (Variant);
4034 end loop Find_Discrete_Value;
4035 end Search_For_Discriminant_Value;
4037 if No (Variant) then
4039 ("value of discriminant & is out of range", Discrim_Value, Discrim);
4040 Report_Errors := True;
4044 -- If we have found the corresponding choice, recursively add its
4045 -- components to the Into list.
4047 Gather_Components (Empty,
4048 Component_List (Variant), Governed_By, Into, Report_Errors);
4049 end Gather_Components;
4051 ------------------------
4052 -- Get_Actual_Subtype --
4053 ------------------------
4055 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4056 Typ : constant Entity_Id := Etype (N);
4057 Utyp : Entity_Id := Underlying_Type (Typ);
4066 -- If what we have is an identifier that references a subprogram
4067 -- formal, or a variable or constant object, then we get the actual
4068 -- subtype from the referenced entity if one has been built.
4070 if Nkind (N) = N_Identifier
4072 (Is_Formal (Entity (N))
4073 or else Ekind (Entity (N)) = E_Constant
4074 or else Ekind (Entity (N)) = E_Variable)
4075 and then Present (Actual_Subtype (Entity (N)))
4077 return Actual_Subtype (Entity (N));
4079 -- Actual subtype of unchecked union is always itself. We never need
4080 -- the "real" actual subtype. If we did, we couldn't get it anyway
4081 -- because the discriminant is not available. The restrictions on
4082 -- Unchecked_Union are designed to make sure that this is OK.
4084 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4087 -- Here for the unconstrained case, we must find actual subtype
4088 -- No actual subtype is available, so we must build it on the fly.
4090 -- Checking the type, not the underlying type, for constrainedness
4091 -- seems to be necessary. Maybe all the tests should be on the type???
4093 elsif (not Is_Constrained (Typ))
4094 and then (Is_Array_Type (Utyp)
4095 or else (Is_Record_Type (Utyp)
4096 and then Has_Discriminants (Utyp)))
4097 and then not Has_Unknown_Discriminants (Utyp)
4098 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4100 -- Nothing to do if in spec expression (why not???)
4102 if In_Spec_Expression then
4105 elsif Is_Private_Type (Typ)
4106 and then not Has_Discriminants (Typ)
4108 -- If the type has no discriminants, there is no subtype to
4109 -- build, even if the underlying type is discriminated.
4113 -- Else build the actual subtype
4116 Decl := Build_Actual_Subtype (Typ, N);
4117 Atyp := Defining_Identifier (Decl);
4119 -- If Build_Actual_Subtype generated a new declaration then use it
4123 -- The actual subtype is an Itype, so analyze the declaration,
4124 -- but do not attach it to the tree, to get the type defined.
4126 Set_Parent (Decl, N);
4127 Set_Is_Itype (Atyp);
4128 Analyze (Decl, Suppress => All_Checks);
4129 Set_Associated_Node_For_Itype (Atyp, N);
4130 Set_Has_Delayed_Freeze (Atyp, False);
4132 -- We need to freeze the actual subtype immediately. This is
4133 -- needed, because otherwise this Itype will not get frozen
4134 -- at all, and it is always safe to freeze on creation because
4135 -- any associated types must be frozen at this point.
4137 Freeze_Itype (Atyp, N);
4140 -- Otherwise we did not build a declaration, so return original
4147 -- For all remaining cases, the actual subtype is the same as
4148 -- the nominal type.
4153 end Get_Actual_Subtype;
4155 -------------------------------------
4156 -- Get_Actual_Subtype_If_Available --
4157 -------------------------------------
4159 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4160 Typ : constant Entity_Id := Etype (N);
4163 -- If what we have is an identifier that references a subprogram
4164 -- formal, or a variable or constant object, then we get the actual
4165 -- subtype from the referenced entity if one has been built.
4167 if Nkind (N) = N_Identifier
4169 (Is_Formal (Entity (N))
4170 or else Ekind (Entity (N)) = E_Constant
4171 or else Ekind (Entity (N)) = E_Variable)
4172 and then Present (Actual_Subtype (Entity (N)))
4174 return Actual_Subtype (Entity (N));
4176 -- Otherwise the Etype of N is returned unchanged
4181 end Get_Actual_Subtype_If_Available;
4183 -------------------------------
4184 -- Get_Default_External_Name --
4185 -------------------------------
4187 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4189 Get_Decoded_Name_String (Chars (E));
4191 if Opt.External_Name_Imp_Casing = Uppercase then
4192 Set_Casing (All_Upper_Case);
4194 Set_Casing (All_Lower_Case);
4198 Make_String_Literal (Sloc (E),
4199 Strval => String_From_Name_Buffer);
4200 end Get_Default_External_Name;
4202 ---------------------------
4203 -- Get_Enum_Lit_From_Pos --
4204 ---------------------------
4206 function Get_Enum_Lit_From_Pos
4209 Loc : Source_Ptr) return Node_Id
4214 -- In the case where the literal is of type Character, Wide_Character
4215 -- or Wide_Wide_Character or of a type derived from them, there needs
4216 -- to be some special handling since there is no explicit chain of
4217 -- literals to search. Instead, an N_Character_Literal node is created
4218 -- with the appropriate Char_Code and Chars fields.
4220 if Is_Standard_Character_Type (T) then
4221 Set_Character_Literal_Name (UI_To_CC (Pos));
4223 Make_Character_Literal (Loc,
4225 Char_Literal_Value => Pos);
4227 -- For all other cases, we have a complete table of literals, and
4228 -- we simply iterate through the chain of literal until the one
4229 -- with the desired position value is found.
4233 Lit := First_Literal (Base_Type (T));
4234 for J in 1 .. UI_To_Int (Pos) loop
4238 return New_Occurrence_Of (Lit, Loc);
4240 end Get_Enum_Lit_From_Pos;
4242 ------------------------
4243 -- Get_Generic_Entity --
4244 ------------------------
4246 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4247 Ent : constant Entity_Id := Entity (Name (N));
4249 if Present (Renamed_Object (Ent)) then
4250 return Renamed_Object (Ent);
4254 end Get_Generic_Entity;
4256 ----------------------
4257 -- Get_Index_Bounds --
4258 ----------------------
4260 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4261 Kind : constant Node_Kind := Nkind (N);
4265 if Kind = N_Range then
4267 H := High_Bound (N);
4269 elsif Kind = N_Subtype_Indication then
4270 R := Range_Expression (Constraint (N));
4278 L := Low_Bound (Range_Expression (Constraint (N)));
4279 H := High_Bound (Range_Expression (Constraint (N)));
4282 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4283 if Error_Posted (Scalar_Range (Entity (N))) then
4287 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4288 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4291 L := Low_Bound (Scalar_Range (Entity (N)));
4292 H := High_Bound (Scalar_Range (Entity (N)));
4296 -- N is an expression, indicating a range with one value
4301 end Get_Index_Bounds;
4303 ----------------------------------
4304 -- Get_Library_Unit_Name_string --
4305 ----------------------------------
4307 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4308 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4311 Get_Unit_Name_String (Unit_Name_Id);
4313 -- Remove seven last character (" (spec)" or " (body)")
4315 Name_Len := Name_Len - 7;
4316 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4317 end Get_Library_Unit_Name_String;
4319 ------------------------
4320 -- Get_Name_Entity_Id --
4321 ------------------------
4323 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4325 return Entity_Id (Get_Name_Table_Info (Id));
4326 end Get_Name_Entity_Id;
4332 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4334 return Get_Pragma_Id (Pragma_Name (N));
4337 ---------------------------
4338 -- Get_Referenced_Object --
4339 ---------------------------
4341 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4346 while Is_Entity_Name (R)
4347 and then Present (Renamed_Object (Entity (R)))
4349 R := Renamed_Object (Entity (R));
4353 end Get_Referenced_Object;
4355 ------------------------
4356 -- Get_Renamed_Entity --
4357 ------------------------
4359 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4364 while Present (Renamed_Entity (R)) loop
4365 R := Renamed_Entity (R);
4369 end Get_Renamed_Entity;
4371 -------------------------
4372 -- Get_Subprogram_Body --
4373 -------------------------
4375 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4379 Decl := Unit_Declaration_Node (E);
4381 if Nkind (Decl) = N_Subprogram_Body then
4384 -- The below comment is bad, because it is possible for
4385 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4387 else -- Nkind (Decl) = N_Subprogram_Declaration
4389 if Present (Corresponding_Body (Decl)) then
4390 return Unit_Declaration_Node (Corresponding_Body (Decl));
4392 -- Imported subprogram case
4398 end Get_Subprogram_Body;
4400 ---------------------------
4401 -- Get_Subprogram_Entity --
4402 ---------------------------
4404 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4409 if Nkind (Nod) = N_Accept_Statement then
4410 Nam := Entry_Direct_Name (Nod);
4412 -- For an entry call, the prefix of the call is a selected component.
4413 -- Need additional code for internal calls ???
4415 elsif Nkind (Nod) = N_Entry_Call_Statement then
4416 if Nkind (Name (Nod)) = N_Selected_Component then
4417 Nam := Entity (Selector_Name (Name (Nod)));
4426 if Nkind (Nam) = N_Explicit_Dereference then
4427 Proc := Etype (Prefix (Nam));
4428 elsif Is_Entity_Name (Nam) then
4429 Proc := Entity (Nam);
4434 if Is_Object (Proc) then
4435 Proc := Etype (Proc);
4438 if Ekind (Proc) = E_Access_Subprogram_Type then
4439 Proc := Directly_Designated_Type (Proc);
4442 if not Is_Subprogram (Proc)
4443 and then Ekind (Proc) /= E_Subprogram_Type
4449 end Get_Subprogram_Entity;
4451 -----------------------------
4452 -- Get_Task_Body_Procedure --
4453 -----------------------------
4455 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4457 -- Note: A task type may be the completion of a private type with
4458 -- discriminants. When performing elaboration checks on a task
4459 -- declaration, the current view of the type may be the private one,
4460 -- and the procedure that holds the body of the task is held in its
4463 -- This is an odd function, why not have Task_Body_Procedure do
4464 -- the following digging???
4466 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4467 end Get_Task_Body_Procedure;
4469 -----------------------
4470 -- Has_Access_Values --
4471 -----------------------
4473 function Has_Access_Values (T : Entity_Id) return Boolean is
4474 Typ : constant Entity_Id := Underlying_Type (T);
4477 -- Case of a private type which is not completed yet. This can only
4478 -- happen in the case of a generic format type appearing directly, or
4479 -- as a component of the type to which this function is being applied
4480 -- at the top level. Return False in this case, since we certainly do
4481 -- not know that the type contains access types.
4486 elsif Is_Access_Type (Typ) then
4489 elsif Is_Array_Type (Typ) then
4490 return Has_Access_Values (Component_Type (Typ));
4492 elsif Is_Record_Type (Typ) then
4497 -- Loop to Check components
4499 Comp := First_Component_Or_Discriminant (Typ);
4500 while Present (Comp) loop
4502 -- Check for access component, tag field does not count, even
4503 -- though it is implemented internally using an access type.
4505 if Has_Access_Values (Etype (Comp))
4506 and then Chars (Comp) /= Name_uTag
4511 Next_Component_Or_Discriminant (Comp);
4520 end Has_Access_Values;
4522 ------------------------------
4523 -- Has_Compatible_Alignment --
4524 ------------------------------
4526 function Has_Compatible_Alignment
4528 Expr : Node_Id) return Alignment_Result
4530 function Has_Compatible_Alignment_Internal
4533 Default : Alignment_Result) return Alignment_Result;
4534 -- This is the internal recursive function that actually does the work.
4535 -- There is one additional parameter, which says what the result should
4536 -- be if no alignment information is found, and there is no definite
4537 -- indication of compatible alignments. At the outer level, this is set
4538 -- to Unknown, but for internal recursive calls in the case where types
4539 -- are known to be correct, it is set to Known_Compatible.
4541 ---------------------------------------
4542 -- Has_Compatible_Alignment_Internal --
4543 ---------------------------------------
4545 function Has_Compatible_Alignment_Internal
4548 Default : Alignment_Result) return Alignment_Result
4550 Result : Alignment_Result := Known_Compatible;
4551 -- Holds the current status of the result. Note that once a value of
4552 -- Known_Incompatible is set, it is sticky and does not get changed
4553 -- to Unknown (the value in Result only gets worse as we go along,
4556 Offs : Uint := No_Uint;
4557 -- Set to a factor of the offset from the base object when Expr is a
4558 -- selected or indexed component, based on Component_Bit_Offset and
4559 -- Component_Size respectively. A negative value is used to represent
4560 -- a value which is not known at compile time.
4562 procedure Check_Prefix;
4563 -- Checks the prefix recursively in the case where the expression
4564 -- is an indexed or selected component.
4566 procedure Set_Result (R : Alignment_Result);
4567 -- If R represents a worse outcome (unknown instead of known
4568 -- compatible, or known incompatible), then set Result to R.
4574 procedure Check_Prefix is
4576 -- The subtlety here is that in doing a recursive call to check
4577 -- the prefix, we have to decide what to do in the case where we
4578 -- don't find any specific indication of an alignment problem.
4580 -- At the outer level, we normally set Unknown as the result in
4581 -- this case, since we can only set Known_Compatible if we really
4582 -- know that the alignment value is OK, but for the recursive
4583 -- call, in the case where the types match, and we have not
4584 -- specified a peculiar alignment for the object, we are only
4585 -- concerned about suspicious rep clauses, the default case does
4586 -- not affect us, since the compiler will, in the absence of such
4587 -- rep clauses, ensure that the alignment is correct.
4589 if Default = Known_Compatible
4591 (Etype (Obj) = Etype (Expr)
4592 and then (Unknown_Alignment (Obj)
4594 Alignment (Obj) = Alignment (Etype (Obj))))
4597 (Has_Compatible_Alignment_Internal
4598 (Obj, Prefix (Expr), Known_Compatible));
4600 -- In all other cases, we need a full check on the prefix
4604 (Has_Compatible_Alignment_Internal
4605 (Obj, Prefix (Expr), Unknown));
4613 procedure Set_Result (R : Alignment_Result) is
4620 -- Start of processing for Has_Compatible_Alignment_Internal
4623 -- If Expr is a selected component, we must make sure there is no
4624 -- potentially troublesome component clause, and that the record is
4627 if Nkind (Expr) = N_Selected_Component then
4629 -- Packed record always generate unknown alignment
4631 if Is_Packed (Etype (Prefix (Expr))) then
4632 Set_Result (Unknown);
4635 -- Check prefix and component offset
4638 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4640 -- If Expr is an indexed component, we must make sure there is no
4641 -- potentially troublesome Component_Size clause and that the array
4642 -- is not bit-packed.
4644 elsif Nkind (Expr) = N_Indexed_Component then
4646 Typ : constant Entity_Id := Etype (Prefix (Expr));
4647 Ind : constant Node_Id := First_Index (Typ);
4650 -- Bit packed array always generates unknown alignment
4652 if Is_Bit_Packed_Array (Typ) then
4653 Set_Result (Unknown);
4656 -- Check prefix and component offset
4659 Offs := Component_Size (Typ);
4661 -- Small optimization: compute the full offset when possible
4664 and then Offs > Uint_0
4665 and then Present (Ind)
4666 and then Nkind (Ind) = N_Range
4667 and then Compile_Time_Known_Value (Low_Bound (Ind))
4668 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4670 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4671 - Expr_Value (Low_Bound ((Ind))));
4676 -- If we have a null offset, the result is entirely determined by
4677 -- the base object and has already been computed recursively.
4679 if Offs = Uint_0 then
4682 -- Case where we know the alignment of the object
4684 elsif Known_Alignment (Obj) then
4686 ObjA : constant Uint := Alignment (Obj);
4687 ExpA : Uint := No_Uint;
4688 SizA : Uint := No_Uint;
4691 -- If alignment of Obj is 1, then we are always OK
4694 Set_Result (Known_Compatible);
4696 -- Alignment of Obj is greater than 1, so we need to check
4699 -- If we have an offset, see if it is compatible
4701 if Offs /= No_Uint and Offs > Uint_0 then
4702 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4703 Set_Result (Known_Incompatible);
4706 -- See if Expr is an object with known alignment
4708 elsif Is_Entity_Name (Expr)
4709 and then Known_Alignment (Entity (Expr))
4711 ExpA := Alignment (Entity (Expr));
4713 -- Otherwise, we can use the alignment of the type of
4714 -- Expr given that we already checked for
4715 -- discombobulating rep clauses for the cases of indexed
4716 -- and selected components above.
4718 elsif Known_Alignment (Etype (Expr)) then
4719 ExpA := Alignment (Etype (Expr));
4721 -- Otherwise the alignment is unknown
4724 Set_Result (Default);
4727 -- If we got an alignment, see if it is acceptable
4729 if ExpA /= No_Uint and then ExpA < ObjA then
4730 Set_Result (Known_Incompatible);
4733 -- If Expr is not a piece of a larger object, see if size
4734 -- is given. If so, check that it is not too small for the
4735 -- required alignment.
4737 if Offs /= No_Uint then
4740 -- See if Expr is an object with known size
4742 elsif Is_Entity_Name (Expr)
4743 and then Known_Static_Esize (Entity (Expr))
4745 SizA := Esize (Entity (Expr));
4747 -- Otherwise, we check the object size of the Expr type
4749 elsif Known_Static_Esize (Etype (Expr)) then
4750 SizA := Esize (Etype (Expr));
4753 -- If we got a size, see if it is a multiple of the Obj
4754 -- alignment, if not, then the alignment cannot be
4755 -- acceptable, since the size is always a multiple of the
4758 if SizA /= No_Uint then
4759 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4760 Set_Result (Known_Incompatible);
4766 -- If we do not know required alignment, any non-zero offset is a
4767 -- potential problem (but certainly may be OK, so result is unknown).
4769 elsif Offs /= No_Uint then
4770 Set_Result (Unknown);
4772 -- If we can't find the result by direct comparison of alignment
4773 -- values, then there is still one case that we can determine known
4774 -- result, and that is when we can determine that the types are the
4775 -- same, and no alignments are specified. Then we known that the
4776 -- alignments are compatible, even if we don't know the alignment
4777 -- value in the front end.
4779 elsif Etype (Obj) = Etype (Expr) then
4781 -- Types are the same, but we have to check for possible size
4782 -- and alignments on the Expr object that may make the alignment
4783 -- different, even though the types are the same.
4785 if Is_Entity_Name (Expr) then
4787 -- First check alignment of the Expr object. Any alignment less
4788 -- than Maximum_Alignment is worrisome since this is the case
4789 -- where we do not know the alignment of Obj.
4791 if Known_Alignment (Entity (Expr))
4793 UI_To_Int (Alignment (Entity (Expr))) <
4794 Ttypes.Maximum_Alignment
4796 Set_Result (Unknown);
4798 -- Now check size of Expr object. Any size that is not an
4799 -- even multiple of Maximum_Alignment is also worrisome
4800 -- since it may cause the alignment of the object to be less
4801 -- than the alignment of the type.
4803 elsif Known_Static_Esize (Entity (Expr))
4805 (UI_To_Int (Esize (Entity (Expr))) mod
4806 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4809 Set_Result (Unknown);
4811 -- Otherwise same type is decisive
4814 Set_Result (Known_Compatible);
4818 -- Another case to deal with is when there is an explicit size or
4819 -- alignment clause when the types are not the same. If so, then the
4820 -- result is Unknown. We don't need to do this test if the Default is
4821 -- Unknown, since that result will be set in any case.
4823 elsif Default /= Unknown
4824 and then (Has_Size_Clause (Etype (Expr))
4826 Has_Alignment_Clause (Etype (Expr)))
4828 Set_Result (Unknown);
4830 -- If no indication found, set default
4833 Set_Result (Default);
4836 -- Return worst result found
4839 end Has_Compatible_Alignment_Internal;
4841 -- Start of processing for Has_Compatible_Alignment
4844 -- If Obj has no specified alignment, then set alignment from the type
4845 -- alignment. Perhaps we should always do this, but for sure we should
4846 -- do it when there is an address clause since we can do more if the
4847 -- alignment is known.
4849 if Unknown_Alignment (Obj) then
4850 Set_Alignment (Obj, Alignment (Etype (Obj)));
4853 -- Now do the internal call that does all the work
4855 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4856 end Has_Compatible_Alignment;
4858 ----------------------
4859 -- Has_Declarations --
4860 ----------------------
4862 function Has_Declarations (N : Node_Id) return Boolean is
4864 return Nkind_In (Nkind (N), N_Accept_Statement,
4866 N_Compilation_Unit_Aux,
4872 N_Package_Specification);
4873 end Has_Declarations;
4875 -------------------------------------------
4876 -- Has_Discriminant_Dependent_Constraint --
4877 -------------------------------------------
4879 function Has_Discriminant_Dependent_Constraint
4880 (Comp : Entity_Id) return Boolean
4882 Comp_Decl : constant Node_Id := Parent (Comp);
4883 Subt_Indic : constant Node_Id :=
4884 Subtype_Indication (Component_Definition (Comp_Decl));
4889 if Nkind (Subt_Indic) = N_Subtype_Indication then
4890 Constr := Constraint (Subt_Indic);
4892 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4893 Assn := First (Constraints (Constr));
4894 while Present (Assn) loop
4895 case Nkind (Assn) is
4896 when N_Subtype_Indication |
4900 if Depends_On_Discriminant (Assn) then
4904 when N_Discriminant_Association =>
4905 if Depends_On_Discriminant (Expression (Assn)) then
4920 end Has_Discriminant_Dependent_Constraint;
4922 --------------------
4923 -- Has_Infinities --
4924 --------------------
4926 function Has_Infinities (E : Entity_Id) return Boolean is
4929 Is_Floating_Point_Type (E)
4930 and then Nkind (Scalar_Range (E)) = N_Range
4931 and then Includes_Infinities (Scalar_Range (E));
4934 --------------------
4935 -- Has_Interfaces --
4936 --------------------
4938 function Has_Interfaces
4940 Use_Full_View : Boolean := True) return Boolean
4942 Typ : Entity_Id := Base_Type (T);
4945 -- Handle concurrent types
4947 if Is_Concurrent_Type (Typ) then
4948 Typ := Corresponding_Record_Type (Typ);
4951 if not Present (Typ)
4952 or else not Is_Record_Type (Typ)
4953 or else not Is_Tagged_Type (Typ)
4958 -- Handle private types
4961 and then Present (Full_View (Typ))
4963 Typ := Full_View (Typ);
4966 -- Handle concurrent record types
4968 if Is_Concurrent_Record_Type (Typ)
4969 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4975 if Is_Interface (Typ)
4977 (Is_Record_Type (Typ)
4978 and then Present (Interfaces (Typ))
4979 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4984 exit when Etype (Typ) = Typ
4986 -- Handle private types
4988 or else (Present (Full_View (Etype (Typ)))
4989 and then Full_View (Etype (Typ)) = Typ)
4991 -- Protect the frontend against wrong source with cyclic
4994 or else Etype (Typ) = T;
4996 -- Climb to the ancestor type handling private types
4998 if Present (Full_View (Etype (Typ))) then
4999 Typ := Full_View (Etype (Typ));
5008 ------------------------
5009 -- Has_Null_Exclusion --
5010 ------------------------
5012 function Has_Null_Exclusion (N : Node_Id) return Boolean is
5015 when N_Access_Definition |
5016 N_Access_Function_Definition |
5017 N_Access_Procedure_Definition |
5018 N_Access_To_Object_Definition |
5020 N_Derived_Type_Definition |
5021 N_Function_Specification |
5022 N_Subtype_Declaration =>
5023 return Null_Exclusion_Present (N);
5025 when N_Component_Definition |
5026 N_Formal_Object_Declaration |
5027 N_Object_Renaming_Declaration =>
5028 if Present (Subtype_Mark (N)) then
5029 return Null_Exclusion_Present (N);
5030 else pragma Assert (Present (Access_Definition (N)));
5031 return Null_Exclusion_Present (Access_Definition (N));
5034 when N_Discriminant_Specification =>
5035 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
5036 return Null_Exclusion_Present (Discriminant_Type (N));
5038 return Null_Exclusion_Present (N);
5041 when N_Object_Declaration =>
5042 if Nkind (Object_Definition (N)) = N_Access_Definition then
5043 return Null_Exclusion_Present (Object_Definition (N));
5045 return Null_Exclusion_Present (N);
5048 when N_Parameter_Specification =>
5049 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5050 return Null_Exclusion_Present (Parameter_Type (N));
5052 return Null_Exclusion_Present (N);
5059 end Has_Null_Exclusion;
5061 ------------------------
5062 -- Has_Null_Extension --
5063 ------------------------
5065 function Has_Null_Extension (T : Entity_Id) return Boolean is
5066 B : constant Entity_Id := Base_Type (T);
5071 if Nkind (Parent (B)) = N_Full_Type_Declaration
5072 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5074 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5076 if Present (Ext) then
5077 if Null_Present (Ext) then
5080 Comps := Component_List (Ext);
5082 -- The null component list is rewritten during analysis to
5083 -- include the parent component. Any other component indicates
5084 -- that the extension was not originally null.
5086 return Null_Present (Comps)
5087 or else No (Next (First (Component_Items (Comps))));
5096 end Has_Null_Extension;
5098 -------------------------------
5099 -- Has_Overriding_Initialize --
5100 -------------------------------
5102 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5103 BT : constant Entity_Id := Base_Type (T);
5107 if Is_Controlled (BT) then
5108 if Is_RTU (Scope (BT), Ada_Finalization) then
5111 elsif Present (Primitive_Operations (BT)) then
5112 P := First_Elmt (Primitive_Operations (BT));
5113 while Present (P) loop
5115 Init : constant Entity_Id := Node (P);
5116 Formal : constant Entity_Id := First_Formal (Init);
5118 if Ekind (Init) = E_Procedure
5119 and then Chars (Init) = Name_Initialize
5120 and then Comes_From_Source (Init)
5121 and then Present (Formal)
5122 and then Etype (Formal) = BT
5123 and then No (Next_Formal (Formal))
5124 and then (Ada_Version < Ada_2012
5125 or else not Null_Present (Parent (Init)))
5135 -- Here if type itself does not have a non-null Initialize operation:
5136 -- check immediate ancestor.
5138 if Is_Derived_Type (BT)
5139 and then Has_Overriding_Initialize (Etype (BT))
5146 end Has_Overriding_Initialize;
5148 --------------------------------------
5149 -- Has_Preelaborable_Initialization --
5150 --------------------------------------
5152 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5155 procedure Check_Components (E : Entity_Id);
5156 -- Check component/discriminant chain, sets Has_PE False if a component
5157 -- or discriminant does not meet the preelaborable initialization rules.
5159 ----------------------
5160 -- Check_Components --
5161 ----------------------
5163 procedure Check_Components (E : Entity_Id) is
5167 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5168 -- Returns True if and only if the expression denoted by N does not
5169 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5171 ---------------------------------
5172 -- Is_Preelaborable_Expression --
5173 ---------------------------------
5175 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5179 Comp_Type : Entity_Id;
5180 Is_Array_Aggr : Boolean;
5183 if Is_Static_Expression (N) then
5186 elsif Nkind (N) = N_Null then
5189 -- Attributes are allowed in general, even if their prefix is a
5190 -- formal type. (It seems that certain attributes known not to be
5191 -- static might not be allowed, but there are no rules to prevent
5194 elsif Nkind (N) = N_Attribute_Reference then
5197 -- The name of a discriminant evaluated within its parent type is
5198 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5199 -- names that denote discriminals as well as discriminants to
5200 -- catch references occurring within init procs.
5202 elsif Is_Entity_Name (N)
5204 (Ekind (Entity (N)) = E_Discriminant
5206 ((Ekind (Entity (N)) = E_Constant
5207 or else Ekind (Entity (N)) = E_In_Parameter)
5208 and then Present (Discriminal_Link (Entity (N)))))
5212 elsif Nkind (N) = N_Qualified_Expression then
5213 return Is_Preelaborable_Expression (Expression (N));
5215 -- For aggregates we have to check that each of the associations
5216 -- is preelaborable.
5218 elsif Nkind (N) = N_Aggregate
5219 or else Nkind (N) = N_Extension_Aggregate
5221 Is_Array_Aggr := Is_Array_Type (Etype (N));
5223 if Is_Array_Aggr then
5224 Comp_Type := Component_Type (Etype (N));
5227 -- Check the ancestor part of extension aggregates, which must
5228 -- be either the name of a type that has preelaborable init or
5229 -- an expression that is preelaborable.
5231 if Nkind (N) = N_Extension_Aggregate then
5233 Anc_Part : constant Node_Id := Ancestor_Part (N);
5236 if Is_Entity_Name (Anc_Part)
5237 and then Is_Type (Entity (Anc_Part))
5239 if not Has_Preelaborable_Initialization
5245 elsif not Is_Preelaborable_Expression (Anc_Part) then
5251 -- Check positional associations
5253 Exp := First (Expressions (N));
5254 while Present (Exp) loop
5255 if not Is_Preelaborable_Expression (Exp) then
5262 -- Check named associations
5264 Assn := First (Component_Associations (N));
5265 while Present (Assn) loop
5266 Choice := First (Choices (Assn));
5267 while Present (Choice) loop
5268 if Is_Array_Aggr then
5269 if Nkind (Choice) = N_Others_Choice then
5272 elsif Nkind (Choice) = N_Range then
5273 if not Is_Static_Range (Choice) then
5277 elsif not Is_Static_Expression (Choice) then
5282 Comp_Type := Etype (Choice);
5288 -- If the association has a <> at this point, then we have
5289 -- to check whether the component's type has preelaborable
5290 -- initialization. Note that this only occurs when the
5291 -- association's corresponding component does not have a
5292 -- default expression, the latter case having already been
5293 -- expanded as an expression for the association.
5295 if Box_Present (Assn) then
5296 if not Has_Preelaborable_Initialization (Comp_Type) then
5300 -- In the expression case we check whether the expression
5301 -- is preelaborable.
5304 not Is_Preelaborable_Expression (Expression (Assn))
5312 -- If we get here then aggregate as a whole is preelaborable
5316 -- All other cases are not preelaborable
5321 end Is_Preelaborable_Expression;
5323 -- Start of processing for Check_Components
5326 -- Loop through entities of record or protected type
5329 while Present (Ent) loop
5331 -- We are interested only in components and discriminants
5338 -- Get default expression if any. If there is no declaration
5339 -- node, it means we have an internal entity. The parent and
5340 -- tag fields are examples of such entities. For such cases,
5341 -- we just test the type of the entity.
5343 if Present (Declaration_Node (Ent)) then
5344 Exp := Expression (Declaration_Node (Ent));
5347 when E_Discriminant =>
5349 -- Note: for a renamed discriminant, the Declaration_Node
5350 -- may point to the one from the ancestor, and have a
5351 -- different expression, so use the proper attribute to
5352 -- retrieve the expression from the derived constraint.
5354 Exp := Discriminant_Default_Value (Ent);
5357 goto Check_Next_Entity;
5360 -- A component has PI if it has no default expression and the
5361 -- component type has PI.
5364 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5369 -- Require the default expression to be preelaborable
5371 elsif not Is_Preelaborable_Expression (Exp) then
5376 <<Check_Next_Entity>>
5379 end Check_Components;
5381 -- Start of processing for Has_Preelaborable_Initialization
5384 -- Immediate return if already marked as known preelaborable init. This
5385 -- covers types for which this function has already been called once
5386 -- and returned True (in which case the result is cached), and also
5387 -- types to which a pragma Preelaborable_Initialization applies.
5389 if Known_To_Have_Preelab_Init (E) then
5393 -- If the type is a subtype representing a generic actual type, then
5394 -- test whether its base type has preelaborable initialization since
5395 -- the subtype representing the actual does not inherit this attribute
5396 -- from the actual or formal. (but maybe it should???)
5398 if Is_Generic_Actual_Type (E) then
5399 return Has_Preelaborable_Initialization (Base_Type (E));
5402 -- All elementary types have preelaborable initialization
5404 if Is_Elementary_Type (E) then
5407 -- Array types have PI if the component type has PI
5409 elsif Is_Array_Type (E) then
5410 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5412 -- A derived type has preelaborable initialization if its parent type
5413 -- has preelaborable initialization and (in the case of a derived record
5414 -- extension) if the non-inherited components all have preelaborable
5415 -- initialization. However, a user-defined controlled type with an
5416 -- overriding Initialize procedure does not have preelaborable
5419 elsif Is_Derived_Type (E) then
5421 -- If the derived type is a private extension then it doesn't have
5422 -- preelaborable initialization.
5424 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5428 -- First check whether ancestor type has preelaborable initialization
5430 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5432 -- If OK, check extension components (if any)
5434 if Has_PE and then Is_Record_Type (E) then
5435 Check_Components (First_Entity (E));
5438 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5439 -- with a user defined Initialize procedure does not have PI.
5442 and then Is_Controlled (E)
5443 and then Has_Overriding_Initialize (E)
5448 -- Private types not derived from a type having preelaborable init and
5449 -- that are not marked with pragma Preelaborable_Initialization do not
5450 -- have preelaborable initialization.
5452 elsif Is_Private_Type (E) then
5455 -- Record type has PI if it is non private and all components have PI
5457 elsif Is_Record_Type (E) then
5459 Check_Components (First_Entity (E));
5461 -- Protected types must not have entries, and components must meet
5462 -- same set of rules as for record components.
5464 elsif Is_Protected_Type (E) then
5465 if Has_Entries (E) then
5469 Check_Components (First_Entity (E));
5470 Check_Components (First_Private_Entity (E));
5473 -- Type System.Address always has preelaborable initialization
5475 elsif Is_RTE (E, RE_Address) then
5478 -- In all other cases, type does not have preelaborable initialization
5484 -- If type has preelaborable initialization, cache result
5487 Set_Known_To_Have_Preelab_Init (E);
5491 end Has_Preelaborable_Initialization;
5493 ---------------------------
5494 -- Has_Private_Component --
5495 ---------------------------
5497 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5498 Btype : Entity_Id := Base_Type (Type_Id);
5499 Component : Entity_Id;
5502 if Error_Posted (Type_Id)
5503 or else Error_Posted (Btype)
5508 if Is_Class_Wide_Type (Btype) then
5509 Btype := Root_Type (Btype);
5512 if Is_Private_Type (Btype) then
5514 UT : constant Entity_Id := Underlying_Type (Btype);
5517 if No (Full_View (Btype)) then
5518 return not Is_Generic_Type (Btype)
5519 and then not Is_Generic_Type (Root_Type (Btype));
5521 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5524 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5528 elsif Is_Array_Type (Btype) then
5529 return Has_Private_Component (Component_Type (Btype));
5531 elsif Is_Record_Type (Btype) then
5532 Component := First_Component (Btype);
5533 while Present (Component) loop
5534 if Has_Private_Component (Etype (Component)) then
5538 Next_Component (Component);
5543 elsif Is_Protected_Type (Btype)
5544 and then Present (Corresponding_Record_Type (Btype))
5546 return Has_Private_Component (Corresponding_Record_Type (Btype));
5551 end Has_Private_Component;
5553 -----------------------------
5554 -- Has_Static_Array_Bounds --
5555 -----------------------------
5557 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
5558 Ndims : constant Nat := Number_Dimensions (Typ);
5565 -- Unconstrained types do not have static bounds
5567 if not Is_Constrained (Typ) then
5571 -- First treat specially string literals, as the lower bound and length
5572 -- of string literals are not stored like those of arrays.
5574 -- A string literal always has static bounds
5576 if Ekind (Typ) = E_String_Literal_Subtype then
5580 -- Treat all dimensions in turn
5582 Index := First_Index (Typ);
5583 for Indx in 1 .. Ndims loop
5585 -- In case of an erroneous index which is not a discrete type, return
5586 -- that the type is not static.
5588 if not Is_Discrete_Type (Etype (Index))
5589 or else Etype (Index) = Any_Type
5594 Get_Index_Bounds (Index, Low, High);
5596 if Error_Posted (Low) or else Error_Posted (High) then
5600 if Is_OK_Static_Expression (Low)
5601 and then Is_OK_Static_Expression (High)
5611 -- If we fall through the loop, all indexes matched
5614 end Has_Static_Array_Bounds;
5620 function Has_Stream (T : Entity_Id) return Boolean is
5627 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5630 elsif Is_Array_Type (T) then
5631 return Has_Stream (Component_Type (T));
5633 elsif Is_Record_Type (T) then
5634 E := First_Component (T);
5635 while Present (E) loop
5636 if Has_Stream (Etype (E)) then
5645 elsif Is_Private_Type (T) then
5646 return Has_Stream (Underlying_Type (T));
5657 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5659 Get_Name_String (Chars (E));
5660 return Name_Buffer (Name_Len) = Suffix;
5663 --------------------------
5664 -- Has_Tagged_Component --
5665 --------------------------
5667 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5671 if Is_Private_Type (Typ)
5672 and then Present (Underlying_Type (Typ))
5674 return Has_Tagged_Component (Underlying_Type (Typ));
5676 elsif Is_Array_Type (Typ) then
5677 return Has_Tagged_Component (Component_Type (Typ));
5679 elsif Is_Tagged_Type (Typ) then
5682 elsif Is_Record_Type (Typ) then
5683 Comp := First_Component (Typ);
5684 while Present (Comp) loop
5685 if Has_Tagged_Component (Etype (Comp)) then
5689 Next_Component (Comp);
5697 end Has_Tagged_Component;
5699 -------------------------
5700 -- Implementation_Kind --
5701 -------------------------
5703 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5704 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5706 pragma Assert (Present (Impl_Prag));
5708 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5709 end Implementation_Kind;
5711 --------------------------
5712 -- Implements_Interface --
5713 --------------------------
5715 function Implements_Interface
5716 (Typ_Ent : Entity_Id;
5717 Iface_Ent : Entity_Id;
5718 Exclude_Parents : Boolean := False) return Boolean
5720 Ifaces_List : Elist_Id;
5722 Iface : Entity_Id := Base_Type (Iface_Ent);
5723 Typ : Entity_Id := Base_Type (Typ_Ent);
5726 if Is_Class_Wide_Type (Typ) then
5727 Typ := Root_Type (Typ);
5730 if not Has_Interfaces (Typ) then
5734 if Is_Class_Wide_Type (Iface) then
5735 Iface := Root_Type (Iface);
5738 Collect_Interfaces (Typ, Ifaces_List);
5740 Elmt := First_Elmt (Ifaces_List);
5741 while Present (Elmt) loop
5742 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5743 and then Exclude_Parents
5747 elsif Node (Elmt) = Iface then
5755 end Implements_Interface;
5761 function In_Instance return Boolean is
5762 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5768 and then S /= Standard_Standard
5770 if (Ekind (S) = E_Function
5771 or else Ekind (S) = E_Package
5772 or else Ekind (S) = E_Procedure)
5773 and then Is_Generic_Instance (S)
5775 -- A child instance is always compiled in the context of a parent
5776 -- instance. Nevertheless, the actuals are not analyzed in an
5777 -- instance context. We detect this case by examining the current
5778 -- compilation unit, which must be a child instance, and checking
5779 -- that it is not currently on the scope stack.
5781 if Is_Child_Unit (Curr_Unit)
5783 Nkind (Unit (Cunit (Current_Sem_Unit)))
5784 = N_Package_Instantiation
5785 and then not In_Open_Scopes (Curr_Unit)
5799 ----------------------
5800 -- In_Instance_Body --
5801 ----------------------
5803 function In_Instance_Body return Boolean is
5809 and then S /= Standard_Standard
5811 if (Ekind (S) = E_Function
5812 or else Ekind (S) = E_Procedure)
5813 and then Is_Generic_Instance (S)
5817 elsif Ekind (S) = E_Package
5818 and then In_Package_Body (S)
5819 and then Is_Generic_Instance (S)
5828 end In_Instance_Body;
5830 -----------------------------
5831 -- In_Instance_Not_Visible --
5832 -----------------------------
5834 function In_Instance_Not_Visible return Boolean is
5840 and then S /= Standard_Standard
5842 if (Ekind (S) = E_Function
5843 or else Ekind (S) = E_Procedure)
5844 and then Is_Generic_Instance (S)
5848 elsif Ekind (S) = E_Package
5849 and then (In_Package_Body (S) or else In_Private_Part (S))
5850 and then Is_Generic_Instance (S)
5859 end In_Instance_Not_Visible;
5861 ------------------------------
5862 -- In_Instance_Visible_Part --
5863 ------------------------------
5865 function In_Instance_Visible_Part return Boolean is
5871 and then S /= Standard_Standard
5873 if Ekind (S) = E_Package
5874 and then Is_Generic_Instance (S)
5875 and then not In_Package_Body (S)
5876 and then not In_Private_Part (S)
5885 end In_Instance_Visible_Part;
5887 ---------------------
5888 -- In_Package_Body --
5889 ---------------------
5891 function In_Package_Body return Boolean is
5897 and then S /= Standard_Standard
5899 if Ekind (S) = E_Package
5900 and then In_Package_Body (S)
5909 end In_Package_Body;
5911 --------------------------------
5912 -- In_Parameter_Specification --
5913 --------------------------------
5915 function In_Parameter_Specification (N : Node_Id) return Boolean is
5920 while Present (PN) loop
5921 if Nkind (PN) = N_Parameter_Specification then
5929 end In_Parameter_Specification;
5931 --------------------------------------
5932 -- In_Subprogram_Or_Concurrent_Unit --
5933 --------------------------------------
5935 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5940 -- Use scope chain to check successively outer scopes
5946 if K in Subprogram_Kind
5947 or else K in Concurrent_Kind
5948 or else K in Generic_Subprogram_Kind
5952 elsif E = Standard_Standard then
5958 end In_Subprogram_Or_Concurrent_Unit;
5960 ---------------------
5961 -- In_Visible_Part --
5962 ---------------------
5964 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5967 Is_Package_Or_Generic_Package (Scope_Id)
5968 and then In_Open_Scopes (Scope_Id)
5969 and then not In_Package_Body (Scope_Id)
5970 and then not In_Private_Part (Scope_Id);
5971 end In_Visible_Part;
5973 ---------------------------------
5974 -- Insert_Explicit_Dereference --
5975 ---------------------------------
5977 procedure Insert_Explicit_Dereference (N : Node_Id) is
5978 New_Prefix : constant Node_Id := Relocate_Node (N);
5979 Ent : Entity_Id := Empty;
5986 Save_Interps (N, New_Prefix);
5989 Make_Explicit_Dereference (Sloc (Parent (N)),
5990 Prefix => New_Prefix));
5992 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5994 if Is_Overloaded (New_Prefix) then
5996 -- The dereference is also overloaded, and its interpretations are
5997 -- the designated types of the interpretations of the original node.
5999 Set_Etype (N, Any_Type);
6001 Get_First_Interp (New_Prefix, I, It);
6002 while Present (It.Nam) loop
6005 if Is_Access_Type (T) then
6006 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
6009 Get_Next_Interp (I, It);
6015 -- Prefix is unambiguous: mark the original prefix (which might
6016 -- Come_From_Source) as a reference, since the new (relocated) one
6017 -- won't be taken into account.
6019 if Is_Entity_Name (New_Prefix) then
6020 Ent := Entity (New_Prefix);
6023 -- For a retrieval of a subcomponent of some composite object,
6024 -- retrieve the ultimate entity if there is one.
6026 elsif Nkind (New_Prefix) = N_Selected_Component
6027 or else Nkind (New_Prefix) = N_Indexed_Component
6029 Pref := Prefix (New_Prefix);
6030 while Present (Pref)
6032 (Nkind (Pref) = N_Selected_Component
6033 or else Nkind (Pref) = N_Indexed_Component)
6035 Pref := Prefix (Pref);
6038 if Present (Pref) and then Is_Entity_Name (Pref) then
6039 Ent := Entity (Pref);
6043 -- Place the reference on the entity node
6045 if Present (Ent) then
6046 Generate_Reference (Ent, Pref);
6049 end Insert_Explicit_Dereference;
6051 ------------------------------------------
6052 -- Inspect_Deferred_Constant_Completion --
6053 ------------------------------------------
6055 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
6059 Decl := First (Decls);
6060 while Present (Decl) loop
6062 -- Deferred constant signature
6064 if Nkind (Decl) = N_Object_Declaration
6065 and then Constant_Present (Decl)
6066 and then No (Expression (Decl))
6068 -- No need to check internally generated constants
6070 and then Comes_From_Source (Decl)
6072 -- The constant is not completed. A full object declaration or a
6073 -- pragma Import complete a deferred constant.
6075 and then not Has_Completion (Defining_Identifier (Decl))
6078 ("constant declaration requires initialization expression",
6079 Defining_Identifier (Decl));
6082 Decl := Next (Decl);
6084 end Inspect_Deferred_Constant_Completion;
6086 -----------------------------
6087 -- Is_Actual_Out_Parameter --
6088 -----------------------------
6090 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
6094 Find_Actual (N, Formal, Call);
6095 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
6096 end Is_Actual_Out_Parameter;
6098 -------------------------
6099 -- Is_Actual_Parameter --
6100 -------------------------
6102 function Is_Actual_Parameter (N : Node_Id) return Boolean is
6103 PK : constant Node_Kind := Nkind (Parent (N));
6107 when N_Parameter_Association =>
6108 return N = Explicit_Actual_Parameter (Parent (N));
6110 when N_Function_Call | N_Procedure_Call_Statement =>
6111 return Is_List_Member (N)
6113 List_Containing (N) = Parameter_Associations (Parent (N));
6118 end Is_Actual_Parameter;
6120 --------------------------------
6121 -- Is_Actual_Tagged_Parameter --
6122 --------------------------------
6124 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6128 Find_Actual (N, Formal, Call);
6129 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6130 end Is_Actual_Tagged_Parameter;
6132 ---------------------
6133 -- Is_Aliased_View --
6134 ---------------------
6136 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6140 if Is_Entity_Name (Obj) then
6148 or else (Present (Renamed_Object (E))
6149 and then Is_Aliased_View (Renamed_Object (E)))))
6151 or else ((Is_Formal (E)
6152 or else Ekind (E) = E_Generic_In_Out_Parameter
6153 or else Ekind (E) = E_Generic_In_Parameter)
6154 and then Is_Tagged_Type (Etype (E)))
6156 or else (Is_Concurrent_Type (E)
6157 and then In_Open_Scopes (E))
6159 -- Current instance of type, either directly or as rewritten
6160 -- reference to the current object.
6162 or else (Is_Entity_Name (Original_Node (Obj))
6163 and then Present (Entity (Original_Node (Obj)))
6164 and then Is_Type (Entity (Original_Node (Obj))))
6166 or else (Is_Type (E) and then E = Current_Scope)
6168 or else (Is_Incomplete_Or_Private_Type (E)
6169 and then Full_View (E) = Current_Scope);
6171 elsif Nkind (Obj) = N_Selected_Component then
6172 return Is_Aliased (Entity (Selector_Name (Obj)));
6174 elsif Nkind (Obj) = N_Indexed_Component then
6175 return Has_Aliased_Components (Etype (Prefix (Obj)))
6177 (Is_Access_Type (Etype (Prefix (Obj)))
6179 Has_Aliased_Components
6180 (Designated_Type (Etype (Prefix (Obj)))));
6182 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6183 or else Nkind (Obj) = N_Type_Conversion
6185 return Is_Tagged_Type (Etype (Obj))
6186 and then Is_Aliased_View (Expression (Obj));
6188 elsif Nkind (Obj) = N_Explicit_Dereference then
6189 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6194 end Is_Aliased_View;
6196 -------------------------
6197 -- Is_Ancestor_Package --
6198 -------------------------
6200 function Is_Ancestor_Package
6202 E2 : Entity_Id) return Boolean
6209 and then Par /= Standard_Standard
6219 end Is_Ancestor_Package;
6221 ----------------------
6222 -- Is_Atomic_Object --
6223 ----------------------
6225 function Is_Atomic_Object (N : Node_Id) return Boolean is
6227 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6228 -- Determines if given object has atomic components
6230 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6231 -- If prefix is an implicit dereference, examine designated type
6233 ----------------------
6234 -- Is_Atomic_Prefix --
6235 ----------------------
6237 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6239 if Is_Access_Type (Etype (N)) then
6241 Has_Atomic_Components (Designated_Type (Etype (N)));
6243 return Object_Has_Atomic_Components (N);
6245 end Is_Atomic_Prefix;
6247 ----------------------------------
6248 -- Object_Has_Atomic_Components --
6249 ----------------------------------
6251 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6253 if Has_Atomic_Components (Etype (N))
6254 or else Is_Atomic (Etype (N))
6258 elsif Is_Entity_Name (N)
6259 and then (Has_Atomic_Components (Entity (N))
6260 or else Is_Atomic (Entity (N)))
6264 elsif Nkind (N) = N_Indexed_Component
6265 or else Nkind (N) = N_Selected_Component
6267 return Is_Atomic_Prefix (Prefix (N));
6272 end Object_Has_Atomic_Components;
6274 -- Start of processing for Is_Atomic_Object
6277 -- Predicate is not relevant to subprograms
6279 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6282 elsif Is_Atomic (Etype (N))
6283 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6287 elsif Nkind (N) = N_Indexed_Component
6288 or else Nkind (N) = N_Selected_Component
6290 return Is_Atomic_Prefix (Prefix (N));
6295 end Is_Atomic_Object;
6297 -------------------------
6298 -- Is_Coextension_Root --
6299 -------------------------
6301 function Is_Coextension_Root (N : Node_Id) return Boolean is
6304 Nkind (N) = N_Allocator
6305 and then Present (Coextensions (N))
6307 -- Anonymous access discriminants carry a list of all nested
6308 -- controlled coextensions.
6310 and then not Is_Dynamic_Coextension (N)
6311 and then not Is_Static_Coextension (N);
6312 end Is_Coextension_Root;
6314 -----------------------------
6315 -- Is_Concurrent_Interface --
6316 -----------------------------
6318 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6323 (Is_Protected_Interface (T)
6324 or else Is_Synchronized_Interface (T)
6325 or else Is_Task_Interface (T));
6326 end Is_Concurrent_Interface;
6328 --------------------------------------
6329 -- Is_Controlling_Limited_Procedure --
6330 --------------------------------------
6332 function Is_Controlling_Limited_Procedure
6333 (Proc_Nam : Entity_Id) return Boolean
6335 Param_Typ : Entity_Id := Empty;
6338 if Ekind (Proc_Nam) = E_Procedure
6339 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6341 Param_Typ := Etype (Parameter_Type (First (
6342 Parameter_Specifications (Parent (Proc_Nam)))));
6344 -- In this case where an Itype was created, the procedure call has been
6347 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6348 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6350 Present (Parameter_Associations
6351 (Associated_Node_For_Itype (Proc_Nam)))
6354 Etype (First (Parameter_Associations
6355 (Associated_Node_For_Itype (Proc_Nam))));
6358 if Present (Param_Typ) then
6360 Is_Interface (Param_Typ)
6361 and then Is_Limited_Record (Param_Typ);
6365 end Is_Controlling_Limited_Procedure;
6367 -----------------------------
6368 -- Is_CPP_Constructor_Call --
6369 -----------------------------
6371 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6373 return Nkind (N) = N_Function_Call
6374 and then Is_CPP_Class (Etype (Etype (N)))
6375 and then Is_Constructor (Entity (Name (N)))
6376 and then Is_Imported (Entity (Name (N)));
6377 end Is_CPP_Constructor_Call;
6383 function Is_Delegate (T : Entity_Id) return Boolean is
6384 Desig_Type : Entity_Id;
6387 if VM_Target /= CLI_Target then
6391 -- Access-to-subprograms are delegates in CIL
6393 if Ekind (T) = E_Access_Subprogram_Type then
6397 if Ekind (T) not in Access_Kind then
6399 -- A delegate is a managed pointer. If no designated type is defined
6400 -- it means that it's not a delegate.
6405 Desig_Type := Etype (Directly_Designated_Type (T));
6407 if not Is_Tagged_Type (Desig_Type) then
6411 -- Test if the type is inherited from [mscorlib]System.Delegate
6413 while Etype (Desig_Type) /= Desig_Type loop
6414 if Chars (Scope (Desig_Type)) /= No_Name
6415 and then Is_Imported (Scope (Desig_Type))
6416 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6421 Desig_Type := Etype (Desig_Type);
6427 ----------------------------------------------
6428 -- Is_Dependent_Component_Of_Mutable_Object --
6429 ----------------------------------------------
6431 function Is_Dependent_Component_Of_Mutable_Object
6432 (Object : Node_Id) return Boolean
6435 Prefix_Type : Entity_Id;
6436 P_Aliased : Boolean := False;
6439 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6440 -- Returns True if and only if Comp is declared within a variant part
6442 --------------------------------
6443 -- Is_Declared_Within_Variant --
6444 --------------------------------
6446 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6447 Comp_Decl : constant Node_Id := Parent (Comp);
6448 Comp_List : constant Node_Id := Parent (Comp_Decl);
6450 return Nkind (Parent (Comp_List)) = N_Variant;
6451 end Is_Declared_Within_Variant;
6453 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6456 if Is_Variable (Object) then
6458 if Nkind (Object) = N_Selected_Component then
6459 P := Prefix (Object);
6460 Prefix_Type := Etype (P);
6462 if Is_Entity_Name (P) then
6464 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6465 Prefix_Type := Base_Type (Prefix_Type);
6468 if Is_Aliased (Entity (P)) then
6472 -- A discriminant check on a selected component may be expanded
6473 -- into a dereference when removing side-effects. Recover the
6474 -- original node and its type, which may be unconstrained.
6476 elsif Nkind (P) = N_Explicit_Dereference
6477 and then not (Comes_From_Source (P))
6479 P := Original_Node (P);
6480 Prefix_Type := Etype (P);
6483 -- Check for prefix being an aliased component???
6489 -- A heap object is constrained by its initial value
6491 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6492 -- the dereferenced case, since the access value might denote an
6493 -- unconstrained aliased object, whereas in Ada 95 the designated
6494 -- object is guaranteed to be constrained. A worst-case assumption
6495 -- has to apply in Ada 2005 because we can't tell at compile time
6496 -- whether the object is "constrained by its initial value"
6497 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6498 -- semantic rules -- these rules are acknowledged to need fixing).
6500 if Ada_Version < Ada_2005 then
6501 if Is_Access_Type (Prefix_Type)
6502 or else Nkind (P) = N_Explicit_Dereference
6507 elsif Ada_Version >= Ada_2005 then
6508 if Is_Access_Type (Prefix_Type) then
6510 -- If the access type is pool-specific, and there is no
6511 -- constrained partial view of the designated type, then the
6512 -- designated object is known to be constrained.
6514 if Ekind (Prefix_Type) = E_Access_Type
6515 and then not Has_Constrained_Partial_View
6516 (Designated_Type (Prefix_Type))
6520 -- Otherwise (general access type, or there is a constrained
6521 -- partial view of the designated type), we need to check
6522 -- based on the designated type.
6525 Prefix_Type := Designated_Type (Prefix_Type);
6531 Original_Record_Component (Entity (Selector_Name (Object)));
6533 -- As per AI-0017, the renaming is illegal in a generic body, even
6534 -- if the subtype is indefinite.
6536 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6538 if not Is_Constrained (Prefix_Type)
6539 and then (not Is_Indefinite_Subtype (Prefix_Type)
6541 (Is_Generic_Type (Prefix_Type)
6542 and then Ekind (Current_Scope) = E_Generic_Package
6543 and then In_Package_Body (Current_Scope)))
6545 and then (Is_Declared_Within_Variant (Comp)
6546 or else Has_Discriminant_Dependent_Constraint (Comp))
6547 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6553 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6557 elsif Nkind (Object) = N_Indexed_Component
6558 or else Nkind (Object) = N_Slice
6560 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6562 -- A type conversion that Is_Variable is a view conversion:
6563 -- go back to the denoted object.
6565 elsif Nkind (Object) = N_Type_Conversion then
6567 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6572 end Is_Dependent_Component_Of_Mutable_Object;
6574 ---------------------
6575 -- Is_Dereferenced --
6576 ---------------------
6578 function Is_Dereferenced (N : Node_Id) return Boolean is
6579 P : constant Node_Id := Parent (N);
6582 (Nkind (P) = N_Selected_Component
6584 Nkind (P) = N_Explicit_Dereference
6586 Nkind (P) = N_Indexed_Component
6588 Nkind (P) = N_Slice)
6589 and then Prefix (P) = N;
6590 end Is_Dereferenced;
6592 ----------------------
6593 -- Is_Descendent_Of --
6594 ----------------------
6596 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6601 pragma Assert (Nkind (T1) in N_Entity);
6602 pragma Assert (Nkind (T2) in N_Entity);
6604 T := Base_Type (T1);
6606 -- Immediate return if the types match
6611 -- Comment needed here ???
6613 elsif Ekind (T) = E_Class_Wide_Type then
6614 return Etype (T) = T2;
6622 -- Done if we found the type we are looking for
6627 -- Done if no more derivations to check
6634 -- Following test catches error cases resulting from prev errors
6636 elsif No (Etyp) then
6639 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6642 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6646 T := Base_Type (Etyp);
6649 end Is_Descendent_Of;
6651 ----------------------------
6652 -- Is_Expression_Function --
6653 ----------------------------
6655 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6656 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6659 return Ekind (Subp) = E_Function
6660 and then Nkind (Decl) = N_Subprogram_Declaration
6662 (Nkind (Original_Node (Decl)) = N_Expression_Function
6664 (Present (Corresponding_Body (Decl))
6666 Nkind (Original_Node
6667 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6668 = N_Expression_Function));
6669 end Is_Expression_Function;
6675 function Is_False (U : Uint) return Boolean is
6680 ---------------------------
6681 -- Is_Fixed_Model_Number --
6682 ---------------------------
6684 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6685 S : constant Ureal := Small_Value (T);
6686 M : Urealp.Save_Mark;
6690 R := (U = UR_Trunc (U / S) * S);
6693 end Is_Fixed_Model_Number;
6695 -------------------------------
6696 -- Is_Fully_Initialized_Type --
6697 -------------------------------
6699 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6701 if Is_Scalar_Type (Typ) then
6704 elsif Is_Access_Type (Typ) then
6707 elsif Is_Array_Type (Typ) then
6708 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6712 -- An interesting case, if we have a constrained type one of whose
6713 -- bounds is known to be null, then there are no elements to be
6714 -- initialized, so all the elements are initialized!
6716 if Is_Constrained (Typ) then
6719 Indx_Typ : Entity_Id;
6723 Indx := First_Index (Typ);
6724 while Present (Indx) loop
6725 if Etype (Indx) = Any_Type then
6728 -- If index is a range, use directly
6730 elsif Nkind (Indx) = N_Range then
6731 Lbd := Low_Bound (Indx);
6732 Hbd := High_Bound (Indx);
6735 Indx_Typ := Etype (Indx);
6737 if Is_Private_Type (Indx_Typ) then
6738 Indx_Typ := Full_View (Indx_Typ);
6741 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6744 Lbd := Type_Low_Bound (Indx_Typ);
6745 Hbd := Type_High_Bound (Indx_Typ);
6749 if Compile_Time_Known_Value (Lbd)
6750 and then Compile_Time_Known_Value (Hbd)
6752 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6762 -- If no null indexes, then type is not fully initialized
6768 elsif Is_Record_Type (Typ) then
6769 if Has_Discriminants (Typ)
6771 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6772 and then Is_Fully_Initialized_Variant (Typ)
6777 -- Controlled records are considered to be fully initialized if
6778 -- there is a user defined Initialize routine. This may not be
6779 -- entirely correct, but as the spec notes, we are guessing here
6780 -- what is best from the point of view of issuing warnings.
6782 if Is_Controlled (Typ) then
6784 Utyp : constant Entity_Id := Underlying_Type (Typ);
6787 if Present (Utyp) then
6789 Init : constant Entity_Id :=
6791 (Underlying_Type (Typ), Name_Initialize));
6795 and then Comes_From_Source (Init)
6797 Is_Predefined_File_Name
6798 (File_Name (Get_Source_File_Index (Sloc (Init))))
6802 elsif Has_Null_Extension (Typ)
6804 Is_Fully_Initialized_Type
6805 (Etype (Base_Type (Typ)))
6814 -- Otherwise see if all record components are initialized
6820 Ent := First_Entity (Typ);
6821 while Present (Ent) loop
6822 if Chars (Ent) = Name_uController then
6825 elsif Ekind (Ent) = E_Component
6826 and then (No (Parent (Ent))
6827 or else No (Expression (Parent (Ent))))
6828 and then not Is_Fully_Initialized_Type (Etype (Ent))
6830 -- Special VM case for tag components, which need to be
6831 -- defined in this case, but are never initialized as VMs
6832 -- are using other dispatching mechanisms. Ignore this
6833 -- uninitialized case. Note that this applies both to the
6834 -- uTag entry and the main vtable pointer (CPP_Class case).
6836 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6845 -- No uninitialized components, so type is fully initialized.
6846 -- Note that this catches the case of no components as well.
6850 elsif Is_Concurrent_Type (Typ) then
6853 elsif Is_Private_Type (Typ) then
6855 U : constant Entity_Id := Underlying_Type (Typ);
6861 return Is_Fully_Initialized_Type (U);
6868 end Is_Fully_Initialized_Type;
6870 ----------------------------------
6871 -- Is_Fully_Initialized_Variant --
6872 ----------------------------------
6874 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6875 Loc : constant Source_Ptr := Sloc (Typ);
6876 Constraints : constant List_Id := New_List;
6877 Components : constant Elist_Id := New_Elmt_List;
6878 Comp_Elmt : Elmt_Id;
6880 Comp_List : Node_Id;
6882 Discr_Val : Node_Id;
6884 Report_Errors : Boolean;
6885 pragma Warnings (Off, Report_Errors);
6888 if Serious_Errors_Detected > 0 then
6892 if Is_Record_Type (Typ)
6893 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6894 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6896 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6898 Discr := First_Discriminant (Typ);
6899 while Present (Discr) loop
6900 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6901 Discr_Val := Expression (Parent (Discr));
6903 if Present (Discr_Val)
6904 and then Is_OK_Static_Expression (Discr_Val)
6906 Append_To (Constraints,
6907 Make_Component_Association (Loc,
6908 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6909 Expression => New_Copy (Discr_Val)));
6917 Next_Discriminant (Discr);
6922 Comp_List => Comp_List,
6923 Governed_By => Constraints,
6925 Report_Errors => Report_Errors);
6927 -- Check that each component present is fully initialized
6929 Comp_Elmt := First_Elmt (Components);
6930 while Present (Comp_Elmt) loop
6931 Comp_Id := Node (Comp_Elmt);
6933 if Ekind (Comp_Id) = E_Component
6934 and then (No (Parent (Comp_Id))
6935 or else No (Expression (Parent (Comp_Id))))
6936 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6941 Next_Elmt (Comp_Elmt);
6946 elsif Is_Private_Type (Typ) then
6948 U : constant Entity_Id := Underlying_Type (Typ);
6954 return Is_Fully_Initialized_Variant (U);
6960 end Is_Fully_Initialized_Variant;
6966 -- We seem to have a lot of overlapping functions that do similar things
6967 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6968 -- purely syntactic, it should be in Sem_Aux I would think???
6970 function Is_LHS (N : Node_Id) return Boolean is
6971 P : constant Node_Id := Parent (N);
6974 if Nkind (P) = N_Assignment_Statement then
6975 return Name (P) = N;
6978 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6980 return N = Prefix (P) and then Is_LHS (P);
6987 ----------------------------
6988 -- Is_Inherited_Operation --
6989 ----------------------------
6991 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6992 Kind : constant Node_Kind := Nkind (Parent (E));
6994 pragma Assert (Is_Overloadable (E));
6995 return Kind = N_Full_Type_Declaration
6996 or else Kind = N_Private_Extension_Declaration
6997 or else Kind = N_Subtype_Declaration
6998 or else (Ekind (E) = E_Enumeration_Literal
6999 and then Is_Derived_Type (Etype (E)));
7000 end Is_Inherited_Operation;
7002 -------------------------------------
7003 -- Is_Inherited_Operation_For_Type --
7004 -------------------------------------
7006 function Is_Inherited_Operation_For_Type
7007 (E : Entity_Id; Typ : Entity_Id) return Boolean
7010 return Is_Inherited_Operation (E)
7011 and then Etype (Parent (E)) = Typ;
7012 end Is_Inherited_Operation_For_Type;
7014 -----------------------------
7015 -- Is_Library_Level_Entity --
7016 -----------------------------
7018 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
7020 -- The following is a small optimization, and it also properly handles
7021 -- discriminals, which in task bodies might appear in expressions before
7022 -- the corresponding procedure has been created, and which therefore do
7023 -- not have an assigned scope.
7025 if Is_Formal (E) then
7029 -- Normal test is simply that the enclosing dynamic scope is Standard
7031 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
7032 end Is_Library_Level_Entity;
7034 ---------------------------------
7035 -- Is_Local_Variable_Reference --
7036 ---------------------------------
7038 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
7040 if not Is_Entity_Name (Expr) then
7045 Ent : constant Entity_Id := Entity (Expr);
7046 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
7048 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
7051 return Present (Sub) and then Sub = Current_Subprogram;
7055 end Is_Local_Variable_Reference;
7057 -------------------------
7058 -- Is_Object_Reference --
7059 -------------------------
7061 function Is_Object_Reference (N : Node_Id) return Boolean is
7063 if Is_Entity_Name (N) then
7064 return Present (Entity (N)) and then Is_Object (Entity (N));
7068 when N_Indexed_Component | N_Slice =>
7070 Is_Object_Reference (Prefix (N))
7071 or else Is_Access_Type (Etype (Prefix (N)));
7073 -- In Ada95, a function call is a constant object; a procedure
7076 when N_Function_Call =>
7077 return Etype (N) /= Standard_Void_Type;
7079 -- A reference to the stream attribute Input is a function call
7081 when N_Attribute_Reference =>
7082 return Attribute_Name (N) = Name_Input;
7084 when N_Selected_Component =>
7086 Is_Object_Reference (Selector_Name (N))
7088 (Is_Object_Reference (Prefix (N))
7089 or else Is_Access_Type (Etype (Prefix (N))));
7091 when N_Explicit_Dereference =>
7094 -- A view conversion of a tagged object is an object reference
7096 when N_Type_Conversion =>
7097 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
7098 and then Is_Tagged_Type (Etype (Expression (N)))
7099 and then Is_Object_Reference (Expression (N));
7101 -- An unchecked type conversion is considered to be an object if
7102 -- the operand is an object (this construction arises only as a
7103 -- result of expansion activities).
7105 when N_Unchecked_Type_Conversion =>
7112 end Is_Object_Reference;
7114 -----------------------------------
7115 -- Is_OK_Variable_For_Out_Formal --
7116 -----------------------------------
7118 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7120 Note_Possible_Modification (AV, Sure => True);
7122 -- We must reject parenthesized variable names. The check for
7123 -- Comes_From_Source is present because there are currently
7124 -- cases where the compiler violates this rule (e.g. passing
7125 -- a task object to its controlled Initialize routine).
7127 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7130 -- A variable is always allowed
7132 elsif Is_Variable (AV) then
7135 -- Unchecked conversions are allowed only if they come from the
7136 -- generated code, which sometimes uses unchecked conversions for out
7137 -- parameters in cases where code generation is unaffected. We tell
7138 -- source unchecked conversions by seeing if they are rewrites of an
7139 -- original Unchecked_Conversion function call, or of an explicit
7140 -- conversion of a function call.
7142 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7143 if Nkind (Original_Node (AV)) = N_Function_Call then
7146 elsif Comes_From_Source (AV)
7147 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7151 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7152 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7158 -- Normal type conversions are allowed if argument is a variable
7160 elsif Nkind (AV) = N_Type_Conversion then
7161 if Is_Variable (Expression (AV))
7162 and then Paren_Count (Expression (AV)) = 0
7164 Note_Possible_Modification (Expression (AV), Sure => True);
7167 -- We also allow a non-parenthesized expression that raises
7168 -- constraint error if it rewrites what used to be a variable
7170 elsif Raises_Constraint_Error (Expression (AV))
7171 and then Paren_Count (Expression (AV)) = 0
7172 and then Is_Variable (Original_Node (Expression (AV)))
7176 -- Type conversion of something other than a variable
7182 -- If this node is rewritten, then test the original form, if that is
7183 -- OK, then we consider the rewritten node OK (for example, if the
7184 -- original node is a conversion, then Is_Variable will not be true
7185 -- but we still want to allow the conversion if it converts a variable).
7187 elsif Original_Node (AV) /= AV then
7188 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7190 -- All other non-variables are rejected
7195 end Is_OK_Variable_For_Out_Formal;
7197 -----------------------------------
7198 -- Is_Partially_Initialized_Type --
7199 -----------------------------------
7201 function Is_Partially_Initialized_Type
7203 Include_Implicit : Boolean := True) return Boolean
7206 if Is_Scalar_Type (Typ) then
7209 elsif Is_Access_Type (Typ) then
7210 return Include_Implicit;
7212 elsif Is_Array_Type (Typ) then
7214 -- If component type is partially initialized, so is array type
7216 if Is_Partially_Initialized_Type
7217 (Component_Type (Typ), Include_Implicit)
7221 -- Otherwise we are only partially initialized if we are fully
7222 -- initialized (this is the empty array case, no point in us
7223 -- duplicating that code here).
7226 return Is_Fully_Initialized_Type (Typ);
7229 elsif Is_Record_Type (Typ) then
7231 -- A discriminated type is always partially initialized if in
7234 if Has_Discriminants (Typ) and then Include_Implicit then
7237 -- A tagged type is always partially initialized
7239 elsif Is_Tagged_Type (Typ) then
7242 -- Case of non-discriminated record
7248 Component_Present : Boolean := False;
7249 -- Set True if at least one component is present. If no
7250 -- components are present, then record type is fully
7251 -- initialized (another odd case, like the null array).
7254 -- Loop through components
7256 Ent := First_Entity (Typ);
7257 while Present (Ent) loop
7258 if Ekind (Ent) = E_Component then
7259 Component_Present := True;
7261 -- If a component has an initialization expression then
7262 -- the enclosing record type is partially initialized
7264 if Present (Parent (Ent))
7265 and then Present (Expression (Parent (Ent)))
7269 -- If a component is of a type which is itself partially
7270 -- initialized, then the enclosing record type is also.
7272 elsif Is_Partially_Initialized_Type
7273 (Etype (Ent), Include_Implicit)
7282 -- No initialized components found. If we found any components
7283 -- they were all uninitialized so the result is false.
7285 if Component_Present then
7288 -- But if we found no components, then all the components are
7289 -- initialized so we consider the type to be initialized.
7297 -- Concurrent types are always fully initialized
7299 elsif Is_Concurrent_Type (Typ) then
7302 -- For a private type, go to underlying type. If there is no underlying
7303 -- type then just assume this partially initialized. Not clear if this
7304 -- can happen in a non-error case, but no harm in testing for this.
7306 elsif Is_Private_Type (Typ) then
7308 U : constant Entity_Id := Underlying_Type (Typ);
7313 return Is_Partially_Initialized_Type (U, Include_Implicit);
7317 -- For any other type (are there any?) assume partially initialized
7322 end Is_Partially_Initialized_Type;
7324 ------------------------------------
7325 -- Is_Potentially_Persistent_Type --
7326 ------------------------------------
7328 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7333 -- For private type, test corresponding full type
7335 if Is_Private_Type (T) then
7336 return Is_Potentially_Persistent_Type (Full_View (T));
7338 -- Scalar types are potentially persistent
7340 elsif Is_Scalar_Type (T) then
7343 -- Record type is potentially persistent if not tagged and the types of
7344 -- all it components are potentially persistent, and no component has
7345 -- an initialization expression.
7347 elsif Is_Record_Type (T)
7348 and then not Is_Tagged_Type (T)
7349 and then not Is_Partially_Initialized_Type (T)
7351 Comp := First_Component (T);
7352 while Present (Comp) loop
7353 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7362 -- Array type is potentially persistent if its component type is
7363 -- potentially persistent and if all its constraints are static.
7365 elsif Is_Array_Type (T) then
7366 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7370 Indx := First_Index (T);
7371 while Present (Indx) loop
7372 if not Is_OK_Static_Subtype (Etype (Indx)) then
7381 -- All other types are not potentially persistent
7386 end Is_Potentially_Persistent_Type;
7388 ---------------------------------
7389 -- Is_Protected_Self_Reference --
7390 ---------------------------------
7392 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7394 function In_Access_Definition (N : Node_Id) return Boolean;
7395 -- Returns true if N belongs to an access definition
7397 --------------------------
7398 -- In_Access_Definition --
7399 --------------------------
7401 function In_Access_Definition (N : Node_Id) return Boolean is
7406 while Present (P) loop
7407 if Nkind (P) = N_Access_Definition then
7415 end In_Access_Definition;
7417 -- Start of processing for Is_Protected_Self_Reference
7420 -- Verify that prefix is analyzed and has the proper form. Note that
7421 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7422 -- produce the address of an entity, do not analyze their prefix
7423 -- because they denote entities that are not necessarily visible.
7424 -- Neither of them can apply to a protected type.
7426 return Ada_Version >= Ada_2005
7427 and then Is_Entity_Name (N)
7428 and then Present (Entity (N))
7429 and then Is_Protected_Type (Entity (N))
7430 and then In_Open_Scopes (Entity (N))
7431 and then not In_Access_Definition (N);
7432 end Is_Protected_Self_Reference;
7434 -----------------------------
7435 -- Is_RCI_Pkg_Spec_Or_Body --
7436 -----------------------------
7438 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7440 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7441 -- Return True if the unit of Cunit is an RCI package declaration
7443 ---------------------------
7444 -- Is_RCI_Pkg_Decl_Cunit --
7445 ---------------------------
7447 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7448 The_Unit : constant Node_Id := Unit (Cunit);
7451 if Nkind (The_Unit) /= N_Package_Declaration then
7455 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7456 end Is_RCI_Pkg_Decl_Cunit;
7458 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7461 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7463 (Nkind (Unit (Cunit)) = N_Package_Body
7464 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7465 end Is_RCI_Pkg_Spec_Or_Body;
7467 -----------------------------------------
7468 -- Is_Remote_Access_To_Class_Wide_Type --
7469 -----------------------------------------
7471 function Is_Remote_Access_To_Class_Wide_Type
7472 (E : Entity_Id) return Boolean
7475 -- A remote access to class-wide type is a general access to object type
7476 -- declared in the visible part of a Remote_Types or Remote_Call_
7479 return Ekind (E) = E_General_Access_Type
7480 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7481 end Is_Remote_Access_To_Class_Wide_Type;
7483 -----------------------------------------
7484 -- Is_Remote_Access_To_Subprogram_Type --
7485 -----------------------------------------
7487 function Is_Remote_Access_To_Subprogram_Type
7488 (E : Entity_Id) return Boolean
7491 return (Ekind (E) = E_Access_Subprogram_Type
7492 or else (Ekind (E) = E_Record_Type
7493 and then Present (Corresponding_Remote_Type (E))))
7494 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7495 end Is_Remote_Access_To_Subprogram_Type;
7497 --------------------
7498 -- Is_Remote_Call --
7499 --------------------
7501 function Is_Remote_Call (N : Node_Id) return Boolean is
7503 if Nkind (N) /= N_Procedure_Call_Statement
7504 and then Nkind (N) /= N_Function_Call
7506 -- An entry call cannot be remote
7510 elsif Nkind (Name (N)) in N_Has_Entity
7511 and then Is_Remote_Call_Interface (Entity (Name (N)))
7513 -- A subprogram declared in the spec of a RCI package is remote
7517 elsif Nkind (Name (N)) = N_Explicit_Dereference
7518 and then Is_Remote_Access_To_Subprogram_Type
7519 (Etype (Prefix (Name (N))))
7521 -- The dereference of a RAS is a remote call
7525 elsif Present (Controlling_Argument (N))
7526 and then Is_Remote_Access_To_Class_Wide_Type
7527 (Etype (Controlling_Argument (N)))
7529 -- Any primitive operation call with a controlling argument of
7530 -- a RACW type is a remote call.
7535 -- All other calls are local calls
7540 ----------------------
7541 -- Is_Renamed_Entry --
7542 ----------------------
7544 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7545 Orig_Node : Node_Id := Empty;
7546 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7548 function Is_Entry (Nam : Node_Id) return Boolean;
7549 -- Determine whether Nam is an entry. Traverse selectors if there are
7550 -- nested selected components.
7556 function Is_Entry (Nam : Node_Id) return Boolean is
7558 if Nkind (Nam) = N_Selected_Component then
7559 return Is_Entry (Selector_Name (Nam));
7562 return Ekind (Entity (Nam)) = E_Entry;
7565 -- Start of processing for Is_Renamed_Entry
7568 if Present (Alias (Proc_Nam)) then
7569 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7572 -- Look for a rewritten subprogram renaming declaration
7574 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7575 and then Present (Original_Node (Subp_Decl))
7577 Orig_Node := Original_Node (Subp_Decl);
7580 -- The rewritten subprogram is actually an entry
7582 if Present (Orig_Node)
7583 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7584 and then Is_Entry (Name (Orig_Node))
7590 end Is_Renamed_Entry;
7592 ----------------------
7593 -- Is_Selector_Name --
7594 ----------------------
7596 function Is_Selector_Name (N : Node_Id) return Boolean is
7598 if not Is_List_Member (N) then
7600 P : constant Node_Id := Parent (N);
7601 K : constant Node_Kind := Nkind (P);
7604 (K = N_Expanded_Name or else
7605 K = N_Generic_Association or else
7606 K = N_Parameter_Association or else
7607 K = N_Selected_Component)
7608 and then Selector_Name (P) = N;
7613 L : constant List_Id := List_Containing (N);
7614 P : constant Node_Id := Parent (L);
7616 return (Nkind (P) = N_Discriminant_Association
7617 and then Selector_Names (P) = L)
7619 (Nkind (P) = N_Component_Association
7620 and then Choices (P) = L);
7623 end Is_Selector_Name;
7625 ----------------------------------
7626 -- Is_SPARK_Initialization_Expr --
7627 ----------------------------------
7629 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7632 Comp_Assn : Node_Id;
7633 Orig_N : constant Node_Id := Original_Node (N);
7638 if not Comes_From_Source (Orig_N) then
7642 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7644 case Nkind (Orig_N) is
7645 when N_Character_Literal |
7653 if Is_Entity_Name (Orig_N)
7654 and then Present (Entity (Orig_N)) -- needed in some cases
7656 case Ekind (Entity (Orig_N)) is
7658 E_Enumeration_Literal |
7663 if Is_Type (Entity (Orig_N)) then
7671 when N_Qualified_Expression |
7672 N_Type_Conversion =>
7673 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7676 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7680 N_Membership_Test =>
7681 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7682 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7685 N_Extension_Aggregate =>
7686 if Nkind (Orig_N) = N_Extension_Aggregate then
7687 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7690 Expr := First (Expressions (Orig_N));
7691 while Present (Expr) loop
7692 if not Is_SPARK_Initialization_Expr (Expr) then
7700 Comp_Assn := First (Component_Associations (Orig_N));
7701 while Present (Comp_Assn) loop
7702 Expr := Expression (Comp_Assn);
7703 if Present (Expr) -- needed for box association
7704 and then not Is_SPARK_Initialization_Expr (Expr)
7713 when N_Attribute_Reference =>
7714 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7715 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7718 Expr := First (Expressions (Orig_N));
7719 while Present (Expr) loop
7720 if not Is_SPARK_Initialization_Expr (Expr) then
7728 -- Selected components might be expanded named not yet resolved, so
7729 -- default on the safe side. (Eg on sparklex.ads)
7731 when N_Selected_Component =>
7740 end Is_SPARK_Initialization_Expr;
7742 -------------------------------
7743 -- Is_SPARK_Object_Reference --
7744 -------------------------------
7746 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7748 if Is_Entity_Name (N) then
7749 return Present (Entity (N))
7751 (Ekind_In (Entity (N), E_Constant, E_Variable)
7752 or else Ekind (Entity (N)) in Formal_Kind);
7756 when N_Selected_Component =>
7757 return Is_SPARK_Object_Reference (Prefix (N));
7763 end Is_SPARK_Object_Reference;
7769 function Is_Statement (N : Node_Id) return Boolean is
7772 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7773 or else Nkind (N) = N_Procedure_Call_Statement;
7776 ---------------------------------
7777 -- Is_Synchronized_Tagged_Type --
7778 ---------------------------------
7780 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7781 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7784 -- A task or protected type derived from an interface is a tagged type.
7785 -- Such a tagged type is called a synchronized tagged type, as are
7786 -- synchronized interfaces and private extensions whose declaration
7787 -- includes the reserved word synchronized.
7789 return (Is_Tagged_Type (E)
7790 and then (Kind = E_Task_Type
7791 or else Kind = E_Protected_Type))
7794 and then Is_Synchronized_Interface (E))
7796 (Ekind (E) = E_Record_Type_With_Private
7797 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7798 and then (Synchronized_Present (Parent (E))
7799 or else Is_Synchronized_Interface (Etype (E))));
7800 end Is_Synchronized_Tagged_Type;
7806 function Is_Transfer (N : Node_Id) return Boolean is
7807 Kind : constant Node_Kind := Nkind (N);
7810 if Kind = N_Simple_Return_Statement
7812 Kind = N_Extended_Return_Statement
7814 Kind = N_Goto_Statement
7816 Kind = N_Raise_Statement
7818 Kind = N_Requeue_Statement
7822 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7823 and then No (Condition (N))
7827 elsif Kind = N_Procedure_Call_Statement
7828 and then Is_Entity_Name (Name (N))
7829 and then Present (Entity (Name (N)))
7830 and then No_Return (Entity (Name (N)))
7834 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7846 function Is_True (U : Uint) return Boolean is
7851 -------------------------------
7852 -- Is_Universal_Numeric_Type --
7853 -------------------------------
7855 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7857 return T = Universal_Integer or else T = Universal_Real;
7858 end Is_Universal_Numeric_Type;
7864 function Is_Value_Type (T : Entity_Id) return Boolean is
7866 return VM_Target = CLI_Target
7867 and then Nkind (T) in N_Has_Chars
7868 and then Chars (T) /= No_Name
7869 and then Get_Name_String (Chars (T)) = "valuetype";
7872 ---------------------
7873 -- Is_VMS_Operator --
7874 ---------------------
7876 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7878 -- The VMS operators are declared in a child of System that is loaded
7879 -- through pragma Extend_System. In some rare cases a program is run
7880 -- with this extension but without indicating that the target is VMS.
7882 return Ekind (Op) = E_Function
7883 and then Is_Intrinsic_Subprogram (Op)
7885 ((Present_System_Aux
7886 and then Scope (Op) = System_Aux_Id)
7889 and then Scope (Scope (Op)) = RTU_Entity (System)));
7890 end Is_VMS_Operator;
7896 function Is_Variable
7898 Use_Original_Node : Boolean := True) return Boolean
7900 Orig_Node : Node_Id;
7902 function In_Protected_Function (E : Entity_Id) return Boolean;
7903 -- Within a protected function, the private components of the enclosing
7904 -- protected type are constants. A function nested within a (protected)
7905 -- procedure is not itself protected.
7907 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7908 -- Prefixes can involve implicit dereferences, in which case we must
7909 -- test for the case of a reference of a constant access type, which can
7910 -- can never be a variable.
7912 ---------------------------
7913 -- In_Protected_Function --
7914 ---------------------------
7916 function In_Protected_Function (E : Entity_Id) return Boolean is
7917 Prot : constant Entity_Id := Scope (E);
7921 if not Is_Protected_Type (Prot) then
7925 while Present (S) and then S /= Prot loop
7926 if Ekind (S) = E_Function and then Scope (S) = Prot then
7935 end In_Protected_Function;
7937 ------------------------
7938 -- Is_Variable_Prefix --
7939 ------------------------
7941 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7943 if Is_Access_Type (Etype (P)) then
7944 return not Is_Access_Constant (Root_Type (Etype (P)));
7946 -- For the case of an indexed component whose prefix has a packed
7947 -- array type, the prefix has been rewritten into a type conversion.
7948 -- Determine variable-ness from the converted expression.
7950 elsif Nkind (P) = N_Type_Conversion
7951 and then not Comes_From_Source (P)
7952 and then Is_Array_Type (Etype (P))
7953 and then Is_Packed (Etype (P))
7955 return Is_Variable (Expression (P));
7958 return Is_Variable (P);
7960 end Is_Variable_Prefix;
7962 -- Start of processing for Is_Variable
7965 -- Check if we perform the test on the original node since this may be a
7966 -- test of syntactic categories which must not be disturbed by whatever
7967 -- rewriting might have occurred. For example, an aggregate, which is
7968 -- certainly NOT a variable, could be turned into a variable by
7971 if Use_Original_Node then
7972 Orig_Node := Original_Node (N);
7977 -- Definitely OK if Assignment_OK is set. Since this is something that
7978 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7980 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7983 -- Normally we go to the original node, but there is one exception where
7984 -- we use the rewritten node, namely when it is an explicit dereference.
7985 -- The generated code may rewrite a prefix which is an access type with
7986 -- an explicit dereference. The dereference is a variable, even though
7987 -- the original node may not be (since it could be a constant of the
7990 -- In Ada 2005 we have a further case to consider: the prefix may be a
7991 -- function call given in prefix notation. The original node appears to
7992 -- be a selected component, but we need to examine the call.
7994 elsif Nkind (N) = N_Explicit_Dereference
7995 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7996 and then Present (Etype (Orig_Node))
7997 and then Is_Access_Type (Etype (Orig_Node))
7999 -- Note that if the prefix is an explicit dereference that does not
8000 -- come from source, we must check for a rewritten function call in
8001 -- prefixed notation before other forms of rewriting, to prevent a
8005 (Nkind (Orig_Node) = N_Function_Call
8006 and then not Is_Access_Constant (Etype (Prefix (N))))
8008 Is_Variable_Prefix (Original_Node (Prefix (N)));
8010 -- A function call is never a variable
8012 elsif Nkind (N) = N_Function_Call then
8015 -- All remaining checks use the original node
8017 elsif Is_Entity_Name (Orig_Node)
8018 and then Present (Entity (Orig_Node))
8021 E : constant Entity_Id := Entity (Orig_Node);
8022 K : constant Entity_Kind := Ekind (E);
8025 return (K = E_Variable
8026 and then Nkind (Parent (E)) /= N_Exception_Handler)
8027 or else (K = E_Component
8028 and then not In_Protected_Function (E))
8029 or else K = E_Out_Parameter
8030 or else K = E_In_Out_Parameter
8031 or else K = E_Generic_In_Out_Parameter
8033 -- Current instance of type:
8035 or else (Is_Type (E) and then In_Open_Scopes (E))
8036 or else (Is_Incomplete_Or_Private_Type (E)
8037 and then In_Open_Scopes (Full_View (E)));
8041 case Nkind (Orig_Node) is
8042 when N_Indexed_Component | N_Slice =>
8043 return Is_Variable_Prefix (Prefix (Orig_Node));
8045 when N_Selected_Component =>
8046 return Is_Variable_Prefix (Prefix (Orig_Node))
8047 and then Is_Variable (Selector_Name (Orig_Node));
8049 -- For an explicit dereference, the type of the prefix cannot
8050 -- be an access to constant or an access to subprogram.
8052 when N_Explicit_Dereference =>
8054 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
8056 return Is_Access_Type (Typ)
8057 and then not Is_Access_Constant (Root_Type (Typ))
8058 and then Ekind (Typ) /= E_Access_Subprogram_Type;
8061 -- The type conversion is the case where we do not deal with the
8062 -- context dependent special case of an actual parameter. Thus
8063 -- the type conversion is only considered a variable for the
8064 -- purposes of this routine if the target type is tagged. However,
8065 -- a type conversion is considered to be a variable if it does not
8066 -- come from source (this deals for example with the conversions
8067 -- of expressions to their actual subtypes).
8069 when N_Type_Conversion =>
8070 return Is_Variable (Expression (Orig_Node))
8072 (not Comes_From_Source (Orig_Node)
8074 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
8076 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
8078 -- GNAT allows an unchecked type conversion as a variable. This
8079 -- only affects the generation of internal expanded code, since
8080 -- calls to instantiations of Unchecked_Conversion are never
8081 -- considered variables (since they are function calls).
8082 -- This is also true for expression actions.
8084 when N_Unchecked_Type_Conversion =>
8085 return Is_Variable (Expression (Orig_Node));
8093 ---------------------------
8094 -- Is_Visibly_Controlled --
8095 ---------------------------
8097 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
8098 Root : constant Entity_Id := Root_Type (T);
8100 return Chars (Scope (Root)) = Name_Finalization
8101 and then Chars (Scope (Scope (Root))) = Name_Ada
8102 and then Scope (Scope (Scope (Root))) = Standard_Standard;
8103 end Is_Visibly_Controlled;
8105 ------------------------
8106 -- Is_Volatile_Object --
8107 ------------------------
8109 function Is_Volatile_Object (N : Node_Id) return Boolean is
8111 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8112 -- Determines if given object has volatile components
8114 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8115 -- If prefix is an implicit dereference, examine designated type
8117 ------------------------
8118 -- Is_Volatile_Prefix --
8119 ------------------------
8121 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8122 Typ : constant Entity_Id := Etype (N);
8125 if Is_Access_Type (Typ) then
8127 Dtyp : constant Entity_Id := Designated_Type (Typ);
8130 return Is_Volatile (Dtyp)
8131 or else Has_Volatile_Components (Dtyp);
8135 return Object_Has_Volatile_Components (N);
8137 end Is_Volatile_Prefix;
8139 ------------------------------------
8140 -- Object_Has_Volatile_Components --
8141 ------------------------------------
8143 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8144 Typ : constant Entity_Id := Etype (N);
8147 if Is_Volatile (Typ)
8148 or else Has_Volatile_Components (Typ)
8152 elsif Is_Entity_Name (N)
8153 and then (Has_Volatile_Components (Entity (N))
8154 or else Is_Volatile (Entity (N)))
8158 elsif Nkind (N) = N_Indexed_Component
8159 or else Nkind (N) = N_Selected_Component
8161 return Is_Volatile_Prefix (Prefix (N));
8166 end Object_Has_Volatile_Components;
8168 -- Start of processing for Is_Volatile_Object
8171 if Is_Volatile (Etype (N))
8172 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8176 elsif Nkind (N) = N_Indexed_Component
8177 or else Nkind (N) = N_Selected_Component
8179 return Is_Volatile_Prefix (Prefix (N));
8184 end Is_Volatile_Object;
8186 -------------------------
8187 -- Kill_Current_Values --
8188 -------------------------
8190 procedure Kill_Current_Values
8192 Last_Assignment_Only : Boolean := False)
8195 -- ??? do we have to worry about clearing cached checks?
8197 if Is_Assignable (Ent) then
8198 Set_Last_Assignment (Ent, Empty);
8201 if Is_Object (Ent) then
8202 if not Last_Assignment_Only then
8204 Set_Current_Value (Ent, Empty);
8206 if not Can_Never_Be_Null (Ent) then
8207 Set_Is_Known_Non_Null (Ent, False);
8210 Set_Is_Known_Null (Ent, False);
8212 -- Reset Is_Known_Valid unless type is always valid, or if we have
8213 -- a loop parameter (loop parameters are always valid, since their
8214 -- bounds are defined by the bounds given in the loop header).
8216 if not Is_Known_Valid (Etype (Ent))
8217 and then Ekind (Ent) /= E_Loop_Parameter
8219 Set_Is_Known_Valid (Ent, False);
8223 end Kill_Current_Values;
8225 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8228 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8229 -- Clear current value for entity E and all entities chained to E
8231 ------------------------------------------
8232 -- Kill_Current_Values_For_Entity_Chain --
8233 ------------------------------------------
8235 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8239 while Present (Ent) loop
8240 Kill_Current_Values (Ent, Last_Assignment_Only);
8243 end Kill_Current_Values_For_Entity_Chain;
8245 -- Start of processing for Kill_Current_Values
8248 -- Kill all saved checks, a special case of killing saved values
8250 if not Last_Assignment_Only then
8254 -- Loop through relevant scopes, which includes the current scope and
8255 -- any parent scopes if the current scope is a block or a package.
8260 -- Clear current values of all entities in current scope
8262 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8264 -- If scope is a package, also clear current values of all
8265 -- private entities in the scope.
8267 if Is_Package_Or_Generic_Package (S)
8268 or else Is_Concurrent_Type (S)
8270 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8273 -- If this is a not a subprogram, deal with parents
8275 if not Is_Subprogram (S) then
8277 exit Scope_Loop when S = Standard_Standard;
8281 end loop Scope_Loop;
8282 end Kill_Current_Values;
8284 --------------------------
8285 -- Kill_Size_Check_Code --
8286 --------------------------
8288 procedure Kill_Size_Check_Code (E : Entity_Id) is
8290 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8291 and then Present (Size_Check_Code (E))
8293 Remove (Size_Check_Code (E));
8294 Set_Size_Check_Code (E, Empty);
8296 end Kill_Size_Check_Code;
8298 --------------------------
8299 -- Known_To_Be_Assigned --
8300 --------------------------
8302 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8303 P : constant Node_Id := Parent (N);
8308 -- Test left side of assignment
8310 when N_Assignment_Statement =>
8311 return N = Name (P);
8313 -- Function call arguments are never lvalues
8315 when N_Function_Call =>
8318 -- Positional parameter for procedure or accept call
8320 when N_Procedure_Call_Statement |
8329 Proc := Get_Subprogram_Entity (P);
8335 -- If we are not a list member, something is strange, so
8336 -- be conservative and return False.
8338 if not Is_List_Member (N) then
8342 -- We are going to find the right formal by stepping forward
8343 -- through the formals, as we step backwards in the actuals.
8345 Form := First_Formal (Proc);
8348 -- If no formal, something is weird, so be conservative
8349 -- and return False.
8360 return Ekind (Form) /= E_In_Parameter;
8363 -- Named parameter for procedure or accept call
8365 when N_Parameter_Association =>
8371 Proc := Get_Subprogram_Entity (Parent (P));
8377 -- Loop through formals to find the one that matches
8379 Form := First_Formal (Proc);
8381 -- If no matching formal, that's peculiar, some kind of
8382 -- previous error, so return False to be conservative.
8388 -- Else test for match
8390 if Chars (Form) = Chars (Selector_Name (P)) then
8391 return Ekind (Form) /= E_In_Parameter;
8398 -- Test for appearing in a conversion that itself appears
8399 -- in an lvalue context, since this should be an lvalue.
8401 when N_Type_Conversion =>
8402 return Known_To_Be_Assigned (P);
8404 -- All other references are definitely not known to be modifications
8410 end Known_To_Be_Assigned;
8412 ---------------------------
8413 -- Last_Source_Statement --
8414 ---------------------------
8416 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8420 N := Last (Statements (HSS));
8421 while Present (N) loop
8422 exit when Comes_From_Source (N);
8427 end Last_Source_Statement;
8429 ----------------------------------
8430 -- Matching_Static_Array_Bounds --
8431 ----------------------------------
8433 function Matching_Static_Array_Bounds
8435 R_Typ : Node_Id) return Boolean
8437 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8438 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8450 if L_Ndims /= R_Ndims then
8454 -- Unconstrained types do not have static bounds
8456 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8460 -- First treat specially the first dimension, as the lower bound and
8461 -- length of string literals are not stored like those of arrays.
8463 if Ekind (L_Typ) = E_String_Literal_Subtype then
8464 L_Low := String_Literal_Low_Bound (L_Typ);
8465 L_Len := String_Literal_Length (L_Typ);
8467 L_Index := First_Index (L_Typ);
8468 Get_Index_Bounds (L_Index, L_Low, L_High);
8470 if Is_OK_Static_Expression (L_Low)
8471 and then Is_OK_Static_Expression (L_High)
8473 if Expr_Value (L_High) < Expr_Value (L_Low) then
8476 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8483 if Ekind (R_Typ) = E_String_Literal_Subtype then
8484 R_Low := String_Literal_Low_Bound (R_Typ);
8485 R_Len := String_Literal_Length (R_Typ);
8487 R_Index := First_Index (R_Typ);
8488 Get_Index_Bounds (R_Index, R_Low, R_High);
8490 if Is_OK_Static_Expression (R_Low)
8491 and then Is_OK_Static_Expression (R_High)
8493 if Expr_Value (R_High) < Expr_Value (R_Low) then
8496 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8503 if Is_OK_Static_Expression (L_Low)
8504 and then Is_OK_Static_Expression (R_Low)
8505 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8506 and then L_Len = R_Len
8513 -- Then treat all other dimensions
8515 for Indx in 2 .. L_Ndims loop
8519 Get_Index_Bounds (L_Index, L_Low, L_High);
8520 Get_Index_Bounds (R_Index, R_Low, R_High);
8522 if Is_OK_Static_Expression (L_Low)
8523 and then Is_OK_Static_Expression (L_High)
8524 and then Is_OK_Static_Expression (R_Low)
8525 and then Is_OK_Static_Expression (R_High)
8526 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8527 and then Expr_Value (L_High) = Expr_Value (R_High)
8535 -- If we fall through the loop, all indexes matched
8538 end Matching_Static_Array_Bounds;
8544 function May_Be_Lvalue (N : Node_Id) return Boolean is
8545 P : constant Node_Id := Parent (N);
8550 -- Test left side of assignment
8552 when N_Assignment_Statement =>
8553 return N = Name (P);
8555 -- Test prefix of component or attribute. Note that the prefix of an
8556 -- explicit or implicit dereference cannot be an l-value.
8558 when N_Attribute_Reference =>
8559 return N = Prefix (P)
8560 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8562 -- For an expanded name, the name is an lvalue if the expanded name
8563 -- is an lvalue, but the prefix is never an lvalue, since it is just
8564 -- the scope where the name is found.
8566 when N_Expanded_Name =>
8567 if N = Prefix (P) then
8568 return May_Be_Lvalue (P);
8573 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8574 -- B is a little interesting, if we have A.B := 3, there is some
8575 -- discussion as to whether B is an lvalue or not, we choose to say
8576 -- it is. Note however that A is not an lvalue if it is of an access
8577 -- type since this is an implicit dereference.
8579 when N_Selected_Component =>
8581 and then Present (Etype (N))
8582 and then Is_Access_Type (Etype (N))
8586 return May_Be_Lvalue (P);
8589 -- For an indexed component or slice, the index or slice bounds is
8590 -- never an lvalue. The prefix is an lvalue if the indexed component
8591 -- or slice is an lvalue, except if it is an access type, where we
8592 -- have an implicit dereference.
8594 when N_Indexed_Component =>
8596 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8600 return May_Be_Lvalue (P);
8603 -- Prefix of a reference is an lvalue if the reference is an lvalue
8606 return May_Be_Lvalue (P);
8608 -- Prefix of explicit dereference is never an lvalue
8610 when N_Explicit_Dereference =>
8613 -- Positional parameter for subprogram, entry, or accept call.
8614 -- In older versions of Ada function call arguments are never
8615 -- lvalues. In Ada 2012 functions can have in-out parameters.
8617 when N_Function_Call |
8618 N_Procedure_Call_Statement |
8619 N_Entry_Call_Statement |
8622 if Nkind (P) = N_Function_Call
8623 and then Ada_Version < Ada_2012
8628 -- The following mechanism is clumsy and fragile. A single
8629 -- flag set in Resolve_Actuals would be preferable ???
8637 Proc := Get_Subprogram_Entity (P);
8643 -- If we are not a list member, something is strange, so
8644 -- be conservative and return True.
8646 if not Is_List_Member (N) then
8650 -- We are going to find the right formal by stepping forward
8651 -- through the formals, as we step backwards in the actuals.
8653 Form := First_Formal (Proc);
8656 -- If no formal, something is weird, so be conservative
8668 return Ekind (Form) /= E_In_Parameter;
8671 -- Named parameter for procedure or accept call
8673 when N_Parameter_Association =>
8679 Proc := Get_Subprogram_Entity (Parent (P));
8685 -- Loop through formals to find the one that matches
8687 Form := First_Formal (Proc);
8689 -- If no matching formal, that's peculiar, some kind of
8690 -- previous error, so return True to be conservative.
8696 -- Else test for match
8698 if Chars (Form) = Chars (Selector_Name (P)) then
8699 return Ekind (Form) /= E_In_Parameter;
8706 -- Test for appearing in a conversion that itself appears in an
8707 -- lvalue context, since this should be an lvalue.
8709 when N_Type_Conversion =>
8710 return May_Be_Lvalue (P);
8712 -- Test for appearance in object renaming declaration
8714 when N_Object_Renaming_Declaration =>
8717 -- All other references are definitely not lvalues
8725 -----------------------
8726 -- Mark_Coextensions --
8727 -----------------------
8729 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8730 Is_Dynamic : Boolean;
8731 -- Indicates whether the context causes nested coextensions to be
8732 -- dynamic or static
8734 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8735 -- Recognize an allocator node and label it as a dynamic coextension
8737 --------------------
8738 -- Mark_Allocator --
8739 --------------------
8741 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8743 if Nkind (N) = N_Allocator then
8745 Set_Is_Dynamic_Coextension (N);
8747 -- If the allocator expression is potentially dynamic, it may
8748 -- be expanded out of order and require dynamic allocation
8749 -- anyway, so we treat the coextension itself as dynamic.
8750 -- Potential optimization ???
8752 elsif Nkind (Expression (N)) = N_Qualified_Expression
8753 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8755 Set_Is_Dynamic_Coextension (N);
8758 Set_Is_Static_Coextension (N);
8765 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8767 -- Start of processing Mark_Coextensions
8770 case Nkind (Context_Nod) is
8771 when N_Assignment_Statement |
8772 N_Simple_Return_Statement =>
8773 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8775 when N_Object_Declaration =>
8776 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8778 -- This routine should not be called for constructs which may not
8779 -- contain coextensions.
8782 raise Program_Error;
8785 Mark_Allocators (Root_Nod);
8786 end Mark_Coextensions;
8788 ----------------------
8789 -- Needs_One_Actual --
8790 ----------------------
8792 function Needs_One_Actual (E : Entity_Id) return Boolean is
8796 if Ada_Version >= Ada_2005
8797 and then Present (First_Formal (E))
8799 Formal := Next_Formal (First_Formal (E));
8800 while Present (Formal) loop
8801 if No (Default_Value (Formal)) then
8805 Next_Formal (Formal);
8813 end Needs_One_Actual;
8815 ------------------------
8816 -- New_Copy_List_Tree --
8817 ------------------------
8819 function New_Copy_List_Tree (List : List_Id) return List_Id is
8824 if List = No_List then
8831 while Present (E) loop
8832 Append (New_Copy_Tree (E), NL);
8838 end New_Copy_List_Tree;
8844 use Atree.Unchecked_Access;
8845 use Atree_Private_Part;
8847 -- Our approach here requires a two pass traversal of the tree. The
8848 -- first pass visits all nodes that eventually will be copied looking
8849 -- for defining Itypes. If any defining Itypes are found, then they are
8850 -- copied, and an entry is added to the replacement map. In the second
8851 -- phase, the tree is copied, using the replacement map to replace any
8852 -- Itype references within the copied tree.
8854 -- The following hash tables are used if the Map supplied has more
8855 -- than hash threshold entries to speed up access to the map. If
8856 -- there are fewer entries, then the map is searched sequentially
8857 -- (because setting up a hash table for only a few entries takes
8858 -- more time than it saves.
8860 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8861 -- Hash function used for hash operations
8867 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8869 return Nat (E) mod (NCT_Header_Num'Last + 1);
8876 -- The hash table NCT_Assoc associates old entities in the table
8877 -- with their corresponding new entities (i.e. the pairs of entries
8878 -- presented in the original Map argument are Key-Element pairs).
8880 package NCT_Assoc is new Simple_HTable (
8881 Header_Num => NCT_Header_Num,
8882 Element => Entity_Id,
8883 No_Element => Empty,
8885 Hash => New_Copy_Hash,
8886 Equal => Types."=");
8888 ---------------------
8889 -- NCT_Itype_Assoc --
8890 ---------------------
8892 -- The hash table NCT_Itype_Assoc contains entries only for those
8893 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8894 -- The key is the associated node, and the element is the new node
8895 -- itself (NOT the associated node for the new node).
8897 package NCT_Itype_Assoc is new Simple_HTable (
8898 Header_Num => NCT_Header_Num,
8899 Element => Entity_Id,
8900 No_Element => Empty,
8902 Hash => New_Copy_Hash,
8903 Equal => Types."=");
8905 -- Start of processing for New_Copy_Tree function
8907 function New_Copy_Tree
8909 Map : Elist_Id := No_Elist;
8910 New_Sloc : Source_Ptr := No_Location;
8911 New_Scope : Entity_Id := Empty) return Node_Id
8913 Actual_Map : Elist_Id := Map;
8914 -- This is the actual map for the copy. It is initialized with the
8915 -- given elements, and then enlarged as required for Itypes that are
8916 -- copied during the first phase of the copy operation. The visit
8917 -- procedures add elements to this map as Itypes are encountered.
8918 -- The reason we cannot use Map directly, is that it may well be
8919 -- (and normally is) initialized to No_Elist, and if we have mapped
8920 -- entities, we have to reset it to point to a real Elist.
8922 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8923 -- Called during second phase to map entities into their corresponding
8924 -- copies using Actual_Map. If the argument is not an entity, or is not
8925 -- in Actual_Map, then it is returned unchanged.
8927 procedure Build_NCT_Hash_Tables;
8928 -- Builds hash tables (number of elements >= threshold value)
8930 function Copy_Elist_With_Replacement
8931 (Old_Elist : Elist_Id) return Elist_Id;
8932 -- Called during second phase to copy element list doing replacements
8934 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8935 -- Called during the second phase to process a copied Itype. The actual
8936 -- copy happened during the first phase (so that we could make the entry
8937 -- in the mapping), but we still have to deal with the descendents of
8938 -- the copied Itype and copy them where necessary.
8940 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8941 -- Called during second phase to copy list doing replacements
8943 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8944 -- Called during second phase to copy node doing replacements
8946 procedure Visit_Elist (E : Elist_Id);
8947 -- Called during first phase to visit all elements of an Elist
8949 procedure Visit_Field (F : Union_Id; N : Node_Id);
8950 -- Visit a single field, recursing to call Visit_Node or Visit_List
8951 -- if the field is a syntactic descendent of the current node (i.e.
8952 -- its parent is Node N).
8954 procedure Visit_Itype (Old_Itype : Entity_Id);
8955 -- Called during first phase to visit subsidiary fields of a defining
8956 -- Itype, and also create a copy and make an entry in the replacement
8957 -- map for the new copy.
8959 procedure Visit_List (L : List_Id);
8960 -- Called during first phase to visit all elements of a List
8962 procedure Visit_Node (N : Node_Or_Entity_Id);
8963 -- Called during first phase to visit a node and all its subtrees
8969 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8974 if not Has_Extension (N) or else No (Actual_Map) then
8977 elsif NCT_Hash_Tables_Used then
8978 Ent := NCT_Assoc.Get (Entity_Id (N));
8980 if Present (Ent) then
8986 -- No hash table used, do serial search
8989 E := First_Elmt (Actual_Map);
8990 while Present (E) loop
8991 if Node (E) = N then
8992 return Node (Next_Elmt (E));
8994 E := Next_Elmt (Next_Elmt (E));
9002 ---------------------------
9003 -- Build_NCT_Hash_Tables --
9004 ---------------------------
9006 procedure Build_NCT_Hash_Tables is
9010 if NCT_Hash_Table_Setup then
9012 NCT_Itype_Assoc.Reset;
9015 Elmt := First_Elmt (Actual_Map);
9016 while Present (Elmt) loop
9019 -- Get new entity, and associate old and new
9022 NCT_Assoc.Set (Ent, Node (Elmt));
9024 if Is_Type (Ent) then
9026 Anode : constant Entity_Id :=
9027 Associated_Node_For_Itype (Ent);
9030 if Present (Anode) then
9032 -- Enter a link between the associated node of the
9033 -- old Itype and the new Itype, for updating later
9034 -- when node is copied.
9036 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
9044 NCT_Hash_Tables_Used := True;
9045 NCT_Hash_Table_Setup := True;
9046 end Build_NCT_Hash_Tables;
9048 ---------------------------------
9049 -- Copy_Elist_With_Replacement --
9050 ---------------------------------
9052 function Copy_Elist_With_Replacement
9053 (Old_Elist : Elist_Id) return Elist_Id
9056 New_Elist : Elist_Id;
9059 if No (Old_Elist) then
9063 New_Elist := New_Elmt_List;
9065 M := First_Elmt (Old_Elist);
9066 while Present (M) loop
9067 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
9073 end Copy_Elist_With_Replacement;
9075 ---------------------------------
9076 -- Copy_Itype_With_Replacement --
9077 ---------------------------------
9079 -- This routine exactly parallels its phase one analog Visit_Itype,
9081 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
9083 -- Translate Next_Entity, Scope and Etype fields, in case they
9084 -- reference entities that have been mapped into copies.
9086 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
9087 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
9089 if Present (New_Scope) then
9090 Set_Scope (New_Itype, New_Scope);
9092 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
9095 -- Copy referenced fields
9097 if Is_Discrete_Type (New_Itype) then
9098 Set_Scalar_Range (New_Itype,
9099 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
9101 elsif Has_Discriminants (Base_Type (New_Itype)) then
9102 Set_Discriminant_Constraint (New_Itype,
9103 Copy_Elist_With_Replacement
9104 (Discriminant_Constraint (New_Itype)));
9106 elsif Is_Array_Type (New_Itype) then
9107 if Present (First_Index (New_Itype)) then
9108 Set_First_Index (New_Itype,
9109 First (Copy_List_With_Replacement
9110 (List_Containing (First_Index (New_Itype)))));
9113 if Is_Packed (New_Itype) then
9114 Set_Packed_Array_Type (New_Itype,
9115 Copy_Node_With_Replacement
9116 (Packed_Array_Type (New_Itype)));
9119 end Copy_Itype_With_Replacement;
9121 --------------------------------
9122 -- Copy_List_With_Replacement --
9123 --------------------------------
9125 function Copy_List_With_Replacement
9126 (Old_List : List_Id) return List_Id
9132 if Old_List = No_List then
9136 New_List := Empty_List;
9138 E := First (Old_List);
9139 while Present (E) loop
9140 Append (Copy_Node_With_Replacement (E), New_List);
9146 end Copy_List_With_Replacement;
9148 --------------------------------
9149 -- Copy_Node_With_Replacement --
9150 --------------------------------
9152 function Copy_Node_With_Replacement
9153 (Old_Node : Node_Id) return Node_Id
9157 procedure Adjust_Named_Associations
9158 (Old_Node : Node_Id;
9159 New_Node : Node_Id);
9160 -- If a call node has named associations, these are chained through
9161 -- the First_Named_Actual, Next_Named_Actual links. These must be
9162 -- propagated separately to the new parameter list, because these
9163 -- are not syntactic fields.
9165 function Copy_Field_With_Replacement
9166 (Field : Union_Id) return Union_Id;
9167 -- Given Field, which is a field of Old_Node, return a copy of it
9168 -- if it is a syntactic field (i.e. its parent is Node), setting
9169 -- the parent of the copy to poit to New_Node. Otherwise returns
9170 -- the field (possibly mapped if it is an entity).
9172 -------------------------------
9173 -- Adjust_Named_Associations --
9174 -------------------------------
9176 procedure Adjust_Named_Associations
9177 (Old_Node : Node_Id;
9187 Old_E := First (Parameter_Associations (Old_Node));
9188 New_E := First (Parameter_Associations (New_Node));
9189 while Present (Old_E) loop
9190 if Nkind (Old_E) = N_Parameter_Association
9191 and then Present (Next_Named_Actual (Old_E))
9193 if First_Named_Actual (Old_Node)
9194 = Explicit_Actual_Parameter (Old_E)
9196 Set_First_Named_Actual
9197 (New_Node, Explicit_Actual_Parameter (New_E));
9200 -- Now scan parameter list from the beginning,to locate
9201 -- next named actual, which can be out of order.
9203 Old_Next := First (Parameter_Associations (Old_Node));
9204 New_Next := First (Parameter_Associations (New_Node));
9206 while Nkind (Old_Next) /= N_Parameter_Association
9207 or else Explicit_Actual_Parameter (Old_Next)
9208 /= Next_Named_Actual (Old_E)
9214 Set_Next_Named_Actual
9215 (New_E, Explicit_Actual_Parameter (New_Next));
9221 end Adjust_Named_Associations;
9223 ---------------------------------
9224 -- Copy_Field_With_Replacement --
9225 ---------------------------------
9227 function Copy_Field_With_Replacement
9228 (Field : Union_Id) return Union_Id
9231 if Field = Union_Id (Empty) then
9234 elsif Field in Node_Range then
9236 Old_N : constant Node_Id := Node_Id (Field);
9240 -- If syntactic field, as indicated by the parent pointer
9241 -- being set, then copy the referenced node recursively.
9243 if Parent (Old_N) = Old_Node then
9244 New_N := Copy_Node_With_Replacement (Old_N);
9246 if New_N /= Old_N then
9247 Set_Parent (New_N, New_Node);
9250 -- For semantic fields, update possible entity reference
9251 -- from the replacement map.
9254 New_N := Assoc (Old_N);
9257 return Union_Id (New_N);
9260 elsif Field in List_Range then
9262 Old_L : constant List_Id := List_Id (Field);
9266 -- If syntactic field, as indicated by the parent pointer,
9267 -- then recursively copy the entire referenced list.
9269 if Parent (Old_L) = Old_Node then
9270 New_L := Copy_List_With_Replacement (Old_L);
9271 Set_Parent (New_L, New_Node);
9273 -- For semantic list, just returned unchanged
9279 return Union_Id (New_L);
9282 -- Anything other than a list or a node is returned unchanged
9287 end Copy_Field_With_Replacement;
9289 -- Start of processing for Copy_Node_With_Replacement
9292 if Old_Node <= Empty_Or_Error then
9295 elsif Has_Extension (Old_Node) then
9296 return Assoc (Old_Node);
9299 New_Node := New_Copy (Old_Node);
9301 -- If the node we are copying is the associated node of a
9302 -- previously copied Itype, then adjust the associated node
9303 -- of the copy of that Itype accordingly.
9305 if Present (Actual_Map) then
9311 -- Case of hash table used
9313 if NCT_Hash_Tables_Used then
9314 Ent := NCT_Itype_Assoc.Get (Old_Node);
9316 if Present (Ent) then
9317 Set_Associated_Node_For_Itype (Ent, New_Node);
9320 -- Case of no hash table used
9323 E := First_Elmt (Actual_Map);
9324 while Present (E) loop
9325 if Is_Itype (Node (E))
9327 Old_Node = Associated_Node_For_Itype (Node (E))
9329 Set_Associated_Node_For_Itype
9330 (Node (Next_Elmt (E)), New_Node);
9333 E := Next_Elmt (Next_Elmt (E));
9339 -- Recursively copy descendents
9342 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9344 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9346 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9348 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9350 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9352 -- Adjust Sloc of new node if necessary
9354 if New_Sloc /= No_Location then
9355 Set_Sloc (New_Node, New_Sloc);
9357 -- If we adjust the Sloc, then we are essentially making
9358 -- a completely new node, so the Comes_From_Source flag
9359 -- should be reset to the proper default value.
9361 Nodes.Table (New_Node).Comes_From_Source :=
9362 Default_Node.Comes_From_Source;
9365 -- If the node is call and has named associations,
9366 -- set the corresponding links in the copy.
9368 if (Nkind (Old_Node) = N_Function_Call
9369 or else Nkind (Old_Node) = N_Entry_Call_Statement
9371 Nkind (Old_Node) = N_Procedure_Call_Statement)
9372 and then Present (First_Named_Actual (Old_Node))
9374 Adjust_Named_Associations (Old_Node, New_Node);
9377 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9378 -- The replacement mechanism applies to entities, and is not used
9379 -- here. Eventually we may need a more general graph-copying
9380 -- routine. For now, do a sequential search to find desired node.
9382 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9383 and then Present (First_Real_Statement (Old_Node))
9386 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9390 N1 := First (Statements (Old_Node));
9391 N2 := First (Statements (New_Node));
9393 while N1 /= Old_F loop
9398 Set_First_Real_Statement (New_Node, N2);
9403 -- All done, return copied node
9406 end Copy_Node_With_Replacement;
9412 procedure Visit_Elist (E : Elist_Id) is
9416 Elmt := First_Elmt (E);
9418 while Elmt /= No_Elmt loop
9419 Visit_Node (Node (Elmt));
9429 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9431 if F = Union_Id (Empty) then
9434 elsif F in Node_Range then
9436 -- Copy node if it is syntactic, i.e. its parent pointer is
9437 -- set to point to the field that referenced it (certain
9438 -- Itypes will also meet this criterion, which is fine, since
9439 -- these are clearly Itypes that do need to be copied, since
9440 -- we are copying their parent.)
9442 if Parent (Node_Id (F)) = N then
9443 Visit_Node (Node_Id (F));
9446 -- Another case, if we are pointing to an Itype, then we want
9447 -- to copy it if its associated node is somewhere in the tree
9450 -- Note: the exclusion of self-referential copies is just an
9451 -- optimization, since the search of the already copied list
9452 -- would catch it, but it is a common case (Etype pointing
9453 -- to itself for an Itype that is a base type).
9455 elsif Has_Extension (Node_Id (F))
9456 and then Is_Itype (Entity_Id (F))
9457 and then Node_Id (F) /= N
9463 P := Associated_Node_For_Itype (Node_Id (F));
9464 while Present (P) loop
9466 Visit_Node (Node_Id (F));
9473 -- An Itype whose parent is not being copied definitely
9474 -- should NOT be copied, since it does not belong in any
9475 -- sense to the copied subtree.
9481 elsif F in List_Range
9482 and then Parent (List_Id (F)) = N
9484 Visit_List (List_Id (F));
9493 procedure Visit_Itype (Old_Itype : Entity_Id) is
9494 New_Itype : Entity_Id;
9499 -- Itypes that describe the designated type of access to subprograms
9500 -- have the structure of subprogram declarations, with signatures,
9501 -- etc. Either we duplicate the signatures completely, or choose to
9502 -- share such itypes, which is fine because their elaboration will
9503 -- have no side effects.
9505 if Ekind (Old_Itype) = E_Subprogram_Type then
9509 New_Itype := New_Copy (Old_Itype);
9511 -- The new Itype has all the attributes of the old one, and
9512 -- we just copy the contents of the entity. However, the back-end
9513 -- needs different names for debugging purposes, so we create a
9514 -- new internal name for it in all cases.
9516 Set_Chars (New_Itype, New_Internal_Name ('T'));
9518 -- If our associated node is an entity that has already been copied,
9519 -- then set the associated node of the copy to point to the right
9520 -- copy. If we have copied an Itype that is itself the associated
9521 -- node of some previously copied Itype, then we set the right
9522 -- pointer in the other direction.
9524 if Present (Actual_Map) then
9526 -- Case of hash tables used
9528 if NCT_Hash_Tables_Used then
9530 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9532 if Present (Ent) then
9533 Set_Associated_Node_For_Itype (New_Itype, Ent);
9536 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9537 if Present (Ent) then
9538 Set_Associated_Node_For_Itype (Ent, New_Itype);
9540 -- If the hash table has no association for this Itype and
9541 -- its associated node, enter one now.
9545 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9548 -- Case of hash tables not used
9551 E := First_Elmt (Actual_Map);
9552 while Present (E) loop
9553 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9554 Set_Associated_Node_For_Itype
9555 (New_Itype, Node (Next_Elmt (E)));
9558 if Is_Type (Node (E))
9560 Old_Itype = Associated_Node_For_Itype (Node (E))
9562 Set_Associated_Node_For_Itype
9563 (Node (Next_Elmt (E)), New_Itype);
9566 E := Next_Elmt (Next_Elmt (E));
9571 if Present (Freeze_Node (New_Itype)) then
9572 Set_Is_Frozen (New_Itype, False);
9573 Set_Freeze_Node (New_Itype, Empty);
9576 -- Add new association to map
9578 if No (Actual_Map) then
9579 Actual_Map := New_Elmt_List;
9582 Append_Elmt (Old_Itype, Actual_Map);
9583 Append_Elmt (New_Itype, Actual_Map);
9585 if NCT_Hash_Tables_Used then
9586 NCT_Assoc.Set (Old_Itype, New_Itype);
9589 NCT_Table_Entries := NCT_Table_Entries + 1;
9591 if NCT_Table_Entries > NCT_Hash_Threshold then
9592 Build_NCT_Hash_Tables;
9596 -- If a record subtype is simply copied, the entity list will be
9597 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9599 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9600 Set_Cloned_Subtype (New_Itype, Old_Itype);
9603 -- Visit descendents that eventually get copied
9605 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9607 if Is_Discrete_Type (Old_Itype) then
9608 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9610 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9611 -- ??? This should involve call to Visit_Field
9612 Visit_Elist (Discriminant_Constraint (Old_Itype));
9614 elsif Is_Array_Type (Old_Itype) then
9615 if Present (First_Index (Old_Itype)) then
9616 Visit_Field (Union_Id (List_Containing
9617 (First_Index (Old_Itype))),
9621 if Is_Packed (Old_Itype) then
9622 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9632 procedure Visit_List (L : List_Id) is
9635 if L /= No_List then
9638 while Present (N) loop
9649 procedure Visit_Node (N : Node_Or_Entity_Id) is
9651 -- Start of processing for Visit_Node
9654 -- Handle case of an Itype, which must be copied
9656 if Has_Extension (N)
9657 and then Is_Itype (N)
9659 -- Nothing to do if already in the list. This can happen with an
9660 -- Itype entity that appears more than once in the tree.
9661 -- Note that we do not want to visit descendents in this case.
9663 -- Test for already in list when hash table is used
9665 if NCT_Hash_Tables_Used then
9666 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9670 -- Test for already in list when hash table not used
9676 if Present (Actual_Map) then
9677 E := First_Elmt (Actual_Map);
9678 while Present (E) loop
9679 if Node (E) = N then
9682 E := Next_Elmt (Next_Elmt (E));
9692 -- Visit descendents
9694 Visit_Field (Field1 (N), N);
9695 Visit_Field (Field2 (N), N);
9696 Visit_Field (Field3 (N), N);
9697 Visit_Field (Field4 (N), N);
9698 Visit_Field (Field5 (N), N);
9701 -- Start of processing for New_Copy_Tree
9706 -- See if we should use hash table
9708 if No (Actual_Map) then
9709 NCT_Hash_Tables_Used := False;
9716 NCT_Table_Entries := 0;
9718 Elmt := First_Elmt (Actual_Map);
9719 while Present (Elmt) loop
9720 NCT_Table_Entries := NCT_Table_Entries + 1;
9725 if NCT_Table_Entries > NCT_Hash_Threshold then
9726 Build_NCT_Hash_Tables;
9728 NCT_Hash_Tables_Used := False;
9733 -- Hash table set up if required, now start phase one by visiting
9734 -- top node (we will recursively visit the descendents).
9736 Visit_Node (Source);
9738 -- Now the second phase of the copy can start. First we process
9739 -- all the mapped entities, copying their descendents.
9741 if Present (Actual_Map) then
9744 New_Itype : Entity_Id;
9746 Elmt := First_Elmt (Actual_Map);
9747 while Present (Elmt) loop
9749 New_Itype := Node (Elmt);
9750 Copy_Itype_With_Replacement (New_Itype);
9756 -- Now we can copy the actual tree
9758 return Copy_Node_With_Replacement (Source);
9761 -------------------------
9762 -- New_External_Entity --
9763 -------------------------
9765 function New_External_Entity
9766 (Kind : Entity_Kind;
9767 Scope_Id : Entity_Id;
9768 Sloc_Value : Source_Ptr;
9769 Related_Id : Entity_Id;
9771 Suffix_Index : Nat := 0;
9772 Prefix : Character := ' ') return Entity_Id
9774 N : constant Entity_Id :=
9775 Make_Defining_Identifier (Sloc_Value,
9777 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9780 Set_Ekind (N, Kind);
9781 Set_Is_Internal (N, True);
9782 Append_Entity (N, Scope_Id);
9783 Set_Public_Status (N);
9785 if Kind in Type_Kind then
9786 Init_Size_Align (N);
9790 end New_External_Entity;
9792 -------------------------
9793 -- New_Internal_Entity --
9794 -------------------------
9796 function New_Internal_Entity
9797 (Kind : Entity_Kind;
9798 Scope_Id : Entity_Id;
9799 Sloc_Value : Source_Ptr;
9800 Id_Char : Character) return Entity_Id
9802 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9805 Set_Ekind (N, Kind);
9806 Set_Is_Internal (N, True);
9807 Append_Entity (N, Scope_Id);
9809 if Kind in Type_Kind then
9810 Init_Size_Align (N);
9814 end New_Internal_Entity;
9820 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9824 -- If we are pointing at a positional parameter, it is a member of a
9825 -- node list (the list of parameters), and the next parameter is the
9826 -- next node on the list, unless we hit a parameter association, then
9827 -- we shift to using the chain whose head is the First_Named_Actual in
9828 -- the parent, and then is threaded using the Next_Named_Actual of the
9829 -- Parameter_Association. All this fiddling is because the original node
9830 -- list is in the textual call order, and what we need is the
9831 -- declaration order.
9833 if Is_List_Member (Actual_Id) then
9834 N := Next (Actual_Id);
9836 if Nkind (N) = N_Parameter_Association then
9837 return First_Named_Actual (Parent (Actual_Id));
9843 return Next_Named_Actual (Parent (Actual_Id));
9847 procedure Next_Actual (Actual_Id : in out Node_Id) is
9849 Actual_Id := Next_Actual (Actual_Id);
9852 -----------------------
9853 -- Normalize_Actuals --
9854 -----------------------
9856 -- Chain actuals according to formals of subprogram. If there are no named
9857 -- associations, the chain is simply the list of Parameter Associations,
9858 -- since the order is the same as the declaration order. If there are named
9859 -- associations, then the First_Named_Actual field in the N_Function_Call
9860 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9861 -- node for the parameter that comes first in declaration order. The
9862 -- remaining named parameters are then chained in declaration order using
9863 -- Next_Named_Actual.
9865 -- This routine also verifies that the number of actuals is compatible with
9866 -- the number and default values of formals, but performs no type checking
9867 -- (type checking is done by the caller).
9869 -- If the matching succeeds, Success is set to True and the caller proceeds
9870 -- with type-checking. If the match is unsuccessful, then Success is set to
9871 -- False, and the caller attempts a different interpretation, if there is
9874 -- If the flag Report is on, the call is not overloaded, and a failure to
9875 -- match can be reported here, rather than in the caller.
9877 procedure Normalize_Actuals
9881 Success : out Boolean)
9883 Actuals : constant List_Id := Parameter_Associations (N);
9884 Actual : Node_Id := Empty;
9886 Last : Node_Id := Empty;
9887 First_Named : Node_Id := Empty;
9890 Formals_To_Match : Integer := 0;
9891 Actuals_To_Match : Integer := 0;
9893 procedure Chain (A : Node_Id);
9894 -- Add named actual at the proper place in the list, using the
9895 -- Next_Named_Actual link.
9897 function Reporting return Boolean;
9898 -- Determines if an error is to be reported. To report an error, we
9899 -- need Report to be True, and also we do not report errors caused
9900 -- by calls to init procs that occur within other init procs. Such
9901 -- errors must always be cascaded errors, since if all the types are
9902 -- declared correctly, the compiler will certainly build decent calls!
9908 procedure Chain (A : Node_Id) is
9912 -- Call node points to first actual in list
9914 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9917 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9921 Set_Next_Named_Actual (Last, Empty);
9928 function Reporting return Boolean is
9933 elsif not Within_Init_Proc then
9936 elsif Is_Init_Proc (Entity (Name (N))) then
9944 -- Start of processing for Normalize_Actuals
9947 if Is_Access_Type (S) then
9949 -- The name in the call is a function call that returns an access
9950 -- to subprogram. The designated type has the list of formals.
9952 Formal := First_Formal (Designated_Type (S));
9954 Formal := First_Formal (S);
9957 while Present (Formal) loop
9958 Formals_To_Match := Formals_To_Match + 1;
9959 Next_Formal (Formal);
9962 -- Find if there is a named association, and verify that no positional
9963 -- associations appear after named ones.
9965 if Present (Actuals) then
9966 Actual := First (Actuals);
9969 while Present (Actual)
9970 and then Nkind (Actual) /= N_Parameter_Association
9972 Actuals_To_Match := Actuals_To_Match + 1;
9976 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9978 -- Most common case: positional notation, no defaults
9983 elsif Actuals_To_Match > Formals_To_Match then
9985 -- Too many actuals: will not work
9988 if Is_Entity_Name (Name (N)) then
9989 Error_Msg_N ("too many arguments in call to&", Name (N));
9991 Error_Msg_N ("too many arguments in call", N);
9999 First_Named := Actual;
10001 while Present (Actual) loop
10002 if Nkind (Actual) /= N_Parameter_Association then
10004 ("positional parameters not allowed after named ones", Actual);
10009 Actuals_To_Match := Actuals_To_Match + 1;
10015 if Present (Actuals) then
10016 Actual := First (Actuals);
10019 Formal := First_Formal (S);
10020 while Present (Formal) loop
10022 -- Match the formals in order. If the corresponding actual is
10023 -- positional, nothing to do. Else scan the list of named actuals
10024 -- to find the one with the right name.
10026 if Present (Actual)
10027 and then Nkind (Actual) /= N_Parameter_Association
10030 Actuals_To_Match := Actuals_To_Match - 1;
10031 Formals_To_Match := Formals_To_Match - 1;
10034 -- For named parameters, search the list of actuals to find
10035 -- one that matches the next formal name.
10037 Actual := First_Named;
10039 while Present (Actual) loop
10040 if Chars (Selector_Name (Actual)) = Chars (Formal) then
10043 Actuals_To_Match := Actuals_To_Match - 1;
10044 Formals_To_Match := Formals_To_Match - 1;
10052 if Ekind (Formal) /= E_In_Parameter
10053 or else No (Default_Value (Formal))
10056 if (Comes_From_Source (S)
10057 or else Sloc (S) = Standard_Location)
10058 and then Is_Overloadable (S)
10062 (Nkind (Parent (N)) = N_Procedure_Call_Statement
10064 (Nkind (Parent (N)) = N_Function_Call
10066 Nkind (Parent (N)) = N_Parameter_Association))
10067 and then Ekind (S) /= E_Function
10069 Set_Etype (N, Etype (S));
10071 Error_Msg_Name_1 := Chars (S);
10072 Error_Msg_Sloc := Sloc (S);
10074 ("missing argument for parameter & " &
10075 "in call to % declared #", N, Formal);
10078 elsif Is_Overloadable (S) then
10079 Error_Msg_Name_1 := Chars (S);
10081 -- Point to type derivation that generated the
10084 Error_Msg_Sloc := Sloc (Parent (S));
10087 ("missing argument for parameter & " &
10088 "in call to % (inherited) #", N, Formal);
10092 ("missing argument for parameter &", N, Formal);
10100 Formals_To_Match := Formals_To_Match - 1;
10105 Next_Formal (Formal);
10108 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10115 -- Find some superfluous named actual that did not get
10116 -- attached to the list of associations.
10118 Actual := First (Actuals);
10119 while Present (Actual) loop
10120 if Nkind (Actual) = N_Parameter_Association
10121 and then Actual /= Last
10122 and then No (Next_Named_Actual (Actual))
10124 Error_Msg_N ("unmatched actual & in call",
10125 Selector_Name (Actual));
10136 end Normalize_Actuals;
10138 --------------------------------
10139 -- Note_Possible_Modification --
10140 --------------------------------
10142 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10143 Modification_Comes_From_Source : constant Boolean :=
10144 Comes_From_Source (Parent (N));
10150 -- Loop to find referenced entity, if there is one
10157 if Is_Entity_Name (Exp) then
10158 Ent := Entity (Exp);
10160 -- If the entity is missing, it is an undeclared identifier,
10161 -- and there is nothing to annotate.
10167 elsif Nkind (Exp) = N_Explicit_Dereference then
10169 P : constant Node_Id := Prefix (Exp);
10172 if Nkind (P) = N_Selected_Component
10174 Entry_Formal (Entity (Selector_Name (P))))
10176 -- Case of a reference to an entry formal
10178 Ent := Entry_Formal (Entity (Selector_Name (P)));
10180 elsif Nkind (P) = N_Identifier
10181 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10182 and then Present (Expression (Parent (Entity (P))))
10183 and then Nkind (Expression (Parent (Entity (P))))
10186 -- Case of a reference to a value on which side effects have
10189 Exp := Prefix (Expression (Parent (Entity (P))));
10198 elsif Nkind (Exp) = N_Type_Conversion
10199 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10201 Exp := Expression (Exp);
10204 elsif Nkind (Exp) = N_Slice
10205 or else Nkind (Exp) = N_Indexed_Component
10206 or else Nkind (Exp) = N_Selected_Component
10208 Exp := Prefix (Exp);
10215 -- Now look for entity being referenced
10217 if Present (Ent) then
10218 if Is_Object (Ent) then
10219 if Comes_From_Source (Exp)
10220 or else Modification_Comes_From_Source
10222 -- Give warning if pragma unmodified given and we are
10223 -- sure this is a modification.
10225 if Has_Pragma_Unmodified (Ent) and then Sure then
10226 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10229 Set_Never_Set_In_Source (Ent, False);
10232 Set_Is_True_Constant (Ent, False);
10233 Set_Current_Value (Ent, Empty);
10234 Set_Is_Known_Null (Ent, False);
10236 if not Can_Never_Be_Null (Ent) then
10237 Set_Is_Known_Non_Null (Ent, False);
10240 -- Follow renaming chain
10242 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10243 and then Present (Renamed_Object (Ent))
10245 Exp := Renamed_Object (Ent);
10249 -- Generate a reference only if the assignment comes from
10250 -- source. This excludes, for example, calls to a dispatching
10251 -- assignment operation when the left-hand side is tagged.
10253 if Modification_Comes_From_Source then
10254 Generate_Reference (Ent, Exp, 'm');
10256 -- If the target of the assignment is the bound variable
10257 -- in an iterator, indicate that the corresponding array
10258 -- or container is also modified.
10260 if Ada_Version >= Ada_2012
10262 Nkind (Parent (Ent)) = N_Iterator_Specification
10265 Domain : constant Node_Id := Name (Parent (Ent));
10268 -- TBD : in the full version of the construct, the
10269 -- domain of iteration can be given by an expression.
10271 if Is_Entity_Name (Domain) then
10272 Generate_Reference (Entity (Domain), Exp, 'm');
10273 Set_Is_True_Constant (Entity (Domain), False);
10274 Set_Never_Set_In_Source (Entity (Domain), False);
10280 Check_Nested_Access (Ent);
10285 -- If we are sure this is a modification from source, and we know
10286 -- this modifies a constant, then give an appropriate warning.
10288 if Overlays_Constant (Ent)
10289 and then Modification_Comes_From_Source
10293 A : constant Node_Id := Address_Clause (Ent);
10295 if Present (A) then
10297 Exp : constant Node_Id := Expression (A);
10299 if Nkind (Exp) = N_Attribute_Reference
10300 and then Attribute_Name (Exp) = Name_Address
10301 and then Is_Entity_Name (Prefix (Exp))
10303 Error_Msg_Sloc := Sloc (A);
10305 ("constant& may be modified via address clause#?",
10306 N, Entity (Prefix (Exp)));
10316 end Note_Possible_Modification;
10318 -------------------------
10319 -- Object_Access_Level --
10320 -------------------------
10322 function Object_Access_Level (Obj : Node_Id) return Uint is
10325 -- Returns the static accessibility level of the view denoted by Obj. Note
10326 -- that the value returned is the result of a call to Scope_Depth. Only
10327 -- scope depths associated with dynamic scopes can actually be returned.
10328 -- Since only relative levels matter for accessibility checking, the fact
10329 -- that the distance between successive levels of accessibility is not
10330 -- always one is immaterial (invariant: if level(E2) is deeper than
10331 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10333 function Reference_To (Obj : Node_Id) return Node_Id;
10334 -- An explicit dereference is created when removing side-effects from
10335 -- expressions for constraint checking purposes. In this case a local
10336 -- access type is created for it. The correct access level is that of
10337 -- the original source node. We detect this case by noting that the
10338 -- prefix of the dereference is created by an object declaration whose
10339 -- initial expression is a reference.
10345 function Reference_To (Obj : Node_Id) return Node_Id is
10346 Pref : constant Node_Id := Prefix (Obj);
10348 if Is_Entity_Name (Pref)
10349 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10350 and then Present (Expression (Parent (Entity (Pref))))
10351 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10353 return (Prefix (Expression (Parent (Entity (Pref)))));
10359 -- Start of processing for Object_Access_Level
10362 if Is_Entity_Name (Obj) then
10365 if Is_Prival (E) then
10366 E := Prival_Link (E);
10369 -- If E is a type then it denotes a current instance. For this case
10370 -- we add one to the normal accessibility level of the type to ensure
10371 -- that current instances are treated as always being deeper than
10372 -- than the level of any visible named access type (see 3.10.2(21)).
10374 if Is_Type (E) then
10375 return Type_Access_Level (E) + 1;
10377 elsif Present (Renamed_Object (E)) then
10378 return Object_Access_Level (Renamed_Object (E));
10380 -- Similarly, if E is a component of the current instance of a
10381 -- protected type, any instance of it is assumed to be at a deeper
10382 -- level than the type. For a protected object (whose type is an
10383 -- anonymous protected type) its components are at the same level
10384 -- as the type itself.
10386 elsif not Is_Overloadable (E)
10387 and then Ekind (Scope (E)) = E_Protected_Type
10388 and then Comes_From_Source (Scope (E))
10390 return Type_Access_Level (Scope (E)) + 1;
10393 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10396 elsif Nkind (Obj) = N_Selected_Component then
10397 if Is_Access_Type (Etype (Prefix (Obj))) then
10398 return Type_Access_Level (Etype (Prefix (Obj)));
10400 return Object_Access_Level (Prefix (Obj));
10403 elsif Nkind (Obj) = N_Indexed_Component then
10404 if Is_Access_Type (Etype (Prefix (Obj))) then
10405 return Type_Access_Level (Etype (Prefix (Obj)));
10407 return Object_Access_Level (Prefix (Obj));
10410 elsif Nkind (Obj) = N_Explicit_Dereference then
10412 -- If the prefix is a selected access discriminant then we make a
10413 -- recursive call on the prefix, which will in turn check the level
10414 -- of the prefix object of the selected discriminant.
10416 if Nkind (Prefix (Obj)) = N_Selected_Component
10417 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10419 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10421 return Object_Access_Level (Prefix (Obj));
10423 elsif not (Comes_From_Source (Obj)) then
10425 Ref : constant Node_Id := Reference_To (Obj);
10427 if Present (Ref) then
10428 return Object_Access_Level (Ref);
10430 return Type_Access_Level (Etype (Prefix (Obj)));
10435 return Type_Access_Level (Etype (Prefix (Obj)));
10438 elsif Nkind (Obj) = N_Type_Conversion
10439 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10441 return Object_Access_Level (Expression (Obj));
10443 elsif Nkind (Obj) = N_Function_Call then
10445 -- Function results are objects, so we get either the access level of
10446 -- the function or, in the case of an indirect call, the level of the
10447 -- access-to-subprogram type. (This code is used for Ada 95, but it
10448 -- looks wrong, because it seems that we should be checking the level
10449 -- of the call itself, even for Ada 95. However, using the Ada 2005
10450 -- version of the code causes regressions in several tests that are
10451 -- compiled with -gnat95. ???)
10453 if Ada_Version < Ada_2005 then
10454 if Is_Entity_Name (Name (Obj)) then
10455 return Subprogram_Access_Level (Entity (Name (Obj)));
10457 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10460 -- For Ada 2005, the level of the result object of a function call is
10461 -- defined to be the level of the call's innermost enclosing master.
10462 -- We determine that by querying the depth of the innermost enclosing
10466 Return_Master_Scope_Depth_Of_Call : declare
10468 function Innermost_Master_Scope_Depth
10469 (N : Node_Id) return Uint;
10470 -- Returns the scope depth of the given node's innermost
10471 -- enclosing dynamic scope (effectively the accessibility
10472 -- level of the innermost enclosing master).
10474 ----------------------------------
10475 -- Innermost_Master_Scope_Depth --
10476 ----------------------------------
10478 function Innermost_Master_Scope_Depth
10479 (N : Node_Id) return Uint
10481 Node_Par : Node_Id := Parent (N);
10484 -- Locate the nearest enclosing node (by traversing Parents)
10485 -- that Defining_Entity can be applied to, and return the
10486 -- depth of that entity's nearest enclosing dynamic scope.
10488 while Present (Node_Par) loop
10489 case Nkind (Node_Par) is
10490 when N_Component_Declaration |
10491 N_Entry_Declaration |
10492 N_Formal_Object_Declaration |
10493 N_Formal_Type_Declaration |
10494 N_Full_Type_Declaration |
10495 N_Incomplete_Type_Declaration |
10496 N_Loop_Parameter_Specification |
10497 N_Object_Declaration |
10498 N_Protected_Type_Declaration |
10499 N_Private_Extension_Declaration |
10500 N_Private_Type_Declaration |
10501 N_Subtype_Declaration |
10502 N_Function_Specification |
10503 N_Procedure_Specification |
10504 N_Task_Type_Declaration |
10506 N_Generic_Instantiation |
10508 N_Implicit_Label_Declaration |
10509 N_Package_Declaration |
10510 N_Single_Task_Declaration |
10511 N_Subprogram_Declaration |
10512 N_Generic_Declaration |
10513 N_Renaming_Declaration |
10514 N_Block_Statement |
10515 N_Formal_Subprogram_Declaration |
10516 N_Abstract_Subprogram_Declaration |
10518 N_Exception_Declaration |
10519 N_Formal_Package_Declaration |
10520 N_Number_Declaration |
10521 N_Package_Specification |
10522 N_Parameter_Specification |
10523 N_Single_Protected_Declaration |
10527 (Nearest_Dynamic_Scope
10528 (Defining_Entity (Node_Par)));
10534 Node_Par := Parent (Node_Par);
10537 pragma Assert (False);
10539 -- Should never reach the following return
10541 return Scope_Depth (Current_Scope) + 1;
10542 end Innermost_Master_Scope_Depth;
10544 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10547 return Innermost_Master_Scope_Depth (Obj);
10548 end Return_Master_Scope_Depth_Of_Call;
10551 -- For convenience we handle qualified expressions, even though
10552 -- they aren't technically object names.
10554 elsif Nkind (Obj) = N_Qualified_Expression then
10555 return Object_Access_Level (Expression (Obj));
10557 -- Otherwise return the scope level of Standard.
10558 -- (If there are cases that fall through
10559 -- to this point they will be treated as
10560 -- having global accessibility for now. ???)
10563 return Scope_Depth (Standard_Standard);
10565 end Object_Access_Level;
10567 --------------------------------------
10568 -- Original_Corresponding_Operation --
10569 --------------------------------------
10571 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10573 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10576 -- If S is an inherited primitive S2 the original corresponding
10577 -- operation of S is the original corresponding operation of S2
10579 if Present (Alias (S))
10580 and then Find_Dispatching_Type (Alias (S)) /= Typ
10582 return Original_Corresponding_Operation (Alias (S));
10584 -- If S overrides an inherited subprogram S2 the original corresponding
10585 -- operation of S is the original corresponding operation of S2
10587 elsif Present (Overridden_Operation (S)) then
10588 return Original_Corresponding_Operation (Overridden_Operation (S));
10590 -- otherwise it is S itself
10595 end Original_Corresponding_Operation;
10597 -----------------------
10598 -- Private_Component --
10599 -----------------------
10601 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10602 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10604 function Trace_Components
10606 Check : Boolean) return Entity_Id;
10607 -- Recursive function that does the work, and checks against circular
10608 -- definition for each subcomponent type.
10610 ----------------------
10611 -- Trace_Components --
10612 ----------------------
10614 function Trace_Components
10616 Check : Boolean) return Entity_Id
10618 Btype : constant Entity_Id := Base_Type (T);
10619 Component : Entity_Id;
10621 Candidate : Entity_Id := Empty;
10624 if Check and then Btype = Ancestor then
10625 Error_Msg_N ("circular type definition", Type_Id);
10629 if Is_Private_Type (Btype)
10630 and then not Is_Generic_Type (Btype)
10632 if Present (Full_View (Btype))
10633 and then Is_Record_Type (Full_View (Btype))
10634 and then not Is_Frozen (Btype)
10636 -- To indicate that the ancestor depends on a private type, the
10637 -- current Btype is sufficient. However, to check for circular
10638 -- definition we must recurse on the full view.
10640 Candidate := Trace_Components (Full_View (Btype), True);
10642 if Candidate = Any_Type then
10652 elsif Is_Array_Type (Btype) then
10653 return Trace_Components (Component_Type (Btype), True);
10655 elsif Is_Record_Type (Btype) then
10656 Component := First_Entity (Btype);
10657 while Present (Component) loop
10659 -- Skip anonymous types generated by constrained components
10661 if not Is_Type (Component) then
10662 P := Trace_Components (Etype (Component), True);
10664 if Present (P) then
10665 if P = Any_Type then
10673 Next_Entity (Component);
10681 end Trace_Components;
10683 -- Start of processing for Private_Component
10686 return Trace_Components (Type_Id, False);
10687 end Private_Component;
10689 ---------------------------
10690 -- Primitive_Names_Match --
10691 ---------------------------
10693 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10695 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10696 -- Given an internal name, returns the corresponding non-internal name
10698 ------------------------
10699 -- Non_Internal_Name --
10700 ------------------------
10702 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10704 Get_Name_String (Chars (E));
10705 Name_Len := Name_Len - 1;
10707 end Non_Internal_Name;
10709 -- Start of processing for Primitive_Names_Match
10712 pragma Assert (Present (E1) and then Present (E2));
10714 return Chars (E1) = Chars (E2)
10716 (not Is_Internal_Name (Chars (E1))
10717 and then Is_Internal_Name (Chars (E2))
10718 and then Non_Internal_Name (E2) = Chars (E1))
10720 (not Is_Internal_Name (Chars (E2))
10721 and then Is_Internal_Name (Chars (E1))
10722 and then Non_Internal_Name (E1) = Chars (E2))
10724 (Is_Predefined_Dispatching_Operation (E1)
10725 and then Is_Predefined_Dispatching_Operation (E2)
10726 and then Same_TSS (E1, E2))
10728 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10729 end Primitive_Names_Match;
10731 -----------------------
10732 -- Process_End_Label --
10733 -----------------------
10735 procedure Process_End_Label
10744 Label_Ref : Boolean;
10745 -- Set True if reference to end label itself is required
10748 -- Gets set to the operator symbol or identifier that references the
10749 -- entity Ent. For the child unit case, this is the identifier from the
10750 -- designator. For other cases, this is simply Endl.
10752 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10753 -- N is an identifier node that appears as a parent unit reference in
10754 -- the case where Ent is a child unit. This procedure generates an
10755 -- appropriate cross-reference entry. E is the corresponding entity.
10757 -------------------------
10758 -- Generate_Parent_Ref --
10759 -------------------------
10761 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10763 -- If names do not match, something weird, skip reference
10765 if Chars (E) = Chars (N) then
10767 -- Generate the reference. We do NOT consider this as a reference
10768 -- for unreferenced symbol purposes.
10770 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10772 if Style_Check then
10773 Style.Check_Identifier (N, E);
10776 end Generate_Parent_Ref;
10778 -- Start of processing for Process_End_Label
10781 -- If no node, ignore. This happens in some error situations, and
10782 -- also for some internally generated structures where no end label
10783 -- references are required in any case.
10789 -- Nothing to do if no End_Label, happens for internally generated
10790 -- constructs where we don't want an end label reference anyway. Also
10791 -- nothing to do if Endl is a string literal, which means there was
10792 -- some prior error (bad operator symbol)
10794 Endl := End_Label (N);
10796 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10800 -- Reference node is not in extended main source unit
10802 if not In_Extended_Main_Source_Unit (N) then
10804 -- Generally we do not collect references except for the extended
10805 -- main source unit. The one exception is the 'e' entry for a
10806 -- package spec, where it is useful for a client to have the
10807 -- ending information to define scopes.
10813 Label_Ref := False;
10815 -- For this case, we can ignore any parent references, but we
10816 -- need the package name itself for the 'e' entry.
10818 if Nkind (Endl) = N_Designator then
10819 Endl := Identifier (Endl);
10823 -- Reference is in extended main source unit
10828 -- For designator, generate references for the parent entries
10830 if Nkind (Endl) = N_Designator then
10832 -- Generate references for the prefix if the END line comes from
10833 -- source (otherwise we do not need these references) We climb the
10834 -- scope stack to find the expected entities.
10836 if Comes_From_Source (Endl) then
10837 Nam := Name (Endl);
10838 Scop := Current_Scope;
10839 while Nkind (Nam) = N_Selected_Component loop
10840 Scop := Scope (Scop);
10841 exit when No (Scop);
10842 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10843 Nam := Prefix (Nam);
10846 if Present (Scop) then
10847 Generate_Parent_Ref (Nam, Scope (Scop));
10851 Endl := Identifier (Endl);
10855 -- If the end label is not for the given entity, then either we have
10856 -- some previous error, or this is a generic instantiation for which
10857 -- we do not need to make a cross-reference in this case anyway. In
10858 -- either case we simply ignore the call.
10860 if Chars (Ent) /= Chars (Endl) then
10864 -- If label was really there, then generate a normal reference and then
10865 -- adjust the location in the end label to point past the name (which
10866 -- should almost always be the semicolon).
10868 Loc := Sloc (Endl);
10870 if Comes_From_Source (Endl) then
10872 -- If a label reference is required, then do the style check and
10873 -- generate an l-type cross-reference entry for the label
10876 if Style_Check then
10877 Style.Check_Identifier (Endl, Ent);
10880 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10883 -- Set the location to point past the label (normally this will
10884 -- mean the semicolon immediately following the label). This is
10885 -- done for the sake of the 'e' or 't' entry generated below.
10887 Get_Decoded_Name_String (Chars (Endl));
10888 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10891 -- In SPARK mode, no missing label is allowed for packages and
10892 -- subprogram bodies. Detect those cases by testing whether
10893 -- Process_End_Label was called for a body (Typ = 't') or a package.
10895 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
10896 and then (Typ = 't' or else Ekind (Ent) = E_Package)
10898 Error_Msg_Node_1 := Endl;
10899 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
10903 -- Now generate the e/t reference
10905 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10907 -- Restore Sloc, in case modified above, since we have an identifier
10908 -- and the normal Sloc should be left set in the tree.
10910 Set_Sloc (Endl, Loc);
10911 end Process_End_Label;
10913 ------------------------------------
10914 -- References_Generic_Formal_Type --
10915 ------------------------------------
10917 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10919 function Process (N : Node_Id) return Traverse_Result;
10920 -- Process one node in search for generic formal type
10926 function Process (N : Node_Id) return Traverse_Result is
10928 if Nkind (N) in N_Has_Entity then
10930 E : constant Entity_Id := Entity (N);
10932 if Present (E) then
10933 if Is_Generic_Type (E) then
10935 elsif Present (Etype (E))
10936 and then Is_Generic_Type (Etype (E))
10947 function Traverse is new Traverse_Func (Process);
10948 -- Traverse tree to look for generic type
10951 if Inside_A_Generic then
10952 return Traverse (N) = Abandon;
10956 end References_Generic_Formal_Type;
10958 --------------------
10959 -- Remove_Homonym --
10960 --------------------
10962 procedure Remove_Homonym (E : Entity_Id) is
10963 Prev : Entity_Id := Empty;
10967 if E = Current_Entity (E) then
10968 if Present (Homonym (E)) then
10969 Set_Current_Entity (Homonym (E));
10971 Set_Name_Entity_Id (Chars (E), Empty);
10974 H := Current_Entity (E);
10975 while Present (H) and then H /= E loop
10980 Set_Homonym (Prev, Homonym (E));
10982 end Remove_Homonym;
10984 ---------------------
10985 -- Rep_To_Pos_Flag --
10986 ---------------------
10988 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10990 return New_Occurrence_Of
10991 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10992 end Rep_To_Pos_Flag;
10994 --------------------
10995 -- Require_Entity --
10996 --------------------
10998 procedure Require_Entity (N : Node_Id) is
11000 if Is_Entity_Name (N) and then No (Entity (N)) then
11001 if Total_Errors_Detected /= 0 then
11002 Set_Entity (N, Any_Id);
11004 raise Program_Error;
11007 end Require_Entity;
11009 ------------------------------
11010 -- Requires_Transient_Scope --
11011 ------------------------------
11013 -- A transient scope is required when variable-sized temporaries are
11014 -- allocated in the primary or secondary stack, or when finalization
11015 -- actions must be generated before the next instruction.
11017 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
11018 Typ : constant Entity_Id := Underlying_Type (Id);
11020 -- Start of processing for Requires_Transient_Scope
11023 -- This is a private type which is not completed yet. This can only
11024 -- happen in a default expression (of a formal parameter or of a
11025 -- record component). Do not expand transient scope in this case
11030 -- Do not expand transient scope for non-existent procedure return
11032 elsif Typ = Standard_Void_Type then
11035 -- Elementary types do not require a transient scope
11037 elsif Is_Elementary_Type (Typ) then
11040 -- Generally, indefinite subtypes require a transient scope, since the
11041 -- back end cannot generate temporaries, since this is not a valid type
11042 -- for declaring an object. It might be possible to relax this in the
11043 -- future, e.g. by declaring the maximum possible space for the type.
11045 elsif Is_Indefinite_Subtype (Typ) then
11048 -- Functions returning tagged types may dispatch on result so their
11049 -- returned value is allocated on the secondary stack. Controlled
11050 -- type temporaries need finalization.
11052 elsif Is_Tagged_Type (Typ)
11053 or else Has_Controlled_Component (Typ)
11055 return not Is_Value_Type (Typ);
11059 elsif Is_Record_Type (Typ) then
11063 Comp := First_Entity (Typ);
11064 while Present (Comp) loop
11065 if Ekind (Comp) = E_Component
11066 and then Requires_Transient_Scope (Etype (Comp))
11070 Next_Entity (Comp);
11077 -- String literal types never require transient scope
11079 elsif Ekind (Typ) = E_String_Literal_Subtype then
11082 -- Array type. Note that we already know that this is a constrained
11083 -- array, since unconstrained arrays will fail the indefinite test.
11085 elsif Is_Array_Type (Typ) then
11087 -- If component type requires a transient scope, the array does too
11089 if Requires_Transient_Scope (Component_Type (Typ)) then
11092 -- Otherwise, we only need a transient scope if the size depends on
11093 -- the value of one or more discriminants.
11096 return Size_Depends_On_Discriminant (Typ);
11099 -- All other cases do not require a transient scope
11104 end Requires_Transient_Scope;
11106 --------------------------
11107 -- Reset_Analyzed_Flags --
11108 --------------------------
11110 procedure Reset_Analyzed_Flags (N : Node_Id) is
11112 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11113 -- Function used to reset Analyzed flags in tree. Note that we do
11114 -- not reset Analyzed flags in entities, since there is no need to
11115 -- reanalyze entities, and indeed, it is wrong to do so, since it
11116 -- can result in generating auxiliary stuff more than once.
11118 --------------------
11119 -- Clear_Analyzed --
11120 --------------------
11122 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11124 if not Has_Extension (N) then
11125 Set_Analyzed (N, False);
11129 end Clear_Analyzed;
11131 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11133 -- Start of processing for Reset_Analyzed_Flags
11136 Reset_Analyzed (N);
11137 end Reset_Analyzed_Flags;
11139 ---------------------------
11140 -- Safe_To_Capture_Value --
11141 ---------------------------
11143 function Safe_To_Capture_Value
11146 Cond : Boolean := False) return Boolean
11149 -- The only entities for which we track constant values are variables
11150 -- which are not renamings, constants, out parameters, and in out
11151 -- parameters, so check if we have this case.
11153 -- Note: it may seem odd to track constant values for constants, but in
11154 -- fact this routine is used for other purposes than simply capturing
11155 -- the value. In particular, the setting of Known[_Non]_Null.
11157 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11159 Ekind (Ent) = E_Constant
11161 Ekind (Ent) = E_Out_Parameter
11163 Ekind (Ent) = E_In_Out_Parameter
11167 -- For conditionals, we also allow loop parameters and all formals,
11168 -- including in parameters.
11172 (Ekind (Ent) = E_Loop_Parameter
11174 Ekind (Ent) = E_In_Parameter)
11178 -- For all other cases, not just unsafe, but impossible to capture
11179 -- Current_Value, since the above are the only entities which have
11180 -- Current_Value fields.
11186 -- Skip if volatile or aliased, since funny things might be going on in
11187 -- these cases which we cannot necessarily track. Also skip any variable
11188 -- for which an address clause is given, or whose address is taken. Also
11189 -- never capture value of library level variables (an attempt to do so
11190 -- can occur in the case of package elaboration code).
11192 if Treat_As_Volatile (Ent)
11193 or else Is_Aliased (Ent)
11194 or else Present (Address_Clause (Ent))
11195 or else Address_Taken (Ent)
11196 or else (Is_Library_Level_Entity (Ent)
11197 and then Ekind (Ent) = E_Variable)
11202 -- OK, all above conditions are met. We also require that the scope of
11203 -- the reference be the same as the scope of the entity, not counting
11204 -- packages and blocks and loops.
11207 E_Scope : constant Entity_Id := Scope (Ent);
11208 R_Scope : Entity_Id;
11211 R_Scope := Current_Scope;
11212 while R_Scope /= Standard_Standard loop
11213 exit when R_Scope = E_Scope;
11215 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11218 R_Scope := Scope (R_Scope);
11223 -- We also require that the reference does not appear in a context
11224 -- where it is not sure to be executed (i.e. a conditional context
11225 -- or an exception handler). We skip this if Cond is True, since the
11226 -- capturing of values from conditional tests handles this ok.
11240 while Present (P) loop
11241 if Nkind (P) = N_If_Statement
11242 or else Nkind (P) = N_Case_Statement
11243 or else (Nkind (P) in N_Short_Circuit
11244 and then Desc = Right_Opnd (P))
11245 or else (Nkind (P) = N_Conditional_Expression
11246 and then Desc /= First (Expressions (P)))
11247 or else Nkind (P) = N_Exception_Handler
11248 or else Nkind (P) = N_Selective_Accept
11249 or else Nkind (P) = N_Conditional_Entry_Call
11250 or else Nkind (P) = N_Timed_Entry_Call
11251 or else Nkind (P) = N_Asynchronous_Select
11261 -- OK, looks safe to set value
11264 end Safe_To_Capture_Value;
11270 function Same_Name (N1, N2 : Node_Id) return Boolean is
11271 K1 : constant Node_Kind := Nkind (N1);
11272 K2 : constant Node_Kind := Nkind (N2);
11275 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11276 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11278 return Chars (N1) = Chars (N2);
11280 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11281 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11283 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11284 and then Same_Name (Prefix (N1), Prefix (N2));
11295 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11296 N1 : constant Node_Id := Original_Node (Node1);
11297 N2 : constant Node_Id := Original_Node (Node2);
11298 -- We do the tests on original nodes, since we are most interested
11299 -- in the original source, not any expansion that got in the way.
11301 K1 : constant Node_Kind := Nkind (N1);
11302 K2 : constant Node_Kind := Nkind (N2);
11305 -- First case, both are entities with same entity
11307 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11309 EN1 : constant Entity_Id := Entity (N1);
11310 EN2 : constant Entity_Id := Entity (N2);
11312 if Present (EN1) and then Present (EN2)
11313 and then (Ekind_In (EN1, E_Variable, E_Constant)
11314 or else Is_Formal (EN1))
11322 -- Second case, selected component with same selector, same record
11324 if K1 = N_Selected_Component
11325 and then K2 = N_Selected_Component
11326 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11328 return Same_Object (Prefix (N1), Prefix (N2));
11330 -- Third case, indexed component with same subscripts, same array
11332 elsif K1 = N_Indexed_Component
11333 and then K2 = N_Indexed_Component
11334 and then Same_Object (Prefix (N1), Prefix (N2))
11339 E1 := First (Expressions (N1));
11340 E2 := First (Expressions (N2));
11341 while Present (E1) loop
11342 if not Same_Value (E1, E2) then
11353 -- Fourth case, slice of same array with same bounds
11356 and then K2 = N_Slice
11357 and then Nkind (Discrete_Range (N1)) = N_Range
11358 and then Nkind (Discrete_Range (N2)) = N_Range
11359 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11360 Low_Bound (Discrete_Range (N2)))
11361 and then Same_Value (High_Bound (Discrete_Range (N1)),
11362 High_Bound (Discrete_Range (N2)))
11364 return Same_Name (Prefix (N1), Prefix (N2));
11366 -- All other cases, not clearly the same object
11377 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11382 elsif not Is_Constrained (T1)
11383 and then not Is_Constrained (T2)
11384 and then Base_Type (T1) = Base_Type (T2)
11388 -- For now don't bother with case of identical constraints, to be
11389 -- fiddled with later on perhaps (this is only used for optimization
11390 -- purposes, so it is not critical to do a best possible job)
11401 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11403 if Compile_Time_Known_Value (Node1)
11404 and then Compile_Time_Known_Value (Node2)
11405 and then Expr_Value (Node1) = Expr_Value (Node2)
11408 elsif Same_Object (Node1, Node2) then
11419 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11421 if Ada_Version < Ada_2012 then
11424 elsif Is_Entity_Name (N)
11426 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11428 (Nkind (N) = N_Attribute_Reference
11429 and then Attribute_Name (N) = Name_Access)
11432 -- We are only interested in IN OUT parameters of inner calls
11435 or else Nkind (Parent (N)) = N_Function_Call
11436 or else Nkind (Parent (N)) in N_Op
11438 Actuals_In_Call.Increment_Last;
11439 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11444 ------------------------
11445 -- Scope_Is_Transient --
11446 ------------------------
11448 function Scope_Is_Transient return Boolean is
11450 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11451 end Scope_Is_Transient;
11457 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11462 while Scop /= Standard_Standard loop
11463 Scop := Scope (Scop);
11465 if Scop = Scope2 then
11473 --------------------------
11474 -- Scope_Within_Or_Same --
11475 --------------------------
11477 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11482 while Scop /= Standard_Standard loop
11483 if Scop = Scope2 then
11486 Scop := Scope (Scop);
11491 end Scope_Within_Or_Same;
11493 --------------------
11494 -- Set_Convention --
11495 --------------------
11497 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11499 Basic_Set_Convention (E, Val);
11502 and then Is_Access_Subprogram_Type (Base_Type (E))
11503 and then Has_Foreign_Convention (E)
11505 Set_Can_Use_Internal_Rep (E, False);
11507 end Set_Convention;
11509 ------------------------
11510 -- Set_Current_Entity --
11511 ------------------------
11513 -- The given entity is to be set as the currently visible definition
11514 -- of its associated name (i.e. the Node_Id associated with its name).
11515 -- All we have to do is to get the name from the identifier, and
11516 -- then set the associated Node_Id to point to the given entity.
11518 procedure Set_Current_Entity (E : Entity_Id) is
11520 Set_Name_Entity_Id (Chars (E), E);
11521 end Set_Current_Entity;
11523 ---------------------------
11524 -- Set_Debug_Info_Needed --
11525 ---------------------------
11527 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11529 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11530 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11531 -- Used to set debug info in a related node if not set already
11533 --------------------------------------
11534 -- Set_Debug_Info_Needed_If_Not_Set --
11535 --------------------------------------
11537 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11540 and then not Needs_Debug_Info (E)
11542 Set_Debug_Info_Needed (E);
11544 -- For a private type, indicate that the full view also needs
11545 -- debug information.
11548 and then Is_Private_Type (E)
11549 and then Present (Full_View (E))
11551 Set_Debug_Info_Needed (Full_View (E));
11554 end Set_Debug_Info_Needed_If_Not_Set;
11556 -- Start of processing for Set_Debug_Info_Needed
11559 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11560 -- indicates that Debug_Info_Needed is never required for the entity.
11563 or else Debug_Info_Off (T)
11568 -- Set flag in entity itself. Note that we will go through the following
11569 -- circuitry even if the flag is already set on T. That's intentional,
11570 -- it makes sure that the flag will be set in subsidiary entities.
11572 Set_Needs_Debug_Info (T);
11574 -- Set flag on subsidiary entities if not set already
11576 if Is_Object (T) then
11577 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11579 elsif Is_Type (T) then
11580 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11582 if Is_Record_Type (T) then
11584 Ent : Entity_Id := First_Entity (T);
11586 while Present (Ent) loop
11587 Set_Debug_Info_Needed_If_Not_Set (Ent);
11592 -- For a class wide subtype, we also need debug information
11593 -- for the equivalent type.
11595 if Ekind (T) = E_Class_Wide_Subtype then
11596 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11599 elsif Is_Array_Type (T) then
11600 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11603 Indx : Node_Id := First_Index (T);
11605 while Present (Indx) loop
11606 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11607 Indx := Next_Index (Indx);
11611 if Is_Packed (T) then
11612 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11615 elsif Is_Access_Type (T) then
11616 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11618 elsif Is_Private_Type (T) then
11619 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11621 elsif Is_Protected_Type (T) then
11622 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11625 end Set_Debug_Info_Needed;
11627 ---------------------------------
11628 -- Set_Entity_With_Style_Check --
11629 ---------------------------------
11631 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11632 Val_Actual : Entity_Id;
11636 Set_Entity (N, Val);
11639 and then not Suppress_Style_Checks (Val)
11640 and then not In_Instance
11642 if Nkind (N) = N_Identifier then
11644 elsif Nkind (N) = N_Expanded_Name then
11645 Nod := Selector_Name (N);
11650 -- A special situation arises for derived operations, where we want
11651 -- to do the check against the parent (since the Sloc of the derived
11652 -- operation points to the derived type declaration itself).
11655 while not Comes_From_Source (Val_Actual)
11656 and then Nkind (Val_Actual) in N_Entity
11657 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11658 or else Is_Subprogram (Val_Actual)
11659 or else Is_Generic_Subprogram (Val_Actual))
11660 and then Present (Alias (Val_Actual))
11662 Val_Actual := Alias (Val_Actual);
11665 -- Renaming declarations for generic actuals do not come from source,
11666 -- and have a different name from that of the entity they rename, so
11667 -- there is no style check to perform here.
11669 if Chars (Nod) = Chars (Val_Actual) then
11670 Style.Check_Identifier (Nod, Val_Actual);
11674 Set_Entity (N, Val);
11675 end Set_Entity_With_Style_Check;
11677 ------------------------
11678 -- Set_Name_Entity_Id --
11679 ------------------------
11681 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11683 Set_Name_Table_Info (Id, Int (Val));
11684 end Set_Name_Entity_Id;
11686 ---------------------
11687 -- Set_Next_Actual --
11688 ---------------------
11690 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11692 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11693 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11695 end Set_Next_Actual;
11697 ----------------------------------
11698 -- Set_Optimize_Alignment_Flags --
11699 ----------------------------------
11701 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11703 if Optimize_Alignment = 'S' then
11704 Set_Optimize_Alignment_Space (E);
11705 elsif Optimize_Alignment = 'T' then
11706 Set_Optimize_Alignment_Time (E);
11708 end Set_Optimize_Alignment_Flags;
11710 -----------------------
11711 -- Set_Public_Status --
11712 -----------------------
11714 procedure Set_Public_Status (Id : Entity_Id) is
11715 S : constant Entity_Id := Current_Scope;
11717 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11718 -- Determines if E is defined within handled statement sequence or
11719 -- an if statement, returns True if so, False otherwise.
11721 ----------------------
11722 -- Within_HSS_Or_If --
11723 ----------------------
11725 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11728 N := Declaration_Node (E);
11735 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11741 end Within_HSS_Or_If;
11743 -- Start of processing for Set_Public_Status
11746 -- Everything in the scope of Standard is public
11748 if S = Standard_Standard then
11749 Set_Is_Public (Id);
11751 -- Entity is definitely not public if enclosing scope is not public
11753 elsif not Is_Public (S) then
11756 -- An object or function declaration that occurs in a handled sequence
11757 -- of statements or within an if statement is the declaration for a
11758 -- temporary object or local subprogram generated by the expander. It
11759 -- never needs to be made public and furthermore, making it public can
11760 -- cause back end problems.
11762 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11763 N_Function_Specification)
11764 and then Within_HSS_Or_If (Id)
11768 -- Entities in public packages or records are public
11770 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11771 Set_Is_Public (Id);
11773 -- The bounds of an entry family declaration can generate object
11774 -- declarations that are visible to the back-end, e.g. in the
11775 -- the declaration of a composite type that contains tasks.
11777 elsif Is_Concurrent_Type (S)
11778 and then not Has_Completion (S)
11779 and then Nkind (Parent (Id)) = N_Object_Declaration
11781 Set_Is_Public (Id);
11783 end Set_Public_Status;
11785 -----------------------------
11786 -- Set_Referenced_Modified --
11787 -----------------------------
11789 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11793 -- Deal with indexed or selected component where prefix is modified
11795 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11796 Pref := Prefix (N);
11798 -- If prefix is access type, then it is the designated object that is
11799 -- being modified, which means we have no entity to set the flag on.
11801 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11804 -- Otherwise chase the prefix
11807 Set_Referenced_Modified (Pref, Out_Param);
11810 -- Otherwise see if we have an entity name (only other case to process)
11812 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11813 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11814 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11816 end Set_Referenced_Modified;
11818 ----------------------------
11819 -- Set_Scope_Is_Transient --
11820 ----------------------------
11822 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11824 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11825 end Set_Scope_Is_Transient;
11827 -------------------
11828 -- Set_Size_Info --
11829 -------------------
11831 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11833 -- We copy Esize, but not RM_Size, since in general RM_Size is
11834 -- subtype specific and does not get inherited by all subtypes.
11836 Set_Esize (T1, Esize (T2));
11837 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11839 if Is_Discrete_Or_Fixed_Point_Type (T1)
11841 Is_Discrete_Or_Fixed_Point_Type (T2)
11843 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11846 Set_Alignment (T1, Alignment (T2));
11849 --------------------
11850 -- Static_Boolean --
11851 --------------------
11853 function Static_Boolean (N : Node_Id) return Uint is
11855 Analyze_And_Resolve (N, Standard_Boolean);
11858 or else Error_Posted (N)
11859 or else Etype (N) = Any_Type
11864 if Is_Static_Expression (N) then
11865 if not Raises_Constraint_Error (N) then
11866 return Expr_Value (N);
11871 elsif Etype (N) = Any_Type then
11875 Flag_Non_Static_Expr
11876 ("static boolean expression required here", N);
11879 end Static_Boolean;
11881 --------------------
11882 -- Static_Integer --
11883 --------------------
11885 function Static_Integer (N : Node_Id) return Uint is
11887 Analyze_And_Resolve (N, Any_Integer);
11890 or else Error_Posted (N)
11891 or else Etype (N) = Any_Type
11896 if Is_Static_Expression (N) then
11897 if not Raises_Constraint_Error (N) then
11898 return Expr_Value (N);
11903 elsif Etype (N) = Any_Type then
11907 Flag_Non_Static_Expr
11908 ("static integer expression required here", N);
11911 end Static_Integer;
11913 --------------------------
11914 -- Statically_Different --
11915 --------------------------
11917 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11918 R1 : constant Node_Id := Get_Referenced_Object (E1);
11919 R2 : constant Node_Id := Get_Referenced_Object (E2);
11921 return Is_Entity_Name (R1)
11922 and then Is_Entity_Name (R2)
11923 and then Entity (R1) /= Entity (R2)
11924 and then not Is_Formal (Entity (R1))
11925 and then not Is_Formal (Entity (R2));
11926 end Statically_Different;
11928 -----------------------------
11929 -- Subprogram_Access_Level --
11930 -----------------------------
11932 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11934 if Present (Alias (Subp)) then
11935 return Subprogram_Access_Level (Alias (Subp));
11937 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11939 end Subprogram_Access_Level;
11945 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11947 if Debug_Flag_W then
11948 for J in 0 .. Scope_Stack.Last loop
11953 Write_Name (Chars (E));
11954 Write_Str (" from ");
11955 Write_Location (Sloc (N));
11960 -----------------------
11961 -- Transfer_Entities --
11962 -----------------------
11964 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11965 Ent : Entity_Id := First_Entity (From);
11972 if (Last_Entity (To)) = Empty then
11973 Set_First_Entity (To, Ent);
11975 Set_Next_Entity (Last_Entity (To), Ent);
11978 Set_Last_Entity (To, Last_Entity (From));
11980 while Present (Ent) loop
11981 Set_Scope (Ent, To);
11983 if not Is_Public (Ent) then
11984 Set_Public_Status (Ent);
11987 and then Ekind (Ent) = E_Record_Subtype
11990 -- The components of the propagated Itype must be public
11996 Comp := First_Entity (Ent);
11997 while Present (Comp) loop
11998 Set_Is_Public (Comp);
11999 Next_Entity (Comp);
12008 Set_First_Entity (From, Empty);
12009 Set_Last_Entity (From, Empty);
12010 end Transfer_Entities;
12012 -----------------------
12013 -- Type_Access_Level --
12014 -----------------------
12016 function Type_Access_Level (Typ : Entity_Id) return Uint is
12020 Btyp := Base_Type (Typ);
12022 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
12023 -- simply use the level where the type is declared. This is true for
12024 -- stand-alone object declarations, and for anonymous access types
12025 -- associated with components the level is the same as that of the
12026 -- enclosing composite type. However, special treatment is needed for
12027 -- the cases of access parameters, return objects of an anonymous access
12028 -- type, and, in Ada 95, access discriminants of limited types.
12030 if Ekind (Btyp) in Access_Kind then
12031 if Ekind (Btyp) = E_Anonymous_Access_Type then
12033 -- If the type is a nonlocal anonymous access type (such as for
12034 -- an access parameter) we treat it as being declared at the
12035 -- library level to ensure that names such as X.all'access don't
12036 -- fail static accessibility checks.
12038 if not Is_Local_Anonymous_Access (Typ) then
12039 return Scope_Depth (Standard_Standard);
12041 -- If this is a return object, the accessibility level is that of
12042 -- the result subtype of the enclosing function. The test here is
12043 -- little complicated, because we have to account for extended
12044 -- return statements that have been rewritten as blocks, in which
12045 -- case we have to find and the Is_Return_Object attribute of the
12046 -- itype's associated object. It would be nice to find a way to
12047 -- simplify this test, but it doesn't seem worthwhile to add a new
12048 -- flag just for purposes of this test. ???
12050 elsif Ekind (Scope (Btyp)) = E_Return_Statement
12053 and then Nkind (Associated_Node_For_Itype (Btyp)) =
12054 N_Object_Declaration
12055 and then Is_Return_Object
12056 (Defining_Identifier
12057 (Associated_Node_For_Itype (Btyp))))
12063 Scop := Scope (Scope (Btyp));
12064 while Present (Scop) loop
12065 exit when Ekind (Scop) = E_Function;
12066 Scop := Scope (Scop);
12069 -- Treat the return object's type as having the level of the
12070 -- function's result subtype (as per RM05-6.5(5.3/2)).
12072 return Type_Access_Level (Etype (Scop));
12077 Btyp := Root_Type (Btyp);
12079 -- The accessibility level of anonymous access types associated with
12080 -- discriminants is that of the current instance of the type, and
12081 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
12083 -- AI-402: access discriminants have accessibility based on the
12084 -- object rather than the type in Ada 2005, so the above paragraph
12087 -- ??? Needs completion with rules from AI-416
12089 if Ada_Version <= Ada_95
12090 and then Ekind (Typ) = E_Anonymous_Access_Type
12091 and then Present (Associated_Node_For_Itype (Typ))
12092 and then Nkind (Associated_Node_For_Itype (Typ)) =
12093 N_Discriminant_Specification
12095 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
12099 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
12100 end Type_Access_Level;
12102 --------------------------
12103 -- Unit_Declaration_Node --
12104 --------------------------
12106 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12107 N : Node_Id := Parent (Unit_Id);
12110 -- Predefined operators do not have a full function declaration
12112 if Ekind (Unit_Id) = E_Operator then
12116 -- Isn't there some better way to express the following ???
12118 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12119 and then Nkind (N) /= N_Formal_Package_Declaration
12120 and then Nkind (N) /= N_Function_Instantiation
12121 and then Nkind (N) /= N_Generic_Package_Declaration
12122 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12123 and then Nkind (N) /= N_Package_Declaration
12124 and then Nkind (N) /= N_Package_Body
12125 and then Nkind (N) /= N_Package_Instantiation
12126 and then Nkind (N) /= N_Package_Renaming_Declaration
12127 and then Nkind (N) /= N_Procedure_Instantiation
12128 and then Nkind (N) /= N_Protected_Body
12129 and then Nkind (N) /= N_Subprogram_Declaration
12130 and then Nkind (N) /= N_Subprogram_Body
12131 and then Nkind (N) /= N_Subprogram_Body_Stub
12132 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12133 and then Nkind (N) /= N_Task_Body
12134 and then Nkind (N) /= N_Task_Type_Declaration
12135 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12136 and then Nkind (N) not in N_Generic_Renaming_Declaration
12139 pragma Assert (Present (N));
12143 end Unit_Declaration_Node;
12145 ---------------------
12146 -- Unit_Is_Visible --
12147 ---------------------
12149 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12150 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12151 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12153 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12154 -- For a child unit, check whether unit appears in a with_clause
12157 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12158 -- Scan the context clause of one compilation unit looking for a
12159 -- with_clause for the unit in question.
12161 ----------------------------
12162 -- Unit_In_Parent_Context --
12163 ----------------------------
12165 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12167 if Unit_In_Context (Par_Unit) then
12170 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12171 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12176 end Unit_In_Parent_Context;
12178 ---------------------
12179 -- Unit_In_Context --
12180 ---------------------
12182 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12186 Clause := First (Context_Items (Comp_Unit));
12187 while Present (Clause) loop
12188 if Nkind (Clause) = N_With_Clause then
12189 if Library_Unit (Clause) = U then
12192 -- The with_clause may denote a renaming of the unit we are
12193 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12196 Renamed_Entity (Entity (Name (Clause))) =
12197 Defining_Entity (Unit (U))
12207 end Unit_In_Context;
12209 -- Start of processing for Unit_Is_Visible
12212 -- The currrent unit is directly visible.
12217 elsif Unit_In_Context (Curr) then
12220 -- If the current unit is a body, check the context of the spec.
12222 elsif Nkind (Unit (Curr)) = N_Package_Body
12224 (Nkind (Unit (Curr)) = N_Subprogram_Body
12225 and then not Acts_As_Spec (Unit (Curr)))
12227 if Unit_In_Context (Library_Unit (Curr)) then
12232 -- If the spec is a child unit, examine the parents.
12234 if Is_Child_Unit (Curr_Entity) then
12235 if Nkind (Unit (Curr)) in N_Unit_Body then
12237 Unit_In_Parent_Context
12238 (Parent_Spec (Unit (Library_Unit (Curr))));
12240 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12246 end Unit_Is_Visible;
12248 ------------------------------
12249 -- Universal_Interpretation --
12250 ------------------------------
12252 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12253 Index : Interp_Index;
12257 -- The argument may be a formal parameter of an operator or subprogram
12258 -- with multiple interpretations, or else an expression for an actual.
12260 if Nkind (Opnd) = N_Defining_Identifier
12261 or else not Is_Overloaded (Opnd)
12263 if Etype (Opnd) = Universal_Integer
12264 or else Etype (Opnd) = Universal_Real
12266 return Etype (Opnd);
12272 Get_First_Interp (Opnd, Index, It);
12273 while Present (It.Typ) loop
12274 if It.Typ = Universal_Integer
12275 or else It.Typ = Universal_Real
12280 Get_Next_Interp (Index, It);
12285 end Universal_Interpretation;
12291 function Unqualify (Expr : Node_Id) return Node_Id is
12293 -- Recurse to handle unlikely case of multiple levels of qualification
12295 if Nkind (Expr) = N_Qualified_Expression then
12296 return Unqualify (Expression (Expr));
12298 -- Normal case, not a qualified expression
12305 -----------------------
12306 -- Visible_Ancestors --
12307 -----------------------
12309 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12315 pragma Assert (Is_Record_Type (Typ)
12316 and then Is_Tagged_Type (Typ));
12318 -- Collect all the parents and progenitors of Typ. If the full-view of
12319 -- private parents and progenitors is available then it is used to
12320 -- generate the list of visible ancestors; otherwise their partial
12321 -- view is added to the resulting list.
12326 Use_Full_View => True);
12330 Ifaces_List => List_2,
12331 Exclude_Parents => True,
12332 Use_Full_View => True);
12334 -- Join the two lists. Avoid duplications because an interface may
12335 -- simultaneously be parent and progenitor of a type.
12337 Elmt := First_Elmt (List_2);
12338 while Present (Elmt) loop
12339 Append_Unique_Elmt (Node (Elmt), List_1);
12344 end Visible_Ancestors;
12346 ----------------------
12347 -- Within_Init_Proc --
12348 ----------------------
12350 function Within_Init_Proc return Boolean is
12354 S := Current_Scope;
12355 while not Is_Overloadable (S) loop
12356 if S = Standard_Standard then
12363 return Is_Init_Proc (S);
12364 end Within_Init_Proc;
12370 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12371 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12372 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12374 function Has_One_Matching_Field return Boolean;
12375 -- Determines if Expec_Type is a record type with a single component or
12376 -- discriminant whose type matches the found type or is one dimensional
12377 -- array whose component type matches the found type.
12379 ----------------------------
12380 -- Has_One_Matching_Field --
12381 ----------------------------
12383 function Has_One_Matching_Field return Boolean is
12387 if Is_Array_Type (Expec_Type)
12388 and then Number_Dimensions (Expec_Type) = 1
12390 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12394 elsif not Is_Record_Type (Expec_Type) then
12398 E := First_Entity (Expec_Type);
12403 elsif (Ekind (E) /= E_Discriminant
12404 and then Ekind (E) /= E_Component)
12405 or else (Chars (E) = Name_uTag
12406 or else Chars (E) = Name_uParent)
12415 if not Covers (Etype (E), Found_Type) then
12418 elsif Present (Next_Entity (E)) then
12425 end Has_One_Matching_Field;
12427 -- Start of processing for Wrong_Type
12430 -- Don't output message if either type is Any_Type, or if a message
12431 -- has already been posted for this node. We need to do the latter
12432 -- check explicitly (it is ordinarily done in Errout), because we
12433 -- are using ! to force the output of the error messages.
12435 if Expec_Type = Any_Type
12436 or else Found_Type = Any_Type
12437 or else Error_Posted (Expr)
12441 -- In an instance, there is an ongoing problem with completion of
12442 -- type derived from private types. Their structure is what Gigi
12443 -- expects, but the Etype is the parent type rather than the
12444 -- derived private type itself. Do not flag error in this case. The
12445 -- private completion is an entity without a parent, like an Itype.
12446 -- Similarly, full and partial views may be incorrect in the instance.
12447 -- There is no simple way to insure that it is consistent ???
12449 elsif In_Instance then
12450 if Etype (Etype (Expr)) = Etype (Expected_Type)
12452 (Has_Private_Declaration (Expected_Type)
12453 or else Has_Private_Declaration (Etype (Expr)))
12454 and then No (Parent (Expected_Type))
12460 -- An interesting special check. If the expression is parenthesized
12461 -- and its type corresponds to the type of the sole component of the
12462 -- expected record type, or to the component type of the expected one
12463 -- dimensional array type, then assume we have a bad aggregate attempt.
12465 if Nkind (Expr) in N_Subexpr
12466 and then Paren_Count (Expr) /= 0
12467 and then Has_One_Matching_Field
12469 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12471 -- Another special check, if we are looking for a pool-specific access
12472 -- type and we found an E_Access_Attribute_Type, then we have the case
12473 -- of an Access attribute being used in a context which needs a pool-
12474 -- specific type, which is never allowed. The one extra check we make
12475 -- is that the expected designated type covers the Found_Type.
12477 elsif Is_Access_Type (Expec_Type)
12478 and then Ekind (Found_Type) = E_Access_Attribute_Type
12479 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12480 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12482 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12484 Error_Msg_N -- CODEFIX
12485 ("result must be general access type!", Expr);
12486 Error_Msg_NE -- CODEFIX
12487 ("add ALL to }!", Expr, Expec_Type);
12489 -- Another special check, if the expected type is an integer type,
12490 -- but the expression is of type System.Address, and the parent is
12491 -- an addition or subtraction operation whose left operand is the
12492 -- expression in question and whose right operand is of an integral
12493 -- type, then this is an attempt at address arithmetic, so give
12494 -- appropriate message.
12496 elsif Is_Integer_Type (Expec_Type)
12497 and then Is_RTE (Found_Type, RE_Address)
12498 and then (Nkind (Parent (Expr)) = N_Op_Add
12500 Nkind (Parent (Expr)) = N_Op_Subtract)
12501 and then Expr = Left_Opnd (Parent (Expr))
12502 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12505 ("address arithmetic not predefined in package System",
12508 ("\possible missing with/use of System.Storage_Elements",
12512 -- If the expected type is an anonymous access type, as for access
12513 -- parameters and discriminants, the error is on the designated types.
12515 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12516 if Comes_From_Source (Expec_Type) then
12517 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12520 ("expected an access type with designated}",
12521 Expr, Designated_Type (Expec_Type));
12524 if Is_Access_Type (Found_Type)
12525 and then not Comes_From_Source (Found_Type)
12528 ("\\found an access type with designated}!",
12529 Expr, Designated_Type (Found_Type));
12531 if From_With_Type (Found_Type) then
12532 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12533 Error_Msg_Qual_Level := 99;
12534 Error_Msg_NE -- CODEFIX
12535 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12536 Error_Msg_Qual_Level := 0;
12538 Error_Msg_NE ("found}!", Expr, Found_Type);
12542 -- Normal case of one type found, some other type expected
12545 -- If the names of the two types are the same, see if some number
12546 -- of levels of qualification will help. Don't try more than three
12547 -- levels, and if we get to standard, it's no use (and probably
12548 -- represents an error in the compiler) Also do not bother with
12549 -- internal scope names.
12552 Expec_Scope : Entity_Id;
12553 Found_Scope : Entity_Id;
12556 Expec_Scope := Expec_Type;
12557 Found_Scope := Found_Type;
12559 for Levels in Int range 0 .. 3 loop
12560 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12561 Error_Msg_Qual_Level := Levels;
12565 Expec_Scope := Scope (Expec_Scope);
12566 Found_Scope := Scope (Found_Scope);
12568 exit when Expec_Scope = Standard_Standard
12569 or else Found_Scope = Standard_Standard
12570 or else not Comes_From_Source (Expec_Scope)
12571 or else not Comes_From_Source (Found_Scope);
12575 if Is_Record_Type (Expec_Type)
12576 and then Present (Corresponding_Remote_Type (Expec_Type))
12578 Error_Msg_NE ("expected}!", Expr,
12579 Corresponding_Remote_Type (Expec_Type));
12581 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12584 if Is_Entity_Name (Expr)
12585 and then Is_Package_Or_Generic_Package (Entity (Expr))
12587 Error_Msg_N ("\\found package name!", Expr);
12589 elsif Is_Entity_Name (Expr)
12591 (Ekind (Entity (Expr)) = E_Procedure
12593 Ekind (Entity (Expr)) = E_Generic_Procedure)
12595 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12597 ("found procedure name, possibly missing Access attribute!",
12601 ("\\found procedure name instead of function!", Expr);
12604 elsif Nkind (Expr) = N_Function_Call
12605 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12606 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12607 and then No (Parameter_Associations (Expr))
12610 ("found function name, possibly missing Access attribute!",
12613 -- Catch common error: a prefix or infix operator which is not
12614 -- directly visible because the type isn't.
12616 elsif Nkind (Expr) in N_Op
12617 and then Is_Overloaded (Expr)
12618 and then not Is_Immediately_Visible (Expec_Type)
12619 and then not Is_Potentially_Use_Visible (Expec_Type)
12620 and then not In_Use (Expec_Type)
12621 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12624 ("operator of the type is not directly visible!", Expr);
12626 elsif Ekind (Found_Type) = E_Void
12627 and then Present (Parent (Found_Type))
12628 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12630 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12633 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12636 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12637 -- of the same modular type, and (M1 and M2) = 0 was intended.
12639 if Expec_Type = Standard_Boolean
12640 and then Is_Modular_Integer_Type (Found_Type)
12641 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12642 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12645 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12646 L : constant Node_Id := Left_Opnd (Op);
12647 R : constant Node_Id := Right_Opnd (Op);
12649 -- The case for the message is when the left operand of the
12650 -- comparison is the same modular type, or when it is an
12651 -- integer literal (or other universal integer expression),
12652 -- which would have been typed as the modular type if the
12653 -- parens had been there.
12655 if (Etype (L) = Found_Type
12657 Etype (L) = Universal_Integer)
12658 and then Is_Integer_Type (Etype (R))
12661 ("\\possible missing parens for modular operation", Expr);
12666 -- Reset error message qualification indication
12668 Error_Msg_Qual_Level := 0;