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 Genconflieral 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))
169 and then Nkind (Parent (Full_View (Typ)))
170 = N_Full_Type_Declaration
172 Nod := Type_Definition (Parent (Full_View (Typ)));
174 -- If the full-view is not available we cannot do anything else
175 -- here (the source has errors).
181 -- Support for generic formals with interfaces is still missing ???
183 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
188 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
192 elsif Ekind (Typ) = E_Record_Subtype then
193 Nod := Type_Definition (Parent (Etype (Typ)));
195 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
197 -- Recurse, because parent may still be a private extension. Also
198 -- note that the full view of the subtype or the full view of its
199 -- base type may (both) be unavailable.
201 return Abstract_Interface_List (Etype (Typ));
203 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
204 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
205 Nod := Formal_Type_Definition (Parent (Typ));
207 Nod := Type_Definition (Parent (Typ));
211 return Interface_List (Nod);
212 end Abstract_Interface_List;
214 --------------------------------
215 -- Add_Access_Type_To_Process --
216 --------------------------------
218 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
222 Ensure_Freeze_Node (E);
223 L := Access_Types_To_Process (Freeze_Node (E));
227 Set_Access_Types_To_Process (Freeze_Node (E), L);
231 end Add_Access_Type_To_Process;
233 ----------------------------
234 -- Add_Global_Declaration --
235 ----------------------------
237 procedure Add_Global_Declaration (N : Node_Id) is
238 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
241 if No (Declarations (Aux_Node)) then
242 Set_Declarations (Aux_Node, New_List);
245 Append_To (Declarations (Aux_Node), N);
247 end Add_Global_Declaration;
253 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
255 function Addressable (V : Uint) return Boolean is
257 return V = Uint_8 or else
263 function Addressable (V : Int) return Boolean is
271 -----------------------
272 -- Alignment_In_Bits --
273 -----------------------
275 function Alignment_In_Bits (E : Entity_Id) return Uint is
277 return Alignment (E) * System_Storage_Unit;
278 end Alignment_In_Bits;
280 -----------------------------------------
281 -- Apply_Compile_Time_Constraint_Error --
282 -----------------------------------------
284 procedure Apply_Compile_Time_Constraint_Error
287 Reason : RT_Exception_Code;
288 Ent : Entity_Id := Empty;
289 Typ : Entity_Id := Empty;
290 Loc : Source_Ptr := No_Location;
291 Rep : Boolean := True;
292 Warn : Boolean := False)
294 Stat : constant Boolean := Is_Static_Expression (N);
295 R_Stat : constant Node_Id :=
296 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
307 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
313 -- Now we replace the node by an N_Raise_Constraint_Error node
314 -- This does not need reanalyzing, so set it as analyzed now.
317 Set_Analyzed (N, True);
320 Set_Raises_Constraint_Error (N);
322 -- Now deal with possible local raise handling
324 Possible_Local_Raise (N, Standard_Constraint_Error);
326 -- If the original expression was marked as static, the result is
327 -- still marked as static, but the Raises_Constraint_Error flag is
328 -- always set so that further static evaluation is not attempted.
331 Set_Is_Static_Expression (N);
333 end Apply_Compile_Time_Constraint_Error;
335 --------------------------------
336 -- Bad_Predicated_Subtype_Use --
337 --------------------------------
339 procedure Bad_Predicated_Subtype_Use
345 if Has_Predicates (Typ) then
346 if Is_Generic_Actual_Type (Typ) then
347 Error_Msg_FE (Msg & '?', N, Typ);
348 Error_Msg_F ("\Program_Error will be raised at run time?", N);
350 Make_Raise_Program_Error (Sloc (N),
351 Reason => PE_Bad_Predicated_Generic_Type));
354 Error_Msg_FE (Msg, N, Typ);
357 end Bad_Predicated_Subtype_Use;
359 --------------------------
360 -- Build_Actual_Subtype --
361 --------------------------
363 function Build_Actual_Subtype
365 N : Node_Or_Entity_Id) return Node_Id
368 -- Normally Sloc (N), but may point to corresponding body in some cases
370 Constraints : List_Id;
376 Disc_Type : Entity_Id;
382 if Nkind (N) = N_Defining_Identifier then
383 Obj := New_Reference_To (N, Loc);
385 -- If this is a formal parameter of a subprogram declaration, and
386 -- we are compiling the body, we want the declaration for the
387 -- actual subtype to carry the source position of the body, to
388 -- prevent anomalies in gdb when stepping through the code.
390 if Is_Formal (N) then
392 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
394 if Nkind (Decl) = N_Subprogram_Declaration
395 and then Present (Corresponding_Body (Decl))
397 Loc := Sloc (Corresponding_Body (Decl));
406 if Is_Array_Type (T) then
407 Constraints := New_List;
408 for J in 1 .. Number_Dimensions (T) loop
410 -- Build an array subtype declaration with the nominal subtype and
411 -- the bounds of the actual. Add the declaration in front of the
412 -- local declarations for the subprogram, for analysis before any
413 -- reference to the formal in the body.
416 Make_Attribute_Reference (Loc,
418 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
419 Attribute_Name => Name_First,
420 Expressions => New_List (
421 Make_Integer_Literal (Loc, J)));
424 Make_Attribute_Reference (Loc,
426 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
427 Attribute_Name => Name_Last,
428 Expressions => New_List (
429 Make_Integer_Literal (Loc, J)));
431 Append (Make_Range (Loc, Lo, Hi), Constraints);
434 -- If the type has unknown discriminants there is no constrained
435 -- subtype to build. This is never called for a formal or for a
436 -- lhs, so returning the type is ok ???
438 elsif Has_Unknown_Discriminants (T) then
442 Constraints := New_List;
444 -- Type T is a generic derived type, inherit the discriminants from
447 if Is_Private_Type (T)
448 and then No (Full_View (T))
450 -- T was flagged as an error if it was declared as a formal
451 -- derived type with known discriminants. In this case there
452 -- is no need to look at the parent type since T already carries
453 -- its own discriminants.
455 and then not Error_Posted (T)
457 Disc_Type := Etype (Base_Type (T));
462 Discr := First_Discriminant (Disc_Type);
463 while Present (Discr) loop
464 Append_To (Constraints,
465 Make_Selected_Component (Loc,
467 Duplicate_Subexpr_No_Checks (Obj),
468 Selector_Name => New_Occurrence_Of (Discr, Loc)));
469 Next_Discriminant (Discr);
473 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
474 Set_Is_Internal (Subt);
477 Make_Subtype_Declaration (Loc,
478 Defining_Identifier => Subt,
479 Subtype_Indication =>
480 Make_Subtype_Indication (Loc,
481 Subtype_Mark => New_Reference_To (T, Loc),
483 Make_Index_Or_Discriminant_Constraint (Loc,
484 Constraints => Constraints)));
486 Mark_Rewrite_Insertion (Decl);
488 end Build_Actual_Subtype;
490 ---------------------------------------
491 -- Build_Actual_Subtype_Of_Component --
492 ---------------------------------------
494 function Build_Actual_Subtype_Of_Component
496 N : Node_Id) return Node_Id
498 Loc : constant Source_Ptr := Sloc (N);
499 P : constant Node_Id := Prefix (N);
502 Indx_Type : Entity_Id;
504 Deaccessed_T : Entity_Id;
505 -- This is either a copy of T, or if T is an access type, then it is
506 -- the directly designated type of this access type.
508 function Build_Actual_Array_Constraint return List_Id;
509 -- If one or more of the bounds of the component depends on
510 -- discriminants, build actual constraint using the discriminants
513 function Build_Actual_Record_Constraint return List_Id;
514 -- Similar to previous one, for discriminated components constrained
515 -- by the discriminant of the enclosing object.
517 -----------------------------------
518 -- Build_Actual_Array_Constraint --
519 -----------------------------------
521 function Build_Actual_Array_Constraint return List_Id is
522 Constraints : constant List_Id := New_List;
530 Indx := First_Index (Deaccessed_T);
531 while Present (Indx) loop
532 Old_Lo := Type_Low_Bound (Etype (Indx));
533 Old_Hi := Type_High_Bound (Etype (Indx));
535 if Denotes_Discriminant (Old_Lo) then
537 Make_Selected_Component (Loc,
538 Prefix => New_Copy_Tree (P),
539 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
542 Lo := New_Copy_Tree (Old_Lo);
544 -- The new bound will be reanalyzed in the enclosing
545 -- declaration. For literal bounds that come from a type
546 -- declaration, the type of the context must be imposed, so
547 -- insure that analysis will take place. For non-universal
548 -- types this is not strictly necessary.
550 Set_Analyzed (Lo, False);
553 if Denotes_Discriminant (Old_Hi) then
555 Make_Selected_Component (Loc,
556 Prefix => New_Copy_Tree (P),
557 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
560 Hi := New_Copy_Tree (Old_Hi);
561 Set_Analyzed (Hi, False);
564 Append (Make_Range (Loc, Lo, Hi), Constraints);
569 end Build_Actual_Array_Constraint;
571 ------------------------------------
572 -- Build_Actual_Record_Constraint --
573 ------------------------------------
575 function Build_Actual_Record_Constraint return List_Id is
576 Constraints : constant List_Id := New_List;
581 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
582 while Present (D) loop
583 if Denotes_Discriminant (Node (D)) then
584 D_Val := Make_Selected_Component (Loc,
585 Prefix => New_Copy_Tree (P),
586 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
589 D_Val := New_Copy_Tree (Node (D));
592 Append (D_Val, Constraints);
597 end Build_Actual_Record_Constraint;
599 -- Start of processing for Build_Actual_Subtype_Of_Component
602 -- Why the test for Spec_Expression mode here???
604 if In_Spec_Expression then
607 -- More comments for the rest of this body would be good ???
609 elsif Nkind (N) = N_Explicit_Dereference then
610 if Is_Composite_Type (T)
611 and then not Is_Constrained (T)
612 and then not (Is_Class_Wide_Type (T)
613 and then Is_Constrained (Root_Type (T)))
614 and then not Has_Unknown_Discriminants (T)
616 -- If the type of the dereference is already constrained, it is an
619 if Is_Array_Type (Etype (N))
620 and then Is_Constrained (Etype (N))
624 Remove_Side_Effects (P);
625 return Build_Actual_Subtype (T, N);
632 if Ekind (T) = E_Access_Subtype then
633 Deaccessed_T := Designated_Type (T);
638 if Ekind (Deaccessed_T) = E_Array_Subtype then
639 Id := First_Index (Deaccessed_T);
640 while Present (Id) loop
641 Indx_Type := Underlying_Type (Etype (Id));
643 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
645 Denotes_Discriminant (Type_High_Bound (Indx_Type))
647 Remove_Side_Effects (P);
649 Build_Component_Subtype
650 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
656 elsif Is_Composite_Type (Deaccessed_T)
657 and then Has_Discriminants (Deaccessed_T)
658 and then not Has_Unknown_Discriminants (Deaccessed_T)
660 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
661 while Present (D) loop
662 if Denotes_Discriminant (Node (D)) then
663 Remove_Side_Effects (P);
665 Build_Component_Subtype (
666 Build_Actual_Record_Constraint, Loc, Base_Type (T));
673 -- If none of the above, the actual and nominal subtypes are the same
676 end Build_Actual_Subtype_Of_Component;
678 -----------------------------
679 -- Build_Component_Subtype --
680 -----------------------------
682 function Build_Component_Subtype
685 T : Entity_Id) return Node_Id
691 -- Unchecked_Union components do not require component subtypes
693 if Is_Unchecked_Union (T) then
697 Subt := Make_Temporary (Loc, 'S');
698 Set_Is_Internal (Subt);
701 Make_Subtype_Declaration (Loc,
702 Defining_Identifier => Subt,
703 Subtype_Indication =>
704 Make_Subtype_Indication (Loc,
705 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
707 Make_Index_Or_Discriminant_Constraint (Loc,
710 Mark_Rewrite_Insertion (Decl);
712 end Build_Component_Subtype;
714 ---------------------------
715 -- Build_Default_Subtype --
716 ---------------------------
718 function Build_Default_Subtype
720 N : Node_Id) return Entity_Id
722 Loc : constant Source_Ptr := Sloc (N);
726 if not Has_Discriminants (T) or else Is_Constrained (T) then
730 Disc := First_Discriminant (T);
732 if No (Discriminant_Default_Value (Disc)) then
737 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
738 Constraints : constant List_Id := New_List;
742 while Present (Disc) loop
743 Append_To (Constraints,
744 New_Copy_Tree (Discriminant_Default_Value (Disc)));
745 Next_Discriminant (Disc);
749 Make_Subtype_Declaration (Loc,
750 Defining_Identifier => Act,
751 Subtype_Indication =>
752 Make_Subtype_Indication (Loc,
753 Subtype_Mark => New_Occurrence_Of (T, Loc),
755 Make_Index_Or_Discriminant_Constraint (Loc,
756 Constraints => Constraints)));
758 Insert_Action (N, Decl);
762 end Build_Default_Subtype;
764 --------------------------------------------
765 -- Build_Discriminal_Subtype_Of_Component --
766 --------------------------------------------
768 function Build_Discriminal_Subtype_Of_Component
769 (T : Entity_Id) return Node_Id
771 Loc : constant Source_Ptr := Sloc (T);
775 function Build_Discriminal_Array_Constraint return List_Id;
776 -- If one or more of the bounds of the component depends on
777 -- discriminants, build actual constraint using the discriminants
780 function Build_Discriminal_Record_Constraint return List_Id;
781 -- Similar to previous one, for discriminated components constrained
782 -- by the discriminant of the enclosing object.
784 ----------------------------------------
785 -- Build_Discriminal_Array_Constraint --
786 ----------------------------------------
788 function Build_Discriminal_Array_Constraint return List_Id is
789 Constraints : constant List_Id := New_List;
797 Indx := First_Index (T);
798 while Present (Indx) loop
799 Old_Lo := Type_Low_Bound (Etype (Indx));
800 Old_Hi := Type_High_Bound (Etype (Indx));
802 if Denotes_Discriminant (Old_Lo) then
803 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
806 Lo := New_Copy_Tree (Old_Lo);
809 if Denotes_Discriminant (Old_Hi) then
810 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
813 Hi := New_Copy_Tree (Old_Hi);
816 Append (Make_Range (Loc, Lo, Hi), Constraints);
821 end Build_Discriminal_Array_Constraint;
823 -----------------------------------------
824 -- Build_Discriminal_Record_Constraint --
825 -----------------------------------------
827 function Build_Discriminal_Record_Constraint return List_Id is
828 Constraints : constant List_Id := New_List;
833 D := First_Elmt (Discriminant_Constraint (T));
834 while Present (D) loop
835 if Denotes_Discriminant (Node (D)) then
837 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
840 D_Val := New_Copy_Tree (Node (D));
843 Append (D_Val, Constraints);
848 end Build_Discriminal_Record_Constraint;
850 -- Start of processing for Build_Discriminal_Subtype_Of_Component
853 if Ekind (T) = E_Array_Subtype then
854 Id := First_Index (T);
855 while Present (Id) loop
856 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
857 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
859 return Build_Component_Subtype
860 (Build_Discriminal_Array_Constraint, Loc, T);
866 elsif Ekind (T) = E_Record_Subtype
867 and then Has_Discriminants (T)
868 and then not Has_Unknown_Discriminants (T)
870 D := First_Elmt (Discriminant_Constraint (T));
871 while Present (D) loop
872 if Denotes_Discriminant (Node (D)) then
873 return Build_Component_Subtype
874 (Build_Discriminal_Record_Constraint, Loc, T);
881 -- If none of the above, the actual and nominal subtypes are the same
884 end Build_Discriminal_Subtype_Of_Component;
886 ------------------------------
887 -- Build_Elaboration_Entity --
888 ------------------------------
890 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
891 Loc : constant Source_Ptr := Sloc (N);
893 Elab_Ent : Entity_Id;
895 procedure Set_Package_Name (Ent : Entity_Id);
896 -- Given an entity, sets the fully qualified name of the entity in
897 -- Name_Buffer, with components separated by double underscores. This
898 -- is a recursive routine that climbs the scope chain to Standard.
900 ----------------------
901 -- Set_Package_Name --
902 ----------------------
904 procedure Set_Package_Name (Ent : Entity_Id) is
906 if Scope (Ent) /= Standard_Standard then
907 Set_Package_Name (Scope (Ent));
910 Nam : constant String := Get_Name_String (Chars (Ent));
912 Name_Buffer (Name_Len + 1) := '_';
913 Name_Buffer (Name_Len + 2) := '_';
914 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
915 Name_Len := Name_Len + Nam'Length + 2;
919 Get_Name_String (Chars (Ent));
921 end Set_Package_Name;
923 -- Start of processing for Build_Elaboration_Entity
926 -- Ignore if already constructed
928 if Present (Elaboration_Entity (Spec_Id)) then
932 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
933 -- name with dots replaced by double underscore. We have to manually
934 -- construct this name, since it will be elaborated in the outer scope,
935 -- and thus will not have the unit name automatically prepended.
937 Set_Package_Name (Spec_Id);
941 Name_Buffer (Name_Len + 1) := '_';
942 Name_Buffer (Name_Len + 2) := 'E';
943 Name_Len := Name_Len + 2;
945 -- Create elaboration flag
948 Make_Defining_Identifier (Loc, Chars => Name_Find);
949 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
952 Make_Object_Declaration (Loc,
953 Defining_Identifier => Elab_Ent,
955 New_Occurrence_Of (Standard_Boolean, Loc),
957 New_Occurrence_Of (Standard_False, Loc));
959 Push_Scope (Standard_Standard);
960 Add_Global_Declaration (Decl);
963 -- Reset True_Constant indication, since we will indeed assign a value
964 -- to the variable in the binder main. We also kill the Current_Value
965 -- and Last_Assignment fields for the same reason.
967 Set_Is_True_Constant (Elab_Ent, False);
968 Set_Current_Value (Elab_Ent, Empty);
969 Set_Last_Assignment (Elab_Ent, Empty);
971 -- We do not want any further qualification of the name (if we did
972 -- not do this, we would pick up the name of the generic package
973 -- in the case of a library level generic instantiation).
975 Set_Has_Qualified_Name (Elab_Ent);
976 Set_Has_Fully_Qualified_Name (Elab_Ent);
977 end Build_Elaboration_Entity;
979 -----------------------------------
980 -- Cannot_Raise_Constraint_Error --
981 -----------------------------------
983 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
985 if Compile_Time_Known_Value (Expr) then
988 elsif Do_Range_Check (Expr) then
991 elsif Raises_Constraint_Error (Expr) then
999 when N_Expanded_Name =>
1002 when N_Selected_Component =>
1003 return not Do_Discriminant_Check (Expr);
1005 when N_Attribute_Reference =>
1006 if Do_Overflow_Check (Expr) then
1009 elsif No (Expressions (Expr)) then
1017 N := First (Expressions (Expr));
1018 while Present (N) loop
1019 if Cannot_Raise_Constraint_Error (N) then
1030 when N_Type_Conversion =>
1031 if Do_Overflow_Check (Expr)
1032 or else Do_Length_Check (Expr)
1033 or else Do_Tag_Check (Expr)
1038 Cannot_Raise_Constraint_Error (Expression (Expr));
1041 when N_Unchecked_Type_Conversion =>
1042 return Cannot_Raise_Constraint_Error (Expression (Expr));
1045 if Do_Overflow_Check (Expr) then
1049 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1056 if Do_Division_Check (Expr)
1057 or else Do_Overflow_Check (Expr)
1062 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1064 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1083 N_Op_Shift_Right_Arithmetic |
1087 if Do_Overflow_Check (Expr) then
1091 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1093 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1100 end Cannot_Raise_Constraint_Error;
1102 -----------------------------------------
1103 -- Check_Dynamically_Tagged_Expression --
1104 -----------------------------------------
1106 procedure Check_Dynamically_Tagged_Expression
1109 Related_Nod : Node_Id)
1112 pragma Assert (Is_Tagged_Type (Typ));
1114 -- In order to avoid spurious errors when analyzing the expanded code,
1115 -- this check is done only for nodes that come from source and for
1116 -- actuals of generic instantiations.
1118 if (Comes_From_Source (Related_Nod)
1119 or else In_Generic_Actual (Expr))
1120 and then (Is_Class_Wide_Type (Etype (Expr))
1121 or else Is_Dynamically_Tagged (Expr))
1122 and then Is_Tagged_Type (Typ)
1123 and then not Is_Class_Wide_Type (Typ)
1125 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1127 end Check_Dynamically_Tagged_Expression;
1129 --------------------------
1130 -- Check_Fully_Declared --
1131 --------------------------
1133 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1135 if Ekind (T) = E_Incomplete_Type then
1137 -- Ada 2005 (AI-50217): If the type is available through a limited
1138 -- with_clause, verify that its full view has been analyzed.
1140 if From_With_Type (T)
1141 and then Present (Non_Limited_View (T))
1142 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1144 -- The non-limited view is fully declared
1149 ("premature usage of incomplete}", N, First_Subtype (T));
1152 -- Need comments for these tests ???
1154 elsif Has_Private_Component (T)
1155 and then not Is_Generic_Type (Root_Type (T))
1156 and then not In_Spec_Expression
1158 -- Special case: if T is the anonymous type created for a single
1159 -- task or protected object, use the name of the source object.
1161 if Is_Concurrent_Type (T)
1162 and then not Comes_From_Source (T)
1163 and then Nkind (N) = N_Object_Declaration
1165 Error_Msg_NE ("type of& has incomplete component", N,
1166 Defining_Identifier (N));
1170 ("premature usage of incomplete}", N, First_Subtype (T));
1173 end Check_Fully_Declared;
1175 -------------------------
1176 -- Check_Nested_Access --
1177 -------------------------
1179 procedure Check_Nested_Access (Ent : Entity_Id) is
1180 Scop : constant Entity_Id := Current_Scope;
1181 Current_Subp : Entity_Id;
1182 Enclosing : Entity_Id;
1185 -- Currently only enabled for VM back-ends for efficiency, should we
1186 -- enable it more systematically ???
1188 -- Check for Is_Imported needs commenting below ???
1190 if VM_Target /= No_VM
1191 and then (Ekind (Ent) = E_Variable
1193 Ekind (Ent) = E_Constant
1195 Ekind (Ent) = E_Loop_Parameter)
1196 and then Scope (Ent) /= Empty
1197 and then not Is_Library_Level_Entity (Ent)
1198 and then not Is_Imported (Ent)
1200 if Is_Subprogram (Scop)
1201 or else Is_Generic_Subprogram (Scop)
1202 or else Is_Entry (Scop)
1204 Current_Subp := Scop;
1206 Current_Subp := Current_Subprogram;
1209 Enclosing := Enclosing_Subprogram (Ent);
1211 if Enclosing /= Empty
1212 and then Enclosing /= Current_Subp
1214 Set_Has_Up_Level_Access (Ent, True);
1217 end Check_Nested_Access;
1219 ----------------------------
1220 -- Check_Order_Dependence --
1221 ----------------------------
1223 procedure Check_Order_Dependence is
1228 if Ada_Version < Ada_2012 then
1232 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1233 -- calls within a construct have been collected. If one of them is
1234 -- writable and overlaps with another one, evaluation of the enclosing
1235 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1236 -- treated as a warning for now.
1238 for J in 1 .. Actuals_In_Call.Last loop
1239 if Actuals_In_Call.Table (J).Is_Writable then
1240 Act1 := Actuals_In_Call.Table (J).Act;
1242 if Nkind (Act1) = N_Attribute_Reference then
1243 Act1 := Prefix (Act1);
1246 for K in 1 .. Actuals_In_Call.Last loop
1248 Act2 := Actuals_In_Call.Table (K).Act;
1250 if Nkind (Act2) = N_Attribute_Reference then
1251 Act2 := Prefix (Act2);
1254 if Actuals_In_Call.Table (K).Is_Writable
1261 elsif Denotes_Same_Object (Act1, Act2)
1262 and then Parent (Act1) /= Parent (Act2)
1265 ("result may differ if evaluated "
1266 & "after other actual in expression?", Act1);
1273 -- Remove checked actuals from table
1275 Actuals_In_Call.Set_Last (0);
1276 end Check_Order_Dependence;
1278 ------------------------------------------
1279 -- Check_Potentially_Blocking_Operation --
1280 ------------------------------------------
1282 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1286 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1287 -- When pragma Detect_Blocking is active, the run time will raise
1288 -- Program_Error. Here we only issue a warning, since we generally
1289 -- support the use of potentially blocking operations in the absence
1292 -- Indirect blocking through a subprogram call cannot be diagnosed
1293 -- statically without interprocedural analysis, so we do not attempt
1296 S := Scope (Current_Scope);
1297 while Present (S) and then S /= Standard_Standard loop
1298 if Is_Protected_Type (S) then
1300 ("potentially blocking operation in protected operation?", N);
1306 end Check_Potentially_Blocking_Operation;
1308 ------------------------------
1309 -- Check_Unprotected_Access --
1310 ------------------------------
1312 procedure Check_Unprotected_Access
1316 Cont_Encl_Typ : Entity_Id;
1317 Pref_Encl_Typ : Entity_Id;
1319 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1320 -- Check whether Obj is a private component of a protected object.
1321 -- Return the protected type where the component resides, Empty
1324 function Is_Public_Operation return Boolean;
1325 -- Verify that the enclosing operation is callable from outside the
1326 -- protected object, to minimize false positives.
1328 ------------------------------
1329 -- Enclosing_Protected_Type --
1330 ------------------------------
1332 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1334 if Is_Entity_Name (Obj) then
1336 Ent : Entity_Id := Entity (Obj);
1339 -- The object can be a renaming of a private component, use
1340 -- the original record component.
1342 if Is_Prival (Ent) then
1343 Ent := Prival_Link (Ent);
1346 if Is_Protected_Type (Scope (Ent)) then
1352 -- For indexed and selected components, recursively check the prefix
1354 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1355 return Enclosing_Protected_Type (Prefix (Obj));
1357 -- The object does not denote a protected component
1362 end Enclosing_Protected_Type;
1364 -------------------------
1365 -- Is_Public_Operation --
1366 -------------------------
1368 function Is_Public_Operation return Boolean is
1375 and then S /= Pref_Encl_Typ
1377 if Scope (S) = Pref_Encl_Typ then
1378 E := First_Entity (Pref_Encl_Typ);
1380 and then E /= First_Private_Entity (Pref_Encl_Typ)
1393 end Is_Public_Operation;
1395 -- Start of processing for Check_Unprotected_Access
1398 if Nkind (Expr) = N_Attribute_Reference
1399 and then Attribute_Name (Expr) = Name_Unchecked_Access
1401 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1402 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1404 -- Check whether we are trying to export a protected component to a
1405 -- context with an equal or lower access level.
1407 if Present (Pref_Encl_Typ)
1408 and then No (Cont_Encl_Typ)
1409 and then Is_Public_Operation
1410 and then Scope_Depth (Pref_Encl_Typ) >=
1411 Object_Access_Level (Context)
1414 ("?possible unprotected access to protected data", Expr);
1417 end Check_Unprotected_Access;
1423 procedure Check_VMS (Construct : Node_Id) is
1425 if not OpenVMS_On_Target then
1427 ("this construct is allowed only in Open'V'M'S", Construct);
1431 ------------------------
1432 -- Collect_Interfaces --
1433 ------------------------
1435 procedure Collect_Interfaces
1437 Ifaces_List : out Elist_Id;
1438 Exclude_Parents : Boolean := False;
1439 Use_Full_View : Boolean := True)
1441 procedure Collect (Typ : Entity_Id);
1442 -- Subsidiary subprogram used to traverse the whole list
1443 -- of directly and indirectly implemented interfaces
1449 procedure Collect (Typ : Entity_Id) is
1450 Ancestor : Entity_Id;
1458 -- Handle private types
1461 and then Is_Private_Type (Typ)
1462 and then Present (Full_View (Typ))
1464 Full_T := Full_View (Typ);
1467 -- Include the ancestor if we are generating the whole list of
1468 -- abstract interfaces.
1470 if Etype (Full_T) /= Typ
1472 -- Protect the frontend against wrong sources. For example:
1475 -- type A is tagged null record;
1476 -- type B is new A with private;
1477 -- type C is new A with private;
1479 -- type B is new C with null record;
1480 -- type C is new B with null record;
1483 and then Etype (Full_T) /= T
1485 Ancestor := Etype (Full_T);
1488 if Is_Interface (Ancestor)
1489 and then not Exclude_Parents
1491 Append_Unique_Elmt (Ancestor, Ifaces_List);
1495 -- Traverse the graph of ancestor interfaces
1497 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1498 Id := First (Abstract_Interface_List (Full_T));
1499 while Present (Id) loop
1500 Iface := Etype (Id);
1502 -- Protect against wrong uses. For example:
1503 -- type I is interface;
1504 -- type O is tagged null record;
1505 -- type Wrong is new I and O with null record; -- ERROR
1507 if Is_Interface (Iface) then
1509 and then Etype (T) /= T
1510 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1515 Append_Unique_Elmt (Iface, Ifaces_List);
1524 -- Start of processing for Collect_Interfaces
1527 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1528 Ifaces_List := New_Elmt_List;
1530 end Collect_Interfaces;
1532 ----------------------------------
1533 -- Collect_Interface_Components --
1534 ----------------------------------
1536 procedure Collect_Interface_Components
1537 (Tagged_Type : Entity_Id;
1538 Components_List : out Elist_Id)
1540 procedure Collect (Typ : Entity_Id);
1541 -- Subsidiary subprogram used to climb to the parents
1547 procedure Collect (Typ : Entity_Id) is
1548 Tag_Comp : Entity_Id;
1549 Parent_Typ : Entity_Id;
1552 -- Handle private types
1554 if Present (Full_View (Etype (Typ))) then
1555 Parent_Typ := Full_View (Etype (Typ));
1557 Parent_Typ := Etype (Typ);
1560 if Parent_Typ /= Typ
1562 -- Protect the frontend against wrong sources. For example:
1565 -- type A is tagged null record;
1566 -- type B is new A with private;
1567 -- type C is new A with private;
1569 -- type B is new C with null record;
1570 -- type C is new B with null record;
1573 and then Parent_Typ /= Tagged_Type
1575 Collect (Parent_Typ);
1578 -- Collect the components containing tags of secondary dispatch
1581 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1582 while Present (Tag_Comp) loop
1583 pragma Assert (Present (Related_Type (Tag_Comp)));
1584 Append_Elmt (Tag_Comp, Components_List);
1586 Tag_Comp := Next_Tag_Component (Tag_Comp);
1590 -- Start of processing for Collect_Interface_Components
1593 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1594 and then Is_Tagged_Type (Tagged_Type));
1596 Components_List := New_Elmt_List;
1597 Collect (Tagged_Type);
1598 end Collect_Interface_Components;
1600 -----------------------------
1601 -- Collect_Interfaces_Info --
1602 -----------------------------
1604 procedure Collect_Interfaces_Info
1606 Ifaces_List : out Elist_Id;
1607 Components_List : out Elist_Id;
1608 Tags_List : out Elist_Id)
1610 Comps_List : Elist_Id;
1611 Comp_Elmt : Elmt_Id;
1612 Comp_Iface : Entity_Id;
1613 Iface_Elmt : Elmt_Id;
1616 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1617 -- Search for the secondary tag associated with the interface type
1618 -- Iface that is implemented by T.
1624 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1627 if not Is_CPP_Class (T) then
1628 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1630 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1634 and then Is_Tag (Node (ADT))
1635 and then Related_Type (Node (ADT)) /= Iface
1637 -- Skip secondary dispatch table referencing thunks to user
1638 -- defined primitives covered by this interface.
1640 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1643 -- Skip secondary dispatch tables of Ada types
1645 if not Is_CPP_Class (T) then
1647 -- Skip secondary dispatch table referencing thunks to
1648 -- predefined primitives.
1650 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1653 -- Skip secondary dispatch table referencing user-defined
1654 -- primitives covered by this interface.
1656 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1659 -- Skip secondary dispatch table referencing predefined
1662 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1667 pragma Assert (Is_Tag (Node (ADT)));
1671 -- Start of processing for Collect_Interfaces_Info
1674 Collect_Interfaces (T, Ifaces_List);
1675 Collect_Interface_Components (T, Comps_List);
1677 -- Search for the record component and tag associated with each
1678 -- interface type of T.
1680 Components_List := New_Elmt_List;
1681 Tags_List := New_Elmt_List;
1683 Iface_Elmt := First_Elmt (Ifaces_List);
1684 while Present (Iface_Elmt) loop
1685 Iface := Node (Iface_Elmt);
1687 -- Associate the primary tag component and the primary dispatch table
1688 -- with all the interfaces that are parents of T
1690 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1691 Append_Elmt (First_Tag_Component (T), Components_List);
1692 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1694 -- Otherwise search for the tag component and secondary dispatch
1698 Comp_Elmt := First_Elmt (Comps_List);
1699 while Present (Comp_Elmt) loop
1700 Comp_Iface := Related_Type (Node (Comp_Elmt));
1702 if Comp_Iface = Iface
1703 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1705 Append_Elmt (Node (Comp_Elmt), Components_List);
1706 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1710 Next_Elmt (Comp_Elmt);
1712 pragma Assert (Present (Comp_Elmt));
1715 Next_Elmt (Iface_Elmt);
1717 end Collect_Interfaces_Info;
1719 ---------------------
1720 -- Collect_Parents --
1721 ---------------------
1723 procedure Collect_Parents
1725 List : out Elist_Id;
1726 Use_Full_View : Boolean := True)
1728 Current_Typ : Entity_Id := T;
1729 Parent_Typ : Entity_Id;
1732 List := New_Elmt_List;
1734 -- No action if the if the type has no parents
1736 if T = Etype (T) then
1741 Parent_Typ := Etype (Current_Typ);
1743 if Is_Private_Type (Parent_Typ)
1744 and then Present (Full_View (Parent_Typ))
1745 and then Use_Full_View
1747 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1750 Append_Elmt (Parent_Typ, List);
1752 exit when Parent_Typ = Current_Typ;
1753 Current_Typ := Parent_Typ;
1755 end Collect_Parents;
1757 ----------------------------------
1758 -- Collect_Primitive_Operations --
1759 ----------------------------------
1761 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1762 B_Type : constant Entity_Id := Base_Type (T);
1763 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1764 B_Scope : Entity_Id := Scope (B_Type);
1768 Formal_Derived : Boolean := False;
1771 function Match (E : Entity_Id) return Boolean;
1772 -- True if E's base type is B_Type, or E is of an anonymous access type
1773 -- and the base type of its designated type is B_Type.
1779 function Match (E : Entity_Id) return Boolean is
1780 Etyp : Entity_Id := Etype (E);
1783 if Ekind (Etyp) = E_Anonymous_Access_Type then
1784 Etyp := Designated_Type (Etyp);
1787 return Base_Type (Etyp) = B_Type;
1790 -- Start of processing for Collect_Primitive_Operations
1793 -- For tagged types, the primitive operations are collected as they
1794 -- are declared, and held in an explicit list which is simply returned.
1796 if Is_Tagged_Type (B_Type) then
1797 return Primitive_Operations (B_Type);
1799 -- An untagged generic type that is a derived type inherits the
1800 -- primitive operations of its parent type. Other formal types only
1801 -- have predefined operators, which are not explicitly represented.
1803 elsif Is_Generic_Type (B_Type) then
1804 if Nkind (B_Decl) = N_Formal_Type_Declaration
1805 and then Nkind (Formal_Type_Definition (B_Decl))
1806 = N_Formal_Derived_Type_Definition
1808 Formal_Derived := True;
1810 return New_Elmt_List;
1814 Op_List := New_Elmt_List;
1816 if B_Scope = Standard_Standard then
1817 if B_Type = Standard_String then
1818 Append_Elmt (Standard_Op_Concat, Op_List);
1820 elsif B_Type = Standard_Wide_String then
1821 Append_Elmt (Standard_Op_Concatw, Op_List);
1827 elsif (Is_Package_Or_Generic_Package (B_Scope)
1829 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1831 or else Is_Derived_Type (B_Type)
1833 -- The primitive operations appear after the base type, except
1834 -- if the derivation happens within the private part of B_Scope
1835 -- and the type is a private type, in which case both the type
1836 -- and some primitive operations may appear before the base
1837 -- type, and the list of candidates starts after the type.
1839 if In_Open_Scopes (B_Scope)
1840 and then Scope (T) = B_Scope
1841 and then In_Private_Part (B_Scope)
1843 Id := Next_Entity (T);
1845 Id := Next_Entity (B_Type);
1848 while Present (Id) loop
1850 -- Note that generic formal subprograms are not
1851 -- considered to be primitive operations and thus
1852 -- are never inherited.
1854 if Is_Overloadable (Id)
1855 and then Nkind (Parent (Parent (Id)))
1856 not in N_Formal_Subprogram_Declaration
1864 Formal := First_Formal (Id);
1865 while Present (Formal) loop
1866 if Match (Formal) then
1871 Next_Formal (Formal);
1875 -- For a formal derived type, the only primitives are the
1876 -- ones inherited from the parent type. Operations appearing
1877 -- in the package declaration are not primitive for it.
1880 and then (not Formal_Derived
1881 or else Present (Alias (Id)))
1883 -- In the special case of an equality operator aliased to
1884 -- an overriding dispatching equality belonging to the same
1885 -- type, we don't include it in the list of primitives.
1886 -- This avoids inheriting multiple equality operators when
1887 -- deriving from untagged private types whose full type is
1888 -- tagged, which can otherwise cause ambiguities. Note that
1889 -- this should only happen for this kind of untagged parent
1890 -- type, since normally dispatching operations are inherited
1891 -- using the type's Primitive_Operations list.
1893 if Chars (Id) = Name_Op_Eq
1894 and then Is_Dispatching_Operation (Id)
1895 and then Present (Alias (Id))
1896 and then Present (Overridden_Operation (Alias (Id)))
1897 and then Base_Type (Etype (First_Entity (Id))) =
1898 Base_Type (Etype (First_Entity (Alias (Id))))
1902 -- Include the subprogram in the list of primitives
1905 Append_Elmt (Id, Op_List);
1912 -- For a type declared in System, some of its operations may
1913 -- appear in the target-specific extension to System.
1916 and then B_Scope = RTU_Entity (System)
1917 and then Present_System_Aux
1919 B_Scope := System_Aux_Id;
1920 Id := First_Entity (System_Aux_Id);
1926 end Collect_Primitive_Operations;
1928 -----------------------------------
1929 -- Compile_Time_Constraint_Error --
1930 -----------------------------------
1932 function Compile_Time_Constraint_Error
1935 Ent : Entity_Id := Empty;
1936 Loc : Source_Ptr := No_Location;
1937 Warn : Boolean := False) return Node_Id
1939 Msgc : String (1 .. Msg'Length + 2);
1940 -- Copy of message, with room for possible ? and ! at end
1950 -- A static constraint error in an instance body is not a fatal error.
1951 -- we choose to inhibit the message altogether, because there is no
1952 -- obvious node (for now) on which to post it. On the other hand the
1953 -- offending node must be replaced with a constraint_error in any case.
1955 -- No messages are generated if we already posted an error on this node
1957 if not Error_Posted (N) then
1958 if Loc /= No_Location then
1964 Msgc (1 .. Msg'Length) := Msg;
1967 -- Message is a warning, even in Ada 95 case
1969 if Msg (Msg'Last) = '?' then
1972 -- In Ada 83, all messages are warnings. In the private part and
1973 -- the body of an instance, constraint_checks are only warnings.
1974 -- We also make this a warning if the Warn parameter is set.
1977 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1983 elsif In_Instance_Not_Visible then
1988 -- Otherwise we have a real error message (Ada 95 static case)
1989 -- and we make this an unconditional message. Note that in the
1990 -- warning case we do not make the message unconditional, it seems
1991 -- quite reasonable to delete messages like this (about exceptions
1992 -- that will be raised) in dead code.
2000 -- Should we generate a warning? The answer is not quite yes. The
2001 -- very annoying exception occurs in the case of a short circuit
2002 -- operator where the left operand is static and decisive. Climb
2003 -- parents to see if that is the case we have here. Conditional
2004 -- expressions with decisive conditions are a similar situation.
2012 -- And then with False as left operand
2014 if Nkind (P) = N_And_Then
2015 and then Compile_Time_Known_Value (Left_Opnd (P))
2016 and then Is_False (Expr_Value (Left_Opnd (P)))
2021 -- OR ELSE with True as left operand
2023 elsif Nkind (P) = N_Or_Else
2024 and then Compile_Time_Known_Value (Left_Opnd (P))
2025 and then Is_True (Expr_Value (Left_Opnd (P)))
2030 -- Conditional expression
2032 elsif Nkind (P) = N_Conditional_Expression then
2034 Cond : constant Node_Id := First (Expressions (P));
2035 Texp : constant Node_Id := Next (Cond);
2036 Fexp : constant Node_Id := Next (Texp);
2039 if Compile_Time_Known_Value (Cond) then
2041 -- Condition is True and we are in the right operand
2043 if Is_True (Expr_Value (Cond))
2044 and then OldP = Fexp
2049 -- Condition is False and we are in the left operand
2051 elsif Is_False (Expr_Value (Cond))
2052 and then OldP = Texp
2060 -- Special case for component association in aggregates, where
2061 -- we want to keep climbing up to the parent aggregate.
2063 elsif Nkind (P) = N_Component_Association
2064 and then Nkind (Parent (P)) = N_Aggregate
2068 -- Keep going if within subexpression
2071 exit when Nkind (P) not in N_Subexpr;
2076 if Present (Ent) then
2077 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2079 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2083 if Inside_Init_Proc then
2085 ("\?& will be raised for objects of this type",
2086 N, Standard_Constraint_Error, Eloc);
2089 ("\?& will be raised at run time",
2090 N, Standard_Constraint_Error, Eloc);
2095 ("\static expression fails Constraint_Check", Eloc);
2096 Set_Error_Posted (N);
2102 end Compile_Time_Constraint_Error;
2104 -----------------------
2105 -- Conditional_Delay --
2106 -----------------------
2108 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2110 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2111 Set_Has_Delayed_Freeze (New_Ent);
2113 end Conditional_Delay;
2115 -------------------------
2116 -- Copy_Parameter_List --
2117 -------------------------
2119 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2120 Loc : constant Source_Ptr := Sloc (Subp_Id);
2125 if No (First_Formal (Subp_Id)) then
2129 Formal := First_Formal (Subp_Id);
2130 while Present (Formal) loop
2132 (Make_Parameter_Specification (Loc,
2133 Defining_Identifier =>
2134 Make_Defining_Identifier (Sloc (Formal),
2135 Chars => Chars (Formal)),
2136 In_Present => In_Present (Parent (Formal)),
2137 Out_Present => Out_Present (Parent (Formal)),
2139 New_Reference_To (Etype (Formal), Loc),
2141 New_Copy_Tree (Expression (Parent (Formal)))),
2144 Next_Formal (Formal);
2149 end Copy_Parameter_List;
2151 --------------------
2152 -- Current_Entity --
2153 --------------------
2155 -- The currently visible definition for a given identifier is the
2156 -- one most chained at the start of the visibility chain, i.e. the
2157 -- one that is referenced by the Node_Id value of the name of the
2158 -- given identifier.
2160 function Current_Entity (N : Node_Id) return Entity_Id is
2162 return Get_Name_Entity_Id (Chars (N));
2165 -----------------------------
2166 -- Current_Entity_In_Scope --
2167 -----------------------------
2169 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2171 CS : constant Entity_Id := Current_Scope;
2173 Transient_Case : constant Boolean := Scope_Is_Transient;
2176 E := Get_Name_Entity_Id (Chars (N));
2178 and then Scope (E) /= CS
2179 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2185 end Current_Entity_In_Scope;
2191 function Current_Scope return Entity_Id is
2193 if Scope_Stack.Last = -1 then
2194 return Standard_Standard;
2197 C : constant Entity_Id :=
2198 Scope_Stack.Table (Scope_Stack.Last).Entity;
2203 return Standard_Standard;
2209 ------------------------
2210 -- Current_Subprogram --
2211 ------------------------
2213 function Current_Subprogram return Entity_Id is
2214 Scop : constant Entity_Id := Current_Scope;
2216 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2219 return Enclosing_Subprogram (Scop);
2221 end Current_Subprogram;
2223 ---------------------
2224 -- Defining_Entity --
2225 ---------------------
2227 function Defining_Entity (N : Node_Id) return Entity_Id is
2228 K : constant Node_Kind := Nkind (N);
2229 Err : Entity_Id := Empty;
2234 N_Subprogram_Declaration |
2235 N_Abstract_Subprogram_Declaration |
2237 N_Package_Declaration |
2238 N_Subprogram_Renaming_Declaration |
2239 N_Subprogram_Body_Stub |
2240 N_Generic_Subprogram_Declaration |
2241 N_Generic_Package_Declaration |
2242 N_Formal_Subprogram_Declaration
2244 return Defining_Entity (Specification (N));
2247 N_Component_Declaration |
2248 N_Defining_Program_Unit_Name |
2249 N_Discriminant_Specification |
2251 N_Entry_Declaration |
2252 N_Entry_Index_Specification |
2253 N_Exception_Declaration |
2254 N_Exception_Renaming_Declaration |
2255 N_Formal_Object_Declaration |
2256 N_Formal_Package_Declaration |
2257 N_Formal_Type_Declaration |
2258 N_Full_Type_Declaration |
2259 N_Implicit_Label_Declaration |
2260 N_Incomplete_Type_Declaration |
2261 N_Loop_Parameter_Specification |
2262 N_Number_Declaration |
2263 N_Object_Declaration |
2264 N_Object_Renaming_Declaration |
2265 N_Package_Body_Stub |
2266 N_Parameter_Specification |
2267 N_Private_Extension_Declaration |
2268 N_Private_Type_Declaration |
2270 N_Protected_Body_Stub |
2271 N_Protected_Type_Declaration |
2272 N_Single_Protected_Declaration |
2273 N_Single_Task_Declaration |
2274 N_Subtype_Declaration |
2277 N_Task_Type_Declaration
2279 return Defining_Identifier (N);
2282 return Defining_Entity (Proper_Body (N));
2285 N_Function_Instantiation |
2286 N_Function_Specification |
2287 N_Generic_Function_Renaming_Declaration |
2288 N_Generic_Package_Renaming_Declaration |
2289 N_Generic_Procedure_Renaming_Declaration |
2291 N_Package_Instantiation |
2292 N_Package_Renaming_Declaration |
2293 N_Package_Specification |
2294 N_Procedure_Instantiation |
2295 N_Procedure_Specification
2298 Nam : constant Node_Id := Defining_Unit_Name (N);
2301 if Nkind (Nam) in N_Entity then
2304 -- For Error, make up a name and attach to declaration
2305 -- so we can continue semantic analysis
2307 elsif Nam = Error then
2308 Err := Make_Temporary (Sloc (N), 'T');
2309 Set_Defining_Unit_Name (N, Err);
2312 -- If not an entity, get defining identifier
2315 return Defining_Identifier (Nam);
2319 when N_Block_Statement =>
2320 return Entity (Identifier (N));
2323 raise Program_Error;
2326 end Defining_Entity;
2328 --------------------------
2329 -- Denotes_Discriminant --
2330 --------------------------
2332 function Denotes_Discriminant
2334 Check_Concurrent : Boolean := False) return Boolean
2338 if not Is_Entity_Name (N)
2339 or else No (Entity (N))
2346 -- If we are checking for a protected type, the discriminant may have
2347 -- been rewritten as the corresponding discriminal of the original type
2348 -- or of the corresponding concurrent record, depending on whether we
2349 -- are in the spec or body of the protected type.
2351 return Ekind (E) = E_Discriminant
2354 and then Ekind (E) = E_In_Parameter
2355 and then Present (Discriminal_Link (E))
2357 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2359 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2361 end Denotes_Discriminant;
2363 -------------------------
2364 -- Denotes_Same_Object --
2365 -------------------------
2367 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2368 Obj1 : Node_Id := A1;
2369 Obj2 : Node_Id := A2;
2371 procedure Check_Renaming (Obj : in out Node_Id);
2372 -- If an object is a renaming, examine renamed object. If it is a
2373 -- dereference of a variable, or an indexed expression with non-constant
2374 -- indexes, no overlap check can be reported.
2376 --------------------
2377 -- Check_Renaming --
2378 --------------------
2380 procedure Check_Renaming (Obj : in out Node_Id) is
2382 if Is_Entity_Name (Obj)
2383 and then Present (Renamed_Entity (Entity (Obj)))
2385 Obj := Renamed_Entity (Entity (Obj));
2386 if Nkind (Obj) = N_Explicit_Dereference
2387 and then Is_Variable (Prefix (Obj))
2391 elsif Nkind (Obj) = N_Indexed_Component then
2396 Indx := First (Expressions (Obj));
2397 while Present (Indx) loop
2398 if not Is_OK_Static_Expression (Indx) then
2410 -- Start of processing for Denotes_Same_Object
2413 Check_Renaming (Obj1);
2414 Check_Renaming (Obj2);
2422 -- If we have entity names, then must be same entity
2424 if Is_Entity_Name (Obj1) then
2425 if Is_Entity_Name (Obj2) then
2426 return Entity (Obj1) = Entity (Obj2);
2431 -- No match if not same node kind
2433 elsif Nkind (Obj1) /= Nkind (Obj2) then
2436 -- For selected components, must have same prefix and selector
2438 elsif Nkind (Obj1) = N_Selected_Component then
2439 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2441 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2443 -- For explicit dereferences, prefixes must be same
2445 elsif Nkind (Obj1) = N_Explicit_Dereference then
2446 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2448 -- For indexed components, prefixes and all subscripts must be the same
2450 elsif Nkind (Obj1) = N_Indexed_Component then
2451 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2457 Indx1 := First (Expressions (Obj1));
2458 Indx2 := First (Expressions (Obj2));
2459 while Present (Indx1) loop
2461 -- Indexes must denote the same static value or same object
2463 if Is_OK_Static_Expression (Indx1) then
2464 if not Is_OK_Static_Expression (Indx2) then
2467 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2471 elsif not Denotes_Same_Object (Indx1, Indx2) then
2485 -- For slices, prefixes must match and bounds must match
2487 elsif Nkind (Obj1) = N_Slice
2488 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2491 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2494 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2495 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2497 -- Check whether bounds are statically identical. There is no
2498 -- attempt to detect partial overlap of slices.
2500 return Denotes_Same_Object (Lo1, Lo2)
2501 and then Denotes_Same_Object (Hi1, Hi2);
2504 -- Literals will appear as indexes. Isn't this where we should check
2505 -- Known_At_Compile_Time at least if we are generating warnings ???
2507 elsif Nkind (Obj1) = N_Integer_Literal then
2508 return Intval (Obj1) = Intval (Obj2);
2513 end Denotes_Same_Object;
2515 -------------------------
2516 -- Denotes_Same_Prefix --
2517 -------------------------
2519 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2522 if Is_Entity_Name (A1) then
2523 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2524 and then not Is_Access_Type (Etype (A1))
2526 return Denotes_Same_Object (A1, Prefix (A2))
2527 or else Denotes_Same_Prefix (A1, Prefix (A2));
2532 elsif Is_Entity_Name (A2) then
2533 return Denotes_Same_Prefix (A2, A1);
2535 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2537 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2540 Root1, Root2 : Node_Id;
2541 Depth1, Depth2 : Int := 0;
2544 Root1 := Prefix (A1);
2545 while not Is_Entity_Name (Root1) loop
2547 (Root1, N_Selected_Component, N_Indexed_Component)
2551 Root1 := Prefix (Root1);
2554 Depth1 := Depth1 + 1;
2557 Root2 := Prefix (A2);
2558 while not Is_Entity_Name (Root2) loop
2560 (Root2, N_Selected_Component, N_Indexed_Component)
2564 Root2 := Prefix (Root2);
2567 Depth2 := Depth2 + 1;
2570 -- If both have the same depth and they do not denote the same
2571 -- object, they are disjoint and not warning is needed.
2573 if Depth1 = Depth2 then
2576 elsif Depth1 > Depth2 then
2577 Root1 := Prefix (A1);
2578 for I in 1 .. Depth1 - Depth2 - 1 loop
2579 Root1 := Prefix (Root1);
2582 return Denotes_Same_Object (Root1, A2);
2585 Root2 := Prefix (A2);
2586 for I in 1 .. Depth2 - Depth1 - 1 loop
2587 Root2 := Prefix (Root2);
2590 return Denotes_Same_Object (A1, Root2);
2597 end Denotes_Same_Prefix;
2599 ----------------------
2600 -- Denotes_Variable --
2601 ----------------------
2603 function Denotes_Variable (N : Node_Id) return Boolean is
2605 return Is_Variable (N) and then Paren_Count (N) = 0;
2606 end Denotes_Variable;
2608 -----------------------------
2609 -- Depends_On_Discriminant --
2610 -----------------------------
2612 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2617 Get_Index_Bounds (N, L, H);
2618 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2619 end Depends_On_Discriminant;
2621 -------------------------
2622 -- Designate_Same_Unit --
2623 -------------------------
2625 function Designate_Same_Unit
2627 Name2 : Node_Id) return Boolean
2629 K1 : constant Node_Kind := Nkind (Name1);
2630 K2 : constant Node_Kind := Nkind (Name2);
2632 function Prefix_Node (N : Node_Id) return Node_Id;
2633 -- Returns the parent unit name node of a defining program unit name
2634 -- or the prefix if N is a selected component or an expanded name.
2636 function Select_Node (N : Node_Id) return Node_Id;
2637 -- Returns the defining identifier node of a defining program unit
2638 -- name or the selector node if N is a selected component or an
2645 function Prefix_Node (N : Node_Id) return Node_Id is
2647 if Nkind (N) = N_Defining_Program_Unit_Name then
2659 function Select_Node (N : Node_Id) return Node_Id is
2661 if Nkind (N) = N_Defining_Program_Unit_Name then
2662 return Defining_Identifier (N);
2665 return Selector_Name (N);
2669 -- Start of processing for Designate_Next_Unit
2672 if (K1 = N_Identifier or else
2673 K1 = N_Defining_Identifier)
2675 (K2 = N_Identifier or else
2676 K2 = N_Defining_Identifier)
2678 return Chars (Name1) = Chars (Name2);
2681 (K1 = N_Expanded_Name or else
2682 K1 = N_Selected_Component or else
2683 K1 = N_Defining_Program_Unit_Name)
2685 (K2 = N_Expanded_Name or else
2686 K2 = N_Selected_Component or else
2687 K2 = N_Defining_Program_Unit_Name)
2690 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2692 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2697 end Designate_Same_Unit;
2699 --------------------------
2700 -- Enclosing_CPP_Parent --
2701 --------------------------
2703 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2704 Parent_Typ : Entity_Id := Typ;
2707 while not Is_CPP_Class (Parent_Typ)
2708 and then Etype (Parent_Typ) /= Parent_Typ
2710 Parent_Typ := Etype (Parent_Typ);
2712 if Is_Private_Type (Parent_Typ) then
2713 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2717 pragma Assert (Is_CPP_Class (Parent_Typ));
2719 end Enclosing_CPP_Parent;
2721 ----------------------------
2722 -- Enclosing_Generic_Body --
2723 ----------------------------
2725 function Enclosing_Generic_Body
2726 (N : Node_Id) return Node_Id
2734 while Present (P) loop
2735 if Nkind (P) = N_Package_Body
2736 or else Nkind (P) = N_Subprogram_Body
2738 Spec := Corresponding_Spec (P);
2740 if Present (Spec) then
2741 Decl := Unit_Declaration_Node (Spec);
2743 if Nkind (Decl) = N_Generic_Package_Declaration
2744 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2755 end Enclosing_Generic_Body;
2757 ----------------------------
2758 -- Enclosing_Generic_Unit --
2759 ----------------------------
2761 function Enclosing_Generic_Unit
2762 (N : Node_Id) return Node_Id
2770 while Present (P) loop
2771 if Nkind (P) = N_Generic_Package_Declaration
2772 or else Nkind (P) = N_Generic_Subprogram_Declaration
2776 elsif Nkind (P) = N_Package_Body
2777 or else Nkind (P) = N_Subprogram_Body
2779 Spec := Corresponding_Spec (P);
2781 if Present (Spec) then
2782 Decl := Unit_Declaration_Node (Spec);
2784 if Nkind (Decl) = N_Generic_Package_Declaration
2785 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2796 end Enclosing_Generic_Unit;
2798 -------------------------------
2799 -- Enclosing_Lib_Unit_Entity --
2800 -------------------------------
2802 function Enclosing_Lib_Unit_Entity return Entity_Id is
2803 Unit_Entity : Entity_Id;
2806 -- Look for enclosing library unit entity by following scope links.
2807 -- Equivalent to, but faster than indexing through the scope stack.
2809 Unit_Entity := Current_Scope;
2810 while (Present (Scope (Unit_Entity))
2811 and then Scope (Unit_Entity) /= Standard_Standard)
2812 and not Is_Child_Unit (Unit_Entity)
2814 Unit_Entity := Scope (Unit_Entity);
2818 end Enclosing_Lib_Unit_Entity;
2820 -----------------------------
2821 -- Enclosing_Lib_Unit_Node --
2822 -----------------------------
2824 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2825 Current_Node : Node_Id;
2829 while Present (Current_Node)
2830 and then Nkind (Current_Node) /= N_Compilation_Unit
2832 Current_Node := Parent (Current_Node);
2835 if Nkind (Current_Node) /= N_Compilation_Unit then
2839 return Current_Node;
2840 end Enclosing_Lib_Unit_Node;
2842 --------------------------
2843 -- Enclosing_Subprogram --
2844 --------------------------
2846 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2847 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2850 if Dynamic_Scope = Standard_Standard then
2853 elsif Dynamic_Scope = Empty then
2856 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2857 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2859 elsif Ekind (Dynamic_Scope) = E_Block
2860 or else Ekind (Dynamic_Scope) = E_Return_Statement
2862 return Enclosing_Subprogram (Dynamic_Scope);
2864 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2865 return Get_Task_Body_Procedure (Dynamic_Scope);
2867 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2868 and then Present (Full_View (Dynamic_Scope))
2869 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2871 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2873 -- No body is generated if the protected operation is eliminated
2875 elsif Convention (Dynamic_Scope) = Convention_Protected
2876 and then not Is_Eliminated (Dynamic_Scope)
2877 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2879 return Protected_Body_Subprogram (Dynamic_Scope);
2882 return Dynamic_Scope;
2884 end Enclosing_Subprogram;
2886 ------------------------
2887 -- Ensure_Freeze_Node --
2888 ------------------------
2890 procedure Ensure_Freeze_Node (E : Entity_Id) is
2894 if No (Freeze_Node (E)) then
2895 FN := Make_Freeze_Entity (Sloc (E));
2896 Set_Has_Delayed_Freeze (E);
2897 Set_Freeze_Node (E, FN);
2898 Set_Access_Types_To_Process (FN, No_Elist);
2899 Set_TSS_Elist (FN, No_Elist);
2902 end Ensure_Freeze_Node;
2908 procedure Enter_Name (Def_Id : Entity_Id) is
2909 C : constant Entity_Id := Current_Entity (Def_Id);
2910 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2911 S : constant Entity_Id := Current_Scope;
2914 Generate_Definition (Def_Id);
2916 -- Add new name to current scope declarations. Check for duplicate
2917 -- declaration, which may or may not be a genuine error.
2921 -- Case of previous entity entered because of a missing declaration
2922 -- or else a bad subtype indication. Best is to use the new entity,
2923 -- and make the previous one invisible.
2925 if Etype (E) = Any_Type then
2926 Set_Is_Immediately_Visible (E, False);
2928 -- Case of renaming declaration constructed for package instances.
2929 -- if there is an explicit declaration with the same identifier,
2930 -- the renaming is not immediately visible any longer, but remains
2931 -- visible through selected component notation.
2933 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2934 and then not Comes_From_Source (E)
2936 Set_Is_Immediately_Visible (E, False);
2938 -- The new entity may be the package renaming, which has the same
2939 -- same name as a generic formal which has been seen already.
2941 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2942 and then not Comes_From_Source (Def_Id)
2944 Set_Is_Immediately_Visible (E, False);
2946 -- For a fat pointer corresponding to a remote access to subprogram,
2947 -- we use the same identifier as the RAS type, so that the proper
2948 -- name appears in the stub. This type is only retrieved through
2949 -- the RAS type and never by visibility, and is not added to the
2950 -- visibility list (see below).
2952 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2953 and then Present (Corresponding_Remote_Type (Def_Id))
2957 -- A controller component for a type extension overrides the
2958 -- inherited component.
2960 elsif Chars (E) = Name_uController then
2963 -- Case of an implicit operation or derived literal. The new entity
2964 -- hides the implicit one, which is removed from all visibility,
2965 -- i.e. the entity list of its scope, and homonym chain of its name.
2967 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2968 or else Is_Internal (E)
2972 Prev_Vis : Entity_Id;
2973 Decl : constant Node_Id := Parent (E);
2976 -- If E is an implicit declaration, it cannot be the first
2977 -- entity in the scope.
2979 Prev := First_Entity (Current_Scope);
2980 while Present (Prev)
2981 and then Next_Entity (Prev) /= E
2988 -- If E is not on the entity chain of the current scope,
2989 -- it is an implicit declaration in the generic formal
2990 -- part of a generic subprogram. When analyzing the body,
2991 -- the generic formals are visible but not on the entity
2992 -- chain of the subprogram. The new entity will become
2993 -- the visible one in the body.
2996 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3000 Set_Next_Entity (Prev, Next_Entity (E));
3002 if No (Next_Entity (Prev)) then
3003 Set_Last_Entity (Current_Scope, Prev);
3006 if E = Current_Entity (E) then
3010 Prev_Vis := Current_Entity (E);
3011 while Homonym (Prev_Vis) /= E loop
3012 Prev_Vis := Homonym (Prev_Vis);
3016 if Present (Prev_Vis) then
3018 -- Skip E in the visibility chain
3020 Set_Homonym (Prev_Vis, Homonym (E));
3023 Set_Name_Entity_Id (Chars (E), Homonym (E));
3028 -- This section of code could use a comment ???
3030 elsif Present (Etype (E))
3031 and then Is_Concurrent_Type (Etype (E))
3036 -- If the homograph is a protected component renaming, it should not
3037 -- be hiding the current entity. Such renamings are treated as weak
3040 elsif Is_Prival (E) then
3041 Set_Is_Immediately_Visible (E, False);
3043 -- In this case the current entity is a protected component renaming.
3044 -- Perform minimal decoration by setting the scope and return since
3045 -- the prival should not be hiding other visible entities.
3047 elsif Is_Prival (Def_Id) then
3048 Set_Scope (Def_Id, Current_Scope);
3051 -- Analogous to privals, the discriminal generated for an entry index
3052 -- parameter acts as a weak declaration. Perform minimal decoration
3053 -- to avoid bogus errors.
3055 elsif Is_Discriminal (Def_Id)
3056 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3058 Set_Scope (Def_Id, Current_Scope);
3061 -- In the body or private part of an instance, a type extension may
3062 -- introduce a component with the same name as that of an actual. The
3063 -- legality rule is not enforced, but the semantics of the full type
3064 -- with two components of same name are not clear at this point???
3066 elsif In_Instance_Not_Visible then
3069 -- When compiling a package body, some child units may have become
3070 -- visible. They cannot conflict with local entities that hide them.
3072 elsif Is_Child_Unit (E)
3073 and then In_Open_Scopes (Scope (E))
3074 and then not Is_Immediately_Visible (E)
3078 -- Conversely, with front-end inlining we may compile the parent body
3079 -- first, and a child unit subsequently. The context is now the
3080 -- parent spec, and body entities are not visible.
3082 elsif Is_Child_Unit (Def_Id)
3083 and then Is_Package_Body_Entity (E)
3084 and then not In_Package_Body (Current_Scope)
3088 -- Case of genuine duplicate declaration
3091 Error_Msg_Sloc := Sloc (E);
3093 -- If the previous declaration is an incomplete type declaration
3094 -- this may be an attempt to complete it with a private type. The
3095 -- following avoids confusing cascaded errors.
3097 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3098 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3101 ("incomplete type cannot be completed with a private " &
3102 "declaration", Parent (Def_Id));
3103 Set_Is_Immediately_Visible (E, False);
3104 Set_Full_View (E, Def_Id);
3106 -- An inherited component of a record conflicts with a new
3107 -- discriminant. The discriminant is inserted first in the scope,
3108 -- but the error should be posted on it, not on the component.
3110 elsif Ekind (E) = E_Discriminant
3111 and then Present (Scope (Def_Id))
3112 and then Scope (Def_Id) /= Current_Scope
3114 Error_Msg_Sloc := Sloc (Def_Id);
3115 Error_Msg_N ("& conflicts with declaration#", E);
3118 -- If the name of the unit appears in its own context clause, a
3119 -- dummy package with the name has already been created, and the
3120 -- error emitted. Try to continue quietly.
3122 elsif Error_Posted (E)
3123 and then Sloc (E) = No_Location
3124 and then Nkind (Parent (E)) = N_Package_Specification
3125 and then Current_Scope = Standard_Standard
3127 Set_Scope (Def_Id, Current_Scope);
3131 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3133 -- Avoid cascaded messages with duplicate components in
3136 if Ekind_In (E, E_Component, E_Discriminant) then
3141 if Nkind (Parent (Parent (Def_Id))) =
3142 N_Generic_Subprogram_Declaration
3144 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3146 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3149 -- If entity is in standard, then we are in trouble, because it
3150 -- means that we have a library package with a duplicated name.
3151 -- That's hard to recover from, so abort!
3153 if S = Standard_Standard then
3154 raise Unrecoverable_Error;
3156 -- Otherwise we continue with the declaration. Having two
3157 -- identical declarations should not cause us too much trouble!
3165 -- If we fall through, declaration is OK, at least OK enough to continue
3167 -- If Def_Id is a discriminant or a record component we are in the midst
3168 -- of inheriting components in a derived record definition. Preserve
3169 -- their Ekind and Etype.
3171 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3174 -- If a type is already set, leave it alone (happens when a type
3175 -- declaration is reanalyzed following a call to the optimizer).
3177 elsif Present (Etype (Def_Id)) then
3180 -- Otherwise, the kind E_Void insures that premature uses of the entity
3181 -- will be detected. Any_Type insures that no cascaded errors will occur
3184 Set_Ekind (Def_Id, E_Void);
3185 Set_Etype (Def_Id, Any_Type);
3188 -- Inherited discriminants and components in derived record types are
3189 -- immediately visible. Itypes are not.
3191 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3192 or else (No (Corresponding_Remote_Type (Def_Id))
3193 and then not Is_Itype (Def_Id))
3195 Set_Is_Immediately_Visible (Def_Id);
3196 Set_Current_Entity (Def_Id);
3199 Set_Homonym (Def_Id, C);
3200 Append_Entity (Def_Id, S);
3201 Set_Public_Status (Def_Id);
3203 -- Declaring a homonym is not allowed in SPARK or ALFA ...
3205 if Formal_Verification_Mode and then Present (C)
3207 -- ... unless the new declaration is in a subprogram, and the visible
3208 -- declaration is a variable declaration or a parameter specification
3209 -- outside that subprogram.
3212 (Nkind_In (Parent (Parent (Def_Id)), N_Subprogram_Body,
3213 N_Function_Specification,
3214 N_Procedure_Specification)
3216 Nkind_In (Parent (C), N_Object_Declaration,
3217 N_Parameter_Specification))
3219 -- ... or the new declaration is in a package, and the visible
3220 -- declaration occurs outside that package.
3223 Nkind_In (Parent (Parent (Def_Id)), N_Package_Specification,
3226 -- ... or the new declaration is a component declaration in a record
3229 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3231 -- Don't issue error for non-source entities
3233 and then Comes_From_Source (Def_Id)
3234 and then Comes_From_Source (C)
3236 Error_Msg_Sloc := Sloc (C);
3237 Error_Msg_F ("|~~redeclaration of identifier &#", Def_Id);
3240 -- Warn if new entity hides an old one
3242 if Warn_On_Hiding and then Present (C)
3244 -- Don't warn for record components since they always have a well
3245 -- defined scope which does not confuse other uses. Note that in
3246 -- some cases, Ekind has not been set yet.
3248 and then Ekind (C) /= E_Component
3249 and then Ekind (C) /= E_Discriminant
3250 and then Nkind (Parent (C)) /= N_Component_Declaration
3251 and then Ekind (Def_Id) /= E_Component
3252 and then Ekind (Def_Id) /= E_Discriminant
3253 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3255 -- Don't warn for one character variables. It is too common to use
3256 -- such variables as locals and will just cause too many false hits.
3258 and then Length_Of_Name (Chars (C)) /= 1
3260 -- Don't warn for non-source entities
3262 and then Comes_From_Source (C)
3263 and then Comes_From_Source (Def_Id)
3265 -- Don't warn unless entity in question is in extended main source
3267 and then In_Extended_Main_Source_Unit (Def_Id)
3269 -- Finally, the hidden entity must be either immediately visible or
3270 -- use visible (i.e. from a used package).
3273 (Is_Immediately_Visible (C)
3275 Is_Potentially_Use_Visible (C))
3277 Error_Msg_Sloc := Sloc (C);
3278 Error_Msg_N ("declaration hides &#?", Def_Id);
3282 --------------------------
3283 -- Explain_Limited_Type --
3284 --------------------------
3286 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3290 -- For array, component type must be limited
3292 if Is_Array_Type (T) then
3293 Error_Msg_Node_2 := T;
3295 ("\component type& of type& is limited", N, Component_Type (T));
3296 Explain_Limited_Type (Component_Type (T), N);
3298 elsif Is_Record_Type (T) then
3300 -- No need for extra messages if explicit limited record
3302 if Is_Limited_Record (Base_Type (T)) then
3306 -- Otherwise find a limited component. Check only components that
3307 -- come from source, or inherited components that appear in the
3308 -- source of the ancestor.
3310 C := First_Component (T);
3311 while Present (C) loop
3312 if Is_Limited_Type (Etype (C))
3314 (Comes_From_Source (C)
3316 (Present (Original_Record_Component (C))
3318 Comes_From_Source (Original_Record_Component (C))))
3320 Error_Msg_Node_2 := T;
3321 Error_Msg_NE ("\component& of type& has limited type", N, C);
3322 Explain_Limited_Type (Etype (C), N);
3329 -- The type may be declared explicitly limited, even if no component
3330 -- of it is limited, in which case we fall out of the loop.
3333 end Explain_Limited_Type;
3339 procedure Find_Actual
3341 Formal : out Entity_Id;
3344 Parnt : constant Node_Id := Parent (N);
3348 if (Nkind (Parnt) = N_Indexed_Component
3350 Nkind (Parnt) = N_Selected_Component)
3351 and then N = Prefix (Parnt)
3353 Find_Actual (Parnt, Formal, Call);
3356 elsif Nkind (Parnt) = N_Parameter_Association
3357 and then N = Explicit_Actual_Parameter (Parnt)
3359 Call := Parent (Parnt);
3361 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3370 -- If we have a call to a subprogram look for the parameter. Note that
3371 -- we exclude overloaded calls, since we don't know enough to be sure
3372 -- of giving the right answer in this case.
3374 if Is_Entity_Name (Name (Call))
3375 and then Present (Entity (Name (Call)))
3376 and then Is_Overloadable (Entity (Name (Call)))
3377 and then not Is_Overloaded (Name (Call))
3379 -- Fall here if we are definitely a parameter
3381 Actual := First_Actual (Call);
3382 Formal := First_Formal (Entity (Name (Call)));
3383 while Present (Formal) and then Present (Actual) loop
3387 Actual := Next_Actual (Actual);
3388 Formal := Next_Formal (Formal);
3393 -- Fall through here if we did not find matching actual
3399 ---------------------------
3400 -- Find_Body_Discriminal --
3401 ---------------------------
3403 function Find_Body_Discriminal
3404 (Spec_Discriminant : Entity_Id) return Entity_Id
3406 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3408 Tsk : constant Entity_Id :=
3409 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3413 -- Find discriminant of original concurrent type, and use its current
3414 -- discriminal, which is the renaming within the task/protected body.
3416 Disc := First_Discriminant (Tsk);
3417 while Present (Disc) loop
3418 if Chars (Disc) = Chars (Spec_Discriminant) then
3419 return Discriminal (Disc);
3422 Next_Discriminant (Disc);
3425 -- That loop should always succeed in finding a matching entry and
3426 -- returning. Fatal error if not.
3428 raise Program_Error;
3429 end Find_Body_Discriminal;
3431 -------------------------------------
3432 -- Find_Corresponding_Discriminant --
3433 -------------------------------------
3435 function Find_Corresponding_Discriminant
3437 Typ : Entity_Id) return Entity_Id
3439 Par_Disc : Entity_Id;
3440 Old_Disc : Entity_Id;
3441 New_Disc : Entity_Id;
3444 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3446 -- The original type may currently be private, and the discriminant
3447 -- only appear on its full view.
3449 if Is_Private_Type (Scope (Par_Disc))
3450 and then not Has_Discriminants (Scope (Par_Disc))
3451 and then Present (Full_View (Scope (Par_Disc)))
3453 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3455 Old_Disc := First_Discriminant (Scope (Par_Disc));
3458 if Is_Class_Wide_Type (Typ) then
3459 New_Disc := First_Discriminant (Root_Type (Typ));
3461 New_Disc := First_Discriminant (Typ);
3464 while Present (Old_Disc) and then Present (New_Disc) loop
3465 if Old_Disc = Par_Disc then
3468 Next_Discriminant (Old_Disc);
3469 Next_Discriminant (New_Disc);
3473 -- Should always find it
3475 raise Program_Error;
3476 end Find_Corresponding_Discriminant;
3478 --------------------------
3479 -- Find_Overlaid_Entity --
3480 --------------------------
3482 procedure Find_Overlaid_Entity
3484 Ent : out Entity_Id;
3490 -- We are looking for one of the two following forms:
3492 -- for X'Address use Y'Address
3496 -- Const : constant Address := expr;
3498 -- for X'Address use Const;
3500 -- In the second case, the expr is either Y'Address, or recursively a
3501 -- constant that eventually references Y'Address.
3506 if Nkind (N) = N_Attribute_Definition_Clause
3507 and then Chars (N) = Name_Address
3509 Expr := Expression (N);
3511 -- This loop checks the form of the expression for Y'Address,
3512 -- using recursion to deal with intermediate constants.
3515 -- Check for Y'Address
3517 if Nkind (Expr) = N_Attribute_Reference
3518 and then Attribute_Name (Expr) = Name_Address
3520 Expr := Prefix (Expr);
3523 -- Check for Const where Const is a constant entity
3525 elsif Is_Entity_Name (Expr)
3526 and then Ekind (Entity (Expr)) = E_Constant
3528 Expr := Constant_Value (Entity (Expr));
3530 -- Anything else does not need checking
3537 -- This loop checks the form of the prefix for an entity,
3538 -- using recursion to deal with intermediate components.
3541 -- Check for Y where Y is an entity
3543 if Is_Entity_Name (Expr) then
3544 Ent := Entity (Expr);
3547 -- Check for components
3550 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3552 Expr := Prefix (Expr);
3555 -- Anything else does not need checking
3562 end Find_Overlaid_Entity;
3564 -------------------------
3565 -- Find_Parameter_Type --
3566 -------------------------
3568 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3570 if Nkind (Param) /= N_Parameter_Specification then
3573 -- For an access parameter, obtain the type from the formal entity
3574 -- itself, because access to subprogram nodes do not carry a type.
3575 -- Shouldn't we always use the formal entity ???
3577 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3578 return Etype (Defining_Identifier (Param));
3581 return Etype (Parameter_Type (Param));
3583 end Find_Parameter_Type;
3585 -----------------------------
3586 -- Find_Static_Alternative --
3587 -----------------------------
3589 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3590 Expr : constant Node_Id := Expression (N);
3591 Val : constant Uint := Expr_Value (Expr);
3596 Alt := First (Alternatives (N));
3599 if Nkind (Alt) /= N_Pragma then
3600 Choice := First (Discrete_Choices (Alt));
3601 while Present (Choice) loop
3603 -- Others choice, always matches
3605 if Nkind (Choice) = N_Others_Choice then
3608 -- Range, check if value is in the range
3610 elsif Nkind (Choice) = N_Range then
3612 Val >= Expr_Value (Low_Bound (Choice))
3614 Val <= Expr_Value (High_Bound (Choice));
3616 -- Choice is a subtype name. Note that we know it must
3617 -- be a static subtype, since otherwise it would have
3618 -- been diagnosed as illegal.
3620 elsif Is_Entity_Name (Choice)
3621 and then Is_Type (Entity (Choice))
3623 exit Search when Is_In_Range (Expr, Etype (Choice),
3624 Assume_Valid => False);
3626 -- Choice is a subtype indication
3628 elsif Nkind (Choice) = N_Subtype_Indication then
3630 C : constant Node_Id := Constraint (Choice);
3631 R : constant Node_Id := Range_Expression (C);
3635 Val >= Expr_Value (Low_Bound (R))
3637 Val <= Expr_Value (High_Bound (R));
3640 -- Choice is a simple expression
3643 exit Search when Val = Expr_Value (Choice);
3651 pragma Assert (Present (Alt));
3654 -- The above loop *must* terminate by finding a match, since
3655 -- we know the case statement is valid, and the value of the
3656 -- expression is known at compile time. When we fall out of
3657 -- the loop, Alt points to the alternative that we know will
3658 -- be selected at run time.
3661 end Find_Static_Alternative;
3667 function First_Actual (Node : Node_Id) return Node_Id is
3671 if No (Parameter_Associations (Node)) then
3675 N := First (Parameter_Associations (Node));
3677 if Nkind (N) = N_Parameter_Association then
3678 return First_Named_Actual (Node);
3684 -----------------------
3685 -- Gather_Components --
3686 -----------------------
3688 procedure Gather_Components
3690 Comp_List : Node_Id;
3691 Governed_By : List_Id;
3693 Report_Errors : out Boolean)
3697 Discrete_Choice : Node_Id;
3698 Comp_Item : Node_Id;
3700 Discrim : Entity_Id;
3701 Discrim_Name : Node_Id;
3702 Discrim_Value : Node_Id;
3705 Report_Errors := False;
3707 if No (Comp_List) or else Null_Present (Comp_List) then
3710 elsif Present (Component_Items (Comp_List)) then
3711 Comp_Item := First (Component_Items (Comp_List));
3717 while Present (Comp_Item) loop
3719 -- Skip the tag of a tagged record, the interface tags, as well
3720 -- as all items that are not user components (anonymous types,
3721 -- rep clauses, Parent field, controller field).
3723 if Nkind (Comp_Item) = N_Component_Declaration then
3725 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3727 if not Is_Tag (Comp)
3728 and then Chars (Comp) /= Name_uParent
3729 and then Chars (Comp) /= Name_uController
3731 Append_Elmt (Comp, Into);
3739 if No (Variant_Part (Comp_List)) then
3742 Discrim_Name := Name (Variant_Part (Comp_List));
3743 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3746 -- Look for the discriminant that governs this variant part.
3747 -- The discriminant *must* be in the Governed_By List
3749 Assoc := First (Governed_By);
3750 Find_Constraint : loop
3751 Discrim := First (Choices (Assoc));
3752 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3753 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3755 Chars (Corresponding_Discriminant (Entity (Discrim)))
3756 = Chars (Discrim_Name))
3757 or else Chars (Original_Record_Component (Entity (Discrim)))
3758 = Chars (Discrim_Name);
3760 if No (Next (Assoc)) then
3761 if not Is_Constrained (Typ)
3762 and then Is_Derived_Type (Typ)
3763 and then Present (Stored_Constraint (Typ))
3765 -- If the type is a tagged type with inherited discriminants,
3766 -- use the stored constraint on the parent in order to find
3767 -- the values of discriminants that are otherwise hidden by an
3768 -- explicit constraint. Renamed discriminants are handled in
3771 -- If several parent discriminants are renamed by a single
3772 -- discriminant of the derived type, the call to obtain the
3773 -- Corresponding_Discriminant field only retrieves the last
3774 -- of them. We recover the constraint on the others from the
3775 -- Stored_Constraint as well.
3782 D := First_Discriminant (Etype (Typ));
3783 C := First_Elmt (Stored_Constraint (Typ));
3784 while Present (D) and then Present (C) loop
3785 if Chars (Discrim_Name) = Chars (D) then
3786 if Is_Entity_Name (Node (C))
3787 and then Entity (Node (C)) = Entity (Discrim)
3789 -- D is renamed by Discrim, whose value is given in
3796 Make_Component_Association (Sloc (Typ),
3798 (New_Occurrence_Of (D, Sloc (Typ))),
3799 Duplicate_Subexpr_No_Checks (Node (C)));
3801 exit Find_Constraint;
3804 Next_Discriminant (D);
3811 if No (Next (Assoc)) then
3812 Error_Msg_NE (" missing value for discriminant&",
3813 First (Governed_By), Discrim_Name);
3814 Report_Errors := True;
3819 end loop Find_Constraint;
3821 Discrim_Value := Expression (Assoc);
3823 if not Is_OK_Static_Expression (Discrim_Value) then
3825 ("value for discriminant & must be static!",
3826 Discrim_Value, Discrim);
3827 Why_Not_Static (Discrim_Value);
3828 Report_Errors := True;
3832 Search_For_Discriminant_Value : declare
3838 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3841 Find_Discrete_Value : while Present (Variant) loop
3842 Discrete_Choice := First (Discrete_Choices (Variant));
3843 while Present (Discrete_Choice) loop
3845 exit Find_Discrete_Value when
3846 Nkind (Discrete_Choice) = N_Others_Choice;
3848 Get_Index_Bounds (Discrete_Choice, Low, High);
3850 UI_Low := Expr_Value (Low);
3851 UI_High := Expr_Value (High);
3853 exit Find_Discrete_Value when
3854 UI_Low <= UI_Discrim_Value
3856 UI_High >= UI_Discrim_Value;
3858 Next (Discrete_Choice);
3861 Next_Non_Pragma (Variant);
3862 end loop Find_Discrete_Value;
3863 end Search_For_Discriminant_Value;
3865 if No (Variant) then
3867 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3868 Report_Errors := True;
3872 -- If we have found the corresponding choice, recursively add its
3873 -- components to the Into list.
3875 Gather_Components (Empty,
3876 Component_List (Variant), Governed_By, Into, Report_Errors);
3877 end Gather_Components;
3879 ------------------------
3880 -- Get_Actual_Subtype --
3881 ------------------------
3883 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3884 Typ : constant Entity_Id := Etype (N);
3885 Utyp : Entity_Id := Underlying_Type (Typ);
3894 -- If what we have is an identifier that references a subprogram
3895 -- formal, or a variable or constant object, then we get the actual
3896 -- subtype from the referenced entity if one has been built.
3898 if Nkind (N) = N_Identifier
3900 (Is_Formal (Entity (N))
3901 or else Ekind (Entity (N)) = E_Constant
3902 or else Ekind (Entity (N)) = E_Variable)
3903 and then Present (Actual_Subtype (Entity (N)))
3905 return Actual_Subtype (Entity (N));
3907 -- Actual subtype of unchecked union is always itself. We never need
3908 -- the "real" actual subtype. If we did, we couldn't get it anyway
3909 -- because the discriminant is not available. The restrictions on
3910 -- Unchecked_Union are designed to make sure that this is OK.
3912 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3915 -- Here for the unconstrained case, we must find actual subtype
3916 -- No actual subtype is available, so we must build it on the fly.
3918 -- Checking the type, not the underlying type, for constrainedness
3919 -- seems to be necessary. Maybe all the tests should be on the type???
3921 elsif (not Is_Constrained (Typ))
3922 and then (Is_Array_Type (Utyp)
3923 or else (Is_Record_Type (Utyp)
3924 and then Has_Discriminants (Utyp)))
3925 and then not Has_Unknown_Discriminants (Utyp)
3926 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3928 -- Nothing to do if in spec expression (why not???)
3930 if In_Spec_Expression then
3933 elsif Is_Private_Type (Typ)
3934 and then not Has_Discriminants (Typ)
3936 -- If the type has no discriminants, there is no subtype to
3937 -- build, even if the underlying type is discriminated.
3941 -- Else build the actual subtype
3944 Decl := Build_Actual_Subtype (Typ, N);
3945 Atyp := Defining_Identifier (Decl);
3947 -- If Build_Actual_Subtype generated a new declaration then use it
3951 -- The actual subtype is an Itype, so analyze the declaration,
3952 -- but do not attach it to the tree, to get the type defined.
3954 Set_Parent (Decl, N);
3955 Set_Is_Itype (Atyp);
3956 Analyze (Decl, Suppress => All_Checks);
3957 Set_Associated_Node_For_Itype (Atyp, N);
3958 Set_Has_Delayed_Freeze (Atyp, False);
3960 -- We need to freeze the actual subtype immediately. This is
3961 -- needed, because otherwise this Itype will not get frozen
3962 -- at all, and it is always safe to freeze on creation because
3963 -- any associated types must be frozen at this point.
3965 Freeze_Itype (Atyp, N);
3968 -- Otherwise we did not build a declaration, so return original
3975 -- For all remaining cases, the actual subtype is the same as
3976 -- the nominal type.
3981 end Get_Actual_Subtype;
3983 -------------------------------------
3984 -- Get_Actual_Subtype_If_Available --
3985 -------------------------------------
3987 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3988 Typ : constant Entity_Id := Etype (N);
3991 -- If what we have is an identifier that references a subprogram
3992 -- formal, or a variable or constant object, then we get the actual
3993 -- subtype from the referenced entity if one has been built.
3995 if Nkind (N) = N_Identifier
3997 (Is_Formal (Entity (N))
3998 or else Ekind (Entity (N)) = E_Constant
3999 or else Ekind (Entity (N)) = E_Variable)
4000 and then Present (Actual_Subtype (Entity (N)))
4002 return Actual_Subtype (Entity (N));
4004 -- Otherwise the Etype of N is returned unchanged
4009 end Get_Actual_Subtype_If_Available;
4011 -------------------------------
4012 -- Get_Default_External_Name --
4013 -------------------------------
4015 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4017 Get_Decoded_Name_String (Chars (E));
4019 if Opt.External_Name_Imp_Casing = Uppercase then
4020 Set_Casing (All_Upper_Case);
4022 Set_Casing (All_Lower_Case);
4026 Make_String_Literal (Sloc (E),
4027 Strval => String_From_Name_Buffer);
4028 end Get_Default_External_Name;
4030 ---------------------------
4031 -- Get_Enum_Lit_From_Pos --
4032 ---------------------------
4034 function Get_Enum_Lit_From_Pos
4037 Loc : Source_Ptr) return Node_Id
4042 -- In the case where the literal is of type Character, Wide_Character
4043 -- or Wide_Wide_Character or of a type derived from them, there needs
4044 -- to be some special handling since there is no explicit chain of
4045 -- literals to search. Instead, an N_Character_Literal node is created
4046 -- with the appropriate Char_Code and Chars fields.
4048 if Is_Standard_Character_Type (T) then
4049 Set_Character_Literal_Name (UI_To_CC (Pos));
4051 Make_Character_Literal (Loc,
4053 Char_Literal_Value => Pos);
4055 -- For all other cases, we have a complete table of literals, and
4056 -- we simply iterate through the chain of literal until the one
4057 -- with the desired position value is found.
4061 Lit := First_Literal (Base_Type (T));
4062 for J in 1 .. UI_To_Int (Pos) loop
4066 return New_Occurrence_Of (Lit, Loc);
4068 end Get_Enum_Lit_From_Pos;
4070 ------------------------
4071 -- Get_Generic_Entity --
4072 ------------------------
4074 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4075 Ent : constant Entity_Id := Entity (Name (N));
4077 if Present (Renamed_Object (Ent)) then
4078 return Renamed_Object (Ent);
4082 end Get_Generic_Entity;
4084 ----------------------
4085 -- Get_Index_Bounds --
4086 ----------------------
4088 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4089 Kind : constant Node_Kind := Nkind (N);
4093 if Kind = N_Range then
4095 H := High_Bound (N);
4097 elsif Kind = N_Subtype_Indication then
4098 R := Range_Expression (Constraint (N));
4106 L := Low_Bound (Range_Expression (Constraint (N)));
4107 H := High_Bound (Range_Expression (Constraint (N)));
4110 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4111 if Error_Posted (Scalar_Range (Entity (N))) then
4115 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4116 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4119 L := Low_Bound (Scalar_Range (Entity (N)));
4120 H := High_Bound (Scalar_Range (Entity (N)));
4124 -- N is an expression, indicating a range with one value
4129 end Get_Index_Bounds;
4131 ----------------------------------
4132 -- Get_Library_Unit_Name_string --
4133 ----------------------------------
4135 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4136 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4139 Get_Unit_Name_String (Unit_Name_Id);
4141 -- Remove seven last character (" (spec)" or " (body)")
4143 Name_Len := Name_Len - 7;
4144 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4145 end Get_Library_Unit_Name_String;
4147 ------------------------
4148 -- Get_Name_Entity_Id --
4149 ------------------------
4151 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4153 return Entity_Id (Get_Name_Table_Info (Id));
4154 end Get_Name_Entity_Id;
4160 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4162 return Get_Pragma_Id (Pragma_Name (N));
4165 ---------------------------
4166 -- Get_Referenced_Object --
4167 ---------------------------
4169 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4174 while Is_Entity_Name (R)
4175 and then Present (Renamed_Object (Entity (R)))
4177 R := Renamed_Object (Entity (R));
4181 end Get_Referenced_Object;
4183 ------------------------
4184 -- Get_Renamed_Entity --
4185 ------------------------
4187 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4192 while Present (Renamed_Entity (R)) loop
4193 R := Renamed_Entity (R);
4197 end Get_Renamed_Entity;
4199 -------------------------
4200 -- Get_Subprogram_Body --
4201 -------------------------
4203 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4207 Decl := Unit_Declaration_Node (E);
4209 if Nkind (Decl) = N_Subprogram_Body then
4212 -- The below comment is bad, because it is possible for
4213 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4215 else -- Nkind (Decl) = N_Subprogram_Declaration
4217 if Present (Corresponding_Body (Decl)) then
4218 return Unit_Declaration_Node (Corresponding_Body (Decl));
4220 -- Imported subprogram case
4226 end Get_Subprogram_Body;
4228 ---------------------------
4229 -- Get_Subprogram_Entity --
4230 ---------------------------
4232 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4237 if Nkind (Nod) = N_Accept_Statement then
4238 Nam := Entry_Direct_Name (Nod);
4240 -- For an entry call, the prefix of the call is a selected component.
4241 -- Need additional code for internal calls ???
4243 elsif Nkind (Nod) = N_Entry_Call_Statement then
4244 if Nkind (Name (Nod)) = N_Selected_Component then
4245 Nam := Entity (Selector_Name (Name (Nod)));
4254 if Nkind (Nam) = N_Explicit_Dereference then
4255 Proc := Etype (Prefix (Nam));
4256 elsif Is_Entity_Name (Nam) then
4257 Proc := Entity (Nam);
4262 if Is_Object (Proc) then
4263 Proc := Etype (Proc);
4266 if Ekind (Proc) = E_Access_Subprogram_Type then
4267 Proc := Directly_Designated_Type (Proc);
4270 if not Is_Subprogram (Proc)
4271 and then Ekind (Proc) /= E_Subprogram_Type
4277 end Get_Subprogram_Entity;
4279 -----------------------------
4280 -- Get_Task_Body_Procedure --
4281 -----------------------------
4283 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4285 -- Note: A task type may be the completion of a private type with
4286 -- discriminants. When performing elaboration checks on a task
4287 -- declaration, the current view of the type may be the private one,
4288 -- and the procedure that holds the body of the task is held in its
4291 -- This is an odd function, why not have Task_Body_Procedure do
4292 -- the following digging???
4294 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4295 end Get_Task_Body_Procedure;
4297 -----------------------
4298 -- Has_Access_Values --
4299 -----------------------
4301 function Has_Access_Values (T : Entity_Id) return Boolean is
4302 Typ : constant Entity_Id := Underlying_Type (T);
4305 -- Case of a private type which is not completed yet. This can only
4306 -- happen in the case of a generic format type appearing directly, or
4307 -- as a component of the type to which this function is being applied
4308 -- at the top level. Return False in this case, since we certainly do
4309 -- not know that the type contains access types.
4314 elsif Is_Access_Type (Typ) then
4317 elsif Is_Array_Type (Typ) then
4318 return Has_Access_Values (Component_Type (Typ));
4320 elsif Is_Record_Type (Typ) then
4325 -- Loop to Check components
4327 Comp := First_Component_Or_Discriminant (Typ);
4328 while Present (Comp) loop
4330 -- Check for access component, tag field does not count, even
4331 -- though it is implemented internally using an access type.
4333 if Has_Access_Values (Etype (Comp))
4334 and then Chars (Comp) /= Name_uTag
4339 Next_Component_Or_Discriminant (Comp);
4348 end Has_Access_Values;
4350 ------------------------------
4351 -- Has_Compatible_Alignment --
4352 ------------------------------
4354 function Has_Compatible_Alignment
4356 Expr : Node_Id) return Alignment_Result
4358 function Has_Compatible_Alignment_Internal
4361 Default : Alignment_Result) return Alignment_Result;
4362 -- This is the internal recursive function that actually does the work.
4363 -- There is one additional parameter, which says what the result should
4364 -- be if no alignment information is found, and there is no definite
4365 -- indication of compatible alignments. At the outer level, this is set
4366 -- to Unknown, but for internal recursive calls in the case where types
4367 -- are known to be correct, it is set to Known_Compatible.
4369 ---------------------------------------
4370 -- Has_Compatible_Alignment_Internal --
4371 ---------------------------------------
4373 function Has_Compatible_Alignment_Internal
4376 Default : Alignment_Result) return Alignment_Result
4378 Result : Alignment_Result := Known_Compatible;
4379 -- Holds the current status of the result. Note that once a value of
4380 -- Known_Incompatible is set, it is sticky and does not get changed
4381 -- to Unknown (the value in Result only gets worse as we go along,
4384 Offs : Uint := No_Uint;
4385 -- Set to a factor of the offset from the base object when Expr is a
4386 -- selected or indexed component, based on Component_Bit_Offset and
4387 -- Component_Size respectively. A negative value is used to represent
4388 -- a value which is not known at compile time.
4390 procedure Check_Prefix;
4391 -- Checks the prefix recursively in the case where the expression
4392 -- is an indexed or selected component.
4394 procedure Set_Result (R : Alignment_Result);
4395 -- If R represents a worse outcome (unknown instead of known
4396 -- compatible, or known incompatible), then set Result to R.
4402 procedure Check_Prefix is
4404 -- The subtlety here is that in doing a recursive call to check
4405 -- the prefix, we have to decide what to do in the case where we
4406 -- don't find any specific indication of an alignment problem.
4408 -- At the outer level, we normally set Unknown as the result in
4409 -- this case, since we can only set Known_Compatible if we really
4410 -- know that the alignment value is OK, but for the recursive
4411 -- call, in the case where the types match, and we have not
4412 -- specified a peculiar alignment for the object, we are only
4413 -- concerned about suspicious rep clauses, the default case does
4414 -- not affect us, since the compiler will, in the absence of such
4415 -- rep clauses, ensure that the alignment is correct.
4417 if Default = Known_Compatible
4419 (Etype (Obj) = Etype (Expr)
4420 and then (Unknown_Alignment (Obj)
4422 Alignment (Obj) = Alignment (Etype (Obj))))
4425 (Has_Compatible_Alignment_Internal
4426 (Obj, Prefix (Expr), Known_Compatible));
4428 -- In all other cases, we need a full check on the prefix
4432 (Has_Compatible_Alignment_Internal
4433 (Obj, Prefix (Expr), Unknown));
4441 procedure Set_Result (R : Alignment_Result) is
4448 -- Start of processing for Has_Compatible_Alignment_Internal
4451 -- If Expr is a selected component, we must make sure there is no
4452 -- potentially troublesome component clause, and that the record is
4455 if Nkind (Expr) = N_Selected_Component then
4457 -- Packed record always generate unknown alignment
4459 if Is_Packed (Etype (Prefix (Expr))) then
4460 Set_Result (Unknown);
4463 -- Check prefix and component offset
4466 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4468 -- If Expr is an indexed component, we must make sure there is no
4469 -- potentially troublesome Component_Size clause and that the array
4470 -- is not bit-packed.
4472 elsif Nkind (Expr) = N_Indexed_Component then
4474 Typ : constant Entity_Id := Etype (Prefix (Expr));
4475 Ind : constant Node_Id := First_Index (Typ);
4478 -- Bit packed array always generates unknown alignment
4480 if Is_Bit_Packed_Array (Typ) then
4481 Set_Result (Unknown);
4484 -- Check prefix and component offset
4487 Offs := Component_Size (Typ);
4489 -- Small optimization: compute the full offset when possible
4492 and then Offs > Uint_0
4493 and then Present (Ind)
4494 and then Nkind (Ind) = N_Range
4495 and then Compile_Time_Known_Value (Low_Bound (Ind))
4496 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4498 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4499 - Expr_Value (Low_Bound ((Ind))));
4504 -- If we have a null offset, the result is entirely determined by
4505 -- the base object and has already been computed recursively.
4507 if Offs = Uint_0 then
4510 -- Case where we know the alignment of the object
4512 elsif Known_Alignment (Obj) then
4514 ObjA : constant Uint := Alignment (Obj);
4515 ExpA : Uint := No_Uint;
4516 SizA : Uint := No_Uint;
4519 -- If alignment of Obj is 1, then we are always OK
4522 Set_Result (Known_Compatible);
4524 -- Alignment of Obj is greater than 1, so we need to check
4527 -- If we have an offset, see if it is compatible
4529 if Offs /= No_Uint and Offs > Uint_0 then
4530 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4531 Set_Result (Known_Incompatible);
4534 -- See if Expr is an object with known alignment
4536 elsif Is_Entity_Name (Expr)
4537 and then Known_Alignment (Entity (Expr))
4539 ExpA := Alignment (Entity (Expr));
4541 -- Otherwise, we can use the alignment of the type of
4542 -- Expr given that we already checked for
4543 -- discombobulating rep clauses for the cases of indexed
4544 -- and selected components above.
4546 elsif Known_Alignment (Etype (Expr)) then
4547 ExpA := Alignment (Etype (Expr));
4549 -- Otherwise the alignment is unknown
4552 Set_Result (Default);
4555 -- If we got an alignment, see if it is acceptable
4557 if ExpA /= No_Uint and then ExpA < ObjA then
4558 Set_Result (Known_Incompatible);
4561 -- If Expr is not a piece of a larger object, see if size
4562 -- is given. If so, check that it is not too small for the
4563 -- required alignment.
4565 if Offs /= No_Uint then
4568 -- See if Expr is an object with known size
4570 elsif Is_Entity_Name (Expr)
4571 and then Known_Static_Esize (Entity (Expr))
4573 SizA := Esize (Entity (Expr));
4575 -- Otherwise, we check the object size of the Expr type
4577 elsif Known_Static_Esize (Etype (Expr)) then
4578 SizA := Esize (Etype (Expr));
4581 -- If we got a size, see if it is a multiple of the Obj
4582 -- alignment, if not, then the alignment cannot be
4583 -- acceptable, since the size is always a multiple of the
4586 if SizA /= No_Uint then
4587 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4588 Set_Result (Known_Incompatible);
4594 -- If we do not know required alignment, any non-zero offset is a
4595 -- potential problem (but certainly may be OK, so result is unknown).
4597 elsif Offs /= No_Uint then
4598 Set_Result (Unknown);
4600 -- If we can't find the result by direct comparison of alignment
4601 -- values, then there is still one case that we can determine known
4602 -- result, and that is when we can determine that the types are the
4603 -- same, and no alignments are specified. Then we known that the
4604 -- alignments are compatible, even if we don't know the alignment
4605 -- value in the front end.
4607 elsif Etype (Obj) = Etype (Expr) then
4609 -- Types are the same, but we have to check for possible size
4610 -- and alignments on the Expr object that may make the alignment
4611 -- different, even though the types are the same.
4613 if Is_Entity_Name (Expr) then
4615 -- First check alignment of the Expr object. Any alignment less
4616 -- than Maximum_Alignment is worrisome since this is the case
4617 -- where we do not know the alignment of Obj.
4619 if Known_Alignment (Entity (Expr))
4621 UI_To_Int (Alignment (Entity (Expr))) <
4622 Ttypes.Maximum_Alignment
4624 Set_Result (Unknown);
4626 -- Now check size of Expr object. Any size that is not an
4627 -- even multiple of Maximum_Alignment is also worrisome
4628 -- since it may cause the alignment of the object to be less
4629 -- than the alignment of the type.
4631 elsif Known_Static_Esize (Entity (Expr))
4633 (UI_To_Int (Esize (Entity (Expr))) mod
4634 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4637 Set_Result (Unknown);
4639 -- Otherwise same type is decisive
4642 Set_Result (Known_Compatible);
4646 -- Another case to deal with is when there is an explicit size or
4647 -- alignment clause when the types are not the same. If so, then the
4648 -- result is Unknown. We don't need to do this test if the Default is
4649 -- Unknown, since that result will be set in any case.
4651 elsif Default /= Unknown
4652 and then (Has_Size_Clause (Etype (Expr))
4654 Has_Alignment_Clause (Etype (Expr)))
4656 Set_Result (Unknown);
4658 -- If no indication found, set default
4661 Set_Result (Default);
4664 -- Return worst result found
4667 end Has_Compatible_Alignment_Internal;
4669 -- Start of processing for Has_Compatible_Alignment
4672 -- If Obj has no specified alignment, then set alignment from the type
4673 -- alignment. Perhaps we should always do this, but for sure we should
4674 -- do it when there is an address clause since we can do more if the
4675 -- alignment is known.
4677 if Unknown_Alignment (Obj) then
4678 Set_Alignment (Obj, Alignment (Etype (Obj)));
4681 -- Now do the internal call that does all the work
4683 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4684 end Has_Compatible_Alignment;
4686 ----------------------
4687 -- Has_Declarations --
4688 ----------------------
4690 function Has_Declarations (N : Node_Id) return Boolean is
4692 return Nkind_In (Nkind (N), N_Accept_Statement,
4694 N_Compilation_Unit_Aux,
4700 N_Package_Specification);
4701 end Has_Declarations;
4703 -------------------------------------------
4704 -- Has_Discriminant_Dependent_Constraint --
4705 -------------------------------------------
4707 function Has_Discriminant_Dependent_Constraint
4708 (Comp : Entity_Id) return Boolean
4710 Comp_Decl : constant Node_Id := Parent (Comp);
4711 Subt_Indic : constant Node_Id :=
4712 Subtype_Indication (Component_Definition (Comp_Decl));
4717 if Nkind (Subt_Indic) = N_Subtype_Indication then
4718 Constr := Constraint (Subt_Indic);
4720 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4721 Assn := First (Constraints (Constr));
4722 while Present (Assn) loop
4723 case Nkind (Assn) is
4724 when N_Subtype_Indication |
4728 if Depends_On_Discriminant (Assn) then
4732 when N_Discriminant_Association =>
4733 if Depends_On_Discriminant (Expression (Assn)) then
4748 end Has_Discriminant_Dependent_Constraint;
4750 --------------------
4751 -- Has_Infinities --
4752 --------------------
4754 function Has_Infinities (E : Entity_Id) return Boolean is
4757 Is_Floating_Point_Type (E)
4758 and then Nkind (Scalar_Range (E)) = N_Range
4759 and then Includes_Infinities (Scalar_Range (E));
4762 --------------------
4763 -- Has_Interfaces --
4764 --------------------
4766 function Has_Interfaces
4768 Use_Full_View : Boolean := True) return Boolean
4770 Typ : Entity_Id := Base_Type (T);
4773 -- Handle concurrent types
4775 if Is_Concurrent_Type (Typ) then
4776 Typ := Corresponding_Record_Type (Typ);
4779 if not Present (Typ)
4780 or else not Is_Record_Type (Typ)
4781 or else not Is_Tagged_Type (Typ)
4786 -- Handle private types
4789 and then Present (Full_View (Typ))
4791 Typ := Full_View (Typ);
4794 -- Handle concurrent record types
4796 if Is_Concurrent_Record_Type (Typ)
4797 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4803 if Is_Interface (Typ)
4805 (Is_Record_Type (Typ)
4806 and then Present (Interfaces (Typ))
4807 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4812 exit when Etype (Typ) = Typ
4814 -- Handle private types
4816 or else (Present (Full_View (Etype (Typ)))
4817 and then Full_View (Etype (Typ)) = Typ)
4819 -- Protect the frontend against wrong source with cyclic
4822 or else Etype (Typ) = T;
4824 -- Climb to the ancestor type handling private types
4826 if Present (Full_View (Etype (Typ))) then
4827 Typ := Full_View (Etype (Typ));
4836 ------------------------
4837 -- Has_Null_Exclusion --
4838 ------------------------
4840 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4843 when N_Access_Definition |
4844 N_Access_Function_Definition |
4845 N_Access_Procedure_Definition |
4846 N_Access_To_Object_Definition |
4848 N_Derived_Type_Definition |
4849 N_Function_Specification |
4850 N_Subtype_Declaration =>
4851 return Null_Exclusion_Present (N);
4853 when N_Component_Definition |
4854 N_Formal_Object_Declaration |
4855 N_Object_Renaming_Declaration =>
4856 if Present (Subtype_Mark (N)) then
4857 return Null_Exclusion_Present (N);
4858 else pragma Assert (Present (Access_Definition (N)));
4859 return Null_Exclusion_Present (Access_Definition (N));
4862 when N_Discriminant_Specification =>
4863 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4864 return Null_Exclusion_Present (Discriminant_Type (N));
4866 return Null_Exclusion_Present (N);
4869 when N_Object_Declaration =>
4870 if Nkind (Object_Definition (N)) = N_Access_Definition then
4871 return Null_Exclusion_Present (Object_Definition (N));
4873 return Null_Exclusion_Present (N);
4876 when N_Parameter_Specification =>
4877 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4878 return Null_Exclusion_Present (Parameter_Type (N));
4880 return Null_Exclusion_Present (N);
4887 end Has_Null_Exclusion;
4889 ------------------------
4890 -- Has_Null_Extension --
4891 ------------------------
4893 function Has_Null_Extension (T : Entity_Id) return Boolean is
4894 B : constant Entity_Id := Base_Type (T);
4899 if Nkind (Parent (B)) = N_Full_Type_Declaration
4900 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4902 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4904 if Present (Ext) then
4905 if Null_Present (Ext) then
4908 Comps := Component_List (Ext);
4910 -- The null component list is rewritten during analysis to
4911 -- include the parent component. Any other component indicates
4912 -- that the extension was not originally null.
4914 return Null_Present (Comps)
4915 or else No (Next (First (Component_Items (Comps))));
4924 end Has_Null_Extension;
4926 -------------------------------
4927 -- Has_Overriding_Initialize --
4928 -------------------------------
4930 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4931 BT : constant Entity_Id := Base_Type (T);
4935 if Is_Controlled (BT) then
4936 if Is_RTU (Scope (BT), Ada_Finalization) then
4939 elsif Present (Primitive_Operations (BT)) then
4940 P := First_Elmt (Primitive_Operations (BT));
4941 while Present (P) loop
4943 Init : constant Entity_Id := Node (P);
4944 Formal : constant Entity_Id := First_Formal (Init);
4946 if Ekind (Init) = E_Procedure
4947 and then Chars (Init) = Name_Initialize
4948 and then Comes_From_Source (Init)
4949 and then Present (Formal)
4950 and then Etype (Formal) = BT
4951 and then No (Next_Formal (Formal))
4952 and then (Ada_Version < Ada_2012
4953 or else not Null_Present (Parent (Init)))
4963 -- Here if type itself does not have a non-null Initialize operation:
4964 -- check immediate ancestor.
4966 if Is_Derived_Type (BT)
4967 and then Has_Overriding_Initialize (Etype (BT))
4974 end Has_Overriding_Initialize;
4976 --------------------------------------
4977 -- Has_Preelaborable_Initialization --
4978 --------------------------------------
4980 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4983 procedure Check_Components (E : Entity_Id);
4984 -- Check component/discriminant chain, sets Has_PE False if a component
4985 -- or discriminant does not meet the preelaborable initialization rules.
4987 ----------------------
4988 -- Check_Components --
4989 ----------------------
4991 procedure Check_Components (E : Entity_Id) is
4995 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4996 -- Returns True if and only if the expression denoted by N does not
4997 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4999 ---------------------------------
5000 -- Is_Preelaborable_Expression --
5001 ---------------------------------
5003 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5007 Comp_Type : Entity_Id;
5008 Is_Array_Aggr : Boolean;
5011 if Is_Static_Expression (N) then
5014 elsif Nkind (N) = N_Null then
5017 -- Attributes are allowed in general, even if their prefix is a
5018 -- formal type. (It seems that certain attributes known not to be
5019 -- static might not be allowed, but there are no rules to prevent
5022 elsif Nkind (N) = N_Attribute_Reference then
5025 -- The name of a discriminant evaluated within its parent type is
5026 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5027 -- names that denote discriminals as well as discriminants to
5028 -- catch references occurring within init procs.
5030 elsif Is_Entity_Name (N)
5032 (Ekind (Entity (N)) = E_Discriminant
5034 ((Ekind (Entity (N)) = E_Constant
5035 or else Ekind (Entity (N)) = E_In_Parameter)
5036 and then Present (Discriminal_Link (Entity (N)))))
5040 elsif Nkind (N) = N_Qualified_Expression then
5041 return Is_Preelaborable_Expression (Expression (N));
5043 -- For aggregates we have to check that each of the associations
5044 -- is preelaborable.
5046 elsif Nkind (N) = N_Aggregate
5047 or else Nkind (N) = N_Extension_Aggregate
5049 Is_Array_Aggr := Is_Array_Type (Etype (N));
5051 if Is_Array_Aggr then
5052 Comp_Type := Component_Type (Etype (N));
5055 -- Check the ancestor part of extension aggregates, which must
5056 -- be either the name of a type that has preelaborable init or
5057 -- an expression that is preelaborable.
5059 if Nkind (N) = N_Extension_Aggregate then
5061 Anc_Part : constant Node_Id := Ancestor_Part (N);
5064 if Is_Entity_Name (Anc_Part)
5065 and then Is_Type (Entity (Anc_Part))
5067 if not Has_Preelaborable_Initialization
5073 elsif not Is_Preelaborable_Expression (Anc_Part) then
5079 -- Check positional associations
5081 Exp := First (Expressions (N));
5082 while Present (Exp) loop
5083 if not Is_Preelaborable_Expression (Exp) then
5090 -- Check named associations
5092 Assn := First (Component_Associations (N));
5093 while Present (Assn) loop
5094 Choice := First (Choices (Assn));
5095 while Present (Choice) loop
5096 if Is_Array_Aggr then
5097 if Nkind (Choice) = N_Others_Choice then
5100 elsif Nkind (Choice) = N_Range then
5101 if not Is_Static_Range (Choice) then
5105 elsif not Is_Static_Expression (Choice) then
5110 Comp_Type := Etype (Choice);
5116 -- If the association has a <> at this point, then we have
5117 -- to check whether the component's type has preelaborable
5118 -- initialization. Note that this only occurs when the
5119 -- association's corresponding component does not have a
5120 -- default expression, the latter case having already been
5121 -- expanded as an expression for the association.
5123 if Box_Present (Assn) then
5124 if not Has_Preelaborable_Initialization (Comp_Type) then
5128 -- In the expression case we check whether the expression
5129 -- is preelaborable.
5132 not Is_Preelaborable_Expression (Expression (Assn))
5140 -- If we get here then aggregate as a whole is preelaborable
5144 -- All other cases are not preelaborable
5149 end Is_Preelaborable_Expression;
5151 -- Start of processing for Check_Components
5154 -- Loop through entities of record or protected type
5157 while Present (Ent) loop
5159 -- We are interested only in components and discriminants
5166 -- Get default expression if any. If there is no declaration
5167 -- node, it means we have an internal entity. The parent and
5168 -- tag fields are examples of such entities. For such cases,
5169 -- we just test the type of the entity.
5171 if Present (Declaration_Node (Ent)) then
5172 Exp := Expression (Declaration_Node (Ent));
5175 when E_Discriminant =>
5177 -- Note: for a renamed discriminant, the Declaration_Node
5178 -- may point to the one from the ancestor, and have a
5179 -- different expression, so use the proper attribute to
5180 -- retrieve the expression from the derived constraint.
5182 Exp := Discriminant_Default_Value (Ent);
5185 goto Check_Next_Entity;
5188 -- A component has PI if it has no default expression and the
5189 -- component type has PI.
5192 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5197 -- Require the default expression to be preelaborable
5199 elsif not Is_Preelaborable_Expression (Exp) then
5204 <<Check_Next_Entity>>
5207 end Check_Components;
5209 -- Start of processing for Has_Preelaborable_Initialization
5212 -- Immediate return if already marked as known preelaborable init. This
5213 -- covers types for which this function has already been called once
5214 -- and returned True (in which case the result is cached), and also
5215 -- types to which a pragma Preelaborable_Initialization applies.
5217 if Known_To_Have_Preelab_Init (E) then
5221 -- If the type is a subtype representing a generic actual type, then
5222 -- test whether its base type has preelaborable initialization since
5223 -- the subtype representing the actual does not inherit this attribute
5224 -- from the actual or formal. (but maybe it should???)
5226 if Is_Generic_Actual_Type (E) then
5227 return Has_Preelaborable_Initialization (Base_Type (E));
5230 -- All elementary types have preelaborable initialization
5232 if Is_Elementary_Type (E) then
5235 -- Array types have PI if the component type has PI
5237 elsif Is_Array_Type (E) then
5238 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5240 -- A derived type has preelaborable initialization if its parent type
5241 -- has preelaborable initialization and (in the case of a derived record
5242 -- extension) if the non-inherited components all have preelaborable
5243 -- initialization. However, a user-defined controlled type with an
5244 -- overriding Initialize procedure does not have preelaborable
5247 elsif Is_Derived_Type (E) then
5249 -- If the derived type is a private extension then it doesn't have
5250 -- preelaborable initialization.
5252 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5256 -- First check whether ancestor type has preelaborable initialization
5258 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5260 -- If OK, check extension components (if any)
5262 if Has_PE and then Is_Record_Type (E) then
5263 Check_Components (First_Entity (E));
5266 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5267 -- with a user defined Initialize procedure does not have PI.
5270 and then Is_Controlled (E)
5271 and then Has_Overriding_Initialize (E)
5276 -- Private types not derived from a type having preelaborable init and
5277 -- that are not marked with pragma Preelaborable_Initialization do not
5278 -- have preelaborable initialization.
5280 elsif Is_Private_Type (E) then
5283 -- Record type has PI if it is non private and all components have PI
5285 elsif Is_Record_Type (E) then
5287 Check_Components (First_Entity (E));
5289 -- Protected types must not have entries, and components must meet
5290 -- same set of rules as for record components.
5292 elsif Is_Protected_Type (E) then
5293 if Has_Entries (E) then
5297 Check_Components (First_Entity (E));
5298 Check_Components (First_Private_Entity (E));
5301 -- Type System.Address always has preelaborable initialization
5303 elsif Is_RTE (E, RE_Address) then
5306 -- In all other cases, type does not have preelaborable initialization
5312 -- If type has preelaborable initialization, cache result
5315 Set_Known_To_Have_Preelab_Init (E);
5319 end Has_Preelaborable_Initialization;
5321 ---------------------------
5322 -- Has_Private_Component --
5323 ---------------------------
5325 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5326 Btype : Entity_Id := Base_Type (Type_Id);
5327 Component : Entity_Id;
5330 if Error_Posted (Type_Id)
5331 or else Error_Posted (Btype)
5336 if Is_Class_Wide_Type (Btype) then
5337 Btype := Root_Type (Btype);
5340 if Is_Private_Type (Btype) then
5342 UT : constant Entity_Id := Underlying_Type (Btype);
5345 if No (Full_View (Btype)) then
5346 return not Is_Generic_Type (Btype)
5347 and then not Is_Generic_Type (Root_Type (Btype));
5349 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5352 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5356 elsif Is_Array_Type (Btype) then
5357 return Has_Private_Component (Component_Type (Btype));
5359 elsif Is_Record_Type (Btype) then
5360 Component := First_Component (Btype);
5361 while Present (Component) loop
5362 if Has_Private_Component (Etype (Component)) then
5366 Next_Component (Component);
5371 elsif Is_Protected_Type (Btype)
5372 and then Present (Corresponding_Record_Type (Btype))
5374 return Has_Private_Component (Corresponding_Record_Type (Btype));
5379 end Has_Private_Component;
5385 function Has_Stream (T : Entity_Id) return Boolean is
5392 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5395 elsif Is_Array_Type (T) then
5396 return Has_Stream (Component_Type (T));
5398 elsif Is_Record_Type (T) then
5399 E := First_Component (T);
5400 while Present (E) loop
5401 if Has_Stream (Etype (E)) then
5410 elsif Is_Private_Type (T) then
5411 return Has_Stream (Underlying_Type (T));
5422 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5424 Get_Name_String (Chars (E));
5425 return Name_Buffer (Name_Len) = Suffix;
5428 --------------------------
5429 -- Has_Tagged_Component --
5430 --------------------------
5432 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5436 if Is_Private_Type (Typ)
5437 and then Present (Underlying_Type (Typ))
5439 return Has_Tagged_Component (Underlying_Type (Typ));
5441 elsif Is_Array_Type (Typ) then
5442 return Has_Tagged_Component (Component_Type (Typ));
5444 elsif Is_Tagged_Type (Typ) then
5447 elsif Is_Record_Type (Typ) then
5448 Comp := First_Component (Typ);
5449 while Present (Comp) loop
5450 if Has_Tagged_Component (Etype (Comp)) then
5454 Next_Component (Comp);
5462 end Has_Tagged_Component;
5464 -------------------------
5465 -- Implementation_Kind --
5466 -------------------------
5468 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5469 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5471 pragma Assert (Present (Impl_Prag));
5473 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5474 end Implementation_Kind;
5476 --------------------------
5477 -- Implements_Interface --
5478 --------------------------
5480 function Implements_Interface
5481 (Typ_Ent : Entity_Id;
5482 Iface_Ent : Entity_Id;
5483 Exclude_Parents : Boolean := False) return Boolean
5485 Ifaces_List : Elist_Id;
5487 Iface : Entity_Id := Base_Type (Iface_Ent);
5488 Typ : Entity_Id := Base_Type (Typ_Ent);
5491 if Is_Class_Wide_Type (Typ) then
5492 Typ := Root_Type (Typ);
5495 if not Has_Interfaces (Typ) then
5499 if Is_Class_Wide_Type (Iface) then
5500 Iface := Root_Type (Iface);
5503 Collect_Interfaces (Typ, Ifaces_List);
5505 Elmt := First_Elmt (Ifaces_List);
5506 while Present (Elmt) loop
5507 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5508 and then Exclude_Parents
5512 elsif Node (Elmt) = Iface then
5520 end Implements_Interface;
5526 function In_Instance return Boolean is
5527 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5533 and then S /= Standard_Standard
5535 if (Ekind (S) = E_Function
5536 or else Ekind (S) = E_Package
5537 or else Ekind (S) = E_Procedure)
5538 and then Is_Generic_Instance (S)
5540 -- A child instance is always compiled in the context of a parent
5541 -- instance. Nevertheless, the actuals are not analyzed in an
5542 -- instance context. We detect this case by examining the current
5543 -- compilation unit, which must be a child instance, and checking
5544 -- that it is not currently on the scope stack.
5546 if Is_Child_Unit (Curr_Unit)
5548 Nkind (Unit (Cunit (Current_Sem_Unit)))
5549 = N_Package_Instantiation
5550 and then not In_Open_Scopes (Curr_Unit)
5564 ----------------------
5565 -- In_Instance_Body --
5566 ----------------------
5568 function In_Instance_Body return Boolean is
5574 and then S /= Standard_Standard
5576 if (Ekind (S) = E_Function
5577 or else Ekind (S) = E_Procedure)
5578 and then Is_Generic_Instance (S)
5582 elsif Ekind (S) = E_Package
5583 and then In_Package_Body (S)
5584 and then Is_Generic_Instance (S)
5593 end In_Instance_Body;
5595 -----------------------------
5596 -- In_Instance_Not_Visible --
5597 -----------------------------
5599 function In_Instance_Not_Visible return Boolean is
5605 and then S /= Standard_Standard
5607 if (Ekind (S) = E_Function
5608 or else Ekind (S) = E_Procedure)
5609 and then Is_Generic_Instance (S)
5613 elsif Ekind (S) = E_Package
5614 and then (In_Package_Body (S) or else In_Private_Part (S))
5615 and then Is_Generic_Instance (S)
5624 end In_Instance_Not_Visible;
5626 ------------------------------
5627 -- In_Instance_Visible_Part --
5628 ------------------------------
5630 function In_Instance_Visible_Part return Boolean is
5636 and then S /= Standard_Standard
5638 if Ekind (S) = E_Package
5639 and then Is_Generic_Instance (S)
5640 and then not In_Package_Body (S)
5641 and then not In_Private_Part (S)
5650 end In_Instance_Visible_Part;
5652 ---------------------
5653 -- In_Package_Body --
5654 ---------------------
5656 function In_Package_Body return Boolean is
5662 and then S /= Standard_Standard
5664 if Ekind (S) = E_Package
5665 and then In_Package_Body (S)
5674 end In_Package_Body;
5676 --------------------------------
5677 -- In_Parameter_Specification --
5678 --------------------------------
5680 function In_Parameter_Specification (N : Node_Id) return Boolean is
5685 while Present (PN) loop
5686 if Nkind (PN) = N_Parameter_Specification then
5694 end In_Parameter_Specification;
5696 --------------------------------------
5697 -- In_Subprogram_Or_Concurrent_Unit --
5698 --------------------------------------
5700 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5705 -- Use scope chain to check successively outer scopes
5711 if K in Subprogram_Kind
5712 or else K in Concurrent_Kind
5713 or else K in Generic_Subprogram_Kind
5717 elsif E = Standard_Standard then
5723 end In_Subprogram_Or_Concurrent_Unit;
5725 ---------------------
5726 -- In_Visible_Part --
5727 ---------------------
5729 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5732 Is_Package_Or_Generic_Package (Scope_Id)
5733 and then In_Open_Scopes (Scope_Id)
5734 and then not In_Package_Body (Scope_Id)
5735 and then not In_Private_Part (Scope_Id);
5736 end In_Visible_Part;
5738 ---------------------------------
5739 -- Insert_Explicit_Dereference --
5740 ---------------------------------
5742 procedure Insert_Explicit_Dereference (N : Node_Id) is
5743 New_Prefix : constant Node_Id := Relocate_Node (N);
5744 Ent : Entity_Id := Empty;
5751 Save_Interps (N, New_Prefix);
5754 Make_Explicit_Dereference (Sloc (Parent (N)),
5755 Prefix => New_Prefix));
5757 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5759 if Is_Overloaded (New_Prefix) then
5761 -- The dereference is also overloaded, and its interpretations are
5762 -- the designated types of the interpretations of the original node.
5764 Set_Etype (N, Any_Type);
5766 Get_First_Interp (New_Prefix, I, It);
5767 while Present (It.Nam) loop
5770 if Is_Access_Type (T) then
5771 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5774 Get_Next_Interp (I, It);
5780 -- Prefix is unambiguous: mark the original prefix (which might
5781 -- Come_From_Source) as a reference, since the new (relocated) one
5782 -- won't be taken into account.
5784 if Is_Entity_Name (New_Prefix) then
5785 Ent := Entity (New_Prefix);
5788 -- For a retrieval of a subcomponent of some composite object,
5789 -- retrieve the ultimate entity if there is one.
5791 elsif Nkind (New_Prefix) = N_Selected_Component
5792 or else Nkind (New_Prefix) = N_Indexed_Component
5794 Pref := Prefix (New_Prefix);
5795 while Present (Pref)
5797 (Nkind (Pref) = N_Selected_Component
5798 or else Nkind (Pref) = N_Indexed_Component)
5800 Pref := Prefix (Pref);
5803 if Present (Pref) and then Is_Entity_Name (Pref) then
5804 Ent := Entity (Pref);
5808 -- Place the reference on the entity node
5810 if Present (Ent) then
5811 Generate_Reference (Ent, Pref);
5814 end Insert_Explicit_Dereference;
5816 ------------------------------------------
5817 -- Inspect_Deferred_Constant_Completion --
5818 ------------------------------------------
5820 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5824 Decl := First (Decls);
5825 while Present (Decl) loop
5827 -- Deferred constant signature
5829 if Nkind (Decl) = N_Object_Declaration
5830 and then Constant_Present (Decl)
5831 and then No (Expression (Decl))
5833 -- No need to check internally generated constants
5835 and then Comes_From_Source (Decl)
5837 -- The constant is not completed. A full object declaration or a
5838 -- pragma Import complete a deferred constant.
5840 and then not Has_Completion (Defining_Identifier (Decl))
5843 ("constant declaration requires initialization expression",
5844 Defining_Identifier (Decl));
5847 Decl := Next (Decl);
5849 end Inspect_Deferred_Constant_Completion;
5851 -----------------------------
5852 -- Is_Actual_Out_Parameter --
5853 -----------------------------
5855 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5859 Find_Actual (N, Formal, Call);
5860 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5861 end Is_Actual_Out_Parameter;
5863 -------------------------
5864 -- Is_Actual_Parameter --
5865 -------------------------
5867 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5868 PK : constant Node_Kind := Nkind (Parent (N));
5872 when N_Parameter_Association =>
5873 return N = Explicit_Actual_Parameter (Parent (N));
5875 when N_Function_Call | N_Procedure_Call_Statement =>
5876 return Is_List_Member (N)
5878 List_Containing (N) = Parameter_Associations (Parent (N));
5883 end Is_Actual_Parameter;
5885 ---------------------
5886 -- Is_Aliased_View --
5887 ---------------------
5889 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5893 if Is_Entity_Name (Obj) then
5901 or else (Present (Renamed_Object (E))
5902 and then Is_Aliased_View (Renamed_Object (E)))))
5904 or else ((Is_Formal (E)
5905 or else Ekind (E) = E_Generic_In_Out_Parameter
5906 or else Ekind (E) = E_Generic_In_Parameter)
5907 and then Is_Tagged_Type (Etype (E)))
5909 or else (Is_Concurrent_Type (E)
5910 and then In_Open_Scopes (E))
5912 -- Current instance of type, either directly or as rewritten
5913 -- reference to the current object.
5915 or else (Is_Entity_Name (Original_Node (Obj))
5916 and then Present (Entity (Original_Node (Obj)))
5917 and then Is_Type (Entity (Original_Node (Obj))))
5919 or else (Is_Type (E) and then E = Current_Scope)
5921 or else (Is_Incomplete_Or_Private_Type (E)
5922 and then Full_View (E) = Current_Scope);
5924 elsif Nkind (Obj) = N_Selected_Component then
5925 return Is_Aliased (Entity (Selector_Name (Obj)));
5927 elsif Nkind (Obj) = N_Indexed_Component then
5928 return Has_Aliased_Components (Etype (Prefix (Obj)))
5930 (Is_Access_Type (Etype (Prefix (Obj)))
5932 Has_Aliased_Components
5933 (Designated_Type (Etype (Prefix (Obj)))));
5935 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5936 or else Nkind (Obj) = N_Type_Conversion
5938 return Is_Tagged_Type (Etype (Obj))
5939 and then Is_Aliased_View (Expression (Obj));
5941 elsif Nkind (Obj) = N_Explicit_Dereference then
5942 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5947 end Is_Aliased_View;
5949 -------------------------
5950 -- Is_Ancestor_Package --
5951 -------------------------
5953 function Is_Ancestor_Package
5955 E2 : Entity_Id) return Boolean
5962 and then Par /= Standard_Standard
5972 end Is_Ancestor_Package;
5974 ----------------------
5975 -- Is_Atomic_Object --
5976 ----------------------
5978 function Is_Atomic_Object (N : Node_Id) return Boolean is
5980 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5981 -- Determines if given object has atomic components
5983 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5984 -- If prefix is an implicit dereference, examine designated type
5986 ----------------------
5987 -- Is_Atomic_Prefix --
5988 ----------------------
5990 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5992 if Is_Access_Type (Etype (N)) then
5994 Has_Atomic_Components (Designated_Type (Etype (N)));
5996 return Object_Has_Atomic_Components (N);
5998 end Is_Atomic_Prefix;
6000 ----------------------------------
6001 -- Object_Has_Atomic_Components --
6002 ----------------------------------
6004 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6006 if Has_Atomic_Components (Etype (N))
6007 or else Is_Atomic (Etype (N))
6011 elsif Is_Entity_Name (N)
6012 and then (Has_Atomic_Components (Entity (N))
6013 or else Is_Atomic (Entity (N)))
6017 elsif Nkind (N) = N_Indexed_Component
6018 or else Nkind (N) = N_Selected_Component
6020 return Is_Atomic_Prefix (Prefix (N));
6025 end Object_Has_Atomic_Components;
6027 -- Start of processing for Is_Atomic_Object
6030 -- Predicate is not relevant to subprograms
6032 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6035 elsif Is_Atomic (Etype (N))
6036 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6040 elsif Nkind (N) = N_Indexed_Component
6041 or else Nkind (N) = N_Selected_Component
6043 return Is_Atomic_Prefix (Prefix (N));
6048 end Is_Atomic_Object;
6050 -------------------------
6051 -- Is_Coextension_Root --
6052 -------------------------
6054 function Is_Coextension_Root (N : Node_Id) return Boolean is
6057 Nkind (N) = N_Allocator
6058 and then Present (Coextensions (N))
6060 -- Anonymous access discriminants carry a list of all nested
6061 -- controlled coextensions.
6063 and then not Is_Dynamic_Coextension (N)
6064 and then not Is_Static_Coextension (N);
6065 end Is_Coextension_Root;
6067 -----------------------------
6068 -- Is_Concurrent_Interface --
6069 -----------------------------
6071 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6076 (Is_Protected_Interface (T)
6077 or else Is_Synchronized_Interface (T)
6078 or else Is_Task_Interface (T));
6079 end Is_Concurrent_Interface;
6081 --------------------------------------
6082 -- Is_Controlling_Limited_Procedure --
6083 --------------------------------------
6085 function Is_Controlling_Limited_Procedure
6086 (Proc_Nam : Entity_Id) return Boolean
6088 Param_Typ : Entity_Id := Empty;
6091 if Ekind (Proc_Nam) = E_Procedure
6092 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6094 Param_Typ := Etype (Parameter_Type (First (
6095 Parameter_Specifications (Parent (Proc_Nam)))));
6097 -- In this case where an Itype was created, the procedure call has been
6100 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6101 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6103 Present (Parameter_Associations
6104 (Associated_Node_For_Itype (Proc_Nam)))
6107 Etype (First (Parameter_Associations
6108 (Associated_Node_For_Itype (Proc_Nam))));
6111 if Present (Param_Typ) then
6113 Is_Interface (Param_Typ)
6114 and then Is_Limited_Record (Param_Typ);
6118 end Is_Controlling_Limited_Procedure;
6120 -----------------------------
6121 -- Is_CPP_Constructor_Call --
6122 -----------------------------
6124 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6126 return Nkind (N) = N_Function_Call
6127 and then Is_CPP_Class (Etype (Etype (N)))
6128 and then Is_Constructor (Entity (Name (N)))
6129 and then Is_Imported (Entity (Name (N)));
6130 end Is_CPP_Constructor_Call;
6136 function Is_Delegate (T : Entity_Id) return Boolean is
6137 Desig_Type : Entity_Id;
6140 if VM_Target /= CLI_Target then
6144 -- Access-to-subprograms are delegates in CIL
6146 if Ekind (T) = E_Access_Subprogram_Type then
6150 if Ekind (T) not in Access_Kind then
6152 -- A delegate is a managed pointer. If no designated type is defined
6153 -- it means that it's not a delegate.
6158 Desig_Type := Etype (Directly_Designated_Type (T));
6160 if not Is_Tagged_Type (Desig_Type) then
6164 -- Test if the type is inherited from [mscorlib]System.Delegate
6166 while Etype (Desig_Type) /= Desig_Type loop
6167 if Chars (Scope (Desig_Type)) /= No_Name
6168 and then Is_Imported (Scope (Desig_Type))
6169 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6174 Desig_Type := Etype (Desig_Type);
6180 ----------------------------------------------
6181 -- Is_Dependent_Component_Of_Mutable_Object --
6182 ----------------------------------------------
6184 function Is_Dependent_Component_Of_Mutable_Object
6185 (Object : Node_Id) return Boolean
6188 Prefix_Type : Entity_Id;
6189 P_Aliased : Boolean := False;
6192 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6193 -- Returns True if and only if Comp is declared within a variant part
6195 --------------------------------
6196 -- Is_Declared_Within_Variant --
6197 --------------------------------
6199 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6200 Comp_Decl : constant Node_Id := Parent (Comp);
6201 Comp_List : constant Node_Id := Parent (Comp_Decl);
6203 return Nkind (Parent (Comp_List)) = N_Variant;
6204 end Is_Declared_Within_Variant;
6206 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6209 if Is_Variable (Object) then
6211 if Nkind (Object) = N_Selected_Component then
6212 P := Prefix (Object);
6213 Prefix_Type := Etype (P);
6215 if Is_Entity_Name (P) then
6217 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6218 Prefix_Type := Base_Type (Prefix_Type);
6221 if Is_Aliased (Entity (P)) then
6225 -- A discriminant check on a selected component may be expanded
6226 -- into a dereference when removing side-effects. Recover the
6227 -- original node and its type, which may be unconstrained.
6229 elsif Nkind (P) = N_Explicit_Dereference
6230 and then not (Comes_From_Source (P))
6232 P := Original_Node (P);
6233 Prefix_Type := Etype (P);
6236 -- Check for prefix being an aliased component???
6242 -- A heap object is constrained by its initial value
6244 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6245 -- the dereferenced case, since the access value might denote an
6246 -- unconstrained aliased object, whereas in Ada 95 the designated
6247 -- object is guaranteed to be constrained. A worst-case assumption
6248 -- has to apply in Ada 2005 because we can't tell at compile time
6249 -- whether the object is "constrained by its initial value"
6250 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6251 -- semantic rules -- these rules are acknowledged to need fixing).
6253 if Ada_Version < Ada_2005 then
6254 if Is_Access_Type (Prefix_Type)
6255 or else Nkind (P) = N_Explicit_Dereference
6260 elsif Ada_Version >= Ada_2005 then
6261 if Is_Access_Type (Prefix_Type) then
6263 -- If the access type is pool-specific, and there is no
6264 -- constrained partial view of the designated type, then the
6265 -- designated object is known to be constrained.
6267 if Ekind (Prefix_Type) = E_Access_Type
6268 and then not Has_Constrained_Partial_View
6269 (Designated_Type (Prefix_Type))
6273 -- Otherwise (general access type, or there is a constrained
6274 -- partial view of the designated type), we need to check
6275 -- based on the designated type.
6278 Prefix_Type := Designated_Type (Prefix_Type);
6284 Original_Record_Component (Entity (Selector_Name (Object)));
6286 -- As per AI-0017, the renaming is illegal in a generic body, even
6287 -- if the subtype is indefinite.
6289 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6291 if not Is_Constrained (Prefix_Type)
6292 and then (not Is_Indefinite_Subtype (Prefix_Type)
6294 (Is_Generic_Type (Prefix_Type)
6295 and then Ekind (Current_Scope) = E_Generic_Package
6296 and then In_Package_Body (Current_Scope)))
6298 and then (Is_Declared_Within_Variant (Comp)
6299 or else Has_Discriminant_Dependent_Constraint (Comp))
6300 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6306 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6310 elsif Nkind (Object) = N_Indexed_Component
6311 or else Nkind (Object) = N_Slice
6313 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6315 -- A type conversion that Is_Variable is a view conversion:
6316 -- go back to the denoted object.
6318 elsif Nkind (Object) = N_Type_Conversion then
6320 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6325 end Is_Dependent_Component_Of_Mutable_Object;
6327 ---------------------
6328 -- Is_Dereferenced --
6329 ---------------------
6331 function Is_Dereferenced (N : Node_Id) return Boolean is
6332 P : constant Node_Id := Parent (N);
6335 (Nkind (P) = N_Selected_Component
6337 Nkind (P) = N_Explicit_Dereference
6339 Nkind (P) = N_Indexed_Component
6341 Nkind (P) = N_Slice)
6342 and then Prefix (P) = N;
6343 end Is_Dereferenced;
6345 ----------------------
6346 -- Is_Descendent_Of --
6347 ----------------------
6349 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6354 pragma Assert (Nkind (T1) in N_Entity);
6355 pragma Assert (Nkind (T2) in N_Entity);
6357 T := Base_Type (T1);
6359 -- Immediate return if the types match
6364 -- Comment needed here ???
6366 elsif Ekind (T) = E_Class_Wide_Type then
6367 return Etype (T) = T2;
6375 -- Done if we found the type we are looking for
6380 -- Done if no more derivations to check
6387 -- Following test catches error cases resulting from prev errors
6389 elsif No (Etyp) then
6392 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6395 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6399 T := Base_Type (Etyp);
6402 end Is_Descendent_Of;
6408 function Is_False (U : Uint) return Boolean is
6413 ---------------------------
6414 -- Is_Fixed_Model_Number --
6415 ---------------------------
6417 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6418 S : constant Ureal := Small_Value (T);
6419 M : Urealp.Save_Mark;
6423 R := (U = UR_Trunc (U / S) * S);
6426 end Is_Fixed_Model_Number;
6428 -------------------------------
6429 -- Is_Fully_Initialized_Type --
6430 -------------------------------
6432 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6434 if Is_Scalar_Type (Typ) then
6437 elsif Is_Access_Type (Typ) then
6440 elsif Is_Array_Type (Typ) then
6441 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6445 -- An interesting case, if we have a constrained type one of whose
6446 -- bounds is known to be null, then there are no elements to be
6447 -- initialized, so all the elements are initialized!
6449 if Is_Constrained (Typ) then
6452 Indx_Typ : Entity_Id;
6456 Indx := First_Index (Typ);
6457 while Present (Indx) loop
6458 if Etype (Indx) = Any_Type then
6461 -- If index is a range, use directly
6463 elsif Nkind (Indx) = N_Range then
6464 Lbd := Low_Bound (Indx);
6465 Hbd := High_Bound (Indx);
6468 Indx_Typ := Etype (Indx);
6470 if Is_Private_Type (Indx_Typ) then
6471 Indx_Typ := Full_View (Indx_Typ);
6474 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6477 Lbd := Type_Low_Bound (Indx_Typ);
6478 Hbd := Type_High_Bound (Indx_Typ);
6482 if Compile_Time_Known_Value (Lbd)
6483 and then Compile_Time_Known_Value (Hbd)
6485 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6495 -- If no null indexes, then type is not fully initialized
6501 elsif Is_Record_Type (Typ) then
6502 if Has_Discriminants (Typ)
6504 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6505 and then Is_Fully_Initialized_Variant (Typ)
6510 -- Controlled records are considered to be fully initialized if
6511 -- there is a user defined Initialize routine. This may not be
6512 -- entirely correct, but as the spec notes, we are guessing here
6513 -- what is best from the point of view of issuing warnings.
6515 if Is_Controlled (Typ) then
6517 Utyp : constant Entity_Id := Underlying_Type (Typ);
6520 if Present (Utyp) then
6522 Init : constant Entity_Id :=
6524 (Underlying_Type (Typ), Name_Initialize));
6528 and then Comes_From_Source (Init)
6530 Is_Predefined_File_Name
6531 (File_Name (Get_Source_File_Index (Sloc (Init))))
6535 elsif Has_Null_Extension (Typ)
6537 Is_Fully_Initialized_Type
6538 (Etype (Base_Type (Typ)))
6547 -- Otherwise see if all record components are initialized
6553 Ent := First_Entity (Typ);
6554 while Present (Ent) loop
6555 if Chars (Ent) = Name_uController then
6558 elsif Ekind (Ent) = E_Component
6559 and then (No (Parent (Ent))
6560 or else No (Expression (Parent (Ent))))
6561 and then not Is_Fully_Initialized_Type (Etype (Ent))
6563 -- Special VM case for tag components, which need to be
6564 -- defined in this case, but are never initialized as VMs
6565 -- are using other dispatching mechanisms. Ignore this
6566 -- uninitialized case. Note that this applies both to the
6567 -- uTag entry and the main vtable pointer (CPP_Class case).
6569 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6578 -- No uninitialized components, so type is fully initialized.
6579 -- Note that this catches the case of no components as well.
6583 elsif Is_Concurrent_Type (Typ) then
6586 elsif Is_Private_Type (Typ) then
6588 U : constant Entity_Id := Underlying_Type (Typ);
6594 return Is_Fully_Initialized_Type (U);
6601 end Is_Fully_Initialized_Type;
6603 ----------------------------------
6604 -- Is_Fully_Initialized_Variant --
6605 ----------------------------------
6607 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6608 Loc : constant Source_Ptr := Sloc (Typ);
6609 Constraints : constant List_Id := New_List;
6610 Components : constant Elist_Id := New_Elmt_List;
6611 Comp_Elmt : Elmt_Id;
6613 Comp_List : Node_Id;
6615 Discr_Val : Node_Id;
6617 Report_Errors : Boolean;
6618 pragma Warnings (Off, Report_Errors);
6621 if Serious_Errors_Detected > 0 then
6625 if Is_Record_Type (Typ)
6626 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6627 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6629 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6631 Discr := First_Discriminant (Typ);
6632 while Present (Discr) loop
6633 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6634 Discr_Val := Expression (Parent (Discr));
6636 if Present (Discr_Val)
6637 and then Is_OK_Static_Expression (Discr_Val)
6639 Append_To (Constraints,
6640 Make_Component_Association (Loc,
6641 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6642 Expression => New_Copy (Discr_Val)));
6650 Next_Discriminant (Discr);
6655 Comp_List => Comp_List,
6656 Governed_By => Constraints,
6658 Report_Errors => Report_Errors);
6660 -- Check that each component present is fully initialized
6662 Comp_Elmt := First_Elmt (Components);
6663 while Present (Comp_Elmt) loop
6664 Comp_Id := Node (Comp_Elmt);
6666 if Ekind (Comp_Id) = E_Component
6667 and then (No (Parent (Comp_Id))
6668 or else No (Expression (Parent (Comp_Id))))
6669 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6674 Next_Elmt (Comp_Elmt);
6679 elsif Is_Private_Type (Typ) then
6681 U : constant Entity_Id := Underlying_Type (Typ);
6687 return Is_Fully_Initialized_Variant (U);
6693 end Is_Fully_Initialized_Variant;
6699 -- We seem to have a lot of overlapping functions that do similar things
6700 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6701 -- purely syntactic, it should be in Sem_Aux I would think???
6703 function Is_LHS (N : Node_Id) return Boolean is
6704 P : constant Node_Id := Parent (N);
6707 if Nkind (P) = N_Assignment_Statement then
6708 return Name (P) = N;
6711 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6713 return N = Prefix (P) and then Is_LHS (P);
6720 ----------------------------
6721 -- Is_Inherited_Operation --
6722 ----------------------------
6724 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6725 Kind : constant Node_Kind := Nkind (Parent (E));
6727 pragma Assert (Is_Overloadable (E));
6728 return Kind = N_Full_Type_Declaration
6729 or else Kind = N_Private_Extension_Declaration
6730 or else Kind = N_Subtype_Declaration
6731 or else (Ekind (E) = E_Enumeration_Literal
6732 and then Is_Derived_Type (Etype (E)));
6733 end Is_Inherited_Operation;
6735 -----------------------------
6736 -- Is_Library_Level_Entity --
6737 -----------------------------
6739 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6741 -- The following is a small optimization, and it also properly handles
6742 -- discriminals, which in task bodies might appear in expressions before
6743 -- the corresponding procedure has been created, and which therefore do
6744 -- not have an assigned scope.
6746 if Is_Formal (E) then
6750 -- Normal test is simply that the enclosing dynamic scope is Standard
6752 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6753 end Is_Library_Level_Entity;
6755 ---------------------------------
6756 -- Is_Local_Variable_Reference --
6757 ---------------------------------
6759 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6761 if not Is_Entity_Name (Expr) then
6766 Ent : constant Entity_Id := Entity (Expr);
6767 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6769 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6772 return Present (Sub) and then Sub = Current_Subprogram;
6776 end Is_Local_Variable_Reference;
6778 -------------------------
6779 -- Is_Object_Reference --
6780 -------------------------
6782 function Is_Object_Reference (N : Node_Id) return Boolean is
6784 if Is_Entity_Name (N) then
6785 return Present (Entity (N)) and then Is_Object (Entity (N));
6789 when N_Indexed_Component | N_Slice =>
6791 Is_Object_Reference (Prefix (N))
6792 or else Is_Access_Type (Etype (Prefix (N)));
6794 -- In Ada95, a function call is a constant object; a procedure
6797 when N_Function_Call =>
6798 return Etype (N) /= Standard_Void_Type;
6800 -- A reference to the stream attribute Input is a function call
6802 when N_Attribute_Reference =>
6803 return Attribute_Name (N) = Name_Input;
6805 when N_Selected_Component =>
6807 Is_Object_Reference (Selector_Name (N))
6809 (Is_Object_Reference (Prefix (N))
6810 or else Is_Access_Type (Etype (Prefix (N))));
6812 when N_Explicit_Dereference =>
6815 -- A view conversion of a tagged object is an object reference
6817 when N_Type_Conversion =>
6818 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6819 and then Is_Tagged_Type (Etype (Expression (N)))
6820 and then Is_Object_Reference (Expression (N));
6822 -- An unchecked type conversion is considered to be an object if
6823 -- the operand is an object (this construction arises only as a
6824 -- result of expansion activities).
6826 when N_Unchecked_Type_Conversion =>
6833 end Is_Object_Reference;
6835 -----------------------------------
6836 -- Is_OK_Variable_For_Out_Formal --
6837 -----------------------------------
6839 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6841 Note_Possible_Modification (AV, Sure => True);
6843 -- We must reject parenthesized variable names. The check for
6844 -- Comes_From_Source is present because there are currently
6845 -- cases where the compiler violates this rule (e.g. passing
6846 -- a task object to its controlled Initialize routine).
6848 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6851 -- A variable is always allowed
6853 elsif Is_Variable (AV) then
6856 -- Unchecked conversions are allowed only if they come from the
6857 -- generated code, which sometimes uses unchecked conversions for out
6858 -- parameters in cases where code generation is unaffected. We tell
6859 -- source unchecked conversions by seeing if they are rewrites of an
6860 -- original Unchecked_Conversion function call, or of an explicit
6861 -- conversion of a function call.
6863 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6864 if Nkind (Original_Node (AV)) = N_Function_Call then
6867 elsif Comes_From_Source (AV)
6868 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6872 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6873 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6879 -- Normal type conversions are allowed if argument is a variable
6881 elsif Nkind (AV) = N_Type_Conversion then
6882 if Is_Variable (Expression (AV))
6883 and then Paren_Count (Expression (AV)) = 0
6885 Note_Possible_Modification (Expression (AV), Sure => True);
6888 -- We also allow a non-parenthesized expression that raises
6889 -- constraint error if it rewrites what used to be a variable
6891 elsif Raises_Constraint_Error (Expression (AV))
6892 and then Paren_Count (Expression (AV)) = 0
6893 and then Is_Variable (Original_Node (Expression (AV)))
6897 -- Type conversion of something other than a variable
6903 -- If this node is rewritten, then test the original form, if that is
6904 -- OK, then we consider the rewritten node OK (for example, if the
6905 -- original node is a conversion, then Is_Variable will not be true
6906 -- but we still want to allow the conversion if it converts a variable).
6908 elsif Original_Node (AV) /= AV then
6909 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6911 -- All other non-variables are rejected
6916 end Is_OK_Variable_For_Out_Formal;
6918 -----------------------------------
6919 -- Is_Partially_Initialized_Type --
6920 -----------------------------------
6922 function Is_Partially_Initialized_Type
6924 Include_Implicit : Boolean := True) return Boolean
6927 if Is_Scalar_Type (Typ) then
6930 elsif Is_Access_Type (Typ) then
6931 return Include_Implicit;
6933 elsif Is_Array_Type (Typ) then
6935 -- If component type is partially initialized, so is array type
6937 if Is_Partially_Initialized_Type
6938 (Component_Type (Typ), Include_Implicit)
6942 -- Otherwise we are only partially initialized if we are fully
6943 -- initialized (this is the empty array case, no point in us
6944 -- duplicating that code here).
6947 return Is_Fully_Initialized_Type (Typ);
6950 elsif Is_Record_Type (Typ) then
6952 -- A discriminated type is always partially initialized if in
6955 if Has_Discriminants (Typ) and then Include_Implicit then
6958 -- A tagged type is always partially initialized
6960 elsif Is_Tagged_Type (Typ) then
6963 -- Case of non-discriminated record
6969 Component_Present : Boolean := False;
6970 -- Set True if at least one component is present. If no
6971 -- components are present, then record type is fully
6972 -- initialized (another odd case, like the null array).
6975 -- Loop through components
6977 Ent := First_Entity (Typ);
6978 while Present (Ent) loop
6979 if Ekind (Ent) = E_Component then
6980 Component_Present := True;
6982 -- If a component has an initialization expression then
6983 -- the enclosing record type is partially initialized
6985 if Present (Parent (Ent))
6986 and then Present (Expression (Parent (Ent)))
6990 -- If a component is of a type which is itself partially
6991 -- initialized, then the enclosing record type is also.
6993 elsif Is_Partially_Initialized_Type
6994 (Etype (Ent), Include_Implicit)
7003 -- No initialized components found. If we found any components
7004 -- they were all uninitialized so the result is false.
7006 if Component_Present then
7009 -- But if we found no components, then all the components are
7010 -- initialized so we consider the type to be initialized.
7018 -- Concurrent types are always fully initialized
7020 elsif Is_Concurrent_Type (Typ) then
7023 -- For a private type, go to underlying type. If there is no underlying
7024 -- type then just assume this partially initialized. Not clear if this
7025 -- can happen in a non-error case, but no harm in testing for this.
7027 elsif Is_Private_Type (Typ) then
7029 U : constant Entity_Id := Underlying_Type (Typ);
7034 return Is_Partially_Initialized_Type (U, Include_Implicit);
7038 -- For any other type (are there any?) assume partially initialized
7043 end Is_Partially_Initialized_Type;
7045 ------------------------------------
7046 -- Is_Potentially_Persistent_Type --
7047 ------------------------------------
7049 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7054 -- For private type, test corresponding full type
7056 if Is_Private_Type (T) then
7057 return Is_Potentially_Persistent_Type (Full_View (T));
7059 -- Scalar types are potentially persistent
7061 elsif Is_Scalar_Type (T) then
7064 -- Record type is potentially persistent if not tagged and the types of
7065 -- all it components are potentially persistent, and no component has
7066 -- an initialization expression.
7068 elsif Is_Record_Type (T)
7069 and then not Is_Tagged_Type (T)
7070 and then not Is_Partially_Initialized_Type (T)
7072 Comp := First_Component (T);
7073 while Present (Comp) loop
7074 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7083 -- Array type is potentially persistent if its component type is
7084 -- potentially persistent and if all its constraints are static.
7086 elsif Is_Array_Type (T) then
7087 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7091 Indx := First_Index (T);
7092 while Present (Indx) loop
7093 if not Is_OK_Static_Subtype (Etype (Indx)) then
7102 -- All other types are not potentially persistent
7107 end Is_Potentially_Persistent_Type;
7109 ---------------------------------
7110 -- Is_Protected_Self_Reference --
7111 ---------------------------------
7113 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7115 function In_Access_Definition (N : Node_Id) return Boolean;
7116 -- Returns true if N belongs to an access definition
7118 --------------------------
7119 -- In_Access_Definition --
7120 --------------------------
7122 function In_Access_Definition (N : Node_Id) return Boolean is
7127 while Present (P) loop
7128 if Nkind (P) = N_Access_Definition then
7136 end In_Access_Definition;
7138 -- Start of processing for Is_Protected_Self_Reference
7141 -- Verify that prefix is analyzed and has the proper form. Note that
7142 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7143 -- produce the address of an entity, do not analyze their prefix
7144 -- because they denote entities that are not necessarily visible.
7145 -- Neither of them can apply to a protected type.
7147 return Ada_Version >= Ada_2005
7148 and then Is_Entity_Name (N)
7149 and then Present (Entity (N))
7150 and then Is_Protected_Type (Entity (N))
7151 and then In_Open_Scopes (Entity (N))
7152 and then not In_Access_Definition (N);
7153 end Is_Protected_Self_Reference;
7155 -----------------------------
7156 -- Is_RCI_Pkg_Spec_Or_Body --
7157 -----------------------------
7159 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7161 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7162 -- Return True if the unit of Cunit is an RCI package declaration
7164 ---------------------------
7165 -- Is_RCI_Pkg_Decl_Cunit --
7166 ---------------------------
7168 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7169 The_Unit : constant Node_Id := Unit (Cunit);
7172 if Nkind (The_Unit) /= N_Package_Declaration then
7176 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7177 end Is_RCI_Pkg_Decl_Cunit;
7179 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7182 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7184 (Nkind (Unit (Cunit)) = N_Package_Body
7185 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7186 end Is_RCI_Pkg_Spec_Or_Body;
7188 -----------------------------------------
7189 -- Is_Remote_Access_To_Class_Wide_Type --
7190 -----------------------------------------
7192 function Is_Remote_Access_To_Class_Wide_Type
7193 (E : Entity_Id) return Boolean
7196 -- A remote access to class-wide type is a general access to object type
7197 -- declared in the visible part of a Remote_Types or Remote_Call_
7200 return Ekind (E) = E_General_Access_Type
7201 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7202 end Is_Remote_Access_To_Class_Wide_Type;
7204 -----------------------------------------
7205 -- Is_Remote_Access_To_Subprogram_Type --
7206 -----------------------------------------
7208 function Is_Remote_Access_To_Subprogram_Type
7209 (E : Entity_Id) return Boolean
7212 return (Ekind (E) = E_Access_Subprogram_Type
7213 or else (Ekind (E) = E_Record_Type
7214 and then Present (Corresponding_Remote_Type (E))))
7215 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7216 end Is_Remote_Access_To_Subprogram_Type;
7218 --------------------
7219 -- Is_Remote_Call --
7220 --------------------
7222 function Is_Remote_Call (N : Node_Id) return Boolean is
7224 if Nkind (N) /= N_Procedure_Call_Statement
7225 and then Nkind (N) /= N_Function_Call
7227 -- An entry call cannot be remote
7231 elsif Nkind (Name (N)) in N_Has_Entity
7232 and then Is_Remote_Call_Interface (Entity (Name (N)))
7234 -- A subprogram declared in the spec of a RCI package is remote
7238 elsif Nkind (Name (N)) = N_Explicit_Dereference
7239 and then Is_Remote_Access_To_Subprogram_Type
7240 (Etype (Prefix (Name (N))))
7242 -- The dereference of a RAS is a remote call
7246 elsif Present (Controlling_Argument (N))
7247 and then Is_Remote_Access_To_Class_Wide_Type
7248 (Etype (Controlling_Argument (N)))
7250 -- Any primitive operation call with a controlling argument of
7251 -- a RACW type is a remote call.
7256 -- All other calls are local calls
7261 ----------------------
7262 -- Is_Renamed_Entry --
7263 ----------------------
7265 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7266 Orig_Node : Node_Id := Empty;
7267 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7269 function Is_Entry (Nam : Node_Id) return Boolean;
7270 -- Determine whether Nam is an entry. Traverse selectors if there are
7271 -- nested selected components.
7277 function Is_Entry (Nam : Node_Id) return Boolean is
7279 if Nkind (Nam) = N_Selected_Component then
7280 return Is_Entry (Selector_Name (Nam));
7283 return Ekind (Entity (Nam)) = E_Entry;
7286 -- Start of processing for Is_Renamed_Entry
7289 if Present (Alias (Proc_Nam)) then
7290 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7293 -- Look for a rewritten subprogram renaming declaration
7295 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7296 and then Present (Original_Node (Subp_Decl))
7298 Orig_Node := Original_Node (Subp_Decl);
7301 -- The rewritten subprogram is actually an entry
7303 if Present (Orig_Node)
7304 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7305 and then Is_Entry (Name (Orig_Node))
7311 end Is_Renamed_Entry;
7313 ----------------------
7314 -- Is_Selector_Name --
7315 ----------------------
7317 function Is_Selector_Name (N : Node_Id) return Boolean is
7319 if not Is_List_Member (N) then
7321 P : constant Node_Id := Parent (N);
7322 K : constant Node_Kind := Nkind (P);
7325 (K = N_Expanded_Name or else
7326 K = N_Generic_Association or else
7327 K = N_Parameter_Association or else
7328 K = N_Selected_Component)
7329 and then Selector_Name (P) = N;
7334 L : constant List_Id := List_Containing (N);
7335 P : constant Node_Id := Parent (L);
7337 return (Nkind (P) = N_Discriminant_Association
7338 and then Selector_Names (P) = L)
7340 (Nkind (P) = N_Component_Association
7341 and then Choices (P) = L);
7344 end Is_Selector_Name;
7350 function Is_Statement (N : Node_Id) return Boolean is
7353 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7354 or else Nkind (N) = N_Procedure_Call_Statement;
7357 ---------------------------------
7358 -- Is_Synchronized_Tagged_Type --
7359 ---------------------------------
7361 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7362 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7365 -- A task or protected type derived from an interface is a tagged type.
7366 -- Such a tagged type is called a synchronized tagged type, as are
7367 -- synchronized interfaces and private extensions whose declaration
7368 -- includes the reserved word synchronized.
7370 return (Is_Tagged_Type (E)
7371 and then (Kind = E_Task_Type
7372 or else Kind = E_Protected_Type))
7375 and then Is_Synchronized_Interface (E))
7377 (Ekind (E) = E_Record_Type_With_Private
7378 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7379 and then (Synchronized_Present (Parent (E))
7380 or else Is_Synchronized_Interface (Etype (E))));
7381 end Is_Synchronized_Tagged_Type;
7387 function Is_Transfer (N : Node_Id) return Boolean is
7388 Kind : constant Node_Kind := Nkind (N);
7391 if Kind = N_Simple_Return_Statement
7393 Kind = N_Extended_Return_Statement
7395 Kind = N_Goto_Statement
7397 Kind = N_Raise_Statement
7399 Kind = N_Requeue_Statement
7403 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7404 and then No (Condition (N))
7408 elsif Kind = N_Procedure_Call_Statement
7409 and then Is_Entity_Name (Name (N))
7410 and then Present (Entity (Name (N)))
7411 and then No_Return (Entity (Name (N)))
7415 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7427 function Is_True (U : Uint) return Boolean is
7432 -------------------------------
7433 -- Is_Universal_Numeric_Type --
7434 -------------------------------
7436 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7438 return T = Universal_Integer or else T = Universal_Real;
7439 end Is_Universal_Numeric_Type;
7445 function Is_Value_Type (T : Entity_Id) return Boolean is
7447 return VM_Target = CLI_Target
7448 and then Nkind (T) in N_Has_Chars
7449 and then Chars (T) /= No_Name
7450 and then Get_Name_String (Chars (T)) = "valuetype";
7453 ---------------------
7454 -- Is_VMS_Operator --
7455 ---------------------
7457 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7459 -- The VMS operators are declared in a child of System that is loaded
7460 -- through pragma Extend_System. In some rare cases a program is run
7461 -- with this extension but without indicating that the target is VMS.
7463 return Ekind (Op) = E_Function
7464 and then Is_Intrinsic_Subprogram (Op)
7466 ((Present_System_Aux
7467 and then Scope (Op) = System_Aux_Id)
7470 and then Scope (Scope (Op)) = RTU_Entity (System)));
7471 end Is_VMS_Operator;
7477 function Is_Variable (N : Node_Id) return Boolean is
7479 Orig_Node : constant Node_Id := Original_Node (N);
7480 -- We do the test on the original node, since this is basically a test
7481 -- of syntactic categories, so it must not be disturbed by whatever
7482 -- rewriting might have occurred. For example, an aggregate, which is
7483 -- certainly NOT a variable, could be turned into a variable by
7486 function In_Protected_Function (E : Entity_Id) return Boolean;
7487 -- Within a protected function, the private components of the enclosing
7488 -- protected type are constants. A function nested within a (protected)
7489 -- procedure is not itself protected.
7491 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7492 -- Prefixes can involve implicit dereferences, in which case we must
7493 -- test for the case of a reference of a constant access type, which can
7494 -- can never be a variable.
7496 ---------------------------
7497 -- In_Protected_Function --
7498 ---------------------------
7500 function In_Protected_Function (E : Entity_Id) return Boolean is
7501 Prot : constant Entity_Id := Scope (E);
7505 if not Is_Protected_Type (Prot) then
7509 while Present (S) and then S /= Prot loop
7510 if Ekind (S) = E_Function and then Scope (S) = Prot then
7519 end In_Protected_Function;
7521 ------------------------
7522 -- Is_Variable_Prefix --
7523 ------------------------
7525 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7527 if Is_Access_Type (Etype (P)) then
7528 return not Is_Access_Constant (Root_Type (Etype (P)));
7530 -- For the case of an indexed component whose prefix has a packed
7531 -- array type, the prefix has been rewritten into a type conversion.
7532 -- Determine variable-ness from the converted expression.
7534 elsif Nkind (P) = N_Type_Conversion
7535 and then not Comes_From_Source (P)
7536 and then Is_Array_Type (Etype (P))
7537 and then Is_Packed (Etype (P))
7539 return Is_Variable (Expression (P));
7542 return Is_Variable (P);
7544 end Is_Variable_Prefix;
7546 -- Start of processing for Is_Variable
7549 -- Definitely OK if Assignment_OK is set. Since this is something that
7550 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7552 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7555 -- Normally we go to the original node, but there is one exception where
7556 -- we use the rewritten node, namely when it is an explicit dereference.
7557 -- The generated code may rewrite a prefix which is an access type with
7558 -- an explicit dereference. The dereference is a variable, even though
7559 -- the original node may not be (since it could be a constant of the
7562 -- In Ada 2005 we have a further case to consider: the prefix may be a
7563 -- function call given in prefix notation. The original node appears to
7564 -- be a selected component, but we need to examine the call.
7566 elsif Nkind (N) = N_Explicit_Dereference
7567 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7568 and then Present (Etype (Orig_Node))
7569 and then Is_Access_Type (Etype (Orig_Node))
7571 -- Note that if the prefix is an explicit dereference that does not
7572 -- come from source, we must check for a rewritten function call in
7573 -- prefixed notation before other forms of rewriting, to prevent a
7577 (Nkind (Orig_Node) = N_Function_Call
7578 and then not Is_Access_Constant (Etype (Prefix (N))))
7580 Is_Variable_Prefix (Original_Node (Prefix (N)));
7582 -- A function call is never a variable
7584 elsif Nkind (N) = N_Function_Call then
7587 -- All remaining checks use the original node
7589 elsif Is_Entity_Name (Orig_Node)
7590 and then Present (Entity (Orig_Node))
7593 E : constant Entity_Id := Entity (Orig_Node);
7594 K : constant Entity_Kind := Ekind (E);
7597 return (K = E_Variable
7598 and then Nkind (Parent (E)) /= N_Exception_Handler)
7599 or else (K = E_Component
7600 and then not In_Protected_Function (E))
7601 or else K = E_Out_Parameter
7602 or else K = E_In_Out_Parameter
7603 or else K = E_Generic_In_Out_Parameter
7605 -- Current instance of type:
7607 or else (Is_Type (E) and then In_Open_Scopes (E))
7608 or else (Is_Incomplete_Or_Private_Type (E)
7609 and then In_Open_Scopes (Full_View (E)));
7613 case Nkind (Orig_Node) is
7614 when N_Indexed_Component | N_Slice =>
7615 return Is_Variable_Prefix (Prefix (Orig_Node));
7617 when N_Selected_Component =>
7618 return Is_Variable_Prefix (Prefix (Orig_Node))
7619 and then Is_Variable (Selector_Name (Orig_Node));
7621 -- For an explicit dereference, the type of the prefix cannot
7622 -- be an access to constant or an access to subprogram.
7624 when N_Explicit_Dereference =>
7626 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7628 return Is_Access_Type (Typ)
7629 and then not Is_Access_Constant (Root_Type (Typ))
7630 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7633 -- The type conversion is the case where we do not deal with the
7634 -- context dependent special case of an actual parameter. Thus
7635 -- the type conversion is only considered a variable for the
7636 -- purposes of this routine if the target type is tagged. However,
7637 -- a type conversion is considered to be a variable if it does not
7638 -- come from source (this deals for example with the conversions
7639 -- of expressions to their actual subtypes).
7641 when N_Type_Conversion =>
7642 return Is_Variable (Expression (Orig_Node))
7644 (not Comes_From_Source (Orig_Node)
7646 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7648 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7650 -- GNAT allows an unchecked type conversion as a variable. This
7651 -- only affects the generation of internal expanded code, since
7652 -- calls to instantiations of Unchecked_Conversion are never
7653 -- considered variables (since they are function calls).
7654 -- This is also true for expression actions.
7656 when N_Unchecked_Type_Conversion =>
7657 return Is_Variable (Expression (Orig_Node));
7665 ---------------------------
7666 -- Is_Visibly_Controlled --
7667 ---------------------------
7669 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7670 Root : constant Entity_Id := Root_Type (T);
7672 return Chars (Scope (Root)) = Name_Finalization
7673 and then Chars (Scope (Scope (Root))) = Name_Ada
7674 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7675 end Is_Visibly_Controlled;
7677 ------------------------
7678 -- Is_Volatile_Object --
7679 ------------------------
7681 function Is_Volatile_Object (N : Node_Id) return Boolean is
7683 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7684 -- Determines if given object has volatile components
7686 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7687 -- If prefix is an implicit dereference, examine designated type
7689 ------------------------
7690 -- Is_Volatile_Prefix --
7691 ------------------------
7693 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7694 Typ : constant Entity_Id := Etype (N);
7697 if Is_Access_Type (Typ) then
7699 Dtyp : constant Entity_Id := Designated_Type (Typ);
7702 return Is_Volatile (Dtyp)
7703 or else Has_Volatile_Components (Dtyp);
7707 return Object_Has_Volatile_Components (N);
7709 end Is_Volatile_Prefix;
7711 ------------------------------------
7712 -- Object_Has_Volatile_Components --
7713 ------------------------------------
7715 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7716 Typ : constant Entity_Id := Etype (N);
7719 if Is_Volatile (Typ)
7720 or else Has_Volatile_Components (Typ)
7724 elsif Is_Entity_Name (N)
7725 and then (Has_Volatile_Components (Entity (N))
7726 or else Is_Volatile (Entity (N)))
7730 elsif Nkind (N) = N_Indexed_Component
7731 or else Nkind (N) = N_Selected_Component
7733 return Is_Volatile_Prefix (Prefix (N));
7738 end Object_Has_Volatile_Components;
7740 -- Start of processing for Is_Volatile_Object
7743 if Is_Volatile (Etype (N))
7744 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7748 elsif Nkind (N) = N_Indexed_Component
7749 or else Nkind (N) = N_Selected_Component
7751 return Is_Volatile_Prefix (Prefix (N));
7756 end Is_Volatile_Object;
7758 -------------------------
7759 -- Kill_Current_Values --
7760 -------------------------
7762 procedure Kill_Current_Values
7764 Last_Assignment_Only : Boolean := False)
7767 -- ??? do we have to worry about clearing cached checks?
7769 if Is_Assignable (Ent) then
7770 Set_Last_Assignment (Ent, Empty);
7773 if Is_Object (Ent) then
7774 if not Last_Assignment_Only then
7776 Set_Current_Value (Ent, Empty);
7778 if not Can_Never_Be_Null (Ent) then
7779 Set_Is_Known_Non_Null (Ent, False);
7782 Set_Is_Known_Null (Ent, False);
7784 -- Reset Is_Known_Valid unless type is always valid, or if we have
7785 -- a loop parameter (loop parameters are always valid, since their
7786 -- bounds are defined by the bounds given in the loop header).
7788 if not Is_Known_Valid (Etype (Ent))
7789 and then Ekind (Ent) /= E_Loop_Parameter
7791 Set_Is_Known_Valid (Ent, False);
7795 end Kill_Current_Values;
7797 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7800 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7801 -- Clear current value for entity E and all entities chained to E
7803 ------------------------------------------
7804 -- Kill_Current_Values_For_Entity_Chain --
7805 ------------------------------------------
7807 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7811 while Present (Ent) loop
7812 Kill_Current_Values (Ent, Last_Assignment_Only);
7815 end Kill_Current_Values_For_Entity_Chain;
7817 -- Start of processing for Kill_Current_Values
7820 -- Kill all saved checks, a special case of killing saved values
7822 if not Last_Assignment_Only then
7826 -- Loop through relevant scopes, which includes the current scope and
7827 -- any parent scopes if the current scope is a block or a package.
7832 -- Clear current values of all entities in current scope
7834 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7836 -- If scope is a package, also clear current values of all
7837 -- private entities in the scope.
7839 if Is_Package_Or_Generic_Package (S)
7840 or else Is_Concurrent_Type (S)
7842 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7845 -- If this is a not a subprogram, deal with parents
7847 if not Is_Subprogram (S) then
7849 exit Scope_Loop when S = Standard_Standard;
7853 end loop Scope_Loop;
7854 end Kill_Current_Values;
7856 --------------------------
7857 -- Kill_Size_Check_Code --
7858 --------------------------
7860 procedure Kill_Size_Check_Code (E : Entity_Id) is
7862 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7863 and then Present (Size_Check_Code (E))
7865 Remove (Size_Check_Code (E));
7866 Set_Size_Check_Code (E, Empty);
7868 end Kill_Size_Check_Code;
7870 --------------------------
7871 -- Known_To_Be_Assigned --
7872 --------------------------
7874 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7875 P : constant Node_Id := Parent (N);
7880 -- Test left side of assignment
7882 when N_Assignment_Statement =>
7883 return N = Name (P);
7885 -- Function call arguments are never lvalues
7887 when N_Function_Call =>
7890 -- Positional parameter for procedure or accept call
7892 when N_Procedure_Call_Statement |
7901 Proc := Get_Subprogram_Entity (P);
7907 -- If we are not a list member, something is strange, so
7908 -- be conservative and return False.
7910 if not Is_List_Member (N) then
7914 -- We are going to find the right formal by stepping forward
7915 -- through the formals, as we step backwards in the actuals.
7917 Form := First_Formal (Proc);
7920 -- If no formal, something is weird, so be conservative
7921 -- and return False.
7932 return Ekind (Form) /= E_In_Parameter;
7935 -- Named parameter for procedure or accept call
7937 when N_Parameter_Association =>
7943 Proc := Get_Subprogram_Entity (Parent (P));
7949 -- Loop through formals to find the one that matches
7951 Form := First_Formal (Proc);
7953 -- If no matching formal, that's peculiar, some kind of
7954 -- previous error, so return False to be conservative.
7960 -- Else test for match
7962 if Chars (Form) = Chars (Selector_Name (P)) then
7963 return Ekind (Form) /= E_In_Parameter;
7970 -- Test for appearing in a conversion that itself appears
7971 -- in an lvalue context, since this should be an lvalue.
7973 when N_Type_Conversion =>
7974 return Known_To_Be_Assigned (P);
7976 -- All other references are definitely not known to be modifications
7982 end Known_To_Be_Assigned;
7984 ---------------------------
7985 -- Last_Source_Statement --
7986 ---------------------------
7988 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
7992 N := Last (Statements (HSS));
7993 while Present (N) loop
7994 exit when Comes_From_Source (N);
7999 end Last_Source_Statement;
8005 function May_Be_Lvalue (N : Node_Id) return Boolean is
8006 P : constant Node_Id := Parent (N);
8011 -- Test left side of assignment
8013 when N_Assignment_Statement =>
8014 return N = Name (P);
8016 -- Test prefix of component or attribute. Note that the prefix of an
8017 -- explicit or implicit dereference cannot be an l-value.
8019 when N_Attribute_Reference =>
8020 return N = Prefix (P)
8021 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8023 -- For an expanded name, the name is an lvalue if the expanded name
8024 -- is an lvalue, but the prefix is never an lvalue, since it is just
8025 -- the scope where the name is found.
8027 when N_Expanded_Name =>
8028 if N = Prefix (P) then
8029 return May_Be_Lvalue (P);
8034 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8035 -- B is a little interesting, if we have A.B := 3, there is some
8036 -- discussion as to whether B is an lvalue or not, we choose to say
8037 -- it is. Note however that A is not an lvalue if it is of an access
8038 -- type since this is an implicit dereference.
8040 when N_Selected_Component =>
8042 and then Present (Etype (N))
8043 and then Is_Access_Type (Etype (N))
8047 return May_Be_Lvalue (P);
8050 -- For an indexed component or slice, the index or slice bounds is
8051 -- never an lvalue. The prefix is an lvalue if the indexed component
8052 -- or slice is an lvalue, except if it is an access type, where we
8053 -- have an implicit dereference.
8055 when N_Indexed_Component =>
8057 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8061 return May_Be_Lvalue (P);
8064 -- Prefix of a reference is an lvalue if the reference is an lvalue
8067 return May_Be_Lvalue (P);
8069 -- Prefix of explicit dereference is never an lvalue
8071 when N_Explicit_Dereference =>
8074 -- Positional parameter for subprogram, entry, or accept call.
8075 -- In older versions of Ada function call arguments are never
8076 -- lvalues. In Ada 2012 functions can have in-out parameters.
8078 when N_Function_Call |
8079 N_Procedure_Call_Statement |
8080 N_Entry_Call_Statement |
8083 if Nkind (P) = N_Function_Call
8084 and then Ada_Version < Ada_2012
8089 -- The following mechanism is clumsy and fragile. A single
8090 -- flag set in Resolve_Actuals would be preferable ???
8098 Proc := Get_Subprogram_Entity (P);
8104 -- If we are not a list member, something is strange, so
8105 -- be conservative and return True.
8107 if not Is_List_Member (N) then
8111 -- We are going to find the right formal by stepping forward
8112 -- through the formals, as we step backwards in the actuals.
8114 Form := First_Formal (Proc);
8117 -- If no formal, something is weird, so be conservative
8129 return Ekind (Form) /= E_In_Parameter;
8132 -- Named parameter for procedure or accept call
8134 when N_Parameter_Association =>
8140 Proc := Get_Subprogram_Entity (Parent (P));
8146 -- Loop through formals to find the one that matches
8148 Form := First_Formal (Proc);
8150 -- If no matching formal, that's peculiar, some kind of
8151 -- previous error, so return True to be conservative.
8157 -- Else test for match
8159 if Chars (Form) = Chars (Selector_Name (P)) then
8160 return Ekind (Form) /= E_In_Parameter;
8167 -- Test for appearing in a conversion that itself appears in an
8168 -- lvalue context, since this should be an lvalue.
8170 when N_Type_Conversion =>
8171 return May_Be_Lvalue (P);
8173 -- Test for appearance in object renaming declaration
8175 when N_Object_Renaming_Declaration =>
8178 -- All other references are definitely not lvalues
8186 -----------------------
8187 -- Mark_Coextensions --
8188 -----------------------
8190 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8191 Is_Dynamic : Boolean;
8192 -- Indicates whether the context causes nested coextensions to be
8193 -- dynamic or static
8195 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8196 -- Recognize an allocator node and label it as a dynamic coextension
8198 --------------------
8199 -- Mark_Allocator --
8200 --------------------
8202 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8204 if Nkind (N) = N_Allocator then
8206 Set_Is_Dynamic_Coextension (N);
8208 -- If the allocator expression is potentially dynamic, it may
8209 -- be expanded out of order and require dynamic allocation
8210 -- anyway, so we treat the coextension itself as dynamic.
8211 -- Potential optimization ???
8213 elsif Nkind (Expression (N)) = N_Qualified_Expression
8214 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8216 Set_Is_Dynamic_Coextension (N);
8219 Set_Is_Static_Coextension (N);
8226 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8228 -- Start of processing Mark_Coextensions
8231 case Nkind (Context_Nod) is
8232 when N_Assignment_Statement |
8233 N_Simple_Return_Statement =>
8234 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8236 when N_Object_Declaration =>
8237 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8239 -- This routine should not be called for constructs which may not
8240 -- contain coextensions.
8243 raise Program_Error;
8246 Mark_Allocators (Root_Nod);
8247 end Mark_Coextensions;
8249 ----------------------
8250 -- Needs_One_Actual --
8251 ----------------------
8253 function Needs_One_Actual (E : Entity_Id) return Boolean is
8257 if Ada_Version >= Ada_2005
8258 and then Present (First_Formal (E))
8260 Formal := Next_Formal (First_Formal (E));
8261 while Present (Formal) loop
8262 if No (Default_Value (Formal)) then
8266 Next_Formal (Formal);
8274 end Needs_One_Actual;
8276 ------------------------
8277 -- New_Copy_List_Tree --
8278 ------------------------
8280 function New_Copy_List_Tree (List : List_Id) return List_Id is
8285 if List = No_List then
8292 while Present (E) loop
8293 Append (New_Copy_Tree (E), NL);
8299 end New_Copy_List_Tree;
8305 use Atree.Unchecked_Access;
8306 use Atree_Private_Part;
8308 -- Our approach here requires a two pass traversal of the tree. The
8309 -- first pass visits all nodes that eventually will be copied looking
8310 -- for defining Itypes. If any defining Itypes are found, then they are
8311 -- copied, and an entry is added to the replacement map. In the second
8312 -- phase, the tree is copied, using the replacement map to replace any
8313 -- Itype references within the copied tree.
8315 -- The following hash tables are used if the Map supplied has more
8316 -- than hash threshold entries to speed up access to the map. If
8317 -- there are fewer entries, then the map is searched sequentially
8318 -- (because setting up a hash table for only a few entries takes
8319 -- more time than it saves.
8321 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8322 -- Hash function used for hash operations
8328 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8330 return Nat (E) mod (NCT_Header_Num'Last + 1);
8337 -- The hash table NCT_Assoc associates old entities in the table
8338 -- with their corresponding new entities (i.e. the pairs of entries
8339 -- presented in the original Map argument are Key-Element pairs).
8341 package NCT_Assoc is new Simple_HTable (
8342 Header_Num => NCT_Header_Num,
8343 Element => Entity_Id,
8344 No_Element => Empty,
8346 Hash => New_Copy_Hash,
8347 Equal => Types."=");
8349 ---------------------
8350 -- NCT_Itype_Assoc --
8351 ---------------------
8353 -- The hash table NCT_Itype_Assoc contains entries only for those
8354 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8355 -- The key is the associated node, and the element is the new node
8356 -- itself (NOT the associated node for the new node).
8358 package NCT_Itype_Assoc is new Simple_HTable (
8359 Header_Num => NCT_Header_Num,
8360 Element => Entity_Id,
8361 No_Element => Empty,
8363 Hash => New_Copy_Hash,
8364 Equal => Types."=");
8366 -- Start of processing for New_Copy_Tree function
8368 function New_Copy_Tree
8370 Map : Elist_Id := No_Elist;
8371 New_Sloc : Source_Ptr := No_Location;
8372 New_Scope : Entity_Id := Empty) return Node_Id
8374 Actual_Map : Elist_Id := Map;
8375 -- This is the actual map for the copy. It is initialized with the
8376 -- given elements, and then enlarged as required for Itypes that are
8377 -- copied during the first phase of the copy operation. The visit
8378 -- procedures add elements to this map as Itypes are encountered.
8379 -- The reason we cannot use Map directly, is that it may well be
8380 -- (and normally is) initialized to No_Elist, and if we have mapped
8381 -- entities, we have to reset it to point to a real Elist.
8383 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8384 -- Called during second phase to map entities into their corresponding
8385 -- copies using Actual_Map. If the argument is not an entity, or is not
8386 -- in Actual_Map, then it is returned unchanged.
8388 procedure Build_NCT_Hash_Tables;
8389 -- Builds hash tables (number of elements >= threshold value)
8391 function Copy_Elist_With_Replacement
8392 (Old_Elist : Elist_Id) return Elist_Id;
8393 -- Called during second phase to copy element list doing replacements
8395 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8396 -- Called during the second phase to process a copied Itype. The actual
8397 -- copy happened during the first phase (so that we could make the entry
8398 -- in the mapping), but we still have to deal with the descendents of
8399 -- the copied Itype and copy them where necessary.
8401 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8402 -- Called during second phase to copy list doing replacements
8404 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8405 -- Called during second phase to copy node doing replacements
8407 procedure Visit_Elist (E : Elist_Id);
8408 -- Called during first phase to visit all elements of an Elist
8410 procedure Visit_Field (F : Union_Id; N : Node_Id);
8411 -- Visit a single field, recursing to call Visit_Node or Visit_List
8412 -- if the field is a syntactic descendent of the current node (i.e.
8413 -- its parent is Node N).
8415 procedure Visit_Itype (Old_Itype : Entity_Id);
8416 -- Called during first phase to visit subsidiary fields of a defining
8417 -- Itype, and also create a copy and make an entry in the replacement
8418 -- map for the new copy.
8420 procedure Visit_List (L : List_Id);
8421 -- Called during first phase to visit all elements of a List
8423 procedure Visit_Node (N : Node_Or_Entity_Id);
8424 -- Called during first phase to visit a node and all its subtrees
8430 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8435 if not Has_Extension (N) or else No (Actual_Map) then
8438 elsif NCT_Hash_Tables_Used then
8439 Ent := NCT_Assoc.Get (Entity_Id (N));
8441 if Present (Ent) then
8447 -- No hash table used, do serial search
8450 E := First_Elmt (Actual_Map);
8451 while Present (E) loop
8452 if Node (E) = N then
8453 return Node (Next_Elmt (E));
8455 E := Next_Elmt (Next_Elmt (E));
8463 ---------------------------
8464 -- Build_NCT_Hash_Tables --
8465 ---------------------------
8467 procedure Build_NCT_Hash_Tables is
8471 if NCT_Hash_Table_Setup then
8473 NCT_Itype_Assoc.Reset;
8476 Elmt := First_Elmt (Actual_Map);
8477 while Present (Elmt) loop
8480 -- Get new entity, and associate old and new
8483 NCT_Assoc.Set (Ent, Node (Elmt));
8485 if Is_Type (Ent) then
8487 Anode : constant Entity_Id :=
8488 Associated_Node_For_Itype (Ent);
8491 if Present (Anode) then
8493 -- Enter a link between the associated node of the
8494 -- old Itype and the new Itype, for updating later
8495 -- when node is copied.
8497 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8505 NCT_Hash_Tables_Used := True;
8506 NCT_Hash_Table_Setup := True;
8507 end Build_NCT_Hash_Tables;
8509 ---------------------------------
8510 -- Copy_Elist_With_Replacement --
8511 ---------------------------------
8513 function Copy_Elist_With_Replacement
8514 (Old_Elist : Elist_Id) return Elist_Id
8517 New_Elist : Elist_Id;
8520 if No (Old_Elist) then
8524 New_Elist := New_Elmt_List;
8526 M := First_Elmt (Old_Elist);
8527 while Present (M) loop
8528 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8534 end Copy_Elist_With_Replacement;
8536 ---------------------------------
8537 -- Copy_Itype_With_Replacement --
8538 ---------------------------------
8540 -- This routine exactly parallels its phase one analog Visit_Itype,
8542 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8544 -- Translate Next_Entity, Scope and Etype fields, in case they
8545 -- reference entities that have been mapped into copies.
8547 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8548 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8550 if Present (New_Scope) then
8551 Set_Scope (New_Itype, New_Scope);
8553 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8556 -- Copy referenced fields
8558 if Is_Discrete_Type (New_Itype) then
8559 Set_Scalar_Range (New_Itype,
8560 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8562 elsif Has_Discriminants (Base_Type (New_Itype)) then
8563 Set_Discriminant_Constraint (New_Itype,
8564 Copy_Elist_With_Replacement
8565 (Discriminant_Constraint (New_Itype)));
8567 elsif Is_Array_Type (New_Itype) then
8568 if Present (First_Index (New_Itype)) then
8569 Set_First_Index (New_Itype,
8570 First (Copy_List_With_Replacement
8571 (List_Containing (First_Index (New_Itype)))));
8574 if Is_Packed (New_Itype) then
8575 Set_Packed_Array_Type (New_Itype,
8576 Copy_Node_With_Replacement
8577 (Packed_Array_Type (New_Itype)));
8580 end Copy_Itype_With_Replacement;
8582 --------------------------------
8583 -- Copy_List_With_Replacement --
8584 --------------------------------
8586 function Copy_List_With_Replacement
8587 (Old_List : List_Id) return List_Id
8593 if Old_List = No_List then
8597 New_List := Empty_List;
8599 E := First (Old_List);
8600 while Present (E) loop
8601 Append (Copy_Node_With_Replacement (E), New_List);
8607 end Copy_List_With_Replacement;
8609 --------------------------------
8610 -- Copy_Node_With_Replacement --
8611 --------------------------------
8613 function Copy_Node_With_Replacement
8614 (Old_Node : Node_Id) return Node_Id
8618 procedure Adjust_Named_Associations
8619 (Old_Node : Node_Id;
8620 New_Node : Node_Id);
8621 -- If a call node has named associations, these are chained through
8622 -- the First_Named_Actual, Next_Named_Actual links. These must be
8623 -- propagated separately to the new parameter list, because these
8624 -- are not syntactic fields.
8626 function Copy_Field_With_Replacement
8627 (Field : Union_Id) return Union_Id;
8628 -- Given Field, which is a field of Old_Node, return a copy of it
8629 -- if it is a syntactic field (i.e. its parent is Node), setting
8630 -- the parent of the copy to poit to New_Node. Otherwise returns
8631 -- the field (possibly mapped if it is an entity).
8633 -------------------------------
8634 -- Adjust_Named_Associations --
8635 -------------------------------
8637 procedure Adjust_Named_Associations
8638 (Old_Node : Node_Id;
8648 Old_E := First (Parameter_Associations (Old_Node));
8649 New_E := First (Parameter_Associations (New_Node));
8650 while Present (Old_E) loop
8651 if Nkind (Old_E) = N_Parameter_Association
8652 and then Present (Next_Named_Actual (Old_E))
8654 if First_Named_Actual (Old_Node)
8655 = Explicit_Actual_Parameter (Old_E)
8657 Set_First_Named_Actual
8658 (New_Node, Explicit_Actual_Parameter (New_E));
8661 -- Now scan parameter list from the beginning,to locate
8662 -- next named actual, which can be out of order.
8664 Old_Next := First (Parameter_Associations (Old_Node));
8665 New_Next := First (Parameter_Associations (New_Node));
8667 while Nkind (Old_Next) /= N_Parameter_Association
8668 or else Explicit_Actual_Parameter (Old_Next)
8669 /= Next_Named_Actual (Old_E)
8675 Set_Next_Named_Actual
8676 (New_E, Explicit_Actual_Parameter (New_Next));
8682 end Adjust_Named_Associations;
8684 ---------------------------------
8685 -- Copy_Field_With_Replacement --
8686 ---------------------------------
8688 function Copy_Field_With_Replacement
8689 (Field : Union_Id) return Union_Id
8692 if Field = Union_Id (Empty) then
8695 elsif Field in Node_Range then
8697 Old_N : constant Node_Id := Node_Id (Field);
8701 -- If syntactic field, as indicated by the parent pointer
8702 -- being set, then copy the referenced node recursively.
8704 if Parent (Old_N) = Old_Node then
8705 New_N := Copy_Node_With_Replacement (Old_N);
8707 if New_N /= Old_N then
8708 Set_Parent (New_N, New_Node);
8711 -- For semantic fields, update possible entity reference
8712 -- from the replacement map.
8715 New_N := Assoc (Old_N);
8718 return Union_Id (New_N);
8721 elsif Field in List_Range then
8723 Old_L : constant List_Id := List_Id (Field);
8727 -- If syntactic field, as indicated by the parent pointer,
8728 -- then recursively copy the entire referenced list.
8730 if Parent (Old_L) = Old_Node then
8731 New_L := Copy_List_With_Replacement (Old_L);
8732 Set_Parent (New_L, New_Node);
8734 -- For semantic list, just returned unchanged
8740 return Union_Id (New_L);
8743 -- Anything other than a list or a node is returned unchanged
8748 end Copy_Field_With_Replacement;
8750 -- Start of processing for Copy_Node_With_Replacement
8753 if Old_Node <= Empty_Or_Error then
8756 elsif Has_Extension (Old_Node) then
8757 return Assoc (Old_Node);
8760 New_Node := New_Copy (Old_Node);
8762 -- If the node we are copying is the associated node of a
8763 -- previously copied Itype, then adjust the associated node
8764 -- of the copy of that Itype accordingly.
8766 if Present (Actual_Map) then
8772 -- Case of hash table used
8774 if NCT_Hash_Tables_Used then
8775 Ent := NCT_Itype_Assoc.Get (Old_Node);
8777 if Present (Ent) then
8778 Set_Associated_Node_For_Itype (Ent, New_Node);
8781 -- Case of no hash table used
8784 E := First_Elmt (Actual_Map);
8785 while Present (E) loop
8786 if Is_Itype (Node (E))
8788 Old_Node = Associated_Node_For_Itype (Node (E))
8790 Set_Associated_Node_For_Itype
8791 (Node (Next_Elmt (E)), New_Node);
8794 E := Next_Elmt (Next_Elmt (E));
8800 -- Recursively copy descendents
8803 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8805 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8807 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8809 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8811 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8813 -- Adjust Sloc of new node if necessary
8815 if New_Sloc /= No_Location then
8816 Set_Sloc (New_Node, New_Sloc);
8818 -- If we adjust the Sloc, then we are essentially making
8819 -- a completely new node, so the Comes_From_Source flag
8820 -- should be reset to the proper default value.
8822 Nodes.Table (New_Node).Comes_From_Source :=
8823 Default_Node.Comes_From_Source;
8826 -- If the node is call and has named associations,
8827 -- set the corresponding links in the copy.
8829 if (Nkind (Old_Node) = N_Function_Call
8830 or else Nkind (Old_Node) = N_Entry_Call_Statement
8832 Nkind (Old_Node) = N_Procedure_Call_Statement)
8833 and then Present (First_Named_Actual (Old_Node))
8835 Adjust_Named_Associations (Old_Node, New_Node);
8838 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8839 -- The replacement mechanism applies to entities, and is not used
8840 -- here. Eventually we may need a more general graph-copying
8841 -- routine. For now, do a sequential search to find desired node.
8843 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8844 and then Present (First_Real_Statement (Old_Node))
8847 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8851 N1 := First (Statements (Old_Node));
8852 N2 := First (Statements (New_Node));
8854 while N1 /= Old_F loop
8859 Set_First_Real_Statement (New_Node, N2);
8864 -- All done, return copied node
8867 end Copy_Node_With_Replacement;
8873 procedure Visit_Elist (E : Elist_Id) is
8877 Elmt := First_Elmt (E);
8879 while Elmt /= No_Elmt loop
8880 Visit_Node (Node (Elmt));
8890 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8892 if F = Union_Id (Empty) then
8895 elsif F in Node_Range then
8897 -- Copy node if it is syntactic, i.e. its parent pointer is
8898 -- set to point to the field that referenced it (certain
8899 -- Itypes will also meet this criterion, which is fine, since
8900 -- these are clearly Itypes that do need to be copied, since
8901 -- we are copying their parent.)
8903 if Parent (Node_Id (F)) = N then
8904 Visit_Node (Node_Id (F));
8907 -- Another case, if we are pointing to an Itype, then we want
8908 -- to copy it if its associated node is somewhere in the tree
8911 -- Note: the exclusion of self-referential copies is just an
8912 -- optimization, since the search of the already copied list
8913 -- would catch it, but it is a common case (Etype pointing
8914 -- to itself for an Itype that is a base type).
8916 elsif Has_Extension (Node_Id (F))
8917 and then Is_Itype (Entity_Id (F))
8918 and then Node_Id (F) /= N
8924 P := Associated_Node_For_Itype (Node_Id (F));
8925 while Present (P) loop
8927 Visit_Node (Node_Id (F));
8934 -- An Itype whose parent is not being copied definitely
8935 -- should NOT be copied, since it does not belong in any
8936 -- sense to the copied subtree.
8942 elsif F in List_Range
8943 and then Parent (List_Id (F)) = N
8945 Visit_List (List_Id (F));
8954 procedure Visit_Itype (Old_Itype : Entity_Id) is
8955 New_Itype : Entity_Id;
8960 -- Itypes that describe the designated type of access to subprograms
8961 -- have the structure of subprogram declarations, with signatures,
8962 -- etc. Either we duplicate the signatures completely, or choose to
8963 -- share such itypes, which is fine because their elaboration will
8964 -- have no side effects.
8966 if Ekind (Old_Itype) = E_Subprogram_Type then
8970 New_Itype := New_Copy (Old_Itype);
8972 -- The new Itype has all the attributes of the old one, and
8973 -- we just copy the contents of the entity. However, the back-end
8974 -- needs different names for debugging purposes, so we create a
8975 -- new internal name for it in all cases.
8977 Set_Chars (New_Itype, New_Internal_Name ('T'));
8979 -- If our associated node is an entity that has already been copied,
8980 -- then set the associated node of the copy to point to the right
8981 -- copy. If we have copied an Itype that is itself the associated
8982 -- node of some previously copied Itype, then we set the right
8983 -- pointer in the other direction.
8985 if Present (Actual_Map) then
8987 -- Case of hash tables used
8989 if NCT_Hash_Tables_Used then
8991 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8993 if Present (Ent) then
8994 Set_Associated_Node_For_Itype (New_Itype, Ent);
8997 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8998 if Present (Ent) then
8999 Set_Associated_Node_For_Itype (Ent, New_Itype);
9001 -- If the hash table has no association for this Itype and
9002 -- its associated node, enter one now.
9006 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9009 -- Case of hash tables not used
9012 E := First_Elmt (Actual_Map);
9013 while Present (E) loop
9014 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9015 Set_Associated_Node_For_Itype
9016 (New_Itype, Node (Next_Elmt (E)));
9019 if Is_Type (Node (E))
9021 Old_Itype = Associated_Node_For_Itype (Node (E))
9023 Set_Associated_Node_For_Itype
9024 (Node (Next_Elmt (E)), New_Itype);
9027 E := Next_Elmt (Next_Elmt (E));
9032 if Present (Freeze_Node (New_Itype)) then
9033 Set_Is_Frozen (New_Itype, False);
9034 Set_Freeze_Node (New_Itype, Empty);
9037 -- Add new association to map
9039 if No (Actual_Map) then
9040 Actual_Map := New_Elmt_List;
9043 Append_Elmt (Old_Itype, Actual_Map);
9044 Append_Elmt (New_Itype, Actual_Map);
9046 if NCT_Hash_Tables_Used then
9047 NCT_Assoc.Set (Old_Itype, New_Itype);
9050 NCT_Table_Entries := NCT_Table_Entries + 1;
9052 if NCT_Table_Entries > NCT_Hash_Threshold then
9053 Build_NCT_Hash_Tables;
9057 -- If a record subtype is simply copied, the entity list will be
9058 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9060 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9061 Set_Cloned_Subtype (New_Itype, Old_Itype);
9064 -- Visit descendents that eventually get copied
9066 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9068 if Is_Discrete_Type (Old_Itype) then
9069 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9071 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9072 -- ??? This should involve call to Visit_Field
9073 Visit_Elist (Discriminant_Constraint (Old_Itype));
9075 elsif Is_Array_Type (Old_Itype) then
9076 if Present (First_Index (Old_Itype)) then
9077 Visit_Field (Union_Id (List_Containing
9078 (First_Index (Old_Itype))),
9082 if Is_Packed (Old_Itype) then
9083 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9093 procedure Visit_List (L : List_Id) is
9096 if L /= No_List then
9099 while Present (N) loop
9110 procedure Visit_Node (N : Node_Or_Entity_Id) is
9112 -- Start of processing for Visit_Node
9115 -- Handle case of an Itype, which must be copied
9117 if Has_Extension (N)
9118 and then Is_Itype (N)
9120 -- Nothing to do if already in the list. This can happen with an
9121 -- Itype entity that appears more than once in the tree.
9122 -- Note that we do not want to visit descendents in this case.
9124 -- Test for already in list when hash table is used
9126 if NCT_Hash_Tables_Used then
9127 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9131 -- Test for already in list when hash table not used
9137 if Present (Actual_Map) then
9138 E := First_Elmt (Actual_Map);
9139 while Present (E) loop
9140 if Node (E) = N then
9143 E := Next_Elmt (Next_Elmt (E));
9153 -- Visit descendents
9155 Visit_Field (Field1 (N), N);
9156 Visit_Field (Field2 (N), N);
9157 Visit_Field (Field3 (N), N);
9158 Visit_Field (Field4 (N), N);
9159 Visit_Field (Field5 (N), N);
9162 -- Start of processing for New_Copy_Tree
9167 -- See if we should use hash table
9169 if No (Actual_Map) then
9170 NCT_Hash_Tables_Used := False;
9177 NCT_Table_Entries := 0;
9179 Elmt := First_Elmt (Actual_Map);
9180 while Present (Elmt) loop
9181 NCT_Table_Entries := NCT_Table_Entries + 1;
9186 if NCT_Table_Entries > NCT_Hash_Threshold then
9187 Build_NCT_Hash_Tables;
9189 NCT_Hash_Tables_Used := False;
9194 -- Hash table set up if required, now start phase one by visiting
9195 -- top node (we will recursively visit the descendents).
9197 Visit_Node (Source);
9199 -- Now the second phase of the copy can start. First we process
9200 -- all the mapped entities, copying their descendents.
9202 if Present (Actual_Map) then
9205 New_Itype : Entity_Id;
9207 Elmt := First_Elmt (Actual_Map);
9208 while Present (Elmt) loop
9210 New_Itype := Node (Elmt);
9211 Copy_Itype_With_Replacement (New_Itype);
9217 -- Now we can copy the actual tree
9219 return Copy_Node_With_Replacement (Source);
9222 -------------------------
9223 -- New_External_Entity --
9224 -------------------------
9226 function New_External_Entity
9227 (Kind : Entity_Kind;
9228 Scope_Id : Entity_Id;
9229 Sloc_Value : Source_Ptr;
9230 Related_Id : Entity_Id;
9232 Suffix_Index : Nat := 0;
9233 Prefix : Character := ' ') return Entity_Id
9235 N : constant Entity_Id :=
9236 Make_Defining_Identifier (Sloc_Value,
9238 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9241 Set_Ekind (N, Kind);
9242 Set_Is_Internal (N, True);
9243 Append_Entity (N, Scope_Id);
9244 Set_Public_Status (N);
9246 if Kind in Type_Kind then
9247 Init_Size_Align (N);
9251 end New_External_Entity;
9253 -------------------------
9254 -- New_Internal_Entity --
9255 -------------------------
9257 function New_Internal_Entity
9258 (Kind : Entity_Kind;
9259 Scope_Id : Entity_Id;
9260 Sloc_Value : Source_Ptr;
9261 Id_Char : Character) return Entity_Id
9263 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9266 Set_Ekind (N, Kind);
9267 Set_Is_Internal (N, True);
9268 Append_Entity (N, Scope_Id);
9270 if Kind in Type_Kind then
9271 Init_Size_Align (N);
9275 end New_Internal_Entity;
9281 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9285 -- If we are pointing at a positional parameter, it is a member of a
9286 -- node list (the list of parameters), and the next parameter is the
9287 -- next node on the list, unless we hit a parameter association, then
9288 -- we shift to using the chain whose head is the First_Named_Actual in
9289 -- the parent, and then is threaded using the Next_Named_Actual of the
9290 -- Parameter_Association. All this fiddling is because the original node
9291 -- list is in the textual call order, and what we need is the
9292 -- declaration order.
9294 if Is_List_Member (Actual_Id) then
9295 N := Next (Actual_Id);
9297 if Nkind (N) = N_Parameter_Association then
9298 return First_Named_Actual (Parent (Actual_Id));
9304 return Next_Named_Actual (Parent (Actual_Id));
9308 procedure Next_Actual (Actual_Id : in out Node_Id) is
9310 Actual_Id := Next_Actual (Actual_Id);
9313 -----------------------
9314 -- Normalize_Actuals --
9315 -----------------------
9317 -- Chain actuals according to formals of subprogram. If there are no named
9318 -- associations, the chain is simply the list of Parameter Associations,
9319 -- since the order is the same as the declaration order. If there are named
9320 -- associations, then the First_Named_Actual field in the N_Function_Call
9321 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9322 -- node for the parameter that comes first in declaration order. The
9323 -- remaining named parameters are then chained in declaration order using
9324 -- Next_Named_Actual.
9326 -- This routine also verifies that the number of actuals is compatible with
9327 -- the number and default values of formals, but performs no type checking
9328 -- (type checking is done by the caller).
9330 -- If the matching succeeds, Success is set to True and the caller proceeds
9331 -- with type-checking. If the match is unsuccessful, then Success is set to
9332 -- False, and the caller attempts a different interpretation, if there is
9335 -- If the flag Report is on, the call is not overloaded, and a failure to
9336 -- match can be reported here, rather than in the caller.
9338 procedure Normalize_Actuals
9342 Success : out Boolean)
9344 Actuals : constant List_Id := Parameter_Associations (N);
9345 Actual : Node_Id := Empty;
9347 Last : Node_Id := Empty;
9348 First_Named : Node_Id := Empty;
9351 Formals_To_Match : Integer := 0;
9352 Actuals_To_Match : Integer := 0;
9354 procedure Chain (A : Node_Id);
9355 -- Add named actual at the proper place in the list, using the
9356 -- Next_Named_Actual link.
9358 function Reporting return Boolean;
9359 -- Determines if an error is to be reported. To report an error, we
9360 -- need Report to be True, and also we do not report errors caused
9361 -- by calls to init procs that occur within other init procs. Such
9362 -- errors must always be cascaded errors, since if all the types are
9363 -- declared correctly, the compiler will certainly build decent calls!
9369 procedure Chain (A : Node_Id) is
9373 -- Call node points to first actual in list
9375 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9378 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9382 Set_Next_Named_Actual (Last, Empty);
9389 function Reporting return Boolean is
9394 elsif not Within_Init_Proc then
9397 elsif Is_Init_Proc (Entity (Name (N))) then
9405 -- Start of processing for Normalize_Actuals
9408 if Is_Access_Type (S) then
9410 -- The name in the call is a function call that returns an access
9411 -- to subprogram. The designated type has the list of formals.
9413 Formal := First_Formal (Designated_Type (S));
9415 Formal := First_Formal (S);
9418 while Present (Formal) loop
9419 Formals_To_Match := Formals_To_Match + 1;
9420 Next_Formal (Formal);
9423 -- Find if there is a named association, and verify that no positional
9424 -- associations appear after named ones.
9426 if Present (Actuals) then
9427 Actual := First (Actuals);
9430 while Present (Actual)
9431 and then Nkind (Actual) /= N_Parameter_Association
9433 Actuals_To_Match := Actuals_To_Match + 1;
9437 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9439 -- Most common case: positional notation, no defaults
9444 elsif Actuals_To_Match > Formals_To_Match then
9446 -- Too many actuals: will not work
9449 if Is_Entity_Name (Name (N)) then
9450 Error_Msg_N ("too many arguments in call to&", Name (N));
9452 Error_Msg_N ("too many arguments in call", N);
9460 First_Named := Actual;
9462 while Present (Actual) loop
9463 if Nkind (Actual) /= N_Parameter_Association then
9465 ("positional parameters not allowed after named ones", Actual);
9470 Actuals_To_Match := Actuals_To_Match + 1;
9476 if Present (Actuals) then
9477 Actual := First (Actuals);
9480 Formal := First_Formal (S);
9481 while Present (Formal) loop
9483 -- Match the formals in order. If the corresponding actual is
9484 -- positional, nothing to do. Else scan the list of named actuals
9485 -- to find the one with the right name.
9488 and then Nkind (Actual) /= N_Parameter_Association
9491 Actuals_To_Match := Actuals_To_Match - 1;
9492 Formals_To_Match := Formals_To_Match - 1;
9495 -- For named parameters, search the list of actuals to find
9496 -- one that matches the next formal name.
9498 Actual := First_Named;
9500 while Present (Actual) loop
9501 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9504 Actuals_To_Match := Actuals_To_Match - 1;
9505 Formals_To_Match := Formals_To_Match - 1;
9513 if Ekind (Formal) /= E_In_Parameter
9514 or else No (Default_Value (Formal))
9517 if (Comes_From_Source (S)
9518 or else Sloc (S) = Standard_Location)
9519 and then Is_Overloadable (S)
9523 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9525 (Nkind (Parent (N)) = N_Function_Call
9527 Nkind (Parent (N)) = N_Parameter_Association))
9528 and then Ekind (S) /= E_Function
9530 Set_Etype (N, Etype (S));
9532 Error_Msg_Name_1 := Chars (S);
9533 Error_Msg_Sloc := Sloc (S);
9535 ("missing argument for parameter & " &
9536 "in call to % declared #", N, Formal);
9539 elsif Is_Overloadable (S) then
9540 Error_Msg_Name_1 := Chars (S);
9542 -- Point to type derivation that generated the
9545 Error_Msg_Sloc := Sloc (Parent (S));
9548 ("missing argument for parameter & " &
9549 "in call to % (inherited) #", N, Formal);
9553 ("missing argument for parameter &", N, Formal);
9561 Formals_To_Match := Formals_To_Match - 1;
9566 Next_Formal (Formal);
9569 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9576 -- Find some superfluous named actual that did not get
9577 -- attached to the list of associations.
9579 Actual := First (Actuals);
9580 while Present (Actual) loop
9581 if Nkind (Actual) = N_Parameter_Association
9582 and then Actual /= Last
9583 and then No (Next_Named_Actual (Actual))
9585 Error_Msg_N ("unmatched actual & in call",
9586 Selector_Name (Actual));
9597 end Normalize_Actuals;
9599 --------------------------------
9600 -- Note_Possible_Modification --
9601 --------------------------------
9603 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9604 Modification_Comes_From_Source : constant Boolean :=
9605 Comes_From_Source (Parent (N));
9611 -- Loop to find referenced entity, if there is one
9618 if Is_Entity_Name (Exp) then
9619 Ent := Entity (Exp);
9621 -- If the entity is missing, it is an undeclared identifier,
9622 -- and there is nothing to annotate.
9628 elsif Nkind (Exp) = N_Explicit_Dereference then
9630 P : constant Node_Id := Prefix (Exp);
9633 if Nkind (P) = N_Selected_Component
9635 Entry_Formal (Entity (Selector_Name (P))))
9637 -- Case of a reference to an entry formal
9639 Ent := Entry_Formal (Entity (Selector_Name (P)));
9641 elsif Nkind (P) = N_Identifier
9642 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9643 and then Present (Expression (Parent (Entity (P))))
9644 and then Nkind (Expression (Parent (Entity (P))))
9647 -- Case of a reference to a value on which side effects have
9650 Exp := Prefix (Expression (Parent (Entity (P))));
9659 elsif Nkind (Exp) = N_Type_Conversion
9660 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9662 Exp := Expression (Exp);
9665 elsif Nkind (Exp) = N_Slice
9666 or else Nkind (Exp) = N_Indexed_Component
9667 or else Nkind (Exp) = N_Selected_Component
9669 Exp := Prefix (Exp);
9676 -- Now look for entity being referenced
9678 if Present (Ent) then
9679 if Is_Object (Ent) then
9680 if Comes_From_Source (Exp)
9681 or else Modification_Comes_From_Source
9683 -- Give warning if pragma unmodified given and we are
9684 -- sure this is a modification.
9686 if Has_Pragma_Unmodified (Ent) and then Sure then
9687 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9690 Set_Never_Set_In_Source (Ent, False);
9693 Set_Is_True_Constant (Ent, False);
9694 Set_Current_Value (Ent, Empty);
9695 Set_Is_Known_Null (Ent, False);
9697 if not Can_Never_Be_Null (Ent) then
9698 Set_Is_Known_Non_Null (Ent, False);
9701 -- Follow renaming chain
9703 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9704 and then Present (Renamed_Object (Ent))
9706 Exp := Renamed_Object (Ent);
9710 -- Generate a reference only if the assignment comes from
9711 -- source. This excludes, for example, calls to a dispatching
9712 -- assignment operation when the left-hand side is tagged.
9714 if Modification_Comes_From_Source then
9715 Generate_Reference (Ent, Exp, 'm');
9717 -- If the target of the assignment is the bound variable
9718 -- in an iterator, indicate that the corresponding array
9719 -- or container is also modified.
9721 if Ada_Version >= Ada_2012
9723 Nkind (Parent (Ent)) = N_Iterator_Specification
9726 Domain : constant Node_Id := Name (Parent (Ent));
9729 -- TBD : in the full version of the construct, the
9730 -- domain of iteration can be given by an expression.
9732 if Is_Entity_Name (Domain) then
9733 Generate_Reference (Entity (Domain), Exp, 'm');
9734 Set_Is_True_Constant (Entity (Domain), False);
9735 Set_Never_Set_In_Source (Entity (Domain), False);
9741 Check_Nested_Access (Ent);
9746 -- If we are sure this is a modification from source, and we know
9747 -- this modifies a constant, then give an appropriate warning.
9749 if Overlays_Constant (Ent)
9750 and then Modification_Comes_From_Source
9754 A : constant Node_Id := Address_Clause (Ent);
9758 Exp : constant Node_Id := Expression (A);
9760 if Nkind (Exp) = N_Attribute_Reference
9761 and then Attribute_Name (Exp) = Name_Address
9762 and then Is_Entity_Name (Prefix (Exp))
9764 Error_Msg_Sloc := Sloc (A);
9766 ("constant& may be modified via address clause#?",
9767 N, Entity (Prefix (Exp)));
9777 end Note_Possible_Modification;
9779 -------------------------
9780 -- Object_Access_Level --
9781 -------------------------
9783 function Object_Access_Level (Obj : Node_Id) return Uint is
9786 -- Returns the static accessibility level of the view denoted by Obj. Note
9787 -- that the value returned is the result of a call to Scope_Depth. Only
9788 -- scope depths associated with dynamic scopes can actually be returned.
9789 -- Since only relative levels matter for accessibility checking, the fact
9790 -- that the distance between successive levels of accessibility is not
9791 -- always one is immaterial (invariant: if level(E2) is deeper than
9792 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9794 function Reference_To (Obj : Node_Id) return Node_Id;
9795 -- An explicit dereference is created when removing side-effects from
9796 -- expressions for constraint checking purposes. In this case a local
9797 -- access type is created for it. The correct access level is that of
9798 -- the original source node. We detect this case by noting that the
9799 -- prefix of the dereference is created by an object declaration whose
9800 -- initial expression is a reference.
9806 function Reference_To (Obj : Node_Id) return Node_Id is
9807 Pref : constant Node_Id := Prefix (Obj);
9809 if Is_Entity_Name (Pref)
9810 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9811 and then Present (Expression (Parent (Entity (Pref))))
9812 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9814 return (Prefix (Expression (Parent (Entity (Pref)))));
9820 -- Start of processing for Object_Access_Level
9823 if Is_Entity_Name (Obj) then
9826 if Is_Prival (E) then
9827 E := Prival_Link (E);
9830 -- If E is a type then it denotes a current instance. For this case
9831 -- we add one to the normal accessibility level of the type to ensure
9832 -- that current instances are treated as always being deeper than
9833 -- than the level of any visible named access type (see 3.10.2(21)).
9836 return Type_Access_Level (E) + 1;
9838 elsif Present (Renamed_Object (E)) then
9839 return Object_Access_Level (Renamed_Object (E));
9841 -- Similarly, if E is a component of the current instance of a
9842 -- protected type, any instance of it is assumed to be at a deeper
9843 -- level than the type. For a protected object (whose type is an
9844 -- anonymous protected type) its components are at the same level
9845 -- as the type itself.
9847 elsif not Is_Overloadable (E)
9848 and then Ekind (Scope (E)) = E_Protected_Type
9849 and then Comes_From_Source (Scope (E))
9851 return Type_Access_Level (Scope (E)) + 1;
9854 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9857 elsif Nkind (Obj) = N_Selected_Component then
9858 if Is_Access_Type (Etype (Prefix (Obj))) then
9859 return Type_Access_Level (Etype (Prefix (Obj)));
9861 return Object_Access_Level (Prefix (Obj));
9864 elsif Nkind (Obj) = N_Indexed_Component then
9865 if Is_Access_Type (Etype (Prefix (Obj))) then
9866 return Type_Access_Level (Etype (Prefix (Obj)));
9868 return Object_Access_Level (Prefix (Obj));
9871 elsif Nkind (Obj) = N_Explicit_Dereference then
9873 -- If the prefix is a selected access discriminant then we make a
9874 -- recursive call on the prefix, which will in turn check the level
9875 -- of the prefix object of the selected discriminant.
9877 if Nkind (Prefix (Obj)) = N_Selected_Component
9878 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9880 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9882 return Object_Access_Level (Prefix (Obj));
9884 elsif not (Comes_From_Source (Obj)) then
9886 Ref : constant Node_Id := Reference_To (Obj);
9888 if Present (Ref) then
9889 return Object_Access_Level (Ref);
9891 return Type_Access_Level (Etype (Prefix (Obj)));
9896 return Type_Access_Level (Etype (Prefix (Obj)));
9899 elsif Nkind (Obj) = N_Type_Conversion
9900 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9902 return Object_Access_Level (Expression (Obj));
9904 elsif Nkind (Obj) = N_Function_Call then
9906 -- Function results are objects, so we get either the access level of
9907 -- the function or, in the case of an indirect call, the level of the
9908 -- access-to-subprogram type. (This code is used for Ada 95, but it
9909 -- looks wrong, because it seems that we should be checking the level
9910 -- of the call itself, even for Ada 95. However, using the Ada 2005
9911 -- version of the code causes regressions in several tests that are
9912 -- compiled with -gnat95. ???)
9914 if Ada_Version < Ada_2005 then
9915 if Is_Entity_Name (Name (Obj)) then
9916 return Subprogram_Access_Level (Entity (Name (Obj)));
9918 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9921 -- For Ada 2005, the level of the result object of a function call is
9922 -- defined to be the level of the call's innermost enclosing master.
9923 -- We determine that by querying the depth of the innermost enclosing
9927 Return_Master_Scope_Depth_Of_Call : declare
9929 function Innermost_Master_Scope_Depth
9930 (N : Node_Id) return Uint;
9931 -- Returns the scope depth of the given node's innermost
9932 -- enclosing dynamic scope (effectively the accessibility
9933 -- level of the innermost enclosing master).
9935 ----------------------------------
9936 -- Innermost_Master_Scope_Depth --
9937 ----------------------------------
9939 function Innermost_Master_Scope_Depth
9940 (N : Node_Id) return Uint
9942 Node_Par : Node_Id := Parent (N);
9945 -- Locate the nearest enclosing node (by traversing Parents)
9946 -- that Defining_Entity can be applied to, and return the
9947 -- depth of that entity's nearest enclosing dynamic scope.
9949 while Present (Node_Par) loop
9950 case Nkind (Node_Par) is
9951 when N_Component_Declaration |
9952 N_Entry_Declaration |
9953 N_Formal_Object_Declaration |
9954 N_Formal_Type_Declaration |
9955 N_Full_Type_Declaration |
9956 N_Incomplete_Type_Declaration |
9957 N_Loop_Parameter_Specification |
9958 N_Object_Declaration |
9959 N_Protected_Type_Declaration |
9960 N_Private_Extension_Declaration |
9961 N_Private_Type_Declaration |
9962 N_Subtype_Declaration |
9963 N_Function_Specification |
9964 N_Procedure_Specification |
9965 N_Task_Type_Declaration |
9967 N_Generic_Instantiation |
9969 N_Implicit_Label_Declaration |
9970 N_Package_Declaration |
9971 N_Single_Task_Declaration |
9972 N_Subprogram_Declaration |
9973 N_Generic_Declaration |
9974 N_Renaming_Declaration |
9976 N_Formal_Subprogram_Declaration |
9977 N_Abstract_Subprogram_Declaration |
9979 N_Exception_Declaration |
9980 N_Formal_Package_Declaration |
9981 N_Number_Declaration |
9982 N_Package_Specification |
9983 N_Parameter_Specification |
9984 N_Single_Protected_Declaration |
9988 (Nearest_Dynamic_Scope
9989 (Defining_Entity (Node_Par)));
9995 Node_Par := Parent (Node_Par);
9998 pragma Assert (False);
10000 -- Should never reach the following return
10002 return Scope_Depth (Current_Scope) + 1;
10003 end Innermost_Master_Scope_Depth;
10005 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10008 return Innermost_Master_Scope_Depth (Obj);
10009 end Return_Master_Scope_Depth_Of_Call;
10012 -- For convenience we handle qualified expressions, even though
10013 -- they aren't technically object names.
10015 elsif Nkind (Obj) = N_Qualified_Expression then
10016 return Object_Access_Level (Expression (Obj));
10018 -- Otherwise return the scope level of Standard.
10019 -- (If there are cases that fall through
10020 -- to this point they will be treated as
10021 -- having global accessibility for now. ???)
10024 return Scope_Depth (Standard_Standard);
10026 end Object_Access_Level;
10028 --------------------------------------
10029 -- Original_Corresponding_Operation --
10030 --------------------------------------
10032 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10034 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10037 -- If S is an inherited primitive S2 the original corresponding
10038 -- operation of S is the original corresponding operation of S2
10040 if Present (Alias (S))
10041 and then Find_Dispatching_Type (Alias (S)) /= Typ
10043 return Original_Corresponding_Operation (Alias (S));
10045 -- If S overrides an inherited subprogram S2 the original corresponding
10046 -- operation of S is the original corresponding operation of S2
10048 elsif Present (Overridden_Operation (S)) then
10049 return Original_Corresponding_Operation (Overridden_Operation (S));
10051 -- otherwise it is S itself
10056 end Original_Corresponding_Operation;
10058 -----------------------
10059 -- Private_Component --
10060 -----------------------
10062 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10063 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10065 function Trace_Components
10067 Check : Boolean) return Entity_Id;
10068 -- Recursive function that does the work, and checks against circular
10069 -- definition for each subcomponent type.
10071 ----------------------
10072 -- Trace_Components --
10073 ----------------------
10075 function Trace_Components
10077 Check : Boolean) return Entity_Id
10079 Btype : constant Entity_Id := Base_Type (T);
10080 Component : Entity_Id;
10082 Candidate : Entity_Id := Empty;
10085 if Check and then Btype = Ancestor then
10086 Error_Msg_N ("circular type definition", Type_Id);
10090 if Is_Private_Type (Btype)
10091 and then not Is_Generic_Type (Btype)
10093 if Present (Full_View (Btype))
10094 and then Is_Record_Type (Full_View (Btype))
10095 and then not Is_Frozen (Btype)
10097 -- To indicate that the ancestor depends on a private type, the
10098 -- current Btype is sufficient. However, to check for circular
10099 -- definition we must recurse on the full view.
10101 Candidate := Trace_Components (Full_View (Btype), True);
10103 if Candidate = Any_Type then
10113 elsif Is_Array_Type (Btype) then
10114 return Trace_Components (Component_Type (Btype), True);
10116 elsif Is_Record_Type (Btype) then
10117 Component := First_Entity (Btype);
10118 while Present (Component) loop
10120 -- Skip anonymous types generated by constrained components
10122 if not Is_Type (Component) then
10123 P := Trace_Components (Etype (Component), True);
10125 if Present (P) then
10126 if P = Any_Type then
10134 Next_Entity (Component);
10142 end Trace_Components;
10144 -- Start of processing for Private_Component
10147 return Trace_Components (Type_Id, False);
10148 end Private_Component;
10150 ---------------------------
10151 -- Primitive_Names_Match --
10152 ---------------------------
10154 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10156 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10157 -- Given an internal name, returns the corresponding non-internal name
10159 ------------------------
10160 -- Non_Internal_Name --
10161 ------------------------
10163 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10165 Get_Name_String (Chars (E));
10166 Name_Len := Name_Len - 1;
10168 end Non_Internal_Name;
10170 -- Start of processing for Primitive_Names_Match
10173 pragma Assert (Present (E1) and then Present (E2));
10175 return Chars (E1) = Chars (E2)
10177 (not Is_Internal_Name (Chars (E1))
10178 and then Is_Internal_Name (Chars (E2))
10179 and then Non_Internal_Name (E2) = Chars (E1))
10181 (not Is_Internal_Name (Chars (E2))
10182 and then Is_Internal_Name (Chars (E1))
10183 and then Non_Internal_Name (E1) = Chars (E2))
10185 (Is_Predefined_Dispatching_Operation (E1)
10186 and then Is_Predefined_Dispatching_Operation (E2)
10187 and then Same_TSS (E1, E2))
10189 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10190 end Primitive_Names_Match;
10192 -----------------------
10193 -- Process_End_Label --
10194 -----------------------
10196 procedure Process_End_Label
10205 Label_Ref : Boolean;
10206 -- Set True if reference to end label itself is required
10209 -- Gets set to the operator symbol or identifier that references the
10210 -- entity Ent. For the child unit case, this is the identifier from the
10211 -- designator. For other cases, this is simply Endl.
10213 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10214 -- N is an identifier node that appears as a parent unit reference in
10215 -- the case where Ent is a child unit. This procedure generates an
10216 -- appropriate cross-reference entry. E is the corresponding entity.
10218 -------------------------
10219 -- Generate_Parent_Ref --
10220 -------------------------
10222 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10224 -- If names do not match, something weird, skip reference
10226 if Chars (E) = Chars (N) then
10228 -- Generate the reference. We do NOT consider this as a reference
10229 -- for unreferenced symbol purposes.
10231 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10233 if Style_Check then
10234 Style.Check_Identifier (N, E);
10237 end Generate_Parent_Ref;
10239 -- Start of processing for Process_End_Label
10242 -- If no node, ignore. This happens in some error situations, and
10243 -- also for some internally generated structures where no end label
10244 -- references are required in any case.
10250 -- Nothing to do if no End_Label, happens for internally generated
10251 -- constructs where we don't want an end label reference anyway. Also
10252 -- nothing to do if Endl is a string literal, which means there was
10253 -- some prior error (bad operator symbol)
10255 Endl := End_Label (N);
10257 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10261 -- Reference node is not in extended main source unit
10263 if not In_Extended_Main_Source_Unit (N) then
10265 -- Generally we do not collect references except for the extended
10266 -- main source unit. The one exception is the 'e' entry for a
10267 -- package spec, where it is useful for a client to have the
10268 -- ending information to define scopes.
10274 Label_Ref := False;
10276 -- For this case, we can ignore any parent references, but we
10277 -- need the package name itself for the 'e' entry.
10279 if Nkind (Endl) = N_Designator then
10280 Endl := Identifier (Endl);
10284 -- Reference is in extended main source unit
10289 -- For designator, generate references for the parent entries
10291 if Nkind (Endl) = N_Designator then
10293 -- Generate references for the prefix if the END line comes from
10294 -- source (otherwise we do not need these references) We climb the
10295 -- scope stack to find the expected entities.
10297 if Comes_From_Source (Endl) then
10298 Nam := Name (Endl);
10299 Scop := Current_Scope;
10300 while Nkind (Nam) = N_Selected_Component loop
10301 Scop := Scope (Scop);
10302 exit when No (Scop);
10303 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10304 Nam := Prefix (Nam);
10307 if Present (Scop) then
10308 Generate_Parent_Ref (Nam, Scope (Scop));
10312 Endl := Identifier (Endl);
10316 -- If the end label is not for the given entity, then either we have
10317 -- some previous error, or this is a generic instantiation for which
10318 -- we do not need to make a cross-reference in this case anyway. In
10319 -- either case we simply ignore the call.
10321 if Chars (Ent) /= Chars (Endl) then
10325 -- If label was really there, then generate a normal reference and then
10326 -- adjust the location in the end label to point past the name (which
10327 -- should almost always be the semicolon).
10329 Loc := Sloc (Endl);
10331 if Comes_From_Source (Endl) then
10333 -- If a label reference is required, then do the style check and
10334 -- generate an l-type cross-reference entry for the label
10337 if Style_Check then
10338 Style.Check_Identifier (Endl, Ent);
10341 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10344 -- Set the location to point past the label (normally this will
10345 -- mean the semicolon immediately following the label). This is
10346 -- done for the sake of the 'e' or 't' entry generated below.
10348 Get_Decoded_Name_String (Chars (Endl));
10349 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10352 -- Now generate the e/t reference
10354 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10356 -- Restore Sloc, in case modified above, since we have an identifier
10357 -- and the normal Sloc should be left set in the tree.
10359 Set_Sloc (Endl, Loc);
10360 end Process_End_Label;
10362 ------------------------------------
10363 -- References_Generic_Formal_Type --
10364 ------------------------------------
10366 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10368 function Process (N : Node_Id) return Traverse_Result;
10369 -- Process one node in search for generic formal type
10375 function Process (N : Node_Id) return Traverse_Result is
10377 if Nkind (N) in N_Has_Entity then
10379 E : constant Entity_Id := Entity (N);
10381 if Present (E) then
10382 if Is_Generic_Type (E) then
10384 elsif Present (Etype (E))
10385 and then Is_Generic_Type (Etype (E))
10396 function Traverse is new Traverse_Func (Process);
10397 -- Traverse tree to look for generic type
10400 if Inside_A_Generic then
10401 return Traverse (N) = Abandon;
10405 end References_Generic_Formal_Type;
10407 --------------------
10408 -- Remove_Homonym --
10409 --------------------
10411 procedure Remove_Homonym (E : Entity_Id) is
10412 Prev : Entity_Id := Empty;
10416 if E = Current_Entity (E) then
10417 if Present (Homonym (E)) then
10418 Set_Current_Entity (Homonym (E));
10420 Set_Name_Entity_Id (Chars (E), Empty);
10423 H := Current_Entity (E);
10424 while Present (H) and then H /= E loop
10429 Set_Homonym (Prev, Homonym (E));
10431 end Remove_Homonym;
10433 ---------------------
10434 -- Rep_To_Pos_Flag --
10435 ---------------------
10437 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10439 return New_Occurrence_Of
10440 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10441 end Rep_To_Pos_Flag;
10443 --------------------
10444 -- Require_Entity --
10445 --------------------
10447 procedure Require_Entity (N : Node_Id) is
10449 if Is_Entity_Name (N) and then No (Entity (N)) then
10450 if Total_Errors_Detected /= 0 then
10451 Set_Entity (N, Any_Id);
10453 raise Program_Error;
10456 end Require_Entity;
10458 ------------------------------
10459 -- Requires_Transient_Scope --
10460 ------------------------------
10462 -- A transient scope is required when variable-sized temporaries are
10463 -- allocated in the primary or secondary stack, or when finalization
10464 -- actions must be generated before the next instruction.
10466 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10467 Typ : constant Entity_Id := Underlying_Type (Id);
10469 -- Start of processing for Requires_Transient_Scope
10472 -- This is a private type which is not completed yet. This can only
10473 -- happen in a default expression (of a formal parameter or of a
10474 -- record component). Do not expand transient scope in this case
10479 -- Do not expand transient scope for non-existent procedure return
10481 elsif Typ = Standard_Void_Type then
10484 -- Elementary types do not require a transient scope
10486 elsif Is_Elementary_Type (Typ) then
10489 -- Generally, indefinite subtypes require a transient scope, since the
10490 -- back end cannot generate temporaries, since this is not a valid type
10491 -- for declaring an object. It might be possible to relax this in the
10492 -- future, e.g. by declaring the maximum possible space for the type.
10494 elsif Is_Indefinite_Subtype (Typ) then
10497 -- Functions returning tagged types may dispatch on result so their
10498 -- returned value is allocated on the secondary stack. Controlled
10499 -- type temporaries need finalization.
10501 elsif Is_Tagged_Type (Typ)
10502 or else Has_Controlled_Component (Typ)
10504 return not Is_Value_Type (Typ);
10508 elsif Is_Record_Type (Typ) then
10512 Comp := First_Entity (Typ);
10513 while Present (Comp) loop
10514 if Ekind (Comp) = E_Component
10515 and then Requires_Transient_Scope (Etype (Comp))
10519 Next_Entity (Comp);
10526 -- String literal types never require transient scope
10528 elsif Ekind (Typ) = E_String_Literal_Subtype then
10531 -- Array type. Note that we already know that this is a constrained
10532 -- array, since unconstrained arrays will fail the indefinite test.
10534 elsif Is_Array_Type (Typ) then
10536 -- If component type requires a transient scope, the array does too
10538 if Requires_Transient_Scope (Component_Type (Typ)) then
10541 -- Otherwise, we only need a transient scope if the size depends on
10542 -- the value of one or more discriminants.
10545 return Size_Depends_On_Discriminant (Typ);
10548 -- All other cases do not require a transient scope
10553 end Requires_Transient_Scope;
10555 --------------------------
10556 -- Reset_Analyzed_Flags --
10557 --------------------------
10559 procedure Reset_Analyzed_Flags (N : Node_Id) is
10561 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10562 -- Function used to reset Analyzed flags in tree. Note that we do
10563 -- not reset Analyzed flags in entities, since there is no need to
10564 -- reanalyze entities, and indeed, it is wrong to do so, since it
10565 -- can result in generating auxiliary stuff more than once.
10567 --------------------
10568 -- Clear_Analyzed --
10569 --------------------
10571 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10573 if not Has_Extension (N) then
10574 Set_Analyzed (N, False);
10578 end Clear_Analyzed;
10580 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10582 -- Start of processing for Reset_Analyzed_Flags
10585 Reset_Analyzed (N);
10586 end Reset_Analyzed_Flags;
10588 ---------------------------
10589 -- Safe_To_Capture_Value --
10590 ---------------------------
10592 function Safe_To_Capture_Value
10595 Cond : Boolean := False) return Boolean
10598 -- The only entities for which we track constant values are variables
10599 -- which are not renamings, constants, out parameters, and in out
10600 -- parameters, so check if we have this case.
10602 -- Note: it may seem odd to track constant values for constants, but in
10603 -- fact this routine is used for other purposes than simply capturing
10604 -- the value. In particular, the setting of Known[_Non]_Null.
10606 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10608 Ekind (Ent) = E_Constant
10610 Ekind (Ent) = E_Out_Parameter
10612 Ekind (Ent) = E_In_Out_Parameter
10616 -- For conditionals, we also allow loop parameters and all formals,
10617 -- including in parameters.
10621 (Ekind (Ent) = E_Loop_Parameter
10623 Ekind (Ent) = E_In_Parameter)
10627 -- For all other cases, not just unsafe, but impossible to capture
10628 -- Current_Value, since the above are the only entities which have
10629 -- Current_Value fields.
10635 -- Skip if volatile or aliased, since funny things might be going on in
10636 -- these cases which we cannot necessarily track. Also skip any variable
10637 -- for which an address clause is given, or whose address is taken. Also
10638 -- never capture value of library level variables (an attempt to do so
10639 -- can occur in the case of package elaboration code).
10641 if Treat_As_Volatile (Ent)
10642 or else Is_Aliased (Ent)
10643 or else Present (Address_Clause (Ent))
10644 or else Address_Taken (Ent)
10645 or else (Is_Library_Level_Entity (Ent)
10646 and then Ekind (Ent) = E_Variable)
10651 -- OK, all above conditions are met. We also require that the scope of
10652 -- the reference be the same as the scope of the entity, not counting
10653 -- packages and blocks and loops.
10656 E_Scope : constant Entity_Id := Scope (Ent);
10657 R_Scope : Entity_Id;
10660 R_Scope := Current_Scope;
10661 while R_Scope /= Standard_Standard loop
10662 exit when R_Scope = E_Scope;
10664 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10667 R_Scope := Scope (R_Scope);
10672 -- We also require that the reference does not appear in a context
10673 -- where it is not sure to be executed (i.e. a conditional context
10674 -- or an exception handler). We skip this if Cond is True, since the
10675 -- capturing of values from conditional tests handles this ok.
10689 while Present (P) loop
10690 if Nkind (P) = N_If_Statement
10691 or else Nkind (P) = N_Case_Statement
10692 or else (Nkind (P) in N_Short_Circuit
10693 and then Desc = Right_Opnd (P))
10694 or else (Nkind (P) = N_Conditional_Expression
10695 and then Desc /= First (Expressions (P)))
10696 or else Nkind (P) = N_Exception_Handler
10697 or else Nkind (P) = N_Selective_Accept
10698 or else Nkind (P) = N_Conditional_Entry_Call
10699 or else Nkind (P) = N_Timed_Entry_Call
10700 or else Nkind (P) = N_Asynchronous_Select
10710 -- OK, looks safe to set value
10713 end Safe_To_Capture_Value;
10719 function Same_Name (N1, N2 : Node_Id) return Boolean is
10720 K1 : constant Node_Kind := Nkind (N1);
10721 K2 : constant Node_Kind := Nkind (N2);
10724 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10725 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10727 return Chars (N1) = Chars (N2);
10729 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10730 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10732 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10733 and then Same_Name (Prefix (N1), Prefix (N2));
10744 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10745 N1 : constant Node_Id := Original_Node (Node1);
10746 N2 : constant Node_Id := Original_Node (Node2);
10747 -- We do the tests on original nodes, since we are most interested
10748 -- in the original source, not any expansion that got in the way.
10750 K1 : constant Node_Kind := Nkind (N1);
10751 K2 : constant Node_Kind := Nkind (N2);
10754 -- First case, both are entities with same entity
10756 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
10758 EN1 : constant Entity_Id := Entity (N1);
10759 EN2 : constant Entity_Id := Entity (N2);
10761 if Present (EN1) and then Present (EN2)
10762 and then (Ekind_In (EN1, E_Variable, E_Constant)
10763 or else Is_Formal (EN1))
10771 -- Second case, selected component with same selector, same record
10773 if K1 = N_Selected_Component
10774 and then K2 = N_Selected_Component
10775 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10777 return Same_Object (Prefix (N1), Prefix (N2));
10779 -- Third case, indexed component with same subscripts, same array
10781 elsif K1 = N_Indexed_Component
10782 and then K2 = N_Indexed_Component
10783 and then Same_Object (Prefix (N1), Prefix (N2))
10788 E1 := First (Expressions (N1));
10789 E2 := First (Expressions (N2));
10790 while Present (E1) loop
10791 if not Same_Value (E1, E2) then
10802 -- Fourth case, slice of same array with same bounds
10805 and then K2 = N_Slice
10806 and then Nkind (Discrete_Range (N1)) = N_Range
10807 and then Nkind (Discrete_Range (N2)) = N_Range
10808 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10809 Low_Bound (Discrete_Range (N2)))
10810 and then Same_Value (High_Bound (Discrete_Range (N1)),
10811 High_Bound (Discrete_Range (N2)))
10813 return Same_Name (Prefix (N1), Prefix (N2));
10815 -- All other cases, not clearly the same object
10826 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10831 elsif not Is_Constrained (T1)
10832 and then not Is_Constrained (T2)
10833 and then Base_Type (T1) = Base_Type (T2)
10837 -- For now don't bother with case of identical constraints, to be
10838 -- fiddled with later on perhaps (this is only used for optimization
10839 -- purposes, so it is not critical to do a best possible job)
10850 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10852 if Compile_Time_Known_Value (Node1)
10853 and then Compile_Time_Known_Value (Node2)
10854 and then Expr_Value (Node1) = Expr_Value (Node2)
10857 elsif Same_Object (Node1, Node2) then
10868 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
10870 if Ada_Version < Ada_2012 then
10873 elsif Is_Entity_Name (N)
10875 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
10877 (Nkind (N) = N_Attribute_Reference
10878 and then Attribute_Name (N) = Name_Access)
10881 -- We are only interested in IN OUT parameters of inner calls
10884 or else Nkind (Parent (N)) = N_Function_Call
10885 or else Nkind (Parent (N)) in N_Op
10887 Actuals_In_Call.Increment_Last;
10888 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
10893 ------------------------
10894 -- Scope_Is_Transient --
10895 ------------------------
10897 function Scope_Is_Transient return Boolean is
10899 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10900 end Scope_Is_Transient;
10906 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10911 while Scop /= Standard_Standard loop
10912 Scop := Scope (Scop);
10914 if Scop = Scope2 then
10922 --------------------------
10923 -- Scope_Within_Or_Same --
10924 --------------------------
10926 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10931 while Scop /= Standard_Standard loop
10932 if Scop = Scope2 then
10935 Scop := Scope (Scop);
10940 end Scope_Within_Or_Same;
10942 --------------------
10943 -- Set_Convention --
10944 --------------------
10946 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10948 Basic_Set_Convention (E, Val);
10951 and then Is_Access_Subprogram_Type (Base_Type (E))
10952 and then Has_Foreign_Convention (E)
10954 Set_Can_Use_Internal_Rep (E, False);
10956 end Set_Convention;
10958 ------------------------
10959 -- Set_Current_Entity --
10960 ------------------------
10962 -- The given entity is to be set as the currently visible definition
10963 -- of its associated name (i.e. the Node_Id associated with its name).
10964 -- All we have to do is to get the name from the identifier, and
10965 -- then set the associated Node_Id to point to the given entity.
10967 procedure Set_Current_Entity (E : Entity_Id) is
10969 Set_Name_Entity_Id (Chars (E), E);
10970 end Set_Current_Entity;
10972 ---------------------------
10973 -- Set_Debug_Info_Needed --
10974 ---------------------------
10976 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10978 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10979 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10980 -- Used to set debug info in a related node if not set already
10982 --------------------------------------
10983 -- Set_Debug_Info_Needed_If_Not_Set --
10984 --------------------------------------
10986 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10989 and then not Needs_Debug_Info (E)
10991 Set_Debug_Info_Needed (E);
10993 -- For a private type, indicate that the full view also needs
10994 -- debug information.
10997 and then Is_Private_Type (E)
10998 and then Present (Full_View (E))
11000 Set_Debug_Info_Needed (Full_View (E));
11003 end Set_Debug_Info_Needed_If_Not_Set;
11005 -- Start of processing for Set_Debug_Info_Needed
11008 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11009 -- indicates that Debug_Info_Needed is never required for the entity.
11012 or else Debug_Info_Off (T)
11017 -- Set flag in entity itself. Note that we will go through the following
11018 -- circuitry even if the flag is already set on T. That's intentional,
11019 -- it makes sure that the flag will be set in subsidiary entities.
11021 Set_Needs_Debug_Info (T);
11023 -- Set flag on subsidiary entities if not set already
11025 if Is_Object (T) then
11026 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11028 elsif Is_Type (T) then
11029 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11031 if Is_Record_Type (T) then
11033 Ent : Entity_Id := First_Entity (T);
11035 while Present (Ent) loop
11036 Set_Debug_Info_Needed_If_Not_Set (Ent);
11041 -- For a class wide subtype, we also need debug information
11042 -- for the equivalent type.
11044 if Ekind (T) = E_Class_Wide_Subtype then
11045 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11048 elsif Is_Array_Type (T) then
11049 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11052 Indx : Node_Id := First_Index (T);
11054 while Present (Indx) loop
11055 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11056 Indx := Next_Index (Indx);
11060 if Is_Packed (T) then
11061 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11064 elsif Is_Access_Type (T) then
11065 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11067 elsif Is_Private_Type (T) then
11068 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11070 elsif Is_Protected_Type (T) then
11071 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11074 end Set_Debug_Info_Needed;
11076 ---------------------------------
11077 -- Set_Entity_With_Style_Check --
11078 ---------------------------------
11080 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11081 Val_Actual : Entity_Id;
11085 Set_Entity (N, Val);
11088 and then not Suppress_Style_Checks (Val)
11089 and then not In_Instance
11091 if Nkind (N) = N_Identifier then
11093 elsif Nkind (N) = N_Expanded_Name then
11094 Nod := Selector_Name (N);
11099 -- A special situation arises for derived operations, where we want
11100 -- to do the check against the parent (since the Sloc of the derived
11101 -- operation points to the derived type declaration itself).
11104 while not Comes_From_Source (Val_Actual)
11105 and then Nkind (Val_Actual) in N_Entity
11106 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11107 or else Is_Subprogram (Val_Actual)
11108 or else Is_Generic_Subprogram (Val_Actual))
11109 and then Present (Alias (Val_Actual))
11111 Val_Actual := Alias (Val_Actual);
11114 -- Renaming declarations for generic actuals do not come from source,
11115 -- and have a different name from that of the entity they rename, so
11116 -- there is no style check to perform here.
11118 if Chars (Nod) = Chars (Val_Actual) then
11119 Style.Check_Identifier (Nod, Val_Actual);
11123 Set_Entity (N, Val);
11124 end Set_Entity_With_Style_Check;
11126 ------------------------
11127 -- Set_Name_Entity_Id --
11128 ------------------------
11130 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11132 Set_Name_Table_Info (Id, Int (Val));
11133 end Set_Name_Entity_Id;
11135 ---------------------
11136 -- Set_Next_Actual --
11137 ---------------------
11139 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11141 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11142 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11144 end Set_Next_Actual;
11146 ----------------------------------
11147 -- Set_Optimize_Alignment_Flags --
11148 ----------------------------------
11150 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11152 if Optimize_Alignment = 'S' then
11153 Set_Optimize_Alignment_Space (E);
11154 elsif Optimize_Alignment = 'T' then
11155 Set_Optimize_Alignment_Time (E);
11157 end Set_Optimize_Alignment_Flags;
11159 -----------------------
11160 -- Set_Public_Status --
11161 -----------------------
11163 procedure Set_Public_Status (Id : Entity_Id) is
11164 S : constant Entity_Id := Current_Scope;
11166 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11167 -- Determines if E is defined within handled statement sequence or
11168 -- an if statement, returns True if so, False otherwise.
11170 ----------------------
11171 -- Within_HSS_Or_If --
11172 ----------------------
11174 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11177 N := Declaration_Node (E);
11184 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11190 end Within_HSS_Or_If;
11192 -- Start of processing for Set_Public_Status
11195 -- Everything in the scope of Standard is public
11197 if S = Standard_Standard then
11198 Set_Is_Public (Id);
11200 -- Entity is definitely not public if enclosing scope is not public
11202 elsif not Is_Public (S) then
11205 -- An object or function declaration that occurs in a handled sequence
11206 -- of statements or within an if statement is the declaration for a
11207 -- temporary object or local subprogram generated by the expander. It
11208 -- never needs to be made public and furthermore, making it public can
11209 -- cause back end problems.
11211 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11212 N_Function_Specification)
11213 and then Within_HSS_Or_If (Id)
11217 -- Entities in public packages or records are public
11219 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11220 Set_Is_Public (Id);
11222 -- The bounds of an entry family declaration can generate object
11223 -- declarations that are visible to the back-end, e.g. in the
11224 -- the declaration of a composite type that contains tasks.
11226 elsif Is_Concurrent_Type (S)
11227 and then not Has_Completion (S)
11228 and then Nkind (Parent (Id)) = N_Object_Declaration
11230 Set_Is_Public (Id);
11232 end Set_Public_Status;
11234 -----------------------------
11235 -- Set_Referenced_Modified --
11236 -----------------------------
11238 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11242 -- Deal with indexed or selected component where prefix is modified
11244 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11245 Pref := Prefix (N);
11247 -- If prefix is access type, then it is the designated object that is
11248 -- being modified, which means we have no entity to set the flag on.
11250 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11253 -- Otherwise chase the prefix
11256 Set_Referenced_Modified (Pref, Out_Param);
11259 -- Otherwise see if we have an entity name (only other case to process)
11261 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11262 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11263 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11265 end Set_Referenced_Modified;
11267 ----------------------------
11268 -- Set_Scope_Is_Transient --
11269 ----------------------------
11271 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11273 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11274 end Set_Scope_Is_Transient;
11276 -------------------
11277 -- Set_Size_Info --
11278 -------------------
11280 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11282 -- We copy Esize, but not RM_Size, since in general RM_Size is
11283 -- subtype specific and does not get inherited by all subtypes.
11285 Set_Esize (T1, Esize (T2));
11286 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11288 if Is_Discrete_Or_Fixed_Point_Type (T1)
11290 Is_Discrete_Or_Fixed_Point_Type (T2)
11292 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11295 Set_Alignment (T1, Alignment (T2));
11298 --------------------
11299 -- Static_Boolean --
11300 --------------------
11302 function Static_Boolean (N : Node_Id) return Uint is
11304 Analyze_And_Resolve (N, Standard_Boolean);
11307 or else Error_Posted (N)
11308 or else Etype (N) = Any_Type
11313 if Is_Static_Expression (N) then
11314 if not Raises_Constraint_Error (N) then
11315 return Expr_Value (N);
11320 elsif Etype (N) = Any_Type then
11324 Flag_Non_Static_Expr
11325 ("static boolean expression required here", N);
11328 end Static_Boolean;
11330 --------------------
11331 -- Static_Integer --
11332 --------------------
11334 function Static_Integer (N : Node_Id) return Uint is
11336 Analyze_And_Resolve (N, Any_Integer);
11339 or else Error_Posted (N)
11340 or else Etype (N) = Any_Type
11345 if Is_Static_Expression (N) then
11346 if not Raises_Constraint_Error (N) then
11347 return Expr_Value (N);
11352 elsif Etype (N) = Any_Type then
11356 Flag_Non_Static_Expr
11357 ("static integer expression required here", N);
11360 end Static_Integer;
11362 --------------------------
11363 -- Statically_Different --
11364 --------------------------
11366 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11367 R1 : constant Node_Id := Get_Referenced_Object (E1);
11368 R2 : constant Node_Id := Get_Referenced_Object (E2);
11370 return Is_Entity_Name (R1)
11371 and then Is_Entity_Name (R2)
11372 and then Entity (R1) /= Entity (R2)
11373 and then not Is_Formal (Entity (R1))
11374 and then not Is_Formal (Entity (R2));
11375 end Statically_Different;
11377 -----------------------------
11378 -- Subprogram_Access_Level --
11379 -----------------------------
11381 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11383 if Present (Alias (Subp)) then
11384 return Subprogram_Access_Level (Alias (Subp));
11386 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11388 end Subprogram_Access_Level;
11394 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11396 if Debug_Flag_W then
11397 for J in 0 .. Scope_Stack.Last loop
11402 Write_Name (Chars (E));
11403 Write_Str (" from ");
11404 Write_Location (Sloc (N));
11409 -----------------------
11410 -- Transfer_Entities --
11411 -----------------------
11413 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11414 Ent : Entity_Id := First_Entity (From);
11421 if (Last_Entity (To)) = Empty then
11422 Set_First_Entity (To, Ent);
11424 Set_Next_Entity (Last_Entity (To), Ent);
11427 Set_Last_Entity (To, Last_Entity (From));
11429 while Present (Ent) loop
11430 Set_Scope (Ent, To);
11432 if not Is_Public (Ent) then
11433 Set_Public_Status (Ent);
11436 and then Ekind (Ent) = E_Record_Subtype
11439 -- The components of the propagated Itype must be public
11445 Comp := First_Entity (Ent);
11446 while Present (Comp) loop
11447 Set_Is_Public (Comp);
11448 Next_Entity (Comp);
11457 Set_First_Entity (From, Empty);
11458 Set_Last_Entity (From, Empty);
11459 end Transfer_Entities;
11461 -----------------------
11462 -- Type_Access_Level --
11463 -----------------------
11465 function Type_Access_Level (Typ : Entity_Id) return Uint is
11469 Btyp := Base_Type (Typ);
11471 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11472 -- simply use the level where the type is declared. This is true for
11473 -- stand-alone object declarations, and for anonymous access types
11474 -- associated with components the level is the same as that of the
11475 -- enclosing composite type. However, special treatment is needed for
11476 -- the cases of access parameters, return objects of an anonymous access
11477 -- type, and, in Ada 95, access discriminants of limited types.
11479 if Ekind (Btyp) in Access_Kind then
11480 if Ekind (Btyp) = E_Anonymous_Access_Type then
11482 -- If the type is a nonlocal anonymous access type (such as for
11483 -- an access parameter) we treat it as being declared at the
11484 -- library level to ensure that names such as X.all'access don't
11485 -- fail static accessibility checks.
11487 if not Is_Local_Anonymous_Access (Typ) then
11488 return Scope_Depth (Standard_Standard);
11490 -- If this is a return object, the accessibility level is that of
11491 -- the result subtype of the enclosing function. The test here is
11492 -- little complicated, because we have to account for extended
11493 -- return statements that have been rewritten as blocks, in which
11494 -- case we have to find and the Is_Return_Object attribute of the
11495 -- itype's associated object. It would be nice to find a way to
11496 -- simplify this test, but it doesn't seem worthwhile to add a new
11497 -- flag just for purposes of this test. ???
11499 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11502 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11503 N_Object_Declaration
11504 and then Is_Return_Object
11505 (Defining_Identifier
11506 (Associated_Node_For_Itype (Btyp))))
11512 Scop := Scope (Scope (Btyp));
11513 while Present (Scop) loop
11514 exit when Ekind (Scop) = E_Function;
11515 Scop := Scope (Scop);
11518 -- Treat the return object's type as having the level of the
11519 -- function's result subtype (as per RM05-6.5(5.3/2)).
11521 return Type_Access_Level (Etype (Scop));
11526 Btyp := Root_Type (Btyp);
11528 -- The accessibility level of anonymous access types associated with
11529 -- discriminants is that of the current instance of the type, and
11530 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11532 -- AI-402: access discriminants have accessibility based on the
11533 -- object rather than the type in Ada 2005, so the above paragraph
11536 -- ??? Needs completion with rules from AI-416
11538 if Ada_Version <= Ada_95
11539 and then Ekind (Typ) = E_Anonymous_Access_Type
11540 and then Present (Associated_Node_For_Itype (Typ))
11541 and then Nkind (Associated_Node_For_Itype (Typ)) =
11542 N_Discriminant_Specification
11544 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11548 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11549 end Type_Access_Level;
11551 --------------------------
11552 -- Unit_Declaration_Node --
11553 --------------------------
11555 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11556 N : Node_Id := Parent (Unit_Id);
11559 -- Predefined operators do not have a full function declaration
11561 if Ekind (Unit_Id) = E_Operator then
11565 -- Isn't there some better way to express the following ???
11567 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11568 and then Nkind (N) /= N_Formal_Package_Declaration
11569 and then Nkind (N) /= N_Function_Instantiation
11570 and then Nkind (N) /= N_Generic_Package_Declaration
11571 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11572 and then Nkind (N) /= N_Package_Declaration
11573 and then Nkind (N) /= N_Package_Body
11574 and then Nkind (N) /= N_Package_Instantiation
11575 and then Nkind (N) /= N_Package_Renaming_Declaration
11576 and then Nkind (N) /= N_Procedure_Instantiation
11577 and then Nkind (N) /= N_Protected_Body
11578 and then Nkind (N) /= N_Subprogram_Declaration
11579 and then Nkind (N) /= N_Subprogram_Body
11580 and then Nkind (N) /= N_Subprogram_Body_Stub
11581 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11582 and then Nkind (N) /= N_Task_Body
11583 and then Nkind (N) /= N_Task_Type_Declaration
11584 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11585 and then Nkind (N) not in N_Generic_Renaming_Declaration
11588 pragma Assert (Present (N));
11592 end Unit_Declaration_Node;
11594 ---------------------
11595 -- Unit_Is_Visible --
11596 ---------------------
11598 function Unit_Is_Visible (U : Entity_Id) return Boolean is
11599 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
11600 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11602 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
11603 -- For a child unit, check whether unit appears in a with_clause
11606 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
11607 -- Scan the context clause of one compilation unit looking for a
11608 -- with_clause for the unit in question.
11610 ----------------------------
11611 -- Unit_In_Parent_Context --
11612 ----------------------------
11614 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
11616 if Unit_In_Context (Par_Unit) then
11619 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
11620 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
11625 end Unit_In_Parent_Context;
11627 ---------------------
11628 -- Unit_In_Context --
11629 ---------------------
11631 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
11635 Clause := First (Context_Items (Comp_Unit));
11636 while Present (Clause) loop
11637 if Nkind (Clause) = N_With_Clause then
11638 if Library_Unit (Clause) = U then
11641 -- The with_clause may denote a renaming of the unit we are
11642 -- looking for, eg. Text_IO which renames Ada.Text_IO.
11645 Renamed_Entity (Entity (Name (Clause))) =
11646 Defining_Entity (Unit (U))
11656 end Unit_In_Context;
11658 -- Start of processing for Unit_Is_Visible
11661 -- The currrent unit is directly visible.
11666 elsif Unit_In_Context (Curr) then
11669 -- If the current unit is a body, check the context of the spec.
11671 elsif Nkind (Unit (Curr)) = N_Package_Body
11673 (Nkind (Unit (Curr)) = N_Subprogram_Body
11674 and then not Acts_As_Spec (Unit (Curr)))
11676 if Unit_In_Context (Library_Unit (Curr)) then
11681 -- If the spec is a child unit, examine the parents.
11683 if Is_Child_Unit (Curr_Entity) then
11684 if Nkind (Unit (Curr)) in N_Unit_Body then
11686 Unit_In_Parent_Context
11687 (Parent_Spec (Unit (Library_Unit (Curr))));
11689 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
11695 end Unit_Is_Visible;
11697 ------------------------------
11698 -- Universal_Interpretation --
11699 ------------------------------
11701 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11702 Index : Interp_Index;
11706 -- The argument may be a formal parameter of an operator or subprogram
11707 -- with multiple interpretations, or else an expression for an actual.
11709 if Nkind (Opnd) = N_Defining_Identifier
11710 or else not Is_Overloaded (Opnd)
11712 if Etype (Opnd) = Universal_Integer
11713 or else Etype (Opnd) = Universal_Real
11715 return Etype (Opnd);
11721 Get_First_Interp (Opnd, Index, It);
11722 while Present (It.Typ) loop
11723 if It.Typ = Universal_Integer
11724 or else It.Typ = Universal_Real
11729 Get_Next_Interp (Index, It);
11734 end Universal_Interpretation;
11740 function Unqualify (Expr : Node_Id) return Node_Id is
11742 -- Recurse to handle unlikely case of multiple levels of qualification
11744 if Nkind (Expr) = N_Qualified_Expression then
11745 return Unqualify (Expression (Expr));
11747 -- Normal case, not a qualified expression
11754 -----------------------
11755 -- Visible_Ancestors --
11756 -----------------------
11758 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
11764 pragma Assert (Is_Record_Type (Typ)
11765 and then Is_Tagged_Type (Typ));
11767 -- Collect all the parents and progenitors of Typ. If the full-view of
11768 -- private parents and progenitors is available then it is used to
11769 -- generate the list of visible ancestors; otherwise their partial
11770 -- view is added to the resulting list.
11775 Use_Full_View => True);
11779 Ifaces_List => List_2,
11780 Exclude_Parents => True,
11781 Use_Full_View => True);
11783 -- Join the two lists. Avoid duplications because an interface may
11784 -- simultaneously be parent and progenitor of a type.
11786 Elmt := First_Elmt (List_2);
11787 while Present (Elmt) loop
11788 Append_Unique_Elmt (Node (Elmt), List_1);
11793 end Visible_Ancestors;
11795 ----------------------
11796 -- Within_Init_Proc --
11797 ----------------------
11799 function Within_Init_Proc return Boolean is
11803 S := Current_Scope;
11804 while not Is_Overloadable (S) loop
11805 if S = Standard_Standard then
11812 return Is_Init_Proc (S);
11813 end Within_Init_Proc;
11819 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11820 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11821 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11823 function Has_One_Matching_Field return Boolean;
11824 -- Determines if Expec_Type is a record type with a single component or
11825 -- discriminant whose type matches the found type or is one dimensional
11826 -- array whose component type matches the found type.
11828 ----------------------------
11829 -- Has_One_Matching_Field --
11830 ----------------------------
11832 function Has_One_Matching_Field return Boolean is
11836 if Is_Array_Type (Expec_Type)
11837 and then Number_Dimensions (Expec_Type) = 1
11839 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11843 elsif not Is_Record_Type (Expec_Type) then
11847 E := First_Entity (Expec_Type);
11852 elsif (Ekind (E) /= E_Discriminant
11853 and then Ekind (E) /= E_Component)
11854 or else (Chars (E) = Name_uTag
11855 or else Chars (E) = Name_uParent)
11864 if not Covers (Etype (E), Found_Type) then
11867 elsif Present (Next_Entity (E)) then
11874 end Has_One_Matching_Field;
11876 -- Start of processing for Wrong_Type
11879 -- Don't output message if either type is Any_Type, or if a message
11880 -- has already been posted for this node. We need to do the latter
11881 -- check explicitly (it is ordinarily done in Errout), because we
11882 -- are using ! to force the output of the error messages.
11884 if Expec_Type = Any_Type
11885 or else Found_Type = Any_Type
11886 or else Error_Posted (Expr)
11890 -- In an instance, there is an ongoing problem with completion of
11891 -- type derived from private types. Their structure is what Gigi
11892 -- expects, but the Etype is the parent type rather than the
11893 -- derived private type itself. Do not flag error in this case. The
11894 -- private completion is an entity without a parent, like an Itype.
11895 -- Similarly, full and partial views may be incorrect in the instance.
11896 -- There is no simple way to insure that it is consistent ???
11898 elsif In_Instance then
11899 if Etype (Etype (Expr)) = Etype (Expected_Type)
11901 (Has_Private_Declaration (Expected_Type)
11902 or else Has_Private_Declaration (Etype (Expr)))
11903 and then No (Parent (Expected_Type))
11909 -- An interesting special check. If the expression is parenthesized
11910 -- and its type corresponds to the type of the sole component of the
11911 -- expected record type, or to the component type of the expected one
11912 -- dimensional array type, then assume we have a bad aggregate attempt.
11914 if Nkind (Expr) in N_Subexpr
11915 and then Paren_Count (Expr) /= 0
11916 and then Has_One_Matching_Field
11918 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11920 -- Another special check, if we are looking for a pool-specific access
11921 -- type and we found an E_Access_Attribute_Type, then we have the case
11922 -- of an Access attribute being used in a context which needs a pool-
11923 -- specific type, which is never allowed. The one extra check we make
11924 -- is that the expected designated type covers the Found_Type.
11926 elsif Is_Access_Type (Expec_Type)
11927 and then Ekind (Found_Type) = E_Access_Attribute_Type
11928 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11929 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11931 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11933 Error_Msg_N -- CODEFIX
11934 ("result must be general access type!", Expr);
11935 Error_Msg_NE -- CODEFIX
11936 ("add ALL to }!", Expr, Expec_Type);
11938 -- Another special check, if the expected type is an integer type,
11939 -- but the expression is of type System.Address, and the parent is
11940 -- an addition or subtraction operation whose left operand is the
11941 -- expression in question and whose right operand is of an integral
11942 -- type, then this is an attempt at address arithmetic, so give
11943 -- appropriate message.
11945 elsif Is_Integer_Type (Expec_Type)
11946 and then Is_RTE (Found_Type, RE_Address)
11947 and then (Nkind (Parent (Expr)) = N_Op_Add
11949 Nkind (Parent (Expr)) = N_Op_Subtract)
11950 and then Expr = Left_Opnd (Parent (Expr))
11951 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11954 ("address arithmetic not predefined in package System",
11957 ("\possible missing with/use of System.Storage_Elements",
11961 -- If the expected type is an anonymous access type, as for access
11962 -- parameters and discriminants, the error is on the designated types.
11964 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11965 if Comes_From_Source (Expec_Type) then
11966 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11969 ("expected an access type with designated}",
11970 Expr, Designated_Type (Expec_Type));
11973 if Is_Access_Type (Found_Type)
11974 and then not Comes_From_Source (Found_Type)
11977 ("\\found an access type with designated}!",
11978 Expr, Designated_Type (Found_Type));
11980 if From_With_Type (Found_Type) then
11981 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11982 Error_Msg_Qual_Level := 99;
11983 Error_Msg_NE -- CODEFIX
11984 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11985 Error_Msg_Qual_Level := 0;
11987 Error_Msg_NE ("found}!", Expr, Found_Type);
11991 -- Normal case of one type found, some other type expected
11994 -- If the names of the two types are the same, see if some number
11995 -- of levels of qualification will help. Don't try more than three
11996 -- levels, and if we get to standard, it's no use (and probably
11997 -- represents an error in the compiler) Also do not bother with
11998 -- internal scope names.
12001 Expec_Scope : Entity_Id;
12002 Found_Scope : Entity_Id;
12005 Expec_Scope := Expec_Type;
12006 Found_Scope := Found_Type;
12008 for Levels in Int range 0 .. 3 loop
12009 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12010 Error_Msg_Qual_Level := Levels;
12014 Expec_Scope := Scope (Expec_Scope);
12015 Found_Scope := Scope (Found_Scope);
12017 exit when Expec_Scope = Standard_Standard
12018 or else Found_Scope = Standard_Standard
12019 or else not Comes_From_Source (Expec_Scope)
12020 or else not Comes_From_Source (Found_Scope);
12024 if Is_Record_Type (Expec_Type)
12025 and then Present (Corresponding_Remote_Type (Expec_Type))
12027 Error_Msg_NE ("expected}!", Expr,
12028 Corresponding_Remote_Type (Expec_Type));
12030 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12033 if Is_Entity_Name (Expr)
12034 and then Is_Package_Or_Generic_Package (Entity (Expr))
12036 Error_Msg_N ("\\found package name!", Expr);
12038 elsif Is_Entity_Name (Expr)
12040 (Ekind (Entity (Expr)) = E_Procedure
12042 Ekind (Entity (Expr)) = E_Generic_Procedure)
12044 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12046 ("found procedure name, possibly missing Access attribute!",
12050 ("\\found procedure name instead of function!", Expr);
12053 elsif Nkind (Expr) = N_Function_Call
12054 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12055 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12056 and then No (Parameter_Associations (Expr))
12059 ("found function name, possibly missing Access attribute!",
12062 -- Catch common error: a prefix or infix operator which is not
12063 -- directly visible because the type isn't.
12065 elsif Nkind (Expr) in N_Op
12066 and then Is_Overloaded (Expr)
12067 and then not Is_Immediately_Visible (Expec_Type)
12068 and then not Is_Potentially_Use_Visible (Expec_Type)
12069 and then not In_Use (Expec_Type)
12070 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12073 ("operator of the type is not directly visible!", Expr);
12075 elsif Ekind (Found_Type) = E_Void
12076 and then Present (Parent (Found_Type))
12077 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12079 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12082 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12085 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12086 -- of the same modular type, and (M1 and M2) = 0 was intended.
12088 if Expec_Type = Standard_Boolean
12089 and then Is_Modular_Integer_Type (Found_Type)
12090 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12091 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12094 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12095 L : constant Node_Id := Left_Opnd (Op);
12096 R : constant Node_Id := Right_Opnd (Op);
12098 -- The case for the message is when the left operand of the
12099 -- comparison is the same modular type, or when it is an
12100 -- integer literal (or other universal integer expression),
12101 -- which would have been typed as the modular type if the
12102 -- parens had been there.
12104 if (Etype (L) = Found_Type
12106 Etype (L) = Universal_Integer)
12107 and then Is_Integer_Type (Etype (R))
12110 ("\\possible missing parens for modular operation", Expr);
12115 -- Reset error message qualification indication
12117 Error_Msg_Qual_Level := 0;