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_Disp; use Exp_Disp;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Output; use Output;
42 with Rtsfind; use Rtsfind;
43 with Scans; use Scans;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Attr; use Sem_Attr;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Stand; use Stand;
56 with Stringt; use Stringt;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
60 with Uname; use Uname;
62 with GNAT.HTable; use GNAT.HTable;
63 package body Sem_Util is
65 ----------------------------------------
66 -- Global_Variables for New_Copy_Tree --
67 ----------------------------------------
69 -- These global variables are used by New_Copy_Tree. See description
70 -- of the body of this subprogram for details. Global variables can be
71 -- safely used by New_Copy_Tree, since there is no case of a recursive
72 -- call from the processing inside New_Copy_Tree.
74 NCT_Hash_Threshhold : constant := 20;
75 -- If there are more than this number of pairs of entries in the
76 -- map, then Hash_Tables_Used will be set, and the hash tables will
77 -- be initialized and used for the searches.
79 NCT_Hash_Tables_Used : Boolean := False;
80 -- Set to True if hash tables are in use
82 NCT_Table_Entries : Nat;
83 -- Count entries in table to see if threshhold is reached
85 NCT_Hash_Table_Setup : Boolean := False;
86 -- Set to True if hash table contains data. We set this True if we
87 -- setup the hash table with data, and leave it set permanently
88 -- from then on, this is a signal that second and subsequent users
89 -- of the hash table must clear the old entries before reuse.
91 subtype NCT_Header_Num is Int range 0 .. 511;
92 -- Defines range of headers in hash tables (512 headers)
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 function Build_Component_Subtype
101 T : Entity_Id) return Node_Id;
102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
104 -- Loc is the source location, T is the original subtype.
106 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
107 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
108 -- with discriminants whose default values are static, examine only the
109 -- components in the selected variant to determine whether all of them
112 function Has_Null_Extension (T : Entity_Id) return Boolean;
113 -- T is a derived tagged type. Check whether the type extension is null.
114 -- If the parent type is fully initialized, T can be treated as such.
116 ------------------------------
117 -- Abstract_Interface_List --
118 ------------------------------
120 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
124 if Is_Concurrent_Type (Typ) then
126 -- If we are dealing with a synchronized subtype, go to the base
127 -- type, whose declaration has the interface list.
129 -- Shouldn't this be Declaration_Node???
131 Nod := Parent (Base_Type (Typ));
133 if Nkind (Nod) = N_Full_Type_Declaration then
137 elsif Ekind (Typ) = E_Record_Type_With_Private then
138 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
139 Nod := Type_Definition (Parent (Typ));
141 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
142 if Present (Full_View (Typ)) then
143 Nod := Type_Definition (Parent (Full_View (Typ)));
145 -- If the full-view is not available we cannot do anything else
146 -- here (the source has errors).
152 -- Support for generic formals with interfaces is still missing ???
154 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
159 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
163 elsif Ekind (Typ) = E_Record_Subtype then
164 Nod := Type_Definition (Parent (Etype (Typ)));
166 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
168 -- Recurse, because parent may still be a private extension. Also
169 -- note that the full view of the subtype or the full view of its
170 -- base type may (both) be unavailable.
172 return Abstract_Interface_List (Etype (Typ));
174 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
175 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
176 Nod := Formal_Type_Definition (Parent (Typ));
178 Nod := Type_Definition (Parent (Typ));
182 return Interface_List (Nod);
183 end Abstract_Interface_List;
185 --------------------------------
186 -- Add_Access_Type_To_Process --
187 --------------------------------
189 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
193 Ensure_Freeze_Node (E);
194 L := Access_Types_To_Process (Freeze_Node (E));
198 Set_Access_Types_To_Process (Freeze_Node (E), L);
202 end Add_Access_Type_To_Process;
204 ----------------------------
205 -- Add_Global_Declaration --
206 ----------------------------
208 procedure Add_Global_Declaration (N : Node_Id) is
209 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
212 if No (Declarations (Aux_Node)) then
213 Set_Declarations (Aux_Node, New_List);
216 Append_To (Declarations (Aux_Node), N);
218 end Add_Global_Declaration;
220 -----------------------
221 -- Alignment_In_Bits --
222 -----------------------
224 function Alignment_In_Bits (E : Entity_Id) return Uint is
226 return Alignment (E) * System_Storage_Unit;
227 end Alignment_In_Bits;
229 -----------------------------------------
230 -- Apply_Compile_Time_Constraint_Error --
231 -----------------------------------------
233 procedure Apply_Compile_Time_Constraint_Error
236 Reason : RT_Exception_Code;
237 Ent : Entity_Id := Empty;
238 Typ : Entity_Id := Empty;
239 Loc : Source_Ptr := No_Location;
240 Rep : Boolean := True;
241 Warn : Boolean := False)
243 Stat : constant Boolean := Is_Static_Expression (N);
244 R_Stat : constant Node_Id :=
245 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
256 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
262 -- Now we replace the node by an N_Raise_Constraint_Error node
263 -- This does not need reanalyzing, so set it as analyzed now.
266 Set_Analyzed (N, True);
269 Set_Raises_Constraint_Error (N);
271 -- If the original expression was marked as static, the result is
272 -- still marked as static, but the Raises_Constraint_Error flag is
273 -- always set so that further static evaluation is not attempted.
276 Set_Is_Static_Expression (N);
278 end Apply_Compile_Time_Constraint_Error;
280 --------------------------
281 -- Build_Actual_Subtype --
282 --------------------------
284 function Build_Actual_Subtype
286 N : Node_Or_Entity_Id) return Node_Id
289 -- Normally Sloc (N), but may point to corresponding body in some cases
291 Constraints : List_Id;
297 Disc_Type : Entity_Id;
303 if Nkind (N) = N_Defining_Identifier then
304 Obj := New_Reference_To (N, Loc);
306 -- If this is a formal parameter of a subprogram declaration, and
307 -- we are compiling the body, we want the declaration for the
308 -- actual subtype to carry the source position of the body, to
309 -- prevent anomalies in gdb when stepping through the code.
311 if Is_Formal (N) then
313 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
315 if Nkind (Decl) = N_Subprogram_Declaration
316 and then Present (Corresponding_Body (Decl))
318 Loc := Sloc (Corresponding_Body (Decl));
327 if Is_Array_Type (T) then
328 Constraints := New_List;
329 for J in 1 .. Number_Dimensions (T) loop
331 -- Build an array subtype declaration with the nominal subtype and
332 -- the bounds of the actual. Add the declaration in front of the
333 -- local declarations for the subprogram, for analysis before any
334 -- reference to the formal in the body.
337 Make_Attribute_Reference (Loc,
339 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
340 Attribute_Name => Name_First,
341 Expressions => New_List (
342 Make_Integer_Literal (Loc, J)));
345 Make_Attribute_Reference (Loc,
347 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
348 Attribute_Name => Name_Last,
349 Expressions => New_List (
350 Make_Integer_Literal (Loc, J)));
352 Append (Make_Range (Loc, Lo, Hi), Constraints);
355 -- If the type has unknown discriminants there is no constrained
356 -- subtype to build. This is never called for a formal or for a
357 -- lhs, so returning the type is ok ???
359 elsif Has_Unknown_Discriminants (T) then
363 Constraints := New_List;
365 -- Type T is a generic derived type, inherit the discriminants from
368 if Is_Private_Type (T)
369 and then No (Full_View (T))
371 -- T was flagged as an error if it was declared as a formal
372 -- derived type with known discriminants. In this case there
373 -- is no need to look at the parent type since T already carries
374 -- its own discriminants.
376 and then not Error_Posted (T)
378 Disc_Type := Etype (Base_Type (T));
383 Discr := First_Discriminant (Disc_Type);
384 while Present (Discr) loop
385 Append_To (Constraints,
386 Make_Selected_Component (Loc,
388 Duplicate_Subexpr_No_Checks (Obj),
389 Selector_Name => New_Occurrence_Of (Discr, Loc)));
390 Next_Discriminant (Discr);
395 Make_Defining_Identifier (Loc,
396 Chars => New_Internal_Name ('S'));
397 Set_Is_Internal (Subt);
400 Make_Subtype_Declaration (Loc,
401 Defining_Identifier => Subt,
402 Subtype_Indication =>
403 Make_Subtype_Indication (Loc,
404 Subtype_Mark => New_Reference_To (T, Loc),
406 Make_Index_Or_Discriminant_Constraint (Loc,
407 Constraints => Constraints)));
409 Mark_Rewrite_Insertion (Decl);
411 end Build_Actual_Subtype;
413 ---------------------------------------
414 -- Build_Actual_Subtype_Of_Component --
415 ---------------------------------------
417 function Build_Actual_Subtype_Of_Component
419 N : Node_Id) return Node_Id
421 Loc : constant Source_Ptr := Sloc (N);
422 P : constant Node_Id := Prefix (N);
425 Indx_Type : Entity_Id;
427 Deaccessed_T : Entity_Id;
428 -- This is either a copy of T, or if T is an access type, then it is
429 -- the directly designated type of this access type.
431 function Build_Actual_Array_Constraint return List_Id;
432 -- If one or more of the bounds of the component depends on
433 -- discriminants, build actual constraint using the discriminants
436 function Build_Actual_Record_Constraint return List_Id;
437 -- Similar to previous one, for discriminated components constrained
438 -- by the discriminant of the enclosing object.
440 -----------------------------------
441 -- Build_Actual_Array_Constraint --
442 -----------------------------------
444 function Build_Actual_Array_Constraint return List_Id is
445 Constraints : constant List_Id := New_List;
453 Indx := First_Index (Deaccessed_T);
454 while Present (Indx) loop
455 Old_Lo := Type_Low_Bound (Etype (Indx));
456 Old_Hi := Type_High_Bound (Etype (Indx));
458 if Denotes_Discriminant (Old_Lo) then
460 Make_Selected_Component (Loc,
461 Prefix => New_Copy_Tree (P),
462 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
465 Lo := New_Copy_Tree (Old_Lo);
467 -- The new bound will be reanalyzed in the enclosing
468 -- declaration. For literal bounds that come from a type
469 -- declaration, the type of the context must be imposed, so
470 -- insure that analysis will take place. For non-universal
471 -- types this is not strictly necessary.
473 Set_Analyzed (Lo, False);
476 if Denotes_Discriminant (Old_Hi) then
478 Make_Selected_Component (Loc,
479 Prefix => New_Copy_Tree (P),
480 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
483 Hi := New_Copy_Tree (Old_Hi);
484 Set_Analyzed (Hi, False);
487 Append (Make_Range (Loc, Lo, Hi), Constraints);
492 end Build_Actual_Array_Constraint;
494 ------------------------------------
495 -- Build_Actual_Record_Constraint --
496 ------------------------------------
498 function Build_Actual_Record_Constraint return List_Id is
499 Constraints : constant List_Id := New_List;
504 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
505 while Present (D) loop
506 if Denotes_Discriminant (Node (D)) then
507 D_Val := Make_Selected_Component (Loc,
508 Prefix => New_Copy_Tree (P),
509 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
512 D_Val := New_Copy_Tree (Node (D));
515 Append (D_Val, Constraints);
520 end Build_Actual_Record_Constraint;
522 -- Start of processing for Build_Actual_Subtype_Of_Component
525 -- Why the test for Spec_Expression mode here???
527 if In_Spec_Expression then
530 -- More comments for the rest of this body would be good ???
532 elsif Nkind (N) = N_Explicit_Dereference then
533 if Is_Composite_Type (T)
534 and then not Is_Constrained (T)
535 and then not (Is_Class_Wide_Type (T)
536 and then Is_Constrained (Root_Type (T)))
537 and then not Has_Unknown_Discriminants (T)
539 -- If the type of the dereference is already constrained, it
540 -- is an actual subtype.
542 if Is_Array_Type (Etype (N))
543 and then Is_Constrained (Etype (N))
547 Remove_Side_Effects (P);
548 return Build_Actual_Subtype (T, N);
555 if Ekind (T) = E_Access_Subtype then
556 Deaccessed_T := Designated_Type (T);
561 if Ekind (Deaccessed_T) = E_Array_Subtype then
562 Id := First_Index (Deaccessed_T);
563 while Present (Id) loop
564 Indx_Type := Underlying_Type (Etype (Id));
566 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
568 Denotes_Discriminant (Type_High_Bound (Indx_Type))
570 Remove_Side_Effects (P);
572 Build_Component_Subtype
573 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
579 elsif Is_Composite_Type (Deaccessed_T)
580 and then Has_Discriminants (Deaccessed_T)
581 and then not Has_Unknown_Discriminants (Deaccessed_T)
583 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
584 while Present (D) loop
585 if Denotes_Discriminant (Node (D)) then
586 Remove_Side_Effects (P);
588 Build_Component_Subtype (
589 Build_Actual_Record_Constraint, Loc, Base_Type (T));
596 -- If none of the above, the actual and nominal subtypes are the same
599 end Build_Actual_Subtype_Of_Component;
601 -----------------------------
602 -- Build_Component_Subtype --
603 -----------------------------
605 function Build_Component_Subtype
608 T : Entity_Id) return Node_Id
614 -- Unchecked_Union components do not require component subtypes
616 if Is_Unchecked_Union (T) then
621 Make_Defining_Identifier (Loc,
622 Chars => New_Internal_Name ('S'));
623 Set_Is_Internal (Subt);
626 Make_Subtype_Declaration (Loc,
627 Defining_Identifier => Subt,
628 Subtype_Indication =>
629 Make_Subtype_Indication (Loc,
630 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
632 Make_Index_Or_Discriminant_Constraint (Loc,
635 Mark_Rewrite_Insertion (Decl);
637 end Build_Component_Subtype;
639 ---------------------------
640 -- Build_Default_Subtype --
641 ---------------------------
643 function Build_Default_Subtype
645 N : Node_Id) return Entity_Id
647 Loc : constant Source_Ptr := Sloc (N);
651 if not Has_Discriminants (T) or else Is_Constrained (T) then
655 Disc := First_Discriminant (T);
657 if No (Discriminant_Default_Value (Disc)) then
662 Act : constant Entity_Id :=
663 Make_Defining_Identifier (Loc,
664 Chars => New_Internal_Name ('S'));
666 Constraints : constant List_Id := New_List;
670 while Present (Disc) loop
671 Append_To (Constraints,
672 New_Copy_Tree (Discriminant_Default_Value (Disc)));
673 Next_Discriminant (Disc);
677 Make_Subtype_Declaration (Loc,
678 Defining_Identifier => Act,
679 Subtype_Indication =>
680 Make_Subtype_Indication (Loc,
681 Subtype_Mark => New_Occurrence_Of (T, Loc),
683 Make_Index_Or_Discriminant_Constraint (Loc,
684 Constraints => Constraints)));
686 Insert_Action (N, Decl);
690 end Build_Default_Subtype;
692 --------------------------------------------
693 -- Build_Discriminal_Subtype_Of_Component --
694 --------------------------------------------
696 function Build_Discriminal_Subtype_Of_Component
697 (T : Entity_Id) return Node_Id
699 Loc : constant Source_Ptr := Sloc (T);
703 function Build_Discriminal_Array_Constraint return List_Id;
704 -- If one or more of the bounds of the component depends on
705 -- discriminants, build actual constraint using the discriminants
708 function Build_Discriminal_Record_Constraint return List_Id;
709 -- Similar to previous one, for discriminated components constrained
710 -- by the discriminant of the enclosing object.
712 ----------------------------------------
713 -- Build_Discriminal_Array_Constraint --
714 ----------------------------------------
716 function Build_Discriminal_Array_Constraint return List_Id is
717 Constraints : constant List_Id := New_List;
725 Indx := First_Index (T);
726 while Present (Indx) loop
727 Old_Lo := Type_Low_Bound (Etype (Indx));
728 Old_Hi := Type_High_Bound (Etype (Indx));
730 if Denotes_Discriminant (Old_Lo) then
731 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
734 Lo := New_Copy_Tree (Old_Lo);
737 if Denotes_Discriminant (Old_Hi) then
738 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
741 Hi := New_Copy_Tree (Old_Hi);
744 Append (Make_Range (Loc, Lo, Hi), Constraints);
749 end Build_Discriminal_Array_Constraint;
751 -----------------------------------------
752 -- Build_Discriminal_Record_Constraint --
753 -----------------------------------------
755 function Build_Discriminal_Record_Constraint return List_Id is
756 Constraints : constant List_Id := New_List;
761 D := First_Elmt (Discriminant_Constraint (T));
762 while Present (D) loop
763 if Denotes_Discriminant (Node (D)) then
765 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
768 D_Val := New_Copy_Tree (Node (D));
771 Append (D_Val, Constraints);
776 end Build_Discriminal_Record_Constraint;
778 -- Start of processing for Build_Discriminal_Subtype_Of_Component
781 if Ekind (T) = E_Array_Subtype then
782 Id := First_Index (T);
783 while Present (Id) loop
784 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
785 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
787 return Build_Component_Subtype
788 (Build_Discriminal_Array_Constraint, Loc, T);
794 elsif Ekind (T) = E_Record_Subtype
795 and then Has_Discriminants (T)
796 and then not Has_Unknown_Discriminants (T)
798 D := First_Elmt (Discriminant_Constraint (T));
799 while Present (D) loop
800 if Denotes_Discriminant (Node (D)) then
801 return Build_Component_Subtype
802 (Build_Discriminal_Record_Constraint, Loc, T);
809 -- If none of the above, the actual and nominal subtypes are the same
812 end Build_Discriminal_Subtype_Of_Component;
814 ------------------------------
815 -- Build_Elaboration_Entity --
816 ------------------------------
818 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
819 Loc : constant Source_Ptr := Sloc (N);
821 Elab_Ent : Entity_Id;
823 procedure Set_Package_Name (Ent : Entity_Id);
824 -- Given an entity, sets the fully qualified name of the entity in
825 -- Name_Buffer, with components separated by double underscores. This
826 -- is a recursive routine that climbs the scope chain to Standard.
828 ----------------------
829 -- Set_Package_Name --
830 ----------------------
832 procedure Set_Package_Name (Ent : Entity_Id) is
834 if Scope (Ent) /= Standard_Standard then
835 Set_Package_Name (Scope (Ent));
838 Nam : constant String := Get_Name_String (Chars (Ent));
840 Name_Buffer (Name_Len + 1) := '_';
841 Name_Buffer (Name_Len + 2) := '_';
842 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
843 Name_Len := Name_Len + Nam'Length + 2;
847 Get_Name_String (Chars (Ent));
849 end Set_Package_Name;
851 -- Start of processing for Build_Elaboration_Entity
854 -- Ignore if already constructed
856 if Present (Elaboration_Entity (Spec_Id)) then
860 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
861 -- name with dots replaced by double underscore. We have to manually
862 -- construct this name, since it will be elaborated in the outer scope,
863 -- and thus will not have the unit name automatically prepended.
865 Set_Package_Name (Spec_Id);
869 Name_Buffer (Name_Len + 1) := '_';
870 Name_Buffer (Name_Len + 2) := 'E';
871 Name_Len := Name_Len + 2;
873 -- Create elaboration flag
876 Make_Defining_Identifier (Loc, Chars => Name_Find);
877 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
880 Make_Object_Declaration (Loc,
881 Defining_Identifier => Elab_Ent,
883 New_Occurrence_Of (Standard_Boolean, Loc),
885 New_Occurrence_Of (Standard_False, Loc));
887 Push_Scope (Standard_Standard);
888 Add_Global_Declaration (Decl);
891 -- Reset True_Constant indication, since we will indeed assign a value
892 -- to the variable in the binder main. We also kill the Current_Value
893 -- and Last_Assignment fields for the same reason.
895 Set_Is_True_Constant (Elab_Ent, False);
896 Set_Current_Value (Elab_Ent, Empty);
897 Set_Last_Assignment (Elab_Ent, Empty);
899 -- We do not want any further qualification of the name (if we did
900 -- not do this, we would pick up the name of the generic package
901 -- in the case of a library level generic instantiation).
903 Set_Has_Qualified_Name (Elab_Ent);
904 Set_Has_Fully_Qualified_Name (Elab_Ent);
905 end Build_Elaboration_Entity;
907 -----------------------------------
908 -- Cannot_Raise_Constraint_Error --
909 -----------------------------------
911 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
913 if Compile_Time_Known_Value (Expr) then
916 elsif Do_Range_Check (Expr) then
919 elsif Raises_Constraint_Error (Expr) then
927 when N_Expanded_Name =>
930 when N_Selected_Component =>
931 return not Do_Discriminant_Check (Expr);
933 when N_Attribute_Reference =>
934 if Do_Overflow_Check (Expr) then
937 elsif No (Expressions (Expr)) then
945 N := First (Expressions (Expr));
946 while Present (N) loop
947 if Cannot_Raise_Constraint_Error (N) then
958 when N_Type_Conversion =>
959 if Do_Overflow_Check (Expr)
960 or else Do_Length_Check (Expr)
961 or else Do_Tag_Check (Expr)
966 Cannot_Raise_Constraint_Error (Expression (Expr));
969 when N_Unchecked_Type_Conversion =>
970 return Cannot_Raise_Constraint_Error (Expression (Expr));
973 if Do_Overflow_Check (Expr) then
977 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
984 if Do_Division_Check (Expr)
985 or else Do_Overflow_Check (Expr)
990 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
992 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1011 N_Op_Shift_Right_Arithmetic |
1015 if Do_Overflow_Check (Expr) then
1019 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1021 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1028 end Cannot_Raise_Constraint_Error;
1030 --------------------------
1031 -- Check_Fully_Declared --
1032 --------------------------
1034 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1036 if Ekind (T) = E_Incomplete_Type then
1038 -- Ada 2005 (AI-50217): If the type is available through a limited
1039 -- with_clause, verify that its full view has been analyzed.
1041 if From_With_Type (T)
1042 and then Present (Non_Limited_View (T))
1043 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1045 -- The non-limited view is fully declared
1050 ("premature usage of incomplete}", N, First_Subtype (T));
1053 -- Need comments for these tests ???
1055 elsif Has_Private_Component (T)
1056 and then not Is_Generic_Type (Root_Type (T))
1057 and then not In_Spec_Expression
1059 -- Special case: if T is the anonymous type created for a single
1060 -- task or protected object, use the name of the source object.
1062 if Is_Concurrent_Type (T)
1063 and then not Comes_From_Source (T)
1064 and then Nkind (N) = N_Object_Declaration
1066 Error_Msg_NE ("type of& has incomplete component", N,
1067 Defining_Identifier (N));
1071 ("premature usage of incomplete}", N, First_Subtype (T));
1074 end Check_Fully_Declared;
1076 -------------------------
1077 -- Check_Nested_Access --
1078 -------------------------
1080 procedure Check_Nested_Access (Ent : Entity_Id) is
1081 Scop : constant Entity_Id := Current_Scope;
1082 Current_Subp : Entity_Id;
1083 Enclosing : Entity_Id;
1086 -- Currently only enabled for VM back-ends for efficiency, should we
1087 -- enable it more systematically ???
1089 -- Check for Is_Imported needs commenting below ???
1091 if VM_Target /= No_VM
1092 and then (Ekind (Ent) = E_Variable
1094 Ekind (Ent) = E_Constant
1096 Ekind (Ent) = E_Loop_Parameter)
1097 and then Scope (Ent) /= Empty
1098 and then not Is_Library_Level_Entity (Ent)
1099 and then not Is_Imported (Ent)
1101 if Is_Subprogram (Scop)
1102 or else Is_Generic_Subprogram (Scop)
1103 or else Is_Entry (Scop)
1105 Current_Subp := Scop;
1107 Current_Subp := Current_Subprogram;
1110 Enclosing := Enclosing_Subprogram (Ent);
1112 if Enclosing /= Empty
1113 and then Enclosing /= Current_Subp
1115 Set_Has_Up_Level_Access (Ent, True);
1118 end Check_Nested_Access;
1120 ------------------------------------------
1121 -- Check_Potentially_Blocking_Operation --
1122 ------------------------------------------
1124 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1127 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1128 -- When pragma Detect_Blocking is active, the run time will raise
1129 -- Program_Error. Here we only issue a warning, since we generally
1130 -- support the use of potentially blocking operations in the absence
1133 -- Indirect blocking through a subprogram call cannot be diagnosed
1134 -- statically without interprocedural analysis, so we do not attempt
1137 S := Scope (Current_Scope);
1138 while Present (S) and then S /= Standard_Standard loop
1139 if Is_Protected_Type (S) then
1141 ("potentially blocking operation in protected operation?", N);
1148 end Check_Potentially_Blocking_Operation;
1150 ------------------------------
1151 -- Check_Unprotected_Access --
1152 ------------------------------
1154 procedure Check_Unprotected_Access
1158 Cont_Encl_Typ : Entity_Id;
1159 Pref_Encl_Typ : Entity_Id;
1161 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1162 -- Check whether Obj is a private component of a protected object.
1163 -- Return the protected type where the component resides, Empty
1166 function Is_Public_Operation return Boolean;
1167 -- Verify that the enclosing operation is callable from outside the
1168 -- protected object, to minimize false positives.
1170 ------------------------------
1171 -- Enclosing_Protected_Type --
1172 ------------------------------
1174 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1176 if Is_Entity_Name (Obj) then
1178 Ent : Entity_Id := Entity (Obj);
1181 -- The object can be a renaming of a private component, use
1182 -- the original record component.
1184 if Is_Prival (Ent) then
1185 Ent := Prival_Link (Ent);
1188 if Is_Protected_Type (Scope (Ent)) then
1194 -- For indexed and selected components, recursively check the prefix
1196 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1197 return Enclosing_Protected_Type (Prefix (Obj));
1199 -- The object does not denote a protected component
1204 end Enclosing_Protected_Type;
1206 -------------------------
1207 -- Is_Public_Operation --
1208 -------------------------
1210 function Is_Public_Operation return Boolean is
1217 and then S /= Pref_Encl_Typ
1219 if Scope (S) = Pref_Encl_Typ then
1220 E := First_Entity (Pref_Encl_Typ);
1222 and then E /= First_Private_Entity (Pref_Encl_Typ)
1235 end Is_Public_Operation;
1237 -- Start of processing for Check_Unprotected_Access
1240 if Nkind (Expr) = N_Attribute_Reference
1241 and then Attribute_Name (Expr) = Name_Unchecked_Access
1243 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1244 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1246 -- Check whether we are trying to export a protected component to a
1247 -- context with an equal or lower access level.
1249 if Present (Pref_Encl_Typ)
1250 and then No (Cont_Encl_Typ)
1251 and then Is_Public_Operation
1252 and then Scope_Depth (Pref_Encl_Typ) >=
1253 Object_Access_Level (Context)
1256 ("?possible unprotected access to protected data", Expr);
1259 end Check_Unprotected_Access;
1265 procedure Check_VMS (Construct : Node_Id) is
1267 if not OpenVMS_On_Target then
1269 ("this construct is allowed only in Open'V'M'S", Construct);
1273 ------------------------
1274 -- Collect_Interfaces --
1275 ------------------------
1277 procedure Collect_Interfaces
1279 Ifaces_List : out Elist_Id;
1280 Exclude_Parents : Boolean := False;
1281 Use_Full_View : Boolean := True)
1283 procedure Collect (Typ : Entity_Id);
1284 -- Subsidiary subprogram used to traverse the whole list
1285 -- of directly and indirectly implemented interfaces
1291 procedure Collect (Typ : Entity_Id) is
1292 Ancestor : Entity_Id;
1300 -- Handle private types
1303 and then Is_Private_Type (Typ)
1304 and then Present (Full_View (Typ))
1306 Full_T := Full_View (Typ);
1309 -- Include the ancestor if we are generating the whole list of
1310 -- abstract interfaces.
1312 if Etype (Full_T) /= Typ
1314 -- Protect the frontend against wrong sources. For example:
1317 -- type A is tagged null record;
1318 -- type B is new A with private;
1319 -- type C is new A with private;
1321 -- type B is new C with null record;
1322 -- type C is new B with null record;
1325 and then Etype (Full_T) /= T
1327 Ancestor := Etype (Full_T);
1330 if Is_Interface (Ancestor)
1331 and then not Exclude_Parents
1333 Append_Unique_Elmt (Ancestor, Ifaces_List);
1337 -- Traverse the graph of ancestor interfaces
1339 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1340 Id := First (Abstract_Interface_List (Full_T));
1341 while Present (Id) loop
1342 Iface := Etype (Id);
1344 -- Protect against wrong uses. For example:
1345 -- type I is interface;
1346 -- type O is tagged null record;
1347 -- type Wrong is new I and O with null record; -- ERROR
1349 if Is_Interface (Iface) then
1351 and then Etype (T) /= T
1352 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1357 Append_Unique_Elmt (Iface, Ifaces_List);
1366 -- Start of processing for Collect_Interfaces
1369 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1370 Ifaces_List := New_Elmt_List;
1372 end Collect_Interfaces;
1374 ----------------------------------
1375 -- Collect_Interface_Components --
1376 ----------------------------------
1378 procedure Collect_Interface_Components
1379 (Tagged_Type : Entity_Id;
1380 Components_List : out Elist_Id)
1382 procedure Collect (Typ : Entity_Id);
1383 -- Subsidiary subprogram used to climb to the parents
1389 procedure Collect (Typ : Entity_Id) is
1390 Tag_Comp : Entity_Id;
1391 Parent_Typ : Entity_Id;
1394 -- Handle private types
1396 if Present (Full_View (Etype (Typ))) then
1397 Parent_Typ := Full_View (Etype (Typ));
1399 Parent_Typ := Etype (Typ);
1402 if Parent_Typ /= Typ
1404 -- Protect the frontend against wrong sources. For example:
1407 -- type A is tagged null record;
1408 -- type B is new A with private;
1409 -- type C is new A with private;
1411 -- type B is new C with null record;
1412 -- type C is new B with null record;
1415 and then Parent_Typ /= Tagged_Type
1417 Collect (Parent_Typ);
1420 -- Collect the components containing tags of secondary dispatch
1423 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1424 while Present (Tag_Comp) loop
1425 pragma Assert (Present (Related_Type (Tag_Comp)));
1426 Append_Elmt (Tag_Comp, Components_List);
1428 Tag_Comp := Next_Tag_Component (Tag_Comp);
1432 -- Start of processing for Collect_Interface_Components
1435 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1436 and then Is_Tagged_Type (Tagged_Type));
1438 Components_List := New_Elmt_List;
1439 Collect (Tagged_Type);
1440 end Collect_Interface_Components;
1442 -----------------------------
1443 -- Collect_Interfaces_Info --
1444 -----------------------------
1446 procedure Collect_Interfaces_Info
1448 Ifaces_List : out Elist_Id;
1449 Components_List : out Elist_Id;
1450 Tags_List : out Elist_Id)
1452 Comps_List : Elist_Id;
1453 Comp_Elmt : Elmt_Id;
1454 Comp_Iface : Entity_Id;
1455 Iface_Elmt : Elmt_Id;
1458 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1459 -- Search for the secondary tag associated with the interface type
1460 -- Iface that is implemented by T.
1466 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1470 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1472 and then Ekind (Node (ADT)) = E_Constant
1473 and then Related_Type (Node (ADT)) /= Iface
1475 -- Skip the secondary dispatch tables of Iface
1483 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1487 -- Start of processing for Collect_Interfaces_Info
1490 Collect_Interfaces (T, Ifaces_List);
1491 Collect_Interface_Components (T, Comps_List);
1493 -- Search for the record component and tag associated with each
1494 -- interface type of T.
1496 Components_List := New_Elmt_List;
1497 Tags_List := New_Elmt_List;
1499 Iface_Elmt := First_Elmt (Ifaces_List);
1500 while Present (Iface_Elmt) loop
1501 Iface := Node (Iface_Elmt);
1503 -- Associate the primary tag component and the primary dispatch table
1504 -- with all the interfaces that are parents of T
1506 if Is_Ancestor (Iface, T) then
1507 Append_Elmt (First_Tag_Component (T), Components_List);
1508 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1510 -- Otherwise search for the tag component and secondary dispatch
1514 Comp_Elmt := First_Elmt (Comps_List);
1515 while Present (Comp_Elmt) loop
1516 Comp_Iface := Related_Type (Node (Comp_Elmt));
1518 if Comp_Iface = Iface
1519 or else Is_Ancestor (Iface, Comp_Iface)
1521 Append_Elmt (Node (Comp_Elmt), Components_List);
1522 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1526 Next_Elmt (Comp_Elmt);
1528 pragma Assert (Present (Comp_Elmt));
1531 Next_Elmt (Iface_Elmt);
1533 end Collect_Interfaces_Info;
1535 ----------------------------------
1536 -- Collect_Primitive_Operations --
1537 ----------------------------------
1539 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1540 B_Type : constant Entity_Id := Base_Type (T);
1541 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1542 B_Scope : Entity_Id := Scope (B_Type);
1546 Formal_Derived : Boolean := False;
1550 -- For tagged types, the primitive operations are collected as they
1551 -- are declared, and held in an explicit list which is simply returned.
1553 if Is_Tagged_Type (B_Type) then
1554 return Primitive_Operations (B_Type);
1556 -- An untagged generic type that is a derived type inherits the
1557 -- primitive operations of its parent type. Other formal types only
1558 -- have predefined operators, which are not explicitly represented.
1560 elsif Is_Generic_Type (B_Type) then
1561 if Nkind (B_Decl) = N_Formal_Type_Declaration
1562 and then Nkind (Formal_Type_Definition (B_Decl))
1563 = N_Formal_Derived_Type_Definition
1565 Formal_Derived := True;
1567 return New_Elmt_List;
1571 Op_List := New_Elmt_List;
1573 if B_Scope = Standard_Standard then
1574 if B_Type = Standard_String then
1575 Append_Elmt (Standard_Op_Concat, Op_List);
1577 elsif B_Type = Standard_Wide_String then
1578 Append_Elmt (Standard_Op_Concatw, Op_List);
1584 elsif (Is_Package_Or_Generic_Package (B_Scope)
1586 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1588 or else Is_Derived_Type (B_Type)
1590 -- The primitive operations appear after the base type, except
1591 -- if the derivation happens within the private part of B_Scope
1592 -- and the type is a private type, in which case both the type
1593 -- and some primitive operations may appear before the base
1594 -- type, and the list of candidates starts after the type.
1596 if In_Open_Scopes (B_Scope)
1597 and then Scope (T) = B_Scope
1598 and then In_Private_Part (B_Scope)
1600 Id := Next_Entity (T);
1602 Id := Next_Entity (B_Type);
1605 while Present (Id) loop
1607 -- Note that generic formal subprograms are not
1608 -- considered to be primitive operations and thus
1609 -- are never inherited.
1611 if Is_Overloadable (Id)
1612 and then Nkind (Parent (Parent (Id)))
1613 not in N_Formal_Subprogram_Declaration
1617 if Base_Type (Etype (Id)) = B_Type then
1620 Formal := First_Formal (Id);
1621 while Present (Formal) loop
1622 if Base_Type (Etype (Formal)) = B_Type then
1626 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1628 (Designated_Type (Etype (Formal))) = B_Type
1634 Next_Formal (Formal);
1638 -- For a formal derived type, the only primitives are the
1639 -- ones inherited from the parent type. Operations appearing
1640 -- in the package declaration are not primitive for it.
1643 and then (not Formal_Derived
1644 or else Present (Alias (Id)))
1646 Append_Elmt (Id, Op_List);
1652 -- For a type declared in System, some of its operations
1653 -- may appear in the target-specific extension to System.
1656 and then Chars (B_Scope) = Name_System
1657 and then Scope (B_Scope) = Standard_Standard
1658 and then Present_System_Aux
1660 B_Scope := System_Aux_Id;
1661 Id := First_Entity (System_Aux_Id);
1667 end Collect_Primitive_Operations;
1669 -----------------------------------
1670 -- Compile_Time_Constraint_Error --
1671 -----------------------------------
1673 function Compile_Time_Constraint_Error
1676 Ent : Entity_Id := Empty;
1677 Loc : Source_Ptr := No_Location;
1678 Warn : Boolean := False) return Node_Id
1680 Msgc : String (1 .. Msg'Length + 2);
1681 -- Copy of message, with room for possible ? and ! at end
1691 -- A static constraint error in an instance body is not a fatal error.
1692 -- we choose to inhibit the message altogether, because there is no
1693 -- obvious node (for now) on which to post it. On the other hand the
1694 -- offending node must be replaced with a constraint_error in any case.
1696 -- No messages are generated if we already posted an error on this node
1698 if not Error_Posted (N) then
1699 if Loc /= No_Location then
1705 Msgc (1 .. Msg'Length) := Msg;
1708 -- Message is a warning, even in Ada 95 case
1710 if Msg (Msg'Last) = '?' then
1713 -- In Ada 83, all messages are warnings. In the private part and
1714 -- the body of an instance, constraint_checks are only warnings.
1715 -- We also make this a warning if the Warn parameter is set.
1718 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1724 elsif In_Instance_Not_Visible then
1729 -- Otherwise we have a real error message (Ada 95 static case)
1730 -- and we make this an unconditional message. Note that in the
1731 -- warning case we do not make the message unconditional, it seems
1732 -- quite reasonable to delete messages like this (about exceptions
1733 -- that will be raised) in dead code.
1741 -- Should we generate a warning? The answer is not quite yes. The
1742 -- very annoying exception occurs in the case of a short circuit
1743 -- operator where the left operand is static and decisive. Climb
1744 -- parents to see if that is the case we have here. Conditional
1745 -- expressions with decisive conditions are a similar situation.
1753 -- And then with False as left operand
1755 if Nkind (P) = N_And_Then
1756 and then Compile_Time_Known_Value (Left_Opnd (P))
1757 and then Is_False (Expr_Value (Left_Opnd (P)))
1762 -- OR ELSE with True as left operand
1764 elsif Nkind (P) = N_Or_Else
1765 and then Compile_Time_Known_Value (Left_Opnd (P))
1766 and then Is_True (Expr_Value (Left_Opnd (P)))
1771 -- Conditional expression
1773 elsif Nkind (P) = N_Conditional_Expression then
1775 Cond : constant Node_Id := First (Expressions (P));
1776 Texp : constant Node_Id := Next (Cond);
1777 Fexp : constant Node_Id := Next (Texp);
1780 if Compile_Time_Known_Value (Cond) then
1782 -- Condition is True and we are in the right operand
1784 if Is_True (Expr_Value (Cond))
1785 and then OldP = Fexp
1790 -- Condition is False and we are in the left operand
1792 elsif Is_False (Expr_Value (Cond))
1793 and then OldP = Texp
1801 -- Special case for component association in aggregates, where
1802 -- we want to keep climbing up to the parent aggregate.
1804 elsif Nkind (P) = N_Component_Association
1805 and then Nkind (Parent (P)) = N_Aggregate
1809 -- Keep going if within subexpression
1812 exit when Nkind (P) not in N_Subexpr;
1817 if Present (Ent) then
1818 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1820 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1824 if Inside_Init_Proc then
1826 ("\?& will be raised for objects of this type",
1827 N, Standard_Constraint_Error, Eloc);
1830 ("\?& will be raised at run time",
1831 N, Standard_Constraint_Error, Eloc);
1836 ("\static expression fails Constraint_Check", Eloc);
1837 Set_Error_Posted (N);
1843 end Compile_Time_Constraint_Error;
1845 -----------------------
1846 -- Conditional_Delay --
1847 -----------------------
1849 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1851 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1852 Set_Has_Delayed_Freeze (New_Ent);
1854 end Conditional_Delay;
1856 -------------------------
1857 -- Copy_Parameter_List --
1858 -------------------------
1860 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1861 Loc : constant Source_Ptr := Sloc (Subp_Id);
1866 if No (First_Formal (Subp_Id)) then
1870 Formal := First_Formal (Subp_Id);
1871 while Present (Formal) loop
1873 (Make_Parameter_Specification (Loc,
1874 Defining_Identifier =>
1875 Make_Defining_Identifier (Sloc (Formal),
1876 Chars => Chars (Formal)),
1877 In_Present => In_Present (Parent (Formal)),
1878 Out_Present => Out_Present (Parent (Formal)),
1880 New_Reference_To (Etype (Formal), Loc),
1882 New_Copy_Tree (Expression (Parent (Formal)))),
1885 Next_Formal (Formal);
1890 end Copy_Parameter_List;
1892 --------------------
1893 -- Current_Entity --
1894 --------------------
1896 -- The currently visible definition for a given identifier is the
1897 -- one most chained at the start of the visibility chain, i.e. the
1898 -- one that is referenced by the Node_Id value of the name of the
1899 -- given identifier.
1901 function Current_Entity (N : Node_Id) return Entity_Id is
1903 return Get_Name_Entity_Id (Chars (N));
1906 -----------------------------
1907 -- Current_Entity_In_Scope --
1908 -----------------------------
1910 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1912 CS : constant Entity_Id := Current_Scope;
1914 Transient_Case : constant Boolean := Scope_Is_Transient;
1917 E := Get_Name_Entity_Id (Chars (N));
1919 and then Scope (E) /= CS
1920 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1926 end Current_Entity_In_Scope;
1932 function Current_Scope return Entity_Id is
1934 if Scope_Stack.Last = -1 then
1935 return Standard_Standard;
1938 C : constant Entity_Id :=
1939 Scope_Stack.Table (Scope_Stack.Last).Entity;
1944 return Standard_Standard;
1950 ------------------------
1951 -- Current_Subprogram --
1952 ------------------------
1954 function Current_Subprogram return Entity_Id is
1955 Scop : constant Entity_Id := Current_Scope;
1957 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1960 return Enclosing_Subprogram (Scop);
1962 end Current_Subprogram;
1964 ---------------------
1965 -- Defining_Entity --
1966 ---------------------
1968 function Defining_Entity (N : Node_Id) return Entity_Id is
1969 K : constant Node_Kind := Nkind (N);
1970 Err : Entity_Id := Empty;
1975 N_Subprogram_Declaration |
1976 N_Abstract_Subprogram_Declaration |
1978 N_Package_Declaration |
1979 N_Subprogram_Renaming_Declaration |
1980 N_Subprogram_Body_Stub |
1981 N_Generic_Subprogram_Declaration |
1982 N_Generic_Package_Declaration |
1983 N_Formal_Subprogram_Declaration
1985 return Defining_Entity (Specification (N));
1988 N_Component_Declaration |
1989 N_Defining_Program_Unit_Name |
1990 N_Discriminant_Specification |
1992 N_Entry_Declaration |
1993 N_Entry_Index_Specification |
1994 N_Exception_Declaration |
1995 N_Exception_Renaming_Declaration |
1996 N_Formal_Object_Declaration |
1997 N_Formal_Package_Declaration |
1998 N_Formal_Type_Declaration |
1999 N_Full_Type_Declaration |
2000 N_Implicit_Label_Declaration |
2001 N_Incomplete_Type_Declaration |
2002 N_Loop_Parameter_Specification |
2003 N_Number_Declaration |
2004 N_Object_Declaration |
2005 N_Object_Renaming_Declaration |
2006 N_Package_Body_Stub |
2007 N_Parameter_Specification |
2008 N_Private_Extension_Declaration |
2009 N_Private_Type_Declaration |
2011 N_Protected_Body_Stub |
2012 N_Protected_Type_Declaration |
2013 N_Single_Protected_Declaration |
2014 N_Single_Task_Declaration |
2015 N_Subtype_Declaration |
2018 N_Task_Type_Declaration
2020 return Defining_Identifier (N);
2023 return Defining_Entity (Proper_Body (N));
2026 N_Function_Instantiation |
2027 N_Function_Specification |
2028 N_Generic_Function_Renaming_Declaration |
2029 N_Generic_Package_Renaming_Declaration |
2030 N_Generic_Procedure_Renaming_Declaration |
2032 N_Package_Instantiation |
2033 N_Package_Renaming_Declaration |
2034 N_Package_Specification |
2035 N_Procedure_Instantiation |
2036 N_Procedure_Specification
2039 Nam : constant Node_Id := Defining_Unit_Name (N);
2042 if Nkind (Nam) in N_Entity then
2045 -- For Error, make up a name and attach to declaration
2046 -- so we can continue semantic analysis
2048 elsif Nam = Error then
2050 Make_Defining_Identifier (Sloc (N),
2051 Chars => New_Internal_Name ('T'));
2052 Set_Defining_Unit_Name (N, Err);
2055 -- If not an entity, get defining identifier
2058 return Defining_Identifier (Nam);
2062 when N_Block_Statement =>
2063 return Entity (Identifier (N));
2066 raise Program_Error;
2069 end Defining_Entity;
2071 --------------------------
2072 -- Denotes_Discriminant --
2073 --------------------------
2075 function Denotes_Discriminant
2077 Check_Concurrent : Boolean := False) return Boolean
2081 if not Is_Entity_Name (N)
2082 or else No (Entity (N))
2089 -- If we are checking for a protected type, the discriminant may have
2090 -- been rewritten as the corresponding discriminal of the original type
2091 -- or of the corresponding concurrent record, depending on whether we
2092 -- are in the spec or body of the protected type.
2094 return Ekind (E) = E_Discriminant
2097 and then Ekind (E) = E_In_Parameter
2098 and then Present (Discriminal_Link (E))
2100 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2102 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2104 end Denotes_Discriminant;
2106 ----------------------
2107 -- Denotes_Variable --
2108 ----------------------
2110 function Denotes_Variable (N : Node_Id) return Boolean is
2112 return Is_Variable (N) and then Paren_Count (N) = 0;
2113 end Denotes_Variable;
2115 -----------------------------
2116 -- Depends_On_Discriminant --
2117 -----------------------------
2119 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2124 Get_Index_Bounds (N, L, H);
2125 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2126 end Depends_On_Discriminant;
2128 -------------------------
2129 -- Designate_Same_Unit --
2130 -------------------------
2132 function Designate_Same_Unit
2134 Name2 : Node_Id) return Boolean
2136 K1 : constant Node_Kind := Nkind (Name1);
2137 K2 : constant Node_Kind := Nkind (Name2);
2139 function Prefix_Node (N : Node_Id) return Node_Id;
2140 -- Returns the parent unit name node of a defining program unit name
2141 -- or the prefix if N is a selected component or an expanded name.
2143 function Select_Node (N : Node_Id) return Node_Id;
2144 -- Returns the defining identifier node of a defining program unit
2145 -- name or the selector node if N is a selected component or an
2152 function Prefix_Node (N : Node_Id) return Node_Id is
2154 if Nkind (N) = N_Defining_Program_Unit_Name then
2166 function Select_Node (N : Node_Id) return Node_Id is
2168 if Nkind (N) = N_Defining_Program_Unit_Name then
2169 return Defining_Identifier (N);
2172 return Selector_Name (N);
2176 -- Start of processing for Designate_Next_Unit
2179 if (K1 = N_Identifier or else
2180 K1 = N_Defining_Identifier)
2182 (K2 = N_Identifier or else
2183 K2 = N_Defining_Identifier)
2185 return Chars (Name1) = Chars (Name2);
2188 (K1 = N_Expanded_Name or else
2189 K1 = N_Selected_Component or else
2190 K1 = N_Defining_Program_Unit_Name)
2192 (K2 = N_Expanded_Name or else
2193 K2 = N_Selected_Component or else
2194 K2 = N_Defining_Program_Unit_Name)
2197 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2199 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2204 end Designate_Same_Unit;
2206 ----------------------------
2207 -- Enclosing_Generic_Body --
2208 ----------------------------
2210 function Enclosing_Generic_Body
2211 (N : Node_Id) return Node_Id
2219 while Present (P) loop
2220 if Nkind (P) = N_Package_Body
2221 or else Nkind (P) = N_Subprogram_Body
2223 Spec := Corresponding_Spec (P);
2225 if Present (Spec) then
2226 Decl := Unit_Declaration_Node (Spec);
2228 if Nkind (Decl) = N_Generic_Package_Declaration
2229 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2240 end Enclosing_Generic_Body;
2242 ----------------------------
2243 -- Enclosing_Generic_Unit --
2244 ----------------------------
2246 function Enclosing_Generic_Unit
2247 (N : Node_Id) return Node_Id
2255 while Present (P) loop
2256 if Nkind (P) = N_Generic_Package_Declaration
2257 or else Nkind (P) = N_Generic_Subprogram_Declaration
2261 elsif Nkind (P) = N_Package_Body
2262 or else Nkind (P) = N_Subprogram_Body
2264 Spec := Corresponding_Spec (P);
2266 if Present (Spec) then
2267 Decl := Unit_Declaration_Node (Spec);
2269 if Nkind (Decl) = N_Generic_Package_Declaration
2270 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2281 end Enclosing_Generic_Unit;
2283 -------------------------------
2284 -- Enclosing_Lib_Unit_Entity --
2285 -------------------------------
2287 function Enclosing_Lib_Unit_Entity return Entity_Id is
2288 Unit_Entity : Entity_Id;
2291 -- Look for enclosing library unit entity by following scope links.
2292 -- Equivalent to, but faster than indexing through the scope stack.
2294 Unit_Entity := Current_Scope;
2295 while (Present (Scope (Unit_Entity))
2296 and then Scope (Unit_Entity) /= Standard_Standard)
2297 and not Is_Child_Unit (Unit_Entity)
2299 Unit_Entity := Scope (Unit_Entity);
2303 end Enclosing_Lib_Unit_Entity;
2305 -----------------------------
2306 -- Enclosing_Lib_Unit_Node --
2307 -----------------------------
2309 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2310 Current_Node : Node_Id;
2314 while Present (Current_Node)
2315 and then Nkind (Current_Node) /= N_Compilation_Unit
2317 Current_Node := Parent (Current_Node);
2320 if Nkind (Current_Node) /= N_Compilation_Unit then
2324 return Current_Node;
2325 end Enclosing_Lib_Unit_Node;
2327 --------------------------
2328 -- Enclosing_Subprogram --
2329 --------------------------
2331 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2332 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2335 if Dynamic_Scope = Standard_Standard then
2338 elsif Dynamic_Scope = Empty then
2341 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2342 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2344 elsif Ekind (Dynamic_Scope) = E_Block
2345 or else Ekind (Dynamic_Scope) = E_Return_Statement
2347 return Enclosing_Subprogram (Dynamic_Scope);
2349 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2350 return Get_Task_Body_Procedure (Dynamic_Scope);
2352 elsif Convention (Dynamic_Scope) = Convention_Protected then
2353 return Protected_Body_Subprogram (Dynamic_Scope);
2356 return Dynamic_Scope;
2358 end Enclosing_Subprogram;
2360 ------------------------
2361 -- Ensure_Freeze_Node --
2362 ------------------------
2364 procedure Ensure_Freeze_Node (E : Entity_Id) is
2368 if No (Freeze_Node (E)) then
2369 FN := Make_Freeze_Entity (Sloc (E));
2370 Set_Has_Delayed_Freeze (E);
2371 Set_Freeze_Node (E, FN);
2372 Set_Access_Types_To_Process (FN, No_Elist);
2373 Set_TSS_Elist (FN, No_Elist);
2376 end Ensure_Freeze_Node;
2382 procedure Enter_Name (Def_Id : Entity_Id) is
2383 C : constant Entity_Id := Current_Entity (Def_Id);
2384 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2385 S : constant Entity_Id := Current_Scope;
2388 Generate_Definition (Def_Id);
2390 -- Add new name to current scope declarations. Check for duplicate
2391 -- declaration, which may or may not be a genuine error.
2395 -- Case of previous entity entered because of a missing declaration
2396 -- or else a bad subtype indication. Best is to use the new entity,
2397 -- and make the previous one invisible.
2399 if Etype (E) = Any_Type then
2400 Set_Is_Immediately_Visible (E, False);
2402 -- Case of renaming declaration constructed for package instances.
2403 -- if there is an explicit declaration with the same identifier,
2404 -- the renaming is not immediately visible any longer, but remains
2405 -- visible through selected component notation.
2407 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2408 and then not Comes_From_Source (E)
2410 Set_Is_Immediately_Visible (E, False);
2412 -- The new entity may be the package renaming, which has the same
2413 -- same name as a generic formal which has been seen already.
2415 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2416 and then not Comes_From_Source (Def_Id)
2418 Set_Is_Immediately_Visible (E, False);
2420 -- For a fat pointer corresponding to a remote access to subprogram,
2421 -- we use the same identifier as the RAS type, so that the proper
2422 -- name appears in the stub. This type is only retrieved through
2423 -- the RAS type and never by visibility, and is not added to the
2424 -- visibility list (see below).
2426 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2427 and then Present (Corresponding_Remote_Type (Def_Id))
2431 -- A controller component for a type extension overrides the
2432 -- inherited component.
2434 elsif Chars (E) = Name_uController then
2437 -- Case of an implicit operation or derived literal. The new entity
2438 -- hides the implicit one, which is removed from all visibility,
2439 -- i.e. the entity list of its scope, and homonym chain of its name.
2441 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2442 or else Is_Internal (E)
2446 Prev_Vis : Entity_Id;
2447 Decl : constant Node_Id := Parent (E);
2450 -- If E is an implicit declaration, it cannot be the first
2451 -- entity in the scope.
2453 Prev := First_Entity (Current_Scope);
2454 while Present (Prev)
2455 and then Next_Entity (Prev) /= E
2462 -- If E is not on the entity chain of the current scope,
2463 -- it is an implicit declaration in the generic formal
2464 -- part of a generic subprogram. When analyzing the body,
2465 -- the generic formals are visible but not on the entity
2466 -- chain of the subprogram. The new entity will become
2467 -- the visible one in the body.
2470 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2474 Set_Next_Entity (Prev, Next_Entity (E));
2476 if No (Next_Entity (Prev)) then
2477 Set_Last_Entity (Current_Scope, Prev);
2480 if E = Current_Entity (E) then
2484 Prev_Vis := Current_Entity (E);
2485 while Homonym (Prev_Vis) /= E loop
2486 Prev_Vis := Homonym (Prev_Vis);
2490 if Present (Prev_Vis) then
2492 -- Skip E in the visibility chain
2494 Set_Homonym (Prev_Vis, Homonym (E));
2497 Set_Name_Entity_Id (Chars (E), Homonym (E));
2502 -- This section of code could use a comment ???
2504 elsif Present (Etype (E))
2505 and then Is_Concurrent_Type (Etype (E))
2510 -- If the homograph is a protected component renaming, it should not
2511 -- be hiding the current entity. Such renamings are treated as weak
2514 elsif Is_Prival (E) then
2515 Set_Is_Immediately_Visible (E, False);
2517 -- In this case the current entity is a protected component renaming.
2518 -- Perform minimal decoration by setting the scope and return since
2519 -- the prival should not be hiding other visible entities.
2521 elsif Is_Prival (Def_Id) then
2522 Set_Scope (Def_Id, Current_Scope);
2525 -- Analogous to privals, the discriminal generated for an entry
2526 -- index parameter acts as a weak declaration. Perform minimal
2527 -- decoration to avoid bogus errors.
2529 elsif Is_Discriminal (Def_Id)
2530 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2532 Set_Scope (Def_Id, Current_Scope);
2535 -- In the body or private part of an instance, a type extension
2536 -- may introduce a component with the same name as that of an
2537 -- actual. The legality rule is not enforced, but the semantics
2538 -- of the full type with two components of the same name are not
2539 -- clear at this point ???
2541 elsif In_Instance_Not_Visible then
2544 -- When compiling a package body, some child units may have become
2545 -- visible. They cannot conflict with local entities that hide them.
2547 elsif Is_Child_Unit (E)
2548 and then In_Open_Scopes (Scope (E))
2549 and then not Is_Immediately_Visible (E)
2553 -- Conversely, with front-end inlining we may compile the parent
2554 -- body first, and a child unit subsequently. The context is now
2555 -- the parent spec, and body entities are not visible.
2557 elsif Is_Child_Unit (Def_Id)
2558 and then Is_Package_Body_Entity (E)
2559 and then not In_Package_Body (Current_Scope)
2563 -- Case of genuine duplicate declaration
2566 Error_Msg_Sloc := Sloc (E);
2568 -- If the previous declaration is an incomplete type declaration
2569 -- this may be an attempt to complete it with a private type.
2570 -- The following avoids confusing cascaded errors.
2572 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2573 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2576 ("incomplete type cannot be completed with a private " &
2577 "declaration", Parent (Def_Id));
2578 Set_Is_Immediately_Visible (E, False);
2579 Set_Full_View (E, Def_Id);
2581 -- An inherited component of a record conflicts with a new
2582 -- discriminant. The discriminant is inserted first in the scope,
2583 -- but the error should be posted on it, not on the component.
2585 elsif Ekind (E) = E_Discriminant
2586 and then Present (Scope (Def_Id))
2587 and then Scope (Def_Id) /= Current_Scope
2589 Error_Msg_Sloc := Sloc (Def_Id);
2590 Error_Msg_N ("& conflicts with declaration#", E);
2593 -- If the name of the unit appears in its own context clause,
2594 -- a dummy package with the name has already been created, and
2595 -- the error emitted. Try to continue quietly.
2597 elsif Error_Posted (E)
2598 and then Sloc (E) = No_Location
2599 and then Nkind (Parent (E)) = N_Package_Specification
2600 and then Current_Scope = Standard_Standard
2602 Set_Scope (Def_Id, Current_Scope);
2606 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2608 -- Avoid cascaded messages with duplicate components in
2611 if Ekind (E) = E_Component
2612 or else Ekind (E) = E_Discriminant
2618 if Nkind (Parent (Parent (Def_Id))) =
2619 N_Generic_Subprogram_Declaration
2621 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2623 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2626 -- If entity is in standard, then we are in trouble, because
2627 -- it means that we have a library package with a duplicated
2628 -- name. That's hard to recover from, so abort!
2630 if S = Standard_Standard then
2631 raise Unrecoverable_Error;
2633 -- Otherwise we continue with the declaration. Having two
2634 -- identical declarations should not cause us too much trouble!
2642 -- If we fall through, declaration is OK , or OK enough to continue
2644 -- If Def_Id is a discriminant or a record component we are in the
2645 -- midst of inheriting components in a derived record definition.
2646 -- Preserve their Ekind and Etype.
2648 if Ekind (Def_Id) = E_Discriminant
2649 or else Ekind (Def_Id) = E_Component
2653 -- If a type is already set, leave it alone (happens whey a type
2654 -- declaration is reanalyzed following a call to the optimizer)
2656 elsif Present (Etype (Def_Id)) then
2659 -- Otherwise, the kind E_Void insures that premature uses of the entity
2660 -- will be detected. Any_Type insures that no cascaded errors will occur
2663 Set_Ekind (Def_Id, E_Void);
2664 Set_Etype (Def_Id, Any_Type);
2667 -- Inherited discriminants and components in derived record types are
2668 -- immediately visible. Itypes are not.
2670 if Ekind (Def_Id) = E_Discriminant
2671 or else Ekind (Def_Id) = E_Component
2672 or else (No (Corresponding_Remote_Type (Def_Id))
2673 and then not Is_Itype (Def_Id))
2675 Set_Is_Immediately_Visible (Def_Id);
2676 Set_Current_Entity (Def_Id);
2679 Set_Homonym (Def_Id, C);
2680 Append_Entity (Def_Id, S);
2681 Set_Public_Status (Def_Id);
2683 -- Warn if new entity hides an old one
2685 if Warn_On_Hiding and then Present (C)
2687 -- Don't warn for record components since they always have a well
2688 -- defined scope which does not confuse other uses. Note that in
2689 -- some cases, Ekind has not been set yet.
2691 and then Ekind (C) /= E_Component
2692 and then Ekind (C) /= E_Discriminant
2693 and then Nkind (Parent (C)) /= N_Component_Declaration
2694 and then Ekind (Def_Id) /= E_Component
2695 and then Ekind (Def_Id) /= E_Discriminant
2696 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2698 -- Don't warn for one character variables. It is too common to use
2699 -- such variables as locals and will just cause too many false hits.
2701 and then Length_Of_Name (Chars (C)) /= 1
2703 -- Don't warn for non-source entities
2705 and then Comes_From_Source (C)
2706 and then Comes_From_Source (Def_Id)
2708 -- Don't warn unless entity in question is in extended main source
2710 and then In_Extended_Main_Source_Unit (Def_Id)
2712 -- Finally, the hidden entity must be either immediately visible
2713 -- or use visible (from a used package)
2716 (Is_Immediately_Visible (C)
2718 Is_Potentially_Use_Visible (C))
2720 Error_Msg_Sloc := Sloc (C);
2721 Error_Msg_N ("declaration hides &#?", Def_Id);
2725 --------------------------
2726 -- Explain_Limited_Type --
2727 --------------------------
2729 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2733 -- For array, component type must be limited
2735 if Is_Array_Type (T) then
2736 Error_Msg_Node_2 := T;
2738 ("\component type& of type& is limited", N, Component_Type (T));
2739 Explain_Limited_Type (Component_Type (T), N);
2741 elsif Is_Record_Type (T) then
2743 -- No need for extra messages if explicit limited record
2745 if Is_Limited_Record (Base_Type (T)) then
2749 -- Otherwise find a limited component. Check only components that
2750 -- come from source, or inherited components that appear in the
2751 -- source of the ancestor.
2753 C := First_Component (T);
2754 while Present (C) loop
2755 if Is_Limited_Type (Etype (C))
2757 (Comes_From_Source (C)
2759 (Present (Original_Record_Component (C))
2761 Comes_From_Source (Original_Record_Component (C))))
2763 Error_Msg_Node_2 := T;
2764 Error_Msg_NE ("\component& of type& has limited type", N, C);
2765 Explain_Limited_Type (Etype (C), N);
2772 -- The type may be declared explicitly limited, even if no component
2773 -- of it is limited, in which case we fall out of the loop.
2776 end Explain_Limited_Type;
2782 procedure Find_Actual
2784 Formal : out Entity_Id;
2787 Parnt : constant Node_Id := Parent (N);
2791 if (Nkind (Parnt) = N_Indexed_Component
2793 Nkind (Parnt) = N_Selected_Component)
2794 and then N = Prefix (Parnt)
2796 Find_Actual (Parnt, Formal, Call);
2799 elsif Nkind (Parnt) = N_Parameter_Association
2800 and then N = Explicit_Actual_Parameter (Parnt)
2802 Call := Parent (Parnt);
2804 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2813 -- If we have a call to a subprogram look for the parameter. Note that
2814 -- we exclude overloaded calls, since we don't know enough to be sure
2815 -- of giving the right answer in this case.
2817 if Is_Entity_Name (Name (Call))
2818 and then Present (Entity (Name (Call)))
2819 and then Is_Overloadable (Entity (Name (Call)))
2820 and then not Is_Overloaded (Name (Call))
2822 -- Fall here if we are definitely a parameter
2824 Actual := First_Actual (Call);
2825 Formal := First_Formal (Entity (Name (Call)));
2826 while Present (Formal) and then Present (Actual) loop
2830 Actual := Next_Actual (Actual);
2831 Formal := Next_Formal (Formal);
2836 -- Fall through here if we did not find matching actual
2842 -------------------------------------
2843 -- Find_Corresponding_Discriminant --
2844 -------------------------------------
2846 function Find_Corresponding_Discriminant
2848 Typ : Entity_Id) return Entity_Id
2850 Par_Disc : Entity_Id;
2851 Old_Disc : Entity_Id;
2852 New_Disc : Entity_Id;
2855 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2857 -- The original type may currently be private, and the discriminant
2858 -- only appear on its full view.
2860 if Is_Private_Type (Scope (Par_Disc))
2861 and then not Has_Discriminants (Scope (Par_Disc))
2862 and then Present (Full_View (Scope (Par_Disc)))
2864 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2866 Old_Disc := First_Discriminant (Scope (Par_Disc));
2869 if Is_Class_Wide_Type (Typ) then
2870 New_Disc := First_Discriminant (Root_Type (Typ));
2872 New_Disc := First_Discriminant (Typ);
2875 while Present (Old_Disc) and then Present (New_Disc) loop
2876 if Old_Disc = Par_Disc then
2879 Next_Discriminant (Old_Disc);
2880 Next_Discriminant (New_Disc);
2884 -- Should always find it
2886 raise Program_Error;
2887 end Find_Corresponding_Discriminant;
2889 --------------------------
2890 -- Find_Overlaid_Object --
2891 --------------------------
2893 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2897 -- We are looking for one of the two following forms:
2899 -- for X'Address use Y'Address
2903 -- Const : constant Address := expr;
2905 -- for X'Address use Const;
2907 -- In the second case, the expr is either Y'Address, or recursively a
2908 -- constant that eventually references Y'Address.
2910 if Nkind (N) = N_Attribute_Definition_Clause
2911 and then Chars (N) = Name_Address
2913 -- This loop checks the form of the expression for Y'Address where Y
2914 -- is an object entity name. The first loop checks the original
2915 -- expression in the attribute definition clause. Subsequent loops
2916 -- check referenced constants.
2918 Expr := Expression (N);
2920 -- Check for Y'Address where Y is an object entity
2922 if Nkind (Expr) = N_Attribute_Reference
2923 and then Attribute_Name (Expr) = Name_Address
2924 and then Is_Entity_Name (Prefix (Expr))
2925 and then Is_Object (Entity (Prefix (Expr)))
2927 return Entity (Prefix (Expr));
2929 -- Check for Const where Const is a constant entity
2931 elsif Is_Entity_Name (Expr)
2932 and then Ekind (Entity (Expr)) = E_Constant
2934 Expr := Constant_Value (Entity (Expr));
2936 -- Anything else does not need checking
2945 end Find_Overlaid_Object;
2947 -------------------------
2948 -- Find_Parameter_Type --
2949 -------------------------
2951 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2953 if Nkind (Param) /= N_Parameter_Specification then
2956 -- For an access parameter, obtain the type from the formal entity
2957 -- itself, because access to subprogram nodes do not carry a type.
2958 -- Shouldn't we always use the formal entity ???
2960 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
2961 return Etype (Defining_Identifier (Param));
2964 return Etype (Parameter_Type (Param));
2966 end Find_Parameter_Type;
2968 -----------------------------
2969 -- Find_Static_Alternative --
2970 -----------------------------
2972 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2973 Expr : constant Node_Id := Expression (N);
2974 Val : constant Uint := Expr_Value (Expr);
2979 Alt := First (Alternatives (N));
2982 if Nkind (Alt) /= N_Pragma then
2983 Choice := First (Discrete_Choices (Alt));
2984 while Present (Choice) loop
2986 -- Others choice, always matches
2988 if Nkind (Choice) = N_Others_Choice then
2991 -- Range, check if value is in the range
2993 elsif Nkind (Choice) = N_Range then
2995 Val >= Expr_Value (Low_Bound (Choice))
2997 Val <= Expr_Value (High_Bound (Choice));
2999 -- Choice is a subtype name. Note that we know it must
3000 -- be a static subtype, since otherwise it would have
3001 -- been diagnosed as illegal.
3003 elsif Is_Entity_Name (Choice)
3004 and then Is_Type (Entity (Choice))
3006 exit Search when Is_In_Range (Expr, Etype (Choice),
3007 Assume_Valid => False);
3009 -- Choice is a subtype indication
3011 elsif Nkind (Choice) = N_Subtype_Indication then
3013 C : constant Node_Id := Constraint (Choice);
3014 R : constant Node_Id := Range_Expression (C);
3018 Val >= Expr_Value (Low_Bound (R))
3020 Val <= Expr_Value (High_Bound (R));
3023 -- Choice is a simple expression
3026 exit Search when Val = Expr_Value (Choice);
3034 pragma Assert (Present (Alt));
3037 -- The above loop *must* terminate by finding a match, since
3038 -- we know the case statement is valid, and the value of the
3039 -- expression is known at compile time. When we fall out of
3040 -- the loop, Alt points to the alternative that we know will
3041 -- be selected at run time.
3044 end Find_Static_Alternative;
3050 function First_Actual (Node : Node_Id) return Node_Id is
3054 if No (Parameter_Associations (Node)) then
3058 N := First (Parameter_Associations (Node));
3060 if Nkind (N) = N_Parameter_Association then
3061 return First_Named_Actual (Node);
3067 -------------------------
3068 -- Full_Qualified_Name --
3069 -------------------------
3071 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3073 pragma Warnings (Off, Res);
3075 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3076 -- Compute recursively the qualified name without NUL at the end
3078 ----------------------------------
3079 -- Internal_Full_Qualified_Name --
3080 ----------------------------------
3082 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3083 Ent : Entity_Id := E;
3084 Parent_Name : String_Id := No_String;
3087 -- Deals properly with child units
3089 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3090 Ent := Defining_Identifier (Ent);
3093 -- Compute qualification recursively (only "Standard" has no scope)
3095 if Present (Scope (Scope (Ent))) then
3096 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3099 -- Every entity should have a name except some expanded blocks
3100 -- don't bother about those.
3102 if Chars (Ent) = No_Name then
3106 -- Add a period between Name and qualification
3108 if Parent_Name /= No_String then
3109 Start_String (Parent_Name);
3110 Store_String_Char (Get_Char_Code ('.'));
3116 -- Generates the entity name in upper case
3118 Get_Decoded_Name_String (Chars (Ent));
3120 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3122 end Internal_Full_Qualified_Name;
3124 -- Start of processing for Full_Qualified_Name
3127 Res := Internal_Full_Qualified_Name (E);
3128 Store_String_Char (Get_Char_Code (ASCII.NUL));
3130 end Full_Qualified_Name;
3132 -----------------------
3133 -- Gather_Components --
3134 -----------------------
3136 procedure Gather_Components
3138 Comp_List : Node_Id;
3139 Governed_By : List_Id;
3141 Report_Errors : out Boolean)
3145 Discrete_Choice : Node_Id;
3146 Comp_Item : Node_Id;
3148 Discrim : Entity_Id;
3149 Discrim_Name : Node_Id;
3150 Discrim_Value : Node_Id;
3153 Report_Errors := False;
3155 if No (Comp_List) or else Null_Present (Comp_List) then
3158 elsif Present (Component_Items (Comp_List)) then
3159 Comp_Item := First (Component_Items (Comp_List));
3165 while Present (Comp_Item) loop
3167 -- Skip the tag of a tagged record, the interface tags, as well
3168 -- as all items that are not user components (anonymous types,
3169 -- rep clauses, Parent field, controller field).
3171 if Nkind (Comp_Item) = N_Component_Declaration then
3173 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3175 if not Is_Tag (Comp)
3176 and then Chars (Comp) /= Name_uParent
3177 and then Chars (Comp) /= Name_uController
3179 Append_Elmt (Comp, Into);
3187 if No (Variant_Part (Comp_List)) then
3190 Discrim_Name := Name (Variant_Part (Comp_List));
3191 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3194 -- Look for the discriminant that governs this variant part.
3195 -- The discriminant *must* be in the Governed_By List
3197 Assoc := First (Governed_By);
3198 Find_Constraint : loop
3199 Discrim := First (Choices (Assoc));
3200 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3201 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3203 Chars (Corresponding_Discriminant (Entity (Discrim)))
3204 = Chars (Discrim_Name))
3205 or else Chars (Original_Record_Component (Entity (Discrim)))
3206 = Chars (Discrim_Name);
3208 if No (Next (Assoc)) then
3209 if not Is_Constrained (Typ)
3210 and then Is_Derived_Type (Typ)
3211 and then Present (Stored_Constraint (Typ))
3213 -- If the type is a tagged type with inherited discriminants,
3214 -- use the stored constraint on the parent in order to find
3215 -- the values of discriminants that are otherwise hidden by an
3216 -- explicit constraint. Renamed discriminants are handled in
3219 -- If several parent discriminants are renamed by a single
3220 -- discriminant of the derived type, the call to obtain the
3221 -- Corresponding_Discriminant field only retrieves the last
3222 -- of them. We recover the constraint on the others from the
3223 -- Stored_Constraint as well.
3230 D := First_Discriminant (Etype (Typ));
3231 C := First_Elmt (Stored_Constraint (Typ));
3232 while Present (D) and then Present (C) loop
3233 if Chars (Discrim_Name) = Chars (D) then
3234 if Is_Entity_Name (Node (C))
3235 and then Entity (Node (C)) = Entity (Discrim)
3237 -- D is renamed by Discrim, whose value is given in
3244 Make_Component_Association (Sloc (Typ),
3246 (New_Occurrence_Of (D, Sloc (Typ))),
3247 Duplicate_Subexpr_No_Checks (Node (C)));
3249 exit Find_Constraint;
3252 Next_Discriminant (D);
3259 if No (Next (Assoc)) then
3260 Error_Msg_NE (" missing value for discriminant&",
3261 First (Governed_By), Discrim_Name);
3262 Report_Errors := True;
3267 end loop Find_Constraint;
3269 Discrim_Value := Expression (Assoc);
3271 if not Is_OK_Static_Expression (Discrim_Value) then
3273 ("value for discriminant & must be static!",
3274 Discrim_Value, Discrim);
3275 Why_Not_Static (Discrim_Value);
3276 Report_Errors := True;
3280 Search_For_Discriminant_Value : declare
3286 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3289 Find_Discrete_Value : while Present (Variant) loop
3290 Discrete_Choice := First (Discrete_Choices (Variant));
3291 while Present (Discrete_Choice) loop
3293 exit Find_Discrete_Value when
3294 Nkind (Discrete_Choice) = N_Others_Choice;
3296 Get_Index_Bounds (Discrete_Choice, Low, High);
3298 UI_Low := Expr_Value (Low);
3299 UI_High := Expr_Value (High);
3301 exit Find_Discrete_Value when
3302 UI_Low <= UI_Discrim_Value
3304 UI_High >= UI_Discrim_Value;
3306 Next (Discrete_Choice);
3309 Next_Non_Pragma (Variant);
3310 end loop Find_Discrete_Value;
3311 end Search_For_Discriminant_Value;
3313 if No (Variant) then
3315 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3316 Report_Errors := True;
3320 -- If we have found the corresponding choice, recursively add its
3321 -- components to the Into list.
3323 Gather_Components (Empty,
3324 Component_List (Variant), Governed_By, Into, Report_Errors);
3325 end Gather_Components;
3327 ------------------------
3328 -- Get_Actual_Subtype --
3329 ------------------------
3331 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3332 Typ : constant Entity_Id := Etype (N);
3333 Utyp : Entity_Id := Underlying_Type (Typ);
3342 -- If what we have is an identifier that references a subprogram
3343 -- formal, or a variable or constant object, then we get the actual
3344 -- subtype from the referenced entity if one has been built.
3346 if Nkind (N) = N_Identifier
3348 (Is_Formal (Entity (N))
3349 or else Ekind (Entity (N)) = E_Constant
3350 or else Ekind (Entity (N)) = E_Variable)
3351 and then Present (Actual_Subtype (Entity (N)))
3353 return Actual_Subtype (Entity (N));
3355 -- Actual subtype of unchecked union is always itself. We never need
3356 -- the "real" actual subtype. If we did, we couldn't get it anyway
3357 -- because the discriminant is not available. The restrictions on
3358 -- Unchecked_Union are designed to make sure that this is OK.
3360 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3363 -- Here for the unconstrained case, we must find actual subtype
3364 -- No actual subtype is available, so we must build it on the fly.
3366 -- Checking the type, not the underlying type, for constrainedness
3367 -- seems to be necessary. Maybe all the tests should be on the type???
3369 elsif (not Is_Constrained (Typ))
3370 and then (Is_Array_Type (Utyp)
3371 or else (Is_Record_Type (Utyp)
3372 and then Has_Discriminants (Utyp)))
3373 and then not Has_Unknown_Discriminants (Utyp)
3374 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3376 -- Nothing to do if in spec expression (why not???)
3378 if In_Spec_Expression then
3381 elsif Is_Private_Type (Typ)
3382 and then not Has_Discriminants (Typ)
3384 -- If the type has no discriminants, there is no subtype to
3385 -- build, even if the underlying type is discriminated.
3389 -- Else build the actual subtype
3392 Decl := Build_Actual_Subtype (Typ, N);
3393 Atyp := Defining_Identifier (Decl);
3395 -- If Build_Actual_Subtype generated a new declaration then use it
3399 -- The actual subtype is an Itype, so analyze the declaration,
3400 -- but do not attach it to the tree, to get the type defined.
3402 Set_Parent (Decl, N);
3403 Set_Is_Itype (Atyp);
3404 Analyze (Decl, Suppress => All_Checks);
3405 Set_Associated_Node_For_Itype (Atyp, N);
3406 Set_Has_Delayed_Freeze (Atyp, False);
3408 -- We need to freeze the actual subtype immediately. This is
3409 -- needed, because otherwise this Itype will not get frozen
3410 -- at all, and it is always safe to freeze on creation because
3411 -- any associated types must be frozen at this point.
3413 Freeze_Itype (Atyp, N);
3416 -- Otherwise we did not build a declaration, so return original
3423 -- For all remaining cases, the actual subtype is the same as
3424 -- the nominal type.
3429 end Get_Actual_Subtype;
3431 -------------------------------------
3432 -- Get_Actual_Subtype_If_Available --
3433 -------------------------------------
3435 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3436 Typ : constant Entity_Id := Etype (N);
3439 -- If what we have is an identifier that references a subprogram
3440 -- formal, or a variable or constant object, then we get the actual
3441 -- subtype from the referenced entity if one has been built.
3443 if Nkind (N) = N_Identifier
3445 (Is_Formal (Entity (N))
3446 or else Ekind (Entity (N)) = E_Constant
3447 or else Ekind (Entity (N)) = E_Variable)
3448 and then Present (Actual_Subtype (Entity (N)))
3450 return Actual_Subtype (Entity (N));
3452 -- Otherwise the Etype of N is returned unchanged
3457 end Get_Actual_Subtype_If_Available;
3459 -------------------------------
3460 -- Get_Default_External_Name --
3461 -------------------------------
3463 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3465 Get_Decoded_Name_String (Chars (E));
3467 if Opt.External_Name_Imp_Casing = Uppercase then
3468 Set_Casing (All_Upper_Case);
3470 Set_Casing (All_Lower_Case);
3474 Make_String_Literal (Sloc (E),
3475 Strval => String_From_Name_Buffer);
3476 end Get_Default_External_Name;
3478 ---------------------------
3479 -- Get_Enum_Lit_From_Pos --
3480 ---------------------------
3482 function Get_Enum_Lit_From_Pos
3485 Loc : Source_Ptr) return Node_Id
3490 -- In the case where the literal is of type Character, Wide_Character
3491 -- or Wide_Wide_Character or of a type derived from them, there needs
3492 -- to be some special handling since there is no explicit chain of
3493 -- literals to search. Instead, an N_Character_Literal node is created
3494 -- with the appropriate Char_Code and Chars fields.
3496 if Is_Standard_Character_Type (T) then
3497 Set_Character_Literal_Name (UI_To_CC (Pos));
3499 Make_Character_Literal (Loc,
3501 Char_Literal_Value => Pos);
3503 -- For all other cases, we have a complete table of literals, and
3504 -- we simply iterate through the chain of literal until the one
3505 -- with the desired position value is found.
3509 Lit := First_Literal (Base_Type (T));
3510 for J in 1 .. UI_To_Int (Pos) loop
3514 return New_Occurrence_Of (Lit, Loc);
3516 end Get_Enum_Lit_From_Pos;
3518 ------------------------
3519 -- Get_Generic_Entity --
3520 ------------------------
3522 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3523 Ent : constant Entity_Id := Entity (Name (N));
3525 if Present (Renamed_Object (Ent)) then
3526 return Renamed_Object (Ent);
3530 end Get_Generic_Entity;
3532 ----------------------
3533 -- Get_Index_Bounds --
3534 ----------------------
3536 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3537 Kind : constant Node_Kind := Nkind (N);
3541 if Kind = N_Range then
3543 H := High_Bound (N);
3545 elsif Kind = N_Subtype_Indication then
3546 R := Range_Expression (Constraint (N));
3554 L := Low_Bound (Range_Expression (Constraint (N)));
3555 H := High_Bound (Range_Expression (Constraint (N)));
3558 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3559 if Error_Posted (Scalar_Range (Entity (N))) then
3563 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3564 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3567 L := Low_Bound (Scalar_Range (Entity (N)));
3568 H := High_Bound (Scalar_Range (Entity (N)));
3572 -- N is an expression, indicating a range with one value
3577 end Get_Index_Bounds;
3579 ----------------------------------
3580 -- Get_Library_Unit_Name_string --
3581 ----------------------------------
3583 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3584 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3587 Get_Unit_Name_String (Unit_Name_Id);
3589 -- Remove seven last character (" (spec)" or " (body)")
3591 Name_Len := Name_Len - 7;
3592 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3593 end Get_Library_Unit_Name_String;
3595 ------------------------
3596 -- Get_Name_Entity_Id --
3597 ------------------------
3599 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3601 return Entity_Id (Get_Name_Table_Info (Id));
3602 end Get_Name_Entity_Id;
3608 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3610 return Get_Pragma_Id (Pragma_Name (N));
3613 ---------------------------
3614 -- Get_Referenced_Object --
3615 ---------------------------
3617 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3622 while Is_Entity_Name (R)
3623 and then Present (Renamed_Object (Entity (R)))
3625 R := Renamed_Object (Entity (R));
3629 end Get_Referenced_Object;
3631 ------------------------
3632 -- Get_Renamed_Entity --
3633 ------------------------
3635 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3640 while Present (Renamed_Entity (R)) loop
3641 R := Renamed_Entity (R);
3645 end Get_Renamed_Entity;
3647 -------------------------
3648 -- Get_Subprogram_Body --
3649 -------------------------
3651 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3655 Decl := Unit_Declaration_Node (E);
3657 if Nkind (Decl) = N_Subprogram_Body then
3660 -- The below comment is bad, because it is possible for
3661 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3663 else -- Nkind (Decl) = N_Subprogram_Declaration
3665 if Present (Corresponding_Body (Decl)) then
3666 return Unit_Declaration_Node (Corresponding_Body (Decl));
3668 -- Imported subprogram case
3674 end Get_Subprogram_Body;
3676 ---------------------------
3677 -- Get_Subprogram_Entity --
3678 ---------------------------
3680 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3685 if Nkind (Nod) = N_Accept_Statement then
3686 Nam := Entry_Direct_Name (Nod);
3688 -- For an entry call, the prefix of the call is a selected component.
3689 -- Need additional code for internal calls ???
3691 elsif Nkind (Nod) = N_Entry_Call_Statement then
3692 if Nkind (Name (Nod)) = N_Selected_Component then
3693 Nam := Entity (Selector_Name (Name (Nod)));
3702 if Nkind (Nam) = N_Explicit_Dereference then
3703 Proc := Etype (Prefix (Nam));
3704 elsif Is_Entity_Name (Nam) then
3705 Proc := Entity (Nam);
3710 if Is_Object (Proc) then
3711 Proc := Etype (Proc);
3714 if Ekind (Proc) = E_Access_Subprogram_Type then
3715 Proc := Directly_Designated_Type (Proc);
3718 if not Is_Subprogram (Proc)
3719 and then Ekind (Proc) /= E_Subprogram_Type
3725 end Get_Subprogram_Entity;
3727 -----------------------------
3728 -- Get_Task_Body_Procedure --
3729 -----------------------------
3731 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3733 -- Note: A task type may be the completion of a private type with
3734 -- discriminants. When performing elaboration checks on a task
3735 -- declaration, the current view of the type may be the private one,
3736 -- and the procedure that holds the body of the task is held in its
3739 -- This is an odd function, why not have Task_Body_Procedure do
3740 -- the following digging???
3742 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3743 end Get_Task_Body_Procedure;
3745 -----------------------
3746 -- Has_Access_Values --
3747 -----------------------
3749 function Has_Access_Values (T : Entity_Id) return Boolean is
3750 Typ : constant Entity_Id := Underlying_Type (T);
3753 -- Case of a private type which is not completed yet. This can only
3754 -- happen in the case of a generic format type appearing directly, or
3755 -- as a component of the type to which this function is being applied
3756 -- at the top level. Return False in this case, since we certainly do
3757 -- not know that the type contains access types.
3762 elsif Is_Access_Type (Typ) then
3765 elsif Is_Array_Type (Typ) then
3766 return Has_Access_Values (Component_Type (Typ));
3768 elsif Is_Record_Type (Typ) then
3773 -- Loop to Check components
3775 Comp := First_Component_Or_Discriminant (Typ);
3776 while Present (Comp) loop
3778 -- Check for access component, tag field does not count, even
3779 -- though it is implemented internally using an access type.
3781 if Has_Access_Values (Etype (Comp))
3782 and then Chars (Comp) /= Name_uTag
3787 Next_Component_Or_Discriminant (Comp);
3796 end Has_Access_Values;
3798 ------------------------------
3799 -- Has_Compatible_Alignment --
3800 ------------------------------
3802 function Has_Compatible_Alignment
3804 Expr : Node_Id) return Alignment_Result
3806 function Has_Compatible_Alignment_Internal
3809 Default : Alignment_Result) return Alignment_Result;
3810 -- This is the internal recursive function that actually does the work.
3811 -- There is one additional parameter, which says what the result should
3812 -- be if no alignment information is found, and there is no definite
3813 -- indication of compatible alignments. At the outer level, this is set
3814 -- to Unknown, but for internal recursive calls in the case where types
3815 -- are known to be correct, it is set to Known_Compatible.
3817 ---------------------------------------
3818 -- Has_Compatible_Alignment_Internal --
3819 ---------------------------------------
3821 function Has_Compatible_Alignment_Internal
3824 Default : Alignment_Result) return Alignment_Result
3826 Result : Alignment_Result := Known_Compatible;
3827 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3828 -- Note that once a value of Known_Incompatible is set, it is sticky
3829 -- and does not get changed to Unknown (the value in Result only gets
3830 -- worse as we go along, never better).
3832 procedure Check_Offset (Offs : Uint);
3833 -- Called when Expr is a selected or indexed component with Offs set
3834 -- to resp Component_First_Bit or Component_Size. Checks that if the
3835 -- offset is specified it is compatible with the object alignment
3836 -- requirements. The value in Result is modified accordingly.
3838 procedure Check_Prefix;
3839 -- Checks the prefix recursively in the case where the expression
3840 -- is an indexed or selected component.
3842 procedure Set_Result (R : Alignment_Result);
3843 -- If R represents a worse outcome (unknown instead of known
3844 -- compatible, or known incompatible), then set Result to R.
3850 procedure Check_Offset (Offs : Uint) is
3852 -- Unspecified or zero offset is always OK
3854 if Offs = No_Uint or else Offs = Uint_0 then
3857 -- If we do not know required alignment, any non-zero offset is
3858 -- a potential problem (but certainly may be OK, so result is
3861 elsif Unknown_Alignment (Obj) then
3862 Set_Result (Unknown);
3864 -- If we know the required alignment, see if offset is compatible
3867 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3868 Set_Result (Known_Incompatible);
3877 procedure Check_Prefix is
3879 -- The subtlety here is that in doing a recursive call to check
3880 -- the prefix, we have to decide what to do in the case where we
3881 -- don't find any specific indication of an alignment problem.
3883 -- At the outer level, we normally set Unknown as the result in
3884 -- this case, since we can only set Known_Compatible if we really
3885 -- know that the alignment value is OK, but for the recursive
3886 -- call, in the case where the types match, and we have not
3887 -- specified a peculiar alignment for the object, we are only
3888 -- concerned about suspicious rep clauses, the default case does
3889 -- not affect us, since the compiler will, in the absence of such
3890 -- rep clauses, ensure that the alignment is correct.
3892 if Default = Known_Compatible
3894 (Etype (Obj) = Etype (Expr)
3895 and then (Unknown_Alignment (Obj)
3897 Alignment (Obj) = Alignment (Etype (Obj))))
3900 (Has_Compatible_Alignment_Internal
3901 (Obj, Prefix (Expr), Known_Compatible));
3903 -- In all other cases, we need a full check on the prefix
3907 (Has_Compatible_Alignment_Internal
3908 (Obj, Prefix (Expr), Unknown));
3916 procedure Set_Result (R : Alignment_Result) is
3923 -- Start of processing for Has_Compatible_Alignment_Internal
3926 -- If Expr is a selected component, we must make sure there is no
3927 -- potentially troublesome component clause, and that the record is
3930 if Nkind (Expr) = N_Selected_Component then
3932 -- Packed record always generate unknown alignment
3934 if Is_Packed (Etype (Prefix (Expr))) then
3935 Set_Result (Unknown);
3938 -- Check possible bad component offset and check prefix
3941 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3944 -- If Expr is an indexed component, we must make sure there is no
3945 -- potentially troublesome Component_Size clause and that the array
3946 -- is not bit-packed.
3948 elsif Nkind (Expr) = N_Indexed_Component then
3950 -- Bit packed array always generates unknown alignment
3952 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3953 Set_Result (Unknown);
3956 -- Check possible bad component size and check prefix
3958 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3962 -- Case where we know the alignment of the object
3964 if Known_Alignment (Obj) then
3966 ObjA : constant Uint := Alignment (Obj);
3967 ExpA : Uint := No_Uint;
3968 SizA : Uint := No_Uint;
3971 -- If alignment of Obj is 1, then we are always OK
3974 Set_Result (Known_Compatible);
3976 -- Alignment of Obj is greater than 1, so we need to check
3979 -- See if Expr is an object with known alignment
3981 if Is_Entity_Name (Expr)
3982 and then Known_Alignment (Entity (Expr))
3984 ExpA := Alignment (Entity (Expr));
3986 -- Otherwise, we can use the alignment of the type of
3987 -- Expr given that we already checked for
3988 -- discombobulating rep clauses for the cases of indexed
3989 -- and selected components above.
3991 elsif Known_Alignment (Etype (Expr)) then
3992 ExpA := Alignment (Etype (Expr));
3995 -- If we got an alignment, see if it is acceptable
3997 if ExpA /= No_Uint then
3999 Set_Result (Known_Incompatible);
4002 -- Case of Expr alignment unknown
4005 Set_Result (Default);
4008 -- See if size is given. If so, check that it is not too
4009 -- small for the required alignment.
4010 -- See if Expr is an object with known alignment
4012 if Is_Entity_Name (Expr)
4013 and then Known_Static_Esize (Entity (Expr))
4015 SizA := Esize (Entity (Expr));
4017 -- Otherwise, we check the object size of the Expr type
4019 elsif Known_Static_Esize (Etype (Expr)) then
4020 SizA := Esize (Etype (Expr));
4023 -- If we got a size, see if it is a multiple of the Obj
4024 -- alignment, if not, then the alignment cannot be
4025 -- acceptable, since the size is always a multiple of the
4028 if SizA /= No_Uint then
4029 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4030 Set_Result (Known_Incompatible);
4036 -- If we can't find the result by direct comparison of alignment
4037 -- values, then there is still one case that we can determine known
4038 -- result, and that is when we can determine that the types are the
4039 -- same, and no alignments are specified. Then we known that the
4040 -- alignments are compatible, even if we don't know the alignment
4041 -- value in the front end.
4043 elsif Etype (Obj) = Etype (Expr) then
4045 -- Types are the same, but we have to check for possible size
4046 -- and alignments on the Expr object that may make the alignment
4047 -- different, even though the types are the same.
4049 if Is_Entity_Name (Expr) then
4051 -- First check alignment of the Expr object. Any alignment less
4052 -- than Maximum_Alignment is worrisome since this is the case
4053 -- where we do not know the alignment of Obj.
4055 if Known_Alignment (Entity (Expr))
4057 UI_To_Int (Alignment (Entity (Expr)))
4058 < Ttypes.Maximum_Alignment
4060 Set_Result (Unknown);
4062 -- Now check size of Expr object. Any size that is not an
4063 -- even multiple of Maximum_Alignment is also worrisome
4064 -- since it may cause the alignment of the object to be less
4065 -- than the alignment of the type.
4067 elsif Known_Static_Esize (Entity (Expr))
4069 (UI_To_Int (Esize (Entity (Expr))) mod
4070 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4073 Set_Result (Unknown);
4075 -- Otherwise same type is decisive
4078 Set_Result (Known_Compatible);
4082 -- Another case to deal with is when there is an explicit size or
4083 -- alignment clause when the types are not the same. If so, then the
4084 -- result is Unknown. We don't need to do this test if the Default is
4085 -- Unknown, since that result will be set in any case.
4087 elsif Default /= Unknown
4088 and then (Has_Size_Clause (Etype (Expr))
4090 Has_Alignment_Clause (Etype (Expr)))
4092 Set_Result (Unknown);
4094 -- If no indication found, set default
4097 Set_Result (Default);
4100 -- Return worst result found
4103 end Has_Compatible_Alignment_Internal;
4105 -- Start of processing for Has_Compatible_Alignment
4108 -- If Obj has no specified alignment, then set alignment from the type
4109 -- alignment. Perhaps we should always do this, but for sure we should
4110 -- do it when there is an address clause since we can do more if the
4111 -- alignment is known.
4113 if Unknown_Alignment (Obj) then
4114 Set_Alignment (Obj, Alignment (Etype (Obj)));
4117 -- Now do the internal call that does all the work
4119 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4120 end Has_Compatible_Alignment;
4122 ----------------------
4123 -- Has_Declarations --
4124 ----------------------
4126 function Has_Declarations (N : Node_Id) return Boolean is
4127 K : constant Node_Kind := Nkind (N);
4129 return K = N_Accept_Statement
4130 or else K = N_Block_Statement
4131 or else K = N_Compilation_Unit_Aux
4132 or else K = N_Entry_Body
4133 or else K = N_Package_Body
4134 or else K = N_Protected_Body
4135 or else K = N_Subprogram_Body
4136 or else K = N_Task_Body
4137 or else K = N_Package_Specification;
4138 end Has_Declarations;
4140 -------------------------------------------
4141 -- Has_Discriminant_Dependent_Constraint --
4142 -------------------------------------------
4144 function Has_Discriminant_Dependent_Constraint
4145 (Comp : Entity_Id) return Boolean
4147 Comp_Decl : constant Node_Id := Parent (Comp);
4148 Subt_Indic : constant Node_Id :=
4149 Subtype_Indication (Component_Definition (Comp_Decl));
4154 if Nkind (Subt_Indic) = N_Subtype_Indication then
4155 Constr := Constraint (Subt_Indic);
4157 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4158 Assn := First (Constraints (Constr));
4159 while Present (Assn) loop
4160 case Nkind (Assn) is
4161 when N_Subtype_Indication |
4165 if Depends_On_Discriminant (Assn) then
4169 when N_Discriminant_Association =>
4170 if Depends_On_Discriminant (Expression (Assn)) then
4185 end Has_Discriminant_Dependent_Constraint;
4187 --------------------
4188 -- Has_Infinities --
4189 --------------------
4191 function Has_Infinities (E : Entity_Id) return Boolean is
4194 Is_Floating_Point_Type (E)
4195 and then Nkind (Scalar_Range (E)) = N_Range
4196 and then Includes_Infinities (Scalar_Range (E));
4199 --------------------
4200 -- Has_Interfaces --
4201 --------------------
4203 function Has_Interfaces
4205 Use_Full_View : Boolean := True) return Boolean
4210 -- Handle concurrent types
4212 if Is_Concurrent_Type (T) then
4213 Typ := Corresponding_Record_Type (T);
4218 if not Present (Typ)
4219 or else not Is_Record_Type (Typ)
4220 or else not Is_Tagged_Type (Typ)
4225 -- Handle private types
4228 and then Present (Full_View (Typ))
4230 Typ := Full_View (Typ);
4233 -- Handle concurrent record types
4235 if Is_Concurrent_Record_Type (Typ)
4236 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4242 if Is_Interface (Typ)
4244 (Is_Record_Type (Typ)
4245 and then Present (Interfaces (Typ))
4246 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4251 exit when Etype (Typ) = Typ
4253 -- Handle private types
4255 or else (Present (Full_View (Etype (Typ)))
4256 and then Full_View (Etype (Typ)) = Typ)
4258 -- Protect the frontend against wrong source with cyclic
4261 or else Etype (Typ) = T;
4263 -- Climb to the ancestor type handling private types
4265 if Present (Full_View (Etype (Typ))) then
4266 Typ := Full_View (Etype (Typ));
4275 ------------------------
4276 -- Has_Null_Exclusion --
4277 ------------------------
4279 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4282 when N_Access_Definition |
4283 N_Access_Function_Definition |
4284 N_Access_Procedure_Definition |
4285 N_Access_To_Object_Definition |
4287 N_Derived_Type_Definition |
4288 N_Function_Specification |
4289 N_Subtype_Declaration =>
4290 return Null_Exclusion_Present (N);
4292 when N_Component_Definition |
4293 N_Formal_Object_Declaration |
4294 N_Object_Renaming_Declaration =>
4295 if Present (Subtype_Mark (N)) then
4296 return Null_Exclusion_Present (N);
4297 else pragma Assert (Present (Access_Definition (N)));
4298 return Null_Exclusion_Present (Access_Definition (N));
4301 when N_Discriminant_Specification =>
4302 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4303 return Null_Exclusion_Present (Discriminant_Type (N));
4305 return Null_Exclusion_Present (N);
4308 when N_Object_Declaration =>
4309 if Nkind (Object_Definition (N)) = N_Access_Definition then
4310 return Null_Exclusion_Present (Object_Definition (N));
4312 return Null_Exclusion_Present (N);
4315 when N_Parameter_Specification =>
4316 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4317 return Null_Exclusion_Present (Parameter_Type (N));
4319 return Null_Exclusion_Present (N);
4326 end Has_Null_Exclusion;
4328 ------------------------
4329 -- Has_Null_Extension --
4330 ------------------------
4332 function Has_Null_Extension (T : Entity_Id) return Boolean is
4333 B : constant Entity_Id := Base_Type (T);
4338 if Nkind (Parent (B)) = N_Full_Type_Declaration
4339 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4341 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4343 if Present (Ext) then
4344 if Null_Present (Ext) then
4347 Comps := Component_List (Ext);
4349 -- The null component list is rewritten during analysis to
4350 -- include the parent component. Any other component indicates
4351 -- that the extension was not originally null.
4353 return Null_Present (Comps)
4354 or else No (Next (First (Component_Items (Comps))));
4363 end Has_Null_Extension;
4365 -------------------------------
4366 -- Has_Overriding_Initialize --
4367 -------------------------------
4369 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4370 BT : constant Entity_Id := Base_Type (T);
4375 if Is_Controlled (BT) then
4377 -- For derived types, check immediate ancestor, excluding
4378 -- Controlled itself.
4380 if Is_Derived_Type (BT)
4381 and then not In_Predefined_Unit (Etype (BT))
4382 and then Has_Overriding_Initialize (Etype (BT))
4386 elsif Present (Primitive_Operations (BT)) then
4387 P := First_Elmt (Primitive_Operations (BT));
4388 while Present (P) loop
4389 if Chars (Node (P)) = Name_Initialize
4390 and then Comes_From_Source (Node (P))
4401 elsif Has_Controlled_Component (BT) then
4402 Comp := First_Component (BT);
4403 while Present (Comp) loop
4404 if Has_Overriding_Initialize (Etype (Comp)) then
4408 Next_Component (Comp);
4416 end Has_Overriding_Initialize;
4418 --------------------------------------
4419 -- Has_Preelaborable_Initialization --
4420 --------------------------------------
4422 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4425 procedure Check_Components (E : Entity_Id);
4426 -- Check component/discriminant chain, sets Has_PE False if a component
4427 -- or discriminant does not meet the preelaborable initialization rules.
4429 ----------------------
4430 -- Check_Components --
4431 ----------------------
4433 procedure Check_Components (E : Entity_Id) is
4437 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4438 -- Returns True if and only if the expression denoted by N does not
4439 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4441 ---------------------------------
4442 -- Is_Preelaborable_Expression --
4443 ---------------------------------
4445 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4449 Comp_Type : Entity_Id;
4450 Is_Array_Aggr : Boolean;
4453 if Is_Static_Expression (N) then
4456 elsif Nkind (N) = N_Null then
4459 -- Attributes are allowed in general, even if their prefix is a
4460 -- formal type. (It seems that certain attributes known not to be
4461 -- static might not be allowed, but there are no rules to prevent
4464 elsif Nkind (N) = N_Attribute_Reference then
4467 -- The name of a discriminant evaluated within its parent type is
4468 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4469 -- names that denote discriminals as well as discriminants to
4470 -- catch references occurring within init procs.
4472 elsif Is_Entity_Name (N)
4474 (Ekind (Entity (N)) = E_Discriminant
4476 ((Ekind (Entity (N)) = E_Constant
4477 or else Ekind (Entity (N)) = E_In_Parameter)
4478 and then Present (Discriminal_Link (Entity (N)))))
4482 elsif Nkind (N) = N_Qualified_Expression then
4483 return Is_Preelaborable_Expression (Expression (N));
4485 -- For aggregates we have to check that each of the associations
4486 -- is preelaborable.
4488 elsif Nkind (N) = N_Aggregate
4489 or else Nkind (N) = N_Extension_Aggregate
4491 Is_Array_Aggr := Is_Array_Type (Etype (N));
4493 if Is_Array_Aggr then
4494 Comp_Type := Component_Type (Etype (N));
4497 -- Check the ancestor part of extension aggregates, which must
4498 -- be either the name of a type that has preelaborable init or
4499 -- an expression that is preelaborable.
4501 if Nkind (N) = N_Extension_Aggregate then
4503 Anc_Part : constant Node_Id := Ancestor_Part (N);
4506 if Is_Entity_Name (Anc_Part)
4507 and then Is_Type (Entity (Anc_Part))
4509 if not Has_Preelaborable_Initialization
4515 elsif not Is_Preelaborable_Expression (Anc_Part) then
4521 -- Check positional associations
4523 Exp := First (Expressions (N));
4524 while Present (Exp) loop
4525 if not Is_Preelaborable_Expression (Exp) then
4532 -- Check named associations
4534 Assn := First (Component_Associations (N));
4535 while Present (Assn) loop
4536 Choice := First (Choices (Assn));
4537 while Present (Choice) loop
4538 if Is_Array_Aggr then
4539 if Nkind (Choice) = N_Others_Choice then
4542 elsif Nkind (Choice) = N_Range then
4543 if not Is_Static_Range (Choice) then
4547 elsif not Is_Static_Expression (Choice) then
4552 Comp_Type := Etype (Choice);
4558 -- If the association has a <> at this point, then we have
4559 -- to check whether the component's type has preelaborable
4560 -- initialization. Note that this only occurs when the
4561 -- association's corresponding component does not have a
4562 -- default expression, the latter case having already been
4563 -- expanded as an expression for the association.
4565 if Box_Present (Assn) then
4566 if not Has_Preelaborable_Initialization (Comp_Type) then
4570 -- In the expression case we check whether the expression
4571 -- is preelaborable.
4574 not Is_Preelaborable_Expression (Expression (Assn))
4582 -- If we get here then aggregate as a whole is preelaborable
4586 -- All other cases are not preelaborable
4591 end Is_Preelaborable_Expression;
4593 -- Start of processing for Check_Components
4596 -- Loop through entities of record or protected type
4599 while Present (Ent) loop
4601 -- We are interested only in components and discriminants
4603 if Ekind (Ent) = E_Component
4605 Ekind (Ent) = E_Discriminant
4607 -- Get default expression if any. If there is no declaration
4608 -- node, it means we have an internal entity. The parent and
4609 -- tag fields are examples of such entities. For these cases,
4610 -- we just test the type of the entity.
4612 if Present (Declaration_Node (Ent)) then
4613 Exp := Expression (Declaration_Node (Ent));
4618 -- A component has PI if it has no default expression and the
4619 -- component type has PI.
4622 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4627 -- Require the default expression to be preelaborable
4629 elsif not Is_Preelaborable_Expression (Exp) then
4637 end Check_Components;
4639 -- Start of processing for Has_Preelaborable_Initialization
4642 -- Immediate return if already marked as known preelaborable init. This
4643 -- covers types for which this function has already been called once
4644 -- and returned True (in which case the result is cached), and also
4645 -- types to which a pragma Preelaborable_Initialization applies.
4647 if Known_To_Have_Preelab_Init (E) then
4651 -- If the type is a subtype representing a generic actual type, then
4652 -- test whether its base type has preelaborable initialization since
4653 -- the subtype representing the actual does not inherit this attribute
4654 -- from the actual or formal. (but maybe it should???)
4656 if Is_Generic_Actual_Type (E) then
4657 return Has_Preelaborable_Initialization (Base_Type (E));
4660 -- All elementary types have preelaborable initialization
4662 if Is_Elementary_Type (E) then
4665 -- Array types have PI if the component type has PI
4667 elsif Is_Array_Type (E) then
4668 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4670 -- A derived type has preelaborable initialization if its parent type
4671 -- has preelaborable initialization and (in the case of a derived record
4672 -- extension) if the non-inherited components all have preelaborable
4673 -- initialization. However, a user-defined controlled type with an
4674 -- overriding Initialize procedure does not have preelaborable
4677 elsif Is_Derived_Type (E) then
4679 -- If the derived type is a private extension then it doesn't have
4680 -- preelaborable initialization.
4682 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
4686 -- First check whether ancestor type has preelaborable initialization
4688 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4690 -- If OK, check extension components (if any)
4692 if Has_PE and then Is_Record_Type (E) then
4693 Check_Components (First_Entity (E));
4696 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4697 -- with a user defined Initialize procedure does not have PI.
4700 and then Is_Controlled (E)
4701 and then Has_Overriding_Initialize (E)
4706 -- Private types not derived from a type having preelaborable init and
4707 -- that are not marked with pragma Preelaborable_Initialization do not
4708 -- have preelaborable initialization.
4710 elsif Is_Private_Type (E) then
4713 -- Record type has PI if it is non private and all components have PI
4715 elsif Is_Record_Type (E) then
4717 Check_Components (First_Entity (E));
4719 -- Protected types must not have entries, and components must meet
4720 -- same set of rules as for record components.
4722 elsif Is_Protected_Type (E) then
4723 if Has_Entries (E) then
4727 Check_Components (First_Entity (E));
4728 Check_Components (First_Private_Entity (E));
4731 -- Type System.Address always has preelaborable initialization
4733 elsif Is_RTE (E, RE_Address) then
4736 -- In all other cases, type does not have preelaborable initialization
4742 -- If type has preelaborable initialization, cache result
4745 Set_Known_To_Have_Preelab_Init (E);
4749 end Has_Preelaborable_Initialization;
4751 ---------------------------
4752 -- Has_Private_Component --
4753 ---------------------------
4755 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4756 Btype : Entity_Id := Base_Type (Type_Id);
4757 Component : Entity_Id;
4760 if Error_Posted (Type_Id)
4761 or else Error_Posted (Btype)
4766 if Is_Class_Wide_Type (Btype) then
4767 Btype := Root_Type (Btype);
4770 if Is_Private_Type (Btype) then
4772 UT : constant Entity_Id := Underlying_Type (Btype);
4775 if No (Full_View (Btype)) then
4776 return not Is_Generic_Type (Btype)
4777 and then not Is_Generic_Type (Root_Type (Btype));
4779 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4782 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4786 elsif Is_Array_Type (Btype) then
4787 return Has_Private_Component (Component_Type (Btype));
4789 elsif Is_Record_Type (Btype) then
4790 Component := First_Component (Btype);
4791 while Present (Component) loop
4792 if Has_Private_Component (Etype (Component)) then
4796 Next_Component (Component);
4801 elsif Is_Protected_Type (Btype)
4802 and then Present (Corresponding_Record_Type (Btype))
4804 return Has_Private_Component (Corresponding_Record_Type (Btype));
4809 end Has_Private_Component;
4815 function Has_Stream (T : Entity_Id) return Boolean is
4822 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4825 elsif Is_Array_Type (T) then
4826 return Has_Stream (Component_Type (T));
4828 elsif Is_Record_Type (T) then
4829 E := First_Component (T);
4830 while Present (E) loop
4831 if Has_Stream (Etype (E)) then
4840 elsif Is_Private_Type (T) then
4841 return Has_Stream (Underlying_Type (T));
4848 --------------------------
4849 -- Has_Tagged_Component --
4850 --------------------------
4852 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4856 if Is_Private_Type (Typ)
4857 and then Present (Underlying_Type (Typ))
4859 return Has_Tagged_Component (Underlying_Type (Typ));
4861 elsif Is_Array_Type (Typ) then
4862 return Has_Tagged_Component (Component_Type (Typ));
4864 elsif Is_Tagged_Type (Typ) then
4867 elsif Is_Record_Type (Typ) then
4868 Comp := First_Component (Typ);
4869 while Present (Comp) loop
4870 if Has_Tagged_Component (Etype (Comp)) then
4874 Next_Component (Comp);
4882 end Has_Tagged_Component;
4884 --------------------------
4885 -- Implements_Interface --
4886 --------------------------
4888 function Implements_Interface
4889 (Typ_Ent : Entity_Id;
4890 Iface_Ent : Entity_Id;
4891 Exclude_Parents : Boolean := False) return Boolean
4893 Ifaces_List : Elist_Id;
4899 if Is_Class_Wide_Type (Typ_Ent) then
4900 Typ := Etype (Typ_Ent);
4905 if Is_Class_Wide_Type (Iface_Ent) then
4906 Iface := Etype (Iface_Ent);
4911 if not Has_Interfaces (Typ) then
4915 Collect_Interfaces (Typ, Ifaces_List);
4917 Elmt := First_Elmt (Ifaces_List);
4918 while Present (Elmt) loop
4919 if Is_Ancestor (Node (Elmt), Typ)
4920 and then Exclude_Parents
4924 elsif Node (Elmt) = Iface then
4932 end Implements_Interface;
4938 function In_Instance return Boolean is
4939 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4945 and then S /= Standard_Standard
4947 if (Ekind (S) = E_Function
4948 or else Ekind (S) = E_Package
4949 or else Ekind (S) = E_Procedure)
4950 and then Is_Generic_Instance (S)
4952 -- A child instance is always compiled in the context of a parent
4953 -- instance. Nevertheless, the actuals are not analyzed in an
4954 -- instance context. We detect this case by examining the current
4955 -- compilation unit, which must be a child instance, and checking
4956 -- that it is not currently on the scope stack.
4958 if Is_Child_Unit (Curr_Unit)
4960 Nkind (Unit (Cunit (Current_Sem_Unit)))
4961 = N_Package_Instantiation
4962 and then not In_Open_Scopes (Curr_Unit)
4976 ----------------------
4977 -- In_Instance_Body --
4978 ----------------------
4980 function In_Instance_Body return Boolean is
4986 and then S /= Standard_Standard
4988 if (Ekind (S) = E_Function
4989 or else Ekind (S) = E_Procedure)
4990 and then Is_Generic_Instance (S)
4994 elsif Ekind (S) = E_Package
4995 and then In_Package_Body (S)
4996 and then Is_Generic_Instance (S)
5005 end In_Instance_Body;
5007 -----------------------------
5008 -- In_Instance_Not_Visible --
5009 -----------------------------
5011 function In_Instance_Not_Visible return Boolean is
5017 and then S /= Standard_Standard
5019 if (Ekind (S) = E_Function
5020 or else Ekind (S) = E_Procedure)
5021 and then Is_Generic_Instance (S)
5025 elsif Ekind (S) = E_Package
5026 and then (In_Package_Body (S) or else In_Private_Part (S))
5027 and then Is_Generic_Instance (S)
5036 end In_Instance_Not_Visible;
5038 ------------------------------
5039 -- In_Instance_Visible_Part --
5040 ------------------------------
5042 function In_Instance_Visible_Part return Boolean is
5048 and then S /= Standard_Standard
5050 if Ekind (S) = E_Package
5051 and then Is_Generic_Instance (S)
5052 and then not In_Package_Body (S)
5053 and then not In_Private_Part (S)
5062 end In_Instance_Visible_Part;
5064 ---------------------
5065 -- In_Package_Body --
5066 ---------------------
5068 function In_Package_Body return Boolean is
5074 and then S /= Standard_Standard
5076 if Ekind (S) = E_Package
5077 and then In_Package_Body (S)
5086 end In_Package_Body;
5088 --------------------------------
5089 -- In_Parameter_Specification --
5090 --------------------------------
5092 function In_Parameter_Specification (N : Node_Id) return Boolean is
5097 while Present (PN) loop
5098 if Nkind (PN) = N_Parameter_Specification then
5106 end In_Parameter_Specification;
5108 --------------------------------------
5109 -- In_Subprogram_Or_Concurrent_Unit --
5110 --------------------------------------
5112 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5117 -- Use scope chain to check successively outer scopes
5123 if K in Subprogram_Kind
5124 or else K in Concurrent_Kind
5125 or else K in Generic_Subprogram_Kind
5129 elsif E = Standard_Standard then
5135 end In_Subprogram_Or_Concurrent_Unit;
5137 ---------------------
5138 -- In_Visible_Part --
5139 ---------------------
5141 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5144 Is_Package_Or_Generic_Package (Scope_Id)
5145 and then In_Open_Scopes (Scope_Id)
5146 and then not In_Package_Body (Scope_Id)
5147 and then not In_Private_Part (Scope_Id);
5148 end In_Visible_Part;
5150 ---------------------------------
5151 -- Insert_Explicit_Dereference --
5152 ---------------------------------
5154 procedure Insert_Explicit_Dereference (N : Node_Id) is
5155 New_Prefix : constant Node_Id := Relocate_Node (N);
5156 Ent : Entity_Id := Empty;
5163 Save_Interps (N, New_Prefix);
5164 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5166 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5168 if Is_Overloaded (New_Prefix) then
5170 -- The deference is also overloaded, and its interpretations are the
5171 -- designated types of the interpretations of the original node.
5173 Set_Etype (N, Any_Type);
5175 Get_First_Interp (New_Prefix, I, It);
5176 while Present (It.Nam) loop
5179 if Is_Access_Type (T) then
5180 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5183 Get_Next_Interp (I, It);
5189 -- Prefix is unambiguous: mark the original prefix (which might
5190 -- Come_From_Source) as a reference, since the new (relocated) one
5191 -- won't be taken into account.
5193 if Is_Entity_Name (New_Prefix) then
5194 Ent := Entity (New_Prefix);
5196 -- For a retrieval of a subcomponent of some composite object,
5197 -- retrieve the ultimate entity if there is one.
5199 elsif Nkind (New_Prefix) = N_Selected_Component
5200 or else Nkind (New_Prefix) = N_Indexed_Component
5202 Pref := Prefix (New_Prefix);
5203 while Present (Pref)
5205 (Nkind (Pref) = N_Selected_Component
5206 or else Nkind (Pref) = N_Indexed_Component)
5208 Pref := Prefix (Pref);
5211 if Present (Pref) and then Is_Entity_Name (Pref) then
5212 Ent := Entity (Pref);
5216 if Present (Ent) then
5217 Generate_Reference (Ent, New_Prefix);
5220 end Insert_Explicit_Dereference;
5222 ------------------------------------------
5223 -- Inspect_Deferred_Constant_Completion --
5224 ------------------------------------------
5226 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5230 Decl := First (Decls);
5231 while Present (Decl) loop
5233 -- Deferred constant signature
5235 if Nkind (Decl) = N_Object_Declaration
5236 and then Constant_Present (Decl)
5237 and then No (Expression (Decl))
5239 -- No need to check internally generated constants
5241 and then Comes_From_Source (Decl)
5243 -- The constant is not completed. A full object declaration
5244 -- or a pragma Import complete a deferred constant.
5246 and then not Has_Completion (Defining_Identifier (Decl))
5249 ("constant declaration requires initialization expression",
5250 Defining_Identifier (Decl));
5253 Decl := Next (Decl);
5255 end Inspect_Deferred_Constant_Completion;
5261 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5262 pragma Assert (Is_Type (E));
5264 return AAMP_On_Target
5265 and then Is_Floating_Point_Type (E)
5266 and then E = Base_Type (E);
5269 -------------------------
5270 -- Is_Actual_Parameter --
5271 -------------------------
5273 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5274 PK : constant Node_Kind := Nkind (Parent (N));
5278 when N_Parameter_Association =>
5279 return N = Explicit_Actual_Parameter (Parent (N));
5281 when N_Function_Call | N_Procedure_Call_Statement =>
5282 return Is_List_Member (N)
5284 List_Containing (N) = Parameter_Associations (Parent (N));
5289 end Is_Actual_Parameter;
5291 ---------------------
5292 -- Is_Aliased_View --
5293 ---------------------
5295 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5299 if Is_Entity_Name (Obj) then
5307 or else (Present (Renamed_Object (E))
5308 and then Is_Aliased_View (Renamed_Object (E)))))
5310 or else ((Is_Formal (E)
5311 or else Ekind (E) = E_Generic_In_Out_Parameter
5312 or else Ekind (E) = E_Generic_In_Parameter)
5313 and then Is_Tagged_Type (Etype (E)))
5315 or else (Is_Concurrent_Type (E)
5316 and then In_Open_Scopes (E))
5318 -- Current instance of type, either directly or as rewritten
5319 -- reference to the current object.
5321 or else (Is_Entity_Name (Original_Node (Obj))
5322 and then Present (Entity (Original_Node (Obj)))
5323 and then Is_Type (Entity (Original_Node (Obj))))
5325 or else (Is_Type (E) and then E = Current_Scope)
5327 or else (Is_Incomplete_Or_Private_Type (E)
5328 and then Full_View (E) = Current_Scope);
5330 elsif Nkind (Obj) = N_Selected_Component then
5331 return Is_Aliased (Entity (Selector_Name (Obj)));
5333 elsif Nkind (Obj) = N_Indexed_Component then
5334 return Has_Aliased_Components (Etype (Prefix (Obj)))
5336 (Is_Access_Type (Etype (Prefix (Obj)))
5338 Has_Aliased_Components
5339 (Designated_Type (Etype (Prefix (Obj)))));
5341 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5342 or else Nkind (Obj) = N_Type_Conversion
5344 return Is_Tagged_Type (Etype (Obj))
5345 and then Is_Aliased_View (Expression (Obj));
5347 elsif Nkind (Obj) = N_Explicit_Dereference then
5348 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5353 end Is_Aliased_View;
5355 -------------------------
5356 -- Is_Ancestor_Package --
5357 -------------------------
5359 function Is_Ancestor_Package
5361 E2 : Entity_Id) return Boolean
5368 and then Par /= Standard_Standard
5378 end Is_Ancestor_Package;
5380 ----------------------
5381 -- Is_Atomic_Object --
5382 ----------------------
5384 function Is_Atomic_Object (N : Node_Id) return Boolean is
5386 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5387 -- Determines if given object has atomic components
5389 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5390 -- If prefix is an implicit dereference, examine designated type
5392 ----------------------
5393 -- Is_Atomic_Prefix --
5394 ----------------------
5396 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5398 if Is_Access_Type (Etype (N)) then
5400 Has_Atomic_Components (Designated_Type (Etype (N)));
5402 return Object_Has_Atomic_Components (N);
5404 end Is_Atomic_Prefix;
5406 ----------------------------------
5407 -- Object_Has_Atomic_Components --
5408 ----------------------------------
5410 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5412 if Has_Atomic_Components (Etype (N))
5413 or else Is_Atomic (Etype (N))
5417 elsif Is_Entity_Name (N)
5418 and then (Has_Atomic_Components (Entity (N))
5419 or else Is_Atomic (Entity (N)))
5423 elsif Nkind (N) = N_Indexed_Component
5424 or else Nkind (N) = N_Selected_Component
5426 return Is_Atomic_Prefix (Prefix (N));
5431 end Object_Has_Atomic_Components;
5433 -- Start of processing for Is_Atomic_Object
5436 if Is_Atomic (Etype (N))
5437 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5441 elsif Nkind (N) = N_Indexed_Component
5442 or else Nkind (N) = N_Selected_Component
5444 return Is_Atomic_Prefix (Prefix (N));
5449 end Is_Atomic_Object;
5451 -------------------------
5452 -- Is_Coextension_Root --
5453 -------------------------
5455 function Is_Coextension_Root (N : Node_Id) return Boolean is
5458 Nkind (N) = N_Allocator
5459 and then Present (Coextensions (N))
5461 -- Anonymous access discriminants carry a list of all nested
5462 -- controlled coextensions.
5464 and then not Is_Dynamic_Coextension (N)
5465 and then not Is_Static_Coextension (N);
5466 end Is_Coextension_Root;
5468 -----------------------------
5469 -- Is_Concurrent_Interface --
5470 -----------------------------
5472 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5477 (Is_Protected_Interface (T)
5478 or else Is_Synchronized_Interface (T)
5479 or else Is_Task_Interface (T));
5480 end Is_Concurrent_Interface;
5482 --------------------------------------
5483 -- Is_Controlling_Limited_Procedure --
5484 --------------------------------------
5486 function Is_Controlling_Limited_Procedure
5487 (Proc_Nam : Entity_Id) return Boolean
5489 Param_Typ : Entity_Id := Empty;
5492 if Ekind (Proc_Nam) = E_Procedure
5493 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5495 Param_Typ := Etype (Parameter_Type (First (
5496 Parameter_Specifications (Parent (Proc_Nam)))));
5498 -- In this case where an Itype was created, the procedure call has been
5501 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5502 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5504 Present (Parameter_Associations
5505 (Associated_Node_For_Itype (Proc_Nam)))
5508 Etype (First (Parameter_Associations
5509 (Associated_Node_For_Itype (Proc_Nam))));
5512 if Present (Param_Typ) then
5514 Is_Interface (Param_Typ)
5515 and then Is_Limited_Record (Param_Typ);
5519 end Is_Controlling_Limited_Procedure;
5521 -----------------------------
5522 -- Is_CPP_Constructor_Call --
5523 -----------------------------
5525 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5527 return Nkind (N) = N_Function_Call
5528 and then Is_Class_Wide_Type (Etype (N))
5529 and then Is_CPP_Class (Etype (Etype (N)))
5530 and then Is_Constructor (Entity (Name (N)))
5531 and then Is_Imported (Entity (Name (N)));
5532 end Is_CPP_Constructor_Call;
5534 ----------------------------------------------
5535 -- Is_Dependent_Component_Of_Mutable_Object --
5536 ----------------------------------------------
5538 function Is_Dependent_Component_Of_Mutable_Object
5539 (Object : Node_Id) return Boolean
5542 Prefix_Type : Entity_Id;
5543 P_Aliased : Boolean := False;
5546 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5547 -- Returns True if and only if Comp is declared within a variant part
5549 --------------------------------
5550 -- Is_Declared_Within_Variant --
5551 --------------------------------
5553 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5554 Comp_Decl : constant Node_Id := Parent (Comp);
5555 Comp_List : constant Node_Id := Parent (Comp_Decl);
5557 return Nkind (Parent (Comp_List)) = N_Variant;
5558 end Is_Declared_Within_Variant;
5560 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5563 if Is_Variable (Object) then
5565 if Nkind (Object) = N_Selected_Component then
5566 P := Prefix (Object);
5567 Prefix_Type := Etype (P);
5569 if Is_Entity_Name (P) then
5571 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5572 Prefix_Type := Base_Type (Prefix_Type);
5575 if Is_Aliased (Entity (P)) then
5579 -- A discriminant check on a selected component may be
5580 -- expanded into a dereference when removing side-effects.
5581 -- Recover the original node and its type, which may be
5584 elsif Nkind (P) = N_Explicit_Dereference
5585 and then not (Comes_From_Source (P))
5587 P := Original_Node (P);
5588 Prefix_Type := Etype (P);
5591 -- Check for prefix being an aliased component ???
5596 -- A heap object is constrained by its initial value
5598 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5599 -- the dereferenced case, since the access value might denote an
5600 -- unconstrained aliased object, whereas in Ada 95 the designated
5601 -- object is guaranteed to be constrained. A worst-case assumption
5602 -- has to apply in Ada 2005 because we can't tell at compile time
5603 -- whether the object is "constrained by its initial value"
5604 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5605 -- semantic rules -- these rules are acknowledged to need fixing).
5607 if Ada_Version < Ada_05 then
5608 if Is_Access_Type (Prefix_Type)
5609 or else Nkind (P) = N_Explicit_Dereference
5614 elsif Ada_Version >= Ada_05 then
5615 if Is_Access_Type (Prefix_Type) then
5617 -- If the access type is pool-specific, and there is no
5618 -- constrained partial view of the designated type, then the
5619 -- designated object is known to be constrained.
5621 if Ekind (Prefix_Type) = E_Access_Type
5622 and then not Has_Constrained_Partial_View
5623 (Designated_Type (Prefix_Type))
5627 -- Otherwise (general access type, or there is a constrained
5628 -- partial view of the designated type), we need to check
5629 -- based on the designated type.
5632 Prefix_Type := Designated_Type (Prefix_Type);
5638 Original_Record_Component (Entity (Selector_Name (Object)));
5640 -- As per AI-0017, the renaming is illegal in a generic body,
5641 -- even if the subtype is indefinite.
5643 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5645 if not Is_Constrained (Prefix_Type)
5646 and then (not Is_Indefinite_Subtype (Prefix_Type)
5648 (Is_Generic_Type (Prefix_Type)
5649 and then Ekind (Current_Scope) = E_Generic_Package
5650 and then In_Package_Body (Current_Scope)))
5652 and then (Is_Declared_Within_Variant (Comp)
5653 or else Has_Discriminant_Dependent_Constraint (Comp))
5654 and then (not P_Aliased or else Ada_Version >= Ada_05)
5660 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5664 elsif Nkind (Object) = N_Indexed_Component
5665 or else Nkind (Object) = N_Slice
5667 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5669 -- A type conversion that Is_Variable is a view conversion:
5670 -- go back to the denoted object.
5672 elsif Nkind (Object) = N_Type_Conversion then
5674 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5679 end Is_Dependent_Component_Of_Mutable_Object;
5681 ---------------------
5682 -- Is_Dereferenced --
5683 ---------------------
5685 function Is_Dereferenced (N : Node_Id) return Boolean is
5686 P : constant Node_Id := Parent (N);
5689 (Nkind (P) = N_Selected_Component
5691 Nkind (P) = N_Explicit_Dereference
5693 Nkind (P) = N_Indexed_Component
5695 Nkind (P) = N_Slice)
5696 and then Prefix (P) = N;
5697 end Is_Dereferenced;
5699 ----------------------
5700 -- Is_Descendent_Of --
5701 ----------------------
5703 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5708 pragma Assert (Nkind (T1) in N_Entity);
5709 pragma Assert (Nkind (T2) in N_Entity);
5711 T := Base_Type (T1);
5713 -- Immediate return if the types match
5718 -- Comment needed here ???
5720 elsif Ekind (T) = E_Class_Wide_Type then
5721 return Etype (T) = T2;
5729 -- Done if we found the type we are looking for
5734 -- Done if no more derivations to check
5741 -- Following test catches error cases resulting from prev errors
5743 elsif No (Etyp) then
5746 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5749 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5753 T := Base_Type (Etyp);
5756 end Is_Descendent_Of;
5762 function Is_False (U : Uint) return Boolean is
5767 ---------------------------
5768 -- Is_Fixed_Model_Number --
5769 ---------------------------
5771 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5772 S : constant Ureal := Small_Value (T);
5773 M : Urealp.Save_Mark;
5777 R := (U = UR_Trunc (U / S) * S);
5780 end Is_Fixed_Model_Number;
5782 -------------------------------
5783 -- Is_Fully_Initialized_Type --
5784 -------------------------------
5786 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5788 if Is_Scalar_Type (Typ) then
5791 elsif Is_Access_Type (Typ) then
5794 elsif Is_Array_Type (Typ) then
5795 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5799 -- An interesting case, if we have a constrained type one of whose
5800 -- bounds is known to be null, then there are no elements to be
5801 -- initialized, so all the elements are initialized!
5803 if Is_Constrained (Typ) then
5806 Indx_Typ : Entity_Id;
5810 Indx := First_Index (Typ);
5811 while Present (Indx) loop
5812 if Etype (Indx) = Any_Type then
5815 -- If index is a range, use directly
5817 elsif Nkind (Indx) = N_Range then
5818 Lbd := Low_Bound (Indx);
5819 Hbd := High_Bound (Indx);
5822 Indx_Typ := Etype (Indx);
5824 if Is_Private_Type (Indx_Typ) then
5825 Indx_Typ := Full_View (Indx_Typ);
5828 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5831 Lbd := Type_Low_Bound (Indx_Typ);
5832 Hbd := Type_High_Bound (Indx_Typ);
5836 if Compile_Time_Known_Value (Lbd)
5837 and then Compile_Time_Known_Value (Hbd)
5839 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5849 -- If no null indexes, then type is not fully initialized
5855 elsif Is_Record_Type (Typ) then
5856 if Has_Discriminants (Typ)
5858 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5859 and then Is_Fully_Initialized_Variant (Typ)
5864 -- Controlled records are considered to be fully initialized if
5865 -- there is a user defined Initialize routine. This may not be
5866 -- entirely correct, but as the spec notes, we are guessing here
5867 -- what is best from the point of view of issuing warnings.
5869 if Is_Controlled (Typ) then
5871 Utyp : constant Entity_Id := Underlying_Type (Typ);
5874 if Present (Utyp) then
5876 Init : constant Entity_Id :=
5878 (Underlying_Type (Typ), Name_Initialize));
5882 and then Comes_From_Source (Init)
5884 Is_Predefined_File_Name
5885 (File_Name (Get_Source_File_Index (Sloc (Init))))
5889 elsif Has_Null_Extension (Typ)
5891 Is_Fully_Initialized_Type
5892 (Etype (Base_Type (Typ)))
5901 -- Otherwise see if all record components are initialized
5907 Ent := First_Entity (Typ);
5908 while Present (Ent) loop
5909 if Chars (Ent) = Name_uController then
5912 elsif Ekind (Ent) = E_Component
5913 and then (No (Parent (Ent))
5914 or else No (Expression (Parent (Ent))))
5915 and then not Is_Fully_Initialized_Type (Etype (Ent))
5917 -- Special VM case for tag components, which need to be
5918 -- defined in this case, but are never initialized as VMs
5919 -- are using other dispatching mechanisms. Ignore this
5920 -- uninitialized case. Note that this applies both to the
5921 -- uTag entry and the main vtable pointer (CPP_Class case).
5923 and then (VM_Target = No_VM or else not Is_Tag (Ent))
5932 -- No uninitialized components, so type is fully initialized.
5933 -- Note that this catches the case of no components as well.
5937 elsif Is_Concurrent_Type (Typ) then
5940 elsif Is_Private_Type (Typ) then
5942 U : constant Entity_Id := Underlying_Type (Typ);
5948 return Is_Fully_Initialized_Type (U);
5955 end Is_Fully_Initialized_Type;
5957 ----------------------------------
5958 -- Is_Fully_Initialized_Variant --
5959 ----------------------------------
5961 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5962 Loc : constant Source_Ptr := Sloc (Typ);
5963 Constraints : constant List_Id := New_List;
5964 Components : constant Elist_Id := New_Elmt_List;
5965 Comp_Elmt : Elmt_Id;
5967 Comp_List : Node_Id;
5969 Discr_Val : Node_Id;
5971 Report_Errors : Boolean;
5972 pragma Warnings (Off, Report_Errors);
5975 if Serious_Errors_Detected > 0 then
5979 if Is_Record_Type (Typ)
5980 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5981 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5983 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5985 Discr := First_Discriminant (Typ);
5986 while Present (Discr) loop
5987 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5988 Discr_Val := Expression (Parent (Discr));
5990 if Present (Discr_Val)
5991 and then Is_OK_Static_Expression (Discr_Val)
5993 Append_To (Constraints,
5994 Make_Component_Association (Loc,
5995 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5996 Expression => New_Copy (Discr_Val)));
6004 Next_Discriminant (Discr);
6009 Comp_List => Comp_List,
6010 Governed_By => Constraints,
6012 Report_Errors => Report_Errors);
6014 -- Check that each component present is fully initialized
6016 Comp_Elmt := First_Elmt (Components);
6017 while Present (Comp_Elmt) loop
6018 Comp_Id := Node (Comp_Elmt);
6020 if Ekind (Comp_Id) = E_Component
6021 and then (No (Parent (Comp_Id))
6022 or else No (Expression (Parent (Comp_Id))))
6023 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6028 Next_Elmt (Comp_Elmt);
6033 elsif Is_Private_Type (Typ) then
6035 U : constant Entity_Id := Underlying_Type (Typ);
6041 return Is_Fully_Initialized_Variant (U);
6047 end Is_Fully_Initialized_Variant;
6049 ----------------------------
6050 -- Is_Inherited_Operation --
6051 ----------------------------
6053 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6054 Kind : constant Node_Kind := Nkind (Parent (E));
6056 pragma Assert (Is_Overloadable (E));
6057 return Kind = N_Full_Type_Declaration
6058 or else Kind = N_Private_Extension_Declaration
6059 or else Kind = N_Subtype_Declaration
6060 or else (Ekind (E) = E_Enumeration_Literal
6061 and then Is_Derived_Type (Etype (E)));
6062 end Is_Inherited_Operation;
6064 -----------------------------
6065 -- Is_Library_Level_Entity --
6066 -----------------------------
6068 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6070 -- The following is a small optimization, and it also properly handles
6071 -- discriminals, which in task bodies might appear in expressions before
6072 -- the corresponding procedure has been created, and which therefore do
6073 -- not have an assigned scope.
6075 if Ekind (E) in Formal_Kind then
6079 -- Normal test is simply that the enclosing dynamic scope is Standard
6081 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6082 end Is_Library_Level_Entity;
6084 ---------------------------------
6085 -- Is_Local_Variable_Reference --
6086 ---------------------------------
6088 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6090 if not Is_Entity_Name (Expr) then
6095 Ent : constant Entity_Id := Entity (Expr);
6096 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6098 if Ekind (Ent) /= E_Variable
6100 Ekind (Ent) /= E_In_Out_Parameter
6104 return Present (Sub) and then Sub = Current_Subprogram;
6108 end Is_Local_Variable_Reference;
6110 -------------------------
6111 -- Is_Object_Reference --
6112 -------------------------
6114 function Is_Object_Reference (N : Node_Id) return Boolean is
6116 if Is_Entity_Name (N) then
6117 return Present (Entity (N)) and then Is_Object (Entity (N));
6121 when N_Indexed_Component | N_Slice =>
6123 Is_Object_Reference (Prefix (N))
6124 or else Is_Access_Type (Etype (Prefix (N)));
6126 -- In Ada95, a function call is a constant object; a procedure
6129 when N_Function_Call =>
6130 return Etype (N) /= Standard_Void_Type;
6132 -- A reference to the stream attribute Input is a function call
6134 when N_Attribute_Reference =>
6135 return Attribute_Name (N) = Name_Input;
6137 when N_Selected_Component =>
6139 Is_Object_Reference (Selector_Name (N))
6141 (Is_Object_Reference (Prefix (N))
6142 or else Is_Access_Type (Etype (Prefix (N))));
6144 when N_Explicit_Dereference =>
6147 -- A view conversion of a tagged object is an object reference
6149 when N_Type_Conversion =>
6150 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6151 and then Is_Tagged_Type (Etype (Expression (N)))
6152 and then Is_Object_Reference (Expression (N));
6154 -- An unchecked type conversion is considered to be an object if
6155 -- the operand is an object (this construction arises only as a
6156 -- result of expansion activities).
6158 when N_Unchecked_Type_Conversion =>
6165 end Is_Object_Reference;
6167 -----------------------------------
6168 -- Is_OK_Variable_For_Out_Formal --
6169 -----------------------------------
6171 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6173 Note_Possible_Modification (AV, Sure => True);
6175 -- We must reject parenthesized variable names. The check for
6176 -- Comes_From_Source is present because there are currently
6177 -- cases where the compiler violates this rule (e.g. passing
6178 -- a task object to its controlled Initialize routine).
6180 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6183 -- A variable is always allowed
6185 elsif Is_Variable (AV) then
6188 -- Unchecked conversions are allowed only if they come from the
6189 -- generated code, which sometimes uses unchecked conversions for out
6190 -- parameters in cases where code generation is unaffected. We tell
6191 -- source unchecked conversions by seeing if they are rewrites of an
6192 -- original Unchecked_Conversion function call, or of an explicit
6193 -- conversion of a function call.
6195 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6196 if Nkind (Original_Node (AV)) = N_Function_Call then
6199 elsif Comes_From_Source (AV)
6200 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6204 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6205 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6211 -- Normal type conversions are allowed if argument is a variable
6213 elsif Nkind (AV) = N_Type_Conversion then
6214 if Is_Variable (Expression (AV))
6215 and then Paren_Count (Expression (AV)) = 0
6217 Note_Possible_Modification (Expression (AV), Sure => True);
6220 -- We also allow a non-parenthesized expression that raises
6221 -- constraint error if it rewrites what used to be a variable
6223 elsif Raises_Constraint_Error (Expression (AV))
6224 and then Paren_Count (Expression (AV)) = 0
6225 and then Is_Variable (Original_Node (Expression (AV)))
6229 -- Type conversion of something other than a variable
6235 -- If this node is rewritten, then test the original form, if that is
6236 -- OK, then we consider the rewritten node OK (for example, if the
6237 -- original node is a conversion, then Is_Variable will not be true
6238 -- but we still want to allow the conversion if it converts a variable).
6240 elsif Original_Node (AV) /= AV then
6241 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6243 -- All other non-variables are rejected
6248 end Is_OK_Variable_For_Out_Formal;
6250 -----------------------------------
6251 -- Is_Partially_Initialized_Type --
6252 -----------------------------------
6254 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6256 if Is_Scalar_Type (Typ) then
6259 elsif Is_Access_Type (Typ) then
6262 elsif Is_Array_Type (Typ) then
6264 -- If component type is partially initialized, so is array type
6266 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6269 -- Otherwise we are only partially initialized if we are fully
6270 -- initialized (this is the empty array case, no point in us
6271 -- duplicating that code here).
6274 return Is_Fully_Initialized_Type (Typ);
6277 elsif Is_Record_Type (Typ) then
6279 -- A discriminated type is always partially initialized
6281 if Has_Discriminants (Typ) then
6284 -- A tagged type is always partially initialized
6286 elsif Is_Tagged_Type (Typ) then
6289 -- Case of non-discriminated record
6295 Component_Present : Boolean := False;
6296 -- Set True if at least one component is present. If no
6297 -- components are present, then record type is fully
6298 -- initialized (another odd case, like the null array).
6301 -- Loop through components
6303 Ent := First_Entity (Typ);
6304 while Present (Ent) loop
6305 if Ekind (Ent) = E_Component then
6306 Component_Present := True;
6308 -- If a component has an initialization expression then
6309 -- the enclosing record type is partially initialized
6311 if Present (Parent (Ent))
6312 and then Present (Expression (Parent (Ent)))
6316 -- If a component is of a type which is itself partially
6317 -- initialized, then the enclosing record type is also.
6319 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6327 -- No initialized components found. If we found any components
6328 -- they were all uninitialized so the result is false.
6330 if Component_Present then
6333 -- But if we found no components, then all the components are
6334 -- initialized so we consider the type to be initialized.
6342 -- Concurrent types are always fully initialized
6344 elsif Is_Concurrent_Type (Typ) then
6347 -- For a private type, go to underlying type. If there is no underlying
6348 -- type then just assume this partially initialized. Not clear if this
6349 -- can happen in a non-error case, but no harm in testing for this.
6351 elsif Is_Private_Type (Typ) then
6353 U : constant Entity_Id := Underlying_Type (Typ);
6358 return Is_Partially_Initialized_Type (U);
6362 -- For any other type (are there any?) assume partially initialized
6367 end Is_Partially_Initialized_Type;
6369 ------------------------------------
6370 -- Is_Potentially_Persistent_Type --
6371 ------------------------------------
6373 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6378 -- For private type, test corresponding full type
6380 if Is_Private_Type (T) then
6381 return Is_Potentially_Persistent_Type (Full_View (T));
6383 -- Scalar types are potentially persistent
6385 elsif Is_Scalar_Type (T) then
6388 -- Record type is potentially persistent if not tagged and the types of
6389 -- all it components are potentially persistent, and no component has
6390 -- an initialization expression.
6392 elsif Is_Record_Type (T)
6393 and then not Is_Tagged_Type (T)
6394 and then not Is_Partially_Initialized_Type (T)
6396 Comp := First_Component (T);
6397 while Present (Comp) loop
6398 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6407 -- Array type is potentially persistent if its component type is
6408 -- potentially persistent and if all its constraints are static.
6410 elsif Is_Array_Type (T) then
6411 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6415 Indx := First_Index (T);
6416 while Present (Indx) loop
6417 if not Is_OK_Static_Subtype (Etype (Indx)) then
6426 -- All other types are not potentially persistent
6431 end Is_Potentially_Persistent_Type;
6433 ---------------------------------
6434 -- Is_Protected_Self_Reference --
6435 ---------------------------------
6437 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6439 function In_Access_Definition (N : Node_Id) return Boolean;
6440 -- Returns true if N belongs to an access definition
6442 --------------------------
6443 -- In_Access_Definition --
6444 --------------------------
6446 function In_Access_Definition (N : Node_Id) return Boolean is
6451 while Present (P) loop
6452 if Nkind (P) = N_Access_Definition then
6460 end In_Access_Definition;
6462 -- Start of processing for Is_Protected_Self_Reference
6465 -- Verify that prefix is analyzed and has the proper form. Note that
6466 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6467 -- produce the address of an entity, do not analyze their prefix
6468 -- because they denote entities that are not necessarily visible.
6469 -- Neither of them can apply to a protected type.
6471 return Ada_Version >= Ada_05
6472 and then Is_Entity_Name (N)
6473 and then Present (Entity (N))
6474 and then Is_Protected_Type (Entity (N))
6475 and then In_Open_Scopes (Entity (N))
6476 and then not In_Access_Definition (N);
6477 end Is_Protected_Self_Reference;
6479 -----------------------------
6480 -- Is_RCI_Pkg_Spec_Or_Body --
6481 -----------------------------
6483 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6485 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6486 -- Return True if the unit of Cunit is an RCI package declaration
6488 ---------------------------
6489 -- Is_RCI_Pkg_Decl_Cunit --
6490 ---------------------------
6492 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6493 The_Unit : constant Node_Id := Unit (Cunit);
6496 if Nkind (The_Unit) /= N_Package_Declaration then
6500 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6501 end Is_RCI_Pkg_Decl_Cunit;
6503 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6506 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6508 (Nkind (Unit (Cunit)) = N_Package_Body
6509 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6510 end Is_RCI_Pkg_Spec_Or_Body;
6512 -----------------------------------------
6513 -- Is_Remote_Access_To_Class_Wide_Type --
6514 -----------------------------------------
6516 function Is_Remote_Access_To_Class_Wide_Type
6517 (E : Entity_Id) return Boolean
6520 -- A remote access to class-wide type is a general access to object type
6521 -- declared in the visible part of a Remote_Types or Remote_Call_
6524 return Ekind (E) = E_General_Access_Type
6525 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6526 end Is_Remote_Access_To_Class_Wide_Type;
6528 -----------------------------------------
6529 -- Is_Remote_Access_To_Subprogram_Type --
6530 -----------------------------------------
6532 function Is_Remote_Access_To_Subprogram_Type
6533 (E : Entity_Id) return Boolean
6536 return (Ekind (E) = E_Access_Subprogram_Type
6537 or else (Ekind (E) = E_Record_Type
6538 and then Present (Corresponding_Remote_Type (E))))
6539 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6540 end Is_Remote_Access_To_Subprogram_Type;
6542 --------------------
6543 -- Is_Remote_Call --
6544 --------------------
6546 function Is_Remote_Call (N : Node_Id) return Boolean is
6548 if Nkind (N) /= N_Procedure_Call_Statement
6549 and then Nkind (N) /= N_Function_Call
6551 -- An entry call cannot be remote
6555 elsif Nkind (Name (N)) in N_Has_Entity
6556 and then Is_Remote_Call_Interface (Entity (Name (N)))
6558 -- A subprogram declared in the spec of a RCI package is remote
6562 elsif Nkind (Name (N)) = N_Explicit_Dereference
6563 and then Is_Remote_Access_To_Subprogram_Type
6564 (Etype (Prefix (Name (N))))
6566 -- The dereference of a RAS is a remote call
6570 elsif Present (Controlling_Argument (N))
6571 and then Is_Remote_Access_To_Class_Wide_Type
6572 (Etype (Controlling_Argument (N)))
6574 -- Any primitive operation call with a controlling argument of
6575 -- a RACW type is a remote call.
6580 -- All other calls are local calls
6585 ----------------------
6586 -- Is_Renamed_Entry --
6587 ----------------------
6589 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6590 Orig_Node : Node_Id := Empty;
6591 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6593 function Is_Entry (Nam : Node_Id) return Boolean;
6594 -- Determine whether Nam is an entry. Traverse selectors if there are
6595 -- nested selected components.
6601 function Is_Entry (Nam : Node_Id) return Boolean is
6603 if Nkind (Nam) = N_Selected_Component then
6604 return Is_Entry (Selector_Name (Nam));
6607 return Ekind (Entity (Nam)) = E_Entry;
6610 -- Start of processing for Is_Renamed_Entry
6613 if Present (Alias (Proc_Nam)) then
6614 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6617 -- Look for a rewritten subprogram renaming declaration
6619 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6620 and then Present (Original_Node (Subp_Decl))
6622 Orig_Node := Original_Node (Subp_Decl);
6625 -- The rewritten subprogram is actually an entry
6627 if Present (Orig_Node)
6628 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6629 and then Is_Entry (Name (Orig_Node))
6635 end Is_Renamed_Entry;
6637 ----------------------
6638 -- Is_Selector_Name --
6639 ----------------------
6641 function Is_Selector_Name (N : Node_Id) return Boolean is
6643 if not Is_List_Member (N) then
6645 P : constant Node_Id := Parent (N);
6646 K : constant Node_Kind := Nkind (P);
6649 (K = N_Expanded_Name or else
6650 K = N_Generic_Association or else
6651 K = N_Parameter_Association or else
6652 K = N_Selected_Component)
6653 and then Selector_Name (P) = N;
6658 L : constant List_Id := List_Containing (N);
6659 P : constant Node_Id := Parent (L);
6661 return (Nkind (P) = N_Discriminant_Association
6662 and then Selector_Names (P) = L)
6664 (Nkind (P) = N_Component_Association
6665 and then Choices (P) = L);
6668 end Is_Selector_Name;
6674 function Is_Statement (N : Node_Id) return Boolean is
6677 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6678 or else Nkind (N) = N_Procedure_Call_Statement;
6681 ---------------------------------
6682 -- Is_Synchronized_Tagged_Type --
6683 ---------------------------------
6685 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6686 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6689 -- A task or protected type derived from an interface is a tagged type.
6690 -- Such a tagged type is called a synchronized tagged type, as are
6691 -- synchronized interfaces and private extensions whose declaration
6692 -- includes the reserved word synchronized.
6694 return (Is_Tagged_Type (E)
6695 and then (Kind = E_Task_Type
6696 or else Kind = E_Protected_Type))
6699 and then Is_Synchronized_Interface (E))
6701 (Ekind (E) = E_Record_Type_With_Private
6702 and then (Synchronized_Present (Parent (E))
6703 or else Is_Synchronized_Interface (Etype (E))));
6704 end Is_Synchronized_Tagged_Type;
6710 function Is_Transfer (N : Node_Id) return Boolean is
6711 Kind : constant Node_Kind := Nkind (N);
6714 if Kind = N_Simple_Return_Statement
6716 Kind = N_Extended_Return_Statement
6718 Kind = N_Goto_Statement
6720 Kind = N_Raise_Statement
6722 Kind = N_Requeue_Statement
6726 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6727 and then No (Condition (N))
6731 elsif Kind = N_Procedure_Call_Statement
6732 and then Is_Entity_Name (Name (N))
6733 and then Present (Entity (Name (N)))
6734 and then No_Return (Entity (Name (N)))
6738 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6750 function Is_True (U : Uint) return Boolean is
6759 function Is_Value_Type (T : Entity_Id) return Boolean is
6761 return VM_Target = CLI_Target
6762 and then Chars (T) /= No_Name
6763 and then Get_Name_String (Chars (T)) = "valuetype";
6770 function Is_Variable (N : Node_Id) return Boolean is
6772 Orig_Node : constant Node_Id := Original_Node (N);
6773 -- We do the test on the original node, since this is basically a
6774 -- test of syntactic categories, so it must not be disturbed by
6775 -- whatever rewriting might have occurred. For example, an aggregate,
6776 -- which is certainly NOT a variable, could be turned into a variable
6779 function In_Protected_Function (E : Entity_Id) return Boolean;
6780 -- Within a protected function, the private components of the
6781 -- enclosing protected type are constants. A function nested within
6782 -- a (protected) procedure is not itself protected.
6784 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6785 -- Prefixes can involve implicit dereferences, in which case we
6786 -- must test for the case of a reference of a constant access
6787 -- type, which can never be a variable.
6789 ---------------------------
6790 -- In_Protected_Function --
6791 ---------------------------
6793 function In_Protected_Function (E : Entity_Id) return Boolean is
6794 Prot : constant Entity_Id := Scope (E);
6798 if not Is_Protected_Type (Prot) then
6802 while Present (S) and then S /= Prot loop
6803 if Ekind (S) = E_Function
6804 and then Scope (S) = Prot
6814 end In_Protected_Function;
6816 ------------------------
6817 -- Is_Variable_Prefix --
6818 ------------------------
6820 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6822 if Is_Access_Type (Etype (P)) then
6823 return not Is_Access_Constant (Root_Type (Etype (P)));
6825 -- For the case of an indexed component whose prefix has a packed
6826 -- array type, the prefix has been rewritten into a type conversion.
6827 -- Determine variable-ness from the converted expression.
6829 elsif Nkind (P) = N_Type_Conversion
6830 and then not Comes_From_Source (P)
6831 and then Is_Array_Type (Etype (P))
6832 and then Is_Packed (Etype (P))
6834 return Is_Variable (Expression (P));
6837 return Is_Variable (P);
6839 end Is_Variable_Prefix;
6841 -- Start of processing for Is_Variable
6844 -- Definitely OK if Assignment_OK is set. Since this is something that
6845 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6847 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6850 -- Normally we go to the original node, but there is one exception
6851 -- where we use the rewritten node, namely when it is an explicit
6852 -- dereference. The generated code may rewrite a prefix which is an
6853 -- access type with an explicit dereference. The dereference is a
6854 -- variable, even though the original node may not be (since it could
6855 -- be a constant of the access type).
6857 -- In Ada 2005 we have a further case to consider: the prefix may be
6858 -- a function call given in prefix notation. The original node appears
6859 -- to be a selected component, but we need to examine the call.
6861 elsif Nkind (N) = N_Explicit_Dereference
6862 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6863 and then Present (Etype (Orig_Node))
6864 and then Is_Access_Type (Etype (Orig_Node))
6866 -- Note that if the prefix is an explicit dereference that does not
6867 -- come from source, we must check for a rewritten function call in
6868 -- prefixed notation before other forms of rewriting, to prevent a
6872 (Nkind (Orig_Node) = N_Function_Call
6873 and then not Is_Access_Constant (Etype (Prefix (N))))
6875 Is_Variable_Prefix (Original_Node (Prefix (N)));
6877 -- A function call is never a variable
6879 elsif Nkind (N) = N_Function_Call then
6882 -- All remaining checks use the original node
6884 elsif Is_Entity_Name (Orig_Node)
6885 and then Present (Entity (Orig_Node))
6888 E : constant Entity_Id := Entity (Orig_Node);
6889 K : constant Entity_Kind := Ekind (E);
6892 return (K = E_Variable
6893 and then Nkind (Parent (E)) /= N_Exception_Handler)
6894 or else (K = E_Component
6895 and then not In_Protected_Function (E))
6896 or else K = E_Out_Parameter
6897 or else K = E_In_Out_Parameter
6898 or else K = E_Generic_In_Out_Parameter
6900 -- Current instance of type:
6902 or else (Is_Type (E) and then In_Open_Scopes (E))
6903 or else (Is_Incomplete_Or_Private_Type (E)
6904 and then In_Open_Scopes (Full_View (E)));
6908 case Nkind (Orig_Node) is
6909 when N_Indexed_Component | N_Slice =>
6910 return Is_Variable_Prefix (Prefix (Orig_Node));
6912 when N_Selected_Component =>
6913 return Is_Variable_Prefix (Prefix (Orig_Node))
6914 and then Is_Variable (Selector_Name (Orig_Node));
6916 -- For an explicit dereference, the type of the prefix cannot
6917 -- be an access to constant or an access to subprogram.
6919 when N_Explicit_Dereference =>
6921 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6923 return Is_Access_Type (Typ)
6924 and then not Is_Access_Constant (Root_Type (Typ))
6925 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6928 -- The type conversion is the case where we do not deal with the
6929 -- context dependent special case of an actual parameter. Thus
6930 -- the type conversion is only considered a variable for the
6931 -- purposes of this routine if the target type is tagged. However,
6932 -- a type conversion is considered to be a variable if it does not
6933 -- come from source (this deals for example with the conversions
6934 -- of expressions to their actual subtypes).
6936 when N_Type_Conversion =>
6937 return Is_Variable (Expression (Orig_Node))
6939 (not Comes_From_Source (Orig_Node)
6941 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6943 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6945 -- GNAT allows an unchecked type conversion as a variable. This
6946 -- only affects the generation of internal expanded code, since
6947 -- calls to instantiations of Unchecked_Conversion are never
6948 -- considered variables (since they are function calls).
6949 -- This is also true for expression actions.
6951 when N_Unchecked_Type_Conversion =>
6952 return Is_Variable (Expression (Orig_Node));
6960 ------------------------
6961 -- Is_Volatile_Object --
6962 ------------------------
6964 function Is_Volatile_Object (N : Node_Id) return Boolean is
6966 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6967 -- Determines if given object has volatile components
6969 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6970 -- If prefix is an implicit dereference, examine designated type
6972 ------------------------
6973 -- Is_Volatile_Prefix --
6974 ------------------------
6976 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6977 Typ : constant Entity_Id := Etype (N);
6980 if Is_Access_Type (Typ) then
6982 Dtyp : constant Entity_Id := Designated_Type (Typ);
6985 return Is_Volatile (Dtyp)
6986 or else Has_Volatile_Components (Dtyp);
6990 return Object_Has_Volatile_Components (N);
6992 end Is_Volatile_Prefix;
6994 ------------------------------------
6995 -- Object_Has_Volatile_Components --
6996 ------------------------------------
6998 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6999 Typ : constant Entity_Id := Etype (N);
7002 if Is_Volatile (Typ)
7003 or else Has_Volatile_Components (Typ)
7007 elsif Is_Entity_Name (N)
7008 and then (Has_Volatile_Components (Entity (N))
7009 or else Is_Volatile (Entity (N)))
7013 elsif Nkind (N) = N_Indexed_Component
7014 or else Nkind (N) = N_Selected_Component
7016 return Is_Volatile_Prefix (Prefix (N));
7021 end Object_Has_Volatile_Components;
7023 -- Start of processing for Is_Volatile_Object
7026 if Is_Volatile (Etype (N))
7027 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7031 elsif Nkind (N) = N_Indexed_Component
7032 or else Nkind (N) = N_Selected_Component
7034 return Is_Volatile_Prefix (Prefix (N));
7039 end Is_Volatile_Object;
7041 -------------------------
7042 -- Kill_Current_Values --
7043 -------------------------
7045 procedure Kill_Current_Values
7047 Last_Assignment_Only : Boolean := False)
7050 if Is_Assignable (Ent) then
7051 Set_Last_Assignment (Ent, Empty);
7054 if not Last_Assignment_Only and then Is_Object (Ent) then
7056 Set_Current_Value (Ent, Empty);
7058 if not Can_Never_Be_Null (Ent) then
7059 Set_Is_Known_Non_Null (Ent, False);
7062 Set_Is_Known_Null (Ent, False);
7064 end Kill_Current_Values;
7066 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7069 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7070 -- Clear current value for entity E and all entities chained to E
7072 ------------------------------------------
7073 -- Kill_Current_Values_For_Entity_Chain --
7074 ------------------------------------------
7076 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7080 while Present (Ent) loop
7081 Kill_Current_Values (Ent, Last_Assignment_Only);
7084 end Kill_Current_Values_For_Entity_Chain;
7086 -- Start of processing for Kill_Current_Values
7089 -- Kill all saved checks, a special case of killing saved values
7091 if not Last_Assignment_Only then
7095 -- Loop through relevant scopes, which includes the current scope and
7096 -- any parent scopes if the current scope is a block or a package.
7101 -- Clear current values of all entities in current scope
7103 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7105 -- If scope is a package, also clear current values of all
7106 -- private entities in the scope.
7108 if Is_Package_Or_Generic_Package (S)
7109 or else Is_Concurrent_Type (S)
7111 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7114 -- If this is a not a subprogram, deal with parents
7116 if not Is_Subprogram (S) then
7118 exit Scope_Loop when S = Standard_Standard;
7122 end loop Scope_Loop;
7123 end Kill_Current_Values;
7125 --------------------------
7126 -- Kill_Size_Check_Code --
7127 --------------------------
7129 procedure Kill_Size_Check_Code (E : Entity_Id) is
7131 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7132 and then Present (Size_Check_Code (E))
7134 Remove (Size_Check_Code (E));
7135 Set_Size_Check_Code (E, Empty);
7137 end Kill_Size_Check_Code;
7139 --------------------------
7140 -- Known_To_Be_Assigned --
7141 --------------------------
7143 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7144 P : constant Node_Id := Parent (N);
7149 -- Test left side of assignment
7151 when N_Assignment_Statement =>
7152 return N = Name (P);
7154 -- Function call arguments are never lvalues
7156 when N_Function_Call =>
7159 -- Positional parameter for procedure or accept call
7161 when N_Procedure_Call_Statement |
7170 Proc := Get_Subprogram_Entity (P);
7176 -- If we are not a list member, something is strange, so
7177 -- be conservative and return False.
7179 if not Is_List_Member (N) then
7183 -- We are going to find the right formal by stepping forward
7184 -- through the formals, as we step backwards in the actuals.
7186 Form := First_Formal (Proc);
7189 -- If no formal, something is weird, so be conservative
7190 -- and return False.
7201 return Ekind (Form) /= E_In_Parameter;
7204 -- Named parameter for procedure or accept call
7206 when N_Parameter_Association =>
7212 Proc := Get_Subprogram_Entity (Parent (P));
7218 -- Loop through formals to find the one that matches
7220 Form := First_Formal (Proc);
7222 -- If no matching formal, that's peculiar, some kind of
7223 -- previous error, so return False to be conservative.
7229 -- Else test for match
7231 if Chars (Form) = Chars (Selector_Name (P)) then
7232 return Ekind (Form) /= E_In_Parameter;
7239 -- Test for appearing in a conversion that itself appears
7240 -- in an lvalue context, since this should be an lvalue.
7242 when N_Type_Conversion =>
7243 return Known_To_Be_Assigned (P);
7245 -- All other references are definitely not known to be modifications
7251 end Known_To_Be_Assigned;
7257 function May_Be_Lvalue (N : Node_Id) return Boolean is
7258 P : constant Node_Id := Parent (N);
7263 -- Test left side of assignment
7265 when N_Assignment_Statement =>
7266 return N = Name (P);
7268 -- Test prefix of component or attribute. Note that the prefix of an
7269 -- explicit or implicit dereference cannot be an l-value.
7271 when N_Attribute_Reference =>
7272 return N = Prefix (P)
7273 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7275 -- For an expanded name, the name is an lvalue if the expanded name
7276 -- is an lvalue, but the prefix is never an lvalue, since it is just
7277 -- the scope where the name is found.
7279 when N_Expanded_Name =>
7280 if N = Prefix (P) then
7281 return May_Be_Lvalue (P);
7286 -- For a selected component A.B, A is certainly an Lvalue if A.B is
7287 -- an Lvalue. B is a little interesting, if we have A.B:=3, there is
7288 -- some discussion as to whether B is an Lvalue or not, we choose to
7289 -- say it is. Note however that A is not an Lvalue if it is of an
7290 -- access type since this is an implicit dereference.
7292 when N_Selected_Component =>
7294 and then Present (Etype (N))
7295 and then Is_Access_Type (Etype (N))
7299 return May_Be_Lvalue (P);
7302 -- For an indexed component or slice, the index or slice bounds is
7303 -- never an Lvalue. The prefix is an lvalue if the indexed component
7304 -- or slice is an Lvalue, except if it is an access type, where we
7305 -- have an implicit dereference.
7307 when N_Indexed_Component =>
7309 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7313 return May_Be_Lvalue (P);
7316 -- Prefix of a reference is an Lvalue if the reference is an Lvalue
7319 return May_Be_Lvalue (P);
7321 -- Prefix of explicit dereference is never an Lvalue
7323 when N_Explicit_Dereference =>
7326 -- Function call arguments are never Lvalues
7328 when N_Function_Call =>
7331 -- Positional parameter for procedure, entry, or accept call
7333 when N_Procedure_Call_Statement |
7334 N_Entry_Call_Statement |
7343 Proc := Get_Subprogram_Entity (P);
7349 -- If we are not a list member, something is strange, so
7350 -- be conservative and return True.
7352 if not Is_List_Member (N) then
7356 -- We are going to find the right formal by stepping forward
7357 -- through the formals, as we step backwards in the actuals.
7359 Form := First_Formal (Proc);
7362 -- If no formal, something is weird, so be conservative
7374 return Ekind (Form) /= E_In_Parameter;
7377 -- Named parameter for procedure or accept call
7379 when N_Parameter_Association =>
7385 Proc := Get_Subprogram_Entity (Parent (P));
7391 -- Loop through formals to find the one that matches
7393 Form := First_Formal (Proc);
7395 -- If no matching formal, that's peculiar, some kind of
7396 -- previous error, so return True to be conservative.
7402 -- Else test for match
7404 if Chars (Form) = Chars (Selector_Name (P)) then
7405 return Ekind (Form) /= E_In_Parameter;
7412 -- Test for appearing in a conversion that itself appears in an
7413 -- lvalue context, since this should be an lvalue.
7415 when N_Type_Conversion =>
7416 return May_Be_Lvalue (P);
7418 -- Test for appearance in object renaming declaration
7420 when N_Object_Renaming_Declaration =>
7423 -- All other references are definitely not Lvalues
7431 -----------------------
7432 -- Mark_Coextensions --
7433 -----------------------
7435 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7436 Is_Dynamic : Boolean;
7437 -- Indicates whether the context causes nested coextensions to be
7438 -- dynamic or static
7440 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7441 -- Recognize an allocator node and label it as a dynamic coextension
7443 --------------------
7444 -- Mark_Allocator --
7445 --------------------
7447 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7449 if Nkind (N) = N_Allocator then
7451 Set_Is_Dynamic_Coextension (N);
7453 Set_Is_Static_Coextension (N);
7460 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7462 -- Start of processing Mark_Coextensions
7465 case Nkind (Context_Nod) is
7466 when N_Assignment_Statement |
7467 N_Simple_Return_Statement =>
7468 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7470 when N_Object_Declaration =>
7471 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7473 -- This routine should not be called for constructs which may not
7474 -- contain coextensions.
7477 raise Program_Error;
7480 Mark_Allocators (Root_Nod);
7481 end Mark_Coextensions;
7483 ----------------------
7484 -- Needs_One_Actual --
7485 ----------------------
7487 function Needs_One_Actual (E : Entity_Id) return Boolean is
7491 if Ada_Version >= Ada_05
7492 and then Present (First_Formal (E))
7494 Formal := Next_Formal (First_Formal (E));
7495 while Present (Formal) loop
7496 if No (Default_Value (Formal)) then
7500 Next_Formal (Formal);
7508 end Needs_One_Actual;
7510 ------------------------
7511 -- New_Copy_List_Tree --
7512 ------------------------
7514 function New_Copy_List_Tree (List : List_Id) return List_Id is
7519 if List = No_List then
7526 while Present (E) loop
7527 Append (New_Copy_Tree (E), NL);
7533 end New_Copy_List_Tree;
7539 use Atree.Unchecked_Access;
7540 use Atree_Private_Part;
7542 -- Our approach here requires a two pass traversal of the tree. The
7543 -- first pass visits all nodes that eventually will be copied looking
7544 -- for defining Itypes. If any defining Itypes are found, then they are
7545 -- copied, and an entry is added to the replacement map. In the second
7546 -- phase, the tree is copied, using the replacement map to replace any
7547 -- Itype references within the copied tree.
7549 -- The following hash tables are used if the Map supplied has more
7550 -- than hash threshhold entries to speed up access to the map. If
7551 -- there are fewer entries, then the map is searched sequentially
7552 -- (because setting up a hash table for only a few entries takes
7553 -- more time than it saves.
7555 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
7556 -- Hash function used for hash operations
7562 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
7564 return Nat (E) mod (NCT_Header_Num'Last + 1);
7571 -- The hash table NCT_Assoc associates old entities in the table
7572 -- with their corresponding new entities (i.e. the pairs of entries
7573 -- presented in the original Map argument are Key-Element pairs).
7575 package NCT_Assoc is new Simple_HTable (
7576 Header_Num => NCT_Header_Num,
7577 Element => Entity_Id,
7578 No_Element => Empty,
7580 Hash => New_Copy_Hash,
7581 Equal => Types."=");
7583 ---------------------
7584 -- NCT_Itype_Assoc --
7585 ---------------------
7587 -- The hash table NCT_Itype_Assoc contains entries only for those
7588 -- old nodes which have a non-empty Associated_Node_For_Itype set.
7589 -- The key is the associated node, and the element is the new node
7590 -- itself (NOT the associated node for the new node).
7592 package NCT_Itype_Assoc is new Simple_HTable (
7593 Header_Num => NCT_Header_Num,
7594 Element => Entity_Id,
7595 No_Element => Empty,
7597 Hash => New_Copy_Hash,
7598 Equal => Types."=");
7600 -- Start of processing for New_Copy_Tree function
7602 function New_Copy_Tree
7604 Map : Elist_Id := No_Elist;
7605 New_Sloc : Source_Ptr := No_Location;
7606 New_Scope : Entity_Id := Empty) return Node_Id
7608 Actual_Map : Elist_Id := Map;
7609 -- This is the actual map for the copy. It is initialized with the
7610 -- given elements, and then enlarged as required for Itypes that are
7611 -- copied during the first phase of the copy operation. The visit
7612 -- procedures add elements to this map as Itypes are encountered.
7613 -- The reason we cannot use Map directly, is that it may well be
7614 -- (and normally is) initialized to No_Elist, and if we have mapped
7615 -- entities, we have to reset it to point to a real Elist.
7617 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
7618 -- Called during second phase to map entities into their corresponding
7619 -- copies using Actual_Map. If the argument is not an entity, or is not
7620 -- in Actual_Map, then it is returned unchanged.
7622 procedure Build_NCT_Hash_Tables;
7623 -- Builds hash tables (number of elements >= threshold value)
7625 function Copy_Elist_With_Replacement
7626 (Old_Elist : Elist_Id) return Elist_Id;
7627 -- Called during second phase to copy element list doing replacements
7629 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
7630 -- Called during the second phase to process a copied Itype. The actual
7631 -- copy happened during the first phase (so that we could make the entry
7632 -- in the mapping), but we still have to deal with the descendents of
7633 -- the copied Itype and copy them where necessary.
7635 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
7636 -- Called during second phase to copy list doing replacements
7638 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
7639 -- Called during second phase to copy node doing replacements
7641 procedure Visit_Elist (E : Elist_Id);
7642 -- Called during first phase to visit all elements of an Elist
7644 procedure Visit_Field (F : Union_Id; N : Node_Id);
7645 -- Visit a single field, recursing to call Visit_Node or Visit_List
7646 -- if the field is a syntactic descendent of the current node (i.e.
7647 -- its parent is Node N).
7649 procedure Visit_Itype (Old_Itype : Entity_Id);
7650 -- Called during first phase to visit subsidiary fields of a defining
7651 -- Itype, and also create a copy and make an entry in the replacement
7652 -- map for the new copy.
7654 procedure Visit_List (L : List_Id);
7655 -- Called during first phase to visit all elements of a List
7657 procedure Visit_Node (N : Node_Or_Entity_Id);
7658 -- Called during first phase to visit a node and all its subtrees
7664 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
7669 if not Has_Extension (N) or else No (Actual_Map) then
7672 elsif NCT_Hash_Tables_Used then
7673 Ent := NCT_Assoc.Get (Entity_Id (N));
7675 if Present (Ent) then
7681 -- No hash table used, do serial search
7684 E := First_Elmt (Actual_Map);
7685 while Present (E) loop
7686 if Node (E) = N then
7687 return Node (Next_Elmt (E));
7689 E := Next_Elmt (Next_Elmt (E));
7697 ---------------------------
7698 -- Build_NCT_Hash_Tables --
7699 ---------------------------
7701 procedure Build_NCT_Hash_Tables is
7705 if NCT_Hash_Table_Setup then
7707 NCT_Itype_Assoc.Reset;
7710 Elmt := First_Elmt (Actual_Map);
7711 while Present (Elmt) loop
7714 -- Get new entity, and associate old and new
7717 NCT_Assoc.Set (Ent, Node (Elmt));
7719 if Is_Type (Ent) then
7721 Anode : constant Entity_Id :=
7722 Associated_Node_For_Itype (Ent);
7725 if Present (Anode) then
7727 -- Enter a link between the associated node of the
7728 -- old Itype and the new Itype, for updating later
7729 -- when node is copied.
7731 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
7739 NCT_Hash_Tables_Used := True;
7740 NCT_Hash_Table_Setup := True;
7741 end Build_NCT_Hash_Tables;
7743 ---------------------------------
7744 -- Copy_Elist_With_Replacement --
7745 ---------------------------------
7747 function Copy_Elist_With_Replacement
7748 (Old_Elist : Elist_Id) return Elist_Id
7751 New_Elist : Elist_Id;
7754 if No (Old_Elist) then
7758 New_Elist := New_Elmt_List;
7760 M := First_Elmt (Old_Elist);
7761 while Present (M) loop
7762 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
7768 end Copy_Elist_With_Replacement;
7770 ---------------------------------
7771 -- Copy_Itype_With_Replacement --
7772 ---------------------------------
7774 -- This routine exactly parallels its phase one analog Visit_Itype,
7776 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
7778 -- Translate Next_Entity, Scope and Etype fields, in case they
7779 -- reference entities that have been mapped into copies.
7781 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
7782 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
7784 if Present (New_Scope) then
7785 Set_Scope (New_Itype, New_Scope);
7787 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
7790 -- Copy referenced fields
7792 if Is_Discrete_Type (New_Itype) then
7793 Set_Scalar_Range (New_Itype,
7794 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
7796 elsif Has_Discriminants (Base_Type (New_Itype)) then
7797 Set_Discriminant_Constraint (New_Itype,
7798 Copy_Elist_With_Replacement
7799 (Discriminant_Constraint (New_Itype)));
7801 elsif Is_Array_Type (New_Itype) then
7802 if Present (First_Index (New_Itype)) then
7803 Set_First_Index (New_Itype,
7804 First (Copy_List_With_Replacement
7805 (List_Containing (First_Index (New_Itype)))));
7808 if Is_Packed (New_Itype) then
7809 Set_Packed_Array_Type (New_Itype,
7810 Copy_Node_With_Replacement
7811 (Packed_Array_Type (New_Itype)));
7814 end Copy_Itype_With_Replacement;
7816 --------------------------------
7817 -- Copy_List_With_Replacement --
7818 --------------------------------
7820 function Copy_List_With_Replacement
7821 (Old_List : List_Id) return List_Id
7827 if Old_List = No_List then
7831 New_List := Empty_List;
7833 E := First (Old_List);
7834 while Present (E) loop
7835 Append (Copy_Node_With_Replacement (E), New_List);
7841 end Copy_List_With_Replacement;
7843 --------------------------------
7844 -- Copy_Node_With_Replacement --
7845 --------------------------------
7847 function Copy_Node_With_Replacement
7848 (Old_Node : Node_Id) return Node_Id
7852 procedure Adjust_Named_Associations
7853 (Old_Node : Node_Id;
7854 New_Node : Node_Id);
7855 -- If a call node has named associations, these are chained through
7856 -- the First_Named_Actual, Next_Named_Actual links. These must be
7857 -- propagated separately to the new parameter list, because these
7858 -- are not syntactic fields.
7860 function Copy_Field_With_Replacement
7861 (Field : Union_Id) return Union_Id;
7862 -- Given Field, which is a field of Old_Node, return a copy of it
7863 -- if it is a syntactic field (i.e. its parent is Node), setting
7864 -- the parent of the copy to poit to New_Node. Otherwise returns
7865 -- the field (possibly mapped if it is an entity).
7867 -------------------------------
7868 -- Adjust_Named_Associations --
7869 -------------------------------
7871 procedure Adjust_Named_Associations
7872 (Old_Node : Node_Id;
7882 Old_E := First (Parameter_Associations (Old_Node));
7883 New_E := First (Parameter_Associations (New_Node));
7884 while Present (Old_E) loop
7885 if Nkind (Old_E) = N_Parameter_Association
7886 and then Present (Next_Named_Actual (Old_E))
7888 if First_Named_Actual (Old_Node)
7889 = Explicit_Actual_Parameter (Old_E)
7891 Set_First_Named_Actual
7892 (New_Node, Explicit_Actual_Parameter (New_E));
7895 -- Now scan parameter list from the beginning,to locate
7896 -- next named actual, which can be out of order.
7898 Old_Next := First (Parameter_Associations (Old_Node));
7899 New_Next := First (Parameter_Associations (New_Node));
7901 while Nkind (Old_Next) /= N_Parameter_Association
7902 or else Explicit_Actual_Parameter (Old_Next)
7903 /= Next_Named_Actual (Old_E)
7909 Set_Next_Named_Actual
7910 (New_E, Explicit_Actual_Parameter (New_Next));
7916 end Adjust_Named_Associations;
7918 ---------------------------------
7919 -- Copy_Field_With_Replacement --
7920 ---------------------------------
7922 function Copy_Field_With_Replacement
7923 (Field : Union_Id) return Union_Id
7926 if Field = Union_Id (Empty) then
7929 elsif Field in Node_Range then
7931 Old_N : constant Node_Id := Node_Id (Field);
7935 -- If syntactic field, as indicated by the parent pointer
7936 -- being set, then copy the referenced node recursively.
7938 if Parent (Old_N) = Old_Node then
7939 New_N := Copy_Node_With_Replacement (Old_N);
7941 if New_N /= Old_N then
7942 Set_Parent (New_N, New_Node);
7945 -- For semantic fields, update possible entity reference
7946 -- from the replacement map.
7949 New_N := Assoc (Old_N);
7952 return Union_Id (New_N);
7955 elsif Field in List_Range then
7957 Old_L : constant List_Id := List_Id (Field);
7961 -- If syntactic field, as indicated by the parent pointer,
7962 -- then recursively copy the entire referenced list.
7964 if Parent (Old_L) = Old_Node then
7965 New_L := Copy_List_With_Replacement (Old_L);
7966 Set_Parent (New_L, New_Node);
7968 -- For semantic list, just returned unchanged
7974 return Union_Id (New_L);
7977 -- Anything other than a list or a node is returned unchanged
7982 end Copy_Field_With_Replacement;
7984 -- Start of processing for Copy_Node_With_Replacement
7987 if Old_Node <= Empty_Or_Error then
7990 elsif Has_Extension (Old_Node) then
7991 return Assoc (Old_Node);
7994 New_Node := New_Copy (Old_Node);
7996 -- If the node we are copying is the associated node of a
7997 -- previously copied Itype, then adjust the associated node
7998 -- of the copy of that Itype accordingly.
8000 if Present (Actual_Map) then
8006 -- Case of hash table used
8008 if NCT_Hash_Tables_Used then
8009 Ent := NCT_Itype_Assoc.Get (Old_Node);
8011 if Present (Ent) then
8012 Set_Associated_Node_For_Itype (Ent, New_Node);
8015 -- Case of no hash table used
8018 E := First_Elmt (Actual_Map);
8019 while Present (E) loop
8020 if Is_Itype (Node (E))
8022 Old_Node = Associated_Node_For_Itype (Node (E))
8024 Set_Associated_Node_For_Itype
8025 (Node (Next_Elmt (E)), New_Node);
8028 E := Next_Elmt (Next_Elmt (E));
8034 -- Recursively copy descendents
8037 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8039 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8041 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8043 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8045 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8047 -- Adjust Sloc of new node if necessary
8049 if New_Sloc /= No_Location then
8050 Set_Sloc (New_Node, New_Sloc);
8052 -- If we adjust the Sloc, then we are essentially making
8053 -- a completely new node, so the Comes_From_Source flag
8054 -- should be reset to the proper default value.
8056 Nodes.Table (New_Node).Comes_From_Source :=
8057 Default_Node.Comes_From_Source;
8060 -- If the node is call and has named associations,
8061 -- set the corresponding links in the copy.
8063 if (Nkind (Old_Node) = N_Function_Call
8064 or else Nkind (Old_Node) = N_Entry_Call_Statement
8066 Nkind (Old_Node) = N_Procedure_Call_Statement)
8067 and then Present (First_Named_Actual (Old_Node))
8069 Adjust_Named_Associations (Old_Node, New_Node);
8072 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8073 -- The replacement mechanism applies to entities, and is not used
8074 -- here. Eventually we may need a more general graph-copying
8075 -- routine. For now, do a sequential search to find desired node.
8077 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8078 and then Present (First_Real_Statement (Old_Node))
8081 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8085 N1 := First (Statements (Old_Node));
8086 N2 := First (Statements (New_Node));
8088 while N1 /= Old_F loop
8093 Set_First_Real_Statement (New_Node, N2);
8098 -- All done, return copied node
8101 end Copy_Node_With_Replacement;
8107 procedure Visit_Elist (E : Elist_Id) is
8111 Elmt := First_Elmt (E);
8113 while Elmt /= No_Elmt loop
8114 Visit_Node (Node (Elmt));
8124 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8126 if F = Union_Id (Empty) then
8129 elsif F in Node_Range then
8131 -- Copy node if it is syntactic, i.e. its parent pointer is
8132 -- set to point to the field that referenced it (certain
8133 -- Itypes will also meet this criterion, which is fine, since
8134 -- these are clearly Itypes that do need to be copied, since
8135 -- we are copying their parent.)
8137 if Parent (Node_Id (F)) = N then
8138 Visit_Node (Node_Id (F));
8141 -- Another case, if we are pointing to an Itype, then we want
8142 -- to copy it if its associated node is somewhere in the tree
8145 -- Note: the exclusion of self-referential copies is just an
8146 -- optimization, since the search of the already copied list
8147 -- would catch it, but it is a common case (Etype pointing
8148 -- to itself for an Itype that is a base type).
8150 elsif Has_Extension (Node_Id (F))
8151 and then Is_Itype (Entity_Id (F))
8152 and then Node_Id (F) /= N
8158 P := Associated_Node_For_Itype (Node_Id (F));
8159 while Present (P) loop
8161 Visit_Node (Node_Id (F));
8168 -- An Itype whose parent is not being copied definitely
8169 -- should NOT be copied, since it does not belong in any
8170 -- sense to the copied subtree.
8176 elsif F in List_Range
8177 and then Parent (List_Id (F)) = N
8179 Visit_List (List_Id (F));
8188 procedure Visit_Itype (Old_Itype : Entity_Id) is
8189 New_Itype : Entity_Id;
8194 -- Itypes that describe the designated type of access to subprograms
8195 -- have the structure of subprogram declarations, with signatures,
8196 -- etc. Either we duplicate the signatures completely, or choose to
8197 -- share such itypes, which is fine because their elaboration will
8198 -- have no side effects.
8200 if Ekind (Old_Itype) = E_Subprogram_Type then
8204 New_Itype := New_Copy (Old_Itype);
8206 -- The new Itype has all the attributes of the old one, and
8207 -- we just copy the contents of the entity. However, the back-end
8208 -- needs different names for debugging purposes, so we create a
8209 -- new internal name for it in all cases.
8211 Set_Chars (New_Itype, New_Internal_Name ('T'));
8213 -- If our associated node is an entity that has already been copied,
8214 -- then set the associated node of the copy to point to the right
8215 -- copy. If we have copied an Itype that is itself the associated
8216 -- node of some previously copied Itype, then we set the right
8217 -- pointer in the other direction.
8219 if Present (Actual_Map) then
8221 -- Case of hash tables used
8223 if NCT_Hash_Tables_Used then
8225 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8227 if Present (Ent) then
8228 Set_Associated_Node_For_Itype (New_Itype, Ent);
8231 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8232 if Present (Ent) then
8233 Set_Associated_Node_For_Itype (Ent, New_Itype);
8235 -- If the hash table has no association for this Itype and
8236 -- its associated node, enter one now.
8240 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8243 -- Case of hash tables not used
8246 E := First_Elmt (Actual_Map);
8247 while Present (E) loop
8248 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8249 Set_Associated_Node_For_Itype
8250 (New_Itype, Node (Next_Elmt (E)));
8253 if Is_Type (Node (E))
8255 Old_Itype = Associated_Node_For_Itype (Node (E))
8257 Set_Associated_Node_For_Itype
8258 (Node (Next_Elmt (E)), New_Itype);
8261 E := Next_Elmt (Next_Elmt (E));
8266 if Present (Freeze_Node (New_Itype)) then
8267 Set_Is_Frozen (New_Itype, False);
8268 Set_Freeze_Node (New_Itype, Empty);
8271 -- Add new association to map
8273 if No (Actual_Map) then
8274 Actual_Map := New_Elmt_List;
8277 Append_Elmt (Old_Itype, Actual_Map);
8278 Append_Elmt (New_Itype, Actual_Map);
8280 if NCT_Hash_Tables_Used then
8281 NCT_Assoc.Set (Old_Itype, New_Itype);
8284 NCT_Table_Entries := NCT_Table_Entries + 1;
8286 if NCT_Table_Entries > NCT_Hash_Threshhold then
8287 Build_NCT_Hash_Tables;
8291 -- If a record subtype is simply copied, the entity list will be
8292 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8294 if Ekind (Old_Itype) = E_Record_Subtype
8295 or else Ekind (Old_Itype) = E_Class_Wide_Subtype
8297 Set_Cloned_Subtype (New_Itype, Old_Itype);
8300 -- Visit descendents that eventually get copied
8302 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8304 if Is_Discrete_Type (Old_Itype) then
8305 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8307 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8308 -- ??? This should involve call to Visit_Field
8309 Visit_Elist (Discriminant_Constraint (Old_Itype));
8311 elsif Is_Array_Type (Old_Itype) then
8312 if Present (First_Index (Old_Itype)) then
8313 Visit_Field (Union_Id (List_Containing
8314 (First_Index (Old_Itype))),
8318 if Is_Packed (Old_Itype) then
8319 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8329 procedure Visit_List (L : List_Id) is
8332 if L /= No_List then
8335 while Present (N) loop
8346 procedure Visit_Node (N : Node_Or_Entity_Id) is
8348 -- Start of processing for Visit_Node
8351 -- Handle case of an Itype, which must be copied
8353 if Has_Extension (N)
8354 and then Is_Itype (N)
8356 -- Nothing to do if already in the list. This can happen with an
8357 -- Itype entity that appears more than once in the tree.
8358 -- Note that we do not want to visit descendents in this case.
8360 -- Test for already in list when hash table is used
8362 if NCT_Hash_Tables_Used then
8363 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8367 -- Test for already in list when hash table not used
8373 if Present (Actual_Map) then
8374 E := First_Elmt (Actual_Map);
8375 while Present (E) loop
8376 if Node (E) = N then
8379 E := Next_Elmt (Next_Elmt (E));
8389 -- Visit descendents
8391 Visit_Field (Field1 (N), N);
8392 Visit_Field (Field2 (N), N);
8393 Visit_Field (Field3 (N), N);
8394 Visit_Field (Field4 (N), N);
8395 Visit_Field (Field5 (N), N);
8398 -- Start of processing for New_Copy_Tree
8403 -- See if we should use hash table
8405 if No (Actual_Map) then
8406 NCT_Hash_Tables_Used := False;
8413 NCT_Table_Entries := 0;
8415 Elmt := First_Elmt (Actual_Map);
8416 while Present (Elmt) loop
8417 NCT_Table_Entries := NCT_Table_Entries + 1;
8422 if NCT_Table_Entries > NCT_Hash_Threshhold then
8423 Build_NCT_Hash_Tables;
8425 NCT_Hash_Tables_Used := False;
8430 -- Hash table set up if required, now start phase one by visiting
8431 -- top node (we will recursively visit the descendents).
8433 Visit_Node (Source);
8435 -- Now the second phase of the copy can start. First we process
8436 -- all the mapped entities, copying their descendents.
8438 if Present (Actual_Map) then
8441 New_Itype : Entity_Id;
8443 Elmt := First_Elmt (Actual_Map);
8444 while Present (Elmt) loop
8446 New_Itype := Node (Elmt);
8447 Copy_Itype_With_Replacement (New_Itype);
8453 -- Now we can copy the actual tree
8455 return Copy_Node_With_Replacement (Source);
8458 -------------------------
8459 -- New_External_Entity --
8460 -------------------------
8462 function New_External_Entity
8463 (Kind : Entity_Kind;
8464 Scope_Id : Entity_Id;
8465 Sloc_Value : Source_Ptr;
8466 Related_Id : Entity_Id;
8468 Suffix_Index : Nat := 0;
8469 Prefix : Character := ' ') return Entity_Id
8471 N : constant Entity_Id :=
8472 Make_Defining_Identifier (Sloc_Value,
8474 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8477 Set_Ekind (N, Kind);
8478 Set_Is_Internal (N, True);
8479 Append_Entity (N, Scope_Id);
8480 Set_Public_Status (N);
8482 if Kind in Type_Kind then
8483 Init_Size_Align (N);
8487 end New_External_Entity;
8489 -------------------------
8490 -- New_Internal_Entity --
8491 -------------------------
8493 function New_Internal_Entity
8494 (Kind : Entity_Kind;
8495 Scope_Id : Entity_Id;
8496 Sloc_Value : Source_Ptr;
8497 Id_Char : Character) return Entity_Id
8499 N : constant Entity_Id :=
8500 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
8503 Set_Ekind (N, Kind);
8504 Set_Is_Internal (N, True);
8505 Append_Entity (N, Scope_Id);
8507 if Kind in Type_Kind then
8508 Init_Size_Align (N);
8512 end New_Internal_Entity;
8518 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
8522 -- If we are pointing at a positional parameter, it is a member of a
8523 -- node list (the list of parameters), and the next parameter is the
8524 -- next node on the list, unless we hit a parameter association, then
8525 -- we shift to using the chain whose head is the First_Named_Actual in
8526 -- the parent, and then is threaded using the Next_Named_Actual of the
8527 -- Parameter_Association. All this fiddling is because the original node
8528 -- list is in the textual call order, and what we need is the
8529 -- declaration order.
8531 if Is_List_Member (Actual_Id) then
8532 N := Next (Actual_Id);
8534 if Nkind (N) = N_Parameter_Association then
8535 return First_Named_Actual (Parent (Actual_Id));
8541 return Next_Named_Actual (Parent (Actual_Id));
8545 procedure Next_Actual (Actual_Id : in out Node_Id) is
8547 Actual_Id := Next_Actual (Actual_Id);
8550 -----------------------
8551 -- Normalize_Actuals --
8552 -----------------------
8554 -- Chain actuals according to formals of subprogram. If there are no named
8555 -- associations, the chain is simply the list of Parameter Associations,
8556 -- since the order is the same as the declaration order. If there are named
8557 -- associations, then the First_Named_Actual field in the N_Function_Call
8558 -- or N_Procedure_Call_Statement node points to the Parameter_Association
8559 -- node for the parameter that comes first in declaration order. The
8560 -- remaining named parameters are then chained in declaration order using
8561 -- Next_Named_Actual.
8563 -- This routine also verifies that the number of actuals is compatible with
8564 -- the number and default values of formals, but performs no type checking
8565 -- (type checking is done by the caller).
8567 -- If the matching succeeds, Success is set to True and the caller proceeds
8568 -- with type-checking. If the match is unsuccessful, then Success is set to
8569 -- False, and the caller attempts a different interpretation, if there is
8572 -- If the flag Report is on, the call is not overloaded, and a failure to
8573 -- match can be reported here, rather than in the caller.
8575 procedure Normalize_Actuals
8579 Success : out Boolean)
8581 Actuals : constant List_Id := Parameter_Associations (N);
8582 Actual : Node_Id := Empty;
8584 Last : Node_Id := Empty;
8585 First_Named : Node_Id := Empty;
8588 Formals_To_Match : Integer := 0;
8589 Actuals_To_Match : Integer := 0;
8591 procedure Chain (A : Node_Id);
8592 -- Add named actual at the proper place in the list, using the
8593 -- Next_Named_Actual link.
8595 function Reporting return Boolean;
8596 -- Determines if an error is to be reported. To report an error, we
8597 -- need Report to be True, and also we do not report errors caused
8598 -- by calls to init procs that occur within other init procs. Such
8599 -- errors must always be cascaded errors, since if all the types are
8600 -- declared correctly, the compiler will certainly build decent calls!
8606 procedure Chain (A : Node_Id) is
8610 -- Call node points to first actual in list
8612 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
8615 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
8619 Set_Next_Named_Actual (Last, Empty);
8626 function Reporting return Boolean is
8631 elsif not Within_Init_Proc then
8634 elsif Is_Init_Proc (Entity (Name (N))) then
8642 -- Start of processing for Normalize_Actuals
8645 if Is_Access_Type (S) then
8647 -- The name in the call is a function call that returns an access
8648 -- to subprogram. The designated type has the list of formals.
8650 Formal := First_Formal (Designated_Type (S));
8652 Formal := First_Formal (S);
8655 while Present (Formal) loop
8656 Formals_To_Match := Formals_To_Match + 1;
8657 Next_Formal (Formal);
8660 -- Find if there is a named association, and verify that no positional
8661 -- associations appear after named ones.
8663 if Present (Actuals) then
8664 Actual := First (Actuals);
8667 while Present (Actual)
8668 and then Nkind (Actual) /= N_Parameter_Association
8670 Actuals_To_Match := Actuals_To_Match + 1;
8674 if No (Actual) and Actuals_To_Match = Formals_To_Match then
8676 -- Most common case: positional notation, no defaults
8681 elsif Actuals_To_Match > Formals_To_Match then
8683 -- Too many actuals: will not work
8686 if Is_Entity_Name (Name (N)) then
8687 Error_Msg_N ("too many arguments in call to&", Name (N));
8689 Error_Msg_N ("too many arguments in call", N);
8697 First_Named := Actual;
8699 while Present (Actual) loop
8700 if Nkind (Actual) /= N_Parameter_Association then
8702 ("positional parameters not allowed after named ones", Actual);
8707 Actuals_To_Match := Actuals_To_Match + 1;
8713 if Present (Actuals) then
8714 Actual := First (Actuals);
8717 Formal := First_Formal (S);
8718 while Present (Formal) loop
8720 -- Match the formals in order. If the corresponding actual is
8721 -- positional, nothing to do. Else scan the list of named actuals
8722 -- to find the one with the right name.
8725 and then Nkind (Actual) /= N_Parameter_Association
8728 Actuals_To_Match := Actuals_To_Match - 1;
8729 Formals_To_Match := Formals_To_Match - 1;
8732 -- For named parameters, search the list of actuals to find
8733 -- one that matches the next formal name.
8735 Actual := First_Named;
8737 while Present (Actual) loop
8738 if Chars (Selector_Name (Actual)) = Chars (Formal) then
8741 Actuals_To_Match := Actuals_To_Match - 1;
8742 Formals_To_Match := Formals_To_Match - 1;
8750 if Ekind (Formal) /= E_In_Parameter
8751 or else No (Default_Value (Formal))
8754 if (Comes_From_Source (S)
8755 or else Sloc (S) = Standard_Location)
8756 and then Is_Overloadable (S)
8760 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8762 (Nkind (Parent (N)) = N_Function_Call
8764 Nkind (Parent (N)) = N_Parameter_Association))
8765 and then Ekind (S) /= E_Function
8767 Set_Etype (N, Etype (S));
8769 Error_Msg_Name_1 := Chars (S);
8770 Error_Msg_Sloc := Sloc (S);
8772 ("missing argument for parameter & " &
8773 "in call to % declared #", N, Formal);
8776 elsif Is_Overloadable (S) then
8777 Error_Msg_Name_1 := Chars (S);
8779 -- Point to type derivation that generated the
8782 Error_Msg_Sloc := Sloc (Parent (S));
8785 ("missing argument for parameter & " &
8786 "in call to % (inherited) #", N, Formal);
8790 ("missing argument for parameter &", N, Formal);
8798 Formals_To_Match := Formals_To_Match - 1;
8803 Next_Formal (Formal);
8806 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8813 -- Find some superfluous named actual that did not get
8814 -- attached to the list of associations.
8816 Actual := First (Actuals);
8817 while Present (Actual) loop
8818 if Nkind (Actual) = N_Parameter_Association
8819 and then Actual /= Last
8820 and then No (Next_Named_Actual (Actual))
8822 Error_Msg_N ("unmatched actual & in call",
8823 Selector_Name (Actual));
8834 end Normalize_Actuals;
8836 --------------------------------
8837 -- Note_Possible_Modification --
8838 --------------------------------
8840 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8841 Modification_Comes_From_Source : constant Boolean :=
8842 Comes_From_Source (Parent (N));
8848 -- Loop to find referenced entity, if there is one
8855 if Is_Entity_Name (Exp) then
8856 Ent := Entity (Exp);
8858 -- If the entity is missing, it is an undeclared identifier,
8859 -- and there is nothing to annotate.
8865 elsif Nkind (Exp) = N_Explicit_Dereference then
8867 P : constant Node_Id := Prefix (Exp);
8870 if Nkind (P) = N_Selected_Component
8872 Entry_Formal (Entity (Selector_Name (P))))
8874 -- Case of a reference to an entry formal
8876 Ent := Entry_Formal (Entity (Selector_Name (P)));
8878 elsif Nkind (P) = N_Identifier
8879 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
8880 and then Present (Expression (Parent (Entity (P))))
8881 and then Nkind (Expression (Parent (Entity (P))))
8884 -- Case of a reference to a value on which side effects have
8887 Exp := Prefix (Expression (Parent (Entity (P))));
8896 elsif Nkind (Exp) = N_Type_Conversion
8897 or else Nkind (Exp) = N_Unchecked_Type_Conversion
8899 Exp := Expression (Exp);
8902 elsif Nkind (Exp) = N_Slice
8903 or else Nkind (Exp) = N_Indexed_Component
8904 or else Nkind (Exp) = N_Selected_Component
8906 Exp := Prefix (Exp);
8913 -- Now look for entity being referenced
8915 if Present (Ent) then
8916 if Is_Object (Ent) then
8917 if Comes_From_Source (Exp)
8918 or else Modification_Comes_From_Source
8920 if Has_Pragma_Unmodified (Ent) then
8921 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
8924 Set_Never_Set_In_Source (Ent, False);
8927 Set_Is_True_Constant (Ent, False);
8928 Set_Current_Value (Ent, Empty);
8929 Set_Is_Known_Null (Ent, False);
8931 if not Can_Never_Be_Null (Ent) then
8932 Set_Is_Known_Non_Null (Ent, False);
8935 -- Follow renaming chain
8937 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
8938 and then Present (Renamed_Object (Ent))
8940 Exp := Renamed_Object (Ent);
8944 -- Generate a reference only if the assignment comes from
8945 -- source. This excludes, for example, calls to a dispatching
8946 -- assignment operation when the left-hand side is tagged.
8948 if Modification_Comes_From_Source then
8949 Generate_Reference (Ent, Exp, 'm');
8952 Check_Nested_Access (Ent);
8957 -- If we are sure this is a modification from source, and we know
8958 -- this modifies a constant, then give an appropriate warning.
8960 if Overlays_Constant (Ent)
8961 and then Modification_Comes_From_Source
8965 A : constant Node_Id := Address_Clause (Ent);
8969 Exp : constant Node_Id := Expression (A);
8971 if Nkind (Exp) = N_Attribute_Reference
8972 and then Attribute_Name (Exp) = Name_Address
8973 and then Is_Entity_Name (Prefix (Exp))
8975 Error_Msg_Sloc := Sloc (A);
8977 ("constant& may be modified via address clause#?",
8978 N, Entity (Prefix (Exp)));
8988 end Note_Possible_Modification;
8990 -------------------------
8991 -- Object_Access_Level --
8992 -------------------------
8994 function Object_Access_Level (Obj : Node_Id) return Uint is
8997 -- Returns the static accessibility level of the view denoted by Obj. Note
8998 -- that the value returned is the result of a call to Scope_Depth. Only
8999 -- scope depths associated with dynamic scopes can actually be returned.
9000 -- Since only relative levels matter for accessibility checking, the fact
9001 -- that the distance between successive levels of accessibility is not
9002 -- always one is immaterial (invariant: if level(E2) is deeper than
9003 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9005 function Reference_To (Obj : Node_Id) return Node_Id;
9006 -- An explicit dereference is created when removing side-effects from
9007 -- expressions for constraint checking purposes. In this case a local
9008 -- access type is created for it. The correct access level is that of
9009 -- the original source node. We detect this case by noting that the
9010 -- prefix of the dereference is created by an object declaration whose
9011 -- initial expression is a reference.
9017 function Reference_To (Obj : Node_Id) return Node_Id is
9018 Pref : constant Node_Id := Prefix (Obj);
9020 if Is_Entity_Name (Pref)
9021 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9022 and then Present (Expression (Parent (Entity (Pref))))
9023 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9025 return (Prefix (Expression (Parent (Entity (Pref)))));
9031 -- Start of processing for Object_Access_Level
9034 if Is_Entity_Name (Obj) then
9037 if Is_Prival (E) then
9038 E := Prival_Link (E);
9041 -- If E is a type then it denotes a current instance. For this case
9042 -- we add one to the normal accessibility level of the type to ensure
9043 -- that current instances are treated as always being deeper than
9044 -- than the level of any visible named access type (see 3.10.2(21)).
9047 return Type_Access_Level (E) + 1;
9049 elsif Present (Renamed_Object (E)) then
9050 return Object_Access_Level (Renamed_Object (E));
9052 -- Similarly, if E is a component of the current instance of a
9053 -- protected type, any instance of it is assumed to be at a deeper
9054 -- level than the type. For a protected object (whose type is an
9055 -- anonymous protected type) its components are at the same level
9056 -- as the type itself.
9058 elsif not Is_Overloadable (E)
9059 and then Ekind (Scope (E)) = E_Protected_Type
9060 and then Comes_From_Source (Scope (E))
9062 return Type_Access_Level (Scope (E)) + 1;
9065 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9068 elsif Nkind (Obj) = N_Selected_Component then
9069 if Is_Access_Type (Etype (Prefix (Obj))) then
9070 return Type_Access_Level (Etype (Prefix (Obj)));
9072 return Object_Access_Level (Prefix (Obj));
9075 elsif Nkind (Obj) = N_Indexed_Component then
9076 if Is_Access_Type (Etype (Prefix (Obj))) then
9077 return Type_Access_Level (Etype (Prefix (Obj)));
9079 return Object_Access_Level (Prefix (Obj));
9082 elsif Nkind (Obj) = N_Explicit_Dereference then
9084 -- If the prefix is a selected access discriminant then we make a
9085 -- recursive call on the prefix, which will in turn check the level
9086 -- of the prefix object of the selected discriminant.
9088 if Nkind (Prefix (Obj)) = N_Selected_Component
9089 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9091 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9093 return Object_Access_Level (Prefix (Obj));
9095 elsif not (Comes_From_Source (Obj)) then
9097 Ref : constant Node_Id := Reference_To (Obj);
9099 if Present (Ref) then
9100 return Object_Access_Level (Ref);
9102 return Type_Access_Level (Etype (Prefix (Obj)));
9107 return Type_Access_Level (Etype (Prefix (Obj)));
9110 elsif Nkind (Obj) = N_Type_Conversion
9111 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9113 return Object_Access_Level (Expression (Obj));
9115 -- Function results are objects, so we get either the access level of
9116 -- the function or, in the case of an indirect call, the level of the
9117 -- access-to-subprogram type.
9119 elsif Nkind (Obj) = N_Function_Call then
9120 if Is_Entity_Name (Name (Obj)) then
9121 return Subprogram_Access_Level (Entity (Name (Obj)));
9123 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9126 -- For convenience we handle qualified expressions, even though
9127 -- they aren't technically object names.
9129 elsif Nkind (Obj) = N_Qualified_Expression then
9130 return Object_Access_Level (Expression (Obj));
9132 -- Otherwise return the scope level of Standard.
9133 -- (If there are cases that fall through
9134 -- to this point they will be treated as
9135 -- having global accessibility for now. ???)
9138 return Scope_Depth (Standard_Standard);
9140 end Object_Access_Level;
9142 -----------------------
9143 -- Private_Component --
9144 -----------------------
9146 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9147 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9149 function Trace_Components
9151 Check : Boolean) return Entity_Id;
9152 -- Recursive function that does the work, and checks against circular
9153 -- definition for each subcomponent type.
9155 ----------------------
9156 -- Trace_Components --
9157 ----------------------
9159 function Trace_Components
9161 Check : Boolean) return Entity_Id
9163 Btype : constant Entity_Id := Base_Type (T);
9164 Component : Entity_Id;
9166 Candidate : Entity_Id := Empty;
9169 if Check and then Btype = Ancestor then
9170 Error_Msg_N ("circular type definition", Type_Id);
9174 if Is_Private_Type (Btype)
9175 and then not Is_Generic_Type (Btype)
9177 if Present (Full_View (Btype))
9178 and then Is_Record_Type (Full_View (Btype))
9179 and then not Is_Frozen (Btype)
9181 -- To indicate that the ancestor depends on a private type, the
9182 -- current Btype is sufficient. However, to check for circular
9183 -- definition we must recurse on the full view.
9185 Candidate := Trace_Components (Full_View (Btype), True);
9187 if Candidate = Any_Type then
9197 elsif Is_Array_Type (Btype) then
9198 return Trace_Components (Component_Type (Btype), True);
9200 elsif Is_Record_Type (Btype) then
9201 Component := First_Entity (Btype);
9202 while Present (Component) loop
9204 -- Skip anonymous types generated by constrained components
9206 if not Is_Type (Component) then
9207 P := Trace_Components (Etype (Component), True);
9210 if P = Any_Type then
9218 Next_Entity (Component);
9226 end Trace_Components;
9228 -- Start of processing for Private_Component
9231 return Trace_Components (Type_Id, False);
9232 end Private_Component;
9234 ---------------------------
9235 -- Primitive_Names_Match --
9236 ---------------------------
9238 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9240 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9241 -- Given an internal name, returns the corresponding non-internal name
9243 ------------------------
9244 -- Non_Internal_Name --
9245 ------------------------
9247 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9249 Get_Name_String (Chars (E));
9250 Name_Len := Name_Len - 1;
9252 end Non_Internal_Name;
9254 -- Start of processing for Primitive_Names_Match
9257 pragma Assert (Present (E1) and then Present (E2));
9259 return Chars (E1) = Chars (E2)
9261 (not Is_Internal_Name (Chars (E1))
9262 and then Is_Internal_Name (Chars (E2))
9263 and then Non_Internal_Name (E2) = Chars (E1))
9265 (not Is_Internal_Name (Chars (E2))
9266 and then Is_Internal_Name (Chars (E1))
9267 and then Non_Internal_Name (E1) = Chars (E2))
9269 (Is_Predefined_Dispatching_Operation (E1)
9270 and then Is_Predefined_Dispatching_Operation (E2)
9271 and then Same_TSS (E1, E2))
9273 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9274 end Primitive_Names_Match;
9276 -----------------------
9277 -- Process_End_Label --
9278 -----------------------
9280 procedure Process_End_Label
9289 Label_Ref : Boolean;
9290 -- Set True if reference to end label itself is required
9293 -- Gets set to the operator symbol or identifier that references the
9294 -- entity Ent. For the child unit case, this is the identifier from the
9295 -- designator. For other cases, this is simply Endl.
9297 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9298 -- N is an identifier node that appears as a parent unit reference in
9299 -- the case where Ent is a child unit. This procedure generates an
9300 -- appropriate cross-reference entry. E is the corresponding entity.
9302 -------------------------
9303 -- Generate_Parent_Ref --
9304 -------------------------
9306 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9308 -- If names do not match, something weird, skip reference
9310 if Chars (E) = Chars (N) then
9312 -- Generate the reference. We do NOT consider this as a reference
9313 -- for unreferenced symbol purposes.
9315 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9318 Style.Check_Identifier (N, E);
9321 end Generate_Parent_Ref;
9323 -- Start of processing for Process_End_Label
9326 -- If no node, ignore. This happens in some error situations, and
9327 -- also for some internally generated structures where no end label
9328 -- references are required in any case.
9334 -- Nothing to do if no End_Label, happens for internally generated
9335 -- constructs where we don't want an end label reference anyway. Also
9336 -- nothing to do if Endl is a string literal, which means there was
9337 -- some prior error (bad operator symbol)
9339 Endl := End_Label (N);
9341 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9345 -- Reference node is not in extended main source unit
9347 if not In_Extended_Main_Source_Unit (N) then
9349 -- Generally we do not collect references except for the extended
9350 -- main source unit. The one exception is the 'e' entry for a
9351 -- package spec, where it is useful for a client to have the
9352 -- ending information to define scopes.
9360 -- For this case, we can ignore any parent references, but we
9361 -- need the package name itself for the 'e' entry.
9363 if Nkind (Endl) = N_Designator then
9364 Endl := Identifier (Endl);
9368 -- Reference is in extended main source unit
9373 -- For designator, generate references for the parent entries
9375 if Nkind (Endl) = N_Designator then
9377 -- Generate references for the prefix if the END line comes from
9378 -- source (otherwise we do not need these references) We climb the
9379 -- scope stack to find the expected entities.
9381 if Comes_From_Source (Endl) then
9383 Scop := Current_Scope;
9384 while Nkind (Nam) = N_Selected_Component loop
9385 Scop := Scope (Scop);
9386 exit when No (Scop);
9387 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9388 Nam := Prefix (Nam);
9391 if Present (Scop) then
9392 Generate_Parent_Ref (Nam, Scope (Scop));
9396 Endl := Identifier (Endl);
9400 -- If the end label is not for the given entity, then either we have
9401 -- some previous error, or this is a generic instantiation for which
9402 -- we do not need to make a cross-reference in this case anyway. In
9403 -- either case we simply ignore the call.
9405 if Chars (Ent) /= Chars (Endl) then
9409 -- If label was really there, then generate a normal reference and then
9410 -- adjust the location in the end label to point past the name (which
9411 -- should almost always be the semicolon).
9415 if Comes_From_Source (Endl) then
9417 -- If a label reference is required, then do the style check and
9418 -- generate an l-type cross-reference entry for the label
9422 Style.Check_Identifier (Endl, Ent);
9425 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
9428 -- Set the location to point past the label (normally this will
9429 -- mean the semicolon immediately following the label). This is
9430 -- done for the sake of the 'e' or 't' entry generated below.
9432 Get_Decoded_Name_String (Chars (Endl));
9433 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
9436 -- Now generate the e/t reference
9438 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
9440 -- Restore Sloc, in case modified above, since we have an identifier
9441 -- and the normal Sloc should be left set in the tree.
9443 Set_Sloc (Endl, Loc);
9444 end Process_End_Label;
9450 -- We do the conversion to get the value of the real string by using
9451 -- the scanner, see Sinput for details on use of the internal source
9452 -- buffer for scanning internal strings.
9454 function Real_Convert (S : String) return Node_Id is
9455 Save_Src : constant Source_Buffer_Ptr := Source;
9459 Source := Internal_Source_Ptr;
9462 for J in S'Range loop
9463 Source (Source_Ptr (J)) := S (J);
9466 Source (S'Length + 1) := EOF;
9468 if Source (Scan_Ptr) = '-' then
9470 Scan_Ptr := Scan_Ptr + 1;
9478 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
9485 --------------------
9486 -- Remove_Homonym --
9487 --------------------
9489 procedure Remove_Homonym (E : Entity_Id) is
9490 Prev : Entity_Id := Empty;
9494 if E = Current_Entity (E) then
9495 if Present (Homonym (E)) then
9496 Set_Current_Entity (Homonym (E));
9498 Set_Name_Entity_Id (Chars (E), Empty);
9501 H := Current_Entity (E);
9502 while Present (H) and then H /= E loop
9507 Set_Homonym (Prev, Homonym (E));
9511 ---------------------
9512 -- Rep_To_Pos_Flag --
9513 ---------------------
9515 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
9517 return New_Occurrence_Of
9518 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
9519 end Rep_To_Pos_Flag;
9521 --------------------
9522 -- Require_Entity --
9523 --------------------
9525 procedure Require_Entity (N : Node_Id) is
9527 if Is_Entity_Name (N) and then No (Entity (N)) then
9528 if Total_Errors_Detected /= 0 then
9529 Set_Entity (N, Any_Id);
9531 raise Program_Error;
9536 ------------------------------
9537 -- Requires_Transient_Scope --
9538 ------------------------------
9540 -- A transient scope is required when variable-sized temporaries are
9541 -- allocated in the primary or secondary stack, or when finalization
9542 -- actions must be generated before the next instruction.
9544 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
9545 Typ : constant Entity_Id := Underlying_Type (Id);
9547 -- Start of processing for Requires_Transient_Scope
9550 -- This is a private type which is not completed yet. This can only
9551 -- happen in a default expression (of a formal parameter or of a
9552 -- record component). Do not expand transient scope in this case
9557 -- Do not expand transient scope for non-existent procedure return
9559 elsif Typ = Standard_Void_Type then
9562 -- Elementary types do not require a transient scope
9564 elsif Is_Elementary_Type (Typ) then
9567 -- Generally, indefinite subtypes require a transient scope, since the
9568 -- back end cannot generate temporaries, since this is not a valid type
9569 -- for declaring an object. It might be possible to relax this in the
9570 -- future, e.g. by declaring the maximum possible space for the type.
9572 elsif Is_Indefinite_Subtype (Typ) then
9575 -- Functions returning tagged types may dispatch on result so their
9576 -- returned value is allocated on the secondary stack. Controlled
9577 -- type temporaries need finalization.
9579 elsif Is_Tagged_Type (Typ)
9580 or else Has_Controlled_Component (Typ)
9582 return not Is_Value_Type (Typ);
9586 elsif Is_Record_Type (Typ) then
9590 Comp := First_Entity (Typ);
9591 while Present (Comp) loop
9592 if Ekind (Comp) = E_Component
9593 and then Requires_Transient_Scope (Etype (Comp))
9604 -- String literal types never require transient scope
9606 elsif Ekind (Typ) = E_String_Literal_Subtype then
9609 -- Array type. Note that we already know that this is a constrained
9610 -- array, since unconstrained arrays will fail the indefinite test.
9612 elsif Is_Array_Type (Typ) then
9614 -- If component type requires a transient scope, the array does too
9616 if Requires_Transient_Scope (Component_Type (Typ)) then
9619 -- Otherwise, we only need a transient scope if the size is not
9620 -- known at compile time.
9623 return not Size_Known_At_Compile_Time (Typ);
9626 -- All other cases do not require a transient scope
9631 end Requires_Transient_Scope;
9633 --------------------------
9634 -- Reset_Analyzed_Flags --
9635 --------------------------
9637 procedure Reset_Analyzed_Flags (N : Node_Id) is
9639 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
9640 -- Function used to reset Analyzed flags in tree. Note that we do
9641 -- not reset Analyzed flags in entities, since there is no need to
9642 -- reanalyze entities, and indeed, it is wrong to do so, since it
9643 -- can result in generating auxiliary stuff more than once.
9645 --------------------
9646 -- Clear_Analyzed --
9647 --------------------
9649 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
9651 if not Has_Extension (N) then
9652 Set_Analyzed (N, False);
9658 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
9660 -- Start of processing for Reset_Analyzed_Flags
9664 end Reset_Analyzed_Flags;
9666 ---------------------------
9667 -- Safe_To_Capture_Value --
9668 ---------------------------
9670 function Safe_To_Capture_Value
9673 Cond : Boolean := False) return Boolean
9676 -- The only entities for which we track constant values are variables
9677 -- which are not renamings, constants, out parameters, and in out
9678 -- parameters, so check if we have this case.
9680 -- Note: it may seem odd to track constant values for constants, but in
9681 -- fact this routine is used for other purposes than simply capturing
9682 -- the value. In particular, the setting of Known[_Non]_Null.
9684 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
9686 Ekind (Ent) = E_Constant
9688 Ekind (Ent) = E_Out_Parameter
9690 Ekind (Ent) = E_In_Out_Parameter
9694 -- For conditionals, we also allow loop parameters and all formals,
9695 -- including in parameters.
9699 (Ekind (Ent) = E_Loop_Parameter
9701 Ekind (Ent) = E_In_Parameter)
9705 -- For all other cases, not just unsafe, but impossible to capture
9706 -- Current_Value, since the above are the only entities which have
9707 -- Current_Value fields.
9713 -- Skip if volatile or aliased, since funny things might be going on in
9714 -- these cases which we cannot necessarily track. Also skip any variable
9715 -- for which an address clause is given, or whose address is taken. Also
9716 -- never capture value of library level variables (an attempt to do so
9717 -- can occur in the case of package elaboration code).
9719 if Treat_As_Volatile (Ent)
9720 or else Is_Aliased (Ent)
9721 or else Present (Address_Clause (Ent))
9722 or else Address_Taken (Ent)
9723 or else (Is_Library_Level_Entity (Ent)
9724 and then Ekind (Ent) = E_Variable)
9729 -- OK, all above conditions are met. We also require that the scope of
9730 -- the reference be the same as the scope of the entity, not counting
9731 -- packages and blocks and loops.
9734 E_Scope : constant Entity_Id := Scope (Ent);
9735 R_Scope : Entity_Id;
9738 R_Scope := Current_Scope;
9739 while R_Scope /= Standard_Standard loop
9740 exit when R_Scope = E_Scope;
9742 if Ekind (R_Scope) /= E_Package
9744 Ekind (R_Scope) /= E_Block
9746 Ekind (R_Scope) /= E_Loop
9750 R_Scope := Scope (R_Scope);
9755 -- We also require that the reference does not appear in a context
9756 -- where it is not sure to be executed (i.e. a conditional context
9757 -- or an exception handler). We skip this if Cond is True, since the
9758 -- capturing of values from conditional tests handles this ok.
9772 while Present (P) loop
9773 if Nkind (P) = N_If_Statement
9774 or else Nkind (P) = N_Case_Statement
9775 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
9776 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
9777 or else Nkind (P) = N_Exception_Handler
9778 or else Nkind (P) = N_Selective_Accept
9779 or else Nkind (P) = N_Conditional_Entry_Call
9780 or else Nkind (P) = N_Timed_Entry_Call
9781 or else Nkind (P) = N_Asynchronous_Select
9791 -- OK, looks safe to set value
9794 end Safe_To_Capture_Value;
9800 function Same_Name (N1, N2 : Node_Id) return Boolean is
9801 K1 : constant Node_Kind := Nkind (N1);
9802 K2 : constant Node_Kind := Nkind (N2);
9805 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
9806 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
9808 return Chars (N1) = Chars (N2);
9810 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
9811 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
9813 return Same_Name (Selector_Name (N1), Selector_Name (N2))
9814 and then Same_Name (Prefix (N1), Prefix (N2));
9825 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9826 N1 : constant Node_Id := Original_Node (Node1);
9827 N2 : constant Node_Id := Original_Node (Node2);
9828 -- We do the tests on original nodes, since we are most interested
9829 -- in the original source, not any expansion that got in the way.
9831 K1 : constant Node_Kind := Nkind (N1);
9832 K2 : constant Node_Kind := Nkind (N2);
9835 -- First case, both are entities with same entity
9837 if K1 in N_Has_Entity
9838 and then K2 in N_Has_Entity
9839 and then Present (Entity (N1))
9840 and then Present (Entity (N2))
9841 and then (Ekind (Entity (N1)) = E_Variable
9843 Ekind (Entity (N1)) = E_Constant)
9844 and then Entity (N1) = Entity (N2)
9848 -- Second case, selected component with same selector, same record
9850 elsif K1 = N_Selected_Component
9851 and then K2 = N_Selected_Component
9852 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
9854 return Same_Object (Prefix (N1), Prefix (N2));
9856 -- Third case, indexed component with same subscripts, same array
9858 elsif K1 = N_Indexed_Component
9859 and then K2 = N_Indexed_Component
9860 and then Same_Object (Prefix (N1), Prefix (N2))
9865 E1 := First (Expressions (N1));
9866 E2 := First (Expressions (N2));
9867 while Present (E1) loop
9868 if not Same_Value (E1, E2) then
9879 -- Fourth case, slice of same array with same bounds
9882 and then K2 = N_Slice
9883 and then Nkind (Discrete_Range (N1)) = N_Range
9884 and then Nkind (Discrete_Range (N2)) = N_Range
9885 and then Same_Value (Low_Bound (Discrete_Range (N1)),
9886 Low_Bound (Discrete_Range (N2)))
9887 and then Same_Value (High_Bound (Discrete_Range (N1)),
9888 High_Bound (Discrete_Range (N2)))
9890 return Same_Name (Prefix (N1), Prefix (N2));
9892 -- All other cases, not clearly the same object
9903 function Same_Type (T1, T2 : Entity_Id) return Boolean is
9908 elsif not Is_Constrained (T1)
9909 and then not Is_Constrained (T2)
9910 and then Base_Type (T1) = Base_Type (T2)
9914 -- For now don't bother with case of identical constraints, to be
9915 -- fiddled with later on perhaps (this is only used for optimization
9916 -- purposes, so it is not critical to do a best possible job)
9927 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
9929 if Compile_Time_Known_Value (Node1)
9930 and then Compile_Time_Known_Value (Node2)
9931 and then Expr_Value (Node1) = Expr_Value (Node2)
9934 elsif Same_Object (Node1, Node2) then
9941 ------------------------
9942 -- Scope_Is_Transient --
9943 ------------------------
9945 function Scope_Is_Transient return Boolean is
9947 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
9948 end Scope_Is_Transient;
9954 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
9959 while Scop /= Standard_Standard loop
9960 Scop := Scope (Scop);
9962 if Scop = Scope2 then
9970 --------------------------
9971 -- Scope_Within_Or_Same --
9972 --------------------------
9974 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
9979 while Scop /= Standard_Standard loop
9980 if Scop = Scope2 then
9983 Scop := Scope (Scop);
9988 end Scope_Within_Or_Same;
9990 --------------------
9991 -- Set_Convention --
9992 --------------------
9994 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
9996 Basic_Set_Convention (E, Val);
9999 and then Is_Access_Subprogram_Type (Base_Type (E))
10000 and then Has_Foreign_Convention (E)
10002 Set_Can_Use_Internal_Rep (E, False);
10004 end Set_Convention;
10006 ------------------------
10007 -- Set_Current_Entity --
10008 ------------------------
10010 -- The given entity is to be set as the currently visible definition
10011 -- of its associated name (i.e. the Node_Id associated with its name).
10012 -- All we have to do is to get the name from the identifier, and
10013 -- then set the associated Node_Id to point to the given entity.
10015 procedure Set_Current_Entity (E : Entity_Id) is
10017 Set_Name_Entity_Id (Chars (E), E);
10018 end Set_Current_Entity;
10020 ---------------------------
10021 -- Set_Debug_Info_Needed --
10022 ---------------------------
10024 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10026 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10027 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10028 -- Used to set debug info in a related node if not set already
10030 --------------------------------------
10031 -- Set_Debug_Info_Needed_If_Not_Set --
10032 --------------------------------------
10034 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10037 and then not Needs_Debug_Info (E)
10039 Set_Debug_Info_Needed (E);
10041 -- For a private type, indicate that the full view also needs
10042 -- debug information.
10045 and then Is_Private_Type (E)
10046 and then Present (Full_View (E))
10048 Set_Debug_Info_Needed (Full_View (E));
10051 end Set_Debug_Info_Needed_If_Not_Set;
10053 -- Start of processing for Set_Debug_Info_Needed
10056 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10057 -- indicates that Debug_Info_Needed is never required for the entity.
10060 or else Debug_Info_Off (T)
10065 -- Set flag in entity itself. Note that we will go through the following
10066 -- circuitry even if the flag is already set on T. That's intentional,
10067 -- it makes sure that the flag will be set in subsidiary entities.
10069 Set_Needs_Debug_Info (T);
10071 -- Set flag on subsidiary entities if not set already
10073 if Is_Object (T) then
10074 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10076 elsif Is_Type (T) then
10077 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10079 if Is_Record_Type (T) then
10081 Ent : Entity_Id := First_Entity (T);
10083 while Present (Ent) loop
10084 Set_Debug_Info_Needed_If_Not_Set (Ent);
10089 elsif Is_Array_Type (T) then
10090 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10093 Indx : Node_Id := First_Index (T);
10095 while Present (Indx) loop
10096 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10097 Indx := Next_Index (Indx);
10101 if Is_Packed (T) then
10102 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10105 elsif Is_Access_Type (T) then
10106 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10108 elsif Is_Private_Type (T) then
10109 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10111 elsif Is_Protected_Type (T) then
10112 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10115 end Set_Debug_Info_Needed;
10117 ---------------------------------
10118 -- Set_Entity_With_Style_Check --
10119 ---------------------------------
10121 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10122 Val_Actual : Entity_Id;
10126 Set_Entity (N, Val);
10129 and then not Suppress_Style_Checks (Val)
10130 and then not In_Instance
10132 if Nkind (N) = N_Identifier then
10134 elsif Nkind (N) = N_Expanded_Name then
10135 Nod := Selector_Name (N);
10140 -- A special situation arises for derived operations, where we want
10141 -- to do the check against the parent (since the Sloc of the derived
10142 -- operation points to the derived type declaration itself).
10145 while not Comes_From_Source (Val_Actual)
10146 and then Nkind (Val_Actual) in N_Entity
10147 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10148 or else Is_Subprogram (Val_Actual)
10149 or else Is_Generic_Subprogram (Val_Actual))
10150 and then Present (Alias (Val_Actual))
10152 Val_Actual := Alias (Val_Actual);
10155 -- Renaming declarations for generic actuals do not come from source,
10156 -- and have a different name from that of the entity they rename, so
10157 -- there is no style check to perform here.
10159 if Chars (Nod) = Chars (Val_Actual) then
10160 Style.Check_Identifier (Nod, Val_Actual);
10164 Set_Entity (N, Val);
10165 end Set_Entity_With_Style_Check;
10167 ------------------------
10168 -- Set_Name_Entity_Id --
10169 ------------------------
10171 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10173 Set_Name_Table_Info (Id, Int (Val));
10174 end Set_Name_Entity_Id;
10176 ---------------------
10177 -- Set_Next_Actual --
10178 ---------------------
10180 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10182 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10183 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10185 end Set_Next_Actual;
10187 ----------------------------------
10188 -- Set_Optimize_Alignment_Flags --
10189 ----------------------------------
10191 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10193 if Optimize_Alignment = 'S' then
10194 Set_Optimize_Alignment_Space (E);
10195 elsif Optimize_Alignment = 'T' then
10196 Set_Optimize_Alignment_Time (E);
10198 end Set_Optimize_Alignment_Flags;
10200 -----------------------
10201 -- Set_Public_Status --
10202 -----------------------
10204 procedure Set_Public_Status (Id : Entity_Id) is
10205 S : constant Entity_Id := Current_Scope;
10207 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10208 -- Determines if E is defined within handled statement sequence or
10209 -- an if statement, returns True if so, False otherwise.
10211 ----------------------
10212 -- Within_HSS_Or_If --
10213 ----------------------
10215 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10218 N := Declaration_Node (E);
10225 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10231 end Within_HSS_Or_If;
10233 -- Start of processing for Set_Public_Status
10236 -- Everything in the scope of Standard is public
10238 if S = Standard_Standard then
10239 Set_Is_Public (Id);
10241 -- Entity is definitely not public if enclosing scope is not public
10243 elsif not Is_Public (S) then
10246 -- An object or function declaration that occurs in a handled sequence
10247 -- of statements or within an if statement is the declaration for a
10248 -- temporary object or local subprogram generated by the expander. It
10249 -- never needs to be made public and furthermore, making it public can
10250 -- cause back end problems.
10252 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10253 N_Function_Specification)
10254 and then Within_HSS_Or_If (Id)
10258 -- Entities in public packages or records are public
10260 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10261 Set_Is_Public (Id);
10263 -- The bounds of an entry family declaration can generate object
10264 -- declarations that are visible to the back-end, e.g. in the
10265 -- the declaration of a composite type that contains tasks.
10267 elsif Is_Concurrent_Type (S)
10268 and then not Has_Completion (S)
10269 and then Nkind (Parent (Id)) = N_Object_Declaration
10271 Set_Is_Public (Id);
10273 end Set_Public_Status;
10275 -----------------------------
10276 -- Set_Referenced_Modified --
10277 -----------------------------
10279 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10283 -- Deal with indexed or selected component where prefix is modified
10285 if Nkind (N) = N_Indexed_Component
10287 Nkind (N) = N_Selected_Component
10289 Pref := Prefix (N);
10291 -- If prefix is access type, then it is the designated object that is
10292 -- being modified, which means we have no entity to set the flag on.
10294 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10297 -- Otherwise chase the prefix
10300 Set_Referenced_Modified (Pref, Out_Param);
10303 -- Otherwise see if we have an entity name (only other case to process)
10305 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10306 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10307 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10309 end Set_Referenced_Modified;
10311 ----------------------------
10312 -- Set_Scope_Is_Transient --
10313 ----------------------------
10315 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10317 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10318 end Set_Scope_Is_Transient;
10320 -------------------
10321 -- Set_Size_Info --
10322 -------------------
10324 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10326 -- We copy Esize, but not RM_Size, since in general RM_Size is
10327 -- subtype specific and does not get inherited by all subtypes.
10329 Set_Esize (T1, Esize (T2));
10330 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10332 if Is_Discrete_Or_Fixed_Point_Type (T1)
10334 Is_Discrete_Or_Fixed_Point_Type (T2)
10336 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10339 Set_Alignment (T1, Alignment (T2));
10342 --------------------
10343 -- Static_Integer --
10344 --------------------
10346 function Static_Integer (N : Node_Id) return Uint is
10348 Analyze_And_Resolve (N, Any_Integer);
10351 or else Error_Posted (N)
10352 or else Etype (N) = Any_Type
10357 if Is_Static_Expression (N) then
10358 if not Raises_Constraint_Error (N) then
10359 return Expr_Value (N);
10364 elsif Etype (N) = Any_Type then
10368 Flag_Non_Static_Expr
10369 ("static integer expression required here", N);
10372 end Static_Integer;
10374 --------------------------
10375 -- Statically_Different --
10376 --------------------------
10378 function Statically_Different (E1, E2 : Node_Id) return Boolean is
10379 R1 : constant Node_Id := Get_Referenced_Object (E1);
10380 R2 : constant Node_Id := Get_Referenced_Object (E2);
10382 return Is_Entity_Name (R1)
10383 and then Is_Entity_Name (R2)
10384 and then Entity (R1) /= Entity (R2)
10385 and then not Is_Formal (Entity (R1))
10386 and then not Is_Formal (Entity (R2));
10387 end Statically_Different;
10389 -----------------------------
10390 -- Subprogram_Access_Level --
10391 -----------------------------
10393 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
10395 if Present (Alias (Subp)) then
10396 return Subprogram_Access_Level (Alias (Subp));
10398 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
10400 end Subprogram_Access_Level;
10406 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
10408 if Debug_Flag_W then
10409 for J in 0 .. Scope_Stack.Last loop
10414 Write_Name (Chars (E));
10415 Write_Str (" from ");
10416 Write_Location (Sloc (N));
10421 -----------------------
10422 -- Transfer_Entities --
10423 -----------------------
10425 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
10426 Ent : Entity_Id := First_Entity (From);
10433 if (Last_Entity (To)) = Empty then
10434 Set_First_Entity (To, Ent);
10436 Set_Next_Entity (Last_Entity (To), Ent);
10439 Set_Last_Entity (To, Last_Entity (From));
10441 while Present (Ent) loop
10442 Set_Scope (Ent, To);
10444 if not Is_Public (Ent) then
10445 Set_Public_Status (Ent);
10448 and then Ekind (Ent) = E_Record_Subtype
10451 -- The components of the propagated Itype must be public
10457 Comp := First_Entity (Ent);
10458 while Present (Comp) loop
10459 Set_Is_Public (Comp);
10460 Next_Entity (Comp);
10469 Set_First_Entity (From, Empty);
10470 Set_Last_Entity (From, Empty);
10471 end Transfer_Entities;
10473 -----------------------
10474 -- Type_Access_Level --
10475 -----------------------
10477 function Type_Access_Level (Typ : Entity_Id) return Uint is
10481 Btyp := Base_Type (Typ);
10483 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
10484 -- simply use the level where the type is declared. This is true for
10485 -- stand-alone object declarations, and for anonymous access types
10486 -- associated with components the level is the same as that of the
10487 -- enclosing composite type. However, special treatment is needed for
10488 -- the cases of access parameters, return objects of an anonymous access
10489 -- type, and, in Ada 95, access discriminants of limited types.
10491 if Ekind (Btyp) in Access_Kind then
10492 if Ekind (Btyp) = E_Anonymous_Access_Type then
10494 -- If the type is a nonlocal anonymous access type (such as for
10495 -- an access parameter) we treat it as being declared at the
10496 -- library level to ensure that names such as X.all'access don't
10497 -- fail static accessibility checks.
10499 if not Is_Local_Anonymous_Access (Typ) then
10500 return Scope_Depth (Standard_Standard);
10502 -- If this is a return object, the accessibility level is that of
10503 -- the result subtype of the enclosing function. The test here is
10504 -- little complicated, because we have to account for extended
10505 -- return statements that have been rewritten as blocks, in which
10506 -- case we have to find and the Is_Return_Object attribute of the
10507 -- itype's associated object. It would be nice to find a way to
10508 -- simplify this test, but it doesn't seem worthwhile to add a new
10509 -- flag just for purposes of this test. ???
10511 elsif Ekind (Scope (Btyp)) = E_Return_Statement
10514 and then Nkind (Associated_Node_For_Itype (Btyp)) =
10515 N_Object_Declaration
10516 and then Is_Return_Object
10517 (Defining_Identifier
10518 (Associated_Node_For_Itype (Btyp))))
10524 Scop := Scope (Scope (Btyp));
10525 while Present (Scop) loop
10526 exit when Ekind (Scop) = E_Function;
10527 Scop := Scope (Scop);
10530 -- Treat the return object's type as having the level of the
10531 -- function's result subtype (as per RM05-6.5(5.3/2)).
10533 return Type_Access_Level (Etype (Scop));
10538 Btyp := Root_Type (Btyp);
10540 -- The accessibility level of anonymous access types associated with
10541 -- discriminants is that of the current instance of the type, and
10542 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
10544 -- AI-402: access discriminants have accessibility based on the
10545 -- object rather than the type in Ada 2005, so the above paragraph
10548 -- ??? Needs completion with rules from AI-416
10550 if Ada_Version <= Ada_95
10551 and then Ekind (Typ) = E_Anonymous_Access_Type
10552 and then Present (Associated_Node_For_Itype (Typ))
10553 and then Nkind (Associated_Node_For_Itype (Typ)) =
10554 N_Discriminant_Specification
10556 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
10560 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
10561 end Type_Access_Level;
10563 --------------------
10564 -- Ultimate_Alias --
10565 --------------------
10566 -- To do: add occurrences calling this new subprogram
10568 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
10569 E : Entity_Id := Prim;
10572 while Present (Alias (E)) loop
10577 end Ultimate_Alias;
10579 --------------------------
10580 -- Unit_Declaration_Node --
10581 --------------------------
10583 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
10584 N : Node_Id := Parent (Unit_Id);
10587 -- Predefined operators do not have a full function declaration
10589 if Ekind (Unit_Id) = E_Operator then
10593 -- Isn't there some better way to express the following ???
10595 while Nkind (N) /= N_Abstract_Subprogram_Declaration
10596 and then Nkind (N) /= N_Formal_Package_Declaration
10597 and then Nkind (N) /= N_Function_Instantiation
10598 and then Nkind (N) /= N_Generic_Package_Declaration
10599 and then Nkind (N) /= N_Generic_Subprogram_Declaration
10600 and then Nkind (N) /= N_Package_Declaration
10601 and then Nkind (N) /= N_Package_Body
10602 and then Nkind (N) /= N_Package_Instantiation
10603 and then Nkind (N) /= N_Package_Renaming_Declaration
10604 and then Nkind (N) /= N_Procedure_Instantiation
10605 and then Nkind (N) /= N_Protected_Body
10606 and then Nkind (N) /= N_Subprogram_Declaration
10607 and then Nkind (N) /= N_Subprogram_Body
10608 and then Nkind (N) /= N_Subprogram_Body_Stub
10609 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
10610 and then Nkind (N) /= N_Task_Body
10611 and then Nkind (N) /= N_Task_Type_Declaration
10612 and then Nkind (N) not in N_Formal_Subprogram_Declaration
10613 and then Nkind (N) not in N_Generic_Renaming_Declaration
10616 pragma Assert (Present (N));
10620 end Unit_Declaration_Node;
10622 ------------------------------
10623 -- Universal_Interpretation --
10624 ------------------------------
10626 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
10627 Index : Interp_Index;
10631 -- The argument may be a formal parameter of an operator or subprogram
10632 -- with multiple interpretations, or else an expression for an actual.
10634 if Nkind (Opnd) = N_Defining_Identifier
10635 or else not Is_Overloaded (Opnd)
10637 if Etype (Opnd) = Universal_Integer
10638 or else Etype (Opnd) = Universal_Real
10640 return Etype (Opnd);
10646 Get_First_Interp (Opnd, Index, It);
10647 while Present (It.Typ) loop
10648 if It.Typ = Universal_Integer
10649 or else It.Typ = Universal_Real
10654 Get_Next_Interp (Index, It);
10659 end Universal_Interpretation;
10665 function Unqualify (Expr : Node_Id) return Node_Id is
10667 -- Recurse to handle unlikely case of multiple levels of qualification
10669 if Nkind (Expr) = N_Qualified_Expression then
10670 return Unqualify (Expression (Expr));
10672 -- Normal case, not a qualified expression
10679 ----------------------
10680 -- Within_Init_Proc --
10681 ----------------------
10683 function Within_Init_Proc return Boolean is
10687 S := Current_Scope;
10688 while not Is_Overloadable (S) loop
10689 if S = Standard_Standard then
10696 return Is_Init_Proc (S);
10697 end Within_Init_Proc;
10703 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
10704 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
10705 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
10707 function Has_One_Matching_Field return Boolean;
10708 -- Determines if Expec_Type is a record type with a single component or
10709 -- discriminant whose type matches the found type or is one dimensional
10710 -- array whose component type matches the found type.
10712 ----------------------------
10713 -- Has_One_Matching_Field --
10714 ----------------------------
10716 function Has_One_Matching_Field return Boolean is
10720 if Is_Array_Type (Expec_Type)
10721 and then Number_Dimensions (Expec_Type) = 1
10723 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
10727 elsif not Is_Record_Type (Expec_Type) then
10731 E := First_Entity (Expec_Type);
10736 elsif (Ekind (E) /= E_Discriminant
10737 and then Ekind (E) /= E_Component)
10738 or else (Chars (E) = Name_uTag
10739 or else Chars (E) = Name_uParent)
10748 if not Covers (Etype (E), Found_Type) then
10751 elsif Present (Next_Entity (E)) then
10758 end Has_One_Matching_Field;
10760 -- Start of processing for Wrong_Type
10763 -- Don't output message if either type is Any_Type, or if a message
10764 -- has already been posted for this node. We need to do the latter
10765 -- check explicitly (it is ordinarily done in Errout), because we
10766 -- are using ! to force the output of the error messages.
10768 if Expec_Type = Any_Type
10769 or else Found_Type = Any_Type
10770 or else Error_Posted (Expr)
10774 -- In an instance, there is an ongoing problem with completion of
10775 -- type derived from private types. Their structure is what Gigi
10776 -- expects, but the Etype is the parent type rather than the
10777 -- derived private type itself. Do not flag error in this case. The
10778 -- private completion is an entity without a parent, like an Itype.
10779 -- Similarly, full and partial views may be incorrect in the instance.
10780 -- There is no simple way to insure that it is consistent ???
10782 elsif In_Instance then
10783 if Etype (Etype (Expr)) = Etype (Expected_Type)
10785 (Has_Private_Declaration (Expected_Type)
10786 or else Has_Private_Declaration (Etype (Expr)))
10787 and then No (Parent (Expected_Type))
10793 -- An interesting special check. If the expression is parenthesized
10794 -- and its type corresponds to the type of the sole component of the
10795 -- expected record type, or to the component type of the expected one
10796 -- dimensional array type, then assume we have a bad aggregate attempt.
10798 if Nkind (Expr) in N_Subexpr
10799 and then Paren_Count (Expr) /= 0
10800 and then Has_One_Matching_Field
10802 Error_Msg_N ("positional aggregate cannot have one component", Expr);
10804 -- Another special check, if we are looking for a pool-specific access
10805 -- type and we found an E_Access_Attribute_Type, then we have the case
10806 -- of an Access attribute being used in a context which needs a pool-
10807 -- specific type, which is never allowed. The one extra check we make
10808 -- is that the expected designated type covers the Found_Type.
10810 elsif Is_Access_Type (Expec_Type)
10811 and then Ekind (Found_Type) = E_Access_Attribute_Type
10812 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
10813 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
10815 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
10817 Error_Msg_N ("result must be general access type!", Expr);
10818 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
10820 -- Another special check, if the expected type is an integer type,
10821 -- but the expression is of type System.Address, and the parent is
10822 -- an addition or subtraction operation whose left operand is the
10823 -- expression in question and whose right operand is of an integral
10824 -- type, then this is an attempt at address arithmetic, so give
10825 -- appropriate message.
10827 elsif Is_Integer_Type (Expec_Type)
10828 and then Is_RTE (Found_Type, RE_Address)
10829 and then (Nkind (Parent (Expr)) = N_Op_Add
10831 Nkind (Parent (Expr)) = N_Op_Subtract)
10832 and then Expr = Left_Opnd (Parent (Expr))
10833 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
10836 ("address arithmetic not predefined in package System",
10839 ("\possible missing with/use of System.Storage_Elements",
10843 -- If the expected type is an anonymous access type, as for access
10844 -- parameters and discriminants, the error is on the designated types.
10846 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
10847 if Comes_From_Source (Expec_Type) then
10848 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10851 ("expected an access type with designated}",
10852 Expr, Designated_Type (Expec_Type));
10855 if Is_Access_Type (Found_Type)
10856 and then not Comes_From_Source (Found_Type)
10859 ("\\found an access type with designated}!",
10860 Expr, Designated_Type (Found_Type));
10862 if From_With_Type (Found_Type) then
10863 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
10864 Error_Msg_Qual_Level := 99;
10865 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
10866 Error_Msg_Qual_Level := 0;
10868 Error_Msg_NE ("found}!", Expr, Found_Type);
10872 -- Normal case of one type found, some other type expected
10875 -- If the names of the two types are the same, see if some number
10876 -- of levels of qualification will help. Don't try more than three
10877 -- levels, and if we get to standard, it's no use (and probably
10878 -- represents an error in the compiler) Also do not bother with
10879 -- internal scope names.
10882 Expec_Scope : Entity_Id;
10883 Found_Scope : Entity_Id;
10886 Expec_Scope := Expec_Type;
10887 Found_Scope := Found_Type;
10889 for Levels in Int range 0 .. 3 loop
10890 if Chars (Expec_Scope) /= Chars (Found_Scope) then
10891 Error_Msg_Qual_Level := Levels;
10895 Expec_Scope := Scope (Expec_Scope);
10896 Found_Scope := Scope (Found_Scope);
10898 exit when Expec_Scope = Standard_Standard
10899 or else Found_Scope = Standard_Standard
10900 or else not Comes_From_Source (Expec_Scope)
10901 or else not Comes_From_Source (Found_Scope);
10905 if Is_Record_Type (Expec_Type)
10906 and then Present (Corresponding_Remote_Type (Expec_Type))
10908 Error_Msg_NE ("expected}!", Expr,
10909 Corresponding_Remote_Type (Expec_Type));
10911 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10914 if Is_Entity_Name (Expr)
10915 and then Is_Package_Or_Generic_Package (Entity (Expr))
10917 Error_Msg_N ("\\found package name!", Expr);
10919 elsif Is_Entity_Name (Expr)
10921 (Ekind (Entity (Expr)) = E_Procedure
10923 Ekind (Entity (Expr)) = E_Generic_Procedure)
10925 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
10927 ("found procedure name, possibly missing Access attribute!",
10931 ("\\found procedure name instead of function!", Expr);
10934 elsif Nkind (Expr) = N_Function_Call
10935 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
10936 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
10937 and then No (Parameter_Associations (Expr))
10940 ("found function name, possibly missing Access attribute!",
10943 -- Catch common error: a prefix or infix operator which is not
10944 -- directly visible because the type isn't.
10946 elsif Nkind (Expr) in N_Op
10947 and then Is_Overloaded (Expr)
10948 and then not Is_Immediately_Visible (Expec_Type)
10949 and then not Is_Potentially_Use_Visible (Expec_Type)
10950 and then not In_Use (Expec_Type)
10951 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
10954 ("operator of the type is not directly visible!", Expr);
10956 elsif Ekind (Found_Type) = E_Void
10957 and then Present (Parent (Found_Type))
10958 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
10960 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
10963 Error_Msg_NE ("\\found}!", Expr, Found_Type);
10966 Error_Msg_Qual_Level := 0;