1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Treepr; -- ???For debugging code below
28 with Aspects; use Aspects;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Disp; use Exp_Disp;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Ghost; use Ghost;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
72 with GNAT.HTable; use GNAT.HTable;
74 package body Sem_Util is
76 ----------------------------------------
77 -- Global Variables for New_Copy_Tree --
78 ----------------------------------------
80 -- These global variables are used by New_Copy_Tree. See description of the
81 -- body of this subprogram for details. Global variables can be safely used
82 -- by New_Copy_Tree, since there is no case of a recursive call from the
83 -- processing inside New_Copy_Tree.
85 NCT_Hash_Threshold : constant := 20;
86 -- If there are more than this number of pairs of entries in the map, then
87 -- Hash_Tables_Used will be set, and the hash tables will be initialized
88 -- and used for the searches.
90 NCT_Hash_Tables_Used : Boolean := False;
91 -- Set to True if hash tables are in use
93 NCT_Table_Entries : Nat := 0;
94 -- Count entries in table to see if threshold is reached
96 NCT_Hash_Table_Setup : Boolean := False;
97 -- Set to True if hash table contains data. We set this True if we setup
98 -- the hash table with data, and leave it set permanently from then on,
99 -- this is a signal that second and subsequent users of the hash table
100 -- must clear the old entries before reuse.
102 subtype NCT_Header_Num is Int range 0 .. 511;
103 -- Defines range of headers in hash tables (512 headers)
105 -----------------------
106 -- Local Subprograms --
107 -----------------------
109 function Build_Component_Subtype
112 T : Entity_Id) return Node_Id;
113 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
114 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
115 -- Loc is the source location, T is the original subtype.
117 function Has_Enabled_Property
118 (Item_Id : Entity_Id;
119 Property : Name_Id) return Boolean;
120 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
121 -- Determine whether an abstract state or a variable denoted by entity
122 -- Item_Id has enabled property Property.
124 function Has_Null_Extension (T : Entity_Id) return Boolean;
125 -- T is a derived tagged type. Check whether the type extension is null.
126 -- If the parent type is fully initialized, T can be treated as such.
128 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
129 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
130 -- with discriminants whose default values are static, examine only the
131 -- components in the selected variant to determine whether all of them
134 ------------------------------
135 -- Abstract_Interface_List --
136 ------------------------------
138 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
142 if Is_Concurrent_Type (Typ) then
144 -- If we are dealing with a synchronized subtype, go to the base
145 -- type, whose declaration has the interface list.
147 -- Shouldn't this be Declaration_Node???
149 Nod := Parent (Base_Type (Typ));
151 if Nkind (Nod) = N_Full_Type_Declaration then
155 elsif Ekind (Typ) = E_Record_Type_With_Private then
156 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
157 Nod := Type_Definition (Parent (Typ));
159 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
160 if Present (Full_View (Typ))
162 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
164 Nod := Type_Definition (Parent (Full_View (Typ)));
166 -- If the full-view is not available we cannot do anything else
167 -- here (the source has errors).
173 -- Support for generic formals with interfaces is still missing ???
175 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
180 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
184 elsif Ekind (Typ) = E_Record_Subtype then
185 Nod := Type_Definition (Parent (Etype (Typ)));
187 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
189 -- Recurse, because parent may still be a private extension. Also
190 -- note that the full view of the subtype or the full view of its
191 -- base type may (both) be unavailable.
193 return Abstract_Interface_List (Etype (Typ));
195 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
196 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
197 Nod := Formal_Type_Definition (Parent (Typ));
199 Nod := Type_Definition (Parent (Typ));
203 return Interface_List (Nod);
204 end Abstract_Interface_List;
206 --------------------------------
207 -- Add_Access_Type_To_Process --
208 --------------------------------
210 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
214 Ensure_Freeze_Node (E);
215 L := Access_Types_To_Process (Freeze_Node (E));
219 Set_Access_Types_To_Process (Freeze_Node (E), L);
223 end Add_Access_Type_To_Process;
225 --------------------------
226 -- Add_Block_Identifier --
227 --------------------------
229 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
230 Loc : constant Source_Ptr := Sloc (N);
233 pragma Assert (Nkind (N) = N_Block_Statement);
235 -- The block already has a label, return its entity
237 if Present (Identifier (N)) then
238 Id := Entity (Identifier (N));
240 -- Create a new block label and set its attributes
243 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
244 Set_Etype (Id, Standard_Void_Type);
247 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
248 Set_Block_Node (Id, Identifier (N));
250 end Add_Block_Identifier;
252 ----------------------------
253 -- Add_Global_Declaration --
254 ----------------------------
256 procedure Add_Global_Declaration (N : Node_Id) is
257 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
260 if No (Declarations (Aux_Node)) then
261 Set_Declarations (Aux_Node, New_List);
264 Append_To (Declarations (Aux_Node), N);
266 end Add_Global_Declaration;
268 --------------------------------
269 -- Address_Integer_Convert_OK --
270 --------------------------------
272 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
274 if Allow_Integer_Address
275 and then ((Is_Descendent_Of_Address (T1)
276 and then Is_Private_Type (T1)
277 and then Is_Integer_Type (T2))
279 (Is_Descendent_Of_Address (T2)
280 and then Is_Private_Type (T2)
281 and then Is_Integer_Type (T1)))
287 end Address_Integer_Convert_OK;
293 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
295 function Addressable (V : Uint) return Boolean is
297 return V = Uint_8 or else
303 function Addressable (V : Int) return Boolean is
311 ---------------------------------
312 -- Aggregate_Constraint_Checks --
313 ---------------------------------
315 procedure Aggregate_Constraint_Checks
317 Check_Typ : Entity_Id)
319 Exp_Typ : constant Entity_Id := Etype (Exp);
322 if Raises_Constraint_Error (Exp) then
326 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
327 -- component's type to force the appropriate accessibility checks.
329 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
330 -- type to force the corresponding run-time check
332 if Is_Access_Type (Check_Typ)
333 and then ((Is_Local_Anonymous_Access (Check_Typ))
334 or else (Can_Never_Be_Null (Check_Typ)
335 and then not Can_Never_Be_Null (Exp_Typ)))
337 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
338 Analyze_And_Resolve (Exp, Check_Typ);
339 Check_Unset_Reference (Exp);
342 -- This is really expansion activity, so make sure that expansion is
343 -- on and is allowed. In GNATprove mode, we also want check flags to
344 -- be added in the tree, so that the formal verification can rely on
345 -- those to be present. In GNATprove mode for formal verification, some
346 -- treatment typically only done during expansion needs to be performed
347 -- on the tree, but it should not be applied inside generics. Otherwise,
348 -- this breaks the name resolution mechanism for generic instances.
350 if not Expander_Active
351 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
356 -- First check if we have to insert discriminant checks
358 if Has_Discriminants (Exp_Typ) then
359 Apply_Discriminant_Check (Exp, Check_Typ);
361 -- Next emit length checks for array aggregates
363 elsif Is_Array_Type (Exp_Typ) then
364 Apply_Length_Check (Exp, Check_Typ);
366 -- Finally emit scalar and string checks. If we are dealing with a
367 -- scalar literal we need to check by hand because the Etype of
368 -- literals is not necessarily correct.
370 elsif Is_Scalar_Type (Exp_Typ)
371 and then Compile_Time_Known_Value (Exp)
373 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
374 Apply_Compile_Time_Constraint_Error
375 (Exp, "value not in range of}??", CE_Range_Check_Failed,
376 Ent => Base_Type (Check_Typ),
377 Typ => Base_Type (Check_Typ));
379 elsif Is_Out_Of_Range (Exp, Check_Typ) then
380 Apply_Compile_Time_Constraint_Error
381 (Exp, "value not in range of}??", CE_Range_Check_Failed,
385 elsif not Range_Checks_Suppressed (Check_Typ) then
386 Apply_Scalar_Range_Check (Exp, Check_Typ);
389 -- Verify that target type is also scalar, to prevent view anomalies
390 -- in instantiations.
392 elsif (Is_Scalar_Type (Exp_Typ)
393 or else Nkind (Exp) = N_String_Literal)
394 and then Is_Scalar_Type (Check_Typ)
395 and then Exp_Typ /= Check_Typ
397 if Is_Entity_Name (Exp)
398 and then Ekind (Entity (Exp)) = E_Constant
400 -- If expression is a constant, it is worthwhile checking whether
401 -- it is a bound of the type.
403 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
404 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
406 (Is_Entity_Name (Type_High_Bound (Check_Typ))
407 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
412 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
413 Analyze_And_Resolve (Exp, Check_Typ);
414 Check_Unset_Reference (Exp);
417 -- Could use a comment on this case ???
420 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
421 Analyze_And_Resolve (Exp, Check_Typ);
422 Check_Unset_Reference (Exp);
426 end Aggregate_Constraint_Checks;
428 -----------------------
429 -- Alignment_In_Bits --
430 -----------------------
432 function Alignment_In_Bits (E : Entity_Id) return Uint is
434 return Alignment (E) * System_Storage_Unit;
435 end Alignment_In_Bits;
437 --------------------------------------
438 -- All_Composite_Constraints_Static --
439 --------------------------------------
441 function All_Composite_Constraints_Static
442 (Constr : Node_Id) return Boolean
445 if No (Constr) or else Error_Posted (Constr) then
449 case Nkind (Constr) is
451 if Nkind (Constr) in N_Has_Entity
452 and then Present (Entity (Constr))
454 if Is_Type (Entity (Constr)) then
456 not Is_Discrete_Type (Entity (Constr))
457 or else Is_OK_Static_Subtype (Entity (Constr));
460 elsif Nkind (Constr) = N_Range then
462 Is_OK_Static_Expression (Low_Bound (Constr))
464 Is_OK_Static_Expression (High_Bound (Constr));
466 elsif Nkind (Constr) = N_Attribute_Reference
467 and then Attribute_Name (Constr) = Name_Range
470 Is_OK_Static_Expression
471 (Type_Low_Bound (Etype (Prefix (Constr))))
473 Is_OK_Static_Expression
474 (Type_High_Bound (Etype (Prefix (Constr))));
478 not Present (Etype (Constr)) -- previous error
479 or else not Is_Discrete_Type (Etype (Constr))
480 or else Is_OK_Static_Expression (Constr);
482 when N_Discriminant_Association =>
483 return All_Composite_Constraints_Static (Expression (Constr));
485 when N_Range_Constraint =>
487 All_Composite_Constraints_Static (Range_Expression (Constr));
489 when N_Index_Or_Discriminant_Constraint =>
491 One_Cstr : Entity_Id;
493 One_Cstr := First (Constraints (Constr));
494 while Present (One_Cstr) loop
495 if not All_Composite_Constraints_Static (One_Cstr) then
505 when N_Subtype_Indication =>
507 All_Composite_Constraints_Static (Subtype_Mark (Constr))
509 All_Composite_Constraints_Static (Constraint (Constr));
514 end All_Composite_Constraints_Static;
516 ---------------------------------
517 -- Append_Inherited_Subprogram --
518 ---------------------------------
520 procedure Append_Inherited_Subprogram (S : Entity_Id) is
521 Par : constant Entity_Id := Alias (S);
522 -- The parent subprogram
524 Scop : constant Entity_Id := Scope (Par);
525 -- The scope of definition of the parent subprogram
527 Typ : constant Entity_Id := Defining_Entity (Parent (S));
528 -- The derived type of which S is a primitive operation
534 if Ekind (Current_Scope) = E_Package
535 and then In_Private_Part (Current_Scope)
536 and then Has_Private_Declaration (Typ)
537 and then Is_Tagged_Type (Typ)
538 and then Scop = Current_Scope
540 -- The inherited operation is available at the earliest place after
541 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
542 -- relevant for type extensions. If the parent operation appears
543 -- after the type extension, the operation is not visible.
546 (Visible_Declarations
547 (Package_Specification (Current_Scope)));
548 while Present (Decl) loop
549 if Nkind (Decl) = N_Private_Extension_Declaration
550 and then Defining_Entity (Decl) = Typ
552 if Sloc (Decl) > Sloc (Par) then
553 Next_E := Next_Entity (Par);
554 Set_Next_Entity (Par, S);
555 Set_Next_Entity (S, Next_E);
567 -- If partial view is not a type extension, or it appears before the
568 -- subprogram declaration, insert normally at end of entity list.
570 Append_Entity (S, Current_Scope);
571 end Append_Inherited_Subprogram;
573 -----------------------------------------
574 -- Apply_Compile_Time_Constraint_Error --
575 -----------------------------------------
577 procedure Apply_Compile_Time_Constraint_Error
580 Reason : RT_Exception_Code;
581 Ent : Entity_Id := Empty;
582 Typ : Entity_Id := Empty;
583 Loc : Source_Ptr := No_Location;
584 Rep : Boolean := True;
585 Warn : Boolean := False)
587 Stat : constant Boolean := Is_Static_Expression (N);
588 R_Stat : constant Node_Id :=
589 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
600 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
606 -- Now we replace the node by an N_Raise_Constraint_Error node
607 -- This does not need reanalyzing, so set it as analyzed now.
610 Set_Analyzed (N, True);
613 Set_Raises_Constraint_Error (N);
615 -- Now deal with possible local raise handling
617 Possible_Local_Raise (N, Standard_Constraint_Error);
619 -- If the original expression was marked as static, the result is
620 -- still marked as static, but the Raises_Constraint_Error flag is
621 -- always set so that further static evaluation is not attempted.
624 Set_Is_Static_Expression (N);
626 end Apply_Compile_Time_Constraint_Error;
628 ---------------------------
629 -- Async_Readers_Enabled --
630 ---------------------------
632 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
634 return Has_Enabled_Property (Id, Name_Async_Readers);
635 end Async_Readers_Enabled;
637 ---------------------------
638 -- Async_Writers_Enabled --
639 ---------------------------
641 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
643 return Has_Enabled_Property (Id, Name_Async_Writers);
644 end Async_Writers_Enabled;
646 --------------------------------------
647 -- Available_Full_View_Of_Component --
648 --------------------------------------
650 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
651 ST : constant Entity_Id := Scope (T);
652 SCT : constant Entity_Id := Scope (Component_Type (T));
654 return In_Open_Scopes (ST)
655 and then In_Open_Scopes (SCT)
656 and then Scope_Depth (ST) >= Scope_Depth (SCT);
657 end Available_Full_View_Of_Component;
663 procedure Bad_Attribute
666 Warn : Boolean := False)
669 Error_Msg_Warn := Warn;
670 Error_Msg_N ("unrecognized attribute&<<", N);
672 -- Check for possible misspelling
674 Error_Msg_Name_1 := First_Attribute_Name;
675 while Error_Msg_Name_1 <= Last_Attribute_Name loop
676 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
677 Error_Msg_N -- CODEFIX
678 ("\possible misspelling of %<<", N);
682 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
686 --------------------------------
687 -- Bad_Predicated_Subtype_Use --
688 --------------------------------
690 procedure Bad_Predicated_Subtype_Use
694 Suggest_Static : Boolean := False)
699 -- Avoid cascaded errors
701 if Error_Posted (N) then
705 if Inside_A_Generic then
706 Gen := Current_Scope;
707 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
715 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
716 Set_No_Predicate_On_Actual (Typ);
719 elsif Has_Predicates (Typ) then
720 if Is_Generic_Actual_Type (Typ) then
722 -- The restriction on loop parameters is only that the type
723 -- should have no dynamic predicates.
725 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
726 and then not Has_Dynamic_Predicate_Aspect (Typ)
727 and then Is_OK_Static_Subtype (Typ)
732 Gen := Current_Scope;
733 while not Is_Generic_Instance (Gen) loop
737 pragma Assert (Present (Gen));
739 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
740 Error_Msg_Warn := SPARK_Mode /= On;
741 Error_Msg_FE (Msg & "<<", N, Typ);
742 Error_Msg_F ("\Program_Error [<<", N);
745 Make_Raise_Program_Error (Sloc (N),
746 Reason => PE_Bad_Predicated_Generic_Type));
749 Error_Msg_FE (Msg & "<<", N, Typ);
753 Error_Msg_FE (Msg, N, Typ);
756 -- Emit an optional suggestion on how to remedy the error if the
757 -- context warrants it.
759 if Suggest_Static and then Has_Static_Predicate (Typ) then
760 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
763 end Bad_Predicated_Subtype_Use;
765 -----------------------------------------
766 -- Bad_Unordered_Enumeration_Reference --
767 -----------------------------------------
769 function Bad_Unordered_Enumeration_Reference
771 T : Entity_Id) return Boolean
774 return Is_Enumeration_Type (T)
775 and then Warn_On_Unordered_Enumeration_Type
776 and then not Is_Generic_Type (T)
777 and then Comes_From_Source (N)
778 and then not Has_Pragma_Ordered (T)
779 and then not In_Same_Extended_Unit (N, T);
780 end Bad_Unordered_Enumeration_Reference;
782 --------------------------
783 -- Build_Actual_Subtype --
784 --------------------------
786 function Build_Actual_Subtype
788 N : Node_Or_Entity_Id) return Node_Id
791 -- Normally Sloc (N), but may point to corresponding body in some cases
793 Constraints : List_Id;
799 Disc_Type : Entity_Id;
805 if Nkind (N) = N_Defining_Identifier then
806 Obj := New_Occurrence_Of (N, Loc);
808 -- If this is a formal parameter of a subprogram declaration, and
809 -- we are compiling the body, we want the declaration for the
810 -- actual subtype to carry the source position of the body, to
811 -- prevent anomalies in gdb when stepping through the code.
813 if Is_Formal (N) then
815 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
817 if Nkind (Decl) = N_Subprogram_Declaration
818 and then Present (Corresponding_Body (Decl))
820 Loc := Sloc (Corresponding_Body (Decl));
829 if Is_Array_Type (T) then
830 Constraints := New_List;
831 for J in 1 .. Number_Dimensions (T) loop
833 -- Build an array subtype declaration with the nominal subtype and
834 -- the bounds of the actual. Add the declaration in front of the
835 -- local declarations for the subprogram, for analysis before any
836 -- reference to the formal in the body.
839 Make_Attribute_Reference (Loc,
841 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
842 Attribute_Name => Name_First,
843 Expressions => New_List (
844 Make_Integer_Literal (Loc, J)));
847 Make_Attribute_Reference (Loc,
849 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
850 Attribute_Name => Name_Last,
851 Expressions => New_List (
852 Make_Integer_Literal (Loc, J)));
854 Append (Make_Range (Loc, Lo, Hi), Constraints);
857 -- If the type has unknown discriminants there is no constrained
858 -- subtype to build. This is never called for a formal or for a
859 -- lhs, so returning the type is ok ???
861 elsif Has_Unknown_Discriminants (T) then
865 Constraints := New_List;
867 -- Type T is a generic derived type, inherit the discriminants from
870 if Is_Private_Type (T)
871 and then No (Full_View (T))
873 -- T was flagged as an error if it was declared as a formal
874 -- derived type with known discriminants. In this case there
875 -- is no need to look at the parent type since T already carries
876 -- its own discriminants.
878 and then not Error_Posted (T)
880 Disc_Type := Etype (Base_Type (T));
885 Discr := First_Discriminant (Disc_Type);
886 while Present (Discr) loop
887 Append_To (Constraints,
888 Make_Selected_Component (Loc,
890 Duplicate_Subexpr_No_Checks (Obj),
891 Selector_Name => New_Occurrence_Of (Discr, Loc)));
892 Next_Discriminant (Discr);
896 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
897 Set_Is_Internal (Subt);
900 Make_Subtype_Declaration (Loc,
901 Defining_Identifier => Subt,
902 Subtype_Indication =>
903 Make_Subtype_Indication (Loc,
904 Subtype_Mark => New_Occurrence_Of (T, Loc),
906 Make_Index_Or_Discriminant_Constraint (Loc,
907 Constraints => Constraints)));
909 Mark_Rewrite_Insertion (Decl);
911 end Build_Actual_Subtype;
913 ---------------------------------------
914 -- Build_Actual_Subtype_Of_Component --
915 ---------------------------------------
917 function Build_Actual_Subtype_Of_Component
919 N : Node_Id) return Node_Id
921 Loc : constant Source_Ptr := Sloc (N);
922 P : constant Node_Id := Prefix (N);
925 Index_Typ : Entity_Id;
927 Desig_Typ : Entity_Id;
928 -- This is either a copy of T, or if T is an access type, then it is
929 -- the directly designated type of this access type.
931 function Build_Actual_Array_Constraint return List_Id;
932 -- If one or more of the bounds of the component depends on
933 -- discriminants, build actual constraint using the discriminants
936 function Build_Actual_Record_Constraint return List_Id;
937 -- Similar to previous one, for discriminated components constrained
938 -- by the discriminant of the enclosing object.
940 -----------------------------------
941 -- Build_Actual_Array_Constraint --
942 -----------------------------------
944 function Build_Actual_Array_Constraint return List_Id is
945 Constraints : constant List_Id := New_List;
953 Indx := First_Index (Desig_Typ);
954 while Present (Indx) loop
955 Old_Lo := Type_Low_Bound (Etype (Indx));
956 Old_Hi := Type_High_Bound (Etype (Indx));
958 if Denotes_Discriminant (Old_Lo) then
960 Make_Selected_Component (Loc,
961 Prefix => New_Copy_Tree (P),
962 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
965 Lo := New_Copy_Tree (Old_Lo);
967 -- The new bound will be reanalyzed in the enclosing
968 -- declaration. For literal bounds that come from a type
969 -- declaration, the type of the context must be imposed, so
970 -- insure that analysis will take place. For non-universal
971 -- types this is not strictly necessary.
973 Set_Analyzed (Lo, False);
976 if Denotes_Discriminant (Old_Hi) then
978 Make_Selected_Component (Loc,
979 Prefix => New_Copy_Tree (P),
980 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
983 Hi := New_Copy_Tree (Old_Hi);
984 Set_Analyzed (Hi, False);
987 Append (Make_Range (Loc, Lo, Hi), Constraints);
992 end Build_Actual_Array_Constraint;
994 ------------------------------------
995 -- Build_Actual_Record_Constraint --
996 ------------------------------------
998 function Build_Actual_Record_Constraint return List_Id is
999 Constraints : constant List_Id := New_List;
1004 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1005 while Present (D) loop
1006 if Denotes_Discriminant (Node (D)) then
1007 D_Val := Make_Selected_Component (Loc,
1008 Prefix => New_Copy_Tree (P),
1009 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1012 D_Val := New_Copy_Tree (Node (D));
1015 Append (D_Val, Constraints);
1020 end Build_Actual_Record_Constraint;
1022 -- Start of processing for Build_Actual_Subtype_Of_Component
1025 -- Why the test for Spec_Expression mode here???
1027 if In_Spec_Expression then
1030 -- More comments for the rest of this body would be good ???
1032 elsif Nkind (N) = N_Explicit_Dereference then
1033 if Is_Composite_Type (T)
1034 and then not Is_Constrained (T)
1035 and then not (Is_Class_Wide_Type (T)
1036 and then Is_Constrained (Root_Type (T)))
1037 and then not Has_Unknown_Discriminants (T)
1039 -- If the type of the dereference is already constrained, it is an
1042 if Is_Array_Type (Etype (N))
1043 and then Is_Constrained (Etype (N))
1047 Remove_Side_Effects (P);
1048 return Build_Actual_Subtype (T, N);
1055 if Ekind (T) = E_Access_Subtype then
1056 Desig_Typ := Designated_Type (T);
1061 if Ekind (Desig_Typ) = E_Array_Subtype then
1062 Id := First_Index (Desig_Typ);
1063 while Present (Id) loop
1064 Index_Typ := Underlying_Type (Etype (Id));
1066 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1068 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1070 Remove_Side_Effects (P);
1072 Build_Component_Subtype
1073 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1079 elsif Is_Composite_Type (Desig_Typ)
1080 and then Has_Discriminants (Desig_Typ)
1081 and then not Has_Unknown_Discriminants (Desig_Typ)
1083 if Is_Private_Type (Desig_Typ)
1084 and then No (Discriminant_Constraint (Desig_Typ))
1086 Desig_Typ := Full_View (Desig_Typ);
1089 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1090 while Present (D) loop
1091 if Denotes_Discriminant (Node (D)) then
1092 Remove_Side_Effects (P);
1094 Build_Component_Subtype (
1095 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1102 -- If none of the above, the actual and nominal subtypes are the same
1105 end Build_Actual_Subtype_Of_Component;
1107 -----------------------------
1108 -- Build_Component_Subtype --
1109 -----------------------------
1111 function Build_Component_Subtype
1114 T : Entity_Id) return Node_Id
1120 -- Unchecked_Union components do not require component subtypes
1122 if Is_Unchecked_Union (T) then
1126 Subt := Make_Temporary (Loc, 'S');
1127 Set_Is_Internal (Subt);
1130 Make_Subtype_Declaration (Loc,
1131 Defining_Identifier => Subt,
1132 Subtype_Indication =>
1133 Make_Subtype_Indication (Loc,
1134 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1136 Make_Index_Or_Discriminant_Constraint (Loc,
1137 Constraints => C)));
1139 Mark_Rewrite_Insertion (Decl);
1141 end Build_Component_Subtype;
1143 ----------------------------------
1144 -- Build_Default_Init_Cond_Call --
1145 ----------------------------------
1147 function Build_Default_Init_Cond_Call
1150 Typ : Entity_Id) return Node_Id
1152 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1153 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1157 Make_Procedure_Call_Statement (Loc,
1158 Name => New_Occurrence_Of (Proc_Id, Loc),
1159 Parameter_Associations => New_List (
1160 Make_Unchecked_Type_Conversion (Loc,
1161 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1162 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1163 end Build_Default_Init_Cond_Call;
1165 ----------------------------------------------
1166 -- Build_Default_Init_Cond_Procedure_Bodies --
1167 ----------------------------------------------
1169 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1170 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1171 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1172 -- body of the procedure which verifies the assumption of the pragma at
1173 -- run time. The generated body is added after the type declaration.
1175 --------------------------------------------
1176 -- Build_Default_Init_Cond_Procedure_Body --
1177 --------------------------------------------
1179 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1180 Param_Id : Entity_Id;
1181 -- The entity of the sole formal parameter of the default initial
1182 -- condition procedure.
1184 procedure Replace_Type_Reference (N : Node_Id);
1185 -- Replace a single reference to type Typ with a reference to formal
1186 -- parameter Param_Id.
1188 ----------------------------
1189 -- Replace_Type_Reference --
1190 ----------------------------
1192 procedure Replace_Type_Reference (N : Node_Id) is
1194 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1195 end Replace_Type_Reference;
1197 procedure Replace_Type_References is
1198 new Replace_Type_References_Generic (Replace_Type_Reference);
1202 Loc : constant Source_Ptr := Sloc (Typ);
1203 Prag : constant Node_Id :=
1204 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1205 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1206 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1207 Body_Decl : Node_Id;
1211 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1213 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1216 -- The procedure should be generated only for [sub]types subject to
1217 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1218 -- not get this specialized procedure.
1220 pragma Assert (Has_Default_Init_Cond (Typ));
1221 pragma Assert (Present (Prag));
1222 pragma Assert (Present (Proc_Id));
1224 -- Nothing to do if the body was already built
1226 if Present (Corresponding_Body (Spec_Decl)) then
1230 -- The related type may be subject to pragma Ghost. Set the mode now
1231 -- to ensure that the analysis and expansion produce Ghost nodes.
1233 Set_Ghost_Mode_From_Entity (Typ);
1235 Param_Id := First_Formal (Proc_Id);
1237 -- The pragma has an argument. Note that the argument is analyzed
1238 -- after all references to the current instance of the type are
1241 if Present (Pragma_Argument_Associations (Prag)) then
1243 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1245 if Nkind (Expr) = N_Null then
1246 Stmt := Make_Null_Statement (Loc);
1248 -- Preserve the original argument of the pragma by replicating it.
1249 -- Replace all references to the current instance of the type with
1250 -- references to the formal parameter.
1253 Expr := New_Copy_Tree (Expr);
1254 Replace_Type_References (Expr, Typ);
1257 -- pragma Check (Default_Initial_Condition, <Expr>);
1261 Pragma_Identifier =>
1262 Make_Identifier (Loc, Name_Check),
1264 Pragma_Argument_Associations => New_List (
1265 Make_Pragma_Argument_Association (Loc,
1267 Make_Identifier (Loc,
1268 Chars => Name_Default_Initial_Condition)),
1269 Make_Pragma_Argument_Association (Loc,
1270 Expression => Expr)));
1273 -- Otherwise the pragma appears without an argument
1276 Stmt := Make_Null_Statement (Loc);
1280 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1283 -- end <Typ>Default_Init_Cond;
1286 Make_Subprogram_Body (Loc,
1288 Copy_Separate_Tree (Specification (Spec_Decl)),
1289 Declarations => Empty_List,
1290 Handled_Statement_Sequence =>
1291 Make_Handled_Sequence_Of_Statements (Loc,
1292 Statements => New_List (Stmt)));
1294 -- Link the spec and body of the default initial condition procedure
1295 -- to prevent the generation of a duplicate body.
1297 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1298 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1300 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1301 Ghost_Mode := Save_Ghost_Mode;
1302 end Build_Default_Init_Cond_Procedure_Body;
1309 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1312 -- Inspect the private declarations looking for [sub]type declarations
1314 Decl := First (Priv_Decls);
1315 while Present (Decl) loop
1316 if Nkind_In (Decl, N_Full_Type_Declaration,
1317 N_Subtype_Declaration)
1319 Typ := Defining_Entity (Decl);
1321 -- Guard against partially decorate types due to previous errors
1323 if Is_Type (Typ) then
1325 -- If the type is subject to pragma Default_Initial_Condition,
1326 -- generate the body of the internal procedure which verifies
1327 -- the assertion of the pragma at run time.
1329 if Has_Default_Init_Cond (Typ) then
1330 Build_Default_Init_Cond_Procedure_Body (Typ);
1332 -- A derived type inherits the default initial condition
1333 -- procedure from its parent type.
1335 elsif Has_Inherited_Default_Init_Cond (Typ) then
1336 Inherit_Default_Init_Cond_Procedure (Typ);
1343 end Build_Default_Init_Cond_Procedure_Bodies;
1345 ---------------------------------------------------
1346 -- Build_Default_Init_Cond_Procedure_Declaration --
1347 ---------------------------------------------------
1349 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1350 Loc : constant Source_Ptr := Sloc (Typ);
1351 Prag : constant Node_Id :=
1352 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1354 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1356 Proc_Id : Entity_Id;
1359 -- The procedure should be generated only for types subject to pragma
1360 -- Default_Initial_Condition. Types that inherit the pragma do not get
1361 -- this specialized procedure.
1363 pragma Assert (Has_Default_Init_Cond (Typ));
1364 pragma Assert (Present (Prag));
1366 -- Nothing to do if default initial condition procedure already built
1368 if Present (Default_Init_Cond_Procedure (Typ)) then
1372 -- The related type may be subject to pragma Ghost. Set the mode now to
1373 -- ensure that the analysis and expansion produce Ghost nodes.
1375 Set_Ghost_Mode_From_Entity (Typ);
1378 Make_Defining_Identifier (Loc,
1379 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1381 -- Associate default initial condition procedure with the private type
1383 Set_Ekind (Proc_Id, E_Procedure);
1384 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1385 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1387 -- Mark the default initial condition procedure explicitly as Ghost
1388 -- because it does not come from source.
1390 if Ghost_Mode > None then
1391 Set_Is_Ghost_Entity (Proc_Id);
1395 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1397 Insert_After_And_Analyze (Prag,
1398 Make_Subprogram_Declaration (Loc,
1400 Make_Procedure_Specification (Loc,
1401 Defining_Unit_Name => Proc_Id,
1402 Parameter_Specifications => New_List (
1403 Make_Parameter_Specification (Loc,
1404 Defining_Identifier => Make_Temporary (Loc, 'I'),
1405 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1407 Ghost_Mode := Save_Ghost_Mode;
1408 end Build_Default_Init_Cond_Procedure_Declaration;
1410 ---------------------------
1411 -- Build_Default_Subtype --
1412 ---------------------------
1414 function Build_Default_Subtype
1416 N : Node_Id) return Entity_Id
1418 Loc : constant Source_Ptr := Sloc (N);
1422 -- The base type that is to be constrained by the defaults
1425 if not Has_Discriminants (T) or else Is_Constrained (T) then
1429 Bas := Base_Type (T);
1431 -- If T is non-private but its base type is private, this is the
1432 -- completion of a subtype declaration whose parent type is private
1433 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1434 -- are to be found in the full view of the base. Check that the private
1435 -- status of T and its base differ.
1437 if Is_Private_Type (Bas)
1438 and then not Is_Private_Type (T)
1439 and then Present (Full_View (Bas))
1441 Bas := Full_View (Bas);
1444 Disc := First_Discriminant (T);
1446 if No (Discriminant_Default_Value (Disc)) then
1451 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1452 Constraints : constant List_Id := New_List;
1456 while Present (Disc) loop
1457 Append_To (Constraints,
1458 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1459 Next_Discriminant (Disc);
1463 Make_Subtype_Declaration (Loc,
1464 Defining_Identifier => Act,
1465 Subtype_Indication =>
1466 Make_Subtype_Indication (Loc,
1467 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1469 Make_Index_Or_Discriminant_Constraint (Loc,
1470 Constraints => Constraints)));
1472 Insert_Action (N, Decl);
1474 -- If the context is a component declaration the subtype declaration
1475 -- will be analyzed when the enclosing type is frozen, otherwise do
1478 if Ekind (Current_Scope) /= E_Record_Type then
1484 end Build_Default_Subtype;
1486 --------------------------------------------
1487 -- Build_Discriminal_Subtype_Of_Component --
1488 --------------------------------------------
1490 function Build_Discriminal_Subtype_Of_Component
1491 (T : Entity_Id) return Node_Id
1493 Loc : constant Source_Ptr := Sloc (T);
1497 function Build_Discriminal_Array_Constraint return List_Id;
1498 -- If one or more of the bounds of the component depends on
1499 -- discriminants, build actual constraint using the discriminants
1502 function Build_Discriminal_Record_Constraint return List_Id;
1503 -- Similar to previous one, for discriminated components constrained by
1504 -- the discriminant of the enclosing object.
1506 ----------------------------------------
1507 -- Build_Discriminal_Array_Constraint --
1508 ----------------------------------------
1510 function Build_Discriminal_Array_Constraint return List_Id is
1511 Constraints : constant List_Id := New_List;
1519 Indx := First_Index (T);
1520 while Present (Indx) loop
1521 Old_Lo := Type_Low_Bound (Etype (Indx));
1522 Old_Hi := Type_High_Bound (Etype (Indx));
1524 if Denotes_Discriminant (Old_Lo) then
1525 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1528 Lo := New_Copy_Tree (Old_Lo);
1531 if Denotes_Discriminant (Old_Hi) then
1532 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1535 Hi := New_Copy_Tree (Old_Hi);
1538 Append (Make_Range (Loc, Lo, Hi), Constraints);
1543 end Build_Discriminal_Array_Constraint;
1545 -----------------------------------------
1546 -- Build_Discriminal_Record_Constraint --
1547 -----------------------------------------
1549 function Build_Discriminal_Record_Constraint return List_Id is
1550 Constraints : constant List_Id := New_List;
1555 D := First_Elmt (Discriminant_Constraint (T));
1556 while Present (D) loop
1557 if Denotes_Discriminant (Node (D)) then
1559 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1561 D_Val := New_Copy_Tree (Node (D));
1564 Append (D_Val, Constraints);
1569 end Build_Discriminal_Record_Constraint;
1571 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1574 if Ekind (T) = E_Array_Subtype then
1575 Id := First_Index (T);
1576 while Present (Id) loop
1577 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1579 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1581 return Build_Component_Subtype
1582 (Build_Discriminal_Array_Constraint, Loc, T);
1588 elsif Ekind (T) = E_Record_Subtype
1589 and then Has_Discriminants (T)
1590 and then not Has_Unknown_Discriminants (T)
1592 D := First_Elmt (Discriminant_Constraint (T));
1593 while Present (D) loop
1594 if Denotes_Discriminant (Node (D)) then
1595 return Build_Component_Subtype
1596 (Build_Discriminal_Record_Constraint, Loc, T);
1603 -- If none of the above, the actual and nominal subtypes are the same
1606 end Build_Discriminal_Subtype_Of_Component;
1608 ------------------------------
1609 -- Build_Elaboration_Entity --
1610 ------------------------------
1612 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1613 Loc : constant Source_Ptr := Sloc (N);
1615 Elab_Ent : Entity_Id;
1617 procedure Set_Package_Name (Ent : Entity_Id);
1618 -- Given an entity, sets the fully qualified name of the entity in
1619 -- Name_Buffer, with components separated by double underscores. This
1620 -- is a recursive routine that climbs the scope chain to Standard.
1622 ----------------------
1623 -- Set_Package_Name --
1624 ----------------------
1626 procedure Set_Package_Name (Ent : Entity_Id) is
1628 if Scope (Ent) /= Standard_Standard then
1629 Set_Package_Name (Scope (Ent));
1632 Nam : constant String := Get_Name_String (Chars (Ent));
1634 Name_Buffer (Name_Len + 1) := '_';
1635 Name_Buffer (Name_Len + 2) := '_';
1636 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1637 Name_Len := Name_Len + Nam'Length + 2;
1641 Get_Name_String (Chars (Ent));
1643 end Set_Package_Name;
1645 -- Start of processing for Build_Elaboration_Entity
1648 -- Ignore call if already constructed
1650 if Present (Elaboration_Entity (Spec_Id)) then
1653 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1654 -- no role in analysis.
1656 elsif ASIS_Mode then
1659 -- See if we need elaboration entity. We always need it for the dynamic
1660 -- elaboration model, since it is needed to properly generate the PE
1661 -- exception for access before elaboration.
1663 elsif Dynamic_Elaboration_Checks then
1666 -- For the static model, we don't need the elaboration counter if this
1667 -- unit is sure to have no elaboration code, since that means there
1668 -- is no elaboration unit to be called. Note that we can't just decide
1669 -- after the fact by looking to see whether there was elaboration code,
1670 -- because that's too late to make this decision.
1672 elsif Restriction_Active (No_Elaboration_Code) then
1675 -- Similarly, for the static model, we can skip the elaboration counter
1676 -- if we have the No_Multiple_Elaboration restriction, since for the
1677 -- static model, that's the only purpose of the counter (to avoid
1678 -- multiple elaboration).
1680 elsif Restriction_Active (No_Multiple_Elaboration) then
1684 -- Here we need the elaboration entity
1686 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1687 -- name with dots replaced by double underscore. We have to manually
1688 -- construct this name, since it will be elaborated in the outer scope,
1689 -- and thus will not have the unit name automatically prepended.
1691 Set_Package_Name (Spec_Id);
1692 Add_Str_To_Name_Buffer ("_E");
1694 -- Create elaboration counter
1696 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1697 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1700 Make_Object_Declaration (Loc,
1701 Defining_Identifier => Elab_Ent,
1702 Object_Definition =>
1703 New_Occurrence_Of (Standard_Short_Integer, Loc),
1704 Expression => Make_Integer_Literal (Loc, Uint_0));
1706 Push_Scope (Standard_Standard);
1707 Add_Global_Declaration (Decl);
1710 -- Reset True_Constant indication, since we will indeed assign a value
1711 -- to the variable in the binder main. We also kill the Current_Value
1712 -- and Last_Assignment fields for the same reason.
1714 Set_Is_True_Constant (Elab_Ent, False);
1715 Set_Current_Value (Elab_Ent, Empty);
1716 Set_Last_Assignment (Elab_Ent, Empty);
1718 -- We do not want any further qualification of the name (if we did not
1719 -- do this, we would pick up the name of the generic package in the case
1720 -- of a library level generic instantiation).
1722 Set_Has_Qualified_Name (Elab_Ent);
1723 Set_Has_Fully_Qualified_Name (Elab_Ent);
1724 end Build_Elaboration_Entity;
1726 --------------------------------
1727 -- Build_Explicit_Dereference --
1728 --------------------------------
1730 procedure Build_Explicit_Dereference
1734 Loc : constant Source_Ptr := Sloc (Expr);
1737 -- An entity of a type with a reference aspect is overloaded with
1738 -- both interpretations: with and without the dereference. Now that
1739 -- the dereference is made explicit, set the type of the node properly,
1740 -- to prevent anomalies in the backend. Same if the expression is an
1741 -- overloaded function call whose return type has a reference aspect.
1743 if Is_Entity_Name (Expr) then
1744 Set_Etype (Expr, Etype (Entity (Expr)));
1746 elsif Nkind (Expr) = N_Function_Call then
1747 Set_Etype (Expr, Etype (Name (Expr)));
1750 Set_Is_Overloaded (Expr, False);
1752 -- The expression will often be a generalized indexing that yields a
1753 -- container element that is then dereferenced, in which case the
1754 -- generalized indexing call is also non-overloaded.
1756 if Nkind (Expr) = N_Indexed_Component
1757 and then Present (Generalized_Indexing (Expr))
1759 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1763 Make_Explicit_Dereference (Loc,
1765 Make_Selected_Component (Loc,
1766 Prefix => Relocate_Node (Expr),
1767 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1768 Set_Etype (Prefix (Expr), Etype (Disc));
1769 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1770 end Build_Explicit_Dereference;
1772 -----------------------------------
1773 -- Cannot_Raise_Constraint_Error --
1774 -----------------------------------
1776 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1778 if Compile_Time_Known_Value (Expr) then
1781 elsif Do_Range_Check (Expr) then
1784 elsif Raises_Constraint_Error (Expr) then
1788 case Nkind (Expr) is
1789 when N_Identifier =>
1792 when N_Expanded_Name =>
1795 when N_Selected_Component =>
1796 return not Do_Discriminant_Check (Expr);
1798 when N_Attribute_Reference =>
1799 if Do_Overflow_Check (Expr) then
1802 elsif No (Expressions (Expr)) then
1810 N := First (Expressions (Expr));
1811 while Present (N) loop
1812 if Cannot_Raise_Constraint_Error (N) then
1823 when N_Type_Conversion =>
1824 if Do_Overflow_Check (Expr)
1825 or else Do_Length_Check (Expr)
1826 or else Do_Tag_Check (Expr)
1830 return Cannot_Raise_Constraint_Error (Expression (Expr));
1833 when N_Unchecked_Type_Conversion =>
1834 return Cannot_Raise_Constraint_Error (Expression (Expr));
1837 if Do_Overflow_Check (Expr) then
1840 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1847 if Do_Division_Check (Expr)
1849 Do_Overflow_Check (Expr)
1854 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1856 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1875 N_Op_Shift_Right_Arithmetic |
1879 if Do_Overflow_Check (Expr) then
1883 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1885 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1892 end Cannot_Raise_Constraint_Error;
1894 -----------------------------------------
1895 -- Check_Dynamically_Tagged_Expression --
1896 -----------------------------------------
1898 procedure Check_Dynamically_Tagged_Expression
1901 Related_Nod : Node_Id)
1904 pragma Assert (Is_Tagged_Type (Typ));
1906 -- In order to avoid spurious errors when analyzing the expanded code,
1907 -- this check is done only for nodes that come from source and for
1908 -- actuals of generic instantiations.
1910 if (Comes_From_Source (Related_Nod)
1911 or else In_Generic_Actual (Expr))
1912 and then (Is_Class_Wide_Type (Etype (Expr))
1913 or else Is_Dynamically_Tagged (Expr))
1914 and then Is_Tagged_Type (Typ)
1915 and then not Is_Class_Wide_Type (Typ)
1917 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1919 end Check_Dynamically_Tagged_Expression;
1921 --------------------------
1922 -- Check_Fully_Declared --
1923 --------------------------
1925 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1927 if Ekind (T) = E_Incomplete_Type then
1929 -- Ada 2005 (AI-50217): If the type is available through a limited
1930 -- with_clause, verify that its full view has been analyzed.
1932 if From_Limited_With (T)
1933 and then Present (Non_Limited_View (T))
1934 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1936 -- The non-limited view is fully declared
1942 ("premature usage of incomplete}", N, First_Subtype (T));
1945 -- Need comments for these tests ???
1947 elsif Has_Private_Component (T)
1948 and then not Is_Generic_Type (Root_Type (T))
1949 and then not In_Spec_Expression
1951 -- Special case: if T is the anonymous type created for a single
1952 -- task or protected object, use the name of the source object.
1954 if Is_Concurrent_Type (T)
1955 and then not Comes_From_Source (T)
1956 and then Nkind (N) = N_Object_Declaration
1959 ("type of& has incomplete component",
1960 N, Defining_Identifier (N));
1963 ("premature usage of incomplete}",
1964 N, First_Subtype (T));
1967 end Check_Fully_Declared;
1969 -------------------------------------------
1970 -- Check_Function_With_Address_Parameter --
1971 -------------------------------------------
1973 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1978 F := First_Formal (Subp_Id);
1979 while Present (F) loop
1982 if Is_Private_Type (T) and then Present (Full_View (T)) then
1986 if Is_Descendent_Of_Address (T) or else Is_Limited_Type (T) then
1987 Set_Is_Pure (Subp_Id, False);
1993 end Check_Function_With_Address_Parameter;
1995 -------------------------------------
1996 -- Check_Function_Writable_Actuals --
1997 -------------------------------------
1999 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2000 Writable_Actuals_List : Elist_Id := No_Elist;
2001 Identifiers_List : Elist_Id := No_Elist;
2002 Aggr_Error_Node : Node_Id := Empty;
2003 Error_Node : Node_Id := Empty;
2005 procedure Collect_Identifiers (N : Node_Id);
2006 -- In a single traversal of subtree N collect in Writable_Actuals_List
2007 -- all the actuals of functions with writable actuals, and in the list
2008 -- Identifiers_List collect all the identifiers that are not actuals of
2009 -- functions with writable actuals. If a writable actual is referenced
2010 -- twice as writable actual then Error_Node is set to reference its
2011 -- second occurrence, the error is reported, and the tree traversal
2014 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2015 -- Return the entity associated with the function call
2017 procedure Preanalyze_Without_Errors (N : Node_Id);
2018 -- Preanalyze N without reporting errors. Very dubious, you can't just
2019 -- go analyzing things more than once???
2021 -------------------------
2022 -- Collect_Identifiers --
2023 -------------------------
2025 procedure Collect_Identifiers (N : Node_Id) is
2027 function Check_Node (N : Node_Id) return Traverse_Result;
2028 -- Process a single node during the tree traversal to collect the
2029 -- writable actuals of functions and all the identifiers which are
2030 -- not writable actuals of functions.
2032 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2033 -- Returns True if List has a node whose Entity is Entity (N)
2035 -------------------------
2036 -- Check_Function_Call --
2037 -------------------------
2039 function Check_Node (N : Node_Id) return Traverse_Result is
2040 Is_Writable_Actual : Boolean := False;
2044 if Nkind (N) = N_Identifier then
2046 -- No analysis possible if the entity is not decorated
2048 if No (Entity (N)) then
2051 -- Don't collect identifiers of packages, called functions, etc
2053 elsif Ekind_In (Entity (N), E_Package,
2060 -- For rewritten nodes, continue the traversal in the original
2061 -- subtree. Needed to handle aggregates in original expressions
2062 -- extracted from the tree by Remove_Side_Effects.
2064 elsif Is_Rewrite_Substitution (N) then
2065 Collect_Identifiers (Original_Node (N));
2068 -- For now we skip aggregate discriminants, since they require
2069 -- performing the analysis in two phases to identify conflicts:
2070 -- first one analyzing discriminants and second one analyzing
2071 -- the rest of components (since at run time, discriminants are
2072 -- evaluated prior to components): too much computation cost
2073 -- to identify a corner case???
2075 elsif Nkind (Parent (N)) = N_Component_Association
2076 and then Nkind_In (Parent (Parent (N)),
2078 N_Extension_Aggregate)
2081 Choice : constant Node_Id := First (Choices (Parent (N)));
2084 if Ekind (Entity (N)) = E_Discriminant then
2087 elsif Expression (Parent (N)) = N
2088 and then Nkind (Choice) = N_Identifier
2089 and then Ekind (Entity (Choice)) = E_Discriminant
2095 -- Analyze if N is a writable actual of a function
2097 elsif Nkind (Parent (N)) = N_Function_Call then
2099 Call : constant Node_Id := Parent (N);
2104 Id := Get_Function_Id (Call);
2106 -- In case of previous error, no check is possible
2112 if Ekind_In (Id, E_Function, E_Generic_Function)
2113 and then Has_Out_Or_In_Out_Parameter (Id)
2115 Formal := First_Formal (Id);
2116 Actual := First_Actual (Call);
2117 while Present (Actual) and then Present (Formal) loop
2119 if Ekind_In (Formal, E_Out_Parameter,
2122 Is_Writable_Actual := True;
2128 Next_Formal (Formal);
2129 Next_Actual (Actual);
2135 if Is_Writable_Actual then
2137 -- Skip checking the error in non-elementary types since
2138 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2139 -- store this actual in Writable_Actuals_List since it is
2140 -- needed to perform checks on other constructs that have
2141 -- arbitrary order of evaluation (for example, aggregates).
2143 if not Is_Elementary_Type (Etype (N)) then
2144 if not Contains (Writable_Actuals_List, N) then
2145 Append_New_Elmt (N, To => Writable_Actuals_List);
2148 -- Second occurrence of an elementary type writable actual
2150 elsif Contains (Writable_Actuals_List, N) then
2152 -- Report the error on the second occurrence of the
2153 -- identifier. We cannot assume that N is the second
2154 -- occurrence (according to their location in the
2155 -- sources), since Traverse_Func walks through Field2
2156 -- last (see comment in the body of Traverse_Func).
2162 Elmt := First_Elmt (Writable_Actuals_List);
2163 while Present (Elmt)
2164 and then Entity (Node (Elmt)) /= Entity (N)
2169 if Sloc (N) > Sloc (Node (Elmt)) then
2172 Error_Node := Node (Elmt);
2176 ("value may be affected by call to & "
2177 & "because order of evaluation is arbitrary",
2182 -- First occurrence of a elementary type writable actual
2185 Append_New_Elmt (N, To => Writable_Actuals_List);
2189 if Identifiers_List = No_Elist then
2190 Identifiers_List := New_Elmt_List;
2193 Append_Unique_Elmt (N, Identifiers_List);
2206 N : Node_Id) return Boolean
2208 pragma Assert (Nkind (N) in N_Has_Entity);
2213 if List = No_Elist then
2217 Elmt := First_Elmt (List);
2218 while Present (Elmt) loop
2219 if Entity (Node (Elmt)) = Entity (N) then
2233 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2234 -- The traversal procedure
2236 -- Start of processing for Collect_Identifiers
2239 if Present (Error_Node) then
2243 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2248 end Collect_Identifiers;
2250 ---------------------
2251 -- Get_Function_Id --
2252 ---------------------
2254 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2255 Nam : constant Node_Id := Name (Call);
2259 if Nkind (Nam) = N_Explicit_Dereference then
2261 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2263 elsif Nkind (Nam) = N_Selected_Component then
2264 Id := Entity (Selector_Name (Nam));
2266 elsif Nkind (Nam) = N_Indexed_Component then
2267 Id := Entity (Selector_Name (Prefix (Nam)));
2274 end Get_Function_Id;
2276 -------------------------------
2277 -- Preanalyze_Without_Errors --
2278 -------------------------------
2280 procedure Preanalyze_Without_Errors (N : Node_Id) is
2281 Status : constant Boolean := Get_Ignore_Errors;
2283 Set_Ignore_Errors (True);
2285 Set_Ignore_Errors (Status);
2286 end Preanalyze_Without_Errors;
2288 -- Start of processing for Check_Function_Writable_Actuals
2291 -- The check only applies to Ada 2012 code on which Check_Actuals has
2292 -- been set, and only to constructs that have multiple constituents
2293 -- whose order of evaluation is not specified by the language.
2295 if Ada_Version < Ada_2012
2296 or else not Check_Actuals (N)
2297 or else (not (Nkind (N) in N_Op)
2298 and then not (Nkind (N) in N_Membership_Test)
2299 and then not Nkind_In (N, N_Range,
2301 N_Extension_Aggregate,
2302 N_Full_Type_Declaration,
2304 N_Procedure_Call_Statement,
2305 N_Entry_Call_Statement))
2306 or else (Nkind (N) = N_Full_Type_Declaration
2307 and then not Is_Record_Type (Defining_Identifier (N)))
2309 -- In addition, this check only applies to source code, not to code
2310 -- generated by constraint checks.
2312 or else not Comes_From_Source (N)
2317 -- If a construct C has two or more direct constituents that are names
2318 -- or expressions whose evaluation may occur in an arbitrary order, at
2319 -- least one of which contains a function call with an in out or out
2320 -- parameter, then the construct is legal only if: for each name N that
2321 -- is passed as a parameter of mode in out or out to some inner function
2322 -- call C2 (not including the construct C itself), there is no other
2323 -- name anywhere within a direct constituent of the construct C other
2324 -- than the one containing C2, that is known to refer to the same
2325 -- object (RM 6.4.1(6.17/3)).
2329 Collect_Identifiers (Low_Bound (N));
2330 Collect_Identifiers (High_Bound (N));
2332 when N_Op | N_Membership_Test =>
2337 Collect_Identifiers (Left_Opnd (N));
2339 if Present (Right_Opnd (N)) then
2340 Collect_Identifiers (Right_Opnd (N));
2343 if Nkind_In (N, N_In, N_Not_In)
2344 and then Present (Alternatives (N))
2346 Expr := First (Alternatives (N));
2347 while Present (Expr) loop
2348 Collect_Identifiers (Expr);
2355 when N_Full_Type_Declaration =>
2357 function Get_Record_Part (N : Node_Id) return Node_Id;
2358 -- Return the record part of this record type definition
2360 function Get_Record_Part (N : Node_Id) return Node_Id is
2361 Type_Def : constant Node_Id := Type_Definition (N);
2363 if Nkind (Type_Def) = N_Derived_Type_Definition then
2364 return Record_Extension_Part (Type_Def);
2368 end Get_Record_Part;
2371 Def_Id : Entity_Id := Defining_Identifier (N);
2372 Rec : Node_Id := Get_Record_Part (N);
2375 -- No need to perform any analysis if the record has no
2378 if No (Rec) or else No (Component_List (Rec)) then
2382 -- Collect the identifiers starting from the deepest
2383 -- derivation. Done to report the error in the deepest
2387 if Present (Component_List (Rec)) then
2388 Comp := First (Component_Items (Component_List (Rec)));
2389 while Present (Comp) loop
2390 if Nkind (Comp) = N_Component_Declaration
2391 and then Present (Expression (Comp))
2393 Collect_Identifiers (Expression (Comp));
2400 exit when No (Underlying_Type (Etype (Def_Id)))
2401 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2404 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2405 Rec := Get_Record_Part (Parent (Def_Id));
2409 when N_Subprogram_Call |
2410 N_Entry_Call_Statement =>
2412 Id : constant Entity_Id := Get_Function_Id (N);
2417 Formal := First_Formal (Id);
2418 Actual := First_Actual (N);
2419 while Present (Actual) and then Present (Formal) loop
2420 if Ekind_In (Formal, E_Out_Parameter,
2423 Collect_Identifiers (Actual);
2426 Next_Formal (Formal);
2427 Next_Actual (Actual);
2432 N_Extension_Aggregate =>
2436 Comp_Expr : Node_Id;
2439 -- Handle the N_Others_Choice of array aggregates with static
2440 -- bounds. There is no need to perform this analysis in
2441 -- aggregates without static bounds since we cannot evaluate
2442 -- if the N_Others_Choice covers several elements. There is
2443 -- no need to handle the N_Others choice of record aggregates
2444 -- since at this stage it has been already expanded by
2445 -- Resolve_Record_Aggregate.
2447 if Is_Array_Type (Etype (N))
2448 and then Nkind (N) = N_Aggregate
2449 and then Present (Aggregate_Bounds (N))
2450 and then Compile_Time_Known_Bounds (Etype (N))
2451 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2453 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2456 Count_Components : Uint := Uint_0;
2457 Num_Components : Uint;
2458 Others_Assoc : Node_Id;
2459 Others_Choice : Node_Id := Empty;
2460 Others_Box_Present : Boolean := False;
2463 -- Count positional associations
2465 if Present (Expressions (N)) then
2466 Comp_Expr := First (Expressions (N));
2467 while Present (Comp_Expr) loop
2468 Count_Components := Count_Components + 1;
2473 -- Count the rest of elements and locate the N_Others
2476 Assoc := First (Component_Associations (N));
2477 while Present (Assoc) loop
2478 Choice := First (Choices (Assoc));
2479 while Present (Choice) loop
2480 if Nkind (Choice) = N_Others_Choice then
2481 Others_Assoc := Assoc;
2482 Others_Choice := Choice;
2483 Others_Box_Present := Box_Present (Assoc);
2485 -- Count several components
2487 elsif Nkind_In (Choice, N_Range,
2488 N_Subtype_Indication)
2489 or else (Is_Entity_Name (Choice)
2490 and then Is_Type (Entity (Choice)))
2495 Get_Index_Bounds (Choice, L, H);
2497 (Compile_Time_Known_Value (L)
2498 and then Compile_Time_Known_Value (H));
2501 + Expr_Value (H) - Expr_Value (L) + 1;
2504 -- Count single component. No other case available
2505 -- since we are handling an aggregate with static
2509 pragma Assert (Is_OK_Static_Expression (Choice)
2510 or else Nkind (Choice) = N_Identifier
2511 or else Nkind (Choice) = N_Integer_Literal);
2513 Count_Components := Count_Components + 1;
2523 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2524 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2526 pragma Assert (Count_Components <= Num_Components);
2528 -- Handle the N_Others choice if it covers several
2531 if Present (Others_Choice)
2532 and then (Num_Components - Count_Components) > 1
2534 if not Others_Box_Present then
2536 -- At this stage, if expansion is active, the
2537 -- expression of the others choice has not been
2538 -- analyzed. Hence we generate a duplicate and
2539 -- we analyze it silently to have available the
2540 -- minimum decoration required to collect the
2543 if not Expander_Active then
2544 Comp_Expr := Expression (Others_Assoc);
2547 New_Copy_Tree (Expression (Others_Assoc));
2548 Preanalyze_Without_Errors (Comp_Expr);
2551 Collect_Identifiers (Comp_Expr);
2553 if Writable_Actuals_List /= No_Elist then
2555 -- As suggested by Robert, at current stage we
2556 -- report occurrences of this case as warnings.
2559 ("writable function parameter may affect "
2560 & "value in other component because order "
2561 & "of evaluation is unspecified??",
2562 Node (First_Elmt (Writable_Actuals_List)));
2568 -- For an array aggregate, a discrete_choice_list that has
2569 -- a nonstatic range is considered as two or more separate
2570 -- occurrences of the expression (RM 6.4.1(20/3)).
2572 elsif Is_Array_Type (Etype (N))
2573 and then Nkind (N) = N_Aggregate
2574 and then Present (Aggregate_Bounds (N))
2575 and then not Compile_Time_Known_Bounds (Etype (N))
2577 -- Collect identifiers found in the dynamic bounds
2580 Count_Components : Natural := 0;
2581 Low, High : Node_Id;
2584 Assoc := First (Component_Associations (N));
2585 while Present (Assoc) loop
2586 Choice := First (Choices (Assoc));
2587 while Present (Choice) loop
2588 if Nkind_In (Choice, N_Range,
2589 N_Subtype_Indication)
2590 or else (Is_Entity_Name (Choice)
2591 and then Is_Type (Entity (Choice)))
2593 Get_Index_Bounds (Choice, Low, High);
2595 if not Compile_Time_Known_Value (Low) then
2596 Collect_Identifiers (Low);
2598 if No (Aggr_Error_Node) then
2599 Aggr_Error_Node := Low;
2603 if not Compile_Time_Known_Value (High) then
2604 Collect_Identifiers (High);
2606 if No (Aggr_Error_Node) then
2607 Aggr_Error_Node := High;
2611 -- The RM rule is violated if there is more than
2612 -- a single choice in a component association.
2615 Count_Components := Count_Components + 1;
2617 if No (Aggr_Error_Node)
2618 and then Count_Components > 1
2620 Aggr_Error_Node := Choice;
2623 if not Compile_Time_Known_Value (Choice) then
2624 Collect_Identifiers (Choice);
2636 -- Handle ancestor part of extension aggregates
2638 if Nkind (N) = N_Extension_Aggregate then
2639 Collect_Identifiers (Ancestor_Part (N));
2642 -- Handle positional associations
2644 if Present (Expressions (N)) then
2645 Comp_Expr := First (Expressions (N));
2646 while Present (Comp_Expr) loop
2647 if not Is_OK_Static_Expression (Comp_Expr) then
2648 Collect_Identifiers (Comp_Expr);
2655 -- Handle discrete associations
2657 if Present (Component_Associations (N)) then
2658 Assoc := First (Component_Associations (N));
2659 while Present (Assoc) loop
2661 if not Box_Present (Assoc) then
2662 Choice := First (Choices (Assoc));
2663 while Present (Choice) loop
2665 -- For now we skip discriminants since it requires
2666 -- performing the analysis in two phases: first one
2667 -- analyzing discriminants and second one analyzing
2668 -- the rest of components since discriminants are
2669 -- evaluated prior to components: too much extra
2670 -- work to detect a corner case???
2672 if Nkind (Choice) in N_Has_Entity
2673 and then Present (Entity (Choice))
2674 and then Ekind (Entity (Choice)) = E_Discriminant
2678 elsif Box_Present (Assoc) then
2682 if not Analyzed (Expression (Assoc)) then
2684 New_Copy_Tree (Expression (Assoc));
2685 Set_Parent (Comp_Expr, Parent (N));
2686 Preanalyze_Without_Errors (Comp_Expr);
2688 Comp_Expr := Expression (Assoc);
2691 Collect_Identifiers (Comp_Expr);
2707 -- No further action needed if we already reported an error
2709 if Present (Error_Node) then
2713 -- Check violation of RM 6.20/3 in aggregates
2715 if Present (Aggr_Error_Node)
2716 and then Writable_Actuals_List /= No_Elist
2719 ("value may be affected by call in other component because they "
2720 & "are evaluated in unspecified order",
2721 Node (First_Elmt (Writable_Actuals_List)));
2725 -- Check if some writable argument of a function is referenced
2727 if Writable_Actuals_List /= No_Elist
2728 and then Identifiers_List /= No_Elist
2735 Elmt_1 := First_Elmt (Writable_Actuals_List);
2736 while Present (Elmt_1) loop
2737 Elmt_2 := First_Elmt (Identifiers_List);
2738 while Present (Elmt_2) loop
2739 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2740 case Nkind (Parent (Node (Elmt_2))) is
2742 N_Component_Association |
2743 N_Component_Declaration =>
2745 ("value may be affected by call in other "
2746 & "component because they are evaluated "
2747 & "in unspecified order",
2750 when N_In | N_Not_In =>
2752 ("value may be affected by call in other "
2753 & "alternative because they are evaluated "
2754 & "in unspecified order",
2759 ("value of actual may be affected by call in "
2760 & "other actual because they are evaluated "
2761 & "in unspecified order",
2773 end Check_Function_Writable_Actuals;
2775 --------------------------------
2776 -- Check_Implicit_Dereference --
2777 --------------------------------
2779 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2785 if Nkind (N) = N_Indexed_Component
2786 and then Present (Generalized_Indexing (N))
2788 Nam := Generalized_Indexing (N);
2793 if Ada_Version < Ada_2012
2794 or else not Has_Implicit_Dereference (Base_Type (Typ))
2798 elsif not Comes_From_Source (N)
2799 and then Nkind (N) /= N_Indexed_Component
2803 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2807 Disc := First_Discriminant (Typ);
2808 while Present (Disc) loop
2809 if Has_Implicit_Dereference (Disc) then
2810 Desig := Designated_Type (Etype (Disc));
2811 Add_One_Interp (Nam, Disc, Desig);
2813 -- If the node is a generalized indexing, add interpretation
2814 -- to that node as well, for subsequent resolution.
2816 if Nkind (N) = N_Indexed_Component then
2817 Add_One_Interp (N, Disc, Desig);
2820 -- If the operation comes from a generic unit and the context
2821 -- is a selected component, the selector name may be global
2822 -- and set in the instance already. Remove the entity to
2823 -- force resolution of the selected component, and the
2824 -- generation of an explicit dereference if needed.
2827 and then Nkind (Parent (Nam)) = N_Selected_Component
2829 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2835 Next_Discriminant (Disc);
2838 end Check_Implicit_Dereference;
2840 ----------------------------------
2841 -- Check_Internal_Protected_Use --
2842 ----------------------------------
2844 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2850 while Present (S) loop
2851 if S = Standard_Standard then
2854 elsif Ekind (S) = E_Function
2855 and then Ekind (Scope (S)) = E_Protected_Type
2864 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2866 -- An indirect function call (e.g. a callback within a protected
2867 -- function body) is not statically illegal. If the access type is
2868 -- anonymous and is the type of an access parameter, the scope of Nam
2869 -- will be the protected type, but it is not a protected operation.
2871 if Ekind (Nam) = E_Subprogram_Type
2873 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2877 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2879 ("within protected function cannot use protected "
2880 & "procedure in renaming or as generic actual", N);
2882 elsif Nkind (N) = N_Attribute_Reference then
2884 ("within protected function cannot take access of "
2885 & " protected procedure", N);
2889 ("within protected function, protected object is constant", N);
2891 ("\cannot call operation that may modify it", N);
2894 end Check_Internal_Protected_Use;
2896 ---------------------------------------
2897 -- Check_Later_Vs_Basic_Declarations --
2898 ---------------------------------------
2900 procedure Check_Later_Vs_Basic_Declarations
2902 During_Parsing : Boolean)
2904 Body_Sloc : Source_Ptr;
2907 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2908 -- Return whether Decl is considered as a declarative item.
2909 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2910 -- When During_Parsing is False, the semantics of SPARK is followed.
2912 -------------------------------
2913 -- Is_Later_Declarative_Item --
2914 -------------------------------
2916 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2918 if Nkind (Decl) in N_Later_Decl_Item then
2921 elsif Nkind (Decl) = N_Pragma then
2924 elsif During_Parsing then
2927 -- In SPARK, a package declaration is not considered as a later
2928 -- declarative item.
2930 elsif Nkind (Decl) = N_Package_Declaration then
2933 -- In SPARK, a renaming is considered as a later declarative item
2935 elsif Nkind (Decl) in N_Renaming_Declaration then
2941 end Is_Later_Declarative_Item;
2943 -- Start of processing for Check_Later_Vs_Basic_Declarations
2946 Decl := First (Decls);
2948 -- Loop through sequence of basic declarative items
2950 Outer : while Present (Decl) loop
2951 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2952 and then Nkind (Decl) not in N_Body_Stub
2956 -- Once a body is encountered, we only allow later declarative
2957 -- items. The inner loop checks the rest of the list.
2960 Body_Sloc := Sloc (Decl);
2962 Inner : while Present (Decl) loop
2963 if not Is_Later_Declarative_Item (Decl) then
2964 if During_Parsing then
2965 if Ada_Version = Ada_83 then
2966 Error_Msg_Sloc := Body_Sloc;
2968 ("(Ada 83) decl cannot appear after body#", Decl);
2971 Error_Msg_Sloc := Body_Sloc;
2972 Check_SPARK_05_Restriction
2973 ("decl cannot appear after body#", Decl);
2981 end Check_Later_Vs_Basic_Declarations;
2983 ---------------------------
2984 -- Check_No_Hidden_State --
2985 ---------------------------
2987 procedure Check_No_Hidden_State (Id : Entity_Id) is
2988 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2989 -- Determine whether the entity of a package denoted by Pkg has a null
2992 -----------------------------
2993 -- Has_Null_Abstract_State --
2994 -----------------------------
2996 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2997 States : constant Elist_Id := Abstract_States (Pkg);
3000 -- Check first available state of related package. A null abstract
3001 -- state always appears as the sole element of the state list.
3005 and then Is_Null_State (Node (First_Elmt (States)));
3006 end Has_Null_Abstract_State;
3010 Context : Entity_Id := Empty;
3011 Not_Visible : Boolean := False;
3014 -- Start of processing for Check_No_Hidden_State
3017 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3019 -- Find the proper context where the object or state appears
3022 while Present (Scop) loop
3025 -- Keep track of the context's visibility
3027 Not_Visible := Not_Visible or else In_Private_Part (Context);
3029 -- Prevent the search from going too far
3031 if Context = Standard_Standard then
3034 -- Objects and states that appear immediately within a subprogram or
3035 -- inside a construct nested within a subprogram do not introduce a
3036 -- hidden state. They behave as local variable declarations.
3038 elsif Is_Subprogram (Context) then
3041 -- When examining a package body, use the entity of the spec as it
3042 -- carries the abstract state declarations.
3044 elsif Ekind (Context) = E_Package_Body then
3045 Context := Spec_Entity (Context);
3048 -- Stop the traversal when a package subject to a null abstract state
3051 if Ekind_In (Context, E_Generic_Package, E_Package)
3052 and then Has_Null_Abstract_State (Context)
3057 Scop := Scope (Scop);
3060 -- At this point we know that there is at least one package with a null
3061 -- abstract state in visibility. Emit an error message unconditionally
3062 -- if the entity being processed is a state because the placement of the
3063 -- related package is irrelevant. This is not the case for objects as
3064 -- the intermediate context matters.
3066 if Present (Context)
3067 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3069 Error_Msg_N ("cannot introduce hidden state &", Id);
3070 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3072 end Check_No_Hidden_State;
3074 ----------------------------------------
3075 -- Check_Nonvolatile_Function_Profile --
3076 ----------------------------------------
3078 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3082 -- Inspect all formal parameters
3084 Formal := First_Formal (Func_Id);
3085 while Present (Formal) loop
3086 if Is_Effectively_Volatile (Etype (Formal)) then
3088 ("nonvolatile function & cannot have a volatile parameter",
3092 Next_Formal (Formal);
3095 -- Inspect the return type
3097 if Is_Effectively_Volatile (Etype (Func_Id)) then
3099 ("nonvolatile function & cannot have a volatile return type",
3102 end Check_Nonvolatile_Function_Profile;
3104 ------------------------------------------
3105 -- Check_Potentially_Blocking_Operation --
3106 ------------------------------------------
3108 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3112 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3113 -- When pragma Detect_Blocking is active, the run time will raise
3114 -- Program_Error. Here we only issue a warning, since we generally
3115 -- support the use of potentially blocking operations in the absence
3118 -- Indirect blocking through a subprogram call cannot be diagnosed
3119 -- statically without interprocedural analysis, so we do not attempt
3122 S := Scope (Current_Scope);
3123 while Present (S) and then S /= Standard_Standard loop
3124 if Is_Protected_Type (S) then
3126 ("potentially blocking operation in protected operation??", N);
3132 end Check_Potentially_Blocking_Operation;
3134 ---------------------------------
3135 -- Check_Result_And_Post_State --
3136 ---------------------------------
3138 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3139 procedure Check_Result_And_Post_State_In_Pragma
3141 Result_Seen : in out Boolean);
3142 -- Determine whether pragma Prag mentions attribute 'Result and whether
3143 -- the pragma contains an expression that evaluates differently in pre-
3144 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3145 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3147 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3148 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3149 -- formal parameter.
3151 -------------------------------------------
3152 -- Check_Result_And_Post_State_In_Pragma --
3153 -------------------------------------------
3155 procedure Check_Result_And_Post_State_In_Pragma
3157 Result_Seen : in out Boolean)
3159 procedure Check_Expression (Expr : Node_Id);
3160 -- Perform the 'Result and post-state checks on a given expression
3162 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3163 -- Attempt to find attribute 'Result in a subtree denoted by N
3165 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3166 -- Determine whether source node N denotes "True" or "False"
3168 function Mentions_Post_State (N : Node_Id) return Boolean;
3169 -- Determine whether a subtree denoted by N mentions any construct
3170 -- that denotes a post-state.
3172 procedure Check_Function_Result is
3173 new Traverse_Proc (Is_Function_Result);
3175 ----------------------
3176 -- Check_Expression --
3177 ----------------------
3179 procedure Check_Expression (Expr : Node_Id) is
3181 if not Is_Trivial_Boolean (Expr) then
3182 Check_Function_Result (Expr);
3184 if not Mentions_Post_State (Expr) then
3185 if Pragma_Name (Prag) = Name_Contract_Cases then
3187 ("contract case does not check the outcome of calling "
3188 & "&?T?", Expr, Subp_Id);
3190 elsif Pragma_Name (Prag) = Name_Refined_Post then
3192 ("refined postcondition does not check the outcome of "
3193 & "calling &?T?", Prag, Subp_Id);
3197 ("postcondition does not check the outcome of calling "
3198 & "&?T?", Prag, Subp_Id);
3202 end Check_Expression;
3204 ------------------------
3205 -- Is_Function_Result --
3206 ------------------------
3208 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3210 if Is_Attribute_Result (N) then
3211 Result_Seen := True;
3214 -- Continue the traversal
3219 end Is_Function_Result;
3221 ------------------------
3222 -- Is_Trivial_Boolean --
3223 ------------------------
3225 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3228 Comes_From_Source (N)
3229 and then Is_Entity_Name (N)
3230 and then (Entity (N) = Standard_True
3232 Entity (N) = Standard_False);
3233 end Is_Trivial_Boolean;
3235 -------------------------
3236 -- Mentions_Post_State --
3237 -------------------------
3239 function Mentions_Post_State (N : Node_Id) return Boolean is
3240 Post_State_Seen : Boolean := False;
3242 function Is_Post_State (N : Node_Id) return Traverse_Result;
3243 -- Attempt to find a construct that denotes a post-state. If this
3244 -- is the case, set flag Post_State_Seen.
3250 function Is_Post_State (N : Node_Id) return Traverse_Result is
3254 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3255 Post_State_Seen := True;
3258 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3261 -- The entity may be modifiable through an implicit
3265 or else Ekind (Ent) in Assignable_Kind
3266 or else (Is_Access_Type (Etype (Ent))
3267 and then Nkind (Parent (N)) =
3268 N_Selected_Component)
3270 Post_State_Seen := True;
3274 elsif Nkind (N) = N_Attribute_Reference then
3275 if Attribute_Name (N) = Name_Old then
3278 elsif Attribute_Name (N) = Name_Result then
3279 Post_State_Seen := True;
3287 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3289 -- Start of processing for Mentions_Post_State
3292 Find_Post_State (N);
3294 return Post_State_Seen;
3295 end Mentions_Post_State;
3299 Expr : constant Node_Id :=
3301 (First (Pragma_Argument_Associations (Prag)));
3302 Nam : constant Name_Id := Pragma_Name (Prag);
3305 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3308 -- Examine all consequences
3310 if Nam = Name_Contract_Cases then
3311 CCase := First (Component_Associations (Expr));
3312 while Present (CCase) loop
3313 Check_Expression (Expression (CCase));
3318 -- Examine the expression of a postcondition
3320 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3321 Name_Refined_Post));
3322 Check_Expression (Expr);
3324 end Check_Result_And_Post_State_In_Pragma;
3326 --------------------------
3327 -- Has_In_Out_Parameter --
3328 --------------------------
3330 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3334 -- Traverse the formals looking for an IN OUT parameter
3336 Formal := First_Formal (Subp_Id);
3337 while Present (Formal) loop
3338 if Ekind (Formal) = E_In_Out_Parameter then
3342 Next_Formal (Formal);
3346 end Has_In_Out_Parameter;
3350 Items : constant Node_Id := Contract (Subp_Id);
3351 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3352 Case_Prag : Node_Id := Empty;
3353 Post_Prag : Node_Id := Empty;
3355 Seen_In_Case : Boolean := False;
3356 Seen_In_Post : Boolean := False;
3357 Spec_Id : Entity_Id;
3359 -- Start of processing for Check_Result_And_Post_State
3362 -- The lack of attribute 'Result or a post-state is classified as a
3363 -- suspicious contract. Do not perform the check if the corresponding
3364 -- swich is not set.
3366 if not Warn_On_Suspicious_Contract then
3369 -- Nothing to do if there is no contract
3371 elsif No (Items) then
3375 -- Retrieve the entity of the subprogram spec (if any)
3377 if Nkind (Subp_Decl) = N_Subprogram_Body
3378 and then Present (Corresponding_Spec (Subp_Decl))
3380 Spec_Id := Corresponding_Spec (Subp_Decl);
3382 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3383 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3385 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3391 -- Examine all postconditions for attribute 'Result and a post-state
3393 Prag := Pre_Post_Conditions (Items);
3394 while Present (Prag) loop
3395 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3397 and then not Error_Posted (Prag)
3400 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3403 Prag := Next_Pragma (Prag);
3406 -- Examine the contract cases of the subprogram for attribute 'Result
3407 -- and a post-state.
3409 Prag := Contract_Test_Cases (Items);
3410 while Present (Prag) loop
3411 if Pragma_Name (Prag) = Name_Contract_Cases
3412 and then not Error_Posted (Prag)
3415 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3418 Prag := Next_Pragma (Prag);
3421 -- Do not emit any errors if the subprogram is not a function
3423 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3426 -- Regardless of whether the function has postconditions or contract
3427 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3428 -- parameter is always treated as a result.
3430 elsif Has_In_Out_Parameter (Spec_Id) then
3433 -- The function has both a postcondition and contract cases and they do
3434 -- not mention attribute 'Result.
3436 elsif Present (Case_Prag)
3437 and then not Seen_In_Case
3438 and then Present (Post_Prag)
3439 and then not Seen_In_Post
3442 ("neither postcondition nor contract cases mention function "
3443 & "result?T?", Post_Prag);
3445 -- The function has contract cases only and they do not mention
3446 -- attribute 'Result.
3448 elsif Present (Case_Prag) and then not Seen_In_Case then
3449 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3451 -- The function has postconditions only and they do not mention
3452 -- attribute 'Result.
3454 elsif Present (Post_Prag) and then not Seen_In_Post then
3456 ("postcondition does not mention function result?T?", Post_Prag);
3458 end Check_Result_And_Post_State;
3460 ------------------------------
3461 -- Check_Unprotected_Access --
3462 ------------------------------
3464 procedure Check_Unprotected_Access
3468 Cont_Encl_Typ : Entity_Id;
3469 Pref_Encl_Typ : Entity_Id;
3471 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3472 -- Check whether Obj is a private component of a protected object.
3473 -- Return the protected type where the component resides, Empty
3476 function Is_Public_Operation return Boolean;
3477 -- Verify that the enclosing operation is callable from outside the
3478 -- protected object, to minimize false positives.
3480 ------------------------------
3481 -- Enclosing_Protected_Type --
3482 ------------------------------
3484 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3486 if Is_Entity_Name (Obj) then
3488 Ent : Entity_Id := Entity (Obj);
3491 -- The object can be a renaming of a private component, use
3492 -- the original record component.
3494 if Is_Prival (Ent) then
3495 Ent := Prival_Link (Ent);
3498 if Is_Protected_Type (Scope (Ent)) then
3504 -- For indexed and selected components, recursively check the prefix
3506 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3507 return Enclosing_Protected_Type (Prefix (Obj));
3509 -- The object does not denote a protected component
3514 end Enclosing_Protected_Type;
3516 -------------------------
3517 -- Is_Public_Operation --
3518 -------------------------
3520 function Is_Public_Operation return Boolean is
3526 while Present (S) and then S /= Pref_Encl_Typ loop
3527 if Scope (S) = Pref_Encl_Typ then
3528 E := First_Entity (Pref_Encl_Typ);
3530 and then E /= First_Private_Entity (Pref_Encl_Typ)
3544 end Is_Public_Operation;
3546 -- Start of processing for Check_Unprotected_Access
3549 if Nkind (Expr) = N_Attribute_Reference
3550 and then Attribute_Name (Expr) = Name_Unchecked_Access
3552 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3553 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3555 -- Check whether we are trying to export a protected component to a
3556 -- context with an equal or lower access level.
3558 if Present (Pref_Encl_Typ)
3559 and then No (Cont_Encl_Typ)
3560 and then Is_Public_Operation
3561 and then Scope_Depth (Pref_Encl_Typ) >=
3562 Object_Access_Level (Context)
3565 ("??possible unprotected access to protected data", Expr);
3568 end Check_Unprotected_Access;
3570 ------------------------------
3571 -- Check_Unused_Body_States --
3572 ------------------------------
3574 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3575 Legal_Constits : Boolean := True;
3576 -- This flag designates whether all constituents of pragma Refined_State
3577 -- are legal. The flag is used to suppress the generation of potentially
3578 -- misleading error messages due to a malformed pragma.
3580 procedure Process_Refinement_Clause
3583 -- Inspect all constituents of refinement clause Clause and remove any
3584 -- matches from body state list States.
3586 -------------------------------
3587 -- Process_Refinement_Clause --
3588 -------------------------------
3590 procedure Process_Refinement_Clause
3594 procedure Process_Constituent (Constit : Node_Id);
3595 -- Remove constituent Constit from body state list States
3597 -------------------------
3598 -- Process_Constituent --
3599 -------------------------
3601 procedure Process_Constituent (Constit : Node_Id) is
3602 Constit_Id : Entity_Id;
3605 if Error_Posted (Constit) then
3606 Legal_Constits := False;
3609 -- Guard against illegal constituents. Only abstract states and
3610 -- objects can appear on the right hand side of a refinement.
3612 if Is_Entity_Name (Constit) then
3613 Constit_Id := Entity_Of (Constit);
3615 if Present (Constit_Id)
3616 and then Ekind_In (Constit_Id, E_Abstract_State,
3620 Remove (States, Constit_Id);
3623 end Process_Constituent;
3629 -- Start of processing for Process_Refinement_Clause
3632 if Nkind (Clause) = N_Component_Association then
3633 Constit := Expression (Clause);
3635 -- Multiple constituents appear as an aggregate
3637 if Nkind (Constit) = N_Aggregate then
3638 Constit := First (Expressions (Constit));
3639 while Present (Constit) loop
3640 Process_Constituent (Constit);
3644 -- Various forms of a single constituent
3647 Process_Constituent (Constit);
3650 end Process_Refinement_Clause;
3654 Prag : constant Node_Id :=
3655 Get_Pragma (Body_Id, Pragma_Refined_State);
3656 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3660 -- Start of processing for Check_Unused_Body_States
3663 -- Inspect the clauses of pragma Refined_State and determine whether all
3664 -- visible states declared within the body of the package participate in
3667 if Present (Prag) then
3668 Clause := Expression (Get_Argument (Prag, Spec_Id));
3669 States := Collect_Body_States (Body_Id);
3671 -- Multiple non-null state refinements appear as an aggregate
3673 if Nkind (Clause) = N_Aggregate then
3674 Clause := First (Component_Associations (Clause));
3675 while Present (Clause) loop
3676 Process_Refinement_Clause (Clause, States);
3680 -- Various forms of a single state refinement
3683 Process_Refinement_Clause (Clause, States);
3686 -- Ensure that all abstract states and objects declared in the body
3687 -- state space of the related package are utilized as constituents.
3689 if Legal_Constits then
3690 Report_Unused_Body_States (Body_Id, States);
3693 end Check_Unused_Body_States;
3695 -------------------------
3696 -- Collect_Body_States --
3697 -------------------------
3699 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3700 procedure Collect_Visible_States
3701 (Pack_Id : Entity_Id;
3702 States : in out Elist_Id);
3703 -- Gather the entities of all abstract states and objects declared in
3704 -- the visible state space of package Pack_Id.
3706 ----------------------------
3707 -- Collect_Visible_States --
3708 ----------------------------
3710 procedure Collect_Visible_States
3711 (Pack_Id : Entity_Id;
3712 States : in out Elist_Id)
3714 Item_Id : Entity_Id;
3717 -- Traverse the entity chain of the package and inspect all visible
3720 Item_Id := First_Entity (Pack_Id);
3721 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3723 -- Do not consider internally generated items as those cannot be
3724 -- named and participate in refinement.
3726 if not Comes_From_Source (Item_Id) then
3729 elsif Ekind (Item_Id) = E_Abstract_State then
3730 Append_New_Elmt (Item_Id, States);
3732 -- Do not consider objects that map generic formals to their
3733 -- actuals, as the formals cannot be named from the outside and
3734 -- participate in refinement.
3736 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3737 and then No (Corresponding_Generic_Association
3738 (Declaration_Node (Item_Id)))
3740 Append_New_Elmt (Item_Id, States);
3742 -- Recursively gather the visible states of a nested package
3744 elsif Ekind (Item_Id) = E_Package then
3745 Collect_Visible_States (Item_Id, States);
3748 Next_Entity (Item_Id);
3750 end Collect_Visible_States;
3754 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3756 Item_Id : Entity_Id;
3757 States : Elist_Id := No_Elist;
3759 -- Start of processing for Collect_Body_States
3762 -- Inspect the declarations of the body looking for source objects,
3763 -- packages and package instantiations.
3765 Decl := First (Declarations (Body_Decl));
3766 while Present (Decl) loop
3768 -- Capture source objects as internally generated temporaries cannot
3769 -- be named and participate in refinement.
3771 if Nkind (Decl) = N_Object_Declaration then
3772 Item_Id := Defining_Entity (Decl);
3774 if Comes_From_Source (Item_Id) then
3775 Append_New_Elmt (Item_Id, States);
3778 -- Capture the visible abstract states and objects of a source
3779 -- package [instantiation].
3781 elsif Nkind (Decl) = N_Package_Declaration then
3782 Item_Id := Defining_Entity (Decl);
3784 if Comes_From_Source (Item_Id) then
3785 Collect_Visible_States (Item_Id, States);
3793 end Collect_Body_States;
3795 ------------------------
3796 -- Collect_Interfaces --
3797 ------------------------
3799 procedure Collect_Interfaces
3801 Ifaces_List : out Elist_Id;
3802 Exclude_Parents : Boolean := False;
3803 Use_Full_View : Boolean := True)
3805 procedure Collect (Typ : Entity_Id);
3806 -- Subsidiary subprogram used to traverse the whole list
3807 -- of directly and indirectly implemented interfaces
3813 procedure Collect (Typ : Entity_Id) is
3814 Ancestor : Entity_Id;
3822 -- Handle private types and subtypes
3825 and then Is_Private_Type (Typ)
3826 and then Present (Full_View (Typ))
3828 Full_T := Full_View (Typ);
3830 if Ekind (Full_T) = E_Record_Subtype then
3831 Full_T := Full_View (Etype (Typ));
3835 -- Include the ancestor if we are generating the whole list of
3836 -- abstract interfaces.
3838 if Etype (Full_T) /= Typ
3840 -- Protect the frontend against wrong sources. For example:
3843 -- type A is tagged null record;
3844 -- type B is new A with private;
3845 -- type C is new A with private;
3847 -- type B is new C with null record;
3848 -- type C is new B with null record;
3851 and then Etype (Full_T) /= T
3853 Ancestor := Etype (Full_T);
3856 if Is_Interface (Ancestor) and then not Exclude_Parents then
3857 Append_Unique_Elmt (Ancestor, Ifaces_List);
3861 -- Traverse the graph of ancestor interfaces
3863 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3864 Id := First (Abstract_Interface_List (Full_T));
3865 while Present (Id) loop
3866 Iface := Etype (Id);
3868 -- Protect against wrong uses. For example:
3869 -- type I is interface;
3870 -- type O is tagged null record;
3871 -- type Wrong is new I and O with null record; -- ERROR
3873 if Is_Interface (Iface) then
3875 and then Etype (T) /= T
3876 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3881 Append_Unique_Elmt (Iface, Ifaces_List);
3890 -- Start of processing for Collect_Interfaces
3893 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3894 Ifaces_List := New_Elmt_List;
3896 end Collect_Interfaces;
3898 ----------------------------------
3899 -- Collect_Interface_Components --
3900 ----------------------------------
3902 procedure Collect_Interface_Components
3903 (Tagged_Type : Entity_Id;
3904 Components_List : out Elist_Id)
3906 procedure Collect (Typ : Entity_Id);
3907 -- Subsidiary subprogram used to climb to the parents
3913 procedure Collect (Typ : Entity_Id) is
3914 Tag_Comp : Entity_Id;
3915 Parent_Typ : Entity_Id;
3918 -- Handle private types
3920 if Present (Full_View (Etype (Typ))) then
3921 Parent_Typ := Full_View (Etype (Typ));
3923 Parent_Typ := Etype (Typ);
3926 if Parent_Typ /= Typ
3928 -- Protect the frontend against wrong sources. For example:
3931 -- type A is tagged null record;
3932 -- type B is new A with private;
3933 -- type C is new A with private;
3935 -- type B is new C with null record;
3936 -- type C is new B with null record;
3939 and then Parent_Typ /= Tagged_Type
3941 Collect (Parent_Typ);
3944 -- Collect the components containing tags of secondary dispatch
3947 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3948 while Present (Tag_Comp) loop
3949 pragma Assert (Present (Related_Type (Tag_Comp)));
3950 Append_Elmt (Tag_Comp, Components_List);
3952 Tag_Comp := Next_Tag_Component (Tag_Comp);
3956 -- Start of processing for Collect_Interface_Components
3959 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3960 and then Is_Tagged_Type (Tagged_Type));
3962 Components_List := New_Elmt_List;
3963 Collect (Tagged_Type);
3964 end Collect_Interface_Components;
3966 -----------------------------
3967 -- Collect_Interfaces_Info --
3968 -----------------------------
3970 procedure Collect_Interfaces_Info
3972 Ifaces_List : out Elist_Id;
3973 Components_List : out Elist_Id;
3974 Tags_List : out Elist_Id)
3976 Comps_List : Elist_Id;
3977 Comp_Elmt : Elmt_Id;
3978 Comp_Iface : Entity_Id;
3979 Iface_Elmt : Elmt_Id;
3982 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3983 -- Search for the secondary tag associated with the interface type
3984 -- Iface that is implemented by T.
3990 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3993 if not Is_CPP_Class (T) then
3994 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3996 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4000 and then Is_Tag (Node (ADT))
4001 and then Related_Type (Node (ADT)) /= Iface
4003 -- Skip secondary dispatch table referencing thunks to user
4004 -- defined primitives covered by this interface.
4006 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4009 -- Skip secondary dispatch tables of Ada types
4011 if not Is_CPP_Class (T) then
4013 -- Skip secondary dispatch table referencing thunks to
4014 -- predefined primitives.
4016 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4019 -- Skip secondary dispatch table referencing user-defined
4020 -- primitives covered by this interface.
4022 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4025 -- Skip secondary dispatch table referencing predefined
4028 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4033 pragma Assert (Is_Tag (Node (ADT)));
4037 -- Start of processing for Collect_Interfaces_Info
4040 Collect_Interfaces (T, Ifaces_List);
4041 Collect_Interface_Components (T, Comps_List);
4043 -- Search for the record component and tag associated with each
4044 -- interface type of T.
4046 Components_List := New_Elmt_List;
4047 Tags_List := New_Elmt_List;
4049 Iface_Elmt := First_Elmt (Ifaces_List);
4050 while Present (Iface_Elmt) loop
4051 Iface := Node (Iface_Elmt);
4053 -- Associate the primary tag component and the primary dispatch table
4054 -- with all the interfaces that are parents of T
4056 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4057 Append_Elmt (First_Tag_Component (T), Components_List);
4058 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4060 -- Otherwise search for the tag component and secondary dispatch
4064 Comp_Elmt := First_Elmt (Comps_List);
4065 while Present (Comp_Elmt) loop
4066 Comp_Iface := Related_Type (Node (Comp_Elmt));
4068 if Comp_Iface = Iface
4069 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4071 Append_Elmt (Node (Comp_Elmt), Components_List);
4072 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4076 Next_Elmt (Comp_Elmt);
4078 pragma Assert (Present (Comp_Elmt));
4081 Next_Elmt (Iface_Elmt);
4083 end Collect_Interfaces_Info;
4085 ---------------------
4086 -- Collect_Parents --
4087 ---------------------
4089 procedure Collect_Parents
4091 List : out Elist_Id;
4092 Use_Full_View : Boolean := True)
4094 Current_Typ : Entity_Id := T;
4095 Parent_Typ : Entity_Id;
4098 List := New_Elmt_List;
4100 -- No action if the if the type has no parents
4102 if T = Etype (T) then
4107 Parent_Typ := Etype (Current_Typ);
4109 if Is_Private_Type (Parent_Typ)
4110 and then Present (Full_View (Parent_Typ))
4111 and then Use_Full_View
4113 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4116 Append_Elmt (Parent_Typ, List);
4118 exit when Parent_Typ = Current_Typ;
4119 Current_Typ := Parent_Typ;
4121 end Collect_Parents;
4123 ----------------------------------
4124 -- Collect_Primitive_Operations --
4125 ----------------------------------
4127 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4128 B_Type : constant Entity_Id := Base_Type (T);
4129 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4130 B_Scope : Entity_Id := Scope (B_Type);
4134 Is_Type_In_Pkg : Boolean;
4135 Formal_Derived : Boolean := False;
4138 function Match (E : Entity_Id) return Boolean;
4139 -- True if E's base type is B_Type, or E is of an anonymous access type
4140 -- and the base type of its designated type is B_Type.
4146 function Match (E : Entity_Id) return Boolean is
4147 Etyp : Entity_Id := Etype (E);
4150 if Ekind (Etyp) = E_Anonymous_Access_Type then
4151 Etyp := Designated_Type (Etyp);
4154 -- In Ada 2012 a primitive operation may have a formal of an
4155 -- incomplete view of the parent type.
4157 return Base_Type (Etyp) = B_Type
4159 (Ada_Version >= Ada_2012
4160 and then Ekind (Etyp) = E_Incomplete_Type
4161 and then Full_View (Etyp) = B_Type);
4164 -- Start of processing for Collect_Primitive_Operations
4167 -- For tagged types, the primitive operations are collected as they
4168 -- are declared, and held in an explicit list which is simply returned.
4170 if Is_Tagged_Type (B_Type) then
4171 return Primitive_Operations (B_Type);
4173 -- An untagged generic type that is a derived type inherits the
4174 -- primitive operations of its parent type. Other formal types only
4175 -- have predefined operators, which are not explicitly represented.
4177 elsif Is_Generic_Type (B_Type) then
4178 if Nkind (B_Decl) = N_Formal_Type_Declaration
4179 and then Nkind (Formal_Type_Definition (B_Decl)) =
4180 N_Formal_Derived_Type_Definition
4182 Formal_Derived := True;
4184 return New_Elmt_List;
4188 Op_List := New_Elmt_List;
4190 if B_Scope = Standard_Standard then
4191 if B_Type = Standard_String then
4192 Append_Elmt (Standard_Op_Concat, Op_List);
4194 elsif B_Type = Standard_Wide_String then
4195 Append_Elmt (Standard_Op_Concatw, Op_List);
4201 -- Locate the primitive subprograms of the type
4204 -- The primitive operations appear after the base type, except
4205 -- if the derivation happens within the private part of B_Scope
4206 -- and the type is a private type, in which case both the type
4207 -- and some primitive operations may appear before the base
4208 -- type, and the list of candidates starts after the type.
4210 if In_Open_Scopes (B_Scope)
4211 and then Scope (T) = B_Scope
4212 and then In_Private_Part (B_Scope)
4214 Id := Next_Entity (T);
4216 -- In Ada 2012, If the type has an incomplete partial view, there
4217 -- may be primitive operations declared before the full view, so
4218 -- we need to start scanning from the incomplete view, which is
4219 -- earlier on the entity chain.
4221 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4222 and then Present (Incomplete_View (Parent (B_Type)))
4224 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4227 Id := Next_Entity (B_Type);
4230 -- Set flag if this is a type in a package spec
4233 Is_Package_Or_Generic_Package (B_Scope)
4235 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4238 while Present (Id) loop
4240 -- Test whether the result type or any of the parameter types of
4241 -- each subprogram following the type match that type when the
4242 -- type is declared in a package spec, is a derived type, or the
4243 -- subprogram is marked as primitive. (The Is_Primitive test is
4244 -- needed to find primitives of nonderived types in declarative
4245 -- parts that happen to override the predefined "=" operator.)
4247 -- Note that generic formal subprograms are not considered to be
4248 -- primitive operations and thus are never inherited.
4250 if Is_Overloadable (Id)
4251 and then (Is_Type_In_Pkg
4252 or else Is_Derived_Type (B_Type)
4253 or else Is_Primitive (Id))
4254 and then Nkind (Parent (Parent (Id)))
4255 not in N_Formal_Subprogram_Declaration
4263 Formal := First_Formal (Id);
4264 while Present (Formal) loop
4265 if Match (Formal) then
4270 Next_Formal (Formal);
4274 -- For a formal derived type, the only primitives are the ones
4275 -- inherited from the parent type. Operations appearing in the
4276 -- package declaration are not primitive for it.
4279 and then (not Formal_Derived or else Present (Alias (Id)))
4281 -- In the special case of an equality operator aliased to
4282 -- an overriding dispatching equality belonging to the same
4283 -- type, we don't include it in the list of primitives.
4284 -- This avoids inheriting multiple equality operators when
4285 -- deriving from untagged private types whose full type is
4286 -- tagged, which can otherwise cause ambiguities. Note that
4287 -- this should only happen for this kind of untagged parent
4288 -- type, since normally dispatching operations are inherited
4289 -- using the type's Primitive_Operations list.
4291 if Chars (Id) = Name_Op_Eq
4292 and then Is_Dispatching_Operation (Id)
4293 and then Present (Alias (Id))
4294 and then Present (Overridden_Operation (Alias (Id)))
4295 and then Base_Type (Etype (First_Entity (Id))) =
4296 Base_Type (Etype (First_Entity (Alias (Id))))
4300 -- Include the subprogram in the list of primitives
4303 Append_Elmt (Id, Op_List);
4310 -- For a type declared in System, some of its operations may
4311 -- appear in the target-specific extension to System.
4314 and then B_Scope = RTU_Entity (System)
4315 and then Present_System_Aux
4317 B_Scope := System_Aux_Id;
4318 Id := First_Entity (System_Aux_Id);
4324 end Collect_Primitive_Operations;
4326 -----------------------------------
4327 -- Compile_Time_Constraint_Error --
4328 -----------------------------------
4330 function Compile_Time_Constraint_Error
4333 Ent : Entity_Id := Empty;
4334 Loc : Source_Ptr := No_Location;
4335 Warn : Boolean := False) return Node_Id
4337 Msgc : String (1 .. Msg'Length + 3);
4338 -- Copy of message, with room for possible ?? or << and ! at end
4344 -- Start of processing for Compile_Time_Constraint_Error
4347 -- If this is a warning, convert it into an error if we are in code
4348 -- subject to SPARK_Mode being set ON.
4350 Error_Msg_Warn := SPARK_Mode /= On;
4352 -- A static constraint error in an instance body is not a fatal error.
4353 -- we choose to inhibit the message altogether, because there is no
4354 -- obvious node (for now) on which to post it. On the other hand the
4355 -- offending node must be replaced with a constraint_error in any case.
4357 -- No messages are generated if we already posted an error on this node
4359 if not Error_Posted (N) then
4360 if Loc /= No_Location then
4366 -- Copy message to Msgc, converting any ? in the message into
4367 -- < instead, so that we have an error in GNATprove mode.
4371 for J in 1 .. Msgl loop
4372 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4375 Msgc (J) := Msg (J);
4379 -- Message is a warning, even in Ada 95 case
4381 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4384 -- In Ada 83, all messages are warnings. In the private part and
4385 -- the body of an instance, constraint_checks are only warnings.
4386 -- We also make this a warning if the Warn parameter is set.
4389 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4397 elsif In_Instance_Not_Visible then
4404 -- Otherwise we have a real error message (Ada 95 static case)
4405 -- and we make this an unconditional message. Note that in the
4406 -- warning case we do not make the message unconditional, it seems
4407 -- quite reasonable to delete messages like this (about exceptions
4408 -- that will be raised) in dead code.
4416 -- One more test, skip the warning if the related expression is
4417 -- statically unevaluated, since we don't want to warn about what
4418 -- will happen when something is evaluated if it never will be
4421 if not Is_Statically_Unevaluated (N) then
4422 Error_Msg_Warn := SPARK_Mode /= On;
4424 if Present (Ent) then
4425 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4427 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4432 -- Check whether the context is an Init_Proc
4434 if Inside_Init_Proc then
4436 Conc_Typ : constant Entity_Id :=
4437 Corresponding_Concurrent_Type
4438 (Entity (Parameter_Type (First
4439 (Parameter_Specifications
4440 (Parent (Current_Scope))))));
4443 -- Don't complain if the corresponding concurrent type
4444 -- doesn't come from source (i.e. a single task/protected
4447 if Present (Conc_Typ)
4448 and then not Comes_From_Source (Conc_Typ)
4451 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4454 if GNATprove_Mode then
4456 ("\& would have been raised for objects of this "
4457 & "type", N, Standard_Constraint_Error, Eloc);
4460 ("\& will be raised for objects of this type??",
4461 N, Standard_Constraint_Error, Eloc);
4467 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4471 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4472 Set_Error_Posted (N);
4478 end Compile_Time_Constraint_Error;
4480 -----------------------
4481 -- Conditional_Delay --
4482 -----------------------
4484 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4486 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4487 Set_Has_Delayed_Freeze (New_Ent);
4489 end Conditional_Delay;
4491 ----------------------------
4492 -- Contains_Refined_State --
4493 ----------------------------
4495 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4496 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4497 -- Determine whether a dependency list mentions a state with a visible
4500 function Has_State_In_Global (List : Node_Id) return Boolean;
4501 -- Determine whether a global list mentions a state with a visible
4504 function Is_Refined_State (Item : Node_Id) return Boolean;
4505 -- Determine whether Item is a reference to an abstract state with a
4506 -- visible refinement.
4508 -----------------------------
4509 -- Has_State_In_Dependency --
4510 -----------------------------
4512 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4517 -- A null dependency list does not mention any states
4519 if Nkind (List) = N_Null then
4522 -- Dependency clauses appear as component associations of an
4525 elsif Nkind (List) = N_Aggregate
4526 and then Present (Component_Associations (List))
4528 Clause := First (Component_Associations (List));
4529 while Present (Clause) loop
4531 -- Inspect the outputs of a dependency clause
4533 Output := First (Choices (Clause));
4534 while Present (Output) loop
4535 if Is_Refined_State (Output) then
4542 -- Inspect the outputs of a dependency clause
4544 if Is_Refined_State (Expression (Clause)) then
4551 -- If we get here, then none of the dependency clauses mention a
4552 -- state with visible refinement.
4556 -- An illegal pragma managed to sneak in
4559 raise Program_Error;
4561 end Has_State_In_Dependency;
4563 -------------------------
4564 -- Has_State_In_Global --
4565 -------------------------
4567 function Has_State_In_Global (List : Node_Id) return Boolean is
4571 -- A null global list does not mention any states
4573 if Nkind (List) = N_Null then
4576 -- Simple global list or moded global list declaration
4578 elsif Nkind (List) = N_Aggregate then
4580 -- The declaration of a simple global list appear as a collection
4583 if Present (Expressions (List)) then
4584 Item := First (Expressions (List));
4585 while Present (Item) loop
4586 if Is_Refined_State (Item) then
4593 -- The declaration of a moded global list appears as a collection
4594 -- of component associations where individual choices denote
4598 Item := First (Component_Associations (List));
4599 while Present (Item) loop
4600 if Has_State_In_Global (Expression (Item)) then
4608 -- If we get here, then the simple/moded global list did not
4609 -- mention any states with a visible refinement.
4613 -- Single global item declaration
4615 elsif Is_Entity_Name (List) then
4616 return Is_Refined_State (List);
4618 -- An illegal pragma managed to sneak in
4621 raise Program_Error;
4623 end Has_State_In_Global;
4625 ----------------------
4626 -- Is_Refined_State --
4627 ----------------------
4629 function Is_Refined_State (Item : Node_Id) return Boolean is
4631 Item_Id : Entity_Id;
4634 if Nkind (Item) = N_Null then
4637 -- States cannot be subject to attribute 'Result. This case arises
4638 -- in dependency relations.
4640 elsif Nkind (Item) = N_Attribute_Reference
4641 and then Attribute_Name (Item) = Name_Result
4645 -- Multiple items appear as an aggregate. This case arises in
4646 -- dependency relations.
4648 elsif Nkind (Item) = N_Aggregate
4649 and then Present (Expressions (Item))
4651 Elmt := First (Expressions (Item));
4652 while Present (Elmt) loop
4653 if Is_Refined_State (Elmt) then
4660 -- If we get here, then none of the inputs or outputs reference a
4661 -- state with visible refinement.
4668 Item_Id := Entity_Of (Item);
4672 and then Ekind (Item_Id) = E_Abstract_State
4673 and then Has_Visible_Refinement (Item_Id);
4675 end Is_Refined_State;
4679 Arg : constant Node_Id :=
4680 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4681 Nam : constant Name_Id := Pragma_Name (Prag);
4683 -- Start of processing for Contains_Refined_State
4686 if Nam = Name_Depends then
4687 return Has_State_In_Dependency (Arg);
4689 else pragma Assert (Nam = Name_Global);
4690 return Has_State_In_Global (Arg);
4692 end Contains_Refined_State;
4694 -------------------------
4695 -- Copy_Component_List --
4696 -------------------------
4698 function Copy_Component_List
4700 Loc : Source_Ptr) return List_Id
4703 Comps : constant List_Id := New_List;
4706 Comp := First_Component (Underlying_Type (R_Typ));
4707 while Present (Comp) loop
4708 if Comes_From_Source (Comp) then
4710 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4713 Make_Component_Declaration (Loc,
4714 Defining_Identifier =>
4715 Make_Defining_Identifier (Loc, Chars (Comp)),
4716 Component_Definition =>
4718 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4722 Next_Component (Comp);
4726 end Copy_Component_List;
4728 -------------------------
4729 -- Copy_Parameter_List --
4730 -------------------------
4732 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4733 Loc : constant Source_Ptr := Sloc (Subp_Id);
4738 if No (First_Formal (Subp_Id)) then
4742 Formal := First_Formal (Subp_Id);
4743 while Present (Formal) loop
4745 Make_Parameter_Specification (Loc,
4746 Defining_Identifier =>
4747 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4748 In_Present => In_Present (Parent (Formal)),
4749 Out_Present => Out_Present (Parent (Formal)),
4751 New_Occurrence_Of (Etype (Formal), Loc),
4753 New_Copy_Tree (Expression (Parent (Formal)))));
4755 Next_Formal (Formal);
4760 end Copy_Parameter_List;
4762 --------------------------
4763 -- Copy_Subprogram_Spec --
4764 --------------------------
4766 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4768 Formal_Spec : Node_Id;
4772 -- The structure of the original tree must be replicated without any
4773 -- alterations. Use New_Copy_Tree for this purpose.
4775 Result := New_Copy_Tree (Spec);
4777 -- Create a new entity for the defining unit name
4779 Def_Id := Defining_Unit_Name (Result);
4780 Set_Defining_Unit_Name (Result,
4781 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4783 -- Create new entities for the formal parameters
4785 if Present (Parameter_Specifications (Result)) then
4786 Formal_Spec := First (Parameter_Specifications (Result));
4787 while Present (Formal_Spec) loop
4788 Def_Id := Defining_Identifier (Formal_Spec);
4789 Set_Defining_Identifier (Formal_Spec,
4790 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4797 end Copy_Subprogram_Spec;
4799 --------------------------------
4800 -- Corresponding_Generic_Type --
4801 --------------------------------
4803 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4809 if not Is_Generic_Actual_Type (T) then
4812 -- If the actual is the actual of an enclosing instance, resolution
4813 -- was correct in the generic.
4815 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4816 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4818 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4825 if Is_Wrapper_Package (Inst) then
4826 Inst := Related_Instance (Inst);
4831 (Specification (Unit_Declaration_Node (Inst)));
4833 -- Generic actual has the same name as the corresponding formal
4835 Typ := First_Entity (Gen);
4836 while Present (Typ) loop
4837 if Chars (Typ) = Chars (T) then
4846 end Corresponding_Generic_Type;
4848 --------------------
4849 -- Current_Entity --
4850 --------------------
4852 -- The currently visible definition for a given identifier is the
4853 -- one most chained at the start of the visibility chain, i.e. the
4854 -- one that is referenced by the Node_Id value of the name of the
4855 -- given identifier.
4857 function Current_Entity (N : Node_Id) return Entity_Id is
4859 return Get_Name_Entity_Id (Chars (N));
4862 -----------------------------
4863 -- Current_Entity_In_Scope --
4864 -----------------------------
4866 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4868 CS : constant Entity_Id := Current_Scope;
4870 Transient_Case : constant Boolean := Scope_Is_Transient;
4873 E := Get_Name_Entity_Id (Chars (N));
4875 and then Scope (E) /= CS
4876 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4882 end Current_Entity_In_Scope;
4888 function Current_Scope return Entity_Id is
4890 if Scope_Stack.Last = -1 then
4891 return Standard_Standard;
4894 C : constant Entity_Id :=
4895 Scope_Stack.Table (Scope_Stack.Last).Entity;
4900 return Standard_Standard;
4906 ------------------------
4907 -- Current_Subprogram --
4908 ------------------------
4910 function Current_Subprogram return Entity_Id is
4911 Scop : constant Entity_Id := Current_Scope;
4913 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4916 return Enclosing_Subprogram (Scop);
4918 end Current_Subprogram;
4920 ----------------------------------
4921 -- Deepest_Type_Access_Level --
4922 ----------------------------------
4924 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4926 if Ekind (Typ) = E_Anonymous_Access_Type
4927 and then not Is_Local_Anonymous_Access (Typ)
4928 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4930 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4934 Scope_Depth (Enclosing_Dynamic_Scope
4935 (Defining_Identifier
4936 (Associated_Node_For_Itype (Typ))));
4938 -- For generic formal type, return Int'Last (infinite).
4939 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4941 elsif Is_Generic_Type (Root_Type (Typ)) then
4942 return UI_From_Int (Int'Last);
4945 return Type_Access_Level (Typ);
4947 end Deepest_Type_Access_Level;
4949 ---------------------
4950 -- Defining_Entity --
4951 ---------------------
4953 function Defining_Entity
4955 Empty_On_Errors : Boolean := False) return Entity_Id
4957 Err : Entity_Id := Empty;
4961 when N_Abstract_Subprogram_Declaration |
4962 N_Expression_Function |
4963 N_Formal_Subprogram_Declaration |
4964 N_Generic_Package_Declaration |
4965 N_Generic_Subprogram_Declaration |
4966 N_Package_Declaration |
4968 N_Subprogram_Body_Stub |
4969 N_Subprogram_Declaration |
4970 N_Subprogram_Renaming_Declaration
4972 return Defining_Entity (Specification (N));
4974 when N_Component_Declaration |
4975 N_Defining_Program_Unit_Name |
4976 N_Discriminant_Specification |
4978 N_Entry_Declaration |
4979 N_Entry_Index_Specification |
4980 N_Exception_Declaration |
4981 N_Exception_Renaming_Declaration |
4982 N_Formal_Object_Declaration |
4983 N_Formal_Package_Declaration |
4984 N_Formal_Type_Declaration |
4985 N_Full_Type_Declaration |
4986 N_Implicit_Label_Declaration |
4987 N_Incomplete_Type_Declaration |
4988 N_Loop_Parameter_Specification |
4989 N_Number_Declaration |
4990 N_Object_Declaration |
4991 N_Object_Renaming_Declaration |
4992 N_Package_Body_Stub |
4993 N_Parameter_Specification |
4994 N_Private_Extension_Declaration |
4995 N_Private_Type_Declaration |
4997 N_Protected_Body_Stub |
4998 N_Protected_Type_Declaration |
4999 N_Single_Protected_Declaration |
5000 N_Single_Task_Declaration |
5001 N_Subtype_Declaration |
5004 N_Task_Type_Declaration
5006 return Defining_Identifier (N);
5009 return Defining_Entity (Proper_Body (N));
5011 when N_Function_Instantiation |
5012 N_Function_Specification |
5013 N_Generic_Function_Renaming_Declaration |
5014 N_Generic_Package_Renaming_Declaration |
5015 N_Generic_Procedure_Renaming_Declaration |
5017 N_Package_Instantiation |
5018 N_Package_Renaming_Declaration |
5019 N_Package_Specification |
5020 N_Procedure_Instantiation |
5021 N_Procedure_Specification
5024 Nam : constant Node_Id := Defining_Unit_Name (N);
5027 if Nkind (Nam) in N_Entity then
5030 -- For Error, make up a name and attach to declaration so we
5031 -- can continue semantic analysis.
5033 elsif Nam = Error then
5034 if Empty_On_Errors then
5037 Err := Make_Temporary (Sloc (N), 'T');
5038 Set_Defining_Unit_Name (N, Err);
5043 -- If not an entity, get defining identifier
5046 return Defining_Identifier (Nam);
5050 when N_Block_Statement |
5052 return Entity (Identifier (N));
5055 if Empty_On_Errors then
5058 raise Program_Error;
5062 end Defining_Entity;
5064 --------------------------
5065 -- Denotes_Discriminant --
5066 --------------------------
5068 function Denotes_Discriminant
5070 Check_Concurrent : Boolean := False) return Boolean
5075 if not Is_Entity_Name (N) or else No (Entity (N)) then
5081 -- If we are checking for a protected type, the discriminant may have
5082 -- been rewritten as the corresponding discriminal of the original type
5083 -- or of the corresponding concurrent record, depending on whether we
5084 -- are in the spec or body of the protected type.
5086 return Ekind (E) = E_Discriminant
5089 and then Ekind (E) = E_In_Parameter
5090 and then Present (Discriminal_Link (E))
5092 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5094 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5095 end Denotes_Discriminant;
5097 -------------------------
5098 -- Denotes_Same_Object --
5099 -------------------------
5101 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5102 Obj1 : Node_Id := A1;
5103 Obj2 : Node_Id := A2;
5105 function Has_Prefix (N : Node_Id) return Boolean;
5106 -- Return True if N has attribute Prefix
5108 function Is_Renaming (N : Node_Id) return Boolean;
5109 -- Return true if N names a renaming entity
5111 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5112 -- For renamings, return False if the prefix of any dereference within
5113 -- the renamed object_name is a variable, or any expression within the
5114 -- renamed object_name contains references to variables or calls on
5115 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5121 function Has_Prefix (N : Node_Id) return Boolean is
5125 N_Attribute_Reference,
5127 N_Explicit_Dereference,
5128 N_Indexed_Component,
5130 N_Selected_Component,
5138 function Is_Renaming (N : Node_Id) return Boolean is
5140 return Is_Entity_Name (N)
5141 and then Present (Renamed_Entity (Entity (N)));
5144 -----------------------
5145 -- Is_Valid_Renaming --
5146 -----------------------
5148 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5150 function Check_Renaming (N : Node_Id) return Boolean;
5151 -- Recursive function used to traverse all the prefixes of N
5153 function Check_Renaming (N : Node_Id) return Boolean is
5156 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5161 if Nkind (N) = N_Indexed_Component then
5166 Indx := First (Expressions (N));
5167 while Present (Indx) loop
5168 if not Is_OK_Static_Expression (Indx) then
5177 if Has_Prefix (N) then
5179 P : constant Node_Id := Prefix (N);
5182 if Nkind (N) = N_Explicit_Dereference
5183 and then Is_Variable (P)
5187 elsif Is_Entity_Name (P)
5188 and then Ekind (Entity (P)) = E_Function
5192 elsif Nkind (P) = N_Function_Call then
5196 -- Recursion to continue traversing the prefix of the
5197 -- renaming expression
5199 return Check_Renaming (P);
5206 -- Start of processing for Is_Valid_Renaming
5209 return Check_Renaming (N);
5210 end Is_Valid_Renaming;
5212 -- Start of processing for Denotes_Same_Object
5215 -- Both names statically denote the same stand-alone object or parameter
5216 -- (RM 6.4.1(6.5/3))
5218 if Is_Entity_Name (Obj1)
5219 and then Is_Entity_Name (Obj2)
5220 and then Entity (Obj1) = Entity (Obj2)
5225 -- For renamings, the prefix of any dereference within the renamed
5226 -- object_name is not a variable, and any expression within the
5227 -- renamed object_name contains no references to variables nor
5228 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5230 if Is_Renaming (Obj1) then
5231 if Is_Valid_Renaming (Obj1) then
5232 Obj1 := Renamed_Entity (Entity (Obj1));
5238 if Is_Renaming (Obj2) then
5239 if Is_Valid_Renaming (Obj2) then
5240 Obj2 := Renamed_Entity (Entity (Obj2));
5246 -- No match if not same node kind (such cases are handled by
5247 -- Denotes_Same_Prefix)
5249 if Nkind (Obj1) /= Nkind (Obj2) then
5252 -- After handling valid renamings, one of the two names statically
5253 -- denoted a renaming declaration whose renamed object_name is known
5254 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5256 elsif Is_Entity_Name (Obj1) then
5257 if Is_Entity_Name (Obj2) then
5258 return Entity (Obj1) = Entity (Obj2);
5263 -- Both names are selected_components, their prefixes are known to
5264 -- denote the same object, and their selector_names denote the same
5265 -- component (RM 6.4.1(6.6/3)).
5267 elsif Nkind (Obj1) = N_Selected_Component then
5268 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5270 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5272 -- Both names are dereferences and the dereferenced names are known to
5273 -- denote the same object (RM 6.4.1(6.7/3))
5275 elsif Nkind (Obj1) = N_Explicit_Dereference then
5276 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5278 -- Both names are indexed_components, their prefixes are known to denote
5279 -- the same object, and each of the pairs of corresponding index values
5280 -- are either both static expressions with the same static value or both
5281 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5283 elsif Nkind (Obj1) = N_Indexed_Component then
5284 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5292 Indx1 := First (Expressions (Obj1));
5293 Indx2 := First (Expressions (Obj2));
5294 while Present (Indx1) loop
5296 -- Indexes must denote the same static value or same object
5298 if Is_OK_Static_Expression (Indx1) then
5299 if not Is_OK_Static_Expression (Indx2) then
5302 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5306 elsif not Denotes_Same_Object (Indx1, Indx2) then
5318 -- Both names are slices, their prefixes are known to denote the same
5319 -- object, and the two slices have statically matching index constraints
5320 -- (RM 6.4.1(6.9/3))
5322 elsif Nkind (Obj1) = N_Slice
5323 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5326 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5329 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5330 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5332 -- Check whether bounds are statically identical. There is no
5333 -- attempt to detect partial overlap of slices.
5335 return Denotes_Same_Object (Lo1, Lo2)
5337 Denotes_Same_Object (Hi1, Hi2);
5340 -- In the recursion, literals appear as indexes
5342 elsif Nkind (Obj1) = N_Integer_Literal
5344 Nkind (Obj2) = N_Integer_Literal
5346 return Intval (Obj1) = Intval (Obj2);
5351 end Denotes_Same_Object;
5353 -------------------------
5354 -- Denotes_Same_Prefix --
5355 -------------------------
5357 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5359 if Is_Entity_Name (A1) then
5360 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5361 and then not Is_Access_Type (Etype (A1))
5363 return Denotes_Same_Object (A1, Prefix (A2))
5364 or else Denotes_Same_Prefix (A1, Prefix (A2));
5369 elsif Is_Entity_Name (A2) then
5370 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5372 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5374 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5377 Root1, Root2 : Node_Id;
5378 Depth1, Depth2 : Int := 0;
5381 Root1 := Prefix (A1);
5382 while not Is_Entity_Name (Root1) loop
5384 (Root1, N_Selected_Component, N_Indexed_Component)
5388 Root1 := Prefix (Root1);
5391 Depth1 := Depth1 + 1;
5394 Root2 := Prefix (A2);
5395 while not Is_Entity_Name (Root2) loop
5396 if not Nkind_In (Root2, N_Selected_Component,
5397 N_Indexed_Component)
5401 Root2 := Prefix (Root2);
5404 Depth2 := Depth2 + 1;
5407 -- If both have the same depth and they do not denote the same
5408 -- object, they are disjoint and no warning is needed.
5410 if Depth1 = Depth2 then
5413 elsif Depth1 > Depth2 then
5414 Root1 := Prefix (A1);
5415 for J in 1 .. Depth1 - Depth2 - 1 loop
5416 Root1 := Prefix (Root1);
5419 return Denotes_Same_Object (Root1, A2);
5422 Root2 := Prefix (A2);
5423 for J in 1 .. Depth2 - Depth1 - 1 loop
5424 Root2 := Prefix (Root2);
5427 return Denotes_Same_Object (A1, Root2);
5434 end Denotes_Same_Prefix;
5436 ----------------------
5437 -- Denotes_Variable --
5438 ----------------------
5440 function Denotes_Variable (N : Node_Id) return Boolean is
5442 return Is_Variable (N) and then Paren_Count (N) = 0;
5443 end Denotes_Variable;
5445 -----------------------------
5446 -- Depends_On_Discriminant --
5447 -----------------------------
5449 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5454 Get_Index_Bounds (N, L, H);
5455 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5456 end Depends_On_Discriminant;
5458 -------------------------
5459 -- Designate_Same_Unit --
5460 -------------------------
5462 function Designate_Same_Unit
5464 Name2 : Node_Id) return Boolean
5466 K1 : constant Node_Kind := Nkind (Name1);
5467 K2 : constant Node_Kind := Nkind (Name2);
5469 function Prefix_Node (N : Node_Id) return Node_Id;
5470 -- Returns the parent unit name node of a defining program unit name
5471 -- or the prefix if N is a selected component or an expanded name.
5473 function Select_Node (N : Node_Id) return Node_Id;
5474 -- Returns the defining identifier node of a defining program unit
5475 -- name or the selector node if N is a selected component or an
5482 function Prefix_Node (N : Node_Id) return Node_Id is
5484 if Nkind (N) = N_Defining_Program_Unit_Name then
5495 function Select_Node (N : Node_Id) return Node_Id is
5497 if Nkind (N) = N_Defining_Program_Unit_Name then
5498 return Defining_Identifier (N);
5500 return Selector_Name (N);
5504 -- Start of processing for Designate_Same_Unit
5507 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5509 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5511 return Chars (Name1) = Chars (Name2);
5513 elsif Nkind_In (K1, N_Expanded_Name,
5514 N_Selected_Component,
5515 N_Defining_Program_Unit_Name)
5517 Nkind_In (K2, N_Expanded_Name,
5518 N_Selected_Component,
5519 N_Defining_Program_Unit_Name)
5522 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5524 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5529 end Designate_Same_Unit;
5531 ------------------------------------------
5532 -- function Dynamic_Accessibility_Level --
5533 ------------------------------------------
5535 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5537 Loc : constant Source_Ptr := Sloc (Expr);
5539 function Make_Level_Literal (Level : Uint) return Node_Id;
5540 -- Construct an integer literal representing an accessibility level
5541 -- with its type set to Natural.
5543 ------------------------
5544 -- Make_Level_Literal --
5545 ------------------------
5547 function Make_Level_Literal (Level : Uint) return Node_Id is
5548 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5550 Set_Etype (Result, Standard_Natural);
5552 end Make_Level_Literal;
5554 -- Start of processing for Dynamic_Accessibility_Level
5557 if Is_Entity_Name (Expr) then
5560 if Present (Renamed_Object (E)) then
5561 return Dynamic_Accessibility_Level (Renamed_Object (E));
5564 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5565 if Present (Extra_Accessibility (E)) then
5566 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5571 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5573 case Nkind (Expr) is
5575 -- For access discriminant, the level of the enclosing object
5577 when N_Selected_Component =>
5578 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5579 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5580 E_Anonymous_Access_Type
5582 return Make_Level_Literal (Object_Access_Level (Expr));
5585 when N_Attribute_Reference =>
5586 case Get_Attribute_Id (Attribute_Name (Expr)) is
5588 -- For X'Access, the level of the prefix X
5590 when Attribute_Access =>
5591 return Make_Level_Literal
5592 (Object_Access_Level (Prefix (Expr)));
5594 -- Treat the unchecked attributes as library-level
5596 when Attribute_Unchecked_Access |
5597 Attribute_Unrestricted_Access =>
5598 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5600 -- No other access-valued attributes
5603 raise Program_Error;
5608 -- Unimplemented: depends on context. As an actual parameter where
5609 -- formal type is anonymous, use
5610 -- Scope_Depth (Current_Scope) + 1.
5611 -- For other cases, see 3.10.2(14/3) and following. ???
5615 when N_Type_Conversion =>
5616 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5618 -- Handle type conversions introduced for a rename of an
5619 -- Ada 2012 stand-alone object of an anonymous access type.
5621 return Dynamic_Accessibility_Level (Expression (Expr));
5628 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5629 end Dynamic_Accessibility_Level;
5631 -----------------------------------
5632 -- Effective_Extra_Accessibility --
5633 -----------------------------------
5635 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5637 if Present (Renamed_Object (Id))
5638 and then Is_Entity_Name (Renamed_Object (Id))
5640 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5642 return Extra_Accessibility (Id);
5644 end Effective_Extra_Accessibility;
5646 -----------------------------
5647 -- Effective_Reads_Enabled --
5648 -----------------------------
5650 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5652 return Has_Enabled_Property (Id, Name_Effective_Reads);
5653 end Effective_Reads_Enabled;
5655 ------------------------------
5656 -- Effective_Writes_Enabled --
5657 ------------------------------
5659 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5661 return Has_Enabled_Property (Id, Name_Effective_Writes);
5662 end Effective_Writes_Enabled;
5664 ------------------------------
5665 -- Enclosing_Comp_Unit_Node --
5666 ------------------------------
5668 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5669 Current_Node : Node_Id;
5673 while Present (Current_Node)
5674 and then Nkind (Current_Node) /= N_Compilation_Unit
5676 Current_Node := Parent (Current_Node);
5679 if Nkind (Current_Node) /= N_Compilation_Unit then
5682 return Current_Node;
5684 end Enclosing_Comp_Unit_Node;
5686 --------------------------
5687 -- Enclosing_CPP_Parent --
5688 --------------------------
5690 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5691 Parent_Typ : Entity_Id := Typ;
5694 while not Is_CPP_Class (Parent_Typ)
5695 and then Etype (Parent_Typ) /= Parent_Typ
5697 Parent_Typ := Etype (Parent_Typ);
5699 if Is_Private_Type (Parent_Typ) then
5700 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5704 pragma Assert (Is_CPP_Class (Parent_Typ));
5706 end Enclosing_CPP_Parent;
5708 ---------------------------
5709 -- Enclosing_Declaration --
5710 ---------------------------
5712 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5713 Decl : Node_Id := N;
5716 while Present (Decl)
5717 and then not (Nkind (Decl) in N_Declaration
5719 Nkind (Decl) in N_Later_Decl_Item)
5721 Decl := Parent (Decl);
5725 end Enclosing_Declaration;
5727 ----------------------------
5728 -- Enclosing_Generic_Body --
5729 ----------------------------
5731 function Enclosing_Generic_Body
5732 (N : Node_Id) return Node_Id
5740 while Present (P) loop
5741 if Nkind (P) = N_Package_Body
5742 or else Nkind (P) = N_Subprogram_Body
5744 Spec := Corresponding_Spec (P);
5746 if Present (Spec) then
5747 Decl := Unit_Declaration_Node (Spec);
5749 if Nkind (Decl) = N_Generic_Package_Declaration
5750 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5761 end Enclosing_Generic_Body;
5763 ----------------------------
5764 -- Enclosing_Generic_Unit --
5765 ----------------------------
5767 function Enclosing_Generic_Unit
5768 (N : Node_Id) return Node_Id
5776 while Present (P) loop
5777 if Nkind (P) = N_Generic_Package_Declaration
5778 or else Nkind (P) = N_Generic_Subprogram_Declaration
5782 elsif Nkind (P) = N_Package_Body
5783 or else Nkind (P) = N_Subprogram_Body
5785 Spec := Corresponding_Spec (P);
5787 if Present (Spec) then
5788 Decl := Unit_Declaration_Node (Spec);
5790 if Nkind (Decl) = N_Generic_Package_Declaration
5791 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5802 end Enclosing_Generic_Unit;
5804 -------------------------------
5805 -- Enclosing_Lib_Unit_Entity --
5806 -------------------------------
5808 function Enclosing_Lib_Unit_Entity
5809 (E : Entity_Id := Current_Scope) return Entity_Id
5811 Unit_Entity : Entity_Id;
5814 -- Look for enclosing library unit entity by following scope links.
5815 -- Equivalent to, but faster than indexing through the scope stack.
5818 while (Present (Scope (Unit_Entity))
5819 and then Scope (Unit_Entity) /= Standard_Standard)
5820 and not Is_Child_Unit (Unit_Entity)
5822 Unit_Entity := Scope (Unit_Entity);
5826 end Enclosing_Lib_Unit_Entity;
5828 -----------------------------
5829 -- Enclosing_Lib_Unit_Node --
5830 -----------------------------
5832 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
5833 Encl_Unit : Node_Id;
5836 Encl_Unit := Enclosing_Comp_Unit_Node (N);
5837 while Present (Encl_Unit)
5838 and then Nkind (Unit (Encl_Unit)) = N_Subunit
5840 Encl_Unit := Library_Unit (Encl_Unit);
5844 end Enclosing_Lib_Unit_Node;
5846 -----------------------
5847 -- Enclosing_Package --
5848 -----------------------
5850 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5851 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5854 if Dynamic_Scope = Standard_Standard then
5855 return Standard_Standard;
5857 elsif Dynamic_Scope = Empty then
5860 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5863 return Dynamic_Scope;
5866 return Enclosing_Package (Dynamic_Scope);
5868 end Enclosing_Package;
5870 -------------------------------------
5871 -- Enclosing_Package_Or_Subprogram --
5872 -------------------------------------
5874 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
5879 while Present (S) loop
5880 if Is_Package_Or_Generic_Package (S)
5881 or else Ekind (S) = E_Package_Body
5885 elsif Is_Subprogram_Or_Generic_Subprogram (S)
5886 or else Ekind (S) = E_Subprogram_Body
5896 end Enclosing_Package_Or_Subprogram;
5898 --------------------------
5899 -- Enclosing_Subprogram --
5900 --------------------------
5902 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5903 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5906 if Dynamic_Scope = Standard_Standard then
5909 elsif Dynamic_Scope = Empty then
5912 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5913 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5915 elsif Ekind (Dynamic_Scope) = E_Block
5916 or else Ekind (Dynamic_Scope) = E_Return_Statement
5918 return Enclosing_Subprogram (Dynamic_Scope);
5920 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5921 return Get_Task_Body_Procedure (Dynamic_Scope);
5923 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5924 and then Present (Full_View (Dynamic_Scope))
5925 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5927 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5929 -- No body is generated if the protected operation is eliminated
5931 elsif Convention (Dynamic_Scope) = Convention_Protected
5932 and then not Is_Eliminated (Dynamic_Scope)
5933 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5935 return Protected_Body_Subprogram (Dynamic_Scope);
5938 return Dynamic_Scope;
5940 end Enclosing_Subprogram;
5942 ------------------------
5943 -- Ensure_Freeze_Node --
5944 ------------------------
5946 procedure Ensure_Freeze_Node (E : Entity_Id) is
5949 if No (Freeze_Node (E)) then
5950 FN := Make_Freeze_Entity (Sloc (E));
5951 Set_Has_Delayed_Freeze (E);
5952 Set_Freeze_Node (E, FN);
5953 Set_Access_Types_To_Process (FN, No_Elist);
5954 Set_TSS_Elist (FN, No_Elist);
5957 end Ensure_Freeze_Node;
5963 procedure Enter_Name (Def_Id : Entity_Id) is
5964 C : constant Entity_Id := Current_Entity (Def_Id);
5965 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5966 S : constant Entity_Id := Current_Scope;
5969 Generate_Definition (Def_Id);
5971 -- Add new name to current scope declarations. Check for duplicate
5972 -- declaration, which may or may not be a genuine error.
5976 -- Case of previous entity entered because of a missing declaration
5977 -- or else a bad subtype indication. Best is to use the new entity,
5978 -- and make the previous one invisible.
5980 if Etype (E) = Any_Type then
5981 Set_Is_Immediately_Visible (E, False);
5983 -- Case of renaming declaration constructed for package instances.
5984 -- if there is an explicit declaration with the same identifier,
5985 -- the renaming is not immediately visible any longer, but remains
5986 -- visible through selected component notation.
5988 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5989 and then not Comes_From_Source (E)
5991 Set_Is_Immediately_Visible (E, False);
5993 -- The new entity may be the package renaming, which has the same
5994 -- same name as a generic formal which has been seen already.
5996 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5997 and then not Comes_From_Source (Def_Id)
5999 Set_Is_Immediately_Visible (E, False);
6001 -- For a fat pointer corresponding to a remote access to subprogram,
6002 -- we use the same identifier as the RAS type, so that the proper
6003 -- name appears in the stub. This type is only retrieved through
6004 -- the RAS type and never by visibility, and is not added to the
6005 -- visibility list (see below).
6007 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6008 and then Ekind (Def_Id) = E_Record_Type
6009 and then Present (Corresponding_Remote_Type (Def_Id))
6013 -- Case of an implicit operation or derived literal. The new entity
6014 -- hides the implicit one, which is removed from all visibility,
6015 -- i.e. the entity list of its scope, and homonym chain of its name.
6017 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6018 or else Is_Internal (E)
6022 Prev_Vis : Entity_Id;
6023 Decl : constant Node_Id := Parent (E);
6026 -- If E is an implicit declaration, it cannot be the first
6027 -- entity in the scope.
6029 Prev := First_Entity (Current_Scope);
6030 while Present (Prev) and then Next_Entity (Prev) /= E loop
6036 -- If E is not on the entity chain of the current scope,
6037 -- it is an implicit declaration in the generic formal
6038 -- part of a generic subprogram. When analyzing the body,
6039 -- the generic formals are visible but not on the entity
6040 -- chain of the subprogram. The new entity will become
6041 -- the visible one in the body.
6044 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6048 Set_Next_Entity (Prev, Next_Entity (E));
6050 if No (Next_Entity (Prev)) then
6051 Set_Last_Entity (Current_Scope, Prev);
6054 if E = Current_Entity (E) then
6058 Prev_Vis := Current_Entity (E);
6059 while Homonym (Prev_Vis) /= E loop
6060 Prev_Vis := Homonym (Prev_Vis);
6064 if Present (Prev_Vis) then
6066 -- Skip E in the visibility chain
6068 Set_Homonym (Prev_Vis, Homonym (E));
6071 Set_Name_Entity_Id (Chars (E), Homonym (E));
6076 -- This section of code could use a comment ???
6078 elsif Present (Etype (E))
6079 and then Is_Concurrent_Type (Etype (E))
6084 -- If the homograph is a protected component renaming, it should not
6085 -- be hiding the current entity. Such renamings are treated as weak
6088 elsif Is_Prival (E) then
6089 Set_Is_Immediately_Visible (E, False);
6091 -- In this case the current entity is a protected component renaming.
6092 -- Perform minimal decoration by setting the scope and return since
6093 -- the prival should not be hiding other visible entities.
6095 elsif Is_Prival (Def_Id) then
6096 Set_Scope (Def_Id, Current_Scope);
6099 -- Analogous to privals, the discriminal generated for an entry index
6100 -- parameter acts as a weak declaration. Perform minimal decoration
6101 -- to avoid bogus errors.
6103 elsif Is_Discriminal (Def_Id)
6104 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6106 Set_Scope (Def_Id, Current_Scope);
6109 -- In the body or private part of an instance, a type extension may
6110 -- introduce a component with the same name as that of an actual. The
6111 -- legality rule is not enforced, but the semantics of the full type
6112 -- with two components of same name are not clear at this point???
6114 elsif In_Instance_Not_Visible then
6117 -- When compiling a package body, some child units may have become
6118 -- visible. They cannot conflict with local entities that hide them.
6120 elsif Is_Child_Unit (E)
6121 and then In_Open_Scopes (Scope (E))
6122 and then not Is_Immediately_Visible (E)
6126 -- Conversely, with front-end inlining we may compile the parent body
6127 -- first, and a child unit subsequently. The context is now the
6128 -- parent spec, and body entities are not visible.
6130 elsif Is_Child_Unit (Def_Id)
6131 and then Is_Package_Body_Entity (E)
6132 and then not In_Package_Body (Current_Scope)
6136 -- Case of genuine duplicate declaration
6139 Error_Msg_Sloc := Sloc (E);
6141 -- If the previous declaration is an incomplete type declaration
6142 -- this may be an attempt to complete it with a private type. The
6143 -- following avoids confusing cascaded errors.
6145 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6146 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6149 ("incomplete type cannot be completed with a private " &
6150 "declaration", Parent (Def_Id));
6151 Set_Is_Immediately_Visible (E, False);
6152 Set_Full_View (E, Def_Id);
6154 -- An inherited component of a record conflicts with a new
6155 -- discriminant. The discriminant is inserted first in the scope,
6156 -- but the error should be posted on it, not on the component.
6158 elsif Ekind (E) = E_Discriminant
6159 and then Present (Scope (Def_Id))
6160 and then Scope (Def_Id) /= Current_Scope
6162 Error_Msg_Sloc := Sloc (Def_Id);
6163 Error_Msg_N ("& conflicts with declaration#", E);
6166 -- If the name of the unit appears in its own context clause, a
6167 -- dummy package with the name has already been created, and the
6168 -- error emitted. Try to continue quietly.
6170 elsif Error_Posted (E)
6171 and then Sloc (E) = No_Location
6172 and then Nkind (Parent (E)) = N_Package_Specification
6173 and then Current_Scope = Standard_Standard
6175 Set_Scope (Def_Id, Current_Scope);
6179 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6181 -- Avoid cascaded messages with duplicate components in
6184 if Ekind_In (E, E_Component, E_Discriminant) then
6189 if Nkind (Parent (Parent (Def_Id))) =
6190 N_Generic_Subprogram_Declaration
6192 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6194 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6197 -- If entity is in standard, then we are in trouble, because it
6198 -- means that we have a library package with a duplicated name.
6199 -- That's hard to recover from, so abort.
6201 if S = Standard_Standard then
6202 raise Unrecoverable_Error;
6204 -- Otherwise we continue with the declaration. Having two
6205 -- identical declarations should not cause us too much trouble.
6213 -- If we fall through, declaration is OK, at least OK enough to continue
6215 -- If Def_Id is a discriminant or a record component we are in the midst
6216 -- of inheriting components in a derived record definition. Preserve
6217 -- their Ekind and Etype.
6219 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6222 -- If a type is already set, leave it alone (happens when a type
6223 -- declaration is reanalyzed following a call to the optimizer).
6225 elsif Present (Etype (Def_Id)) then
6228 -- Otherwise, the kind E_Void insures that premature uses of the entity
6229 -- will be detected. Any_Type insures that no cascaded errors will occur
6232 Set_Ekind (Def_Id, E_Void);
6233 Set_Etype (Def_Id, Any_Type);
6236 -- Inherited discriminants and components in derived record types are
6237 -- immediately visible. Itypes are not.
6239 -- Unless the Itype is for a record type with a corresponding remote
6240 -- type (what is that about, it was not commented ???)
6242 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6244 ((not Is_Record_Type (Def_Id)
6245 or else No (Corresponding_Remote_Type (Def_Id)))
6246 and then not Is_Itype (Def_Id))
6248 Set_Is_Immediately_Visible (Def_Id);
6249 Set_Current_Entity (Def_Id);
6252 Set_Homonym (Def_Id, C);
6253 Append_Entity (Def_Id, S);
6254 Set_Public_Status (Def_Id);
6256 -- Declaring a homonym is not allowed in SPARK ...
6258 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6260 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6261 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6262 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6265 -- ... unless the new declaration is in a subprogram, and the
6266 -- visible declaration is a variable declaration or a parameter
6267 -- specification outside that subprogram.
6269 if Present (Enclosing_Subp)
6270 and then Nkind_In (Parent (C), N_Object_Declaration,
6271 N_Parameter_Specification)
6272 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6276 -- ... or the new declaration is in a package, and the visible
6277 -- declaration occurs outside that package.
6279 elsif Present (Enclosing_Pack)
6280 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6284 -- ... or the new declaration is a component declaration in a
6285 -- record type definition.
6287 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6290 -- Don't issue error for non-source entities
6292 elsif Comes_From_Source (Def_Id)
6293 and then Comes_From_Source (C)
6295 Error_Msg_Sloc := Sloc (C);
6296 Check_SPARK_05_Restriction
6297 ("redeclaration of identifier &#", Def_Id);
6302 -- Warn if new entity hides an old one
6304 if Warn_On_Hiding and then Present (C)
6306 -- Don't warn for record components since they always have a well
6307 -- defined scope which does not confuse other uses. Note that in
6308 -- some cases, Ekind has not been set yet.
6310 and then Ekind (C) /= E_Component
6311 and then Ekind (C) /= E_Discriminant
6312 and then Nkind (Parent (C)) /= N_Component_Declaration
6313 and then Ekind (Def_Id) /= E_Component
6314 and then Ekind (Def_Id) /= E_Discriminant
6315 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6317 -- Don't warn for one character variables. It is too common to use
6318 -- such variables as locals and will just cause too many false hits.
6320 and then Length_Of_Name (Chars (C)) /= 1
6322 -- Don't warn for non-source entities
6324 and then Comes_From_Source (C)
6325 and then Comes_From_Source (Def_Id)
6327 -- Don't warn unless entity in question is in extended main source
6329 and then In_Extended_Main_Source_Unit (Def_Id)
6331 -- Finally, the hidden entity must be either immediately visible or
6332 -- use visible (i.e. from a used package).
6335 (Is_Immediately_Visible (C)
6337 Is_Potentially_Use_Visible (C))
6339 Error_Msg_Sloc := Sloc (C);
6340 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6348 function Entity_Of (N : Node_Id) return Entity_Id is
6354 if Is_Entity_Name (N) then
6357 -- Follow a possible chain of renamings to reach the root renamed
6361 and then Is_Object (Id)
6362 and then Present (Renamed_Object (Id))
6364 if Is_Entity_Name (Renamed_Object (Id)) then
6365 Id := Entity (Renamed_Object (Id));
6376 --------------------------
6377 -- Explain_Limited_Type --
6378 --------------------------
6380 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6384 -- For array, component type must be limited
6386 if Is_Array_Type (T) then
6387 Error_Msg_Node_2 := T;
6389 ("\component type& of type& is limited", N, Component_Type (T));
6390 Explain_Limited_Type (Component_Type (T), N);
6392 elsif Is_Record_Type (T) then
6394 -- No need for extra messages if explicit limited record
6396 if Is_Limited_Record (Base_Type (T)) then
6400 -- Otherwise find a limited component. Check only components that
6401 -- come from source, or inherited components that appear in the
6402 -- source of the ancestor.
6404 C := First_Component (T);
6405 while Present (C) loop
6406 if Is_Limited_Type (Etype (C))
6408 (Comes_From_Source (C)
6410 (Present (Original_Record_Component (C))
6412 Comes_From_Source (Original_Record_Component (C))))
6414 Error_Msg_Node_2 := T;
6415 Error_Msg_NE ("\component& of type& has limited type", N, C);
6416 Explain_Limited_Type (Etype (C), N);
6423 -- The type may be declared explicitly limited, even if no component
6424 -- of it is limited, in which case we fall out of the loop.
6427 end Explain_Limited_Type;
6429 -------------------------------
6430 -- Extensions_Visible_Status --
6431 -------------------------------
6433 function Extensions_Visible_Status
6434 (Id : Entity_Id) return Extensions_Visible_Mode
6443 -- When a formal parameter is subject to Extensions_Visible, the pragma
6444 -- is stored in the contract of related subprogram.
6446 if Is_Formal (Id) then
6449 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6452 -- No other construct carries this pragma
6455 return Extensions_Visible_None;
6458 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6460 -- In certain cases analysis may request the Extensions_Visible status
6461 -- of an expression function before the pragma has been analyzed yet.
6462 -- Inspect the declarative items after the expression function looking
6463 -- for the pragma (if any).
6465 if No (Prag) and then Is_Expression_Function (Subp) then
6466 Decl := Next (Unit_Declaration_Node (Subp));
6467 while Present (Decl) loop
6468 if Nkind (Decl) = N_Pragma
6469 and then Pragma_Name (Decl) = Name_Extensions_Visible
6474 -- A source construct ends the region where Extensions_Visible may
6475 -- appear, stop the traversal. An expanded expression function is
6476 -- no longer a source construct, but it must still be recognized.
6478 elsif Comes_From_Source (Decl)
6480 (Nkind_In (Decl, N_Subprogram_Body,
6481 N_Subprogram_Declaration)
6482 and then Is_Expression_Function (Defining_Entity (Decl)))
6491 -- Extract the value from the Boolean expression (if any)
6493 if Present (Prag) then
6494 Arg := First (Pragma_Argument_Associations (Prag));
6496 if Present (Arg) then
6497 Expr := Get_Pragma_Arg (Arg);
6499 -- When the associated subprogram is an expression function, the
6500 -- argument of the pragma may not have been analyzed.
6502 if not Analyzed (Expr) then
6503 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6506 -- Guard against cascading errors when the argument of pragma
6507 -- Extensions_Visible is not a valid static Boolean expression.
6509 if Error_Posted (Expr) then
6510 return Extensions_Visible_None;
6512 elsif Is_True (Expr_Value (Expr)) then
6513 return Extensions_Visible_True;
6516 return Extensions_Visible_False;
6519 -- Otherwise the aspect or pragma defaults to True
6522 return Extensions_Visible_True;
6525 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6526 -- directly specified. In SPARK code, its value defaults to "False".
6528 elsif SPARK_Mode = On then
6529 return Extensions_Visible_False;
6531 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6535 return Extensions_Visible_True;
6537 end Extensions_Visible_Status;
6543 procedure Find_Actual
6545 Formal : out Entity_Id;
6548 Context : constant Node_Id := Parent (N);
6553 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6554 and then N = Prefix (Context)
6556 Find_Actual (Context, Formal, Call);
6559 elsif Nkind (Context) = N_Parameter_Association
6560 and then N = Explicit_Actual_Parameter (Context)
6562 Call := Parent (Context);
6564 elsif Nkind_In (Context, N_Entry_Call_Statement,
6566 N_Procedure_Call_Statement)
6576 -- If we have a call to a subprogram look for the parameter. Note that
6577 -- we exclude overloaded calls, since we don't know enough to be sure
6578 -- of giving the right answer in this case.
6580 if Nkind_In (Call, N_Entry_Call_Statement,
6582 N_Procedure_Call_Statement)
6584 Call_Nam := Name (Call);
6586 -- A call to a protected or task entry appears as a selected
6587 -- component rather than an expanded name.
6589 if Nkind (Call_Nam) = N_Selected_Component then
6590 Call_Nam := Selector_Name (Call_Nam);
6593 if Is_Entity_Name (Call_Nam)
6594 and then Present (Entity (Call_Nam))
6595 and then Is_Overloadable (Entity (Call_Nam))
6596 and then not Is_Overloaded (Call_Nam)
6598 -- If node is name in call it is not an actual
6600 if N = Call_Nam then
6606 -- Fall here if we are definitely a parameter
6608 Actual := First_Actual (Call);
6609 Formal := First_Formal (Entity (Call_Nam));
6610 while Present (Formal) and then Present (Actual) loop
6614 -- An actual that is the prefix in a prefixed call may have
6615 -- been rewritten in the call, after the deferred reference
6616 -- was collected. Check if sloc and kinds and names match.
6618 elsif Sloc (Actual) = Sloc (N)
6619 and then Nkind (Actual) = N_Identifier
6620 and then Nkind (Actual) = Nkind (N)
6621 and then Chars (Actual) = Chars (N)
6626 Actual := Next_Actual (Actual);
6627 Formal := Next_Formal (Formal);
6633 -- Fall through here if we did not find matching actual
6639 ---------------------------
6640 -- Find_Body_Discriminal --
6641 ---------------------------
6643 function Find_Body_Discriminal
6644 (Spec_Discriminant : Entity_Id) return Entity_Id
6650 -- If expansion is suppressed, then the scope can be the concurrent type
6651 -- itself rather than a corresponding concurrent record type.
6653 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6654 Tsk := Scope (Spec_Discriminant);
6657 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6659 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6662 -- Find discriminant of original concurrent type, and use its current
6663 -- discriminal, which is the renaming within the task/protected body.
6665 Disc := First_Discriminant (Tsk);
6666 while Present (Disc) loop
6667 if Chars (Disc) = Chars (Spec_Discriminant) then
6668 return Discriminal (Disc);
6671 Next_Discriminant (Disc);
6674 -- That loop should always succeed in finding a matching entry and
6675 -- returning. Fatal error if not.
6677 raise Program_Error;
6678 end Find_Body_Discriminal;
6680 -------------------------------------
6681 -- Find_Corresponding_Discriminant --
6682 -------------------------------------
6684 function Find_Corresponding_Discriminant
6686 Typ : Entity_Id) return Entity_Id
6688 Par_Disc : Entity_Id;
6689 Old_Disc : Entity_Id;
6690 New_Disc : Entity_Id;
6693 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6695 -- The original type may currently be private, and the discriminant
6696 -- only appear on its full view.
6698 if Is_Private_Type (Scope (Par_Disc))
6699 and then not Has_Discriminants (Scope (Par_Disc))
6700 and then Present (Full_View (Scope (Par_Disc)))
6702 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6704 Old_Disc := First_Discriminant (Scope (Par_Disc));
6707 if Is_Class_Wide_Type (Typ) then
6708 New_Disc := First_Discriminant (Root_Type (Typ));
6710 New_Disc := First_Discriminant (Typ);
6713 while Present (Old_Disc) and then Present (New_Disc) loop
6714 if Old_Disc = Par_Disc then
6718 Next_Discriminant (Old_Disc);
6719 Next_Discriminant (New_Disc);
6722 -- Should always find it
6724 raise Program_Error;
6725 end Find_Corresponding_Discriminant;
6727 ----------------------------------
6728 -- Find_Enclosing_Iterator_Loop --
6729 ----------------------------------
6731 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6736 -- Traverse the scope chain looking for an iterator loop. Such loops are
6737 -- usually transformed into blocks, hence the use of Original_Node.
6740 while Present (S) and then S /= Standard_Standard loop
6741 if Ekind (S) = E_Loop
6742 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6744 Constr := Original_Node (Label_Construct (Parent (S)));
6746 if Nkind (Constr) = N_Loop_Statement
6747 and then Present (Iteration_Scheme (Constr))
6748 and then Nkind (Iterator_Specification
6749 (Iteration_Scheme (Constr))) =
6750 N_Iterator_Specification
6760 end Find_Enclosing_Iterator_Loop;
6762 ------------------------------------
6763 -- Find_Loop_In_Conditional_Block --
6764 ------------------------------------
6766 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6772 if Nkind (Stmt) = N_If_Statement then
6773 Stmt := First (Then_Statements (Stmt));
6776 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6778 -- Inspect the statements of the conditional block. In general the loop
6779 -- should be the first statement in the statement sequence of the block,
6780 -- but the finalization machinery may have introduced extra object
6783 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6784 while Present (Stmt) loop
6785 if Nkind (Stmt) = N_Loop_Statement then
6792 -- The expansion of attribute 'Loop_Entry produced a malformed block
6794 raise Program_Error;
6795 end Find_Loop_In_Conditional_Block;
6797 --------------------------
6798 -- Find_Overlaid_Entity --
6799 --------------------------
6801 procedure Find_Overlaid_Entity
6803 Ent : out Entity_Id;
6809 -- We are looking for one of the two following forms:
6811 -- for X'Address use Y'Address
6815 -- Const : constant Address := expr;
6817 -- for X'Address use Const;
6819 -- In the second case, the expr is either Y'Address, or recursively a
6820 -- constant that eventually references Y'Address.
6825 if Nkind (N) = N_Attribute_Definition_Clause
6826 and then Chars (N) = Name_Address
6828 Expr := Expression (N);
6830 -- This loop checks the form of the expression for Y'Address,
6831 -- using recursion to deal with intermediate constants.
6834 -- Check for Y'Address
6836 if Nkind (Expr) = N_Attribute_Reference
6837 and then Attribute_Name (Expr) = Name_Address
6839 Expr := Prefix (Expr);
6842 -- Check for Const where Const is a constant entity
6844 elsif Is_Entity_Name (Expr)
6845 and then Ekind (Entity (Expr)) = E_Constant
6847 Expr := Constant_Value (Entity (Expr));
6849 -- Anything else does not need checking
6856 -- This loop checks the form of the prefix for an entity, using
6857 -- recursion to deal with intermediate components.
6860 -- Check for Y where Y is an entity
6862 if Is_Entity_Name (Expr) then
6863 Ent := Entity (Expr);
6866 -- Check for components
6869 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6871 Expr := Prefix (Expr);
6874 -- Anything else does not need checking
6881 end Find_Overlaid_Entity;
6883 -------------------------
6884 -- Find_Parameter_Type --
6885 -------------------------
6887 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6889 if Nkind (Param) /= N_Parameter_Specification then
6892 -- For an access parameter, obtain the type from the formal entity
6893 -- itself, because access to subprogram nodes do not carry a type.
6894 -- Shouldn't we always use the formal entity ???
6896 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6897 return Etype (Defining_Identifier (Param));
6900 return Etype (Parameter_Type (Param));
6902 end Find_Parameter_Type;
6904 -----------------------------------
6905 -- Find_Placement_In_State_Space --
6906 -----------------------------------
6908 procedure Find_Placement_In_State_Space
6909 (Item_Id : Entity_Id;
6910 Placement : out State_Space_Kind;
6911 Pack_Id : out Entity_Id)
6913 Context : Entity_Id;
6916 -- Assume that the item does not appear in the state space of a package
6918 Placement := Not_In_Package;
6921 -- Climb the scope stack and examine the enclosing context
6923 Context := Scope (Item_Id);
6924 while Present (Context) and then Context /= Standard_Standard loop
6925 if Ekind (Context) = E_Package then
6928 -- A package body is a cut off point for the traversal as the item
6929 -- cannot be visible to the outside from this point on. Note that
6930 -- this test must be done first as a body is also classified as a
6933 if In_Package_Body (Context) then
6934 Placement := Body_State_Space;
6937 -- The private part of a package is a cut off point for the
6938 -- traversal as the item cannot be visible to the outside from
6941 elsif In_Private_Part (Context) then
6942 Placement := Private_State_Space;
6945 -- When the item appears in the visible state space of a package,
6946 -- continue to climb the scope stack as this may not be the final
6950 Placement := Visible_State_Space;
6952 -- The visible state space of a child unit acts as the proper
6953 -- placement of an item.
6955 if Is_Child_Unit (Context) then
6960 -- The item or its enclosing package appear in a construct that has
6964 Placement := Not_In_Package;
6968 Context := Scope (Context);
6970 end Find_Placement_In_State_Space;
6972 ------------------------
6973 -- Find_Specific_Type --
6974 ------------------------
6976 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6977 Typ : Entity_Id := Root_Type (CW);
6980 if Ekind (Typ) = E_Incomplete_Type then
6981 if From_Limited_With (Typ) then
6982 Typ := Non_Limited_View (Typ);
6984 Typ := Full_View (Typ);
6988 if Is_Private_Type (Typ)
6989 and then not Is_Tagged_Type (Typ)
6990 and then Present (Full_View (Typ))
6992 return Full_View (Typ);
6996 end Find_Specific_Type;
6998 -----------------------------
6999 -- Find_Static_Alternative --
7000 -----------------------------
7002 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7003 Expr : constant Node_Id := Expression (N);
7004 Val : constant Uint := Expr_Value (Expr);
7009 Alt := First (Alternatives (N));
7012 if Nkind (Alt) /= N_Pragma then
7013 Choice := First (Discrete_Choices (Alt));
7014 while Present (Choice) loop
7016 -- Others choice, always matches
7018 if Nkind (Choice) = N_Others_Choice then
7021 -- Range, check if value is in the range
7023 elsif Nkind (Choice) = N_Range then
7025 Val >= Expr_Value (Low_Bound (Choice))
7027 Val <= Expr_Value (High_Bound (Choice));
7029 -- Choice is a subtype name. Note that we know it must
7030 -- be a static subtype, since otherwise it would have
7031 -- been diagnosed as illegal.
7033 elsif Is_Entity_Name (Choice)
7034 and then Is_Type (Entity (Choice))
7036 exit Search when Is_In_Range (Expr, Etype (Choice),
7037 Assume_Valid => False);
7039 -- Choice is a subtype indication
7041 elsif Nkind (Choice) = N_Subtype_Indication then
7043 C : constant Node_Id := Constraint (Choice);
7044 R : constant Node_Id := Range_Expression (C);
7048 Val >= Expr_Value (Low_Bound (R))
7050 Val <= Expr_Value (High_Bound (R));
7053 -- Choice is a simple expression
7056 exit Search when Val = Expr_Value (Choice);
7064 pragma Assert (Present (Alt));
7067 -- The above loop *must* terminate by finding a match, since
7068 -- we know the case statement is valid, and the value of the
7069 -- expression is known at compile time. When we fall out of
7070 -- the loop, Alt points to the alternative that we know will
7071 -- be selected at run time.
7074 end Find_Static_Alternative;
7080 function First_Actual (Node : Node_Id) return Node_Id is
7084 if No (Parameter_Associations (Node)) then
7088 N := First (Parameter_Associations (Node));
7090 if Nkind (N) = N_Parameter_Association then
7091 return First_Named_Actual (Node);
7101 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7102 Is_Task : constant Boolean :=
7103 Ekind_In (Id, E_Task_Body, E_Task_Type)
7104 or else (Is_Single_Concurrent_Object (Id)
7105 and then Ekind (Etype (Id)) = E_Task_Type);
7106 Msg_Last : constant Natural := Msg'Last;
7107 Msg_Index : Natural;
7108 Res : String (Msg'Range) := (others => ' ');
7109 Res_Index : Natural;
7112 -- Copy all characters from the input message Msg to result Res with
7113 -- suitable replacements.
7115 Msg_Index := Msg'First;
7116 Res_Index := Res'First;
7117 while Msg_Index <= Msg_Last loop
7119 -- Replace "subprogram" with a different word
7121 if Msg_Index <= Msg_Last - 10
7122 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7124 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7125 Res (Res_Index .. Res_Index + 4) := "entry";
7126 Res_Index := Res_Index + 5;
7129 Res (Res_Index .. Res_Index + 8) := "task type";
7130 Res_Index := Res_Index + 9;
7133 Res (Res_Index .. Res_Index + 9) := "subprogram";
7134 Res_Index := Res_Index + 10;
7137 Msg_Index := Msg_Index + 10;
7139 -- Replace "protected" with a different word
7141 elsif Msg_Index <= Msg_Last - 9
7142 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7145 Res (Res_Index .. Res_Index + 3) := "task";
7146 Res_Index := Res_Index + 4;
7147 Msg_Index := Msg_Index + 9;
7149 -- Otherwise copy the character
7152 Res (Res_Index) := Msg (Msg_Index);
7153 Msg_Index := Msg_Index + 1;
7154 Res_Index := Res_Index + 1;
7158 return Res (Res'First .. Res_Index - 1);
7161 -----------------------
7162 -- Gather_Components --
7163 -----------------------
7165 procedure Gather_Components
7167 Comp_List : Node_Id;
7168 Governed_By : List_Id;
7170 Report_Errors : out Boolean)
7174 Discrete_Choice : Node_Id;
7175 Comp_Item : Node_Id;
7177 Discrim : Entity_Id;
7178 Discrim_Name : Node_Id;
7179 Discrim_Value : Node_Id;
7182 Report_Errors := False;
7184 if No (Comp_List) or else Null_Present (Comp_List) then
7187 elsif Present (Component_Items (Comp_List)) then
7188 Comp_Item := First (Component_Items (Comp_List));
7194 while Present (Comp_Item) loop
7196 -- Skip the tag of a tagged record, the interface tags, as well
7197 -- as all items that are not user components (anonymous types,
7198 -- rep clauses, Parent field, controller field).
7200 if Nkind (Comp_Item) = N_Component_Declaration then
7202 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7204 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7205 Append_Elmt (Comp, Into);
7213 if No (Variant_Part (Comp_List)) then
7216 Discrim_Name := Name (Variant_Part (Comp_List));
7217 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7220 -- Look for the discriminant that governs this variant part.
7221 -- The discriminant *must* be in the Governed_By List
7223 Assoc := First (Governed_By);
7224 Find_Constraint : loop
7225 Discrim := First (Choices (Assoc));
7226 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7227 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7229 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7230 Chars (Discrim_Name))
7231 or else Chars (Original_Record_Component (Entity (Discrim)))
7232 = Chars (Discrim_Name);
7234 if No (Next (Assoc)) then
7235 if not Is_Constrained (Typ)
7236 and then Is_Derived_Type (Typ)
7237 and then Present (Stored_Constraint (Typ))
7239 -- If the type is a tagged type with inherited discriminants,
7240 -- use the stored constraint on the parent in order to find
7241 -- the values of discriminants that are otherwise hidden by an
7242 -- explicit constraint. Renamed discriminants are handled in
7245 -- If several parent discriminants are renamed by a single
7246 -- discriminant of the derived type, the call to obtain the
7247 -- Corresponding_Discriminant field only retrieves the last
7248 -- of them. We recover the constraint on the others from the
7249 -- Stored_Constraint as well.
7256 D := First_Discriminant (Etype (Typ));
7257 C := First_Elmt (Stored_Constraint (Typ));
7258 while Present (D) and then Present (C) loop
7259 if Chars (Discrim_Name) = Chars (D) then
7260 if Is_Entity_Name (Node (C))
7261 and then Entity (Node (C)) = Entity (Discrim)
7263 -- D is renamed by Discrim, whose value is given in
7270 Make_Component_Association (Sloc (Typ),
7272 (New_Occurrence_Of (D, Sloc (Typ))),
7273 Duplicate_Subexpr_No_Checks (Node (C)));
7275 exit Find_Constraint;
7278 Next_Discriminant (D);
7285 if No (Next (Assoc)) then
7286 Error_Msg_NE (" missing value for discriminant&",
7287 First (Governed_By), Discrim_Name);
7288 Report_Errors := True;
7293 end loop Find_Constraint;
7295 Discrim_Value := Expression (Assoc);
7297 if not Is_OK_Static_Expression (Discrim_Value) then
7299 -- If the variant part is governed by a discriminant of the type
7300 -- this is an error. If the variant part and the discriminant are
7301 -- inherited from an ancestor this is legal (AI05-120) unless the
7302 -- components are being gathered for an aggregate, in which case
7303 -- the caller must check Report_Errors.
7305 if Scope (Original_Record_Component
7306 ((Entity (First (Choices (Assoc)))))) = Typ
7309 ("value for discriminant & must be static!",
7310 Discrim_Value, Discrim);
7311 Why_Not_Static (Discrim_Value);
7314 Report_Errors := True;
7318 Search_For_Discriminant_Value : declare
7324 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7327 Find_Discrete_Value : while Present (Variant) loop
7328 Discrete_Choice := First (Discrete_Choices (Variant));
7329 while Present (Discrete_Choice) loop
7330 exit Find_Discrete_Value when
7331 Nkind (Discrete_Choice) = N_Others_Choice;
7333 Get_Index_Bounds (Discrete_Choice, Low, High);
7335 UI_Low := Expr_Value (Low);
7336 UI_High := Expr_Value (High);
7338 exit Find_Discrete_Value when
7339 UI_Low <= UI_Discrim_Value
7341 UI_High >= UI_Discrim_Value;
7343 Next (Discrete_Choice);
7346 Next_Non_Pragma (Variant);
7347 end loop Find_Discrete_Value;
7348 end Search_For_Discriminant_Value;
7350 if No (Variant) then
7352 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7353 Report_Errors := True;
7357 -- If we have found the corresponding choice, recursively add its
7358 -- components to the Into list. The nested components are part of
7359 -- the same record type.
7362 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7363 end Gather_Components;
7365 ------------------------
7366 -- Get_Actual_Subtype --
7367 ------------------------
7369 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7370 Typ : constant Entity_Id := Etype (N);
7371 Utyp : Entity_Id := Underlying_Type (Typ);
7380 -- If what we have is an identifier that references a subprogram
7381 -- formal, or a variable or constant object, then we get the actual
7382 -- subtype from the referenced entity if one has been built.
7384 if Nkind (N) = N_Identifier
7386 (Is_Formal (Entity (N))
7387 or else Ekind (Entity (N)) = E_Constant
7388 or else Ekind (Entity (N)) = E_Variable)
7389 and then Present (Actual_Subtype (Entity (N)))
7391 return Actual_Subtype (Entity (N));
7393 -- Actual subtype of unchecked union is always itself. We never need
7394 -- the "real" actual subtype. If we did, we couldn't get it anyway
7395 -- because the discriminant is not available. The restrictions on
7396 -- Unchecked_Union are designed to make sure that this is OK.
7398 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7401 -- Here for the unconstrained case, we must find actual subtype
7402 -- No actual subtype is available, so we must build it on the fly.
7404 -- Checking the type, not the underlying type, for constrainedness
7405 -- seems to be necessary. Maybe all the tests should be on the type???
7407 elsif (not Is_Constrained (Typ))
7408 and then (Is_Array_Type (Utyp)
7409 or else (Is_Record_Type (Utyp)
7410 and then Has_Discriminants (Utyp)))
7411 and then not Has_Unknown_Discriminants (Utyp)
7412 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7414 -- Nothing to do if in spec expression (why not???)
7416 if In_Spec_Expression then
7419 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7421 -- If the type has no discriminants, there is no subtype to
7422 -- build, even if the underlying type is discriminated.
7426 -- Else build the actual subtype
7429 Decl := Build_Actual_Subtype (Typ, N);
7430 Atyp := Defining_Identifier (Decl);
7432 -- If Build_Actual_Subtype generated a new declaration then use it
7436 -- The actual subtype is an Itype, so analyze the declaration,
7437 -- but do not attach it to the tree, to get the type defined.
7439 Set_Parent (Decl, N);
7440 Set_Is_Itype (Atyp);
7441 Analyze (Decl, Suppress => All_Checks);
7442 Set_Associated_Node_For_Itype (Atyp, N);
7443 Set_Has_Delayed_Freeze (Atyp, False);
7445 -- We need to freeze the actual subtype immediately. This is
7446 -- needed, because otherwise this Itype will not get frozen
7447 -- at all, and it is always safe to freeze on creation because
7448 -- any associated types must be frozen at this point.
7450 Freeze_Itype (Atyp, N);
7453 -- Otherwise we did not build a declaration, so return original
7460 -- For all remaining cases, the actual subtype is the same as
7461 -- the nominal type.
7466 end Get_Actual_Subtype;
7468 -------------------------------------
7469 -- Get_Actual_Subtype_If_Available --
7470 -------------------------------------
7472 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7473 Typ : constant Entity_Id := Etype (N);
7476 -- If what we have is an identifier that references a subprogram
7477 -- formal, or a variable or constant object, then we get the actual
7478 -- subtype from the referenced entity if one has been built.
7480 if Nkind (N) = N_Identifier
7482 (Is_Formal (Entity (N))
7483 or else Ekind (Entity (N)) = E_Constant
7484 or else Ekind (Entity (N)) = E_Variable)
7485 and then Present (Actual_Subtype (Entity (N)))
7487 return Actual_Subtype (Entity (N));
7489 -- Otherwise the Etype of N is returned unchanged
7494 end Get_Actual_Subtype_If_Available;
7496 ------------------------
7497 -- Get_Body_From_Stub --
7498 ------------------------
7500 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7502 return Proper_Body (Unit (Library_Unit (N)));
7503 end Get_Body_From_Stub;
7505 ---------------------
7506 -- Get_Cursor_Type --
7507 ---------------------
7509 function Get_Cursor_Type
7511 Typ : Entity_Id) return Entity_Id
7515 First_Op : Entity_Id;
7519 -- If error already detected, return
7521 if Error_Posted (Aspect) then
7525 -- The cursor type for an Iterable aspect is the return type of a
7526 -- non-overloaded First primitive operation. Locate association for
7529 Assoc := First (Component_Associations (Expression (Aspect)));
7531 while Present (Assoc) loop
7532 if Chars (First (Choices (Assoc))) = Name_First then
7533 First_Op := Expression (Assoc);
7540 if First_Op = Any_Id then
7541 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7547 -- Locate function with desired name and profile in scope of type
7549 Func := First_Entity (Scope (Typ));
7550 while Present (Func) loop
7551 if Chars (Func) = Chars (First_Op)
7552 and then Ekind (Func) = E_Function
7553 and then Present (First_Formal (Func))
7554 and then Etype (First_Formal (Func)) = Typ
7555 and then No (Next_Formal (First_Formal (Func)))
7557 if Cursor /= Any_Type then
7559 ("Operation First for iterable type must be unique", Aspect);
7562 Cursor := Etype (Func);
7569 -- If not found, no way to resolve remaining primitives.
7571 if Cursor = Any_Type then
7573 ("No legal primitive operation First for Iterable type", Aspect);
7577 end Get_Cursor_Type;
7579 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7581 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7582 end Get_Cursor_Type;
7584 -------------------------------
7585 -- Get_Default_External_Name --
7586 -------------------------------
7588 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7590 Get_Decoded_Name_String (Chars (E));
7592 if Opt.External_Name_Imp_Casing = Uppercase then
7593 Set_Casing (All_Upper_Case);
7595 Set_Casing (All_Lower_Case);
7599 Make_String_Literal (Sloc (E),
7600 Strval => String_From_Name_Buffer);
7601 end Get_Default_External_Name;
7603 --------------------------
7604 -- Get_Enclosing_Object --
7605 --------------------------
7607 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7609 if Is_Entity_Name (N) then
7613 when N_Indexed_Component |
7615 N_Selected_Component =>
7617 -- If not generating code, a dereference may be left implicit.
7618 -- In thoses cases, return Empty.
7620 if Is_Access_Type (Etype (Prefix (N))) then
7623 return Get_Enclosing_Object (Prefix (N));
7626 when N_Type_Conversion =>
7627 return Get_Enclosing_Object (Expression (N));
7633 end Get_Enclosing_Object;
7635 ---------------------------
7636 -- Get_Enum_Lit_From_Pos --
7637 ---------------------------
7639 function Get_Enum_Lit_From_Pos
7642 Loc : Source_Ptr) return Node_Id
7644 Btyp : Entity_Id := Base_Type (T);
7648 -- In the case where the literal is of type Character, Wide_Character
7649 -- or Wide_Wide_Character or of a type derived from them, there needs
7650 -- to be some special handling since there is no explicit chain of
7651 -- literals to search. Instead, an N_Character_Literal node is created
7652 -- with the appropriate Char_Code and Chars fields.
7654 if Is_Standard_Character_Type (T) then
7655 Set_Character_Literal_Name (UI_To_CC (Pos));
7657 Make_Character_Literal (Loc,
7659 Char_Literal_Value => Pos);
7661 -- For all other cases, we have a complete table of literals, and
7662 -- we simply iterate through the chain of literal until the one
7663 -- with the desired position value is found.
7666 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7667 Btyp := Full_View (Btyp);
7670 Lit := First_Literal (Btyp);
7671 for J in 1 .. UI_To_Int (Pos) loop
7675 return New_Occurrence_Of (Lit, Loc);
7677 end Get_Enum_Lit_From_Pos;
7679 ------------------------
7680 -- Get_Generic_Entity --
7681 ------------------------
7683 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7684 Ent : constant Entity_Id := Entity (Name (N));
7686 if Present (Renamed_Object (Ent)) then
7687 return Renamed_Object (Ent);
7691 end Get_Generic_Entity;
7693 -------------------------------------
7694 -- Get_Incomplete_View_Of_Ancestor --
7695 -------------------------------------
7697 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7698 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7699 Par_Scope : Entity_Id;
7700 Par_Type : Entity_Id;
7703 -- The incomplete view of an ancestor is only relevant for private
7704 -- derived types in child units.
7706 if not Is_Derived_Type (E)
7707 or else not Is_Child_Unit (Cur_Unit)
7712 Par_Scope := Scope (Cur_Unit);
7713 if No (Par_Scope) then
7717 Par_Type := Etype (Base_Type (E));
7719 -- Traverse list of ancestor types until we find one declared in
7720 -- a parent or grandparent unit (two levels seem sufficient).
7722 while Present (Par_Type) loop
7723 if Scope (Par_Type) = Par_Scope
7724 or else Scope (Par_Type) = Scope (Par_Scope)
7728 elsif not Is_Derived_Type (Par_Type) then
7732 Par_Type := Etype (Base_Type (Par_Type));
7736 -- If none found, there is no relevant ancestor type.
7740 end Get_Incomplete_View_Of_Ancestor;
7742 ----------------------
7743 -- Get_Index_Bounds --
7744 ----------------------
7746 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7747 Kind : constant Node_Kind := Nkind (N);
7751 if Kind = N_Range then
7753 H := High_Bound (N);
7755 elsif Kind = N_Subtype_Indication then
7756 R := Range_Expression (Constraint (N));
7764 L := Low_Bound (Range_Expression (Constraint (N)));
7765 H := High_Bound (Range_Expression (Constraint (N)));
7768 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7769 if Error_Posted (Scalar_Range (Entity (N))) then
7773 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7774 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7777 L := Low_Bound (Scalar_Range (Entity (N)));
7778 H := High_Bound (Scalar_Range (Entity (N)));
7782 -- N is an expression, indicating a range with one value
7787 end Get_Index_Bounds;
7789 ---------------------------------
7790 -- Get_Iterable_Type_Primitive --
7791 ---------------------------------
7793 function Get_Iterable_Type_Primitive
7795 Nam : Name_Id) return Entity_Id
7797 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7805 Assoc := First (Component_Associations (Funcs));
7806 while Present (Assoc) loop
7807 if Chars (First (Choices (Assoc))) = Nam then
7808 return Entity (Expression (Assoc));
7811 Assoc := Next (Assoc);
7816 end Get_Iterable_Type_Primitive;
7818 ----------------------------------
7819 -- Get_Library_Unit_Name_string --
7820 ----------------------------------
7822 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7823 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7826 Get_Unit_Name_String (Unit_Name_Id);
7828 -- Remove seven last character (" (spec)" or " (body)")
7830 Name_Len := Name_Len - 7;
7831 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7832 end Get_Library_Unit_Name_String;
7834 ------------------------
7835 -- Get_Name_Entity_Id --
7836 ------------------------
7838 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7840 return Entity_Id (Get_Name_Table_Int (Id));
7841 end Get_Name_Entity_Id;
7843 ------------------------------
7844 -- Get_Name_From_CTC_Pragma --
7845 ------------------------------
7847 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7848 Arg : constant Node_Id :=
7849 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7851 return Strval (Expr_Value_S (Arg));
7852 end Get_Name_From_CTC_Pragma;
7854 -----------------------
7855 -- Get_Parent_Entity --
7856 -----------------------
7858 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7860 if Nkind (Unit) = N_Package_Body
7861 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7863 return Defining_Entity
7864 (Specification (Instance_Spec (Original_Node (Unit))));
7865 elsif Nkind (Unit) = N_Package_Instantiation then
7866 return Defining_Entity (Specification (Instance_Spec (Unit)));
7868 return Defining_Entity (Unit);
7870 end Get_Parent_Entity;
7876 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7878 return Get_Pragma_Id (Pragma_Name (N));
7881 -----------------------
7882 -- Get_Reason_String --
7883 -----------------------
7885 procedure Get_Reason_String (N : Node_Id) is
7887 if Nkind (N) = N_String_Literal then
7888 Store_String_Chars (Strval (N));
7890 elsif Nkind (N) = N_Op_Concat then
7891 Get_Reason_String (Left_Opnd (N));
7892 Get_Reason_String (Right_Opnd (N));
7894 -- If not of required form, error
7898 ("Reason for pragma Warnings has wrong form", N);
7900 ("\must be string literal or concatenation of string literals", N);
7903 end Get_Reason_String;
7905 --------------------------------
7906 -- Get_Reference_Discriminant --
7907 --------------------------------
7909 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
7913 D := First_Discriminant (Typ);
7914 while Present (D) loop
7915 if Has_Implicit_Dereference (D) then
7918 Next_Discriminant (D);
7922 end Get_Reference_Discriminant;
7924 ---------------------------
7925 -- Get_Referenced_Object --
7926 ---------------------------
7928 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7933 while Is_Entity_Name (R)
7934 and then Present (Renamed_Object (Entity (R)))
7936 R := Renamed_Object (Entity (R));
7940 end Get_Referenced_Object;
7942 ------------------------
7943 -- Get_Renamed_Entity --
7944 ------------------------
7946 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7951 while Present (Renamed_Entity (R)) loop
7952 R := Renamed_Entity (R);
7956 end Get_Renamed_Entity;
7958 -----------------------
7959 -- Get_Return_Object --
7960 -----------------------
7962 function Get_Return_Object (N : Node_Id) return Entity_Id is
7966 Decl := First (Return_Object_Declarations (N));
7967 while Present (Decl) loop
7968 exit when Nkind (Decl) = N_Object_Declaration
7969 and then Is_Return_Object (Defining_Identifier (Decl));
7973 pragma Assert (Present (Decl));
7974 return Defining_Identifier (Decl);
7975 end Get_Return_Object;
7977 ---------------------------
7978 -- Get_Subprogram_Entity --
7979 ---------------------------
7981 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7983 Subp_Id : Entity_Id;
7986 if Nkind (Nod) = N_Accept_Statement then
7987 Subp := Entry_Direct_Name (Nod);
7989 elsif Nkind (Nod) = N_Slice then
7990 Subp := Prefix (Nod);
7996 -- Strip the subprogram call
7999 if Nkind_In (Subp, N_Explicit_Dereference,
8000 N_Indexed_Component,
8001 N_Selected_Component)
8003 Subp := Prefix (Subp);
8005 elsif Nkind_In (Subp, N_Type_Conversion,
8006 N_Unchecked_Type_Conversion)
8008 Subp := Expression (Subp);
8015 -- Extract the entity of the subprogram call
8017 if Is_Entity_Name (Subp) then
8018 Subp_Id := Entity (Subp);
8020 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8021 Subp_Id := Directly_Designated_Type (Subp_Id);
8024 if Is_Subprogram (Subp_Id) then
8030 -- The search did not find a construct that denotes a subprogram
8035 end Get_Subprogram_Entity;
8037 -----------------------------
8038 -- Get_Task_Body_Procedure --
8039 -----------------------------
8041 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8043 -- Note: A task type may be the completion of a private type with
8044 -- discriminants. When performing elaboration checks on a task
8045 -- declaration, the current view of the type may be the private one,
8046 -- and the procedure that holds the body of the task is held in its
8049 -- This is an odd function, why not have Task_Body_Procedure do
8050 -- the following digging???
8052 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8053 end Get_Task_Body_Procedure;
8055 -------------------------
8056 -- Get_User_Defined_Eq --
8057 -------------------------
8059 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8064 Prim := First_Elmt (Collect_Primitive_Operations (E));
8065 while Present (Prim) loop
8068 if Chars (Op) = Name_Op_Eq
8069 and then Etype (Op) = Standard_Boolean
8070 and then Etype (First_Formal (Op)) = E
8071 and then Etype (Next_Formal (First_Formal (Op))) = E
8080 end Get_User_Defined_Eq;
8082 -----------------------
8083 -- Has_Access_Values --
8084 -----------------------
8086 function Has_Access_Values (T : Entity_Id) return Boolean is
8087 Typ : constant Entity_Id := Underlying_Type (T);
8090 -- Case of a private type which is not completed yet. This can only
8091 -- happen in the case of a generic format type appearing directly, or
8092 -- as a component of the type to which this function is being applied
8093 -- at the top level. Return False in this case, since we certainly do
8094 -- not know that the type contains access types.
8099 elsif Is_Access_Type (Typ) then
8102 elsif Is_Array_Type (Typ) then
8103 return Has_Access_Values (Component_Type (Typ));
8105 elsif Is_Record_Type (Typ) then
8110 -- Loop to Check components
8112 Comp := First_Component_Or_Discriminant (Typ);
8113 while Present (Comp) loop
8115 -- Check for access component, tag field does not count, even
8116 -- though it is implemented internally using an access type.
8118 if Has_Access_Values (Etype (Comp))
8119 and then Chars (Comp) /= Name_uTag
8124 Next_Component_Or_Discriminant (Comp);
8133 end Has_Access_Values;
8135 ------------------------------
8136 -- Has_Compatible_Alignment --
8137 ------------------------------
8139 function Has_Compatible_Alignment
8141 Expr : Node_Id) return Alignment_Result
8143 function Has_Compatible_Alignment_Internal
8146 Default : Alignment_Result) return Alignment_Result;
8147 -- This is the internal recursive function that actually does the work.
8148 -- There is one additional parameter, which says what the result should
8149 -- be if no alignment information is found, and there is no definite
8150 -- indication of compatible alignments. At the outer level, this is set
8151 -- to Unknown, but for internal recursive calls in the case where types
8152 -- are known to be correct, it is set to Known_Compatible.
8154 ---------------------------------------
8155 -- Has_Compatible_Alignment_Internal --
8156 ---------------------------------------
8158 function Has_Compatible_Alignment_Internal
8161 Default : Alignment_Result) return Alignment_Result
8163 Result : Alignment_Result := Known_Compatible;
8164 -- Holds the current status of the result. Note that once a value of
8165 -- Known_Incompatible is set, it is sticky and does not get changed
8166 -- to Unknown (the value in Result only gets worse as we go along,
8169 Offs : Uint := No_Uint;
8170 -- Set to a factor of the offset from the base object when Expr is a
8171 -- selected or indexed component, based on Component_Bit_Offset and
8172 -- Component_Size respectively. A negative value is used to represent
8173 -- a value which is not known at compile time.
8175 procedure Check_Prefix;
8176 -- Checks the prefix recursively in the case where the expression
8177 -- is an indexed or selected component.
8179 procedure Set_Result (R : Alignment_Result);
8180 -- If R represents a worse outcome (unknown instead of known
8181 -- compatible, or known incompatible), then set Result to R.
8187 procedure Check_Prefix is
8189 -- The subtlety here is that in doing a recursive call to check
8190 -- the prefix, we have to decide what to do in the case where we
8191 -- don't find any specific indication of an alignment problem.
8193 -- At the outer level, we normally set Unknown as the result in
8194 -- this case, since we can only set Known_Compatible if we really
8195 -- know that the alignment value is OK, but for the recursive
8196 -- call, in the case where the types match, and we have not
8197 -- specified a peculiar alignment for the object, we are only
8198 -- concerned about suspicious rep clauses, the default case does
8199 -- not affect us, since the compiler will, in the absence of such
8200 -- rep clauses, ensure that the alignment is correct.
8202 if Default = Known_Compatible
8204 (Etype (Obj) = Etype (Expr)
8205 and then (Unknown_Alignment (Obj)
8207 Alignment (Obj) = Alignment (Etype (Obj))))
8210 (Has_Compatible_Alignment_Internal
8211 (Obj, Prefix (Expr), Known_Compatible));
8213 -- In all other cases, we need a full check on the prefix
8217 (Has_Compatible_Alignment_Internal
8218 (Obj, Prefix (Expr), Unknown));
8226 procedure Set_Result (R : Alignment_Result) is
8233 -- Start of processing for Has_Compatible_Alignment_Internal
8236 -- If Expr is a selected component, we must make sure there is no
8237 -- potentially troublesome component clause, and that the record is
8240 if Nkind (Expr) = N_Selected_Component then
8242 -- Packed record always generate unknown alignment
8244 if Is_Packed (Etype (Prefix (Expr))) then
8245 Set_Result (Unknown);
8248 -- Check prefix and component offset
8251 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8253 -- If Expr is an indexed component, we must make sure there is no
8254 -- potentially troublesome Component_Size clause and that the array
8255 -- is not bit-packed.
8257 elsif Nkind (Expr) = N_Indexed_Component then
8259 Typ : constant Entity_Id := Etype (Prefix (Expr));
8260 Ind : constant Node_Id := First_Index (Typ);
8263 -- Bit packed array always generates unknown alignment
8265 if Is_Bit_Packed_Array (Typ) then
8266 Set_Result (Unknown);
8269 -- Check prefix and component offset
8272 Offs := Component_Size (Typ);
8274 -- Small optimization: compute the full offset when possible
8277 and then Offs > Uint_0
8278 and then Present (Ind)
8279 and then Nkind (Ind) = N_Range
8280 and then Compile_Time_Known_Value (Low_Bound (Ind))
8281 and then Compile_Time_Known_Value (First (Expressions (Expr)))
8283 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
8284 - Expr_Value (Low_Bound ((Ind))));
8289 -- If we have a null offset, the result is entirely determined by
8290 -- the base object and has already been computed recursively.
8292 if Offs = Uint_0 then
8295 -- Case where we know the alignment of the object
8297 elsif Known_Alignment (Obj) then
8299 ObjA : constant Uint := Alignment (Obj);
8300 ExpA : Uint := No_Uint;
8301 SizA : Uint := No_Uint;
8304 -- If alignment of Obj is 1, then we are always OK
8307 Set_Result (Known_Compatible);
8309 -- Alignment of Obj is greater than 1, so we need to check
8312 -- If we have an offset, see if it is compatible
8314 if Offs /= No_Uint and Offs > Uint_0 then
8315 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8316 Set_Result (Known_Incompatible);
8319 -- See if Expr is an object with known alignment
8321 elsif Is_Entity_Name (Expr)
8322 and then Known_Alignment (Entity (Expr))
8324 ExpA := Alignment (Entity (Expr));
8326 -- Otherwise, we can use the alignment of the type of
8327 -- Expr given that we already checked for
8328 -- discombobulating rep clauses for the cases of indexed
8329 -- and selected components above.
8331 elsif Known_Alignment (Etype (Expr)) then
8332 ExpA := Alignment (Etype (Expr));
8334 -- Otherwise the alignment is unknown
8337 Set_Result (Default);
8340 -- If we got an alignment, see if it is acceptable
8342 if ExpA /= No_Uint and then ExpA < ObjA then
8343 Set_Result (Known_Incompatible);
8346 -- If Expr is not a piece of a larger object, see if size
8347 -- is given. If so, check that it is not too small for the
8348 -- required alignment.
8350 if Offs /= No_Uint then
8353 -- See if Expr is an object with known size
8355 elsif Is_Entity_Name (Expr)
8356 and then Known_Static_Esize (Entity (Expr))
8358 SizA := Esize (Entity (Expr));
8360 -- Otherwise, we check the object size of the Expr type
8362 elsif Known_Static_Esize (Etype (Expr)) then
8363 SizA := Esize (Etype (Expr));
8366 -- If we got a size, see if it is a multiple of the Obj
8367 -- alignment, if not, then the alignment cannot be
8368 -- acceptable, since the size is always a multiple of the
8371 if SizA /= No_Uint then
8372 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8373 Set_Result (Known_Incompatible);
8379 -- If we do not know required alignment, any non-zero offset is a
8380 -- potential problem (but certainly may be OK, so result is unknown).
8382 elsif Offs /= No_Uint then
8383 Set_Result (Unknown);
8385 -- If we can't find the result by direct comparison of alignment
8386 -- values, then there is still one case that we can determine known
8387 -- result, and that is when we can determine that the types are the
8388 -- same, and no alignments are specified. Then we known that the
8389 -- alignments are compatible, even if we don't know the alignment
8390 -- value in the front end.
8392 elsif Etype (Obj) = Etype (Expr) then
8394 -- Types are the same, but we have to check for possible size
8395 -- and alignments on the Expr object that may make the alignment
8396 -- different, even though the types are the same.
8398 if Is_Entity_Name (Expr) then
8400 -- First check alignment of the Expr object. Any alignment less
8401 -- than Maximum_Alignment is worrisome since this is the case
8402 -- where we do not know the alignment of Obj.
8404 if Known_Alignment (Entity (Expr))
8405 and then UI_To_Int (Alignment (Entity (Expr))) <
8406 Ttypes.Maximum_Alignment
8408 Set_Result (Unknown);
8410 -- Now check size of Expr object. Any size that is not an
8411 -- even multiple of Maximum_Alignment is also worrisome
8412 -- since it may cause the alignment of the object to be less
8413 -- than the alignment of the type.
8415 elsif Known_Static_Esize (Entity (Expr))
8417 (UI_To_Int (Esize (Entity (Expr))) mod
8418 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8421 Set_Result (Unknown);
8423 -- Otherwise same type is decisive
8426 Set_Result (Known_Compatible);
8430 -- Another case to deal with is when there is an explicit size or
8431 -- alignment clause when the types are not the same. If so, then the
8432 -- result is Unknown. We don't need to do this test if the Default is
8433 -- Unknown, since that result will be set in any case.
8435 elsif Default /= Unknown
8436 and then (Has_Size_Clause (Etype (Expr))
8438 Has_Alignment_Clause (Etype (Expr)))
8440 Set_Result (Unknown);
8442 -- If no indication found, set default
8445 Set_Result (Default);
8448 -- Return worst result found
8451 end Has_Compatible_Alignment_Internal;
8453 -- Start of processing for Has_Compatible_Alignment
8456 -- If Obj has no specified alignment, then set alignment from the type
8457 -- alignment. Perhaps we should always do this, but for sure we should
8458 -- do it when there is an address clause since we can do more if the
8459 -- alignment is known.
8461 if Unknown_Alignment (Obj) then
8462 Set_Alignment (Obj, Alignment (Etype (Obj)));
8465 -- Now do the internal call that does all the work
8467 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
8468 end Has_Compatible_Alignment;
8470 ----------------------
8471 -- Has_Declarations --
8472 ----------------------
8474 function Has_Declarations (N : Node_Id) return Boolean is
8476 return Nkind_In (Nkind (N), N_Accept_Statement,
8478 N_Compilation_Unit_Aux,
8484 N_Package_Specification);
8485 end Has_Declarations;
8487 ---------------------------------
8488 -- Has_Defaulted_Discriminants --
8489 ---------------------------------
8491 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8493 return Has_Discriminants (Typ)
8494 and then Present (First_Discriminant (Typ))
8495 and then Present (Discriminant_Default_Value
8496 (First_Discriminant (Typ)));
8497 end Has_Defaulted_Discriminants;
8503 function Has_Denormals (E : Entity_Id) return Boolean is
8505 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8508 -------------------------------------------
8509 -- Has_Discriminant_Dependent_Constraint --
8510 -------------------------------------------
8512 function Has_Discriminant_Dependent_Constraint
8513 (Comp : Entity_Id) return Boolean
8515 Comp_Decl : constant Node_Id := Parent (Comp);
8516 Subt_Indic : Node_Id;
8521 -- Discriminants can't depend on discriminants
8523 if Ekind (Comp) = E_Discriminant then
8527 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8529 if Nkind (Subt_Indic) = N_Subtype_Indication then
8530 Constr := Constraint (Subt_Indic);
8532 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8533 Assn := First (Constraints (Constr));
8534 while Present (Assn) loop
8535 case Nkind (Assn) is
8536 when N_Subtype_Indication |
8540 if Depends_On_Discriminant (Assn) then
8544 when N_Discriminant_Association =>
8545 if Depends_On_Discriminant (Expression (Assn)) then
8560 end Has_Discriminant_Dependent_Constraint;
8562 --------------------------------------
8563 -- Has_Effectively_Volatile_Profile --
8564 --------------------------------------
8566 function Has_Effectively_Volatile_Profile
8567 (Subp_Id : Entity_Id) return Boolean
8572 -- Inspect the formal parameters looking for an effectively volatile
8575 Formal := First_Formal (Subp_Id);
8576 while Present (Formal) loop
8577 if Is_Effectively_Volatile (Etype (Formal)) then
8581 Next_Formal (Formal);
8584 -- Inspect the return type of functions
8586 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8587 and then Is_Effectively_Volatile (Etype (Subp_Id))
8593 end Has_Effectively_Volatile_Profile;
8595 --------------------------
8596 -- Has_Enabled_Property --
8597 --------------------------
8599 function Has_Enabled_Property
8600 (Item_Id : Entity_Id;
8601 Property : Name_Id) return Boolean
8603 function State_Has_Enabled_Property return Boolean;
8604 -- Determine whether a state denoted by Item_Id has the property enabled
8606 function Variable_Has_Enabled_Property return Boolean;
8607 -- Determine whether a variable denoted by Item_Id has the property
8610 --------------------------------
8611 -- State_Has_Enabled_Property --
8612 --------------------------------
8614 function State_Has_Enabled_Property return Boolean is
8615 Decl : constant Node_Id := Parent (Item_Id);
8623 -- The declaration of an external abstract state appears as an
8624 -- extension aggregate. If this is not the case, properties can never
8627 if Nkind (Decl) /= N_Extension_Aggregate then
8631 -- When External appears as a simple option, it automatically enables
8634 Opt := First (Expressions (Decl));
8635 while Present (Opt) loop
8636 if Nkind (Opt) = N_Identifier
8637 and then Chars (Opt) = Name_External
8645 -- When External specifies particular properties, inspect those and
8646 -- find the desired one (if any).
8648 Opt := First (Component_Associations (Decl));
8649 while Present (Opt) loop
8650 Opt_Nam := First (Choices (Opt));
8652 if Nkind (Opt_Nam) = N_Identifier
8653 and then Chars (Opt_Nam) = Name_External
8655 Props := Expression (Opt);
8657 -- Multiple properties appear as an aggregate
8659 if Nkind (Props) = N_Aggregate then
8661 -- Simple property form
8663 Prop := First (Expressions (Props));
8664 while Present (Prop) loop
8665 if Chars (Prop) = Property then
8672 -- Property with expression form
8674 Prop := First (Component_Associations (Props));
8675 while Present (Prop) loop
8676 Prop_Nam := First (Choices (Prop));
8678 -- The property can be represented in two ways:
8679 -- others => <value>
8680 -- <property> => <value>
8682 if Nkind (Prop_Nam) = N_Others_Choice
8683 or else (Nkind (Prop_Nam) = N_Identifier
8684 and then Chars (Prop_Nam) = Property)
8686 return Is_True (Expr_Value (Expression (Prop)));
8695 return Chars (Props) = Property;
8703 end State_Has_Enabled_Property;
8705 -----------------------------------
8706 -- Variable_Has_Enabled_Property --
8707 -----------------------------------
8709 function Variable_Has_Enabled_Property return Boolean is
8710 function Is_Enabled (Prag : Node_Id) return Boolean;
8711 -- Determine whether property pragma Prag (if present) denotes an
8712 -- enabled property.
8718 function Is_Enabled (Prag : Node_Id) return Boolean is
8722 if Present (Prag) then
8723 Arg1 := First (Pragma_Argument_Associations (Prag));
8725 -- The pragma has an optional Boolean expression, the related
8726 -- property is enabled only when the expression evaluates to
8729 if Present (Arg1) then
8730 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
8732 -- Otherwise the lack of expression enables the property by
8739 -- The property was never set in the first place
8748 AR : constant Node_Id :=
8749 Get_Pragma (Item_Id, Pragma_Async_Readers);
8750 AW : constant Node_Id :=
8751 Get_Pragma (Item_Id, Pragma_Async_Writers);
8752 ER : constant Node_Id :=
8753 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8754 EW : constant Node_Id :=
8755 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8757 -- Start of processing for Variable_Has_Enabled_Property
8760 -- A non-effectively volatile object can never possess external
8763 if not Is_Effectively_Volatile (Item_Id) then
8766 -- External properties related to variables come in two flavors -
8767 -- explicit and implicit. The explicit case is characterized by the
8768 -- presence of a property pragma with an optional Boolean flag. The
8769 -- property is enabled when the flag evaluates to True or the flag is
8770 -- missing altogether.
8772 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8775 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8778 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8781 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8784 -- The implicit case lacks all property pragmas
8786 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8792 end Variable_Has_Enabled_Property;
8794 -- Start of processing for Has_Enabled_Property
8797 -- Abstract states and variables have a flexible scheme of specifying
8798 -- external properties.
8800 if Ekind (Item_Id) = E_Abstract_State then
8801 return State_Has_Enabled_Property;
8803 elsif Ekind (Item_Id) = E_Variable then
8804 return Variable_Has_Enabled_Property;
8806 -- Otherwise a property is enabled when the related item is effectively
8810 return Is_Effectively_Volatile (Item_Id);
8812 end Has_Enabled_Property;
8814 -------------------------------------
8815 -- Has_Full_Default_Initialization --
8816 -------------------------------------
8818 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
8822 -- A scalar type is fully default initialized if it is subject to aspect
8825 if Is_Scalar_Type (Typ) then
8826 return Has_Default_Aspect (Typ);
8828 -- An array type is fully default initialized if its element type is
8829 -- scalar and the array type carries aspect Default_Component_Value or
8830 -- the element type is fully default initialized.
8832 elsif Is_Array_Type (Typ) then
8834 Has_Default_Aspect (Typ)
8835 or else Has_Full_Default_Initialization (Component_Type (Typ));
8837 -- A protected type, record type or type extension is fully default
8838 -- initialized if all its components either carry an initialization
8839 -- expression or have a type that is fully default initialized. The
8840 -- parent type of a type extension must be fully default initialized.
8842 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
8844 -- Inspect all entities defined in the scope of the type, looking for
8845 -- uninitialized components.
8847 Comp := First_Entity (Typ);
8848 while Present (Comp) loop
8849 if Ekind (Comp) = E_Component
8850 and then Comes_From_Source (Comp)
8851 and then No (Expression (Parent (Comp)))
8852 and then not Has_Full_Default_Initialization (Etype (Comp))
8860 -- Ensure that the parent type of a type extension is fully default
8863 if Etype (Typ) /= Typ
8864 and then not Has_Full_Default_Initialization (Etype (Typ))
8869 -- If we get here, then all components and parent portion are fully
8870 -- default initialized.
8874 -- A task type is fully default initialized by default
8876 elsif Is_Task_Type (Typ) then
8880 -- A private type and by extension its full view is fully default
8881 -- initialized if it is subject to pragma Default_Initial_Condition
8882 -- with a non-null argument or inherits the pragma from a parent type.
8883 -- Since any type can act as the full view of a private type, this check
8884 -- is separated from the circuitry above.
8886 if Has_Default_Init_Cond (Typ)
8887 or else Has_Inherited_Default_Init_Cond (Typ)
8890 Nkind (First (Pragma_Argument_Associations (Get_Pragma
8891 (Typ, Pragma_Default_Initial_Condition)))) /= N_Null;
8893 -- Otherwise the type is not fully default initialized
8898 end Has_Full_Default_Initialization;
8900 --------------------
8901 -- Has_Infinities --
8902 --------------------
8904 function Has_Infinities (E : Entity_Id) return Boolean is
8907 Is_Floating_Point_Type (E)
8908 and then Nkind (Scalar_Range (E)) = N_Range
8909 and then Includes_Infinities (Scalar_Range (E));
8912 --------------------
8913 -- Has_Interfaces --
8914 --------------------
8916 function Has_Interfaces
8918 Use_Full_View : Boolean := True) return Boolean
8920 Typ : Entity_Id := Base_Type (T);
8923 -- Handle concurrent types
8925 if Is_Concurrent_Type (Typ) then
8926 Typ := Corresponding_Record_Type (Typ);
8929 if not Present (Typ)
8930 or else not Is_Record_Type (Typ)
8931 or else not Is_Tagged_Type (Typ)
8936 -- Handle private types
8938 if Use_Full_View and then Present (Full_View (Typ)) then
8939 Typ := Full_View (Typ);
8942 -- Handle concurrent record types
8944 if Is_Concurrent_Record_Type (Typ)
8945 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8951 if Is_Interface (Typ)
8953 (Is_Record_Type (Typ)
8954 and then Present (Interfaces (Typ))
8955 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8960 exit when Etype (Typ) = Typ
8962 -- Handle private types
8964 or else (Present (Full_View (Etype (Typ)))
8965 and then Full_View (Etype (Typ)) = Typ)
8967 -- Protect frontend against wrong sources with cyclic derivations
8969 or else Etype (Typ) = T;
8971 -- Climb to the ancestor type handling private types
8973 if Present (Full_View (Etype (Typ))) then
8974 Typ := Full_View (Etype (Typ));
8983 ---------------------------------
8984 -- Has_No_Obvious_Side_Effects --
8985 ---------------------------------
8987 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8989 -- For now, just handle literals, constants, and non-volatile
8990 -- variables and expressions combining these with operators or
8991 -- short circuit forms.
8993 if Nkind (N) in N_Numeric_Or_String_Literal then
8996 elsif Nkind (N) = N_Character_Literal then
8999 elsif Nkind (N) in N_Unary_Op then
9000 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9002 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9003 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9005 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9007 elsif Nkind (N) = N_Expression_With_Actions
9008 and then Is_Empty_List (Actions (N))
9010 return Has_No_Obvious_Side_Effects (Expression (N));
9012 elsif Nkind (N) in N_Has_Entity then
9013 return Present (Entity (N))
9014 and then Ekind_In (Entity (N), E_Variable,
9016 E_Enumeration_Literal,
9020 and then not Is_Volatile (Entity (N));
9025 end Has_No_Obvious_Side_Effects;
9027 ------------------------
9028 -- Has_Null_Exclusion --
9029 ------------------------
9031 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9034 when N_Access_Definition |
9035 N_Access_Function_Definition |
9036 N_Access_Procedure_Definition |
9037 N_Access_To_Object_Definition |
9039 N_Derived_Type_Definition |
9040 N_Function_Specification |
9041 N_Subtype_Declaration =>
9042 return Null_Exclusion_Present (N);
9044 when N_Component_Definition |
9045 N_Formal_Object_Declaration |
9046 N_Object_Renaming_Declaration =>
9047 if Present (Subtype_Mark (N)) then
9048 return Null_Exclusion_Present (N);
9049 else pragma Assert (Present (Access_Definition (N)));
9050 return Null_Exclusion_Present (Access_Definition (N));
9053 when N_Discriminant_Specification =>
9054 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9055 return Null_Exclusion_Present (Discriminant_Type (N));
9057 return Null_Exclusion_Present (N);
9060 when N_Object_Declaration =>
9061 if Nkind (Object_Definition (N)) = N_Access_Definition then
9062 return Null_Exclusion_Present (Object_Definition (N));
9064 return Null_Exclusion_Present (N);
9067 when N_Parameter_Specification =>
9068 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9069 return Null_Exclusion_Present (Parameter_Type (N));
9071 return Null_Exclusion_Present (N);
9078 end Has_Null_Exclusion;
9080 ------------------------
9081 -- Has_Null_Extension --
9082 ------------------------
9084 function Has_Null_Extension (T : Entity_Id) return Boolean is
9085 B : constant Entity_Id := Base_Type (T);
9090 if Nkind (Parent (B)) = N_Full_Type_Declaration
9091 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9093 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9095 if Present (Ext) then
9096 if Null_Present (Ext) then
9099 Comps := Component_List (Ext);
9101 -- The null component list is rewritten during analysis to
9102 -- include the parent component. Any other component indicates
9103 -- that the extension was not originally null.
9105 return Null_Present (Comps)
9106 or else No (Next (First (Component_Items (Comps))));
9115 end Has_Null_Extension;
9117 -------------------------------
9118 -- Has_Overriding_Initialize --
9119 -------------------------------
9121 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9122 BT : constant Entity_Id := Base_Type (T);
9126 if Is_Controlled (BT) then
9127 if Is_RTU (Scope (BT), Ada_Finalization) then
9130 elsif Present (Primitive_Operations (BT)) then
9131 P := First_Elmt (Primitive_Operations (BT));
9132 while Present (P) loop
9134 Init : constant Entity_Id := Node (P);
9135 Formal : constant Entity_Id := First_Formal (Init);
9137 if Ekind (Init) = E_Procedure
9138 and then Chars (Init) = Name_Initialize
9139 and then Comes_From_Source (Init)
9140 and then Present (Formal)
9141 and then Etype (Formal) = BT
9142 and then No (Next_Formal (Formal))
9143 and then (Ada_Version < Ada_2012
9144 or else not Null_Present (Parent (Init)))
9154 -- Here if type itself does not have a non-null Initialize operation:
9155 -- check immediate ancestor.
9157 if Is_Derived_Type (BT)
9158 and then Has_Overriding_Initialize (Etype (BT))
9165 end Has_Overriding_Initialize;
9167 --------------------------------------
9168 -- Has_Preelaborable_Initialization --
9169 --------------------------------------
9171 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9174 procedure Check_Components (E : Entity_Id);
9175 -- Check component/discriminant chain, sets Has_PE False if a component
9176 -- or discriminant does not meet the preelaborable initialization rules.
9178 ----------------------
9179 -- Check_Components --
9180 ----------------------
9182 procedure Check_Components (E : Entity_Id) is
9186 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9187 -- Returns True if and only if the expression denoted by N does not
9188 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9190 ---------------------------------
9191 -- Is_Preelaborable_Expression --
9192 ---------------------------------
9194 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9198 Comp_Type : Entity_Id;
9199 Is_Array_Aggr : Boolean;
9202 if Is_OK_Static_Expression (N) then
9205 elsif Nkind (N) = N_Null then
9208 -- Attributes are allowed in general, even if their prefix is a
9209 -- formal type. (It seems that certain attributes known not to be
9210 -- static might not be allowed, but there are no rules to prevent
9213 elsif Nkind (N) = N_Attribute_Reference then
9216 -- The name of a discriminant evaluated within its parent type is
9217 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9218 -- names that denote discriminals as well as discriminants to
9219 -- catch references occurring within init procs.
9221 elsif Is_Entity_Name (N)
9223 (Ekind (Entity (N)) = E_Discriminant
9224 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9225 and then Present (Discriminal_Link (Entity (N)))))
9229 elsif Nkind (N) = N_Qualified_Expression then
9230 return Is_Preelaborable_Expression (Expression (N));
9232 -- For aggregates we have to check that each of the associations
9233 -- is preelaborable.
9235 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9236 Is_Array_Aggr := Is_Array_Type (Etype (N));
9238 if Is_Array_Aggr then
9239 Comp_Type := Component_Type (Etype (N));
9242 -- Check the ancestor part of extension aggregates, which must
9243 -- be either the name of a type that has preelaborable init or
9244 -- an expression that is preelaborable.
9246 if Nkind (N) = N_Extension_Aggregate then
9248 Anc_Part : constant Node_Id := Ancestor_Part (N);
9251 if Is_Entity_Name (Anc_Part)
9252 and then Is_Type (Entity (Anc_Part))
9254 if not Has_Preelaborable_Initialization
9260 elsif not Is_Preelaborable_Expression (Anc_Part) then
9266 -- Check positional associations
9268 Exp := First (Expressions (N));
9269 while Present (Exp) loop
9270 if not Is_Preelaborable_Expression (Exp) then
9277 -- Check named associations
9279 Assn := First (Component_Associations (N));
9280 while Present (Assn) loop
9281 Choice := First (Choices (Assn));
9282 while Present (Choice) loop
9283 if Is_Array_Aggr then
9284 if Nkind (Choice) = N_Others_Choice then
9287 elsif Nkind (Choice) = N_Range then
9288 if not Is_OK_Static_Range (Choice) then
9292 elsif not Is_OK_Static_Expression (Choice) then
9297 Comp_Type := Etype (Choice);
9303 -- If the association has a <> at this point, then we have
9304 -- to check whether the component's type has preelaborable
9305 -- initialization. Note that this only occurs when the
9306 -- association's corresponding component does not have a
9307 -- default expression, the latter case having already been
9308 -- expanded as an expression for the association.
9310 if Box_Present (Assn) then
9311 if not Has_Preelaborable_Initialization (Comp_Type) then
9315 -- In the expression case we check whether the expression
9316 -- is preelaborable.
9319 not Is_Preelaborable_Expression (Expression (Assn))
9327 -- If we get here then aggregate as a whole is preelaborable
9331 -- All other cases are not preelaborable
9336 end Is_Preelaborable_Expression;
9338 -- Start of processing for Check_Components
9341 -- Loop through entities of record or protected type
9344 while Present (Ent) loop
9346 -- We are interested only in components and discriminants
9353 -- Get default expression if any. If there is no declaration
9354 -- node, it means we have an internal entity. The parent and
9355 -- tag fields are examples of such entities. For such cases,
9356 -- we just test the type of the entity.
9358 if Present (Declaration_Node (Ent)) then
9359 Exp := Expression (Declaration_Node (Ent));
9362 when E_Discriminant =>
9364 -- Note: for a renamed discriminant, the Declaration_Node
9365 -- may point to the one from the ancestor, and have a
9366 -- different expression, so use the proper attribute to
9367 -- retrieve the expression from the derived constraint.
9369 Exp := Discriminant_Default_Value (Ent);
9372 goto Check_Next_Entity;
9375 -- A component has PI if it has no default expression and the
9376 -- component type has PI.
9379 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9384 -- Require the default expression to be preelaborable
9386 elsif not Is_Preelaborable_Expression (Exp) then
9391 <<Check_Next_Entity>>
9394 end Check_Components;
9396 -- Start of processing for Has_Preelaborable_Initialization
9399 -- Immediate return if already marked as known preelaborable init. This
9400 -- covers types for which this function has already been called once
9401 -- and returned True (in which case the result is cached), and also
9402 -- types to which a pragma Preelaborable_Initialization applies.
9404 if Known_To_Have_Preelab_Init (E) then
9408 -- If the type is a subtype representing a generic actual type, then
9409 -- test whether its base type has preelaborable initialization since
9410 -- the subtype representing the actual does not inherit this attribute
9411 -- from the actual or formal. (but maybe it should???)
9413 if Is_Generic_Actual_Type (E) then
9414 return Has_Preelaborable_Initialization (Base_Type (E));
9417 -- All elementary types have preelaborable initialization
9419 if Is_Elementary_Type (E) then
9422 -- Array types have PI if the component type has PI
9424 elsif Is_Array_Type (E) then
9425 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9427 -- A derived type has preelaborable initialization if its parent type
9428 -- has preelaborable initialization and (in the case of a derived record
9429 -- extension) if the non-inherited components all have preelaborable
9430 -- initialization. However, a user-defined controlled type with an
9431 -- overriding Initialize procedure does not have preelaborable
9434 elsif Is_Derived_Type (E) then
9436 -- If the derived type is a private extension then it doesn't have
9437 -- preelaborable initialization.
9439 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9443 -- First check whether ancestor type has preelaborable initialization
9445 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9447 -- If OK, check extension components (if any)
9449 if Has_PE and then Is_Record_Type (E) then
9450 Check_Components (First_Entity (E));
9453 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9454 -- with a user defined Initialize procedure does not have PI. If
9455 -- the type is untagged, the control primitives come from a component
9456 -- that has already been checked.
9459 and then Is_Controlled (E)
9460 and then Is_Tagged_Type (E)
9461 and then Has_Overriding_Initialize (E)
9466 -- Private types not derived from a type having preelaborable init and
9467 -- that are not marked with pragma Preelaborable_Initialization do not
9468 -- have preelaborable initialization.
9470 elsif Is_Private_Type (E) then
9473 -- Record type has PI if it is non private and all components have PI
9475 elsif Is_Record_Type (E) then
9477 Check_Components (First_Entity (E));
9479 -- Protected types must not have entries, and components must meet
9480 -- same set of rules as for record components.
9482 elsif Is_Protected_Type (E) then
9483 if Has_Entries (E) then
9487 Check_Components (First_Entity (E));
9488 Check_Components (First_Private_Entity (E));
9491 -- Type System.Address always has preelaborable initialization
9493 elsif Is_RTE (E, RE_Address) then
9496 -- In all other cases, type does not have preelaborable initialization
9502 -- If type has preelaborable initialization, cache result
9505 Set_Known_To_Have_Preelab_Init (E);
9509 end Has_Preelaborable_Initialization;
9511 ---------------------------
9512 -- Has_Private_Component --
9513 ---------------------------
9515 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9516 Btype : Entity_Id := Base_Type (Type_Id);
9517 Component : Entity_Id;
9520 if Error_Posted (Type_Id)
9521 or else Error_Posted (Btype)
9526 if Is_Class_Wide_Type (Btype) then
9527 Btype := Root_Type (Btype);
9530 if Is_Private_Type (Btype) then
9532 UT : constant Entity_Id := Underlying_Type (Btype);
9535 if No (Full_View (Btype)) then
9536 return not Is_Generic_Type (Btype)
9538 not Is_Generic_Type (Root_Type (Btype));
9540 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9543 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9547 elsif Is_Array_Type (Btype) then
9548 return Has_Private_Component (Component_Type (Btype));
9550 elsif Is_Record_Type (Btype) then
9551 Component := First_Component (Btype);
9552 while Present (Component) loop
9553 if Has_Private_Component (Etype (Component)) then
9557 Next_Component (Component);
9562 elsif Is_Protected_Type (Btype)
9563 and then Present (Corresponding_Record_Type (Btype))
9565 return Has_Private_Component (Corresponding_Record_Type (Btype));
9570 end Has_Private_Component;
9572 ----------------------
9573 -- Has_Signed_Zeros --
9574 ----------------------
9576 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9578 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9579 end Has_Signed_Zeros;
9581 ------------------------------
9582 -- Has_Significant_Contract --
9583 ------------------------------
9585 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9586 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9589 -- _Finalizer procedure
9591 if Subp_Nam = Name_uFinalizer then
9594 -- _Postconditions procedure
9596 elsif Subp_Nam = Name_uPostconditions then
9599 -- Predicate function
9601 elsif Ekind (Subp_Id) = E_Function
9602 and then Is_Predicate_Function (Subp_Id)
9608 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9614 end Has_Significant_Contract;
9616 -----------------------------
9617 -- Has_Static_Array_Bounds --
9618 -----------------------------
9620 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9621 Ndims : constant Nat := Number_Dimensions (Typ);
9628 -- Unconstrained types do not have static bounds
9630 if not Is_Constrained (Typ) then
9634 -- First treat string literals specially, as the lower bound and length
9635 -- of string literals are not stored like those of arrays.
9637 -- A string literal always has static bounds
9639 if Ekind (Typ) = E_String_Literal_Subtype then
9643 -- Treat all dimensions in turn
9645 Index := First_Index (Typ);
9646 for Indx in 1 .. Ndims loop
9648 -- In case of an illegal index which is not a discrete type, return
9649 -- that the type is not static.
9651 if not Is_Discrete_Type (Etype (Index))
9652 or else Etype (Index) = Any_Type
9657 Get_Index_Bounds (Index, Low, High);
9659 if Error_Posted (Low) or else Error_Posted (High) then
9663 if Is_OK_Static_Expression (Low)
9665 Is_OK_Static_Expression (High)
9675 -- If we fall through the loop, all indexes matched
9678 end Has_Static_Array_Bounds;
9684 function Has_Stream (T : Entity_Id) return Boolean is
9691 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
9694 elsif Is_Array_Type (T) then
9695 return Has_Stream (Component_Type (T));
9697 elsif Is_Record_Type (T) then
9698 E := First_Component (T);
9699 while Present (E) loop
9700 if Has_Stream (Etype (E)) then
9709 elsif Is_Private_Type (T) then
9710 return Has_Stream (Underlying_Type (T));
9721 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
9723 Get_Name_String (Chars (E));
9724 return Name_Buffer (Name_Len) = Suffix;
9731 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9733 Get_Name_String (Chars (E));
9734 Add_Char_To_Name_Buffer (Suffix);
9742 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9744 pragma Assert (Has_Suffix (E, Suffix));
9745 Get_Name_String (Chars (E));
9746 Name_Len := Name_Len - 1;
9750 --------------------------
9751 -- Has_Tagged_Component --
9752 --------------------------
9754 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
9758 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
9759 return Has_Tagged_Component (Underlying_Type (Typ));
9761 elsif Is_Array_Type (Typ) then
9762 return Has_Tagged_Component (Component_Type (Typ));
9764 elsif Is_Tagged_Type (Typ) then
9767 elsif Is_Record_Type (Typ) then
9768 Comp := First_Component (Typ);
9769 while Present (Comp) loop
9770 if Has_Tagged_Component (Etype (Comp)) then
9774 Next_Component (Comp);
9782 end Has_Tagged_Component;
9784 ----------------------------
9785 -- Has_Volatile_Component --
9786 ----------------------------
9788 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
9792 if Has_Volatile_Components (Typ) then
9795 elsif Is_Array_Type (Typ) then
9796 return Is_Volatile (Component_Type (Typ));
9798 elsif Is_Record_Type (Typ) then
9799 Comp := First_Component (Typ);
9800 while Present (Comp) loop
9801 if Is_Volatile_Object (Comp) then
9805 Comp := Next_Component (Comp);
9810 end Has_Volatile_Component;
9812 -------------------------
9813 -- Implementation_Kind --
9814 -------------------------
9816 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9817 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9820 pragma Assert (Present (Impl_Prag));
9821 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9822 return Chars (Get_Pragma_Arg (Arg));
9823 end Implementation_Kind;
9825 --------------------------
9826 -- Implements_Interface --
9827 --------------------------
9829 function Implements_Interface
9830 (Typ_Ent : Entity_Id;
9831 Iface_Ent : Entity_Id;
9832 Exclude_Parents : Boolean := False) return Boolean
9834 Ifaces_List : Elist_Id;
9836 Iface : Entity_Id := Base_Type (Iface_Ent);
9837 Typ : Entity_Id := Base_Type (Typ_Ent);
9840 if Is_Class_Wide_Type (Typ) then
9841 Typ := Root_Type (Typ);
9844 if not Has_Interfaces (Typ) then
9848 if Is_Class_Wide_Type (Iface) then
9849 Iface := Root_Type (Iface);
9852 Collect_Interfaces (Typ, Ifaces_List);
9854 Elmt := First_Elmt (Ifaces_List);
9855 while Present (Elmt) loop
9856 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9857 and then Exclude_Parents
9861 elsif Node (Elmt) = Iface then
9869 end Implements_Interface;
9871 ------------------------------------
9872 -- In_Assertion_Expression_Pragma --
9873 ------------------------------------
9875 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9877 Prag : Node_Id := Empty;
9880 -- Climb the parent chain looking for an enclosing pragma
9883 while Present (Par) loop
9884 if Nkind (Par) = N_Pragma then
9888 -- Precondition-like pragmas are expanded into if statements, check
9889 -- the original node instead.
9891 elsif Nkind (Original_Node (Par)) = N_Pragma then
9892 Prag := Original_Node (Par);
9895 -- The expansion of attribute 'Old generates a constant to capture
9896 -- the result of the prefix. If the parent traversal reaches
9897 -- one of these constants, then the node technically came from a
9898 -- postcondition-like pragma. Note that the Ekind is not tested here
9899 -- because N may be the expression of an object declaration which is
9900 -- currently being analyzed. Such objects carry Ekind of E_Void.
9902 elsif Nkind (Par) = N_Object_Declaration
9903 and then Constant_Present (Par)
9904 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9908 -- Prevent the search from going too far
9910 elsif Is_Body_Or_Package_Declaration (Par) then
9914 Par := Parent (Par);
9919 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9920 end In_Assertion_Expression_Pragma;
9926 function In_Instance return Boolean is
9927 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9932 while Present (S) and then S /= Standard_Standard loop
9933 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9934 and then Is_Generic_Instance (S)
9936 -- A child instance is always compiled in the context of a parent
9937 -- instance. Nevertheless, the actuals are not analyzed in an
9938 -- instance context. We detect this case by examining the current
9939 -- compilation unit, which must be a child instance, and checking
9940 -- that it is not currently on the scope stack.
9942 if Is_Child_Unit (Curr_Unit)
9943 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9944 N_Package_Instantiation
9945 and then not In_Open_Scopes (Curr_Unit)
9959 ----------------------
9960 -- In_Instance_Body --
9961 ----------------------
9963 function In_Instance_Body return Boolean is
9968 while Present (S) and then S /= Standard_Standard loop
9969 if Ekind_In (S, E_Function, E_Procedure)
9970 and then Is_Generic_Instance (S)
9974 elsif Ekind (S) = E_Package
9975 and then In_Package_Body (S)
9976 and then Is_Generic_Instance (S)
9985 end In_Instance_Body;
9987 -----------------------------
9988 -- In_Instance_Not_Visible --
9989 -----------------------------
9991 function In_Instance_Not_Visible return Boolean is
9996 while Present (S) and then S /= Standard_Standard loop
9997 if Ekind_In (S, E_Function, E_Procedure)
9998 and then Is_Generic_Instance (S)
10002 elsif Ekind (S) = E_Package
10003 and then (In_Package_Body (S) or else In_Private_Part (S))
10004 and then Is_Generic_Instance (S)
10013 end In_Instance_Not_Visible;
10015 ------------------------------
10016 -- In_Instance_Visible_Part --
10017 ------------------------------
10019 function In_Instance_Visible_Part return Boolean is
10023 S := Current_Scope;
10024 while Present (S) and then S /= Standard_Standard loop
10025 if Ekind (S) = E_Package
10026 and then Is_Generic_Instance (S)
10027 and then not In_Package_Body (S)
10028 and then not In_Private_Part (S)
10037 end In_Instance_Visible_Part;
10039 ---------------------
10040 -- In_Package_Body --
10041 ---------------------
10043 function In_Package_Body return Boolean is
10047 S := Current_Scope;
10048 while Present (S) and then S /= Standard_Standard loop
10049 if Ekind (S) = E_Package and then In_Package_Body (S) then
10057 end In_Package_Body;
10059 --------------------------------
10060 -- In_Parameter_Specification --
10061 --------------------------------
10063 function In_Parameter_Specification (N : Node_Id) return Boolean is
10068 while Present (PN) loop
10069 if Nkind (PN) = N_Parameter_Specification then
10077 end In_Parameter_Specification;
10079 --------------------------
10080 -- In_Pragma_Expression --
10081 --------------------------
10083 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10090 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10096 end In_Pragma_Expression;
10098 -------------------------------------
10099 -- In_Reverse_Storage_Order_Object --
10100 -------------------------------------
10102 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10104 Btyp : Entity_Id := Empty;
10107 -- Climb up indexed components
10111 case Nkind (Pref) is
10112 when N_Selected_Component =>
10113 Pref := Prefix (Pref);
10116 when N_Indexed_Component =>
10117 Pref := Prefix (Pref);
10125 if Present (Pref) then
10126 Btyp := Base_Type (Etype (Pref));
10129 return Present (Btyp)
10130 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10131 and then Reverse_Storage_Order (Btyp);
10132 end In_Reverse_Storage_Order_Object;
10134 --------------------------------------
10135 -- In_Subprogram_Or_Concurrent_Unit --
10136 --------------------------------------
10138 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10143 -- Use scope chain to check successively outer scopes
10145 E := Current_Scope;
10149 if K in Subprogram_Kind
10150 or else K in Concurrent_Kind
10151 or else K in Generic_Subprogram_Kind
10155 elsif E = Standard_Standard then
10161 end In_Subprogram_Or_Concurrent_Unit;
10163 ---------------------
10164 -- In_Visible_Part --
10165 ---------------------
10167 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10169 return Is_Package_Or_Generic_Package (Scope_Id)
10170 and then In_Open_Scopes (Scope_Id)
10171 and then not In_Package_Body (Scope_Id)
10172 and then not In_Private_Part (Scope_Id);
10173 end In_Visible_Part;
10175 --------------------------------
10176 -- Incomplete_Or_Partial_View --
10177 --------------------------------
10179 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10180 function Inspect_Decls
10182 Taft : Boolean := False) return Entity_Id;
10183 -- Check whether a declarative region contains the incomplete or partial
10186 -------------------
10187 -- Inspect_Decls --
10188 -------------------
10190 function Inspect_Decls
10192 Taft : Boolean := False) return Entity_Id
10198 Decl := First (Decls);
10199 while Present (Decl) loop
10203 if Nkind (Decl) = N_Incomplete_Type_Declaration then
10204 Match := Defining_Identifier (Decl);
10208 if Nkind_In (Decl, N_Private_Extension_Declaration,
10209 N_Private_Type_Declaration)
10211 Match := Defining_Identifier (Decl);
10216 and then Present (Full_View (Match))
10217 and then Full_View (Match) = Id
10232 -- Start of processing for Incomplete_Or_Partial_View
10235 -- Deferred constant or incomplete type case
10237 Prev := Current_Entity_In_Scope (Id);
10240 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10241 and then Present (Full_View (Prev))
10242 and then Full_View (Prev) = Id
10247 -- Private or Taft amendment type case
10250 Pkg : constant Entity_Id := Scope (Id);
10251 Pkg_Decl : Node_Id := Pkg;
10254 if Present (Pkg) and then Ekind (Pkg) = E_Package then
10255 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10256 Pkg_Decl := Parent (Pkg_Decl);
10259 -- It is knows that Typ has a private view, look for it in the
10260 -- visible declarations of the enclosing scope. A special case
10261 -- of this is when the two views have been exchanged - the full
10262 -- appears earlier than the private.
10264 if Has_Private_Declaration (Id) then
10265 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10267 -- Exchanged view case, look in the private declarations
10270 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10275 -- Otherwise if this is the package body, then Typ is a potential
10276 -- Taft amendment type. The incomplete view should be located in
10277 -- the private declarations of the enclosing scope.
10279 elsif In_Package_Body (Pkg) then
10280 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10285 -- The type has no incomplete or private view
10288 end Incomplete_Or_Partial_View;
10290 -----------------------------------------
10291 -- Inherit_Default_Init_Cond_Procedure --
10292 -----------------------------------------
10294 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
10295 Par_Typ : constant Entity_Id := Etype (Typ);
10298 -- A derived type inherits the default initial condition procedure of
10299 -- its parent type.
10301 if No (Default_Init_Cond_Procedure (Typ)) then
10302 Set_Default_Init_Cond_Procedure
10303 (Typ, Default_Init_Cond_Procedure (Par_Typ));
10305 end Inherit_Default_Init_Cond_Procedure;
10307 ----------------------------
10308 -- Inherit_Rep_Item_Chain --
10309 ----------------------------
10311 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
10312 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
10313 Item : Node_Id := Empty;
10314 Last_Item : Node_Id := Empty;
10317 -- Reach the end of the destination type's chain (if any) and capture
10320 Item := First_Rep_Item (Typ);
10321 while Present (Item) loop
10323 -- Do not inherit a chain that has been inherited already
10325 if Item = From_Item then
10330 Item := Next_Rep_Item (Item);
10333 Item := First_Rep_Item (From_Typ);
10335 -- Additional check when both parent and current type have rep.
10336 -- items, to prevent circularities when the derivation completes
10337 -- a private declaration and inherits from both views of the parent.
10338 -- There may be a remaining problem with the proper ordering of
10339 -- attribute specifications and aspects on the chains of the four
10340 -- entities involved. ???
10342 if Present (Item) and then Present (From_Item) then
10343 while Present (Item) loop
10344 if Item = First_Rep_Item (Typ) then
10348 Item := Next_Rep_Item (Item);
10352 -- When the destination type has a rep item chain, the chain of the
10353 -- source type is appended to it.
10355 if Present (Last_Item) then
10356 Set_Next_Rep_Item (Last_Item, From_Item);
10358 -- Otherwise the destination type directly inherits the rep item chain
10359 -- of the source type (if any).
10362 Set_First_Rep_Item (Typ, From_Item);
10364 end Inherit_Rep_Item_Chain;
10366 ---------------------------------
10367 -- Insert_Explicit_Dereference --
10368 ---------------------------------
10370 procedure Insert_Explicit_Dereference (N : Node_Id) is
10371 New_Prefix : constant Node_Id := Relocate_Node (N);
10372 Ent : Entity_Id := Empty;
10379 Save_Interps (N, New_Prefix);
10382 Make_Explicit_Dereference (Sloc (Parent (N)),
10383 Prefix => New_Prefix));
10385 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
10387 if Is_Overloaded (New_Prefix) then
10389 -- The dereference is also overloaded, and its interpretations are
10390 -- the designated types of the interpretations of the original node.
10392 Set_Etype (N, Any_Type);
10394 Get_First_Interp (New_Prefix, I, It);
10395 while Present (It.Nam) loop
10398 if Is_Access_Type (T) then
10399 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
10402 Get_Next_Interp (I, It);
10408 -- Prefix is unambiguous: mark the original prefix (which might
10409 -- Come_From_Source) as a reference, since the new (relocated) one
10410 -- won't be taken into account.
10412 if Is_Entity_Name (New_Prefix) then
10413 Ent := Entity (New_Prefix);
10414 Pref := New_Prefix;
10416 -- For a retrieval of a subcomponent of some composite object,
10417 -- retrieve the ultimate entity if there is one.
10419 elsif Nkind_In (New_Prefix, N_Selected_Component,
10420 N_Indexed_Component)
10422 Pref := Prefix (New_Prefix);
10423 while Present (Pref)
10424 and then Nkind_In (Pref, N_Selected_Component,
10425 N_Indexed_Component)
10427 Pref := Prefix (Pref);
10430 if Present (Pref) and then Is_Entity_Name (Pref) then
10431 Ent := Entity (Pref);
10435 -- Place the reference on the entity node
10437 if Present (Ent) then
10438 Generate_Reference (Ent, Pref);
10441 end Insert_Explicit_Dereference;
10443 ------------------------------------------
10444 -- Inspect_Deferred_Constant_Completion --
10445 ------------------------------------------
10447 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10451 Decl := First (Decls);
10452 while Present (Decl) loop
10454 -- Deferred constant signature
10456 if Nkind (Decl) = N_Object_Declaration
10457 and then Constant_Present (Decl)
10458 and then No (Expression (Decl))
10460 -- No need to check internally generated constants
10462 and then Comes_From_Source (Decl)
10464 -- The constant is not completed. A full object declaration or a
10465 -- pragma Import complete a deferred constant.
10467 and then not Has_Completion (Defining_Identifier (Decl))
10470 ("constant declaration requires initialization expression",
10471 Defining_Identifier (Decl));
10474 Decl := Next (Decl);
10476 end Inspect_Deferred_Constant_Completion;
10478 -----------------------------
10479 -- Install_Generic_Formals --
10480 -----------------------------
10482 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10486 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10488 E := First_Entity (Subp_Id);
10489 while Present (E) loop
10490 Install_Entity (E);
10493 end Install_Generic_Formals;
10495 -----------------------------
10496 -- Is_Actual_Out_Parameter --
10497 -----------------------------
10499 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10500 Formal : Entity_Id;
10503 Find_Actual (N, Formal, Call);
10504 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10505 end Is_Actual_Out_Parameter;
10507 -------------------------
10508 -- Is_Actual_Parameter --
10509 -------------------------
10511 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10512 PK : constant Node_Kind := Nkind (Parent (N));
10516 when N_Parameter_Association =>
10517 return N = Explicit_Actual_Parameter (Parent (N));
10519 when N_Subprogram_Call =>
10520 return Is_List_Member (N)
10522 List_Containing (N) = Parameter_Associations (Parent (N));
10527 end Is_Actual_Parameter;
10529 --------------------------------
10530 -- Is_Actual_Tagged_Parameter --
10531 --------------------------------
10533 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10534 Formal : Entity_Id;
10537 Find_Actual (N, Formal, Call);
10538 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10539 end Is_Actual_Tagged_Parameter;
10541 ---------------------
10542 -- Is_Aliased_View --
10543 ---------------------
10545 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10549 if Is_Entity_Name (Obj) then
10556 or else (Present (Renamed_Object (E))
10557 and then Is_Aliased_View (Renamed_Object (E)))))
10559 or else ((Is_Formal (E)
10560 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10561 E_Generic_In_Parameter))
10562 and then Is_Tagged_Type (Etype (E)))
10564 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10566 -- Current instance of type, either directly or as rewritten
10567 -- reference to the current object.
10569 or else (Is_Entity_Name (Original_Node (Obj))
10570 and then Present (Entity (Original_Node (Obj)))
10571 and then Is_Type (Entity (Original_Node (Obj))))
10573 or else (Is_Type (E) and then E = Current_Scope)
10575 or else (Is_Incomplete_Or_Private_Type (E)
10576 and then Full_View (E) = Current_Scope)
10578 -- Ada 2012 AI05-0053: the return object of an extended return
10579 -- statement is aliased if its type is immutably limited.
10581 or else (Is_Return_Object (E)
10582 and then Is_Limited_View (Etype (E)));
10584 elsif Nkind (Obj) = N_Selected_Component then
10585 return Is_Aliased (Entity (Selector_Name (Obj)));
10587 elsif Nkind (Obj) = N_Indexed_Component then
10588 return Has_Aliased_Components (Etype (Prefix (Obj)))
10590 (Is_Access_Type (Etype (Prefix (Obj)))
10591 and then Has_Aliased_Components
10592 (Designated_Type (Etype (Prefix (Obj)))));
10594 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10595 return Is_Tagged_Type (Etype (Obj))
10596 and then Is_Aliased_View (Expression (Obj));
10598 elsif Nkind (Obj) = N_Explicit_Dereference then
10599 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10604 end Is_Aliased_View;
10606 -------------------------
10607 -- Is_Ancestor_Package --
10608 -------------------------
10610 function Is_Ancestor_Package
10612 E2 : Entity_Id) return Boolean
10618 while Present (Par) and then Par /= Standard_Standard loop
10623 Par := Scope (Par);
10627 end Is_Ancestor_Package;
10629 ----------------------
10630 -- Is_Atomic_Object --
10631 ----------------------
10633 function Is_Atomic_Object (N : Node_Id) return Boolean is
10635 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
10636 -- Determines if given object has atomic components
10638 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
10639 -- If prefix is an implicit dereference, examine designated type
10641 ----------------------
10642 -- Is_Atomic_Prefix --
10643 ----------------------
10645 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
10647 if Is_Access_Type (Etype (N)) then
10649 Has_Atomic_Components (Designated_Type (Etype (N)));
10651 return Object_Has_Atomic_Components (N);
10653 end Is_Atomic_Prefix;
10655 ----------------------------------
10656 -- Object_Has_Atomic_Components --
10657 ----------------------------------
10659 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
10661 if Has_Atomic_Components (Etype (N))
10662 or else Is_Atomic (Etype (N))
10666 elsif Is_Entity_Name (N)
10667 and then (Has_Atomic_Components (Entity (N))
10668 or else Is_Atomic (Entity (N)))
10672 elsif Nkind (N) = N_Selected_Component
10673 and then Is_Atomic (Entity (Selector_Name (N)))
10677 elsif Nkind (N) = N_Indexed_Component
10678 or else Nkind (N) = N_Selected_Component
10680 return Is_Atomic_Prefix (Prefix (N));
10685 end Object_Has_Atomic_Components;
10687 -- Start of processing for Is_Atomic_Object
10690 -- Predicate is not relevant to subprograms
10692 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
10695 elsif Is_Atomic (Etype (N))
10696 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
10700 elsif Nkind (N) = N_Selected_Component
10701 and then Is_Atomic (Entity (Selector_Name (N)))
10705 elsif Nkind (N) = N_Indexed_Component
10706 or else Nkind (N) = N_Selected_Component
10708 return Is_Atomic_Prefix (Prefix (N));
10713 end Is_Atomic_Object;
10715 -----------------------------
10716 -- Is_Atomic_Or_VFA_Object --
10717 -----------------------------
10719 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
10721 return Is_Atomic_Object (N)
10722 or else (Is_Object_Reference (N)
10723 and then Is_Entity_Name (N)
10724 and then (Is_Volatile_Full_Access (Entity (N))
10726 Is_Volatile_Full_Access (Etype (Entity (N)))));
10727 end Is_Atomic_Or_VFA_Object;
10729 -------------------------
10730 -- Is_Attribute_Result --
10731 -------------------------
10733 function Is_Attribute_Result (N : Node_Id) return Boolean is
10735 return Nkind (N) = N_Attribute_Reference
10736 and then Attribute_Name (N) = Name_Result;
10737 end Is_Attribute_Result;
10739 -------------------------
10740 -- Is_Attribute_Update --
10741 -------------------------
10743 function Is_Attribute_Update (N : Node_Id) return Boolean is
10745 return Nkind (N) = N_Attribute_Reference
10746 and then Attribute_Name (N) = Name_Update;
10747 end Is_Attribute_Update;
10749 ------------------------------------
10750 -- Is_Body_Or_Package_Declaration --
10751 ------------------------------------
10753 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
10755 return Nkind_In (N, N_Entry_Body,
10757 N_Package_Declaration,
10761 end Is_Body_Or_Package_Declaration;
10763 -----------------------
10764 -- Is_Bounded_String --
10765 -----------------------
10767 function Is_Bounded_String (T : Entity_Id) return Boolean is
10768 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
10771 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10772 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10773 -- be True for all the Bounded_String types in instances of the
10774 -- Generic_Bounded_Length generics, and for types derived from those.
10776 return Present (Under)
10777 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
10778 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
10779 Is_RTE (Root_Type (Under), RO_WW_Super_String));
10780 end Is_Bounded_String;
10782 -------------------------
10783 -- Is_Child_Or_Sibling --
10784 -------------------------
10786 function Is_Child_Or_Sibling
10787 (Pack_1 : Entity_Id;
10788 Pack_2 : Entity_Id) return Boolean
10790 function Distance_From_Standard (Pack : Entity_Id) return Nat;
10791 -- Given an arbitrary package, return the number of "climbs" necessary
10792 -- to reach scope Standard_Standard.
10794 procedure Equalize_Depths
10795 (Pack : in out Entity_Id;
10796 Depth : in out Nat;
10797 Depth_To_Reach : Nat);
10798 -- Given an arbitrary package, its depth and a target depth to reach,
10799 -- climb the scope chain until the said depth is reached. The pointer
10800 -- to the package and its depth a modified during the climb.
10802 ----------------------------
10803 -- Distance_From_Standard --
10804 ----------------------------
10806 function Distance_From_Standard (Pack : Entity_Id) return Nat is
10813 while Present (Scop) and then Scop /= Standard_Standard loop
10815 Scop := Scope (Scop);
10819 end Distance_From_Standard;
10821 ---------------------
10822 -- Equalize_Depths --
10823 ---------------------
10825 procedure Equalize_Depths
10826 (Pack : in out Entity_Id;
10827 Depth : in out Nat;
10828 Depth_To_Reach : Nat)
10831 -- The package must be at a greater or equal depth
10833 if Depth < Depth_To_Reach then
10834 raise Program_Error;
10837 -- Climb the scope chain until the desired depth is reached
10839 while Present (Pack) and then Depth /= Depth_To_Reach loop
10840 Pack := Scope (Pack);
10841 Depth := Depth - 1;
10843 end Equalize_Depths;
10847 P_1 : Entity_Id := Pack_1;
10848 P_1_Child : Boolean := False;
10849 P_1_Depth : Nat := Distance_From_Standard (P_1);
10850 P_2 : Entity_Id := Pack_2;
10851 P_2_Child : Boolean := False;
10852 P_2_Depth : Nat := Distance_From_Standard (P_2);
10854 -- Start of processing for Is_Child_Or_Sibling
10858 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10860 -- Both packages denote the same entity, therefore they cannot be
10861 -- children or siblings.
10866 -- One of the packages is at a deeper level than the other. Note that
10867 -- both may still come from differen hierarchies.
10875 elsif P_1_Depth > P_2_Depth then
10878 Depth => P_1_Depth,
10879 Depth_To_Reach => P_2_Depth);
10888 elsif P_2_Depth > P_1_Depth then
10891 Depth => P_2_Depth,
10892 Depth_To_Reach => P_1_Depth);
10896 -- At this stage the package pointers have been elevated to the same
10897 -- depth. If the related entities are the same, then one package is a
10898 -- potential child of the other:
10902 -- X became P_1 P_2 or vica versa
10908 return Is_Child_Unit (Pack_1);
10910 else pragma Assert (P_2_Child);
10911 return Is_Child_Unit (Pack_2);
10914 -- The packages may come from the same package chain or from entirely
10915 -- different hierarcies. To determine this, climb the scope stack until
10916 -- a common root is found.
10918 -- (root) (root 1) (root 2)
10923 while Present (P_1) and then Present (P_2) loop
10925 -- The two packages may be siblings
10928 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10931 P_1 := Scope (P_1);
10932 P_2 := Scope (P_2);
10937 end Is_Child_Or_Sibling;
10939 -----------------------------
10940 -- Is_Concurrent_Interface --
10941 -----------------------------
10943 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10945 return Is_Interface (T)
10947 (Is_Protected_Interface (T)
10948 or else Is_Synchronized_Interface (T)
10949 or else Is_Task_Interface (T));
10950 end Is_Concurrent_Interface;
10952 -----------------------
10953 -- Is_Constant_Bound --
10954 -----------------------
10956 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10958 if Compile_Time_Known_Value (Exp) then
10961 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10962 return Is_Constant_Object (Entity (Exp))
10963 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10965 elsif Nkind (Exp) in N_Binary_Op then
10966 return Is_Constant_Bound (Left_Opnd (Exp))
10967 and then Is_Constant_Bound (Right_Opnd (Exp))
10968 and then Scope (Entity (Exp)) = Standard_Standard;
10973 end Is_Constant_Bound;
10975 ---------------------------
10976 -- Is_Container_Element --
10977 ---------------------------
10979 function Is_Container_Element (Exp : Node_Id) return Boolean is
10980 Loc : constant Source_Ptr := Sloc (Exp);
10981 Pref : constant Node_Id := Prefix (Exp);
10984 -- Call to an indexing aspect
10986 Cont_Typ : Entity_Id;
10987 -- The type of the container being accessed
10989 Elem_Typ : Entity_Id;
10990 -- Its element type
10992 Indexing : Entity_Id;
10993 Is_Const : Boolean;
10994 -- Indicates that constant indexing is used, and the element is thus
10997 Ref_Typ : Entity_Id;
10998 -- The reference type returned by the indexing operation
11001 -- If C is a container, in a context that imposes the element type of
11002 -- that container, the indexing notation C (X) is rewritten as:
11004 -- Indexing (C, X).Discr.all
11006 -- where Indexing is one of the indexing aspects of the container.
11007 -- If the context does not require a reference, the construct can be
11012 -- First, verify that the construct has the proper form
11014 if not Expander_Active then
11017 elsif Nkind (Pref) /= N_Selected_Component then
11020 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11024 Call := Prefix (Pref);
11025 Ref_Typ := Etype (Call);
11028 if not Has_Implicit_Dereference (Ref_Typ)
11029 or else No (First (Parameter_Associations (Call)))
11030 or else not Is_Entity_Name (Name (Call))
11035 -- Retrieve type of container object, and its iterator aspects
11037 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11038 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11041 if No (Indexing) then
11043 -- Container should have at least one indexing operation
11047 elsif Entity (Name (Call)) /= Entity (Indexing) then
11049 -- This may be a variable indexing operation
11051 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11054 or else Entity (Name (Call)) /= Entity (Indexing)
11063 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
11065 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
11069 -- Check that the expression is not the target of an assignment, in
11070 -- which case the rewriting is not possible.
11072 if not Is_Const then
11078 while Present (Par)
11080 if Nkind (Parent (Par)) = N_Assignment_Statement
11081 and then Par = Name (Parent (Par))
11085 -- A renaming produces a reference, and the transformation
11088 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
11092 (Nkind (Parent (Par)), N_Function_Call,
11093 N_Procedure_Call_Statement,
11094 N_Entry_Call_Statement)
11096 -- Check that the element is not part of an actual for an
11097 -- in-out parameter.
11104 F := First_Formal (Entity (Name (Parent (Par))));
11105 A := First (Parameter_Associations (Parent (Par)));
11106 while Present (F) loop
11107 if A = Par and then Ekind (F) /= E_In_Parameter then
11116 -- E_In_Parameter in a call: element is not modified.
11121 Par := Parent (Par);
11126 -- The expression has the proper form and the context requires the
11127 -- element type. Retrieve the Element function of the container and
11128 -- rewrite the construct as a call to it.
11134 Op := First_Elmt (Primitive_Operations (Cont_Typ));
11135 while Present (Op) loop
11136 exit when Chars (Node (Op)) = Name_Element;
11145 Make_Function_Call (Loc,
11146 Name => New_Occurrence_Of (Node (Op), Loc),
11147 Parameter_Associations => Parameter_Associations (Call)));
11148 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
11152 end Is_Container_Element;
11154 ----------------------------
11155 -- Is_Contract_Annotation --
11156 ----------------------------
11158 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
11160 return Is_Package_Contract_Annotation (Item)
11162 Is_Subprogram_Contract_Annotation (Item);
11163 end Is_Contract_Annotation;
11165 --------------------------------------
11166 -- Is_Controlling_Limited_Procedure --
11167 --------------------------------------
11169 function Is_Controlling_Limited_Procedure
11170 (Proc_Nam : Entity_Id) return Boolean
11172 Param_Typ : Entity_Id := Empty;
11175 if Ekind (Proc_Nam) = E_Procedure
11176 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
11178 Param_Typ := Etype (Parameter_Type (First (
11179 Parameter_Specifications (Parent (Proc_Nam)))));
11181 -- In this case where an Itype was created, the procedure call has been
11184 elsif Present (Associated_Node_For_Itype (Proc_Nam))
11185 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
11187 Present (Parameter_Associations
11188 (Associated_Node_For_Itype (Proc_Nam)))
11191 Etype (First (Parameter_Associations
11192 (Associated_Node_For_Itype (Proc_Nam))));
11195 if Present (Param_Typ) then
11197 Is_Interface (Param_Typ)
11198 and then Is_Limited_Record (Param_Typ);
11202 end Is_Controlling_Limited_Procedure;
11204 -----------------------------
11205 -- Is_CPP_Constructor_Call --
11206 -----------------------------
11208 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
11210 return Nkind (N) = N_Function_Call
11211 and then Is_CPP_Class (Etype (Etype (N)))
11212 and then Is_Constructor (Entity (Name (N)))
11213 and then Is_Imported (Entity (Name (N)));
11214 end Is_CPP_Constructor_Call;
11216 -------------------------
11217 -- Is_Current_Instance --
11218 -------------------------
11220 function Is_Current_Instance (N : Node_Id) return Boolean is
11221 Typ : constant Entity_Id := Entity (N);
11225 -- Simplest case: entity is a concurrent type and we are currently
11226 -- inside the body. This will eventually be expanded into a
11227 -- call to Self (for tasks) or _object (for protected objects).
11229 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
11233 -- Check whether the context is a (sub)type declaration for the
11237 while Present (P) loop
11238 if Nkind_In (P, N_Full_Type_Declaration,
11239 N_Private_Type_Declaration,
11240 N_Subtype_Declaration)
11241 and then Comes_From_Source (P)
11242 and then Defining_Entity (P) = Typ
11251 -- In any other context this is not a current occurrence
11254 end Is_Current_Instance;
11256 --------------------
11257 -- Is_Declaration --
11258 --------------------
11260 function Is_Declaration (N : Node_Id) return Boolean is
11263 when N_Abstract_Subprogram_Declaration |
11264 N_Exception_Declaration |
11265 N_Exception_Renaming_Declaration |
11266 N_Full_Type_Declaration |
11267 N_Generic_Function_Renaming_Declaration |
11268 N_Generic_Package_Declaration |
11269 N_Generic_Package_Renaming_Declaration |
11270 N_Generic_Procedure_Renaming_Declaration |
11271 N_Generic_Subprogram_Declaration |
11272 N_Number_Declaration |
11273 N_Object_Declaration |
11274 N_Object_Renaming_Declaration |
11275 N_Package_Declaration |
11276 N_Package_Renaming_Declaration |
11277 N_Private_Extension_Declaration |
11278 N_Private_Type_Declaration |
11279 N_Subprogram_Declaration |
11280 N_Subprogram_Renaming_Declaration |
11281 N_Subtype_Declaration =>
11287 end Is_Declaration;
11289 --------------------------------
11290 -- Is_Declared_Within_Variant --
11291 --------------------------------
11293 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
11294 Comp_Decl : constant Node_Id := Parent (Comp);
11295 Comp_List : constant Node_Id := Parent (Comp_Decl);
11297 return Nkind (Parent (Comp_List)) = N_Variant;
11298 end Is_Declared_Within_Variant;
11300 ----------------------------------------------
11301 -- Is_Dependent_Component_Of_Mutable_Object --
11302 ----------------------------------------------
11304 function Is_Dependent_Component_Of_Mutable_Object
11305 (Object : Node_Id) return Boolean
11308 Prefix_Type : Entity_Id;
11309 P_Aliased : Boolean := False;
11312 Deref : Node_Id := Object;
11313 -- Dereference node, in something like X.all.Y(2)
11315 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11318 -- Find the dereference node if any
11320 while Nkind_In (Deref, N_Indexed_Component,
11321 N_Selected_Component,
11324 Deref := Prefix (Deref);
11327 -- Ada 2005: If we have a component or slice of a dereference,
11328 -- something like X.all.Y (2), and the type of X is access-to-constant,
11329 -- Is_Variable will return False, because it is indeed a constant
11330 -- view. But it might be a view of a variable object, so we want the
11331 -- following condition to be True in that case.
11333 if Is_Variable (Object)
11334 or else (Ada_Version >= Ada_2005
11335 and then Nkind (Deref) = N_Explicit_Dereference)
11337 if Nkind (Object) = N_Selected_Component then
11338 P := Prefix (Object);
11339 Prefix_Type := Etype (P);
11341 if Is_Entity_Name (P) then
11342 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
11343 Prefix_Type := Base_Type (Prefix_Type);
11346 if Is_Aliased (Entity (P)) then
11350 -- A discriminant check on a selected component may be expanded
11351 -- into a dereference when removing side-effects. Recover the
11352 -- original node and its type, which may be unconstrained.
11354 elsif Nkind (P) = N_Explicit_Dereference
11355 and then not (Comes_From_Source (P))
11357 P := Original_Node (P);
11358 Prefix_Type := Etype (P);
11361 -- Check for prefix being an aliased component???
11367 -- A heap object is constrained by its initial value
11369 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11370 -- the dereferenced case, since the access value might denote an
11371 -- unconstrained aliased object, whereas in Ada 95 the designated
11372 -- object is guaranteed to be constrained. A worst-case assumption
11373 -- has to apply in Ada 2005 because we can't tell at compile
11374 -- time whether the object is "constrained by its initial value"
11375 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11376 -- rules (these rules are acknowledged to need fixing).
11378 if Ada_Version < Ada_2005 then
11379 if Is_Access_Type (Prefix_Type)
11380 or else Nkind (P) = N_Explicit_Dereference
11385 else pragma Assert (Ada_Version >= Ada_2005);
11386 if Is_Access_Type (Prefix_Type) then
11388 -- If the access type is pool-specific, and there is no
11389 -- constrained partial view of the designated type, then the
11390 -- designated object is known to be constrained.
11392 if Ekind (Prefix_Type) = E_Access_Type
11393 and then not Object_Type_Has_Constrained_Partial_View
11394 (Typ => Designated_Type (Prefix_Type),
11395 Scop => Current_Scope)
11399 -- Otherwise (general access type, or there is a constrained
11400 -- partial view of the designated type), we need to check
11401 -- based on the designated type.
11404 Prefix_Type := Designated_Type (Prefix_Type);
11410 Original_Record_Component (Entity (Selector_Name (Object)));
11412 -- As per AI-0017, the renaming is illegal in a generic body, even
11413 -- if the subtype is indefinite.
11415 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11417 if not Is_Constrained (Prefix_Type)
11418 and then (Is_Definite_Subtype (Prefix_Type)
11420 (Is_Generic_Type (Prefix_Type)
11421 and then Ekind (Current_Scope) = E_Generic_Package
11422 and then In_Package_Body (Current_Scope)))
11424 and then (Is_Declared_Within_Variant (Comp)
11425 or else Has_Discriminant_Dependent_Constraint (Comp))
11426 and then (not P_Aliased or else Ada_Version >= Ada_2005)
11430 -- If the prefix is of an access type at this point, then we want
11431 -- to return False, rather than calling this function recursively
11432 -- on the access object (which itself might be a discriminant-
11433 -- dependent component of some other object, but that isn't
11434 -- relevant to checking the object passed to us). This avoids
11435 -- issuing wrong errors when compiling with -gnatc, where there
11436 -- can be implicit dereferences that have not been expanded.
11438 elsif Is_Access_Type (Etype (Prefix (Object))) then
11443 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11446 elsif Nkind (Object) = N_Indexed_Component
11447 or else Nkind (Object) = N_Slice
11449 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11451 -- A type conversion that Is_Variable is a view conversion:
11452 -- go back to the denoted object.
11454 elsif Nkind (Object) = N_Type_Conversion then
11456 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
11461 end Is_Dependent_Component_Of_Mutable_Object;
11463 ---------------------
11464 -- Is_Dereferenced --
11465 ---------------------
11467 function Is_Dereferenced (N : Node_Id) return Boolean is
11468 P : constant Node_Id := Parent (N);
11470 return Nkind_In (P, N_Selected_Component,
11471 N_Explicit_Dereference,
11472 N_Indexed_Component,
11474 and then Prefix (P) = N;
11475 end Is_Dereferenced;
11477 ----------------------
11478 -- Is_Descendent_Of --
11479 ----------------------
11481 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11486 pragma Assert (Nkind (T1) in N_Entity);
11487 pragma Assert (Nkind (T2) in N_Entity);
11489 T := Base_Type (T1);
11491 -- Immediate return if the types match
11496 -- Comment needed here ???
11498 elsif Ekind (T) = E_Class_Wide_Type then
11499 return Etype (T) = T2;
11507 -- Done if we found the type we are looking for
11512 -- Done if no more derivations to check
11519 -- Following test catches error cases resulting from prev errors
11521 elsif No (Etyp) then
11524 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11527 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11531 T := Base_Type (Etyp);
11534 end Is_Descendent_Of;
11536 ----------------------------------------
11537 -- Is_Descendant_Of_Suspension_Object --
11538 ----------------------------------------
11540 function Is_Descendant_Of_Suspension_Object
11541 (Typ : Entity_Id) return Boolean
11543 Cur_Typ : Entity_Id;
11544 Par_Typ : Entity_Id;
11547 -- Climb the type derivation chain checking each parent type against
11548 -- Suspension_Object.
11550 Cur_Typ := Base_Type (Typ);
11551 while Present (Cur_Typ) loop
11552 Par_Typ := Etype (Cur_Typ);
11554 -- The current type is a match
11556 if Is_Suspension_Object (Cur_Typ) then
11559 -- Stop the traversal once the root of the derivation chain has been
11560 -- reached. In that case the current type is its own base type.
11562 elsif Cur_Typ = Par_Typ then
11566 Cur_Typ := Base_Type (Par_Typ);
11570 end Is_Descendant_Of_Suspension_Object;
11572 ---------------------------------------------
11573 -- Is_Double_Precision_Floating_Point_Type --
11574 ---------------------------------------------
11576 function Is_Double_Precision_Floating_Point_Type
11577 (E : Entity_Id) return Boolean is
11579 return Is_Floating_Point_Type (E)
11580 and then Machine_Radix_Value (E) = Uint_2
11581 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
11582 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
11583 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
11584 end Is_Double_Precision_Floating_Point_Type;
11586 -----------------------------
11587 -- Is_Effectively_Volatile --
11588 -----------------------------
11590 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11592 if Is_Type (Id) then
11594 -- An arbitrary type is effectively volatile when it is subject to
11595 -- pragma Atomic or Volatile.
11597 if Is_Volatile (Id) then
11600 -- An array type is effectively volatile when it is subject to pragma
11601 -- Atomic_Components or Volatile_Components or its compolent type is
11602 -- effectively volatile.
11604 elsif Is_Array_Type (Id) then
11606 Has_Volatile_Components (Id)
11608 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
11610 -- A protected type is always volatile
11612 elsif Is_Protected_Type (Id) then
11615 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
11616 -- automatically volatile.
11618 elsif Is_Descendant_Of_Suspension_Object (Id) then
11621 -- Otherwise the type is not effectively volatile
11627 -- Otherwise Id denotes an object
11632 or else Has_Volatile_Components (Id)
11633 or else Is_Effectively_Volatile (Etype (Id));
11635 end Is_Effectively_Volatile;
11637 ------------------------------------
11638 -- Is_Effectively_Volatile_Object --
11639 ------------------------------------
11641 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
11643 if Is_Entity_Name (N) then
11644 return Is_Effectively_Volatile (Entity (N));
11646 elsif Nkind (N) = N_Expanded_Name then
11647 return Is_Effectively_Volatile (Entity (N));
11649 elsif Nkind (N) = N_Indexed_Component then
11650 return Is_Effectively_Volatile_Object (Prefix (N));
11652 elsif Nkind (N) = N_Selected_Component then
11654 Is_Effectively_Volatile_Object (Prefix (N))
11656 Is_Effectively_Volatile_Object (Selector_Name (N));
11661 end Is_Effectively_Volatile_Object;
11663 -------------------
11664 -- Is_Entry_Body --
11665 -------------------
11667 function Is_Entry_Body (Id : Entity_Id) return Boolean is
11670 Ekind_In (Id, E_Entry, E_Entry_Family)
11671 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
11674 --------------------------
11675 -- Is_Entry_Declaration --
11676 --------------------------
11678 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
11681 Ekind_In (Id, E_Entry, E_Entry_Family)
11682 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
11683 end Is_Entry_Declaration;
11685 ----------------------------
11686 -- Is_Expression_Function --
11687 ----------------------------
11689 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
11691 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
11693 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
11694 N_Expression_Function;
11698 end Is_Expression_Function;
11700 ------------------------------------------
11701 -- Is_Expression_Function_Or_Completion --
11702 ------------------------------------------
11704 function Is_Expression_Function_Or_Completion
11705 (Subp : Entity_Id) return Boolean
11707 Subp_Decl : Node_Id;
11710 if Ekind (Subp) = E_Function then
11711 Subp_Decl := Unit_Declaration_Node (Subp);
11713 -- The function declaration is either an expression function or is
11714 -- completed by an expression function body.
11717 Is_Expression_Function (Subp)
11718 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
11719 and then Present (Corresponding_Body (Subp_Decl))
11720 and then Is_Expression_Function
11721 (Corresponding_Body (Subp_Decl)));
11723 elsif Ekind (Subp) = E_Subprogram_Body then
11724 return Is_Expression_Function (Subp);
11729 end Is_Expression_Function_Or_Completion;
11731 -----------------------
11732 -- Is_EVF_Expression --
11733 -----------------------
11735 function Is_EVF_Expression (N : Node_Id) return Boolean is
11736 Orig_N : constant Node_Id := Original_Node (N);
11742 -- Detect a reference to a formal parameter of a specific tagged type
11743 -- whose related subprogram is subject to pragma Expresions_Visible with
11746 if Is_Entity_Name (N) and then Present (Entity (N)) then
11751 and then Is_Specific_Tagged_Type (Etype (Id))
11752 and then Extensions_Visible_Status (Id) =
11753 Extensions_Visible_False;
11755 -- A case expression is an EVF expression when it contains at least one
11756 -- EVF dependent_expression. Note that a case expression may have been
11757 -- expanded, hence the use of Original_Node.
11759 elsif Nkind (Orig_N) = N_Case_Expression then
11760 Alt := First (Alternatives (Orig_N));
11761 while Present (Alt) loop
11762 if Is_EVF_Expression (Expression (Alt)) then
11769 -- An if expression is an EVF expression when it contains at least one
11770 -- EVF dependent_expression. Note that an if expression may have been
11771 -- expanded, hence the use of Original_Node.
11773 elsif Nkind (Orig_N) = N_If_Expression then
11774 Expr := Next (First (Expressions (Orig_N)));
11775 while Present (Expr) loop
11776 if Is_EVF_Expression (Expr) then
11783 -- A qualified expression or a type conversion is an EVF expression when
11784 -- its operand is an EVF expression.
11786 elsif Nkind_In (N, N_Qualified_Expression,
11787 N_Unchecked_Type_Conversion,
11790 return Is_EVF_Expression (Expression (N));
11792 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
11793 -- their prefix denotes an EVF expression.
11795 elsif Nkind (N) = N_Attribute_Reference
11796 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
11800 return Is_EVF_Expression (Prefix (N));
11804 end Is_EVF_Expression;
11810 function Is_False (U : Uint) return Boolean is
11815 ---------------------------
11816 -- Is_Fixed_Model_Number --
11817 ---------------------------
11819 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
11820 S : constant Ureal := Small_Value (T);
11821 M : Urealp.Save_Mark;
11825 R := (U = UR_Trunc (U / S) * S);
11826 Urealp.Release (M);
11828 end Is_Fixed_Model_Number;
11830 -------------------------------
11831 -- Is_Fully_Initialized_Type --
11832 -------------------------------
11834 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
11838 if Is_Scalar_Type (Typ) then
11840 -- A scalar type with an aspect Default_Value is fully initialized
11842 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11843 -- of a scalar type, but we don't take that into account here, since
11844 -- we don't want these to affect warnings.
11846 return Has_Default_Aspect (Typ);
11848 elsif Is_Access_Type (Typ) then
11851 elsif Is_Array_Type (Typ) then
11852 if Is_Fully_Initialized_Type (Component_Type (Typ))
11853 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
11858 -- An interesting case, if we have a constrained type one of whose
11859 -- bounds is known to be null, then there are no elements to be
11860 -- initialized, so all the elements are initialized.
11862 if Is_Constrained (Typ) then
11865 Indx_Typ : Entity_Id;
11866 Lbd, Hbd : Node_Id;
11869 Indx := First_Index (Typ);
11870 while Present (Indx) loop
11871 if Etype (Indx) = Any_Type then
11874 -- If index is a range, use directly
11876 elsif Nkind (Indx) = N_Range then
11877 Lbd := Low_Bound (Indx);
11878 Hbd := High_Bound (Indx);
11881 Indx_Typ := Etype (Indx);
11883 if Is_Private_Type (Indx_Typ) then
11884 Indx_Typ := Full_View (Indx_Typ);
11887 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
11890 Lbd := Type_Low_Bound (Indx_Typ);
11891 Hbd := Type_High_Bound (Indx_Typ);
11895 if Compile_Time_Known_Value (Lbd)
11897 Compile_Time_Known_Value (Hbd)
11899 if Expr_Value (Hbd) < Expr_Value (Lbd) then
11909 -- If no null indexes, then type is not fully initialized
11915 elsif Is_Record_Type (Typ) then
11916 if Has_Discriminants (Typ)
11918 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
11919 and then Is_Fully_Initialized_Variant (Typ)
11924 -- We consider bounded string types to be fully initialized, because
11925 -- otherwise we get false alarms when the Data component is not
11926 -- default-initialized.
11928 if Is_Bounded_String (Typ) then
11932 -- Controlled records are considered to be fully initialized if
11933 -- there is a user defined Initialize routine. This may not be
11934 -- entirely correct, but as the spec notes, we are guessing here
11935 -- what is best from the point of view of issuing warnings.
11937 if Is_Controlled (Typ) then
11939 Utyp : constant Entity_Id := Underlying_Type (Typ);
11942 if Present (Utyp) then
11944 Init : constant Entity_Id :=
11945 (Find_Optional_Prim_Op
11946 (Underlying_Type (Typ), Name_Initialize));
11950 and then Comes_From_Source (Init)
11952 Is_Predefined_File_Name
11953 (File_Name (Get_Source_File_Index (Sloc (Init))))
11957 elsif Has_Null_Extension (Typ)
11959 Is_Fully_Initialized_Type
11960 (Etype (Base_Type (Typ)))
11969 -- Otherwise see if all record components are initialized
11975 Ent := First_Entity (Typ);
11976 while Present (Ent) loop
11977 if Ekind (Ent) = E_Component
11978 and then (No (Parent (Ent))
11979 or else No (Expression (Parent (Ent))))
11980 and then not Is_Fully_Initialized_Type (Etype (Ent))
11982 -- Special VM case for tag components, which need to be
11983 -- defined in this case, but are never initialized as VMs
11984 -- are using other dispatching mechanisms. Ignore this
11985 -- uninitialized case. Note that this applies both to the
11986 -- uTag entry and the main vtable pointer (CPP_Class case).
11988 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11997 -- No uninitialized components, so type is fully initialized.
11998 -- Note that this catches the case of no components as well.
12002 elsif Is_Concurrent_Type (Typ) then
12005 elsif Is_Private_Type (Typ) then
12007 U : constant Entity_Id := Underlying_Type (Typ);
12013 return Is_Fully_Initialized_Type (U);
12020 end Is_Fully_Initialized_Type;
12022 ----------------------------------
12023 -- Is_Fully_Initialized_Variant --
12024 ----------------------------------
12026 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
12027 Loc : constant Source_Ptr := Sloc (Typ);
12028 Constraints : constant List_Id := New_List;
12029 Components : constant Elist_Id := New_Elmt_List;
12030 Comp_Elmt : Elmt_Id;
12032 Comp_List : Node_Id;
12034 Discr_Val : Node_Id;
12036 Report_Errors : Boolean;
12037 pragma Warnings (Off, Report_Errors);
12040 if Serious_Errors_Detected > 0 then
12044 if Is_Record_Type (Typ)
12045 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
12046 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
12048 Comp_List := Component_List (Type_Definition (Parent (Typ)));
12050 Discr := First_Discriminant (Typ);
12051 while Present (Discr) loop
12052 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
12053 Discr_Val := Expression (Parent (Discr));
12055 if Present (Discr_Val)
12056 and then Is_OK_Static_Expression (Discr_Val)
12058 Append_To (Constraints,
12059 Make_Component_Association (Loc,
12060 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
12061 Expression => New_Copy (Discr_Val)));
12069 Next_Discriminant (Discr);
12074 Comp_List => Comp_List,
12075 Governed_By => Constraints,
12076 Into => Components,
12077 Report_Errors => Report_Errors);
12079 -- Check that each component present is fully initialized
12081 Comp_Elmt := First_Elmt (Components);
12082 while Present (Comp_Elmt) loop
12083 Comp_Id := Node (Comp_Elmt);
12085 if Ekind (Comp_Id) = E_Component
12086 and then (No (Parent (Comp_Id))
12087 or else No (Expression (Parent (Comp_Id))))
12088 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
12093 Next_Elmt (Comp_Elmt);
12098 elsif Is_Private_Type (Typ) then
12100 U : constant Entity_Id := Underlying_Type (Typ);
12106 return Is_Fully_Initialized_Variant (U);
12113 end Is_Fully_Initialized_Variant;
12115 ------------------------------------
12116 -- Is_Generic_Declaration_Or_Body --
12117 ------------------------------------
12119 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
12120 Spec_Decl : Node_Id;
12123 -- Package/subprogram body
12125 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
12126 and then Present (Corresponding_Spec (Decl))
12128 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
12130 -- Package/subprogram body stub
12132 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
12133 and then Present (Corresponding_Spec_Of_Stub (Decl))
12136 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
12144 -- Rather than inspecting the defining entity of the spec declaration,
12145 -- look at its Nkind. This takes care of the case where the analysis of
12146 -- a generic body modifies the Ekind of its spec to allow for recursive
12150 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
12151 N_Generic_Subprogram_Declaration);
12152 end Is_Generic_Declaration_Or_Body;
12154 ----------------------------
12155 -- Is_Inherited_Operation --
12156 ----------------------------
12158 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
12159 pragma Assert (Is_Overloadable (E));
12160 Kind : constant Node_Kind := Nkind (Parent (E));
12162 return Kind = N_Full_Type_Declaration
12163 or else Kind = N_Private_Extension_Declaration
12164 or else Kind = N_Subtype_Declaration
12165 or else (Ekind (E) = E_Enumeration_Literal
12166 and then Is_Derived_Type (Etype (E)));
12167 end Is_Inherited_Operation;
12169 -------------------------------------
12170 -- Is_Inherited_Operation_For_Type --
12171 -------------------------------------
12173 function Is_Inherited_Operation_For_Type
12175 Typ : Entity_Id) return Boolean
12178 -- Check that the operation has been created by the type declaration
12180 return Is_Inherited_Operation (E)
12181 and then Defining_Identifier (Parent (E)) = Typ;
12182 end Is_Inherited_Operation_For_Type;
12188 function Is_Iterator (Typ : Entity_Id) return Boolean is
12189 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
12190 -- Determine whether type Iter_Typ is a predefined forward or reversible
12193 ----------------------
12194 -- Denotes_Iterator --
12195 ----------------------
12197 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
12200 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
12201 Name_Reversible_Iterator)
12202 and then Is_Predefined_File_Name
12203 (Unit_File_Name (Get_Source_Unit (Iter_Typ)));
12204 end Denotes_Iterator;
12208 Iface_Elmt : Elmt_Id;
12211 -- Start of processing for Is_Iterator
12214 -- The type may be a subtype of a descendant of the proper instance of
12215 -- the predefined interface type, so we must use the root type of the
12216 -- given type. The same is done for Is_Reversible_Iterator.
12218 if Is_Class_Wide_Type (Typ)
12219 and then Denotes_Iterator (Root_Type (Typ))
12223 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12226 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
12230 Collect_Interfaces (Typ, Ifaces);
12232 Iface_Elmt := First_Elmt (Ifaces);
12233 while Present (Iface_Elmt) loop
12234 if Denotes_Iterator (Node (Iface_Elmt)) then
12238 Next_Elmt (Iface_Elmt);
12245 ----------------------------
12246 -- Is_Iterator_Over_Array --
12247 ----------------------------
12249 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
12250 Container : constant Node_Id := Name (N);
12251 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
12253 return Is_Array_Type (Container_Typ);
12254 end Is_Iterator_Over_Array;
12260 -- We seem to have a lot of overlapping functions that do similar things
12261 -- (testing for left hand sides or lvalues???).
12263 function Is_LHS (N : Node_Id) return Is_LHS_Result is
12264 P : constant Node_Id := Parent (N);
12267 -- Return True if we are the left hand side of an assignment statement
12269 if Nkind (P) = N_Assignment_Statement then
12270 if Name (P) = N then
12276 -- Case of prefix of indexed or selected component or slice
12278 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
12279 and then N = Prefix (P)
12281 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12282 -- If P is an LHS, then N is also effectively an LHS, but there
12283 -- is an important exception. If N is of an access type, then
12284 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12285 -- case this makes N.all a left hand side but not N itself.
12287 -- If we don't know the type yet, this is the case where we return
12288 -- Unknown, since the answer depends on the type which is unknown.
12290 if No (Etype (N)) then
12293 -- We have an Etype set, so we can check it
12295 elsif Is_Access_Type (Etype (N)) then
12298 -- OK, not access type case, so just test whole expression
12304 -- All other cases are not left hand sides
12311 -----------------------------
12312 -- Is_Library_Level_Entity --
12313 -----------------------------
12315 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
12317 -- The following is a small optimization, and it also properly handles
12318 -- discriminals, which in task bodies might appear in expressions before
12319 -- the corresponding procedure has been created, and which therefore do
12320 -- not have an assigned scope.
12322 if Is_Formal (E) then
12326 -- Normal test is simply that the enclosing dynamic scope is Standard
12328 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
12329 end Is_Library_Level_Entity;
12331 --------------------------------
12332 -- Is_Limited_Class_Wide_Type --
12333 --------------------------------
12335 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
12338 Is_Class_Wide_Type (Typ)
12339 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
12340 end Is_Limited_Class_Wide_Type;
12342 ---------------------------------
12343 -- Is_Local_Variable_Reference --
12344 ---------------------------------
12346 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
12348 if not Is_Entity_Name (Expr) then
12353 Ent : constant Entity_Id := Entity (Expr);
12354 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
12356 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
12359 return Present (Sub) and then Sub = Current_Subprogram;
12363 end Is_Local_Variable_Reference;
12365 -------------------------
12366 -- Is_Object_Reference --
12367 -------------------------
12369 function Is_Object_Reference (N : Node_Id) return Boolean is
12371 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
12372 -- Determine whether N is the name of an internally-generated renaming
12374 --------------------------------------
12375 -- Is_Internally_Generated_Renaming --
12376 --------------------------------------
12378 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
12383 while Present (P) loop
12384 if Nkind (P) = N_Object_Renaming_Declaration then
12385 return not Comes_From_Source (P);
12386 elsif Is_List_Member (P) then
12394 end Is_Internally_Generated_Renaming;
12396 -- Start of processing for Is_Object_Reference
12399 if Is_Entity_Name (N) then
12400 return Present (Entity (N)) and then Is_Object (Entity (N));
12404 when N_Indexed_Component | N_Slice =>
12406 Is_Object_Reference (Prefix (N))
12407 or else Is_Access_Type (Etype (Prefix (N)));
12409 -- In Ada 95, a function call is a constant object; a procedure
12412 when N_Function_Call =>
12413 return Etype (N) /= Standard_Void_Type;
12415 -- Attributes 'Input, 'Loop_Entry, 'Old and 'Result produce
12418 when N_Attribute_Reference =>
12420 Nam_In (Attribute_Name (N), Name_Input,
12425 when N_Selected_Component =>
12427 Is_Object_Reference (Selector_Name (N))
12429 (Is_Object_Reference (Prefix (N))
12430 or else Is_Access_Type (Etype (Prefix (N))));
12432 when N_Explicit_Dereference =>
12435 -- A view conversion of a tagged object is an object reference
12437 when N_Type_Conversion =>
12438 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
12439 and then Is_Tagged_Type (Etype (Expression (N)))
12440 and then Is_Object_Reference (Expression (N));
12442 -- An unchecked type conversion is considered to be an object if
12443 -- the operand is an object (this construction arises only as a
12444 -- result of expansion activities).
12446 when N_Unchecked_Type_Conversion =>
12449 -- Allow string literals to act as objects as long as they appear
12450 -- in internally-generated renamings. The expansion of iterators
12451 -- may generate such renamings when the range involves a string
12454 when N_String_Literal =>
12455 return Is_Internally_Generated_Renaming (Parent (N));
12457 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12458 -- This allows disambiguation of function calls and the use
12459 -- of aggregates in more contexts.
12461 when N_Qualified_Expression =>
12462 if Ada_Version < Ada_2012 then
12465 return Is_Object_Reference (Expression (N))
12466 or else Nkind (Expression (N)) = N_Aggregate;
12473 end Is_Object_Reference;
12475 -----------------------------------
12476 -- Is_OK_Variable_For_Out_Formal --
12477 -----------------------------------
12479 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
12481 Note_Possible_Modification (AV, Sure => True);
12483 -- We must reject parenthesized variable names. Comes_From_Source is
12484 -- checked because there are currently cases where the compiler violates
12485 -- this rule (e.g. passing a task object to its controlled Initialize
12486 -- routine). This should be properly documented in sinfo???
12488 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
12491 -- A variable is always allowed
12493 elsif Is_Variable (AV) then
12496 -- Generalized indexing operations are rewritten as explicit
12497 -- dereferences, and it is only during resolution that we can
12498 -- check whether the context requires an access_to_variable type.
12500 elsif Nkind (AV) = N_Explicit_Dereference
12501 and then Ada_Version >= Ada_2012
12502 and then Nkind (Original_Node (AV)) = N_Indexed_Component
12503 and then Present (Etype (Original_Node (AV)))
12504 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
12506 return not Is_Access_Constant (Etype (Prefix (AV)));
12508 -- Unchecked conversions are allowed only if they come from the
12509 -- generated code, which sometimes uses unchecked conversions for out
12510 -- parameters in cases where code generation is unaffected. We tell
12511 -- source unchecked conversions by seeing if they are rewrites of
12512 -- an original Unchecked_Conversion function call, or of an explicit
12513 -- conversion of a function call or an aggregate (as may happen in the
12514 -- expansion of a packed array aggregate).
12516 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
12517 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
12520 elsif Comes_From_Source (AV)
12521 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
12525 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
12526 return Is_OK_Variable_For_Out_Formal (Expression (AV));
12532 -- Normal type conversions are allowed if argument is a variable
12534 elsif Nkind (AV) = N_Type_Conversion then
12535 if Is_Variable (Expression (AV))
12536 and then Paren_Count (Expression (AV)) = 0
12538 Note_Possible_Modification (Expression (AV), Sure => True);
12541 -- We also allow a non-parenthesized expression that raises
12542 -- constraint error if it rewrites what used to be a variable
12544 elsif Raises_Constraint_Error (Expression (AV))
12545 and then Paren_Count (Expression (AV)) = 0
12546 and then Is_Variable (Original_Node (Expression (AV)))
12550 -- Type conversion of something other than a variable
12556 -- If this node is rewritten, then test the original form, if that is
12557 -- OK, then we consider the rewritten node OK (for example, if the
12558 -- original node is a conversion, then Is_Variable will not be true
12559 -- but we still want to allow the conversion if it converts a variable).
12561 elsif Original_Node (AV) /= AV then
12563 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12564 -- Reference function.
12566 if Ada_Version >= Ada_2012
12567 and then Nkind (Original_Node (AV)) = N_Function_Call
12569 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
12572 -- Check that this is not a constant reference.
12574 return not Is_Access_Constant (Etype (Prefix (AV)));
12576 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
12578 not Is_Access_Constant (Etype
12579 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
12582 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
12585 -- All other non-variables are rejected
12590 end Is_OK_Variable_For_Out_Formal;
12592 ------------------------------------
12593 -- Is_Package_Contract_Annotation --
12594 ------------------------------------
12596 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
12600 if Nkind (Item) = N_Aspect_Specification then
12601 Nam := Chars (Identifier (Item));
12603 else pragma Assert (Nkind (Item) = N_Pragma);
12604 Nam := Pragma_Name (Item);
12607 return Nam = Name_Abstract_State
12608 or else Nam = Name_Initial_Condition
12609 or else Nam = Name_Initializes
12610 or else Nam = Name_Refined_State;
12611 end Is_Package_Contract_Annotation;
12613 -----------------------------------
12614 -- Is_Partially_Initialized_Type --
12615 -----------------------------------
12617 function Is_Partially_Initialized_Type
12619 Include_Implicit : Boolean := True) return Boolean
12622 if Is_Scalar_Type (Typ) then
12625 elsif Is_Access_Type (Typ) then
12626 return Include_Implicit;
12628 elsif Is_Array_Type (Typ) then
12630 -- If component type is partially initialized, so is array type
12632 if Is_Partially_Initialized_Type
12633 (Component_Type (Typ), Include_Implicit)
12637 -- Otherwise we are only partially initialized if we are fully
12638 -- initialized (this is the empty array case, no point in us
12639 -- duplicating that code here).
12642 return Is_Fully_Initialized_Type (Typ);
12645 elsif Is_Record_Type (Typ) then
12647 -- A discriminated type is always partially initialized if in
12650 if Has_Discriminants (Typ) and then Include_Implicit then
12653 -- A tagged type is always partially initialized
12655 elsif Is_Tagged_Type (Typ) then
12658 -- Case of non-discriminated record
12664 Component_Present : Boolean := False;
12665 -- Set True if at least one component is present. If no
12666 -- components are present, then record type is fully
12667 -- initialized (another odd case, like the null array).
12670 -- Loop through components
12672 Ent := First_Entity (Typ);
12673 while Present (Ent) loop
12674 if Ekind (Ent) = E_Component then
12675 Component_Present := True;
12677 -- If a component has an initialization expression then
12678 -- the enclosing record type is partially initialized
12680 if Present (Parent (Ent))
12681 and then Present (Expression (Parent (Ent)))
12685 -- If a component is of a type which is itself partially
12686 -- initialized, then the enclosing record type is also.
12688 elsif Is_Partially_Initialized_Type
12689 (Etype (Ent), Include_Implicit)
12698 -- No initialized components found. If we found any components
12699 -- they were all uninitialized so the result is false.
12701 if Component_Present then
12704 -- But if we found no components, then all the components are
12705 -- initialized so we consider the type to be initialized.
12713 -- Concurrent types are always fully initialized
12715 elsif Is_Concurrent_Type (Typ) then
12718 -- For a private type, go to underlying type. If there is no underlying
12719 -- type then just assume this partially initialized. Not clear if this
12720 -- can happen in a non-error case, but no harm in testing for this.
12722 elsif Is_Private_Type (Typ) then
12724 U : constant Entity_Id := Underlying_Type (Typ);
12729 return Is_Partially_Initialized_Type (U, Include_Implicit);
12733 -- For any other type (are there any?) assume partially initialized
12738 end Is_Partially_Initialized_Type;
12740 ------------------------------------
12741 -- Is_Potentially_Persistent_Type --
12742 ------------------------------------
12744 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
12749 -- For private type, test corresponding full type
12751 if Is_Private_Type (T) then
12752 return Is_Potentially_Persistent_Type (Full_View (T));
12754 -- Scalar types are potentially persistent
12756 elsif Is_Scalar_Type (T) then
12759 -- Record type is potentially persistent if not tagged and the types of
12760 -- all it components are potentially persistent, and no component has
12761 -- an initialization expression.
12763 elsif Is_Record_Type (T)
12764 and then not Is_Tagged_Type (T)
12765 and then not Is_Partially_Initialized_Type (T)
12767 Comp := First_Component (T);
12768 while Present (Comp) loop
12769 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
12772 Next_Entity (Comp);
12778 -- Array type is potentially persistent if its component type is
12779 -- potentially persistent and if all its constraints are static.
12781 elsif Is_Array_Type (T) then
12782 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
12786 Indx := First_Index (T);
12787 while Present (Indx) loop
12788 if not Is_OK_Static_Subtype (Etype (Indx)) then
12797 -- All other types are not potentially persistent
12802 end Is_Potentially_Persistent_Type;
12804 --------------------------------
12805 -- Is_Potentially_Unevaluated --
12806 --------------------------------
12808 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
12816 -- A postcondition whose expression is a short-circuit is broken down
12817 -- into individual aspects for better exception reporting. The original
12818 -- short-circuit expression is rewritten as the second operand, and an
12819 -- occurrence of 'Old in that operand is potentially unevaluated.
12820 -- See Sem_ch13.adb for details of this transformation.
12822 if Nkind (Original_Node (Par)) = N_And_Then then
12826 while not Nkind_In (Par, N_If_Expression,
12834 Par := Parent (Par);
12836 -- If the context is not an expression, or if is the result of
12837 -- expansion of an enclosing construct (such as another attribute)
12838 -- the predicate does not apply.
12840 if Nkind (Par) not in N_Subexpr
12841 or else not Comes_From_Source (Par)
12847 if Nkind (Par) = N_If_Expression then
12848 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
12850 elsif Nkind (Par) = N_Case_Expression then
12851 return Expr /= Expression (Par);
12853 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
12854 return Expr = Right_Opnd (Par);
12856 elsif Nkind_In (Par, N_In, N_Not_In) then
12857 return Expr /= Left_Opnd (Par);
12862 end Is_Potentially_Unevaluated;
12864 ---------------------------------
12865 -- Is_Protected_Self_Reference --
12866 ---------------------------------
12868 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
12870 function In_Access_Definition (N : Node_Id) return Boolean;
12871 -- Returns true if N belongs to an access definition
12873 --------------------------
12874 -- In_Access_Definition --
12875 --------------------------
12877 function In_Access_Definition (N : Node_Id) return Boolean is
12882 while Present (P) loop
12883 if Nkind (P) = N_Access_Definition then
12891 end In_Access_Definition;
12893 -- Start of processing for Is_Protected_Self_Reference
12896 -- Verify that prefix is analyzed and has the proper form. Note that
12897 -- the attributes Elab_Spec, Elab_Body and Elab_Subp_Body which also
12898 -- produce the address of an entity, do not analyze their prefix
12899 -- because they denote entities that are not necessarily visible.
12900 -- Neither of them can apply to a protected type.
12902 return Ada_Version >= Ada_2005
12903 and then Is_Entity_Name (N)
12904 and then Present (Entity (N))
12905 and then Is_Protected_Type (Entity (N))
12906 and then In_Open_Scopes (Entity (N))
12907 and then not In_Access_Definition (N);
12908 end Is_Protected_Self_Reference;
12910 -----------------------------
12911 -- Is_RCI_Pkg_Spec_Or_Body --
12912 -----------------------------
12914 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
12916 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
12917 -- Return True if the unit of Cunit is an RCI package declaration
12919 ---------------------------
12920 -- Is_RCI_Pkg_Decl_Cunit --
12921 ---------------------------
12923 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
12924 The_Unit : constant Node_Id := Unit (Cunit);
12927 if Nkind (The_Unit) /= N_Package_Declaration then
12931 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
12932 end Is_RCI_Pkg_Decl_Cunit;
12934 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12937 return Is_RCI_Pkg_Decl_Cunit (Cunit)
12939 (Nkind (Unit (Cunit)) = N_Package_Body
12940 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
12941 end Is_RCI_Pkg_Spec_Or_Body;
12943 -----------------------------------------
12944 -- Is_Remote_Access_To_Class_Wide_Type --
12945 -----------------------------------------
12947 function Is_Remote_Access_To_Class_Wide_Type
12948 (E : Entity_Id) return Boolean
12951 -- A remote access to class-wide type is a general access to object type
12952 -- declared in the visible part of a Remote_Types or Remote_Call_
12955 return Ekind (E) = E_General_Access_Type
12956 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12957 end Is_Remote_Access_To_Class_Wide_Type;
12959 -----------------------------------------
12960 -- Is_Remote_Access_To_Subprogram_Type --
12961 -----------------------------------------
12963 function Is_Remote_Access_To_Subprogram_Type
12964 (E : Entity_Id) return Boolean
12967 return (Ekind (E) = E_Access_Subprogram_Type
12968 or else (Ekind (E) = E_Record_Type
12969 and then Present (Corresponding_Remote_Type (E))))
12970 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12971 end Is_Remote_Access_To_Subprogram_Type;
12973 --------------------
12974 -- Is_Remote_Call --
12975 --------------------
12977 function Is_Remote_Call (N : Node_Id) return Boolean is
12979 if Nkind (N) not in N_Subprogram_Call then
12981 -- An entry call cannot be remote
12985 elsif Nkind (Name (N)) in N_Has_Entity
12986 and then Is_Remote_Call_Interface (Entity (Name (N)))
12988 -- A subprogram declared in the spec of a RCI package is remote
12992 elsif Nkind (Name (N)) = N_Explicit_Dereference
12993 and then Is_Remote_Access_To_Subprogram_Type
12994 (Etype (Prefix (Name (N))))
12996 -- The dereference of a RAS is a remote call
13000 elsif Present (Controlling_Argument (N))
13001 and then Is_Remote_Access_To_Class_Wide_Type
13002 (Etype (Controlling_Argument (N)))
13004 -- Any primitive operation call with a controlling argument of
13005 -- a RACW type is a remote call.
13010 -- All other calls are local calls
13013 end Is_Remote_Call;
13015 ----------------------
13016 -- Is_Renamed_Entry --
13017 ----------------------
13019 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
13020 Orig_Node : Node_Id := Empty;
13021 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
13023 function Is_Entry (Nam : Node_Id) return Boolean;
13024 -- Determine whether Nam is an entry. Traverse selectors if there are
13025 -- nested selected components.
13031 function Is_Entry (Nam : Node_Id) return Boolean is
13033 if Nkind (Nam) = N_Selected_Component then
13034 return Is_Entry (Selector_Name (Nam));
13037 return Ekind (Entity (Nam)) = E_Entry;
13040 -- Start of processing for Is_Renamed_Entry
13043 if Present (Alias (Proc_Nam)) then
13044 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
13047 -- Look for a rewritten subprogram renaming declaration
13049 if Nkind (Subp_Decl) = N_Subprogram_Declaration
13050 and then Present (Original_Node (Subp_Decl))
13052 Orig_Node := Original_Node (Subp_Decl);
13055 -- The rewritten subprogram is actually an entry
13057 if Present (Orig_Node)
13058 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
13059 and then Is_Entry (Name (Orig_Node))
13065 end Is_Renamed_Entry;
13067 -----------------------------
13068 -- Is_Renaming_Declaration --
13069 -----------------------------
13071 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
13074 when N_Exception_Renaming_Declaration |
13075 N_Generic_Function_Renaming_Declaration |
13076 N_Generic_Package_Renaming_Declaration |
13077 N_Generic_Procedure_Renaming_Declaration |
13078 N_Object_Renaming_Declaration |
13079 N_Package_Renaming_Declaration |
13080 N_Subprogram_Renaming_Declaration =>
13086 end Is_Renaming_Declaration;
13088 ----------------------------
13089 -- Is_Reversible_Iterator --
13090 ----------------------------
13092 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
13093 Ifaces_List : Elist_Id;
13094 Iface_Elmt : Elmt_Id;
13098 if Is_Class_Wide_Type (Typ)
13099 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
13100 and then Is_Predefined_File_Name
13101 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
13105 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13109 Collect_Interfaces (Typ, Ifaces_List);
13111 Iface_Elmt := First_Elmt (Ifaces_List);
13112 while Present (Iface_Elmt) loop
13113 Iface := Node (Iface_Elmt);
13114 if Chars (Iface) = Name_Reversible_Iterator
13116 Is_Predefined_File_Name
13117 (Unit_File_Name (Get_Source_Unit (Iface)))
13122 Next_Elmt (Iface_Elmt);
13127 end Is_Reversible_Iterator;
13129 ----------------------
13130 -- Is_Selector_Name --
13131 ----------------------
13133 function Is_Selector_Name (N : Node_Id) return Boolean is
13135 if not Is_List_Member (N) then
13137 P : constant Node_Id := Parent (N);
13139 return Nkind_In (P, N_Expanded_Name,
13140 N_Generic_Association,
13141 N_Parameter_Association,
13142 N_Selected_Component)
13143 and then Selector_Name (P) = N;
13148 L : constant List_Id := List_Containing (N);
13149 P : constant Node_Id := Parent (L);
13151 return (Nkind (P) = N_Discriminant_Association
13152 and then Selector_Names (P) = L)
13154 (Nkind (P) = N_Component_Association
13155 and then Choices (P) = L);
13158 end Is_Selector_Name;
13160 ---------------------------------
13161 -- Is_Single_Concurrent_Object --
13162 ---------------------------------
13164 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
13167 Ekind (Id) = E_Variable
13168 and then Is_Single_Concurrent_Type (Etype (Id));
13169 end Is_Single_Concurrent_Object;
13171 -------------------------------
13172 -- Is_Single_Concurrent_Type --
13173 -------------------------------
13175 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
13178 Ekind_In (Id, E_Protected_Type, E_Task_Type)
13179 and then Is_Single_Concurrent_Type_Declaration
13180 (Declaration_Node (Id));
13181 end Is_Single_Concurrent_Type;
13183 -------------------------------------------
13184 -- Is_Single_Concurrent_Type_Declaration --
13185 -------------------------------------------
13187 function Is_Single_Concurrent_Type_Declaration
13188 (N : Node_Id) return Boolean
13191 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
13192 N_Single_Task_Declaration);
13193 end Is_Single_Concurrent_Type_Declaration;
13195 ---------------------------------------------
13196 -- Is_Single_Precision_Floating_Point_Type --
13197 ---------------------------------------------
13199 function Is_Single_Precision_Floating_Point_Type
13200 (E : Entity_Id) return Boolean is
13202 return Is_Floating_Point_Type (E)
13203 and then Machine_Radix_Value (E) = Uint_2
13204 and then Machine_Mantissa_Value (E) = Uint_24
13205 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
13206 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
13207 end Is_Single_Precision_Floating_Point_Type;
13209 -------------------------------------
13210 -- Is_SPARK_05_Initialization_Expr --
13211 -------------------------------------
13213 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
13216 Comp_Assn : Node_Id;
13217 Orig_N : constant Node_Id := Original_Node (N);
13222 if not Comes_From_Source (Orig_N) then
13226 pragma Assert (Nkind (Orig_N) in N_Subexpr);
13228 case Nkind (Orig_N) is
13229 when N_Character_Literal |
13230 N_Integer_Literal |
13232 N_String_Literal =>
13235 when N_Identifier |
13237 if Is_Entity_Name (Orig_N)
13238 and then Present (Entity (Orig_N)) -- needed in some cases
13240 case Ekind (Entity (Orig_N)) is
13242 E_Enumeration_Literal |
13247 if Is_Type (Entity (Orig_N)) then
13255 when N_Qualified_Expression |
13256 N_Type_Conversion =>
13257 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
13260 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13264 N_Membership_Test =>
13265 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
13267 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13270 N_Extension_Aggregate =>
13271 if Nkind (Orig_N) = N_Extension_Aggregate then
13273 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
13276 Expr := First (Expressions (Orig_N));
13277 while Present (Expr) loop
13278 if not Is_SPARK_05_Initialization_Expr (Expr) then
13286 Comp_Assn := First (Component_Associations (Orig_N));
13287 while Present (Comp_Assn) loop
13288 Expr := Expression (Comp_Assn);
13290 -- Note: test for Present here needed for box assocation
13293 and then not Is_SPARK_05_Initialization_Expr (Expr)
13302 when N_Attribute_Reference =>
13303 if Nkind (Prefix (Orig_N)) in N_Subexpr then
13304 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
13307 Expr := First (Expressions (Orig_N));
13308 while Present (Expr) loop
13309 if not Is_SPARK_05_Initialization_Expr (Expr) then
13317 -- Selected components might be expanded named not yet resolved, so
13318 -- default on the safe side. (Eg on sparklex.ads)
13320 when N_Selected_Component =>
13329 end Is_SPARK_05_Initialization_Expr;
13331 ----------------------------------
13332 -- Is_SPARK_05_Object_Reference --
13333 ----------------------------------
13335 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
13337 if Is_Entity_Name (N) then
13338 return Present (Entity (N))
13340 (Ekind_In (Entity (N), E_Constant, E_Variable)
13341 or else Ekind (Entity (N)) in Formal_Kind);
13345 when N_Selected_Component =>
13346 return Is_SPARK_05_Object_Reference (Prefix (N));
13352 end Is_SPARK_05_Object_Reference;
13354 -----------------------------
13355 -- Is_Specific_Tagged_Type --
13356 -----------------------------
13358 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
13359 Full_Typ : Entity_Id;
13362 -- Handle private types
13364 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
13365 Full_Typ := Full_View (Typ);
13370 -- A specific tagged type is a non-class-wide tagged type
13372 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
13373 end Is_Specific_Tagged_Type;
13379 function Is_Statement (N : Node_Id) return Boolean is
13382 Nkind (N) in N_Statement_Other_Than_Procedure_Call
13383 or else Nkind (N) = N_Procedure_Call_Statement;
13386 ---------------------------------------
13387 -- Is_Subprogram_Contract_Annotation --
13388 ---------------------------------------
13390 function Is_Subprogram_Contract_Annotation
13391 (Item : Node_Id) return Boolean
13396 if Nkind (Item) = N_Aspect_Specification then
13397 Nam := Chars (Identifier (Item));
13399 else pragma Assert (Nkind (Item) = N_Pragma);
13400 Nam := Pragma_Name (Item);
13403 return Nam = Name_Contract_Cases
13404 or else Nam = Name_Depends
13405 or else Nam = Name_Extensions_Visible
13406 or else Nam = Name_Global
13407 or else Nam = Name_Post
13408 or else Nam = Name_Post_Class
13409 or else Nam = Name_Postcondition
13410 or else Nam = Name_Pre
13411 or else Nam = Name_Pre_Class
13412 or else Nam = Name_Precondition
13413 or else Nam = Name_Refined_Depends
13414 or else Nam = Name_Refined_Global
13415 or else Nam = Name_Refined_Post
13416 or else Nam = Name_Test_Case;
13417 end Is_Subprogram_Contract_Annotation;
13419 --------------------------------------------------
13420 -- Is_Subprogram_Stub_Without_Prior_Declaration --
13421 --------------------------------------------------
13423 function Is_Subprogram_Stub_Without_Prior_Declaration
13424 (N : Node_Id) return Boolean
13427 -- A subprogram stub without prior declaration serves as declaration for
13428 -- the actual subprogram body. As such, it has an attached defining
13429 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
13431 return Nkind (N) = N_Subprogram_Body_Stub
13432 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
13433 end Is_Subprogram_Stub_Without_Prior_Declaration;
13435 --------------------------
13436 -- Is_Suspension_Object --
13437 --------------------------
13439 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
13441 -- This approach does an exact name match rather than to rely on
13442 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
13443 -- front end at point where all auxiliary tables are locked and any
13444 -- modifications to them are treated as violations. Do not tamper with
13445 -- the tables, instead examine the Chars fields of all the scopes of Id.
13448 Chars (Id) = Name_Suspension_Object
13449 and then Present (Scope (Id))
13450 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
13451 and then Present (Scope (Scope (Id)))
13452 and then Chars (Scope (Scope (Id))) = Name_Ada
13453 and then Present (Scope (Scope (Scope (Id))))
13454 and then Scope (Scope (Scope (Id))) = Standard_Standard;
13455 end Is_Suspension_Object;
13457 ----------------------------
13458 -- Is_Synchronized_Object --
13459 ----------------------------
13461 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
13465 if Is_Object (Id) then
13467 -- The object is synchronized if it is of a type that yields a
13468 -- synchronized object.
13470 if Yields_Synchronized_Object (Etype (Id)) then
13473 -- The object is synchronized if it is atomic and Async_Writers is
13476 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
13479 -- A constant is a synchronized object by default
13481 elsif Ekind (Id) = E_Constant then
13484 -- A variable is a synchronized object if it is subject to pragma
13485 -- Constant_After_Elaboration.
13487 elsif Ekind (Id) = E_Variable then
13488 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
13490 return Present (Prag) and then Is_Enabled_Pragma (Prag);
13494 -- Otherwise the input is not an object or it does not qualify as a
13495 -- synchronized object.
13498 end Is_Synchronized_Object;
13500 ---------------------------------
13501 -- Is_Synchronized_Tagged_Type --
13502 ---------------------------------
13504 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
13505 Kind : constant Entity_Kind := Ekind (Base_Type (E));
13508 -- A task or protected type derived from an interface is a tagged type.
13509 -- Such a tagged type is called a synchronized tagged type, as are
13510 -- synchronized interfaces and private extensions whose declaration
13511 -- includes the reserved word synchronized.
13513 return (Is_Tagged_Type (E)
13514 and then (Kind = E_Task_Type
13516 Kind = E_Protected_Type))
13519 and then Is_Synchronized_Interface (E))
13521 (Ekind (E) = E_Record_Type_With_Private
13522 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
13523 and then (Synchronized_Present (Parent (E))
13524 or else Is_Synchronized_Interface (Etype (E))));
13525 end Is_Synchronized_Tagged_Type;
13531 function Is_Transfer (N : Node_Id) return Boolean is
13532 Kind : constant Node_Kind := Nkind (N);
13535 if Kind = N_Simple_Return_Statement
13537 Kind = N_Extended_Return_Statement
13539 Kind = N_Goto_Statement
13541 Kind = N_Raise_Statement
13543 Kind = N_Requeue_Statement
13547 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
13548 and then No (Condition (N))
13552 elsif Kind = N_Procedure_Call_Statement
13553 and then Is_Entity_Name (Name (N))
13554 and then Present (Entity (Name (N)))
13555 and then No_Return (Entity (Name (N)))
13559 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
13571 function Is_True (U : Uint) return Boolean is
13576 --------------------------------------
13577 -- Is_Unchecked_Conversion_Instance --
13578 --------------------------------------
13580 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
13581 Gen_Par : Entity_Id;
13584 -- Look for a function whose generic parent is the predefined intrinsic
13585 -- function Unchecked_Conversion.
13587 if Ekind (Id) = E_Function then
13588 Gen_Par := Generic_Parent (Parent (Id));
13592 and then Chars (Gen_Par) = Name_Unchecked_Conversion
13593 and then Is_Intrinsic_Subprogram (Gen_Par)
13594 and then Is_Predefined_File_Name
13595 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
13599 end Is_Unchecked_Conversion_Instance;
13601 -------------------------------
13602 -- Is_Universal_Numeric_Type --
13603 -------------------------------
13605 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
13607 return T = Universal_Integer or else T = Universal_Real;
13608 end Is_Universal_Numeric_Type;
13610 ----------------------------
13611 -- Is_Variable_Size_Array --
13612 ----------------------------
13614 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
13618 pragma Assert (Is_Array_Type (E));
13620 -- Check if some index is initialized with a non-constant value
13622 Idx := First_Index (E);
13623 while Present (Idx) loop
13624 if Nkind (Idx) = N_Range then
13625 if not Is_Constant_Bound (Low_Bound (Idx))
13626 or else not Is_Constant_Bound (High_Bound (Idx))
13632 Idx := Next_Index (Idx);
13636 end Is_Variable_Size_Array;
13638 -----------------------------
13639 -- Is_Variable_Size_Record --
13640 -----------------------------
13642 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
13644 Comp_Typ : Entity_Id;
13647 pragma Assert (Is_Record_Type (E));
13649 Comp := First_Entity (E);
13650 while Present (Comp) loop
13651 Comp_Typ := Etype (Comp);
13653 -- Recursive call if the record type has discriminants
13655 if Is_Record_Type (Comp_Typ)
13656 and then Has_Discriminants (Comp_Typ)
13657 and then Is_Variable_Size_Record (Comp_Typ)
13661 elsif Is_Array_Type (Comp_Typ)
13662 and then Is_Variable_Size_Array (Comp_Typ)
13667 Next_Entity (Comp);
13671 end Is_Variable_Size_Record;
13677 function Is_Variable
13679 Use_Original_Node : Boolean := True) return Boolean
13681 Orig_Node : Node_Id;
13683 function In_Protected_Function (E : Entity_Id) return Boolean;
13684 -- Within a protected function, the private components of the enclosing
13685 -- protected type are constants. A function nested within a (protected)
13686 -- procedure is not itself protected. Within the body of a protected
13687 -- function the current instance of the protected type is a constant.
13689 function Is_Variable_Prefix (P : Node_Id) return Boolean;
13690 -- Prefixes can involve implicit dereferences, in which case we must
13691 -- test for the case of a reference of a constant access type, which can
13692 -- can never be a variable.
13694 ---------------------------
13695 -- In_Protected_Function --
13696 ---------------------------
13698 function In_Protected_Function (E : Entity_Id) return Boolean is
13703 -- E is the current instance of a type
13705 if Is_Type (E) then
13714 if not Is_Protected_Type (Prot) then
13718 S := Current_Scope;
13719 while Present (S) and then S /= Prot loop
13720 if Ekind (S) = E_Function and then Scope (S) = Prot then
13729 end In_Protected_Function;
13731 ------------------------
13732 -- Is_Variable_Prefix --
13733 ------------------------
13735 function Is_Variable_Prefix (P : Node_Id) return Boolean is
13737 if Is_Access_Type (Etype (P)) then
13738 return not Is_Access_Constant (Root_Type (Etype (P)));
13740 -- For the case of an indexed component whose prefix has a packed
13741 -- array type, the prefix has been rewritten into a type conversion.
13742 -- Determine variable-ness from the converted expression.
13744 elsif Nkind (P) = N_Type_Conversion
13745 and then not Comes_From_Source (P)
13746 and then Is_Array_Type (Etype (P))
13747 and then Is_Packed (Etype (P))
13749 return Is_Variable (Expression (P));
13752 return Is_Variable (P);
13754 end Is_Variable_Prefix;
13756 -- Start of processing for Is_Variable
13759 -- Special check, allow x'Deref(expr) as a variable
13761 if Nkind (N) = N_Attribute_Reference
13762 and then Attribute_Name (N) = Name_Deref
13767 -- Check if we perform the test on the original node since this may be a
13768 -- test of syntactic categories which must not be disturbed by whatever
13769 -- rewriting might have occurred. For example, an aggregate, which is
13770 -- certainly NOT a variable, could be turned into a variable by
13773 if Use_Original_Node then
13774 Orig_Node := Original_Node (N);
13779 -- Definitely OK if Assignment_OK is set. Since this is something that
13780 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
13782 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
13785 -- Normally we go to the original node, but there is one exception where
13786 -- we use the rewritten node, namely when it is an explicit dereference.
13787 -- The generated code may rewrite a prefix which is an access type with
13788 -- an explicit dereference. The dereference is a variable, even though
13789 -- the original node may not be (since it could be a constant of the
13792 -- In Ada 2005 we have a further case to consider: the prefix may be a
13793 -- function call given in prefix notation. The original node appears to
13794 -- be a selected component, but we need to examine the call.
13796 elsif Nkind (N) = N_Explicit_Dereference
13797 and then Nkind (Orig_Node) /= N_Explicit_Dereference
13798 and then Present (Etype (Orig_Node))
13799 and then Is_Access_Type (Etype (Orig_Node))
13801 -- Note that if the prefix is an explicit dereference that does not
13802 -- come from source, we must check for a rewritten function call in
13803 -- prefixed notation before other forms of rewriting, to prevent a
13807 (Nkind (Orig_Node) = N_Function_Call
13808 and then not Is_Access_Constant (Etype (Prefix (N))))
13810 Is_Variable_Prefix (Original_Node (Prefix (N)));
13812 -- in Ada 2012, the dereference may have been added for a type with
13813 -- a declared implicit dereference aspect. Check that it is not an
13814 -- access to constant.
13816 elsif Nkind (N) = N_Explicit_Dereference
13817 and then Present (Etype (Orig_Node))
13818 and then Ada_Version >= Ada_2012
13819 and then Has_Implicit_Dereference (Etype (Orig_Node))
13821 return not Is_Access_Constant (Etype (Prefix (N)));
13823 -- A function call is never a variable
13825 elsif Nkind (N) = N_Function_Call then
13828 -- All remaining checks use the original node
13830 elsif Is_Entity_Name (Orig_Node)
13831 and then Present (Entity (Orig_Node))
13834 E : constant Entity_Id := Entity (Orig_Node);
13835 K : constant Entity_Kind := Ekind (E);
13838 return (K = E_Variable
13839 and then Nkind (Parent (E)) /= N_Exception_Handler)
13840 or else (K = E_Component
13841 and then not In_Protected_Function (E))
13842 or else K = E_Out_Parameter
13843 or else K = E_In_Out_Parameter
13844 or else K = E_Generic_In_Out_Parameter
13846 -- Current instance of type. If this is a protected type, check
13847 -- we are not within the body of one of its protected functions.
13849 or else (Is_Type (E)
13850 and then In_Open_Scopes (E)
13851 and then not In_Protected_Function (E))
13853 or else (Is_Incomplete_Or_Private_Type (E)
13854 and then In_Open_Scopes (Full_View (E)));
13858 case Nkind (Orig_Node) is
13859 when N_Indexed_Component | N_Slice =>
13860 return Is_Variable_Prefix (Prefix (Orig_Node));
13862 when N_Selected_Component =>
13863 return (Is_Variable (Selector_Name (Orig_Node))
13864 and then Is_Variable_Prefix (Prefix (Orig_Node)))
13866 (Nkind (N) = N_Expanded_Name
13867 and then Scope (Entity (N)) = Entity (Prefix (N)));
13869 -- For an explicit dereference, the type of the prefix cannot
13870 -- be an access to constant or an access to subprogram.
13872 when N_Explicit_Dereference =>
13874 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
13876 return Is_Access_Type (Typ)
13877 and then not Is_Access_Constant (Root_Type (Typ))
13878 and then Ekind (Typ) /= E_Access_Subprogram_Type;
13881 -- The type conversion is the case where we do not deal with the
13882 -- context dependent special case of an actual parameter. Thus
13883 -- the type conversion is only considered a variable for the
13884 -- purposes of this routine if the target type is tagged. However,
13885 -- a type conversion is considered to be a variable if it does not
13886 -- come from source (this deals for example with the conversions
13887 -- of expressions to their actual subtypes).
13889 when N_Type_Conversion =>
13890 return Is_Variable (Expression (Orig_Node))
13892 (not Comes_From_Source (Orig_Node)
13894 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
13896 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
13898 -- GNAT allows an unchecked type conversion as a variable. This
13899 -- only affects the generation of internal expanded code, since
13900 -- calls to instantiations of Unchecked_Conversion are never
13901 -- considered variables (since they are function calls).
13903 when N_Unchecked_Type_Conversion =>
13904 return Is_Variable (Expression (Orig_Node));
13912 ---------------------------
13913 -- Is_Visibly_Controlled --
13914 ---------------------------
13916 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
13917 Root : constant Entity_Id := Root_Type (T);
13919 return Chars (Scope (Root)) = Name_Finalization
13920 and then Chars (Scope (Scope (Root))) = Name_Ada
13921 and then Scope (Scope (Scope (Root))) = Standard_Standard;
13922 end Is_Visibly_Controlled;
13924 --------------------------
13925 -- Is_Volatile_Function --
13926 --------------------------
13928 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
13930 -- The caller must ensure that Func_Id denotes a function
13932 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
13934 -- A protected function is automatically volatile
13936 if Is_Primitive (Func_Id)
13937 and then Present (First_Formal (Func_Id))
13938 and then Is_Protected_Type (Etype (First_Formal (Func_Id)))
13942 -- An instance of Ada.Unchecked_Conversion is a volatile function if
13943 -- either the source or the target are effectively volatile.
13945 elsif Is_Unchecked_Conversion_Instance (Func_Id)
13946 and then Has_Effectively_Volatile_Profile (Func_Id)
13950 -- Otherwise the function is treated as volatile if it is subject to
13951 -- enabled pragma Volatile_Function.
13955 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
13957 end Is_Volatile_Function;
13959 ------------------------
13960 -- Is_Volatile_Object --
13961 ------------------------
13963 function Is_Volatile_Object (N : Node_Id) return Boolean is
13965 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
13966 -- If prefix is an implicit dereference, examine designated type
13968 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
13969 -- Determines if given object has volatile components
13971 ------------------------
13972 -- Is_Volatile_Prefix --
13973 ------------------------
13975 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
13976 Typ : constant Entity_Id := Etype (N);
13979 if Is_Access_Type (Typ) then
13981 Dtyp : constant Entity_Id := Designated_Type (Typ);
13984 return Is_Volatile (Dtyp)
13985 or else Has_Volatile_Components (Dtyp);
13989 return Object_Has_Volatile_Components (N);
13991 end Is_Volatile_Prefix;
13993 ------------------------------------
13994 -- Object_Has_Volatile_Components --
13995 ------------------------------------
13997 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
13998 Typ : constant Entity_Id := Etype (N);
14001 if Is_Volatile (Typ)
14002 or else Has_Volatile_Components (Typ)
14006 elsif Is_Entity_Name (N)
14007 and then (Has_Volatile_Components (Entity (N))
14008 or else Is_Volatile (Entity (N)))
14012 elsif Nkind (N) = N_Indexed_Component
14013 or else Nkind (N) = N_Selected_Component
14015 return Is_Volatile_Prefix (Prefix (N));
14020 end Object_Has_Volatile_Components;
14022 -- Start of processing for Is_Volatile_Object
14025 if Nkind (N) = N_Defining_Identifier then
14026 return Is_Volatile (N) or else Is_Volatile (Etype (N));
14028 elsif Nkind (N) = N_Expanded_Name then
14029 return Is_Volatile_Object (Entity (N));
14031 elsif Is_Volatile (Etype (N))
14032 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
14036 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
14037 and then Is_Volatile_Prefix (Prefix (N))
14041 elsif Nkind (N) = N_Selected_Component
14042 and then Is_Volatile (Entity (Selector_Name (N)))
14049 end Is_Volatile_Object;
14051 ---------------------------
14052 -- Itype_Has_Declaration --
14053 ---------------------------
14055 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
14057 pragma Assert (Is_Itype (Id));
14058 return Present (Parent (Id))
14059 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
14060 N_Subtype_Declaration)
14061 and then Defining_Entity (Parent (Id)) = Id;
14062 end Itype_Has_Declaration;
14064 -------------------------
14065 -- Kill_Current_Values --
14066 -------------------------
14068 procedure Kill_Current_Values
14070 Last_Assignment_Only : Boolean := False)
14073 if Is_Assignable (Ent) then
14074 Set_Last_Assignment (Ent, Empty);
14077 if Is_Object (Ent) then
14078 if not Last_Assignment_Only then
14080 Set_Current_Value (Ent, Empty);
14082 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
14083 -- for a constant. Once the constant is elaborated, its value is
14084 -- not changed, therefore the associated flags that describe the
14085 -- value should not be modified either.
14087 if Ekind (Ent) = E_Constant then
14090 -- Non-constant entities
14093 if not Can_Never_Be_Null (Ent) then
14094 Set_Is_Known_Non_Null (Ent, False);
14097 Set_Is_Known_Null (Ent, False);
14099 -- Reset the Is_Known_Valid flag unless the type is always
14100 -- valid. This does not apply to a loop parameter because its
14101 -- bounds are defined by the loop header and therefore always
14104 if not Is_Known_Valid (Etype (Ent))
14105 and then Ekind (Ent) /= E_Loop_Parameter
14107 Set_Is_Known_Valid (Ent, False);
14112 end Kill_Current_Values;
14114 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
14117 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
14118 -- Clear current value for entity E and all entities chained to E
14120 ------------------------------------------
14121 -- Kill_Current_Values_For_Entity_Chain --
14122 ------------------------------------------
14124 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
14128 while Present (Ent) loop
14129 Kill_Current_Values (Ent, Last_Assignment_Only);
14132 end Kill_Current_Values_For_Entity_Chain;
14134 -- Start of processing for Kill_Current_Values
14137 -- Kill all saved checks, a special case of killing saved values
14139 if not Last_Assignment_Only then
14143 -- Loop through relevant scopes, which includes the current scope and
14144 -- any parent scopes if the current scope is a block or a package.
14146 S := Current_Scope;
14149 -- Clear current values of all entities in current scope
14151 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
14153 -- If scope is a package, also clear current values of all private
14154 -- entities in the scope.
14156 if Is_Package_Or_Generic_Package (S)
14157 or else Is_Concurrent_Type (S)
14159 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
14162 -- If this is a not a subprogram, deal with parents
14164 if not Is_Subprogram (S) then
14166 exit Scope_Loop when S = Standard_Standard;
14170 end loop Scope_Loop;
14171 end Kill_Current_Values;
14173 --------------------------
14174 -- Kill_Size_Check_Code --
14175 --------------------------
14177 procedure Kill_Size_Check_Code (E : Entity_Id) is
14179 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14180 and then Present (Size_Check_Code (E))
14182 Remove (Size_Check_Code (E));
14183 Set_Size_Check_Code (E, Empty);
14185 end Kill_Size_Check_Code;
14187 --------------------------
14188 -- Known_To_Be_Assigned --
14189 --------------------------
14191 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
14192 P : constant Node_Id := Parent (N);
14197 -- Test left side of assignment
14199 when N_Assignment_Statement =>
14200 return N = Name (P);
14202 -- Function call arguments are never lvalues
14204 when N_Function_Call =>
14207 -- Positional parameter for procedure or accept call
14209 when N_Procedure_Call_Statement |
14218 Proc := Get_Subprogram_Entity (P);
14224 -- If we are not a list member, something is strange, so
14225 -- be conservative and return False.
14227 if not Is_List_Member (N) then
14231 -- We are going to find the right formal by stepping forward
14232 -- through the formals, as we step backwards in the actuals.
14234 Form := First_Formal (Proc);
14237 -- If no formal, something is weird, so be conservative
14238 -- and return False.
14245 exit when No (Act);
14246 Next_Formal (Form);
14249 return Ekind (Form) /= E_In_Parameter;
14252 -- Named parameter for procedure or accept call
14254 when N_Parameter_Association =>
14260 Proc := Get_Subprogram_Entity (Parent (P));
14266 -- Loop through formals to find the one that matches
14268 Form := First_Formal (Proc);
14270 -- If no matching formal, that's peculiar, some kind of
14271 -- previous error, so return False to be conservative.
14272 -- Actually this also happens in legal code in the case
14273 -- where P is a parameter association for an Extra_Formal???
14279 -- Else test for match
14281 if Chars (Form) = Chars (Selector_Name (P)) then
14282 return Ekind (Form) /= E_In_Parameter;
14285 Next_Formal (Form);
14289 -- Test for appearing in a conversion that itself appears
14290 -- in an lvalue context, since this should be an lvalue.
14292 when N_Type_Conversion =>
14293 return Known_To_Be_Assigned (P);
14295 -- All other references are definitely not known to be modifications
14301 end Known_To_Be_Assigned;
14303 ---------------------------
14304 -- Last_Source_Statement --
14305 ---------------------------
14307 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
14311 N := Last (Statements (HSS));
14312 while Present (N) loop
14313 exit when Comes_From_Source (N);
14318 end Last_Source_Statement;
14320 ----------------------------------
14321 -- Matching_Static_Array_Bounds --
14322 ----------------------------------
14324 function Matching_Static_Array_Bounds
14326 R_Typ : Node_Id) return Boolean
14328 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
14329 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
14341 if L_Ndims /= R_Ndims then
14345 -- Unconstrained types do not have static bounds
14347 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
14351 -- First treat specially the first dimension, as the lower bound and
14352 -- length of string literals are not stored like those of arrays.
14354 if Ekind (L_Typ) = E_String_Literal_Subtype then
14355 L_Low := String_Literal_Low_Bound (L_Typ);
14356 L_Len := String_Literal_Length (L_Typ);
14358 L_Index := First_Index (L_Typ);
14359 Get_Index_Bounds (L_Index, L_Low, L_High);
14361 if Is_OK_Static_Expression (L_Low)
14363 Is_OK_Static_Expression (L_High)
14365 if Expr_Value (L_High) < Expr_Value (L_Low) then
14368 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
14375 if Ekind (R_Typ) = E_String_Literal_Subtype then
14376 R_Low := String_Literal_Low_Bound (R_Typ);
14377 R_Len := String_Literal_Length (R_Typ);
14379 R_Index := First_Index (R_Typ);
14380 Get_Index_Bounds (R_Index, R_Low, R_High);
14382 if Is_OK_Static_Expression (R_Low)
14384 Is_OK_Static_Expression (R_High)
14386 if Expr_Value (R_High) < Expr_Value (R_Low) then
14389 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
14396 if (Is_OK_Static_Expression (L_Low)
14398 Is_OK_Static_Expression (R_Low))
14399 and then Expr_Value (L_Low) = Expr_Value (R_Low)
14400 and then L_Len = R_Len
14407 -- Then treat all other dimensions
14409 for Indx in 2 .. L_Ndims loop
14413 Get_Index_Bounds (L_Index, L_Low, L_High);
14414 Get_Index_Bounds (R_Index, R_Low, R_High);
14416 if (Is_OK_Static_Expression (L_Low) and then
14417 Is_OK_Static_Expression (L_High) and then
14418 Is_OK_Static_Expression (R_Low) and then
14419 Is_OK_Static_Expression (R_High))
14420 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
14422 Expr_Value (L_High) = Expr_Value (R_High))
14430 -- If we fall through the loop, all indexes matched
14433 end Matching_Static_Array_Bounds;
14435 -------------------
14436 -- May_Be_Lvalue --
14437 -------------------
14439 function May_Be_Lvalue (N : Node_Id) return Boolean is
14440 P : constant Node_Id := Parent (N);
14445 -- Test left side of assignment
14447 when N_Assignment_Statement =>
14448 return N = Name (P);
14450 -- Test prefix of component or attribute. Note that the prefix of an
14451 -- explicit or implicit dereference cannot be an l-value.
14453 when N_Attribute_Reference =>
14454 return N = Prefix (P)
14455 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
14457 -- For an expanded name, the name is an lvalue if the expanded name
14458 -- is an lvalue, but the prefix is never an lvalue, since it is just
14459 -- the scope where the name is found.
14461 when N_Expanded_Name =>
14462 if N = Prefix (P) then
14463 return May_Be_Lvalue (P);
14468 -- For a selected component A.B, A is certainly an lvalue if A.B is.
14469 -- B is a little interesting, if we have A.B := 3, there is some
14470 -- discussion as to whether B is an lvalue or not, we choose to say
14471 -- it is. Note however that A is not an lvalue if it is of an access
14472 -- type since this is an implicit dereference.
14474 when N_Selected_Component =>
14476 and then Present (Etype (N))
14477 and then Is_Access_Type (Etype (N))
14481 return May_Be_Lvalue (P);
14484 -- For an indexed component or slice, the index or slice bounds is
14485 -- never an lvalue. The prefix is an lvalue if the indexed component
14486 -- or slice is an lvalue, except if it is an access type, where we
14487 -- have an implicit dereference.
14489 when N_Indexed_Component | N_Slice =>
14491 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
14495 return May_Be_Lvalue (P);
14498 -- Prefix of a reference is an lvalue if the reference is an lvalue
14500 when N_Reference =>
14501 return May_Be_Lvalue (P);
14503 -- Prefix of explicit dereference is never an lvalue
14505 when N_Explicit_Dereference =>
14508 -- Positional parameter for subprogram, entry, or accept call.
14509 -- In older versions of Ada function call arguments are never
14510 -- lvalues. In Ada 2012 functions can have in-out parameters.
14512 when N_Subprogram_Call |
14513 N_Entry_Call_Statement |
14516 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
14520 -- The following mechanism is clumsy and fragile. A single flag
14521 -- set in Resolve_Actuals would be preferable ???
14529 Proc := Get_Subprogram_Entity (P);
14535 -- If we are not a list member, something is strange, so be
14536 -- conservative and return True.
14538 if not Is_List_Member (N) then
14542 -- We are going to find the right formal by stepping forward
14543 -- through the formals, as we step backwards in the actuals.
14545 Form := First_Formal (Proc);
14548 -- If no formal, something is weird, so be conservative and
14556 exit when No (Act);
14557 Next_Formal (Form);
14560 return Ekind (Form) /= E_In_Parameter;
14563 -- Named parameter for procedure or accept call
14565 when N_Parameter_Association =>
14571 Proc := Get_Subprogram_Entity (Parent (P));
14577 -- Loop through formals to find the one that matches
14579 Form := First_Formal (Proc);
14581 -- If no matching formal, that's peculiar, some kind of
14582 -- previous error, so return True to be conservative.
14583 -- Actually happens with legal code for an unresolved call
14584 -- where we may get the wrong homonym???
14590 -- Else test for match
14592 if Chars (Form) = Chars (Selector_Name (P)) then
14593 return Ekind (Form) /= E_In_Parameter;
14596 Next_Formal (Form);
14600 -- Test for appearing in a conversion that itself appears in an
14601 -- lvalue context, since this should be an lvalue.
14603 when N_Type_Conversion =>
14604 return May_Be_Lvalue (P);
14606 -- Test for appearance in object renaming declaration
14608 when N_Object_Renaming_Declaration =>
14611 -- All other references are definitely not lvalues
14619 -----------------------
14620 -- Mark_Coextensions --
14621 -----------------------
14623 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
14624 Is_Dynamic : Boolean;
14625 -- Indicates whether the context causes nested coextensions to be
14626 -- dynamic or static
14628 function Mark_Allocator (N : Node_Id) return Traverse_Result;
14629 -- Recognize an allocator node and label it as a dynamic coextension
14631 --------------------
14632 -- Mark_Allocator --
14633 --------------------
14635 function Mark_Allocator (N : Node_Id) return Traverse_Result is
14637 if Nkind (N) = N_Allocator then
14639 Set_Is_Dynamic_Coextension (N);
14641 -- If the allocator expression is potentially dynamic, it may
14642 -- be expanded out of order and require dynamic allocation
14643 -- anyway, so we treat the coextension itself as dynamic.
14644 -- Potential optimization ???
14646 elsif Nkind (Expression (N)) = N_Qualified_Expression
14647 and then Nkind (Expression (Expression (N))) = N_Op_Concat
14649 Set_Is_Dynamic_Coextension (N);
14651 Set_Is_Static_Coextension (N);
14656 end Mark_Allocator;
14658 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
14660 -- Start of processing for Mark_Coextensions
14663 -- An allocator that appears on the right-hand side of an assignment is
14664 -- treated as a potentially dynamic coextension when the right-hand side
14665 -- is an allocator or a qualified expression.
14667 -- Obj := new ...'(new Coextension ...);
14669 if Nkind (Context_Nod) = N_Assignment_Statement then
14671 Nkind_In (Expression (Context_Nod), N_Allocator,
14672 N_Qualified_Expression);
14674 -- An allocator that appears within the expression of a simple return
14675 -- statement is treated as a potentially dynamic coextension when the
14676 -- expression is either aggregate, allocator, or qualified expression.
14678 -- return (new Coextension ...);
14679 -- return new ...'(new Coextension ...);
14681 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
14683 Nkind_In (Expression (Context_Nod), N_Aggregate,
14685 N_Qualified_Expression);
14687 -- An alloctor that appears within the initialization expression of an
14688 -- object declaration is considered a potentially dynamic coextension
14689 -- when the initialization expression is an allocator or a qualified
14692 -- Obj : ... := new ...'(new Coextension ...);
14694 -- A similar case arises when the object declaration is part of an
14695 -- extended return statement.
14697 -- return Obj : ... := new ...'(new Coextension ...);
14698 -- return Obj : ... := (new Coextension ...);
14700 elsif Nkind (Context_Nod) = N_Object_Declaration then
14702 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
14704 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
14706 -- This routine should not be called with constructs that cannot contain
14710 raise Program_Error;
14713 Mark_Allocators (Root_Nod);
14714 end Mark_Coextensions;
14716 ----------------------
14717 -- Needs_One_Actual --
14718 ----------------------
14720 function Needs_One_Actual (E : Entity_Id) return Boolean is
14721 Formal : Entity_Id;
14724 -- Ada 2005 or later, and formals present
14726 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
14727 Formal := Next_Formal (First_Formal (E));
14728 while Present (Formal) loop
14729 if No (Default_Value (Formal)) then
14733 Next_Formal (Formal);
14738 -- Ada 83/95 or no formals
14743 end Needs_One_Actual;
14745 ------------------------
14746 -- New_Copy_List_Tree --
14747 ------------------------
14749 function New_Copy_List_Tree (List : List_Id) return List_Id is
14754 if List = No_List then
14761 while Present (E) loop
14762 Append (New_Copy_Tree (E), NL);
14768 end New_Copy_List_Tree;
14770 --------------------------------------------------
14771 -- New_Copy_Tree Auxiliary Data and Subprograms --
14772 --------------------------------------------------
14774 use Atree.Unchecked_Access;
14775 use Atree_Private_Part;
14777 -- Our approach here requires a two pass traversal of the tree. The
14778 -- first pass visits all nodes that eventually will be copied looking
14779 -- for defining Itypes. If any defining Itypes are found, then they are
14780 -- copied, and an entry is added to the replacement map. In the second
14781 -- phase, the tree is copied, using the replacement map to replace any
14782 -- Itype references within the copied tree.
14784 -- The following hash tables are used if the Map supplied has more
14785 -- than hash threshold entries to speed up access to the map. If
14786 -- there are fewer entries, then the map is searched sequentially
14787 -- (because setting up a hash table for only a few entries takes
14788 -- more time than it saves.
14790 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
14791 -- Hash function used for hash operations
14793 -------------------
14794 -- New_Copy_Hash --
14795 -------------------
14797 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
14799 return Nat (E) mod (NCT_Header_Num'Last + 1);
14806 -- The hash table NCT_Assoc associates old entities in the table
14807 -- with their corresponding new entities (i.e. the pairs of entries
14808 -- presented in the original Map argument are Key-Element pairs).
14810 package NCT_Assoc is new Simple_HTable (
14811 Header_Num => NCT_Header_Num,
14812 Element => Entity_Id,
14813 No_Element => Empty,
14815 Hash => New_Copy_Hash,
14816 Equal => Types."=");
14818 ---------------------
14819 -- NCT_Itype_Assoc --
14820 ---------------------
14822 -- The hash table NCT_Itype_Assoc contains entries only for those
14823 -- old nodes which have a non-empty Associated_Node_For_Itype set.
14824 -- The key is the associated node, and the element is the new node
14825 -- itself (NOT the associated node for the new node).
14827 package NCT_Itype_Assoc is new Simple_HTable (
14828 Header_Num => NCT_Header_Num,
14829 Element => Entity_Id,
14830 No_Element => Empty,
14832 Hash => New_Copy_Hash,
14833 Equal => Types."=");
14835 -------------------
14836 -- New_Copy_Tree --
14837 -------------------
14839 function New_Copy_Tree
14841 Map : Elist_Id := No_Elist;
14842 New_Sloc : Source_Ptr := No_Location;
14843 New_Scope : Entity_Id := Empty) return Node_Id
14845 Actual_Map : Elist_Id := Map;
14846 -- This is the actual map for the copy. It is initialized with the
14847 -- given elements, and then enlarged as required for Itypes that are
14848 -- copied during the first phase of the copy operation. The visit
14849 -- procedures add elements to this map as Itypes are encountered.
14850 -- The reason we cannot use Map directly, is that it may well be
14851 -- (and normally is) initialized to No_Elist, and if we have mapped
14852 -- entities, we have to reset it to point to a real Elist.
14854 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
14855 -- Called during second phase to map entities into their corresponding
14856 -- copies using Actual_Map. If the argument is not an entity, or is not
14857 -- in Actual_Map, then it is returned unchanged.
14859 procedure Build_NCT_Hash_Tables;
14860 -- Builds hash tables (number of elements >= threshold value)
14862 function Copy_Elist_With_Replacement
14863 (Old_Elist : Elist_Id) return Elist_Id;
14864 -- Called during second phase to copy element list doing replacements
14866 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
14867 -- Called during the second phase to process a copied Itype. The actual
14868 -- copy happened during the first phase (so that we could make the entry
14869 -- in the mapping), but we still have to deal with the descendents of
14870 -- the copied Itype and copy them where necessary.
14872 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
14873 -- Called during second phase to copy list doing replacements
14875 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
14876 -- Called during second phase to copy node doing replacements
14878 procedure Visit_Elist (E : Elist_Id);
14879 -- Called during first phase to visit all elements of an Elist
14881 procedure Visit_Field (F : Union_Id; N : Node_Id);
14882 -- Visit a single field, recursing to call Visit_Node or Visit_List
14883 -- if the field is a syntactic descendent of the current node (i.e.
14884 -- its parent is Node N).
14886 procedure Visit_Itype (Old_Itype : Entity_Id);
14887 -- Called during first phase to visit subsidiary fields of a defining
14888 -- Itype, and also create a copy and make an entry in the replacement
14889 -- map for the new copy.
14891 procedure Visit_List (L : List_Id);
14892 -- Called during first phase to visit all elements of a List
14894 procedure Visit_Node (N : Node_Or_Entity_Id);
14895 -- Called during first phase to visit a node and all its subtrees
14901 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
14906 if not Has_Extension (N) or else No (Actual_Map) then
14909 elsif NCT_Hash_Tables_Used then
14910 Ent := NCT_Assoc.Get (Entity_Id (N));
14912 if Present (Ent) then
14918 -- No hash table used, do serial search
14921 E := First_Elmt (Actual_Map);
14922 while Present (E) loop
14923 if Node (E) = N then
14924 return Node (Next_Elmt (E));
14926 E := Next_Elmt (Next_Elmt (E));
14934 ---------------------------
14935 -- Build_NCT_Hash_Tables --
14936 ---------------------------
14938 procedure Build_NCT_Hash_Tables is
14942 if NCT_Hash_Table_Setup then
14944 NCT_Itype_Assoc.Reset;
14947 Elmt := First_Elmt (Actual_Map);
14948 while Present (Elmt) loop
14949 Ent := Node (Elmt);
14951 -- Get new entity, and associate old and new
14954 NCT_Assoc.Set (Ent, Node (Elmt));
14956 if Is_Type (Ent) then
14958 Anode : constant Entity_Id :=
14959 Associated_Node_For_Itype (Ent);
14962 if Present (Anode) then
14964 -- Enter a link between the associated node of the
14965 -- old Itype and the new Itype, for updating later
14966 -- when node is copied.
14968 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
14976 NCT_Hash_Tables_Used := True;
14977 NCT_Hash_Table_Setup := True;
14978 end Build_NCT_Hash_Tables;
14980 ---------------------------------
14981 -- Copy_Elist_With_Replacement --
14982 ---------------------------------
14984 function Copy_Elist_With_Replacement
14985 (Old_Elist : Elist_Id) return Elist_Id
14988 New_Elist : Elist_Id;
14991 if No (Old_Elist) then
14995 New_Elist := New_Elmt_List;
14997 M := First_Elmt (Old_Elist);
14998 while Present (M) loop
14999 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
15005 end Copy_Elist_With_Replacement;
15007 ---------------------------------
15008 -- Copy_Itype_With_Replacement --
15009 ---------------------------------
15011 -- This routine exactly parallels its phase one analog Visit_Itype,
15013 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
15015 -- Translate Next_Entity, Scope and Etype fields, in case they
15016 -- reference entities that have been mapped into copies.
15018 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
15019 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
15021 if Present (New_Scope) then
15022 Set_Scope (New_Itype, New_Scope);
15024 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
15027 -- Copy referenced fields
15029 if Is_Discrete_Type (New_Itype) then
15030 Set_Scalar_Range (New_Itype,
15031 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
15033 elsif Has_Discriminants (Base_Type (New_Itype)) then
15034 Set_Discriminant_Constraint (New_Itype,
15035 Copy_Elist_With_Replacement
15036 (Discriminant_Constraint (New_Itype)));
15038 elsif Is_Array_Type (New_Itype) then
15039 if Present (First_Index (New_Itype)) then
15040 Set_First_Index (New_Itype,
15041 First (Copy_List_With_Replacement
15042 (List_Containing (First_Index (New_Itype)))));
15045 if Is_Packed (New_Itype) then
15046 Set_Packed_Array_Impl_Type (New_Itype,
15047 Copy_Node_With_Replacement
15048 (Packed_Array_Impl_Type (New_Itype)));
15051 end Copy_Itype_With_Replacement;
15053 --------------------------------
15054 -- Copy_List_With_Replacement --
15055 --------------------------------
15057 function Copy_List_With_Replacement
15058 (Old_List : List_Id) return List_Id
15060 New_List : List_Id;
15064 if Old_List = No_List then
15068 New_List := Empty_List;
15070 E := First (Old_List);
15071 while Present (E) loop
15072 Append (Copy_Node_With_Replacement (E), New_List);
15078 end Copy_List_With_Replacement;
15080 --------------------------------
15081 -- Copy_Node_With_Replacement --
15082 --------------------------------
15084 function Copy_Node_With_Replacement
15085 (Old_Node : Node_Id) return Node_Id
15087 New_Node : Node_Id;
15089 procedure Adjust_Named_Associations
15090 (Old_Node : Node_Id;
15091 New_Node : Node_Id);
15092 -- If a call node has named associations, these are chained through
15093 -- the First_Named_Actual, Next_Named_Actual links. These must be
15094 -- propagated separately to the new parameter list, because these
15095 -- are not syntactic fields.
15097 function Copy_Field_With_Replacement
15098 (Field : Union_Id) return Union_Id;
15099 -- Given Field, which is a field of Old_Node, return a copy of it
15100 -- if it is a syntactic field (i.e. its parent is Node), setting
15101 -- the parent of the copy to poit to New_Node. Otherwise returns
15102 -- the field (possibly mapped if it is an entity).
15104 -------------------------------
15105 -- Adjust_Named_Associations --
15106 -------------------------------
15108 procedure Adjust_Named_Associations
15109 (Old_Node : Node_Id;
15110 New_Node : Node_Id)
15115 Old_Next : Node_Id;
15116 New_Next : Node_Id;
15119 Old_E := First (Parameter_Associations (Old_Node));
15120 New_E := First (Parameter_Associations (New_Node));
15121 while Present (Old_E) loop
15122 if Nkind (Old_E) = N_Parameter_Association
15123 and then Present (Next_Named_Actual (Old_E))
15125 if First_Named_Actual (Old_Node)
15126 = Explicit_Actual_Parameter (Old_E)
15128 Set_First_Named_Actual
15129 (New_Node, Explicit_Actual_Parameter (New_E));
15132 -- Now scan parameter list from the beginning,to locate
15133 -- next named actual, which can be out of order.
15135 Old_Next := First (Parameter_Associations (Old_Node));
15136 New_Next := First (Parameter_Associations (New_Node));
15138 while Nkind (Old_Next) /= N_Parameter_Association
15139 or else Explicit_Actual_Parameter (Old_Next) /=
15140 Next_Named_Actual (Old_E)
15146 Set_Next_Named_Actual
15147 (New_E, Explicit_Actual_Parameter (New_Next));
15153 end Adjust_Named_Associations;
15155 ---------------------------------
15156 -- Copy_Field_With_Replacement --
15157 ---------------------------------
15159 function Copy_Field_With_Replacement
15160 (Field : Union_Id) return Union_Id
15163 if Field = Union_Id (Empty) then
15166 elsif Field in Node_Range then
15168 Old_N : constant Node_Id := Node_Id (Field);
15172 -- If syntactic field, as indicated by the parent pointer
15173 -- being set, then copy the referenced node recursively.
15175 if Parent (Old_N) = Old_Node then
15176 New_N := Copy_Node_With_Replacement (Old_N);
15178 if New_N /= Old_N then
15179 Set_Parent (New_N, New_Node);
15182 -- For semantic fields, update possible entity reference
15183 -- from the replacement map.
15186 New_N := Assoc (Old_N);
15189 return Union_Id (New_N);
15192 elsif Field in List_Range then
15194 Old_L : constant List_Id := List_Id (Field);
15198 -- If syntactic field, as indicated by the parent pointer,
15199 -- then recursively copy the entire referenced list.
15201 if Parent (Old_L) = Old_Node then
15202 New_L := Copy_List_With_Replacement (Old_L);
15203 Set_Parent (New_L, New_Node);
15205 -- For semantic list, just returned unchanged
15211 return Union_Id (New_L);
15214 -- Anything other than a list or a node is returned unchanged
15219 end Copy_Field_With_Replacement;
15221 -- Start of processing for Copy_Node_With_Replacement
15224 if Old_Node <= Empty_Or_Error then
15227 elsif Has_Extension (Old_Node) then
15228 return Assoc (Old_Node);
15231 New_Node := New_Copy (Old_Node);
15233 -- If the node we are copying is the associated node of a
15234 -- previously copied Itype, then adjust the associated node
15235 -- of the copy of that Itype accordingly.
15237 if Present (Actual_Map) then
15243 -- Case of hash table used
15245 if NCT_Hash_Tables_Used then
15246 Ent := NCT_Itype_Assoc.Get (Old_Node);
15248 if Present (Ent) then
15249 Set_Associated_Node_For_Itype (Ent, New_Node);
15252 -- Case of no hash table used
15255 E := First_Elmt (Actual_Map);
15256 while Present (E) loop
15257 if Is_Itype (Node (E))
15259 Old_Node = Associated_Node_For_Itype (Node (E))
15261 Set_Associated_Node_For_Itype
15262 (Node (Next_Elmt (E)), New_Node);
15265 E := Next_Elmt (Next_Elmt (E));
15271 -- Recursively copy descendents
15274 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
15276 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
15278 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
15280 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
15282 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
15284 -- Adjust Sloc of new node if necessary
15286 if New_Sloc /= No_Location then
15287 Set_Sloc (New_Node, New_Sloc);
15289 -- If we adjust the Sloc, then we are essentially making
15290 -- a completely new node, so the Comes_From_Source flag
15291 -- should be reset to the proper default value.
15293 Nodes.Table (New_Node).Comes_From_Source :=
15294 Default_Node.Comes_From_Source;
15297 -- If the node is call and has named associations,
15298 -- set the corresponding links in the copy.
15300 if (Nkind (Old_Node) = N_Function_Call
15301 or else Nkind (Old_Node) = N_Entry_Call_Statement
15303 Nkind (Old_Node) = N_Procedure_Call_Statement)
15304 and then Present (First_Named_Actual (Old_Node))
15306 Adjust_Named_Associations (Old_Node, New_Node);
15309 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
15310 -- The replacement mechanism applies to entities, and is not used
15311 -- here. Eventually we may need a more general graph-copying
15312 -- routine. For now, do a sequential search to find desired node.
15314 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
15315 and then Present (First_Real_Statement (Old_Node))
15318 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
15322 N1 := First (Statements (Old_Node));
15323 N2 := First (Statements (New_Node));
15325 while N1 /= Old_F loop
15330 Set_First_Real_Statement (New_Node, N2);
15335 -- All done, return copied node
15338 end Copy_Node_With_Replacement;
15344 procedure Visit_Elist (E : Elist_Id) is
15347 if Present (E) then
15348 Elmt := First_Elmt (E);
15350 while Elmt /= No_Elmt loop
15351 Visit_Node (Node (Elmt));
15361 procedure Visit_Field (F : Union_Id; N : Node_Id) is
15363 if F = Union_Id (Empty) then
15366 elsif F in Node_Range then
15368 -- Copy node if it is syntactic, i.e. its parent pointer is
15369 -- set to point to the field that referenced it (certain
15370 -- Itypes will also meet this criterion, which is fine, since
15371 -- these are clearly Itypes that do need to be copied, since
15372 -- we are copying their parent.)
15374 if Parent (Node_Id (F)) = N then
15375 Visit_Node (Node_Id (F));
15378 -- Another case, if we are pointing to an Itype, then we want
15379 -- to copy it if its associated node is somewhere in the tree
15382 -- Note: the exclusion of self-referential copies is just an
15383 -- optimization, since the search of the already copied list
15384 -- would catch it, but it is a common case (Etype pointing
15385 -- to itself for an Itype that is a base type).
15387 elsif Has_Extension (Node_Id (F))
15388 and then Is_Itype (Entity_Id (F))
15389 and then Node_Id (F) /= N
15395 P := Associated_Node_For_Itype (Node_Id (F));
15396 while Present (P) loop
15398 Visit_Node (Node_Id (F));
15405 -- An Itype whose parent is not being copied definitely
15406 -- should NOT be copied, since it does not belong in any
15407 -- sense to the copied subtree.
15413 elsif F in List_Range and then Parent (List_Id (F)) = N then
15414 Visit_List (List_Id (F));
15423 procedure Visit_Itype (Old_Itype : Entity_Id) is
15424 New_Itype : Entity_Id;
15429 -- Itypes that describe the designated type of access to subprograms
15430 -- have the structure of subprogram declarations, with signatures,
15431 -- etc. Either we duplicate the signatures completely, or choose to
15432 -- share such itypes, which is fine because their elaboration will
15433 -- have no side effects.
15435 if Ekind (Old_Itype) = E_Subprogram_Type then
15439 New_Itype := New_Copy (Old_Itype);
15441 -- The new Itype has all the attributes of the old one, and
15442 -- we just copy the contents of the entity. However, the back-end
15443 -- needs different names for debugging purposes, so we create a
15444 -- new internal name for it in all cases.
15446 Set_Chars (New_Itype, New_Internal_Name ('T'));
15448 -- If our associated node is an entity that has already been copied,
15449 -- then set the associated node of the copy to point to the right
15450 -- copy. If we have copied an Itype that is itself the associated
15451 -- node of some previously copied Itype, then we set the right
15452 -- pointer in the other direction.
15454 if Present (Actual_Map) then
15456 -- Case of hash tables used
15458 if NCT_Hash_Tables_Used then
15460 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
15462 if Present (Ent) then
15463 Set_Associated_Node_For_Itype (New_Itype, Ent);
15466 Ent := NCT_Itype_Assoc.Get (Old_Itype);
15467 if Present (Ent) then
15468 Set_Associated_Node_For_Itype (Ent, New_Itype);
15470 -- If the hash table has no association for this Itype and
15471 -- its associated node, enter one now.
15474 NCT_Itype_Assoc.Set
15475 (Associated_Node_For_Itype (Old_Itype), New_Itype);
15478 -- Case of hash tables not used
15481 E := First_Elmt (Actual_Map);
15482 while Present (E) loop
15483 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
15484 Set_Associated_Node_For_Itype
15485 (New_Itype, Node (Next_Elmt (E)));
15488 if Is_Type (Node (E))
15489 and then Old_Itype = Associated_Node_For_Itype (Node (E))
15491 Set_Associated_Node_For_Itype
15492 (Node (Next_Elmt (E)), New_Itype);
15495 E := Next_Elmt (Next_Elmt (E));
15500 if Present (Freeze_Node (New_Itype)) then
15501 Set_Is_Frozen (New_Itype, False);
15502 Set_Freeze_Node (New_Itype, Empty);
15505 -- Add new association to map
15507 if No (Actual_Map) then
15508 Actual_Map := New_Elmt_List;
15511 Append_Elmt (Old_Itype, Actual_Map);
15512 Append_Elmt (New_Itype, Actual_Map);
15514 if NCT_Hash_Tables_Used then
15515 NCT_Assoc.Set (Old_Itype, New_Itype);
15518 NCT_Table_Entries := NCT_Table_Entries + 1;
15520 if NCT_Table_Entries > NCT_Hash_Threshold then
15521 Build_NCT_Hash_Tables;
15525 -- If a record subtype is simply copied, the entity list will be
15526 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
15528 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
15529 Set_Cloned_Subtype (New_Itype, Old_Itype);
15532 -- Visit descendents that eventually get copied
15534 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
15536 if Is_Discrete_Type (Old_Itype) then
15537 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
15539 elsif Has_Discriminants (Base_Type (Old_Itype)) then
15540 -- ??? This should involve call to Visit_Field
15541 Visit_Elist (Discriminant_Constraint (Old_Itype));
15543 elsif Is_Array_Type (Old_Itype) then
15544 if Present (First_Index (Old_Itype)) then
15545 Visit_Field (Union_Id (List_Containing
15546 (First_Index (Old_Itype))),
15550 if Is_Packed (Old_Itype) then
15551 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
15561 procedure Visit_List (L : List_Id) is
15564 if L /= No_List then
15567 while Present (N) loop
15578 procedure Visit_Node (N : Node_Or_Entity_Id) is
15580 -- Start of processing for Visit_Node
15583 -- Handle case of an Itype, which must be copied
15585 if Has_Extension (N) and then Is_Itype (N) then
15587 -- Nothing to do if already in the list. This can happen with an
15588 -- Itype entity that appears more than once in the tree.
15589 -- Note that we do not want to visit descendents in this case.
15591 -- Test for already in list when hash table is used
15593 if NCT_Hash_Tables_Used then
15594 if Present (NCT_Assoc.Get (Entity_Id (N))) then
15598 -- Test for already in list when hash table not used
15604 if Present (Actual_Map) then
15605 E := First_Elmt (Actual_Map);
15606 while Present (E) loop
15607 if Node (E) = N then
15610 E := Next_Elmt (Next_Elmt (E));
15620 -- Visit descendents
15622 Visit_Field (Field1 (N), N);
15623 Visit_Field (Field2 (N), N);
15624 Visit_Field (Field3 (N), N);
15625 Visit_Field (Field4 (N), N);
15626 Visit_Field (Field5 (N), N);
15629 -- Start of processing for New_Copy_Tree
15634 -- See if we should use hash table
15636 if No (Actual_Map) then
15637 NCT_Hash_Tables_Used := False;
15644 NCT_Table_Entries := 0;
15646 Elmt := First_Elmt (Actual_Map);
15647 while Present (Elmt) loop
15648 NCT_Table_Entries := NCT_Table_Entries + 1;
15653 if NCT_Table_Entries > NCT_Hash_Threshold then
15654 Build_NCT_Hash_Tables;
15656 NCT_Hash_Tables_Used := False;
15661 -- Hash table set up if required, now start phase one by visiting
15662 -- top node (we will recursively visit the descendents).
15664 Visit_Node (Source);
15666 -- Now the second phase of the copy can start. First we process
15667 -- all the mapped entities, copying their descendents.
15669 if Present (Actual_Map) then
15672 New_Itype : Entity_Id;
15674 Elmt := First_Elmt (Actual_Map);
15675 while Present (Elmt) loop
15677 New_Itype := Node (Elmt);
15679 if Is_Itype (New_Itype) then
15680 Copy_Itype_With_Replacement (New_Itype);
15687 -- Now we can copy the actual tree
15689 return Copy_Node_With_Replacement (Source);
15692 -------------------------
15693 -- New_External_Entity --
15694 -------------------------
15696 function New_External_Entity
15697 (Kind : Entity_Kind;
15698 Scope_Id : Entity_Id;
15699 Sloc_Value : Source_Ptr;
15700 Related_Id : Entity_Id;
15701 Suffix : Character;
15702 Suffix_Index : Nat := 0;
15703 Prefix : Character := ' ') return Entity_Id
15705 N : constant Entity_Id :=
15706 Make_Defining_Identifier (Sloc_Value,
15708 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
15711 Set_Ekind (N, Kind);
15712 Set_Is_Internal (N, True);
15713 Append_Entity (N, Scope_Id);
15714 Set_Public_Status (N);
15716 if Kind in Type_Kind then
15717 Init_Size_Align (N);
15721 end New_External_Entity;
15723 -------------------------
15724 -- New_Internal_Entity --
15725 -------------------------
15727 function New_Internal_Entity
15728 (Kind : Entity_Kind;
15729 Scope_Id : Entity_Id;
15730 Sloc_Value : Source_Ptr;
15731 Id_Char : Character) return Entity_Id
15733 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
15736 Set_Ekind (N, Kind);
15737 Set_Is_Internal (N, True);
15738 Append_Entity (N, Scope_Id);
15740 if Kind in Type_Kind then
15741 Init_Size_Align (N);
15745 end New_Internal_Entity;
15751 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
15755 -- If we are pointing at a positional parameter, it is a member of a
15756 -- node list (the list of parameters), and the next parameter is the
15757 -- next node on the list, unless we hit a parameter association, then
15758 -- we shift to using the chain whose head is the First_Named_Actual in
15759 -- the parent, and then is threaded using the Next_Named_Actual of the
15760 -- Parameter_Association. All this fiddling is because the original node
15761 -- list is in the textual call order, and what we need is the
15762 -- declaration order.
15764 if Is_List_Member (Actual_Id) then
15765 N := Next (Actual_Id);
15767 if Nkind (N) = N_Parameter_Association then
15768 return First_Named_Actual (Parent (Actual_Id));
15774 return Next_Named_Actual (Parent (Actual_Id));
15778 procedure Next_Actual (Actual_Id : in out Node_Id) is
15780 Actual_Id := Next_Actual (Actual_Id);
15783 -----------------------
15784 -- Normalize_Actuals --
15785 -----------------------
15787 -- Chain actuals according to formals of subprogram. If there are no named
15788 -- associations, the chain is simply the list of Parameter Associations,
15789 -- since the order is the same as the declaration order. If there are named
15790 -- associations, then the First_Named_Actual field in the N_Function_Call
15791 -- or N_Procedure_Call_Statement node points to the Parameter_Association
15792 -- node for the parameter that comes first in declaration order. The
15793 -- remaining named parameters are then chained in declaration order using
15794 -- Next_Named_Actual.
15796 -- This routine also verifies that the number of actuals is compatible with
15797 -- the number and default values of formals, but performs no type checking
15798 -- (type checking is done by the caller).
15800 -- If the matching succeeds, Success is set to True and the caller proceeds
15801 -- with type-checking. If the match is unsuccessful, then Success is set to
15802 -- False, and the caller attempts a different interpretation, if there is
15805 -- If the flag Report is on, the call is not overloaded, and a failure to
15806 -- match can be reported here, rather than in the caller.
15808 procedure Normalize_Actuals
15812 Success : out Boolean)
15814 Actuals : constant List_Id := Parameter_Associations (N);
15815 Actual : Node_Id := Empty;
15816 Formal : Entity_Id;
15817 Last : Node_Id := Empty;
15818 First_Named : Node_Id := Empty;
15821 Formals_To_Match : Integer := 0;
15822 Actuals_To_Match : Integer := 0;
15824 procedure Chain (A : Node_Id);
15825 -- Add named actual at the proper place in the list, using the
15826 -- Next_Named_Actual link.
15828 function Reporting return Boolean;
15829 -- Determines if an error is to be reported. To report an error, we
15830 -- need Report to be True, and also we do not report errors caused
15831 -- by calls to init procs that occur within other init procs. Such
15832 -- errors must always be cascaded errors, since if all the types are
15833 -- declared correctly, the compiler will certainly build decent calls.
15839 procedure Chain (A : Node_Id) is
15843 -- Call node points to first actual in list
15845 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
15848 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
15852 Set_Next_Named_Actual (Last, Empty);
15859 function Reporting return Boolean is
15864 elsif not Within_Init_Proc then
15867 elsif Is_Init_Proc (Entity (Name (N))) then
15875 -- Start of processing for Normalize_Actuals
15878 if Is_Access_Type (S) then
15880 -- The name in the call is a function call that returns an access
15881 -- to subprogram. The designated type has the list of formals.
15883 Formal := First_Formal (Designated_Type (S));
15885 Formal := First_Formal (S);
15888 while Present (Formal) loop
15889 Formals_To_Match := Formals_To_Match + 1;
15890 Next_Formal (Formal);
15893 -- Find if there is a named association, and verify that no positional
15894 -- associations appear after named ones.
15896 if Present (Actuals) then
15897 Actual := First (Actuals);
15900 while Present (Actual)
15901 and then Nkind (Actual) /= N_Parameter_Association
15903 Actuals_To_Match := Actuals_To_Match + 1;
15907 if No (Actual) and Actuals_To_Match = Formals_To_Match then
15909 -- Most common case: positional notation, no defaults
15914 elsif Actuals_To_Match > Formals_To_Match then
15916 -- Too many actuals: will not work
15919 if Is_Entity_Name (Name (N)) then
15920 Error_Msg_N ("too many arguments in call to&", Name (N));
15922 Error_Msg_N ("too many arguments in call", N);
15930 First_Named := Actual;
15932 while Present (Actual) loop
15933 if Nkind (Actual) /= N_Parameter_Association then
15935 ("positional parameters not allowed after named ones", Actual);
15940 Actuals_To_Match := Actuals_To_Match + 1;
15946 if Present (Actuals) then
15947 Actual := First (Actuals);
15950 Formal := First_Formal (S);
15951 while Present (Formal) loop
15953 -- Match the formals in order. If the corresponding actual is
15954 -- positional, nothing to do. Else scan the list of named actuals
15955 -- to find the one with the right name.
15957 if Present (Actual)
15958 and then Nkind (Actual) /= N_Parameter_Association
15961 Actuals_To_Match := Actuals_To_Match - 1;
15962 Formals_To_Match := Formals_To_Match - 1;
15965 -- For named parameters, search the list of actuals to find
15966 -- one that matches the next formal name.
15968 Actual := First_Named;
15970 while Present (Actual) loop
15971 if Chars (Selector_Name (Actual)) = Chars (Formal) then
15974 Actuals_To_Match := Actuals_To_Match - 1;
15975 Formals_To_Match := Formals_To_Match - 1;
15983 if Ekind (Formal) /= E_In_Parameter
15984 or else No (Default_Value (Formal))
15987 if (Comes_From_Source (S)
15988 or else Sloc (S) = Standard_Location)
15989 and then Is_Overloadable (S)
15993 Nkind_In (Parent (N), N_Procedure_Call_Statement,
15995 N_Parameter_Association)
15996 and then Ekind (S) /= E_Function
15998 Set_Etype (N, Etype (S));
16001 Error_Msg_Name_1 := Chars (S);
16002 Error_Msg_Sloc := Sloc (S);
16004 ("missing argument for parameter & "
16005 & "in call to % declared #", N, Formal);
16008 elsif Is_Overloadable (S) then
16009 Error_Msg_Name_1 := Chars (S);
16011 -- Point to type derivation that generated the
16014 Error_Msg_Sloc := Sloc (Parent (S));
16017 ("missing argument for parameter & "
16018 & "in call to % (inherited) #", N, Formal);
16022 ("missing argument for parameter &", N, Formal);
16030 Formals_To_Match := Formals_To_Match - 1;
16035 Next_Formal (Formal);
16038 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
16045 -- Find some superfluous named actual that did not get
16046 -- attached to the list of associations.
16048 Actual := First (Actuals);
16049 while Present (Actual) loop
16050 if Nkind (Actual) = N_Parameter_Association
16051 and then Actual /= Last
16052 and then No (Next_Named_Actual (Actual))
16054 Error_Msg_N ("unmatched actual & in call",
16055 Selector_Name (Actual));
16066 end Normalize_Actuals;
16068 --------------------------------
16069 -- Note_Possible_Modification --
16070 --------------------------------
16072 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
16073 Modification_Comes_From_Source : constant Boolean :=
16074 Comes_From_Source (Parent (N));
16080 -- Loop to find referenced entity, if there is one
16086 if Is_Entity_Name (Exp) then
16087 Ent := Entity (Exp);
16089 -- If the entity is missing, it is an undeclared identifier,
16090 -- and there is nothing to annotate.
16096 elsif Nkind (Exp) = N_Explicit_Dereference then
16098 P : constant Node_Id := Prefix (Exp);
16101 -- In formal verification mode, keep track of all reads and
16102 -- writes through explicit dereferences.
16104 if GNATprove_Mode then
16105 SPARK_Specific.Generate_Dereference (N, 'm');
16108 if Nkind (P) = N_Selected_Component
16109 and then Present (Entry_Formal (Entity (Selector_Name (P))))
16111 -- Case of a reference to an entry formal
16113 Ent := Entry_Formal (Entity (Selector_Name (P)));
16115 elsif Nkind (P) = N_Identifier
16116 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
16117 and then Present (Expression (Parent (Entity (P))))
16118 and then Nkind (Expression (Parent (Entity (P)))) =
16121 -- Case of a reference to a value on which side effects have
16124 Exp := Prefix (Expression (Parent (Entity (P))));
16132 elsif Nkind_In (Exp, N_Type_Conversion,
16133 N_Unchecked_Type_Conversion)
16135 Exp := Expression (Exp);
16138 elsif Nkind_In (Exp, N_Slice,
16139 N_Indexed_Component,
16140 N_Selected_Component)
16142 -- Special check, if the prefix is an access type, then return
16143 -- since we are modifying the thing pointed to, not the prefix.
16144 -- When we are expanding, most usually the prefix is replaced
16145 -- by an explicit dereference, and this test is not needed, but
16146 -- in some cases (notably -gnatc mode and generics) when we do
16147 -- not do full expansion, we need this special test.
16149 if Is_Access_Type (Etype (Prefix (Exp))) then
16152 -- Otherwise go to prefix and keep going
16155 Exp := Prefix (Exp);
16159 -- All other cases, not a modification
16165 -- Now look for entity being referenced
16167 if Present (Ent) then
16168 if Is_Object (Ent) then
16169 if Comes_From_Source (Exp)
16170 or else Modification_Comes_From_Source
16172 -- Give warning if pragma unmodified given and we are
16173 -- sure this is a modification.
16175 if Has_Pragma_Unmodified (Ent) and then Sure then
16176 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
16179 Set_Never_Set_In_Source (Ent, False);
16182 Set_Is_True_Constant (Ent, False);
16183 Set_Current_Value (Ent, Empty);
16184 Set_Is_Known_Null (Ent, False);
16186 if not Can_Never_Be_Null (Ent) then
16187 Set_Is_Known_Non_Null (Ent, False);
16190 -- Follow renaming chain
16192 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
16193 and then Present (Renamed_Object (Ent))
16195 Exp := Renamed_Object (Ent);
16197 -- If the entity is the loop variable in an iteration over
16198 -- a container, retrieve container expression to indicate
16199 -- possible modification.
16201 if Present (Related_Expression (Ent))
16202 and then Nkind (Parent (Related_Expression (Ent))) =
16203 N_Iterator_Specification
16205 Exp := Original_Node (Related_Expression (Ent));
16210 -- The expression may be the renaming of a subcomponent of an
16211 -- array or container. The assignment to the subcomponent is
16212 -- a modification of the container.
16214 elsif Comes_From_Source (Original_Node (Exp))
16215 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
16216 N_Indexed_Component)
16218 Exp := Prefix (Original_Node (Exp));
16222 -- Generate a reference only if the assignment comes from
16223 -- source. This excludes, for example, calls to a dispatching
16224 -- assignment operation when the left-hand side is tagged. In
16225 -- GNATprove mode, we need those references also on generated
16226 -- code, as these are used to compute the local effects of
16229 if Modification_Comes_From_Source or GNATprove_Mode then
16230 Generate_Reference (Ent, Exp, 'm');
16232 -- If the target of the assignment is the bound variable
16233 -- in an iterator, indicate that the corresponding array
16234 -- or container is also modified.
16236 if Ada_Version >= Ada_2012
16237 and then Nkind (Parent (Ent)) = N_Iterator_Specification
16240 Domain : constant Node_Id := Name (Parent (Ent));
16243 -- TBD : in the full version of the construct, the
16244 -- domain of iteration can be given by an expression.
16246 if Is_Entity_Name (Domain) then
16247 Generate_Reference (Entity (Domain), Exp, 'm');
16248 Set_Is_True_Constant (Entity (Domain), False);
16249 Set_Never_Set_In_Source (Entity (Domain), False);
16258 -- If we are sure this is a modification from source, and we know
16259 -- this modifies a constant, then give an appropriate warning.
16262 and then Modification_Comes_From_Source
16263 and then Overlays_Constant (Ent)
16264 and then Address_Clause_Overlay_Warnings
16267 Addr : constant Node_Id := Address_Clause (Ent);
16272 Find_Overlaid_Entity (Addr, O_Ent, Off);
16274 Error_Msg_Sloc := Sloc (Addr);
16276 ("??constant& may be modified via address clause#",
16287 end Note_Possible_Modification;
16289 -------------------------
16290 -- Object_Access_Level --
16291 -------------------------
16293 -- Returns the static accessibility level of the view denoted by Obj. Note
16294 -- that the value returned is the result of a call to Scope_Depth. Only
16295 -- scope depths associated with dynamic scopes can actually be returned.
16296 -- Since only relative levels matter for accessibility checking, the fact
16297 -- that the distance between successive levels of accessibility is not
16298 -- always one is immaterial (invariant: if level(E2) is deeper than
16299 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
16301 function Object_Access_Level (Obj : Node_Id) return Uint is
16302 function Is_Interface_Conversion (N : Node_Id) return Boolean;
16303 -- Determine whether N is a construct of the form
16304 -- Some_Type (Operand._tag'Address)
16305 -- This construct appears in the context of dispatching calls.
16307 function Reference_To (Obj : Node_Id) return Node_Id;
16308 -- An explicit dereference is created when removing side-effects from
16309 -- expressions for constraint checking purposes. In this case a local
16310 -- access type is created for it. The correct access level is that of
16311 -- the original source node. We detect this case by noting that the
16312 -- prefix of the dereference is created by an object declaration whose
16313 -- initial expression is a reference.
16315 -----------------------------
16316 -- Is_Interface_Conversion --
16317 -----------------------------
16319 function Is_Interface_Conversion (N : Node_Id) return Boolean is
16321 return Nkind (N) = N_Unchecked_Type_Conversion
16322 and then Nkind (Expression (N)) = N_Attribute_Reference
16323 and then Attribute_Name (Expression (N)) = Name_Address;
16324 end Is_Interface_Conversion;
16330 function Reference_To (Obj : Node_Id) return Node_Id is
16331 Pref : constant Node_Id := Prefix (Obj);
16333 if Is_Entity_Name (Pref)
16334 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
16335 and then Present (Expression (Parent (Entity (Pref))))
16336 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
16338 return (Prefix (Expression (Parent (Entity (Pref)))));
16348 -- Start of processing for Object_Access_Level
16351 if Nkind (Obj) = N_Defining_Identifier
16352 or else Is_Entity_Name (Obj)
16354 if Nkind (Obj) = N_Defining_Identifier then
16360 if Is_Prival (E) then
16361 E := Prival_Link (E);
16364 -- If E is a type then it denotes a current instance. For this case
16365 -- we add one to the normal accessibility level of the type to ensure
16366 -- that current instances are treated as always being deeper than
16367 -- than the level of any visible named access type (see 3.10.2(21)).
16369 if Is_Type (E) then
16370 return Type_Access_Level (E) + 1;
16372 elsif Present (Renamed_Object (E)) then
16373 return Object_Access_Level (Renamed_Object (E));
16375 -- Similarly, if E is a component of the current instance of a
16376 -- protected type, any instance of it is assumed to be at a deeper
16377 -- level than the type. For a protected object (whose type is an
16378 -- anonymous protected type) its components are at the same level
16379 -- as the type itself.
16381 elsif not Is_Overloadable (E)
16382 and then Ekind (Scope (E)) = E_Protected_Type
16383 and then Comes_From_Source (Scope (E))
16385 return Type_Access_Level (Scope (E)) + 1;
16388 -- Aliased formals of functions take their access level from the
16389 -- point of call, i.e. require a dynamic check. For static check
16390 -- purposes, this is smaller than the level of the subprogram
16391 -- itself. For procedures the aliased makes no difference.
16394 and then Is_Aliased (E)
16395 and then Ekind (Scope (E)) = E_Function
16397 return Type_Access_Level (Etype (E));
16400 return Scope_Depth (Enclosing_Dynamic_Scope (E));
16404 elsif Nkind (Obj) = N_Selected_Component then
16405 if Is_Access_Type (Etype (Prefix (Obj))) then
16406 return Type_Access_Level (Etype (Prefix (Obj)));
16408 return Object_Access_Level (Prefix (Obj));
16411 elsif Nkind (Obj) = N_Indexed_Component then
16412 if Is_Access_Type (Etype (Prefix (Obj))) then
16413 return Type_Access_Level (Etype (Prefix (Obj)));
16415 return Object_Access_Level (Prefix (Obj));
16418 elsif Nkind (Obj) = N_Explicit_Dereference then
16420 -- If the prefix is a selected access discriminant then we make a
16421 -- recursive call on the prefix, which will in turn check the level
16422 -- of the prefix object of the selected discriminant.
16424 -- In Ada 2012, if the discriminant has implicit dereference and
16425 -- the context is a selected component, treat this as an object of
16426 -- unknown scope (see below). This is necessary in compile-only mode;
16427 -- otherwise expansion will already have transformed the prefix into
16430 if Nkind (Prefix (Obj)) = N_Selected_Component
16431 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
16433 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
16435 (not Has_Implicit_Dereference
16436 (Entity (Selector_Name (Prefix (Obj))))
16437 or else Nkind (Parent (Obj)) /= N_Selected_Component)
16439 return Object_Access_Level (Prefix (Obj));
16441 -- Detect an interface conversion in the context of a dispatching
16442 -- call. Use the original form of the conversion to find the access
16443 -- level of the operand.
16445 elsif Is_Interface (Etype (Obj))
16446 and then Is_Interface_Conversion (Prefix (Obj))
16447 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
16449 return Object_Access_Level (Original_Node (Obj));
16451 elsif not Comes_From_Source (Obj) then
16453 Ref : constant Node_Id := Reference_To (Obj);
16455 if Present (Ref) then
16456 return Object_Access_Level (Ref);
16458 return Type_Access_Level (Etype (Prefix (Obj)));
16463 return Type_Access_Level (Etype (Prefix (Obj)));
16466 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
16467 return Object_Access_Level (Expression (Obj));
16469 elsif Nkind (Obj) = N_Function_Call then
16471 -- Function results are objects, so we get either the access level of
16472 -- the function or, in the case of an indirect call, the level of the
16473 -- access-to-subprogram type. (This code is used for Ada 95, but it
16474 -- looks wrong, because it seems that we should be checking the level
16475 -- of the call itself, even for Ada 95. However, using the Ada 2005
16476 -- version of the code causes regressions in several tests that are
16477 -- compiled with -gnat95. ???)
16479 if Ada_Version < Ada_2005 then
16480 if Is_Entity_Name (Name (Obj)) then
16481 return Subprogram_Access_Level (Entity (Name (Obj)));
16483 return Type_Access_Level (Etype (Prefix (Name (Obj))));
16486 -- For Ada 2005, the level of the result object of a function call is
16487 -- defined to be the level of the call's innermost enclosing master.
16488 -- We determine that by querying the depth of the innermost enclosing
16492 Return_Master_Scope_Depth_Of_Call : declare
16494 function Innermost_Master_Scope_Depth
16495 (N : Node_Id) return Uint;
16496 -- Returns the scope depth of the given node's innermost
16497 -- enclosing dynamic scope (effectively the accessibility
16498 -- level of the innermost enclosing master).
16500 ----------------------------------
16501 -- Innermost_Master_Scope_Depth --
16502 ----------------------------------
16504 function Innermost_Master_Scope_Depth
16505 (N : Node_Id) return Uint
16507 Node_Par : Node_Id := Parent (N);
16510 -- Locate the nearest enclosing node (by traversing Parents)
16511 -- that Defining_Entity can be applied to, and return the
16512 -- depth of that entity's nearest enclosing dynamic scope.
16514 while Present (Node_Par) loop
16515 case Nkind (Node_Par) is
16516 when N_Component_Declaration |
16517 N_Entry_Declaration |
16518 N_Formal_Object_Declaration |
16519 N_Formal_Type_Declaration |
16520 N_Full_Type_Declaration |
16521 N_Incomplete_Type_Declaration |
16522 N_Loop_Parameter_Specification |
16523 N_Object_Declaration |
16524 N_Protected_Type_Declaration |
16525 N_Private_Extension_Declaration |
16526 N_Private_Type_Declaration |
16527 N_Subtype_Declaration |
16528 N_Function_Specification |
16529 N_Procedure_Specification |
16530 N_Task_Type_Declaration |
16532 N_Generic_Instantiation |
16534 N_Implicit_Label_Declaration |
16535 N_Package_Declaration |
16536 N_Single_Task_Declaration |
16537 N_Subprogram_Declaration |
16538 N_Generic_Declaration |
16539 N_Renaming_Declaration |
16540 N_Block_Statement |
16541 N_Formal_Subprogram_Declaration |
16542 N_Abstract_Subprogram_Declaration |
16544 N_Exception_Declaration |
16545 N_Formal_Package_Declaration |
16546 N_Number_Declaration |
16547 N_Package_Specification |
16548 N_Parameter_Specification |
16549 N_Single_Protected_Declaration |
16553 (Nearest_Dynamic_Scope
16554 (Defining_Entity (Node_Par)));
16560 Node_Par := Parent (Node_Par);
16563 pragma Assert (False);
16565 -- Should never reach the following return
16567 return Scope_Depth (Current_Scope) + 1;
16568 end Innermost_Master_Scope_Depth;
16570 -- Start of processing for Return_Master_Scope_Depth_Of_Call
16573 return Innermost_Master_Scope_Depth (Obj);
16574 end Return_Master_Scope_Depth_Of_Call;
16577 -- For convenience we handle qualified expressions, even though they
16578 -- aren't technically object names.
16580 elsif Nkind (Obj) = N_Qualified_Expression then
16581 return Object_Access_Level (Expression (Obj));
16583 -- Ditto for aggregates. They have the level of the temporary that
16584 -- will hold their value.
16586 elsif Nkind (Obj) = N_Aggregate then
16587 return Object_Access_Level (Current_Scope);
16589 -- Otherwise return the scope level of Standard. (If there are cases
16590 -- that fall through to this point they will be treated as having
16591 -- global accessibility for now. ???)
16594 return Scope_Depth (Standard_Standard);
16596 end Object_Access_Level;
16598 ---------------------------------
16599 -- Original_Aspect_Pragma_Name --
16600 ---------------------------------
16602 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
16604 Item_Nam : Name_Id;
16607 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
16611 -- The pragma was generated to emulate an aspect, use the original
16612 -- aspect specification.
16614 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
16615 Item := Corresponding_Aspect (Item);
16618 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
16619 -- Post and Post_Class rewrite their pragma identifier to preserve the
16621 -- ??? this is kludgey
16623 if Nkind (Item) = N_Pragma then
16624 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
16627 pragma Assert (Nkind (Item) = N_Aspect_Specification);
16628 Item_Nam := Chars (Identifier (Item));
16631 -- Deal with 'Class by converting the name to its _XXX form
16633 if Class_Present (Item) then
16634 if Item_Nam = Name_Invariant then
16635 Item_Nam := Name_uInvariant;
16637 elsif Item_Nam = Name_Post then
16638 Item_Nam := Name_uPost;
16640 elsif Item_Nam = Name_Pre then
16641 Item_Nam := Name_uPre;
16643 elsif Nam_In (Item_Nam, Name_Type_Invariant,
16644 Name_Type_Invariant_Class)
16646 Item_Nam := Name_uType_Invariant;
16648 -- Nothing to do for other cases (e.g. a Check that derived from
16649 -- Pre_Class and has the flag set). Also we do nothing if the name
16650 -- is already in special _xxx form.
16656 end Original_Aspect_Pragma_Name;
16658 --------------------------------------
16659 -- Original_Corresponding_Operation --
16660 --------------------------------------
16662 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
16664 Typ : constant Entity_Id := Find_Dispatching_Type (S);
16667 -- If S is an inherited primitive S2 the original corresponding
16668 -- operation of S is the original corresponding operation of S2
16670 if Present (Alias (S))
16671 and then Find_Dispatching_Type (Alias (S)) /= Typ
16673 return Original_Corresponding_Operation (Alias (S));
16675 -- If S overrides an inherited subprogram S2 the original corresponding
16676 -- operation of S is the original corresponding operation of S2
16678 elsif Present (Overridden_Operation (S)) then
16679 return Original_Corresponding_Operation (Overridden_Operation (S));
16681 -- otherwise it is S itself
16686 end Original_Corresponding_Operation;
16688 ----------------------
16689 -- Policy_In_Effect --
16690 ----------------------
16692 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
16693 function Policy_In_List (List : Node_Id) return Name_Id;
16694 -- Determine the mode of a policy in a N_Pragma list
16696 --------------------
16697 -- Policy_In_List --
16698 --------------------
16700 function Policy_In_List (List : Node_Id) return Name_Id is
16707 while Present (Prag) loop
16708 Arg1 := First (Pragma_Argument_Associations (Prag));
16709 Arg2 := Next (Arg1);
16711 Arg1 := Get_Pragma_Arg (Arg1);
16712 Arg2 := Get_Pragma_Arg (Arg2);
16714 -- The current Check_Policy pragma matches the requested policy or
16715 -- appears in the single argument form (Assertion, policy_id).
16717 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
16718 return Chars (Arg2);
16721 Prag := Next_Pragma (Prag);
16725 end Policy_In_List;
16731 -- Start of processing for Policy_In_Effect
16734 if not Is_Valid_Assertion_Kind (Policy) then
16735 raise Program_Error;
16738 -- Inspect all policy pragmas that appear within scopes (if any)
16740 Kind := Policy_In_List (Check_Policy_List);
16742 -- Inspect all configuration policy pragmas (if any)
16744 if Kind = No_Name then
16745 Kind := Policy_In_List (Check_Policy_List_Config);
16748 -- The context lacks policy pragmas, determine the mode based on whether
16749 -- assertions are enabled at the configuration level. This ensures that
16750 -- the policy is preserved when analyzing generics.
16752 if Kind = No_Name then
16753 if Assertions_Enabled_Config then
16754 Kind := Name_Check;
16756 Kind := Name_Ignore;
16761 end Policy_In_Effect;
16763 ----------------------------------
16764 -- Predicate_Tests_On_Arguments --
16765 ----------------------------------
16767 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
16769 -- Always test predicates on indirect call
16771 if Ekind (Subp) = E_Subprogram_Type then
16774 -- Do not test predicates on call to generated default Finalize, since
16775 -- we are not interested in whether something we are finalizing (and
16776 -- typically destroying) satisfies its predicates.
16778 elsif Chars (Subp) = Name_Finalize
16779 and then not Comes_From_Source (Subp)
16783 -- Do not test predicates on any internally generated routines
16785 elsif Is_Internal_Name (Chars (Subp)) then
16788 -- Do not test predicates on call to Init_Proc, since if needed the
16789 -- predicate test will occur at some other point.
16791 elsif Is_Init_Proc (Subp) then
16794 -- Do not test predicates on call to predicate function, since this
16795 -- would cause infinite recursion.
16797 elsif Ekind (Subp) = E_Function
16798 and then (Is_Predicate_Function (Subp)
16800 Is_Predicate_Function_M (Subp))
16804 -- For now, no other exceptions
16809 end Predicate_Tests_On_Arguments;
16811 -----------------------
16812 -- Private_Component --
16813 -----------------------
16815 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
16816 Ancestor : constant Entity_Id := Base_Type (Type_Id);
16818 function Trace_Components
16820 Check : Boolean) return Entity_Id;
16821 -- Recursive function that does the work, and checks against circular
16822 -- definition for each subcomponent type.
16824 ----------------------
16825 -- Trace_Components --
16826 ----------------------
16828 function Trace_Components
16830 Check : Boolean) return Entity_Id
16832 Btype : constant Entity_Id := Base_Type (T);
16833 Component : Entity_Id;
16835 Candidate : Entity_Id := Empty;
16838 if Check and then Btype = Ancestor then
16839 Error_Msg_N ("circular type definition", Type_Id);
16843 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
16844 if Present (Full_View (Btype))
16845 and then Is_Record_Type (Full_View (Btype))
16846 and then not Is_Frozen (Btype)
16848 -- To indicate that the ancestor depends on a private type, the
16849 -- current Btype is sufficient. However, to check for circular
16850 -- definition we must recurse on the full view.
16852 Candidate := Trace_Components (Full_View (Btype), True);
16854 if Candidate = Any_Type then
16864 elsif Is_Array_Type (Btype) then
16865 return Trace_Components (Component_Type (Btype), True);
16867 elsif Is_Record_Type (Btype) then
16868 Component := First_Entity (Btype);
16869 while Present (Component)
16870 and then Comes_From_Source (Component)
16872 -- Skip anonymous types generated by constrained components
16874 if not Is_Type (Component) then
16875 P := Trace_Components (Etype (Component), True);
16877 if Present (P) then
16878 if P = Any_Type then
16886 Next_Entity (Component);
16894 end Trace_Components;
16896 -- Start of processing for Private_Component
16899 return Trace_Components (Type_Id, False);
16900 end Private_Component;
16902 ---------------------------
16903 -- Primitive_Names_Match --
16904 ---------------------------
16906 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
16908 function Non_Internal_Name (E : Entity_Id) return Name_Id;
16909 -- Given an internal name, returns the corresponding non-internal name
16911 ------------------------
16912 -- Non_Internal_Name --
16913 ------------------------
16915 function Non_Internal_Name (E : Entity_Id) return Name_Id is
16917 Get_Name_String (Chars (E));
16918 Name_Len := Name_Len - 1;
16920 end Non_Internal_Name;
16922 -- Start of processing for Primitive_Names_Match
16925 pragma Assert (Present (E1) and then Present (E2));
16927 return Chars (E1) = Chars (E2)
16929 (not Is_Internal_Name (Chars (E1))
16930 and then Is_Internal_Name (Chars (E2))
16931 and then Non_Internal_Name (E2) = Chars (E1))
16933 (not Is_Internal_Name (Chars (E2))
16934 and then Is_Internal_Name (Chars (E1))
16935 and then Non_Internal_Name (E1) = Chars (E2))
16937 (Is_Predefined_Dispatching_Operation (E1)
16938 and then Is_Predefined_Dispatching_Operation (E2)
16939 and then Same_TSS (E1, E2))
16941 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
16942 end Primitive_Names_Match;
16944 -----------------------
16945 -- Process_End_Label --
16946 -----------------------
16948 procedure Process_End_Label
16957 Label_Ref : Boolean;
16958 -- Set True if reference to end label itself is required
16961 -- Gets set to the operator symbol or identifier that references the
16962 -- entity Ent. For the child unit case, this is the identifier from the
16963 -- designator. For other cases, this is simply Endl.
16965 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
16966 -- N is an identifier node that appears as a parent unit reference in
16967 -- the case where Ent is a child unit. This procedure generates an
16968 -- appropriate cross-reference entry. E is the corresponding entity.
16970 -------------------------
16971 -- Generate_Parent_Ref --
16972 -------------------------
16974 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
16976 -- If names do not match, something weird, skip reference
16978 if Chars (E) = Chars (N) then
16980 -- Generate the reference. We do NOT consider this as a reference
16981 -- for unreferenced symbol purposes.
16983 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
16985 if Style_Check then
16986 Style.Check_Identifier (N, E);
16989 end Generate_Parent_Ref;
16991 -- Start of processing for Process_End_Label
16994 -- If no node, ignore. This happens in some error situations, and
16995 -- also for some internally generated structures where no end label
16996 -- references are required in any case.
17002 -- Nothing to do if no End_Label, happens for internally generated
17003 -- constructs where we don't want an end label reference anyway. Also
17004 -- nothing to do if Endl is a string literal, which means there was
17005 -- some prior error (bad operator symbol)
17007 Endl := End_Label (N);
17009 if No (Endl) or else Nkind (Endl) = N_String_Literal then
17013 -- Reference node is not in extended main source unit
17015 if not In_Extended_Main_Source_Unit (N) then
17017 -- Generally we do not collect references except for the extended
17018 -- main source unit. The one exception is the 'e' entry for a
17019 -- package spec, where it is useful for a client to have the
17020 -- ending information to define scopes.
17026 Label_Ref := False;
17028 -- For this case, we can ignore any parent references, but we
17029 -- need the package name itself for the 'e' entry.
17031 if Nkind (Endl) = N_Designator then
17032 Endl := Identifier (Endl);
17036 -- Reference is in extended main source unit
17041 -- For designator, generate references for the parent entries
17043 if Nkind (Endl) = N_Designator then
17045 -- Generate references for the prefix if the END line comes from
17046 -- source (otherwise we do not need these references) We climb the
17047 -- scope stack to find the expected entities.
17049 if Comes_From_Source (Endl) then
17050 Nam := Name (Endl);
17051 Scop := Current_Scope;
17052 while Nkind (Nam) = N_Selected_Component loop
17053 Scop := Scope (Scop);
17054 exit when No (Scop);
17055 Generate_Parent_Ref (Selector_Name (Nam), Scop);
17056 Nam := Prefix (Nam);
17059 if Present (Scop) then
17060 Generate_Parent_Ref (Nam, Scope (Scop));
17064 Endl := Identifier (Endl);
17068 -- If the end label is not for the given entity, then either we have
17069 -- some previous error, or this is a generic instantiation for which
17070 -- we do not need to make a cross-reference in this case anyway. In
17071 -- either case we simply ignore the call.
17073 if Chars (Ent) /= Chars (Endl) then
17077 -- If label was really there, then generate a normal reference and then
17078 -- adjust the location in the end label to point past the name (which
17079 -- should almost always be the semicolon).
17081 Loc := Sloc (Endl);
17083 if Comes_From_Source (Endl) then
17085 -- If a label reference is required, then do the style check and
17086 -- generate an l-type cross-reference entry for the label
17089 if Style_Check then
17090 Style.Check_Identifier (Endl, Ent);
17093 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
17096 -- Set the location to point past the label (normally this will
17097 -- mean the semicolon immediately following the label). This is
17098 -- done for the sake of the 'e' or 't' entry generated below.
17100 Get_Decoded_Name_String (Chars (Endl));
17101 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
17104 -- In SPARK mode, no missing label is allowed for packages and
17105 -- subprogram bodies. Detect those cases by testing whether
17106 -- Process_End_Label was called for a body (Typ = 't') or a package.
17108 if Restriction_Check_Required (SPARK_05)
17109 and then (Typ = 't' or else Ekind (Ent) = E_Package)
17111 Error_Msg_Node_1 := Endl;
17112 Check_SPARK_05_Restriction
17113 ("`END &` required", Endl, Force => True);
17117 -- Now generate the e/t reference
17119 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
17121 -- Restore Sloc, in case modified above, since we have an identifier
17122 -- and the normal Sloc should be left set in the tree.
17124 Set_Sloc (Endl, Loc);
17125 end Process_End_Label;
17131 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
17132 Seen : Boolean := False;
17134 function Is_Reference (N : Node_Id) return Traverse_Result;
17135 -- Determine whether node N denotes a reference to Id. If this is the
17136 -- case, set global flag Seen to True and stop the traversal.
17142 function Is_Reference (N : Node_Id) return Traverse_Result is
17144 if Is_Entity_Name (N)
17145 and then Present (Entity (N))
17146 and then Entity (N) = Id
17155 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
17157 -- Start of processing for Referenced
17160 Inspect_Expression (Expr);
17164 ------------------------------------
17165 -- References_Generic_Formal_Type --
17166 ------------------------------------
17168 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
17170 function Process (N : Node_Id) return Traverse_Result;
17171 -- Process one node in search for generic formal type
17177 function Process (N : Node_Id) return Traverse_Result is
17179 if Nkind (N) in N_Has_Entity then
17181 E : constant Entity_Id := Entity (N);
17183 if Present (E) then
17184 if Is_Generic_Type (E) then
17186 elsif Present (Etype (E))
17187 and then Is_Generic_Type (Etype (E))
17198 function Traverse is new Traverse_Func (Process);
17199 -- Traverse tree to look for generic type
17202 if Inside_A_Generic then
17203 return Traverse (N) = Abandon;
17207 end References_Generic_Formal_Type;
17209 --------------------
17210 -- Remove_Homonym --
17211 --------------------
17213 procedure Remove_Homonym (E : Entity_Id) is
17214 Prev : Entity_Id := Empty;
17218 if E = Current_Entity (E) then
17219 if Present (Homonym (E)) then
17220 Set_Current_Entity (Homonym (E));
17222 Set_Name_Entity_Id (Chars (E), Empty);
17226 H := Current_Entity (E);
17227 while Present (H) and then H /= E loop
17232 -- If E is not on the homonym chain, nothing to do
17234 if Present (H) then
17235 Set_Homonym (Prev, Homonym (E));
17238 end Remove_Homonym;
17240 ------------------------------
17241 -- Remove_Overloaded_Entity --
17242 ------------------------------
17244 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
17245 procedure Remove_Primitive_Of (Typ : Entity_Id);
17246 -- Remove primitive subprogram Id from the list of primitives that
17247 -- belong to type Typ.
17249 -------------------------
17250 -- Remove_Primitive_Of --
17251 -------------------------
17253 procedure Remove_Primitive_Of (Typ : Entity_Id) is
17257 if Is_Tagged_Type (Typ) then
17258 Prims := Direct_Primitive_Operations (Typ);
17260 if Present (Prims) then
17261 Remove (Prims, Id);
17264 end Remove_Primitive_Of;
17268 Scop : constant Entity_Id := Scope (Id);
17269 Formal : Entity_Id;
17270 Prev_Id : Entity_Id;
17272 -- Start of processing for Remove_Overloaded_Entity
17275 -- Remove the entity from the homonym chain. When the entity is the
17276 -- head of the chain, associate the entry in the name table with its
17277 -- homonym effectively making it the new head of the chain.
17279 if Current_Entity (Id) = Id then
17280 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
17282 -- Otherwise link the previous and next homonyms
17285 Prev_Id := Current_Entity (Id);
17286 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
17287 Prev_Id := Homonym (Prev_Id);
17290 Set_Homonym (Prev_Id, Homonym (Id));
17293 -- Remove the entity from the scope entity chain. When the entity is
17294 -- the head of the chain, set the next entity as the new head of the
17297 if First_Entity (Scop) = Id then
17299 Set_First_Entity (Scop, Next_Entity (Id));
17301 -- Otherwise the entity is either in the middle of the chain or it acts
17302 -- as its tail. Traverse and link the previous and next entities.
17305 Prev_Id := First_Entity (Scop);
17306 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
17307 Next_Entity (Prev_Id);
17310 Set_Next_Entity (Prev_Id, Next_Entity (Id));
17313 -- Handle the case where the entity acts as the tail of the scope entity
17316 if Last_Entity (Scop) = Id then
17317 Set_Last_Entity (Scop, Prev_Id);
17320 -- The entity denotes a primitive subprogram. Remove it from the list of
17321 -- primitives of the associated controlling type.
17323 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
17324 Formal := First_Formal (Id);
17325 while Present (Formal) loop
17326 if Is_Controlling_Formal (Formal) then
17327 Remove_Primitive_Of (Etype (Formal));
17331 Next_Formal (Formal);
17334 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
17335 Remove_Primitive_Of (Etype (Id));
17338 end Remove_Overloaded_Entity;
17340 ---------------------
17341 -- Rep_To_Pos_Flag --
17342 ---------------------
17344 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
17346 return New_Occurrence_Of
17347 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
17348 end Rep_To_Pos_Flag;
17350 -------------------------------
17351 -- Report_Unused_Body_States --
17352 -------------------------------
17354 procedure Report_Unused_Body_States
17355 (Body_Id : Entity_Id;
17358 Posted : Boolean := False;
17359 State_Elmt : Elmt_Id;
17360 State_Id : Entity_Id;
17363 if Present (States) then
17364 State_Elmt := First_Elmt (States);
17365 while Present (State_Elmt) loop
17366 State_Id := Node (State_Elmt);
17368 -- Constants are part of the hidden state of a package, but the
17369 -- compiler cannot determine whether they have variable input
17370 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
17371 -- hidden state. Do not emit an error when a constant does not
17372 -- participate in a state refinement, even though it acts as a
17375 if Ekind (State_Id) = E_Constant then
17378 -- Generate an error message of the form:
17380 -- body of package ... has unused hidden states
17381 -- abstract state ... defined at ...
17382 -- variable ... defined at ...
17388 ("body of package & has unused hidden states", Body_Id);
17391 Error_Msg_Sloc := Sloc (State_Id);
17393 if Ekind (State_Id) = E_Abstract_State then
17395 ("\abstract state & defined #", Body_Id, State_Id);
17398 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
17402 Next_Elmt (State_Elmt);
17405 end Report_Unused_Body_States;
17407 --------------------
17408 -- Require_Entity --
17409 --------------------
17411 procedure Require_Entity (N : Node_Id) is
17413 if Is_Entity_Name (N) and then No (Entity (N)) then
17414 if Total_Errors_Detected /= 0 then
17415 Set_Entity (N, Any_Id);
17417 raise Program_Error;
17420 end Require_Entity;
17422 -------------------------------
17423 -- Requires_State_Refinement --
17424 -------------------------------
17426 function Requires_State_Refinement
17427 (Spec_Id : Entity_Id;
17428 Body_Id : Entity_Id) return Boolean
17430 function Mode_Is_Off (Prag : Node_Id) return Boolean;
17431 -- Given pragma SPARK_Mode, determine whether the mode is Off
17437 function Mode_Is_Off (Prag : Node_Id) return Boolean is
17441 -- The default SPARK mode is On
17447 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
17449 -- Then the pragma lacks an argument, the default mode is On
17454 return Chars (Mode) = Name_Off;
17458 -- Start of processing for Requires_State_Refinement
17461 -- A package that does not define at least one abstract state cannot
17462 -- possibly require refinement.
17464 if No (Abstract_States (Spec_Id)) then
17467 -- The package instroduces a single null state which does not merit
17470 elsif Has_Null_Abstract_State (Spec_Id) then
17473 -- Check whether the package body is subject to pragma SPARK_Mode. If
17474 -- it is and the mode is Off, the package body is considered to be in
17475 -- regular Ada and does not require refinement.
17477 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
17480 -- The body's SPARK_Mode may be inherited from a similar pragma that
17481 -- appears in the private declarations of the spec. The pragma we are
17482 -- interested appears as the second entry in SPARK_Pragma.
17484 elsif Present (SPARK_Pragma (Spec_Id))
17485 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
17489 -- The spec defines at least one abstract state and the body has no way
17490 -- of circumventing the refinement.
17495 end Requires_State_Refinement;
17497 ------------------------------
17498 -- Requires_Transient_Scope --
17499 ------------------------------
17501 -- A transient scope is required when variable-sized temporaries are
17502 -- allocated on the secondary stack, or when finalization actions must be
17503 -- generated before the next instruction.
17505 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17506 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17507 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
17508 -- the time being. New_Requires_Transient_Scope is used by default; the
17509 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
17510 -- instead. The intent is to use this temporarily to measure before/after
17511 -- efficiency. Note: when this temporary code is removed, the documentation
17512 -- of dQ in debug.adb should be removed.
17514 procedure Results_Differ (Id : Entity_Id);
17515 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
17516 -- removed when New_Requires_Transient_Scope becomes
17517 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
17519 procedure Results_Differ (Id : Entity_Id) is
17521 if False then -- False to disable; True for debugging
17522 Treepr.Print_Tree_Node (Id);
17524 if Old_Requires_Transient_Scope (Id) =
17525 New_Requires_Transient_Scope (Id)
17527 raise Program_Error;
17530 end Results_Differ;
17532 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17533 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
17536 if Debug_Flag_QQ then
17541 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
17544 -- Assert that we're not putting things on the secondary stack if we
17545 -- didn't before; we are trying to AVOID secondary stack when
17548 if not Old_Result then
17549 pragma Assert (not New_Result);
17553 if New_Result /= Old_Result then
17554 Results_Differ (Id);
17559 end Requires_Transient_Scope;
17561 ----------------------------------
17562 -- Old_Requires_Transient_Scope --
17563 ----------------------------------
17565 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17566 Typ : constant Entity_Id := Underlying_Type (Id);
17569 -- This is a private type which is not completed yet. This can only
17570 -- happen in a default expression (of a formal parameter or of a
17571 -- record component). Do not expand transient scope in this case.
17576 -- Do not expand transient scope for non-existent procedure return
17578 elsif Typ = Standard_Void_Type then
17581 -- Elementary types do not require a transient scope
17583 elsif Is_Elementary_Type (Typ) then
17586 -- Generally, indefinite subtypes require a transient scope, since the
17587 -- back end cannot generate temporaries, since this is not a valid type
17588 -- for declaring an object. It might be possible to relax this in the
17589 -- future, e.g. by declaring the maximum possible space for the type.
17591 elsif not Is_Definite_Subtype (Typ) then
17594 -- Functions returning tagged types may dispatch on result so their
17595 -- returned value is allocated on the secondary stack. Controlled
17596 -- type temporaries need finalization.
17598 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17603 elsif Is_Record_Type (Typ) then
17608 Comp := First_Entity (Typ);
17609 while Present (Comp) loop
17610 if Ekind (Comp) = E_Component then
17612 -- ???It's not clear we need a full recursive call to
17613 -- Old_Requires_Transient_Scope here. Note that the
17614 -- following can't happen.
17616 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
17617 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
17619 if Old_Requires_Transient_Scope (Etype (Comp)) then
17624 Next_Entity (Comp);
17630 -- String literal types never require transient scope
17632 elsif Ekind (Typ) = E_String_Literal_Subtype then
17635 -- Array type. Note that we already know that this is a constrained
17636 -- array, since unconstrained arrays will fail the indefinite test.
17638 elsif Is_Array_Type (Typ) then
17640 -- If component type requires a transient scope, the array does too
17642 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
17645 -- Otherwise, we only need a transient scope if the size depends on
17646 -- the value of one or more discriminants.
17649 return Size_Depends_On_Discriminant (Typ);
17652 -- All other cases do not require a transient scope
17655 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
17658 end Old_Requires_Transient_Scope;
17660 ----------------------------------
17661 -- New_Requires_Transient_Scope --
17662 ----------------------------------
17664 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17666 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17667 -- This is called for untagged records and protected types, with
17668 -- nondefaulted discriminants. Returns True if the size of function
17669 -- results is known at the call site, False otherwise. Returns False
17670 -- if there is a variant part that depends on the discriminants of
17671 -- this type, or if there is an array constrained by the discriminants
17672 -- of this type. ???Currently, this is overly conservative (the array
17673 -- could be nested inside some other record that is constrained by
17674 -- nondiscriminants). That is, the recursive calls are too conservative.
17676 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17677 -- Returns True if Typ is a nonlimited record with defaulted
17678 -- discriminants whose max size makes it unsuitable for allocating on
17679 -- the primary stack.
17681 ------------------------------
17682 -- Caller_Known_Size_Record --
17683 ------------------------------
17685 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17686 pragma Assert (Typ = Underlying_Type (Typ));
17689 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17697 Comp := First_Entity (Typ);
17698 while Present (Comp) loop
17700 -- Only look at E_Component entities. No need to look at
17701 -- E_Discriminant entities, and we must ignore internal
17702 -- subtypes generated for constrained components.
17704 if Ekind (Comp) = E_Component then
17706 Comp_Type : constant Entity_Id :=
17707 Underlying_Type (Etype (Comp));
17710 if Is_Record_Type (Comp_Type)
17712 Is_Protected_Type (Comp_Type)
17714 if not Caller_Known_Size_Record (Comp_Type) then
17718 elsif Is_Array_Type (Comp_Type) then
17719 if Size_Depends_On_Discriminant (Comp_Type) then
17726 Next_Entity (Comp);
17731 end Caller_Known_Size_Record;
17733 ------------------------------
17734 -- Large_Max_Size_Mutable --
17735 ------------------------------
17737 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17738 pragma Assert (Typ = Underlying_Type (Typ));
17740 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17741 -- Returns true if the discrete type T has a large range
17743 ----------------------------
17744 -- Is_Large_Discrete_Type --
17745 ----------------------------
17747 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17748 Threshold : constant Int := 16;
17749 -- Arbitrary threshold above which we consider it "large". We want
17750 -- a fairly large threshold, because these large types really
17751 -- shouldn't have default discriminants in the first place, in
17755 return UI_To_Int (RM_Size (T)) > Threshold;
17756 end Is_Large_Discrete_Type;
17759 if Is_Record_Type (Typ)
17760 and then not Is_Limited_View (Typ)
17761 and then Has_Defaulted_Discriminants (Typ)
17763 -- Loop through the components, looking for an array whose upper
17764 -- bound(s) depends on discriminants, where both the subtype of
17765 -- the discriminant and the index subtype are too large.
17771 Comp := First_Entity (Typ);
17772 while Present (Comp) loop
17773 if Ekind (Comp) = E_Component then
17775 Comp_Type : constant Entity_Id :=
17776 Underlying_Type (Etype (Comp));
17782 if Is_Array_Type (Comp_Type) then
17783 Indx := First_Index (Comp_Type);
17785 while Present (Indx) loop
17786 Ityp := Etype (Indx);
17787 Hi := Type_High_Bound (Ityp);
17789 if Nkind (Hi) = N_Identifier
17790 and then Ekind (Entity (Hi)) = E_Discriminant
17791 and then Is_Large_Discrete_Type (Ityp)
17792 and then Is_Large_Discrete_Type
17793 (Etype (Entity (Hi)))
17804 Next_Entity (Comp);
17810 end Large_Max_Size_Mutable;
17812 -- Local declarations
17814 Typ : constant Entity_Id := Underlying_Type (Id);
17816 -- Start of processing for New_Requires_Transient_Scope
17819 -- This is a private type which is not completed yet. This can only
17820 -- happen in a default expression (of a formal parameter or of a
17821 -- record component). Do not expand transient scope in this case.
17826 -- Do not expand transient scope for non-existent procedure return or
17827 -- string literal types.
17829 elsif Typ = Standard_Void_Type
17830 or else Ekind (Typ) = E_String_Literal_Subtype
17834 -- If Typ is a generic formal incomplete type, then we want to look at
17835 -- the actual type.
17837 elsif Ekind (Typ) = E_Record_Subtype
17838 and then Present (Cloned_Subtype (Typ))
17840 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
17842 -- Functions returning specific tagged types may dispatch on result, so
17843 -- their returned value is allocated on the secondary stack, even in the
17844 -- definite case. We must treat nondispatching functions the same way,
17845 -- because access-to-function types can point at both, so the calling
17846 -- conventions must be compatible. Is_Tagged_Type includes controlled
17847 -- types and class-wide types. Controlled type temporaries need
17850 -- ???It's not clear why we need to return noncontrolled types with
17851 -- controlled components on the secondary stack.
17853 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17856 -- Untagged definite subtypes are known size. This includes all
17857 -- elementary [sub]types. Tasks are known size even if they have
17858 -- discriminants. So we return False here, with one exception:
17859 -- For a type like:
17860 -- type T (Last : Natural := 0) is
17861 -- X : String (1 .. Last);
17863 -- we return True. That's because for "P(F(...));", where F returns T,
17864 -- we don't know the size of the result at the call site, so if we
17865 -- allocated it on the primary stack, we would have to allocate the
17866 -- maximum size, which is way too big.
17868 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
17869 return Large_Max_Size_Mutable (Typ);
17871 -- Indefinite (discriminated) untagged record or protected type
17873 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
17874 return not Caller_Known_Size_Record (Typ);
17876 -- Unconstrained array
17879 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
17882 end New_Requires_Transient_Scope;
17884 --------------------------
17885 -- Reset_Analyzed_Flags --
17886 --------------------------
17888 procedure Reset_Analyzed_Flags (N : Node_Id) is
17890 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
17891 -- Function used to reset Analyzed flags in tree. Note that we do
17892 -- not reset Analyzed flags in entities, since there is no need to
17893 -- reanalyze entities, and indeed, it is wrong to do so, since it
17894 -- can result in generating auxiliary stuff more than once.
17896 --------------------
17897 -- Clear_Analyzed --
17898 --------------------
17900 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
17902 if not Has_Extension (N) then
17903 Set_Analyzed (N, False);
17907 end Clear_Analyzed;
17909 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
17911 -- Start of processing for Reset_Analyzed_Flags
17914 Reset_Analyzed (N);
17915 end Reset_Analyzed_Flags;
17917 ------------------------
17918 -- Restore_SPARK_Mode --
17919 ------------------------
17921 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
17923 SPARK_Mode := Mode;
17924 end Restore_SPARK_Mode;
17926 --------------------------------
17927 -- Returns_Unconstrained_Type --
17928 --------------------------------
17930 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
17932 return Ekind (Subp) = E_Function
17933 and then not Is_Scalar_Type (Etype (Subp))
17934 and then not Is_Access_Type (Etype (Subp))
17935 and then not Is_Constrained (Etype (Subp));
17936 end Returns_Unconstrained_Type;
17938 ----------------------------
17939 -- Root_Type_Of_Full_View --
17940 ----------------------------
17942 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
17943 Rtyp : constant Entity_Id := Root_Type (T);
17946 -- The root type of the full view may itself be a private type. Keep
17947 -- looking for the ultimate derivation parent.
17949 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
17950 return Root_Type_Of_Full_View (Full_View (Rtyp));
17954 end Root_Type_Of_Full_View;
17956 ---------------------------
17957 -- Safe_To_Capture_Value --
17958 ---------------------------
17960 function Safe_To_Capture_Value
17963 Cond : Boolean := False) return Boolean
17966 -- The only entities for which we track constant values are variables
17967 -- which are not renamings, constants, out parameters, and in out
17968 -- parameters, so check if we have this case.
17970 -- Note: it may seem odd to track constant values for constants, but in
17971 -- fact this routine is used for other purposes than simply capturing
17972 -- the value. In particular, the setting of Known[_Non]_Null.
17974 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
17976 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
17980 -- For conditionals, we also allow loop parameters and all formals,
17981 -- including in parameters.
17983 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
17986 -- For all other cases, not just unsafe, but impossible to capture
17987 -- Current_Value, since the above are the only entities which have
17988 -- Current_Value fields.
17994 -- Skip if volatile or aliased, since funny things might be going on in
17995 -- these cases which we cannot necessarily track. Also skip any variable
17996 -- for which an address clause is given, or whose address is taken. Also
17997 -- never capture value of library level variables (an attempt to do so
17998 -- can occur in the case of package elaboration code).
18000 if Treat_As_Volatile (Ent)
18001 or else Is_Aliased (Ent)
18002 or else Present (Address_Clause (Ent))
18003 or else Address_Taken (Ent)
18004 or else (Is_Library_Level_Entity (Ent)
18005 and then Ekind (Ent) = E_Variable)
18010 -- OK, all above conditions are met. We also require that the scope of
18011 -- the reference be the same as the scope of the entity, not counting
18012 -- packages and blocks and loops.
18015 E_Scope : constant Entity_Id := Scope (Ent);
18016 R_Scope : Entity_Id;
18019 R_Scope := Current_Scope;
18020 while R_Scope /= Standard_Standard loop
18021 exit when R_Scope = E_Scope;
18023 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
18026 R_Scope := Scope (R_Scope);
18031 -- We also require that the reference does not appear in a context
18032 -- where it is not sure to be executed (i.e. a conditional context
18033 -- or an exception handler). We skip this if Cond is True, since the
18034 -- capturing of values from conditional tests handles this ok.
18047 -- Seems dubious that case expressions are not handled here ???
18050 while Present (P) loop
18051 if Nkind (P) = N_If_Statement
18052 or else Nkind (P) = N_Case_Statement
18053 or else (Nkind (P) in N_Short_Circuit
18054 and then Desc = Right_Opnd (P))
18055 or else (Nkind (P) = N_If_Expression
18056 and then Desc /= First (Expressions (P)))
18057 or else Nkind (P) = N_Exception_Handler
18058 or else Nkind (P) = N_Selective_Accept
18059 or else Nkind (P) = N_Conditional_Entry_Call
18060 or else Nkind (P) = N_Timed_Entry_Call
18061 or else Nkind (P) = N_Asynchronous_Select
18069 -- A special Ada 2012 case: the original node may be part
18070 -- of the else_actions of a conditional expression, in which
18071 -- case it might not have been expanded yet, and appears in
18072 -- a non-syntactic list of actions. In that case it is clearly
18073 -- not safe to save a value.
18076 and then Is_List_Member (Desc)
18077 and then No (Parent (List_Containing (Desc)))
18085 -- OK, looks safe to set value
18088 end Safe_To_Capture_Value;
18094 function Same_Name (N1, N2 : Node_Id) return Boolean is
18095 K1 : constant Node_Kind := Nkind (N1);
18096 K2 : constant Node_Kind := Nkind (N2);
18099 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
18100 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
18102 return Chars (N1) = Chars (N2);
18104 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
18105 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
18107 return Same_Name (Selector_Name (N1), Selector_Name (N2))
18108 and then Same_Name (Prefix (N1), Prefix (N2));
18119 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
18120 N1 : constant Node_Id := Original_Node (Node1);
18121 N2 : constant Node_Id := Original_Node (Node2);
18122 -- We do the tests on original nodes, since we are most interested
18123 -- in the original source, not any expansion that got in the way.
18125 K1 : constant Node_Kind := Nkind (N1);
18126 K2 : constant Node_Kind := Nkind (N2);
18129 -- First case, both are entities with same entity
18131 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
18133 EN1 : constant Entity_Id := Entity (N1);
18134 EN2 : constant Entity_Id := Entity (N2);
18136 if Present (EN1) and then Present (EN2)
18137 and then (Ekind_In (EN1, E_Variable, E_Constant)
18138 or else Is_Formal (EN1))
18146 -- Second case, selected component with same selector, same record
18148 if K1 = N_Selected_Component
18149 and then K2 = N_Selected_Component
18150 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
18152 return Same_Object (Prefix (N1), Prefix (N2));
18154 -- Third case, indexed component with same subscripts, same array
18156 elsif K1 = N_Indexed_Component
18157 and then K2 = N_Indexed_Component
18158 and then Same_Object (Prefix (N1), Prefix (N2))
18163 E1 := First (Expressions (N1));
18164 E2 := First (Expressions (N2));
18165 while Present (E1) loop
18166 if not Same_Value (E1, E2) then
18177 -- Fourth case, slice of same array with same bounds
18180 and then K2 = N_Slice
18181 and then Nkind (Discrete_Range (N1)) = N_Range
18182 and then Nkind (Discrete_Range (N2)) = N_Range
18183 and then Same_Value (Low_Bound (Discrete_Range (N1)),
18184 Low_Bound (Discrete_Range (N2)))
18185 and then Same_Value (High_Bound (Discrete_Range (N1)),
18186 High_Bound (Discrete_Range (N2)))
18188 return Same_Name (Prefix (N1), Prefix (N2));
18190 -- All other cases, not clearly the same object
18201 function Same_Type (T1, T2 : Entity_Id) return Boolean is
18206 elsif not Is_Constrained (T1)
18207 and then not Is_Constrained (T2)
18208 and then Base_Type (T1) = Base_Type (T2)
18212 -- For now don't bother with case of identical constraints, to be
18213 -- fiddled with later on perhaps (this is only used for optimization
18214 -- purposes, so it is not critical to do a best possible job)
18225 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
18227 if Compile_Time_Known_Value (Node1)
18228 and then Compile_Time_Known_Value (Node2)
18229 and then Expr_Value (Node1) = Expr_Value (Node2)
18232 elsif Same_Object (Node1, Node2) then
18239 -----------------------------
18240 -- Save_SPARK_Mode_And_Set --
18241 -----------------------------
18243 procedure Save_SPARK_Mode_And_Set
18244 (Context : Entity_Id;
18245 Mode : out SPARK_Mode_Type)
18248 -- Save the current mode in effect
18250 Mode := SPARK_Mode;
18252 -- Do not consider illegal or partially decorated constructs
18254 if Ekind (Context) = E_Void or else Error_Posted (Context) then
18257 elsif Present (SPARK_Pragma (Context)) then
18258 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
18260 end Save_SPARK_Mode_And_Set;
18262 -------------------------
18263 -- Scalar_Part_Present --
18264 -------------------------
18266 function Scalar_Part_Present (T : Entity_Id) return Boolean is
18270 if Is_Scalar_Type (T) then
18273 elsif Is_Array_Type (T) then
18274 return Scalar_Part_Present (Component_Type (T));
18276 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
18277 C := First_Component_Or_Discriminant (T);
18278 while Present (C) loop
18279 if Scalar_Part_Present (Etype (C)) then
18282 Next_Component_Or_Discriminant (C);
18288 end Scalar_Part_Present;
18290 ------------------------
18291 -- Scope_Is_Transient --
18292 ------------------------
18294 function Scope_Is_Transient return Boolean is
18296 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
18297 end Scope_Is_Transient;
18303 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
18308 while Scop /= Standard_Standard loop
18309 Scop := Scope (Scop);
18311 if Scop = Scope2 then
18319 --------------------------
18320 -- Scope_Within_Or_Same --
18321 --------------------------
18323 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
18328 while Scop /= Standard_Standard loop
18329 if Scop = Scope2 then
18332 Scop := Scope (Scop);
18337 end Scope_Within_Or_Same;
18339 --------------------
18340 -- Set_Convention --
18341 --------------------
18343 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
18345 Basic_Set_Convention (E, Val);
18348 and then Is_Access_Subprogram_Type (Base_Type (E))
18349 and then Has_Foreign_Convention (E)
18352 -- A pragma Convention in an instance may apply to the subtype
18353 -- created for a formal, in which case we have already verified
18354 -- that conventions of actual and formal match and there is nothing
18355 -- to flag on the subtype.
18357 if In_Instance then
18360 Set_Can_Use_Internal_Rep (E, False);
18364 -- If E is an object or component, and the type of E is an anonymous
18365 -- access type with no convention set, then also set the convention of
18366 -- the anonymous access type. We do not do this for anonymous protected
18367 -- types, since protected types always have the default convention.
18369 if Present (Etype (E))
18370 and then (Is_Object (E)
18371 or else Ekind (E) = E_Component
18373 -- Allow E_Void (happens for pragma Convention appearing
18374 -- in the middle of a record applying to a component)
18376 or else Ekind (E) = E_Void)
18379 Typ : constant Entity_Id := Etype (E);
18382 if Ekind_In (Typ, E_Anonymous_Access_Type,
18383 E_Anonymous_Access_Subprogram_Type)
18384 and then not Has_Convention_Pragma (Typ)
18386 Basic_Set_Convention (Typ, Val);
18387 Set_Has_Convention_Pragma (Typ);
18389 -- And for the access subprogram type, deal similarly with the
18390 -- designated E_Subprogram_Type if it is also internal (which
18393 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
18395 Dtype : constant Entity_Id := Designated_Type (Typ);
18397 if Ekind (Dtype) = E_Subprogram_Type
18398 and then Is_Itype (Dtype)
18399 and then not Has_Convention_Pragma (Dtype)
18401 Basic_Set_Convention (Dtype, Val);
18402 Set_Has_Convention_Pragma (Dtype);
18409 end Set_Convention;
18411 ------------------------
18412 -- Set_Current_Entity --
18413 ------------------------
18415 -- The given entity is to be set as the currently visible definition of its
18416 -- associated name (i.e. the Node_Id associated with its name). All we have
18417 -- to do is to get the name from the identifier, and then set the
18418 -- associated Node_Id to point to the given entity.
18420 procedure Set_Current_Entity (E : Entity_Id) is
18422 Set_Name_Entity_Id (Chars (E), E);
18423 end Set_Current_Entity;
18425 ---------------------------
18426 -- Set_Debug_Info_Needed --
18427 ---------------------------
18429 procedure Set_Debug_Info_Needed (T : Entity_Id) is
18431 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
18432 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
18433 -- Used to set debug info in a related node if not set already
18435 --------------------------------------
18436 -- Set_Debug_Info_Needed_If_Not_Set --
18437 --------------------------------------
18439 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
18441 if Present (E) and then not Needs_Debug_Info (E) then
18442 Set_Debug_Info_Needed (E);
18444 -- For a private type, indicate that the full view also needs
18445 -- debug information.
18448 and then Is_Private_Type (E)
18449 and then Present (Full_View (E))
18451 Set_Debug_Info_Needed (Full_View (E));
18454 end Set_Debug_Info_Needed_If_Not_Set;
18456 -- Start of processing for Set_Debug_Info_Needed
18459 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
18460 -- indicates that Debug_Info_Needed is never required for the entity.
18461 -- Nothing to do if entity comes from a predefined file. Library files
18462 -- are compiled without debug information, but inlined bodies of these
18463 -- routines may appear in user code, and debug information on them ends
18464 -- up complicating debugging the user code.
18467 or else Debug_Info_Off (T)
18471 elsif In_Inlined_Body
18472 and then Is_Predefined_File_Name
18473 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
18475 Set_Needs_Debug_Info (T, False);
18478 -- Set flag in entity itself. Note that we will go through the following
18479 -- circuitry even if the flag is already set on T. That's intentional,
18480 -- it makes sure that the flag will be set in subsidiary entities.
18482 Set_Needs_Debug_Info (T);
18484 -- Set flag on subsidiary entities if not set already
18486 if Is_Object (T) then
18487 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18489 elsif Is_Type (T) then
18490 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18492 if Is_Record_Type (T) then
18494 Ent : Entity_Id := First_Entity (T);
18496 while Present (Ent) loop
18497 Set_Debug_Info_Needed_If_Not_Set (Ent);
18502 -- For a class wide subtype, we also need debug information
18503 -- for the equivalent type.
18505 if Ekind (T) = E_Class_Wide_Subtype then
18506 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
18509 elsif Is_Array_Type (T) then
18510 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
18513 Indx : Node_Id := First_Index (T);
18515 while Present (Indx) loop
18516 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
18517 Indx := Next_Index (Indx);
18521 -- For a packed array type, we also need debug information for
18522 -- the type used to represent the packed array. Conversely, we
18523 -- also need it for the former if we need it for the latter.
18525 if Is_Packed (T) then
18526 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
18529 if Is_Packed_Array_Impl_Type (T) then
18530 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
18533 elsif Is_Access_Type (T) then
18534 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
18536 elsif Is_Private_Type (T) then
18538 FV : constant Entity_Id := Full_View (T);
18541 Set_Debug_Info_Needed_If_Not_Set (FV);
18543 -- If the full view is itself a derived private type, we need
18544 -- debug information on its underlying type.
18547 and then Is_Private_Type (FV)
18548 and then Present (Underlying_Full_View (FV))
18550 Set_Needs_Debug_Info (Underlying_Full_View (FV));
18554 elsif Is_Protected_Type (T) then
18555 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
18557 elsif Is_Scalar_Type (T) then
18559 -- If the subrange bounds are materialized by dedicated constant
18560 -- objects, also include them in the debug info to make sure the
18561 -- debugger can properly use them.
18563 if Present (Scalar_Range (T))
18564 and then Nkind (Scalar_Range (T)) = N_Range
18567 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
18568 High_Bnd : constant Node_Id := Type_High_Bound (T);
18571 if Is_Entity_Name (Low_Bnd) then
18572 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
18575 if Is_Entity_Name (High_Bnd) then
18576 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
18582 end Set_Debug_Info_Needed;
18584 ----------------------------
18585 -- Set_Entity_With_Checks --
18586 ----------------------------
18588 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
18589 Val_Actual : Entity_Id;
18591 Post_Node : Node_Id;
18594 -- Unconditionally set the entity
18596 Set_Entity (N, Val);
18598 -- The node to post on is the selector in the case of an expanded name,
18599 -- and otherwise the node itself.
18601 if Nkind (N) = N_Expanded_Name then
18602 Post_Node := Selector_Name (N);
18607 -- Check for violation of No_Fixed_IO
18609 if Restriction_Check_Required (No_Fixed_IO)
18611 ((RTU_Loaded (Ada_Text_IO)
18612 and then (Is_RTE (Val, RE_Decimal_IO)
18614 Is_RTE (Val, RE_Fixed_IO)))
18617 (RTU_Loaded (Ada_Wide_Text_IO)
18618 and then (Is_RTE (Val, RO_WT_Decimal_IO)
18620 Is_RTE (Val, RO_WT_Fixed_IO)))
18623 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
18624 and then (Is_RTE (Val, RO_WW_Decimal_IO)
18626 Is_RTE (Val, RO_WW_Fixed_IO))))
18628 -- A special extra check, don't complain about a reference from within
18629 -- the Ada.Interrupts package itself!
18631 and then not In_Same_Extended_Unit (N, Val)
18633 Check_Restriction (No_Fixed_IO, Post_Node);
18636 -- Remaining checks are only done on source nodes. Note that we test
18637 -- for violation of No_Fixed_IO even on non-source nodes, because the
18638 -- cases for checking violations of this restriction are instantiations
18639 -- where the reference in the instance has Comes_From_Source False.
18641 if not Comes_From_Source (N) then
18645 -- Check for violation of No_Abort_Statements, which is triggered by
18646 -- call to Ada.Task_Identification.Abort_Task.
18648 if Restriction_Check_Required (No_Abort_Statements)
18649 and then (Is_RTE (Val, RE_Abort_Task))
18651 -- A special extra check, don't complain about a reference from within
18652 -- the Ada.Task_Identification package itself!
18654 and then not In_Same_Extended_Unit (N, Val)
18656 Check_Restriction (No_Abort_Statements, Post_Node);
18659 if Val = Standard_Long_Long_Integer then
18660 Check_Restriction (No_Long_Long_Integers, Post_Node);
18663 -- Check for violation of No_Dynamic_Attachment
18665 if Restriction_Check_Required (No_Dynamic_Attachment)
18666 and then RTU_Loaded (Ada_Interrupts)
18667 and then (Is_RTE (Val, RE_Is_Reserved) or else
18668 Is_RTE (Val, RE_Is_Attached) or else
18669 Is_RTE (Val, RE_Current_Handler) or else
18670 Is_RTE (Val, RE_Attach_Handler) or else
18671 Is_RTE (Val, RE_Exchange_Handler) or else
18672 Is_RTE (Val, RE_Detach_Handler) or else
18673 Is_RTE (Val, RE_Reference))
18675 -- A special extra check, don't complain about a reference from within
18676 -- the Ada.Interrupts package itself!
18678 and then not In_Same_Extended_Unit (N, Val)
18680 Check_Restriction (No_Dynamic_Attachment, Post_Node);
18683 -- Check for No_Implementation_Identifiers
18685 if Restriction_Check_Required (No_Implementation_Identifiers) then
18687 -- We have an implementation defined entity if it is marked as
18688 -- implementation defined, or is defined in a package marked as
18689 -- implementation defined. However, library packages themselves
18690 -- are excluded (we don't want to flag Interfaces itself, just
18691 -- the entities within it).
18693 if (Is_Implementation_Defined (Val)
18695 (Present (Scope (Val))
18696 and then Is_Implementation_Defined (Scope (Val))))
18697 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
18698 and then Is_Library_Level_Entity (Val))
18700 Check_Restriction (No_Implementation_Identifiers, Post_Node);
18704 -- Do the style check
18707 and then not Suppress_Style_Checks (Val)
18708 and then not In_Instance
18710 if Nkind (N) = N_Identifier then
18712 elsif Nkind (N) = N_Expanded_Name then
18713 Nod := Selector_Name (N);
18718 -- A special situation arises for derived operations, where we want
18719 -- to do the check against the parent (since the Sloc of the derived
18720 -- operation points to the derived type declaration itself).
18723 while not Comes_From_Source (Val_Actual)
18724 and then Nkind (Val_Actual) in N_Entity
18725 and then (Ekind (Val_Actual) = E_Enumeration_Literal
18726 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
18727 and then Present (Alias (Val_Actual))
18729 Val_Actual := Alias (Val_Actual);
18732 -- Renaming declarations for generic actuals do not come from source,
18733 -- and have a different name from that of the entity they rename, so
18734 -- there is no style check to perform here.
18736 if Chars (Nod) = Chars (Val_Actual) then
18737 Style.Check_Identifier (Nod, Val_Actual);
18741 Set_Entity (N, Val);
18742 end Set_Entity_With_Checks;
18744 ------------------------
18745 -- Set_Name_Entity_Id --
18746 ------------------------
18748 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
18750 Set_Name_Table_Int (Id, Int (Val));
18751 end Set_Name_Entity_Id;
18753 ---------------------
18754 -- Set_Next_Actual --
18755 ---------------------
18757 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
18759 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
18760 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
18762 end Set_Next_Actual;
18764 ----------------------------------
18765 -- Set_Optimize_Alignment_Flags --
18766 ----------------------------------
18768 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
18770 if Optimize_Alignment = 'S' then
18771 Set_Optimize_Alignment_Space (E);
18772 elsif Optimize_Alignment = 'T' then
18773 Set_Optimize_Alignment_Time (E);
18775 end Set_Optimize_Alignment_Flags;
18777 -----------------------
18778 -- Set_Public_Status --
18779 -----------------------
18781 procedure Set_Public_Status (Id : Entity_Id) is
18782 S : constant Entity_Id := Current_Scope;
18784 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
18785 -- Determines if E is defined within handled statement sequence or
18786 -- an if statement, returns True if so, False otherwise.
18788 ----------------------
18789 -- Within_HSS_Or_If --
18790 ----------------------
18792 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
18795 N := Declaration_Node (E);
18802 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
18808 end Within_HSS_Or_If;
18810 -- Start of processing for Set_Public_Status
18813 -- Everything in the scope of Standard is public
18815 if S = Standard_Standard then
18816 Set_Is_Public (Id);
18818 -- Entity is definitely not public if enclosing scope is not public
18820 elsif not Is_Public (S) then
18823 -- An object or function declaration that occurs in a handled sequence
18824 -- of statements or within an if statement is the declaration for a
18825 -- temporary object or local subprogram generated by the expander. It
18826 -- never needs to be made public and furthermore, making it public can
18827 -- cause back end problems.
18829 elsif Nkind_In (Parent (Id), N_Object_Declaration,
18830 N_Function_Specification)
18831 and then Within_HSS_Or_If (Id)
18835 -- Entities in public packages or records are public
18837 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
18838 Set_Is_Public (Id);
18840 -- The bounds of an entry family declaration can generate object
18841 -- declarations that are visible to the back-end, e.g. in the
18842 -- the declaration of a composite type that contains tasks.
18844 elsif Is_Concurrent_Type (S)
18845 and then not Has_Completion (S)
18846 and then Nkind (Parent (Id)) = N_Object_Declaration
18848 Set_Is_Public (Id);
18850 end Set_Public_Status;
18852 -----------------------------
18853 -- Set_Referenced_Modified --
18854 -----------------------------
18856 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
18860 -- Deal with indexed or selected component where prefix is modified
18862 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
18863 Pref := Prefix (N);
18865 -- If prefix is access type, then it is the designated object that is
18866 -- being modified, which means we have no entity to set the flag on.
18868 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
18871 -- Otherwise chase the prefix
18874 Set_Referenced_Modified (Pref, Out_Param);
18877 -- Otherwise see if we have an entity name (only other case to process)
18879 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18880 Set_Referenced_As_LHS (Entity (N), not Out_Param);
18881 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
18883 end Set_Referenced_Modified;
18885 ----------------------------
18886 -- Set_Scope_Is_Transient --
18887 ----------------------------
18889 procedure Set_Scope_Is_Transient (V : Boolean := True) is
18891 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
18892 end Set_Scope_Is_Transient;
18894 -------------------
18895 -- Set_Size_Info --
18896 -------------------
18898 procedure Set_Size_Info (T1, T2 : Entity_Id) is
18900 -- We copy Esize, but not RM_Size, since in general RM_Size is
18901 -- subtype specific and does not get inherited by all subtypes.
18903 Set_Esize (T1, Esize (T2));
18904 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
18906 if Is_Discrete_Or_Fixed_Point_Type (T1)
18908 Is_Discrete_Or_Fixed_Point_Type (T2)
18910 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
18913 Set_Alignment (T1, Alignment (T2));
18916 --------------------
18917 -- Static_Boolean --
18918 --------------------
18920 function Static_Boolean (N : Node_Id) return Uint is
18922 Analyze_And_Resolve (N, Standard_Boolean);
18925 or else Error_Posted (N)
18926 or else Etype (N) = Any_Type
18931 if Is_OK_Static_Expression (N) then
18932 if not Raises_Constraint_Error (N) then
18933 return Expr_Value (N);
18938 elsif Etype (N) = Any_Type then
18942 Flag_Non_Static_Expr
18943 ("static boolean expression required here", N);
18946 end Static_Boolean;
18948 --------------------
18949 -- Static_Integer --
18950 --------------------
18952 function Static_Integer (N : Node_Id) return Uint is
18954 Analyze_And_Resolve (N, Any_Integer);
18957 or else Error_Posted (N)
18958 or else Etype (N) = Any_Type
18963 if Is_OK_Static_Expression (N) then
18964 if not Raises_Constraint_Error (N) then
18965 return Expr_Value (N);
18970 elsif Etype (N) = Any_Type then
18974 Flag_Non_Static_Expr
18975 ("static integer expression required here", N);
18978 end Static_Integer;
18980 --------------------------
18981 -- Statically_Different --
18982 --------------------------
18984 function Statically_Different (E1, E2 : Node_Id) return Boolean is
18985 R1 : constant Node_Id := Get_Referenced_Object (E1);
18986 R2 : constant Node_Id := Get_Referenced_Object (E2);
18988 return Is_Entity_Name (R1)
18989 and then Is_Entity_Name (R2)
18990 and then Entity (R1) /= Entity (R2)
18991 and then not Is_Formal (Entity (R1))
18992 and then not Is_Formal (Entity (R2));
18993 end Statically_Different;
18995 --------------------------------------
18996 -- Subject_To_Loop_Entry_Attributes --
18997 --------------------------------------
18999 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
19005 -- The expansion mechanism transform a loop subject to at least one
19006 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
19007 -- the conditional part.
19009 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
19010 and then Nkind (Original_Node (N)) = N_Loop_Statement
19012 Stmt := Original_Node (N);
19016 Nkind (Stmt) = N_Loop_Statement
19017 and then Present (Identifier (Stmt))
19018 and then Present (Entity (Identifier (Stmt)))
19019 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
19020 end Subject_To_Loop_Entry_Attributes;
19022 -----------------------------
19023 -- Subprogram_Access_Level --
19024 -----------------------------
19026 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
19028 if Present (Alias (Subp)) then
19029 return Subprogram_Access_Level (Alias (Subp));
19031 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
19033 end Subprogram_Access_Level;
19035 -------------------------------
19036 -- Support_Atomic_Primitives --
19037 -------------------------------
19039 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
19043 -- Verify the alignment of Typ is known
19045 if not Known_Alignment (Typ) then
19049 if Known_Static_Esize (Typ) then
19050 Size := UI_To_Int (Esize (Typ));
19052 -- If the Esize (Object_Size) is unknown at compile time, look at the
19053 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
19055 elsif Known_Static_RM_Size (Typ) then
19056 Size := UI_To_Int (RM_Size (Typ));
19058 -- Otherwise, the size is considered to be unknown.
19064 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
19065 -- Typ is properly aligned.
19068 when 8 | 16 | 32 | 64 =>
19069 return Size = UI_To_Int (Alignment (Typ)) * 8;
19073 end Support_Atomic_Primitives;
19079 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
19081 if Debug_Flag_W then
19082 for J in 0 .. Scope_Stack.Last loop
19087 Write_Name (Chars (E));
19088 Write_Str (" from ");
19089 Write_Location (Sloc (N));
19094 -----------------------
19095 -- Transfer_Entities --
19096 -----------------------
19098 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
19099 procedure Set_Public_Status_Of (Id : Entity_Id);
19100 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
19101 -- Set_Public_Status. If successfull and Id denotes a record type, set
19102 -- the Is_Public attribute of its fields.
19104 --------------------------
19105 -- Set_Public_Status_Of --
19106 --------------------------
19108 procedure Set_Public_Status_Of (Id : Entity_Id) is
19112 if not Is_Public (Id) then
19113 Set_Public_Status (Id);
19115 -- When the input entity is a public record type, ensure that all
19116 -- its internal fields are also exposed to the linker. The fields
19117 -- of a class-wide type are never made public.
19120 and then Is_Record_Type (Id)
19121 and then not Is_Class_Wide_Type (Id)
19123 Field := First_Entity (Id);
19124 while Present (Field) loop
19125 Set_Is_Public (Field);
19126 Next_Entity (Field);
19130 end Set_Public_Status_Of;
19134 Full_Id : Entity_Id;
19137 -- Start of processing for Transfer_Entities
19140 Id := First_Entity (From);
19142 if Present (Id) then
19144 -- Merge the entity chain of the source scope with that of the
19145 -- destination scope.
19147 if Present (Last_Entity (To)) then
19148 Set_Next_Entity (Last_Entity (To), Id);
19150 Set_First_Entity (To, Id);
19153 Set_Last_Entity (To, Last_Entity (From));
19155 -- Inspect the entities of the source scope and update their Scope
19158 while Present (Id) loop
19159 Set_Scope (Id, To);
19160 Set_Public_Status_Of (Id);
19162 -- Handle an internally generated full view for a private type
19164 if Is_Private_Type (Id)
19165 and then Present (Full_View (Id))
19166 and then Is_Itype (Full_View (Id))
19168 Full_Id := Full_View (Id);
19170 Set_Scope (Full_Id, To);
19171 Set_Public_Status_Of (Full_Id);
19177 Set_First_Entity (From, Empty);
19178 Set_Last_Entity (From, Empty);
19180 end Transfer_Entities;
19182 -----------------------
19183 -- Type_Access_Level --
19184 -----------------------
19186 function Type_Access_Level (Typ : Entity_Id) return Uint is
19190 Btyp := Base_Type (Typ);
19192 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
19193 -- simply use the level where the type is declared. This is true for
19194 -- stand-alone object declarations, and for anonymous access types
19195 -- associated with components the level is the same as that of the
19196 -- enclosing composite type. However, special treatment is needed for
19197 -- the cases of access parameters, return objects of an anonymous access
19198 -- type, and, in Ada 95, access discriminants of limited types.
19200 if Is_Access_Type (Btyp) then
19201 if Ekind (Btyp) = E_Anonymous_Access_Type then
19203 -- If the type is a nonlocal anonymous access type (such as for
19204 -- an access parameter) we treat it as being declared at the
19205 -- library level to ensure that names such as X.all'access don't
19206 -- fail static accessibility checks.
19208 if not Is_Local_Anonymous_Access (Typ) then
19209 return Scope_Depth (Standard_Standard);
19211 -- If this is a return object, the accessibility level is that of
19212 -- the result subtype of the enclosing function. The test here is
19213 -- little complicated, because we have to account for extended
19214 -- return statements that have been rewritten as blocks, in which
19215 -- case we have to find and the Is_Return_Object attribute of the
19216 -- itype's associated object. It would be nice to find a way to
19217 -- simplify this test, but it doesn't seem worthwhile to add a new
19218 -- flag just for purposes of this test. ???
19220 elsif Ekind (Scope (Btyp)) = E_Return_Statement
19223 and then Nkind (Associated_Node_For_Itype (Btyp)) =
19224 N_Object_Declaration
19225 and then Is_Return_Object
19226 (Defining_Identifier
19227 (Associated_Node_For_Itype (Btyp))))
19233 Scop := Scope (Scope (Btyp));
19234 while Present (Scop) loop
19235 exit when Ekind (Scop) = E_Function;
19236 Scop := Scope (Scop);
19239 -- Treat the return object's type as having the level of the
19240 -- function's result subtype (as per RM05-6.5(5.3/2)).
19242 return Type_Access_Level (Etype (Scop));
19247 Btyp := Root_Type (Btyp);
19249 -- The accessibility level of anonymous access types associated with
19250 -- discriminants is that of the current instance of the type, and
19251 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
19253 -- AI-402: access discriminants have accessibility based on the
19254 -- object rather than the type in Ada 2005, so the above paragraph
19257 -- ??? Needs completion with rules from AI-416
19259 if Ada_Version <= Ada_95
19260 and then Ekind (Typ) = E_Anonymous_Access_Type
19261 and then Present (Associated_Node_For_Itype (Typ))
19262 and then Nkind (Associated_Node_For_Itype (Typ)) =
19263 N_Discriminant_Specification
19265 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
19269 -- Return library level for a generic formal type. This is done because
19270 -- RM(10.3.2) says that "The statically deeper relationship does not
19271 -- apply to ... a descendant of a generic formal type". Rather than
19272 -- checking at each point where a static accessibility check is
19273 -- performed to see if we are dealing with a formal type, this rule is
19274 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
19275 -- return extreme values for a formal type; Deepest_Type_Access_Level
19276 -- returns Int'Last. By calling the appropriate function from among the
19277 -- two, we ensure that the static accessibility check will pass if we
19278 -- happen to run into a formal type. More specifically, we should call
19279 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
19280 -- call occurs as part of a static accessibility check and the error
19281 -- case is the case where the type's level is too shallow (as opposed
19284 if Is_Generic_Type (Root_Type (Btyp)) then
19285 return Scope_Depth (Standard_Standard);
19288 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
19289 end Type_Access_Level;
19291 ------------------------------------
19292 -- Type_Without_Stream_Operation --
19293 ------------------------------------
19295 function Type_Without_Stream_Operation
19297 Op : TSS_Name_Type := TSS_Null) return Entity_Id
19299 BT : constant Entity_Id := Base_Type (T);
19300 Op_Missing : Boolean;
19303 if not Restriction_Active (No_Default_Stream_Attributes) then
19307 if Is_Elementary_Type (T) then
19308 if Op = TSS_Null then
19310 No (TSS (BT, TSS_Stream_Read))
19311 or else No (TSS (BT, TSS_Stream_Write));
19314 Op_Missing := No (TSS (BT, Op));
19323 elsif Is_Array_Type (T) then
19324 return Type_Without_Stream_Operation (Component_Type (T), Op);
19326 elsif Is_Record_Type (T) then
19332 Comp := First_Component (T);
19333 while Present (Comp) loop
19334 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
19336 if Present (C_Typ) then
19340 Next_Component (Comp);
19346 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
19347 return Type_Without_Stream_Operation (Full_View (T), Op);
19351 end Type_Without_Stream_Operation;
19353 ----------------------------
19354 -- Unique_Defining_Entity --
19355 ----------------------------
19357 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
19359 return Unique_Entity (Defining_Entity (N));
19360 end Unique_Defining_Entity;
19362 -------------------
19363 -- Unique_Entity --
19364 -------------------
19366 function Unique_Entity (E : Entity_Id) return Entity_Id is
19367 U : Entity_Id := E;
19373 if Present (Full_View (E)) then
19374 U := Full_View (E);
19378 if Nkind (Parent (E)) = N_Entry_Body then
19380 Prot_Item : Entity_Id;
19382 -- Traverse the entity list of the protected type and locate
19383 -- an entry declaration which matches the entry body.
19385 Prot_Item := First_Entity (Scope (E));
19386 while Present (Prot_Item) loop
19387 if Ekind (Prot_Item) = E_Entry
19388 and then Corresponding_Body (Parent (Prot_Item)) = E
19394 Next_Entity (Prot_Item);
19399 when Formal_Kind =>
19400 if Present (Spec_Entity (E)) then
19401 U := Spec_Entity (E);
19404 when E_Package_Body =>
19407 if Nkind (P) = N_Defining_Program_Unit_Name then
19411 if Nkind (P) = N_Package_Body
19412 and then Present (Corresponding_Spec (P))
19414 U := Corresponding_Spec (P);
19416 elsif Nkind (P) = N_Package_Body_Stub
19417 and then Present (Corresponding_Spec_Of_Stub (P))
19419 U := Corresponding_Spec_Of_Stub (P);
19422 when E_Protected_Body =>
19425 if Nkind (P) = N_Protected_Body
19426 and then Present (Corresponding_Spec (P))
19428 U := Corresponding_Spec (P);
19430 elsif Nkind (P) = N_Protected_Body_Stub
19431 and then Present (Corresponding_Spec_Of_Stub (P))
19433 U := Corresponding_Spec_Of_Stub (P);
19436 when E_Subprogram_Body =>
19439 if Nkind (P) = N_Defining_Program_Unit_Name then
19445 if Nkind (P) = N_Subprogram_Body
19446 and then Present (Corresponding_Spec (P))
19448 U := Corresponding_Spec (P);
19450 elsif Nkind (P) = N_Subprogram_Body_Stub
19451 and then Present (Corresponding_Spec_Of_Stub (P))
19453 U := Corresponding_Spec_Of_Stub (P);
19456 when E_Task_Body =>
19459 if Nkind (P) = N_Task_Body
19460 and then Present (Corresponding_Spec (P))
19462 U := Corresponding_Spec (P);
19464 elsif Nkind (P) = N_Task_Body_Stub
19465 and then Present (Corresponding_Spec_Of_Stub (P))
19467 U := Corresponding_Spec_Of_Stub (P);
19471 if Present (Full_View (E)) then
19472 U := Full_View (E);
19486 function Unique_Name (E : Entity_Id) return String is
19488 -- Names of E_Subprogram_Body or E_Package_Body entities are not
19489 -- reliable, as they may not include the overloading suffix. Instead,
19490 -- when looking for the name of E or one of its enclosing scope, we get
19491 -- the name of the corresponding Unique_Entity.
19493 function Get_Scoped_Name (E : Entity_Id) return String;
19494 -- Return the name of E prefixed by all the names of the scopes to which
19495 -- E belongs, except for Standard.
19497 ---------------------
19498 -- Get_Scoped_Name --
19499 ---------------------
19501 function Get_Scoped_Name (E : Entity_Id) return String is
19502 Name : constant String := Get_Name_String (Chars (E));
19504 if Has_Fully_Qualified_Name (E)
19505 or else Scope (E) = Standard_Standard
19509 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
19511 end Get_Scoped_Name;
19513 -- Start of processing for Unique_Name
19516 if E = Standard_Standard then
19517 return Get_Name_String (Name_Standard);
19519 elsif Scope (E) = Standard_Standard
19520 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
19522 return Get_Name_String (Name_Standard) & "__" &
19523 Get_Name_String (Chars (E));
19525 elsif Ekind (E) = E_Enumeration_Literal then
19526 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
19529 return Get_Scoped_Name (Unique_Entity (E));
19533 ---------------------
19534 -- Unit_Is_Visible --
19535 ---------------------
19537 function Unit_Is_Visible (U : Entity_Id) return Boolean is
19538 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
19539 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
19541 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
19542 -- For a child unit, check whether unit appears in a with_clause
19545 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
19546 -- Scan the context clause of one compilation unit looking for a
19547 -- with_clause for the unit in question.
19549 ----------------------------
19550 -- Unit_In_Parent_Context --
19551 ----------------------------
19553 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
19555 if Unit_In_Context (Par_Unit) then
19558 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
19559 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
19564 end Unit_In_Parent_Context;
19566 ---------------------
19567 -- Unit_In_Context --
19568 ---------------------
19570 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
19574 Clause := First (Context_Items (Comp_Unit));
19575 while Present (Clause) loop
19576 if Nkind (Clause) = N_With_Clause then
19577 if Library_Unit (Clause) = U then
19580 -- The with_clause may denote a renaming of the unit we are
19581 -- looking for, eg. Text_IO which renames Ada.Text_IO.
19584 Renamed_Entity (Entity (Name (Clause))) =
19585 Defining_Entity (Unit (U))
19595 end Unit_In_Context;
19597 -- Start of processing for Unit_Is_Visible
19600 -- The currrent unit is directly visible
19605 elsif Unit_In_Context (Curr) then
19608 -- If the current unit is a body, check the context of the spec
19610 elsif Nkind (Unit (Curr)) = N_Package_Body
19612 (Nkind (Unit (Curr)) = N_Subprogram_Body
19613 and then not Acts_As_Spec (Unit (Curr)))
19615 if Unit_In_Context (Library_Unit (Curr)) then
19620 -- If the spec is a child unit, examine the parents
19622 if Is_Child_Unit (Curr_Entity) then
19623 if Nkind (Unit (Curr)) in N_Unit_Body then
19625 Unit_In_Parent_Context
19626 (Parent_Spec (Unit (Library_Unit (Curr))));
19628 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
19634 end Unit_Is_Visible;
19636 ------------------------------
19637 -- Universal_Interpretation --
19638 ------------------------------
19640 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
19641 Index : Interp_Index;
19645 -- The argument may be a formal parameter of an operator or subprogram
19646 -- with multiple interpretations, or else an expression for an actual.
19648 if Nkind (Opnd) = N_Defining_Identifier
19649 or else not Is_Overloaded (Opnd)
19651 if Etype (Opnd) = Universal_Integer
19652 or else Etype (Opnd) = Universal_Real
19654 return Etype (Opnd);
19660 Get_First_Interp (Opnd, Index, It);
19661 while Present (It.Typ) loop
19662 if It.Typ = Universal_Integer
19663 or else It.Typ = Universal_Real
19668 Get_Next_Interp (Index, It);
19673 end Universal_Interpretation;
19679 function Unqualify (Expr : Node_Id) return Node_Id is
19681 -- Recurse to handle unlikely case of multiple levels of qualification
19683 if Nkind (Expr) = N_Qualified_Expression then
19684 return Unqualify (Expression (Expr));
19686 -- Normal case, not a qualified expression
19693 -----------------------
19694 -- Visible_Ancestors --
19695 -----------------------
19697 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
19703 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
19705 -- Collect all the parents and progenitors of Typ. If the full-view of
19706 -- private parents and progenitors is available then it is used to
19707 -- generate the list of visible ancestors; otherwise their partial
19708 -- view is added to the resulting list.
19713 Use_Full_View => True);
19717 Ifaces_List => List_2,
19718 Exclude_Parents => True,
19719 Use_Full_View => True);
19721 -- Join the two lists. Avoid duplications because an interface may
19722 -- simultaneously be parent and progenitor of a type.
19724 Elmt := First_Elmt (List_2);
19725 while Present (Elmt) loop
19726 Append_Unique_Elmt (Node (Elmt), List_1);
19731 end Visible_Ancestors;
19733 ----------------------
19734 -- Within_Init_Proc --
19735 ----------------------
19737 function Within_Init_Proc return Boolean is
19741 S := Current_Scope;
19742 while not Is_Overloadable (S) loop
19743 if S = Standard_Standard then
19750 return Is_Init_Proc (S);
19751 end Within_Init_Proc;
19757 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
19764 elsif SE = Standard_Standard then
19776 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
19777 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
19778 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
19780 Matching_Field : Entity_Id;
19781 -- Entity to give a more precise suggestion on how to write a one-
19782 -- element positional aggregate.
19784 function Has_One_Matching_Field return Boolean;
19785 -- Determines if Expec_Type is a record type with a single component or
19786 -- discriminant whose type matches the found type or is one dimensional
19787 -- array whose component type matches the found type. In the case of
19788 -- one discriminant, we ignore the variant parts. That's not accurate,
19789 -- but good enough for the warning.
19791 ----------------------------
19792 -- Has_One_Matching_Field --
19793 ----------------------------
19795 function Has_One_Matching_Field return Boolean is
19799 Matching_Field := Empty;
19801 if Is_Array_Type (Expec_Type)
19802 and then Number_Dimensions (Expec_Type) = 1
19803 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
19805 -- Use type name if available. This excludes multidimensional
19806 -- arrays and anonymous arrays.
19808 if Comes_From_Source (Expec_Type) then
19809 Matching_Field := Expec_Type;
19811 -- For an assignment, use name of target
19813 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
19814 and then Is_Entity_Name (Name (Parent (Expr)))
19816 Matching_Field := Entity (Name (Parent (Expr)));
19821 elsif not Is_Record_Type (Expec_Type) then
19825 E := First_Entity (Expec_Type);
19830 elsif not Ekind_In (E, E_Discriminant, E_Component)
19831 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
19840 if not Covers (Etype (E), Found_Type) then
19843 elsif Present (Next_Entity (E))
19844 and then (Ekind (E) = E_Component
19845 or else Ekind (Next_Entity (E)) = E_Discriminant)
19850 Matching_Field := E;
19854 end Has_One_Matching_Field;
19856 -- Start of processing for Wrong_Type
19859 -- Don't output message if either type is Any_Type, or if a message
19860 -- has already been posted for this node. We need to do the latter
19861 -- check explicitly (it is ordinarily done in Errout), because we
19862 -- are using ! to force the output of the error messages.
19864 if Expec_Type = Any_Type
19865 or else Found_Type = Any_Type
19866 or else Error_Posted (Expr)
19870 -- If one of the types is a Taft-Amendment type and the other it its
19871 -- completion, it must be an illegal use of a TAT in the spec, for
19872 -- which an error was already emitted. Avoid cascaded errors.
19874 elsif Is_Incomplete_Type (Expec_Type)
19875 and then Has_Completion_In_Body (Expec_Type)
19876 and then Full_View (Expec_Type) = Etype (Expr)
19880 elsif Is_Incomplete_Type (Etype (Expr))
19881 and then Has_Completion_In_Body (Etype (Expr))
19882 and then Full_View (Etype (Expr)) = Expec_Type
19886 -- In an instance, there is an ongoing problem with completion of
19887 -- type derived from private types. Their structure is what Gigi
19888 -- expects, but the Etype is the parent type rather than the
19889 -- derived private type itself. Do not flag error in this case. The
19890 -- private completion is an entity without a parent, like an Itype.
19891 -- Similarly, full and partial views may be incorrect in the instance.
19892 -- There is no simple way to insure that it is consistent ???
19894 -- A similar view discrepancy can happen in an inlined body, for the
19895 -- same reason: inserted body may be outside of the original package
19896 -- and only partial views are visible at the point of insertion.
19898 elsif In_Instance or else In_Inlined_Body then
19899 if Etype (Etype (Expr)) = Etype (Expected_Type)
19901 (Has_Private_Declaration (Expected_Type)
19902 or else Has_Private_Declaration (Etype (Expr)))
19903 and then No (Parent (Expected_Type))
19907 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
19908 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
19912 elsif Is_Private_Type (Expected_Type)
19913 and then Present (Full_View (Expected_Type))
19914 and then Covers (Full_View (Expected_Type), Etype (Expr))
19918 -- Conversely, type of expression may be the private one
19920 elsif Is_Private_Type (Base_Type (Etype (Expr)))
19921 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
19927 -- An interesting special check. If the expression is parenthesized
19928 -- and its type corresponds to the type of the sole component of the
19929 -- expected record type, or to the component type of the expected one
19930 -- dimensional array type, then assume we have a bad aggregate attempt.
19932 if Nkind (Expr) in N_Subexpr
19933 and then Paren_Count (Expr) /= 0
19934 and then Has_One_Matching_Field
19936 Error_Msg_N ("positional aggregate cannot have one component", Expr);
19938 if Present (Matching_Field) then
19939 if Is_Array_Type (Expec_Type) then
19941 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
19944 ("\write instead `& ='> ...`", Expr, Matching_Field);
19948 -- Another special check, if we are looking for a pool-specific access
19949 -- type and we found an E_Access_Attribute_Type, then we have the case
19950 -- of an Access attribute being used in a context which needs a pool-
19951 -- specific type, which is never allowed. The one extra check we make
19952 -- is that the expected designated type covers the Found_Type.
19954 elsif Is_Access_Type (Expec_Type)
19955 and then Ekind (Found_Type) = E_Access_Attribute_Type
19956 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
19957 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
19959 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
19961 Error_Msg_N -- CODEFIX
19962 ("result must be general access type!", Expr);
19963 Error_Msg_NE -- CODEFIX
19964 ("add ALL to }!", Expr, Expec_Type);
19966 -- Another special check, if the expected type is an integer type,
19967 -- but the expression is of type System.Address, and the parent is
19968 -- an addition or subtraction operation whose left operand is the
19969 -- expression in question and whose right operand is of an integral
19970 -- type, then this is an attempt at address arithmetic, so give
19971 -- appropriate message.
19973 elsif Is_Integer_Type (Expec_Type)
19974 and then Is_RTE (Found_Type, RE_Address)
19975 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
19976 and then Expr = Left_Opnd (Parent (Expr))
19977 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
19980 ("address arithmetic not predefined in package System",
19983 ("\possible missing with/use of System.Storage_Elements",
19987 -- If the expected type is an anonymous access type, as for access
19988 -- parameters and discriminants, the error is on the designated types.
19990 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
19991 if Comes_From_Source (Expec_Type) then
19992 Error_Msg_NE ("expected}!", Expr, Expec_Type);
19995 ("expected an access type with designated}",
19996 Expr, Designated_Type (Expec_Type));
19999 if Is_Access_Type (Found_Type)
20000 and then not Comes_From_Source (Found_Type)
20003 ("\\found an access type with designated}!",
20004 Expr, Designated_Type (Found_Type));
20006 if From_Limited_With (Found_Type) then
20007 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
20008 Error_Msg_Qual_Level := 99;
20009 Error_Msg_NE -- CODEFIX
20010 ("\\missing `WITH &;", Expr, Scope (Found_Type));
20011 Error_Msg_Qual_Level := 0;
20013 Error_Msg_NE ("found}!", Expr, Found_Type);
20017 -- Normal case of one type found, some other type expected
20020 -- If the names of the two types are the same, see if some number
20021 -- of levels of qualification will help. Don't try more than three
20022 -- levels, and if we get to standard, it's no use (and probably
20023 -- represents an error in the compiler) Also do not bother with
20024 -- internal scope names.
20027 Expec_Scope : Entity_Id;
20028 Found_Scope : Entity_Id;
20031 Expec_Scope := Expec_Type;
20032 Found_Scope := Found_Type;
20034 for Levels in Nat range 0 .. 3 loop
20035 if Chars (Expec_Scope) /= Chars (Found_Scope) then
20036 Error_Msg_Qual_Level := Levels;
20040 Expec_Scope := Scope (Expec_Scope);
20041 Found_Scope := Scope (Found_Scope);
20043 exit when Expec_Scope = Standard_Standard
20044 or else Found_Scope = Standard_Standard
20045 or else not Comes_From_Source (Expec_Scope)
20046 or else not Comes_From_Source (Found_Scope);
20050 if Is_Record_Type (Expec_Type)
20051 and then Present (Corresponding_Remote_Type (Expec_Type))
20053 Error_Msg_NE ("expected}!", Expr,
20054 Corresponding_Remote_Type (Expec_Type));
20056 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20059 if Is_Entity_Name (Expr)
20060 and then Is_Package_Or_Generic_Package (Entity (Expr))
20062 Error_Msg_N ("\\found package name!", Expr);
20064 elsif Is_Entity_Name (Expr)
20065 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
20067 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
20069 ("found procedure name, possibly missing Access attribute!",
20073 ("\\found procedure name instead of function!", Expr);
20076 elsif Nkind (Expr) = N_Function_Call
20077 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
20078 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
20079 and then No (Parameter_Associations (Expr))
20082 ("found function name, possibly missing Access attribute!",
20085 -- Catch common error: a prefix or infix operator which is not
20086 -- directly visible because the type isn't.
20088 elsif Nkind (Expr) in N_Op
20089 and then Is_Overloaded (Expr)
20090 and then not Is_Immediately_Visible (Expec_Type)
20091 and then not Is_Potentially_Use_Visible (Expec_Type)
20092 and then not In_Use (Expec_Type)
20093 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
20096 ("operator of the type is not directly visible!", Expr);
20098 elsif Ekind (Found_Type) = E_Void
20099 and then Present (Parent (Found_Type))
20100 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
20102 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
20105 Error_Msg_NE ("\\found}!", Expr, Found_Type);
20108 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
20109 -- of the same modular type, and (M1 and M2) = 0 was intended.
20111 if Expec_Type = Standard_Boolean
20112 and then Is_Modular_Integer_Type (Found_Type)
20113 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
20114 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
20117 Op : constant Node_Id := Right_Opnd (Parent (Expr));
20118 L : constant Node_Id := Left_Opnd (Op);
20119 R : constant Node_Id := Right_Opnd (Op);
20122 -- The case for the message is when the left operand of the
20123 -- comparison is the same modular type, or when it is an
20124 -- integer literal (or other universal integer expression),
20125 -- which would have been typed as the modular type if the
20126 -- parens had been there.
20128 if (Etype (L) = Found_Type
20130 Etype (L) = Universal_Integer)
20131 and then Is_Integer_Type (Etype (R))
20134 ("\\possible missing parens for modular operation", Expr);
20139 -- Reset error message qualification indication
20141 Error_Msg_Qual_Level := 0;
20145 --------------------------------
20146 -- Yields_Synchronized_Object --
20147 --------------------------------
20149 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
20150 Has_Sync_Comp : Boolean := False;
20154 -- An array type yields a synchronized object if its component type
20155 -- yields a synchronized object.
20157 if Is_Array_Type (Typ) then
20158 return Yields_Synchronized_Object (Component_Type (Typ));
20160 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
20161 -- yields a synchronized object by default.
20163 elsif Is_Descendant_Of_Suspension_Object (Typ) then
20166 -- A protected type yields a synchronized object by default
20168 elsif Is_Protected_Type (Typ) then
20171 -- A record type or type extension yields a synchronized object when its
20172 -- discriminants (if any) lack default values and all components are of
20173 -- a type that yelds a synchronized object.
20175 elsif Is_Record_Type (Typ) then
20177 -- Inspect all entities defined in the scope of the type, looking for
20178 -- components of a type that does not yeld a synchronized object or
20179 -- for discriminants with default values.
20181 Id := First_Entity (Typ);
20182 while Present (Id) loop
20183 if Comes_From_Source (Id) then
20184 if Ekind (Id) = E_Component then
20185 if Yields_Synchronized_Object (Etype (Id)) then
20186 Has_Sync_Comp := True;
20188 -- The component does not yield a synchronized object
20194 elsif Ekind (Id) = E_Discriminant
20195 and then Present (Expression (Parent (Id)))
20204 -- Ensure that the parent type of a type extension yields a
20205 -- synchronized object.
20207 if Etype (Typ) /= Typ
20208 and then not Yields_Synchronized_Object (Etype (Typ))
20213 -- If we get here, then all discriminants lack default values and all
20214 -- components are of a type that yields a synchronized object.
20216 return Has_Sync_Comp;
20218 -- A synchronized interface type yields a synchronized object by default
20220 elsif Is_Synchronized_Interface (Typ) then
20223 -- A task type yelds a synchronized object by default
20225 elsif Is_Task_Type (Typ) then
20228 -- Otherwise the type does not yield a synchronized object
20233 end Yields_Synchronized_Object;