1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
43 with Rtsfind; use Rtsfind;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Attr; use Sem_Attr;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Disp; use Sem_Disp;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Stand; use Stand;
56 with Stringt; use Stringt;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uname; use Uname;
63 with GNAT.HTable; use GNAT.HTable;
65 package body Sem_Util is
67 ----------------------------------------
68 -- Global_Variables for New_Copy_Tree --
69 ----------------------------------------
71 -- These global variables are used by New_Copy_Tree. See description
72 -- of the body of this subprogram for details. Global variables can be
73 -- safely used by New_Copy_Tree, since there is no case of a recursive
74 -- call from the processing inside New_Copy_Tree.
76 NCT_Hash_Threshhold : constant := 20;
77 -- If there are more than this number of pairs of entries in the
78 -- map, then Hash_Tables_Used will be set, and the hash tables will
79 -- be initialized and used for the searches.
81 NCT_Hash_Tables_Used : Boolean := False;
82 -- Set to True if hash tables are in use
84 NCT_Table_Entries : Nat;
85 -- Count entries in table to see if threshhold is reached
87 NCT_Hash_Table_Setup : Boolean := False;
88 -- Set to True if hash table contains data. We set this True if we
89 -- setup the hash table with data, and leave it set permanently
90 -- from then on, this is a signal that second and subsequent users
91 -- of the hash table must clear the old entries before reuse.
93 subtype NCT_Header_Num is Int range 0 .. 511;
94 -- Defines range of headers in hash tables (512 headers)
96 ----------------------------------
97 -- Order Dependence (AI05-0144) --
98 ----------------------------------
100 -- Each actual in a call is entered into the table below. A flag indicates
101 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
102 -- (procedure call, condition, assignment) examines all the actuals for a
103 -- possible order dependence. The table is reset after each such check.
105 type Actual_Name is record
107 Is_Writable : Boolean;
108 -- Comments needed???
112 package Actuals_In_Call is new Table.Table (
113 Table_Component_Type => Actual_Name,
114 Table_Index_Type => Int,
115 Table_Low_Bound => 0,
117 Table_Increment => 100,
118 Table_Name => "Actuals");
120 -----------------------
121 -- Local Subprograms --
122 -----------------------
124 function Build_Component_Subtype
127 T : Entity_Id) return Node_Id;
128 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
129 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
130 -- Loc is the source location, T is the original subtype.
132 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
133 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
134 -- with discriminants whose default values are static, examine only the
135 -- components in the selected variant to determine whether all of them
138 function Has_Null_Extension (T : Entity_Id) return Boolean;
139 -- T is a derived tagged type. Check whether the type extension is null.
140 -- If the parent type is fully initialized, T can be treated as such.
142 ------------------------------
143 -- Abstract_Interface_List --
144 ------------------------------
146 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
150 if Is_Concurrent_Type (Typ) then
152 -- If we are dealing with a synchronized subtype, go to the base
153 -- type, whose declaration has the interface list.
155 -- Shouldn't this be Declaration_Node???
157 Nod := Parent (Base_Type (Typ));
159 if Nkind (Nod) = N_Full_Type_Declaration then
163 elsif Ekind (Typ) = E_Record_Type_With_Private then
164 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
165 Nod := Type_Definition (Parent (Typ));
167 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
168 if Present (Full_View (Typ)) then
169 Nod := Type_Definition (Parent (Full_View (Typ)));
171 -- If the full-view is not available we cannot do anything else
172 -- here (the source has errors).
178 -- Support for generic formals with interfaces is still missing ???
180 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
185 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
189 elsif Ekind (Typ) = E_Record_Subtype then
190 Nod := Type_Definition (Parent (Etype (Typ)));
192 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
194 -- Recurse, because parent may still be a private extension. Also
195 -- note that the full view of the subtype or the full view of its
196 -- base type may (both) be unavailable.
198 return Abstract_Interface_List (Etype (Typ));
200 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
201 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
202 Nod := Formal_Type_Definition (Parent (Typ));
204 Nod := Type_Definition (Parent (Typ));
208 return Interface_List (Nod);
209 end Abstract_Interface_List;
211 --------------------------------
212 -- Add_Access_Type_To_Process --
213 --------------------------------
215 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
219 Ensure_Freeze_Node (E);
220 L := Access_Types_To_Process (Freeze_Node (E));
224 Set_Access_Types_To_Process (Freeze_Node (E), L);
228 end Add_Access_Type_To_Process;
230 ----------------------------
231 -- Add_Global_Declaration --
232 ----------------------------
234 procedure Add_Global_Declaration (N : Node_Id) is
235 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
238 if No (Declarations (Aux_Node)) then
239 Set_Declarations (Aux_Node, New_List);
242 Append_To (Declarations (Aux_Node), N);
244 end Add_Global_Declaration;
250 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
252 function Addressable (V : Uint) return Boolean is
254 return V = Uint_8 or else
260 function Addressable (V : Int) return Boolean is
268 -----------------------
269 -- Alignment_In_Bits --
270 -----------------------
272 function Alignment_In_Bits (E : Entity_Id) return Uint is
274 return Alignment (E) * System_Storage_Unit;
275 end Alignment_In_Bits;
277 -----------------------------------------
278 -- Apply_Compile_Time_Constraint_Error --
279 -----------------------------------------
281 procedure Apply_Compile_Time_Constraint_Error
284 Reason : RT_Exception_Code;
285 Ent : Entity_Id := Empty;
286 Typ : Entity_Id := Empty;
287 Loc : Source_Ptr := No_Location;
288 Rep : Boolean := True;
289 Warn : Boolean := False)
291 Stat : constant Boolean := Is_Static_Expression (N);
292 R_Stat : constant Node_Id :=
293 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
304 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
310 -- Now we replace the node by an N_Raise_Constraint_Error node
311 -- This does not need reanalyzing, so set it as analyzed now.
314 Set_Analyzed (N, True);
317 Set_Raises_Constraint_Error (N);
319 -- Now deal with possible local raise handling
321 Possible_Local_Raise (N, Standard_Constraint_Error);
323 -- If the original expression was marked as static, the result is
324 -- still marked as static, but the Raises_Constraint_Error flag is
325 -- always set so that further static evaluation is not attempted.
328 Set_Is_Static_Expression (N);
330 end Apply_Compile_Time_Constraint_Error;
332 --------------------------
333 -- Build_Actual_Subtype --
334 --------------------------
336 function Build_Actual_Subtype
338 N : Node_Or_Entity_Id) return Node_Id
341 -- Normally Sloc (N), but may point to corresponding body in some cases
343 Constraints : List_Id;
349 Disc_Type : Entity_Id;
355 if Nkind (N) = N_Defining_Identifier then
356 Obj := New_Reference_To (N, Loc);
358 -- If this is a formal parameter of a subprogram declaration, and
359 -- we are compiling the body, we want the declaration for the
360 -- actual subtype to carry the source position of the body, to
361 -- prevent anomalies in gdb when stepping through the code.
363 if Is_Formal (N) then
365 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
367 if Nkind (Decl) = N_Subprogram_Declaration
368 and then Present (Corresponding_Body (Decl))
370 Loc := Sloc (Corresponding_Body (Decl));
379 if Is_Array_Type (T) then
380 Constraints := New_List;
381 for J in 1 .. Number_Dimensions (T) loop
383 -- Build an array subtype declaration with the nominal subtype and
384 -- the bounds of the actual. Add the declaration in front of the
385 -- local declarations for the subprogram, for analysis before any
386 -- reference to the formal in the body.
389 Make_Attribute_Reference (Loc,
391 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
392 Attribute_Name => Name_First,
393 Expressions => New_List (
394 Make_Integer_Literal (Loc, J)));
397 Make_Attribute_Reference (Loc,
399 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
400 Attribute_Name => Name_Last,
401 Expressions => New_List (
402 Make_Integer_Literal (Loc, J)));
404 Append (Make_Range (Loc, Lo, Hi), Constraints);
407 -- If the type has unknown discriminants there is no constrained
408 -- subtype to build. This is never called for a formal or for a
409 -- lhs, so returning the type is ok ???
411 elsif Has_Unknown_Discriminants (T) then
415 Constraints := New_List;
417 -- Type T is a generic derived type, inherit the discriminants from
420 if Is_Private_Type (T)
421 and then No (Full_View (T))
423 -- T was flagged as an error if it was declared as a formal
424 -- derived type with known discriminants. In this case there
425 -- is no need to look at the parent type since T already carries
426 -- its own discriminants.
428 and then not Error_Posted (T)
430 Disc_Type := Etype (Base_Type (T));
435 Discr := First_Discriminant (Disc_Type);
436 while Present (Discr) loop
437 Append_To (Constraints,
438 Make_Selected_Component (Loc,
440 Duplicate_Subexpr_No_Checks (Obj),
441 Selector_Name => New_Occurrence_Of (Discr, Loc)));
442 Next_Discriminant (Discr);
446 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
447 Set_Is_Internal (Subt);
450 Make_Subtype_Declaration (Loc,
451 Defining_Identifier => Subt,
452 Subtype_Indication =>
453 Make_Subtype_Indication (Loc,
454 Subtype_Mark => New_Reference_To (T, Loc),
456 Make_Index_Or_Discriminant_Constraint (Loc,
457 Constraints => Constraints)));
459 Mark_Rewrite_Insertion (Decl);
461 end Build_Actual_Subtype;
463 ---------------------------------------
464 -- Build_Actual_Subtype_Of_Component --
465 ---------------------------------------
467 function Build_Actual_Subtype_Of_Component
469 N : Node_Id) return Node_Id
471 Loc : constant Source_Ptr := Sloc (N);
472 P : constant Node_Id := Prefix (N);
475 Indx_Type : Entity_Id;
477 Deaccessed_T : Entity_Id;
478 -- This is either a copy of T, or if T is an access type, then it is
479 -- the directly designated type of this access type.
481 function Build_Actual_Array_Constraint return List_Id;
482 -- If one or more of the bounds of the component depends on
483 -- discriminants, build actual constraint using the discriminants
486 function Build_Actual_Record_Constraint return List_Id;
487 -- Similar to previous one, for discriminated components constrained
488 -- by the discriminant of the enclosing object.
490 -----------------------------------
491 -- Build_Actual_Array_Constraint --
492 -----------------------------------
494 function Build_Actual_Array_Constraint return List_Id is
495 Constraints : constant List_Id := New_List;
503 Indx := First_Index (Deaccessed_T);
504 while Present (Indx) loop
505 Old_Lo := Type_Low_Bound (Etype (Indx));
506 Old_Hi := Type_High_Bound (Etype (Indx));
508 if Denotes_Discriminant (Old_Lo) then
510 Make_Selected_Component (Loc,
511 Prefix => New_Copy_Tree (P),
512 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
515 Lo := New_Copy_Tree (Old_Lo);
517 -- The new bound will be reanalyzed in the enclosing
518 -- declaration. For literal bounds that come from a type
519 -- declaration, the type of the context must be imposed, so
520 -- insure that analysis will take place. For non-universal
521 -- types this is not strictly necessary.
523 Set_Analyzed (Lo, False);
526 if Denotes_Discriminant (Old_Hi) then
528 Make_Selected_Component (Loc,
529 Prefix => New_Copy_Tree (P),
530 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
533 Hi := New_Copy_Tree (Old_Hi);
534 Set_Analyzed (Hi, False);
537 Append (Make_Range (Loc, Lo, Hi), Constraints);
542 end Build_Actual_Array_Constraint;
544 ------------------------------------
545 -- Build_Actual_Record_Constraint --
546 ------------------------------------
548 function Build_Actual_Record_Constraint return List_Id is
549 Constraints : constant List_Id := New_List;
554 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
555 while Present (D) loop
556 if Denotes_Discriminant (Node (D)) then
557 D_Val := Make_Selected_Component (Loc,
558 Prefix => New_Copy_Tree (P),
559 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
562 D_Val := New_Copy_Tree (Node (D));
565 Append (D_Val, Constraints);
570 end Build_Actual_Record_Constraint;
572 -- Start of processing for Build_Actual_Subtype_Of_Component
575 -- Why the test for Spec_Expression mode here???
577 if In_Spec_Expression then
580 -- More comments for the rest of this body would be good ???
582 elsif Nkind (N) = N_Explicit_Dereference then
583 if Is_Composite_Type (T)
584 and then not Is_Constrained (T)
585 and then not (Is_Class_Wide_Type (T)
586 and then Is_Constrained (Root_Type (T)))
587 and then not Has_Unknown_Discriminants (T)
589 -- If the type of the dereference is already constrained, it is an
592 if Is_Array_Type (Etype (N))
593 and then Is_Constrained (Etype (N))
597 Remove_Side_Effects (P);
598 return Build_Actual_Subtype (T, N);
605 if Ekind (T) = E_Access_Subtype then
606 Deaccessed_T := Designated_Type (T);
611 if Ekind (Deaccessed_T) = E_Array_Subtype then
612 Id := First_Index (Deaccessed_T);
613 while Present (Id) loop
614 Indx_Type := Underlying_Type (Etype (Id));
616 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
618 Denotes_Discriminant (Type_High_Bound (Indx_Type))
620 Remove_Side_Effects (P);
622 Build_Component_Subtype
623 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
629 elsif Is_Composite_Type (Deaccessed_T)
630 and then Has_Discriminants (Deaccessed_T)
631 and then not Has_Unknown_Discriminants (Deaccessed_T)
633 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
634 while Present (D) loop
635 if Denotes_Discriminant (Node (D)) then
636 Remove_Side_Effects (P);
638 Build_Component_Subtype (
639 Build_Actual_Record_Constraint, Loc, Base_Type (T));
646 -- If none of the above, the actual and nominal subtypes are the same
649 end Build_Actual_Subtype_Of_Component;
651 -----------------------------
652 -- Build_Component_Subtype --
653 -----------------------------
655 function Build_Component_Subtype
658 T : Entity_Id) return Node_Id
664 -- Unchecked_Union components do not require component subtypes
666 if Is_Unchecked_Union (T) then
670 Subt := Make_Temporary (Loc, 'S');
671 Set_Is_Internal (Subt);
674 Make_Subtype_Declaration (Loc,
675 Defining_Identifier => Subt,
676 Subtype_Indication =>
677 Make_Subtype_Indication (Loc,
678 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
680 Make_Index_Or_Discriminant_Constraint (Loc,
683 Mark_Rewrite_Insertion (Decl);
685 end Build_Component_Subtype;
687 ---------------------------
688 -- Build_Default_Subtype --
689 ---------------------------
691 function Build_Default_Subtype
693 N : Node_Id) return Entity_Id
695 Loc : constant Source_Ptr := Sloc (N);
699 if not Has_Discriminants (T) or else Is_Constrained (T) then
703 Disc := First_Discriminant (T);
705 if No (Discriminant_Default_Value (Disc)) then
710 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
711 Constraints : constant List_Id := New_List;
715 while Present (Disc) loop
716 Append_To (Constraints,
717 New_Copy_Tree (Discriminant_Default_Value (Disc)));
718 Next_Discriminant (Disc);
722 Make_Subtype_Declaration (Loc,
723 Defining_Identifier => Act,
724 Subtype_Indication =>
725 Make_Subtype_Indication (Loc,
726 Subtype_Mark => New_Occurrence_Of (T, Loc),
728 Make_Index_Or_Discriminant_Constraint (Loc,
729 Constraints => Constraints)));
731 Insert_Action (N, Decl);
735 end Build_Default_Subtype;
737 --------------------------------------------
738 -- Build_Discriminal_Subtype_Of_Component --
739 --------------------------------------------
741 function Build_Discriminal_Subtype_Of_Component
742 (T : Entity_Id) return Node_Id
744 Loc : constant Source_Ptr := Sloc (T);
748 function Build_Discriminal_Array_Constraint return List_Id;
749 -- If one or more of the bounds of the component depends on
750 -- discriminants, build actual constraint using the discriminants
753 function Build_Discriminal_Record_Constraint return List_Id;
754 -- Similar to previous one, for discriminated components constrained
755 -- by the discriminant of the enclosing object.
757 ----------------------------------------
758 -- Build_Discriminal_Array_Constraint --
759 ----------------------------------------
761 function Build_Discriminal_Array_Constraint return List_Id is
762 Constraints : constant List_Id := New_List;
770 Indx := First_Index (T);
771 while Present (Indx) loop
772 Old_Lo := Type_Low_Bound (Etype (Indx));
773 Old_Hi := Type_High_Bound (Etype (Indx));
775 if Denotes_Discriminant (Old_Lo) then
776 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
779 Lo := New_Copy_Tree (Old_Lo);
782 if Denotes_Discriminant (Old_Hi) then
783 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
786 Hi := New_Copy_Tree (Old_Hi);
789 Append (Make_Range (Loc, Lo, Hi), Constraints);
794 end Build_Discriminal_Array_Constraint;
796 -----------------------------------------
797 -- Build_Discriminal_Record_Constraint --
798 -----------------------------------------
800 function Build_Discriminal_Record_Constraint return List_Id is
801 Constraints : constant List_Id := New_List;
806 D := First_Elmt (Discriminant_Constraint (T));
807 while Present (D) loop
808 if Denotes_Discriminant (Node (D)) then
810 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
813 D_Val := New_Copy_Tree (Node (D));
816 Append (D_Val, Constraints);
821 end Build_Discriminal_Record_Constraint;
823 -- Start of processing for Build_Discriminal_Subtype_Of_Component
826 if Ekind (T) = E_Array_Subtype then
827 Id := First_Index (T);
828 while Present (Id) loop
829 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
830 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
832 return Build_Component_Subtype
833 (Build_Discriminal_Array_Constraint, Loc, T);
839 elsif Ekind (T) = E_Record_Subtype
840 and then Has_Discriminants (T)
841 and then not Has_Unknown_Discriminants (T)
843 D := First_Elmt (Discriminant_Constraint (T));
844 while Present (D) loop
845 if Denotes_Discriminant (Node (D)) then
846 return Build_Component_Subtype
847 (Build_Discriminal_Record_Constraint, Loc, T);
854 -- If none of the above, the actual and nominal subtypes are the same
857 end Build_Discriminal_Subtype_Of_Component;
859 ------------------------------
860 -- Build_Elaboration_Entity --
861 ------------------------------
863 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
864 Loc : constant Source_Ptr := Sloc (N);
866 Elab_Ent : Entity_Id;
868 procedure Set_Package_Name (Ent : Entity_Id);
869 -- Given an entity, sets the fully qualified name of the entity in
870 -- Name_Buffer, with components separated by double underscores. This
871 -- is a recursive routine that climbs the scope chain to Standard.
873 ----------------------
874 -- Set_Package_Name --
875 ----------------------
877 procedure Set_Package_Name (Ent : Entity_Id) is
879 if Scope (Ent) /= Standard_Standard then
880 Set_Package_Name (Scope (Ent));
883 Nam : constant String := Get_Name_String (Chars (Ent));
885 Name_Buffer (Name_Len + 1) := '_';
886 Name_Buffer (Name_Len + 2) := '_';
887 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
888 Name_Len := Name_Len + Nam'Length + 2;
892 Get_Name_String (Chars (Ent));
894 end Set_Package_Name;
896 -- Start of processing for Build_Elaboration_Entity
899 -- Ignore if already constructed
901 if Present (Elaboration_Entity (Spec_Id)) then
905 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
906 -- name with dots replaced by double underscore. We have to manually
907 -- construct this name, since it will be elaborated in the outer scope,
908 -- and thus will not have the unit name automatically prepended.
910 Set_Package_Name (Spec_Id);
914 Name_Buffer (Name_Len + 1) := '_';
915 Name_Buffer (Name_Len + 2) := 'E';
916 Name_Len := Name_Len + 2;
918 -- Create elaboration flag
921 Make_Defining_Identifier (Loc, Chars => Name_Find);
922 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
925 Make_Object_Declaration (Loc,
926 Defining_Identifier => Elab_Ent,
928 New_Occurrence_Of (Standard_Boolean, Loc),
930 New_Occurrence_Of (Standard_False, Loc));
932 Push_Scope (Standard_Standard);
933 Add_Global_Declaration (Decl);
936 -- Reset True_Constant indication, since we will indeed assign a value
937 -- to the variable in the binder main. We also kill the Current_Value
938 -- and Last_Assignment fields for the same reason.
940 Set_Is_True_Constant (Elab_Ent, False);
941 Set_Current_Value (Elab_Ent, Empty);
942 Set_Last_Assignment (Elab_Ent, Empty);
944 -- We do not want any further qualification of the name (if we did
945 -- not do this, we would pick up the name of the generic package
946 -- in the case of a library level generic instantiation).
948 Set_Has_Qualified_Name (Elab_Ent);
949 Set_Has_Fully_Qualified_Name (Elab_Ent);
950 end Build_Elaboration_Entity;
952 -----------------------------------
953 -- Cannot_Raise_Constraint_Error --
954 -----------------------------------
956 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
958 if Compile_Time_Known_Value (Expr) then
961 elsif Do_Range_Check (Expr) then
964 elsif Raises_Constraint_Error (Expr) then
972 when N_Expanded_Name =>
975 when N_Selected_Component =>
976 return not Do_Discriminant_Check (Expr);
978 when N_Attribute_Reference =>
979 if Do_Overflow_Check (Expr) then
982 elsif No (Expressions (Expr)) then
990 N := First (Expressions (Expr));
991 while Present (N) loop
992 if Cannot_Raise_Constraint_Error (N) then
1003 when N_Type_Conversion =>
1004 if Do_Overflow_Check (Expr)
1005 or else Do_Length_Check (Expr)
1006 or else Do_Tag_Check (Expr)
1011 Cannot_Raise_Constraint_Error (Expression (Expr));
1014 when N_Unchecked_Type_Conversion =>
1015 return Cannot_Raise_Constraint_Error (Expression (Expr));
1018 if Do_Overflow_Check (Expr) then
1022 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1029 if Do_Division_Check (Expr)
1030 or else Do_Overflow_Check (Expr)
1035 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1037 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1056 N_Op_Shift_Right_Arithmetic |
1060 if Do_Overflow_Check (Expr) then
1064 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1066 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1073 end Cannot_Raise_Constraint_Error;
1075 -----------------------------------------
1076 -- Check_Dynamically_Tagged_Expression --
1077 -----------------------------------------
1079 procedure Check_Dynamically_Tagged_Expression
1082 Related_Nod : Node_Id)
1085 pragma Assert (Is_Tagged_Type (Typ));
1087 -- In order to avoid spurious errors when analyzing the expanded code,
1088 -- this check is done only for nodes that come from source and for
1089 -- actuals of generic instantiations.
1091 if (Comes_From_Source (Related_Nod)
1092 or else In_Generic_Actual (Expr))
1093 and then (Is_Class_Wide_Type (Etype (Expr))
1094 or else Is_Dynamically_Tagged (Expr))
1095 and then Is_Tagged_Type (Typ)
1096 and then not Is_Class_Wide_Type (Typ)
1098 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1100 end Check_Dynamically_Tagged_Expression;
1102 --------------------------
1103 -- Check_Fully_Declared --
1104 --------------------------
1106 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1108 if Ekind (T) = E_Incomplete_Type then
1110 -- Ada 2005 (AI-50217): If the type is available through a limited
1111 -- with_clause, verify that its full view has been analyzed.
1113 if From_With_Type (T)
1114 and then Present (Non_Limited_View (T))
1115 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1117 -- The non-limited view is fully declared
1122 ("premature usage of incomplete}", N, First_Subtype (T));
1125 -- Need comments for these tests ???
1127 elsif Has_Private_Component (T)
1128 and then not Is_Generic_Type (Root_Type (T))
1129 and then not In_Spec_Expression
1131 -- Special case: if T is the anonymous type created for a single
1132 -- task or protected object, use the name of the source object.
1134 if Is_Concurrent_Type (T)
1135 and then not Comes_From_Source (T)
1136 and then Nkind (N) = N_Object_Declaration
1138 Error_Msg_NE ("type of& has incomplete component", N,
1139 Defining_Identifier (N));
1143 ("premature usage of incomplete}", N, First_Subtype (T));
1146 end Check_Fully_Declared;
1148 -------------------------
1149 -- Check_Nested_Access --
1150 -------------------------
1152 procedure Check_Nested_Access (Ent : Entity_Id) is
1153 Scop : constant Entity_Id := Current_Scope;
1154 Current_Subp : Entity_Id;
1155 Enclosing : Entity_Id;
1158 -- Currently only enabled for VM back-ends for efficiency, should we
1159 -- enable it more systematically ???
1161 -- Check for Is_Imported needs commenting below ???
1163 if VM_Target /= No_VM
1164 and then (Ekind (Ent) = E_Variable
1166 Ekind (Ent) = E_Constant
1168 Ekind (Ent) = E_Loop_Parameter)
1169 and then Scope (Ent) /= Empty
1170 and then not Is_Library_Level_Entity (Ent)
1171 and then not Is_Imported (Ent)
1173 if Is_Subprogram (Scop)
1174 or else Is_Generic_Subprogram (Scop)
1175 or else Is_Entry (Scop)
1177 Current_Subp := Scop;
1179 Current_Subp := Current_Subprogram;
1182 Enclosing := Enclosing_Subprogram (Ent);
1184 if Enclosing /= Empty
1185 and then Enclosing /= Current_Subp
1187 Set_Has_Up_Level_Access (Ent, True);
1190 end Check_Nested_Access;
1192 ----------------------------
1193 -- Check_Order_Dependence --
1194 ----------------------------
1196 procedure Check_Order_Dependence is
1201 -- This could use comments ???
1203 for J in 0 .. Actuals_In_Call.Last loop
1204 if Actuals_In_Call.Table (J).Is_Writable then
1205 Act1 := Actuals_In_Call.Table (J).Act;
1207 if Nkind (Act1) = N_Attribute_Reference then
1208 Act1 := Prefix (Act1);
1211 for K in 0 .. Actuals_In_Call.Last loop
1213 Act2 := Actuals_In_Call.Table (K).Act;
1215 if Nkind (Act2) = N_Attribute_Reference then
1216 Act2 := Prefix (Act2);
1219 if Actuals_In_Call.Table (K).Is_Writable
1226 elsif Denotes_Same_Object (Act1, Act2)
1229 Error_Msg_N ("?,mighty suspicious!!!", Act1);
1236 Actuals_In_Call.Set_Last (0);
1237 end Check_Order_Dependence;
1239 ------------------------------------------
1240 -- Check_Potentially_Blocking_Operation --
1241 ------------------------------------------
1243 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1246 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1247 -- When pragma Detect_Blocking is active, the run time will raise
1248 -- Program_Error. Here we only issue a warning, since we generally
1249 -- support the use of potentially blocking operations in the absence
1252 -- Indirect blocking through a subprogram call cannot be diagnosed
1253 -- statically without interprocedural analysis, so we do not attempt
1256 S := Scope (Current_Scope);
1257 while Present (S) and then S /= Standard_Standard loop
1258 if Is_Protected_Type (S) then
1260 ("potentially blocking operation in protected operation?", N);
1267 end Check_Potentially_Blocking_Operation;
1269 ------------------------------
1270 -- Check_Unprotected_Access --
1271 ------------------------------
1273 procedure Check_Unprotected_Access
1277 Cont_Encl_Typ : Entity_Id;
1278 Pref_Encl_Typ : Entity_Id;
1280 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1281 -- Check whether Obj is a private component of a protected object.
1282 -- Return the protected type where the component resides, Empty
1285 function Is_Public_Operation return Boolean;
1286 -- Verify that the enclosing operation is callable from outside the
1287 -- protected object, to minimize false positives.
1289 ------------------------------
1290 -- Enclosing_Protected_Type --
1291 ------------------------------
1293 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1295 if Is_Entity_Name (Obj) then
1297 Ent : Entity_Id := Entity (Obj);
1300 -- The object can be a renaming of a private component, use
1301 -- the original record component.
1303 if Is_Prival (Ent) then
1304 Ent := Prival_Link (Ent);
1307 if Is_Protected_Type (Scope (Ent)) then
1313 -- For indexed and selected components, recursively check the prefix
1315 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1316 return Enclosing_Protected_Type (Prefix (Obj));
1318 -- The object does not denote a protected component
1323 end Enclosing_Protected_Type;
1325 -------------------------
1326 -- Is_Public_Operation --
1327 -------------------------
1329 function Is_Public_Operation return Boolean is
1336 and then S /= Pref_Encl_Typ
1338 if Scope (S) = Pref_Encl_Typ then
1339 E := First_Entity (Pref_Encl_Typ);
1341 and then E /= First_Private_Entity (Pref_Encl_Typ)
1354 end Is_Public_Operation;
1356 -- Start of processing for Check_Unprotected_Access
1359 if Nkind (Expr) = N_Attribute_Reference
1360 and then Attribute_Name (Expr) = Name_Unchecked_Access
1362 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1363 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1365 -- Check whether we are trying to export a protected component to a
1366 -- context with an equal or lower access level.
1368 if Present (Pref_Encl_Typ)
1369 and then No (Cont_Encl_Typ)
1370 and then Is_Public_Operation
1371 and then Scope_Depth (Pref_Encl_Typ) >=
1372 Object_Access_Level (Context)
1375 ("?possible unprotected access to protected data", Expr);
1378 end Check_Unprotected_Access;
1384 procedure Check_VMS (Construct : Node_Id) is
1386 if not OpenVMS_On_Target then
1388 ("this construct is allowed only in Open'V'M'S", Construct);
1392 ------------------------
1393 -- Collect_Interfaces --
1394 ------------------------
1396 procedure Collect_Interfaces
1398 Ifaces_List : out Elist_Id;
1399 Exclude_Parents : Boolean := False;
1400 Use_Full_View : Boolean := True)
1402 procedure Collect (Typ : Entity_Id);
1403 -- Subsidiary subprogram used to traverse the whole list
1404 -- of directly and indirectly implemented interfaces
1410 procedure Collect (Typ : Entity_Id) is
1411 Ancestor : Entity_Id;
1419 -- Handle private types
1422 and then Is_Private_Type (Typ)
1423 and then Present (Full_View (Typ))
1425 Full_T := Full_View (Typ);
1428 -- Include the ancestor if we are generating the whole list of
1429 -- abstract interfaces.
1431 if Etype (Full_T) /= Typ
1433 -- Protect the frontend against wrong sources. For example:
1436 -- type A is tagged null record;
1437 -- type B is new A with private;
1438 -- type C is new A with private;
1440 -- type B is new C with null record;
1441 -- type C is new B with null record;
1444 and then Etype (Full_T) /= T
1446 Ancestor := Etype (Full_T);
1449 if Is_Interface (Ancestor)
1450 and then not Exclude_Parents
1452 Append_Unique_Elmt (Ancestor, Ifaces_List);
1456 -- Traverse the graph of ancestor interfaces
1458 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1459 Id := First (Abstract_Interface_List (Full_T));
1460 while Present (Id) loop
1461 Iface := Etype (Id);
1463 -- Protect against wrong uses. For example:
1464 -- type I is interface;
1465 -- type O is tagged null record;
1466 -- type Wrong is new I and O with null record; -- ERROR
1468 if Is_Interface (Iface) then
1470 and then Etype (T) /= T
1471 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1476 Append_Unique_Elmt (Iface, Ifaces_List);
1485 -- Start of processing for Collect_Interfaces
1488 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1489 Ifaces_List := New_Elmt_List;
1491 end Collect_Interfaces;
1493 ----------------------------------
1494 -- Collect_Interface_Components --
1495 ----------------------------------
1497 procedure Collect_Interface_Components
1498 (Tagged_Type : Entity_Id;
1499 Components_List : out Elist_Id)
1501 procedure Collect (Typ : Entity_Id);
1502 -- Subsidiary subprogram used to climb to the parents
1508 procedure Collect (Typ : Entity_Id) is
1509 Tag_Comp : Entity_Id;
1510 Parent_Typ : Entity_Id;
1513 -- Handle private types
1515 if Present (Full_View (Etype (Typ))) then
1516 Parent_Typ := Full_View (Etype (Typ));
1518 Parent_Typ := Etype (Typ);
1521 if Parent_Typ /= Typ
1523 -- Protect the frontend against wrong sources. For example:
1526 -- type A is tagged null record;
1527 -- type B is new A with private;
1528 -- type C is new A with private;
1530 -- type B is new C with null record;
1531 -- type C is new B with null record;
1534 and then Parent_Typ /= Tagged_Type
1536 Collect (Parent_Typ);
1539 -- Collect the components containing tags of secondary dispatch
1542 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1543 while Present (Tag_Comp) loop
1544 pragma Assert (Present (Related_Type (Tag_Comp)));
1545 Append_Elmt (Tag_Comp, Components_List);
1547 Tag_Comp := Next_Tag_Component (Tag_Comp);
1551 -- Start of processing for Collect_Interface_Components
1554 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1555 and then Is_Tagged_Type (Tagged_Type));
1557 Components_List := New_Elmt_List;
1558 Collect (Tagged_Type);
1559 end Collect_Interface_Components;
1561 -----------------------------
1562 -- Collect_Interfaces_Info --
1563 -----------------------------
1565 procedure Collect_Interfaces_Info
1567 Ifaces_List : out Elist_Id;
1568 Components_List : out Elist_Id;
1569 Tags_List : out Elist_Id)
1571 Comps_List : Elist_Id;
1572 Comp_Elmt : Elmt_Id;
1573 Comp_Iface : Entity_Id;
1574 Iface_Elmt : Elmt_Id;
1577 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1578 -- Search for the secondary tag associated with the interface type
1579 -- Iface that is implemented by T.
1585 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1588 if not Is_CPP_Class (T) then
1589 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1591 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1595 and then Is_Tag (Node (ADT))
1596 and then Related_Type (Node (ADT)) /= Iface
1598 -- Skip secondary dispatch table referencing thunks to user
1599 -- defined primitives covered by this interface.
1601 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1604 -- Skip secondary dispatch tables of Ada types
1606 if not Is_CPP_Class (T) then
1608 -- Skip secondary dispatch table referencing thunks to
1609 -- predefined primitives.
1611 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1614 -- Skip secondary dispatch table referencing user-defined
1615 -- primitives covered by this interface.
1617 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1620 -- Skip secondary dispatch table referencing predefined
1623 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1628 pragma Assert (Is_Tag (Node (ADT)));
1632 -- Start of processing for Collect_Interfaces_Info
1635 Collect_Interfaces (T, Ifaces_List);
1636 Collect_Interface_Components (T, Comps_List);
1638 -- Search for the record component and tag associated with each
1639 -- interface type of T.
1641 Components_List := New_Elmt_List;
1642 Tags_List := New_Elmt_List;
1644 Iface_Elmt := First_Elmt (Ifaces_List);
1645 while Present (Iface_Elmt) loop
1646 Iface := Node (Iface_Elmt);
1648 -- Associate the primary tag component and the primary dispatch table
1649 -- with all the interfaces that are parents of T
1651 if Is_Ancestor (Iface, T) then
1652 Append_Elmt (First_Tag_Component (T), Components_List);
1653 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1655 -- Otherwise search for the tag component and secondary dispatch
1659 Comp_Elmt := First_Elmt (Comps_List);
1660 while Present (Comp_Elmt) loop
1661 Comp_Iface := Related_Type (Node (Comp_Elmt));
1663 if Comp_Iface = Iface
1664 or else Is_Ancestor (Iface, Comp_Iface)
1666 Append_Elmt (Node (Comp_Elmt), Components_List);
1667 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1671 Next_Elmt (Comp_Elmt);
1673 pragma Assert (Present (Comp_Elmt));
1676 Next_Elmt (Iface_Elmt);
1678 end Collect_Interfaces_Info;
1680 ---------------------
1681 -- Collect_Parents --
1682 ---------------------
1684 procedure Collect_Parents
1686 List : out Elist_Id;
1687 Use_Full_View : Boolean := True)
1689 Current_Typ : Entity_Id := T;
1690 Parent_Typ : Entity_Id;
1693 List := New_Elmt_List;
1695 -- No action if the if the type has no parents
1697 if T = Etype (T) then
1702 Parent_Typ := Etype (Current_Typ);
1704 if Is_Private_Type (Parent_Typ)
1705 and then Present (Full_View (Parent_Typ))
1706 and then Use_Full_View
1708 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1711 Append_Elmt (Parent_Typ, List);
1713 exit when Parent_Typ = Current_Typ;
1714 Current_Typ := Parent_Typ;
1716 end Collect_Parents;
1718 ----------------------------------
1719 -- Collect_Primitive_Operations --
1720 ----------------------------------
1722 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1723 B_Type : constant Entity_Id := Base_Type (T);
1724 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1725 B_Scope : Entity_Id := Scope (B_Type);
1729 Formal_Derived : Boolean := False;
1732 function Match (E : Entity_Id) return Boolean;
1733 -- True if E's base type is B_Type, or E is of an anonymous access type
1734 -- and the base type of its designated type is B_Type.
1740 function Match (E : Entity_Id) return Boolean is
1741 Etyp : Entity_Id := Etype (E);
1744 if Ekind (Etyp) = E_Anonymous_Access_Type then
1745 Etyp := Designated_Type (Etyp);
1748 return Base_Type (Etyp) = B_Type;
1751 -- Start of processing for Collect_Primitive_Operations
1754 -- For tagged types, the primitive operations are collected as they
1755 -- are declared, and held in an explicit list which is simply returned.
1757 if Is_Tagged_Type (B_Type) then
1758 return Primitive_Operations (B_Type);
1760 -- An untagged generic type that is a derived type inherits the
1761 -- primitive operations of its parent type. Other formal types only
1762 -- have predefined operators, which are not explicitly represented.
1764 elsif Is_Generic_Type (B_Type) then
1765 if Nkind (B_Decl) = N_Formal_Type_Declaration
1766 and then Nkind (Formal_Type_Definition (B_Decl))
1767 = N_Formal_Derived_Type_Definition
1769 Formal_Derived := True;
1771 return New_Elmt_List;
1775 Op_List := New_Elmt_List;
1777 if B_Scope = Standard_Standard then
1778 if B_Type = Standard_String then
1779 Append_Elmt (Standard_Op_Concat, Op_List);
1781 elsif B_Type = Standard_Wide_String then
1782 Append_Elmt (Standard_Op_Concatw, Op_List);
1788 elsif (Is_Package_Or_Generic_Package (B_Scope)
1790 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1792 or else Is_Derived_Type (B_Type)
1794 -- The primitive operations appear after the base type, except
1795 -- if the derivation happens within the private part of B_Scope
1796 -- and the type is a private type, in which case both the type
1797 -- and some primitive operations may appear before the base
1798 -- type, and the list of candidates starts after the type.
1800 if In_Open_Scopes (B_Scope)
1801 and then Scope (T) = B_Scope
1802 and then In_Private_Part (B_Scope)
1804 Id := Next_Entity (T);
1806 Id := Next_Entity (B_Type);
1809 while Present (Id) loop
1811 -- Note that generic formal subprograms are not
1812 -- considered to be primitive operations and thus
1813 -- are never inherited.
1815 if Is_Overloadable (Id)
1816 and then Nkind (Parent (Parent (Id)))
1817 not in N_Formal_Subprogram_Declaration
1825 Formal := First_Formal (Id);
1826 while Present (Formal) loop
1827 if Match (Formal) then
1832 Next_Formal (Formal);
1836 -- For a formal derived type, the only primitives are the
1837 -- ones inherited from the parent type. Operations appearing
1838 -- in the package declaration are not primitive for it.
1841 and then (not Formal_Derived
1842 or else Present (Alias (Id)))
1844 -- In the special case of an equality operator aliased to
1845 -- an overriding dispatching equality belonging to the same
1846 -- type, we don't include it in the list of primitives.
1847 -- This avoids inheriting multiple equality operators when
1848 -- deriving from untagged private types whose full type is
1849 -- tagged, which can otherwise cause ambiguities. Note that
1850 -- this should only happen for this kind of untagged parent
1851 -- type, since normally dispatching operations are inherited
1852 -- using the type's Primitive_Operations list.
1854 if Chars (Id) = Name_Op_Eq
1855 and then Is_Dispatching_Operation (Id)
1856 and then Present (Alias (Id))
1857 and then Is_Overriding_Operation (Alias (Id))
1858 and then Base_Type (Etype (First_Entity (Id))) =
1859 Base_Type (Etype (First_Entity (Alias (Id))))
1863 -- Include the subprogram in the list of primitives
1866 Append_Elmt (Id, Op_List);
1873 -- For a type declared in System, some of its operations may
1874 -- appear in the target-specific extension to System.
1877 and then B_Scope = RTU_Entity (System)
1878 and then Present_System_Aux
1880 B_Scope := System_Aux_Id;
1881 Id := First_Entity (System_Aux_Id);
1887 end Collect_Primitive_Operations;
1889 -----------------------------------
1890 -- Compile_Time_Constraint_Error --
1891 -----------------------------------
1893 function Compile_Time_Constraint_Error
1896 Ent : Entity_Id := Empty;
1897 Loc : Source_Ptr := No_Location;
1898 Warn : Boolean := False) return Node_Id
1900 Msgc : String (1 .. Msg'Length + 2);
1901 -- Copy of message, with room for possible ? and ! at end
1911 -- A static constraint error in an instance body is not a fatal error.
1912 -- we choose to inhibit the message altogether, because there is no
1913 -- obvious node (for now) on which to post it. On the other hand the
1914 -- offending node must be replaced with a constraint_error in any case.
1916 -- No messages are generated if we already posted an error on this node
1918 if not Error_Posted (N) then
1919 if Loc /= No_Location then
1925 Msgc (1 .. Msg'Length) := Msg;
1928 -- Message is a warning, even in Ada 95 case
1930 if Msg (Msg'Last) = '?' then
1933 -- In Ada 83, all messages are warnings. In the private part and
1934 -- the body of an instance, constraint_checks are only warnings.
1935 -- We also make this a warning if the Warn parameter is set.
1938 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1944 elsif In_Instance_Not_Visible then
1949 -- Otherwise we have a real error message (Ada 95 static case)
1950 -- and we make this an unconditional message. Note that in the
1951 -- warning case we do not make the message unconditional, it seems
1952 -- quite reasonable to delete messages like this (about exceptions
1953 -- that will be raised) in dead code.
1961 -- Should we generate a warning? The answer is not quite yes. The
1962 -- very annoying exception occurs in the case of a short circuit
1963 -- operator where the left operand is static and decisive. Climb
1964 -- parents to see if that is the case we have here. Conditional
1965 -- expressions with decisive conditions are a similar situation.
1973 -- And then with False as left operand
1975 if Nkind (P) = N_And_Then
1976 and then Compile_Time_Known_Value (Left_Opnd (P))
1977 and then Is_False (Expr_Value (Left_Opnd (P)))
1982 -- OR ELSE with True as left operand
1984 elsif Nkind (P) = N_Or_Else
1985 and then Compile_Time_Known_Value (Left_Opnd (P))
1986 and then Is_True (Expr_Value (Left_Opnd (P)))
1991 -- Conditional expression
1993 elsif Nkind (P) = N_Conditional_Expression then
1995 Cond : constant Node_Id := First (Expressions (P));
1996 Texp : constant Node_Id := Next (Cond);
1997 Fexp : constant Node_Id := Next (Texp);
2000 if Compile_Time_Known_Value (Cond) then
2002 -- Condition is True and we are in the right operand
2004 if Is_True (Expr_Value (Cond))
2005 and then OldP = Fexp
2010 -- Condition is False and we are in the left operand
2012 elsif Is_False (Expr_Value (Cond))
2013 and then OldP = Texp
2021 -- Special case for component association in aggregates, where
2022 -- we want to keep climbing up to the parent aggregate.
2024 elsif Nkind (P) = N_Component_Association
2025 and then Nkind (Parent (P)) = N_Aggregate
2029 -- Keep going if within subexpression
2032 exit when Nkind (P) not in N_Subexpr;
2037 if Present (Ent) then
2038 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2040 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2044 if Inside_Init_Proc then
2046 ("\?& will be raised for objects of this type",
2047 N, Standard_Constraint_Error, Eloc);
2050 ("\?& will be raised at run time",
2051 N, Standard_Constraint_Error, Eloc);
2056 ("\static expression fails Constraint_Check", Eloc);
2057 Set_Error_Posted (N);
2063 end Compile_Time_Constraint_Error;
2065 -----------------------
2066 -- Conditional_Delay --
2067 -----------------------
2069 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2071 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2072 Set_Has_Delayed_Freeze (New_Ent);
2074 end Conditional_Delay;
2076 -------------------------
2077 -- Copy_Parameter_List --
2078 -------------------------
2080 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2081 Loc : constant Source_Ptr := Sloc (Subp_Id);
2086 if No (First_Formal (Subp_Id)) then
2090 Formal := First_Formal (Subp_Id);
2091 while Present (Formal) loop
2093 (Make_Parameter_Specification (Loc,
2094 Defining_Identifier =>
2095 Make_Defining_Identifier (Sloc (Formal),
2096 Chars => Chars (Formal)),
2097 In_Present => In_Present (Parent (Formal)),
2098 Out_Present => Out_Present (Parent (Formal)),
2100 New_Reference_To (Etype (Formal), Loc),
2102 New_Copy_Tree (Expression (Parent (Formal)))),
2105 Next_Formal (Formal);
2110 end Copy_Parameter_List;
2112 --------------------
2113 -- Current_Entity --
2114 --------------------
2116 -- The currently visible definition for a given identifier is the
2117 -- one most chained at the start of the visibility chain, i.e. the
2118 -- one that is referenced by the Node_Id value of the name of the
2119 -- given identifier.
2121 function Current_Entity (N : Node_Id) return Entity_Id is
2123 return Get_Name_Entity_Id (Chars (N));
2126 -----------------------------
2127 -- Current_Entity_In_Scope --
2128 -----------------------------
2130 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2132 CS : constant Entity_Id := Current_Scope;
2134 Transient_Case : constant Boolean := Scope_Is_Transient;
2137 E := Get_Name_Entity_Id (Chars (N));
2139 and then Scope (E) /= CS
2140 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2146 end Current_Entity_In_Scope;
2152 function Current_Scope return Entity_Id is
2154 if Scope_Stack.Last = -1 then
2155 return Standard_Standard;
2158 C : constant Entity_Id :=
2159 Scope_Stack.Table (Scope_Stack.Last).Entity;
2164 return Standard_Standard;
2170 ------------------------
2171 -- Current_Subprogram --
2172 ------------------------
2174 function Current_Subprogram return Entity_Id is
2175 Scop : constant Entity_Id := Current_Scope;
2177 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2180 return Enclosing_Subprogram (Scop);
2182 end Current_Subprogram;
2184 ---------------------
2185 -- Defining_Entity --
2186 ---------------------
2188 function Defining_Entity (N : Node_Id) return Entity_Id is
2189 K : constant Node_Kind := Nkind (N);
2190 Err : Entity_Id := Empty;
2195 N_Subprogram_Declaration |
2196 N_Abstract_Subprogram_Declaration |
2198 N_Package_Declaration |
2199 N_Subprogram_Renaming_Declaration |
2200 N_Subprogram_Body_Stub |
2201 N_Generic_Subprogram_Declaration |
2202 N_Generic_Package_Declaration |
2203 N_Formal_Subprogram_Declaration
2205 return Defining_Entity (Specification (N));
2208 N_Component_Declaration |
2209 N_Defining_Program_Unit_Name |
2210 N_Discriminant_Specification |
2212 N_Entry_Declaration |
2213 N_Entry_Index_Specification |
2214 N_Exception_Declaration |
2215 N_Exception_Renaming_Declaration |
2216 N_Formal_Object_Declaration |
2217 N_Formal_Package_Declaration |
2218 N_Formal_Type_Declaration |
2219 N_Full_Type_Declaration |
2220 N_Implicit_Label_Declaration |
2221 N_Incomplete_Type_Declaration |
2222 N_Loop_Parameter_Specification |
2223 N_Number_Declaration |
2224 N_Object_Declaration |
2225 N_Object_Renaming_Declaration |
2226 N_Package_Body_Stub |
2227 N_Parameter_Specification |
2228 N_Private_Extension_Declaration |
2229 N_Private_Type_Declaration |
2231 N_Protected_Body_Stub |
2232 N_Protected_Type_Declaration |
2233 N_Single_Protected_Declaration |
2234 N_Single_Task_Declaration |
2235 N_Subtype_Declaration |
2238 N_Task_Type_Declaration
2240 return Defining_Identifier (N);
2243 return Defining_Entity (Proper_Body (N));
2246 N_Function_Instantiation |
2247 N_Function_Specification |
2248 N_Generic_Function_Renaming_Declaration |
2249 N_Generic_Package_Renaming_Declaration |
2250 N_Generic_Procedure_Renaming_Declaration |
2252 N_Package_Instantiation |
2253 N_Package_Renaming_Declaration |
2254 N_Package_Specification |
2255 N_Procedure_Instantiation |
2256 N_Procedure_Specification
2259 Nam : constant Node_Id := Defining_Unit_Name (N);
2262 if Nkind (Nam) in N_Entity then
2265 -- For Error, make up a name and attach to declaration
2266 -- so we can continue semantic analysis
2268 elsif Nam = Error then
2269 Err := Make_Temporary (Sloc (N), 'T');
2270 Set_Defining_Unit_Name (N, Err);
2273 -- If not an entity, get defining identifier
2276 return Defining_Identifier (Nam);
2280 when N_Block_Statement =>
2281 return Entity (Identifier (N));
2284 raise Program_Error;
2287 end Defining_Entity;
2289 --------------------------
2290 -- Denotes_Discriminant --
2291 --------------------------
2293 function Denotes_Discriminant
2295 Check_Concurrent : Boolean := False) return Boolean
2299 if not Is_Entity_Name (N)
2300 or else No (Entity (N))
2307 -- If we are checking for a protected type, the discriminant may have
2308 -- been rewritten as the corresponding discriminal of the original type
2309 -- or of the corresponding concurrent record, depending on whether we
2310 -- are in the spec or body of the protected type.
2312 return Ekind (E) = E_Discriminant
2315 and then Ekind (E) = E_In_Parameter
2316 and then Present (Discriminal_Link (E))
2318 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2320 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2322 end Denotes_Discriminant;
2324 -------------------------
2325 -- Denotes_Same_Object --
2326 -------------------------
2328 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2330 -- If we have entity names, then must be same entity
2332 if Is_Entity_Name (A1) then
2333 if Is_Entity_Name (A2) then
2334 return Entity (A1) = Entity (A2);
2339 -- No match if not same node kind
2341 elsif Nkind (A1) /= Nkind (A2) then
2344 -- For selected components, must have same prefix and selector
2346 elsif Nkind (A1) = N_Selected_Component then
2347 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
2349 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
2351 -- For explicit dereferences, prefixes must be same
2353 elsif Nkind (A1) = N_Explicit_Dereference then
2354 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
2356 -- For indexed components, prefixes and all subscripts must be the same
2358 elsif Nkind (A1) = N_Indexed_Component then
2359 if Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
2365 Indx1 := First (Expressions (A1));
2366 Indx2 := First (Expressions (A2));
2367 while Present (Indx1) loop
2369 -- Shouldn't we be checking that values are the same???
2371 if not Denotes_Same_Object (Indx1, Indx2) then
2385 -- For slices, prefixes must match and bounds must match
2387 elsif Nkind (A1) = N_Slice
2388 and then Denotes_Same_Object (Prefix (A1), Prefix (A2))
2391 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2394 Get_Index_Bounds (Etype (A1), Lo1, Hi1);
2395 Get_Index_Bounds (Etype (A2), Lo2, Hi2);
2397 -- Check whether bounds are statically identical. There is no
2398 -- attempt to detect partial overlap of slices.
2400 -- What about an array and a slice of an array???
2402 return Denotes_Same_Object (Lo1, Lo2)
2403 and then Denotes_Same_Object (Hi1, Hi2);
2406 -- Literals will appear as indexes. Isn't this where we should check
2407 -- Known_At_Compile_Time at least if we are generating warnings ???
2409 elsif Nkind (A1) = N_Integer_Literal then
2410 return Intval (A1) = Intval (A2);
2415 end Denotes_Same_Object;
2417 -------------------------
2418 -- Denotes_Same_Prefix --
2419 -------------------------
2421 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2424 if Is_Entity_Name (A1) then
2425 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2426 and then not Is_Access_Type (Etype (A1))
2428 return Denotes_Same_Object (A1, Prefix (A2))
2429 or else Denotes_Same_Prefix (A1, Prefix (A2));
2434 elsif Is_Entity_Name (A2) then
2435 return Denotes_Same_Prefix (A2, A1);
2437 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2439 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2442 Root1, Root2 : Node_Id;
2443 Depth1, Depth2 : Int := 0;
2446 Root1 := Prefix (A1);
2447 while not Is_Entity_Name (Root1) loop
2449 (Root1, N_Selected_Component, N_Indexed_Component)
2453 Root1 := Prefix (Root1);
2456 Depth1 := Depth1 + 1;
2459 Root2 := Prefix (A2);
2460 while not Is_Entity_Name (Root2) loop
2462 (Root2, N_Selected_Component, N_Indexed_Component)
2466 Root2 := Prefix (Root2);
2469 Depth2 := Depth2 + 1;
2472 -- If both have the same depth and they do not denote the same
2473 -- object, they are disjoint and not warning is needed.
2475 if Depth1 = Depth2 then
2478 elsif Depth1 > Depth2 then
2479 Root1 := Prefix (A1);
2480 for I in 1 .. Depth1 - Depth2 - 1 loop
2481 Root1 := Prefix (Root1);
2484 return Denotes_Same_Object (Root1, A2);
2487 Root2 := Prefix (A2);
2488 for I in 1 .. Depth2 - Depth1 - 1 loop
2489 Root2 := Prefix (Root2);
2492 return Denotes_Same_Object (A1, Root2);
2499 end Denotes_Same_Prefix;
2501 ----------------------
2502 -- Denotes_Variable --
2503 ----------------------
2505 function Denotes_Variable (N : Node_Id) return Boolean is
2507 return Is_Variable (N) and then Paren_Count (N) = 0;
2508 end Denotes_Variable;
2510 -----------------------------
2511 -- Depends_On_Discriminant --
2512 -----------------------------
2514 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2519 Get_Index_Bounds (N, L, H);
2520 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2521 end Depends_On_Discriminant;
2523 -------------------------
2524 -- Designate_Same_Unit --
2525 -------------------------
2527 function Designate_Same_Unit
2529 Name2 : Node_Id) return Boolean
2531 K1 : constant Node_Kind := Nkind (Name1);
2532 K2 : constant Node_Kind := Nkind (Name2);
2534 function Prefix_Node (N : Node_Id) return Node_Id;
2535 -- Returns the parent unit name node of a defining program unit name
2536 -- or the prefix if N is a selected component or an expanded name.
2538 function Select_Node (N : Node_Id) return Node_Id;
2539 -- Returns the defining identifier node of a defining program unit
2540 -- name or the selector node if N is a selected component or an
2547 function Prefix_Node (N : Node_Id) return Node_Id is
2549 if Nkind (N) = N_Defining_Program_Unit_Name then
2561 function Select_Node (N : Node_Id) return Node_Id is
2563 if Nkind (N) = N_Defining_Program_Unit_Name then
2564 return Defining_Identifier (N);
2567 return Selector_Name (N);
2571 -- Start of processing for Designate_Next_Unit
2574 if (K1 = N_Identifier or else
2575 K1 = N_Defining_Identifier)
2577 (K2 = N_Identifier or else
2578 K2 = N_Defining_Identifier)
2580 return Chars (Name1) = Chars (Name2);
2583 (K1 = N_Expanded_Name or else
2584 K1 = N_Selected_Component or else
2585 K1 = N_Defining_Program_Unit_Name)
2587 (K2 = N_Expanded_Name or else
2588 K2 = N_Selected_Component or else
2589 K2 = N_Defining_Program_Unit_Name)
2592 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2594 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2599 end Designate_Same_Unit;
2601 --------------------------
2602 -- Enclosing_CPP_Parent --
2603 --------------------------
2605 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2606 Parent_Typ : Entity_Id := Typ;
2609 while not Is_CPP_Class (Parent_Typ)
2610 and then Etype (Parent_Typ) /= Parent_Typ
2612 Parent_Typ := Etype (Parent_Typ);
2614 if Is_Private_Type (Parent_Typ) then
2615 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2619 pragma Assert (Is_CPP_Class (Parent_Typ));
2621 end Enclosing_CPP_Parent;
2623 ----------------------------
2624 -- Enclosing_Generic_Body --
2625 ----------------------------
2627 function Enclosing_Generic_Body
2628 (N : Node_Id) return Node_Id
2636 while Present (P) loop
2637 if Nkind (P) = N_Package_Body
2638 or else Nkind (P) = N_Subprogram_Body
2640 Spec := Corresponding_Spec (P);
2642 if Present (Spec) then
2643 Decl := Unit_Declaration_Node (Spec);
2645 if Nkind (Decl) = N_Generic_Package_Declaration
2646 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2657 end Enclosing_Generic_Body;
2659 ----------------------------
2660 -- Enclosing_Generic_Unit --
2661 ----------------------------
2663 function Enclosing_Generic_Unit
2664 (N : Node_Id) return Node_Id
2672 while Present (P) loop
2673 if Nkind (P) = N_Generic_Package_Declaration
2674 or else Nkind (P) = N_Generic_Subprogram_Declaration
2678 elsif Nkind (P) = N_Package_Body
2679 or else Nkind (P) = N_Subprogram_Body
2681 Spec := Corresponding_Spec (P);
2683 if Present (Spec) then
2684 Decl := Unit_Declaration_Node (Spec);
2686 if Nkind (Decl) = N_Generic_Package_Declaration
2687 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2698 end Enclosing_Generic_Unit;
2700 -------------------------------
2701 -- Enclosing_Lib_Unit_Entity --
2702 -------------------------------
2704 function Enclosing_Lib_Unit_Entity return Entity_Id is
2705 Unit_Entity : Entity_Id;
2708 -- Look for enclosing library unit entity by following scope links.
2709 -- Equivalent to, but faster than indexing through the scope stack.
2711 Unit_Entity := Current_Scope;
2712 while (Present (Scope (Unit_Entity))
2713 and then Scope (Unit_Entity) /= Standard_Standard)
2714 and not Is_Child_Unit (Unit_Entity)
2716 Unit_Entity := Scope (Unit_Entity);
2720 end Enclosing_Lib_Unit_Entity;
2722 -----------------------------
2723 -- Enclosing_Lib_Unit_Node --
2724 -----------------------------
2726 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2727 Current_Node : Node_Id;
2731 while Present (Current_Node)
2732 and then Nkind (Current_Node) /= N_Compilation_Unit
2734 Current_Node := Parent (Current_Node);
2737 if Nkind (Current_Node) /= N_Compilation_Unit then
2741 return Current_Node;
2742 end Enclosing_Lib_Unit_Node;
2744 --------------------------
2745 -- Enclosing_Subprogram --
2746 --------------------------
2748 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2749 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2752 if Dynamic_Scope = Standard_Standard then
2755 elsif Dynamic_Scope = Empty then
2758 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2759 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2761 elsif Ekind (Dynamic_Scope) = E_Block
2762 or else Ekind (Dynamic_Scope) = E_Return_Statement
2764 return Enclosing_Subprogram (Dynamic_Scope);
2766 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2767 return Get_Task_Body_Procedure (Dynamic_Scope);
2769 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2770 and then Present (Full_View (Dynamic_Scope))
2771 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2773 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2775 -- No body is generated if the protected operation is eliminated
2777 elsif Convention (Dynamic_Scope) = Convention_Protected
2778 and then not Is_Eliminated (Dynamic_Scope)
2779 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2781 return Protected_Body_Subprogram (Dynamic_Scope);
2784 return Dynamic_Scope;
2786 end Enclosing_Subprogram;
2788 ------------------------
2789 -- Ensure_Freeze_Node --
2790 ------------------------
2792 procedure Ensure_Freeze_Node (E : Entity_Id) is
2796 if No (Freeze_Node (E)) then
2797 FN := Make_Freeze_Entity (Sloc (E));
2798 Set_Has_Delayed_Freeze (E);
2799 Set_Freeze_Node (E, FN);
2800 Set_Access_Types_To_Process (FN, No_Elist);
2801 Set_TSS_Elist (FN, No_Elist);
2804 end Ensure_Freeze_Node;
2810 procedure Enter_Name (Def_Id : Entity_Id) is
2811 C : constant Entity_Id := Current_Entity (Def_Id);
2812 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2813 S : constant Entity_Id := Current_Scope;
2816 Generate_Definition (Def_Id);
2818 -- Add new name to current scope declarations. Check for duplicate
2819 -- declaration, which may or may not be a genuine error.
2823 -- Case of previous entity entered because of a missing declaration
2824 -- or else a bad subtype indication. Best is to use the new entity,
2825 -- and make the previous one invisible.
2827 if Etype (E) = Any_Type then
2828 Set_Is_Immediately_Visible (E, False);
2830 -- Case of renaming declaration constructed for package instances.
2831 -- if there is an explicit declaration with the same identifier,
2832 -- the renaming is not immediately visible any longer, but remains
2833 -- visible through selected component notation.
2835 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2836 and then not Comes_From_Source (E)
2838 Set_Is_Immediately_Visible (E, False);
2840 -- The new entity may be the package renaming, which has the same
2841 -- same name as a generic formal which has been seen already.
2843 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2844 and then not Comes_From_Source (Def_Id)
2846 Set_Is_Immediately_Visible (E, False);
2848 -- For a fat pointer corresponding to a remote access to subprogram,
2849 -- we use the same identifier as the RAS type, so that the proper
2850 -- name appears in the stub. This type is only retrieved through
2851 -- the RAS type and never by visibility, and is not added to the
2852 -- visibility list (see below).
2854 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2855 and then Present (Corresponding_Remote_Type (Def_Id))
2859 -- A controller component for a type extension overrides the
2860 -- inherited component.
2862 elsif Chars (E) = Name_uController then
2865 -- Case of an implicit operation or derived literal. The new entity
2866 -- hides the implicit one, which is removed from all visibility,
2867 -- i.e. the entity list of its scope, and homonym chain of its name.
2869 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2870 or else Is_Internal (E)
2874 Prev_Vis : Entity_Id;
2875 Decl : constant Node_Id := Parent (E);
2878 -- If E is an implicit declaration, it cannot be the first
2879 -- entity in the scope.
2881 Prev := First_Entity (Current_Scope);
2882 while Present (Prev)
2883 and then Next_Entity (Prev) /= E
2890 -- If E is not on the entity chain of the current scope,
2891 -- it is an implicit declaration in the generic formal
2892 -- part of a generic subprogram. When analyzing the body,
2893 -- the generic formals are visible but not on the entity
2894 -- chain of the subprogram. The new entity will become
2895 -- the visible one in the body.
2898 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2902 Set_Next_Entity (Prev, Next_Entity (E));
2904 if No (Next_Entity (Prev)) then
2905 Set_Last_Entity (Current_Scope, Prev);
2908 if E = Current_Entity (E) then
2912 Prev_Vis := Current_Entity (E);
2913 while Homonym (Prev_Vis) /= E loop
2914 Prev_Vis := Homonym (Prev_Vis);
2918 if Present (Prev_Vis) then
2920 -- Skip E in the visibility chain
2922 Set_Homonym (Prev_Vis, Homonym (E));
2925 Set_Name_Entity_Id (Chars (E), Homonym (E));
2930 -- This section of code could use a comment ???
2932 elsif Present (Etype (E))
2933 and then Is_Concurrent_Type (Etype (E))
2938 -- If the homograph is a protected component renaming, it should not
2939 -- be hiding the current entity. Such renamings are treated as weak
2942 elsif Is_Prival (E) then
2943 Set_Is_Immediately_Visible (E, False);
2945 -- In this case the current entity is a protected component renaming.
2946 -- Perform minimal decoration by setting the scope and return since
2947 -- the prival should not be hiding other visible entities.
2949 elsif Is_Prival (Def_Id) then
2950 Set_Scope (Def_Id, Current_Scope);
2953 -- Analogous to privals, the discriminal generated for an entry
2954 -- index parameter acts as a weak declaration. Perform minimal
2955 -- decoration to avoid bogus errors.
2957 elsif Is_Discriminal (Def_Id)
2958 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2960 Set_Scope (Def_Id, Current_Scope);
2963 -- In the body or private part of an instance, a type extension
2964 -- may introduce a component with the same name as that of an
2965 -- actual. The legality rule is not enforced, but the semantics
2966 -- of the full type with two components of the same name are not
2967 -- clear at this point ???
2969 elsif In_Instance_Not_Visible then
2972 -- When compiling a package body, some child units may have become
2973 -- visible. They cannot conflict with local entities that hide them.
2975 elsif Is_Child_Unit (E)
2976 and then In_Open_Scopes (Scope (E))
2977 and then not Is_Immediately_Visible (E)
2981 -- Conversely, with front-end inlining we may compile the parent
2982 -- body first, and a child unit subsequently. The context is now
2983 -- the parent spec, and body entities are not visible.
2985 elsif Is_Child_Unit (Def_Id)
2986 and then Is_Package_Body_Entity (E)
2987 and then not In_Package_Body (Current_Scope)
2991 -- Case of genuine duplicate declaration
2994 Error_Msg_Sloc := Sloc (E);
2996 -- If the previous declaration is an incomplete type declaration
2997 -- this may be an attempt to complete it with a private type.
2998 -- The following avoids confusing cascaded errors.
3000 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3001 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3004 ("incomplete type cannot be completed with a private " &
3005 "declaration", Parent (Def_Id));
3006 Set_Is_Immediately_Visible (E, False);
3007 Set_Full_View (E, Def_Id);
3009 -- An inherited component of a record conflicts with a new
3010 -- discriminant. The discriminant is inserted first in the scope,
3011 -- but the error should be posted on it, not on the component.
3013 elsif Ekind (E) = E_Discriminant
3014 and then Present (Scope (Def_Id))
3015 and then Scope (Def_Id) /= Current_Scope
3017 Error_Msg_Sloc := Sloc (Def_Id);
3018 Error_Msg_N ("& conflicts with declaration#", E);
3021 -- If the name of the unit appears in its own context clause,
3022 -- a dummy package with the name has already been created, and
3023 -- the error emitted. Try to continue quietly.
3025 elsif Error_Posted (E)
3026 and then Sloc (E) = No_Location
3027 and then Nkind (Parent (E)) = N_Package_Specification
3028 and then Current_Scope = Standard_Standard
3030 Set_Scope (Def_Id, Current_Scope);
3034 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3036 -- Avoid cascaded messages with duplicate components in
3039 if Ekind_In (E, E_Component, E_Discriminant) then
3044 if Nkind (Parent (Parent (Def_Id))) =
3045 N_Generic_Subprogram_Declaration
3047 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3049 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3052 -- If entity is in standard, then we are in trouble, because
3053 -- it means that we have a library package with a duplicated
3054 -- name. That's hard to recover from, so abort!
3056 if S = Standard_Standard then
3057 raise Unrecoverable_Error;
3059 -- Otherwise we continue with the declaration. Having two
3060 -- identical declarations should not cause us too much trouble!
3068 -- If we fall through, declaration is OK , or OK enough to continue
3070 -- If Def_Id is a discriminant or a record component we are in the
3071 -- midst of inheriting components in a derived record definition.
3072 -- Preserve their Ekind and Etype.
3074 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3077 -- If a type is already set, leave it alone (happens whey a type
3078 -- declaration is reanalyzed following a call to the optimizer)
3080 elsif Present (Etype (Def_Id)) then
3083 -- Otherwise, the kind E_Void insures that premature uses of the entity
3084 -- will be detected. Any_Type insures that no cascaded errors will occur
3087 Set_Ekind (Def_Id, E_Void);
3088 Set_Etype (Def_Id, Any_Type);
3091 -- Inherited discriminants and components in derived record types are
3092 -- immediately visible. Itypes are not.
3094 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3095 or else (No (Corresponding_Remote_Type (Def_Id))
3096 and then not Is_Itype (Def_Id))
3098 Set_Is_Immediately_Visible (Def_Id);
3099 Set_Current_Entity (Def_Id);
3102 Set_Homonym (Def_Id, C);
3103 Append_Entity (Def_Id, S);
3104 Set_Public_Status (Def_Id);
3106 -- Warn if new entity hides an old one
3108 if Warn_On_Hiding and then Present (C)
3110 -- Don't warn for record components since they always have a well
3111 -- defined scope which does not confuse other uses. Note that in
3112 -- some cases, Ekind has not been set yet.
3114 and then Ekind (C) /= E_Component
3115 and then Ekind (C) /= E_Discriminant
3116 and then Nkind (Parent (C)) /= N_Component_Declaration
3117 and then Ekind (Def_Id) /= E_Component
3118 and then Ekind (Def_Id) /= E_Discriminant
3119 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3121 -- Don't warn for one character variables. It is too common to use
3122 -- such variables as locals and will just cause too many false hits.
3124 and then Length_Of_Name (Chars (C)) /= 1
3126 -- Don't warn for non-source entities
3128 and then Comes_From_Source (C)
3129 and then Comes_From_Source (Def_Id)
3131 -- Don't warn unless entity in question is in extended main source
3133 and then In_Extended_Main_Source_Unit (Def_Id)
3135 -- Finally, the hidden entity must be either immediately visible
3136 -- or use visible (from a used package)
3139 (Is_Immediately_Visible (C)
3141 Is_Potentially_Use_Visible (C))
3143 Error_Msg_Sloc := Sloc (C);
3144 Error_Msg_N ("declaration hides &#?", Def_Id);
3148 --------------------------
3149 -- Explain_Limited_Type --
3150 --------------------------
3152 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3156 -- For array, component type must be limited
3158 if Is_Array_Type (T) then
3159 Error_Msg_Node_2 := T;
3161 ("\component type& of type& is limited", N, Component_Type (T));
3162 Explain_Limited_Type (Component_Type (T), N);
3164 elsif Is_Record_Type (T) then
3166 -- No need for extra messages if explicit limited record
3168 if Is_Limited_Record (Base_Type (T)) then
3172 -- Otherwise find a limited component. Check only components that
3173 -- come from source, or inherited components that appear in the
3174 -- source of the ancestor.
3176 C := First_Component (T);
3177 while Present (C) loop
3178 if Is_Limited_Type (Etype (C))
3180 (Comes_From_Source (C)
3182 (Present (Original_Record_Component (C))
3184 Comes_From_Source (Original_Record_Component (C))))
3186 Error_Msg_Node_2 := T;
3187 Error_Msg_NE ("\component& of type& has limited type", N, C);
3188 Explain_Limited_Type (Etype (C), N);
3195 -- The type may be declared explicitly limited, even if no component
3196 -- of it is limited, in which case we fall out of the loop.
3199 end Explain_Limited_Type;
3205 procedure Find_Actual
3207 Formal : out Entity_Id;
3210 Parnt : constant Node_Id := Parent (N);
3214 if (Nkind (Parnt) = N_Indexed_Component
3216 Nkind (Parnt) = N_Selected_Component)
3217 and then N = Prefix (Parnt)
3219 Find_Actual (Parnt, Formal, Call);
3222 elsif Nkind (Parnt) = N_Parameter_Association
3223 and then N = Explicit_Actual_Parameter (Parnt)
3225 Call := Parent (Parnt);
3227 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3236 -- If we have a call to a subprogram look for the parameter. Note that
3237 -- we exclude overloaded calls, since we don't know enough to be sure
3238 -- of giving the right answer in this case.
3240 if Is_Entity_Name (Name (Call))
3241 and then Present (Entity (Name (Call)))
3242 and then Is_Overloadable (Entity (Name (Call)))
3243 and then not Is_Overloaded (Name (Call))
3245 -- Fall here if we are definitely a parameter
3247 Actual := First_Actual (Call);
3248 Formal := First_Formal (Entity (Name (Call)));
3249 while Present (Formal) and then Present (Actual) loop
3253 Actual := Next_Actual (Actual);
3254 Formal := Next_Formal (Formal);
3259 -- Fall through here if we did not find matching actual
3265 ---------------------------
3266 -- Find_Body_Discriminal --
3267 ---------------------------
3269 function Find_Body_Discriminal
3270 (Spec_Discriminant : Entity_Id) return Entity_Id
3272 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3274 Tsk : constant Entity_Id :=
3275 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3279 -- Find discriminant of original concurrent type, and use its current
3280 -- discriminal, which is the renaming within the task/protected body.
3282 Disc := First_Discriminant (Tsk);
3283 while Present (Disc) loop
3284 if Chars (Disc) = Chars (Spec_Discriminant) then
3285 return Discriminal (Disc);
3288 Next_Discriminant (Disc);
3291 -- That loop should always succeed in finding a matching entry and
3292 -- returning. Fatal error if not.
3294 raise Program_Error;
3295 end Find_Body_Discriminal;
3297 -------------------------------------
3298 -- Find_Corresponding_Discriminant --
3299 -------------------------------------
3301 function Find_Corresponding_Discriminant
3303 Typ : Entity_Id) return Entity_Id
3305 Par_Disc : Entity_Id;
3306 Old_Disc : Entity_Id;
3307 New_Disc : Entity_Id;
3310 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3312 -- The original type may currently be private, and the discriminant
3313 -- only appear on its full view.
3315 if Is_Private_Type (Scope (Par_Disc))
3316 and then not Has_Discriminants (Scope (Par_Disc))
3317 and then Present (Full_View (Scope (Par_Disc)))
3319 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3321 Old_Disc := First_Discriminant (Scope (Par_Disc));
3324 if Is_Class_Wide_Type (Typ) then
3325 New_Disc := First_Discriminant (Root_Type (Typ));
3327 New_Disc := First_Discriminant (Typ);
3330 while Present (Old_Disc) and then Present (New_Disc) loop
3331 if Old_Disc = Par_Disc then
3334 Next_Discriminant (Old_Disc);
3335 Next_Discriminant (New_Disc);
3339 -- Should always find it
3341 raise Program_Error;
3342 end Find_Corresponding_Discriminant;
3344 --------------------------
3345 -- Find_Overlaid_Entity --
3346 --------------------------
3348 procedure Find_Overlaid_Entity
3350 Ent : out Entity_Id;
3356 -- We are looking for one of the two following forms:
3358 -- for X'Address use Y'Address
3362 -- Const : constant Address := expr;
3364 -- for X'Address use Const;
3366 -- In the second case, the expr is either Y'Address, or recursively a
3367 -- constant that eventually references Y'Address.
3372 if Nkind (N) = N_Attribute_Definition_Clause
3373 and then Chars (N) = Name_Address
3375 Expr := Expression (N);
3377 -- This loop checks the form of the expression for Y'Address,
3378 -- using recursion to deal with intermediate constants.
3381 -- Check for Y'Address
3383 if Nkind (Expr) = N_Attribute_Reference
3384 and then Attribute_Name (Expr) = Name_Address
3386 Expr := Prefix (Expr);
3389 -- Check for Const where Const is a constant entity
3391 elsif Is_Entity_Name (Expr)
3392 and then Ekind (Entity (Expr)) = E_Constant
3394 Expr := Constant_Value (Entity (Expr));
3396 -- Anything else does not need checking
3403 -- This loop checks the form of the prefix for an entity,
3404 -- using recursion to deal with intermediate components.
3407 -- Check for Y where Y is an entity
3409 if Is_Entity_Name (Expr) then
3410 Ent := Entity (Expr);
3413 -- Check for components
3416 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3418 Expr := Prefix (Expr);
3421 -- Anything else does not need checking
3428 end Find_Overlaid_Entity;
3430 -------------------------
3431 -- Find_Parameter_Type --
3432 -------------------------
3434 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3436 if Nkind (Param) /= N_Parameter_Specification then
3439 -- For an access parameter, obtain the type from the formal entity
3440 -- itself, because access to subprogram nodes do not carry a type.
3441 -- Shouldn't we always use the formal entity ???
3443 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3444 return Etype (Defining_Identifier (Param));
3447 return Etype (Parameter_Type (Param));
3449 end Find_Parameter_Type;
3451 -----------------------------
3452 -- Find_Static_Alternative --
3453 -----------------------------
3455 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3456 Expr : constant Node_Id := Expression (N);
3457 Val : constant Uint := Expr_Value (Expr);
3462 Alt := First (Alternatives (N));
3465 if Nkind (Alt) /= N_Pragma then
3466 Choice := First (Discrete_Choices (Alt));
3467 while Present (Choice) loop
3469 -- Others choice, always matches
3471 if Nkind (Choice) = N_Others_Choice then
3474 -- Range, check if value is in the range
3476 elsif Nkind (Choice) = N_Range then
3478 Val >= Expr_Value (Low_Bound (Choice))
3480 Val <= Expr_Value (High_Bound (Choice));
3482 -- Choice is a subtype name. Note that we know it must
3483 -- be a static subtype, since otherwise it would have
3484 -- been diagnosed as illegal.
3486 elsif Is_Entity_Name (Choice)
3487 and then Is_Type (Entity (Choice))
3489 exit Search when Is_In_Range (Expr, Etype (Choice),
3490 Assume_Valid => False);
3492 -- Choice is a subtype indication
3494 elsif Nkind (Choice) = N_Subtype_Indication then
3496 C : constant Node_Id := Constraint (Choice);
3497 R : constant Node_Id := Range_Expression (C);
3501 Val >= Expr_Value (Low_Bound (R))
3503 Val <= Expr_Value (High_Bound (R));
3506 -- Choice is a simple expression
3509 exit Search when Val = Expr_Value (Choice);
3517 pragma Assert (Present (Alt));
3520 -- The above loop *must* terminate by finding a match, since
3521 -- we know the case statement is valid, and the value of the
3522 -- expression is known at compile time. When we fall out of
3523 -- the loop, Alt points to the alternative that we know will
3524 -- be selected at run time.
3527 end Find_Static_Alternative;
3533 function First_Actual (Node : Node_Id) return Node_Id is
3537 if No (Parameter_Associations (Node)) then
3541 N := First (Parameter_Associations (Node));
3543 if Nkind (N) = N_Parameter_Association then
3544 return First_Named_Actual (Node);
3550 -----------------------
3551 -- Gather_Components --
3552 -----------------------
3554 procedure Gather_Components
3556 Comp_List : Node_Id;
3557 Governed_By : List_Id;
3559 Report_Errors : out Boolean)
3563 Discrete_Choice : Node_Id;
3564 Comp_Item : Node_Id;
3566 Discrim : Entity_Id;
3567 Discrim_Name : Node_Id;
3568 Discrim_Value : Node_Id;
3571 Report_Errors := False;
3573 if No (Comp_List) or else Null_Present (Comp_List) then
3576 elsif Present (Component_Items (Comp_List)) then
3577 Comp_Item := First (Component_Items (Comp_List));
3583 while Present (Comp_Item) loop
3585 -- Skip the tag of a tagged record, the interface tags, as well
3586 -- as all items that are not user components (anonymous types,
3587 -- rep clauses, Parent field, controller field).
3589 if Nkind (Comp_Item) = N_Component_Declaration then
3591 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3593 if not Is_Tag (Comp)
3594 and then Chars (Comp) /= Name_uParent
3595 and then Chars (Comp) /= Name_uController
3597 Append_Elmt (Comp, Into);
3605 if No (Variant_Part (Comp_List)) then
3608 Discrim_Name := Name (Variant_Part (Comp_List));
3609 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3612 -- Look for the discriminant that governs this variant part.
3613 -- The discriminant *must* be in the Governed_By List
3615 Assoc := First (Governed_By);
3616 Find_Constraint : loop
3617 Discrim := First (Choices (Assoc));
3618 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3619 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3621 Chars (Corresponding_Discriminant (Entity (Discrim)))
3622 = Chars (Discrim_Name))
3623 or else Chars (Original_Record_Component (Entity (Discrim)))
3624 = Chars (Discrim_Name);
3626 if No (Next (Assoc)) then
3627 if not Is_Constrained (Typ)
3628 and then Is_Derived_Type (Typ)
3629 and then Present (Stored_Constraint (Typ))
3631 -- If the type is a tagged type with inherited discriminants,
3632 -- use the stored constraint on the parent in order to find
3633 -- the values of discriminants that are otherwise hidden by an
3634 -- explicit constraint. Renamed discriminants are handled in
3637 -- If several parent discriminants are renamed by a single
3638 -- discriminant of the derived type, the call to obtain the
3639 -- Corresponding_Discriminant field only retrieves the last
3640 -- of them. We recover the constraint on the others from the
3641 -- Stored_Constraint as well.
3648 D := First_Discriminant (Etype (Typ));
3649 C := First_Elmt (Stored_Constraint (Typ));
3650 while Present (D) and then Present (C) loop
3651 if Chars (Discrim_Name) = Chars (D) then
3652 if Is_Entity_Name (Node (C))
3653 and then Entity (Node (C)) = Entity (Discrim)
3655 -- D is renamed by Discrim, whose value is given in
3662 Make_Component_Association (Sloc (Typ),
3664 (New_Occurrence_Of (D, Sloc (Typ))),
3665 Duplicate_Subexpr_No_Checks (Node (C)));
3667 exit Find_Constraint;
3670 Next_Discriminant (D);
3677 if No (Next (Assoc)) then
3678 Error_Msg_NE (" missing value for discriminant&",
3679 First (Governed_By), Discrim_Name);
3680 Report_Errors := True;
3685 end loop Find_Constraint;
3687 Discrim_Value := Expression (Assoc);
3689 if not Is_OK_Static_Expression (Discrim_Value) then
3691 ("value for discriminant & must be static!",
3692 Discrim_Value, Discrim);
3693 Why_Not_Static (Discrim_Value);
3694 Report_Errors := True;
3698 Search_For_Discriminant_Value : declare
3704 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3707 Find_Discrete_Value : while Present (Variant) loop
3708 Discrete_Choice := First (Discrete_Choices (Variant));
3709 while Present (Discrete_Choice) loop
3711 exit Find_Discrete_Value when
3712 Nkind (Discrete_Choice) = N_Others_Choice;
3714 Get_Index_Bounds (Discrete_Choice, Low, High);
3716 UI_Low := Expr_Value (Low);
3717 UI_High := Expr_Value (High);
3719 exit Find_Discrete_Value when
3720 UI_Low <= UI_Discrim_Value
3722 UI_High >= UI_Discrim_Value;
3724 Next (Discrete_Choice);
3727 Next_Non_Pragma (Variant);
3728 end loop Find_Discrete_Value;
3729 end Search_For_Discriminant_Value;
3731 if No (Variant) then
3733 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3734 Report_Errors := True;
3738 -- If we have found the corresponding choice, recursively add its
3739 -- components to the Into list.
3741 Gather_Components (Empty,
3742 Component_List (Variant), Governed_By, Into, Report_Errors);
3743 end Gather_Components;
3745 ------------------------
3746 -- Get_Actual_Subtype --
3747 ------------------------
3749 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3750 Typ : constant Entity_Id := Etype (N);
3751 Utyp : Entity_Id := Underlying_Type (Typ);
3760 -- If what we have is an identifier that references a subprogram
3761 -- formal, or a variable or constant object, then we get the actual
3762 -- subtype from the referenced entity if one has been built.
3764 if Nkind (N) = N_Identifier
3766 (Is_Formal (Entity (N))
3767 or else Ekind (Entity (N)) = E_Constant
3768 or else Ekind (Entity (N)) = E_Variable)
3769 and then Present (Actual_Subtype (Entity (N)))
3771 return Actual_Subtype (Entity (N));
3773 -- Actual subtype of unchecked union is always itself. We never need
3774 -- the "real" actual subtype. If we did, we couldn't get it anyway
3775 -- because the discriminant is not available. The restrictions on
3776 -- Unchecked_Union are designed to make sure that this is OK.
3778 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3781 -- Here for the unconstrained case, we must find actual subtype
3782 -- No actual subtype is available, so we must build it on the fly.
3784 -- Checking the type, not the underlying type, for constrainedness
3785 -- seems to be necessary. Maybe all the tests should be on the type???
3787 elsif (not Is_Constrained (Typ))
3788 and then (Is_Array_Type (Utyp)
3789 or else (Is_Record_Type (Utyp)
3790 and then Has_Discriminants (Utyp)))
3791 and then not Has_Unknown_Discriminants (Utyp)
3792 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3794 -- Nothing to do if in spec expression (why not???)
3796 if In_Spec_Expression then
3799 elsif Is_Private_Type (Typ)
3800 and then not Has_Discriminants (Typ)
3802 -- If the type has no discriminants, there is no subtype to
3803 -- build, even if the underlying type is discriminated.
3807 -- Else build the actual subtype
3810 Decl := Build_Actual_Subtype (Typ, N);
3811 Atyp := Defining_Identifier (Decl);
3813 -- If Build_Actual_Subtype generated a new declaration then use it
3817 -- The actual subtype is an Itype, so analyze the declaration,
3818 -- but do not attach it to the tree, to get the type defined.
3820 Set_Parent (Decl, N);
3821 Set_Is_Itype (Atyp);
3822 Analyze (Decl, Suppress => All_Checks);
3823 Set_Associated_Node_For_Itype (Atyp, N);
3824 Set_Has_Delayed_Freeze (Atyp, False);
3826 -- We need to freeze the actual subtype immediately. This is
3827 -- needed, because otherwise this Itype will not get frozen
3828 -- at all, and it is always safe to freeze on creation because
3829 -- any associated types must be frozen at this point.
3831 Freeze_Itype (Atyp, N);
3834 -- Otherwise we did not build a declaration, so return original
3841 -- For all remaining cases, the actual subtype is the same as
3842 -- the nominal type.
3847 end Get_Actual_Subtype;
3849 -------------------------------------
3850 -- Get_Actual_Subtype_If_Available --
3851 -------------------------------------
3853 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3854 Typ : constant Entity_Id := Etype (N);
3857 -- If what we have is an identifier that references a subprogram
3858 -- formal, or a variable or constant object, then we get the actual
3859 -- subtype from the referenced entity if one has been built.
3861 if Nkind (N) = N_Identifier
3863 (Is_Formal (Entity (N))
3864 or else Ekind (Entity (N)) = E_Constant
3865 or else Ekind (Entity (N)) = E_Variable)
3866 and then Present (Actual_Subtype (Entity (N)))
3868 return Actual_Subtype (Entity (N));
3870 -- Otherwise the Etype of N is returned unchanged
3875 end Get_Actual_Subtype_If_Available;
3877 -------------------------------
3878 -- Get_Default_External_Name --
3879 -------------------------------
3881 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3883 Get_Decoded_Name_String (Chars (E));
3885 if Opt.External_Name_Imp_Casing = Uppercase then
3886 Set_Casing (All_Upper_Case);
3888 Set_Casing (All_Lower_Case);
3892 Make_String_Literal (Sloc (E),
3893 Strval => String_From_Name_Buffer);
3894 end Get_Default_External_Name;
3896 ---------------------------
3897 -- Get_Enum_Lit_From_Pos --
3898 ---------------------------
3900 function Get_Enum_Lit_From_Pos
3903 Loc : Source_Ptr) return Node_Id
3908 -- In the case where the literal is of type Character, Wide_Character
3909 -- or Wide_Wide_Character or of a type derived from them, there needs
3910 -- to be some special handling since there is no explicit chain of
3911 -- literals to search. Instead, an N_Character_Literal node is created
3912 -- with the appropriate Char_Code and Chars fields.
3914 if Is_Standard_Character_Type (T) then
3915 Set_Character_Literal_Name (UI_To_CC (Pos));
3917 Make_Character_Literal (Loc,
3919 Char_Literal_Value => Pos);
3921 -- For all other cases, we have a complete table of literals, and
3922 -- we simply iterate through the chain of literal until the one
3923 -- with the desired position value is found.
3927 Lit := First_Literal (Base_Type (T));
3928 for J in 1 .. UI_To_Int (Pos) loop
3932 return New_Occurrence_Of (Lit, Loc);
3934 end Get_Enum_Lit_From_Pos;
3936 ------------------------
3937 -- Get_Generic_Entity --
3938 ------------------------
3940 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3941 Ent : constant Entity_Id := Entity (Name (N));
3943 if Present (Renamed_Object (Ent)) then
3944 return Renamed_Object (Ent);
3948 end Get_Generic_Entity;
3950 ----------------------
3951 -- Get_Index_Bounds --
3952 ----------------------
3954 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3955 Kind : constant Node_Kind := Nkind (N);
3959 if Kind = N_Range then
3961 H := High_Bound (N);
3963 elsif Kind = N_Subtype_Indication then
3964 R := Range_Expression (Constraint (N));
3972 L := Low_Bound (Range_Expression (Constraint (N)));
3973 H := High_Bound (Range_Expression (Constraint (N)));
3976 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3977 if Error_Posted (Scalar_Range (Entity (N))) then
3981 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3982 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3985 L := Low_Bound (Scalar_Range (Entity (N)));
3986 H := High_Bound (Scalar_Range (Entity (N)));
3990 -- N is an expression, indicating a range with one value
3995 end Get_Index_Bounds;
3997 ----------------------------------
3998 -- Get_Library_Unit_Name_string --
3999 ----------------------------------
4001 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4002 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4005 Get_Unit_Name_String (Unit_Name_Id);
4007 -- Remove seven last character (" (spec)" or " (body)")
4009 Name_Len := Name_Len - 7;
4010 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4011 end Get_Library_Unit_Name_String;
4013 ------------------------
4014 -- Get_Name_Entity_Id --
4015 ------------------------
4017 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4019 return Entity_Id (Get_Name_Table_Info (Id));
4020 end Get_Name_Entity_Id;
4026 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4028 return Get_Pragma_Id (Pragma_Name (N));
4031 ---------------------------
4032 -- Get_Referenced_Object --
4033 ---------------------------
4035 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4040 while Is_Entity_Name (R)
4041 and then Present (Renamed_Object (Entity (R)))
4043 R := Renamed_Object (Entity (R));
4047 end Get_Referenced_Object;
4049 ------------------------
4050 -- Get_Renamed_Entity --
4051 ------------------------
4053 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4058 while Present (Renamed_Entity (R)) loop
4059 R := Renamed_Entity (R);
4063 end Get_Renamed_Entity;
4065 -------------------------
4066 -- Get_Subprogram_Body --
4067 -------------------------
4069 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4073 Decl := Unit_Declaration_Node (E);
4075 if Nkind (Decl) = N_Subprogram_Body then
4078 -- The below comment is bad, because it is possible for
4079 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4081 else -- Nkind (Decl) = N_Subprogram_Declaration
4083 if Present (Corresponding_Body (Decl)) then
4084 return Unit_Declaration_Node (Corresponding_Body (Decl));
4086 -- Imported subprogram case
4092 end Get_Subprogram_Body;
4094 ---------------------------
4095 -- Get_Subprogram_Entity --
4096 ---------------------------
4098 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4103 if Nkind (Nod) = N_Accept_Statement then
4104 Nam := Entry_Direct_Name (Nod);
4106 -- For an entry call, the prefix of the call is a selected component.
4107 -- Need additional code for internal calls ???
4109 elsif Nkind (Nod) = N_Entry_Call_Statement then
4110 if Nkind (Name (Nod)) = N_Selected_Component then
4111 Nam := Entity (Selector_Name (Name (Nod)));
4120 if Nkind (Nam) = N_Explicit_Dereference then
4121 Proc := Etype (Prefix (Nam));
4122 elsif Is_Entity_Name (Nam) then
4123 Proc := Entity (Nam);
4128 if Is_Object (Proc) then
4129 Proc := Etype (Proc);
4132 if Ekind (Proc) = E_Access_Subprogram_Type then
4133 Proc := Directly_Designated_Type (Proc);
4136 if not Is_Subprogram (Proc)
4137 and then Ekind (Proc) /= E_Subprogram_Type
4143 end Get_Subprogram_Entity;
4145 -----------------------------
4146 -- Get_Task_Body_Procedure --
4147 -----------------------------
4149 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4151 -- Note: A task type may be the completion of a private type with
4152 -- discriminants. When performing elaboration checks on a task
4153 -- declaration, the current view of the type may be the private one,
4154 -- and the procedure that holds the body of the task is held in its
4157 -- This is an odd function, why not have Task_Body_Procedure do
4158 -- the following digging???
4160 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4161 end Get_Task_Body_Procedure;
4163 -----------------------
4164 -- Has_Access_Values --
4165 -----------------------
4167 function Has_Access_Values (T : Entity_Id) return Boolean is
4168 Typ : constant Entity_Id := Underlying_Type (T);
4171 -- Case of a private type which is not completed yet. This can only
4172 -- happen in the case of a generic format type appearing directly, or
4173 -- as a component of the type to which this function is being applied
4174 -- at the top level. Return False in this case, since we certainly do
4175 -- not know that the type contains access types.
4180 elsif Is_Access_Type (Typ) then
4183 elsif Is_Array_Type (Typ) then
4184 return Has_Access_Values (Component_Type (Typ));
4186 elsif Is_Record_Type (Typ) then
4191 -- Loop to Check components
4193 Comp := First_Component_Or_Discriminant (Typ);
4194 while Present (Comp) loop
4196 -- Check for access component, tag field does not count, even
4197 -- though it is implemented internally using an access type.
4199 if Has_Access_Values (Etype (Comp))
4200 and then Chars (Comp) /= Name_uTag
4205 Next_Component_Or_Discriminant (Comp);
4214 end Has_Access_Values;
4216 ------------------------------
4217 -- Has_Compatible_Alignment --
4218 ------------------------------
4220 function Has_Compatible_Alignment
4222 Expr : Node_Id) return Alignment_Result
4224 function Has_Compatible_Alignment_Internal
4227 Default : Alignment_Result) return Alignment_Result;
4228 -- This is the internal recursive function that actually does the work.
4229 -- There is one additional parameter, which says what the result should
4230 -- be if no alignment information is found, and there is no definite
4231 -- indication of compatible alignments. At the outer level, this is set
4232 -- to Unknown, but for internal recursive calls in the case where types
4233 -- are known to be correct, it is set to Known_Compatible.
4235 ---------------------------------------
4236 -- Has_Compatible_Alignment_Internal --
4237 ---------------------------------------
4239 function Has_Compatible_Alignment_Internal
4242 Default : Alignment_Result) return Alignment_Result
4244 Result : Alignment_Result := Known_Compatible;
4245 -- Holds the current status of the result. Note that once a value of
4246 -- Known_Incompatible is set, it is sticky and does not get changed
4247 -- to Unknown (the value in Result only gets worse as we go along,
4250 Offs : Uint := No_Uint;
4251 -- Set to a factor of the offset from the base object when Expr is a
4252 -- selected or indexed component, based on Component_Bit_Offset and
4253 -- Component_Size respectively. A negative value is used to represent
4254 -- a value which is not known at compile time.
4256 procedure Check_Prefix;
4257 -- Checks the prefix recursively in the case where the expression
4258 -- is an indexed or selected component.
4260 procedure Set_Result (R : Alignment_Result);
4261 -- If R represents a worse outcome (unknown instead of known
4262 -- compatible, or known incompatible), then set Result to R.
4268 procedure Check_Prefix is
4270 -- The subtlety here is that in doing a recursive call to check
4271 -- the prefix, we have to decide what to do in the case where we
4272 -- don't find any specific indication of an alignment problem.
4274 -- At the outer level, we normally set Unknown as the result in
4275 -- this case, since we can only set Known_Compatible if we really
4276 -- know that the alignment value is OK, but for the recursive
4277 -- call, in the case where the types match, and we have not
4278 -- specified a peculiar alignment for the object, we are only
4279 -- concerned about suspicious rep clauses, the default case does
4280 -- not affect us, since the compiler will, in the absence of such
4281 -- rep clauses, ensure that the alignment is correct.
4283 if Default = Known_Compatible
4285 (Etype (Obj) = Etype (Expr)
4286 and then (Unknown_Alignment (Obj)
4288 Alignment (Obj) = Alignment (Etype (Obj))))
4291 (Has_Compatible_Alignment_Internal
4292 (Obj, Prefix (Expr), Known_Compatible));
4294 -- In all other cases, we need a full check on the prefix
4298 (Has_Compatible_Alignment_Internal
4299 (Obj, Prefix (Expr), Unknown));
4307 procedure Set_Result (R : Alignment_Result) is
4314 -- Start of processing for Has_Compatible_Alignment_Internal
4317 -- If Expr is a selected component, we must make sure there is no
4318 -- potentially troublesome component clause, and that the record is
4321 if Nkind (Expr) = N_Selected_Component then
4323 -- Packed record always generate unknown alignment
4325 if Is_Packed (Etype (Prefix (Expr))) then
4326 Set_Result (Unknown);
4329 -- Check prefix and component offset
4332 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4334 -- If Expr is an indexed component, we must make sure there is no
4335 -- potentially troublesome Component_Size clause and that the array
4336 -- is not bit-packed.
4338 elsif Nkind (Expr) = N_Indexed_Component then
4340 Typ : constant Entity_Id := Etype (Prefix (Expr));
4341 Ind : constant Node_Id := First_Index (Typ);
4344 -- Bit packed array always generates unknown alignment
4346 if Is_Bit_Packed_Array (Typ) then
4347 Set_Result (Unknown);
4350 -- Check prefix and component offset
4353 Offs := Component_Size (Typ);
4355 -- Small optimization: compute the full offset when possible
4358 and then Offs > Uint_0
4359 and then Present (Ind)
4360 and then Nkind (Ind) = N_Range
4361 and then Compile_Time_Known_Value (Low_Bound (Ind))
4362 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4364 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4365 - Expr_Value (Low_Bound ((Ind))));
4370 -- If we have a null offset, the result is entirely determined by
4371 -- the base object and has already been computed recursively.
4373 if Offs = Uint_0 then
4376 -- Case where we know the alignment of the object
4378 elsif Known_Alignment (Obj) then
4380 ObjA : constant Uint := Alignment (Obj);
4381 ExpA : Uint := No_Uint;
4382 SizA : Uint := No_Uint;
4385 -- If alignment of Obj is 1, then we are always OK
4388 Set_Result (Known_Compatible);
4390 -- Alignment of Obj is greater than 1, so we need to check
4393 -- If we have an offset, see if it is compatible
4395 if Offs /= No_Uint and Offs > Uint_0 then
4396 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4397 Set_Result (Known_Incompatible);
4400 -- See if Expr is an object with known alignment
4402 elsif Is_Entity_Name (Expr)
4403 and then Known_Alignment (Entity (Expr))
4405 ExpA := Alignment (Entity (Expr));
4407 -- Otherwise, we can use the alignment of the type of
4408 -- Expr given that we already checked for
4409 -- discombobulating rep clauses for the cases of indexed
4410 -- and selected components above.
4412 elsif Known_Alignment (Etype (Expr)) then
4413 ExpA := Alignment (Etype (Expr));
4415 -- Otherwise the alignment is unknown
4418 Set_Result (Default);
4421 -- If we got an alignment, see if it is acceptable
4423 if ExpA /= No_Uint and then ExpA < ObjA then
4424 Set_Result (Known_Incompatible);
4427 -- If Expr is not a piece of a larger object, see if size
4428 -- is given. If so, check that it is not too small for the
4429 -- required alignment.
4431 if Offs /= No_Uint then
4434 -- See if Expr is an object with known size
4436 elsif Is_Entity_Name (Expr)
4437 and then Known_Static_Esize (Entity (Expr))
4439 SizA := Esize (Entity (Expr));
4441 -- Otherwise, we check the object size of the Expr type
4443 elsif Known_Static_Esize (Etype (Expr)) then
4444 SizA := Esize (Etype (Expr));
4447 -- If we got a size, see if it is a multiple of the Obj
4448 -- alignment, if not, then the alignment cannot be
4449 -- acceptable, since the size is always a multiple of the
4452 if SizA /= No_Uint then
4453 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4454 Set_Result (Known_Incompatible);
4460 -- If we do not know required alignment, any non-zero offset is a
4461 -- potential problem (but certainly may be OK, so result is unknown).
4463 elsif Offs /= No_Uint then
4464 Set_Result (Unknown);
4466 -- If we can't find the result by direct comparison of alignment
4467 -- values, then there is still one case that we can determine known
4468 -- result, and that is when we can determine that the types are the
4469 -- same, and no alignments are specified. Then we known that the
4470 -- alignments are compatible, even if we don't know the alignment
4471 -- value in the front end.
4473 elsif Etype (Obj) = Etype (Expr) then
4475 -- Types are the same, but we have to check for possible size
4476 -- and alignments on the Expr object that may make the alignment
4477 -- different, even though the types are the same.
4479 if Is_Entity_Name (Expr) then
4481 -- First check alignment of the Expr object. Any alignment less
4482 -- than Maximum_Alignment is worrisome since this is the case
4483 -- where we do not know the alignment of Obj.
4485 if Known_Alignment (Entity (Expr))
4487 UI_To_Int (Alignment (Entity (Expr))) <
4488 Ttypes.Maximum_Alignment
4490 Set_Result (Unknown);
4492 -- Now check size of Expr object. Any size that is not an
4493 -- even multiple of Maximum_Alignment is also worrisome
4494 -- since it may cause the alignment of the object to be less
4495 -- than the alignment of the type.
4497 elsif Known_Static_Esize (Entity (Expr))
4499 (UI_To_Int (Esize (Entity (Expr))) mod
4500 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4503 Set_Result (Unknown);
4505 -- Otherwise same type is decisive
4508 Set_Result (Known_Compatible);
4512 -- Another case to deal with is when there is an explicit size or
4513 -- alignment clause when the types are not the same. If so, then the
4514 -- result is Unknown. We don't need to do this test if the Default is
4515 -- Unknown, since that result will be set in any case.
4517 elsif Default /= Unknown
4518 and then (Has_Size_Clause (Etype (Expr))
4520 Has_Alignment_Clause (Etype (Expr)))
4522 Set_Result (Unknown);
4524 -- If no indication found, set default
4527 Set_Result (Default);
4530 -- Return worst result found
4533 end Has_Compatible_Alignment_Internal;
4535 -- Start of processing for Has_Compatible_Alignment
4538 -- If Obj has no specified alignment, then set alignment from the type
4539 -- alignment. Perhaps we should always do this, but for sure we should
4540 -- do it when there is an address clause since we can do more if the
4541 -- alignment is known.
4543 if Unknown_Alignment (Obj) then
4544 Set_Alignment (Obj, Alignment (Etype (Obj)));
4547 -- Now do the internal call that does all the work
4549 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4550 end Has_Compatible_Alignment;
4552 ----------------------
4553 -- Has_Declarations --
4554 ----------------------
4556 function Has_Declarations (N : Node_Id) return Boolean is
4558 return Nkind_In (Nkind (N), N_Accept_Statement,
4560 N_Compilation_Unit_Aux,
4566 N_Package_Specification);
4567 end Has_Declarations;
4569 -------------------------------------------
4570 -- Has_Discriminant_Dependent_Constraint --
4571 -------------------------------------------
4573 function Has_Discriminant_Dependent_Constraint
4574 (Comp : Entity_Id) return Boolean
4576 Comp_Decl : constant Node_Id := Parent (Comp);
4577 Subt_Indic : constant Node_Id :=
4578 Subtype_Indication (Component_Definition (Comp_Decl));
4583 if Nkind (Subt_Indic) = N_Subtype_Indication then
4584 Constr := Constraint (Subt_Indic);
4586 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4587 Assn := First (Constraints (Constr));
4588 while Present (Assn) loop
4589 case Nkind (Assn) is
4590 when N_Subtype_Indication |
4594 if Depends_On_Discriminant (Assn) then
4598 when N_Discriminant_Association =>
4599 if Depends_On_Discriminant (Expression (Assn)) then
4614 end Has_Discriminant_Dependent_Constraint;
4616 --------------------
4617 -- Has_Infinities --
4618 --------------------
4620 function Has_Infinities (E : Entity_Id) return Boolean is
4623 Is_Floating_Point_Type (E)
4624 and then Nkind (Scalar_Range (E)) = N_Range
4625 and then Includes_Infinities (Scalar_Range (E));
4628 --------------------
4629 -- Has_Interfaces --
4630 --------------------
4632 function Has_Interfaces
4634 Use_Full_View : Boolean := True) return Boolean
4636 Typ : Entity_Id := Base_Type (T);
4639 -- Handle concurrent types
4641 if Is_Concurrent_Type (Typ) then
4642 Typ := Corresponding_Record_Type (Typ);
4645 if not Present (Typ)
4646 or else not Is_Record_Type (Typ)
4647 or else not Is_Tagged_Type (Typ)
4652 -- Handle private types
4655 and then Present (Full_View (Typ))
4657 Typ := Full_View (Typ);
4660 -- Handle concurrent record types
4662 if Is_Concurrent_Record_Type (Typ)
4663 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4669 if Is_Interface (Typ)
4671 (Is_Record_Type (Typ)
4672 and then Present (Interfaces (Typ))
4673 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4678 exit when Etype (Typ) = Typ
4680 -- Handle private types
4682 or else (Present (Full_View (Etype (Typ)))
4683 and then Full_View (Etype (Typ)) = Typ)
4685 -- Protect the frontend against wrong source with cyclic
4688 or else Etype (Typ) = T;
4690 -- Climb to the ancestor type handling private types
4692 if Present (Full_View (Etype (Typ))) then
4693 Typ := Full_View (Etype (Typ));
4702 ------------------------
4703 -- Has_Null_Exclusion --
4704 ------------------------
4706 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4709 when N_Access_Definition |
4710 N_Access_Function_Definition |
4711 N_Access_Procedure_Definition |
4712 N_Access_To_Object_Definition |
4714 N_Derived_Type_Definition |
4715 N_Function_Specification |
4716 N_Subtype_Declaration =>
4717 return Null_Exclusion_Present (N);
4719 when N_Component_Definition |
4720 N_Formal_Object_Declaration |
4721 N_Object_Renaming_Declaration =>
4722 if Present (Subtype_Mark (N)) then
4723 return Null_Exclusion_Present (N);
4724 else pragma Assert (Present (Access_Definition (N)));
4725 return Null_Exclusion_Present (Access_Definition (N));
4728 when N_Discriminant_Specification =>
4729 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4730 return Null_Exclusion_Present (Discriminant_Type (N));
4732 return Null_Exclusion_Present (N);
4735 when N_Object_Declaration =>
4736 if Nkind (Object_Definition (N)) = N_Access_Definition then
4737 return Null_Exclusion_Present (Object_Definition (N));
4739 return Null_Exclusion_Present (N);
4742 when N_Parameter_Specification =>
4743 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4744 return Null_Exclusion_Present (Parameter_Type (N));
4746 return Null_Exclusion_Present (N);
4753 end Has_Null_Exclusion;
4755 ------------------------
4756 -- Has_Null_Extension --
4757 ------------------------
4759 function Has_Null_Extension (T : Entity_Id) return Boolean is
4760 B : constant Entity_Id := Base_Type (T);
4765 if Nkind (Parent (B)) = N_Full_Type_Declaration
4766 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4768 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4770 if Present (Ext) then
4771 if Null_Present (Ext) then
4774 Comps := Component_List (Ext);
4776 -- The null component list is rewritten during analysis to
4777 -- include the parent component. Any other component indicates
4778 -- that the extension was not originally null.
4780 return Null_Present (Comps)
4781 or else No (Next (First (Component_Items (Comps))));
4790 end Has_Null_Extension;
4792 -------------------------------
4793 -- Has_Overriding_Initialize --
4794 -------------------------------
4796 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4797 BT : constant Entity_Id := Base_Type (T);
4802 if Is_Controlled (BT) then
4804 -- For derived types, check immediate ancestor, excluding
4805 -- Controlled itself.
4807 if Is_Derived_Type (BT)
4808 and then not In_Predefined_Unit (Etype (BT))
4809 and then Has_Overriding_Initialize (Etype (BT))
4813 elsif Present (Primitive_Operations (BT)) then
4814 P := First_Elmt (Primitive_Operations (BT));
4815 while Present (P) loop
4816 if Chars (Node (P)) = Name_Initialize
4817 and then Comes_From_Source (Node (P))
4828 elsif Has_Controlled_Component (BT) then
4829 Comp := First_Component (BT);
4830 while Present (Comp) loop
4831 if Has_Overriding_Initialize (Etype (Comp)) then
4835 Next_Component (Comp);
4843 end Has_Overriding_Initialize;
4845 --------------------------------------
4846 -- Has_Preelaborable_Initialization --
4847 --------------------------------------
4849 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4852 procedure Check_Components (E : Entity_Id);
4853 -- Check component/discriminant chain, sets Has_PE False if a component
4854 -- or discriminant does not meet the preelaborable initialization rules.
4856 ----------------------
4857 -- Check_Components --
4858 ----------------------
4860 procedure Check_Components (E : Entity_Id) is
4864 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4865 -- Returns True if and only if the expression denoted by N does not
4866 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4868 ---------------------------------
4869 -- Is_Preelaborable_Expression --
4870 ---------------------------------
4872 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4876 Comp_Type : Entity_Id;
4877 Is_Array_Aggr : Boolean;
4880 if Is_Static_Expression (N) then
4883 elsif Nkind (N) = N_Null then
4886 -- Attributes are allowed in general, even if their prefix is a
4887 -- formal type. (It seems that certain attributes known not to be
4888 -- static might not be allowed, but there are no rules to prevent
4891 elsif Nkind (N) = N_Attribute_Reference then
4894 -- The name of a discriminant evaluated within its parent type is
4895 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4896 -- names that denote discriminals as well as discriminants to
4897 -- catch references occurring within init procs.
4899 elsif Is_Entity_Name (N)
4901 (Ekind (Entity (N)) = E_Discriminant
4903 ((Ekind (Entity (N)) = E_Constant
4904 or else Ekind (Entity (N)) = E_In_Parameter)
4905 and then Present (Discriminal_Link (Entity (N)))))
4909 elsif Nkind (N) = N_Qualified_Expression then
4910 return Is_Preelaborable_Expression (Expression (N));
4912 -- For aggregates we have to check that each of the associations
4913 -- is preelaborable.
4915 elsif Nkind (N) = N_Aggregate
4916 or else Nkind (N) = N_Extension_Aggregate
4918 Is_Array_Aggr := Is_Array_Type (Etype (N));
4920 if Is_Array_Aggr then
4921 Comp_Type := Component_Type (Etype (N));
4924 -- Check the ancestor part of extension aggregates, which must
4925 -- be either the name of a type that has preelaborable init or
4926 -- an expression that is preelaborable.
4928 if Nkind (N) = N_Extension_Aggregate then
4930 Anc_Part : constant Node_Id := Ancestor_Part (N);
4933 if Is_Entity_Name (Anc_Part)
4934 and then Is_Type (Entity (Anc_Part))
4936 if not Has_Preelaborable_Initialization
4942 elsif not Is_Preelaborable_Expression (Anc_Part) then
4948 -- Check positional associations
4950 Exp := First (Expressions (N));
4951 while Present (Exp) loop
4952 if not Is_Preelaborable_Expression (Exp) then
4959 -- Check named associations
4961 Assn := First (Component_Associations (N));
4962 while Present (Assn) loop
4963 Choice := First (Choices (Assn));
4964 while Present (Choice) loop
4965 if Is_Array_Aggr then
4966 if Nkind (Choice) = N_Others_Choice then
4969 elsif Nkind (Choice) = N_Range then
4970 if not Is_Static_Range (Choice) then
4974 elsif not Is_Static_Expression (Choice) then
4979 Comp_Type := Etype (Choice);
4985 -- If the association has a <> at this point, then we have
4986 -- to check whether the component's type has preelaborable
4987 -- initialization. Note that this only occurs when the
4988 -- association's corresponding component does not have a
4989 -- default expression, the latter case having already been
4990 -- expanded as an expression for the association.
4992 if Box_Present (Assn) then
4993 if not Has_Preelaborable_Initialization (Comp_Type) then
4997 -- In the expression case we check whether the expression
4998 -- is preelaborable.
5001 not Is_Preelaborable_Expression (Expression (Assn))
5009 -- If we get here then aggregate as a whole is preelaborable
5013 -- All other cases are not preelaborable
5018 end Is_Preelaborable_Expression;
5020 -- Start of processing for Check_Components
5023 -- Loop through entities of record or protected type
5026 while Present (Ent) loop
5028 -- We are interested only in components and discriminants
5030 if Ekind_In (Ent, E_Component, E_Discriminant) then
5032 -- Get default expression if any. If there is no declaration
5033 -- node, it means we have an internal entity. The parent and
5034 -- tag fields are examples of such entities. For these cases,
5035 -- we just test the type of the entity.
5037 if Present (Declaration_Node (Ent)) then
5038 Exp := Expression (Declaration_Node (Ent));
5043 -- A component has PI if it has no default expression and the
5044 -- component type has PI.
5047 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5052 -- Require the default expression to be preelaborable
5054 elsif not Is_Preelaborable_Expression (Exp) then
5062 end Check_Components;
5064 -- Start of processing for Has_Preelaborable_Initialization
5067 -- Immediate return if already marked as known preelaborable init. This
5068 -- covers types for which this function has already been called once
5069 -- and returned True (in which case the result is cached), and also
5070 -- types to which a pragma Preelaborable_Initialization applies.
5072 if Known_To_Have_Preelab_Init (E) then
5076 -- If the type is a subtype representing a generic actual type, then
5077 -- test whether its base type has preelaborable initialization since
5078 -- the subtype representing the actual does not inherit this attribute
5079 -- from the actual or formal. (but maybe it should???)
5081 if Is_Generic_Actual_Type (E) then
5082 return Has_Preelaborable_Initialization (Base_Type (E));
5085 -- All elementary types have preelaborable initialization
5087 if Is_Elementary_Type (E) then
5090 -- Array types have PI if the component type has PI
5092 elsif Is_Array_Type (E) then
5093 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5095 -- A derived type has preelaborable initialization if its parent type
5096 -- has preelaborable initialization and (in the case of a derived record
5097 -- extension) if the non-inherited components all have preelaborable
5098 -- initialization. However, a user-defined controlled type with an
5099 -- overriding Initialize procedure does not have preelaborable
5102 elsif Is_Derived_Type (E) then
5104 -- If the derived type is a private extension then it doesn't have
5105 -- preelaborable initialization.
5107 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5111 -- First check whether ancestor type has preelaborable initialization
5113 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5115 -- If OK, check extension components (if any)
5117 if Has_PE and then Is_Record_Type (E) then
5118 Check_Components (First_Entity (E));
5121 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5122 -- with a user defined Initialize procedure does not have PI.
5125 and then Is_Controlled (E)
5126 and then Has_Overriding_Initialize (E)
5131 -- Private types not derived from a type having preelaborable init and
5132 -- that are not marked with pragma Preelaborable_Initialization do not
5133 -- have preelaborable initialization.
5135 elsif Is_Private_Type (E) then
5138 -- Record type has PI if it is non private and all components have PI
5140 elsif Is_Record_Type (E) then
5142 Check_Components (First_Entity (E));
5144 -- Protected types must not have entries, and components must meet
5145 -- same set of rules as for record components.
5147 elsif Is_Protected_Type (E) then
5148 if Has_Entries (E) then
5152 Check_Components (First_Entity (E));
5153 Check_Components (First_Private_Entity (E));
5156 -- Type System.Address always has preelaborable initialization
5158 elsif Is_RTE (E, RE_Address) then
5161 -- In all other cases, type does not have preelaborable initialization
5167 -- If type has preelaborable initialization, cache result
5170 Set_Known_To_Have_Preelab_Init (E);
5174 end Has_Preelaborable_Initialization;
5176 ---------------------------
5177 -- Has_Private_Component --
5178 ---------------------------
5180 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5181 Btype : Entity_Id := Base_Type (Type_Id);
5182 Component : Entity_Id;
5185 if Error_Posted (Type_Id)
5186 or else Error_Posted (Btype)
5191 if Is_Class_Wide_Type (Btype) then
5192 Btype := Root_Type (Btype);
5195 if Is_Private_Type (Btype) then
5197 UT : constant Entity_Id := Underlying_Type (Btype);
5200 if No (Full_View (Btype)) then
5201 return not Is_Generic_Type (Btype)
5202 and then not Is_Generic_Type (Root_Type (Btype));
5204 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5207 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5211 elsif Is_Array_Type (Btype) then
5212 return Has_Private_Component (Component_Type (Btype));
5214 elsif Is_Record_Type (Btype) then
5215 Component := First_Component (Btype);
5216 while Present (Component) loop
5217 if Has_Private_Component (Etype (Component)) then
5221 Next_Component (Component);
5226 elsif Is_Protected_Type (Btype)
5227 and then Present (Corresponding_Record_Type (Btype))
5229 return Has_Private_Component (Corresponding_Record_Type (Btype));
5234 end Has_Private_Component;
5240 function Has_Stream (T : Entity_Id) return Boolean is
5247 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5250 elsif Is_Array_Type (T) then
5251 return Has_Stream (Component_Type (T));
5253 elsif Is_Record_Type (T) then
5254 E := First_Component (T);
5255 while Present (E) loop
5256 if Has_Stream (Etype (E)) then
5265 elsif Is_Private_Type (T) then
5266 return Has_Stream (Underlying_Type (T));
5277 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5279 Get_Name_String (Chars (E));
5280 return Name_Buffer (Name_Len) = Suffix;
5283 --------------------------
5284 -- Has_Tagged_Component --
5285 --------------------------
5287 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5291 if Is_Private_Type (Typ)
5292 and then Present (Underlying_Type (Typ))
5294 return Has_Tagged_Component (Underlying_Type (Typ));
5296 elsif Is_Array_Type (Typ) then
5297 return Has_Tagged_Component (Component_Type (Typ));
5299 elsif Is_Tagged_Type (Typ) then
5302 elsif Is_Record_Type (Typ) then
5303 Comp := First_Component (Typ);
5304 while Present (Comp) loop
5305 if Has_Tagged_Component (Etype (Comp)) then
5309 Next_Component (Comp);
5317 end Has_Tagged_Component;
5319 -------------------------
5320 -- Implementation_Kind --
5321 -------------------------
5323 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5324 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5326 pragma Assert (Present (Impl_Prag));
5328 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5329 end Implementation_Kind;
5331 --------------------------
5332 -- Implements_Interface --
5333 --------------------------
5335 function Implements_Interface
5336 (Typ_Ent : Entity_Id;
5337 Iface_Ent : Entity_Id;
5338 Exclude_Parents : Boolean := False) return Boolean
5340 Ifaces_List : Elist_Id;
5342 Iface : Entity_Id := Base_Type (Iface_Ent);
5343 Typ : Entity_Id := Base_Type (Typ_Ent);
5346 if Is_Class_Wide_Type (Typ) then
5347 Typ := Root_Type (Typ);
5350 if not Has_Interfaces (Typ) then
5354 if Is_Class_Wide_Type (Iface) then
5355 Iface := Root_Type (Iface);
5358 Collect_Interfaces (Typ, Ifaces_List);
5360 Elmt := First_Elmt (Ifaces_List);
5361 while Present (Elmt) loop
5362 if Is_Ancestor (Node (Elmt), Typ)
5363 and then Exclude_Parents
5367 elsif Node (Elmt) = Iface then
5375 end Implements_Interface;
5381 function In_Instance return Boolean is
5382 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5388 and then S /= Standard_Standard
5390 if (Ekind (S) = E_Function
5391 or else Ekind (S) = E_Package
5392 or else Ekind (S) = E_Procedure)
5393 and then Is_Generic_Instance (S)
5395 -- A child instance is always compiled in the context of a parent
5396 -- instance. Nevertheless, the actuals are not analyzed in an
5397 -- instance context. We detect this case by examining the current
5398 -- compilation unit, which must be a child instance, and checking
5399 -- that it is not currently on the scope stack.
5401 if Is_Child_Unit (Curr_Unit)
5403 Nkind (Unit (Cunit (Current_Sem_Unit)))
5404 = N_Package_Instantiation
5405 and then not In_Open_Scopes (Curr_Unit)
5419 ----------------------
5420 -- In_Instance_Body --
5421 ----------------------
5423 function In_Instance_Body return Boolean is
5429 and then S /= Standard_Standard
5431 if (Ekind (S) = E_Function
5432 or else Ekind (S) = E_Procedure)
5433 and then Is_Generic_Instance (S)
5437 elsif Ekind (S) = E_Package
5438 and then In_Package_Body (S)
5439 and then Is_Generic_Instance (S)
5448 end In_Instance_Body;
5450 -----------------------------
5451 -- In_Instance_Not_Visible --
5452 -----------------------------
5454 function In_Instance_Not_Visible return Boolean is
5460 and then S /= Standard_Standard
5462 if (Ekind (S) = E_Function
5463 or else Ekind (S) = E_Procedure)
5464 and then Is_Generic_Instance (S)
5468 elsif Ekind (S) = E_Package
5469 and then (In_Package_Body (S) or else In_Private_Part (S))
5470 and then Is_Generic_Instance (S)
5479 end In_Instance_Not_Visible;
5481 ------------------------------
5482 -- In_Instance_Visible_Part --
5483 ------------------------------
5485 function In_Instance_Visible_Part return Boolean is
5491 and then S /= Standard_Standard
5493 if Ekind (S) = E_Package
5494 and then Is_Generic_Instance (S)
5495 and then not In_Package_Body (S)
5496 and then not In_Private_Part (S)
5505 end In_Instance_Visible_Part;
5507 ---------------------
5508 -- In_Package_Body --
5509 ---------------------
5511 function In_Package_Body return Boolean is
5517 and then S /= Standard_Standard
5519 if Ekind (S) = E_Package
5520 and then In_Package_Body (S)
5529 end In_Package_Body;
5531 --------------------------------
5532 -- In_Parameter_Specification --
5533 --------------------------------
5535 function In_Parameter_Specification (N : Node_Id) return Boolean is
5540 while Present (PN) loop
5541 if Nkind (PN) = N_Parameter_Specification then
5549 end In_Parameter_Specification;
5551 --------------------------------------
5552 -- In_Subprogram_Or_Concurrent_Unit --
5553 --------------------------------------
5555 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5560 -- Use scope chain to check successively outer scopes
5566 if K in Subprogram_Kind
5567 or else K in Concurrent_Kind
5568 or else K in Generic_Subprogram_Kind
5572 elsif E = Standard_Standard then
5578 end In_Subprogram_Or_Concurrent_Unit;
5580 ---------------------
5581 -- In_Visible_Part --
5582 ---------------------
5584 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5587 Is_Package_Or_Generic_Package (Scope_Id)
5588 and then In_Open_Scopes (Scope_Id)
5589 and then not In_Package_Body (Scope_Id)
5590 and then not In_Private_Part (Scope_Id);
5591 end In_Visible_Part;
5593 ---------------------------------
5594 -- Insert_Explicit_Dereference --
5595 ---------------------------------
5597 procedure Insert_Explicit_Dereference (N : Node_Id) is
5598 New_Prefix : constant Node_Id := Relocate_Node (N);
5599 Ent : Entity_Id := Empty;
5606 Save_Interps (N, New_Prefix);
5609 Make_Explicit_Dereference (Sloc (Parent (N)),
5610 Prefix => New_Prefix));
5612 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5614 if Is_Overloaded (New_Prefix) then
5616 -- The dereference is also overloaded, and its interpretations are
5617 -- the designated types of the interpretations of the original node.
5619 Set_Etype (N, Any_Type);
5621 Get_First_Interp (New_Prefix, I, It);
5622 while Present (It.Nam) loop
5625 if Is_Access_Type (T) then
5626 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5629 Get_Next_Interp (I, It);
5635 -- Prefix is unambiguous: mark the original prefix (which might
5636 -- Come_From_Source) as a reference, since the new (relocated) one
5637 -- won't be taken into account.
5639 if Is_Entity_Name (New_Prefix) then
5640 Ent := Entity (New_Prefix);
5643 -- For a retrieval of a subcomponent of some composite object,
5644 -- retrieve the ultimate entity if there is one.
5646 elsif Nkind (New_Prefix) = N_Selected_Component
5647 or else Nkind (New_Prefix) = N_Indexed_Component
5649 Pref := Prefix (New_Prefix);
5650 while Present (Pref)
5652 (Nkind (Pref) = N_Selected_Component
5653 or else Nkind (Pref) = N_Indexed_Component)
5655 Pref := Prefix (Pref);
5658 if Present (Pref) and then Is_Entity_Name (Pref) then
5659 Ent := Entity (Pref);
5663 -- Place the reference on the entity node
5665 if Present (Ent) then
5666 Generate_Reference (Ent, Pref);
5669 end Insert_Explicit_Dereference;
5671 ------------------------------------------
5672 -- Inspect_Deferred_Constant_Completion --
5673 ------------------------------------------
5675 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5679 Decl := First (Decls);
5680 while Present (Decl) loop
5682 -- Deferred constant signature
5684 if Nkind (Decl) = N_Object_Declaration
5685 and then Constant_Present (Decl)
5686 and then No (Expression (Decl))
5688 -- No need to check internally generated constants
5690 and then Comes_From_Source (Decl)
5692 -- The constant is not completed. A full object declaration or a
5693 -- pragma Import complete a deferred constant.
5695 and then not Has_Completion (Defining_Identifier (Decl))
5698 ("constant declaration requires initialization expression",
5699 Defining_Identifier (Decl));
5702 Decl := Next (Decl);
5704 end Inspect_Deferred_Constant_Completion;
5706 -----------------------------
5707 -- Is_Actual_Out_Parameter --
5708 -----------------------------
5710 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5714 Find_Actual (N, Formal, Call);
5715 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5716 end Is_Actual_Out_Parameter;
5718 -------------------------
5719 -- Is_Actual_Parameter --
5720 -------------------------
5722 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5723 PK : constant Node_Kind := Nkind (Parent (N));
5727 when N_Parameter_Association =>
5728 return N = Explicit_Actual_Parameter (Parent (N));
5730 when N_Function_Call | N_Procedure_Call_Statement =>
5731 return Is_List_Member (N)
5733 List_Containing (N) = Parameter_Associations (Parent (N));
5738 end Is_Actual_Parameter;
5740 ---------------------
5741 -- Is_Aliased_View --
5742 ---------------------
5744 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5748 if Is_Entity_Name (Obj) then
5756 or else (Present (Renamed_Object (E))
5757 and then Is_Aliased_View (Renamed_Object (E)))))
5759 or else ((Is_Formal (E)
5760 or else Ekind (E) = E_Generic_In_Out_Parameter
5761 or else Ekind (E) = E_Generic_In_Parameter)
5762 and then Is_Tagged_Type (Etype (E)))
5764 or else (Is_Concurrent_Type (E)
5765 and then In_Open_Scopes (E))
5767 -- Current instance of type, either directly or as rewritten
5768 -- reference to the current object.
5770 or else (Is_Entity_Name (Original_Node (Obj))
5771 and then Present (Entity (Original_Node (Obj)))
5772 and then Is_Type (Entity (Original_Node (Obj))))
5774 or else (Is_Type (E) and then E = Current_Scope)
5776 or else (Is_Incomplete_Or_Private_Type (E)
5777 and then Full_View (E) = Current_Scope);
5779 elsif Nkind (Obj) = N_Selected_Component then
5780 return Is_Aliased (Entity (Selector_Name (Obj)));
5782 elsif Nkind (Obj) = N_Indexed_Component then
5783 return Has_Aliased_Components (Etype (Prefix (Obj)))
5785 (Is_Access_Type (Etype (Prefix (Obj)))
5787 Has_Aliased_Components
5788 (Designated_Type (Etype (Prefix (Obj)))));
5790 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5791 or else Nkind (Obj) = N_Type_Conversion
5793 return Is_Tagged_Type (Etype (Obj))
5794 and then Is_Aliased_View (Expression (Obj));
5796 elsif Nkind (Obj) = N_Explicit_Dereference then
5797 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5802 end Is_Aliased_View;
5804 -------------------------
5805 -- Is_Ancestor_Package --
5806 -------------------------
5808 function Is_Ancestor_Package
5810 E2 : Entity_Id) return Boolean
5817 and then Par /= Standard_Standard
5827 end Is_Ancestor_Package;
5829 ----------------------
5830 -- Is_Atomic_Object --
5831 ----------------------
5833 function Is_Atomic_Object (N : Node_Id) return Boolean is
5835 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5836 -- Determines if given object has atomic components
5838 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5839 -- If prefix is an implicit dereference, examine designated type
5841 ----------------------
5842 -- Is_Atomic_Prefix --
5843 ----------------------
5845 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5847 if Is_Access_Type (Etype (N)) then
5849 Has_Atomic_Components (Designated_Type (Etype (N)));
5851 return Object_Has_Atomic_Components (N);
5853 end Is_Atomic_Prefix;
5855 ----------------------------------
5856 -- Object_Has_Atomic_Components --
5857 ----------------------------------
5859 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5861 if Has_Atomic_Components (Etype (N))
5862 or else Is_Atomic (Etype (N))
5866 elsif Is_Entity_Name (N)
5867 and then (Has_Atomic_Components (Entity (N))
5868 or else Is_Atomic (Entity (N)))
5872 elsif Nkind (N) = N_Indexed_Component
5873 or else Nkind (N) = N_Selected_Component
5875 return Is_Atomic_Prefix (Prefix (N));
5880 end Object_Has_Atomic_Components;
5882 -- Start of processing for Is_Atomic_Object
5885 -- Predicate is not relevant to subprograms
5887 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
5890 elsif Is_Atomic (Etype (N))
5891 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5895 elsif Nkind (N) = N_Indexed_Component
5896 or else Nkind (N) = N_Selected_Component
5898 return Is_Atomic_Prefix (Prefix (N));
5903 end Is_Atomic_Object;
5905 -------------------------
5906 -- Is_Coextension_Root --
5907 -------------------------
5909 function Is_Coextension_Root (N : Node_Id) return Boolean is
5912 Nkind (N) = N_Allocator
5913 and then Present (Coextensions (N))
5915 -- Anonymous access discriminants carry a list of all nested
5916 -- controlled coextensions.
5918 and then not Is_Dynamic_Coextension (N)
5919 and then not Is_Static_Coextension (N);
5920 end Is_Coextension_Root;
5922 -----------------------------
5923 -- Is_Concurrent_Interface --
5924 -----------------------------
5926 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5931 (Is_Protected_Interface (T)
5932 or else Is_Synchronized_Interface (T)
5933 or else Is_Task_Interface (T));
5934 end Is_Concurrent_Interface;
5936 --------------------------------------
5937 -- Is_Controlling_Limited_Procedure --
5938 --------------------------------------
5940 function Is_Controlling_Limited_Procedure
5941 (Proc_Nam : Entity_Id) return Boolean
5943 Param_Typ : Entity_Id := Empty;
5946 if Ekind (Proc_Nam) = E_Procedure
5947 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5949 Param_Typ := Etype (Parameter_Type (First (
5950 Parameter_Specifications (Parent (Proc_Nam)))));
5952 -- In this case where an Itype was created, the procedure call has been
5955 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5956 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5958 Present (Parameter_Associations
5959 (Associated_Node_For_Itype (Proc_Nam)))
5962 Etype (First (Parameter_Associations
5963 (Associated_Node_For_Itype (Proc_Nam))));
5966 if Present (Param_Typ) then
5968 Is_Interface (Param_Typ)
5969 and then Is_Limited_Record (Param_Typ);
5973 end Is_Controlling_Limited_Procedure;
5975 -----------------------------
5976 -- Is_CPP_Constructor_Call --
5977 -----------------------------
5979 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5981 return Nkind (N) = N_Function_Call
5982 and then Is_CPP_Class (Etype (Etype (N)))
5983 and then Is_Constructor (Entity (Name (N)))
5984 and then Is_Imported (Entity (Name (N)));
5985 end Is_CPP_Constructor_Call;
5991 function Is_Delegate (T : Entity_Id) return Boolean is
5992 Desig_Type : Entity_Id;
5995 if VM_Target /= CLI_Target then
5999 -- Access-to-subprograms are delegates in CIL
6001 if Ekind (T) = E_Access_Subprogram_Type then
6005 if Ekind (T) not in Access_Kind then
6007 -- A delegate is a managed pointer. If no designated type is defined
6008 -- it means that it's not a delegate.
6013 Desig_Type := Etype (Directly_Designated_Type (T));
6015 if not Is_Tagged_Type (Desig_Type) then
6019 -- Test if the type is inherited from [mscorlib]System.Delegate
6021 while Etype (Desig_Type) /= Desig_Type loop
6022 if Chars (Scope (Desig_Type)) /= No_Name
6023 and then Is_Imported (Scope (Desig_Type))
6024 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6029 Desig_Type := Etype (Desig_Type);
6035 ----------------------------------------------
6036 -- Is_Dependent_Component_Of_Mutable_Object --
6037 ----------------------------------------------
6039 function Is_Dependent_Component_Of_Mutable_Object
6040 (Object : Node_Id) return Boolean
6043 Prefix_Type : Entity_Id;
6044 P_Aliased : Boolean := False;
6047 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6048 -- Returns True if and only if Comp is declared within a variant part
6050 --------------------------------
6051 -- Is_Declared_Within_Variant --
6052 --------------------------------
6054 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6055 Comp_Decl : constant Node_Id := Parent (Comp);
6056 Comp_List : constant Node_Id := Parent (Comp_Decl);
6058 return Nkind (Parent (Comp_List)) = N_Variant;
6059 end Is_Declared_Within_Variant;
6061 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6064 if Is_Variable (Object) then
6066 if Nkind (Object) = N_Selected_Component then
6067 P := Prefix (Object);
6068 Prefix_Type := Etype (P);
6070 if Is_Entity_Name (P) then
6072 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6073 Prefix_Type := Base_Type (Prefix_Type);
6076 if Is_Aliased (Entity (P)) then
6080 -- A discriminant check on a selected component may be expanded
6081 -- into a dereference when removing side-effects. Recover the
6082 -- original node and its type, which may be unconstrained.
6084 elsif Nkind (P) = N_Explicit_Dereference
6085 and then not (Comes_From_Source (P))
6087 P := Original_Node (P);
6088 Prefix_Type := Etype (P);
6091 -- Check for prefix being an aliased component???
6097 -- A heap object is constrained by its initial value
6099 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6100 -- the dereferenced case, since the access value might denote an
6101 -- unconstrained aliased object, whereas in Ada 95 the designated
6102 -- object is guaranteed to be constrained. A worst-case assumption
6103 -- has to apply in Ada 2005 because we can't tell at compile time
6104 -- whether the object is "constrained by its initial value"
6105 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6106 -- semantic rules -- these rules are acknowledged to need fixing).
6108 if Ada_Version < Ada_2005 then
6109 if Is_Access_Type (Prefix_Type)
6110 or else Nkind (P) = N_Explicit_Dereference
6115 elsif Ada_Version >= Ada_2005 then
6116 if Is_Access_Type (Prefix_Type) then
6118 -- If the access type is pool-specific, and there is no
6119 -- constrained partial view of the designated type, then the
6120 -- designated object is known to be constrained.
6122 if Ekind (Prefix_Type) = E_Access_Type
6123 and then not Has_Constrained_Partial_View
6124 (Designated_Type (Prefix_Type))
6128 -- Otherwise (general access type, or there is a constrained
6129 -- partial view of the designated type), we need to check
6130 -- based on the designated type.
6133 Prefix_Type := Designated_Type (Prefix_Type);
6139 Original_Record_Component (Entity (Selector_Name (Object)));
6141 -- As per AI-0017, the renaming is illegal in a generic body, even
6142 -- if the subtype is indefinite.
6144 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6146 if not Is_Constrained (Prefix_Type)
6147 and then (not Is_Indefinite_Subtype (Prefix_Type)
6149 (Is_Generic_Type (Prefix_Type)
6150 and then Ekind (Current_Scope) = E_Generic_Package
6151 and then In_Package_Body (Current_Scope)))
6153 and then (Is_Declared_Within_Variant (Comp)
6154 or else Has_Discriminant_Dependent_Constraint (Comp))
6155 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6161 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6165 elsif Nkind (Object) = N_Indexed_Component
6166 or else Nkind (Object) = N_Slice
6168 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6170 -- A type conversion that Is_Variable is a view conversion:
6171 -- go back to the denoted object.
6173 elsif Nkind (Object) = N_Type_Conversion then
6175 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6180 end Is_Dependent_Component_Of_Mutable_Object;
6182 ---------------------
6183 -- Is_Dereferenced --
6184 ---------------------
6186 function Is_Dereferenced (N : Node_Id) return Boolean is
6187 P : constant Node_Id := Parent (N);
6190 (Nkind (P) = N_Selected_Component
6192 Nkind (P) = N_Explicit_Dereference
6194 Nkind (P) = N_Indexed_Component
6196 Nkind (P) = N_Slice)
6197 and then Prefix (P) = N;
6198 end Is_Dereferenced;
6200 ----------------------
6201 -- Is_Descendent_Of --
6202 ----------------------
6204 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6209 pragma Assert (Nkind (T1) in N_Entity);
6210 pragma Assert (Nkind (T2) in N_Entity);
6212 T := Base_Type (T1);
6214 -- Immediate return if the types match
6219 -- Comment needed here ???
6221 elsif Ekind (T) = E_Class_Wide_Type then
6222 return Etype (T) = T2;
6230 -- Done if we found the type we are looking for
6235 -- Done if no more derivations to check
6242 -- Following test catches error cases resulting from prev errors
6244 elsif No (Etyp) then
6247 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6250 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6254 T := Base_Type (Etyp);
6257 end Is_Descendent_Of;
6263 function Is_False (U : Uint) return Boolean is
6268 ---------------------------
6269 -- Is_Fixed_Model_Number --
6270 ---------------------------
6272 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6273 S : constant Ureal := Small_Value (T);
6274 M : Urealp.Save_Mark;
6278 R := (U = UR_Trunc (U / S) * S);
6281 end Is_Fixed_Model_Number;
6283 -------------------------------
6284 -- Is_Fully_Initialized_Type --
6285 -------------------------------
6287 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6289 if Is_Scalar_Type (Typ) then
6292 elsif Is_Access_Type (Typ) then
6295 elsif Is_Array_Type (Typ) then
6296 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6300 -- An interesting case, if we have a constrained type one of whose
6301 -- bounds is known to be null, then there are no elements to be
6302 -- initialized, so all the elements are initialized!
6304 if Is_Constrained (Typ) then
6307 Indx_Typ : Entity_Id;
6311 Indx := First_Index (Typ);
6312 while Present (Indx) loop
6313 if Etype (Indx) = Any_Type then
6316 -- If index is a range, use directly
6318 elsif Nkind (Indx) = N_Range then
6319 Lbd := Low_Bound (Indx);
6320 Hbd := High_Bound (Indx);
6323 Indx_Typ := Etype (Indx);
6325 if Is_Private_Type (Indx_Typ) then
6326 Indx_Typ := Full_View (Indx_Typ);
6329 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6332 Lbd := Type_Low_Bound (Indx_Typ);
6333 Hbd := Type_High_Bound (Indx_Typ);
6337 if Compile_Time_Known_Value (Lbd)
6338 and then Compile_Time_Known_Value (Hbd)
6340 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6350 -- If no null indexes, then type is not fully initialized
6356 elsif Is_Record_Type (Typ) then
6357 if Has_Discriminants (Typ)
6359 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6360 and then Is_Fully_Initialized_Variant (Typ)
6365 -- Controlled records are considered to be fully initialized if
6366 -- there is a user defined Initialize routine. This may not be
6367 -- entirely correct, but as the spec notes, we are guessing here
6368 -- what is best from the point of view of issuing warnings.
6370 if Is_Controlled (Typ) then
6372 Utyp : constant Entity_Id := Underlying_Type (Typ);
6375 if Present (Utyp) then
6377 Init : constant Entity_Id :=
6379 (Underlying_Type (Typ), Name_Initialize));
6383 and then Comes_From_Source (Init)
6385 Is_Predefined_File_Name
6386 (File_Name (Get_Source_File_Index (Sloc (Init))))
6390 elsif Has_Null_Extension (Typ)
6392 Is_Fully_Initialized_Type
6393 (Etype (Base_Type (Typ)))
6402 -- Otherwise see if all record components are initialized
6408 Ent := First_Entity (Typ);
6409 while Present (Ent) loop
6410 if Chars (Ent) = Name_uController then
6413 elsif Ekind (Ent) = E_Component
6414 and then (No (Parent (Ent))
6415 or else No (Expression (Parent (Ent))))
6416 and then not Is_Fully_Initialized_Type (Etype (Ent))
6418 -- Special VM case for tag components, which need to be
6419 -- defined in this case, but are never initialized as VMs
6420 -- are using other dispatching mechanisms. Ignore this
6421 -- uninitialized case. Note that this applies both to the
6422 -- uTag entry and the main vtable pointer (CPP_Class case).
6424 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6433 -- No uninitialized components, so type is fully initialized.
6434 -- Note that this catches the case of no components as well.
6438 elsif Is_Concurrent_Type (Typ) then
6441 elsif Is_Private_Type (Typ) then
6443 U : constant Entity_Id := Underlying_Type (Typ);
6449 return Is_Fully_Initialized_Type (U);
6456 end Is_Fully_Initialized_Type;
6458 ----------------------------------
6459 -- Is_Fully_Initialized_Variant --
6460 ----------------------------------
6462 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6463 Loc : constant Source_Ptr := Sloc (Typ);
6464 Constraints : constant List_Id := New_List;
6465 Components : constant Elist_Id := New_Elmt_List;
6466 Comp_Elmt : Elmt_Id;
6468 Comp_List : Node_Id;
6470 Discr_Val : Node_Id;
6472 Report_Errors : Boolean;
6473 pragma Warnings (Off, Report_Errors);
6476 if Serious_Errors_Detected > 0 then
6480 if Is_Record_Type (Typ)
6481 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6482 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6484 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6486 Discr := First_Discriminant (Typ);
6487 while Present (Discr) loop
6488 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6489 Discr_Val := Expression (Parent (Discr));
6491 if Present (Discr_Val)
6492 and then Is_OK_Static_Expression (Discr_Val)
6494 Append_To (Constraints,
6495 Make_Component_Association (Loc,
6496 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6497 Expression => New_Copy (Discr_Val)));
6505 Next_Discriminant (Discr);
6510 Comp_List => Comp_List,
6511 Governed_By => Constraints,
6513 Report_Errors => Report_Errors);
6515 -- Check that each component present is fully initialized
6517 Comp_Elmt := First_Elmt (Components);
6518 while Present (Comp_Elmt) loop
6519 Comp_Id := Node (Comp_Elmt);
6521 if Ekind (Comp_Id) = E_Component
6522 and then (No (Parent (Comp_Id))
6523 or else No (Expression (Parent (Comp_Id))))
6524 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6529 Next_Elmt (Comp_Elmt);
6534 elsif Is_Private_Type (Typ) then
6536 U : constant Entity_Id := Underlying_Type (Typ);
6542 return Is_Fully_Initialized_Variant (U);
6548 end Is_Fully_Initialized_Variant;
6554 -- We seem to have a lot of overlapping functions that do similar things
6555 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6556 -- purely syntactic, it should be in Sem_Aux I would think???
6558 function Is_LHS (N : Node_Id) return Boolean is
6559 P : constant Node_Id := Parent (N);
6561 return Nkind (P) = N_Assignment_Statement
6562 and then Name (P) = N;
6565 ----------------------------
6566 -- Is_Inherited_Operation --
6567 ----------------------------
6569 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6570 Kind : constant Node_Kind := Nkind (Parent (E));
6572 pragma Assert (Is_Overloadable (E));
6573 return Kind = N_Full_Type_Declaration
6574 or else Kind = N_Private_Extension_Declaration
6575 or else Kind = N_Subtype_Declaration
6576 or else (Ekind (E) = E_Enumeration_Literal
6577 and then Is_Derived_Type (Etype (E)));
6578 end Is_Inherited_Operation;
6580 -----------------------------
6581 -- Is_Library_Level_Entity --
6582 -----------------------------
6584 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6586 -- The following is a small optimization, and it also properly handles
6587 -- discriminals, which in task bodies might appear in expressions before
6588 -- the corresponding procedure has been created, and which therefore do
6589 -- not have an assigned scope.
6591 if Is_Formal (E) then
6595 -- Normal test is simply that the enclosing dynamic scope is Standard
6597 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6598 end Is_Library_Level_Entity;
6600 ---------------------------------
6601 -- Is_Local_Variable_Reference --
6602 ---------------------------------
6604 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6606 if not Is_Entity_Name (Expr) then
6611 Ent : constant Entity_Id := Entity (Expr);
6612 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6614 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6617 return Present (Sub) and then Sub = Current_Subprogram;
6621 end Is_Local_Variable_Reference;
6623 -------------------------
6624 -- Is_Object_Reference --
6625 -------------------------
6627 function Is_Object_Reference (N : Node_Id) return Boolean is
6629 if Is_Entity_Name (N) then
6630 return Present (Entity (N)) and then Is_Object (Entity (N));
6634 when N_Indexed_Component | N_Slice =>
6636 Is_Object_Reference (Prefix (N))
6637 or else Is_Access_Type (Etype (Prefix (N)));
6639 -- In Ada95, a function call is a constant object; a procedure
6642 when N_Function_Call =>
6643 return Etype (N) /= Standard_Void_Type;
6645 -- A reference to the stream attribute Input is a function call
6647 when N_Attribute_Reference =>
6648 return Attribute_Name (N) = Name_Input;
6650 when N_Selected_Component =>
6652 Is_Object_Reference (Selector_Name (N))
6654 (Is_Object_Reference (Prefix (N))
6655 or else Is_Access_Type (Etype (Prefix (N))));
6657 when N_Explicit_Dereference =>
6660 -- A view conversion of a tagged object is an object reference
6662 when N_Type_Conversion =>
6663 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6664 and then Is_Tagged_Type (Etype (Expression (N)))
6665 and then Is_Object_Reference (Expression (N));
6667 -- An unchecked type conversion is considered to be an object if
6668 -- the operand is an object (this construction arises only as a
6669 -- result of expansion activities).
6671 when N_Unchecked_Type_Conversion =>
6678 end Is_Object_Reference;
6680 -----------------------------------
6681 -- Is_OK_Variable_For_Out_Formal --
6682 -----------------------------------
6684 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6686 Note_Possible_Modification (AV, Sure => True);
6688 -- We must reject parenthesized variable names. The check for
6689 -- Comes_From_Source is present because there are currently
6690 -- cases where the compiler violates this rule (e.g. passing
6691 -- a task object to its controlled Initialize routine).
6693 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6696 -- A variable is always allowed
6698 elsif Is_Variable (AV) then
6701 -- Unchecked conversions are allowed only if they come from the
6702 -- generated code, which sometimes uses unchecked conversions for out
6703 -- parameters in cases where code generation is unaffected. We tell
6704 -- source unchecked conversions by seeing if they are rewrites of an
6705 -- original Unchecked_Conversion function call, or of an explicit
6706 -- conversion of a function call.
6708 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6709 if Nkind (Original_Node (AV)) = N_Function_Call then
6712 elsif Comes_From_Source (AV)
6713 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6717 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6718 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6724 -- Normal type conversions are allowed if argument is a variable
6726 elsif Nkind (AV) = N_Type_Conversion then
6727 if Is_Variable (Expression (AV))
6728 and then Paren_Count (Expression (AV)) = 0
6730 Note_Possible_Modification (Expression (AV), Sure => True);
6733 -- We also allow a non-parenthesized expression that raises
6734 -- constraint error if it rewrites what used to be a variable
6736 elsif Raises_Constraint_Error (Expression (AV))
6737 and then Paren_Count (Expression (AV)) = 0
6738 and then Is_Variable (Original_Node (Expression (AV)))
6742 -- Type conversion of something other than a variable
6748 -- If this node is rewritten, then test the original form, if that is
6749 -- OK, then we consider the rewritten node OK (for example, if the
6750 -- original node is a conversion, then Is_Variable will not be true
6751 -- but we still want to allow the conversion if it converts a variable).
6753 elsif Original_Node (AV) /= AV then
6754 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6756 -- All other non-variables are rejected
6761 end Is_OK_Variable_For_Out_Formal;
6763 -----------------------------------
6764 -- Is_Partially_Initialized_Type --
6765 -----------------------------------
6767 function Is_Partially_Initialized_Type
6769 Include_Null : Boolean := True) return Boolean
6772 if Is_Scalar_Type (Typ) then
6775 elsif Is_Access_Type (Typ) then
6776 return Include_Null;
6778 elsif Is_Array_Type (Typ) then
6780 -- If component type is partially initialized, so is array type
6782 if Is_Partially_Initialized_Type
6783 (Component_Type (Typ), Include_Null)
6787 -- Otherwise we are only partially initialized if we are fully
6788 -- initialized (this is the empty array case, no point in us
6789 -- duplicating that code here).
6792 return Is_Fully_Initialized_Type (Typ);
6795 elsif Is_Record_Type (Typ) then
6797 -- A discriminated type is always partially initialized
6799 if Has_Discriminants (Typ) then
6802 -- A tagged type is always partially initialized
6804 elsif Is_Tagged_Type (Typ) then
6807 -- Case of non-discriminated record
6813 Component_Present : Boolean := False;
6814 -- Set True if at least one component is present. If no
6815 -- components are present, then record type is fully
6816 -- initialized (another odd case, like the null array).
6819 -- Loop through components
6821 Ent := First_Entity (Typ);
6822 while Present (Ent) loop
6823 if Ekind (Ent) = E_Component then
6824 Component_Present := True;
6826 -- If a component has an initialization expression then
6827 -- the enclosing record type is partially initialized
6829 if Present (Parent (Ent))
6830 and then Present (Expression (Parent (Ent)))
6834 -- If a component is of a type which is itself partially
6835 -- initialized, then the enclosing record type is also.
6837 elsif Is_Partially_Initialized_Type
6838 (Etype (Ent), Include_Null)
6847 -- No initialized components found. If we found any components
6848 -- they were all uninitialized so the result is false.
6850 if Component_Present then
6853 -- But if we found no components, then all the components are
6854 -- initialized so we consider the type to be initialized.
6862 -- Concurrent types are always fully initialized
6864 elsif Is_Concurrent_Type (Typ) then
6867 -- For a private type, go to underlying type. If there is no underlying
6868 -- type then just assume this partially initialized. Not clear if this
6869 -- can happen in a non-error case, but no harm in testing for this.
6871 elsif Is_Private_Type (Typ) then
6873 U : constant Entity_Id := Underlying_Type (Typ);
6878 return Is_Partially_Initialized_Type (U, Include_Null);
6882 -- For any other type (are there any?) assume partially initialized
6887 end Is_Partially_Initialized_Type;
6889 ------------------------------------
6890 -- Is_Potentially_Persistent_Type --
6891 ------------------------------------
6893 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6898 -- For private type, test corresponding full type
6900 if Is_Private_Type (T) then
6901 return Is_Potentially_Persistent_Type (Full_View (T));
6903 -- Scalar types are potentially persistent
6905 elsif Is_Scalar_Type (T) then
6908 -- Record type is potentially persistent if not tagged and the types of
6909 -- all it components are potentially persistent, and no component has
6910 -- an initialization expression.
6912 elsif Is_Record_Type (T)
6913 and then not Is_Tagged_Type (T)
6914 and then not Is_Partially_Initialized_Type (T)
6916 Comp := First_Component (T);
6917 while Present (Comp) loop
6918 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6927 -- Array type is potentially persistent if its component type is
6928 -- potentially persistent and if all its constraints are static.
6930 elsif Is_Array_Type (T) then
6931 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6935 Indx := First_Index (T);
6936 while Present (Indx) loop
6937 if not Is_OK_Static_Subtype (Etype (Indx)) then
6946 -- All other types are not potentially persistent
6951 end Is_Potentially_Persistent_Type;
6953 ---------------------------------
6954 -- Is_Protected_Self_Reference --
6955 ---------------------------------
6957 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6959 function In_Access_Definition (N : Node_Id) return Boolean;
6960 -- Returns true if N belongs to an access definition
6962 --------------------------
6963 -- In_Access_Definition --
6964 --------------------------
6966 function In_Access_Definition (N : Node_Id) return Boolean is
6971 while Present (P) loop
6972 if Nkind (P) = N_Access_Definition then
6980 end In_Access_Definition;
6982 -- Start of processing for Is_Protected_Self_Reference
6985 -- Verify that prefix is analyzed and has the proper form. Note that
6986 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6987 -- produce the address of an entity, do not analyze their prefix
6988 -- because they denote entities that are not necessarily visible.
6989 -- Neither of them can apply to a protected type.
6991 return Ada_Version >= Ada_2005
6992 and then Is_Entity_Name (N)
6993 and then Present (Entity (N))
6994 and then Is_Protected_Type (Entity (N))
6995 and then In_Open_Scopes (Entity (N))
6996 and then not In_Access_Definition (N);
6997 end Is_Protected_Self_Reference;
6999 -----------------------------
7000 -- Is_RCI_Pkg_Spec_Or_Body --
7001 -----------------------------
7003 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7005 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7006 -- Return True if the unit of Cunit is an RCI package declaration
7008 ---------------------------
7009 -- Is_RCI_Pkg_Decl_Cunit --
7010 ---------------------------
7012 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7013 The_Unit : constant Node_Id := Unit (Cunit);
7016 if Nkind (The_Unit) /= N_Package_Declaration then
7020 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7021 end Is_RCI_Pkg_Decl_Cunit;
7023 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7026 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7028 (Nkind (Unit (Cunit)) = N_Package_Body
7029 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7030 end Is_RCI_Pkg_Spec_Or_Body;
7032 -----------------------------------------
7033 -- Is_Remote_Access_To_Class_Wide_Type --
7034 -----------------------------------------
7036 function Is_Remote_Access_To_Class_Wide_Type
7037 (E : Entity_Id) return Boolean
7040 -- A remote access to class-wide type is a general access to object type
7041 -- declared in the visible part of a Remote_Types or Remote_Call_
7044 return Ekind (E) = E_General_Access_Type
7045 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7046 end Is_Remote_Access_To_Class_Wide_Type;
7048 -----------------------------------------
7049 -- Is_Remote_Access_To_Subprogram_Type --
7050 -----------------------------------------
7052 function Is_Remote_Access_To_Subprogram_Type
7053 (E : Entity_Id) return Boolean
7056 return (Ekind (E) = E_Access_Subprogram_Type
7057 or else (Ekind (E) = E_Record_Type
7058 and then Present (Corresponding_Remote_Type (E))))
7059 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7060 end Is_Remote_Access_To_Subprogram_Type;
7062 --------------------
7063 -- Is_Remote_Call --
7064 --------------------
7066 function Is_Remote_Call (N : Node_Id) return Boolean is
7068 if Nkind (N) /= N_Procedure_Call_Statement
7069 and then Nkind (N) /= N_Function_Call
7071 -- An entry call cannot be remote
7075 elsif Nkind (Name (N)) in N_Has_Entity
7076 and then Is_Remote_Call_Interface (Entity (Name (N)))
7078 -- A subprogram declared in the spec of a RCI package is remote
7082 elsif Nkind (Name (N)) = N_Explicit_Dereference
7083 and then Is_Remote_Access_To_Subprogram_Type
7084 (Etype (Prefix (Name (N))))
7086 -- The dereference of a RAS is a remote call
7090 elsif Present (Controlling_Argument (N))
7091 and then Is_Remote_Access_To_Class_Wide_Type
7092 (Etype (Controlling_Argument (N)))
7094 -- Any primitive operation call with a controlling argument of
7095 -- a RACW type is a remote call.
7100 -- All other calls are local calls
7105 ----------------------
7106 -- Is_Renamed_Entry --
7107 ----------------------
7109 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7110 Orig_Node : Node_Id := Empty;
7111 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7113 function Is_Entry (Nam : Node_Id) return Boolean;
7114 -- Determine whether Nam is an entry. Traverse selectors if there are
7115 -- nested selected components.
7121 function Is_Entry (Nam : Node_Id) return Boolean is
7123 if Nkind (Nam) = N_Selected_Component then
7124 return Is_Entry (Selector_Name (Nam));
7127 return Ekind (Entity (Nam)) = E_Entry;
7130 -- Start of processing for Is_Renamed_Entry
7133 if Present (Alias (Proc_Nam)) then
7134 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7137 -- Look for a rewritten subprogram renaming declaration
7139 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7140 and then Present (Original_Node (Subp_Decl))
7142 Orig_Node := Original_Node (Subp_Decl);
7145 -- The rewritten subprogram is actually an entry
7147 if Present (Orig_Node)
7148 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7149 and then Is_Entry (Name (Orig_Node))
7155 end Is_Renamed_Entry;
7157 ----------------------
7158 -- Is_Selector_Name --
7159 ----------------------
7161 function Is_Selector_Name (N : Node_Id) return Boolean is
7163 if not Is_List_Member (N) then
7165 P : constant Node_Id := Parent (N);
7166 K : constant Node_Kind := Nkind (P);
7169 (K = N_Expanded_Name or else
7170 K = N_Generic_Association or else
7171 K = N_Parameter_Association or else
7172 K = N_Selected_Component)
7173 and then Selector_Name (P) = N;
7178 L : constant List_Id := List_Containing (N);
7179 P : constant Node_Id := Parent (L);
7181 return (Nkind (P) = N_Discriminant_Association
7182 and then Selector_Names (P) = L)
7184 (Nkind (P) = N_Component_Association
7185 and then Choices (P) = L);
7188 end Is_Selector_Name;
7194 function Is_Statement (N : Node_Id) return Boolean is
7197 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7198 or else Nkind (N) = N_Procedure_Call_Statement;
7201 ---------------------------------
7202 -- Is_Synchronized_Tagged_Type --
7203 ---------------------------------
7205 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7206 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7209 -- A task or protected type derived from an interface is a tagged type.
7210 -- Such a tagged type is called a synchronized tagged type, as are
7211 -- synchronized interfaces and private extensions whose declaration
7212 -- includes the reserved word synchronized.
7214 return (Is_Tagged_Type (E)
7215 and then (Kind = E_Task_Type
7216 or else Kind = E_Protected_Type))
7219 and then Is_Synchronized_Interface (E))
7221 (Ekind (E) = E_Record_Type_With_Private
7222 and then (Synchronized_Present (Parent (E))
7223 or else Is_Synchronized_Interface (Etype (E))));
7224 end Is_Synchronized_Tagged_Type;
7230 function Is_Transfer (N : Node_Id) return Boolean is
7231 Kind : constant Node_Kind := Nkind (N);
7234 if Kind = N_Simple_Return_Statement
7236 Kind = N_Extended_Return_Statement
7238 Kind = N_Goto_Statement
7240 Kind = N_Raise_Statement
7242 Kind = N_Requeue_Statement
7246 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7247 and then No (Condition (N))
7251 elsif Kind = N_Procedure_Call_Statement
7252 and then Is_Entity_Name (Name (N))
7253 and then Present (Entity (Name (N)))
7254 and then No_Return (Entity (Name (N)))
7258 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7270 function Is_True (U : Uint) return Boolean is
7275 -------------------------------
7276 -- Is_Universal_Numeric_Type --
7277 -------------------------------
7279 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7281 return T = Universal_Integer or else T = Universal_Real;
7282 end Is_Universal_Numeric_Type;
7288 function Is_Value_Type (T : Entity_Id) return Boolean is
7290 return VM_Target = CLI_Target
7291 and then Nkind (T) in N_Has_Chars
7292 and then Chars (T) /= No_Name
7293 and then Get_Name_String (Chars (T)) = "valuetype";
7296 ---------------------
7297 -- Is_VMS_Operator --
7298 ---------------------
7300 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7302 -- The VMS operators are declared in a child of System that is loaded
7303 -- through pragma Extend_System. In some rare cases a program is run
7304 -- with this extension but without indicating that the target is VMS.
7306 return Ekind (Op) = E_Function
7307 and then Is_Intrinsic_Subprogram (Op)
7309 ((Present_System_Aux
7310 and then Scope (Op) = System_Aux_Id)
7313 and then Scope (Scope (Op)) = RTU_Entity (System)));
7314 end Is_VMS_Operator;
7320 function Is_Variable (N : Node_Id) return Boolean is
7322 Orig_Node : constant Node_Id := Original_Node (N);
7323 -- We do the test on the original node, since this is basically a test
7324 -- of syntactic categories, so it must not be disturbed by whatever
7325 -- rewriting might have occurred. For example, an aggregate, which is
7326 -- certainly NOT a variable, could be turned into a variable by
7329 function In_Protected_Function (E : Entity_Id) return Boolean;
7330 -- Within a protected function, the private components of the enclosing
7331 -- protected type are constants. A function nested within a (protected)
7332 -- procedure is not itself protected.
7334 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7335 -- Prefixes can involve implicit dereferences, in which case we must
7336 -- test for the case of a reference of a constant access type, which can
7337 -- can never be a variable.
7339 ---------------------------
7340 -- In_Protected_Function --
7341 ---------------------------
7343 function In_Protected_Function (E : Entity_Id) return Boolean is
7344 Prot : constant Entity_Id := Scope (E);
7348 if not Is_Protected_Type (Prot) then
7352 while Present (S) and then S /= Prot loop
7353 if Ekind (S) = E_Function and then Scope (S) = Prot then
7362 end In_Protected_Function;
7364 ------------------------
7365 -- Is_Variable_Prefix --
7366 ------------------------
7368 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7370 if Is_Access_Type (Etype (P)) then
7371 return not Is_Access_Constant (Root_Type (Etype (P)));
7373 -- For the case of an indexed component whose prefix has a packed
7374 -- array type, the prefix has been rewritten into a type conversion.
7375 -- Determine variable-ness from the converted expression.
7377 elsif Nkind (P) = N_Type_Conversion
7378 and then not Comes_From_Source (P)
7379 and then Is_Array_Type (Etype (P))
7380 and then Is_Packed (Etype (P))
7382 return Is_Variable (Expression (P));
7385 return Is_Variable (P);
7387 end Is_Variable_Prefix;
7389 -- Start of processing for Is_Variable
7392 -- Definitely OK if Assignment_OK is set. Since this is something that
7393 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7395 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7398 -- Normally we go to the original node, but there is one exception where
7399 -- we use the rewritten node, namely when it is an explicit dereference.
7400 -- The generated code may rewrite a prefix which is an access type with
7401 -- an explicit dereference. The dereference is a variable, even though
7402 -- the original node may not be (since it could be a constant of the
7405 -- In Ada 2005 we have a further case to consider: the prefix may be a
7406 -- function call given in prefix notation. The original node appears to
7407 -- be a selected component, but we need to examine the call.
7409 elsif Nkind (N) = N_Explicit_Dereference
7410 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7411 and then Present (Etype (Orig_Node))
7412 and then Is_Access_Type (Etype (Orig_Node))
7414 -- Note that if the prefix is an explicit dereference that does not
7415 -- come from source, we must check for a rewritten function call in
7416 -- prefixed notation before other forms of rewriting, to prevent a
7420 (Nkind (Orig_Node) = N_Function_Call
7421 and then not Is_Access_Constant (Etype (Prefix (N))))
7423 Is_Variable_Prefix (Original_Node (Prefix (N)));
7425 -- A function call is never a variable
7427 elsif Nkind (N) = N_Function_Call then
7430 -- All remaining checks use the original node
7432 elsif Is_Entity_Name (Orig_Node)
7433 and then Present (Entity (Orig_Node))
7436 E : constant Entity_Id := Entity (Orig_Node);
7437 K : constant Entity_Kind := Ekind (E);
7440 return (K = E_Variable
7441 and then Nkind (Parent (E)) /= N_Exception_Handler)
7442 or else (K = E_Component
7443 and then not In_Protected_Function (E))
7444 or else K = E_Out_Parameter
7445 or else K = E_In_Out_Parameter
7446 or else K = E_Generic_In_Out_Parameter
7448 -- Current instance of type:
7450 or else (Is_Type (E) and then In_Open_Scopes (E))
7451 or else (Is_Incomplete_Or_Private_Type (E)
7452 and then In_Open_Scopes (Full_View (E)));
7456 case Nkind (Orig_Node) is
7457 when N_Indexed_Component | N_Slice =>
7458 return Is_Variable_Prefix (Prefix (Orig_Node));
7460 when N_Selected_Component =>
7461 return Is_Variable_Prefix (Prefix (Orig_Node))
7462 and then Is_Variable (Selector_Name (Orig_Node));
7464 -- For an explicit dereference, the type of the prefix cannot
7465 -- be an access to constant or an access to subprogram.
7467 when N_Explicit_Dereference =>
7469 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7471 return Is_Access_Type (Typ)
7472 and then not Is_Access_Constant (Root_Type (Typ))
7473 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7476 -- The type conversion is the case where we do not deal with the
7477 -- context dependent special case of an actual parameter. Thus
7478 -- the type conversion is only considered a variable for the
7479 -- purposes of this routine if the target type is tagged. However,
7480 -- a type conversion is considered to be a variable if it does not
7481 -- come from source (this deals for example with the conversions
7482 -- of expressions to their actual subtypes).
7484 when N_Type_Conversion =>
7485 return Is_Variable (Expression (Orig_Node))
7487 (not Comes_From_Source (Orig_Node)
7489 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7491 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7493 -- GNAT allows an unchecked type conversion as a variable. This
7494 -- only affects the generation of internal expanded code, since
7495 -- calls to instantiations of Unchecked_Conversion are never
7496 -- considered variables (since they are function calls).
7497 -- This is also true for expression actions.
7499 when N_Unchecked_Type_Conversion =>
7500 return Is_Variable (Expression (Orig_Node));
7508 ---------------------------
7509 -- Is_Visibly_Controlled --
7510 ---------------------------
7512 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7513 Root : constant Entity_Id := Root_Type (T);
7515 return Chars (Scope (Root)) = Name_Finalization
7516 and then Chars (Scope (Scope (Root))) = Name_Ada
7517 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7518 end Is_Visibly_Controlled;
7520 ------------------------
7521 -- Is_Volatile_Object --
7522 ------------------------
7524 function Is_Volatile_Object (N : Node_Id) return Boolean is
7526 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7527 -- Determines if given object has volatile components
7529 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7530 -- If prefix is an implicit dereference, examine designated type
7532 ------------------------
7533 -- Is_Volatile_Prefix --
7534 ------------------------
7536 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7537 Typ : constant Entity_Id := Etype (N);
7540 if Is_Access_Type (Typ) then
7542 Dtyp : constant Entity_Id := Designated_Type (Typ);
7545 return Is_Volatile (Dtyp)
7546 or else Has_Volatile_Components (Dtyp);
7550 return Object_Has_Volatile_Components (N);
7552 end Is_Volatile_Prefix;
7554 ------------------------------------
7555 -- Object_Has_Volatile_Components --
7556 ------------------------------------
7558 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7559 Typ : constant Entity_Id := Etype (N);
7562 if Is_Volatile (Typ)
7563 or else Has_Volatile_Components (Typ)
7567 elsif Is_Entity_Name (N)
7568 and then (Has_Volatile_Components (Entity (N))
7569 or else Is_Volatile (Entity (N)))
7573 elsif Nkind (N) = N_Indexed_Component
7574 or else Nkind (N) = N_Selected_Component
7576 return Is_Volatile_Prefix (Prefix (N));
7581 end Object_Has_Volatile_Components;
7583 -- Start of processing for Is_Volatile_Object
7586 if Is_Volatile (Etype (N))
7587 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7591 elsif Nkind (N) = N_Indexed_Component
7592 or else Nkind (N) = N_Selected_Component
7594 return Is_Volatile_Prefix (Prefix (N));
7599 end Is_Volatile_Object;
7601 -------------------------
7602 -- Kill_Current_Values --
7603 -------------------------
7605 procedure Kill_Current_Values
7607 Last_Assignment_Only : Boolean := False)
7610 -- ??? do we have to worry about clearing cached checks?
7612 if Is_Assignable (Ent) then
7613 Set_Last_Assignment (Ent, Empty);
7616 if Is_Object (Ent) then
7617 if not Last_Assignment_Only then
7619 Set_Current_Value (Ent, Empty);
7621 if not Can_Never_Be_Null (Ent) then
7622 Set_Is_Known_Non_Null (Ent, False);
7625 Set_Is_Known_Null (Ent, False);
7627 -- Reset Is_Known_Valid unless type is always valid, or if we have
7628 -- a loop parameter (loop parameters are always valid, since their
7629 -- bounds are defined by the bounds given in the loop header).
7631 if not Is_Known_Valid (Etype (Ent))
7632 and then Ekind (Ent) /= E_Loop_Parameter
7634 Set_Is_Known_Valid (Ent, False);
7638 end Kill_Current_Values;
7640 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7643 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7644 -- Clear current value for entity E and all entities chained to E
7646 ------------------------------------------
7647 -- Kill_Current_Values_For_Entity_Chain --
7648 ------------------------------------------
7650 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7654 while Present (Ent) loop
7655 Kill_Current_Values (Ent, Last_Assignment_Only);
7658 end Kill_Current_Values_For_Entity_Chain;
7660 -- Start of processing for Kill_Current_Values
7663 -- Kill all saved checks, a special case of killing saved values
7665 if not Last_Assignment_Only then
7669 -- Loop through relevant scopes, which includes the current scope and
7670 -- any parent scopes if the current scope is a block or a package.
7675 -- Clear current values of all entities in current scope
7677 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7679 -- If scope is a package, also clear current values of all
7680 -- private entities in the scope.
7682 if Is_Package_Or_Generic_Package (S)
7683 or else Is_Concurrent_Type (S)
7685 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7688 -- If this is a not a subprogram, deal with parents
7690 if not Is_Subprogram (S) then
7692 exit Scope_Loop when S = Standard_Standard;
7696 end loop Scope_Loop;
7697 end Kill_Current_Values;
7699 --------------------------
7700 -- Kill_Size_Check_Code --
7701 --------------------------
7703 procedure Kill_Size_Check_Code (E : Entity_Id) is
7705 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7706 and then Present (Size_Check_Code (E))
7708 Remove (Size_Check_Code (E));
7709 Set_Size_Check_Code (E, Empty);
7711 end Kill_Size_Check_Code;
7713 --------------------------
7714 -- Known_To_Be_Assigned --
7715 --------------------------
7717 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7718 P : constant Node_Id := Parent (N);
7723 -- Test left side of assignment
7725 when N_Assignment_Statement =>
7726 return N = Name (P);
7728 -- Function call arguments are never lvalues
7730 when N_Function_Call =>
7733 -- Positional parameter for procedure or accept call
7735 when N_Procedure_Call_Statement |
7744 Proc := Get_Subprogram_Entity (P);
7750 -- If we are not a list member, something is strange, so
7751 -- be conservative and return False.
7753 if not Is_List_Member (N) then
7757 -- We are going to find the right formal by stepping forward
7758 -- through the formals, as we step backwards in the actuals.
7760 Form := First_Formal (Proc);
7763 -- If no formal, something is weird, so be conservative
7764 -- and return False.
7775 return Ekind (Form) /= E_In_Parameter;
7778 -- Named parameter for procedure or accept call
7780 when N_Parameter_Association =>
7786 Proc := Get_Subprogram_Entity (Parent (P));
7792 -- Loop through formals to find the one that matches
7794 Form := First_Formal (Proc);
7796 -- If no matching formal, that's peculiar, some kind of
7797 -- previous error, so return False to be conservative.
7803 -- Else test for match
7805 if Chars (Form) = Chars (Selector_Name (P)) then
7806 return Ekind (Form) /= E_In_Parameter;
7813 -- Test for appearing in a conversion that itself appears
7814 -- in an lvalue context, since this should be an lvalue.
7816 when N_Type_Conversion =>
7817 return Known_To_Be_Assigned (P);
7819 -- All other references are definitely not known to be modifications
7825 end Known_To_Be_Assigned;
7831 function May_Be_Lvalue (N : Node_Id) return Boolean is
7832 P : constant Node_Id := Parent (N);
7837 -- Test left side of assignment
7839 when N_Assignment_Statement =>
7840 return N = Name (P);
7842 -- Test prefix of component or attribute. Note that the prefix of an
7843 -- explicit or implicit dereference cannot be an l-value.
7845 when N_Attribute_Reference =>
7846 return N = Prefix (P)
7847 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7849 -- For an expanded name, the name is an lvalue if the expanded name
7850 -- is an lvalue, but the prefix is never an lvalue, since it is just
7851 -- the scope where the name is found.
7853 when N_Expanded_Name =>
7854 if N = Prefix (P) then
7855 return May_Be_Lvalue (P);
7860 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7861 -- B is a little interesting, if we have A.B := 3, there is some
7862 -- discussion as to whether B is an lvalue or not, we choose to say
7863 -- it is. Note however that A is not an lvalue if it is of an access
7864 -- type since this is an implicit dereference.
7866 when N_Selected_Component =>
7868 and then Present (Etype (N))
7869 and then Is_Access_Type (Etype (N))
7873 return May_Be_Lvalue (P);
7876 -- For an indexed component or slice, the index or slice bounds is
7877 -- never an lvalue. The prefix is an lvalue if the indexed component
7878 -- or slice is an lvalue, except if it is an access type, where we
7879 -- have an implicit dereference.
7881 when N_Indexed_Component =>
7883 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7887 return May_Be_Lvalue (P);
7890 -- Prefix of a reference is an lvalue if the reference is an lvalue
7893 return May_Be_Lvalue (P);
7895 -- Prefix of explicit dereference is never an lvalue
7897 when N_Explicit_Dereference =>
7900 -- Function call arguments are never lvalues
7902 when N_Function_Call =>
7905 -- Positional parameter for procedure, entry, or accept call
7907 when N_Procedure_Call_Statement |
7908 N_Entry_Call_Statement |
7917 Proc := Get_Subprogram_Entity (P);
7923 -- If we are not a list member, something is strange, so
7924 -- be conservative and return True.
7926 if not Is_List_Member (N) then
7930 -- We are going to find the right formal by stepping forward
7931 -- through the formals, as we step backwards in the actuals.
7933 Form := First_Formal (Proc);
7936 -- If no formal, something is weird, so be conservative
7948 return Ekind (Form) /= E_In_Parameter;
7951 -- Named parameter for procedure or accept call
7953 when N_Parameter_Association =>
7959 Proc := Get_Subprogram_Entity (Parent (P));
7965 -- Loop through formals to find the one that matches
7967 Form := First_Formal (Proc);
7969 -- If no matching formal, that's peculiar, some kind of
7970 -- previous error, so return True to be conservative.
7976 -- Else test for match
7978 if Chars (Form) = Chars (Selector_Name (P)) then
7979 return Ekind (Form) /= E_In_Parameter;
7986 -- Test for appearing in a conversion that itself appears in an
7987 -- lvalue context, since this should be an lvalue.
7989 when N_Type_Conversion =>
7990 return May_Be_Lvalue (P);
7992 -- Test for appearance in object renaming declaration
7994 when N_Object_Renaming_Declaration =>
7997 -- All other references are definitely not lvalues
8005 -----------------------
8006 -- Mark_Coextensions --
8007 -----------------------
8009 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8010 Is_Dynamic : Boolean;
8011 -- Indicates whether the context causes nested coextensions to be
8012 -- dynamic or static
8014 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8015 -- Recognize an allocator node and label it as a dynamic coextension
8017 --------------------
8018 -- Mark_Allocator --
8019 --------------------
8021 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8023 if Nkind (N) = N_Allocator then
8025 Set_Is_Dynamic_Coextension (N);
8027 -- If the allocator expression is potentially dynamic, it may
8028 -- be expanded out of order and require dynamic allocation
8029 -- anyway, so we treat the coextension itself as dynamic.
8030 -- Potential optimization ???
8032 elsif Nkind (Expression (N)) = N_Qualified_Expression
8033 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8035 Set_Is_Dynamic_Coextension (N);
8038 Set_Is_Static_Coextension (N);
8045 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8047 -- Start of processing Mark_Coextensions
8050 case Nkind (Context_Nod) is
8051 when N_Assignment_Statement |
8052 N_Simple_Return_Statement =>
8053 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8055 when N_Object_Declaration =>
8056 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8058 -- This routine should not be called for constructs which may not
8059 -- contain coextensions.
8062 raise Program_Error;
8065 Mark_Allocators (Root_Nod);
8066 end Mark_Coextensions;
8068 ----------------------
8069 -- Needs_One_Actual --
8070 ----------------------
8072 function Needs_One_Actual (E : Entity_Id) return Boolean is
8076 if Ada_Version >= Ada_2005
8077 and then Present (First_Formal (E))
8079 Formal := Next_Formal (First_Formal (E));
8080 while Present (Formal) loop
8081 if No (Default_Value (Formal)) then
8085 Next_Formal (Formal);
8093 end Needs_One_Actual;
8095 ------------------------
8096 -- New_Copy_List_Tree --
8097 ------------------------
8099 function New_Copy_List_Tree (List : List_Id) return List_Id is
8104 if List = No_List then
8111 while Present (E) loop
8112 Append (New_Copy_Tree (E), NL);
8118 end New_Copy_List_Tree;
8124 use Atree.Unchecked_Access;
8125 use Atree_Private_Part;
8127 -- Our approach here requires a two pass traversal of the tree. The
8128 -- first pass visits all nodes that eventually will be copied looking
8129 -- for defining Itypes. If any defining Itypes are found, then they are
8130 -- copied, and an entry is added to the replacement map. In the second
8131 -- phase, the tree is copied, using the replacement map to replace any
8132 -- Itype references within the copied tree.
8134 -- The following hash tables are used if the Map supplied has more
8135 -- than hash threshhold entries to speed up access to the map. If
8136 -- there are fewer entries, then the map is searched sequentially
8137 -- (because setting up a hash table for only a few entries takes
8138 -- more time than it saves.
8140 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8141 -- Hash function used for hash operations
8147 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8149 return Nat (E) mod (NCT_Header_Num'Last + 1);
8156 -- The hash table NCT_Assoc associates old entities in the table
8157 -- with their corresponding new entities (i.e. the pairs of entries
8158 -- presented in the original Map argument are Key-Element pairs).
8160 package NCT_Assoc is new Simple_HTable (
8161 Header_Num => NCT_Header_Num,
8162 Element => Entity_Id,
8163 No_Element => Empty,
8165 Hash => New_Copy_Hash,
8166 Equal => Types."=");
8168 ---------------------
8169 -- NCT_Itype_Assoc --
8170 ---------------------
8172 -- The hash table NCT_Itype_Assoc contains entries only for those
8173 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8174 -- The key is the associated node, and the element is the new node
8175 -- itself (NOT the associated node for the new node).
8177 package NCT_Itype_Assoc is new Simple_HTable (
8178 Header_Num => NCT_Header_Num,
8179 Element => Entity_Id,
8180 No_Element => Empty,
8182 Hash => New_Copy_Hash,
8183 Equal => Types."=");
8185 -- Start of processing for New_Copy_Tree function
8187 function New_Copy_Tree
8189 Map : Elist_Id := No_Elist;
8190 New_Sloc : Source_Ptr := No_Location;
8191 New_Scope : Entity_Id := Empty) return Node_Id
8193 Actual_Map : Elist_Id := Map;
8194 -- This is the actual map for the copy. It is initialized with the
8195 -- given elements, and then enlarged as required for Itypes that are
8196 -- copied during the first phase of the copy operation. The visit
8197 -- procedures add elements to this map as Itypes are encountered.
8198 -- The reason we cannot use Map directly, is that it may well be
8199 -- (and normally is) initialized to No_Elist, and if we have mapped
8200 -- entities, we have to reset it to point to a real Elist.
8202 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8203 -- Called during second phase to map entities into their corresponding
8204 -- copies using Actual_Map. If the argument is not an entity, or is not
8205 -- in Actual_Map, then it is returned unchanged.
8207 procedure Build_NCT_Hash_Tables;
8208 -- Builds hash tables (number of elements >= threshold value)
8210 function Copy_Elist_With_Replacement
8211 (Old_Elist : Elist_Id) return Elist_Id;
8212 -- Called during second phase to copy element list doing replacements
8214 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8215 -- Called during the second phase to process a copied Itype. The actual
8216 -- copy happened during the first phase (so that we could make the entry
8217 -- in the mapping), but we still have to deal with the descendents of
8218 -- the copied Itype and copy them where necessary.
8220 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8221 -- Called during second phase to copy list doing replacements
8223 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8224 -- Called during second phase to copy node doing replacements
8226 procedure Visit_Elist (E : Elist_Id);
8227 -- Called during first phase to visit all elements of an Elist
8229 procedure Visit_Field (F : Union_Id; N : Node_Id);
8230 -- Visit a single field, recursing to call Visit_Node or Visit_List
8231 -- if the field is a syntactic descendent of the current node (i.e.
8232 -- its parent is Node N).
8234 procedure Visit_Itype (Old_Itype : Entity_Id);
8235 -- Called during first phase to visit subsidiary fields of a defining
8236 -- Itype, and also create a copy and make an entry in the replacement
8237 -- map for the new copy.
8239 procedure Visit_List (L : List_Id);
8240 -- Called during first phase to visit all elements of a List
8242 procedure Visit_Node (N : Node_Or_Entity_Id);
8243 -- Called during first phase to visit a node and all its subtrees
8249 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8254 if not Has_Extension (N) or else No (Actual_Map) then
8257 elsif NCT_Hash_Tables_Used then
8258 Ent := NCT_Assoc.Get (Entity_Id (N));
8260 if Present (Ent) then
8266 -- No hash table used, do serial search
8269 E := First_Elmt (Actual_Map);
8270 while Present (E) loop
8271 if Node (E) = N then
8272 return Node (Next_Elmt (E));
8274 E := Next_Elmt (Next_Elmt (E));
8282 ---------------------------
8283 -- Build_NCT_Hash_Tables --
8284 ---------------------------
8286 procedure Build_NCT_Hash_Tables is
8290 if NCT_Hash_Table_Setup then
8292 NCT_Itype_Assoc.Reset;
8295 Elmt := First_Elmt (Actual_Map);
8296 while Present (Elmt) loop
8299 -- Get new entity, and associate old and new
8302 NCT_Assoc.Set (Ent, Node (Elmt));
8304 if Is_Type (Ent) then
8306 Anode : constant Entity_Id :=
8307 Associated_Node_For_Itype (Ent);
8310 if Present (Anode) then
8312 -- Enter a link between the associated node of the
8313 -- old Itype and the new Itype, for updating later
8314 -- when node is copied.
8316 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8324 NCT_Hash_Tables_Used := True;
8325 NCT_Hash_Table_Setup := True;
8326 end Build_NCT_Hash_Tables;
8328 ---------------------------------
8329 -- Copy_Elist_With_Replacement --
8330 ---------------------------------
8332 function Copy_Elist_With_Replacement
8333 (Old_Elist : Elist_Id) return Elist_Id
8336 New_Elist : Elist_Id;
8339 if No (Old_Elist) then
8343 New_Elist := New_Elmt_List;
8345 M := First_Elmt (Old_Elist);
8346 while Present (M) loop
8347 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8353 end Copy_Elist_With_Replacement;
8355 ---------------------------------
8356 -- Copy_Itype_With_Replacement --
8357 ---------------------------------
8359 -- This routine exactly parallels its phase one analog Visit_Itype,
8361 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8363 -- Translate Next_Entity, Scope and Etype fields, in case they
8364 -- reference entities that have been mapped into copies.
8366 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8367 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8369 if Present (New_Scope) then
8370 Set_Scope (New_Itype, New_Scope);
8372 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8375 -- Copy referenced fields
8377 if Is_Discrete_Type (New_Itype) then
8378 Set_Scalar_Range (New_Itype,
8379 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8381 elsif Has_Discriminants (Base_Type (New_Itype)) then
8382 Set_Discriminant_Constraint (New_Itype,
8383 Copy_Elist_With_Replacement
8384 (Discriminant_Constraint (New_Itype)));
8386 elsif Is_Array_Type (New_Itype) then
8387 if Present (First_Index (New_Itype)) then
8388 Set_First_Index (New_Itype,
8389 First (Copy_List_With_Replacement
8390 (List_Containing (First_Index (New_Itype)))));
8393 if Is_Packed (New_Itype) then
8394 Set_Packed_Array_Type (New_Itype,
8395 Copy_Node_With_Replacement
8396 (Packed_Array_Type (New_Itype)));
8399 end Copy_Itype_With_Replacement;
8401 --------------------------------
8402 -- Copy_List_With_Replacement --
8403 --------------------------------
8405 function Copy_List_With_Replacement
8406 (Old_List : List_Id) return List_Id
8412 if Old_List = No_List then
8416 New_List := Empty_List;
8418 E := First (Old_List);
8419 while Present (E) loop
8420 Append (Copy_Node_With_Replacement (E), New_List);
8426 end Copy_List_With_Replacement;
8428 --------------------------------
8429 -- Copy_Node_With_Replacement --
8430 --------------------------------
8432 function Copy_Node_With_Replacement
8433 (Old_Node : Node_Id) return Node_Id
8437 procedure Adjust_Named_Associations
8438 (Old_Node : Node_Id;
8439 New_Node : Node_Id);
8440 -- If a call node has named associations, these are chained through
8441 -- the First_Named_Actual, Next_Named_Actual links. These must be
8442 -- propagated separately to the new parameter list, because these
8443 -- are not syntactic fields.
8445 function Copy_Field_With_Replacement
8446 (Field : Union_Id) return Union_Id;
8447 -- Given Field, which is a field of Old_Node, return a copy of it
8448 -- if it is a syntactic field (i.e. its parent is Node), setting
8449 -- the parent of the copy to poit to New_Node. Otherwise returns
8450 -- the field (possibly mapped if it is an entity).
8452 -------------------------------
8453 -- Adjust_Named_Associations --
8454 -------------------------------
8456 procedure Adjust_Named_Associations
8457 (Old_Node : Node_Id;
8467 Old_E := First (Parameter_Associations (Old_Node));
8468 New_E := First (Parameter_Associations (New_Node));
8469 while Present (Old_E) loop
8470 if Nkind (Old_E) = N_Parameter_Association
8471 and then Present (Next_Named_Actual (Old_E))
8473 if First_Named_Actual (Old_Node)
8474 = Explicit_Actual_Parameter (Old_E)
8476 Set_First_Named_Actual
8477 (New_Node, Explicit_Actual_Parameter (New_E));
8480 -- Now scan parameter list from the beginning,to locate
8481 -- next named actual, which can be out of order.
8483 Old_Next := First (Parameter_Associations (Old_Node));
8484 New_Next := First (Parameter_Associations (New_Node));
8486 while Nkind (Old_Next) /= N_Parameter_Association
8487 or else Explicit_Actual_Parameter (Old_Next)
8488 /= Next_Named_Actual (Old_E)
8494 Set_Next_Named_Actual
8495 (New_E, Explicit_Actual_Parameter (New_Next));
8501 end Adjust_Named_Associations;
8503 ---------------------------------
8504 -- Copy_Field_With_Replacement --
8505 ---------------------------------
8507 function Copy_Field_With_Replacement
8508 (Field : Union_Id) return Union_Id
8511 if Field = Union_Id (Empty) then
8514 elsif Field in Node_Range then
8516 Old_N : constant Node_Id := Node_Id (Field);
8520 -- If syntactic field, as indicated by the parent pointer
8521 -- being set, then copy the referenced node recursively.
8523 if Parent (Old_N) = Old_Node then
8524 New_N := Copy_Node_With_Replacement (Old_N);
8526 if New_N /= Old_N then
8527 Set_Parent (New_N, New_Node);
8530 -- For semantic fields, update possible entity reference
8531 -- from the replacement map.
8534 New_N := Assoc (Old_N);
8537 return Union_Id (New_N);
8540 elsif Field in List_Range then
8542 Old_L : constant List_Id := List_Id (Field);
8546 -- If syntactic field, as indicated by the parent pointer,
8547 -- then recursively copy the entire referenced list.
8549 if Parent (Old_L) = Old_Node then
8550 New_L := Copy_List_With_Replacement (Old_L);
8551 Set_Parent (New_L, New_Node);
8553 -- For semantic list, just returned unchanged
8559 return Union_Id (New_L);
8562 -- Anything other than a list or a node is returned unchanged
8567 end Copy_Field_With_Replacement;
8569 -- Start of processing for Copy_Node_With_Replacement
8572 if Old_Node <= Empty_Or_Error then
8575 elsif Has_Extension (Old_Node) then
8576 return Assoc (Old_Node);
8579 New_Node := New_Copy (Old_Node);
8581 -- If the node we are copying is the associated node of a
8582 -- previously copied Itype, then adjust the associated node
8583 -- of the copy of that Itype accordingly.
8585 if Present (Actual_Map) then
8591 -- Case of hash table used
8593 if NCT_Hash_Tables_Used then
8594 Ent := NCT_Itype_Assoc.Get (Old_Node);
8596 if Present (Ent) then
8597 Set_Associated_Node_For_Itype (Ent, New_Node);
8600 -- Case of no hash table used
8603 E := First_Elmt (Actual_Map);
8604 while Present (E) loop
8605 if Is_Itype (Node (E))
8607 Old_Node = Associated_Node_For_Itype (Node (E))
8609 Set_Associated_Node_For_Itype
8610 (Node (Next_Elmt (E)), New_Node);
8613 E := Next_Elmt (Next_Elmt (E));
8619 -- Recursively copy descendents
8622 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8624 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8626 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8628 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8630 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8632 -- Adjust Sloc of new node if necessary
8634 if New_Sloc /= No_Location then
8635 Set_Sloc (New_Node, New_Sloc);
8637 -- If we adjust the Sloc, then we are essentially making
8638 -- a completely new node, so the Comes_From_Source flag
8639 -- should be reset to the proper default value.
8641 Nodes.Table (New_Node).Comes_From_Source :=
8642 Default_Node.Comes_From_Source;
8645 -- If the node is call and has named associations,
8646 -- set the corresponding links in the copy.
8648 if (Nkind (Old_Node) = N_Function_Call
8649 or else Nkind (Old_Node) = N_Entry_Call_Statement
8651 Nkind (Old_Node) = N_Procedure_Call_Statement)
8652 and then Present (First_Named_Actual (Old_Node))
8654 Adjust_Named_Associations (Old_Node, New_Node);
8657 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8658 -- The replacement mechanism applies to entities, and is not used
8659 -- here. Eventually we may need a more general graph-copying
8660 -- routine. For now, do a sequential search to find desired node.
8662 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8663 and then Present (First_Real_Statement (Old_Node))
8666 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8670 N1 := First (Statements (Old_Node));
8671 N2 := First (Statements (New_Node));
8673 while N1 /= Old_F loop
8678 Set_First_Real_Statement (New_Node, N2);
8683 -- All done, return copied node
8686 end Copy_Node_With_Replacement;
8692 procedure Visit_Elist (E : Elist_Id) is
8696 Elmt := First_Elmt (E);
8698 while Elmt /= No_Elmt loop
8699 Visit_Node (Node (Elmt));
8709 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8711 if F = Union_Id (Empty) then
8714 elsif F in Node_Range then
8716 -- Copy node if it is syntactic, i.e. its parent pointer is
8717 -- set to point to the field that referenced it (certain
8718 -- Itypes will also meet this criterion, which is fine, since
8719 -- these are clearly Itypes that do need to be copied, since
8720 -- we are copying their parent.)
8722 if Parent (Node_Id (F)) = N then
8723 Visit_Node (Node_Id (F));
8726 -- Another case, if we are pointing to an Itype, then we want
8727 -- to copy it if its associated node is somewhere in the tree
8730 -- Note: the exclusion of self-referential copies is just an
8731 -- optimization, since the search of the already copied list
8732 -- would catch it, but it is a common case (Etype pointing
8733 -- to itself for an Itype that is a base type).
8735 elsif Has_Extension (Node_Id (F))
8736 and then Is_Itype (Entity_Id (F))
8737 and then Node_Id (F) /= N
8743 P := Associated_Node_For_Itype (Node_Id (F));
8744 while Present (P) loop
8746 Visit_Node (Node_Id (F));
8753 -- An Itype whose parent is not being copied definitely
8754 -- should NOT be copied, since it does not belong in any
8755 -- sense to the copied subtree.
8761 elsif F in List_Range
8762 and then Parent (List_Id (F)) = N
8764 Visit_List (List_Id (F));
8773 procedure Visit_Itype (Old_Itype : Entity_Id) is
8774 New_Itype : Entity_Id;
8779 -- Itypes that describe the designated type of access to subprograms
8780 -- have the structure of subprogram declarations, with signatures,
8781 -- etc. Either we duplicate the signatures completely, or choose to
8782 -- share such itypes, which is fine because their elaboration will
8783 -- have no side effects.
8785 if Ekind (Old_Itype) = E_Subprogram_Type then
8789 New_Itype := New_Copy (Old_Itype);
8791 -- The new Itype has all the attributes of the old one, and
8792 -- we just copy the contents of the entity. However, the back-end
8793 -- needs different names for debugging purposes, so we create a
8794 -- new internal name for it in all cases.
8796 Set_Chars (New_Itype, New_Internal_Name ('T'));
8798 -- If our associated node is an entity that has already been copied,
8799 -- then set the associated node of the copy to point to the right
8800 -- copy. If we have copied an Itype that is itself the associated
8801 -- node of some previously copied Itype, then we set the right
8802 -- pointer in the other direction.
8804 if Present (Actual_Map) then
8806 -- Case of hash tables used
8808 if NCT_Hash_Tables_Used then
8810 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8812 if Present (Ent) then
8813 Set_Associated_Node_For_Itype (New_Itype, Ent);
8816 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8817 if Present (Ent) then
8818 Set_Associated_Node_For_Itype (Ent, New_Itype);
8820 -- If the hash table has no association for this Itype and
8821 -- its associated node, enter one now.
8825 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8828 -- Case of hash tables not used
8831 E := First_Elmt (Actual_Map);
8832 while Present (E) loop
8833 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8834 Set_Associated_Node_For_Itype
8835 (New_Itype, Node (Next_Elmt (E)));
8838 if Is_Type (Node (E))
8840 Old_Itype = Associated_Node_For_Itype (Node (E))
8842 Set_Associated_Node_For_Itype
8843 (Node (Next_Elmt (E)), New_Itype);
8846 E := Next_Elmt (Next_Elmt (E));
8851 if Present (Freeze_Node (New_Itype)) then
8852 Set_Is_Frozen (New_Itype, False);
8853 Set_Freeze_Node (New_Itype, Empty);
8856 -- Add new association to map
8858 if No (Actual_Map) then
8859 Actual_Map := New_Elmt_List;
8862 Append_Elmt (Old_Itype, Actual_Map);
8863 Append_Elmt (New_Itype, Actual_Map);
8865 if NCT_Hash_Tables_Used then
8866 NCT_Assoc.Set (Old_Itype, New_Itype);
8869 NCT_Table_Entries := NCT_Table_Entries + 1;
8871 if NCT_Table_Entries > NCT_Hash_Threshhold then
8872 Build_NCT_Hash_Tables;
8876 -- If a record subtype is simply copied, the entity list will be
8877 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8879 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
8880 Set_Cloned_Subtype (New_Itype, Old_Itype);
8883 -- Visit descendents that eventually get copied
8885 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8887 if Is_Discrete_Type (Old_Itype) then
8888 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8890 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8891 -- ??? This should involve call to Visit_Field
8892 Visit_Elist (Discriminant_Constraint (Old_Itype));
8894 elsif Is_Array_Type (Old_Itype) then
8895 if Present (First_Index (Old_Itype)) then
8896 Visit_Field (Union_Id (List_Containing
8897 (First_Index (Old_Itype))),
8901 if Is_Packed (Old_Itype) then
8902 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8912 procedure Visit_List (L : List_Id) is
8915 if L /= No_List then
8918 while Present (N) loop
8929 procedure Visit_Node (N : Node_Or_Entity_Id) is
8931 -- Start of processing for Visit_Node
8934 -- Handle case of an Itype, which must be copied
8936 if Has_Extension (N)
8937 and then Is_Itype (N)
8939 -- Nothing to do if already in the list. This can happen with an
8940 -- Itype entity that appears more than once in the tree.
8941 -- Note that we do not want to visit descendents in this case.
8943 -- Test for already in list when hash table is used
8945 if NCT_Hash_Tables_Used then
8946 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8950 -- Test for already in list when hash table not used
8956 if Present (Actual_Map) then
8957 E := First_Elmt (Actual_Map);
8958 while Present (E) loop
8959 if Node (E) = N then
8962 E := Next_Elmt (Next_Elmt (E));
8972 -- Visit descendents
8974 Visit_Field (Field1 (N), N);
8975 Visit_Field (Field2 (N), N);
8976 Visit_Field (Field3 (N), N);
8977 Visit_Field (Field4 (N), N);
8978 Visit_Field (Field5 (N), N);
8981 -- Start of processing for New_Copy_Tree
8986 -- See if we should use hash table
8988 if No (Actual_Map) then
8989 NCT_Hash_Tables_Used := False;
8996 NCT_Table_Entries := 0;
8998 Elmt := First_Elmt (Actual_Map);
8999 while Present (Elmt) loop
9000 NCT_Table_Entries := NCT_Table_Entries + 1;
9005 if NCT_Table_Entries > NCT_Hash_Threshhold then
9006 Build_NCT_Hash_Tables;
9008 NCT_Hash_Tables_Used := False;
9013 -- Hash table set up if required, now start phase one by visiting
9014 -- top node (we will recursively visit the descendents).
9016 Visit_Node (Source);
9018 -- Now the second phase of the copy can start. First we process
9019 -- all the mapped entities, copying their descendents.
9021 if Present (Actual_Map) then
9024 New_Itype : Entity_Id;
9026 Elmt := First_Elmt (Actual_Map);
9027 while Present (Elmt) loop
9029 New_Itype := Node (Elmt);
9030 Copy_Itype_With_Replacement (New_Itype);
9036 -- Now we can copy the actual tree
9038 return Copy_Node_With_Replacement (Source);
9041 -------------------------
9042 -- New_External_Entity --
9043 -------------------------
9045 function New_External_Entity
9046 (Kind : Entity_Kind;
9047 Scope_Id : Entity_Id;
9048 Sloc_Value : Source_Ptr;
9049 Related_Id : Entity_Id;
9051 Suffix_Index : Nat := 0;
9052 Prefix : Character := ' ') return Entity_Id
9054 N : constant Entity_Id :=
9055 Make_Defining_Identifier (Sloc_Value,
9057 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9060 Set_Ekind (N, Kind);
9061 Set_Is_Internal (N, True);
9062 Append_Entity (N, Scope_Id);
9063 Set_Public_Status (N);
9065 if Kind in Type_Kind then
9066 Init_Size_Align (N);
9070 end New_External_Entity;
9072 -------------------------
9073 -- New_Internal_Entity --
9074 -------------------------
9076 function New_Internal_Entity
9077 (Kind : Entity_Kind;
9078 Scope_Id : Entity_Id;
9079 Sloc_Value : Source_Ptr;
9080 Id_Char : Character) return Entity_Id
9082 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9085 Set_Ekind (N, Kind);
9086 Set_Is_Internal (N, True);
9087 Append_Entity (N, Scope_Id);
9089 if Kind in Type_Kind then
9090 Init_Size_Align (N);
9094 end New_Internal_Entity;
9100 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9104 -- If we are pointing at a positional parameter, it is a member of a
9105 -- node list (the list of parameters), and the next parameter is the
9106 -- next node on the list, unless we hit a parameter association, then
9107 -- we shift to using the chain whose head is the First_Named_Actual in
9108 -- the parent, and then is threaded using the Next_Named_Actual of the
9109 -- Parameter_Association. All this fiddling is because the original node
9110 -- list is in the textual call order, and what we need is the
9111 -- declaration order.
9113 if Is_List_Member (Actual_Id) then
9114 N := Next (Actual_Id);
9116 if Nkind (N) = N_Parameter_Association then
9117 return First_Named_Actual (Parent (Actual_Id));
9123 return Next_Named_Actual (Parent (Actual_Id));
9127 procedure Next_Actual (Actual_Id : in out Node_Id) is
9129 Actual_Id := Next_Actual (Actual_Id);
9132 -----------------------
9133 -- Normalize_Actuals --
9134 -----------------------
9136 -- Chain actuals according to formals of subprogram. If there are no named
9137 -- associations, the chain is simply the list of Parameter Associations,
9138 -- since the order is the same as the declaration order. If there are named
9139 -- associations, then the First_Named_Actual field in the N_Function_Call
9140 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9141 -- node for the parameter that comes first in declaration order. The
9142 -- remaining named parameters are then chained in declaration order using
9143 -- Next_Named_Actual.
9145 -- This routine also verifies that the number of actuals is compatible with
9146 -- the number and default values of formals, but performs no type checking
9147 -- (type checking is done by the caller).
9149 -- If the matching succeeds, Success is set to True and the caller proceeds
9150 -- with type-checking. If the match is unsuccessful, then Success is set to
9151 -- False, and the caller attempts a different interpretation, if there is
9154 -- If the flag Report is on, the call is not overloaded, and a failure to
9155 -- match can be reported here, rather than in the caller.
9157 procedure Normalize_Actuals
9161 Success : out Boolean)
9163 Actuals : constant List_Id := Parameter_Associations (N);
9164 Actual : Node_Id := Empty;
9166 Last : Node_Id := Empty;
9167 First_Named : Node_Id := Empty;
9170 Formals_To_Match : Integer := 0;
9171 Actuals_To_Match : Integer := 0;
9173 procedure Chain (A : Node_Id);
9174 -- Add named actual at the proper place in the list, using the
9175 -- Next_Named_Actual link.
9177 function Reporting return Boolean;
9178 -- Determines if an error is to be reported. To report an error, we
9179 -- need Report to be True, and also we do not report errors caused
9180 -- by calls to init procs that occur within other init procs. Such
9181 -- errors must always be cascaded errors, since if all the types are
9182 -- declared correctly, the compiler will certainly build decent calls!
9188 procedure Chain (A : Node_Id) is
9192 -- Call node points to first actual in list
9194 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9197 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9201 Set_Next_Named_Actual (Last, Empty);
9208 function Reporting return Boolean is
9213 elsif not Within_Init_Proc then
9216 elsif Is_Init_Proc (Entity (Name (N))) then
9224 -- Start of processing for Normalize_Actuals
9227 if Is_Access_Type (S) then
9229 -- The name in the call is a function call that returns an access
9230 -- to subprogram. The designated type has the list of formals.
9232 Formal := First_Formal (Designated_Type (S));
9234 Formal := First_Formal (S);
9237 while Present (Formal) loop
9238 Formals_To_Match := Formals_To_Match + 1;
9239 Next_Formal (Formal);
9242 -- Find if there is a named association, and verify that no positional
9243 -- associations appear after named ones.
9245 if Present (Actuals) then
9246 Actual := First (Actuals);
9249 while Present (Actual)
9250 and then Nkind (Actual) /= N_Parameter_Association
9252 Actuals_To_Match := Actuals_To_Match + 1;
9256 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9258 -- Most common case: positional notation, no defaults
9263 elsif Actuals_To_Match > Formals_To_Match then
9265 -- Too many actuals: will not work
9268 if Is_Entity_Name (Name (N)) then
9269 Error_Msg_N ("too many arguments in call to&", Name (N));
9271 Error_Msg_N ("too many arguments in call", N);
9279 First_Named := Actual;
9281 while Present (Actual) loop
9282 if Nkind (Actual) /= N_Parameter_Association then
9284 ("positional parameters not allowed after named ones", Actual);
9289 Actuals_To_Match := Actuals_To_Match + 1;
9295 if Present (Actuals) then
9296 Actual := First (Actuals);
9299 Formal := First_Formal (S);
9300 while Present (Formal) loop
9302 -- Match the formals in order. If the corresponding actual is
9303 -- positional, nothing to do. Else scan the list of named actuals
9304 -- to find the one with the right name.
9307 and then Nkind (Actual) /= N_Parameter_Association
9310 Actuals_To_Match := Actuals_To_Match - 1;
9311 Formals_To_Match := Formals_To_Match - 1;
9314 -- For named parameters, search the list of actuals to find
9315 -- one that matches the next formal name.
9317 Actual := First_Named;
9319 while Present (Actual) loop
9320 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9323 Actuals_To_Match := Actuals_To_Match - 1;
9324 Formals_To_Match := Formals_To_Match - 1;
9332 if Ekind (Formal) /= E_In_Parameter
9333 or else No (Default_Value (Formal))
9336 if (Comes_From_Source (S)
9337 or else Sloc (S) = Standard_Location)
9338 and then Is_Overloadable (S)
9342 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9344 (Nkind (Parent (N)) = N_Function_Call
9346 Nkind (Parent (N)) = N_Parameter_Association))
9347 and then Ekind (S) /= E_Function
9349 Set_Etype (N, Etype (S));
9351 Error_Msg_Name_1 := Chars (S);
9352 Error_Msg_Sloc := Sloc (S);
9354 ("missing argument for parameter & " &
9355 "in call to % declared #", N, Formal);
9358 elsif Is_Overloadable (S) then
9359 Error_Msg_Name_1 := Chars (S);
9361 -- Point to type derivation that generated the
9364 Error_Msg_Sloc := Sloc (Parent (S));
9367 ("missing argument for parameter & " &
9368 "in call to % (inherited) #", N, Formal);
9372 ("missing argument for parameter &", N, Formal);
9380 Formals_To_Match := Formals_To_Match - 1;
9385 Next_Formal (Formal);
9388 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9395 -- Find some superfluous named actual that did not get
9396 -- attached to the list of associations.
9398 Actual := First (Actuals);
9399 while Present (Actual) loop
9400 if Nkind (Actual) = N_Parameter_Association
9401 and then Actual /= Last
9402 and then No (Next_Named_Actual (Actual))
9404 Error_Msg_N ("unmatched actual & in call",
9405 Selector_Name (Actual));
9416 end Normalize_Actuals;
9418 --------------------------------
9419 -- Note_Possible_Modification --
9420 --------------------------------
9422 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9423 Modification_Comes_From_Source : constant Boolean :=
9424 Comes_From_Source (Parent (N));
9430 -- Loop to find referenced entity, if there is one
9437 if Is_Entity_Name (Exp) then
9438 Ent := Entity (Exp);
9440 -- If the entity is missing, it is an undeclared identifier,
9441 -- and there is nothing to annotate.
9447 elsif Nkind (Exp) = N_Explicit_Dereference then
9449 P : constant Node_Id := Prefix (Exp);
9452 if Nkind (P) = N_Selected_Component
9454 Entry_Formal (Entity (Selector_Name (P))))
9456 -- Case of a reference to an entry formal
9458 Ent := Entry_Formal (Entity (Selector_Name (P)));
9460 elsif Nkind (P) = N_Identifier
9461 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9462 and then Present (Expression (Parent (Entity (P))))
9463 and then Nkind (Expression (Parent (Entity (P))))
9466 -- Case of a reference to a value on which side effects have
9469 Exp := Prefix (Expression (Parent (Entity (P))));
9478 elsif Nkind (Exp) = N_Type_Conversion
9479 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9481 Exp := Expression (Exp);
9484 elsif Nkind (Exp) = N_Slice
9485 or else Nkind (Exp) = N_Indexed_Component
9486 or else Nkind (Exp) = N_Selected_Component
9488 Exp := Prefix (Exp);
9495 -- Now look for entity being referenced
9497 if Present (Ent) then
9498 if Is_Object (Ent) then
9499 if Comes_From_Source (Exp)
9500 or else Modification_Comes_From_Source
9502 -- Give warning if pragma unmodified given and we are
9503 -- sure this is a modification.
9505 if Has_Pragma_Unmodified (Ent) and then Sure then
9506 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9509 Set_Never_Set_In_Source (Ent, False);
9512 Set_Is_True_Constant (Ent, False);
9513 Set_Current_Value (Ent, Empty);
9514 Set_Is_Known_Null (Ent, False);
9516 if not Can_Never_Be_Null (Ent) then
9517 Set_Is_Known_Non_Null (Ent, False);
9520 -- Follow renaming chain
9522 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9523 and then Present (Renamed_Object (Ent))
9525 Exp := Renamed_Object (Ent);
9529 -- Generate a reference only if the assignment comes from
9530 -- source. This excludes, for example, calls to a dispatching
9531 -- assignment operation when the left-hand side is tagged.
9533 if Modification_Comes_From_Source then
9534 Generate_Reference (Ent, Exp, 'm');
9537 Check_Nested_Access (Ent);
9542 -- If we are sure this is a modification from source, and we know
9543 -- this modifies a constant, then give an appropriate warning.
9545 if Overlays_Constant (Ent)
9546 and then Modification_Comes_From_Source
9550 A : constant Node_Id := Address_Clause (Ent);
9554 Exp : constant Node_Id := Expression (A);
9556 if Nkind (Exp) = N_Attribute_Reference
9557 and then Attribute_Name (Exp) = Name_Address
9558 and then Is_Entity_Name (Prefix (Exp))
9560 Error_Msg_Sloc := Sloc (A);
9562 ("constant& may be modified via address clause#?",
9563 N, Entity (Prefix (Exp)));
9573 end Note_Possible_Modification;
9575 -------------------------
9576 -- Object_Access_Level --
9577 -------------------------
9579 function Object_Access_Level (Obj : Node_Id) return Uint is
9582 -- Returns the static accessibility level of the view denoted by Obj. Note
9583 -- that the value returned is the result of a call to Scope_Depth. Only
9584 -- scope depths associated with dynamic scopes can actually be returned.
9585 -- Since only relative levels matter for accessibility checking, the fact
9586 -- that the distance between successive levels of accessibility is not
9587 -- always one is immaterial (invariant: if level(E2) is deeper than
9588 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9590 function Reference_To (Obj : Node_Id) return Node_Id;
9591 -- An explicit dereference is created when removing side-effects from
9592 -- expressions for constraint checking purposes. In this case a local
9593 -- access type is created for it. The correct access level is that of
9594 -- the original source node. We detect this case by noting that the
9595 -- prefix of the dereference is created by an object declaration whose
9596 -- initial expression is a reference.
9602 function Reference_To (Obj : Node_Id) return Node_Id is
9603 Pref : constant Node_Id := Prefix (Obj);
9605 if Is_Entity_Name (Pref)
9606 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9607 and then Present (Expression (Parent (Entity (Pref))))
9608 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9610 return (Prefix (Expression (Parent (Entity (Pref)))));
9616 -- Start of processing for Object_Access_Level
9619 if Is_Entity_Name (Obj) then
9622 if Is_Prival (E) then
9623 E := Prival_Link (E);
9626 -- If E is a type then it denotes a current instance. For this case
9627 -- we add one to the normal accessibility level of the type to ensure
9628 -- that current instances are treated as always being deeper than
9629 -- than the level of any visible named access type (see 3.10.2(21)).
9632 return Type_Access_Level (E) + 1;
9634 elsif Present (Renamed_Object (E)) then
9635 return Object_Access_Level (Renamed_Object (E));
9637 -- Similarly, if E is a component of the current instance of a
9638 -- protected type, any instance of it is assumed to be at a deeper
9639 -- level than the type. For a protected object (whose type is an
9640 -- anonymous protected type) its components are at the same level
9641 -- as the type itself.
9643 elsif not Is_Overloadable (E)
9644 and then Ekind (Scope (E)) = E_Protected_Type
9645 and then Comes_From_Source (Scope (E))
9647 return Type_Access_Level (Scope (E)) + 1;
9650 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9653 elsif Nkind (Obj) = N_Selected_Component then
9654 if Is_Access_Type (Etype (Prefix (Obj))) then
9655 return Type_Access_Level (Etype (Prefix (Obj)));
9657 return Object_Access_Level (Prefix (Obj));
9660 elsif Nkind (Obj) = N_Indexed_Component then
9661 if Is_Access_Type (Etype (Prefix (Obj))) then
9662 return Type_Access_Level (Etype (Prefix (Obj)));
9664 return Object_Access_Level (Prefix (Obj));
9667 elsif Nkind (Obj) = N_Explicit_Dereference then
9669 -- If the prefix is a selected access discriminant then we make a
9670 -- recursive call on the prefix, which will in turn check the level
9671 -- of the prefix object of the selected discriminant.
9673 if Nkind (Prefix (Obj)) = N_Selected_Component
9674 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9676 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9678 return Object_Access_Level (Prefix (Obj));
9680 elsif not (Comes_From_Source (Obj)) then
9682 Ref : constant Node_Id := Reference_To (Obj);
9684 if Present (Ref) then
9685 return Object_Access_Level (Ref);
9687 return Type_Access_Level (Etype (Prefix (Obj)));
9692 return Type_Access_Level (Etype (Prefix (Obj)));
9695 elsif Nkind (Obj) = N_Type_Conversion
9696 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9698 return Object_Access_Level (Expression (Obj));
9700 elsif Nkind (Obj) = N_Function_Call then
9702 -- Function results are objects, so we get either the access level of
9703 -- the function or, in the case of an indirect call, the level of the
9704 -- access-to-subprogram type. (This code is used for Ada 95, but it
9705 -- looks wrong, because it seems that we should be checking the level
9706 -- of the call itself, even for Ada 95. However, using the Ada 2005
9707 -- version of the code causes regressions in several tests that are
9708 -- compiled with -gnat95. ???)
9710 if Ada_Version < Ada_2005 then
9711 if Is_Entity_Name (Name (Obj)) then
9712 return Subprogram_Access_Level (Entity (Name (Obj)));
9714 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9717 -- For Ada 2005, the level of the result object of a function call is
9718 -- defined to be the level of the call's innermost enclosing master.
9719 -- We determine that by querying the depth of the innermost enclosing
9723 Return_Master_Scope_Depth_Of_Call : declare
9725 function Innermost_Master_Scope_Depth
9726 (N : Node_Id) return Uint;
9727 -- Returns the scope depth of the given node's innermost
9728 -- enclosing dynamic scope (effectively the accessibility
9729 -- level of the innermost enclosing master).
9731 ----------------------------------
9732 -- Innermost_Master_Scope_Depth --
9733 ----------------------------------
9735 function Innermost_Master_Scope_Depth
9736 (N : Node_Id) return Uint
9738 Node_Par : Node_Id := Parent (N);
9741 -- Locate the nearest enclosing node (by traversing Parents)
9742 -- that Defining_Entity can be applied to, and return the
9743 -- depth of that entity's nearest enclosing dynamic scope.
9745 while Present (Node_Par) loop
9746 case Nkind (Node_Par) is
9747 when N_Component_Declaration |
9748 N_Entry_Declaration |
9749 N_Formal_Object_Declaration |
9750 N_Formal_Type_Declaration |
9751 N_Full_Type_Declaration |
9752 N_Incomplete_Type_Declaration |
9753 N_Loop_Parameter_Specification |
9754 N_Object_Declaration |
9755 N_Protected_Type_Declaration |
9756 N_Private_Extension_Declaration |
9757 N_Private_Type_Declaration |
9758 N_Subtype_Declaration |
9759 N_Function_Specification |
9760 N_Procedure_Specification |
9761 N_Task_Type_Declaration |
9763 N_Generic_Instantiation |
9765 N_Implicit_Label_Declaration |
9766 N_Package_Declaration |
9767 N_Single_Task_Declaration |
9768 N_Subprogram_Declaration |
9769 N_Generic_Declaration |
9770 N_Renaming_Declaration |
9772 N_Formal_Subprogram_Declaration |
9773 N_Abstract_Subprogram_Declaration |
9775 N_Exception_Declaration |
9776 N_Formal_Package_Declaration |
9777 N_Number_Declaration |
9778 N_Package_Specification |
9779 N_Parameter_Specification |
9780 N_Single_Protected_Declaration |
9784 (Nearest_Dynamic_Scope
9785 (Defining_Entity (Node_Par)));
9791 Node_Par := Parent (Node_Par);
9794 pragma Assert (False);
9796 -- Should never reach the following return
9798 return Scope_Depth (Current_Scope) + 1;
9799 end Innermost_Master_Scope_Depth;
9801 -- Start of processing for Return_Master_Scope_Depth_Of_Call
9804 return Innermost_Master_Scope_Depth (Obj);
9805 end Return_Master_Scope_Depth_Of_Call;
9808 -- For convenience we handle qualified expressions, even though
9809 -- they aren't technically object names.
9811 elsif Nkind (Obj) = N_Qualified_Expression then
9812 return Object_Access_Level (Expression (Obj));
9814 -- Otherwise return the scope level of Standard.
9815 -- (If there are cases that fall through
9816 -- to this point they will be treated as
9817 -- having global accessibility for now. ???)
9820 return Scope_Depth (Standard_Standard);
9822 end Object_Access_Level;
9824 --------------------------------------
9825 -- Original_Corresponding_Operation --
9826 --------------------------------------
9828 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
9830 Typ : constant Entity_Id := Find_Dispatching_Type (S);
9833 -- If S is an inherited primitive S2 the original corresponding
9834 -- operation of S is the original corresponding operation of S2
9836 if Present (Alias (S))
9837 and then Find_Dispatching_Type (Alias (S)) /= Typ
9839 return Original_Corresponding_Operation (Alias (S));
9841 -- If S overrides an inherted subprogram S2 the original corresponding
9842 -- operation of S is the original corresponding operation of S2
9844 elsif Is_Overriding_Operation (S)
9845 and then Present (Overridden_Operation (S))
9847 return Original_Corresponding_Operation (Overridden_Operation (S));
9849 -- otherwise it is S itself
9854 end Original_Corresponding_Operation;
9856 -----------------------
9857 -- Private_Component --
9858 -----------------------
9860 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9861 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9863 function Trace_Components
9865 Check : Boolean) return Entity_Id;
9866 -- Recursive function that does the work, and checks against circular
9867 -- definition for each subcomponent type.
9869 ----------------------
9870 -- Trace_Components --
9871 ----------------------
9873 function Trace_Components
9875 Check : Boolean) return Entity_Id
9877 Btype : constant Entity_Id := Base_Type (T);
9878 Component : Entity_Id;
9880 Candidate : Entity_Id := Empty;
9883 if Check and then Btype = Ancestor then
9884 Error_Msg_N ("circular type definition", Type_Id);
9888 if Is_Private_Type (Btype)
9889 and then not Is_Generic_Type (Btype)
9891 if Present (Full_View (Btype))
9892 and then Is_Record_Type (Full_View (Btype))
9893 and then not Is_Frozen (Btype)
9895 -- To indicate that the ancestor depends on a private type, the
9896 -- current Btype is sufficient. However, to check for circular
9897 -- definition we must recurse on the full view.
9899 Candidate := Trace_Components (Full_View (Btype), True);
9901 if Candidate = Any_Type then
9911 elsif Is_Array_Type (Btype) then
9912 return Trace_Components (Component_Type (Btype), True);
9914 elsif Is_Record_Type (Btype) then
9915 Component := First_Entity (Btype);
9916 while Present (Component) loop
9918 -- Skip anonymous types generated by constrained components
9920 if not Is_Type (Component) then
9921 P := Trace_Components (Etype (Component), True);
9924 if P = Any_Type then
9932 Next_Entity (Component);
9940 end Trace_Components;
9942 -- Start of processing for Private_Component
9945 return Trace_Components (Type_Id, False);
9946 end Private_Component;
9948 ---------------------------
9949 -- Primitive_Names_Match --
9950 ---------------------------
9952 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9954 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9955 -- Given an internal name, returns the corresponding non-internal name
9957 ------------------------
9958 -- Non_Internal_Name --
9959 ------------------------
9961 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9963 Get_Name_String (Chars (E));
9964 Name_Len := Name_Len - 1;
9966 end Non_Internal_Name;
9968 -- Start of processing for Primitive_Names_Match
9971 pragma Assert (Present (E1) and then Present (E2));
9973 return Chars (E1) = Chars (E2)
9975 (not Is_Internal_Name (Chars (E1))
9976 and then Is_Internal_Name (Chars (E2))
9977 and then Non_Internal_Name (E2) = Chars (E1))
9979 (not Is_Internal_Name (Chars (E2))
9980 and then Is_Internal_Name (Chars (E1))
9981 and then Non_Internal_Name (E1) = Chars (E2))
9983 (Is_Predefined_Dispatching_Operation (E1)
9984 and then Is_Predefined_Dispatching_Operation (E2)
9985 and then Same_TSS (E1, E2))
9987 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9988 end Primitive_Names_Match;
9990 -----------------------
9991 -- Process_End_Label --
9992 -----------------------
9994 procedure Process_End_Label
10003 Label_Ref : Boolean;
10004 -- Set True if reference to end label itself is required
10007 -- Gets set to the operator symbol or identifier that references the
10008 -- entity Ent. For the child unit case, this is the identifier from the
10009 -- designator. For other cases, this is simply Endl.
10011 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10012 -- N is an identifier node that appears as a parent unit reference in
10013 -- the case where Ent is a child unit. This procedure generates an
10014 -- appropriate cross-reference entry. E is the corresponding entity.
10016 -------------------------
10017 -- Generate_Parent_Ref --
10018 -------------------------
10020 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10022 -- If names do not match, something weird, skip reference
10024 if Chars (E) = Chars (N) then
10026 -- Generate the reference. We do NOT consider this as a reference
10027 -- for unreferenced symbol purposes.
10029 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10031 if Style_Check then
10032 Style.Check_Identifier (N, E);
10035 end Generate_Parent_Ref;
10037 -- Start of processing for Process_End_Label
10040 -- If no node, ignore. This happens in some error situations, and
10041 -- also for some internally generated structures where no end label
10042 -- references are required in any case.
10048 -- Nothing to do if no End_Label, happens for internally generated
10049 -- constructs where we don't want an end label reference anyway. Also
10050 -- nothing to do if Endl is a string literal, which means there was
10051 -- some prior error (bad operator symbol)
10053 Endl := End_Label (N);
10055 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10059 -- Reference node is not in extended main source unit
10061 if not In_Extended_Main_Source_Unit (N) then
10063 -- Generally we do not collect references except for the extended
10064 -- main source unit. The one exception is the 'e' entry for a
10065 -- package spec, where it is useful for a client to have the
10066 -- ending information to define scopes.
10072 Label_Ref := False;
10074 -- For this case, we can ignore any parent references, but we
10075 -- need the package name itself for the 'e' entry.
10077 if Nkind (Endl) = N_Designator then
10078 Endl := Identifier (Endl);
10082 -- Reference is in extended main source unit
10087 -- For designator, generate references for the parent entries
10089 if Nkind (Endl) = N_Designator then
10091 -- Generate references for the prefix if the END line comes from
10092 -- source (otherwise we do not need these references) We climb the
10093 -- scope stack to find the expected entities.
10095 if Comes_From_Source (Endl) then
10096 Nam := Name (Endl);
10097 Scop := Current_Scope;
10098 while Nkind (Nam) = N_Selected_Component loop
10099 Scop := Scope (Scop);
10100 exit when No (Scop);
10101 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10102 Nam := Prefix (Nam);
10105 if Present (Scop) then
10106 Generate_Parent_Ref (Nam, Scope (Scop));
10110 Endl := Identifier (Endl);
10114 -- If the end label is not for the given entity, then either we have
10115 -- some previous error, or this is a generic instantiation for which
10116 -- we do not need to make a cross-reference in this case anyway. In
10117 -- either case we simply ignore the call.
10119 if Chars (Ent) /= Chars (Endl) then
10123 -- If label was really there, then generate a normal reference and then
10124 -- adjust the location in the end label to point past the name (which
10125 -- should almost always be the semicolon).
10127 Loc := Sloc (Endl);
10129 if Comes_From_Source (Endl) then
10131 -- If a label reference is required, then do the style check and
10132 -- generate an l-type cross-reference entry for the label
10135 if Style_Check then
10136 Style.Check_Identifier (Endl, Ent);
10139 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10142 -- Set the location to point past the label (normally this will
10143 -- mean the semicolon immediately following the label). This is
10144 -- done for the sake of the 'e' or 't' entry generated below.
10146 Get_Decoded_Name_String (Chars (Endl));
10147 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10150 -- Now generate the e/t reference
10152 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10154 -- Restore Sloc, in case modified above, since we have an identifier
10155 -- and the normal Sloc should be left set in the tree.
10157 Set_Sloc (Endl, Loc);
10158 end Process_End_Label;
10160 ------------------------------------
10161 -- References_Generic_Formal_Type --
10162 ------------------------------------
10164 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10166 function Process (N : Node_Id) return Traverse_Result;
10167 -- Process one node in search for generic formal type
10173 function Process (N : Node_Id) return Traverse_Result is
10175 if Nkind (N) in N_Has_Entity then
10177 E : constant Entity_Id := Entity (N);
10179 if Present (E) then
10180 if Is_Generic_Type (E) then
10182 elsif Present (Etype (E))
10183 and then Is_Generic_Type (Etype (E))
10194 function Traverse is new Traverse_Func (Process);
10195 -- Traverse tree to look for generic type
10198 if Inside_A_Generic then
10199 return Traverse (N) = Abandon;
10203 end References_Generic_Formal_Type;
10205 --------------------
10206 -- Remove_Homonym --
10207 --------------------
10209 procedure Remove_Homonym (E : Entity_Id) is
10210 Prev : Entity_Id := Empty;
10214 if E = Current_Entity (E) then
10215 if Present (Homonym (E)) then
10216 Set_Current_Entity (Homonym (E));
10218 Set_Name_Entity_Id (Chars (E), Empty);
10221 H := Current_Entity (E);
10222 while Present (H) and then H /= E loop
10227 Set_Homonym (Prev, Homonym (E));
10229 end Remove_Homonym;
10231 ---------------------
10232 -- Rep_To_Pos_Flag --
10233 ---------------------
10235 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10237 return New_Occurrence_Of
10238 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10239 end Rep_To_Pos_Flag;
10241 --------------------
10242 -- Require_Entity --
10243 --------------------
10245 procedure Require_Entity (N : Node_Id) is
10247 if Is_Entity_Name (N) and then No (Entity (N)) then
10248 if Total_Errors_Detected /= 0 then
10249 Set_Entity (N, Any_Id);
10251 raise Program_Error;
10254 end Require_Entity;
10256 ------------------------------
10257 -- Requires_Transient_Scope --
10258 ------------------------------
10260 -- A transient scope is required when variable-sized temporaries are
10261 -- allocated in the primary or secondary stack, or when finalization
10262 -- actions must be generated before the next instruction.
10264 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10265 Typ : constant Entity_Id := Underlying_Type (Id);
10267 -- Start of processing for Requires_Transient_Scope
10270 -- This is a private type which is not completed yet. This can only
10271 -- happen in a default expression (of a formal parameter or of a
10272 -- record component). Do not expand transient scope in this case
10277 -- Do not expand transient scope for non-existent procedure return
10279 elsif Typ = Standard_Void_Type then
10282 -- Elementary types do not require a transient scope
10284 elsif Is_Elementary_Type (Typ) then
10287 -- Generally, indefinite subtypes require a transient scope, since the
10288 -- back end cannot generate temporaries, since this is not a valid type
10289 -- for declaring an object. It might be possible to relax this in the
10290 -- future, e.g. by declaring the maximum possible space for the type.
10292 elsif Is_Indefinite_Subtype (Typ) then
10295 -- Functions returning tagged types may dispatch on result so their
10296 -- returned value is allocated on the secondary stack. Controlled
10297 -- type temporaries need finalization.
10299 elsif Is_Tagged_Type (Typ)
10300 or else Has_Controlled_Component (Typ)
10302 return not Is_Value_Type (Typ);
10306 elsif Is_Record_Type (Typ) then
10310 Comp := First_Entity (Typ);
10311 while Present (Comp) loop
10312 if Ekind (Comp) = E_Component
10313 and then Requires_Transient_Scope (Etype (Comp))
10317 Next_Entity (Comp);
10324 -- String literal types never require transient scope
10326 elsif Ekind (Typ) = E_String_Literal_Subtype then
10329 -- Array type. Note that we already know that this is a constrained
10330 -- array, since unconstrained arrays will fail the indefinite test.
10332 elsif Is_Array_Type (Typ) then
10334 -- If component type requires a transient scope, the array does too
10336 if Requires_Transient_Scope (Component_Type (Typ)) then
10339 -- Otherwise, we only need a transient scope if the size is not
10340 -- known at compile time.
10343 return not Size_Known_At_Compile_Time (Typ);
10346 -- All other cases do not require a transient scope
10351 end Requires_Transient_Scope;
10353 --------------------------
10354 -- Reset_Analyzed_Flags --
10355 --------------------------
10357 procedure Reset_Analyzed_Flags (N : Node_Id) is
10359 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10360 -- Function used to reset Analyzed flags in tree. Note that we do
10361 -- not reset Analyzed flags in entities, since there is no need to
10362 -- reanalyze entities, and indeed, it is wrong to do so, since it
10363 -- can result in generating auxiliary stuff more than once.
10365 --------------------
10366 -- Clear_Analyzed --
10367 --------------------
10369 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10371 if not Has_Extension (N) then
10372 Set_Analyzed (N, False);
10376 end Clear_Analyzed;
10378 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10380 -- Start of processing for Reset_Analyzed_Flags
10383 Reset_Analyzed (N);
10384 end Reset_Analyzed_Flags;
10386 ---------------------------
10387 -- Safe_To_Capture_Value --
10388 ---------------------------
10390 function Safe_To_Capture_Value
10393 Cond : Boolean := False) return Boolean
10396 -- The only entities for which we track constant values are variables
10397 -- which are not renamings, constants, out parameters, and in out
10398 -- parameters, so check if we have this case.
10400 -- Note: it may seem odd to track constant values for constants, but in
10401 -- fact this routine is used for other purposes than simply capturing
10402 -- the value. In particular, the setting of Known[_Non]_Null.
10404 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10406 Ekind (Ent) = E_Constant
10408 Ekind (Ent) = E_Out_Parameter
10410 Ekind (Ent) = E_In_Out_Parameter
10414 -- For conditionals, we also allow loop parameters and all formals,
10415 -- including in parameters.
10419 (Ekind (Ent) = E_Loop_Parameter
10421 Ekind (Ent) = E_In_Parameter)
10425 -- For all other cases, not just unsafe, but impossible to capture
10426 -- Current_Value, since the above are the only entities which have
10427 -- Current_Value fields.
10433 -- Skip if volatile or aliased, since funny things might be going on in
10434 -- these cases which we cannot necessarily track. Also skip any variable
10435 -- for which an address clause is given, or whose address is taken. Also
10436 -- never capture value of library level variables (an attempt to do so
10437 -- can occur in the case of package elaboration code).
10439 if Treat_As_Volatile (Ent)
10440 or else Is_Aliased (Ent)
10441 or else Present (Address_Clause (Ent))
10442 or else Address_Taken (Ent)
10443 or else (Is_Library_Level_Entity (Ent)
10444 and then Ekind (Ent) = E_Variable)
10449 -- OK, all above conditions are met. We also require that the scope of
10450 -- the reference be the same as the scope of the entity, not counting
10451 -- packages and blocks and loops.
10454 E_Scope : constant Entity_Id := Scope (Ent);
10455 R_Scope : Entity_Id;
10458 R_Scope := Current_Scope;
10459 while R_Scope /= Standard_Standard loop
10460 exit when R_Scope = E_Scope;
10462 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10465 R_Scope := Scope (R_Scope);
10470 -- We also require that the reference does not appear in a context
10471 -- where it is not sure to be executed (i.e. a conditional context
10472 -- or an exception handler). We skip this if Cond is True, since the
10473 -- capturing of values from conditional tests handles this ok.
10487 while Present (P) loop
10488 if Nkind (P) = N_If_Statement
10489 or else Nkind (P) = N_Case_Statement
10490 or else (Nkind (P) in N_Short_Circuit
10491 and then Desc = Right_Opnd (P))
10492 or else (Nkind (P) = N_Conditional_Expression
10493 and then Desc /= First (Expressions (P)))
10494 or else Nkind (P) = N_Exception_Handler
10495 or else Nkind (P) = N_Selective_Accept
10496 or else Nkind (P) = N_Conditional_Entry_Call
10497 or else Nkind (P) = N_Timed_Entry_Call
10498 or else Nkind (P) = N_Asynchronous_Select
10508 -- OK, looks safe to set value
10511 end Safe_To_Capture_Value;
10517 function Same_Name (N1, N2 : Node_Id) return Boolean is
10518 K1 : constant Node_Kind := Nkind (N1);
10519 K2 : constant Node_Kind := Nkind (N2);
10522 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10523 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10525 return Chars (N1) = Chars (N2);
10527 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10528 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10530 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10531 and then Same_Name (Prefix (N1), Prefix (N2));
10542 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10543 N1 : constant Node_Id := Original_Node (Node1);
10544 N2 : constant Node_Id := Original_Node (Node2);
10545 -- We do the tests on original nodes, since we are most interested
10546 -- in the original source, not any expansion that got in the way.
10548 K1 : constant Node_Kind := Nkind (N1);
10549 K2 : constant Node_Kind := Nkind (N2);
10552 -- First case, both are entities with same entity
10554 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
10556 EN1 : constant Entity_Id := Entity (N1);
10557 EN2 : constant Entity_Id := Entity (N2);
10559 if Present (EN1) and then Present (EN2)
10560 and then (Ekind_In (EN1, E_Variable, E_Constant)
10561 or else Is_Formal (EN1))
10569 -- Second case, selected component with same selector, same record
10571 if K1 = N_Selected_Component
10572 and then K2 = N_Selected_Component
10573 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10575 return Same_Object (Prefix (N1), Prefix (N2));
10577 -- Third case, indexed component with same subscripts, same array
10579 elsif K1 = N_Indexed_Component
10580 and then K2 = N_Indexed_Component
10581 and then Same_Object (Prefix (N1), Prefix (N2))
10586 E1 := First (Expressions (N1));
10587 E2 := First (Expressions (N2));
10588 while Present (E1) loop
10589 if not Same_Value (E1, E2) then
10600 -- Fourth case, slice of same array with same bounds
10603 and then K2 = N_Slice
10604 and then Nkind (Discrete_Range (N1)) = N_Range
10605 and then Nkind (Discrete_Range (N2)) = N_Range
10606 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10607 Low_Bound (Discrete_Range (N2)))
10608 and then Same_Value (High_Bound (Discrete_Range (N1)),
10609 High_Bound (Discrete_Range (N2)))
10611 return Same_Name (Prefix (N1), Prefix (N2));
10613 -- All other cases, not clearly the same object
10624 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10629 elsif not Is_Constrained (T1)
10630 and then not Is_Constrained (T2)
10631 and then Base_Type (T1) = Base_Type (T2)
10635 -- For now don't bother with case of identical constraints, to be
10636 -- fiddled with later on perhaps (this is only used for optimization
10637 -- purposes, so it is not critical to do a best possible job)
10648 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10650 if Compile_Time_Known_Value (Node1)
10651 and then Compile_Time_Known_Value (Node2)
10652 and then Expr_Value (Node1) = Expr_Value (Node2)
10655 elsif Same_Object (Node1, Node2) then
10666 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
10668 if Is_Entity_Name (N)
10670 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
10672 (Nkind (N) = N_Attribute_Reference
10673 and then Attribute_Name (N) = Name_Access)
10676 -- We are only interested in IN OUT parameters of inner calls
10679 or else Nkind (Parent (N)) = N_Function_Call
10680 or else Nkind (Parent (N)) in N_Op
10682 Actuals_In_Call.Increment_Last;
10683 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
10688 ------------------------
10689 -- Scope_Is_Transient --
10690 ------------------------
10692 function Scope_Is_Transient return Boolean is
10694 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10695 end Scope_Is_Transient;
10701 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10706 while Scop /= Standard_Standard loop
10707 Scop := Scope (Scop);
10709 if Scop = Scope2 then
10717 --------------------------
10718 -- Scope_Within_Or_Same --
10719 --------------------------
10721 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10726 while Scop /= Standard_Standard loop
10727 if Scop = Scope2 then
10730 Scop := Scope (Scop);
10735 end Scope_Within_Or_Same;
10737 --------------------
10738 -- Set_Convention --
10739 --------------------
10741 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10743 Basic_Set_Convention (E, Val);
10746 and then Is_Access_Subprogram_Type (Base_Type (E))
10747 and then Has_Foreign_Convention (E)
10749 Set_Can_Use_Internal_Rep (E, False);
10751 end Set_Convention;
10753 ------------------------
10754 -- Set_Current_Entity --
10755 ------------------------
10757 -- The given entity is to be set as the currently visible definition
10758 -- of its associated name (i.e. the Node_Id associated with its name).
10759 -- All we have to do is to get the name from the identifier, and
10760 -- then set the associated Node_Id to point to the given entity.
10762 procedure Set_Current_Entity (E : Entity_Id) is
10764 Set_Name_Entity_Id (Chars (E), E);
10765 end Set_Current_Entity;
10767 ---------------------------
10768 -- Set_Debug_Info_Needed --
10769 ---------------------------
10771 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10773 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10774 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10775 -- Used to set debug info in a related node if not set already
10777 --------------------------------------
10778 -- Set_Debug_Info_Needed_If_Not_Set --
10779 --------------------------------------
10781 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10784 and then not Needs_Debug_Info (E)
10786 Set_Debug_Info_Needed (E);
10788 -- For a private type, indicate that the full view also needs
10789 -- debug information.
10792 and then Is_Private_Type (E)
10793 and then Present (Full_View (E))
10795 Set_Debug_Info_Needed (Full_View (E));
10798 end Set_Debug_Info_Needed_If_Not_Set;
10800 -- Start of processing for Set_Debug_Info_Needed
10803 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10804 -- indicates that Debug_Info_Needed is never required for the entity.
10807 or else Debug_Info_Off (T)
10812 -- Set flag in entity itself. Note that we will go through the following
10813 -- circuitry even if the flag is already set on T. That's intentional,
10814 -- it makes sure that the flag will be set in subsidiary entities.
10816 Set_Needs_Debug_Info (T);
10818 -- Set flag on subsidiary entities if not set already
10820 if Is_Object (T) then
10821 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10823 elsif Is_Type (T) then
10824 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10826 if Is_Record_Type (T) then
10828 Ent : Entity_Id := First_Entity (T);
10830 while Present (Ent) loop
10831 Set_Debug_Info_Needed_If_Not_Set (Ent);
10836 -- For a class wide subtype, we also need debug information
10837 -- for the equivalent type.
10839 if Ekind (T) = E_Class_Wide_Subtype then
10840 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10843 elsif Is_Array_Type (T) then
10844 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10847 Indx : Node_Id := First_Index (T);
10849 while Present (Indx) loop
10850 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10851 Indx := Next_Index (Indx);
10855 if Is_Packed (T) then
10856 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10859 elsif Is_Access_Type (T) then
10860 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10862 elsif Is_Private_Type (T) then
10863 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10865 elsif Is_Protected_Type (T) then
10866 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10869 end Set_Debug_Info_Needed;
10871 ---------------------------------
10872 -- Set_Entity_With_Style_Check --
10873 ---------------------------------
10875 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10876 Val_Actual : Entity_Id;
10880 Set_Entity (N, Val);
10883 and then not Suppress_Style_Checks (Val)
10884 and then not In_Instance
10886 if Nkind (N) = N_Identifier then
10888 elsif Nkind (N) = N_Expanded_Name then
10889 Nod := Selector_Name (N);
10894 -- A special situation arises for derived operations, where we want
10895 -- to do the check against the parent (since the Sloc of the derived
10896 -- operation points to the derived type declaration itself).
10899 while not Comes_From_Source (Val_Actual)
10900 and then Nkind (Val_Actual) in N_Entity
10901 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10902 or else Is_Subprogram (Val_Actual)
10903 or else Is_Generic_Subprogram (Val_Actual))
10904 and then Present (Alias (Val_Actual))
10906 Val_Actual := Alias (Val_Actual);
10909 -- Renaming declarations for generic actuals do not come from source,
10910 -- and have a different name from that of the entity they rename, so
10911 -- there is no style check to perform here.
10913 if Chars (Nod) = Chars (Val_Actual) then
10914 Style.Check_Identifier (Nod, Val_Actual);
10918 Set_Entity (N, Val);
10919 end Set_Entity_With_Style_Check;
10921 ------------------------
10922 -- Set_Name_Entity_Id --
10923 ------------------------
10925 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10927 Set_Name_Table_Info (Id, Int (Val));
10928 end Set_Name_Entity_Id;
10930 ---------------------
10931 -- Set_Next_Actual --
10932 ---------------------
10934 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10936 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10937 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10939 end Set_Next_Actual;
10941 ----------------------------------
10942 -- Set_Optimize_Alignment_Flags --
10943 ----------------------------------
10945 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10947 if Optimize_Alignment = 'S' then
10948 Set_Optimize_Alignment_Space (E);
10949 elsif Optimize_Alignment = 'T' then
10950 Set_Optimize_Alignment_Time (E);
10952 end Set_Optimize_Alignment_Flags;
10954 -----------------------
10955 -- Set_Public_Status --
10956 -----------------------
10958 procedure Set_Public_Status (Id : Entity_Id) is
10959 S : constant Entity_Id := Current_Scope;
10961 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10962 -- Determines if E is defined within handled statement sequence or
10963 -- an if statement, returns True if so, False otherwise.
10965 ----------------------
10966 -- Within_HSS_Or_If --
10967 ----------------------
10969 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10972 N := Declaration_Node (E);
10979 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10985 end Within_HSS_Or_If;
10987 -- Start of processing for Set_Public_Status
10990 -- Everything in the scope of Standard is public
10992 if S = Standard_Standard then
10993 Set_Is_Public (Id);
10995 -- Entity is definitely not public if enclosing scope is not public
10997 elsif not Is_Public (S) then
11000 -- An object or function declaration that occurs in a handled sequence
11001 -- of statements or within an if statement is the declaration for a
11002 -- temporary object or local subprogram generated by the expander. It
11003 -- never needs to be made public and furthermore, making it public can
11004 -- cause back end problems.
11006 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11007 N_Function_Specification)
11008 and then Within_HSS_Or_If (Id)
11012 -- Entities in public packages or records are public
11014 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11015 Set_Is_Public (Id);
11017 -- The bounds of an entry family declaration can generate object
11018 -- declarations that are visible to the back-end, e.g. in the
11019 -- the declaration of a composite type that contains tasks.
11021 elsif Is_Concurrent_Type (S)
11022 and then not Has_Completion (S)
11023 and then Nkind (Parent (Id)) = N_Object_Declaration
11025 Set_Is_Public (Id);
11027 end Set_Public_Status;
11029 -----------------------------
11030 -- Set_Referenced_Modified --
11031 -----------------------------
11033 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11037 -- Deal with indexed or selected component where prefix is modified
11039 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11040 Pref := Prefix (N);
11042 -- If prefix is access type, then it is the designated object that is
11043 -- being modified, which means we have no entity to set the flag on.
11045 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11048 -- Otherwise chase the prefix
11051 Set_Referenced_Modified (Pref, Out_Param);
11054 -- Otherwise see if we have an entity name (only other case to process)
11056 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11057 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11058 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11060 end Set_Referenced_Modified;
11062 ----------------------------
11063 -- Set_Scope_Is_Transient --
11064 ----------------------------
11066 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11068 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11069 end Set_Scope_Is_Transient;
11071 -------------------
11072 -- Set_Size_Info --
11073 -------------------
11075 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11077 -- We copy Esize, but not RM_Size, since in general RM_Size is
11078 -- subtype specific and does not get inherited by all subtypes.
11080 Set_Esize (T1, Esize (T2));
11081 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11083 if Is_Discrete_Or_Fixed_Point_Type (T1)
11085 Is_Discrete_Or_Fixed_Point_Type (T2)
11087 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11090 Set_Alignment (T1, Alignment (T2));
11093 --------------------
11094 -- Static_Integer --
11095 --------------------
11097 function Static_Integer (N : Node_Id) return Uint is
11099 Analyze_And_Resolve (N, Any_Integer);
11102 or else Error_Posted (N)
11103 or else Etype (N) = Any_Type
11108 if Is_Static_Expression (N) then
11109 if not Raises_Constraint_Error (N) then
11110 return Expr_Value (N);
11115 elsif Etype (N) = Any_Type then
11119 Flag_Non_Static_Expr
11120 ("static integer expression required here", N);
11123 end Static_Integer;
11125 --------------------------
11126 -- Statically_Different --
11127 --------------------------
11129 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11130 R1 : constant Node_Id := Get_Referenced_Object (E1);
11131 R2 : constant Node_Id := Get_Referenced_Object (E2);
11133 return Is_Entity_Name (R1)
11134 and then Is_Entity_Name (R2)
11135 and then Entity (R1) /= Entity (R2)
11136 and then not Is_Formal (Entity (R1))
11137 and then not Is_Formal (Entity (R2));
11138 end Statically_Different;
11140 -----------------------------
11141 -- Subprogram_Access_Level --
11142 -----------------------------
11144 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11146 if Present (Alias (Subp)) then
11147 return Subprogram_Access_Level (Alias (Subp));
11149 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11151 end Subprogram_Access_Level;
11157 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11159 if Debug_Flag_W then
11160 for J in 0 .. Scope_Stack.Last loop
11165 Write_Name (Chars (E));
11166 Write_Str (" from ");
11167 Write_Location (Sloc (N));
11172 -----------------------
11173 -- Transfer_Entities --
11174 -----------------------
11176 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11177 Ent : Entity_Id := First_Entity (From);
11184 if (Last_Entity (To)) = Empty then
11185 Set_First_Entity (To, Ent);
11187 Set_Next_Entity (Last_Entity (To), Ent);
11190 Set_Last_Entity (To, Last_Entity (From));
11192 while Present (Ent) loop
11193 Set_Scope (Ent, To);
11195 if not Is_Public (Ent) then
11196 Set_Public_Status (Ent);
11199 and then Ekind (Ent) = E_Record_Subtype
11202 -- The components of the propagated Itype must be public
11208 Comp := First_Entity (Ent);
11209 while Present (Comp) loop
11210 Set_Is_Public (Comp);
11211 Next_Entity (Comp);
11220 Set_First_Entity (From, Empty);
11221 Set_Last_Entity (From, Empty);
11222 end Transfer_Entities;
11224 -----------------------
11225 -- Type_Access_Level --
11226 -----------------------
11228 function Type_Access_Level (Typ : Entity_Id) return Uint is
11232 Btyp := Base_Type (Typ);
11234 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11235 -- simply use the level where the type is declared. This is true for
11236 -- stand-alone object declarations, and for anonymous access types
11237 -- associated with components the level is the same as that of the
11238 -- enclosing composite type. However, special treatment is needed for
11239 -- the cases of access parameters, return objects of an anonymous access
11240 -- type, and, in Ada 95, access discriminants of limited types.
11242 if Ekind (Btyp) in Access_Kind then
11243 if Ekind (Btyp) = E_Anonymous_Access_Type then
11245 -- If the type is a nonlocal anonymous access type (such as for
11246 -- an access parameter) we treat it as being declared at the
11247 -- library level to ensure that names such as X.all'access don't
11248 -- fail static accessibility checks.
11250 if not Is_Local_Anonymous_Access (Typ) then
11251 return Scope_Depth (Standard_Standard);
11253 -- If this is a return object, the accessibility level is that of
11254 -- the result subtype of the enclosing function. The test here is
11255 -- little complicated, because we have to account for extended
11256 -- return statements that have been rewritten as blocks, in which
11257 -- case we have to find and the Is_Return_Object attribute of the
11258 -- itype's associated object. It would be nice to find a way to
11259 -- simplify this test, but it doesn't seem worthwhile to add a new
11260 -- flag just for purposes of this test. ???
11262 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11265 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11266 N_Object_Declaration
11267 and then Is_Return_Object
11268 (Defining_Identifier
11269 (Associated_Node_For_Itype (Btyp))))
11275 Scop := Scope (Scope (Btyp));
11276 while Present (Scop) loop
11277 exit when Ekind (Scop) = E_Function;
11278 Scop := Scope (Scop);
11281 -- Treat the return object's type as having the level of the
11282 -- function's result subtype (as per RM05-6.5(5.3/2)).
11284 return Type_Access_Level (Etype (Scop));
11289 Btyp := Root_Type (Btyp);
11291 -- The accessibility level of anonymous access types associated with
11292 -- discriminants is that of the current instance of the type, and
11293 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11295 -- AI-402: access discriminants have accessibility based on the
11296 -- object rather than the type in Ada 2005, so the above paragraph
11299 -- ??? Needs completion with rules from AI-416
11301 if Ada_Version <= Ada_95
11302 and then Ekind (Typ) = E_Anonymous_Access_Type
11303 and then Present (Associated_Node_For_Itype (Typ))
11304 and then Nkind (Associated_Node_For_Itype (Typ)) =
11305 N_Discriminant_Specification
11307 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11311 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11312 end Type_Access_Level;
11314 --------------------------
11315 -- Unit_Declaration_Node --
11316 --------------------------
11318 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11319 N : Node_Id := Parent (Unit_Id);
11322 -- Predefined operators do not have a full function declaration
11324 if Ekind (Unit_Id) = E_Operator then
11328 -- Isn't there some better way to express the following ???
11330 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11331 and then Nkind (N) /= N_Formal_Package_Declaration
11332 and then Nkind (N) /= N_Function_Instantiation
11333 and then Nkind (N) /= N_Generic_Package_Declaration
11334 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11335 and then Nkind (N) /= N_Package_Declaration
11336 and then Nkind (N) /= N_Package_Body
11337 and then Nkind (N) /= N_Package_Instantiation
11338 and then Nkind (N) /= N_Package_Renaming_Declaration
11339 and then Nkind (N) /= N_Procedure_Instantiation
11340 and then Nkind (N) /= N_Protected_Body
11341 and then Nkind (N) /= N_Subprogram_Declaration
11342 and then Nkind (N) /= N_Subprogram_Body
11343 and then Nkind (N) /= N_Subprogram_Body_Stub
11344 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11345 and then Nkind (N) /= N_Task_Body
11346 and then Nkind (N) /= N_Task_Type_Declaration
11347 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11348 and then Nkind (N) not in N_Generic_Renaming_Declaration
11351 pragma Assert (Present (N));
11355 end Unit_Declaration_Node;
11357 ------------------------------
11358 -- Universal_Interpretation --
11359 ------------------------------
11361 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11362 Index : Interp_Index;
11366 -- The argument may be a formal parameter of an operator or subprogram
11367 -- with multiple interpretations, or else an expression for an actual.
11369 if Nkind (Opnd) = N_Defining_Identifier
11370 or else not Is_Overloaded (Opnd)
11372 if Etype (Opnd) = Universal_Integer
11373 or else Etype (Opnd) = Universal_Real
11375 return Etype (Opnd);
11381 Get_First_Interp (Opnd, Index, It);
11382 while Present (It.Typ) loop
11383 if It.Typ = Universal_Integer
11384 or else It.Typ = Universal_Real
11389 Get_Next_Interp (Index, It);
11394 end Universal_Interpretation;
11400 function Unqualify (Expr : Node_Id) return Node_Id is
11402 -- Recurse to handle unlikely case of multiple levels of qualification
11404 if Nkind (Expr) = N_Qualified_Expression then
11405 return Unqualify (Expression (Expr));
11407 -- Normal case, not a qualified expression
11414 -----------------------
11415 -- Visible_Ancestors --
11416 -----------------------
11418 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
11424 pragma Assert (Is_Record_Type (Typ)
11425 and then Is_Tagged_Type (Typ));
11427 -- Collect all the parents and progenitors of Typ. If the full-view of
11428 -- private parents and progenitors is available then it is used to
11429 -- generate the list of visible ancestors; otherwise their partial
11430 -- view is added to the resulting list.
11435 Use_Full_View => True);
11439 Ifaces_List => List_2,
11440 Exclude_Parents => True,
11441 Use_Full_View => True);
11443 -- Join the two lists. Avoid duplications because an interface may
11444 -- simultaneously be parent and progenitor of a type.
11446 Elmt := First_Elmt (List_2);
11447 while Present (Elmt) loop
11448 Append_Unique_Elmt (Node (Elmt), List_1);
11453 end Visible_Ancestors;
11455 ----------------------
11456 -- Within_Init_Proc --
11457 ----------------------
11459 function Within_Init_Proc return Boolean is
11463 S := Current_Scope;
11464 while not Is_Overloadable (S) loop
11465 if S = Standard_Standard then
11472 return Is_Init_Proc (S);
11473 end Within_Init_Proc;
11479 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11480 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11481 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11483 function Has_One_Matching_Field return Boolean;
11484 -- Determines if Expec_Type is a record type with a single component or
11485 -- discriminant whose type matches the found type or is one dimensional
11486 -- array whose component type matches the found type.
11488 ----------------------------
11489 -- Has_One_Matching_Field --
11490 ----------------------------
11492 function Has_One_Matching_Field return Boolean is
11496 if Is_Array_Type (Expec_Type)
11497 and then Number_Dimensions (Expec_Type) = 1
11499 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11503 elsif not Is_Record_Type (Expec_Type) then
11507 E := First_Entity (Expec_Type);
11512 elsif (Ekind (E) /= E_Discriminant
11513 and then Ekind (E) /= E_Component)
11514 or else (Chars (E) = Name_uTag
11515 or else Chars (E) = Name_uParent)
11524 if not Covers (Etype (E), Found_Type) then
11527 elsif Present (Next_Entity (E)) then
11534 end Has_One_Matching_Field;
11536 -- Start of processing for Wrong_Type
11539 -- Don't output message if either type is Any_Type, or if a message
11540 -- has already been posted for this node. We need to do the latter
11541 -- check explicitly (it is ordinarily done in Errout), because we
11542 -- are using ! to force the output of the error messages.
11544 if Expec_Type = Any_Type
11545 or else Found_Type = Any_Type
11546 or else Error_Posted (Expr)
11550 -- In an instance, there is an ongoing problem with completion of
11551 -- type derived from private types. Their structure is what Gigi
11552 -- expects, but the Etype is the parent type rather than the
11553 -- derived private type itself. Do not flag error in this case. The
11554 -- private completion is an entity without a parent, like an Itype.
11555 -- Similarly, full and partial views may be incorrect in the instance.
11556 -- There is no simple way to insure that it is consistent ???
11558 elsif In_Instance then
11559 if Etype (Etype (Expr)) = Etype (Expected_Type)
11561 (Has_Private_Declaration (Expected_Type)
11562 or else Has_Private_Declaration (Etype (Expr)))
11563 and then No (Parent (Expected_Type))
11569 -- An interesting special check. If the expression is parenthesized
11570 -- and its type corresponds to the type of the sole component of the
11571 -- expected record type, or to the component type of the expected one
11572 -- dimensional array type, then assume we have a bad aggregate attempt.
11574 if Nkind (Expr) in N_Subexpr
11575 and then Paren_Count (Expr) /= 0
11576 and then Has_One_Matching_Field
11578 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11580 -- Another special check, if we are looking for a pool-specific access
11581 -- type and we found an E_Access_Attribute_Type, then we have the case
11582 -- of an Access attribute being used in a context which needs a pool-
11583 -- specific type, which is never allowed. The one extra check we make
11584 -- is that the expected designated type covers the Found_Type.
11586 elsif Is_Access_Type (Expec_Type)
11587 and then Ekind (Found_Type) = E_Access_Attribute_Type
11588 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11589 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11591 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11593 Error_Msg_N -- CODEFIX
11594 ("result must be general access type!", Expr);
11595 Error_Msg_NE -- CODEFIX
11596 ("add ALL to }!", Expr, Expec_Type);
11598 -- Another special check, if the expected type is an integer type,
11599 -- but the expression is of type System.Address, and the parent is
11600 -- an addition or subtraction operation whose left operand is the
11601 -- expression in question and whose right operand is of an integral
11602 -- type, then this is an attempt at address arithmetic, so give
11603 -- appropriate message.
11605 elsif Is_Integer_Type (Expec_Type)
11606 and then Is_RTE (Found_Type, RE_Address)
11607 and then (Nkind (Parent (Expr)) = N_Op_Add
11609 Nkind (Parent (Expr)) = N_Op_Subtract)
11610 and then Expr = Left_Opnd (Parent (Expr))
11611 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11614 ("address arithmetic not predefined in package System",
11617 ("\possible missing with/use of System.Storage_Elements",
11621 -- If the expected type is an anonymous access type, as for access
11622 -- parameters and discriminants, the error is on the designated types.
11624 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11625 if Comes_From_Source (Expec_Type) then
11626 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11629 ("expected an access type with designated}",
11630 Expr, Designated_Type (Expec_Type));
11633 if Is_Access_Type (Found_Type)
11634 and then not Comes_From_Source (Found_Type)
11637 ("\\found an access type with designated}!",
11638 Expr, Designated_Type (Found_Type));
11640 if From_With_Type (Found_Type) then
11641 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11642 Error_Msg_Qual_Level := 99;
11643 Error_Msg_NE -- CODEFIX
11644 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11645 Error_Msg_Qual_Level := 0;
11647 Error_Msg_NE ("found}!", Expr, Found_Type);
11651 -- Normal case of one type found, some other type expected
11654 -- If the names of the two types are the same, see if some number
11655 -- of levels of qualification will help. Don't try more than three
11656 -- levels, and if we get to standard, it's no use (and probably
11657 -- represents an error in the compiler) Also do not bother with
11658 -- internal scope names.
11661 Expec_Scope : Entity_Id;
11662 Found_Scope : Entity_Id;
11665 Expec_Scope := Expec_Type;
11666 Found_Scope := Found_Type;
11668 for Levels in Int range 0 .. 3 loop
11669 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11670 Error_Msg_Qual_Level := Levels;
11674 Expec_Scope := Scope (Expec_Scope);
11675 Found_Scope := Scope (Found_Scope);
11677 exit when Expec_Scope = Standard_Standard
11678 or else Found_Scope = Standard_Standard
11679 or else not Comes_From_Source (Expec_Scope)
11680 or else not Comes_From_Source (Found_Scope);
11684 if Is_Record_Type (Expec_Type)
11685 and then Present (Corresponding_Remote_Type (Expec_Type))
11687 Error_Msg_NE ("expected}!", Expr,
11688 Corresponding_Remote_Type (Expec_Type));
11690 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11693 if Is_Entity_Name (Expr)
11694 and then Is_Package_Or_Generic_Package (Entity (Expr))
11696 Error_Msg_N ("\\found package name!", Expr);
11698 elsif Is_Entity_Name (Expr)
11700 (Ekind (Entity (Expr)) = E_Procedure
11702 Ekind (Entity (Expr)) = E_Generic_Procedure)
11704 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11706 ("found procedure name, possibly missing Access attribute!",
11710 ("\\found procedure name instead of function!", Expr);
11713 elsif Nkind (Expr) = N_Function_Call
11714 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11715 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11716 and then No (Parameter_Associations (Expr))
11719 ("found function name, possibly missing Access attribute!",
11722 -- Catch common error: a prefix or infix operator which is not
11723 -- directly visible because the type isn't.
11725 elsif Nkind (Expr) in N_Op
11726 and then Is_Overloaded (Expr)
11727 and then not Is_Immediately_Visible (Expec_Type)
11728 and then not Is_Potentially_Use_Visible (Expec_Type)
11729 and then not In_Use (Expec_Type)
11730 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11733 ("operator of the type is not directly visible!", Expr);
11735 elsif Ekind (Found_Type) = E_Void
11736 and then Present (Parent (Found_Type))
11737 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11739 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11742 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11745 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11746 -- of the same modular type, and (M1 and M2) = 0 was intended.
11748 if Expec_Type = Standard_Boolean
11749 and then Is_Modular_Integer_Type (Found_Type)
11750 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11751 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11754 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11755 L : constant Node_Id := Left_Opnd (Op);
11756 R : constant Node_Id := Right_Opnd (Op);
11758 -- The case for the message is when the left operand of the
11759 -- comparison is the same modular type, or when it is an
11760 -- integer literal (or other universal integer expression),
11761 -- which would have been typed as the modular type if the
11762 -- parens had been there.
11764 if (Etype (L) = Found_Type
11766 Etype (L) = Universal_Integer)
11767 and then Is_Integer_Type (Etype (R))
11770 ("\\possible missing parens for modular operation", Expr);
11775 -- Reset error message qualification indication
11777 Error_Msg_Qual_Level := 0;