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 Rtsfind; use Rtsfind;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Attr; use Sem_Attr;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Disp; use Sem_Disp;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Stand; use Stand;
56 with Stringt; use Stringt;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uname; use Uname;
63 with GNAT.HTable; use GNAT.HTable;
65 package body Sem_Util is
67 ----------------------------------------
68 -- Global_Variables for New_Copy_Tree --
69 ----------------------------------------
71 -- These global variables are used by New_Copy_Tree. See description
72 -- of the body of this subprogram for details. Global variables can be
73 -- safely used by New_Copy_Tree, since there is no case of a recursive
74 -- call from the processing inside New_Copy_Tree.
76 NCT_Hash_Threshold : constant := 20;
77 -- If there are more than this number of pairs of entries in the
78 -- map, then Hash_Tables_Used will be set, and the hash tables will
79 -- be initialized and used for the searches.
81 NCT_Hash_Tables_Used : Boolean := False;
82 -- Set to True if hash tables are in use
84 NCT_Table_Entries : Nat;
85 -- Count entries in table to see if threshold is reached
87 NCT_Hash_Table_Setup : Boolean := False;
88 -- Set to True if hash table contains data. We set this True if we
89 -- setup the hash table with data, and leave it set permanently
90 -- from then on, this is a signal that second and subsequent users
91 -- of the hash table must clear the old entries before reuse.
93 subtype NCT_Header_Num is Int range 0 .. 511;
94 -- Defines range of headers in hash tables (512 headers)
96 ----------------------------------
97 -- Order Dependence (AI05-0144) --
98 ----------------------------------
100 -- Each actual in a call is entered into the table below. A flag indicates
101 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
102 -- (procedure call, condition, assignment) examines all the actuals for a
103 -- possible order dependence. The table is reset after each such check.
104 -- The actuals to be checked in a call to Check_Order_Dependence are at
105 -- positions 1 .. Last.
107 type Actual_Name is record
109 Is_Writable : Boolean;
112 package Actuals_In_Call is new Table.Table (
113 Table_Component_Type => Actual_Name,
114 Table_Index_Type => Int,
115 Table_Low_Bound => 0,
117 Table_Increment => 100,
118 Table_Name => "Actuals");
120 -----------------------
121 -- Local Subprograms --
122 -----------------------
124 function Build_Component_Subtype
127 T : Entity_Id) return Node_Id;
128 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
129 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
130 -- Loc is the source location, T is the original subtype.
132 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
133 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
134 -- with discriminants whose default values are static, examine only the
135 -- components in the selected variant to determine whether all of them
138 function Has_Null_Extension (T : Entity_Id) return Boolean;
139 -- T is a derived tagged type. Check whether the type extension is null.
140 -- If the parent type is fully initialized, T can be treated as such.
142 ------------------------------
143 -- Abstract_Interface_List --
144 ------------------------------
146 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
150 if Is_Concurrent_Type (Typ) then
152 -- If we are dealing with a synchronized subtype, go to the base
153 -- type, whose declaration has the interface list.
155 -- Shouldn't this be Declaration_Node???
157 Nod := Parent (Base_Type (Typ));
159 if Nkind (Nod) = N_Full_Type_Declaration then
163 elsif Ekind (Typ) = E_Record_Type_With_Private then
164 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
165 Nod := Type_Definition (Parent (Typ));
167 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
168 if Present (Full_View (Typ)) then
169 Nod := Type_Definition (Parent (Full_View (Typ)));
171 -- If the full-view is not available we cannot do anything else
172 -- here (the source has errors).
178 -- Support for generic formals with interfaces is still missing ???
180 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
185 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
189 elsif Ekind (Typ) = E_Record_Subtype then
190 Nod := Type_Definition (Parent (Etype (Typ)));
192 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
194 -- Recurse, because parent may still be a private extension. Also
195 -- note that the full view of the subtype or the full view of its
196 -- base type may (both) be unavailable.
198 return Abstract_Interface_List (Etype (Typ));
200 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
201 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
202 Nod := Formal_Type_Definition (Parent (Typ));
204 Nod := Type_Definition (Parent (Typ));
208 return Interface_List (Nod);
209 end Abstract_Interface_List;
211 --------------------------------
212 -- Add_Access_Type_To_Process --
213 --------------------------------
215 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
219 Ensure_Freeze_Node (E);
220 L := Access_Types_To_Process (Freeze_Node (E));
224 Set_Access_Types_To_Process (Freeze_Node (E), L);
228 end Add_Access_Type_To_Process;
230 ----------------------------
231 -- Add_Global_Declaration --
232 ----------------------------
234 procedure Add_Global_Declaration (N : Node_Id) is
235 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
238 if No (Declarations (Aux_Node)) then
239 Set_Declarations (Aux_Node, New_List);
242 Append_To (Declarations (Aux_Node), N);
244 end Add_Global_Declaration;
250 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
252 function Addressable (V : Uint) return Boolean is
254 return V = Uint_8 or else
260 function Addressable (V : Int) return Boolean is
268 -----------------------
269 -- Alignment_In_Bits --
270 -----------------------
272 function Alignment_In_Bits (E : Entity_Id) return Uint is
274 return Alignment (E) * System_Storage_Unit;
275 end Alignment_In_Bits;
277 -----------------------------------------
278 -- Apply_Compile_Time_Constraint_Error --
279 -----------------------------------------
281 procedure Apply_Compile_Time_Constraint_Error
284 Reason : RT_Exception_Code;
285 Ent : Entity_Id := Empty;
286 Typ : Entity_Id := Empty;
287 Loc : Source_Ptr := No_Location;
288 Rep : Boolean := True;
289 Warn : Boolean := False)
291 Stat : constant Boolean := Is_Static_Expression (N);
292 R_Stat : constant Node_Id :=
293 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
304 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
310 -- Now we replace the node by an N_Raise_Constraint_Error node
311 -- This does not need reanalyzing, so set it as analyzed now.
314 Set_Analyzed (N, True);
317 Set_Raises_Constraint_Error (N);
319 -- Now deal with possible local raise handling
321 Possible_Local_Raise (N, Standard_Constraint_Error);
323 -- If the original expression was marked as static, the result is
324 -- still marked as static, but the Raises_Constraint_Error flag is
325 -- always set so that further static evaluation is not attempted.
328 Set_Is_Static_Expression (N);
330 end Apply_Compile_Time_Constraint_Error;
332 --------------------------------
333 -- Bad_Predicated_Subtype_Use --
334 --------------------------------
336 procedure Bad_Predicated_Subtype_Use
342 if Has_Predicates (Typ) then
343 if Is_Generic_Actual_Type (Typ) then
344 Error_Msg_FE (Msg & '?', N, Typ);
345 Error_Msg_F ("\Program_Error will be raised at run time?", N);
347 Make_Raise_Program_Error (Sloc (N),
348 Reason => PE_Bad_Predicated_Generic_Type));
351 Error_Msg_FE (Msg, N, Typ);
354 end Bad_Predicated_Subtype_Use;
356 --------------------------
357 -- Build_Actual_Subtype --
358 --------------------------
360 function Build_Actual_Subtype
362 N : Node_Or_Entity_Id) return Node_Id
365 -- Normally Sloc (N), but may point to corresponding body in some cases
367 Constraints : List_Id;
373 Disc_Type : Entity_Id;
379 if Nkind (N) = N_Defining_Identifier then
380 Obj := New_Reference_To (N, Loc);
382 -- If this is a formal parameter of a subprogram declaration, and
383 -- we are compiling the body, we want the declaration for the
384 -- actual subtype to carry the source position of the body, to
385 -- prevent anomalies in gdb when stepping through the code.
387 if Is_Formal (N) then
389 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
391 if Nkind (Decl) = N_Subprogram_Declaration
392 and then Present (Corresponding_Body (Decl))
394 Loc := Sloc (Corresponding_Body (Decl));
403 if Is_Array_Type (T) then
404 Constraints := New_List;
405 for J in 1 .. Number_Dimensions (T) loop
407 -- Build an array subtype declaration with the nominal subtype and
408 -- the bounds of the actual. Add the declaration in front of the
409 -- local declarations for the subprogram, for analysis before any
410 -- reference to the formal in the body.
413 Make_Attribute_Reference (Loc,
415 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
416 Attribute_Name => Name_First,
417 Expressions => New_List (
418 Make_Integer_Literal (Loc, J)));
421 Make_Attribute_Reference (Loc,
423 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
424 Attribute_Name => Name_Last,
425 Expressions => New_List (
426 Make_Integer_Literal (Loc, J)));
428 Append (Make_Range (Loc, Lo, Hi), Constraints);
431 -- If the type has unknown discriminants there is no constrained
432 -- subtype to build. This is never called for a formal or for a
433 -- lhs, so returning the type is ok ???
435 elsif Has_Unknown_Discriminants (T) then
439 Constraints := New_List;
441 -- Type T is a generic derived type, inherit the discriminants from
444 if Is_Private_Type (T)
445 and then No (Full_View (T))
447 -- T was flagged as an error if it was declared as a formal
448 -- derived type with known discriminants. In this case there
449 -- is no need to look at the parent type since T already carries
450 -- its own discriminants.
452 and then not Error_Posted (T)
454 Disc_Type := Etype (Base_Type (T));
459 Discr := First_Discriminant (Disc_Type);
460 while Present (Discr) loop
461 Append_To (Constraints,
462 Make_Selected_Component (Loc,
464 Duplicate_Subexpr_No_Checks (Obj),
465 Selector_Name => New_Occurrence_Of (Discr, Loc)));
466 Next_Discriminant (Discr);
470 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
471 Set_Is_Internal (Subt);
474 Make_Subtype_Declaration (Loc,
475 Defining_Identifier => Subt,
476 Subtype_Indication =>
477 Make_Subtype_Indication (Loc,
478 Subtype_Mark => New_Reference_To (T, Loc),
480 Make_Index_Or_Discriminant_Constraint (Loc,
481 Constraints => Constraints)));
483 Mark_Rewrite_Insertion (Decl);
485 end Build_Actual_Subtype;
487 ---------------------------------------
488 -- Build_Actual_Subtype_Of_Component --
489 ---------------------------------------
491 function Build_Actual_Subtype_Of_Component
493 N : Node_Id) return Node_Id
495 Loc : constant Source_Ptr := Sloc (N);
496 P : constant Node_Id := Prefix (N);
499 Indx_Type : Entity_Id;
501 Deaccessed_T : Entity_Id;
502 -- This is either a copy of T, or if T is an access type, then it is
503 -- the directly designated type of this access type.
505 function Build_Actual_Array_Constraint return List_Id;
506 -- If one or more of the bounds of the component depends on
507 -- discriminants, build actual constraint using the discriminants
510 function Build_Actual_Record_Constraint return List_Id;
511 -- Similar to previous one, for discriminated components constrained
512 -- by the discriminant of the enclosing object.
514 -----------------------------------
515 -- Build_Actual_Array_Constraint --
516 -----------------------------------
518 function Build_Actual_Array_Constraint return List_Id is
519 Constraints : constant List_Id := New_List;
527 Indx := First_Index (Deaccessed_T);
528 while Present (Indx) loop
529 Old_Lo := Type_Low_Bound (Etype (Indx));
530 Old_Hi := Type_High_Bound (Etype (Indx));
532 if Denotes_Discriminant (Old_Lo) then
534 Make_Selected_Component (Loc,
535 Prefix => New_Copy_Tree (P),
536 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
539 Lo := New_Copy_Tree (Old_Lo);
541 -- The new bound will be reanalyzed in the enclosing
542 -- declaration. For literal bounds that come from a type
543 -- declaration, the type of the context must be imposed, so
544 -- insure that analysis will take place. For non-universal
545 -- types this is not strictly necessary.
547 Set_Analyzed (Lo, False);
550 if Denotes_Discriminant (Old_Hi) then
552 Make_Selected_Component (Loc,
553 Prefix => New_Copy_Tree (P),
554 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
557 Hi := New_Copy_Tree (Old_Hi);
558 Set_Analyzed (Hi, False);
561 Append (Make_Range (Loc, Lo, Hi), Constraints);
566 end Build_Actual_Array_Constraint;
568 ------------------------------------
569 -- Build_Actual_Record_Constraint --
570 ------------------------------------
572 function Build_Actual_Record_Constraint return List_Id is
573 Constraints : constant List_Id := New_List;
578 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
579 while Present (D) loop
580 if Denotes_Discriminant (Node (D)) then
581 D_Val := Make_Selected_Component (Loc,
582 Prefix => New_Copy_Tree (P),
583 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
586 D_Val := New_Copy_Tree (Node (D));
589 Append (D_Val, Constraints);
594 end Build_Actual_Record_Constraint;
596 -- Start of processing for Build_Actual_Subtype_Of_Component
599 -- Why the test for Spec_Expression mode here???
601 if In_Spec_Expression then
604 -- More comments for the rest of this body would be good ???
606 elsif Nkind (N) = N_Explicit_Dereference then
607 if Is_Composite_Type (T)
608 and then not Is_Constrained (T)
609 and then not (Is_Class_Wide_Type (T)
610 and then Is_Constrained (Root_Type (T)))
611 and then not Has_Unknown_Discriminants (T)
613 -- If the type of the dereference is already constrained, it is an
616 if Is_Array_Type (Etype (N))
617 and then Is_Constrained (Etype (N))
621 Remove_Side_Effects (P);
622 return Build_Actual_Subtype (T, N);
629 if Ekind (T) = E_Access_Subtype then
630 Deaccessed_T := Designated_Type (T);
635 if Ekind (Deaccessed_T) = E_Array_Subtype then
636 Id := First_Index (Deaccessed_T);
637 while Present (Id) loop
638 Indx_Type := Underlying_Type (Etype (Id));
640 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
642 Denotes_Discriminant (Type_High_Bound (Indx_Type))
644 Remove_Side_Effects (P);
646 Build_Component_Subtype
647 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
653 elsif Is_Composite_Type (Deaccessed_T)
654 and then Has_Discriminants (Deaccessed_T)
655 and then not Has_Unknown_Discriminants (Deaccessed_T)
657 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
658 while Present (D) loop
659 if Denotes_Discriminant (Node (D)) then
660 Remove_Side_Effects (P);
662 Build_Component_Subtype (
663 Build_Actual_Record_Constraint, Loc, Base_Type (T));
670 -- If none of the above, the actual and nominal subtypes are the same
673 end Build_Actual_Subtype_Of_Component;
675 -----------------------------
676 -- Build_Component_Subtype --
677 -----------------------------
679 function Build_Component_Subtype
682 T : Entity_Id) return Node_Id
688 -- Unchecked_Union components do not require component subtypes
690 if Is_Unchecked_Union (T) then
694 Subt := Make_Temporary (Loc, 'S');
695 Set_Is_Internal (Subt);
698 Make_Subtype_Declaration (Loc,
699 Defining_Identifier => Subt,
700 Subtype_Indication =>
701 Make_Subtype_Indication (Loc,
702 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
704 Make_Index_Or_Discriminant_Constraint (Loc,
707 Mark_Rewrite_Insertion (Decl);
709 end Build_Component_Subtype;
711 ---------------------------
712 -- Build_Default_Subtype --
713 ---------------------------
715 function Build_Default_Subtype
717 N : Node_Id) return Entity_Id
719 Loc : constant Source_Ptr := Sloc (N);
723 if not Has_Discriminants (T) or else Is_Constrained (T) then
727 Disc := First_Discriminant (T);
729 if No (Discriminant_Default_Value (Disc)) then
734 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
735 Constraints : constant List_Id := New_List;
739 while Present (Disc) loop
740 Append_To (Constraints,
741 New_Copy_Tree (Discriminant_Default_Value (Disc)));
742 Next_Discriminant (Disc);
746 Make_Subtype_Declaration (Loc,
747 Defining_Identifier => Act,
748 Subtype_Indication =>
749 Make_Subtype_Indication (Loc,
750 Subtype_Mark => New_Occurrence_Of (T, Loc),
752 Make_Index_Or_Discriminant_Constraint (Loc,
753 Constraints => Constraints)));
755 Insert_Action (N, Decl);
759 end Build_Default_Subtype;
761 --------------------------------------------
762 -- Build_Discriminal_Subtype_Of_Component --
763 --------------------------------------------
765 function Build_Discriminal_Subtype_Of_Component
766 (T : Entity_Id) return Node_Id
768 Loc : constant Source_Ptr := Sloc (T);
772 function Build_Discriminal_Array_Constraint return List_Id;
773 -- If one or more of the bounds of the component depends on
774 -- discriminants, build actual constraint using the discriminants
777 function Build_Discriminal_Record_Constraint return List_Id;
778 -- Similar to previous one, for discriminated components constrained
779 -- by the discriminant of the enclosing object.
781 ----------------------------------------
782 -- Build_Discriminal_Array_Constraint --
783 ----------------------------------------
785 function Build_Discriminal_Array_Constraint return List_Id is
786 Constraints : constant List_Id := New_List;
794 Indx := First_Index (T);
795 while Present (Indx) loop
796 Old_Lo := Type_Low_Bound (Etype (Indx));
797 Old_Hi := Type_High_Bound (Etype (Indx));
799 if Denotes_Discriminant (Old_Lo) then
800 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
803 Lo := New_Copy_Tree (Old_Lo);
806 if Denotes_Discriminant (Old_Hi) then
807 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
810 Hi := New_Copy_Tree (Old_Hi);
813 Append (Make_Range (Loc, Lo, Hi), Constraints);
818 end Build_Discriminal_Array_Constraint;
820 -----------------------------------------
821 -- Build_Discriminal_Record_Constraint --
822 -----------------------------------------
824 function Build_Discriminal_Record_Constraint return List_Id is
825 Constraints : constant List_Id := New_List;
830 D := First_Elmt (Discriminant_Constraint (T));
831 while Present (D) loop
832 if Denotes_Discriminant (Node (D)) then
834 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
837 D_Val := New_Copy_Tree (Node (D));
840 Append (D_Val, Constraints);
845 end Build_Discriminal_Record_Constraint;
847 -- Start of processing for Build_Discriminal_Subtype_Of_Component
850 if Ekind (T) = E_Array_Subtype then
851 Id := First_Index (T);
852 while Present (Id) loop
853 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
854 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
856 return Build_Component_Subtype
857 (Build_Discriminal_Array_Constraint, Loc, T);
863 elsif Ekind (T) = E_Record_Subtype
864 and then Has_Discriminants (T)
865 and then not Has_Unknown_Discriminants (T)
867 D := First_Elmt (Discriminant_Constraint (T));
868 while Present (D) loop
869 if Denotes_Discriminant (Node (D)) then
870 return Build_Component_Subtype
871 (Build_Discriminal_Record_Constraint, Loc, T);
878 -- If none of the above, the actual and nominal subtypes are the same
881 end Build_Discriminal_Subtype_Of_Component;
883 ------------------------------
884 -- Build_Elaboration_Entity --
885 ------------------------------
887 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
888 Loc : constant Source_Ptr := Sloc (N);
890 Elab_Ent : Entity_Id;
892 procedure Set_Package_Name (Ent : Entity_Id);
893 -- Given an entity, sets the fully qualified name of the entity in
894 -- Name_Buffer, with components separated by double underscores. This
895 -- is a recursive routine that climbs the scope chain to Standard.
897 ----------------------
898 -- Set_Package_Name --
899 ----------------------
901 procedure Set_Package_Name (Ent : Entity_Id) is
903 if Scope (Ent) /= Standard_Standard then
904 Set_Package_Name (Scope (Ent));
907 Nam : constant String := Get_Name_String (Chars (Ent));
909 Name_Buffer (Name_Len + 1) := '_';
910 Name_Buffer (Name_Len + 2) := '_';
911 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
912 Name_Len := Name_Len + Nam'Length + 2;
916 Get_Name_String (Chars (Ent));
918 end Set_Package_Name;
920 -- Start of processing for Build_Elaboration_Entity
923 -- Ignore if already constructed
925 if Present (Elaboration_Entity (Spec_Id)) then
929 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
930 -- name with dots replaced by double underscore. We have to manually
931 -- construct this name, since it will be elaborated in the outer scope,
932 -- and thus will not have the unit name automatically prepended.
934 Set_Package_Name (Spec_Id);
938 Name_Buffer (Name_Len + 1) := '_';
939 Name_Buffer (Name_Len + 2) := 'E';
940 Name_Len := Name_Len + 2;
942 -- Create elaboration flag
945 Make_Defining_Identifier (Loc, Chars => Name_Find);
946 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
949 Make_Object_Declaration (Loc,
950 Defining_Identifier => Elab_Ent,
952 New_Occurrence_Of (Standard_Boolean, Loc),
954 New_Occurrence_Of (Standard_False, Loc));
956 Push_Scope (Standard_Standard);
957 Add_Global_Declaration (Decl);
960 -- Reset True_Constant indication, since we will indeed assign a value
961 -- to the variable in the binder main. We also kill the Current_Value
962 -- and Last_Assignment fields for the same reason.
964 Set_Is_True_Constant (Elab_Ent, False);
965 Set_Current_Value (Elab_Ent, Empty);
966 Set_Last_Assignment (Elab_Ent, Empty);
968 -- We do not want any further qualification of the name (if we did
969 -- not do this, we would pick up the name of the generic package
970 -- in the case of a library level generic instantiation).
972 Set_Has_Qualified_Name (Elab_Ent);
973 Set_Has_Fully_Qualified_Name (Elab_Ent);
974 end Build_Elaboration_Entity;
976 -----------------------------------
977 -- Cannot_Raise_Constraint_Error --
978 -----------------------------------
980 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
982 if Compile_Time_Known_Value (Expr) then
985 elsif Do_Range_Check (Expr) then
988 elsif Raises_Constraint_Error (Expr) then
996 when N_Expanded_Name =>
999 when N_Selected_Component =>
1000 return not Do_Discriminant_Check (Expr);
1002 when N_Attribute_Reference =>
1003 if Do_Overflow_Check (Expr) then
1006 elsif No (Expressions (Expr)) then
1014 N := First (Expressions (Expr));
1015 while Present (N) loop
1016 if Cannot_Raise_Constraint_Error (N) then
1027 when N_Type_Conversion =>
1028 if Do_Overflow_Check (Expr)
1029 or else Do_Length_Check (Expr)
1030 or else Do_Tag_Check (Expr)
1035 Cannot_Raise_Constraint_Error (Expression (Expr));
1038 when N_Unchecked_Type_Conversion =>
1039 return Cannot_Raise_Constraint_Error (Expression (Expr));
1042 if Do_Overflow_Check (Expr) then
1046 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1053 if Do_Division_Check (Expr)
1054 or else Do_Overflow_Check (Expr)
1059 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1061 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1080 N_Op_Shift_Right_Arithmetic |
1084 if Do_Overflow_Check (Expr) then
1088 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1090 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1097 end Cannot_Raise_Constraint_Error;
1099 -----------------------------------------
1100 -- Check_Dynamically_Tagged_Expression --
1101 -----------------------------------------
1103 procedure Check_Dynamically_Tagged_Expression
1106 Related_Nod : Node_Id)
1109 pragma Assert (Is_Tagged_Type (Typ));
1111 -- In order to avoid spurious errors when analyzing the expanded code,
1112 -- this check is done only for nodes that come from source and for
1113 -- actuals of generic instantiations.
1115 if (Comes_From_Source (Related_Nod)
1116 or else In_Generic_Actual (Expr))
1117 and then (Is_Class_Wide_Type (Etype (Expr))
1118 or else Is_Dynamically_Tagged (Expr))
1119 and then Is_Tagged_Type (Typ)
1120 and then not Is_Class_Wide_Type (Typ)
1122 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1124 end Check_Dynamically_Tagged_Expression;
1126 --------------------------
1127 -- Check_Fully_Declared --
1128 --------------------------
1130 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1132 if Ekind (T) = E_Incomplete_Type then
1134 -- Ada 2005 (AI-50217): If the type is available through a limited
1135 -- with_clause, verify that its full view has been analyzed.
1137 if From_With_Type (T)
1138 and then Present (Non_Limited_View (T))
1139 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1141 -- The non-limited view is fully declared
1146 ("premature usage of incomplete}", N, First_Subtype (T));
1149 -- Need comments for these tests ???
1151 elsif Has_Private_Component (T)
1152 and then not Is_Generic_Type (Root_Type (T))
1153 and then not In_Spec_Expression
1155 -- Special case: if T is the anonymous type created for a single
1156 -- task or protected object, use the name of the source object.
1158 if Is_Concurrent_Type (T)
1159 and then not Comes_From_Source (T)
1160 and then Nkind (N) = N_Object_Declaration
1162 Error_Msg_NE ("type of& has incomplete component", N,
1163 Defining_Identifier (N));
1167 ("premature usage of incomplete}", N, First_Subtype (T));
1170 end Check_Fully_Declared;
1172 -------------------------
1173 -- Check_Nested_Access --
1174 -------------------------
1176 procedure Check_Nested_Access (Ent : Entity_Id) is
1177 Scop : constant Entity_Id := Current_Scope;
1178 Current_Subp : Entity_Id;
1179 Enclosing : Entity_Id;
1182 -- Currently only enabled for VM back-ends for efficiency, should we
1183 -- enable it more systematically ???
1185 -- Check for Is_Imported needs commenting below ???
1187 if VM_Target /= No_VM
1188 and then (Ekind (Ent) = E_Variable
1190 Ekind (Ent) = E_Constant
1192 Ekind (Ent) = E_Loop_Parameter)
1193 and then Scope (Ent) /= Empty
1194 and then not Is_Library_Level_Entity (Ent)
1195 and then not Is_Imported (Ent)
1197 if Is_Subprogram (Scop)
1198 or else Is_Generic_Subprogram (Scop)
1199 or else Is_Entry (Scop)
1201 Current_Subp := Scop;
1203 Current_Subp := Current_Subprogram;
1206 Enclosing := Enclosing_Subprogram (Ent);
1208 if Enclosing /= Empty
1209 and then Enclosing /= Current_Subp
1211 Set_Has_Up_Level_Access (Ent, True);
1214 end Check_Nested_Access;
1216 ----------------------------
1217 -- Check_Order_Dependence --
1218 ----------------------------
1220 procedure Check_Order_Dependence is
1225 if Ada_Version < Ada_2012 then
1229 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1230 -- calls within a construct have been collected. If one of them is
1231 -- writable and overlaps with another one, evaluation of the enclosing
1232 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1233 -- treated as a warning for now.
1235 for J in 1 .. Actuals_In_Call.Last loop
1236 if Actuals_In_Call.Table (J).Is_Writable then
1237 Act1 := Actuals_In_Call.Table (J).Act;
1239 if Nkind (Act1) = N_Attribute_Reference then
1240 Act1 := Prefix (Act1);
1243 for K in 1 .. Actuals_In_Call.Last loop
1245 Act2 := Actuals_In_Call.Table (K).Act;
1247 if Nkind (Act2) = N_Attribute_Reference then
1248 Act2 := Prefix (Act2);
1251 if Actuals_In_Call.Table (K).Is_Writable
1258 elsif Denotes_Same_Object (Act1, Act2)
1259 and then Parent (Act1) /= Parent (Act2)
1262 ("result may differ if evaluated "
1263 & "after other actual in expression?", Act1);
1270 -- Remove checked actuals from table
1272 Actuals_In_Call.Set_Last (0);
1273 end Check_Order_Dependence;
1275 ------------------------------------------
1276 -- Check_Potentially_Blocking_Operation --
1277 ------------------------------------------
1279 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1283 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1284 -- When pragma Detect_Blocking is active, the run time will raise
1285 -- Program_Error. Here we only issue a warning, since we generally
1286 -- support the use of potentially blocking operations in the absence
1289 -- Indirect blocking through a subprogram call cannot be diagnosed
1290 -- statically without interprocedural analysis, so we do not attempt
1293 S := Scope (Current_Scope);
1294 while Present (S) and then S /= Standard_Standard loop
1295 if Is_Protected_Type (S) then
1297 ("potentially blocking operation in protected operation?", N);
1303 end Check_Potentially_Blocking_Operation;
1305 ------------------------------
1306 -- Check_Unprotected_Access --
1307 ------------------------------
1309 procedure Check_Unprotected_Access
1313 Cont_Encl_Typ : Entity_Id;
1314 Pref_Encl_Typ : Entity_Id;
1316 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1317 -- Check whether Obj is a private component of a protected object.
1318 -- Return the protected type where the component resides, Empty
1321 function Is_Public_Operation return Boolean;
1322 -- Verify that the enclosing operation is callable from outside the
1323 -- protected object, to minimize false positives.
1325 ------------------------------
1326 -- Enclosing_Protected_Type --
1327 ------------------------------
1329 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1331 if Is_Entity_Name (Obj) then
1333 Ent : Entity_Id := Entity (Obj);
1336 -- The object can be a renaming of a private component, use
1337 -- the original record component.
1339 if Is_Prival (Ent) then
1340 Ent := Prival_Link (Ent);
1343 if Is_Protected_Type (Scope (Ent)) then
1349 -- For indexed and selected components, recursively check the prefix
1351 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1352 return Enclosing_Protected_Type (Prefix (Obj));
1354 -- The object does not denote a protected component
1359 end Enclosing_Protected_Type;
1361 -------------------------
1362 -- Is_Public_Operation --
1363 -------------------------
1365 function Is_Public_Operation return Boolean is
1372 and then S /= Pref_Encl_Typ
1374 if Scope (S) = Pref_Encl_Typ then
1375 E := First_Entity (Pref_Encl_Typ);
1377 and then E /= First_Private_Entity (Pref_Encl_Typ)
1390 end Is_Public_Operation;
1392 -- Start of processing for Check_Unprotected_Access
1395 if Nkind (Expr) = N_Attribute_Reference
1396 and then Attribute_Name (Expr) = Name_Unchecked_Access
1398 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1399 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1401 -- Check whether we are trying to export a protected component to a
1402 -- context with an equal or lower access level.
1404 if Present (Pref_Encl_Typ)
1405 and then No (Cont_Encl_Typ)
1406 and then Is_Public_Operation
1407 and then Scope_Depth (Pref_Encl_Typ) >=
1408 Object_Access_Level (Context)
1411 ("?possible unprotected access to protected data", Expr);
1414 end Check_Unprotected_Access;
1420 procedure Check_VMS (Construct : Node_Id) is
1422 if not OpenVMS_On_Target then
1424 ("this construct is allowed only in Open'V'M'S", Construct);
1428 ------------------------
1429 -- Collect_Interfaces --
1430 ------------------------
1432 procedure Collect_Interfaces
1434 Ifaces_List : out Elist_Id;
1435 Exclude_Parents : Boolean := False;
1436 Use_Full_View : Boolean := True)
1438 procedure Collect (Typ : Entity_Id);
1439 -- Subsidiary subprogram used to traverse the whole list
1440 -- of directly and indirectly implemented interfaces
1446 procedure Collect (Typ : Entity_Id) is
1447 Ancestor : Entity_Id;
1455 -- Handle private types
1458 and then Is_Private_Type (Typ)
1459 and then Present (Full_View (Typ))
1461 Full_T := Full_View (Typ);
1464 -- Include the ancestor if we are generating the whole list of
1465 -- abstract interfaces.
1467 if Etype (Full_T) /= Typ
1469 -- Protect the frontend against wrong sources. For example:
1472 -- type A is tagged null record;
1473 -- type B is new A with private;
1474 -- type C is new A with private;
1476 -- type B is new C with null record;
1477 -- type C is new B with null record;
1480 and then Etype (Full_T) /= T
1482 Ancestor := Etype (Full_T);
1485 if Is_Interface (Ancestor)
1486 and then not Exclude_Parents
1488 Append_Unique_Elmt (Ancestor, Ifaces_List);
1492 -- Traverse the graph of ancestor interfaces
1494 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1495 Id := First (Abstract_Interface_List (Full_T));
1496 while Present (Id) loop
1497 Iface := Etype (Id);
1499 -- Protect against wrong uses. For example:
1500 -- type I is interface;
1501 -- type O is tagged null record;
1502 -- type Wrong is new I and O with null record; -- ERROR
1504 if Is_Interface (Iface) then
1506 and then Etype (T) /= T
1507 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1512 Append_Unique_Elmt (Iface, Ifaces_List);
1521 -- Start of processing for Collect_Interfaces
1524 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1525 Ifaces_List := New_Elmt_List;
1527 end Collect_Interfaces;
1529 ----------------------------------
1530 -- Collect_Interface_Components --
1531 ----------------------------------
1533 procedure Collect_Interface_Components
1534 (Tagged_Type : Entity_Id;
1535 Components_List : out Elist_Id)
1537 procedure Collect (Typ : Entity_Id);
1538 -- Subsidiary subprogram used to climb to the parents
1544 procedure Collect (Typ : Entity_Id) is
1545 Tag_Comp : Entity_Id;
1546 Parent_Typ : Entity_Id;
1549 -- Handle private types
1551 if Present (Full_View (Etype (Typ))) then
1552 Parent_Typ := Full_View (Etype (Typ));
1554 Parent_Typ := Etype (Typ);
1557 if Parent_Typ /= Typ
1559 -- Protect the frontend against wrong sources. For example:
1562 -- type A is tagged null record;
1563 -- type B is new A with private;
1564 -- type C is new A with private;
1566 -- type B is new C with null record;
1567 -- type C is new B with null record;
1570 and then Parent_Typ /= Tagged_Type
1572 Collect (Parent_Typ);
1575 -- Collect the components containing tags of secondary dispatch
1578 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1579 while Present (Tag_Comp) loop
1580 pragma Assert (Present (Related_Type (Tag_Comp)));
1581 Append_Elmt (Tag_Comp, Components_List);
1583 Tag_Comp := Next_Tag_Component (Tag_Comp);
1587 -- Start of processing for Collect_Interface_Components
1590 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1591 and then Is_Tagged_Type (Tagged_Type));
1593 Components_List := New_Elmt_List;
1594 Collect (Tagged_Type);
1595 end Collect_Interface_Components;
1597 -----------------------------
1598 -- Collect_Interfaces_Info --
1599 -----------------------------
1601 procedure Collect_Interfaces_Info
1603 Ifaces_List : out Elist_Id;
1604 Components_List : out Elist_Id;
1605 Tags_List : out Elist_Id)
1607 Comps_List : Elist_Id;
1608 Comp_Elmt : Elmt_Id;
1609 Comp_Iface : Entity_Id;
1610 Iface_Elmt : Elmt_Id;
1613 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1614 -- Search for the secondary tag associated with the interface type
1615 -- Iface that is implemented by T.
1621 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1624 if not Is_CPP_Class (T) then
1625 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1627 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1631 and then Is_Tag (Node (ADT))
1632 and then Related_Type (Node (ADT)) /= Iface
1634 -- Skip secondary dispatch table referencing thunks to user
1635 -- defined primitives covered by this interface.
1637 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1640 -- Skip secondary dispatch tables of Ada types
1642 if not Is_CPP_Class (T) then
1644 -- Skip secondary dispatch table referencing thunks to
1645 -- predefined primitives.
1647 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1650 -- Skip secondary dispatch table referencing user-defined
1651 -- primitives covered by this interface.
1653 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1656 -- Skip secondary dispatch table referencing predefined
1659 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1664 pragma Assert (Is_Tag (Node (ADT)));
1668 -- Start of processing for Collect_Interfaces_Info
1671 Collect_Interfaces (T, Ifaces_List);
1672 Collect_Interface_Components (T, Comps_List);
1674 -- Search for the record component and tag associated with each
1675 -- interface type of T.
1677 Components_List := New_Elmt_List;
1678 Tags_List := New_Elmt_List;
1680 Iface_Elmt := First_Elmt (Ifaces_List);
1681 while Present (Iface_Elmt) loop
1682 Iface := Node (Iface_Elmt);
1684 -- Associate the primary tag component and the primary dispatch table
1685 -- with all the interfaces that are parents of T
1687 if Is_Ancestor (Iface, T) then
1688 Append_Elmt (First_Tag_Component (T), Components_List);
1689 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1691 -- Otherwise search for the tag component and secondary dispatch
1695 Comp_Elmt := First_Elmt (Comps_List);
1696 while Present (Comp_Elmt) loop
1697 Comp_Iface := Related_Type (Node (Comp_Elmt));
1699 if Comp_Iface = Iface
1700 or else Is_Ancestor (Iface, Comp_Iface)
1702 Append_Elmt (Node (Comp_Elmt), Components_List);
1703 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1707 Next_Elmt (Comp_Elmt);
1709 pragma Assert (Present (Comp_Elmt));
1712 Next_Elmt (Iface_Elmt);
1714 end Collect_Interfaces_Info;
1716 ---------------------
1717 -- Collect_Parents --
1718 ---------------------
1720 procedure Collect_Parents
1722 List : out Elist_Id;
1723 Use_Full_View : Boolean := True)
1725 Current_Typ : Entity_Id := T;
1726 Parent_Typ : Entity_Id;
1729 List := New_Elmt_List;
1731 -- No action if the if the type has no parents
1733 if T = Etype (T) then
1738 Parent_Typ := Etype (Current_Typ);
1740 if Is_Private_Type (Parent_Typ)
1741 and then Present (Full_View (Parent_Typ))
1742 and then Use_Full_View
1744 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1747 Append_Elmt (Parent_Typ, List);
1749 exit when Parent_Typ = Current_Typ;
1750 Current_Typ := Parent_Typ;
1752 end Collect_Parents;
1754 ----------------------------------
1755 -- Collect_Primitive_Operations --
1756 ----------------------------------
1758 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1759 B_Type : constant Entity_Id := Base_Type (T);
1760 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1761 B_Scope : Entity_Id := Scope (B_Type);
1765 Formal_Derived : Boolean := False;
1768 function Match (E : Entity_Id) return Boolean;
1769 -- True if E's base type is B_Type, or E is of an anonymous access type
1770 -- and the base type of its designated type is B_Type.
1776 function Match (E : Entity_Id) return Boolean is
1777 Etyp : Entity_Id := Etype (E);
1780 if Ekind (Etyp) = E_Anonymous_Access_Type then
1781 Etyp := Designated_Type (Etyp);
1784 return Base_Type (Etyp) = B_Type;
1787 -- Start of processing for Collect_Primitive_Operations
1790 -- For tagged types, the primitive operations are collected as they
1791 -- are declared, and held in an explicit list which is simply returned.
1793 if Is_Tagged_Type (B_Type) then
1794 return Primitive_Operations (B_Type);
1796 -- An untagged generic type that is a derived type inherits the
1797 -- primitive operations of its parent type. Other formal types only
1798 -- have predefined operators, which are not explicitly represented.
1800 elsif Is_Generic_Type (B_Type) then
1801 if Nkind (B_Decl) = N_Formal_Type_Declaration
1802 and then Nkind (Formal_Type_Definition (B_Decl))
1803 = N_Formal_Derived_Type_Definition
1805 Formal_Derived := True;
1807 return New_Elmt_List;
1811 Op_List := New_Elmt_List;
1813 if B_Scope = Standard_Standard then
1814 if B_Type = Standard_String then
1815 Append_Elmt (Standard_Op_Concat, Op_List);
1817 elsif B_Type = Standard_Wide_String then
1818 Append_Elmt (Standard_Op_Concatw, Op_List);
1824 elsif (Is_Package_Or_Generic_Package (B_Scope)
1826 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1828 or else Is_Derived_Type (B_Type)
1830 -- The primitive operations appear after the base type, except
1831 -- if the derivation happens within the private part of B_Scope
1832 -- and the type is a private type, in which case both the type
1833 -- and some primitive operations may appear before the base
1834 -- type, and the list of candidates starts after the type.
1836 if In_Open_Scopes (B_Scope)
1837 and then Scope (T) = B_Scope
1838 and then In_Private_Part (B_Scope)
1840 Id := Next_Entity (T);
1842 Id := Next_Entity (B_Type);
1845 while Present (Id) loop
1847 -- Note that generic formal subprograms are not
1848 -- considered to be primitive operations and thus
1849 -- are never inherited.
1851 if Is_Overloadable (Id)
1852 and then Nkind (Parent (Parent (Id)))
1853 not in N_Formal_Subprogram_Declaration
1861 Formal := First_Formal (Id);
1862 while Present (Formal) loop
1863 if Match (Formal) then
1868 Next_Formal (Formal);
1872 -- For a formal derived type, the only primitives are the
1873 -- ones inherited from the parent type. Operations appearing
1874 -- in the package declaration are not primitive for it.
1877 and then (not Formal_Derived
1878 or else Present (Alias (Id)))
1880 -- In the special case of an equality operator aliased to
1881 -- an overriding dispatching equality belonging to the same
1882 -- type, we don't include it in the list of primitives.
1883 -- This avoids inheriting multiple equality operators when
1884 -- deriving from untagged private types whose full type is
1885 -- tagged, which can otherwise cause ambiguities. Note that
1886 -- this should only happen for this kind of untagged parent
1887 -- type, since normally dispatching operations are inherited
1888 -- using the type's Primitive_Operations list.
1890 if Chars (Id) = Name_Op_Eq
1891 and then Is_Dispatching_Operation (Id)
1892 and then Present (Alias (Id))
1893 and then Present (Overridden_Operation (Alias (Id)))
1894 and then Base_Type (Etype (First_Entity (Id))) =
1895 Base_Type (Etype (First_Entity (Alias (Id))))
1899 -- Include the subprogram in the list of primitives
1902 Append_Elmt (Id, Op_List);
1909 -- For a type declared in System, some of its operations may
1910 -- appear in the target-specific extension to System.
1913 and then B_Scope = RTU_Entity (System)
1914 and then Present_System_Aux
1916 B_Scope := System_Aux_Id;
1917 Id := First_Entity (System_Aux_Id);
1923 end Collect_Primitive_Operations;
1925 -----------------------------------
1926 -- Compile_Time_Constraint_Error --
1927 -----------------------------------
1929 function Compile_Time_Constraint_Error
1932 Ent : Entity_Id := Empty;
1933 Loc : Source_Ptr := No_Location;
1934 Warn : Boolean := False) return Node_Id
1936 Msgc : String (1 .. Msg'Length + 2);
1937 -- Copy of message, with room for possible ? and ! at end
1947 -- A static constraint error in an instance body is not a fatal error.
1948 -- we choose to inhibit the message altogether, because there is no
1949 -- obvious node (for now) on which to post it. On the other hand the
1950 -- offending node must be replaced with a constraint_error in any case.
1952 -- No messages are generated if we already posted an error on this node
1954 if not Error_Posted (N) then
1955 if Loc /= No_Location then
1961 Msgc (1 .. Msg'Length) := Msg;
1964 -- Message is a warning, even in Ada 95 case
1966 if Msg (Msg'Last) = '?' then
1969 -- In Ada 83, all messages are warnings. In the private part and
1970 -- the body of an instance, constraint_checks are only warnings.
1971 -- We also make this a warning if the Warn parameter is set.
1974 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1980 elsif In_Instance_Not_Visible then
1985 -- Otherwise we have a real error message (Ada 95 static case)
1986 -- and we make this an unconditional message. Note that in the
1987 -- warning case we do not make the message unconditional, it seems
1988 -- quite reasonable to delete messages like this (about exceptions
1989 -- that will be raised) in dead code.
1997 -- Should we generate a warning? The answer is not quite yes. The
1998 -- very annoying exception occurs in the case of a short circuit
1999 -- operator where the left operand is static and decisive. Climb
2000 -- parents to see if that is the case we have here. Conditional
2001 -- expressions with decisive conditions are a similar situation.
2009 -- And then with False as left operand
2011 if Nkind (P) = N_And_Then
2012 and then Compile_Time_Known_Value (Left_Opnd (P))
2013 and then Is_False (Expr_Value (Left_Opnd (P)))
2018 -- OR ELSE with True as left operand
2020 elsif Nkind (P) = N_Or_Else
2021 and then Compile_Time_Known_Value (Left_Opnd (P))
2022 and then Is_True (Expr_Value (Left_Opnd (P)))
2027 -- Conditional expression
2029 elsif Nkind (P) = N_Conditional_Expression then
2031 Cond : constant Node_Id := First (Expressions (P));
2032 Texp : constant Node_Id := Next (Cond);
2033 Fexp : constant Node_Id := Next (Texp);
2036 if Compile_Time_Known_Value (Cond) then
2038 -- Condition is True and we are in the right operand
2040 if Is_True (Expr_Value (Cond))
2041 and then OldP = Fexp
2046 -- Condition is False and we are in the left operand
2048 elsif Is_False (Expr_Value (Cond))
2049 and then OldP = Texp
2057 -- Special case for component association in aggregates, where
2058 -- we want to keep climbing up to the parent aggregate.
2060 elsif Nkind (P) = N_Component_Association
2061 and then Nkind (Parent (P)) = N_Aggregate
2065 -- Keep going if within subexpression
2068 exit when Nkind (P) not in N_Subexpr;
2073 if Present (Ent) then
2074 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2076 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2080 if Inside_Init_Proc then
2082 ("\?& will be raised for objects of this type",
2083 N, Standard_Constraint_Error, Eloc);
2086 ("\?& will be raised at run time",
2087 N, Standard_Constraint_Error, Eloc);
2092 ("\static expression fails Constraint_Check", Eloc);
2093 Set_Error_Posted (N);
2099 end Compile_Time_Constraint_Error;
2101 -----------------------
2102 -- Conditional_Delay --
2103 -----------------------
2105 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2107 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2108 Set_Has_Delayed_Freeze (New_Ent);
2110 end Conditional_Delay;
2112 -------------------------
2113 -- Copy_Parameter_List --
2114 -------------------------
2116 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2117 Loc : constant Source_Ptr := Sloc (Subp_Id);
2122 if No (First_Formal (Subp_Id)) then
2126 Formal := First_Formal (Subp_Id);
2127 while Present (Formal) loop
2129 (Make_Parameter_Specification (Loc,
2130 Defining_Identifier =>
2131 Make_Defining_Identifier (Sloc (Formal),
2132 Chars => Chars (Formal)),
2133 In_Present => In_Present (Parent (Formal)),
2134 Out_Present => Out_Present (Parent (Formal)),
2136 New_Reference_To (Etype (Formal), Loc),
2138 New_Copy_Tree (Expression (Parent (Formal)))),
2141 Next_Formal (Formal);
2146 end Copy_Parameter_List;
2148 --------------------
2149 -- Current_Entity --
2150 --------------------
2152 -- The currently visible definition for a given identifier is the
2153 -- one most chained at the start of the visibility chain, i.e. the
2154 -- one that is referenced by the Node_Id value of the name of the
2155 -- given identifier.
2157 function Current_Entity (N : Node_Id) return Entity_Id is
2159 return Get_Name_Entity_Id (Chars (N));
2162 -----------------------------
2163 -- Current_Entity_In_Scope --
2164 -----------------------------
2166 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2168 CS : constant Entity_Id := Current_Scope;
2170 Transient_Case : constant Boolean := Scope_Is_Transient;
2173 E := Get_Name_Entity_Id (Chars (N));
2175 and then Scope (E) /= CS
2176 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2182 end Current_Entity_In_Scope;
2188 function Current_Scope return Entity_Id is
2190 if Scope_Stack.Last = -1 then
2191 return Standard_Standard;
2194 C : constant Entity_Id :=
2195 Scope_Stack.Table (Scope_Stack.Last).Entity;
2200 return Standard_Standard;
2206 ------------------------
2207 -- Current_Subprogram --
2208 ------------------------
2210 function Current_Subprogram return Entity_Id is
2211 Scop : constant Entity_Id := Current_Scope;
2213 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2216 return Enclosing_Subprogram (Scop);
2218 end Current_Subprogram;
2220 ---------------------
2221 -- Defining_Entity --
2222 ---------------------
2224 function Defining_Entity (N : Node_Id) return Entity_Id is
2225 K : constant Node_Kind := Nkind (N);
2226 Err : Entity_Id := Empty;
2231 N_Subprogram_Declaration |
2232 N_Abstract_Subprogram_Declaration |
2234 N_Package_Declaration |
2235 N_Subprogram_Renaming_Declaration |
2236 N_Subprogram_Body_Stub |
2237 N_Generic_Subprogram_Declaration |
2238 N_Generic_Package_Declaration |
2239 N_Formal_Subprogram_Declaration
2241 return Defining_Entity (Specification (N));
2244 N_Component_Declaration |
2245 N_Defining_Program_Unit_Name |
2246 N_Discriminant_Specification |
2248 N_Entry_Declaration |
2249 N_Entry_Index_Specification |
2250 N_Exception_Declaration |
2251 N_Exception_Renaming_Declaration |
2252 N_Formal_Object_Declaration |
2253 N_Formal_Package_Declaration |
2254 N_Formal_Type_Declaration |
2255 N_Full_Type_Declaration |
2256 N_Implicit_Label_Declaration |
2257 N_Incomplete_Type_Declaration |
2258 N_Loop_Parameter_Specification |
2259 N_Number_Declaration |
2260 N_Object_Declaration |
2261 N_Object_Renaming_Declaration |
2262 N_Package_Body_Stub |
2263 N_Parameter_Specification |
2264 N_Private_Extension_Declaration |
2265 N_Private_Type_Declaration |
2267 N_Protected_Body_Stub |
2268 N_Protected_Type_Declaration |
2269 N_Single_Protected_Declaration |
2270 N_Single_Task_Declaration |
2271 N_Subtype_Declaration |
2274 N_Task_Type_Declaration
2276 return Defining_Identifier (N);
2279 return Defining_Entity (Proper_Body (N));
2282 N_Function_Instantiation |
2283 N_Function_Specification |
2284 N_Generic_Function_Renaming_Declaration |
2285 N_Generic_Package_Renaming_Declaration |
2286 N_Generic_Procedure_Renaming_Declaration |
2288 N_Package_Instantiation |
2289 N_Package_Renaming_Declaration |
2290 N_Package_Specification |
2291 N_Procedure_Instantiation |
2292 N_Procedure_Specification
2295 Nam : constant Node_Id := Defining_Unit_Name (N);
2298 if Nkind (Nam) in N_Entity then
2301 -- For Error, make up a name and attach to declaration
2302 -- so we can continue semantic analysis
2304 elsif Nam = Error then
2305 Err := Make_Temporary (Sloc (N), 'T');
2306 Set_Defining_Unit_Name (N, Err);
2309 -- If not an entity, get defining identifier
2312 return Defining_Identifier (Nam);
2316 when N_Block_Statement =>
2317 return Entity (Identifier (N));
2320 raise Program_Error;
2323 end Defining_Entity;
2325 --------------------------
2326 -- Denotes_Discriminant --
2327 --------------------------
2329 function Denotes_Discriminant
2331 Check_Concurrent : Boolean := False) return Boolean
2335 if not Is_Entity_Name (N)
2336 or else No (Entity (N))
2343 -- If we are checking for a protected type, the discriminant may have
2344 -- been rewritten as the corresponding discriminal of the original type
2345 -- or of the corresponding concurrent record, depending on whether we
2346 -- are in the spec or body of the protected type.
2348 return Ekind (E) = E_Discriminant
2351 and then Ekind (E) = E_In_Parameter
2352 and then Present (Discriminal_Link (E))
2354 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2356 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2358 end Denotes_Discriminant;
2360 -------------------------
2361 -- Denotes_Same_Object --
2362 -------------------------
2364 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2365 Obj1 : Node_Id := A1;
2366 Obj2 : Node_Id := A2;
2368 procedure Check_Renaming (Obj : in out Node_Id);
2369 -- If an object is a renaming, examine renamed object. If it is a
2370 -- dereference of a variable, or an indexed expression with non-constant
2371 -- indexes, no overlap check can be reported.
2373 --------------------
2374 -- Check_Renaming --
2375 --------------------
2377 procedure Check_Renaming (Obj : in out Node_Id) is
2379 if Is_Entity_Name (Obj)
2380 and then Present (Renamed_Entity (Entity (Obj)))
2382 Obj := Renamed_Entity (Entity (Obj));
2383 if Nkind (Obj) = N_Explicit_Dereference
2384 and then Is_Variable (Prefix (Obj))
2388 elsif Nkind (Obj) = N_Indexed_Component then
2393 Indx := First (Expressions (Obj));
2394 while Present (Indx) loop
2395 if not Is_OK_Static_Expression (Indx) then
2407 -- Start of processing for Denotes_Same_Object
2410 Check_Renaming (Obj1);
2411 Check_Renaming (Obj2);
2419 -- If we have entity names, then must be same entity
2421 if Is_Entity_Name (Obj1) then
2422 if Is_Entity_Name (Obj2) then
2423 return Entity (Obj1) = Entity (Obj2);
2428 -- No match if not same node kind
2430 elsif Nkind (Obj1) /= Nkind (Obj2) then
2433 -- For selected components, must have same prefix and selector
2435 elsif Nkind (Obj1) = N_Selected_Component then
2436 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2438 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2440 -- For explicit dereferences, prefixes must be same
2442 elsif Nkind (Obj1) = N_Explicit_Dereference then
2443 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2445 -- For indexed components, prefixes and all subscripts must be the same
2447 elsif Nkind (Obj1) = N_Indexed_Component then
2448 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2454 Indx1 := First (Expressions (Obj1));
2455 Indx2 := First (Expressions (Obj2));
2456 while Present (Indx1) loop
2458 -- Indexes must denote the same static value or same object
2460 if Is_OK_Static_Expression (Indx1) then
2461 if not Is_OK_Static_Expression (Indx2) then
2464 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2468 elsif not Denotes_Same_Object (Indx1, Indx2) then
2482 -- For slices, prefixes must match and bounds must match
2484 elsif Nkind (Obj1) = N_Slice
2485 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2488 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2491 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2492 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2494 -- Check whether bounds are statically identical. There is no
2495 -- attempt to detect partial overlap of slices.
2497 return Denotes_Same_Object (Lo1, Lo2)
2498 and then Denotes_Same_Object (Hi1, Hi2);
2501 -- Literals will appear as indexes. Isn't this where we should check
2502 -- Known_At_Compile_Time at least if we are generating warnings ???
2504 elsif Nkind (Obj1) = N_Integer_Literal then
2505 return Intval (Obj1) = Intval (Obj2);
2510 end Denotes_Same_Object;
2512 -------------------------
2513 -- Denotes_Same_Prefix --
2514 -------------------------
2516 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2519 if Is_Entity_Name (A1) then
2520 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2521 and then not Is_Access_Type (Etype (A1))
2523 return Denotes_Same_Object (A1, Prefix (A2))
2524 or else Denotes_Same_Prefix (A1, Prefix (A2));
2529 elsif Is_Entity_Name (A2) then
2530 return Denotes_Same_Prefix (A2, A1);
2532 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2534 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2537 Root1, Root2 : Node_Id;
2538 Depth1, Depth2 : Int := 0;
2541 Root1 := Prefix (A1);
2542 while not Is_Entity_Name (Root1) loop
2544 (Root1, N_Selected_Component, N_Indexed_Component)
2548 Root1 := Prefix (Root1);
2551 Depth1 := Depth1 + 1;
2554 Root2 := Prefix (A2);
2555 while not Is_Entity_Name (Root2) loop
2557 (Root2, N_Selected_Component, N_Indexed_Component)
2561 Root2 := Prefix (Root2);
2564 Depth2 := Depth2 + 1;
2567 -- If both have the same depth and they do not denote the same
2568 -- object, they are disjoint and not warning is needed.
2570 if Depth1 = Depth2 then
2573 elsif Depth1 > Depth2 then
2574 Root1 := Prefix (A1);
2575 for I in 1 .. Depth1 - Depth2 - 1 loop
2576 Root1 := Prefix (Root1);
2579 return Denotes_Same_Object (Root1, A2);
2582 Root2 := Prefix (A2);
2583 for I in 1 .. Depth2 - Depth1 - 1 loop
2584 Root2 := Prefix (Root2);
2587 return Denotes_Same_Object (A1, Root2);
2594 end Denotes_Same_Prefix;
2596 ----------------------
2597 -- Denotes_Variable --
2598 ----------------------
2600 function Denotes_Variable (N : Node_Id) return Boolean is
2602 return Is_Variable (N) and then Paren_Count (N) = 0;
2603 end Denotes_Variable;
2605 -----------------------------
2606 -- Depends_On_Discriminant --
2607 -----------------------------
2609 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2614 Get_Index_Bounds (N, L, H);
2615 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2616 end Depends_On_Discriminant;
2618 -------------------------
2619 -- Designate_Same_Unit --
2620 -------------------------
2622 function Designate_Same_Unit
2624 Name2 : Node_Id) return Boolean
2626 K1 : constant Node_Kind := Nkind (Name1);
2627 K2 : constant Node_Kind := Nkind (Name2);
2629 function Prefix_Node (N : Node_Id) return Node_Id;
2630 -- Returns the parent unit name node of a defining program unit name
2631 -- or the prefix if N is a selected component or an expanded name.
2633 function Select_Node (N : Node_Id) return Node_Id;
2634 -- Returns the defining identifier node of a defining program unit
2635 -- name or the selector node if N is a selected component or an
2642 function Prefix_Node (N : Node_Id) return Node_Id is
2644 if Nkind (N) = N_Defining_Program_Unit_Name then
2656 function Select_Node (N : Node_Id) return Node_Id is
2658 if Nkind (N) = N_Defining_Program_Unit_Name then
2659 return Defining_Identifier (N);
2662 return Selector_Name (N);
2666 -- Start of processing for Designate_Next_Unit
2669 if (K1 = N_Identifier or else
2670 K1 = N_Defining_Identifier)
2672 (K2 = N_Identifier or else
2673 K2 = N_Defining_Identifier)
2675 return Chars (Name1) = Chars (Name2);
2678 (K1 = N_Expanded_Name or else
2679 K1 = N_Selected_Component or else
2680 K1 = N_Defining_Program_Unit_Name)
2682 (K2 = N_Expanded_Name or else
2683 K2 = N_Selected_Component or else
2684 K2 = N_Defining_Program_Unit_Name)
2687 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2689 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2694 end Designate_Same_Unit;
2696 --------------------------
2697 -- Enclosing_CPP_Parent --
2698 --------------------------
2700 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2701 Parent_Typ : Entity_Id := Typ;
2704 while not Is_CPP_Class (Parent_Typ)
2705 and then Etype (Parent_Typ) /= Parent_Typ
2707 Parent_Typ := Etype (Parent_Typ);
2709 if Is_Private_Type (Parent_Typ) then
2710 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2714 pragma Assert (Is_CPP_Class (Parent_Typ));
2716 end Enclosing_CPP_Parent;
2718 ----------------------------
2719 -- Enclosing_Generic_Body --
2720 ----------------------------
2722 function Enclosing_Generic_Body
2723 (N : Node_Id) return Node_Id
2731 while Present (P) loop
2732 if Nkind (P) = N_Package_Body
2733 or else Nkind (P) = N_Subprogram_Body
2735 Spec := Corresponding_Spec (P);
2737 if Present (Spec) then
2738 Decl := Unit_Declaration_Node (Spec);
2740 if Nkind (Decl) = N_Generic_Package_Declaration
2741 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2752 end Enclosing_Generic_Body;
2754 ----------------------------
2755 -- Enclosing_Generic_Unit --
2756 ----------------------------
2758 function Enclosing_Generic_Unit
2759 (N : Node_Id) return Node_Id
2767 while Present (P) loop
2768 if Nkind (P) = N_Generic_Package_Declaration
2769 or else Nkind (P) = N_Generic_Subprogram_Declaration
2773 elsif Nkind (P) = N_Package_Body
2774 or else Nkind (P) = N_Subprogram_Body
2776 Spec := Corresponding_Spec (P);
2778 if Present (Spec) then
2779 Decl := Unit_Declaration_Node (Spec);
2781 if Nkind (Decl) = N_Generic_Package_Declaration
2782 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2793 end Enclosing_Generic_Unit;
2795 -------------------------------
2796 -- Enclosing_Lib_Unit_Entity --
2797 -------------------------------
2799 function Enclosing_Lib_Unit_Entity return Entity_Id is
2800 Unit_Entity : Entity_Id;
2803 -- Look for enclosing library unit entity by following scope links.
2804 -- Equivalent to, but faster than indexing through the scope stack.
2806 Unit_Entity := Current_Scope;
2807 while (Present (Scope (Unit_Entity))
2808 and then Scope (Unit_Entity) /= Standard_Standard)
2809 and not Is_Child_Unit (Unit_Entity)
2811 Unit_Entity := Scope (Unit_Entity);
2815 end Enclosing_Lib_Unit_Entity;
2817 -----------------------------
2818 -- Enclosing_Lib_Unit_Node --
2819 -----------------------------
2821 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2822 Current_Node : Node_Id;
2826 while Present (Current_Node)
2827 and then Nkind (Current_Node) /= N_Compilation_Unit
2829 Current_Node := Parent (Current_Node);
2832 if Nkind (Current_Node) /= N_Compilation_Unit then
2836 return Current_Node;
2837 end Enclosing_Lib_Unit_Node;
2839 --------------------------
2840 -- Enclosing_Subprogram --
2841 --------------------------
2843 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2844 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2847 if Dynamic_Scope = Standard_Standard then
2850 elsif Dynamic_Scope = Empty then
2853 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2854 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2856 elsif Ekind (Dynamic_Scope) = E_Block
2857 or else Ekind (Dynamic_Scope) = E_Return_Statement
2859 return Enclosing_Subprogram (Dynamic_Scope);
2861 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2862 return Get_Task_Body_Procedure (Dynamic_Scope);
2864 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2865 and then Present (Full_View (Dynamic_Scope))
2866 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2868 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2870 -- No body is generated if the protected operation is eliminated
2872 elsif Convention (Dynamic_Scope) = Convention_Protected
2873 and then not Is_Eliminated (Dynamic_Scope)
2874 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2876 return Protected_Body_Subprogram (Dynamic_Scope);
2879 return Dynamic_Scope;
2881 end Enclosing_Subprogram;
2883 ------------------------
2884 -- Ensure_Freeze_Node --
2885 ------------------------
2887 procedure Ensure_Freeze_Node (E : Entity_Id) is
2891 if No (Freeze_Node (E)) then
2892 FN := Make_Freeze_Entity (Sloc (E));
2893 Set_Has_Delayed_Freeze (E);
2894 Set_Freeze_Node (E, FN);
2895 Set_Access_Types_To_Process (FN, No_Elist);
2896 Set_TSS_Elist (FN, No_Elist);
2899 end Ensure_Freeze_Node;
2905 procedure Enter_Name (Def_Id : Entity_Id) is
2906 C : constant Entity_Id := Current_Entity (Def_Id);
2907 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2908 S : constant Entity_Id := Current_Scope;
2911 Generate_Definition (Def_Id);
2913 -- Add new name to current scope declarations. Check for duplicate
2914 -- declaration, which may or may not be a genuine error.
2918 -- Case of previous entity entered because of a missing declaration
2919 -- or else a bad subtype indication. Best is to use the new entity,
2920 -- and make the previous one invisible.
2922 if Etype (E) = Any_Type then
2923 Set_Is_Immediately_Visible (E, False);
2925 -- Case of renaming declaration constructed for package instances.
2926 -- if there is an explicit declaration with the same identifier,
2927 -- the renaming is not immediately visible any longer, but remains
2928 -- visible through selected component notation.
2930 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2931 and then not Comes_From_Source (E)
2933 Set_Is_Immediately_Visible (E, False);
2935 -- The new entity may be the package renaming, which has the same
2936 -- same name as a generic formal which has been seen already.
2938 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2939 and then not Comes_From_Source (Def_Id)
2941 Set_Is_Immediately_Visible (E, False);
2943 -- For a fat pointer corresponding to a remote access to subprogram,
2944 -- we use the same identifier as the RAS type, so that the proper
2945 -- name appears in the stub. This type is only retrieved through
2946 -- the RAS type and never by visibility, and is not added to the
2947 -- visibility list (see below).
2949 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2950 and then Present (Corresponding_Remote_Type (Def_Id))
2954 -- A controller component for a type extension overrides the
2955 -- inherited component.
2957 elsif Chars (E) = Name_uController then
2960 -- Case of an implicit operation or derived literal. The new entity
2961 -- hides the implicit one, which is removed from all visibility,
2962 -- i.e. the entity list of its scope, and homonym chain of its name.
2964 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2965 or else Is_Internal (E)
2969 Prev_Vis : Entity_Id;
2970 Decl : constant Node_Id := Parent (E);
2973 -- If E is an implicit declaration, it cannot be the first
2974 -- entity in the scope.
2976 Prev := First_Entity (Current_Scope);
2977 while Present (Prev)
2978 and then Next_Entity (Prev) /= E
2985 -- If E is not on the entity chain of the current scope,
2986 -- it is an implicit declaration in the generic formal
2987 -- part of a generic subprogram. When analyzing the body,
2988 -- the generic formals are visible but not on the entity
2989 -- chain of the subprogram. The new entity will become
2990 -- the visible one in the body.
2993 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2997 Set_Next_Entity (Prev, Next_Entity (E));
2999 if No (Next_Entity (Prev)) then
3000 Set_Last_Entity (Current_Scope, Prev);
3003 if E = Current_Entity (E) then
3007 Prev_Vis := Current_Entity (E);
3008 while Homonym (Prev_Vis) /= E loop
3009 Prev_Vis := Homonym (Prev_Vis);
3013 if Present (Prev_Vis) then
3015 -- Skip E in the visibility chain
3017 Set_Homonym (Prev_Vis, Homonym (E));
3020 Set_Name_Entity_Id (Chars (E), Homonym (E));
3025 -- This section of code could use a comment ???
3027 elsif Present (Etype (E))
3028 and then Is_Concurrent_Type (Etype (E))
3033 -- If the homograph is a protected component renaming, it should not
3034 -- be hiding the current entity. Such renamings are treated as weak
3037 elsif Is_Prival (E) then
3038 Set_Is_Immediately_Visible (E, False);
3040 -- In this case the current entity is a protected component renaming.
3041 -- Perform minimal decoration by setting the scope and return since
3042 -- the prival should not be hiding other visible entities.
3044 elsif Is_Prival (Def_Id) then
3045 Set_Scope (Def_Id, Current_Scope);
3048 -- Analogous to privals, the discriminal generated for an entry index
3049 -- parameter acts as a weak declaration. Perform minimal decoration
3050 -- to avoid bogus errors.
3052 elsif Is_Discriminal (Def_Id)
3053 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3055 Set_Scope (Def_Id, Current_Scope);
3058 -- In the body or private part of an instance, a type extension may
3059 -- introduce a component with the same name as that of an actual. The
3060 -- legality rule is not enforced, but the semantics of the full type
3061 -- with two components of same name are not clear at this point???
3063 elsif In_Instance_Not_Visible then
3066 -- When compiling a package body, some child units may have become
3067 -- visible. They cannot conflict with local entities that hide them.
3069 elsif Is_Child_Unit (E)
3070 and then In_Open_Scopes (Scope (E))
3071 and then not Is_Immediately_Visible (E)
3075 -- Conversely, with front-end inlining we may compile the parent body
3076 -- first, and a child unit subsequently. The context is now the
3077 -- parent spec, and body entities are not visible.
3079 elsif Is_Child_Unit (Def_Id)
3080 and then Is_Package_Body_Entity (E)
3081 and then not In_Package_Body (Current_Scope)
3085 -- Case of genuine duplicate declaration
3088 Error_Msg_Sloc := Sloc (E);
3090 -- If the previous declaration is an incomplete type declaration
3091 -- this may be an attempt to complete it with a private type. The
3092 -- following avoids confusing cascaded errors.
3094 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3095 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3098 ("incomplete type cannot be completed with a private " &
3099 "declaration", Parent (Def_Id));
3100 Set_Is_Immediately_Visible (E, False);
3101 Set_Full_View (E, Def_Id);
3103 -- An inherited component of a record conflicts with a new
3104 -- discriminant. The discriminant is inserted first in the scope,
3105 -- but the error should be posted on it, not on the component.
3107 elsif Ekind (E) = E_Discriminant
3108 and then Present (Scope (Def_Id))
3109 and then Scope (Def_Id) /= Current_Scope
3111 Error_Msg_Sloc := Sloc (Def_Id);
3112 Error_Msg_N ("& conflicts with declaration#", E);
3115 -- If the name of the unit appears in its own context clause, a
3116 -- dummy package with the name has already been created, and the
3117 -- error emitted. Try to continue quietly.
3119 elsif Error_Posted (E)
3120 and then Sloc (E) = No_Location
3121 and then Nkind (Parent (E)) = N_Package_Specification
3122 and then Current_Scope = Standard_Standard
3124 Set_Scope (Def_Id, Current_Scope);
3128 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3130 -- Avoid cascaded messages with duplicate components in
3133 if Ekind_In (E, E_Component, E_Discriminant) then
3138 if Nkind (Parent (Parent (Def_Id))) =
3139 N_Generic_Subprogram_Declaration
3141 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3143 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3146 -- If entity is in standard, then we are in trouble, because it
3147 -- means that we have a library package with a duplicated name.
3148 -- That's hard to recover from, so abort!
3150 if S = Standard_Standard then
3151 raise Unrecoverable_Error;
3153 -- Otherwise we continue with the declaration. Having two
3154 -- identical declarations should not cause us too much trouble!
3162 -- If we fall through, declaration is OK, at least OK enough to continue
3164 -- If Def_Id is a discriminant or a record component we are in the midst
3165 -- of inheriting components in a derived record definition. Preserve
3166 -- their Ekind and Etype.
3168 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3171 -- If a type is already set, leave it alone (happens when a type
3172 -- declaration is reanalyzed following a call to the optimizer).
3174 elsif Present (Etype (Def_Id)) then
3177 -- Otherwise, the kind E_Void insures that premature uses of the entity
3178 -- will be detected. Any_Type insures that no cascaded errors will occur
3181 Set_Ekind (Def_Id, E_Void);
3182 Set_Etype (Def_Id, Any_Type);
3185 -- Inherited discriminants and components in derived record types are
3186 -- immediately visible. Itypes are not.
3188 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3189 or else (No (Corresponding_Remote_Type (Def_Id))
3190 and then not Is_Itype (Def_Id))
3192 Set_Is_Immediately_Visible (Def_Id);
3193 Set_Current_Entity (Def_Id);
3196 Set_Homonym (Def_Id, C);
3197 Append_Entity (Def_Id, S);
3198 Set_Public_Status (Def_Id);
3200 -- Warn if new entity hides an old one
3202 if Warn_On_Hiding and then Present (C)
3204 -- Don't warn for record components since they always have a well
3205 -- defined scope which does not confuse other uses. Note that in
3206 -- some cases, Ekind has not been set yet.
3208 and then Ekind (C) /= E_Component
3209 and then Ekind (C) /= E_Discriminant
3210 and then Nkind (Parent (C)) /= N_Component_Declaration
3211 and then Ekind (Def_Id) /= E_Component
3212 and then Ekind (Def_Id) /= E_Discriminant
3213 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3215 -- Don't warn for one character variables. It is too common to use
3216 -- such variables as locals and will just cause too many false hits.
3218 and then Length_Of_Name (Chars (C)) /= 1
3220 -- Don't warn for non-source entities
3222 and then Comes_From_Source (C)
3223 and then Comes_From_Source (Def_Id)
3225 -- Don't warn unless entity in question is in extended main source
3227 and then In_Extended_Main_Source_Unit (Def_Id)
3229 -- Finally, the hidden entity must be either immediately visible or
3230 -- use visible (i.e. from a used package).
3233 (Is_Immediately_Visible (C)
3235 Is_Potentially_Use_Visible (C))
3237 Error_Msg_Sloc := Sloc (C);
3238 Error_Msg_N ("declaration hides &#?", Def_Id);
3242 --------------------------
3243 -- Explain_Limited_Type --
3244 --------------------------
3246 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3250 -- For array, component type must be limited
3252 if Is_Array_Type (T) then
3253 Error_Msg_Node_2 := T;
3255 ("\component type& of type& is limited", N, Component_Type (T));
3256 Explain_Limited_Type (Component_Type (T), N);
3258 elsif Is_Record_Type (T) then
3260 -- No need for extra messages if explicit limited record
3262 if Is_Limited_Record (Base_Type (T)) then
3266 -- Otherwise find a limited component. Check only components that
3267 -- come from source, or inherited components that appear in the
3268 -- source of the ancestor.
3270 C := First_Component (T);
3271 while Present (C) loop
3272 if Is_Limited_Type (Etype (C))
3274 (Comes_From_Source (C)
3276 (Present (Original_Record_Component (C))
3278 Comes_From_Source (Original_Record_Component (C))))
3280 Error_Msg_Node_2 := T;
3281 Error_Msg_NE ("\component& of type& has limited type", N, C);
3282 Explain_Limited_Type (Etype (C), N);
3289 -- The type may be declared explicitly limited, even if no component
3290 -- of it is limited, in which case we fall out of the loop.
3293 end Explain_Limited_Type;
3299 procedure Find_Actual
3301 Formal : out Entity_Id;
3304 Parnt : constant Node_Id := Parent (N);
3308 if (Nkind (Parnt) = N_Indexed_Component
3310 Nkind (Parnt) = N_Selected_Component)
3311 and then N = Prefix (Parnt)
3313 Find_Actual (Parnt, Formal, Call);
3316 elsif Nkind (Parnt) = N_Parameter_Association
3317 and then N = Explicit_Actual_Parameter (Parnt)
3319 Call := Parent (Parnt);
3321 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3330 -- If we have a call to a subprogram look for the parameter. Note that
3331 -- we exclude overloaded calls, since we don't know enough to be sure
3332 -- of giving the right answer in this case.
3334 if Is_Entity_Name (Name (Call))
3335 and then Present (Entity (Name (Call)))
3336 and then Is_Overloadable (Entity (Name (Call)))
3337 and then not Is_Overloaded (Name (Call))
3339 -- Fall here if we are definitely a parameter
3341 Actual := First_Actual (Call);
3342 Formal := First_Formal (Entity (Name (Call)));
3343 while Present (Formal) and then Present (Actual) loop
3347 Actual := Next_Actual (Actual);
3348 Formal := Next_Formal (Formal);
3353 -- Fall through here if we did not find matching actual
3359 ---------------------------
3360 -- Find_Body_Discriminal --
3361 ---------------------------
3363 function Find_Body_Discriminal
3364 (Spec_Discriminant : Entity_Id) return Entity_Id
3366 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3368 Tsk : constant Entity_Id :=
3369 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3373 -- Find discriminant of original concurrent type, and use its current
3374 -- discriminal, which is the renaming within the task/protected body.
3376 Disc := First_Discriminant (Tsk);
3377 while Present (Disc) loop
3378 if Chars (Disc) = Chars (Spec_Discriminant) then
3379 return Discriminal (Disc);
3382 Next_Discriminant (Disc);
3385 -- That loop should always succeed in finding a matching entry and
3386 -- returning. Fatal error if not.
3388 raise Program_Error;
3389 end Find_Body_Discriminal;
3391 -------------------------------------
3392 -- Find_Corresponding_Discriminant --
3393 -------------------------------------
3395 function Find_Corresponding_Discriminant
3397 Typ : Entity_Id) return Entity_Id
3399 Par_Disc : Entity_Id;
3400 Old_Disc : Entity_Id;
3401 New_Disc : Entity_Id;
3404 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3406 -- The original type may currently be private, and the discriminant
3407 -- only appear on its full view.
3409 if Is_Private_Type (Scope (Par_Disc))
3410 and then not Has_Discriminants (Scope (Par_Disc))
3411 and then Present (Full_View (Scope (Par_Disc)))
3413 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3415 Old_Disc := First_Discriminant (Scope (Par_Disc));
3418 if Is_Class_Wide_Type (Typ) then
3419 New_Disc := First_Discriminant (Root_Type (Typ));
3421 New_Disc := First_Discriminant (Typ);
3424 while Present (Old_Disc) and then Present (New_Disc) loop
3425 if Old_Disc = Par_Disc then
3428 Next_Discriminant (Old_Disc);
3429 Next_Discriminant (New_Disc);
3433 -- Should always find it
3435 raise Program_Error;
3436 end Find_Corresponding_Discriminant;
3438 --------------------------
3439 -- Find_Overlaid_Entity --
3440 --------------------------
3442 procedure Find_Overlaid_Entity
3444 Ent : out Entity_Id;
3450 -- We are looking for one of the two following forms:
3452 -- for X'Address use Y'Address
3456 -- Const : constant Address := expr;
3458 -- for X'Address use Const;
3460 -- In the second case, the expr is either Y'Address, or recursively a
3461 -- constant that eventually references Y'Address.
3466 if Nkind (N) = N_Attribute_Definition_Clause
3467 and then Chars (N) = Name_Address
3469 Expr := Expression (N);
3471 -- This loop checks the form of the expression for Y'Address,
3472 -- using recursion to deal with intermediate constants.
3475 -- Check for Y'Address
3477 if Nkind (Expr) = N_Attribute_Reference
3478 and then Attribute_Name (Expr) = Name_Address
3480 Expr := Prefix (Expr);
3483 -- Check for Const where Const is a constant entity
3485 elsif Is_Entity_Name (Expr)
3486 and then Ekind (Entity (Expr)) = E_Constant
3488 Expr := Constant_Value (Entity (Expr));
3490 -- Anything else does not need checking
3497 -- This loop checks the form of the prefix for an entity,
3498 -- using recursion to deal with intermediate components.
3501 -- Check for Y where Y is an entity
3503 if Is_Entity_Name (Expr) then
3504 Ent := Entity (Expr);
3507 -- Check for components
3510 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3512 Expr := Prefix (Expr);
3515 -- Anything else does not need checking
3522 end Find_Overlaid_Entity;
3524 -------------------------
3525 -- Find_Parameter_Type --
3526 -------------------------
3528 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3530 if Nkind (Param) /= N_Parameter_Specification then
3533 -- For an access parameter, obtain the type from the formal entity
3534 -- itself, because access to subprogram nodes do not carry a type.
3535 -- Shouldn't we always use the formal entity ???
3537 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3538 return Etype (Defining_Identifier (Param));
3541 return Etype (Parameter_Type (Param));
3543 end Find_Parameter_Type;
3545 -----------------------------
3546 -- Find_Static_Alternative --
3547 -----------------------------
3549 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3550 Expr : constant Node_Id := Expression (N);
3551 Val : constant Uint := Expr_Value (Expr);
3556 Alt := First (Alternatives (N));
3559 if Nkind (Alt) /= N_Pragma then
3560 Choice := First (Discrete_Choices (Alt));
3561 while Present (Choice) loop
3563 -- Others choice, always matches
3565 if Nkind (Choice) = N_Others_Choice then
3568 -- Range, check if value is in the range
3570 elsif Nkind (Choice) = N_Range then
3572 Val >= Expr_Value (Low_Bound (Choice))
3574 Val <= Expr_Value (High_Bound (Choice));
3576 -- Choice is a subtype name. Note that we know it must
3577 -- be a static subtype, since otherwise it would have
3578 -- been diagnosed as illegal.
3580 elsif Is_Entity_Name (Choice)
3581 and then Is_Type (Entity (Choice))
3583 exit Search when Is_In_Range (Expr, Etype (Choice),
3584 Assume_Valid => False);
3586 -- Choice is a subtype indication
3588 elsif Nkind (Choice) = N_Subtype_Indication then
3590 C : constant Node_Id := Constraint (Choice);
3591 R : constant Node_Id := Range_Expression (C);
3595 Val >= Expr_Value (Low_Bound (R))
3597 Val <= Expr_Value (High_Bound (R));
3600 -- Choice is a simple expression
3603 exit Search when Val = Expr_Value (Choice);
3611 pragma Assert (Present (Alt));
3614 -- The above loop *must* terminate by finding a match, since
3615 -- we know the case statement is valid, and the value of the
3616 -- expression is known at compile time. When we fall out of
3617 -- the loop, Alt points to the alternative that we know will
3618 -- be selected at run time.
3621 end Find_Static_Alternative;
3627 function First_Actual (Node : Node_Id) return Node_Id is
3631 if No (Parameter_Associations (Node)) then
3635 N := First (Parameter_Associations (Node));
3637 if Nkind (N) = N_Parameter_Association then
3638 return First_Named_Actual (Node);
3644 -----------------------
3645 -- Gather_Components --
3646 -----------------------
3648 procedure Gather_Components
3650 Comp_List : Node_Id;
3651 Governed_By : List_Id;
3653 Report_Errors : out Boolean)
3657 Discrete_Choice : Node_Id;
3658 Comp_Item : Node_Id;
3660 Discrim : Entity_Id;
3661 Discrim_Name : Node_Id;
3662 Discrim_Value : Node_Id;
3665 Report_Errors := False;
3667 if No (Comp_List) or else Null_Present (Comp_List) then
3670 elsif Present (Component_Items (Comp_List)) then
3671 Comp_Item := First (Component_Items (Comp_List));
3677 while Present (Comp_Item) loop
3679 -- Skip the tag of a tagged record, the interface tags, as well
3680 -- as all items that are not user components (anonymous types,
3681 -- rep clauses, Parent field, controller field).
3683 if Nkind (Comp_Item) = N_Component_Declaration then
3685 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3687 if not Is_Tag (Comp)
3688 and then Chars (Comp) /= Name_uParent
3689 and then Chars (Comp) /= Name_uController
3691 Append_Elmt (Comp, Into);
3699 if No (Variant_Part (Comp_List)) then
3702 Discrim_Name := Name (Variant_Part (Comp_List));
3703 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3706 -- Look for the discriminant that governs this variant part.
3707 -- The discriminant *must* be in the Governed_By List
3709 Assoc := First (Governed_By);
3710 Find_Constraint : loop
3711 Discrim := First (Choices (Assoc));
3712 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3713 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3715 Chars (Corresponding_Discriminant (Entity (Discrim)))
3716 = Chars (Discrim_Name))
3717 or else Chars (Original_Record_Component (Entity (Discrim)))
3718 = Chars (Discrim_Name);
3720 if No (Next (Assoc)) then
3721 if not Is_Constrained (Typ)
3722 and then Is_Derived_Type (Typ)
3723 and then Present (Stored_Constraint (Typ))
3725 -- If the type is a tagged type with inherited discriminants,
3726 -- use the stored constraint on the parent in order to find
3727 -- the values of discriminants that are otherwise hidden by an
3728 -- explicit constraint. Renamed discriminants are handled in
3731 -- If several parent discriminants are renamed by a single
3732 -- discriminant of the derived type, the call to obtain the
3733 -- Corresponding_Discriminant field only retrieves the last
3734 -- of them. We recover the constraint on the others from the
3735 -- Stored_Constraint as well.
3742 D := First_Discriminant (Etype (Typ));
3743 C := First_Elmt (Stored_Constraint (Typ));
3744 while Present (D) and then Present (C) loop
3745 if Chars (Discrim_Name) = Chars (D) then
3746 if Is_Entity_Name (Node (C))
3747 and then Entity (Node (C)) = Entity (Discrim)
3749 -- D is renamed by Discrim, whose value is given in
3756 Make_Component_Association (Sloc (Typ),
3758 (New_Occurrence_Of (D, Sloc (Typ))),
3759 Duplicate_Subexpr_No_Checks (Node (C)));
3761 exit Find_Constraint;
3764 Next_Discriminant (D);
3771 if No (Next (Assoc)) then
3772 Error_Msg_NE (" missing value for discriminant&",
3773 First (Governed_By), Discrim_Name);
3774 Report_Errors := True;
3779 end loop Find_Constraint;
3781 Discrim_Value := Expression (Assoc);
3783 if not Is_OK_Static_Expression (Discrim_Value) then
3785 ("value for discriminant & must be static!",
3786 Discrim_Value, Discrim);
3787 Why_Not_Static (Discrim_Value);
3788 Report_Errors := True;
3792 Search_For_Discriminant_Value : declare
3798 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3801 Find_Discrete_Value : while Present (Variant) loop
3802 Discrete_Choice := First (Discrete_Choices (Variant));
3803 while Present (Discrete_Choice) loop
3805 exit Find_Discrete_Value when
3806 Nkind (Discrete_Choice) = N_Others_Choice;
3808 Get_Index_Bounds (Discrete_Choice, Low, High);
3810 UI_Low := Expr_Value (Low);
3811 UI_High := Expr_Value (High);
3813 exit Find_Discrete_Value when
3814 UI_Low <= UI_Discrim_Value
3816 UI_High >= UI_Discrim_Value;
3818 Next (Discrete_Choice);
3821 Next_Non_Pragma (Variant);
3822 end loop Find_Discrete_Value;
3823 end Search_For_Discriminant_Value;
3825 if No (Variant) then
3827 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3828 Report_Errors := True;
3832 -- If we have found the corresponding choice, recursively add its
3833 -- components to the Into list.
3835 Gather_Components (Empty,
3836 Component_List (Variant), Governed_By, Into, Report_Errors);
3837 end Gather_Components;
3839 ------------------------
3840 -- Get_Actual_Subtype --
3841 ------------------------
3843 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3844 Typ : constant Entity_Id := Etype (N);
3845 Utyp : Entity_Id := Underlying_Type (Typ);
3854 -- If what we have is an identifier that references a subprogram
3855 -- formal, or a variable or constant object, then we get the actual
3856 -- subtype from the referenced entity if one has been built.
3858 if Nkind (N) = N_Identifier
3860 (Is_Formal (Entity (N))
3861 or else Ekind (Entity (N)) = E_Constant
3862 or else Ekind (Entity (N)) = E_Variable)
3863 and then Present (Actual_Subtype (Entity (N)))
3865 return Actual_Subtype (Entity (N));
3867 -- Actual subtype of unchecked union is always itself. We never need
3868 -- the "real" actual subtype. If we did, we couldn't get it anyway
3869 -- because the discriminant is not available. The restrictions on
3870 -- Unchecked_Union are designed to make sure that this is OK.
3872 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3875 -- Here for the unconstrained case, we must find actual subtype
3876 -- No actual subtype is available, so we must build it on the fly.
3878 -- Checking the type, not the underlying type, for constrainedness
3879 -- seems to be necessary. Maybe all the tests should be on the type???
3881 elsif (not Is_Constrained (Typ))
3882 and then (Is_Array_Type (Utyp)
3883 or else (Is_Record_Type (Utyp)
3884 and then Has_Discriminants (Utyp)))
3885 and then not Has_Unknown_Discriminants (Utyp)
3886 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3888 -- Nothing to do if in spec expression (why not???)
3890 if In_Spec_Expression then
3893 elsif Is_Private_Type (Typ)
3894 and then not Has_Discriminants (Typ)
3896 -- If the type has no discriminants, there is no subtype to
3897 -- build, even if the underlying type is discriminated.
3901 -- Else build the actual subtype
3904 Decl := Build_Actual_Subtype (Typ, N);
3905 Atyp := Defining_Identifier (Decl);
3907 -- If Build_Actual_Subtype generated a new declaration then use it
3911 -- The actual subtype is an Itype, so analyze the declaration,
3912 -- but do not attach it to the tree, to get the type defined.
3914 Set_Parent (Decl, N);
3915 Set_Is_Itype (Atyp);
3916 Analyze (Decl, Suppress => All_Checks);
3917 Set_Associated_Node_For_Itype (Atyp, N);
3918 Set_Has_Delayed_Freeze (Atyp, False);
3920 -- We need to freeze the actual subtype immediately. This is
3921 -- needed, because otherwise this Itype will not get frozen
3922 -- at all, and it is always safe to freeze on creation because
3923 -- any associated types must be frozen at this point.
3925 Freeze_Itype (Atyp, N);
3928 -- Otherwise we did not build a declaration, so return original
3935 -- For all remaining cases, the actual subtype is the same as
3936 -- the nominal type.
3941 end Get_Actual_Subtype;
3943 -------------------------------------
3944 -- Get_Actual_Subtype_If_Available --
3945 -------------------------------------
3947 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3948 Typ : constant Entity_Id := Etype (N);
3951 -- If what we have is an identifier that references a subprogram
3952 -- formal, or a variable or constant object, then we get the actual
3953 -- subtype from the referenced entity if one has been built.
3955 if Nkind (N) = N_Identifier
3957 (Is_Formal (Entity (N))
3958 or else Ekind (Entity (N)) = E_Constant
3959 or else Ekind (Entity (N)) = E_Variable)
3960 and then Present (Actual_Subtype (Entity (N)))
3962 return Actual_Subtype (Entity (N));
3964 -- Otherwise the Etype of N is returned unchanged
3969 end Get_Actual_Subtype_If_Available;
3971 -------------------------------
3972 -- Get_Default_External_Name --
3973 -------------------------------
3975 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3977 Get_Decoded_Name_String (Chars (E));
3979 if Opt.External_Name_Imp_Casing = Uppercase then
3980 Set_Casing (All_Upper_Case);
3982 Set_Casing (All_Lower_Case);
3986 Make_String_Literal (Sloc (E),
3987 Strval => String_From_Name_Buffer);
3988 end Get_Default_External_Name;
3990 ---------------------------
3991 -- Get_Enum_Lit_From_Pos --
3992 ---------------------------
3994 function Get_Enum_Lit_From_Pos
3997 Loc : Source_Ptr) return Node_Id
4002 -- In the case where the literal is of type Character, Wide_Character
4003 -- or Wide_Wide_Character or of a type derived from them, there needs
4004 -- to be some special handling since there is no explicit chain of
4005 -- literals to search. Instead, an N_Character_Literal node is created
4006 -- with the appropriate Char_Code and Chars fields.
4008 if Is_Standard_Character_Type (T) then
4009 Set_Character_Literal_Name (UI_To_CC (Pos));
4011 Make_Character_Literal (Loc,
4013 Char_Literal_Value => Pos);
4015 -- For all other cases, we have a complete table of literals, and
4016 -- we simply iterate through the chain of literal until the one
4017 -- with the desired position value is found.
4021 Lit := First_Literal (Base_Type (T));
4022 for J in 1 .. UI_To_Int (Pos) loop
4026 return New_Occurrence_Of (Lit, Loc);
4028 end Get_Enum_Lit_From_Pos;
4030 ------------------------
4031 -- Get_Generic_Entity --
4032 ------------------------
4034 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4035 Ent : constant Entity_Id := Entity (Name (N));
4037 if Present (Renamed_Object (Ent)) then
4038 return Renamed_Object (Ent);
4042 end Get_Generic_Entity;
4044 ----------------------
4045 -- Get_Index_Bounds --
4046 ----------------------
4048 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4049 Kind : constant Node_Kind := Nkind (N);
4053 if Kind = N_Range then
4055 H := High_Bound (N);
4057 elsif Kind = N_Subtype_Indication then
4058 R := Range_Expression (Constraint (N));
4066 L := Low_Bound (Range_Expression (Constraint (N)));
4067 H := High_Bound (Range_Expression (Constraint (N)));
4070 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4071 if Error_Posted (Scalar_Range (Entity (N))) then
4075 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4076 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4079 L := Low_Bound (Scalar_Range (Entity (N)));
4080 H := High_Bound (Scalar_Range (Entity (N)));
4084 -- N is an expression, indicating a range with one value
4089 end Get_Index_Bounds;
4091 ----------------------------------
4092 -- Get_Library_Unit_Name_string --
4093 ----------------------------------
4095 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4096 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4099 Get_Unit_Name_String (Unit_Name_Id);
4101 -- Remove seven last character (" (spec)" or " (body)")
4103 Name_Len := Name_Len - 7;
4104 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4105 end Get_Library_Unit_Name_String;
4107 ------------------------
4108 -- Get_Name_Entity_Id --
4109 ------------------------
4111 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4113 return Entity_Id (Get_Name_Table_Info (Id));
4114 end Get_Name_Entity_Id;
4120 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4122 return Get_Pragma_Id (Pragma_Name (N));
4125 ---------------------------
4126 -- Get_Referenced_Object --
4127 ---------------------------
4129 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4134 while Is_Entity_Name (R)
4135 and then Present (Renamed_Object (Entity (R)))
4137 R := Renamed_Object (Entity (R));
4141 end Get_Referenced_Object;
4143 ------------------------
4144 -- Get_Renamed_Entity --
4145 ------------------------
4147 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4152 while Present (Renamed_Entity (R)) loop
4153 R := Renamed_Entity (R);
4157 end Get_Renamed_Entity;
4159 -------------------------
4160 -- Get_Subprogram_Body --
4161 -------------------------
4163 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4167 Decl := Unit_Declaration_Node (E);
4169 if Nkind (Decl) = N_Subprogram_Body then
4172 -- The below comment is bad, because it is possible for
4173 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4175 else -- Nkind (Decl) = N_Subprogram_Declaration
4177 if Present (Corresponding_Body (Decl)) then
4178 return Unit_Declaration_Node (Corresponding_Body (Decl));
4180 -- Imported subprogram case
4186 end Get_Subprogram_Body;
4188 ---------------------------
4189 -- Get_Subprogram_Entity --
4190 ---------------------------
4192 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4197 if Nkind (Nod) = N_Accept_Statement then
4198 Nam := Entry_Direct_Name (Nod);
4200 -- For an entry call, the prefix of the call is a selected component.
4201 -- Need additional code for internal calls ???
4203 elsif Nkind (Nod) = N_Entry_Call_Statement then
4204 if Nkind (Name (Nod)) = N_Selected_Component then
4205 Nam := Entity (Selector_Name (Name (Nod)));
4214 if Nkind (Nam) = N_Explicit_Dereference then
4215 Proc := Etype (Prefix (Nam));
4216 elsif Is_Entity_Name (Nam) then
4217 Proc := Entity (Nam);
4222 if Is_Object (Proc) then
4223 Proc := Etype (Proc);
4226 if Ekind (Proc) = E_Access_Subprogram_Type then
4227 Proc := Directly_Designated_Type (Proc);
4230 if not Is_Subprogram (Proc)
4231 and then Ekind (Proc) /= E_Subprogram_Type
4237 end Get_Subprogram_Entity;
4239 -----------------------------
4240 -- Get_Task_Body_Procedure --
4241 -----------------------------
4243 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4245 -- Note: A task type may be the completion of a private type with
4246 -- discriminants. When performing elaboration checks on a task
4247 -- declaration, the current view of the type may be the private one,
4248 -- and the procedure that holds the body of the task is held in its
4251 -- This is an odd function, why not have Task_Body_Procedure do
4252 -- the following digging???
4254 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4255 end Get_Task_Body_Procedure;
4257 -----------------------
4258 -- Has_Access_Values --
4259 -----------------------
4261 function Has_Access_Values (T : Entity_Id) return Boolean is
4262 Typ : constant Entity_Id := Underlying_Type (T);
4265 -- Case of a private type which is not completed yet. This can only
4266 -- happen in the case of a generic format type appearing directly, or
4267 -- as a component of the type to which this function is being applied
4268 -- at the top level. Return False in this case, since we certainly do
4269 -- not know that the type contains access types.
4274 elsif Is_Access_Type (Typ) then
4277 elsif Is_Array_Type (Typ) then
4278 return Has_Access_Values (Component_Type (Typ));
4280 elsif Is_Record_Type (Typ) then
4285 -- Loop to Check components
4287 Comp := First_Component_Or_Discriminant (Typ);
4288 while Present (Comp) loop
4290 -- Check for access component, tag field does not count, even
4291 -- though it is implemented internally using an access type.
4293 if Has_Access_Values (Etype (Comp))
4294 and then Chars (Comp) /= Name_uTag
4299 Next_Component_Or_Discriminant (Comp);
4308 end Has_Access_Values;
4310 ------------------------------
4311 -- Has_Compatible_Alignment --
4312 ------------------------------
4314 function Has_Compatible_Alignment
4316 Expr : Node_Id) return Alignment_Result
4318 function Has_Compatible_Alignment_Internal
4321 Default : Alignment_Result) return Alignment_Result;
4322 -- This is the internal recursive function that actually does the work.
4323 -- There is one additional parameter, which says what the result should
4324 -- be if no alignment information is found, and there is no definite
4325 -- indication of compatible alignments. At the outer level, this is set
4326 -- to Unknown, but for internal recursive calls in the case where types
4327 -- are known to be correct, it is set to Known_Compatible.
4329 ---------------------------------------
4330 -- Has_Compatible_Alignment_Internal --
4331 ---------------------------------------
4333 function Has_Compatible_Alignment_Internal
4336 Default : Alignment_Result) return Alignment_Result
4338 Result : Alignment_Result := Known_Compatible;
4339 -- Holds the current status of the result. Note that once a value of
4340 -- Known_Incompatible is set, it is sticky and does not get changed
4341 -- to Unknown (the value in Result only gets worse as we go along,
4344 Offs : Uint := No_Uint;
4345 -- Set to a factor of the offset from the base object when Expr is a
4346 -- selected or indexed component, based on Component_Bit_Offset and
4347 -- Component_Size respectively. A negative value is used to represent
4348 -- a value which is not known at compile time.
4350 procedure Check_Prefix;
4351 -- Checks the prefix recursively in the case where the expression
4352 -- is an indexed or selected component.
4354 procedure Set_Result (R : Alignment_Result);
4355 -- If R represents a worse outcome (unknown instead of known
4356 -- compatible, or known incompatible), then set Result to R.
4362 procedure Check_Prefix is
4364 -- The subtlety here is that in doing a recursive call to check
4365 -- the prefix, we have to decide what to do in the case where we
4366 -- don't find any specific indication of an alignment problem.
4368 -- At the outer level, we normally set Unknown as the result in
4369 -- this case, since we can only set Known_Compatible if we really
4370 -- know that the alignment value is OK, but for the recursive
4371 -- call, in the case where the types match, and we have not
4372 -- specified a peculiar alignment for the object, we are only
4373 -- concerned about suspicious rep clauses, the default case does
4374 -- not affect us, since the compiler will, in the absence of such
4375 -- rep clauses, ensure that the alignment is correct.
4377 if Default = Known_Compatible
4379 (Etype (Obj) = Etype (Expr)
4380 and then (Unknown_Alignment (Obj)
4382 Alignment (Obj) = Alignment (Etype (Obj))))
4385 (Has_Compatible_Alignment_Internal
4386 (Obj, Prefix (Expr), Known_Compatible));
4388 -- In all other cases, we need a full check on the prefix
4392 (Has_Compatible_Alignment_Internal
4393 (Obj, Prefix (Expr), Unknown));
4401 procedure Set_Result (R : Alignment_Result) is
4408 -- Start of processing for Has_Compatible_Alignment_Internal
4411 -- If Expr is a selected component, we must make sure there is no
4412 -- potentially troublesome component clause, and that the record is
4415 if Nkind (Expr) = N_Selected_Component then
4417 -- Packed record always generate unknown alignment
4419 if Is_Packed (Etype (Prefix (Expr))) then
4420 Set_Result (Unknown);
4423 -- Check prefix and component offset
4426 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4428 -- If Expr is an indexed component, we must make sure there is no
4429 -- potentially troublesome Component_Size clause and that the array
4430 -- is not bit-packed.
4432 elsif Nkind (Expr) = N_Indexed_Component then
4434 Typ : constant Entity_Id := Etype (Prefix (Expr));
4435 Ind : constant Node_Id := First_Index (Typ);
4438 -- Bit packed array always generates unknown alignment
4440 if Is_Bit_Packed_Array (Typ) then
4441 Set_Result (Unknown);
4444 -- Check prefix and component offset
4447 Offs := Component_Size (Typ);
4449 -- Small optimization: compute the full offset when possible
4452 and then Offs > Uint_0
4453 and then Present (Ind)
4454 and then Nkind (Ind) = N_Range
4455 and then Compile_Time_Known_Value (Low_Bound (Ind))
4456 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4458 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4459 - Expr_Value (Low_Bound ((Ind))));
4464 -- If we have a null offset, the result is entirely determined by
4465 -- the base object and has already been computed recursively.
4467 if Offs = Uint_0 then
4470 -- Case where we know the alignment of the object
4472 elsif Known_Alignment (Obj) then
4474 ObjA : constant Uint := Alignment (Obj);
4475 ExpA : Uint := No_Uint;
4476 SizA : Uint := No_Uint;
4479 -- If alignment of Obj is 1, then we are always OK
4482 Set_Result (Known_Compatible);
4484 -- Alignment of Obj is greater than 1, so we need to check
4487 -- If we have an offset, see if it is compatible
4489 if Offs /= No_Uint and Offs > Uint_0 then
4490 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4491 Set_Result (Known_Incompatible);
4494 -- See if Expr is an object with known alignment
4496 elsif Is_Entity_Name (Expr)
4497 and then Known_Alignment (Entity (Expr))
4499 ExpA := Alignment (Entity (Expr));
4501 -- Otherwise, we can use the alignment of the type of
4502 -- Expr given that we already checked for
4503 -- discombobulating rep clauses for the cases of indexed
4504 -- and selected components above.
4506 elsif Known_Alignment (Etype (Expr)) then
4507 ExpA := Alignment (Etype (Expr));
4509 -- Otherwise the alignment is unknown
4512 Set_Result (Default);
4515 -- If we got an alignment, see if it is acceptable
4517 if ExpA /= No_Uint and then ExpA < ObjA then
4518 Set_Result (Known_Incompatible);
4521 -- If Expr is not a piece of a larger object, see if size
4522 -- is given. If so, check that it is not too small for the
4523 -- required alignment.
4525 if Offs /= No_Uint then
4528 -- See if Expr is an object with known size
4530 elsif Is_Entity_Name (Expr)
4531 and then Known_Static_Esize (Entity (Expr))
4533 SizA := Esize (Entity (Expr));
4535 -- Otherwise, we check the object size of the Expr type
4537 elsif Known_Static_Esize (Etype (Expr)) then
4538 SizA := Esize (Etype (Expr));
4541 -- If we got a size, see if it is a multiple of the Obj
4542 -- alignment, if not, then the alignment cannot be
4543 -- acceptable, since the size is always a multiple of the
4546 if SizA /= No_Uint then
4547 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4548 Set_Result (Known_Incompatible);
4554 -- If we do not know required alignment, any non-zero offset is a
4555 -- potential problem (but certainly may be OK, so result is unknown).
4557 elsif Offs /= No_Uint then
4558 Set_Result (Unknown);
4560 -- If we can't find the result by direct comparison of alignment
4561 -- values, then there is still one case that we can determine known
4562 -- result, and that is when we can determine that the types are the
4563 -- same, and no alignments are specified. Then we known that the
4564 -- alignments are compatible, even if we don't know the alignment
4565 -- value in the front end.
4567 elsif Etype (Obj) = Etype (Expr) then
4569 -- Types are the same, but we have to check for possible size
4570 -- and alignments on the Expr object that may make the alignment
4571 -- different, even though the types are the same.
4573 if Is_Entity_Name (Expr) then
4575 -- First check alignment of the Expr object. Any alignment less
4576 -- than Maximum_Alignment is worrisome since this is the case
4577 -- where we do not know the alignment of Obj.
4579 if Known_Alignment (Entity (Expr))
4581 UI_To_Int (Alignment (Entity (Expr))) <
4582 Ttypes.Maximum_Alignment
4584 Set_Result (Unknown);
4586 -- Now check size of Expr object. Any size that is not an
4587 -- even multiple of Maximum_Alignment is also worrisome
4588 -- since it may cause the alignment of the object to be less
4589 -- than the alignment of the type.
4591 elsif Known_Static_Esize (Entity (Expr))
4593 (UI_To_Int (Esize (Entity (Expr))) mod
4594 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4597 Set_Result (Unknown);
4599 -- Otherwise same type is decisive
4602 Set_Result (Known_Compatible);
4606 -- Another case to deal with is when there is an explicit size or
4607 -- alignment clause when the types are not the same. If so, then the
4608 -- result is Unknown. We don't need to do this test if the Default is
4609 -- Unknown, since that result will be set in any case.
4611 elsif Default /= Unknown
4612 and then (Has_Size_Clause (Etype (Expr))
4614 Has_Alignment_Clause (Etype (Expr)))
4616 Set_Result (Unknown);
4618 -- If no indication found, set default
4621 Set_Result (Default);
4624 -- Return worst result found
4627 end Has_Compatible_Alignment_Internal;
4629 -- Start of processing for Has_Compatible_Alignment
4632 -- If Obj has no specified alignment, then set alignment from the type
4633 -- alignment. Perhaps we should always do this, but for sure we should
4634 -- do it when there is an address clause since we can do more if the
4635 -- alignment is known.
4637 if Unknown_Alignment (Obj) then
4638 Set_Alignment (Obj, Alignment (Etype (Obj)));
4641 -- Now do the internal call that does all the work
4643 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4644 end Has_Compatible_Alignment;
4646 ----------------------
4647 -- Has_Declarations --
4648 ----------------------
4650 function Has_Declarations (N : Node_Id) return Boolean is
4652 return Nkind_In (Nkind (N), N_Accept_Statement,
4654 N_Compilation_Unit_Aux,
4660 N_Package_Specification);
4661 end Has_Declarations;
4663 -------------------------------------------
4664 -- Has_Discriminant_Dependent_Constraint --
4665 -------------------------------------------
4667 function Has_Discriminant_Dependent_Constraint
4668 (Comp : Entity_Id) return Boolean
4670 Comp_Decl : constant Node_Id := Parent (Comp);
4671 Subt_Indic : constant Node_Id :=
4672 Subtype_Indication (Component_Definition (Comp_Decl));
4677 if Nkind (Subt_Indic) = N_Subtype_Indication then
4678 Constr := Constraint (Subt_Indic);
4680 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4681 Assn := First (Constraints (Constr));
4682 while Present (Assn) loop
4683 case Nkind (Assn) is
4684 when N_Subtype_Indication |
4688 if Depends_On_Discriminant (Assn) then
4692 when N_Discriminant_Association =>
4693 if Depends_On_Discriminant (Expression (Assn)) then
4708 end Has_Discriminant_Dependent_Constraint;
4710 --------------------
4711 -- Has_Infinities --
4712 --------------------
4714 function Has_Infinities (E : Entity_Id) return Boolean is
4717 Is_Floating_Point_Type (E)
4718 and then Nkind (Scalar_Range (E)) = N_Range
4719 and then Includes_Infinities (Scalar_Range (E));
4722 --------------------
4723 -- Has_Interfaces --
4724 --------------------
4726 function Has_Interfaces
4728 Use_Full_View : Boolean := True) return Boolean
4730 Typ : Entity_Id := Base_Type (T);
4733 -- Handle concurrent types
4735 if Is_Concurrent_Type (Typ) then
4736 Typ := Corresponding_Record_Type (Typ);
4739 if not Present (Typ)
4740 or else not Is_Record_Type (Typ)
4741 or else not Is_Tagged_Type (Typ)
4746 -- Handle private types
4749 and then Present (Full_View (Typ))
4751 Typ := Full_View (Typ);
4754 -- Handle concurrent record types
4756 if Is_Concurrent_Record_Type (Typ)
4757 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4763 if Is_Interface (Typ)
4765 (Is_Record_Type (Typ)
4766 and then Present (Interfaces (Typ))
4767 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4772 exit when Etype (Typ) = Typ
4774 -- Handle private types
4776 or else (Present (Full_View (Etype (Typ)))
4777 and then Full_View (Etype (Typ)) = Typ)
4779 -- Protect the frontend against wrong source with cyclic
4782 or else Etype (Typ) = T;
4784 -- Climb to the ancestor type handling private types
4786 if Present (Full_View (Etype (Typ))) then
4787 Typ := Full_View (Etype (Typ));
4796 ------------------------
4797 -- Has_Null_Exclusion --
4798 ------------------------
4800 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4803 when N_Access_Definition |
4804 N_Access_Function_Definition |
4805 N_Access_Procedure_Definition |
4806 N_Access_To_Object_Definition |
4808 N_Derived_Type_Definition |
4809 N_Function_Specification |
4810 N_Subtype_Declaration =>
4811 return Null_Exclusion_Present (N);
4813 when N_Component_Definition |
4814 N_Formal_Object_Declaration |
4815 N_Object_Renaming_Declaration =>
4816 if Present (Subtype_Mark (N)) then
4817 return Null_Exclusion_Present (N);
4818 else pragma Assert (Present (Access_Definition (N)));
4819 return Null_Exclusion_Present (Access_Definition (N));
4822 when N_Discriminant_Specification =>
4823 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4824 return Null_Exclusion_Present (Discriminant_Type (N));
4826 return Null_Exclusion_Present (N);
4829 when N_Object_Declaration =>
4830 if Nkind (Object_Definition (N)) = N_Access_Definition then
4831 return Null_Exclusion_Present (Object_Definition (N));
4833 return Null_Exclusion_Present (N);
4836 when N_Parameter_Specification =>
4837 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4838 return Null_Exclusion_Present (Parameter_Type (N));
4840 return Null_Exclusion_Present (N);
4847 end Has_Null_Exclusion;
4849 ------------------------
4850 -- Has_Null_Extension --
4851 ------------------------
4853 function Has_Null_Extension (T : Entity_Id) return Boolean is
4854 B : constant Entity_Id := Base_Type (T);
4859 if Nkind (Parent (B)) = N_Full_Type_Declaration
4860 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4862 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4864 if Present (Ext) then
4865 if Null_Present (Ext) then
4868 Comps := Component_List (Ext);
4870 -- The null component list is rewritten during analysis to
4871 -- include the parent component. Any other component indicates
4872 -- that the extension was not originally null.
4874 return Null_Present (Comps)
4875 or else No (Next (First (Component_Items (Comps))));
4884 end Has_Null_Extension;
4886 -------------------------------
4887 -- Has_Overriding_Initialize --
4888 -------------------------------
4890 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4891 BT : constant Entity_Id := Base_Type (T);
4895 if Is_Controlled (BT) then
4896 if Is_RTU (Scope (BT), Ada_Finalization) then
4899 elsif Present (Primitive_Operations (BT)) then
4900 P := First_Elmt (Primitive_Operations (BT));
4901 while Present (P) loop
4903 Init : constant Entity_Id := Node (P);
4904 Formal : constant Entity_Id := First_Formal (Init);
4906 if Ekind (Init) = E_Procedure
4907 and then Chars (Init) = Name_Initialize
4908 and then Comes_From_Source (Init)
4909 and then Present (Formal)
4910 and then Etype (Formal) = BT
4911 and then No (Next_Formal (Formal))
4912 and then (Ada_Version < Ada_2012
4913 or else not Null_Present (Parent (Init)))
4923 -- Here if type itself does not have a non-null Initialize operation:
4924 -- check immediate ancestor.
4926 if Is_Derived_Type (BT)
4927 and then Has_Overriding_Initialize (Etype (BT))
4934 end Has_Overriding_Initialize;
4936 --------------------------------------
4937 -- Has_Preelaborable_Initialization --
4938 --------------------------------------
4940 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4943 procedure Check_Components (E : Entity_Id);
4944 -- Check component/discriminant chain, sets Has_PE False if a component
4945 -- or discriminant does not meet the preelaborable initialization rules.
4947 ----------------------
4948 -- Check_Components --
4949 ----------------------
4951 procedure Check_Components (E : Entity_Id) is
4955 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4956 -- Returns True if and only if the expression denoted by N does not
4957 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4959 ---------------------------------
4960 -- Is_Preelaborable_Expression --
4961 ---------------------------------
4963 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4967 Comp_Type : Entity_Id;
4968 Is_Array_Aggr : Boolean;
4971 if Is_Static_Expression (N) then
4974 elsif Nkind (N) = N_Null then
4977 -- Attributes are allowed in general, even if their prefix is a
4978 -- formal type. (It seems that certain attributes known not to be
4979 -- static might not be allowed, but there are no rules to prevent
4982 elsif Nkind (N) = N_Attribute_Reference then
4985 -- The name of a discriminant evaluated within its parent type is
4986 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4987 -- names that denote discriminals as well as discriminants to
4988 -- catch references occurring within init procs.
4990 elsif Is_Entity_Name (N)
4992 (Ekind (Entity (N)) = E_Discriminant
4994 ((Ekind (Entity (N)) = E_Constant
4995 or else Ekind (Entity (N)) = E_In_Parameter)
4996 and then Present (Discriminal_Link (Entity (N)))))
5000 elsif Nkind (N) = N_Qualified_Expression then
5001 return Is_Preelaborable_Expression (Expression (N));
5003 -- For aggregates we have to check that each of the associations
5004 -- is preelaborable.
5006 elsif Nkind (N) = N_Aggregate
5007 or else Nkind (N) = N_Extension_Aggregate
5009 Is_Array_Aggr := Is_Array_Type (Etype (N));
5011 if Is_Array_Aggr then
5012 Comp_Type := Component_Type (Etype (N));
5015 -- Check the ancestor part of extension aggregates, which must
5016 -- be either the name of a type that has preelaborable init or
5017 -- an expression that is preelaborable.
5019 if Nkind (N) = N_Extension_Aggregate then
5021 Anc_Part : constant Node_Id := Ancestor_Part (N);
5024 if Is_Entity_Name (Anc_Part)
5025 and then Is_Type (Entity (Anc_Part))
5027 if not Has_Preelaborable_Initialization
5033 elsif not Is_Preelaborable_Expression (Anc_Part) then
5039 -- Check positional associations
5041 Exp := First (Expressions (N));
5042 while Present (Exp) loop
5043 if not Is_Preelaborable_Expression (Exp) then
5050 -- Check named associations
5052 Assn := First (Component_Associations (N));
5053 while Present (Assn) loop
5054 Choice := First (Choices (Assn));
5055 while Present (Choice) loop
5056 if Is_Array_Aggr then
5057 if Nkind (Choice) = N_Others_Choice then
5060 elsif Nkind (Choice) = N_Range then
5061 if not Is_Static_Range (Choice) then
5065 elsif not Is_Static_Expression (Choice) then
5070 Comp_Type := Etype (Choice);
5076 -- If the association has a <> at this point, then we have
5077 -- to check whether the component's type has preelaborable
5078 -- initialization. Note that this only occurs when the
5079 -- association's corresponding component does not have a
5080 -- default expression, the latter case having already been
5081 -- expanded as an expression for the association.
5083 if Box_Present (Assn) then
5084 if not Has_Preelaborable_Initialization (Comp_Type) then
5088 -- In the expression case we check whether the expression
5089 -- is preelaborable.
5092 not Is_Preelaborable_Expression (Expression (Assn))
5100 -- If we get here then aggregate as a whole is preelaborable
5104 -- All other cases are not preelaborable
5109 end Is_Preelaborable_Expression;
5111 -- Start of processing for Check_Components
5114 -- Loop through entities of record or protected type
5117 while Present (Ent) loop
5119 -- We are interested only in components and discriminants
5126 -- Get default expression if any. If there is no declaration
5127 -- node, it means we have an internal entity. The parent and
5128 -- tag fields are examples of such entities. For such cases,
5129 -- we just test the type of the entity.
5131 if Present (Declaration_Node (Ent)) then
5132 Exp := Expression (Declaration_Node (Ent));
5135 when E_Discriminant =>
5137 -- Note: for a renamed discriminant, the Declaration_Node
5138 -- may point to the one from the ancestor, and have a
5139 -- different expression, so use the proper attribute to
5140 -- retrieve the expression from the derived constraint.
5142 Exp := Discriminant_Default_Value (Ent);
5145 goto Check_Next_Entity;
5148 -- A component has PI if it has no default expression and the
5149 -- component type has PI.
5152 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5157 -- Require the default expression to be preelaborable
5159 elsif not Is_Preelaborable_Expression (Exp) then
5164 <<Check_Next_Entity>>
5167 end Check_Components;
5169 -- Start of processing for Has_Preelaborable_Initialization
5172 -- Immediate return if already marked as known preelaborable init. This
5173 -- covers types for which this function has already been called once
5174 -- and returned True (in which case the result is cached), and also
5175 -- types to which a pragma Preelaborable_Initialization applies.
5177 if Known_To_Have_Preelab_Init (E) then
5181 -- If the type is a subtype representing a generic actual type, then
5182 -- test whether its base type has preelaborable initialization since
5183 -- the subtype representing the actual does not inherit this attribute
5184 -- from the actual or formal. (but maybe it should???)
5186 if Is_Generic_Actual_Type (E) then
5187 return Has_Preelaborable_Initialization (Base_Type (E));
5190 -- All elementary types have preelaborable initialization
5192 if Is_Elementary_Type (E) then
5195 -- Array types have PI if the component type has PI
5197 elsif Is_Array_Type (E) then
5198 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5200 -- A derived type has preelaborable initialization if its parent type
5201 -- has preelaborable initialization and (in the case of a derived record
5202 -- extension) if the non-inherited components all have preelaborable
5203 -- initialization. However, a user-defined controlled type with an
5204 -- overriding Initialize procedure does not have preelaborable
5207 elsif Is_Derived_Type (E) then
5209 -- If the derived type is a private extension then it doesn't have
5210 -- preelaborable initialization.
5212 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5216 -- First check whether ancestor type has preelaborable initialization
5218 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5220 -- If OK, check extension components (if any)
5222 if Has_PE and then Is_Record_Type (E) then
5223 Check_Components (First_Entity (E));
5226 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5227 -- with a user defined Initialize procedure does not have PI.
5230 and then Is_Controlled (E)
5231 and then Has_Overriding_Initialize (E)
5236 -- Private types not derived from a type having preelaborable init and
5237 -- that are not marked with pragma Preelaborable_Initialization do not
5238 -- have preelaborable initialization.
5240 elsif Is_Private_Type (E) then
5243 -- Record type has PI if it is non private and all components have PI
5245 elsif Is_Record_Type (E) then
5247 Check_Components (First_Entity (E));
5249 -- Protected types must not have entries, and components must meet
5250 -- same set of rules as for record components.
5252 elsif Is_Protected_Type (E) then
5253 if Has_Entries (E) then
5257 Check_Components (First_Entity (E));
5258 Check_Components (First_Private_Entity (E));
5261 -- Type System.Address always has preelaborable initialization
5263 elsif Is_RTE (E, RE_Address) then
5266 -- In all other cases, type does not have preelaborable initialization
5272 -- If type has preelaborable initialization, cache result
5275 Set_Known_To_Have_Preelab_Init (E);
5279 end Has_Preelaborable_Initialization;
5281 ---------------------------
5282 -- Has_Private_Component --
5283 ---------------------------
5285 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5286 Btype : Entity_Id := Base_Type (Type_Id);
5287 Component : Entity_Id;
5290 if Error_Posted (Type_Id)
5291 or else Error_Posted (Btype)
5296 if Is_Class_Wide_Type (Btype) then
5297 Btype := Root_Type (Btype);
5300 if Is_Private_Type (Btype) then
5302 UT : constant Entity_Id := Underlying_Type (Btype);
5305 if No (Full_View (Btype)) then
5306 return not Is_Generic_Type (Btype)
5307 and then not Is_Generic_Type (Root_Type (Btype));
5309 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5312 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5316 elsif Is_Array_Type (Btype) then
5317 return Has_Private_Component (Component_Type (Btype));
5319 elsif Is_Record_Type (Btype) then
5320 Component := First_Component (Btype);
5321 while Present (Component) loop
5322 if Has_Private_Component (Etype (Component)) then
5326 Next_Component (Component);
5331 elsif Is_Protected_Type (Btype)
5332 and then Present (Corresponding_Record_Type (Btype))
5334 return Has_Private_Component (Corresponding_Record_Type (Btype));
5339 end Has_Private_Component;
5345 function Has_Stream (T : Entity_Id) return Boolean is
5352 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5355 elsif Is_Array_Type (T) then
5356 return Has_Stream (Component_Type (T));
5358 elsif Is_Record_Type (T) then
5359 E := First_Component (T);
5360 while Present (E) loop
5361 if Has_Stream (Etype (E)) then
5370 elsif Is_Private_Type (T) then
5371 return Has_Stream (Underlying_Type (T));
5382 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5384 Get_Name_String (Chars (E));
5385 return Name_Buffer (Name_Len) = Suffix;
5388 --------------------------
5389 -- Has_Tagged_Component --
5390 --------------------------
5392 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5396 if Is_Private_Type (Typ)
5397 and then Present (Underlying_Type (Typ))
5399 return Has_Tagged_Component (Underlying_Type (Typ));
5401 elsif Is_Array_Type (Typ) then
5402 return Has_Tagged_Component (Component_Type (Typ));
5404 elsif Is_Tagged_Type (Typ) then
5407 elsif Is_Record_Type (Typ) then
5408 Comp := First_Component (Typ);
5409 while Present (Comp) loop
5410 if Has_Tagged_Component (Etype (Comp)) then
5414 Next_Component (Comp);
5422 end Has_Tagged_Component;
5424 -------------------------
5425 -- Implementation_Kind --
5426 -------------------------
5428 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5429 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5431 pragma Assert (Present (Impl_Prag));
5433 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5434 end Implementation_Kind;
5436 --------------------------
5437 -- Implements_Interface --
5438 --------------------------
5440 function Implements_Interface
5441 (Typ_Ent : Entity_Id;
5442 Iface_Ent : Entity_Id;
5443 Exclude_Parents : Boolean := False) return Boolean
5445 Ifaces_List : Elist_Id;
5447 Iface : Entity_Id := Base_Type (Iface_Ent);
5448 Typ : Entity_Id := Base_Type (Typ_Ent);
5451 if Is_Class_Wide_Type (Typ) then
5452 Typ := Root_Type (Typ);
5455 if not Has_Interfaces (Typ) then
5459 if Is_Class_Wide_Type (Iface) then
5460 Iface := Root_Type (Iface);
5463 Collect_Interfaces (Typ, Ifaces_List);
5465 Elmt := First_Elmt (Ifaces_List);
5466 while Present (Elmt) loop
5467 if Is_Ancestor (Node (Elmt), Typ)
5468 and then Exclude_Parents
5472 elsif Node (Elmt) = Iface then
5480 end Implements_Interface;
5486 function In_Instance return Boolean is
5487 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5493 and then S /= Standard_Standard
5495 if (Ekind (S) = E_Function
5496 or else Ekind (S) = E_Package
5497 or else Ekind (S) = E_Procedure)
5498 and then Is_Generic_Instance (S)
5500 -- A child instance is always compiled in the context of a parent
5501 -- instance. Nevertheless, the actuals are not analyzed in an
5502 -- instance context. We detect this case by examining the current
5503 -- compilation unit, which must be a child instance, and checking
5504 -- that it is not currently on the scope stack.
5506 if Is_Child_Unit (Curr_Unit)
5508 Nkind (Unit (Cunit (Current_Sem_Unit)))
5509 = N_Package_Instantiation
5510 and then not In_Open_Scopes (Curr_Unit)
5524 ----------------------
5525 -- In_Instance_Body --
5526 ----------------------
5528 function In_Instance_Body return Boolean is
5534 and then S /= Standard_Standard
5536 if (Ekind (S) = E_Function
5537 or else Ekind (S) = E_Procedure)
5538 and then Is_Generic_Instance (S)
5542 elsif Ekind (S) = E_Package
5543 and then In_Package_Body (S)
5544 and then Is_Generic_Instance (S)
5553 end In_Instance_Body;
5555 -----------------------------
5556 -- In_Instance_Not_Visible --
5557 -----------------------------
5559 function In_Instance_Not_Visible return Boolean is
5565 and then S /= Standard_Standard
5567 if (Ekind (S) = E_Function
5568 or else Ekind (S) = E_Procedure)
5569 and then Is_Generic_Instance (S)
5573 elsif Ekind (S) = E_Package
5574 and then (In_Package_Body (S) or else In_Private_Part (S))
5575 and then Is_Generic_Instance (S)
5584 end In_Instance_Not_Visible;
5586 ------------------------------
5587 -- In_Instance_Visible_Part --
5588 ------------------------------
5590 function In_Instance_Visible_Part return Boolean is
5596 and then S /= Standard_Standard
5598 if Ekind (S) = E_Package
5599 and then Is_Generic_Instance (S)
5600 and then not In_Package_Body (S)
5601 and then not In_Private_Part (S)
5610 end In_Instance_Visible_Part;
5612 ---------------------
5613 -- In_Package_Body --
5614 ---------------------
5616 function In_Package_Body return Boolean is
5622 and then S /= Standard_Standard
5624 if Ekind (S) = E_Package
5625 and then In_Package_Body (S)
5634 end In_Package_Body;
5636 --------------------------------
5637 -- In_Parameter_Specification --
5638 --------------------------------
5640 function In_Parameter_Specification (N : Node_Id) return Boolean is
5645 while Present (PN) loop
5646 if Nkind (PN) = N_Parameter_Specification then
5654 end In_Parameter_Specification;
5656 --------------------------------------
5657 -- In_Subprogram_Or_Concurrent_Unit --
5658 --------------------------------------
5660 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5665 -- Use scope chain to check successively outer scopes
5671 if K in Subprogram_Kind
5672 or else K in Concurrent_Kind
5673 or else K in Generic_Subprogram_Kind
5677 elsif E = Standard_Standard then
5683 end In_Subprogram_Or_Concurrent_Unit;
5685 ---------------------
5686 -- In_Visible_Part --
5687 ---------------------
5689 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5692 Is_Package_Or_Generic_Package (Scope_Id)
5693 and then In_Open_Scopes (Scope_Id)
5694 and then not In_Package_Body (Scope_Id)
5695 and then not In_Private_Part (Scope_Id);
5696 end In_Visible_Part;
5698 ---------------------------------
5699 -- Insert_Explicit_Dereference --
5700 ---------------------------------
5702 procedure Insert_Explicit_Dereference (N : Node_Id) is
5703 New_Prefix : constant Node_Id := Relocate_Node (N);
5704 Ent : Entity_Id := Empty;
5711 Save_Interps (N, New_Prefix);
5714 Make_Explicit_Dereference (Sloc (Parent (N)),
5715 Prefix => New_Prefix));
5717 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5719 if Is_Overloaded (New_Prefix) then
5721 -- The dereference is also overloaded, and its interpretations are
5722 -- the designated types of the interpretations of the original node.
5724 Set_Etype (N, Any_Type);
5726 Get_First_Interp (New_Prefix, I, It);
5727 while Present (It.Nam) loop
5730 if Is_Access_Type (T) then
5731 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5734 Get_Next_Interp (I, It);
5740 -- Prefix is unambiguous: mark the original prefix (which might
5741 -- Come_From_Source) as a reference, since the new (relocated) one
5742 -- won't be taken into account.
5744 if Is_Entity_Name (New_Prefix) then
5745 Ent := Entity (New_Prefix);
5748 -- For a retrieval of a subcomponent of some composite object,
5749 -- retrieve the ultimate entity if there is one.
5751 elsif Nkind (New_Prefix) = N_Selected_Component
5752 or else Nkind (New_Prefix) = N_Indexed_Component
5754 Pref := Prefix (New_Prefix);
5755 while Present (Pref)
5757 (Nkind (Pref) = N_Selected_Component
5758 or else Nkind (Pref) = N_Indexed_Component)
5760 Pref := Prefix (Pref);
5763 if Present (Pref) and then Is_Entity_Name (Pref) then
5764 Ent := Entity (Pref);
5768 -- Place the reference on the entity node
5770 if Present (Ent) then
5771 Generate_Reference (Ent, Pref);
5774 end Insert_Explicit_Dereference;
5776 ------------------------------------------
5777 -- Inspect_Deferred_Constant_Completion --
5778 ------------------------------------------
5780 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5784 Decl := First (Decls);
5785 while Present (Decl) loop
5787 -- Deferred constant signature
5789 if Nkind (Decl) = N_Object_Declaration
5790 and then Constant_Present (Decl)
5791 and then No (Expression (Decl))
5793 -- No need to check internally generated constants
5795 and then Comes_From_Source (Decl)
5797 -- The constant is not completed. A full object declaration or a
5798 -- pragma Import complete a deferred constant.
5800 and then not Has_Completion (Defining_Identifier (Decl))
5803 ("constant declaration requires initialization expression",
5804 Defining_Identifier (Decl));
5807 Decl := Next (Decl);
5809 end Inspect_Deferred_Constant_Completion;
5811 -----------------------------
5812 -- Is_Actual_Out_Parameter --
5813 -----------------------------
5815 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5819 Find_Actual (N, Formal, Call);
5820 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5821 end Is_Actual_Out_Parameter;
5823 -------------------------
5824 -- Is_Actual_Parameter --
5825 -------------------------
5827 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5828 PK : constant Node_Kind := Nkind (Parent (N));
5832 when N_Parameter_Association =>
5833 return N = Explicit_Actual_Parameter (Parent (N));
5835 when N_Function_Call | N_Procedure_Call_Statement =>
5836 return Is_List_Member (N)
5838 List_Containing (N) = Parameter_Associations (Parent (N));
5843 end Is_Actual_Parameter;
5845 ---------------------
5846 -- Is_Aliased_View --
5847 ---------------------
5849 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5853 if Is_Entity_Name (Obj) then
5861 or else (Present (Renamed_Object (E))
5862 and then Is_Aliased_View (Renamed_Object (E)))))
5864 or else ((Is_Formal (E)
5865 or else Ekind (E) = E_Generic_In_Out_Parameter
5866 or else Ekind (E) = E_Generic_In_Parameter)
5867 and then Is_Tagged_Type (Etype (E)))
5869 or else (Is_Concurrent_Type (E)
5870 and then In_Open_Scopes (E))
5872 -- Current instance of type, either directly or as rewritten
5873 -- reference to the current object.
5875 or else (Is_Entity_Name (Original_Node (Obj))
5876 and then Present (Entity (Original_Node (Obj)))
5877 and then Is_Type (Entity (Original_Node (Obj))))
5879 or else (Is_Type (E) and then E = Current_Scope)
5881 or else (Is_Incomplete_Or_Private_Type (E)
5882 and then Full_View (E) = Current_Scope);
5884 elsif Nkind (Obj) = N_Selected_Component then
5885 return Is_Aliased (Entity (Selector_Name (Obj)));
5887 elsif Nkind (Obj) = N_Indexed_Component then
5888 return Has_Aliased_Components (Etype (Prefix (Obj)))
5890 (Is_Access_Type (Etype (Prefix (Obj)))
5892 Has_Aliased_Components
5893 (Designated_Type (Etype (Prefix (Obj)))));
5895 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5896 or else Nkind (Obj) = N_Type_Conversion
5898 return Is_Tagged_Type (Etype (Obj))
5899 and then Is_Aliased_View (Expression (Obj));
5901 elsif Nkind (Obj) = N_Explicit_Dereference then
5902 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5907 end Is_Aliased_View;
5909 -------------------------
5910 -- Is_Ancestor_Package --
5911 -------------------------
5913 function Is_Ancestor_Package
5915 E2 : Entity_Id) return Boolean
5922 and then Par /= Standard_Standard
5932 end Is_Ancestor_Package;
5934 ----------------------
5935 -- Is_Atomic_Object --
5936 ----------------------
5938 function Is_Atomic_Object (N : Node_Id) return Boolean is
5940 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5941 -- Determines if given object has atomic components
5943 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5944 -- If prefix is an implicit dereference, examine designated type
5946 ----------------------
5947 -- Is_Atomic_Prefix --
5948 ----------------------
5950 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5952 if Is_Access_Type (Etype (N)) then
5954 Has_Atomic_Components (Designated_Type (Etype (N)));
5956 return Object_Has_Atomic_Components (N);
5958 end Is_Atomic_Prefix;
5960 ----------------------------------
5961 -- Object_Has_Atomic_Components --
5962 ----------------------------------
5964 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5966 if Has_Atomic_Components (Etype (N))
5967 or else Is_Atomic (Etype (N))
5971 elsif Is_Entity_Name (N)
5972 and then (Has_Atomic_Components (Entity (N))
5973 or else Is_Atomic (Entity (N)))
5977 elsif Nkind (N) = N_Indexed_Component
5978 or else Nkind (N) = N_Selected_Component
5980 return Is_Atomic_Prefix (Prefix (N));
5985 end Object_Has_Atomic_Components;
5987 -- Start of processing for Is_Atomic_Object
5990 -- Predicate is not relevant to subprograms
5992 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
5995 elsif Is_Atomic (Etype (N))
5996 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6000 elsif Nkind (N) = N_Indexed_Component
6001 or else Nkind (N) = N_Selected_Component
6003 return Is_Atomic_Prefix (Prefix (N));
6008 end Is_Atomic_Object;
6010 -------------------------
6011 -- Is_Coextension_Root --
6012 -------------------------
6014 function Is_Coextension_Root (N : Node_Id) return Boolean is
6017 Nkind (N) = N_Allocator
6018 and then Present (Coextensions (N))
6020 -- Anonymous access discriminants carry a list of all nested
6021 -- controlled coextensions.
6023 and then not Is_Dynamic_Coextension (N)
6024 and then not Is_Static_Coextension (N);
6025 end Is_Coextension_Root;
6027 -----------------------------
6028 -- Is_Concurrent_Interface --
6029 -----------------------------
6031 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6036 (Is_Protected_Interface (T)
6037 or else Is_Synchronized_Interface (T)
6038 or else Is_Task_Interface (T));
6039 end Is_Concurrent_Interface;
6041 --------------------------------------
6042 -- Is_Controlling_Limited_Procedure --
6043 --------------------------------------
6045 function Is_Controlling_Limited_Procedure
6046 (Proc_Nam : Entity_Id) return Boolean
6048 Param_Typ : Entity_Id := Empty;
6051 if Ekind (Proc_Nam) = E_Procedure
6052 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6054 Param_Typ := Etype (Parameter_Type (First (
6055 Parameter_Specifications (Parent (Proc_Nam)))));
6057 -- In this case where an Itype was created, the procedure call has been
6060 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6061 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6063 Present (Parameter_Associations
6064 (Associated_Node_For_Itype (Proc_Nam)))
6067 Etype (First (Parameter_Associations
6068 (Associated_Node_For_Itype (Proc_Nam))));
6071 if Present (Param_Typ) then
6073 Is_Interface (Param_Typ)
6074 and then Is_Limited_Record (Param_Typ);
6078 end Is_Controlling_Limited_Procedure;
6080 -----------------------------
6081 -- Is_CPP_Constructor_Call --
6082 -----------------------------
6084 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6086 return Nkind (N) = N_Function_Call
6087 and then Is_CPP_Class (Etype (Etype (N)))
6088 and then Is_Constructor (Entity (Name (N)))
6089 and then Is_Imported (Entity (Name (N)));
6090 end Is_CPP_Constructor_Call;
6096 function Is_Delegate (T : Entity_Id) return Boolean is
6097 Desig_Type : Entity_Id;
6100 if VM_Target /= CLI_Target then
6104 -- Access-to-subprograms are delegates in CIL
6106 if Ekind (T) = E_Access_Subprogram_Type then
6110 if Ekind (T) not in Access_Kind then
6112 -- A delegate is a managed pointer. If no designated type is defined
6113 -- it means that it's not a delegate.
6118 Desig_Type := Etype (Directly_Designated_Type (T));
6120 if not Is_Tagged_Type (Desig_Type) then
6124 -- Test if the type is inherited from [mscorlib]System.Delegate
6126 while Etype (Desig_Type) /= Desig_Type loop
6127 if Chars (Scope (Desig_Type)) /= No_Name
6128 and then Is_Imported (Scope (Desig_Type))
6129 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6134 Desig_Type := Etype (Desig_Type);
6140 ----------------------------------------------
6141 -- Is_Dependent_Component_Of_Mutable_Object --
6142 ----------------------------------------------
6144 function Is_Dependent_Component_Of_Mutable_Object
6145 (Object : Node_Id) return Boolean
6148 Prefix_Type : Entity_Id;
6149 P_Aliased : Boolean := False;
6152 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6153 -- Returns True if and only if Comp is declared within a variant part
6155 --------------------------------
6156 -- Is_Declared_Within_Variant --
6157 --------------------------------
6159 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6160 Comp_Decl : constant Node_Id := Parent (Comp);
6161 Comp_List : constant Node_Id := Parent (Comp_Decl);
6163 return Nkind (Parent (Comp_List)) = N_Variant;
6164 end Is_Declared_Within_Variant;
6166 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6169 if Is_Variable (Object) then
6171 if Nkind (Object) = N_Selected_Component then
6172 P := Prefix (Object);
6173 Prefix_Type := Etype (P);
6175 if Is_Entity_Name (P) then
6177 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6178 Prefix_Type := Base_Type (Prefix_Type);
6181 if Is_Aliased (Entity (P)) then
6185 -- A discriminant check on a selected component may be expanded
6186 -- into a dereference when removing side-effects. Recover the
6187 -- original node and its type, which may be unconstrained.
6189 elsif Nkind (P) = N_Explicit_Dereference
6190 and then not (Comes_From_Source (P))
6192 P := Original_Node (P);
6193 Prefix_Type := Etype (P);
6196 -- Check for prefix being an aliased component???
6202 -- A heap object is constrained by its initial value
6204 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6205 -- the dereferenced case, since the access value might denote an
6206 -- unconstrained aliased object, whereas in Ada 95 the designated
6207 -- object is guaranteed to be constrained. A worst-case assumption
6208 -- has to apply in Ada 2005 because we can't tell at compile time
6209 -- whether the object is "constrained by its initial value"
6210 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6211 -- semantic rules -- these rules are acknowledged to need fixing).
6213 if Ada_Version < Ada_2005 then
6214 if Is_Access_Type (Prefix_Type)
6215 or else Nkind (P) = N_Explicit_Dereference
6220 elsif Ada_Version >= Ada_2005 then
6221 if Is_Access_Type (Prefix_Type) then
6223 -- If the access type is pool-specific, and there is no
6224 -- constrained partial view of the designated type, then the
6225 -- designated object is known to be constrained.
6227 if Ekind (Prefix_Type) = E_Access_Type
6228 and then not Has_Constrained_Partial_View
6229 (Designated_Type (Prefix_Type))
6233 -- Otherwise (general access type, or there is a constrained
6234 -- partial view of the designated type), we need to check
6235 -- based on the designated type.
6238 Prefix_Type := Designated_Type (Prefix_Type);
6244 Original_Record_Component (Entity (Selector_Name (Object)));
6246 -- As per AI-0017, the renaming is illegal in a generic body, even
6247 -- if the subtype is indefinite.
6249 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6251 if not Is_Constrained (Prefix_Type)
6252 and then (not Is_Indefinite_Subtype (Prefix_Type)
6254 (Is_Generic_Type (Prefix_Type)
6255 and then Ekind (Current_Scope) = E_Generic_Package
6256 and then In_Package_Body (Current_Scope)))
6258 and then (Is_Declared_Within_Variant (Comp)
6259 or else Has_Discriminant_Dependent_Constraint (Comp))
6260 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6266 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6270 elsif Nkind (Object) = N_Indexed_Component
6271 or else Nkind (Object) = N_Slice
6273 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6275 -- A type conversion that Is_Variable is a view conversion:
6276 -- go back to the denoted object.
6278 elsif Nkind (Object) = N_Type_Conversion then
6280 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6285 end Is_Dependent_Component_Of_Mutable_Object;
6287 ---------------------
6288 -- Is_Dereferenced --
6289 ---------------------
6291 function Is_Dereferenced (N : Node_Id) return Boolean is
6292 P : constant Node_Id := Parent (N);
6295 (Nkind (P) = N_Selected_Component
6297 Nkind (P) = N_Explicit_Dereference
6299 Nkind (P) = N_Indexed_Component
6301 Nkind (P) = N_Slice)
6302 and then Prefix (P) = N;
6303 end Is_Dereferenced;
6305 ----------------------
6306 -- Is_Descendent_Of --
6307 ----------------------
6309 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6314 pragma Assert (Nkind (T1) in N_Entity);
6315 pragma Assert (Nkind (T2) in N_Entity);
6317 T := Base_Type (T1);
6319 -- Immediate return if the types match
6324 -- Comment needed here ???
6326 elsif Ekind (T) = E_Class_Wide_Type then
6327 return Etype (T) = T2;
6335 -- Done if we found the type we are looking for
6340 -- Done if no more derivations to check
6347 -- Following test catches error cases resulting from prev errors
6349 elsif No (Etyp) then
6352 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6355 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6359 T := Base_Type (Etyp);
6362 end Is_Descendent_Of;
6368 function Is_False (U : Uint) return Boolean is
6373 ---------------------------
6374 -- Is_Fixed_Model_Number --
6375 ---------------------------
6377 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6378 S : constant Ureal := Small_Value (T);
6379 M : Urealp.Save_Mark;
6383 R := (U = UR_Trunc (U / S) * S);
6386 end Is_Fixed_Model_Number;
6388 -------------------------------
6389 -- Is_Fully_Initialized_Type --
6390 -------------------------------
6392 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6394 if Is_Scalar_Type (Typ) then
6397 elsif Is_Access_Type (Typ) then
6400 elsif Is_Array_Type (Typ) then
6401 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6405 -- An interesting case, if we have a constrained type one of whose
6406 -- bounds is known to be null, then there are no elements to be
6407 -- initialized, so all the elements are initialized!
6409 if Is_Constrained (Typ) then
6412 Indx_Typ : Entity_Id;
6416 Indx := First_Index (Typ);
6417 while Present (Indx) loop
6418 if Etype (Indx) = Any_Type then
6421 -- If index is a range, use directly
6423 elsif Nkind (Indx) = N_Range then
6424 Lbd := Low_Bound (Indx);
6425 Hbd := High_Bound (Indx);
6428 Indx_Typ := Etype (Indx);
6430 if Is_Private_Type (Indx_Typ) then
6431 Indx_Typ := Full_View (Indx_Typ);
6434 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6437 Lbd := Type_Low_Bound (Indx_Typ);
6438 Hbd := Type_High_Bound (Indx_Typ);
6442 if Compile_Time_Known_Value (Lbd)
6443 and then Compile_Time_Known_Value (Hbd)
6445 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6455 -- If no null indexes, then type is not fully initialized
6461 elsif Is_Record_Type (Typ) then
6462 if Has_Discriminants (Typ)
6464 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6465 and then Is_Fully_Initialized_Variant (Typ)
6470 -- Controlled records are considered to be fully initialized if
6471 -- there is a user defined Initialize routine. This may not be
6472 -- entirely correct, but as the spec notes, we are guessing here
6473 -- what is best from the point of view of issuing warnings.
6475 if Is_Controlled (Typ) then
6477 Utyp : constant Entity_Id := Underlying_Type (Typ);
6480 if Present (Utyp) then
6482 Init : constant Entity_Id :=
6484 (Underlying_Type (Typ), Name_Initialize));
6488 and then Comes_From_Source (Init)
6490 Is_Predefined_File_Name
6491 (File_Name (Get_Source_File_Index (Sloc (Init))))
6495 elsif Has_Null_Extension (Typ)
6497 Is_Fully_Initialized_Type
6498 (Etype (Base_Type (Typ)))
6507 -- Otherwise see if all record components are initialized
6513 Ent := First_Entity (Typ);
6514 while Present (Ent) loop
6515 if Chars (Ent) = Name_uController then
6518 elsif Ekind (Ent) = E_Component
6519 and then (No (Parent (Ent))
6520 or else No (Expression (Parent (Ent))))
6521 and then not Is_Fully_Initialized_Type (Etype (Ent))
6523 -- Special VM case for tag components, which need to be
6524 -- defined in this case, but are never initialized as VMs
6525 -- are using other dispatching mechanisms. Ignore this
6526 -- uninitialized case. Note that this applies both to the
6527 -- uTag entry and the main vtable pointer (CPP_Class case).
6529 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6538 -- No uninitialized components, so type is fully initialized.
6539 -- Note that this catches the case of no components as well.
6543 elsif Is_Concurrent_Type (Typ) then
6546 elsif Is_Private_Type (Typ) then
6548 U : constant Entity_Id := Underlying_Type (Typ);
6554 return Is_Fully_Initialized_Type (U);
6561 end Is_Fully_Initialized_Type;
6563 ----------------------------------
6564 -- Is_Fully_Initialized_Variant --
6565 ----------------------------------
6567 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6568 Loc : constant Source_Ptr := Sloc (Typ);
6569 Constraints : constant List_Id := New_List;
6570 Components : constant Elist_Id := New_Elmt_List;
6571 Comp_Elmt : Elmt_Id;
6573 Comp_List : Node_Id;
6575 Discr_Val : Node_Id;
6577 Report_Errors : Boolean;
6578 pragma Warnings (Off, Report_Errors);
6581 if Serious_Errors_Detected > 0 then
6585 if Is_Record_Type (Typ)
6586 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6587 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6589 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6591 Discr := First_Discriminant (Typ);
6592 while Present (Discr) loop
6593 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6594 Discr_Val := Expression (Parent (Discr));
6596 if Present (Discr_Val)
6597 and then Is_OK_Static_Expression (Discr_Val)
6599 Append_To (Constraints,
6600 Make_Component_Association (Loc,
6601 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6602 Expression => New_Copy (Discr_Val)));
6610 Next_Discriminant (Discr);
6615 Comp_List => Comp_List,
6616 Governed_By => Constraints,
6618 Report_Errors => Report_Errors);
6620 -- Check that each component present is fully initialized
6622 Comp_Elmt := First_Elmt (Components);
6623 while Present (Comp_Elmt) loop
6624 Comp_Id := Node (Comp_Elmt);
6626 if Ekind (Comp_Id) = E_Component
6627 and then (No (Parent (Comp_Id))
6628 or else No (Expression (Parent (Comp_Id))))
6629 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6634 Next_Elmt (Comp_Elmt);
6639 elsif Is_Private_Type (Typ) then
6641 U : constant Entity_Id := Underlying_Type (Typ);
6647 return Is_Fully_Initialized_Variant (U);
6653 end Is_Fully_Initialized_Variant;
6659 -- We seem to have a lot of overlapping functions that do similar things
6660 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6661 -- purely syntactic, it should be in Sem_Aux I would think???
6663 function Is_LHS (N : Node_Id) return Boolean is
6664 P : constant Node_Id := Parent (N);
6666 if Nkind (P) = N_Assignment_Statement then
6667 return Name (P) = N;
6670 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6672 return N = Prefix (P) and then Is_LHS (P);
6679 ----------------------------
6680 -- Is_Inherited_Operation --
6681 ----------------------------
6683 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6684 Kind : constant Node_Kind := Nkind (Parent (E));
6686 pragma Assert (Is_Overloadable (E));
6687 return Kind = N_Full_Type_Declaration
6688 or else Kind = N_Private_Extension_Declaration
6689 or else Kind = N_Subtype_Declaration
6690 or else (Ekind (E) = E_Enumeration_Literal
6691 and then Is_Derived_Type (Etype (E)));
6692 end Is_Inherited_Operation;
6694 -----------------------------
6695 -- Is_Library_Level_Entity --
6696 -----------------------------
6698 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6700 -- The following is a small optimization, and it also properly handles
6701 -- discriminals, which in task bodies might appear in expressions before
6702 -- the corresponding procedure has been created, and which therefore do
6703 -- not have an assigned scope.
6705 if Is_Formal (E) then
6709 -- Normal test is simply that the enclosing dynamic scope is Standard
6711 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6712 end Is_Library_Level_Entity;
6714 ---------------------------------
6715 -- Is_Local_Variable_Reference --
6716 ---------------------------------
6718 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6720 if not Is_Entity_Name (Expr) then
6725 Ent : constant Entity_Id := Entity (Expr);
6726 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6728 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6731 return Present (Sub) and then Sub = Current_Subprogram;
6735 end Is_Local_Variable_Reference;
6737 -------------------------
6738 -- Is_Object_Reference --
6739 -------------------------
6741 function Is_Object_Reference (N : Node_Id) return Boolean is
6743 if Is_Entity_Name (N) then
6744 return Present (Entity (N)) and then Is_Object (Entity (N));
6748 when N_Indexed_Component | N_Slice =>
6750 Is_Object_Reference (Prefix (N))
6751 or else Is_Access_Type (Etype (Prefix (N)));
6753 -- In Ada95, a function call is a constant object; a procedure
6756 when N_Function_Call =>
6757 return Etype (N) /= Standard_Void_Type;
6759 -- A reference to the stream attribute Input is a function call
6761 when N_Attribute_Reference =>
6762 return Attribute_Name (N) = Name_Input;
6764 when N_Selected_Component =>
6766 Is_Object_Reference (Selector_Name (N))
6768 (Is_Object_Reference (Prefix (N))
6769 or else Is_Access_Type (Etype (Prefix (N))));
6771 when N_Explicit_Dereference =>
6774 -- A view conversion of a tagged object is an object reference
6776 when N_Type_Conversion =>
6777 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6778 and then Is_Tagged_Type (Etype (Expression (N)))
6779 and then Is_Object_Reference (Expression (N));
6781 -- An unchecked type conversion is considered to be an object if
6782 -- the operand is an object (this construction arises only as a
6783 -- result of expansion activities).
6785 when N_Unchecked_Type_Conversion =>
6792 end Is_Object_Reference;
6794 -----------------------------------
6795 -- Is_OK_Variable_For_Out_Formal --
6796 -----------------------------------
6798 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6800 Note_Possible_Modification (AV, Sure => True);
6802 -- We must reject parenthesized variable names. The check for
6803 -- Comes_From_Source is present because there are currently
6804 -- cases where the compiler violates this rule (e.g. passing
6805 -- a task object to its controlled Initialize routine).
6807 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6810 -- A variable is always allowed
6812 elsif Is_Variable (AV) then
6815 -- Unchecked conversions are allowed only if they come from the
6816 -- generated code, which sometimes uses unchecked conversions for out
6817 -- parameters in cases where code generation is unaffected. We tell
6818 -- source unchecked conversions by seeing if they are rewrites of an
6819 -- original Unchecked_Conversion function call, or of an explicit
6820 -- conversion of a function call.
6822 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6823 if Nkind (Original_Node (AV)) = N_Function_Call then
6826 elsif Comes_From_Source (AV)
6827 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6831 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6832 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6838 -- Normal type conversions are allowed if argument is a variable
6840 elsif Nkind (AV) = N_Type_Conversion then
6841 if Is_Variable (Expression (AV))
6842 and then Paren_Count (Expression (AV)) = 0
6844 Note_Possible_Modification (Expression (AV), Sure => True);
6847 -- We also allow a non-parenthesized expression that raises
6848 -- constraint error if it rewrites what used to be a variable
6850 elsif Raises_Constraint_Error (Expression (AV))
6851 and then Paren_Count (Expression (AV)) = 0
6852 and then Is_Variable (Original_Node (Expression (AV)))
6856 -- Type conversion of something other than a variable
6862 -- If this node is rewritten, then test the original form, if that is
6863 -- OK, then we consider the rewritten node OK (for example, if the
6864 -- original node is a conversion, then Is_Variable will not be true
6865 -- but we still want to allow the conversion if it converts a variable).
6867 elsif Original_Node (AV) /= AV then
6868 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6870 -- All other non-variables are rejected
6875 end Is_OK_Variable_For_Out_Formal;
6877 -----------------------------------
6878 -- Is_Partially_Initialized_Type --
6879 -----------------------------------
6881 function Is_Partially_Initialized_Type
6883 Include_Implicit : Boolean := True) return Boolean
6886 if Is_Scalar_Type (Typ) then
6889 elsif Is_Access_Type (Typ) then
6890 return Include_Implicit;
6892 elsif Is_Array_Type (Typ) then
6894 -- If component type is partially initialized, so is array type
6896 if Is_Partially_Initialized_Type
6897 (Component_Type (Typ), Include_Implicit)
6901 -- Otherwise we are only partially initialized if we are fully
6902 -- initialized (this is the empty array case, no point in us
6903 -- duplicating that code here).
6906 return Is_Fully_Initialized_Type (Typ);
6909 elsif Is_Record_Type (Typ) then
6911 -- A discriminated type is always partially initialized if in
6914 if Has_Discriminants (Typ) and then Include_Implicit then
6917 -- A tagged type is always partially initialized
6919 elsif Is_Tagged_Type (Typ) then
6922 -- Case of non-discriminated record
6928 Component_Present : Boolean := False;
6929 -- Set True if at least one component is present. If no
6930 -- components are present, then record type is fully
6931 -- initialized (another odd case, like the null array).
6934 -- Loop through components
6936 Ent := First_Entity (Typ);
6937 while Present (Ent) loop
6938 if Ekind (Ent) = E_Component then
6939 Component_Present := True;
6941 -- If a component has an initialization expression then
6942 -- the enclosing record type is partially initialized
6944 if Present (Parent (Ent))
6945 and then Present (Expression (Parent (Ent)))
6949 -- If a component is of a type which is itself partially
6950 -- initialized, then the enclosing record type is also.
6952 elsif Is_Partially_Initialized_Type
6953 (Etype (Ent), Include_Implicit)
6962 -- No initialized components found. If we found any components
6963 -- they were all uninitialized so the result is false.
6965 if Component_Present then
6968 -- But if we found no components, then all the components are
6969 -- initialized so we consider the type to be initialized.
6977 -- Concurrent types are always fully initialized
6979 elsif Is_Concurrent_Type (Typ) then
6982 -- For a private type, go to underlying type. If there is no underlying
6983 -- type then just assume this partially initialized. Not clear if this
6984 -- can happen in a non-error case, but no harm in testing for this.
6986 elsif Is_Private_Type (Typ) then
6988 U : constant Entity_Id := Underlying_Type (Typ);
6993 return Is_Partially_Initialized_Type (U, Include_Implicit);
6997 -- For any other type (are there any?) assume partially initialized
7002 end Is_Partially_Initialized_Type;
7004 ------------------------------------
7005 -- Is_Potentially_Persistent_Type --
7006 ------------------------------------
7008 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7013 -- For private type, test corresponding full type
7015 if Is_Private_Type (T) then
7016 return Is_Potentially_Persistent_Type (Full_View (T));
7018 -- Scalar types are potentially persistent
7020 elsif Is_Scalar_Type (T) then
7023 -- Record type is potentially persistent if not tagged and the types of
7024 -- all it components are potentially persistent, and no component has
7025 -- an initialization expression.
7027 elsif Is_Record_Type (T)
7028 and then not Is_Tagged_Type (T)
7029 and then not Is_Partially_Initialized_Type (T)
7031 Comp := First_Component (T);
7032 while Present (Comp) loop
7033 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7042 -- Array type is potentially persistent if its component type is
7043 -- potentially persistent and if all its constraints are static.
7045 elsif Is_Array_Type (T) then
7046 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7050 Indx := First_Index (T);
7051 while Present (Indx) loop
7052 if not Is_OK_Static_Subtype (Etype (Indx)) then
7061 -- All other types are not potentially persistent
7066 end Is_Potentially_Persistent_Type;
7068 ---------------------------------
7069 -- Is_Protected_Self_Reference --
7070 ---------------------------------
7072 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7074 function In_Access_Definition (N : Node_Id) return Boolean;
7075 -- Returns true if N belongs to an access definition
7077 --------------------------
7078 -- In_Access_Definition --
7079 --------------------------
7081 function In_Access_Definition (N : Node_Id) return Boolean is
7086 while Present (P) loop
7087 if Nkind (P) = N_Access_Definition then
7095 end In_Access_Definition;
7097 -- Start of processing for Is_Protected_Self_Reference
7100 -- Verify that prefix is analyzed and has the proper form. Note that
7101 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7102 -- produce the address of an entity, do not analyze their prefix
7103 -- because they denote entities that are not necessarily visible.
7104 -- Neither of them can apply to a protected type.
7106 return Ada_Version >= Ada_2005
7107 and then Is_Entity_Name (N)
7108 and then Present (Entity (N))
7109 and then Is_Protected_Type (Entity (N))
7110 and then In_Open_Scopes (Entity (N))
7111 and then not In_Access_Definition (N);
7112 end Is_Protected_Self_Reference;
7114 -----------------------------
7115 -- Is_RCI_Pkg_Spec_Or_Body --
7116 -----------------------------
7118 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7120 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7121 -- Return True if the unit of Cunit is an RCI package declaration
7123 ---------------------------
7124 -- Is_RCI_Pkg_Decl_Cunit --
7125 ---------------------------
7127 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7128 The_Unit : constant Node_Id := Unit (Cunit);
7131 if Nkind (The_Unit) /= N_Package_Declaration then
7135 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7136 end Is_RCI_Pkg_Decl_Cunit;
7138 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7141 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7143 (Nkind (Unit (Cunit)) = N_Package_Body
7144 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7145 end Is_RCI_Pkg_Spec_Or_Body;
7147 -----------------------------------------
7148 -- Is_Remote_Access_To_Class_Wide_Type --
7149 -----------------------------------------
7151 function Is_Remote_Access_To_Class_Wide_Type
7152 (E : Entity_Id) return Boolean
7155 -- A remote access to class-wide type is a general access to object type
7156 -- declared in the visible part of a Remote_Types or Remote_Call_
7159 return Ekind (E) = E_General_Access_Type
7160 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7161 end Is_Remote_Access_To_Class_Wide_Type;
7163 -----------------------------------------
7164 -- Is_Remote_Access_To_Subprogram_Type --
7165 -----------------------------------------
7167 function Is_Remote_Access_To_Subprogram_Type
7168 (E : Entity_Id) return Boolean
7171 return (Ekind (E) = E_Access_Subprogram_Type
7172 or else (Ekind (E) = E_Record_Type
7173 and then Present (Corresponding_Remote_Type (E))))
7174 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7175 end Is_Remote_Access_To_Subprogram_Type;
7177 --------------------
7178 -- Is_Remote_Call --
7179 --------------------
7181 function Is_Remote_Call (N : Node_Id) return Boolean is
7183 if Nkind (N) /= N_Procedure_Call_Statement
7184 and then Nkind (N) /= N_Function_Call
7186 -- An entry call cannot be remote
7190 elsif Nkind (Name (N)) in N_Has_Entity
7191 and then Is_Remote_Call_Interface (Entity (Name (N)))
7193 -- A subprogram declared in the spec of a RCI package is remote
7197 elsif Nkind (Name (N)) = N_Explicit_Dereference
7198 and then Is_Remote_Access_To_Subprogram_Type
7199 (Etype (Prefix (Name (N))))
7201 -- The dereference of a RAS is a remote call
7205 elsif Present (Controlling_Argument (N))
7206 and then Is_Remote_Access_To_Class_Wide_Type
7207 (Etype (Controlling_Argument (N)))
7209 -- Any primitive operation call with a controlling argument of
7210 -- a RACW type is a remote call.
7215 -- All other calls are local calls
7220 ----------------------
7221 -- Is_Renamed_Entry --
7222 ----------------------
7224 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7225 Orig_Node : Node_Id := Empty;
7226 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7228 function Is_Entry (Nam : Node_Id) return Boolean;
7229 -- Determine whether Nam is an entry. Traverse selectors if there are
7230 -- nested selected components.
7236 function Is_Entry (Nam : Node_Id) return Boolean is
7238 if Nkind (Nam) = N_Selected_Component then
7239 return Is_Entry (Selector_Name (Nam));
7242 return Ekind (Entity (Nam)) = E_Entry;
7245 -- Start of processing for Is_Renamed_Entry
7248 if Present (Alias (Proc_Nam)) then
7249 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7252 -- Look for a rewritten subprogram renaming declaration
7254 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7255 and then Present (Original_Node (Subp_Decl))
7257 Orig_Node := Original_Node (Subp_Decl);
7260 -- The rewritten subprogram is actually an entry
7262 if Present (Orig_Node)
7263 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7264 and then Is_Entry (Name (Orig_Node))
7270 end Is_Renamed_Entry;
7272 ----------------------
7273 -- Is_Selector_Name --
7274 ----------------------
7276 function Is_Selector_Name (N : Node_Id) return Boolean is
7278 if not Is_List_Member (N) then
7280 P : constant Node_Id := Parent (N);
7281 K : constant Node_Kind := Nkind (P);
7284 (K = N_Expanded_Name or else
7285 K = N_Generic_Association or else
7286 K = N_Parameter_Association or else
7287 K = N_Selected_Component)
7288 and then Selector_Name (P) = N;
7293 L : constant List_Id := List_Containing (N);
7294 P : constant Node_Id := Parent (L);
7296 return (Nkind (P) = N_Discriminant_Association
7297 and then Selector_Names (P) = L)
7299 (Nkind (P) = N_Component_Association
7300 and then Choices (P) = L);
7303 end Is_Selector_Name;
7309 function Is_Statement (N : Node_Id) return Boolean is
7312 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7313 or else Nkind (N) = N_Procedure_Call_Statement;
7316 ---------------------------------
7317 -- Is_Synchronized_Tagged_Type --
7318 ---------------------------------
7320 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7321 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7324 -- A task or protected type derived from an interface is a tagged type.
7325 -- Such a tagged type is called a synchronized tagged type, as are
7326 -- synchronized interfaces and private extensions whose declaration
7327 -- includes the reserved word synchronized.
7329 return (Is_Tagged_Type (E)
7330 and then (Kind = E_Task_Type
7331 or else Kind = E_Protected_Type))
7334 and then Is_Synchronized_Interface (E))
7336 (Ekind (E) = E_Record_Type_With_Private
7337 and then (Synchronized_Present (Parent (E))
7338 or else Is_Synchronized_Interface (Etype (E))));
7339 end Is_Synchronized_Tagged_Type;
7345 function Is_Transfer (N : Node_Id) return Boolean is
7346 Kind : constant Node_Kind := Nkind (N);
7349 if Kind = N_Simple_Return_Statement
7351 Kind = N_Extended_Return_Statement
7353 Kind = N_Goto_Statement
7355 Kind = N_Raise_Statement
7357 Kind = N_Requeue_Statement
7361 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7362 and then No (Condition (N))
7366 elsif Kind = N_Procedure_Call_Statement
7367 and then Is_Entity_Name (Name (N))
7368 and then Present (Entity (Name (N)))
7369 and then No_Return (Entity (Name (N)))
7373 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7385 function Is_True (U : Uint) return Boolean is
7390 -------------------------------
7391 -- Is_Universal_Numeric_Type --
7392 -------------------------------
7394 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7396 return T = Universal_Integer or else T = Universal_Real;
7397 end Is_Universal_Numeric_Type;
7403 function Is_Value_Type (T : Entity_Id) return Boolean is
7405 return VM_Target = CLI_Target
7406 and then Nkind (T) in N_Has_Chars
7407 and then Chars (T) /= No_Name
7408 and then Get_Name_String (Chars (T)) = "valuetype";
7411 ---------------------
7412 -- Is_VMS_Operator --
7413 ---------------------
7415 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7417 -- The VMS operators are declared in a child of System that is loaded
7418 -- through pragma Extend_System. In some rare cases a program is run
7419 -- with this extension but without indicating that the target is VMS.
7421 return Ekind (Op) = E_Function
7422 and then Is_Intrinsic_Subprogram (Op)
7424 ((Present_System_Aux
7425 and then Scope (Op) = System_Aux_Id)
7428 and then Scope (Scope (Op)) = RTU_Entity (System)));
7429 end Is_VMS_Operator;
7435 function Is_Variable (N : Node_Id) return Boolean is
7437 Orig_Node : constant Node_Id := Original_Node (N);
7438 -- We do the test on the original node, since this is basically a test
7439 -- of syntactic categories, so it must not be disturbed by whatever
7440 -- rewriting might have occurred. For example, an aggregate, which is
7441 -- certainly NOT a variable, could be turned into a variable by
7444 function In_Protected_Function (E : Entity_Id) return Boolean;
7445 -- Within a protected function, the private components of the enclosing
7446 -- protected type are constants. A function nested within a (protected)
7447 -- procedure is not itself protected.
7449 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7450 -- Prefixes can involve implicit dereferences, in which case we must
7451 -- test for the case of a reference of a constant access type, which can
7452 -- can never be a variable.
7454 ---------------------------
7455 -- In_Protected_Function --
7456 ---------------------------
7458 function In_Protected_Function (E : Entity_Id) return Boolean is
7459 Prot : constant Entity_Id := Scope (E);
7463 if not Is_Protected_Type (Prot) then
7467 while Present (S) and then S /= Prot loop
7468 if Ekind (S) = E_Function and then Scope (S) = Prot then
7477 end In_Protected_Function;
7479 ------------------------
7480 -- Is_Variable_Prefix --
7481 ------------------------
7483 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7485 if Is_Access_Type (Etype (P)) then
7486 return not Is_Access_Constant (Root_Type (Etype (P)));
7488 -- For the case of an indexed component whose prefix has a packed
7489 -- array type, the prefix has been rewritten into a type conversion.
7490 -- Determine variable-ness from the converted expression.
7492 elsif Nkind (P) = N_Type_Conversion
7493 and then not Comes_From_Source (P)
7494 and then Is_Array_Type (Etype (P))
7495 and then Is_Packed (Etype (P))
7497 return Is_Variable (Expression (P));
7500 return Is_Variable (P);
7502 end Is_Variable_Prefix;
7504 -- Start of processing for Is_Variable
7507 -- Definitely OK if Assignment_OK is set. Since this is something that
7508 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7510 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7513 -- Normally we go to the original node, but there is one exception where
7514 -- we use the rewritten node, namely when it is an explicit dereference.
7515 -- The generated code may rewrite a prefix which is an access type with
7516 -- an explicit dereference. The dereference is a variable, even though
7517 -- the original node may not be (since it could be a constant of the
7520 -- In Ada 2005 we have a further case to consider: the prefix may be a
7521 -- function call given in prefix notation. The original node appears to
7522 -- be a selected component, but we need to examine the call.
7524 elsif Nkind (N) = N_Explicit_Dereference
7525 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7526 and then Present (Etype (Orig_Node))
7527 and then Is_Access_Type (Etype (Orig_Node))
7529 -- Note that if the prefix is an explicit dereference that does not
7530 -- come from source, we must check for a rewritten function call in
7531 -- prefixed notation before other forms of rewriting, to prevent a
7535 (Nkind (Orig_Node) = N_Function_Call
7536 and then not Is_Access_Constant (Etype (Prefix (N))))
7538 Is_Variable_Prefix (Original_Node (Prefix (N)));
7540 -- A function call is never a variable
7542 elsif Nkind (N) = N_Function_Call then
7545 -- All remaining checks use the original node
7547 elsif Is_Entity_Name (Orig_Node)
7548 and then Present (Entity (Orig_Node))
7551 E : constant Entity_Id := Entity (Orig_Node);
7552 K : constant Entity_Kind := Ekind (E);
7555 return (K = E_Variable
7556 and then Nkind (Parent (E)) /= N_Exception_Handler)
7557 or else (K = E_Component
7558 and then not In_Protected_Function (E))
7559 or else K = E_Out_Parameter
7560 or else K = E_In_Out_Parameter
7561 or else K = E_Generic_In_Out_Parameter
7563 -- Current instance of type:
7565 or else (Is_Type (E) and then In_Open_Scopes (E))
7566 or else (Is_Incomplete_Or_Private_Type (E)
7567 and then In_Open_Scopes (Full_View (E)));
7571 case Nkind (Orig_Node) is
7572 when N_Indexed_Component | N_Slice =>
7573 return Is_Variable_Prefix (Prefix (Orig_Node));
7575 when N_Selected_Component =>
7576 return Is_Variable_Prefix (Prefix (Orig_Node))
7577 and then Is_Variable (Selector_Name (Orig_Node));
7579 -- For an explicit dereference, the type of the prefix cannot
7580 -- be an access to constant or an access to subprogram.
7582 when N_Explicit_Dereference =>
7584 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7586 return Is_Access_Type (Typ)
7587 and then not Is_Access_Constant (Root_Type (Typ))
7588 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7591 -- The type conversion is the case where we do not deal with the
7592 -- context dependent special case of an actual parameter. Thus
7593 -- the type conversion is only considered a variable for the
7594 -- purposes of this routine if the target type is tagged. However,
7595 -- a type conversion is considered to be a variable if it does not
7596 -- come from source (this deals for example with the conversions
7597 -- of expressions to their actual subtypes).
7599 when N_Type_Conversion =>
7600 return Is_Variable (Expression (Orig_Node))
7602 (not Comes_From_Source (Orig_Node)
7604 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7606 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7608 -- GNAT allows an unchecked type conversion as a variable. This
7609 -- only affects the generation of internal expanded code, since
7610 -- calls to instantiations of Unchecked_Conversion are never
7611 -- considered variables (since they are function calls).
7612 -- This is also true for expression actions.
7614 when N_Unchecked_Type_Conversion =>
7615 return Is_Variable (Expression (Orig_Node));
7623 ---------------------------
7624 -- Is_Visibly_Controlled --
7625 ---------------------------
7627 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7628 Root : constant Entity_Id := Root_Type (T);
7630 return Chars (Scope (Root)) = Name_Finalization
7631 and then Chars (Scope (Scope (Root))) = Name_Ada
7632 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7633 end Is_Visibly_Controlled;
7635 ------------------------
7636 -- Is_Volatile_Object --
7637 ------------------------
7639 function Is_Volatile_Object (N : Node_Id) return Boolean is
7641 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7642 -- Determines if given object has volatile components
7644 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7645 -- If prefix is an implicit dereference, examine designated type
7647 ------------------------
7648 -- Is_Volatile_Prefix --
7649 ------------------------
7651 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7652 Typ : constant Entity_Id := Etype (N);
7655 if Is_Access_Type (Typ) then
7657 Dtyp : constant Entity_Id := Designated_Type (Typ);
7660 return Is_Volatile (Dtyp)
7661 or else Has_Volatile_Components (Dtyp);
7665 return Object_Has_Volatile_Components (N);
7667 end Is_Volatile_Prefix;
7669 ------------------------------------
7670 -- Object_Has_Volatile_Components --
7671 ------------------------------------
7673 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7674 Typ : constant Entity_Id := Etype (N);
7677 if Is_Volatile (Typ)
7678 or else Has_Volatile_Components (Typ)
7682 elsif Is_Entity_Name (N)
7683 and then (Has_Volatile_Components (Entity (N))
7684 or else Is_Volatile (Entity (N)))
7688 elsif Nkind (N) = N_Indexed_Component
7689 or else Nkind (N) = N_Selected_Component
7691 return Is_Volatile_Prefix (Prefix (N));
7696 end Object_Has_Volatile_Components;
7698 -- Start of processing for Is_Volatile_Object
7701 if Is_Volatile (Etype (N))
7702 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7706 elsif Nkind (N) = N_Indexed_Component
7707 or else Nkind (N) = N_Selected_Component
7709 return Is_Volatile_Prefix (Prefix (N));
7714 end Is_Volatile_Object;
7716 -------------------------
7717 -- Kill_Current_Values --
7718 -------------------------
7720 procedure Kill_Current_Values
7722 Last_Assignment_Only : Boolean := False)
7725 -- ??? do we have to worry about clearing cached checks?
7727 if Is_Assignable (Ent) then
7728 Set_Last_Assignment (Ent, Empty);
7731 if Is_Object (Ent) then
7732 if not Last_Assignment_Only then
7734 Set_Current_Value (Ent, Empty);
7736 if not Can_Never_Be_Null (Ent) then
7737 Set_Is_Known_Non_Null (Ent, False);
7740 Set_Is_Known_Null (Ent, False);
7742 -- Reset Is_Known_Valid unless type is always valid, or if we have
7743 -- a loop parameter (loop parameters are always valid, since their
7744 -- bounds are defined by the bounds given in the loop header).
7746 if not Is_Known_Valid (Etype (Ent))
7747 and then Ekind (Ent) /= E_Loop_Parameter
7749 Set_Is_Known_Valid (Ent, False);
7753 end Kill_Current_Values;
7755 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7758 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7759 -- Clear current value for entity E and all entities chained to E
7761 ------------------------------------------
7762 -- Kill_Current_Values_For_Entity_Chain --
7763 ------------------------------------------
7765 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7769 while Present (Ent) loop
7770 Kill_Current_Values (Ent, Last_Assignment_Only);
7773 end Kill_Current_Values_For_Entity_Chain;
7775 -- Start of processing for Kill_Current_Values
7778 -- Kill all saved checks, a special case of killing saved values
7780 if not Last_Assignment_Only then
7784 -- Loop through relevant scopes, which includes the current scope and
7785 -- any parent scopes if the current scope is a block or a package.
7790 -- Clear current values of all entities in current scope
7792 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7794 -- If scope is a package, also clear current values of all
7795 -- private entities in the scope.
7797 if Is_Package_Or_Generic_Package (S)
7798 or else Is_Concurrent_Type (S)
7800 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7803 -- If this is a not a subprogram, deal with parents
7805 if not Is_Subprogram (S) then
7807 exit Scope_Loop when S = Standard_Standard;
7811 end loop Scope_Loop;
7812 end Kill_Current_Values;
7814 --------------------------
7815 -- Kill_Size_Check_Code --
7816 --------------------------
7818 procedure Kill_Size_Check_Code (E : Entity_Id) is
7820 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7821 and then Present (Size_Check_Code (E))
7823 Remove (Size_Check_Code (E));
7824 Set_Size_Check_Code (E, Empty);
7826 end Kill_Size_Check_Code;
7828 --------------------------
7829 -- Known_To_Be_Assigned --
7830 --------------------------
7832 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7833 P : constant Node_Id := Parent (N);
7838 -- Test left side of assignment
7840 when N_Assignment_Statement =>
7841 return N = Name (P);
7843 -- Function call arguments are never lvalues
7845 when N_Function_Call =>
7848 -- Positional parameter for procedure or accept call
7850 when N_Procedure_Call_Statement |
7859 Proc := Get_Subprogram_Entity (P);
7865 -- If we are not a list member, something is strange, so
7866 -- be conservative and return False.
7868 if not Is_List_Member (N) then
7872 -- We are going to find the right formal by stepping forward
7873 -- through the formals, as we step backwards in the actuals.
7875 Form := First_Formal (Proc);
7878 -- If no formal, something is weird, so be conservative
7879 -- and return False.
7890 return Ekind (Form) /= E_In_Parameter;
7893 -- Named parameter for procedure or accept call
7895 when N_Parameter_Association =>
7901 Proc := Get_Subprogram_Entity (Parent (P));
7907 -- Loop through formals to find the one that matches
7909 Form := First_Formal (Proc);
7911 -- If no matching formal, that's peculiar, some kind of
7912 -- previous error, so return False to be conservative.
7918 -- Else test for match
7920 if Chars (Form) = Chars (Selector_Name (P)) then
7921 return Ekind (Form) /= E_In_Parameter;
7928 -- Test for appearing in a conversion that itself appears
7929 -- in an lvalue context, since this should be an lvalue.
7931 when N_Type_Conversion =>
7932 return Known_To_Be_Assigned (P);
7934 -- All other references are definitely not known to be modifications
7940 end Known_To_Be_Assigned;
7946 function May_Be_Lvalue (N : Node_Id) return Boolean is
7947 P : constant Node_Id := Parent (N);
7952 -- Test left side of assignment
7954 when N_Assignment_Statement =>
7955 return N = Name (P);
7957 -- Test prefix of component or attribute. Note that the prefix of an
7958 -- explicit or implicit dereference cannot be an l-value.
7960 when N_Attribute_Reference =>
7961 return N = Prefix (P)
7962 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7964 -- For an expanded name, the name is an lvalue if the expanded name
7965 -- is an lvalue, but the prefix is never an lvalue, since it is just
7966 -- the scope where the name is found.
7968 when N_Expanded_Name =>
7969 if N = Prefix (P) then
7970 return May_Be_Lvalue (P);
7975 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7976 -- B is a little interesting, if we have A.B := 3, there is some
7977 -- discussion as to whether B is an lvalue or not, we choose to say
7978 -- it is. Note however that A is not an lvalue if it is of an access
7979 -- type since this is an implicit dereference.
7981 when N_Selected_Component =>
7983 and then Present (Etype (N))
7984 and then Is_Access_Type (Etype (N))
7988 return May_Be_Lvalue (P);
7991 -- For an indexed component or slice, the index or slice bounds is
7992 -- never an lvalue. The prefix is an lvalue if the indexed component
7993 -- or slice is an lvalue, except if it is an access type, where we
7994 -- have an implicit dereference.
7996 when N_Indexed_Component =>
7998 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8002 return May_Be_Lvalue (P);
8005 -- Prefix of a reference is an lvalue if the reference is an lvalue
8008 return May_Be_Lvalue (P);
8010 -- Prefix of explicit dereference is never an lvalue
8012 when N_Explicit_Dereference =>
8015 -- Positional parameter for subprogram, entry, or accept call.
8016 -- In older versions of Ada function call arguments are never
8017 -- lvalues. In Ada 2012 functions can have in-out parameters.
8019 when N_Function_Call |
8020 N_Procedure_Call_Statement |
8021 N_Entry_Call_Statement |
8024 if Nkind (P) = N_Function_Call
8025 and then Ada_Version < Ada_2012
8030 -- The following mechanism is clumsy and fragile. A single
8031 -- flag set in Resolve_Actuals would be preferable ???
8039 Proc := Get_Subprogram_Entity (P);
8045 -- If we are not a list member, something is strange, so
8046 -- be conservative and return True.
8048 if not Is_List_Member (N) then
8052 -- We are going to find the right formal by stepping forward
8053 -- through the formals, as we step backwards in the actuals.
8055 Form := First_Formal (Proc);
8058 -- If no formal, something is weird, so be conservative
8070 return Ekind (Form) /= E_In_Parameter;
8073 -- Named parameter for procedure or accept call
8075 when N_Parameter_Association =>
8081 Proc := Get_Subprogram_Entity (Parent (P));
8087 -- Loop through formals to find the one that matches
8089 Form := First_Formal (Proc);
8091 -- If no matching formal, that's peculiar, some kind of
8092 -- previous error, so return True to be conservative.
8098 -- Else test for match
8100 if Chars (Form) = Chars (Selector_Name (P)) then
8101 return Ekind (Form) /= E_In_Parameter;
8108 -- Test for appearing in a conversion that itself appears in an
8109 -- lvalue context, since this should be an lvalue.
8111 when N_Type_Conversion =>
8112 return May_Be_Lvalue (P);
8114 -- Test for appearance in object renaming declaration
8116 when N_Object_Renaming_Declaration =>
8119 -- All other references are definitely not lvalues
8127 -----------------------
8128 -- Mark_Coextensions --
8129 -----------------------
8131 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8132 Is_Dynamic : Boolean;
8133 -- Indicates whether the context causes nested coextensions to be
8134 -- dynamic or static
8136 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8137 -- Recognize an allocator node and label it as a dynamic coextension
8139 --------------------
8140 -- Mark_Allocator --
8141 --------------------
8143 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8145 if Nkind (N) = N_Allocator then
8147 Set_Is_Dynamic_Coextension (N);
8149 -- If the allocator expression is potentially dynamic, it may
8150 -- be expanded out of order and require dynamic allocation
8151 -- anyway, so we treat the coextension itself as dynamic.
8152 -- Potential optimization ???
8154 elsif Nkind (Expression (N)) = N_Qualified_Expression
8155 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8157 Set_Is_Dynamic_Coextension (N);
8160 Set_Is_Static_Coextension (N);
8167 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8169 -- Start of processing Mark_Coextensions
8172 case Nkind (Context_Nod) is
8173 when N_Assignment_Statement |
8174 N_Simple_Return_Statement =>
8175 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8177 when N_Object_Declaration =>
8178 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8180 -- This routine should not be called for constructs which may not
8181 -- contain coextensions.
8184 raise Program_Error;
8187 Mark_Allocators (Root_Nod);
8188 end Mark_Coextensions;
8190 ----------------------
8191 -- Needs_One_Actual --
8192 ----------------------
8194 function Needs_One_Actual (E : Entity_Id) return Boolean is
8198 if Ada_Version >= Ada_2005
8199 and then Present (First_Formal (E))
8201 Formal := Next_Formal (First_Formal (E));
8202 while Present (Formal) loop
8203 if No (Default_Value (Formal)) then
8207 Next_Formal (Formal);
8215 end Needs_One_Actual;
8217 ------------------------
8218 -- New_Copy_List_Tree --
8219 ------------------------
8221 function New_Copy_List_Tree (List : List_Id) return List_Id is
8226 if List = No_List then
8233 while Present (E) loop
8234 Append (New_Copy_Tree (E), NL);
8240 end New_Copy_List_Tree;
8246 use Atree.Unchecked_Access;
8247 use Atree_Private_Part;
8249 -- Our approach here requires a two pass traversal of the tree. The
8250 -- first pass visits all nodes that eventually will be copied looking
8251 -- for defining Itypes. If any defining Itypes are found, then they are
8252 -- copied, and an entry is added to the replacement map. In the second
8253 -- phase, the tree is copied, using the replacement map to replace any
8254 -- Itype references within the copied tree.
8256 -- The following hash tables are used if the Map supplied has more
8257 -- than hash threshold entries to speed up access to the map. If
8258 -- there are fewer entries, then the map is searched sequentially
8259 -- (because setting up a hash table for only a few entries takes
8260 -- more time than it saves.
8262 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8263 -- Hash function used for hash operations
8269 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8271 return Nat (E) mod (NCT_Header_Num'Last + 1);
8278 -- The hash table NCT_Assoc associates old entities in the table
8279 -- with their corresponding new entities (i.e. the pairs of entries
8280 -- presented in the original Map argument are Key-Element pairs).
8282 package NCT_Assoc is new Simple_HTable (
8283 Header_Num => NCT_Header_Num,
8284 Element => Entity_Id,
8285 No_Element => Empty,
8287 Hash => New_Copy_Hash,
8288 Equal => Types."=");
8290 ---------------------
8291 -- NCT_Itype_Assoc --
8292 ---------------------
8294 -- The hash table NCT_Itype_Assoc contains entries only for those
8295 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8296 -- The key is the associated node, and the element is the new node
8297 -- itself (NOT the associated node for the new node).
8299 package NCT_Itype_Assoc is new Simple_HTable (
8300 Header_Num => NCT_Header_Num,
8301 Element => Entity_Id,
8302 No_Element => Empty,
8304 Hash => New_Copy_Hash,
8305 Equal => Types."=");
8307 -- Start of processing for New_Copy_Tree function
8309 function New_Copy_Tree
8311 Map : Elist_Id := No_Elist;
8312 New_Sloc : Source_Ptr := No_Location;
8313 New_Scope : Entity_Id := Empty) return Node_Id
8315 Actual_Map : Elist_Id := Map;
8316 -- This is the actual map for the copy. It is initialized with the
8317 -- given elements, and then enlarged as required for Itypes that are
8318 -- copied during the first phase of the copy operation. The visit
8319 -- procedures add elements to this map as Itypes are encountered.
8320 -- The reason we cannot use Map directly, is that it may well be
8321 -- (and normally is) initialized to No_Elist, and if we have mapped
8322 -- entities, we have to reset it to point to a real Elist.
8324 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8325 -- Called during second phase to map entities into their corresponding
8326 -- copies using Actual_Map. If the argument is not an entity, or is not
8327 -- in Actual_Map, then it is returned unchanged.
8329 procedure Build_NCT_Hash_Tables;
8330 -- Builds hash tables (number of elements >= threshold value)
8332 function Copy_Elist_With_Replacement
8333 (Old_Elist : Elist_Id) return Elist_Id;
8334 -- Called during second phase to copy element list doing replacements
8336 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8337 -- Called during the second phase to process a copied Itype. The actual
8338 -- copy happened during the first phase (so that we could make the entry
8339 -- in the mapping), but we still have to deal with the descendents of
8340 -- the copied Itype and copy them where necessary.
8342 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8343 -- Called during second phase to copy list doing replacements
8345 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8346 -- Called during second phase to copy node doing replacements
8348 procedure Visit_Elist (E : Elist_Id);
8349 -- Called during first phase to visit all elements of an Elist
8351 procedure Visit_Field (F : Union_Id; N : Node_Id);
8352 -- Visit a single field, recursing to call Visit_Node or Visit_List
8353 -- if the field is a syntactic descendent of the current node (i.e.
8354 -- its parent is Node N).
8356 procedure Visit_Itype (Old_Itype : Entity_Id);
8357 -- Called during first phase to visit subsidiary fields of a defining
8358 -- Itype, and also create a copy and make an entry in the replacement
8359 -- map for the new copy.
8361 procedure Visit_List (L : List_Id);
8362 -- Called during first phase to visit all elements of a List
8364 procedure Visit_Node (N : Node_Or_Entity_Id);
8365 -- Called during first phase to visit a node and all its subtrees
8371 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8376 if not Has_Extension (N) or else No (Actual_Map) then
8379 elsif NCT_Hash_Tables_Used then
8380 Ent := NCT_Assoc.Get (Entity_Id (N));
8382 if Present (Ent) then
8388 -- No hash table used, do serial search
8391 E := First_Elmt (Actual_Map);
8392 while Present (E) loop
8393 if Node (E) = N then
8394 return Node (Next_Elmt (E));
8396 E := Next_Elmt (Next_Elmt (E));
8404 ---------------------------
8405 -- Build_NCT_Hash_Tables --
8406 ---------------------------
8408 procedure Build_NCT_Hash_Tables is
8412 if NCT_Hash_Table_Setup then
8414 NCT_Itype_Assoc.Reset;
8417 Elmt := First_Elmt (Actual_Map);
8418 while Present (Elmt) loop
8421 -- Get new entity, and associate old and new
8424 NCT_Assoc.Set (Ent, Node (Elmt));
8426 if Is_Type (Ent) then
8428 Anode : constant Entity_Id :=
8429 Associated_Node_For_Itype (Ent);
8432 if Present (Anode) then
8434 -- Enter a link between the associated node of the
8435 -- old Itype and the new Itype, for updating later
8436 -- when node is copied.
8438 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8446 NCT_Hash_Tables_Used := True;
8447 NCT_Hash_Table_Setup := True;
8448 end Build_NCT_Hash_Tables;
8450 ---------------------------------
8451 -- Copy_Elist_With_Replacement --
8452 ---------------------------------
8454 function Copy_Elist_With_Replacement
8455 (Old_Elist : Elist_Id) return Elist_Id
8458 New_Elist : Elist_Id;
8461 if No (Old_Elist) then
8465 New_Elist := New_Elmt_List;
8467 M := First_Elmt (Old_Elist);
8468 while Present (M) loop
8469 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8475 end Copy_Elist_With_Replacement;
8477 ---------------------------------
8478 -- Copy_Itype_With_Replacement --
8479 ---------------------------------
8481 -- This routine exactly parallels its phase one analog Visit_Itype,
8483 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8485 -- Translate Next_Entity, Scope and Etype fields, in case they
8486 -- reference entities that have been mapped into copies.
8488 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8489 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8491 if Present (New_Scope) then
8492 Set_Scope (New_Itype, New_Scope);
8494 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8497 -- Copy referenced fields
8499 if Is_Discrete_Type (New_Itype) then
8500 Set_Scalar_Range (New_Itype,
8501 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8503 elsif Has_Discriminants (Base_Type (New_Itype)) then
8504 Set_Discriminant_Constraint (New_Itype,
8505 Copy_Elist_With_Replacement
8506 (Discriminant_Constraint (New_Itype)));
8508 elsif Is_Array_Type (New_Itype) then
8509 if Present (First_Index (New_Itype)) then
8510 Set_First_Index (New_Itype,
8511 First (Copy_List_With_Replacement
8512 (List_Containing (First_Index (New_Itype)))));
8515 if Is_Packed (New_Itype) then
8516 Set_Packed_Array_Type (New_Itype,
8517 Copy_Node_With_Replacement
8518 (Packed_Array_Type (New_Itype)));
8521 end Copy_Itype_With_Replacement;
8523 --------------------------------
8524 -- Copy_List_With_Replacement --
8525 --------------------------------
8527 function Copy_List_With_Replacement
8528 (Old_List : List_Id) return List_Id
8534 if Old_List = No_List then
8538 New_List := Empty_List;
8540 E := First (Old_List);
8541 while Present (E) loop
8542 Append (Copy_Node_With_Replacement (E), New_List);
8548 end Copy_List_With_Replacement;
8550 --------------------------------
8551 -- Copy_Node_With_Replacement --
8552 --------------------------------
8554 function Copy_Node_With_Replacement
8555 (Old_Node : Node_Id) return Node_Id
8559 procedure Adjust_Named_Associations
8560 (Old_Node : Node_Id;
8561 New_Node : Node_Id);
8562 -- If a call node has named associations, these are chained through
8563 -- the First_Named_Actual, Next_Named_Actual links. These must be
8564 -- propagated separately to the new parameter list, because these
8565 -- are not syntactic fields.
8567 function Copy_Field_With_Replacement
8568 (Field : Union_Id) return Union_Id;
8569 -- Given Field, which is a field of Old_Node, return a copy of it
8570 -- if it is a syntactic field (i.e. its parent is Node), setting
8571 -- the parent of the copy to poit to New_Node. Otherwise returns
8572 -- the field (possibly mapped if it is an entity).
8574 -------------------------------
8575 -- Adjust_Named_Associations --
8576 -------------------------------
8578 procedure Adjust_Named_Associations
8579 (Old_Node : Node_Id;
8589 Old_E := First (Parameter_Associations (Old_Node));
8590 New_E := First (Parameter_Associations (New_Node));
8591 while Present (Old_E) loop
8592 if Nkind (Old_E) = N_Parameter_Association
8593 and then Present (Next_Named_Actual (Old_E))
8595 if First_Named_Actual (Old_Node)
8596 = Explicit_Actual_Parameter (Old_E)
8598 Set_First_Named_Actual
8599 (New_Node, Explicit_Actual_Parameter (New_E));
8602 -- Now scan parameter list from the beginning,to locate
8603 -- next named actual, which can be out of order.
8605 Old_Next := First (Parameter_Associations (Old_Node));
8606 New_Next := First (Parameter_Associations (New_Node));
8608 while Nkind (Old_Next) /= N_Parameter_Association
8609 or else Explicit_Actual_Parameter (Old_Next)
8610 /= Next_Named_Actual (Old_E)
8616 Set_Next_Named_Actual
8617 (New_E, Explicit_Actual_Parameter (New_Next));
8623 end Adjust_Named_Associations;
8625 ---------------------------------
8626 -- Copy_Field_With_Replacement --
8627 ---------------------------------
8629 function Copy_Field_With_Replacement
8630 (Field : Union_Id) return Union_Id
8633 if Field = Union_Id (Empty) then
8636 elsif Field in Node_Range then
8638 Old_N : constant Node_Id := Node_Id (Field);
8642 -- If syntactic field, as indicated by the parent pointer
8643 -- being set, then copy the referenced node recursively.
8645 if Parent (Old_N) = Old_Node then
8646 New_N := Copy_Node_With_Replacement (Old_N);
8648 if New_N /= Old_N then
8649 Set_Parent (New_N, New_Node);
8652 -- For semantic fields, update possible entity reference
8653 -- from the replacement map.
8656 New_N := Assoc (Old_N);
8659 return Union_Id (New_N);
8662 elsif Field in List_Range then
8664 Old_L : constant List_Id := List_Id (Field);
8668 -- If syntactic field, as indicated by the parent pointer,
8669 -- then recursively copy the entire referenced list.
8671 if Parent (Old_L) = Old_Node then
8672 New_L := Copy_List_With_Replacement (Old_L);
8673 Set_Parent (New_L, New_Node);
8675 -- For semantic list, just returned unchanged
8681 return Union_Id (New_L);
8684 -- Anything other than a list or a node is returned unchanged
8689 end Copy_Field_With_Replacement;
8691 -- Start of processing for Copy_Node_With_Replacement
8694 if Old_Node <= Empty_Or_Error then
8697 elsif Has_Extension (Old_Node) then
8698 return Assoc (Old_Node);
8701 New_Node := New_Copy (Old_Node);
8703 -- If the node we are copying is the associated node of a
8704 -- previously copied Itype, then adjust the associated node
8705 -- of the copy of that Itype accordingly.
8707 if Present (Actual_Map) then
8713 -- Case of hash table used
8715 if NCT_Hash_Tables_Used then
8716 Ent := NCT_Itype_Assoc.Get (Old_Node);
8718 if Present (Ent) then
8719 Set_Associated_Node_For_Itype (Ent, New_Node);
8722 -- Case of no hash table used
8725 E := First_Elmt (Actual_Map);
8726 while Present (E) loop
8727 if Is_Itype (Node (E))
8729 Old_Node = Associated_Node_For_Itype (Node (E))
8731 Set_Associated_Node_For_Itype
8732 (Node (Next_Elmt (E)), New_Node);
8735 E := Next_Elmt (Next_Elmt (E));
8741 -- Recursively copy descendents
8744 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8746 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8748 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8750 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8752 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8754 -- Adjust Sloc of new node if necessary
8756 if New_Sloc /= No_Location then
8757 Set_Sloc (New_Node, New_Sloc);
8759 -- If we adjust the Sloc, then we are essentially making
8760 -- a completely new node, so the Comes_From_Source flag
8761 -- should be reset to the proper default value.
8763 Nodes.Table (New_Node).Comes_From_Source :=
8764 Default_Node.Comes_From_Source;
8767 -- If the node is call and has named associations,
8768 -- set the corresponding links in the copy.
8770 if (Nkind (Old_Node) = N_Function_Call
8771 or else Nkind (Old_Node) = N_Entry_Call_Statement
8773 Nkind (Old_Node) = N_Procedure_Call_Statement)
8774 and then Present (First_Named_Actual (Old_Node))
8776 Adjust_Named_Associations (Old_Node, New_Node);
8779 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8780 -- The replacement mechanism applies to entities, and is not used
8781 -- here. Eventually we may need a more general graph-copying
8782 -- routine. For now, do a sequential search to find desired node.
8784 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8785 and then Present (First_Real_Statement (Old_Node))
8788 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8792 N1 := First (Statements (Old_Node));
8793 N2 := First (Statements (New_Node));
8795 while N1 /= Old_F loop
8800 Set_First_Real_Statement (New_Node, N2);
8805 -- All done, return copied node
8808 end Copy_Node_With_Replacement;
8814 procedure Visit_Elist (E : Elist_Id) is
8818 Elmt := First_Elmt (E);
8820 while Elmt /= No_Elmt loop
8821 Visit_Node (Node (Elmt));
8831 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8833 if F = Union_Id (Empty) then
8836 elsif F in Node_Range then
8838 -- Copy node if it is syntactic, i.e. its parent pointer is
8839 -- set to point to the field that referenced it (certain
8840 -- Itypes will also meet this criterion, which is fine, since
8841 -- these are clearly Itypes that do need to be copied, since
8842 -- we are copying their parent.)
8844 if Parent (Node_Id (F)) = N then
8845 Visit_Node (Node_Id (F));
8848 -- Another case, if we are pointing to an Itype, then we want
8849 -- to copy it if its associated node is somewhere in the tree
8852 -- Note: the exclusion of self-referential copies is just an
8853 -- optimization, since the search of the already copied list
8854 -- would catch it, but it is a common case (Etype pointing
8855 -- to itself for an Itype that is a base type).
8857 elsif Has_Extension (Node_Id (F))
8858 and then Is_Itype (Entity_Id (F))
8859 and then Node_Id (F) /= N
8865 P := Associated_Node_For_Itype (Node_Id (F));
8866 while Present (P) loop
8868 Visit_Node (Node_Id (F));
8875 -- An Itype whose parent is not being copied definitely
8876 -- should NOT be copied, since it does not belong in any
8877 -- sense to the copied subtree.
8883 elsif F in List_Range
8884 and then Parent (List_Id (F)) = N
8886 Visit_List (List_Id (F));
8895 procedure Visit_Itype (Old_Itype : Entity_Id) is
8896 New_Itype : Entity_Id;
8901 -- Itypes that describe the designated type of access to subprograms
8902 -- have the structure of subprogram declarations, with signatures,
8903 -- etc. Either we duplicate the signatures completely, or choose to
8904 -- share such itypes, which is fine because their elaboration will
8905 -- have no side effects.
8907 if Ekind (Old_Itype) = E_Subprogram_Type then
8911 New_Itype := New_Copy (Old_Itype);
8913 -- The new Itype has all the attributes of the old one, and
8914 -- we just copy the contents of the entity. However, the back-end
8915 -- needs different names for debugging purposes, so we create a
8916 -- new internal name for it in all cases.
8918 Set_Chars (New_Itype, New_Internal_Name ('T'));
8920 -- If our associated node is an entity that has already been copied,
8921 -- then set the associated node of the copy to point to the right
8922 -- copy. If we have copied an Itype that is itself the associated
8923 -- node of some previously copied Itype, then we set the right
8924 -- pointer in the other direction.
8926 if Present (Actual_Map) then
8928 -- Case of hash tables used
8930 if NCT_Hash_Tables_Used then
8932 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8934 if Present (Ent) then
8935 Set_Associated_Node_For_Itype (New_Itype, Ent);
8938 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8939 if Present (Ent) then
8940 Set_Associated_Node_For_Itype (Ent, New_Itype);
8942 -- If the hash table has no association for this Itype and
8943 -- its associated node, enter one now.
8947 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8950 -- Case of hash tables not used
8953 E := First_Elmt (Actual_Map);
8954 while Present (E) loop
8955 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8956 Set_Associated_Node_For_Itype
8957 (New_Itype, Node (Next_Elmt (E)));
8960 if Is_Type (Node (E))
8962 Old_Itype = Associated_Node_For_Itype (Node (E))
8964 Set_Associated_Node_For_Itype
8965 (Node (Next_Elmt (E)), New_Itype);
8968 E := Next_Elmt (Next_Elmt (E));
8973 if Present (Freeze_Node (New_Itype)) then
8974 Set_Is_Frozen (New_Itype, False);
8975 Set_Freeze_Node (New_Itype, Empty);
8978 -- Add new association to map
8980 if No (Actual_Map) then
8981 Actual_Map := New_Elmt_List;
8984 Append_Elmt (Old_Itype, Actual_Map);
8985 Append_Elmt (New_Itype, Actual_Map);
8987 if NCT_Hash_Tables_Used then
8988 NCT_Assoc.Set (Old_Itype, New_Itype);
8991 NCT_Table_Entries := NCT_Table_Entries + 1;
8993 if NCT_Table_Entries > NCT_Hash_Threshold then
8994 Build_NCT_Hash_Tables;
8998 -- If a record subtype is simply copied, the entity list will be
8999 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9001 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9002 Set_Cloned_Subtype (New_Itype, Old_Itype);
9005 -- Visit descendents that eventually get copied
9007 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9009 if Is_Discrete_Type (Old_Itype) then
9010 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9012 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9013 -- ??? This should involve call to Visit_Field
9014 Visit_Elist (Discriminant_Constraint (Old_Itype));
9016 elsif Is_Array_Type (Old_Itype) then
9017 if Present (First_Index (Old_Itype)) then
9018 Visit_Field (Union_Id (List_Containing
9019 (First_Index (Old_Itype))),
9023 if Is_Packed (Old_Itype) then
9024 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9034 procedure Visit_List (L : List_Id) is
9037 if L /= No_List then
9040 while Present (N) loop
9051 procedure Visit_Node (N : Node_Or_Entity_Id) is
9053 -- Start of processing for Visit_Node
9056 -- Handle case of an Itype, which must be copied
9058 if Has_Extension (N)
9059 and then Is_Itype (N)
9061 -- Nothing to do if already in the list. This can happen with an
9062 -- Itype entity that appears more than once in the tree.
9063 -- Note that we do not want to visit descendents in this case.
9065 -- Test for already in list when hash table is used
9067 if NCT_Hash_Tables_Used then
9068 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9072 -- Test for already in list when hash table not used
9078 if Present (Actual_Map) then
9079 E := First_Elmt (Actual_Map);
9080 while Present (E) loop
9081 if Node (E) = N then
9084 E := Next_Elmt (Next_Elmt (E));
9094 -- Visit descendents
9096 Visit_Field (Field1 (N), N);
9097 Visit_Field (Field2 (N), N);
9098 Visit_Field (Field3 (N), N);
9099 Visit_Field (Field4 (N), N);
9100 Visit_Field (Field5 (N), N);
9103 -- Start of processing for New_Copy_Tree
9108 -- See if we should use hash table
9110 if No (Actual_Map) then
9111 NCT_Hash_Tables_Used := False;
9118 NCT_Table_Entries := 0;
9120 Elmt := First_Elmt (Actual_Map);
9121 while Present (Elmt) loop
9122 NCT_Table_Entries := NCT_Table_Entries + 1;
9127 if NCT_Table_Entries > NCT_Hash_Threshold then
9128 Build_NCT_Hash_Tables;
9130 NCT_Hash_Tables_Used := False;
9135 -- Hash table set up if required, now start phase one by visiting
9136 -- top node (we will recursively visit the descendents).
9138 Visit_Node (Source);
9140 -- Now the second phase of the copy can start. First we process
9141 -- all the mapped entities, copying their descendents.
9143 if Present (Actual_Map) then
9146 New_Itype : Entity_Id;
9148 Elmt := First_Elmt (Actual_Map);
9149 while Present (Elmt) loop
9151 New_Itype := Node (Elmt);
9152 Copy_Itype_With_Replacement (New_Itype);
9158 -- Now we can copy the actual tree
9160 return Copy_Node_With_Replacement (Source);
9163 -------------------------
9164 -- New_External_Entity --
9165 -------------------------
9167 function New_External_Entity
9168 (Kind : Entity_Kind;
9169 Scope_Id : Entity_Id;
9170 Sloc_Value : Source_Ptr;
9171 Related_Id : Entity_Id;
9173 Suffix_Index : Nat := 0;
9174 Prefix : Character := ' ') return Entity_Id
9176 N : constant Entity_Id :=
9177 Make_Defining_Identifier (Sloc_Value,
9179 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9182 Set_Ekind (N, Kind);
9183 Set_Is_Internal (N, True);
9184 Append_Entity (N, Scope_Id);
9185 Set_Public_Status (N);
9187 if Kind in Type_Kind then
9188 Init_Size_Align (N);
9192 end New_External_Entity;
9194 -------------------------
9195 -- New_Internal_Entity --
9196 -------------------------
9198 function New_Internal_Entity
9199 (Kind : Entity_Kind;
9200 Scope_Id : Entity_Id;
9201 Sloc_Value : Source_Ptr;
9202 Id_Char : Character) return Entity_Id
9204 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9207 Set_Ekind (N, Kind);
9208 Set_Is_Internal (N, True);
9209 Append_Entity (N, Scope_Id);
9211 if Kind in Type_Kind then
9212 Init_Size_Align (N);
9216 end New_Internal_Entity;
9222 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9226 -- If we are pointing at a positional parameter, it is a member of a
9227 -- node list (the list of parameters), and the next parameter is the
9228 -- next node on the list, unless we hit a parameter association, then
9229 -- we shift to using the chain whose head is the First_Named_Actual in
9230 -- the parent, and then is threaded using the Next_Named_Actual of the
9231 -- Parameter_Association. All this fiddling is because the original node
9232 -- list is in the textual call order, and what we need is the
9233 -- declaration order.
9235 if Is_List_Member (Actual_Id) then
9236 N := Next (Actual_Id);
9238 if Nkind (N) = N_Parameter_Association then
9239 return First_Named_Actual (Parent (Actual_Id));
9245 return Next_Named_Actual (Parent (Actual_Id));
9249 procedure Next_Actual (Actual_Id : in out Node_Id) is
9251 Actual_Id := Next_Actual (Actual_Id);
9254 -----------------------
9255 -- Normalize_Actuals --
9256 -----------------------
9258 -- Chain actuals according to formals of subprogram. If there are no named
9259 -- associations, the chain is simply the list of Parameter Associations,
9260 -- since the order is the same as the declaration order. If there are named
9261 -- associations, then the First_Named_Actual field in the N_Function_Call
9262 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9263 -- node for the parameter that comes first in declaration order. The
9264 -- remaining named parameters are then chained in declaration order using
9265 -- Next_Named_Actual.
9267 -- This routine also verifies that the number of actuals is compatible with
9268 -- the number and default values of formals, but performs no type checking
9269 -- (type checking is done by the caller).
9271 -- If the matching succeeds, Success is set to True and the caller proceeds
9272 -- with type-checking. If the match is unsuccessful, then Success is set to
9273 -- False, and the caller attempts a different interpretation, if there is
9276 -- If the flag Report is on, the call is not overloaded, and a failure to
9277 -- match can be reported here, rather than in the caller.
9279 procedure Normalize_Actuals
9283 Success : out Boolean)
9285 Actuals : constant List_Id := Parameter_Associations (N);
9286 Actual : Node_Id := Empty;
9288 Last : Node_Id := Empty;
9289 First_Named : Node_Id := Empty;
9292 Formals_To_Match : Integer := 0;
9293 Actuals_To_Match : Integer := 0;
9295 procedure Chain (A : Node_Id);
9296 -- Add named actual at the proper place in the list, using the
9297 -- Next_Named_Actual link.
9299 function Reporting return Boolean;
9300 -- Determines if an error is to be reported. To report an error, we
9301 -- need Report to be True, and also we do not report errors caused
9302 -- by calls to init procs that occur within other init procs. Such
9303 -- errors must always be cascaded errors, since if all the types are
9304 -- declared correctly, the compiler will certainly build decent calls!
9310 procedure Chain (A : Node_Id) is
9314 -- Call node points to first actual in list
9316 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9319 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9323 Set_Next_Named_Actual (Last, Empty);
9330 function Reporting return Boolean is
9335 elsif not Within_Init_Proc then
9338 elsif Is_Init_Proc (Entity (Name (N))) then
9346 -- Start of processing for Normalize_Actuals
9349 if Is_Access_Type (S) then
9351 -- The name in the call is a function call that returns an access
9352 -- to subprogram. The designated type has the list of formals.
9354 Formal := First_Formal (Designated_Type (S));
9356 Formal := First_Formal (S);
9359 while Present (Formal) loop
9360 Formals_To_Match := Formals_To_Match + 1;
9361 Next_Formal (Formal);
9364 -- Find if there is a named association, and verify that no positional
9365 -- associations appear after named ones.
9367 if Present (Actuals) then
9368 Actual := First (Actuals);
9371 while Present (Actual)
9372 and then Nkind (Actual) /= N_Parameter_Association
9374 Actuals_To_Match := Actuals_To_Match + 1;
9378 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9380 -- Most common case: positional notation, no defaults
9385 elsif Actuals_To_Match > Formals_To_Match then
9387 -- Too many actuals: will not work
9390 if Is_Entity_Name (Name (N)) then
9391 Error_Msg_N ("too many arguments in call to&", Name (N));
9393 Error_Msg_N ("too many arguments in call", N);
9401 First_Named := Actual;
9403 while Present (Actual) loop
9404 if Nkind (Actual) /= N_Parameter_Association then
9406 ("positional parameters not allowed after named ones", Actual);
9411 Actuals_To_Match := Actuals_To_Match + 1;
9417 if Present (Actuals) then
9418 Actual := First (Actuals);
9421 Formal := First_Formal (S);
9422 while Present (Formal) loop
9424 -- Match the formals in order. If the corresponding actual is
9425 -- positional, nothing to do. Else scan the list of named actuals
9426 -- to find the one with the right name.
9429 and then Nkind (Actual) /= N_Parameter_Association
9432 Actuals_To_Match := Actuals_To_Match - 1;
9433 Formals_To_Match := Formals_To_Match - 1;
9436 -- For named parameters, search the list of actuals to find
9437 -- one that matches the next formal name.
9439 Actual := First_Named;
9441 while Present (Actual) loop
9442 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9445 Actuals_To_Match := Actuals_To_Match - 1;
9446 Formals_To_Match := Formals_To_Match - 1;
9454 if Ekind (Formal) /= E_In_Parameter
9455 or else No (Default_Value (Formal))
9458 if (Comes_From_Source (S)
9459 or else Sloc (S) = Standard_Location)
9460 and then Is_Overloadable (S)
9464 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9466 (Nkind (Parent (N)) = N_Function_Call
9468 Nkind (Parent (N)) = N_Parameter_Association))
9469 and then Ekind (S) /= E_Function
9471 Set_Etype (N, Etype (S));
9473 Error_Msg_Name_1 := Chars (S);
9474 Error_Msg_Sloc := Sloc (S);
9476 ("missing argument for parameter & " &
9477 "in call to % declared #", N, Formal);
9480 elsif Is_Overloadable (S) then
9481 Error_Msg_Name_1 := Chars (S);
9483 -- Point to type derivation that generated the
9486 Error_Msg_Sloc := Sloc (Parent (S));
9489 ("missing argument for parameter & " &
9490 "in call to % (inherited) #", N, Formal);
9494 ("missing argument for parameter &", N, Formal);
9502 Formals_To_Match := Formals_To_Match - 1;
9507 Next_Formal (Formal);
9510 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9517 -- Find some superfluous named actual that did not get
9518 -- attached to the list of associations.
9520 Actual := First (Actuals);
9521 while Present (Actual) loop
9522 if Nkind (Actual) = N_Parameter_Association
9523 and then Actual /= Last
9524 and then No (Next_Named_Actual (Actual))
9526 Error_Msg_N ("unmatched actual & in call",
9527 Selector_Name (Actual));
9538 end Normalize_Actuals;
9540 --------------------------------
9541 -- Note_Possible_Modification --
9542 --------------------------------
9544 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9545 Modification_Comes_From_Source : constant Boolean :=
9546 Comes_From_Source (Parent (N));
9552 -- Loop to find referenced entity, if there is one
9559 if Is_Entity_Name (Exp) then
9560 Ent := Entity (Exp);
9562 -- If the entity is missing, it is an undeclared identifier,
9563 -- and there is nothing to annotate.
9569 elsif Nkind (Exp) = N_Explicit_Dereference then
9571 P : constant Node_Id := Prefix (Exp);
9574 if Nkind (P) = N_Selected_Component
9576 Entry_Formal (Entity (Selector_Name (P))))
9578 -- Case of a reference to an entry formal
9580 Ent := Entry_Formal (Entity (Selector_Name (P)));
9582 elsif Nkind (P) = N_Identifier
9583 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9584 and then Present (Expression (Parent (Entity (P))))
9585 and then Nkind (Expression (Parent (Entity (P))))
9588 -- Case of a reference to a value on which side effects have
9591 Exp := Prefix (Expression (Parent (Entity (P))));
9600 elsif Nkind (Exp) = N_Type_Conversion
9601 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9603 Exp := Expression (Exp);
9606 elsif Nkind (Exp) = N_Slice
9607 or else Nkind (Exp) = N_Indexed_Component
9608 or else Nkind (Exp) = N_Selected_Component
9610 Exp := Prefix (Exp);
9617 -- Now look for entity being referenced
9619 if Present (Ent) then
9620 if Is_Object (Ent) then
9621 if Comes_From_Source (Exp)
9622 or else Modification_Comes_From_Source
9624 -- Give warning if pragma unmodified given and we are
9625 -- sure this is a modification.
9627 if Has_Pragma_Unmodified (Ent) and then Sure then
9628 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9631 Set_Never_Set_In_Source (Ent, False);
9634 Set_Is_True_Constant (Ent, False);
9635 Set_Current_Value (Ent, Empty);
9636 Set_Is_Known_Null (Ent, False);
9638 if not Can_Never_Be_Null (Ent) then
9639 Set_Is_Known_Non_Null (Ent, False);
9642 -- Follow renaming chain
9644 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9645 and then Present (Renamed_Object (Ent))
9647 Exp := Renamed_Object (Ent);
9651 -- Generate a reference only if the assignment comes from
9652 -- source. This excludes, for example, calls to a dispatching
9653 -- assignment operation when the left-hand side is tagged.
9655 if Modification_Comes_From_Source then
9656 Generate_Reference (Ent, Exp, 'm');
9658 -- If the target of the assignment is the bound variable
9659 -- in an iterator, indicate that the corresponding array
9660 -- or container is also modified.
9662 if Ada_Version >= Ada_2012
9664 Nkind (Parent (Ent)) = N_Iterator_Specification
9667 Domain : constant Node_Id := Name (Parent (Ent));
9670 -- TBD : in the full version of the construct, the
9671 -- domain of iteration can be given by an expression.
9673 if Is_Entity_Name (Domain) then
9674 Generate_Reference (Entity (Domain), Exp, 'm');
9675 Set_Is_True_Constant (Entity (Domain), False);
9676 Set_Never_Set_In_Source (Entity (Domain), False);
9682 Check_Nested_Access (Ent);
9687 -- If we are sure this is a modification from source, and we know
9688 -- this modifies a constant, then give an appropriate warning.
9690 if Overlays_Constant (Ent)
9691 and then Modification_Comes_From_Source
9695 A : constant Node_Id := Address_Clause (Ent);
9699 Exp : constant Node_Id := Expression (A);
9701 if Nkind (Exp) = N_Attribute_Reference
9702 and then Attribute_Name (Exp) = Name_Address
9703 and then Is_Entity_Name (Prefix (Exp))
9705 Error_Msg_Sloc := Sloc (A);
9707 ("constant& may be modified via address clause#?",
9708 N, Entity (Prefix (Exp)));
9718 end Note_Possible_Modification;
9720 -------------------------
9721 -- Object_Access_Level --
9722 -------------------------
9724 function Object_Access_Level (Obj : Node_Id) return Uint is
9727 -- Returns the static accessibility level of the view denoted by Obj. Note
9728 -- that the value returned is the result of a call to Scope_Depth. Only
9729 -- scope depths associated with dynamic scopes can actually be returned.
9730 -- Since only relative levels matter for accessibility checking, the fact
9731 -- that the distance between successive levels of accessibility is not
9732 -- always one is immaterial (invariant: if level(E2) is deeper than
9733 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9735 function Reference_To (Obj : Node_Id) return Node_Id;
9736 -- An explicit dereference is created when removing side-effects from
9737 -- expressions for constraint checking purposes. In this case a local
9738 -- access type is created for it. The correct access level is that of
9739 -- the original source node. We detect this case by noting that the
9740 -- prefix of the dereference is created by an object declaration whose
9741 -- initial expression is a reference.
9747 function Reference_To (Obj : Node_Id) return Node_Id is
9748 Pref : constant Node_Id := Prefix (Obj);
9750 if Is_Entity_Name (Pref)
9751 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9752 and then Present (Expression (Parent (Entity (Pref))))
9753 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9755 return (Prefix (Expression (Parent (Entity (Pref)))));
9761 -- Start of processing for Object_Access_Level
9764 if Is_Entity_Name (Obj) then
9767 if Is_Prival (E) then
9768 E := Prival_Link (E);
9771 -- If E is a type then it denotes a current instance. For this case
9772 -- we add one to the normal accessibility level of the type to ensure
9773 -- that current instances are treated as always being deeper than
9774 -- than the level of any visible named access type (see 3.10.2(21)).
9777 return Type_Access_Level (E) + 1;
9779 elsif Present (Renamed_Object (E)) then
9780 return Object_Access_Level (Renamed_Object (E));
9782 -- Similarly, if E is a component of the current instance of a
9783 -- protected type, any instance of it is assumed to be at a deeper
9784 -- level than the type. For a protected object (whose type is an
9785 -- anonymous protected type) its components are at the same level
9786 -- as the type itself.
9788 elsif not Is_Overloadable (E)
9789 and then Ekind (Scope (E)) = E_Protected_Type
9790 and then Comes_From_Source (Scope (E))
9792 return Type_Access_Level (Scope (E)) + 1;
9795 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9798 elsif Nkind (Obj) = N_Selected_Component then
9799 if Is_Access_Type (Etype (Prefix (Obj))) then
9800 return Type_Access_Level (Etype (Prefix (Obj)));
9802 return Object_Access_Level (Prefix (Obj));
9805 elsif Nkind (Obj) = N_Indexed_Component then
9806 if Is_Access_Type (Etype (Prefix (Obj))) then
9807 return Type_Access_Level (Etype (Prefix (Obj)));
9809 return Object_Access_Level (Prefix (Obj));
9812 elsif Nkind (Obj) = N_Explicit_Dereference then
9814 -- If the prefix is a selected access discriminant then we make a
9815 -- recursive call on the prefix, which will in turn check the level
9816 -- of the prefix object of the selected discriminant.
9818 if Nkind (Prefix (Obj)) = N_Selected_Component
9819 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9821 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9823 return Object_Access_Level (Prefix (Obj));
9825 elsif not (Comes_From_Source (Obj)) then
9827 Ref : constant Node_Id := Reference_To (Obj);
9829 if Present (Ref) then
9830 return Object_Access_Level (Ref);
9832 return Type_Access_Level (Etype (Prefix (Obj)));
9837 return Type_Access_Level (Etype (Prefix (Obj)));
9840 elsif Nkind (Obj) = N_Type_Conversion
9841 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9843 return Object_Access_Level (Expression (Obj));
9845 elsif Nkind (Obj) = N_Function_Call then
9847 -- Function results are objects, so we get either the access level of
9848 -- the function or, in the case of an indirect call, the level of the
9849 -- access-to-subprogram type. (This code is used for Ada 95, but it
9850 -- looks wrong, because it seems that we should be checking the level
9851 -- of the call itself, even for Ada 95. However, using the Ada 2005
9852 -- version of the code causes regressions in several tests that are
9853 -- compiled with -gnat95. ???)
9855 if Ada_Version < Ada_2005 then
9856 if Is_Entity_Name (Name (Obj)) then
9857 return Subprogram_Access_Level (Entity (Name (Obj)));
9859 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9862 -- For Ada 2005, the level of the result object of a function call is
9863 -- defined to be the level of the call's innermost enclosing master.
9864 -- We determine that by querying the depth of the innermost enclosing
9868 Return_Master_Scope_Depth_Of_Call : declare
9870 function Innermost_Master_Scope_Depth
9871 (N : Node_Id) return Uint;
9872 -- Returns the scope depth of the given node's innermost
9873 -- enclosing dynamic scope (effectively the accessibility
9874 -- level of the innermost enclosing master).
9876 ----------------------------------
9877 -- Innermost_Master_Scope_Depth --
9878 ----------------------------------
9880 function Innermost_Master_Scope_Depth
9881 (N : Node_Id) return Uint
9883 Node_Par : Node_Id := Parent (N);
9886 -- Locate the nearest enclosing node (by traversing Parents)
9887 -- that Defining_Entity can be applied to, and return the
9888 -- depth of that entity's nearest enclosing dynamic scope.
9890 while Present (Node_Par) loop
9891 case Nkind (Node_Par) is
9892 when N_Component_Declaration |
9893 N_Entry_Declaration |
9894 N_Formal_Object_Declaration |
9895 N_Formal_Type_Declaration |
9896 N_Full_Type_Declaration |
9897 N_Incomplete_Type_Declaration |
9898 N_Loop_Parameter_Specification |
9899 N_Object_Declaration |
9900 N_Protected_Type_Declaration |
9901 N_Private_Extension_Declaration |
9902 N_Private_Type_Declaration |
9903 N_Subtype_Declaration |
9904 N_Function_Specification |
9905 N_Procedure_Specification |
9906 N_Task_Type_Declaration |
9908 N_Generic_Instantiation |
9910 N_Implicit_Label_Declaration |
9911 N_Package_Declaration |
9912 N_Single_Task_Declaration |
9913 N_Subprogram_Declaration |
9914 N_Generic_Declaration |
9915 N_Renaming_Declaration |
9917 N_Formal_Subprogram_Declaration |
9918 N_Abstract_Subprogram_Declaration |
9920 N_Exception_Declaration |
9921 N_Formal_Package_Declaration |
9922 N_Number_Declaration |
9923 N_Package_Specification |
9924 N_Parameter_Specification |
9925 N_Single_Protected_Declaration |
9929 (Nearest_Dynamic_Scope
9930 (Defining_Entity (Node_Par)));
9936 Node_Par := Parent (Node_Par);
9939 pragma Assert (False);
9941 -- Should never reach the following return
9943 return Scope_Depth (Current_Scope) + 1;
9944 end Innermost_Master_Scope_Depth;
9946 -- Start of processing for Return_Master_Scope_Depth_Of_Call
9949 return Innermost_Master_Scope_Depth (Obj);
9950 end Return_Master_Scope_Depth_Of_Call;
9953 -- For convenience we handle qualified expressions, even though
9954 -- they aren't technically object names.
9956 elsif Nkind (Obj) = N_Qualified_Expression then
9957 return Object_Access_Level (Expression (Obj));
9959 -- Otherwise return the scope level of Standard.
9960 -- (If there are cases that fall through
9961 -- to this point they will be treated as
9962 -- having global accessibility for now. ???)
9965 return Scope_Depth (Standard_Standard);
9967 end Object_Access_Level;
9969 --------------------------------------
9970 -- Original_Corresponding_Operation --
9971 --------------------------------------
9973 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
9975 Typ : constant Entity_Id := Find_Dispatching_Type (S);
9978 -- If S is an inherited primitive S2 the original corresponding
9979 -- operation of S is the original corresponding operation of S2
9981 if Present (Alias (S))
9982 and then Find_Dispatching_Type (Alias (S)) /= Typ
9984 return Original_Corresponding_Operation (Alias (S));
9986 -- If S overrides an inherited subprogram S2 the original corresponding
9987 -- operation of S is the original corresponding operation of S2
9989 elsif Present (Overridden_Operation (S)) then
9990 return Original_Corresponding_Operation (Overridden_Operation (S));
9992 -- otherwise it is S itself
9997 end Original_Corresponding_Operation;
9999 -----------------------
10000 -- Private_Component --
10001 -----------------------
10003 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10004 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10006 function Trace_Components
10008 Check : Boolean) return Entity_Id;
10009 -- Recursive function that does the work, and checks against circular
10010 -- definition for each subcomponent type.
10012 ----------------------
10013 -- Trace_Components --
10014 ----------------------
10016 function Trace_Components
10018 Check : Boolean) return Entity_Id
10020 Btype : constant Entity_Id := Base_Type (T);
10021 Component : Entity_Id;
10023 Candidate : Entity_Id := Empty;
10026 if Check and then Btype = Ancestor then
10027 Error_Msg_N ("circular type definition", Type_Id);
10031 if Is_Private_Type (Btype)
10032 and then not Is_Generic_Type (Btype)
10034 if Present (Full_View (Btype))
10035 and then Is_Record_Type (Full_View (Btype))
10036 and then not Is_Frozen (Btype)
10038 -- To indicate that the ancestor depends on a private type, the
10039 -- current Btype is sufficient. However, to check for circular
10040 -- definition we must recurse on the full view.
10042 Candidate := Trace_Components (Full_View (Btype), True);
10044 if Candidate = Any_Type then
10054 elsif Is_Array_Type (Btype) then
10055 return Trace_Components (Component_Type (Btype), True);
10057 elsif Is_Record_Type (Btype) then
10058 Component := First_Entity (Btype);
10059 while Present (Component) loop
10061 -- Skip anonymous types generated by constrained components
10063 if not Is_Type (Component) then
10064 P := Trace_Components (Etype (Component), True);
10066 if Present (P) then
10067 if P = Any_Type then
10075 Next_Entity (Component);
10083 end Trace_Components;
10085 -- Start of processing for Private_Component
10088 return Trace_Components (Type_Id, False);
10089 end Private_Component;
10091 ---------------------------
10092 -- Primitive_Names_Match --
10093 ---------------------------
10095 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10097 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10098 -- Given an internal name, returns the corresponding non-internal name
10100 ------------------------
10101 -- Non_Internal_Name --
10102 ------------------------
10104 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10106 Get_Name_String (Chars (E));
10107 Name_Len := Name_Len - 1;
10109 end Non_Internal_Name;
10111 -- Start of processing for Primitive_Names_Match
10114 pragma Assert (Present (E1) and then Present (E2));
10116 return Chars (E1) = Chars (E2)
10118 (not Is_Internal_Name (Chars (E1))
10119 and then Is_Internal_Name (Chars (E2))
10120 and then Non_Internal_Name (E2) = Chars (E1))
10122 (not Is_Internal_Name (Chars (E2))
10123 and then Is_Internal_Name (Chars (E1))
10124 and then Non_Internal_Name (E1) = Chars (E2))
10126 (Is_Predefined_Dispatching_Operation (E1)
10127 and then Is_Predefined_Dispatching_Operation (E2)
10128 and then Same_TSS (E1, E2))
10130 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10131 end Primitive_Names_Match;
10133 -----------------------
10134 -- Process_End_Label --
10135 -----------------------
10137 procedure Process_End_Label
10146 Label_Ref : Boolean;
10147 -- Set True if reference to end label itself is required
10150 -- Gets set to the operator symbol or identifier that references the
10151 -- entity Ent. For the child unit case, this is the identifier from the
10152 -- designator. For other cases, this is simply Endl.
10154 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10155 -- N is an identifier node that appears as a parent unit reference in
10156 -- the case where Ent is a child unit. This procedure generates an
10157 -- appropriate cross-reference entry. E is the corresponding entity.
10159 -------------------------
10160 -- Generate_Parent_Ref --
10161 -------------------------
10163 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10165 -- If names do not match, something weird, skip reference
10167 if Chars (E) = Chars (N) then
10169 -- Generate the reference. We do NOT consider this as a reference
10170 -- for unreferenced symbol purposes.
10172 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10174 if Style_Check then
10175 Style.Check_Identifier (N, E);
10178 end Generate_Parent_Ref;
10180 -- Start of processing for Process_End_Label
10183 -- If no node, ignore. This happens in some error situations, and
10184 -- also for some internally generated structures where no end label
10185 -- references are required in any case.
10191 -- Nothing to do if no End_Label, happens for internally generated
10192 -- constructs where we don't want an end label reference anyway. Also
10193 -- nothing to do if Endl is a string literal, which means there was
10194 -- some prior error (bad operator symbol)
10196 Endl := End_Label (N);
10198 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10202 -- Reference node is not in extended main source unit
10204 if not In_Extended_Main_Source_Unit (N) then
10206 -- Generally we do not collect references except for the extended
10207 -- main source unit. The one exception is the 'e' entry for a
10208 -- package spec, where it is useful for a client to have the
10209 -- ending information to define scopes.
10215 Label_Ref := False;
10217 -- For this case, we can ignore any parent references, but we
10218 -- need the package name itself for the 'e' entry.
10220 if Nkind (Endl) = N_Designator then
10221 Endl := Identifier (Endl);
10225 -- Reference is in extended main source unit
10230 -- For designator, generate references for the parent entries
10232 if Nkind (Endl) = N_Designator then
10234 -- Generate references for the prefix if the END line comes from
10235 -- source (otherwise we do not need these references) We climb the
10236 -- scope stack to find the expected entities.
10238 if Comes_From_Source (Endl) then
10239 Nam := Name (Endl);
10240 Scop := Current_Scope;
10241 while Nkind (Nam) = N_Selected_Component loop
10242 Scop := Scope (Scop);
10243 exit when No (Scop);
10244 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10245 Nam := Prefix (Nam);
10248 if Present (Scop) then
10249 Generate_Parent_Ref (Nam, Scope (Scop));
10253 Endl := Identifier (Endl);
10257 -- If the end label is not for the given entity, then either we have
10258 -- some previous error, or this is a generic instantiation for which
10259 -- we do not need to make a cross-reference in this case anyway. In
10260 -- either case we simply ignore the call.
10262 if Chars (Ent) /= Chars (Endl) then
10266 -- If label was really there, then generate a normal reference and then
10267 -- adjust the location in the end label to point past the name (which
10268 -- should almost always be the semicolon).
10270 Loc := Sloc (Endl);
10272 if Comes_From_Source (Endl) then
10274 -- If a label reference is required, then do the style check and
10275 -- generate an l-type cross-reference entry for the label
10278 if Style_Check then
10279 Style.Check_Identifier (Endl, Ent);
10282 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10285 -- Set the location to point past the label (normally this will
10286 -- mean the semicolon immediately following the label). This is
10287 -- done for the sake of the 'e' or 't' entry generated below.
10289 Get_Decoded_Name_String (Chars (Endl));
10290 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10293 -- Now generate the e/t reference
10295 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10297 -- Restore Sloc, in case modified above, since we have an identifier
10298 -- and the normal Sloc should be left set in the tree.
10300 Set_Sloc (Endl, Loc);
10301 end Process_End_Label;
10303 ------------------------------------
10304 -- References_Generic_Formal_Type --
10305 ------------------------------------
10307 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10309 function Process (N : Node_Id) return Traverse_Result;
10310 -- Process one node in search for generic formal type
10316 function Process (N : Node_Id) return Traverse_Result is
10318 if Nkind (N) in N_Has_Entity then
10320 E : constant Entity_Id := Entity (N);
10322 if Present (E) then
10323 if Is_Generic_Type (E) then
10325 elsif Present (Etype (E))
10326 and then Is_Generic_Type (Etype (E))
10337 function Traverse is new Traverse_Func (Process);
10338 -- Traverse tree to look for generic type
10341 if Inside_A_Generic then
10342 return Traverse (N) = Abandon;
10346 end References_Generic_Formal_Type;
10348 --------------------
10349 -- Remove_Homonym --
10350 --------------------
10352 procedure Remove_Homonym (E : Entity_Id) is
10353 Prev : Entity_Id := Empty;
10357 if E = Current_Entity (E) then
10358 if Present (Homonym (E)) then
10359 Set_Current_Entity (Homonym (E));
10361 Set_Name_Entity_Id (Chars (E), Empty);
10364 H := Current_Entity (E);
10365 while Present (H) and then H /= E loop
10370 Set_Homonym (Prev, Homonym (E));
10372 end Remove_Homonym;
10374 ---------------------
10375 -- Rep_To_Pos_Flag --
10376 ---------------------
10378 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10380 return New_Occurrence_Of
10381 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10382 end Rep_To_Pos_Flag;
10384 --------------------
10385 -- Require_Entity --
10386 --------------------
10388 procedure Require_Entity (N : Node_Id) is
10390 if Is_Entity_Name (N) and then No (Entity (N)) then
10391 if Total_Errors_Detected /= 0 then
10392 Set_Entity (N, Any_Id);
10394 raise Program_Error;
10397 end Require_Entity;
10399 ------------------------------
10400 -- Requires_Transient_Scope --
10401 ------------------------------
10403 -- A transient scope is required when variable-sized temporaries are
10404 -- allocated in the primary or secondary stack, or when finalization
10405 -- actions must be generated before the next instruction.
10407 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10408 Typ : constant Entity_Id := Underlying_Type (Id);
10410 -- Start of processing for Requires_Transient_Scope
10413 -- This is a private type which is not completed yet. This can only
10414 -- happen in a default expression (of a formal parameter or of a
10415 -- record component). Do not expand transient scope in this case
10420 -- Do not expand transient scope for non-existent procedure return
10422 elsif Typ = Standard_Void_Type then
10425 -- Elementary types do not require a transient scope
10427 elsif Is_Elementary_Type (Typ) then
10430 -- Generally, indefinite subtypes require a transient scope, since the
10431 -- back end cannot generate temporaries, since this is not a valid type
10432 -- for declaring an object. It might be possible to relax this in the
10433 -- future, e.g. by declaring the maximum possible space for the type.
10435 elsif Is_Indefinite_Subtype (Typ) then
10438 -- Functions returning tagged types may dispatch on result so their
10439 -- returned value is allocated on the secondary stack. Controlled
10440 -- type temporaries need finalization.
10442 elsif Is_Tagged_Type (Typ)
10443 or else Has_Controlled_Component (Typ)
10445 return not Is_Value_Type (Typ);
10449 elsif Is_Record_Type (Typ) then
10453 Comp := First_Entity (Typ);
10454 while Present (Comp) loop
10455 if Ekind (Comp) = E_Component
10456 and then Requires_Transient_Scope (Etype (Comp))
10460 Next_Entity (Comp);
10467 -- String literal types never require transient scope
10469 elsif Ekind (Typ) = E_String_Literal_Subtype then
10472 -- Array type. Note that we already know that this is a constrained
10473 -- array, since unconstrained arrays will fail the indefinite test.
10475 elsif Is_Array_Type (Typ) then
10477 -- If component type requires a transient scope, the array does too
10479 if Requires_Transient_Scope (Component_Type (Typ)) then
10482 -- Otherwise, we only need a transient scope if the size depends on
10483 -- the value of one or more discriminants.
10486 return Size_Depends_On_Discriminant (Typ);
10489 -- All other cases do not require a transient scope
10494 end Requires_Transient_Scope;
10496 --------------------------
10497 -- Reset_Analyzed_Flags --
10498 --------------------------
10500 procedure Reset_Analyzed_Flags (N : Node_Id) is
10502 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10503 -- Function used to reset Analyzed flags in tree. Note that we do
10504 -- not reset Analyzed flags in entities, since there is no need to
10505 -- reanalyze entities, and indeed, it is wrong to do so, since it
10506 -- can result in generating auxiliary stuff more than once.
10508 --------------------
10509 -- Clear_Analyzed --
10510 --------------------
10512 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10514 if not Has_Extension (N) then
10515 Set_Analyzed (N, False);
10519 end Clear_Analyzed;
10521 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10523 -- Start of processing for Reset_Analyzed_Flags
10526 Reset_Analyzed (N);
10527 end Reset_Analyzed_Flags;
10529 ---------------------------
10530 -- Safe_To_Capture_Value --
10531 ---------------------------
10533 function Safe_To_Capture_Value
10536 Cond : Boolean := False) return Boolean
10539 -- The only entities for which we track constant values are variables
10540 -- which are not renamings, constants, out parameters, and in out
10541 -- parameters, so check if we have this case.
10543 -- Note: it may seem odd to track constant values for constants, but in
10544 -- fact this routine is used for other purposes than simply capturing
10545 -- the value. In particular, the setting of Known[_Non]_Null.
10547 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10549 Ekind (Ent) = E_Constant
10551 Ekind (Ent) = E_Out_Parameter
10553 Ekind (Ent) = E_In_Out_Parameter
10557 -- For conditionals, we also allow loop parameters and all formals,
10558 -- including in parameters.
10562 (Ekind (Ent) = E_Loop_Parameter
10564 Ekind (Ent) = E_In_Parameter)
10568 -- For all other cases, not just unsafe, but impossible to capture
10569 -- Current_Value, since the above are the only entities which have
10570 -- Current_Value fields.
10576 -- Skip if volatile or aliased, since funny things might be going on in
10577 -- these cases which we cannot necessarily track. Also skip any variable
10578 -- for which an address clause is given, or whose address is taken. Also
10579 -- never capture value of library level variables (an attempt to do so
10580 -- can occur in the case of package elaboration code).
10582 if Treat_As_Volatile (Ent)
10583 or else Is_Aliased (Ent)
10584 or else Present (Address_Clause (Ent))
10585 or else Address_Taken (Ent)
10586 or else (Is_Library_Level_Entity (Ent)
10587 and then Ekind (Ent) = E_Variable)
10592 -- OK, all above conditions are met. We also require that the scope of
10593 -- the reference be the same as the scope of the entity, not counting
10594 -- packages and blocks and loops.
10597 E_Scope : constant Entity_Id := Scope (Ent);
10598 R_Scope : Entity_Id;
10601 R_Scope := Current_Scope;
10602 while R_Scope /= Standard_Standard loop
10603 exit when R_Scope = E_Scope;
10605 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10608 R_Scope := Scope (R_Scope);
10613 -- We also require that the reference does not appear in a context
10614 -- where it is not sure to be executed (i.e. a conditional context
10615 -- or an exception handler). We skip this if Cond is True, since the
10616 -- capturing of values from conditional tests handles this ok.
10630 while Present (P) loop
10631 if Nkind (P) = N_If_Statement
10632 or else Nkind (P) = N_Case_Statement
10633 or else (Nkind (P) in N_Short_Circuit
10634 and then Desc = Right_Opnd (P))
10635 or else (Nkind (P) = N_Conditional_Expression
10636 and then Desc /= First (Expressions (P)))
10637 or else Nkind (P) = N_Exception_Handler
10638 or else Nkind (P) = N_Selective_Accept
10639 or else Nkind (P) = N_Conditional_Entry_Call
10640 or else Nkind (P) = N_Timed_Entry_Call
10641 or else Nkind (P) = N_Asynchronous_Select
10651 -- OK, looks safe to set value
10654 end Safe_To_Capture_Value;
10660 function Same_Name (N1, N2 : Node_Id) return Boolean is
10661 K1 : constant Node_Kind := Nkind (N1);
10662 K2 : constant Node_Kind := Nkind (N2);
10665 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10666 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10668 return Chars (N1) = Chars (N2);
10670 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10671 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10673 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10674 and then Same_Name (Prefix (N1), Prefix (N2));
10685 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10686 N1 : constant Node_Id := Original_Node (Node1);
10687 N2 : constant Node_Id := Original_Node (Node2);
10688 -- We do the tests on original nodes, since we are most interested
10689 -- in the original source, not any expansion that got in the way.
10691 K1 : constant Node_Kind := Nkind (N1);
10692 K2 : constant Node_Kind := Nkind (N2);
10695 -- First case, both are entities with same entity
10697 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
10699 EN1 : constant Entity_Id := Entity (N1);
10700 EN2 : constant Entity_Id := Entity (N2);
10702 if Present (EN1) and then Present (EN2)
10703 and then (Ekind_In (EN1, E_Variable, E_Constant)
10704 or else Is_Formal (EN1))
10712 -- Second case, selected component with same selector, same record
10714 if K1 = N_Selected_Component
10715 and then K2 = N_Selected_Component
10716 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10718 return Same_Object (Prefix (N1), Prefix (N2));
10720 -- Third case, indexed component with same subscripts, same array
10722 elsif K1 = N_Indexed_Component
10723 and then K2 = N_Indexed_Component
10724 and then Same_Object (Prefix (N1), Prefix (N2))
10729 E1 := First (Expressions (N1));
10730 E2 := First (Expressions (N2));
10731 while Present (E1) loop
10732 if not Same_Value (E1, E2) then
10743 -- Fourth case, slice of same array with same bounds
10746 and then K2 = N_Slice
10747 and then Nkind (Discrete_Range (N1)) = N_Range
10748 and then Nkind (Discrete_Range (N2)) = N_Range
10749 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10750 Low_Bound (Discrete_Range (N2)))
10751 and then Same_Value (High_Bound (Discrete_Range (N1)),
10752 High_Bound (Discrete_Range (N2)))
10754 return Same_Name (Prefix (N1), Prefix (N2));
10756 -- All other cases, not clearly the same object
10767 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10772 elsif not Is_Constrained (T1)
10773 and then not Is_Constrained (T2)
10774 and then Base_Type (T1) = Base_Type (T2)
10778 -- For now don't bother with case of identical constraints, to be
10779 -- fiddled with later on perhaps (this is only used for optimization
10780 -- purposes, so it is not critical to do a best possible job)
10791 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10793 if Compile_Time_Known_Value (Node1)
10794 and then Compile_Time_Known_Value (Node2)
10795 and then Expr_Value (Node1) = Expr_Value (Node2)
10798 elsif Same_Object (Node1, Node2) then
10809 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
10811 if Ada_Version < Ada_2012 then
10814 elsif Is_Entity_Name (N)
10816 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
10818 (Nkind (N) = N_Attribute_Reference
10819 and then Attribute_Name (N) = Name_Access)
10822 -- We are only interested in IN OUT parameters of inner calls
10825 or else Nkind (Parent (N)) = N_Function_Call
10826 or else Nkind (Parent (N)) in N_Op
10828 Actuals_In_Call.Increment_Last;
10829 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
10834 ------------------------
10835 -- Scope_Is_Transient --
10836 ------------------------
10838 function Scope_Is_Transient return Boolean is
10840 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10841 end Scope_Is_Transient;
10847 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10852 while Scop /= Standard_Standard loop
10853 Scop := Scope (Scop);
10855 if Scop = Scope2 then
10863 --------------------------
10864 -- Scope_Within_Or_Same --
10865 --------------------------
10867 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10872 while Scop /= Standard_Standard loop
10873 if Scop = Scope2 then
10876 Scop := Scope (Scop);
10881 end Scope_Within_Or_Same;
10883 --------------------
10884 -- Set_Convention --
10885 --------------------
10887 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10889 Basic_Set_Convention (E, Val);
10892 and then Is_Access_Subprogram_Type (Base_Type (E))
10893 and then Has_Foreign_Convention (E)
10895 Set_Can_Use_Internal_Rep (E, False);
10897 end Set_Convention;
10899 ------------------------
10900 -- Set_Current_Entity --
10901 ------------------------
10903 -- The given entity is to be set as the currently visible definition
10904 -- of its associated name (i.e. the Node_Id associated with its name).
10905 -- All we have to do is to get the name from the identifier, and
10906 -- then set the associated Node_Id to point to the given entity.
10908 procedure Set_Current_Entity (E : Entity_Id) is
10910 Set_Name_Entity_Id (Chars (E), E);
10911 end Set_Current_Entity;
10913 ---------------------------
10914 -- Set_Debug_Info_Needed --
10915 ---------------------------
10917 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10919 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10920 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10921 -- Used to set debug info in a related node if not set already
10923 --------------------------------------
10924 -- Set_Debug_Info_Needed_If_Not_Set --
10925 --------------------------------------
10927 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10930 and then not Needs_Debug_Info (E)
10932 Set_Debug_Info_Needed (E);
10934 -- For a private type, indicate that the full view also needs
10935 -- debug information.
10938 and then Is_Private_Type (E)
10939 and then Present (Full_View (E))
10941 Set_Debug_Info_Needed (Full_View (E));
10944 end Set_Debug_Info_Needed_If_Not_Set;
10946 -- Start of processing for Set_Debug_Info_Needed
10949 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10950 -- indicates that Debug_Info_Needed is never required for the entity.
10953 or else Debug_Info_Off (T)
10958 -- Set flag in entity itself. Note that we will go through the following
10959 -- circuitry even if the flag is already set on T. That's intentional,
10960 -- it makes sure that the flag will be set in subsidiary entities.
10962 Set_Needs_Debug_Info (T);
10964 -- Set flag on subsidiary entities if not set already
10966 if Is_Object (T) then
10967 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10969 elsif Is_Type (T) then
10970 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10972 if Is_Record_Type (T) then
10974 Ent : Entity_Id := First_Entity (T);
10976 while Present (Ent) loop
10977 Set_Debug_Info_Needed_If_Not_Set (Ent);
10982 -- For a class wide subtype, we also need debug information
10983 -- for the equivalent type.
10985 if Ekind (T) = E_Class_Wide_Subtype then
10986 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10989 elsif Is_Array_Type (T) then
10990 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10993 Indx : Node_Id := First_Index (T);
10995 while Present (Indx) loop
10996 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10997 Indx := Next_Index (Indx);
11001 if Is_Packed (T) then
11002 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11005 elsif Is_Access_Type (T) then
11006 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11008 elsif Is_Private_Type (T) then
11009 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11011 elsif Is_Protected_Type (T) then
11012 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11015 end Set_Debug_Info_Needed;
11017 ---------------------------------
11018 -- Set_Entity_With_Style_Check --
11019 ---------------------------------
11021 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11022 Val_Actual : Entity_Id;
11026 Set_Entity (N, Val);
11029 and then not Suppress_Style_Checks (Val)
11030 and then not In_Instance
11032 if Nkind (N) = N_Identifier then
11034 elsif Nkind (N) = N_Expanded_Name then
11035 Nod := Selector_Name (N);
11040 -- A special situation arises for derived operations, where we want
11041 -- to do the check against the parent (since the Sloc of the derived
11042 -- operation points to the derived type declaration itself).
11045 while not Comes_From_Source (Val_Actual)
11046 and then Nkind (Val_Actual) in N_Entity
11047 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11048 or else Is_Subprogram (Val_Actual)
11049 or else Is_Generic_Subprogram (Val_Actual))
11050 and then Present (Alias (Val_Actual))
11052 Val_Actual := Alias (Val_Actual);
11055 -- Renaming declarations for generic actuals do not come from source,
11056 -- and have a different name from that of the entity they rename, so
11057 -- there is no style check to perform here.
11059 if Chars (Nod) = Chars (Val_Actual) then
11060 Style.Check_Identifier (Nod, Val_Actual);
11064 Set_Entity (N, Val);
11065 end Set_Entity_With_Style_Check;
11067 ------------------------
11068 -- Set_Name_Entity_Id --
11069 ------------------------
11071 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11073 Set_Name_Table_Info (Id, Int (Val));
11074 end Set_Name_Entity_Id;
11076 ---------------------
11077 -- Set_Next_Actual --
11078 ---------------------
11080 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11082 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11083 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11085 end Set_Next_Actual;
11087 ----------------------------------
11088 -- Set_Optimize_Alignment_Flags --
11089 ----------------------------------
11091 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11093 if Optimize_Alignment = 'S' then
11094 Set_Optimize_Alignment_Space (E);
11095 elsif Optimize_Alignment = 'T' then
11096 Set_Optimize_Alignment_Time (E);
11098 end Set_Optimize_Alignment_Flags;
11100 -----------------------
11101 -- Set_Public_Status --
11102 -----------------------
11104 procedure Set_Public_Status (Id : Entity_Id) is
11105 S : constant Entity_Id := Current_Scope;
11107 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11108 -- Determines if E is defined within handled statement sequence or
11109 -- an if statement, returns True if so, False otherwise.
11111 ----------------------
11112 -- Within_HSS_Or_If --
11113 ----------------------
11115 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11118 N := Declaration_Node (E);
11125 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11131 end Within_HSS_Or_If;
11133 -- Start of processing for Set_Public_Status
11136 -- Everything in the scope of Standard is public
11138 if S = Standard_Standard then
11139 Set_Is_Public (Id);
11141 -- Entity is definitely not public if enclosing scope is not public
11143 elsif not Is_Public (S) then
11146 -- An object or function declaration that occurs in a handled sequence
11147 -- of statements or within an if statement is the declaration for a
11148 -- temporary object or local subprogram generated by the expander. It
11149 -- never needs to be made public and furthermore, making it public can
11150 -- cause back end problems.
11152 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11153 N_Function_Specification)
11154 and then Within_HSS_Or_If (Id)
11158 -- Entities in public packages or records are public
11160 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11161 Set_Is_Public (Id);
11163 -- The bounds of an entry family declaration can generate object
11164 -- declarations that are visible to the back-end, e.g. in the
11165 -- the declaration of a composite type that contains tasks.
11167 elsif Is_Concurrent_Type (S)
11168 and then not Has_Completion (S)
11169 and then Nkind (Parent (Id)) = N_Object_Declaration
11171 Set_Is_Public (Id);
11173 end Set_Public_Status;
11175 -----------------------------
11176 -- Set_Referenced_Modified --
11177 -----------------------------
11179 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11183 -- Deal with indexed or selected component where prefix is modified
11185 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11186 Pref := Prefix (N);
11188 -- If prefix is access type, then it is the designated object that is
11189 -- being modified, which means we have no entity to set the flag on.
11191 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11194 -- Otherwise chase the prefix
11197 Set_Referenced_Modified (Pref, Out_Param);
11200 -- Otherwise see if we have an entity name (only other case to process)
11202 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11203 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11204 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11206 end Set_Referenced_Modified;
11208 ----------------------------
11209 -- Set_Scope_Is_Transient --
11210 ----------------------------
11212 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11214 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11215 end Set_Scope_Is_Transient;
11217 -------------------
11218 -- Set_Size_Info --
11219 -------------------
11221 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11223 -- We copy Esize, but not RM_Size, since in general RM_Size is
11224 -- subtype specific and does not get inherited by all subtypes.
11226 Set_Esize (T1, Esize (T2));
11227 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11229 if Is_Discrete_Or_Fixed_Point_Type (T1)
11231 Is_Discrete_Or_Fixed_Point_Type (T2)
11233 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11236 Set_Alignment (T1, Alignment (T2));
11239 --------------------
11240 -- Static_Boolean --
11241 --------------------
11243 function Static_Boolean (N : Node_Id) return Uint is
11245 Analyze_And_Resolve (N, Standard_Boolean);
11248 or else Error_Posted (N)
11249 or else Etype (N) = Any_Type
11254 if Is_Static_Expression (N) then
11255 if not Raises_Constraint_Error (N) then
11256 return Expr_Value (N);
11261 elsif Etype (N) = Any_Type then
11265 Flag_Non_Static_Expr
11266 ("static boolean expression required here", N);
11269 end Static_Boolean;
11271 --------------------
11272 -- Static_Integer --
11273 --------------------
11275 function Static_Integer (N : Node_Id) return Uint is
11277 Analyze_And_Resolve (N, Any_Integer);
11280 or else Error_Posted (N)
11281 or else Etype (N) = Any_Type
11286 if Is_Static_Expression (N) then
11287 if not Raises_Constraint_Error (N) then
11288 return Expr_Value (N);
11293 elsif Etype (N) = Any_Type then
11297 Flag_Non_Static_Expr
11298 ("static integer expression required here", N);
11301 end Static_Integer;
11303 --------------------------
11304 -- Statically_Different --
11305 --------------------------
11307 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11308 R1 : constant Node_Id := Get_Referenced_Object (E1);
11309 R2 : constant Node_Id := Get_Referenced_Object (E2);
11311 return Is_Entity_Name (R1)
11312 and then Is_Entity_Name (R2)
11313 and then Entity (R1) /= Entity (R2)
11314 and then not Is_Formal (Entity (R1))
11315 and then not Is_Formal (Entity (R2));
11316 end Statically_Different;
11318 -----------------------------
11319 -- Subprogram_Access_Level --
11320 -----------------------------
11322 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11324 if Present (Alias (Subp)) then
11325 return Subprogram_Access_Level (Alias (Subp));
11327 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11329 end Subprogram_Access_Level;
11335 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11337 if Debug_Flag_W then
11338 for J in 0 .. Scope_Stack.Last loop
11343 Write_Name (Chars (E));
11344 Write_Str (" from ");
11345 Write_Location (Sloc (N));
11350 -----------------------
11351 -- Transfer_Entities --
11352 -----------------------
11354 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11355 Ent : Entity_Id := First_Entity (From);
11362 if (Last_Entity (To)) = Empty then
11363 Set_First_Entity (To, Ent);
11365 Set_Next_Entity (Last_Entity (To), Ent);
11368 Set_Last_Entity (To, Last_Entity (From));
11370 while Present (Ent) loop
11371 Set_Scope (Ent, To);
11373 if not Is_Public (Ent) then
11374 Set_Public_Status (Ent);
11377 and then Ekind (Ent) = E_Record_Subtype
11380 -- The components of the propagated Itype must be public
11386 Comp := First_Entity (Ent);
11387 while Present (Comp) loop
11388 Set_Is_Public (Comp);
11389 Next_Entity (Comp);
11398 Set_First_Entity (From, Empty);
11399 Set_Last_Entity (From, Empty);
11400 end Transfer_Entities;
11402 -----------------------
11403 -- Type_Access_Level --
11404 -----------------------
11406 function Type_Access_Level (Typ : Entity_Id) return Uint is
11410 Btyp := Base_Type (Typ);
11412 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11413 -- simply use the level where the type is declared. This is true for
11414 -- stand-alone object declarations, and for anonymous access types
11415 -- associated with components the level is the same as that of the
11416 -- enclosing composite type. However, special treatment is needed for
11417 -- the cases of access parameters, return objects of an anonymous access
11418 -- type, and, in Ada 95, access discriminants of limited types.
11420 if Ekind (Btyp) in Access_Kind then
11421 if Ekind (Btyp) = E_Anonymous_Access_Type then
11423 -- If the type is a nonlocal anonymous access type (such as for
11424 -- an access parameter) we treat it as being declared at the
11425 -- library level to ensure that names such as X.all'access don't
11426 -- fail static accessibility checks.
11428 if not Is_Local_Anonymous_Access (Typ) then
11429 return Scope_Depth (Standard_Standard);
11431 -- If this is a return object, the accessibility level is that of
11432 -- the result subtype of the enclosing function. The test here is
11433 -- little complicated, because we have to account for extended
11434 -- return statements that have been rewritten as blocks, in which
11435 -- case we have to find and the Is_Return_Object attribute of the
11436 -- itype's associated object. It would be nice to find a way to
11437 -- simplify this test, but it doesn't seem worthwhile to add a new
11438 -- flag just for purposes of this test. ???
11440 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11443 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11444 N_Object_Declaration
11445 and then Is_Return_Object
11446 (Defining_Identifier
11447 (Associated_Node_For_Itype (Btyp))))
11453 Scop := Scope (Scope (Btyp));
11454 while Present (Scop) loop
11455 exit when Ekind (Scop) = E_Function;
11456 Scop := Scope (Scop);
11459 -- Treat the return object's type as having the level of the
11460 -- function's result subtype (as per RM05-6.5(5.3/2)).
11462 return Type_Access_Level (Etype (Scop));
11467 Btyp := Root_Type (Btyp);
11469 -- The accessibility level of anonymous access types associated with
11470 -- discriminants is that of the current instance of the type, and
11471 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11473 -- AI-402: access discriminants have accessibility based on the
11474 -- object rather than the type in Ada 2005, so the above paragraph
11477 -- ??? Needs completion with rules from AI-416
11479 if Ada_Version <= Ada_95
11480 and then Ekind (Typ) = E_Anonymous_Access_Type
11481 and then Present (Associated_Node_For_Itype (Typ))
11482 and then Nkind (Associated_Node_For_Itype (Typ)) =
11483 N_Discriminant_Specification
11485 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11489 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11490 end Type_Access_Level;
11492 --------------------------
11493 -- Unit_Declaration_Node --
11494 --------------------------
11496 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11497 N : Node_Id := Parent (Unit_Id);
11500 -- Predefined operators do not have a full function declaration
11502 if Ekind (Unit_Id) = E_Operator then
11506 -- Isn't there some better way to express the following ???
11508 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11509 and then Nkind (N) /= N_Formal_Package_Declaration
11510 and then Nkind (N) /= N_Function_Instantiation
11511 and then Nkind (N) /= N_Generic_Package_Declaration
11512 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11513 and then Nkind (N) /= N_Package_Declaration
11514 and then Nkind (N) /= N_Package_Body
11515 and then Nkind (N) /= N_Package_Instantiation
11516 and then Nkind (N) /= N_Package_Renaming_Declaration
11517 and then Nkind (N) /= N_Procedure_Instantiation
11518 and then Nkind (N) /= N_Protected_Body
11519 and then Nkind (N) /= N_Subprogram_Declaration
11520 and then Nkind (N) /= N_Subprogram_Body
11521 and then Nkind (N) /= N_Subprogram_Body_Stub
11522 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11523 and then Nkind (N) /= N_Task_Body
11524 and then Nkind (N) /= N_Task_Type_Declaration
11525 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11526 and then Nkind (N) not in N_Generic_Renaming_Declaration
11529 pragma Assert (Present (N));
11533 end Unit_Declaration_Node;
11535 ------------------------------
11536 -- Universal_Interpretation --
11537 ------------------------------
11539 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11540 Index : Interp_Index;
11544 -- The argument may be a formal parameter of an operator or subprogram
11545 -- with multiple interpretations, or else an expression for an actual.
11547 if Nkind (Opnd) = N_Defining_Identifier
11548 or else not Is_Overloaded (Opnd)
11550 if Etype (Opnd) = Universal_Integer
11551 or else Etype (Opnd) = Universal_Real
11553 return Etype (Opnd);
11559 Get_First_Interp (Opnd, Index, It);
11560 while Present (It.Typ) loop
11561 if It.Typ = Universal_Integer
11562 or else It.Typ = Universal_Real
11567 Get_Next_Interp (Index, It);
11572 end Universal_Interpretation;
11578 function Unqualify (Expr : Node_Id) return Node_Id is
11580 -- Recurse to handle unlikely case of multiple levels of qualification
11582 if Nkind (Expr) = N_Qualified_Expression then
11583 return Unqualify (Expression (Expr));
11585 -- Normal case, not a qualified expression
11592 -----------------------
11593 -- Visible_Ancestors --
11594 -----------------------
11596 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
11602 pragma Assert (Is_Record_Type (Typ)
11603 and then Is_Tagged_Type (Typ));
11605 -- Collect all the parents and progenitors of Typ. If the full-view of
11606 -- private parents and progenitors is available then it is used to
11607 -- generate the list of visible ancestors; otherwise their partial
11608 -- view is added to the resulting list.
11613 Use_Full_View => True);
11617 Ifaces_List => List_2,
11618 Exclude_Parents => True,
11619 Use_Full_View => True);
11621 -- Join the two lists. Avoid duplications because an interface may
11622 -- simultaneously be parent and progenitor of a type.
11624 Elmt := First_Elmt (List_2);
11625 while Present (Elmt) loop
11626 Append_Unique_Elmt (Node (Elmt), List_1);
11631 end Visible_Ancestors;
11633 ----------------------
11634 -- Within_Init_Proc --
11635 ----------------------
11637 function Within_Init_Proc return Boolean is
11641 S := Current_Scope;
11642 while not Is_Overloadable (S) loop
11643 if S = Standard_Standard then
11650 return Is_Init_Proc (S);
11651 end Within_Init_Proc;
11657 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11658 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11659 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11661 function Has_One_Matching_Field return Boolean;
11662 -- Determines if Expec_Type is a record type with a single component or
11663 -- discriminant whose type matches the found type or is one dimensional
11664 -- array whose component type matches the found type.
11666 ----------------------------
11667 -- Has_One_Matching_Field --
11668 ----------------------------
11670 function Has_One_Matching_Field return Boolean is
11674 if Is_Array_Type (Expec_Type)
11675 and then Number_Dimensions (Expec_Type) = 1
11677 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11681 elsif not Is_Record_Type (Expec_Type) then
11685 E := First_Entity (Expec_Type);
11690 elsif (Ekind (E) /= E_Discriminant
11691 and then Ekind (E) /= E_Component)
11692 or else (Chars (E) = Name_uTag
11693 or else Chars (E) = Name_uParent)
11702 if not Covers (Etype (E), Found_Type) then
11705 elsif Present (Next_Entity (E)) then
11712 end Has_One_Matching_Field;
11714 -- Start of processing for Wrong_Type
11717 -- Don't output message if either type is Any_Type, or if a message
11718 -- has already been posted for this node. We need to do the latter
11719 -- check explicitly (it is ordinarily done in Errout), because we
11720 -- are using ! to force the output of the error messages.
11722 if Expec_Type = Any_Type
11723 or else Found_Type = Any_Type
11724 or else Error_Posted (Expr)
11728 -- In an instance, there is an ongoing problem with completion of
11729 -- type derived from private types. Their structure is what Gigi
11730 -- expects, but the Etype is the parent type rather than the
11731 -- derived private type itself. Do not flag error in this case. The
11732 -- private completion is an entity without a parent, like an Itype.
11733 -- Similarly, full and partial views may be incorrect in the instance.
11734 -- There is no simple way to insure that it is consistent ???
11736 elsif In_Instance then
11737 if Etype (Etype (Expr)) = Etype (Expected_Type)
11739 (Has_Private_Declaration (Expected_Type)
11740 or else Has_Private_Declaration (Etype (Expr)))
11741 and then No (Parent (Expected_Type))
11747 -- An interesting special check. If the expression is parenthesized
11748 -- and its type corresponds to the type of the sole component of the
11749 -- expected record type, or to the component type of the expected one
11750 -- dimensional array type, then assume we have a bad aggregate attempt.
11752 if Nkind (Expr) in N_Subexpr
11753 and then Paren_Count (Expr) /= 0
11754 and then Has_One_Matching_Field
11756 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11758 -- Another special check, if we are looking for a pool-specific access
11759 -- type and we found an E_Access_Attribute_Type, then we have the case
11760 -- of an Access attribute being used in a context which needs a pool-
11761 -- specific type, which is never allowed. The one extra check we make
11762 -- is that the expected designated type covers the Found_Type.
11764 elsif Is_Access_Type (Expec_Type)
11765 and then Ekind (Found_Type) = E_Access_Attribute_Type
11766 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11767 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11769 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11771 Error_Msg_N -- CODEFIX
11772 ("result must be general access type!", Expr);
11773 Error_Msg_NE -- CODEFIX
11774 ("add ALL to }!", Expr, Expec_Type);
11776 -- Another special check, if the expected type is an integer type,
11777 -- but the expression is of type System.Address, and the parent is
11778 -- an addition or subtraction operation whose left operand is the
11779 -- expression in question and whose right operand is of an integral
11780 -- type, then this is an attempt at address arithmetic, so give
11781 -- appropriate message.
11783 elsif Is_Integer_Type (Expec_Type)
11784 and then Is_RTE (Found_Type, RE_Address)
11785 and then (Nkind (Parent (Expr)) = N_Op_Add
11787 Nkind (Parent (Expr)) = N_Op_Subtract)
11788 and then Expr = Left_Opnd (Parent (Expr))
11789 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11792 ("address arithmetic not predefined in package System",
11795 ("\possible missing with/use of System.Storage_Elements",
11799 -- If the expected type is an anonymous access type, as for access
11800 -- parameters and discriminants, the error is on the designated types.
11802 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11803 if Comes_From_Source (Expec_Type) then
11804 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11807 ("expected an access type with designated}",
11808 Expr, Designated_Type (Expec_Type));
11811 if Is_Access_Type (Found_Type)
11812 and then not Comes_From_Source (Found_Type)
11815 ("\\found an access type with designated}!",
11816 Expr, Designated_Type (Found_Type));
11818 if From_With_Type (Found_Type) then
11819 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11820 Error_Msg_Qual_Level := 99;
11821 Error_Msg_NE -- CODEFIX
11822 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11823 Error_Msg_Qual_Level := 0;
11825 Error_Msg_NE ("found}!", Expr, Found_Type);
11829 -- Normal case of one type found, some other type expected
11832 -- If the names of the two types are the same, see if some number
11833 -- of levels of qualification will help. Don't try more than three
11834 -- levels, and if we get to standard, it's no use (and probably
11835 -- represents an error in the compiler) Also do not bother with
11836 -- internal scope names.
11839 Expec_Scope : Entity_Id;
11840 Found_Scope : Entity_Id;
11843 Expec_Scope := Expec_Type;
11844 Found_Scope := Found_Type;
11846 for Levels in Int range 0 .. 3 loop
11847 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11848 Error_Msg_Qual_Level := Levels;
11852 Expec_Scope := Scope (Expec_Scope);
11853 Found_Scope := Scope (Found_Scope);
11855 exit when Expec_Scope = Standard_Standard
11856 or else Found_Scope = Standard_Standard
11857 or else not Comes_From_Source (Expec_Scope)
11858 or else not Comes_From_Source (Found_Scope);
11862 if Is_Record_Type (Expec_Type)
11863 and then Present (Corresponding_Remote_Type (Expec_Type))
11865 Error_Msg_NE ("expected}!", Expr,
11866 Corresponding_Remote_Type (Expec_Type));
11868 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11871 if Is_Entity_Name (Expr)
11872 and then Is_Package_Or_Generic_Package (Entity (Expr))
11874 Error_Msg_N ("\\found package name!", Expr);
11876 elsif Is_Entity_Name (Expr)
11878 (Ekind (Entity (Expr)) = E_Procedure
11880 Ekind (Entity (Expr)) = E_Generic_Procedure)
11882 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11884 ("found procedure name, possibly missing Access attribute!",
11888 ("\\found procedure name instead of function!", Expr);
11891 elsif Nkind (Expr) = N_Function_Call
11892 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11893 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11894 and then No (Parameter_Associations (Expr))
11897 ("found function name, possibly missing Access attribute!",
11900 -- Catch common error: a prefix or infix operator which is not
11901 -- directly visible because the type isn't.
11903 elsif Nkind (Expr) in N_Op
11904 and then Is_Overloaded (Expr)
11905 and then not Is_Immediately_Visible (Expec_Type)
11906 and then not Is_Potentially_Use_Visible (Expec_Type)
11907 and then not In_Use (Expec_Type)
11908 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11911 ("operator of the type is not directly visible!", Expr);
11913 elsif Ekind (Found_Type) = E_Void
11914 and then Present (Parent (Found_Type))
11915 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11917 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11920 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11923 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11924 -- of the same modular type, and (M1 and M2) = 0 was intended.
11926 if Expec_Type = Standard_Boolean
11927 and then Is_Modular_Integer_Type (Found_Type)
11928 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11929 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11932 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11933 L : constant Node_Id := Left_Opnd (Op);
11934 R : constant Node_Id := Right_Opnd (Op);
11936 -- The case for the message is when the left operand of the
11937 -- comparison is the same modular type, or when it is an
11938 -- integer literal (or other universal integer expression),
11939 -- which would have been typed as the modular type if the
11940 -- parens had been there.
11942 if (Etype (L) = Found_Type
11944 Etype (L) = Universal_Integer)
11945 and then Is_Integer_Type (Etype (R))
11948 ("\\possible missing parens for modular operation", Expr);
11953 -- Reset error message qualification indication
11955 Error_Msg_Qual_Level := 0;