1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Rtsfind; use Rtsfind;
44 with Scans; use Scans;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_SCIL; use Sem_SCIL;
54 with Sem_Type; use Sem_Type;
55 with Sinfo; use Sinfo;
56 with Sinput; use Sinput;
57 with Stand; use Stand;
59 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
66 package body Sem_Util is
68 ----------------------------------------
69 -- Global_Variables for New_Copy_Tree --
70 ----------------------------------------
72 -- These global variables are used by New_Copy_Tree. See description
73 -- of the body of this subprogram for details. Global variables can be
74 -- safely used by New_Copy_Tree, since there is no case of a recursive
75 -- call from the processing inside New_Copy_Tree.
77 NCT_Hash_Threshhold : constant := 20;
78 -- If there are more than this number of pairs of entries in the
79 -- map, then Hash_Tables_Used will be set, and the hash tables will
80 -- be initialized and used for the searches.
82 NCT_Hash_Tables_Used : Boolean := False;
83 -- Set to True if hash tables are in use
85 NCT_Table_Entries : Nat;
86 -- Count entries in table to see if threshhold is reached
88 NCT_Hash_Table_Setup : Boolean := False;
89 -- Set to True if hash table contains data. We set this True if we
90 -- setup the hash table with data, and leave it set permanently
91 -- from then on, this is a signal that second and subsequent users
92 -- of the hash table must clear the old entries before reuse.
94 subtype NCT_Header_Num is Int range 0 .. 511;
95 -- Defines range of headers in hash tables (512 headers)
97 -----------------------
98 -- Local Subprograms --
99 -----------------------
101 function Build_Component_Subtype
104 T : Entity_Id) return Node_Id;
105 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
106 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
107 -- Loc is the source location, T is the original subtype.
109 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
110 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
111 -- with discriminants whose default values are static, examine only the
112 -- components in the selected variant to determine whether all of them
115 function Has_Null_Extension (T : Entity_Id) return Boolean;
116 -- T is a derived tagged type. Check whether the type extension is null.
117 -- If the parent type is fully initialized, T can be treated as such.
119 ------------------------------
120 -- Abstract_Interface_List --
121 ------------------------------
123 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
127 if Is_Concurrent_Type (Typ) then
129 -- If we are dealing with a synchronized subtype, go to the base
130 -- type, whose declaration has the interface list.
132 -- Shouldn't this be Declaration_Node???
134 Nod := Parent (Base_Type (Typ));
136 if Nkind (Nod) = N_Full_Type_Declaration then
140 elsif Ekind (Typ) = E_Record_Type_With_Private then
141 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
142 Nod := Type_Definition (Parent (Typ));
144 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
145 if Present (Full_View (Typ)) then
146 Nod := Type_Definition (Parent (Full_View (Typ)));
148 -- If the full-view is not available we cannot do anything else
149 -- here (the source has errors).
155 -- Support for generic formals with interfaces is still missing ???
157 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
162 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
166 elsif Ekind (Typ) = E_Record_Subtype then
167 Nod := Type_Definition (Parent (Etype (Typ)));
169 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
171 -- Recurse, because parent may still be a private extension. Also
172 -- note that the full view of the subtype or the full view of its
173 -- base type may (both) be unavailable.
175 return Abstract_Interface_List (Etype (Typ));
177 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
178 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
179 Nod := Formal_Type_Definition (Parent (Typ));
181 Nod := Type_Definition (Parent (Typ));
185 return Interface_List (Nod);
186 end Abstract_Interface_List;
188 --------------------------------
189 -- Add_Access_Type_To_Process --
190 --------------------------------
192 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
196 Ensure_Freeze_Node (E);
197 L := Access_Types_To_Process (Freeze_Node (E));
201 Set_Access_Types_To_Process (Freeze_Node (E), L);
205 end Add_Access_Type_To_Process;
207 ----------------------------
208 -- Add_Global_Declaration --
209 ----------------------------
211 procedure Add_Global_Declaration (N : Node_Id) is
212 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
215 if No (Declarations (Aux_Node)) then
216 Set_Declarations (Aux_Node, New_List);
219 Append_To (Declarations (Aux_Node), N);
221 end Add_Global_Declaration;
223 -----------------------
224 -- Alignment_In_Bits --
225 -----------------------
227 function Alignment_In_Bits (E : Entity_Id) return Uint is
229 return Alignment (E) * System_Storage_Unit;
230 end Alignment_In_Bits;
232 -----------------------------------------
233 -- Apply_Compile_Time_Constraint_Error --
234 -----------------------------------------
236 procedure Apply_Compile_Time_Constraint_Error
239 Reason : RT_Exception_Code;
240 Ent : Entity_Id := Empty;
241 Typ : Entity_Id := Empty;
242 Loc : Source_Ptr := No_Location;
243 Rep : Boolean := True;
244 Warn : Boolean := False)
246 Stat : constant Boolean := Is_Static_Expression (N);
247 R_Stat : constant Node_Id :=
248 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
259 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
265 -- Now we replace the node by an N_Raise_Constraint_Error node
266 -- This does not need reanalyzing, so set it as analyzed now.
269 Set_Analyzed (N, True);
272 Set_Raises_Constraint_Error (N);
274 -- Now deal with possible local raise handling
276 Possible_Local_Raise (N, Standard_Constraint_Error);
278 -- If the original expression was marked as static, the result is
279 -- still marked as static, but the Raises_Constraint_Error flag is
280 -- always set so that further static evaluation is not attempted.
283 Set_Is_Static_Expression (N);
285 end Apply_Compile_Time_Constraint_Error;
287 --------------------------
288 -- Build_Actual_Subtype --
289 --------------------------
291 function Build_Actual_Subtype
293 N : Node_Or_Entity_Id) return Node_Id
296 -- Normally Sloc (N), but may point to corresponding body in some cases
298 Constraints : List_Id;
304 Disc_Type : Entity_Id;
310 if Nkind (N) = N_Defining_Identifier then
311 Obj := New_Reference_To (N, Loc);
313 -- If this is a formal parameter of a subprogram declaration, and
314 -- we are compiling the body, we want the declaration for the
315 -- actual subtype to carry the source position of the body, to
316 -- prevent anomalies in gdb when stepping through the code.
318 if Is_Formal (N) then
320 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
322 if Nkind (Decl) = N_Subprogram_Declaration
323 and then Present (Corresponding_Body (Decl))
325 Loc := Sloc (Corresponding_Body (Decl));
334 if Is_Array_Type (T) then
335 Constraints := New_List;
336 for J in 1 .. Number_Dimensions (T) loop
338 -- Build an array subtype declaration with the nominal subtype and
339 -- the bounds of the actual. Add the declaration in front of the
340 -- local declarations for the subprogram, for analysis before any
341 -- reference to the formal in the body.
344 Make_Attribute_Reference (Loc,
346 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
347 Attribute_Name => Name_First,
348 Expressions => New_List (
349 Make_Integer_Literal (Loc, J)));
352 Make_Attribute_Reference (Loc,
354 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
355 Attribute_Name => Name_Last,
356 Expressions => New_List (
357 Make_Integer_Literal (Loc, J)));
359 Append (Make_Range (Loc, Lo, Hi), Constraints);
362 -- If the type has unknown discriminants there is no constrained
363 -- subtype to build. This is never called for a formal or for a
364 -- lhs, so returning the type is ok ???
366 elsif Has_Unknown_Discriminants (T) then
370 Constraints := New_List;
372 -- Type T is a generic derived type, inherit the discriminants from
375 if Is_Private_Type (T)
376 and then No (Full_View (T))
378 -- T was flagged as an error if it was declared as a formal
379 -- derived type with known discriminants. In this case there
380 -- is no need to look at the parent type since T already carries
381 -- its own discriminants.
383 and then not Error_Posted (T)
385 Disc_Type := Etype (Base_Type (T));
390 Discr := First_Discriminant (Disc_Type);
391 while Present (Discr) loop
392 Append_To (Constraints,
393 Make_Selected_Component (Loc,
395 Duplicate_Subexpr_No_Checks (Obj),
396 Selector_Name => New_Occurrence_Of (Discr, Loc)));
397 Next_Discriminant (Discr);
402 Make_Defining_Identifier (Loc,
403 Chars => New_Internal_Name ('S'));
404 Set_Is_Internal (Subt);
407 Make_Subtype_Declaration (Loc,
408 Defining_Identifier => Subt,
409 Subtype_Indication =>
410 Make_Subtype_Indication (Loc,
411 Subtype_Mark => New_Reference_To (T, Loc),
413 Make_Index_Or_Discriminant_Constraint (Loc,
414 Constraints => Constraints)));
416 Mark_Rewrite_Insertion (Decl);
418 end Build_Actual_Subtype;
420 ---------------------------------------
421 -- Build_Actual_Subtype_Of_Component --
422 ---------------------------------------
424 function Build_Actual_Subtype_Of_Component
426 N : Node_Id) return Node_Id
428 Loc : constant Source_Ptr := Sloc (N);
429 P : constant Node_Id := Prefix (N);
432 Indx_Type : Entity_Id;
434 Deaccessed_T : Entity_Id;
435 -- This is either a copy of T, or if T is an access type, then it is
436 -- the directly designated type of this access type.
438 function Build_Actual_Array_Constraint return List_Id;
439 -- If one or more of the bounds of the component depends on
440 -- discriminants, build actual constraint using the discriminants
443 function Build_Actual_Record_Constraint return List_Id;
444 -- Similar to previous one, for discriminated components constrained
445 -- by the discriminant of the enclosing object.
447 -----------------------------------
448 -- Build_Actual_Array_Constraint --
449 -----------------------------------
451 function Build_Actual_Array_Constraint return List_Id is
452 Constraints : constant List_Id := New_List;
460 Indx := First_Index (Deaccessed_T);
461 while Present (Indx) loop
462 Old_Lo := Type_Low_Bound (Etype (Indx));
463 Old_Hi := Type_High_Bound (Etype (Indx));
465 if Denotes_Discriminant (Old_Lo) then
467 Make_Selected_Component (Loc,
468 Prefix => New_Copy_Tree (P),
469 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
472 Lo := New_Copy_Tree (Old_Lo);
474 -- The new bound will be reanalyzed in the enclosing
475 -- declaration. For literal bounds that come from a type
476 -- declaration, the type of the context must be imposed, so
477 -- insure that analysis will take place. For non-universal
478 -- types this is not strictly necessary.
480 Set_Analyzed (Lo, False);
483 if Denotes_Discriminant (Old_Hi) then
485 Make_Selected_Component (Loc,
486 Prefix => New_Copy_Tree (P),
487 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
490 Hi := New_Copy_Tree (Old_Hi);
491 Set_Analyzed (Hi, False);
494 Append (Make_Range (Loc, Lo, Hi), Constraints);
499 end Build_Actual_Array_Constraint;
501 ------------------------------------
502 -- Build_Actual_Record_Constraint --
503 ------------------------------------
505 function Build_Actual_Record_Constraint return List_Id is
506 Constraints : constant List_Id := New_List;
511 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
512 while Present (D) loop
513 if Denotes_Discriminant (Node (D)) then
514 D_Val := Make_Selected_Component (Loc,
515 Prefix => New_Copy_Tree (P),
516 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
519 D_Val := New_Copy_Tree (Node (D));
522 Append (D_Val, Constraints);
527 end Build_Actual_Record_Constraint;
529 -- Start of processing for Build_Actual_Subtype_Of_Component
532 -- Why the test for Spec_Expression mode here???
534 if In_Spec_Expression then
537 -- More comments for the rest of this body would be good ???
539 elsif Nkind (N) = N_Explicit_Dereference then
540 if Is_Composite_Type (T)
541 and then not Is_Constrained (T)
542 and then not (Is_Class_Wide_Type (T)
543 and then Is_Constrained (Root_Type (T)))
544 and then not Has_Unknown_Discriminants (T)
546 -- If the type of the dereference is already constrained, it
547 -- is an actual subtype.
549 if Is_Array_Type (Etype (N))
550 and then Is_Constrained (Etype (N))
554 Remove_Side_Effects (P);
555 return Build_Actual_Subtype (T, N);
562 if Ekind (T) = E_Access_Subtype then
563 Deaccessed_T := Designated_Type (T);
568 if Ekind (Deaccessed_T) = E_Array_Subtype then
569 Id := First_Index (Deaccessed_T);
570 while Present (Id) loop
571 Indx_Type := Underlying_Type (Etype (Id));
573 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
575 Denotes_Discriminant (Type_High_Bound (Indx_Type))
577 Remove_Side_Effects (P);
579 Build_Component_Subtype
580 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
586 elsif Is_Composite_Type (Deaccessed_T)
587 and then Has_Discriminants (Deaccessed_T)
588 and then not Has_Unknown_Discriminants (Deaccessed_T)
590 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
591 while Present (D) loop
592 if Denotes_Discriminant (Node (D)) then
593 Remove_Side_Effects (P);
595 Build_Component_Subtype (
596 Build_Actual_Record_Constraint, Loc, Base_Type (T));
603 -- If none of the above, the actual and nominal subtypes are the same
606 end Build_Actual_Subtype_Of_Component;
608 -----------------------------
609 -- Build_Component_Subtype --
610 -----------------------------
612 function Build_Component_Subtype
615 T : Entity_Id) return Node_Id
621 -- Unchecked_Union components do not require component subtypes
623 if Is_Unchecked_Union (T) then
628 Make_Defining_Identifier (Loc,
629 Chars => New_Internal_Name ('S'));
630 Set_Is_Internal (Subt);
633 Make_Subtype_Declaration (Loc,
634 Defining_Identifier => Subt,
635 Subtype_Indication =>
636 Make_Subtype_Indication (Loc,
637 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
639 Make_Index_Or_Discriminant_Constraint (Loc,
642 Mark_Rewrite_Insertion (Decl);
644 end Build_Component_Subtype;
646 ---------------------------
647 -- Build_Default_Subtype --
648 ---------------------------
650 function Build_Default_Subtype
652 N : Node_Id) return Entity_Id
654 Loc : constant Source_Ptr := Sloc (N);
658 if not Has_Discriminants (T) or else Is_Constrained (T) then
662 Disc := First_Discriminant (T);
664 if No (Discriminant_Default_Value (Disc)) then
669 Act : constant Entity_Id :=
670 Make_Defining_Identifier (Loc,
671 Chars => New_Internal_Name ('S'));
673 Constraints : constant List_Id := New_List;
677 while Present (Disc) loop
678 Append_To (Constraints,
679 New_Copy_Tree (Discriminant_Default_Value (Disc)));
680 Next_Discriminant (Disc);
684 Make_Subtype_Declaration (Loc,
685 Defining_Identifier => Act,
686 Subtype_Indication =>
687 Make_Subtype_Indication (Loc,
688 Subtype_Mark => New_Occurrence_Of (T, Loc),
690 Make_Index_Or_Discriminant_Constraint (Loc,
691 Constraints => Constraints)));
693 Insert_Action (N, Decl);
697 end Build_Default_Subtype;
699 --------------------------------------------
700 -- Build_Discriminal_Subtype_Of_Component --
701 --------------------------------------------
703 function Build_Discriminal_Subtype_Of_Component
704 (T : Entity_Id) return Node_Id
706 Loc : constant Source_Ptr := Sloc (T);
710 function Build_Discriminal_Array_Constraint return List_Id;
711 -- If one or more of the bounds of the component depends on
712 -- discriminants, build actual constraint using the discriminants
715 function Build_Discriminal_Record_Constraint return List_Id;
716 -- Similar to previous one, for discriminated components constrained
717 -- by the discriminant of the enclosing object.
719 ----------------------------------------
720 -- Build_Discriminal_Array_Constraint --
721 ----------------------------------------
723 function Build_Discriminal_Array_Constraint return List_Id is
724 Constraints : constant List_Id := New_List;
732 Indx := First_Index (T);
733 while Present (Indx) loop
734 Old_Lo := Type_Low_Bound (Etype (Indx));
735 Old_Hi := Type_High_Bound (Etype (Indx));
737 if Denotes_Discriminant (Old_Lo) then
738 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
741 Lo := New_Copy_Tree (Old_Lo);
744 if Denotes_Discriminant (Old_Hi) then
745 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
748 Hi := New_Copy_Tree (Old_Hi);
751 Append (Make_Range (Loc, Lo, Hi), Constraints);
756 end Build_Discriminal_Array_Constraint;
758 -----------------------------------------
759 -- Build_Discriminal_Record_Constraint --
760 -----------------------------------------
762 function Build_Discriminal_Record_Constraint return List_Id is
763 Constraints : constant List_Id := New_List;
768 D := First_Elmt (Discriminant_Constraint (T));
769 while Present (D) loop
770 if Denotes_Discriminant (Node (D)) then
772 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
775 D_Val := New_Copy_Tree (Node (D));
778 Append (D_Val, Constraints);
783 end Build_Discriminal_Record_Constraint;
785 -- Start of processing for Build_Discriminal_Subtype_Of_Component
788 if Ekind (T) = E_Array_Subtype then
789 Id := First_Index (T);
790 while Present (Id) loop
791 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
792 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
794 return Build_Component_Subtype
795 (Build_Discriminal_Array_Constraint, Loc, T);
801 elsif Ekind (T) = E_Record_Subtype
802 and then Has_Discriminants (T)
803 and then not Has_Unknown_Discriminants (T)
805 D := First_Elmt (Discriminant_Constraint (T));
806 while Present (D) loop
807 if Denotes_Discriminant (Node (D)) then
808 return Build_Component_Subtype
809 (Build_Discriminal_Record_Constraint, Loc, T);
816 -- If none of the above, the actual and nominal subtypes are the same
819 end Build_Discriminal_Subtype_Of_Component;
821 ------------------------------
822 -- Build_Elaboration_Entity --
823 ------------------------------
825 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
826 Loc : constant Source_Ptr := Sloc (N);
828 Elab_Ent : Entity_Id;
830 procedure Set_Package_Name (Ent : Entity_Id);
831 -- Given an entity, sets the fully qualified name of the entity in
832 -- Name_Buffer, with components separated by double underscores. This
833 -- is a recursive routine that climbs the scope chain to Standard.
835 ----------------------
836 -- Set_Package_Name --
837 ----------------------
839 procedure Set_Package_Name (Ent : Entity_Id) is
841 if Scope (Ent) /= Standard_Standard then
842 Set_Package_Name (Scope (Ent));
845 Nam : constant String := Get_Name_String (Chars (Ent));
847 Name_Buffer (Name_Len + 1) := '_';
848 Name_Buffer (Name_Len + 2) := '_';
849 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
850 Name_Len := Name_Len + Nam'Length + 2;
854 Get_Name_String (Chars (Ent));
856 end Set_Package_Name;
858 -- Start of processing for Build_Elaboration_Entity
861 -- Ignore if already constructed
863 if Present (Elaboration_Entity (Spec_Id)) then
867 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
868 -- name with dots replaced by double underscore. We have to manually
869 -- construct this name, since it will be elaborated in the outer scope,
870 -- and thus will not have the unit name automatically prepended.
872 Set_Package_Name (Spec_Id);
876 Name_Buffer (Name_Len + 1) := '_';
877 Name_Buffer (Name_Len + 2) := 'E';
878 Name_Len := Name_Len + 2;
880 -- Create elaboration flag
883 Make_Defining_Identifier (Loc, Chars => Name_Find);
884 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
887 Make_Object_Declaration (Loc,
888 Defining_Identifier => Elab_Ent,
890 New_Occurrence_Of (Standard_Boolean, Loc),
892 New_Occurrence_Of (Standard_False, Loc));
894 Push_Scope (Standard_Standard);
895 Add_Global_Declaration (Decl);
898 -- Reset True_Constant indication, since we will indeed assign a value
899 -- to the variable in the binder main. We also kill the Current_Value
900 -- and Last_Assignment fields for the same reason.
902 Set_Is_True_Constant (Elab_Ent, False);
903 Set_Current_Value (Elab_Ent, Empty);
904 Set_Last_Assignment (Elab_Ent, Empty);
906 -- We do not want any further qualification of the name (if we did
907 -- not do this, we would pick up the name of the generic package
908 -- in the case of a library level generic instantiation).
910 Set_Has_Qualified_Name (Elab_Ent);
911 Set_Has_Fully_Qualified_Name (Elab_Ent);
912 end Build_Elaboration_Entity;
914 -----------------------------------
915 -- Cannot_Raise_Constraint_Error --
916 -----------------------------------
918 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
920 if Compile_Time_Known_Value (Expr) then
923 elsif Do_Range_Check (Expr) then
926 elsif Raises_Constraint_Error (Expr) then
934 when N_Expanded_Name =>
937 when N_Selected_Component =>
938 return not Do_Discriminant_Check (Expr);
940 when N_Attribute_Reference =>
941 if Do_Overflow_Check (Expr) then
944 elsif No (Expressions (Expr)) then
952 N := First (Expressions (Expr));
953 while Present (N) loop
954 if Cannot_Raise_Constraint_Error (N) then
965 when N_Type_Conversion =>
966 if Do_Overflow_Check (Expr)
967 or else Do_Length_Check (Expr)
968 or else Do_Tag_Check (Expr)
973 Cannot_Raise_Constraint_Error (Expression (Expr));
976 when N_Unchecked_Type_Conversion =>
977 return Cannot_Raise_Constraint_Error (Expression (Expr));
980 if Do_Overflow_Check (Expr) then
984 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
991 if Do_Division_Check (Expr)
992 or else Do_Overflow_Check (Expr)
997 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
999 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1018 N_Op_Shift_Right_Arithmetic |
1022 if Do_Overflow_Check (Expr) then
1026 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1028 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1035 end Cannot_Raise_Constraint_Error;
1037 -----------------------------------------
1038 -- Check_Dynamically_Tagged_Expression --
1039 -----------------------------------------
1041 procedure Check_Dynamically_Tagged_Expression
1044 Related_Nod : Node_Id)
1047 pragma Assert (Is_Tagged_Type (Typ));
1049 -- In order to avoid spurious errors when analyzing the expanded code,
1050 -- this check is done only for nodes that come from source and for
1051 -- actuals of generic instantiations.
1053 if (Comes_From_Source (Related_Nod)
1054 or else In_Generic_Actual (Expr))
1055 and then (Is_Class_Wide_Type (Etype (Expr))
1056 or else Is_Dynamically_Tagged (Expr))
1057 and then Is_Tagged_Type (Typ)
1058 and then not Is_Class_Wide_Type (Typ)
1060 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1062 end Check_Dynamically_Tagged_Expression;
1064 --------------------------
1065 -- Check_Fully_Declared --
1066 --------------------------
1068 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1070 if Ekind (T) = E_Incomplete_Type then
1072 -- Ada 2005 (AI-50217): If the type is available through a limited
1073 -- with_clause, verify that its full view has been analyzed.
1075 if From_With_Type (T)
1076 and then Present (Non_Limited_View (T))
1077 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1079 -- The non-limited view is fully declared
1084 ("premature usage of incomplete}", N, First_Subtype (T));
1087 -- Need comments for these tests ???
1089 elsif Has_Private_Component (T)
1090 and then not Is_Generic_Type (Root_Type (T))
1091 and then not In_Spec_Expression
1093 -- Special case: if T is the anonymous type created for a single
1094 -- task or protected object, use the name of the source object.
1096 if Is_Concurrent_Type (T)
1097 and then not Comes_From_Source (T)
1098 and then Nkind (N) = N_Object_Declaration
1100 Error_Msg_NE ("type of& has incomplete component", N,
1101 Defining_Identifier (N));
1105 ("premature usage of incomplete}", N, First_Subtype (T));
1108 end Check_Fully_Declared;
1110 -------------------------
1111 -- Check_Nested_Access --
1112 -------------------------
1114 procedure Check_Nested_Access (Ent : Entity_Id) is
1115 Scop : constant Entity_Id := Current_Scope;
1116 Current_Subp : Entity_Id;
1117 Enclosing : Entity_Id;
1120 -- Currently only enabled for VM back-ends for efficiency, should we
1121 -- enable it more systematically ???
1123 -- Check for Is_Imported needs commenting below ???
1125 if VM_Target /= No_VM
1126 and then (Ekind (Ent) = E_Variable
1128 Ekind (Ent) = E_Constant
1130 Ekind (Ent) = E_Loop_Parameter)
1131 and then Scope (Ent) /= Empty
1132 and then not Is_Library_Level_Entity (Ent)
1133 and then not Is_Imported (Ent)
1135 if Is_Subprogram (Scop)
1136 or else Is_Generic_Subprogram (Scop)
1137 or else Is_Entry (Scop)
1139 Current_Subp := Scop;
1141 Current_Subp := Current_Subprogram;
1144 Enclosing := Enclosing_Subprogram (Ent);
1146 if Enclosing /= Empty
1147 and then Enclosing /= Current_Subp
1149 Set_Has_Up_Level_Access (Ent, True);
1152 end Check_Nested_Access;
1154 ------------------------------------------
1155 -- Check_Potentially_Blocking_Operation --
1156 ------------------------------------------
1158 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1161 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1162 -- When pragma Detect_Blocking is active, the run time will raise
1163 -- Program_Error. Here we only issue a warning, since we generally
1164 -- support the use of potentially blocking operations in the absence
1167 -- Indirect blocking through a subprogram call cannot be diagnosed
1168 -- statically without interprocedural analysis, so we do not attempt
1171 S := Scope (Current_Scope);
1172 while Present (S) and then S /= Standard_Standard loop
1173 if Is_Protected_Type (S) then
1175 ("potentially blocking operation in protected operation?", N);
1182 end Check_Potentially_Blocking_Operation;
1184 ------------------------------
1185 -- Check_Unprotected_Access --
1186 ------------------------------
1188 procedure Check_Unprotected_Access
1192 Cont_Encl_Typ : Entity_Id;
1193 Pref_Encl_Typ : Entity_Id;
1195 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1196 -- Check whether Obj is a private component of a protected object.
1197 -- Return the protected type where the component resides, Empty
1200 function Is_Public_Operation return Boolean;
1201 -- Verify that the enclosing operation is callable from outside the
1202 -- protected object, to minimize false positives.
1204 ------------------------------
1205 -- Enclosing_Protected_Type --
1206 ------------------------------
1208 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1210 if Is_Entity_Name (Obj) then
1212 Ent : Entity_Id := Entity (Obj);
1215 -- The object can be a renaming of a private component, use
1216 -- the original record component.
1218 if Is_Prival (Ent) then
1219 Ent := Prival_Link (Ent);
1222 if Is_Protected_Type (Scope (Ent)) then
1228 -- For indexed and selected components, recursively check the prefix
1230 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1231 return Enclosing_Protected_Type (Prefix (Obj));
1233 -- The object does not denote a protected component
1238 end Enclosing_Protected_Type;
1240 -------------------------
1241 -- Is_Public_Operation --
1242 -------------------------
1244 function Is_Public_Operation return Boolean is
1251 and then S /= Pref_Encl_Typ
1253 if Scope (S) = Pref_Encl_Typ then
1254 E := First_Entity (Pref_Encl_Typ);
1256 and then E /= First_Private_Entity (Pref_Encl_Typ)
1269 end Is_Public_Operation;
1271 -- Start of processing for Check_Unprotected_Access
1274 if Nkind (Expr) = N_Attribute_Reference
1275 and then Attribute_Name (Expr) = Name_Unchecked_Access
1277 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1278 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1280 -- Check whether we are trying to export a protected component to a
1281 -- context with an equal or lower access level.
1283 if Present (Pref_Encl_Typ)
1284 and then No (Cont_Encl_Typ)
1285 and then Is_Public_Operation
1286 and then Scope_Depth (Pref_Encl_Typ) >=
1287 Object_Access_Level (Context)
1290 ("?possible unprotected access to protected data", Expr);
1293 end Check_Unprotected_Access;
1299 procedure Check_VMS (Construct : Node_Id) is
1301 if not OpenVMS_On_Target then
1303 ("this construct is allowed only in Open'V'M'S", Construct);
1307 ------------------------
1308 -- Collect_Interfaces --
1309 ------------------------
1311 procedure Collect_Interfaces
1313 Ifaces_List : out Elist_Id;
1314 Exclude_Parents : Boolean := False;
1315 Use_Full_View : Boolean := True)
1317 procedure Collect (Typ : Entity_Id);
1318 -- Subsidiary subprogram used to traverse the whole list
1319 -- of directly and indirectly implemented interfaces
1325 procedure Collect (Typ : Entity_Id) is
1326 Ancestor : Entity_Id;
1334 -- Handle private types
1337 and then Is_Private_Type (Typ)
1338 and then Present (Full_View (Typ))
1340 Full_T := Full_View (Typ);
1343 -- Include the ancestor if we are generating the whole list of
1344 -- abstract interfaces.
1346 if Etype (Full_T) /= Typ
1348 -- Protect the frontend against wrong sources. For example:
1351 -- type A is tagged null record;
1352 -- type B is new A with private;
1353 -- type C is new A with private;
1355 -- type B is new C with null record;
1356 -- type C is new B with null record;
1359 and then Etype (Full_T) /= T
1361 Ancestor := Etype (Full_T);
1364 if Is_Interface (Ancestor)
1365 and then not Exclude_Parents
1367 Append_Unique_Elmt (Ancestor, Ifaces_List);
1371 -- Traverse the graph of ancestor interfaces
1373 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1374 Id := First (Abstract_Interface_List (Full_T));
1375 while Present (Id) loop
1376 Iface := Etype (Id);
1378 -- Protect against wrong uses. For example:
1379 -- type I is interface;
1380 -- type O is tagged null record;
1381 -- type Wrong is new I and O with null record; -- ERROR
1383 if Is_Interface (Iface) then
1385 and then Etype (T) /= T
1386 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1391 Append_Unique_Elmt (Iface, Ifaces_List);
1400 -- Start of processing for Collect_Interfaces
1403 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1404 Ifaces_List := New_Elmt_List;
1406 end Collect_Interfaces;
1408 ----------------------------------
1409 -- Collect_Interface_Components --
1410 ----------------------------------
1412 procedure Collect_Interface_Components
1413 (Tagged_Type : Entity_Id;
1414 Components_List : out Elist_Id)
1416 procedure Collect (Typ : Entity_Id);
1417 -- Subsidiary subprogram used to climb to the parents
1423 procedure Collect (Typ : Entity_Id) is
1424 Tag_Comp : Entity_Id;
1425 Parent_Typ : Entity_Id;
1428 -- Handle private types
1430 if Present (Full_View (Etype (Typ))) then
1431 Parent_Typ := Full_View (Etype (Typ));
1433 Parent_Typ := Etype (Typ);
1436 if Parent_Typ /= Typ
1438 -- Protect the frontend against wrong sources. For example:
1441 -- type A is tagged null record;
1442 -- type B is new A with private;
1443 -- type C is new A with private;
1445 -- type B is new C with null record;
1446 -- type C is new B with null record;
1449 and then Parent_Typ /= Tagged_Type
1451 Collect (Parent_Typ);
1454 -- Collect the components containing tags of secondary dispatch
1457 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1458 while Present (Tag_Comp) loop
1459 pragma Assert (Present (Related_Type (Tag_Comp)));
1460 Append_Elmt (Tag_Comp, Components_List);
1462 Tag_Comp := Next_Tag_Component (Tag_Comp);
1466 -- Start of processing for Collect_Interface_Components
1469 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1470 and then Is_Tagged_Type (Tagged_Type));
1472 Components_List := New_Elmt_List;
1473 Collect (Tagged_Type);
1474 end Collect_Interface_Components;
1476 -----------------------------
1477 -- Collect_Interfaces_Info --
1478 -----------------------------
1480 procedure Collect_Interfaces_Info
1482 Ifaces_List : out Elist_Id;
1483 Components_List : out Elist_Id;
1484 Tags_List : out Elist_Id)
1486 Comps_List : Elist_Id;
1487 Comp_Elmt : Elmt_Id;
1488 Comp_Iface : Entity_Id;
1489 Iface_Elmt : Elmt_Id;
1492 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1493 -- Search for the secondary tag associated with the interface type
1494 -- Iface that is implemented by T.
1500 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1504 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1506 and then Ekind (Node (ADT)) = E_Constant
1507 and then Related_Type (Node (ADT)) /= Iface
1509 -- Skip the secondary dispatch tables of Iface
1517 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1521 -- Start of processing for Collect_Interfaces_Info
1524 Collect_Interfaces (T, Ifaces_List);
1525 Collect_Interface_Components (T, Comps_List);
1527 -- Search for the record component and tag associated with each
1528 -- interface type of T.
1530 Components_List := New_Elmt_List;
1531 Tags_List := New_Elmt_List;
1533 Iface_Elmt := First_Elmt (Ifaces_List);
1534 while Present (Iface_Elmt) loop
1535 Iface := Node (Iface_Elmt);
1537 -- Associate the primary tag component and the primary dispatch table
1538 -- with all the interfaces that are parents of T
1540 if Is_Ancestor (Iface, T) then
1541 Append_Elmt (First_Tag_Component (T), Components_List);
1542 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1544 -- Otherwise search for the tag component and secondary dispatch
1548 Comp_Elmt := First_Elmt (Comps_List);
1549 while Present (Comp_Elmt) loop
1550 Comp_Iface := Related_Type (Node (Comp_Elmt));
1552 if Comp_Iface = Iface
1553 or else Is_Ancestor (Iface, Comp_Iface)
1555 Append_Elmt (Node (Comp_Elmt), Components_List);
1556 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1560 Next_Elmt (Comp_Elmt);
1562 pragma Assert (Present (Comp_Elmt));
1565 Next_Elmt (Iface_Elmt);
1567 end Collect_Interfaces_Info;
1569 ----------------------------------
1570 -- Collect_Primitive_Operations --
1571 ----------------------------------
1573 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1574 B_Type : constant Entity_Id := Base_Type (T);
1575 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1576 B_Scope : Entity_Id := Scope (B_Type);
1580 Formal_Derived : Boolean := False;
1584 -- For tagged types, the primitive operations are collected as they
1585 -- are declared, and held in an explicit list which is simply returned.
1587 if Is_Tagged_Type (B_Type) then
1588 return Primitive_Operations (B_Type);
1590 -- An untagged generic type that is a derived type inherits the
1591 -- primitive operations of its parent type. Other formal types only
1592 -- have predefined operators, which are not explicitly represented.
1594 elsif Is_Generic_Type (B_Type) then
1595 if Nkind (B_Decl) = N_Formal_Type_Declaration
1596 and then Nkind (Formal_Type_Definition (B_Decl))
1597 = N_Formal_Derived_Type_Definition
1599 Formal_Derived := True;
1601 return New_Elmt_List;
1605 Op_List := New_Elmt_List;
1607 if B_Scope = Standard_Standard then
1608 if B_Type = Standard_String then
1609 Append_Elmt (Standard_Op_Concat, Op_List);
1611 elsif B_Type = Standard_Wide_String then
1612 Append_Elmt (Standard_Op_Concatw, Op_List);
1618 elsif (Is_Package_Or_Generic_Package (B_Scope)
1620 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1622 or else Is_Derived_Type (B_Type)
1624 -- The primitive operations appear after the base type, except
1625 -- if the derivation happens within the private part of B_Scope
1626 -- and the type is a private type, in which case both the type
1627 -- and some primitive operations may appear before the base
1628 -- type, and the list of candidates starts after the type.
1630 if In_Open_Scopes (B_Scope)
1631 and then Scope (T) = B_Scope
1632 and then In_Private_Part (B_Scope)
1634 Id := Next_Entity (T);
1636 Id := Next_Entity (B_Type);
1639 while Present (Id) loop
1641 -- Note that generic formal subprograms are not
1642 -- considered to be primitive operations and thus
1643 -- are never inherited.
1645 if Is_Overloadable (Id)
1646 and then Nkind (Parent (Parent (Id)))
1647 not in N_Formal_Subprogram_Declaration
1651 if Base_Type (Etype (Id)) = B_Type then
1654 Formal := First_Formal (Id);
1655 while Present (Formal) loop
1656 if Base_Type (Etype (Formal)) = B_Type then
1660 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1662 (Designated_Type (Etype (Formal))) = B_Type
1668 Next_Formal (Formal);
1672 -- For a formal derived type, the only primitives are the
1673 -- ones inherited from the parent type. Operations appearing
1674 -- in the package declaration are not primitive for it.
1677 and then (not Formal_Derived
1678 or else Present (Alias (Id)))
1680 Append_Elmt (Id, Op_List);
1686 -- For a type declared in System, some of its operations
1687 -- may appear in the target-specific extension to System.
1690 and then Chars (B_Scope) = Name_System
1691 and then Scope (B_Scope) = Standard_Standard
1692 and then Present_System_Aux
1694 B_Scope := System_Aux_Id;
1695 Id := First_Entity (System_Aux_Id);
1701 end Collect_Primitive_Operations;
1703 -----------------------------------
1704 -- Compile_Time_Constraint_Error --
1705 -----------------------------------
1707 function Compile_Time_Constraint_Error
1710 Ent : Entity_Id := Empty;
1711 Loc : Source_Ptr := No_Location;
1712 Warn : Boolean := False) return Node_Id
1714 Msgc : String (1 .. Msg'Length + 2);
1715 -- Copy of message, with room for possible ? and ! at end
1725 -- A static constraint error in an instance body is not a fatal error.
1726 -- we choose to inhibit the message altogether, because there is no
1727 -- obvious node (for now) on which to post it. On the other hand the
1728 -- offending node must be replaced with a constraint_error in any case.
1730 -- No messages are generated if we already posted an error on this node
1732 if not Error_Posted (N) then
1733 if Loc /= No_Location then
1739 Msgc (1 .. Msg'Length) := Msg;
1742 -- Message is a warning, even in Ada 95 case
1744 if Msg (Msg'Last) = '?' then
1747 -- In Ada 83, all messages are warnings. In the private part and
1748 -- the body of an instance, constraint_checks are only warnings.
1749 -- We also make this a warning if the Warn parameter is set.
1752 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1758 elsif In_Instance_Not_Visible then
1763 -- Otherwise we have a real error message (Ada 95 static case)
1764 -- and we make this an unconditional message. Note that in the
1765 -- warning case we do not make the message unconditional, it seems
1766 -- quite reasonable to delete messages like this (about exceptions
1767 -- that will be raised) in dead code.
1775 -- Should we generate a warning? The answer is not quite yes. The
1776 -- very annoying exception occurs in the case of a short circuit
1777 -- operator where the left operand is static and decisive. Climb
1778 -- parents to see if that is the case we have here. Conditional
1779 -- expressions with decisive conditions are a similar situation.
1787 -- And then with False as left operand
1789 if Nkind (P) = N_And_Then
1790 and then Compile_Time_Known_Value (Left_Opnd (P))
1791 and then Is_False (Expr_Value (Left_Opnd (P)))
1796 -- OR ELSE with True as left operand
1798 elsif Nkind (P) = N_Or_Else
1799 and then Compile_Time_Known_Value (Left_Opnd (P))
1800 and then Is_True (Expr_Value (Left_Opnd (P)))
1805 -- Conditional expression
1807 elsif Nkind (P) = N_Conditional_Expression then
1809 Cond : constant Node_Id := First (Expressions (P));
1810 Texp : constant Node_Id := Next (Cond);
1811 Fexp : constant Node_Id := Next (Texp);
1814 if Compile_Time_Known_Value (Cond) then
1816 -- Condition is True and we are in the right operand
1818 if Is_True (Expr_Value (Cond))
1819 and then OldP = Fexp
1824 -- Condition is False and we are in the left operand
1826 elsif Is_False (Expr_Value (Cond))
1827 and then OldP = Texp
1835 -- Special case for component association in aggregates, where
1836 -- we want to keep climbing up to the parent aggregate.
1838 elsif Nkind (P) = N_Component_Association
1839 and then Nkind (Parent (P)) = N_Aggregate
1843 -- Keep going if within subexpression
1846 exit when Nkind (P) not in N_Subexpr;
1851 if Present (Ent) then
1852 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1854 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1858 if Inside_Init_Proc then
1860 ("\?& will be raised for objects of this type",
1861 N, Standard_Constraint_Error, Eloc);
1864 ("\?& will be raised at run time",
1865 N, Standard_Constraint_Error, Eloc);
1870 ("\static expression fails Constraint_Check", Eloc);
1871 Set_Error_Posted (N);
1877 end Compile_Time_Constraint_Error;
1879 -----------------------
1880 -- Conditional_Delay --
1881 -----------------------
1883 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1885 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1886 Set_Has_Delayed_Freeze (New_Ent);
1888 end Conditional_Delay;
1890 -------------------------
1891 -- Copy_Parameter_List --
1892 -------------------------
1894 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1895 Loc : constant Source_Ptr := Sloc (Subp_Id);
1900 if No (First_Formal (Subp_Id)) then
1904 Formal := First_Formal (Subp_Id);
1905 while Present (Formal) loop
1907 (Make_Parameter_Specification (Loc,
1908 Defining_Identifier =>
1909 Make_Defining_Identifier (Sloc (Formal),
1910 Chars => Chars (Formal)),
1911 In_Present => In_Present (Parent (Formal)),
1912 Out_Present => Out_Present (Parent (Formal)),
1914 New_Reference_To (Etype (Formal), Loc),
1916 New_Copy_Tree (Expression (Parent (Formal)))),
1919 Next_Formal (Formal);
1924 end Copy_Parameter_List;
1926 --------------------
1927 -- Current_Entity --
1928 --------------------
1930 -- The currently visible definition for a given identifier is the
1931 -- one most chained at the start of the visibility chain, i.e. the
1932 -- one that is referenced by the Node_Id value of the name of the
1933 -- given identifier.
1935 function Current_Entity (N : Node_Id) return Entity_Id is
1937 return Get_Name_Entity_Id (Chars (N));
1940 -----------------------------
1941 -- Current_Entity_In_Scope --
1942 -----------------------------
1944 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1946 CS : constant Entity_Id := Current_Scope;
1948 Transient_Case : constant Boolean := Scope_Is_Transient;
1951 E := Get_Name_Entity_Id (Chars (N));
1953 and then Scope (E) /= CS
1954 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1960 end Current_Entity_In_Scope;
1966 function Current_Scope return Entity_Id is
1968 if Scope_Stack.Last = -1 then
1969 return Standard_Standard;
1972 C : constant Entity_Id :=
1973 Scope_Stack.Table (Scope_Stack.Last).Entity;
1978 return Standard_Standard;
1984 ------------------------
1985 -- Current_Subprogram --
1986 ------------------------
1988 function Current_Subprogram return Entity_Id is
1989 Scop : constant Entity_Id := Current_Scope;
1991 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1994 return Enclosing_Subprogram (Scop);
1996 end Current_Subprogram;
1998 ---------------------
1999 -- Defining_Entity --
2000 ---------------------
2002 function Defining_Entity (N : Node_Id) return Entity_Id is
2003 K : constant Node_Kind := Nkind (N);
2004 Err : Entity_Id := Empty;
2009 N_Subprogram_Declaration |
2010 N_Abstract_Subprogram_Declaration |
2012 N_Package_Declaration |
2013 N_Subprogram_Renaming_Declaration |
2014 N_Subprogram_Body_Stub |
2015 N_Generic_Subprogram_Declaration |
2016 N_Generic_Package_Declaration |
2017 N_Formal_Subprogram_Declaration
2019 return Defining_Entity (Specification (N));
2022 N_Component_Declaration |
2023 N_Defining_Program_Unit_Name |
2024 N_Discriminant_Specification |
2026 N_Entry_Declaration |
2027 N_Entry_Index_Specification |
2028 N_Exception_Declaration |
2029 N_Exception_Renaming_Declaration |
2030 N_Formal_Object_Declaration |
2031 N_Formal_Package_Declaration |
2032 N_Formal_Type_Declaration |
2033 N_Full_Type_Declaration |
2034 N_Implicit_Label_Declaration |
2035 N_Incomplete_Type_Declaration |
2036 N_Loop_Parameter_Specification |
2037 N_Number_Declaration |
2038 N_Object_Declaration |
2039 N_Object_Renaming_Declaration |
2040 N_Package_Body_Stub |
2041 N_Parameter_Specification |
2042 N_Private_Extension_Declaration |
2043 N_Private_Type_Declaration |
2045 N_Protected_Body_Stub |
2046 N_Protected_Type_Declaration |
2047 N_Single_Protected_Declaration |
2048 N_Single_Task_Declaration |
2049 N_Subtype_Declaration |
2052 N_Task_Type_Declaration
2054 return Defining_Identifier (N);
2057 return Defining_Entity (Proper_Body (N));
2060 N_Function_Instantiation |
2061 N_Function_Specification |
2062 N_Generic_Function_Renaming_Declaration |
2063 N_Generic_Package_Renaming_Declaration |
2064 N_Generic_Procedure_Renaming_Declaration |
2066 N_Package_Instantiation |
2067 N_Package_Renaming_Declaration |
2068 N_Package_Specification |
2069 N_Procedure_Instantiation |
2070 N_Procedure_Specification
2073 Nam : constant Node_Id := Defining_Unit_Name (N);
2076 if Nkind (Nam) in N_Entity then
2079 -- For Error, make up a name and attach to declaration
2080 -- so we can continue semantic analysis
2082 elsif Nam = Error then
2084 Make_Defining_Identifier (Sloc (N),
2085 Chars => New_Internal_Name ('T'));
2086 Set_Defining_Unit_Name (N, Err);
2089 -- If not an entity, get defining identifier
2092 return Defining_Identifier (Nam);
2096 when N_Block_Statement =>
2097 return Entity (Identifier (N));
2100 raise Program_Error;
2103 end Defining_Entity;
2105 --------------------------
2106 -- Denotes_Discriminant --
2107 --------------------------
2109 function Denotes_Discriminant
2111 Check_Concurrent : Boolean := False) return Boolean
2115 if not Is_Entity_Name (N)
2116 or else No (Entity (N))
2123 -- If we are checking for a protected type, the discriminant may have
2124 -- been rewritten as the corresponding discriminal of the original type
2125 -- or of the corresponding concurrent record, depending on whether we
2126 -- are in the spec or body of the protected type.
2128 return Ekind (E) = E_Discriminant
2131 and then Ekind (E) = E_In_Parameter
2132 and then Present (Discriminal_Link (E))
2134 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2136 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2138 end Denotes_Discriminant;
2140 ----------------------
2141 -- Denotes_Variable --
2142 ----------------------
2144 function Denotes_Variable (N : Node_Id) return Boolean is
2146 return Is_Variable (N) and then Paren_Count (N) = 0;
2147 end Denotes_Variable;
2149 -----------------------------
2150 -- Depends_On_Discriminant --
2151 -----------------------------
2153 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2158 Get_Index_Bounds (N, L, H);
2159 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2160 end Depends_On_Discriminant;
2162 -------------------------
2163 -- Designate_Same_Unit --
2164 -------------------------
2166 function Designate_Same_Unit
2168 Name2 : Node_Id) return Boolean
2170 K1 : constant Node_Kind := Nkind (Name1);
2171 K2 : constant Node_Kind := Nkind (Name2);
2173 function Prefix_Node (N : Node_Id) return Node_Id;
2174 -- Returns the parent unit name node of a defining program unit name
2175 -- or the prefix if N is a selected component or an expanded name.
2177 function Select_Node (N : Node_Id) return Node_Id;
2178 -- Returns the defining identifier node of a defining program unit
2179 -- name or the selector node if N is a selected component or an
2186 function Prefix_Node (N : Node_Id) return Node_Id is
2188 if Nkind (N) = N_Defining_Program_Unit_Name then
2200 function Select_Node (N : Node_Id) return Node_Id is
2202 if Nkind (N) = N_Defining_Program_Unit_Name then
2203 return Defining_Identifier (N);
2206 return Selector_Name (N);
2210 -- Start of processing for Designate_Next_Unit
2213 if (K1 = N_Identifier or else
2214 K1 = N_Defining_Identifier)
2216 (K2 = N_Identifier or else
2217 K2 = N_Defining_Identifier)
2219 return Chars (Name1) = Chars (Name2);
2222 (K1 = N_Expanded_Name or else
2223 K1 = N_Selected_Component or else
2224 K1 = N_Defining_Program_Unit_Name)
2226 (K2 = N_Expanded_Name or else
2227 K2 = N_Selected_Component or else
2228 K2 = N_Defining_Program_Unit_Name)
2231 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2233 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2238 end Designate_Same_Unit;
2240 ----------------------------
2241 -- Enclosing_Generic_Body --
2242 ----------------------------
2244 function Enclosing_Generic_Body
2245 (N : Node_Id) return Node_Id
2253 while Present (P) loop
2254 if Nkind (P) = N_Package_Body
2255 or else Nkind (P) = N_Subprogram_Body
2257 Spec := Corresponding_Spec (P);
2259 if Present (Spec) then
2260 Decl := Unit_Declaration_Node (Spec);
2262 if Nkind (Decl) = N_Generic_Package_Declaration
2263 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2274 end Enclosing_Generic_Body;
2276 ----------------------------
2277 -- Enclosing_Generic_Unit --
2278 ----------------------------
2280 function Enclosing_Generic_Unit
2281 (N : Node_Id) return Node_Id
2289 while Present (P) loop
2290 if Nkind (P) = N_Generic_Package_Declaration
2291 or else Nkind (P) = N_Generic_Subprogram_Declaration
2295 elsif Nkind (P) = N_Package_Body
2296 or else Nkind (P) = N_Subprogram_Body
2298 Spec := Corresponding_Spec (P);
2300 if Present (Spec) then
2301 Decl := Unit_Declaration_Node (Spec);
2303 if Nkind (Decl) = N_Generic_Package_Declaration
2304 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2315 end Enclosing_Generic_Unit;
2317 -------------------------------
2318 -- Enclosing_Lib_Unit_Entity --
2319 -------------------------------
2321 function Enclosing_Lib_Unit_Entity return Entity_Id is
2322 Unit_Entity : Entity_Id;
2325 -- Look for enclosing library unit entity by following scope links.
2326 -- Equivalent to, but faster than indexing through the scope stack.
2328 Unit_Entity := Current_Scope;
2329 while (Present (Scope (Unit_Entity))
2330 and then Scope (Unit_Entity) /= Standard_Standard)
2331 and not Is_Child_Unit (Unit_Entity)
2333 Unit_Entity := Scope (Unit_Entity);
2337 end Enclosing_Lib_Unit_Entity;
2339 -----------------------------
2340 -- Enclosing_Lib_Unit_Node --
2341 -----------------------------
2343 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2344 Current_Node : Node_Id;
2348 while Present (Current_Node)
2349 and then Nkind (Current_Node) /= N_Compilation_Unit
2351 Current_Node := Parent (Current_Node);
2354 if Nkind (Current_Node) /= N_Compilation_Unit then
2358 return Current_Node;
2359 end Enclosing_Lib_Unit_Node;
2361 --------------------------
2362 -- Enclosing_Subprogram --
2363 --------------------------
2365 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2366 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2369 if Dynamic_Scope = Standard_Standard then
2372 elsif Dynamic_Scope = Empty then
2375 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2376 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2378 elsif Ekind (Dynamic_Scope) = E_Block
2379 or else Ekind (Dynamic_Scope) = E_Return_Statement
2381 return Enclosing_Subprogram (Dynamic_Scope);
2383 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2384 return Get_Task_Body_Procedure (Dynamic_Scope);
2386 elsif Convention (Dynamic_Scope) = Convention_Protected then
2387 return Protected_Body_Subprogram (Dynamic_Scope);
2390 return Dynamic_Scope;
2392 end Enclosing_Subprogram;
2394 ------------------------
2395 -- Ensure_Freeze_Node --
2396 ------------------------
2398 procedure Ensure_Freeze_Node (E : Entity_Id) is
2402 if No (Freeze_Node (E)) then
2403 FN := Make_Freeze_Entity (Sloc (E));
2404 Set_Has_Delayed_Freeze (E);
2405 Set_Freeze_Node (E, FN);
2406 Set_Access_Types_To_Process (FN, No_Elist);
2407 Set_TSS_Elist (FN, No_Elist);
2410 end Ensure_Freeze_Node;
2416 procedure Enter_Name (Def_Id : Entity_Id) is
2417 C : constant Entity_Id := Current_Entity (Def_Id);
2418 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2419 S : constant Entity_Id := Current_Scope;
2422 Generate_Definition (Def_Id);
2424 -- Add new name to current scope declarations. Check for duplicate
2425 -- declaration, which may or may not be a genuine error.
2429 -- Case of previous entity entered because of a missing declaration
2430 -- or else a bad subtype indication. Best is to use the new entity,
2431 -- and make the previous one invisible.
2433 if Etype (E) = Any_Type then
2434 Set_Is_Immediately_Visible (E, False);
2436 -- Case of renaming declaration constructed for package instances.
2437 -- if there is an explicit declaration with the same identifier,
2438 -- the renaming is not immediately visible any longer, but remains
2439 -- visible through selected component notation.
2441 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2442 and then not Comes_From_Source (E)
2444 Set_Is_Immediately_Visible (E, False);
2446 -- The new entity may be the package renaming, which has the same
2447 -- same name as a generic formal which has been seen already.
2449 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2450 and then not Comes_From_Source (Def_Id)
2452 Set_Is_Immediately_Visible (E, False);
2454 -- For a fat pointer corresponding to a remote access to subprogram,
2455 -- we use the same identifier as the RAS type, so that the proper
2456 -- name appears in the stub. This type is only retrieved through
2457 -- the RAS type and never by visibility, and is not added to the
2458 -- visibility list (see below).
2460 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2461 and then Present (Corresponding_Remote_Type (Def_Id))
2465 -- A controller component for a type extension overrides the
2466 -- inherited component.
2468 elsif Chars (E) = Name_uController then
2471 -- Case of an implicit operation or derived literal. The new entity
2472 -- hides the implicit one, which is removed from all visibility,
2473 -- i.e. the entity list of its scope, and homonym chain of its name.
2475 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2476 or else Is_Internal (E)
2480 Prev_Vis : Entity_Id;
2481 Decl : constant Node_Id := Parent (E);
2484 -- If E is an implicit declaration, it cannot be the first
2485 -- entity in the scope.
2487 Prev := First_Entity (Current_Scope);
2488 while Present (Prev)
2489 and then Next_Entity (Prev) /= E
2496 -- If E is not on the entity chain of the current scope,
2497 -- it is an implicit declaration in the generic formal
2498 -- part of a generic subprogram. When analyzing the body,
2499 -- the generic formals are visible but not on the entity
2500 -- chain of the subprogram. The new entity will become
2501 -- the visible one in the body.
2504 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2508 Set_Next_Entity (Prev, Next_Entity (E));
2510 if No (Next_Entity (Prev)) then
2511 Set_Last_Entity (Current_Scope, Prev);
2514 if E = Current_Entity (E) then
2518 Prev_Vis := Current_Entity (E);
2519 while Homonym (Prev_Vis) /= E loop
2520 Prev_Vis := Homonym (Prev_Vis);
2524 if Present (Prev_Vis) then
2526 -- Skip E in the visibility chain
2528 Set_Homonym (Prev_Vis, Homonym (E));
2531 Set_Name_Entity_Id (Chars (E), Homonym (E));
2536 -- This section of code could use a comment ???
2538 elsif Present (Etype (E))
2539 and then Is_Concurrent_Type (Etype (E))
2544 -- If the homograph is a protected component renaming, it should not
2545 -- be hiding the current entity. Such renamings are treated as weak
2548 elsif Is_Prival (E) then
2549 Set_Is_Immediately_Visible (E, False);
2551 -- In this case the current entity is a protected component renaming.
2552 -- Perform minimal decoration by setting the scope and return since
2553 -- the prival should not be hiding other visible entities.
2555 elsif Is_Prival (Def_Id) then
2556 Set_Scope (Def_Id, Current_Scope);
2559 -- Analogous to privals, the discriminal generated for an entry
2560 -- index parameter acts as a weak declaration. Perform minimal
2561 -- decoration to avoid bogus errors.
2563 elsif Is_Discriminal (Def_Id)
2564 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2566 Set_Scope (Def_Id, Current_Scope);
2569 -- In the body or private part of an instance, a type extension
2570 -- may introduce a component with the same name as that of an
2571 -- actual. The legality rule is not enforced, but the semantics
2572 -- of the full type with two components of the same name are not
2573 -- clear at this point ???
2575 elsif In_Instance_Not_Visible then
2578 -- When compiling a package body, some child units may have become
2579 -- visible. They cannot conflict with local entities that hide them.
2581 elsif Is_Child_Unit (E)
2582 and then In_Open_Scopes (Scope (E))
2583 and then not Is_Immediately_Visible (E)
2587 -- Conversely, with front-end inlining we may compile the parent
2588 -- body first, and a child unit subsequently. The context is now
2589 -- the parent spec, and body entities are not visible.
2591 elsif Is_Child_Unit (Def_Id)
2592 and then Is_Package_Body_Entity (E)
2593 and then not In_Package_Body (Current_Scope)
2597 -- Case of genuine duplicate declaration
2600 Error_Msg_Sloc := Sloc (E);
2602 -- If the previous declaration is an incomplete type declaration
2603 -- this may be an attempt to complete it with a private type.
2604 -- The following avoids confusing cascaded errors.
2606 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2607 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2610 ("incomplete type cannot be completed with a private " &
2611 "declaration", Parent (Def_Id));
2612 Set_Is_Immediately_Visible (E, False);
2613 Set_Full_View (E, Def_Id);
2615 -- An inherited component of a record conflicts with a new
2616 -- discriminant. The discriminant is inserted first in the scope,
2617 -- but the error should be posted on it, not on the component.
2619 elsif Ekind (E) = E_Discriminant
2620 and then Present (Scope (Def_Id))
2621 and then Scope (Def_Id) /= Current_Scope
2623 Error_Msg_Sloc := Sloc (Def_Id);
2624 Error_Msg_N ("& conflicts with declaration#", E);
2627 -- If the name of the unit appears in its own context clause,
2628 -- a dummy package with the name has already been created, and
2629 -- the error emitted. Try to continue quietly.
2631 elsif Error_Posted (E)
2632 and then Sloc (E) = No_Location
2633 and then Nkind (Parent (E)) = N_Package_Specification
2634 and then Current_Scope = Standard_Standard
2636 Set_Scope (Def_Id, Current_Scope);
2640 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2642 -- Avoid cascaded messages with duplicate components in
2645 if Ekind (E) = E_Component
2646 or else Ekind (E) = E_Discriminant
2652 if Nkind (Parent (Parent (Def_Id))) =
2653 N_Generic_Subprogram_Declaration
2655 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2657 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2660 -- If entity is in standard, then we are in trouble, because
2661 -- it means that we have a library package with a duplicated
2662 -- name. That's hard to recover from, so abort!
2664 if S = Standard_Standard then
2665 raise Unrecoverable_Error;
2667 -- Otherwise we continue with the declaration. Having two
2668 -- identical declarations should not cause us too much trouble!
2676 -- If we fall through, declaration is OK , or OK enough to continue
2678 -- If Def_Id is a discriminant or a record component we are in the
2679 -- midst of inheriting components in a derived record definition.
2680 -- Preserve their Ekind and Etype.
2682 if Ekind (Def_Id) = E_Discriminant
2683 or else Ekind (Def_Id) = E_Component
2687 -- If a type is already set, leave it alone (happens whey a type
2688 -- declaration is reanalyzed following a call to the optimizer)
2690 elsif Present (Etype (Def_Id)) then
2693 -- Otherwise, the kind E_Void insures that premature uses of the entity
2694 -- will be detected. Any_Type insures that no cascaded errors will occur
2697 Set_Ekind (Def_Id, E_Void);
2698 Set_Etype (Def_Id, Any_Type);
2701 -- Inherited discriminants and components in derived record types are
2702 -- immediately visible. Itypes are not.
2704 if Ekind (Def_Id) = E_Discriminant
2705 or else Ekind (Def_Id) = E_Component
2706 or else (No (Corresponding_Remote_Type (Def_Id))
2707 and then not Is_Itype (Def_Id))
2709 Set_Is_Immediately_Visible (Def_Id);
2710 Set_Current_Entity (Def_Id);
2713 Set_Homonym (Def_Id, C);
2714 Append_Entity (Def_Id, S);
2715 Set_Public_Status (Def_Id);
2717 -- Warn if new entity hides an old one
2719 if Warn_On_Hiding and then Present (C)
2721 -- Don't warn for record components since they always have a well
2722 -- defined scope which does not confuse other uses. Note that in
2723 -- some cases, Ekind has not been set yet.
2725 and then Ekind (C) /= E_Component
2726 and then Ekind (C) /= E_Discriminant
2727 and then Nkind (Parent (C)) /= N_Component_Declaration
2728 and then Ekind (Def_Id) /= E_Component
2729 and then Ekind (Def_Id) /= E_Discriminant
2730 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2732 -- Don't warn for one character variables. It is too common to use
2733 -- such variables as locals and will just cause too many false hits.
2735 and then Length_Of_Name (Chars (C)) /= 1
2737 -- Don't warn for non-source entities
2739 and then Comes_From_Source (C)
2740 and then Comes_From_Source (Def_Id)
2742 -- Don't warn unless entity in question is in extended main source
2744 and then In_Extended_Main_Source_Unit (Def_Id)
2746 -- Finally, the hidden entity must be either immediately visible
2747 -- or use visible (from a used package)
2750 (Is_Immediately_Visible (C)
2752 Is_Potentially_Use_Visible (C))
2754 Error_Msg_Sloc := Sloc (C);
2755 Error_Msg_N ("declaration hides &#?", Def_Id);
2759 --------------------------
2760 -- Explain_Limited_Type --
2761 --------------------------
2763 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2767 -- For array, component type must be limited
2769 if Is_Array_Type (T) then
2770 Error_Msg_Node_2 := T;
2772 ("\component type& of type& is limited", N, Component_Type (T));
2773 Explain_Limited_Type (Component_Type (T), N);
2775 elsif Is_Record_Type (T) then
2777 -- No need for extra messages if explicit limited record
2779 if Is_Limited_Record (Base_Type (T)) then
2783 -- Otherwise find a limited component. Check only components that
2784 -- come from source, or inherited components that appear in the
2785 -- source of the ancestor.
2787 C := First_Component (T);
2788 while Present (C) loop
2789 if Is_Limited_Type (Etype (C))
2791 (Comes_From_Source (C)
2793 (Present (Original_Record_Component (C))
2795 Comes_From_Source (Original_Record_Component (C))))
2797 Error_Msg_Node_2 := T;
2798 Error_Msg_NE ("\component& of type& has limited type", N, C);
2799 Explain_Limited_Type (Etype (C), N);
2806 -- The type may be declared explicitly limited, even if no component
2807 -- of it is limited, in which case we fall out of the loop.
2810 end Explain_Limited_Type;
2816 procedure Find_Actual
2818 Formal : out Entity_Id;
2821 Parnt : constant Node_Id := Parent (N);
2825 if (Nkind (Parnt) = N_Indexed_Component
2827 Nkind (Parnt) = N_Selected_Component)
2828 and then N = Prefix (Parnt)
2830 Find_Actual (Parnt, Formal, Call);
2833 elsif Nkind (Parnt) = N_Parameter_Association
2834 and then N = Explicit_Actual_Parameter (Parnt)
2836 Call := Parent (Parnt);
2838 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2847 -- If we have a call to a subprogram look for the parameter. Note that
2848 -- we exclude overloaded calls, since we don't know enough to be sure
2849 -- of giving the right answer in this case.
2851 if Is_Entity_Name (Name (Call))
2852 and then Present (Entity (Name (Call)))
2853 and then Is_Overloadable (Entity (Name (Call)))
2854 and then not Is_Overloaded (Name (Call))
2856 -- Fall here if we are definitely a parameter
2858 Actual := First_Actual (Call);
2859 Formal := First_Formal (Entity (Name (Call)));
2860 while Present (Formal) and then Present (Actual) loop
2864 Actual := Next_Actual (Actual);
2865 Formal := Next_Formal (Formal);
2870 -- Fall through here if we did not find matching actual
2876 -------------------------------------
2877 -- Find_Corresponding_Discriminant --
2878 -------------------------------------
2880 function Find_Corresponding_Discriminant
2882 Typ : Entity_Id) return Entity_Id
2884 Par_Disc : Entity_Id;
2885 Old_Disc : Entity_Id;
2886 New_Disc : Entity_Id;
2889 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2891 -- The original type may currently be private, and the discriminant
2892 -- only appear on its full view.
2894 if Is_Private_Type (Scope (Par_Disc))
2895 and then not Has_Discriminants (Scope (Par_Disc))
2896 and then Present (Full_View (Scope (Par_Disc)))
2898 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2900 Old_Disc := First_Discriminant (Scope (Par_Disc));
2903 if Is_Class_Wide_Type (Typ) then
2904 New_Disc := First_Discriminant (Root_Type (Typ));
2906 New_Disc := First_Discriminant (Typ);
2909 while Present (Old_Disc) and then Present (New_Disc) loop
2910 if Old_Disc = Par_Disc then
2913 Next_Discriminant (Old_Disc);
2914 Next_Discriminant (New_Disc);
2918 -- Should always find it
2920 raise Program_Error;
2921 end Find_Corresponding_Discriminant;
2923 --------------------------
2924 -- Find_Overlaid_Entity --
2925 --------------------------
2927 procedure Find_Overlaid_Entity
2929 Ent : out Entity_Id;
2935 -- We are looking for one of the two following forms:
2937 -- for X'Address use Y'Address
2941 -- Const : constant Address := expr;
2943 -- for X'Address use Const;
2945 -- In the second case, the expr is either Y'Address, or recursively a
2946 -- constant that eventually references Y'Address.
2951 if Nkind (N) = N_Attribute_Definition_Clause
2952 and then Chars (N) = Name_Address
2954 Expr := Expression (N);
2956 -- This loop checks the form of the expression for Y'Address,
2957 -- using recursion to deal with intermediate constants.
2960 -- Check for Y'Address
2962 if Nkind (Expr) = N_Attribute_Reference
2963 and then Attribute_Name (Expr) = Name_Address
2965 Expr := Prefix (Expr);
2968 -- Check for Const where Const is a constant entity
2970 elsif Is_Entity_Name (Expr)
2971 and then Ekind (Entity (Expr)) = E_Constant
2973 Expr := Constant_Value (Entity (Expr));
2975 -- Anything else does not need checking
2982 -- This loop checks the form of the prefix for an entity,
2983 -- using recursion to deal with intermediate components.
2986 -- Check for Y where Y is an entity
2988 if Is_Entity_Name (Expr) then
2989 Ent := Entity (Expr);
2992 -- Check for components
2995 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
2997 Expr := Prefix (Expr);
3000 -- Anything else does not need checking
3007 end Find_Overlaid_Entity;
3009 -------------------------
3010 -- Find_Parameter_Type --
3011 -------------------------
3013 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3015 if Nkind (Param) /= N_Parameter_Specification then
3018 -- For an access parameter, obtain the type from the formal entity
3019 -- itself, because access to subprogram nodes do not carry a type.
3020 -- Shouldn't we always use the formal entity ???
3022 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3023 return Etype (Defining_Identifier (Param));
3026 return Etype (Parameter_Type (Param));
3028 end Find_Parameter_Type;
3030 -----------------------------
3031 -- Find_Static_Alternative --
3032 -----------------------------
3034 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3035 Expr : constant Node_Id := Expression (N);
3036 Val : constant Uint := Expr_Value (Expr);
3041 Alt := First (Alternatives (N));
3044 if Nkind (Alt) /= N_Pragma then
3045 Choice := First (Discrete_Choices (Alt));
3046 while Present (Choice) loop
3048 -- Others choice, always matches
3050 if Nkind (Choice) = N_Others_Choice then
3053 -- Range, check if value is in the range
3055 elsif Nkind (Choice) = N_Range then
3057 Val >= Expr_Value (Low_Bound (Choice))
3059 Val <= Expr_Value (High_Bound (Choice));
3061 -- Choice is a subtype name. Note that we know it must
3062 -- be a static subtype, since otherwise it would have
3063 -- been diagnosed as illegal.
3065 elsif Is_Entity_Name (Choice)
3066 and then Is_Type (Entity (Choice))
3068 exit Search when Is_In_Range (Expr, Etype (Choice),
3069 Assume_Valid => False);
3071 -- Choice is a subtype indication
3073 elsif Nkind (Choice) = N_Subtype_Indication then
3075 C : constant Node_Id := Constraint (Choice);
3076 R : constant Node_Id := Range_Expression (C);
3080 Val >= Expr_Value (Low_Bound (R))
3082 Val <= Expr_Value (High_Bound (R));
3085 -- Choice is a simple expression
3088 exit Search when Val = Expr_Value (Choice);
3096 pragma Assert (Present (Alt));
3099 -- The above loop *must* terminate by finding a match, since
3100 -- we know the case statement is valid, and the value of the
3101 -- expression is known at compile time. When we fall out of
3102 -- the loop, Alt points to the alternative that we know will
3103 -- be selected at run time.
3106 end Find_Static_Alternative;
3112 function First_Actual (Node : Node_Id) return Node_Id is
3116 if No (Parameter_Associations (Node)) then
3120 N := First (Parameter_Associations (Node));
3122 if Nkind (N) = N_Parameter_Association then
3123 return First_Named_Actual (Node);
3129 -------------------------
3130 -- Full_Qualified_Name --
3131 -------------------------
3133 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3135 pragma Warnings (Off, Res);
3137 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3138 -- Compute recursively the qualified name without NUL at the end
3140 ----------------------------------
3141 -- Internal_Full_Qualified_Name --
3142 ----------------------------------
3144 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3145 Ent : Entity_Id := E;
3146 Parent_Name : String_Id := No_String;
3149 -- Deals properly with child units
3151 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3152 Ent := Defining_Identifier (Ent);
3155 -- Compute qualification recursively (only "Standard" has no scope)
3157 if Present (Scope (Scope (Ent))) then
3158 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3161 -- Every entity should have a name except some expanded blocks
3162 -- don't bother about those.
3164 if Chars (Ent) = No_Name then
3168 -- Add a period between Name and qualification
3170 if Parent_Name /= No_String then
3171 Start_String (Parent_Name);
3172 Store_String_Char (Get_Char_Code ('.'));
3178 -- Generates the entity name in upper case
3180 Get_Decoded_Name_String (Chars (Ent));
3182 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3184 end Internal_Full_Qualified_Name;
3186 -- Start of processing for Full_Qualified_Name
3189 Res := Internal_Full_Qualified_Name (E);
3190 Store_String_Char (Get_Char_Code (ASCII.NUL));
3192 end Full_Qualified_Name;
3194 -----------------------
3195 -- Gather_Components --
3196 -----------------------
3198 procedure Gather_Components
3200 Comp_List : Node_Id;
3201 Governed_By : List_Id;
3203 Report_Errors : out Boolean)
3207 Discrete_Choice : Node_Id;
3208 Comp_Item : Node_Id;
3210 Discrim : Entity_Id;
3211 Discrim_Name : Node_Id;
3212 Discrim_Value : Node_Id;
3215 Report_Errors := False;
3217 if No (Comp_List) or else Null_Present (Comp_List) then
3220 elsif Present (Component_Items (Comp_List)) then
3221 Comp_Item := First (Component_Items (Comp_List));
3227 while Present (Comp_Item) loop
3229 -- Skip the tag of a tagged record, the interface tags, as well
3230 -- as all items that are not user components (anonymous types,
3231 -- rep clauses, Parent field, controller field).
3233 if Nkind (Comp_Item) = N_Component_Declaration then
3235 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3237 if not Is_Tag (Comp)
3238 and then Chars (Comp) /= Name_uParent
3239 and then Chars (Comp) /= Name_uController
3241 Append_Elmt (Comp, Into);
3249 if No (Variant_Part (Comp_List)) then
3252 Discrim_Name := Name (Variant_Part (Comp_List));
3253 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3256 -- Look for the discriminant that governs this variant part.
3257 -- The discriminant *must* be in the Governed_By List
3259 Assoc := First (Governed_By);
3260 Find_Constraint : loop
3261 Discrim := First (Choices (Assoc));
3262 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3263 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3265 Chars (Corresponding_Discriminant (Entity (Discrim)))
3266 = Chars (Discrim_Name))
3267 or else Chars (Original_Record_Component (Entity (Discrim)))
3268 = Chars (Discrim_Name);
3270 if No (Next (Assoc)) then
3271 if not Is_Constrained (Typ)
3272 and then Is_Derived_Type (Typ)
3273 and then Present (Stored_Constraint (Typ))
3275 -- If the type is a tagged type with inherited discriminants,
3276 -- use the stored constraint on the parent in order to find
3277 -- the values of discriminants that are otherwise hidden by an
3278 -- explicit constraint. Renamed discriminants are handled in
3281 -- If several parent discriminants are renamed by a single
3282 -- discriminant of the derived type, the call to obtain the
3283 -- Corresponding_Discriminant field only retrieves the last
3284 -- of them. We recover the constraint on the others from the
3285 -- Stored_Constraint as well.
3292 D := First_Discriminant (Etype (Typ));
3293 C := First_Elmt (Stored_Constraint (Typ));
3294 while Present (D) and then Present (C) loop
3295 if Chars (Discrim_Name) = Chars (D) then
3296 if Is_Entity_Name (Node (C))
3297 and then Entity (Node (C)) = Entity (Discrim)
3299 -- D is renamed by Discrim, whose value is given in
3306 Make_Component_Association (Sloc (Typ),
3308 (New_Occurrence_Of (D, Sloc (Typ))),
3309 Duplicate_Subexpr_No_Checks (Node (C)));
3311 exit Find_Constraint;
3314 Next_Discriminant (D);
3321 if No (Next (Assoc)) then
3322 Error_Msg_NE (" missing value for discriminant&",
3323 First (Governed_By), Discrim_Name);
3324 Report_Errors := True;
3329 end loop Find_Constraint;
3331 Discrim_Value := Expression (Assoc);
3333 if not Is_OK_Static_Expression (Discrim_Value) then
3335 ("value for discriminant & must be static!",
3336 Discrim_Value, Discrim);
3337 Why_Not_Static (Discrim_Value);
3338 Report_Errors := True;
3342 Search_For_Discriminant_Value : declare
3348 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3351 Find_Discrete_Value : while Present (Variant) loop
3352 Discrete_Choice := First (Discrete_Choices (Variant));
3353 while Present (Discrete_Choice) loop
3355 exit Find_Discrete_Value when
3356 Nkind (Discrete_Choice) = N_Others_Choice;
3358 Get_Index_Bounds (Discrete_Choice, Low, High);
3360 UI_Low := Expr_Value (Low);
3361 UI_High := Expr_Value (High);
3363 exit Find_Discrete_Value when
3364 UI_Low <= UI_Discrim_Value
3366 UI_High >= UI_Discrim_Value;
3368 Next (Discrete_Choice);
3371 Next_Non_Pragma (Variant);
3372 end loop Find_Discrete_Value;
3373 end Search_For_Discriminant_Value;
3375 if No (Variant) then
3377 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3378 Report_Errors := True;
3382 -- If we have found the corresponding choice, recursively add its
3383 -- components to the Into list.
3385 Gather_Components (Empty,
3386 Component_List (Variant), Governed_By, Into, Report_Errors);
3387 end Gather_Components;
3389 ------------------------
3390 -- Get_Actual_Subtype --
3391 ------------------------
3393 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3394 Typ : constant Entity_Id := Etype (N);
3395 Utyp : Entity_Id := Underlying_Type (Typ);
3404 -- If what we have is an identifier that references a subprogram
3405 -- formal, or a variable or constant object, then we get the actual
3406 -- subtype from the referenced entity if one has been built.
3408 if Nkind (N) = N_Identifier
3410 (Is_Formal (Entity (N))
3411 or else Ekind (Entity (N)) = E_Constant
3412 or else Ekind (Entity (N)) = E_Variable)
3413 and then Present (Actual_Subtype (Entity (N)))
3415 return Actual_Subtype (Entity (N));
3417 -- Actual subtype of unchecked union is always itself. We never need
3418 -- the "real" actual subtype. If we did, we couldn't get it anyway
3419 -- because the discriminant is not available. The restrictions on
3420 -- Unchecked_Union are designed to make sure that this is OK.
3422 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3425 -- Here for the unconstrained case, we must find actual subtype
3426 -- No actual subtype is available, so we must build it on the fly.
3428 -- Checking the type, not the underlying type, for constrainedness
3429 -- seems to be necessary. Maybe all the tests should be on the type???
3431 elsif (not Is_Constrained (Typ))
3432 and then (Is_Array_Type (Utyp)
3433 or else (Is_Record_Type (Utyp)
3434 and then Has_Discriminants (Utyp)))
3435 and then not Has_Unknown_Discriminants (Utyp)
3436 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3438 -- Nothing to do if in spec expression (why not???)
3440 if In_Spec_Expression then
3443 elsif Is_Private_Type (Typ)
3444 and then not Has_Discriminants (Typ)
3446 -- If the type has no discriminants, there is no subtype to
3447 -- build, even if the underlying type is discriminated.
3451 -- Else build the actual subtype
3454 Decl := Build_Actual_Subtype (Typ, N);
3455 Atyp := Defining_Identifier (Decl);
3457 -- If Build_Actual_Subtype generated a new declaration then use it
3461 -- The actual subtype is an Itype, so analyze the declaration,
3462 -- but do not attach it to the tree, to get the type defined.
3464 Set_Parent (Decl, N);
3465 Set_Is_Itype (Atyp);
3466 Analyze (Decl, Suppress => All_Checks);
3467 Set_Associated_Node_For_Itype (Atyp, N);
3468 Set_Has_Delayed_Freeze (Atyp, False);
3470 -- We need to freeze the actual subtype immediately. This is
3471 -- needed, because otherwise this Itype will not get frozen
3472 -- at all, and it is always safe to freeze on creation because
3473 -- any associated types must be frozen at this point.
3475 Freeze_Itype (Atyp, N);
3478 -- Otherwise we did not build a declaration, so return original
3485 -- For all remaining cases, the actual subtype is the same as
3486 -- the nominal type.
3491 end Get_Actual_Subtype;
3493 -------------------------------------
3494 -- Get_Actual_Subtype_If_Available --
3495 -------------------------------------
3497 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3498 Typ : constant Entity_Id := Etype (N);
3501 -- If what we have is an identifier that references a subprogram
3502 -- formal, or a variable or constant object, then we get the actual
3503 -- subtype from the referenced entity if one has been built.
3505 if Nkind (N) = N_Identifier
3507 (Is_Formal (Entity (N))
3508 or else Ekind (Entity (N)) = E_Constant
3509 or else Ekind (Entity (N)) = E_Variable)
3510 and then Present (Actual_Subtype (Entity (N)))
3512 return Actual_Subtype (Entity (N));
3514 -- Otherwise the Etype of N is returned unchanged
3519 end Get_Actual_Subtype_If_Available;
3521 -------------------------------
3522 -- Get_Default_External_Name --
3523 -------------------------------
3525 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3527 Get_Decoded_Name_String (Chars (E));
3529 if Opt.External_Name_Imp_Casing = Uppercase then
3530 Set_Casing (All_Upper_Case);
3532 Set_Casing (All_Lower_Case);
3536 Make_String_Literal (Sloc (E),
3537 Strval => String_From_Name_Buffer);
3538 end Get_Default_External_Name;
3540 ---------------------------
3541 -- Get_Enum_Lit_From_Pos --
3542 ---------------------------
3544 function Get_Enum_Lit_From_Pos
3547 Loc : Source_Ptr) return Node_Id
3552 -- In the case where the literal is of type Character, Wide_Character
3553 -- or Wide_Wide_Character or of a type derived from them, there needs
3554 -- to be some special handling since there is no explicit chain of
3555 -- literals to search. Instead, an N_Character_Literal node is created
3556 -- with the appropriate Char_Code and Chars fields.
3558 if Is_Standard_Character_Type (T) then
3559 Set_Character_Literal_Name (UI_To_CC (Pos));
3561 Make_Character_Literal (Loc,
3563 Char_Literal_Value => Pos);
3565 -- For all other cases, we have a complete table of literals, and
3566 -- we simply iterate through the chain of literal until the one
3567 -- with the desired position value is found.
3571 Lit := First_Literal (Base_Type (T));
3572 for J in 1 .. UI_To_Int (Pos) loop
3576 return New_Occurrence_Of (Lit, Loc);
3578 end Get_Enum_Lit_From_Pos;
3580 ------------------------
3581 -- Get_Generic_Entity --
3582 ------------------------
3584 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3585 Ent : constant Entity_Id := Entity (Name (N));
3587 if Present (Renamed_Object (Ent)) then
3588 return Renamed_Object (Ent);
3592 end Get_Generic_Entity;
3594 ----------------------
3595 -- Get_Index_Bounds --
3596 ----------------------
3598 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3599 Kind : constant Node_Kind := Nkind (N);
3603 if Kind = N_Range then
3605 H := High_Bound (N);
3607 elsif Kind = N_Subtype_Indication then
3608 R := Range_Expression (Constraint (N));
3616 L := Low_Bound (Range_Expression (Constraint (N)));
3617 H := High_Bound (Range_Expression (Constraint (N)));
3620 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3621 if Error_Posted (Scalar_Range (Entity (N))) then
3625 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3626 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3629 L := Low_Bound (Scalar_Range (Entity (N)));
3630 H := High_Bound (Scalar_Range (Entity (N)));
3634 -- N is an expression, indicating a range with one value
3639 end Get_Index_Bounds;
3641 ----------------------------------
3642 -- Get_Library_Unit_Name_string --
3643 ----------------------------------
3645 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3646 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3649 Get_Unit_Name_String (Unit_Name_Id);
3651 -- Remove seven last character (" (spec)" or " (body)")
3653 Name_Len := Name_Len - 7;
3654 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3655 end Get_Library_Unit_Name_String;
3657 ------------------------
3658 -- Get_Name_Entity_Id --
3659 ------------------------
3661 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3663 return Entity_Id (Get_Name_Table_Info (Id));
3664 end Get_Name_Entity_Id;
3670 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3672 return Get_Pragma_Id (Pragma_Name (N));
3675 ---------------------------
3676 -- Get_Referenced_Object --
3677 ---------------------------
3679 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3684 while Is_Entity_Name (R)
3685 and then Present (Renamed_Object (Entity (R)))
3687 R := Renamed_Object (Entity (R));
3691 end Get_Referenced_Object;
3693 ------------------------
3694 -- Get_Renamed_Entity --
3695 ------------------------
3697 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3702 while Present (Renamed_Entity (R)) loop
3703 R := Renamed_Entity (R);
3707 end Get_Renamed_Entity;
3709 -------------------------
3710 -- Get_Subprogram_Body --
3711 -------------------------
3713 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3717 Decl := Unit_Declaration_Node (E);
3719 if Nkind (Decl) = N_Subprogram_Body then
3722 -- The below comment is bad, because it is possible for
3723 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3725 else -- Nkind (Decl) = N_Subprogram_Declaration
3727 if Present (Corresponding_Body (Decl)) then
3728 return Unit_Declaration_Node (Corresponding_Body (Decl));
3730 -- Imported subprogram case
3736 end Get_Subprogram_Body;
3738 ---------------------------
3739 -- Get_Subprogram_Entity --
3740 ---------------------------
3742 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3747 if Nkind (Nod) = N_Accept_Statement then
3748 Nam := Entry_Direct_Name (Nod);
3750 -- For an entry call, the prefix of the call is a selected component.
3751 -- Need additional code for internal calls ???
3753 elsif Nkind (Nod) = N_Entry_Call_Statement then
3754 if Nkind (Name (Nod)) = N_Selected_Component then
3755 Nam := Entity (Selector_Name (Name (Nod)));
3764 if Nkind (Nam) = N_Explicit_Dereference then
3765 Proc := Etype (Prefix (Nam));
3766 elsif Is_Entity_Name (Nam) then
3767 Proc := Entity (Nam);
3772 if Is_Object (Proc) then
3773 Proc := Etype (Proc);
3776 if Ekind (Proc) = E_Access_Subprogram_Type then
3777 Proc := Directly_Designated_Type (Proc);
3780 if not Is_Subprogram (Proc)
3781 and then Ekind (Proc) /= E_Subprogram_Type
3787 end Get_Subprogram_Entity;
3789 -----------------------------
3790 -- Get_Task_Body_Procedure --
3791 -----------------------------
3793 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3795 -- Note: A task type may be the completion of a private type with
3796 -- discriminants. When performing elaboration checks on a task
3797 -- declaration, the current view of the type may be the private one,
3798 -- and the procedure that holds the body of the task is held in its
3801 -- This is an odd function, why not have Task_Body_Procedure do
3802 -- the following digging???
3804 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3805 end Get_Task_Body_Procedure;
3807 -----------------------
3808 -- Has_Access_Values --
3809 -----------------------
3811 function Has_Access_Values (T : Entity_Id) return Boolean is
3812 Typ : constant Entity_Id := Underlying_Type (T);
3815 -- Case of a private type which is not completed yet. This can only
3816 -- happen in the case of a generic format type appearing directly, or
3817 -- as a component of the type to which this function is being applied
3818 -- at the top level. Return False in this case, since we certainly do
3819 -- not know that the type contains access types.
3824 elsif Is_Access_Type (Typ) then
3827 elsif Is_Array_Type (Typ) then
3828 return Has_Access_Values (Component_Type (Typ));
3830 elsif Is_Record_Type (Typ) then
3835 -- Loop to Check components
3837 Comp := First_Component_Or_Discriminant (Typ);
3838 while Present (Comp) loop
3840 -- Check for access component, tag field does not count, even
3841 -- though it is implemented internally using an access type.
3843 if Has_Access_Values (Etype (Comp))
3844 and then Chars (Comp) /= Name_uTag
3849 Next_Component_Or_Discriminant (Comp);
3858 end Has_Access_Values;
3860 ------------------------------
3861 -- Has_Compatible_Alignment --
3862 ------------------------------
3864 function Has_Compatible_Alignment
3866 Expr : Node_Id) return Alignment_Result
3868 function Has_Compatible_Alignment_Internal
3871 Default : Alignment_Result) return Alignment_Result;
3872 -- This is the internal recursive function that actually does the work.
3873 -- There is one additional parameter, which says what the result should
3874 -- be if no alignment information is found, and there is no definite
3875 -- indication of compatible alignments. At the outer level, this is set
3876 -- to Unknown, but for internal recursive calls in the case where types
3877 -- are known to be correct, it is set to Known_Compatible.
3879 ---------------------------------------
3880 -- Has_Compatible_Alignment_Internal --
3881 ---------------------------------------
3883 function Has_Compatible_Alignment_Internal
3886 Default : Alignment_Result) return Alignment_Result
3888 Result : Alignment_Result := Known_Compatible;
3889 -- Holds the current status of the result. Note that once a value of
3890 -- Known_Incompatible is set, it is sticky and does not get changed
3891 -- to Unknown (the value in Result only gets worse as we go along,
3894 Offs : Uint := No_Uint;
3895 -- Set to a factor of the offset from the base object when Expr is a
3896 -- selected or indexed component, based on Component_Bit_Offset and
3897 -- Component_Size respectively. A negative value is used to represent
3898 -- a value which is not known at compile time.
3900 procedure Check_Prefix;
3901 -- Checks the prefix recursively in the case where the expression
3902 -- is an indexed or selected component.
3904 procedure Set_Result (R : Alignment_Result);
3905 -- If R represents a worse outcome (unknown instead of known
3906 -- compatible, or known incompatible), then set Result to R.
3912 procedure Check_Prefix is
3914 -- The subtlety here is that in doing a recursive call to check
3915 -- the prefix, we have to decide what to do in the case where we
3916 -- don't find any specific indication of an alignment problem.
3918 -- At the outer level, we normally set Unknown as the result in
3919 -- this case, since we can only set Known_Compatible if we really
3920 -- know that the alignment value is OK, but for the recursive
3921 -- call, in the case where the types match, and we have not
3922 -- specified a peculiar alignment for the object, we are only
3923 -- concerned about suspicious rep clauses, the default case does
3924 -- not affect us, since the compiler will, in the absence of such
3925 -- rep clauses, ensure that the alignment is correct.
3927 if Default = Known_Compatible
3929 (Etype (Obj) = Etype (Expr)
3930 and then (Unknown_Alignment (Obj)
3932 Alignment (Obj) = Alignment (Etype (Obj))))
3935 (Has_Compatible_Alignment_Internal
3936 (Obj, Prefix (Expr), Known_Compatible));
3938 -- In all other cases, we need a full check on the prefix
3942 (Has_Compatible_Alignment_Internal
3943 (Obj, Prefix (Expr), Unknown));
3951 procedure Set_Result (R : Alignment_Result) is
3958 -- Start of processing for Has_Compatible_Alignment_Internal
3961 -- If Expr is a selected component, we must make sure there is no
3962 -- potentially troublesome component clause, and that the record is
3965 if Nkind (Expr) = N_Selected_Component then
3967 -- Packed record always generate unknown alignment
3969 if Is_Packed (Etype (Prefix (Expr))) then
3970 Set_Result (Unknown);
3973 -- Check prefix and component offset
3976 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
3978 -- If Expr is an indexed component, we must make sure there is no
3979 -- potentially troublesome Component_Size clause and that the array
3980 -- is not bit-packed.
3982 elsif Nkind (Expr) = N_Indexed_Component then
3984 Typ : constant Entity_Id := Etype (Prefix (Expr));
3985 Ind : constant Node_Id := First_Index (Typ);
3988 -- Bit packed array always generates unknown alignment
3990 if Is_Bit_Packed_Array (Typ) then
3991 Set_Result (Unknown);
3994 -- Check prefix and component offset
3997 Offs := Component_Size (Typ);
3999 -- Small optimization: compute the full offset when possible
4002 and then Offs > Uint_0
4003 and then Present (Ind)
4004 and then Nkind (Ind) = N_Range
4005 and then Compile_Time_Known_Value (Low_Bound (Ind))
4006 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4008 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4009 - Expr_Value (Low_Bound ((Ind))));
4014 -- If we have a null offset, the result is entirely determined by
4015 -- the base object and has already been computed recursively.
4017 if Offs = Uint_0 then
4020 -- Case where we know the alignment of the object
4022 elsif Known_Alignment (Obj) then
4024 ObjA : constant Uint := Alignment (Obj);
4025 ExpA : Uint := No_Uint;
4026 SizA : Uint := No_Uint;
4029 -- If alignment of Obj is 1, then we are always OK
4032 Set_Result (Known_Compatible);
4034 -- Alignment of Obj is greater than 1, so we need to check
4037 -- If we have an offset, see if it is compatible
4039 if Offs /= No_Uint and Offs > Uint_0 then
4040 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4041 Set_Result (Known_Incompatible);
4044 -- See if Expr is an object with known alignment
4046 elsif Is_Entity_Name (Expr)
4047 and then Known_Alignment (Entity (Expr))
4049 ExpA := Alignment (Entity (Expr));
4051 -- Otherwise, we can use the alignment of the type of
4052 -- Expr given that we already checked for
4053 -- discombobulating rep clauses for the cases of indexed
4054 -- and selected components above.
4056 elsif Known_Alignment (Etype (Expr)) then
4057 ExpA := Alignment (Etype (Expr));
4059 -- Otherwise the alignment is unknown
4062 Set_Result (Default);
4065 -- If we got an alignment, see if it is acceptable
4067 if ExpA /= No_Uint and then ExpA < ObjA then
4068 Set_Result (Known_Incompatible);
4071 -- If Expr is not a piece of a larger object, see if size
4072 -- is given. If so, check that it is not too small for the
4073 -- required alignment.
4075 if Offs /= No_Uint then
4078 -- See if Expr is an object with known size
4080 elsif Is_Entity_Name (Expr)
4081 and then Known_Static_Esize (Entity (Expr))
4083 SizA := Esize (Entity (Expr));
4085 -- Otherwise, we check the object size of the Expr type
4087 elsif Known_Static_Esize (Etype (Expr)) then
4088 SizA := Esize (Etype (Expr));
4091 -- If we got a size, see if it is a multiple of the Obj
4092 -- alignment, if not, then the alignment cannot be
4093 -- acceptable, since the size is always a multiple of the
4096 if SizA /= No_Uint then
4097 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4098 Set_Result (Known_Incompatible);
4104 -- If we do not know required alignment, any non-zero offset is a
4105 -- potential problem (but certainly may be OK, so result is unknown).
4107 elsif Offs /= No_Uint then
4108 Set_Result (Unknown);
4110 -- If we can't find the result by direct comparison of alignment
4111 -- values, then there is still one case that we can determine known
4112 -- result, and that is when we can determine that the types are the
4113 -- same, and no alignments are specified. Then we known that the
4114 -- alignments are compatible, even if we don't know the alignment
4115 -- value in the front end.
4117 elsif Etype (Obj) = Etype (Expr) then
4119 -- Types are the same, but we have to check for possible size
4120 -- and alignments on the Expr object that may make the alignment
4121 -- different, even though the types are the same.
4123 if Is_Entity_Name (Expr) then
4125 -- First check alignment of the Expr object. Any alignment less
4126 -- than Maximum_Alignment is worrisome since this is the case
4127 -- where we do not know the alignment of Obj.
4129 if Known_Alignment (Entity (Expr))
4131 UI_To_Int (Alignment (Entity (Expr))) <
4132 Ttypes.Maximum_Alignment
4134 Set_Result (Unknown);
4136 -- Now check size of Expr object. Any size that is not an
4137 -- even multiple of Maximum_Alignment is also worrisome
4138 -- since it may cause the alignment of the object to be less
4139 -- than the alignment of the type.
4141 elsif Known_Static_Esize (Entity (Expr))
4143 (UI_To_Int (Esize (Entity (Expr))) mod
4144 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4147 Set_Result (Unknown);
4149 -- Otherwise same type is decisive
4152 Set_Result (Known_Compatible);
4156 -- Another case to deal with is when there is an explicit size or
4157 -- alignment clause when the types are not the same. If so, then the
4158 -- result is Unknown. We don't need to do this test if the Default is
4159 -- Unknown, since that result will be set in any case.
4161 elsif Default /= Unknown
4162 and then (Has_Size_Clause (Etype (Expr))
4164 Has_Alignment_Clause (Etype (Expr)))
4166 Set_Result (Unknown);
4168 -- If no indication found, set default
4171 Set_Result (Default);
4174 -- Return worst result found
4177 end Has_Compatible_Alignment_Internal;
4179 -- Start of processing for Has_Compatible_Alignment
4182 -- If Obj has no specified alignment, then set alignment from the type
4183 -- alignment. Perhaps we should always do this, but for sure we should
4184 -- do it when there is an address clause since we can do more if the
4185 -- alignment is known.
4187 if Unknown_Alignment (Obj) then
4188 Set_Alignment (Obj, Alignment (Etype (Obj)));
4191 -- Now do the internal call that does all the work
4193 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4194 end Has_Compatible_Alignment;
4196 ----------------------
4197 -- Has_Declarations --
4198 ----------------------
4200 function Has_Declarations (N : Node_Id) return Boolean is
4202 return Nkind_In (Nkind (N), N_Accept_Statement,
4204 N_Compilation_Unit_Aux,
4210 N_Package_Specification);
4211 end Has_Declarations;
4213 -------------------------------------------
4214 -- Has_Discriminant_Dependent_Constraint --
4215 -------------------------------------------
4217 function Has_Discriminant_Dependent_Constraint
4218 (Comp : Entity_Id) return Boolean
4220 Comp_Decl : constant Node_Id := Parent (Comp);
4221 Subt_Indic : constant Node_Id :=
4222 Subtype_Indication (Component_Definition (Comp_Decl));
4227 if Nkind (Subt_Indic) = N_Subtype_Indication then
4228 Constr := Constraint (Subt_Indic);
4230 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4231 Assn := First (Constraints (Constr));
4232 while Present (Assn) loop
4233 case Nkind (Assn) is
4234 when N_Subtype_Indication |
4238 if Depends_On_Discriminant (Assn) then
4242 when N_Discriminant_Association =>
4243 if Depends_On_Discriminant (Expression (Assn)) then
4258 end Has_Discriminant_Dependent_Constraint;
4260 --------------------
4261 -- Has_Infinities --
4262 --------------------
4264 function Has_Infinities (E : Entity_Id) return Boolean is
4267 Is_Floating_Point_Type (E)
4268 and then Nkind (Scalar_Range (E)) = N_Range
4269 and then Includes_Infinities (Scalar_Range (E));
4272 --------------------
4273 -- Has_Interfaces --
4274 --------------------
4276 function Has_Interfaces
4278 Use_Full_View : Boolean := True) return Boolean
4283 -- Handle concurrent types
4285 if Is_Concurrent_Type (T) then
4286 Typ := Corresponding_Record_Type (T);
4291 if not Present (Typ)
4292 or else not Is_Record_Type (Typ)
4293 or else not Is_Tagged_Type (Typ)
4298 -- Handle private types
4301 and then Present (Full_View (Typ))
4303 Typ := Full_View (Typ);
4306 -- Handle concurrent record types
4308 if Is_Concurrent_Record_Type (Typ)
4309 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4315 if Is_Interface (Typ)
4317 (Is_Record_Type (Typ)
4318 and then Present (Interfaces (Typ))
4319 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4324 exit when Etype (Typ) = Typ
4326 -- Handle private types
4328 or else (Present (Full_View (Etype (Typ)))
4329 and then Full_View (Etype (Typ)) = Typ)
4331 -- Protect the frontend against wrong source with cyclic
4334 or else Etype (Typ) = T;
4336 -- Climb to the ancestor type handling private types
4338 if Present (Full_View (Etype (Typ))) then
4339 Typ := Full_View (Etype (Typ));
4348 ------------------------
4349 -- Has_Null_Exclusion --
4350 ------------------------
4352 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4355 when N_Access_Definition |
4356 N_Access_Function_Definition |
4357 N_Access_Procedure_Definition |
4358 N_Access_To_Object_Definition |
4360 N_Derived_Type_Definition |
4361 N_Function_Specification |
4362 N_Subtype_Declaration =>
4363 return Null_Exclusion_Present (N);
4365 when N_Component_Definition |
4366 N_Formal_Object_Declaration |
4367 N_Object_Renaming_Declaration =>
4368 if Present (Subtype_Mark (N)) then
4369 return Null_Exclusion_Present (N);
4370 else pragma Assert (Present (Access_Definition (N)));
4371 return Null_Exclusion_Present (Access_Definition (N));
4374 when N_Discriminant_Specification =>
4375 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4376 return Null_Exclusion_Present (Discriminant_Type (N));
4378 return Null_Exclusion_Present (N);
4381 when N_Object_Declaration =>
4382 if Nkind (Object_Definition (N)) = N_Access_Definition then
4383 return Null_Exclusion_Present (Object_Definition (N));
4385 return Null_Exclusion_Present (N);
4388 when N_Parameter_Specification =>
4389 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4390 return Null_Exclusion_Present (Parameter_Type (N));
4392 return Null_Exclusion_Present (N);
4399 end Has_Null_Exclusion;
4401 ------------------------
4402 -- Has_Null_Extension --
4403 ------------------------
4405 function Has_Null_Extension (T : Entity_Id) return Boolean is
4406 B : constant Entity_Id := Base_Type (T);
4411 if Nkind (Parent (B)) = N_Full_Type_Declaration
4412 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4414 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4416 if Present (Ext) then
4417 if Null_Present (Ext) then
4420 Comps := Component_List (Ext);
4422 -- The null component list is rewritten during analysis to
4423 -- include the parent component. Any other component indicates
4424 -- that the extension was not originally null.
4426 return Null_Present (Comps)
4427 or else No (Next (First (Component_Items (Comps))));
4436 end Has_Null_Extension;
4438 -------------------------------
4439 -- Has_Overriding_Initialize --
4440 -------------------------------
4442 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4443 BT : constant Entity_Id := Base_Type (T);
4448 if Is_Controlled (BT) then
4450 -- For derived types, check immediate ancestor, excluding
4451 -- Controlled itself.
4453 if Is_Derived_Type (BT)
4454 and then not In_Predefined_Unit (Etype (BT))
4455 and then Has_Overriding_Initialize (Etype (BT))
4459 elsif Present (Primitive_Operations (BT)) then
4460 P := First_Elmt (Primitive_Operations (BT));
4461 while Present (P) loop
4462 if Chars (Node (P)) = Name_Initialize
4463 and then Comes_From_Source (Node (P))
4474 elsif Has_Controlled_Component (BT) then
4475 Comp := First_Component (BT);
4476 while Present (Comp) loop
4477 if Has_Overriding_Initialize (Etype (Comp)) then
4481 Next_Component (Comp);
4489 end Has_Overriding_Initialize;
4491 --------------------------------------
4492 -- Has_Preelaborable_Initialization --
4493 --------------------------------------
4495 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4498 procedure Check_Components (E : Entity_Id);
4499 -- Check component/discriminant chain, sets Has_PE False if a component
4500 -- or discriminant does not meet the preelaborable initialization rules.
4502 ----------------------
4503 -- Check_Components --
4504 ----------------------
4506 procedure Check_Components (E : Entity_Id) is
4510 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4511 -- Returns True if and only if the expression denoted by N does not
4512 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4514 ---------------------------------
4515 -- Is_Preelaborable_Expression --
4516 ---------------------------------
4518 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4522 Comp_Type : Entity_Id;
4523 Is_Array_Aggr : Boolean;
4526 if Is_Static_Expression (N) then
4529 elsif Nkind (N) = N_Null then
4532 -- Attributes are allowed in general, even if their prefix is a
4533 -- formal type. (It seems that certain attributes known not to be
4534 -- static might not be allowed, but there are no rules to prevent
4537 elsif Nkind (N) = N_Attribute_Reference then
4540 -- The name of a discriminant evaluated within its parent type is
4541 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4542 -- names that denote discriminals as well as discriminants to
4543 -- catch references occurring within init procs.
4545 elsif Is_Entity_Name (N)
4547 (Ekind (Entity (N)) = E_Discriminant
4549 ((Ekind (Entity (N)) = E_Constant
4550 or else Ekind (Entity (N)) = E_In_Parameter)
4551 and then Present (Discriminal_Link (Entity (N)))))
4555 elsif Nkind (N) = N_Qualified_Expression then
4556 return Is_Preelaborable_Expression (Expression (N));
4558 -- For aggregates we have to check that each of the associations
4559 -- is preelaborable.
4561 elsif Nkind (N) = N_Aggregate
4562 or else Nkind (N) = N_Extension_Aggregate
4564 Is_Array_Aggr := Is_Array_Type (Etype (N));
4566 if Is_Array_Aggr then
4567 Comp_Type := Component_Type (Etype (N));
4570 -- Check the ancestor part of extension aggregates, which must
4571 -- be either the name of a type that has preelaborable init or
4572 -- an expression that is preelaborable.
4574 if Nkind (N) = N_Extension_Aggregate then
4576 Anc_Part : constant Node_Id := Ancestor_Part (N);
4579 if Is_Entity_Name (Anc_Part)
4580 and then Is_Type (Entity (Anc_Part))
4582 if not Has_Preelaborable_Initialization
4588 elsif not Is_Preelaborable_Expression (Anc_Part) then
4594 -- Check positional associations
4596 Exp := First (Expressions (N));
4597 while Present (Exp) loop
4598 if not Is_Preelaborable_Expression (Exp) then
4605 -- Check named associations
4607 Assn := First (Component_Associations (N));
4608 while Present (Assn) loop
4609 Choice := First (Choices (Assn));
4610 while Present (Choice) loop
4611 if Is_Array_Aggr then
4612 if Nkind (Choice) = N_Others_Choice then
4615 elsif Nkind (Choice) = N_Range then
4616 if not Is_Static_Range (Choice) then
4620 elsif not Is_Static_Expression (Choice) then
4625 Comp_Type := Etype (Choice);
4631 -- If the association has a <> at this point, then we have
4632 -- to check whether the component's type has preelaborable
4633 -- initialization. Note that this only occurs when the
4634 -- association's corresponding component does not have a
4635 -- default expression, the latter case having already been
4636 -- expanded as an expression for the association.
4638 if Box_Present (Assn) then
4639 if not Has_Preelaborable_Initialization (Comp_Type) then
4643 -- In the expression case we check whether the expression
4644 -- is preelaborable.
4647 not Is_Preelaborable_Expression (Expression (Assn))
4655 -- If we get here then aggregate as a whole is preelaborable
4659 -- All other cases are not preelaborable
4664 end Is_Preelaborable_Expression;
4666 -- Start of processing for Check_Components
4669 -- Loop through entities of record or protected type
4672 while Present (Ent) loop
4674 -- We are interested only in components and discriminants
4676 if Ekind (Ent) = E_Component
4678 Ekind (Ent) = E_Discriminant
4680 -- Get default expression if any. If there is no declaration
4681 -- node, it means we have an internal entity. The parent and
4682 -- tag fields are examples of such entities. For these cases,
4683 -- we just test the type of the entity.
4685 if Present (Declaration_Node (Ent)) then
4686 Exp := Expression (Declaration_Node (Ent));
4691 -- A component has PI if it has no default expression and the
4692 -- component type has PI.
4695 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4700 -- Require the default expression to be preelaborable
4702 elsif not Is_Preelaborable_Expression (Exp) then
4710 end Check_Components;
4712 -- Start of processing for Has_Preelaborable_Initialization
4715 -- Immediate return if already marked as known preelaborable init. This
4716 -- covers types for which this function has already been called once
4717 -- and returned True (in which case the result is cached), and also
4718 -- types to which a pragma Preelaborable_Initialization applies.
4720 if Known_To_Have_Preelab_Init (E) then
4724 -- If the type is a subtype representing a generic actual type, then
4725 -- test whether its base type has preelaborable initialization since
4726 -- the subtype representing the actual does not inherit this attribute
4727 -- from the actual or formal. (but maybe it should???)
4729 if Is_Generic_Actual_Type (E) then
4730 return Has_Preelaborable_Initialization (Base_Type (E));
4733 -- All elementary types have preelaborable initialization
4735 if Is_Elementary_Type (E) then
4738 -- Array types have PI if the component type has PI
4740 elsif Is_Array_Type (E) then
4741 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4743 -- A derived type has preelaborable initialization if its parent type
4744 -- has preelaborable initialization and (in the case of a derived record
4745 -- extension) if the non-inherited components all have preelaborable
4746 -- initialization. However, a user-defined controlled type with an
4747 -- overriding Initialize procedure does not have preelaborable
4750 elsif Is_Derived_Type (E) then
4752 -- If the derived type is a private extension then it doesn't have
4753 -- preelaborable initialization.
4755 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4759 -- First check whether ancestor type has preelaborable initialization
4761 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4763 -- If OK, check extension components (if any)
4765 if Has_PE and then Is_Record_Type (E) then
4766 Check_Components (First_Entity (E));
4769 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4770 -- with a user defined Initialize procedure does not have PI.
4773 and then Is_Controlled (E)
4774 and then Has_Overriding_Initialize (E)
4779 -- Private types not derived from a type having preelaborable init and
4780 -- that are not marked with pragma Preelaborable_Initialization do not
4781 -- have preelaborable initialization.
4783 elsif Is_Private_Type (E) then
4786 -- Record type has PI if it is non private and all components have PI
4788 elsif Is_Record_Type (E) then
4790 Check_Components (First_Entity (E));
4792 -- Protected types must not have entries, and components must meet
4793 -- same set of rules as for record components.
4795 elsif Is_Protected_Type (E) then
4796 if Has_Entries (E) then
4800 Check_Components (First_Entity (E));
4801 Check_Components (First_Private_Entity (E));
4804 -- Type System.Address always has preelaborable initialization
4806 elsif Is_RTE (E, RE_Address) then
4809 -- In all other cases, type does not have preelaborable initialization
4815 -- If type has preelaborable initialization, cache result
4818 Set_Known_To_Have_Preelab_Init (E);
4822 end Has_Preelaborable_Initialization;
4824 ---------------------------
4825 -- Has_Private_Component --
4826 ---------------------------
4828 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4829 Btype : Entity_Id := Base_Type (Type_Id);
4830 Component : Entity_Id;
4833 if Error_Posted (Type_Id)
4834 or else Error_Posted (Btype)
4839 if Is_Class_Wide_Type (Btype) then
4840 Btype := Root_Type (Btype);
4843 if Is_Private_Type (Btype) then
4845 UT : constant Entity_Id := Underlying_Type (Btype);
4848 if No (Full_View (Btype)) then
4849 return not Is_Generic_Type (Btype)
4850 and then not Is_Generic_Type (Root_Type (Btype));
4852 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4855 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4859 elsif Is_Array_Type (Btype) then
4860 return Has_Private_Component (Component_Type (Btype));
4862 elsif Is_Record_Type (Btype) then
4863 Component := First_Component (Btype);
4864 while Present (Component) loop
4865 if Has_Private_Component (Etype (Component)) then
4869 Next_Component (Component);
4874 elsif Is_Protected_Type (Btype)
4875 and then Present (Corresponding_Record_Type (Btype))
4877 return Has_Private_Component (Corresponding_Record_Type (Btype));
4882 end Has_Private_Component;
4888 function Has_Stream (T : Entity_Id) return Boolean is
4895 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4898 elsif Is_Array_Type (T) then
4899 return Has_Stream (Component_Type (T));
4901 elsif Is_Record_Type (T) then
4902 E := First_Component (T);
4903 while Present (E) loop
4904 if Has_Stream (Etype (E)) then
4913 elsif Is_Private_Type (T) then
4914 return Has_Stream (Underlying_Type (T));
4921 --------------------------
4922 -- Has_Tagged_Component --
4923 --------------------------
4925 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4929 if Is_Private_Type (Typ)
4930 and then Present (Underlying_Type (Typ))
4932 return Has_Tagged_Component (Underlying_Type (Typ));
4934 elsif Is_Array_Type (Typ) then
4935 return Has_Tagged_Component (Component_Type (Typ));
4937 elsif Is_Tagged_Type (Typ) then
4940 elsif Is_Record_Type (Typ) then
4941 Comp := First_Component (Typ);
4942 while Present (Comp) loop
4943 if Has_Tagged_Component (Etype (Comp)) then
4947 Next_Component (Comp);
4955 end Has_Tagged_Component;
4957 --------------------------
4958 -- Implements_Interface --
4959 --------------------------
4961 function Implements_Interface
4962 (Typ_Ent : Entity_Id;
4963 Iface_Ent : Entity_Id;
4964 Exclude_Parents : Boolean := False) return Boolean
4966 Ifaces_List : Elist_Id;
4968 Iface : Entity_Id := Base_Type (Iface_Ent);
4969 Typ : Entity_Id := Base_Type (Typ_Ent);
4972 if Is_Class_Wide_Type (Typ) then
4973 Typ := Root_Type (Typ);
4976 if not Has_Interfaces (Typ) then
4980 if Is_Class_Wide_Type (Iface) then
4981 Iface := Root_Type (Iface);
4984 Collect_Interfaces (Typ, Ifaces_List);
4986 Elmt := First_Elmt (Ifaces_List);
4987 while Present (Elmt) loop
4988 if Is_Ancestor (Node (Elmt), Typ)
4989 and then Exclude_Parents
4993 elsif Node (Elmt) = Iface then
5001 end Implements_Interface;
5007 function In_Instance return Boolean is
5008 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5014 and then S /= Standard_Standard
5016 if (Ekind (S) = E_Function
5017 or else Ekind (S) = E_Package
5018 or else Ekind (S) = E_Procedure)
5019 and then Is_Generic_Instance (S)
5021 -- A child instance is always compiled in the context of a parent
5022 -- instance. Nevertheless, the actuals are not analyzed in an
5023 -- instance context. We detect this case by examining the current
5024 -- compilation unit, which must be a child instance, and checking
5025 -- that it is not currently on the scope stack.
5027 if Is_Child_Unit (Curr_Unit)
5029 Nkind (Unit (Cunit (Current_Sem_Unit)))
5030 = N_Package_Instantiation
5031 and then not In_Open_Scopes (Curr_Unit)
5045 ----------------------
5046 -- In_Instance_Body --
5047 ----------------------
5049 function In_Instance_Body return Boolean is
5055 and then S /= Standard_Standard
5057 if (Ekind (S) = E_Function
5058 or else Ekind (S) = E_Procedure)
5059 and then Is_Generic_Instance (S)
5063 elsif Ekind (S) = E_Package
5064 and then In_Package_Body (S)
5065 and then Is_Generic_Instance (S)
5074 end In_Instance_Body;
5076 -----------------------------
5077 -- In_Instance_Not_Visible --
5078 -----------------------------
5080 function In_Instance_Not_Visible return Boolean is
5086 and then S /= Standard_Standard
5088 if (Ekind (S) = E_Function
5089 or else Ekind (S) = E_Procedure)
5090 and then Is_Generic_Instance (S)
5094 elsif Ekind (S) = E_Package
5095 and then (In_Package_Body (S) or else In_Private_Part (S))
5096 and then Is_Generic_Instance (S)
5105 end In_Instance_Not_Visible;
5107 ------------------------------
5108 -- In_Instance_Visible_Part --
5109 ------------------------------
5111 function In_Instance_Visible_Part return Boolean is
5117 and then S /= Standard_Standard
5119 if Ekind (S) = E_Package
5120 and then Is_Generic_Instance (S)
5121 and then not In_Package_Body (S)
5122 and then not In_Private_Part (S)
5131 end In_Instance_Visible_Part;
5133 ---------------------
5134 -- In_Package_Body --
5135 ---------------------
5137 function In_Package_Body return Boolean is
5143 and then S /= Standard_Standard
5145 if Ekind (S) = E_Package
5146 and then In_Package_Body (S)
5155 end In_Package_Body;
5157 --------------------------------
5158 -- In_Parameter_Specification --
5159 --------------------------------
5161 function In_Parameter_Specification (N : Node_Id) return Boolean is
5166 while Present (PN) loop
5167 if Nkind (PN) = N_Parameter_Specification then
5175 end In_Parameter_Specification;
5177 --------------------------------------
5178 -- In_Subprogram_Or_Concurrent_Unit --
5179 --------------------------------------
5181 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5186 -- Use scope chain to check successively outer scopes
5192 if K in Subprogram_Kind
5193 or else K in Concurrent_Kind
5194 or else K in Generic_Subprogram_Kind
5198 elsif E = Standard_Standard then
5204 end In_Subprogram_Or_Concurrent_Unit;
5206 ---------------------
5207 -- In_Visible_Part --
5208 ---------------------
5210 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5213 Is_Package_Or_Generic_Package (Scope_Id)
5214 and then In_Open_Scopes (Scope_Id)
5215 and then not In_Package_Body (Scope_Id)
5216 and then not In_Private_Part (Scope_Id);
5217 end In_Visible_Part;
5219 ---------------------------------
5220 -- Insert_Explicit_Dereference --
5221 ---------------------------------
5223 procedure Insert_Explicit_Dereference (N : Node_Id) is
5224 New_Prefix : constant Node_Id := Relocate_Node (N);
5225 Ent : Entity_Id := Empty;
5232 Save_Interps (N, New_Prefix);
5234 -- Check if the node relocation requires readjustment of some SCIL
5235 -- dispatching node.
5238 and then Nkind (N) = N_Function_Call
5240 Adjust_SCIL_Node (N, New_Prefix);
5243 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5245 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5247 if Is_Overloaded (New_Prefix) then
5249 -- The dereference is also overloaded, and its interpretations are
5250 -- the designated types of the interpretations of the original node.
5252 Set_Etype (N, Any_Type);
5254 Get_First_Interp (New_Prefix, I, It);
5255 while Present (It.Nam) loop
5258 if Is_Access_Type (T) then
5259 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5262 Get_Next_Interp (I, It);
5268 -- Prefix is unambiguous: mark the original prefix (which might
5269 -- Come_From_Source) as a reference, since the new (relocated) one
5270 -- won't be taken into account.
5272 if Is_Entity_Name (New_Prefix) then
5273 Ent := Entity (New_Prefix);
5275 -- For a retrieval of a subcomponent of some composite object,
5276 -- retrieve the ultimate entity if there is one.
5278 elsif Nkind (New_Prefix) = N_Selected_Component
5279 or else Nkind (New_Prefix) = N_Indexed_Component
5281 Pref := Prefix (New_Prefix);
5282 while Present (Pref)
5284 (Nkind (Pref) = N_Selected_Component
5285 or else Nkind (Pref) = N_Indexed_Component)
5287 Pref := Prefix (Pref);
5290 if Present (Pref) and then Is_Entity_Name (Pref) then
5291 Ent := Entity (Pref);
5295 if Present (Ent) then
5296 Generate_Reference (Ent, New_Prefix);
5299 end Insert_Explicit_Dereference;
5301 ------------------------------------------
5302 -- Inspect_Deferred_Constant_Completion --
5303 ------------------------------------------
5305 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5309 Decl := First (Decls);
5310 while Present (Decl) loop
5312 -- Deferred constant signature
5314 if Nkind (Decl) = N_Object_Declaration
5315 and then Constant_Present (Decl)
5316 and then No (Expression (Decl))
5318 -- No need to check internally generated constants
5320 and then Comes_From_Source (Decl)
5322 -- The constant is not completed. A full object declaration
5323 -- or a pragma Import complete a deferred constant.
5325 and then not Has_Completion (Defining_Identifier (Decl))
5328 ("constant declaration requires initialization expression",
5329 Defining_Identifier (Decl));
5332 Decl := Next (Decl);
5334 end Inspect_Deferred_Constant_Completion;
5340 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5341 pragma Assert (Is_Type (E));
5343 return AAMP_On_Target
5344 and then Is_Floating_Point_Type (E)
5345 and then E = Base_Type (E);
5348 -----------------------------
5349 -- Is_Actual_Out_Parameter --
5350 -----------------------------
5352 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5356 Find_Actual (N, Formal, Call);
5357 return Present (Formal)
5358 and then Ekind (Formal) = E_Out_Parameter;
5359 end Is_Actual_Out_Parameter;
5361 -------------------------
5362 -- Is_Actual_Parameter --
5363 -------------------------
5365 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5366 PK : constant Node_Kind := Nkind (Parent (N));
5370 when N_Parameter_Association =>
5371 return N = Explicit_Actual_Parameter (Parent (N));
5373 when N_Function_Call | N_Procedure_Call_Statement =>
5374 return Is_List_Member (N)
5376 List_Containing (N) = Parameter_Associations (Parent (N));
5381 end Is_Actual_Parameter;
5383 ---------------------
5384 -- Is_Aliased_View --
5385 ---------------------
5387 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5391 if Is_Entity_Name (Obj) then
5399 or else (Present (Renamed_Object (E))
5400 and then Is_Aliased_View (Renamed_Object (E)))))
5402 or else ((Is_Formal (E)
5403 or else Ekind (E) = E_Generic_In_Out_Parameter
5404 or else Ekind (E) = E_Generic_In_Parameter)
5405 and then Is_Tagged_Type (Etype (E)))
5407 or else (Is_Concurrent_Type (E)
5408 and then In_Open_Scopes (E))
5410 -- Current instance of type, either directly or as rewritten
5411 -- reference to the current object.
5413 or else (Is_Entity_Name (Original_Node (Obj))
5414 and then Present (Entity (Original_Node (Obj)))
5415 and then Is_Type (Entity (Original_Node (Obj))))
5417 or else (Is_Type (E) and then E = Current_Scope)
5419 or else (Is_Incomplete_Or_Private_Type (E)
5420 and then Full_View (E) = Current_Scope);
5422 elsif Nkind (Obj) = N_Selected_Component then
5423 return Is_Aliased (Entity (Selector_Name (Obj)));
5425 elsif Nkind (Obj) = N_Indexed_Component then
5426 return Has_Aliased_Components (Etype (Prefix (Obj)))
5428 (Is_Access_Type (Etype (Prefix (Obj)))
5430 Has_Aliased_Components
5431 (Designated_Type (Etype (Prefix (Obj)))));
5433 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5434 or else Nkind (Obj) = N_Type_Conversion
5436 return Is_Tagged_Type (Etype (Obj))
5437 and then Is_Aliased_View (Expression (Obj));
5439 elsif Nkind (Obj) = N_Explicit_Dereference then
5440 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5445 end Is_Aliased_View;
5447 -------------------------
5448 -- Is_Ancestor_Package --
5449 -------------------------
5451 function Is_Ancestor_Package
5453 E2 : Entity_Id) return Boolean
5460 and then Par /= Standard_Standard
5470 end Is_Ancestor_Package;
5472 ----------------------
5473 -- Is_Atomic_Object --
5474 ----------------------
5476 function Is_Atomic_Object (N : Node_Id) return Boolean is
5478 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5479 -- Determines if given object has atomic components
5481 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5482 -- If prefix is an implicit dereference, examine designated type
5484 ----------------------
5485 -- Is_Atomic_Prefix --
5486 ----------------------
5488 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5490 if Is_Access_Type (Etype (N)) then
5492 Has_Atomic_Components (Designated_Type (Etype (N)));
5494 return Object_Has_Atomic_Components (N);
5496 end Is_Atomic_Prefix;
5498 ----------------------------------
5499 -- Object_Has_Atomic_Components --
5500 ----------------------------------
5502 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5504 if Has_Atomic_Components (Etype (N))
5505 or else Is_Atomic (Etype (N))
5509 elsif Is_Entity_Name (N)
5510 and then (Has_Atomic_Components (Entity (N))
5511 or else Is_Atomic (Entity (N)))
5515 elsif Nkind (N) = N_Indexed_Component
5516 or else Nkind (N) = N_Selected_Component
5518 return Is_Atomic_Prefix (Prefix (N));
5523 end Object_Has_Atomic_Components;
5525 -- Start of processing for Is_Atomic_Object
5528 if Is_Atomic (Etype (N))
5529 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5533 elsif Nkind (N) = N_Indexed_Component
5534 or else Nkind (N) = N_Selected_Component
5536 return Is_Atomic_Prefix (Prefix (N));
5541 end Is_Atomic_Object;
5543 -------------------------
5544 -- Is_Coextension_Root --
5545 -------------------------
5547 function Is_Coextension_Root (N : Node_Id) return Boolean is
5550 Nkind (N) = N_Allocator
5551 and then Present (Coextensions (N))
5553 -- Anonymous access discriminants carry a list of all nested
5554 -- controlled coextensions.
5556 and then not Is_Dynamic_Coextension (N)
5557 and then not Is_Static_Coextension (N);
5558 end Is_Coextension_Root;
5560 -----------------------------
5561 -- Is_Concurrent_Interface --
5562 -----------------------------
5564 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5569 (Is_Protected_Interface (T)
5570 or else Is_Synchronized_Interface (T)
5571 or else Is_Task_Interface (T));
5572 end Is_Concurrent_Interface;
5574 --------------------------------------
5575 -- Is_Controlling_Limited_Procedure --
5576 --------------------------------------
5578 function Is_Controlling_Limited_Procedure
5579 (Proc_Nam : Entity_Id) return Boolean
5581 Param_Typ : Entity_Id := Empty;
5584 if Ekind (Proc_Nam) = E_Procedure
5585 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5587 Param_Typ := Etype (Parameter_Type (First (
5588 Parameter_Specifications (Parent (Proc_Nam)))));
5590 -- In this case where an Itype was created, the procedure call has been
5593 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5594 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5596 Present (Parameter_Associations
5597 (Associated_Node_For_Itype (Proc_Nam)))
5600 Etype (First (Parameter_Associations
5601 (Associated_Node_For_Itype (Proc_Nam))));
5604 if Present (Param_Typ) then
5606 Is_Interface (Param_Typ)
5607 and then Is_Limited_Record (Param_Typ);
5611 end Is_Controlling_Limited_Procedure;
5613 -----------------------------
5614 -- Is_CPP_Constructor_Call --
5615 -----------------------------
5617 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5619 return Nkind (N) = N_Function_Call
5620 and then Is_CPP_Class (Etype (Etype (N)))
5621 and then Is_Constructor (Entity (Name (N)))
5622 and then Is_Imported (Entity (Name (N)));
5623 end Is_CPP_Constructor_Call;
5625 ----------------------------------------------
5626 -- Is_Dependent_Component_Of_Mutable_Object --
5627 ----------------------------------------------
5629 function Is_Dependent_Component_Of_Mutable_Object
5630 (Object : Node_Id) return Boolean
5633 Prefix_Type : Entity_Id;
5634 P_Aliased : Boolean := False;
5637 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5638 -- Returns True if and only if Comp is declared within a variant part
5640 --------------------------------
5641 -- Is_Declared_Within_Variant --
5642 --------------------------------
5644 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5645 Comp_Decl : constant Node_Id := Parent (Comp);
5646 Comp_List : constant Node_Id := Parent (Comp_Decl);
5648 return Nkind (Parent (Comp_List)) = N_Variant;
5649 end Is_Declared_Within_Variant;
5651 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5654 if Is_Variable (Object) then
5656 if Nkind (Object) = N_Selected_Component then
5657 P := Prefix (Object);
5658 Prefix_Type := Etype (P);
5660 if Is_Entity_Name (P) then
5662 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5663 Prefix_Type := Base_Type (Prefix_Type);
5666 if Is_Aliased (Entity (P)) then
5670 -- A discriminant check on a selected component may be
5671 -- expanded into a dereference when removing side-effects.
5672 -- Recover the original node and its type, which may be
5675 elsif Nkind (P) = N_Explicit_Dereference
5676 and then not (Comes_From_Source (P))
5678 P := Original_Node (P);
5679 Prefix_Type := Etype (P);
5682 -- Check for prefix being an aliased component ???
5687 -- A heap object is constrained by its initial value
5689 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5690 -- the dereferenced case, since the access value might denote an
5691 -- unconstrained aliased object, whereas in Ada 95 the designated
5692 -- object is guaranteed to be constrained. A worst-case assumption
5693 -- has to apply in Ada 2005 because we can't tell at compile time
5694 -- whether the object is "constrained by its initial value"
5695 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5696 -- semantic rules -- these rules are acknowledged to need fixing).
5698 if Ada_Version < Ada_05 then
5699 if Is_Access_Type (Prefix_Type)
5700 or else Nkind (P) = N_Explicit_Dereference
5705 elsif Ada_Version >= Ada_05 then
5706 if Is_Access_Type (Prefix_Type) then
5708 -- If the access type is pool-specific, and there is no
5709 -- constrained partial view of the designated type, then the
5710 -- designated object is known to be constrained.
5712 if Ekind (Prefix_Type) = E_Access_Type
5713 and then not Has_Constrained_Partial_View
5714 (Designated_Type (Prefix_Type))
5718 -- Otherwise (general access type, or there is a constrained
5719 -- partial view of the designated type), we need to check
5720 -- based on the designated type.
5723 Prefix_Type := Designated_Type (Prefix_Type);
5729 Original_Record_Component (Entity (Selector_Name (Object)));
5731 -- As per AI-0017, the renaming is illegal in a generic body,
5732 -- even if the subtype is indefinite.
5734 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5736 if not Is_Constrained (Prefix_Type)
5737 and then (not Is_Indefinite_Subtype (Prefix_Type)
5739 (Is_Generic_Type (Prefix_Type)
5740 and then Ekind (Current_Scope) = E_Generic_Package
5741 and then In_Package_Body (Current_Scope)))
5743 and then (Is_Declared_Within_Variant (Comp)
5744 or else Has_Discriminant_Dependent_Constraint (Comp))
5745 and then (not P_Aliased or else Ada_Version >= Ada_05)
5751 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5755 elsif Nkind (Object) = N_Indexed_Component
5756 or else Nkind (Object) = N_Slice
5758 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5760 -- A type conversion that Is_Variable is a view conversion:
5761 -- go back to the denoted object.
5763 elsif Nkind (Object) = N_Type_Conversion then
5765 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5770 end Is_Dependent_Component_Of_Mutable_Object;
5772 ---------------------
5773 -- Is_Dereferenced --
5774 ---------------------
5776 function Is_Dereferenced (N : Node_Id) return Boolean is
5777 P : constant Node_Id := Parent (N);
5780 (Nkind (P) = N_Selected_Component
5782 Nkind (P) = N_Explicit_Dereference
5784 Nkind (P) = N_Indexed_Component
5786 Nkind (P) = N_Slice)
5787 and then Prefix (P) = N;
5788 end Is_Dereferenced;
5790 ----------------------
5791 -- Is_Descendent_Of --
5792 ----------------------
5794 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5799 pragma Assert (Nkind (T1) in N_Entity);
5800 pragma Assert (Nkind (T2) in N_Entity);
5802 T := Base_Type (T1);
5804 -- Immediate return if the types match
5809 -- Comment needed here ???
5811 elsif Ekind (T) = E_Class_Wide_Type then
5812 return Etype (T) = T2;
5820 -- Done if we found the type we are looking for
5825 -- Done if no more derivations to check
5832 -- Following test catches error cases resulting from prev errors
5834 elsif No (Etyp) then
5837 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5840 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5844 T := Base_Type (Etyp);
5847 end Is_Descendent_Of;
5853 function Is_False (U : Uint) return Boolean is
5858 ---------------------------
5859 -- Is_Fixed_Model_Number --
5860 ---------------------------
5862 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5863 S : constant Ureal := Small_Value (T);
5864 M : Urealp.Save_Mark;
5868 R := (U = UR_Trunc (U / S) * S);
5871 end Is_Fixed_Model_Number;
5873 -------------------------------
5874 -- Is_Fully_Initialized_Type --
5875 -------------------------------
5877 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5879 if Is_Scalar_Type (Typ) then
5882 elsif Is_Access_Type (Typ) then
5885 elsif Is_Array_Type (Typ) then
5886 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5890 -- An interesting case, if we have a constrained type one of whose
5891 -- bounds is known to be null, then there are no elements to be
5892 -- initialized, so all the elements are initialized!
5894 if Is_Constrained (Typ) then
5897 Indx_Typ : Entity_Id;
5901 Indx := First_Index (Typ);
5902 while Present (Indx) loop
5903 if Etype (Indx) = Any_Type then
5906 -- If index is a range, use directly
5908 elsif Nkind (Indx) = N_Range then
5909 Lbd := Low_Bound (Indx);
5910 Hbd := High_Bound (Indx);
5913 Indx_Typ := Etype (Indx);
5915 if Is_Private_Type (Indx_Typ) then
5916 Indx_Typ := Full_View (Indx_Typ);
5919 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5922 Lbd := Type_Low_Bound (Indx_Typ);
5923 Hbd := Type_High_Bound (Indx_Typ);
5927 if Compile_Time_Known_Value (Lbd)
5928 and then Compile_Time_Known_Value (Hbd)
5930 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5940 -- If no null indexes, then type is not fully initialized
5946 elsif Is_Record_Type (Typ) then
5947 if Has_Discriminants (Typ)
5949 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5950 and then Is_Fully_Initialized_Variant (Typ)
5955 -- Controlled records are considered to be fully initialized if
5956 -- there is a user defined Initialize routine. This may not be
5957 -- entirely correct, but as the spec notes, we are guessing here
5958 -- what is best from the point of view of issuing warnings.
5960 if Is_Controlled (Typ) then
5962 Utyp : constant Entity_Id := Underlying_Type (Typ);
5965 if Present (Utyp) then
5967 Init : constant Entity_Id :=
5969 (Underlying_Type (Typ), Name_Initialize));
5973 and then Comes_From_Source (Init)
5975 Is_Predefined_File_Name
5976 (File_Name (Get_Source_File_Index (Sloc (Init))))
5980 elsif Has_Null_Extension (Typ)
5982 Is_Fully_Initialized_Type
5983 (Etype (Base_Type (Typ)))
5992 -- Otherwise see if all record components are initialized
5998 Ent := First_Entity (Typ);
5999 while Present (Ent) loop
6000 if Chars (Ent) = Name_uController then
6003 elsif Ekind (Ent) = E_Component
6004 and then (No (Parent (Ent))
6005 or else No (Expression (Parent (Ent))))
6006 and then not Is_Fully_Initialized_Type (Etype (Ent))
6008 -- Special VM case for tag components, which need to be
6009 -- defined in this case, but are never initialized as VMs
6010 -- are using other dispatching mechanisms. Ignore this
6011 -- uninitialized case. Note that this applies both to the
6012 -- uTag entry and the main vtable pointer (CPP_Class case).
6014 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6023 -- No uninitialized components, so type is fully initialized.
6024 -- Note that this catches the case of no components as well.
6028 elsif Is_Concurrent_Type (Typ) then
6031 elsif Is_Private_Type (Typ) then
6033 U : constant Entity_Id := Underlying_Type (Typ);
6039 return Is_Fully_Initialized_Type (U);
6046 end Is_Fully_Initialized_Type;
6048 ----------------------------------
6049 -- Is_Fully_Initialized_Variant --
6050 ----------------------------------
6052 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6053 Loc : constant Source_Ptr := Sloc (Typ);
6054 Constraints : constant List_Id := New_List;
6055 Components : constant Elist_Id := New_Elmt_List;
6056 Comp_Elmt : Elmt_Id;
6058 Comp_List : Node_Id;
6060 Discr_Val : Node_Id;
6062 Report_Errors : Boolean;
6063 pragma Warnings (Off, Report_Errors);
6066 if Serious_Errors_Detected > 0 then
6070 if Is_Record_Type (Typ)
6071 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6072 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6074 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6076 Discr := First_Discriminant (Typ);
6077 while Present (Discr) loop
6078 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6079 Discr_Val := Expression (Parent (Discr));
6081 if Present (Discr_Val)
6082 and then Is_OK_Static_Expression (Discr_Val)
6084 Append_To (Constraints,
6085 Make_Component_Association (Loc,
6086 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6087 Expression => New_Copy (Discr_Val)));
6095 Next_Discriminant (Discr);
6100 Comp_List => Comp_List,
6101 Governed_By => Constraints,
6103 Report_Errors => Report_Errors);
6105 -- Check that each component present is fully initialized
6107 Comp_Elmt := First_Elmt (Components);
6108 while Present (Comp_Elmt) loop
6109 Comp_Id := Node (Comp_Elmt);
6111 if Ekind (Comp_Id) = E_Component
6112 and then (No (Parent (Comp_Id))
6113 or else No (Expression (Parent (Comp_Id))))
6114 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6119 Next_Elmt (Comp_Elmt);
6124 elsif Is_Private_Type (Typ) then
6126 U : constant Entity_Id := Underlying_Type (Typ);
6132 return Is_Fully_Initialized_Variant (U);
6138 end Is_Fully_Initialized_Variant;
6144 -- We seem to have a lot of overlapping functions that do similar things
6145 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6146 -- purely syntactic, it should be in Sem_Aux I would think???
6148 function Is_LHS (N : Node_Id) return Boolean is
6149 P : constant Node_Id := Parent (N);
6151 return Nkind (P) = N_Assignment_Statement
6152 and then Name (P) = N;
6155 ----------------------------
6156 -- Is_Inherited_Operation --
6157 ----------------------------
6159 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6160 Kind : constant Node_Kind := Nkind (Parent (E));
6162 pragma Assert (Is_Overloadable (E));
6163 return Kind = N_Full_Type_Declaration
6164 or else Kind = N_Private_Extension_Declaration
6165 or else Kind = N_Subtype_Declaration
6166 or else (Ekind (E) = E_Enumeration_Literal
6167 and then Is_Derived_Type (Etype (E)));
6168 end Is_Inherited_Operation;
6170 -----------------------------
6171 -- Is_Library_Level_Entity --
6172 -----------------------------
6174 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6176 -- The following is a small optimization, and it also properly handles
6177 -- discriminals, which in task bodies might appear in expressions before
6178 -- the corresponding procedure has been created, and which therefore do
6179 -- not have an assigned scope.
6181 if Ekind (E) in Formal_Kind then
6185 -- Normal test is simply that the enclosing dynamic scope is Standard
6187 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6188 end Is_Library_Level_Entity;
6190 ---------------------------------
6191 -- Is_Local_Variable_Reference --
6192 ---------------------------------
6194 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6196 if not Is_Entity_Name (Expr) then
6201 Ent : constant Entity_Id := Entity (Expr);
6202 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6204 if Ekind (Ent) /= E_Variable
6206 Ekind (Ent) /= E_In_Out_Parameter
6210 return Present (Sub) and then Sub = Current_Subprogram;
6214 end Is_Local_Variable_Reference;
6216 -------------------------
6217 -- Is_Object_Reference --
6218 -------------------------
6220 function Is_Object_Reference (N : Node_Id) return Boolean is
6222 if Is_Entity_Name (N) then
6223 return Present (Entity (N)) and then Is_Object (Entity (N));
6227 when N_Indexed_Component | N_Slice =>
6229 Is_Object_Reference (Prefix (N))
6230 or else Is_Access_Type (Etype (Prefix (N)));
6232 -- In Ada95, a function call is a constant object; a procedure
6235 when N_Function_Call =>
6236 return Etype (N) /= Standard_Void_Type;
6238 -- A reference to the stream attribute Input is a function call
6240 when N_Attribute_Reference =>
6241 return Attribute_Name (N) = Name_Input;
6243 when N_Selected_Component =>
6245 Is_Object_Reference (Selector_Name (N))
6247 (Is_Object_Reference (Prefix (N))
6248 or else Is_Access_Type (Etype (Prefix (N))));
6250 when N_Explicit_Dereference =>
6253 -- A view conversion of a tagged object is an object reference
6255 when N_Type_Conversion =>
6256 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6257 and then Is_Tagged_Type (Etype (Expression (N)))
6258 and then Is_Object_Reference (Expression (N));
6260 -- An unchecked type conversion is considered to be an object if
6261 -- the operand is an object (this construction arises only as a
6262 -- result of expansion activities).
6264 when N_Unchecked_Type_Conversion =>
6271 end Is_Object_Reference;
6273 -----------------------------------
6274 -- Is_OK_Variable_For_Out_Formal --
6275 -----------------------------------
6277 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6279 Note_Possible_Modification (AV, Sure => True);
6281 -- We must reject parenthesized variable names. The check for
6282 -- Comes_From_Source is present because there are currently
6283 -- cases where the compiler violates this rule (e.g. passing
6284 -- a task object to its controlled Initialize routine).
6286 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6289 -- A variable is always allowed
6291 elsif Is_Variable (AV) then
6294 -- Unchecked conversions are allowed only if they come from the
6295 -- generated code, which sometimes uses unchecked conversions for out
6296 -- parameters in cases where code generation is unaffected. We tell
6297 -- source unchecked conversions by seeing if they are rewrites of an
6298 -- original Unchecked_Conversion function call, or of an explicit
6299 -- conversion of a function call.
6301 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6302 if Nkind (Original_Node (AV)) = N_Function_Call then
6305 elsif Comes_From_Source (AV)
6306 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6310 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6311 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6317 -- Normal type conversions are allowed if argument is a variable
6319 elsif Nkind (AV) = N_Type_Conversion then
6320 if Is_Variable (Expression (AV))
6321 and then Paren_Count (Expression (AV)) = 0
6323 Note_Possible_Modification (Expression (AV), Sure => True);
6326 -- We also allow a non-parenthesized expression that raises
6327 -- constraint error if it rewrites what used to be a variable
6329 elsif Raises_Constraint_Error (Expression (AV))
6330 and then Paren_Count (Expression (AV)) = 0
6331 and then Is_Variable (Original_Node (Expression (AV)))
6335 -- Type conversion of something other than a variable
6341 -- If this node is rewritten, then test the original form, if that is
6342 -- OK, then we consider the rewritten node OK (for example, if the
6343 -- original node is a conversion, then Is_Variable will not be true
6344 -- but we still want to allow the conversion if it converts a variable).
6346 elsif Original_Node (AV) /= AV then
6347 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6349 -- All other non-variables are rejected
6354 end Is_OK_Variable_For_Out_Formal;
6356 -----------------------------------
6357 -- Is_Partially_Initialized_Type --
6358 -----------------------------------
6360 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6362 if Is_Scalar_Type (Typ) then
6365 elsif Is_Access_Type (Typ) then
6368 elsif Is_Array_Type (Typ) then
6370 -- If component type is partially initialized, so is array type
6372 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6375 -- Otherwise we are only partially initialized if we are fully
6376 -- initialized (this is the empty array case, no point in us
6377 -- duplicating that code here).
6380 return Is_Fully_Initialized_Type (Typ);
6383 elsif Is_Record_Type (Typ) then
6385 -- A discriminated type is always partially initialized
6387 if Has_Discriminants (Typ) then
6390 -- A tagged type is always partially initialized
6392 elsif Is_Tagged_Type (Typ) then
6395 -- Case of non-discriminated record
6401 Component_Present : Boolean := False;
6402 -- Set True if at least one component is present. If no
6403 -- components are present, then record type is fully
6404 -- initialized (another odd case, like the null array).
6407 -- Loop through components
6409 Ent := First_Entity (Typ);
6410 while Present (Ent) loop
6411 if Ekind (Ent) = E_Component then
6412 Component_Present := True;
6414 -- If a component has an initialization expression then
6415 -- the enclosing record type is partially initialized
6417 if Present (Parent (Ent))
6418 and then Present (Expression (Parent (Ent)))
6422 -- If a component is of a type which is itself partially
6423 -- initialized, then the enclosing record type is also.
6425 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6433 -- No initialized components found. If we found any components
6434 -- they were all uninitialized so the result is false.
6436 if Component_Present then
6439 -- But if we found no components, then all the components are
6440 -- initialized so we consider the type to be initialized.
6448 -- Concurrent types are always fully initialized
6450 elsif Is_Concurrent_Type (Typ) then
6453 -- For a private type, go to underlying type. If there is no underlying
6454 -- type then just assume this partially initialized. Not clear if this
6455 -- can happen in a non-error case, but no harm in testing for this.
6457 elsif Is_Private_Type (Typ) then
6459 U : constant Entity_Id := Underlying_Type (Typ);
6464 return Is_Partially_Initialized_Type (U);
6468 -- For any other type (are there any?) assume partially initialized
6473 end Is_Partially_Initialized_Type;
6475 ------------------------------------
6476 -- Is_Potentially_Persistent_Type --
6477 ------------------------------------
6479 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6484 -- For private type, test corresponding full type
6486 if Is_Private_Type (T) then
6487 return Is_Potentially_Persistent_Type (Full_View (T));
6489 -- Scalar types are potentially persistent
6491 elsif Is_Scalar_Type (T) then
6494 -- Record type is potentially persistent if not tagged and the types of
6495 -- all it components are potentially persistent, and no component has
6496 -- an initialization expression.
6498 elsif Is_Record_Type (T)
6499 and then not Is_Tagged_Type (T)
6500 and then not Is_Partially_Initialized_Type (T)
6502 Comp := First_Component (T);
6503 while Present (Comp) loop
6504 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6513 -- Array type is potentially persistent if its component type is
6514 -- potentially persistent and if all its constraints are static.
6516 elsif Is_Array_Type (T) then
6517 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6521 Indx := First_Index (T);
6522 while Present (Indx) loop
6523 if not Is_OK_Static_Subtype (Etype (Indx)) then
6532 -- All other types are not potentially persistent
6537 end Is_Potentially_Persistent_Type;
6539 ---------------------------------
6540 -- Is_Protected_Self_Reference --
6541 ---------------------------------
6543 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6545 function In_Access_Definition (N : Node_Id) return Boolean;
6546 -- Returns true if N belongs to an access definition
6548 --------------------------
6549 -- In_Access_Definition --
6550 --------------------------
6552 function In_Access_Definition (N : Node_Id) return Boolean is
6557 while Present (P) loop
6558 if Nkind (P) = N_Access_Definition then
6566 end In_Access_Definition;
6568 -- Start of processing for Is_Protected_Self_Reference
6571 -- Verify that prefix is analyzed and has the proper form. Note that
6572 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6573 -- produce the address of an entity, do not analyze their prefix
6574 -- because they denote entities that are not necessarily visible.
6575 -- Neither of them can apply to a protected type.
6577 return Ada_Version >= Ada_05
6578 and then Is_Entity_Name (N)
6579 and then Present (Entity (N))
6580 and then Is_Protected_Type (Entity (N))
6581 and then In_Open_Scopes (Entity (N))
6582 and then not In_Access_Definition (N);
6583 end Is_Protected_Self_Reference;
6585 -----------------------------
6586 -- Is_RCI_Pkg_Spec_Or_Body --
6587 -----------------------------
6589 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6591 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6592 -- Return True if the unit of Cunit is an RCI package declaration
6594 ---------------------------
6595 -- Is_RCI_Pkg_Decl_Cunit --
6596 ---------------------------
6598 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6599 The_Unit : constant Node_Id := Unit (Cunit);
6602 if Nkind (The_Unit) /= N_Package_Declaration then
6606 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6607 end Is_RCI_Pkg_Decl_Cunit;
6609 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6612 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6614 (Nkind (Unit (Cunit)) = N_Package_Body
6615 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6616 end Is_RCI_Pkg_Spec_Or_Body;
6618 -----------------------------------------
6619 -- Is_Remote_Access_To_Class_Wide_Type --
6620 -----------------------------------------
6622 function Is_Remote_Access_To_Class_Wide_Type
6623 (E : Entity_Id) return Boolean
6626 -- A remote access to class-wide type is a general access to object type
6627 -- declared in the visible part of a Remote_Types or Remote_Call_
6630 return Ekind (E) = E_General_Access_Type
6631 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6632 end Is_Remote_Access_To_Class_Wide_Type;
6634 -----------------------------------------
6635 -- Is_Remote_Access_To_Subprogram_Type --
6636 -----------------------------------------
6638 function Is_Remote_Access_To_Subprogram_Type
6639 (E : Entity_Id) return Boolean
6642 return (Ekind (E) = E_Access_Subprogram_Type
6643 or else (Ekind (E) = E_Record_Type
6644 and then Present (Corresponding_Remote_Type (E))))
6645 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6646 end Is_Remote_Access_To_Subprogram_Type;
6648 --------------------
6649 -- Is_Remote_Call --
6650 --------------------
6652 function Is_Remote_Call (N : Node_Id) return Boolean is
6654 if Nkind (N) /= N_Procedure_Call_Statement
6655 and then Nkind (N) /= N_Function_Call
6657 -- An entry call cannot be remote
6661 elsif Nkind (Name (N)) in N_Has_Entity
6662 and then Is_Remote_Call_Interface (Entity (Name (N)))
6664 -- A subprogram declared in the spec of a RCI package is remote
6668 elsif Nkind (Name (N)) = N_Explicit_Dereference
6669 and then Is_Remote_Access_To_Subprogram_Type
6670 (Etype (Prefix (Name (N))))
6672 -- The dereference of a RAS is a remote call
6676 elsif Present (Controlling_Argument (N))
6677 and then Is_Remote_Access_To_Class_Wide_Type
6678 (Etype (Controlling_Argument (N)))
6680 -- Any primitive operation call with a controlling argument of
6681 -- a RACW type is a remote call.
6686 -- All other calls are local calls
6691 ----------------------
6692 -- Is_Renamed_Entry --
6693 ----------------------
6695 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6696 Orig_Node : Node_Id := Empty;
6697 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6699 function Is_Entry (Nam : Node_Id) return Boolean;
6700 -- Determine whether Nam is an entry. Traverse selectors if there are
6701 -- nested selected components.
6707 function Is_Entry (Nam : Node_Id) return Boolean is
6709 if Nkind (Nam) = N_Selected_Component then
6710 return Is_Entry (Selector_Name (Nam));
6713 return Ekind (Entity (Nam)) = E_Entry;
6716 -- Start of processing for Is_Renamed_Entry
6719 if Present (Alias (Proc_Nam)) then
6720 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6723 -- Look for a rewritten subprogram renaming declaration
6725 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6726 and then Present (Original_Node (Subp_Decl))
6728 Orig_Node := Original_Node (Subp_Decl);
6731 -- The rewritten subprogram is actually an entry
6733 if Present (Orig_Node)
6734 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6735 and then Is_Entry (Name (Orig_Node))
6741 end Is_Renamed_Entry;
6743 ----------------------
6744 -- Is_Selector_Name --
6745 ----------------------
6747 function Is_Selector_Name (N : Node_Id) return Boolean is
6749 if not Is_List_Member (N) then
6751 P : constant Node_Id := Parent (N);
6752 K : constant Node_Kind := Nkind (P);
6755 (K = N_Expanded_Name or else
6756 K = N_Generic_Association or else
6757 K = N_Parameter_Association or else
6758 K = N_Selected_Component)
6759 and then Selector_Name (P) = N;
6764 L : constant List_Id := List_Containing (N);
6765 P : constant Node_Id := Parent (L);
6767 return (Nkind (P) = N_Discriminant_Association
6768 and then Selector_Names (P) = L)
6770 (Nkind (P) = N_Component_Association
6771 and then Choices (P) = L);
6774 end Is_Selector_Name;
6780 function Is_Statement (N : Node_Id) return Boolean is
6783 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6784 or else Nkind (N) = N_Procedure_Call_Statement;
6787 ---------------------------------
6788 -- Is_Synchronized_Tagged_Type --
6789 ---------------------------------
6791 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6792 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6795 -- A task or protected type derived from an interface is a tagged type.
6796 -- Such a tagged type is called a synchronized tagged type, as are
6797 -- synchronized interfaces and private extensions whose declaration
6798 -- includes the reserved word synchronized.
6800 return (Is_Tagged_Type (E)
6801 and then (Kind = E_Task_Type
6802 or else Kind = E_Protected_Type))
6805 and then Is_Synchronized_Interface (E))
6807 (Ekind (E) = E_Record_Type_With_Private
6808 and then (Synchronized_Present (Parent (E))
6809 or else Is_Synchronized_Interface (Etype (E))));
6810 end Is_Synchronized_Tagged_Type;
6816 function Is_Transfer (N : Node_Id) return Boolean is
6817 Kind : constant Node_Kind := Nkind (N);
6820 if Kind = N_Simple_Return_Statement
6822 Kind = N_Extended_Return_Statement
6824 Kind = N_Goto_Statement
6826 Kind = N_Raise_Statement
6828 Kind = N_Requeue_Statement
6832 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6833 and then No (Condition (N))
6837 elsif Kind = N_Procedure_Call_Statement
6838 and then Is_Entity_Name (Name (N))
6839 and then Present (Entity (Name (N)))
6840 and then No_Return (Entity (Name (N)))
6844 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6856 function Is_True (U : Uint) return Boolean is
6865 function Is_Value_Type (T : Entity_Id) return Boolean is
6867 return VM_Target = CLI_Target
6868 and then Chars (T) /= No_Name
6869 and then Get_Name_String (Chars (T)) = "valuetype";
6876 function Is_Variable (N : Node_Id) return Boolean is
6878 Orig_Node : constant Node_Id := Original_Node (N);
6879 -- We do the test on the original node, since this is basically a
6880 -- test of syntactic categories, so it must not be disturbed by
6881 -- whatever rewriting might have occurred. For example, an aggregate,
6882 -- which is certainly NOT a variable, could be turned into a variable
6885 function In_Protected_Function (E : Entity_Id) return Boolean;
6886 -- Within a protected function, the private components of the
6887 -- enclosing protected type are constants. A function nested within
6888 -- a (protected) procedure is not itself protected.
6890 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6891 -- Prefixes can involve implicit dereferences, in which case we
6892 -- must test for the case of a reference of a constant access
6893 -- type, which can never be a variable.
6895 ---------------------------
6896 -- In_Protected_Function --
6897 ---------------------------
6899 function In_Protected_Function (E : Entity_Id) return Boolean is
6900 Prot : constant Entity_Id := Scope (E);
6904 if not Is_Protected_Type (Prot) then
6908 while Present (S) and then S /= Prot loop
6909 if Ekind (S) = E_Function
6910 and then Scope (S) = Prot
6920 end In_Protected_Function;
6922 ------------------------
6923 -- Is_Variable_Prefix --
6924 ------------------------
6926 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6928 if Is_Access_Type (Etype (P)) then
6929 return not Is_Access_Constant (Root_Type (Etype (P)));
6931 -- For the case of an indexed component whose prefix has a packed
6932 -- array type, the prefix has been rewritten into a type conversion.
6933 -- Determine variable-ness from the converted expression.
6935 elsif Nkind (P) = N_Type_Conversion
6936 and then not Comes_From_Source (P)
6937 and then Is_Array_Type (Etype (P))
6938 and then Is_Packed (Etype (P))
6940 return Is_Variable (Expression (P));
6943 return Is_Variable (P);
6945 end Is_Variable_Prefix;
6947 -- Start of processing for Is_Variable
6950 -- Definitely OK if Assignment_OK is set. Since this is something that
6951 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6953 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6956 -- Normally we go to the original node, but there is one exception
6957 -- where we use the rewritten node, namely when it is an explicit
6958 -- dereference. The generated code may rewrite a prefix which is an
6959 -- access type with an explicit dereference. The dereference is a
6960 -- variable, even though the original node may not be (since it could
6961 -- be a constant of the access type).
6963 -- In Ada 2005 we have a further case to consider: the prefix may be
6964 -- a function call given in prefix notation. The original node appears
6965 -- to be a selected component, but we need to examine the call.
6967 elsif Nkind (N) = N_Explicit_Dereference
6968 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6969 and then Present (Etype (Orig_Node))
6970 and then Is_Access_Type (Etype (Orig_Node))
6972 -- Note that if the prefix is an explicit dereference that does not
6973 -- come from source, we must check for a rewritten function call in
6974 -- prefixed notation before other forms of rewriting, to prevent a
6978 (Nkind (Orig_Node) = N_Function_Call
6979 and then not Is_Access_Constant (Etype (Prefix (N))))
6981 Is_Variable_Prefix (Original_Node (Prefix (N)));
6983 -- A function call is never a variable
6985 elsif Nkind (N) = N_Function_Call then
6988 -- All remaining checks use the original node
6990 elsif Is_Entity_Name (Orig_Node)
6991 and then Present (Entity (Orig_Node))
6994 E : constant Entity_Id := Entity (Orig_Node);
6995 K : constant Entity_Kind := Ekind (E);
6998 return (K = E_Variable
6999 and then Nkind (Parent (E)) /= N_Exception_Handler)
7000 or else (K = E_Component
7001 and then not In_Protected_Function (E))
7002 or else K = E_Out_Parameter
7003 or else K = E_In_Out_Parameter
7004 or else K = E_Generic_In_Out_Parameter
7006 -- Current instance of type:
7008 or else (Is_Type (E) and then In_Open_Scopes (E))
7009 or else (Is_Incomplete_Or_Private_Type (E)
7010 and then In_Open_Scopes (Full_View (E)));
7014 case Nkind (Orig_Node) is
7015 when N_Indexed_Component | N_Slice =>
7016 return Is_Variable_Prefix (Prefix (Orig_Node));
7018 when N_Selected_Component =>
7019 return Is_Variable_Prefix (Prefix (Orig_Node))
7020 and then Is_Variable (Selector_Name (Orig_Node));
7022 -- For an explicit dereference, the type of the prefix cannot
7023 -- be an access to constant or an access to subprogram.
7025 when N_Explicit_Dereference =>
7027 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7029 return Is_Access_Type (Typ)
7030 and then not Is_Access_Constant (Root_Type (Typ))
7031 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7034 -- The type conversion is the case where we do not deal with the
7035 -- context dependent special case of an actual parameter. Thus
7036 -- the type conversion is only considered a variable for the
7037 -- purposes of this routine if the target type is tagged. However,
7038 -- a type conversion is considered to be a variable if it does not
7039 -- come from source (this deals for example with the conversions
7040 -- of expressions to their actual subtypes).
7042 when N_Type_Conversion =>
7043 return Is_Variable (Expression (Orig_Node))
7045 (not Comes_From_Source (Orig_Node)
7047 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7049 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7051 -- GNAT allows an unchecked type conversion as a variable. This
7052 -- only affects the generation of internal expanded code, since
7053 -- calls to instantiations of Unchecked_Conversion are never
7054 -- considered variables (since they are function calls).
7055 -- This is also true for expression actions.
7057 when N_Unchecked_Type_Conversion =>
7058 return Is_Variable (Expression (Orig_Node));
7066 ------------------------
7067 -- Is_Volatile_Object --
7068 ------------------------
7070 function Is_Volatile_Object (N : Node_Id) return Boolean is
7072 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7073 -- Determines if given object has volatile components
7075 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7076 -- If prefix is an implicit dereference, examine designated type
7078 ------------------------
7079 -- Is_Volatile_Prefix --
7080 ------------------------
7082 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7083 Typ : constant Entity_Id := Etype (N);
7086 if Is_Access_Type (Typ) then
7088 Dtyp : constant Entity_Id := Designated_Type (Typ);
7091 return Is_Volatile (Dtyp)
7092 or else Has_Volatile_Components (Dtyp);
7096 return Object_Has_Volatile_Components (N);
7098 end Is_Volatile_Prefix;
7100 ------------------------------------
7101 -- Object_Has_Volatile_Components --
7102 ------------------------------------
7104 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7105 Typ : constant Entity_Id := Etype (N);
7108 if Is_Volatile (Typ)
7109 or else Has_Volatile_Components (Typ)
7113 elsif Is_Entity_Name (N)
7114 and then (Has_Volatile_Components (Entity (N))
7115 or else Is_Volatile (Entity (N)))
7119 elsif Nkind (N) = N_Indexed_Component
7120 or else Nkind (N) = N_Selected_Component
7122 return Is_Volatile_Prefix (Prefix (N));
7127 end Object_Has_Volatile_Components;
7129 -- Start of processing for Is_Volatile_Object
7132 if Is_Volatile (Etype (N))
7133 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7137 elsif Nkind (N) = N_Indexed_Component
7138 or else Nkind (N) = N_Selected_Component
7140 return Is_Volatile_Prefix (Prefix (N));
7145 end Is_Volatile_Object;
7147 -------------------------
7148 -- Kill_Current_Values --
7149 -------------------------
7151 procedure Kill_Current_Values
7153 Last_Assignment_Only : Boolean := False)
7156 -- ??? do we have to worry about clearing cached checks?
7158 if Is_Assignable (Ent) then
7159 Set_Last_Assignment (Ent, Empty);
7162 if Is_Object (Ent) then
7163 if not Last_Assignment_Only then
7165 Set_Current_Value (Ent, Empty);
7167 if not Can_Never_Be_Null (Ent) then
7168 Set_Is_Known_Non_Null (Ent, False);
7171 Set_Is_Known_Null (Ent, False);
7173 -- Reset Is_Known_Valid unless type is always valid, or if we have
7174 -- a loop parameter (loop parameters are always valid, since their
7175 -- bounds are defined by the bounds given in the loop header).
7177 if not Is_Known_Valid (Etype (Ent))
7178 and then Ekind (Ent) /= E_Loop_Parameter
7180 Set_Is_Known_Valid (Ent, False);
7184 end Kill_Current_Values;
7186 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7189 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7190 -- Clear current value for entity E and all entities chained to E
7192 ------------------------------------------
7193 -- Kill_Current_Values_For_Entity_Chain --
7194 ------------------------------------------
7196 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7200 while Present (Ent) loop
7201 Kill_Current_Values (Ent, Last_Assignment_Only);
7204 end Kill_Current_Values_For_Entity_Chain;
7206 -- Start of processing for Kill_Current_Values
7209 -- Kill all saved checks, a special case of killing saved values
7211 if not Last_Assignment_Only then
7215 -- Loop through relevant scopes, which includes the current scope and
7216 -- any parent scopes if the current scope is a block or a package.
7221 -- Clear current values of all entities in current scope
7223 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7225 -- If scope is a package, also clear current values of all
7226 -- private entities in the scope.
7228 if Is_Package_Or_Generic_Package (S)
7229 or else Is_Concurrent_Type (S)
7231 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7234 -- If this is a not a subprogram, deal with parents
7236 if not Is_Subprogram (S) then
7238 exit Scope_Loop when S = Standard_Standard;
7242 end loop Scope_Loop;
7243 end Kill_Current_Values;
7245 --------------------------
7246 -- Kill_Size_Check_Code --
7247 --------------------------
7249 procedure Kill_Size_Check_Code (E : Entity_Id) is
7251 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7252 and then Present (Size_Check_Code (E))
7254 Remove (Size_Check_Code (E));
7255 Set_Size_Check_Code (E, Empty);
7257 end Kill_Size_Check_Code;
7259 --------------------------
7260 -- Known_To_Be_Assigned --
7261 --------------------------
7263 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7264 P : constant Node_Id := Parent (N);
7269 -- Test left side of assignment
7271 when N_Assignment_Statement =>
7272 return N = Name (P);
7274 -- Function call arguments are never lvalues
7276 when N_Function_Call =>
7279 -- Positional parameter for procedure or accept call
7281 when N_Procedure_Call_Statement |
7290 Proc := Get_Subprogram_Entity (P);
7296 -- If we are not a list member, something is strange, so
7297 -- be conservative and return False.
7299 if not Is_List_Member (N) then
7303 -- We are going to find the right formal by stepping forward
7304 -- through the formals, as we step backwards in the actuals.
7306 Form := First_Formal (Proc);
7309 -- If no formal, something is weird, so be conservative
7310 -- and return False.
7321 return Ekind (Form) /= E_In_Parameter;
7324 -- Named parameter for procedure or accept call
7326 when N_Parameter_Association =>
7332 Proc := Get_Subprogram_Entity (Parent (P));
7338 -- Loop through formals to find the one that matches
7340 Form := First_Formal (Proc);
7342 -- If no matching formal, that's peculiar, some kind of
7343 -- previous error, so return False to be conservative.
7349 -- Else test for match
7351 if Chars (Form) = Chars (Selector_Name (P)) then
7352 return Ekind (Form) /= E_In_Parameter;
7359 -- Test for appearing in a conversion that itself appears
7360 -- in an lvalue context, since this should be an lvalue.
7362 when N_Type_Conversion =>
7363 return Known_To_Be_Assigned (P);
7365 -- All other references are definitely not known to be modifications
7371 end Known_To_Be_Assigned;
7377 function May_Be_Lvalue (N : Node_Id) return Boolean is
7378 P : constant Node_Id := Parent (N);
7383 -- Test left side of assignment
7385 when N_Assignment_Statement =>
7386 return N = Name (P);
7388 -- Test prefix of component or attribute. Note that the prefix of an
7389 -- explicit or implicit dereference cannot be an l-value.
7391 when N_Attribute_Reference =>
7392 return N = Prefix (P)
7393 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7395 -- For an expanded name, the name is an lvalue if the expanded name
7396 -- is an lvalue, but the prefix is never an lvalue, since it is just
7397 -- the scope where the name is found.
7399 when N_Expanded_Name =>
7400 if N = Prefix (P) then
7401 return May_Be_Lvalue (P);
7406 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7407 -- B is a little interesting, if we have A.B := 3, there is some
7408 -- discussion as to whether B is an lvalue or not, we choose to say
7409 -- it is. Note however that A is not an lvalue if it is of an access
7410 -- type since this is an implicit dereference.
7412 when N_Selected_Component =>
7414 and then Present (Etype (N))
7415 and then Is_Access_Type (Etype (N))
7419 return May_Be_Lvalue (P);
7422 -- For an indexed component or slice, the index or slice bounds is
7423 -- never an lvalue. The prefix is an lvalue if the indexed component
7424 -- or slice is an lvalue, except if it is an access type, where we
7425 -- have an implicit dereference.
7427 when N_Indexed_Component =>
7429 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7433 return May_Be_Lvalue (P);
7436 -- Prefix of a reference is an lvalue if the reference is an lvalue
7439 return May_Be_Lvalue (P);
7441 -- Prefix of explicit dereference is never an lvalue
7443 when N_Explicit_Dereference =>
7446 -- Function call arguments are never lvalues
7448 when N_Function_Call =>
7451 -- Positional parameter for procedure, entry, or accept call
7453 when N_Procedure_Call_Statement |
7454 N_Entry_Call_Statement |
7463 Proc := Get_Subprogram_Entity (P);
7469 -- If we are not a list member, something is strange, so
7470 -- be conservative and return True.
7472 if not Is_List_Member (N) then
7476 -- We are going to find the right formal by stepping forward
7477 -- through the formals, as we step backwards in the actuals.
7479 Form := First_Formal (Proc);
7482 -- If no formal, something is weird, so be conservative
7494 return Ekind (Form) /= E_In_Parameter;
7497 -- Named parameter for procedure or accept call
7499 when N_Parameter_Association =>
7505 Proc := Get_Subprogram_Entity (Parent (P));
7511 -- Loop through formals to find the one that matches
7513 Form := First_Formal (Proc);
7515 -- If no matching formal, that's peculiar, some kind of
7516 -- previous error, so return True to be conservative.
7522 -- Else test for match
7524 if Chars (Form) = Chars (Selector_Name (P)) then
7525 return Ekind (Form) /= E_In_Parameter;
7532 -- Test for appearing in a conversion that itself appears in an
7533 -- lvalue context, since this should be an lvalue.
7535 when N_Type_Conversion =>
7536 return May_Be_Lvalue (P);
7538 -- Test for appearance in object renaming declaration
7540 when N_Object_Renaming_Declaration =>
7543 -- All other references are definitely not lvalues
7551 -----------------------
7552 -- Mark_Coextensions --
7553 -----------------------
7555 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7556 Is_Dynamic : Boolean;
7557 -- Indicates whether the context causes nested coextensions to be
7558 -- dynamic or static
7560 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7561 -- Recognize an allocator node and label it as a dynamic coextension
7563 --------------------
7564 -- Mark_Allocator --
7565 --------------------
7567 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7569 if Nkind (N) = N_Allocator then
7571 Set_Is_Dynamic_Coextension (N);
7573 Set_Is_Static_Coextension (N);
7580 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7582 -- Start of processing Mark_Coextensions
7585 case Nkind (Context_Nod) is
7586 when N_Assignment_Statement |
7587 N_Simple_Return_Statement =>
7588 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7590 when N_Object_Declaration =>
7591 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7593 -- This routine should not be called for constructs which may not
7594 -- contain coextensions.
7597 raise Program_Error;
7600 Mark_Allocators (Root_Nod);
7601 end Mark_Coextensions;
7603 ----------------------
7604 -- Needs_One_Actual --
7605 ----------------------
7607 function Needs_One_Actual (E : Entity_Id) return Boolean is
7611 if Ada_Version >= Ada_05
7612 and then Present (First_Formal (E))
7614 Formal := Next_Formal (First_Formal (E));
7615 while Present (Formal) loop
7616 if No (Default_Value (Formal)) then
7620 Next_Formal (Formal);
7628 end Needs_One_Actual;
7630 ------------------------
7631 -- New_Copy_List_Tree --
7632 ------------------------
7634 function New_Copy_List_Tree (List : List_Id) return List_Id is
7639 if List = No_List then
7646 while Present (E) loop
7647 Append (New_Copy_Tree (E), NL);
7653 end New_Copy_List_Tree;
7659 use Atree.Unchecked_Access;
7660 use Atree_Private_Part;
7662 -- Our approach here requires a two pass traversal of the tree. The
7663 -- first pass visits all nodes that eventually will be copied looking
7664 -- for defining Itypes. If any defining Itypes are found, then they are
7665 -- copied, and an entry is added to the replacement map. In the second
7666 -- phase, the tree is copied, using the replacement map to replace any
7667 -- Itype references within the copied tree.
7669 -- The following hash tables are used if the Map supplied has more
7670 -- than hash threshhold entries to speed up access to the map. If
7671 -- there are fewer entries, then the map is searched sequentially
7672 -- (because setting up a hash table for only a few entries takes
7673 -- more time than it saves.
7675 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7676 -- Hash function used for hash operations
7682 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7684 return Nat (E) mod (NCT_Header_Num'Last + 1);
7691 -- The hash table NCT_Assoc associates old entities in the table
7692 -- with their corresponding new entities (i.e. the pairs of entries
7693 -- presented in the original Map argument are Key-Element pairs).
7695 package NCT_Assoc is new Simple_HTable (
7696 Header_Num => NCT_Header_Num,
7697 Element => Entity_Id,
7698 No_Element => Empty,
7700 Hash => New_Copy_Hash,
7701 Equal => Types."=");
7703 ---------------------
7704 -- NCT_Itype_Assoc --
7705 ---------------------
7707 -- The hash table NCT_Itype_Assoc contains entries only for those
7708 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7709 -- The key is the associated node, and the element is the new node
7710 -- itself (NOT the associated node for the new node).
7712 package NCT_Itype_Assoc is new Simple_HTable (
7713 Header_Num => NCT_Header_Num,
7714 Element => Entity_Id,
7715 No_Element => Empty,
7717 Hash => New_Copy_Hash,
7718 Equal => Types."=");
7720 -- Start of processing for New_Copy_Tree function
7722 function New_Copy_Tree
7724 Map : Elist_Id := No_Elist;
7725 New_Sloc : Source_Ptr := No_Location;
7726 New_Scope : Entity_Id := Empty) return Node_Id
7728 Actual_Map : Elist_Id := Map;
7729 -- This is the actual map for the copy. It is initialized with the
7730 -- given elements, and then enlarged as required for Itypes that are
7731 -- copied during the first phase of the copy operation. The visit
7732 -- procedures add elements to this map as Itypes are encountered.
7733 -- The reason we cannot use Map directly, is that it may well be
7734 -- (and normally is) initialized to No_Elist, and if we have mapped
7735 -- entities, we have to reset it to point to a real Elist.
7737 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
7738 -- Called during second phase to map entities into their corresponding
7739 -- copies using Actual_Map. If the argument is not an entity, or is not
7740 -- in Actual_Map, then it is returned unchanged.
7742 procedure Build_NCT_Hash_Tables;
7743 -- Builds hash tables (number of elements >= threshold value)
7745 function Copy_Elist_With_Replacement
7746 (Old_Elist : Elist_Id) return Elist_Id;
7747 -- Called during second phase to copy element list doing replacements
7749 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
7750 -- Called during the second phase to process a copied Itype. The actual
7751 -- copy happened during the first phase (so that we could make the entry
7752 -- in the mapping), but we still have to deal with the descendents of
7753 -- the copied Itype and copy them where necessary.
7755 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
7756 -- Called during second phase to copy list doing replacements
7758 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
7759 -- Called during second phase to copy node doing replacements
7761 procedure Visit_Elist (E : Elist_Id);
7762 -- Called during first phase to visit all elements of an Elist
7764 procedure Visit_Field (F : Union_Id; N : Node_Id);
7765 -- Visit a single field, recursing to call Visit_Node or Visit_List
7766 -- if the field is a syntactic descendent of the current node (i.e.
7767 -- its parent is Node N).
7769 procedure Visit_Itype (Old_Itype : Entity_Id);
7770 -- Called during first phase to visit subsidiary fields of a defining
7771 -- Itype, and also create a copy and make an entry in the replacement
7772 -- map for the new copy.
7774 procedure Visit_List (L : List_Id);
7775 -- Called during first phase to visit all elements of a List
7777 procedure Visit_Node (N : Node_Or_Entity_Id);
7778 -- Called during first phase to visit a node and all its subtrees
7784 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
7789 if not Has_Extension (N) or else No (Actual_Map) then
7792 elsif NCT_Hash_Tables_Used then
7793 Ent := NCT_Assoc.Get (Entity_Id (N));
7795 if Present (Ent) then
7801 -- No hash table used, do serial search
7804 E := First_Elmt (Actual_Map);
7805 while Present (E) loop
7806 if Node (E) = N then
7807 return Node (Next_Elmt (E));
7809 E := Next_Elmt (Next_Elmt (E));
7817 ---------------------------
7818 -- Build_NCT_Hash_Tables --
7819 ---------------------------
7821 procedure Build_NCT_Hash_Tables is
7825 if NCT_Hash_Table_Setup then
7827 NCT_Itype_Assoc.Reset;
7830 Elmt := First_Elmt (Actual_Map);
7831 while Present (Elmt) loop
7834 -- Get new entity, and associate old and new
7837 NCT_Assoc.Set (Ent, Node (Elmt));
7839 if Is_Type (Ent) then
7841 Anode : constant Entity_Id :=
7842 Associated_Node_For_Itype (Ent);
7845 if Present (Anode) then
7847 -- Enter a link between the associated node of the
7848 -- old Itype and the new Itype, for updating later
7849 -- when node is copied.
7851 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
7859 NCT_Hash_Tables_Used := True;
7860 NCT_Hash_Table_Setup := True;
7861 end Build_NCT_Hash_Tables;
7863 ---------------------------------
7864 -- Copy_Elist_With_Replacement --
7865 ---------------------------------
7867 function Copy_Elist_With_Replacement
7868 (Old_Elist : Elist_Id) return Elist_Id
7871 New_Elist : Elist_Id;
7874 if No (Old_Elist) then
7878 New_Elist := New_Elmt_List;
7880 M := First_Elmt (Old_Elist);
7881 while Present (M) loop
7882 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
7888 end Copy_Elist_With_Replacement;
7890 ---------------------------------
7891 -- Copy_Itype_With_Replacement --
7892 ---------------------------------
7894 -- This routine exactly parallels its phase one analog Visit_Itype,
7896 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
7898 -- Translate Next_Entity, Scope and Etype fields, in case they
7899 -- reference entities that have been mapped into copies.
7901 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
7902 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
7904 if Present (New_Scope) then
7905 Set_Scope (New_Itype, New_Scope);
7907 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
7910 -- Copy referenced fields
7912 if Is_Discrete_Type (New_Itype) then
7913 Set_Scalar_Range (New_Itype,
7914 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
7916 elsif Has_Discriminants (Base_Type (New_Itype)) then
7917 Set_Discriminant_Constraint (New_Itype,
7918 Copy_Elist_With_Replacement
7919 (Discriminant_Constraint (New_Itype)));
7921 elsif Is_Array_Type (New_Itype) then
7922 if Present (First_Index (New_Itype)) then
7923 Set_First_Index (New_Itype,
7924 First (Copy_List_With_Replacement
7925 (List_Containing (First_Index (New_Itype)))));
7928 if Is_Packed (New_Itype) then
7929 Set_Packed_Array_Type (New_Itype,
7930 Copy_Node_With_Replacement
7931 (Packed_Array_Type (New_Itype)));
7934 end Copy_Itype_With_Replacement;
7936 --------------------------------
7937 -- Copy_List_With_Replacement --
7938 --------------------------------
7940 function Copy_List_With_Replacement
7941 (Old_List : List_Id) return List_Id
7947 if Old_List = No_List then
7951 New_List := Empty_List;
7953 E := First (Old_List);
7954 while Present (E) loop
7955 Append (Copy_Node_With_Replacement (E), New_List);
7961 end Copy_List_With_Replacement;
7963 --------------------------------
7964 -- Copy_Node_With_Replacement --
7965 --------------------------------
7967 function Copy_Node_With_Replacement
7968 (Old_Node : Node_Id) return Node_Id
7972 procedure Adjust_Named_Associations
7973 (Old_Node : Node_Id;
7974 New_Node : Node_Id);
7975 -- If a call node has named associations, these are chained through
7976 -- the First_Named_Actual, Next_Named_Actual links. These must be
7977 -- propagated separately to the new parameter list, because these
7978 -- are not syntactic fields.
7980 function Copy_Field_With_Replacement
7981 (Field : Union_Id) return Union_Id;
7982 -- Given Field, which is a field of Old_Node, return a copy of it
7983 -- if it is a syntactic field (i.e. its parent is Node), setting
7984 -- the parent of the copy to poit to New_Node. Otherwise returns
7985 -- the field (possibly mapped if it is an entity).
7987 -------------------------------
7988 -- Adjust_Named_Associations --
7989 -------------------------------
7991 procedure Adjust_Named_Associations
7992 (Old_Node : Node_Id;
8002 Old_E := First (Parameter_Associations (Old_Node));
8003 New_E := First (Parameter_Associations (New_Node));
8004 while Present (Old_E) loop
8005 if Nkind (Old_E) = N_Parameter_Association
8006 and then Present (Next_Named_Actual (Old_E))
8008 if First_Named_Actual (Old_Node)
8009 = Explicit_Actual_Parameter (Old_E)
8011 Set_First_Named_Actual
8012 (New_Node, Explicit_Actual_Parameter (New_E));
8015 -- Now scan parameter list from the beginning,to locate
8016 -- next named actual, which can be out of order.
8018 Old_Next := First (Parameter_Associations (Old_Node));
8019 New_Next := First (Parameter_Associations (New_Node));
8021 while Nkind (Old_Next) /= N_Parameter_Association
8022 or else Explicit_Actual_Parameter (Old_Next)
8023 /= Next_Named_Actual (Old_E)
8029 Set_Next_Named_Actual
8030 (New_E, Explicit_Actual_Parameter (New_Next));
8036 end Adjust_Named_Associations;
8038 ---------------------------------
8039 -- Copy_Field_With_Replacement --
8040 ---------------------------------
8042 function Copy_Field_With_Replacement
8043 (Field : Union_Id) return Union_Id
8046 if Field = Union_Id (Empty) then
8049 elsif Field in Node_Range then
8051 Old_N : constant Node_Id := Node_Id (Field);
8055 -- If syntactic field, as indicated by the parent pointer
8056 -- being set, then copy the referenced node recursively.
8058 if Parent (Old_N) = Old_Node then
8059 New_N := Copy_Node_With_Replacement (Old_N);
8061 if New_N /= Old_N then
8062 Set_Parent (New_N, New_Node);
8065 -- For semantic fields, update possible entity reference
8066 -- from the replacement map.
8069 New_N := Assoc (Old_N);
8072 return Union_Id (New_N);
8075 elsif Field in List_Range then
8077 Old_L : constant List_Id := List_Id (Field);
8081 -- If syntactic field, as indicated by the parent pointer,
8082 -- then recursively copy the entire referenced list.
8084 if Parent (Old_L) = Old_Node then
8085 New_L := Copy_List_With_Replacement (Old_L);
8086 Set_Parent (New_L, New_Node);
8088 -- For semantic list, just returned unchanged
8094 return Union_Id (New_L);
8097 -- Anything other than a list or a node is returned unchanged
8102 end Copy_Field_With_Replacement;
8104 -- Start of processing for Copy_Node_With_Replacement
8107 if Old_Node <= Empty_Or_Error then
8110 elsif Has_Extension (Old_Node) then
8111 return Assoc (Old_Node);
8114 New_Node := New_Copy (Old_Node);
8116 -- If the node we are copying is the associated node of a
8117 -- previously copied Itype, then adjust the associated node
8118 -- of the copy of that Itype accordingly.
8120 if Present (Actual_Map) then
8126 -- Case of hash table used
8128 if NCT_Hash_Tables_Used then
8129 Ent := NCT_Itype_Assoc.Get (Old_Node);
8131 if Present (Ent) then
8132 Set_Associated_Node_For_Itype (Ent, New_Node);
8135 -- Case of no hash table used
8138 E := First_Elmt (Actual_Map);
8139 while Present (E) loop
8140 if Is_Itype (Node (E))
8142 Old_Node = Associated_Node_For_Itype (Node (E))
8144 Set_Associated_Node_For_Itype
8145 (Node (Next_Elmt (E)), New_Node);
8148 E := Next_Elmt (Next_Elmt (E));
8154 -- Recursively copy descendents
8157 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8159 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8161 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8163 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8165 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8167 -- Adjust Sloc of new node if necessary
8169 if New_Sloc /= No_Location then
8170 Set_Sloc (New_Node, New_Sloc);
8172 -- If we adjust the Sloc, then we are essentially making
8173 -- a completely new node, so the Comes_From_Source flag
8174 -- should be reset to the proper default value.
8176 Nodes.Table (New_Node).Comes_From_Source :=
8177 Default_Node.Comes_From_Source;
8180 -- If the node is call and has named associations,
8181 -- set the corresponding links in the copy.
8183 if (Nkind (Old_Node) = N_Function_Call
8184 or else Nkind (Old_Node) = N_Entry_Call_Statement
8186 Nkind (Old_Node) = N_Procedure_Call_Statement)
8187 and then Present (First_Named_Actual (Old_Node))
8189 Adjust_Named_Associations (Old_Node, New_Node);
8192 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8193 -- The replacement mechanism applies to entities, and is not used
8194 -- here. Eventually we may need a more general graph-copying
8195 -- routine. For now, do a sequential search to find desired node.
8197 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8198 and then Present (First_Real_Statement (Old_Node))
8201 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8205 N1 := First (Statements (Old_Node));
8206 N2 := First (Statements (New_Node));
8208 while N1 /= Old_F loop
8213 Set_First_Real_Statement (New_Node, N2);
8218 -- All done, return copied node
8221 end Copy_Node_With_Replacement;
8227 procedure Visit_Elist (E : Elist_Id) is
8231 Elmt := First_Elmt (E);
8233 while Elmt /= No_Elmt loop
8234 Visit_Node (Node (Elmt));
8244 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8246 if F = Union_Id (Empty) then
8249 elsif F in Node_Range then
8251 -- Copy node if it is syntactic, i.e. its parent pointer is
8252 -- set to point to the field that referenced it (certain
8253 -- Itypes will also meet this criterion, which is fine, since
8254 -- these are clearly Itypes that do need to be copied, since
8255 -- we are copying their parent.)
8257 if Parent (Node_Id (F)) = N then
8258 Visit_Node (Node_Id (F));
8261 -- Another case, if we are pointing to an Itype, then we want
8262 -- to copy it if its associated node is somewhere in the tree
8265 -- Note: the exclusion of self-referential copies is just an
8266 -- optimization, since the search of the already copied list
8267 -- would catch it, but it is a common case (Etype pointing
8268 -- to itself for an Itype that is a base type).
8270 elsif Has_Extension (Node_Id (F))
8271 and then Is_Itype (Entity_Id (F))
8272 and then Node_Id (F) /= N
8278 P := Associated_Node_For_Itype (Node_Id (F));
8279 while Present (P) loop
8281 Visit_Node (Node_Id (F));
8288 -- An Itype whose parent is not being copied definitely
8289 -- should NOT be copied, since it does not belong in any
8290 -- sense to the copied subtree.
8296 elsif F in List_Range
8297 and then Parent (List_Id (F)) = N
8299 Visit_List (List_Id (F));
8308 procedure Visit_Itype (Old_Itype : Entity_Id) is
8309 New_Itype : Entity_Id;
8314 -- Itypes that describe the designated type of access to subprograms
8315 -- have the structure of subprogram declarations, with signatures,
8316 -- etc. Either we duplicate the signatures completely, or choose to
8317 -- share such itypes, which is fine because their elaboration will
8318 -- have no side effects.
8320 if Ekind (Old_Itype) = E_Subprogram_Type then
8324 New_Itype := New_Copy (Old_Itype);
8326 -- The new Itype has all the attributes of the old one, and
8327 -- we just copy the contents of the entity. However, the back-end
8328 -- needs different names for debugging purposes, so we create a
8329 -- new internal name for it in all cases.
8331 Set_Chars (New_Itype, New_Internal_Name ('T'));
8333 -- If our associated node is an entity that has already been copied,
8334 -- then set the associated node of the copy to point to the right
8335 -- copy. If we have copied an Itype that is itself the associated
8336 -- node of some previously copied Itype, then we set the right
8337 -- pointer in the other direction.
8339 if Present (Actual_Map) then
8341 -- Case of hash tables used
8343 if NCT_Hash_Tables_Used then
8345 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8347 if Present (Ent) then
8348 Set_Associated_Node_For_Itype (New_Itype, Ent);
8351 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8352 if Present (Ent) then
8353 Set_Associated_Node_For_Itype (Ent, New_Itype);
8355 -- If the hash table has no association for this Itype and
8356 -- its associated node, enter one now.
8360 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8363 -- Case of hash tables not used
8366 E := First_Elmt (Actual_Map);
8367 while Present (E) loop
8368 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8369 Set_Associated_Node_For_Itype
8370 (New_Itype, Node (Next_Elmt (E)));
8373 if Is_Type (Node (E))
8375 Old_Itype = Associated_Node_For_Itype (Node (E))
8377 Set_Associated_Node_For_Itype
8378 (Node (Next_Elmt (E)), New_Itype);
8381 E := Next_Elmt (Next_Elmt (E));
8386 if Present (Freeze_Node (New_Itype)) then
8387 Set_Is_Frozen (New_Itype, False);
8388 Set_Freeze_Node (New_Itype, Empty);
8391 -- Add new association to map
8393 if No (Actual_Map) then
8394 Actual_Map := New_Elmt_List;
8397 Append_Elmt (Old_Itype, Actual_Map);
8398 Append_Elmt (New_Itype, Actual_Map);
8400 if NCT_Hash_Tables_Used then
8401 NCT_Assoc.Set (Old_Itype, New_Itype);
8404 NCT_Table_Entries := NCT_Table_Entries + 1;
8406 if NCT_Table_Entries > NCT_Hash_Threshhold then
8407 Build_NCT_Hash_Tables;
8411 -- If a record subtype is simply copied, the entity list will be
8412 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8414 if Ekind (Old_Itype) = E_Record_Subtype
8415 or else Ekind (Old_Itype) = E_Class_Wide_Subtype
8417 Set_Cloned_Subtype (New_Itype, Old_Itype);
8420 -- Visit descendents that eventually get copied
8422 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8424 if Is_Discrete_Type (Old_Itype) then
8425 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8427 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8428 -- ??? This should involve call to Visit_Field
8429 Visit_Elist (Discriminant_Constraint (Old_Itype));
8431 elsif Is_Array_Type (Old_Itype) then
8432 if Present (First_Index (Old_Itype)) then
8433 Visit_Field (Union_Id (List_Containing
8434 (First_Index (Old_Itype))),
8438 if Is_Packed (Old_Itype) then
8439 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8449 procedure Visit_List (L : List_Id) is
8452 if L /= No_List then
8455 while Present (N) loop
8466 procedure Visit_Node (N : Node_Or_Entity_Id) is
8468 -- Start of processing for Visit_Node
8471 -- Handle case of an Itype, which must be copied
8473 if Has_Extension (N)
8474 and then Is_Itype (N)
8476 -- Nothing to do if already in the list. This can happen with an
8477 -- Itype entity that appears more than once in the tree.
8478 -- Note that we do not want to visit descendents in this case.
8480 -- Test for already in list when hash table is used
8482 if NCT_Hash_Tables_Used then
8483 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8487 -- Test for already in list when hash table not used
8493 if Present (Actual_Map) then
8494 E := First_Elmt (Actual_Map);
8495 while Present (E) loop
8496 if Node (E) = N then
8499 E := Next_Elmt (Next_Elmt (E));
8509 -- Visit descendents
8511 Visit_Field (Field1 (N), N);
8512 Visit_Field (Field2 (N), N);
8513 Visit_Field (Field3 (N), N);
8514 Visit_Field (Field4 (N), N);
8515 Visit_Field (Field5 (N), N);
8518 -- Start of processing for New_Copy_Tree
8523 -- See if we should use hash table
8525 if No (Actual_Map) then
8526 NCT_Hash_Tables_Used := False;
8533 NCT_Table_Entries := 0;
8535 Elmt := First_Elmt (Actual_Map);
8536 while Present (Elmt) loop
8537 NCT_Table_Entries := NCT_Table_Entries + 1;
8542 if NCT_Table_Entries > NCT_Hash_Threshhold then
8543 Build_NCT_Hash_Tables;
8545 NCT_Hash_Tables_Used := False;
8550 -- Hash table set up if required, now start phase one by visiting
8551 -- top node (we will recursively visit the descendents).
8553 Visit_Node (Source);
8555 -- Now the second phase of the copy can start. First we process
8556 -- all the mapped entities, copying their descendents.
8558 if Present (Actual_Map) then
8561 New_Itype : Entity_Id;
8563 Elmt := First_Elmt (Actual_Map);
8564 while Present (Elmt) loop
8566 New_Itype := Node (Elmt);
8567 Copy_Itype_With_Replacement (New_Itype);
8573 -- Now we can copy the actual tree
8575 return Copy_Node_With_Replacement (Source);
8578 -------------------------
8579 -- New_External_Entity --
8580 -------------------------
8582 function New_External_Entity
8583 (Kind : Entity_Kind;
8584 Scope_Id : Entity_Id;
8585 Sloc_Value : Source_Ptr;
8586 Related_Id : Entity_Id;
8588 Suffix_Index : Nat := 0;
8589 Prefix : Character := ' ') return Entity_Id
8591 N : constant Entity_Id :=
8592 Make_Defining_Identifier (Sloc_Value,
8594 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8597 Set_Ekind (N, Kind);
8598 Set_Is_Internal (N, True);
8599 Append_Entity (N, Scope_Id);
8600 Set_Public_Status (N);
8602 if Kind in Type_Kind then
8603 Init_Size_Align (N);
8607 end New_External_Entity;
8609 -------------------------
8610 -- New_Internal_Entity --
8611 -------------------------
8613 function New_Internal_Entity
8614 (Kind : Entity_Kind;
8615 Scope_Id : Entity_Id;
8616 Sloc_Value : Source_Ptr;
8617 Id_Char : Character) return Entity_Id
8619 N : constant Entity_Id :=
8620 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
8623 Set_Ekind (N, Kind);
8624 Set_Is_Internal (N, True);
8625 Append_Entity (N, Scope_Id);
8627 if Kind in Type_Kind then
8628 Init_Size_Align (N);
8632 end New_Internal_Entity;
8638 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8642 -- If we are pointing at a positional parameter, it is a member of a
8643 -- node list (the list of parameters), and the next parameter is the
8644 -- next node on the list, unless we hit a parameter association, then
8645 -- we shift to using the chain whose head is the First_Named_Actual in
8646 -- the parent, and then is threaded using the Next_Named_Actual of the
8647 -- Parameter_Association. All this fiddling is because the original node
8648 -- list is in the textual call order, and what we need is the
8649 -- declaration order.
8651 if Is_List_Member (Actual_Id) then
8652 N := Next (Actual_Id);
8654 if Nkind (N) = N_Parameter_Association then
8655 return First_Named_Actual (Parent (Actual_Id));
8661 return Next_Named_Actual (Parent (Actual_Id));
8665 procedure Next_Actual (Actual_Id : in out Node_Id) is
8667 Actual_Id := Next_Actual (Actual_Id);
8670 -----------------------
8671 -- Normalize_Actuals --
8672 -----------------------
8674 -- Chain actuals according to formals of subprogram. If there are no named
8675 -- associations, the chain is simply the list of Parameter Associations,
8676 -- since the order is the same as the declaration order. If there are named
8677 -- associations, then the First_Named_Actual field in the N_Function_Call
8678 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8679 -- node for the parameter that comes first in declaration order. The
8680 -- remaining named parameters are then chained in declaration order using
8681 -- Next_Named_Actual.
8683 -- This routine also verifies that the number of actuals is compatible with
8684 -- the number and default values of formals, but performs no type checking
8685 -- (type checking is done by the caller).
8687 -- If the matching succeeds, Success is set to True and the caller proceeds
8688 -- with type-checking. If the match is unsuccessful, then Success is set to
8689 -- False, and the caller attempts a different interpretation, if there is
8692 -- If the flag Report is on, the call is not overloaded, and a failure to
8693 -- match can be reported here, rather than in the caller.
8695 procedure Normalize_Actuals
8699 Success : out Boolean)
8701 Actuals : constant List_Id := Parameter_Associations (N);
8702 Actual : Node_Id := Empty;
8704 Last : Node_Id := Empty;
8705 First_Named : Node_Id := Empty;
8708 Formals_To_Match : Integer := 0;
8709 Actuals_To_Match : Integer := 0;
8711 procedure Chain (A : Node_Id);
8712 -- Add named actual at the proper place in the list, using the
8713 -- Next_Named_Actual link.
8715 function Reporting return Boolean;
8716 -- Determines if an error is to be reported. To report an error, we
8717 -- need Report to be True, and also we do not report errors caused
8718 -- by calls to init procs that occur within other init procs. Such
8719 -- errors must always be cascaded errors, since if all the types are
8720 -- declared correctly, the compiler will certainly build decent calls!
8726 procedure Chain (A : Node_Id) is
8730 -- Call node points to first actual in list
8732 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
8735 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
8739 Set_Next_Named_Actual (Last, Empty);
8746 function Reporting return Boolean is
8751 elsif not Within_Init_Proc then
8754 elsif Is_Init_Proc (Entity (Name (N))) then
8762 -- Start of processing for Normalize_Actuals
8765 if Is_Access_Type (S) then
8767 -- The name in the call is a function call that returns an access
8768 -- to subprogram. The designated type has the list of formals.
8770 Formal := First_Formal (Designated_Type (S));
8772 Formal := First_Formal (S);
8775 while Present (Formal) loop
8776 Formals_To_Match := Formals_To_Match + 1;
8777 Next_Formal (Formal);
8780 -- Find if there is a named association, and verify that no positional
8781 -- associations appear after named ones.
8783 if Present (Actuals) then
8784 Actual := First (Actuals);
8787 while Present (Actual)
8788 and then Nkind (Actual) /= N_Parameter_Association
8790 Actuals_To_Match := Actuals_To_Match + 1;
8794 if No (Actual) and Actuals_To_Match = Formals_To_Match then
8796 -- Most common case: positional notation, no defaults
8801 elsif Actuals_To_Match > Formals_To_Match then
8803 -- Too many actuals: will not work
8806 if Is_Entity_Name (Name (N)) then
8807 Error_Msg_N ("too many arguments in call to&", Name (N));
8809 Error_Msg_N ("too many arguments in call", N);
8817 First_Named := Actual;
8819 while Present (Actual) loop
8820 if Nkind (Actual) /= N_Parameter_Association then
8822 ("positional parameters not allowed after named ones", Actual);
8827 Actuals_To_Match := Actuals_To_Match + 1;
8833 if Present (Actuals) then
8834 Actual := First (Actuals);
8837 Formal := First_Formal (S);
8838 while Present (Formal) loop
8840 -- Match the formals in order. If the corresponding actual is
8841 -- positional, nothing to do. Else scan the list of named actuals
8842 -- to find the one with the right name.
8845 and then Nkind (Actual) /= N_Parameter_Association
8848 Actuals_To_Match := Actuals_To_Match - 1;
8849 Formals_To_Match := Formals_To_Match - 1;
8852 -- For named parameters, search the list of actuals to find
8853 -- one that matches the next formal name.
8855 Actual := First_Named;
8857 while Present (Actual) loop
8858 if Chars (Selector_Name (Actual)) = Chars (Formal) then
8861 Actuals_To_Match := Actuals_To_Match - 1;
8862 Formals_To_Match := Formals_To_Match - 1;
8870 if Ekind (Formal) /= E_In_Parameter
8871 or else No (Default_Value (Formal))
8874 if (Comes_From_Source (S)
8875 or else Sloc (S) = Standard_Location)
8876 and then Is_Overloadable (S)
8880 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8882 (Nkind (Parent (N)) = N_Function_Call
8884 Nkind (Parent (N)) = N_Parameter_Association))
8885 and then Ekind (S) /= E_Function
8887 Set_Etype (N, Etype (S));
8889 Error_Msg_Name_1 := Chars (S);
8890 Error_Msg_Sloc := Sloc (S);
8892 ("missing argument for parameter & " &
8893 "in call to % declared #", N, Formal);
8896 elsif Is_Overloadable (S) then
8897 Error_Msg_Name_1 := Chars (S);
8899 -- Point to type derivation that generated the
8902 Error_Msg_Sloc := Sloc (Parent (S));
8905 ("missing argument for parameter & " &
8906 "in call to % (inherited) #", N, Formal);
8910 ("missing argument for parameter &", N, Formal);
8918 Formals_To_Match := Formals_To_Match - 1;
8923 Next_Formal (Formal);
8926 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8933 -- Find some superfluous named actual that did not get
8934 -- attached to the list of associations.
8936 Actual := First (Actuals);
8937 while Present (Actual) loop
8938 if Nkind (Actual) = N_Parameter_Association
8939 and then Actual /= Last
8940 and then No (Next_Named_Actual (Actual))
8942 Error_Msg_N ("unmatched actual & in call",
8943 Selector_Name (Actual));
8954 end Normalize_Actuals;
8956 --------------------------------
8957 -- Note_Possible_Modification --
8958 --------------------------------
8960 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8961 Modification_Comes_From_Source : constant Boolean :=
8962 Comes_From_Source (Parent (N));
8968 -- Loop to find referenced entity, if there is one
8975 if Is_Entity_Name (Exp) then
8976 Ent := Entity (Exp);
8978 -- If the entity is missing, it is an undeclared identifier,
8979 -- and there is nothing to annotate.
8985 elsif Nkind (Exp) = N_Explicit_Dereference then
8987 P : constant Node_Id := Prefix (Exp);
8990 if Nkind (P) = N_Selected_Component
8992 Entry_Formal (Entity (Selector_Name (P))))
8994 -- Case of a reference to an entry formal
8996 Ent := Entry_Formal (Entity (Selector_Name (P)));
8998 elsif Nkind (P) = N_Identifier
8999 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9000 and then Present (Expression (Parent (Entity (P))))
9001 and then Nkind (Expression (Parent (Entity (P))))
9004 -- Case of a reference to a value on which side effects have
9007 Exp := Prefix (Expression (Parent (Entity (P))));
9016 elsif Nkind (Exp) = N_Type_Conversion
9017 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9019 Exp := Expression (Exp);
9022 elsif Nkind (Exp) = N_Slice
9023 or else Nkind (Exp) = N_Indexed_Component
9024 or else Nkind (Exp) = N_Selected_Component
9026 Exp := Prefix (Exp);
9033 -- Now look for entity being referenced
9035 if Present (Ent) then
9036 if Is_Object (Ent) then
9037 if Comes_From_Source (Exp)
9038 or else Modification_Comes_From_Source
9040 if Has_Pragma_Unmodified (Ent) then
9041 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9044 Set_Never_Set_In_Source (Ent, False);
9047 Set_Is_True_Constant (Ent, False);
9048 Set_Current_Value (Ent, Empty);
9049 Set_Is_Known_Null (Ent, False);
9051 if not Can_Never_Be_Null (Ent) then
9052 Set_Is_Known_Non_Null (Ent, False);
9055 -- Follow renaming chain
9057 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9058 and then Present (Renamed_Object (Ent))
9060 Exp := Renamed_Object (Ent);
9064 -- Generate a reference only if the assignment comes from
9065 -- source. This excludes, for example, calls to a dispatching
9066 -- assignment operation when the left-hand side is tagged.
9068 if Modification_Comes_From_Source then
9069 Generate_Reference (Ent, Exp, 'm');
9072 Check_Nested_Access (Ent);
9077 -- If we are sure this is a modification from source, and we know
9078 -- this modifies a constant, then give an appropriate warning.
9080 if Overlays_Constant (Ent)
9081 and then Modification_Comes_From_Source
9085 A : constant Node_Id := Address_Clause (Ent);
9089 Exp : constant Node_Id := Expression (A);
9091 if Nkind (Exp) = N_Attribute_Reference
9092 and then Attribute_Name (Exp) = Name_Address
9093 and then Is_Entity_Name (Prefix (Exp))
9095 Error_Msg_Sloc := Sloc (A);
9097 ("constant& may be modified via address clause#?",
9098 N, Entity (Prefix (Exp)));
9108 end Note_Possible_Modification;
9110 -------------------------
9111 -- Object_Access_Level --
9112 -------------------------
9114 function Object_Access_Level (Obj : Node_Id) return Uint is
9117 -- Returns the static accessibility level of the view denoted by Obj. Note
9118 -- that the value returned is the result of a call to Scope_Depth. Only
9119 -- scope depths associated with dynamic scopes can actually be returned.
9120 -- Since only relative levels matter for accessibility checking, the fact
9121 -- that the distance between successive levels of accessibility is not
9122 -- always one is immaterial (invariant: if level(E2) is deeper than
9123 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9125 function Reference_To (Obj : Node_Id) return Node_Id;
9126 -- An explicit dereference is created when removing side-effects from
9127 -- expressions for constraint checking purposes. In this case a local
9128 -- access type is created for it. The correct access level is that of
9129 -- the original source node. We detect this case by noting that the
9130 -- prefix of the dereference is created by an object declaration whose
9131 -- initial expression is a reference.
9137 function Reference_To (Obj : Node_Id) return Node_Id is
9138 Pref : constant Node_Id := Prefix (Obj);
9140 if Is_Entity_Name (Pref)
9141 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9142 and then Present (Expression (Parent (Entity (Pref))))
9143 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9145 return (Prefix (Expression (Parent (Entity (Pref)))));
9151 -- Start of processing for Object_Access_Level
9154 if Is_Entity_Name (Obj) then
9157 if Is_Prival (E) then
9158 E := Prival_Link (E);
9161 -- If E is a type then it denotes a current instance. For this case
9162 -- we add one to the normal accessibility level of the type to ensure
9163 -- that current instances are treated as always being deeper than
9164 -- than the level of any visible named access type (see 3.10.2(21)).
9167 return Type_Access_Level (E) + 1;
9169 elsif Present (Renamed_Object (E)) then
9170 return Object_Access_Level (Renamed_Object (E));
9172 -- Similarly, if E is a component of the current instance of a
9173 -- protected type, any instance of it is assumed to be at a deeper
9174 -- level than the type. For a protected object (whose type is an
9175 -- anonymous protected type) its components are at the same level
9176 -- as the type itself.
9178 elsif not Is_Overloadable (E)
9179 and then Ekind (Scope (E)) = E_Protected_Type
9180 and then Comes_From_Source (Scope (E))
9182 return Type_Access_Level (Scope (E)) + 1;
9185 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9188 elsif Nkind (Obj) = N_Selected_Component then
9189 if Is_Access_Type (Etype (Prefix (Obj))) then
9190 return Type_Access_Level (Etype (Prefix (Obj)));
9192 return Object_Access_Level (Prefix (Obj));
9195 elsif Nkind (Obj) = N_Indexed_Component then
9196 if Is_Access_Type (Etype (Prefix (Obj))) then
9197 return Type_Access_Level (Etype (Prefix (Obj)));
9199 return Object_Access_Level (Prefix (Obj));
9202 elsif Nkind (Obj) = N_Explicit_Dereference then
9204 -- If the prefix is a selected access discriminant then we make a
9205 -- recursive call on the prefix, which will in turn check the level
9206 -- of the prefix object of the selected discriminant.
9208 if Nkind (Prefix (Obj)) = N_Selected_Component
9209 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9211 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9213 return Object_Access_Level (Prefix (Obj));
9215 elsif not (Comes_From_Source (Obj)) then
9217 Ref : constant Node_Id := Reference_To (Obj);
9219 if Present (Ref) then
9220 return Object_Access_Level (Ref);
9222 return Type_Access_Level (Etype (Prefix (Obj)));
9227 return Type_Access_Level (Etype (Prefix (Obj)));
9230 elsif Nkind (Obj) = N_Type_Conversion
9231 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9233 return Object_Access_Level (Expression (Obj));
9235 -- Function results are objects, so we get either the access level of
9236 -- the function or, in the case of an indirect call, the level of the
9237 -- access-to-subprogram type.
9239 elsif Nkind (Obj) = N_Function_Call then
9240 if Is_Entity_Name (Name (Obj)) then
9241 return Subprogram_Access_Level (Entity (Name (Obj)));
9243 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9246 -- For convenience we handle qualified expressions, even though
9247 -- they aren't technically object names.
9249 elsif Nkind (Obj) = N_Qualified_Expression then
9250 return Object_Access_Level (Expression (Obj));
9252 -- Otherwise return the scope level of Standard.
9253 -- (If there are cases that fall through
9254 -- to this point they will be treated as
9255 -- having global accessibility for now. ???)
9258 return Scope_Depth (Standard_Standard);
9260 end Object_Access_Level;
9262 -----------------------
9263 -- Private_Component --
9264 -----------------------
9266 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9267 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9269 function Trace_Components
9271 Check : Boolean) return Entity_Id;
9272 -- Recursive function that does the work, and checks against circular
9273 -- definition for each subcomponent type.
9275 ----------------------
9276 -- Trace_Components --
9277 ----------------------
9279 function Trace_Components
9281 Check : Boolean) return Entity_Id
9283 Btype : constant Entity_Id := Base_Type (T);
9284 Component : Entity_Id;
9286 Candidate : Entity_Id := Empty;
9289 if Check and then Btype = Ancestor then
9290 Error_Msg_N ("circular type definition", Type_Id);
9294 if Is_Private_Type (Btype)
9295 and then not Is_Generic_Type (Btype)
9297 if Present (Full_View (Btype))
9298 and then Is_Record_Type (Full_View (Btype))
9299 and then not Is_Frozen (Btype)
9301 -- To indicate that the ancestor depends on a private type, the
9302 -- current Btype is sufficient. However, to check for circular
9303 -- definition we must recurse on the full view.
9305 Candidate := Trace_Components (Full_View (Btype), True);
9307 if Candidate = Any_Type then
9317 elsif Is_Array_Type (Btype) then
9318 return Trace_Components (Component_Type (Btype), True);
9320 elsif Is_Record_Type (Btype) then
9321 Component := First_Entity (Btype);
9322 while Present (Component) loop
9324 -- Skip anonymous types generated by constrained components
9326 if not Is_Type (Component) then
9327 P := Trace_Components (Etype (Component), True);
9330 if P = Any_Type then
9338 Next_Entity (Component);
9346 end Trace_Components;
9348 -- Start of processing for Private_Component
9351 return Trace_Components (Type_Id, False);
9352 end Private_Component;
9354 ---------------------------
9355 -- Primitive_Names_Match --
9356 ---------------------------
9358 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9360 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9361 -- Given an internal name, returns the corresponding non-internal name
9363 ------------------------
9364 -- Non_Internal_Name --
9365 ------------------------
9367 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9369 Get_Name_String (Chars (E));
9370 Name_Len := Name_Len - 1;
9372 end Non_Internal_Name;
9374 -- Start of processing for Primitive_Names_Match
9377 pragma Assert (Present (E1) and then Present (E2));
9379 return Chars (E1) = Chars (E2)
9381 (not Is_Internal_Name (Chars (E1))
9382 and then Is_Internal_Name (Chars (E2))
9383 and then Non_Internal_Name (E2) = Chars (E1))
9385 (not Is_Internal_Name (Chars (E2))
9386 and then Is_Internal_Name (Chars (E1))
9387 and then Non_Internal_Name (E1) = Chars (E2))
9389 (Is_Predefined_Dispatching_Operation (E1)
9390 and then Is_Predefined_Dispatching_Operation (E2)
9391 and then Same_TSS (E1, E2))
9393 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9394 end Primitive_Names_Match;
9396 -----------------------
9397 -- Process_End_Label --
9398 -----------------------
9400 procedure Process_End_Label
9409 Label_Ref : Boolean;
9410 -- Set True if reference to end label itself is required
9413 -- Gets set to the operator symbol or identifier that references the
9414 -- entity Ent. For the child unit case, this is the identifier from the
9415 -- designator. For other cases, this is simply Endl.
9417 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9418 -- N is an identifier node that appears as a parent unit reference in
9419 -- the case where Ent is a child unit. This procedure generates an
9420 -- appropriate cross-reference entry. E is the corresponding entity.
9422 -------------------------
9423 -- Generate_Parent_Ref --
9424 -------------------------
9426 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9428 -- If names do not match, something weird, skip reference
9430 if Chars (E) = Chars (N) then
9432 -- Generate the reference. We do NOT consider this as a reference
9433 -- for unreferenced symbol purposes.
9435 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9438 Style.Check_Identifier (N, E);
9441 end Generate_Parent_Ref;
9443 -- Start of processing for Process_End_Label
9446 -- If no node, ignore. This happens in some error situations, and
9447 -- also for some internally generated structures where no end label
9448 -- references are required in any case.
9454 -- Nothing to do if no End_Label, happens for internally generated
9455 -- constructs where we don't want an end label reference anyway. Also
9456 -- nothing to do if Endl is a string literal, which means there was
9457 -- some prior error (bad operator symbol)
9459 Endl := End_Label (N);
9461 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9465 -- Reference node is not in extended main source unit
9467 if not In_Extended_Main_Source_Unit (N) then
9469 -- Generally we do not collect references except for the extended
9470 -- main source unit. The one exception is the 'e' entry for a
9471 -- package spec, where it is useful for a client to have the
9472 -- ending information to define scopes.
9480 -- For this case, we can ignore any parent references, but we
9481 -- need the package name itself for the 'e' entry.
9483 if Nkind (Endl) = N_Designator then
9484 Endl := Identifier (Endl);
9488 -- Reference is in extended main source unit
9493 -- For designator, generate references for the parent entries
9495 if Nkind (Endl) = N_Designator then
9497 -- Generate references for the prefix if the END line comes from
9498 -- source (otherwise we do not need these references) We climb the
9499 -- scope stack to find the expected entities.
9501 if Comes_From_Source (Endl) then
9503 Scop := Current_Scope;
9504 while Nkind (Nam) = N_Selected_Component loop
9505 Scop := Scope (Scop);
9506 exit when No (Scop);
9507 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9508 Nam := Prefix (Nam);
9511 if Present (Scop) then
9512 Generate_Parent_Ref (Nam, Scope (Scop));
9516 Endl := Identifier (Endl);
9520 -- If the end label is not for the given entity, then either we have
9521 -- some previous error, or this is a generic instantiation for which
9522 -- we do not need to make a cross-reference in this case anyway. In
9523 -- either case we simply ignore the call.
9525 if Chars (Ent) /= Chars (Endl) then
9529 -- If label was really there, then generate a normal reference and then
9530 -- adjust the location in the end label to point past the name (which
9531 -- should almost always be the semicolon).
9535 if Comes_From_Source (Endl) then
9537 -- If a label reference is required, then do the style check and
9538 -- generate an l-type cross-reference entry for the label
9542 Style.Check_Identifier (Endl, Ent);
9545 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9548 -- Set the location to point past the label (normally this will
9549 -- mean the semicolon immediately following the label). This is
9550 -- done for the sake of the 'e' or 't' entry generated below.
9552 Get_Decoded_Name_String (Chars (Endl));
9553 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9556 -- Now generate the e/t reference
9558 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9560 -- Restore Sloc, in case modified above, since we have an identifier
9561 -- and the normal Sloc should be left set in the tree.
9563 Set_Sloc (Endl, Loc);
9564 end Process_End_Label;
9570 -- We do the conversion to get the value of the real string by using
9571 -- the scanner, see Sinput for details on use of the internal source
9572 -- buffer for scanning internal strings.
9574 function Real_Convert (S : String) return Node_Id is
9575 Save_Src : constant Source_Buffer_Ptr := Source;
9579 Source := Internal_Source_Ptr;
9582 for J in S'Range loop
9583 Source (Source_Ptr (J)) := S (J);
9586 Source (S'Length + 1) := EOF;
9588 if Source (Scan_Ptr) = '-' then
9590 Scan_Ptr := Scan_Ptr + 1;
9598 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9605 ------------------------------------
9606 -- References_Generic_Formal_Type --
9607 ------------------------------------
9609 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
9611 function Process (N : Node_Id) return Traverse_Result;
9612 -- Process one node in search for generic formal type
9618 function Process (N : Node_Id) return Traverse_Result is
9620 if Nkind (N) in N_Has_Entity then
9622 E : constant Entity_Id := Entity (N);
9625 if Is_Generic_Type (E) then
9627 elsif Present (Etype (E))
9628 and then Is_Generic_Type (Etype (E))
9639 function Traverse is new Traverse_Func (Process);
9640 -- Traverse tree to look for generic type
9643 if Inside_A_Generic then
9644 return Traverse (N) = Abandon;
9648 end References_Generic_Formal_Type;
9650 --------------------
9651 -- Remove_Homonym --
9652 --------------------
9654 procedure Remove_Homonym (E : Entity_Id) is
9655 Prev : Entity_Id := Empty;
9659 if E = Current_Entity (E) then
9660 if Present (Homonym (E)) then
9661 Set_Current_Entity (Homonym (E));
9663 Set_Name_Entity_Id (Chars (E), Empty);
9666 H := Current_Entity (E);
9667 while Present (H) and then H /= E loop
9672 Set_Homonym (Prev, Homonym (E));
9676 ---------------------
9677 -- Rep_To_Pos_Flag --
9678 ---------------------
9680 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
9682 return New_Occurrence_Of
9683 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
9684 end Rep_To_Pos_Flag;
9686 --------------------
9687 -- Require_Entity --
9688 --------------------
9690 procedure Require_Entity (N : Node_Id) is
9692 if Is_Entity_Name (N) and then No (Entity (N)) then
9693 if Total_Errors_Detected /= 0 then
9694 Set_Entity (N, Any_Id);
9696 raise Program_Error;
9701 ------------------------------
9702 -- Requires_Transient_Scope --
9703 ------------------------------
9705 -- A transient scope is required when variable-sized temporaries are
9706 -- allocated in the primary or secondary stack, or when finalization
9707 -- actions must be generated before the next instruction.
9709 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
9710 Typ : constant Entity_Id := Underlying_Type (Id);
9712 -- Start of processing for Requires_Transient_Scope
9715 -- This is a private type which is not completed yet. This can only
9716 -- happen in a default expression (of a formal parameter or of a
9717 -- record component). Do not expand transient scope in this case
9722 -- Do not expand transient scope for non-existent procedure return
9724 elsif Typ = Standard_Void_Type then
9727 -- Elementary types do not require a transient scope
9729 elsif Is_Elementary_Type (Typ) then
9732 -- Generally, indefinite subtypes require a transient scope, since the
9733 -- back end cannot generate temporaries, since this is not a valid type
9734 -- for declaring an object. It might be possible to relax this in the
9735 -- future, e.g. by declaring the maximum possible space for the type.
9737 elsif Is_Indefinite_Subtype (Typ) then
9740 -- Functions returning tagged types may dispatch on result so their
9741 -- returned value is allocated on the secondary stack. Controlled
9742 -- type temporaries need finalization.
9744 elsif Is_Tagged_Type (Typ)
9745 or else Has_Controlled_Component (Typ)
9747 return not Is_Value_Type (Typ);
9751 elsif Is_Record_Type (Typ) then
9755 Comp := First_Entity (Typ);
9756 while Present (Comp) loop
9757 if Ekind (Comp) = E_Component
9758 and then Requires_Transient_Scope (Etype (Comp))
9769 -- String literal types never require transient scope
9771 elsif Ekind (Typ) = E_String_Literal_Subtype then
9774 -- Array type. Note that we already know that this is a constrained
9775 -- array, since unconstrained arrays will fail the indefinite test.
9777 elsif Is_Array_Type (Typ) then
9779 -- If component type requires a transient scope, the array does too
9781 if Requires_Transient_Scope (Component_Type (Typ)) then
9784 -- Otherwise, we only need a transient scope if the size is not
9785 -- known at compile time.
9788 return not Size_Known_At_Compile_Time (Typ);
9791 -- All other cases do not require a transient scope
9796 end Requires_Transient_Scope;
9798 --------------------------
9799 -- Reset_Analyzed_Flags --
9800 --------------------------
9802 procedure Reset_Analyzed_Flags (N : Node_Id) is
9804 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
9805 -- Function used to reset Analyzed flags in tree. Note that we do
9806 -- not reset Analyzed flags in entities, since there is no need to
9807 -- reanalyze entities, and indeed, it is wrong to do so, since it
9808 -- can result in generating auxiliary stuff more than once.
9810 --------------------
9811 -- Clear_Analyzed --
9812 --------------------
9814 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
9816 if not Has_Extension (N) then
9817 Set_Analyzed (N, False);
9823 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
9825 -- Start of processing for Reset_Analyzed_Flags
9829 end Reset_Analyzed_Flags;
9831 ---------------------------
9832 -- Safe_To_Capture_Value --
9833 ---------------------------
9835 function Safe_To_Capture_Value
9838 Cond : Boolean := False) return Boolean
9841 -- The only entities for which we track constant values are variables
9842 -- which are not renamings, constants, out parameters, and in out
9843 -- parameters, so check if we have this case.
9845 -- Note: it may seem odd to track constant values for constants, but in
9846 -- fact this routine is used for other purposes than simply capturing
9847 -- the value. In particular, the setting of Known[_Non]_Null.
9849 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
9851 Ekind (Ent) = E_Constant
9853 Ekind (Ent) = E_Out_Parameter
9855 Ekind (Ent) = E_In_Out_Parameter
9859 -- For conditionals, we also allow loop parameters and all formals,
9860 -- including in parameters.
9864 (Ekind (Ent) = E_Loop_Parameter
9866 Ekind (Ent) = E_In_Parameter)
9870 -- For all other cases, not just unsafe, but impossible to capture
9871 -- Current_Value, since the above are the only entities which have
9872 -- Current_Value fields.
9878 -- Skip if volatile or aliased, since funny things might be going on in
9879 -- these cases which we cannot necessarily track. Also skip any variable
9880 -- for which an address clause is given, or whose address is taken. Also
9881 -- never capture value of library level variables (an attempt to do so
9882 -- can occur in the case of package elaboration code).
9884 if Treat_As_Volatile (Ent)
9885 or else Is_Aliased (Ent)
9886 or else Present (Address_Clause (Ent))
9887 or else Address_Taken (Ent)
9888 or else (Is_Library_Level_Entity (Ent)
9889 and then Ekind (Ent) = E_Variable)
9894 -- OK, all above conditions are met. We also require that the scope of
9895 -- the reference be the same as the scope of the entity, not counting
9896 -- packages and blocks and loops.
9899 E_Scope : constant Entity_Id := Scope (Ent);
9900 R_Scope : Entity_Id;
9903 R_Scope := Current_Scope;
9904 while R_Scope /= Standard_Standard loop
9905 exit when R_Scope = E_Scope;
9907 if Ekind (R_Scope) /= E_Package
9909 Ekind (R_Scope) /= E_Block
9911 Ekind (R_Scope) /= E_Loop
9915 R_Scope := Scope (R_Scope);
9920 -- We also require that the reference does not appear in a context
9921 -- where it is not sure to be executed (i.e. a conditional context
9922 -- or an exception handler). We skip this if Cond is True, since the
9923 -- capturing of values from conditional tests handles this ok.
9937 while Present (P) loop
9938 if Nkind (P) = N_If_Statement
9939 or else Nkind (P) = N_Case_Statement
9940 or else (Nkind (P) in N_Short_Circuit
9941 and then Desc = Right_Opnd (P))
9942 or else (Nkind (P) = N_Conditional_Expression
9943 and then Desc /= First (Expressions (P)))
9944 or else Nkind (P) = N_Exception_Handler
9945 or else Nkind (P) = N_Selective_Accept
9946 or else Nkind (P) = N_Conditional_Entry_Call
9947 or else Nkind (P) = N_Timed_Entry_Call
9948 or else Nkind (P) = N_Asynchronous_Select
9958 -- OK, looks safe to set value
9961 end Safe_To_Capture_Value;
9967 function Same_Name (N1, N2 : Node_Id) return Boolean is
9968 K1 : constant Node_Kind := Nkind (N1);
9969 K2 : constant Node_Kind := Nkind (N2);
9972 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
9973 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
9975 return Chars (N1) = Chars (N2);
9977 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
9978 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
9980 return Same_Name (Selector_Name (N1), Selector_Name (N2))
9981 and then Same_Name (Prefix (N1), Prefix (N2));
9992 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9993 N1 : constant Node_Id := Original_Node (Node1);
9994 N2 : constant Node_Id := Original_Node (Node2);
9995 -- We do the tests on original nodes, since we are most interested
9996 -- in the original source, not any expansion that got in the way.
9998 K1 : constant Node_Kind := Nkind (N1);
9999 K2 : constant Node_Kind := Nkind (N2);
10002 -- First case, both are entities with same entity
10004 if K1 in N_Has_Entity
10005 and then K2 in N_Has_Entity
10006 and then Present (Entity (N1))
10007 and then Present (Entity (N2))
10008 and then (Ekind (Entity (N1)) = E_Variable
10010 Ekind (Entity (N1)) = E_Constant)
10011 and then Entity (N1) = Entity (N2)
10015 -- Second case, selected component with same selector, same record
10017 elsif K1 = N_Selected_Component
10018 and then K2 = N_Selected_Component
10019 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10021 return Same_Object (Prefix (N1), Prefix (N2));
10023 -- Third case, indexed component with same subscripts, same array
10025 elsif K1 = N_Indexed_Component
10026 and then K2 = N_Indexed_Component
10027 and then Same_Object (Prefix (N1), Prefix (N2))
10032 E1 := First (Expressions (N1));
10033 E2 := First (Expressions (N2));
10034 while Present (E1) loop
10035 if not Same_Value (E1, E2) then
10046 -- Fourth case, slice of same array with same bounds
10049 and then K2 = N_Slice
10050 and then Nkind (Discrete_Range (N1)) = N_Range
10051 and then Nkind (Discrete_Range (N2)) = N_Range
10052 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10053 Low_Bound (Discrete_Range (N2)))
10054 and then Same_Value (High_Bound (Discrete_Range (N1)),
10055 High_Bound (Discrete_Range (N2)))
10057 return Same_Name (Prefix (N1), Prefix (N2));
10059 -- All other cases, not clearly the same object
10070 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10075 elsif not Is_Constrained (T1)
10076 and then not Is_Constrained (T2)
10077 and then Base_Type (T1) = Base_Type (T2)
10081 -- For now don't bother with case of identical constraints, to be
10082 -- fiddled with later on perhaps (this is only used for optimization
10083 -- purposes, so it is not critical to do a best possible job)
10094 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10096 if Compile_Time_Known_Value (Node1)
10097 and then Compile_Time_Known_Value (Node2)
10098 and then Expr_Value (Node1) = Expr_Value (Node2)
10101 elsif Same_Object (Node1, Node2) then
10108 ------------------------
10109 -- Scope_Is_Transient --
10110 ------------------------
10112 function Scope_Is_Transient return Boolean is
10114 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10115 end Scope_Is_Transient;
10121 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10126 while Scop /= Standard_Standard loop
10127 Scop := Scope (Scop);
10129 if Scop = Scope2 then
10137 --------------------------
10138 -- Scope_Within_Or_Same --
10139 --------------------------
10141 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10146 while Scop /= Standard_Standard loop
10147 if Scop = Scope2 then
10150 Scop := Scope (Scop);
10155 end Scope_Within_Or_Same;
10157 --------------------
10158 -- Set_Convention --
10159 --------------------
10161 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10163 Basic_Set_Convention (E, Val);
10166 and then Is_Access_Subprogram_Type (Base_Type (E))
10167 and then Has_Foreign_Convention (E)
10169 Set_Can_Use_Internal_Rep (E, False);
10171 end Set_Convention;
10173 ------------------------
10174 -- Set_Current_Entity --
10175 ------------------------
10177 -- The given entity is to be set as the currently visible definition
10178 -- of its associated name (i.e. the Node_Id associated with its name).
10179 -- All we have to do is to get the name from the identifier, and
10180 -- then set the associated Node_Id to point to the given entity.
10182 procedure Set_Current_Entity (E : Entity_Id) is
10184 Set_Name_Entity_Id (Chars (E), E);
10185 end Set_Current_Entity;
10187 ---------------------------
10188 -- Set_Debug_Info_Needed --
10189 ---------------------------
10191 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10193 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10194 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10195 -- Used to set debug info in a related node if not set already
10197 --------------------------------------
10198 -- Set_Debug_Info_Needed_If_Not_Set --
10199 --------------------------------------
10201 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10204 and then not Needs_Debug_Info (E)
10206 Set_Debug_Info_Needed (E);
10208 -- For a private type, indicate that the full view also needs
10209 -- debug information.
10212 and then Is_Private_Type (E)
10213 and then Present (Full_View (E))
10215 Set_Debug_Info_Needed (Full_View (E));
10218 end Set_Debug_Info_Needed_If_Not_Set;
10220 -- Start of processing for Set_Debug_Info_Needed
10223 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10224 -- indicates that Debug_Info_Needed is never required for the entity.
10227 or else Debug_Info_Off (T)
10232 -- Set flag in entity itself. Note that we will go through the following
10233 -- circuitry even if the flag is already set on T. That's intentional,
10234 -- it makes sure that the flag will be set in subsidiary entities.
10236 Set_Needs_Debug_Info (T);
10238 -- Set flag on subsidiary entities if not set already
10240 if Is_Object (T) then
10241 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10243 elsif Is_Type (T) then
10244 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10246 if Is_Record_Type (T) then
10248 Ent : Entity_Id := First_Entity (T);
10250 while Present (Ent) loop
10251 Set_Debug_Info_Needed_If_Not_Set (Ent);
10256 elsif Is_Array_Type (T) then
10257 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10260 Indx : Node_Id := First_Index (T);
10262 while Present (Indx) loop
10263 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10264 Indx := Next_Index (Indx);
10268 if Is_Packed (T) then
10269 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10272 elsif Is_Access_Type (T) then
10273 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10275 elsif Is_Private_Type (T) then
10276 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10278 elsif Is_Protected_Type (T) then
10279 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10282 end Set_Debug_Info_Needed;
10284 ---------------------------------
10285 -- Set_Entity_With_Style_Check --
10286 ---------------------------------
10288 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10289 Val_Actual : Entity_Id;
10293 Set_Entity (N, Val);
10296 and then not Suppress_Style_Checks (Val)
10297 and then not In_Instance
10299 if Nkind (N) = N_Identifier then
10301 elsif Nkind (N) = N_Expanded_Name then
10302 Nod := Selector_Name (N);
10307 -- A special situation arises for derived operations, where we want
10308 -- to do the check against the parent (since the Sloc of the derived
10309 -- operation points to the derived type declaration itself).
10312 while not Comes_From_Source (Val_Actual)
10313 and then Nkind (Val_Actual) in N_Entity
10314 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10315 or else Is_Subprogram (Val_Actual)
10316 or else Is_Generic_Subprogram (Val_Actual))
10317 and then Present (Alias (Val_Actual))
10319 Val_Actual := Alias (Val_Actual);
10322 -- Renaming declarations for generic actuals do not come from source,
10323 -- and have a different name from that of the entity they rename, so
10324 -- there is no style check to perform here.
10326 if Chars (Nod) = Chars (Val_Actual) then
10327 Style.Check_Identifier (Nod, Val_Actual);
10331 Set_Entity (N, Val);
10332 end Set_Entity_With_Style_Check;
10334 ------------------------
10335 -- Set_Name_Entity_Id --
10336 ------------------------
10338 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10340 Set_Name_Table_Info (Id, Int (Val));
10341 end Set_Name_Entity_Id;
10343 ---------------------
10344 -- Set_Next_Actual --
10345 ---------------------
10347 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10349 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10350 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10352 end Set_Next_Actual;
10354 ----------------------------------
10355 -- Set_Optimize_Alignment_Flags --
10356 ----------------------------------
10358 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10360 if Optimize_Alignment = 'S' then
10361 Set_Optimize_Alignment_Space (E);
10362 elsif Optimize_Alignment = 'T' then
10363 Set_Optimize_Alignment_Time (E);
10365 end Set_Optimize_Alignment_Flags;
10367 -----------------------
10368 -- Set_Public_Status --
10369 -----------------------
10371 procedure Set_Public_Status (Id : Entity_Id) is
10372 S : constant Entity_Id := Current_Scope;
10374 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10375 -- Determines if E is defined within handled statement sequence or
10376 -- an if statement, returns True if so, False otherwise.
10378 ----------------------
10379 -- Within_HSS_Or_If --
10380 ----------------------
10382 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10385 N := Declaration_Node (E);
10392 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10398 end Within_HSS_Or_If;
10400 -- Start of processing for Set_Public_Status
10403 -- Everything in the scope of Standard is public
10405 if S = Standard_Standard then
10406 Set_Is_Public (Id);
10408 -- Entity is definitely not public if enclosing scope is not public
10410 elsif not Is_Public (S) then
10413 -- An object or function declaration that occurs in a handled sequence
10414 -- of statements or within an if statement is the declaration for a
10415 -- temporary object or local subprogram generated by the expander. It
10416 -- never needs to be made public and furthermore, making it public can
10417 -- cause back end problems.
10419 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10420 N_Function_Specification)
10421 and then Within_HSS_Or_If (Id)
10425 -- Entities in public packages or records are public
10427 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10428 Set_Is_Public (Id);
10430 -- The bounds of an entry family declaration can generate object
10431 -- declarations that are visible to the back-end, e.g. in the
10432 -- the declaration of a composite type that contains tasks.
10434 elsif Is_Concurrent_Type (S)
10435 and then not Has_Completion (S)
10436 and then Nkind (Parent (Id)) = N_Object_Declaration
10438 Set_Is_Public (Id);
10440 end Set_Public_Status;
10442 -----------------------------
10443 -- Set_Referenced_Modified --
10444 -----------------------------
10446 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10450 -- Deal with indexed or selected component where prefix is modified
10452 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
10453 Pref := Prefix (N);
10455 -- If prefix is access type, then it is the designated object that is
10456 -- being modified, which means we have no entity to set the flag on.
10458 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10461 -- Otherwise chase the prefix
10464 Set_Referenced_Modified (Pref, Out_Param);
10467 -- Otherwise see if we have an entity name (only other case to process)
10469 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10470 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10471 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10473 end Set_Referenced_Modified;
10475 ----------------------------
10476 -- Set_Scope_Is_Transient --
10477 ----------------------------
10479 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10481 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10482 end Set_Scope_Is_Transient;
10484 -------------------
10485 -- Set_Size_Info --
10486 -------------------
10488 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10490 -- We copy Esize, but not RM_Size, since in general RM_Size is
10491 -- subtype specific and does not get inherited by all subtypes.
10493 Set_Esize (T1, Esize (T2));
10494 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10496 if Is_Discrete_Or_Fixed_Point_Type (T1)
10498 Is_Discrete_Or_Fixed_Point_Type (T2)
10500 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10503 Set_Alignment (T1, Alignment (T2));
10506 --------------------
10507 -- Static_Integer --
10508 --------------------
10510 function Static_Integer (N : Node_Id) return Uint is
10512 Analyze_And_Resolve (N, Any_Integer);
10515 or else Error_Posted (N)
10516 or else Etype (N) = Any_Type
10521 if Is_Static_Expression (N) then
10522 if not Raises_Constraint_Error (N) then
10523 return Expr_Value (N);
10528 elsif Etype (N) = Any_Type then
10532 Flag_Non_Static_Expr
10533 ("static integer expression required here", N);
10536 end Static_Integer;
10538 --------------------------
10539 -- Statically_Different --
10540 --------------------------
10542 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10543 R1 : constant Node_Id := Get_Referenced_Object (E1);
10544 R2 : constant Node_Id := Get_Referenced_Object (E2);
10546 return Is_Entity_Name (R1)
10547 and then Is_Entity_Name (R2)
10548 and then Entity (R1) /= Entity (R2)
10549 and then not Is_Formal (Entity (R1))
10550 and then not Is_Formal (Entity (R2));
10551 end Statically_Different;
10553 -----------------------------
10554 -- Subprogram_Access_Level --
10555 -----------------------------
10557 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10559 if Present (Alias (Subp)) then
10560 return Subprogram_Access_Level (Alias (Subp));
10562 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10564 end Subprogram_Access_Level;
10570 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10572 if Debug_Flag_W then
10573 for J in 0 .. Scope_Stack.Last loop
10578 Write_Name (Chars (E));
10579 Write_Str (" from ");
10580 Write_Location (Sloc (N));
10585 -----------------------
10586 -- Transfer_Entities --
10587 -----------------------
10589 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10590 Ent : Entity_Id := First_Entity (From);
10597 if (Last_Entity (To)) = Empty then
10598 Set_First_Entity (To, Ent);
10600 Set_Next_Entity (Last_Entity (To), Ent);
10603 Set_Last_Entity (To, Last_Entity (From));
10605 while Present (Ent) loop
10606 Set_Scope (Ent, To);
10608 if not Is_Public (Ent) then
10609 Set_Public_Status (Ent);
10612 and then Ekind (Ent) = E_Record_Subtype
10615 -- The components of the propagated Itype must be public
10621 Comp := First_Entity (Ent);
10622 while Present (Comp) loop
10623 Set_Is_Public (Comp);
10624 Next_Entity (Comp);
10633 Set_First_Entity (From, Empty);
10634 Set_Last_Entity (From, Empty);
10635 end Transfer_Entities;
10637 -----------------------
10638 -- Type_Access_Level --
10639 -----------------------
10641 function Type_Access_Level (Typ : Entity_Id) return Uint is
10645 Btyp := Base_Type (Typ);
10647 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10648 -- simply use the level where the type is declared. This is true for
10649 -- stand-alone object declarations, and for anonymous access types
10650 -- associated with components the level is the same as that of the
10651 -- enclosing composite type. However, special treatment is needed for
10652 -- the cases of access parameters, return objects of an anonymous access
10653 -- type, and, in Ada 95, access discriminants of limited types.
10655 if Ekind (Btyp) in Access_Kind then
10656 if Ekind (Btyp) = E_Anonymous_Access_Type then
10658 -- If the type is a nonlocal anonymous access type (such as for
10659 -- an access parameter) we treat it as being declared at the
10660 -- library level to ensure that names such as X.all'access don't
10661 -- fail static accessibility checks.
10663 if not Is_Local_Anonymous_Access (Typ) then
10664 return Scope_Depth (Standard_Standard);
10666 -- If this is a return object, the accessibility level is that of
10667 -- the result subtype of the enclosing function. The test here is
10668 -- little complicated, because we have to account for extended
10669 -- return statements that have been rewritten as blocks, in which
10670 -- case we have to find and the Is_Return_Object attribute of the
10671 -- itype's associated object. It would be nice to find a way to
10672 -- simplify this test, but it doesn't seem worthwhile to add a new
10673 -- flag just for purposes of this test. ???
10675 elsif Ekind (Scope (Btyp)) = E_Return_Statement
10678 and then Nkind (Associated_Node_For_Itype (Btyp)) =
10679 N_Object_Declaration
10680 and then Is_Return_Object
10681 (Defining_Identifier
10682 (Associated_Node_For_Itype (Btyp))))
10688 Scop := Scope (Scope (Btyp));
10689 while Present (Scop) loop
10690 exit when Ekind (Scop) = E_Function;
10691 Scop := Scope (Scop);
10694 -- Treat the return object's type as having the level of the
10695 -- function's result subtype (as per RM05-6.5(5.3/2)).
10697 return Type_Access_Level (Etype (Scop));
10702 Btyp := Root_Type (Btyp);
10704 -- The accessibility level of anonymous access types associated with
10705 -- discriminants is that of the current instance of the type, and
10706 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10708 -- AI-402: access discriminants have accessibility based on the
10709 -- object rather than the type in Ada 2005, so the above paragraph
10712 -- ??? Needs completion with rules from AI-416
10714 if Ada_Version <= Ada_95
10715 and then Ekind (Typ) = E_Anonymous_Access_Type
10716 and then Present (Associated_Node_For_Itype (Typ))
10717 and then Nkind (Associated_Node_For_Itype (Typ)) =
10718 N_Discriminant_Specification
10720 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
10724 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
10725 end Type_Access_Level;
10727 --------------------
10728 -- Ultimate_Alias --
10729 --------------------
10730 -- To do: add occurrences calling this new subprogram
10732 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
10733 E : Entity_Id := Prim;
10736 while Present (Alias (E)) loop
10741 end Ultimate_Alias;
10743 --------------------------
10744 -- Unit_Declaration_Node --
10745 --------------------------
10747 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
10748 N : Node_Id := Parent (Unit_Id);
10751 -- Predefined operators do not have a full function declaration
10753 if Ekind (Unit_Id) = E_Operator then
10757 -- Isn't there some better way to express the following ???
10759 while Nkind (N) /= N_Abstract_Subprogram_Declaration
10760 and then Nkind (N) /= N_Formal_Package_Declaration
10761 and then Nkind (N) /= N_Function_Instantiation
10762 and then Nkind (N) /= N_Generic_Package_Declaration
10763 and then Nkind (N) /= N_Generic_Subprogram_Declaration
10764 and then Nkind (N) /= N_Package_Declaration
10765 and then Nkind (N) /= N_Package_Body
10766 and then Nkind (N) /= N_Package_Instantiation
10767 and then Nkind (N) /= N_Package_Renaming_Declaration
10768 and then Nkind (N) /= N_Procedure_Instantiation
10769 and then Nkind (N) /= N_Protected_Body
10770 and then Nkind (N) /= N_Subprogram_Declaration
10771 and then Nkind (N) /= N_Subprogram_Body
10772 and then Nkind (N) /= N_Subprogram_Body_Stub
10773 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
10774 and then Nkind (N) /= N_Task_Body
10775 and then Nkind (N) /= N_Task_Type_Declaration
10776 and then Nkind (N) not in N_Formal_Subprogram_Declaration
10777 and then Nkind (N) not in N_Generic_Renaming_Declaration
10780 pragma Assert (Present (N));
10784 end Unit_Declaration_Node;
10786 ------------------------------
10787 -- Universal_Interpretation --
10788 ------------------------------
10790 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
10791 Index : Interp_Index;
10795 -- The argument may be a formal parameter of an operator or subprogram
10796 -- with multiple interpretations, or else an expression for an actual.
10798 if Nkind (Opnd) = N_Defining_Identifier
10799 or else not Is_Overloaded (Opnd)
10801 if Etype (Opnd) = Universal_Integer
10802 or else Etype (Opnd) = Universal_Real
10804 return Etype (Opnd);
10810 Get_First_Interp (Opnd, Index, It);
10811 while Present (It.Typ) loop
10812 if It.Typ = Universal_Integer
10813 or else It.Typ = Universal_Real
10818 Get_Next_Interp (Index, It);
10823 end Universal_Interpretation;
10829 function Unqualify (Expr : Node_Id) return Node_Id is
10831 -- Recurse to handle unlikely case of multiple levels of qualification
10833 if Nkind (Expr) = N_Qualified_Expression then
10834 return Unqualify (Expression (Expr));
10836 -- Normal case, not a qualified expression
10843 ----------------------
10844 -- Within_Init_Proc --
10845 ----------------------
10847 function Within_Init_Proc return Boolean is
10851 S := Current_Scope;
10852 while not Is_Overloadable (S) loop
10853 if S = Standard_Standard then
10860 return Is_Init_Proc (S);
10861 end Within_Init_Proc;
10867 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
10868 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
10869 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
10871 function Has_One_Matching_Field return Boolean;
10872 -- Determines if Expec_Type is a record type with a single component or
10873 -- discriminant whose type matches the found type or is one dimensional
10874 -- array whose component type matches the found type.
10876 ----------------------------
10877 -- Has_One_Matching_Field --
10878 ----------------------------
10880 function Has_One_Matching_Field return Boolean is
10884 if Is_Array_Type (Expec_Type)
10885 and then Number_Dimensions (Expec_Type) = 1
10887 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
10891 elsif not Is_Record_Type (Expec_Type) then
10895 E := First_Entity (Expec_Type);
10900 elsif (Ekind (E) /= E_Discriminant
10901 and then Ekind (E) /= E_Component)
10902 or else (Chars (E) = Name_uTag
10903 or else Chars (E) = Name_uParent)
10912 if not Covers (Etype (E), Found_Type) then
10915 elsif Present (Next_Entity (E)) then
10922 end Has_One_Matching_Field;
10924 -- Start of processing for Wrong_Type
10927 -- Don't output message if either type is Any_Type, or if a message
10928 -- has already been posted for this node. We need to do the latter
10929 -- check explicitly (it is ordinarily done in Errout), because we
10930 -- are using ! to force the output of the error messages.
10932 if Expec_Type = Any_Type
10933 or else Found_Type = Any_Type
10934 or else Error_Posted (Expr)
10938 -- In an instance, there is an ongoing problem with completion of
10939 -- type derived from private types. Their structure is what Gigi
10940 -- expects, but the Etype is the parent type rather than the
10941 -- derived private type itself. Do not flag error in this case. The
10942 -- private completion is an entity without a parent, like an Itype.
10943 -- Similarly, full and partial views may be incorrect in the instance.
10944 -- There is no simple way to insure that it is consistent ???
10946 elsif In_Instance then
10947 if Etype (Etype (Expr)) = Etype (Expected_Type)
10949 (Has_Private_Declaration (Expected_Type)
10950 or else Has_Private_Declaration (Etype (Expr)))
10951 and then No (Parent (Expected_Type))
10957 -- An interesting special check. If the expression is parenthesized
10958 -- and its type corresponds to the type of the sole component of the
10959 -- expected record type, or to the component type of the expected one
10960 -- dimensional array type, then assume we have a bad aggregate attempt.
10962 if Nkind (Expr) in N_Subexpr
10963 and then Paren_Count (Expr) /= 0
10964 and then Has_One_Matching_Field
10966 Error_Msg_N ("positional aggregate cannot have one component", Expr);
10968 -- Another special check, if we are looking for a pool-specific access
10969 -- type and we found an E_Access_Attribute_Type, then we have the case
10970 -- of an Access attribute being used in a context which needs a pool-
10971 -- specific type, which is never allowed. The one extra check we make
10972 -- is that the expected designated type covers the Found_Type.
10974 elsif Is_Access_Type (Expec_Type)
10975 and then Ekind (Found_Type) = E_Access_Attribute_Type
10976 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
10977 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
10979 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
10981 Error_Msg_N ("result must be general access type!", Expr);
10982 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
10984 -- Another special check, if the expected type is an integer type,
10985 -- but the expression is of type System.Address, and the parent is
10986 -- an addition or subtraction operation whose left operand is the
10987 -- expression in question and whose right operand is of an integral
10988 -- type, then this is an attempt at address arithmetic, so give
10989 -- appropriate message.
10991 elsif Is_Integer_Type (Expec_Type)
10992 and then Is_RTE (Found_Type, RE_Address)
10993 and then (Nkind (Parent (Expr)) = N_Op_Add
10995 Nkind (Parent (Expr)) = N_Op_Subtract)
10996 and then Expr = Left_Opnd (Parent (Expr))
10997 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11000 ("address arithmetic not predefined in package System",
11003 ("\possible missing with/use of System.Storage_Elements",
11007 -- If the expected type is an anonymous access type, as for access
11008 -- parameters and discriminants, the error is on the designated types.
11010 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11011 if Comes_From_Source (Expec_Type) then
11012 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11015 ("expected an access type with designated}",
11016 Expr, Designated_Type (Expec_Type));
11019 if Is_Access_Type (Found_Type)
11020 and then not Comes_From_Source (Found_Type)
11023 ("\\found an access type with designated}!",
11024 Expr, Designated_Type (Found_Type));
11026 if From_With_Type (Found_Type) then
11027 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11028 Error_Msg_Qual_Level := 99;
11029 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
11030 Error_Msg_Qual_Level := 0;
11032 Error_Msg_NE ("found}!", Expr, Found_Type);
11036 -- Normal case of one type found, some other type expected
11039 -- If the names of the two types are the same, see if some number
11040 -- of levels of qualification will help. Don't try more than three
11041 -- levels, and if we get to standard, it's no use (and probably
11042 -- represents an error in the compiler) Also do not bother with
11043 -- internal scope names.
11046 Expec_Scope : Entity_Id;
11047 Found_Scope : Entity_Id;
11050 Expec_Scope := Expec_Type;
11051 Found_Scope := Found_Type;
11053 for Levels in Int range 0 .. 3 loop
11054 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11055 Error_Msg_Qual_Level := Levels;
11059 Expec_Scope := Scope (Expec_Scope);
11060 Found_Scope := Scope (Found_Scope);
11062 exit when Expec_Scope = Standard_Standard
11063 or else Found_Scope = Standard_Standard
11064 or else not Comes_From_Source (Expec_Scope)
11065 or else not Comes_From_Source (Found_Scope);
11069 if Is_Record_Type (Expec_Type)
11070 and then Present (Corresponding_Remote_Type (Expec_Type))
11072 Error_Msg_NE ("expected}!", Expr,
11073 Corresponding_Remote_Type (Expec_Type));
11075 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11078 if Is_Entity_Name (Expr)
11079 and then Is_Package_Or_Generic_Package (Entity (Expr))
11081 Error_Msg_N ("\\found package name!", Expr);
11083 elsif Is_Entity_Name (Expr)
11085 (Ekind (Entity (Expr)) = E_Procedure
11087 Ekind (Entity (Expr)) = E_Generic_Procedure)
11089 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11091 ("found procedure name, possibly missing Access attribute!",
11095 ("\\found procedure name instead of function!", Expr);
11098 elsif Nkind (Expr) = N_Function_Call
11099 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11100 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11101 and then No (Parameter_Associations (Expr))
11104 ("found function name, possibly missing Access attribute!",
11107 -- Catch common error: a prefix or infix operator which is not
11108 -- directly visible because the type isn't.
11110 elsif Nkind (Expr) in N_Op
11111 and then Is_Overloaded (Expr)
11112 and then not Is_Immediately_Visible (Expec_Type)
11113 and then not Is_Potentially_Use_Visible (Expec_Type)
11114 and then not In_Use (Expec_Type)
11115 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11118 ("operator of the type is not directly visible!", Expr);
11120 elsif Ekind (Found_Type) = E_Void
11121 and then Present (Parent (Found_Type))
11122 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11124 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11127 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11130 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11131 -- of the same modular type, and (M1 and M2) = 0 was intended.
11133 if Expec_Type = Standard_Boolean
11134 and then Is_Modular_Integer_Type (Found_Type)
11135 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11136 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11139 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11140 L : constant Node_Id := Left_Opnd (Op);
11141 R : constant Node_Id := Right_Opnd (Op);
11143 if Etype (L) = Found_Type
11144 and then Is_Integer_Type (Etype (R))
11147 ("\\possible missing parens for modular operation", Expr);
11152 -- Reset error message qualification indication
11154 Error_Msg_Qual_Level := 0;